summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.clang-format1
-rw-r--r--bfdd/bfdd_cli.c38
-rw-r--r--bgpd/bgp_attr.c8
-rw-r--r--bgpd/bgp_attr.h34
-rw-r--r--bgpd/bgp_attr_evpn.c52
-rw-r--r--bgpd/bgp_attr_evpn.h24
-rw-r--r--bgpd/bgp_bfd.c14
-rw-r--r--bgpd/bgp_bmp.c5
-rw-r--r--bgpd/bgp_damp.c6
-rw-r--r--bgpd/bgp_debug.c74
-rw-r--r--bgpd/bgp_debug.h4
-rw-r--r--bgpd/bgp_ecommunity.c44
-rw-r--r--bgpd/bgp_ecommunity.h8
-rw-r--r--bgpd/bgp_evpn.c1821
-rw-r--r--bgpd/bgp_evpn.h6
-rw-r--r--bgpd/bgp_evpn_mh.c2905
-rw-r--r--bgpd/bgp_evpn_mh.h299
-rw-r--r--bgpd/bgp_evpn_private.h147
-rw-r--r--bgpd/bgp_evpn_vty.c321
-rw-r--r--bgpd/bgp_flowspec_vty.c7
-rw-r--r--bgpd/bgp_fsm.c9
-rw-r--r--bgpd/bgp_main.c15
-rw-r--r--bgpd/bgp_memory.c5
-rw-r--r--bgpd/bgp_memory.h3
-rw-r--r--bgpd/bgp_nht.c17
-rw-r--r--bgpd/bgp_rd.h1
-rw-r--r--bgpd/bgp_route.c689
-rw-r--r--bgpd/bgp_route.h11
-rw-r--r--bgpd/bgp_snmp.c46
-rw-r--r--bgpd/bgp_table.h2
-rw-r--r--bgpd/bgp_updgrp_adv.c9
-rw-r--r--bgpd/bgp_updgrp_packet.c12
-rw-r--r--bgpd/bgp_vpn.c2
-rw-r--r--bgpd/bgp_vty.c13
-rw-r--r--bgpd/bgp_zebra.c95
-rw-r--r--bgpd/bgpd.c15
-rw-r--r--bgpd/bgpd.h7
-rw-r--r--bgpd/subdir.am3
-rw-r--r--bgpd/valgrind.supp17
-rw-r--r--doc/developer/building-frr-for-openwrt.rst32
-rw-r--r--doc/manpages/frr-watchfrr.rst16
-rw-r--r--doc/user/bfd.rst11
-rw-r--r--doc/user/bgp.rst173
-rw-r--r--doc/user/ospf6d.rst7
-rw-r--r--doc/user/overview.rst4
-rw-r--r--doc/user/pbr.rst16
-rw-r--r--doc/user/pim.rst7
-rw-r--r--doc/user/sharp.rst10
-rw-r--r--eigrpd/eigrp_cli.c60
-rw-r--r--include/linux/if_bridge.h11
-rw-r--r--include/linux/neighbour.h2
-rw-r--r--include/linux/net_namespace.h1
-rw-r--r--include/linux/nexthop.h1
-rw-r--r--isisd/isis_bfd.c81
-rw-r--r--isisd/isis_bfd.h6
-rw-r--r--isisd/isis_cli.c186
-rw-r--r--isisd/isis_nb.c15
-rw-r--r--isisd/isis_nb.h9
-rw-r--r--isisd/isis_nb_config.c43
-rw-r--r--isisd/isis_vty_fabricd.c4
-rw-r--r--ldpd/l2vpn.c12
-rw-r--r--ldpd/lde.c2
-rw-r--r--ldpd/lde.h5
-rw-r--r--ldpd/lde_lib.c49
-rw-r--r--lib/bfd.c27
-rw-r--r--lib/bfd.h4
-rw-r--r--lib/bitfield.h43
-rw-r--r--lib/command.c7
-rw-r--r--lib/command.h33
-rw-r--r--lib/command_graph.h1
-rw-r--r--lib/defun_lex.l2
-rw-r--r--lib/filter.h5
-rw-r--r--lib/filter_cli.c267
-rw-r--r--lib/filter_nb.c412
-rw-r--r--lib/if.c22
-rw-r--r--lib/if.h7
-rw-r--r--lib/ipaddr.h25
-rw-r--r--lib/libfrr.c10
-rw-r--r--lib/linklist.c58
-rw-r--r--lib/linklist.h20
-rw-r--r--lib/log.c4
-rw-r--r--lib/netns_linux.c38
-rw-r--r--lib/nexthop.c127
-rw-r--r--lib/nexthop.h25
-rw-r--r--lib/nexthop_group.c81
-rw-r--r--lib/nexthop_group.h6
-rw-r--r--lib/northbound_cli.c132
-rw-r--r--lib/northbound_cli.h8
-rw-r--r--lib/ns.h16
-rw-r--r--lib/pbr.h7
-rw-r--r--lib/prefix.c21
-rw-r--r--lib/prefix.h62
-rwxr-xr-xlib/route_types.pl2
-rw-r--r--lib/routemap.c6
-rw-r--r--lib/routemap_cli.c163
-rw-r--r--lib/routemap_northbound.c85
-rw-r--r--lib/routing_nb.c40
-rw-r--r--lib/routing_nb.h24
-rw-r--r--lib/routing_nb_config.c74
-rw-r--r--lib/sockunion.c47
-rw-r--r--lib/sockunion.h4
-rw-r--r--lib/srcdest_table.c10
-rw-r--r--lib/srcdest_table.h2
-rw-r--r--lib/stream.c14
-rw-r--r--lib/subdir.am7
-rw-r--r--lib/thread.c30
-rw-r--r--lib/thread.h4
-rw-r--r--lib/vrf.c19
-rw-r--r--lib/vrf.h2
-rw-r--r--lib/vty.c3
-rw-r--r--lib/vty.h8
-rw-r--r--lib/yang.c172
-rw-r--r--lib/yang.h55
-rw-r--r--lib/yang_wrappers.c60
-rw-r--r--lib/yang_wrappers.h3
-rw-r--r--lib/zclient.c47
-rw-r--r--lib/zclient.h16
-rw-r--r--lib/zlog.c6
-rw-r--r--nhrpd/nhrp_route.c4
-rw-r--r--ospf6d/ospf6_abr.c27
-rw-r--r--ospf6d/ospf6_area.c16
-rw-r--r--ospf6d/ospf6_area.h17
-rw-r--r--ospf6d/ospf6_asbr.c55
-rw-r--r--ospf6d/ospf6_bfd.c2
-rw-r--r--ospf6d/ospf6_interface.h8
-rw-r--r--ospf6d/ospf6_intra.c18
-rw-r--r--ospf6d/ospf6_intra.h10
-rw-r--r--ospf6d/ospf6_lsa.h4
-rw-r--r--ospf6d/ospf6_message.h12
-rw-r--r--ospf6d/ospf6_neighbor.h10
-rw-r--r--ospf6d/ospf6_route.h6
-rw-r--r--ospf6d/ospf6_top.c23
-rw-r--r--ospf6d/ospf6_top.h6
-rw-r--r--ospfd/ospf_bfd.c2
-rw-r--r--ospfd/ospf_vty.c6
-rw-r--r--ospfd/ospf_zebra.c2
-rw-r--r--pbrd/pbr_map.c61
-rw-r--r--pbrd/pbr_map.h6
-rw-r--r--pbrd/pbr_nht.c51
-rw-r--r--pbrd/pbr_vty.c107
-rw-r--r--pbrd/pbr_zebra.c1
-rw-r--r--pimd/pim_bfd.c2
-rw-r--r--pimd/pim_cmd.c8
-rw-r--r--pimd/pim_rpf.c1
-rw-r--r--pimd/subdir.am6
-rw-r--r--python/makefile.py9
-rw-r--r--ripd/rip_cli.c68
-rw-r--r--ripngd/ripng_cli.c34
-rw-r--r--sharpd/sharp_main.c3
-rw-r--r--sharpd/sharp_vty.c37
-rw-r--r--sharpd/sharp_zebra.c28
-rw-r--r--sharpd/sharp_zebra.h5
-rw-r--r--staticd/static_main.c11
-rw-r--r--staticd/static_memory.c2
-rw-r--r--staticd/static_memory.h3
-rw-r--r--staticd/static_nb.c188
-rw-r--r--staticd/static_nb.h166
-rw-r--r--staticd/static_nb_config.c1241
-rw-r--r--staticd/static_nht.c122
-rw-r--r--staticd/static_routes.c636
-rw-r--r--staticd/static_routes.h112
-rw-r--r--staticd/static_vrf.c68
-rw-r--r--staticd/static_vrf.h10
-rw-r--r--staticd/static_vty.c1195
-rw-r--r--staticd/static_vty.h2
-rw-r--r--staticd/static_zebra.c142
-rw-r--r--staticd/static_zebra.h8
-rw-r--r--staticd/subdir.am7
-rw-r--r--tests/topotests/all-protocol-startup/r1/show_route_map.ref15
-rw-r--r--tests/topotests/bfd-profiles-topo1/r3/bfd-peers-initial.json4
-rw-r--r--tests/topotests/bfd-profiles-topo1/r3/bfdd.conf9
-rw-r--r--tests/topotests/bfd-profiles-topo1/r3/bgpd.conf2
-rw-r--r--tests/topotests/bfd-profiles-topo1/r3/isisd.conf1
-rw-r--r--tests/topotests/bfd-profiles-topo1/r4/bfd-peers-initial.json4
-rw-r--r--tests/topotests/bfd-profiles-topo1/r4/bgpd.conf2
-rw-r--r--tests/topotests/bfd-profiles-topo1/r4/isisd.conf1
-rwxr-xr-x[-rw-r--r--]tests/topotests/bfd-profiles-topo1/test_bfd_profiles_topo1.py0
-rw-r--r--tests/topotests/bgp-evpn-mh/evpn-mh-topo-tests.pdfbin0 -> 90963 bytes
-rw-r--r--tests/topotests/bgp-evpn-mh/hostd11/evpn.conf0
-rw-r--r--tests/topotests/bgp-evpn-mh/hostd11/pim.conf0
-rw-r--r--tests/topotests/bgp-evpn-mh/hostd11/zebra.conf0
-rw-r--r--tests/topotests/bgp-evpn-mh/hostd12/evpn.conf0
-rw-r--r--tests/topotests/bgp-evpn-mh/hostd12/pim.conf0
-rw-r--r--tests/topotests/bgp-evpn-mh/hostd12/zebra.conf0
-rw-r--r--tests/topotests/bgp-evpn-mh/hostd21/evpn.conf0
-rw-r--r--tests/topotests/bgp-evpn-mh/hostd21/pim.conf0
-rw-r--r--tests/topotests/bgp-evpn-mh/hostd21/zebra.conf0
-rw-r--r--tests/topotests/bgp-evpn-mh/hostd22/evpn.conf0
-rw-r--r--tests/topotests/bgp-evpn-mh/hostd22/pim.conf0
-rw-r--r--tests/topotests/bgp-evpn-mh/hostd22/zebra.conf0
-rw-r--r--tests/topotests/bgp-evpn-mh/spine1/evpn.conf17
-rw-r--r--tests/topotests/bgp-evpn-mh/spine1/pim.conf18
-rw-r--r--tests/topotests/bgp-evpn-mh/spine1/zebra.conf15
-rw-r--r--tests/topotests/bgp-evpn-mh/spine2/evpn.conf17
-rw-r--r--tests/topotests/bgp-evpn-mh/spine2/pim.conf18
-rw-r--r--tests/topotests/bgp-evpn-mh/spine2/zebra.conf15
-rwxr-xr-xtests/topotests/bgp-evpn-mh/test_evpn_mh.py651
-rw-r--r--tests/topotests/bgp-evpn-mh/torm11/evpn.conf21
-rw-r--r--tests/topotests/bgp-evpn-mh/torm11/pim.conf13
-rw-r--r--tests/topotests/bgp-evpn-mh/torm11/zebra.conf23
-rw-r--r--tests/topotests/bgp-evpn-mh/torm12/evpn.conf21
-rw-r--r--tests/topotests/bgp-evpn-mh/torm12/pim.conf13
-rw-r--r--tests/topotests/bgp-evpn-mh/torm12/zebra.conf23
-rw-r--r--tests/topotests/bgp-evpn-mh/torm21/evpn.conf21
-rw-r--r--tests/topotests/bgp-evpn-mh/torm21/pim.conf13
-rw-r--r--tests/topotests/bgp-evpn-mh/torm21/zebra.conf23
-rw-r--r--tests/topotests/bgp-evpn-mh/torm22/evpn.conf21
-rw-r--r--tests/topotests/bgp-evpn-mh/torm22/pim.conf13
-rw-r--r--tests/topotests/bgp-evpn-mh/torm22/zebra.conf23
-rw-r--r--tests/topotests/bgp_l3vpn_to_bgp_direct/ce1/bgpd.conf1
-rw-r--r--tests/topotests/bgp_l3vpn_to_bgp_direct/ce2/bgpd.conf1
-rw-r--r--tests/topotests/bgp_l3vpn_to_bgp_direct/ce3/bgpd.conf1
-rw-r--r--tests/topotests/bgp_l3vpn_to_bgp_direct/r1/bgpd.conf1
-rw-r--r--tests/topotests/bgp_l3vpn_to_bgp_direct/r2/bgpd.conf1
-rw-r--r--tests/topotests/bgp_l3vpn_to_bgp_direct/r3/bgpd.conf1
-rw-r--r--tests/topotests/bgp_l3vpn_to_bgp_direct/r4/bgpd.conf1
-rw-r--r--tests/topotests/bgp_l3vpn_to_bgp_vrf/ce1/bgpd.conf1
-rw-r--r--tests/topotests/bgp_l3vpn_to_bgp_vrf/ce2/bgpd.conf1
-rw-r--r--tests/topotests/bgp_l3vpn_to_bgp_vrf/ce3/bgpd.conf1
-rw-r--r--tests/topotests/bgp_l3vpn_to_bgp_vrf/ce4/bgpd.conf1
-rw-r--r--tests/topotests/bgp_l3vpn_to_bgp_vrf/r1/bgpd.conf1
-rw-r--r--tests/topotests/bgp_l3vpn_to_bgp_vrf/r2/bgpd.conf1
-rw-r--r--tests/topotests/bgp_l3vpn_to_bgp_vrf/r3/bgpd.conf1
-rw-r--r--tests/topotests/bgp_l3vpn_to_bgp_vrf/r4/bgpd.conf1
-rw-r--r--tests/topotests/bgp_prefix_sid/r1/bgpd.conf1
-rw-r--r--tests/topotests/bgp_rfapi_basic_sanity/r1/bgpd.conf1
-rw-r--r--tests/topotests/bgp_rfapi_basic_sanity/r2/bgpd.conf1
-rw-r--r--tests/topotests/bgp_rfapi_basic_sanity/r3/bgpd.conf1
-rw-r--r--tests/topotests/bgp_rfapi_basic_sanity/r4/bgpd.conf1
-rw-r--r--tests/topotests/bgp_rfapi_basic_sanity_config2/r1/bgpd.conf1
-rw-r--r--tests/topotests/bgp_rfapi_basic_sanity_config2/r2/bgpd.conf1
-rw-r--r--tests/topotests/bgp_rfapi_basic_sanity_config2/r3/bgpd.conf1
-rw-r--r--tests/topotests/bgp_rfapi_basic_sanity_config2/r4/bgpd.conf1
-rw-r--r--tests/topotests/evpn_type5_test_topo1/__init__.py0
-rw-r--r--tests/topotests/evpn_type5_test_topo1/evpn_type5_chaos_topo1.json887
-rw-r--r--tests/topotests/evpn_type5_test_topo1/evpn_type5_topo1.json887
-rwxr-xr-xtests/topotests/evpn_type5_test_topo1/test_evpn_type5_chaos_topo1.py1047
-rwxr-xr-xtests/topotests/evpn_type5_test_topo1/test_evpn_type5_topo1.py2117
-rw-r--r--tests/topotests/lib/bgp.py724
-rw-r--r--tests/topotests/lib/common_config.py571
-rw-r--r--tests/topotests/lib/topogen.py4
-rw-r--r--tests/topotests/pbr-topo1/r1/pbr-map.json26
-rw-r--r--tests/topotests/pbr-topo1/r1/pbrd.conf10
-rw-r--r--tests/topotests/pytest.ini2
-rwxr-xr-xtests/topotests/route-scale/test_route_scale.py156
-rw-r--r--tools/cocci.h37
-rw-r--r--tools/etc/frr/daemons5
-rwxr-xr-xtools/frr-reload.py44
-rwxr-xr-xtools/frr.in2
-rw-r--r--tools/frr@.service25
-rw-r--r--tools/frrcommon.sh.in22
-rw-r--r--tools/frrinit.sh.in5
-rw-r--r--tools/gcc-plugins/README.md15
-rw-r--r--tools/gcc-plugins/debian/changelog6
-rw-r--r--tools/gcc-plugins/debian/control4
-rw-r--r--tools/gcc-plugins/debian/source/format2
-rw-r--r--tools/gcc-plugins/format-test.c6
-rw-r--r--tools/gcc-plugins/format-test.py8
-rw-r--r--tools/gcc-plugins/frr-format.c40
-rw-r--r--tools/gcc-plugins/gcc-common.h6
-rw-r--r--tools/subdir.am1
-rw-r--r--vrrpd/vrrp.c4
-rw-r--r--vrrpd/vrrp_packet.c2
-rw-r--r--vrrpd/vrrp_vty.c30
-rwxr-xr-xvtysh/extract.pl.in9
-rw-r--r--vtysh/vtysh.h3
-rw-r--r--vtysh/vtysh_config.c65
-rw-r--r--watchfrr/watchfrr.c181
-rw-r--r--yang/embedmodel.py21
-rw-r--r--yang/frr-filter.yang162
-rw-r--r--yang/frr-isisd.yang17
-rw-r--r--yang/frr-nexthop.yang7
-rw-r--r--yang/frr-ospfd.yang995
-rw-r--r--yang/frr-route-map.yang158
-rw-r--r--yang/frr-routing.yang31
-rw-r--r--yang/frr-staticd.yang92
-rw-r--r--yang/frr-zebra.yang72
-rw-r--r--yang/subdir.am9
-rw-r--r--zebra/debug.c79
-rw-r--r--zebra/debug.h15
-rw-r--r--zebra/dplane_fpm_nl.c169
-rw-r--r--zebra/if_netlink.c148
-rw-r--r--zebra/interface.c36
-rw-r--r--zebra/interface.h31
-rw-r--r--zebra/main.c6
-rw-r--r--zebra/rib.h21
-rw-r--r--zebra/rt.h5
-rw-r--r--zebra/rt_netlink.c336
-rw-r--r--zebra/rt_socket.c21
-rw-r--r--zebra/rule_netlink.c40
-rw-r--r--zebra/subdir.am4
-rw-r--r--zebra/zapi_msg.c117
-rw-r--r--zebra/zebra_dplane.c259
-rw-r--r--zebra/zebra_dplane.h55
-rw-r--r--zebra/zebra_errors.h1
-rw-r--r--zebra/zebra_evpn_mh.c2145
-rw-r--r--zebra/zebra_evpn_mh.h239
-rw-r--r--zebra/zebra_fpm_netlink.c17
-rw-r--r--zebra/zebra_l2.c85
-rw-r--r--zebra/zebra_l2.h11
-rw-r--r--zebra/zebra_memory.c2
-rw-r--r--zebra/zebra_mpls.c86
-rw-r--r--zebra/zebra_nb.c68
-rw-r--r--zebra/zebra_nb.h13
-rw-r--r--zebra/zebra_nb_config.c241
-rw-r--r--zebra/zebra_nb_state.c42
-rw-r--r--zebra/zebra_netns_id.c43
-rw-r--r--zebra/zebra_netns_id.h2
-rw-r--r--zebra/zebra_netns_notify.c21
-rw-r--r--zebra/zebra_nhg.c23
-rw-r--r--zebra/zebra_ns.c17
-rw-r--r--zebra/zebra_ns.h9
-rw-r--r--zebra/zebra_pbr.c17
-rw-r--r--zebra/zebra_pbr.h2
-rw-r--r--zebra/zebra_pw.c104
-rw-r--r--zebra/zebra_rib.c46
-rw-r--r--zebra/zebra_rnh.c26
-rw-r--r--zebra/zebra_routemap.c48
-rw-r--r--zebra/zebra_router.c1
-rw-r--r--zebra/zebra_router.h6
-rw-r--r--zebra/zebra_vty.c348
-rw-r--r--zebra/zebra_vxlan.c2955
-rw-r--r--zebra/zebra_vxlan.h6
-rw-r--r--zebra/zebra_vxlan_private.h78
-rw-r--r--zebra/zserv.c6
-rw-r--r--zebra/zserv.h4
326 files changed, 25784 insertions, 6321 deletions
diff --git a/.clang-format b/.clang-format
index 654577d936..47d681e0e2 100644
--- a/.clang-format
+++ b/.clang-format
@@ -66,5 +66,6 @@ ForEachMacros:
- SUBGRP_FOREACH_ADJ_SAFE
- AF_FOREACH
- FOREACH_AFI_SAFI
+ - FOREACH_SAFI
# ospfd
- LSDB_LOOP
diff --git a/bfdd/bfdd_cli.c b/bfdd/bfdd_cli.c
index 28c6cbee26..0dd021d475 100644
--- a/bfdd/bfdd_cli.c
+++ b/bfdd/bfdd_cli.c
@@ -55,7 +55,7 @@
/*
* Functions.
*/
-DEFPY_NOSH(
+DEFPY_YANG_NOSH(
bfd_enter, bfd_enter_cmd,
"bfd",
"Configure BFD peers\n")
@@ -70,7 +70,7 @@ DEFPY_NOSH(
return ret;
}
-DEFUN(
+DEFUN_YANG(
bfd_config_reset, bfd_config_reset_cmd,
"no bfd",
NO_STR
@@ -93,7 +93,7 @@ void bfd_cli_show_header_end(struct vty *vty,
vty_out(vty, "!\n");
}
-DEFPY_NOSH(
+DEFPY_YANG_NOSH(
bfd_peer_enter, bfd_peer_enter_cmd,
"peer <A.B.C.D|X:X::X:X> [{multihop$multihop|local-address <A.B.C.D|X:X::X:X>|interface IFNAME$ifname|vrf NAME}]",
PEER_STR
@@ -150,7 +150,7 @@ DEFPY_NOSH(
return ret;
}
-DEFPY(
+DEFPY_YANG(
bfd_no_peer, bfd_no_peer_cmd,
"no peer <A.B.C.D|X:X::X:X> [{multihop$multihop|local-address <A.B.C.D|X:X::X:X>|interface IFNAME$ifname|vrf NAME}]",
NO_STR
@@ -244,7 +244,7 @@ void bfd_cli_show_peer_end(struct vty *vty,
vty_out(vty, " !\n");
}
-DEFPY(
+DEFPY_YANG(
bfd_peer_shutdown, bfd_peer_shutdown_cmd,
"[no] shutdown",
NO_STR
@@ -265,7 +265,7 @@ void bfd_cli_show_shutdown(struct vty *vty, struct lyd_node *dnode,
yang_dnode_get_bool(dnode, NULL) ? "" : "no ");
}
-DEFPY(
+DEFPY_YANG(
bfd_peer_mult, bfd_peer_mult_cmd,
"detect-multiplier (2-255)$multiplier",
"Configure peer detection multiplier\n"
@@ -287,7 +287,7 @@ void bfd_cli_show_mult(struct vty *vty, struct lyd_node *dnode,
yang_dnode_get_string(dnode, NULL));
}
-DEFPY(
+DEFPY_YANG(
bfd_peer_rx, bfd_peer_rx_cmd,
"receive-interval (10-60000)$interval",
"Configure peer receive interval\n"
@@ -316,7 +316,7 @@ void bfd_cli_show_rx(struct vty *vty, struct lyd_node *dnode,
}
}
-DEFPY(
+DEFPY_YANG(
bfd_peer_tx, bfd_peer_tx_cmd,
"transmit-interval (10-60000)$interval",
"Configure peer transmit interval\n"
@@ -345,7 +345,7 @@ void bfd_cli_show_tx(struct vty *vty, struct lyd_node *dnode,
}
}
-DEFPY(
+DEFPY_YANG(
bfd_peer_echo, bfd_peer_echo_cmd,
"[no] echo-mode",
NO_STR
@@ -366,7 +366,7 @@ void bfd_cli_show_echo(struct vty *vty, struct lyd_node *dnode,
yang_dnode_get_bool(dnode, NULL) ? "" : "no ");
}
-DEFPY(
+DEFPY_YANG(
bfd_peer_echo_interval, bfd_peer_echo_interval_cmd,
"echo-interval (10-60000)$interval",
"Configure peer echo interval\n"
@@ -398,7 +398,7 @@ void bfd_cli_show_echo_interval(struct vty *vty, struct lyd_node *dnode,
/*
* Profile commands.
*/
-DEFPY_NOSH(bfd_profile, bfd_profile_cmd,
+DEFPY_YANG_NOSH(bfd_profile, bfd_profile_cmd,
"profile WORD$name",
BFD_PROFILE_STR
BFD_PROFILE_NAME_STR)
@@ -419,7 +419,7 @@ DEFPY_NOSH(bfd_profile, bfd_profile_cmd,
return CMD_SUCCESS;
}
-DEFPY(no_bfd_profile, no_bfd_profile_cmd,
+DEFPY_YANG(no_bfd_profile, no_bfd_profile_cmd,
"no profile BFDPROF$name",
NO_STR
BFD_PROFILE_STR
@@ -442,37 +442,37 @@ void bfd_cli_show_profile(struct vty *vty, struct lyd_node *dnode,
vty_out(vty, " profile %s\n", yang_dnode_get_string(dnode, "./name"));
}
-ALIAS(bfd_peer_mult, bfd_profile_mult_cmd,
+ALIAS_YANG(bfd_peer_mult, bfd_profile_mult_cmd,
"detect-multiplier (2-255)$multiplier",
"Configure peer detection multiplier\n"
"Configure peer detection multiplier value\n")
-ALIAS(bfd_peer_tx, bfd_profile_tx_cmd,
+ALIAS_YANG(bfd_peer_tx, bfd_profile_tx_cmd,
"transmit-interval (10-60000)$interval",
"Configure peer transmit interval\n"
"Configure peer transmit interval value in milliseconds\n")
-ALIAS(bfd_peer_rx, bfd_profile_rx_cmd,
+ALIAS_YANG(bfd_peer_rx, bfd_profile_rx_cmd,
"receive-interval (10-60000)$interval",
"Configure peer receive interval\n"
"Configure peer receive interval value in milliseconds\n")
-ALIAS(bfd_peer_shutdown, bfd_profile_shutdown_cmd,
+ALIAS_YANG(bfd_peer_shutdown, bfd_profile_shutdown_cmd,
"[no] shutdown",
NO_STR
"Disable BFD peer\n")
-ALIAS(bfd_peer_echo, bfd_profile_echo_cmd,
+ALIAS_YANG(bfd_peer_echo, bfd_profile_echo_cmd,
"[no] echo-mode",
NO_STR
"Configure echo mode\n")
-ALIAS(bfd_peer_echo_interval, bfd_profile_echo_interval_cmd,
+ALIAS_YANG(bfd_peer_echo_interval, bfd_profile_echo_interval_cmd,
"echo-interval (10-60000)$interval",
"Configure peer echo interval\n"
"Configure peer echo interval value in milliseconds\n")
-DEFPY(bfd_peer_profile, bfd_peer_profile_cmd,
+DEFPY_YANG(bfd_peer_profile, bfd_peer_profile_cmd,
"[no] profile BFDPROF$pname",
NO_STR
"Use BFD profile settings\n"
diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c
index 08e50fc4f2..948055e375 100644
--- a/bgpd/bgp_attr.c
+++ b/bgpd/bgp_attr.c
@@ -718,6 +718,9 @@ bool attrhash_cmp(const void *p1, const void *p2)
&& IPV4_ADDR_SAME(&attr1->originator_id,
&attr2->originator_id)
&& overlay_index_same(attr1, attr2)
+ && !memcmp(&attr1->esi, &attr2->esi, sizeof(esi_t))
+ && attr1->es_flags == attr2->es_flags
+ && attr1->mm_sync_seqnum == attr2->mm_sync_seqnum
&& attr1->nh_ifindex == attr2->nh_ifindex
&& attr1->nh_lla_ifindex == attr2->nh_lla_ifindex
&& attr1->distance == attr2->distance
@@ -2186,6 +2189,7 @@ bgp_attr_ext_communities(struct bgp_attr_parser_args *args)
struct attr *const attr = args->attr;
const bgp_size_t length = args->length;
uint8_t sticky = 0;
+ bool proxy = false;
if (length == 0) {
attr->ecommunity = NULL;
@@ -2223,7 +2227,9 @@ bgp_attr_ext_communities(struct bgp_attr_parser_args *args)
attr->router_flag = 1;
/* Check EVPN Neighbor advertisement flags, R-bit */
- bgp_attr_evpn_na_flag(attr, &attr->router_flag);
+ bgp_attr_evpn_na_flag(attr, &attr->router_flag, &proxy);
+ if (proxy)
+ attr->es_flags |= ATTR_ES_PROXY_ADVERT;
/* Extract the Rmac, if any */
if (bgp_attr_rmac(attr, &attr->rmac)) {
diff --git a/bgpd/bgp_attr.h b/bgpd/bgp_attr.h
index 94531313ae..1b2c75fbef 100644
--- a/bgpd/bgp_attr.h
+++ b/bgpd/bgp_attr.h
@@ -215,6 +215,30 @@ struct attr {
/* NA router flag (R-bit) support in EVPN */
uint8_t router_flag;
+ /* ES info */
+ uint8_t es_flags;
+ /* Path is not "locally-active" on the advertising VTEP. This is
+ * translated into an ARP-ND ECOM.
+ */
+#define ATTR_ES_PROXY_ADVERT (1 << 0)
+ /* Destination ES is present locally. This flag is set on local
+ * paths and sync paths
+ */
+#define ATTR_ES_IS_LOCAL (1 << 1)
+ /* There are one or more non-best paths from ES peers. Note that
+ * this flag is only set on the local MAC-IP paths in the VNI
+ * route table (not set in the global routing table). And only
+ * non-proxy advertisements from an ES peer can result in this
+ * flag being set.
+ */
+#define ATTR_ES_PEER_ACTIVE (1 << 2)
+ /* There are one or more non-best proxy paths from ES peers */
+#define ATTR_ES_PEER_PROXY (1 << 3)
+ /* An ES peer has router bit set - only applicable if
+ * ATTR_ES_PEER_ACTIVE is set
+ */
+#define ATTR_ES_PEER_ROUTER (1 << 4)
+
/* route tag */
route_tag_t tag;
@@ -241,6 +265,13 @@ struct attr {
/* EVPN MAC Mobility sequence number, if any. */
uint32_t mm_seqnum;
+ /* highest MM sequence number rxed in a MAC-IP route from an
+ * ES peer (this includes both proxy and non-proxy MAC-IP
+ * advertisements from ES peers).
+ * This is only applicable to local paths in the VNI routing
+ * table and derived from other imported/non-best paths.
+ */
+ uint32_t mm_sync_seqnum;
/* EVPN local router-mac */
struct ethaddr rmac;
@@ -253,6 +284,9 @@ struct attr {
/* Link bandwidth value, if any. */
uint32_t link_bw;
+
+ /* EVPN ES */
+ esi_t esi;
};
/* rmap_change_flags definition */
diff --git a/bgpd/bgp_attr_evpn.c b/bgpd/bgp_attr_evpn.c
index 65072088ae..aa0c59f3a7 100644
--- a/bgpd/bgp_attr_evpn.c
+++ b/bgpd/bgp_attr_evpn.c
@@ -54,47 +54,27 @@ void bgp_add_routermac_ecom(struct attr *attr, struct ethaddr *routermac)
* format accepted: AA:BB:CC:DD:EE:FF:GG:HH:II:JJ
* if id is null, check only is done
*/
-bool str2esi(const char *str, struct eth_segment_id *id)
+bool str2esi(const char *str, esi_t *id)
{
- unsigned int a[ESI_LEN];
+ unsigned int a[ESI_BYTES];
int i;
if (!str)
return false;
if (sscanf(str, "%2x:%2x:%2x:%2x:%2x:%2x:%2x:%2x:%2x:%2x", a + 0, a + 1,
a + 2, a + 3, a + 4, a + 5, a + 6, a + 7, a + 8, a + 9)
- != ESI_LEN) {
+ != ESI_BYTES) {
/* error in incoming str length */
return false;
}
/* valid mac address */
if (!id)
return true;
- for (i = 0; i < ESI_LEN; ++i)
+ for (i = 0; i < ESI_BYTES; ++i)
id->val[i] = a[i] & 0xff;
return true;
}
-char *esi2str(struct eth_segment_id *id)
-{
- char *ptr;
- uint8_t *val;
-
- if (!id)
- return NULL;
-
- val = id->val;
- ptr = XMALLOC(MTYPE_TMP,
- (ESI_LEN * 2 + ESI_LEN - 1 + 1) * sizeof(char));
-
- snprintf(ptr, (ESI_LEN * 2 + ESI_LEN - 1 + 1),
- "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", val[0],
- val[1], val[2], val[3], val[4], val[5], val[6], val[7], val[8],
- val[9]);
-
- return ptr;
-}
-
char *ecom_mac2str(char *ecom_mac)
{
char *en;
@@ -215,7 +195,8 @@ uint32_t bgp_attr_mac_mobility_seqnum(struct attr *attr, uint8_t *sticky)
/*
* return true if attr contains router flag extended community
*/
-void bgp_attr_evpn_na_flag(struct attr *attr, uint8_t *router_flag)
+void bgp_attr_evpn_na_flag(struct attr *attr,
+ uint8_t *router_flag, bool *proxy)
{
struct ecommunity *ecom;
int i;
@@ -237,10 +218,14 @@ void bgp_attr_evpn_na_flag(struct attr *attr, uint8_t *router_flag)
if (type == ECOMMUNITY_ENCODE_EVPN &&
sub_type == ECOMMUNITY_EVPN_SUBTYPE_ND) {
val = *pnt++;
- if (val & ECOMMUNITY_EVPN_SUBTYPE_ND_ROUTER_FLAG) {
+
+ if (val & ECOMMUNITY_EVPN_SUBTYPE_ND_ROUTER_FLAG)
*router_flag = 1;
- break;
- }
+
+ if (val & ECOMMUNITY_EVPN_SUBTYPE_PROXY_FLAG)
+ *proxy = true;
+
+ break;
}
}
}
@@ -292,14 +277,3 @@ extern bool is_zero_gw_ip(const union gw_addr *gw_ip, const afi_t afi)
return false;
}
-
-extern bool is_zero_esi(const struct eth_segment_id *esi)
-{
- int i;
-
- for (i = 0; i < ESI_LEN; i++)
- if (esi->val[i])
- return false;
-
- return true;
-}
diff --git a/bgpd/bgp_attr_evpn.h b/bgpd/bgp_attr_evpn.h
index c1bfd83765..19c028a826 100644
--- a/bgpd/bgp_attr_evpn.h
+++ b/bgpd/bgp_attr_evpn.h
@@ -21,38 +21,20 @@
#ifndef _QUAGGA_BGP_ATTR_EVPN_H
#define _QUAGGA_BGP_ATTR_EVPN_H
-/* value of first byte of ESI */
-#define ESI_TYPE_ARBITRARY 0 /* */
-#define ESI_TYPE_LACP 1 /* <> */
-#define ESI_TYPE_BRIDGE 2 /* <Root bridge Mac-6B>:<Root Br Priority-2B>:00 */
-#define ESI_TYPE_MAC 3 /* <Syst Mac Add-6B>:<Local Discriminator Value-3B> */
-#define ESI_TYPE_ROUTER 4 /* <RouterId-4B>:<Local Discriminator Value-4B> */
-#define ESI_TYPE_AS 5 /* <AS-4B>:<Local Discriminator Value-4B> */
-
-#define MAX_ESI {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff}
-#define ESI_LEN 10
-
#define MAX_ET 0xffffffff
struct attr;
-/* EVPN ESI */
-struct eth_segment_id {
- uint8_t val[ESI_LEN];
-};
-
union gw_addr {
struct in_addr ipv4;
struct in6_addr ipv6;
};
struct bgp_route_evpn {
- struct eth_segment_id eth_s_id;
union gw_addr gw_ip;
};
-extern bool str2esi(const char *str, struct eth_segment_id *id);
-extern char *esi2str(struct eth_segment_id *id);
+extern bool str2esi(const char *str, esi_t *id);
extern char *ecom_mac2str(char *ecom_mac);
extern void bgp_add_routermac_ecom(struct attr *attr,
@@ -64,9 +46,9 @@ extern uint32_t bgp_attr_mac_mobility_seqnum(struct attr *attr,
uint8_t *sticky);
extern uint8_t bgp_attr_default_gw(struct attr *attr);
-extern void bgp_attr_evpn_na_flag(struct attr *attr, uint8_t *router_flag);
+extern void bgp_attr_evpn_na_flag(struct attr *attr, uint8_t *router_flag,
+ bool *proxy);
extern bool is_zero_gw_ip(const union gw_addr *gw_ip, afi_t afi);
-extern bool is_zero_esi(const struct eth_segment_id *esi);
#endif /* _QUAGGA_BGP_ATTR_EVPN_H */
diff --git a/bgpd/bgp_bfd.c b/bgpd/bgp_bfd.c
index ba57db61cb..67b8018c8e 100644
--- a/bgpd/bgp_bfd.c
+++ b/bgpd/bgp_bfd.c
@@ -486,7 +486,7 @@ static int bgp_bfd_peer_param_set(struct peer *peer, uint32_t min_rx,
int command = 0;
bfd_set_param((struct bfd_info **)&(peer->bfd_info), min_rx, min_tx,
- detect_mult, defaults, &command);
+ detect_mult, NULL, defaults, &command);
/* This command overrides profile if it was previously applied. */
bi = peer->bfd_info;
@@ -497,8 +497,8 @@ static int bgp_bfd_peer_param_set(struct peer *peer, uint32_t min_rx,
for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
command = 0;
bfd_set_param((struct bfd_info **)&(peer->bfd_info),
- min_rx, min_tx, detect_mult, defaults,
- &command);
+ min_rx, min_tx, detect_mult, NULL,
+ defaults, &command);
/*
* This command overrides profile if it was previously
@@ -564,7 +564,7 @@ static int bgp_bfd_peer_param_type_set(struct peer *peer,
if (!peer->bfd_info)
bfd_set_param((struct bfd_info **)&(peer->bfd_info),
BFD_DEF_MIN_RX, BFD_DEF_MIN_TX,
- BFD_DEF_DETECT_MULT, 1, &command);
+ BFD_DEF_DETECT_MULT, NULL, 1, &command);
bfd_info = (struct bfd_info *)peer->bfd_info;
bfd_info->type = type;
@@ -577,7 +577,7 @@ static int bgp_bfd_peer_param_type_set(struct peer *peer,
bfd_set_param(
(struct bfd_info **)&(peer->bfd_info),
BFD_DEF_MIN_RX, BFD_DEF_MIN_TX,
- BFD_DEF_DETECT_MULT, 1, &command);
+ BFD_DEF_DETECT_MULT, NULL, 1, &command);
bfd_info = (struct bfd_info *)peer->bfd_info;
bfd_info->type = type;
@@ -612,7 +612,7 @@ static int bgp_bfd_peer_set_profile(struct peer *peer, const char *profile)
struct bfd_info *bfd_info;
bfd_set_param((struct bfd_info **)&(peer->bfd_info), BFD_DEF_MIN_RX,
- BFD_DEF_MIN_TX, BFD_DEF_DETECT_MULT, 1, &command);
+ BFD_DEF_MIN_TX, BFD_DEF_DETECT_MULT, NULL, 1, &command);
bfd_info = (struct bfd_info *)peer->bfd_info;
@@ -628,7 +628,7 @@ static int bgp_bfd_peer_set_profile(struct peer *peer, const char *profile)
command = 0;
bfd_set_param((struct bfd_info **)&(peer->bfd_info),
BFD_DEF_MIN_RX, BFD_DEF_MIN_TX,
- BFD_DEF_DETECT_MULT, 1, &command);
+ BFD_DEF_DETECT_MULT, NULL, 1, &command);
bfd_info = (struct bfd_info *)peer->bfd_info;
diff --git a/bgpd/bgp_bmp.c b/bgpd/bgp_bmp.c
index db330f998c..af88547ca9 100644
--- a/bgpd/bgp_bmp.c
+++ b/bgpd/bgp_bmp.c
@@ -951,8 +951,11 @@ afibreak:
/* initialize syncrdpos to the first
* mid-layer table entry
*/
- if (!bmp->syncrdpos)
+ if (!bmp->syncrdpos) {
bmp->syncrdpos = bgp_table_top(table);
+ if (!bmp->syncrdpos)
+ goto eor;
+ }
/* look for a valid mid-layer table */
do {
diff --git a/bgpd/bgp_damp.c b/bgpd/bgp_damp.c
index 97d625493f..565d0b8e19 100644
--- a/bgpd/bgp_damp.c
+++ b/bgpd/bgp_damp.c
@@ -50,6 +50,12 @@ static int bgp_reuse_index(int penalty, struct bgp_damp_config *bdc)
unsigned int i;
int index;
+ /*
+ * reuse_limit can't be zero, this is for Coverity
+ * to bypass division by zero test.
+ */
+ assert(bdc->reuse_limit);
+
i = (int)(((double)penalty / bdc->reuse_limit - 1.0)
* bdc->scale_factor);
diff --git a/bgpd/bgp_debug.c b/bgpd/bgp_debug.c
index 2ca9e5ee13..255a7f238b 100644
--- a/bgpd/bgp_debug.c
+++ b/bgpd/bgp_debug.c
@@ -64,6 +64,7 @@ unsigned long conf_bgp_debug_flowspec;
unsigned long conf_bgp_debug_labelpool;
unsigned long conf_bgp_debug_pbr;
unsigned long conf_bgp_debug_graceful_restart;
+unsigned long conf_bgp_debug_evpn_mh;
unsigned long term_bgp_debug_as4;
unsigned long term_bgp_debug_neighbor_events;
@@ -82,6 +83,7 @@ unsigned long term_bgp_debug_flowspec;
unsigned long term_bgp_debug_labelpool;
unsigned long term_bgp_debug_pbr;
unsigned long term_bgp_debug_graceful_restart;
+unsigned long term_bgp_debug_evpn_mh;
struct list *bgp_debug_neighbor_events_peers = NULL;
struct list *bgp_debug_keepalive_peers = NULL;
@@ -2006,6 +2008,57 @@ DEFUN (no_debug_bgp_pbr,
return CMD_SUCCESS;
}
+DEFPY (debug_bgp_evpn_mh,
+ debug_bgp_evpn_mh_cmd,
+ "[no$no] debug bgp evpn mh <es$es|route$rt>",
+ NO_STR
+ DEBUG_STR
+ BGP_STR
+ "EVPN\n"
+ "Multihoming\n"
+ "Ethernet Segment debugging\n"
+ "Route debugging\n")
+{
+ if (es) {
+ if (vty->node == CONFIG_NODE) {
+ if (no)
+ DEBUG_OFF(evpn_mh, EVPN_MH_ES);
+ else
+ DEBUG_ON(evpn_mh, EVPN_MH_ES);
+ } else {
+ if (no) {
+ TERM_DEBUG_OFF(evpn_mh, EVPN_MH_ES);
+ vty_out(vty,
+ "BGP EVPN-MH ES debugging is off\n");
+ } else {
+ TERM_DEBUG_ON(evpn_mh, EVPN_MH_ES);
+ vty_out(vty,
+ "BGP EVPN-MH ES debugging is on\n");
+ }
+ }
+ }
+ if (rt) {
+ if (vty->node == CONFIG_NODE) {
+ if (no)
+ DEBUG_OFF(evpn_mh, EVPN_MH_RT);
+ else
+ DEBUG_ON(evpn_mh, EVPN_MH_RT);
+ } else {
+ if (no) {
+ TERM_DEBUG_OFF(evpn_mh, EVPN_MH_RT);
+ vty_out(vty,
+ "BGP EVPN-MH route debugging is off\n");
+ } else {
+ TERM_DEBUG_ON(evpn_mh, EVPN_MH_RT);
+ vty_out(vty,
+ "BGP EVPN-MH route debugging is on\n");
+ }
+ }
+ }
+
+ return CMD_SUCCESS;
+}
+
DEFUN (debug_bgp_labelpool,
debug_bgp_labelpool_cmd,
"debug bgp labelpool",
@@ -2085,6 +2138,8 @@ DEFUN (no_debug_bgp,
TERM_DEBUG_OFF(pbr, PBR);
TERM_DEBUG_OFF(pbr, PBR_ERROR);
TERM_DEBUG_OFF(graceful_restart, GRACEFUL_RESTART);
+ TERM_DEBUG_OFF(evpn_mh, EVPN_MH_ES);
+ TERM_DEBUG_OFF(evpn_mh, EVPN_MH_RT);
vty_out(vty, "All possible debugging has been turned off\n");
@@ -2144,7 +2199,7 @@ DEFUN_NOSH (show_debugging_bgp,
bgp_debug_zebra_prefixes);
if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
- vty_out(vty, " BGP graceful-restart debugging is on");
+ vty_out(vty, " BGP graceful-restart debugging is on\n");
if (BGP_DEBUG(allow_martians, ALLOW_MARTIANS))
vty_out(vty, " BGP allow martian next hop debugging is on\n");
@@ -2169,6 +2224,11 @@ DEFUN_NOSH (show_debugging_bgp,
if (BGP_DEBUG(pbr, PBR_ERROR))
vty_out(vty, " BGP policy based routing error debugging is on\n");
+ if (BGP_DEBUG(evpn_mh, EVPN_MH_ES))
+ vty_out(vty, " BGP EVPN-MH ES debugging is on\n");
+ if (BGP_DEBUG(evpn_mh, EVPN_MH_RT))
+ vty_out(vty, " BGP EVPN-MH route debugging is on\n");
+
vty_out(vty, "\n");
return CMD_SUCCESS;
}
@@ -2284,6 +2344,16 @@ static int bgp_config_write_debug(struct vty *vty)
vty_out(vty, "debug bgp graceful-restart\n");
write++;
}
+
+ if (CONF_BGP_DEBUG(evpn_mh, EVPN_MH_ES)) {
+ vty_out(vty, "debug bgp evpn mh es\n");
+ write++;
+ }
+ if (CONF_BGP_DEBUG(evpn_mh, EVPN_MH_RT)) {
+ vty_out(vty, "debug bgp evpn mh route\n");
+ write++;
+ }
+
return write;
}
@@ -2410,6 +2480,8 @@ void bgp_debug_init(void)
install_element(ENABLE_NODE, &no_debug_bgp_pbr_cmd);
install_element(CONFIG_NODE, &no_debug_bgp_pbr_cmd);
+ install_element(ENABLE_NODE, &debug_bgp_evpn_mh_cmd);
+ install_element(CONFIG_NODE, &debug_bgp_evpn_mh_cmd);
}
/* Return true if this prefix is on the per_prefix_list of prefixes to debug
diff --git a/bgpd/bgp_debug.h b/bgpd/bgp_debug.h
index 69f25566a9..f16cfee4f2 100644
--- a/bgpd/bgp_debug.h
+++ b/bgpd/bgp_debug.h
@@ -77,6 +77,7 @@ extern unsigned long conf_bgp_debug_flowspec;
extern unsigned long conf_bgp_debug_labelpool;
extern unsigned long conf_bgp_debug_pbr;
extern unsigned long conf_bgp_debug_graceful_restart;
+extern unsigned long conf_bgp_debug_evpn_mh;
extern unsigned long term_bgp_debug_as4;
extern unsigned long term_bgp_debug_neighbor_events;
@@ -93,6 +94,7 @@ extern unsigned long term_bgp_debug_flowspec;
extern unsigned long term_bgp_debug_labelpool;
extern unsigned long term_bgp_debug_pbr;
extern unsigned long term_bgp_debug_graceful_restart;
+extern unsigned long term_bgp_debug_evpn_mh;
extern struct list *bgp_debug_neighbor_events_peers;
extern struct list *bgp_debug_keepalive_peers;
@@ -129,6 +131,8 @@ struct bgp_debug_filter {
#define BGP_DEBUG_LABELPOOL 0x01
#define BGP_DEBUG_PBR 0x01
#define BGP_DEBUG_PBR_ERROR 0x02
+#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
diff --git a/bgpd/bgp_ecommunity.c b/bgpd/bgp_ecommunity.c
index d6c311bfa0..f2aac3646c 100644
--- a/bgpd/bgp_ecommunity.c
+++ b/bgpd/bgp_ecommunity.c
@@ -810,6 +810,35 @@ char *ecommunity_ecom2str(struct ecommunity *ecom, int format, int filter)
ECOMMUNITY_EVPN_SUBTYPE_ND_ROUTER_FLAG))
strlcpy(encbuf, "ND:Router Flag",
sizeof(encbuf));
+ if (CHECK_FLAG(
+ flags,
+ ECOMMUNITY_EVPN_SUBTYPE_PROXY_FLAG))
+ strlcpy(encbuf, "ND:Proxy",
+ sizeof(encbuf));
+ } else if (*pnt
+ == ECOMMUNITY_EVPN_SUBTYPE_ES_IMPORT_RT) {
+ struct ethaddr mac;
+
+ pnt++;
+ memcpy(&mac, pnt, ETH_ALEN);
+ snprintf(encbuf,
+ sizeof(encbuf),
+ "ES-Import-Rt:%02x:%02x:%02x:%02x:%02x:%02x",
+ (uint8_t)mac.octet[0],
+ (uint8_t)mac.octet[1],
+ (uint8_t)mac.octet[2],
+ (uint8_t)mac.octet[3],
+ (uint8_t)mac.octet[4],
+ (uint8_t)mac.octet[5]);
+ } else if (*pnt
+ == ECOMMUNITY_EVPN_SUBTYPE_ESI_LABEL) {
+ uint8_t flags = *++pnt;
+
+ snprintf(encbuf,
+ sizeof(encbuf), "ESI-label-Rt:%s",
+ (flags &
+ ECOMMUNITY_EVPN_SUBTYPE_ESI_SA_FLAG) ?
+ "SA":"AA");
} else
unk_ecom = 1;
} else if (type == ECOMMUNITY_ENCODE_REDIRECT_IP_NH) {
@@ -865,21 +894,6 @@ char *ecommunity_ecom2str(struct ecommunity *ecom, int format, int filter)
} else if (sub_type == ECOMMUNITY_TRAFFIC_MARKING) {
snprintf(encbuf, sizeof(encbuf),
"FS:marking %u", *(pnt + 5));
- } else if (*pnt
- == ECOMMUNITY_EVPN_SUBTYPE_ES_IMPORT_RT) {
- struct ethaddr mac;
-
- memcpy(&mac, pnt, ETH_ALEN);
-
- snprintf(
- encbuf, sizeof(encbuf),
- "ES-Import-Rt:%02x:%02x:%02x:%02x:%02x:%02x",
- (uint8_t)mac.octet[0],
- (uint8_t)mac.octet[1],
- (uint8_t)mac.octet[2],
- (uint8_t)mac.octet[3],
- (uint8_t)mac.octet[4],
- (uint8_t)mac.octet[5]);
} else
unk_ecom = 1;
} else if (type == ECOMMUNITY_ENCODE_AS_NON_TRANS) {
diff --git a/bgpd/bgp_ecommunity.h b/bgpd/bgp_ecommunity.h
index 7deae8e746..812bcc46e7 100644
--- a/bgpd/bgp_ecommunity.h
+++ b/bgpd/bgp_ecommunity.h
@@ -73,8 +73,12 @@
#define ECOMMUNITY_EVPN_SUBTYPE_ND 0x08
#define ECOMMUNITY_EVPN_SUBTYPE_MACMOBILITY_FLAG_STICKY 0x01
-#define ECOMMUNITY_EVPN_SUBTYPE_ND_ROUTER_FLAG 0x01
-#define ECOMMUNITY_EVPN_SUBTYPE_ND_OVERRIDE_FLAG 0x02
+
+#define ECOMMUNITY_EVPN_SUBTYPE_ND_ROUTER_FLAG 0x01
+#define ECOMMUNITY_EVPN_SUBTYPE_ND_OVERRIDE_FLAG 0x02
+#define ECOMMUNITY_EVPN_SUBTYPE_PROXY_FLAG 0x04
+
+#define ECOMMUNITY_EVPN_SUBTYPE_ESI_SA_FLAG (1 << 0) /* single-active */
/* Low-order octet of the Extended Communities type field for OPAQUE types */
#define ECOMMUNITY_OPAQUE_SUBTYPE_ENCAP 0x0c
diff --git a/bgpd/bgp_evpn.c b/bgpd/bgp_evpn.c
index 8c5d6421f1..4a5d5c3b6e 100644
--- a/bgpd/bgp_evpn.c
+++ b/bgpd/bgp_evpn.c
@@ -40,6 +40,7 @@
#include "bgpd/bgp_label.h"
#include "bgpd/bgp_evpn.h"
#include "bgpd/bgp_evpn_private.h"
+#include "bgpd/bgp_evpn_mh.h"
#include "bgpd/bgp_ecommunity.h"
#include "bgpd/bgp_encap_types.h"
#include "bgpd/bgp_debug.h"
@@ -54,61 +55,24 @@
/*
* Definitions and external declarations.
*/
-extern struct zclient *zclient;
-
DEFINE_QOBJ_TYPE(bgpevpn)
-DEFINE_QOBJ_TYPE(evpnes)
+DEFINE_QOBJ_TYPE(bgp_evpn_es)
/*
* Static function declarations
*/
-static void delete_evpn_route_entry(struct bgp *bgp, afi_t afi, safi_t safi,
- struct bgp_dest *dest,
- struct bgp_path_info **pi);
static int delete_all_vni_routes(struct bgp *bgp, struct bgpevpn *vpn);
+static void bgp_evpn_update_type2_route_entry(struct bgp *bgp,
+ struct bgpevpn *vpn,
+ struct bgp_node *rn, struct bgp_path_info *local_pi,
+ const char *caller);
+static struct in_addr zero_vtep_ip;
/*
* Private functions.
*/
-/* compare two IPV4 VTEP IPs */
-static int evpn_vtep_ip_cmp(void *p1, void *p2)
-{
- const struct in_addr *ip1 = p1;
- const struct in_addr *ip2 = p2;
-
- return ip1->s_addr - ip2->s_addr;
-}
-
-/*
- * Make hash key for ESI.
- */
-static unsigned int esi_hash_keymake(const void *p)
-{
- const struct evpnes *pes = p;
- const void *pnt = (void *)pes->esi.val;
-
- return jhash(pnt, ESI_BYTES, 0xa5a5a55a);
-}
-
-/*
- * Compare two ESIs.
- */
-static bool esi_cmp(const void *p1, const void *p2)
-{
- const struct evpnes *pes1 = p1;
- const struct evpnes *pes2 = p2;
-
- if (pes1 == NULL && pes2 == NULL)
- return true;
-
- if (pes1 == NULL || pes2 == NULL)
- return false;
-
- return (memcmp(pes1->esi.val, pes2->esi.val, ESI_BYTES) == 0);
-}
-
/*
* Make vni hash key.
*/
@@ -133,7 +97,7 @@ static bool vni_hash_cmp(const void *p1, const void *p2)
return (vpn1->vni == vpn2->vni);
}
-static int vni_list_cmp(void *p1, void *p2)
+int vni_list_cmp(void *p1, void *p2)
{
const struct bgpevpn *vpn1 = p1;
const struct bgpevpn *vpn2 = p2;
@@ -579,19 +543,54 @@ static void evpn_convert_nexthop_to_ipv6(struct attr *attr)
attr->mp_nexthop_len = IPV6_MAX_BYTELEN;
}
+struct bgp_node *bgp_global_evpn_node_get(
+ struct bgp_table *table, afi_t afi,
+ safi_t safi, const struct prefix_evpn *evp,
+ struct prefix_rd *prd)
+{
+ struct prefix_evpn global_p;
+
+ if (evp->prefix.route_type == BGP_EVPN_AD_ROUTE) {
+ /* prefix in the global table doesn't include the VTEP-IP so
+ * we need to create a different copy of the prefix
+ */
+ evpn_type1_prefix_global_copy(&global_p, evp);
+ evp = &global_p;
+ }
+ return bgp_afi_node_get(table, afi, safi, (struct prefix *)evp, prd);
+}
+
+struct bgp_node *bgp_global_evpn_node_lookup(
+ struct bgp_table *table, afi_t afi,
+ safi_t safi, const struct prefix_evpn *evp,
+ struct prefix_rd *prd)
+{
+ struct prefix_evpn global_p;
+
+ if (evp->prefix.route_type == BGP_EVPN_AD_ROUTE) {
+ /* prefix in the global table doesn't include the VTEP-IP so
+ * we need to create a different copy of the prefix
+ */
+ evpn_type1_prefix_global_copy(&global_p, evp);
+ evp = &global_p;
+ }
+ return bgp_afi_node_lookup(table, afi, safi, (struct prefix *)evp, prd);
+}
+
/*
* Add (update) or delete MACIP from zebra.
*/
static int bgp_zebra_send_remote_macip(struct bgp *bgp, struct bgpevpn *vpn,
const struct prefix_evpn *p,
struct in_addr remote_vtep_ip, int add,
- uint8_t flags, uint32_t seq)
+ uint8_t flags, uint32_t seq, esi_t *esi)
{
struct stream *s;
int ipa_len;
char buf1[ETHER_ADDR_STRLEN];
char buf2[INET6_ADDRSTRLEN];
char buf3[INET6_ADDRSTRLEN];
+ static struct in_addr zero_remote_vtep_ip;
/* Check socket. */
if (!zclient || zclient->sock < 0)
@@ -605,6 +604,9 @@ static int bgp_zebra_send_remote_macip(struct bgp *bgp, struct bgpevpn *vpn,
__func__);
return 0;
}
+
+ if (!esi)
+ esi = zero_esi;
s = zclient->obuf;
stream_reset(s);
@@ -622,13 +624,20 @@ static int bgp_zebra_send_remote_macip(struct bgp *bgp, struct bgpevpn *vpn,
stream_putl(s, ipa_len);
stream_put(s, &p->prefix.macip_addr.ip.ip.addr, ipa_len);
}
- stream_put_in_addr(s, &remote_vtep_ip);
+ /* If the ESI is valid that becomes the nexthop; tape out the
+ * VTEP-IP for that case
+ */
+ if (bgp_evpn_is_esi_valid(esi))
+ stream_put_in_addr(s, &zero_remote_vtep_ip);
+ else
+ stream_put_in_addr(s, &remote_vtep_ip);
/* TX flags - MAC sticky status and/or gateway mac */
/* Also TX the sequence number of the best route. */
if (add) {
stream_putc(s, flags);
stream_putl(s, seq);
+ stream_put(s, esi, sizeof(esi_t));
}
stream_putw_at(s, 0, stream_get_endp(s));
@@ -698,40 +707,6 @@ static int bgp_zebra_send_remote_vtep(struct bgp *bgp, struct bgpevpn *vpn,
}
/*
- * Build extended community for EVPN ES (type-4) route
- */
-static void build_evpn_type4_route_extcomm(struct evpnes *es,
- struct attr *attr)
-{
- struct ecommunity ecom_encap;
- struct ecommunity ecom_es_rt;
- struct ecommunity_val eval;
- struct ecommunity_val eval_es_rt;
- bgp_encap_types tnl_type;
- struct ethaddr mac;
-
- /* Encap */
- tnl_type = BGP_ENCAP_TYPE_VXLAN;
- memset(&ecom_encap, 0, sizeof(ecom_encap));
- encode_encap_extcomm(tnl_type, &eval);
- ecom_encap.size = 1;
- ecom_encap.val = (uint8_t *)eval.val;
- attr->ecommunity = ecommunity_dup(&ecom_encap);
-
- /* ES import RT */
- memset(&mac, 0, sizeof(struct ethaddr));
- memset(&ecom_es_rt, 0, sizeof(ecom_es_rt));
- es_get_system_mac(&es->esi, &mac);
- encode_es_rt_extcomm(&eval_es_rt, &mac);
- ecom_es_rt.size = 1;
- ecom_es_rt.val = (uint8_t *)eval_es_rt.val;
- attr->ecommunity =
- ecommunity_merge(attr->ecommunity, &ecom_es_rt);
-
- attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES);
-}
-
-/*
* Build extended communities for EVPN prefix route.
*/
static void build_evpn_type5_route_extcomm(struct bgp *bgp_vrf,
@@ -800,6 +775,7 @@ static void build_evpn_route_extcomm(struct bgpevpn *vpn, struct attr *attr,
struct ecommunity_val eval_default_gw;
struct ecommunity_val eval_rmac;
struct ecommunity_val eval_na;
+ bool proxy;
bgp_encap_types tnl_type;
struct listnode *node, *nnode;
@@ -861,9 +837,10 @@ static void build_evpn_route_extcomm(struct bgpevpn *vpn, struct attr *attr,
ecommunity_merge(attr->ecommunity, &ecom_default_gw);
}
- if (attr->router_flag) {
+ proxy = !!(attr->es_flags & ATTR_ES_PROXY_ADVERT);
+ if (attr->router_flag || proxy) {
memset(&ecom_na, 0, sizeof(ecom_na));
- encode_na_flag_extcomm(&eval_na, attr->router_flag);
+ encode_na_flag_extcomm(&eval_na, attr->router_flag, proxy);
ecom_na.size = 1;
ecom_na.val = (uint8_t *)eval_na.val;
attr->ecommunity = ecommunity_merge(attr->ecommunity,
@@ -934,19 +911,60 @@ static int evpn_zebra_install(struct bgp *bgp, struct bgpevpn *vpn,
int ret;
uint8_t flags;
int flood_control;
+ uint32_t seq;
if (p->prefix.route_type == BGP_EVPN_MAC_IP_ROUTE) {
flags = 0;
- if (pi->attr->sticky)
- SET_FLAG(flags, ZEBRA_MACIP_TYPE_STICKY);
- if (pi->attr->default_gw)
- SET_FLAG(flags, ZEBRA_MACIP_TYPE_GW);
- if (is_evpn_prefix_ipaddr_v6(p) &&
- pi->attr->router_flag)
- SET_FLAG(flags, ZEBRA_MACIP_TYPE_ROUTER_FLAG);
+
+ if (pi->sub_type == BGP_ROUTE_IMPORTED) {
+ if (pi->attr->sticky)
+ SET_FLAG(flags, ZEBRA_MACIP_TYPE_STICKY);
+ if (pi->attr->default_gw)
+ SET_FLAG(flags, ZEBRA_MACIP_TYPE_GW);
+ if (is_evpn_prefix_ipaddr_v6(p) &&
+ pi->attr->router_flag)
+ SET_FLAG(flags, ZEBRA_MACIP_TYPE_ROUTER_FLAG);
+
+ seq = mac_mobility_seqnum(pi->attr);
+ /* if local ES notify zebra that this is a sync path */
+ if (bgp_evpn_attr_is_local_es(pi->attr)) {
+ SET_FLAG(flags, ZEBRA_MACIP_TYPE_SYNC_PATH);
+ if (bgp_evpn_attr_is_proxy(pi->attr))
+ SET_FLAG(flags,
+ ZEBRA_MACIP_TYPE_PROXY_ADVERT);
+ }
+ } else {
+ if (!bgp_evpn_attr_is_sync(pi->attr))
+ return 0;
+
+ /* if a local path is being turned around and sent
+ * to zebra it is because it is a sync path on
+ * a local ES
+ */
+ SET_FLAG(flags, ZEBRA_MACIP_TYPE_SYNC_PATH);
+ /* supply the highest peer seq number to zebra
+ * for MM seq syncing
+ */
+ seq = bgp_evpn_attr_get_sync_seq(pi->attr);
+ /* if any of the paths from the peer have the ROUTER
+ * flag set install the local entry as a router entry
+ */
+ if (is_evpn_prefix_ipaddr_v6(p) &&
+ (pi->attr->es_flags &
+ ATTR_ES_PEER_ROUTER))
+ SET_FLAG(flags,
+ ZEBRA_MACIP_TYPE_ROUTER_FLAG);
+
+ if (!(pi->attr->es_flags & ATTR_ES_PEER_ACTIVE))
+ SET_FLAG(flags,
+ ZEBRA_MACIP_TYPE_PROXY_ADVERT);
+ }
+
ret = bgp_zebra_send_remote_macip(
- bgp, vpn, p, pi->attr->nexthop, 1, flags,
- mac_mobility_seqnum(pi->attr));
+ bgp, vpn, p, pi->attr->nexthop, 1, flags,
+ seq, bgp_evpn_attr_get_esi(pi->attr));
+ } else if (p->prefix.route_type == BGP_EVPN_AD_ROUTE) {
+ ret = bgp_evpn_remote_es_evi_add(bgp, vpn, p);
} else {
switch (pi->attr->pmsi_tnl_type) {
case PMSI_TNLTYPE_INGR_REPL:
@@ -976,7 +994,9 @@ static int evpn_zebra_uninstall(struct bgp *bgp, struct bgpevpn *vpn,
if (p->prefix.route_type == BGP_EVPN_MAC_IP_ROUTE)
ret = bgp_zebra_send_remote_macip(bgp, vpn, p, remote_vtep_ip,
- 0, 0, 0);
+ 0, 0, 0, NULL);
+ else if (p->prefix.route_type == BGP_EVPN_AD_ROUTE)
+ ret = bgp_evpn_remote_es_evi_del(bgp, vpn, p);
else
ret = bgp_zebra_send_remote_vtep(bgp, vpn, p,
VXLAN_FLOOD_DISABLED, 0);
@@ -991,19 +1011,36 @@ static int evpn_zebra_uninstall(struct bgp *bgp, struct bgpevpn *vpn,
*/
static void evpn_delete_old_local_route(struct bgp *bgp, struct bgpevpn *vpn,
struct bgp_dest *dest,
- struct bgp_path_info *old_local)
+ struct bgp_path_info *old_local,
+ struct bgp_path_info *new_select)
{
struct bgp_dest *global_dest;
struct bgp_path_info *pi;
afi_t afi = AFI_L2VPN;
safi_t safi = SAFI_EVPN;
+ if (BGP_DEBUG(evpn_mh, EVPN_MH_RT)) {
+ char prefix_buf[PREFIX_STRLEN];
+ char esi_buf[ESI_STR_LEN];
+ char esi_buf2[ESI_STR_LEN];
+ struct prefix_evpn *evp = (struct prefix_evpn *)&dest->p;
+
+ zlog_debug("local path deleted %s es %s; new-path-es %s",
+ prefix2str(evp,
+ prefix_buf, sizeof(prefix_buf)),
+ esi_to_str(&old_local->attr->esi,
+ esi_buf, sizeof(esi_buf)),
+ new_select ? esi_to_str(&new_select->attr->esi,
+ esi_buf2, sizeof(esi_buf2)) : "");
+ }
+
/* Locate route node in the global EVPN routing table. Note that
* this table is a 2-level tree (RD-level + Prefix-level) similar to
* L3VPN routes.
*/
- global_dest = bgp_afi_node_lookup(bgp->rib[afi][safi], afi, safi,
- bgp_dest_get_prefix(dest), &vpn->prd);
+ global_dest = bgp_global_evpn_node_lookup(bgp->rib[afi][safi], afi, safi,
+ (const struct prefix_evpn *)bgp_dest_get_prefix(dest),
+ &vpn->prd);
if (global_dest) {
/* Delete route entry in the global EVPN table. */
delete_evpn_route_entry(bgp, afi, safi, global_dest, &pi);
@@ -1020,172 +1057,12 @@ static void evpn_delete_old_local_route(struct bgp *bgp, struct bgpevpn *vpn,
bgp_path_info_delete(dest, old_local);
}
-static struct in_addr *es_vtep_new(struct in_addr vtep)
-{
- struct in_addr *ip;
-
- ip = XCALLOC(MTYPE_BGP_EVPN_ES_VTEP, sizeof(struct in_addr));
-
- ip->s_addr = vtep.s_addr;
- return ip;
-}
-
-static void es_vtep_free(struct in_addr *ip)
-{
- XFREE(MTYPE_BGP_EVPN_ES_VTEP, ip);
-}
-
-/* check if VTEP is already part of the list */
-static int is_vtep_present_in_list(struct list *list,
- struct in_addr vtep)
-{
- struct listnode *node = NULL;
- struct in_addr *tmp;
-
- for (ALL_LIST_ELEMENTS_RO(list, node, tmp)) {
- if (tmp->s_addr == vtep.s_addr)
- return 1;
- }
- return 0;
-}
-
-/*
- * Best path for ES route was changed,
- * update the list of VTEPs for this ES
- */
-static int evpn_es_install_vtep(struct bgp *bgp, struct evpnes *es,
- const struct prefix_evpn *p,
- struct in_addr rvtep)
-{
- struct in_addr *vtep_ip;
-
- if (is_vtep_present_in_list(es->vtep_list, rvtep))
- return 0;
-
-
- vtep_ip = es_vtep_new(rvtep);
- if (vtep_ip)
- listnode_add_sort(es->vtep_list, vtep_ip);
- return 0;
-}
-
-/*
- * Best path for ES route was changed,
- * update the list of VTEPs for this ES
- */
-static int evpn_es_uninstall_vtep(struct bgp *bgp,
- struct evpnes *es,
- struct prefix_evpn *p,
- struct in_addr rvtep)
-{
- struct listnode *node, *nnode, *node_to_del = NULL;
- struct in_addr *tmp;
-
- for (ALL_LIST_ELEMENTS(es->vtep_list, node, nnode, tmp)) {
- if (tmp->s_addr == rvtep.s_addr) {
- es_vtep_free(tmp);
- node_to_del = node;
- }
- }
-
- if (node_to_del)
- list_delete_node(es->vtep_list, node_to_del);
-
- return 0;
-}
-
-/*
- * Calculate the best path for a ES(type-4) route.
- */
-static int evpn_es_route_select_install(struct bgp *bgp, struct evpnes *es,
- struct bgp_dest *dest)
-{
- int ret = 0;
- afi_t afi = AFI_L2VPN;
- safi_t safi = SAFI_EVPN;
- struct bgp_path_info *old_select; /* old best */
- struct bgp_path_info *new_select; /* new best */
- struct bgp_path_info_pair old_and_new;
-
- /* Compute the best path. */
- bgp_best_selection(bgp, dest, &bgp->maxpaths[afi][safi], &old_and_new,
- afi, safi);
- old_select = old_and_new.old;
- new_select = old_and_new.new;
-
- /*
- * If the best path hasn't changed - see if something needs to be
- * updated
- */
- if (old_select && old_select == new_select
- && old_select->type == ZEBRA_ROUTE_BGP
- && old_select->sub_type == BGP_ROUTE_IMPORTED
- && !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 (bgp_zebra_has_route_changed(old_select)) {
- ret = evpn_es_install_vtep(
- bgp, es,
- (const struct prefix_evpn *)bgp_dest_get_prefix(
- dest),
- old_select->attr->nexthop);
- }
- UNSET_FLAG(old_select->flags, BGP_PATH_MULTIPATH_CHG);
- UNSET_FLAG(old_select->flags, BGP_PATH_LINK_BW_CHG);
- bgp_zebra_clear_route_change_flags(dest);
- return ret;
- }
-
- /* If the user did a "clear" this flag will be set */
- UNSET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
-
- /*
- * bestpath has changed; update relevant fields and install or uninstall
- * into the zebra RIB.
- */
- if (old_select || new_select)
- bgp_bump_version(dest);
-
- if (old_select)
- bgp_path_info_unset_flag(dest, old_select, BGP_PATH_SELECTED);
- if (new_select) {
- bgp_path_info_set_flag(dest, new_select, BGP_PATH_SELECTED);
- bgp_path_info_unset_flag(dest, new_select,
- BGP_PATH_ATTR_CHANGED);
- UNSET_FLAG(new_select->flags, BGP_PATH_MULTIPATH_CHG);
- UNSET_FLAG(new_select->flags, BGP_PATH_LINK_BW_CHG);
- }
-
- if (new_select && new_select->type == ZEBRA_ROUTE_BGP
- && new_select->sub_type == BGP_ROUTE_IMPORTED) {
- ret = evpn_es_install_vtep(
- bgp, es,
- (const struct prefix_evpn *)bgp_dest_get_prefix(dest),
- new_select->attr->nexthop);
- } else {
- if (old_select && old_select->type == ZEBRA_ROUTE_BGP
- && old_select->sub_type == BGP_ROUTE_IMPORTED)
- ret = evpn_es_uninstall_vtep(
- bgp, es,
- (struct prefix_evpn *)bgp_dest_get_prefix(dest),
- old_select->attr->nexthop);
- }
-
- /* Clear any route change flags. */
- bgp_zebra_clear_route_change_flags(dest);
-
- /* 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);
-
- return ret;
-}
-
/*
* Calculate the best path for an EVPN route. Install/update best path in zebra,
* if appropriate.
+ * Note: vpn is NULL for local EAD-ES routes.
*/
-static int evpn_route_select_install(struct bgp *bgp, struct bgpevpn *vpn,
+int evpn_route_select_install(struct bgp *bgp, struct bgpevpn *vpn,
struct bgp_dest *dest)
{
struct bgp_path_info *old_select, *new_select;
@@ -1201,12 +1078,15 @@ static int evpn_route_select_install(struct bgp *bgp, struct bgpevpn *vpn,
new_select = old_and_new.new;
/* If the best path hasn't changed - see if there is still something to
- * update
- * to zebra RIB.
+ * update to zebra RIB.
+ * Remote routes and SYNC route (i.e. local routes with
+ * SYNCED_FROM_PEER flag) need to updated to zebra on any attr
+ * change.
*/
if (old_select && old_select == new_select
&& old_select->type == ZEBRA_ROUTE_BGP
- && old_select->sub_type == BGP_ROUTE_IMPORTED
+ && (old_select->sub_type == BGP_ROUTE_IMPORTED ||
+ bgp_evpn_attr_is_sync(old_select->attr))
&& !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)) {
@@ -1241,8 +1121,12 @@ static int evpn_route_select_install(struct bgp *bgp, struct bgpevpn *vpn,
UNSET_FLAG(new_select->flags, BGP_PATH_LINK_BW_CHG);
}
+ /* a local entry with the SYNC flag also results in a MAC-IP update
+ * to zebra
+ */
if (new_select && new_select->type == ZEBRA_ROUTE_BGP
- && new_select->sub_type == BGP_ROUTE_IMPORTED) {
+ && (new_select->sub_type == BGP_ROUTE_IMPORTED ||
+ bgp_evpn_attr_is_sync(new_select->attr))) {
ret = evpn_zebra_install(
bgp, vpn,
(struct prefix_evpn *)bgp_dest_get_prefix(dest),
@@ -1255,10 +1139,13 @@ static int evpn_route_select_install(struct bgp *bgp, struct bgpevpn *vpn,
* need to do an implicit delete and withdraw that route from
* peers.
*/
- if (old_select && old_select->peer == bgp->peer_self
- && old_select->type == ZEBRA_ROUTE_BGP
- && old_select->sub_type == BGP_ROUTE_STATIC)
- evpn_delete_old_local_route(bgp, vpn, dest, old_select);
+ if (new_select->sub_type == BGP_ROUTE_IMPORTED &&
+ old_select && old_select->peer == bgp->peer_self
+ && old_select->type == ZEBRA_ROUTE_BGP
+ && old_select->sub_type == BGP_ROUTE_STATIC
+ && vpn)
+ evpn_delete_old_local_route(bgp, vpn, dest,
+ old_select, new_select);
} else {
if (old_select && old_select->type == ZEBRA_ROUTE_BGP
&& old_select->sub_type == BGP_ROUTE_IMPORTED)
@@ -1279,222 +1166,21 @@ static int evpn_route_select_install(struct bgp *bgp, struct bgpevpn *vpn,
return ret;
}
-/*
- * Return true if the local ri for this rn is of type gateway mac
- */
-static int evpn_route_is_def_gw(struct bgp *bgp, struct bgp_dest *dest)
-{
- struct bgp_path_info *tmp_pi = NULL;
- struct bgp_path_info *local_pi = NULL;
-
- local_pi = NULL;
- for (tmp_pi = bgp_dest_get_bgp_path_info(dest); tmp_pi;
- tmp_pi = tmp_pi->next) {
- if (tmp_pi->peer == bgp->peer_self
- && tmp_pi->type == ZEBRA_ROUTE_BGP
- && tmp_pi->sub_type == BGP_ROUTE_STATIC)
- local_pi = tmp_pi;
- }
-
- if (!local_pi)
- return 0;
-
- return local_pi->attr->default_gw;
-}
-
-
-/*
- * Return true if the local ri for this rn has sticky set
- */
-static int evpn_route_is_sticky(struct bgp *bgp, struct bgp_dest *dest)
+static struct bgp_path_info *bgp_evpn_route_get_local_path(
+ struct bgp *bgp, struct bgp_dest *dest)
{
struct bgp_path_info *tmp_pi;
- struct bgp_path_info *local_pi;
-
- local_pi = NULL;
- for (tmp_pi = bgp_dest_get_bgp_path_info(dest); tmp_pi;
- tmp_pi = tmp_pi->next) {
- if (tmp_pi->peer == bgp->peer_self
- && tmp_pi->type == ZEBRA_ROUTE_BGP
- && tmp_pi->sub_type == BGP_ROUTE_STATIC)
- local_pi = tmp_pi;
- }
-
- if (!local_pi)
- return 0;
-
- return local_pi->attr->sticky;
-}
-
-/*
- * create or update EVPN type4 route entry.
- * This could be in the ES table or the global table.
- * TODO: handle remote ES (type4) routes as well
- */
-static int update_evpn_type4_route_entry(struct bgp *bgp, struct evpnes *es,
- afi_t afi, safi_t safi,
- struct bgp_dest *dest,
- struct attr *attr, int add,
- struct bgp_path_info **ri,
- int *route_changed)
-{
- char buf[ESI_STR_LEN];
- char buf1[INET6_ADDRSTRLEN];
- struct bgp_path_info *tmp_pi = NULL;
- struct bgp_path_info *local_pi = NULL; /* local route entry if any */
- struct bgp_path_info *remote_pi = NULL; /* remote route entry if any */
- struct attr *attr_new = NULL;
- const struct prefix_evpn *evp = NULL;
-
- *ri = NULL;
- *route_changed = 1;
- evp = (const struct prefix_evpn *)bgp_dest_get_prefix(dest);
+ struct bgp_path_info *local_pi = NULL;
- /* locate the local and remote entries if any */
for (tmp_pi = bgp_dest_get_bgp_path_info(dest); tmp_pi;
- tmp_pi = tmp_pi->next) {
- if (tmp_pi->peer == bgp->peer_self
- && tmp_pi->type == ZEBRA_ROUTE_BGP
- && tmp_pi->sub_type == BGP_ROUTE_STATIC)
+ tmp_pi = tmp_pi->next) {
+ if (bgp_evpn_is_path_local(bgp, tmp_pi)) {
local_pi = tmp_pi;
- if (tmp_pi->type == ZEBRA_ROUTE_BGP
- && tmp_pi->sub_type == BGP_ROUTE_IMPORTED
- && CHECK_FLAG(tmp_pi->flags, BGP_PATH_VALID))
- remote_pi = tmp_pi;
- }
-
- /* we don't expect to see a remote_ri at this point.
- * An ES route has esi + vtep_ip as the key,
- * We shouldn't see the same route from any other vtep.
- */
- if (remote_pi) {
- flog_err(
- EC_BGP_ES_INVALID,
- "%u ERROR: local es route for ESI: %s Vtep %s also learnt from remote",
- bgp->vrf_id,
- esi_to_str(&evp->prefix.es_addr.esi, buf, sizeof(buf)),
- ipaddr2str(&es->originator_ip, buf1, sizeof(buf1)));
- return -1;
- }
-
- if (!local_pi && !add)
- return 0;
-
- /* create or update the entry */
- if (!local_pi) {
-
- /* Add or update attribute to hash */
- attr_new = bgp_attr_intern(attr);
-
- /* Create new route with its attribute. */
- tmp_pi = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0,
- bgp->peer_self, attr_new, dest);
- SET_FLAG(tmp_pi->flags, BGP_PATH_VALID);
-
- /* add the newly created path to the route-node */
- bgp_path_info_add(dest, tmp_pi);
- } else {
- tmp_pi = local_pi;
- if (attrhash_cmp(tmp_pi->attr, attr)
- && !CHECK_FLAG(tmp_pi->flags, BGP_PATH_REMOVED))
- *route_changed = 0;
- else {
- /* The attribute has changed.
- * Add (or update) attribute to hash. */
- attr_new = bgp_attr_intern(attr);
- bgp_path_info_set_flag(dest, tmp_pi,
- BGP_PATH_ATTR_CHANGED);
-
- /* Restore route, if needed. */
- if (CHECK_FLAG(tmp_pi->flags, BGP_PATH_REMOVED))
- bgp_path_info_restore(dest, tmp_pi);
-
- /* Unintern existing, set to new. */
- bgp_attr_unintern(&tmp_pi->attr);
- tmp_pi->attr = attr_new;
- tmp_pi->uptime = bgp_clock();
+ break;
}
}
- /* Return back the route entry. */
- *ri = tmp_pi;
- return 0;
-}
-
-/* update evpn es (type-4) route */
-static int update_evpn_type4_route(struct bgp *bgp,
- struct evpnes *es,
- struct prefix_evpn *p)
-{
- int ret = 0;
- int route_changed = 0;
- char buf[ESI_STR_LEN];
- char buf1[INET6_ADDRSTRLEN];
- afi_t afi = AFI_L2VPN;
- safi_t safi = SAFI_EVPN;
- struct attr attr;
- struct attr *attr_new = NULL;
- struct bgp_dest *dest = NULL;
- struct bgp_path_info *pi = NULL;
-
- memset(&attr, 0, sizeof(struct attr));
-
- /* Build path-attribute for this route. */
- bgp_attr_default_set(&attr, BGP_ORIGIN_IGP);
- attr.nexthop = es->originator_ip.ipaddr_v4;
- attr.mp_nexthop_global_in = es->originator_ip.ipaddr_v4;
- attr.mp_nexthop_len = BGP_ATTR_NHLEN_IPV4;
-
- /* Set up extended community. */
- build_evpn_type4_route_extcomm(es, &attr);
-
- /* First, create (or fetch) route node within the ESI. */
- /* NOTE: There is no RD here. */
- dest = bgp_node_get(es->route_table, (struct prefix *)p);
-
- /* Create or update route entry. */
- ret = update_evpn_type4_route_entry(bgp, es, afi, safi, dest, &attr, 1,
- &pi, &route_changed);
- if (ret != 0) {
- flog_err(EC_BGP_ES_INVALID,
- "%u ERROR: Failed to updated ES route ESI: %s VTEP %s",
- bgp->vrf_id,
- esi_to_str(&p->prefix.es_addr.esi, buf, sizeof(buf)),
- ipaddr2str(&es->originator_ip, buf1, sizeof(buf1)));
- }
-
- assert(pi);
- attr_new = pi->attr;
-
- /* Perform route selection;
- * this is just to set the flags correctly
- * as local route in the ES always wins.
- */
- evpn_es_route_select_install(bgp, es, 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
- * from there. Note that this table is a 2-level tree (RD-level +
- * Prefix-level) similar to L3VPN routes.
- */
- if (route_changed) {
- struct bgp_path_info *global_pi;
-
- dest = bgp_afi_node_get(bgp->rib[afi][safi], afi, safi,
- (struct prefix *)p, &es->prd);
- update_evpn_type4_route_entry(bgp, es, afi, safi, dest,
- attr_new, 1, &global_pi,
- &route_changed);
-
- /* Schedule for processing and unlock node. */
- bgp_process(bgp, dest, afi, safi);
- bgp_dest_unlock_node(dest);
- }
-
- /* Unintern temporary. */
- aspath_unintern(&attr.aspath);
- return 0;
+ return local_pi;
}
static int update_evpn_type5_route_entry(struct bgp *bgp_evpn,
@@ -1640,8 +1326,9 @@ static int update_evpn_type5_route(struct bgp *bgp_vrf, struct prefix_evpn *evp,
build_evpn_type5_route_extcomm(bgp_vrf, &attr);
/* get the route node in global table */
- dest = bgp_afi_node_get(bgp_evpn->rib[afi][safi], afi, safi,
- (struct prefix *)evp, &bgp_vrf->vrf_prd);
+ dest = bgp_global_evpn_node_get(bgp_evpn->rib[afi][safi], afi, safi,
+ (const struct prefix_evpn *)evp,
+ &bgp_vrf->vrf_prd);
assert(dest);
/* create or update the route entry within the route node */
@@ -1660,15 +1347,137 @@ static int update_evpn_type5_route(struct bgp *bgp_vrf, struct prefix_evpn *evp,
return 0;
}
+static void bgp_evpn_get_sync_info(struct bgp *bgp, esi_t *esi,
+ struct bgp_node *rn, uint32_t loc_seq, uint32_t *max_sync_seq,
+ bool *active_on_peer, bool *peer_router,
+ bool *proxy_from_peer)
+{
+ struct bgp_path_info *tmp_pi;
+ struct bgp_path_info *second_best_path = NULL;
+ uint32_t tmp_mm_seq = 0;
+ esi_t *tmp_esi;
+ int paths_eq;
+
+ /* find the best non-local path. a local path can only be present
+ * as best path
+ */
+ for (tmp_pi = bgp_dest_get_bgp_path_info(rn); tmp_pi;
+ tmp_pi = tmp_pi->next) {
+ if (tmp_pi->sub_type != BGP_ROUTE_IMPORTED ||
+ !CHECK_FLAG(tmp_pi->flags, BGP_PATH_VALID))
+ continue;
+
+ if (bgp_evpn_path_info_cmp(bgp, tmp_pi,
+ second_best_path, &paths_eq))
+ second_best_path = tmp_pi;
+ }
+
+ if (!second_best_path)
+ return;
+
+ tmp_esi = bgp_evpn_attr_get_esi(second_best_path->attr);
+ /* if this has the same ES desination as the local path
+ * it is a sync path
+ */
+ if (!memcmp(esi, tmp_esi, sizeof(esi_t))) {
+ tmp_mm_seq = mac_mobility_seqnum(second_best_path->attr);
+ if (tmp_mm_seq < loc_seq)
+ return;
+
+ /* we have a non-proxy path from the ES peer. */
+ if (second_best_path->attr->es_flags &
+ ATTR_ES_PROXY_ADVERT) {
+ *proxy_from_peer = true;
+ } else {
+ *active_on_peer = true;
+ }
+
+ if (second_best_path->attr->router_flag)
+ *peer_router = true;
+
+ /* we use both proxy and non-proxy imports to
+ * determine the max sync sequence
+ */
+ if (tmp_mm_seq > *max_sync_seq)
+ *max_sync_seq = tmp_mm_seq;
+ }
+}
+
+/* Bubble up sync-info from all paths (non-best) to the local-path.
+ * This is need for MM sequence number syncing and proxy advertisement.
+ * Note: The local path can only exist as a best path in the
+ * VPN route table. It will take precedence over all sync paths.
+ */
+static void update_evpn_route_entry_sync_info(struct bgp *bgp,
+ struct bgp_node *rn, struct attr *attr, uint32_t loc_seq,
+ bool setup_sync)
+{
+ esi_t *esi;
+ struct prefix_evpn *evp = (struct prefix_evpn *)&rn->p;
+
+ if (evp->prefix.route_type != BGP_EVPN_MAC_IP_ROUTE)
+ return;
+
+ esi = bgp_evpn_attr_get_esi(attr);
+ if (bgp_evpn_is_esi_valid(esi)) {
+ if (setup_sync) {
+ uint32_t max_sync_seq = 0;
+ bool active_on_peer = false;
+ bool peer_router = false;
+ bool proxy_from_peer = false;
+
+ bgp_evpn_get_sync_info(bgp, esi, rn, loc_seq,
+ &max_sync_seq, &active_on_peer,
+ &peer_router, &proxy_from_peer);
+ attr->mm_sync_seqnum = max_sync_seq;
+ if (active_on_peer)
+ attr->es_flags |= ATTR_ES_PEER_ACTIVE;
+ else
+ attr->es_flags &= ~ATTR_ES_PEER_ACTIVE;
+ if (proxy_from_peer)
+ attr->es_flags |= ATTR_ES_PEER_PROXY;
+ else
+ attr->es_flags &= ~ATTR_ES_PEER_PROXY;
+ if (peer_router)
+ attr->es_flags |= ATTR_ES_PEER_ROUTER;
+ else
+ attr->es_flags &= ~ATTR_ES_PEER_ROUTER;
+
+ if (BGP_DEBUG(evpn_mh, EVPN_MH_RT)) {
+ char prefix_buf[PREFIX_STRLEN];
+ char esi_buf[ESI_STR_LEN];
+
+ zlog_debug("setup sync info for %s es %s max_seq %d %s%s%s",
+ prefix2str(evp, prefix_buf,
+ sizeof(prefix_buf)),
+ esi_to_str(esi, esi_buf,
+ sizeof(esi_buf)),
+ max_sync_seq,
+ (attr->es_flags & ATTR_ES_PEER_ACTIVE) ?
+ "peer-active " : "",
+ (attr->es_flags & ATTR_ES_PEER_PROXY) ?
+ "peer-proxy " : "",
+ (attr->es_flags & ATTR_ES_PEER_ROUTER) ?
+ "peer-router " : "");
+ }
+ }
+ } else {
+ attr->mm_sync_seqnum = 0;
+ attr->es_flags &= ~ATTR_ES_PEER_ACTIVE;
+ attr->es_flags &= ~ATTR_ES_PEER_PROXY;
+ }
+}
+
/*
* Create or update EVPN route entry. This could be in the VNI route table
* or the global route table.
*/
static int update_evpn_route_entry(struct bgp *bgp, struct bgpevpn *vpn,
- afi_t afi, safi_t safi,
- struct bgp_dest *dest, struct attr *attr,
- int add, struct bgp_path_info **pi,
- uint8_t flags, uint32_t seq)
+ afi_t afi, safi_t safi, struct bgp_dest *dest,
+ struct attr *attr, int add,
+ struct bgp_path_info **pi, uint8_t flags,
+ uint32_t seq, bool setup_sync,
+ bool *old_is_sync)
{
struct bgp_path_info *tmp_pi;
struct bgp_path_info *local_pi;
@@ -1684,14 +1493,7 @@ static int update_evpn_route_entry(struct bgp *bgp, struct bgpevpn *vpn,
memset(&label, 0, sizeof(label));
/* See if this is an update of an existing route, or a new add. */
- local_pi = NULL;
- for (tmp_pi = bgp_dest_get_bgp_path_info(dest); tmp_pi;
- tmp_pi = tmp_pi->next) {
- if (tmp_pi->peer == bgp->peer_self
- && tmp_pi->type == ZEBRA_ROUTE_BGP
- && tmp_pi->sub_type == BGP_ROUTE_STATIC)
- local_pi = tmp_pi;
- }
+ local_pi = bgp_evpn_route_get_local_path(bgp, dest);
/* If route doesn't exist already, create a new one, if told to.
* Otherwise act based on whether the attributes of the route have
@@ -1700,6 +1502,14 @@ static int update_evpn_route_entry(struct bgp *bgp, struct bgpevpn *vpn,
if (!local_pi && !add)
return 0;
+ if (old_is_sync && local_pi)
+ *old_is_sync = bgp_evpn_attr_is_sync(local_pi->attr);
+
+ /* if a local path is being added with a non-zero esi look
+ * for SYNC paths from ES peers and bubble up the sync-info
+ */
+ update_evpn_route_entry_sync_info(bgp, dest, attr, seq, setup_sync);
+
/* For non-GW MACs, update MAC mobility seq number, if needed. */
if (seq && !CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_GW))
add_mac_mobility_to_attr(seq, attr);
@@ -1811,11 +1621,11 @@ static void evpn_zebra_reinstall_best_route(struct bgp *bgp,
}
if (curr_select && curr_select->type == ZEBRA_ROUTE_BGP
- && curr_select->sub_type == BGP_ROUTE_IMPORTED)
- evpn_zebra_install(
- bgp, vpn,
- (const struct prefix_evpn *)bgp_dest_get_prefix(dest),
- curr_select);
+ && (curr_select->sub_type == BGP_ROUTE_IMPORTED ||
+ bgp_evpn_attr_is_sync(curr_select->attr)))
+ evpn_zebra_install(bgp, vpn,
+ (const struct prefix_evpn *)bgp_dest_get_prefix(dest),
+ curr_select);
}
/*
@@ -1842,7 +1652,7 @@ static void evpn_cleanup_local_non_best_route(struct bgp *bgp,
zlog_debug("evicting local evpn prefix %pRN as remote won",
dest);
- evpn_delete_old_local_route(bgp, vpn, dest, local_pi);
+ 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 */
@@ -1855,7 +1665,7 @@ static void evpn_cleanup_local_non_best_route(struct bgp *bgp,
*/
static int update_evpn_route(struct bgp *bgp, struct bgpevpn *vpn,
struct prefix_evpn *p, uint8_t flags,
- uint32_t seq)
+ uint32_t seq, esi_t *esi)
{
struct bgp_dest *dest;
struct attr attr;
@@ -1865,6 +1675,7 @@ static int update_evpn_route(struct bgp *bgp, struct bgpevpn *vpn,
afi_t afi = AFI_L2VPN;
safi_t safi = SAFI_EVPN;
int route_change;
+ bool old_is_sync = false;
memset(&attr, 0, sizeof(struct attr));
@@ -1877,6 +1688,13 @@ static int update_evpn_route(struct bgp *bgp, struct bgpevpn *vpn,
attr.default_gw = CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_GW) ? 1 : 0;
attr.router_flag = CHECK_FLAG(flags,
ZEBRA_MACIP_TYPE_ROUTER_FLAG) ? 1 : 0;
+ if (CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_PROXY_ADVERT))
+ attr.es_flags |= ATTR_ES_PROXY_ADVERT;
+
+ if (esi && bgp_evpn_is_esi_valid(esi)) {
+ memcpy(&attr.esi, esi, sizeof(esi_t));
+ attr.es_flags |= ATTR_ES_IS_LOCAL;
+ }
/* PMSI is only needed for type-3 routes */
if (p->prefix.route_type == BGP_EVPN_IMET_ROUTE) {
@@ -1884,6 +1702,21 @@ static int update_evpn_route(struct bgp *bgp, struct bgpevpn *vpn,
attr.pmsi_tnl_type = PMSI_TNLTYPE_INGR_REPL;
}
+ if (bgp_debug_zebra(NULL)) {
+ char buf[ETHER_ADDR_STRLEN];
+ char buf1[PREFIX_STRLEN];
+ char buf3[ESI_STR_LEN];
+
+ zlog_debug("VRF %s vni %u type-2 route evp %s RMAC %s nexthop %s esi %s",
+ vpn->bgp_vrf ?
+ vrf_id_to_name(vpn->bgp_vrf->vrf_id) : " ",
+ vpn->vni,
+ prefix2str(p, buf1, sizeof(buf1)),
+ prefix_mac2str(&attr.rmac, buf,
+ sizeof(buf)),
+ inet_ntoa(attr.mp_nexthop_global_in),
+ esi_to_str(esi, buf3, sizeof(buf3)));
+ }
/* router mac is only needed for type-2 routes here. */
if (p->prefix.route_type == BGP_EVPN_MAC_IP_ROUTE) {
uint8_t af_flags = 0;
@@ -1892,20 +1725,6 @@ static int update_evpn_route(struct bgp *bgp, struct bgpevpn *vpn,
SET_FLAG(af_flags, BGP_EVPN_MACIP_TYPE_SVI_IP);
bgp_evpn_get_rmac_nexthop(vpn, p, &attr, af_flags);
-
- if (bgp_debug_zebra(NULL)) {
- char buf[ETHER_ADDR_STRLEN];
- char buf1[PREFIX_STRLEN];
-
- zlog_debug("VRF %s vni %u type-2 route evp %s RMAC %s nexthop %s",
- vpn->bgp_vrf ?
- vrf_id_to_name(vpn->bgp_vrf->vrf_id) : " ",
- vpn->vni,
- prefix2str(p, buf1, sizeof(buf1)),
- prefix_mac2str(&attr.rmac, buf,
- sizeof(buf)),
- inet_ntoa(attr.mp_nexthop_global_in));
- }
}
vni2label(vpn->vni, &(attr.label));
@@ -1930,7 +1749,8 @@ static int update_evpn_route(struct bgp *bgp, struct bgpevpn *vpn,
/* Create or update route entry. */
route_change = update_evpn_route_entry(bgp, vpn, afi, safi, dest, &attr,
- 1, &pi, flags, seq);
+ 1, &pi, flags, seq,
+ true /* setup_sync */, &old_is_sync);
assert(pi);
attr_new = pi->attr;
@@ -1951,9 +1771,25 @@ static int update_evpn_route(struct bgp *bgp, struct bgpevpn *vpn,
* to re-add the best remote dest. BGP doesn't retain non-best local
* routes.
*/
- if (!CHECK_FLAG(pi->flags, BGP_PATH_SELECTED)) {
+ if (CHECK_FLAG(pi->flags, BGP_PATH_REMOVED)) {
route_change = 0;
- evpn_cleanup_local_non_best_route(bgp, vpn, dest, pi);
+ } else {
+ if (!CHECK_FLAG(pi->flags, BGP_PATH_SELECTED)) {
+ route_change = 0;
+ evpn_cleanup_local_non_best_route(bgp, vpn, dest, pi);
+ } else {
+ bool new_is_sync;
+
+ /* If the local path already existed and is still the
+ * best path we need to also check if it transitioned
+ * from being a sync path to a non-sync path. If it
+ * it did we need to notify zebra that the sync-path
+ * has been removed.
+ */
+ new_is_sync = bgp_evpn_attr_is_sync(pi->attr);
+ if (!new_is_sync && old_is_sync)
+ evpn_zebra_uninstall(bgp, vpn, p, zero_vtep_ip);
+ }
}
bgp_path_info_unlock(pi);
@@ -1967,10 +1803,12 @@ static int update_evpn_route(struct bgp *bgp, struct bgpevpn *vpn,
if (route_change) {
struct bgp_path_info *global_pi;
- dest = bgp_afi_node_get(bgp->rib[afi][safi], afi, safi,
- (struct prefix *)p, &vpn->prd);
+ dest = bgp_global_evpn_node_get(bgp->rib[afi][safi], afi, safi,
+ (const struct prefix_evpn *)p,
+ &vpn->prd);
update_evpn_route_entry(bgp, vpn, afi, safi, dest, attr_new, 1,
- &global_pi, flags, seq);
+ &global_pi, flags, seq,
+ false /* setup_sync */, NULL /* old_is_sync */);
/* Schedule for processing and unlock node. */
bgp_process(bgp, dest, afi, safi);
@@ -1987,7 +1825,7 @@ static int update_evpn_route(struct bgp *bgp, struct bgpevpn *vpn,
* Delete EVPN route entry.
* The entry can be in ESI/VNI table or the global table.
*/
-static void delete_evpn_route_entry(struct bgp *bgp, afi_t afi, safi_t safi,
+void delete_evpn_route_entry(struct bgp *bgp, afi_t afi, safi_t safi,
struct bgp_dest *dest,
struct bgp_path_info **pi)
{
@@ -2010,56 +1848,6 @@ static void delete_evpn_route_entry(struct bgp *bgp, afi_t afi, safi_t safi,
bgp_path_info_delete(dest, tmp_pi);
}
-
-
-/* Delete EVPN ES (type-4) route */
-static int delete_evpn_type4_route(struct bgp *bgp,
- struct evpnes *es,
- struct prefix_evpn *p)
-{
- afi_t afi = AFI_L2VPN;
- safi_t safi = SAFI_EVPN;
- struct bgp_path_info *pi;
- struct bgp_dest *dest = NULL; /* dest in esi table */
- struct bgp_dest *global_dest = NULL; /* dest in global table */
-
- /* First, locate the route node within the ESI.
- * If it doesn't exist, ther is nothing to do.
- * Note: there is no RD here.
- */
- dest = bgp_node_lookup(es->route_table, (struct prefix *)p);
- if (!dest)
- return 0;
-
- /* Next, locate route node in the global EVPN routing table.
- * Note that this table is a 2-level tree (RD-level + Prefix-level)
- */
- global_dest = bgp_afi_node_lookup(bgp->rib[afi][safi], afi, safi,
- (struct prefix *)p, &es->prd);
- if (global_dest) {
-
- /* Delete route entry in the global EVPN table. */
- delete_evpn_route_entry(bgp, afi, safi, global_dest, &pi);
-
- /* Schedule for processing - withdraws to peers happen from
- * this table.
- */
- if (pi)
- bgp_process(bgp, global_dest, afi, safi);
- bgp_dest_unlock_node(global_dest);
- }
-
- /*
- * Delete route entry in the ESI route table.
- * This can just be removed.
- */
- delete_evpn_route_entry(bgp, afi, safi, dest, &pi);
- if (pi)
- bgp_path_info_reap(dest, pi);
- bgp_dest_unlock_node(dest);
- return 0;
-}
-
/* Delete EVPN type5 route */
static int delete_evpn_type5_route(struct bgp *bgp_vrf, struct prefix_evpn *evp)
{
@@ -2074,8 +1862,8 @@ static int delete_evpn_type5_route(struct bgp *bgp_vrf, struct prefix_evpn *evp)
return 0;
/* locate the global route entry for this type-5 prefix */
- dest = bgp_afi_node_lookup(bgp_evpn->rib[afi][safi], afi, safi,
- (struct prefix *)evp, &bgp_vrf->vrf_prd);
+ dest = bgp_global_evpn_node_lookup(bgp_evpn->rib[afi][safi], afi, safi,
+ (const struct prefix_evpn *)evp, &bgp_vrf->vrf_prd);
if (!dest)
return 0;
@@ -2111,8 +1899,8 @@ static int delete_evpn_route(struct bgp *bgp, struct bgpevpn *vpn,
* this table is a 2-level tree (RD-level + Prefix-level) similar to
* L3VPN routes.
*/
- global_dest = bgp_afi_node_lookup(bgp->rib[afi][safi], afi, safi,
- (struct prefix *)p, &vpn->prd);
+ global_dest = bgp_global_evpn_node_lookup(bgp->rib[afi][safi], afi, safi,
+ (const struct prefix_evpn *)p, &vpn->prd);
if (global_dest) {
/* Delete route entry in the global EVPN table. */
delete_evpn_route_entry(bgp, afi, safi, global_dest, &pi);
@@ -2137,139 +1925,177 @@ static int delete_evpn_route(struct bgp *bgp, struct bgpevpn *vpn,
return 0;
}
+static void bgp_evpn_update_type2_route_entry(struct bgp *bgp,
+ struct bgpevpn *vpn, struct bgp_node *rn,
+ struct bgp_path_info *local_pi, const char *caller)
+{
+ afi_t afi = AFI_L2VPN;
+ safi_t safi = SAFI_EVPN;
+ struct bgp_path_info *pi;
+ struct attr attr;
+ struct attr *attr_new;
+ uint32_t seq;
+ int add_l3_ecomm = 0;
+ struct bgp_node *global_rn;
+ struct bgp_path_info *global_pi;
+ struct prefix_evpn *evp = (struct prefix_evpn *)&rn->p;
+ int route_change;
+ bool old_is_sync = false;
+
+ if (CHECK_FLAG(local_pi->flags, BGP_PATH_REMOVED))
+ return;
+
+ /*
+ * Build attribute per local route as the MAC mobility and
+ * some other values could differ for different routes. The
+ * attributes will be shared in the hash table.
+ */
+ bgp_attr_default_set(&attr, BGP_ORIGIN_IGP);
+ attr.nexthop = vpn->originator_ip;
+ attr.mp_nexthop_global_in = vpn->originator_ip;
+ attr.mp_nexthop_len = BGP_ATTR_NHLEN_IPV4;
+ attr.sticky = (local_pi->attr->sticky) ? 1 : 0;
+ attr.router_flag = (local_pi->attr->router_flag) ? 1 : 0;
+ attr.es_flags = local_pi->attr->es_flags;
+ if (local_pi->attr->default_gw) {
+ attr.default_gw = 1;
+ if (is_evpn_prefix_ipaddr_v6(evp))
+ 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);
+ 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.
+ */
+ if ((is_evpn_prefix_ipaddr_v4(evp) ||
+ !IN6_IS_ADDR_LINKLOCAL(
+ &evp->prefix.macip_addr.ip.ipaddr_v6)) &&
+ CHECK_FLAG(vpn->flags, VNI_FLAG_USE_TWO_LABELS) &&
+ bgpevpn_get_l3vni(vpn))
+ add_l3_ecomm = 1;
+
+ /* Set up extended community. */
+ build_evpn_route_extcomm(vpn, &attr, add_l3_ecomm);
+ seq = mac_mobility_seqnum(local_pi->attr);
+
+ if (bgp_debug_zebra(NULL)) {
+ char buf[ETHER_ADDR_STRLEN];
+ char buf1[PREFIX_STRLEN];
+ char buf3[ESI_STR_LEN];
+
+ zlog_debug("VRF %s vni %u evp %s RMAC %s nexthop %s esi %s esf 0x%x from %s",
+ vpn->bgp_vrf ?
+ vrf_id_to_name(vpn->bgp_vrf->vrf_id) : " ",
+ vpn->vni,
+ prefix2str(evp, buf1, sizeof(buf1)),
+ prefix_mac2str(&attr.rmac, buf, sizeof(buf)),
+ inet_ntoa(attr.mp_nexthop_global_in),
+ esi_to_str(&attr.esi, buf3, sizeof(buf3)),
+ attr.es_flags, caller);
+ }
+
+ /* Update the route entry. */
+ route_change = update_evpn_route_entry(bgp, vpn, afi, safi,
+ rn, &attr, 0, &pi, 0, seq,
+ true /* setup_sync */, &old_is_sync);
+
+ assert(pi);
+ attr_new = pi->attr;
+ /* lock ri to prevent freeing in evpn_route_select_install */
+ bgp_path_info_lock(pi);
+
+ /* Perform route selection. Normally, the local route in the
+ * VNI is expected to win and be the best route. However,
+ * under peculiar situations (e.g., tunnel (next hop) IP change
+ * that causes best selection to be based on next hop), a
+ * remote route could win. If the local route is the best,
+ * ensure it is updated in the global EVPN route table and
+ * advertised to peers; otherwise, ensure it is evicted and
+ * (re)install the remote route into zebra.
+ */
+ evpn_route_select_install(bgp, vpn, rn);
+
+ if (CHECK_FLAG(pi->flags, BGP_PATH_REMOVED)) {
+ route_change = 0;
+ } else {
+ if (!CHECK_FLAG(pi->flags, BGP_PATH_SELECTED)) {
+ route_change = 0;
+ evpn_cleanup_local_non_best_route(bgp, vpn, rn, pi);
+ } else {
+ bool new_is_sync;
+
+ /* If the local path already existed and is still the
+ * best path we need to also check if it transitioned
+ * from being a sync path to a non-sync path. If it
+ * it did we need to notify zebra that the sync-path
+ * has been removed.
+ */
+ new_is_sync = bgp_evpn_attr_is_sync(pi->attr);
+ if (!new_is_sync && old_is_sync)
+ evpn_zebra_uninstall(bgp, vpn,
+ evp, zero_vtep_ip);
+ }
+ }
+
+
+ /* unlock pi */
+ bgp_path_info_unlock(pi);
+
+ if (route_change) {
+ /* Update route in global routing table. */
+ global_rn = bgp_global_evpn_node_get(bgp->rib[afi][safi],
+ afi, safi, evp, &vpn->prd);
+ assert(global_rn);
+ update_evpn_route_entry(bgp, vpn, afi, safi, global_rn,
+ attr_new, 0, &global_pi, 0,
+ mac_mobility_seqnum(attr_new),
+ false /* setup_sync */, NULL /* old_is_sync */);
+
+ /* Schedule for processing and unlock node. */
+ bgp_process(bgp, global_rn, afi, safi);
+ bgp_dest_unlock_node(global_rn);
+ }
+
+ /* Unintern temporary. */
+ aspath_unintern(&attr.aspath);
+}
+
/*
* Update all type-2 (MACIP) local routes for this VNI - these should also
* be scheduled for advertise to peers.
*/
static int update_all_type2_routes(struct bgp *bgp, struct bgpevpn *vpn)
{
- afi_t afi;
- safi_t safi;
struct bgp_dest *dest;
- struct bgp_path_info *pi, *tmp_pi;
- struct attr attr;
- struct attr *attr_new;
- uint32_t seq;
- int add_l3_ecomm = 0;
-
- afi = AFI_L2VPN;
- safi = SAFI_EVPN;
+ struct bgp_path_info *tmp_pi;
/* Walk this VNI's route table and update local type-2 routes. For any
* routes updated, update corresponding entry in the global table too.
*/
for (dest = bgp_table_top(vpn->route_table); dest;
- dest = bgp_route_next(dest)) {
+ dest = bgp_route_next(dest)) {
const struct prefix_evpn *evp =
(const struct prefix_evpn *)bgp_dest_get_prefix(dest);
- struct bgp_dest *rd_dest;
- struct bgp_path_info *global_pi;
if (evp->prefix.route_type != BGP_EVPN_MAC_IP_ROUTE)
continue;
/* Identify local route. */
for (tmp_pi = bgp_dest_get_bgp_path_info(dest); tmp_pi;
- tmp_pi = tmp_pi->next) {
+ tmp_pi = tmp_pi->next) {
if (tmp_pi->peer == bgp->peer_self
- && tmp_pi->type == ZEBRA_ROUTE_BGP
- && tmp_pi->sub_type == BGP_ROUTE_STATIC)
+ && tmp_pi->type == ZEBRA_ROUTE_BGP
+ && tmp_pi->sub_type == BGP_ROUTE_STATIC)
break;
}
if (!tmp_pi)
continue;
- /*
- * Build attribute per local route as the MAC mobility and
- * some other values could differ for different routes. The
- * attributes will be shared in the hash table.
- */
- bgp_attr_default_set(&attr, BGP_ORIGIN_IGP);
- attr.nexthop = vpn->originator_ip;
- attr.mp_nexthop_global_in = vpn->originator_ip;
- attr.mp_nexthop_len = BGP_ATTR_NHLEN_IPV4;
- bgp_evpn_get_rmac_nexthop(vpn, evp, &attr,
- tmp_pi->extra->af_flags);
-
- if (evpn_route_is_sticky(bgp, dest))
- attr.sticky = 1;
- else if (evpn_route_is_def_gw(bgp, dest)) {
- attr.default_gw = 1;
- if (is_evpn_prefix_ipaddr_v6(evp))
- attr.router_flag = 1;
- }
-
- if (bgp_debug_zebra(NULL)) {
- char buf[ETHER_ADDR_STRLEN];
- char buf1[PREFIX_STRLEN];
-
- zlog_debug("VRF %s vni %u evp %s RMAC %s nexthop %s",
- vpn->bgp_vrf ?
- vrf_id_to_name(vpn->bgp_vrf->vrf_id) : " ",
- vpn->vni,
- prefix2str(evp, buf1, sizeof(buf1)),
- prefix_mac2str(&attr.rmac, buf, sizeof(buf)),
- inet_ntoa(attr.mp_nexthop_global_in));
- }
-
- /* Add L3 VNI RTs and RMAC for non IPv6 link-local if
- * using L3 VNI for type-2 routes also.
- */
- if ((is_evpn_prefix_ipaddr_v4(evp) ||
- !IN6_IS_ADDR_LINKLOCAL(
- &evp->prefix.macip_addr.ip.ipaddr_v6)) &&
- CHECK_FLAG(vpn->flags, VNI_FLAG_USE_TWO_LABELS) &&
- bgpevpn_get_l3vni(vpn))
- add_l3_ecomm = 1;
-
- /* Set up extended community. */
- build_evpn_route_extcomm(vpn, &attr, add_l3_ecomm);
-
- seq = mac_mobility_seqnum(tmp_pi->attr);
-
- /* Update the route entry. */
- update_evpn_route_entry(bgp, vpn, afi, safi, dest, &attr, 0,
- &pi, 0, seq);
-
- /* lock ri to prevent freeing in evpn_route_select_install */
- bgp_path_info_lock(pi);
-
- /* Perform route selection. Normally, the local route in the
- * VNI is expected to win and be the best route. However,
- * under peculiar situations (e.g., tunnel (next hop) IP change
- * that causes best selection to be based on next hop), a
- * remote route could win. If the local route is the best,
- * ensure it is updated in the global EVPN route table and
- * advertised to peers; otherwise, ensure it is evicted and
- * (re)install the remote route into zebra.
- */
- evpn_route_select_install(bgp, vpn, dest);
- if (!CHECK_FLAG(pi->flags, BGP_PATH_SELECTED)) {
- evpn_cleanup_local_non_best_route(bgp, vpn, dest, pi);
- /* unlock pi */
- bgp_path_info_unlock(pi);
- } else {
- attr_new = pi->attr;
- /* unlock pi */
- bgp_path_info_unlock(pi);
-
- /* Update route in global routing table. */
- rd_dest = bgp_afi_node_get(bgp->rib[afi][safi], afi,
- safi, (struct prefix *)evp,
- &vpn->prd);
- assert(rd_dest);
- update_evpn_route_entry(bgp, vpn, afi, safi, rd_dest,
- attr_new, 0, &global_pi, 0,
- mac_mobility_seqnum(attr_new));
-
- /* Schedule for processing and unlock node. */
- bgp_process(bgp, rd_dest, afi, safi);
- bgp_dest_unlock_node(rd_dest);
- }
-
- /* Unintern temporary. */
- aspath_unintern(&attr.aspath);
+ bgp_evpn_update_type2_route_entry(bgp, vpn, dest, tmp_pi,
+ __func__);
}
return 0;
@@ -2356,27 +2182,6 @@ static int delete_all_type2_routes(struct bgp *bgp, struct bgpevpn *vpn)
}
/*
- * Delete all routes in per ES route-table
- */
-static int delete_all_es_routes(struct bgp *bgp, struct evpnes *es)
-{
- struct bgp_dest *dest;
- struct bgp_path_info *pi, *nextpi;
-
- /* Walk this ES's route table and delete all routes. */
- for (dest = bgp_table_top(es->route_table); dest;
- dest = bgp_route_next(dest)) {
- 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);
- }
- }
-
- return 0;
-}
-
-/*
* Delete all routes in the per-VNI route table.
*/
static int delete_all_vni_routes(struct bgp *bgp, struct bgpevpn *vpn)
@@ -2434,7 +2239,7 @@ int update_routes_for_vni(struct bgp *bgp, struct bgpevpn *vpn)
if (bgp_evpn_vni_flood_mode_get(bgp, vpn)
== VXLAN_FLOOD_HEAD_END_REPL) {
build_evpn_type3_prefix(&p, vpn->originator_ip);
- ret = update_evpn_route(bgp, vpn, &p, 0, 0);
+ ret = update_evpn_route(bgp, vpn, &p, 0, 0, NULL);
if (ret)
return ret;
}
@@ -2442,29 +2247,6 @@ int update_routes_for_vni(struct bgp *bgp, struct bgpevpn *vpn)
return update_all_type2_routes(bgp, vpn);
}
-/* Delete (and withdraw) local routes for specified ES from global and ES table.
- * Also remove all other routes from the per ES table.
- * Invoked when ES is deleted.
- */
-static int delete_routes_for_es(struct bgp *bgp, struct evpnes *es)
-{
- int ret;
- char buf[ESI_STR_LEN];
- struct prefix_evpn p;
-
- /* Delete and withdraw locally learnt ES route */
- build_evpn_type4_prefix(&p, &es->esi, es->originator_ip.ipaddr_v4);
- ret = delete_evpn_type4_route(bgp, es, &p);
- if (ret) {
- flog_err(EC_BGP_EVPN_ROUTE_DELETE,
- "%u failed to delete type-4 route for ESI %s",
- bgp->vrf_id, esi_to_str(&es->esi, buf, sizeof(buf)));
- }
-
- /* Delete all routes from per ES table */
- return delete_all_es_routes(bgp, es);
-}
-
/*
* Delete (and withdraw) local routes for specified VNI from the global
* table and per-VNI table. After this, remove all other routes from
@@ -2574,68 +2356,6 @@ bgp_create_evpn_bgp_path_info(struct bgp_path_info *parent_pi,
return pi;
}
-/* Install EVPN route entry in ES */
-static int install_evpn_route_entry_in_es(struct bgp *bgp, struct evpnes *es,
- const struct prefix_evpn *p,
- struct bgp_path_info *parent_pi)
-{
- int ret = 0;
- struct bgp_dest *dest = NULL;
- struct bgp_path_info *pi = NULL;
- struct attr *attr_new = NULL;
-
- /* Create (or fetch) route within the VNI.
- * NOTE: There is no RD here.
- */
- dest = bgp_node_get(es->route_table, (struct prefix *)p);
-
- /* 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)
- break;
-
- if (!pi) {
- /* Add (or update) attribute to hash. */
- attr_new = bgp_attr_intern(parent_pi->attr);
-
- /* Create new route with its attribute. */
- pi = info_make(parent_pi->type, BGP_ROUTE_IMPORTED, 0,
- 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);
- bgp_dest_lock_node((struct bgp_dest *)parent_pi->net);
- bgp_path_info_add(dest, pi);
- } else {
- if (attrhash_cmp(pi->attr, parent_pi->attr)
- && !CHECK_FLAG(pi->flags, BGP_PATH_REMOVED)) {
- bgp_dest_unlock_node(dest);
- return 0;
- }
- /* The attribute has changed. */
- /* Add (or update) attribute to hash. */
- attr_new = bgp_attr_intern(parent_pi->attr);
-
- /* Restore route, if needed. */
- if (CHECK_FLAG(pi->flags, BGP_PATH_REMOVED))
- bgp_path_info_restore(dest, pi);
-
- /* Mark if nexthop has changed. */
- if (!IPV4_ADDR_SAME(&pi->attr->nexthop, &attr_new->nexthop))
- SET_FLAG(pi->flags, BGP_PATH_IGP_CHANGED);
-
- /* Unintern existing, set to new. */
- bgp_attr_unintern(&pi->attr);
- pi->attr = attr_new;
- pi->uptime = bgp_clock();
- }
-
- /* Perform route selection and update zebra, if required. */
- ret = evpn_es_route_select_install(bgp, es, dest);
- return ret;
-}
-
/*
* Install route entry into the VRF routing table and invoke route selection.
*/
@@ -2761,8 +2481,17 @@ static int install_evpn_route_entry(struct bgp *bgp, struct bgpevpn *vpn,
{
struct bgp_dest *dest;
struct bgp_path_info *pi;
+ struct bgp_path_info *local_pi;
struct attr *attr_new;
int ret;
+ struct prefix_evpn ad_evp;
+
+ /* EAD prefix in the global table doesn't include the VTEP-IP so
+ * we need to create a different copy for the VNI
+ */
+ if (p->prefix.route_type == BGP_EVPN_AD_ROUTE)
+ p = evpn_type1_prefix_vni_copy(&ad_evp, p,
+ parent_pi->attr->nexthop);
/* Create (or fetch) route within the VNI. */
/* NOTE: There is no RD here. */
@@ -2805,46 +2534,16 @@ static int install_evpn_route_entry(struct bgp *bgp, struct bgpevpn *vpn,
/* Perform route selection and update zebra, if required. */
ret = evpn_route_select_install(bgp, vpn, dest);
- bgp_dest_unlock_node(dest);
-
- return ret;
-}
-
-/* Uninstall EVPN route entry from ES route table */
-static int uninstall_evpn_route_entry_in_es(struct bgp *bgp, struct evpnes *es,
- const struct prefix_evpn *p,
- struct bgp_path_info *parent_pi)
-{
- int ret;
- struct bgp_dest *dest;
- struct bgp_path_info *pi;
-
- if (!es->route_table)
- return 0;
-
- /* Locate route within the ESI.
- * NOTE: There is no RD here.
+ /* if the best path is a local path with a non-zero ES
+ * sync info against the local path may need to be updated
+ * when a remote path is added/updated (including changes
+ * from sync-path to remote-path)
*/
- dest = bgp_node_lookup(es->route_table, (struct prefix *)p);
- if (!dest)
- return 0;
-
- /* 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)
- break;
-
- if (!pi)
- return 0;
-
- /* Mark entry for deletion */
- bgp_path_info_delete(dest, pi);
+ local_pi = bgp_evpn_route_get_local_path(bgp, dest);
+ if (local_pi && bgp_evpn_attr_is_local_es(local_pi->attr))
+ bgp_evpn_update_type2_route_entry(bgp, vpn, dest, local_pi,
+ __func__);
- /* Perform route selection and update zebra, if required. */
- ret = evpn_es_route_select_install(bgp, es, dest);
-
- /* Unlock route node. */
bgp_dest_unlock_node(dest);
return ret;
@@ -2936,7 +2635,16 @@ static int uninstall_evpn_route_entry(struct bgp *bgp, struct bgpevpn *vpn,
{
struct bgp_dest *dest;
struct bgp_path_info *pi;
+ struct bgp_path_info *local_pi;
int ret;
+ struct prefix_evpn ad_evp;
+
+ /* EAD prefix in the global table doesn't include the VTEP-IP so
+ * we need to create a different copy for the VNI
+ */
+ if (p->prefix.route_type == BGP_EVPN_AD_ROUTE)
+ p = evpn_type1_prefix_vni_copy(&ad_evp, p,
+ parent_pi->attr->nexthop);
/* Locate route within the VNI. */
/* NOTE: There is no RD here. */
@@ -2959,6 +2667,15 @@ static int uninstall_evpn_route_entry(struct bgp *bgp, struct bgpevpn *vpn,
/* Perform route selection and update zebra, if required. */
ret = evpn_route_select_install(bgp, vpn, dest);
+ /* if the best path is a local path with a non-zero ES
+ * sync info against the local path may need to be updated
+ * when a remote path is deleted
+ */
+ local_pi = bgp_evpn_route_get_local_path(bgp, dest);
+ if (local_pi && bgp_evpn_attr_is_local_es(local_pi->attr))
+ bgp_evpn_update_type2_route_entry(bgp, vpn, dest, local_pi,
+ __func__);
+
/* Unlock route node. */
bgp_dest_unlock_node(dest);
@@ -2966,22 +2683,6 @@ static int uninstall_evpn_route_entry(struct bgp *bgp, struct bgpevpn *vpn,
}
/*
- * Given a prefix, see if it belongs to ES.
- */
-static int is_prefix_matching_for_es(const struct prefix_evpn *p,
- struct evpnes *es)
-{
- /* if not an ES route return false */
- if (p->prefix.route_type != BGP_EVPN_ES_ROUTE)
- return 0;
-
- if (memcmp(&p->prefix.es_addr.esi, &es->esi, sizeof(esi_t)) == 0)
- return 1;
-
- return 0;
-}
-
-/*
* Given a route entry and a VRF, see if this route entry should be
* imported into the VRF i.e., RTs match.
*/
@@ -3115,78 +2816,6 @@ static int is_route_matching_for_vni(struct bgp *bgp, struct bgpevpn *vpn,
return 0;
}
-static int install_uninstall_routes_for_es(struct bgp *bgp,
- struct evpnes *es,
- int install)
-{
- int ret;
- afi_t afi;
- safi_t safi;
- char buf[PREFIX_STRLEN];
- char buf1[ESI_STR_LEN];
- struct bgp_dest *rd_dest, *dest;
- struct bgp_table *table;
- struct bgp_path_info *pi;
-
- afi = AFI_L2VPN;
- safi = SAFI_EVPN;
-
- /*
- * Walk entire global routing table and evaluate routes which could be
- * imported into this VRF. Note that we need to loop through all global
- * routes to determine which route matches the import rt on vrf
- */
- 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)) {
- const struct prefix_evpn *evp =
- (const struct prefix_evpn *)bgp_dest_get_prefix(
- dest);
-
- for (pi = bgp_dest_get_bgp_path_info(dest); pi;
- pi = pi->next) {
- /*
- * Consider "valid" remote routes applicable for
- * this ES.
- */
- if (!(CHECK_FLAG(pi->flags, BGP_PATH_VALID)
- && pi->type == ZEBRA_ROUTE_BGP
- && pi->sub_type == BGP_ROUTE_NORMAL))
- continue;
-
- if (!is_prefix_matching_for_es(evp, es))
- continue;
-
- if (install)
- ret = install_evpn_route_entry_in_es(
- bgp, es, evp, pi);
- else
- ret = uninstall_evpn_route_entry_in_es(
- bgp, es, evp, pi);
-
- if (ret) {
- flog_err(
- EC_BGP_EVPN_FAIL,
- "Failed to %s EVPN %s route in ESI %s",
- install ? "install"
- : "uninstall",
- prefix2str(evp, buf,
- sizeof(buf)),
- esi_to_str(&es->esi, buf1,
- sizeof(buf1)));
- return ret;
- }
- }
- }
- }
- return 0;
-}
-
/* 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.
@@ -3390,15 +3019,6 @@ static int install_uninstall_routes_for_vni(struct bgp *bgp,
return 0;
}
-/* Install any existing remote ES routes applicable for this ES into its routing
- * table. This is invoked when ES comes up.
- */
-static int install_routes_for_es(struct bgp *bgp, struct evpnes *es)
-{
- return install_uninstall_routes_for_es(bgp, es, 1);
-}
-
-
/* Install any existing remote routes applicable for this VRF into VRF RIB. This
* is invoked upon l3vni-add or l3vni import rt change
*/
@@ -3425,6 +3045,11 @@ static int install_routes_for_vni(struct bgp *bgp, struct bgpevpn *vpn)
if (ret)
return ret;
+ ret = install_uninstall_routes_for_vni(bgp, vpn, BGP_EVPN_AD_ROUTE,
+ 1);
+ if (ret)
+ return ret;
+
return install_uninstall_routes_for_vni(bgp, vpn, BGP_EVPN_MAC_IP_ROUTE,
1);
}
@@ -3453,33 +3078,14 @@ static int uninstall_routes_for_vni(struct bgp *bgp, struct bgpevpn *vpn)
if (ret)
return ret;
- return install_uninstall_routes_for_vni(bgp, vpn, BGP_EVPN_IMET_ROUTE,
- 0);
-}
+ ret = install_uninstall_routes_for_vni(bgp, vpn, BGP_EVPN_AD_ROUTE,
+ 1);
+ if (ret)
+ return ret;
-/* Install or unistall route in ES */
-static int install_uninstall_route_in_es(struct bgp *bgp, struct evpnes *es,
- afi_t afi, safi_t safi,
- struct prefix_evpn *evp,
- struct bgp_path_info *pi, int install)
-{
- int ret = 0;
- char buf[ESI_STR_LEN];
- if (install)
- ret = install_evpn_route_entry_in_es(bgp, es, evp, pi);
- else
- ret = uninstall_evpn_route_entry_in_es(bgp, es, evp, pi);
-
- if (ret) {
- flog_err(
- EC_BGP_EVPN_FAIL,
- "%u: Failed to %s EVPN %s route in ESI %s", bgp->vrf_id,
- install ? "install" : "uninstall", "ES",
- esi_to_str(&evp->prefix.es_addr.esi, buf, sizeof(buf)));
- return ret;
- }
- return 0;
+ return install_uninstall_routes_for_vni(bgp, vpn, BGP_EVPN_IMET_ROUTE,
+ 0);
}
/*
@@ -3576,6 +3182,7 @@ static int install_uninstall_evpn_route(struct bgp *bgp, afi_t afi, safi_t safi,
struct attr *attr = pi->attr;
struct ecommunity *ecom;
int i;
+ struct prefix_evpn ad_evp;
assert(attr);
@@ -3583,6 +3190,7 @@ static int install_uninstall_evpn_route(struct bgp *bgp, afi_t afi, safi_t safi,
if (!(evp->prefix.route_type == BGP_EVPN_MAC_IP_ROUTE
|| evp->prefix.route_type == BGP_EVPN_IMET_ROUTE
|| evp->prefix.route_type == BGP_EVPN_ES_ROUTE
+ || evp->prefix.route_type == BGP_EVPN_AD_ROUTE
|| evp->prefix.route_type == BGP_EVPN_IP_PREFIX_ROUTE))
return 0;
@@ -3590,6 +3198,12 @@ static int install_uninstall_evpn_route(struct bgp *bgp, afi_t afi, safi_t safi,
if (!(attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES)))
return 0;
+ /* EAD prefix in the global table doesn't include the VTEP-IP so
+ * we need to create a different copy for the VNI
+ */
+ if (evp->prefix.route_type == BGP_EVPN_AD_ROUTE)
+ evp = evpn_type1_prefix_vni_copy(&ad_evp, evp, attr->nexthop);
+
ecom = attr->ecommunity;
if (!ecom || !ecom->size)
return -1;
@@ -3603,7 +3217,7 @@ static int install_uninstall_evpn_route(struct bgp *bgp, afi_t afi, safi_t safi,
struct ecommunity_val eval_tmp;
struct irt_node *irt; /* import rt for l2vni */
struct vrf_irt_node *vrf_irt; /* import rt for l3vni */
- struct evpnes *es;
+ struct bgp_evpn_es *es;
/* Only deal with RTs */
pnt = (ecom->val + (i * ECOMMUNITY_SIZE));
@@ -3621,6 +3235,7 @@ static int install_uninstall_evpn_route(struct bgp *bgp, afi_t afi, safi_t safi,
*/
if (evp->prefix.route_type == BGP_EVPN_MAC_IP_ROUTE ||
evp->prefix.route_type == BGP_EVPN_IMET_ROUTE ||
+ evp->prefix.route_type == BGP_EVPN_AD_ROUTE ||
evp->prefix.route_type == BGP_EVPN_IP_PREFIX_ROUTE) {
irt = lookup_import_rt(bgp, eval);
@@ -3668,9 +3283,9 @@ static int install_uninstall_evpn_route(struct bgp *bgp, afi_t afi, safi_t safi,
/* we will match based on the entire esi to avoid
* imoort of an es route for esi2 into esi1
*/
- es = bgp_evpn_lookup_es(bgp, &evp->prefix.es_addr.esi);
- if (es && is_es_local(es))
- install_uninstall_route_in_es(
+ es = bgp_evpn_es_find(&evp->prefix.es_addr.esi);
+ if (es && bgp_evpn_is_es_local(es))
+ bgp_evpn_es_route_install_uninstall(
bgp, es, afi, safi, evp, pi, import);
}
}
@@ -3804,10 +3419,11 @@ static int update_advertise_vni_routes(struct bgp *bgp, struct bgpevpn *vpn)
return 0;
attr = pi->attr;
- global_dest = bgp_afi_node_get(bgp->rib[afi][safi], afi, safi,
- (struct prefix *)&p, &vpn->prd);
+ global_dest = bgp_global_evpn_node_get(bgp->rib[afi][safi],
+ afi, safi, &p, &vpn->prd);
update_evpn_route_entry(bgp, vpn, afi, safi, global_dest, attr,
- 1, &pi, 0, mac_mobility_seqnum(attr));
+ 1, &pi, 0, mac_mobility_seqnum(attr),
+ false /* setup_sync */, NULL /* old_is_sync */);
/* Schedule for processing and unlock node. */
bgp_process(bgp, global_dest, afi, safi);
@@ -3838,12 +3454,13 @@ static int update_advertise_vni_routes(struct bgp *bgp, struct bgpevpn *vpn)
* attribute.
*/
attr = pi->attr;
- global_dest = bgp_afi_node_get(bgp->rib[afi][safi], afi, safi,
- (struct prefix *)evp, &vpn->prd);
+ global_dest = bgp_global_evpn_node_get(bgp->rib[afi][safi], afi, safi,
+ evp, &vpn->prd);
assert(global_dest);
- update_evpn_route_entry(bgp, vpn, afi, safi, global_dest, attr,
- 1, &global_pi, 0,
- mac_mobility_seqnum(attr));
+ update_evpn_route_entry(bgp, vpn, afi, safi, global_dest, attr, 1,
+ &global_pi, 0,
+ mac_mobility_seqnum(attr),
+ false /* setup_sync */, NULL /* old_is_sync */);
/* Schedule for processing and unlock node. */
bgp_process(bgp, global_dest, afi, safi);
@@ -3875,8 +3492,8 @@ static int delete_withdraw_vni_routes(struct bgp *bgp, struct bgpevpn *vpn)
/* Remove type-3 route for this VNI from global table. */
build_evpn_type3_prefix(&p, vpn->originator_ip);
- global_dest = bgp_afi_node_lookup(bgp->rib[afi][safi], afi, safi,
- (struct prefix *)&p, &vpn->prd);
+ global_dest = bgp_global_evpn_node_lookup(bgp->rib[afi][safi], afi, safi,
+ (const struct prefix_evpn *)&p, &vpn->prd);
if (global_dest) {
/* Delete route entry in the global EVPN table. */
delete_evpn_route_entry(bgp, afi, safi, global_dest, &pi);
@@ -3943,7 +3560,7 @@ static void create_advertise_type3(struct hash_bucket *bucket, void *data)
return;
build_evpn_type3_prefix(&p, vpn->originator_ip);
- if (update_evpn_route(bgp, vpn, &p, 0, 0))
+ if (update_evpn_route(bgp, vpn, &p, 0, 0, NULL))
flog_err(EC_BGP_EVPN_ROUTE_CREATE,
"Type3 route creation failure for VNI %u", vpn->vni);
}
@@ -4011,8 +3628,14 @@ static int process_type2_route(struct peer *peer, afi_t afi, safi_t safi,
p.prefix.route_type = BGP_EVPN_MAC_IP_ROUTE;
/* Copy Ethernet Seg Identifier */
- memcpy(&evpn.eth_s_id.val, pfx, ESI_LEN);
- pfx += ESI_LEN;
+ if (attr) {
+ memcpy(&attr->esi, pfx, sizeof(esi_t));
+ if (bgp_evpn_is_esi_local(&attr->esi))
+ attr->es_flags |= ATTR_ES_IS_LOCAL;
+ else
+ attr->es_flags &= ~ATTR_ES_IS_LOCAL;
+ }
+ pfx += sizeof(esi_t);
/* Copy Ethernet Tag */
memcpy(&eth_tag, pfx, 4);
@@ -4165,68 +3788,6 @@ static int process_type3_route(struct peer *peer, afi_t afi, safi_t safi,
}
/*
- * Process received EVPN type-4 route (advertise or withdraw).
- */
-static int process_type4_route(struct peer *peer, afi_t afi, safi_t safi,
- struct attr *attr, uint8_t *pfx, int psize,
- uint32_t addpath_id)
-{
- int ret;
- esi_t esi;
- uint8_t ipaddr_len;
- struct in_addr vtep_ip;
- struct prefix_rd prd;
- struct prefix_evpn p;
-
- /* Type-4 route should be either 23 or 35 bytes
- * RD (8), ESI (10), ip-len (1), ip (4 or 16)
- */
- if (psize != 23 && psize != 35) {
- flog_err(EC_BGP_EVPN_ROUTE_INVALID,
- "%u:%s - Rx EVPN Type-4 NLRI with invalid length %d",
- peer->bgp->vrf_id, peer->host, psize);
- return -1;
- }
-
- /* Make prefix_rd */
- prd.family = AF_UNSPEC;
- prd.prefixlen = 64;
- memcpy(&prd.val, pfx, 8);
- pfx += 8;
-
- /* get the ESI */
- memcpy(&esi, pfx, ESI_BYTES);
- pfx += ESI_BYTES;
-
-
- /* Get the IP. */
- ipaddr_len = *pfx++;
- if (ipaddr_len == IPV4_MAX_BITLEN) {
- memcpy(&vtep_ip, pfx, IPV4_MAX_BYTELEN);
- } else {
- flog_err(
- EC_BGP_EVPN_ROUTE_INVALID,
- "%u:%s - Rx EVPN Type-4 NLRI with unsupported IP address length %d",
- peer->bgp->vrf_id, peer->host, ipaddr_len);
- return -1;
- }
-
- build_evpn_type4_prefix(&p, &esi, vtep_ip);
- /* Process the route. */
- if (attr) {
- ret = bgp_update(peer, (struct prefix *)&p, addpath_id, attr,
- afi, safi, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
- &prd, NULL, 0, 0, NULL);
- } else {
- ret = bgp_withdraw(peer, (struct prefix *)&p, addpath_id, attr,
- afi, safi, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
- &prd, NULL, 0, NULL);
- }
- return ret;
-}
-
-
-/*
* Process received EVPN type-5 route (advertise or withdraw).
*/
static int process_type5_route(struct peer *peer, afi_t afi, safi_t safi,
@@ -4271,8 +3832,9 @@ static int process_type5_route(struct peer *peer, afi_t afi, safi_t safi,
memset(&evpn, 0, sizeof(evpn));
/* Fetch ESI */
- memcpy(&evpn.eth_s_id.val, pfx, 10);
- pfx += 10;
+ if (attr)
+ memcpy(&attr->esi, pfx, sizeof(esi_t));
+ pfx += ESI_BYTES;
/* Fetch Ethernet Tag. */
memcpy(&eth_tag, pfx, 4);
@@ -4322,7 +3884,7 @@ static int process_type5_route(struct peer *peer, afi_t afi, safi_t safi,
if (attr) {
is_valid_update = true;
- if (is_zero_mac(&attr->rmac) && is_zero_esi(&evpn.eth_s_id) &&
+ if (is_zero_mac(&attr->rmac) &&
is_zero_gw_ip(&evpn.gw_ip, gw_afi))
is_valid_update = false;
@@ -4368,9 +3930,9 @@ static void evpn_mpattr_encode_type5(struct stream *s, const struct prefix *p,
stream_putc(s, 8 + 10 + 4 + 1 + len + 3);
stream_put(s, prd->val, 8);
if (attr)
- stream_put(s, &(attr->evpn_overlay.eth_s_id), 10);
+ stream_put(s, &attr->esi, sizeof(esi_t));
else
- stream_put(s, &temp, 10);
+ stream_put(s, 0, sizeof(esi_t));
stream_putl(s, p_evpn_p->prefix_addr.eth_tag);
stream_putc(s, p_evpn_p->prefix_addr.ip_prefix_length);
if (IS_IPADDR_V4(&p_evpn_p->prefix_addr.ip))
@@ -5073,6 +4635,15 @@ char *bgp_evpn_route2str(const struct prefix_evpn *p, char *buf, int len)
is_evpn_prefix_ipaddr_v4(p) ? IPV4_MAX_BITLEN
: IPV6_MAX_BITLEN,
inet_ntoa(p->prefix.es_addr.ip.ipaddr_v4));
+ } else if (p->prefix.route_type == BGP_EVPN_AD_ROUTE) {
+ snprintf(buf, len, "[%d]:[%u]:[%s]:[%d]:[%s]",
+ p->prefix.route_type,
+ p->prefix.ead_addr.eth_tag,
+ esi_to_str(&p->prefix.ead_addr.esi,
+ buf3, sizeof(buf3)),
+ is_evpn_prefix_ipaddr_v4(p) ? IPV4_MAX_BITLEN
+ : IPV6_MAX_BITLEN,
+ inet_ntoa(p->prefix.ead_addr.ip.ipaddr_v4));
} else {
/* For EVPN route types not supported yet. */
snprintf(buf, len, "(unsupported route type %d)",
@@ -5112,7 +4683,7 @@ void bgp_evpn_encode_prefix(struct stream *s, const struct prefix *p,
stream_putc(s, len);
stream_put(s, prd->val, 8); /* RD */
if (attr)
- stream_put(s, &attr->evpn_overlay.eth_s_id, ESI_LEN);
+ stream_put(s, &attr->esi, ESI_BYTES);
else
stream_put(s, 0, 10);
stream_putl(s, evp->prefix.macip_addr.eth_tag); /* Ethernet Tag ID */
@@ -5147,6 +4718,16 @@ void bgp_evpn_encode_prefix(struct stream *s, const struct prefix *p,
stream_put_in_addr(s, &evp->prefix.es_addr.ip.ipaddr_v4);
break;
+ case BGP_EVPN_AD_ROUTE:
+ /* RD, ESI, EthTag, 1 VNI */
+ len = RD_BYTES + ESI_BYTES + EVPN_ETH_TAG_BYTES + BGP_LABEL_BYTES;
+ stream_putc(s, len);
+ stream_put(s, prd->val, RD_BYTES); /* RD */
+ stream_put(s, evp->prefix.ead_addr.esi.val, ESI_BYTES); /* ESI */
+ stream_putl(s, evp->prefix.ead_addr.eth_tag); /* Ethernet Tag */
+ stream_put(s, label, BGP_LABEL_BYTES);
+ break;
+
case BGP_EVPN_IP_PREFIX_ROUTE:
/* TODO: AddPath support. */
evpn_mpattr_encode_type5(s, p, prd, label, num_labels, attr);
@@ -5234,7 +4815,7 @@ int bgp_nlri_parse_evpn(struct peer *peer, struct attr *attr,
break;
case BGP_EVPN_ES_ROUTE:
- if (process_type4_route(peer, afi, safi,
+ if (bgp_evpn_type4_route_process(peer, afi, safi,
withdraw ? NULL : attr, pnt,
psize, addpath_id)) {
flog_err(
@@ -5245,6 +4826,18 @@ int bgp_nlri_parse_evpn(struct peer *peer, struct attr *attr,
}
break;
+ case BGP_EVPN_AD_ROUTE:
+ if (bgp_evpn_type1_route_process(peer, afi, safi,
+ withdraw ? NULL : attr, pnt,
+ psize, addpath_id)) {
+ flog_err(
+ EC_BGP_PKT_PROCESS,
+ "%u:%s - Error in processing EVPN type-1 NLRI size %d",
+ peer->bgp->vrf_id, peer->host, psize);
+ return BGP_NLRI_PARSE_ERROR_EVPN_TYPE1_SIZE;
+ }
+ break;
+
case BGP_EVPN_IP_PREFIX_ROUTE:
if (process_type5_route(peer, afi, safi,
withdraw ? NULL : attr, pnt,
@@ -5423,7 +5016,7 @@ void bgp_evpn_derive_auto_rd_for_vrf(struct bgp *bgp)
*/
void bgp_evpn_derive_auto_rd(struct bgp *bgp, struct bgpevpn *vpn)
{
- char buf[100];
+ char buf[BGP_EVPN_PREFIX_RD_LEN];
vpn->prd.family = AF_UNSPEC;
vpn->prd.prefixlen = 64;
@@ -5507,6 +5100,8 @@ struct bgpevpn *bgp_evpn_new(struct bgp *bgp, vni_t vni,
/* add to l2vni list on corresponding vrf */
bgpevpn_link_to_l3vni(vpn);
+ bgp_evpn_vni_es_init(vpn);
+
QOBJ_REG(vpn, bgpevpn);
return vpn;
}
@@ -5519,6 +5114,7 @@ struct bgpevpn *bgp_evpn_new(struct bgp *bgp, vni_t vni,
*/
void bgp_evpn_free(struct bgp *bgp, struct bgpevpn *vpn)
{
+ bgp_evpn_vni_es_cleanup(vpn);
bgpevpn_unlink_from_l3vni(vpn);
bgp_table_unlock(vpn->route_table);
bgp_evpn_unmap_vni_from_its_rts(bgp, vpn);
@@ -5531,79 +5127,6 @@ void bgp_evpn_free(struct bgp *bgp, struct bgpevpn *vpn)
}
/*
- * Lookup local ES.
- */
-struct evpnes *bgp_evpn_lookup_es(struct bgp *bgp, esi_t *esi)
-{
- struct evpnes *es;
- struct evpnes tmp;
-
- memset(&tmp, 0, sizeof(struct evpnes));
- memcpy(&tmp.esi, esi, sizeof(esi_t));
- es = hash_lookup(bgp->esihash, &tmp);
- return es;
-}
-
-/*
- * Create a new local es - invoked upon zebra notification.
- */
-struct evpnes *bgp_evpn_es_new(struct bgp *bgp,
- esi_t *esi,
- struct ipaddr *originator_ip)
-{
- char buf[100];
- struct evpnes *es;
-
- if (!bgp)
- return NULL;
-
- es = XCALLOC(MTYPE_BGP_EVPN_ES, sizeof(struct evpnes));
-
- /* set the ESI and originator_ip */
- memcpy(&es->esi, esi, sizeof(esi_t));
- memcpy(&es->originator_ip, originator_ip, sizeof(struct ipaddr));
-
- /* Initialise the VTEP list */
- es->vtep_list = list_new();
- es->vtep_list->cmp = evpn_vtep_ip_cmp;
-
- /* auto derive RD for this es */
- bf_assign_index(bm->rd_idspace, es->rd_id);
- es->prd.family = AF_UNSPEC;
- es->prd.prefixlen = 64;
- snprintf(buf, sizeof(buf), "%s:%hu", inet_ntoa(bgp->router_id),
- es->rd_id);
- (void)str2prefix_rd(buf, &es->prd);
-
- /* Initialize the ES route table */
- es->route_table = bgp_table_init(bgp, AFI_L2VPN, SAFI_EVPN);
-
- /* Add to hash */
- if (!hash_get(bgp->esihash, es, hash_alloc_intern)) {
- XFREE(MTYPE_BGP_EVPN_ES, es);
- return NULL;
- }
-
- QOBJ_REG(es, evpnes);
- return es;
-}
-
-/*
- * Free a given ES -
- * This just frees appropriate memory, caller should have taken other
- * needed actions.
- */
-void bgp_evpn_es_free(struct bgp *bgp, struct evpnes *es)
-{
- list_delete(&es->vtep_list);
- bgp_table_unlock(es->route_table);
- bf_release_index(bm->rd_idspace, es->rd_id);
- hash_release(bgp->esihash, es);
- QOBJ_UNREG(es);
- XFREE(MTYPE_BGP_EVPN_ES, es);
-}
-
-/*
* Import evpn route from global table to VNI/VRF/ESI.
*/
int bgp_evpn_import_route(struct bgp *bgp, afi_t afi, safi_t safi,
@@ -5724,7 +5247,7 @@ int bgp_evpn_local_macip_del(struct bgp *bgp, vni_t vni, struct ethaddr *mac,
* Handle add of a local MACIP.
*/
int bgp_evpn_local_macip_add(struct bgp *bgp, vni_t vni, struct ethaddr *mac,
- struct ipaddr *ip, uint8_t flags, uint32_t seq)
+ struct ipaddr *ip, uint8_t flags, uint32_t seq, esi_t *esi)
{
struct bgpevpn *vpn;
struct prefix_evpn p;
@@ -5740,7 +5263,7 @@ int bgp_evpn_local_macip_add(struct bgp *bgp, vni_t vni, struct ethaddr *mac,
/* Create EVPN type-2 route and schedule for processing. */
build_evpn_type2_prefix(&p, mac, ip);
- if (update_evpn_route(bgp, vpn, &p, flags, seq)) {
+ if (update_evpn_route(bgp, vpn, &p, flags, seq, esi)) {
char buf[ETHER_ADDR_STRLEN];
char buf2[INET6_ADDRSTRLEN];
@@ -6112,7 +5635,7 @@ int bgp_evpn_local_vni_add(struct bgp *bgp, vni_t vni,
if (bgp_evpn_vni_flood_mode_get(bgp, vpn)
== VXLAN_FLOOD_HEAD_END_REPL) {
build_evpn_type3_prefix(&p, vpn->originator_ip);
- if (update_evpn_route(bgp, vpn, &p, 0, 0)) {
+ if (update_evpn_route(bgp, vpn, &p, 0, 0, NULL)) {
flog_err(EC_BGP_EVPN_ROUTE_CREATE,
"%u: Type3 route creation failure for VNI %u",
bgp->vrf_id, vni);
@@ -6137,88 +5660,6 @@ int bgp_evpn_local_vni_add(struct bgp *bgp, vni_t vni,
}
/*
- * bgp_evpn_local_es_del
- */
-int bgp_evpn_local_es_del(struct bgp *bgp,
- esi_t *esi,
- struct ipaddr *originator_ip)
-{
- char buf[ESI_STR_LEN];
- struct evpnes *es = NULL;
-
- if (!bgp->esihash) {
- flog_err(EC_BGP_ES_CREATE, "%u: ESI hash not yet created",
- bgp->vrf_id);
- return -1;
- }
-
- /* Lookup ESI hash - should exist. */
- es = bgp_evpn_lookup_es(bgp, esi);
- if (!es) {
- flog_warn(EC_BGP_EVPN_ESI,
- "%u: ESI hash entry for ESI %s at Local ES DEL",
- bgp->vrf_id, esi_to_str(esi, buf, sizeof(buf)));
- return -1;
- }
-
- /* Delete all local EVPN ES routes from ESI table
- * and schedule for processing (to withdraw from peers))
- */
- delete_routes_for_es(bgp, es);
-
- /* free the hash entry */
- bgp_evpn_es_free(bgp, es);
-
- return 0;
-}
-
-/*
- * bgp_evpn_local_es_add
- */
-int bgp_evpn_local_es_add(struct bgp *bgp,
- esi_t *esi,
- struct ipaddr *originator_ip)
-{
- char buf[ESI_STR_LEN];
- struct evpnes *es = NULL;
- struct prefix_evpn p;
-
- if (!bgp->esihash) {
- flog_err(EC_BGP_ES_CREATE, "%u: ESI hash not yet created",
- bgp->vrf_id);
- return -1;
- }
-
- /* create the new es */
- es = bgp_evpn_lookup_es(bgp, esi);
- if (!es) {
- es = bgp_evpn_es_new(bgp, esi, originator_ip);
- if (!es) {
- flog_err(
- EC_BGP_ES_CREATE,
- "%u: Failed to allocate ES entry for ESI %s - at Local ES Add",
- bgp->vrf_id, esi_to_str(esi, buf, sizeof(buf)));
- return -1;
- }
- }
- UNSET_FLAG(es->flags, EVPNES_REMOTE);
- SET_FLAG(es->flags, EVPNES_LOCAL);
-
- build_evpn_type4_prefix(&p, esi, originator_ip->ipaddr_v4);
- if (update_evpn_type4_route(bgp, es, &p)) {
- flog_err(EC_BGP_EVPN_ROUTE_CREATE,
- "%u: Type4 route creation failure for ESI %s",
- bgp->vrf_id, esi_to_str(esi, buf, sizeof(buf)));
- return -1;
- }
-
- /* import all remote ES routes in th ES table */
- install_routes_for_es(bgp, es);
-
- return 0;
-}
-
-/*
* Handle change in setting for BUM handling. The supported values
* are head-end replication and dropping all BUM packets. Any change
* should be registered with zebra. Also, if doing head-end replication,
@@ -6267,9 +5708,6 @@ void bgp_evpn_cleanup(struct bgp *bgp)
hash_free(bgp->vnihash);
bgp->vnihash = NULL;
- if (bgp->esihash)
- hash_free(bgp->esihash);
- bgp->esihash = NULL;
list_delete(&bgp->vrf_import_rtl);
list_delete(&bgp->vrf_export_rtl);
@@ -6286,9 +5724,6 @@ void bgp_evpn_init(struct bgp *bgp)
{
bgp->vnihash =
hash_create(vni_hash_key_make, vni_hash_cmp, "BGP VNI Hash");
- bgp->esihash =
- hash_create(esi_hash_keymake, esi_cmp,
- "BGP EVPN Local ESI Hash");
bgp->import_rt_hash =
hash_create(import_rt_hash_key_make, import_rt_hash_cmp,
"BGP Import RT Hash");
diff --git a/bgpd/bgp_evpn.h b/bgpd/bgp_evpn.h
index 267c87ee54..8535f1fa31 100644
--- a/bgpd/bgp_evpn.h
+++ b/bgpd/bgp_evpn.h
@@ -176,7 +176,7 @@ extern int bgp_evpn_local_macip_del(struct bgp *bgp, vni_t vni,
int state);
extern int bgp_evpn_local_macip_add(struct bgp *bgp, vni_t vni,
struct ethaddr *mac, struct ipaddr *ip,
- uint8_t flags, uint32_t seq);
+ uint8_t flags, uint32_t seq, esi_t *esi);
extern int bgp_evpn_local_l3vni_add(vni_t vni, vrf_id_t vrf_id,
struct ethaddr *rmac,
struct ethaddr *vrr_rmac,
@@ -188,10 +188,6 @@ extern int bgp_evpn_local_vni_add(struct bgp *bgp, vni_t vni,
struct in_addr originator_ip,
vrf_id_t tenant_vrf_id,
struct in_addr mcast_grp);
-extern int bgp_evpn_local_es_add(struct bgp *bgp, esi_t *esi,
- struct ipaddr *originator_ip);
-extern int bgp_evpn_local_es_del(struct bgp *bgp, esi_t *esi,
- struct ipaddr *originator_ip);
extern void bgp_evpn_flood_control_change(struct bgp *bgp);
extern void bgp_evpn_cleanup_on_disable(struct bgp *bgp);
extern void bgp_evpn_cleanup(struct bgp *bgp);
diff --git a/bgpd/bgp_evpn_mh.c b/bgpd/bgp_evpn_mh.c
new file mode 100644
index 0000000000..eb65c43bb9
--- /dev/null
+++ b/bgpd/bgp_evpn_mh.c
@@ -0,0 +1,2905 @@
+/* EVPN Multihoming procedures
+ *
+ * Copyright (C) 2019 Cumulus Networks, Inc.
+ * Anuradha Karuppiah
+ *
+ * This file is part of FRR.
+ *
+ * FRRouting is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2, or (at your option) any
+ * later version.
+ *
+ * FRRouting is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ */
+
+#include <zebra.h>
+
+#include "command.h"
+#include "filter.h"
+#include "prefix.h"
+#include "log.h"
+#include "memory.h"
+#include "stream.h"
+#include "hash.h"
+#include "jhash.h"
+#include "zclient.h"
+
+#include "bgpd/bgp_attr_evpn.h"
+#include "bgpd/bgpd.h"
+#include "bgpd/bgp_table.h"
+#include "bgpd/bgp_route.h"
+#include "bgpd/bgp_attr.h"
+#include "bgpd/bgp_mplsvpn.h"
+#include "bgpd/bgp_evpn.h"
+#include "bgpd/bgp_evpn_private.h"
+#include "bgpd/bgp_evpn_mh.h"
+#include "bgpd/bgp_ecommunity.h"
+#include "bgpd/bgp_encap_types.h"
+#include "bgpd/bgp_debug.h"
+#include "bgpd/bgp_errors.h"
+#include "bgpd/bgp_aspath.h"
+#include "bgpd/bgp_zebra.h"
+#include "bgpd/bgp_addpath.h"
+#include "bgpd/bgp_label.h"
+
+static void bgp_evpn_local_es_down(struct bgp *bgp,
+ struct bgp_evpn_es *es);
+static void bgp_evpn_local_type1_evi_route_del(struct bgp *bgp,
+ struct bgp_evpn_es *es);
+static struct bgp_evpn_es_vtep *bgp_evpn_es_vtep_add(struct bgp *bgp,
+ struct bgp_evpn_es *es, struct in_addr vtep_ip, bool esr);
+static void bgp_evpn_es_vtep_del(struct bgp *bgp,
+ struct bgp_evpn_es *es, struct in_addr vtep_ip, bool esr);
+static void bgp_evpn_es_cons_checks_pend_add(struct bgp_evpn_es *es);
+static void bgp_evpn_es_cons_checks_pend_del(struct bgp_evpn_es *es);
+static void bgp_evpn_local_es_evi_do_del(struct bgp_evpn_es_evi *es_evi);
+
+esi_t zero_esi_buf, *zero_esi = &zero_esi_buf;
+
+/******************************************************************************
+ * per-ES (Ethernet Segment) routing table
+ *
+ * Following routes are added to the ES's routing table -
+ * 1. Local and remote ESR (Type-4)
+ * 2. Local EAD-per-ES (Type-1).
+ *
+ * Key for these routes is {ESI, VTEP-IP} so the path selection is practically
+ * a no-op i.e. all paths lead to same VTEP-IP (i.e. result in the same VTEP
+ * being added to same ES).
+ *
+ * Note the following routes go into the VNI routing table (instead of the
+ * ES routing table) -
+ * 1. Remote EAD-per-ES
+ * 2. Local and remote EAD-per-EVI
+ */
+
+/* Calculate the best path for a multi-homing (Type-1 or Type-4) route
+ * installed in the ES's routing table.
+ */
+static int bgp_evpn_es_route_select_install(struct bgp *bgp,
+ struct bgp_evpn_es *es,
+ struct bgp_node *rn)
+{
+ int ret = 0;
+ afi_t afi = AFI_L2VPN;
+ safi_t safi = SAFI_EVPN;
+ struct bgp_path_info *old_select; /* old best */
+ struct bgp_path_info *new_select; /* new best */
+ struct bgp_path_info_pair old_and_new;
+
+ /* Compute the best path. */
+ bgp_best_selection(bgp, rn, &bgp->maxpaths[afi][safi],
+ &old_and_new, afi, safi);
+ old_select = old_and_new.old;
+ new_select = old_and_new.new;
+
+ /*
+ * If the best path hasn't changed - see if something needs to be
+ * updated
+ */
+ if (old_select && old_select == new_select
+ && old_select->type == ZEBRA_ROUTE_BGP
+ && old_select->sub_type == BGP_ROUTE_IMPORTED
+ && !CHECK_FLAG(rn->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 (bgp_zebra_has_route_changed(old_select)) {
+ bgp_evpn_es_vtep_add(bgp, es,
+ old_select->attr->nexthop,
+ true /*esr*/);
+ }
+ UNSET_FLAG(old_select->flags, BGP_PATH_MULTIPATH_CHG);
+ bgp_zebra_clear_route_change_flags(rn);
+ return ret;
+ }
+
+ /* If the user did a "clear" this flag will be set */
+ UNSET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
+
+ /* bestpath has changed; update relevant fields and install or uninstall
+ * into the zebra RIB.
+ */
+ if (old_select || new_select)
+ bgp_bump_version(rn);
+
+ if (old_select)
+ bgp_path_info_unset_flag(rn, old_select, BGP_PATH_SELECTED);
+ if (new_select) {
+ bgp_path_info_set_flag(rn, new_select, BGP_PATH_SELECTED);
+ bgp_path_info_unset_flag(rn, new_select, BGP_PATH_ATTR_CHANGED);
+ UNSET_FLAG(new_select->flags, BGP_PATH_MULTIPATH_CHG);
+ }
+
+ if (new_select && new_select->type == ZEBRA_ROUTE_BGP
+ && new_select->sub_type == BGP_ROUTE_IMPORTED) {
+ bgp_evpn_es_vtep_add(bgp, es,
+ new_select->attr->nexthop, true /*esr */);
+ } else {
+ if (old_select && old_select->type == ZEBRA_ROUTE_BGP
+ && old_select->sub_type == BGP_ROUTE_IMPORTED)
+ bgp_evpn_es_vtep_del(
+ bgp, es, old_select->attr->nexthop,
+ true /*esr*/);
+ }
+
+ /* Clear any route change flags. */
+ bgp_zebra_clear_route_change_flags(rn);
+
+ /* 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(rn, old_select);
+
+ return ret;
+}
+
+/* Install Type-1/Type-4 route entry in the per-ES routing table */
+static int bgp_evpn_es_route_install(struct bgp *bgp,
+ struct bgp_evpn_es *es, struct prefix_evpn *p,
+ struct bgp_path_info *parent_pi)
+{
+ int ret = 0;
+ struct bgp_node *rn = NULL;
+ struct bgp_path_info *pi = NULL;
+ struct attr *attr_new = NULL;
+
+ /* Create (or fetch) route within the VNI.
+ * NOTE: There is no RD here.
+ */
+ rn = bgp_node_get(es->route_table, (struct prefix *)p);
+
+ /* Check if route entry is already present. */
+ for (pi = bgp_dest_get_bgp_path_info(rn); pi; pi = pi->next)
+ if (pi->extra
+ && (struct bgp_path_info *)pi->extra->parent ==
+ parent_pi)
+ break;
+
+ if (!pi) {
+ /* Add (or update) attribute to hash. */
+ attr_new = bgp_attr_intern(parent_pi->attr);
+
+ /* Create new route with its attribute. */
+ pi = info_make(parent_pi->type, BGP_ROUTE_IMPORTED, 0,
+ parent_pi->peer, attr_new, rn);
+ SET_FLAG(pi->flags, BGP_PATH_VALID);
+ bgp_path_info_extra_get(pi);
+ pi->extra->parent = bgp_path_info_lock(parent_pi);
+ bgp_dest_lock_node((struct bgp_node *)parent_pi->net);
+ bgp_path_info_add(rn, pi);
+ } else {
+ if (attrhash_cmp(pi->attr, parent_pi->attr)
+ && !CHECK_FLAG(pi->flags, BGP_PATH_REMOVED)) {
+ bgp_dest_unlock_node(rn);
+ return 0;
+ }
+ /* The attribute has changed. */
+ /* Add (or update) attribute to hash. */
+ attr_new = bgp_attr_intern(parent_pi->attr);
+
+ /* Restore route, if needed. */
+ if (CHECK_FLAG(pi->flags, BGP_PATH_REMOVED))
+ bgp_path_info_restore(rn, pi);
+
+ /* Mark if nexthop has changed. */
+ if (!IPV4_ADDR_SAME(&pi->attr->nexthop, &attr_new->nexthop))
+ SET_FLAG(pi->flags, BGP_PATH_IGP_CHANGED);
+
+ /* Unintern existing, set to new. */
+ bgp_attr_unintern(&pi->attr);
+ pi->attr = attr_new;
+ pi->uptime = bgp_clock();
+ }
+
+ /* Perform route selection and update zebra, if required. */
+ ret = bgp_evpn_es_route_select_install(bgp, es, rn);
+
+ bgp_dest_unlock_node(rn);
+
+ return ret;
+}
+
+/* Uninstall Type-1/Type-4 route entry from the ES routing table */
+static int bgp_evpn_es_route_uninstall(struct bgp *bgp, struct bgp_evpn_es *es,
+ struct prefix_evpn *p, struct bgp_path_info *parent_pi)
+{
+ int ret;
+ struct bgp_node *rn;
+ struct bgp_path_info *pi;
+
+ if (!es->route_table)
+ return 0;
+
+ /* Locate route within the ESI.
+ * NOTE: There is no RD here.
+ */
+ rn = bgp_node_lookup(es->route_table, (struct prefix *)p);
+ if (!rn)
+ return 0;
+
+ /* Find matching route entry. */
+ for (pi = bgp_dest_get_bgp_path_info(rn); pi; pi = pi->next)
+ if (pi->extra
+ && (struct bgp_path_info *)pi->extra->parent ==
+ parent_pi)
+ break;
+
+ if (!pi)
+ return 0;
+
+ /* Mark entry for deletion */
+ bgp_path_info_delete(rn, pi);
+
+ /* Perform route selection and update zebra, if required. */
+ ret = bgp_evpn_es_route_select_install(bgp, es, rn);
+
+ /* Unlock route node. */
+ bgp_dest_unlock_node(rn);
+
+ return ret;
+}
+
+/* Install or unistall a Tyoe-4 route in the per-ES routing table */
+int bgp_evpn_es_route_install_uninstall(struct bgp *bgp, struct bgp_evpn_es *es,
+ afi_t afi, safi_t safi, struct prefix_evpn *evp,
+ struct bgp_path_info *pi, int install)
+{
+ int ret = 0;
+
+ if (install)
+ ret = bgp_evpn_es_route_install(bgp, es, evp, pi);
+ else
+ ret = bgp_evpn_es_route_uninstall(bgp, es, evp, pi);
+
+ if (ret) {
+ flog_err(
+ EC_BGP_EVPN_FAIL,
+ "%u: Failed to %s EVPN %s route in ESI %s",
+ bgp->vrf_id,
+ install ? "install" : "uninstall",
+ "ES", es->esi_str);
+ return ret;
+ }
+ return 0;
+}
+
+/* Delete (and withdraw) local routes for specified ES from global and ES table.
+ * Also remove all remote routes from the per ES table. Invoked when ES
+ * is deleted.
+ */
+static void bgp_evpn_es_route_del_all(struct bgp *bgp, struct bgp_evpn_es *es)
+{
+ struct bgp_node *rn;
+ struct bgp_path_info *pi, *nextpi;
+
+ /* de-activate the ES */
+ bgp_evpn_local_es_down(bgp, es);
+ bgp_evpn_local_type1_evi_route_del(bgp, es);
+
+ /* Walk this ES's routing table and delete all routes. */
+ for (rn = bgp_table_top(es->route_table); rn;
+ rn = bgp_route_next(rn)) {
+ for (pi = bgp_dest_get_bgp_path_info(rn);
+ (pi != NULL) && (nextpi = pi->next, 1);
+ pi = nextpi) {
+ bgp_path_info_delete(rn, pi);
+ bgp_path_info_reap(rn, pi);
+ }
+ }
+}
+
+/*****************************************************************************
+ * Base APIs for creating MH routes (Type-1 or Type-4) on local ethernet
+ * segment updates.
+ */
+
+/* create or update local EVPN type1/type4 route entry.
+ *
+ * This could be in -
+ * the ES table if ESR/EAD-ES (or)
+ * the VNI table if EAD-EVI (or)
+ * the global table if ESR/EAD-ES/EAD-EVI
+ *
+ * Note: vpn is applicable only to EAD-EVI routes (NULL for EAD-ES and
+ * ESR).
+ */
+static int bgp_evpn_mh_route_update(struct bgp *bgp,
+ struct bgp_evpn_es *es, struct bgpevpn *vpn, afi_t afi,
+ safi_t safi, struct bgp_node *rn, struct attr *attr,
+ int add, struct bgp_path_info **ri, int *route_changed)
+{
+ struct bgp_path_info *tmp_pi = NULL;
+ struct bgp_path_info *local_pi = NULL; /* local route entry if any */
+ struct bgp_path_info *remote_pi = NULL; /* remote route entry if any */
+ struct attr *attr_new = NULL;
+ struct prefix_evpn *evp;
+
+ *ri = NULL;
+ evp = (struct prefix_evpn *)&rn->p;
+ *route_changed = 1;
+
+ /* locate the local and remote entries if any */
+ for (tmp_pi = bgp_dest_get_bgp_path_info(rn); tmp_pi;
+ tmp_pi = tmp_pi->next) {
+ if (tmp_pi->peer == bgp->peer_self
+ && tmp_pi->type == ZEBRA_ROUTE_BGP
+ && tmp_pi->sub_type == BGP_ROUTE_STATIC)
+ local_pi = tmp_pi;
+ if (tmp_pi->type == ZEBRA_ROUTE_BGP
+ && tmp_pi->sub_type == BGP_ROUTE_IMPORTED
+ && CHECK_FLAG(tmp_pi->flags, BGP_PATH_VALID))
+ remote_pi = tmp_pi;
+ }
+
+ /* we don't expect to see a remote_ri at this point as
+ * an ES route has {esi, vtep_ip} as the key in the ES-rt-table
+ * in the VNI-rt-table.
+ */
+ if (remote_pi) {
+ flog_err(
+ EC_BGP_ES_INVALID,
+ "%u ERROR: local es route for ESI: %s Vtep %s also learnt from remote",
+ bgp->vrf_id, es->esi_str,
+ inet_ntoa(es->originator_ip));
+ return -1;
+ }
+
+ if (!local_pi && !add)
+ return 0;
+
+ /* create or update the entry */
+ if (!local_pi) {
+
+ /* Add or update attribute to hash */
+ attr_new = bgp_attr_intern(attr);
+
+ /* Create new route with its attribute. */
+ tmp_pi = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0,
+ bgp->peer_self, attr_new, rn);
+ SET_FLAG(tmp_pi->flags, BGP_PATH_VALID);
+
+ if (evp->prefix.route_type == BGP_EVPN_AD_ROUTE) {
+ bgp_path_info_extra_get(tmp_pi);
+ tmp_pi->extra->num_labels = 1;
+ if (vpn)
+ vni2label(vpn->vni, &tmp_pi->extra->label[0]);
+ else
+ tmp_pi->extra->label[0] = 0;
+ }
+
+ /* add the newly created path to the route-node */
+ bgp_path_info_add(rn, tmp_pi);
+ } else {
+ tmp_pi = local_pi;
+ if (attrhash_cmp(tmp_pi->attr, attr)
+ && !CHECK_FLAG(tmp_pi->flags, BGP_PATH_REMOVED))
+ *route_changed = 0;
+ else {
+ /* The attribute has changed.
+ * Add (or update) attribute to hash.
+ */
+ attr_new = bgp_attr_intern(attr);
+ bgp_path_info_set_flag(rn, tmp_pi,
+ BGP_PATH_ATTR_CHANGED);
+
+ /* Restore route, if needed. */
+ if (CHECK_FLAG(tmp_pi->flags, BGP_PATH_REMOVED))
+ bgp_path_info_restore(rn, tmp_pi);
+
+ /* Unintern existing, set to new. */
+ bgp_attr_unintern(&tmp_pi->attr);
+ tmp_pi->attr = attr_new;
+ tmp_pi->uptime = bgp_clock();
+ }
+ }
+
+ if (*route_changed) {
+ if (BGP_DEBUG(evpn_mh, EVPN_MH_RT))
+ zlog_debug("local ES %s vni %u route-type %s nexthop %s updated",
+ es->esi_str,
+ vpn ? vpn->vni : 0,
+ evp->prefix.route_type ==
+ BGP_EVPN_ES_ROUTE ? "esr" :
+ (vpn ? "ead-evi" : "ead-es"),
+ inet_ntoa(attr->mp_nexthop_global_in));
+ }
+
+ /* Return back the route entry. */
+ *ri = tmp_pi;
+ return 0;
+}
+
+/* Delete local EVPN ESR (type-4) and EAD (type-1) route
+ *
+ * Note: vpn is applicable only to EAD-EVI routes (NULL for EAD-ES and
+ * ESR).
+ */
+static int bgp_evpn_mh_route_delete(struct bgp *bgp, struct bgp_evpn_es *es,
+ struct bgpevpn *vpn, struct prefix_evpn *p)
+{
+ afi_t afi = AFI_L2VPN;
+ safi_t safi = SAFI_EVPN;
+ struct bgp_path_info *pi;
+ struct bgp_node *rn = NULL; /* rn in esi table */
+ struct bgp_node *global_rn = NULL; /* rn in global table */
+ struct bgp_table *rt_table;
+ struct prefix_rd *prd;
+
+ if (vpn) {
+ rt_table = vpn->route_table;
+ prd = &vpn->prd;
+ } else {
+ rt_table = es->route_table;
+ prd = &es->prd;
+ }
+
+ /* First, locate the route node within the ESI or VNI.
+ * If it doesn't exist, ther is nothing to do.
+ * Note: there is no RD here.
+ */
+ rn = bgp_node_lookup(rt_table, (struct prefix *)p);
+ if (!rn)
+ return 0;
+
+ if (BGP_DEBUG(evpn_mh, EVPN_MH_RT))
+ zlog_debug("local ES %s vni %u route-type %s nexthop %s delete",
+ es->esi_str,
+ vpn ? vpn->vni : 0,
+ p->prefix.route_type == BGP_EVPN_ES_ROUTE ?
+ "esr" : (vpn ? "ead-evi" : "ead-es"),
+ inet_ntoa(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)
+ */
+ global_rn = bgp_global_evpn_node_lookup(bgp->rib[afi][safi], afi, safi,
+ (const struct prefix_evpn *)p, prd);
+ if (global_rn) {
+
+ /* Delete route entry in the global EVPN table. */
+ delete_evpn_route_entry(bgp, afi, safi, global_rn, &pi);
+
+ /* Schedule for processing - withdraws to peers happen from
+ * this table.
+ */
+ if (pi)
+ bgp_process(bgp, global_rn, afi, safi);
+ bgp_dest_unlock_node(global_rn);
+ }
+
+ /*
+ * Delete route entry in the ESI or VNI routing table.
+ * This can just be removed.
+ */
+ delete_evpn_route_entry(bgp, afi, safi, rn, &pi);
+ if (pi)
+ bgp_path_info_reap(rn, pi);
+ bgp_dest_unlock_node(rn);
+ return 0;
+}
+
+/*****************************************************************************
+ * Ethernet Segment (Type-4) Routes
+ * ESRs are used for BUM handling. XXX - BUM support is planned for phase-2 i.e.
+ * this code is just a place holder for now
+ */
+/* Build extended community for EVPN ES (type-4) route */
+static void bgp_evpn_type4_route_extcomm_build(struct bgp_evpn_es *es,
+ struct attr *attr)
+{
+ struct ecommunity ecom_encap;
+ struct ecommunity ecom_es_rt;
+ struct ecommunity_val eval;
+ struct ecommunity_val eval_es_rt;
+ bgp_encap_types tnl_type;
+ struct ethaddr mac;
+
+ /* Encap */
+ tnl_type = BGP_ENCAP_TYPE_VXLAN;
+ memset(&ecom_encap, 0, sizeof(ecom_encap));
+ encode_encap_extcomm(tnl_type, &eval);
+ ecom_encap.size = 1;
+ ecom_encap.val = (uint8_t *)eval.val;
+ attr->ecommunity = ecommunity_dup(&ecom_encap);
+
+ /* ES import RT */
+ memset(&mac, 0, sizeof(struct ethaddr));
+ memset(&ecom_es_rt, 0, sizeof(ecom_es_rt));
+ es_get_system_mac(&es->esi, &mac);
+ encode_es_rt_extcomm(&eval_es_rt, &mac);
+ ecom_es_rt.size = 1;
+ ecom_es_rt.val = (uint8_t *)eval_es_rt.val;
+ attr->ecommunity =
+ ecommunity_merge(attr->ecommunity, &ecom_es_rt);
+
+ attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES);
+}
+
+/* Create or update local type-4 route */
+static int bgp_evpn_type4_route_update(struct bgp *bgp,
+ struct bgp_evpn_es *es, struct prefix_evpn *p)
+{
+ int ret = 0;
+ int route_changed = 0;
+ afi_t afi = AFI_L2VPN;
+ safi_t safi = SAFI_EVPN;
+ struct attr attr;
+ struct attr *attr_new = NULL;
+ struct bgp_node *rn = NULL;
+ struct bgp_path_info *pi = NULL;
+
+ memset(&attr, 0, sizeof(struct attr));
+
+ /* Build path-attribute for this route. */
+ bgp_attr_default_set(&attr, BGP_ORIGIN_IGP);
+ attr.nexthop = es->originator_ip;
+ attr.mp_nexthop_global_in = es->originator_ip;
+ attr.mp_nexthop_len = BGP_ATTR_NHLEN_IPV4;
+
+ /* Set up extended community. */
+ bgp_evpn_type4_route_extcomm_build(es, &attr);
+
+ /* First, create (or fetch) route node within the ESI. */
+ /* NOTE: There is no RD here. */
+ rn = bgp_node_get(es->route_table, (struct prefix *)p);
+
+ /* Create or update route entry. */
+ ret = bgp_evpn_mh_route_update(bgp, es, NULL, afi, safi,
+ rn, &attr, 1, &pi, &route_changed);
+ if (ret != 0) {
+ flog_err(EC_BGP_ES_INVALID,
+ "%u ERROR: Failed to updated ES route ESI: %s VTEP %s",
+ bgp->vrf_id, es->esi_str,
+ inet_ntoa(es->originator_ip));
+ }
+
+ assert(pi);
+ attr_new = pi->attr;
+
+ /* Perform route selection;
+ * this is just to set the flags correctly
+ * as local route in the ES always wins.
+ */
+ bgp_evpn_es_route_select_install(bgp, es, rn);
+ bgp_dest_unlock_node(rn);
+
+ /* 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
+ * from there. Note that this table is a 2-level tree (RD-level +
+ * Prefix-level) similar to L3VPN routes.
+ */
+ if (route_changed) {
+ struct bgp_path_info *global_pi;
+
+ rn = bgp_global_evpn_node_get(bgp->rib[afi][safi], afi, safi,
+ p, &es->prd);
+ bgp_evpn_mh_route_update(bgp, es, NULL, afi, safi,
+ rn, attr_new, 1, &global_pi, &route_changed);
+
+ /* Schedule for processing and unlock node. */
+ bgp_process(bgp, rn, afi, safi);
+ bgp_dest_unlock_node(rn);
+ }
+
+ /* Unintern temporary. */
+ aspath_unintern(&attr.aspath);
+ return 0;
+}
+
+/* Delete local type-4 route */
+static int bgp_evpn_type4_route_delete(struct bgp *bgp,
+ struct bgp_evpn_es *es, struct prefix_evpn *p)
+{
+ return bgp_evpn_mh_route_delete(bgp, es, NULL /* l2vni */, p);
+}
+
+/* Process remote/received EVPN type-4 route (advertise or withdraw) */
+int bgp_evpn_type4_route_process(struct peer *peer, afi_t afi, safi_t safi,
+ struct attr *attr, uint8_t *pfx, int psize,
+ uint32_t addpath_id)
+{
+ int ret;
+ esi_t esi;
+ uint8_t ipaddr_len;
+ struct in_addr vtep_ip;
+ struct prefix_rd prd;
+ struct prefix_evpn p;
+
+ /* Type-4 route should be either 23 or 35 bytes
+ * RD (8), ESI (10), ip-len (1), ip (4 or 16)
+ */
+ if (psize != BGP_EVPN_TYPE4_V4_PSIZE &&
+ psize != BGP_EVPN_TYPE4_V6_PSIZE) {
+ flog_err(EC_BGP_EVPN_ROUTE_INVALID,
+ "%u:%s - Rx EVPN Type-4 NLRI with invalid length %d",
+ peer->bgp->vrf_id, peer->host, psize);
+ return -1;
+ }
+
+ /* Make prefix_rd */
+ prd.family = AF_UNSPEC;
+ prd.prefixlen = 64;
+ memcpy(&prd.val, pfx, RD_BYTES);
+ pfx += RD_BYTES;
+
+ /* get the ESI */
+ memcpy(&esi, pfx, ESI_BYTES);
+ pfx += ESI_BYTES;
+
+
+ /* Get the IP. */
+ ipaddr_len = *pfx++;
+ if (ipaddr_len == IPV4_MAX_BITLEN) {
+ memcpy(&vtep_ip, pfx, IPV4_MAX_BYTELEN);
+ } else {
+ flog_err(
+ EC_BGP_EVPN_ROUTE_INVALID,
+ "%u:%s - Rx EVPN Type-4 NLRI with unsupported IP address length %d",
+ peer->bgp->vrf_id, peer->host, ipaddr_len);
+ return -1;
+ }
+
+ build_evpn_type4_prefix(&p, &esi, vtep_ip);
+ /* Process the route. */
+ if (attr) {
+ ret = bgp_update(peer, (struct prefix *)&p, addpath_id, attr,
+ afi, safi, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
+ &prd, NULL, 0, 0, NULL);
+ } else {
+ ret = bgp_withdraw(peer, (struct prefix *)&p, addpath_id, attr,
+ afi, safi, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
+ &prd, NULL, 0, NULL);
+ }
+ return ret;
+}
+
+/* Check if a prefix belongs to the local ES */
+static bool bgp_evpn_type4_prefix_match(struct prefix_evpn *p,
+ struct bgp_evpn_es *es)
+{
+ return (p->prefix.route_type == BGP_EVPN_ES_ROUTE) &&
+ !memcmp(&p->prefix.es_addr.esi, &es->esi, sizeof(esi_t));
+}
+
+/* Import remote ESRs on local ethernet segment add */
+static int bgp_evpn_type4_remote_routes_import(struct bgp *bgp,
+ struct bgp_evpn_es *es, bool install)
+{
+ int ret;
+ afi_t afi;
+ safi_t safi;
+ char buf[PREFIX_STRLEN];
+ struct bgp_node *rd_rn, *rn;
+ struct bgp_table *table;
+ struct bgp_path_info *pi;
+
+ afi = AFI_L2VPN;
+ safi = SAFI_EVPN;
+
+ /* Walk entire global routing table and evaluate routes which could be
+ * imported into this Ethernet Segment.
+ */
+ for (rd_rn = bgp_table_top(bgp->rib[afi][safi]); rd_rn;
+ rd_rn = bgp_route_next(rd_rn)) {
+ table = bgp_dest_get_bgp_table_info(rd_rn);
+ if (!table)
+ continue;
+
+ for (rn = bgp_table_top(table); rn; rn = bgp_route_next(rn)) {
+ struct prefix_evpn *evp = (struct prefix_evpn *)&rn->p;
+
+ for (pi = bgp_dest_get_bgp_path_info(rn); pi;
+ pi = pi->next) {
+ /*
+ * Consider "valid" remote routes applicable for
+ * this ES.
+ */
+ if (!(CHECK_FLAG(pi->flags, BGP_PATH_VALID)
+ && pi->type == ZEBRA_ROUTE_BGP
+ && pi->sub_type == BGP_ROUTE_NORMAL))
+ continue;
+
+ if (!bgp_evpn_type4_prefix_match(evp, es))
+ continue;
+
+ if (install)
+ ret = bgp_evpn_es_route_install(
+ bgp, es, evp, pi);
+ else
+ ret = bgp_evpn_es_route_uninstall(
+ bgp, es, evp, pi);
+
+ if (ret) {
+ flog_err(
+ EC_BGP_EVPN_FAIL,
+ "Failed to %s EVPN %s route in ESI %s",
+ install ? "install"
+ : "uninstall",
+ prefix2str(evp, buf,
+ sizeof(buf)),
+ es->esi_str);
+ return ret;
+ }
+ }
+ }
+ }
+ return 0;
+}
+
+/*****************************************************************************
+ * Ethernet Auto Discovery (EAD/Type-1) route handling
+ * There are two types of EAD routes -
+ * 1. EAD-per-ES - Key: {ESI, ET=0xffffffff}
+ * 2. EAD-per-EVI - Key: {ESI, ET=0}
+ */
+
+/* Extended communities associated with EAD-per-ES */
+static void bgp_evpn_type1_es_route_extcomm_build(struct bgp_evpn_es *es,
+ struct attr *attr)
+{
+ struct ecommunity ecom_encap;
+ struct ecommunity ecom_esi_label;
+ struct ecommunity_val eval;
+ struct ecommunity_val eval_esi_label;
+ bgp_encap_types tnl_type;
+ struct listnode *evi_node, *rt_node;
+ struct ecommunity *ecom;
+ struct bgp_evpn_es_evi *es_evi;
+
+ /* Encap */
+ tnl_type = BGP_ENCAP_TYPE_VXLAN;
+ memset(&ecom_encap, 0, sizeof(ecom_encap));
+ encode_encap_extcomm(tnl_type, &eval);
+ ecom_encap.size = 1;
+ ecom_encap.val = (uint8_t *)eval.val;
+ attr->ecommunity = ecommunity_dup(&ecom_encap);
+
+ /* ESI label */
+ encode_esi_label_extcomm(&eval_esi_label,
+ false /*single_active*/);
+ ecom_esi_label.size = 1;
+ ecom_esi_label.val = (uint8_t *)eval_esi_label.val;
+ attr->ecommunity =
+ ecommunity_merge(attr->ecommunity, &ecom_esi_label);
+
+ /* Add export RTs for all L2-VNIs associated with this ES */
+ /* XXX - suppress EAD-ES advertisment if there are no EVIs associated
+ * with it.
+ */
+ for (ALL_LIST_ELEMENTS_RO(es->es_evi_list,
+ evi_node, es_evi)) {
+ if (!CHECK_FLAG(es_evi->flags, BGP_EVPNES_EVI_LOCAL))
+ continue;
+ for (ALL_LIST_ELEMENTS_RO(es_evi->vpn->export_rtl,
+ rt_node, ecom))
+ attr->ecommunity = ecommunity_merge(attr->ecommunity,
+ ecom);
+ }
+
+ attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES);
+}
+
+/* Extended communities associated with EAD-per-EVI */
+static void bgp_evpn_type1_evi_route_extcomm_build(struct bgp_evpn_es *es,
+ struct bgpevpn *vpn, struct attr *attr)
+{
+ struct ecommunity ecom_encap;
+ struct ecommunity_val eval;
+ bgp_encap_types tnl_type;
+ struct listnode *rt_node;
+ struct ecommunity *ecom;
+
+ /* Encap */
+ tnl_type = BGP_ENCAP_TYPE_VXLAN;
+ memset(&ecom_encap, 0, sizeof(ecom_encap));
+ encode_encap_extcomm(tnl_type, &eval);
+ ecom_encap.size = 1;
+ ecom_encap.val = (uint8_t *)eval.val;
+ attr->ecommunity = ecommunity_dup(&ecom_encap);
+
+ /* Add export RTs for the L2-VNI */
+ for (ALL_LIST_ELEMENTS_RO(vpn->export_rtl, rt_node, ecom))
+ attr->ecommunity = ecommunity_merge(attr->ecommunity, ecom);
+
+ attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES);
+}
+
+/* Update EVPN EAD (type-1) route -
+ * vpn - valid for EAD-EVI routes and NULL for EAD-ES routes
+ */
+static int bgp_evpn_type1_route_update(struct bgp *bgp,
+ struct bgp_evpn_es *es, struct bgpevpn *vpn,
+ struct prefix_evpn *p)
+{
+ int ret = 0;
+ afi_t afi = AFI_L2VPN;
+ safi_t safi = SAFI_EVPN;
+ struct attr attr;
+ struct attr *attr_new = NULL;
+ struct bgp_node *rn = NULL;
+ struct bgp_path_info *pi = NULL;
+ int route_changed = 0;
+ struct prefix_rd *global_rd;
+
+ memset(&attr, 0, sizeof(struct attr));
+
+ /* Build path-attribute for this route. */
+ bgp_attr_default_set(&attr, BGP_ORIGIN_IGP);
+ attr.nexthop = es->originator_ip;
+ attr.mp_nexthop_global_in = es->originator_ip;
+ attr.mp_nexthop_len = BGP_ATTR_NHLEN_IPV4;
+
+ if (vpn) {
+ /* EAD-EVI route update */
+ /* MPLS label */
+ vni2label(vpn->vni, &(attr.label));
+
+ /* Set up extended community */
+ bgp_evpn_type1_evi_route_extcomm_build(es, vpn, &attr);
+
+ /* First, create (or fetch) route node within the VNI. */
+ rn = bgp_node_get(vpn->route_table, (struct prefix *)p);
+
+ /* Create or update route entry. */
+ ret = bgp_evpn_mh_route_update(bgp, es, vpn, afi, safi,
+ rn, &attr, 1, &pi, &route_changed);
+ if (ret != 0) {
+ flog_err(EC_BGP_ES_INVALID,
+ "%u Failed to update EAD-EVI route ESI: %s VNI %u VTEP %s",
+ bgp->vrf_id, es->esi_str, vpn->vni,
+ inet_ntoa(es->originator_ip));
+ }
+ global_rd = &vpn->prd;
+ } else {
+ /* EAD-ES route update */
+ /* MPLS label is 0 for EAD-ES route */
+
+ /* Set up extended community */
+ bgp_evpn_type1_es_route_extcomm_build(es, &attr);
+
+ /* First, create (or fetch) route node within the ES. */
+ /* NOTE: There is no RD here. */
+ /* XXX: fragment ID must be included as a part of the prefix. */
+ rn = bgp_node_get(es->route_table, (struct prefix *)p);
+
+ /* Create or update route entry. */
+ ret = bgp_evpn_mh_route_update(bgp, es, vpn, afi, safi,
+ rn, &attr, 1, &pi, &route_changed);
+ if (ret != 0) {
+ flog_err(EC_BGP_ES_INVALID,
+ "%u ERROR: Failed to updated EAD-EVI route ESI: %s VTEP %s",
+ bgp->vrf_id, es->esi_str,
+ inet_ntoa(es->originator_ip));
+ }
+ global_rd = &es->prd;
+ }
+
+
+ assert(pi);
+ attr_new = pi->attr;
+
+ /* Perform route selection;
+ * this is just to set the flags correctly as local route in
+ * the ES always wins.
+ */
+ evpn_route_select_install(bgp, vpn, rn);
+ bgp_dest_unlock_node(rn);
+
+ /* 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
+ * from there. Note that this table is a 2-level tree (RD-level +
+ * Prefix-level) similar to L3VPN routes.
+ */
+ if (route_changed) {
+ struct bgp_path_info *global_pi;
+
+ rn = bgp_global_evpn_node_get(bgp->rib[afi][safi], afi, safi,
+ p, global_rd);
+ bgp_evpn_mh_route_update(bgp, es, vpn, afi, safi,
+ rn, attr_new, 1, &global_pi, &route_changed);
+
+ /* Schedule for processing and unlock node. */
+ bgp_process(bgp, rn, afi, safi);
+ bgp_dest_unlock_node(rn);
+ }
+
+ /* Unintern temporary. */
+ aspath_unintern(&attr.aspath);
+ return 0;
+}
+
+/* Delete local Type-1 route */
+static int bgp_evpn_type1_es_route_delete(struct bgp *bgp,
+ struct bgp_evpn_es *es, struct prefix_evpn *p)
+{
+ return bgp_evpn_mh_route_delete(bgp, es, NULL /* l2vni */, p);
+}
+
+static int bgp_evpn_type1_evi_route_delete(struct bgp *bgp,
+ struct bgp_evpn_es *es, struct bgpevpn *vpn,
+ struct prefix_evpn *p)
+{
+ return bgp_evpn_mh_route_delete(bgp, es, vpn, p);
+}
+
+/* Generate EAD-EVI for all VNIs */
+static void bgp_evpn_local_type1_evi_route_add(struct bgp *bgp,
+ struct bgp_evpn_es *es)
+{
+ struct listnode *evi_node;
+ struct prefix_evpn p;
+ struct bgp_evpn_es_evi *es_evi;
+
+ if (CHECK_FLAG(es->flags, BGP_EVPNES_ADV_EVI))
+ /* EAD-EVI route add for this ES is already done */
+ return;
+
+ SET_FLAG(es->flags, BGP_EVPNES_ADV_EVI);
+ build_evpn_type1_prefix(&p, BGP_EVPN_AD_EVI_ETH_TAG,
+ &es->esi, es->originator_ip);
+
+ for (ALL_LIST_ELEMENTS_RO(es->es_evi_list, evi_node, es_evi)) {
+ if (!CHECK_FLAG(es_evi->flags, BGP_EVPNES_EVI_LOCAL))
+ continue;
+ if (bgp_evpn_type1_route_update(bgp, es, es_evi->vpn, &p))
+ flog_err(EC_BGP_EVPN_ROUTE_CREATE,
+ "%u: Type4 route creation failure for ESI %s",
+ bgp->vrf_id, es->esi_str);
+ }
+}
+
+/*
+ * Withdraw EAD-EVI for all VNIs
+ */
+static void bgp_evpn_local_type1_evi_route_del(struct bgp *bgp,
+ struct bgp_evpn_es *es)
+{
+ struct listnode *evi_node;
+ struct prefix_evpn p;
+ struct bgp_evpn_es_evi *es_evi;
+
+ /* Delete and withdraw locally learnt EAD-EVI route */
+ if (!CHECK_FLAG(es->flags, BGP_EVPNES_ADV_EVI))
+ /* EAD-EVI route has not been advertised for this ES */
+ return;
+
+ UNSET_FLAG(es->flags, BGP_EVPNES_ADV_EVI);
+ build_evpn_type1_prefix(&p, BGP_EVPN_AD_EVI_ETH_TAG,
+ &es->esi, es->originator_ip);
+ for (ALL_LIST_ELEMENTS_RO(es->es_evi_list, evi_node, es_evi)) {
+ if (!CHECK_FLAG(es_evi->flags, BGP_EVPNES_EVI_LOCAL))
+ continue;
+ if (bgp_evpn_mh_route_delete(bgp, es, es_evi->vpn, &p))
+ flog_err(EC_BGP_EVPN_ROUTE_CREATE,
+ "%u: Type4 route creation failure for ESI %s",
+ bgp->vrf_id, es->esi_str);
+ }
+}
+
+/*
+ * Process received EVPN type-1 route (advertise or withdraw).
+ */
+int bgp_evpn_type1_route_process(struct peer *peer, afi_t afi, safi_t safi,
+ struct attr *attr, uint8_t *pfx, int psize,
+ uint32_t addpath_id)
+{
+ int ret;
+ struct prefix_rd prd;
+ esi_t esi;
+ uint32_t eth_tag;
+ mpls_label_t label;
+ struct in_addr vtep_ip;
+ struct prefix_evpn p;
+
+ if (psize != BGP_EVPN_TYPE1_PSIZE) {
+ flog_err(EC_BGP_EVPN_ROUTE_INVALID,
+ "%u:%s - Rx EVPN Type-1 NLRI with invalid length %d",
+ peer->bgp->vrf_id, peer->host, psize);
+ return -1;
+ }
+
+ /* Make prefix_rd */
+ prd.family = AF_UNSPEC;
+ prd.prefixlen = 64;
+ memcpy(&prd.val, pfx, RD_BYTES);
+ pfx += RD_BYTES;
+
+ /* get the ESI */
+ memcpy(&esi, pfx, ESI_BYTES);
+ pfx += ESI_BYTES;
+
+ /* Copy Ethernet Tag */
+ memcpy(&eth_tag, pfx, EVPN_ETH_TAG_BYTES);
+ eth_tag = ntohl(eth_tag);
+ pfx += EVPN_ETH_TAG_BYTES;
+
+ memcpy(&label, pfx, BGP_LABEL_BYTES);
+
+ /* EAD route prefix doesn't include the nexthop in the global
+ * table
+ */
+ vtep_ip.s_addr = 0;
+ build_evpn_type1_prefix(&p, eth_tag, &esi, vtep_ip);
+ /* Process the route. */
+ if (attr) {
+ ret = bgp_update(peer, (struct prefix *)&p, addpath_id, attr,
+ afi, safi, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
+ &prd, NULL, 0, 0, NULL);
+ } else {
+ ret = bgp_withdraw(peer, (struct prefix *)&p, addpath_id, attr,
+ afi, safi, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
+ &prd, NULL, 0, NULL);
+ }
+ return ret;
+}
+
+/*****************************************************************************/
+/* Ethernet Segment Management
+ * 1. Ethernet Segment is a collection of links attached to the same
+ * server (MHD) or switch (MHN)
+ * 2. An Ethernet Segment can span multiple PEs and is identified by the
+ * 10-byte ES-ID.
+ * 3. Local ESs are configured in zebra and sent to BGP
+ * 4. Remote ESs are created by BGP when one or more ES-EVIs reference it i.e.
+ * created on first reference and release on last de-reference
+ * 5. An ES can be both local and remote. Infact most local ESs are expected
+ * to have an ES peer.
+ */
+
+/* A list of remote VTEPs is maintained for each ES. This list includes -
+ * 1. VTEPs for which we have imported the ESR i.e. ES-peers
+ * 2. VTEPs that have an "active" ES-EVI VTEP i.e. EAD-per-ES and EAD-per-EVI
+ * have been imported into one or more VNIs
+ */
+static int bgp_evpn_es_vtep_cmp(void *p1, void *p2)
+{
+ const struct bgp_evpn_es_vtep *es_vtep1 = p1;
+ const struct bgp_evpn_es_vtep *es_vtep2 = p2;
+
+ return es_vtep1->vtep_ip.s_addr - es_vtep2->vtep_ip.s_addr;
+}
+
+static struct bgp_evpn_es_vtep *bgp_evpn_es_vtep_new(struct bgp_evpn_es *es,
+ struct in_addr vtep_ip)
+{
+ struct bgp_evpn_es_vtep *es_vtep;
+
+ es_vtep = XCALLOC(MTYPE_BGP_EVPN_ES_VTEP, sizeof(*es_vtep));
+
+ es_vtep->es = es;
+ es_vtep->vtep_ip.s_addr = vtep_ip.s_addr;
+ listnode_init(&es_vtep->es_listnode, es_vtep);
+ listnode_add_sort(es->es_vtep_list, &es_vtep->es_listnode);
+
+ return es_vtep;
+}
+
+static void bgp_evpn_es_vtep_free(struct bgp_evpn_es_vtep *es_vtep)
+{
+ struct bgp_evpn_es *es = es_vtep->es;
+
+ if (CHECK_FLAG(es_vtep->flags, BGP_EVPNES_VTEP_ESR) ||
+ es_vtep->evi_cnt)
+ /* as long as there is some reference we can't free it */
+ return;
+
+ list_delete_node(es->es_vtep_list, &es_vtep->es_listnode);
+ XFREE(MTYPE_BGP_EVPN_ES_VTEP, es_vtep);
+}
+
+/* check if VTEP is already part of the list */
+static struct bgp_evpn_es_vtep *bgp_evpn_es_vtep_find(struct bgp_evpn_es *es,
+ struct in_addr vtep_ip)
+{
+ struct listnode *node = NULL;
+ struct bgp_evpn_es_vtep *es_vtep;
+
+ for (ALL_LIST_ELEMENTS_RO(es->es_vtep_list, node, es_vtep)) {
+ if (es_vtep->vtep_ip.s_addr == vtep_ip.s_addr)
+ return es_vtep;
+ }
+ return NULL;
+}
+
+/* Send the remote ES to zebra for NHG programming */
+static int bgp_zebra_send_remote_es_vtep(struct bgp *bgp,
+ struct bgp_evpn_es_vtep *es_vtep, bool add)
+{
+ struct bgp_evpn_es *es = es_vtep->es;
+ struct stream *s;
+
+ /* Check socket. */
+ if (!zclient || zclient->sock < 0)
+ return 0;
+
+ /* Don't try to register if Zebra doesn't know of this instance. */
+ if (!IS_BGP_INST_KNOWN_TO_ZEBRA(bgp)) {
+ if (BGP_DEBUG(zebra, ZEBRA))
+ zlog_debug("No zebra instance, not installing remote es %s",
+ es->esi_str);
+ return 0;
+ }
+
+ s = zclient->obuf;
+ stream_reset(s);
+
+ zclient_create_header(s,
+ add ? ZEBRA_REMOTE_ES_VTEP_ADD : ZEBRA_REMOTE_ES_VTEP_DEL,
+ bgp->vrf_id);
+ stream_put(s, &es->esi, sizeof(esi_t));
+ stream_put_ipv4(s, es_vtep->vtep_ip.s_addr);
+
+ stream_putw_at(s, 0, stream_get_endp(s));
+
+ if (BGP_DEBUG(evpn_mh, EVPN_MH_ES))
+ zlog_debug("Tx %s Remote ESI %s VTEP %s",
+ add ? "ADD" : "DEL", es->esi_str,
+ inet_ntoa(es_vtep->vtep_ip));
+
+ return zclient_send_message(zclient);
+}
+
+static void bgp_evpn_es_vtep_re_eval_active(struct bgp *bgp,
+ struct bgp_evpn_es_vtep *es_vtep)
+{
+ bool old_active;
+ bool new_active;
+
+ old_active = !!CHECK_FLAG(es_vtep->flags, BGP_EVPNES_VTEP_ACTIVE);
+ /* currently we need an active EVI reference to use the VTEP as
+ * a nexthop. this may change...
+ */
+ if (es_vtep->evi_cnt)
+ SET_FLAG(es_vtep->flags, BGP_EVPNES_VTEP_ACTIVE);
+ else
+ UNSET_FLAG(es_vtep->flags, BGP_EVPNES_VTEP_ACTIVE);
+
+ new_active = !!CHECK_FLAG(es_vtep->flags, BGP_EVPNES_VTEP_ACTIVE);
+
+ if (old_active == new_active)
+ return;
+
+ if (BGP_DEBUG(evpn_mh, EVPN_MH_ES))
+ zlog_debug("es %s vtep %s %s",
+ es_vtep->es->esi_str,
+ inet_ntoa(es_vtep->vtep_ip),
+ new_active ? "active" : "inactive");
+
+ /* send remote ES to zebra */
+ bgp_zebra_send_remote_es_vtep(bgp, es_vtep, new_active);
+
+ /* queue up the es for background consistency checks */
+ bgp_evpn_es_cons_checks_pend_add(es_vtep->es);
+}
+
+static struct bgp_evpn_es_vtep *bgp_evpn_es_vtep_add(struct bgp *bgp,
+ struct bgp_evpn_es *es, struct in_addr vtep_ip, bool esr)
+{
+ struct bgp_evpn_es_vtep *es_vtep;
+
+ es_vtep = bgp_evpn_es_vtep_find(es, vtep_ip);
+
+ if (!es_vtep)
+ es_vtep = bgp_evpn_es_vtep_new(es, vtep_ip);
+
+ if (BGP_DEBUG(evpn_mh, EVPN_MH_ES))
+ zlog_debug("es %s vtep %s add %s",
+ es_vtep->es->esi_str,
+ inet_ntoa(es_vtep->vtep_ip),
+ esr ? "esr" : "ead");
+
+ if (esr)
+ SET_FLAG(es_vtep->flags, BGP_EVPNES_VTEP_ESR);
+ else
+ ++es_vtep->evi_cnt;
+
+ bgp_evpn_es_vtep_re_eval_active(bgp, es_vtep);
+
+ return es_vtep;
+}
+
+static void bgp_evpn_es_vtep_do_del(struct bgp *bgp,
+ struct bgp_evpn_es_vtep *es_vtep, bool esr)
+{
+ if (BGP_DEBUG(evpn_mh, EVPN_MH_ES))
+ zlog_debug("es %s vtep %s del %s",
+ es_vtep->es->esi_str,
+ inet_ntoa(es_vtep->vtep_ip),
+ esr ? "esr" : "ead");
+ if (esr) {
+ UNSET_FLAG(es_vtep->flags, BGP_EVPNES_VTEP_ESR);
+ } else {
+ if (es_vtep->evi_cnt)
+ --es_vtep->evi_cnt;
+ }
+
+ bgp_evpn_es_vtep_re_eval_active(bgp, es_vtep);
+ bgp_evpn_es_vtep_free(es_vtep);
+}
+
+static void bgp_evpn_es_vtep_del(struct bgp *bgp,
+ struct bgp_evpn_es *es, struct in_addr vtep_ip, bool esr)
+{
+ struct bgp_evpn_es_vtep *es_vtep;
+
+ es_vtep = bgp_evpn_es_vtep_find(es, vtep_ip);
+ if (es_vtep)
+ bgp_evpn_es_vtep_do_del(bgp, es_vtep, esr);
+}
+
+/* compare ES-IDs for the global ES RB tree */
+static int bgp_es_rb_cmp(const struct bgp_evpn_es *es1,
+ const struct bgp_evpn_es *es2)
+{
+ return memcmp(&es1->esi, &es2->esi, ESI_BYTES);
+}
+RB_GENERATE(bgp_es_rb_head, bgp_evpn_es, rb_node, bgp_es_rb_cmp);
+
+struct bgp_evpn_es *bgp_evpn_es_find(const esi_t *esi)
+{
+ struct bgp_evpn_es tmp;
+
+ memcpy(&tmp.esi, esi, sizeof(esi_t));
+ return RB_FIND(bgp_es_rb_head, &bgp_mh_info->es_rb_tree, &tmp);
+}
+
+static struct bgp_evpn_es *bgp_evpn_es_new(struct bgp *bgp, const esi_t *esi)
+{
+ struct bgp_evpn_es *es;
+
+ if (!bgp)
+ return NULL;
+
+ es = XCALLOC(MTYPE_BGP_EVPN_ES, sizeof(struct bgp_evpn_es));
+
+ /* set the ESI */
+ memcpy(&es->esi, esi, sizeof(esi_t));
+
+ /* Initialise the VTEP list */
+ es->es_vtep_list = list_new();
+ listset_app_node_mem(es->es_vtep_list);
+ es->es_vtep_list->cmp = bgp_evpn_es_vtep_cmp;
+
+ esi_to_str(&es->esi, es->esi_str, sizeof(es->esi_str));
+
+ /* Initialize the ES routing table */
+ es->route_table = bgp_table_init(bgp, AFI_L2VPN, SAFI_EVPN);
+
+ /* Add to rb_tree */
+ if (RB_INSERT(bgp_es_rb_head, &bgp_mh_info->es_rb_tree, es)) {
+ XFREE(MTYPE_BGP_EVPN_ES, es);
+ return NULL;
+ }
+
+ /* Initialise the ES-EVI list */
+ es->es_evi_list = list_new();
+ listset_app_node_mem(es->es_evi_list);
+
+ QOBJ_REG(es, bgp_evpn_es);
+
+ return es;
+}
+
+/* Free a given ES -
+ * This just frees appropriate memory, caller should have taken other
+ * needed actions.
+ */
+static void bgp_evpn_es_free(struct bgp_evpn_es *es)
+{
+ if (es->flags & (BGP_EVPNES_LOCAL | BGP_EVPNES_REMOTE))
+ return;
+
+ /* cleanup resources maintained against the ES */
+ list_delete(&es->es_evi_list);
+ list_delete(&es->es_vtep_list);
+ bgp_table_unlock(es->route_table);
+
+ /* remove the entry from various databases */
+ RB_REMOVE(bgp_es_rb_head, &bgp_mh_info->es_rb_tree, es);
+ bgp_evpn_es_cons_checks_pend_del(es);
+
+ QOBJ_UNREG(es);
+ XFREE(MTYPE_BGP_EVPN_ES, es);
+}
+
+/* init local info associated with the ES */
+static void bgp_evpn_es_local_info_set(struct bgp *bgp, struct bgp_evpn_es *es)
+{
+ char buf[BGP_EVPN_PREFIX_RD_LEN];
+
+ if (CHECK_FLAG(es->flags, BGP_EVPNES_LOCAL))
+ return;
+
+ SET_FLAG(es->flags, BGP_EVPNES_LOCAL);
+ listnode_init(&es->es_listnode, es);
+ listnode_add(bgp_mh_info->local_es_list, &es->es_listnode);
+
+ /* auto derive RD for this es */
+ bf_assign_index(bm->rd_idspace, es->rd_id);
+ es->prd.family = AF_UNSPEC;
+ es->prd.prefixlen = 64;
+ snprintf(buf, sizeof(buf), "%s:%hu", inet_ntoa(bgp->router_id),
+ es->rd_id);
+ (void)str2prefix_rd(buf, &es->prd);
+}
+
+/* clear any local info associated with the ES */
+static void bgp_evpn_es_local_info_clear(struct bgp_evpn_es *es)
+{
+ if (!CHECK_FLAG(es->flags, BGP_EVPNES_LOCAL))
+ return;
+
+ UNSET_FLAG(es->flags, BGP_EVPNES_LOCAL);
+
+ /* remove from the ES local list */
+ list_delete_node(bgp_mh_info->local_es_list, &es->es_listnode);
+
+ bf_release_index(bm->rd_idspace, es->rd_id);
+
+ bgp_evpn_es_free(es);
+}
+
+/* eval remote info associated with the ES */
+static void bgp_evpn_es_remote_info_re_eval(struct bgp_evpn_es *es)
+{
+ if (es->remote_es_evi_cnt) {
+ SET_FLAG(es->flags, BGP_EVPNES_REMOTE);
+ } else {
+ if (CHECK_FLAG(es->flags, BGP_EVPNES_REMOTE)) {
+ UNSET_FLAG(es->flags, BGP_EVPNES_REMOTE);
+ bgp_evpn_es_free(es);
+ }
+ }
+}
+
+/* Process ES link oper-down by withdrawing ES-EAD and ESR */
+static void bgp_evpn_local_es_down(struct bgp *bgp,
+ struct bgp_evpn_es *es)
+{
+ struct prefix_evpn p;
+ int ret;
+
+ if (!CHECK_FLAG(es->flags, BGP_EVPNES_OPER_UP))
+ return;
+
+ UNSET_FLAG(es->flags, BGP_EVPNES_OPER_UP);
+
+ if (BGP_DEBUG(evpn_mh, EVPN_MH_ES))
+ zlog_debug("local es %s down", es->esi_str);
+
+ /* withdraw ESR */
+ /* Delete and withdraw locally learnt ES route */
+ build_evpn_type4_prefix(&p, &es->esi, es->originator_ip);
+ ret = bgp_evpn_type4_route_delete(bgp, es, &p);
+ if (ret) {
+ flog_err(EC_BGP_EVPN_ROUTE_DELETE,
+ "%u failed to delete type-4 route for ESI %s",
+ bgp->vrf_id, es->esi_str);
+ }
+
+ /* withdraw EAD-EVI */
+ if (!bgp_mh_info->ead_evi_adv_for_down_links)
+ bgp_evpn_local_type1_evi_route_del(bgp, es);
+
+ /* withdraw EAD-ES */
+ build_evpn_type1_prefix(&p, BGP_EVPN_AD_ES_ETH_TAG,
+ &es->esi, es->originator_ip);
+ ret = bgp_evpn_type1_es_route_delete(bgp, es, &p);
+ if (ret) {
+ flog_err(EC_BGP_EVPN_ROUTE_DELETE,
+ "%u failed to delete type-1 route for ESI %s",
+ bgp->vrf_id, es->esi_str);
+ }
+}
+
+/* Process ES link oper-up by generating ES-EAD and ESR */
+static void bgp_evpn_local_es_up(struct bgp *bgp, struct bgp_evpn_es *es)
+{
+ struct prefix_evpn p;
+
+ if (CHECK_FLAG(es->flags, BGP_EVPNES_OPER_UP))
+ return;
+
+ SET_FLAG(es->flags, BGP_EVPNES_OPER_UP);
+
+ if (BGP_DEBUG(evpn_mh, EVPN_MH_ES))
+ zlog_debug("local es %s up", es->esi_str);
+
+ /* generate ESR */
+ build_evpn_type4_prefix(&p, &es->esi, es->originator_ip);
+ if (bgp_evpn_type4_route_update(bgp, es, &p))
+ flog_err(EC_BGP_EVPN_ROUTE_CREATE,
+ "%u: Type4 route creation failure for ESI %s",
+ bgp->vrf_id, es->esi_str);
+
+ /* generate EAD-EVI */
+ bgp_evpn_local_type1_evi_route_add(bgp, es);
+
+ /* generate EAD-ES */
+ build_evpn_type1_prefix(&p, BGP_EVPN_AD_ES_ETH_TAG,
+ &es->esi, es->originator_ip);
+ bgp_evpn_type1_route_update(bgp, es, NULL, &p);
+}
+
+static void bgp_evpn_local_es_do_del(struct bgp *bgp, struct bgp_evpn_es *es)
+{
+ struct bgp_evpn_es_evi *es_evi;
+ struct listnode *evi_node, *evi_next_node;
+
+ if (BGP_DEBUG(evpn_mh, EVPN_MH_ES))
+ zlog_debug("del local es %s", es->esi_str);
+
+ /* Delete all local EVPN ES routes from ESI table
+ * and schedule for processing (to withdraw from peers))
+ */
+ bgp_evpn_es_route_del_all(bgp, es);
+
+ /* release all local ES EVIs associated with the ES */
+ for (ALL_LIST_ELEMENTS(es->es_evi_list, evi_node,
+ evi_next_node, es_evi)) {
+ bgp_evpn_local_es_evi_do_del(es_evi);
+ }
+
+ /* Clear local info associated with the ES and free it up if there is
+ * no remote reference
+ */
+ bgp_evpn_es_local_info_clear(es);
+}
+
+bool bgp_evpn_is_esi_local(esi_t *esi)
+{
+ struct bgp_evpn_es *es = NULL;
+
+ /* Lookup ESI hash - should exist. */
+ es = bgp_evpn_es_find(esi);
+ return es ? !!(es->flags & BGP_EVPNES_LOCAL) : false;
+}
+
+int bgp_evpn_local_es_del(struct bgp *bgp, esi_t *esi)
+{
+ struct bgp_evpn_es *es = NULL;
+
+ /* Lookup ESI hash - should exist. */
+ es = bgp_evpn_es_find(esi);
+ if (!es) {
+ flog_warn(EC_BGP_EVPN_ESI,
+ "%u: ES %s missing at local ES DEL",
+ bgp->vrf_id, es->esi_str);
+ return -1;
+ }
+
+ bgp_evpn_local_es_do_del(bgp, es);
+ return 0;
+}
+
+/* Handle device to ES id association. Results in the creation of a local
+ * ES.
+ */
+int bgp_evpn_local_es_add(struct bgp *bgp, esi_t *esi,
+ struct in_addr originator_ip, bool oper_up)
+{
+ char buf[ESI_STR_LEN];
+ struct bgp_evpn_es *es;
+ bool new_es = true;
+
+ /* create the new es */
+ es = bgp_evpn_es_find(esi);
+ if (es) {
+ if (CHECK_FLAG(es->flags, BGP_EVPNES_LOCAL))
+ new_es = false;
+ } else {
+ es = bgp_evpn_es_new(bgp, esi);
+ if (!es) {
+ flog_err(EC_BGP_ES_CREATE,
+ "%u: Failed to allocate ES entry for ESI %s - at Local ES Add",
+ bgp->vrf_id, esi_to_str(esi, buf, sizeof(buf)));
+ return -1;
+ }
+ }
+
+ if (BGP_DEBUG(evpn_mh, EVPN_MH_ES))
+ zlog_debug("add local es %s orig-ip %s",
+ es->esi_str,
+ inet_ntoa(originator_ip));
+
+ es->originator_ip = originator_ip;
+ bgp_evpn_es_local_info_set(bgp, es);
+
+ /* import all remote Type-4 routes in the ES table */
+ if (new_es)
+ bgp_evpn_type4_remote_routes_import(bgp, es,
+ true /* install */);
+
+ /* create and advertise EAD-EVI routes for the ES -
+ * XXX - till an ES-EVI reference is created there is really nothing to
+ * advertise
+ */
+ if (bgp_mh_info->ead_evi_adv_for_down_links)
+ bgp_evpn_local_type1_evi_route_add(bgp, es);
+
+ /* If the ES link is operationally up generate EAD-ES. EAD-EVI
+ * can be generated even if the link is inactive.
+ */
+ if (oper_up)
+ bgp_evpn_local_es_up(bgp, es);
+ else
+ bgp_evpn_local_es_down(bgp, es);
+
+ return 0;
+}
+
+static char *bgp_evpn_es_vteps_str(char *vtep_str, struct bgp_evpn_es *es,
+ uint8_t vtep_str_size)
+{
+ char vtep_flag_str[BGP_EVPN_FLAG_STR_SZ];
+ struct listnode *node;
+ struct bgp_evpn_es_vtep *es_vtep;
+ bool first = true;
+
+ vtep_str[0] = '\0';
+ for (ALL_LIST_ELEMENTS_RO(es->es_vtep_list, node, es_vtep)) {
+ vtep_flag_str[0] = '\0';
+ if (es_vtep->flags & BGP_EVPNES_VTEP_ESR)
+ strlcat(vtep_flag_str, "E", sizeof(vtep_flag_str));
+ if (es_vtep->flags & BGP_EVPNES_VTEP_ACTIVE)
+ strlcat(vtep_flag_str, "A", sizeof(vtep_flag_str));
+
+ if (!strlen(vtep_flag_str))
+ strlcat(vtep_flag_str, "-", sizeof(vtep_flag_str));
+ if (first)
+ first = false;
+ else
+ strlcat(vtep_str, ",", vtep_str_size);
+ strlcat(vtep_str, inet_ntoa(es_vtep->vtep_ip), vtep_str_size);
+ strlcat(vtep_str, "(", vtep_str_size);
+ strlcat(vtep_str, vtep_flag_str, vtep_str_size);
+ strlcat(vtep_str, ")", vtep_str_size);
+ }
+
+ return vtep_str;
+}
+
+static inline void json_array_string_add(json_object *json, const char *str)
+{
+ json_object_array_add(json, json_object_new_string(str));
+}
+
+static void bgp_evpn_es_json_vtep_fill(json_object *json_vteps,
+ struct bgp_evpn_es_vtep *es_vtep)
+{
+ json_object *json_vtep_entry;
+ json_object *json_flags;
+
+ json_vtep_entry = json_object_new_object();
+
+ json_object_string_add(json_vtep_entry, "vtep_ip",
+ inet_ntoa(es_vtep->vtep_ip));
+ if (es_vtep->flags & (BGP_EVPNES_VTEP_ESR |
+ BGP_EVPNES_VTEP_ACTIVE)) {
+ json_flags = json_object_new_array();
+ if (es_vtep->flags & BGP_EVPNES_VTEP_ESR)
+ json_array_string_add(json_flags, "esr");
+ if (es_vtep->flags & BGP_EVPNES_VTEP_ACTIVE)
+ json_array_string_add(json_flags, "active");
+ json_object_object_add(json_vtep_entry, "flags", json_flags);
+ }
+
+ json_object_array_add(json_vteps,
+ json_vtep_entry);
+}
+
+static void bgp_evpn_es_show_entry(struct vty *vty,
+ struct bgp_evpn_es *es, json_object *json)
+{
+ char buf1[RD_ADDRSTRLEN];
+ struct listnode *node;
+ struct bgp_evpn_es_vtep *es_vtep;
+
+ if (json) {
+ json_object *json_vteps;
+ json_object *json_types;
+
+ json_object_string_add(json, "esi", es->esi_str);
+ json_object_string_add(json, "rd",
+ prefix_rd2str(&es->prd, buf1,
+ sizeof(buf1)));
+
+ if (es->flags & (BGP_EVPNES_LOCAL | BGP_EVPNES_REMOTE)) {
+ json_types = json_object_new_array();
+ if (es->flags & BGP_EVPNES_LOCAL)
+ json_array_string_add(json_types, "local");
+ if (es->flags & BGP_EVPNES_REMOTE)
+ json_array_string_add(json_types, "remote");
+ json_object_object_add(json, "type", json_types);
+ }
+
+ if (listcount(es->es_vtep_list)) {
+ json_vteps = json_object_new_array();
+ for (ALL_LIST_ELEMENTS_RO(es->es_vtep_list,
+ node, es_vtep)) {
+ bgp_evpn_es_json_vtep_fill(json_vteps, es_vtep);
+ }
+ json_object_object_add(json, "vteps", json_vteps);
+ }
+ json_object_int_add(json, "vniCount",
+ listcount(es->es_evi_list));
+ } else {
+ char type_str[4];
+ char vtep_str[ES_VTEP_LIST_STR_SZ + BGP_EVPN_VTEPS_FLAG_STR_SZ];
+
+ type_str[0] = '\0';
+ if (es->flags & BGP_EVPNES_LOCAL)
+ strlcat(type_str, "L", sizeof(type_str));
+ if (es->flags & BGP_EVPNES_REMOTE)
+ strlcat(type_str, "R", sizeof(type_str));
+ if (es->inconsistencies)
+ strlcat(type_str, "I", sizeof(type_str));
+
+ bgp_evpn_es_vteps_str(vtep_str, es, sizeof(vtep_str));
+
+ if (es->flags & BGP_EVPNES_LOCAL)
+ prefix_rd2str(&es->prd, buf1, sizeof(buf1));
+ else
+ strlcpy(buf1, "-", sizeof(buf1));
+
+ vty_out(vty, "%-30s %-5s %-21s %-8d %s\n",
+ es->esi_str, type_str, buf1,
+ listcount(es->es_evi_list), vtep_str);
+ }
+}
+
+static void bgp_evpn_es_show_entry_detail(struct vty *vty,
+ struct bgp_evpn_es *es, json_object *json)
+{
+ if (json) {
+ json_object *json_flags;
+ json_object *json_incons;
+
+ /* Add the "brief" info first */
+ bgp_evpn_es_show_entry(vty, es, json);
+ if (es->flags & (BGP_EVPNES_OPER_UP | BGP_EVPNES_ADV_EVI)) {
+ json_flags = json_object_new_array();
+ if (es->flags & BGP_EVPNES_OPER_UP)
+ json_array_string_add(json_flags, "up");
+ if (es->flags & BGP_EVPNES_ADV_EVI)
+ json_array_string_add(json_flags,
+ "advertiseEVI");
+ json_object_object_add(json, "flags", json_flags);
+ }
+ json_object_string_add(json, "originator_ip",
+ inet_ntoa(es->originator_ip));
+ json_object_int_add(json, "remoteVniCount",
+ es->remote_es_evi_cnt);
+ json_object_int_add(json, "inconsistentVniVtepCount",
+ es->incons_evi_vtep_cnt);
+ if (es->inconsistencies) {
+ json_incons = json_object_new_array();
+ if (es->inconsistencies & BGP_EVPNES_INCONS_VTEP_LIST)
+ json_array_string_add(json_incons,
+ "vni-vtep-mismatch");
+ json_object_object_add(json, "inconsistencies",
+ json_incons);
+ }
+ } else {
+ char incons_str[BGP_EVPNES_INCONS_STR_SZ];
+ char type_str[4];
+ char vtep_str[ES_VTEP_LIST_STR_SZ + BGP_EVPN_VTEPS_FLAG_STR_SZ];
+ char buf1[RD_ADDRSTRLEN];
+
+ type_str[0] = '\0';
+ if (es->flags & BGP_EVPNES_LOCAL)
+ strlcat(type_str, "L", sizeof(type_str));
+ if (es->flags & BGP_EVPNES_REMOTE)
+ strlcat(type_str, "R", sizeof(type_str));
+
+ bgp_evpn_es_vteps_str(vtep_str, es, sizeof(vtep_str));
+ if (!strlen(vtep_str))
+ strlcpy(buf1, "-", sizeof(buf1));
+
+ if (es->flags & BGP_EVPNES_LOCAL)
+ prefix_rd2str(&es->prd, buf1, sizeof(buf1));
+ else
+ strlcpy(buf1, "-", sizeof(buf1));
+
+ vty_out(vty, "ESI: %s\n", es->esi_str);
+ vty_out(vty, " Type: %s\n", type_str);
+ vty_out(vty, " RD: %s\n", buf1);
+ vty_out(vty, " Originator-IP: %s\n",
+ inet_ntoa(es->originator_ip));
+ vty_out(vty, " VNI Count: %d\n", listcount(es->es_evi_list));
+ vty_out(vty, " Remote VNI Count: %d\n",
+ es->remote_es_evi_cnt);
+ vty_out(vty, " Inconsistent VNI VTEP Count: %d\n",
+ es->incons_evi_vtep_cnt);
+ if (es->inconsistencies) {
+ incons_str[0] = '\0';
+ if (es->inconsistencies & BGP_EVPNES_INCONS_VTEP_LIST)
+ strlcat(incons_str, "vni-vtep-mismatch",
+ sizeof(incons_str));
+ } else {
+ strlcpy(incons_str, "-", sizeof(incons_str));
+ }
+ vty_out(vty, " Inconsistencies: %s\n",
+ incons_str);
+ vty_out(vty, " VTEPs: %s\n", vtep_str);
+ vty_out(vty, "\n");
+ }
+}
+
+/* Display all ESs */
+void bgp_evpn_es_show(struct vty *vty, bool uj, bool detail)
+{
+ struct bgp_evpn_es *es;
+ json_object *json_array = NULL;
+ json_object *json = NULL;
+
+ if (uj) {
+ /* create an array of ESs */
+ json_array = json_object_new_array();
+ } else {
+ if (!detail) {
+ vty_out(vty,
+ "ES Flags: L local, R remote, I inconsistent\n");
+ vty_out(vty,
+ "VTEP Flags: E ESR/Type-4, A active nexthop\n");
+ vty_out(vty,
+ "%-30s %-5s %-21s %-8s %s\n",
+ "ESI", "Flags", "RD", "#VNIs", "VTEPs");
+ }
+ }
+
+ RB_FOREACH(es, bgp_es_rb_head, &bgp_mh_info->es_rb_tree) {
+ if (uj)
+ /* create a separate json object for each ES */
+ json = json_object_new_object();
+ if (detail)
+ bgp_evpn_es_show_entry_detail(vty, es, json);
+ else
+ bgp_evpn_es_show_entry(vty, es, json);
+ /* add ES to the json array */
+ if (uj)
+ json_object_array_add(json_array, json);
+ }
+
+ /* print the array of json-ESs */
+ if (uj) {
+ vty_out(vty, "%s\n", json_object_to_json_string_ext(
+ json_array, JSON_C_TO_STRING_PRETTY));
+ json_object_free(json_array);
+ }
+}
+
+/* Display specific ES */
+void bgp_evpn_es_show_esi(struct vty *vty, esi_t *esi, bool uj)
+{
+ struct bgp_evpn_es *es;
+ json_object *json = NULL;
+
+ if (uj)
+ json = json_object_new_object();
+
+ es = bgp_evpn_es_find(esi);
+ if (es) {
+ bgp_evpn_es_show_entry_detail(vty, es, json);
+ } else {
+ if (!uj)
+ vty_out(vty, "ESI not found\n");
+ }
+
+ if (uj) {
+ vty_out(vty, "%s\n", json_object_to_json_string_ext(
+ json, JSON_C_TO_STRING_PRETTY));
+ json_object_free(json);
+ }
+}
+
+/*****************************************************************************/
+/* Ethernet Segment to EVI association -
+ * 1. The ES-EVI entry is maintained as a RB tree per L2-VNI
+ * (bgpevpn->es_evi_rb_tree).
+ * 2. Each local ES-EVI entry is rxed from zebra and then used by BGP to
+ * advertises an EAD-EVI (Type-1 EVPN) route
+ * 3. The remote ES-EVI is created when a bgp_evpn_es_evi_vtep references
+ * it.
+ */
+
+/* A list of remote VTEPs is maintained for each ES-EVI. This list includes -
+ * 1. VTEPs for which we have imported the EAD-per-ES Type1 route
+ * 2. VTEPs for which we have imported the EAD-per-EVI Type1 route
+ * VTEPs for which both routes have been rxed are activated. Activation
+ * creates a NHG in the parent ES.
+ */
+static int bgp_evpn_es_evi_vtep_cmp(void *p1, void *p2)
+{
+ const struct bgp_evpn_es_evi_vtep *evi_vtep1 = p1;
+ const struct bgp_evpn_es_evi_vtep *evi_vtep2 = p2;
+
+ return evi_vtep1->vtep_ip.s_addr - evi_vtep2->vtep_ip.s_addr;
+}
+
+static struct bgp_evpn_es_evi_vtep *bgp_evpn_es_evi_vtep_new(
+ struct bgp_evpn_es_evi *es_evi, struct in_addr vtep_ip)
+{
+ struct bgp_evpn_es_evi_vtep *evi_vtep;
+
+ evi_vtep = XCALLOC(MTYPE_BGP_EVPN_ES_EVI_VTEP, sizeof(*evi_vtep));
+
+ evi_vtep->es_evi = es_evi;
+ evi_vtep->vtep_ip.s_addr = vtep_ip.s_addr;
+ listnode_init(&evi_vtep->es_evi_listnode, evi_vtep);
+ listnode_add_sort(es_evi->es_evi_vtep_list, &evi_vtep->es_evi_listnode);
+
+ return evi_vtep;
+}
+
+static void bgp_evpn_es_evi_vtep_free(struct bgp_evpn_es_evi_vtep *evi_vtep)
+{
+ struct bgp_evpn_es_evi *es_evi = evi_vtep->es_evi;
+
+ if (evi_vtep->flags & (BGP_EVPN_EVI_VTEP_EAD))
+ /* as long as there is some reference we can't free it */
+ return;
+
+ list_delete_node(es_evi->es_evi_vtep_list, &evi_vtep->es_evi_listnode);
+ XFREE(MTYPE_BGP_EVPN_ES_EVI_VTEP, evi_vtep);
+}
+
+/* check if VTEP is already part of the list */
+static struct bgp_evpn_es_evi_vtep *bgp_evpn_es_evi_vtep_find(
+ struct bgp_evpn_es_evi *es_evi, struct in_addr vtep_ip)
+{
+ struct listnode *node = NULL;
+ struct bgp_evpn_es_evi_vtep *evi_vtep;
+
+ for (ALL_LIST_ELEMENTS_RO(es_evi->es_evi_vtep_list, node, evi_vtep)) {
+ if (evi_vtep->vtep_ip.s_addr == vtep_ip.s_addr)
+ return evi_vtep;
+ }
+ return NULL;
+}
+
+/* A VTEP can be added as "active" attach to an ES if EAD-per-ES and
+ * EAD-per-EVI routes are rxed from it.
+ */
+static void bgp_evpn_es_evi_vtep_re_eval_active(struct bgp *bgp,
+ struct bgp_evpn_es_evi_vtep *evi_vtep)
+{
+ bool old_active;
+ bool new_active;
+
+ old_active = !!CHECK_FLAG(evi_vtep->flags, BGP_EVPN_EVI_VTEP_ACTIVE);
+
+ /* Both EAD-per-ES and EAD-per-EVI routes must be rxed from a PE
+ * before it can be activated.
+ */
+ if ((evi_vtep->flags & BGP_EVPN_EVI_VTEP_EAD) ==
+ BGP_EVPN_EVI_VTEP_EAD)
+ SET_FLAG(evi_vtep->flags, BGP_EVPN_EVI_VTEP_ACTIVE);
+ else
+ UNSET_FLAG(evi_vtep->flags, BGP_EVPN_EVI_VTEP_ACTIVE);
+
+ new_active = !!CHECK_FLAG(evi_vtep->flags, BGP_EVPN_EVI_VTEP_ACTIVE);
+
+ if (old_active == new_active)
+ return;
+
+ if (BGP_DEBUG(evpn_mh, EVPN_MH_ES))
+ zlog_debug("es %s evi %u vtep %s %s",
+ evi_vtep->es_evi->es->esi_str,
+ evi_vtep->es_evi->vpn->vni,
+ inet_ntoa(evi_vtep->vtep_ip),
+ new_active ? "active" : "inactive");
+
+ /* add VTEP to parent es */
+ if (new_active) {
+ struct bgp_evpn_es_vtep *es_vtep;
+
+ es_vtep = bgp_evpn_es_vtep_add(bgp, evi_vtep->es_evi->es,
+ evi_vtep->vtep_ip, false /*esr*/);
+ evi_vtep->es_vtep = es_vtep;
+ } else {
+ if (evi_vtep->es_vtep) {
+ bgp_evpn_es_vtep_do_del(bgp, evi_vtep->es_vtep,
+ false /*esr*/);
+ evi_vtep->es_vtep = NULL;
+ }
+ }
+ /* queue up the parent es for background consistency checks */
+ bgp_evpn_es_cons_checks_pend_add(evi_vtep->es_evi->es);
+}
+
+static void bgp_evpn_es_evi_vtep_add(struct bgp *bgp,
+ struct bgp_evpn_es_evi *es_evi, struct in_addr vtep_ip,
+ bool ead_es)
+{
+ struct bgp_evpn_es_evi_vtep *evi_vtep;
+
+ evi_vtep = bgp_evpn_es_evi_vtep_find(es_evi, vtep_ip);
+
+ if (!evi_vtep)
+ evi_vtep = bgp_evpn_es_evi_vtep_new(es_evi, vtep_ip);
+
+ if (BGP_DEBUG(evpn_mh, EVPN_MH_ES))
+ zlog_debug("add es %s evi %u vtep %s %s",
+ evi_vtep->es_evi->es->esi_str,
+ evi_vtep->es_evi->vpn->vni,
+ inet_ntoa(evi_vtep->vtep_ip),
+ ead_es ? "ead_es" : "ead_evi");
+
+ if (ead_es)
+ SET_FLAG(evi_vtep->flags, BGP_EVPN_EVI_VTEP_EAD_PER_ES);
+ else
+ SET_FLAG(evi_vtep->flags, BGP_EVPN_EVI_VTEP_EAD_PER_EVI);
+
+ bgp_evpn_es_evi_vtep_re_eval_active(bgp, evi_vtep);
+}
+
+static void bgp_evpn_es_evi_vtep_del(struct bgp *bgp,
+ struct bgp_evpn_es_evi *es_evi, struct in_addr vtep_ip,
+ bool ead_es)
+{
+ struct bgp_evpn_es_evi_vtep *evi_vtep;
+
+ evi_vtep = bgp_evpn_es_evi_vtep_find(es_evi, vtep_ip);
+ if (!evi_vtep)
+ return;
+
+ if (BGP_DEBUG(evpn_mh, EVPN_MH_ES))
+ zlog_debug("del es %s evi %u vtep %s %s",
+ evi_vtep->es_evi->es->esi_str,
+ evi_vtep->es_evi->vpn->vni,
+ inet_ntoa(evi_vtep->vtep_ip),
+ ead_es ? "ead_es" : "ead_evi");
+
+ if (ead_es)
+ UNSET_FLAG(evi_vtep->flags, BGP_EVPN_EVI_VTEP_EAD_PER_ES);
+ else
+ UNSET_FLAG(evi_vtep->flags, BGP_EVPN_EVI_VTEP_EAD_PER_EVI);
+
+ bgp_evpn_es_evi_vtep_re_eval_active(bgp, evi_vtep);
+ bgp_evpn_es_evi_vtep_free(evi_vtep);
+}
+
+/* compare ES-IDs for the ES-EVI RB tree maintained per-VNI */
+static int bgp_es_evi_rb_cmp(const struct bgp_evpn_es_evi *es_evi1,
+ const struct bgp_evpn_es_evi *es_evi2)
+{
+ return memcmp(&es_evi1->es->esi, &es_evi2->es->esi, ESI_BYTES);
+}
+RB_GENERATE(bgp_es_evi_rb_head, bgp_evpn_es_evi, rb_node, bgp_es_evi_rb_cmp);
+
+/* find the ES-EVI in the per-L2-VNI RB tree */
+static struct bgp_evpn_es_evi *bgp_evpn_es_evi_find(struct bgp_evpn_es *es,
+ struct bgpevpn *vpn)
+{
+ struct bgp_evpn_es_evi es_evi;
+
+ es_evi.es = es;
+
+ return RB_FIND(bgp_es_evi_rb_head, &vpn->es_evi_rb_tree, &es_evi);
+}
+
+/* allocate a new ES-EVI and insert it into the per-L2-VNI and per-ES
+ * tables.
+ */
+static struct bgp_evpn_es_evi *bgp_evpn_es_evi_new(struct bgp_evpn_es *es,
+ struct bgpevpn *vpn)
+{
+ struct bgp_evpn_es_evi *es_evi;
+
+ es_evi = XCALLOC(MTYPE_BGP_EVPN_ES_EVI, sizeof(*es_evi));
+
+ es_evi->es = es;
+ es_evi->vpn = vpn;
+
+ /* Initialise the VTEP list */
+ es_evi->es_evi_vtep_list = list_new();
+ listset_app_node_mem(es_evi->es_evi_vtep_list);
+ es_evi->es_evi_vtep_list->cmp = bgp_evpn_es_evi_vtep_cmp;
+
+ /* insert into the VNI-ESI rb tree */
+ if (RB_INSERT(bgp_es_evi_rb_head, &vpn->es_evi_rb_tree, es_evi)) {
+ XFREE(MTYPE_BGP_EVPN_ES_EVI, es_evi);
+ return NULL;
+ }
+
+ /* add to the ES's VNI list */
+ listnode_init(&es_evi->es_listnode, es_evi);
+ listnode_add(es->es_evi_list, &es_evi->es_listnode);
+
+ return es_evi;
+}
+
+/* remove the ES-EVI from the per-L2-VNI and per-ES tables and free
+ * up the memory.
+ */
+static void bgp_evpn_es_evi_free(struct bgp_evpn_es_evi *es_evi)
+{
+ struct bgp_evpn_es *es = es_evi->es;
+ struct bgpevpn *vpn = es_evi->vpn;
+
+ /* cannot free the element as long as there is a local or remote
+ * reference
+ */
+ if (es_evi->flags & (BGP_EVPNES_EVI_LOCAL | BGP_EVPNES_EVI_REMOTE))
+ return;
+
+ /* remove from the ES's VNI list */
+ list_delete_node(es->es_evi_list, &es_evi->es_listnode);
+
+ /* remove from the VNI-ESI rb tree */
+ RB_REMOVE(bgp_es_evi_rb_head, &vpn->es_evi_rb_tree, es_evi);
+
+ /* free the VTEP list */
+ list_delete(&es_evi->es_evi_vtep_list);
+
+ /* remove from the VNI-ESI rb tree */
+ XFREE(MTYPE_BGP_EVPN_ES_EVI, es_evi);
+}
+
+/* init local info associated with the ES-EVI */
+static void bgp_evpn_es_evi_local_info_set(struct bgp_evpn_es_evi *es_evi)
+{
+ struct bgpevpn *vpn = es_evi->vpn;
+
+ if (CHECK_FLAG(es_evi->flags, BGP_EVPNES_EVI_LOCAL))
+ return;
+
+ SET_FLAG(es_evi->flags, BGP_EVPNES_EVI_LOCAL);
+ listnode_init(&es_evi->l2vni_listnode, es_evi);
+ listnode_add(vpn->local_es_evi_list, &es_evi->l2vni_listnode);
+}
+
+/* clear any local info associated with the ES-EVI */
+static void bgp_evpn_es_evi_local_info_clear(struct bgp_evpn_es_evi *es_evi)
+{
+ struct bgpevpn *vpn = es_evi->vpn;
+
+ if (!CHECK_FLAG(es_evi->flags, BGP_EVPNES_EVI_LOCAL))
+ return;
+
+ UNSET_FLAG(es_evi->flags, BGP_EVPNES_EVI_LOCAL);
+ list_delete_node(vpn->local_es_evi_list, &es_evi->l2vni_listnode);
+
+ bgp_evpn_es_evi_free(es_evi);
+}
+
+/* eval remote info associated with the ES */
+static void bgp_evpn_es_evi_remote_info_re_eval(struct bgp_evpn_es_evi *es_evi)
+{
+ struct bgp_evpn_es *es = es_evi->es;
+
+ /* if there are remote VTEPs the ES-EVI is classified as "remote" */
+ if (listcount(es_evi->es_evi_vtep_list)) {
+ if (!CHECK_FLAG(es_evi->flags, BGP_EVPNES_EVI_REMOTE)) {
+ SET_FLAG(es_evi->flags, BGP_EVPNES_EVI_REMOTE);
+ ++es->remote_es_evi_cnt;
+ /* set remote on the parent es */
+ bgp_evpn_es_remote_info_re_eval(es);
+ }
+ } else {
+ if (CHECK_FLAG(es_evi->flags, BGP_EVPNES_EVI_REMOTE)) {
+ UNSET_FLAG(es_evi->flags, BGP_EVPNES_EVI_REMOTE);
+ if (es->remote_es_evi_cnt)
+ --es->remote_es_evi_cnt;
+ bgp_evpn_es_evi_free(es_evi);
+ /* check if "remote" can be cleared from the
+ * parent es.
+ */
+ bgp_evpn_es_remote_info_re_eval(es);
+ }
+ }
+}
+
+static void bgp_evpn_local_es_evi_do_del(struct bgp_evpn_es_evi *es_evi)
+{
+ struct prefix_evpn p;
+ struct bgp_evpn_es *es = es_evi->es;
+ struct bgp *bgp;
+
+ if (!CHECK_FLAG(es_evi->flags, BGP_EVPNES_EVI_LOCAL))
+ return;
+
+ if (BGP_DEBUG(evpn_mh, EVPN_MH_ES))
+ zlog_debug("del local es %s evi %u",
+ es_evi->es->esi_str,
+ es_evi->vpn->vni);
+
+ bgp = bgp_get_evpn();
+
+ if (bgp) {
+ /* update EAD-ES with new list of VNIs */
+ if (CHECK_FLAG(es->flags, BGP_EVPNES_OPER_UP)) {
+ build_evpn_type1_prefix(&p, BGP_EVPN_AD_ES_ETH_TAG,
+ &es->esi, es->originator_ip);
+ if (bgp_evpn_type1_route_update(bgp, es, NULL, &p))
+ flog_err(EC_BGP_EVPN_ROUTE_CREATE,
+ "%u: EAD-ES route update failure for ESI %s VNI %u",
+ bgp->vrf_id, es->esi_str,
+ es_evi->vpn->vni);
+ }
+
+ /* withdraw and delete EAD-EVI */
+ if (CHECK_FLAG(es->flags, BGP_EVPNES_ADV_EVI)) {
+ build_evpn_type1_prefix(&p, BGP_EVPN_AD_EVI_ETH_TAG,
+ &es->esi, es->originator_ip);
+ if (bgp_evpn_type1_evi_route_delete(bgp,
+ es, es_evi->vpn, &p))
+ flog_err(EC_BGP_EVPN_ROUTE_DELETE,
+ "%u: EAD-EVI route deletion failure for ESI %s VNI %u",
+ bgp->vrf_id, es->esi_str,
+ es_evi->vpn->vni);
+ }
+ }
+
+ bgp_evpn_es_evi_local_info_clear(es_evi);
+
+}
+
+int bgp_evpn_local_es_evi_del(struct bgp *bgp, esi_t *esi, vni_t vni)
+{
+ struct bgpevpn *vpn;
+ struct bgp_evpn_es *es;
+ struct bgp_evpn_es_evi *es_evi;
+ char buf[ESI_STR_LEN];
+
+ es = bgp_evpn_es_find(esi);
+ if (!es) {
+ flog_err(
+ EC_BGP_ES_CREATE,
+ "%u: Failed to deref VNI %d from ESI %s; ES not present",
+ bgp->vrf_id, vni,
+ esi_to_str(esi, buf, sizeof(buf)));
+ return -1;
+ }
+
+ vpn = bgp_evpn_lookup_vni(bgp, vni);
+ if (!vpn) {
+ flog_err(
+ EC_BGP_ES_CREATE,
+ "%u: Failed to deref VNI %d from ESI %s; VNI not present",
+ bgp->vrf_id, vni, es->esi_str);
+ return -1;
+ }
+
+ es_evi = bgp_evpn_es_evi_find(es, vpn);
+ if (!es_evi) {
+ flog_err(
+ EC_BGP_ES_CREATE,
+ "%u: Failed to deref VNI %d from ESI %s; ES-VNI not present",
+ bgp->vrf_id, vni, es->esi_str);
+ return -1;
+ }
+
+ bgp_evpn_local_es_evi_do_del(es_evi);
+ return 0;
+}
+
+/* Create ES-EVI and advertise the corresponding EAD routes */
+int bgp_evpn_local_es_evi_add(struct bgp *bgp, esi_t *esi, vni_t vni)
+{
+ struct bgpevpn *vpn;
+ struct prefix_evpn p;
+ struct bgp_evpn_es *es;
+ struct bgp_evpn_es_evi *es_evi;
+ char buf[ESI_STR_LEN];
+
+ es = bgp_evpn_es_find(esi);
+ if (!es) {
+ flog_err(
+ EC_BGP_ES_CREATE,
+ "%u: Failed to associate VNI %d with ESI %s; ES not present",
+ bgp->vrf_id, vni,
+ esi_to_str(esi, buf, sizeof(buf)));
+ return -1;
+ }
+
+ vpn = bgp_evpn_lookup_vni(bgp, vni);
+ if (!vpn) {
+ flog_err(
+ EC_BGP_ES_CREATE,
+ "%u: Failed to associate VNI %d with ESI %s; VNI not present",
+ bgp->vrf_id, vni, es->esi_str);
+ return -1;
+ }
+
+ if (BGP_DEBUG(evpn_mh, EVPN_MH_ES))
+ zlog_debug("add local es %s evi %u",
+ es->esi_str, vni);
+
+ es_evi = bgp_evpn_es_evi_find(es, vpn);
+
+ if (es_evi) {
+ if (CHECK_FLAG(es_evi->flags, BGP_EVPNES_EVI_LOCAL))
+ /* dup */
+ return 0;
+ } else {
+ es_evi = bgp_evpn_es_evi_new(es, vpn);
+ if (!es_evi)
+ return -1;
+ }
+
+ bgp_evpn_es_evi_local_info_set(es_evi);
+
+ /* generate an EAD-EVI for this new VNI */
+ build_evpn_type1_prefix(&p, BGP_EVPN_AD_EVI_ETH_TAG,
+ &es->esi, es->originator_ip);
+ if (CHECK_FLAG(es->flags, BGP_EVPNES_ADV_EVI)) {
+ if (bgp_evpn_type1_route_update(bgp, es, vpn, &p))
+ flog_err(EC_BGP_EVPN_ROUTE_CREATE,
+ "%u: EAD-EVI route creation failure for ESI %s VNI %u",
+ bgp->vrf_id, es->esi_str, vni);
+ }
+
+ /* update EAD-ES */
+ build_evpn_type1_prefix(&p, BGP_EVPN_AD_ES_ETH_TAG,
+ &es->esi, es->originator_ip);
+ if (CHECK_FLAG(es->flags, BGP_EVPNES_OPER_UP)) {
+ if (bgp_evpn_type1_route_update(bgp, es, NULL, &p))
+ flog_err(EC_BGP_EVPN_ROUTE_CREATE,
+ "%u: EAD-ES route creation failure for ESI %s VNI %u",
+ bgp->vrf_id, es->esi_str, vni);
+ }
+
+ return 0;
+}
+
+/* Add remote ES-EVI entry. This is actually the remote VTEP add and the
+ * ES-EVI is implicity created on first VTEP's reference.
+ */
+int bgp_evpn_remote_es_evi_add(struct bgp *bgp, struct bgpevpn *vpn,
+ const struct prefix_evpn *p)
+{
+ char buf[ESI_STR_LEN];
+ struct bgp_evpn_es *es;
+ struct bgp_evpn_es_evi *es_evi;
+ bool ead_es;
+ const esi_t *esi = &p->prefix.ead_addr.esi;
+
+ if (!vpn)
+ /* local EAD-ES need not be sent back to zebra */
+ return 0;
+
+ if (BGP_DEBUG(evpn_mh, EVPN_MH_ES))
+ zlog_debug("add remote %s es %s evi %u vtep %s",
+ p->prefix.ead_addr.eth_tag ?
+ "ead-es" : "ead-evi",
+ esi_to_str(esi, buf,
+ sizeof(buf)),
+ vpn->vni,
+ inet_ntoa(p->prefix.ead_addr.ip.ipaddr_v4));
+
+ es = bgp_evpn_es_find(esi);
+ if (!es) {
+ es = bgp_evpn_es_new(bgp, esi);
+ if (!es) {
+ flog_err(EC_BGP_ES_CREATE,
+ "%u: Failed to allocate ES entry for ESI %s - at remote ES Add",
+ bgp->vrf_id, esi_to_str(esi, buf, sizeof(buf)));
+ return -1;
+ }
+ }
+
+ es_evi = bgp_evpn_es_evi_find(es, vpn);
+ if (!es_evi) {
+ es_evi = bgp_evpn_es_evi_new(es, vpn);
+ if (!es_evi) {
+ bgp_evpn_es_free(es);
+ return -1;
+ }
+ }
+
+ ead_es = !!p->prefix.ead_addr.eth_tag;
+ bgp_evpn_es_evi_vtep_add(bgp, es_evi, p->prefix.ead_addr.ip.ipaddr_v4,
+ ead_es);
+
+ bgp_evpn_es_evi_remote_info_re_eval(es_evi);
+ return 0;
+}
+
+/* A remote VTEP has withdrawn. The es-evi-vtep will be deleted and the
+ * parent es-evi freed up implicitly in last VTEP's deref.
+ */
+int bgp_evpn_remote_es_evi_del(struct bgp *bgp, struct bgpevpn *vpn,
+ const struct prefix_evpn *p)
+{
+ char buf[ESI_STR_LEN];
+ struct bgp_evpn_es *es;
+ struct bgp_evpn_es_evi *es_evi;
+ bool ead_es;
+
+ if (!vpn)
+ /* local EAD-ES need not be sent back to zebra */
+ return 0;
+
+ if (BGP_DEBUG(evpn_mh, EVPN_MH_ES))
+ zlog_debug("del remote %s es %s evi %u vtep %s",
+ p->prefix.ead_addr.eth_tag ?
+ "ead-es" : "ead-evi",
+ esi_to_str(&p->prefix.ead_addr.esi, buf,
+ sizeof(buf)),
+ vpn->vni,
+ inet_ntoa(p->prefix.ead_addr.ip.ipaddr_v4));
+
+ es = bgp_evpn_es_find(&p->prefix.ead_addr.esi);
+ if (!es)
+ /* XXX - error logs */
+ return 0;
+ es_evi = bgp_evpn_es_evi_find(es, vpn);
+ if (!es_evi)
+ /* XXX - error logs */
+ return 0;
+
+ ead_es = !!p->prefix.ead_addr.eth_tag;
+ bgp_evpn_es_evi_vtep_del(bgp, es_evi, p->prefix.ead_addr.ip.ipaddr_v4,
+ ead_es);
+ bgp_evpn_es_evi_remote_info_re_eval(es_evi);
+ return 0;
+}
+
+/* Initialize the ES tables maintained per-L2_VNI */
+void bgp_evpn_vni_es_init(struct bgpevpn *vpn)
+{
+ /* Initialize the ES-EVI RB tree */
+ RB_INIT(bgp_es_evi_rb_head, &vpn->es_evi_rb_tree);
+
+ /* Initialize the local list maintained for quick walks by type */
+ vpn->local_es_evi_list = list_new();
+ listset_app_node_mem(vpn->local_es_evi_list);
+}
+
+/* Cleanup the ES info maintained per-L2_VNI */
+void bgp_evpn_vni_es_cleanup(struct bgpevpn *vpn)
+{
+ struct bgp_evpn_es_evi *es_evi;
+ struct bgp_evpn_es_evi *es_evi_next;
+
+ RB_FOREACH_SAFE(es_evi, bgp_es_evi_rb_head,
+ &vpn->es_evi_rb_tree, es_evi_next) {
+ bgp_evpn_local_es_evi_do_del(es_evi);
+ }
+
+ list_delete(&vpn->local_es_evi_list);
+}
+
+static char *bgp_evpn_es_evi_vteps_str(char *vtep_str,
+ struct bgp_evpn_es_evi *es_evi,
+ uint8_t vtep_str_size)
+{
+ char vtep_flag_str[BGP_EVPN_FLAG_STR_SZ];
+ struct listnode *node;
+ struct bgp_evpn_es_evi_vtep *evi_vtep;
+ bool first = true;
+
+ vtep_str[0] = '\0';
+ for (ALL_LIST_ELEMENTS_RO(es_evi->es_evi_vtep_list, node, evi_vtep)) {
+ vtep_flag_str[0] = '\0';
+ if (evi_vtep->flags & BGP_EVPN_EVI_VTEP_EAD_PER_ES)
+ strlcat(vtep_flag_str, "E", sizeof(vtep_flag_str));
+ if (evi_vtep->flags & BGP_EVPN_EVI_VTEP_EAD_PER_EVI)
+ strlcat(vtep_flag_str, "V", sizeof(vtep_flag_str));
+
+ if (!strnlen(vtep_flag_str, sizeof(vtep_flag_str)))
+ strlcpy(vtep_flag_str, "-", sizeof(vtep_flag_str));
+ if (first)
+ first = false;
+ else
+ strlcat(vtep_str, ",", vtep_str_size);
+ strlcat(vtep_str, inet_ntoa(evi_vtep->vtep_ip), vtep_str_size);
+ strlcat(vtep_str, "(", vtep_str_size);
+ strlcat(vtep_str, vtep_flag_str, vtep_str_size);
+ strlcat(vtep_str, ")", vtep_str_size);
+ }
+
+ return vtep_str;
+}
+
+static void bgp_evpn_es_evi_json_vtep_fill(json_object *json_vteps,
+ struct bgp_evpn_es_evi_vtep *evi_vtep)
+{
+ json_object *json_vtep_entry;
+ json_object *json_flags;
+
+ json_vtep_entry = json_object_new_object();
+
+ json_object_string_add(json_vtep_entry,
+ "vtep_ip",
+ inet_ntoa(evi_vtep->vtep_ip));
+ if (evi_vtep->flags & (BGP_EVPN_EVI_VTEP_EAD_PER_ES |
+ BGP_EVPN_EVI_VTEP_EAD_PER_EVI)) {
+ json_flags = json_object_new_array();
+ if (evi_vtep->flags & BGP_EVPN_EVI_VTEP_EAD_PER_ES)
+ json_array_string_add(json_flags, "ead-per-es");
+ if (evi_vtep->flags & BGP_EVPN_EVI_VTEP_EAD_PER_EVI)
+ json_array_string_add(json_flags, "ed-per-evi");
+ json_object_object_add(json_vtep_entry,
+ "flags", json_flags);
+ }
+
+ json_object_array_add(json_vteps,
+ json_vtep_entry);
+}
+
+static void bgp_evpn_es_evi_show_entry(struct vty *vty,
+ struct bgp_evpn_es_evi *es_evi, json_object *json)
+{
+ struct listnode *node;
+ struct bgp_evpn_es_evi_vtep *evi_vtep;
+
+ if (json) {
+ json_object *json_vteps;
+ json_object *json_types;
+
+ json_object_string_add(json, "esi", es_evi->es->esi_str);
+ json_object_int_add(json, "vni", es_evi->vpn->vni);
+
+ if (es_evi->flags & (BGP_EVPNES_EVI_LOCAL |
+ BGP_EVPNES_EVI_REMOTE)) {
+ json_types = json_object_new_array();
+ if (es_evi->flags & BGP_EVPNES_EVI_LOCAL)
+ json_array_string_add(json_types, "local");
+ if (es_evi->flags & BGP_EVPNES_EVI_REMOTE)
+ json_array_string_add(json_types, "remote");
+ json_object_object_add(json, "type", json_types);
+ }
+
+ if (listcount(es_evi->es_evi_vtep_list)) {
+ json_vteps = json_object_new_array();
+ for (ALL_LIST_ELEMENTS_RO(es_evi->es_evi_vtep_list,
+ node, evi_vtep)) {
+ bgp_evpn_es_evi_json_vtep_fill(json_vteps,
+ evi_vtep);
+ }
+ json_object_object_add(json, "vteps", json_vteps);
+ }
+ } else {
+ char type_str[4];
+ char vtep_str[ES_VTEP_LIST_STR_SZ + BGP_EVPN_VTEPS_FLAG_STR_SZ];
+
+ type_str[0] = '\0';
+ if (es_evi->flags & BGP_EVPNES_EVI_LOCAL)
+ strlcat(type_str, "L", sizeof(type_str));
+ if (es_evi->flags & BGP_EVPNES_EVI_REMOTE)
+ strlcat(type_str, "R", sizeof(type_str));
+ if (es_evi->flags & BGP_EVPNES_EVI_INCONS_VTEP_LIST)
+ strlcat(type_str, "I", sizeof(type_str));
+
+ bgp_evpn_es_evi_vteps_str(vtep_str, es_evi, sizeof(vtep_str));
+
+ vty_out(vty, "%-8d %-30s %-5s %s\n",
+ es_evi->vpn->vni, es_evi->es->esi_str,
+ type_str, vtep_str);
+ }
+}
+
+static void bgp_evpn_es_evi_show_entry_detail(struct vty *vty,
+ struct bgp_evpn_es_evi *es_evi, json_object *json)
+{
+ if (json) {
+ json_object *json_flags;
+
+ /* Add the "brief" info first */
+ bgp_evpn_es_evi_show_entry(vty, es_evi, json);
+ if (es_evi->flags & BGP_EVPNES_EVI_INCONS_VTEP_LIST) {
+ json_flags = json_object_new_array();
+ json_array_string_add(json_flags, "es-vtep-mismatch");
+ json_object_object_add(json, "flags", json_flags);
+ }
+ } else {
+ char vtep_str[ES_VTEP_LIST_STR_SZ + BGP_EVPN_VTEPS_FLAG_STR_SZ];
+ char type_str[4];
+
+ type_str[0] = '\0';
+ if (es_evi->flags & BGP_EVPNES_EVI_LOCAL)
+ strlcat(type_str, "L", sizeof(type_str));
+ if (es_evi->flags & BGP_EVPNES_EVI_REMOTE)
+ strlcat(type_str, "R", sizeof(type_str));
+
+ bgp_evpn_es_evi_vteps_str(vtep_str, es_evi, sizeof(vtep_str));
+ if (!strlen(vtep_str))
+ strlcpy(vtep_str, "-", sizeof(type_str));
+
+ vty_out(vty, "VNI: %d ESI: %s\n",
+ es_evi->vpn->vni, es_evi->es->esi_str);
+ vty_out(vty, " Type: %s\n", type_str);
+ vty_out(vty, " Inconsistencies: %s\n",
+ (es_evi->flags & BGP_EVPNES_EVI_INCONS_VTEP_LIST) ?
+ "es-vtep-mismatch":"-");
+ vty_out(vty, " VTEPs: %s\n", vtep_str);
+ vty_out(vty, "\n");
+ }
+}
+
+static void bgp_evpn_es_evi_show_one_vni(struct bgpevpn *vpn, struct vty *vty,
+ json_object *json_array, bool detail)
+{
+ struct bgp_evpn_es_evi *es_evi;
+ json_object *json = NULL;
+
+ RB_FOREACH(es_evi, bgp_es_evi_rb_head, &vpn->es_evi_rb_tree) {
+ if (json_array)
+ /* create a separate json object for each ES */
+ json = json_object_new_object();
+ if (detail)
+ bgp_evpn_es_evi_show_entry_detail(vty, es_evi, json);
+ else
+ bgp_evpn_es_evi_show_entry(vty, es_evi, json);
+ /* add ES to the json array */
+ if (json_array)
+ json_object_array_add(json_array, json);
+ }
+}
+
+struct es_evi_show_ctx {
+ struct vty *vty;
+ json_object *json;
+ int detail;
+};
+
+static void bgp_evpn_es_evi_show_one_vni_hash_cb(struct hash_bucket *bucket,
+ void *ctxt)
+{
+ struct bgpevpn *vpn = (struct bgpevpn *)bucket->data;
+ struct es_evi_show_ctx *wctx = (struct es_evi_show_ctx *)ctxt;
+
+ bgp_evpn_es_evi_show_one_vni(vpn, wctx->vty, wctx->json, wctx->detail);
+}
+
+/* Display all ES EVIs */
+void bgp_evpn_es_evi_show(struct vty *vty, bool uj, bool detail)
+{
+ json_object *json_array = NULL;
+ struct es_evi_show_ctx wctx;
+ struct bgp *bgp;
+
+ if (uj) {
+ /* create an array of ES-EVIs */
+ json_array = json_object_new_array();
+ }
+
+ wctx.vty = vty;
+ wctx.json = json_array;
+ wctx.detail = detail;
+
+ bgp = bgp_get_evpn();
+
+ if (!json_array && !detail) {
+ vty_out(vty, "Flags: L local, R remote, I inconsistent\n");
+ vty_out(vty, "VTEP-Flags: E EAD-per-ES, V EAD-per-EVI\n");
+ vty_out(vty, "%-8s %-30s %-5s %s\n",
+ "VNI", "ESI", "Flags", "VTEPs");
+ }
+
+ if (bgp)
+ hash_iterate(bgp->vnihash,
+ (void (*)(struct hash_bucket *,
+ void *))bgp_evpn_es_evi_show_one_vni_hash_cb,
+ &wctx);
+ if (uj) {
+ vty_out(vty, "%s\n", json_object_to_json_string_ext(
+ json_array, JSON_C_TO_STRING_PRETTY));
+ json_object_free(json_array);
+ }
+}
+
+/* Display specific ES EVI */
+void bgp_evpn_es_evi_show_vni(struct vty *vty, vni_t vni,
+ bool uj, bool detail)
+{
+ struct bgpevpn *vpn = NULL;
+ json_object *json_array = NULL;
+ struct bgp *bgp;
+
+ if (uj) {
+ /* create an array of ES-EVIs */
+ json_array = json_object_new_array();
+ }
+
+ bgp = bgp_get_evpn();
+ if (bgp)
+ vpn = bgp_evpn_lookup_vni(bgp, vni);
+
+ if (vpn) {
+ if (!json_array && !detail) {
+ vty_out(vty, "Flags: L local, R remote, I inconsistent\n");
+ vty_out(vty, "VTEP-Flags: E EAD-per-ES, V EAD-per-EVI\n");
+ vty_out(vty, "%-8s %-30s %-5s %s\n",
+ "VNI", "ESI", "Flags", "VTEPs");
+ }
+
+ bgp_evpn_es_evi_show_one_vni(vpn, vty, json_array, detail);
+ } else {
+ if (!uj)
+ vty_out(vty, "VNI not found\n");
+ }
+
+ if (uj) {
+ vty_out(vty, "%s\n", json_object_to_json_string_ext(
+ json_array, JSON_C_TO_STRING_PRETTY));
+ json_object_free(json_array);
+ }
+}
+
+/*****************************************************************************
+ * Ethernet Segment Consistency checks
+ * Consistency checking is done to detect misconfig or mis-cabling. When
+ * an inconsistency is detected it is simply logged (and displayed via
+ * show commands) at this point. A more drastic action can be executed (based
+ * on user config) in the future.
+ */
+/* queue up the es for background consistency checks */
+static void bgp_evpn_es_cons_checks_pend_add(struct bgp_evpn_es *es)
+{
+ if (!bgp_mh_info->consistency_checking)
+ /* consistency checking is not enabled */
+ return;
+
+ if (CHECK_FLAG(es->flags, BGP_EVPNES_CONS_CHECK_PEND))
+ /* already queued for consistency checking */
+ return;
+
+ SET_FLAG(es->flags, BGP_EVPNES_CONS_CHECK_PEND);
+ listnode_init(&es->pend_es_listnode, es);
+ listnode_add_after(bgp_mh_info->pend_es_list,
+ listtail_unchecked(bgp_mh_info->pend_es_list),
+ &es->pend_es_listnode);
+}
+
+/* pull the ES from the consistency check list */
+static void bgp_evpn_es_cons_checks_pend_del(struct bgp_evpn_es *es)
+{
+ if (!CHECK_FLAG(es->flags, BGP_EVPNES_CONS_CHECK_PEND))
+ return;
+
+ UNSET_FLAG(es->flags, BGP_EVPNES_CONS_CHECK_PEND);
+ list_delete_node(bgp_mh_info->pend_es_list,
+ &es->pend_es_listnode);
+}
+
+/* Number of active VTEPs associated with the ES-per-EVI */
+static uint32_t bgp_evpn_es_evi_get_active_vtep_cnt(
+ struct bgp_evpn_es_evi *es_evi)
+{
+ struct bgp_evpn_es_evi_vtep *evi_vtep;
+ struct listnode *node;
+ uint32_t vtep_cnt = 0;
+
+ for (ALL_LIST_ELEMENTS_RO(es_evi->es_evi_vtep_list, node, evi_vtep)) {
+ if (CHECK_FLAG(evi_vtep->flags, BGP_EVPN_EVI_VTEP_ACTIVE))
+ ++vtep_cnt;
+ }
+
+ return vtep_cnt;
+}
+
+/* Number of active VTEPs associated with the ES */
+static uint32_t bgp_evpn_es_get_active_vtep_cnt(struct bgp_evpn_es *es)
+{
+ struct listnode *node;
+ uint32_t vtep_cnt = 0;
+ struct bgp_evpn_es_vtep *es_vtep;
+
+ for (ALL_LIST_ELEMENTS_RO(es->es_vtep_list, node, es_vtep)) {
+ if (CHECK_FLAG(es_vtep->flags, BGP_EVPNES_VTEP_ACTIVE))
+ ++vtep_cnt;
+ }
+
+ return vtep_cnt;
+}
+
+static struct bgp_evpn_es_vtep *bgp_evpn_es_get_next_active_vtep(
+ struct bgp_evpn_es *es, struct bgp_evpn_es_vtep *es_vtep)
+{
+ struct listnode *node;
+ struct bgp_evpn_es_vtep *next_es_vtep;
+
+ if (es_vtep)
+ node = listnextnode_unchecked(&es_vtep->es_listnode);
+ else
+ node = listhead(es->es_vtep_list);
+
+ for (; node; node = listnextnode_unchecked(node)) {
+ next_es_vtep = listgetdata(node);
+ if (CHECK_FLAG(next_es_vtep->flags, BGP_EVPNES_VTEP_ACTIVE))
+ return next_es_vtep;
+ }
+
+ return NULL;
+}
+
+static struct bgp_evpn_es_evi_vtep *bgp_evpn_es_evi_get_next_active_vtep(
+ struct bgp_evpn_es_evi *es_evi,
+ struct bgp_evpn_es_evi_vtep *evi_vtep)
+{
+ struct listnode *node;
+ struct bgp_evpn_es_evi_vtep *next_evi_vtep;
+
+ if (evi_vtep)
+ node = listnextnode_unchecked(&evi_vtep->es_evi_listnode);
+ else
+ node = listhead(es_evi->es_evi_vtep_list);
+
+ for (; node; node = listnextnode_unchecked(node)) {
+ next_evi_vtep = listgetdata(node);
+ if (CHECK_FLAG(next_evi_vtep->flags, BGP_EVPN_EVI_VTEP_ACTIVE))
+ return next_evi_vtep;
+ }
+
+ return NULL;
+}
+
+static void bgp_evpn_es_evi_set_inconsistent(struct bgp_evpn_es_evi *es_evi)
+{
+ if (!CHECK_FLAG(es_evi->flags, BGP_EVPNES_EVI_INCONS_VTEP_LIST)) {
+ if (BGP_DEBUG(evpn_mh, EVPN_MH_ES))
+ zlog_debug("inconsistency detected - es %s evi %u vtep list mismatch",
+ es_evi->es->esi_str,
+ es_evi->vpn->vni);
+ SET_FLAG(es_evi->flags, BGP_EVPNES_EVI_INCONS_VTEP_LIST);
+
+ /* update parent ES with the incosistency setting */
+ if (!es_evi->es->incons_evi_vtep_cnt &&
+ BGP_DEBUG(evpn_mh, EVPN_MH_ES))
+ zlog_debug("inconsistency detected - es %s vtep list mismatch",
+ es_evi->es->esi_str);
+ ++es_evi->es->incons_evi_vtep_cnt;
+ SET_FLAG(es_evi->es->inconsistencies,
+ BGP_EVPNES_INCONS_VTEP_LIST);
+ }
+}
+
+static uint32_t bgp_evpn_es_run_consistency_checks(struct bgp_evpn_es *es)
+{
+ int proc_cnt = 0;
+ int es_active_vtep_cnt;
+ int evi_active_vtep_cnt;
+ struct bgp_evpn_es_evi *es_evi;
+ struct listnode *evi_node;
+ struct bgp_evpn_es_vtep *es_vtep;
+ struct bgp_evpn_es_evi_vtep *evi_vtep;
+
+ /* reset the inconsistencies and re-evaluate */
+ es->incons_evi_vtep_cnt = 0;
+ es->inconsistencies = 0;
+
+ es_active_vtep_cnt = bgp_evpn_es_get_active_vtep_cnt(es);
+ for (ALL_LIST_ELEMENTS_RO(es->es_evi_list,
+ evi_node, es_evi)) {
+ ++proc_cnt;
+
+ /* reset the inconsistencies on the EVI and re-evaluate*/
+ UNSET_FLAG(es_evi->flags, BGP_EVPNES_EVI_INCONS_VTEP_LIST);
+
+ evi_active_vtep_cnt =
+ bgp_evpn_es_evi_get_active_vtep_cnt(es_evi);
+ if (es_active_vtep_cnt != evi_active_vtep_cnt) {
+ bgp_evpn_es_evi_set_inconsistent(es_evi);
+ continue;
+ }
+
+ if (!es_active_vtep_cnt)
+ continue;
+
+ es_vtep = NULL;
+ evi_vtep = NULL;
+ while ((es_vtep = bgp_evpn_es_get_next_active_vtep(
+ es, es_vtep))) {
+ evi_vtep = bgp_evpn_es_evi_get_next_active_vtep(es_evi,
+ evi_vtep);
+ if (!evi_vtep) {
+ bgp_evpn_es_evi_set_inconsistent(es_evi);
+ break;
+ }
+ if (es_vtep->vtep_ip.s_addr !=
+ evi_vtep->vtep_ip.s_addr) {
+ /* inconsistency detected; set it and move
+ * to the next evi
+ */
+ bgp_evpn_es_evi_set_inconsistent(es_evi);
+ break;
+ }
+ }
+ }
+
+ return proc_cnt;
+}
+
+static int bgp_evpn_run_consistency_checks(struct thread *t)
+{
+ int proc_cnt = 0;
+ int es_cnt = 0;
+ struct listnode *node;
+ struct listnode *nextnode;
+ struct bgp_evpn_es *es;
+
+ for (ALL_LIST_ELEMENTS(bgp_mh_info->pend_es_list,
+ node, nextnode, es)) {
+ ++es_cnt;
+ ++proc_cnt;
+ /* run consistency checks on the ES and remove it from the
+ * pending list
+ */
+ proc_cnt += bgp_evpn_es_run_consistency_checks(es);
+ bgp_evpn_es_cons_checks_pend_del(es);
+ if (proc_cnt > 500)
+ break;
+ }
+
+ /* restart the timer */
+ thread_add_timer(bm->master, bgp_evpn_run_consistency_checks, NULL,
+ BGP_EVPN_CONS_CHECK_INTERVAL,
+ &bgp_mh_info->t_cons_check);
+
+ return 0;
+}
+
+/*****************************************************************************/
+void bgp_evpn_mh_init(void)
+{
+ bm->mh_info = XCALLOC(MTYPE_BGP_EVPN_MH_INFO, sizeof(*bm->mh_info));
+
+ /* setup ES tables */
+ RB_INIT(bgp_es_rb_head, &bgp_mh_info->es_rb_tree);
+ /* local ES list */
+ bgp_mh_info->local_es_list = list_new();
+ listset_app_node_mem(bgp_mh_info->local_es_list);
+ /* list of ESs with pending processing */
+ bgp_mh_info->pend_es_list = list_new();
+ listset_app_node_mem(bgp_mh_info->pend_es_list);
+
+ /* config knobs - XXX add cli to control it */
+ bgp_mh_info->ead_evi_adv_for_down_links = true;
+ bgp_mh_info->consistency_checking = true;
+
+ if (bgp_mh_info->consistency_checking)
+ thread_add_timer(bm->master, bgp_evpn_run_consistency_checks,
+ NULL, BGP_EVPN_CONS_CHECK_INTERVAL,
+ &bgp_mh_info->t_cons_check);
+
+ memset(&zero_esi_buf, 0, sizeof(esi_t));
+}
+
+void bgp_evpn_mh_finish(void)
+{
+ struct bgp_evpn_es *es;
+ struct bgp_evpn_es *es_next;
+ struct bgp *bgp;
+
+ bgp = bgp_get_evpn();
+ if (bgp) {
+ RB_FOREACH_SAFE(es, bgp_es_rb_head,
+ &bgp_mh_info->es_rb_tree, es_next) {
+ /* XXX - need to force free remote ESs here */
+ bgp_evpn_local_es_do_del(bgp, es);
+ }
+ }
+ thread_cancel(bgp_mh_info->t_cons_check);
+ list_delete(&bgp_mh_info->local_es_list);
+ list_delete(&bgp_mh_info->pend_es_list);
+
+ XFREE(MTYPE_BGP_EVPN_MH_INFO, bgp_mh_info);
+}
diff --git a/bgpd/bgp_evpn_mh.h b/bgpd/bgp_evpn_mh.h
new file mode 100644
index 0000000000..93355d495a
--- /dev/null
+++ b/bgpd/bgp_evpn_mh.h
@@ -0,0 +1,299 @@
+/* EVPN header for multihoming procedures
+ *
+ * Copyright (C) 2019 Cumulus Networks
+ * Anuradha Karuppiah
+ *
+ * This file is part of FRRouting.
+ *
+ * FRRouting is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2, or (at your option) any
+ * later version.
+ *
+ * FRRouting is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ */
+
+#ifndef _FRR_BGP_EVPN_MH_H
+#define _FRR_BGP_EVPN_MH_H
+
+#include "vxlan.h"
+#include "bgpd.h"
+#include "bgp_evpn.h"
+#include "bgp_evpn_private.h"
+
+#define BGP_EVPN_AD_ES_ETH_TAG 0xffffffff
+#define BGP_EVPN_AD_EVI_ETH_TAG 0
+
+#define BGP_EVPNES_INCONS_STR_SZ 80
+#define BGP_EVPN_FLAG_STR_SZ 5
+#define BGP_EVPN_VTEPS_FLAG_STR_SZ (BGP_EVPN_FLAG_STR_SZ * ES_VTEP_MAX_CNT)
+
+#define BGP_EVPN_CONS_CHECK_INTERVAL 60
+
+
+/* Ethernet Segment entry -
+ * - Local and remote ESs are maintained in a global RB tree,
+ * bgp_mh_info->es_rb_tree using ESI as key
+ * - Local ESs are received from zebra (BGP_EVPNES_LOCAL)
+ * - Remotes ESs are implicitly created (by reference) by a remote ES-EVI
+ * (BGP_EVPNES_REMOTE)
+ * - An ES can be simulatenously LOCAL and REMOTE; infact all LOCAL ESs are
+ * expected to have REMOTE ES peers.
+ */
+struct bgp_evpn_es {
+ /* Ethernet Segment Identifier */
+ esi_t esi;
+ char esi_str[ESI_STR_LEN];
+
+ /* es flags */
+ uint32_t flags;
+ /* created via zebra config */
+#define BGP_EVPNES_LOCAL (1 << 0)
+ /* created implicitly by a remote ES-EVI reference */
+#define BGP_EVPNES_REMOTE (1 << 1)
+ /* local ES link is oper-up */
+#define BGP_EVPNES_OPER_UP (1 << 2)
+ /* enable generation of EAD-EVI routes */
+#define BGP_EVPNES_ADV_EVI (1 << 3)
+ /* consistency checks pending */
+#define BGP_EVPNES_CONS_CHECK_PEND (1 << 4)
+
+ /* memory used for adding the es to bgp->es_rb_tree */
+ RB_ENTRY(bgp_evpn_es) rb_node;
+
+ /* [EVPNES_LOCAL] memory used for linking the es to
+ * bgp_mh_info->local_es_list
+ */
+ struct listnode es_listnode;
+
+ /* memory used for linking the es to "processing" pending list
+ * bgp_mh_info->pend_es_list
+ */
+ struct listnode pend_es_listnode;
+
+ /* [EVPNES_LOCAL] Id for deriving the RD automatically for this ESI */
+ uint16_t rd_id;
+
+ /* [EVPNES_LOCAL] RD for this ES */
+ struct prefix_rd prd;
+
+ /* [EVPNES_LOCAL] originator ip address */
+ struct in_addr originator_ip;
+
+ /* [EVPNES_LOCAL] Route table for EVPN routes for this ESI-
+ * - Type-4 local and remote routes
+ * - Type-1 local routes
+ */
+ struct bgp_table *route_table;
+
+ /* list of PEs (bgp_evpn_es_vtep) attached to the ES */
+ struct list *es_vtep_list;
+
+ /* List of ES-EVIs associated with this ES */
+ struct list *es_evi_list;
+
+ /* Number of remote VNIs referencing this ES */
+ uint32_t remote_es_evi_cnt;
+
+ uint32_t inconsistencies;
+ /* there are one or more EVIs whose VTEP list doesn't match
+ * with the ES's VTEP list
+ */
+#define BGP_EVPNES_INCONS_VTEP_LIST (1 << 0)
+
+ /* number of es-evi entries whose VTEP list doesn't match
+ * with the ES's
+ */
+ uint32_t incons_evi_vtep_cnt;
+
+ QOBJ_FIELDS
+};
+DECLARE_QOBJ_TYPE(bgp_evpn_es)
+RB_HEAD(bgp_es_rb_head, bgp_evpn_es);
+RB_PROTOTYPE(bgp_es_rb_head, bgp_evpn_es, rb_node, bgp_es_rb_cmp);
+
+/* PE attached to an ES */
+struct bgp_evpn_es_vtep {
+ struct bgp_evpn_es *es; /* parent ES */
+ struct in_addr vtep_ip;
+
+ uint32_t flags;
+ /* Rxed a Type4 route from this PE */
+#define BGP_EVPNES_VTEP_ESR (1 << 0)
+ /* Active (rxed EAD-ES and EAD-EVI) and can be included as
+ * a nexthop
+ */
+#define BGP_EVPNES_VTEP_ACTIVE (1 << 1)
+
+ uint32_t evi_cnt; /* es_evis referencing this vtep as an active path */
+
+ /* memory used for adding the entry to es->es_vtep_list */
+ struct listnode es_listnode;
+};
+
+/* ES per-EVI info
+ * - ES-EVIs are maintained per-L2-VNI (vpn->es_evi_rb_tree)
+ * - ES-EVIs are also linked to the parent ES (es->es_evi_list)
+ * - Local ES-EVIs are created by zebra (via config). They are linked to a
+ * per-VNI list (vpn->local_es_evi_list) for quick access
+ * - Remote ES-EVIs are created implicitly when a bgp_evpn_es_evi_vtep
+ * references it.
+ */
+struct bgp_evpn_es_evi {
+ struct bgp_evpn_es *es;
+ struct bgpevpn *vpn;
+
+ /* ES-EVI flags */
+ uint32_t flags;
+/* local ES-EVI, created by zebra */
+#define BGP_EVPNES_EVI_LOCAL (1 << 0)
+/* created via a remote VTEP imported by BGP */
+#define BGP_EVPNES_EVI_REMOTE (1 << 1)
+#define BGP_EVPNES_EVI_INCONS_VTEP_LIST (1 << 2)
+
+ /* memory used for adding the es_evi to es_evi->vpn->es_evi_rb_tree */
+ RB_ENTRY(bgp_evpn_es_evi) rb_node;
+ /* memory used for linking the es_evi to
+ * es_evi->vpn->local_es_evi_list
+ */
+ struct listnode l2vni_listnode;
+ /* memory used for linking the es_evi to
+ * es_evi->es->es_evi_list
+ */
+ struct listnode es_listnode;
+
+ /* list of PEs (bgp_evpn_es_evi_vtep) attached to the ES for this VNI */
+ struct list *es_evi_vtep_list;
+};
+
+/* PE attached to an ES for a VNI. This entry is created when an EAD-per-ES
+ * or EAD-per-EVI Type1 route is imported into the VNI.
+ */
+struct bgp_evpn_es_evi_vtep {
+ struct bgp_evpn_es_evi *es_evi; /* parent ES-EVI */
+ struct in_addr vtep_ip;
+
+ uint32_t flags;
+ /* Rxed an EAD-per-ES route from the PE */
+#define BGP_EVPN_EVI_VTEP_EAD_PER_ES (1 << 0) /* rxed EAD-per-ES */
+ /* Rxed an EAD-per-EVI route from the PE */
+#define BGP_EVPN_EVI_VTEP_EAD_PER_EVI (1 << 1) /* rxed EAD-per-EVI */
+ /* VTEP is active i.e. will result in the creation of an es-vtep */
+#define BGP_EVPN_EVI_VTEP_ACTIVE (1 << 2)
+#define BGP_EVPN_EVI_VTEP_EAD (BGP_EVPN_EVI_VTEP_EAD_PER_ES |\
+ BGP_EVPN_EVI_VTEP_EAD_PER_EVI)
+
+ /* memory used for adding the entry to es_evi->es_evi_vtep_list */
+ struct listnode es_evi_listnode;
+ struct bgp_evpn_es_vtep *es_vtep;
+};
+
+/* multihoming information stored in bgp_master */
+#define bgp_mh_info (bm->mh_info)
+struct bgp_evpn_mh_info {
+ /* RB tree of Ethernet segments (used for EVPN-MH) */
+ struct bgp_es_rb_head es_rb_tree;
+ /* List of local ESs */
+ struct list *local_es_list;
+ /* List of ESs with pending/periodic processing */
+ struct list *pend_es_list;
+ /* periodic timer for running background consistency checks */
+ struct thread *t_cons_check;
+
+ /* config knobs for optimizing or interop */
+ /* Generate EAD-EVI routes even if the ES is oper-down. This can be
+ * enabled as an optimization to avoid a storm of updates when an ES
+ * link flaps.
+ */
+ bool ead_evi_adv_for_down_links;
+ /* Enable ES consistency checking */
+ bool consistency_checking;
+};
+
+/****************************************************************************/
+static inline int bgp_evpn_is_es_local(struct bgp_evpn_es *es)
+{
+ return CHECK_FLAG(es->flags, BGP_EVPNES_LOCAL) ? 1 : 0;
+}
+
+extern esi_t *zero_esi;
+static inline bool bgp_evpn_is_esi_valid(esi_t *esi)
+{
+ return !!memcmp(esi, zero_esi, sizeof(esi_t));
+}
+
+static inline esi_t *bgp_evpn_attr_get_esi(struct attr *attr)
+{
+ return attr ? &attr->esi : zero_esi;
+}
+
+static inline bool bgp_evpn_attr_is_sync(struct attr *attr)
+{
+ return attr ? !!(attr->es_flags &
+ (ATTR_ES_PEER_PROXY | ATTR_ES_PEER_ACTIVE)) : false;
+}
+
+static inline uint32_t bgp_evpn_attr_get_sync_seq(struct attr *attr)
+{
+ return attr ? attr->mm_sync_seqnum : 0;
+}
+
+static inline bool bgp_evpn_attr_is_active_on_peer(struct attr *attr)
+{
+ return attr ?
+ !!(attr->es_flags & ATTR_ES_PEER_ACTIVE) : false;
+}
+
+static inline bool bgp_evpn_attr_is_router_on_peer(struct attr *attr)
+{
+ return attr ?
+ !!(attr->es_flags & ATTR_ES_PEER_ROUTER) : false;
+}
+
+static inline bool bgp_evpn_attr_is_proxy(struct attr *attr)
+{
+ return attr ? !!(attr->es_flags & ATTR_ES_PROXY_ADVERT) : false;
+}
+
+static inline bool bgp_evpn_attr_is_local_es(struct attr *attr)
+{
+ return attr ? !!(attr->es_flags & ATTR_ES_IS_LOCAL) : false;
+}
+
+/****************************************************************************/
+extern int bgp_evpn_es_route_install_uninstall(struct bgp *bgp,
+ struct bgp_evpn_es *es, afi_t afi, safi_t safi,
+ struct prefix_evpn *evp, struct bgp_path_info *pi,
+ int install);
+int bgp_evpn_type1_route_process(struct peer *peer, afi_t afi, safi_t safi,
+ struct attr *attr, uint8_t *pfx, int psize,
+ uint32_t addpath_id);
+int bgp_evpn_type4_route_process(struct peer *peer, afi_t afi, safi_t safi,
+ struct attr *attr, uint8_t *pfx, int psize,
+ uint32_t addpath_id);
+extern int bgp_evpn_local_es_add(struct bgp *bgp, esi_t *esi,
+ struct in_addr originator_ip, bool oper_up);
+extern int bgp_evpn_local_es_del(struct bgp *bgp, esi_t *esi);
+extern int bgp_evpn_local_es_evi_add(struct bgp *bgp, esi_t *esi, vni_t vni);
+extern int bgp_evpn_local_es_evi_del(struct bgp *bgp, esi_t *esi, vni_t vni);
+extern int bgp_evpn_remote_es_evi_add(struct bgp *bgp, struct bgpevpn *vpn,
+ const struct prefix_evpn *p);
+extern int bgp_evpn_remote_es_evi_del(struct bgp *bgp, struct bgpevpn *vpn,
+ const struct prefix_evpn *p);
+extern void bgp_evpn_mh_init(void);
+extern void bgp_evpn_mh_finish(void);
+void bgp_evpn_vni_es_init(struct bgpevpn *vpn);
+void bgp_evpn_vni_es_cleanup(struct bgpevpn *vpn);
+void bgp_evpn_es_show_esi(struct vty *vty, esi_t *esi, bool uj);
+void bgp_evpn_es_show(struct vty *vty, bool uj, bool detail);
+void bgp_evpn_es_evi_show_vni(struct vty *vty, vni_t vni,
+ bool uj, bool detail);
+void bgp_evpn_es_evi_show(struct vty *vty, bool uj, bool detail);
+struct bgp_evpn_es *bgp_evpn_es_find(const esi_t *esi);
+extern bool bgp_evpn_is_esi_local(esi_t *esi);
+
+#endif /* _FRR_BGP_EVPN_MH_H */
diff --git a/bgpd/bgp_evpn_private.h b/bgpd/bgp_evpn_private.h
index c7ccf69f05..ca45b198a7 100644
--- a/bgpd/bgp_evpn_private.h
+++ b/bgpd/bgp_evpn_private.h
@@ -34,15 +34,23 @@
* in bits */
#define EVPN_ROUTE_PREFIXLEN (sizeof(struct evpn_addr) * 8)
-/* EVPN route types. */
-typedef enum {
- BGP_EVPN_AD_ROUTE = 1, /* Ethernet Auto-Discovery (A-D) route */
- BGP_EVPN_MAC_IP_ROUTE, /* MAC/IP Advertisement route */
- BGP_EVPN_IMET_ROUTE, /* Inclusive Multicast Ethernet Tag route */
- BGP_EVPN_ES_ROUTE, /* Ethernet Segment route */
- BGP_EVPN_IP_PREFIX_ROUTE, /* IP Prefix route */
-} bgp_evpn_route_type;
+/* EVPN route RD buffer length */
+#define BGP_EVPN_PREFIX_RD_LEN 100
+/* packet sizes for EVPN routes */
+/* Type-1 route should be 25 bytes
+ * RD (8), ESI (10), eth-tag (4), vni (3)
+ */
+#define BGP_EVPN_TYPE1_PSIZE 25
+/* Type-4 route should be either 23 or 35 bytes
+ * RD (8), ESI (10), ip-len (1), ip (4 or 16)
+ */
+#define BGP_EVPN_TYPE4_V4_PSIZE 23
+#define BGP_EVPN_TYPE4_V6_PSIZE 34
+
+RB_HEAD(bgp_es_evi_rb_head, bgp_evpn_es_evi);
+RB_PROTOTYPE(bgp_es_evi_rb_head, bgp_evpn_es_evi, rb_node,
+ bgp_es_evi_rb_cmp);
/*
* Hash table of EVIs. Right now, the only type of EVI supported is with
* VxLAN encapsulation, hence each EVI corresponds to a L2 VNI.
@@ -98,46 +106,16 @@ struct bgpevpn {
* this VNI. */
struct bgp_table *route_table;
- QOBJ_FIELDS
-};
-
-DECLARE_QOBJ_TYPE(bgpevpn)
+ /* RB tree of ES-EVIs */
+ struct bgp_es_evi_rb_head es_evi_rb_tree;
-struct evpnes {
-
- /* Ethernet Segment Identifier */
- esi_t esi;
-
- /* es flags */
- uint16_t flags;
-#define EVPNES_LOCAL 0x01
-#define EVPNES_REMOTE 0x02
-
- /*
- * Id for deriving the RD
- * automatically for this ESI
- */
- uint16_t rd_id;
-
- /* RD for this VNI. */
- struct prefix_rd prd;
-
- /* originator ip address */
- struct ipaddr originator_ip;
-
- /* list of VTEPs in the same site */
- struct list *vtep_list;
-
- /*
- * Route table for EVPN routes for
- * this ESI. - type4 routes
- */
- struct bgp_table *route_table;
+ /* List of local ESs */
+ struct list *local_es_evi_list;
QOBJ_FIELDS
};
-DECLARE_QOBJ_TYPE(evpnes)
+DECLARE_QOBJ_TYPE(bgpevpn)
/* Mapping of Import RT to VNIs.
* The Import RTs of all VNIs are maintained in a hash table with each
@@ -330,6 +308,16 @@ static inline void encode_es_rt_extcomm(struct ecommunity_val *eval,
memcpy(&eval->val[2], mac, ETH_ALEN);
}
+static inline void encode_esi_label_extcomm(struct ecommunity_val *eval,
+ bool single_active)
+{
+ memset(eval, 0, sizeof(struct ecommunity_val));
+ eval->val[0] = ECOMMUNITY_ENCODE_EVPN;
+ eval->val[1] = ECOMMUNITY_EVPN_SUBTYPE_ESI_LABEL;
+ if (single_active)
+ eval->val[2] |= (1 << 0);
+}
+
static inline void encode_rmac_extcomm(struct ecommunity_val *eval,
struct ethaddr *rmac)
{
@@ -361,13 +349,15 @@ static inline void encode_mac_mobility_extcomm(int static_mac, uint32_t seq,
}
static inline void encode_na_flag_extcomm(struct ecommunity_val *eval,
- uint8_t na_flag)
+ uint8_t na_flag, bool proxy)
{
memset(eval, 0, sizeof(*eval));
eval->val[0] = ECOMMUNITY_ENCODE_EVPN;
eval->val[1] = ECOMMUNITY_EVPN_SUBTYPE_ND;
if (na_flag)
eval->val[2] |= ECOMMUNITY_EVPN_SUBTYPE_ND_ROUTER_FLAG;
+ if (proxy)
+ eval->val[2] |= ECOMMUNITY_EVPN_SUBTYPE_PROXY_FLAG;
}
static inline void ip_prefix_from_type5_prefix(const struct prefix_evpn *evp,
@@ -487,6 +477,44 @@ static inline void build_evpn_type4_prefix(struct prefix_evpn *p,
memcpy(&p->prefix.es_addr.esi, esi, sizeof(esi_t));
}
+static inline void build_evpn_type1_prefix(struct prefix_evpn *p,
+ uint32_t eth_tag,
+ esi_t *esi,
+ struct in_addr originator_ip)
+{
+ memset(p, 0, sizeof(struct prefix_evpn));
+ p->family = AF_EVPN;
+ p->prefixlen = EVPN_ROUTE_PREFIXLEN;
+ p->prefix.route_type = BGP_EVPN_AD_ROUTE;
+ p->prefix.ead_addr.eth_tag = eth_tag;
+ p->prefix.ead_addr.ip.ipa_type = IPADDR_V4;
+ p->prefix.ead_addr.ip.ipaddr_v4 = originator_ip;
+ memcpy(&p->prefix.ead_addr.esi, esi, sizeof(esi_t));
+}
+
+static inline void evpn_type1_prefix_global_copy(struct prefix_evpn *global_p,
+ const struct prefix_evpn *vni_p)
+{
+ memcpy(global_p, vni_p, sizeof(*global_p));
+ global_p->prefix.ead_addr.ip.ipa_type = 0;
+ global_p->prefix.ead_addr.ip.ipaddr_v4.s_addr = 0;
+}
+
+/* EAD prefix in the global table doesn't include the VTEP-IP so
+ * we need to create a different copy for the VNI
+ */
+static inline struct prefix_evpn *evpn_type1_prefix_vni_copy(
+ struct prefix_evpn *vni_p,
+ const struct prefix_evpn *global_p,
+ struct in_addr originator_ip)
+{
+ memcpy(vni_p, global_p, sizeof(*vni_p));
+ vni_p->prefix.ead_addr.ip.ipa_type = IPADDR_V4;
+ vni_p->prefix.ead_addr.ip.ipaddr_v4 = originator_ip;
+
+ return vni_p;
+}
+
static inline int evpn_default_originate_set(struct bgp *bgp, afi_t afi,
safi_t safi)
{
@@ -511,11 +539,6 @@ static inline void es_get_system_mac(esi_t *esi,
memcpy(mac, &esi->val[1], ETH_ALEN);
}
-static inline int is_es_local(struct evpnes *es)
-{
- return CHECK_FLAG(es->flags, EVPNES_LOCAL) ? 1 : 0;
-}
-
static inline bool bgp_evpn_is_svi_macip_enabled(struct bgpevpn *vpn)
{
struct bgp *bgp_evpn = NULL;
@@ -526,6 +549,16 @@ static inline bool bgp_evpn_is_svi_macip_enabled(struct bgpevpn *vpn)
vpn->advertise_svi_macip);
}
+static inline bool bgp_evpn_is_path_local(struct bgp *bgp,
+ struct bgp_path_info *pi)
+{
+ return (pi->peer == bgp->peer_self
+ && pi->type == ZEBRA_ROUTE_BGP
+ && pi->sub_type == BGP_ROUTE_STATIC);
+}
+
+extern struct zclient *zclient;
+
extern void bgp_evpn_install_uninstall_default_route(struct bgp *bgp_vrf,
afi_t afi, safi_t safi,
bool add);
@@ -563,10 +596,18 @@ extern struct bgpevpn *bgp_evpn_new(struct bgp *bgp, vni_t vni,
vrf_id_t tenant_vrf_id,
struct in_addr mcast_grp);
extern void bgp_evpn_free(struct bgp *bgp, struct bgpevpn *vpn);
-extern struct evpnes *bgp_evpn_lookup_es(struct bgp *bgp, esi_t *esi);
-extern struct evpnes *bgp_evpn_es_new(struct bgp *bgp, esi_t *esi,
- struct ipaddr *originator_ip);
-extern void bgp_evpn_es_free(struct bgp *bgp, struct evpnes *es);
extern bool bgp_evpn_lookup_l3vni_l2vni_table(vni_t vni);
extern int update_routes_for_vni(struct bgp *bgp, struct bgpevpn *vpn);
+extern void delete_evpn_route_entry(struct bgp *bgp, afi_t afi, safi_t safi,
+ struct bgp_dest *dest,
+ struct bgp_path_info **pi);
+int vni_list_cmp(void *p1, void *p2);
+extern int evpn_route_select_install(struct bgp *bgp, struct bgpevpn *vpn,
+ struct bgp_node *rn);
+extern struct bgp_node *bgp_global_evpn_node_get(
+ struct bgp_table *table, afi_t afi, safi_t safi,
+ const struct prefix_evpn *evp, struct prefix_rd *prd);
+extern struct bgp_node *bgp_global_evpn_node_lookup(
+ struct bgp_table *table, afi_t afi, safi_t safi,
+ const struct prefix_evpn *evp, struct prefix_rd *prd);
#endif /* _BGP_EVPN_PRIVATE_H */
diff --git a/bgpd/bgp_evpn_vty.c b/bgpd/bgp_evpn_vty.c
index 95e24eae12..15ecffdc72 100644
--- a/bgpd/bgp_evpn_vty.c
+++ b/bgpd/bgp_evpn_vty.c
@@ -33,6 +33,7 @@
#include "bgpd/bgp_evpn_vty.h"
#include "bgpd/bgp_evpn.h"
#include "bgpd/bgp_evpn_private.h"
+#include "bgpd/bgp_evpn_mh.h"
#include "bgpd/bgp_zebra.h"
#include "bgpd/bgp_vty.h"
#include "bgpd/bgp_errors.h"
@@ -348,6 +349,8 @@ static void bgp_evpn_show_route_header(struct vty *vty, struct bgp *bgp,
"Status codes: s suppressed, d damped, h history, * valid, > best, i - internal\n");
vty_out(vty, "Origin codes: i - IGP, e - EGP, ? - incomplete\n");
vty_out(vty,
+ "EVPN type-1 prefix: [1]:[ESI]:[EthTag]:[IPlen]:[VTEP-IP]\n");
+ vty_out(vty,
"EVPN type-2 prefix: [2]:[EthTag]:[MAClen]:[MAC]:[IPlen]:[IP]\n");
vty_out(vty, "EVPN type-3 prefix: [3]:[EthTag]:[IPlen]:[OrigIP]\n");
vty_out(vty, "EVPN type-4 prefix: [4]:[ESI]:[IPlen]:[OrigIP]\n");
@@ -461,47 +464,6 @@ static void display_l3vni(struct vty *vty, struct bgp *bgp_vrf,
json_object_object_add(json, "exportRts", json_export_rtl);
}
-static void display_es(struct vty *vty, struct evpnes *es, json_object *json)
-{
- struct in_addr *vtep;
- char buf[ESI_STR_LEN];
- char buf1[RD_ADDRSTRLEN];
- char buf2[INET6_ADDRSTRLEN];
- struct listnode *node = NULL;
- json_object *json_vteps = NULL;
-
- if (json) {
- json_vteps = json_object_new_array();
- json_object_string_add(json, "esi",
- esi_to_str(&es->esi, buf, sizeof(buf)));
- json_object_string_add(json, "rd",
- prefix_rd2str(&es->prd, buf1,
- sizeof(buf1)));
- json_object_string_add(
- json, "originatorIp",
- ipaddr2str(&es->originator_ip, buf2, sizeof(buf2)));
- if (es->vtep_list) {
- for (ALL_LIST_ELEMENTS_RO(es->vtep_list, node, vtep))
- json_object_array_add(
- json_vteps, json_object_new_string(
- inet_ntoa(*vtep)));
- }
- json_object_object_add(json, "vteps", json_vteps);
- } else {
- vty_out(vty, "ESI: %s\n",
- esi_to_str(&es->esi, buf, sizeof(buf)));
- vty_out(vty, " RD: %s\n", prefix_rd2str(&es->prd, buf1,
- sizeof(buf1)));
- vty_out(vty, " Originator-IP: %s\n",
- ipaddr2str(&es->originator_ip, buf2, sizeof(buf2)));
- if (es->vtep_list) {
- vty_out(vty, " VTEP List:\n");
- for (ALL_LIST_ELEMENTS_RO(es->vtep_list, node, vtep))
- vty_out(vty, " %s\n", inet_ntoa(*vtep));
- }
- }
-}
-
static void display_vni(struct vty *vty, struct bgpevpn *vpn, json_object *json)
{
char buf1[RD_ADDRSTRLEN];
@@ -628,7 +590,7 @@ static void display_vni(struct vty *vty, struct bgpevpn *vpn, json_object *json)
}
static void show_esi_routes(struct bgp *bgp,
- struct evpnes *es,
+ struct bgp_evpn_es *es,
struct vty *vty,
json_object *json)
{
@@ -679,7 +641,8 @@ static void show_esi_routes(struct bgp *bgp,
if (json)
json_path = json_object_new_array();
- route_vty_out(vty, p, pi, 0, SAFI_EVPN, json_path);
+ route_vty_out(vty, p, pi, 0, SAFI_EVPN, json_path,
+ false);
if (json)
json_object_array_add(json_paths, json_path);
@@ -788,7 +751,7 @@ static void show_vni_routes(struct bgp *bgp, struct bgpevpn *vpn, int type,
json_path);
else
route_vty_out(vty, p, pi, 0, SAFI_EVPN,
- json_path);
+ json_path, false);
if (json)
json_object_array_add(json_paths, json_path);
@@ -978,48 +941,6 @@ static void show_l3vni_entry(struct vty *vty, struct bgp *bgp,
}
}
-static void show_es_entry(struct hash_bucket *bucket, void *args[])
-{
- char buf[ESI_STR_LEN];
- char buf1[RD_ADDRSTRLEN];
- char buf2[INET6_ADDRSTRLEN];
- struct in_addr *vtep = NULL;
- struct vty *vty = args[0];
- json_object *json = args[1];
- json_object *json_vteps = NULL;
- struct listnode *node = NULL;
- struct evpnes *es = (struct evpnes *)bucket->data;
-
- if (json) {
- json_vteps = json_object_new_array();
- json_object_string_add(json, "esi",
- esi_to_str(&es->esi, buf, sizeof(buf)));
- json_object_string_add(json, "type",
- is_es_local(es) ? "Local" : "Remote");
- json_object_string_add(json, "rd",
- prefix_rd2str(&es->prd, buf1,
- sizeof(buf1)));
- json_object_string_add(
- json, "originatorIp",
- ipaddr2str(&es->originator_ip, buf2, sizeof(buf2)));
- if (es->vtep_list) {
- for (ALL_LIST_ELEMENTS_RO(es->vtep_list, node, vtep))
- json_object_array_add(json_vteps,
- json_object_new_string(
- inet_ntoa(*vtep)));
- }
- json_object_object_add(json, "vteps", json_vteps);
- } else {
- vty_out(vty, "%-30s %-6s %-21s %-15s %-6d\n",
- esi_to_str(&es->esi, buf, sizeof(buf)),
- is_es_local(es) ? "Local" : "Remote",
- prefix_rd2str(&es->prd, buf1, sizeof(buf1)),
- ipaddr2str(&es->originator_ip, buf2,
- sizeof(buf2)),
- es->vtep_list ? listcount(es->vtep_list) : 0);
- }
-}
-
static void show_vni_entry(struct hash_bucket *bucket, void *args[])
{
struct vty *vty;
@@ -1314,7 +1235,7 @@ static int bgp_show_ethernet_vpn(struct vty *vty, struct prefix_rd *prd,
route_vty_out(vty,
bgp_dest_get_prefix(rm),
pi, no_display, SAFI_EVPN,
- json_array);
+ json_array, false);
no_display = 1;
}
@@ -2453,10 +2374,10 @@ static void evpn_show_route_vni_macip(struct vty *vty, struct bgp *bgp,
static void evpn_show_routes_esi(struct vty *vty, struct bgp *bgp,
esi_t *esi, json_object *json)
{
- struct evpnes *es = NULL;
+ struct bgp_evpn_es *es = NULL;
/* locate the ES */
- es = bgp_evpn_lookup_es(bgp, esi);
+ es = bgp_evpn_es_find(esi);
if (!es) {
if (!json)
vty_out(vty, "ESI not found\n");
@@ -2813,7 +2734,7 @@ static void evpn_show_all_routes(struct vty *vty, struct bgp *bgp, int type,
SAFI_EVPN, json_path);
} else
route_vty_out(vty, p, pi, 0, SAFI_EVPN,
- json_path);
+ json_path, false);
if (json)
json_object_array_add(json_paths,
@@ -2862,43 +2783,6 @@ static void evpn_show_all_routes(struct vty *vty, struct bgp *bgp, int type,
}
}
-/* Display specific ES */
-static void evpn_show_es(struct vty *vty, struct bgp *bgp, esi_t *esi,
- json_object *json)
-{
- struct evpnes *es = NULL;
-
- es = bgp_evpn_lookup_es(bgp, esi);
- if (es) {
- display_es(vty, es, json);
- } else {
- if (json) {
- vty_out(vty, "{}\n");
- } else {
- vty_out(vty, "ESI not found\n");
- return;
- }
- }
-}
-
-/* Display all ESs */
-static void evpn_show_all_es(struct vty *vty, struct bgp *bgp,
- json_object *json)
-{
- void *args[2];
-
- if (!json)
- vty_out(vty, "%-30s %-6s %-21s %-15s %-6s\n",
- "ESI", "Type", "RD", "Originator-IP", "#VTEPs");
-
- /* print all ESs */
- args[0] = vty;
- args[1] = json;
- hash_iterate(bgp->esihash,
- (void (*)(struct hash_bucket *, void *))show_es_entry,
- args);
-}
-
/*
* Display specified VNI (vty handler)
*/
@@ -3898,6 +3782,12 @@ DEFPY (bgp_evpn_advertise_pip_ip_mac,
struct listnode *node = NULL;
struct bgpevpn *vpn = NULL;
+ /*
+ * At this point if bgp_evpn is NULL and evpn is enabled
+ * something stupid has gone wrong
+ */
+ assert(bgp_evpn);
+
update_advertise_vrf_routes(bgp_vrf);
/* Update (svi) type-2 routes */
@@ -4015,55 +3905,50 @@ DEFUN(show_bgp_l2vpn_evpn_vni,
return CMD_SUCCESS;
}
-/* Disaply ES */
-DEFUN(show_bgp_l2vpn_evpn_es,
+DEFPY(show_bgp_l2vpn_evpn_es_evi,
+ show_bgp_l2vpn_evpn_es_evi_cmd,
+ "show bgp l2vpn evpn es-evi [vni (1-16777215)$vni] [json$uj] [detail$detail]",
+ SHOW_STR
+ BGP_STR
+ L2VPN_HELP_STR
+ EVPN_HELP_STR
+ "ES per EVI\n"
+ "VxLAN Network Identifier\n"
+ "VNI\n"
+ JSON_STR
+ "Detailed information\n")
+{
+ if (vni)
+ bgp_evpn_es_evi_show_vni(vty, vni, !!uj, !!detail);
+ else
+ bgp_evpn_es_evi_show(vty, !!uj, !!detail);
+
+ return CMD_SUCCESS;
+}
+
+DEFPY(show_bgp_l2vpn_evpn_es,
show_bgp_l2vpn_evpn_es_cmd,
- "show bgp l2vpn evpn es [ESI] [json]",
+ "show bgp l2vpn evpn es [NAME$esi_str|detail$detail] [json$uj]",
SHOW_STR
BGP_STR
L2VPN_HELP_STR
EVPN_HELP_STR
- "ethernet-Segment\n"
- "Ethernet-Segment Identifier\n"
+ "Ethernet Segment\n"
+ "ES ID\n"
+ "Detailed information\n"
JSON_STR)
{
- int idx = 0;
- bool uj = false;
esi_t esi;
- json_object *json = NULL;
- struct bgp *bgp = NULL;
- memset(&esi, 0, sizeof(esi));
- uj = use_json(argc, argv);
-
- bgp = bgp_get_evpn();
- if (!bgp)
- return CMD_WARNING;
-
- if (!argv_find(argv, argc, "evpn", &idx))
- return CMD_WARNING;
-
- if ((uj && argc == ((idx + 1) + 2)) ||
- (!uj && argc == (idx + 1) + 1)) {
-
- /* show all ESs */
- evpn_show_all_es(vty, bgp, json);
- } else {
-
- /* show a specific ES */
-
- /* get the ESI - ESI-ID is at argv[5] */
- if (!str_to_esi(argv[idx + 2]->arg, &esi)) {
- vty_out(vty, "%% Malformed ESI\n");
+ if (esi_str) {
+ if (!str_to_esi(esi_str, &esi)) {
+ vty_out(vty, "%%Malformed ESI\n");
return CMD_WARNING;
}
- evpn_show_es(vty, bgp, &esi, json);
- }
+ bgp_evpn_es_show_esi(vty, &esi, uj);
+ } else {
- if (uj) {
- vty_out(vty, "%s\n", json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
+ bgp_evpn_es_show(vty, uj, !!detail);
}
return CMD_SUCCESS;
@@ -4108,7 +3993,7 @@ DEFUN(show_bgp_l2vpn_evpn_summary,
*/
DEFUN(show_bgp_l2vpn_evpn_route,
show_bgp_l2vpn_evpn_route_cmd,
- "show bgp l2vpn evpn route [detail] [type <macip|2|multicast|3|es|4|prefix|5>] [json]",
+ "show bgp l2vpn evpn route [detail] [type <ead|1|macip|2|multicast|3|es|4|prefix|5>] [json]",
SHOW_STR
BGP_STR
L2VPN_HELP_STR
@@ -4116,6 +4001,8 @@ DEFUN(show_bgp_l2vpn_evpn_route,
"EVPN route information\n"
"Display Detailed Information\n"
"Specify Route type\n"
+ "EAD (Type-1) route\n"
+ "EAD (Type-1) route\n"
"MAC-IP (Type-2) route\n"
"MAC-IP (Type-2) route\n"
"Multicast (Type-3) route\n"
@@ -4151,9 +4038,12 @@ DEFUN(show_bgp_l2vpn_evpn_route,
else if ((strncmp(argv[type_idx + 1]->arg, "mu", 2) == 0)
|| (strmatch(argv[type_idx + 1]->arg, "3")))
type = BGP_EVPN_IMET_ROUTE;
- else if ((strncmp(argv[type_idx + 1]->arg, "e", 1) == 0)
+ else if ((strncmp(argv[type_idx + 1]->arg, "es", 2) == 0)
|| (strmatch(argv[type_idx + 1]->arg, "4")))
type = BGP_EVPN_ES_ROUTE;
+ else if ((strncmp(argv[type_idx + 1]->arg, "ea", 2) == 0)
+ || (strmatch(argv[type_idx + 1]->arg, "1")))
+ type = BGP_EVPN_AD_ROUTE;
else if ((strncmp(argv[type_idx + 1]->arg, "p", 1) == 0)
|| (strmatch(argv[type_idx + 1]->arg, "5")))
type = BGP_EVPN_IP_PREFIX_ROUTE;
@@ -4179,7 +4069,7 @@ DEFUN(show_bgp_l2vpn_evpn_route,
*/
DEFUN(show_bgp_l2vpn_evpn_route_rd,
show_bgp_l2vpn_evpn_route_rd_cmd,
- "show bgp l2vpn evpn route rd ASN:NN_OR_IP-ADDRESS:NN [type <macip|multicast|es|prefix>] [json]",
+ "show bgp l2vpn evpn route rd ASN:NN_OR_IP-ADDRESS:NN [type <ead|macip|multicast|es|prefix>] [json]",
SHOW_STR
BGP_STR
L2VPN_HELP_STR
@@ -4188,6 +4078,7 @@ DEFUN(show_bgp_l2vpn_evpn_route_rd,
"Route Distinguisher\n"
"ASN:XX or A.B.C.D:XX\n"
"Specify Route type\n"
+ "EAD (Type-1) route\n"
"MAC-IP (Type-2) route\n"
"Multicast (Type-3) route\n"
"Ethernet Segment route\n"
@@ -4229,6 +4120,10 @@ DEFUN(show_bgp_l2vpn_evpn_route_rd,
type = BGP_EVPN_MAC_IP_ROUTE;
else if (strncmp(argv[type_idx + 1]->arg, "mu", 2) == 0)
type = BGP_EVPN_IMET_ROUTE;
+ else if (strncmp(argv[type_idx + 1]->arg, "es", 2) == 0)
+ type = BGP_EVPN_ES_ROUTE;
+ else if (strncmp(argv[type_idx + 1]->arg, "ea", 2) == 0)
+ type = BGP_EVPN_AD_ROUTE;
else if (strncmp(argv[type_idx + 1]->arg, "pr", 2) == 0)
type = BGP_EVPN_IP_PREFIX_ROUTE;
else
@@ -4373,7 +4268,7 @@ DEFUN(show_bgp_l2vpn_evpn_route_esi,
* Display per-VNI EVPN routing table.
*/
DEFUN(show_bgp_l2vpn_evpn_route_vni, show_bgp_l2vpn_evpn_route_vni_cmd,
- "show bgp l2vpn evpn route vni " CMD_VNI_RANGE " [<type <macip|multicast> | vtep A.B.C.D>] [json]",
+ "show bgp l2vpn evpn route vni " CMD_VNI_RANGE " [<type <ead|macip|multicast> | vtep A.B.C.D>] [json]",
SHOW_STR
BGP_STR
L2VPN_HELP_STR
@@ -4382,6 +4277,7 @@ DEFUN(show_bgp_l2vpn_evpn_route_vni, show_bgp_l2vpn_evpn_route_vni_cmd,
"VXLAN Network Identifier\n"
"VNI number\n"
"Specify Route type\n"
+ "EAD (Type-1) route\n"
"MAC-IP (Type-2) route\n"
"Multicast (Type-3) route\n"
"Remote VTEP\n"
@@ -4419,6 +4315,8 @@ DEFUN(show_bgp_l2vpn_evpn_route_vni, show_bgp_l2vpn_evpn_route_vni_cmd,
type = BGP_EVPN_MAC_IP_ROUTE;
else if (strncmp(argv[idx + 5]->arg, "mu", 2) == 0)
type = BGP_EVPN_IMET_ROUTE;
+ else if (strncmp(argv[idx + 5]->arg, "ea", 2) == 0)
+ type = BGP_EVPN_AD_ROUTE;
else
return CMD_WARNING;
} else if (strncmp(argv[idx + 4]->arg, "vtep", 4) == 0) {
@@ -4704,17 +4602,22 @@ DEFUN(show_bgp_l2vpn_evpn_import_rt,
return CMD_SUCCESS;
}
-DEFUN(test_adv_evpn_type4_route,
- test_adv_evpn_type4_route_cmd,
- "advertise es ESI",
- "Advertise EVPN ES route\n"
+DEFPY(test_es_add,
+ test_es_add_cmd,
+ "[no$no] test es NAME$esi_str [state NAME$state_str]",
+ NO_STR
+ "Test\n"
"Ethernet-segment\n"
- "Ethernet-Segment Identifier\n")
+ "Ethernet-Segment Identifier\n"
+ "ES link state\n"
+ "up|down\n"
+)
{
int ret = 0;
esi_t esi;
struct bgp *bgp;
- struct ipaddr vtep_ip;
+ struct in_addr vtep_ip;
+ bool oper_up;
bgp = bgp_get_evpn();
if (!bgp) {
@@ -4722,33 +4625,47 @@ DEFUN(test_adv_evpn_type4_route,
return CMD_WARNING;
}
- if (!str_to_esi(argv[2]->arg, &esi)) {
+ if (!str_to_esi(esi_str, &esi)) {
vty_out(vty, "%%Malformed ESI\n");
return CMD_WARNING;
}
- vtep_ip.ipa_type = IPADDR_V4;
- vtep_ip.ipaddr_v4 = bgp->router_id;
+ if (no) {
+ ret = bgp_evpn_local_es_del(bgp, &esi);
+ if (ret == -1) {
+ vty_out(vty, "%%Failed to delete ES\n");
+ return CMD_WARNING;
+ }
+ } else {
+ if (state_str && !strcmp(state_str, "up"))
+ oper_up = true;
+ else
+ oper_up = false;
+ vtep_ip = bgp->router_id;
- ret = bgp_evpn_local_es_add(bgp, &esi, &vtep_ip);
- if (ret == -1) {
- vty_out(vty, "%%Failed to EVPN advertise type-4 route\n");
- return CMD_WARNING;
+ ret = bgp_evpn_local_es_add(bgp, &esi, vtep_ip, oper_up);
+ if (ret == -1) {
+ vty_out(vty, "%%Failed to add ES\n");
+ return CMD_WARNING;
+ }
}
return CMD_SUCCESS;
}
-DEFUN(test_withdraw_evpn_type4_route,
- test_withdraw_evpn_type4_route_cmd,
- "withdraw es ESI",
- "Advertise EVPN ES route\n"
+DEFPY(test_es_vni_add,
+ test_es_vni_add_cmd,
+ "[no$no] test es NAME$esi_str vni (1-16777215)$vni",
+ NO_STR
+ "Test\n"
"Ethernet-segment\n"
- "Ethernet-Segment Identifier\n")
+ "Ethernet-Segment Identifier\n"
+ "VNI\n"
+ "1-16777215\n"
+)
{
int ret = 0;
esi_t esi;
struct bgp *bgp;
- struct ipaddr vtep_ip;
bgp = bgp_get_evpn();
if (!bgp) {
@@ -4756,22 +4673,23 @@ DEFUN(test_withdraw_evpn_type4_route,
return CMD_WARNING;
}
- if (!bgp->peer_self) {
- vty_out(vty, "%%BGP instance doesn't have self peer\n");
- return CMD_WARNING;
- }
-
- if (!str_to_esi(argv[2]->arg, &esi)) {
+ if (!str_to_esi(esi_str, &esi)) {
vty_out(vty, "%%Malformed ESI\n");
return CMD_WARNING;
}
- vtep_ip.ipa_type = IPADDR_V4;
- vtep_ip.ipaddr_v4 = bgp->router_id;
- ret = bgp_evpn_local_es_del(bgp, &esi, &vtep_ip);
- if (ret == -1) {
- vty_out(vty, "%%Failed to withdraw EVPN type-4 route\n");
- return CMD_WARNING;
+ if (no) {
+ ret = bgp_evpn_local_es_evi_del(bgp, &esi, vni);
+ if (ret == -1) {
+ vty_out(vty, "%%Failed to deref ES VNI\n");
+ return CMD_WARNING;
+ }
+ } else {
+ ret = bgp_evpn_local_es_evi_add(bgp, &esi, vni);
+ if (ret == -1) {
+ vty_out(vty, "%%Failed to ref ES VNI\n");
+ return CMD_WARNING;
+ }
}
return CMD_SUCCESS;
}
@@ -5829,11 +5747,12 @@ void bgp_ethernetvpn_init(void)
install_element(BGP_EVPN_NODE, &bgp_evpn_advertise_pip_ip_mac_cmd);
/* test commands */
- install_element(BGP_EVPN_NODE, &test_adv_evpn_type4_route_cmd);
- install_element(BGP_EVPN_NODE, &test_withdraw_evpn_type4_route_cmd);
+ install_element(BGP_EVPN_NODE, &test_es_add_cmd);
+ install_element(BGP_EVPN_NODE, &test_es_vni_add_cmd);
/* "show bgp l2vpn evpn" commands. */
install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_es_cmd);
+ install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_es_evi_cmd);
install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_vni_cmd);
install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_summary_cmd);
install_element(VIEW_NODE, &show_bgp_l2vpn_evpn_route_cmd);
diff --git a/bgpd/bgp_flowspec_vty.c b/bgpd/bgp_flowspec_vty.c
index 64a6c2ea8f..e309fa948e 100644
--- a/bgpd/bgp_flowspec_vty.c
+++ b/bgpd/bgp_flowspec_vty.c
@@ -376,11 +376,10 @@ void route_vty_out_flowspec(struct vty *vty, const struct prefix *p,
bpr->priority,
bpr->action->table_id);
}
- if (list_began)
- vty_out(vty, ")");
- vty_out(vty, "\n");
}
- if (!list_began)
+ if (list_began)
+ vty_out(vty, ")\n");
+ else
vty_out(vty, "\tnot installed in PBR\n");
}
}
diff --git a/bgpd/bgp_fsm.c b/bgpd/bgp_fsm.c
index e133cde6a5..ab3b88da7a 100644
--- a/bgpd/bgp_fsm.c
+++ b/bgpd/bgp_fsm.c
@@ -470,7 +470,6 @@ static int bgp_start_timer(struct thread *thread)
struct peer *peer;
peer = THREAD_ARG(thread);
- peer->t_start = NULL;
if (bgp_debug_neighbor_events(peer))
zlog_debug("%s [FSM] Timer (start timer expire).", peer->host);
@@ -492,8 +491,6 @@ static int bgp_connect_timer(struct thread *thread)
assert(!peer->t_write);
assert(!peer->t_read);
- peer->t_connect = NULL;
-
if (bgp_debug_neighbor_events(peer))
zlog_debug("%s [FSM] Timer (connect timer expire)", peer->host);
@@ -516,7 +513,6 @@ static int bgp_holdtime_timer(struct thread *thread)
struct peer *peer;
peer = THREAD_ARG(thread);
- peer->t_holdtime = NULL;
if (bgp_debug_neighbor_events(peer))
zlog_debug("%s [FSM] Timer (holdtime timer expire)",
@@ -552,7 +548,6 @@ int bgp_routeadv_timer(struct thread *thread)
struct peer *peer;
peer = THREAD_ARG(thread);
- peer->t_routeadv = NULL;
if (bgp_debug_neighbor_events(peer))
zlog_debug("%s [FSM] Timer (routeadv timer expire)",
@@ -612,7 +607,6 @@ static int bgp_graceful_restart_timer_expire(struct thread *thread)
safi_t safi;
peer = THREAD_ARG(thread);
- peer->t_gr_restart = NULL;
/* NSF delete stale route */
for (afi = AFI_IP; afi < AFI_MAX; afi++)
@@ -641,7 +635,6 @@ static int bgp_graceful_stale_timer_expire(struct thread *thread)
safi_t safi;
peer = THREAD_ARG(thread);
- peer->t_gr_stale = NULL;
if (bgp_debug_neighbor_events(peer))
zlog_debug("%s graceful restart stalepath timer expired",
@@ -674,8 +667,6 @@ static int bgp_graceful_deferral_timer_expire(struct thread *thread)
"afi %d, safi %d : graceful restart deferral timer expired",
afi, safi);
- bgp->gr_info[afi][safi].t_select_deferral = NULL;
-
bgp->gr_info[afi][safi].eor_required = 0;
bgp->gr_info[afi][safi].eor_received = 0;
XFREE(MTYPE_TMP, info);
diff --git a/bgpd/bgp_main.c b/bgpd/bgp_main.c
index 33eaf9ae74..b082aa9c6a 100644
--- a/bgpd/bgp_main.c
+++ b/bgpd/bgp_main.c
@@ -133,19 +133,20 @@ void sighup(void)
/*
* This is turned off for the moment. There is all
* sorts of config turned off by bgp_terminate
- * that is not setup properly again in bgp_rest.
+ * that is not setup properly again in bgp_reset.
* I see no easy way to do this nor do I see that
* this is a desirable way to reload config
* given the yang work.
*/
/* Terminate all thread. */
- bgp_terminate();
- bgp_reset();
- zlog_info("bgpd restarting!");
-
- /* Reload config file. */
- vty_read_config(NULL, bgpd_di.config_file, config_default);
+ /*
+ * bgp_terminate();
+ * bgp_reset();
+ * zlog_info("bgpd restarting!");
+ * Reload config file.
+ * vty_read_config(NULL, bgpd_di.config_file, config_default);
+ */
/* Try to return to normal operation. */
}
diff --git a/bgpd/bgp_memory.c b/bgpd/bgp_memory.c
index 41c4108c0a..8bdab16680 100644
--- a/bgpd/bgp_memory.c
+++ b/bgpd/bgp_memory.c
@@ -116,8 +116,11 @@ DEFINE_MTYPE(BGPD, LCOMMUNITY_STR, "Large Community display string")
DEFINE_MTYPE(BGPD, LCOMMUNITY_VAL, "Large Community value")
DEFINE_MTYPE(BGPD, BGP_EVPN, "BGP EVPN Information")
-DEFINE_MTYPE(BGPD, BGP_EVPN_ES_VTEP, "BGP EVPN ES VTEP Ip")
+DEFINE_MTYPE(BGPD, BGP_EVPN_MH_INFO, "BGP EVPN Multihoming Information")
+DEFINE_MTYPE(BGPD, BGP_EVPN_ES_VTEP, "BGP EVPN ES VTEP")
+DEFINE_MTYPE(BGPD, BGP_EVPN_ES_EVI_VTEP, "BGP EVPN ES-EVI VTEP")
DEFINE_MTYPE(BGPD, BGP_EVPN_ES, "BGP EVPN ESI Information")
+DEFINE_MTYPE(BGPD, BGP_EVPN_ES_EVI, "BGP EVPN ES-per-EVI Information")
DEFINE_MTYPE(BGPD, BGP_EVPN_IMPORT_RT, "BGP EVPN Import RT")
DEFINE_MTYPE(BGPD, BGP_EVPN_VRF_IMPORT_RT, "BGP EVPN VRF Import RT")
DEFINE_MTYPE(BGPD, BGP_EVPN_MACIP, "BGP EVPN MAC IP")
diff --git a/bgpd/bgp_memory.h b/bgpd/bgp_memory.h
index 5428022551..d1ae392c65 100644
--- a/bgpd/bgp_memory.h
+++ b/bgpd/bgp_memory.h
@@ -111,8 +111,11 @@ DECLARE_MTYPE(LCOMMUNITY)
DECLARE_MTYPE(LCOMMUNITY_STR)
DECLARE_MTYPE(LCOMMUNITY_VAL)
+DECLARE_MTYPE(BGP_EVPN_MH_INFO)
DECLARE_MTYPE(BGP_EVPN_ES)
+DECLARE_MTYPE(BGP_EVPN_ES_EVI)
DECLARE_MTYPE(BGP_EVPN_ES_VTEP)
+DECLARE_MTYPE(BGP_EVPN_ES_EVI_VTEP)
DECLARE_MTYPE(BGP_EVPN)
DECLARE_MTYPE(BGP_EVPN_IMPORT_RT)
diff --git a/bgpd/bgp_nht.c b/bgpd/bgp_nht.c
index aefcaeff3a..a74b5f91ac 100644
--- a/bgpd/bgp_nht.c
+++ b/bgpd/bgp_nht.c
@@ -146,6 +146,11 @@ int bgp_find_or_add_nexthop(struct bgp *bgp_route, struct bgp *bgp_nexthop,
afi = BGP_ATTR_NEXTHOP_AFI_IP6(pi->attr) ? AFI_IP6
: AFI_IP;
+ /* Validation for the ipv4 mapped ipv6 nexthop. */
+ if (IS_MAPPED_IPV6(&pi->attr->mp_nexthop_global)) {
+ afi = AFI_IP;
+ }
+
/* This will return true if the global IPv6 NH is a link local
* addr */
if (make_prefix(afi, pi, &p) < 0)
@@ -533,6 +538,7 @@ static int make_prefix(int afi, struct bgp_path_info *pi, struct prefix *p)
: 0;
struct bgp_dest *net = pi->net;
const struct prefix *p_orig = bgp_dest_get_prefix(net);
+ struct in_addr ipv4;
if (p_orig->family == AF_FLOWSPEC) {
if (!pi->peer)
@@ -548,8 +554,15 @@ static int make_prefix(int afi, struct bgp_path_info *pi, struct prefix *p)
p->u.prefix4 = p_orig->u.prefix4;
p->prefixlen = p_orig->prefixlen;
} else {
- p->u.prefix4 = pi->attr->nexthop;
- p->prefixlen = IPV4_MAX_BITLEN;
+ if (IS_MAPPED_IPV6(&pi->attr->mp_nexthop_global)) {
+ ipv4_mapped_ipv6_to_ipv4(
+ &pi->attr->mp_nexthop_global, &ipv4);
+ p->u.prefix4 = ipv4;
+ p->prefixlen = IPV4_MAX_BITLEN;
+ } else {
+ p->u.prefix4 = pi->attr->nexthop;
+ p->prefixlen = IPV4_MAX_BITLEN;
+ }
}
break;
case AFI_IP6:
diff --git a/bgpd/bgp_rd.h b/bgpd/bgp_rd.h
index b5ad9d624d..2aee44c721 100644
--- a/bgpd/bgp_rd.h
+++ b/bgpd/bgp_rd.h
@@ -33,6 +33,7 @@
#endif
#define RD_ADDRSTRLEN 28
+#define RD_BYTES 8
struct rd_as {
uint16_t type;
diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c
index 545e140028..80ffa18424 100644
--- a/bgpd/bgp_route.c
+++ b/bgpd/bgp_route.c
@@ -79,6 +79,7 @@
#include "bgpd/bgp_encap_types.h"
#include "bgpd/bgp_encap_tlv.h"
#include "bgpd/bgp_evpn.h"
+#include "bgpd/bgp_evpn_mh.h"
#include "bgpd/bgp_evpn_vty.h"
#include "bgpd/bgp_flowspec.h"
#include "bgpd/bgp_flowspec_util.h"
@@ -544,6 +545,11 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
uint32_t new_mm_seq;
uint32_t exist_mm_seq;
int nh_cmp;
+ esi_t *exist_esi;
+ esi_t *new_esi;
+ bool same_esi;
+ bool old_proxy;
+ bool new_proxy;
*paths_eq = 0;
@@ -620,6 +626,47 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
}
}
+ new_esi = bgp_evpn_attr_get_esi(newattr);
+ exist_esi = bgp_evpn_attr_get_esi(existattr);
+ if (bgp_evpn_is_esi_valid(new_esi) &&
+ !memcmp(new_esi, exist_esi, sizeof(esi_t))) {
+ same_esi = true;
+ } else {
+ same_esi = false;
+ }
+
+ /* If both paths have the same non-zero ES and
+ * one path is local it wins.
+ * PS: Note the local path wins even if the remote
+ * has the higher MM seq. The local path's
+ * MM seq will be fixed up to match the highest
+ * rem seq, subsequently.
+ */
+ if (same_esi) {
+ char esi_buf[ESI_STR_LEN];
+
+ if (bgp_evpn_is_path_local(bgp, new)) {
+ *reason = bgp_path_selection_evpn_local_path;
+ if (debug)
+ zlog_debug(
+ "%s: %s wins over %s as ES %s is same and local",
+ pfx_buf, new_buf, exist_buf,
+ esi_to_str(new_esi, esi_buf,
+ sizeof(esi_buf)));
+ return 1;
+ }
+ if (bgp_evpn_is_path_local(bgp, exist)) {
+ *reason = bgp_path_selection_evpn_local_path;
+ if (debug)
+ zlog_debug(
+ "%s: %s loses to %s as ES %s is same and local",
+ pfx_buf, new_buf, exist_buf,
+ esi_to_str(new_esi, esi_buf,
+ sizeof(esi_buf)));
+ return 0;
+ }
+ }
+
new_mm_seq = mac_mobility_seqnum(newattr);
exist_mm_seq = mac_mobility_seqnum(existattr);
@@ -643,6 +690,30 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
return 0;
}
+ /* if the sequence numbers and ESI are the same and one path
+ * is non-proxy it wins (over proxy)
+ */
+ new_proxy = bgp_evpn_attr_is_proxy(newattr);
+ old_proxy = bgp_evpn_attr_is_proxy(existattr);
+ if (same_esi && bgp_evpn_attr_is_local_es(newattr) &&
+ old_proxy != new_proxy) {
+ if (!new_proxy) {
+ *reason = bgp_path_selection_evpn_non_proxy;
+ if (debug)
+ zlog_debug(
+ "%s: %s wins over %s, same seq/es and non-proxy",
+ pfx_buf, new_buf, exist_buf);
+ return 1;
+ }
+
+ *reason = bgp_path_selection_evpn_non_proxy;
+ if (debug)
+ zlog_debug(
+ "%s: %s loses to %s, same seq/es and non-proxy",
+ pfx_buf, new_buf, exist_buf);
+ return 0;
+ }
+
/*
* if sequence numbers are the same path with the lowest IP
* wins
@@ -1175,6 +1246,17 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
return 1;
}
+
+int bgp_evpn_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
+ struct bgp_path_info *exist, int *paths_eq)
+{
+ 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);
+}
+
/* Compare two bgp route entity. Return -1 if new is preferred, 1 if exist
* is preferred, or 0 if they are the same (usually will only occur if
* multipath is enabled
@@ -3172,19 +3254,10 @@ struct bgp_path_info *info_make(int type, int sub_type, unsigned short instance,
}
static void overlay_index_update(struct attr *attr,
- struct eth_segment_id *eth_s_id,
union gw_addr *gw_ip)
{
if (!attr)
return;
-
- if (eth_s_id == NULL) {
- memset(&(attr->evpn_overlay.eth_s_id), 0,
- sizeof(struct eth_segment_id));
- } else {
- memcpy(&(attr->evpn_overlay.eth_s_id), eth_s_id,
- sizeof(struct eth_segment_id));
- }
if (gw_ip == NULL) {
memset(&(attr->evpn_overlay.gw_ip), 0, sizeof(union gw_addr));
} else {
@@ -3194,20 +3267,17 @@ static void overlay_index_update(struct attr *attr,
}
static bool overlay_index_equal(afi_t afi, struct bgp_path_info *path,
- struct eth_segment_id *eth_s_id,
union gw_addr *gw_ip)
{
- struct eth_segment_id *path_eth_s_id, *path_eth_s_id_remote;
union gw_addr *path_gw_ip, *path_gw_ip_remote;
union {
- struct eth_segment_id esi;
+ esi_t esi;
union gw_addr ip;
} temp;
if (afi != AFI_L2VPN)
return true;
- path_eth_s_id = &(path->attr->evpn_overlay.eth_s_id);
path_gw_ip = &(path->attr->evpn_overlay.gw_ip);
if (gw_ip == NULL) {
@@ -3216,17 +3286,7 @@ static bool overlay_index_equal(afi_t afi, struct bgp_path_info *path,
} else
path_gw_ip_remote = gw_ip;
- if (eth_s_id == NULL) {
- memset(&temp, 0, sizeof(temp));
- path_eth_s_id_remote = &temp.esi;
- } else
- path_eth_s_id_remote = eth_s_id;
-
- if (!memcmp(path_gw_ip, path_gw_ip_remote, sizeof(union gw_addr)))
- return false;
-
- return !memcmp(path_eth_s_id, path_eth_s_id_remote,
- sizeof(struct eth_segment_id));
+ return !!memcmp(path_gw_ip, path_gw_ip_remote, sizeof(union gw_addr));
}
/* Check if received nexthop is valid or not. */
@@ -3521,7 +3581,7 @@ int bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id,
num_labels * sizeof(mpls_label_t))
== 0)
&& (overlay_index_equal(
- afi, pi, evpn == NULL ? NULL : &evpn->eth_s_id,
+ afi, pi,
evpn == NULL ? NULL : &evpn->gw_ip))) {
if (CHECK_FLAG(bgp->af_flags[afi][safi],
BGP_CONFIG_DAMPENING)
@@ -3746,7 +3806,7 @@ int bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id,
/* Update Overlay Index */
if (afi == AFI_L2VPN) {
overlay_index_update(
- pi->attr, evpn == NULL ? NULL : &evpn->eth_s_id,
+ pi->attr,
evpn == NULL ? NULL : &evpn->gw_ip);
}
@@ -3791,13 +3851,9 @@ int bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id,
BGP_PATH_VALID);
else {
if (BGP_DEBUG(nht, NHT)) {
- char buf1[INET6_ADDRSTRLEN];
- inet_ntop(AF_INET,
- (const void *)&attr_new
- ->nexthop,
- buf1, INET6_ADDRSTRLEN);
- zlog_debug("%s(%s): NH unresolved",
- __func__, buf1);
+ zlog_debug("%s(%pI4): NH unresolved",
+ __func__,
+ (in_addr_t *)&attr_new->nexthop);
}
bgp_path_info_unset_flag(dest, pi,
BGP_PATH_VALID);
@@ -3916,7 +3972,6 @@ int bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id,
/* Update Overlay Index */
if (afi == AFI_L2VPN) {
overlay_index_update(new->attr,
- evpn == NULL ? NULL : &evpn->eth_s_id,
evpn == NULL ? NULL : &evpn->gw_ip);
}
/* Nexthop reachability check. */
@@ -5305,7 +5360,7 @@ static void bgp_static_update_safi(struct bgp *bgp, const struct prefix *p,
else if (bgp_static->gatewayIp.family == AF_INET6)
memcpy(&(add.ipv6), &(bgp_static->gatewayIp.u.prefix6),
sizeof(struct in6_addr));
- overlay_index_update(&attr, bgp_static->eth_s_id, &add);
+ 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(struct bgp_encap_type_vxlan));
@@ -5356,7 +5411,7 @@ static void bgp_static_update_safi(struct bgp *bgp, const struct prefix *p,
if (pi) {
memset(&add, 0, sizeof(union gw_addr));
if (attrhash_cmp(pi->attr, attr_new)
- && overlay_index_equal(afi, pi, bgp_static->eth_s_id, &add)
+ && overlay_index_equal(afi, pi, &add)
&& !CHECK_FLAG(pi->flags, BGP_PATH_REMOVED)) {
bgp_dest_unlock_node(dest);
bgp_attr_unintern(&attr_new);
@@ -5860,7 +5915,7 @@ int bgp_static_set_safi(afi_t afi, safi_t safi, struct vty *vty,
if (esi) {
bgp_static->eth_s_id =
XCALLOC(MTYPE_ATTR,
- sizeof(struct eth_segment_id));
+ sizeof(esi_t));
str2esi(esi, bgp_static->eth_s_id);
}
if (routermac) {
@@ -7411,7 +7466,7 @@ void bgp_redistribute_withdraw(struct bgp *bgp, afi_t afi, int type,
/* Static function to display route. */
static void route_vty_out_route(const struct prefix *p, struct vty *vty,
- json_object *json)
+ json_object *json, bool wide)
{
int len = 0;
char buf[BUFSIZ];
@@ -7466,7 +7521,7 @@ static void route_vty_out_route(const struct prefix *p, struct vty *vty,
}
if (!json) {
- len = 17 - len;
+ len = wide ? (45 - len) : (17 - len);
if (len < 1)
vty_out(vty, "\n%*s", 20, " ");
else
@@ -7569,7 +7624,7 @@ static char *bgp_nexthop_hostname(struct peer *peer,
/* called from terminal list command */
void route_vty_out(struct vty *vty, const struct prefix *p,
struct bgp_path_info *path, int display, safi_t safi,
- json_object *json_paths)
+ json_object *json_paths, bool wide)
{
int len;
struct attr *attr = path->attr;
@@ -7586,6 +7641,7 @@ void route_vty_out(struct vty *vty, const struct prefix *p,
const char *nexthop_vrfname = VRF_DEFAULT_NAME;
char *nexthop_hostname =
bgp_nexthop_hostname(path->peer, path->nexthop);
+ char esi_buf[ESI_STR_LEN];
if (json_paths)
json_path = json_object_new_object();
@@ -7596,11 +7652,11 @@ void route_vty_out(struct vty *vty, const struct prefix *p,
if (!json_paths) {
/* print prefix and mask */
if (!display)
- route_vty_out_route(p, vty, json_path);
+ route_vty_out_route(p, vty, json_path, wide);
else
- vty_out(vty, "%*s", 17, " ");
+ vty_out(vty, "%*s", (wide ? 45 : 17), " ");
} else {
- route_vty_out_route(p, vty, json_path);
+ route_vty_out_route(p, vty, json_path, wide);
}
/*
@@ -7690,7 +7746,7 @@ void route_vty_out(struct vty *vty, const struct prefix *p,
else
len = vty_out(vty, "%s%s", nexthop, vrf_id_str);
- len = 16 - len;
+ len = wide ? (41 - len) : (16 - len);
if (len < 1)
vty_out(vty, "\n%*s", 36, " ");
else
@@ -7720,7 +7776,7 @@ void route_vty_out(struct vty *vty, const struct prefix *p,
len = vty_out(vty, "%pI4%s", &attr->nexthop,
vrf_id_str);
- len = 16 - len;
+ len = wide ? (41 - len) : (16 - len);
if (len < 1)
vty_out(vty, "\n%*s", 36, " ");
else
@@ -7756,7 +7812,7 @@ void route_vty_out(struct vty *vty, const struct prefix *p,
&attr->nexthop,
vrf_id_str);
- len = 16 - len;
+ len = wide ? (41 - len) : (16 - len);
if (len < 1)
vty_out(vty, "\n%*s", 36, " ");
else
@@ -7787,7 +7843,7 @@ void route_vty_out(struct vty *vty, const struct prefix *p,
len = vty_out(vty, "%pI4%s", &attr->nexthop,
vrf_id_str);
- len = 16 - len;
+ len = wide ? (41 - len) : (16 - len);
if (len < 1)
vty_out(vty, "\n%*s", 36, " ");
else
@@ -7860,10 +7916,9 @@ void route_vty_out(struct vty *vty, const struct prefix *p,
if (path->peer->conf_if) {
len = vty_out(vty, "%s",
path->peer->conf_if);
- len = 16 - len; /* len of IPv6
- addr + max
- len of def
- ifname */
+ /* len of IPv6 addr + max len of def
+ * ifname */
+ len = wide ? (41 - len) : (16 - len);
if (len < 1)
vty_out(vty, "\n%*s", 36, " ");
@@ -7882,7 +7937,7 @@ void route_vty_out(struct vty *vty, const struct prefix *p,
&attr->mp_nexthop_local,
vrf_id_str);
- len = 16 - len;
+ len = wide ? (41 - len) : (16 - len);
if (len < 1)
vty_out(vty, "\n%*s", 36, " ");
@@ -7900,7 +7955,7 @@ void route_vty_out(struct vty *vty, const struct prefix *p,
&attr->mp_nexthop_global,
vrf_id_str);
- len = 16 - len;
+ len = wide ? (41 - len) : (16 - len);
if (len < 1)
vty_out(vty, "\n%*s", 36, " ");
@@ -7914,10 +7969,16 @@ void route_vty_out(struct vty *vty, const struct prefix *p,
if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
if (json_paths)
json_object_int_add(json_path, "metric", attr->med);
+ else if (wide)
+ vty_out(vty, "%7u", attr->med);
else
vty_out(vty, "%10u", attr->med);
- else if (!json_paths)
- vty_out(vty, " ");
+ else if (!json_paths) {
+ if (wide)
+ vty_out(vty, "%*s", 7, " ");
+ else
+ vty_out(vty, "%*s", 10, " ");
+ }
/* Local Pref */
if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
@@ -7958,6 +8019,11 @@ void route_vty_out(struct vty *vty, const struct prefix *p,
vty_out(vty, "%s", bgp_origin_str[attr->origin]);
if (json_paths) {
+ if (bgp_evpn_is_esi_valid(&attr->esi)) {
+ json_object_string_add(json_path, "esi",
+ esi_to_str(&attr->esi,
+ esi_buf, sizeof(esi_buf)));
+ }
if (safi == SAFI_EVPN &&
attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES)) {
json_ext_community = json_object_new_object();
@@ -8003,10 +8069,18 @@ void route_vty_out(struct vty *vty, const struct prefix *p,
} else {
vty_out(vty, "\n");
- if (safi == SAFI_EVPN &&
- attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES)) {
- vty_out(vty, "%*s", 20, " ");
- vty_out(vty, "%s\n", attr->ecommunity->str);
+ if (safi == SAFI_EVPN) {
+ if (bgp_evpn_is_esi_valid(&attr->esi)) {
+ vty_out(vty, "%*s", 20, " ");
+ vty_out(vty, "ESI:%s\n",
+ esi_to_str(&attr->esi,
+ esi_buf, sizeof(esi_buf)));
+ }
+ if (attr->flag &
+ ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES)) {
+ vty_out(vty, "%*s", 20, " ");
+ vty_out(vty, "%s\n", attr->ecommunity->str);
+ }
}
#ifdef ENABLE_BGP_VNC
@@ -8021,7 +8095,7 @@ void route_vty_out(struct vty *vty, const struct prefix *p,
/* called from terminal list command */
void route_vty_out_tmp(struct vty *vty, const struct prefix *p,
struct attr *attr, safi_t safi, bool use_json,
- json_object *json_ar)
+ json_object *json_ar, bool wide)
{
json_object *json_status = NULL;
json_object *json_net = NULL;
@@ -8053,7 +8127,7 @@ void route_vty_out_tmp(struct vty *vty, const struct prefix *p,
json_object_string_add(json_net, "network", buff);
}
} else
- route_vty_out_route(p, vty, NULL);
+ route_vty_out_route(p, vty, NULL, wide);
/* Print attribute */
if (attr) {
@@ -8114,6 +8188,9 @@ void route_vty_out_tmp(struct vty *vty, const struct prefix *p,
vty_out(vty, "%-16s",
inet_ntoa(
attr->mp_nexthop_global_in));
+ else if (wide)
+ vty_out(vty, "%-41s",
+ inet_ntoa(attr->nexthop));
else
vty_out(vty, "%-16s",
inet_ntoa(attr->nexthop));
@@ -8126,7 +8203,7 @@ void route_vty_out_tmp(struct vty *vty, const struct prefix *p,
inet_ntop(AF_INET6,
&attr->mp_nexthop_global, buf,
BUFSIZ));
- len = 16 - len;
+ len = wide ? (41 - len) : (16 - len);
if (len < 1)
vty_out(vty, "\n%*s", 36, " ");
else
@@ -8134,7 +8211,12 @@ void route_vty_out_tmp(struct vty *vty, const struct prefix *p,
}
if (attr->flag
& ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
- vty_out(vty, "%10u", attr->med);
+ if (wide)
+ vty_out(vty, "%7u", attr->med);
+ else
+ vty_out(vty, "%10u", attr->med);
+ else if (wide)
+ vty_out(vty, " ");
else
vty_out(vty, " ");
@@ -8185,7 +8267,7 @@ void route_vty_out_tag(struct vty *vty, const struct prefix *p,
/* print prefix and mask */
if (json == NULL) {
if (!display)
- route_vty_out_route(p, vty, NULL);
+ route_vty_out_route(p, vty, NULL, false);
else
vty_out(vty, "%*s", 17, " ");
}
@@ -8282,7 +8364,7 @@ void route_vty_out_overlay(struct vty *vty, const struct prefix *p,
/* print prefix and mask */
if (!display)
- route_vty_out_route(p, vty, json_path);
+ route_vty_out_route(p, vty, json_path, false);
else
vty_out(vty, "%*s", 17, " ");
@@ -8331,15 +8413,6 @@ void route_vty_out_overlay(struct vty *vty, const struct prefix *p,
}
}
- char *str = esi2str(&(attr->evpn_overlay.eth_s_id));
-
- if (!json_path)
- vty_out(vty, "%s", str);
- else
- json_object_string_add(json_overlay, "esi", str);
-
- XFREE(MTYPE_TMP, str);
-
if (is_evpn_prefix_ipaddr_v4((struct prefix_evpn *)p)) {
inet_ntop(AF_INET, &(attr->evpn_overlay.gw_ip.ipv4), buf,
BUFSIZ);
@@ -8397,7 +8470,7 @@ static void damp_route_vty_out(struct vty *vty, const struct prefix *p,
/* print prefix and mask */
if (!use_json) {
if (!display)
- route_vty_out_route(p, vty, NULL);
+ route_vty_out_route(p, vty, NULL, false);
else
vty_out(vty, "%*s", 17, " ");
}
@@ -8468,7 +8541,7 @@ static void flap_route_vty_out(struct vty *vty, const struct prefix *p,
/* print prefix and mask */
if (!use_json) {
if (!display)
- route_vty_out_route(p, vty, NULL);
+ route_vty_out_route(p, vty, NULL, false);
else
vty_out(vty, "%*s", 17, " ");
}
@@ -8623,6 +8696,10 @@ static const char *bgp_path_selection_reason2str(
return "EVPN sequence number";
case bgp_path_selection_evpn_lower_ip:
return "EVPN lower IP";
+ case bgp_path_selection_evpn_local_path:
+ return "EVPN local ES path";
+ case bgp_path_selection_evpn_non_proxy:
+ return "EVPN non proxy";
case bgp_path_selection_weight:
return "Weight";
case bgp_path_selection_local_pref:
@@ -8661,9 +8738,67 @@ static const char *bgp_path_selection_reason2str(
return "Invalid (internal error)";
}
-void route_vty_out_detail(struct vty *vty, struct bgp *bgp, struct bgp_dest *bn,
- struct bgp_path_info *path, afi_t afi, safi_t safi,
- json_object *json_paths)
+static void route_vty_out_detail_es_info(struct vty *vty,
+ struct attr *attr, json_object *json_path)
+{
+ char esi_buf[ESI_STR_LEN];
+ bool es_local = !!CHECK_FLAG(attr->es_flags, ATTR_ES_IS_LOCAL);
+ bool peer_router = !!CHECK_FLAG(attr->es_flags,
+ ATTR_ES_PEER_ROUTER);
+ bool peer_active = !!CHECK_FLAG(attr->es_flags,
+ ATTR_ES_PEER_ACTIVE);
+ bool peer_proxy = !!CHECK_FLAG(attr->es_flags,
+ ATTR_ES_PEER_PROXY);
+
+ esi_to_str(&attr->esi, esi_buf, sizeof(esi_buf));
+ if (json_path) {
+ json_object *json_es_info = NULL;
+
+ json_object_string_add(
+ json_path, "esi",
+ esi_buf);
+ if (es_local || bgp_evpn_attr_is_sync(attr)) {
+ json_es_info = json_object_new_object();
+ if (es_local)
+ json_object_boolean_true_add(
+ json_es_info, "localEs");
+ if (peer_active)
+ json_object_boolean_true_add(
+ json_es_info, "peerActive");
+ if (peer_proxy)
+ json_object_boolean_true_add(
+ json_es_info, "peerProxy");
+ if (peer_router)
+ json_object_boolean_true_add(
+ json_es_info, "peerRouter");
+ if (attr->mm_sync_seqnum)
+ json_object_int_add(
+ json_es_info, "peerSeq",
+ attr->mm_sync_seqnum);
+ json_object_object_add(
+ json_path, "es_info",
+ json_es_info);
+ }
+ } else {
+ if (bgp_evpn_attr_is_sync(attr))
+ vty_out(vty,
+ " ESI %s %s peer-info: (%s%s%sMM: %d)\n",
+ esi_buf,
+ es_local ? "local-es":"",
+ peer_proxy ? "proxy " : "",
+ peer_active ? "active ":"",
+ peer_router ? "router ":"",
+ attr->mm_sync_seqnum);
+ else
+ vty_out(vty, " ESI %s %s\n",
+ esi_buf,
+ es_local ? "local-es":"");
+ }
+}
+
+void route_vty_out_detail(struct vty *vty, struct bgp *bgp,
+ struct bgp_dest *bn, struct bgp_path_info *path,
+ afi_t afi, safi_t safi, json_object *json_paths)
{
char buf[INET6_ADDRSTRLEN];
char buf1[BUFSIZ];
@@ -9133,6 +9268,11 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp, struct bgp_dest *bn,
"used");
}
+ if (safi == SAFI_EVPN &&
+ bgp_evpn_is_esi_valid(&attr->esi)) {
+ route_vty_out_detail_es_info(vty, attr, json_path);
+ }
+
/* Line 3 display Origin, Med, Locpref, Weight, Tag, valid,
* Int/Ext/Local, Atomic, best */
if (json_paths)
@@ -9583,7 +9723,7 @@ static int bgp_show_table(struct vty *vty, struct bgp *bgp, safi_t safi,
void *output_arg, bool use_json, char *rd,
int is_last, unsigned long *output_cum,
unsigned long *total_cum,
- unsigned long *json_header_depth)
+ unsigned long *json_header_depth, bool wide)
{
struct bgp_path_info *pi;
struct bgp_dest *dest;
@@ -9592,7 +9732,6 @@ static int bgp_show_table(struct vty *vty, struct bgp *bgp, safi_t safi,
unsigned long output_count = 0;
unsigned long total_count = 0;
struct prefix *p;
- char buf2[BUFSIZ];
json_object *json_paths = NULL;
int first = 1;
@@ -9807,7 +9946,8 @@ static int bgp_show_table(struct vty *vty, struct bgp *bgp, safi_t safi,
|| type == bgp_show_type_flap_neighbor)
vty_out(vty, BGP_SHOW_FLAP_HEADER);
else
- vty_out(vty, BGP_SHOW_HEADER);
+ vty_out(vty, (wide ? BGP_SHOW_HEADER_WIDE
+ : BGP_SHOW_HEADER));
header = 0;
}
if (rd != NULL && !display && !output_count) {
@@ -9828,7 +9968,7 @@ static int bgp_show_table(struct vty *vty, struct bgp *bgp, safi_t safi,
json_paths);
else
route_vty_out(vty, dest_p, pi, display, safi,
- json_paths);
+ json_paths, wide);
display++;
}
@@ -9855,11 +9995,10 @@ static int bgp_show_table(struct vty *vty, struct bgp *bgp, safi_t safi,
dest_p->u.prefix_flowspec
.prefixlen);
} else {
- prefix2str(dest_p, buf2, sizeof(buf2));
if (first)
- vty_out(vty, "\"%s\": ", buf2);
+ vty_out(vty, "\"%pFX\": ", dest_p);
else
- vty_out(vty, ",\"%s\": ", buf2);
+ vty_out(vty, ",\"%pFX\": ", dest_p);
}
vty_out(vty, "%s",
json_object_to_json_string_ext(
@@ -9936,7 +10075,7 @@ int bgp_show_table_rd(struct vty *vty, struct bgp *bgp, safi_t safi,
prefix_rd2str(&prd, rd, sizeof(rd));
bgp_show_table(vty, bgp, safi, itable, type, output_arg,
use_json, rd, next == NULL, &output_cum,
- &total_cum, &json_header_depth);
+ &total_cum, &json_header_depth, false);
if (next == NULL)
show_msg = false;
}
@@ -9953,7 +10092,8 @@ int bgp_show_table_rd(struct vty *vty, struct bgp *bgp, safi_t safi,
return CMD_SUCCESS;
}
static int bgp_show(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
- enum bgp_show_type type, void *output_arg, bool use_json)
+ enum bgp_show_type type, void *output_arg, bool use_json,
+ bool wide)
{
struct bgp_table *table;
unsigned long json_header_depth = 0;
@@ -9987,11 +10127,12 @@ static int bgp_show(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
safi = SAFI_UNICAST;
return bgp_show_table(vty, bgp, safi, table, type, output_arg, use_json,
- NULL, 1, NULL, NULL, &json_header_depth);
+ NULL, 1, NULL, NULL, &json_header_depth, wide);
}
static void bgp_show_all_instances_routes_vty(struct vty *vty, afi_t afi,
- safi_t safi, bool use_json)
+ safi_t safi, bool use_json,
+ bool wide)
{
struct listnode *node, *nnode;
struct bgp *bgp;
@@ -10020,7 +10161,7 @@ static void bgp_show_all_instances_routes_vty(struct vty *vty, afi_t afi,
: bgp->name);
}
bgp_show(vty, bgp, afi, safi, bgp_show_type_normal, NULL,
- use_json);
+ use_json, wide);
}
if (use_json)
@@ -10507,8 +10648,8 @@ static int bgp_show_lcommunity(struct vty *vty, struct bgp *bgp, int argc,
return bgp_show(vty, bgp, afi, safi,
(exact ? bgp_show_type_lcommunity_exact
- : bgp_show_type_lcommunity),
- lcom, uj);
+ : bgp_show_type_lcommunity),
+ lcom, uj, false);
}
static int bgp_show_lcommunity_list(struct vty *vty, struct bgp *bgp,
@@ -10527,8 +10668,8 @@ static int bgp_show_lcommunity_list(struct vty *vty, struct bgp *bgp,
return bgp_show(vty, bgp, afi, safi,
(exact ? bgp_show_type_lcommunity_list_exact
- : bgp_show_type_lcommunity_list),
- list, uj);
+ : bgp_show_type_lcommunity_list),
+ list, uj, false);
}
DEFUN (show_ip_bgp_large_community_list,
@@ -10607,9 +10748,11 @@ DEFUN (show_ip_bgp_large_community,
exact_match, afi, safi, uj);
} else
return bgp_show(vty, bgp, afi, safi,
- bgp_show_type_lcommunity_all, NULL, uj);
+ bgp_show_type_lcommunity_all, NULL, uj, false);
}
+static int bgp_table_stats_single(struct vty *vty, struct bgp *bgp, afi_t afi,
+ safi_t safi, struct json_object *json_array);
static int bgp_table_stats(struct vty *vty, struct bgp *bgp, afi_t afi,
safi_t safi, struct json_object *json);
@@ -10629,7 +10772,7 @@ DEFUN(show_ip_bgp_statistics_all, show_ip_bgp_statistics_all_cmd,
bgp_vty_find_and_parse_afi_safi_bgp(vty, argv, argc, &idx, &afi, &safi,
&bgp, false);
- if (!bgp)
+ if (!idx)
return CMD_WARNING;
if (uj)
@@ -10829,7 +10972,7 @@ DEFUN(show_ip_bgp, show_ip_bgp_cmd,
}
/* BGP route print out function with JSON */
-DEFUN (show_ip_bgp_json,
+DEFPY (show_ip_bgp_json,
show_ip_bgp_json_cmd,
"show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]]\
[cidr-only\
@@ -10839,7 +10982,7 @@ DEFUN (show_ip_bgp_json,
|accept-own|accept-own-nexthop|route-filter-v6\
|route-filter-v4|route-filter-translated-v6\
|route-filter-translated-v4] [exact-match]\
- ] [json]",
+ ] [json$uj | wide$wide]",
SHOW_STR
IP_STR
BGP_STR
@@ -10867,7 +11010,8 @@ DEFUN (show_ip_bgp_json,
"RT translated VPNv6 route filtering (well-known community)\n"
"RT translated VPNv4 route filtering (well-known community)\n"
"Exact match of the communities\n"
- JSON_STR)
+ JSON_STR
+ "Increase table width for longer prefixes\n")
{
afi_t afi = AFI_IP6;
safi_t safi = SAFI_UNICAST;
@@ -10875,7 +11019,6 @@ DEFUN (show_ip_bgp_json,
struct bgp *bgp = NULL;
int idx = 0;
int exact_match = 0;
- bool uj = use_json(argc, argv);
if (uj)
argc--;
@@ -10887,16 +11030,17 @@ DEFUN (show_ip_bgp_json,
if (argv_find(argv, argc, "cidr-only", &idx))
return bgp_show(vty, bgp, afi, safi, bgp_show_type_cidr_only,
- NULL, uj);
+ NULL, uj, wide);
if (argv_find(argv, argc, "dampening", &idx)) {
if (argv_find(argv, argc, "dampened-paths", &idx))
return bgp_show(vty, bgp, afi, safi,
- bgp_show_type_dampend_paths, NULL, uj);
+ bgp_show_type_dampend_paths, NULL, uj,
+ wide);
else if (argv_find(argv, argc, "flap-statistics", &idx))
return bgp_show(vty, bgp, afi, safi,
- bgp_show_type_flap_statistics, NULL,
- uj);
+ bgp_show_type_flap_statistics, NULL, uj,
+ wide);
}
if (argv_find(argv, argc, "community", &idx)) {
@@ -10922,11 +11066,11 @@ DEFUN (show_ip_bgp_json,
exact_match, afi, safi, uj);
else
return (bgp_show(vty, bgp, afi, safi,
- bgp_show_type_community_all, NULL,
- uj));
+ bgp_show_type_community_all, NULL, uj,
+ wide));
}
- return bgp_show(vty, bgp, afi, safi, sh_type, NULL, uj);
+ return bgp_show(vty, bgp, afi, safi, sh_type, NULL, uj, wide);
}
DEFUN (show_ip_bgp_route,
@@ -11037,22 +11181,22 @@ DEFUN (show_ip_bgp_regexp,
bgp_show_type_regexp, uj);
}
-DEFUN (show_ip_bgp_instance_all,
+DEFPY (show_ip_bgp_instance_all,
show_ip_bgp_instance_all_cmd,
- "show [ip] bgp <view|vrf> all ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] [json]",
+ "show [ip] bgp <view|vrf> all ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] [json$uj | wide$wide]",
SHOW_STR
IP_STR
BGP_STR
BGP_INSTANCE_ALL_HELP_STR
BGP_AFI_HELP_STR
BGP_SAFI_WITH_LABEL_HELP_STR
- JSON_STR)
+ JSON_STR
+ "Increase table width for longer prefixes\n")
{
afi_t afi = AFI_IP;
safi_t safi = SAFI_UNICAST;
struct bgp *bgp = NULL;
int idx = 0;
- bool uj = use_json(argc, argv);
if (uj)
argc--;
@@ -11062,7 +11206,7 @@ DEFUN (show_ip_bgp_instance_all,
if (!idx)
return CMD_WARNING;
- bgp_show_all_instances_routes_vty(vty, afi, safi, uj);
+ bgp_show_all_instances_routes_vty(vty, afi, safi, uj, wide);
return CMD_SUCCESS;
}
@@ -11085,7 +11229,7 @@ static int bgp_show_regexp(struct vty *vty, struct bgp *bgp, const char *regstr,
return CMD_WARNING;
}
- rc = bgp_show(vty, bgp, afi, safi, type, regex, use_json);
+ rc = bgp_show(vty, bgp, afi, safi, type, regex, use_json, false);
bgp_regex_free(regex);
return rc;
}
@@ -11103,7 +11247,7 @@ static int bgp_show_prefix_list(struct vty *vty, struct bgp *bgp,
return CMD_WARNING;
}
- return bgp_show(vty, bgp, afi, safi, type, plist, 0);
+ return bgp_show(vty, bgp, afi, safi, type, plist, 0, false);
}
static int bgp_show_filter_list(struct vty *vty, struct bgp *bgp,
@@ -11119,7 +11263,7 @@ static int bgp_show_filter_list(struct vty *vty, struct bgp *bgp,
return CMD_WARNING;
}
- return bgp_show(vty, bgp, afi, safi, type, as_list, 0);
+ return bgp_show(vty, bgp, afi, safi, type, as_list, 0, false);
}
static int bgp_show_route_map(struct vty *vty, struct bgp *bgp,
@@ -11134,7 +11278,7 @@ static int bgp_show_route_map(struct vty *vty, struct bgp *bgp,
return CMD_WARNING;
}
- return bgp_show(vty, bgp, afi, safi, type, rmap, 0);
+ return bgp_show(vty, bgp, afi, safi, type, rmap, 0, false);
}
static int bgp_show_community(struct vty *vty, struct bgp *bgp,
@@ -11153,7 +11297,7 @@ static int bgp_show_community(struct vty *vty, struct bgp *bgp,
ret = bgp_show(vty, bgp, afi, safi,
(exact ? bgp_show_type_community_exact
: bgp_show_type_community),
- com, use_json);
+ com, use_json, false);
community_free(&com);
return ret;
@@ -11174,7 +11318,7 @@ static int bgp_show_community_list(struct vty *vty, struct bgp *bgp,
return bgp_show(vty, bgp, afi, safi,
(exact ? bgp_show_type_community_list_exact
: bgp_show_type_community_list),
- list, 0);
+ list, 0, false);
}
static int bgp_show_prefix_longer(struct vty *vty, struct bgp *bgp,
@@ -11192,7 +11336,7 @@ static int bgp_show_prefix_longer(struct vty *vty, struct bgp *bgp,
return CMD_WARNING;
}
- ret = bgp_show(vty, bgp, afi, safi, type, p, 0);
+ ret = bgp_show(vty, bgp, afi, safi, type, p, 0, false);
prefix_free(&p);
return ret;
}
@@ -11387,8 +11531,18 @@ static int bgp_table_stats_walker(struct thread *t)
return 0;
}
-static int bgp_table_stats(struct vty *vty, struct bgp *bgp, afi_t afi,
- safi_t safi, struct json_object *json_array)
+static void bgp_table_stats_all(struct vty *vty, afi_t afi, safi_t safi,
+ struct json_object *json_array)
+{
+ struct listnode *node, *nnode;
+ struct bgp *bgp;
+
+ for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
+ bgp_table_stats_single(vty, bgp, afi, safi, json_array);
+}
+
+static int bgp_table_stats_single(struct vty *vty, struct bgp *bgp, afi_t afi,
+ safi_t safi, struct json_object *json_array)
{
struct bgp_table_stats ts;
unsigned int i;
@@ -11416,8 +11570,10 @@ static int bgp_table_stats(struct vty *vty, struct bgp *bgp, afi_t afi,
}
if (!json)
- vty_out(vty, "BGP %s RIB statistics\n",
- get_afi_safi_str(afi, safi, false));
+ vty_out(vty, "BGP %s RIB statistics (%s)\n",
+ get_afi_safi_str(afi, safi, false), bgp->name_pretty);
+ else
+ json_object_string_add(json, "instance", bgp->name_pretty);
/* labeled-unicast routes live in the unicast table */
if (safi == SAFI_LABELED_UNICAST)
@@ -11606,6 +11762,17 @@ end_table_stats:
return ret;
}
+static int bgp_table_stats(struct vty *vty, struct bgp *bgp, afi_t afi,
+ safi_t safi, struct json_object *json_array)
+{
+ if (!bgp) {
+ bgp_table_stats_all(vty, afi, safi, json_array);
+ return CMD_SUCCESS;
+ }
+
+ return bgp_table_stats_single(vty, bgp, afi, safi, json_array);
+}
+
enum bgp_pcounts {
PCOUNT_ADJ_IN = 0,
PCOUNT_DAMPED,
@@ -11615,6 +11782,7 @@ enum bgp_pcounts {
PCOUNT_VALID,
PCOUNT_ALL,
PCOUNT_COUNTED,
+ PCOUNT_BPATH_SELECTED,
PCOUNT_PFCNT, /* the figure we display to users */
PCOUNT_MAX,
};
@@ -11628,6 +11796,7 @@ static const char *const pcount_strs[] = {
[PCOUNT_VALID] = "Valid",
[PCOUNT_ALL] = "All RIB",
[PCOUNT_COUNTED] = "PfxCt counted",
+ [PCOUNT_BPATH_SELECTED] = "PfxCt Best Selected",
[PCOUNT_PFCNT] = "Useable",
[PCOUNT_MAX] = NULL,
};
@@ -11668,6 +11837,8 @@ static void bgp_peer_count_proc(struct bgp_dest *rn, struct peer_pcounts *pc)
pc->count[PCOUNT_VALID]++;
if (!CHECK_FLAG(pi->flags, BGP_PATH_UNUSEABLE))
pc->count[PCOUNT_PFCNT]++;
+ if (CHECK_FLAG(pi->flags, BGP_PATH_SELECTED))
+ pc->count[PCOUNT_BPATH_SELECTED]++;
if (CHECK_FLAG(pi->flags, BGP_PATH_COUNTED)) {
pc->count[PCOUNT_COUNTED]++;
@@ -11931,10 +12102,56 @@ DEFUN (show_bgp_l2vpn_evpn_route_prefix,
use_json(argc, argv));
}
+static void show_adj_route_header(struct vty *vty, struct bgp *bgp,
+ struct bgp_table *table, int *header1,
+ int *header2, json_object *json,
+ json_object *json_scode,
+ json_object *json_ocode, bool wide)
+{
+ uint64_t version = table ? table->version : 0;
+
+ if (*header1) {
+ if (json) {
+ json_object_int_add(json, "bgpTableVersion", version);
+ json_object_string_add(json, "bgpLocalRouterId",
+ inet_ntoa(bgp->router_id));
+ json_object_int_add(json, "defaultLocPrf",
+ bgp->default_local_pref);
+ 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 %" PRIu64 ", local router ID is %s, vrf id ",
+ version, inet_ntoa(bgp->router_id));
+ if (bgp->vrf_id == VRF_UNKNOWN)
+ vty_out(vty, "%s", VRFID_NONE_STR);
+ else
+ vty_out(vty, "%u", bgp->vrf_id);
+ vty_out(vty, "\n");
+ vty_out(vty, "Default local pref %u, ",
+ bgp->default_local_pref);
+ vty_out(vty, "local AS %u\n", bgp->as);
+ vty_out(vty, BGP_SHOW_SCODE_HEADER);
+ vty_out(vty, BGP_SHOW_NCODE_HEADER);
+ vty_out(vty, BGP_SHOW_OCODE_HEADER);
+ }
+ *header1 = 0;
+ }
+ if (*header2) {
+ if (!json)
+ vty_out(vty, (wide ? BGP_SHOW_HEADER_WIDE
+ : BGP_SHOW_HEADER));
+ *header2 = 0;
+ }
+}
+
static void show_adj_route(struct vty *vty, struct peer *peer, afi_t afi,
safi_t safi, enum bgp_show_adj_route_type type,
const char *rmap_name, bool use_json,
- json_object *json)
+ json_object *json, bool wide)
{
struct bgp_table *table;
struct bgp_adj_in *ain;
@@ -12041,58 +12258,9 @@ static void show_adj_route(struct vty *vty, struct peer *peer, afi_t afi,
if (ain->peer != peer)
continue;
- if (header1) {
- if (use_json) {
- json_object_int_add(
- json, "bgpTableVersion",
- 0);
- json_object_string_add(
- json,
- "bgpLocalRouterId",
- inet_ntoa(
- bgp->router_id));
- json_object_int_add(json,
- "defaultLocPrf",
- bgp->default_local_pref);
- 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 %s, vrf id ",
- inet_ntoa(
- bgp->router_id));
- if (bgp->vrf_id == VRF_UNKNOWN)
- vty_out(vty, "%s",
- VRFID_NONE_STR);
- else
- vty_out(vty, "%u",
- bgp->vrf_id);
- vty_out(vty, "\n");
- vty_out(vty,
- "Default local pref %u, ",
- bgp->default_local_pref);
- vty_out(vty, "local AS %u\n",
- bgp->as);
- vty_out(vty,
- BGP_SHOW_SCODE_HEADER);
- vty_out(vty,
- BGP_SHOW_NCODE_HEADER);
- vty_out(vty,
- BGP_SHOW_OCODE_HEADER);
- }
- header1 = 0;
- }
- if (header2) {
- if (!use_json)
- vty_out(vty, BGP_SHOW_HEADER);
- header2 = 0;
- }
+ show_adj_route_header(
+ vty, bgp, table, &header1, &header2,
+ json, json_scode, json_ocode, wide);
attr = *ain->attr;
route_filtered = false;
@@ -12123,7 +12291,7 @@ static void show_adj_route(struct vty *vty, struct peer *peer, afi_t afi,
filtered_count++;
route_vty_out_tmp(vty, rn_p, &attr, safi,
- use_json, json_ar);
+ use_json, json_ar, wide);
bgp_attr_undup(&attr, ain->attr);
output_count++;
}
@@ -12133,70 +12301,10 @@ static void show_adj_route(struct vty *vty, struct peer *peer, afi_t afi,
if (paf->peer != peer || !adj->attr)
continue;
- if (header1) {
- if (use_json) {
- json_object_int_add(
- json,
- "bgpTableVersion",
- table->version);
- json_object_string_add(
- json,
- "bgpLocalRouterId",
- inet_ntoa(
- bgp->router_id));
- json_object_int_add(
- json, "defaultLocPrf",
- bgp->default_local_pref
- );
- 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 %" PRIu64", local router ID is %s, vrf id ",
- table->version,
- inet_ntoa(
- bgp->router_id));
- if (bgp->vrf_id ==
- VRF_UNKNOWN)
- vty_out(vty,
- "%s",
- VRFID_NONE_STR);
- else
- vty_out(vty,
- "%u",
- bgp->vrf_id);
- vty_out(vty, "\n");
- vty_out(vty,
- "Default local pref %u, ",
- bgp->default_local_pref
- );
- vty_out(vty,
- "local AS %u\n",
- bgp->as);
- vty_out(vty,
- BGP_SHOW_SCODE_HEADER);
- vty_out(vty,
- BGP_SHOW_NCODE_HEADER);
- vty_out(vty,
- BGP_SHOW_OCODE_HEADER);
- }
- header1 = 0;
- }
- if (header2) {
- if (!use_json)
- vty_out(vty,
- BGP_SHOW_HEADER);
- header2 = 0;
- }
+ show_adj_route_header(
+ vty, bgp, table, &header1,
+ &header2, json, json_scode,
+ json_ocode, wide);
const struct prefix *rn_p =
bgp_dest_get_prefix(dest);
@@ -12209,7 +12317,8 @@ static void show_adj_route(struct vty *vty, struct peer *peer, afi_t afi,
if (ret != RMAP_DENY) {
route_vty_out_tmp(
vty, rn_p, &attr, safi,
- use_json, json_ar);
+ use_json, json_ar,
+ wide);
output_count++;
} else {
filtered_count++;
@@ -12217,6 +12326,27 @@ static void show_adj_route(struct vty *vty, struct peer *peer, afi_t afi,
bgp_attr_undup(&attr, adj->attr);
}
+ } else if (type == bgp_show_adj_route_bestpath) {
+ struct bgp_path_info *pi;
+
+ show_adj_route_header(vty, bgp, table, &header1,
+ &header2, json, json_scode,
+ json_ocode, wide);
+
+ for (pi = bgp_dest_get_bgp_path_info(dest); pi;
+ pi = pi->next) {
+ if (pi->peer != peer)
+ continue;
+
+ if (!CHECK_FLAG(pi->flags, BGP_PATH_SELECTED))
+ continue;
+
+ route_vty_out_tmp(vty,
+ bgp_dest_get_prefix(dest),
+ pi->attr, safi, use_json,
+ json_ar, wide);
+ output_count++;
+ }
}
}
@@ -12248,7 +12378,7 @@ static void show_adj_route(struct vty *vty, struct peer *peer, afi_t afi,
static int peer_adj_routes(struct vty *vty, struct peer *peer, afi_t afi,
safi_t safi, enum bgp_show_adj_route_type type,
- const char *rmap_name, bool use_json)
+ const char *rmap_name, bool use_json, bool wide)
{
json_object *json = NULL;
@@ -12285,14 +12415,57 @@ static int peer_adj_routes(struct vty *vty, struct peer *peer, afi_t afi,
return CMD_WARNING;
}
- show_adj_route(vty, peer, afi, safi, type, rmap_name, use_json, json);
+ show_adj_route(vty, peer, afi, safi, type, rmap_name, use_json, json,
+ wide);
return CMD_SUCCESS;
}
-DEFUN (show_ip_bgp_instance_neighbor_advertised_route,
+DEFPY (show_ip_bgp_instance_neighbor_bestpath_route,
+ show_ip_bgp_instance_neighbor_bestpath_route_cmd,
+ "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] neighbors <A.B.C.D|X:X::X:X|WORD> bestpath-routes [json$uj | wide$wide]",
+ SHOW_STR
+ IP_STR
+ BGP_STR
+ BGP_INSTANCE_HELP_STR
+ BGP_AFI_HELP_STR
+ BGP_SAFI_WITH_LABEL_HELP_STR
+ "Detailed information on TCP and BGP neighbor connections\n"
+ "Neighbor to display information about\n"
+ "Neighbor to display information about\n"
+ "Neighbor on BGP configured interface\n"
+ "Display the routes selected by best path\n"
+ JSON_STR
+ "Increase table width for longer prefixes\n")
+{
+ afi_t afi = AFI_IP6;
+ safi_t safi = SAFI_UNICAST;
+ char *rmap_name = NULL;
+ char *peerstr = NULL;
+ struct bgp *bgp = NULL;
+ struct peer *peer;
+ enum bgp_show_adj_route_type type = bgp_show_adj_route_bestpath;
+ int idx = 0;
+
+ bgp_vty_find_and_parse_afi_safi_bgp(vty, argv, argc, &idx, &afi, &safi,
+ &bgp, uj);
+
+ if (!idx)
+ return CMD_WARNING;
+
+ argv_find(argv, argc, "neighbors", &idx);
+ peerstr = argv[++idx]->arg;
+
+ peer = peer_lookup_in_view(vty, bgp, peerstr, uj);
+ if (!peer)
+ return CMD_WARNING;
+
+ return peer_adj_routes(vty, peer, afi, safi, type, rmap_name, uj, wide);
+}
+
+DEFPY (show_ip_bgp_instance_neighbor_advertised_route,
show_ip_bgp_instance_neighbor_advertised_route_cmd,
- "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] neighbors <A.B.C.D|X:X::X:X|WORD> <advertised-routes|received-routes|filtered-routes> [route-map WORD] [json]",
+ "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] neighbors <A.B.C.D|X:X::X:X|WORD> <advertised-routes|received-routes|filtered-routes> [route-map WORD] [json$uj | wide$wide]",
SHOW_STR
IP_STR
BGP_STR
@@ -12308,7 +12481,8 @@ DEFUN (show_ip_bgp_instance_neighbor_advertised_route,
"Display the filtered routes received from neighbor\n"
"Route-map to modify the attributes\n"
"Name of the route map\n"
- JSON_STR)
+ JSON_STR
+ "Increase table width for longer prefixes\n")
{
afi_t afi = AFI_IP6;
safi_t safi = SAFI_UNICAST;
@@ -12318,7 +12492,6 @@ DEFUN (show_ip_bgp_instance_neighbor_advertised_route,
struct peer *peer;
enum bgp_show_adj_route_type type = bgp_show_adj_route_advertised;
int idx = 0;
- bool uj = use_json(argc, argv);
if (uj)
argc--;
@@ -12346,7 +12519,7 @@ DEFUN (show_ip_bgp_instance_neighbor_advertised_route,
if (argv_find(argv, argc, "route-map", &idx))
rmap_name = argv[++idx]->arg;
- return peer_adj_routes(vty, peer, afi, safi, type, rmap_name, uj);
+ return peer_adj_routes(vty, peer, afi, safi, type, rmap_name, uj, wide);
}
DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
@@ -12454,7 +12627,8 @@ static int bgp_show_neighbor_route(struct vty *vty, struct peer *peer,
return CMD_WARNING;
}
- return bgp_show(vty, peer->bgp, afi, safi, type, &peer->su, use_json);
+ return bgp_show(vty, peer->bgp, afi, safi, type, &peer->su, use_json,
+ false);
}
DEFUN (show_ip_bgp_flowspec_routes_detailed,
@@ -12483,7 +12657,8 @@ DEFUN (show_ip_bgp_flowspec_routes_detailed,
if (!idx)
return CMD_WARNING;
- return bgp_show(vty, bgp, afi, safi, bgp_show_type_detail, NULL, uj);
+ return bgp_show(vty, bgp, afi, safi, bgp_show_type_detail, NULL, uj,
+ false);
}
DEFUN (show_ip_bgp_neighbor_routes,
@@ -13272,6 +13447,7 @@ static void bgp_config_write_network_evpn(struct vty *vty, struct bgp *bgp,
char buf[PREFIX_STRLEN * 2];
char buf2[SU_ADDRSTRLEN];
char rdbuf[RD_ADDRSTRLEN];
+ char esi_buf[ESI_BYTES];
/* Network configuration. */
for (pdest = bgp_table_top(bgp->route[afi][safi]); pdest;
@@ -13287,13 +13463,13 @@ static void bgp_config_write_network_evpn(struct vty *vty, struct bgp *bgp,
continue;
char *macrouter = NULL;
- char *esi = NULL;
if (bgp_static->router_mac)
macrouter = prefix_mac2str(
bgp_static->router_mac, NULL, 0);
if (bgp_static->eth_s_id)
- esi = esi2str(bgp_static->eth_s_id);
+ esi_to_str(bgp_static->eth_s_id,
+ esi_buf, sizeof(esi_buf));
p = bgp_dest_get_prefix(dest);
prd = (struct prefix_rd *)bgp_dest_get_prefix(pdest);
@@ -13324,11 +13500,10 @@ static void bgp_config_write_network_evpn(struct vty *vty, struct bgp *bgp,
" network %s rd %s ethtag %u label %u esi %s gwip %s routermac %s\n",
buf, rdbuf,
p->u.prefix_evpn.prefix_addr.eth_tag,
- decode_label(&bgp_static->label), esi, buf2,
+ decode_label(&bgp_static->label), esi_buf, buf2,
macrouter);
XFREE(MTYPE_TMP, macrouter);
- XFREE(MTYPE_TMP, esi);
}
}
}
@@ -13497,6 +13672,8 @@ void bgp_route_init(void)
install_element(VIEW_NODE,
&show_ip_bgp_instance_neighbor_advertised_route_cmd);
+ install_element(VIEW_NODE,
+ &show_ip_bgp_instance_neighbor_bestpath_route_cmd);
install_element(VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
install_element(VIEW_NODE,
&show_ip_bgp_neighbor_received_prefix_filter_cmd);
diff --git a/bgpd/bgp_route.h b/bgpd/bgp_route.h
index ee52dcc8c6..3f734d2672 100644
--- a/bgpd/bgp_route.h
+++ b/bgpd/bgp_route.h
@@ -62,6 +62,7 @@ enum bgp_show_adj_route_type {
bgp_show_adj_route_advertised,
bgp_show_adj_route_received,
bgp_show_adj_route_filtered,
+ bgp_show_adj_route_bestpath,
};
@@ -72,6 +73,7 @@ enum bgp_show_adj_route_type {
#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete\n\n"
#define BGP_SHOW_NCODE_HEADER "Nexthop codes: @NNN nexthop's vrf id, < announce-nh-self\n"
#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path\n"
+#define BGP_SHOW_HEADER_WIDE " Network Next Hop Metric LocPrf Weight Path\n"
/* Maximum number of labels we can process or send with a prefix. We
* really do only 1 for MPLS (BGP-LU) but we can do 2 for EVPN-VxLAN.
@@ -97,6 +99,7 @@ enum bgp_show_adj_route_type {
#define BGP_NLRI_PARSE_ERROR_FLOWSPEC_NLRI_SIZELIMIT -12
#define BGP_NLRI_PARSE_ERROR_FLOWSPEC_BAD_FORMAT -13
#define BGP_NLRI_PARSE_ERROR_ADDRESS_FAMILY -14
+#define BGP_NLRI_PARSE_ERROR_EVPN_TYPE1_SIZE -15
#define BGP_NLRI_PARSE_ERROR -32
/* Ancillary information to struct bgp_path_info,
@@ -301,7 +304,7 @@ struct bgp_static {
mpls_label_t label;
/* EVPN */
- struct eth_segment_id *eth_s_id;
+ esi_t *eth_s_id;
struct ethaddr *router_mac;
uint16_t encap_tunneltype;
struct prefix gatewayIp;
@@ -618,13 +621,13 @@ extern struct bgp_path_info *info_make(int type, int sub_type,
extern void route_vty_out(struct vty *vty, const struct prefix *p,
struct bgp_path_info *path, int display, safi_t safi,
- json_object *json_paths);
+ json_object *json_paths, bool wide);
extern void route_vty_out_tag(struct vty *vty, const struct prefix *p,
struct bgp_path_info *path, int display,
safi_t safi, json_object *json);
extern void route_vty_out_tmp(struct vty *vty, const struct prefix *p,
struct attr *attr, safi_t safi, bool use_json,
- json_object *json_ar);
+ json_object *json_ar, bool wide);
extern void route_vty_out_overlay(struct vty *vty, const struct prefix *p,
struct bgp_path_info *path, int display,
json_object *json);
@@ -679,4 +682,6 @@ extern int bgp_best_path_select_defer(struct bgp *bgp, afi_t afi, safi_t safi);
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);
#endif /* _QUAGGA_BGP_ROUTE_H */
diff --git a/bgpd/bgp_snmp.c b/bgpd/bgp_snmp.c
index 719ff1452b..303f4ca56e 100644
--- a/bgpd/bgp_snmp.c
+++ b/bgpd/bgp_snmp.c
@@ -356,17 +356,16 @@ static struct peer *peer_lookup_addr_ipv4(struct in_addr *src)
struct bgp *bgp;
struct peer *peer;
struct listnode *node;
+ struct listnode *bgpnode;
- bgp = bgp_get_default();
- if (!bgp)
- return NULL;
+ 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)
+ continue;
- for (ALL_LIST_ELEMENTS_RO(bgp->peer, node, peer)) {
- if (sockunion_family(&peer->su) != AF_INET)
- continue;
-
- if (sockunion2ip(&peer->su) == src->s_addr)
- return peer;
+ if (sockunion2ip(&peer->su) == src->s_addr)
+ return peer;
+ }
}
return NULL;
@@ -378,21 +377,20 @@ static struct peer *bgp_peer_lookup_next(struct in_addr *src)
struct peer *peer;
struct peer *next_peer = NULL;
struct listnode *node;
-
- bgp = bgp_get_default();
- if (!bgp)
- return NULL;
-
- for (ALL_LIST_ELEMENTS_RO(bgp->peer, node, peer)) {
- if (sockunion_family(&peer->su) != AF_INET)
- continue;
- if (ntohl(sockunion2ip(&peer->su)) <= ntohl(src->s_addr))
- continue;
-
- if (!next_peer
- || ntohl(sockunion2ip(&next_peer->su))
- > ntohl(sockunion2ip(&peer->su))) {
- next_peer = peer;
+ struct listnode *bgpnode;
+
+ 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)
+ continue;
+ if (ntohl(sockunion2ip(&peer->su)) <= ntohl(src->s_addr))
+ continue;
+
+ if (!next_peer
+ || ntohl(sockunion2ip(&next_peer->su))
+ > ntohl(sockunion2ip(&peer->su))) {
+ next_peer = peer;
+ }
}
}
diff --git a/bgpd/bgp_table.h b/bgpd/bgp_table.h
index a9ec36d29b..cf0086b52e 100644
--- a/bgpd/bgp_table.h
+++ b/bgpd/bgp_table.h
@@ -51,6 +51,8 @@ enum bgp_path_selection_reason {
bgp_path_selection_first,
bgp_path_selection_evpn_sticky_mac,
bgp_path_selection_evpn_seq,
+ bgp_path_selection_evpn_local_path,
+ bgp_path_selection_evpn_non_proxy,
bgp_path_selection_evpn_lower_ip,
bgp_path_selection_weight,
bgp_path_selection_local_pref,
diff --git a/bgpd/bgp_updgrp_adv.c b/bgpd/bgp_updgrp_adv.c
index e8e9b33d4b..ecdcaa38b8 100644
--- a/bgpd/bgp_updgrp_adv.c
+++ b/bgpd/bgp_updgrp_adv.c
@@ -262,14 +262,15 @@ static void subgrp_show_adjq_vty(struct update_subgroup *subgrp,
route_vty_out_tmp(vty, dest_p,
adj->adv->baa->attr,
SUBGRP_SAFI(subgrp),
- 0, NULL);
+ 0, NULL, false);
output_count++;
}
if ((flags & UPDWALK_FLAGS_ADVERTISED)
&& adj->attr) {
- route_vty_out_tmp(
- vty, dest_p, adj->attr,
- SUBGRP_SAFI(subgrp), 0, NULL);
+ route_vty_out_tmp(vty, dest_p,
+ adj->attr,
+ SUBGRP_SAFI(subgrp),
+ 0, NULL, false);
output_count++;
}
}
diff --git a/bgpd/bgp_updgrp_packet.c b/bgpd/bgp_updgrp_packet.c
index 4de5ec3b04..5df9e3f23f 100644
--- a/bgpd/bgp_updgrp_packet.c
+++ b/bgpd/bgp_updgrp_packet.c
@@ -574,6 +574,18 @@ struct stream *bpacket_reformat_for_peer(struct bpacket *pkt,
gnh_modified = 1;
}
+ if (IN6_IS_ADDR_UNSPECIFIED(mod_v6nhg)) {
+ if (peer->nexthop.v4.s_addr) {
+ ipv4_to_ipv4_mapped_ipv6(mod_v6nhg,
+ peer->nexthop.v4);
+ }
+ }
+
+ if (IS_MAPPED_IPV6(&peer->nexthop.v6_global)) {
+ mod_v6nhg = &peer->nexthop.v6_global;
+ gnh_modified = 1;
+ }
+
if (nhlen == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
|| nhlen == BGP_ATTR_NHLEN_VPNV6_GLOBAL_AND_LL) {
stream_get_from(&v6nhlocal, s, offset_nhlocal,
diff --git a/bgpd/bgp_vpn.c b/bgpd/bgp_vpn.c
index c8b8e2391d..0b5d156e6d 100644
--- a/bgpd/bgp_vpn.c
+++ b/bgpd/bgp_vpn.c
@@ -226,7 +226,7 @@ int show_adj_route_vpn(struct vty *vty, struct peer *peer,
rd_header = 0;
}
route_vty_out_tmp(vty, bgp_dest_get_prefix(rm), attr,
- safi, use_json, json_routes);
+ safi, use_json, json_routes, false);
output_count++;
}
diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c
index e07c990ab7..0268b7ec9d 100644
--- a/bgpd/bgp_vty.c
+++ b/bgpd/bgp_vty.c
@@ -65,6 +65,7 @@
#include "bgpd/bgp_io.h"
#include "bgpd/bgp_evpn.h"
#include "bgpd/bgp_evpn_vty.h"
+#include "bgpd/bgp_evpn_mh.h"
#include "bgpd/bgp_addpath.h"
#include "bgpd/bgp_mac.h"
#include "bgpd/bgp_flowspec.h"
@@ -1093,7 +1094,8 @@ DEFUN_HIDDEN (bgp_local_mac,
return CMD_WARNING;
}
- rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq);
+ rv = bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, 0 /* flags */, seq,
+ zero_esi);
if (rv < 0) {
vty_out(vty, "Internal error\n");
return CMD_WARNING;
@@ -4388,7 +4390,7 @@ DEFUN (neighbor_shutdown_msg,
NEIGHBOR_STR
NEIGHBOR_ADDR_STR2
"Administratively shut down this neighbor\n"
- "Add a shutdown message (draft-ietf-idr-shutdown-06)\n"
+ "Add a shutdown message (RFC 8203)\n"
"Shutdown message\n")
{
int idx_peer = 1;
@@ -4420,7 +4422,7 @@ DEFUN (no_neighbor_shutdown_msg,
NEIGHBOR_STR
NEIGHBOR_ADDR_STR2
"Administratively shut down this neighbor\n"
- "Remove a shutdown message (draft-ietf-idr-shutdown-06)\n"
+ "Remove a shutdown message (RFC 8203)\n"
"Shutdown message\n")
{
int idx_peer = 2;
@@ -10881,10 +10883,9 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
p->group, &prefix);
if (range) {
- prefix2str(range, buf1, sizeof(buf1));
vty_out(vty,
- " Belongs to the subnet range group: %s\n",
- buf1);
+ " Belongs to the subnet range group: %pFX\n",
+ range);
}
}
}
diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c
index 518532cb51..87936f1dd6 100644
--- a/bgpd/bgp_zebra.c
+++ b/bgpd/bgp_zebra.c
@@ -60,6 +60,7 @@
#include "bgpd/bgp_labelpool.h"
#include "bgpd/bgp_pbr.h"
#include "bgpd/bgp_evpn_private.h"
+#include "bgpd/bgp_evpn_mh.h"
#include "bgpd/bgp_mac.h"
/* All information about zebra. */
@@ -1143,8 +1144,7 @@ static bool update_ipv6nh_for_route_install(int nh_othervrf, struct bgp *nh_bgp,
api_nh->ifindex = 0;
}
}
- if (nexthop)
- api_nh->gate.ipv6 = *nexthop;
+ api_nh->gate.ipv6 = *nexthop;
return true;
}
@@ -1178,7 +1178,7 @@ 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;
+ struct zapi_route api = { 0 };
struct zapi_nexthop *api_nh;
int nh_family;
unsigned int valid_nh_count = 0;
@@ -1224,7 +1224,6 @@ void bgp_zebra_announce(struct bgp_dest *dest, const struct prefix *p,
nh_othervrf = 1;
/* Make Zebra API structure. */
- memset(&api, 0, sizeof(api));
api.vrf_id = bgp->vrf_id;
api.type = ZEBRA_ROUTE_BGP;
api.safi = safi;
@@ -2500,17 +2499,66 @@ static void bgp_zebra_connected(struct zclient *zclient)
BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer);
}
-static int bgp_zebra_process_local_es(ZAPI_CALLBACK_ARGS)
+static int bgp_zebra_process_local_es_add(ZAPI_CALLBACK_ARGS)
+{
+ esi_t esi;
+ struct bgp *bgp = NULL;
+ struct stream *s = NULL;
+ char buf[ESI_STR_LEN];
+ struct in_addr originator_ip;
+ uint8_t active;
+
+ bgp = bgp_lookup_by_vrf_id(vrf_id);
+ if (!bgp)
+ return 0;
+
+ s = zclient->ibuf;
+ stream_get(&esi, s, sizeof(esi_t));
+ originator_ip.s_addr = stream_get_ipv4(s);
+ active = stream_getc(s);
+
+ if (BGP_DEBUG(zebra, ZEBRA))
+ zlog_debug("Rx add ESI %s originator-ip %s active %u",
+ esi_to_str(&esi, buf, sizeof(buf)),
+ inet_ntoa(originator_ip),
+ active);
+
+ bgp_evpn_local_es_add(bgp, &esi, originator_ip, active);
+
+ return 0;
+}
+
+static int bgp_zebra_process_local_es_del(ZAPI_CALLBACK_ARGS)
{
esi_t esi;
struct bgp *bgp = NULL;
struct stream *s = NULL;
char buf[ESI_STR_LEN];
- char buf1[INET6_ADDRSTRLEN];
- struct ipaddr originator_ip;
memset(&esi, 0, sizeof(esi_t));
- memset(&originator_ip, 0, sizeof(struct ipaddr));
+ bgp = bgp_lookup_by_vrf_id(vrf_id);
+ if (!bgp)
+ return 0;
+
+ s = zclient->ibuf;
+ stream_get(&esi, s, sizeof(esi_t));
+
+ if (BGP_DEBUG(zebra, ZEBRA))
+ zlog_debug("Rx del ESI %s",
+ esi_to_str(&esi, buf, sizeof(buf)));
+
+ bgp_evpn_local_es_del(bgp, &esi);
+
+ return 0;
+}
+
+static int bgp_zebra_process_local_es_evi(ZAPI_CALLBACK_ARGS)
+{
+ esi_t esi;
+ vni_t vni;
+ struct bgp *bgp;
+ struct stream *s;
+ char buf[ESI_STR_LEN];
bgp = bgp_lookup_by_vrf_id(vrf_id);
if (!bgp)
@@ -2518,18 +2566,18 @@ static int bgp_zebra_process_local_es(ZAPI_CALLBACK_ARGS)
s = zclient->ibuf;
stream_get(&esi, s, sizeof(esi_t));
- stream_get(&originator_ip, s, sizeof(struct ipaddr));
+ vni = stream_getl(s);
if (BGP_DEBUG(zebra, ZEBRA))
- zlog_debug("Rx %s ESI %s originator-ip %s",
- (cmd == ZEBRA_LOCAL_ES_ADD) ? "add" : "del",
- esi_to_str(&esi, buf, sizeof(buf)),
- ipaddr2str(&originator_ip, buf1, sizeof(buf1)));
+ zlog_debug("Rx %s ESI %s VNI %u",
+ ZEBRA_VNI_ADD ? "add" : "del",
+ esi_to_str(&esi, buf, sizeof(buf)), vni);
- if (cmd == ZEBRA_LOCAL_ES_ADD)
- bgp_evpn_local_es_add(bgp, &esi, &originator_ip);
+ if (cmd == ZEBRA_LOCAL_ES_EVI_ADD)
+ bgp_evpn_local_es_evi_add(bgp, &esi, vni);
else
- bgp_evpn_local_es_del(bgp, &esi, &originator_ip);
+ bgp_evpn_local_es_evi_del(bgp, &esi, vni);
+
return 0;
}
@@ -2629,6 +2677,8 @@ static int bgp_zebra_process_local_macip(ZAPI_CALLBACK_ARGS)
uint8_t flags = 0;
uint32_t seqnum = 0;
int state = 0;
+ char buf2[ESI_STR_LEN];
+ esi_t esi;
memset(&ip, 0, sizeof(ip));
s = zclient->ibuf;
@@ -2652,6 +2702,7 @@ static int bgp_zebra_process_local_macip(ZAPI_CALLBACK_ARGS)
if (cmd == ZEBRA_MACIP_ADD) {
flags = stream_getc(s);
seqnum = stream_getl(s);
+ stream_get(&esi, s, sizeof(esi_t));
} else {
state = stream_getl(s);
}
@@ -2661,15 +2712,15 @@ static int bgp_zebra_process_local_macip(ZAPI_CALLBACK_ARGS)
return 0;
if (BGP_DEBUG(zebra, ZEBRA))
- zlog_debug("%u:Recv MACIP %s flags 0x%x MAC %s IP %s VNI %u seq %u state %d",
+ zlog_debug("%u:Recv MACIP %s f 0x%x MAC %s IP %s VNI %u seq %u state %d ESI %s",
vrf_id, (cmd == ZEBRA_MACIP_ADD) ? "Add" : "Del",
flags, prefix_mac2str(&mac, buf, sizeof(buf)),
ipaddr2str(&ip, buf1, sizeof(buf1)), vni, seqnum,
- state);
+ state, esi_to_str(&esi, buf2, sizeof(buf2)));
if (cmd == ZEBRA_MACIP_ADD)
return bgp_evpn_local_macip_add(bgp, vni, &mac, &ip,
- flags, seqnum);
+ flags, seqnum, &esi);
else
return bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, state);
}
@@ -2802,9 +2853,11 @@ void bgp_zebra_init(struct thread_master *master, unsigned short instance)
zclient->nexthop_update = bgp_read_nexthop_update;
zclient->import_check_update = bgp_read_import_check_update;
zclient->fec_update = bgp_read_fec_update;
- zclient->local_es_add = bgp_zebra_process_local_es;
- zclient->local_es_del = bgp_zebra_process_local_es;
+ zclient->local_es_add = bgp_zebra_process_local_es_add;
+ zclient->local_es_del = bgp_zebra_process_local_es_del;
zclient->local_vni_add = bgp_zebra_process_local_vni;
+ zclient->local_es_evi_add = bgp_zebra_process_local_es_evi;
+ zclient->local_es_evi_del = bgp_zebra_process_local_es_evi;
zclient->local_vni_del = bgp_zebra_process_local_vni;
zclient->local_macip_add = bgp_zebra_process_local_macip;
zclient->local_macip_del = bgp_zebra_process_local_macip;
diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c
index e11ac459f2..c9e6fd2ac0 100644
--- a/bgpd/bgpd.c
+++ b/bgpd/bgpd.c
@@ -87,6 +87,7 @@
#include "bgpd/bgp_pbr.h"
#include "bgpd/bgp_addpath.h"
#include "bgpd/bgp_evpn_private.h"
+#include "bgpd/bgp_evpn_mh.h"
#include "bgpd/bgp_mac.h"
DEFINE_MTYPE_STATIC(BGPD, PEER_TX_SHUTDOWN_MSG, "Peer shutdown message (TX)");
@@ -1227,6 +1228,10 @@ struct peer *peer_new(struct bgp *bgp)
peer->addpath_type[afi][safi] = BGP_ADDPATH_NONE;
}
+ /* set nexthop-unchanged for l2vpn evpn by default */
+ SET_FLAG(peer->af_flags[AFI_L2VPN][SAFI_EVPN],
+ PEER_FLAG_NEXTHOP_UNCHANGED);
+
SET_FLAG(peer->sflags, PEER_STATUS_CAPABILITY_OPEN);
/* Initialize per peer bgp GR FSM */
@@ -2174,14 +2179,6 @@ int peer_deactivate(struct peer *peer, afi_t afi, safi_t safi)
return ret;
}
-int peer_afc_set(struct peer *peer, afi_t afi, safi_t safi, int enable)
-{
- if (enable)
- return peer_activate(peer, afi, safi);
- else
- return peer_deactivate(peer, afi, safi);
-}
-
void peer_nsf_stop(struct peer *peer)
{
afi_t afi;
@@ -6943,6 +6940,7 @@ void bgp_master_init(struct thread_master *master, const int buffer_size)
/* mpls label dynamic allocation pool */
bgp_lp_init(bm->master, &bm->labelpool);
+ bgp_evpn_mh_init();
QOBJ_REG(bm, bgp_master);
}
@@ -7142,6 +7140,7 @@ void bgp_terminate(void)
BGP_TIMER_OFF(bm->t_rmap_update);
bgp_mac_finish();
+ bgp_evpn_mh_finish();
}
struct peer *peer_lookup_in_view(struct vty *vty, struct bgp *bgp,
diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h
index 4efc068dea..966de87830 100644
--- a/bgpd/bgpd.h
+++ b/bgpd/bgpd.h
@@ -165,6 +165,9 @@ struct bgp_master {
/* How big should we set the socket buffer size */
uint32_t socket_buffer;
+ /* EVPN multihoming */
+ struct bgp_evpn_mh_info *mh_info;
+
bool terminating; /* global flag that sigint terminate seen */
QOBJ_FIELDS
};
@@ -661,9 +664,6 @@ struct bgp {
struct bgp_pbr_config *bgp_pbr_cfg;
- /* local esi hash table */
- struct hash *esihash;
-
/* Count of peers in established state */
uint32_t established_peers;
@@ -1838,7 +1838,6 @@ extern void peer_group_notify_unconfig(struct peer_group *group);
extern int peer_activate(struct peer *, afi_t, safi_t);
extern int peer_deactivate(struct peer *, afi_t, safi_t);
-extern int peer_afc_set(struct peer *, afi_t, safi_t, int);
extern int peer_group_bind(struct bgp *, union sockunion *, struct peer *,
struct peer_group *, as_t *);
diff --git a/bgpd/subdir.am b/bgpd/subdir.am
index 6b5c0fe719..a5393e25ac 100644
--- a/bgpd/subdir.am
+++ b/bgpd/subdir.am
@@ -15,6 +15,7 @@ vtysh_scan += \
bgpd/bgp_bfd.c \
bgpd/bgp_debug.c \
bgpd/bgp_dump.c \
+ bgpd/bgp_evpn_mh.c \
bgpd/bgp_evpn_vty.c \
bgpd/bgp_filter.c \
bgpd/bgp_mplsvpn.c \
@@ -65,6 +66,7 @@ bgpd_libbgp_a_SOURCES = \
bgpd/bgp_encap_tlv.c \
bgpd/bgp_errors.c \
bgpd/bgp_evpn.c \
+ bgpd/bgp_evpn_mh.c \
bgpd/bgp_evpn_vty.c \
bgpd/bgp_filter.c \
bgpd/bgp_flowspec.c \
@@ -139,6 +141,7 @@ noinst_HEADERS += \
bgpd/bgp_encap_types.h \
bgpd/bgp_errors.h \
bgpd/bgp_evpn.h \
+ bgpd/bgp_evpn_mh.h \
bgpd/bgp_evpn_private.h \
bgpd/bgp_evpn_vty.h \
bgpd/bgp_filter.h \
diff --git a/bgpd/valgrind.supp b/bgpd/valgrind.supp
index ed236a6dc5..31f2477a58 100644
--- a/bgpd/valgrind.supp
+++ b/bgpd/valgrind.supp
@@ -1,17 +1,18 @@
{
- <libyang_0.16.46>
+ <zlog_keep_working_at_exit>
Memcheck:Leak
+ match-leak-kinds: reachable
fun:calloc
- fun:_dlerror_run
- fun:dlopen@@GLIBC_2.2.5
- fun:ly_load_plugins_dir
- fun:ly_load_plugins
+ fun:qcalloc
+ fun:zlog_target_clone
}
{
- <zlog_keep_working_at_exit>
+ <libyang1_1.0.184>
Memcheck:Leak
match-leak-kinds: reachable
fun:calloc
- fun:qcalloc
- fun:zlog_target_clone
+ fun:_dlerror_run
+ fun:dlopen@@GLIBC_2.2.5
+ obj:/usr/lib/x86_64-linux-gnu/libyang.so.1.9.2
+ fun:ly_load_plugins
}
diff --git a/doc/developer/building-frr-for-openwrt.rst b/doc/developer/building-frr-for-openwrt.rst
index 5d8f82f27e..9bd1296dad 100644
--- a/doc/developer/building-frr-for-openwrt.rst
+++ b/doc/developer/building-frr-for-openwrt.rst
@@ -1,6 +1,8 @@
-OpenWRT
+OpenWrt
=======
+General info about OpenWrt buildsystem: `link <https://openwrt.org/docs/guide-developer/build-system/start>`_.
+
Prepare build environment
-------------------------
@@ -13,16 +15,16 @@ For Debian based distributions, run:
For other environments, instructions can be found in the
`official documentation
-<https://wiki.openwrt.org/doc/howto/buildroot.exigence#examples_of_package_installations>`_.
+<https://openwrt.org/docs/guide-developer/build-system/install-buildsystem#examples_of_package_installations>`_.
-Get OpenWRT Sources (from Git)
+Get OpenWrt Sources (from Git)
------------------------------
.. note::
- The OpenWRT build will fail if you run it as root. So take care to run it as a nonprivileged user.
+ The OpenWrt build will fail if you run it as root. So take care to run it as a nonprivileged user.
-Clone the OpenWRT sources and retrieve the package feeds
+Clone the OpenWrt sources and retrieve the package feeds
::
@@ -30,21 +32,15 @@ Clone the OpenWRT sources and retrieve the package feeds
cd openwrt
./scripts/feeds update -a
./scripts/feeds install -a
- cd feeds/routing
- git fetch origin pull/319/head
- git read-tree --prefix=frr/ -u FETCH_HEAD:frr
- cd ../../package/feeds/routing/
- ln -sv ../../../feeds/routing/frr .
- cd ../../..
-
-Configure OpenWRT for your target and select the needed FRR packages in Network -> Routing and Redirection -> frr,
+
+Configure OpenWrt for your target and select the needed FRR packages in Network -> Routing and Redirection -> frr,
exit and save
::
make menuconfig
-Then, to compile either a complete OpenWRT image, or the FRR packages, run:
+Then, to compile either a complete OpenWrt image, or the FRR packages, run:
::
@@ -54,10 +50,16 @@ It may be possible that on first build ``make package/frr/compile`` not
to work and it may be needed to run a ``make`` for the entire build
environment. Add ``V=s`` to get more debugging output.
+More information about OpenWrt buildsystem can be found `here
+<https://openwrt.org/docs/guide-developer/build-system/use-buildsystem>`_.
+
Work with sources
-----------------
-To update to a newer version, or change other options, you need to edit the ``feeds/routing/frr/Makefile``.
+To update to a newer version, or change other options, you need to edit the ``feeds/packages/frr/Makefile``.
+
+More information about working with patches in OpenWrt buildsystem can be found `here
+<https://openwrt.org/docs/guide-developer/build-system/use-patches-with-buildsystem>`_.
Usage
-----
diff --git a/doc/manpages/frr-watchfrr.rst b/doc/manpages/frr-watchfrr.rst
index dceb423f82..d8c82eafa9 100644
--- a/doc/manpages/frr-watchfrr.rst
+++ b/doc/manpages/frr-watchfrr.rst
@@ -35,6 +35,22 @@ OPTIONS
Set the VTY socket directory (the default value is "/var/run/frr").
+.. option:: -N <name>, --pathspace <name>
+
+ Insert the given name into paths used by the FRR daemons. This is appended
+ to the VTY socket directory and passed to the daemons which also add it to
+ their paths in /etc.
+
+.. option:: --netns[=<name>]
+
+ (Linux only.) Switch network namespaces when starting watchfrr. The name
+ defaults to the value passed with -N (which it should be used in conjunction
+ with.) If the name is not specified, the option has no effect.
+
+ If the network namespace does not exist, it is created in a manner
+ compatible with iproute2. Network namespaces are not removed by FRR, this
+ must be done with "ip netns delete".
+
.. option:: -l <level>, --loglevel <level>
Set the logging level (the default value is "6"). The value should range from 0 (LOG_EMERG) to 7 (LOG_DEBUG), but higher number can be supplied if extra debugging messages are required.
diff --git a/doc/user/bfd.rst b/doc/user/bfd.rst
index 618d90a85e..47792317ad 100644
--- a/doc/user/bfd.rst
+++ b/doc/user/bfd.rst
@@ -254,7 +254,7 @@ IS-IS BFD Configuration
The following commands are available inside the interface configuration node.
.. index:: isis bfd
-.. clicmd:: ip isis bfd
+.. clicmd:: isis bfd
Listen for BFD events on peers created on the interface. Every time
a new neighbor is found a BFD peer is created to monitor the link
@@ -269,6 +269,15 @@ The following commands are available inside the interface configuration node.
IPv4 and IPv6 support are configured then just a IPv6 based session is
created.
+.. index:: isis bfd profile BFDPROF
+.. clicmd:: isis bfd profile BFDPROF
+
+ Use a BFD profile BFDPROF as provided in the BFD configuration.
+
+.. index:: no isis bfd profile BFDPROF
+.. clicmd:: no isis bfd profile BFDPROF
+
+ Removes any BFD profile if present.
.. _bfd-ospf-peer-config:
diff --git a/doc/user/bgp.rst b/doc/user/bgp.rst
index bb968735b9..db0776adba 100644
--- a/doc/user/bgp.rst
+++ b/doc/user/bgp.rst
@@ -1191,19 +1191,28 @@ Defining Peers
``net.core.optmem_max`` to allow the kernel to allocate the necessary option
memory.
+.. index:: [no] coalesce-time (0-4294967295)
+.. clicmd:: [no] coalesce-time (0-4294967295)
+
+ The time in milliseconds that BGP will delay before deciding what peers
+ can be put into an update-group together in order to generate a single
+ update for them. The default time is 1000.
+
.. _bgp-configuring-peers:
Configuring Peers
^^^^^^^^^^^^^^^^^
-.. index:: [no] neighbor PEER shutdown
-.. clicmd:: [no] neighbor PEER shutdown
+.. index:: [no] neighbor PEER shutdown [message MSG...]
+.. clicmd:: [no] neighbor PEER shutdown [message MSG...]
Shutdown the peer. We can delete the neighbor's configuration by
``no neighbor PEER remote-as ASN`` but all configuration of the neighbor
will be deleted. When you want to preserve the configuration, but want to
drop the BGP peer, use this syntax.
+ Optionally you can specify a shutdown message `MSG`.
+
.. index:: [no] neighbor PEER disable-connected-check
.. clicmd:: [no] neighbor PEER disable-connected-check
@@ -1334,6 +1343,49 @@ Configuring Peers
This command is only allowed for eBGP peers.
+.. index:: [no] neighbor <A.B.C.D|X:X::X:X|WORD> as-override
+.. clicmd:: [no] neighbor <A.B.C.D|X:X::X:X|WORD> as-override
+
+ Override AS number of the originating router with the local AS number.
+
+ Usually this configuration is used in PEs (Provider Edge) to replace
+ the incoming customer AS number so the connected CE (Customer Edge)
+ can use the same AS number as the other customer sites. This allows
+ customers of the provider network to use the same AS number across
+ their sites.
+
+ This command is only allowed for eBGP peers.
+
+.. index:: [no] neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]
+.. clicmd:: [no] neighbor <A.B.C.D|X:X::X:X|WORD> allowas-in [<(1-10)|origin>]
+
+ Accept incoming routes with AS path containing AS number with the same value
+ as the current system AS.
+
+ This is used when you want to use the same AS number in your sites, but you
+ can't connect them directly. This is an alternative to
+ `neighbor WORD as-override`.
+
+ The parameter `(1-10)` configures the amount of accepted occurences of the
+ system AS number in AS path.
+
+ The parameter `origin` configures BGP to only accept routes originated with
+ the same AS number as the system.
+
+ This command is only allowed for eBGP peers.
+
+.. index:: [no] neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths
+.. clicmd:: [no] neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-all-paths
+
+ Configure BGP to send all known paths to neighbor in order to preserve multi
+ path capabilities inside a network.
+
+.. index:: [no] neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS
+.. clicmd:: [no] neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-bestpath-per-AS
+
+ Configure BGP to send best known paths to neighbor in order to preserve multi
+ path capabilities inside a network.
+
.. index:: [no] neighbor PEER ttl-security hops NUMBER
.. clicmd:: [no] neighbor PEER ttl-security hops NUMBER
@@ -1386,6 +1438,15 @@ Configuring Peers
peer in question. This number is between 0 and 600 seconds,
with the default advertisement interval being 0.
+Displaying Information about Peers
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+.. index:: show bgp <afi> <safi> neighbors WORD bestpath-routes [json] [wide]
+.. clicmd:: show bgp <afi> <safi> neighbors WORD bestpath-routes [json] [wide]
+
+ For the given neighbor, WORD, that is specified list the routes selected
+ by BGP as having the best path.
+
.. _bgp-peer-filtering:
Peer Filtering
@@ -2404,92 +2465,6 @@ the same behavior of using same next-hop and RMAC values.
Enables or disables advertise-pip feature, specifiy system-IP and/or system-MAC
parameters.
-Support with VRF network namespace backend
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-It is possible to separate overlay networks contained in VXLAN interfaces from
-underlay networks by using VRFs. VRF-lite and VRF-netns backends can be used for
-that. In the latter case, this is necessary to set both bridge and vxlan interface
-on the same network namespace, as below example illustrates:
-
-.. code-block:: shell
-
- # linux shell
- ip netns add vrf1
- ip link add name vxlan101 type vxlan id 101 dstport 4789 dev eth0 local 10.1.1.1
- ip link set dev vxlan101 netns vrf1
- ip netns exec vrf1 ip link set dev lo up
- ip netns exec vrf1 brctl addbr bridge101
- ip netns exec vrf1 brctl addif bridge101 vxlan101
-
-This makes possible to separate not only layer 3 networks like VRF-lite networks.
-Also, VRF netns based make possible to separate layer 2 networks on separate VRF
-instances.
-
-.. _bgp-cisco-compatibility:
-
-Cisco Compatibility
--------------------
-
-FRR has commands that change some configuration syntax and default behavior to
-behave more closely to Cisco conventions. These are deprecated and will be
-removed in a future version of FRR.
-
-.. deprecated:: 5.0
- Please transition to using the FRR specific syntax for your configuration.
-
-.. index:: bgp config-type cisco
-.. clicmd:: bgp config-type cisco
-
- Cisco compatible BGP configuration output.
-
- When this configuration line is specified:
-
- - ``no synchronization`` is displayed. This command does nothing and is for
- display purposes only.
- - ``no auto-summary`` is displayed.
- - The ``network`` and ``aggregate-address`` arguments are displayed as:
-
- ::
-
- A.B.C.D M.M.M.M
-
- FRR: network 10.0.0.0/8
- Cisco: network 10.0.0.0
-
- FRR: aggregate-address 192.168.0.0/24
- Cisco: aggregate-address 192.168.0.0 255.255.255.0
-
- Community attribute handling is also different. If no configuration is
- specified community attribute and extended community attribute are sent to
- the neighbor. If a user manually disables the feature, the community
- attribute is not sent to the neighbor. When ``bgp config-type cisco`` is
- specified, the community attribute is not sent to the neighbor by default.
- To send the community attribute user has to specify
- :clicmd:`neighbor A.B.C.D send-community` like so:
-
- .. code-block:: frr
-
- !
- router bgp 1
- neighbor 10.0.0.1 remote-as 1
- address-family ipv4 unicast
- no neighbor 10.0.0.1 send-community
- exit-address-family
- !
- router bgp 1
- neighbor 10.0.0.1 remote-as 1
- address-family ipv4 unicast
- neighbor 10.0.0.1 send-community
- exit-address-family
- !
-
-.. deprecated:: 5.0
- Please transition to using the FRR specific syntax for your configuration.
-
-.. index:: bgp config-type zebra
-.. clicmd:: bgp config-type zebra
-
- FRR style BGP configuration. This is the default.
.. _bgp-debugging:
@@ -2671,17 +2646,17 @@ daemon project, while :clicmd:`show bgp` command is the new format. The choice
has been done to keep old format with IPv4 routing table, while new format
displays IPv6 routing table.
-.. index:: show ip bgp
-.. clicmd:: show ip bgp
+.. index:: show ip bgp [wide]
+.. clicmd:: show ip bgp [wide]
-.. index:: show ip bgp A.B.C.D
-.. clicmd:: show ip bgp A.B.C.D
+.. index:: show ip bgp A.B.C.D [wide]
+.. clicmd:: show ip bgp A.B.C.D [wide]
-.. index:: show bgp
-.. clicmd:: show bgp
+.. index:: show bgp [wide]
+.. clicmd:: show bgp [wide]
-.. index:: show bgp X:X::X:X
-.. clicmd:: show bgp X:X::X:X
+.. index:: show bgp X:X::X:X [wide]
+.. clicmd:: show bgp X:X::X:X [wide]
These commands display BGP routes. When no route is specified, the default
is to display all BGP routes.
@@ -2697,6 +2672,12 @@ displays IPv6 routing table.
Total number of prefixes 1
+ If _wide_ option is specified, then the prefix table's width is increased
+ to fully display the prefix and the nexthop.
+
+ This is especially handy dealing with IPv6 prefixes and
+ if :clicmd:`[no] bgp default show-nexthop-hostname` is enabled.
+
Some other commands provide additional options for filtering the output.
.. index:: show [ip] bgp regexp LINE
diff --git a/doc/user/ospf6d.rst b/doc/user/ospf6d.rst
index cd095af862..6295ba9293 100644
--- a/doc/user/ospf6d.rst
+++ b/doc/user/ospf6d.rst
@@ -20,8 +20,11 @@ OSPF6 router
Set router's Router-ID.
-.. index:: interface IFNAME area AREA
-.. clicmd:: interface IFNAME area AREA
+.. index:: interface IFNAME area (0-4294967295)
+.. clicmd:: interface IFNAME area (0-4294967295)
+
+.. index:: interface IFNAME area A.B.C.D
+.. clicmd:: interface IFNAME area A.B.C.D
Bind interface to specified area, and start sending OSPF packets. `area` can
be specified as 0.
diff --git a/doc/user/overview.rst b/doc/user/overview.rst
index adc20936ed..ac6a1e5a8c 100644
--- a/doc/user/overview.rst
+++ b/doc/user/overview.rst
@@ -290,6 +290,8 @@ BGP
:t:`A Border Gateway Protocol 4 (BGP-4). Updates RFC1771. Y. Rekhter, T. Li & S. Hares. January 2006.`
- :rfc:`4364`
:t:`BGP/MPLS IP Virtual Private Networks (VPNs). Y. Rekhter. Feb 2006.`
+- :rfc:`4486`
+ :t:`Subcodes for BGP Cease Notification Message. E. Chen, V. Gillet. April 2006.`
- :rfc:`4659`
:t:`BGP-MPLS IP Virtual Private Network (VPN) Extension for IPv6 VPN. J. De Clercq, D. Ooms, M. Carugi, F. Le Faucheur. September 2006.`
- :rfc:`4893`
@@ -320,6 +322,8 @@ BGP
:t:`BGP Large Communities Attribute. J. Heitz, Ed., J. Snijders, Ed, K. Patel, I. Bagdonas, N. Hilliard. February 2017`
- :rfc:`8195`
:t:`Use of BGP Large Communities. J. Snijders, J. Heasley, M. Schmidt, June 2017`
+- :rfc:`8203`
+ :t:`BGP Administrative Shutdown Communication. J. Snijders, J. Heitz, J. Scudder. July 2017.`
- :rfc:`8212`
:t:`Default External BGP (EBGP) Route Propagation Behavior without Policies. J. Mauch, J. Snijders, G. Hankins. July 2017`
- :rfc:`8277`
diff --git a/doc/user/pbr.rst b/doc/user/pbr.rst
index 149949e863..99ef258cb2 100644
--- a/doc/user/pbr.rst
+++ b/doc/user/pbr.rst
@@ -123,6 +123,22 @@ end destination.
on another platform it will be denied. This mark translates 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.
+
+ 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.
+
+.. 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.
+
.. clicmd:: set nexthop-group NAME
Use the nexthop-group NAME as the place to forward packets when the match
diff --git a/doc/user/pim.rst b/doc/user/pim.rst
index 919dc51f69..d30a5ed647 100644
--- a/doc/user/pim.rst
+++ b/doc/user/pim.rst
@@ -252,6 +252,13 @@ is in a vrf, enter the interface command with the vrf keyword at the end.
reports on the interface. Refer to the next `ip igmp` command for IGMP
management.
+.. index:: [no] ip pim use-source A.B.C.D
+.. clicmd:: [no] ip pim use-source A.B.C.D
+
+ If you have multiple addresses configured on a particular interface
+ and would like pim to use a specific source address associated with
+ that interface.
+
.. index:: ip igmp
.. clicmd:: ip igmp
diff --git a/doc/user/sharp.rst b/doc/user/sharp.rst
index 1c474193f2..76bdc48dc0 100644
--- a/doc/user/sharp.rst
+++ b/doc/user/sharp.rst
@@ -88,13 +88,13 @@ keyword. At present, no sharp commands will be preserved in the config.
may have been turned on.
.. index:: sharp lsp
-.. clicmd:: sharp lsp (0-100000) nexthop-group NAME [prefix A.B.C.D/M TYPE [instance (0-255)]]
+.. clicmd:: sharp lsp [update] (0-100000) nexthop-group NAME [prefix A.B.C.D/M TYPE [instance (0-255)]]
Install an LSP using the specified in-label, with nexthops as
- listed in nexthop-group ``NAME``. The LSP is installed as type
- ZEBRA_LSP_SHARP. If ``prefix`` is specified, an existing route with
- type ``TYPE`` (and optional ``instance`` id) will be updated to use
- the LSP.
+ listed in nexthop-group ``NAME``. If ``update`` is included, the
+ update path is used. The LSP is installed as type ZEBRA_LSP_SHARP.
+ If ``prefix`` is specified, an existing route with type ``TYPE``
+ (and optional ``instance`` id) will be updated to use the LSP.
.. index:: sharp remove lsp
.. clicmd:: sharp remove lsp (0-100000) nexthop-group NAME [prefix A.B.C.D/M TYPE [instance (0-255)]]
diff --git a/eigrpd/eigrp_cli.c b/eigrpd/eigrp_cli.c
index c76e067685..3610b3a869 100644
--- a/eigrpd/eigrp_cli.c
+++ b/eigrpd/eigrp_cli.c
@@ -37,7 +37,7 @@
/*
* XPath: /frr-eigrpd:eigrpd/instance
*/
-DEFPY_NOSH(
+DEFPY_YANG_NOSH(
router_eigrp,
router_eigrp_cmd,
"router eigrp (1-65535)$as [vrf NAME]",
@@ -61,7 +61,7 @@ DEFPY_NOSH(
return rv;
}
-DEFPY(
+DEFPY_YANG(
no_router_eigrp,
no_router_eigrp_cmd,
"no router eigrp (1-65535)$as [vrf NAME]",
@@ -101,7 +101,7 @@ void eigrp_cli_show_end_header(struct vty *vty, struct lyd_node *dnode)
/*
* XPath: /frr-eigrpd:eigrpd/instance/router-id
*/
-DEFPY(
+DEFPY_YANG(
eigrp_router_id,
eigrp_router_id_cmd,
"eigrp router-id A.B.C.D$addr",
@@ -113,7 +113,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
no_eigrp_router_id,
no_eigrp_router_id_cmd,
"no eigrp router-id [A.B.C.D]",
@@ -137,7 +137,7 @@ void eigrp_cli_show_router_id(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-eigrpd:eigrpd/instance/passive-interface
*/
-DEFPY(
+DEFPY_YANG(
eigrp_passive_interface,
eigrp_passive_interface_cmd,
"[no] passive-interface IFNAME",
@@ -166,7 +166,7 @@ void eigrp_cli_show_passive_interface(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-eigrpd:eigrpd/instance/active-time
*/
-DEFPY(
+DEFPY_YANG(
eigrp_timers_active,
eigrp_timers_active_cmd,
"timers active-time <(1-65535)$timer|disabled$disabled>",
@@ -184,7 +184,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
no_eigrp_timers_active,
no_eigrp_timers_active_cmd,
"no timers active-time [<(1-65535)|disabled>]",
@@ -209,7 +209,7 @@ void eigrp_cli_show_active_time(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-eigrpd:eigrpd/instance/variance
*/
-DEFPY(
+DEFPY_YANG(
eigrp_variance,
eigrp_variance_cmd,
"variance (1-128)$variance",
@@ -220,7 +220,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
no_eigrp_variance,
no_eigrp_variance_cmd,
"no variance [(1-128)]",
@@ -243,7 +243,7 @@ void eigrp_cli_show_variance(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-eigrpd:eigrpd/instance/maximum-paths
*/
-DEFPY(
+DEFPY_YANG(
eigrp_maximum_paths,
eigrp_maximum_paths_cmd,
"maximum-paths (1-32)$maximum_paths",
@@ -255,7 +255,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
no_eigrp_maximum_paths,
no_eigrp_maximum_paths_cmd,
"no maximum-paths [(1-32)]",
@@ -283,7 +283,7 @@ void eigrp_cli_show_maximum_paths(struct vty *vty, struct lyd_node *dnode,
* XPath: /frr-eigrpd:eigrpd/instance/metric-weights/K5
* XPath: /frr-eigrpd:eigrpd/instance/metric-weights/K6
*/
-DEFPY(
+DEFPY_YANG(
eigrp_metric_weights,
eigrp_metric_weights_cmd,
"metric weights (0-255)$k1 (0-255)$k2 (0-255)$k3 (0-255)$k4 (0-255)$k5 [(0-255)$k6]",
@@ -308,7 +308,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
no_eigrp_metric_weights,
no_eigrp_metric_weights_cmd,
"no metric weights [(0-255) (0-255) (0-255) (0-255) (0-255) (0-255)]",
@@ -359,7 +359,7 @@ void eigrp_cli_show_metrics(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-eigrpd:eigrpd/instance/network
*/
-DEFPY(
+DEFPY_YANG(
eigrp_network,
eigrp_network_cmd,
"[no] network A.B.C.D/M$prefix",
@@ -388,7 +388,7 @@ void eigrp_cli_show_network(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-eigrpd:eigrpd/instance/neighbor
*/
-DEFPY(
+DEFPY_YANG(
eigrp_neighbor,
eigrp_neighbor_cmd,
"[no] neighbor A.B.C.D$addr",
@@ -423,7 +423,7 @@ void eigrp_cli_show_neighbor(struct vty *vty, struct lyd_node *dnode,
* XPath: /frr-eigrpd:eigrpd/instance/redistribute/metrics/load
* XPath: /frr-eigrpd:eigrpd/instance/redistribute/metrics/mtu
*/
-DEFPY(
+DEFPY_YANG(
eigrp_redistribute_source_metric,
eigrp_redistribute_source_metric_cmd,
"[no] redistribute " FRR_REDIST_STR_EIGRPD
@@ -493,7 +493,7 @@ void eigrp_cli_show_redistribute(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-interface:lib/interface/frr-eigrpd:eigrp/delay
*/
-DEFPY(
+DEFPY_YANG(
eigrp_if_delay,
eigrp_if_delay_cmd,
"delay (1-16777215)$delay",
@@ -505,7 +505,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
no_eigrp_if_delay,
no_eigrp_if_delay_cmd,
"no delay [(1-16777215)]",
@@ -529,7 +529,7 @@ void eigrp_cli_show_delay(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-interface:lib/interface/frr-eigrpd:eigrp/bandwidth
*/
-DEFPY(
+DEFPY_YANG(
eigrp_if_bandwidth,
eigrp_if_bandwidth_cmd,
"eigrp bandwidth (1-10000000)$bw",
@@ -542,7 +542,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
no_eigrp_if_bandwidth,
no_eigrp_if_bandwidth_cmd,
"no eigrp bandwidth [(1-10000000)]",
@@ -567,7 +567,7 @@ void eigrp_cli_show_bandwidth(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-interface:lib/interface/frr-eigrpd:eigrp/hello-interval
*/
-DEFPY(
+DEFPY_YANG(
eigrp_if_ip_hellointerval,
eigrp_if_ip_hellointerval_cmd,
"ip hello-interval eigrp (1-65535)$hello",
@@ -581,7 +581,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
no_eigrp_if_ip_hellointerval,
no_eigrp_if_ip_hellointerval_cmd,
"no ip hello-interval eigrp [(1-65535)]",
@@ -608,7 +608,7 @@ void eigrp_cli_show_hello_interval(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-interface:lib/interface/frr-eigrpd:eigrp/hold-time
*/
-DEFPY(
+DEFPY_YANG(
eigrp_if_ip_holdinterval,
eigrp_if_ip_holdinterval_cmd,
"ip hold-time eigrp (1-65535)$hold",
@@ -622,7 +622,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
no_eigrp_if_ip_holdinterval,
no_eigrp_if_ip_holdinterval_cmd,
"no ip hold-time eigrp [(1-65535)]",
@@ -654,7 +654,7 @@ void eigrp_cli_show_hold_time(struct vty *vty, struct lyd_node *dnode,
* XPath: /frr-interface:lib/interface/frr-eigrpd:eigrp/instance
* XPath: /frr-interface:lib/interface/frr-eigrpd:eigrp/instance/summarize-addresses
*/
-DEFPY(
+DEFPY_YANG(
eigrp_ip_summary_address,
eigrp_ip_summary_address_cmd,
"ip summary-address eigrp (1-65535)$as A.B.C.D/M$prefix",
@@ -676,7 +676,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
no_eigrp_ip_summary_address,
no_eigrp_ip_summary_address_cmd,
"no ip summary-address eigrp (1-65535)$as A.B.C.D/M$prefix",
@@ -714,7 +714,7 @@ void eigrp_cli_show_summarize_address(struct vty *vty, struct lyd_node *dnode,
* XPath: /frr-interface:lib/interface/frr-eigrpd:eigrp/instance
* XPath: /frr-interface:lib/interface/frr-eigrpd:eigrp/instance/authentication
*/
-DEFPY(
+DEFPY_YANG(
eigrp_authentication_mode,
eigrp_authentication_mode_cmd,
"ip authentication mode eigrp (1-65535)$as <md5|hmac-sha-256>$crypt",
@@ -738,7 +738,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
no_eigrp_authentication_mode,
no_eigrp_authentication_mode_cmd,
"no ip authentication mode eigrp (1-65535)$as [<md5|hmac-sha-256>]",
@@ -778,7 +778,7 @@ void eigrp_cli_show_authentication(struct vty *vty, struct lyd_node *dnode,
* XPath: /frr-interface:lib/interface/frr-eigrpd:eigrp/instance
* XPath: /frr-interface:lib/interface/frr-eigrpd:eigrp/instance/keychain
*/
-DEFPY(
+DEFPY_YANG(
eigrp_authentication_keychain,
eigrp_authentication_keychain_cmd,
"ip authentication key-chain eigrp (1-65535)$as WORD$name",
@@ -801,7 +801,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
no_eigrp_authentication_keychain,
no_eigrp_authentication_keychain_cmd,
"no ip authentication key-chain eigrp (1-65535)$as [WORD]",
diff --git a/include/linux/if_bridge.h b/include/linux/if_bridge.h
index fb79481cb2..50011d55ec 100644
--- a/include/linux/if_bridge.h
+++ b/include/linux/if_bridge.h
@@ -293,4 +293,15 @@ struct br_mcast_stats {
__u64 mcast_bytes[BR_MCAST_DIR_SIZE];
__u64 mcast_packets[BR_MCAST_DIR_SIZE];
};
+
+/* FDB notification bits for NDA_NOTIFY:
+ * - BR_FDB_NFY_STATIC - notify on activity/expire even for a static entry
+ * - BR_FDB_NFY_INACTIVE - mark as inactive to avoid double notification,
+ * used with BR_FDB_NFY_STATIC (kernel controlled)
+ */
+enum {
+ BR_FDB_NFY_STATIC,
+ BR_FDB_NFY_INACTIVE,
+ BR_FDB_NFY_MAX
+};
#endif /* _UAPI_LINUX_IF_BRIDGE_H */
diff --git a/include/linux/neighbour.h b/include/linux/neighbour.h
index cd144e3099..33c17af1cc 100644
--- a/include/linux/neighbour.h
+++ b/include/linux/neighbour.h
@@ -29,6 +29,8 @@ enum {
NDA_LINK_NETNSID,
NDA_SRC_VNI,
NDA_PROTOCOL, /* Originator of entry */
+ NDA_NH_ID,
+ NDA_NOTIFY,
__NDA_MAX
};
diff --git a/include/linux/net_namespace.h b/include/linux/net_namespace.h
index 0ed9dd61d3..0187c74d88 100644
--- a/include/linux/net_namespace.h
+++ b/include/linux/net_namespace.h
@@ -16,7 +16,6 @@ enum {
NETNSA_NSID,
NETNSA_PID,
NETNSA_FD,
- NETNSA_TARGET_NSID,
__NETNSA_MAX,
};
diff --git a/include/linux/nexthop.h b/include/linux/nexthop.h
index e4d6e256ef..ee2a15b9c7 100644
--- a/include/linux/nexthop.h
+++ b/include/linux/nexthop.h
@@ -50,6 +50,7 @@ enum {
*/
NHA_GROUPS, /* flag; only return nexthop groups in dump */
NHA_MASTER, /* u32; only return nexthops with given master dev */
+ NHA_FDB, /* nexthop belongs to a bridge fdb */
__NHA_MAX,
};
diff --git a/isisd/isis_bfd.c b/isisd/isis_bfd.c
index 69c971ee2c..5729994baa 100644
--- a/isisd/isis_bfd.c
+++ b/isisd/isis_bfd.c
@@ -255,6 +255,43 @@ static void bfd_debug(int family, union g_addr *dst, union g_addr *src,
command_str, dst_str, interface, src_str);
}
+static void bfd_command(int command, struct bfd_info *bfd_info, int family,
+ const void *dst_ip, const void *src_ip,
+ const char *if_name)
+{
+ struct bfd_session_arg args = {};
+ size_t addrlen;
+
+ args.cbit = 1;
+ args.family = family;
+ args.vrf_id = VRF_DEFAULT;
+ args.command = command;
+ args.bfd_info = bfd_info;
+ if (args.bfd_info) {
+ args.min_rx = bfd_info->required_min_rx;
+ args.min_tx = bfd_info->desired_min_tx;
+ args.detection_multiplier = bfd_info->detect_mult;
+ if (bfd_info->profile[0]) {
+ args.profilelen = strlen(bfd_info->profile);
+ strlcpy(args.profile, bfd_info->profile,
+ sizeof(args.profile));
+ }
+ }
+
+ addrlen = family == AF_INET ? sizeof(struct in_addr)
+ : sizeof(struct in6_addr);
+ memcpy(&args.dst, dst_ip, addrlen);
+ if (src_ip)
+ memcpy(&args.src, src_ip, addrlen);
+
+ if (if_name) {
+ strlcpy(args.ifname, if_name, sizeof(args.ifname));
+ args.ifnamelen = strlen(args.ifname);
+ }
+
+ zclient_bfd_command(zclient, &args);
+}
+
static void bfd_handle_adj_down(struct isis_adjacency *adj)
{
if (!adj->bfd_session)
@@ -264,17 +301,11 @@ static void bfd_handle_adj_down(struct isis_adjacency *adj)
&adj->bfd_session->src_ip, adj->circuit->interface->name,
ZEBRA_BFD_DEST_DEREGISTER);
- bfd_peer_sendmsg(zclient, NULL, adj->bfd_session->family,
- &adj->bfd_session->dst_ip, &adj->bfd_session->src_ip,
- (adj->circuit->interface)
- ? adj->circuit->interface->name
- : NULL,
- 0, /* ttl */
- 0, /* multihop */
- 1, /* control plane independent bit is on */
- ZEBRA_BFD_DEST_DEREGISTER,
- 0, /* set_flag */
- VRF_DEFAULT);
+ bfd_command(ZEBRA_BFD_DEST_DEREGISTER, NULL, adj->bfd_session->family,
+ &adj->bfd_session->dst_ip, &adj->bfd_session->src_ip,
+ (adj->circuit->interface) ? adj->circuit->interface->name
+ : NULL);
+
bfd_session_free(&adj->bfd_session);
}
@@ -324,18 +355,12 @@ static void bfd_handle_adj_up(struct isis_adjacency *adj, int command)
bfd_debug(adj->bfd_session->family, &adj->bfd_session->dst_ip,
&adj->bfd_session->src_ip, circuit->interface->name, command);
- bfd_peer_sendmsg(zclient, circuit->bfd_info, adj->bfd_session->family,
- &adj->bfd_session->dst_ip,
- &adj->bfd_session->src_ip,
- (adj->circuit->interface)
- ? adj->circuit->interface->name
- : NULL,
- 0, /* ttl */
- 0, /* multihop */
- 1, /* control plane independent bit is on */
- command,
- 0, /* set flag */
- VRF_DEFAULT);
+
+ bfd_command(command, circuit->bfd_info, family,
+ &adj->bfd_session->dst_ip, &adj->bfd_session->src_ip,
+ (adj->circuit->interface) ? adj->circuit->interface->name
+ : NULL);
+
return;
out:
bfd_handle_adj_down(adj);
@@ -383,14 +408,14 @@ void isis_bfd_circuit_cmd(struct isis_circuit *circuit, int command)
}
}
-void isis_bfd_circuit_param_set(struct isis_circuit *circuit,
- uint32_t min_rx, uint32_t min_tx,
- uint32_t detect_mult, int defaults)
+void isis_bfd_circuit_param_set(struct isis_circuit *circuit, uint32_t min_rx,
+ uint32_t min_tx, uint32_t detect_mult,
+ const char *profile, int defaults)
{
int command = 0;
- bfd_set_param(&circuit->bfd_info, min_rx,
- min_tx, detect_mult, defaults, &command);
+ bfd_set_param(&circuit->bfd_info, min_rx, min_tx, detect_mult, profile,
+ defaults, &command);
if (command)
isis_bfd_circuit_cmd(circuit, command);
diff --git a/isisd/isis_bfd.h b/isisd/isis_bfd.h
index 3193f16061..6ce630688c 100644
--- a/isisd/isis_bfd.h
+++ b/isisd/isis_bfd.h
@@ -22,9 +22,9 @@
struct isis_circuit;
void isis_bfd_circuit_cmd(struct isis_circuit *circuit, int command);
-void isis_bfd_circuit_param_set(struct isis_circuit *circuit,
- uint32_t min_rx, uint32_t min_tx,
- uint32_t detect_mult, int defaults);
+void isis_bfd_circuit_param_set(struct isis_circuit *circuit, uint32_t min_rx,
+ uint32_t min_tx, uint32_t detect_mult,
+ const char *profile, int defaults);
void isis_bfd_init(void);
#endif
diff --git a/isisd/isis_cli.c b/isisd/isis_cli.c
index 28b98610b2..cd75116c50 100644
--- a/isisd/isis_cli.c
+++ b/isisd/isis_cli.c
@@ -46,7 +46,7 @@
/*
* XPath: /frr-isisd:isis/instance
*/
-DEFPY_NOSH(router_isis, router_isis_cmd, "router isis WORD$tag",
+DEFPY_YANG_NOSH(router_isis, router_isis_cmd, "router isis WORD$tag",
ROUTER_STR
"ISO IS-IS\n"
"ISO Routing area tag\n")
@@ -72,7 +72,7 @@ DEFPY_NOSH(router_isis, router_isis_cmd, "router isis WORD$tag",
return ret;
}
-DEFPY(no_router_isis, no_router_isis_cmd, "no router isis WORD$tag",
+DEFPY_YANG(no_router_isis, no_router_isis_cmd, "no router isis WORD$tag",
NO_STR ROUTER_STR
"ISO IS-IS\n"
"ISO Routing area tag\n")
@@ -126,7 +126,7 @@ void cli_show_router_isis(struct vty *vty, struct lyd_node *dnode,
* XPath: /frr-interface:lib/interface/frr-isisd:isis/ipv6-routing
* XPath: /frr-isisd:isis/instance
*/
-DEFPY(ip_router_isis, ip_router_isis_cmd, "ip router isis WORD$tag",
+DEFPY_YANG(ip_router_isis, ip_router_isis_cmd, "ip router isis WORD$tag",
"Interface Internet Protocol config commands\n"
"IP router interface commands\n"
"IS-IS routing protocol\n"
@@ -196,7 +196,7 @@ DEFPY(ip_router_isis, ip_router_isis_cmd, "ip router isis WORD$tag",
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(ip6_router_isis, ip6_router_isis_cmd, "ipv6 router isis WORD$tag",
+DEFPY_YANG(ip6_router_isis, ip6_router_isis_cmd, "ipv6 router isis WORD$tag",
"Interface Internet Protocol config commands\n"
"IP router interface commands\n"
"IS-IS routing protocol\n"
@@ -266,7 +266,7 @@ DEFPY(ip6_router_isis, ip6_router_isis_cmd, "ipv6 router isis WORD$tag",
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(no_ip_router_isis, no_ip_router_isis_cmd,
+DEFPY_YANG(no_ip_router_isis, no_ip_router_isis_cmd,
"no <ip|ipv6>$ip router isis [WORD]$tag",
NO_STR
"Interface Internet Protocol config commands\n"
@@ -327,11 +327,10 @@ void cli_show_ip_isis_ipv6(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-interface:lib/interface/frr-isisd:isis/bfd-monitoring
*/
-DEFPY(isis_bfd,
+DEFPY_YANG(isis_bfd,
isis_bfd_cmd,
"[no] isis bfd",
- NO_STR
- PROTO_HELP
+ NO_STR PROTO_HELP
"Enable BFD support\n")
{
const struct lyd_node *dnode;
@@ -343,25 +342,59 @@ DEFPY(isis_bfd,
return CMD_SUCCESS;
}
- nb_cli_enqueue_change(vty, "./frr-isisd:isis/bfd-monitoring",
+ nb_cli_enqueue_change(vty, "./frr-isisd:isis/bfd-monitoring/enabled",
NB_OP_MODIFY, no ? "false" : "true");
return nb_cli_apply_changes(vty, NULL);
}
+/*
+ * XPath: /frr-interface:lib/interface/frr-isisd:isis/bfd-monitoring/profile
+ */
+DEFPY_YANG(isis_bfd_profile,
+ isis_bfd_profile_cmd,
+ "[no] isis bfd profile WORD",
+ NO_STR PROTO_HELP
+ "Enable BFD support\n"
+ "Use a pre-configured profile\n"
+ "Profile name\n")
+{
+ const struct lyd_node *dnode;
+
+ dnode = yang_dnode_get(vty->candidate_config->dnode,
+ "%s/frr-isisd:isis", VTY_CURR_XPATH);
+ if (dnode == NULL) {
+ vty_out(vty, "ISIS is not enabled on this circuit\n");
+ return CMD_SUCCESS;
+ }
+
+ nb_cli_enqueue_change(vty, "./frr-isisd:isis/bfd-monitoring/profile",
+ NB_OP_MODIFY, no ? NULL : profile);
+
+ return nb_cli_apply_changes(vty, NULL);
+}
+
void cli_show_ip_isis_bfd_monitoring(struct vty *vty, struct lyd_node *dnode,
bool show_defaults)
{
- if (!yang_dnode_get_bool(dnode, NULL))
+ const char *profile;
+
+ if (!yang_dnode_get_bool(dnode, "./enabled"))
vty_out(vty, " no");
vty_out(vty, " isis bfd\n");
+
+ if (yang_dnode_exists(dnode, "./profile")) {
+ profile = yang_dnode_get_string(dnode, "./profile");
+ if (profile[0] != '\0')
+ vty_out(vty, " isis bfd profile %s\n", profile);
+ }
}
/*
* XPath: /frr-isisd:isis/instance/area-address
*/
-DEFPY(net, net_cmd, "[no] net WORD",
+DEFPY_YANG(net, net_cmd, "[no] net WORD",
"Remove an existing Network Entity Title for this process\n"
"A Network Entity Title for this process (OSI only)\n"
"XX.XXXX. ... .XXX.XX Network entity title (NET)\n")
@@ -381,7 +414,7 @@ void cli_show_isis_area_address(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-isisd:isis/instance/is-type
*/
-DEFPY(is_type, is_type_cmd, "is-type <level-1|level-1-2|level-2-only>$level",
+DEFPY_YANG(is_type, is_type_cmd, "is-type <level-1|level-1-2|level-2-only>$level",
"IS Level for this routing process (OSI only)\n"
"Act as a station router only\n"
"Act as both a station router and an area router\n"
@@ -394,7 +427,7 @@ DEFPY(is_type, is_type_cmd, "is-type <level-1|level-1-2|level-2-only>$level",
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(no_is_type, no_is_type_cmd,
+DEFPY_YANG(no_is_type, no_is_type_cmd,
"no is-type [<level-1|level-1-2|level-2-only>]",
NO_STR
"IS Level for this routing process (OSI only)\n"
@@ -428,7 +461,7 @@ void cli_show_isis_is_type(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-isisd:isis/instance/dynamic-hostname
*/
-DEFPY(dynamic_hostname, dynamic_hostname_cmd, "[no] hostname dynamic",
+DEFPY_YANG(dynamic_hostname, dynamic_hostname_cmd, "[no] hostname dynamic",
NO_STR
"Dynamic hostname for IS-IS\n"
"Dynamic hostname\n")
@@ -451,7 +484,7 @@ void cli_show_isis_dynamic_hostname(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-isisd:isis/instance/overload
*/
-DEFPY(set_overload_bit, set_overload_bit_cmd, "[no] set-overload-bit",
+DEFPY_YANG(set_overload_bit, set_overload_bit_cmd, "[no] set-overload-bit",
"Reset overload bit to accept transit traffic\n"
"Set overload bit to avoid any transit traffic\n")
{
@@ -472,7 +505,7 @@ void cli_show_isis_overload(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-isisd:isis/instance/attached
*/
-DEFPY(set_attached_bit, set_attached_bit_cmd, "[no] set-attached-bit",
+DEFPY_YANG(set_attached_bit, set_attached_bit_cmd, "[no] set-attached-bit",
"Reset attached bit\n"
"Set attached bit to identify as L1/L2 router for inter-area traffic\n")
{
@@ -493,7 +526,7 @@ void cli_show_isis_attached(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-isisd:isis/instance/metric-style
*/
-DEFPY(metric_style, metric_style_cmd,
+DEFPY_YANG(metric_style, metric_style_cmd,
"metric-style <narrow|transition|wide>$style",
"Use old-style (ISO 10589) or new-style packet formats\n"
"Use old style of TLVs with narrow metric\n"
@@ -505,7 +538,7 @@ DEFPY(metric_style, metric_style_cmd,
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(no_metric_style, no_metric_style_cmd,
+DEFPY_YANG(no_metric_style, no_metric_style_cmd,
"no metric-style [narrow|transition|wide]",
NO_STR
"Use old-style (ISO 10589) or new-style packet formats\n"
@@ -539,7 +572,7 @@ void cli_show_isis_metric_style(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-isisd:isis/instance/area-password
*/
-DEFPY(area_passwd, area_passwd_cmd,
+DEFPY_YANG(area_passwd, area_passwd_cmd,
"area-password <clear|md5>$pwd_type WORD$pwd [authenticate snp <send-only|validate>$snp]",
"Configure the authentication password for an area\n"
"Clear-text authentication type\n"
@@ -578,7 +611,7 @@ void cli_show_isis_area_pwd(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-isisd:isis/instance/domain-password
*/
-DEFPY(domain_passwd, domain_passwd_cmd,
+DEFPY_YANG(domain_passwd, domain_passwd_cmd,
"domain-password <clear|md5>$pwd_type WORD$pwd [authenticate snp <send-only|validate>$snp]",
"Set the authentication password for a routing domain\n"
"Clear-text authentication type\n"
@@ -600,7 +633,7 @@ DEFPY(domain_passwd, domain_passwd_cmd,
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(no_area_passwd, no_area_passwd_cmd,
+DEFPY_YANG(no_area_passwd, no_area_passwd_cmd,
"no <area-password|domain-password>$cmd",
NO_STR
"Configure the authentication password for an area\n"
@@ -629,7 +662,7 @@ void cli_show_isis_domain_pwd(struct vty *vty, struct lyd_node *dnode,
* XPath: /frr-isisd:isis/instance/lsp/timers/level-1/generation-interval
* XPath: /frr-isisd:isis/instance/lsp/timers/level-2/generation-interval
*/
-DEFPY(lsp_gen_interval, lsp_gen_interval_cmd,
+DEFPY_YANG(lsp_gen_interval, lsp_gen_interval_cmd,
"lsp-gen-interval [level-1|level-2]$level (1-120)$val",
"Minimum interval between regenerating same LSP\n"
"Set interval for level 1 only\n"
@@ -648,7 +681,7 @@ DEFPY(lsp_gen_interval, lsp_gen_interval_cmd,
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(no_lsp_gen_interval, no_lsp_gen_interval_cmd,
+DEFPY_YANG(no_lsp_gen_interval, no_lsp_gen_interval_cmd,
"no lsp-gen-interval [level-1|level-2]$level [(1-120)]",
NO_STR
"Minimum interval between regenerating same LSP\n"
@@ -672,7 +705,7 @@ DEFPY(no_lsp_gen_interval, no_lsp_gen_interval_cmd,
* XPath: /frr-isisd:isis/instance/lsp/timers/level-1/refresh-interval
* XPath: /frr-isisd:isis/instance/lsp/timers/level-2/refresh-interval
*/
-DEFPY(lsp_refresh_interval, lsp_refresh_interval_cmd,
+DEFPY_YANG(lsp_refresh_interval, lsp_refresh_interval_cmd,
"lsp-refresh-interval [level-1|level-2]$level (1-65235)$val",
"LSP refresh interval\n"
"LSP refresh interval for Level 1 only\n"
@@ -691,7 +724,7 @@ DEFPY(lsp_refresh_interval, lsp_refresh_interval_cmd,
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(no_lsp_refresh_interval, no_lsp_refresh_interval_cmd,
+DEFPY_YANG(no_lsp_refresh_interval, no_lsp_refresh_interval_cmd,
"no lsp-refresh-interval [level-1|level-2]$level [(1-65235)]",
NO_STR
"LSP refresh interval\n"
@@ -716,7 +749,7 @@ DEFPY(no_lsp_refresh_interval, no_lsp_refresh_interval_cmd,
* XPath: /frr-isisd:isis/instance/lsp/timers/level-1/maximum-lifetime
*/
-DEFPY(max_lsp_lifetime, max_lsp_lifetime_cmd,
+DEFPY_YANG(max_lsp_lifetime, max_lsp_lifetime_cmd,
"max-lsp-lifetime [level-1|level-2]$level (350-65535)$val",
"Maximum LSP lifetime\n"
"Maximum LSP lifetime for Level 1 only\n"
@@ -735,7 +768,7 @@ DEFPY(max_lsp_lifetime, max_lsp_lifetime_cmd,
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(no_max_lsp_lifetime, no_max_lsp_lifetime_cmd,
+DEFPY_YANG(no_max_lsp_lifetime, no_max_lsp_lifetime_cmd,
"no max-lsp-lifetime [level-1|level-2]$level [(350-65535)]",
NO_STR
"Maximum LSP lifetime\n"
@@ -759,7 +792,7 @@ DEFPY(no_max_lsp_lifetime, no_max_lsp_lifetime_cmd,
* XPath: /frr-isisd:isis/instance/lsp/timers
*/
-DEFPY(lsp_timers, lsp_timers_cmd,
+DEFPY_YANG(lsp_timers, lsp_timers_cmd,
"lsp-timers [level-1|level-2]$level gen-interval (1-120)$gen refresh-interval (1-65235)$refresh max-lifetime (350-65535)$lifetime",
"LSP-related timers\n"
"LSP-related timers for Level 1 only\n"
@@ -797,7 +830,7 @@ DEFPY(lsp_timers, lsp_timers_cmd,
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(no_lsp_timers, no_lsp_timers_cmd,
+DEFPY_YANG(no_lsp_timers, no_lsp_timers_cmd,
"no lsp-timers [level-1|level-2]$level [gen-interval (1-120) refresh-interval (1-65235) max-lifetime (350-65535)]",
NO_STR
"LSP-related timers\n"
@@ -869,7 +902,7 @@ void cli_show_isis_lsp_timers(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-isisd:isis/instance/lsp/mtu
*/
-DEFPY(area_lsp_mtu, area_lsp_mtu_cmd, "lsp-mtu (128-4352)$val",
+DEFPY_YANG(area_lsp_mtu, area_lsp_mtu_cmd, "lsp-mtu (128-4352)$val",
"Configure the maximum size of generated LSPs\n"
"Maximum size of generated LSPs\n")
{
@@ -878,7 +911,7 @@ DEFPY(area_lsp_mtu, area_lsp_mtu_cmd, "lsp-mtu (128-4352)$val",
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(no_area_lsp_mtu, no_area_lsp_mtu_cmd, "no lsp-mtu [(128-4352)]",
+DEFPY_YANG(no_area_lsp_mtu, no_area_lsp_mtu_cmd, "no lsp-mtu [(128-4352)]",
NO_STR
"Configure the maximum size of generated LSPs\n"
"Maximum size of generated LSPs\n")
@@ -897,7 +930,7 @@ void cli_show_isis_lsp_mtu(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-isisd:isis/instance/spf/minimum-interval
*/
-DEFPY(spf_interval, spf_interval_cmd,
+DEFPY_YANG(spf_interval, spf_interval_cmd,
"spf-interval [level-1|level-2]$level (1-120)$val",
"Minimum interval between SPF calculations\n"
"Set interval for level 1 only\n"
@@ -914,7 +947,7 @@ DEFPY(spf_interval, spf_interval_cmd,
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(no_spf_interval, no_spf_interval_cmd,
+DEFPY_YANG(no_spf_interval, no_spf_interval_cmd,
"no spf-interval [level-1|level-2]$level [(1-120)]",
NO_STR
"Minimum interval between SPF calculations\n"
@@ -949,7 +982,7 @@ void cli_show_isis_spf_min_interval(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-isisd:isis/instance/spf/ietf-backoff-delay
*/
-DEFPY(spf_delay_ietf, spf_delay_ietf_cmd,
+DEFPY_YANG(spf_delay_ietf, spf_delay_ietf_cmd,
"spf-delay-ietf init-delay (0-60000) short-delay (0-60000) long-delay (0-60000) holddown (0-60000) time-to-learn (0-60000)",
"IETF SPF delay algorithm\n"
"Delay used while in QUIET state\n"
@@ -979,7 +1012,7 @@ DEFPY(spf_delay_ietf, spf_delay_ietf_cmd,
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(no_spf_delay_ietf, no_spf_delay_ietf_cmd,
+DEFPY_YANG(no_spf_delay_ietf, no_spf_delay_ietf_cmd,
"no spf-delay-ietf [init-delay (0-60000) short-delay (0-60000) long-delay (0-60000) holddown (0-60000) time-to-learn (0-60000)]",
NO_STR
"IETF SPF delay algorithm\n"
@@ -1015,7 +1048,7 @@ void cli_show_isis_spf_ietf_backoff(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-isisd:isis/instance/purge-originator
*/
-DEFPY(area_purge_originator, area_purge_originator_cmd, "[no] purge-originator",
+DEFPY_YANG(area_purge_originator, area_purge_originator_cmd, "[no] purge-originator",
NO_STR "Use the RFC 6232 purge-originator\n")
{
nb_cli_enqueue_change(vty, "./purge-originator", NB_OP_MODIFY,
@@ -1035,7 +1068,7 @@ void cli_show_isis_purge_origin(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-isisd:isis/instance/mpls-te
*/
-DEFPY(isis_mpls_te_on, isis_mpls_te_on_cmd, "mpls-te on",
+DEFPY_YANG(isis_mpls_te_on, isis_mpls_te_on_cmd, "mpls-te on",
MPLS_TE_STR "Enable the MPLS-TE functionality\n")
{
nb_cli_enqueue_change(vty, "./mpls-te", NB_OP_CREATE,
@@ -1044,7 +1077,7 @@ DEFPY(isis_mpls_te_on, isis_mpls_te_on_cmd, "mpls-te on",
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(no_isis_mpls_te_on, no_isis_mpls_te_on_cmd, "no mpls-te [on]",
+DEFPY_YANG(no_isis_mpls_te_on, no_isis_mpls_te_on_cmd, "no mpls-te [on]",
NO_STR
"Disable the MPLS-TE functionality\n"
"Disable the MPLS-TE functionality\n")
@@ -1064,7 +1097,7 @@ void cli_show_isis_mpls_te(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-isisd:isis/instance/mpls-te/router-address
*/
-DEFPY(isis_mpls_te_router_addr, isis_mpls_te_router_addr_cmd,
+DEFPY_YANG(isis_mpls_te_router_addr, isis_mpls_te_router_addr_cmd,
"mpls-te router-address A.B.C.D",
MPLS_TE_STR
"Stable IP address of the advertising router\n"
@@ -1076,7 +1109,7 @@ DEFPY(isis_mpls_te_router_addr, isis_mpls_te_router_addr_cmd,
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(no_isis_mpls_te_router_addr, no_isis_mpls_te_router_addr_cmd,
+DEFPY_YANG(no_isis_mpls_te_router_addr, no_isis_mpls_te_router_addr_cmd,
"no mpls-te router-address [A.B.C.D]",
NO_STR MPLS_TE_STR
"Delete IP address of the advertising router\n"
@@ -1095,7 +1128,7 @@ void cli_show_isis_mpls_te_router_addr(struct vty *vty, struct lyd_node *dnode,
yang_dnode_get_string(dnode, NULL));
}
-DEFPY(isis_mpls_te_inter_as, isis_mpls_te_inter_as_cmd,
+DEFPY_YANG(isis_mpls_te_inter_as, isis_mpls_te_inter_as_cmd,
"[no] mpls-te inter-as [level-1|level-1-2|level-2-only]",
NO_STR MPLS_TE_STR
"Configure MPLS-TE Inter-AS support\n"
@@ -1110,7 +1143,7 @@ DEFPY(isis_mpls_te_inter_as, isis_mpls_te_inter_as_cmd,
/*
* XPath: /frr-isisd:isis/instance/default-information-originate
*/
-DEFPY(isis_default_originate, isis_default_originate_cmd,
+DEFPY_YANG(isis_default_originate, isis_default_originate_cmd,
"[no] default-information originate <ipv4|ipv6>$ip <level-1|level-2>$level [always]$always [{metric (0-16777215)$metric|route-map WORD$rmap}]",
NO_STR
"Control distribution of default information\n"
@@ -1186,7 +1219,7 @@ void cli_show_isis_def_origin_ipv6(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-isisd:isis/instance/redistribute
*/
-DEFPY(isis_redistribute, isis_redistribute_cmd,
+DEFPY_YANG(isis_redistribute, isis_redistribute_cmd,
"[no] redistribute <ipv4|ipv6>$ip " PROTO_REDIST_STR
"$proto <level-1|level-2>$level [{metric (0-16777215)|route-map WORD}]",
NO_STR REDIST_STR
@@ -1245,7 +1278,7 @@ void cli_show_isis_redistribute_ipv6(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-isisd:isis/instance/multi-topology
*/
-DEFPY(isis_topology, isis_topology_cmd,
+DEFPY_YANG(isis_topology, isis_topology_cmd,
"[no] topology <ipv4-unicast|ipv4-mgmt|ipv6-unicast|ipv4-multicast|ipv6-multicast|ipv6-mgmt|ipv6-dstsrc>$topology [overload]$overload",
NO_STR
"Configure IS-IS topologies\n"
@@ -1346,7 +1379,7 @@ void cli_show_isis_mt_ipv6_dstsrc(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-isisd:isis/instance/segment-routing/enabled
*/
-DEFPY (isis_sr_enable,
+DEFPY_YANG (isis_sr_enable,
isis_sr_enable_cmd,
"segment-routing on",
SR_STR
@@ -1358,7 +1391,7 @@ DEFPY (isis_sr_enable,
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY (no_isis_sr_enable,
+DEFPY_YANG (no_isis_sr_enable,
no_isis_sr_enable_cmd,
"no segment-routing [on]",
NO_STR
@@ -1383,7 +1416,7 @@ void cli_show_isis_sr_enabled(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-isisd:isis/instance/segment-routing/srgb
*/
-DEFPY (isis_sr_global_block_label_range,
+DEFPY_YANG (isis_sr_global_block_label_range,
isis_sr_global_block_label_range_cmd,
"segment-routing global-block (16-1048575)$lower_bound (16-1048575)$upper_bound",
SR_STR
@@ -1399,7 +1432,7 @@ DEFPY (isis_sr_global_block_label_range,
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY (no_isis_sr_global_block_label_range,
+DEFPY_YANG (no_isis_sr_global_block_label_range,
no_isis_sr_global_block_label_range_cmd,
"no segment-routing global-block [(16-1048575) (16-1048575)]",
NO_STR
@@ -1427,7 +1460,7 @@ void cli_show_isis_srgb(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-isisd:isis/instance/segment-routing/srlb
*/
-DEFPY (isis_sr_local_block_label_range,
+DEFPY_YANG (isis_sr_local_block_label_range,
isis_sr_local_block_label_range_cmd,
"segment-routing local-block (16-1048575)$lower_bound (16-1048575)$upper_bound",
SR_STR
@@ -1443,7 +1476,7 @@ DEFPY (isis_sr_local_block_label_range,
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY (no_isis_sr_local_block_label_range,
+DEFPY_YANG (no_isis_sr_local_block_label_range,
no_isis_sr_local_block_label_range_cmd,
"no segment-routing local-block [(16-1048575) (16-1048575)]",
NO_STR
@@ -1471,7 +1504,7 @@ void cli_show_isis_srlb(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-isisd:isis/instance/segment-routing/msd/node-msd
*/
-DEFPY (isis_sr_node_msd,
+DEFPY_YANG (isis_sr_node_msd,
isis_sr_node_msd_cmd,
"segment-routing node-msd (1-16)$msd",
SR_STR
@@ -1484,7 +1517,7 @@ DEFPY (isis_sr_node_msd,
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY (no_isis_sr_node_msd,
+DEFPY_YANG (no_isis_sr_node_msd,
no_isis_sr_node_msd_cmd,
"no segment-routing node-msd [(1-16)]",
NO_STR
@@ -1508,7 +1541,7 @@ void cli_show_isis_node_msd(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-isisd:isis/instance/segment-routing/prefix-sid-map/prefix-sid
*/
-DEFPY (isis_sr_prefix_sid,
+DEFPY_YANG (isis_sr_prefix_sid,
isis_sr_prefix_sid_cmd,
"segment-routing prefix\
<A.B.C.D/M|X:X::X:X/M>$prefix\
@@ -1547,7 +1580,7 @@ DEFPY (isis_sr_prefix_sid,
prefix_str);
}
-DEFPY (no_isis_sr_prefix_sid,
+DEFPY_YANG (no_isis_sr_prefix_sid,
no_isis_sr_prefix_sid_cmd,
"no segment-routing prefix <A.B.C.D/M|X:X::X:X/M>$prefix\
[<absolute$sid_type (16-1048575)|index (0-65535)> [<no-php-flag|explicit-null>]]",
@@ -1599,7 +1632,7 @@ void cli_show_isis_prefix_sid(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-interface:lib/interface/frr-isisd:isis/passive
*/
-DEFPY(isis_passive, isis_passive_cmd, "[no] isis passive",
+DEFPY_YANG(isis_passive, isis_passive_cmd, "[no] isis passive",
NO_STR
"IS-IS routing protocol\n"
"Configure the passive mode for interface\n")
@@ -1622,7 +1655,7 @@ void cli_show_ip_isis_passive(struct vty *vty, struct lyd_node *dnode,
* XPath: /frr-interface:lib/interface/frr-isisd:isis/password
*/
-DEFPY(isis_passwd, isis_passwd_cmd, "isis password <md5|clear>$type WORD$pwd",
+DEFPY_YANG(isis_passwd, isis_passwd_cmd, "isis password <md5|clear>$type WORD$pwd",
"IS-IS routing protocol\n"
"Configure the authentication password for a circuit\n"
"HMAC-MD5 authentication\n"
@@ -1639,7 +1672,7 @@ DEFPY(isis_passwd, isis_passwd_cmd, "isis password <md5|clear>$type WORD$pwd",
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(no_isis_passwd, no_isis_passwd_cmd, "no isis password [<md5|clear> WORD]",
+DEFPY_YANG(no_isis_passwd, no_isis_passwd_cmd, "no isis password [<md5|clear> WORD]",
NO_STR
"IS-IS routing protocol\n"
"Configure the authentication password for a circuit\n"
@@ -1664,7 +1697,7 @@ void cli_show_ip_isis_password(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-interface:lib/interface/frr-isisd:isis/metric
*/
-DEFPY(isis_metric, isis_metric_cmd,
+DEFPY_YANG(isis_metric, isis_metric_cmd,
"isis metric [level-1|level-2]$level (0-16777215)$met",
"IS-IS routing protocol\n"
"Set default metric for circuit\n"
@@ -1682,7 +1715,7 @@ DEFPY(isis_metric, isis_metric_cmd,
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(no_isis_metric, no_isis_metric_cmd,
+DEFPY_YANG(no_isis_metric, no_isis_metric_cmd,
"no isis metric [level-1|level-2]$level [(0-16777215)]",
NO_STR
"IS-IS routing protocol\n"
@@ -1718,7 +1751,7 @@ void cli_show_ip_isis_metric(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-interface:lib/interface/frr-isisd:isis/hello/interval
*/
-DEFPY(isis_hello_interval, isis_hello_interval_cmd,
+DEFPY_YANG(isis_hello_interval, isis_hello_interval_cmd,
"isis hello-interval [level-1|level-2]$level (1-600)$intv",
"IS-IS routing protocol\n"
"Set Hello interval\n"
@@ -1738,7 +1771,7 @@ DEFPY(isis_hello_interval, isis_hello_interval_cmd,
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(no_isis_hello_interval, no_isis_hello_interval_cmd,
+DEFPY_YANG(no_isis_hello_interval, no_isis_hello_interval_cmd,
"no isis hello-interval [level-1|level-2]$level [(1-600)]",
NO_STR
"IS-IS routing protocol\n"
@@ -1776,7 +1809,7 @@ void cli_show_ip_isis_hello_interval(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-interface:lib/interface/frr-isisd:isis/hello/multiplier
*/
-DEFPY(isis_hello_multiplier, isis_hello_multiplier_cmd,
+DEFPY_YANG(isis_hello_multiplier, isis_hello_multiplier_cmd,
"isis hello-multiplier [level-1|level-2]$level (2-100)$mult",
"IS-IS routing protocol\n"
"Set multiplier for Hello holding time\n"
@@ -1796,7 +1829,7 @@ DEFPY(isis_hello_multiplier, isis_hello_multiplier_cmd,
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(no_isis_hello_multiplier, no_isis_hello_multiplier_cmd,
+DEFPY_YANG(no_isis_hello_multiplier, no_isis_hello_multiplier_cmd,
"no isis hello-multiplier [level-1|level-2]$level [(2-100)]",
NO_STR
"IS-IS routing protocol\n"
@@ -1835,7 +1868,7 @@ void cli_show_ip_isis_hello_multi(struct vty *vty, struct lyd_node *dnode,
* XPath:
* /frr-interface:lib/interface/frr-isisd:isis/disable-three-way-handshake
*/
-DEFPY(isis_threeway_adj, isis_threeway_adj_cmd, "[no] isis three-way-handshake",
+DEFPY_YANG(isis_threeway_adj, isis_threeway_adj_cmd, "[no] isis three-way-handshake",
NO_STR
"IS-IS commands\n"
"Enable/Disable three-way handshake\n")
@@ -1858,7 +1891,7 @@ void cli_show_ip_isis_threeway_shake(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-interface:lib/interface/frr-isisd:isis/hello/padding
*/
-DEFPY(isis_hello_padding, isis_hello_padding_cmd, "[no] isis hello padding",
+DEFPY_YANG(isis_hello_padding, isis_hello_padding_cmd, "[no] isis hello padding",
NO_STR
"IS-IS routing protocol\n"
"Add padding to IS-IS hello packets\n"
@@ -1882,7 +1915,7 @@ void cli_show_ip_isis_hello_padding(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-interface:lib/interface/frr-isisd:isis/csnp-interval
*/
-DEFPY(csnp_interval, csnp_interval_cmd,
+DEFPY_YANG(csnp_interval, csnp_interval_cmd,
"isis csnp-interval (1-600)$intv [level-1|level-2]$level",
"IS-IS routing protocol\n"
"Set CSNP interval in seconds\n"
@@ -1902,7 +1935,7 @@ DEFPY(csnp_interval, csnp_interval_cmd,
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(no_csnp_interval, no_csnp_interval_cmd,
+DEFPY_YANG(no_csnp_interval, no_csnp_interval_cmd,
"no isis csnp-interval [(1-600)] [level-1|level-2]$level",
NO_STR
"IS-IS routing protocol\n"
@@ -1940,7 +1973,7 @@ void cli_show_ip_isis_csnp_interval(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-interface:lib/interface/frr-isisd:isis/psnp-interval
*/
-DEFPY(psnp_interval, psnp_interval_cmd,
+DEFPY_YANG(psnp_interval, psnp_interval_cmd,
"isis psnp-interval (1-120)$intv [level-1|level-2]$level",
"IS-IS routing protocol\n"
"Set PSNP interval in seconds\n"
@@ -1960,7 +1993,7 @@ DEFPY(psnp_interval, psnp_interval_cmd,
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(no_psnp_interval, no_psnp_interval_cmd,
+DEFPY_YANG(no_psnp_interval, no_psnp_interval_cmd,
"no isis psnp-interval [(1-120)] [level-1|level-2]$level",
NO_STR
"IS-IS routing protocol\n"
@@ -1998,7 +2031,7 @@ void cli_show_ip_isis_psnp_interval(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-interface:lib/interface/frr-isisd:isis/multi-topology
*/
-DEFPY(circuit_topology, circuit_topology_cmd,
+DEFPY_YANG(circuit_topology, circuit_topology_cmd,
"[no] isis topology<ipv4-unicast|ipv4-mgmt|ipv6-unicast|ipv4-multicast|ipv6-multicast|ipv6-mgmt|ipv6-dstsrc>$topology",
NO_STR
"IS-IS routing protocol\n"
@@ -2083,7 +2116,7 @@ void cli_show_ip_isis_mt_ipv6_dstsrc(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-interface:lib/interface/frr-isisd:isis/circuit-type
*/
-DEFPY(isis_circuit_type, isis_circuit_type_cmd,
+DEFPY_YANG(isis_circuit_type, isis_circuit_type_cmd,
"isis circuit-type <level-1|level-1-2|level-2-only>$type",
"IS-IS routing protocol\n"
"Configure circuit type for interface\n"
@@ -2098,7 +2131,7 @@ DEFPY(isis_circuit_type, isis_circuit_type_cmd,
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(no_isis_circuit_type, no_isis_circuit_type_cmd,
+DEFPY_YANG(no_isis_circuit_type, no_isis_circuit_type_cmd,
"no isis circuit-type [level-1|level-1-2|level-2-only]",
NO_STR
"IS-IS routing protocol\n"
@@ -2176,7 +2209,7 @@ void cli_show_ip_isis_circ_type(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-interface:lib/interface/frr-isisd:isis/network-type
*/
-DEFPY(isis_network, isis_network_cmd, "[no] isis network point-to-point",
+DEFPY_YANG(isis_network, isis_network_cmd, "[no] isis network point-to-point",
NO_STR
"IS-IS routing protocol\n"
"Set network type\n"
@@ -2201,7 +2234,7 @@ void cli_show_ip_isis_network_type(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-interface:lib/interface/frr-isisd:isis/priority
*/
-DEFPY(isis_priority, isis_priority_cmd,
+DEFPY_YANG(isis_priority, isis_priority_cmd,
"isis priority (0-127)$prio [level-1|level-2]$level",
"IS-IS routing protocol\n"
"Set priority for Designated Router election\n"
@@ -2219,7 +2252,7 @@ DEFPY(isis_priority, isis_priority_cmd,
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(no_isis_priority, no_isis_priority_cmd,
+DEFPY_YANG(no_isis_priority, no_isis_priority_cmd,
"no isis priority [(0-127)] [level-1|level-2]$level",
NO_STR
"IS-IS routing protocol\n"
@@ -2255,7 +2288,7 @@ void cli_show_ip_isis_priority(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-isisd:isis/instance/log-adjacency-changes
*/
-DEFPY(log_adj_changes, log_adj_changes_cmd, "[no] log-adjacency-changes",
+DEFPY_YANG(log_adj_changes, log_adj_changes_cmd, "[no] log-adjacency-changes",
NO_STR "Log changes in adjacency state\n")
{
nb_cli_enqueue_change(vty, "./log-adjacency-changes", NB_OP_MODIFY,
@@ -2281,6 +2314,7 @@ void isis_cli_init(void)
install_element(INTERFACE_NODE, &ip6_router_isis_cmd);
install_element(INTERFACE_NODE, &no_ip_router_isis_cmd);
install_element(INTERFACE_NODE, &isis_bfd_cmd);
+ install_element(INTERFACE_NODE, &isis_bfd_profile_cmd);
install_element(ISIS_NODE, &net_cmd);
diff --git a/isisd/isis_nb.c b/isisd/isis_nb.c
index 1d842eb13b..2b8b02e3f1 100644
--- a/isisd/isis_nb.c
+++ b/isisd/isis_nb.c
@@ -574,11 +574,24 @@ const struct frr_yang_module_info frr_isisd_info = {
{
.xpath = "/frr-interface:lib/interface/frr-isisd:isis/bfd-monitoring",
.cbs = {
- .modify = lib_interface_isis_bfd_monitoring_modify,
+ .apply_finish = lib_interface_isis_bfd_monitoring_apply_finish,
.cli_show = cli_show_ip_isis_bfd_monitoring,
}
},
{
+ .xpath = "/frr-interface:lib/interface/frr-isisd:isis/bfd-monitoring/enabled",
+ .cbs = {
+ .modify = lib_interface_isis_bfd_monitoring_enabled_modify,
+ }
+ },
+ {
+ .xpath = "/frr-interface:lib/interface/frr-isisd:isis/bfd-monitoring/profile",
+ .cbs = {
+ .modify = lib_interface_isis_bfd_monitoring_profile_modify,
+ .destroy = lib_interface_isis_bfd_monitoring_profile_destroy,
+ }
+ },
+ {
.xpath = "/frr-interface:lib/interface/frr-isisd:isis/csnp-interval",
.cbs = {
.cli_show = cli_show_ip_isis_csnp_interval,
diff --git a/isisd/isis_nb.h b/isisd/isis_nb.h
index e887b1a388..a9401bc86a 100644
--- a/isisd/isis_nb.h
+++ b/isisd/isis_nb.h
@@ -171,7 +171,14 @@ int lib_interface_isis_area_tag_modify(struct nb_cb_modify_args *args);
int lib_interface_isis_ipv4_routing_modify(struct nb_cb_modify_args *args);
int lib_interface_isis_ipv6_routing_modify(struct nb_cb_modify_args *args);
int lib_interface_isis_circuit_type_modify(struct nb_cb_modify_args *args);
-int lib_interface_isis_bfd_monitoring_modify(struct nb_cb_modify_args *args);
+void lib_interface_isis_bfd_monitoring_apply_finish(
+ struct nb_cb_apply_finish_args *args);
+int lib_interface_isis_bfd_monitoring_enabled_modify(
+ struct nb_cb_modify_args *args);
+int lib_interface_isis_bfd_monitoring_profile_modify(
+ struct nb_cb_modify_args *args);
+int lib_interface_isis_bfd_monitoring_profile_destroy(
+ struct nb_cb_destroy_args *args);
int isis_instance_segment_routing_enabled_modify(
struct nb_cb_modify_args *args);
int isis_instance_segment_routing_enabled_modify(
diff --git a/isisd/isis_nb_config.c b/isisd/isis_nb_config.c
index 5fad974d25..6873c652f2 100644
--- a/isisd/isis_nb_config.c
+++ b/isisd/isis_nb_config.c
@@ -2029,26 +2029,53 @@ int lib_interface_isis_ipv6_routing_modify(struct nb_cb_modify_args *args)
/*
* XPath: /frr-interface:lib/interface/frr-isisd:isis/bfd-monitoring
*/
-int lib_interface_isis_bfd_monitoring_modify(struct nb_cb_modify_args *args)
+void lib_interface_isis_bfd_monitoring_apply_finish(
+ struct nb_cb_apply_finish_args *args)
{
struct isis_circuit *circuit;
- bool bfd_monitoring;
-
- if (args->event != NB_EV_APPLY)
- return NB_OK;
+ bool enabled;
+ const char *profile = NULL;
circuit = nb_running_get_entry(args->dnode, NULL, true);
- bfd_monitoring = yang_dnode_get_bool(args->dnode, NULL);
+ enabled = yang_dnode_get_bool(args->dnode, "./enabled");
+
+ if (yang_dnode_exists(args->dnode, "./profile"))
+ profile = yang_dnode_get_string(args->dnode, "./profile");
- if (bfd_monitoring) {
+ if (enabled) {
isis_bfd_circuit_param_set(circuit, BFD_DEF_MIN_RX,
BFD_DEF_MIN_TX, BFD_DEF_DETECT_MULT,
- true);
+ profile, true);
} else {
isis_bfd_circuit_cmd(circuit, ZEBRA_BFD_DEST_DEREGISTER);
bfd_info_free(&circuit->bfd_info);
}
+}
+
+/*
+ * XPath: /frr-interface:lib/interface/frr-isisd:isis/bfd-monitoring/enabled
+ */
+int lib_interface_isis_bfd_monitoring_enabled_modify(
+ struct nb_cb_modify_args *args)
+{
+ /* Everything done in apply_finish */
+ return NB_OK;
+}
+/*
+ * XPath: /frr-interface:lib/interface/frr-isisd:isis/bfd-monitoring/profile
+ */
+int lib_interface_isis_bfd_monitoring_profile_modify(
+ struct nb_cb_modify_args *args)
+{
+ /* Everything done in apply_finish */
+ return NB_OK;
+}
+
+int lib_interface_isis_bfd_monitoring_profile_destroy(
+ struct nb_cb_destroy_args *args)
+{
+ /* Everything done in apply_finish */
return NB_OK;
}
diff --git a/isisd/isis_vty_fabricd.c b/isisd/isis_vty_fabricd.c
index 562881bbdb..a574c5bd3f 100644
--- a/isisd/isis_vty_fabricd.c
+++ b/isisd/isis_vty_fabricd.c
@@ -315,8 +315,8 @@ DEFUN (isis_bfd,
return CMD_SUCCESS;
}
- isis_bfd_circuit_param_set(circuit, BFD_DEF_MIN_RX,
- BFD_DEF_MIN_TX, BFD_DEF_DETECT_MULT, true);
+ isis_bfd_circuit_param_set(circuit, BFD_DEF_MIN_RX, BFD_DEF_MIN_TX,
+ BFD_DEF_DETECT_MULT, NULL, true);
return CMD_SUCCESS;
}
diff --git a/ldpd/l2vpn.c b/ldpd/l2vpn.c
index 0d479e77ba..2c68f3edbd 100644
--- a/ldpd/l2vpn.c
+++ b/ldpd/l2vpn.c
@@ -294,6 +294,16 @@ l2vpn_pw_reset(struct l2vpn_pw *pw)
pw->flags |= F_PW_STATUSTLV;
else
pw->flags &= ~F_PW_STATUSTLV;
+
+ if (pw->flags & F_PW_STATUSTLV_CONF) {
+ struct fec_node *fn;
+ struct fec fec;
+ l2vpn_pw_fec(pw, &fec);
+ fn = (struct fec_node *)fec_find(&ft, &fec);
+ if (fn)
+ pw->remote_status = fn->pw_remote_status;
+ }
+
}
int
@@ -433,6 +443,8 @@ l2vpn_recv_pw_status(struct lde_nbr *ln, struct notify_msg *nm)
/* unknown fec */
return;
+ fn->pw_remote_status = nm->pw_status;
+
pw = (struct l2vpn_pw *) fn->data;
if (pw == NULL)
return;
diff --git a/ldpd/lde.c b/ldpd/lde.c
index 4fca4b0962..734c1ea230 100644
--- a/ldpd/lde.c
+++ b/ldpd/lde.c
@@ -296,7 +296,7 @@ lde_dispatch_imsg(struct thread *thread)
switch (imsg.hdr.type) {
case IMSG_LABEL_MAPPING:
- lde_check_mapping(map, ln);
+ lde_check_mapping(map, ln, 1);
break;
case IMSG_LABEL_REQUEST:
lde_check_request(map, ln);
diff --git a/ldpd/lde.h b/ldpd/lde.h
index 2895e00ae5..9e6db3a90b 100644
--- a/ldpd/lde.h
+++ b/ldpd/lde.h
@@ -125,6 +125,9 @@ struct fec_node {
struct lde_map_head upstream; /* sent mappings */
uint32_t local_label;
+
+ uint32_t pw_remote_status;
+
void *data; /* fec specific data */
};
@@ -209,7 +212,7 @@ void lde_kernel_insert(struct fec *, int, union ldpd_addr *,
void lde_kernel_remove(struct fec *, int, union ldpd_addr *,
ifindex_t, uint8_t, unsigned short);
void lde_kernel_update(struct fec *);
-void lde_check_mapping(struct map *, struct lde_nbr *);
+void lde_check_mapping(struct map *, struct lde_nbr *, int);
void lde_check_request(struct map *, struct lde_nbr *);
void lde_check_request_wcard(struct map *, struct lde_nbr *);
void lde_check_release(struct map *, struct lde_nbr *);
diff --git a/ldpd/lde_lib.c b/ldpd/lde_lib.c
index 8f524e0aa9..11d85b7449 100644
--- a/ldpd/lde_lib.c
+++ b/ldpd/lde_lib.c
@@ -267,6 +267,9 @@ fec_add(struct fec *fec)
RB_INIT(lde_map_head, &fn->downstream);
LIST_INIT(&fn->nexthops);
+ if (fec->type == FEC_TYPE_PWID)
+ fn->pw_remote_status = PW_FORWARDING;
+
if (fec_insert(&ft, &fn->fec))
log_warnx("failed to add %s to ft tree",
log_fec(&fn->fec));
@@ -455,13 +458,13 @@ lde_kernel_update(struct fec *fec)
me = (struct lde_map *)fec_find(&ln->recv_map, &fn->fec);
if (me)
/* FEC.5 */
- lde_check_mapping(&me->map, ln);
+ lde_check_mapping(&me->map, ln, 0);
}
}
}
void
-lde_check_mapping(struct map *map, struct lde_nbr *ln)
+lde_check_mapping(struct map *map, struct lde_nbr *ln, int rcvd_label_mapping)
{
struct fec fec;
struct fec_node *fn;
@@ -507,8 +510,12 @@ lde_check_mapping(struct map *map, struct lde_nbr *ln)
lde_req_del(ln, lre, 1);
/* RFC 4447 control word and status tlv negotiation */
- if (map->type == MAP_TYPE_PWID && l2vpn_pw_negotiate(ln, fn, map))
+ if (map->type == MAP_TYPE_PWID && l2vpn_pw_negotiate(ln, fn, map)) {
+ if (rcvd_label_mapping && map->flags & F_MAP_PW_STATUS)
+ fn->pw_remote_status = map->pw_status;
+
return;
+ }
/*
* LMp.3 - LMp.8: loop detection - unnecessary for frame-mode
@@ -570,8 +577,10 @@ lde_check_mapping(struct map *map, struct lde_nbr *ln)
pw->remote_group = map->fec.pwid.group_id;
if (map->flags & F_MAP_PW_IFMTU)
pw->remote_mtu = map->fec.pwid.ifmtu;
- if (map->flags & F_MAP_PW_STATUS)
+ if (rcvd_label_mapping && map->flags & F_MAP_PW_STATUS) {
pw->remote_status = map->pw_status;
+ fn->pw_remote_status = map->pw_status;
+ }
else
pw->remote_status = PW_FORWARDING;
fnh->remote_label = map->label;
@@ -847,6 +856,9 @@ lde_check_withdraw(struct map *map, struct lde_nbr *ln)
if (me && (map->label == NO_LABEL || map->label == me->map.label))
/* LWd.4: remove record of previously received lbl mapping */
lde_map_del(ln, me, 0);
+ else
+ /* LWd.13 done */
+ return;
/* Ordered Control: additional withdraw steps */
if (ldeconf->flags & F_LDPD_ORDERED_CONTROL) {
@@ -858,15 +870,17 @@ lde_check_withdraw(struct map *map, struct lde_nbr *ln)
/* LWd.9: check if previously sent a label mapping */
me = (struct lde_map *)fec_find(&lnbr->sent_map,
&fn->fec);
+
/*
* LWd.10: does label sent to peer "map" to withdraw
* label
*/
- if (me)
+ if (me && lde_nbr_is_nexthop(fn, lnbr))
/* LWd.11: send label withdraw */
lde_send_labelwithdraw(lnbr, fn, NULL, NULL);
}
}
+
}
void
@@ -924,24 +938,33 @@ lde_check_withdraw_wcard(struct map *map, struct lde_nbr *ln)
* label mapping
*/
lde_map_del(ln, me, 0);
+ else
+ /* LWd.13 done */
+ continue;
/* Ordered Control: additional withdraw steps */
if (ldeconf->flags & F_LDPD_ORDERED_CONTROL) {
- /* LWd.8: for each neighbor other that src of withdraw msg */
+ /*
+ * LWd.8: for each neighbor other that src of
+ * withdraw msg
+ */
RB_FOREACH(lnbr, nbr_tree, &lde_nbrs) {
if (ln->peerid == lnbr->peerid)
continue;
- /* LWd.9: check if previously sent a label mapping */
- me = (struct lde_map *)fec_find(&lnbr->sent_map,
- &fn->fec);
+ /* LWd.9: check if previously sent a label
+ * mapping
+ */
+ me = (struct lde_map *)fec_find(
+ &lnbr->sent_map, &fn->fec);
/*
- * LWd.10: does label sent to peer "map" to withdraw
- * label
+ * LWd.10: does label sent to peer "map" to
+ * withdraw label
*/
- if (me)
+ if (me && lde_nbr_is_nexthop(fn, lnbr))
/* LWd.11: send label withdraw */
- lde_send_labelwithdraw(lnbr, fn, NULL, NULL);
+ lde_send_labelwithdraw(lnbr, fn, NULL,
+ NULL);
}
}
}
diff --git a/lib/bfd.c b/lib/bfd.c
index 6173ebc197..d1a0ec671e 100644
--- a/lib/bfd.c
+++ b/lib/bfd.c
@@ -94,7 +94,8 @@ int bfd_validate_param(struct vty *vty, const char *dm_str, const char *rx_str,
* bfd_set_param - Set the configured BFD paramter values
*/
void bfd_set_param(struct bfd_info **bfd_info, uint32_t min_rx, uint32_t min_tx,
- uint8_t detect_mult, int defaults, int *command)
+ uint8_t detect_mult, const char *profile, int defaults,
+ int *command)
{
if (!*bfd_info) {
*bfd_info = bfd_info_create();
@@ -102,7 +103,8 @@ void bfd_set_param(struct bfd_info **bfd_info, uint32_t min_rx, uint32_t min_tx,
} else {
if (((*bfd_info)->required_min_rx != min_rx)
|| ((*bfd_info)->desired_min_tx != min_tx)
- || ((*bfd_info)->detect_mult != detect_mult))
+ || ((*bfd_info)->detect_mult != detect_mult)
+ || (profile && strcmp((*bfd_info)->profile, profile)))
*command = ZEBRA_BFD_DEST_UPDATE;
}
@@ -110,6 +112,11 @@ void bfd_set_param(struct bfd_info **bfd_info, uint32_t min_rx, uint32_t min_tx,
(*bfd_info)->required_min_rx = min_rx;
(*bfd_info)->desired_min_tx = min_tx;
(*bfd_info)->detect_mult = detect_mult;
+ if (profile)
+ strlcpy((*bfd_info)->profile, profile,
+ BFD_PROFILE_NAME_LEN);
+ else
+ (*bfd_info)->profile[0] = '\0';
}
if (!defaults)
@@ -121,6 +128,8 @@ void bfd_set_param(struct bfd_info **bfd_info, uint32_t min_rx, uint32_t min_tx,
/*
* bfd_peer_sendmsg - Format and send a peer register/Unregister
* command to Zebra to be forwarded to BFD
+ *
+ * DEPRECATED: use zclient_bfd_command instead
*/
void bfd_peer_sendmsg(struct zclient *zclient, struct bfd_info *bfd_info,
int family, void *dst_ip, void *src_ip, char *if_name,
@@ -161,6 +170,11 @@ void bfd_peer_sendmsg(struct zclient *zclient, struct bfd_info *bfd_info,
args.min_rx = bfd_info->required_min_rx;
args.min_tx = bfd_info->desired_min_tx;
args.detection_multiplier = bfd_info->detect_mult;
+ if (bfd_info->profile[0]) {
+ args.profilelen = strlen(bfd_info->profile);
+ strlcpy(args.profile, bfd_info->profile,
+ sizeof(args.profile));
+ }
}
addrlen = family == AF_INET ? sizeof(struct in_addr)
@@ -425,6 +439,15 @@ int zclient_bfd_command(struct zclient *zc, struct bfd_session_arg *args)
struct stream *s;
size_t addrlen;
+ /* Individual reg/dereg messages are suppressed during shutdown. */
+ if (CHECK_FLAG(bfd_gbl.flags, BFD_GBL_FLAG_IN_SHUTDOWN)) {
+ if (bfd_debug)
+ zlog_debug(
+ "%s: Suppressing BFD peer reg/dereg messages",
+ __func__);
+ return -1;
+ }
+
/* Check socket. */
if (!zc || zc->sock < 0) {
if (bfd_debug)
diff --git a/lib/bfd.h b/lib/bfd.h
index d7d4b5fe35..ceab4628b6 100644
--- a/lib/bfd.h
+++ b/lib/bfd.h
@@ -92,8 +92,8 @@ extern int bfd_validate_param(struct vty *vty, const char *dm_str,
uint32_t *tx_val);
extern void bfd_set_param(struct bfd_info **bfd_info, uint32_t min_rx,
- uint32_t min_tx, uint8_t detect_mult, int defaults,
- int *command);
+ uint32_t min_tx, uint8_t detect_mult,
+ const char *profile, int defaults, int *command);
extern void bfd_peer_sendmsg(struct zclient *zclient, struct bfd_info *bfd_info,
int family, void *dst_ip, void *src_ip,
char *if_name, int ttl, int multihop, int cbit,
diff --git a/lib/bitfield.h b/lib/bitfield.h
index 72980165f9..244938933b 100644
--- a/lib/bitfield.h
+++ b/lib/bitfield.h
@@ -58,7 +58,7 @@ typedef unsigned int word_t;
* @n: The current word number that is being used.
* @m: total number of words in 'data'
*/
-#define bitfield_t struct { word_t *data; size_t n, m; }
+typedef struct {word_t *data; size_t n, m; } bitfield_t;
/**
* Initialize the bits.
@@ -97,6 +97,16 @@ typedef unsigned int word_t;
#define bf_release_index(v, id) \
(v).data[bf_index(id)] &= ~(1 << (bf_offset(id)))
+/* check if an id is in use */
+#define bf_test_index(v, id) \
+ ((v).data[bf_index(id)] & (1 << (bf_offset(id))))
+
+/* check if the bit field has been setup */
+#define bf_is_inited(v) ((v).data)
+
+/* compare two bitmaps of the same length */
+#define bf_cmp(v1, v2) (memcmp((v1).data, (v2).data, ((v1).m * sizeof(word_t))))
+
/*
* return 0th index back to bitfield
*/
@@ -146,6 +156,37 @@ typedef unsigned int word_t;
(b) += (w * WORD_SIZE); \
} while (0)
+static inline unsigned int bf_find_next_set_bit(bitfield_t v,
+ word_t start_index)
+{
+ int start_bit;
+ unsigned long i, offset;
+
+ start_bit = start_index & (WORD_SIZE - 1);
+
+ for (i = bf_index(start_index); i < v.m; ++i) {
+ if (v.data[i] == 0) {
+ /* if the whole word is empty move to the next */
+ start_bit = 0;
+ continue;
+ }
+ /* scan one word for set bits */
+ for (offset = start_bit; offset < WORD_SIZE; ++offset) {
+ if ((v.data[i] >> offset) & 1)
+ return ((i * WORD_SIZE) + offset);
+ }
+ /* move to the next word */
+ start_bit = 0;
+ }
+ return WORD_MAX;
+}
+
+/* iterate through all the set bits */
+#define bf_for_each_set_bit(v, b, max) \
+ for ((b) = bf_find_next_set_bit((v), 0); \
+ (b) < max; \
+ (b) = bf_find_next_set_bit((v), (b) + 1))
+
/*
* Free the allocated memory for data
* @v: an instance of bitfield_t struct.
diff --git a/lib/command.c b/lib/command.c
index 80b75d9b23..159ed07b38 100644
--- a/lib/command.c
+++ b/lib/command.c
@@ -904,6 +904,13 @@ static int cmd_execute_command_real(vector vline, enum cmd_filter_type filter,
> vty->candidate_config->version)
nb_config_replace(vty->candidate_config,
running_config, true);
+
+ /*
+ * Perform pending commit (if any) before executing
+ * non-YANG command.
+ */
+ if (matched_element->attr != CMD_ATTR_YANG)
+ nb_cli_pending_commit_check(vty);
}
ret = matched_element->func(matched_element, vty, argc, argv);
diff --git a/lib/command.h b/lib/command.h
index 21bb613540..a7a2eaf868 100644
--- a/lib/command.h
+++ b/lib/command.h
@@ -257,6 +257,12 @@ struct cmd_node {
#define DEFPY_HIDDEN(funcname, cmdname, cmdstr, helpstr) \
DEFPY_ATTR(funcname, cmdname, cmdstr, helpstr, CMD_ATTR_HIDDEN)
+#define DEFPY_YANG(funcname, cmdname, cmdstr, helpstr) \
+ DEFPY_ATTR(funcname, cmdname, cmdstr, helpstr, CMD_ATTR_YANG)
+
+#define DEFPY_YANG_NOSH(funcname, cmdname, cmdstr, helpstr) \
+ DEFPY_YANG(funcname, cmdname, cmdstr, helpstr)
+
#define DEFUN(funcname, cmdname, cmdstr, helpstr) \
DEFUN_CMD_FUNC_DECL(funcname) \
DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, 0, 0) \
@@ -270,10 +276,16 @@ struct cmd_node {
#define DEFUN_HIDDEN(funcname, cmdname, cmdstr, helpstr) \
DEFUN_ATTR(funcname, cmdname, cmdstr, helpstr, CMD_ATTR_HIDDEN)
+#define DEFUN_YANG(funcname, cmdname, cmdstr, helpstr) \
+ DEFUN_ATTR(funcname, cmdname, cmdstr, helpstr, CMD_ATTR_YANG)
+
/* DEFUN_NOSH for commands that vtysh should ignore */
#define DEFUN_NOSH(funcname, cmdname, cmdstr, helpstr) \
DEFUN(funcname, cmdname, cmdstr, helpstr)
+#define DEFUN_YANG_NOSH(funcname, cmdname, cmdstr, helpstr) \
+ DEFUN_YANG(funcname, cmdname, cmdstr, helpstr)
+
/* DEFSH for vtysh. */
#define DEFSH(daemon, cmdname, cmdstr, helpstr) \
DEFUN_CMD_ELEMENT(NULL, cmdname, cmdstr, helpstr, 0, daemon)
@@ -282,6 +294,9 @@ struct cmd_node {
DEFUN_CMD_ELEMENT(NULL, cmdname, cmdstr, helpstr, CMD_ATTR_HIDDEN, \
daemon)
+#define DEFSH_YANG(daemon, cmdname, cmdstr, helpstr) \
+ DEFUN_CMD_ELEMENT(NULL, cmdname, cmdstr, helpstr, CMD_ATTR_YANG, daemon)
+
/* DEFUN + DEFSH */
#define DEFUNSH(daemon, funcname, cmdname, cmdstr, helpstr) \
DEFUN_CMD_FUNC_DECL(funcname) \
@@ -302,6 +317,9 @@ struct cmd_node {
DEFUNSH_ATTR(daemon, funcname, cmdname, cmdstr, helpstr, \
CMD_ATTR_DEPRECATED)
+#define DEFUNSH_YANG(daemon, funcname, cmdname, cmdstr, helpstr) \
+ DEFUNSH_ATTR(daemon, funcname, cmdname, cmdstr, helpstr, CMD_ATTR_YANG)
+
/* ALIAS macro which define existing command's alias. */
#define ALIAS(funcname, cmdname, cmdstr, helpstr) \
DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, 0, 0)
@@ -317,6 +335,9 @@ struct cmd_node {
DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, \
CMD_ATTR_DEPRECATED, 0)
+#define ALIAS_YANG(funcname, cmdname, cmdstr, helpstr) \
+ DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, CMD_ATTR_YANG, 0)
+
#define ALIAS_SH(daemon, funcname, cmdname, cmdstr, helpstr) \
DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, 0, daemon)
@@ -328,18 +349,6 @@ struct cmd_node {
DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, \
CMD_ATTR_DEPRECATED, daemon)
-#else /* VTYSH_EXTRACT_PL */
-#define DEFPY(funcname, cmdname, cmdstr, helpstr) \
- DEFUN(funcname, cmdname, cmdstr, helpstr)
-
-#define DEFPY_NOSH(funcname, cmdname, cmdstr, helpstr) \
- DEFUN_NOSH(funcname, cmdname, cmdstr, helpstr)
-
-#define DEFPY_ATTR(funcname, cmdname, cmdstr, helpstr, attr) \
- DEFUN_ATTR(funcname, cmdname, cmdstr, helpstr, attr)
-
-#define DEFPY_HIDDEN(funcname, cmdname, cmdstr, helpstr) \
- DEFUN_HIDDEN(funcname, cmdname, cmdstr, helpstr)
#endif /* VTYSH_EXTRACT_PL */
/* Some macroes */
diff --git a/lib/command_graph.h b/lib/command_graph.h
index 1efe8b1803..179e104a57 100644
--- a/lib/command_graph.h
+++ b/lib/command_graph.h
@@ -74,6 +74,7 @@ enum cmd_token_type {
enum { CMD_ATTR_NORMAL,
CMD_ATTR_DEPRECATED,
CMD_ATTR_HIDDEN,
+ CMD_ATTR_YANG,
};
/* Comamand token struct. */
diff --git a/lib/defun_lex.l b/lib/defun_lex.l
index 19b06f51b8..bc5fbd24d9 100644
--- a/lib/defun_lex.l
+++ b/lib/defun_lex.l
@@ -140,6 +140,8 @@ SPECIAL [(),]
"DEFPY_NOSH" value = strdup(yytext); return DEFUNNY;
"DEFPY_ATTR" value = strdup(yytext); return DEFUNNY;
"DEFPY_HIDDEN" value = strdup(yytext); return DEFUNNY;
+"DEFPY_YANG" value = strdup(yytext); return DEFUNNY;
+"DEFPY_YANG_NOSH" value = strdup(yytext); return DEFUNNY;
"ALIAS" value = strdup(yytext); return DEFUNNY;
"ALIAS_HIDDEN" value = strdup(yytext); return DEFUNNY;
"install_element" value = strdup(yytext); return INSTALL;
diff --git a/lib/filter.h b/lib/filter.h
index 76e992bf8e..d41f3b65cd 100644
--- a/lib/filter.h
+++ b/lib/filter.h
@@ -170,11 +170,6 @@ enum yang_prefix_list_action {
struct lyd_node;
struct vty;
-extern void access_list_legacy_show(struct vty *vty, struct lyd_node *dnode,
- bool show_defaults);
-extern void access_list_legacy_remark_show(struct vty *vty,
- struct lyd_node *dnode,
- bool show_defaults);
extern void access_list_show(struct vty *vty, struct lyd_node *dnode,
bool show_defaults);
extern void access_list_remark_show(struct vty *vty, struct lyd_node *dnode,
diff --git a/lib/filter_cli.c b/lib/filter_cli.c
index fe8190d098..8c7a515dc5 100644
--- a/lib/filter_cli.c
+++ b/lib/filter_cli.c
@@ -169,7 +169,7 @@ static long acl_get_seq(struct vty *vty, const char *xpath)
/*
* Cisco (legacy) access lists.
*/
-DEFPY(
+DEFPY_YANG(
access_list_std, access_list_std_cmd,
"access-list <(1-99)|(1300-1999)>$number [seq (1-4294967295)$seq] <deny|permit>$action <[host] A.B.C.D$host|A.B.C.D$host A.B.C.D$mask|any>",
ACCESS_LIST_STR
@@ -193,7 +193,8 @@ DEFPY(
* none given (backward compatibility).
*/
snprintf(xpath, sizeof(xpath),
- "/frr-filter:lib/access-list-legacy[number='%s']", number_str);
+ "/frr-filter:lib/access-list[type='ipv4'][name='%s']",
+ number_str);
nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
if (seq_str == NULL) {
/* Use XPath to find the next sequence number. */
@@ -213,13 +214,13 @@ DEFPY(
concat_addr_mask_v4(host_str, mask_str, ipmask, sizeof(ipmask));
nb_cli_enqueue_change(vty, "./network", NB_OP_MODIFY, ipmask);
} else {
- nb_cli_enqueue_change(vty, "./any", NB_OP_CREATE, NULL);
+ nb_cli_enqueue_change(vty, "./source-any", NB_OP_CREATE, NULL);
}
return nb_cli_apply_changes(vty, xpath_entry);
}
-DEFPY(
+DEFPY_YANG(
no_access_list_std, no_access_list_std_cmd,
"no access-list <(1-99)|(1300-1999)>$number [seq (1-4294967295)$seq] <deny|permit>$action <[host] A.B.C.D$host|A.B.C.D$host A.B.C.D$mask|any>",
NO_STR
@@ -244,7 +245,7 @@ DEFPY(
if (seq_str != NULL) {
snprintf(
xpath, sizeof(xpath),
- "/frr-filter:lib/access-list-legacy[number='%s']/entry[sequence='%s']",
+ "/frr-filter:lib/access-list[type='ipv4'][name='%s']/entry[sequence='%s']",
number_str, seq_str);
nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
return nb_cli_apply_changes(vty, NULL);
@@ -252,7 +253,8 @@ DEFPY(
/* Otherwise, to keep compatibility, we need to figure it out. */
snprintf(xpath, sizeof(xpath),
- "/frr-filter:lib/access-list-legacy[number='%s']", number_str);
+ "/frr-filter:lib/access-list[type='ipv4'][name='%s']",
+ number_str);
/* Access-list must exist before entries. */
if (yang_dnode_exists(running_config->dnode, xpath) == false)
@@ -278,7 +280,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
access_list_ext, access_list_ext_cmd,
"access-list <(100-199)|(2000-2699)>$number [seq (1-4294967295)$seq] <deny|permit>$action ip <A.B.C.D$src A.B.C.D$src_mask|host A.B.C.D$src|any> <A.B.C.D$dst A.B.C.D$dst_mask|host A.B.C.D$dst|any>",
ACCESS_LIST_STR
@@ -308,7 +310,8 @@ DEFPY(
* none given (backward compatibility).
*/
snprintf(xpath, sizeof(xpath),
- "/frr-filter:lib/access-list-legacy[number='%s']", number_str);
+ "/frr-filter:lib/access-list[type='ipv4'][name='%s']",
+ number_str);
nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
if (seq_str == NULL) {
/* Use XPath to find the next sequence number. */
@@ -329,7 +332,7 @@ DEFPY(
sizeof(ipmask));
nb_cli_enqueue_change(vty, "./network", NB_OP_MODIFY, ipmask);
} else {
- nb_cli_enqueue_change(vty, "./any", NB_OP_CREATE, NULL);
+ nb_cli_enqueue_change(vty, "./source-any", NB_OP_CREATE, NULL);
}
if (dst_str != NULL && dst_mask_str == NULL) {
@@ -348,7 +351,7 @@ DEFPY(
return nb_cli_apply_changes(vty, xpath_entry);
}
-DEFPY(
+DEFPY_YANG(
no_access_list_ext, no_access_list_ext_cmd,
"no access-list <(100-199)|(2000-2699)>$number [seq (1-4294967295)$seq] <deny|permit>$action ip <A.B.C.D$src A.B.C.D$src_mask|host A.B.C.D$src|any> <A.B.C.D$dst A.B.C.D$dst_mask|host A.B.C.D$dst|any>",
NO_STR
@@ -379,7 +382,7 @@ DEFPY(
if (seq_str != NULL) {
snprintfrr(
xpath, sizeof(xpath),
- "/frr-filter:lib/access-list-legacy[number='%s']/entry[sequence='%s']",
+ "/frr-filter:lib/access-list[type='ipv4'][name='%s']/entry[sequence='%s']",
number_str, seq_str);
nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
return nb_cli_apply_changes(vty, NULL);
@@ -387,7 +390,8 @@ DEFPY(
/* Otherwise, to keep compatibility, we need to figure it out. */
snprintf(xpath, sizeof(xpath),
- "/frr-filter:lib/access-list-legacy[number='%s']", number_str);
+ "/frr-filter:lib/access-list[type='ipv4'][name='%s']",
+ number_str);
/* Access-list must exist before entries. */
if (yang_dnode_exists(running_config->dnode, xpath) == false)
@@ -429,131 +433,10 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
- no_access_list_legacy, no_access_list_legacy_cmd,
- "no access-list <(1-99)|(100-199)|(1300-1999)|(2000-2699)>$number",
- NO_STR
- ACCESS_LIST_STR
- ACCESS_LIST_XLEG_STR)
-{
- char xpath[XPATH_MAXLEN];
-
- snprintf(xpath, sizeof(xpath),
- "/frr-filter:lib/access-list-legacy[number='%s']", number_str);
- nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
-
- return nb_cli_apply_changes(vty, NULL);
-}
-
-void access_list_legacy_show(struct vty *vty, struct lyd_node *dnode,
- bool show_defaults)
-{
- uint16_t number = yang_dnode_get_uint16(dnode, "../number");
- bool extended;
- struct prefix p;
- struct in_addr mask;
-
- vty_out(vty, "access-list %d seq %s %s", number,
- yang_dnode_get_string(dnode, "./sequence"),
- yang_dnode_get_string(dnode, "./action"));
-
- extended = (number >= 100 && number <= 199)
- || (number >= 2000 && number <= 2699);
- if (extended)
- vty_out(vty, " ip");
-
- if (yang_dnode_exists(dnode, "./network")) {
- yang_dnode_get_prefix(&p, dnode, "./network");
- masklen2ip(p.prefixlen, &mask);
- vty_out(vty, " %pI4 %pI4", &p.u.prefix4, &mask);
- } else if (yang_dnode_exists(dnode, "./host")) {
- if (extended)
- vty_out(vty, " host");
-
- vty_out(vty, " %s", yang_dnode_get_string(dnode, "./host"));
- } else if (yang_dnode_exists(dnode, "./any"))
- vty_out(vty, " any");
-
- if (extended) {
- if (yang_dnode_exists(dnode, "./destination-network")) {
- yang_dnode_get_prefix(&p, dnode,
- "./destination-network");
- masklen2ip(p.prefixlen, &mask);
- vty_out(vty, " %pI4 %pI4", &p.u.prefix4, &mask);
- } 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"))
- vty_out(vty, " any");
- }
-
- vty_out(vty, "\n");
-}
-
-DEFPY(
- access_list_legacy_remark, access_list_legacy_remark_cmd,
- "access-list <(1-99)|(100-199)|(1300-1999)|(2000-2699)>$number remark LINE...",
- ACCESS_LIST_STR
- ACCESS_LIST_XLEG_STR
- ACCESS_LIST_REMARK_STR
- ACCESS_LIST_REMARK_LINE_STR)
-{
- int rv;
- char *remark;
- char xpath[XPATH_MAXLEN];
-
- snprintf(xpath, sizeof(xpath),
- "/frr-filter:lib/access-list-legacy[number='%s']", number_str);
- nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
-
- remark = argv_concat(argv, argc, 3);
- nb_cli_enqueue_change(vty, "./remark", NB_OP_CREATE, remark);
- rv = nb_cli_apply_changes(vty, xpath);
- XFREE(MTYPE_TMP, remark);
-
- return rv;
-}
-
-DEFPY(
- no_access_list_legacy_remark, no_access_list_legacy_remark_cmd,
- "no access-list <(1-99)|(100-199)|(1300-1999)|(2000-2699)>$number remark",
- NO_STR
- ACCESS_LIST_STR
- ACCESS_LIST_XLEG_STR
- ACCESS_LIST_REMARK_STR)
-{
- char xpath[XPATH_MAXLEN];
-
- snprintf(xpath, sizeof(xpath),
- "/frr-filter:lib/access-list-legacy[number='%s']/remark",
- number_str);
- nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
-
- return nb_cli_apply_changes(vty, NULL);
-}
-
-ALIAS(
- no_access_list_legacy_remark, no_access_list_legacy_remark_line_cmd,
- "no access-list <(1-99)|(100-199)|(1300-1999)|(2000-2699)>$number remark LINE...",
- NO_STR
- ACCESS_LIST_STR
- ACCESS_LIST_XLEG_STR
- ACCESS_LIST_REMARK_STR
- ACCESS_LIST_REMARK_LINE_STR)
-
-void access_list_legacy_remark_show(struct vty *vty, struct lyd_node *dnode,
- bool show_defaults)
-{
- vty_out(vty, "access-list %s remark %s\n",
- yang_dnode_get_string(dnode, "../number"),
- yang_dnode_get_string(dnode, NULL));
-}
-
/*
* Zebra access lists.
*/
-DEFPY(
+DEFPY_YANG(
access_list, access_list_cmd,
"access-list WORD$name [seq (1-4294967295)$seq] <deny|permit>$action <A.B.C.D/M$prefix [exact-match$exact]|any>",
ACCESS_LIST_STR
@@ -599,7 +482,7 @@ DEFPY(
return nb_cli_apply_changes(vty, xpath_entry);
}
-DEFPY(
+DEFPY_YANG(
no_access_list, no_access_list_cmd,
"no access-list WORD$name [seq (1-4294967295)$seq] <deny|permit>$action <A.B.C.D/M$prefix [exact-match$exact]|any>",
NO_STR
@@ -656,7 +539,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
no_access_list_all, no_access_list_all_cmd,
"no access-list WORD$name",
NO_STR
@@ -672,7 +555,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
access_list_remark, access_list_remark_cmd,
"access-list WORD$name remark LINE...",
ACCESS_LIST_STR
@@ -696,7 +579,7 @@ DEFPY(
return rv;
}
-DEFPY(
+DEFPY_YANG(
no_access_list_remark, no_access_list_remark_cmd,
"no access-list WORD$name remark",
NO_STR
@@ -723,7 +606,7 @@ ALIAS(
ACCESS_LIST_REMARK_STR
ACCESS_LIST_REMARK_LINE_STR)
-DEFPY(
+DEFPY_YANG(
ipv6_access_list, ipv6_access_list_cmd,
"ipv6 access-list WORD$name [seq (1-4294967295)$seq] <deny|permit>$action <X:X::X:X/M$prefix [exact-match$exact]|any>",
IPV6_STR
@@ -770,7 +653,7 @@ DEFPY(
return nb_cli_apply_changes(vty, xpath_entry);
}
-DEFPY(
+DEFPY_YANG(
no_ipv6_access_list, no_ipv6_access_list_cmd,
"no ipv6 access-list WORD$name [seq (1-4294967295)$seq] <deny|permit>$action <X:X::X:X/M$prefix [exact-match$exact]|any>",
NO_STR
@@ -828,7 +711,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
no_ipv6_access_list_all, no_ipv6_access_list_all_cmd,
"no ipv6 access-list WORD$name",
NO_STR
@@ -845,7 +728,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
ipv6_access_list_remark, ipv6_access_list_remark_cmd,
"ipv6 access-list WORD$name remark LINE...",
IPV6_STR
@@ -870,7 +753,7 @@ DEFPY(
return rv;
}
-DEFPY(
+DEFPY_YANG(
no_ipv6_access_list_remark, no_ipv6_access_list_remark_cmd,
"no ipv6 access-list WORD$name remark",
NO_STR
@@ -899,7 +782,7 @@ ALIAS(
ACCESS_LIST_REMARK_STR
ACCESS_LIST_REMARK_LINE_STR)
-DEFPY(
+DEFPY_YANG(
mac_access_list, mac_access_list_cmd,
"mac access-list WORD$name [seq (1-4294967295)$seq] <deny|permit>$action <X:X:X:X:X:X$mac|any>",
MAC_STR
@@ -942,7 +825,7 @@ DEFPY(
return nb_cli_apply_changes(vty, xpath_entry);
}
-DEFPY(
+DEFPY_YANG(
no_mac_access_list, no_mac_access_list_cmd,
"no mac access-list WORD$name [seq (1-4294967295)$seq] <deny|permit>$action <X:X:X:X:X:X$prefix|any>",
NO_STR
@@ -999,7 +882,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
no_mac_access_list_all, no_mac_access_list_all_cmd,
"no mac access-list WORD$name",
NO_STR
@@ -1016,7 +899,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
mac_access_list_remark, mac_access_list_remark_cmd,
"mac access-list WORD$name remark LINE...",
MAC_STR
@@ -1041,7 +924,7 @@ DEFPY(
return rv;
}
-DEFPY(
+DEFPY_YANG(
no_mac_access_list_remark, no_mac_access_list_remark_cmd,
"no mac access-list WORD$name remark",
NO_STR
@@ -1077,6 +960,9 @@ void access_list_show(struct vty *vty, struct lyd_node *dnode,
struct prefix p;
bool is_any;
bool is_exact = false;
+ bool cisco_style = false;
+ bool cisco_extended = false;
+ struct in_addr mask;
char macstr[PREFIX2STR_BUFFER];
is_any = yang_dnode_exists(dnode, "./any");
@@ -1085,8 +971,19 @@ void access_list_show(struct vty *vty, struct lyd_node *dnode,
if (is_any)
break;
- yang_dnode_get_prefix(&p, dnode, "./ipv4-prefix");
- is_exact = yang_dnode_get_bool(dnode, "./ipv4-exact-match");
+ if (yang_dnode_exists(dnode, "./host")
+ || yang_dnode_exists(dnode, "./network")
+ || yang_dnode_exists(dnode, "./source-any")) {
+ cisco_style = true;
+ if (yang_dnode_exists(dnode, "./destination-host")
+ || yang_dnode_exists(dnode, "./destination-network")
+ || yang_dnode_exists(dnode, "./destination-any"))
+ cisco_extended = true;
+ } else {
+ yang_dnode_get_prefix(&p, dnode, "./ipv4-prefix");
+ is_exact = yang_dnode_get_bool(dnode,
+ "./ipv4-exact-match");
+ }
break;
case YALT_IPV6: /* ipv6 */
vty_out(vty, "ipv6 ");
@@ -1110,6 +1007,48 @@ void access_list_show(struct vty *vty, struct lyd_node *dnode,
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_prefix(&p, dnode, "./network");
+ masklen2ip(p.prefixlen, &mask);
+ vty_out(vty, " %pI4 %pI4", &p.u.prefix4, &mask);
+ } 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"))
+ vty_out(vty, " any");
+
+ /* Not extended, exit earlier. */
+ if (!cisco_extended) {
+ vty_out(vty, "\n");
+ return;
+ }
+
+ /* Handle destination address. */
+ if (yang_dnode_exists(dnode, "./destination-network")) {
+ yang_dnode_get_prefix(&p, dnode,
+ "./destination-network");
+ masklen2ip(p.prefixlen, &mask);
+ vty_out(vty, " %pI4 %pI4", &p.u.prefix4, &mask);
+ } 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"))
+ vty_out(vty, " any");
+
+ vty_out(vty, "\n");
+ return;
+ }
+
+ /* Zebra style access list. */
if (!is_any) {
/* If type is MAC don't show '/mask'. */
if (type == 2 /* mac */) {
@@ -1243,7 +1182,7 @@ static int plist_remove(struct vty *vty, const char *iptype, const char *name,
return rv;
}
-DEFPY(
+DEFPY_YANG(
ip_prefix_list, ip_prefix_list_cmd,
"ip prefix-list WORD$name [seq (1-4294967295)$seq] <deny|permit>$action <any|A.B.C.D/M$prefix [{ge (0-32)$ge|le (0-32)$le}]>",
IP_STR
@@ -1300,7 +1239,7 @@ DEFPY(
return nb_cli_apply_changes(vty, xpath_entry);
}
-DEFPY(
+DEFPY_YANG(
no_ip_prefix_list, no_ip_prefix_list_cmd,
"no ip prefix-list WORD$name [seq (1-4294967295)$seq] <deny|permit>$action <any|A.B.C.D/M$prefix [{ge (0-32)|le (0-32)}]>",
NO_STR
@@ -1320,7 +1259,7 @@ DEFPY(
(struct prefix *)prefix, ge, le);
}
-DEFPY(
+DEFPY_YANG(
no_ip_prefix_list_seq, no_ip_prefix_list_seq_cmd,
"no ip prefix-list WORD$name seq (1-4294967295)$seq",
NO_STR
@@ -1332,7 +1271,7 @@ DEFPY(
return plist_remove(vty, "ipv4", name, seq_str, NULL, NULL, 0, 0);
}
-DEFPY(
+DEFPY_YANG(
no_ip_prefix_list_all, no_ip_prefix_list_all_cmd,
"no ip prefix-list WORD$name",
NO_STR
@@ -1349,7 +1288,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
ip_prefix_list_remark, ip_prefix_list_remark_cmd,
"ip prefix-list WORD$name description LINE...",
IP_STR
@@ -1374,7 +1313,7 @@ DEFPY(
return rv;
}
-DEFPY(
+DEFPY_YANG(
no_ip_prefix_list_remark, no_ip_prefix_list_remark_cmd,
"no ip prefix-list WORD$name description",
NO_STR
@@ -1403,7 +1342,7 @@ ALIAS(
ACCESS_LIST_REMARK_STR
ACCESS_LIST_REMARK_LINE_STR)
-DEFPY(
+DEFPY_YANG(
ipv6_prefix_list, ipv6_prefix_list_cmd,
"ipv6 prefix-list WORD$name [seq (1-4294967295)] <deny|permit>$action <any|X:X::X:X/M$prefix [{ge (0-128)$ge|le (0-128)$le}]>",
IPV6_STR
@@ -1460,7 +1399,7 @@ DEFPY(
return nb_cli_apply_changes(vty, xpath_entry);
}
-DEFPY(
+DEFPY_YANG(
no_ipv6_prefix_list, no_ipv6_prefix_list_cmd,
"no ipv6 prefix-list WORD$name [seq (1-4294967295)$seq] <deny|permit>$action <any|X:X::X:X/M$prefix [{ge (0-128)$ge|le (0-128)$le}]>",
NO_STR
@@ -1480,7 +1419,7 @@ DEFPY(
(struct prefix *)prefix, ge, le);
}
-DEFPY(
+DEFPY_YANG(
no_ipv6_prefix_list_seq, no_ipv6_prefix_list_seq_cmd,
"no ipv6 prefix-list WORD$name seq (1-4294967295)$seq",
NO_STR
@@ -1492,7 +1431,7 @@ DEFPY(
return plist_remove(vty, "ipv6", name, seq_str, NULL, NULL, 0, 0);
}
-DEFPY(
+DEFPY_YANG(
no_ipv6_prefix_list_all, no_ipv6_prefix_list_all_cmd,
"no ipv6 prefix-list WORD$name",
NO_STR
@@ -1509,7 +1448,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
ipv6_prefix_list_remark, ipv6_prefix_list_remark_cmd,
"ipv6 prefix-list WORD$name description LINE...",
IPV6_STR
@@ -1534,7 +1473,7 @@ DEFPY(
return rv;
}
-DEFPY(
+DEFPY_YANG(
no_ipv6_prefix_list_remark, no_ipv6_prefix_list_remark_cmd,
"no ipv6 prefix-list WORD$name description",
NO_STR
@@ -1648,10 +1587,6 @@ void filter_cli_init(void)
install_element(CONFIG_NODE, &no_access_list_std_cmd);
install_element(CONFIG_NODE, &access_list_ext_cmd);
install_element(CONFIG_NODE, &no_access_list_ext_cmd);
- install_element(CONFIG_NODE, &no_access_list_legacy_cmd);
- install_element(CONFIG_NODE, &access_list_legacy_remark_cmd);
- install_element(CONFIG_NODE, &no_access_list_legacy_remark_cmd);
- install_element(CONFIG_NODE, &no_access_list_legacy_remark_line_cmd);
/* access-list zebra-style. */
install_element(CONFIG_NODE, &access_list_cmd);
diff --git a/lib/filter_nb.c b/lib/filter_nb.c
index d3d868b468..41bf3cf7f4 100644
--- a/lib/filter_nb.c
+++ b/lib/filter_nb.c
@@ -111,24 +111,38 @@ static void prefix_list_entry_set_empty(struct prefix_list_entry *ple)
}
/*
- * XPath: /frr-filter:lib/access-list-legacy
+ * XPath: /frr-filter:lib/access-list
*/
-static int lib_access_list_legacy_create(struct nb_cb_create_args *args)
+static int lib_access_list_create(struct nb_cb_create_args *args)
{
- struct access_list *acl;
+ struct access_list *acl = NULL;
const char *acl_name;
+ int type;
if (args->event != NB_EV_APPLY)
return NB_OK;
- acl_name = yang_dnode_get_string(args->dnode, "./number");
- acl = access_list_get(AFI_IP, acl_name);
+ type = yang_dnode_get_enum(args->dnode, "./type");
+ acl_name = yang_dnode_get_string(args->dnode, "./name");
+
+ switch (type) {
+ case YALT_IPV4:
+ acl = access_list_get(AFI_IP, acl_name);
+ break;
+ case YALT_IPV6:
+ acl = access_list_get(AFI_IP6, acl_name);
+ break;
+ case YALT_MAC:
+ acl = access_list_get(AFI_L2VPN, acl_name);
+ break;
+ }
+
nb_running_set_entry(args->dnode, acl);
return NB_OK;
}
-static int lib_access_list_legacy_destroy(struct nb_cb_destroy_args *args)
+static int lib_access_list_destroy(struct nb_cb_destroy_args *args)
{
struct access_master *am;
struct access_list *acl;
@@ -147,9 +161,9 @@ static int lib_access_list_legacy_destroy(struct nb_cb_destroy_args *args)
}
/*
- * XPath: /frr-filter:lib/access-list-legacy/remark
+ * XPath: /frr-filter:lib/access-list/remark
*/
-static int lib_access_list_legacy_remark_modify(struct nb_cb_modify_args *args)
+static int lib_access_list_remark_modify(struct nb_cb_modify_args *args)
{
struct access_list *acl;
const char *remark;
@@ -168,7 +182,7 @@ static int lib_access_list_legacy_remark_modify(struct nb_cb_modify_args *args)
}
static int
-lib_access_list_legacy_remark_destroy(struct nb_cb_destroy_args *args)
+lib_access_list_remark_destroy(struct nb_cb_destroy_args *args)
{
struct access_list *acl;
@@ -182,31 +196,20 @@ lib_access_list_legacy_remark_destroy(struct nb_cb_destroy_args *args)
return NB_OK;
}
+
/*
- * XPath: /frr-filter:lib/access-list-legacy/entry
+ * XPath: /frr-filter:lib/access-list/entry
*/
-static int lib_access_list_legacy_entry_create(struct nb_cb_create_args *args)
+static int lib_access_list_entry_create(struct nb_cb_create_args *args)
{
- struct filter_cisco *fc;
struct access_list *acl;
struct filter *f;
- uint32_t aclno;
-
- /* TODO: validate `filter_lookup_cisco` returns NULL. */
if (args->event != NB_EV_APPLY)
return NB_OK;
- aclno = yang_dnode_get_uint16(args->dnode, "../number");
-
f = filter_new();
- f->cisco = 1;
f->seq = yang_dnode_get_uint32(args->dnode, "./sequence");
- fc = &f->u.cfilter;
- if ((aclno >= 1 && aclno <= 99) || (aclno >= 1300 && aclno <= 1999))
- fc->extended = 0;
- else
- fc->extended = 1;
acl = nb_running_get_entry(args->dnode, NULL, true);
f->acl = acl;
@@ -216,7 +219,7 @@ static int lib_access_list_legacy_entry_create(struct nb_cb_create_args *args)
return NB_OK;
}
-static int lib_access_list_legacy_entry_destroy(struct nb_cb_destroy_args *args)
+static int lib_access_list_entry_destroy(struct nb_cb_destroy_args *args)
{
struct access_list *acl;
struct filter *f;
@@ -232,10 +235,10 @@ static int lib_access_list_legacy_entry_destroy(struct nb_cb_destroy_args *args)
}
/*
- * XPath: /frr-filter:lib/access-list-legacy/entry/action
+ * XPath: /frr-filter:lib/access-list/entry/action
*/
static int
-lib_access_list_legacy_entry_action_modify(struct nb_cb_modify_args *args)
+lib_access_list_entry_action_modify(struct nb_cb_modify_args *args)
{
const char *filter_type;
struct filter *f;
@@ -254,86 +257,81 @@ lib_access_list_legacy_entry_action_modify(struct nb_cb_modify_args *args)
}
/*
- * XPath: /frr-filter:lib/access-list-legacy/entry/host
+ * XPath: /frr-filter:lib/access-list/entry/ipv4-prefix
*/
static int
-lib_access_list_legacy_entry_host_modify(struct nb_cb_modify_args *args)
+lib_access_list_entry_ipv4_prefix_modify(struct nb_cb_modify_args *args)
{
- struct filter_cisco *fc;
+ struct filter_zebra *fz;
struct filter *f;
if (args->event != NB_EV_APPLY)
return NB_OK;
f = nb_running_get_entry(args->dnode, NULL, true);
- fc = &f->u.cfilter;
- yang_dnode_get_ipv4(&fc->addr, args->dnode, NULL);
- fc->addr_mask.s_addr = INADDR_ANY;
+ f->cisco = 0;
+ fz = &f->u.zfilter;
+ yang_dnode_get_prefix(&fz->prefix, args->dnode, NULL);
return NB_OK;
}
static int
-lib_access_list_legacy_entry_host_destroy(struct nb_cb_destroy_args *args)
+lib_access_list_entry_ipv4_prefix_destroy(struct nb_cb_destroy_args *args)
{
- struct filter_cisco *fc;
+ struct filter_zebra *fz;
struct filter *f;
if (args->event != NB_EV_APPLY)
return NB_OK;
f = nb_running_get_entry(args->dnode, NULL, true);
- fc = &f->u.cfilter;
- fc->addr.s_addr = INADDR_ANY;
- fc->addr_mask.s_addr = INADDR_NONE;
+ fz = &f->u.zfilter;
+ memset(&fz->prefix, 0, sizeof(fz->prefix));
return NB_OK;
}
/*
- * XPath: /frr-filter:lib/access-list-legacy/entry/network
+ * XPath: /frr-filter:lib/access-list/entry/ipv4-exact-match
*/
static int
-lib_access_list_legacy_entry_network_modify(struct nb_cb_modify_args *args)
+lib_access_list_entry_ipv4_exact_match_modify(struct nb_cb_modify_args *args)
{
- struct filter_cisco *fc;
+ struct filter_zebra *fz;
struct filter *f;
- struct prefix p;
if (args->event != NB_EV_APPLY)
return NB_OK;
f = nb_running_get_entry(args->dnode, NULL, true);
- fc = &f->u.cfilter;
- yang_dnode_get_prefix(&p, args->dnode, NULL);
- fc->addr.s_addr = ipv4_network_addr(p.u.prefix4.s_addr, p.prefixlen);
- masklen2ip(p.prefixlen, &fc->addr_mask);
+ fz = &f->u.zfilter;
+ fz->exact = yang_dnode_get_bool(args->dnode, NULL);
return NB_OK;
}
static int
-lib_access_list_legacy_entry_network_destroy(struct nb_cb_destroy_args *args)
+lib_access_list_entry_ipv4_exact_match_destroy(struct nb_cb_destroy_args *args)
{
- struct filter_cisco *fc;
+ struct filter_zebra *fz;
struct filter *f;
if (args->event != NB_EV_APPLY)
return NB_OK;
f = nb_running_get_entry(args->dnode, NULL, true);
- fc = &f->u.cfilter;
- fc->addr.s_addr = INADDR_ANY;
- fc->addr_mask.s_addr = INADDR_NONE;
+ fz = &f->u.zfilter;
+ fz->exact = 0;
return NB_OK;
}
/*
- * XPath: /frr-filter:lib/access-list-legacy/entry/any
+ * XPath: /frr-filter:lib/access-list/entry/host
*/
static int
-lib_access_list_legacy_entry_any_create(struct nb_cb_create_args *args)
+lib_access_list_entry_host_modify(struct nb_cb_modify_args *args)
{
struct filter_cisco *fc;
struct filter *f;
@@ -342,15 +340,16 @@ lib_access_list_legacy_entry_any_create(struct nb_cb_create_args *args)
return NB_OK;
f = nb_running_get_entry(args->dnode, NULL, true);
+ f->cisco = 1;
fc = &f->u.cfilter;
- fc->addr.s_addr = INADDR_ANY;
- fc->addr_mask.s_addr = INADDR_NONE;
+ yang_dnode_get_ipv4(&fc->addr, args->dnode, NULL);
+ fc->addr_mask.s_addr = INADDR_ANY;
return NB_OK;
}
static int
-lib_access_list_legacy_entry_any_destroy(struct nb_cb_destroy_args *args)
+lib_access_list_entry_host_destroy(struct nb_cb_destroy_args *args)
{
struct filter_cisco *fc;
struct filter *f;
@@ -367,27 +366,30 @@ lib_access_list_legacy_entry_any_destroy(struct nb_cb_destroy_args *args)
}
/*
- * XPath: /frr-filter:lib/access-list-legacy/entry/destination-host
+ * XPath: /frr-filter:lib/access-list/entry/network
*/
-static int lib_access_list_legacy_entry_destination_host_modify(
- struct nb_cb_modify_args *args)
+static int
+lib_access_list_entry_network_modify(struct nb_cb_modify_args *args)
{
struct filter_cisco *fc;
struct filter *f;
+ struct prefix p;
if (args->event != NB_EV_APPLY)
return NB_OK;
f = nb_running_get_entry(args->dnode, NULL, true);
+ f->cisco = 1;
fc = &f->u.cfilter;
- yang_dnode_get_ipv4(&fc->mask, args->dnode, NULL);
- fc->mask_mask.s_addr = INADDR_ANY;
+ yang_dnode_get_prefix(&p, args->dnode, NULL);
+ fc->addr.s_addr = ipv4_network_addr(p.u.prefix4.s_addr, p.prefixlen);
+ masklen2ip(p.prefixlen, &fc->addr_mask);
return NB_OK;
}
-static int lib_access_list_legacy_entry_destination_host_destroy(
- struct nb_cb_destroy_args *args)
+static int
+lib_access_list_entry_network_destroy(struct nb_cb_destroy_args *args)
{
struct filter_cisco *fc;
struct filter *f;
@@ -397,36 +399,35 @@ static int lib_access_list_legacy_entry_destination_host_destroy(
f = nb_running_get_entry(args->dnode, NULL, true);
fc = &f->u.cfilter;
- fc->mask.s_addr = INADDR_ANY;
- fc->mask_mask.s_addr = INADDR_NONE;
+ fc->addr.s_addr = INADDR_ANY;
+ fc->addr_mask.s_addr = INADDR_NONE;
return NB_OK;
}
/*
- * XPath: /frr-filter:lib/access-list-legacy/entry/destination-network
+ * XPath: /frr-filter:lib/access-list/entry/source-any
*/
-static int lib_access_list_legacy_entry_destination_network_modify(
- struct nb_cb_modify_args *args)
+static int
+lib_access_list_entry_source_any_create(struct nb_cb_create_args *args)
{
struct filter_cisco *fc;
struct filter *f;
- struct prefix p;
if (args->event != NB_EV_APPLY)
return NB_OK;
f = nb_running_get_entry(args->dnode, NULL, true);
+ f->cisco = 1;
fc = &f->u.cfilter;
- yang_dnode_get_prefix(&p, args->dnode, NULL);
- fc->mask.s_addr = ipv4_network_addr(p.u.prefix4.s_addr, p.prefixlen);
- masklen2ip(p.prefixlen, &fc->mask_mask);
+ fc->addr.s_addr = INADDR_ANY;
+ fc->addr_mask.s_addr = INADDR_NONE;
return NB_OK;
}
-static int lib_access_list_legacy_entry_destination_network_destroy(
- struct nb_cb_destroy_args *args)
+static int
+lib_access_list_entry_source_any_destroy(struct nb_cb_destroy_args *args)
{
struct filter_cisco *fc;
struct filter *f;
@@ -436,17 +437,17 @@ static int lib_access_list_legacy_entry_destination_network_destroy(
f = nb_running_get_entry(args->dnode, NULL, true);
fc = &f->u.cfilter;
- fc->mask.s_addr = INADDR_ANY;
- fc->mask_mask.s_addr = INADDR_NONE;
+ fc->addr.s_addr = INADDR_ANY;
+ fc->addr_mask.s_addr = INADDR_NONE;
return NB_OK;
}
/*
- * XPath: /frr-filter:lib/access-list-legacy/entry/destination-any
+ * XPath: /frr-filter:lib/access-list/entry/destination-host
*/
-static int lib_access_list_legacy_entry_destination_any_create(
- struct nb_cb_create_args *args)
+static int lib_access_list_entry_destination_host_modify(
+ struct nb_cb_modify_args *args)
{
struct filter_cisco *fc;
struct filter *f;
@@ -456,13 +457,14 @@ static int lib_access_list_legacy_entry_destination_any_create(
f = nb_running_get_entry(args->dnode, NULL, true);
fc = &f->u.cfilter;
- fc->mask.s_addr = INADDR_ANY;
- fc->mask_mask.s_addr = INADDR_NONE;
+ fc->extended = 1;
+ yang_dnode_get_ipv4(&fc->mask, args->dnode, NULL);
+ fc->mask_mask.s_addr = INADDR_ANY;
return NB_OK;
}
-static int lib_access_list_legacy_entry_destination_any_destroy(
+static int lib_access_list_entry_destination_host_destroy(
struct nb_cb_destroy_args *args)
{
struct filter_cisco *fc;
@@ -473,6 +475,7 @@ static int lib_access_list_legacy_entry_destination_any_destroy(
f = nb_running_get_entry(args->dnode, NULL, true);
fc = &f->u.cfilter;
+ fc->extended = 0;
fc->mask.s_addr = INADDR_ANY;
fc->mask_mask.s_addr = INADDR_NONE;
@@ -480,160 +483,81 @@ static int lib_access_list_legacy_entry_destination_any_destroy(
}
/*
- * XPath: /frr-filter:lib/access-list
- */
-static int lib_access_list_create(struct nb_cb_create_args *args)
-{
- struct access_list *acl = NULL;
- const char *acl_name;
- int type;
-
- 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");
-
- switch (type) {
- case YALT_IPV4:
- acl = access_list_get(AFI_IP, acl_name);
- break;
- case YALT_IPV6:
- acl = access_list_get(AFI_IP6, acl_name);
- break;
- case YALT_MAC:
- acl = access_list_get(AFI_L2VPN, acl_name);
- break;
- }
-
- nb_running_set_entry(args->dnode, acl);
-
- return NB_OK;
-}
-
-static int lib_access_list_destroy(struct nb_cb_destroy_args *args)
-{
- struct access_master *am;
- struct access_list *acl;
-
- if (args->event != NB_EV_APPLY)
- return NB_OK;
-
- acl = nb_running_unset_entry(args->dnode);
- am = acl->master;
- if (am->delete_hook)
- am->delete_hook(acl);
-
- access_list_delete(acl);
-
- return NB_OK;
-}
-
-/*
- * XPath: /frr-filter:lib/access-list/entry
- */
-static int lib_access_list_entry_create(struct nb_cb_create_args *args)
-{
- struct access_list *acl;
- struct filter *f;
-
- /* TODO: validate `filter_lookup_zebra` returns NULL. */
-
- if (args->event != NB_EV_APPLY)
- return NB_OK;
-
- f = filter_new();
- f->seq = yang_dnode_get_uint32(args->dnode, "./sequence");
-
- acl = nb_running_get_entry(args->dnode, NULL, true);
- f->acl = acl;
- access_list_filter_add(acl, f);
- nb_running_set_entry(args->dnode, f);
-
- return NB_OK;
-}
-
-static int lib_access_list_entry_destroy(struct nb_cb_destroy_args *args)
-{
- struct access_list *acl;
- struct filter *f;
-
- if (args->event != NB_EV_APPLY)
- return NB_OK;
-
- f = nb_running_unset_entry(args->dnode);
- acl = f->acl;
- access_list_filter_delete(acl, f);
-
- return NB_OK;
-}
-
-/*
- * XPath: /frr-filter:lib/access-list/entry/ipv4-prefix
+ * XPath: /frr-filter:lib/access-list/entry/destination-network
*/
-static int
-lib_access_list_entry_ipv4_prefix_modify(struct nb_cb_modify_args *args)
+static int lib_access_list_entry_destination_network_modify(
+ struct nb_cb_modify_args *args)
{
- struct filter_zebra *fz;
+ struct filter_cisco *fc;
struct filter *f;
+ struct prefix p;
if (args->event != NB_EV_APPLY)
return NB_OK;
f = nb_running_get_entry(args->dnode, NULL, true);
- fz = &f->u.zfilter;
- yang_dnode_get_prefix(&fz->prefix, args->dnode, NULL);
+ fc = &f->u.cfilter;
+ fc->extended = 1;
+ yang_dnode_get_prefix(&p, args->dnode, NULL);
+ fc->mask.s_addr = ipv4_network_addr(p.u.prefix4.s_addr, p.prefixlen);
+ masklen2ip(p.prefixlen, &fc->mask_mask);
return NB_OK;
}
-static int
-lib_access_list_entry_ipv4_prefix_destroy(struct nb_cb_destroy_args *args)
+static int lib_access_list_entry_destination_network_destroy(
+ struct nb_cb_destroy_args *args)
{
- struct filter_zebra *fz;
+ struct filter_cisco *fc;
struct filter *f;
if (args->event != NB_EV_APPLY)
return NB_OK;
f = nb_running_get_entry(args->dnode, NULL, true);
- fz = &f->u.zfilter;
- memset(&fz->prefix, 0, sizeof(fz->prefix));
+ fc = &f->u.cfilter;
+ fc->extended = 0;
+ fc->mask.s_addr = INADDR_ANY;
+ fc->mask_mask.s_addr = INADDR_NONE;
return NB_OK;
}
/*
- * XPath: /frr-filter:lib/access-list/entry/ipv4-exact-match
+ * XPath: /frr-filter:lib/access-list/entry/destination-any
*/
-static int
-lib_access_list_entry_ipv4_exact_match_modify(struct nb_cb_modify_args *args)
+static int lib_access_list_entry_destination_any_create(
+ struct nb_cb_create_args *args)
{
- struct filter_zebra *fz;
+ struct filter_cisco *fc;
struct filter *f;
if (args->event != NB_EV_APPLY)
return NB_OK;
f = nb_running_get_entry(args->dnode, NULL, true);
- fz = &f->u.zfilter;
- fz->exact = yang_dnode_get_bool(args->dnode, NULL);
+ fc = &f->u.cfilter;
+ fc->extended = 1;
+ fc->mask.s_addr = INADDR_ANY;
+ fc->mask_mask.s_addr = INADDR_NONE;
return NB_OK;
}
-static int
-lib_access_list_entry_ipv4_exact_match_destroy(struct nb_cb_destroy_args *args)
+static int lib_access_list_entry_destination_any_destroy(
+ struct nb_cb_destroy_args *args)
{
- struct filter_zebra *fz;
+ struct filter_cisco *fc;
struct filter *f;
if (args->event != NB_EV_APPLY)
return NB_OK;
f = nb_running_get_entry(args->dnode, NULL, true);
- fz = &f->u.zfilter;
- fz->exact = 0;
+ fc = &f->u.cfilter;
+ fc->extended = 0;
+ fc->mask.s_addr = INADDR_ANY;
+ fc->mask_mask.s_addr = INADDR_NONE;
return NB_OK;
}
@@ -651,6 +575,7 @@ static int lib_access_list_entry_any_create(struct nb_cb_create_args *args)
return NB_OK;
f = nb_running_get_entry(args->dnode, NULL, true);
+ f->cisco = 0;
fz = &f->u.zfilter;
memset(&fz->prefix, 0, sizeof(fz->prefix));
@@ -1059,117 +984,88 @@ const struct frr_yang_module_info frr_filter_info = {
.name = "frr-filter",
.nodes = {
{
- .xpath = "/frr-filter:lib/access-list-legacy",
- .cbs = {
- .create = lib_access_list_legacy_create,
- .destroy = lib_access_list_legacy_destroy,
- }
- },
- {
- .xpath = "/frr-filter:lib/access-list-legacy/remark",
- .cbs = {
- .modify = lib_access_list_legacy_remark_modify,
- .destroy = lib_access_list_legacy_remark_destroy,
- .cli_show = access_list_legacy_remark_show,
- }
- },
- {
- .xpath = "/frr-filter:lib/access-list-legacy/entry",
- .cbs = {
- .create = lib_access_list_legacy_entry_create,
- .destroy = lib_access_list_legacy_entry_destroy,
- .cli_show = access_list_legacy_show,
- }
- },
- {
- .xpath = "/frr-filter:lib/access-list-legacy/entry/action",
- .cbs = {
- .modify = lib_access_list_legacy_entry_action_modify,
- }
- },
- {
- .xpath = "/frr-filter:lib/access-list-legacy/entry/host",
+ .xpath = "/frr-filter:lib/access-list",
.cbs = {
- .modify = lib_access_list_legacy_entry_host_modify,
- .destroy = lib_access_list_legacy_entry_host_destroy,
+ .create = lib_access_list_create,
+ .destroy = lib_access_list_destroy,
}
},
{
- .xpath = "/frr-filter:lib/access-list-legacy/entry/network",
+ .xpath = "/frr-filter:lib/access-list/remark",
.cbs = {
- .modify = lib_access_list_legacy_entry_network_modify,
- .destroy = lib_access_list_legacy_entry_network_destroy,
+ .modify = lib_access_list_remark_modify,
+ .destroy = lib_access_list_remark_destroy,
+ .cli_show = access_list_remark_show,
}
},
{
- .xpath = "/frr-filter:lib/access-list-legacy/entry/any",
+ .xpath = "/frr-filter:lib/access-list/entry",
.cbs = {
- .create = lib_access_list_legacy_entry_any_create,
- .destroy = lib_access_list_legacy_entry_any_destroy,
+ .create = lib_access_list_entry_create,
+ .destroy = lib_access_list_entry_destroy,
+ .cli_show = access_list_show,
}
},
{
- .xpath = "/frr-filter:lib/access-list-legacy/entry/destination-host",
+ .xpath = "/frr-filter:lib/access-list/entry/action",
.cbs = {
- .modify = lib_access_list_legacy_entry_destination_host_modify,
- .destroy = lib_access_list_legacy_entry_destination_host_destroy,
+ .modify = lib_access_list_entry_action_modify,
}
},
{
- .xpath = "/frr-filter:lib/access-list-legacy/entry/destination-network",
+ .xpath = "/frr-filter:lib/access-list/entry/ipv4-prefix",
.cbs = {
- .modify = lib_access_list_legacy_entry_destination_network_modify,
- .destroy = lib_access_list_legacy_entry_destination_network_destroy,
+ .modify = lib_access_list_entry_ipv4_prefix_modify,
+ .destroy = lib_access_list_entry_ipv4_prefix_destroy,
}
},
{
- .xpath = "/frr-filter:lib/access-list-legacy/entry/destination-any",
+ .xpath = "/frr-filter:lib/access-list/entry/ipv4-exact-match",
.cbs = {
- .create = lib_access_list_legacy_entry_destination_any_create,
- .destroy = lib_access_list_legacy_entry_destination_any_destroy,
+ .modify = lib_access_list_entry_ipv4_exact_match_modify,
+ .destroy = lib_access_list_entry_ipv4_exact_match_destroy,
}
},
{
- .xpath = "/frr-filter:lib/access-list",
+ .xpath = "/frr-filter:lib/access-list/entry/host",
.cbs = {
- .create = lib_access_list_create,
- .destroy = lib_access_list_destroy,
+ .modify = lib_access_list_entry_host_modify,
+ .destroy = lib_access_list_entry_host_destroy,
}
},
{
- .xpath = "/frr-filter:lib/access-list/remark",
+ .xpath = "/frr-filter:lib/access-list/entry/network",
.cbs = {
- .modify = lib_access_list_legacy_remark_modify,
- .destroy = lib_access_list_legacy_remark_destroy,
- .cli_show = access_list_remark_show,
+ .modify = lib_access_list_entry_network_modify,
+ .destroy = lib_access_list_entry_network_destroy,
}
},
{
- .xpath = "/frr-filter:lib/access-list/entry",
+ .xpath = "/frr-filter:lib/access-list/entry/source-any",
.cbs = {
- .create = lib_access_list_entry_create,
- .destroy = lib_access_list_entry_destroy,
- .cli_show = access_list_show,
+ .create = lib_access_list_entry_source_any_create,
+ .destroy = lib_access_list_entry_source_any_destroy,
}
},
{
- .xpath = "/frr-filter:lib/access-list/entry/action",
+ .xpath = "/frr-filter:lib/access-list/entry/destination-host",
.cbs = {
- .modify = lib_access_list_legacy_entry_action_modify,
+ .modify = lib_access_list_entry_destination_host_modify,
+ .destroy = lib_access_list_entry_destination_host_destroy,
}
},
{
- .xpath = "/frr-filter:lib/access-list/entry/ipv4-prefix",
+ .xpath = "/frr-filter:lib/access-list/entry/destination-network",
.cbs = {
- .modify = lib_access_list_entry_ipv4_prefix_modify,
- .destroy = lib_access_list_entry_ipv4_prefix_destroy,
+ .modify = lib_access_list_entry_destination_network_modify,
+ .destroy = lib_access_list_entry_destination_network_destroy,
}
},
{
- .xpath = "/frr-filter:lib/access-list/entry/ipv4-exact-match",
+ .xpath = "/frr-filter:lib/access-list/entry/destination-any",
.cbs = {
- .modify = lib_access_list_entry_ipv4_exact_match_modify,
- .destroy = lib_access_list_entry_ipv4_exact_match_destroy,
+ .create = lib_access_list_entry_destination_any_create,
+ .destroy = lib_access_list_entry_destination_any_destroy,
}
},
{
diff --git a/lib/if.c b/lib/if.c
index 3620f20e4b..d8392708e1 100644
--- a/lib/if.c
+++ b/lib/if.c
@@ -217,16 +217,14 @@ struct interface *if_create_name(const char *name, vrf_id_t vrf_id)
return ifp;
}
-struct interface *if_create_ifindex(ifindex_t ifindex, vrf_id_t vrf_id,
- char *optional_name)
+struct interface *if_create_ifindex(ifindex_t ifindex, vrf_id_t vrf_id)
{
struct interface *ifp;
ifp = if_new(vrf_id);
if_set_index(ifp, ifindex);
- if (optional_name)
- if_set_name(ifp, optional_name);
+
hook_call(if_add, ifp);
return ifp;
}
@@ -573,8 +571,7 @@ struct interface *if_get_by_name(const char *name, vrf_id_t vrf_id)
return NULL;
}
-struct interface *if_get_by_ifindex(ifindex_t ifindex, vrf_id_t vrf_id,
- char *optional_name)
+struct interface *if_get_by_ifindex(ifindex_t ifindex, vrf_id_t vrf_id)
{
struct interface *ifp;
@@ -584,7 +581,7 @@ struct interface *if_get_by_ifindex(ifindex_t ifindex, vrf_id_t vrf_id,
ifp = if_lookup_by_ifindex(ifindex, vrf_id);
if (ifp)
return ifp;
- return if_create_ifindex(ifindex, vrf_id, optional_name);
+ return if_create_ifindex(ifindex, vrf_id);
case VRF_BACKEND_VRF_LITE:
ifp = if_lookup_by_index_all_vrf(ifindex);
if (ifp) {
@@ -596,7 +593,7 @@ struct interface *if_get_by_ifindex(ifindex_t ifindex, vrf_id_t vrf_id,
if_update_to_new_vrf(ifp, vrf_id);
return ifp;
}
- return if_create_ifindex(ifindex, vrf_id, optional_name);
+ return if_create_ifindex(ifindex, vrf_id);
}
return NULL;
@@ -1321,7 +1318,7 @@ void if_link_params_free(struct interface *ifp)
/*
* XPath: /frr-interface:lib/interface
*/
-DEFPY_NOSH (interface,
+DEFPY_YANG_NOSH (interface,
interface_cmd,
"interface IFNAME [vrf NAME$vrf_name]",
"Select an interface to configure\n"
@@ -1384,6 +1381,7 @@ DEFPY_NOSH (interface,
* all interface-level commands are converted to the new
* northbound model.
*/
+ nb_cli_pending_commit_check(vty);
ifp = if_lookup_by_name(ifname, vrf_id);
if (ifp)
VTY_PUSH_CONTEXT(INTERFACE_NODE, ifp);
@@ -1392,7 +1390,7 @@ DEFPY_NOSH (interface,
return ret;
}
-DEFPY (no_interface,
+DEFPY_YANG (no_interface,
no_interface_cmd,
"no interface IFNAME [vrf NAME$vrf_name]",
NO_STR
@@ -1427,7 +1425,7 @@ static void cli_show_interface(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-interface:lib/interface/description
*/
-DEFPY (interface_desc,
+DEFPY_YANG (interface_desc,
interface_desc_cmd,
"description LINE...",
"Interface specific description\n"
@@ -1444,7 +1442,7 @@ DEFPY (interface_desc,
return ret;
}
-DEFPY (no_interface_desc,
+DEFPY_YANG (no_interface_desc,
no_interface_desc_cmd,
"no description",
NO_STR
diff --git a/lib/if.h b/lib/if.h
index 40e87c1e31..1fb0757db2 100644
--- a/lib/if.h
+++ b/lib/if.h
@@ -509,8 +509,7 @@ extern void if_update_to_new_vrf(struct interface *, vrf_id_t vrf_id);
extern struct interface *if_create_name(const char *name, vrf_id_t vrf_id);
/* Create new interface, adds to index list only */
-extern struct interface *if_create_ifindex(ifindex_t ifindex, vrf_id_t vrf_id,
- char *name);
+extern struct interface *if_create_ifindex(ifindex_t ifindex, 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_all_vrf(ifindex_t);
extern struct interface *if_lookup_exact_address(const void *matchaddr,
@@ -527,8 +526,8 @@ extern struct interface *if_lookup_by_name_all_vrf(const char *ifname);
extern struct interface *if_lookup_by_name_vrf(const char *name, struct vrf *vrf);
extern struct interface *if_lookup_by_name(const char *ifname, vrf_id_t vrf_id);
extern struct interface *if_get_by_name(const char *ifname, vrf_id_t vrf_id);
-extern struct interface *if_get_by_ifindex(ifindex_t ifindex, vrf_id_t vrf_id,
- char *optional_name);
+extern struct interface *if_get_by_ifindex(ifindex_t ifindex, vrf_id_t vrf_id);
+
/* Sets the index and adds to index list */
extern int if_set_index(struct interface *ifp, ifindex_t ifindex);
/* Sets the name and adds to name list */
diff --git a/lib/ipaddr.h b/lib/ipaddr.h
index cd7f79a04e..f2b75c1306 100644
--- a/lib/ipaddr.h
+++ b/lib/ipaddr.h
@@ -33,9 +33,9 @@ extern "C" {
* Generic IP address - union of IPv4 and IPv6 address.
*/
enum ipaddr_type_t {
- IPADDR_NONE = 0,
- IPADDR_V4 = 1, /* IPv4 */
- IPADDR_V6 = 2, /* IPv6 */
+ IPADDR_NONE = AF_UNSPEC,
+ IPADDR_V4 = AF_INET,
+ IPADDR_V6 = AF_INET6,
};
struct ipaddr {
@@ -84,15 +84,18 @@ static inline int str2ipaddr(const char *str, struct ipaddr *ip)
static inline char *ipaddr2str(const struct ipaddr *ip, char *buf, int size)
{
buf[0] = '\0';
- if (ip) {
- if (IS_IPADDR_V4(ip))
- inet_ntop(AF_INET, &ip->ip.addr, buf, size);
- else if (IS_IPADDR_V6(ip))
- inet_ntop(AF_INET6, &ip->ip.addr, buf, size);
- }
+ if (ip)
+ inet_ntop(ip->ipa_type, &ip->ip.addr, buf, size);
return buf;
}
+#define IS_MAPPED_IPV6(A) \
+ ((A)->s6_addr32[0] == 0x00000000 \
+ ? ((A)->s6_addr32[1] == 0x00000000 \
+ ? (ntohl((A)->s6_addr32[2]) == 0xFFFF ? 1 : 0) \
+ : 0) \
+ : 0)
+
/*
* Convert IPv4 address to IPv4-mapped IPv6 address which is of the
* form ::FFFF:<IPv4 address> (RFC 4291). This IPv6 address can then
@@ -128,6 +131,10 @@ static inline bool ipaddr_isset(struct ipaddr *ip)
return (0 != memcmp(&a, ip, sizeof(struct ipaddr)));
}
+#ifdef _FRR_ATTRIBUTE_PRINTFRR
+#pragma FRR printfrr_ext "%pIA" (struct ipaddr *)
+#endif
+
#ifdef __cplusplus
}
#endif
diff --git a/lib/libfrr.c b/lib/libfrr.c
index b3df7de6d3..2597eb61e2 100644
--- a/lib/libfrr.c
+++ b/lib/libfrr.c
@@ -105,6 +105,7 @@ static const struct option lo_always[] = {
{"daemon", no_argument, NULL, 'd'},
{"module", no_argument, NULL, 'M'},
{"profile", required_argument, NULL, 'F'},
+ {"pathspace", required_argument, NULL, 'N'},
{"vty_socket", required_argument, NULL, OPTION_VTYSOCK},
{"moduledir", required_argument, NULL, OPTION_MODULEDIR},
{"log", required_argument, NULL, OPTION_LOG},
@@ -113,12 +114,13 @@ static const struct option lo_always[] = {
{"command-log-always", no_argument, NULL, OPTION_LOGGING},
{NULL}};
static const struct optspec os_always = {
- "hvdM:F:",
+ "hvdM:F:N:",
" -h, --help Display this help and exit\n"
" -v, --version Print program version\n"
" -d, --daemon Runs in daemon mode\n"
" -M, --module Load specified module\n"
" -F, --profile Use specified configuration profile\n"
+ " -N, --pathspace Insert prefix into config & socket paths\n"
" --vty_socket Override vty socket path\n"
" --moduledir Override modules directory\n"
" --log Set Logging to stdout, syslog, or file:<name>\n"
@@ -133,18 +135,16 @@ static const struct option lo_cfg_pid_dry[] = {
#ifdef HAVE_SQLITE3
{"db_file", required_argument, NULL, OPTION_DB_FILE},
#endif
- {"pathspace", required_argument, NULL, 'N'},
{"dryrun", no_argument, NULL, 'C'},
{"terminal", no_argument, NULL, 't'},
{NULL}};
static const struct optspec os_cfg_pid_dry = {
- "f:i:CtN:",
+ "f:i:Ct",
" -f, --config_file Set configuration file name\n"
" -i, --pid_file Set process identifier file name\n"
#ifdef HAVE_SQLITE3
" --db_file Set database file name\n"
#endif
- " -N, --pathspace Insert prefix into config & socket paths\n"
" -C, --dryrun Check configuration for validity and exit\n"
" -t, --terminal Open terminal session on stdio\n"
" -d -t Daemonize after terminal session ends\n",
@@ -428,8 +428,6 @@ static int frr_opt(int opt)
di->config_file = optarg;
break;
case 'N':
- if (di->flags & FRR_NO_CFG_PID_DRY)
- return 1;
if (di->pathspace) {
fprintf(stderr,
"-N/--pathspace option specified more than once!\n");
diff --git a/lib/linklist.c b/lib/linklist.c
index 272e153276..2936c5b502 100644
--- a/lib/linklist.c
+++ b/lib/linklist.c
@@ -38,16 +38,30 @@ static void list_free_internal(struct list *l)
XFREE(MTYPE_LINK_LIST, l);
}
+
/* Allocate new listnode. Internal use only. */
-static struct listnode *listnode_new(void)
+static struct listnode *listnode_new(struct list *list, void *val)
{
- return XCALLOC(MTYPE_LINK_NODE, sizeof(struct listnode));
+ struct listnode *node;
+
+ /* if listnode memory is managed by the app then the val
+ * passed in is the listnode
+ */
+ if (list->flags & LINKLIST_FLAG_NODE_MEM_BY_APP) {
+ node = val;
+ node->prev = node->next = NULL;
+ } else {
+ node = XCALLOC(MTYPE_LINK_NODE, sizeof(struct listnode));
+ node->data = val;
+ }
+ return node;
}
/* Free listnode. */
-static void listnode_free(struct listnode *node)
+static void listnode_free(struct list *list, struct listnode *node)
{
- XFREE(MTYPE_LINK_NODE, node);
+ if (!(list->flags & LINKLIST_FLAG_NODE_MEM_BY_APP))
+ XFREE(MTYPE_LINK_NODE, node);
}
struct listnode *listnode_add(struct list *list, void *val)
@@ -56,10 +70,9 @@ struct listnode *listnode_add(struct list *list, void *val)
assert(val != NULL);
- node = listnode_new();
+ node = listnode_new(list, val);
node->prev = list->tail;
- node->data = val;
if (list->head == NULL)
list->head = node;
@@ -78,10 +91,9 @@ void listnode_add_head(struct list *list, void *val)
assert(val != NULL);
- node = listnode_new();
+ node = listnode_new(list, val);
node->next = list->head;
- node->data = val;
if (list->head == NULL)
list->head = node;
@@ -97,15 +109,22 @@ bool listnode_add_sort_nodup(struct list *list, void *val)
struct listnode *n;
struct listnode *new;
int ret;
+ void *data;
assert(val != NULL);
+ if (list->flags & LINKLIST_FLAG_NODE_MEM_BY_APP) {
+ n = val;
+ data = n->data;
+ } else {
+ data = val;
+ }
+
if (list->cmp) {
for (n = list->head; n; n = n->next) {
- ret = (*list->cmp)(val, n->data);
+ ret = (*list->cmp)(data, n->data);
if (ret < 0) {
- new = listnode_new();
- new->data = val;
+ new = listnode_new(list, val);
new->next = n;
new->prev = n->prev;
@@ -124,8 +143,7 @@ bool listnode_add_sort_nodup(struct list *list, void *val)
}
}
- new = listnode_new();
- new->data = val;
+ new = listnode_new(list, val);
LISTNODE_ATTACH(list, new);
@@ -139,8 +157,8 @@ void listnode_add_sort(struct list *list, void *val)
assert(val != NULL);
- new = listnode_new();
- new->data = val;
+ new = listnode_new(list, val);
+ val = new->data;
if (list->cmp) {
for (n = list->head; n; n = n->next) {
@@ -177,8 +195,7 @@ struct listnode *listnode_add_after(struct list *list, struct listnode *pp,
assert(val != NULL);
- nn = listnode_new();
- nn->data = val;
+ nn = listnode_new(list, val);
if (pp == NULL) {
if (list->head)
@@ -212,8 +229,7 @@ struct listnode *listnode_add_before(struct list *list, struct listnode *pp,
assert(val != NULL);
- nn = listnode_new();
- nn->data = val;
+ nn = listnode_new(list, val);
if (pp == NULL) {
if (list->tail)
@@ -276,7 +292,7 @@ void list_delete_all_node(struct list *list)
next = node->next;
if (*list->del)
(*list->del)(node->data);
- listnode_free(node);
+ listnode_free(list, node);
}
list->head = list->tail = NULL;
list->count = 0;
@@ -336,7 +352,7 @@ void list_delete_node(struct list *list, struct listnode *node)
else
list->tail = node->prev;
list->count--;
- listnode_free(node);
+ listnode_free(list, node);
}
void list_sort(struct list *list, int (*cmp)(const void **, const void **))
diff --git a/lib/linklist.h b/lib/linklist.h
index 00cb9f8714..94a1a1604a 100644
--- a/lib/linklist.h
+++ b/lib/linklist.h
@@ -43,6 +43,12 @@ struct list {
/* invariant: count is the number of listnodes in the list */
unsigned int count;
+ uint8_t flags;
+/* Indicates that listnode memory is managed by the application and
+ * doesn't need to be freed by this library via listnode_delete etc.
+ */
+#define LINKLIST_FLAG_NODE_MEM_BY_APP (1 << 0)
+
/*
* Returns -1 if val1 < val2, 0 if equal?, 1 if val1 > val2.
* Used as definition of sorted for listnode_add_sort
@@ -60,10 +66,14 @@ struct list {
#define listhead(X) ((X) ? ((X)->head) : NULL)
#define listhead_unchecked(X) ((X)->head)
#define listtail(X) ((X) ? ((X)->tail) : NULL)
+#define listtail_unchecked(X) ((X)->tail)
#define listcount(X) ((X)->count)
#define list_isempty(X) ((X)->head == NULL && (X)->tail == NULL)
/* return X->data only if X and X->data are not NULL */
#define listgetdata(X) (assert(X), assert((X)->data != NULL), (X)->data)
+/* App is going to manage listnode memory */
+#define listset_app_node_mem(X) ((X)->flags |= LINKLIST_FLAG_NODE_MEM_BY_APP)
+#define listnode_init(X, val) ((X)->data = (val))
/*
* Create a new linked list.
@@ -95,7 +105,7 @@ extern struct listnode *listnode_add(struct list *list, void *data);
* list to operate on
*
* data
- * element to add
+ * If MEM_BY_APP is set this is listnode. Otherwise it is element to add.
*/
extern void listnode_add_head(struct list *list, void *data);
@@ -112,7 +122,7 @@ extern void listnode_add_head(struct list *list, void *data);
* list to operate on
*
* val
- * element to add
+ * If MEM_BY_APP is set this is listnode. Otherwise it is element to add.
*/
extern void listnode_add_sort(struct list *list, void *val);
@@ -128,7 +138,7 @@ extern void listnode_add_sort(struct list *list, void *val);
* listnode to insert after
*
* data
- * data to insert
+ * If MEM_BY_APP is set this is listnode. Otherwise it is element to add.
*
* Returns:
* pointer to newly created listnode that contains the inserted data
@@ -148,7 +158,7 @@ extern struct listnode *listnode_add_after(struct list *list,
* listnode to insert before
*
* data
- * data to insert
+ * If MEM_BY_APP is set this is listnode. Otherwise it is element to add.
*
* Returns:
* pointer to newly created listnode that contains the inserted data
@@ -313,7 +323,7 @@ extern void list_filter_out_nodes(struct list *list, bool (*cond)(void *data));
* list to operate on
*
* val
- * element to add
+ * If MEM_BY_APP is set this is listnode. Otherwise it is element to add.
*/
extern bool listnode_add_sort_nodup(struct list *list, void *val);
diff --git a/lib/log.c b/lib/log.c
index 2baa09b6fd..bbce4eb793 100644
--- a/lib/log.c
+++ b/lib/log.c
@@ -398,6 +398,10 @@ static const struct zebra_desc_table command_types[] = {
DESC_ENTRY(ZEBRA_ADVERTISE_SUBNET),
DESC_ENTRY(ZEBRA_LOCAL_ES_ADD),
DESC_ENTRY(ZEBRA_LOCAL_ES_DEL),
+ DESC_ENTRY(ZEBRA_REMOTE_ES_VTEP_ADD),
+ DESC_ENTRY(ZEBRA_REMOTE_ES_VTEP_DEL),
+ DESC_ENTRY(ZEBRA_LOCAL_ES_EVI_ADD),
+ DESC_ENTRY(ZEBRA_LOCAL_ES_EVI_DEL),
DESC_ENTRY(ZEBRA_VNI_ADD),
DESC_ENTRY(ZEBRA_VNI_DEL),
DESC_ENTRY(ZEBRA_L3VNI_ADD),
diff --git a/lib/netns_linux.c b/lib/netns_linux.c
index e1c0159fc5..98f359401e 100644
--- a/lib/netns_linux.c
+++ b/lib/netns_linux.c
@@ -379,20 +379,12 @@ struct ns *ns_lookup(ns_id_t ns_id)
return ns_lookup_internal(ns_id);
}
-void ns_walk_func(int (*func)(struct ns *,
- void *param_in,
- void **param_out),
- void *param_in,
- void **param_out)
+void ns_walk_func(int (*func)(struct ns *))
{
struct ns *ns = NULL;
- int ret;
- RB_FOREACH (ns, ns_head, &ns_tree) {
- ret = func(ns, param_in, param_out);
- if (ret == NS_WALK_STOP)
- return;
- }
+ RB_FOREACH (ns, ns_head, &ns_tree)
+ func(ns);
}
const char *ns_get_name(struct ns *ns)
@@ -592,33 +584,9 @@ int ns_socket(int domain, int type, int protocol, ns_id_t ns_id)
return ret;
}
-/* if relative link_nsid matches default netns,
- * then return default absolute netns value
- * otherwise, return NS_UNKNOWN
- */
-ns_id_t ns_id_get_absolute(ns_id_t ns_id_reference, ns_id_t link_nsid)
-{
- struct ns *ns;
-
- ns = ns_lookup(ns_id_reference);
- if (!ns)
- return NS_UNKNOWN;
- if (ns->relative_default_ns != link_nsid)
- return NS_UNKNOWN;
- ns = ns_get_default();
- assert(ns);
- return ns->ns_id;
-}
-
ns_id_t ns_get_default_id(void)
{
if (default_ns)
return default_ns->ns_id;
return NS_DEFAULT_INTERNAL;
}
-
-struct ns *ns_get_default(void)
-{
- return default_ns;
-}
-
diff --git a/lib/nexthop.c b/lib/nexthop.c
index 3496081d47..28d96a539c 100644
--- a/lib/nexthop.c
+++ b/lib/nexthop.c
@@ -157,6 +157,10 @@ static int _nexthop_cmp_no_labels(const struct nexthop *next1,
goto done;
if (!CHECK_FLAG(next1->flags, NEXTHOP_FLAG_HAS_BACKUP) &&
+ !CHECK_FLAG(next2->flags, NEXTHOP_FLAG_HAS_BACKUP))
+ return 0;
+
+ if (!CHECK_FLAG(next1->flags, NEXTHOP_FLAG_HAS_BACKUP) &&
CHECK_FLAG(next2->flags, NEXTHOP_FLAG_HAS_BACKUP))
return -1;
@@ -164,12 +168,18 @@ static int _nexthop_cmp_no_labels(const struct nexthop *next1,
!CHECK_FLAG(next2->flags, NEXTHOP_FLAG_HAS_BACKUP))
return 1;
- if (next1->backup_idx < next2->backup_idx)
+ if (next1->backup_num == 0 && next2->backup_num == 0)
+ goto done;
+
+ if (next1->backup_num < next2->backup_num)
return -1;
- if (next1->backup_idx > next2->backup_idx)
+ if (next1->backup_num > next2->backup_num)
return 1;
+ ret = memcmp(next1->backup_idx,
+ next2->backup_idx, next1->backup_num);
+
done:
return ret;
}
@@ -515,11 +525,12 @@ struct nexthop *nexthop_next_active_resolved(const struct nexthop *nexthop)
return next;
}
-unsigned int nexthop_level(struct nexthop *nexthop)
+unsigned int nexthop_level(const struct nexthop *nexthop)
{
unsigned int rv = 0;
- for (struct nexthop *par = nexthop->rparent; par; par = par->rparent)
+ for (const struct nexthop *par = nexthop->rparent;
+ par; par = par->rparent)
rv++;
return rv;
@@ -529,14 +540,15 @@ unsigned int nexthop_level(struct nexthop *nexthop)
uint32_t nexthop_hash_quick(const struct nexthop *nexthop)
{
uint32_t key = 0x45afe398;
- uint32_t val;
+ int i;
key = jhash_3words(nexthop->type, nexthop->vrf_id,
nexthop->nh_label_type, key);
if (nexthop->nh_label) {
int labels = nexthop->nh_label->num_labels;
- int i = 0;
+
+ i = 0;
while (labels >= 3) {
key = jhash_3words(nexthop->nh_label->label[i],
@@ -559,14 +571,35 @@ uint32_t nexthop_hash_quick(const struct nexthop *nexthop)
key = jhash_1word(nexthop->nh_label->label[i], key);
}
- val = 0;
- if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_HAS_BACKUP))
- val = (uint32_t)nexthop->backup_idx;
-
- key = jhash_3words(nexthop->ifindex,
- CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_ONLINK), val,
+ key = jhash_2words(nexthop->ifindex,
+ CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_ONLINK),
key);
+ /* Include backup nexthops, if present */
+ if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_HAS_BACKUP)) {
+ int backups = nexthop->backup_num;
+
+ i = 0;
+
+ while (backups >= 3) {
+ key = jhash_3words(nexthop->backup_idx[i],
+ nexthop->backup_idx[i + 1],
+ nexthop->backup_idx[i + 2], key);
+ backups -= 3;
+ i += 3;
+ }
+
+ while (backups >= 2) {
+ key = jhash_2words(nexthop->backup_idx[i],
+ nexthop->backup_idx[i + 1], key);
+ backups -= 2;
+ i += 2;
+ }
+
+ if (backups >= 1)
+ key = jhash_1word(nexthop->backup_idx[i], key);
+ }
+
return key;
}
@@ -604,7 +637,12 @@ void nexthop_copy_no_recurse(struct nexthop *copy,
copy->type = nexthop->type;
copy->flags = nexthop->flags;
copy->weight = nexthop->weight;
- copy->backup_idx = nexthop->backup_idx;
+
+ assert(nexthop->backup_num < NEXTHOP_MAX_BACKUPS);
+ copy->backup_num = nexthop->backup_num;
+ if (copy->backup_num > 0)
+ memcpy(copy->backup_idx, nexthop->backup_idx, copy->backup_num);
+
memcpy(&copy->gate, &nexthop->gate, sizeof(nexthop->gate));
memcpy(&copy->src, &nexthop->src, sizeof(nexthop->src));
memcpy(&copy->rmap_src, &nexthop->rmap_src, sizeof(nexthop->rmap_src));
@@ -621,7 +659,7 @@ void nexthop_copy(struct nexthop *copy, const struct nexthop *nexthop,
nexthop_copy_no_recurse(copy, nexthop, rparent);
/* Bit of a special case here, we need to handle the case
- * of a nexthop resolving to agroup. Hence, we need to
+ * of a nexthop resolving to a group. Hence, we need to
* use a nexthop_group API.
*/
if (CHECK_FLAG(copy->flags, NEXTHOP_FLAG_RECURSIVE))
@@ -647,6 +685,67 @@ struct nexthop *nexthop_dup(const struct nexthop *nexthop,
}
/*
+ * Parse one or more backup index values, as comma-separated numbers,
+ * into caller's array of uint8_ts. The array must be NEXTHOP_MAX_BACKUPS
+ * in size. Mails back the number of values converted, and returns 0 on
+ * success, <0 if an error in parsing.
+ */
+int nexthop_str2backups(const char *str, int *num_backups,
+ uint8_t *backups)
+{
+ char *ostr; /* copy of string (start) */
+ char *lstr; /* working copy of string */
+ char *nump; /* pointer to next segment */
+ char *endp; /* end pointer */
+ int i, ret;
+ uint8_t tmp[NEXTHOP_MAX_BACKUPS];
+ uint32_t lval;
+
+ /* Copy incoming string; the parse is destructive */
+ lstr = ostr = XSTRDUP(MTYPE_TMP, str);
+ *num_backups = 0;
+ ret = 0;
+
+ for (i = 0; i < NEXTHOP_MAX_BACKUPS && lstr; i++) {
+ nump = strsep(&lstr, ",");
+ lval = strtoul(nump, &endp, 10);
+
+ /* Format check */
+ if (*endp != '\0') {
+ ret = -1;
+ break;
+ }
+
+ /* Empty value */
+ if (endp == nump) {
+ ret = -1;
+ break;
+ }
+
+ /* Limit to one octet */
+ if (lval > 255) {
+ ret = -1;
+ break;
+ }
+
+ tmp[i] = lval;
+ }
+
+ /* Excess values */
+ if (ret == 0 && i == NEXTHOP_MAX_BACKUPS && lstr)
+ ret = -1;
+
+ if (ret == 0) {
+ *num_backups = i;
+ memcpy(backups, tmp, i);
+ }
+
+ XFREE(MTYPE_TMP, ostr);
+
+ return ret;
+}
+
+/*
* nexthop printing variants:
* %pNHvv
* via 1.2.3.4
diff --git a/lib/nexthop.h b/lib/nexthop.h
index eda88efc08..ed40cc7eed 100644
--- a/lib/nexthop.h
+++ b/lib/nexthop.h
@@ -65,6 +65,12 @@ enum nh_encap_type {
NET_VXLAN = 100, /* value copied from FPM_NH_ENCAP_VXLAN. */
};
+/* Fixed limit on the number of backup nexthops per primary nexthop */
+#define NEXTHOP_MAX_BACKUPS 8
+
+/* Backup index value is limited */
+#define NEXTHOP_BACKUP_IDX_MAX 255
+
/* Nexthop structure. */
struct nexthop {
struct nexthop *next;
@@ -124,10 +130,11 @@ struct nexthop {
/* Weight of the nexthop ( for unequal cost ECMP ) */
uint8_t weight;
- /* Index of a corresponding backup nexthop in a backup list;
+ /* Count and index of corresponding backup nexthop(s) in a backup list;
* only meaningful if the HAS_BACKUP flag is set.
*/
- uint8_t backup_idx;
+ uint8_t backup_num;
+ uint8_t backup_idx[NEXTHOP_MAX_BACKUPS];
/* Encapsulation information. */
enum nh_encap_type nh_encap_type;
@@ -136,9 +143,6 @@ struct nexthop {
} nh_encap;
};
-/* Backup index value is limited */
-#define NEXTHOP_BACKUP_IDX_MAX 255
-
/* Utility to append one nexthop to another. */
#define NEXTHOP_APPEND(to, new) \
do { \
@@ -216,7 +220,7 @@ extern const char *nexthop2str(const struct nexthop *nexthop,
extern struct nexthop *nexthop_next(const struct nexthop *nexthop);
extern struct nexthop *
nexthop_next_active_resolved(const struct nexthop *nexthop);
-extern unsigned int nexthop_level(struct nexthop *nexthop);
+extern unsigned int nexthop_level(const struct nexthop *nexthop);
/* Copies to an already allocated nexthop struct */
extern void nexthop_copy(struct nexthop *copy, const struct nexthop *nexthop,
struct nexthop *rparent);
@@ -231,6 +235,15 @@ extern struct nexthop *nexthop_dup(const struct nexthop *nexthop,
extern struct nexthop *nexthop_dup_no_recurse(const struct nexthop *nexthop,
struct nexthop *rparent);
+/*
+ * Parse one or more backup index values, as comma-separated numbers,
+ * into caller's array of uint8_ts. The array must be NEXTHOP_MAX_BACKUPS
+ * in size. Mails back the number of values converted, and returns 0 on
+ * success, <0 if an error in parsing.
+ */
+int nexthop_str2backups(const char *str, int *num_backups,
+ uint8_t *backups);
+
#ifdef _FRR_ATTRIBUTE_PRINTFRR
#pragma FRR printfrr_ext "%pNH" (struct nexthop *)
#endif
diff --git a/lib/nexthop_group.c b/lib/nexthop_group.c
index 4f0c72af27..97815ceeb9 100644
--- a/lib/nexthop_group.c
+++ b/lib/nexthop_group.c
@@ -43,12 +43,9 @@ struct nexthop_hold {
char *intf;
char *labels;
uint32_t weight;
- int backup_idx; /* Index of backup nexthop, if >= 0 */
+ char *backup_str;
};
-/* Invalid/unset value for nexthop_hold's backup_idx */
-#define NHH_BACKUP_IDX_INVALID -1
-
struct nexthop_group_hooks {
void (*new)(const char *name);
void (*add_nexthop)(const struct nexthop_group_cmd *nhg,
@@ -677,7 +674,8 @@ static void nexthop_group_save_nhop(struct nexthop_group_cmd *nhgc,
const char *nhvrf_name,
const union sockunion *addr,
const char *intf, const char *labels,
- const uint32_t weight, int backup_idx)
+ const uint32_t weight,
+ const char *backup_str)
{
struct nexthop_hold *nh;
@@ -694,7 +692,8 @@ static void nexthop_group_save_nhop(struct nexthop_group_cmd *nhgc,
nh->weight = weight;
- nh->backup_idx = backup_idx;
+ if (backup_str)
+ nh->backup_str = XSTRDUP(MTYPE_TMP, backup_str);
listnode_add_sort(nhgc->nhg_list, nh);
}
@@ -741,10 +740,11 @@ static bool nexthop_group_parse_nexthop(struct nexthop *nhop,
const union sockunion *addr,
const char *intf, const char *name,
const char *labels, int *lbl_ret,
- uint32_t weight, int backup_idx)
+ uint32_t weight, const char *backup_str)
{
int ret = 0;
struct vrf *vrf;
+ int num;
memset(nhop, 0, sizeof(*nhop));
@@ -800,13 +800,15 @@ static bool nexthop_group_parse_nexthop(struct nexthop *nhop,
nhop->weight = weight;
- if (backup_idx != NHH_BACKUP_IDX_INVALID) {
- /* Validate index value */
- if (backup_idx > NEXTHOP_BACKUP_IDX_MAX)
+ if (backup_str) {
+ /* Parse backup indexes */
+ ret = nexthop_str2backups(backup_str,
+ &num, nhop->backup_idx);
+ if (ret == 0) {
+ SET_FLAG(nhop->flags, NEXTHOP_FLAG_HAS_BACKUP);
+ nhop->backup_num = num;
+ } else
return false;
-
- SET_FLAG(nhop->flags, NEXTHOP_FLAG_HAS_BACKUP);
- nhop->backup_idx = backup_idx;
}
return true;
@@ -820,7 +822,7 @@ static bool nexthop_group_parse_nhh(struct nexthop *nhop,
{
return (nexthop_group_parse_nexthop(nhop, nhh->addr, nhh->intf,
nhh->nhvrf_name, nhh->labels, NULL,
- nhh->weight, nhh->backup_idx));
+ nhh->weight, nhh->backup_str));
}
DEFPY(ecmp_nexthops, ecmp_nexthops_cmd,
@@ -833,7 +835,7 @@ DEFPY(ecmp_nexthops, ecmp_nexthops_cmd,
nexthop-vrf NAME$vrf_name \
|label WORD \
|weight (1-255) \
- |backup-idx$bi_str (0-254)$idx \
+ |backup-idx WORD \
}]",
NO_STR
"Specify one of the nexthops in this ECMP group\n"
@@ -847,19 +849,26 @@ DEFPY(ecmp_nexthops, ecmp_nexthops_cmd,
"One or more labels in the range (16-1048575) separated by '/'\n"
"Weight to be used by the nexthop for purposes of ECMP\n"
"Weight value to be used\n"
- "Backup nexthop index in another group\n"
- "Nexthop index value\n")
+ "Specify backup nexthop indexes in another group\n"
+ "One or more indexes in the range (0-254) separated by ','\n")
{
VTY_DECLVAR_CONTEXT(nexthop_group_cmd, nhgc);
struct nexthop nhop;
struct nexthop *nh;
int lbl_ret = 0;
bool legal;
- int backup_idx = idx;
+ int num;
+ uint8_t backups[NEXTHOP_MAX_BACKUPS];
bool yes = !no;
- if (bi_str == NULL)
- backup_idx = NHH_BACKUP_IDX_INVALID;
+ /* Pre-parse backup string to validate */
+ if (backup_idx) {
+ lbl_ret = nexthop_str2backups(backup_idx, &num, backups);
+ if (lbl_ret < 0) {
+ vty_out(vty, "%% Invalid backups\n");
+ return CMD_WARNING_CONFIG_FAILED;
+ }
+ }
legal = nexthop_group_parse_nexthop(&nhop, addr, intf, vrf_name, label,
&lbl_ret, weight, backup_idx);
@@ -943,10 +952,11 @@ static struct cmd_node nexthop_group_node = {
.config_write = nexthop_group_write,
};
-void nexthop_group_write_nexthop(struct vty *vty, struct nexthop *nh)
+void nexthop_group_write_nexthop(struct vty *vty, const struct nexthop *nh)
{
char buf[100];
struct vrf *vrf;
+ int i;
vty_out(vty, "nexthop ");
@@ -991,16 +1001,22 @@ void nexthop_group_write_nexthop(struct vty *vty, struct nexthop *nh)
if (nh->weight)
vty_out(vty, " weight %u", nh->weight);
- if (CHECK_FLAG(nh->flags, NEXTHOP_FLAG_HAS_BACKUP))
- vty_out(vty, " backup-idx %d", nh->backup_idx);
+ if (CHECK_FLAG(nh->flags, NEXTHOP_FLAG_HAS_BACKUP)) {
+ vty_out(vty, " backup-idx %d", nh->backup_idx[0]);
+
+ for (i = 1; i < nh->backup_num; i++)
+ vty_out(vty, ",%d", nh->backup_idx[i]);
+ }
vty_out(vty, "\n");
}
-void nexthop_group_json_nexthop(json_object *j, struct nexthop *nh)
+void nexthop_group_json_nexthop(json_object *j, const struct nexthop *nh)
{
char buf[100];
struct vrf *vrf;
+ json_object *json_backups = NULL;
+ int i;
switch (nh->type) {
case NEXTHOP_TYPE_IFINDEX:
@@ -1047,12 +1063,19 @@ void nexthop_group_json_nexthop(json_object *j, struct nexthop *nh)
if (nh->weight)
json_object_int_add(j, "weight", nh->weight);
- if (CHECK_FLAG(nh->flags, NEXTHOP_FLAG_HAS_BACKUP))
- json_object_int_add(j, "backupIdx", nh->backup_idx);
+ if (CHECK_FLAG(nh->flags, NEXTHOP_FLAG_HAS_BACKUP)) {
+ json_backups = json_object_new_array();
+ for (i = 0; i < nh->backup_num; i++)
+ json_object_array_add(
+ json_backups,
+ json_object_new_int(nh->backup_idx[i]));
+
+ json_object_object_add(j, "backupIdx", json_backups);
+ }
}
static void nexthop_group_write_nexthop_internal(struct vty *vty,
- struct nexthop_hold *nh)
+ const struct nexthop_hold *nh)
{
char buf[100];
@@ -1073,8 +1096,8 @@ static void nexthop_group_write_nexthop_internal(struct vty *vty,
if (nh->weight)
vty_out(vty, " weight %u", nh->weight);
- if (nh->backup_idx != NHH_BACKUP_IDX_INVALID)
- vty_out(vty, " backup-idx %d", nh->backup_idx);
+ if (nh->backup_str)
+ vty_out(vty, " backup-idx %s", nh->backup_str);
vty_out(vty, "\n");
}
diff --git a/lib/nexthop_group.h b/lib/nexthop_group.h
index 9888dad982..0b5ac91bb2 100644
--- a/lib/nexthop_group.h
+++ b/lib/nexthop_group.h
@@ -135,9 +135,11 @@ extern bool nexthop_group_equal(const struct nexthop_group *nhg1,
extern struct nexthop_group_cmd *nhgc_find(const char *name);
-extern void nexthop_group_write_nexthop(struct vty *vty, struct nexthop *nh);
+extern void nexthop_group_write_nexthop(struct vty *vty,
+ const struct nexthop *nh);
-extern void nexthop_group_json_nexthop(json_object *j, struct nexthop *nh);
+extern void nexthop_group_json_nexthop(json_object *j,
+ const struct nexthop *nh);
/* Return the number of nexthops in this nhg */
extern uint8_t nexthop_group_nexthop_num(const struct nexthop_group *nhg);
diff --git a/lib/northbound_cli.c b/lib/northbound_cli.c
index 105fc83cef..534b5128ee 100644
--- a/lib/northbound_cli.c
+++ b/lib/northbound_cli.c
@@ -53,6 +53,106 @@ static void vty_show_nb_errors(struct vty *vty, int error, const char *errmsg)
vty_out(vty, "Error description: %s\n", errmsg);
}
+static int nb_cli_classic_commit(struct vty *vty)
+{
+ struct nb_context context = {};
+ char errmsg[BUFSIZ] = {0};
+ int ret;
+
+ context.client = NB_CLIENT_CLI;
+ context.user = vty;
+ ret = nb_candidate_commit(&context, vty->candidate_config, true, NULL,
+ NULL, errmsg, sizeof(errmsg));
+ if (ret != NB_OK && ret != NB_ERR_NO_CHANGES) {
+ vty_out(vty, "%% Configuration failed.\n\n");
+ vty_show_nb_errors(vty, ret, errmsg);
+ if (vty->t_pending_commit)
+ vty_out(vty,
+ "The following commands were dynamically grouped into the same transaction and rejected:\n%s",
+ vty->pending_cmds_buf);
+
+ /* Regenerate candidate for consistency. */
+ nb_config_replace(vty->candidate_config, running_config, true);
+ return CMD_WARNING_CONFIG_FAILED;
+ }
+
+ return CMD_SUCCESS;
+}
+
+static void nb_cli_pending_commit_clear(struct vty *vty)
+{
+ THREAD_TIMER_OFF(vty->t_pending_commit);
+ vty->backoff_cmd_count = 0;
+ XFREE(MTYPE_TMP, vty->pending_cmds_buf);
+ vty->pending_cmds_buflen = 0;
+ vty->pending_cmds_bufpos = 0;
+}
+
+static int nb_cli_pending_commit_cb(struct thread *thread)
+{
+ struct vty *vty = THREAD_ARG(thread);
+
+ (void)nb_cli_classic_commit(vty);
+ nb_cli_pending_commit_clear(vty);
+
+ return 0;
+}
+
+void nb_cli_pending_commit_check(struct vty *vty)
+{
+ if (vty->t_pending_commit) {
+ (void)nb_cli_classic_commit(vty);
+ nb_cli_pending_commit_clear(vty);
+ }
+}
+
+static bool nb_cli_backoff_start(struct vty *vty)
+{
+ struct timeval now, delta;
+
+ /*
+ * Start the configuration backoff timer only if 100 YANG-modeled
+ * commands or more were entered within the last second.
+ */
+ monotime(&now);
+ if (monotime_since(&vty->backoff_start, &delta) >= 1000000) {
+ vty->backoff_start = now;
+ vty->backoff_cmd_count = 1;
+ return false;
+ }
+ if (++vty->backoff_cmd_count < 100)
+ return false;
+
+ return true;
+}
+
+static int nb_cli_schedule_command(struct vty *vty)
+{
+ /* Append command to dynamically sized buffer of scheduled commands. */
+ if (!vty->pending_cmds_buf) {
+ vty->pending_cmds_buflen = 4096;
+ vty->pending_cmds_buf =
+ XCALLOC(MTYPE_TMP, vty->pending_cmds_buflen);
+ }
+ if ((strlen(vty->buf) + 3)
+ > (vty->pending_cmds_buflen - vty->pending_cmds_bufpos)) {
+ vty->pending_cmds_buflen *= 2;
+ vty->pending_cmds_buf =
+ XREALLOC(MTYPE_TMP, vty->pending_cmds_buf,
+ vty->pending_cmds_buflen);
+ }
+ strlcat(vty->pending_cmds_buf, "- ", vty->pending_cmds_buflen);
+ vty->pending_cmds_bufpos = strlcat(vty->pending_cmds_buf, vty->buf,
+ vty->pending_cmds_buflen);
+
+ /* Schedule the commit operation. */
+ THREAD_TIMER_OFF(vty->t_pending_commit);
+ thread_add_timer_msec(master, nb_cli_pending_commit_cb, vty, 100,
+ &vty->t_pending_commit);
+
+ return CMD_SUCCESS;
+}
+
void nb_cli_enqueue_change(struct vty *vty, const char *xpath,
enum nb_operation operation, const char *value)
{
@@ -76,7 +176,6 @@ int nb_cli_apply_changes(struct vty *vty, const char *xpath_base_fmt, ...)
{
char xpath_base[XPATH_MAXLEN] = {};
bool error = false;
- int ret;
VTY_CHECK_XPATH;
@@ -95,6 +194,7 @@ int nb_cli_apply_changes(struct vty *vty, const char *xpath_base_fmt, ...)
struct nb_node *nb_node;
char xpath[XPATH_MAXLEN];
struct yang_data *data;
+ int ret;
/* Handle relative XPaths. */
memset(xpath, 0, sizeof(xpath));
@@ -158,25 +258,19 @@ int nb_cli_apply_changes(struct vty *vty, const char *xpath_base_fmt, ...)
yang_print_errors(ly_native_ctx, buf, sizeof(buf)));
}
- /* Do an implicit "commit" when using the classic CLI mode. */
+ /*
+ * Do an implicit commit when using the classic CLI mode.
+ *
+ * NOTE: the implicit commit might be scheduled to run later when
+ * too many commands are being sent at the same time. This is a
+ * protection mechanism where multiple commands are grouped into the
+ * same configuration transaction, allowing them to be processed much
+ * faster.
+ */
if (frr_get_cli_mode() == FRR_CLI_CLASSIC) {
- struct nb_context context = {};
- char errmsg[BUFSIZ] = {0};
-
- context.client = NB_CLIENT_CLI;
- context.user = vty;
- ret = nb_candidate_commit(&context, vty->candidate_config,
- false, NULL, NULL, errmsg,
- sizeof(errmsg));
- if (ret != NB_OK && ret != NB_ERR_NO_CHANGES) {
- vty_out(vty, "%% Configuration failed.\n\n");
- vty_show_nb_errors(vty, ret, errmsg);
-
- /* Regenerate candidate for consistency. */
- nb_config_replace(vty->candidate_config, running_config,
- true);
- return CMD_WARNING_CONFIG_FAILED;
- }
+ if (vty->t_pending_commit || nb_cli_backoff_start(vty))
+ return nb_cli_schedule_command(vty);
+ return nb_cli_classic_commit(vty);
}
return CMD_SUCCESS;
diff --git a/lib/northbound_cli.h b/lib/northbound_cli.h
index b2d8c8f035..112d62efda 100644
--- a/lib/northbound_cli.h
+++ b/lib/northbound_cli.h
@@ -108,6 +108,14 @@ extern int nb_cli_rpc(const char *xpath, struct list *input,
extern void nb_cli_show_dnode_cmds(struct vty *vty, struct lyd_node *dnode,
bool show_defaults);
+/*
+ * Perform pending commit, if any.
+ *
+ * vty
+ * The vty context.
+ */
+extern void nb_cli_pending_commit_check(struct vty *vty);
+
/* Prototypes of internal functions. */
extern void nb_cli_show_config_prepare(struct nb_config *config,
bool with_defaults);
diff --git a/lib/ns.h b/lib/ns.h
index 286ff5b295..20e0a38e3b 100644
--- a/lib/ns.h
+++ b/lib/ns.h
@@ -53,11 +53,6 @@ struct ns {
/* Identifier, mapped on the NSID value */
ns_id_t internal_ns_id;
- /* Identifier, value of NSID of default netns,
- * relative value in that local netns
- */
- ns_id_t relative_default_ns;
-
/* Name */
char *name;
@@ -125,14 +120,7 @@ int ns_socket(int domain, int type, int protocol, ns_id_t ns_id);
extern char *ns_netns_pathname(struct vty *vty, const char *name);
/* Parse and execute a function on all the NETNS */
-#define NS_WALK_CONTINUE 0
-#define NS_WALK_STOP 1
-
-extern void ns_walk_func(int (*func)(struct ns *,
- void *,
- void **),
- void *param_in,
- void **param_out);
+extern void ns_walk_func(int (*func)(struct ns *));
/* API to get the NETNS name, from the ns pointer */
extern const char *ns_get_name(struct ns *ns);
@@ -186,9 +174,7 @@ extern struct ns *ns_lookup_name(const char *name);
*/
extern int ns_enable(struct ns *ns, void (*func)(ns_id_t, void *));
extern struct ns *ns_get_created(struct ns *ns, char *name, ns_id_t ns_id);
-extern ns_id_t ns_id_get_absolute(ns_id_t ns_id_reference, ns_id_t link_nsid);
extern void ns_disable(struct ns *ns);
-extern struct ns *ns_get_default(void);
#ifdef __cplusplus
}
diff --git a/lib/pbr.h b/lib/pbr.h
index cf6ac41d32..fd183d7115 100644
--- a/lib/pbr.h
+++ b/lib/pbr.h
@@ -49,6 +49,10 @@ struct pbr_filter {
#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_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. */
struct prefix src_ip;
@@ -58,6 +62,9 @@ struct pbr_filter {
uint16_t src_port;
uint16_t dst_port;
+ /* Filter by Differentiated Services field */
+ uint8_t dsfield; /* DSCP (6 bits) & ECN (2 bits) */
+
/* Filter with fwmark */
uint32_t fwmark;
};
diff --git a/lib/prefix.c b/lib/prefix.c
index 0900100be3..697e1a6239 100644
--- a/lib/prefix.c
+++ b/lib/prefix.c
@@ -22,6 +22,7 @@
#include <zebra.h>
#include "prefix.h"
+#include "ipaddr.h"
#include "vty.h"
#include "sockunion.h"
#include "memory.h"
@@ -1316,6 +1317,26 @@ char *esi_to_str(const esi_t *esi, char *buf, int size)
return ptr;
}
+printfrr_ext_autoreg_p("EA", printfrr_ea)
+static ssize_t printfrr_ea(char *buf, size_t bsz, const char *fmt,
+ int prec, const void *ptr)
+{
+ const struct ethaddr *mac = ptr;
+
+ prefix_mac2str(mac, buf, bsz);
+ return 2;
+}
+
+printfrr_ext_autoreg_p("IA", printfrr_ia)
+static ssize_t printfrr_ia(char *buf, size_t bsz, const char *fmt,
+ int prec, const void *ptr)
+{
+ const struct ipaddr *ipa = ptr;
+
+ ipaddr2str(ipa, buf, bsz);
+ return 2;
+}
+
printfrr_ext_autoreg_p("I4", printfrr_i4)
static ssize_t printfrr_i4(char *buf, size_t bsz, const char *fmt,
int prec, const void *ptr)
diff --git a/lib/prefix.h b/lib/prefix.h
index 0bd457cc23..400f07386f 100644
--- a/lib/prefix.h
+++ b/lib/prefix.h
@@ -43,9 +43,36 @@ extern "C" {
#define ETH_ALEN 6
#endif
+/* EVPN route types. */
+typedef enum {
+ BGP_EVPN_AD_ROUTE = 1, /* Ethernet Auto-Discovery (A-D) route */
+ BGP_EVPN_MAC_IP_ROUTE, /* MAC/IP Advertisement route */
+ BGP_EVPN_IMET_ROUTE, /* Inclusive Multicast Ethernet Tag route */
+ BGP_EVPN_ES_ROUTE, /* Ethernet Segment route */
+ BGP_EVPN_IP_PREFIX_ROUTE, /* IP Prefix route */
+} bgp_evpn_route_type;
+
+/* value of first byte of ESI */
+#define ESI_TYPE_ARBITRARY 0 /* */
+#define ESI_TYPE_LACP 1 /* <> */
+#define ESI_TYPE_BRIDGE 2 /* <Root bridge Mac-6B>:<Root Br Priority-2B>:00 */
+#define ESI_TYPE_MAC 3 /* <Syst Mac Add-6B>:<Local Discriminator Value-3B> */
+#define ESI_TYPE_ROUTER 4 /* <RouterId-4B>:<Local Discriminator Value-4B> */
+#define ESI_TYPE_AS 5 /* <AS-4B>:<Local Discriminator Value-4B> */
+
+#define MAX_ESI {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
+
+
+#define EVPN_ETH_TAG_BYTES 4
#define ESI_BYTES 10
#define ESI_STR_LEN (3 * ESI_BYTES)
+/* Maximum number of VTEPs per-ES -
+ * XXX - temporary limit for allocating strings etc.
+ */
+#define ES_VTEP_MAX_CNT 10
+#define ES_VTEP_LIST_STR_SZ (ES_VTEP_MAX_CNT * 16)
+
#define ETHER_ADDR_STRLEN (3*ETH_ALEN)
/*
* there isn't a portable ethernet address type. We define our
@@ -64,12 +91,13 @@ struct ethaddr {
#define PREFIX_LEN_ROUTE_TYPE_5_IPV6 (30*8)
typedef struct esi_t_ {
- uint8_t val[10];
+ uint8_t val[ESI_BYTES];
} esi_t;
struct evpn_ead_addr {
esi_t esi;
uint32_t eth_tag;
+ struct ipaddr ip;
};
struct evpn_macip_addr {
@@ -217,39 +245,45 @@ struct prefix_evpn {
static inline int is_evpn_prefix_ipaddr_none(const struct prefix_evpn *evp)
{
- if (evp->prefix.route_type == 2)
+ if (evp->prefix.route_type == BGP_EVPN_AD_ROUTE)
+ return IS_IPADDR_NONE(&(evp)->prefix.ead_addr.ip);
+ if (evp->prefix.route_type == BGP_EVPN_MAC_IP_ROUTE)
return IS_IPADDR_NONE(&(evp)->prefix.macip_addr.ip);
- if (evp->prefix.route_type == 3)
+ if (evp->prefix.route_type == BGP_EVPN_IMET_ROUTE)
return IS_IPADDR_NONE(&(evp)->prefix.imet_addr.ip);
- if (evp->prefix.route_type == 4)
+ if (evp->prefix.route_type == BGP_EVPN_ES_ROUTE)
return IS_IPADDR_NONE(&(evp)->prefix.es_addr.ip);
- if (evp->prefix.route_type == 5)
+ if (evp->prefix.route_type == BGP_EVPN_IP_PREFIX_ROUTE)
return IS_IPADDR_NONE(&(evp)->prefix.prefix_addr.ip);
return 0;
}
static inline int is_evpn_prefix_ipaddr_v4(const struct prefix_evpn *evp)
{
- if (evp->prefix.route_type == 2)
+ if (evp->prefix.route_type == BGP_EVPN_AD_ROUTE)
+ return IS_IPADDR_V4(&(evp)->prefix.ead_addr.ip);
+ if (evp->prefix.route_type == BGP_EVPN_MAC_IP_ROUTE)
return IS_IPADDR_V4(&(evp)->prefix.macip_addr.ip);
- if (evp->prefix.route_type == 3)
+ if (evp->prefix.route_type == BGP_EVPN_IMET_ROUTE)
return IS_IPADDR_V4(&(evp)->prefix.imet_addr.ip);
- if (evp->prefix.route_type == 4)
+ if (evp->prefix.route_type == BGP_EVPN_ES_ROUTE)
return IS_IPADDR_V4(&(evp)->prefix.es_addr.ip);
- if (evp->prefix.route_type == 5)
+ if (evp->prefix.route_type == BGP_EVPN_IP_PREFIX_ROUTE)
return IS_IPADDR_V4(&(evp)->prefix.prefix_addr.ip);
return 0;
}
static inline int is_evpn_prefix_ipaddr_v6(const struct prefix_evpn *evp)
{
- if (evp->prefix.route_type == 2)
+ if (evp->prefix.route_type == BGP_EVPN_AD_ROUTE)
+ return IS_IPADDR_V6(&(evp)->prefix.ead_addr.ip);
+ if (evp->prefix.route_type == BGP_EVPN_MAC_IP_ROUTE)
return IS_IPADDR_V6(&(evp)->prefix.macip_addr.ip);
- if (evp->prefix.route_type == 3)
+ if (evp->prefix.route_type == BGP_EVPN_IMET_ROUTE)
return IS_IPADDR_V6(&(evp)->prefix.imet_addr.ip);
- if (evp->prefix.route_type == 4)
+ if (evp->prefix.route_type == BGP_EVPN_ES_ROUTE)
return IS_IPADDR_V6(&(evp)->prefix.es_addr.ip);
- if (evp->prefix.route_type == 5)
+ if (evp->prefix.route_type == BGP_EVPN_IP_PREFIX_ROUTE)
return IS_IPADDR_V6(&(evp)->prefix.prefix_addr.ip);
return 0;
}
@@ -555,6 +589,8 @@ static inline int is_default_host_route(const struct prefix *p)
}
#ifdef _FRR_ATTRIBUTE_PRINTFRR
+#pragma FRR printfrr_ext "%pEA" (struct ethaddr *)
+
#pragma FRR printfrr_ext "%pI4" (struct in_addr *)
#pragma FRR printfrr_ext "%pI4" (in_addr_t *)
diff --git a/lib/route_types.pl b/lib/route_types.pl
index f297096633..e007de4d69 100755
--- a/lib/route_types.pl
+++ b/lib/route_types.pl
@@ -121,7 +121,7 @@ sub codelist {
}
$str =~ s/ $//;
push @lines, $str . "\\n\" \\\n";
- push @lines, " \" > - selected route, * - FIB route, q - queued route, r - rejected route\\n\\n\"";
+ push @lines, " \" > - selected route, * - FIB route, q - queued, r - rejected, b - backup\\n\\n\"";
return join("", @lines);
}
diff --git a/lib/routemap.c b/lib/routemap.c
index 22b4beb79d..df9a6a33ea 100644
--- a/lib/routemap.c
+++ b/lib/routemap.c
@@ -821,9 +821,10 @@ static void vty_show_route_map_entry(struct vty *vty, struct route_map *map)
struct route_map_index *index;
struct route_map_rule *rule;
- vty_out(vty, "route-map: %s Invoked: %" PRIu64 " Optimization: %s\n",
+ vty_out(vty, "route-map: %s Invoked: %" PRIu64 " Optimization: %s Processed Change: %s\n",
map->name, map->applied - map->applied_clear,
- map->optimization_disabled ? "disabled" : "enabled");
+ map->optimization_disabled ? "disabled" : "enabled",
+ map->to_be_processed ? "true" : "false");
for (index = map->head; index; index = index->next) {
vty_out(vty, " %s, sequence %d Invoked %" PRIu64 "\n",
@@ -2412,6 +2413,7 @@ route_map_result_t route_map_apply(struct route_map *map,
for (; index; index = index->next) {
if (!skip_match_clause) {
+ index->applied++;
/* Apply this index. */
match_ret = route_map_apply_match(&index->match_list,
prefix, type, object);
diff --git a/lib/routemap_cli.c b/lib/routemap_cli.c
index 2c45f09751..836be38113 100644
--- a/lib/routemap_cli.c
+++ b/lib/routemap_cli.c
@@ -39,7 +39,7 @@
#define ROUTE_MAP_SEQUENCE_CMD_STR \
"Sequence to insert to/delete from existing route-map entry\n"
-DEFPY_NOSH(
+DEFPY_YANG_NOSH(
route_map, route_map_cmd,
"route-map WORD$name <deny|permit>$action (1-65535)$sequence",
ROUTE_MAP_CMD_STR
@@ -70,6 +70,7 @@ DEFPY_NOSH(
VTY_PUSH_XPATH(RMAP_NODE, xpath_index);
/* Add support for non-migrated route map users. */
+ nb_cli_pending_commit_check(vty);
rm = route_map_get(name);
action_type = (action[0] == 'p') ? RMAP_PERMIT : RMAP_DENY;
rmi = route_map_index_get(rm, action_type, sequence);
@@ -79,7 +80,7 @@ DEFPY_NOSH(
return rv;
}
-DEFPY(
+DEFPY_YANG(
no_route_map_all, no_route_map_all_cmd,
"no route-map WORD$name",
NO_STR
@@ -94,7 +95,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
no_route_map, no_route_map_cmd,
"no route-map WORD$name <deny|permit>$action (1-65535)$sequence",
NO_STR
@@ -179,7 +180,7 @@ void route_map_instance_show_end(struct vty *vty, struct lyd_node *dnode)
vty_out(vty, "!\n");
}
-DEFPY(
+DEFPY_YANG(
match_interface, match_interface_cmd,
"match interface IFNAME",
MATCH_STR
@@ -196,7 +197,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
no_match_interface, no_match_interface_cmd,
"no match interface [IFNAME]",
NO_STR
@@ -211,9 +212,9 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
match_ip_address, match_ip_address_cmd,
- "match ip address <(1-199)$acll|(1300-2699)$aclh|WORD$name>",
+ "match ip address <(1-199)|(1300-2699)|WORD>$name",
MATCH_STR
IP_STR
"Match address of route\n"
@@ -223,34 +224,15 @@ DEFPY(
{
const char *xpath = "./match-condition[condition='ipv4-address-list']";
char xpath_value[XPATH_MAXLEN + 32];
- int acln = acll ? acll : aclh;
nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
- if (name) {
- snprintf(xpath_value, sizeof(xpath_value), "%s/list-name",
- xpath);
- nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, name);
- } else /* if (acll || aclh) */ {
- if ((acln >= 1 && acln <= 99)
- || (acln >= 1300 && acln <= 1999)) {
- snprintf(xpath_value, sizeof(xpath_value),
- "%s/access-list-num", xpath);
- } else {
- /*
- * if ((acln >= 100 && acln <= 199)
- * || (acln >= 2000 && acln <= 2699))
- */
- snprintf(xpath_value, sizeof(xpath_value),
- "%s/access-list-num-extended", xpath);
- }
- nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY,
- acll_str ? acll_str : aclh_str);
- }
+ snprintf(xpath_value, sizeof(xpath_value), "%s/list-name", xpath);
+ nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, name);
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
no_match_ip_address, no_match_ip_address_cmd,
"no match ip address [<(1-199)|(1300-2699)|WORD>]",
NO_STR
@@ -268,7 +250,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
match_ip_address_prefix_list,
match_ip_address_prefix_list_cmd,
"match ip address prefix-list WORD$name",
@@ -288,7 +270,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
no_match_ip_address_prefix_list, no_match_ip_address_prefix_list_cmd,
"no match ip address prefix-list [WORD]",
NO_STR
@@ -305,9 +287,9 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
match_ip_next_hop, match_ip_next_hop_cmd,
- "match ip next-hop <(1-199)$acll|(1300-2699)$aclh|WORD$name>",
+ "match ip next-hop <(1-199)|(1300-2699)|WORD>$name",
MATCH_STR
IP_STR
"Match next-hop address of route\n"
@@ -317,34 +299,15 @@ DEFPY(
{
const char *xpath = "./match-condition[condition='ipv4-next-hop-list']";
char xpath_value[XPATH_MAXLEN + 32];
- int acln = acll ? acll : aclh;
nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
- if (name) {
- snprintf(xpath_value, sizeof(xpath_value), "%s/list-name",
- xpath);
- nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, name);
- } else /* if (acll || aclh) */ {
- if ((acln >= 1 && acln <= 99)
- || (acln >= 1300 && acln <= 1999)) {
- snprintf(xpath_value, sizeof(xpath_value),
- "%s/access-list-num", xpath);
- } else {
- /*
- * if ((acln >= 100 && acln <= 199)
- * || (acln >= 2000 && acln <= 2699))
- */
- snprintf(xpath_value, sizeof(xpath_value),
- "%s/access-list-num-extended", xpath);
- }
- nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY,
- acll_str ? acll_str : aclh_str);
- }
+ snprintf(xpath_value, sizeof(xpath_value), "%s/list-name", xpath);
+ nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, name);
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
no_match_ip_next_hop, no_match_ip_next_hop_cmd,
"no match ip next-hop [<(1-199)|(1300-2699)|WORD>]",
NO_STR
@@ -362,7 +325,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
match_ip_next_hop_prefix_list,
match_ip_next_hop_prefix_list_cmd,
"match ip next-hop prefix-list WORD$name",
@@ -383,7 +346,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
no_match_ip_next_hop_prefix_list,
no_match_ip_next_hop_prefix_list_cmd,
"no match ip next-hop prefix-list [WORD]",
@@ -402,7 +365,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
match_ip_next_hop_type, match_ip_next_hop_type_cmd,
"match ip next-hop type <blackhole>$type",
MATCH_STR
@@ -422,7 +385,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
no_match_ip_next_hop_type, no_match_ip_next_hop_type_cmd,
"no match ip next-hop type [<blackhole>]",
NO_STR MATCH_STR IP_STR
@@ -437,7 +400,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
match_ipv6_address, match_ipv6_address_cmd,
"match ipv6 address WORD$name",
MATCH_STR
@@ -455,7 +418,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
no_match_ipv6_address, no_match_ipv6_address_cmd,
"no match ipv6 address [WORD]",
NO_STR
@@ -471,7 +434,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
match_ipv6_address_prefix_list, match_ipv6_address_prefix_list_cmd,
"match ipv6 address prefix-list WORD$name",
MATCH_STR
@@ -490,7 +453,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
no_match_ipv6_address_prefix_list,
no_match_ipv6_address_prefix_list_cmd,
"no match ipv6 address prefix-list [WORD]",
@@ -508,7 +471,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
match_ipv6_next_hop_type, match_ipv6_next_hop_type_cmd,
"match ipv6 next-hop type <blackhole>$type",
MATCH_STR IPV6_STR
@@ -527,7 +490,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
no_match_ipv6_next_hop_type, no_match_ipv6_next_hop_type_cmd,
"no match ipv6 next-hop type [<blackhole>]",
NO_STR MATCH_STR IPV6_STR
@@ -542,7 +505,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
match_metric, match_metric_cmd,
"match metric (0-4294967295)$metric",
MATCH_STR
@@ -559,7 +522,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
no_match_metric, no_match_metric_cmd,
"no match metric [(0-4294967295)]",
NO_STR
@@ -574,7 +537,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
match_tag, match_tag_cmd,
"match tag (1-4294967295)$tag",
MATCH_STR
@@ -591,7 +554,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
no_match_tag, no_match_tag_cmd,
"no match tag [(1-4294967295)]",
NO_STR
@@ -610,8 +573,6 @@ void route_map_condition_show(struct vty *vty, struct lyd_node *dnode,
bool show_defaults)
{
int condition = yang_dnode_get_enum(dnode, "./condition");
- struct lyd_node *ln;
- const char *acl;
switch (condition) {
case 0: /* interface */
@@ -620,25 +581,14 @@ void route_map_condition_show(struct vty *vty, struct lyd_node *dnode,
break;
case 1: /* ipv4-address-list */
case 3: /* ipv4-next-hop-list */
- acl = NULL;
- if ((ln = yang_dnode_get(dnode, "./list-name")) != NULL)
- acl = yang_dnode_get_string(ln, NULL);
- else if ((ln = yang_dnode_get(dnode, "./access-list-num"))
- != NULL)
- acl = yang_dnode_get_string(ln, NULL);
- else if ((ln = yang_dnode_get(dnode,
- "./access-list-num-extended"))
- != NULL)
- acl = yang_dnode_get_string(ln, NULL);
-
- assert(acl);
-
switch (condition) {
case 1:
- vty_out(vty, " match ip address %s\n", acl);
+ vty_out(vty, " match ip address %s\n",
+ yang_dnode_get_string(dnode, "./list-name"));
break;
case 3:
- vty_out(vty, " match ip next-hop %s\n", acl);
+ vty_out(vty, " match ip next-hop %s\n",
+ yang_dnode_get_string(dnode, "./list-name"));
break;
}
break;
@@ -697,7 +647,7 @@ void route_map_condition_show(struct vty *vty, struct lyd_node *dnode,
}
}
-DEFPY(
+DEFPY_YANG(
set_ip_nexthop, set_ip_nexthop_cmd,
"set ip next-hop A.B.C.D$addr",
SET_STR
@@ -715,7 +665,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
no_set_ip_nexthop, no_set_ip_nexthop_cmd,
"no set ip next-hop [A.B.C.D]",
NO_STR
@@ -731,7 +681,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
set_ipv6_nexthop_local, set_ipv6_nexthop_local_cmd,
"set ipv6 next-hop local X:X::X:X$addr",
SET_STR
@@ -750,7 +700,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
no_set_ipv6_nexthop_local, no_set_ipv6_nexthop_local_cmd,
"no set ipv6 next-hop local [X:X::X:X]",
NO_STR
@@ -767,7 +717,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
set_metric, set_metric_cmd,
"set metric <(0-4294967295)$metric|rtt$rtt|+rtt$artt|-rtt$srtt|+metric$ametric|-metric$smetric>",
SET_STR
@@ -813,7 +763,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
no_set_metric, no_set_metric_cmd,
"no set metric [(0-4294967295)]",
NO_STR
@@ -827,7 +777,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
set_tag, set_tag_cmd,
"set tag (1-4294967295)$tag",
SET_STR
@@ -844,7 +794,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
no_set_tag, no_set_tag_cmd,
"no set tag [(1-4294967295)]",
NO_STR
@@ -904,7 +854,7 @@ void route_map_action_show(struct vty *vty, struct lyd_node *dnode,
}
}
-DEFPY(
+DEFPY_YANG(
rmap_onmatch_next, rmap_onmatch_next_cmd,
"on-match next",
"Exit policy on matches\n"
@@ -915,7 +865,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
no_rmap_onmatch_next,
no_rmap_onmatch_next_cmd,
"no on-match next",
@@ -928,7 +878,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
rmap_onmatch_goto, rmap_onmatch_goto_cmd,
"on-match goto (1-65535)$rm_num",
"Exit policy on matches\n"
@@ -941,7 +891,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
no_rmap_onmatch_goto, no_rmap_onmatch_goto_cmd,
"no on-match goto",
NO_STR
@@ -954,13 +904,13 @@ DEFPY(
}
/* Cisco/GNU Zebra compatibility aliases */
-ALIAS(
+ALIAS_YANG(
rmap_onmatch_goto, rmap_continue_cmd,
"continue (1-65535)$rm_num",
"Continue on a different entry within the route-map\n"
"Route-map entry sequence number\n")
-ALIAS(
+ALIAS_YANG(
no_rmap_onmatch_goto, no_rmap_continue_cmd,
"no continue [(1-65535)]",
NO_STR
@@ -986,7 +936,7 @@ void route_map_exit_policy_show(struct vty *vty, struct lyd_node *dnode,
}
}
-DEFPY(
+DEFPY_YANG(
rmap_call, rmap_call_cmd,
"call WORD$name",
"Jump to another Route-Map after match+set\n"
@@ -997,11 +947,12 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
no_rmap_call, no_rmap_call_cmd,
- "no call",
+ "no call [NAME]",
NO_STR
- "Jump to another Route-Map after match+set\n")
+ "Jump to another Route-Map after match+set\n"
+ "Target route-map name\n")
{
nb_cli_enqueue_change(vty, "./call", NB_OP_DESTROY, NULL);
@@ -1014,7 +965,7 @@ void route_map_call_show(struct vty *vty, struct lyd_node *dnode,
vty_out(vty, " call %s\n", yang_dnode_get_string(dnode, NULL));
}
-DEFPY(
+DEFPY_YANG(
rmap_description, rmap_description_cmd,
"description LINE...",
"Route-map comment\n"
@@ -1031,7 +982,7 @@ DEFPY(
return rv;
}
-DEFUN (no_rmap_description,
+DEFUN_YANG (no_rmap_description,
no_rmap_description_cmd,
"no description",
NO_STR
diff --git a/lib/routemap_northbound.c b/lib/routemap_northbound.c
index f500a6c408..967f3fd4d4 100644
--- a/lib/routemap_northbound.c
+++ b/lib/routemap_northbound.c
@@ -516,77 +516,6 @@ static int lib_route_map_entry_match_condition_interface_destroy(
}
/*
- * XPath: /frr-route-map:lib/route-map/entry/match-condition/access-list-num
- */
-static int lib_route_map_entry_match_condition_access_list_num_modify(
- struct nb_cb_modify_args *args)
-{
- struct routemap_hook_context *rhc;
- const char *acl;
- int condition, rv;
-
- if (args->event != NB_EV_APPLY)
- return NB_OK;
-
- /* Check for hook function. */
- rv = CMD_SUCCESS;
- acl = yang_dnode_get_string(args->dnode, NULL);
- rhc = nb_running_get_entry(args->dnode, NULL, true);
- condition = yang_dnode_get_enum(args->dnode, "../condition");
- switch (condition) {
- case 1: /* ipv4-address-list */
- if (rmap_match_set_hook.match_ip_address == NULL)
- break;
- rhc->rhc_mhook = rmap_match_set_hook.no_match_ip_address;
- rhc->rhc_rule = "ip address";
- rhc->rhc_event = RMAP_EVENT_FILTER_DELETED;
- rv = rmap_match_set_hook.match_ip_address(
- NULL, rhc->rhc_rmi, "ip address", acl,
- RMAP_EVENT_FILTER_ADDED);
- break;
- case 3: /* ipv4-next-hop-list */
- if (rmap_match_set_hook.match_ip_next_hop == NULL)
- break;
- rhc->rhc_mhook = rmap_match_set_hook.no_match_ip_next_hop;
- rhc->rhc_rule = "ip next-hop";
- rhc->rhc_event = RMAP_EVENT_FILTER_DELETED;
- rv = rmap_match_set_hook.match_ip_next_hop(
- NULL, rhc->rhc_rmi, "ip next-hop", acl,
- RMAP_EVENT_FILTER_ADDED);
- break;
- }
- if (rv != CMD_SUCCESS) {
- rhc->rhc_mhook = NULL;
- return NB_ERR_INCONSISTENCY;
- }
-
- return NB_OK;
-}
-
-static int lib_route_map_entry_match_condition_access_list_num_destroy(
- struct nb_cb_destroy_args *args)
-{
- return lib_route_map_entry_match_destroy(args);
-}
-
-/*
- * XPath:
- * /frr-route-map:lib/route-map/entry/match-condition/access-list-num-extended
- */
-static int lib_route_map_entry_match_condition_access_list_num_extended_modify(
- struct nb_cb_modify_args *args)
-{
- return lib_route_map_entry_match_condition_access_list_num_modify(args);
-}
-
-static int lib_route_map_entry_match_condition_access_list_num_extended_destroy(
- struct nb_cb_destroy_args *args)
-{
- return lib_route_map_entry_match_condition_access_list_num_destroy(
- args);
-}
-
-/*
* XPath: /frr-route-map:lib/route-map/entry/match-condition/list-name
*/
static int lib_route_map_entry_match_condition_list_name_modify(
@@ -1245,20 +1174,6 @@ const struct frr_yang_module_info frr_route_map_info = {
}
},
{
- .xpath = "/frr-route-map:lib/route-map/entry/match-condition/access-list-num",
- .cbs = {
- .modify = lib_route_map_entry_match_condition_access_list_num_modify,
- .destroy = lib_route_map_entry_match_condition_access_list_num_destroy,
- }
- },
- {
- .xpath = "/frr-route-map:lib/route-map/entry/match-condition/access-list-num-extended",
- .cbs = {
- .modify = lib_route_map_entry_match_condition_access_list_num_extended_modify,
- .destroy = lib_route_map_entry_match_condition_access_list_num_extended_destroy,
- }
- },
- {
.xpath = "/frr-route-map:lib/route-map/entry/match-condition/list-name",
.cbs = {
.modify = lib_route_map_entry_match_condition_list_name_modify,
diff --git a/lib/routing_nb.c b/lib/routing_nb.c
new file mode 100644
index 0000000000..0160354a7e
--- /dev/null
+++ b/lib/routing_nb.c
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2018 Vmware
+ * Vishal Dhingra
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; see the file COPYING; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#include "northbound.h"
+#include "libfrr.h"
+#include "routing_nb.h"
+
+
+
+/* clang-format off */
+const struct frr_yang_module_info frr_routing_info = {
+ .name = "frr-routing",
+ .nodes = {
+ {
+ .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol",
+ .cbs = {
+ .create = routing_control_plane_protocols_control_plane_protocol_create,
+ .destroy = routing_control_plane_protocols_control_plane_protocol_destroy,
+ }
+ },
+ {
+ .xpath = NULL,
+ },
+ }
+};
diff --git a/lib/routing_nb.h b/lib/routing_nb.h
new file mode 100644
index 0000000000..d1b59ea29e
--- /dev/null
+++ b/lib/routing_nb.h
@@ -0,0 +1,24 @@
+#ifndef _FRR_ROUTING_NB_H_
+#define _FRR_ROUTING_NB_H_
+
+extern const struct frr_yang_module_info frr_routing_info;
+
+/* Mandatory callbacks. */
+int routing_control_plane_protocols_control_plane_protocol_create(
+ struct nb_cb_create_args *args);
+int routing_control_plane_protocols_control_plane_protocol_destroy(
+ struct nb_cb_destroy_args *args);
+
+#define FRR_ROUTING_XPATH \
+ "/frr-routing:routing/control-plane-protocols/control-plane-protocol"
+
+#define FRR_ROUTING_KEY_XPATH \
+ "/frr-routing:routing/control-plane-protocols/" \
+ "control-plane-protocol[type='%s'][name='%s'][vrf='%s']"
+/*
+ * callbacks for routing to handle configuration events
+ * based on the control plane protocol
+ */
+DECLARE_HOOK(routing_conf_event, (struct nb_cb_create_args *args), (args))
+
+#endif /* _FRR_ROUTING_NB_H_ */
diff --git a/lib/routing_nb_config.c b/lib/routing_nb_config.c
new file mode 100644
index 0000000000..b789e8494e
--- /dev/null
+++ b/lib/routing_nb_config.c
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2018 Vmware
+ * Vishal Dhingra
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; see the file COPYING; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "northbound.h"
+#include "libfrr.h"
+#include "vrf.h"
+#include "lib_errors.h"
+#include "routing_nb.h"
+
+
+DEFINE_HOOK(routing_conf_event, (struct nb_cb_create_args *args), (args))
+
+/*
+ * XPath: /frr-routing:routing/control-plane-protocols/control-plane-protocol
+ */
+
+int routing_control_plane_protocols_control_plane_protocol_create(
+ struct nb_cb_create_args *args)
+{
+ struct vrf *vrf;
+ const char *vrfname;
+
+ switch (args->event) {
+ case NB_EV_VALIDATE:
+ if (hook_call(routing_conf_event, args))
+ return NB_ERR_VALIDATION;
+ break;
+ case NB_EV_PREPARE:
+ case NB_EV_ABORT:
+ break;
+ case NB_EV_APPLY:
+ vrfname = yang_dnode_get_string(args->dnode, "./vrf");
+ vrf = vrf_lookup_by_name(vrfname);
+ vrf = vrf ? vrf : vrf_get(VRF_UNKNOWN, vrfname);
+ if (!vrf) {
+ flog_warn(EC_LIB_NB_CB_CONFIG_APPLY,
+ "vrf creation %s failed", vrfname);
+ return NB_ERR;
+ }
+ nb_running_set_entry(args->dnode, vrf);
+ break;
+ };
+
+ return NB_OK;
+}
+
+int routing_control_plane_protocols_control_plane_protocol_destroy(
+ struct nb_cb_destroy_args *args)
+{
+ struct vrf *vrf __attribute__((unused));
+
+ if (args->event != NB_EV_APPLY)
+ return NB_OK;
+
+ vrf = nb_running_unset_entry(args->dnode);
+
+ return NB_OK;
+}
diff --git a/lib/sockunion.c b/lib/sockunion.c
index 0e7483bfbe..d77229797c 100644
--- a/lib/sockunion.c
+++ b/lib/sockunion.c
@@ -27,6 +27,7 @@
#include "log.h"
#include "jhash.h"
#include "lib_errors.h"
+#include "printfrr.h"
DEFINE_MTYPE_STATIC(LIB, SOCKUNION, "Socket union")
@@ -665,3 +666,49 @@ void sockunion_init(union sockunion *su)
{
memset(su, 0, sizeof(union sockunion));
}
+
+printfrr_ext_autoreg_p("SU", printfrr_psu)
+static ssize_t printfrr_psu(char *buf, size_t bsz, const char *fmt,
+ int prec, const void *ptr)
+{
+ const union sockunion *su = ptr;
+ struct fbuf fb = { .buf = buf, .pos = buf, .len = bsz - 1 };
+ bool include_port = false;
+ bool endflags = false;
+ ssize_t consumed = 2;
+
+ while (!endflags) {
+ switch (fmt[consumed++]) {
+ case 'p':
+ include_port = true;
+ break;
+ default:
+ consumed--;
+ endflags = true;
+ break;
+ }
+ };
+
+ switch (sockunion_family(su)) {
+ case AF_UNSPEC:
+ bprintfrr(&fb, "(unspec)");
+ break;
+ case AF_INET:
+ inet_ntop(AF_INET, &su->sin.sin_addr, buf, bsz);
+ fb.pos += strlen(fb.buf);
+ if (include_port)
+ bprintfrr(&fb, ":%d", su->sin.sin_port);
+ break;
+ case AF_INET6:
+ inet_ntop(AF_INET6, &su->sin6.sin6_addr, buf, bsz);
+ fb.pos += strlen(fb.buf);
+ if (include_port)
+ bprintfrr(&fb, ":%d", su->sin6.sin6_port);
+ break;
+ default:
+ bprintfrr(&fb, "(af %d)", sockunion_family(su));
+ }
+
+ fb.pos[0] = '\0';
+ return consumed;
+}
diff --git a/lib/sockunion.h b/lib/sockunion.h
index 7091c1b5e7..72f12b77ca 100644
--- a/lib/sockunion.h
+++ b/lib/sockunion.h
@@ -103,6 +103,10 @@ extern union sockunion *sockunion_dup(const union sockunion *);
extern void sockunion_free(union sockunion *);
extern void sockunion_init(union sockunion *);
+#ifdef _FRR_ATTRIBUTE_PRINTFRR
+#pragma FRR printfrr_ext "%pSU" (union sockunion *)
+#endif
+
#ifdef __cplusplus
}
#endif
diff --git a/lib/srcdest_table.c b/lib/srcdest_table.c
index 66b735919b..8ffa0e9709 100644
--- a/lib/srcdest_table.c
+++ b/lib/srcdest_table.c
@@ -317,3 +317,13 @@ static ssize_t printfrr_rn(char *buf, size_t bsz, const char *fmt,
srcdest2str(dst_p, (const struct prefix_ipv6 *)src_p, buf, bsz);
return 2;
}
+
+struct route_table *srcdest_srcnode_table(struct route_node *rn)
+{
+ if (rnode_is_dstnode(rn)) {
+ struct srcdest_rnode *srn = srcdest_rnode_from_rnode(rn);
+
+ return srn->src_table;
+ }
+ return NULL;
+}
diff --git a/lib/srcdest_table.h b/lib/srcdest_table.h
index 7982260777..79afef9bb0 100644
--- a/lib/srcdest_table.h
+++ b/lib/srcdest_table.h
@@ -100,6 +100,8 @@ static inline void *srcdest_rnode_table_info(struct route_node *rn)
return route_table_get_info(srcdest_rnode_table(rn));
}
+extern struct route_table *srcdest_srcnode_table(struct route_node *rn);
+
#ifdef __cplusplus
}
#endif
diff --git a/lib/stream.c b/lib/stream.c
index 17520f978e..d3afebbf13 100644
--- a/lib/stream.c
+++ b/lib/stream.c
@@ -55,15 +55,19 @@ DEFINE_MTYPE_STATIC(LIB, STREAM_FIFO, "Stream FIFO")
* using stream_put..._at() functions.
*/
#define STREAM_WARN_OFFSETS(S) \
- flog_warn(EC_LIB_STREAM, \
- "&(struct stream): %p, size: %lu, getp: %lu, endp: %lu\n", \
- (void *)(S), (unsigned long)(S)->size, \
- (unsigned long)(S)->getp, (unsigned long)(S)->endp)
+ do { \
+ flog_warn(EC_LIB_STREAM, \
+ "&(struct stream): %p, size: %lu, getp: %lu, endp: %lu\n", \
+ (void *)(S), (unsigned long)(S)->size, \
+ (unsigned long)(S)->getp, (unsigned long)(S)->endp); \
+ zlog_backtrace(LOG_WARNING); \
+ } while (0)
#define STREAM_VERIFY_SANE(S) \
do { \
- if (!(GETP_VALID(S, (S)->getp) && ENDP_VALID(S, (S)->endp))) \
+ if (!(GETP_VALID(S, (S)->getp) && ENDP_VALID(S, (S)->endp))) { \
STREAM_WARN_OFFSETS(S); \
+ } \
assert(GETP_VALID(S, (S)->getp)); \
assert(ENDP_VALID(S, (S)->endp)); \
} while (0)
diff --git a/lib/subdir.am b/lib/subdir.am
index 57b2cea832..34ad30f968 100644
--- a/lib/subdir.am
+++ b/lib/subdir.am
@@ -108,6 +108,8 @@ lib_libfrr_la_SOURCES = \
lib/printf/printf-pos.c \
lib/printf/vfprintf.c \
lib/printf/glue.c \
+ lib/routing_nb.c \
+ lib/routing_nb_config.c \
# end
nodist_lib_libfrr_la_SOURCES = \
@@ -117,13 +119,11 @@ nodist_lib_libfrr_la_SOURCES = \
yang/frr-route-types.yang.c \
yang/frr-vrf.yang.c \
yang/frr-routing.yang.c \
+ yang/frr-nexthop.yang.c \
yang/ietf/ietf-routing-types.yang.c \
yang/ietf/ietf-interfaces.yang.c \
yang/frr-module-translator.yang.c \
yang/frr-nexthop.yang.c \
- yang/frr-igmp.yang.c \
- yang/frr-pim.yang.c \
- yang/frr-pim-rp.yang.c \
# end
vtysh_scan += \
@@ -266,6 +266,7 @@ pkginclude_HEADERS += \
lib/zlog.h \
lib/zlog_targets.h \
lib/pbr.h \
+ lib/routing_nb.h \
# end
diff --git a/lib/thread.c b/lib/thread.c
index 5c7c104842..1df4eee25c 100644
--- a/lib/thread.c
+++ b/lib/thread.c
@@ -634,6 +634,36 @@ struct timeval thread_timer_remain(struct thread *thread)
return remain;
}
+static int time_hhmmss(char *buf, int buf_size, long sec)
+{
+ long hh;
+ long mm;
+ int wr;
+
+ zassert(buf_size >= 8);
+
+ hh = sec / 3600;
+ sec %= 3600;
+ mm = sec / 60;
+ sec %= 60;
+
+ wr = snprintf(buf, buf_size, "%02ld:%02ld:%02ld", hh, mm, sec);
+
+ return wr != 8;
+}
+
+char *thread_timer_to_hhmmss(char *buf, int buf_size,
+ struct thread *t_timer)
+{
+ if (t_timer) {
+ time_hhmmss(buf, buf_size,
+ thread_timer_remain_second(t_timer));
+ } else {
+ snprintf(buf, buf_size, "--:--:--");
+ }
+ return buf;
+}
+
/* Get new thread. */
static struct thread *thread_get(struct thread_master *m, uint8_t type,
int (*func)(struct thread *), void *arg,
diff --git a/lib/thread.h b/lib/thread.h
index 412a4d93bf..c22b2105cd 100644
--- a/lib/thread.h
+++ b/lib/thread.h
@@ -140,6 +140,8 @@ struct cpu_thread_history {
/* Thread yield time. */
#define THREAD_YIELD_TIME_SLOT 10 * 1000L /* 10ms */
+#define THREAD_TIMER_STRLEN 12
+
/* Macros. */
#define THREAD_ARG(X) ((X)->arg)
#define THREAD_FD(X) ((X)->u.fd)
@@ -228,6 +230,8 @@ extern unsigned long thread_consumed_time(RUSAGE_T *after, RUSAGE_T *before,
/* only for use in logging functions! */
extern pthread_key_t thread_current;
+extern char *thread_timer_to_hhmmss(char *buf, int buf_size,
+ struct thread *t_timer);
#ifdef __cplusplus
}
diff --git a/lib/vrf.c b/lib/vrf.c
index a9ea632ac5..2a3ce2a315 100644
--- a/lib/vrf.c
+++ b/lib/vrf.c
@@ -638,6 +638,7 @@ int vrf_handler_create(struct vty *vty, const char *vrfname,
ret = nb_cli_apply_changes(vty, xpath_list);
if (ret == CMD_SUCCESS) {
VTY_PUSH_XPATH(VRF_NODE, xpath_list);
+ nb_cli_pending_commit_check(vty);
vrfp = vrf_lookup_by_name(vrfname);
if (vrfp)
VTY_PUSH_CONTEXT(VRF_NODE, vrfp);
@@ -652,8 +653,7 @@ int vrf_handler_create(struct vty *vty, const char *vrfname,
}
int vrf_netns_handler_create(struct vty *vty, struct vrf *vrf, char *pathname,
- ns_id_t ns_id, ns_id_t internal_ns_id,
- ns_id_t rel_def_ns_id)
+ ns_id_t ns_id, ns_id_t internal_ns_id)
{
struct ns *ns = NULL;
@@ -700,7 +700,6 @@ int vrf_netns_handler_create(struct vty *vty, struct vrf *vrf, char *pathname,
}
ns = ns_get_created(ns, pathname, ns_id);
ns->internal_ns_id = internal_ns_id;
- ns->relative_default_ns = rel_def_ns_id;
ns->vrf_ctxt = (void *)vrf;
vrf->ns_ctxt = (void *)ns;
/* update VRF netns NAME */
@@ -731,7 +730,7 @@ DEFUN_NOSH(vrf_exit,
return CMD_SUCCESS;
}
-DEFUN_NOSH (vrf,
+DEFUN_YANG_NOSH (vrf,
vrf_cmd,
"vrf NAME",
"Select a VRF to configure\n"
@@ -743,7 +742,7 @@ DEFUN_NOSH (vrf,
return vrf_handler_create(vty, vrfname, NULL);
}
-DEFUN (no_vrf,
+DEFUN_YANG (no_vrf,
no_vrf_cmd,
"no vrf NAME",
NO_STR
@@ -757,10 +756,8 @@ DEFUN (no_vrf,
vrfp = vrf_lookup_by_name(vrfname);
- if (vrfp == NULL) {
- vty_out(vty, "%% VRF %s does not exist\n", vrfname);
- return CMD_WARNING_CONFIG_FAILED;
- }
+ if (vrfp == NULL)
+ return CMD_SUCCESS;
if (CHECK_FLAG(vrfp->status, VRF_ACTIVE)) {
vty_out(vty, "%% Only inactive VRFs can be deleted\n");
@@ -798,9 +795,7 @@ DEFUN_NOSH (vrf_netns,
frr_with_privs(vrf_daemon_privs) {
ret = vrf_netns_handler_create(vty, vrf, pathname,
- NS_UNKNOWN,
- NS_UNKNOWN,
- NS_UNKNOWN);
+ NS_UNKNOWN, NS_UNKNOWN);
}
return ret;
}
diff --git a/lib/vrf.h b/lib/vrf.h
index a8514d74ed..83ed16b48e 100644
--- a/lib/vrf.h
+++ b/lib/vrf.h
@@ -315,7 +315,7 @@ extern int vrf_handler_create(struct vty *vty, const char *name,
*/
extern int vrf_netns_handler_create(struct vty *vty, struct vrf *vrf,
char *pathname, ns_id_t ext_ns_id,
- ns_id_t ns_id, ns_id_t rel_def_ns_id);
+ ns_id_t ns_id);
/* used internally to enable or disable VRF.
* Notify a change in the VRF ID of the VRF
diff --git a/lib/vty.c b/lib/vty.c
index 0d0e54af6c..184c7604b8 100644
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -2631,6 +2631,9 @@ int vty_config_node_exit(struct vty *vty)
{
vty->xpath_index = 0;
+ /* Perform pending commit if any. */
+ nb_cli_pending_commit_check(vty);
+
/* Check if there's a pending confirmed commit. */
if (vty->t_confirmed_commit_timeout) {
vty_out(vty,
diff --git a/lib/vty.h b/lib/vty.h
index 5d5676199b..623f97ab03 100644
--- a/lib/vty.h
+++ b/lib/vty.h
@@ -134,6 +134,14 @@ struct vty {
/* Base candidate configuration. */
struct nb_config *candidate_config_base;
+ /* Dynamic transaction information. */
+ struct timeval backoff_start;
+ size_t backoff_cmd_count;
+ struct thread *t_pending_commit;
+ char *pending_cmds_buf;
+ size_t pending_cmds_buflen;
+ size_t pending_cmds_bufpos;
+
/* Confirmed-commit timeout and rollback configuration. */
struct thread *t_confirmed_commit_timeout;
struct nb_config *confirmed_commit_rollback;
diff --git a/lib/yang.c b/lib/yang.c
index 0714ddf7bb..6ab9492d52 100644
--- a/lib/yang.c
+++ b/lib/yang.c
@@ -53,22 +53,30 @@ static const char *yang_module_imp_clb(const char *mod_name,
{
struct yang_module_embed *e;
- if (submod_name || submod_rev)
- return NULL;
-
for (e = embeds; e; e = e->next) {
- if (strcmp(e->mod_name, mod_name))
- continue;
- if (mod_rev && strcmp(e->mod_rev, mod_rev))
- continue;
+ if (e->sub_mod_name && submod_name) {
+ if (strcmp(e->sub_mod_name, submod_name))
+ continue;
+
+ if (submod_rev && strcmp(e->sub_mod_rev, submod_rev))
+ continue;
+ } else {
+ if (strcmp(e->mod_name, mod_name))
+ continue;
+
+ if (mod_rev && strcmp(e->mod_rev, mod_rev))
+ continue;
+ }
*format = e->format;
return e->data;
}
- flog_warn(EC_LIB_YANG_MODULE_LOAD,
- "YANG model \"%s@%s\" not embedded, trying external file",
- mod_name, mod_rev ? mod_rev : "*");
+ flog_warn(
+ EC_LIB_YANG_MODULE_LOAD,
+ "YANG model \"%s@%s\" \"%s@%s\"not embedded, trying external file",
+ mod_name, mod_rev ? mod_rev : "*",
+ submod_name ? submod_name : "*", submod_rev ? submod_rev : "*");
return NULL;
}
@@ -749,3 +757,147 @@ void yang_terminate(void)
ly_ctx_destroy(ly_native_ctx, NULL);
}
+
+const struct lyd_node *yang_dnode_get_parent(const struct lyd_node *dnode,
+ const char *name)
+{
+ const struct lyd_node *orig_dnode = dnode;
+
+ while (orig_dnode) {
+ switch (orig_dnode->schema->nodetype) {
+ case LYS_LIST:
+ case LYS_CONTAINER:
+ if (!strcmp(orig_dnode->schema->name, name))
+ return orig_dnode;
+ break;
+ default:
+ break;
+ }
+
+ orig_dnode = orig_dnode->parent;
+ }
+
+ return NULL;
+}
+
+/* API to check if the given node is last node in the list */
+static bool yang_is_last_list_dnode(const struct lyd_node *dnode)
+{
+ return (((dnode->next == NULL)
+ || (dnode->next
+ && (strcmp(dnode->next->schema->name, dnode->schema->name)
+ != 0)))
+ && dnode->prev
+ && ((dnode->prev == dnode)
+ || (strcmp(dnode->prev->schema->name, dnode->schema->name)
+ != 0)));
+}
+
+/* API to check if the given node is last node in the data tree level */
+static bool yang_is_last_level_dnode(const struct lyd_node *dnode)
+{
+ const struct lyd_node *parent;
+ const struct lys_node_list *snode;
+ const struct lyd_node *key_leaf;
+ uint8_t keys_size;
+
+ switch (dnode->schema->nodetype) {
+ case LYS_LIST:
+ assert(dnode->parent);
+ parent = dnode->parent;
+ snode = (struct lys_node_list *)parent->schema;
+ key_leaf = dnode->prev;
+ for (keys_size = 1; keys_size < snode->keys_size; keys_size++)
+ key_leaf = key_leaf->prev;
+ if (key_leaf->prev == dnode)
+ return true;
+ break;
+ case LYS_CONTAINER:
+ return true;
+ default:
+ break;
+ }
+
+ return false;
+}
+
+
+const struct lyd_node *
+yang_get_subtree_with_no_sibling(const struct lyd_node *dnode)
+{
+ bool parent = true;
+ const struct lyd_node *node;
+ const struct lys_node_container *snode;
+
+ node = dnode;
+ if (node->schema->nodetype != LYS_LIST)
+ return node;
+
+ while (parent) {
+ switch (node->schema->nodetype) {
+ case LYS_CONTAINER:
+ snode = (struct lys_node_container *)node->schema;
+ if ((!snode->presence)
+ && yang_is_last_level_dnode(node)) {
+ if (node->parent
+ && (node->parent->schema->module
+ == dnode->schema->module))
+ node = node->parent;
+ else
+ parent = false;
+ } else
+ parent = false;
+ break;
+ case LYS_LIST:
+ if (yang_is_last_list_dnode(node)
+ && yang_is_last_level_dnode(node)) {
+ if (node->parent
+ && (node->parent->schema->module
+ == dnode->schema->module))
+ node = node->parent;
+ else
+ parent = false;
+ } else
+ parent = false;
+ break;
+ default:
+ parent = false;
+ break;
+ }
+ }
+ return node;
+}
+
+uint32_t yang_get_list_pos(const struct lyd_node *node)
+{
+ return lyd_list_pos(node);
+}
+
+uint32_t yang_get_list_elements_count(const struct lyd_node *node)
+{
+ unsigned int count;
+ struct lys_node *schema;
+
+ if (!node
+ || ((node->schema->nodetype != LYS_LIST)
+ && (node->schema->nodetype != LYS_LEAFLIST))) {
+ return 0;
+ }
+
+ schema = node->schema;
+ count = 0;
+ do {
+ if (node->schema == schema)
+ ++count;
+ node = node->next;
+ } while (node);
+ return count;
+}
+
+
+const struct lyd_node *yang_dnode_get_child(const struct lyd_node *dnode)
+{
+ if (dnode)
+ return dnode->child;
+ return NULL;
+}
diff --git a/lib/yang.h b/lib/yang.h
index 85ef0d758c..cc048c44e8 100644
--- a/lib/yang.h
+++ b/lib/yang.h
@@ -34,7 +34,7 @@ extern "C" {
#endif
/* Maximum XPath length. */
-#define XPATH_MAXLEN 512
+#define XPATH_MAXLEN 1024
/* Maximum list key length. */
#define LIST_MAXKEYS 8
@@ -48,6 +48,8 @@ extern "C" {
struct yang_module_embed {
struct yang_module_embed *next;
const char *mod_name, *mod_rev;
+ const char *sub_mod_name;
+ const char *sub_mod_rev;
const char *data;
LYS_INFORMAT format;
};
@@ -551,6 +553,57 @@ extern void yang_init(bool embedded_modules);
*/
extern void yang_terminate(void);
+/*
+ * API to return the parent dnode having a given schema-node name
+ * Use case: One has to access the parent dnode's private pointer
+ * for a given child node.
+ * For that there is a need to find parent dnode first.
+ *
+ * dnode The starting node to work on
+ *
+ * name The name of container/list schema-node
+ *
+ * Returns The dnode matched with the given name
+ */
+extern const struct lyd_node *
+yang_dnode_get_parent(const struct lyd_node *dnode, const char *name);
+
+
+/*
+ * In some cases there is a need to auto delete the parent nodes
+ * if the given node is last in the list.
+ * It tries to delete all the parents in a given tree in a given module.
+ * The use case is with static routes and route maps
+ * example : ip route 1.1.1.1/32 ens33
+ * ip route 1.1.1.1/32 ens34
+ * After this no ip route 1.1.1.1/32 ens34 came, now staticd
+ * has to find out upto which level it has to delete the dnodes.
+ * For this case it has to send delete nexthop
+ * After this no ip route 1.1.1.1/32 ens33 came, now staticd has to
+ * clear nexthop, path and route nodes.
+ * The same scheme is required for routemaps also
+ * dnode The starting node to work on
+ *
+ * Returns The final parent node selected for deletion
+ */
+extern const struct lyd_node *
+yang_get_subtree_with_no_sibling(const struct lyd_node *dnode);
+
+/* To get the relative position of a node in list */
+extern uint32_t yang_get_list_pos(const struct lyd_node *node);
+
+/* To get the number of elements in a list
+ *
+ * dnode : The head of list
+ * Returns : The number of dnodes present in the list
+ */
+extern uint32_t yang_get_list_elements_count(const struct lyd_node *node);
+
+
+/* To get the immediate child of a dnode */
+const struct lyd_node *yang_dnode_get_child(const struct lyd_node *dnode);
+
+
#ifdef __cplusplus
}
#endif
diff --git a/lib/yang_wrappers.c b/lib/yang_wrappers.c
index c31ba3fcc0..4f743096ee 100644
--- a/lib/yang_wrappers.c
+++ b/lib/yang_wrappers.c
@@ -1191,3 +1191,63 @@ const char *yang_nexthop_type2str(uint32_t ntype)
break;
}
}
+
+
+const char *yang_afi_safi_value2identity(afi_t afi, safi_t safi)
+{
+ if (afi == AFI_IP && safi == SAFI_UNICAST)
+ return "frr-routing:ipv4-unicast";
+ if (afi == AFI_IP6 && safi == SAFI_UNICAST)
+ return "frr-routing:ipv6-unicast";
+ if (afi == AFI_IP && safi == SAFI_MULTICAST)
+ return "frr-routing:ipv4-multicast";
+ if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
+ return "frr-routing:ipv6-multicast";
+ if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
+ return "frr-routing:l3vpn-ipv4-unicast";
+ if (afi == AFI_IP6 && safi == SAFI_MPLS_VPN)
+ return "frr-routing:l3vpn-ipv6-unicast";
+ if (afi == AFI_L2VPN && safi == SAFI_EVPN)
+ return "frr-routing:l2vpn-evpn";
+ if (afi == AFI_IP && safi == SAFI_LABELED_UNICAST)
+ return "frr-routing:ipv4-labeled-unicast";
+ if (afi == AFI_IP6 && safi == SAFI_LABELED_UNICAST)
+ return "frr-routing:ipv6-labeled-unicast";
+
+ return NULL;
+}
+
+void yang_afi_safi_identity2value(const char *key, afi_t *afi, safi_t *safi)
+{
+ if (strmatch(key, "frr-routing:ipv4-unicast")) {
+ *afi = AFI_IP;
+ *safi = SAFI_UNICAST;
+ } else if (strmatch(key, "frr-routing:ipv6-unicast")) {
+ *afi = AFI_IP6;
+ *safi = SAFI_UNICAST;
+ } else if (strmatch(key, "frr-routing:ipv4-multicast")) {
+ *afi = AFI_IP;
+ *safi = SAFI_MULTICAST;
+ } else if (strmatch(key, "frr-routing:ipv6-multicast")) {
+ *afi = AFI_IP6;
+ *safi = SAFI_MULTICAST;
+ } else if (strmatch(key, "frr-routing:l3vpn-ipv4-unicast")) {
+ *afi = AFI_IP;
+ *safi = SAFI_MPLS_VPN;
+ } else if (strmatch(key, "frr-routing:l3vpn-ipv6-unicast")) {
+ *afi = AFI_IP6;
+ *safi = SAFI_MPLS_VPN;
+ } else if (strmatch(key, "frr-routing:ipv4-labeled-unicast")) {
+ *afi = AFI_IP;
+ *safi = SAFI_LABELED_UNICAST;
+ } else if (strmatch(key, "frr-routing:ipv6-labeled-unicast")) {
+ *afi = AFI_IP6;
+ *safi = SAFI_LABELED_UNICAST;
+ } else if (strmatch(key, "frr-routing:l2vpn-evpn")) {
+ *afi = AFI_L2VPN;
+ *safi = SAFI_EVPN;
+ } else {
+ *afi = AFI_UNSPEC;
+ *safi = SAFI_UNSPEC;
+ }
+}
diff --git a/lib/yang_wrappers.h b/lib/yang_wrappers.h
index ba2cf5139c..335ff319d5 100644
--- a/lib/yang_wrappers.h
+++ b/lib/yang_wrappers.h
@@ -191,6 +191,9 @@ extern struct yang_data *yang_data_new_date_and_time(const char *xpath,
/* nexthop enum2str */
extern const char *yang_nexthop_type2str(uint32_t ntype);
+const char *yang_afi_safi_value2identity(afi_t afi, safi_t safi);
+void yang_afi_safi_identity2value(const char *key, afi_t *afi, safi_t *safi);
+
#ifdef __cplusplus
}
#endif
diff --git a/lib/zclient.c b/lib/zclient.c
index 1bb9aeed85..250d697bb4 100644
--- a/lib/zclient.c
+++ b/lib/zclient.c
@@ -902,7 +902,7 @@ static void zapi_nexthop_group_sort(struct zapi_nexthop *nh_grp,
int zapi_nexthop_encode(struct stream *s, const struct zapi_nexthop *api_nh,
uint32_t api_flags)
{
- int ret = 0;
+ int i, ret = 0;
int nh_flags = api_nh->flags;
stream_putl(s, api_nh->vrf_id);
@@ -965,8 +965,17 @@ int zapi_nexthop_encode(struct stream *s, const struct zapi_nexthop *api_nh,
sizeof(struct ethaddr));
/* Index of backup nexthop */
- if (CHECK_FLAG(nh_flags, ZAPI_NEXTHOP_FLAG_HAS_BACKUP))
- stream_putc(s, api_nh->backup_idx);
+ if (CHECK_FLAG(nh_flags, ZAPI_NEXTHOP_FLAG_HAS_BACKUP)) {
+ /* Validate backup count */
+ if (api_nh->backup_num > NEXTHOP_MAX_BACKUPS) {
+ ret = -1;
+ goto done;
+ }
+
+ stream_putc(s, api_nh->backup_num);
+ for (i = 0; i < api_nh->backup_num; i++)
+ stream_putc(s, api_nh->backup_idx[i]);
+ }
done:
return ret;
@@ -1125,7 +1134,7 @@ int zapi_route_encode(uint8_t cmd, struct stream *s, struct zapi_route *api)
static int zapi_nexthop_decode(struct stream *s, struct zapi_nexthop *api_nh,
uint32_t api_flags)
{
- int ret = -1;
+ int i, ret = -1;
STREAM_GETL(s, api_nh->vrf_id);
STREAM_GETC(s, api_nh->type);
@@ -1177,8 +1186,15 @@ static int zapi_nexthop_decode(struct stream *s, struct zapi_nexthop *api_nh,
sizeof(struct ethaddr));
/* Backup nexthop index */
- if (CHECK_FLAG(api_nh->flags, ZAPI_NEXTHOP_FLAG_HAS_BACKUP))
- STREAM_GETC(s, api_nh->backup_idx);
+ if (CHECK_FLAG(api_nh->flags, ZAPI_NEXTHOP_FLAG_HAS_BACKUP)) {
+ STREAM_GETC(s, api_nh->backup_num);
+
+ if (api_nh->backup_num > NEXTHOP_MAX_BACKUPS)
+ return -1;
+
+ for (i = 0; i < api_nh->backup_num; i++)
+ STREAM_GETC(s, api_nh->backup_idx[i]);
+ }
/* Success */
ret = 0;
@@ -1497,7 +1513,8 @@ struct nexthop *nexthop_from_zapi_nexthop(const struct zapi_nexthop *znh)
if (CHECK_FLAG(znh->flags, ZAPI_NEXTHOP_FLAG_HAS_BACKUP)) {
SET_FLAG(n->flags, NEXTHOP_FLAG_HAS_BACKUP);
- n->backup_idx = znh->backup_idx;
+ n->backup_num = znh->backup_num;
+ memcpy(n->backup_idx, znh->backup_idx, n->backup_num);
}
return n;
@@ -1533,8 +1550,12 @@ int zapi_nexthop_from_nexthop(struct zapi_nexthop *znh,
}
if (CHECK_FLAG(nh->flags, NEXTHOP_FLAG_HAS_BACKUP)) {
+ if (nh->backup_num > NEXTHOP_MAX_BACKUPS)
+ return -1;
+
SET_FLAG(znh->flags, ZAPI_NEXTHOP_FLAG_HAS_BACKUP);
- znh->backup_idx = nh->backup_idx;
+ znh->backup_num = nh->backup_num;
+ memcpy(znh->backup_idx, nh->backup_idx, znh->backup_num);
}
return 0;
@@ -3512,6 +3533,16 @@ static int zclient_read(struct thread *thread)
(*zclient->local_es_del)(command, zclient, length,
vrf_id);
break;
+ case ZEBRA_LOCAL_ES_EVI_ADD:
+ if (zclient->local_es_evi_add)
+ (*zclient->local_es_evi_add)(command, zclient, length,
+ vrf_id);
+ break;
+ case ZEBRA_LOCAL_ES_EVI_DEL:
+ if (zclient->local_es_evi_del)
+ (*zclient->local_es_evi_del)(command, zclient, length,
+ vrf_id);
+ break;
case ZEBRA_VNI_ADD:
if (zclient->local_vni_add)
(*zclient->local_vni_add)(command, zclient, length,
diff --git a/lib/zclient.h b/lib/zclient.h
index fd4afc0397..f1730f15b2 100644
--- a/lib/zclient.h
+++ b/lib/zclient.h
@@ -157,6 +157,10 @@ typedef enum {
ZEBRA_ADVERTISE_ALL_VNI,
ZEBRA_LOCAL_ES_ADD,
ZEBRA_LOCAL_ES_DEL,
+ ZEBRA_REMOTE_ES_VTEP_ADD,
+ ZEBRA_REMOTE_ES_VTEP_DEL,
+ ZEBRA_LOCAL_ES_EVI_ADD,
+ ZEBRA_LOCAL_ES_EVI_DEL,
ZEBRA_VNI_ADD,
ZEBRA_VNI_DEL,
ZEBRA_L3VNI_ADD,
@@ -321,6 +325,8 @@ struct zclient {
int (*fec_update)(int, struct zclient *, uint16_t);
int (*local_es_add)(ZAPI_CALLBACK_ARGS);
int (*local_es_del)(ZAPI_CALLBACK_ARGS);
+ int (*local_es_evi_add)(ZAPI_CALLBACK_ARGS);
+ int (*local_es_evi_del)(ZAPI_CALLBACK_ARGS);
int (*local_vni_add)(ZAPI_CALLBACK_ARGS);
int (*local_vni_del)(ZAPI_CALLBACK_ARGS);
int (*local_l3vni_add)(ZAPI_CALLBACK_ARGS);
@@ -394,8 +400,9 @@ struct zapi_nexthop {
uint32_t weight;
- /* Index of backup nexthop */
- uint8_t backup_idx;
+ /* Backup nexthops, for IP-FRR, TI-LFA, etc */
+ uint8_t backup_num;
+ uint8_t backup_idx[NEXTHOP_MAX_BACKUPS];
};
/*
@@ -600,6 +607,11 @@ zapi_rule_notify_owner2str(enum zapi_rule_notify_owner note)
#define ZEBRA_MACIP_TYPE_ROUTER_FLAG 0x04 /* Router Flag - proxy NA */
#define ZEBRA_MACIP_TYPE_OVERRIDE_FLAG 0x08 /* Override Flag */
#define ZEBRA_MACIP_TYPE_SVI_IP 0x10 /* SVI MAC-IP */
+#define ZEBRA_MACIP_TYPE_PROXY_ADVERT 0x20 /* Not locally active */
+#define ZEBRA_MACIP_TYPE_SYNC_PATH 0x40 /* sync path */
+/* XXX - flags is an u8; that needs to be changed to u32 if you need
+ * to allocate past 0x80
+ */
enum zebra_neigh_state { ZEBRA_NEIGH_INACTIVE = 0, ZEBRA_NEIGH_ACTIVE = 1 };
diff --git a/lib/zlog.c b/lib/zlog.c
index 45726755f8..8dfd20371b 100644
--- a/lib/zlog.c
+++ b/lib/zlog.c
@@ -246,10 +246,10 @@ void zlog_tls_buffer_init(void)
fchown(mmfd, zlog_uid, zlog_gid);
#ifdef HAVE_POSIX_FALLOCATE
- if (posix_fallocate(mmfd, 0, TLS_LOG_BUF_SIZE) < 0) {
-#else
- if (ftruncate(mmfd, TLS_LOG_BUF_SIZE) < 0) {
+ if (posix_fallocate(mmfd, 0, TLS_LOG_BUF_SIZE) != 0)
+ /* note next statement is under above if() */
#endif
+ if (ftruncate(mmfd, TLS_LOG_BUF_SIZE) < 0) {
zlog_err("failed to allocate thread log buffer \"%s\": %s",
mmpath, strerror(errno));
goto out_anon_unlink;
diff --git a/nhrpd/nhrp_route.c b/nhrpd/nhrp_route.c
index e4270f09a5..0c5513b892 100644
--- a/nhrpd/nhrp_route.c
+++ b/nhrpd/nhrp_route.c
@@ -198,6 +198,10 @@ int nhrp_route_read(ZAPI_CALLBACK_ARGS)
if (CHECK_FLAG(api.message, ZAPI_MESSAGE_SRCPFX))
return 0;
+ /* ignore our routes */
+ if (api.type == ZEBRA_ROUTE_NHRP)
+ return 0;
+
sockunion_family(&nexthop_addr) = AF_UNSPEC;
if (CHECK_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP)) {
api_nh = &api.nexthops[0];
diff --git a/ospf6d/ospf6_abr.c b/ospf6d/ospf6_abr.c
index 1f6cc9d527..b339790492 100644
--- a/ospf6d/ospf6_abr.c
+++ b/ospf6d/ospf6_abr.c
@@ -875,7 +875,6 @@ void ospf6_abr_examin_summary(struct ospf6_lsa *lsa, struct ospf6_area *oa)
bool old_entry_updated = false;
struct ospf6_path *path, *o_path, *ecmp_path;
struct listnode *anode;
- char adv_router[16];
memset(&prefix, 0, sizeof(prefix));
@@ -940,10 +939,6 @@ void ospf6_abr_examin_summary(struct ospf6_lsa *lsa, struct ospf6_area *oa)
if (listcount(route->paths) > 1) {
for (ALL_LIST_ELEMENTS_RO(route->paths, anode,
o_path)) {
- inet_ntop(AF_INET,
- &o_path->origin.adv_router,
- adv_router,
- sizeof(adv_router));
if (o_path->origin.id == lsa->header->id
&& o_path->origin.adv_router ==
lsa->header->adv_router) {
@@ -951,9 +946,9 @@ void ospf6_abr_examin_summary(struct ospf6_lsa *lsa, struct ospf6_area *oa)
if (is_debug)
zlog_debug(
- "%s: old entry found in paths, adv_router %s",
+ "%s: old entry found in paths, adv_router %pI4",
__func__,
- adv_router);
+ &o_path->origin.adv_router);
break;
}
@@ -1185,14 +1180,11 @@ void ospf6_abr_examin_summary(struct ospf6_lsa *lsa, struct ospf6_area *oa)
listnode_add_sort(old_route->paths, ecmp_path);
if (is_debug) {
- prefix2str(&route->prefix, buf, sizeof(buf));
- inet_ntop(AF_INET,
- &ecmp_path->origin.adv_router,
- adv_router, sizeof(adv_router));
zlog_debug(
- "%s: route %s cost %u another path %s added with nh %u, effective paths %u nh %u",
- __func__, buf, old_route->path.cost,
- adv_router,
+ "%s: route %pFX cost %u another path %pI4 added with nh %u, effective paths %u nh %u",
+ __func__, &route->prefix,
+ old_route->path.cost,
+ &ecmp_path->origin.adv_router,
listcount(ecmp_path->nh_list),
old_route->paths
? listcount(old_route->paths)
@@ -1239,12 +1231,11 @@ void ospf6_abr_examin_summary(struct ospf6_lsa *lsa, struct ospf6_area *oa)
if (old_entry_updated == false) {
if (is_debug) {
- inet_ntop(AF_INET, &route->path.origin.adv_router,
- adv_router, sizeof(adv_router));
zlog_debug(
- "%s: Install route: %s cost %u nh %u adv_router %s ",
+ "%s: Install route: %s cost %u nh %u adv_router %pI4",
__func__, buf, route->path.cost,
- listcount(route->nh_list), adv_router);
+ listcount(route->nh_list),
+ &route->path.origin.adv_router);
}
path = ospf6_path_dup(&route->path);
diff --git a/ospf6d/ospf6_area.c b/ospf6d/ospf6_area.c
index 9fe077b544..713ce26ecb 100644
--- a/ospf6d/ospf6_area.c
+++ b/ospf6d/ospf6_area.c
@@ -379,22 +379,6 @@ void ospf6_area_show(struct vty *vty, struct ospf6_area *oa)
vty_out(vty, "SPF has not been run\n");
}
-
-#define OSPF6_CMD_AREA_GET(str, oa) \
- { \
- char *ep; \
- uint32_t area_id = htonl(strtoul(str, &ep, 10)); \
- if (*ep && inet_pton(AF_INET, str, &area_id) != 1) { \
- vty_out(vty, "Malformed Area-ID: %s\n", str); \
- return CMD_SUCCESS; \
- } \
- int format = !*ep ? OSPF6_AREA_FMT_DECIMAL \
- : OSPF6_AREA_FMT_DOTTEDQUAD; \
- oa = ospf6_area_lookup(area_id, ospf6); \
- if (oa == NULL) \
- oa = ospf6_area_create(area_id, ospf6, format); \
- }
-
DEFUN (area_range,
area_range_cmd,
"area <A.B.C.D|(0-4294967295)> range X:X::X:X/M [<advertise|not-advertise|cost (0-16777215)>]",
diff --git a/ospf6d/ospf6_area.h b/ospf6d/ospf6_area.h
index 5648b1dfec..f6287660d6 100644
--- a/ospf6d/ospf6_area.h
+++ b/ospf6d/ospf6_area.h
@@ -28,7 +28,7 @@ struct ospf6_area {
struct ospf6 *ospf6;
/* Area-ID */
- uint32_t area_id;
+ in_addr_t area_id;
#define OSPF6_AREA_FMT_DOTTEDQUAD 1
#define OSPF6_AREA_FMT_DECIMAL 2
@@ -117,6 +117,21 @@ struct ospf6_area {
#define IS_AREA_TRANSIT(oa) (CHECK_FLAG ((oa)->flag, OSPF6_AREA_TRANSIT))
#define IS_AREA_STUB(oa) (CHECK_FLAG ((oa)->flag, OSPF6_AREA_STUB))
+#define OSPF6_CMD_AREA_GET(str, oa) \
+ { \
+ char *ep; \
+ uint32_t area_id = htonl(strtoul(str, &ep, 10)); \
+ if (*ep && inet_pton(AF_INET, str, &area_id) != 1) { \
+ vty_out(vty, "Malformed Area-ID: %s\n", str); \
+ return CMD_SUCCESS; \
+ } \
+ int format = !*ep ? OSPF6_AREA_FMT_DECIMAL \
+ : OSPF6_AREA_FMT_DOTTEDQUAD; \
+ oa = ospf6_area_lookup(area_id, ospf6); \
+ if (oa == NULL) \
+ oa = ospf6_area_create(area_id, ospf6, format); \
+ }
+
/* prototypes */
extern int ospf6_area_cmp(void *va, void *vb);
diff --git a/ospf6d/ospf6_asbr.c b/ospf6d/ospf6_asbr.c
index cea4dd93e5..5562529ea8 100644
--- a/ospf6d/ospf6_asbr.c
+++ b/ospf6d/ospf6_asbr.c
@@ -244,11 +244,9 @@ void ospf6_asbr_update_route_ecmp_path(struct ospf6_route *old,
continue;
if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL)) {
- prefix2str(&old_route->prefix, buf,
- sizeof(buf));
zlog_debug(
- "%s: route %s cost old %u new %u is not same, replace route",
- __func__, buf, o_path->cost,
+ "%s: route %pFX cost old %u new %u is not same, replace route",
+ __func__, &old_route->prefix, o_path->cost,
route->path.cost);
}
@@ -308,11 +306,9 @@ void ospf6_asbr_update_route_ecmp_path(struct ospf6_route *old,
}
} else {
if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL)) {
- prefix2str(&old_route->prefix, buf,
- sizeof(buf));
zlog_debug(
- "%s: route %s old cost %u new cost %u, delete old entry.",
- __func__, buf,
+ "%s: route %pFX old cost %u new cost %u, delete old entry.",
+ __func__, &old_route->prefix,
old_route->path.cost,
route->path.cost);
}
@@ -339,11 +335,10 @@ void ospf6_asbr_update_route_ecmp_path(struct ospf6_route *old,
&& (old_route->path.u.cost_e2 == route->path.u.cost_e2)) {
if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL)) {
- prefix2str(&old_route->prefix, buf,
- sizeof(buf));
zlog_debug(
- "%s: old route %s path cost %u e2 %u",
- __func__, buf, old_route->path.cost,
+ "%s: old route %pFX path cost %u e2 %u",
+ __func__, &old_route->prefix,
+ old_route->path.cost,
old_route->path.u.cost_e2);
}
route_found = true;
@@ -562,7 +557,6 @@ void ospf6_asbr_lsa_remove(struct ospf6_lsa *lsa,
struct ospf6_as_external_lsa *external;
struct prefix prefix;
struct ospf6_route *route, *nroute, *route_to_del;
- char buf[PREFIX2STR_BUFFER];
external = (struct ospf6_as_external_lsa *)OSPF6_LSA_HEADER_END(
lsa->header);
@@ -612,8 +606,7 @@ void ospf6_asbr_lsa_remove(struct ospf6_lsa *lsa,
route = ospf6_route_lookup(&prefix, ospf6->route_table);
if (route == NULL) {
if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL)) {
- prefix2str(&prefix, buf, sizeof(buf));
- zlog_debug("AS-External route %s not found", buf);
+ zlog_debug("AS-External route %pFX not found", &prefix);
}
ospf6_route_delete(route_to_del);
@@ -621,10 +614,9 @@ void ospf6_asbr_lsa_remove(struct ospf6_lsa *lsa,
}
if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL)) {
- prefix2str(&prefix, buf, sizeof(buf));
zlog_debug(
- "%s: Current route %s cost %u e2 %u, route to del cost %u e2 %u",
- __func__, buf, route->path.cost, route->path.u.cost_e2,
+ "%s: Current route %pFX cost %u e2 %u, route to del cost %u e2 %u",
+ __func__, &prefix, route->path.cost, route->path.u.cost_e2,
route_to_del->path.cost, route_to_del->path.u.cost_e2);
}
@@ -668,11 +660,9 @@ void ospf6_asbr_lsa_remove(struct ospf6_lsa *lsa,
.cost_e2)) {
if (IS_OSPF6_DEBUG_EXAMIN(
AS_EXTERNAL)) {
- prefix2str(&prefix, buf,
- sizeof(buf));
zlog_debug(
- "%s: route %s to delete is not same, cost %u del cost %u. skip",
- __func__, buf,
+ "%s: route %pFX to delete is not same, cost %u del cost %u. skip",
+ __func__, &prefix,
route->path.cost,
route_to_del->path
.cost);
@@ -681,10 +671,9 @@ void ospf6_asbr_lsa_remove(struct ospf6_lsa *lsa,
}
if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL)) {
- prefix2str(&prefix, buf, sizeof(buf));
zlog_debug(
- "%s: route %s path found with cost %u nh %u to remove.",
- __func__, buf, route->path.cost,
+ "%s: route %pFX path found with cost %u nh %u to remove.",
+ __func__, &prefix, route->path.cost,
listcount(o_path->nh_list));
}
@@ -723,16 +712,14 @@ void ospf6_asbr_lsa_remove(struct ospf6_lsa *lsa,
}
if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL)) {
- prefix2str(&route->prefix, buf,
- sizeof(buf));
zlog_debug(
- "%s: AS-External %u route %s update paths %u nh %u",
+ "%s: AS-External %u route %pFX update paths %u nh %u",
__func__,
(route->path.type
== OSPF6_PATH_TYPE_EXTERNAL1)
? 1
: 2,
- buf, listcount(route->paths),
+ &route->prefix, listcount(route->paths),
route->nh_list ? listcount(
route->nh_list)
: 0);
@@ -784,10 +771,9 @@ void ospf6_asbr_lsa_remove(struct ospf6_lsa *lsa,
|| (route->path.u.cost_e2
!= route_to_del->path.u.cost_e2))) {
if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL)) {
- prefix2str(&prefix, buf, sizeof(buf));
zlog_debug(
- "%s: route %s to delete is not same, cost %u del cost %u. skip",
- __func__, buf, route->path.cost,
+ "%s: route %pFX to delete is not same, cost %u del cost %u. skip",
+ __func__, &prefix, route->path.cost,
route_to_del->path.cost);
}
continue;
@@ -800,14 +786,13 @@ void ospf6_asbr_lsa_remove(struct ospf6_lsa *lsa,
continue;
}
if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL)) {
- prefix2str(&route->prefix, buf, sizeof(buf));
zlog_debug(
- "%s: AS-External %u route remove %s cost %u(%u) nh %u",
+ "%s: AS-External %u route remove %pFX cost %u(%u) nh %u",
__func__,
route->path.type == OSPF6_PATH_TYPE_EXTERNAL1
? 1
: 2,
- buf, route->path.cost, route->path.u.cost_e2,
+ &route->prefix, route->path.cost, route->path.u.cost_e2,
listcount(route->nh_list));
}
ospf6_route_remove(route, ospf6->route_table);
diff --git a/ospf6d/ospf6_bfd.c b/ospf6d/ospf6_bfd.c
index 4e7a0050aa..916e59baf0 100644
--- a/ospf6d/ospf6_bfd.c
+++ b/ospf6d/ospf6_bfd.c
@@ -308,7 +308,7 @@ static void ospf6_bfd_if_param_set(struct ospf6_interface *oi, uint32_t min_rx,
int command = 0;
bfd_set_param((struct bfd_info **)&(oi->bfd_info), min_rx, min_tx,
- detect_mult, defaults, &command);
+ detect_mult, NULL, defaults, &command);
if (command)
ospf6_bfd_reg_dereg_all_nbr(oi, command);
}
diff --git a/ospf6d/ospf6_interface.h b/ospf6d/ospf6_interface.h
index 05ba698a1b..6cbfe04c44 100644
--- a/ospf6d/ospf6_interface.h
+++ b/ospf6d/ospf6_interface.h
@@ -90,10 +90,10 @@ struct ospf6_interface {
uint8_t mtu_ignore;
/* Decision of DR Election */
- uint32_t drouter;
- uint32_t bdrouter;
- uint32_t prev_drouter;
- uint32_t prev_bdrouter;
+ in_addr_t drouter;
+ in_addr_t bdrouter;
+ in_addr_t prev_drouter;
+ in_addr_t prev_bdrouter;
/* Linklocal LSA Database: includes Link-LSA */
struct ospf6_lsdb *lsdb;
diff --git a/ospf6d/ospf6_intra.c b/ospf6d/ospf6_intra.c
index b700899ccf..ef5d1d0583 100644
--- a/ospf6d/ospf6_intra.c
+++ b/ospf6d/ospf6_intra.c
@@ -1400,11 +1400,9 @@ void ospf6_intra_prefix_route_ecmp_path(struct ospf6_area *oa,
continue;
if (IS_OSPF6_DEBUG_EXAMIN(INTRA_PREFIX)) {
- prefix2str(&old_route->prefix, buf,
- sizeof(buf));
zlog_debug(
- "%s: route %s cost old %u new %u is not same, replace route",
- __func__, buf, o_path->cost,
+ "%s: route %pFX cost old %u new %u is not same, replace route",
+ __func__, &old_route->prefix, o_path->cost,
route->path.cost);
}
@@ -1458,11 +1456,9 @@ void ospf6_intra_prefix_route_ecmp_path(struct ospf6_area *oa,
}
} else {
if (IS_OSPF6_DEBUG_EXAMIN(INTRA_PREFIX)) {
- prefix2str(&old_route->prefix, buf,
- sizeof(buf));
zlog_debug(
- "%s: route %s old cost %u new cost %u, delete old entry.",
- __func__, buf,
+ "%s: route %pFX old cost %u new cost %u, delete old entry.",
+ __func__, &old_route->prefix,
old_route->path.cost,
route->path.cost);
}
@@ -1515,11 +1511,9 @@ void ospf6_intra_prefix_route_ecmp_path(struct ospf6_area *oa,
listnode_add_sort(old_route->paths, ecmp_path);
if (IS_OSPF6_DEBUG_EXAMIN(INTRA_PREFIX)) {
- prefix2str(&route->prefix, buf,
- sizeof(buf));
zlog_debug(
- "%s: route %s %p another path added with nh %u, effective paths %u nh %u",
- __func__, buf,
+ "%s: route %pFX %p another path added with nh %u, effective paths %u nh %u",
+ __func__, &route->prefix,
(void *)old_route,
listcount(ecmp_path->nh_list),
old_route->paths ? listcount(
diff --git a/ospf6d/ospf6_intra.h b/ospf6d/ospf6_intra.h
index 672e288bf3..9c29681dee 100644
--- a/ospf6d/ospf6_intra.h
+++ b/ospf6d/ospf6_intra.h
@@ -23,8 +23,8 @@
/* Debug option */
extern unsigned char conf_debug_ospf6_brouter;
-extern uint32_t conf_debug_ospf6_brouter_specific_router_id;
-extern uint32_t conf_debug_ospf6_brouter_specific_area_id;
+extern in_addr_t conf_debug_ospf6_brouter_specific_router_id;
+extern in_addr_t conf_debug_ospf6_brouter_specific_area_id;
#define OSPF6_DEBUG_BROUTER_SUMMARY 0x01
#define OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER 0x02
#define OSPF6_DEBUG_BROUTER_SPECIFIC_AREA 0x04
@@ -86,7 +86,7 @@ struct ospf6_router_lsdesc {
uint16_t metric; /* output cost */
uint32_t interface_id;
uint32_t neighbor_interface_id;
- uint32_t neighbor_router_id;
+ in_addr_t neighbor_router_id;
};
#define OSPF6_ROUTER_LSDESC_POINTTOPOINT 1
@@ -125,7 +125,7 @@ struct ospf6_network_lsa {
/* Link State Description in Router-LSA */
#define OSPF6_NETWORK_LSDESC_FIX_SIZE 4U
struct ospf6_network_lsdesc {
- uint32_t router_id;
+ in_addr_t router_id;
};
#define NETWORK_LSDESC_GET_NBR_ROUTERID(x) \
(((struct ospf6_network_lsdesc *)(x))->router_id)
@@ -146,7 +146,7 @@ struct ospf6_intra_prefix_lsa {
uint16_t prefix_num;
uint16_t ref_type;
uint32_t ref_id;
- uint32_t ref_adv_router;
+ in_addr_t ref_adv_router;
/* followed by ospf6 prefix(es) */
};
diff --git a/ospf6d/ospf6_lsa.h b/ospf6d/ospf6_lsa.h
index 5519dd1b80..a85d7b0603 100644
--- a/ospf6d/ospf6_lsa.h
+++ b/ospf6d/ospf6_lsa.h
@@ -80,8 +80,8 @@
struct ospf6_lsa_header {
uint16_t age; /* LS age */
uint16_t type; /* LS type */
- uint32_t id; /* Link State ID */
- uint32_t adv_router; /* Advertising Router */
+ in_addr_t id; /* Link State ID */
+ in_addr_t adv_router; /* Advertising Router */
uint32_t seqnum; /* LS sequence number */
uint16_t checksum; /* LS checksum */
uint16_t length; /* LSA length */
diff --git a/ospf6d/ospf6_message.h b/ospf6d/ospf6_message.h
index d24b7f8942..7ec8cb785f 100644
--- a/ospf6d/ospf6_message.h
+++ b/ospf6d/ospf6_message.h
@@ -49,8 +49,8 @@ struct ospf6_header {
uint8_t version;
uint8_t type;
uint16_t length;
- uint32_t router_id;
- uint32_t area_id;
+ in_addr_t router_id;
+ in_addr_t area_id;
uint16_t checksum;
uint8_t instance_id;
uint8_t reserved;
@@ -66,8 +66,8 @@ struct ospf6_hello {
uint8_t options[3];
uint16_t hello_interval;
uint16_t dead_interval;
- uint32_t drouter;
- uint32_t bdrouter;
+ in_addr_t drouter;
+ in_addr_t bdrouter;
/* Followed by Router-IDs */
};
@@ -94,8 +94,8 @@ struct ospf6_dbdesc {
struct ospf6_lsreq_entry {
uint16_t reserved; /* Must Be Zero */
uint16_t type; /* LS type */
- uint32_t id; /* Link State ID */
- uint32_t adv_router; /* Advertising Router */
+ in_addr_t id; /* Link State ID */
+ in_addr_t adv_router; /* Advertising Router */
};
/* Link State Update */
diff --git a/ospf6d/ospf6_neighbor.h b/ospf6d/ospf6_neighbor.h
index e221e9d82c..1a45a1966a 100644
--- a/ospf6d/ospf6_neighbor.h
+++ b/ospf6d/ospf6_neighbor.h
@@ -48,7 +48,7 @@ struct ospf6_neighbor {
struct timeval last_changed;
/* Neighbor Router ID */
- uint32_t router_id;
+ in_addr_t router_id;
/* Neighbor Interface ID */
ifindex_t ifindex;
@@ -56,10 +56,10 @@ struct ospf6_neighbor {
/* Router Priority of this neighbor */
uint8_t priority;
- uint32_t drouter;
- uint32_t bdrouter;
- uint32_t prev_drouter;
- uint32_t prev_bdrouter;
+ in_addr_t drouter;
+ in_addr_t bdrouter;
+ in_addr_t prev_drouter;
+ in_addr_t prev_bdrouter;
/* Options field (Capability) */
char options[3];
diff --git a/ospf6d/ospf6_route.h b/ospf6d/ospf6_route.h
index 13b01a3487..95ba983e6b 100644
--- a/ospf6d/ospf6_route.h
+++ b/ospf6d/ospf6_route.h
@@ -64,8 +64,8 @@ struct ospf6_nexthop {
/* Path */
struct ospf6_ls_origin {
uint16_t type;
- uint32_t id;
- uint32_t adv_router;
+ in_addr_t id;
+ in_addr_t adv_router;
};
struct ospf6_path {
@@ -82,7 +82,7 @@ struct ospf6_path {
uint8_t prefix_options;
/* Associated Area */
- uint32_t area_id;
+ in_addr_t area_id;
/* Path-type */
uint8_t type;
diff --git a/ospf6d/ospf6_top.c b/ospf6d/ospf6_top.c
index a36012194d..50687a7290 100644
--- a/ospf6d/ospf6_top.c
+++ b/ospf6d/ospf6_top.c
@@ -642,11 +642,12 @@ DEFUN (no_ospf6_distance_source,
DEFUN (ospf6_interface_area,
ospf6_interface_area_cmd,
- "interface IFNAME area A.B.C.D",
+ "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, o);
@@ -655,7 +656,6 @@ DEFUN (ospf6_interface_area,
struct ospf6_area *oa;
struct ospf6_interface *oi;
struct interface *ifp;
- uint32_t area_id;
/* find/create ospf6 interface */
ifp = if_get_by_name(argv[idx_ifname]->arg, VRF_DEFAULT);
@@ -669,15 +669,7 @@ DEFUN (ospf6_interface_area,
}
/* parse Area-ID */
- if (inet_pton(AF_INET, argv[idx_ipv4]->arg, &area_id) != 1) {
- vty_out(vty, "Invalid Area-ID: %s\n", argv[idx_ipv4]->arg);
- return CMD_SUCCESS;
- }
-
- /* find/create ospf6 area */
- oa = ospf6_area_lookup(area_id, o);
- if (oa == NULL)
- oa = ospf6_area_create(area_id, o, OSPF6_AREA_FMT_DOTTEDQUAD);
+ OSPF6_CMD_AREA_GET(argv[idx_ipv4]->arg, oa);
/* attach interface to area */
listnode_add(oa->if_list, oi); /* sort ?? */
@@ -701,12 +693,13 @@ DEFUN (ospf6_interface_area,
DEFUN (no_ospf6_interface_area,
no_ospf6_interface_area_cmd,
- "no interface IFNAME area A.B.C.D",
+ "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"
)
{
int idx_ifname = 2;
@@ -729,10 +722,8 @@ DEFUN (no_ospf6_interface_area,
}
/* parse Area-ID */
- if (inet_pton(AF_INET, argv[idx_ipv4]->arg, &area_id) != 1) {
- vty_out(vty, "Invalid Area-ID: %s\n", argv[idx_ipv4]->arg);
- return CMD_SUCCESS;
- }
+ 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) {
diff --git a/ospf6d/ospf6_top.h b/ospf6d/ospf6_top.h
index 18c0697025..806b4da1cf 100644
--- a/ospf6d/ospf6_top.h
+++ b/ospf6d/ospf6_top.h
@@ -26,7 +26,7 @@
struct ospf6_master {
- uint32_t zebra_router_id;
+ in_addr_t zebra_router_id;
};
/* ospf6->config_flags */
@@ -41,10 +41,10 @@ struct ospf6 {
vrf_id_t vrf_id;
/* my router id */
- uint32_t router_id;
+ in_addr_t router_id;
/* static router id */
- uint32_t router_id_static;
+ in_addr_t router_id_static;
struct in_addr router_id_zebra;
diff --git a/ospfd/ospf_bfd.c b/ospfd/ospf_bfd.c
index b9e78f4cd3..d2c5090f2f 100644
--- a/ospfd/ospf_bfd.c
+++ b/ospfd/ospf_bfd.c
@@ -381,7 +381,7 @@ static void ospf_bfd_if_param_set(struct interface *ifp, uint32_t min_rx,
params = IF_DEF_PARAMS(ifp);
bfd_set_param((struct bfd_info **)&(params->bfd_info), min_rx, min_tx,
- detect_mult, defaults, &command);
+ detect_mult, NULL, defaults, &command);
if (command)
ospf_bfd_reg_dereg_all_nbr(ifp, command);
}
diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c
index 08736b555f..e8cc50c8d0 100644
--- a/ospfd/ospf_vty.c
+++ b/ospfd/ospf_vty.c
@@ -1177,9 +1177,9 @@ DEFUN (no_ospf_area_vlink,
"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_STR
VLINK_HELPSTR_IPADDR
- "Enable authentication on this virtual link\n" \
- "Use message-digest authentication\n" \
- "Use null authentication\n" \
+ "Enable authentication on this virtual link\n"
+ "Use message-digest authentication\n"
+ "Use null authentication\n"
VLINK_HELPSTR_AUTH_MD5
VLINK_HELPSTR_AUTH_SIMPLE)
{
diff --git a/ospfd/ospf_zebra.c b/ospfd/ospf_zebra.c
index e04eb539d8..84bdb9ec5b 100644
--- a/ospfd/ospf_zebra.c
+++ b/ospfd/ospf_zebra.c
@@ -276,7 +276,7 @@ void ospf_zebra_add(struct ospf *ospf, struct prefix_ipv4 *p,
count++;
if (IS_DEBUG_OSPF(zebra, ZEBRA_REDISTRIBUTE)) {
- char buf[2][INET_ADDRSTRLEN];
+ char buf[2][PREFIX2STR_BUFFER];
struct interface *ifp;
ifp = if_lookup_by_index(path->ifindex, ospf->vrf_id);
diff --git a/pbrd/pbr_map.c b/pbrd/pbr_map.c
index edc3f1d8da..10a75a9f54 100644
--- a/pbrd/pbr_map.c
+++ b/pbrd/pbr_map.c
@@ -444,6 +444,59 @@ static void pbr_map_add_interfaces(struct pbr_map *pbrm)
}
}
+/* Decodes a standardized DSCP into its representative value */
+uint8_t pbr_map_decode_dscp_enum(const char *name)
+{
+ /* Standard Differentiated Services Field Codepoints */
+ if (!strcmp(name, "cs0"))
+ return 0;
+ if (!strcmp(name, "cs1"))
+ return 8;
+ if (!strcmp(name, "cs2"))
+ return 16;
+ if (!strcmp(name, "cs3"))
+ return 24;
+ if (!strcmp(name, "cs4"))
+ return 32;
+ if (!strcmp(name, "cs5"))
+ return 40;
+ if (!strcmp(name, "cs6"))
+ return 48;
+ if (!strcmp(name, "cs7"))
+ return 56;
+ if (!strcmp(name, "af11"))
+ return 10;
+ if (!strcmp(name, "af12"))
+ return 12;
+ if (!strcmp(name, "af13"))
+ return 14;
+ if (!strcmp(name, "af21"))
+ return 18;
+ if (!strcmp(name, "af22"))
+ return 20;
+ if (!strcmp(name, "af23"))
+ return 22;
+ if (!strcmp(name, "af31"))
+ return 26;
+ if (!strcmp(name, "af32"))
+ return 28;
+ if (!strcmp(name, "af33"))
+ return 30;
+ if (!strcmp(name, "af41"))
+ return 34;
+ if (!strcmp(name, "af42"))
+ return 36;
+ if (!strcmp(name, "af43"))
+ return 38;
+ if (!strcmp(name, "ef"))
+ return 46;
+ if (!strcmp(name, "voice-admit"))
+ return 44;
+
+ /* No match? Error out */
+ return -1;
+}
+
struct pbr_map_sequence *pbrms_get(const char *name, uint32_t seqno)
{
struct pbr_map *pbrm;
@@ -547,7 +600,7 @@ 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)
+ if (!pbrms->src && !pbrms->dst && !pbrms->mark && !pbrms->dsfield)
pbrms->reason |= PBR_MAP_INVALID_EMPTY;
}
@@ -603,7 +656,7 @@ bool pbr_map_check_valid(const char *name)
return pbrm->valid;
}
-void pbr_map_schedule_policy_from_nhg(const char *nh_group)
+void pbr_map_schedule_policy_from_nhg(const char *nh_group, bool installed)
{
struct pbr_map_sequence *pbrms;
struct pbr_map *pbrm;
@@ -618,7 +671,7 @@ void pbr_map_schedule_policy_from_nhg(const char *nh_group)
if (pbrms->nhgrp_name
&& (strcmp(nh_group, pbrms->nhgrp_name) == 0)) {
- pbrms->nhs_installed = true;
+ pbrms->nhs_installed = installed;
pbr_map_check(pbrms, false);
}
@@ -626,7 +679,7 @@ void pbr_map_schedule_policy_from_nhg(const char *nh_group)
if (pbrms->nhg
&& (strcmp(nh_group, pbrms->internal_nhg_name)
== 0)) {
- pbrms->nhs_installed = true;
+ pbrms->nhs_installed = installed;
pbr_map_check(pbrms, false);
}
diff --git a/pbrd/pbr_map.h b/pbrd/pbr_map.h
index 41f1703954..64c090d2e8 100644
--- a/pbrd/pbr_map.h
+++ b/pbrd/pbr_map.h
@@ -89,6 +89,7 @@ struct pbr_map_sequence {
*/
struct prefix *src;
struct prefix *dst;
+ uint8_t dsfield;
uint32_t mark;
/*
@@ -168,6 +169,8 @@ extern void pbr_map_add_interface(struct pbr_map *pbrm, struct interface *ifp);
extern void pbr_map_interface_delete(struct pbr_map *pbrm,
struct interface *ifp);
+extern uint8_t pbr_map_decode_dscp_enum(const char *name);
+
/* Update maps installed on interface */
extern void pbr_map_policy_interface_update(const struct interface *ifp,
bool state_up);
@@ -194,7 +197,8 @@ extern void pbr_map_check(struct pbr_map_sequence *pbrms, bool changed);
extern void pbr_map_check_nh_group_change(const char *nh_group);
extern void pbr_map_reason_string(unsigned int reason, char *buf, int size);
-extern void pbr_map_schedule_policy_from_nhg(const char *nh_group);
+extern void pbr_map_schedule_policy_from_nhg(const char *nh_group,
+ bool installed);
extern void pbr_map_install(struct pbr_map *pbrm);
diff --git a/pbrd/pbr_nht.c b/pbrd/pbr_nht.c
index 98be958fce..31da656793 100644
--- a/pbrd/pbr_nht.c
+++ b/pbrd/pbr_nht.c
@@ -328,27 +328,29 @@ static struct pbr_nexthop_cache *pbr_nht_lookup_nexthop(struct nexthop *nexthop)
}
#endif
+static void
+pbr_nht_find_nhg_from_table_update(struct pbr_nexthop_group_cache *pnhgc,
+ uint32_t table_id, bool installed)
+{
+ if (pnhgc->table_id == table_id) {
+ DEBUGD(&pbr_dbg_nht, "%s: %s: Table ID (%u) matches %s",
+ __func__, (installed ? "install" : "remove"), table_id,
+ pnhgc->name);
+
+ pnhgc->installed = installed;
+ pnhgc->valid = installed;
+ pbr_map_schedule_policy_from_nhg(pnhgc->name, pnhgc->installed);
+ }
+}
+
static void pbr_nht_find_nhg_from_table_install(struct hash_bucket *b,
void *data)
{
struct pbr_nexthop_group_cache *pnhgc =
(struct pbr_nexthop_group_cache *)b->data;
- uint32_t *table_id = (uint32_t *)data;
-
- if (pnhgc->table_id == *table_id) {
- DEBUGD(&pbr_dbg_nht, "%s: Table ID (%u) matches %s", __func__,
- *table_id, pnhgc->name);
+ uint32_t table_id = *(uint32_t *)data;
- /*
- * If the table has been re-handled by zebra
- * and we are already installed no need to do
- * anything here.
- */
- if (!pnhgc->installed) {
- pnhgc->installed = true;
- pbr_map_schedule_policy_from_nhg(pnhgc->name);
- }
- }
+ pbr_nht_find_nhg_from_table_update(pnhgc, table_id, true);
}
void pbr_nht_route_installed_for_table(uint32_t table_id)
@@ -360,7 +362,11 @@ void pbr_nht_route_installed_for_table(uint32_t table_id)
static void pbr_nht_find_nhg_from_table_remove(struct hash_bucket *b,
void *data)
{
- ;
+ struct pbr_nexthop_group_cache *pnhgc =
+ (struct pbr_nexthop_group_cache *)b->data;
+ uint32_t table_id = *(uint32_t *)data;
+
+ pbr_nht_find_nhg_from_table_update(pnhgc, table_id, false);
}
void pbr_nht_route_removed_for_table(uint32_t table_id)
@@ -852,12 +858,15 @@ static void pbr_nht_nexthop_update_lookup(struct hash_bucket *b, void *data)
*/
pnhgc->valid = !!pnhi.valid;
- if (pnhgc->valid) {
- pbr_nexthop_group_cache_to_nexthop_group(&nhg, pnhgc);
+ pbr_nexthop_group_cache_to_nexthop_group(&nhg, pnhgc);
+
+ if (pnhgc->valid)
pbr_nht_install_nexthop_group(pnhgc, nhg);
- /* Don't need copied nexthops anymore */
- nexthops_free(nhg.nexthop);
- }
+ else
+ pbr_nht_uninstall_nexthop_group(pnhgc, nhg, 0);
+
+ /* Don't need copied nexthops anymore */
+ nexthops_free(nhg.nexthop);
if (old_valid != pnhgc->valid)
pbr_map_check_nh_group_change(pnhgc->name);
diff --git a/pbrd/pbr_vty.c b/pbrd/pbr_vty.c
index cd9096cbc8..a73d885ea6 100644
--- a/pbrd/pbr_vty.c
+++ b/pbrd/pbr_vty.c
@@ -183,6 +183,91 @@ DEFPY(pbr_map_match_dst, pbr_map_match_dst_cmd,
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")
+{
+ struct pbr_map_sequence *pbrms = VTY_GET_CONTEXT(pbr_map_sequence);
+ char dscpname[100];
+ uint8_t rawDscp;
+
+ /* 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;
+
+ /* Lowercase the dscp enum (if needed) */
+ if (isupper(dscp[i]))
+ dscpname[i] = tolower(dscp[i]);
+ else
+ dscpname[i] = dscp[i];
+ }
+ dscpname[strlen(dscp)] = '\0';
+
+ if (isANumber) {
+ /* dscp passed is a regular number */
+ long dscpAsNum = strtol(dscp, NULL, 0);
+
+ 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 (!no) {
+ if (((pbrms->dsfield & PBR_DSFIELD_DSCP) >> 2) == rawDscp)
+ return CMD_SUCCESS;
+
+ /* Set the DSCP bits of the DSField */
+ pbrms->dsfield =
+ (pbrms->dsfield & ~PBR_DSFIELD_DSCP) | (rawDscp << 2);
+ } else {
+ pbrms->dsfield &= ~PBR_DSFIELD_DSCP;
+ }
+
+ 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")
+{
+ struct pbr_map_sequence *pbrms = VTY_GET_CONTEXT(pbr_map_sequence);
+
+ if (!no) {
+ if ((pbrms->dsfield & PBR_DSFIELD_ECN) == ecn)
+ return CMD_SUCCESS;
+
+ /* Set the ECN bits of the DSField */
+ pbrms->dsfield = (pbrms->dsfield & ~PBR_DSFIELD_ECN) | ecn;
+ } else {
+ pbrms->dsfield &= ~PBR_DSFIELD_ECN;
+ }
+
+ pbr_map_check(pbrms, true);
+
+ return CMD_SUCCESS;
+}
+
DEFPY(pbr_map_match_mark, pbr_map_match_mark_cmd,
"[no] match mark (1-4294967295)$mark",
NO_STR
@@ -559,6 +644,12 @@ static void vty_show_pbrms(struct vty *vty,
if (pbrms->dst)
vty_out(vty, " DST Match: %s\n",
prefix2str(pbrms->dst, buf, sizeof(buf)));
+ if (pbrms->dsfield & PBR_DSFIELD_DSCP)
+ vty_out(vty, " DSCP Match: %u\n",
+ (pbrms->dsfield & PBR_DSFIELD_DSCP) >> 2);
+ if (pbrms->dsfield & PBR_DSFIELD_ECN)
+ vty_out(vty, " ECN Match: %u\n",
+ pbrms->dsfield & PBR_DSFIELD_ECN);
if (pbrms->mark)
vty_out(vty, " MARK Match: %u\n", pbrms->mark);
@@ -653,6 +744,12 @@ static void vty_json_pbrms(json_object *j, struct vty *vty,
prefix2str(pbrms->dst, buf, sizeof(buf)));
if (pbrms->mark)
json_object_int_add(jpbrm, "matchMark", pbrms->mark);
+ if (pbrms->dsfield & PBR_DSFIELD_DSCP)
+ json_object_int_add(jpbrm, "matchDscp",
+ (pbrms->dsfield & PBR_DSFIELD_DSCP) >> 2);
+ if (pbrms->dsfield & PBR_DSFIELD_ECN)
+ json_object_int_add(jpbrm, "matchEcn",
+ pbrms->dsfield & PBR_DSFIELD_ECN);
json_object_array_add(j, jpbrm);
}
@@ -946,6 +1043,14 @@ static int pbr_vty_map_config_write_sequence(struct vty *vty,
vty_out(vty, " match dst-ip %s\n",
prefix2str(pbrms->dst, buff, sizeof(buff)));
+ if (pbrms->dsfield & PBR_DSFIELD_DSCP)
+ vty_out(vty, " match dscp %u\n",
+ (pbrms->dsfield & PBR_DSFIELD_DSCP) >> 2);
+
+ if (pbrms->dsfield & PBR_DSFIELD_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);
@@ -1026,6 +1131,8 @@ void pbr_vty_init(void)
install_element(INTERFACE_NODE, &pbr_policy_cmd);
install_element(PBRMAP_NODE, &pbr_map_match_src_cmd);
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_mark_cmd);
install_element(PBRMAP_NODE, &pbr_map_nexthop_group_cmd);
install_element(PBRMAP_NODE, &no_pbr_map_nexthop_group_cmd);
diff --git a/pbrd/pbr_zebra.c b/pbrd/pbr_zebra.c
index de2a99e269..d0099a46e3 100644
--- a/pbrd/pbr_zebra.c
+++ b/pbrd/pbr_zebra.c
@@ -536,6 +536,7 @@ static void pbr_encode_pbr_map_sequence(struct stream *s,
stream_putw(s, 0); /* src port */
pbr_encode_pbr_map_sequence_prefix(s, pbrms->dst, family);
stream_putw(s, 0); /* dst port */
+ stream_putc(s, pbrms->dsfield);
stream_putl(s, pbrms->mark);
if (pbrms->vrf_unchanged || pbrms->vrf_lookup)
diff --git a/pimd/pim_bfd.c b/pimd/pim_bfd.c
index 0df8ea6922..146b53fa8f 100644
--- a/pimd/pim_bfd.c
+++ b/pimd/pim_bfd.c
@@ -194,7 +194,7 @@ void pim_bfd_if_param_set(struct interface *ifp, uint32_t min_rx,
if (!pim_ifp)
return;
- bfd_set_param(&(pim_ifp->bfd_info), min_rx, min_tx, detect_mult,
+ bfd_set_param(&(pim_ifp->bfd_info), min_rx, min_tx, detect_mult, NULL,
defaults, &command);
if (pim_ifp->bfd_info) {
diff --git a/pimd/pim_cmd.c b/pimd/pim_cmd.c
index 6ede015a0e..db3f0b8b23 100644
--- a/pimd/pim_cmd.c
+++ b/pimd/pim_cmd.c
@@ -6784,12 +6784,13 @@ static int pim_rp_cmd_worker(struct pim_instance *pim, struct vty *vty,
if (result == PIM_GROUP_BAD_ADDR_MASK_COMBO) {
vty_out(vty, "%% Inconsistent address and mask: %s\n",
- group);
+ group ? group : "No Group Address");
return CMD_WARNING_CONFIG_FAILED;
}
if (result == PIM_GROUP_BAD_ADDRESS) {
- vty_out(vty, "%% Bad group address specified: %s\n", group);
+ vty_out(vty, "%% Bad group address specified: %s\n",
+ group ? group : "No Group Address");
return CMD_WARNING_CONFIG_FAILED;
}
@@ -7158,7 +7159,8 @@ static int pim_no_rp_cmd_worker(struct pim_instance *pim, struct vty *vty,
int result = pim_rp_del_config(pim, rp, group, plist);
if (result == PIM_GROUP_BAD_ADDRESS) {
- vty_out(vty, "%% Bad group address specified: %s\n", group);
+ vty_out(vty, "%% Bad group address specified: %s\n",
+ group ? group : "No Group Address");
return CMD_WARNING_CONFIG_FAILED;
}
diff --git a/pimd/pim_rpf.c b/pimd/pim_rpf.c
index f971520c86..043ccdb848 100644
--- a/pimd/pim_rpf.c
+++ b/pimd/pim_rpf.c
@@ -346,6 +346,7 @@ void pim_upstream_rpf_clear(struct pim_instance *pim,
struct pim_upstream *up)
{
if (up->rpf.source_nexthop.interface) {
+ pim_upstream_switch(pim, up, PIM_UPSTREAM_NOTJOINED);
up->rpf.source_nexthop.interface = NULL;
up->rpf.source_nexthop.mrib_nexthop_addr.u.prefix4.s_addr =
PIM_NET_INADDR_ANY;
diff --git a/pimd/subdir.am b/pimd/subdir.am
index 121abea598..8540651544 100644
--- a/pimd/subdir.am
+++ b/pimd/subdir.am
@@ -127,6 +127,12 @@ clippy_scan += \
pimd/pim_cmd.c \
# end
+nodist_pimd_pimd_SOURCES = \
+ yang/frr-igmp.yang.c \
+ yang/frr-pim.yang.c \
+ yang/frr-pim-rp.yang.c \
+ # end
+
pimd_pimd_LDADD = pimd/libpim.a lib/libfrr.la $(LIBCAP)
pimd_pimd_SOURCES = pimd/pim_main.c
diff --git a/python/makefile.py b/python/makefile.py
index 948d3f7391..fe20945ccc 100644
--- a/python/makefile.py
+++ b/python/makefile.py
@@ -73,11 +73,18 @@ while lines:
out_lines.append(line)
continue
- m = make_rule_re.match(line)
+ full_line = line
+ full_lines = lines[:]
+ while full_line.endswith('\\'):
+ full_line = full_line[:-1] + full_lines.pop(0)
+
+ m = make_rule_re.match(full_line)
if m is None:
out_lines.append(line)
continue
+ line, lines = full_line, full_lines
+
target, dep = m.group(1), m.group(2)
if target.endswith('.lo') or target.endswith('.o'):
diff --git a/ripd/rip_cli.c b/ripd/rip_cli.c
index 7e2394f473..5e64b7afdb 100644
--- a/ripd/rip_cli.c
+++ b/ripd/rip_cli.c
@@ -37,7 +37,7 @@
/*
* XPath: /frr-ripd:ripd/instance
*/
-DEFPY_NOSH (router_rip,
+DEFPY_YANG_NOSH (router_rip,
router_rip_cmd,
"router rip [vrf NAME]",
"Enable a routing process\n"
@@ -62,7 +62,7 @@ DEFPY_NOSH (router_rip,
return ret;
}
-DEFPY (no_router_rip,
+DEFPY_YANG (no_router_rip,
no_router_rip_cmd,
"no router rip [vrf NAME]",
NO_STR
@@ -100,7 +100,7 @@ void cli_show_router_rip(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-ripd:ripd/instance/allow-ecmp
*/
-DEFPY (rip_allow_ecmp,
+DEFPY_YANG (rip_allow_ecmp,
rip_allow_ecmp_cmd,
"[no] allow-ecmp",
NO_STR
@@ -124,7 +124,7 @@ void cli_show_rip_allow_ecmp(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-ripd:ripd/instance/default-information-originate
*/
-DEFPY (rip_default_information_originate,
+DEFPY_YANG (rip_default_information_originate,
rip_default_information_originate_cmd,
"[no] default-information originate",
NO_STR
@@ -150,7 +150,7 @@ void cli_show_rip_default_information_originate(struct vty *vty,
/*
* XPath: /frr-ripd:ripd/instance/default-metric
*/
-DEFPY (rip_default_metric,
+DEFPY_YANG (rip_default_metric,
rip_default_metric_cmd,
"default-metric (1-16)",
"Set a metric of redistribute routes\n"
@@ -162,7 +162,7 @@ DEFPY (rip_default_metric,
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY (no_rip_default_metric,
+DEFPY_YANG (no_rip_default_metric,
no_rip_default_metric_cmd,
"no default-metric [(1-16)]",
NO_STR
@@ -184,7 +184,7 @@ void cli_show_rip_default_metric(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-ripd:ripd/instance/distance/default
*/
-DEFPY (rip_distance,
+DEFPY_YANG (rip_distance,
rip_distance_cmd,
"distance (1-255)",
"Administrative distance\n"
@@ -196,7 +196,7 @@ DEFPY (rip_distance,
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY (no_rip_distance,
+DEFPY_YANG (no_rip_distance,
no_rip_distance_cmd,
"no distance [(1-255)]",
NO_STR
@@ -221,7 +221,7 @@ void cli_show_rip_distance(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-ripd:ripd/instance/distance/source
*/
-DEFPY (rip_distance_source,
+DEFPY_YANG (rip_distance_source,
rip_distance_source_cmd,
"[no] distance (1-255) A.B.C.D/M$prefix [WORD$acl]",
NO_STR
@@ -258,7 +258,7 @@ void cli_show_rip_distance_source(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-ripd:ripd/instance/explicit-neighbor
*/
-DEFPY (rip_neighbor,
+DEFPY_YANG (rip_neighbor,
rip_neighbor_cmd,
"[no] neighbor A.B.C.D",
NO_STR
@@ -280,7 +280,7 @@ void cli_show_rip_neighbor(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-ripd:ripd/instance/network
*/
-DEFPY (rip_network_prefix,
+DEFPY_YANG (rip_network_prefix,
rip_network_prefix_cmd,
"[no] network A.B.C.D/M",
NO_STR
@@ -302,7 +302,7 @@ void cli_show_rip_network_prefix(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-ripd:ripd/instance/interface
*/
-DEFPY (rip_network_if,
+DEFPY_YANG (rip_network_if,
rip_network_if_cmd,
"[no] network WORD",
NO_STR
@@ -324,7 +324,7 @@ void cli_show_rip_network_interface(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-ripd:ripd/instance/offset-list
*/
-DEFPY (rip_offset_list,
+DEFPY_YANG (rip_offset_list,
rip_offset_list_cmd,
"[no] offset-list WORD$acl <in|out>$direction (0-16)$metric [IFNAME]",
NO_STR
@@ -367,7 +367,7 @@ void cli_show_rip_offset_list(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-ripd:ripd/instance/passive-default
*/
-DEFPY (rip_passive_default,
+DEFPY_YANG (rip_passive_default,
rip_passive_default_cmd,
"[no] passive-interface default",
NO_STR
@@ -393,7 +393,7 @@ void cli_show_rip_passive_default(struct vty *vty, struct lyd_node *dnode,
* XPath: /frr-ripd:ripd/instance/passive-interface
* /frr-ripd:ripd/instance/non-passive-interface
*/
-DEFPY (rip_passive_interface,
+DEFPY_YANG (rip_passive_interface,
rip_passive_interface_cmd,
"[no] passive-interface IFNAME",
NO_STR
@@ -434,7 +434,7 @@ void cli_show_rip_non_passive_interface(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-ripd:ripd/instance/redistribute
*/
-DEFPY (rip_redistribute,
+DEFPY_YANG (rip_redistribute,
rip_redistribute_cmd,
"[no] redistribute " FRR_REDIST_STR_RIPD "$protocol [{metric (0-16)|route-map WORD}]",
NO_STR
@@ -477,7 +477,7 @@ void cli_show_rip_redistribute(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-ripd:ripd/instance/static-route
*/
-DEFPY (rip_route,
+DEFPY_YANG (rip_route,
rip_route_cmd,
"[no] route A.B.C.D/M",
NO_STR
@@ -499,7 +499,7 @@ void cli_show_rip_route(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-ripd:ripd/instance/timers
*/
-DEFPY (rip_timers,
+DEFPY_YANG (rip_timers,
rip_timers_cmd,
"timers basic (5-2147483647)$update (5-2147483647)$timeout (5-2147483647)$garbage",
"Adjust routing timers\n"
@@ -518,7 +518,7 @@ DEFPY (rip_timers,
return nb_cli_apply_changes(vty, "./timers");
}
-DEFPY (no_rip_timers,
+DEFPY_YANG (no_rip_timers,
no_rip_timers_cmd,
"no timers basic [(5-2147483647) (5-2147483647) (5-2147483647)]",
NO_STR
@@ -547,7 +547,7 @@ void cli_show_rip_timers(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-ripd:ripd/instance/version
*/
-DEFPY (rip_version,
+DEFPY_YANG (rip_version,
rip_version_cmd,
"version (1-2)",
"Set routing protocol version\n"
@@ -560,7 +560,7 @@ DEFPY (rip_version,
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY (no_rip_version,
+DEFPY_YANG (no_rip_version,
no_rip_version_cmd,
"no version [(1-2)]",
NO_STR
@@ -596,7 +596,7 @@ void cli_show_rip_version(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-interface:lib/interface/frr-ripd:rip/split-horizon
*/
-DEFPY (ip_rip_split_horizon,
+DEFPY_YANG (ip_rip_split_horizon,
ip_rip_split_horizon_cmd,
"[no] ip rip split-horizon [poisoned-reverse$poisoned_reverse]",
NO_STR
@@ -641,7 +641,7 @@ void cli_show_ip_rip_split_horizon(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-interface:lib/interface/frr-ripd:rip/v2-broadcast
*/
-DEFPY (ip_rip_v2_broadcast,
+DEFPY_YANG (ip_rip_v2_broadcast,
ip_rip_v2_broadcast_cmd,
"[no] ip rip v2-broadcast",
NO_STR
@@ -667,7 +667,7 @@ void cli_show_ip_rip_v2_broadcast(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-interface:lib/interface/frr-ripd:rip/version-receive
*/
-DEFPY (ip_rip_receive_version,
+DEFPY_YANG (ip_rip_receive_version,
ip_rip_receive_version_cmd,
"ip rip receive version <{1$v1|2$v2}|none>",
IP_STR
@@ -694,7 +694,7 @@ DEFPY (ip_rip_receive_version,
return nb_cli_apply_changes(vty, "./frr-ripd:rip");
}
-DEFPY (no_ip_rip_receive_version,
+DEFPY_YANG (no_ip_rip_receive_version,
no_ip_rip_receive_version_cmd,
"no ip rip receive version [<{1|2}|none>]",
NO_STR
@@ -736,7 +736,7 @@ void cli_show_ip_rip_receive_version(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-interface:lib/interface/frr-ripd:rip/version-send
*/
-DEFPY (ip_rip_send_version,
+DEFPY_YANG (ip_rip_send_version,
ip_rip_send_version_cmd,
"ip rip send version <{1$v1|2$v2}|none>",
IP_STR
@@ -763,7 +763,7 @@ DEFPY (ip_rip_send_version,
return nb_cli_apply_changes(vty, "./frr-ripd:rip");
}
-DEFPY (no_ip_rip_send_version,
+DEFPY_YANG (no_ip_rip_send_version,
no_ip_rip_send_version_cmd,
"no ip rip send version [<{1|2}|none>]",
NO_STR
@@ -805,7 +805,7 @@ void cli_show_ip_rip_send_version(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-interface:lib/interface/frr-ripd:rip/authentication-scheme
*/
-DEFPY (ip_rip_authentication_mode,
+DEFPY_YANG (ip_rip_authentication_mode,
ip_rip_authentication_mode_cmd,
"ip rip authentication mode <md5$mode [auth-length <rfc|old-ripd>$auth_length]|text$mode>",
IP_STR
@@ -837,7 +837,7 @@ DEFPY (ip_rip_authentication_mode,
return nb_cli_apply_changes(vty, "./frr-ripd:rip");
}
-DEFPY (no_ip_rip_authentication_mode,
+DEFPY_YANG (no_ip_rip_authentication_mode,
no_ip_rip_authentication_mode_cmd,
"no ip rip authentication mode [<md5 [auth-length <rfc|old-ripd>]|text>]",
NO_STR
@@ -888,7 +888,7 @@ void cli_show_ip_rip_authentication_scheme(struct vty *vty,
/*
* XPath: /frr-interface:lib/interface/frr-ripd:rip/authentication-password
*/
-DEFPY (ip_rip_authentication_string,
+DEFPY_YANG (ip_rip_authentication_string,
ip_rip_authentication_string_cmd,
"ip rip authentication string LINE$password",
IP_STR
@@ -916,7 +916,7 @@ DEFPY (ip_rip_authentication_string,
return nb_cli_apply_changes(vty, "./frr-ripd:rip");
}
-DEFPY (no_ip_rip_authentication_string,
+DEFPY_YANG (no_ip_rip_authentication_string,
no_ip_rip_authentication_string_cmd,
"no ip rip authentication string [LINE]",
NO_STR
@@ -943,7 +943,7 @@ void cli_show_ip_rip_authentication_string(struct vty *vty,
/*
* XPath: /frr-interface:lib/interface/frr-ripd:rip/authentication-key-chain
*/
-DEFPY (ip_rip_authentication_key_chain,
+DEFPY_YANG (ip_rip_authentication_key_chain,
ip_rip_authentication_key_chain_cmd,
"ip rip authentication key-chain LINE$keychain",
IP_STR
@@ -965,7 +965,7 @@ DEFPY (ip_rip_authentication_key_chain,
return nb_cli_apply_changes(vty, "./frr-ripd:rip");
}
-DEFPY (no_ip_rip_authentication_key_chain,
+DEFPY_YANG (no_ip_rip_authentication_key_chain,
no_ip_rip_authentication_key_chain_cmd,
"no ip rip authentication key-chain [LINE]",
NO_STR
@@ -992,7 +992,7 @@ void cli_show_ip_rip_authentication_key_chain(struct vty *vty,
/*
* XPath: /frr-ripd:clear-rip-route
*/
-DEFPY (clear_ip_rip,
+DEFPY_YANG (clear_ip_rip,
clear_ip_rip_cmd,
"clear ip rip [vrf WORD]",
CLEAR_STR
diff --git a/ripngd/ripng_cli.c b/ripngd/ripng_cli.c
index b3d92fb0d9..f66de175fa 100644
--- a/ripngd/ripng_cli.c
+++ b/ripngd/ripng_cli.c
@@ -37,7 +37,7 @@
/*
* XPath: /frr-ripngd:ripngd/instance
*/
-DEFPY_NOSH (router_ripng,
+DEFPY_YANG_NOSH (router_ripng,
router_ripng_cmd,
"router ripng [vrf NAME]",
"Enable a routing process\n"
@@ -62,7 +62,7 @@ DEFPY_NOSH (router_ripng,
return ret;
}
-DEFPY (no_router_ripng,
+DEFPY_YANG (no_router_ripng,
no_router_ripng_cmd,
"no router ripng [vrf NAME]",
NO_STR
@@ -100,7 +100,7 @@ void cli_show_router_ripng(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-ripngd:ripngd/instance/allow-ecmp
*/
-DEFPY (ripng_allow_ecmp,
+DEFPY_YANG (ripng_allow_ecmp,
ripng_allow_ecmp_cmd,
"[no] allow-ecmp",
NO_STR
@@ -124,7 +124,7 @@ void cli_show_ripng_allow_ecmp(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-ripngd:ripngd/instance/default-information-originate
*/
-DEFPY (ripng_default_information_originate,
+DEFPY_YANG (ripng_default_information_originate,
ripng_default_information_originate_cmd,
"[no] default-information originate",
NO_STR
@@ -150,7 +150,7 @@ void cli_show_ripng_default_information_originate(struct vty *vty,
/*
* XPath: /frr-ripngd:ripngd/instance/default-metric
*/
-DEFPY (ripng_default_metric,
+DEFPY_YANG (ripng_default_metric,
ripng_default_metric_cmd,
"default-metric (1-16)",
"Set a metric of redistribute routes\n"
@@ -162,7 +162,7 @@ DEFPY (ripng_default_metric,
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY (no_ripng_default_metric,
+DEFPY_YANG (no_ripng_default_metric,
no_ripng_default_metric_cmd,
"no default-metric [(1-16)]",
NO_STR
@@ -184,7 +184,7 @@ void cli_show_ripng_default_metric(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-ripngd:ripngd/instance/network
*/
-DEFPY (ripng_network_prefix,
+DEFPY_YANG (ripng_network_prefix,
ripng_network_prefix_cmd,
"[no] network X:X::X:X/M",
NO_STR
@@ -206,7 +206,7 @@ void cli_show_ripng_network_prefix(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-ripngd:ripngd/instance/interface
*/
-DEFPY (ripng_network_if,
+DEFPY_YANG (ripng_network_if,
ripng_network_if_cmd,
"[no] network WORD",
NO_STR
@@ -228,7 +228,7 @@ void cli_show_ripng_network_interface(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-ripngd:ripngd/instance/offset-list
*/
-DEFPY (ripng_offset_list,
+DEFPY_YANG (ripng_offset_list,
ripng_offset_list_cmd,
"[no] offset-list WORD$acl <in|out>$direction (0-16)$metric [IFNAME]",
NO_STR
@@ -271,7 +271,7 @@ void cli_show_ripng_offset_list(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-ripngd:ripngd/instance/passive-interface
*/
-DEFPY (ripng_passive_interface,
+DEFPY_YANG (ripng_passive_interface,
ripng_passive_interface_cmd,
"[no] passive-interface IFNAME",
NO_STR
@@ -294,7 +294,7 @@ void cli_show_ripng_passive_interface(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-ripngd:ripngd/instance/redistribute
*/
-DEFPY (ripng_redistribute,
+DEFPY_YANG (ripng_redistribute,
ripng_redistribute_cmd,
"[no] redistribute " FRR_REDIST_STR_RIPNGD "$protocol [{metric (0-16)|route-map WORD}]",
NO_STR
@@ -337,7 +337,7 @@ void cli_show_ripng_redistribute(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-ripngd:ripngd/instance/static-route
*/
-DEFPY (ripng_route,
+DEFPY_YANG (ripng_route,
ripng_route_cmd,
"[no] route X:X::X:X/M",
NO_STR
@@ -359,7 +359,7 @@ void cli_show_ripng_route(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-ripngd:ripngd/instance/aggregate-addres
*/
-DEFPY (ripng_aggregate_address,
+DEFPY_YANG (ripng_aggregate_address,
ripng_aggregate_address_cmd,
"[no] aggregate-address X:X::X:X/M",
NO_STR
@@ -383,7 +383,7 @@ void cli_show_ripng_aggregate_address(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-ripngd:ripngd/instance/timers
*/
-DEFPY (ripng_timers,
+DEFPY_YANG (ripng_timers,
ripng_timers_cmd,
"timers basic (1-65535)$update (1-65535)$timeout (1-65535)$garbage",
"RIPng timers setup\n"
@@ -402,7 +402,7 @@ DEFPY (ripng_timers,
return nb_cli_apply_changes(vty, "./timers");
}
-DEFPY (no_ripng_timers,
+DEFPY_YANG (no_ripng_timers,
no_ripng_timers_cmd,
"no timers basic [(1-65535) (1-65535) (1-65535)]",
NO_STR
@@ -431,7 +431,7 @@ void cli_show_ripng_timers(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-interface:lib/interface/frr-ripngd:ripng/split-horizon
*/
-DEFPY (ipv6_ripng_split_horizon,
+DEFPY_YANG (ipv6_ripng_split_horizon,
ipv6_ripng_split_horizon_cmd,
"[no] ipv6 ripng split-horizon [poisoned-reverse$poisoned_reverse]",
NO_STR
@@ -476,7 +476,7 @@ void cli_show_ipv6_ripng_split_horizon(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-ripngd:clear-ripng-route
*/
-DEFPY (clear_ipv6_rip,
+DEFPY_YANG (clear_ipv6_rip,
clear_ipv6_rip_cmd,
"clear ipv6 ripng [vrf WORD]",
CLEAR_STR
diff --git a/sharpd/sharp_main.c b/sharpd/sharp_main.c
index 40b41fd728..ccf34b10dd 100644
--- a/sharpd/sharp_main.c
+++ b/sharpd/sharp_main.c
@@ -167,9 +167,6 @@ int main(int argc, char **argv, char **envp)
nexthop_group_init(NULL, NULL, NULL, NULL);
vrf_init(NULL, NULL, NULL, NULL, NULL);
- access_list_init();
- route_map_init();
-
sharp_zebra_init();
/* Get configuration file. */
diff --git a/sharpd/sharp_vty.c b/sharpd/sharp_vty.c
index 48220d1c9b..6a120c8eff 100644
--- a/sharpd/sharp_vty.c
+++ b/sharpd/sharp_vty.c
@@ -278,7 +278,8 @@ DEFPY (install_routes,
if (backup) {
/* Set flag and index in primary nexthop */
SET_FLAG(sg.r.nhop.flags, NEXTHOP_FLAG_HAS_BACKUP);
- sg.r.nhop.backup_idx = 0;
+ sg.r.nhop.backup_num = 1;
+ sg.r.nhop.backup_idx[0] = 0;
if (backup_nexthop4.s_addr != INADDR_ANY) {
sg.r.backup_nhop.gate.ipv4 = backup_nexthop4;
@@ -393,27 +394,31 @@ DEFUN_NOSH (show_debugging_sharpd,
return CMD_SUCCESS;
}
-DEFPY(sharp_lsp_prefix_v4, sharp_lsp_prefix_v4_cmd,
- "sharp lsp (0-100000)$inlabel\
+DEFPY (sharp_lsp_prefix_v4, sharp_lsp_prefix_v4_cmd,
+ "sharp lsp [update]$update (0-100000)$inlabel\
nexthop-group NHGNAME$nhgname\
[prefix A.B.C.D/M$pfx\
" FRR_IP_REDIST_STR_ZEBRA "$type_str [instance (0-255)$instance]]",
- "Sharp Routing Protocol\n"
- "Add an LSP\n"
- "The ingress label to use\n"
- "Use nexthops from a nexthop-group\n"
- "The nexthop-group name\n"
- "Label a prefix\n"
- "The v4 prefix to label\n"
- FRR_IP_REDIST_HELP_STR_ZEBRA
- "Instance to use\n"
- "Instance\n")
+ "Sharp Routing Protocol\n"
+ "Add an LSP\n"
+ "Update an LSP\n"
+ "The ingress label to use\n"
+ "Use nexthops from a nexthop-group\n"
+ "The nexthop-group name\n"
+ "Label a prefix\n"
+ "The v4 prefix to label\n"
+ FRR_IP_REDIST_HELP_STR_ZEBRA
+ "Instance to use\n"
+ "Instance\n")
{
struct nexthop_group_cmd *nhgc = NULL;
struct nexthop_group_cmd *backup_nhgc = NULL;
struct nexthop_group *backup_nhg = NULL;
struct prefix p = {};
int type = 0;
+ bool update_p;
+
+ update_p = (update != NULL);
/* We're offered a v4 prefix */
if (pfx->family > 0 && type_str) {
@@ -457,7 +462,8 @@ DEFPY(sharp_lsp_prefix_v4, sharp_lsp_prefix_v4_cmd,
backup_nhg = &(backup_nhgc->nhg);
}
- if (sharp_install_lsps_helper(true, pfx->family > 0 ? &p : NULL,
+ if (sharp_install_lsps_helper(true /*install*/, update_p,
+ pfx->family > 0 ? &p : NULL,
type, instance, inlabel,
&(nhgc->nhg), backup_nhg) == 0)
return CMD_SUCCESS;
@@ -522,7 +528,8 @@ DEFPY(sharp_remove_lsp_prefix_v4, sharp_remove_lsp_prefix_v4_cmd,
nhg = &(nhgc->nhg);
}
- if (sharp_install_lsps_helper(false, pfx->family > 0 ? &p : NULL,
+ if (sharp_install_lsps_helper(false /*!install*/, false,
+ pfx->family > 0 ? &p : NULL,
type, instance, inlabel, nhg, NULL) == 0)
return CMD_SUCCESS;
else {
diff --git a/sharpd/sharp_zebra.c b/sharpd/sharp_zebra.c
index 7ab2d6ec22..e0f16d71f5 100644
--- a/sharpd/sharp_zebra.c
+++ b/sharpd/sharp_zebra.c
@@ -114,15 +114,16 @@ static int sharp_ifp_down(struct interface *ifp)
return 0;
}
-int sharp_install_lsps_helper(bool install_p, const struct prefix *p,
- uint8_t type, int instance, uint32_t in_label,
+int sharp_install_lsps_helper(bool install_p, bool update_p,
+ const struct prefix *p, uint8_t type,
+ int instance, uint32_t in_label,
const struct nexthop_group *nhg,
const struct nexthop_group *backup_nhg)
{
struct zapi_labels zl = {};
struct zapi_nexthop *znh;
const struct nexthop *nh;
- int i, ret;
+ int i, cmd, ret;
zl.type = ZEBRA_LSP_SHARP;
zl.local_label = in_label;
@@ -155,6 +156,8 @@ int sharp_install_lsps_helper(bool install_p, const struct prefix *p,
return -1;
i++;
+ if (i >= MULTIPATH_NUM)
+ break;
}
}
@@ -188,6 +191,8 @@ int sharp_install_lsps_helper(bool install_p, const struct prefix *p,
return -1;
i++;
+ if (i >= MULTIPATH_NUM)
+ break;
}
if (i > 0)
@@ -196,12 +201,17 @@ int sharp_install_lsps_helper(bool install_p, const struct prefix *p,
zl.backup_nexthop_num = i;
}
- if (install_p)
- ret = zebra_send_mpls_labels(zclient, ZEBRA_MPLS_LABELS_ADD,
- &zl);
- else
- ret = zebra_send_mpls_labels(zclient, ZEBRA_MPLS_LABELS_DELETE,
- &zl);
+
+ if (install_p) {
+ if (update_p)
+ cmd = ZEBRA_MPLS_LABELS_REPLACE;
+ else
+ cmd = ZEBRA_MPLS_LABELS_ADD;
+ } else {
+ cmd = ZEBRA_MPLS_LABELS_DELETE;
+ }
+
+ ret = zebra_send_mpls_labels(zclient, cmd, &zl);
return ret;
}
diff --git a/sharpd/sharp_zebra.h b/sharpd/sharp_zebra.h
index cb2f38a6ab..e40585aa6a 100644
--- a/sharpd/sharp_zebra.h
+++ b/sharpd/sharp_zebra.h
@@ -44,8 +44,9 @@ extern void sharp_install_routes_helper(struct prefix *p, vrf_id_t vrf_id,
extern void sharp_remove_routes_helper(struct prefix *p, vrf_id_t vrf_id,
uint8_t instance, uint32_t routes);
-int sharp_install_lsps_helper(bool install_p, const struct prefix *p,
- uint8_t type, int instance, uint32_t in_label,
+int sharp_install_lsps_helper(bool install_p, bool update_p,
+ const struct prefix *p, uint8_t type,
+ int instance, uint32_t in_label,
const struct nexthop_group *nhg,
const struct nexthop_group *backup_nhg);
diff --git a/staticd/static_main.c b/staticd/static_main.c
index 3c5922b85a..ac8f8ff029 100644
--- a/staticd/static_main.c
+++ b/staticd/static_main.c
@@ -31,12 +31,14 @@
#include "vrf.h"
#include "nexthop.h"
#include "filter.h"
+#include "routing_nb.h"
#include "static_vrf.h"
#include "static_vty.h"
#include "static_routes.h"
#include "static_zebra.h"
#include "static_debug.h"
+#include "static_nb.h"
char backup_config_file[256];
@@ -63,10 +65,12 @@ struct option longopts[] = { { 0 } };
/* Master of threads. */
struct thread_master *master;
+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);
}
/* SIGINT / SIGTERM handler. */
@@ -108,7 +112,10 @@ struct quagga_signal_t static_signals[] = {
static const struct frr_yang_module_info *const staticd_yang_modules[] = {
&frr_filter_info,
+ &frr_interface_info,
&frr_vrf_info,
+ &frr_routing_info,
+ &frr_staticd_info,
};
#define STATIC_VTY_PORT 2616
@@ -148,13 +155,15 @@ int main(int argc, char **argv, char **envp)
master = frr_init();
- access_list_init();
static_debug_init();
static_vrf_init();
static_zebra_init();
static_vty_init();
+ hook_register(routing_conf_event,
+ routing_control_plane_protocols_name_validate);
+
snprintf(backup_config_file, sizeof(backup_config_file),
"%s/zebra.conf", frr_sysconfdir);
staticd_di.backup_config_file = backup_config_file;
diff --git a/staticd/static_memory.c b/staticd/static_memory.c
index 77ca4a3439..122cc9fce1 100644
--- a/staticd/static_memory.c
+++ b/staticd/static_memory.c
@@ -25,4 +25,4 @@
DEFINE_MGROUP(STATIC, "staticd")
-DEFINE_MTYPE(STATIC, STATIC_ROUTE, "Static Route");
+DEFINE_MTYPE(STATIC, STATIC_NEXTHOP, "Static Nexthop");
diff --git a/staticd/static_memory.h b/staticd/static_memory.h
index 77a0db3b12..e9cc7ba469 100644
--- a/staticd/static_memory.h
+++ b/staticd/static_memory.h
@@ -23,6 +23,7 @@
DECLARE_MGROUP(STATIC)
-DECLARE_MTYPE(STATIC_ROUTE);
+DECLARE_MTYPE(STATIC_NEXTHOP);
+DECLARE_MTYPE(STATIC_PATH);
#endif
diff --git a/staticd/static_nb.c b/staticd/static_nb.c
new file mode 100644
index 0000000000..419a6a5366
--- /dev/null
+++ b/staticd/static_nb.c
@@ -0,0 +1,188 @@
+/*
+ * Copyright (C) 2018 Vmware
+ * Vishal Dhingra
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; see the file COPYING; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#include "northbound.h"
+#include "libfrr.h"
+#include "static_nb.h"
+
+
+/* clang-format off */
+
+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/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,
+ }
+ },
+ {
+ .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/path-list",
+ .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,
+ }
+ },
+ {
+ .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/path-list/tag",
+ .cbs = {
+ .modify = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_tag_modify,
+ }
+ },
+ {
+ .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/path-list/table-id",
+ .cbs = {
+ .modify = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_table_id_modify,
+ }
+ },
+ {
+ .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/path-list/frr-nexthops/nexthop",
+ .cbs = {
+ .apply_finish = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_apply_finish,
+ .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,
+ }
+ },
+ {
+ .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/path-list/frr-nexthops/nexthop/bh-type",
+ .cbs = {
+ .modify = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_bh_type_modify,
+ .destroy = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_bh_type_destroy,
+ }
+ },
+ {
+ .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/path-list/frr-nexthops/nexthop/onlink",
+ .cbs = {
+ .modify = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_onlink_modify,
+ .destroy = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_onlink_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 = {
+ .create = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_create,
+ .destroy = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_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/label",
+ .cbs = {
+ .modify = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_label_modify,
+ .destroy = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_label_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/ttl",
+ .cbs = {
+ .modify = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_ttl_modify,
+ .destroy = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_ttl_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/traffic-class",
+ .cbs = {
+ .modify = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_traffic_class_modify,
+ .destroy = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_traffic_class_destroy,
+ }
+ },
+ {
+ .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/src-list",
+ .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,
+ }
+ },
+ {
+ .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/src-list/path-list",
+ .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,
+ }
+ },
+ {
+ .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/src-list/path-list/tag",
+ .cbs = {
+ .modify = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_tag_modify,
+ }
+ },
+ {
+ .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/src-list/path-list/table-id",
+ .cbs = {
+ .modify = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_table_id_modify,
+ }
+ },
+ {
+ .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/src-list/path-list/frr-nexthops/nexthop",
+ .cbs = {
+ .apply_finish = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_apply_finish,
+ .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,
+ }
+ },
+ {
+ .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/src-list/path-list/frr-nexthops/nexthop/bh-type",
+ .cbs = {
+ .modify = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_bh_type_modify,
+ .destroy = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_bh_type_destroy,
+ }
+ },
+ {
+ .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/src-list/path-list/frr-nexthops/nexthop/onlink",
+ .cbs = {
+ .modify = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_onlink_modify,
+ .destroy = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_onlink_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 = {
+ .create = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_create,
+ .destroy = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_mpls_label_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/mpls-label-stack/entry/label",
+ .cbs = {
+ .modify = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_label_modify,
+ .destroy = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_label_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/ttl",
+ .cbs = {
+ .modify = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_ttl_modify,
+ .destroy = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_ttl_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/traffic-class",
+ .cbs = {
+ .modify = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_traffic_class_modify,
+ .destroy = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_traffic_class_destroy,
+ }
+ },
+ {
+ .xpath = NULL,
+ },
+ }
+};
diff --git a/staticd/static_nb.h b/staticd/static_nb.h
new file mode 100644
index 0000000000..e46c156265
--- /dev/null
+++ b/staticd/static_nb.h
@@ -0,0 +1,166 @@
+/*
+ * Copyright (C) 2018 Vmware
+ * Vishal Dhingra
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; see the file COPYING; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#ifndef _FRR_STATIC_NB_H_
+#define _FRR_STATIC_NB_H_
+
+extern const struct frr_yang_module_info frr_staticd_info;
+
+/* Mandatory callbacks. */
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_create(
+ struct nb_cb_create_args *args);
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_destroy(
+ struct nb_cb_destroy_args *args);
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_create(
+ struct nb_cb_create_args *args);
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_destroy(
+ struct nb_cb_destroy_args *args);
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_tag_modify(
+ struct nb_cb_modify_args *args);
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_table_id_modify(
+ struct nb_cb_modify_args *args);
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_create(
+ struct nb_cb_create_args *args);
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_destroy(
+ struct nb_cb_destroy_args *args);
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_bh_type_modify(
+ struct nb_cb_modify_args *args);
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_bh_type_destroy(
+ struct nb_cb_destroy_args *args);
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_onlink_modify(
+ struct nb_cb_modify_args *args);
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_onlink_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(
+ 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_label_modify(
+ struct nb_cb_modify_args *args);
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_label_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_ttl_modify(
+ struct nb_cb_modify_args *args);
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_ttl_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_traffic_class_modify(
+ struct nb_cb_modify_args *args);
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_traffic_class_destroy(
+ struct nb_cb_destroy_args *args);
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_create(
+ struct nb_cb_create_args *args);
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_destroy(
+ struct nb_cb_destroy_args *args);
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_create(
+ struct nb_cb_create_args *args);
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_destroy(
+ struct nb_cb_destroy_args *args);
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_tag_modify(
+ struct nb_cb_modify_args *args);
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_table_id_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_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_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_bh_type_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_bh_type_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_onlink_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_onlink_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(
+ 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_label_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_mpls_label_stack_entry_label_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_ttl_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_mpls_label_stack_entry_ttl_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_traffic_class_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_mpls_label_stack_entry_traffic_class_destroy(
+ struct nb_cb_destroy_args *args);
+
+/* Optional 'apply_finish' callbacks. */
+
+void routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_apply_finish(
+ struct nb_cb_apply_finish_args *args);
+void routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_apply_finish(
+ struct nb_cb_apply_finish_args *args);
+
+/* Optional 'pre_validate' callbacks. */
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_pre_validate(
+ struct nb_cb_pre_validate_args *args);
+
+/*
+ * Callback registered with routing_nb lib to validate only
+ * one instance of staticd is allowed
+ */
+int routing_control_plane_protocols_name_validate(
+ struct nb_cb_create_args *args);
+
+/* xpath macros */
+/* route-list */
+#define FRR_STATIC_ROUTE_INFO_KEY_XPATH \
+ "/frr-routing:routing/control-plane-protocols/" \
+ "control-plane-protocol[type='%s'][name='%s'][vrf='%s']/" \
+ "frr-staticd:staticd/route-list[prefix='%s'][afi-safi='%s']/" \
+ "path-list[distance='%u']"
+
+
+#define FRR_STATIC_ROUTE_PATH_TAG_XPATH "/tag"
+
+#define FRR_STATIC_ROUTE_PATH_TABLEID_XPATH "/table-id"
+
+/* route-list/frr-nexthops */
+#define FRR_STATIC_ROUTE_NH_KEY_XPATH \
+ "/frr-nexthops/" \
+ "nexthop[nh-type='%s'][vrf='%s'][gateway='%s'][interface='%s']"
+
+#define FRR_STATIC_ROUTE_NH_ONLINK_XPATH "/onlink"
+
+#define FRR_STATIC_ROUTE_NH_BH_XPATH "/bh-type"
+
+#define FRR_STATIC_ROUTE_NH_LABEL_XPATH "/mpls-label-stack"
+
+#define FRR_STATIC_ROUTE_NHLB_KEY_XPATH "/entry[id='%u']/label"
+
+/* route-list/srclist */
+#define FRR_S_ROUTE_SRC_INFO_KEY_XPATH \
+ "/frr-routing:routing/control-plane-protocols/" \
+ "control-plane-protocol[type='%s'][name='%s'][vrf='%s']/" \
+ "frr-staticd:staticd/route-list[prefix='%s'][afi-safi='%s']/" \
+ "src-list[src-prefix='%s']/path-list[distance='%u']"
+
+/* route-list/frr-nexthops */
+#define FRR_DEL_S_ROUTE_NH_KEY_XPATH \
+ FRR_STATIC_ROUTE_INFO_KEY_XPATH \
+ FRR_STATIC_ROUTE_NH_KEY_XPATH
+
+/* route-list/src/src-list/frr-nexthops*/
+#define FRR_DEL_S_ROUTE_SRC_NH_KEY_XPATH \
+ FRR_S_ROUTE_SRC_INFO_KEY_XPATH \
+ FRR_STATIC_ROUTE_NH_KEY_XPATH
+
+#endif
diff --git a/staticd/static_nb_config.c b/staticd/static_nb_config.c
new file mode 100644
index 0000000000..40c4d85fb6
--- /dev/null
+++ b/staticd/static_nb_config.c
@@ -0,0 +1,1241 @@
+/*
+ * Copyright (C) 2018 Vmware
+ * Vishal Dhingra
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; see the file COPYING; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#include "northbound.h"
+#include "libfrr.h"
+#include "log.h"
+#include "lib_errors.h"
+#include "prefix.h"
+#include "table.h"
+#include "vrf.h"
+#include "nexthop.h"
+#include "srcdest_table.h"
+
+#include "static_vrf.h"
+#include "static_routes.h"
+#include "static_nb.h"
+
+
+static int static_path_list_create(struct nb_cb_create_args *args)
+{
+ struct route_node *rn;
+ struct static_path *pn;
+ uint8_t distance;
+
+ switch (args->event) {
+ case NB_EV_VALIDATE:
+ case NB_EV_ABORT:
+ case NB_EV_PREPARE:
+ break;
+ case NB_EV_APPLY:
+ rn = nb_running_get_entry(args->dnode, NULL, true);
+ distance = yang_dnode_get_uint8(args->dnode, "./distance");
+ pn = static_add_path(rn, distance);
+ nb_running_set_entry(args->dnode, pn);
+ }
+
+ return NB_OK;
+}
+
+static void static_path_list_destroy(struct nb_cb_destroy_args *args,
+ const struct lyd_node *rn_dnode,
+ struct stable_info *info)
+{
+ struct route_node *rn;
+ struct static_path *pn;
+
+ pn = nb_running_unset_entry(args->dnode);
+ rn = nb_running_get_entry(rn_dnode, NULL, true);
+ static_del_path(rn, pn, info->safi, info->svrf);
+}
+
+static void static_path_list_tag_modify(struct nb_cb_modify_args *args,
+ const struct lyd_node *rn_dnode,
+ struct stable_info *info)
+{
+ struct static_path *pn;
+ struct route_node *rn;
+ route_tag_t tag;
+
+ tag = yang_dnode_get_uint32(args->dnode, NULL);
+ pn = nb_running_get_entry(args->dnode, NULL, true);
+ pn->tag = tag;
+ rn = nb_running_get_entry(rn_dnode, NULL, true);
+
+ static_install_path(rn, pn, info->safi, info->svrf);
+}
+
+static int static_path_list_tableid_modify(struct nb_cb_modify_args *args,
+ const struct lyd_node *rn_dnode,
+ struct stable_info *info)
+{
+ struct static_path *pn;
+ struct route_node *rn;
+ uint32_t table_id;
+ const struct lyd_node *vrf_dnode;
+ const char *vrf;
+
+ switch (args->event) {
+ 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, NULL);
+ if (table_id && (strcmp(vrf, vrf_get_default_name()) != 0)
+ && !vrf_is_backend_netns()) {
+ snprintf(args->errmsg, args->errmsg_len,
+ "%% table param only available when running on netns-based vrfs");
+ return NB_ERR_VALIDATION;
+ }
+ break;
+ case NB_EV_PREPARE:
+ case NB_EV_ABORT:
+ break;
+ case NB_EV_APPLY:
+ table_id = yang_dnode_get_uint32(args->dnode, NULL);
+ pn = nb_running_get_entry(args->dnode, NULL, true);
+ pn->table_id = table_id;
+ rn = nb_running_get_entry(rn_dnode, NULL, true);
+ static_install_path(rn, pn, info->safi, info->svrf);
+ break;
+ }
+
+ return NB_OK;
+}
+
+static bool static_nexthop_create(struct nb_cb_create_args *args,
+ const struct lyd_node *rn_dnode,
+ struct stable_info *info)
+{
+ struct route_node *rn;
+ struct static_path *pn;
+ struct ipaddr ipaddr;
+ struct static_nexthop *nh;
+ int nh_type;
+ const char *ifname;
+ const char *nh_vrf;
+
+ switch (args->event) {
+ case NB_EV_VALIDATE:
+ ifname = yang_dnode_get_string(args->dnode, "./interface");
+ if (ifname != NULL) {
+ if (strcasecmp(ifname, "Null0") == 0
+ || strcasecmp(ifname, "reject") == 0
+ || strcasecmp(ifname, "blackhole") == 0) {
+ snprintf(args->errmsg, args->errmsg_len,
+ "%s: Nexthop interface name can not be from reserved keywords(Null0, reject, blackhole)",
+ ifname);
+ return NB_ERR_VALIDATION;
+ }
+ }
+ break;
+ case NB_EV_PREPARE:
+ 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");
+ pn = nb_running_get_entry(args->dnode, NULL, true);
+ rn = nb_running_get_entry(rn_dnode, NULL, true);
+
+ if (!static_add_nexthop_validate(info->svrf, nh_type, &ipaddr))
+ flog_warn(
+ EC_LIB_NB_CB_CONFIG_VALIDATE,
+ "Warning!! Local connected address is configured as Gateway IP((%s))",
+ yang_dnode_get_string(args->dnode,
+ "./gateway"));
+ nh = static_add_nexthop(rn, pn, info->safi, info->svrf, nh_type,
+ &ipaddr, ifname, nh_vrf);
+ if (!nh) {
+ char buf[SRCDEST2STR_BUFFER];
+
+ flog_warn(
+ EC_LIB_NB_CB_CONFIG_APPLY,
+ "%s : nh [%d:%s:%s:%s] nexthop creation failed",
+ srcdest_rnode2str(rn, buf, sizeof(buf)),
+ nh_type, ifname,
+ yang_dnode_get_string(args->dnode, "./gateway"),
+ nh_vrf);
+ return NB_ERR;
+ }
+ nb_running_set_entry(args->dnode, nh);
+ break;
+ }
+
+ return NB_OK;
+}
+
+static bool static_nexthop_destroy(struct nb_cb_destroy_args *args,
+ const struct lyd_node *rn_dnode,
+ struct stable_info *info)
+{
+ struct route_node *rn;
+ struct static_path *pn;
+ const struct lyd_node *pn_dnode;
+ struct static_nexthop *nh;
+ int ret;
+
+ nh = nb_running_unset_entry(args->dnode);
+ pn_dnode = yang_dnode_get_parent(args->dnode, "path-list");
+ pn = nb_running_get_entry(pn_dnode, NULL, true);
+ rn = nb_running_get_entry(rn_dnode, NULL, true);
+
+ ret = static_delete_nexthop(rn, pn, info->safi, info->svrf, nh);
+ if (!ret) {
+ char buf[SRCDEST2STR_BUFFER];
+
+ flog_warn(EC_LIB_NB_CB_CONFIG_APPLY,
+ "%s : nh [%d:%s:%s:%s] nexthop destroy failed",
+ srcdest_rnode2str(rn, buf, sizeof(buf)),
+ yang_dnode_get_enum(args->dnode, "./nh-type"),
+ yang_dnode_get_string(args->dnode, "./interface"),
+ yang_dnode_get_string(args->dnode, "./gateway"),
+ yang_dnode_get_string(args->dnode, "./vrf"));
+ return NB_ERR;
+ }
+
+ return NB_OK;
+}
+
+static int nexthop_mpls_label_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 label position");
+ return NB_ERR;
+ }
+ /* Mapping to array = list-index -1 */
+ index = pos - 1;
+ nh->snh_label.label[index] = 0;
+ nh->snh_label.num_labels++;
+ break;
+ }
+
+ return NB_OK;
+}
+
+static int
+nexthop_mpls_label_stack_entry_destroy(struct nb_cb_destroy_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 label position");
+ return NB_ERR;
+ }
+ index = pos - 1;
+ nh->snh_label.label[index] = 0;
+ nh->snh_label.num_labels--;
+ break;
+ }
+
+ return NB_OK;
+}
+
+static int static_nexthop_mpls_label_modify(struct nb_cb_modify_args *args)
+{
+ struct static_nexthop *nh;
+ uint32_t pos;
+ uint8_t index;
+
+ nh = nb_running_get_entry(args->dnode, NULL, true);
+ pos = yang_get_list_pos(args->dnode->parent);
+ if (!pos) {
+ flog_warn(EC_LIB_NB_CB_CONFIG_APPLY,
+ "libyang returns invalid label position");
+ return NB_ERR;
+ }
+ /* Mapping to array = list-index -1 */
+ index = pos - 1;
+ nh->snh_label.label[index] = yang_dnode_get_uint32(args->dnode, NULL);
+
+ return NB_OK;
+}
+
+static int static_nexthop_onlink_modify(struct nb_cb_modify_args *args)
+{
+ struct static_nexthop *nh;
+
+ nh = nb_running_get_entry(args->dnode, NULL, true);
+ nh->onlink = yang_dnode_get_bool(args->dnode, NULL);
+
+ return NB_OK;
+}
+
+static int static_nexthop_bh_type_modify(struct nb_cb_modify_args *args)
+{
+ struct static_nexthop *nh;
+
+ nh = nb_running_get_entry(args->dnode, NULL, true);
+ nh->bh_type = yang_dnode_get_enum(args->dnode, NULL);
+
+ return NB_OK;
+}
+
+
+void routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_apply_finish(
+ struct nb_cb_apply_finish_args *args)
+{
+ struct static_nexthop *nh;
+ struct static_path *pn;
+ struct route_node *rn;
+ const struct lyd_node *pn_dnode;
+ const struct lyd_node *rn_dnode;
+ const char *ifname;
+ const char *nh_vrf;
+ struct stable_info *info;
+ int nh_type;
+
+ 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");
+
+ nh = nb_running_get_entry(args->dnode, NULL, true);
+
+ pn_dnode = yang_dnode_get_parent(args->dnode, "path-list");
+ pn = nb_running_get_entry(pn_dnode, NULL, true);
+
+ rn_dnode = yang_dnode_get_parent(pn_dnode, "route-list");
+ rn = nb_running_get_entry(rn_dnode, NULL, true);
+ info = route_table_get_info(rn->table);
+
+ static_install_nexthop(rn, pn, nh, info->safi, info->svrf, ifname,
+ nh_type, nh_vrf);
+}
+
+
+void routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_apply_finish(
+ struct nb_cb_apply_finish_args *args)
+{
+ struct static_nexthop *nh;
+ struct static_path *pn;
+ struct route_node *rn;
+ struct route_node *src_rn;
+ const struct lyd_node *pn_dnode;
+ const struct lyd_node *rn_dnode;
+ const struct lyd_node *src_dnode;
+ const char *ifname;
+ const char *nh_vrf;
+ struct stable_info *info;
+ int nh_type;
+
+ 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");
+
+ nh = nb_running_get_entry(args->dnode, NULL, true);
+
+ pn_dnode = yang_dnode_get_parent(args->dnode, "path-list");
+ pn = nb_running_get_entry(pn_dnode, NULL, true);
+
+ src_dnode = yang_dnode_get_parent(pn_dnode, "src-list");
+ src_rn = nb_running_get_entry(src_dnode, NULL, true);
+
+ rn_dnode = yang_dnode_get_parent(src_dnode, "route-list");
+ rn = nb_running_get_entry(rn_dnode, NULL, true);
+ info = route_table_get_info(rn->table);
+
+ static_install_nexthop(src_rn, pn, nh, info->safi, info->svrf, ifname,
+ nh_type, nh_vrf);
+}
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_pre_validate(
+ struct nb_cb_pre_validate_args *args)
+{
+ const struct lyd_node *mls_dnode;
+ uint32_t count;
+
+ mls_dnode = yang_dnode_get(args->dnode, "./mpls-label-stack");
+ count = yang_get_list_elements_count(yang_dnode_get_child(mls_dnode));
+
+ if (count > MPLS_MAX_LABELS) {
+ snprintf(args->errmsg, args->errmsg_len,
+ "Too many labels, Enter %d or fewer",
+ MPLS_MAX_LABELS);
+ return NB_ERR_VALIDATION;
+ }
+ return NB_OK;
+}
+
+int routing_control_plane_protocols_name_validate(
+ struct nb_cb_create_args *args)
+{
+ const char *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");
+ return NB_ERR_VALIDATION;
+ }
+ return NB_OK;
+}
+/*
+ * XPath:
+ * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list
+ */
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_create(
+ struct nb_cb_create_args *args)
+{
+ struct vrf *vrf;
+ struct static_vrf *s_vrf;
+ struct route_node *rn;
+ const struct lyd_node *vrf_dnode;
+ struct prefix prefix;
+ const char *afi_safi;
+ afi_t prefix_afi;
+ afi_t afi;
+ safi_t safi;
+
+ 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_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"));
+ return NB_ERR_VALIDATION;
+ }
+ break;
+ case NB_EV_PREPARE:
+ case NB_EV_ABORT:
+ break;
+ case NB_EV_APPLY:
+ vrf_dnode = yang_dnode_get_parent(args->dnode,
+ "control-plane-protocol");
+ 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_afi_safi_identity2value(afi_safi, &afi, &safi);
+
+ rn = static_add_route(afi, safi, &prefix, NULL, s_vrf);
+ if (!rn) {
+ flog_warn(
+ EC_LIB_NB_CB_CONFIG_APPLY,
+ "route node %s creation failed",
+ yang_dnode_get_string(args->dnode, "./prefix"));
+ return NB_ERR;
+ }
+ nb_running_set_entry(args->dnode, rn);
+ break;
+ }
+ return NB_OK;
+}
+
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_destroy(
+ struct nb_cb_destroy_args *args)
+{
+ struct route_node *rn;
+ struct stable_info *info;
+
+ switch (args->event) {
+ case NB_EV_VALIDATE:
+ case NB_EV_PREPARE:
+ case NB_EV_ABORT:
+ break;
+ case NB_EV_APPLY:
+ rn = nb_running_unset_entry(args->dnode);
+ info = route_table_get_info(rn->table);
+ static_del_route(rn, info->safi, info->svrf);
+ break;
+ }
+ return NB_OK;
+}
+
+/*
+ * XPath:
+ * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/path-list
+ */
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_create(
+ struct nb_cb_create_args *args)
+{
+ return static_path_list_create(args);
+}
+
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_destroy(
+ struct nb_cb_destroy_args *args)
+{
+ const struct lyd_node *rn_dnode;
+ struct route_node *rn;
+ struct stable_info *info;
+
+ switch (args->event) {
+ case NB_EV_VALIDATE:
+ case NB_EV_PREPARE:
+ case NB_EV_ABORT:
+ break;
+ case NB_EV_APPLY:
+ rn_dnode = yang_dnode_get_parent(args->dnode, "route-list");
+ rn = nb_running_get_entry(rn_dnode, NULL, true);
+ info = route_table_get_info(rn->table);
+ static_path_list_destroy(args, rn_dnode, info);
+ break;
+ }
+ return NB_OK;
+}
+
+/*
+ * XPath:
+ * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/path-list/tag
+ */
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_tag_modify(
+ struct nb_cb_modify_args *args)
+{
+ struct stable_info *info;
+ struct route_node *rn;
+ const struct lyd_node *rn_dnode;
+
+ switch (args->event) {
+ case NB_EV_VALIDATE:
+ case NB_EV_ABORT:
+ case NB_EV_PREPARE:
+ break;
+ case NB_EV_APPLY:
+ rn_dnode = yang_dnode_get_parent(args->dnode, "route-list");
+ rn = nb_running_get_entry(rn_dnode, NULL, true);
+ info = route_table_get_info(rn->table);
+ static_path_list_tag_modify(args, rn_dnode, info);
+ break;
+ }
+
+ return NB_OK;
+}
+
+/*
+ * XPath:
+ * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/path-list/table-id
+ */
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_table_id_modify(
+ struct nb_cb_modify_args *args)
+{
+ struct route_node *rn;
+ const struct lyd_node *rn_dnode;
+ struct stable_info *info;
+
+ switch (args->event) {
+ case NB_EV_VALIDATE:
+ if (static_path_list_tableid_modify(args, NULL, NULL) != NB_OK)
+ return NB_ERR_VALIDATION;
+ break;
+ case NB_EV_PREPARE:
+ case NB_EV_ABORT:
+ break;
+ case NB_EV_APPLY:
+ rn_dnode = yang_dnode_get_parent(args->dnode, "route-list");
+ rn = nb_running_get_entry(rn_dnode, NULL, true);
+ info = route_table_get_info(rn->table);
+
+ if (static_path_list_tableid_modify(args, rn_dnode, info)
+ != NB_OK)
+ return NB_ERR_VALIDATION;
+ break;
+ }
+ return NB_OK;
+}
+
+/*
+ * XPath:
+ * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/path-list/frr-nexthops/nexthop
+ */
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_create(
+ struct nb_cb_create_args *args)
+{
+ struct route_node *rn;
+ const struct lyd_node *rn_dnode;
+ struct stable_info *info;
+
+ switch (args->event) {
+ case NB_EV_VALIDATE:
+ rn_dnode = yang_dnode_get_parent(args->dnode, "route-list");
+ if (static_nexthop_create(args, rn_dnode, NULL) != NB_OK)
+ return NB_ERR_VALIDATION;
+ break;
+ case NB_EV_PREPARE:
+ case NB_EV_ABORT:
+ break;
+ case NB_EV_APPLY:
+ rn_dnode = yang_dnode_get_parent(args->dnode, "route-list");
+ rn = nb_running_get_entry(rn_dnode, NULL, true);
+ info = route_table_get_info(rn->table);
+
+ if (static_nexthop_create(args, rn_dnode, info) != NB_OK)
+ return NB_ERR_VALIDATION;
+ break;
+ }
+ return NB_OK;
+}
+
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_destroy(
+ struct nb_cb_destroy_args *args)
+{
+ struct route_node *rn;
+ const struct lyd_node *rn_dnode;
+ struct stable_info *info;
+
+ switch (args->event) {
+ case NB_EV_VALIDATE:
+ case NB_EV_PREPARE:
+ case NB_EV_ABORT:
+ break;
+ case NB_EV_APPLY:
+ rn_dnode = yang_dnode_get_parent(args->dnode, "route-list");
+ rn = nb_running_get_entry(rn_dnode, NULL, true);
+ info = route_table_get_info(rn->table);
+
+ if (static_nexthop_destroy(args, rn_dnode, info) != NB_OK)
+ return NB_ERR;
+ break;
+ }
+ return NB_OK;
+}
+
+/*
+ * XPath:
+ * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/path-list/frr-nexthops/nexthop/bh-type
+ */
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_bh_type_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_bh_type_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_bh_type_destroy(
+ struct nb_cb_destroy_args *args)
+{
+ /* blackhole type has a boolean type with default value,
+ * so no need to do any operations in destroy callback
+ */
+ 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/onlink
+ */
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_onlink_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_onlink_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_onlink_destroy(
+ struct nb_cb_destroy_args *args)
+{
+ /* onlink has a boolean type with default value,
+ * so no need to do any operations in destroy callback
+ */
+ 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
+ */
+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)
+{
+ return nexthop_mpls_label_stack_entry_create(args);
+}
+
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_destroy(
+ struct nb_cb_destroy_args *args)
+{
+ return nexthop_mpls_label_stack_entry_destroy(args);
+}
+
+/*
+ * XPath:
+ * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/path-list/frr-nexthops/nexthop/mpls-label-stack/entry/label
+ */
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_label_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_mpls_label_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_mpls_label_stack_entry_label_destroy(
+ struct nb_cb_destroy_args *args)
+{
+ /*
+ * No operation is required in this call back.
+ * nexthop_mpls_label_stack_entry_destroy() will take care
+ * to reset the label 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/ttl
+ */
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_ttl_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 routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_ttl_destroy(
+ struct nb_cb_destroy_args *args)
+{
+ switch (args->event) {
+ case NB_EV_VALIDATE:
+ case NB_EV_PREPARE:
+ case NB_EV_ABORT:
+ case NB_EV_APPLY:
+ 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/traffic-class
+ */
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_traffic_class_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 routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_traffic_class_destroy(
+ struct nb_cb_destroy_args *args)
+{
+ switch (args->event) {
+ case NB_EV_VALIDATE:
+ case NB_EV_PREPARE:
+ case NB_EV_ABORT:
+ case NB_EV_APPLY:
+ break;
+ }
+
+ return NB_OK;
+}
+
+/*
+ * XPath:
+ * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/src-list
+ */
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_create(
+ struct nb_cb_create_args *args)
+{
+ struct static_vrf *s_vrf;
+ struct route_node *rn;
+ struct route_node *src_rn;
+ struct prefix_ipv6 src_prefix = {};
+ struct stable_info *info;
+ afi_t afi;
+ safi_t safi = SAFI_UNICAST;
+
+ switch (args->event) {
+ case NB_EV_VALIDATE:
+ case NB_EV_PREPARE:
+ case NB_EV_ABORT:
+ break;
+ case NB_EV_APPLY:
+ 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");
+ afi = family2afi(src_prefix.family);
+ src_rn =
+ static_add_route(afi, safi, &rn->p, &src_prefix, s_vrf);
+ if (!src_rn) {
+ flog_warn(EC_LIB_NB_CB_CONFIG_APPLY,
+ "src rn %s creation failed",
+ yang_dnode_get_string(args->dnode,
+ "./src-prefix"));
+ return NB_ERR;
+ }
+ nb_running_set_entry(args->dnode, src_rn);
+ break;
+ }
+ return NB_OK;
+}
+
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_destroy(
+ struct nb_cb_destroy_args *args)
+{
+ struct route_node *src_rn;
+ struct route_node *rn;
+ struct stable_info *info;
+ const struct lyd_node *rn_dnode;
+
+ switch (args->event) {
+ case NB_EV_VALIDATE:
+ case NB_EV_PREPARE:
+ case NB_EV_ABORT:
+ break;
+ case NB_EV_APPLY:
+ src_rn = nb_running_unset_entry(args->dnode);
+ rn_dnode = yang_dnode_get_parent(args->dnode, "route-list");
+ rn = nb_running_get_entry(rn_dnode, NULL, true);
+ info = route_table_get_info(rn->table);
+ static_del_route(src_rn, info->safi, info->svrf);
+ break;
+ }
+
+ return NB_OK;
+}
+
+/*
+ * XPath:
+ * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/src-list/path-list
+ */
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_create(
+ struct nb_cb_create_args *args)
+{
+ return static_path_list_create(args);
+}
+
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_destroy(
+ struct nb_cb_destroy_args *args)
+{
+ struct route_node *rn;
+ const struct lyd_node *rn_dnode;
+ const struct lyd_node *srn_dnode;
+ struct stable_info *info;
+
+ switch (args->event) {
+ case NB_EV_VALIDATE:
+ case NB_EV_PREPARE:
+ case NB_EV_ABORT:
+ break;
+ case NB_EV_APPLY:
+ srn_dnode = yang_dnode_get_parent(args->dnode, "src-list");
+ rn_dnode = yang_dnode_get_parent(srn_dnode, "route-list");
+ rn = nb_running_get_entry(rn_dnode, NULL, true);
+ info = route_table_get_info(rn->table);
+ static_path_list_destroy(args, srn_dnode, info);
+ break;
+ }
+ return NB_OK;
+}
+
+/*
+ * XPath:
+ * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/src-list/path-list/tag
+ */
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_tag_modify(
+ struct nb_cb_modify_args *args)
+{
+ struct stable_info *info;
+ struct route_node *rn;
+ const struct lyd_node *srn_dnode;
+ const struct lyd_node *rn_dnode;
+
+ switch (args->event) {
+ case NB_EV_VALIDATE:
+ case NB_EV_ABORT:
+ case NB_EV_PREPARE:
+ break;
+ case NB_EV_APPLY:
+ srn_dnode = yang_dnode_get_parent(args->dnode, "src-list");
+ rn_dnode = yang_dnode_get_parent(srn_dnode, "route-list");
+ rn = nb_running_get_entry(rn_dnode, NULL, true);
+ info = route_table_get_info(rn->table);
+ static_path_list_tag_modify(args, srn_dnode, info);
+ break;
+ }
+ return NB_OK;
+}
+
+/*
+ * XPath:
+ * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/src-list/path-list/table-id
+ */
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_table_id_modify(
+ struct nb_cb_modify_args *args)
+{
+ struct route_node *rn;
+ const struct lyd_node *rn_dnode;
+ const struct lyd_node *src_dnode;
+ struct stable_info *info;
+
+ switch (args->event) {
+ case NB_EV_VALIDATE:
+ if (static_path_list_tableid_modify(args, NULL, NULL) != NB_OK)
+ return NB_ERR_VALIDATION;
+ break;
+ case NB_EV_PREPARE:
+ case NB_EV_ABORT:
+ break;
+ case NB_EV_APPLY:
+ src_dnode = yang_dnode_get_parent(args->dnode, "src-list");
+ rn_dnode = yang_dnode_get_parent(src_dnode, "route-list");
+ rn = nb_running_get_entry(rn_dnode, NULL, true);
+ info = route_table_get_info(rn->table);
+
+ if (static_path_list_tableid_modify(args, src_dnode, info)
+ != NB_OK)
+ return NB_ERR_VALIDATION;
+
+ 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
+ */
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_create(
+ struct nb_cb_create_args *args)
+{
+ struct route_node *rn;
+ const struct lyd_node *rn_dnode;
+ const struct lyd_node *src_dnode;
+ struct stable_info *info;
+
+ switch (args->event) {
+ case NB_EV_VALIDATE:
+ rn_dnode = yang_dnode_get_parent(args->dnode, "route-list");
+ if (static_nexthop_create(args, rn_dnode, NULL) != NB_OK)
+ return NB_ERR_VALIDATION;
+ break;
+ case NB_EV_PREPARE:
+ case NB_EV_ABORT:
+ break;
+ case NB_EV_APPLY:
+ src_dnode = yang_dnode_get_parent(args->dnode, "src-list");
+ rn_dnode = yang_dnode_get_parent(src_dnode, "route-list");
+ rn = nb_running_get_entry(rn_dnode, NULL, true);
+ info = route_table_get_info(rn->table);
+
+ if (static_nexthop_create(args, src_dnode, info) != NB_OK)
+ return NB_ERR_VALIDATION;
+
+ break;
+ }
+ return NB_OK;
+}
+
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_destroy(
+ struct nb_cb_destroy_args *args)
+{
+ struct route_node *rn;
+ const struct lyd_node *rn_dnode;
+ const struct lyd_node *src_dnode;
+ struct stable_info *info;
+
+ switch (args->event) {
+ case NB_EV_VALIDATE:
+ case NB_EV_PREPARE:
+ case NB_EV_ABORT:
+ break;
+ case NB_EV_APPLY:
+ src_dnode = yang_dnode_get_parent(args->dnode, "src-list");
+ rn_dnode = yang_dnode_get_parent(src_dnode, "route-list");
+ rn = nb_running_get_entry(rn_dnode, NULL, true);
+ info = route_table_get_info(rn->table);
+
+ if (static_nexthop_destroy(args, rn_dnode, info) != NB_OK)
+ return NB_ERR;
+ 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/bh-type
+ */
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_bh_type_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_bh_type_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_bh_type_destroy(
+ struct nb_cb_destroy_args *args)
+{
+ /* blackhole type has a boolean type with default value,
+ * so no need to do any operations in destroy callback
+ */
+ 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/onlink
+ */
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_onlink_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_onlink_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_onlink_destroy(
+ struct nb_cb_destroy_args *args)
+{
+ /* onlink has a boolean type with default value,
+ * so no need to do any operations in destroy callback
+ */
+ 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
+ */
+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)
+{
+ return nexthop_mpls_label_stack_entry_create(args);
+}
+
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_destroy(
+ struct nb_cb_destroy_args *args)
+{
+ return nexthop_mpls_label_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/mpls-label-stack/entry/label
+ */
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_label_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_mpls_label_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_mpls_label_stack_entry_label_destroy(
+ struct nb_cb_destroy_args *args)
+{
+ /*
+ * No operation is required in this call back.
+ * nexthop_mpls_label_stack_entry_destroy() will take care
+ * to reset the label 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/ttl
+ */
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_ttl_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 routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_ttl_destroy(
+ struct nb_cb_destroy_args *args)
+{
+ switch (args->event) {
+ case NB_EV_VALIDATE:
+ case NB_EV_PREPARE:
+ case NB_EV_ABORT:
+ case NB_EV_APPLY:
+ 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/traffic-class
+ */
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_traffic_class_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 routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_traffic_class_destroy(
+ struct nb_cb_destroy_args *args)
+{
+ switch (args->event) {
+ case NB_EV_VALIDATE:
+ case NB_EV_PREPARE:
+ case NB_EV_ABORT:
+ case NB_EV_APPLY:
+ break;
+ }
+
+ return NB_OK;
+}
diff --git a/staticd/static_nht.c b/staticd/static_nht.c
index 1a2ddd7f05..feb6e0f993 100644
--- a/staticd/static_nht.c
+++ b/staticd/static_nht.c
@@ -30,33 +30,33 @@
#include "static_zebra.h"
#include "static_nht.h"
-static void static_nht_update_rn(struct route_node *rn,
- struct prefix *nhp, uint32_t nh_num,
- vrf_id_t nh_vrf_id, struct vrf *vrf,
- safi_t safi)
+static void static_nht_update_path(struct route_node *rn,
+ struct static_path *pn, struct prefix *nhp,
+ uint32_t nh_num, vrf_id_t nh_vrf_id,
+ struct vrf *vrf, safi_t safi)
{
- struct static_route *si;
+ struct static_nexthop *nh;
- for (si = rn->info; si; si = si->next) {
- if (si->nh_vrf_id != nh_vrf_id)
+ frr_each(static_nexthop_list, &pn->nexthop_list, nh) {
+ if (nh->nh_vrf_id != nh_vrf_id)
continue;
- if (si->type != STATIC_IPV4_GATEWAY
- && si->type != STATIC_IPV4_GATEWAY_IFNAME
- && si->type != STATIC_IPV6_GATEWAY
- && si->type != STATIC_IPV6_GATEWAY_IFNAME)
+ if (nh->type != STATIC_IPV4_GATEWAY
+ && nh->type != STATIC_IPV4_GATEWAY_IFNAME
+ && nh->type != STATIC_IPV6_GATEWAY
+ && nh->type != STATIC_IPV6_GATEWAY_IFNAME)
continue;
if (nhp->family == AF_INET
- && nhp->u.prefix4.s_addr == si->addr.ipv4.s_addr)
- si->nh_valid = !!nh_num;
+ && nhp->u.prefix4.s_addr == nh->addr.ipv4.s_addr)
+ nh->nh_valid = !!nh_num;
if (nhp->family == AF_INET6
- && memcmp(&nhp->u.prefix6, &si->addr.ipv6, 16) == 0)
- si->nh_valid = !!nh_num;
+ && memcmp(&nhp->u.prefix6, &nh->addr.ipv6, 16) == 0)
+ nh->nh_valid = !!nh_num;
- if (si->state == STATIC_START)
- static_zebra_route_add(rn, si, vrf->vrf_id, safi, true);
+ if (nh->state == STATIC_START)
+ static_zebra_route_add(rn, pn, safi, true);
}
}
@@ -67,6 +67,8 @@ static void static_nht_update_safi(struct prefix *sp, struct prefix *nhp,
struct route_table *stable;
struct static_vrf *svrf;
struct route_node *rn;
+ struct static_path *pn;
+ struct static_route_info *si;
svrf = vrf->info;
if (!svrf)
@@ -78,17 +80,26 @@ static void static_nht_update_safi(struct prefix *sp, struct prefix *nhp,
if (sp) {
rn = srcdest_rnode_lookup(stable, sp, NULL);
- if (rn) {
- static_nht_update_rn(rn, nhp, nh_num, nh_vrf_id,
- vrf, safi);
+ if (rn && rn->info) {
+ si = static_route_info_from_rnode(rn);
+ frr_each(static_path_list, &si->path_list, pn) {
+ static_nht_update_path(rn, pn, nhp, nh_num,
+ nh_vrf_id, vrf, safi);
+ }
route_unlock_node(rn);
}
return;
}
- for (rn = route_top(stable); rn; rn = route_next(rn))
- static_nht_update_rn(rn, nhp, nh_num, nh_vrf_id, vrf, safi);
-
+ for (rn = route_top(stable); rn; rn = route_next(rn)) {
+ si = static_route_info_from_rnode(rn);
+ if (!si)
+ continue;
+ frr_each(static_path_list, &si->path_list, pn) {
+ static_nht_update_path(rn, pn, nhp, nh_num, nh_vrf_id,
+ vrf, safi);
+ }
+ }
}
void static_nht_update(struct prefix *sp, struct prefix *nhp,
@@ -111,8 +122,10 @@ static void static_nht_reset_start_safi(struct prefix *nhp, afi_t afi,
{
struct static_vrf *svrf;
struct route_table *stable;
- struct static_route *si;
+ struct static_nexthop *nh;
+ struct static_path *pn;
struct route_node *rn;
+ struct static_route_info *si;
svrf = vrf->info;
if (!svrf)
@@ -123,25 +136,33 @@ static void static_nht_reset_start_safi(struct prefix *nhp, afi_t afi,
return;
for (rn = route_top(stable); rn; rn = route_next(rn)) {
- for (si = rn->info; si; si = si->next) {
- if (si->nh_vrf_id != nh_vrf_id)
- continue;
-
- if (nhp->family == AF_INET
- && nhp->u.prefix4.s_addr != si->addr.ipv4.s_addr)
- continue;
-
- if (nhp->family == AF_INET6
- && memcmp(&nhp->u.prefix6, &si->addr.ipv6, 16) != 0)
- continue;
-
- /*
- * We've been told that a nexthop we depend
- * on has changed in some manner, so reset
- * the state machine to allow us to start
- * over.
- */
- si->state = STATIC_START;
+ si = static_route_info_from_rnode(rn);
+ if (!si)
+ continue;
+ frr_each(static_path_list, &si->path_list, pn) {
+ frr_each(static_nexthop_list, &pn->nexthop_list, nh) {
+ if (nh->nh_vrf_id != nh_vrf_id)
+ continue;
+
+ if (nhp->family == AF_INET
+ && nhp->u.prefix4.s_addr
+ != nh->addr.ipv4.s_addr)
+ continue;
+
+ if (nhp->family == AF_INET6
+ && memcmp(&nhp->u.prefix6, &nh->addr.ipv6,
+ 16)
+ != 0)
+ continue;
+
+ /*
+ * We've been told that a nexthop we
+ * depend on has changed in some manner,
+ * so reset the state machine to allow
+ * us to start over.
+ */
+ nh->state = STATIC_START;
+ }
}
}
}
@@ -164,8 +185,10 @@ static void static_nht_mark_state_safi(struct prefix *sp, afi_t afi,
{
struct static_vrf *svrf;
struct route_table *stable;
- struct static_route *si;
struct route_node *rn;
+ struct static_nexthop *nh;
+ struct static_path *pn;
+ struct static_route_info *si;
svrf = vrf->info;
if (!svrf)
@@ -178,9 +201,14 @@ static void static_nht_mark_state_safi(struct prefix *sp, afi_t afi,
rn = srcdest_rnode_lookup(stable, sp, NULL);
if (!rn)
return;
-
- for (si = rn->info; si; si = si->next)
- si->state = state;
+ si = rn->info;
+ if (si) {
+ frr_each(static_path_list, &si->path_list, pn) {
+ frr_each(static_nexthop_list, &pn->nexthop_list, nh) {
+ nh->state = state;
+ }
+ }
+ }
route_unlock_node(rn);
}
diff --git a/staticd/static_routes.c b/staticd/static_routes.c
index e8d6a4289b..3836109e36 100644
--- a/staticd/static_routes.c
+++ b/staticd/static_routes.c
@@ -32,267 +32,366 @@
#include "static_memory.h"
#include "static_zebra.h"
-/* Install static route into rib. */
-static void static_install_route(struct route_node *rn,
- struct static_route *si_changed, safi_t safi)
-{
- struct static_route *si;
+DEFINE_MTYPE_STATIC(STATIC, STATIC_ROUTE, "Static Route Info");
+DEFINE_MTYPE(STATIC, STATIC_PATH, "Static Path");
- for (si = rn->info; si; si = si->next)
- static_zebra_nht_register(rn, si, true);
+/* Install static path into rib. */
+void static_install_path(struct route_node *rn, struct static_path *pn,
+ safi_t safi, struct static_vrf *svrf)
+{
+ struct static_nexthop *nh;
- si = rn->info;
- if (si)
- static_zebra_route_add(rn, si_changed, si->vrf_id, safi, true);
+ frr_each(static_nexthop_list, &pn->nexthop_list, nh)
+ static_zebra_nht_register(rn, nh, true);
+ if (static_nexthop_list_count(&pn->nexthop_list) && svrf && svrf->vrf)
+ static_zebra_route_add(rn, pn, safi, true);
}
-/* Uninstall static route from RIB. */
-static void static_uninstall_route(vrf_id_t vrf_id, safi_t safi,
- struct route_node *rn,
- struct static_route *si_changed)
+/* Uninstall static path from RIB. */
+static void static_uninstall_path(struct route_node *rn, struct static_path *pn,
+ safi_t safi, struct static_vrf *svrf)
{
-
- if (rn->info)
- static_zebra_route_add(rn, si_changed, vrf_id, safi, true);
+ if (static_nexthop_list_count(&pn->nexthop_list))
+ static_zebra_route_add(rn, pn, safi, true);
else
- static_zebra_route_add(rn, si_changed, vrf_id, safi, false);
+ static_zebra_route_add(rn, pn, safi, false);
}
-int static_add_route(afi_t afi, safi_t safi, uint8_t type, struct prefix *p,
- struct prefix_ipv6 *src_p, union g_addr *gate,
- const char *ifname, enum static_blackhole_type bh_type,
- route_tag_t tag, uint8_t distance, struct static_vrf *svrf,
- struct static_vrf *nh_svrf,
- struct static_nh_label *snh_label, uint32_t table_id,
- bool onlink)
+struct route_node *static_add_route(afi_t afi, safi_t safi, struct prefix *p,
+ struct prefix_ipv6 *src_p,
+ struct static_vrf *svrf)
{
struct route_node *rn;
- struct static_route *si;
- struct static_route *pp;
- struct static_route *cp;
- struct static_route *update = NULL;
+ struct static_route_info *si;
struct route_table *stable = svrf->stable[afi][safi];
- struct interface *ifp;
if (!stable)
- return -1;
-
- if (!gate && (type == STATIC_IPV4_GATEWAY
- || type == STATIC_IPV4_GATEWAY_IFNAME
- || type == STATIC_IPV6_GATEWAY
- || type == STATIC_IPV6_GATEWAY_IFNAME))
- return -1;
-
- if (!ifname
- && (type == STATIC_IFNAME || type == STATIC_IPV4_GATEWAY_IFNAME
- || type == STATIC_IPV6_GATEWAY_IFNAME))
- return -1;
+ return NULL;
/* Lookup static route prefix. */
rn = srcdest_rnode_get(stable, p, src_p);
- /* Do nothing if there is a same static route. */
- for (si = rn->info; si; si = si->next) {
- if (type == si->type
- && (!gate
- || ((afi == AFI_IP
- && IPV4_ADDR_SAME(&gate->ipv4, &si->addr.ipv4))
- || (afi == AFI_IP6
- && IPV6_ADDR_SAME(gate, &si->addr.ipv6))))
- && (!strcmp(ifname ? ifname : "", si->ifname))
- && nh_svrf->vrf->vrf_id == si->nh_vrf_id) {
- if ((distance == si->distance) && (tag == si->tag)
- && (table_id == si->table_id)
- && !memcmp(&si->snh_label, snh_label,
- sizeof(struct static_nh_label))
- && si->bh_type == bh_type && si->onlink == onlink) {
- route_unlock_node(rn);
- return 0;
- }
- update = si;
+ si = XCALLOC(MTYPE_STATIC_ROUTE, sizeof(struct static_route_info));
+ static_route_info_init(si);
+
+ rn->info = si;
+
+ /* Mark as having FRR configuration */
+ vrf_set_user_cfged(svrf->vrf);
+
+ return rn;
+}
+
+/* To delete the srcnodes */
+static void static_del_src_route(struct route_node *rn, safi_t safi,
+ struct static_vrf *svrf)
+{
+ struct static_path *pn;
+ struct static_route_info *si;
+
+ si = rn->info;
+
+ frr_each_safe(static_path_list, &si->path_list, pn) {
+ static_del_path(rn, pn, safi, svrf);
+ }
+
+ XFREE(MTYPE_STATIC_ROUTE, rn->info);
+ route_unlock_node(rn);
+ /* If no other FRR config for this VRF, mark accordingly. */
+ if (!static_vrf_has_config(svrf))
+ vrf_reset_user_cfged(svrf->vrf);
+}
+
+void static_del_route(struct route_node *rn, safi_t safi,
+ struct static_vrf *svrf)
+{
+ struct static_path *pn;
+ struct static_route_info *si;
+ struct route_table *src_table;
+ struct route_node *src_node;
+
+ si = rn->info;
+
+ frr_each_safe(static_path_list, &si->path_list, pn) {
+ static_del_path(rn, pn, safi, svrf);
+ }
+
+ /* clean up for dst table */
+ src_table = srcdest_srcnode_table(rn);
+ if (src_table) {
+ /* This means the route_node is part of the top hierarchy
+ * and refers to a destination prefix.
+ */
+ for (src_node = route_top(src_table); src_node;
+ src_node = route_next(src_node)) {
+ static_del_src_route(src_node, safi, svrf);
}
}
+ XFREE(MTYPE_STATIC_ROUTE, rn->info);
+ route_unlock_node(rn);
+ /* If no other FRR config for this VRF, mark accordingly. */
+ if (!static_vrf_has_config(svrf))
+ vrf_reset_user_cfged(svrf->vrf);
+}
+
+bool static_add_nexthop_validate(struct static_vrf *svrf, static_types type,
+ struct ipaddr *ipaddr)
+{
+ switch (type) {
+ case STATIC_IPV4_GATEWAY:
+ case STATIC_IPV4_GATEWAY_IFNAME:
+ if (if_lookup_exact_address(&ipaddr->ipaddr_v4, AF_INET,
+ svrf->vrf->vrf_id))
+ return false;
+ break;
+ case STATIC_IPV6_GATEWAY:
+ case STATIC_IPV6_GATEWAY_IFNAME:
+ if (if_lookup_exact_address(&ipaddr->ipaddr_v6, AF_INET6,
+ svrf->vrf->vrf_id))
+ return false;
+ break;
+ default:
+ break;
+ }
- /* Distance or tag or label changed, delete existing first. */
- if (update)
- static_delete_route(afi, safi, type, p, src_p, gate, ifname,
- update->tag, update->distance, svrf,
- &update->snh_label, table_id);
+ return true;
+}
+
+struct static_path *static_add_path(struct route_node *rn, uint8_t distance)
+{
+ struct static_path *pn;
+ struct static_route_info *si;
+
+ route_lock_node(rn);
/* Make new static route structure. */
- si = XCALLOC(MTYPE_STATIC_ROUTE, sizeof(struct static_route));
-
- si->type = type;
- si->distance = distance;
- si->bh_type = bh_type;
- si->tag = tag;
- si->vrf_id = svrf->vrf->vrf_id;
- si->nh_vrf_id = nh_svrf->vrf->vrf_id;
- strlcpy(si->nh_vrfname, nh_svrf->vrf->name, sizeof(si->nh_vrfname));
- si->table_id = table_id;
- si->onlink = onlink;
+ pn = XCALLOC(MTYPE_STATIC_PATH, sizeof(struct static_path));
+
+ pn->distance = distance;
+ static_nexthop_list_init(&(pn->nexthop_list));
+
+ si = rn->info;
+ static_path_list_add_head(&(si->path_list), pn);
+
+ return pn;
+}
+
+void static_del_path(struct route_node *rn, struct static_path *pn, safi_t safi,
+ struct static_vrf *svrf)
+{
+ struct static_route_info *si;
+ struct static_nexthop *nh;
+
+ si = rn->info;
+
+ static_path_list_del(&si->path_list, pn);
+
+ frr_each_safe(static_nexthop_list, &pn->nexthop_list, nh) {
+ static_delete_nexthop(rn, pn, safi, svrf, nh);
+ }
+
+ route_unlock_node(rn);
+
+ XFREE(MTYPE_STATIC_PATH, pn);
+}
+
+struct static_nexthop *
+static_add_nexthop(struct route_node *rn, struct static_path *pn, safi_t safi,
+ struct static_vrf *svrf, static_types type,
+ struct ipaddr *ipaddr, const char *ifname,
+ const char *nh_vrf)
+{
+ struct static_nexthop *nh;
+ struct static_vrf *nh_svrf;
+ struct interface *ifp;
+ struct static_nexthop *cp;
+
+ route_lock_node(rn);
+
+ nh_svrf = static_vty_get_unknown_vrf(nh_vrf);
+
+ if (!nh_svrf)
+ return NULL;
+
+ /* Make new static route structure. */
+ nh = XCALLOC(MTYPE_STATIC_NEXTHOP, sizeof(struct static_nexthop));
+
+ nh->type = type;
+
+ nh->nh_vrf_id = nh_svrf->vrf->vrf_id;
+ strlcpy(nh->nh_vrfname, nh_svrf->vrf->name, sizeof(nh->nh_vrfname));
if (ifname)
- strlcpy(si->ifname, ifname, sizeof(si->ifname));
- si->ifindex = IFINDEX_INTERNAL;
+ strlcpy(nh->ifname, ifname, sizeof(nh->ifname));
+ nh->ifindex = IFINDEX_INTERNAL;
switch (type) {
case STATIC_IPV4_GATEWAY:
case STATIC_IPV4_GATEWAY_IFNAME:
- si->addr.ipv4 = gate->ipv4;
+ nh->addr.ipv4 = ipaddr->ipaddr_v4;
break;
case STATIC_IPV6_GATEWAY:
case STATIC_IPV6_GATEWAY_IFNAME:
- si->addr.ipv6 = gate->ipv6;
+ nh->addr.ipv6 = ipaddr->ipaddr_v6;
break;
- case STATIC_IFNAME:
+ default:
break;
}
-
- /* Save labels, if any. */
- memcpy(&si->snh_label, snh_label, sizeof(struct static_nh_label));
-
/*
* Add new static route information to the tree with sort by
- * distance value and gateway address.
+ * gateway address.
*/
- for (pp = NULL, cp = rn->info; cp; pp = cp, cp = cp->next) {
- if (si->distance < cp->distance)
- break;
- if (si->distance > cp->distance)
- continue;
- if (si->type == STATIC_IPV4_GATEWAY
+ frr_each(static_nexthop_list, &pn->nexthop_list, cp) {
+ if (nh->type == STATIC_IPV4_GATEWAY
&& cp->type == STATIC_IPV4_GATEWAY) {
- if (ntohl(si->addr.ipv4.s_addr)
+ if (ntohl(nh->addr.ipv4.s_addr)
< ntohl(cp->addr.ipv4.s_addr))
break;
- if (ntohl(si->addr.ipv4.s_addr)
+ if (ntohl(nh->addr.ipv4.s_addr)
> ntohl(cp->addr.ipv4.s_addr))
continue;
}
}
+ static_nexthop_list_add_after(&(pn->nexthop_list), cp, nh);
- /* Make linked list. */
- if (pp)
- pp->next = si;
- else
- rn->info = si;
- if (cp)
- cp->prev = si;
- si->prev = pp;
- si->next = cp;
+ if (nh_svrf->vrf->vrf_id == VRF_UNKNOWN)
+ return nh;
/* check whether interface exists in system & install if it does */
- switch (si->type) {
+ switch (nh->type) {
case STATIC_IPV4_GATEWAY:
case STATIC_IPV6_GATEWAY:
- static_zebra_nht_register(rn, si, true);
break;
case STATIC_IPV4_GATEWAY_IFNAME:
case STATIC_IPV6_GATEWAY_IFNAME:
- ifp = if_lookup_by_name(ifname, nh_svrf->vrf->vrf_id);
+ ifp = if_lookup_by_name(ifname, nh_svrf->vrf->vrf_id);
if (ifp && ifp->ifindex != IFINDEX_INTERNAL)
- si->ifindex = ifp->ifindex;
+ nh->ifindex = ifp->ifindex;
else
- zlog_warn("Static Route using %s interface not installed because the interface does not exist in specified vrf",
- ifname);
+ zlog_warn(
+ "Static Route using %s interface not installed because the interface does not exist in specified vrf",
+ ifname);
- static_zebra_nht_register(rn, si, true);
break;
case STATIC_BLACKHOLE:
- static_install_route(rn, si, safi);
break;
case STATIC_IFNAME:
ifp = if_lookup_by_name(ifname, nh_svrf->vrf->vrf_id);
if (ifp && ifp->ifindex != IFINDEX_INTERNAL) {
- si->ifindex = ifp->ifindex;
- static_install_route(rn, si, safi);
+ nh->ifindex = ifp->ifindex;
} else
- zlog_warn("Static Route using %s interface not installed because the interface does not exist in specified vrf",
- ifname);
-
+ zlog_warn(
+ "Static Route using %s interface not installed because the interface does not exist in specified vrf",
+ ifname);
break;
}
- return 1;
+ return nh;
}
-int static_delete_route(afi_t afi, safi_t safi, uint8_t type, struct prefix *p,
- struct prefix_ipv6 *src_p, union g_addr *gate,
- const char *ifname, route_tag_t tag, uint8_t distance,
- struct static_vrf *svrf,
- struct static_nh_label *snh_label,
- uint32_t table_id)
+void static_install_nexthop(struct route_node *rn, struct static_path *pn,
+ struct static_nexthop *nh, safi_t safi,
+ struct static_vrf *svrf, const char *ifname,
+ static_types type, const char *nh_vrf)
{
- struct route_node *rn;
- struct static_route *si;
- struct route_table *stable;
+ struct static_vrf *nh_svrf;
+ struct interface *ifp;
- /* Lookup table. */
- stable = static_vrf_static_table(afi, safi, svrf);
- if (!stable)
- return -1;
+ nh_svrf = static_vty_get_unknown_vrf(nh_vrf);
- /* Lookup static route prefix. */
- rn = srcdest_rnode_lookup(stable, p, src_p);
- if (!rn)
- return 0;
-
- /* Find same static route is the tree */
- for (si = rn->info; si; si = si->next)
- if (type == si->type
- && (!gate
- || ((afi == AFI_IP
- && IPV4_ADDR_SAME(&gate->ipv4, &si->addr.ipv4))
- || (afi == AFI_IP6
- && IPV6_ADDR_SAME(gate, &si->addr.ipv6))))
- && (!strcmp(ifname ? ifname : "", si->ifname))
- && (!tag || (tag == si->tag))
- && (table_id == si->table_id)
- && (!snh_label->num_labels
- || !memcmp(&si->snh_label, snh_label,
- sizeof(struct static_nh_label))))
- break;
-
- /* Can't find static route. */
- if (!si) {
- route_unlock_node(rn);
- return 0;
+ if (!nh_svrf)
+ return;
+
+ if (nh_svrf->vrf->vrf_id == VRF_UNKNOWN)
+ return;
+
+ /* check whether interface exists in system & install if it does */
+ switch (nh->type) {
+ case STATIC_IPV4_GATEWAY:
+ case STATIC_IPV6_GATEWAY:
+ if (!static_zebra_nh_update(rn, nh))
+ static_zebra_nht_register(rn, nh, true);
+ break;
+ case STATIC_IPV4_GATEWAY_IFNAME:
+ case STATIC_IPV6_GATEWAY_IFNAME:
+ if (!static_zebra_nh_update(rn, nh))
+ static_zebra_nht_register(rn, nh, true);
+ break;
+ case STATIC_BLACKHOLE:
+ static_install_path(rn, pn, safi, svrf);
+ break;
+ case STATIC_IFNAME:
+ ifp = if_lookup_by_name(ifname, nh_svrf->vrf->vrf_id);
+ if (ifp && ifp->ifindex != IFINDEX_INTERNAL)
+ static_install_path(rn, pn, safi, svrf);
+
+ break;
}
+}
- static_zebra_nht_register(rn, si, false);
+int static_delete_nexthop(struct route_node *rn, struct static_path *pn,
+ safi_t safi, struct static_vrf *svrf,
+ struct static_nexthop *nh)
+{
+ struct static_vrf *nh_svrf;
- /* Unlink static route from linked list. */
- if (si->prev)
- si->prev->next = si->next;
- else
- rn->info = si->next;
- if (si->next)
- si->next->prev = si->prev;
+ nh_svrf = static_vrf_lookup_by_name(nh->nh_vrfname);
+
+ static_nexthop_list_del(&(pn->nexthop_list), nh);
+ if (nh_svrf->vrf->vrf_id == VRF_UNKNOWN)
+ goto EXIT;
+
+ static_zebra_nht_register(rn, nh, false);
/*
* If we have other si nodes then route replace
* else delete the route
*/
- static_uninstall_route(si->vrf_id, safi, rn, si);
- route_unlock_node(rn);
-
- /* Free static route configuration. */
- XFREE(MTYPE_STATIC_ROUTE, si);
+ static_uninstall_path(rn, pn, safi, svrf);
+EXIT:
route_unlock_node(rn);
+ /* Free static route configuration. */
+ XFREE(MTYPE_STATIC_NEXTHOP, nh);
return 1;
}
+static void static_ifindex_update_nh(struct interface *ifp, bool up,
+ struct route_node *rn,
+ struct static_path *pn,
+ struct static_nexthop *nh,
+ struct static_vrf *svrf, safi_t safi)
+{
+ if (!nh->ifname[0])
+ return;
+ if (up) {
+ if (strcmp(nh->ifname, ifp->name))
+ return;
+ if (nh->nh_vrf_id != ifp->vrf_id)
+ return;
+ nh->ifindex = ifp->ifindex;
+ } else {
+ if (nh->ifindex != ifp->ifindex)
+ return;
+ if (nh->nh_vrf_id != ifp->vrf_id)
+ return;
+ nh->ifindex = IFINDEX_INTERNAL;
+ }
+
+ static_install_path(rn, pn, safi, svrf);
+}
+
static void static_ifindex_update_af(struct interface *ifp, bool up, afi_t afi,
safi_t safi)
{
struct route_table *stable;
struct route_node *rn;
- struct static_route *si;
+ struct static_nexthop *nh;
+ struct static_path *pn;
struct vrf *vrf;
+ struct static_route_info *si;
RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
struct static_vrf *svrf;
@@ -302,26 +401,17 @@ static void static_ifindex_update_af(struct interface *ifp, bool up, afi_t afi,
stable = static_vrf_static_table(afi, safi, svrf);
if (!stable)
continue;
-
for (rn = route_top(stable); rn; rn = srcdest_route_next(rn)) {
- for (si = rn->info; si; si = si->next) {
- if (!si->ifname[0])
- continue;
- if (up) {
- if (strcmp(si->ifname, ifp->name))
- continue;
- if (si->nh_vrf_id != ifp->vrf_id)
- continue;
- si->ifindex = ifp->ifindex;
- } else {
- if (si->ifindex != ifp->ifindex)
- continue;
- if (si->nh_vrf_id != ifp->vrf_id)
- continue;
- si->ifindex = IFINDEX_INTERNAL;
+ si = static_route_info_from_rnode(rn);
+ if (!si)
+ continue;
+ frr_each(static_path_list, &si->path_list, pn) {
+ frr_each(static_nexthop_list,
+ &pn->nexthop_list, nh) {
+ static_ifindex_update_nh(ifp, up, rn,
+ pn, nh, svrf,
+ safi);
}
-
- static_install_route(rn, si, safi);
}
}
}
@@ -343,26 +433,34 @@ static void static_fixup_vrf(struct static_vrf *svrf,
struct route_table *stable, afi_t afi, safi_t safi)
{
struct route_node *rn;
- struct static_route *si;
+ struct static_nexthop *nh;
struct interface *ifp;
+ struct static_path *pn;
+ struct static_route_info *si;
for (rn = route_top(stable); rn; rn = route_next(rn)) {
- for (si = rn->info; si; si = si->next) {
- if (strcmp(svrf->vrf->name, si->nh_vrfname) != 0)
- continue;
-
- si->nh_vrf_id = svrf->vrf->vrf_id;
- si->nh_registered = false;
- if (si->ifindex) {
- ifp = if_lookup_by_name(si->ifname,
- si->nh_vrf_id);
- if (ifp)
- si->ifindex = ifp->ifindex;
- else
+ si = static_route_info_from_rnode(rn);
+ if (!si)
+ continue;
+ frr_each(static_path_list, &si->path_list, pn) {
+ frr_each(static_nexthop_list, &pn->nexthop_list, nh) {
+ if (strcmp(svrf->vrf->name, nh->nh_vrfname)
+ != 0)
continue;
- }
- static_install_route(rn, si, safi);
+ nh->nh_vrf_id = svrf->vrf->vrf_id;
+ nh->nh_registered = false;
+ if (nh->ifindex) {
+ ifp = if_lookup_by_name(nh->ifname,
+ nh->nh_vrf_id);
+ if (ifp)
+ nh->ifindex = ifp->ifindex;
+ else
+ continue;
+ }
+
+ static_install_path(rn, pn, safi, svrf);
+ }
}
}
}
@@ -377,26 +475,31 @@ static void static_fixup_vrf(struct static_vrf *svrf,
* safi -> the safi in question
*/
static void static_enable_vrf(struct static_vrf *svrf,
- struct route_table *stable,
- afi_t afi, safi_t safi)
+ struct route_table *stable, afi_t afi,
+ safi_t safi)
{
struct route_node *rn;
- struct static_route *si;
+ struct static_nexthop *nh;
struct interface *ifp;
- struct vrf *vrf = svrf->vrf;
+ struct static_path *pn;
+ struct static_route_info *si;
for (rn = route_top(stable); rn; rn = route_next(rn)) {
- for (si = rn->info; si; si = si->next) {
- si->vrf_id = vrf->vrf_id;
- if (si->ifindex) {
- ifp = if_lookup_by_name(si->ifname,
- si->nh_vrf_id);
- if (ifp)
- si->ifindex = ifp->ifindex;
- else
- continue;
+ si = static_route_info_from_rnode(rn);
+ if (!si)
+ continue;
+ frr_each(static_path_list, &si->path_list, pn) {
+ frr_each(static_nexthop_list, &pn->nexthop_list, nh) {
+ if (nh->ifindex) {
+ ifp = if_lookup_by_name(nh->ifname,
+ nh->nh_vrf_id);
+ if (ifp)
+ nh->ifindex = ifp->ifindex;
+ else
+ continue;
+ }
+ static_install_path(rn, pn, safi, svrf);
}
- static_install_route(rn, si, safi);
}
}
}
@@ -452,14 +555,22 @@ static void static_cleanup_vrf(struct static_vrf *svrf,
afi_t afi, safi_t safi)
{
struct route_node *rn;
- struct static_route *si;
+ struct static_nexthop *nh;
+ struct static_path *pn;
+ struct static_route_info *si;
for (rn = route_top(stable); rn; rn = route_next(rn)) {
- for (si = rn->info; si; si = si->next) {
- if (strcmp(svrf->vrf->name, si->nh_vrfname) != 0)
- continue;
+ si = static_route_info_from_rnode(rn);
+ if (!si)
+ continue;
+ frr_each(static_path_list, &si->path_list, pn) {
+ frr_each(static_nexthop_list, &pn->nexthop_list, nh) {
+ if (strcmp(svrf->vrf->name, nh->nh_vrfname)
+ != 0)
+ continue;
- static_uninstall_route(si->vrf_id, safi, rn, si);
+ static_uninstall_path(rn, pn, safi, svrf);
+ }
}
}
}
@@ -476,11 +587,23 @@ static void static_disable_vrf(struct route_table *stable,
afi_t afi, safi_t safi)
{
struct route_node *rn;
- struct static_route *si;
+ struct static_nexthop *nh;
+ struct static_path *pn;
+ struct stable_info *info;
+ struct static_route_info *si;
+
+ info = route_table_get_info(stable);
- for (rn = route_top(stable); rn; rn = route_next(rn))
- for (si = rn->info; si; si = si->next)
- static_uninstall_route(si->vrf_id, safi, rn, si);
+ for (rn = route_top(stable); rn; rn = route_next(rn)) {
+ si = static_route_info_from_rnode(rn);
+ if (!si)
+ continue;
+ frr_each(static_path_list, &si->path_list, pn) {
+ frr_each(static_nexthop_list, &pn->nexthop_list, nh) {
+ static_uninstall_path(rn, pn, safi, info->svrf);
+ }
+ }
+ }
}
/*
@@ -535,17 +658,27 @@ static void static_fixup_intf_nh(struct route_table *stable,
afi_t afi, safi_t safi)
{
struct route_node *rn;
- struct static_route *si;
+ struct stable_info *info;
+ struct static_nexthop *nh;
+ struct static_path *pn;
+ struct static_route_info *si;
+
+ info = route_table_get_info(stable);
for (rn = route_top(stable); rn; rn = route_next(rn)) {
- for (si = rn->info; si; si = si->next) {
- if (si->nh_vrf_id != ifp->vrf_id)
- continue;
+ si = static_route_info_from_rnode(rn);
+ if (!si)
+ continue;
+ frr_each(static_path_list, &si->path_list, pn) {
+ frr_each(static_nexthop_list, &pn->nexthop_list, nh) {
+ if (nh->nh_vrf_id != ifp->vrf_id)
+ continue;
- if (si->ifindex != ifp->ifindex)
- continue;
+ if (nh->ifindex != ifp->ifindex)
+ continue;
- static_install_route(rn, si, safi);
+ static_install_path(rn, pn, safi, info->svrf);
+ }
}
}
}
@@ -589,3 +722,40 @@ void static_ifindex_update(struct interface *ifp, bool up)
static_ifindex_update_af(ifp, up, AFI_IP6, SAFI_UNICAST);
static_ifindex_update_af(ifp, up, AFI_IP6, SAFI_MULTICAST);
}
+
+void static_get_nh_type(static_types stype, char *type, size_t size)
+{
+ switch (stype) {
+ case STATIC_IFNAME:
+ strlcpy(type, "ifindex", size);
+ break;
+ case STATIC_IPV4_GATEWAY:
+ strlcpy(type, "ip4", size);
+ break;
+ case STATIC_IPV4_GATEWAY_IFNAME:
+ strlcpy(type, "ip4-ifindex", size);
+ break;
+ case STATIC_BLACKHOLE:
+ strlcpy(type, "blackhole", size);
+ break;
+ case STATIC_IPV6_GATEWAY:
+ strlcpy(type, "ip6", size);
+ break;
+ case STATIC_IPV6_GATEWAY_IFNAME:
+ strlcpy(type, "ip6-ifindex", size);
+ break;
+ };
+}
+
+struct stable_info *static_get_stable_info(struct route_node *rn)
+{
+ struct route_table *table;
+
+ table = srcdest_rnode_table(rn);
+ return table->info;
+}
+
+void static_route_info_init(struct static_route_info *si)
+{
+ static_path_list_init(&(si->path_list));
+}
diff --git a/staticd/static_routes.h b/staticd/static_routes.h
index 6414947b16..89ef544023 100644
--- a/staticd/static_routes.h
+++ b/staticd/static_routes.h
@@ -21,6 +21,7 @@
#define __STATIC_ROUTES_H__
#include "lib/mpls.h"
+#include "table.h"
/* Static route label information */
struct static_nh_label {
@@ -35,13 +36,17 @@ enum static_blackhole_type {
STATIC_BLACKHOLE_REJECT
};
+/*
+ * The order for below macros should be in sync with
+ * yang model typedef nexthop-type
+ */
typedef enum {
- STATIC_IFNAME,
+ STATIC_IFNAME = 1,
STATIC_IPV4_GATEWAY,
STATIC_IPV4_GATEWAY_IFNAME,
- STATIC_BLACKHOLE,
STATIC_IPV6_GATEWAY,
STATIC_IPV6_GATEWAY_IFNAME,
+ STATIC_BLACKHOLE,
} static_types;
/*
@@ -64,14 +69,37 @@ enum static_install_states {
STATIC_NOT_INSTALLED,
};
+PREDECL_DLIST(static_path_list);
+PREDECL_DLIST(static_nexthop_list);
+
+/* Static route information */
+struct static_route_info {
+ /* path list */
+ struct static_path_list_head path_list;
+};
+
+/* Static path information */
+struct static_path {
+ /* Linkage for static path lists */
+ struct static_path_list_item list;
+ /* Administrative distance. */
+ uint8_t distance;
+ /* Tag */
+ route_tag_t tag;
+ /* Table-id */
+ uint32_t table_id;
+ /* Nexthop list */
+ struct static_nexthop_list_head nexthop_list;
+};
+
+DECLARE_DLIST(static_path_list, struct static_path, list);
+
/* Static route information. */
-struct static_route {
+struct static_nexthop {
/* For linked list. */
- struct static_route *prev;
- struct static_route *next;
+ struct static_nexthop_list_item list;
/* VRF identifier. */
- vrf_id_t vrf_id;
vrf_id_t nh_vrf_id;
char nh_vrfname[VRF_NAMSIZ + 1];
@@ -81,12 +109,6 @@ struct static_route {
*/
enum static_install_states state;
- /* Administrative distance. */
- uint8_t distance;
-
- /* Tag */
- route_tag_t tag;
-
/* Flag for this static route's type. */
static_types type;
@@ -104,8 +126,6 @@ struct static_route {
/* Label information */
struct static_nh_label snh_label;
- uint32_t table_id;
-
/*
* Whether to pretend the nexthop is directly attached to the specified
* link. Only meaningful when both a gateway address and interface name
@@ -114,32 +134,64 @@ struct static_route {
bool onlink;
};
+DECLARE_DLIST(static_nexthop_list, struct static_nexthop, list);
+
+
+/*
+ * rib_dest_from_rnode
+ */
+static inline struct static_route_info *
+static_route_info_from_rnode(struct route_node *rn)
+{
+ return (struct static_route_info *)(rn->info);
+}
+
extern bool mpls_enabled;
extern struct zebra_privs_t static_privs;
void static_fixup_vrf_ids(struct static_vrf *svrf);
-extern int static_add_route(afi_t afi, safi_t safi, uint8_t type,
- struct prefix *p, struct prefix_ipv6 *src_p,
- union g_addr *gate, const char *ifname,
- enum static_blackhole_type bh_type, route_tag_t tag,
- uint8_t distance, struct static_vrf *svrf,
- struct static_vrf *nh_svrf,
- struct static_nh_label *snh_label,
- uint32_t table_id, bool onlink);
-
-extern int static_delete_route(afi_t afi, safi_t safi, uint8_t type,
- struct prefix *p, struct prefix_ipv6 *src_p,
- union g_addr *gate, const char *ifname,
- route_tag_t tag, uint8_t distance,
- struct static_vrf *svrf,
- struct static_nh_label *snh_label,
- uint32_t table_id);
+extern struct static_nexthop *
+static_add_nexthop(struct route_node *rn, struct static_path *pn, safi_t safi,
+ struct static_vrf *svrf, static_types type,
+ struct ipaddr *ipaddr, const char *ifname,
+ const char *nh_vrf);
+extern void static_install_nexthop(struct route_node *rn,
+ struct static_path *pn,
+ struct static_nexthop *nh, safi_t safi,
+ struct static_vrf *svrf, const char *ifname,
+ static_types type, const char *nh_vrf);
+
+extern int static_delete_nexthop(struct route_node *rn, struct static_path *pn,
+ safi_t safi, struct static_vrf *svrf,
+ struct static_nexthop *nh);
extern void static_cleanup_vrf_ids(struct static_vrf *disable_svrf);
extern void static_install_intf_nh(struct interface *ifp);
extern void static_ifindex_update(struct interface *ifp, bool up);
+
+extern void static_install_path(struct route_node *rn, struct static_path *pn,
+ safi_t safi, struct static_vrf *svrf);
+
+extern struct route_node *static_add_route(afi_t afi, safi_t safi,
+ struct prefix *p,
+ struct prefix_ipv6 *src_p,
+ struct static_vrf *svrf);
+extern void static_del_route(struct route_node *rn, safi_t safi,
+ struct static_vrf *svrf);
+
+extern struct static_path *static_add_path(struct route_node *rn,
+ uint8_t distance);
+extern void static_del_path(struct route_node *rn, struct static_path *pn,
+ safi_t safi, struct static_vrf *svrf);
+
+extern void static_get_nh_type(static_types stype, char *type, size_t size);
+extern bool static_add_nexthop_validate(struct static_vrf *svrf,
+ static_types type,
+ struct ipaddr *ipaddr);
+extern struct stable_info *static_get_stable_info(struct route_node *rn);
+extern void static_route_info_init(struct static_route_info *si);
#endif
diff --git a/staticd/static_vrf.c b/staticd/static_vrf.c
index 6c065932a1..39b86787ff 100644
--- a/staticd/static_vrf.c
+++ b/staticd/static_vrf.c
@@ -30,26 +30,39 @@
#include "static_zebra.h"
#include "static_vty.h"
+DEFINE_MTYPE_STATIC(STATIC, STATIC_RTABLE_INFO, "Static Route Table Info");
+
static void zebra_stable_node_cleanup(struct route_table *table,
struct route_node *node)
{
- struct static_route *si, *next;
-
- if (node->info)
- for (si = node->info; si; si = next) {
- next = si->next;
- XFREE(MTYPE_STATIC_ROUTE, si);
+ struct static_nexthop *nh;
+ struct static_path *pn;
+ struct static_route_info *si;
+
+ si = node->info;
+
+ if (si) {
+ frr_each_safe(static_path_list, &si->path_list, pn) {
+ frr_each_safe(static_nexthop_list, &pn->nexthop_list,
+ nh) {
+ static_nexthop_list_del(&pn->nexthop_list, nh);
+ XFREE(MTYPE_STATIC_NEXTHOP, nh);
+ }
+ static_path_list_del(&si->path_list, pn);
+ XFREE(MTYPE_STATIC_PATH, pn);
}
+ }
}
static struct static_vrf *static_vrf_alloc(void)
{
struct route_table *table;
struct static_vrf *svrf;
+ struct stable_info *info;
safi_t safi;
afi_t afi;
- svrf = XCALLOC(MTYPE_TMP, sizeof(struct static_vrf));
+ svrf = XCALLOC(MTYPE_STATIC_RTABLE_INFO, sizeof(struct static_vrf));
for (afi = AFI_IP; afi <= AFI_IP6; afi++) {
for (safi = SAFI_UNICAST; safi <= SAFI_MULTICAST; safi++) {
@@ -57,6 +70,14 @@ static struct static_vrf *static_vrf_alloc(void)
table = srcdest_table_init();
else
table = route_table_init();
+
+ info = XCALLOC(MTYPE_STATIC_RTABLE_INFO,
+ sizeof(struct stable_info));
+ info->svrf = svrf;
+ info->afi = afi;
+ info->safi = safi;
+ route_table_set_info(table, info);
+
table->cleanup = zebra_stable_node_cleanup;
svrf->stable[afi][safi] = table;
}
@@ -81,12 +102,6 @@ static int static_vrf_enable(struct vrf *vrf)
static_fixup_vrf_ids(vrf->info);
- /*
- * We may have static routes that are now possible to
- * insert into the appropriate tables
- */
- static_config_install_delayed_routes(vrf->info);
-
return 0;
}
@@ -102,16 +117,19 @@ static int static_vrf_delete(struct vrf *vrf)
struct static_vrf *svrf;
safi_t safi;
afi_t afi;
+ void *info;
svrf = vrf->info;
for (afi = AFI_IP; afi <= AFI_IP6; afi++) {
for (safi = SAFI_UNICAST; safi <= SAFI_MULTICAST; safi++) {
table = svrf->stable[afi][safi];
+ info = route_table_get_info(table);
route_table_finish(table);
+ XFREE(MTYPE_STATIC_RTABLE_INFO, info);
svrf->stable[afi][safi] = NULL;
}
}
- XFREE(MTYPE_TMP, svrf);
+ XFREE(MTYPE_STATIC_RTABLE_INFO, svrf);
return 0;
}
@@ -210,3 +228,25 @@ void static_vrf_terminate(void)
{
vrf_terminate();
}
+
+struct static_vrf *static_vty_get_unknown_vrf(const char *vrf_name)
+{
+ struct static_vrf *svrf;
+ struct vrf *vrf;
+
+ svrf = static_vrf_lookup_by_name(vrf_name);
+
+ if (svrf)
+ return svrf;
+
+ vrf = vrf_get(VRF_UNKNOWN, vrf_name);
+ if (!vrf)
+ return NULL;
+ svrf = vrf->info;
+ if (!svrf)
+ return NULL;
+ /* Mark as having FRR configuration */
+ vrf_set_user_cfged(vrf);
+
+ return svrf;
+}
diff --git a/staticd/static_vrf.h b/staticd/static_vrf.h
index 6951e56712..12ad1b255a 100644
--- a/staticd/static_vrf.h
+++ b/staticd/static_vrf.h
@@ -26,6 +26,14 @@ struct static_vrf {
struct route_table *stable[AFI_MAX][SAFI_MAX];
};
+struct stable_info {
+ struct static_vrf *svrf;
+ afi_t afi;
+ safi_t safi;
+};
+
+#define GET_STABLE_VRF_ID(info) info->svrf->vrf->vrf_id
+
struct static_vrf *static_vrf_lookup_by_name(const char *vrf_name);
struct static_vrf *static_vrf_lookup_by_id(vrf_id_t vrf_id);
@@ -36,4 +44,6 @@ void static_vrf_init(void);
struct route_table *static_vrf_static_table(afi_t afi, safi_t safi,
struct static_vrf *svrf);
extern void static_vrf_terminate(void);
+
+struct static_vrf *static_vty_get_unknown_vrf(const char *vrf_name);
#endif
diff --git a/staticd/static_vty.c b/staticd/static_vty.c
index 75bce82eef..ac18f6adf4 100644
--- a/staticd/static_vty.c
+++ b/staticd/static_vty.c
@@ -27,6 +27,10 @@
#include "table.h"
#include "srcdest_table.h"
#include "mpls.h"
+#include "northbound.h"
+#include "libfrr.h"
+#include "routing_nb.h"
+#include "northbound_cli.h"
#include "static_vrf.h"
#include "static_memory.h"
@@ -36,251 +40,43 @@
#ifndef VTYSH_EXTRACT_PL
#include "staticd/static_vty_clippy.c"
#endif
+#include "static_nb.h"
#define STATICD_STR "Static route daemon\n"
-static struct static_vrf *static_vty_get_unknown_vrf(struct vty *vty,
- const char *vrf_name)
+static int static_route_leak(struct vty *vty, const char *svrf,
+ const char *nh_svrf, afi_t afi, safi_t safi,
+ const char *negate, const char *dest_str,
+ const char *mask_str, const char *src_str,
+ const char *gate_str, const char *ifname,
+ const char *flag_str, const char *tag_str,
+ const char *distance_str, const char *label_str,
+ const char *table_str, bool onlink)
{
- struct static_vrf *svrf;
- struct vrf *vrf;
-
- svrf = static_vrf_lookup_by_name(vrf_name);
-
- if (svrf)
- return svrf;
-
- vrf = vrf_get(VRF_UNKNOWN, vrf_name);
- if (!vrf) {
- vty_out(vty, "%% Could not create vrf %s\n", vrf_name);
- return NULL;
- }
- svrf = vrf->info;
- if (!svrf) {
- vty_out(vty, "%% Could not create vrf-info %s\n",
- vrf_name);
- return NULL;
- }
- /* Mark as having FRR configuration */
- vrf_set_user_cfged(vrf);
-
- return svrf;
-}
-
-struct static_hold_route {
- char *vrf_name;
- char *nhvrf_name;
- afi_t afi;
- safi_t safi;
- char *dest_str;
- char *mask_str;
- char *src_str;
- char *gate_str;
- char *ifname;
- char *flag_str;
- char *tag_str;
- char *distance_str;
- char *label_str;
- char *table_str;
- bool onlink;
-
- /* processed & masked destination, used for config display */
- struct prefix dest;
-};
-
-static struct list *static_list;
-
-static int static_list_compare_helper(const char *s1, const char *s2)
-{
- /* extra (!s1 && !s2) to keep SA happy */
- if (s1 == s2 || (!s1 && !s2))
- return 0;
-
- if (!s1 && s2)
- return -1;
-
- if (s1 && !s2)
- return 1;
-
- return strcmp(s1, s2);
-}
-
-static void static_list_delete(struct static_hold_route *shr)
-{
- XFREE(MTYPE_STATIC_ROUTE, shr->vrf_name);
- XFREE(MTYPE_STATIC_ROUTE, shr->nhvrf_name);
- XFREE(MTYPE_STATIC_ROUTE, shr->dest_str);
- XFREE(MTYPE_STATIC_ROUTE, shr->mask_str);
- XFREE(MTYPE_STATIC_ROUTE, shr->src_str);
- XFREE(MTYPE_STATIC_ROUTE, shr->gate_str);
- XFREE(MTYPE_STATIC_ROUTE, shr->ifname);
- XFREE(MTYPE_STATIC_ROUTE, shr->flag_str);
- XFREE(MTYPE_STATIC_ROUTE, shr->tag_str);
- XFREE(MTYPE_STATIC_ROUTE, shr->distance_str);
- XFREE(MTYPE_STATIC_ROUTE, shr->label_str);
- XFREE(MTYPE_STATIC_ROUTE, shr->table_str);
-
- XFREE(MTYPE_STATIC_ROUTE, shr);
-}
-
-static int static_list_compare(void *arg1, void *arg2)
-{
- struct static_hold_route *shr1 = arg1;
- struct static_hold_route *shr2 = arg2;
int ret;
-
- ret = strcmp(shr1->vrf_name, shr2->vrf_name);
- if (ret)
- return ret;
-
- ret = strcmp(shr1->nhvrf_name, shr2->nhvrf_name);
- if (ret)
- return ret;
-
- ret = shr1->afi - shr2->afi;
- if (ret)
- return ret;
-
- ret = shr1->safi - shr2->safi;
- if (ret)
- return ret;
-
- ret = prefix_cmp(&shr1->dest, &shr2->dest);
- if (ret)
- return ret;
-
- ret = static_list_compare_helper(shr1->src_str, shr2->src_str);
- if (ret)
- return ret;
-
- ret = static_list_compare_helper(shr1->gate_str, shr2->gate_str);
- if (ret)
- return ret;
-
- ret = static_list_compare_helper(shr1->ifname, shr2->ifname);
- if (ret)
- return ret;
-
- ret = static_list_compare_helper(shr1->flag_str, shr2->flag_str);
- if (ret)
- return ret;
-
- ret = static_list_compare_helper(shr1->tag_str, shr2->tag_str);
- if (ret)
- return ret;
-
- ret = static_list_compare_helper(shr1->distance_str,
- shr2->distance_str);
- if (ret)
- return ret;
-
- ret = static_list_compare_helper(shr1->table_str,
- shr2->table_str);
- if (ret)
- return ret;
-
- return static_list_compare_helper(shr1->label_str, shr2->label_str);
-}
-
-
-/* General function for static route. */
-static int zebra_static_route_holdem(
- struct static_vrf *svrf, struct static_vrf *nh_svrf, afi_t afi,
- safi_t safi, const char *negate, struct prefix *dest,
- const char *dest_str, const char *mask_str, const char *src_str,
- const char *gate_str, const char *ifname, const char *flag_str,
- const char *tag_str, const char *distance_str, const char *label_str,
- const char *table_str, bool onlink)
-{
- struct static_hold_route *shr, *lookup;
- struct listnode *node;
-
- zlog_warn("Static Route to %s not installed currently because dependent config not fully available",
- dest_str);
-
- shr = XCALLOC(MTYPE_STATIC_ROUTE, sizeof(*shr));
- shr->vrf_name = XSTRDUP(MTYPE_STATIC_ROUTE, svrf->vrf->name);
- shr->nhvrf_name = XSTRDUP(MTYPE_STATIC_ROUTE, nh_svrf->vrf->name);
- shr->afi = afi;
- shr->safi = safi;
- shr->onlink = onlink;
- if (dest)
- prefix_copy(&shr->dest, dest);
- if (dest_str)
- shr->dest_str = XSTRDUP(MTYPE_STATIC_ROUTE, dest_str);
- if (mask_str)
- shr->mask_str = XSTRDUP(MTYPE_STATIC_ROUTE, mask_str);
- if (src_str)
- shr->src_str = XSTRDUP(MTYPE_STATIC_ROUTE, src_str);
- if (gate_str)
- shr->gate_str = XSTRDUP(MTYPE_STATIC_ROUTE, gate_str);
- if (ifname)
- shr->ifname = XSTRDUP(MTYPE_STATIC_ROUTE, ifname);
- if (flag_str)
- shr->flag_str = XSTRDUP(MTYPE_STATIC_ROUTE, flag_str);
- if (tag_str)
- shr->tag_str = XSTRDUP(MTYPE_STATIC_ROUTE, tag_str);
- if (distance_str)
- shr->distance_str = XSTRDUP(MTYPE_STATIC_ROUTE, distance_str);
- if (label_str)
- shr->label_str = XSTRDUP(MTYPE_STATIC_ROUTE, label_str);
- if (table_str)
- shr->table_str = XSTRDUP(MTYPE_STATIC_ROUTE, table_str);
-
- for (ALL_LIST_ELEMENTS_RO(static_list, node, lookup)) {
- if (static_list_compare(shr, lookup) == 0)
- break;
- }
-
- if (lookup) {
- if (negate) {
- listnode_delete(static_list, lookup);
- static_list_delete(shr);
- static_list_delete(lookup);
-
- return CMD_SUCCESS;
- }
-
- /*
- * If a person enters the same line again
- * we need to silently accept it
- */
- goto shr_cleanup;
- }
-
- if (!negate) {
- listnode_add_sort(static_list, shr);
- return CMD_SUCCESS;
- }
-
- shr_cleanup:
- XFREE(MTYPE_STATIC_ROUTE, shr->nhvrf_name);
- XFREE(MTYPE_STATIC_ROUTE, shr->vrf_name);
- XFREE(MTYPE_STATIC_ROUTE, shr);
-
- return CMD_SUCCESS;
-}
-
-static int static_route_leak(
- struct vty *vty, struct static_vrf *svrf, struct static_vrf *nh_svrf,
- afi_t afi, safi_t safi, const char *negate, const char *dest_str,
- const char *mask_str, const char *src_str, const char *gate_str,
- const char *ifname, const char *flag_str, const char *tag_str,
- const char *distance_str, const char *label_str, const char *table_str,
- bool onlink)
-{
- int ret;
- uint8_t distance;
struct prefix p, src;
- struct prefix_ipv6 *src_p = NULL;
- union g_addr gate;
- union g_addr *gatep = NULL;
struct in_addr mask;
- enum static_blackhole_type bh_type = 0;
- route_tag_t tag = 0;
uint8_t type;
- struct static_nh_label snh_label;
+ const char *bh_type;
+ char xpath_prefix[XPATH_MAXLEN];
+ char xpath_nexthop[XPATH_MAXLEN];
+ char xpath_mpls[XPATH_MAXLEN];
+ char xpath_label[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];
+ char buf_tableid[PREFIX_STRLEN];
+ uint8_t label_stack_id = 0;
+ const char *buf_gate_str;
+ uint8_t distance = ZEBRA_STATIC_DISTANCE_DEFAULT;
+ route_tag_t tag = 0;
uint32_t table_id = 0;
+ const struct lyd_node *dnode;
+
+ memset(buf_src_prefix, 0, PREFIX_STRLEN);
+ memset(buf_nh_type, 0, PREFIX_STRLEN);
ret = str2prefix(dest_str, &p);
if (ret <= 0) {
@@ -322,7 +118,6 @@ static int static_route_leak(
__func__, src_str);
return CMD_WARNING_CONFIG_FAILED;
}
- src_p = (struct prefix_ipv6 *)&src;
}
break;
default:
@@ -332,29 +127,29 @@ static int static_route_leak(
/* Apply mask for given prefix. */
apply_mask(&p);
- if (svrf->vrf->vrf_id == VRF_UNKNOWN
- || nh_svrf->vrf->vrf_id == VRF_UNKNOWN) {
- vrf_set_user_cfged(svrf->vrf);
- return zebra_static_route_holdem(
- svrf, nh_svrf, afi, safi, negate, &p, dest_str,
- mask_str, src_str, gate_str, ifname, flag_str, tag_str,
- distance_str, label_str, table_str, onlink);
- }
+ prefix2str(&p, buf_prefix, sizeof(buf_prefix));
- if (table_str) {
- /* table configured. check consistent with vrf config
- */
- if (svrf->vrf->data.l.table_id != RT_TABLE_MAIN) {
- if (vty)
- vty_out(vty,
- "%% Table %s overlaps vrf table %u\n",
- table_str, svrf->vrf->data.l.table_id);
- else
- zlog_warn("%s: Table %s overlaps vrf table %u",
- __func__, table_str,
- svrf->vrf->data.l.table_id);
- return CMD_WARNING_CONFIG_FAILED;
- }
+ if (src_str)
+ prefix2str(&src, buf_src_prefix, sizeof(buf_src_prefix));
+ if (gate_str)
+ buf_gate_str = gate_str;
+ else
+ buf_gate_str = "";
+
+ if (gate_str == NULL && ifname == NULL)
+ type = STATIC_BLACKHOLE;
+ else if (gate_str && ifname) {
+ if (afi == AFI_IP)
+ type = STATIC_IPV4_GATEWAY_IFNAME;
+ else
+ type = STATIC_IPV6_GATEWAY_IFNAME;
+ } else if (ifname)
+ type = STATIC_IFNAME;
+ else {
+ if (afi == AFI_IP)
+ type = STATIC_IPV4_GATEWAY;
+ else
+ type = STATIC_IPV6_GATEWAY;
}
/* Administrative distance. */
@@ -367,169 +162,160 @@ static int static_route_leak(
if (tag_str)
tag = strtoul(tag_str, NULL, 10);
- /* Labels */
- memset(&snh_label, 0, sizeof(struct static_nh_label));
- if (label_str) {
- if (!mpls_enabled) {
- if (vty)
- vty_out(vty,
- "%% MPLS not turned on in kernel, ignoring command\n");
- else
- zlog_warn(
- "%s: MPLS not turned on in kernel ignoring static route to %s",
- __func__, dest_str);
- return CMD_WARNING_CONFIG_FAILED;
- }
- int rc = mpls_str2label(label_str, &snh_label.num_labels,
- snh_label.label);
- if (rc < 0) {
- switch (rc) {
- case -1:
- if (vty)
- vty_out(vty, "%% Malformed label(s)\n");
- else
- zlog_warn(
- "%s: Malformed labels specified for route %s",
- __func__, dest_str);
- break;
- case -2:
- if (vty)
- vty_out(vty,
- "%% Cannot use reserved label(s) (%d-%d)\n",
- MPLS_LABEL_RESERVED_MIN,
- MPLS_LABEL_RESERVED_MAX);
- else
- zlog_warn(
- "%s: Cannot use reserved labels (%d-%d) for %s",
- __func__,
- MPLS_LABEL_RESERVED_MIN,
- MPLS_LABEL_RESERVED_MAX,
- dest_str);
- break;
- case -3:
- if (vty)
- vty_out(vty,
- "%% Too many labels. Enter %d or fewer\n",
- MPLS_MAX_LABELS);
- else
- zlog_warn(
- "%s: Too many labels, Enter %d or fewer for %s",
- __func__, MPLS_MAX_LABELS,
- dest_str);
- break;
- }
- return CMD_WARNING_CONFIG_FAILED;
- }
- }
-
/* TableID */
if (table_str)
table_id = atol(table_str);
- /* Null0 static route. */
- if (ifname != NULL) {
- if (strcasecmp(ifname, "Null0") == 0
- || strcasecmp(ifname, "reject") == 0
- || strcasecmp(ifname, "blackhole") == 0) {
- if (vty)
- vty_out(vty,
- "%% Nexthop interface name can not be from reserved keywords (Null0, reject, blackhole)\n");
- else
- zlog_warn(
- "%s: %s: Nexthop interface name can not be from reserved keywords (Null0, reject, blackhole)",
- __func__, dest_str);
- return CMD_WARNING_CONFIG_FAILED;
- }
- }
-
- /* Route flags */
- if (flag_str) {
- switch (flag_str[0]) {
- case 'r':
- bh_type = STATIC_BLACKHOLE_REJECT;
- break;
- case 'b':
- bh_type = STATIC_BLACKHOLE_DROP;
- break;
- case 'N':
- bh_type = STATIC_BLACKHOLE_NULL;
- break;
- default:
- if (vty)
- vty_out(vty, "%% Malformed flag %s \n",
- flag_str);
- else
- zlog_warn("%s: Malformed flag %s for %s",
- __func__, flag_str, dest_str);
- return CMD_WARNING_CONFIG_FAILED;
+ static_get_nh_type(type, buf_nh_type, PREFIX_STRLEN);
+ if (!negate) {
+ /* route + path procesing */
+ if (src_str)
+ snprintf(xpath_prefix, sizeof(xpath_prefix),
+ FRR_S_ROUTE_SRC_INFO_KEY_XPATH,
+ "frr-staticd:staticd", "staticd", svrf,
+ buf_prefix,
+ yang_afi_safi_value2identity(afi, safi),
+ buf_src_prefix, distance);
+ else
+ snprintf(xpath_prefix, sizeof(xpath_prefix),
+ FRR_STATIC_ROUTE_INFO_KEY_XPATH,
+ "frr-staticd:staticd", "staticd", svrf,
+ buf_prefix,
+ yang_afi_safi_value2identity(afi, safi),
+ distance);
+
+ nb_cli_enqueue_change(vty, xpath_prefix, NB_OP_CREATE, NULL);
+
+ /* Tag processing */
+ snprintf(buf_tag, sizeof(buf_tag), "%u", tag);
+ strlcpy(ab_xpath, xpath_prefix, sizeof(ab_xpath));
+ strlcat(ab_xpath, FRR_STATIC_ROUTE_PATH_TAG_XPATH,
+ sizeof(ab_xpath));
+ nb_cli_enqueue_change(vty, ab_xpath, NB_OP_MODIFY, buf_tag);
+
+ /* Table-Id processing */
+ snprintf(buf_tableid, sizeof(buf_tableid), "%u", table_id);
+ strlcpy(ab_xpath, xpath_prefix, sizeof(ab_xpath));
+ strlcat(ab_xpath, FRR_STATIC_ROUTE_PATH_TABLEID_XPATH,
+ sizeof(ab_xpath));
+ nb_cli_enqueue_change(vty, ab_xpath, NB_OP_MODIFY, buf_tableid);
+ /* nexthop processing */
+
+ snprintf(ab_xpath, sizeof(ab_xpath),
+ FRR_STATIC_ROUTE_NH_KEY_XPATH, buf_nh_type, nh_svrf,
+ buf_gate_str, ifname);
+ strlcpy(xpath_nexthop, xpath_prefix, sizeof(xpath_nexthop));
+ strlcat(xpath_nexthop, ab_xpath, sizeof(xpath_nexthop));
+ nb_cli_enqueue_change(vty, xpath_nexthop, NB_OP_CREATE, NULL);
+
+ if (type == STATIC_BLACKHOLE) {
+ strlcpy(ab_xpath, xpath_nexthop, sizeof(ab_xpath));
+ strlcat(ab_xpath, FRR_STATIC_ROUTE_NH_BH_XPATH,
+ sizeof(ab_xpath));
+
+ /* Route flags */
+ if (flag_str) {
+ switch (flag_str[0]) {
+ case 'r':
+ bh_type = "reject";
+ break;
+ case 'b':
+ bh_type = "unspec";
+ break;
+ case 'N':
+ bh_type = "null";
+ break;
+ default:
+ bh_type = NULL;
+ break;
+ }
+ nb_cli_enqueue_change(vty, ab_xpath,
+ NB_OP_MODIFY, bh_type);
+ } else {
+ nb_cli_enqueue_change(vty, ab_xpath,
+ NB_OP_MODIFY, "null");
+ }
}
- }
-
- if (gate_str) {
- if (inet_pton(afi2family(afi), gate_str, &gate) != 1) {
- if (vty)
- vty_out(vty,
- "%% Malformed nexthop address %s\n",
- gate_str);
+ if (type == STATIC_IPV4_GATEWAY_IFNAME
+ || type == STATIC_IPV6_GATEWAY_IFNAME) {
+ strlcpy(ab_xpath, xpath_nexthop, sizeof(ab_xpath));
+ strlcat(ab_xpath, FRR_STATIC_ROUTE_NH_ONLINK_XPATH,
+ sizeof(ab_xpath));
+
+ if (onlink)
+ nb_cli_enqueue_change(vty, ab_xpath,
+ NB_OP_MODIFY, "true");
else
- zlog_warn(
- "%s: Malformed nexthop address %s for %s",
- __func__, gate_str, dest_str);
- return CMD_WARNING_CONFIG_FAILED;
+ nb_cli_enqueue_change(vty, ab_xpath,
+ NB_OP_MODIFY, "false");
}
- gatep = &gate;
-
- if (afi == AFI_IP && !negate) {
- if (if_lookup_exact_address(&gatep->ipv4, AF_INET,
- svrf->vrf->vrf_id))
- if (vty)
- vty_out(vty,
- "%% Warning!! Local connected address is configured as Gateway IP(%s)\n",
- gate_str);
- } else if (afi == AFI_IP6 && !negate) {
- if (if_lookup_exact_address(&gatep->ipv6, AF_INET6,
- svrf->vrf->vrf_id))
- if (vty)
- vty_out(vty,
- "%% Warning!! Local connected address is configured as Gateway IPv6(%s)\n",
- gate_str);
+ if (label_str) {
+ /* copy of label string (start) */
+ char *ostr;
+ /* pointer to next segment */
+ char *nump;
+
+ strlcpy(xpath_mpls, xpath_nexthop, sizeof(xpath_mpls));
+ strlcat(xpath_mpls, FRR_STATIC_ROUTE_NH_LABEL_XPATH,
+ sizeof(xpath_mpls));
+
+ nb_cli_enqueue_change(vty, xpath_mpls, NB_OP_DESTROY,
+ NULL);
+
+ ostr = XSTRDUP(MTYPE_TMP, label_str);
+ while ((nump = strsep(&ostr, "/")) != NULL) {
+ snprintf(ab_xpath, sizeof(ab_xpath),
+ FRR_STATIC_ROUTE_NHLB_KEY_XPATH,
+ label_stack_id);
+ strlcpy(xpath_label, xpath_mpls,
+ sizeof(xpath_label));
+ strlcat(xpath_label, ab_xpath,
+ sizeof(xpath_label));
+ nb_cli_enqueue_change(vty, xpath_label,
+ 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,
+ sizeof(xpath_mpls));
+ nb_cli_enqueue_change(vty, xpath_mpls, NB_OP_DESTROY,
+ NULL);
}
-
- }
-
- if (gate_str == NULL && ifname == NULL)
- type = STATIC_BLACKHOLE;
- else if (gate_str && ifname) {
- if (afi == AFI_IP)
- type = STATIC_IPV4_GATEWAY_IFNAME;
- else
- type = STATIC_IPV6_GATEWAY_IFNAME;
- } else if (ifname)
- type = STATIC_IFNAME;
- else {
- if (afi == AFI_IP)
- type = STATIC_IPV4_GATEWAY;
- else
- type = STATIC_IPV6_GATEWAY;
- }
-
- if (!negate) {
- static_add_route(afi, safi, type, &p, src_p, gatep, ifname,
- bh_type, tag, distance, svrf, nh_svrf,
- &snh_label, table_id, onlink);
- /* Mark as having FRR configuration */
- vrf_set_user_cfged(svrf->vrf);
+ ret = nb_cli_apply_changes(vty, xpath_prefix);
} else {
- static_delete_route(afi, safi, type, &p, src_p, gatep, ifname,
- tag, distance, svrf, &snh_label, table_id);
- /* If no other FRR config for this VRF, mark accordingly. */
- if (!static_vrf_has_config(svrf))
- vrf_reset_user_cfged(svrf->vrf);
+ if (src_str)
+ snprintf(ab_xpath, sizeof(ab_xpath),
+ FRR_DEL_S_ROUTE_SRC_NH_KEY_XPATH,
+ "frr-staticd:staticd", "staticd", svrf,
+ buf_prefix,
+ yang_afi_safi_value2identity(afi, safi),
+ buf_src_prefix, distance, buf_nh_type, nh_svrf,
+ buf_gate_str, ifname);
+ else
+ snprintf(ab_xpath, sizeof(ab_xpath),
+ FRR_DEL_S_ROUTE_NH_KEY_XPATH,
+ "frr-staticd:staticd", "staticd", svrf,
+ buf_prefix,
+ yang_afi_safi_value2identity(afi, safi),
+ distance, buf_nh_type, nh_svrf, buf_gate_str,
+ ifname);
+
+ dnode = yang_dnode_get(vty->candidate_config->dnode, ab_xpath);
+ if (!dnode)
+ return ret;
+
+ dnode = yang_get_subtree_with_no_sibling(dnode);
+ assert(dnode);
+ yang_dnode_get_path(dnode, ab_xpath, XPATH_MAXLEN);
+
+ nb_cli_enqueue_change(vty, ab_xpath, NB_OP_DESTROY, NULL);
+ ret = nb_cli_apply_changes(vty, ab_xpath);
}
- return CMD_SUCCESS;
+ return ret;
}
-
static int static_route(struct vty *vty, afi_t afi, safi_t safi,
const char *negate, const char *dest_str,
const char *mask_str, const char *src_str,
@@ -538,77 +324,28 @@ static int static_route(struct vty *vty, afi_t afi, safi_t safi,
const char *distance_str, const char *vrf_name,
const char *label_str, const char *table_str)
{
- struct static_vrf *svrf;
-
- /* VRF id */
- svrf = static_vrf_lookup_by_name(vrf_name);
-
- /* When trying to delete, the VRF must exist. */
- if (negate && !svrf) {
- vty_out(vty, "%% vrf %s is not defined\n", vrf_name);
- return CMD_WARNING_CONFIG_FAILED;
- }
+ if (!vrf_name)
+ vrf_name = VRF_DEFAULT_NAME;
- /* When trying to create, create the VRF if it doesn't exist.
- * Note: The VRF isn't active until we hear about it from the kernel.
- */
- if (!svrf) {
- svrf = static_vty_get_unknown_vrf(vty, vrf_name);
- if (!svrf)
- return CMD_WARNING_CONFIG_FAILED;
- }
- return static_route_leak(vty, svrf, svrf, afi, safi, negate, dest_str,
- mask_str, src_str, gate_str, ifname, flag_str,
- tag_str, distance_str, label_str, table_str,
- false);
-}
-
-void static_config_install_delayed_routes(struct static_vrf *svrf)
-{
- struct listnode *node, *nnode;
- struct static_hold_route *shr;
- struct static_vrf *osvrf, *nh_svrf;
- int installed;
-
- for (ALL_LIST_ELEMENTS(static_list, node, nnode, shr)) {
- osvrf = static_vrf_lookup_by_name(shr->vrf_name);
- nh_svrf = static_vrf_lookup_by_name(shr->nhvrf_name);
-
- if (osvrf != svrf && nh_svrf != svrf)
- continue;
-
- if (osvrf->vrf->vrf_id == VRF_UNKNOWN
- || nh_svrf->vrf->vrf_id == VRF_UNKNOWN)
- continue;
-
- installed = static_route_leak(
- NULL, osvrf, nh_svrf, shr->afi, shr->safi, NULL,
- shr->dest_str, shr->mask_str, shr->src_str,
- shr->gate_str, shr->ifname, shr->flag_str, shr->tag_str,
- shr->distance_str, shr->label_str, shr->table_str,
- shr->onlink);
-
- if (installed != CMD_SUCCESS)
- zlog_debug(
- "%s: Attempt to install %s as a route and it was rejected",
- __func__, shr->dest_str);
- listnode_delete(static_list, shr);
- static_list_delete(shr);
- }
+ return static_route_leak(vty, vrf_name, vrf_name, afi, safi, negate,
+ dest_str, mask_str, src_str, gate_str, ifname,
+ flag_str, tag_str, distance_str, label_str,
+ table_str, false);
}
/* Write static route configuration. */
int static_config(struct vty *vty, struct static_vrf *svrf, afi_t afi,
safi_t safi, const char *cmd)
{
- struct static_hold_route *shr;
- struct listnode *node;
char spacing[100];
struct route_node *rn;
- struct static_route *si;
+ struct static_nexthop *nh;
+ struct static_path *pn;
struct route_table *stable;
+ struct static_route_info *si;
char buf[SRCDEST2STR_BUFFER];
int write = 0;
+ struct stable_info *info;
stable = svrf->stable[afi][safi];
if (stable == NULL)
@@ -617,125 +354,104 @@ int static_config(struct vty *vty, struct static_vrf *svrf, afi_t afi,
snprintf(spacing, sizeof(spacing), "%s%s",
(svrf->vrf->vrf_id == VRF_DEFAULT) ? "" : " ", cmd);
- /*
- * Static routes for vrfs not fully inited
- */
- for (ALL_LIST_ELEMENTS_RO(static_list, node, shr)) {
- if (shr->afi != afi || shr->safi != safi)
+ for (rn = route_top(stable); rn; rn = srcdest_route_next(rn)) {
+ si = static_route_info_from_rnode(rn);
+ if (!si)
continue;
-
- if (strcmp(svrf->vrf->name, shr->vrf_name) != 0)
- continue;
-
- char dest_str[PREFIX_STRLEN];
-
- prefix2str(&shr->dest, dest_str, sizeof(dest_str));
-
- vty_out(vty, "%s ", spacing);
- if (shr->dest_str)
- vty_out(vty, "%s ", dest_str);
- if (shr->src_str)
- vty_out(vty, "from %s ", shr->src_str);
- if (shr->gate_str)
- vty_out(vty, "%s ", shr->gate_str);
- if (shr->ifname)
- vty_out(vty, "%s ", shr->ifname);
- if (shr->flag_str)
- vty_out(vty, "%s ", shr->flag_str);
- if (shr->tag_str)
- vty_out(vty, "tag %s ", shr->tag_str);
- if (shr->distance_str)
- vty_out(vty, "%s ", shr->distance_str);
- if (shr->label_str)
- vty_out(vty, "label %s ", shr->label_str);
- if (shr->table_str)
- vty_out(vty, "table %s", shr->table_str);
- if (strcmp(shr->vrf_name, shr->nhvrf_name) != 0)
- vty_out(vty, "nexthop-vrf %s ", shr->nhvrf_name);
- if (shr->onlink)
- vty_out(vty, "onlink");
- vty_out(vty, "\n");
- }
-
- for (rn = route_top(stable); rn; rn = srcdest_route_next(rn))
- for (si = rn->info; si; si = si->next) {
- vty_out(vty, "%s %s", spacing,
- srcdest_rnode2str(rn, buf, sizeof(buf)));
-
- switch (si->type) {
- case STATIC_IPV4_GATEWAY:
- vty_out(vty, " %s", inet_ntoa(si->addr.ipv4));
- break;
- case STATIC_IPV6_GATEWAY:
- vty_out(vty, " %s",
- inet_ntop(AF_INET6, &si->addr.ipv6, buf,
- sizeof(buf)));
- break;
- case STATIC_IFNAME:
- vty_out(vty, " %s", si->ifname);
- break;
- case STATIC_BLACKHOLE:
- switch (si->bh_type) {
- case STATIC_BLACKHOLE_DROP:
- vty_out(vty, " blackhole");
+ info = static_get_stable_info(rn);
+ frr_each(static_path_list, &si->path_list, pn) {
+ frr_each(static_nexthop_list, &pn->nexthop_list, nh) {
+ vty_out(vty, "%s %s", spacing,
+ srcdest_rnode2str(rn, buf,
+ sizeof(buf)));
+
+ switch (nh->type) {
+ case STATIC_IPV4_GATEWAY:
+ vty_out(vty, " %s",
+ inet_ntoa(nh->addr.ipv4));
break;
- case STATIC_BLACKHOLE_NULL:
- vty_out(vty, " Null0");
+ case STATIC_IPV6_GATEWAY:
+ vty_out(vty, " %s",
+ inet_ntop(AF_INET6,
+ &nh->addr.ipv6, buf,
+ sizeof(buf)));
break;
- case STATIC_BLACKHOLE_REJECT:
- vty_out(vty, " reject");
+ case STATIC_IFNAME:
+ vty_out(vty, " %s", nh->ifname);
+ break;
+ case STATIC_BLACKHOLE:
+ switch (nh->bh_type) {
+ case STATIC_BLACKHOLE_DROP:
+ vty_out(vty, " blackhole");
+ break;
+ case STATIC_BLACKHOLE_NULL:
+ vty_out(vty, " Null0");
+ break;
+ case STATIC_BLACKHOLE_REJECT:
+ vty_out(vty, " reject");
+ break;
+ }
+ break;
+ case STATIC_IPV4_GATEWAY_IFNAME:
+ vty_out(vty, " %s %s",
+ inet_ntop(AF_INET,
+ &nh->addr.ipv4, buf,
+ sizeof(buf)),
+ nh->ifname);
+ break;
+ case STATIC_IPV6_GATEWAY_IFNAME:
+ vty_out(vty, " %s %s",
+ inet_ntop(AF_INET6,
+ &nh->addr.ipv6, buf,
+ sizeof(buf)),
+ nh->ifname);
break;
}
- break;
- case STATIC_IPV4_GATEWAY_IFNAME:
- vty_out(vty, " %s %s",
- inet_ntop(AF_INET, &si->addr.ipv4, buf,
- sizeof(buf)),
- si->ifname);
- break;
- case STATIC_IPV6_GATEWAY_IFNAME:
- vty_out(vty, " %s %s",
- inet_ntop(AF_INET6, &si->addr.ipv6, buf,
- sizeof(buf)),
- si->ifname);
- break;
- }
- if (si->tag)
- vty_out(vty, " tag %" ROUTE_TAG_PRI, si->tag);
-
- if (si->distance != ZEBRA_STATIC_DISTANCE_DEFAULT)
- vty_out(vty, " %d", si->distance);
-
- /* Label information */
- if (si->snh_label.num_labels)
- vty_out(vty, " label %s",
- mpls_label2str(si->snh_label.num_labels,
- si->snh_label.label, buf,
- sizeof(buf), 0));
-
- if (si->nh_vrf_id != si->vrf_id)
- vty_out(vty, " nexthop-vrf %s", si->nh_vrfname);
-
- /*
- * table ID from VRF overrides configured
- */
- if (si->table_id &&
- svrf->vrf->data.l.table_id == RT_TABLE_MAIN)
- vty_out(vty, " table %u", si->table_id);
-
- if (si->onlink)
- vty_out(vty, " onlink");
-
- vty_out(vty, "\n");
-
- write = 1;
+ if (pn->tag)
+ vty_out(vty, " tag %" ROUTE_TAG_PRI,
+ pn->tag);
+
+ if (pn->distance
+ != ZEBRA_STATIC_DISTANCE_DEFAULT)
+ vty_out(vty, " %u", pn->distance);
+
+ /* Label information */
+ if (nh->snh_label.num_labels)
+ vty_out(vty, " label %s",
+ mpls_label2str(
+ nh->snh_label
+ .num_labels,
+ nh->snh_label.label,
+ buf, sizeof(buf), 0));
+
+ if (nh->nh_vrf_id != GET_STABLE_VRF_ID(info))
+ vty_out(vty, " nexthop-vrf %s",
+ nh->nh_vrfname);
+
+ /*
+ * table ID from VRF overrides
+ * configured
+ */
+ if (pn->table_id
+ && svrf->vrf->data.l.table_id
+ == RT_TABLE_MAIN)
+ vty_out(vty, " table %u", pn->table_id);
+
+ if (nh->onlink)
+ vty_out(vty, " onlink");
+
+ vty_out(vty, "\n");
+
+ write = 1;
+ }
}
+ }
return write;
}
/* Static unicast routes for multicast RPF lookup. */
-DEFPY (ip_mroute_dist,
+DEFPY_YANG (ip_mroute_dist,
ip_mroute_dist_cmd,
"[no] ip mroute A.B.C.D/M$prefix <A.B.C.D$gate|INTERFACE$ifname> [(1-255)$distance]",
NO_STR
@@ -752,7 +468,7 @@ DEFPY (ip_mroute_dist,
}
/* Static route configuration. */
-DEFPY(ip_route_blackhole,
+DEFPY_YANG(ip_route_blackhole,
ip_route_blackhole_cmd,
"[no] ip route\
<A.B.C.D/M$prefix|A.B.C.D$prefix A.B.C.D$mask> \
@@ -790,7 +506,7 @@ DEFPY(ip_route_blackhole,
distance_str, vrf, label, table_str);
}
-DEFPY(ip_route_blackhole_vrf,
+DEFPY_YANG(ip_route_blackhole_vrf,
ip_route_blackhole_vrf_cmd,
"[no] ip route\
<A.B.C.D/M$prefix|A.B.C.D$prefix A.B.C.D$mask> \
@@ -815,28 +531,29 @@ DEFPY(ip_route_blackhole_vrf,
"Table to configure\n"
"The table number to configure\n")
{
- VTY_DECLVAR_CONTEXT(vrf, vrf);
- struct static_vrf *svrf = vrf->info;
+ const struct lyd_node *vrf_dnode;
+ const char *vrfname;
- if (table_str && !vrf_is_backend_netns()) {
- vty_out(vty,
- "%% table param only available when running on netns-based vrfs\n");
+ vrf_dnode =
+ yang_dnode_get(vty->candidate_config->dnode, VTY_CURR_XPATH);
+ if (!vrf_dnode) {
+ vty_out(vty, "%% Failed to get vrf dnode in candidate db\n");
return CMD_WARNING_CONFIG_FAILED;
}
-
+ vrfname = yang_dnode_get_string(vrf_dnode, "./name");
/*
* Coverity is complaining that prefix could
* be dereferenced, but we know that prefix will
* valid. Add an assert to make it happy
*/
assert(prefix);
- return static_route_leak(vty, svrf, svrf, AFI_IP, SAFI_UNICAST, no,
- prefix, mask_str, NULL, NULL, NULL, flag,
+ return static_route_leak(vty, vrfname, vrfname, AFI_IP, SAFI_UNICAST,
+ no, prefix, mask_str, NULL, NULL, NULL, flag,
tag_str, distance_str, label, table_str,
false);
}
-DEFPY(ip_route_address_interface,
+DEFPY_YANG(ip_route_address_interface,
ip_route_address_interface_cmd,
"[no] ip route\
<A.B.C.D/M$prefix|A.B.C.D$prefix A.B.C.D$mask> \
@@ -869,44 +586,28 @@ DEFPY(ip_route_address_interface,
VRF_CMD_HELP_STR
"Treat the nexthop as directly attached to the interface\n")
{
- struct static_vrf *svrf;
- struct static_vrf *nh_svrf;
+ const char *nh_vrf;
const char *flag = NULL;
if (ifname && !strncasecmp(ifname, "Null0", 5)) {
flag = "Null0";
ifname = NULL;
}
-
- svrf = static_vty_get_unknown_vrf(vty, vrf);
- if (!svrf) {
- vty_out(vty, "%% vrf %s is not defined\n", vrf);
- return CMD_WARNING_CONFIG_FAILED;
- }
-
- if (table_str && vrf && !vrf_is_backend_netns()) {
- vty_out(vty,
- "%% table param only available when running on netns-based vrfs\n");
- return CMD_WARNING_CONFIG_FAILED;
- }
+ if (!vrf)
+ vrf = VRF_DEFAULT_NAME;
if (nexthop_vrf)
- nh_svrf = static_vty_get_unknown_vrf(vty, nexthop_vrf);
+ nh_vrf = nexthop_vrf;
else
- nh_svrf = svrf;
+ nh_vrf = vrf;
- if (!nh_svrf) {
- vty_out(vty, "%% nexthop vrf %s is not defined\n", nexthop_vrf);
- return CMD_WARNING_CONFIG_FAILED;
- }
-
- return static_route_leak(vty, svrf, nh_svrf, AFI_IP, SAFI_UNICAST, no,
+ return static_route_leak(vty, vrf, nh_vrf, AFI_IP, SAFI_UNICAST, no,
prefix, mask_str, NULL, gate_str, ifname, flag,
tag_str, distance_str, label, table_str,
!!onlink);
}
-DEFPY(ip_route_address_interface_vrf,
+DEFPY_YANG(ip_route_address_interface_vrf,
ip_route_address_interface_vrf_cmd,
"[no] ip route\
<A.B.C.D/M$prefix|A.B.C.D$prefix A.B.C.D$mask> \
@@ -937,39 +638,35 @@ DEFPY(ip_route_address_interface_vrf,
VRF_CMD_HELP_STR
"Treat the nexthop as directly attached to the interface\n")
{
- VTY_DECLVAR_CONTEXT(vrf, vrf);
+ const char *nh_vrf;
const char *flag = NULL;
- struct static_vrf *svrf = vrf->info;
- struct static_vrf *nh_svrf;
+ const struct lyd_node *vrf_dnode;
+ const char *vrfname;
- if (table_str && !vrf_is_backend_netns()) {
- vty_out(vty,
- "%% table param only available when running on netns-based vrfs\n");
+ vrf_dnode =
+ yang_dnode_get(vty->candidate_config->dnode, VTY_CURR_XPATH);
+ if (!vrf_dnode) {
+ vty_out(vty, "%% Failed to get vrf dnode in candidate db\n");
return CMD_WARNING_CONFIG_FAILED;
}
+ vrfname = yang_dnode_get_string(vrf_dnode, "./name");
if (ifname && !strncasecmp(ifname, "Null0", 5)) {
flag = "Null0";
ifname = NULL;
}
-
if (nexthop_vrf)
- nh_svrf = static_vty_get_unknown_vrf(vty, nexthop_vrf);
+ nh_vrf = nexthop_vrf;
else
- nh_svrf = svrf;
-
- if (!nh_svrf) {
- vty_out(vty, "%% nexthop vrf %s is not defined\n", nexthop_vrf);
- return CMD_WARNING_CONFIG_FAILED;
- }
+ nh_vrf = vrfname;
- return static_route_leak(vty, svrf, nh_svrf, AFI_IP, SAFI_UNICAST, no,
+ return static_route_leak(vty, vrfname, nh_vrf, AFI_IP, SAFI_UNICAST, no,
prefix, mask_str, NULL, gate_str, ifname, flag,
tag_str, distance_str, label, table_str,
!!onlink);
}
-DEFPY(ip_route,
+DEFPY_YANG(ip_route,
ip_route_cmd,
"[no] ip route\
<A.B.C.D/M$prefix|A.B.C.D$prefix A.B.C.D$mask> \
@@ -999,44 +696,29 @@ DEFPY(ip_route,
"The table number to configure\n"
VRF_CMD_HELP_STR)
{
- struct static_vrf *svrf;
- struct static_vrf *nh_svrf;
+ const char *nh_vrf;
const char *flag = NULL;
- if (table_str && vrf && !vrf_is_backend_netns()) {
- vty_out(vty,
- "%% table param only available when running on netns-based vrfs\n");
- return CMD_WARNING_CONFIG_FAILED;
- }
-
if (ifname && !strncasecmp(ifname, "Null0", 5)) {
flag = "Null0";
ifname = NULL;
}
- svrf = static_vty_get_unknown_vrf(vty, vrf);
- if (!svrf) {
- vty_out(vty, "%% vrf %s is not defined\n", vrf);
- return CMD_WARNING_CONFIG_FAILED;
- }
+ if (!vrf)
+ vrf = VRF_DEFAULT_NAME;
if (nexthop_vrf)
- nh_svrf = static_vty_get_unknown_vrf(vty, nexthop_vrf);
+ nh_vrf = nexthop_vrf;
else
- nh_svrf = svrf;
+ nh_vrf = vrf;
- if (!nh_svrf) {
- vty_out(vty, "%% nexthop vrf %s is not defined\n", nexthop_vrf);
- return CMD_WARNING_CONFIG_FAILED;
- }
-
- return static_route_leak(
- vty, svrf, nh_svrf, AFI_IP, SAFI_UNICAST, no, prefix, mask_str,
- NULL, gate_str, ifname, flag, tag_str, distance_str, label,
- table_str, false);
+ return static_route_leak(vty, vrf, nh_vrf, AFI_IP, SAFI_UNICAST, no,
+ prefix, mask_str, NULL, gate_str, ifname, flag,
+ tag_str, distance_str, label, table_str,
+ false);
}
-DEFPY(ip_route_vrf,
+DEFPY_YANG(ip_route_vrf,
ip_route_vrf_cmd,
"[no] ip route\
<A.B.C.D/M$prefix|A.B.C.D$prefix A.B.C.D$mask> \
@@ -1064,39 +746,36 @@ DEFPY(ip_route_vrf,
"The table number to configure\n"
VRF_CMD_HELP_STR)
{
- VTY_DECLVAR_CONTEXT(vrf, vrf);
- struct static_vrf *svrf = vrf->info;
- struct static_vrf *nh_svrf;
+ const char *nh_vrf;
const char *flag = NULL;
+ const struct lyd_node *vrf_dnode;
+ const char *vrfname;
- if (table_str && !vrf_is_backend_netns()) {
- vty_out(vty,
- "%% table param only available when running on netns-based vrfs\n");
+ vrf_dnode =
+ yang_dnode_get(vty->candidate_config->dnode, VTY_CURR_XPATH);
+ if (!vrf_dnode) {
+ vty_out(vty, "%% Failed to get vrf dnode in candidate db\n");
return CMD_WARNING_CONFIG_FAILED;
}
+ vrfname = yang_dnode_get_string(vrf_dnode, "./name");
+
if (ifname && !strncasecmp(ifname, "Null0", 5)) {
flag = "Null0";
ifname = NULL;
}
-
if (nexthop_vrf)
- nh_svrf = static_vty_get_unknown_vrf(vty, nexthop_vrf);
+ nh_vrf = nexthop_vrf;
else
- nh_svrf = svrf;
-
- if (!nh_svrf) {
- vty_out(vty, "%% nexthop vrf %s is not defined\n", nexthop_vrf);
- return CMD_WARNING_CONFIG_FAILED;
- }
+ nh_vrf = vrfname;
- return static_route_leak(
- vty, svrf, nh_svrf, AFI_IP, SAFI_UNICAST, no, prefix, mask_str,
- NULL, gate_str, ifname, flag, tag_str, distance_str, label,
- table_str, false);
+ return static_route_leak(vty, vrfname, nh_vrf, AFI_IP, SAFI_UNICAST, no,
+ prefix, mask_str, NULL, gate_str, ifname, flag,
+ tag_str, distance_str, label, table_str,
+ false);
}
-DEFPY(ipv6_route_blackhole,
+DEFPY_YANG(ipv6_route_blackhole,
ipv6_route_blackhole_cmd,
"[no] ipv6 route X:X::X:X/M$prefix [from X:X::X:X/M] \
<reject|blackhole>$flag \
@@ -1134,7 +813,7 @@ DEFPY(ipv6_route_blackhole,
distance_str, vrf, label, table_str);
}
-DEFPY(ipv6_route_blackhole_vrf,
+DEFPY_YANG(ipv6_route_blackhole_vrf,
ipv6_route_blackhole_vrf_cmd,
"[no] ipv6 route X:X::X:X/M$prefix [from X:X::X:X/M] \
<reject|blackhole>$flag \
@@ -1159,14 +838,16 @@ DEFPY(ipv6_route_blackhole_vrf,
"Table to configure\n"
"The table number to configure\n")
{
- VTY_DECLVAR_CONTEXT(vrf, vrf);
- struct static_vrf *svrf = vrf->info;
+ const struct lyd_node *vrf_dnode;
+ const char *vrfname;
- if (table_str && !vrf_is_backend_netns()) {
- vty_out(vty,
- "%% table param only available when running on netns-based vrfs\n");
+ vrf_dnode =
+ yang_dnode_get(vty->candidate_config->dnode, VTY_CURR_XPATH);
+ if (!vrf_dnode) {
+ vty_out(vty, "%% Failed to get vrf dnode in candidate db\n");
return CMD_WARNING_CONFIG_FAILED;
}
+ vrfname = yang_dnode_get_string(vrf_dnode, "./name");
/*
* Coverity is complaining that prefix could
@@ -1174,13 +855,14 @@ DEFPY(ipv6_route_blackhole_vrf,
* valid. Add an assert to make it happy
*/
assert(prefix);
- return static_route_leak(
- vty, svrf, svrf, AFI_IP6, SAFI_UNICAST, no, prefix_str, NULL,
- from_str, NULL, NULL, flag, tag_str, distance_str, label,
- table_str, false);
+
+ return static_route_leak(vty, vrfname, vrfname, AFI_IP6, SAFI_UNICAST,
+ no, prefix_str, NULL, from_str, NULL, NULL,
+ flag, tag_str, distance_str, label, table_str,
+ false);
}
-DEFPY(ipv6_route_address_interface,
+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 \
@@ -1213,44 +895,29 @@ DEFPY(ipv6_route_address_interface,
VRF_CMD_HELP_STR
"Treat the nexthop as directly attached to the interface\n")
{
- struct static_vrf *svrf;
- struct static_vrf *nh_svrf;
+ const char *nh_vrf;
const char *flag = NULL;
- if (table_str && vrf && !vrf_is_backend_netns()) {
- vty_out(vty,
- "%% table param only available when running on netns-based vrfs\n");
- return CMD_WARNING_CONFIG_FAILED;
+ if (ifname && !strncasecmp(ifname, "Null0", 5)) {
+ flag = "Null0";
+ ifname = NULL;
}
- svrf = static_vty_get_unknown_vrf(vty, vrf);
- if (!svrf) {
- vty_out(vty, "%% vrf %s is not defined\n", vrf);
- return CMD_WARNING_CONFIG_FAILED;
- }
+ if (!vrf)
+ vrf = VRF_DEFAULT_NAME;
if (nexthop_vrf)
- nh_svrf = static_vty_get_unknown_vrf(vty, nexthop_vrf);
+ nh_vrf = nexthop_vrf;
else
- nh_svrf = svrf;
-
- if (!nh_svrf) {
- vty_out(vty, "%% nexthop vrf %s is not defined\n", nexthop_vrf);
- return CMD_WARNING_CONFIG_FAILED;
- }
+ nh_vrf = vrf;
- if (ifname && !strncasecmp(ifname, "Null0", 5)) {
- flag = "Null0";
- ifname = NULL;
- }
-
- return static_route_leak(
- vty, svrf, nh_svrf, AFI_IP6, SAFI_UNICAST, no, prefix_str, NULL,
- from_str, gate_str, ifname, flag, tag_str, distance_str, label,
- table_str, !!onlink);
+ return static_route_leak(vty, vrf, nh_vrf, AFI_IP6, SAFI_UNICAST, no,
+ prefix_str, NULL, from_str, gate_str, ifname,
+ flag, tag_str, distance_str, label, table_str,
+ !!onlink);
}
-DEFPY(ipv6_route_address_interface_vrf,
+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] \
X:X::X:X$gate \
@@ -1281,39 +948,35 @@ DEFPY(ipv6_route_address_interface_vrf,
VRF_CMD_HELP_STR
"Treat the nexthop as directly attached to the interface\n")
{
- VTY_DECLVAR_CONTEXT(vrf, vrf);
- struct static_vrf *svrf = vrf->info;
- struct static_vrf *nh_svrf;
+ const char *nh_vrf;
const char *flag = NULL;
+ const struct lyd_node *vrf_dnode;
+ const char *vrfname;
- if (table_str && !vrf_is_backend_netns()) {
- vty_out(vty,
- "%% table param only available when running on netns-based vrfs\n");
+ vrf_dnode =
+ yang_dnode_get(vty->candidate_config->dnode, VTY_CURR_XPATH);
+ if (!vrf_dnode) {
+ vty_out(vty, "%% Failed to get vrf dnode in candidate db\n");
return CMD_WARNING_CONFIG_FAILED;
}
+ vrfname = yang_dnode_get_string(vrf_dnode, "./name");
if (nexthop_vrf)
- nh_svrf = static_vty_get_unknown_vrf(vty, nexthop_vrf);
+ nh_vrf = nexthop_vrf;
else
- nh_svrf = svrf;
-
- if (!nh_svrf) {
- vty_out(vty, "%% nexthop vrf %s is not defined\n", nexthop_vrf);
- return CMD_WARNING_CONFIG_FAILED;
- }
+ nh_vrf = vrfname;
if (ifname && !strncasecmp(ifname, "Null0", 5)) {
flag = "Null0";
ifname = NULL;
}
-
- return static_route_leak(
- vty, svrf, nh_svrf, AFI_IP6, SAFI_UNICAST, no, prefix_str, NULL,
- from_str, gate_str, ifname, flag, tag_str, distance_str, label,
- table_str, !!onlink);
+ return static_route_leak(vty, vrfname, nh_vrf, AFI_IP6, SAFI_UNICAST,
+ no, prefix_str, NULL, from_str, gate_str,
+ ifname, flag, tag_str, distance_str, label,
+ table_str, !!onlink);
}
-DEFPY(ipv6_route,
+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> \
@@ -1343,44 +1006,28 @@ DEFPY(ipv6_route,
"The table number to configure\n"
VRF_CMD_HELP_STR)
{
- struct static_vrf *svrf;
- struct static_vrf *nh_svrf;
+ const char *nh_vrf;
const char *flag = NULL;
- if (table_str && vrf && !vrf_is_backend_netns()) {
- vty_out(vty,
- "%% table param only available when running on netns-based vrfs\n");
- return CMD_WARNING_CONFIG_FAILED;
- }
-
- svrf = static_vty_get_unknown_vrf(vty, vrf);
- if (!svrf) {
- vty_out(vty, "%% vrf %s is not defined\n", vrf);
- return CMD_WARNING_CONFIG_FAILED;
- }
+ if (!vrf)
+ vrf = VRF_DEFAULT_NAME;
if (nexthop_vrf)
- nh_svrf = static_vty_get_unknown_vrf(vty, nexthop_vrf);
+ nh_vrf = nexthop_vrf;
else
- nh_svrf = svrf;
-
- if (!nh_svrf) {
- vty_out(vty, "%% nexthop vrf %s is not defined\n", nexthop_vrf);
- return CMD_WARNING_CONFIG_FAILED;
- }
+ nh_vrf = vrf;
if (ifname && !strncasecmp(ifname, "Null0", 5)) {
flag = "Null0";
ifname = NULL;
}
-
- return static_route_leak(
- vty, svrf, nh_svrf, AFI_IP6, SAFI_UNICAST, no, prefix_str, NULL,
- from_str, gate_str, ifname, flag, tag_str, distance_str, label,
- table_str, false);
+ return static_route_leak(vty, vrf, nh_vrf, AFI_IP6, SAFI_UNICAST, no,
+ prefix_str, NULL, from_str, gate_str, ifname,
+ flag, tag_str, distance_str, label, table_str,
+ false);
}
-DEFPY(ipv6_route_vrf,
+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> \
@@ -1408,38 +1055,34 @@ DEFPY(ipv6_route_vrf,
"The table number to configure\n"
VRF_CMD_HELP_STR)
{
- VTY_DECLVAR_CONTEXT(vrf, vrf);
- struct static_vrf *svrf = vrf->info;
- struct static_vrf *nh_svrf;
+ const char *nh_vrf;
const char *flag = NULL;
+ const struct lyd_node *vrf_dnode;
+ const char *vrfname;
- if (table_str && !vrf_is_backend_netns()) {
- vty_out(vty,
- "%% table param only available when running on netns-based vrfs\n");
+ vrf_dnode =
+ yang_dnode_get(vty->candidate_config->dnode, VTY_CURR_XPATH);
+ if (!vrf_dnode) {
+ vty_out(vty, "%% Failed to get vrf dnode in candidate db\n");
return CMD_WARNING_CONFIG_FAILED;
}
+ vrfname = yang_dnode_get_string(vrf_dnode, "./name");
if (nexthop_vrf)
- nh_svrf = static_vty_get_unknown_vrf(vty, nexthop_vrf);
+ nh_vrf = nexthop_vrf;
else
- nh_svrf = svrf;
-
- if (!nh_svrf) {
- vty_out(vty, "%% nexthop vrf %s is not defined\n", nexthop_vrf);
- return CMD_WARNING_CONFIG_FAILED;
- }
+ nh_vrf = vrfname;
if (ifname && !strncasecmp(ifname, "Null0", 5)) {
flag = "Null0";
ifname = NULL;
}
-
- return static_route_leak(
- vty, svrf, nh_svrf, AFI_IP6, SAFI_UNICAST, no, prefix_str, NULL,
- from_str, gate_str, ifname, flag, tag_str, distance_str, label,
- table_str, false);
+ return static_route_leak(vty, vrfname, nh_vrf, AFI_IP6, SAFI_UNICAST,
+ no, prefix_str, NULL, from_str, gate_str,
+ ifname, flag, tag_str, distance_str, label,
+ table_str, false);
}
-DEFPY(debug_staticd,
+DEFPY_YANG(debug_staticd,
debug_staticd_cmd,
"[no] debug static [{events$events}]",
NO_STR
@@ -1500,8 +1143,4 @@ void static_vty_init(void)
install_element(VIEW_NODE, &show_debugging_static_cmd);
install_element(VIEW_NODE, &debug_staticd_cmd);
install_element(CONFIG_NODE, &debug_staticd_cmd);
-
- static_list = list_new();
- static_list->cmp = (int (*)(void *, void *))static_list_compare;
- static_list->del = (void (*)(void *))static_list_delete;
}
diff --git a/staticd/static_vty.h b/staticd/static_vty.h
index 2f65c08b8b..7ffc8d9c98 100644
--- a/staticd/static_vty.h
+++ b/staticd/static_vty.h
@@ -19,8 +19,6 @@
#ifndef __STATIC_VTY_H__
#define __STATIC_VTY_H__
-void static_config_install_delayed_routes(struct static_vrf *svrf);
-
int static_config(struct vty *vty, struct static_vrf *svrf,
afi_t afi, safi_t safi, const char *cmd);
diff --git a/staticd/static_zebra.c b/staticd/static_zebra.c
index c42f632ffb..d8a4b7f0cb 100644
--- a/staticd/static_zebra.c
+++ b/staticd/static_zebra.c
@@ -89,7 +89,6 @@ static int static_ifp_up(struct interface *ifp)
struct static_vrf *svrf = static_vrf_lookup_by_id(ifp->vrf_id);
static_fixup_vrf_ids(svrf);
- static_config_install_delayed_routes(svrf);
}
/* Install any static reliant on this interface coming up */
@@ -265,8 +264,8 @@ static void static_nht_hash_free(void *data)
XFREE(MTYPE_TMP, nhtd);
}
-void static_zebra_nht_register(struct route_node *rn,
- struct static_route *si, bool reg)
+void static_zebra_nht_register(struct route_node *rn, struct static_nexthop *nh,
+ bool reg)
{
struct static_nht_data *nhtd, lookup;
uint32_t cmd;
@@ -276,14 +275,14 @@ void static_zebra_nht_register(struct route_node *rn,
cmd = (reg) ?
ZEBRA_NEXTHOP_REGISTER : ZEBRA_NEXTHOP_UNREGISTER;
- if (si->nh_registered && reg)
+ if (nh->nh_registered && reg)
return;
- if (!si->nh_registered && !reg)
+ if (!nh->nh_registered && !reg)
return;
memset(&p, 0, sizeof(p));
- switch (si->type) {
+ switch (nh->type) {
case STATIC_IFNAME:
case STATIC_BLACKHOLE:
return;
@@ -291,23 +290,23 @@ void static_zebra_nht_register(struct route_node *rn,
case STATIC_IPV4_GATEWAY_IFNAME:
p.family = AF_INET;
p.prefixlen = IPV4_MAX_BITLEN;
- p.u.prefix4 = si->addr.ipv4;
+ p.u.prefix4 = nh->addr.ipv4;
afi = AFI_IP;
break;
case STATIC_IPV6_GATEWAY:
case STATIC_IPV6_GATEWAY_IFNAME:
p.family = AF_INET6;
p.prefixlen = IPV6_MAX_BITLEN;
- p.u.prefix6 = si->addr.ipv6;
+ p.u.prefix6 = nh->addr.ipv6;
afi = AFI_IP6;
break;
}
memset(&lookup, 0, sizeof(lookup));
lookup.nh = &p;
- lookup.nh_vrf_id = si->nh_vrf_id;
+ lookup.nh_vrf_id = nh->nh_vrf_id;
- si->nh_registered = reg;
+ nh->nh_registered = reg;
if (reg) {
nhtd = hash_get(static_nht_hash, &lookup,
@@ -318,8 +317,8 @@ void static_zebra_nht_register(struct route_node *rn,
zlog_debug("Registered nexthop(%pFX) for %pRN %d", &p,
rn, nhtd->nh_num);
if (nhtd->refcount > 1 && nhtd->nh_num) {
- static_nht_update(&rn->p, nhtd->nh, nhtd->nh_num,
- afi, si->nh_vrf_id);
+ static_nht_update(&rn->p, nhtd->nh, nhtd->nh_num, afi,
+ nh->nh_vrf_id);
return;
}
} else {
@@ -335,25 +334,72 @@ void static_zebra_nht_register(struct route_node *rn,
static_nht_hash_free(nhtd);
}
- if (zclient_send_rnh(zclient, cmd, &p, false, si->nh_vrf_id) < 0)
+ if (zclient_send_rnh(zclient, cmd, &p, false, nh->nh_vrf_id) < 0)
zlog_warn("%s: Failure to send nexthop to zebra", __func__);
}
+/*
+ * When nexthop gets updated via configuration then use the
+ * already registered NH and resend the route to zebra
+ */
+int static_zebra_nh_update(struct route_node *rn, struct static_nexthop *nh)
+{
+ struct static_nht_data *nhtd, lookup = {};
+ struct prefix p = {};
+ afi_t afi = AFI_IP;
+
+ if (!nh->nh_registered)
+ return 0;
+
+ switch (nh->type) {
+ case STATIC_IFNAME:
+ case STATIC_BLACKHOLE:
+ return 0;
+ case STATIC_IPV4_GATEWAY:
+ case STATIC_IPV4_GATEWAY_IFNAME:
+ p.family = AF_INET;
+ p.prefixlen = IPV4_MAX_BITLEN;
+ p.u.prefix4 = nh->addr.ipv4;
+ afi = AFI_IP;
+ break;
+ case STATIC_IPV6_GATEWAY:
+ case STATIC_IPV6_GATEWAY_IFNAME:
+ p.family = AF_INET6;
+ p.prefixlen = IPV6_MAX_BITLEN;
+ p.u.prefix6 = nh->addr.ipv6;
+ afi = AFI_IP6;
+ break;
+ }
+
+ lookup.nh = &p;
+ lookup.nh_vrf_id = nh->nh_vrf_id;
+
+ nhtd = hash_lookup(static_nht_hash, &lookup);
+ if (nhtd && nhtd->nh_num) {
+ nh->state = STATIC_START;
+ static_nht_update(&rn->p, nhtd->nh, nhtd->nh_num, afi,
+ nh->nh_vrf_id);
+ return 1;
+ }
+ return 0;
+}
extern void static_zebra_route_add(struct route_node *rn,
- struct static_route *si_changed,
- vrf_id_t vrf_id, safi_t safi, bool install)
+ struct static_path *pn, safi_t safi,
+ bool install)
{
- struct static_route *si = rn->info;
+ struct static_nexthop *nh;
const struct prefix *p, *src_pp;
struct zapi_nexthop *api_nh;
struct zapi_route api;
uint32_t nh_num = 0;
+ struct stable_info *info;
p = src_pp = NULL;
srcdest_rnode_prefixes(rn, &p, &src_pp);
memset(&api, 0, sizeof(api));
- api.vrf_id = vrf_id;
+ info = static_get_stable_info(rn);
+ api.vrf_id = GET_STABLE_VRF_ID(info);
api.type = ZEBRA_ROUTE_STATIC;
api.safi = safi;
memcpy(&api.prefix, p, sizeof(api.prefix));
@@ -365,71 +411,65 @@ extern void static_zebra_route_add(struct route_node *rn,
SET_FLAG(api.flags, ZEBRA_FLAG_RR_USE_DISTANCE);
SET_FLAG(api.flags, ZEBRA_FLAG_ALLOW_RECURSION);
SET_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP);
- if (si_changed->distance) {
+ if (pn->distance) {
SET_FLAG(api.message, ZAPI_MESSAGE_DISTANCE);
- api.distance = si_changed->distance;
+ api.distance = pn->distance;
}
- if (si_changed->tag) {
+ if (pn->tag) {
SET_FLAG(api.message, ZAPI_MESSAGE_TAG);
- api.tag = si_changed->tag;
+ api.tag = pn->tag;
}
- if (si_changed->table_id != 0) {
+ if (pn->table_id != 0) {
SET_FLAG(api.message, ZAPI_MESSAGE_TABLEID);
- api.tableid = si_changed->table_id;
+ api.tableid = pn->table_id;
}
- for (/*loaded above*/; si; si = si->next) {
+ frr_each(static_nexthop_list, &pn->nexthop_list, nh) {
api_nh = &api.nexthops[nh_num];
- if (si->nh_vrf_id == VRF_UNKNOWN)
- continue;
-
- if (si->distance != si_changed->distance)
- continue;
-
- if (si->table_id != si_changed->table_id)
+ if (nh->nh_vrf_id == VRF_UNKNOWN)
continue;
- api_nh->vrf_id = si->nh_vrf_id;
- if (si->onlink)
+ api_nh->vrf_id = nh->nh_vrf_id;
+ if (nh->onlink)
SET_FLAG(api_nh->flags, ZAPI_NEXTHOP_FLAG_ONLINK);
- si->state = STATIC_SENT_TO_ZEBRA;
+ nh->state = STATIC_SENT_TO_ZEBRA;
- switch (si->type) {
+ switch (nh->type) {
case STATIC_IFNAME:
- if (si->ifindex == IFINDEX_INTERNAL)
+ if (nh->ifindex == IFINDEX_INTERNAL)
continue;
- api_nh->ifindex = si->ifindex;
+ api_nh->ifindex = nh->ifindex;
api_nh->type = NEXTHOP_TYPE_IFINDEX;
break;
case STATIC_IPV4_GATEWAY:
- if (!si->nh_valid)
+ if (!nh->nh_valid)
continue;
api_nh->type = NEXTHOP_TYPE_IPV4;
- api_nh->gate = si->addr;
+ api_nh->gate = nh->addr;
break;
case STATIC_IPV4_GATEWAY_IFNAME:
- if (si->ifindex == IFINDEX_INTERNAL)
+ if (nh->ifindex == IFINDEX_INTERNAL)
continue;
- api_nh->ifindex = si->ifindex;
+ api_nh->ifindex = nh->ifindex;
api_nh->type = NEXTHOP_TYPE_IPV4_IFINDEX;
- api_nh->gate = si->addr;
+ api_nh->gate = nh->addr;
break;
case STATIC_IPV6_GATEWAY:
- if (!si->nh_valid)
+ if (!nh->nh_valid)
continue;
api_nh->type = NEXTHOP_TYPE_IPV6;
- api_nh->gate = si->addr;
+ api_nh->gate = nh->addr;
break;
case STATIC_IPV6_GATEWAY_IFNAME:
- if (si->ifindex == IFINDEX_INTERNAL)
+ if (nh->ifindex == IFINDEX_INTERNAL)
continue;
api_nh->type = NEXTHOP_TYPE_IPV6_IFINDEX;
- api_nh->ifindex = si->ifindex;
- api_nh->gate = si->addr;
+ api_nh->ifindex = nh->ifindex;
+ api_nh->gate = nh->addr;
break;
case STATIC_BLACKHOLE:
api_nh->type = NEXTHOP_TYPE_BLACKHOLE;
- switch (si->bh_type) {
+ switch (nh->bh_type) {
case STATIC_BLACKHOLE_DROP:
case STATIC_BLACKHOLE_NULL:
api_nh->bh_type = BLACKHOLE_NULL;
@@ -440,13 +480,13 @@ extern void static_zebra_route_add(struct route_node *rn,
break;
}
- if (si->snh_label.num_labels) {
+ if (nh->snh_label.num_labels) {
int i;
SET_FLAG(api_nh->flags, ZAPI_NEXTHOP_FLAG_LABEL);
- api_nh->label_num = si->snh_label.num_labels;
+ api_nh->label_num = nh->snh_label.num_labels;
for (i = 0; i < api_nh->label_num; i++)
- api_nh->labels[i] = si->snh_label.label[i];
+ api_nh->labels[i] = nh->snh_label.label[i];
}
nh_num++;
}
diff --git a/staticd/static_zebra.h b/staticd/static_zebra.h
index 962dc3908f..9f93f3ee63 100644
--- a/staticd/static_zebra.h
+++ b/staticd/static_zebra.h
@@ -22,13 +22,15 @@
extern struct thread_master *master;
extern void static_zebra_nht_register(struct route_node *rn,
- struct static_route *si, bool reg);
+ struct static_nexthop *nh, bool reg);
extern void static_zebra_route_add(struct route_node *rn,
- struct static_route *si_changed,
- vrf_id_t vrf_id, safi_t safi, bool install);
+ struct static_path *pn, safi_t safi,
+ bool install);
extern void static_zebra_init(void);
extern void static_zebra_vrf_register(struct vrf *vrf);
extern void static_zebra_vrf_unregister(struct vrf *vrf);
+extern int static_zebra_nh_update(struct route_node *rn,
+ struct static_nexthop *nh);
#endif
diff --git a/staticd/subdir.am b/staticd/subdir.am
index f2b3d11f29..eba7f270bb 100644
--- a/staticd/subdir.am
+++ b/staticd/subdir.am
@@ -18,6 +18,8 @@ staticd_libstatic_a_SOURCES = \
staticd/static_zebra.c \
staticd/static_vrf.c \
staticd/static_vty.c \
+ staticd/static_nb.c \
+ staticd/static_nb_config.c \
# end
noinst_HEADERS += \
@@ -28,6 +30,7 @@ noinst_HEADERS += \
staticd/static_routes.h \
staticd/static_vty.h \
staticd/static_vrf.h \
+ staticd/static_nb.h \
# end
clippy_scan += \
@@ -36,3 +39,7 @@ clippy_scan += \
staticd_staticd_SOURCES = staticd/static_main.c
staticd_staticd_LDADD = staticd/libstatic.a lib/libfrr.la $(LIBCAP)
+
+nodist_staticd_staticd_SOURCES = \
+ yang/frr-staticd.yang.c \
+ # end
diff --git a/tests/topotests/all-protocol-startup/r1/show_route_map.ref b/tests/topotests/all-protocol-startup/r1/show_route_map.ref
index 25786081d1..612d0a729d 100644
--- a/tests/topotests/all-protocol-startup/r1/show_route_map.ref
+++ b/tests/topotests/all-protocol-startup/r1/show_route_map.ref
@@ -1,5 +1,5 @@
ZEBRA:
-route-map: LIES Invoked: 0 Optimization: enabled
+route-map: LIES Invoked: 0 Optimization: enabled Processed Change: false
deny, sequence 10 Invoked 0
Match clauses:
interface notpresent
@@ -8,7 +8,7 @@ route-map: LIES Invoked: 0 Optimization: enabled
Action:
Exit routemap
RIP:
-route-map: LIES Invoked: 0 Optimization: enabled
+route-map: LIES Invoked: 0 Optimization: enabled Processed Change: false
deny, sequence 10 Invoked 0
Match clauses:
interface notpresent
@@ -17,7 +17,7 @@ route-map: LIES Invoked: 0 Optimization: enabled
Action:
Exit routemap
RIPNG:
-route-map: LIES Invoked: 0 Optimization: enabled
+route-map: LIES Invoked: 0 Optimization: enabled Processed Change: false
deny, sequence 10 Invoked 0
Match clauses:
interface notpresent
@@ -26,7 +26,7 @@ route-map: LIES Invoked: 0 Optimization: enabled
Action:
Exit routemap
OSPF:
-route-map: LIES Invoked: 0 Optimization: enabled
+route-map: LIES Invoked: 0 Optimization: enabled Processed Change: false
deny, sequence 10 Invoked 0
Match clauses:
interface notpresent
@@ -35,7 +35,7 @@ route-map: LIES Invoked: 0 Optimization: enabled
Action:
Exit routemap
OSPF6:
-route-map: LIES Invoked: 0 Optimization: enabled
+route-map: LIES Invoked: 0 Optimization: enabled Processed Change: false
deny, sequence 10 Invoked 0
Match clauses:
interface notpresent
@@ -44,7 +44,7 @@ route-map: LIES Invoked: 0 Optimization: enabled
Action:
Exit routemap
BGP:
-route-map: LIES Invoked: 0 Optimization: enabled
+route-map: LIES Invoked: 0 Optimization: enabled Processed Change: false
deny, sequence 10 Invoked 0
Match clauses:
interface notpresent
@@ -52,7 +52,7 @@ route-map: LIES Invoked: 0 Optimization: enabled
Call clause:
Action:
Exit routemap
-route-map: bgp-map Invoked: 0 Optimization: enabled
+route-map: bgp-map Invoked: 0 Optimization: enabled Processed Change: false
permit, sequence 10 Invoked 0
Match clauses:
Set clauses:
@@ -70,4 +70,3 @@ route-map: bgp-map Invoked: 0 Optimization: enabled
Action:
Exit routemap
ISIS:
-SHARP:
diff --git a/tests/topotests/bfd-profiles-topo1/r3/bfd-peers-initial.json b/tests/topotests/bfd-profiles-topo1/r3/bfd-peers-initial.json
index abca1ed131..d2d0c601c3 100644
--- a/tests/topotests/bfd-profiles-topo1/r3/bfd-peers-initial.json
+++ b/tests/topotests/bfd-profiles-topo1/r3/bfd-peers-initial.json
@@ -25,14 +25,14 @@
"local": "*",
"multihop": false,
"peer": "*",
- "receive-interval": 300,
+ "receive-interval": 250,
"remote-detect-multiplier": 3,
"remote-diagnostic": "ok",
"remote-id": "*",
"remote-receive-interval": 300,
"remote-transmit-interval": 300,
"status": "up",
- "transmit-interval": 300,
+ "transmit-interval": 250,
"uptime": "*",
"vrf": "default"
}
diff --git a/tests/topotests/bfd-profiles-topo1/r3/bfdd.conf b/tests/topotests/bfd-profiles-topo1/r3/bfdd.conf
index 74dae5a60d..08eb0468d6 100644
--- a/tests/topotests/bfd-profiles-topo1/r3/bfdd.conf
+++ b/tests/topotests/bfd-profiles-topo1/r3/bfdd.conf
@@ -3,9 +3,8 @@ debug bfd network
debug bfd zebra
!
bfd
- ! profile is commented out on purpose.
- !profile fasttx
- ! receive-interval 250
- ! transmit-interval 250
- !!
+ profile fasttx
+ receive-interval 250
+ transmit-interval 250
+ !
!
diff --git a/tests/topotests/bfd-profiles-topo1/r3/bgpd.conf b/tests/topotests/bfd-profiles-topo1/r3/bgpd.conf
index 9c56a349ed..c7b75d2fde 100644
--- a/tests/topotests/bfd-profiles-topo1/r3/bgpd.conf
+++ b/tests/topotests/bfd-profiles-topo1/r3/bgpd.conf
@@ -1,7 +1,7 @@
router bgp 100
bgp router-id 10.254.254.3
neighbor 172.16.1.2 remote-as 100
- neighbor 172.16.1.2 bfd profile fasttx
+ neighbor 172.16.1.2 bfd profile DOES_NOT_EXIST
address-family ipv4 unicast
redistribute connected
exit-address-family
diff --git a/tests/topotests/bfd-profiles-topo1/r3/isisd.conf b/tests/topotests/bfd-profiles-topo1/r3/isisd.conf
index 5d774a356b..d27a783adf 100644
--- a/tests/topotests/bfd-profiles-topo1/r3/isisd.conf
+++ b/tests/topotests/bfd-profiles-topo1/r3/isisd.conf
@@ -8,6 +8,7 @@ interface r3-eth1
ipv6 router isis lan
isis circuit-type level-1
isis bfd
+ isis bfd profile fasttx
!
router isis lan
net 10.0000.0000.0000.0000.0000.0000.0000.0000.0001.00
diff --git a/tests/topotests/bfd-profiles-topo1/r4/bfd-peers-initial.json b/tests/topotests/bfd-profiles-topo1/r4/bfd-peers-initial.json
index c8bc4c20e9..2c2e136abf 100644
--- a/tests/topotests/bfd-profiles-topo1/r4/bfd-peers-initial.json
+++ b/tests/topotests/bfd-profiles-topo1/r4/bfd-peers-initial.json
@@ -11,8 +11,8 @@
"remote-detect-multiplier": 3,
"remote-diagnostic": "ok",
"remote-id": "*",
- "remote-receive-interval": 300,
- "remote-transmit-interval": 300,
+ "remote-receive-interval": 250,
+ "remote-transmit-interval": 250,
"status": "up",
"transmit-interval": 300,
"uptime": "*",
diff --git a/tests/topotests/bfd-profiles-topo1/r4/bgpd.conf b/tests/topotests/bfd-profiles-topo1/r4/bgpd.conf
index 7c4b39b020..aff1016dee 100644
--- a/tests/topotests/bfd-profiles-topo1/r4/bgpd.conf
+++ b/tests/topotests/bfd-profiles-topo1/r4/bgpd.conf
@@ -5,7 +5,7 @@ router bgp 200
no bgp ebgp-requires-policy
neighbor 2001:db8:1::2 remote-as 100
neighbor 2001:db8:1::2 ebgp-multihop 2
- neighbor 2001:db8:1::2 bfd profile fasttx
+ neighbor 2001:db8:1::2 bfd profile DOES_NOT_EXIST
address-family ipv4 unicast
redistribute connected
exit-address-family
diff --git a/tests/topotests/bfd-profiles-topo1/r4/isisd.conf b/tests/topotests/bfd-profiles-topo1/r4/isisd.conf
index 477740087d..01e197bed5 100644
--- a/tests/topotests/bfd-profiles-topo1/r4/isisd.conf
+++ b/tests/topotests/bfd-profiles-topo1/r4/isisd.conf
@@ -8,6 +8,7 @@ interface r4-eth0
ipv6 router isis lan
isis circuit-type level-1
isis bfd
+ isis bfd profile DOES_NOT_EXIST
!
router isis lan
net 10.0000.0000.0000.0000.0000.0000.0000.0000.0002.00
diff --git a/tests/topotests/bfd-profiles-topo1/test_bfd_profiles_topo1.py b/tests/topotests/bfd-profiles-topo1/test_bfd_profiles_topo1.py
index 02385b32e5..02385b32e5 100644..100755
--- a/tests/topotests/bfd-profiles-topo1/test_bfd_profiles_topo1.py
+++ b/tests/topotests/bfd-profiles-topo1/test_bfd_profiles_topo1.py
diff --git a/tests/topotests/bgp-evpn-mh/evpn-mh-topo-tests.pdf b/tests/topotests/bgp-evpn-mh/evpn-mh-topo-tests.pdf
new file mode 100644
index 0000000000..8858e21496
--- /dev/null
+++ b/tests/topotests/bgp-evpn-mh/evpn-mh-topo-tests.pdf
Binary files differ
diff --git a/tests/topotests/bgp-evpn-mh/hostd11/evpn.conf b/tests/topotests/bgp-evpn-mh/hostd11/evpn.conf
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/topotests/bgp-evpn-mh/hostd11/evpn.conf
diff --git a/tests/topotests/bgp-evpn-mh/hostd11/pim.conf b/tests/topotests/bgp-evpn-mh/hostd11/pim.conf
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/topotests/bgp-evpn-mh/hostd11/pim.conf
diff --git a/tests/topotests/bgp-evpn-mh/hostd11/zebra.conf b/tests/topotests/bgp-evpn-mh/hostd11/zebra.conf
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/topotests/bgp-evpn-mh/hostd11/zebra.conf
diff --git a/tests/topotests/bgp-evpn-mh/hostd12/evpn.conf b/tests/topotests/bgp-evpn-mh/hostd12/evpn.conf
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/topotests/bgp-evpn-mh/hostd12/evpn.conf
diff --git a/tests/topotests/bgp-evpn-mh/hostd12/pim.conf b/tests/topotests/bgp-evpn-mh/hostd12/pim.conf
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/topotests/bgp-evpn-mh/hostd12/pim.conf
diff --git a/tests/topotests/bgp-evpn-mh/hostd12/zebra.conf b/tests/topotests/bgp-evpn-mh/hostd12/zebra.conf
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/topotests/bgp-evpn-mh/hostd12/zebra.conf
diff --git a/tests/topotests/bgp-evpn-mh/hostd21/evpn.conf b/tests/topotests/bgp-evpn-mh/hostd21/evpn.conf
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/topotests/bgp-evpn-mh/hostd21/evpn.conf
diff --git a/tests/topotests/bgp-evpn-mh/hostd21/pim.conf b/tests/topotests/bgp-evpn-mh/hostd21/pim.conf
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/topotests/bgp-evpn-mh/hostd21/pim.conf
diff --git a/tests/topotests/bgp-evpn-mh/hostd21/zebra.conf b/tests/topotests/bgp-evpn-mh/hostd21/zebra.conf
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/topotests/bgp-evpn-mh/hostd21/zebra.conf
diff --git a/tests/topotests/bgp-evpn-mh/hostd22/evpn.conf b/tests/topotests/bgp-evpn-mh/hostd22/evpn.conf
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/topotests/bgp-evpn-mh/hostd22/evpn.conf
diff --git a/tests/topotests/bgp-evpn-mh/hostd22/pim.conf b/tests/topotests/bgp-evpn-mh/hostd22/pim.conf
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/topotests/bgp-evpn-mh/hostd22/pim.conf
diff --git a/tests/topotests/bgp-evpn-mh/hostd22/zebra.conf b/tests/topotests/bgp-evpn-mh/hostd22/zebra.conf
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/topotests/bgp-evpn-mh/hostd22/zebra.conf
diff --git a/tests/topotests/bgp-evpn-mh/spine1/evpn.conf b/tests/topotests/bgp-evpn-mh/spine1/evpn.conf
new file mode 100644
index 0000000000..2e26f60f44
--- /dev/null
+++ b/tests/topotests/bgp-evpn-mh/spine1/evpn.conf
@@ -0,0 +1,17 @@
+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
+ 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
+ exit-address-family
+!
diff --git a/tests/topotests/bgp-evpn-mh/spine1/pim.conf b/tests/topotests/bgp-evpn-mh/spine1/pim.conf
new file mode 100644
index 0000000000..68e686e8c7
--- /dev/null
+++ b/tests/topotests/bgp-evpn-mh/spine1/pim.conf
@@ -0,0 +1,18 @@
+ip pim rp 192.168.100.13
+ip pim spt-switchover infinity-and-beyond
+!
+int lo
+ ip pim
+!
+int spine1-eth0
+ ip pim
+!
+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
new file mode 100644
index 0000000000..80e9e5a263
--- /dev/null
+++ b/tests/topotests/bgp-evpn-mh/spine1/zebra.conf
@@ -0,0 +1,15 @@
+int spine1-eth0
+ ip addr 192.168.1.1/24
+!
+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
+!
+int lo
+ ip addr 192.168.100.13/32
+ ip addr 192.168.100.100/32
diff --git a/tests/topotests/bgp-evpn-mh/spine2/evpn.conf b/tests/topotests/bgp-evpn-mh/spine2/evpn.conf
new file mode 100644
index 0000000000..ec2e789276
--- /dev/null
+++ b/tests/topotests/bgp-evpn-mh/spine2/evpn.conf
@@ -0,0 +1,17 @@
+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
+ 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
+ exit-address-family
+!
diff --git a/tests/topotests/bgp-evpn-mh/spine2/pim.conf b/tests/topotests/bgp-evpn-mh/spine2/pim.conf
new file mode 100644
index 0000000000..c1566240e6
--- /dev/null
+++ b/tests/topotests/bgp-evpn-mh/spine2/pim.conf
@@ -0,0 +1,18 @@
+ip pim rp 192.168.100.13
+ip pim spt-switchover infinity-and-beyond
+!
+int lo
+ ip pim
+!
+int spine2-eth0
+ ip pim
+!
+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
new file mode 100644
index 0000000000..1cd1df8c81
--- /dev/null
+++ b/tests/topotests/bgp-evpn-mh/spine2/zebra.conf
@@ -0,0 +1,15 @@
+int spine2-eth0
+ ip addr 192.168.5.1/24
+!
+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
+!
+int lo
+ ip addr 192.168.100.14/32
+ ip addr 192.168.100.100/32
diff --git a/tests/topotests/bgp-evpn-mh/test_evpn_mh.py b/tests/topotests/bgp-evpn-mh/test_evpn_mh.py
new file mode 100755
index 0000000000..fe28f79bd4
--- /dev/null
+++ b/tests/topotests/bgp-evpn-mh/test_evpn_mh.py
@@ -0,0 +1,651 @@
+#!/usr/bin/env python
+
+#
+# test_evpn_mh.py
+#
+# Copyright (c) 2020 by
+# Cumulus Networks, Inc.
+# Anuradha Karuppiah
+#
+# 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_evpn_mh.py: Testing EVPN multihoming
+
+"""
+
+import os
+import re
+import sys
+import pytest
+import json
+import platform
+from functools import partial
+
+# 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.
+from mininet.topo import Topo
+
+#####################################################
+##
+## Network Topology Definition
+##
+## See topology picture at evpn-mh-topo-tests.pdf
+#####################################################
+
+
+class NetworkTopo(Topo):
+ '''
+ EVPN Multihoming Topology -
+ 1. Two level CLOS
+ 2. Two spine switches - spine1, spine2
+ 3. Two racks with Top-of-Rack switches per rack - tormx1, tormx2
+ 4. Two dual attached hosts per-rack - hostdx1, hostdx2
+ '''
+
+ def build(self, **_opts):
+ "Build function"
+
+ tgen = get_topogen(self)
+
+ tgen.add_router("spine1")
+ tgen.add_router("spine2")
+ tgen.add_router("torm11")
+ tgen.add_router("torm12")
+ tgen.add_router("torm21")
+ tgen.add_router("torm22")
+ tgen.add_router("hostd11")
+ tgen.add_router("hostd12")
+ tgen.add_router("hostd21")
+ tgen.add_router("hostd22")
+
+ # On main router
+ # First switch is for a dummy interface (for local network)
+
+
+ ##################### spine1 ########################
+ # spine1-eth0 is connected to torm11-eth0
+ switch = tgen.add_switch("sw1")
+ switch.add_link(tgen.gears["spine1"])
+ switch.add_link(tgen.gears["torm11"])
+
+ # spine1-eth1 is connected to torm12-eth0
+ switch = tgen.add_switch("sw2")
+ switch.add_link(tgen.gears["spine1"])
+ switch.add_link(tgen.gears["torm12"])
+
+ # spine1-eth2 is connected to torm21-eth0
+ switch = tgen.add_switch("sw3")
+ switch.add_link(tgen.gears["spine1"])
+ switch.add_link(tgen.gears["torm21"])
+
+ # spine1-eth3 is connected to torm22-eth0
+ switch = tgen.add_switch("sw4")
+ switch.add_link(tgen.gears["spine1"])
+ switch.add_link(tgen.gears["torm22"])
+
+ ##################### spine2 ########################
+ # spine2-eth0 is connected to torm11-eth1
+ switch = tgen.add_switch("sw5")
+ switch.add_link(tgen.gears["spine2"])
+ switch.add_link(tgen.gears["torm11"])
+
+ # spine2-eth1 is connected to torm12-eth1
+ switch = tgen.add_switch("sw6")
+ switch.add_link(tgen.gears["spine2"])
+ switch.add_link(tgen.gears["torm12"])
+
+ # spine2-eth2 is connected to torm21-eth1
+ switch = tgen.add_switch("sw7")
+ switch.add_link(tgen.gears["spine2"])
+ switch.add_link(tgen.gears["torm21"])
+
+ # spine2-eth3 is connected to torm22-eth1
+ switch = tgen.add_switch("sw8")
+ switch.add_link(tgen.gears["spine2"])
+ switch.add_link(tgen.gears["torm22"])
+
+ ##################### torm11 ########################
+ # torm11-eth2 is connected to hostd11-eth0
+ switch = tgen.add_switch("sw9")
+ 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.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.add_link(tgen.gears["torm12"])
+ switch.add_link(tgen.gears["hostd11"])
+
+ # torm12-eth3 is connected to hostd12-eth1
+ switch = tgen.add_switch("sw12")
+ 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.add_link(tgen.gears["torm21"])
+ switch.add_link(tgen.gears["hostd21"])
+
+ # torm21-eth3 is connected to hostd22-eth0
+ switch = tgen.add_switch("sw14")
+ 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.add_link(tgen.gears["torm22"])
+ switch.add_link(tgen.gears["hostd21"])
+
+ # torm22-eth3 is connected to hostd22-eth1
+ switch = tgen.add_switch("sw16")
+ switch.add_link(tgen.gears["torm22"])
+ switch.add_link(tgen.gears["hostd22"])
+
+
+#####################################################
+##
+## Tests starting
+##
+#####################################################
+
+tor_ips = {"torm11" : "192.168.100.15", \
+ "torm12" : "192.168.100.16", \
+ "torm21" : "192.168.100.17", \
+ "torm22" : "192.168.100.18"}
+
+svi_ips = {"torm11" : "45.0.0.2", \
+ "torm12" : "45.0.0.3", \
+ "torm21" : "45.0.0.4", \
+ "torm22" : "45.0.0.5"}
+
+tor_ips_rack_1 = {"torm11" : "192.168.100.15", \
+ "torm12" : "192.168.100.16"}
+
+tor_ips_rack_2 = {"torm21" : "192.168.100.17", \
+ "torm22" : "192.168.100.18"}
+
+host_es_map = {"hostd11" : "03:44:38:39:ff:ff:01:00:00:01",
+ "hostd12" : "03:44:38:39:ff:ff:01:00:00:02",
+ "hostd21" : "03:44:38:39:ff:ff:02:00:00:01",
+ "hostd22" : "03:44:38:39:ff:ff:02:00:00:02"}
+
+def config_bond(node, bond_name, bond_members, bond_ad_sys_mac, br):
+ '''
+ Used to setup bonds on the TORs and hosts for MH
+ '''
+ node.run("ip link add dev %s type bond mode 802.3ad" % bond_name)
+ node.run("ip link set dev %s type bond lacp_rate 1" % bond_name)
+ node.run("ip link set dev %s type bond miimon 100" % bond_name)
+ node.run("ip link set dev %s type bond xmit_hash_policy layer3+4" % bond_name)
+ node.run("ip link set dev %s type bond min_links 1" % bond_name)
+ node.run("ip link set dev %s type bond ad_actor_system %s" %\
+ (bond_name, bond_ad_sys_mac))
+
+ for bond_member in bond_members:
+ node.run("ip link set dev %s down" % bond_member)
+ node.run("ip link set dev %s master %s" % (bond_member, bond_name))
+ node.run("ip link set dev %s up" % bond_member)
+
+ node.run("ip link set dev %s up" % bond_name)
+
+ # if bridge is specified add the bond as a bridge member
+ if br:
+ node.run(" ip link set dev %s master bridge" % bond_name)
+ node.run("/sbin/bridge link set dev %s priority 8" % bond_name)
+ node.run("/sbin/bridge vlan del vid 1 dev %s" % bond_name)
+ node.run("/sbin/bridge vlan del vid 1 untagged pvid dev %s" % bond_name)
+ node.run("/sbin/bridge vlan add vid 1000 dev %s" % bond_name)
+ node.run("/sbin/bridge vlan add vid 1000 untagged pvid dev %s"\
+ % bond_name)
+
+
+def config_mcast_tunnel_termination_device(node):
+ '''
+ The kernel requires a device to terminate VxLAN multicast tunnels
+ when EVPN-PIM is used for flooded traffic
+ '''
+ node.run("ip link add dev ipmr-lo type dummy")
+ node.run("ip link set dev ipmr-lo mtu 16000")
+ node.run("ip link set dev ipmr-lo mode dormant")
+ node.run("ip link set dev ipmr-lo up")
+
+
+def config_bridge(node):
+ '''
+ Create a VLAN aware bridge
+ '''
+ node.run("ip link add dev bridge type bridge stp_state 0")
+ node.run("ip link set dev bridge type bridge vlan_filtering 1")
+ node.run("ip link set dev bridge mtu 9216")
+ node.run("ip link set dev bridge type bridge ageing_time 1800")
+ node.run("ip link set dev bridge type bridge mcast_snooping 0")
+ node.run("ip link set dev bridge type bridge vlan_stats_enabled 1")
+ node.run("ip link set dev bridge up")
+ node.run("/sbin/bridge vlan add vid 1000 dev bridge")
+
+
+def config_vxlan(node, node_ip):
+ '''
+ Create a VxLAN device for VNI 1000 and add it to the bridge.
+ VLAN-1000 is mapped to VNI-1000.
+ '''
+ node.run("ip link add dev vx-1000 type vxlan id 1000 dstport 4789")
+ node.run("ip link set dev vx-1000 type vxlan nolearning")
+ node.run("ip link set dev vx-1000 type vxlan local %s" % node_ip)
+ node.run("ip link set dev vx-1000 type vxlan ttl 64")
+ node.run("ip link set dev vx-1000 mtu 9152")
+ node.run("ip link set dev vx-1000 type vxlan dev ipmr-lo group 239.1.1.100")
+ node.run("ip link set dev vx-1000 up")
+
+ # bridge attrs
+ node.run("ip link set dev vx-1000 master bridge")
+ node.run("/sbin/bridge link set dev vx-1000 neigh_suppress on")
+ node.run("/sbin/bridge link set dev vx-1000 learning off")
+ node.run("/sbin/bridge link set dev vx-1000 priority 8")
+ node.run("/sbin/bridge vlan del vid 1 dev vx-1000")
+ node.run("/sbin/bridge vlan del vid 1 untagged pvid dev vx-1000")
+ node.run("/sbin/bridge vlan add vid 1000 dev vx-1000")
+ node.run("/sbin/bridge vlan add vid 1000 untagged pvid dev vx-1000")
+
+
+def config_svi(node, svi_pip):
+ '''
+ Create an SVI for VLAN 1000
+ '''
+ node.run("ip link add link bridge name vlan1000 type vlan id 1000 protocol 802.1q")
+ node.run("ip addr add %s/24 dev vlan1000" % svi_pip)
+ node.run("ip link set dev vlan1000 up")
+ node.run("/sbin/sysctl net.ipv4.conf.vlan1000.arp_accept=1")
+ node.run("ip link add link vlan1000 name vlan1000-v0 type macvlan mode private")
+ node.run("/sbin/sysctl net.ipv6.conf.vlan1000-v0.accept_dad=0")
+ node.run("/sbin/sysctl net.ipv6.conf.vlan1000-v0.dad_transmits")
+ node.run("/sbin/sysctl net.ipv6.conf.vlan1000-v0.dad_transmits=0")
+ node.run("ip link set dev vlan1000-v0 address 00:00:5e:00:01:01")
+ node.run("ip link set dev vlan1000-v0 up")
+ # metric 1024 is not working
+ node.run("ip addr add 45.0.0.1/24 dev vlan1000-v0")
+
+
+def config_tor(tor_name, tor, tor_ip, svi_pip):
+ '''
+ Create the bond/vxlan-bridge on the TOR which acts as VTEP and EPN-PE
+ '''
+ # create a device for terminating VxLAN multicast tunnels
+ config_mcast_tunnel_termination_device(tor)
+
+ # create a vlan aware bridge
+ config_bridge(tor)
+
+ # create vxlan device and add it to bridge
+ config_vxlan(tor, tor_ip)
+
+ # create hostbonds and add them to the bridge
+ if "torm1" in tor_name:
+ sys_mac = "44:38:39:ff:ff:01"
+ else:
+ sys_mac = "44:38:39:ff:ff:02"
+ bond_member = tor_name + "-eth2"
+ config_bond(tor, "hostbond1", [bond_member], sys_mac, "bridge")
+
+ bond_member = tor_name + "-eth3"
+ config_bond(tor, "hostbond2", [bond_member], sys_mac, "bridge")
+
+ # create SVI
+ config_svi(tor, svi_pip)
+
+
+def config_tors(tgen, tors):
+ for tor_name in tors:
+ tor = tgen.gears[tor_name]
+ config_tor(tor_name, tor, tor_ips.get(tor_name), svi_ips.get(tor_name))
+
+def compute_host_ip_mac(host_name):
+ host_id = host_name.split("hostd")[1]
+ host_ip = "45.0.0."+ host_id + "/24"
+ host_mac = "00:00:00:00:00:" + host_id
+
+ return host_ip, host_mac
+
+def config_host(host_name, host):
+ '''
+ Create the dual-attached bond on host nodes for MH
+ '''
+ bond_members = []
+ bond_members.append(host_name + "-eth0")
+ bond_members.append(host_name + "-eth1")
+ bond_name = "torbond"
+ config_bond(host, bond_name, bond_members, "00:00:00:00:00:00", None)
+
+ host_ip, host_mac = compute_host_ip_mac(host_name)
+ host.run("ip addr add %s dev %s" % (host_ip, bond_name))
+ host.run("ip link set dev %s address %s" % (bond_name, host_mac))
+
+
+def config_hosts(tgen, hosts):
+ for host_name in hosts:
+ host = tgen.gears[host_name]
+ config_host(host_name, host)
+
+
+def setup_module(module):
+ "Setup topology"
+ tgen = Topogen(NetworkTopo, module.__name__)
+ tgen.start_topology()
+
+ krel = platform.release()
+ if topotest.version_cmp(krel, "4.19") < 0:
+ tgen.errors = "kernel 4.19 needed for multihoming tests"
+ pytest.skip(tgen.errors)
+
+ tors = []
+ tors.append("torm11")
+ tors.append("torm12")
+ tors.append("torm21")
+ tors.append("torm22")
+ config_tors(tgen, tors)
+
+ hosts = []
+ hosts.append("hostd11")
+ hosts.append("hostd12")
+ hosts.append("hostd21")
+ hosts.append("hostd22")
+ config_hosts(tgen, hosts)
+
+ # tgen.mininet_cli()
+ # This is a sample of configuration loading.
+ router_list = tgen.routers()
+ for rname, router in router_list.iteritems():
+ router.load_config(
+ TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
+ )
+ router.load_config(
+ TopoRouter.RD_PIM, os.path.join(CWD, "{}/pim.conf".format(rname))
+ )
+ router.load_config(
+ TopoRouter.RD_BGP, os.path.join(CWD, "{}/evpn.conf".format(rname))
+ )
+ tgen.start_router()
+ # tgen.mininet_cli()
+
+
+def teardown_module(_mod):
+ "Teardown the pytest environment"
+ tgen = get_topogen()
+
+ # This function tears down the whole topology.
+ tgen.stop_topology()
+
+
+def check_local_es(esi, vtep_ips, dut_name, down_vteps):
+ '''
+ Check if ES peers are setup correctly on local ESs
+ '''
+ peer_ips = []
+ if "torm1" in dut_name:
+ tor_ips_rack = tor_ips_rack_1
+ else:
+ tor_ips_rack = tor_ips_rack_2
+
+ for tor_name, tor_ip in tor_ips_rack.iteritems():
+ if dut_name not in tor_name:
+ peer_ips.append(tor_ip)
+
+ # remove down VTEPs from the peer check list
+ peer_set = set(peer_ips)
+ down_vtep_set = set(down_vteps)
+ peer_set = peer_set - down_vtep_set
+
+ vtep_set = set(vtep_ips)
+ diff = peer_set.symmetric_difference(vtep_set)
+
+ return (esi, diff) if diff else None
+
+
+def check_remote_es(esi, vtep_ips, dut_name, down_vteps):
+ '''
+ Verify list of PEs associated with a remote ES
+ '''
+ remote_ips = []
+
+ if "torm1" in dut_name:
+ tor_ips_rack = tor_ips_rack_2
+ else:
+ tor_ips_rack = tor_ips_rack_1
+
+ for tor_name, tor_ip in tor_ips_rack.iteritems():
+ remote_ips.append(tor_ip)
+
+ # remove down VTEPs from the remote check list
+ remote_set = set(remote_ips)
+ down_vtep_set = set(down_vteps)
+ remote_set = remote_set - down_vtep_set
+
+ vtep_set = set(vtep_ips)
+ diff = remote_set.symmetric_difference(vtep_set)
+
+ return (esi, diff) if diff else None
+
+def check_es(dut):
+ '''
+ Verify list of PEs associated all ESs, local and remote
+ '''
+ bgp_es = dut.vtysh_cmd("show bgp l2vp evpn es json")
+ bgp_es_json = json.loads(bgp_es)
+
+ result = None
+
+ expected_es_set = set([v for k, v in host_es_map.iteritems()])
+ curr_es_set = []
+
+ # check is ES content is correct
+ for es in bgp_es_json:
+ esi = es["esi"]
+ curr_es_set.append(esi)
+ types = es["type"]
+ vtep_ips = []
+ for vtep in es["vteps"]:
+ vtep_ips.append(vtep["vtep_ip"])
+
+ if "local" in types:
+ result = check_local_es(esi, vtep_ips, dut.name, [])
+ else:
+ result = check_remote_es(esi, vtep_ips, dut.name, [])
+
+ if result:
+ return result
+
+ # check if all ESs are present
+ curr_es_set = set(curr_es_set)
+ result = curr_es_set.symmetric_difference(expected_es_set)
+
+ return result if result else None
+
+def check_one_es(dut, esi, down_vteps):
+ '''
+ Verify list of PEs associated all ESs, local and remote
+ '''
+ bgp_es = dut.vtysh_cmd("show bgp l2vp evpn es %s json" % esi)
+ es = json.loads(bgp_es)
+
+ if not es:
+ return "esi %s not found" % esi
+
+ esi = es["esi"]
+ types = es["type"]
+ vtep_ips = []
+ for vtep in es["vteps"]:
+ vtep_ips.append(vtep["vtep_ip"])
+
+ if "local" in types:
+ result = check_local_es(esi, vtep_ips, dut.name, down_vteps)
+ else:
+ result = check_remote_es(esi, vtep_ips, dut.name, down_vteps)
+
+ return result
+
+def test_evpn_es():
+ '''
+ Two ES are setup on each rack. This test checks if -
+ 1. ES peer has been added to the local ES (via Type-1/EAD route)
+ 2. The remote ESs are setup with the right list of PEs (via Type-1)
+ '''
+
+ tgen = get_topogen()
+
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ dut_name = "torm11"
+ dut = tgen.gears[dut_name]
+ test_fn = partial(check_es, dut)
+ _, result = topotest.run_and_expect(test_fn, None, count=20, wait=3)
+
+ assertmsg = '"{}" ES content incorrect'.format(dut_name)
+ assert result is None, assertmsg
+ # tgen.mininet_cli()
+
+def test_evpn_ead_update():
+ '''
+ Flap a host link one the remote rack and check if the EAD updates
+ are sent/processed for the corresponding ESI
+ '''
+ tgen = get_topogen()
+
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ # dut on rack1 and host link flap on rack2
+ dut_name = "torm11"
+ dut = tgen.gears[dut_name]
+
+ remote_tor_name = "torm21"
+ remote_tor = tgen.gears[remote_tor_name]
+
+ host_name = "hostd21"
+ host = tgen.gears[host_name]
+ esi = host_es_map.get(host_name)
+
+ # check if the VTEP list is right to start with
+ down_vteps = []
+ test_fn = partial(check_one_es, dut, esi, down_vteps)
+ _, result = topotest.run_and_expect(test_fn, None, count=20, wait=3)
+ assertmsg = '"{}" ES content incorrect'.format(dut_name)
+ assert result is None, assertmsg
+
+ # down a remote host link and check if the EAD withdraw is rxed
+ # Note: LACP is not working as expected so I am temporarily shutting
+ # down the link on the remote TOR instead of the remote host
+ remote_tor.run("ip link set dev %s-%s down" % (remote_tor_name, "eth2"))
+ down_vteps.append(tor_ips.get(remote_tor_name))
+ _, result = topotest.run_and_expect(test_fn, None, count=20, wait=3)
+ assertmsg = '"{}" ES incorrect after remote link down'.format(dut_name)
+ assert result is None, assertmsg
+
+ # bring up remote host link and check if the EAD update is rxed
+ down_vteps.remove(tor_ips.get(remote_tor_name))
+ remote_tor.run("ip link set dev %s-%s up" % (remote_tor_name, "eth2"))
+ _, result = topotest.run_and_expect(test_fn, None, count=20, wait=3)
+ assertmsg = '"{}" ES incorrect after remote link flap'.format(dut_name)
+ assert result is None, assertmsg
+
+ # tgen.mininet_cli()
+
+def check_mac(dut, vni, mac, m_type, esi, intf):
+ '''
+ checks if mac is present and if desination matches the one provided
+ '''
+
+ out = dut.vtysh_cmd("show evpn mac vni %d mac %s json" % (vni, mac))
+
+ mac_js = json.loads(out)
+ for mac, info in mac_js.iteritems():
+ tmp_esi = info.get("esi", "")
+ tmp_m_type = info.get("type", "")
+ tmp_intf = info.get("intf", "") if tmp_m_type == "local" else ""
+ if tmp_esi == esi and tmp_m_type == m_type and intf == intf:
+ return None
+
+ return "invalid vni %d mac %s out %s" % (vni, mac, mac_js)
+
+def test_evpn_mac():
+ '''
+ 1. Add a MAC on hostd11 and check if the MAC is synced between
+ torm11 and torm12. And installed as a local MAC.
+ 2. Add a MAC on hostd21 and check if the MAC is installed as a
+ remote MAC on torm11 and torm12
+ '''
+
+ tgen = get_topogen()
+
+ local_host = tgen.gears["hostd11"]
+ remote_host = tgen.gears["hostd21"]
+ tors = []
+ tors.append(tgen.gears["torm11"])
+ tors.append(tgen.gears["torm12"])
+
+ # ping the anycast gw from the local and remote hosts to populate
+ # the mac address on the PEs
+ local_host.run("arping -I torbond -c 1 45.0.0.1")
+ remote_host.run("arping -I torbond -c 1 45.0.0.1")
+
+ vni = 1000
+
+ # check if the rack-1 host MAC is present on all rack-1 PEs
+ # and points to local access port
+ m_type = "local"
+ _, mac = compute_host_ip_mac(local_host.name)
+ esi = host_es_map.get(local_host.name)
+ intf = "hostbond1"
+
+ for tor in tors:
+ test_fn = partial(check_mac, tor, vni, mac, m_type, esi, intf)
+ _, result = topotest.run_and_expect(test_fn, None, count=20, wait=3)
+ assertmsg = '"{}" local MAC content incorrect'.format(tor.name)
+ assert result is None, assertmsg
+
+ # check if the rack-2 host MAC is present on all rack-1 PEs
+ # and points to the remote ES destination
+ m_type = "remote"
+ _, mac = compute_host_ip_mac(remote_host.name)
+ esi = host_es_map.get(remote_host.name)
+ intf = ""
+
+ for tor in tors:
+ test_fn = partial(check_mac, tor, vni, mac, m_type, esi, intf)
+ _, result = topotest.run_and_expect(test_fn, None, count=20, wait=3)
+ assertmsg = '"{}" remote MAC content incorrect'.format(tor.name)
+ assert result is None, assertmsg
+
+if __name__ == "__main__":
+ args = ["-s"] + sys.argv[1:]
+ sys.exit(pytest.main(args))
diff --git a/tests/topotests/bgp-evpn-mh/torm11/evpn.conf b/tests/topotests/bgp-evpn-mh/torm11/evpn.conf
new file mode 100644
index 0000000000..01f4b65704
--- /dev/null
+++ b/tests/topotests/bgp-evpn-mh/torm11/evpn.conf
@@ -0,0 +1,21 @@
+!
+frr defaults datacenter
+!
+debug bgp evpn mh es
+debug bgp evpn mh route
+debug bgp zebra
+!
+!
+router bgp 65002
+ bgp router-id 192.168.100.15
+ no bgp ebgp-requires-policy
+ neighbor 192.168.1.1 remote-as external
+ neighbor 192.168.5.1 remote-as external
+ redistribute connected
+ address-family l2vpn evpn
+ neighbor 192.168.1.1 activate
+ neighbor 192.168.5.1 activate
+ advertise-all-vni
+ advertise-svi-ip
+ exit-address-family
+!
diff --git a/tests/topotests/bgp-evpn-mh/torm11/pim.conf b/tests/topotests/bgp-evpn-mh/torm11/pim.conf
new file mode 100644
index 0000000000..fbba735873
--- /dev/null
+++ b/tests/topotests/bgp-evpn-mh/torm11/pim.conf
@@ -0,0 +1,13 @@
+!
+ip pim rp 192.168.100.13 239.1.1.0/24
+ip pim spt-switchover infinity-and-beyond
+!
+interface lo
+ ip igmp
+ ip pim
+!
+interface torm11-eth0
+ ip pim
+!
+interface torm11-eth1
+ ip pim
diff --git a/tests/topotests/bgp-evpn-mh/torm11/zebra.conf b/tests/topotests/bgp-evpn-mh/torm11/zebra.conf
new file mode 100644
index 0000000000..ee4e87e1c2
--- /dev/null
+++ b/tests/topotests/bgp-evpn-mh/torm11/zebra.conf
@@ -0,0 +1,23 @@
+debug zebra evpn mh es
+debug zebra evpn mh mac
+debug zebra evpn mh neigh
+debug zebra evpn mh nh
+debug zebra vxlan
+!
+int torm11-eth0
+ ip addr 192.168.1.2/24
+!
+int torm11-eth1
+ ip addr 192.168.5.2/24
+!
+int lo
+ ip addr 192.168.100.15/32
+!
+interface hostbond1
+ evpn mh es-id 1
+ evpn mh es-sys-mac 44:38:39:ff:ff:01
+!
+interface hostbond2
+ evpn mh es-id 2
+ evpn mh es-sys-mac 44:38:39:ff:ff:01
+!
diff --git a/tests/topotests/bgp-evpn-mh/torm12/evpn.conf b/tests/topotests/bgp-evpn-mh/torm12/evpn.conf
new file mode 100644
index 0000000000..2c13024bbc
--- /dev/null
+++ b/tests/topotests/bgp-evpn-mh/torm12/evpn.conf
@@ -0,0 +1,21 @@
+!
+frr defaults datacenter
+!
+debug bgp evpn mh es
+debug bgp evpn mh route
+debug bgp zebra
+!
+!
+router bgp 65003
+ bgp router-id 192.168.100.16
+ no bgp ebgp-requires-policy
+ neighbor 192.168.2.1 remote-as external
+ neighbor 192.168.6.1 remote-as external
+ redistribute connected
+ address-family l2vpn evpn
+ neighbor 192.168.2.1 activate
+ neighbor 192.168.6.1 activate
+ advertise-all-vni
+ advertise-svi-ip
+ exit-address-family
+!
diff --git a/tests/topotests/bgp-evpn-mh/torm12/pim.conf b/tests/topotests/bgp-evpn-mh/torm12/pim.conf
new file mode 100644
index 0000000000..3dd63b44ca
--- /dev/null
+++ b/tests/topotests/bgp-evpn-mh/torm12/pim.conf
@@ -0,0 +1,13 @@
+!
+ip pim rp 192.168.100.13 239.1.1.0/24
+ip pim spt-switchover infinity-and-beyond
+!
+interface lo
+ ip igmp
+ ip pim
+!
+interface torm12-eth0
+ ip pim
+!
+interface torm12-eth1
+ ip pim
diff --git a/tests/topotests/bgp-evpn-mh/torm12/zebra.conf b/tests/topotests/bgp-evpn-mh/torm12/zebra.conf
new file mode 100644
index 0000000000..736af4159e
--- /dev/null
+++ b/tests/topotests/bgp-evpn-mh/torm12/zebra.conf
@@ -0,0 +1,23 @@
+debug zebra evpn mh es
+debug zebra evpn mh mac
+debug zebra evpn mh neigh
+debug zebra evpn mh nh
+debug zebra vxlan
+!
+int torm12-eth0
+ ip addr 192.168.2.2/24
+!
+int torm12-eth1
+ ip addr 192.168.6.2/24
+!
+int lo
+ ip addr 192.168.100.16/32
+!
+interface hostbond1
+ evpn mh es-id 1
+ evpn mh es-sys-mac 44:38:39:ff:ff:01
+!
+interface hostbond2
+ evpn mh es-id 2
+ evpn mh es-sys-mac 44:38:39:ff:ff:01
+!
diff --git a/tests/topotests/bgp-evpn-mh/torm21/evpn.conf b/tests/topotests/bgp-evpn-mh/torm21/evpn.conf
new file mode 100644
index 0000000000..2a2ba061c6
--- /dev/null
+++ b/tests/topotests/bgp-evpn-mh/torm21/evpn.conf
@@ -0,0 +1,21 @@
+!
+frr defaults datacenter
+!
+debug bgp evpn mh es
+debug bgp evpn mh route
+debug bgp zebra
+!
+!
+router bgp 65004
+ bgp router-id 192.168.100.17
+ no bgp ebgp-requires-policy
+ neighbor 192.168.3.1 remote-as external
+ neighbor 192.168.7.1 remote-as external
+ redistribute connected
+ address-family l2vpn evpn
+ neighbor 192.168.3.1 activate
+ neighbor 192.168.7.1 activate
+ advertise-all-vni
+ advertise-svi-ip
+ exit-address-family
+!
diff --git a/tests/topotests/bgp-evpn-mh/torm21/pim.conf b/tests/topotests/bgp-evpn-mh/torm21/pim.conf
new file mode 100644
index 0000000000..71aa91a06d
--- /dev/null
+++ b/tests/topotests/bgp-evpn-mh/torm21/pim.conf
@@ -0,0 +1,13 @@
+!
+ip pim rp 192.168.100.13 239.1.1.0/24
+ip pim spt-switchover infinity-and-beyond
+!
+interface lo
+ ip igmp
+ ip pim
+!
+interface torm21-eth0
+ ip pim
+!
+interface torm21-eth1
+ ip pim
diff --git a/tests/topotests/bgp-evpn-mh/torm21/zebra.conf b/tests/topotests/bgp-evpn-mh/torm21/zebra.conf
new file mode 100644
index 0000000000..0ebe6f2d95
--- /dev/null
+++ b/tests/topotests/bgp-evpn-mh/torm21/zebra.conf
@@ -0,0 +1,23 @@
+debug zebra evpn mh es
+debug zebra evpn mh mac
+debug zebra evpn mh neigh
+debug zebra evpn mh nh
+debug zebra vxlan
+!
+int torm21-eth0
+ ip addr 192.168.3.2/24
+!
+int torm21-eth1
+ ip addr 192.168.7.2/24
+!
+int lo
+ ip addr 192.168.100.17/32
+!
+interface hostbond1
+ evpn mh es-id 1
+ evpn mh es-sys-mac 44:38:39:ff:ff:02
+!
+interface hostbond2
+ evpn mh es-id 2
+ evpn mh es-sys-mac 44:38:39:ff:ff:02
+!
diff --git a/tests/topotests/bgp-evpn-mh/torm22/evpn.conf b/tests/topotests/bgp-evpn-mh/torm22/evpn.conf
new file mode 100644
index 0000000000..b4f4f1dc25
--- /dev/null
+++ b/tests/topotests/bgp-evpn-mh/torm22/evpn.conf
@@ -0,0 +1,21 @@
+!
+frr defaults datacenter
+!
+debug bgp evpn mh es
+debug bgp evpn mh route
+debug bgp zebra
+!
+!
+router bgp 65005
+ bgp router-id 192.168.100.18
+ no bgp ebgp-requires-policy
+ neighbor 192.168.4.1 remote-as external
+ neighbor 192.168.8.1 remote-as external
+ redistribute connected
+ address-family l2vpn evpn
+ neighbor 192.168.4.1 activate
+ neighbor 192.168.8.1 activate
+ advertise-all-vni
+ advertise-svi-ip
+ exit-address-family
+!
diff --git a/tests/topotests/bgp-evpn-mh/torm22/pim.conf b/tests/topotests/bgp-evpn-mh/torm22/pim.conf
new file mode 100644
index 0000000000..46f330f5cd
--- /dev/null
+++ b/tests/topotests/bgp-evpn-mh/torm22/pim.conf
@@ -0,0 +1,13 @@
+!
+ip pim rp 192.168.100.13 239.1.1.0/24
+ip pim spt-switchover infinity-and-beyond
+!
+interface lo
+ ip igmp
+ ip pim
+!
+interface torm22-eth0
+ ip pim
+!
+interface torm22-eth1
+ ip pim
diff --git a/tests/topotests/bgp-evpn-mh/torm22/zebra.conf b/tests/topotests/bgp-evpn-mh/torm22/zebra.conf
new file mode 100644
index 0000000000..356d8a43e7
--- /dev/null
+++ b/tests/topotests/bgp-evpn-mh/torm22/zebra.conf
@@ -0,0 +1,23 @@
+debug zebra evpn mh es
+debug zebra evpn mh mac
+debug zebra evpn mh neigh
+debug zebra evpn mh nh
+debug zebra vxlan
+!
+int torm22-eth0
+ ip addr 192.168.4.2/24
+!
+int torm22-eth1
+ ip addr 192.168.8.2/24
+!
+int lo
+ ip addr 192.168.100.18/32
+!
+interface hostbond1
+ evpn mh es-id 1
+ evpn mh es-sys-mac 44:38:39:ff:ff:02
+!
+interface hostbond2
+ evpn mh es-id 2
+ evpn mh es-sys-mac 44:38:39:ff:ff:02
+!
diff --git a/tests/topotests/bgp_l3vpn_to_bgp_direct/ce1/bgpd.conf b/tests/topotests/bgp_l3vpn_to_bgp_direct/ce1/bgpd.conf
index c1bb7e3d15..2712e54f12 100644
--- a/tests/topotests/bgp_l3vpn_to_bgp_direct/ce1/bgpd.conf
+++ b/tests/topotests/bgp_l3vpn_to_bgp_direct/ce1/bgpd.conf
@@ -3,7 +3,6 @@ frr defaults traditional
hostname ce1
password zebra
log stdout notifications
-log monitor notifications
log commands
router bgp 5226
no bgp network import-check
diff --git a/tests/topotests/bgp_l3vpn_to_bgp_direct/ce2/bgpd.conf b/tests/topotests/bgp_l3vpn_to_bgp_direct/ce2/bgpd.conf
index c889a4c596..69305512cb 100644
--- a/tests/topotests/bgp_l3vpn_to_bgp_direct/ce2/bgpd.conf
+++ b/tests/topotests/bgp_l3vpn_to_bgp_direct/ce2/bgpd.conf
@@ -3,7 +3,6 @@ frr defaults traditional
hostname ce2
password zebra
log stdout notifications
-log monitor notifications
log commands
router bgp 5226
no bgp network import-check
diff --git a/tests/topotests/bgp_l3vpn_to_bgp_direct/ce3/bgpd.conf b/tests/topotests/bgp_l3vpn_to_bgp_direct/ce3/bgpd.conf
index 36dd97190e..3ad95c3612 100644
--- a/tests/topotests/bgp_l3vpn_to_bgp_direct/ce3/bgpd.conf
+++ b/tests/topotests/bgp_l3vpn_to_bgp_direct/ce3/bgpd.conf
@@ -3,7 +3,6 @@ frr defaults traditional
hostname ce3
password zebra
log stdout notifications
-log monitor notifications
log commands
router bgp 5226
no bgp network import-check
diff --git a/tests/topotests/bgp_l3vpn_to_bgp_direct/r1/bgpd.conf b/tests/topotests/bgp_l3vpn_to_bgp_direct/r1/bgpd.conf
index 33041262f6..502c4c8b2f 100644
--- a/tests/topotests/bgp_l3vpn_to_bgp_direct/r1/bgpd.conf
+++ b/tests/topotests/bgp_l3vpn_to_bgp_direct/r1/bgpd.conf
@@ -3,7 +3,6 @@ frr defaults traditional
hostname r1
password zebra
log stdout notifications
-log monitor notifications
log commands
router bgp 5226
bgp router-id 1.1.1.1
diff --git a/tests/topotests/bgp_l3vpn_to_bgp_direct/r2/bgpd.conf b/tests/topotests/bgp_l3vpn_to_bgp_direct/r2/bgpd.conf
index 524051426b..95890f25b9 100644
--- a/tests/topotests/bgp_l3vpn_to_bgp_direct/r2/bgpd.conf
+++ b/tests/topotests/bgp_l3vpn_to_bgp_direct/r2/bgpd.conf
@@ -3,7 +3,6 @@ frr defaults traditional
hostname r2
password zebra
log stdout notifications
-log monitor notifications
log commands
router bgp 5226
bgp router-id 2.2.2.2
diff --git a/tests/topotests/bgp_l3vpn_to_bgp_direct/r3/bgpd.conf b/tests/topotests/bgp_l3vpn_to_bgp_direct/r3/bgpd.conf
index 29b9f0da6c..2f7de073c3 100644
--- a/tests/topotests/bgp_l3vpn_to_bgp_direct/r3/bgpd.conf
+++ b/tests/topotests/bgp_l3vpn_to_bgp_direct/r3/bgpd.conf
@@ -3,7 +3,6 @@ frr defaults traditional
hostname r3
password zebra
log stdout notifications
-log monitor notifications
log commands
router bgp 5226
bgp router-id 3.3.3.3
diff --git a/tests/topotests/bgp_l3vpn_to_bgp_direct/r4/bgpd.conf b/tests/topotests/bgp_l3vpn_to_bgp_direct/r4/bgpd.conf
index e09b505ee4..720d06dbf1 100644
--- a/tests/topotests/bgp_l3vpn_to_bgp_direct/r4/bgpd.conf
+++ b/tests/topotests/bgp_l3vpn_to_bgp_direct/r4/bgpd.conf
@@ -3,7 +3,6 @@ frr defaults traditional
hostname r4
password zebra
log stdout notifications
-log monitor notifications
log commands
router bgp 5226
bgp router-id 4.4.4.4
diff --git a/tests/topotests/bgp_l3vpn_to_bgp_vrf/ce1/bgpd.conf b/tests/topotests/bgp_l3vpn_to_bgp_vrf/ce1/bgpd.conf
index c3309d8c75..b81cd33c4f 100644
--- a/tests/topotests/bgp_l3vpn_to_bgp_vrf/ce1/bgpd.conf
+++ b/tests/topotests/bgp_l3vpn_to_bgp_vrf/ce1/bgpd.conf
@@ -3,7 +3,6 @@ frr defaults traditional
hostname ce1
password zebra
log stdout notifications
-log monitor notifications
log commands
log file bgpd.log
diff --git a/tests/topotests/bgp_l3vpn_to_bgp_vrf/ce2/bgpd.conf b/tests/topotests/bgp_l3vpn_to_bgp_vrf/ce2/bgpd.conf
index 54401bfb2f..f18e5b852e 100644
--- a/tests/topotests/bgp_l3vpn_to_bgp_vrf/ce2/bgpd.conf
+++ b/tests/topotests/bgp_l3vpn_to_bgp_vrf/ce2/bgpd.conf
@@ -3,7 +3,6 @@ frr defaults traditional
hostname ce2
password zebra
log stdout notifications
-log monitor notifications
log commands
log file bgpd.log
diff --git a/tests/topotests/bgp_l3vpn_to_bgp_vrf/ce3/bgpd.conf b/tests/topotests/bgp_l3vpn_to_bgp_vrf/ce3/bgpd.conf
index f742fede1a..54a0933588 100644
--- a/tests/topotests/bgp_l3vpn_to_bgp_vrf/ce3/bgpd.conf
+++ b/tests/topotests/bgp_l3vpn_to_bgp_vrf/ce3/bgpd.conf
@@ -3,7 +3,6 @@ frr defaults traditional
hostname ce3
password zebra
log stdout notifications
-log monitor notifications
log commands
log file bgpd.log
diff --git a/tests/topotests/bgp_l3vpn_to_bgp_vrf/ce4/bgpd.conf b/tests/topotests/bgp_l3vpn_to_bgp_vrf/ce4/bgpd.conf
index 91311f32c5..5289628480 100644
--- a/tests/topotests/bgp_l3vpn_to_bgp_vrf/ce4/bgpd.conf
+++ b/tests/topotests/bgp_l3vpn_to_bgp_vrf/ce4/bgpd.conf
@@ -3,7 +3,6 @@ frr defaults traditional
hostname ce4
password zebra
log stdout notifications
-log monitor notifications
log commands
log file bgpd.log
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 a9549e8fee..5da53ae1e7 100644
--- a/tests/topotests/bgp_l3vpn_to_bgp_vrf/r1/bgpd.conf
+++ b/tests/topotests/bgp_l3vpn_to_bgp_vrf/r1/bgpd.conf
@@ -3,7 +3,6 @@ frr defaults traditional
hostname r1
password zebra
log stdout notifications
-log monitor notifications
log commands
log file bgpd.log debugging
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 cda6d9429a..e4a6b8e32c 100644
--- a/tests/topotests/bgp_l3vpn_to_bgp_vrf/r2/bgpd.conf
+++ b/tests/topotests/bgp_l3vpn_to_bgp_vrf/r2/bgpd.conf
@@ -3,7 +3,6 @@ frr defaults traditional
hostname r2
password zebra
log stdout notifications
-log monitor notifications
log commands
log file bgpd.log debugging
diff --git a/tests/topotests/bgp_l3vpn_to_bgp_vrf/r3/bgpd.conf b/tests/topotests/bgp_l3vpn_to_bgp_vrf/r3/bgpd.conf
index e2a8de7db7..a861469c7a 100644
--- a/tests/topotests/bgp_l3vpn_to_bgp_vrf/r3/bgpd.conf
+++ b/tests/topotests/bgp_l3vpn_to_bgp_vrf/r3/bgpd.conf
@@ -3,7 +3,6 @@ frr defaults traditional
hostname r3
password zebra
log stdout notifications
-log monitor notifications
log commands
log file bgpd.log
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 7b267a6ee1..480f95954e 100644
--- a/tests/topotests/bgp_l3vpn_to_bgp_vrf/r4/bgpd.conf
+++ b/tests/topotests/bgp_l3vpn_to_bgp_vrf/r4/bgpd.conf
@@ -3,7 +3,6 @@ frr defaults traditional
hostname r4
password zebra
log stdout notifications
-log monitor notifications
log commands
log file bgpd.log debug
diff --git a/tests/topotests/bgp_prefix_sid/r1/bgpd.conf b/tests/topotests/bgp_prefix_sid/r1/bgpd.conf
index 2f8759f960..06bdc31f8c 100644
--- a/tests/topotests/bgp_prefix_sid/r1/bgpd.conf
+++ b/tests/topotests/bgp_prefix_sid/r1/bgpd.conf
@@ -1,5 +1,4 @@
log stdout notifications
-log monitor notifications
log commands
!
router bgp 1
diff --git a/tests/topotests/bgp_rfapi_basic_sanity/r1/bgpd.conf b/tests/topotests/bgp_rfapi_basic_sanity/r1/bgpd.conf
index b3fe5ff23d..ada354bd62 100644
--- a/tests/topotests/bgp_rfapi_basic_sanity/r1/bgpd.conf
+++ b/tests/topotests/bgp_rfapi_basic_sanity/r1/bgpd.conf
@@ -3,7 +3,6 @@ frr defaults traditional
hostname r1
password zebra
log stdout notifications
-log monitor notifications
log commands
router bgp 5226
bgp router-id 1.1.1.1
diff --git a/tests/topotests/bgp_rfapi_basic_sanity/r2/bgpd.conf b/tests/topotests/bgp_rfapi_basic_sanity/r2/bgpd.conf
index 524051426b..95890f25b9 100644
--- a/tests/topotests/bgp_rfapi_basic_sanity/r2/bgpd.conf
+++ b/tests/topotests/bgp_rfapi_basic_sanity/r2/bgpd.conf
@@ -3,7 +3,6 @@ frr defaults traditional
hostname r2
password zebra
log stdout notifications
-log monitor notifications
log commands
router bgp 5226
bgp router-id 2.2.2.2
diff --git a/tests/topotests/bgp_rfapi_basic_sanity/r3/bgpd.conf b/tests/topotests/bgp_rfapi_basic_sanity/r3/bgpd.conf
index fbb6a65d61..4932d63d4f 100644
--- a/tests/topotests/bgp_rfapi_basic_sanity/r3/bgpd.conf
+++ b/tests/topotests/bgp_rfapi_basic_sanity/r3/bgpd.conf
@@ -3,7 +3,6 @@ frr defaults traditional
hostname r3
password zebra
log stdout notifications
-log monitor notifications
log commands
router bgp 5226
bgp router-id 3.3.3.3
diff --git a/tests/topotests/bgp_rfapi_basic_sanity/r4/bgpd.conf b/tests/topotests/bgp_rfapi_basic_sanity/r4/bgpd.conf
index d61f776f3d..1a5e41aae6 100644
--- a/tests/topotests/bgp_rfapi_basic_sanity/r4/bgpd.conf
+++ b/tests/topotests/bgp_rfapi_basic_sanity/r4/bgpd.conf
@@ -3,7 +3,6 @@ frr defaults traditional
hostname r4
password zebra
log stdout notifications
-log monitor notifications
log commands
router bgp 5226
bgp router-id 4.4.4.4
diff --git a/tests/topotests/bgp_rfapi_basic_sanity_config2/r1/bgpd.conf b/tests/topotests/bgp_rfapi_basic_sanity_config2/r1/bgpd.conf
index 626d8227e7..a38afd632f 100644
--- a/tests/topotests/bgp_rfapi_basic_sanity_config2/r1/bgpd.conf
+++ b/tests/topotests/bgp_rfapi_basic_sanity_config2/r1/bgpd.conf
@@ -3,7 +3,6 @@ frr defaults traditional
hostname r1
password zebra
log stdout notifications
-log monitor notifications
log commands
router bgp 5226
bgp router-id 1.1.1.1
diff --git a/tests/topotests/bgp_rfapi_basic_sanity_config2/r2/bgpd.conf b/tests/topotests/bgp_rfapi_basic_sanity_config2/r2/bgpd.conf
index 524051426b..95890f25b9 100644
--- a/tests/topotests/bgp_rfapi_basic_sanity_config2/r2/bgpd.conf
+++ b/tests/topotests/bgp_rfapi_basic_sanity_config2/r2/bgpd.conf
@@ -3,7 +3,6 @@ frr defaults traditional
hostname r2
password zebra
log stdout notifications
-log monitor notifications
log commands
router bgp 5226
bgp router-id 2.2.2.2
diff --git a/tests/topotests/bgp_rfapi_basic_sanity_config2/r3/bgpd.conf b/tests/topotests/bgp_rfapi_basic_sanity_config2/r3/bgpd.conf
index 8c75a39efa..dbeb2c4665 100644
--- a/tests/topotests/bgp_rfapi_basic_sanity_config2/r3/bgpd.conf
+++ b/tests/topotests/bgp_rfapi_basic_sanity_config2/r3/bgpd.conf
@@ -3,7 +3,6 @@ frr defaults traditional
hostname r3
password zebra
log stdout notifications
-log monitor notifications
log commands
router bgp 5226
bgp router-id 3.3.3.3
diff --git a/tests/topotests/bgp_rfapi_basic_sanity_config2/r4/bgpd.conf b/tests/topotests/bgp_rfapi_basic_sanity_config2/r4/bgpd.conf
index 38f8758cbc..ae1787718c 100644
--- a/tests/topotests/bgp_rfapi_basic_sanity_config2/r4/bgpd.conf
+++ b/tests/topotests/bgp_rfapi_basic_sanity_config2/r4/bgpd.conf
@@ -3,7 +3,6 @@ frr defaults traditional
hostname r4
password zebra
log stdout notifications
-log monitor notifications
log commands
router bgp 5226
bgp router-id 4.4.4.4
diff --git a/tests/topotests/evpn_type5_test_topo1/__init__.py b/tests/topotests/evpn_type5_test_topo1/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/topotests/evpn_type5_test_topo1/__init__.py
diff --git a/tests/topotests/evpn_type5_test_topo1/evpn_type5_chaos_topo1.json b/tests/topotests/evpn_type5_test_topo1/evpn_type5_chaos_topo1.json
new file mode 100644
index 0000000000..14842da326
--- /dev/null
+++ b/tests/topotests/evpn_type5_test_topo1/evpn_type5_chaos_topo1.json
@@ -0,0 +1,887 @@
+{
+ "address_types": ["ipv4","ipv6"],
+ "ipv4base": "10.0.0.0",
+ "ipv4mask": 30,
+ "ipv6base": "fd00::",
+ "ipv6mask": 64,
+ "link_ip_start": {
+ "ipv4": "10.0.0.0",
+ "v4mask": 30,
+ "ipv6": "fd00::",
+ "v6mask": 64
+ },
+ "lo_prefix": {
+ "ipv4": "1.0.",
+ "v4mask": 32,
+ "ipv6": "2001:db8:f::",
+ "v6mask": 128
+ },
+ "routers": {
+ "r1": {
+ "links": {
+ "e1": {"ipv4": "auto", "ipv6": "auto", "vrf": "RED"}
+ },
+ "vrfs":[
+ {
+ "name": "RED",
+ "id": "1"
+ }
+ ],
+ "bgp":
+ [
+ {
+ "local_as": "1",
+ "vrf": "RED",
+ "address_family": {
+ "ipv4": {
+ "unicast": {
+ "redistribute": [
+ {"redist_type": "static"}
+ ],
+ "neighbor": {
+ "e1": {
+ "dest_link": {
+ "r1": {}
+ }
+ }
+ }
+ }
+ },
+ "ipv6": {
+ "unicast": {
+ "redistribute": [
+ {"redist_type": "static"}
+ ],
+ "neighbor": {
+ "e1": {
+ "dest_link": {
+ "r1": {}
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ ],
+ "static_routes":[
+ {
+ "network":"10.1.1.1/32",
+ "next_hop":"Null0",
+ "vrf": "RED"
+ },
+ {
+ "network":"10::1/128",
+ "next_hop":"Null0",
+ "vrf": "RED"
+ }
+ ]
+ },
+ "r2": {
+ "links": {
+ "e1-link1": {"ipv4": "auto", "ipv6": "auto", "vrf": "BLUE"},
+ "e1-link2": {"ipv4": "auto", "ipv6": "auto", "vrf": "GREEN"}
+ },
+ "vrfs":[
+ {
+ "name": "BLUE",
+ "id": "1"
+ },
+ {
+ "name": "GREEN",
+ "id": "2"
+ }
+ ],
+ "bgp":
+ [
+ {
+ "local_as": "2",
+ "vrf": "BLUE",
+ "address_family": {
+ "ipv4": {
+ "unicast": {
+ "redistribute": [
+ {"redist_type": "static"}
+ ],
+ "neighbor": {
+ "e1": {
+ "dest_link": {
+ "r2-link1": {}
+ }
+ }
+ }
+ }
+ },
+ "ipv6": {
+ "unicast": {
+ "redistribute": [
+ {"redist_type": "static"}
+ ],
+ "neighbor": {
+ "e1": {
+ "dest_link": {
+ "r2-link1": {}
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ {
+ "local_as": "2",
+ "vrf": "GREEN",
+ "address_family": {
+ "ipv4": {
+ "unicast": {
+ "redistribute": [
+ {"redist_type": "static"}
+ ],
+ "neighbor": {
+ "e1": {
+ "dest_link": {
+ "r2-link2": {}
+ }
+ }
+ }
+ }
+ },
+ "ipv6": {
+ "unicast": {
+ "redistribute": [
+ {"redist_type": "static"}
+ ],
+ "neighbor": {
+ "e1": {
+ "dest_link": {
+ "r2-link2": {}
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ ],
+ "static_routes":[
+ {
+ "network":"20.1.1.1/32",
+ "next_hop":"Null0",
+ "vrf": "BLUE"
+ },
+ {
+ "network":"20::1/128",
+ "next_hop":"Null0",
+ "vrf": "BLUE"
+ },
+ {
+ "network":"30.1.1.1/32",
+ "next_hop":"Null0",
+ "vrf": "GREEN"
+ },
+ {
+ "network":"30::1/128",
+ "next_hop":"Null0",
+ "vrf": "GREEN"
+ }
+ ]
+ },
+ "e1": {
+ "links": {
+ "r1": {"ipv4": "auto", "ipv6": "auto", "vrf": "RED"},
+ "r2-link1": {"ipv4": "auto", "ipv6": "auto", "vrf": "BLUE"},
+ "r2-link2": {"ipv4": "auto", "ipv6": "auto", "vrf": "GREEN"},
+ "d1-link1": {"ipv4": "auto", "ipv6": "auto"},
+ "d2-link1": {"ipv4": "auto", "ipv6": "auto"}
+ },
+ "vrfs":[
+ {
+ "name": "RED",
+ "id": "1",
+ "vni": 75100
+ },
+ {
+ "name": "BLUE",
+ "id": "2",
+ "vni": 75200
+ },
+ {
+ "name": "GREEN",
+ "id": "3",
+ "vni": 75300
+ }
+ ],
+ "bgp":
+ [
+ {
+ "local_as": "100",
+ "vrf": "RED",
+ "address_family": {
+ "ipv4": {
+ "unicast": {
+ "neighbor": {
+ "r1": {
+ "dest_link": {
+ "e1": {}
+ }
+ }
+ }
+ }
+ },
+ "ipv6": {
+ "unicast": {
+ "neighbor": {
+ "r1": {
+ "dest_link": {
+ "e1": {}
+ }
+ }
+ }
+ }
+ },
+ "l2vpn": {
+ "evpn": {
+ "advertise": {
+ "ipv4": {
+ "unicast": {}
+ },
+ "ipv6": {
+ "unicast": {}
+ }
+ }
+ }
+ }
+ }
+ },
+ {
+ "local_as": "100",
+ "vrf": "BLUE",
+ "address_family": {
+ "ipv4": {
+ "unicast": {
+ "neighbor": {
+ "r2": {
+ "dest_link": {
+ "e1-link1": {}
+ }
+ }
+ }
+ }
+ },
+ "ipv6": {
+ "unicast": {
+ "neighbor": {
+ "r2": {
+ "dest_link": {
+ "e1-link1": {}
+ }
+ }
+ }
+ }
+ },
+ "l2vpn": {
+ "evpn": {
+ "advertise": {
+ "ipv4": {
+ "unicast": {}
+ },
+ "ipv6": {
+ "unicast": {}
+ }
+ }
+ }
+ }
+ }
+ },
+ {
+ "local_as": "100",
+ "vrf": "GREEN",
+ "address_family": {
+ "ipv4": {
+ "unicast": {
+ "neighbor": {
+ "r2": {
+ "dest_link": {
+ "e1-link2": {}
+ }
+ }
+ }
+ }
+ },
+ "ipv6": {
+ "unicast": {
+ "neighbor": {
+ "r2": {
+ "dest_link": {
+ "e1-link2": {}
+ }
+ }
+ }
+ }
+ },
+ "l2vpn": {
+ "evpn": {
+ "advertise": {
+ "ipv4": {
+ "unicast": {}
+ },
+ "ipv6": {
+ "unicast": {}
+ }
+ }
+ }
+ }
+ }
+ },
+ {
+ "local_as": "100",
+ "address_family": {
+ "ipv4": {
+ "unicast": {
+ "neighbor": {
+ "d1": {
+ "dest_link": {
+ "e1-link1": {
+ "deactivate": "ipv4"
+ }
+ }
+ },
+ "d2": {
+ "dest_link": {
+ "e1-link1": {
+ "deactivate": "ipv4"
+ }
+ }
+ }
+ }
+ }
+ },
+ "l2vpn": {
+ "evpn": {
+ "neighbor": {
+ "d1": {
+ "ipv4":{
+ "e1-link1": "activate"
+ }
+ },
+ "d2": {
+ "ipv4":{
+ "e1-link1": "activate"
+ }
+ }
+ },
+ "advertise-all-vni": true
+ }
+ }
+ }
+ }
+ ]
+ },
+ "d1": {
+ "links": {
+ "e1-link1": {"ipv4": "auto", "ipv6": "auto"},
+ "r3": {"ipv4": "auto", "ipv6": "auto", "vrf": "RED"},
+ "r4-link1": {"ipv4": "auto", "ipv6": "auto", "vrf": "BLUE"},
+ "r4-link2": {"ipv4": "auto", "ipv6": "auto", "vrf": "GREEN"}
+ },
+ "vrfs":[
+ {
+ "name": "RED",
+ "id": "1",
+ "vni": 75100
+ },
+ {
+ "name": "BLUE",
+ "id": "2",
+ "vni": 75200
+ },
+ {
+ "name": "GREEN",
+ "id": "3",
+ "vni": 75300
+ }
+ ],
+ "bgp":
+ [
+ {
+ "local_as": "100",
+ "address_family": {
+ "ipv4": {
+ "unicast": {
+ "neighbor": {
+ "e1": {
+ "dest_link": {
+ "d1-link1": {
+ "deactivate": "ipv4"
+ }
+ }
+ }
+ }
+ }
+ },
+ "l2vpn": {
+ "evpn": {
+ "neighbor": {
+ "e1": {
+ "ipv4":{
+ "d1-link1": "activate"
+ }
+ }
+ },
+ "advertise-all-vni": true
+ }
+ }
+ }
+ },
+ {
+ "local_as": "100",
+ "vrf": "RED",
+ "address_family": {
+ "ipv4": {
+ "unicast": {
+ "neighbor": {
+ "r3": {
+ "dest_link": {
+ "d1": {}
+ }
+ }
+ }
+ }
+ },
+ "ipv6": {
+ "unicast": {
+ "neighbor": {
+ "r3": {
+ "dest_link": {
+ "d1": {}
+ }
+ }
+ }
+ }
+ },
+ "l2vpn": {
+ "evpn": {
+ "advertise": {
+ "ipv4": {
+ "unicast": {}
+ },
+ "ipv6": {
+ "unicast": {}
+ }
+ }
+ }
+ }
+ }
+ },
+ {
+ "local_as": "100",
+ "vrf": "BLUE",
+ "address_family": {
+ "ipv4": {
+ "unicast": {
+ "neighbor": {
+ "r4": {
+ "dest_link": {
+ "d1-link1": {}
+ }
+ }
+ }
+ }
+ },
+ "ipv6": {
+ "unicast": {
+ "neighbor": {
+ "r4": {
+ "dest_link": {
+ "d1-link1": {}
+ }
+ }
+ }
+ }
+ },
+ "l2vpn": {
+ "evpn": {
+ "advertise": {
+ "ipv4": {
+ "unicast": {}
+ },
+ "ipv6": {
+ "unicast": {}
+ }
+ }
+ }
+ }
+ }
+ },
+ {
+ "local_as": "100",
+ "vrf": "GREEN",
+ "address_family": {
+ "ipv4": {
+ "unicast": {
+ "neighbor": {
+ "r4": {
+ "dest_link": {
+ "d1-link2": {}
+ }
+ }
+ }
+ }
+ },
+ "ipv6": {
+ "unicast": {
+ "neighbor": {
+ "r4": {
+ "dest_link": {
+ "d1-link2": {}
+ }
+ }
+ }
+ }
+ },
+ "l2vpn": {
+ "evpn": {
+ "advertise": {
+ "ipv4": {
+ "unicast": {}
+ },
+ "ipv6": {
+ "unicast": {}
+ }
+ }
+ }
+ }
+ }
+ }
+ ]
+ },
+ "d2": {
+ "links": {
+ "e1-link1": {"ipv4": "auto", "ipv6": "auto"},
+ "r3": {"ipv4": "auto", "ipv6": "auto", "vrf": "RED"},
+ "r4-link1": {"ipv4": "auto", "ipv6": "auto", "vrf": "BLUE"},
+ "r4-link2": {"ipv4": "auto", "ipv6": "auto", "vrf": "GREEN"}
+ },
+ "vrfs":[
+ {
+ "name": "RED",
+ "id": "1",
+ "vni": 75100
+ },
+ {
+ "name": "BLUE",
+ "id": "2",
+ "vni": 75200
+ },
+ {
+ "name": "GREEN",
+ "id": "3",
+ "vni": 75300
+ }
+ ],
+ "bgp":
+ [
+ {
+ "local_as": "200",
+ "address_family": {
+ "ipv4": {
+ "unicast": {
+ "neighbor": {
+ "e1": {
+ "dest_link": {
+ "d2-link1": {
+ "deactivate": "ipv4"
+ }
+ }
+ }
+ }
+ }
+ },
+ "l2vpn": {
+ "evpn": {
+ "neighbor": {
+ "e1": {
+ "ipv4":{
+ "d2-link1": "activate"
+ }
+ }
+ },
+ "advertise-all-vni": true
+ }
+ }
+ }
+ },
+ {
+ "local_as": "200",
+ "vrf": "RED",
+ "address_family": {
+ "ipv4": {
+ "unicast": {
+ "neighbor": {
+ "r3": {
+ "dest_link": {
+ "d2": {}
+ }
+ }
+ }
+ }
+ },
+ "ipv6": {
+ "unicast": {
+ "neighbor": {
+ "r3": {
+ "dest_link": {
+ "d2": {}
+ }
+ }
+ }
+ }
+ },
+ "l2vpn": {
+ "evpn": {
+ "advertise": {
+ "ipv4": {
+ "unicast": {}
+ },
+ "ipv6": {
+ "unicast": {}
+ }
+ }
+ }
+ }
+ }
+ },
+ {
+ "local_as": "200",
+ "vrf": "BLUE",
+ "address_family": {
+ "ipv4": {
+ "unicast": {
+ "neighbor": {
+ "r4": {
+ "dest_link": {
+ "d2-link1": {}
+ }
+ }
+ }
+ }
+ },
+ "ipv6": {
+ "unicast": {
+ "neighbor": {
+ "r4": {
+ "dest_link": {
+ "d2-link1": {}
+ }
+ }
+ }
+ }
+ },
+ "l2vpn": {
+ "evpn": {
+ "advertise": {
+ "ipv4": {
+ "unicast": {}
+ },
+ "ipv6": {
+ "unicast": {}
+ }
+ }
+ }
+ }
+ }
+ },
+ {
+ "local_as": "200",
+ "vrf": "GREEN",
+ "address_family": {
+ "ipv4": {
+ "unicast": {
+ "neighbor": {
+ "r4": {
+ "dest_link": {
+ "d2-link2": {}
+ }
+ }
+ }
+ }
+ },
+ "ipv6": {
+ "unicast": {
+ "neighbor": {
+ "r4": {
+ "dest_link": {
+ "d2-link2": {}
+ }
+ }
+ }
+ }
+ },
+ "l2vpn": {
+ "evpn": {
+ "advertise": {
+ "ipv4": {
+ "unicast": {}
+ },
+ "ipv6": {
+ "unicast": {}
+ }
+ }
+ }
+ }
+ }
+ }
+ ]
+ },
+ "r3": {
+ "links": {
+ "d1": {"ipv4": "auto", "ipv6": "auto", "vrf": "RED"},
+ "d2": {"ipv4": "auto", "ipv6": "auto", "vrf": "RED"}
+ },
+ "vrfs":[
+ {
+ "name": "RED",
+ "id": "1"
+ }
+ ],
+ "bgp":
+ [
+ {
+ "local_as": "3",
+ "vrf": "RED",
+ "address_family": {
+ "ipv4": {
+ "unicast": {
+ "neighbor": {
+ "d1": {
+ "dest_link": {
+ "r3": {}
+ }
+ },
+ "d2": {
+ "dest_link": {
+ "r3": {}
+ }
+ }
+ }
+ }
+ },
+ "ipv6": {
+ "unicast": {
+ "neighbor": {
+ "d1": {
+ "dest_link": {
+ "r3": {}
+ }
+ },
+ "d2": {
+ "dest_link": {
+ "r3": {}
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ ]
+ },
+ "r4": {
+ "links": {
+ "d1-link1": {"ipv4": "auto", "ipv6": "auto", "vrf": "BLUE"},
+ "d1-link2": {"ipv4": "auto", "ipv6": "auto", "vrf": "GREEN"},
+ "d2-link1": {"ipv4": "auto", "ipv6": "auto", "vrf": "BLUE"},
+ "d2-link2": {"ipv4": "auto", "ipv6": "auto", "vrf": "GREEN"}
+ },
+ "vrfs":[
+ {
+ "name": "BLUE",
+ "id": "1"
+ },
+ {
+ "name": "GREEN",
+ "id": "2"
+ }
+ ],
+ "bgp":
+ [
+ {
+ "local_as": "4",
+ "vrf": "BLUE",
+ "address_family": {
+ "ipv4": {
+ "unicast": {
+ "neighbor": {
+ "d1": {
+ "dest_link": {
+ "r4-link1": {}
+ }
+ },
+ "d2": {
+ "dest_link": {
+ "r4-link1": {}
+ }
+ }
+ }
+ }
+ },
+ "ipv6": {
+ "unicast": {
+ "neighbor": {
+ "d1": {
+ "dest_link": {
+ "r4-link1": {}
+ }
+ },
+ "d2": {
+ "dest_link": {
+ "r4-link1": {}
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ {
+ "local_as": "4",
+ "vrf": "GREEN",
+ "address_family": {
+ "ipv4": {
+ "unicast": {
+ "neighbor": {
+ "d1": {
+ "dest_link": {
+ "r4-link2": {}
+ }
+ },
+ "d2": {
+ "dest_link": {
+ "r4-link2": {}
+ }
+ }
+ }
+ }
+ },
+ "ipv6": {
+ "unicast": {
+ "neighbor": {
+ "d1": {
+ "dest_link": {
+ "r4-link2": {}
+ }
+ },
+ "d2": {
+ "dest_link": {
+ "r4-link2": {}
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ ]
+ }
+ }
+}
diff --git a/tests/topotests/evpn_type5_test_topo1/evpn_type5_topo1.json b/tests/topotests/evpn_type5_test_topo1/evpn_type5_topo1.json
new file mode 100644
index 0000000000..14842da326
--- /dev/null
+++ b/tests/topotests/evpn_type5_test_topo1/evpn_type5_topo1.json
@@ -0,0 +1,887 @@
+{
+ "address_types": ["ipv4","ipv6"],
+ "ipv4base": "10.0.0.0",
+ "ipv4mask": 30,
+ "ipv6base": "fd00::",
+ "ipv6mask": 64,
+ "link_ip_start": {
+ "ipv4": "10.0.0.0",
+ "v4mask": 30,
+ "ipv6": "fd00::",
+ "v6mask": 64
+ },
+ "lo_prefix": {
+ "ipv4": "1.0.",
+ "v4mask": 32,
+ "ipv6": "2001:db8:f::",
+ "v6mask": 128
+ },
+ "routers": {
+ "r1": {
+ "links": {
+ "e1": {"ipv4": "auto", "ipv6": "auto", "vrf": "RED"}
+ },
+ "vrfs":[
+ {
+ "name": "RED",
+ "id": "1"
+ }
+ ],
+ "bgp":
+ [
+ {
+ "local_as": "1",
+ "vrf": "RED",
+ "address_family": {
+ "ipv4": {
+ "unicast": {
+ "redistribute": [
+ {"redist_type": "static"}
+ ],
+ "neighbor": {
+ "e1": {
+ "dest_link": {
+ "r1": {}
+ }
+ }
+ }
+ }
+ },
+ "ipv6": {
+ "unicast": {
+ "redistribute": [
+ {"redist_type": "static"}
+ ],
+ "neighbor": {
+ "e1": {
+ "dest_link": {
+ "r1": {}
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ ],
+ "static_routes":[
+ {
+ "network":"10.1.1.1/32",
+ "next_hop":"Null0",
+ "vrf": "RED"
+ },
+ {
+ "network":"10::1/128",
+ "next_hop":"Null0",
+ "vrf": "RED"
+ }
+ ]
+ },
+ "r2": {
+ "links": {
+ "e1-link1": {"ipv4": "auto", "ipv6": "auto", "vrf": "BLUE"},
+ "e1-link2": {"ipv4": "auto", "ipv6": "auto", "vrf": "GREEN"}
+ },
+ "vrfs":[
+ {
+ "name": "BLUE",
+ "id": "1"
+ },
+ {
+ "name": "GREEN",
+ "id": "2"
+ }
+ ],
+ "bgp":
+ [
+ {
+ "local_as": "2",
+ "vrf": "BLUE",
+ "address_family": {
+ "ipv4": {
+ "unicast": {
+ "redistribute": [
+ {"redist_type": "static"}
+ ],
+ "neighbor": {
+ "e1": {
+ "dest_link": {
+ "r2-link1": {}
+ }
+ }
+ }
+ }
+ },
+ "ipv6": {
+ "unicast": {
+ "redistribute": [
+ {"redist_type": "static"}
+ ],
+ "neighbor": {
+ "e1": {
+ "dest_link": {
+ "r2-link1": {}
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ {
+ "local_as": "2",
+ "vrf": "GREEN",
+ "address_family": {
+ "ipv4": {
+ "unicast": {
+ "redistribute": [
+ {"redist_type": "static"}
+ ],
+ "neighbor": {
+ "e1": {
+ "dest_link": {
+ "r2-link2": {}
+ }
+ }
+ }
+ }
+ },
+ "ipv6": {
+ "unicast": {
+ "redistribute": [
+ {"redist_type": "static"}
+ ],
+ "neighbor": {
+ "e1": {
+ "dest_link": {
+ "r2-link2": {}
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ ],
+ "static_routes":[
+ {
+ "network":"20.1.1.1/32",
+ "next_hop":"Null0",
+ "vrf": "BLUE"
+ },
+ {
+ "network":"20::1/128",
+ "next_hop":"Null0",
+ "vrf": "BLUE"
+ },
+ {
+ "network":"30.1.1.1/32",
+ "next_hop":"Null0",
+ "vrf": "GREEN"
+ },
+ {
+ "network":"30::1/128",
+ "next_hop":"Null0",
+ "vrf": "GREEN"
+ }
+ ]
+ },
+ "e1": {
+ "links": {
+ "r1": {"ipv4": "auto", "ipv6": "auto", "vrf": "RED"},
+ "r2-link1": {"ipv4": "auto", "ipv6": "auto", "vrf": "BLUE"},
+ "r2-link2": {"ipv4": "auto", "ipv6": "auto", "vrf": "GREEN"},
+ "d1-link1": {"ipv4": "auto", "ipv6": "auto"},
+ "d2-link1": {"ipv4": "auto", "ipv6": "auto"}
+ },
+ "vrfs":[
+ {
+ "name": "RED",
+ "id": "1",
+ "vni": 75100
+ },
+ {
+ "name": "BLUE",
+ "id": "2",
+ "vni": 75200
+ },
+ {
+ "name": "GREEN",
+ "id": "3",
+ "vni": 75300
+ }
+ ],
+ "bgp":
+ [
+ {
+ "local_as": "100",
+ "vrf": "RED",
+ "address_family": {
+ "ipv4": {
+ "unicast": {
+ "neighbor": {
+ "r1": {
+ "dest_link": {
+ "e1": {}
+ }
+ }
+ }
+ }
+ },
+ "ipv6": {
+ "unicast": {
+ "neighbor": {
+ "r1": {
+ "dest_link": {
+ "e1": {}
+ }
+ }
+ }
+ }
+ },
+ "l2vpn": {
+ "evpn": {
+ "advertise": {
+ "ipv4": {
+ "unicast": {}
+ },
+ "ipv6": {
+ "unicast": {}
+ }
+ }
+ }
+ }
+ }
+ },
+ {
+ "local_as": "100",
+ "vrf": "BLUE",
+ "address_family": {
+ "ipv4": {
+ "unicast": {
+ "neighbor": {
+ "r2": {
+ "dest_link": {
+ "e1-link1": {}
+ }
+ }
+ }
+ }
+ },
+ "ipv6": {
+ "unicast": {
+ "neighbor": {
+ "r2": {
+ "dest_link": {
+ "e1-link1": {}
+ }
+ }
+ }
+ }
+ },
+ "l2vpn": {
+ "evpn": {
+ "advertise": {
+ "ipv4": {
+ "unicast": {}
+ },
+ "ipv6": {
+ "unicast": {}
+ }
+ }
+ }
+ }
+ }
+ },
+ {
+ "local_as": "100",
+ "vrf": "GREEN",
+ "address_family": {
+ "ipv4": {
+ "unicast": {
+ "neighbor": {
+ "r2": {
+ "dest_link": {
+ "e1-link2": {}
+ }
+ }
+ }
+ }
+ },
+ "ipv6": {
+ "unicast": {
+ "neighbor": {
+ "r2": {
+ "dest_link": {
+ "e1-link2": {}
+ }
+ }
+ }
+ }
+ },
+ "l2vpn": {
+ "evpn": {
+ "advertise": {
+ "ipv4": {
+ "unicast": {}
+ },
+ "ipv6": {
+ "unicast": {}
+ }
+ }
+ }
+ }
+ }
+ },
+ {
+ "local_as": "100",
+ "address_family": {
+ "ipv4": {
+ "unicast": {
+ "neighbor": {
+ "d1": {
+ "dest_link": {
+ "e1-link1": {
+ "deactivate": "ipv4"
+ }
+ }
+ },
+ "d2": {
+ "dest_link": {
+ "e1-link1": {
+ "deactivate": "ipv4"
+ }
+ }
+ }
+ }
+ }
+ },
+ "l2vpn": {
+ "evpn": {
+ "neighbor": {
+ "d1": {
+ "ipv4":{
+ "e1-link1": "activate"
+ }
+ },
+ "d2": {
+ "ipv4":{
+ "e1-link1": "activate"
+ }
+ }
+ },
+ "advertise-all-vni": true
+ }
+ }
+ }
+ }
+ ]
+ },
+ "d1": {
+ "links": {
+ "e1-link1": {"ipv4": "auto", "ipv6": "auto"},
+ "r3": {"ipv4": "auto", "ipv6": "auto", "vrf": "RED"},
+ "r4-link1": {"ipv4": "auto", "ipv6": "auto", "vrf": "BLUE"},
+ "r4-link2": {"ipv4": "auto", "ipv6": "auto", "vrf": "GREEN"}
+ },
+ "vrfs":[
+ {
+ "name": "RED",
+ "id": "1",
+ "vni": 75100
+ },
+ {
+ "name": "BLUE",
+ "id": "2",
+ "vni": 75200
+ },
+ {
+ "name": "GREEN",
+ "id": "3",
+ "vni": 75300
+ }
+ ],
+ "bgp":
+ [
+ {
+ "local_as": "100",
+ "address_family": {
+ "ipv4": {
+ "unicast": {
+ "neighbor": {
+ "e1": {
+ "dest_link": {
+ "d1-link1": {
+ "deactivate": "ipv4"
+ }
+ }
+ }
+ }
+ }
+ },
+ "l2vpn": {
+ "evpn": {
+ "neighbor": {
+ "e1": {
+ "ipv4":{
+ "d1-link1": "activate"
+ }
+ }
+ },
+ "advertise-all-vni": true
+ }
+ }
+ }
+ },
+ {
+ "local_as": "100",
+ "vrf": "RED",
+ "address_family": {
+ "ipv4": {
+ "unicast": {
+ "neighbor": {
+ "r3": {
+ "dest_link": {
+ "d1": {}
+ }
+ }
+ }
+ }
+ },
+ "ipv6": {
+ "unicast": {
+ "neighbor": {
+ "r3": {
+ "dest_link": {
+ "d1": {}
+ }
+ }
+ }
+ }
+ },
+ "l2vpn": {
+ "evpn": {
+ "advertise": {
+ "ipv4": {
+ "unicast": {}
+ },
+ "ipv6": {
+ "unicast": {}
+ }
+ }
+ }
+ }
+ }
+ },
+ {
+ "local_as": "100",
+ "vrf": "BLUE",
+ "address_family": {
+ "ipv4": {
+ "unicast": {
+ "neighbor": {
+ "r4": {
+ "dest_link": {
+ "d1-link1": {}
+ }
+ }
+ }
+ }
+ },
+ "ipv6": {
+ "unicast": {
+ "neighbor": {
+ "r4": {
+ "dest_link": {
+ "d1-link1": {}
+ }
+ }
+ }
+ }
+ },
+ "l2vpn": {
+ "evpn": {
+ "advertise": {
+ "ipv4": {
+ "unicast": {}
+ },
+ "ipv6": {
+ "unicast": {}
+ }
+ }
+ }
+ }
+ }
+ },
+ {
+ "local_as": "100",
+ "vrf": "GREEN",
+ "address_family": {
+ "ipv4": {
+ "unicast": {
+ "neighbor": {
+ "r4": {
+ "dest_link": {
+ "d1-link2": {}
+ }
+ }
+ }
+ }
+ },
+ "ipv6": {
+ "unicast": {
+ "neighbor": {
+ "r4": {
+ "dest_link": {
+ "d1-link2": {}
+ }
+ }
+ }
+ }
+ },
+ "l2vpn": {
+ "evpn": {
+ "advertise": {
+ "ipv4": {
+ "unicast": {}
+ },
+ "ipv6": {
+ "unicast": {}
+ }
+ }
+ }
+ }
+ }
+ }
+ ]
+ },
+ "d2": {
+ "links": {
+ "e1-link1": {"ipv4": "auto", "ipv6": "auto"},
+ "r3": {"ipv4": "auto", "ipv6": "auto", "vrf": "RED"},
+ "r4-link1": {"ipv4": "auto", "ipv6": "auto", "vrf": "BLUE"},
+ "r4-link2": {"ipv4": "auto", "ipv6": "auto", "vrf": "GREEN"}
+ },
+ "vrfs":[
+ {
+ "name": "RED",
+ "id": "1",
+ "vni": 75100
+ },
+ {
+ "name": "BLUE",
+ "id": "2",
+ "vni": 75200
+ },
+ {
+ "name": "GREEN",
+ "id": "3",
+ "vni": 75300
+ }
+ ],
+ "bgp":
+ [
+ {
+ "local_as": "200",
+ "address_family": {
+ "ipv4": {
+ "unicast": {
+ "neighbor": {
+ "e1": {
+ "dest_link": {
+ "d2-link1": {
+ "deactivate": "ipv4"
+ }
+ }
+ }
+ }
+ }
+ },
+ "l2vpn": {
+ "evpn": {
+ "neighbor": {
+ "e1": {
+ "ipv4":{
+ "d2-link1": "activate"
+ }
+ }
+ },
+ "advertise-all-vni": true
+ }
+ }
+ }
+ },
+ {
+ "local_as": "200",
+ "vrf": "RED",
+ "address_family": {
+ "ipv4": {
+ "unicast": {
+ "neighbor": {
+ "r3": {
+ "dest_link": {
+ "d2": {}
+ }
+ }
+ }
+ }
+ },
+ "ipv6": {
+ "unicast": {
+ "neighbor": {
+ "r3": {
+ "dest_link": {
+ "d2": {}
+ }
+ }
+ }
+ }
+ },
+ "l2vpn": {
+ "evpn": {
+ "advertise": {
+ "ipv4": {
+ "unicast": {}
+ },
+ "ipv6": {
+ "unicast": {}
+ }
+ }
+ }
+ }
+ }
+ },
+ {
+ "local_as": "200",
+ "vrf": "BLUE",
+ "address_family": {
+ "ipv4": {
+ "unicast": {
+ "neighbor": {
+ "r4": {
+ "dest_link": {
+ "d2-link1": {}
+ }
+ }
+ }
+ }
+ },
+ "ipv6": {
+ "unicast": {
+ "neighbor": {
+ "r4": {
+ "dest_link": {
+ "d2-link1": {}
+ }
+ }
+ }
+ }
+ },
+ "l2vpn": {
+ "evpn": {
+ "advertise": {
+ "ipv4": {
+ "unicast": {}
+ },
+ "ipv6": {
+ "unicast": {}
+ }
+ }
+ }
+ }
+ }
+ },
+ {
+ "local_as": "200",
+ "vrf": "GREEN",
+ "address_family": {
+ "ipv4": {
+ "unicast": {
+ "neighbor": {
+ "r4": {
+ "dest_link": {
+ "d2-link2": {}
+ }
+ }
+ }
+ }
+ },
+ "ipv6": {
+ "unicast": {
+ "neighbor": {
+ "r4": {
+ "dest_link": {
+ "d2-link2": {}
+ }
+ }
+ }
+ }
+ },
+ "l2vpn": {
+ "evpn": {
+ "advertise": {
+ "ipv4": {
+ "unicast": {}
+ },
+ "ipv6": {
+ "unicast": {}
+ }
+ }
+ }
+ }
+ }
+ }
+ ]
+ },
+ "r3": {
+ "links": {
+ "d1": {"ipv4": "auto", "ipv6": "auto", "vrf": "RED"},
+ "d2": {"ipv4": "auto", "ipv6": "auto", "vrf": "RED"}
+ },
+ "vrfs":[
+ {
+ "name": "RED",
+ "id": "1"
+ }
+ ],
+ "bgp":
+ [
+ {
+ "local_as": "3",
+ "vrf": "RED",
+ "address_family": {
+ "ipv4": {
+ "unicast": {
+ "neighbor": {
+ "d1": {
+ "dest_link": {
+ "r3": {}
+ }
+ },
+ "d2": {
+ "dest_link": {
+ "r3": {}
+ }
+ }
+ }
+ }
+ },
+ "ipv6": {
+ "unicast": {
+ "neighbor": {
+ "d1": {
+ "dest_link": {
+ "r3": {}
+ }
+ },
+ "d2": {
+ "dest_link": {
+ "r3": {}
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ ]
+ },
+ "r4": {
+ "links": {
+ "d1-link1": {"ipv4": "auto", "ipv6": "auto", "vrf": "BLUE"},
+ "d1-link2": {"ipv4": "auto", "ipv6": "auto", "vrf": "GREEN"},
+ "d2-link1": {"ipv4": "auto", "ipv6": "auto", "vrf": "BLUE"},
+ "d2-link2": {"ipv4": "auto", "ipv6": "auto", "vrf": "GREEN"}
+ },
+ "vrfs":[
+ {
+ "name": "BLUE",
+ "id": "1"
+ },
+ {
+ "name": "GREEN",
+ "id": "2"
+ }
+ ],
+ "bgp":
+ [
+ {
+ "local_as": "4",
+ "vrf": "BLUE",
+ "address_family": {
+ "ipv4": {
+ "unicast": {
+ "neighbor": {
+ "d1": {
+ "dest_link": {
+ "r4-link1": {}
+ }
+ },
+ "d2": {
+ "dest_link": {
+ "r4-link1": {}
+ }
+ }
+ }
+ }
+ },
+ "ipv6": {
+ "unicast": {
+ "neighbor": {
+ "d1": {
+ "dest_link": {
+ "r4-link1": {}
+ }
+ },
+ "d2": {
+ "dest_link": {
+ "r4-link1": {}
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ {
+ "local_as": "4",
+ "vrf": "GREEN",
+ "address_family": {
+ "ipv4": {
+ "unicast": {
+ "neighbor": {
+ "d1": {
+ "dest_link": {
+ "r4-link2": {}
+ }
+ },
+ "d2": {
+ "dest_link": {
+ "r4-link2": {}
+ }
+ }
+ }
+ }
+ },
+ "ipv6": {
+ "unicast": {
+ "neighbor": {
+ "d1": {
+ "dest_link": {
+ "r4-link2": {}
+ }
+ },
+ "d2": {
+ "dest_link": {
+ "r4-link2": {}
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ ]
+ }
+ }
+}
diff --git a/tests/topotests/evpn_type5_test_topo1/test_evpn_type5_chaos_topo1.py b/tests/topotests/evpn_type5_test_topo1/test_evpn_type5_chaos_topo1.py
new file mode 100755
index 0000000000..941593e51f
--- /dev/null
+++ b/tests/topotests/evpn_type5_test_topo1/test_evpn_type5_chaos_topo1.py
@@ -0,0 +1,1047 @@
+#!/usr/bin/env python
+
+#
+# Copyright (c) 2020 by VMware, Inc. ("VMware")
+# Used Copyright (c) 2018 by Network Device Education Foundation,
+# Inc. ("NetDEF") in this file.
+#
+# 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 VMWARE DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL VMWARE 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.
+#
+
+"""
+Following tests are covered to test EVPN-Type5 functionality:
+1. In absence of an overlay index all IP-Prefixes(RT-5)
+ are advertised with default values for below parameters:
+ --> Ethernet Tag ID = GW IP address = ESI=0
+2. EVPN CLI output and JSON format validation.
+3. RT verification(auto)
+"""
+
+import os
+import re
+import sys
+import json
+import time
+import pytest
+import platform
+from copy import deepcopy
+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.topotest import version_cmp
+from lib.topogen import Topogen, get_topogen
+from mininet.topo import Topo
+
+from lib.common_config import (
+ start_topology,
+ write_test_header,
+ check_address_types,
+ write_test_footer,
+ reset_config_on_routers,
+ verify_rib,
+ step,
+ start_router_daemons,
+ kill_router_daemons,
+ create_static_routes,
+ create_vrf_cfg,
+ create_route_maps,
+ create_interface_in_kernel,
+ check_router_status,
+ configure_vxlan,
+ configure_brctl,
+ apply_raw_config,
+ verify_vrf_vni,
+ verify_cli_json
+)
+
+from lib.topolog import logger
+from lib.bgp import (
+ verify_bgp_convergence,
+ create_router_bgp,
+ clear_bgp,
+ verify_best_path_as_per_bgp_attribute,
+ verify_attributes_for_evpn_routes,
+ verify_evpn_routes
+)
+from lib.topojson import build_topo_from_json, build_config_from_json
+
+# Reading the data from JSON File for topology creation
+jsonFile = "{}/evpn_type5_chaos_topo1.json".format(CWD)
+try:
+ with open(jsonFile, "r") as topoJson:
+ topo = json.load(topoJson)
+except IOError:
+ assert False, "Could not read file {}".format(jsonFile)
+
+# Reading the data from JSON File for topology creation
+# Global variables
+TCPDUMP_FILE = "evpn_log.txt"
+LOGDIR = "/tmp/topotests/"
+NETWORK1_1 = {"ipv4": "10.1.1.1/32", "ipv6": "10::1/128"}
+NETWORK1_2 = {"ipv4": "40.1.1.1/32", "ipv6": "40::1/128"}
+NETWORK1_3 = {"ipv4": "40.1.1.2/32", "ipv6": "40::2/128"}
+NETWORK1_4 = {"ipv4": "40.1.1.3/32", "ipv6": "40::3/128"}
+NETWORK2_1 = {"ipv4": "20.1.1.1/32", "ipv6": "20::1/128"}
+NETWORK3_1 = {"ipv4": "30.1.1.1/32", "ipv6": "30::1/128"}
+NETWORK4_1 = {"ipv4": "100.1.1.1/32 ", "ipv6": "100::100/128"}
+NEXT_HOP_IP = {"ipv4": "Null0", "ipv6": "Null0"}
+VNI_1 = 75100
+VNI_2 = 75200
+VNI_3 = 75300
+MAC_1 = "00:80:48:ba:d1:00"
+MAC_2 = "00:80:48:ba:d1:01"
+MAC_3 = "00:80:48:ba:d1:02"
+BRCTL_1 = "br100"
+BRCTL_2 = "br200"
+BRCTL_3 = "br300"
+VXLAN_1 = "vxlan75100"
+VXLAN_2 = "vxlan75200"
+VXLAN_3 = "vxlan75300"
+BRIDGE_INTF1 = "120.0.0.1"
+BRIDGE_INTF2 = "120.0.0.2"
+BRIDGE_INTF3 = "120.0.0.3"
+MULTICAST_MAC1 = "01:00:5e:00:52:02"
+
+VXLAN = {
+ "vxlan_name": [VXLAN_1, VXLAN_2, VXLAN_3],
+ "vxlan_id": [75100, 75200, 75300],
+ "dstport": 4789,
+ "local_addr": {"e1": BRIDGE_INTF1, "d1": BRIDGE_INTF2, "d2": BRIDGE_INTF3},
+ "learning": "no",
+}
+BRCTL = {
+ "brctl_name": [BRCTL_1, BRCTL_2, BRCTL_3],
+ "addvxlan": [VXLAN_1, VXLAN_2, VXLAN_3],
+ "vrf": ["RED", "BLUE", "GREEN"],
+ "stp": [0, 0, 0],
+}
+
+
+class CreateTopo(Topo):
+ """
+ Test BasicTopo - topology 1
+
+ * `Topo`: Topology object
+ """
+
+ def build(self, *_args, **_opts):
+ """Build function"""
+ tgen = get_topogen(self)
+
+ # Building topology from json file
+ build_topo_from_json(tgen, topo)
+
+
+def setup_module(mod):
+ """
+ Sets up the pytest environment
+
+ * `mod`: module name
+ """
+
+ global topo
+ 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...
+ tgen = Topogen(CreateTopo, mod.__name__)
+ # ... 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)
+
+ # Creating configuration from JSON
+ build_config_from_json(tgen, topo)
+
+ if version_cmp(platform.release(), '4.19') < 0:
+ error_msg = ('EVPN tests will not run (have kernel "{}", '
+ 'but it requires >= 4.19)'.format(platform.release()))
+ pytest.skip(error_msg)
+
+ global BGP_CONVERGENCE
+ 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("Pre-requisite config for testsuite")
+ prerequisite_config_for_test_suite(tgen)
+
+ 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)
+
+
+#####################################################
+#
+# Testcases
+#
+#####################################################
+
+
+def prerequisite_config_for_test_suite(tgen):
+ """
+ API to do prerequisite config for testsuite
+
+ parameters:
+ -----------
+ * `tgen`: topogen object
+ """
+
+ step("Configure vxlan, bridge interface")
+ for dut in ["e1", "d1", "d2"]:
+ step("[DUT: ]Configure vxlan")
+ vxlan_input = {
+ dut: {
+ "vxlan": [
+ {
+ "vxlan_name": VXLAN["vxlan_name"],
+ "vxlan_id": VXLAN["vxlan_id"],
+ "dstport": VXLAN["dstport"],
+ "local_addr": VXLAN["local_addr"][dut],
+ "learning": VXLAN["learning"],
+ }
+ ]
+ }
+ }
+
+ result = configure_vxlan(tgen, vxlan_input)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step("Configure bridge interface")
+ brctl_input = {
+ dut: {
+ "brctl": [
+ {
+ "brctl_name": BRCTL["brctl_name"],
+ "addvxlan": BRCTL["addvxlan"],
+ "vrf": BRCTL["vrf"],
+ "stp": BRCTL["stp"],
+ }
+ ]
+ }
+ }
+ result = configure_brctl(tgen, topo, brctl_input)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step("Configure default routes")
+ add_default_routes(tgen)
+
+
+def add_default_routes(tgen):
+ """
+ API to do prerequisite config for testsuite
+
+ parameters:
+ -----------
+ * `tgen`: topogen object
+ """
+
+ step("Add default routes..")
+
+ default_routes = {
+ "e1": {
+ "static_routes": [
+ {
+ "network": "{}/32".format(VXLAN["local_addr"]["d1"]),
+ "next_hop": topo["routers"]["d1"]["links"]["e1-link1"][
+ "ipv4"
+ ].split("/")[0],
+ },
+ {
+ "network": "{}/32".format(VXLAN["local_addr"]["d2"]),
+ "next_hop": topo["routers"]["d2"]["links"]["e1-link1"][
+ "ipv4"
+ ].split("/")[0],
+ },
+ ]
+ },
+ "d1": {
+ "static_routes": [
+ {
+ "network": "{}/32".format(VXLAN["local_addr"]["e1"]),
+ "next_hop": topo["routers"]["e1"]["links"]["d1-link1"][
+ "ipv4"
+ ].split("/")[0],
+ },
+ {
+ "network": "{}/32".format(VXLAN["local_addr"]["d2"]),
+ "next_hop": topo["routers"]["e1"]["links"]["d1-link1"][
+ "ipv4"
+ ].split("/")[0],
+ },
+ ]
+ },
+ "d2": {
+ "static_routes": [
+ {
+ "network": "{}/32".format(VXLAN["local_addr"]["d1"]),
+ "next_hop": topo["routers"]["e1"]["links"]["d2-link1"][
+ "ipv4"
+ ].split("/")[0],
+ },
+ {
+ "network": "{}/32".format(VXLAN["local_addr"]["e1"]),
+ "next_hop": topo["routers"]["e1"]["links"]["d2-link1"][
+ "ipv4"
+ ].split("/")[0],
+ },
+ ]
+ },
+ }
+
+ result = create_static_routes(tgen, default_routes)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
+
+
+def test_verify_overlay_index_p1(request):
+ """
+ In absence of an overlay index all IP-Prefixes(RT-5)
+ are advertised with default values for below parameters:
+ --> Ethernet Tag ID = GW IP address = ESI=0
+ """
+
+ tgen = get_topogen()
+ tc_name = request.node.name
+ write_test_header(tc_name)
+ check_router_status(tgen)
+ reset_config_on_routers(tgen)
+ add_default_routes(tgen)
+
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ step("Following steps are taken care in base config:")
+ step(
+ "Configure BGP neighborship for both address families"
+ "(IPv4 & IPv6) between Edge-1 and VFN routers(R1 and R2)"
+ )
+ step(
+ "Advertise prefixes from VNF routers R1 and R2 in associated "
+ "VRFs for both address-family."
+ )
+ step("Advertise VRF routes as in EVPN address family from Edge-1 " "router.")
+
+ for addr_type in ADDR_TYPES:
+ input_dict_1 = {
+ "r1": {
+ "static_routes": [
+ {
+ "network": NETWORK1_1[addr_type],
+ "next_hop": NEXT_HOP_IP[addr_type],
+ "vrf": "RED",
+ }
+ ]
+ },
+ "r2": {
+ "static_routes": [
+ {
+ "network": NETWORK2_1[addr_type],
+ "next_hop": NEXT_HOP_IP[addr_type],
+ "vrf": "BLUE",
+ },
+ {
+ "network": NETWORK3_1[addr_type],
+ "next_hop": NEXT_HOP_IP[addr_type],
+ "vrf": "GREEN",
+ }
+ ]
+ }
+ }
+
+ result = create_static_routes(tgen, input_dict_1)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step("Verify: Prefixes are received in all VRFs on Edge-1 router.")
+
+ for addr_type in ADDR_TYPES:
+ input_routes = {key: topo["routers"][key] for key in ["r1"]}
+ result = verify_rib(tgen, addr_type, "e1", input_routes)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ for addr_type in ADDR_TYPES:
+ input_routes = {key: topo["routers"][key] for key in ["r2"]}
+ result = verify_rib(tgen, addr_type, "e1", input_routes)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step(
+ "Verify that EVPN routes, received on DCG-1 and DCG-2 do not "
+ "carry any overlay index and these indexes are set to default "
+ "value=0. "
+ )
+
+ for addr_type in ADDR_TYPES:
+ input_routes = {key: topo["routers"][key] for key in ["r1"]}
+
+ result = verify_attributes_for_evpn_routes(
+ tgen, topo, "d1", input_routes, ethTag=0
+ )
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ result = verify_attributes_for_evpn_routes(
+ tgen, topo, "d2", input_routes, ethTag=0
+ )
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ write_test_footer(tc_name)
+
+
+def test_evpn_cli_json_available_p1(request):
+ """
+ EVPN CLI output and JSON format validation.
+ """
+
+ tgen = get_topogen()
+ tc_name = request.node.name
+ write_test_header(tc_name)
+ check_router_status(tgen)
+ reset_config_on_routers(tgen)
+ add_default_routes(tgen)
+
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ step("Need to verify below CLIs and associated JSON format " "outputs:")
+
+ input_dict = {
+ "e1": {
+ "cli": [
+ "show evpn vni detail",
+ "show bgp l2vpn evpn all overlay",
+ "show bgp l2vpn evpn vni"
+ ]
+ }
+ }
+
+ result = verify_cli_json(tgen, input_dict)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
+
+ write_test_footer(tc_name)
+
+
+def test_RT_verification_auto_p0(request):
+ """
+ RT verification(auto)
+ """
+
+ tgen = get_topogen()
+ tc_name = request.node.name
+ write_test_header(tc_name)
+ check_router_status(tgen)
+ reset_config_on_routers(tgen)
+ add_default_routes(tgen)
+
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ step(
+ "Advertise overlapping prefixes from VNFs R1 and R2 in all VRFs "
+ "RED, GREEN and BLUE 100.1.1.1/32 and 100::100/128"
+ )
+
+ for addr_type in ADDR_TYPES:
+ input_dict_1 = {
+ "r1": {
+ "static_routes": [
+ {
+ "network": NETWORK4_1[addr_type],
+ "next_hop": NEXT_HOP_IP[addr_type],
+ "vrf": "RED",
+ }
+ ]
+ },
+ "r2": {
+ "static_routes": [
+ {
+ "network": NETWORK4_1[addr_type],
+ "next_hop": NEXT_HOP_IP[addr_type],
+ "vrf": "BLUE",
+ },
+ {
+ "network": NETWORK4_1[addr_type],
+ "next_hop": NEXT_HOP_IP[addr_type],
+ "vrf": "GREEN",
+ }
+ ]
+ }
+ }
+
+ result = create_static_routes(tgen, input_dict_1)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step(
+ "Verify that Edge-1 receives same prefixes in all 3 VRFs via "
+ "corresponding next-hop in associated VRF sh bgp vrf all"
+ )
+
+ for addr_type in ADDR_TYPES:
+ input_routes = {
+ "r1": {
+ "static_routes": [
+ {
+ "network": NETWORK4_1[addr_type],
+ "next_hop": NEXT_HOP_IP[addr_type],
+ "vrf": "RED",
+ }
+ ]
+ },
+ "r2": {
+ "static_routes": [
+ {
+ "network": NETWORK4_1[addr_type],
+ "next_hop": NEXT_HOP_IP[addr_type],
+ "vrf": "BLUE",
+ },
+ {
+ "network": NETWORK4_1[addr_type],
+ "next_hop": NEXT_HOP_IP[addr_type],
+ "vrf": "GREEN",
+ },
+ ]
+ },
+ }
+
+ result = verify_rib(tgen, addr_type, "e1", input_routes)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step(
+ "Configure 4-byte local AS number on Edge-1 and establish EVPN "
+ "neighborship with DCG-1 & DCG-2."
+ )
+
+ topo_local = deepcopy(topo)
+
+ step("Delete BGP config for vrf RED.")
+
+ input_dict_vni = {
+ "e1": {
+ "vrfs": [
+ {"name": "RED", "no_vni": VNI_1},
+ {"name": "BLUE", "no_vni": VNI_2},
+ {"name": "GREEN", "no_vni": VNI_3},
+ ]
+ }
+ }
+ result = create_vrf_cfg(tgen, topo, input_dict=input_dict_vni)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
+
+ input_dict_2 = {}
+ for dut in ["e1"]:
+ temp = {dut: {"bgp": []}}
+ input_dict_2.update(temp)
+
+ INDEX = [0, 1, 2, 3]
+ VRFS = ["RED", "BLUE", "GREEN", None]
+ AS_NUM = [100, 100, 100, 100]
+
+ for index, vrf, as_num in zip(INDEX, VRFS, AS_NUM):
+ topo_local["routers"][dut]["bgp"][index]["local_as"] = 4294967293
+ if vrf:
+ temp[dut]["bgp"].append(
+ {"local_as": as_num, "vrf": vrf, "delete": True}
+ )
+ else:
+ temp[dut]["bgp"].append({"local_as": as_num, "delete": True})
+
+ result = create_router_bgp(tgen, topo, input_dict_2)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
+
+ result = create_router_bgp(tgen, topo_local["routers"])
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
+
+ input_dict_vni = {
+ "e1": {
+ "vrfs": [
+ {"name": "RED", "vni": VNI_1},
+ {"name": "BLUE", "vni": VNI_2},
+ {"name": "GREEN", "vni": VNI_3},
+ ]
+ }
+ }
+ result = create_vrf_cfg(tgen, topo, input_dict=input_dict_vni)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
+
+ step(
+ "Verify that all overlapping prefixes across different VRFs are "
+ "advertised in EVPN with unique RD value(auto derived)."
+ )
+ step(
+ "Verify that FRR uses only the lower 2 bytes of ASN+VNI for auto "
+ "derived RT value."
+ )
+
+ for addr_type in ADDR_TYPES:
+ input_routes_1 = {
+ "r1": {"static_routes": [{"network": NETWORK4_1[addr_type], "vrf": "RED"}]}
+ }
+ input_routes_2 = {
+ "r2": {"static_routes": [{"network": NETWORK4_1[addr_type], "vrf": "BLUE"}]}
+ }
+ input_routes_3 = {
+ "r2": {
+ "static_routes": [{"network": NETWORK4_1[addr_type], "vrf": "GREEN"}]
+ }
+ }
+
+ result = verify_attributes_for_evpn_routes(
+ tgen, topo, "e1", input_routes_1, rd="auto", rd_peer="e1"
+ )
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ result = verify_attributes_for_evpn_routes(
+ tgen, topo, "e1", input_routes_1, rt="auto", rt_peer="e1"
+ )
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ result = verify_attributes_for_evpn_routes(
+ tgen, topo, "e1", input_routes_2, rd="auto", rd_peer="e1"
+ )
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ result = verify_attributes_for_evpn_routes(
+ tgen, topo, "e1", input_routes_2, rt="auto", rt_peer="e1"
+ )
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ result = verify_attributes_for_evpn_routes(
+ tgen, topo, "e1", input_routes_3, rd="auto", rd_peer="e1"
+ )
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ result = verify_attributes_for_evpn_routes(
+ tgen, topo, "e1", input_routes_3, rt="auto", rt_peer="e1"
+ )
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step(
+ "Verify that DCG-1(iBGP peer) automatically imports the prefixes"
+ " from EVPN address-family to respective VRFs."
+ )
+ step(
+ "Verify if DCG-2(eBGP peer) automatically imports the prefixes "
+ "from EVPN address-family to respective VRFs or not."
+ )
+
+ for addr_type in ADDR_TYPES:
+ input_routes = {
+ "r1": {
+ "static_routes": [
+ {
+ "network": NETWORK4_1[addr_type],
+ "next_hop": NEXT_HOP_IP[addr_type],
+ "vrf": "RED",
+ }
+ ]
+ },
+ "r2": {
+ "static_routes": [
+ {
+ "network": NETWORK4_1[addr_type],
+ "next_hop": NEXT_HOP_IP[addr_type],
+ "vrf": "BLUE",
+ },
+ {
+ "network": NETWORK4_1[addr_type],
+ "next_hop": NEXT_HOP_IP[addr_type],
+ "vrf": "GREEN",
+ },
+ ]
+ },
+ }
+
+ result = verify_rib(tgen, addr_type, "d1", input_routes)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ result = verify_rib(tgen, addr_type, "d2", input_routes)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step(
+ "Change the VNI number for all 3 VRFs on Edge-1 as:"
+ "RED : 75400, GREEN: 75500, BLUE: 75600"
+ )
+
+ input_dict_vni = {
+ "e1": {
+ "vrfs": [
+ {"name": "RED", "no_vni": VNI_1},
+ {"name": "BLUE", "no_vni": VNI_2},
+ {"name": "GREEN", "no_vni": VNI_3},
+ ]
+ }
+ }
+ result = create_vrf_cfg(tgen, topo, input_dict=input_dict_vni)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
+
+ input_dict_vni = {
+ "e1": {
+ "vrfs": [
+ {"name": "RED", "vni": 75400},
+ {"name": "BLUE", "vni": 75500},
+ {"name": "GREEN", "vni": 75600},
+ ]
+ }
+ }
+ result = create_vrf_cfg(tgen, topo, input_dict=input_dict_vni)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
+
+ step("Delete configured vxlan")
+ dut = "e1"
+ vxlan_input = {
+ dut: {
+ "vxlan": [
+ {
+ "vxlan_name": VXLAN["vxlan_name"],
+ "vxlan_id": VXLAN["vxlan_id"],
+ "dstport": VXLAN["dstport"],
+ "local_addr": VXLAN["local_addr"][dut],
+ "learning": VXLAN["learning"],
+ "delete": True,
+ }
+ ]
+ }
+ }
+
+ result = configure_vxlan(tgen, vxlan_input)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
+
+ step("Configured vxlan")
+ VXLAN["vxlan_id"] = [75400, 75500, 75600]
+ vxlan_input = {
+ dut: {
+ "vxlan": [
+ {
+ "vxlan_name": VXLAN["vxlan_name"],
+ "vxlan_id": VXLAN["vxlan_id"],
+ "dstport": VXLAN["dstport"],
+ "local_addr": VXLAN["local_addr"][dut],
+ "learning": VXLAN["learning"],
+ }
+ ]
+ }
+ }
+
+ result = configure_vxlan(tgen, vxlan_input)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
+
+ step("Configure bridge interface")
+ brctl_input = {
+ dut: {
+ "brctl": [
+ {
+ "brctl_name": BRCTL["brctl_name"],
+ "addvxlan": BRCTL["addvxlan"],
+ "vrf": BRCTL["vrf"],
+ "stp": BRCTL["stp"],
+ }
+ ]
+ }
+ }
+ result = configure_brctl(tgen, topo, brctl_input)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
+
+ step(
+ "Verify on Edge-1 that auto derived RT value has changed for "
+ "each VRF based on VNI number.."
+ )
+
+ input_dict = {
+ "e1": {
+ "vrfs": [
+ {"RED": {"vni": 75400}},
+ {"BLUE": {"vni": 75500}},
+ {"GREEN": {"vni": 75600}},
+ ]
+ }
+ }
+
+ result = verify_vrf_vni(tgen, input_dict)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
+
+ step(
+ "Verify on Edge-1 that auto derived RT value has changed for "
+ "each VRF based on VNI number."
+ )
+
+ for addr_type in ADDR_TYPES:
+ input_routes = {
+ "r1": {"static_routes": [{"network": NETWORK4_1[addr_type], "vrf": "RED"}]}
+ }
+
+ result = verify_attributes_for_evpn_routes(
+ tgen, topo, "e1", input_routes, rt="auto", rt_peer="e1"
+ )
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step(
+ "Verify on DCG-2 that prefixes are not imported from EVPN "
+ "address-family to VRFs as RT values are different on sending("
+ "edge-1) and receiving(DCG-2) end."
+ )
+
+ for addr_type in ADDR_TYPES:
+ input_routes = {
+ "r1": {"static_routes": [{"network": NETWORK4_1[addr_type], "vrf": "RED"}]}
+ }
+
+ result = verify_rib(tgen, addr_type, "d2", input_routes, expected=False)
+ assert result is not True, "Testcase {} :Failed \n "
+ "Routes are still present: {}".format(tc_name, result)
+ logger.info("Expected Behavior: {}".format(result))
+
+ step(
+ "Revert back to original VNI number for all 3 VRFs on Edge-1 "
+ "as: RED : 75100, GREEN: 75200, BLUE: 75300"
+ )
+
+ input_dict_vni = {
+ "e1": {
+ "vrfs": [
+ {"name": "RED", "no_vni": 75400},
+ {"name": "BLUE", "no_vni": 75500},
+ {"name": "GREEN", "no_vni": 75600},
+ ]
+ }
+ }
+ result = create_vrf_cfg(tgen, topo, input_dict=input_dict_vni)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
+
+ input_dict_vni = {
+ "e1": {
+ "vrfs": [
+ {"name": "RED", "vni": VNI_1},
+ {"name": "BLUE", "vni": VNI_2},
+ {"name": "GREEN", "vni": VNI_3},
+ ]
+ }
+ }
+ result = create_vrf_cfg(tgen, topo, input_dict=input_dict_vni)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
+
+ step("Delete configured vxlan")
+ dut = "e1"
+ vxlan_input = {
+ dut: {
+ "vxlan": [
+ {
+ "vxlan_name": VXLAN["vxlan_name"],
+ "vxlan_id": VXLAN["vxlan_id"],
+ "dstport": VXLAN["dstport"],
+ "local_addr": VXLAN["local_addr"][dut],
+ "learning": VXLAN["learning"],
+ "delete": True,
+ }
+ ]
+ }
+ }
+ result = configure_vxlan(tgen, vxlan_input)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
+
+ step("Configured vxlan")
+ VXLAN["vxlan_id"] = [75100, 75200, 75300]
+ vxlan_input = {
+ dut: {
+ "vxlan": [
+ {
+ "vxlan_name": VXLAN["vxlan_name"],
+ "vxlan_id": VXLAN["vxlan_id"],
+ "dstport": VXLAN["dstport"],
+ "local_addr": VXLAN["local_addr"][dut],
+ "learning": VXLAN["learning"],
+ }
+ ]
+ }
+ }
+ result = configure_vxlan(tgen, vxlan_input)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
+
+ step("Configure bridge interface")
+ brctl_input = {
+ dut: {
+ "brctl": [
+ {
+ "brctl_name": BRCTL["brctl_name"],
+ "addvxlan": BRCTL["addvxlan"],
+ "vrf": BRCTL["vrf"],
+ "stp": BRCTL["stp"],
+ }
+ ]
+ }
+ }
+ result = configure_brctl(tgen, topo, brctl_input)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
+
+ step(
+ "Verify on Edge-1 that auto derived RT value has changed for "
+ "each VRF based on VNI number."
+ )
+ step(
+ "Verify that DCG-1(iBGP peer) automatically imports the prefixes"
+ " from EVPN address-family to respective VRFs."
+ )
+
+ for addr_type in ADDR_TYPES:
+ input_routes = {
+ "r1": {"static_routes": [{"network": NETWORK4_1[addr_type], "vrf": "RED"}]}
+ }
+
+ result = verify_attributes_for_evpn_routes(
+ tgen, topo, "e1", input_routes, rt="auto", rt_peer="e1"
+ )
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ result = verify_rib(tgen, addr_type, "d1", input_routes)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step("Test with smaller VNI numbers (1-75000)")
+
+ input_dict_vni = {"e1": {"vrfs": [{"name": "RED", "no_vni": VNI_1}]}}
+ result = create_vrf_cfg(tgen, topo, input_dict=input_dict_vni)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
+
+ input_dict_vni = {"e1": {"vrfs": [{"name": "RED", "vni": 111}]}}
+ result = create_vrf_cfg(tgen, topo, input_dict=input_dict_vni)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
+
+ step(
+ "Verify that DCG-2 receives EVPN prefixes along with auto "
+ "derived RT values(based on smaller VNI numbers)"
+ )
+
+ for addr_type in ADDR_TYPES:
+ input_routes_1 = {
+ "r1": {"static_routes": [{"network": NETWORK4_1[addr_type], "vrf": "RED"}]}
+ }
+
+ result = verify_attributes_for_evpn_routes(
+ tgen, topo, "d2", input_routes_1, rt="auto", rt_peer="e1", expected=False
+ )
+ assert result is not True, "Testcase {} :Failed \n "
+ "Malfaromed Auto-RT value accepted: {}".format(tc_name, result)
+ logger.info("Expected Behavior: {}".format(result))
+
+ step("Configure VNI number more than boundary limit (16777215)")
+
+ input_dict_vni = {"e1": {"vrfs": [{"name": "RED", "no_vni": 111}]}}
+ result = create_vrf_cfg(tgen, topo, input_dict=input_dict_vni)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
+
+ input_dict_vni = {"e1": {"vrfs": [{"name": "RED", "vni": 16777215}]}}
+ result = create_vrf_cfg(tgen, topo, input_dict=input_dict_vni)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
+
+ step("CLI error for malformed VNI.")
+ input_dict = {
+ "e1": {
+ "vrfs": [{"RED": {"vni": 16777215, "routerMac": "None", "state": "Down"}}]
+ }
+ }
+
+ result = verify_vrf_vni(tgen, input_dict)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
+
+ for addr_type in ADDR_TYPES:
+ input_routes_1 = {
+ "r1": {"static_routes": [{"network": NETWORK4_1[addr_type], "vrf": "RED"}]}
+ }
+
+ result = verify_attributes_for_evpn_routes(
+ tgen, topo, "d2", input_routes_1, rt="auto", rt_peer="e1", expected=False
+ )
+ assert result is not True, "Testcase {} :Failed \n "
+ "Malfaromed Auto-RT value accepted: {}".format(tc_name, result)
+ logger.info("Expected Behavior: {}".format(result))
+
+ step("Un-configure VNI number more than boundary limit (16777215)")
+
+ input_dict_vni = {"e1": {"vrfs": [{"name": "RED", "no_vni": 16777215}]}}
+ result = create_vrf_cfg(tgen, topo, input_dict=input_dict_vni)
+ assert result is True, "Testcase {} :Failed \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/evpn_type5_test_topo1/test_evpn_type5_topo1.py b/tests/topotests/evpn_type5_test_topo1/test_evpn_type5_topo1.py
new file mode 100755
index 0000000000..3cdec760f7
--- /dev/null
+++ b/tests/topotests/evpn_type5_test_topo1/test_evpn_type5_topo1.py
@@ -0,0 +1,2117 @@
+#!/usr/bin/env python
+
+#
+# Copyright (c) 2020 by VMware, Inc. ("VMware")
+# Used Copyright (c) 2018 by Network Device Education Foundation,
+# Inc. ("NetDEF") in this file.
+#
+# 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 VMWARE DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL VMWARE 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.
+#
+
+"""
+Following tests are covered to test EVPN-Type5 functionality:
+
+1. RD verification (manual/auto).
+2. RT verification(manual)
+3. In an active/standby EVPN implementation, if active DCG goes down,
+ secondary takes over.
+4. EVPN routes are advertised/withdrawn, based on VNFs
+ advertising/withdrawing IP prefixes.
+5. Route-map operations for EVPN address family.
+6. BGP attributes for EVPN address-family.
+"""
+
+import os
+import re
+import sys
+import json
+import time
+import pytest
+import platform
+from copy import deepcopy
+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.topotest import version_cmp
+from lib.topogen import Topogen, get_topogen
+from mininet.topo import Topo
+
+from lib.common_config import (
+ start_topology,
+ write_test_header,
+ check_address_types,
+ write_test_footer,
+ reset_config_on_routers,
+ verify_rib,
+ step,
+ create_route_maps,
+ verify_cli_json,
+ start_router_daemons,
+ kill_router_daemons,
+ create_static_routes,
+ stop_router,
+ start_router,
+ create_vrf_cfg,
+ check_router_status,
+ apply_raw_config,
+ configure_vxlan,
+ configure_brctl,
+ verify_vrf_vni,
+ create_interface_in_kernel
+)
+
+from lib.topolog import logger
+from lib.bgp import (
+ verify_bgp_convergence,
+ create_router_bgp,
+ clear_bgp,
+ verify_best_path_as_per_bgp_attribute,
+ verify_attributes_for_evpn_routes,
+ verify_evpn_routes
+)
+from lib.topojson import build_topo_from_json, build_config_from_json
+
+# Reading the data from JSON File for topology creation
+jsonFile = "{}/evpn_type5_topo1.json".format(CWD)
+try:
+ with open(jsonFile, "r") as topoJson:
+ topo = json.load(topoJson)
+except IOError:
+ assert False, "Could not read file {}".format(jsonFile)
+
+# Global variables
+NETWORK1_1 = {"ipv4": "10.1.1.1/32", "ipv6": "10::1/128"}
+NETWORK1_2 = {"ipv4": "40.1.1.1/32", "ipv6": "40::1/128"}
+NETWORK1_3 = {"ipv4": "40.1.1.2/32", "ipv6": "40::2/128"}
+NETWORK1_4 = {"ipv4": "40.1.1.3/32", "ipv6": "40::3/128"}
+NETWORK2_1 = {"ipv4": "20.1.1.1/32", "ipv6": "20::1/128"}
+NETWORK3_1 = {"ipv4": "30.1.1.1/32", "ipv6": "30::1/128"}
+NETWORK4_1 = {"ipv4": "100.1.1.1/32 ", "ipv6": "100::100/128"}
+NEXT_HOP_IP = {"ipv4": "Null0", "ipv6": "Null0"}
+VNI_1 = 75100
+VNI_2 = 75200
+VNI_3 = 75300
+MAC_1 = "00:80:48:ba:d1:00"
+MAC_2 = "00:80:48:ba:d1:01"
+MAC_3 = "00:80:48:ba:d1:02"
+BRCTL_1 = "br100"
+BRCTL_2 = "br200"
+BRCTL_3 = "br300"
+VXLAN_1 = "vxlan75100"
+VXLAN_2 = "vxlan75200"
+VXLAN_3 = "vxlan75300"
+BRIDGE_INTF1 = "120.0.0.1"
+BRIDGE_INTF2 = "120.0.0.2"
+BRIDGE_INTF3 = "120.0.0.3"
+
+VXLAN = {
+ "vxlan_name": [VXLAN_1, VXLAN_2, VXLAN_3],
+ "vxlan_id": [75100, 75200, 75300],
+ "dstport": 4789,
+ "local_addr": {"e1": BRIDGE_INTF1, "d1": BRIDGE_INTF2, "d2": BRIDGE_INTF3},
+ "learning": "no",
+}
+BRCTL = {
+ "brctl_name": [BRCTL_1, BRCTL_2, BRCTL_3],
+ "addvxlan": [VXLAN_1, VXLAN_2, VXLAN_3],
+ "vrf": ["RED", "BLUE", "GREEN"],
+ "stp": [0, 0, 0],
+}
+
+
+class CreateTopo(Topo):
+ """
+ Test BasicTopo - topology 1
+
+ * `Topo`: Topology object
+ """
+
+ def build(self, *_args, **_opts):
+ """Build function"""
+ tgen = get_topogen(self)
+
+ # Building topology from json file
+ build_topo_from_json(tgen, topo)
+
+
+def setup_module(mod):
+ """
+ Sets up the pytest environment
+
+ * `mod`: module name
+ """
+
+ global topo
+ 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...
+ tgen = Topogen(CreateTopo, mod.__name__)
+ # ... 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)
+
+ # Creating configuration from JSON
+ build_config_from_json(tgen, topo)
+
+ if version_cmp(platform.release(), '4.19') < 0:
+ error_msg = ('EVPN tests will not run (have kernel "{}", '
+ 'but it requires >= 4.19)'.format(platform.release()))
+ pytest.skip(error_msg)
+
+ global BGP_CONVERGENCE
+ 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("Pre-requisite config for testsuite")
+ prerequisite_config_for_test_suite(tgen)
+
+ 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)
+
+
+#####################################################
+#
+# Testcases
+#
+#####################################################
+
+
+def prerequisite_config_for_test_suite(tgen):
+ """
+ API to do prerequisite config for testsuite
+
+ parameters:
+ -----------
+ * `tgen`: topogen object
+ """
+
+ step("Configure vxlan, bridge interface")
+ for dut in ["e1", "d1", "d2"]:
+ step("[DUT: ]Configure vxlan")
+ vxlan_input = {
+ dut: {
+ "vxlan": [
+ {
+ "vxlan_name": VXLAN["vxlan_name"],
+ "vxlan_id": VXLAN["vxlan_id"],
+ "dstport": VXLAN["dstport"],
+ "local_addr": VXLAN["local_addr"][dut],
+ "learning": VXLAN["learning"],
+ }
+ ]
+ }
+ }
+
+ result = configure_vxlan(tgen, vxlan_input)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step("Configure bridge interface")
+ brctl_input = {
+ dut: {
+ "brctl": [
+ {
+ "brctl_name": BRCTL["brctl_name"],
+ "addvxlan": BRCTL["addvxlan"],
+ "vrf": BRCTL["vrf"],
+ "stp": BRCTL["stp"],
+ }
+ ]
+ }
+ }
+ result = configure_brctl(tgen, topo, brctl_input)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step("Configure default routes")
+ add_default_routes(tgen)
+
+
+def add_default_routes(tgen):
+ """
+ API to do prerequisite config for testsuite
+
+ parameters:
+ -----------
+ * `tgen`: topogen object
+ """
+
+ step("Add default routes..")
+
+ default_routes = {
+ "e1": {
+ "static_routes": [
+ {
+ "network": "{}/32".format(VXLAN["local_addr"]["d1"]),
+ "next_hop": topo["routers"]["d1"]["links"]["e1-link1"][
+ "ipv4"
+ ].split("/")[0],
+ },
+ {
+ "network": "{}/32".format(VXLAN["local_addr"]["d2"]),
+ "next_hop": topo["routers"]["d2"]["links"]["e1-link1"][
+ "ipv4"
+ ].split("/")[0],
+ },
+ ]
+ },
+ "d1": {
+ "static_routes": [
+ {
+ "network": "{}/32".format(VXLAN["local_addr"]["e1"]),
+ "next_hop": topo["routers"]["e1"]["links"]["d1-link1"][
+ "ipv4"
+ ].split("/")[0],
+ },
+ {
+ "network": "{}/32".format(VXLAN["local_addr"]["d2"]),
+ "next_hop": topo["routers"]["e1"]["links"]["d1-link1"][
+ "ipv4"
+ ].split("/")[0],
+ },
+ ]
+ },
+ "d2": {
+ "static_routes": [
+ {
+ "network": "{}/32".format(VXLAN["local_addr"]["d1"]),
+ "next_hop": topo["routers"]["e1"]["links"]["d2-link1"][
+ "ipv4"
+ ].split("/")[0],
+ },
+ {
+ "network": "{}/32".format(VXLAN["local_addr"]["e1"]),
+ "next_hop": topo["routers"]["e1"]["links"]["d2-link1"][
+ "ipv4"
+ ].split("/")[0],
+ },
+ ]
+ },
+ }
+
+ result = create_static_routes(tgen, default_routes)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
+
+
+def test_RD_verification_manual_and_auto_p0(request):
+ """
+ RD verification (manual/auto).
+ """
+
+ tgen = get_topogen()
+ tc_name = request.node.name
+ write_test_header(tc_name)
+ check_router_status(tgen)
+ reset_config_on_routers(tgen)
+ add_default_routes(tgen)
+
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ step(
+ "Advertise prefixes from VNF routers R1 and R2 in associated "
+ "VRFs for both address-family."
+ )
+ step(
+ "Advertise vrf RED's routes in EVPN address family from Edge-1 router"
+ ", without manual configuration of RD."
+ )
+
+ for addr_type in ADDR_TYPES:
+ input_dict_1 = {
+ "r1": {
+ "static_routes": [
+ {
+ "network": NETWORK1_1[addr_type],
+ "next_hop": NEXT_HOP_IP[addr_type],
+ "vrf": "RED",
+ }
+ ]
+ },
+ "r2": {
+ "static_routes": [
+ {
+ "network": NETWORK2_1[addr_type],
+ "next_hop": NEXT_HOP_IP[addr_type],
+ "vrf": "BLUE",
+ },
+ {
+ "network": NETWORK3_1[addr_type],
+ "next_hop": NEXT_HOP_IP[addr_type],
+ "vrf": "GREEN",
+ }
+ ]
+ }
+ }
+
+ result = create_static_routes(tgen, input_dict_1)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step("Verify on DCG-1 and DCG-2:")
+ step("EVPN route for 10.1.1.1/32 has auto-assigned RD value.")
+
+ for dut in ["d1", "d2"]:
+ input_routes = {key: topo["routers"][key] for key in ["r1"]}
+ result = verify_attributes_for_evpn_routes(
+ tgen, topo, dut, input_routes, rd="auto", rd_peer="e1"
+ )
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step(
+ "Configure RD for vrf RED manually as 50.50.50.50:50 and "
+ "advertise vrf RED's routes in EVPN address family from "
+ "Edge-1 router."
+ )
+
+ input_dict_rd = {
+ "e1": {
+ "bgp": [
+ {
+ "local_as": "100",
+ "vrf": "RED",
+ "address_family": {"l2vpn": {"evpn": {"rd": "50.50.50.50:50"}}},
+ }
+ ]
+ }
+ }
+
+ result = create_router_bgp(tgen, topo, input_dict_rd)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
+
+ step("EVPN route for vrf RED has RD value as 50.50.50.50:50")
+ for dut in ["d1", "d2"]:
+ input_routes = {key: topo["routers"][key] for key in ["r1"]}
+ result = verify_attributes_for_evpn_routes(
+ tgen, topo, dut, input_routes, rd="50.50.50.50:50"
+ )
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step(
+ "Configure RD for vrf RED manually as 100.100.100.100:100 and "
+ "advertise vrf RED's routes in EVPN address family from Edge-1 "
+ "router."
+ )
+ input_dict_rd = {
+ "e1": {
+ "bgp": [
+ {
+ "local_as": "100",
+ "vrf": "RED",
+ "address_family": {
+ "l2vpn": {"evpn": {"rd": "100.100.100.100:100"}}
+ }
+ }
+ ]
+ }
+ }
+
+ result = create_router_bgp(tgen, topo, input_dict_rd)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
+
+ step(
+ "EVPN route for vrf RED is overridden with RD value as " "100.100.100.100:100."
+ )
+
+ for dut in ["d1", "d2"]:
+ input_routes = {key: topo["routers"][key] for key in ["r1"]}
+ result = verify_attributes_for_evpn_routes(
+ tgen, topo, dut, input_routes, rd="100.100.100.100:100"
+ )
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step(
+ "Configure RD for vrf BLUE manually same as vrf RED "
+ "(100.100.100.100:100) and advertise vrf RED and BLUE's routes "
+ "in EVPN address family from Edge-1 router."
+ )
+
+ input_dict_rd = {
+ "e1": {
+ "bgp": [
+ {
+ "local_as": "100",
+ "vrf": "BLUE",
+ "address_family": {
+ "l2vpn": {"evpn": {"rd": "100.100.100.100:100"}}
+ },
+ }
+ ]
+ }
+ }
+
+ result = create_router_bgp(tgen, topo, input_dict_rd)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
+
+ step(
+ "Delete manually configured RD and advertise vrf RED's routes "
+ "in EVPN address family from Edge-1 router."
+ )
+
+ input_dict_rd = {
+ "e1": {
+ "bgp": [
+ {
+ "local_as": "100",
+ "vrf": "RED",
+ "address_family": {
+ "l2vpn": {"evpn": {"no rd": "100.100.100.100:100"}}
+ },
+ }
+ ]
+ }
+ }
+
+ result = create_router_bgp(tgen, topo, input_dict_rd)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
+
+ step(
+ "Configure same RD value for vrf GREEN, as auto generated RD "
+ "value for vrf RED on Edge-1 router."
+ )
+
+ input_dict_rd = {
+ "e1": {
+ "bgp": [
+ {
+ "local_as": "100",
+ "vrf": "GREEN",
+ "address_family": {"l2vpn": {"evpn": {"rd": "10.0.0.33:1"}}},
+ }
+ ]
+ }
+ }
+
+ result = create_router_bgp(tgen, topo, input_dict_rd)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
+
+ step("Delete auto configured RD value from vrf RED in EVPN " "address family.")
+
+ input_dict_rd = {
+ "e1": {
+ "bgp": [
+ {
+ "local_as": "100",
+ "vrf": "GREEN",
+ "address_family": {"l2vpn": {"evpn": {"no rd": "10.0.0.33:1"}}},
+ }
+ ]
+ }
+ }
+
+ result = create_router_bgp(tgen, topo, input_dict_rd)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
+
+ step("Configure RD value as 100.100.100:100")
+
+ input_dict_rd = {
+ "e1": {
+ "bgp": [
+ {
+ "local_as": "100",
+ "vrf": "GREEN",
+ "address_family": {"l2vpn": {"evpn": {"rd": "100.100.100:100"}}},
+ }
+ ]
+ }
+ }
+
+ result = create_router_bgp(tgen, topo, input_dict_rd)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
+
+ write_test_footer(tc_name)
+
+
+def test_RT_verification_manual_p0(request):
+ """
+ RT verification(manual)
+ """
+
+ tgen = get_topogen()
+ tc_name = request.node.name
+ write_test_header(tc_name)
+ check_router_status(tgen)
+ reset_config_on_routers(tgen)
+ add_default_routes(tgen)
+
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ step(
+ "Advertise prefixes from VNF routers R1 and R2 in associated "
+ "VRFs for both address-family."
+ )
+ step("Advertise VRF routes as in EVPN address family from Edge-1 " "router.")
+
+ for addr_type in ADDR_TYPES:
+ input_dict_1 = {
+ "r1": {
+ "static_routes": [
+ {
+ "network": NETWORK1_1[addr_type],
+ "next_hop": NEXT_HOP_IP[addr_type],
+ "vrf": "RED",
+ }
+ ]
+ },
+ "r2": {
+ "static_routes": [
+ {
+ "network": NETWORK2_1[addr_type],
+ "next_hop": NEXT_HOP_IP[addr_type],
+ "vrf": "BLUE",
+ },
+ {
+ "network": NETWORK3_1[addr_type],
+ "next_hop": NEXT_HOP_IP[addr_type],
+ "vrf": "GREEN",
+ }
+ ]
+ }
+ }
+
+ result = create_static_routes(tgen, input_dict_1)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step(
+ "Configure RT for vrf RED manually as export 100:100 "
+ "and advertise vrf RED's routes in EVPN address family"
+ " from Edge-1 router."
+ )
+
+ input_dict_rt = {
+ "e1": {
+ "bgp": [
+ {
+ "local_as": "100",
+ "vrf": "RED",
+ "address_family": {
+ "ipv4": {
+ "unicast": {"neighbor": {"r1": {"dest_link": {"e1": {}}}}}
+ },
+ "ipv6": {
+ "unicast": {"neighbor": {"r1": {"dest_link": {"e1": {}}}}}
+ },
+ "l2vpn": {
+ "evpn": {"route-target": {"export": [{"value": "100:100"}]}}
+ },
+ }
+ }
+ ]
+ }
+ }
+
+ result = create_router_bgp(tgen, topo, input_dict_rt)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
+
+ step(
+ "Verify on dcg-1 and dcg-2, EVPN route for 10.1.1.1/32"
+ " and 10::1/128 have RT value as 100:100."
+ )
+
+ for dut in ["d1", "d2"]:
+ input_routes = {key: topo["routers"][key] for key in ["r1"]}
+ result = verify_attributes_for_evpn_routes(
+ tgen, topo, dut, input_routes, rt="100:100"
+ )
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step(
+ "Configure RT for vrf RED manually as export 500:500 and"
+ " advertise vrf RED's routes in EVPN address family from"
+ " e1 router."
+ )
+
+ input_dict_rt = {
+ "e1": {
+ "bgp": [
+ {
+ "local_as": "100",
+ "vrf": "RED",
+ "address_family": {
+ "l2vpn": {
+ "evpn": {"route-target": {"export": [{"value": "500:500"}]}}
+ }
+ },
+ }
+ ]
+ }
+ }
+
+ result = create_router_bgp(tgen, topo, input_dict_rt)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
+
+ step(
+ "Verify on dcg-1 and dcg-2, EVPN route for 10.1.1.1/32"
+ " and 10::1/128 have RT value as 500:500."
+ )
+
+ for dut in ["d1", "d2"]:
+ input_routes = {key: topo["routers"][key] for key in ["r1"]}
+ result = verify_attributes_for_evpn_routes(
+ tgen, topo, dut, input_routes, rt=["100:100", "500:500"]
+ )
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step(
+ "Import RT value 100:100 and 500:500 in vrf BLUE manually on"
+ " peer router DCG-1 and DCG-2."
+ )
+
+ input_dict_rt = {
+ "d1": {
+ "bgp": [
+ {
+ "local_as": "100",
+ "vrf": "BLUE",
+ "address_family": {
+ "l2vpn": {
+ "evpn": {
+ "route-target": {
+ "import": [
+ {"value": "100:100"},
+ {"value": "500:500"},
+ ]
+ }
+ }
+ }
+ },
+ }
+ ]
+ },
+ "d2": {
+ "bgp": [
+ {
+ "local_as": "200",
+ "vrf": "BLUE",
+ "address_family": {
+ "l2vpn": {
+ "evpn": {
+ "route-target": {
+ "import": [
+ {"value": "100:100"},
+ {"value": "500:500"},
+ ]
+ }
+ }
+ }
+ },
+ }
+ ]
+ },
+ }
+
+ result = create_router_bgp(tgen, topo, input_dict_rt)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
+
+ step(
+ "EVPN route for 10.1.1.1/32 and 10::1 should be installed "
+ "in vrf BLUE on DCG-1 and DCG-2 and further advertised to "
+ "VNF router."
+ )
+
+ for addr_type in ADDR_TYPES:
+ input_routes = {
+ "r1": {
+ "static_routes": [{"network": [NETWORK1_1[addr_type]], "vrf": "BLUE"}]
+ }
+ }
+ result = verify_rib(tgen, addr_type, "d1", input_routes)
+ assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
+
+ result = verify_rib(tgen, addr_type, "d2", input_routes)
+ assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
+
+ step(
+ "Delete import RT value 500:500 in vrf BLUE manually on "
+ "peer router DCG-1 and DCG-2."
+ )
+
+ input_dict_rt = {
+ "d1": {
+ "bgp": [
+ {
+ "local_as": "100",
+ "vrf": "BLUE",
+ "address_family": {
+ "l2vpn": {
+ "evpn": {
+ "route-target": {
+ "import": [{"value": "500:500", "delete": True}]
+ }
+ }
+ }
+ },
+ }
+ ]
+ },
+ "d2": {
+ "bgp": [
+ {
+ "local_as": "200",
+ "vrf": "BLUE",
+ "address_family": {
+ "l2vpn": {
+ "evpn": {
+ "route-target": {
+ "import": [{"value": "500:500", "delete": True}]
+ }
+ }
+ }
+ },
+ }
+ ]
+ },
+ }
+
+ result = create_router_bgp(tgen, topo, input_dict_rt)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
+
+ for dut in ["d1", "d2"]:
+ input_routes = {key: topo["routers"][key] for key in ["r1"]}
+ result = verify_attributes_for_evpn_routes(
+ tgen, topo, dut, input_routes, rt=["100:100", "500:500"]
+ )
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step("Delete RT export value 100:100 for vrf RED on Edge-1")
+
+ input_dict_rt = {
+ "e1": {
+ "bgp": [
+ {
+ "local_as": "100",
+ "vrf": "RED",
+ "address_family": {
+ "l2vpn": {
+ "evpn": {
+ "route-target": {
+ "export": [{"value": "100:100", "delete": True}]
+ }
+ }
+ }
+ },
+ }
+ ]
+ }
+ }
+
+ result = create_router_bgp(tgen, topo, input_dict_rt)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
+
+ step(
+ "EVPN route for 10.1.1.1/32 and 10::1 should be withdrawn "
+ "from vrf BLUE on DCG-1,DCG-2 and VNF router."
+ )
+
+ for addr_type in ADDR_TYPES:
+ input_routes = {
+ "r1": {
+ "static_routes": [{"network": [NETWORK1_1[addr_type]], "vrf": "BLUE"}]
+ }
+ }
+ result = verify_rib(tgen, addr_type, "d1", input_routes, expected=False)
+ assert result is not True, (
+ "Testcase {} :Failed \n Expected Behavior: Routes are still "
+ "present \n Error: {}".format(tc_name, result)
+ )
+ logger.info("Expected Behavior: {}".format(result))
+
+ result = verify_rib(tgen, addr_type, "d2", input_routes, expected=False)
+ assert result is not True, (
+ "Testcase {} :Failed \n Expected Behavior: Routes are still "
+ "present \n Error: {}".format(tc_name, result)
+ )
+ logger.info("Expected Behavior: {}".format(result))
+
+ step(
+ "Configure RT value as 100:100000010000010000101010 to check "
+ "the boundary value."
+ )
+
+ input_dict_rt = {
+ "e1": {
+ "bgp": [
+ {
+ "local_as": "100",
+ "vrf": "RED",
+ "address_family": {
+ "l2vpn": {
+ "evpn": {
+ "route-target": {
+ "export": [
+ {"value": "100:100000010000010000101010"}
+ ]
+ }
+ }
+ }
+ },
+ }
+ ]
+ }
+ }
+
+ result = create_router_bgp(tgen, topo, input_dict_rt)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
+
+ step(
+ "CLI error: RT value: 100:100000010000010000101010 should not " "be configured"
+ )
+
+ dut = "e1"
+ input_routes = {key: topo["routers"][key] for key in ["r1"]}
+ result = verify_attributes_for_evpn_routes(
+ tgen, topo, dut, input_routes, rt="100:100000010000010000101010", expected=False
+ )
+ assert result is not True, (
+ "Testcase {} :Failed \n Expected Behavior: RT value of out"
+ " of boundary \n Error: {}".format(tc_name, result)
+ )
+ logger.info("Expected Behavior: {}".format(result))
+
+ write_test_footer(tc_name)
+
+
+def test_active_standby_evpn_implementation_p1(request):
+ """
+ In an active/standby EVPN implementation, if active DCG goes down,
+ secondary takes over.
+ """
+
+ tgen = get_topogen()
+ tc_name = request.node.name
+ write_test_header(tc_name)
+ check_router_status(tgen)
+ reset_config_on_routers(tgen)
+ add_default_routes(tgen)
+
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ step(
+ "Taken care in base config: Configure BGP neighborship for both "
+ "address families(IPv4 & IPv6) between DCG-1/DCG-2 and VFN routers"
+ "(R3 and R4)."
+ )
+
+ step(
+ "BGP neighborships come up within defined VRFs. Please use below "
+ "command: sh bgp vrf all summary"
+ )
+
+ result = verify_bgp_convergence(tgen, topo, "d1")
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
+
+ result = verify_bgp_convergence(tgen, topo, "d2")
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
+
+ step(
+ "Advertise prefixes from VNF routers R3 and R4 in associated "
+ "VRFs for both address-families."
+ )
+
+ for addr_type in ADDR_TYPES:
+ input_dict_1 = {
+ "r3": {
+ "static_routes": [
+ {
+ "network": NETWORK1_2[addr_type],
+ "next_hop": NEXT_HOP_IP[addr_type],
+ "vrf": "RED",
+ }
+ ]
+ },
+ "r4": {
+ "static_routes": [
+ {
+ "network": NETWORK1_3[addr_type],
+ "next_hop": NEXT_HOP_IP[addr_type],
+ "vrf": "BLUE",
+ },
+ {
+ "network": NETWORK1_4[addr_type],
+ "next_hop": NEXT_HOP_IP[addr_type],
+ "vrf": "GREEN",
+ }
+ ]
+ }
+ }
+
+ result = create_static_routes(tgen, input_dict_1)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step(
+ "Redistribute static in (IPv4 and IPv6) address-family "
+ "on Edge-1 for all VRFs."
+ )
+
+ input_dict_2 = {}
+ for dut in ["r3", "r4"]:
+ temp = {dut: {"bgp": []}}
+ input_dict_2.update(temp)
+
+ if dut == "r3":
+ VRFS = ["RED"]
+ AS_NUM = [3]
+ if dut == "r4":
+ VRFS = ["BLUE", "GREEN"]
+ AS_NUM = [4, 4]
+
+ for vrf, as_num in zip(VRFS, AS_NUM):
+ temp[dut]["bgp"].append(
+ {
+ "local_as": as_num,
+ "vrf": vrf,
+ "address_family": {
+ "ipv4": {
+ "unicast": {"redistribute": [{"redist_type": "static"}]}
+ },
+ "ipv6": {
+ "unicast": {"redistribute": [{"redist_type": "static"}]}
+ },
+ },
+ }
+ )
+
+ result = create_router_bgp(tgen, topo, input_dict_2)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
+
+ step("Prefixes are received in respective VRFs on DCG-1/DCG-2.")
+
+ for addr_type in ADDR_TYPES:
+ input_routes = {
+ "r3": {
+ "static_routes": [
+ {
+ "network": NETWORK1_2[addr_type],
+ "next_hop": NEXT_HOP_IP[addr_type],
+ "vrf": "RED",
+ }
+ ]
+ },
+ "r4": {
+ "static_routes": [
+ {
+ "network": NETWORK1_3[addr_type],
+ "next_hop": NEXT_HOP_IP[addr_type],
+ "vrf": "BLUE",
+ },
+ {
+ "network": NETWORK1_4[addr_type],
+ "next_hop": NEXT_HOP_IP[addr_type],
+ "vrf": "GREEN",
+ },
+ ]
+ },
+ }
+
+ result = verify_rib(tgen, addr_type, "d1", input_routes)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ result = verify_rib(tgen, addr_type, "d2", input_routes)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step(
+ "Taken care in base config: Advertise VRF routes in EVPN "
+ "address-family from DCG-1 and DCG-2 router."
+ )
+
+ step("Verify on Edge-1 that EVPN routes are installed via next-hop " "as DCG-2.")
+
+ for addr_type in ADDR_TYPES:
+ input_routes = {
+ "r3": {
+ "static_routes": [
+ {
+ "network": NETWORK1_2[addr_type],
+ "next_hop": NEXT_HOP_IP[addr_type],
+ "vrf": "RED",
+ }
+ ]
+ },
+ "r4": {
+ "static_routes": [
+ {
+ "network": NETWORK1_3[addr_type],
+ "next_hop": NEXT_HOP_IP[addr_type],
+ "vrf": "BLUE",
+ },
+ {
+ "network": NETWORK1_4[addr_type],
+ "next_hop": NEXT_HOP_IP[addr_type],
+ "vrf": "GREEN",
+ },
+ ]
+ },
+ }
+
+ if addr_type == "ipv4":
+ result = verify_rib(
+ tgen, addr_type, "e1", input_routes, next_hop=BRIDGE_INTF2
+ )
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(
+ tc_name, result
+ )
+ else:
+ result = verify_rib(tgen, addr_type, "e1", input_routes)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step(
+ "Configure 'next-hop self' on DCG-1 for peer Edge-1 in EVPN " "address-family."
+ )
+
+ input_dict_3 = {
+ "d1": {
+ "bgp": [
+ {
+ "local_as": "100",
+ "address_family": {
+ "l2vpn": {
+ "evpn": {
+ "neighbor": {
+ "e1": {
+ "ipv4": {"d1-link1": {"next_hop_self": True}}
+ }
+ }
+ }
+ }
+ },
+ }
+ ]
+ }
+ }
+
+ result = create_router_bgp(tgen, topo, input_dict_3)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
+
+ logger.info(
+ "Creating route-map so ipv6 glpbal ip wpuld be preferred " "as next-hop"
+ )
+
+ step(
+ "Verify on Edge-1 that EVPN routes are now preferred via "
+ "next-hop as DCG-1(iBGP) due to shortest AS-Path."
+ )
+
+ for addr_type in ADDR_TYPES:
+
+ logger.info("Verifying only ipv4 routes")
+ if addr_type != "ipv4":
+ continue
+
+ input_routes = {
+ "r3": {
+ "static_routes": [
+ {
+ "network": NETWORK1_2[addr_type],
+ "next_hop": NEXT_HOP_IP[addr_type],
+ "vrf": "RED",
+ }
+ ]
+ },
+ "r4": {
+ "static_routes": [
+ {
+ "network": NETWORK1_3[addr_type],
+ "next_hop": NEXT_HOP_IP[addr_type],
+ "vrf": "BLUE",
+ },
+ {
+ "network": NETWORK1_4[addr_type],
+ "next_hop": NEXT_HOP_IP[addr_type],
+ "vrf": "GREEN",
+ },
+ ]
+ },
+ }
+
+ next_hop = topo["routers"]["d1"]["links"]["e1-link1"]["ipv4"].split("/")[0]
+
+ result = verify_rib(tgen, addr_type, "e1", input_routes, next_hop=next_hop)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ write_test_footer(tc_name)
+
+
+def test_evpn_routes_from_VNFs_p1(request):
+ """
+ EVPN routes are advertised/withdrawn, based on VNFs
+ advertising/withdrawing IP prefixes.
+ """
+
+ tgen = get_topogen()
+ tc_name = request.node.name
+ write_test_header(tc_name)
+ check_router_status(tgen)
+ reset_config_on_routers(tgen)
+ add_default_routes(tgen)
+
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ step(
+ "Advertise prefixes from VNF routers R1 and R2 in associated "
+ "VRFs for both address-family."
+ )
+
+ for addr_type in ADDR_TYPES:
+ input_dict_1 = {
+ "r1": {
+ "static_routes": [
+ {
+ "network": NETWORK1_1[addr_type],
+ "next_hop": NEXT_HOP_IP[addr_type],
+ "vrf": "RED",
+ }
+ ]
+ },
+ "r2": {
+ "static_routes": [
+ {
+ "network": NETWORK2_1[addr_type],
+ "next_hop": NEXT_HOP_IP[addr_type],
+ "vrf": "BLUE",
+ },
+ {
+ "network": NETWORK3_1[addr_type],
+ "next_hop": NEXT_HOP_IP[addr_type],
+ "vrf": "GREEN",
+ }
+ ]
+ }
+ }
+
+ result = create_static_routes(tgen, input_dict_1)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step(
+ "Taken care in base config: Advertise VNFs'(R1 and R2) "
+ "originated routes in EVPN address-family from Edge-1 to "
+ "DCG-1 and DCG-2 routers."
+ )
+ step(
+ "Taken care in base config: Advertise IPv4 and IPv6 routes "
+ "from default vrf in EVPN address-family from Edge-1."
+ )
+
+ step(
+ "Verify on DCG-2 that VNF routes are received in respective "
+ "VRFs along with auto derived RD/RT values 'show bgp l2vpn evpn'"
+ )
+ for dut in ["d1", "d2"]:
+ input_routes = {key: topo["routers"][key] for key in ["r1"]}
+ result = verify_evpn_routes(tgen, topo, dut, input_routes)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ input_routes = {key: topo["routers"][key] for key in ["r2"]}
+ result = verify_evpn_routes(tgen, topo, dut, input_routes)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step(
+ "Verify on R3 and R4 that DCG-2 further advertises all EVPN "
+ "routes to corresponding VRFs."
+ )
+ for addr_type in ADDR_TYPES:
+ input_routes = {key: topo["routers"][key] for key in ["r1"]}
+ result = verify_rib(tgen, addr_type, "r3", input_routes)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ for addr_type in ADDR_TYPES:
+ input_routes = {key: topo["routers"][key] for key in ["r2"]}
+ result = verify_rib(tgen, addr_type, "r4", input_routes)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step(
+ "Verify that DCG-2 receives EVPN routes associated to default "
+ "VRF and install in default IP routing table as well."
+ )
+ for addr_type in ADDR_TYPES:
+ input_routes = {key: topo["routers"][key] for key in ["r1"]}
+ result = verify_rib(tgen, addr_type, "d2", input_routes, expected=False)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ for addr_type in ADDR_TYPES:
+ input_routes = {key: topo["routers"][key] for key in ["r2"]}
+ result = verify_rib(tgen, addr_type, "d2", input_routes, expected=False)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step("Withdraw the IP prefixes from VFN(R1).")
+ dut = "r1"
+ input_dict_2 = {}
+ static_routes = topo["routers"][dut]["static_routes"]
+ for static_route in static_routes:
+ static_route["delete"] = True
+ temp = {dut: {"static_routes": [static_route]}}
+ input_dict_2.update(temp)
+
+ result = create_static_routes(tgen, input_dict_2)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step(
+ "Verify that DCG-2 removes EVPN routes corresponding to vrf RED and "
+ "send an withdraw to VNF(R3) as well."
+ )
+ for addr_type in ADDR_TYPES:
+ input_routes = {key: topo["routers"][key] for key in ["r1"]}
+ result = verify_rib(tgen, addr_type, "d2", input_routes, expected=False)
+ assert result is not True, "Testcase {} :Failed \n "
+ "Routes are still present: {}".format(tc_name, result)
+ logger.info("Expected Behavior: {}".format(result))
+
+ for addr_type in ADDR_TYPES:
+ input_routes = {key: topo["routers"][key] for key in ["r1"]}
+ result = verify_rib(tgen, addr_type, "r3", input_routes, expected=False)
+ assert result is not True, "Testcase {} :Failed \n "
+ "Routes are still present: {}".format(tc_name, result)
+ logger.info("Expected Behavior: {}".format(result))
+
+ step("Re-advertise IP prefixes from VFN(R1).")
+ step(
+ "Advertise prefixes from VNF routers R1 and R2 in associated "
+ "VRFs for both address-family."
+ )
+
+ for addr_type in ADDR_TYPES:
+ input_dict_1 = {
+ "r1": {
+ "static_routes": [
+ {
+ "network": NETWORK1_1[addr_type],
+ "next_hop": NEXT_HOP_IP[addr_type],
+ "vrf": "RED",
+ }
+ ]
+ },
+ "r2": {
+ "static_routes": [
+ {
+ "network": NETWORK2_1[addr_type],
+ "next_hop": NEXT_HOP_IP[addr_type],
+ "vrf": "BLUE",
+ },
+ {
+ "network": NETWORK3_1[addr_type],
+ "next_hop": NEXT_HOP_IP[addr_type],
+ "vrf": "GREEN",
+ }
+ ]
+ }
+ }
+
+ result = create_static_routes(tgen, input_dict_1)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step(
+ "Verify that DCG-2 receives EVPN routes corresponding to vrf RED "
+ "again and send an update to VNF(R3) as well."
+ )
+ for addr_type in ADDR_TYPES:
+ input_routes = {key: topo["routers"][key] for key in ["r1"]}
+ result = verify_rib(tgen, addr_type, "d2", input_routes)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ for addr_type in ADDR_TYPES:
+ input_routes = {key: topo["routers"][key] for key in ["r1"]}
+ result = verify_rib(tgen, addr_type, "r3", input_routes)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step("Delete vrf BLUE from router Edge-1")
+ input_dict_3 = {"e1": {"vrfs": [{"name": "BLUE", "id": "2", "delete": True}]}}
+
+ result = create_vrf_cfg(tgen, input_dict_3)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
+
+ step(
+ "Verify that DCG-2 removes EVPN routes corresponding to "
+ "vrf BLUE and send an withdraw to VNF(R4) as well."
+ )
+ for addr_type in ADDR_TYPES:
+ input_routes = {
+ "r2": {"static_routes": [{"network": NETWORK2_1[addr_type], "vrf": "BLUE"}]}
+ }
+
+ result = verify_rib(tgen, addr_type, "d2", input_routes, expected=False)
+ assert result is not True, "Testcase {} :Failed \n "
+ "Routes are still present: {}".format(tc_name, result)
+ logger.info("Expected Behavior: {}".format(result))
+
+ result = verify_rib(tgen, addr_type, "r4", input_routes, expected=False)
+ assert result is not True, "Testcase {} :Failed \n "
+ "Routes are still present: {}".format(tc_name, result)
+ logger.info("Expected Behavior: {}".format(result))
+
+ step("Add vrf BLUE on router Edge-1 again.")
+ interface = topo["routers"]["e1"]["links"]["r2-link1"]["interface"]
+ input_dict_3 = {
+ "e1": {
+ "links": {
+ "r2-link1": {
+ "interface": interface,
+ "ipv4": "auto",
+ "ipv6": "auto",
+ "vrf": "BLUE",
+ }
+ },
+ "vrfs": [{"name": "BLUE", "id": "2"}],
+ }
+ }
+ result = create_vrf_cfg(tgen, input_dict_3)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
+
+ logger.info(
+ "After deleting VRFs ipv6 addresses wil be deleted "
+ "from kernel Adding back ipv6 addresses"
+ )
+ dut = "e1"
+ vrfs = ["BLUE"]
+
+ for vrf in vrfs:
+ for c_link, c_data in topo["routers"][dut]["links"].items():
+ if "vrf" in c_data:
+ if c_data["vrf"] != vrf:
+ continue
+
+ intf_name = c_data["interface"]
+ intf_ipv6 = c_data["ipv6"]
+
+ create_interface_in_kernel(
+ tgen, dut, intf_name, intf_ipv6, vrf, create=False
+ )
+
+ logger.info("Wait for 60 sec.")
+ sleep(60)
+
+ step(
+ "Verify that DCG-2 receives EVPN routes corresponding to "
+ "vrf BLUE again and send an update to VNF(R4) as well."
+ )
+ for addr_type in ADDR_TYPES:
+ input_routes = {
+ "r2": {"static_routes": [{"network": NETWORK2_1[addr_type], "vrf": "BLUE"}]}
+ }
+
+ result = verify_rib(tgen, addr_type, "d2", input_routes)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ result = verify_rib(tgen, addr_type, "r4", input_routes)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step("Withdraw IPv6 address-family in EVPN advertisements for " "VRF GREEN")
+ addr_type = "ipv6"
+ input_dict_4 = {
+ "e1": {
+ "bgp": [
+ {
+ "local_as": "100",
+ "vrf": "GREEN",
+ "address_family": {
+ "l2vpn": {
+ "evpn": {
+ "advertise": {addr_type: {"unicast": {"delete": True}}}
+ }
+ }
+ },
+ }
+ ]
+ }
+ }
+
+ result = create_router_bgp(tgen, topo, input_dict_4)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
+
+ step(
+ "Verify that EVPN routes (IPv6)associated with vrf GREEN are "
+ "withdrawn from DCG-2 and VNF R4."
+ )
+ input_routes = {
+ "r2": {"static_routes": [{"network": NETWORK3_1[addr_type], "vrf": "GREEN"}]}
+ }
+
+ result = verify_rib(tgen, addr_type, "d2", input_routes, expected=False)
+ assert result is not True, "Testcase {} :Failed \n "
+ "Routes are still present: {}".format(tc_name, result)
+ logger.info("Expected Behavior: {}".format(result))
+
+ result = verify_rib(tgen, addr_type, "r4", input_routes, expected=False)
+ assert result is not True, "Testcase {} :Failed \n "
+ "Routes are still present: {}".format(tc_name, result)
+ logger.info("Expected Behavior: {}".format(result))
+
+ step("Advertise IPv6 address-family in EVPN advertisements " "for VRF GREEN.")
+ addr_type = "ipv6"
+ input_dict_4 = {
+ "e1": {
+ "bgp": [
+ {
+ "local_as": "100",
+ "vrf": "GREEN",
+ "address_family": {
+ "l2vpn": {"evpn": {"advertise": {addr_type: {"unicast": {}}}}}
+ },
+ }
+ ]
+ }
+ }
+
+ result = create_router_bgp(tgen, topo, input_dict_4)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
+
+ for addr_type in ADDR_TYPES:
+ input_routes = {
+ "r2": {
+ "static_routes": [{"network": NETWORK3_1[addr_type], "vrf": "GREEN"}]
+ }
+ }
+
+ result = verify_rib(tgen, addr_type, "d2", input_routes)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ result = verify_rib(tgen, addr_type, "r4", input_routes)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ write_test_footer(tc_name)
+
+
+@pytest.mark.parametrize(
+ "attribute", [{"route-type": "prefix"}, {"vni": VNI_1}, {"rt": "300:300"}]
+)
+def test_route_map_operations_for_evpn_address_family_p1(request, attribute):
+ """
+ Route-map operations for EVPN address family.
+ """
+
+ tgen = get_topogen()
+ tc_name = request.node.name
+ write_test_header(tc_name)
+ check_router_status(tgen)
+ reset_config_on_routers(tgen)
+ add_default_routes(tgen)
+
+ step(
+ "Advertise prefixes from VNF routers R1 and R2 in associated "
+ "VRFs for both address-family."
+ )
+
+ for addr_type in ADDR_TYPES:
+ input_dict_1 = {
+ "r1": {
+ "static_routes": [
+ {
+ "network": NETWORK1_1[addr_type],
+ "next_hop": NEXT_HOP_IP[addr_type],
+ "vrf": "RED",
+ }
+ ]
+ },
+ "r2": {
+ "static_routes": [
+ {
+ "network": NETWORK2_1[addr_type],
+ "next_hop": NEXT_HOP_IP[addr_type],
+ "vrf": "BLUE",
+ },
+ {
+ "network": NETWORK3_1[addr_type],
+ "next_hop": NEXT_HOP_IP[addr_type],
+ "vrf": "GREEN",
+ }
+ ]
+ }
+ }
+
+ result = create_static_routes(tgen, input_dict_1)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ step(
+ "Advertise VRF routes in EVPN address family from Edge-1 router."
+ " Configure a route-map on e1 to filter EVPN routes based on"
+ " below keywords: route-type: prefix"
+ )
+
+ for key, value in attribute.items():
+ if key == "rt":
+ logger.info("Creating extcommunity using raw_config")
+ raw_config = {
+ "d2": {
+ "raw_config": [
+ "bgp extcommunity-list standard ECOMM300 permit {} {}".format(
+ key, value
+ )
+ ]
+ }
+ }
+ result = apply_raw_config(tgen, raw_config)
+ assert result is True, "Testcase {} : Failed Error: {}".format(
+ tc_name, result
+ )
+
+ input_dict_1 = {
+ "e1": {
+ "route_maps": {
+ "rmap_route_type": [
+ {"action": "permit", "set": {"extcommunity": {key: value}}}
+ ]
+ }
+ },
+ "d2": {
+ "route_maps": {
+ "rmap_route_type": [
+ {"action": "permit", "match": {"extcommunity": "ECOMM300"}}
+ ]
+ }
+ },
+ }
+
+ else:
+ input_dict_1 = {
+ "e1": {
+ "route_maps": {
+ "rmap_route_type": [
+ {"action": "permit", "match": {"evpn": {key: value}}}
+ ]
+ }
+ },
+ "d2": {
+ "route_maps": {
+ "rmap_route_type": [
+ {"action": "permit", "match": {"evpn": {key: value}}}
+ ]
+ }
+ },
+ }
+ result = create_route_maps(tgen, input_dict_1)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ input_dict_2 = {
+ "e1": {
+ "bgp": [
+ {
+ "local_as": "100",
+ "address_family": {
+ "l2vpn": {
+ "evpn": {
+ "neighbor": {
+ "d2": {
+ "ipv4": {
+ "e1-link1": {
+ "route_maps": [
+ {
+ "name": "rmap_route_type",
+ "direction": "out",
+ }
+ ]
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ }
+ ]
+ },
+ "d2": {
+ "bgp": [
+ {
+ "local_as": "200",
+ "address_family": {
+ "l2vpn": {
+ "evpn": {
+ "neighbor": {
+ "e1": {
+ "ipv4": {
+ "d2-link1": {
+ "route_maps": [
+ {
+ "name": "rmap_route_type",
+ "direction": "in",
+ }
+ ]
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ }
+ ]
+ },
+ }
+
+ result = create_router_bgp(tgen, topo, input_dict_2)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
+
+ step(
+ "Verify on router DCG-2 that EVPN routes corresponding to all "
+ "VRFs are received. As all EVPN routes are type-5 only."
+ )
+
+ input_routes = {key: topo["routers"][key] for key in ["r1"]}
+ result = verify_evpn_routes(tgen, topo, "d2", input_routes)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
+
+ input_routes = {key: topo["routers"][key] for key in ["r2"]}
+ result = verify_evpn_routes(tgen, topo, "d2", input_routes)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
+
+ write_test_footer(tc_name)
+
+
+@pytest.mark.parametrize("attribute", ["locPrf", "weight", "path"])
+def test_bgp_attributes_for_evpn_address_family_p1(request, attribute):
+ """
+ BGP attributes for EVPN address-family.
+ """
+
+ tgen = get_topogen()
+ tc_name = request.node.name
+ write_test_header(tc_name)
+ check_router_status(tgen)
+ reset_config_on_routers(tgen)
+ add_default_routes(tgen)
+
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ step(
+ "Advertise prefixes from VNF routers R1 and R2 in associated "
+ "VRFs for both address-family."
+ )
+
+ for addr_type in ADDR_TYPES:
+ input_dict_1 = {
+ "r1": {
+ "static_routes": [
+ {
+ "network": NETWORK1_1[addr_type],
+ "next_hop": NEXT_HOP_IP[addr_type],
+ "vrf": "RED",
+ }
+ ]
+ },
+ "r2": {
+ "static_routes": [
+ {
+ "network": NETWORK2_1[addr_type],
+ "next_hop": NEXT_HOP_IP[addr_type],
+ "vrf": "BLUE",
+ },
+ {
+ "network": NETWORK3_1[addr_type],
+ "next_hop": NEXT_HOP_IP[addr_type],
+ "vrf": "GREEN",
+ }
+ ]
+ }
+ }
+
+ result = create_static_routes(tgen, input_dict_1)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ topo_local = deepcopy(topo)
+
+ logger.info("Modifying topology b/w e1 and d1 from iBGP to eBGP")
+ step("Delete BGP config for vrf RED.")
+
+ if attribute == "locPrf":
+ input_dict_vni = {
+ "d1": {
+ "vrfs": [
+ {"name": "RED", "no_vni": VNI_1},
+ {"name": "BLUE", "no_vni": VNI_2},
+ {"name": "GREEN", "no_vni": VNI_3},
+ ]
+ }
+ }
+ result = create_vrf_cfg(tgen, topo, input_dict=input_dict_vni)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ input_dict_2 = {}
+ for dut in ["d1"]:
+ temp = {dut: {"bgp": []}}
+ input_dict_2.update(temp)
+
+ INDEX = [0, 1, 2, 3]
+ VRFS = ["RED", "BLUE", "GREEN", None]
+ AS_NUM = [100, 100, 100, 100]
+
+ for index, vrf, as_num in zip(INDEX, VRFS, AS_NUM):
+ topo_local["routers"][dut]["bgp"][index]["local_as"] = 200
+ if vrf:
+ temp[dut]["bgp"].append(
+ {"local_as": as_num, "vrf": vrf, "delete": True}
+ )
+ else:
+ temp[dut]["bgp"].append({"local_as": as_num, "delete": True})
+
+ result = create_router_bgp(tgen, topo, input_dict_2)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ result = create_router_bgp(tgen, topo_local["routers"])
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step("Advertise VRF routes in EVPN address-family from DCG-1 " "and DCG-2 routers.")
+
+ for addr_type in ADDR_TYPES:
+ input_dict_1 = {
+ "r3": {
+ "static_routes": [
+ {
+ "network": NETWORK1_2[addr_type],
+ "next_hop": NEXT_HOP_IP[addr_type],
+ "vrf": "RED",
+ }
+ ]
+ },
+ "r4": {
+ "static_routes": [
+ {
+ "network": NETWORK1_3[addr_type],
+ "next_hop": NEXT_HOP_IP[addr_type],
+ "vrf": "BLUE",
+ },
+ {
+ "network": NETWORK1_4[addr_type],
+ "next_hop": NEXT_HOP_IP[addr_type],
+ "vrf": "GREEN",
+ },
+ ]
+ },
+ }
+
+ result = create_static_routes(tgen, input_dict_1)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step(
+ "Redistribute static in (IPv4 and IPv6) address-family "
+ "on Edge-1 for all VRFs."
+ )
+
+ input_dict_2 = {}
+ for dut in ["r3", "r4"]:
+ temp = {dut: {"bgp": []}}
+ input_dict_2.update(temp)
+
+ if dut == "r3":
+ VRFS = ["RED"]
+ AS_NUM = [3]
+ if dut == "r4":
+ VRFS = ["BLUE", "GREEN"]
+ AS_NUM = [4, 4]
+
+ for vrf, as_num in zip(VRFS, AS_NUM):
+ temp[dut]["bgp"].append(
+ {
+ "local_as": as_num,
+ "vrf": vrf,
+ "address_family": {
+ "ipv4": {
+ "unicast": {"redistribute": [{"redist_type": "static"}]}
+ },
+ "ipv6": {
+ "unicast": {"redistribute": [{"redist_type": "static"}]}
+ },
+ },
+ }
+ )
+
+ result = create_router_bgp(tgen, topo, input_dict_2)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
+
+ step(
+ "Verify on router Edge-1 that EVPN routes corresponding to "
+ "all VRFs are received from both routers DCG-1 and DCG-2"
+ )
+
+ for addr_type in ADDR_TYPES:
+ input_routes = {
+ "r3": {
+ "static_routes": [
+ {
+ "network": NETWORK1_2[addr_type],
+ "next_hop": NEXT_HOP_IP[addr_type],
+ "vrf": "RED",
+ }
+ ]
+ },
+ "r4": {
+ "static_routes": [
+ {
+ "network": NETWORK1_3[addr_type],
+ "next_hop": NEXT_HOP_IP[addr_type],
+ "vrf": "BLUE",
+ },
+ {
+ "network": NETWORK1_4[addr_type],
+ "next_hop": NEXT_HOP_IP[addr_type],
+ "vrf": "GREEN",
+ },
+ ]
+ },
+ }
+
+ result = verify_rib(tgen, addr_type, "e1", input_routes)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(
+ tc_name, result
+ )
+
+ step(
+ "Configure a route-map on Edge-1 to modify below BGP attributes "
+ "for EVPN address-family:"
+ )
+
+ if attribute == "path":
+ input_dict_1 = {
+ "e1": {
+ "route_maps": {
+ "rmap_d1".format(addr_type): [
+ {
+ "action": "permit",
+ "set": {
+ attribute: {
+ "as_num": "123 231 321",
+ "as_action": "prepend",
+ }
+ },
+ }
+ ],
+ "rmap_d2".format(addr_type): [
+ {
+ "action": "permit",
+ "set": {
+ attribute: {"as_num": "121", "as_action": "prepend"}
+ },
+ }
+ ],
+ }
+ }
+ }
+ else:
+ input_dict_1 = {
+ "e1": {
+ "route_maps": {
+ "rmap_d1".format(addr_type): [
+ {"action": "permit", "set": {attribute: 120}}
+ ],
+ "rmap_d2".format(addr_type): [
+ {"action": "permit", "set": {attribute: 150}}
+ ],
+ }
+ }
+ }
+ result = create_route_maps(tgen, input_dict_1)
+ assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
+
+ input_dict_2 = {
+ "e1": {
+ "bgp": [
+ {
+ "local_as": "100",
+ "address_family": {
+ "l2vpn": {
+ "evpn": {
+ "neighbor": {
+ "d1": {
+ "ipv4": {
+ "e1-link1": {
+ "route_maps": [
+ {
+ "name": "rmap_d1",
+ "direction": "in",
+ }
+ ]
+ }
+ }
+ },
+ "d2": {
+ "ipv4": {
+ "e1-link1": {
+ "route_maps": [
+ {
+ "name": "rmap_d2",
+ "direction": "in",
+ }
+ ]
+ }
+ }
+ },
+ }
+ }
+ }
+ },
+ }
+ ]
+ }
+ }
+
+ result = create_router_bgp(tgen, topo, input_dict_2)
+ assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
+
+ step(
+ "Verify on router Edge-1 that EVPN routes are preferred via"
+ " DCG-1 or DCG-2 based on best path selection criteria "
+ "(according to the configured BGP attribute values in route-map)."
+ )
+
+ for addr_type in ADDR_TYPES:
+ input_routes = {
+ "r3": {
+ "static_routes": [
+ {
+ "network": NETWORK1_2[addr_type],
+ "next_hop": NEXT_HOP_IP[addr_type],
+ "vrf": "RED",
+ }
+ ]
+ },
+ "r4": {
+ "static_routes": [
+ {
+ "network": NETWORK1_3[addr_type],
+ "next_hop": NEXT_HOP_IP[addr_type],
+ "vrf": "BLUE",
+ },
+ {
+ "network": NETWORK1_4[addr_type],
+ "next_hop": NEXT_HOP_IP[addr_type],
+ "vrf": "GREEN",
+ },
+ ]
+ },
+ }
+
+ result = verify_best_path_as_per_bgp_attribute(
+ tgen, addr_type, "e1", input_routes, attribute
+ )
+ assert result is True, "Testcase {} : Failed \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/lib/bgp.py b/tests/topotests/lib/bgp.py
index 971bbd0f3b..7b1eead944 100644
--- a/tests/topotests/lib/bgp.py
+++ b/tests/topotests/lib/bgp.py
@@ -27,6 +27,8 @@ import sys
from lib import topotest
from lib.topolog import logger
+from lib.topogen import TopoRouter, get_topogen
+
# Import common_config to use commomnly used APIs
from lib.common_config import (
create_common_configuration,
@@ -166,6 +168,7 @@ def create_router_bgp(tgen, topo, input_dict=None, build=False, load_config=True
ipv4_data = bgp_addr_data.setdefault("ipv4", {})
ipv6_data = bgp_addr_data.setdefault("ipv6", {})
+ l2vpn_data = bgp_addr_data.setdefault("l2vpn", {})
neigh_unicast = (
True
@@ -174,6 +177,8 @@ def create_router_bgp(tgen, topo, input_dict=None, build=False, load_config=True
else False
)
+ l2vpn_evpn = True if l2vpn_data.setdefault("evpn", {}) else False
+
if neigh_unicast:
data_all_bgp = __create_bgp_unicast_neighbor(
tgen,
@@ -184,6 +189,11 @@ def create_router_bgp(tgen, topo, input_dict=None, build=False, load_config=True
config_data=data_all_bgp,
)
+ if l2vpn_evpn:
+ data_all_bgp = __create_l2vpn_evpn_address_family(
+ tgen, topo, bgp_data, router, config_data=data_all_bgp
+ )
+
try:
result = create_common_configuration(
tgen, router, data_all_bgp, "bgp", build, load_config
@@ -467,6 +477,166 @@ def __create_bgp_unicast_neighbor(
return config_data
+def __create_l2vpn_evpn_address_family(
+ tgen, topo, input_dict, router, config_data=None
+):
+ """
+ Helper API to create configuration for l2vpn evpn address-family
+
+ Parameters
+ ----------
+ * `tgen` : Topogen object
+ * `topo` : json file data
+ * `input_dict` : Input dict data, required when configuring
+ from testcase
+ * `router` : router id to be configured.
+ * `build` : Only for initial setup phase this is set as True.
+ """
+
+ result = False
+
+ logger.debug("Entering lib API: {}".format(sys._getframe().f_code.co_name))
+
+ bgp_data = input_dict["address_family"]
+
+ for family_type, family_dict in bgp_data.iteritems():
+ if family_type != "l2vpn":
+ continue
+
+ family_data = family_dict["evpn"]
+ if family_data:
+ config_data.append("address-family l2vpn evpn")
+
+ advertise_data = family_data.setdefault("advertise", {})
+ neighbor_data = family_data.setdefault("neighbor", {})
+ advertise_all_vni_data = family_data.setdefault("advertise-all-vni", None)
+ rd_data = family_data.setdefault("rd", None)
+ no_rd_data = family_data.setdefault("no rd", False)
+ route_target_data = family_data.setdefault("route-target", {})
+
+ if advertise_data:
+ for address_type, unicast_type in advertise_data.items():
+
+ if isinstance(unicast_type, dict):
+ for key, value in unicast_type.items():
+ cmd = "advertise {} {}".format(address_type, key)
+
+ if value:
+ route_map = value.setdefault("route-map", {})
+ advertise_del_action = value.setdefault("delete", None)
+
+ if route_map:
+ cmd = "{} route-map {}".format(cmd, route_map)
+
+ if advertise_del_action:
+ cmd = "no {}".format(cmd)
+
+ config_data.append(cmd)
+
+ if neighbor_data:
+ for neighbor, neighbor_data in neighbor_data.items():
+ ipv4_neighbor = neighbor_data.setdefault("ipv4", {})
+ ipv6_neighbor = neighbor_data.setdefault("ipv6", {})
+
+ if ipv4_neighbor:
+ for neighbor_name, action in ipv4_neighbor.items():
+ neighbor_ip = topo[neighbor]["links"][neighbor_name][
+ "ipv4"
+ ].split("/")[0]
+
+ if isinstance(action, dict):
+ next_hop_self = action.setdefault("next_hop_self", None)
+ route_maps = action.setdefault("route_maps", {})
+
+ if next_hop_self is not None:
+ if next_hop_self is True:
+ config_data.append(
+ "neighbor {} "
+ "next-hop-self".format(neighbor_ip)
+ )
+ elif next_hop_self is False:
+ config_data.append(
+ "no neighbor {} "
+ "next-hop-self".format(neighbor_ip)
+ )
+
+ if route_maps:
+ for route_map in route_maps:
+ name = route_map.setdefault("name", {})
+ direction = route_map.setdefault("direction", "in")
+ del_action = route_map.setdefault("delete", False)
+
+ if not name:
+ logger.info(
+ "Router %s: 'name' "
+ "not present in "
+ "input_dict for BGP "
+ "neighbor route name",
+ router,
+ )
+ else:
+ cmd = "neighbor {} route-map {} " "{}".format(
+ neighbor_ip, name, direction
+ )
+
+ if del_action:
+ cmd = "no {}".format(cmd)
+
+ config_data.append(cmd)
+
+ else:
+ if action == "activate":
+ cmd = "neighbor {} activate".format(neighbor_ip)
+ elif action == "deactivate":
+ cmd = "no neighbor {} activate".format(neighbor_ip)
+
+ config_data.append(cmd)
+
+ if ipv6_neighbor:
+ for neighbor_name, action in ipv4_neighbor.items():
+ neighbor_ip = topo[neighbor]["links"][neighbor_name][
+ "ipv6"
+ ].split("/")[0]
+ if action == "activate":
+ cmd = "neighbor {} activate".format(neighbor_ip)
+ elif action == "deactivate":
+ cmd = "no neighbor {} activate".format(neighbor_ip)
+
+ config_data.append(cmd)
+
+ if advertise_all_vni_data == True:
+ cmd = "advertise-all-vni"
+ config_data.append(cmd)
+ elif advertise_all_vni_data == False:
+ cmd = "no advertise-all-vni"
+ config_data.append(cmd)
+
+ if rd_data:
+ cmd = "rd {}".format(rd_data)
+ config_data.append(cmd)
+
+ if no_rd_data:
+ cmd = "no rd {}".format(no_rd_data)
+ config_data.append(cmd)
+
+ if route_target_data:
+ for rt_type, rt_dict in route_target_data.items():
+ for _rt_dict in rt_dict:
+ rt_value = _rt_dict.setdefault("value", None)
+ del_rt = _rt_dict.setdefault("delete", None)
+
+ if rt_value:
+ cmd = "route-target {} {}".format(rt_type, rt_value)
+ if del_rt:
+ cmd = "no {}".format(cmd)
+
+ config_data.append(cmd)
+
+ logger.debug("Exiting lib API: {}".format(sys._getframe().f_code.co_name))
+
+ return config_data
+
+
def __create_bgp_neighbor(topo, input_dict, router, addr_type, add_neigh=True):
"""
Helper API to create neighbor specific configuration
@@ -489,7 +659,7 @@ def __create_bgp_neighbor(topo, input_dict, router, addr_type, add_neigh=True):
for dest_link, peer in peer_dict["dest_link"].iteritems():
nh_details = topo[name]
- if "vrfs" in topo[router]:
+ if "vrfs" in topo[router] or type(nh_details["bgp"]) is list:
remote_as = nh_details["bgp"][0]["local_as"]
else:
remote_as = nh_details["bgp"]["local_as"]
@@ -887,19 +1057,16 @@ def verify_bgp_convergence(tgen, topo, dut=None):
API will verify if BGP is converged with in the given time frame.
Running "show bgp summary json" command and verify bgp neighbor
state is established,
-
Parameters
----------
* `tgen`: topogen object
* `topo`: input json file data
* `dut`: device under test
-
Usage
-----
# To veriry is BGP is converged for all the routers used in
topology
results = verify_bgp_convergence(tgen, topo, dut="r1")
-
Returns
-------
errormsg(str) or True
@@ -3463,3 +3630,552 @@ def verify_gr_address_family(tgen, topo, addr_type, addr_family, dut):
return errormsg
logger.debug("Exiting lib API: {}".format(sys._getframe().f_code.co_name))
+
+
+@retry(attempts=5, wait=2, return_is_str=True, initial_wait=2)
+def verify_attributes_for_evpn_routes(
+ tgen,
+ topo,
+ dut,
+ input_dict,
+ rd=None,
+ rt=None,
+ ethTag=None,
+ ipLen=None,
+ rd_peer=None,
+ rt_peer=None,
+):
+ """
+ API to verify rd and rt value using "sh bgp l2vpn evpn 10.1.1.1"
+ command.
+
+ Parameters
+ ----------
+ * `tgen`: topogen object
+ * `topo` : json file data
+ * `dut` : device under test
+ * `input_dict`: having details like - for which route, rd value
+ needs to be verified
+ * `rd` : route distinguisher
+ * `rt` : route target
+ * `ethTag` : Ethernet Tag
+ * `ipLen` : IP prefix length
+ * `rd_peer` : Peer name from which RD will be auto-generated
+ * `rt_peer` : Peer name from which RT will be auto-generated
+
+ Usage
+ -----
+ input_dict_1 = {
+ "r1": {
+ "static_routes": [{
+ "network": [NETWORK1_1[addr_type]],
+ "next_hop": NEXT_HOP_IP[addr_type],
+ "vrf": "RED"
+ }]
+ }
+ }
+
+ result = verify_attributes_for_evpn_routes(tgen, topo,
+ input_dict, rd = "10.0.0.33:1")
+
+ Returns
+ -------
+ errormsg(str) or True
+ """
+
+ logger.debug("Entering lib API: {}".format(sys._getframe().f_code.co_name))
+ for router in input_dict.keys():
+ rnode = tgen.routers()[dut]
+
+ if "static_routes" in input_dict[router]:
+ for static_route in input_dict[router]["static_routes"]:
+ network = static_route["network"]
+
+ if "vrf" in static_route:
+ vrf = static_route["vrf"]
+
+ if type(network) is not list:
+ network = [network]
+
+ for route in network:
+ route = route.split("/")[0]
+ _addr_type = validate_ip_address(route)
+ if "v4" in _addr_type:
+ input_afi = "v4"
+ elif "v6" in _addr_type:
+ input_afi = "v6"
+
+ cmd = "show bgp l2vpn evpn {} json".format(route)
+ evpn_rd_value_json = run_frr_cmd(rnode, cmd, isjson=True)
+ if not bool(evpn_rd_value_json):
+ errormsg = "No output for '{}' cli".format(cmd)
+ return errormsg
+
+ if rd is not None and rd != "auto":
+ logger.info(
+ "[DUT: %s]: Verifying rd value for " "evpn route %s:",
+ dut,
+ route,
+ )
+
+ if rd in evpn_rd_value_json:
+ rd_value_json = evpn_rd_value_json[rd]
+ if rd_value_json["rd"] != rd:
+ errormsg = (
+ "[DUT: %s] Failed: Verifying"
+ " RD value for EVPN route: %s"
+ "[FAILED]!!, EXPECTED : %s "
+ " FOUND : %s"
+ % (dut, route, rd, rd_value_json["rd"])
+ )
+ return errormsg
+
+ else:
+ logger.info(
+ "[DUT %s]: Verifying RD value for"
+ " EVPN route: %s [PASSED]|| "
+ "Found Exprected: %s",
+ dut,
+ route,
+ rd,
+ )
+ return True
+
+ else:
+ errormsg = (
+ "[DUT: %s] RD : %s is not present"
+ " in cli json output" % (dut, rd)
+ )
+ return errormsg
+
+ if rd == "auto":
+ logger.info(
+ "[DUT: %s]: Verifying auto-rd value for " "evpn route %s:",
+ dut,
+ route,
+ )
+
+ if rd_peer:
+ index = 1
+ vni_dict = {}
+
+ rnode = tgen.routers()[rd_peer]
+ vrfs = topo["routers"][rd_peer]["vrfs"]
+ for vrf_dict in vrfs:
+ vni_dict[vrf_dict["name"]] = index
+ index += 1
+
+ show_bgp_json = run_frr_cmd(
+ rnode, "show bgp vrf all summary json", isjson=True
+ )
+
+ # Verifying output dictionary show_bgp_json is empty
+ if not bool(show_bgp_json):
+ errormsg = "BGP is not running"
+ return errormsg
+
+ show_bgp_json_vrf = show_bgp_json[vrf]
+ for afi, afi_data in show_bgp_json_vrf.items():
+ if input_afi not in afi:
+ continue
+ router_id = afi_data["routerId"]
+
+ rd = "{}:{}".format(router_id, vni_dict[vrf])
+ if rd in evpn_rd_value_json:
+ rd_value_json = evpn_rd_value_json[rd]
+ if rd_value_json["rd"] != rd:
+ errormsg = (
+ "[DUT: %s] Failed: Verifying"
+ " RD value for EVPN route: %s"
+ "[FAILED]!!, EXPECTED : %s "
+ " FOUND : %s"
+ % (dut, route, rd, rd_value_json["rd"])
+ )
+ return errormsg
+
+ else:
+ logger.info(
+ "[DUT %s]: Verifying RD value for"
+ " EVPN route: %s [PASSED]|| "
+ "Found Exprected: %s",
+ dut,
+ route,
+ rd,
+ )
+ return True
+
+ else:
+ errormsg = (
+ "[DUT: %s] RD : %s is not present"
+ " in cli json output" % (dut, rd)
+ )
+ return errormsg
+
+ if rt == "auto":
+ logger.info(
+ "[DUT: %s]: Verifying auto-rt value for " "evpn route %s:",
+ dut,
+ route,
+ )
+
+ if rt_peer:
+ vni_dict = {}
+
+ rnode = tgen.routers()[rt_peer]
+ show_bgp_json = run_frr_cmd(
+ rnode, "show bgp vrf all summary json", isjson=True
+ )
+
+ # Verifying output dictionary show_bgp_json is empty
+ if not bool(show_bgp_json):
+ errormsg = "BGP is not running"
+ return errormsg
+
+ show_bgp_json_vrf = show_bgp_json[vrf]
+ for afi, afi_data in show_bgp_json_vrf.items():
+ if input_afi not in afi:
+ continue
+ as_num = afi_data["as"]
+
+ show_vrf_vni_json = run_frr_cmd(
+ rnode, "show vrf vni json", isjson=True
+ )
+
+ vrfs = show_vrf_vni_json["vrfs"]
+ for vrf_dict in vrfs:
+ if vrf_dict["vrf"] == vrf:
+ vni_dict[vrf_dict["vrf"]] = str(vrf_dict["vni"])
+
+ # If AS is 4 byte, FRR uses only the lower 2 bytes of ASN+VNI
+ # for auto derived RT value.
+ if as_num > 65535:
+ as_bin = bin(as_num)
+ as_bin = as_bin[-16:]
+ as_num = int(as_bin, 2)
+
+ rt = "{}:{}".format(str(as_num), vni_dict[vrf])
+ for _rd, route_data in evpn_rd_value_json.items():
+ if route_data["ip"] == route:
+ for rt_data in route_data["paths"]:
+ if vni_dict[vrf] == rt_data["VNI"]:
+ rt_string = rt_data["extendedCommunity"][
+ "string"
+ ]
+ rt_input = "RT:{}".format(rt)
+ if rt_input not in rt_string:
+ errormsg = (
+ "[DUT: %s] Failed:"
+ " Verifying RT "
+ "value for EVPN "
+ " route: %s"
+ "[FAILED]!!,"
+ " EXPECTED : %s "
+ " FOUND : %s"
+ % (dut, route, rt_input, rt_string)
+ )
+ return errormsg
+
+ else:
+ logger.info(
+ "[DUT %s]: Verifying "
+ "RT value for EVPN "
+ "route: %s [PASSED]||"
+ "Found Exprected: %s",
+ dut,
+ route,
+ rt_input,
+ )
+ return True
+
+ else:
+ errormsg = (
+ "[DUT: %s] Route : %s is not"
+ " present in cli json output" % (dut, route)
+ )
+ return errormsg
+
+ if rt is not None and rt != "auto":
+ logger.info(
+ "[DUT: %s]: Verifying rt value for " "evpn route %s:",
+ dut,
+ route,
+ )
+
+ if type(rt) is not list:
+ rt = [rt]
+
+ for _rt in rt:
+ for _rd, route_data in evpn_rd_value_json.items():
+ if route_data["ip"] == route:
+ for rt_data in route_data["paths"]:
+ rt_string = rt_data["extendedCommunity"][
+ "string"
+ ]
+ rt_input = "RT:{}".format(_rt)
+ if rt_input not in rt_string:
+ errormsg = (
+ "[DUT: %s] Failed: "
+ "Verifying RT value "
+ "for EVPN route: %s"
+ "[FAILED]!!,"
+ " EXPECTED : %s "
+ " FOUND : %s"
+ % (dut, route, rt_input, rt_string)
+ )
+ return errormsg
+
+ else:
+ logger.info(
+ "[DUT %s]: Verifying RT"
+ " value for EVPN route:"
+ " %s [PASSED]|| "
+ "Found Exprected: %s",
+ dut,
+ route,
+ rt_input,
+ )
+ return True
+
+ else:
+ errormsg = (
+ "[DUT: %s] Route : %s is not"
+ " present in cli json output" % (dut, route)
+ )
+ return errormsg
+
+ if ethTag is not None:
+ logger.info(
+ "[DUT: %s]: Verifying ethTag value for " "evpn route :", dut
+ )
+
+ for _rd, route_data in evpn_rd_value_json.items():
+ if route_data["ip"] == route:
+ if route_data["ethTag"] != ethTag:
+ errormsg = (
+ "[DUT: %s] RD: %s, Failed: "
+ "Verifying ethTag value "
+ "for EVPN route: %s"
+ "[FAILED]!!,"
+ " EXPECTED : %s "
+ " FOUND : %s"
+ % (
+ dut,
+ _rd,
+ route,
+ ethTag,
+ route_data["ethTag"],
+ )
+ )
+ return errormsg
+
+ else:
+ logger.info(
+ "[DUT %s]: RD: %s, Verifying "
+ "ethTag value for EVPN route:"
+ " %s [PASSED]|| "
+ "Found Exprected: %s",
+ dut,
+ _rd,
+ route,
+ ethTag,
+ )
+ return True
+
+ else:
+ errormsg = (
+ "[DUT: %s] RD: %s, Route : %s "
+ "is not present in cli json "
+ "output" % (dut, _rd, route)
+ )
+ return errormsg
+
+ if ipLen is not None:
+ logger.info(
+ "[DUT: %s]: Verifying ipLen value for " "evpn route :", dut
+ )
+
+ for _rd, route_data in evpn_rd_value_json.items():
+ if route_data["ip"] == route:
+ if route_data["ipLen"] != int(ipLen):
+ errormsg = (
+ "[DUT: %s] RD: %s, Failed: "
+ "Verifying ipLen value "
+ "for EVPN route: %s"
+ "[FAILED]!!,"
+ " EXPECTED : %s "
+ " FOUND : %s"
+ % (dut, _rd, route, ipLen, route_data["ipLen"])
+ )
+ return errormsg
+
+ else:
+ logger.info(
+ "[DUT %s]: RD: %s, Verifying "
+ "ipLen value for EVPN route:"
+ " %s [PASSED]|| "
+ "Found Exprected: %s",
+ dut,
+ _rd,
+ route,
+ ipLen,
+ )
+ return True
+
+ else:
+ errormsg = (
+ "[DUT: %s] RD: %s, Route : %s "
+ "is not present in cli json "
+ "output " % (dut, route)
+ )
+ return errormsg
+
+ logger.debug("Exiting lib API: {}".format(sys._getframe().f_code.co_name))
+ return False
+
+
+@retry(attempts=5, wait=2, return_is_str=True, initial_wait=2)
+def verify_evpn_routes(
+ tgen, topo, dut, input_dict, routeType=5, EthTag=0, next_hop=None
+):
+ """
+ API to verify evpn routes using "sh bgp l2vpn evpn"
+ command.
+
+ Parameters
+ ----------
+ * `tgen`: topogen object
+ * `topo` : json file data
+ * `dut` : device under test
+ * `input_dict`: having details like - for which route, rd value
+ needs to be verified
+ * `route_type` : Route type 5 is supported as of now
+ * `EthTag` : Ethernet tag, by-default is 0
+ * `next_hop` : Prefered nexthop for the evpn routes
+
+ Usage
+ -----
+ input_dict_1 = {
+ "r1": {
+ "static_routes": [{
+ "network": [NETWORK1_1[addr_type]],
+ "next_hop": NEXT_HOP_IP[addr_type],
+ "vrf": "RED"
+ }]
+ }
+ }
+ result = verify_evpn_routes(tgen, topo, input_dict)
+
+ Returns
+ -------
+ errormsg(str) or True
+ """
+
+ logger.debug("Entering lib API: {}".format(sys._getframe().f_code.co_name))
+
+ for router in input_dict.keys():
+ rnode = tgen.routers()[dut]
+
+ logger.info("[DUT: %s]: Verifying evpn routes: ", dut)
+
+ if "static_routes" in input_dict[router]:
+ for static_route in input_dict[router]["static_routes"]:
+ network = static_route["network"]
+
+ if type(network) is not list:
+ network = [network]
+
+ missing_routes = {}
+ for route in network:
+ rd_keys = 0
+ ip_len = route.split("/")[1]
+ route = route.split("/")[0]
+
+ prefix = "[{}]:[{}]:[{}]:[{}]".format(
+ routeType, EthTag, ip_len, route
+ )
+
+ cmd = "show bgp l2vpn evpn route json"
+ evpn_value_json = run_frr_cmd(rnode, cmd, isjson=True)
+
+ if not bool(evpn_value_json):
+ errormsg = "No output for '{}' cli".format(cmd)
+ return errormsg
+
+ if evpn_value_json["numPrefix"] == 0:
+ errormsg = "[DUT: %s]: No EVPN prefixes exist" % (dut)
+ return errormsg
+
+ for key, route_data_json in evpn_value_json.items():
+ if isinstance(route_data_json, dict):
+ rd_keys += 1
+ if prefix not in route_data_json:
+ missing_routes[key] = prefix
+
+ if rd_keys == len(missing_routes.keys()):
+ errormsg = (
+ "[DUT: %s]: "
+ "Missing EVPN routes: "
+ "%s [FAILED]!!" % (dut, list(set(missing_routes.values())))
+ )
+ return errormsg
+
+ for key, route_data_json in evpn_value_json.items():
+ if isinstance(route_data_json, dict):
+ if prefix not in route_data_json:
+ continue
+
+ for paths in route_data_json[prefix]["paths"]:
+ for path in paths:
+ if path["routeType"] != routeType:
+ errormsg = (
+ "[DUT: %s]: "
+ "Verifying routeType "
+ "for EVPN route: %s "
+ "[FAILED]!! "
+ "Expected: %s, "
+ "Found: %s"
+ % (
+ dut,
+ prefix,
+ routeType,
+ path["routeType"],
+ )
+ )
+ return errormsg
+
+ elif next_hop:
+ for nh_dict in path["nexthops"]:
+ if nh_dict["ip"] != next_hop:
+ errormsg = (
+ "[DUT: %s]: "
+ "Verifying "
+ "nexthop for "
+ "EVPN route: %s"
+ "[FAILED]!! "
+ "Expected: %s,"
+ " Found: %s"
+ % (
+ dut,
+ prefix,
+ next_hop,
+ nh_dict["ip"],
+ )
+ )
+ return errormsg
+
+ else:
+ logger.info(
+ "[DUT %s]: Verifying "
+ "EVPN route : %s, "
+ "routeType: %s is "
+ "installed "
+ "[PASSED]|| ",
+ dut,
+ prefix,
+ routeType,
+ )
+ return True
+
+ logger.debug("Exiting lib API: {}".format(sys._getframe().f_code.co_name))
+
+ return False
diff --git a/tests/topotests/lib/common_config.py b/tests/topotests/lib/common_config.py
index d72d0aa223..156a5f7ea4 100644
--- a/tests/topotests/lib/common_config.py
+++ b/tests/topotests/lib/common_config.py
@@ -933,6 +933,16 @@ def create_vrf_cfg(tgen, topo, input_dict=None, build=False):
)
rnode.run(cmd)
+ if vni:
+ config_data.append("vrf {}".format(vrf["name"]))
+ cmd = "vni {}".format(vni)
+ config_data.append(cmd)
+
+ if del_vni:
+ config_data.append("vrf {}".format(vrf["name"]))
+ cmd = "no vni {}".format(del_vni)
+ config_data.append(cmd)
+
result = create_common_configuration(
tgen, c_router, config_data, "vrf", build=build
)
@@ -984,6 +994,34 @@ def create_interface_in_kernel(
rnode.run(cmd)
+def shutdown_bringup_interface_in_kernel(tgen, dut, intf_name, ifaceaction=False):
+ """
+ Cretae interfaces in kernel for ipv4/ipv6
+ Config is done in Linux Kernel:
+
+ Parameters
+ ----------
+ * `tgen` : Topogen object
+ * `dut` : Device for which interfaces to be added
+ * `intf_name` : interface name
+ * `ifaceaction` : False to shutdown and True to bringup the
+ ineterface
+ """
+
+ rnode = tgen.routers()[dut]
+
+ cmd = "ip link set dev"
+ if ifaceaction:
+ action = "up"
+ cmd = "{} {} {}".format(cmd, intf_name, action)
+ else:
+ action = "down"
+ cmd = "{} {} {}".format(cmd, intf_name, action)
+
+ logger.info("[DUT: %s]: Running command: %s", dut, cmd)
+ rnode.run(cmd)
+
+
def validate_ip_address(ip_address):
"""
Validates the type of ip address
@@ -1042,7 +1080,7 @@ def check_address_types(addr_type=None):
return addr_types
if addr_type not in addr_types:
- logger.error(
+ logger.debug(
"{} not in supported/configured address types {}".format(
addr_type, addr_types
)
@@ -1732,6 +1770,7 @@ def create_route_maps(tgen, input_dict, build=False):
set_action = set_data.setdefault("set_action", None)
nexthop = set_data.setdefault("nexthop", None)
origin = set_data.setdefault("origin", None)
+ ext_comm_list = set_data.setdefault("extcommunity", {})
# Local Preference
if local_preference:
@@ -1796,6 +1835,19 @@ def create_route_maps(tgen, input_dict, build=False):
logger.error("In large_comm_list 'id' not" " provided")
return False
+ if ext_comm_list:
+ rt = ext_comm_list.setdefault("rt", None)
+ del_comm = ext_comm_list.setdefault("delete", None)
+ if rt:
+ cmd = "set extcommunity rt {}".format(rt)
+ if del_comm:
+ cmd = "{} delete".format(cmd)
+
+ rmap_data.append(cmd)
+ else:
+ logger.debug("In ext_comm_list 'rt' not" " provided")
+ return False
+
# Weight
if weight:
rmap_data.append("set weight {}".format(weight))
@@ -2151,6 +2203,243 @@ def addKernelRoute(
return True
+def configure_vxlan(tgen, input_dict):
+ """
+ Add and configure vxlan
+
+ * `tgen`: tgen onject
+ * `input_dict` : data for vxlan config
+
+ Usage:
+ ------
+ input_dict= {
+ "dcg2":{
+ "vxlan":[{
+ "vxlan_name": "vxlan75100",
+ "vxlan_id": "75100",
+ "dstport": 4789,
+ "local_addr": "120.0.0.1",
+ "learning": "no",
+ "delete": True
+ }]
+ }
+ }
+
+ configure_vxlan(tgen, input_dict)
+
+ Returns:
+ -------
+ True or errormsg
+
+ """
+
+ logger.debug("Entering lib API: {}".format(sys._getframe().f_code.co_name))
+
+ router_list = tgen.routers()
+ for dut in input_dict.keys():
+ rnode = tgen.routers()[dut]
+
+ if "vxlan" in input_dict[dut]:
+ for vxlan_dict in input_dict[dut]["vxlan"]:
+ cmd = "ip link "
+
+ del_vxlan = vxlan_dict.setdefault("delete", None)
+ vxlan_names = vxlan_dict.setdefault("vxlan_name", [])
+ vxlan_ids = vxlan_dict.setdefault("vxlan_id", [])
+ dstport = vxlan_dict.setdefault("dstport", None)
+ local_addr = vxlan_dict.setdefault("local_addr", None)
+ learning = vxlan_dict.setdefault("learning", None)
+
+ config_data = []
+ if vxlan_names and vxlan_ids:
+ for vxlan_name, vxlan_id in zip(vxlan_names, vxlan_ids):
+ cmd = "ip link"
+
+ if del_vxlan:
+ cmd = "{} del {} type vxlan id {}".format(
+ cmd, vxlan_name, vxlan_id
+ )
+ else:
+ cmd = "{} add {} type vxlan id {}".format(
+ cmd, vxlan_name, vxlan_id
+ )
+
+ if dstport:
+ cmd = "{} dstport {}".format(cmd, dstport)
+
+ if local_addr:
+ ip_cmd = "ip addr add {} dev {}".format(
+ local_addr, vxlan_name
+ )
+ if del_vxlan:
+ ip_cmd = "ip addr del {} dev {}".format(
+ local_addr, vxlan_name
+ )
+
+ config_data.append(ip_cmd)
+
+ cmd = "{} local {}".format(cmd, local_addr)
+
+ if learning == "no":
+ cmd = "{} {} learning".format(cmd, learning)
+
+ elif learning == "yes":
+ cmd = "{} learning".format(cmd)
+
+ config_data.append(cmd)
+
+ try:
+ for _cmd in config_data:
+ logger.info("[DUT: %s]: Running command: %s", dut, _cmd)
+ rnode.run(_cmd)
+
+ except InvalidCLIError:
+ # Traceback
+ errormsg = traceback.format_exc()
+ logger.error(errormsg)
+ return errormsg
+
+ logger.debug("Exiting lib API: {}".format(sys._getframe().f_code.co_name))
+
+ return True
+
+
+def configure_brctl(tgen, topo, input_dict):
+ """
+ Add and configure brctl
+
+ * `tgen`: tgen onject
+ * `input_dict` : data for brctl config
+
+ Usage:
+ ------
+ input_dict= {
+ dut:{
+ "brctl": [{
+ "brctl_name": "br100",
+ "addvxlan": "vxlan75100",
+ "vrf": "RED",
+ "stp": "off"
+ }]
+ }
+ }
+
+ configure_brctl(tgen, topo, input_dict)
+
+ Returns:
+ -------
+ True or errormsg
+
+ """
+
+ logger.debug("Entering lib API: {}".format(sys._getframe().f_code.co_name))
+
+ router_list = tgen.routers()
+ for dut in input_dict.keys():
+ rnode = tgen.routers()[dut]
+
+ if "brctl" in input_dict[dut]:
+ for brctl_dict in input_dict[dut]["brctl"]:
+
+ brctl_names = brctl_dict.setdefault("brctl_name", [])
+ addvxlans = brctl_dict.setdefault("addvxlan", [])
+ stp_values = brctl_dict.setdefault("stp", [])
+ vrfs = brctl_dict.setdefault("vrf", [])
+
+ ip_cmd = "ip link set"
+ for brctl_name, vxlan, vrf, stp in zip(
+ brctl_names, addvxlans, vrfs, stp_values
+ ):
+
+ ip_cmd_list = []
+ cmd = "ip link add name {} type bridge stp_state {}".format(brctl_name, stp)
+
+ logger.info("[DUT: %s]: Running command: %s", dut, cmd)
+ rnode.run(cmd)
+
+ ip_cmd_list.append("{} up dev {}".format(ip_cmd, brctl_name))
+
+ if vxlan:
+ cmd = "{} dev {} master {}".format(ip_cmd, vxlan, brctl_name)
+
+ logger.info("[DUT: %s]: Running command: %s", dut, cmd)
+ rnode.run(cmd)
+
+ ip_cmd_list.append("{} up dev {}".format(ip_cmd, vxlan))
+
+ if vrf:
+ ip_cmd_list.append(
+ "{} dev {} master {}".format(ip_cmd, brctl_name, vrf)
+ )
+
+ for intf_name, data in topo["routers"][dut]["links"].items():
+ if "vrf" not in data:
+ continue
+
+ if data["vrf"] == vrf:
+ ip_cmd_list.append(
+ "{} up dev {}".format(ip_cmd, data["interface"])
+ )
+
+ try:
+ for _ip_cmd in ip_cmd_list:
+ logger.info("[DUT: %s]: Running command: %s", dut, _ip_cmd)
+ rnode.run(_ip_cmd)
+
+ except InvalidCLIError:
+ # Traceback
+ errormsg = traceback.format_exc()
+ logger.error(errormsg)
+ return errormsg
+
+ logger.debug("Exiting lib API: {}".format(sys._getframe().f_code.co_name))
+ return True
+
+
+def configure_interface_mac(tgen, input_dict):
+ """
+ Add and configure brctl
+
+ * `tgen`: tgen onject
+ * `input_dict` : data for mac config
+
+ input_mac= {
+ "edge1":{
+ "br75100": "00:80:48:BA:d1:00,
+ "br75200": "00:80:48:BA:d1:00
+ }
+ }
+
+ configure_interface_mac(tgen, input_mac)
+
+ Returns:
+ -------
+ True or errormsg
+
+ """
+
+ router_list = tgen.routers()
+ for dut in input_dict.keys():
+ rnode = tgen.routers()[dut]
+
+ for intf, mac in input_dict[dut].items():
+ cmd = "ifconfig {} hw ether {}".format(intf, mac)
+ logger.info("[DUT: %s]: Running command: %s", dut, cmd)
+
+ try:
+ result = rnode.run(cmd)
+ if len(result) != 0:
+ return result
+
+ except InvalidCLIError:
+ # Traceback
+ errormsg = traceback.format_exc()
+ logger.error(errormsg)
+ return errormsg
+
+ return True
+
+
#############################################
# Verification APIs
#############################################
@@ -2875,3 +3164,283 @@ def verify_create_community_list(tgen, input_dict):
logger.debug("Exiting lib API: {}".format(sys._getframe().f_code.co_name))
return True
+
+
+def verify_cli_json(tgen, input_dict):
+ """
+ API to verify if JSON is available for clis
+ command.
+
+ Parameters
+ ----------
+ * `tgen`: topogen object
+ * `input_dict`: CLIs for which JSON needs to be verified
+ Usage
+ -----
+ input_dict = {
+ "edge1":{
+ "cli": ["show evpn vni detail", show evpn rmac vni all]
+ }
+ }
+
+ result = verify_cli_json(tgen, input_dict)
+
+ Returns
+ -------
+ errormsg(str) or True
+ """
+
+ logger.debug("Entering lib API: {}".format(sys._getframe().f_code.co_name))
+ for dut in input_dict.keys():
+ rnode = tgen.routers()[dut]
+
+ for cli in input_dict[dut]["cli"]:
+ logger.info(
+ "[DUT: %s]: Verifying JSON is available for " "CLI %s :", dut, cli
+ )
+
+ test_cli = "{} json".format(cli)
+ ret_json = rnode.vtysh_cmd(test_cli, isjson=True)
+ if not bool(ret_json):
+ errormsg = "CLI: %s, JSON format is not available" % (cli)
+ return errormsg
+ elif "unknown" in ret_json or "Unknown" in ret_json:
+ errormsg = "CLI: %s, JSON format is not available" % (cli)
+ return errormsg
+ else:
+ logger.info(
+ "CLI : %s JSON format is available: " "\n %s", cli, ret_json
+ )
+
+ logger.debug("Exiting lib API: {}".format(sys._getframe().f_code.co_name))
+
+ return True
+
+
+@retry(attempts=2, wait=4, return_is_str=True, initial_wait=2)
+def verify_evpn_vni(tgen, input_dict):
+ """
+ API to verify evpn vni details using "show evpn vni detail json"
+ command.
+
+ Parameters
+ ----------
+ * `tgen`: topogen object
+ * `input_dict`: having details like - for which router, evpn details
+ needs to be verified
+ Usage
+ -----
+ input_dict = {
+ "edge1":{
+ "vni": [
+ {
+ "75100":{
+ "vrf": "RED",
+ "vxlanIntf": "vxlan75100",
+ "localVtepIp": "120.1.1.1",
+ "sviIntf": "br100"
+ }
+ }
+ ]
+ }
+ }
+
+ result = verify_evpn_vni(tgen, input_dict)
+
+ Returns
+ -------
+ errormsg(str) or True
+ """
+
+ logger.debug("Entering lib API: {}".format(sys._getframe().f_code.co_name))
+ for dut in input_dict.keys():
+ rnode = tgen.routers()[dut]
+
+ logger.info("[DUT: %s]: Verifying evpn vni details :", dut)
+
+ cmd = "show evpn vni detail json"
+ evpn_all_vni_json = run_frr_cmd(rnode, cmd, isjson=True)
+ if not bool(evpn_all_vni_json):
+ errormsg = "No output for '{}' cli".format(cmd)
+ return errormsg
+
+ if "vni" in input_dict[dut]:
+ for vni_dict in input_dict[dut]["vni"]:
+ found = False
+ vni = vni_dict["name"]
+ for evpn_vni_json in evpn_all_vni_json:
+ if "vni" in evpn_vni_json:
+ if evpn_vni_json["vni"] != int(vni):
+ continue
+
+ for attribute in vni_dict.keys():
+ if vni_dict[attribute] != evpn_vni_json[attribute]:
+ errormsg = (
+ "[DUT: %s] Verifying "
+ "%s for VNI: %s [FAILED]||"
+ ", EXPECTED : %s "
+ " FOUND : %s"
+ % (
+ dut,
+ attribute,
+ vni,
+ vni_dict[attribute],
+ evpn_vni_json[attribute],
+ )
+ )
+ return errormsg
+
+ else:
+ found = True
+ logger.info(
+ "[DUT: %s] Verifying"
+ " %s for VNI: %s , "
+ "Found Expected : %s ",
+ dut,
+ attribute,
+ vni,
+ evpn_vni_json[attribute],
+ )
+
+ if evpn_vni_json["state"] != "Up":
+ errormsg = (
+ "[DUT: %s] Failed: Verifying"
+ " State for VNI: %s is not Up" % (dut, vni)
+ )
+ return errormsg
+
+ else:
+ errormsg = (
+ "[DUT: %s] Failed:"
+ " VNI: %s is not present in JSON" % (dut, vni)
+ )
+ return errormsg
+
+ if found:
+ logger.info(
+ "[DUT %s]: Verifying VNI : %s "
+ "details and state is Up [PASSED]!!",
+ dut,
+ vni,
+ )
+ return True
+
+ else:
+ errormsg = (
+ "[DUT: %s] Failed:" " vni details are not present in input data" % (dut)
+ )
+ return errormsg
+
+ logger.debug("Exiting lib API: {}".format(sys._getframe().f_code.co_name))
+ return False
+
+
+@retry(attempts=2, wait=4, return_is_str=True, initial_wait=2)
+def verify_vrf_vni(tgen, input_dict):
+ """
+ API to verify vrf vni details using "show vrf vni json"
+ command.
+
+ Parameters
+ ----------
+ * `tgen`: topogen object
+ * `input_dict`: having details like - for which router, evpn details
+ needs to be verified
+ Usage
+ -----
+ input_dict = {
+ "edge1":{
+ "vrfs": [
+ {
+ "RED":{
+ "vni": 75000,
+ "vxlanIntf": "vxlan75100",
+ "sviIntf": "br100",
+ "routerMac": "00:80:48:ba:d1:00",
+ "state": "Up"
+ }
+ }
+ ]
+ }
+ }
+
+ result = verify_vrf_vni(tgen, input_dict)
+
+ Returns
+ -------
+ errormsg(str) or True
+ """
+
+ logger.debug("Entering lib API: {}".format(sys._getframe().f_code.co_name))
+ for dut in input_dict.keys():
+ rnode = tgen.routers()[dut]
+
+ logger.info("[DUT: %s]: Verifying vrf vni details :", dut)
+
+ cmd = "show vrf vni json"
+ vrf_all_vni_json = run_frr_cmd(rnode, cmd, isjson=True)
+ if not bool(vrf_all_vni_json):
+ errormsg = "No output for '{}' cli".format(cmd)
+ return errormsg
+
+ if "vrfs" in input_dict[dut]:
+ for vrfs in input_dict[dut]["vrfs"]:
+ for vrf, vrf_dict in vrfs.items():
+ found = False
+ for vrf_vni_json in vrf_all_vni_json["vrfs"]:
+ if "vrf" in vrf_vni_json:
+ if vrf_vni_json["vrf"] != vrf:
+ continue
+
+ for attribute in vrf_dict.keys():
+ if vrf_dict[attribute] == vrf_vni_json[attribute]:
+ found = True
+ logger.info(
+ "[DUT %s]: VRF: %s, "
+ "verifying %s "
+ ", Found Expected: %s "
+ "[PASSED]!!",
+ dut,
+ vrf,
+ attribute,
+ vrf_vni_json[attribute],
+ )
+ else:
+ errormsg = (
+ "[DUT: %s] VRF: %s, "
+ "verifying %s [FAILED!!] "
+ ", EXPECTED : %s "
+ ", FOUND : %s"
+ % (
+ dut,
+ vrf,
+ attribute,
+ vrf_dict[attribute],
+ vrf_vni_json[attribute],
+ )
+ )
+ return errormsg
+
+ else:
+ errormsg = "[DUT: %s] VRF: %s " "is not present in JSON" % (
+ dut,
+ vrf,
+ )
+ return errormsg
+
+ if found:
+ logger.info(
+ "[DUT %s] Verifying VRF: %s " " details [PASSED]!!",
+ dut,
+ vrf,
+ )
+ return True
+
+ else:
+ errormsg = (
+ "[DUT: %s] Failed:" " vrf details are not present in input data" % (dut)
+ )
+ return errormsg
+
+ logger.debug("Exiting lib API: {}".format(sys._getframe().f_code.co_name))
+ return False
diff --git a/tests/topotests/lib/topogen.py b/tests/topotests/lib/topogen.py
index efd5b90685..37b9715010 100644
--- a/tests/topotests/lib/topogen.py
+++ b/tests/topotests/lib/topogen.py
@@ -819,7 +819,9 @@ class TopoRouter(TopoGear):
if memleak_file is None:
return
- self.stop()
+ self.stop(False, False)
+ self.stop(wait=True)
+
self.logger.info("running memory leak report")
self.tgen.net[self.name].report_memory_leaks(memleak_file, testname)
diff --git a/tests/topotests/pbr-topo1/r1/pbr-map.json b/tests/topotests/pbr-topo1/r1/pbr-map.json
index f0738dc540..bfa0ecb849 100644
--- a/tests/topotests/pbr-topo1/r1/pbr-map.json
+++ b/tests/topotests/pbr-topo1/r1/pbr-map.json
@@ -62,6 +62,32 @@
},
"matchDst":"dead:beef::\/64",
"matchMark":314159
+ },
+ {
+ "sequenceNumber":15,
+ "vrfUnchanged":false,
+ "installed":true,
+ "installedReason":"Valid",
+ "nexthopGroup":{
+ "name":"ASAKUSA15",
+ "installed":true,
+ "installedInternally":1
+ },
+ "matchDst":"dead:beef::/64",
+ "matchDscp":10
+ },
+ {
+ "sequenceNumber":20,
+ "vrfUnchanged":false,
+ "installed":true,
+ "installedReason":"Valid",
+ "nexthopGroup":{
+ "name":"ASAKUSA20",
+ "installed":true,
+ "installedInternally":1
+ },
+ "matchDst":"dead:beef::/64",
+ "matchEcn":1
}
]
},
diff --git a/tests/topotests/pbr-topo1/r1/pbrd.conf b/tests/topotests/pbr-topo1/r1/pbrd.conf
index 298cba2860..45cb7656ab 100644
--- a/tests/topotests/pbr-topo1/r1/pbrd.conf
+++ b/tests/topotests/pbr-topo1/r1/pbrd.conf
@@ -73,6 +73,16 @@ pbr-map ASAKUSA seq 10
match mark 314159
set nexthop c0ff:ee::1
!
+pbr-map ASAKUSA seq 15
+ match dst-ip dead:beef::/64
+ match dscp af11
+ set nexthop c0ff:ee::1
+!
+pbr-map ASAKUSA seq 20
+ match dst-ip dead:beef::/64
+ match ecn 1
+ set nexthop c0ff:ee::1
+!
# Interface policies
int r1-eth1
pbr-policy EVA
diff --git a/tests/topotests/pytest.ini b/tests/topotests/pytest.ini
index ade5bfd501..77b8c2b478 100644
--- a/tests/topotests/pytest.ini
+++ b/tests/topotests/pytest.ini
@@ -1,6 +1,6 @@
# Skip pytests example directory
[pytest]
-norecursedirs = .git example-test example-topojson-test lib docker
+norecursedirs = .git example-test example-topojson-test lib docker evpn_type5_test_topo1
[topogen]
# Default configuration values
diff --git a/tests/topotests/route-scale/test_route_scale.py b/tests/topotests/route-scale/test_route_scale.py
index 9ba0c7e50e..508d1746b3 100755
--- a/tests/topotests/route-scale/test_route_scale.py
+++ b/tests/topotests/route-scale/test_route_scale.py
@@ -112,99 +112,103 @@ def test_converge_protocols():
if tgen.routers_have_failure():
pytest.skip(tgen.errors)
-def test_route_install():
- "Test route install for a variety of ecmp"
+def run_one_setup(r1, s):
+ "Run one ecmp config"
- tgen = get_topogen()
- # Don't run this test if we have any failure.
- if tgen.routers_have_failure():
- pytest.skip(tgen.errors)
+ # Extract params
+ expected_installed = s['expect_in']
+ expected_removed = s['expect_rem']
- installed_file = "{}/r1/installed.routes.json".format(CWD)
- expected_installed = json.loads(open(installed_file).read())
+ count = s['count']
+ wait = s['wait']
- removed_file = "{}/r1/no.routes.json".format(CWD)
- expected_removed = json.loads(open(removed_file).read())
+ logger.info("Testing 1 million routes X {} ecmp".format(s['ecmp']))
- r1 = tgen.gears["r1"]
+ r1.vtysh_cmd("sharp install route 1.0.0.0 \
+ nexthop-group {} 1000000".format(s['nhg']),
+ isjson=False)
- r1.vtysh_cmd("sharp install route 1.0.0.0 nexthop-group one 1000000", isjson=False)
test_func = partial(topotest.router_json_cmp, r1, "show ip route summary json", expected_installed)
- _, result = topotest.run_and_expect(test_func, None, count=40, wait=5)
- output = r1.vtysh_cmd("sharp data route", isjson=False)
- logger.info("1 million routes X 1 ecmp installed")
- logger.info(output)
- r1.vtysh_cmd("sharp remove route 1.0.0.0 1000000", isjson=False)
- test_func = partial(topotest.router_json_cmp, r1, "show ip route summary json", expected_removed)
- _, result = topotest.run_and_expect(test_func, None, count=40, wait=5)
- output = r1.vtysh_cmd("sharp data route", isjson=False)
- logger.info("1 million routes x 1 ecmp removed")
- logger.info(output)
+ success, result = topotest.run_and_expect(test_func, None, count, wait)
+ assert success, "Route scale test install failed:\n{}".format(result)
- r1.vtysh_cmd("sharp install route 1.0.0.0 nexthop-group two 1000000", isjson=False)
- test_func = partial(topotest.router_json_cmp, r1, "show ip route summary json", expected_installed)
- _, result = topotest.run_and_expect(test_func, None, count=40, wait=5)
output = r1.vtysh_cmd("sharp data route", isjson=False)
- logger.info("1 million routes X 2 ecmp installed")
+ logger.info("1 million routes X {} ecmp installed".format(s['ecmp']))
logger.info(output)
r1.vtysh_cmd("sharp remove route 1.0.0.0 1000000", isjson=False)
test_func = partial(topotest.router_json_cmp, r1, "show ip route summary json", expected_removed)
- _, result = topotest.run_and_expect(test_func, None, count=40, wait=5)
- output = r1.vtysh_cmd("sharp data route", isjson=False)
- logger.info("1 million routes x 2 ecmp removed")
- logger.info(output)
+ success, result = topotest.run_and_expect(test_func, None, count, wait)
+ assert success, "Route scale test remove failed:\n{}".format(result)
- r1.vtysh_cmd("sharp install route 1.0.0.0 nexthop-group four 1000000", isjson=False)
- test_func = partial(topotest.router_json_cmp, r1, "show ip route summary json", expected_installed)
- _, result = topotest.run_and_expect(test_func, None, count=40, wait=5)
output = r1.vtysh_cmd("sharp data route", isjson=False)
- logger.info("1 million routes X 4 ecmp installed")
- logger.info(output)
- r1.vtysh_cmd("sharp remove route 1.0.0.0 1000000", isjson=False)
- test_func = partial(topotest.router_json_cmp, r1, "show ip route summary json", expected_removed)
- _, result = topotest.run_and_expect(test_func, None, count=40, wait=5)
- output = r1.vtysh_cmd("sharp data route", isjson=False)
- logger.info("1 million routes x 4 ecmp removed")
+ logger.info("1 million routes x {} ecmp removed".format(
+ s['ecmp']))
logger.info(output)
- r1.vtysh_cmd("sharp install route 1.0.0.0 nexthop-group eight 1000000", isjson=False)
- test_func = partial(topotest.router_json_cmp, r1, "show ip route summary json", expected_installed)
- _, result = topotest.run_and_expect(test_func, None, count=40, wait=5)
- output = r1.vtysh_cmd("sharp data route", isjson=False)
- logger.info("1 million routes X 8 ecmp installed")
- logger.info(output)
- r1.vtysh_cmd("sharp remove route 1.0.0.0 1000000", isjson=False)
- test_func = partial(topotest.router_json_cmp, r1, "show ip route summary json", expected_removed)
- _, result = topotest.run_and_expect(test_func, None, count=40, wait=5)
- output = r1.vtysh_cmd("sharp data route", isjson=False)
- logger.info("1 million routes x 8 ecmp removed")
- logger.info(output)
- r1.vtysh_cmd("sharp install route 1.0.0.0 nexthop-group sixteen 1000000", isjson=False)
- test_func = partial(topotest.router_json_cmp, r1, "show ip route summary json", expected_installed)
- _, result = topotest.run_and_expect(test_func, None, count=40, wait=5)
- output = r1.vtysh_cmd("sharp data route", isjson=False)
- logger.info("1 million routes X 16 ecmp installed")
- logger.info(output)
- r1.vtysh_cmd("sharp remove route 1.0.0.0 1000000", isjson=False)
- test_func = partial(topotest.router_json_cmp, r1, "show ip route summary json", expected_removed)
- _, result = topotest.run_and_expect(test_func, None, count=40, wait=5)
- output = r1.vtysh_cmd("sharp data route", isjson=False)
- logger.info("1 million routes x 16 ecmp removed")
- logger.info(output)
+def test_route_install():
+ "Test route install for a variety of ecmp"
- r1.vtysh_cmd("sharp install route 1.0.0.0 nexthop-group thirtytwo 1000000", isjson=False)
- test_func = partial(topotest.router_json_cmp, r1, "show ip route summary json", expected_installed)
- _, result = topotest.run_and_expect(test_func, None, count=40, wait=5)
- output = r1.vtysh_cmd("sharp data route", isjson=False)
- logger.info("1 million routes X 32 ecmp installed")
- logger.info(output)
- r1.vtysh_cmd("sharp remove route 1.0.0.0 1000000", isjson=False)
- test_func = partial(topotest.router_json_cmp, r1, "show ip route summary json", expected_removed)
- _, result = topotest.run_and_expect(test_func, None, count=40, wait=5)
- output = r1.vtysh_cmd("sharp data route", isjson=False)
- logger.info("1 million routes x 32 ecmp removed")
- logger.info(output)
+ 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"]
+
+ installed_file = "{}/r1/installed.routes.json".format(CWD)
+ expected_installed = json.loads(open(installed_file).read())
+
+ removed_file = "{}/r1/no.routes.json".format(CWD)
+ expected_removed = json.loads(open(removed_file).read())
+
+ # dict keys of params: ecmp number, corresponding nhg name, timeout,
+ # number of times to wait
+ scale_keys = ['ecmp', 'nhg', 'wait', 'count', 'expect_in', 'expect_rem']
+
+ # Table of defaults, used for timeout values and 'expected' objects
+ scale_defaults = dict(zip(scale_keys, [None, None, 7, 30,
+ expected_installed,
+ expected_removed]))
+
+ # List of params for each step in the test; note extra time given
+ # for the highest ecmp steps. Executing 'show' at scale can be costly
+ # so we widen the interval there too.
+ scale_steps = [
+ [1, 'one'], [2, 'two'], [4, 'four'],
+ [8, 'eight'], [16, 'sixteen', 10, 40], [32, 'thirtytwo', 10, 40]
+ ]
+
+ # Build up a list of dicts with params for each step of the test;
+ # use defaults where the step doesn't supply a value
+ scale_setups = []
+ for s in scale_steps:
+ d = dict(zip(scale_keys, s))
+ for k in scale_keys:
+ if k not in d:
+ d[k] = scale_defaults[k]
+
+ scale_setups.append(d)
+
+ # Avoid top ecmp case for runs with < 4G memory
+ p = os.popen('free')
+ l = p.readlines()[1].split()
+ mem = int(l[1])
+ if mem < 4000000:
+ logger.info('Limited memory available: {}, skipping x32 testcase'.format(mem))
+ scale_setups = scale_setups[0:-1]
+
+ # Run each step using the dicts we've built
+ for s in scale_setups:
+ run_one_setup(r1, s)
+
+# Mem leak testcase
+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:]
diff --git a/tools/cocci.h b/tools/cocci.h
index 8ca42b349f..7d6bb4cd7f 100644
--- a/tools/cocci.h
+++ b/tools/cocci.h
@@ -7,6 +7,18 @@
#define DEFUN_HIDDEN(funcname, cmdname, str, help) \
static int funcname(const struct cmd_element *self, struct vty *vty, \
int argc, struct cmd_token *argv[])
+#define DEFUN_NOSH(funcname, cmdname, str, help) \
+ static int funcname(const struct cmd_element *self, struct vty *vty, \
+ int argc, struct cmd_token *argv[])
+#define DEFPY(funcname, cmdname, str, help) \
+ static int funcname(const struct cmd_element *self, struct vty *vty, \
+ int argc, struct cmd_token *argv[])
+#define DEFPY_HIDDEN(funcname, cmdname, str, help) \
+ static int funcname(const struct cmd_element *self, struct vty *vty, \
+ int argc, struct cmd_token *argv[])
+#define DEFPY_NOSH(funcname, cmdname, str, help) \
+ static int funcname(const struct cmd_element *self, struct vty *vty, \
+ int argc, struct cmd_token *argv[])
#define ENABLE_BGP_VNC 1
#define ALL_LIST_ELEMENTS_RO(list, node, data) \
@@ -85,3 +97,28 @@
for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
#define FOREACH_SAFI(safi) for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
+
+#define frr_with_privs(p) \
+ for (int x = 1; x; x--)
+#define frr_with_mutex(m) \
+ for (int x = 1; x; x--)
+
+#define ALL_LSDB_TYPED_ADVRTR(lsdb, type, adv_router, lsa) \
+ const struct route_node *iterend = \
+ ospf6_lsdb_head(lsdb, 2, type, adv_router, &lsa); \
+ lsa; \
+ lsa = ospf6_lsdb_next(iterend, lsa)
+
+#define ALL_LSDB_TYPED(lsdb, type, lsa) \
+ const struct route_node *iterend = \
+ ospf6_lsdb_head(lsdb, 1, type, 0, &lsa); \
+ lsa; \
+ lsa = ospf6_lsdb_next(iterend, lsa)
+
+#define ALL_LSDB(lsdb, lsa) \
+ const struct route_node *iterend = \
+ ospf6_lsdb_head(lsdb, 0, 0, 0, &lsa); \
+ lsa; \
+ lsa = ospf6_lsdb_next(iterend, lsa)
+
+#define QOBJ_FIELDS struct qobj_node qobj_node;
diff --git a/tools/etc/frr/daemons b/tools/etc/frr/daemons
index 8bec3c5bb6..0221b0c19e 100644
--- a/tools/etc/frr/daemons
+++ b/tools/etc/frr/daemons
@@ -72,6 +72,11 @@ vrrpd_options=" -A 127.0.0.1"
# The list of daemons to watch is automatically generated by the init script.
#watchfrr_options=""
+# To make watchfrr create/join the specified netns, use the following option:
+#watchfrr_options="--netns"
+# This only has an effect in /etc/frr/<somename>/daemons, and you need to
+# start FRR with "/usr/lib/frr/frrinit.sh start <somename>".
+
# for debugging purposes, you can specify a "wrap" command to start instead
# of starting the daemon directly, e.g. to use valgrind on ospfd:
# ospfd_wrap="/usr/bin/valgrind"
diff --git a/tools/frr-reload.py b/tools/frr-reload.py
index 9e86cf2156..05410e3c25 100755
--- a/tools/frr-reload.py
+++ b/tools/frr-reload.py
@@ -63,14 +63,17 @@ class VtyshException(Exception):
pass
class Vtysh(object):
- def __init__(self, bindir=None, confdir=None, sockdir=None):
+ def __init__(self, bindir=None, confdir=None, sockdir=None, pathspace=None):
self.bindir = bindir
self.confdir = confdir
+ self.pathspace = pathspace
self.common_args = [os.path.join(bindir or '', 'vtysh')]
if confdir:
self.common_args.extend(['--config_dir', confdir])
if sockdir:
self.common_args.extend(['--vty_socket', sockdir])
+ if pathspace:
+ self.common_args.extend(['-N', pathspace])
def _call(self, args, stdin=None, stdout=None, stderr=None):
kwargs = {}
@@ -729,6 +732,36 @@ def line_exist(lines, target_ctx_keys, target_line, exact_match=True):
return 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 is not "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 ignore_delete_re_add_lines(lines_to_add, lines_to_del):
@@ -1156,6 +1189,7 @@ def compare_context_objects(newconf, running):
for line in newconf_ctx.lines:
lines_to_add.append((newconf_ctx_keys, line))
+ (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)
(lines_to_add, lines_to_del) = ignore_unconfigurable_lines(lines_to_add, lines_to_del)
@@ -1171,6 +1205,7 @@ if __name__ == '__main__':
group.add_argument('--test', action='store_true', help='Show the deltas', default=False)
parser.add_argument('--debug', action='store_true', help='Enable debugs', default=False)
parser.add_argument('--stdout', action='store_true', help='Log to STDOUT', default=False)
+ parser.add_argument('--pathspace', '-N', metavar='NAME', help='Reload specified path/namespace', default=None)
parser.add_argument('filename', help='Location of new frr config file')
parser.add_argument('--overwrite', action='store_true', help='Overwrite frr.conf with running config output', default=False)
parser.add_argument('--bindir', help='path to the vtysh executable', default='/usr/bin')
@@ -1246,10 +1281,13 @@ if __name__ == '__main__':
log.error(msg)
sys.exit(1)
- vtysh = Vtysh(args.bindir, args.confdir, args.vty_socket)
+ vtysh = Vtysh(args.bindir, args.confdir, args.vty_socket, args.pathspace)
# Verify that 'service integrated-vtysh-config' is configured
- vtysh_filename = args.confdir + '/vtysh.conf'
+ if args.pathspace:
+ vtysh_filename = args.confdir + '/' + args.pathspace + '/vtysh.conf'
+ else:
+ vtysh_filename = args.confdir + '/vtysh.conf'
service_integrated_vtysh_config = True
if os.path.isfile(vtysh_filename):
diff --git a/tools/frr.in b/tools/frr.in
index 40862aa4c9..b860797d5b 100755
--- a/tools/frr.in
+++ b/tools/frr.in
@@ -77,7 +77,7 @@ vtysh_b ()
{
# Rember, that all variables have been incremented by 1 in convert_daemon_prios()
if [ "$vtysh_enable" = 2 -a -f $C_PATH/frr.conf ]; then
- $VTYSH -b -n
+ $VTYSH -b
fi
}
diff --git a/tools/frr@.service b/tools/frr@.service
new file mode 100644
index 0000000000..0fa41c74a3
--- /dev/null
+++ b/tools/frr@.service
@@ -0,0 +1,25 @@
+[Unit]
+Description=FRRouting
+Documentation=https://frrouting.readthedocs.io/en/latest/setup.html
+Wants=network.target
+After=network-pre.target systemd-sysctl.service
+Before=network.target
+OnFailure=heartbeat-failed@%n.service
+
+[Service]
+Nice=-5
+Type=forking
+NotifyAccess=all
+StartLimitInterval=3m
+StartLimitBurst=3
+TimeoutSec=2m
+WatchdogSec=60s
+RestartSec=5
+Restart=on-abnormal
+LimitNOFILE=1024
+ExecStart=/usr/lib/frr/frrinit.sh start %I
+ExecStop=/usr/lib/frr/frrinit.sh stop %I
+ExecReload=/usr/lib/frr/frrinit.sh reload %I
+
+[Install]
+WantedBy=multi-user.target
diff --git a/tools/frrcommon.sh.in b/tools/frrcommon.sh.in
index 2955f74ce3..9a144b2b06 100644
--- a/tools/frrcommon.sh.in
+++ b/tools/frrcommon.sh.in
@@ -16,10 +16,14 @@
#
# This script should be installed in @CFG_SBIN@/frrcommon.sh
+# FRR_PATHSPACE is passed in from watchfrr
+suffix="${FRR_PATHSPACE:+/${FRR_PATHSPACE}}"
+nsopt="${FRR_PATHSPACE:+-N ${FRR_PATHSPACE}}"
+
PATH=/bin:/usr/bin:/sbin:/usr/sbin
D_PATH="@CFG_SBIN@" # /usr/lib/frr
-C_PATH="@CFG_SYSCONF@" # /etc/frr
-V_PATH="@CFG_STATE@" # /var/run/frr
+C_PATH="@CFG_SYSCONF@${suffix}" # /etc/frr
+V_PATH="@CFG_STATE@${suffix}" # /var/run/frr
VTYSH="@vtysh_bin@" # /usr/bin/vtysh
FRR_USER="@enable_user@" # frr
FRR_GROUP="@enable_group@" # frr
@@ -61,9 +65,9 @@ vtysh_b () {
[ "$1" = "watchfrr" ] && return 0
[ -r "$C_PATH/frr.conf" ] || return 0
if [ -n "$1" ]; then
- "$VTYSH" -b -n -d "$1"
+ "$VTYSH" `echo $nsopt` -b -d "$1"
else
- "$VTYSH" -b -n
+ "$VTYSH" `echo $nsopt` -b
fi
}
@@ -156,7 +160,7 @@ daemon_start() {
instopt="${inst:+-n $inst}"
eval args="\$${daemon}_options"
- if eval "$all_wrap $wrap $bin -d $frr_global_options $instopt $args"; then
+ if eval "$all_wrap $wrap $bin $nsopt -d $frr_global_options $instopt $args"; then
log_success_msg "Started $dmninst"
vtysh_b "$daemon"
else
@@ -292,9 +296,11 @@ load_old_config() {
}
. "$C_PATH/daemons"
-load_old_config "$C_PATH/daemons.conf"
-load_old_config "/etc/default/frr"
-load_old_config "/etc/sysconfig/frr"
+if [ -z "$FRR_PATHSPACE" ]; then
+ load_old_config "$C_PATH/daemons.conf"
+ load_old_config "/etc/default/frr"
+ load_old_config "/etc/sysconfig/frr"
+fi
if { declare -p watchfrr_options 2>/dev/null || true; } | grep -q '^declare \-a'; then
log_warning_msg "watchfrr_options contains a bash array value." \
diff --git a/tools/frrinit.sh.in b/tools/frrinit.sh.in
index 423d6b9b1d..539ab7d816 100644
--- a/tools/frrinit.sh.in
+++ b/tools/frrinit.sh.in
@@ -30,6 +30,9 @@ else
}
fi
+# "/usr/lib/frr/frrinit.sh start somenamespace"
+FRR_PATHSPACE="$2"
+
self="`dirname $0`"
if [ -r "$self/frrcommon.sh" ]; then
. "$self/frrcommon.sh"
@@ -105,7 +108,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 "$NEW_CONFIG_FILE"
+ "$RELOAD_SCRIPT" --reload "$NEW_CONFIG_FILE" `echo $nsopt`
exit $?
;;
diff --git a/tools/gcc-plugins/README.md b/tools/gcc-plugins/README.md
index 94a9635e76..ab31d0e636 100644
--- a/tools/gcc-plugins/README.md
+++ b/tools/gcc-plugins/README.md
@@ -20,11 +20,14 @@ Can be found at [https://deb.nox.tf/devel/].
GCC requirements
----------------
-To use this plugin, you need a **patched 9.3.0** version of GCC using the
-[gcc-retain-typeinfo.patch] provided in this repo. Without this patch, GCC
-strips type information too early during compilation, leaving to the plugin
-being unable to perform more meaningful type checks. (Specifically, all
-`typedef` types will be "cooked down" to their final type.)
+To use this plugin, you need a **patched 9.3.0** or a **patched 10.1.0**
+version of GCC using the [gcc-retain-typeinfo.patch] provided in this repo.
+
+Without this patch, GCC strips type information too early during compilation,
+leaving to the plugin being unable to perform more meaningful type checks.
+(Specifically, all `typedef` casts will be "cooked down" to their final type.)
+If the patch is missing, `format-test.c` will show 4 false negative/positive
+warnings marked with `(need retain-typeinfo patch)`.
(@eqvinox has discussed this one-line diff with some GCC people on their
IRC channel around mid 2019, the consensus was that the line is an "early
@@ -32,7 +35,7 @@ optimization" and removing it should not be harmful. However, doing so is
likely to break GCC's unit tests since warnings would print different types.)
Other versions of gcc are not supported. gcc 8 previously did work but isn't
-actively tested/maintained. gcc 10 is not supported yet but may work.
+actively tested/maintained.
Usage
diff --git a/tools/gcc-plugins/debian/changelog b/tools/gcc-plugins/debian/changelog
index 62bbbcd46f..a772803b1c 100644
--- a/tools/gcc-plugins/debian/changelog
+++ b/tools/gcc-plugins/debian/changelog
@@ -1,3 +1,9 @@
+gcc-frr-plugin (9.3.0d15+equi1) unstable; urgency=medium
+
+ * update & rebuild for gcc 9.3.0-15+equi1
+
+ -- David Lamparter <equinox-debian@diac24.net> Tue, 14 Jul 2020 19:49:24 +0200
+
gcc-frr-plugin (9.3.0d8+equi2) unstable; urgency=medium
* package created (+equi1 used during development, never released.)
diff --git a/tools/gcc-plugins/debian/control b/tools/gcc-plugins/debian/control
index 6a9b886bef..b9b5134b46 100644
--- a/tools/gcc-plugins/debian/control
+++ b/tools/gcc-plugins/debian/control
@@ -3,7 +3,7 @@ Section: devel
Priority: optional
Maintainer: David Lamparter <equinox-debian@diac24.net>
Build-Depends:
- gcc-9-plugin-dev (=9.3.0-8+equi1),
+ gcc-9-plugin-dev (=9.3.0-15+equi1),
debhelper (>= 12)
Standards-Version: 4.4.1
Homepage: https://www.frrouting.org/
@@ -13,7 +13,7 @@ Vcs-Git: https://github.com/FRRouting/frr.git
Package: gcc-9-frr-plugin
Architecture: linux-any
Depends:
- gcc-9 (=9.3.0-8+equi1),
+ gcc-9 (=9.3.0-15+equi1),
${misc:Depends},
${shlibs:Depends}
Description: GCC plugin for FRRouting
diff --git a/tools/gcc-plugins/debian/source/format b/tools/gcc-plugins/debian/source/format
index af745b310b..89ae9db8f8 100644
--- a/tools/gcc-plugins/debian/source/format
+++ b/tools/gcc-plugins/debian/source/format
@@ -1 +1 @@
-3.0 (git)
+3.0 (native)
diff --git a/tools/gcc-plugins/format-test.c b/tools/gcc-plugins/format-test.c
index b031ca5ece..fb7e41c7be 100644
--- a/tools/gcc-plugins/format-test.c
+++ b/tools/gcc-plugins/format-test.c
@@ -82,6 +82,12 @@ int test(unsigned long long ay)
testfn("%Ld", v_pid_t); // WARN
testfn("%Ld", v_uint64_t); // NOWARN
+ /* retain-typeinfo patch */
+ testfn("%zu", (size_t)v_pid_t); // NOWARN (need retain-typeinfo patch)
+ testfn("%lu", (size_t)v_pid_t); // WARN (need retain-typeinfo patch)
+ testfn("%Lu", (uint64_t)v_pid_t); // NOWARN (need retain-typeinfo patch)
+ testfn("%lu", (uint64_t)v_pid_t); // WARN (need retain-typeinfo patch)
+
testfn("%pI4", &v_long); // WARN
in_addr_t v_in_addr_t;
diff --git a/tools/gcc-plugins/format-test.py b/tools/gcc-plugins/format-test.py
index cc6ca6100e..df2437d5bc 100644
--- a/tools/gcc-plugins/format-test.py
+++ b/tools/gcc-plugins/format-test.py
@@ -10,6 +10,10 @@ for k in list(os.environ.keys()):
if k.startswith('LC_'):
os.environ.pop(k)
+if len(sys.argv) < 2:
+ sys.stderr.write('start as format-test.py gcc-123.45 [-options ...]\n')
+ sys.exit(1)
+
c_re = re.compile(r'//\s+(NO)?WARN')
expect = {}
lines = {}
@@ -25,9 +29,9 @@ with open('format-test.c', 'r') as fd:
else:
expect[lno] = 'nowarn'
-cmd = shlex.split('gcc -Wall -Wextra -Wno-unused -fplugin=./frr-format.so -fno-diagnostics-show-caret -c -o format-test.o format-test.c')
+cmd = shlex.split('-Wall -Wextra -Wno-unused -fplugin=./frr-format.so -fno-diagnostics-show-caret -c -o format-test.o format-test.c')
-gcc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+gcc = subprocess.Popen(sys.argv[1:] + cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
sout, serr = gcc.communicate()
gcc.wait()
diff --git a/tools/gcc-plugins/frr-format.c b/tools/gcc-plugins/frr-format.c
index be28bfd818..be56517171 100644
--- a/tools/gcc-plugins/frr-format.c
+++ b/tools/gcc-plugins/frr-format.c
@@ -359,7 +359,7 @@ decode_format_attr (tree args, function_format_info *info, int validated_p)
if (info->first_arg_num != 0 && info->first_arg_num <= info->format_num)
{
gcc_assert (!validated_p);
- error ("format string argument follows the args to be formatted");
+ error ("format string argument follows the arguments to be formatted");
return false;
}
@@ -489,10 +489,10 @@ static const format_flag_pair printf_flag_pairs[] =
#define ETAB_SZ 128
static kernel_ext_fmt ext_p[ETAB_SZ] = {
- { NULL }
+ { }
};
static kernel_ext_fmt ext_d[ETAB_SZ] = {
- { NULL }
+ { }
};
static const format_char_info print_char_table[] =
@@ -740,7 +740,8 @@ check_function_format (tree attrs, int nargs, tree *argarray,
break;
}
if (args != 0)
- warning (OPT_Wsuggest_attribute_format, "function %qD might be a candidate for %qs frr_format attribute",
+ warning (OPT_Wsuggest_attribute_format,
+ "function %qD might be a candidate for %qs %<frr_format%> attribute",
current_function_decl,
format_types[info.format_type].name);
}
@@ -922,7 +923,7 @@ avoid_dollar_number (const char *format)
format++;
if (*format == '$')
{
- warning (OPT_Wformat_, "$ operand number used after format without operand number");
+ warning (OPT_Wformat_, "%<$%> operand number used after format without operand number");
return true;
}
return false;
@@ -953,7 +954,7 @@ finish_dollar_format_checking (format_check_results *res, int pointer_gap_ok)
found_pointer_gap = true;
else
warning_at (res->format_string_loc, OPT_Wformat_,
- "format argument %d unused before used argument %d in $-style format",
+ "format argument %d unused before used argument %d in %<$%>-style format",
i + 1, dollar_max_arg_used);
}
}
@@ -1097,7 +1098,7 @@ check_format_info (function_format_info *info, tree params,
}
if (res.number_dollar_extra_args > 0 && res.number_non_literal == 0
&& res.number_other == 0)
- warning_at (loc, OPT_Wformat_extra_args, "unused arguments in $-style format");
+ warning_at (loc, OPT_Wformat_extra_args, "unused arguments in %<$%>-style format");
if (res.number_empty > 0 && res.number_non_literal == 0
&& res.number_other == 0)
warning_at (loc, OPT_Wformat_zero_length, "zero-length %s format string",
@@ -3525,17 +3526,24 @@ print_type (c_pretty_printer *cpp, tree t, bool *quoted)
/* C-specific implementation of range_label::get_text () vfunc for
range_label_for_type_mismatch. */
+#if BUILDING_GCC_VERSION >= 10000
+#define label_borrow(text) label_text::borrow(text)
+#define label_take(text) label_text::take(text)
+#else
+#define label_borrow(text) label_text((char *)text, false)
+#define label_take(text) label_text(text, true)
+#endif
label_text
frr_range_label_for_type_mismatch::get_text (unsigned /*range_idx*/) const
{
if (m_labelled_type == NULL_TREE)
- return label_text (NULL, false);
+ return label_borrow("(null tree)");
c_pretty_printer cpp;
bool quoted = false;
print_type (&cpp, m_labelled_type, &quoted);
- return label_text (xstrdup (pp_formatted_text (&cpp)), true);
+ return label_take(xstrdup (pp_formatted_text (&cpp)));
}
#define range_label_for_type_mismatch frr_range_label_for_type_mismatch
@@ -3567,7 +3575,7 @@ class range_label_for_format_type_mismatch
char *result = concat (text.m_buffer, p, NULL);
text.maybe_free ();
- return label_text (result, true);
+ return label_take(result);
}
private:
@@ -3857,7 +3865,7 @@ handle_frr_format_attribute (tree *node, tree ARG_UNUSED (name), tree args,
if (arg_num != info.first_arg_num)
{
if (!(flags & (int) ATTR_FLAG_BUILT_IN))
- error ("args to be formatted is not %<...%>");
+ error ("arguments to be formatted is not %<...%>");
*no_add_attrs = true;
return NULL_TREE;
}
@@ -4131,7 +4139,7 @@ setup_type (const char *name, tree *dst)
tmp = identifier_global_value (*dst);
if (tmp && TREE_CODE (tmp) != TYPE_DECL)
{
- warning (0, "%<%s%> is not defined as a type", name);
+ warning (0, "%qs is not defined as a type", name);
*dst = NULL;
return;
}
@@ -4298,7 +4306,7 @@ handle_pragma_printfrr_ext (cpp_reader *dummy)
if (0)
{
warning_at (loc, OPT_Wformat_,
- "%<#pragma FRR printfrr_ext%>: duplicate printf format suffix \"%s\"", s);
+ "%<#pragma FRR printfrr_ext%>: duplicate printf format suffix %qs", s);
warning_at (etab->origin_loc, OPT_Wformat_,
"%<#pragma FRR printfrr_ext%>: previous definition was here");
return;
@@ -4310,9 +4318,9 @@ handle_pragma_printfrr_ext (cpp_reader *dummy)
if (!strncmp(s + 2, etab->suffix, MIN(strlen(s + 2), strlen(etab->suffix))))
{
warning_at (loc, OPT_Wformat_,
- "%<#pragma FRR printfrr_ext%>: overlapping printf format suffix \"%s\"", s);
+ "%<#pragma FRR printfrr_ext%>: overlapping printf format suffix %qs", s);
warning_at (etab->origin_loc, OPT_Wformat_,
- "%<#pragma FRR printfrr_ext%>: previous definition for \"%%%c%s\" was here", s[1], etab->suffix);
+ "%<#pragma FRR printfrr_ext%>: previous definition for %<%%%c%s%> was here", s[1], etab->suffix);
return;
}
}
@@ -4370,7 +4378,7 @@ handle_pragma_printfrr_ext (cpp_reader *dummy)
{
switch (ttype) {
case CPP_NAME:
- error_at (loc, "%<#pragma FRR printfrr_ext%>: unexpected identifier. Note the only supported qualifier is \"const\".");
+ error_at (loc, "%<#pragma FRR printfrr_ext%>: unexpected identifier. Note the only supported qualifier is %<const%>");
goto out_drop;
case CPP_MULT:
diff --git a/tools/gcc-plugins/gcc-common.h b/tools/gcc-plugins/gcc-common.h
index 6b6c17231a..ec45de1a53 100644
--- a/tools/gcc-plugins/gcc-common.h
+++ b/tools/gcc-plugins/gcc-common.h
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0 */
-/* FRR: imported from Linux kernel on 2019-07-29 */
+/* FRR: imported from Linux kernel on 2020-07-14 */
#ifndef GCC_COMMON_H_INCLUDED
#define GCC_COMMON_H_INCLUDED
@@ -38,7 +38,9 @@
#include "ggc.h"
#include "timevar.h"
+#if BUILDING_GCC_VERSION < 10000
#include "params.h"
+#endif
#if BUILDING_GCC_VERSION <= 4009
#include "pointer-set.h"
@@ -852,6 +854,7 @@ static inline gimple gimple_build_assign_with_ops(enum tree_code subcode, tree l
return gimple_build_assign(lhs, subcode, op1, op2 PASS_MEM_STAT);
}
+#if BUILDING_GCC_VERSION < 10000
template <>
template <>
inline bool is_a_helper<const ggoto *>::test(const_gimple gs)
@@ -865,6 +868,7 @@ inline bool is_a_helper<const greturn *>::test(const_gimple gs)
{
return gs->code == GIMPLE_RETURN;
}
+#endif
static inline gasm *as_a_gasm(gimple stmt)
{
diff --git a/tools/subdir.am b/tools/subdir.am
index 723a87d100..e159d82d4c 100644
--- a/tools/subdir.am
+++ b/tools/subdir.am
@@ -48,6 +48,7 @@ EXTRA_DIST += \
tools/frr-reload \
tools/frr-reload.py \
tools/frr.service \
+ tools/frr@.service \
tools/generate_support_bundle.py \
tools/multiple-bgpd.sh \
tools/rrcheck.pl \
diff --git a/vrrpd/vrrp.c b/vrrpd/vrrp.c
index 3e79cff391..d3f9b0c730 100644
--- a/vrrpd/vrrp.c
+++ b/vrrpd/vrrp.c
@@ -2351,7 +2351,7 @@ int vrrp_config_write_global(struct vty *vty)
if (vd.advertisement_interval != VRRP_DEFAULT_ADVINT && ++writes)
vty_out(vty,
- "vrrp default advertisement-interval %hu\n",
+ "vrrp default advertisement-interval %u\n",
vd.advertisement_interval * CS2MS);
if (vd.preempt_mode != VRRP_DEFAULT_PREEMPT && ++writes)
@@ -2374,7 +2374,7 @@ static unsigned int vrrp_hash_key(const void *arg)
const struct vrrp_vrouter *vr = arg;
char key[IFNAMSIZ + 64];
- snprintf(key, sizeof(key), "%s@%hhu", vr->ifp->name, vr->vrid);
+ snprintf(key, sizeof(key), "%s@%u", vr->ifp->name, vr->vrid);
return string_hash_make(key);
}
diff --git a/vrrpd/vrrp_packet.c b/vrrpd/vrrp_packet.c
index 61fcc4e85d..3cb13bd71b 100644
--- a/vrrpd/vrrp_packet.c
+++ b/vrrpd/vrrp_packet.c
@@ -296,7 +296,7 @@ ssize_t vrrp_pkt_parse_datagram(int family, int version, struct msghdr *m,
(*pkt)->hdr.chksum, chksum);
/* Type check */
- VRRP_PKT_VCHECK(((*pkt)->hdr.vertype & 0x0F) == 1, "Bad type %hhu",
+ VRRP_PKT_VCHECK(((*pkt)->hdr.vertype & 0x0F) == 1, "Bad type %u",
(*pkt)->hdr.vertype & 0x0f);
/* Exact size check */
diff --git a/vrrpd/vrrp_vty.c b/vrrpd/vrrp_vty.c
index 1a12337086..3165ea119a 100644
--- a/vrrpd/vrrp_vty.c
+++ b/vrrpd/vrrp_vty.c
@@ -52,7 +52,7 @@
/*
* XPath: /frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group
*/
-DEFPY(vrrp_vrid,
+DEFPY_YANG(vrrp_vrid,
vrrp_vrid_cmd,
"[no] vrrp (1-255)$vrid [version (2-3)]",
NO_STR
@@ -89,7 +89,7 @@ void cli_show_vrrp(struct vty *vty, struct lyd_node *dnode, bool show_defaults)
/*
* XPath: /frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/shutdown
*/
-DEFPY(vrrp_shutdown,
+DEFPY_YANG(vrrp_shutdown,
vrrp_shutdown_cmd,
"[no] vrrp (1-255)$vrid shutdown",
NO_STR
@@ -115,7 +115,7 @@ void cli_show_shutdown(struct vty *vty, struct lyd_node *dnode,
/*
* XPath: /frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/priority
*/
-DEFPY(vrrp_priority,
+DEFPY_YANG(vrrp_priority,
vrrp_priority_cmd,
"vrrp (1-255)$vrid priority (1-254)",
VRRP_STR
@@ -131,7 +131,7 @@ DEFPY(vrrp_priority,
/*
* XPath: /frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/priority
*/
-DEFPY(no_vrrp_priority,
+DEFPY_YANG(no_vrrp_priority,
no_vrrp_priority_cmd,
"no vrrp (1-255)$vrid priority [(1-254)]",
NO_STR
@@ -158,7 +158,7 @@ void cli_show_priority(struct vty *vty, struct lyd_node *dnode,
* XPath:
* /frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/advertisement-interval
*/
-DEFPY(vrrp_advertisement_interval,
+DEFPY_YANG(vrrp_advertisement_interval,
vrrp_advertisement_interval_cmd,
"vrrp (1-255)$vrid advertisement-interval (10-40950)",
VRRP_STR VRRP_VRID_STR VRRP_ADVINT_STR
@@ -179,7 +179,7 @@ DEFPY(vrrp_advertisement_interval,
* XPath:
* /frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/advertisement-interval
*/
-DEFPY(no_vrrp_advertisement_interval,
+DEFPY_YANG(no_vrrp_advertisement_interval,
no_vrrp_advertisement_interval_cmd,
"no vrrp (1-255)$vrid advertisement-interval [(10-40950)]",
NO_STR VRRP_STR VRRP_VRID_STR VRRP_ADVINT_STR
@@ -205,7 +205,7 @@ void cli_show_advertisement_interval(struct vty *vty, struct lyd_node *dnode,
* XPath:
* /frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/v4/virtual-address
*/
-DEFPY(vrrp_ip,
+DEFPY_YANG(vrrp_ip,
vrrp_ip_cmd,
"[no] vrrp (1-255)$vrid ip A.B.C.D",
NO_STR
@@ -233,7 +233,7 @@ void cli_show_ip(struct vty *vty, struct lyd_node *dnode, bool show_defaults)
* XPath:
* /frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/v6/virtual-address
*/
-DEFPY(vrrp_ip6,
+DEFPY_YANG(vrrp_ip6,
vrrp_ip6_cmd,
"[no] vrrp (1-255)$vrid ipv6 X:X::X:X",
NO_STR
@@ -260,7 +260,7 @@ void cli_show_ipv6(struct vty *vty, struct lyd_node *dnode, bool show_defaults)
/*
* XPath: /frr-interface:lib/interface/frr-vrrpd:vrrp/vrrp-group/preempt
*/
-DEFPY(vrrp_preempt,
+DEFPY_YANG(vrrp_preempt,
vrrp_preempt_cmd,
"[no] vrrp (1-255)$vrid preempt",
NO_STR
@@ -284,7 +284,7 @@ void cli_show_preempt(struct vty *vty, struct lyd_node *dnode,
}
/* XXX: yang conversion */
-DEFPY(vrrp_autoconfigure,
+DEFPY_YANG(vrrp_autoconfigure,
vrrp_autoconfigure_cmd,
"[no] vrrp autoconfigure [version (2-3)]",
NO_STR
@@ -304,7 +304,7 @@ DEFPY(vrrp_autoconfigure,
}
/* XXX: yang conversion */
-DEFPY(vrrp_default,
+DEFPY_YANG(vrrp_default,
vrrp_default_cmd,
"[no] vrrp default <advertisement-interval$adv (10-40950)$advint|preempt$p|priority$prio (1-254)$prioval|shutdown$s>",
NO_STR
@@ -583,7 +583,7 @@ static int vrrp_instance_display_sort_cmp(const void **d1, const void **d2)
/* clang-format off */
-DEFPY(vrrp_vrid_show,
+DEFPY_YANG(vrrp_vrid_show,
vrrp_vrid_show_cmd,
"show vrrp [interface INTERFACE$ifn] [(1-255)$vrid] [json$json]",
SHOW_STR
@@ -624,7 +624,7 @@ DEFPY(vrrp_vrid_show,
return CMD_SUCCESS;
}
-DEFPY(vrrp_vrid_show_summary,
+DEFPY_YANG(vrrp_vrid_show_summary,
vrrp_vrid_show_summary_cmd,
"show vrrp [interface INTERFACE$ifn] [(1-255)$vrid] summary",
SHOW_STR
@@ -653,7 +653,7 @@ DEFPY(vrrp_vrid_show_summary,
continue;
ttable_add_row(
- tt, "%s|%hhu|%hhu|%d|%d|%s|%s",
+ tt, "%s|%u|%hhu|%d|%d|%s|%s",
vr->ifp->name, vr->vrid, vr->priority,
vr->v4->addrs->count, vr->v6->addrs->count,
vr->v4->fsm.state == VRRP_STATE_MASTER ? "Master"
@@ -674,7 +674,7 @@ DEFPY(vrrp_vrid_show_summary,
}
-DEFPY(debug_vrrp,
+DEFPY_YANG(debug_vrrp,
debug_vrrp_cmd,
"[no] debug vrrp [{protocol$proto|autoconfigure$ac|packets$pkt|sockets$sock|ndisc$ndisc|arp$arp|zebra$zebra}]",
NO_STR
diff --git a/vtysh/extract.pl.in b/vtysh/extract.pl.in
index 794e1f4c73..60c31bd847 100755
--- a/vtysh/extract.pl.in
+++ b/vtysh/extract.pl.in
@@ -40,7 +40,7 @@ sub scan_file {
$cppadd = $fabricd ? "-DFABRICD=1" : "";
- open (FH, "@CPP@ -DHAVE_CONFIG_H -DVTYSH_EXTRACT_PL -Ivtysh/@top_builddir@ -Ivtysh/@top_srcdir@ -Ivtysh/@top_srcdir@/lib -Ivtysh/@top_builddir@/lib -Ivtysh/@top_srcdir@/bgpd -Ivtysh/@top_srcdir@/bgpd/rfapi @LUA_INCLUDE@ @CPPFLAGS@ $cppadd $file |");
+ open (FH, "@CPP@ -P -DHAVE_CONFIG_H -DVTYSH_EXTRACT_PL -Ivtysh/@top_builddir@ -Ivtysh/@top_srcdir@ -Ivtysh/@top_srcdir@/lib -Ivtysh/@top_builddir@/lib -Ivtysh/@top_srcdir@/bgpd -Ivtysh/@top_srcdir@/bgpd/rfapi @LUA_INCLUDE@ @CPPFLAGS@ $cppadd $file |");
local $/; undef $/;
$line = <FH>;
if (!close (FH)) {
@@ -48,7 +48,7 @@ sub scan_file {
}
# ?: makes a group non-capturing
- @defun = ($line =~ /((?:DEFUN|DEFUN_HIDDEN|ALIAS|ALIAS_HIDDEN)\s*\(.+?\));?\s?\s?\n/sg);
+ @defun = ($line =~ /((?:DEFUN|DEFUN_HIDDEN|DEFUN_YANG|ALIAS|ALIAS_HIDDEN|ALIAS_YANG|DEFPY|DEFPY_HIDDEN|DEFPY_YANG)\s*\(.+?\));?\s?\s?\n/sg);
@install = ($line =~ /install_element\s*\(\s*[0-9A-Z_]+,\s*&[^;]*;\s*\n/sg);
# DEFUN process
@@ -98,7 +98,10 @@ sub scan_file {
elsif ($file =~ /lib\/if\.c$/) {
$protocol = "VTYSH_INTERFACE";
}
- elsif ($file =~ /lib\/(filter|filter_cli|lib_vty)\.c$/) {
+ elsif ($file =~ /lib\/(filter|filter_cli)\.c$/) {
+ $protocol = "VTYSH_ACL";
+ }
+ elsif ($file =~ /lib\/lib_vty\.c$/) {
$protocol = "VTYSH_ALL";
}
elsif ($file =~ /lib\/agentx\.c$/) {
diff --git a/vtysh/vtysh.h b/vtysh/vtysh.h
index d0edbb2710..d2675a81b9 100644
--- a/vtysh/vtysh.h
+++ b/vtysh/vtysh.h
@@ -52,7 +52,8 @@ DECLARE_MGROUP(MVTYSH)
* run on it (logging & co. should stay in a fixed/frozen config, and
* things like prefix lists are not even initialised) */
#define VTYSH_ALL VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_LDPD|VTYSH_BGPD|VTYSH_ISISD|VTYSH_PIMD|VTYSH_NHRPD|VTYSH_EIGRPD|VTYSH_BABELD|VTYSH_SHARPD|VTYSH_PBRD|VTYSH_STATICD|VTYSH_BFDD|VTYSH_FABRICD|VTYSH_VRRPD
-#define VTYSH_RMAP VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ISISD|VTYSH_PIMD|VTYSH_EIGRPD|VTYSH_SHARPD|VTYSH_FABRICD
+#define VTYSH_ACL VTYSH_BFDD|VTYSH_BABELD|VTYSH_BGPD|VTYSH_EIGRPD|VTYSH_ISISD|VTYSH_FABRICD|VTYSH_LDPD|VTYSH_NHRPD|VTYSH_OSPF6D|VTYSH_OSPFD|VTYSH_PBRD|VTYSH_PIMD|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_VRRPD|VTYSH_ZEBRA
+#define VTYSH_RMAP VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ISISD|VTYSH_PIMD|VTYSH_EIGRPD|VTYSH_FABRICD
#define VTYSH_INTERFACE VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_ISISD|VTYSH_PIMD|VTYSH_NHRPD|VTYSH_EIGRPD|VTYSH_BABELD|VTYSH_PBRD|VTYSH_FABRICD|VTYSH_VRRPD
#define VTYSH_VRF VTYSH_ZEBRA|VTYSH_PIMD|VTYSH_STATICD
#define VTYSH_KEYS VTYSH_RIPD|VTYSH_EIGRPD
diff --git a/vtysh/vtysh_config.c b/vtysh/vtysh_config.c
index 61bcf3b658..85221b8b45 100644
--- a/vtysh/vtysh_config.c
+++ b/vtysh/vtysh_config.c
@@ -35,6 +35,7 @@ DEFINE_MTYPE_STATIC(MVTYSH, VTYSH_CONFIG_LINE, "Vtysh configuration line")
vector configvec;
PREDECL_LIST(config_master);
+PREDECL_HASH(config_master_hash);
struct config {
/* Configuration node name. */
@@ -51,6 +52,7 @@ struct config {
/* Node entry for the typed Red-black tree */
struct config_master_item rbt_item;
+ struct config_master_hash_item hash_item;
};
struct list *config_top;
@@ -79,29 +81,49 @@ static void config_del(struct config *config)
XFREE(MTYPE_VTYSH_CONFIG, config);
}
+static int config_cmp(const struct config *c1, const struct config *c2)
+{
+ return strcmp(c1->name, c2->name);
+}
+
+static uint32_t config_hash(const struct config *c)
+{
+ return string_hash_make(c->name);
+}
+
DECLARE_LIST(config_master, struct config, rbt_item)
+DECLARE_HASH(config_master_hash, struct config, hash_item, config_cmp,
+ config_hash)
+
+/*
+ * The config_master_head is a list for order of receipt
+ * The hash is for quick lookup under this NODE
+ */
+struct configuration {
+ struct config_master_head master;
+ struct config_master_hash_head hash_master;
+};
static struct config *config_get(int index, const char *line)
{
struct config *config, *config_loop;
- struct config_master_head *master;
+ struct configuration *configuration;
+ struct config lookup;
config = config_loop = NULL;
- master = vector_lookup_ensure(configvec, index);
+ configuration = vector_lookup_ensure(configvec, index);
- if (!master) {
- master = XMALLOC(MTYPE_VTYSH_CONFIG, sizeof(struct config_master_head));
- config_master_init(master);
- vector_set_index(configvec, index, master);
+ if (!configuration) {
+ configuration = XMALLOC(MTYPE_VTYSH_CONFIG,
+ sizeof(struct configuration));
+ config_master_init(&configuration->master);
+ config_master_hash_init(&configuration->hash_master);
+ vector_set_index(configvec, index, configuration);
}
- frr_each (config_master, master, config_loop) {
- if (strcmp(config_loop->name, line) == 0) {
- config = config_loop;
- break;
- }
- }
+ lookup.name = (char *)line;
+ config = config_master_hash_find(&configuration->hash_master, &lookup);
if (!config) {
config = config_new();
@@ -110,7 +132,8 @@ static struct config *config_get(int index, const char *line)
config->line->cmp = (int (*)(void *, void *))line_cmp;
config->name = XSTRDUP(MTYPE_VTYSH_CONFIG_LINE, line);
config->index = index;
- config_master_add_tail(master, config);
+ config_master_add_tail(&configuration->master, config);
+ config_master_hash_add(&configuration->hash_master, config);
}
return config;
}
@@ -438,7 +461,7 @@ void vtysh_config_dump(void)
struct listnode *node, *nnode;
struct listnode *mnode, *mnnode;
struct config *config;
- struct config_master_head *master;
+ struct configuration *configuration;
char *line;
unsigned int i;
@@ -448,8 +471,11 @@ void vtysh_config_dump(void)
vty_out(vty, "!\n");
for (i = 0; i < vector_active(configvec); i++)
- if ((master = vector_slot(configvec, i)) != NULL) {
- while ((config = config_master_pop(master))) {
+ if ((configuration = vector_slot(configvec, i)) != NULL) {
+ while ((config = config_master_pop(
+ &configuration->master))) {
+ config_master_hash_del(
+ &configuration->hash_master, config);
/* Don't print empty sections for interface.
* Route maps on the
* other hand could have a legitimate empty
@@ -477,9 +503,10 @@ void vtysh_config_dump(void)
}
for (i = 0; i < vector_active(configvec); i++)
- if ((master = vector_slot(configvec, i)) != NULL) {
- config_master_fini(master);
- XFREE(MTYPE_VTYSH_CONFIG, master);
+ if ((configuration = vector_slot(configvec, i)) != NULL) {
+ config_master_fini(&configuration->master);
+ config_master_hash_fini(&configuration->hash_master);
+ XFREE(MTYPE_VTYSH_CONFIG, configuration);
vector_slot(configvec, i) = NULL;
}
list_delete_all_node(config_top);
diff --git a/watchfrr/watchfrr.c b/watchfrr/watchfrr.c
index db327a0fa2..d1003ad5fa 100644
--- a/watchfrr/watchfrr.c
+++ b/watchfrr/watchfrr.c
@@ -29,6 +29,7 @@
#include "lib_errors.h"
#include "zlog_targets.h"
#include "network.h"
+#include "printfrr.h"
#include <getopt.h>
#include <sys/un.h>
@@ -174,6 +175,7 @@ struct daemon {
#define OPTION_MINRESTART 2000
#define OPTION_MAXRESTART 2001
#define OPTION_DRY 2002
+#define OPTION_NETNS 2003
static const struct option longopts[] = {
{"daemon", no_argument, NULL, 'd'},
@@ -190,6 +192,9 @@ static const struct option longopts[] = {
{"max-restart-interval", required_argument, NULL, OPTION_MAXRESTART},
{"pid-file", required_argument, NULL, 'p'},
{"blank-string", required_argument, NULL, 'b'},
+#ifdef GNU_LINUX
+ {"netns", optional_argument, NULL, OPTION_NETNS},
+#endif
{"help", no_argument, NULL, 'h'},
{"version", no_argument, NULL, 'v'},
{NULL, 0, NULL, 0}};
@@ -244,7 +249,12 @@ Otherwise, the interval is doubled (but capped at the -M value).\n\n",
-d, --daemon Run in daemon mode. In this mode, error messages are sent\n\
to syslog instead of stdout.\n\
-S, --statedir Set the vty socket directory (default is %s)\n\
--l, --loglevel Set the logging level (default is %d).\n\
+-N, --pathspace Insert prefix into config & socket paths\n"
+#ifdef GNU_LINUX
+" --netns Create and/or use Linux network namespace. If no name is\n"
+" given, uses the value from `-N`.\n"
+#endif
+"-l, --loglevel Set the logging level (default is %d).\n\
The value should range from %d (LOG_EMERG) to %d (LOG_DEBUG),\n\
but it can be set higher than %d if extra-verbose debugging\n\
messages are desired.\n\
@@ -704,7 +714,7 @@ static void daemon_send_ready(int exitcode)
frr_detach();
- snprintf(started, sizeof(started), "%s%s", frr_vtydir,
+ snprintf(started, sizeof(started), "%s/%s", frr_vtydir,
"watchfrr.started");
fp = fopen(started, "w");
if (fp)
@@ -1102,6 +1112,148 @@ static int startup_timeout(struct thread *t_wakeup)
return 0;
}
+#ifdef GNU_LINUX
+
+#include <sys/mount.h>
+#include <sched.h>
+
+#define NETNS_RUN_DIR "/var/run/netns"
+
+static void netns_create(int dirfd, const char *nsname)
+{
+ /* make /var/run/netns shared between mount namespaces
+ * just like iproute2 sets it up
+ */
+ if (mount("", NETNS_RUN_DIR, "none", MS_SHARED | MS_REC, NULL)) {
+ if (errno != EINVAL) {
+ perror("mount");
+ exit(1);
+ }
+
+ if (mount(NETNS_RUN_DIR, NETNS_RUN_DIR, "none",
+ MS_BIND | MS_REC, NULL)) {
+ perror("mount");
+ exit(1);
+ }
+
+ if (mount("", NETNS_RUN_DIR, "none", MS_SHARED | MS_REC,
+ NULL)) {
+ perror("mount");
+ exit(1);
+ }
+ }
+
+ /* need an empty file to mount on top of */
+ int nsfd = openat(dirfd, nsname, O_CREAT | O_RDONLY | O_EXCL, 0);
+
+ if (nsfd < 0) {
+ fprintf(stderr, "failed to create \"%s/%s\": %s\n",
+ NETNS_RUN_DIR, nsname, strerror(errno));
+ exit(1);
+ }
+ close(nsfd);
+
+ if (unshare(CLONE_NEWNET)) {
+ perror("unshare");
+ unlinkat(dirfd, nsname, 0);
+ exit(1);
+ }
+
+ char *dstpath = asprintfrr(MTYPE_TMP, "%s/%s", NETNS_RUN_DIR, nsname);
+
+ /* bind-mount so the namespace has a name and is persistent */
+ if (mount("/proc/self/ns/net", dstpath, "none", MS_BIND, NULL) < 0) {
+ fprintf(stderr, "failed to bind-mount netns to \"%s\": %s\n",
+ dstpath, strerror(errno));
+ unlinkat(dirfd, nsname, 0);
+ exit(1);
+ }
+
+ XFREE(MTYPE_TMP, dstpath);
+}
+
+static void netns_setup(const char *nsname)
+{
+ int dirfd, nsfd;
+
+ dirfd = open(NETNS_RUN_DIR, O_DIRECTORY | O_RDONLY);
+ if (dirfd < 0) {
+ if (errno == ENOTDIR) {
+ fprintf(stderr, "error: \"%s\" is not a directory!\n",
+ NETNS_RUN_DIR);
+ exit(1);
+ } else if (errno == ENOENT) {
+ if (mkdir(NETNS_RUN_DIR, 0755)) {
+ fprintf(stderr, "error: \"%s\": mkdir: %s\n",
+ NETNS_RUN_DIR, strerror(errno));
+ exit(1);
+ }
+ dirfd = open(NETNS_RUN_DIR, O_DIRECTORY | O_RDONLY);
+ if (dirfd < 0) {
+ fprintf(stderr, "error: \"%s\": opendir: %s\n",
+ NETNS_RUN_DIR, strerror(errno));
+ exit(1);
+ }
+ } else {
+ fprintf(stderr, "error: \"%s\": %s\n",
+ NETNS_RUN_DIR, strerror(errno));
+ exit(1);
+ }
+ }
+
+ nsfd = openat(dirfd, nsname, O_RDONLY);
+ if (nsfd < 0 && errno != ENOENT) {
+ fprintf(stderr, "error: \"%s/%s\": %s\n",
+ NETNS_RUN_DIR, nsname, strerror(errno));
+ exit(1);
+ }
+ if (nsfd < 0)
+ netns_create(dirfd, nsname);
+ else {
+ if (setns(nsfd, CLONE_NEWNET)) {
+ perror("setns");
+ exit(1);
+ }
+ close(nsfd);
+ }
+ close(dirfd);
+
+ /* make sure loopback is up... weird things happen otherwise.
+ * ioctl is perfectly fine for this, don't need netlink...
+ */
+ int sockfd;
+ struct ifreq ifr = { };
+
+ strlcpy(ifr.ifr_name, "lo", sizeof(ifr.ifr_name));
+
+ sockfd = socket(AF_INET, SOCK_DGRAM, 0);
+ if (sockfd < 0) {
+ perror("socket");
+ exit(1);
+ }
+ if (ioctl(sockfd, SIOCGIFFLAGS, &ifr)) {
+ perror("ioctl(SIOCGIFFLAGS, \"lo\")");
+ exit(1);
+ }
+ if (!(ifr.ifr_flags & IFF_UP)) {
+ ifr.ifr_flags |= IFF_UP;
+ if (ioctl(sockfd, SIOCSIFFLAGS, &ifr)) {
+ perror("ioctl(SIOCSIFFLAGS, \"lo\")");
+ exit(1);
+ }
+ }
+ close(sockfd);
+}
+
+#else /* !GNU_LINUX */
+
+static void netns_setup(const char *nsname)
+{
+ fprintf(stderr, "network namespaces are only available on Linux\n");
+ exit(1);
+}
+#endif
+
static void watchfrr_init(int argc, char **argv)
{
const char *special = "zebra";
@@ -1191,11 +1343,13 @@ int main(int argc, char **argv)
{
int opt;
const char *blankstr = NULL;
+ const char *netns = NULL;
+ bool netns_en = false;
frr_preinit(&watchfrr_di, argc, argv);
progname = watchfrr_di.progname;
- frr_opt_add("b:dk:l:i:p:r:S:s:t:T:" DEPRECATED_OPTIONS, longopts, "");
+ frr_opt_add("b:di:k:l:N:p:r:S:s:t:T:" DEPRECATED_OPTIONS, longopts, "");
gs.restart.name = "all";
while ((opt = frr_getopt(argc, argv, NULL)) != EOF) {
@@ -1260,6 +1414,16 @@ int main(int argc, char **argv)
frr_help_exit(1);
}
} break;
+ case OPTION_NETNS:
+ netns_en = true;
+ if (strchr(optarg, '/')) {
+ fprintf(stderr,
+ "invalid network namespace name \"%s\" (may not contain slashes)\n",
+ optarg);
+ frr_help_exit(1);
+ }
+ netns = optarg;
+ break;
case 'i': {
char garbage[3];
int period;
@@ -1351,6 +1515,17 @@ int main(int argc, char **argv)
gs.restart.interval = gs.min_restart_interval;
+ /* env variable for the processes that we start */
+ if (watchfrr_di.pathspace)
+ setenv("FRR_PATHSPACE", watchfrr_di.pathspace, 1);
+ else
+ unsetenv("FRR_PATHSPACE");
+
+ if (netns_en && !netns)
+ netns = watchfrr_di.pathspace;
+ if (netns_en && netns && netns[0])
+ netns_setup(netns);
+
master = frr_init();
watchfrr_error_init();
watchfrr_init(argc, argv);
diff --git a/yang/embedmodel.py b/yang/embedmodel.py
index 624a11da9d..0a25c93da7 100644
--- a/yang/embedmodel.py
+++ b/yang/embedmodel.py
@@ -20,6 +20,8 @@ if not os.path.isdir(outdir):
# to make it even harder.
re_name = re.compile(r'\bmodule\s+([^\s]+)\s+\{')
+re_subname = re.compile(r'\bsubmodule\s+([^\s]+)\s+\{')
+re_mainname = re.compile(r'\bbelongs-to\s+([^\s]+)\s+\{')
re_rev = re.compile(r'\brevision\s+([\d-]+)\s+\{')
@@ -34,6 +36,8 @@ static const char model[] =
static struct yang_module_embed embed = {
\t.mod_name = "%s",
\t.mod_rev = "%s",
+\t.sub_mod_name = "%s",
+\t.sub_mod_rev = "%s",
\t.data = model,
\t.format = %s,
};
@@ -62,6 +66,10 @@ def escape(line):
with open(inname, 'r') as fd:
data = fd.read()
+sub_name = ""
+rev = ""
+sub_rev = ""
+
# XML support isn't actively used currently, but it's here in case the need
# arises. It does avoid the regex'ing.
if '<?xml' in data:
@@ -71,8 +79,15 @@ if '<?xml' in data:
rev = xml.find('{urn:ietf:params:xml:ns:yang:yin:1}revision').get('date')
fmt = 'LYS_YIN'
else:
- name = re_name.search(data).group(1)
- rev = re_rev.search(data).group(1)
+ search_name = re_name.search(data)
+ if search_name :
+ name = search_name.group(1)
+ rev = re_rev.search(data).group(1)
+ else :
+ search_name = re_subname.search(data)
+ sub_name = search_name.group(1)
+ name = re_mainname.search(data).group(1)
+ sub_rev = re_rev.search(data).group(1)
fmt = 'LYS_YANG'
if name is None or rev is None:
@@ -82,4 +97,4 @@ lines = [escape(row) for row in data.split('\n')]
text = '\\n"\n\t"'.join(lines)
with open(outname, 'w') as fd:
- fd.write(template % (text, escape(name), escape(rev), fmt))
+ fd.write(template % (text, escape(name), escape(rev), escape(sub_name), escape(sub_rev), fmt))
diff --git a/yang/frr-filter.yang b/yang/frr-filter.yang
index 78db201ea1..c9e09bef4b 100644
--- a/yang/frr-filter.yang
+++ b/yang/frr-filter.yang
@@ -49,28 +49,6 @@ module frr-filter {
/*
* Types.
*/
- typedef access-list-standard {
- description "Standard IPv4 access list (any, host or a prefix)";
- type uint16 {
- range "1..99 | 1300..1999";
- }
- }
-
- typedef access-list-extended {
- description
- "Extended IPv4 access list (source / destination any, hosts or prefixes)";
- type uint16 {
- range "100..199 | 2000..2699";
- }
- }
-
- typedef access-list-legacy {
- description "Standard/Extended IPv4 access list";
- type uint16 {
- range "1..199 | 1300..2699";
- }
- }
-
typedef access-list-name {
description "Access list name formatting";
type string {
@@ -103,79 +81,6 @@ module frr-filter {
* Configuration data.
*/
container lib {
- list access-list-legacy {
- description "Access list legacy instance";
-
- key "number";
-
- leaf number {
- description "Access list sequence value";
- type access-list-legacy;
- }
-
- leaf remark {
- description "Access list remark";
- type string;
- }
-
- list entry {
- description "Access list legacy entry";
-
- key "sequence";
-
- leaf sequence {
- description "Access list sequence value";
- type access-list-sequence;
- }
-
- leaf action {
- description "Access list action on match";
- type access-list-action;
- mandatory true;
- }
-
- choice value {
- description
- "Standard access list: value to match.
- Extended access list: source value to match.";
- mandatory true;
-
- leaf host {
- description "Host to match";
- type inet:ipv4-address;
- }
- leaf network {
- description "Network to match";
- type inet:ipv4-prefix;
- }
- leaf any {
- description "Match any";
- type empty;
- }
- }
-
- choice extended-value {
- when "../number >= 100 and ../number <= 199 or
- ../number >= 2000 and ../number <= 2699";
- description "Destination value to match";
- mandatory true;
-
- leaf destination-host {
- description "Host to match";
- type inet:ipv4-address;
- }
- leaf destination-network {
- description "Network to match";
- type inet:ipv4-prefix;
- }
- leaf destination-any {
- description "Match any";
- type empty;
- }
- }
- }
- }
-
list access-list {
description "Access list instance";
@@ -232,15 +137,66 @@ module frr-filter {
case ipv4-prefix {
when "../type = 'ipv4'";
- leaf ipv4-prefix {
- description "Configure IPv4 prefix to match";
- type inet:ipv4-prefix;
- }
+ choice style {
+ description "Access list entry style selection: zebra or cisco.";
+ mandatory true;
+
+ case zebra {
+ leaf ipv4-prefix {
+ description "Configure IPv4 prefix to match";
+ type inet:ipv4-prefix;
+ }
+
+ leaf ipv4-exact-match {
+ description "Exact match of prefix";
+ type boolean;
+ default false;
+ }
+ }
+ case cisco {
+ leaf host {
+ description "Host to match";
+ type inet:ipv4-address;
+ }
+ leaf network {
+ description "Network to match";
+ type inet:ipv4-prefix;
+ }
+ leaf source-any {
+ /*
+ * Was `any`, however it conflicts with `any` leaf
+ * outside this choice.
+ */
+ description "Match any";
+ type empty;
+ }
+ }
- leaf ipv4-exact-match {
- description "Exact match of prefix";
- type boolean;
- default false;
+ choice extended-value {
+ /*
+ * Legacy note: before using the new access-list format the
+ * cisco styled list only accepted identifiers using numbers
+ * and they had the following restriction:
+ *
+ * when "../number >= 100 and ../number <= 199 or
+ * ../number >= 2000 and ../number <= 2699";
+ */
+ description "Destination value to match";
+ mandatory true;
+
+ leaf destination-host {
+ description "Host to match";
+ type inet:ipv4-address;
+ }
+ leaf destination-network {
+ description "Network to match";
+ type inet:ipv4-prefix;
+ }
+ leaf destination-any {
+ description "Match any";
+ type empty;
+ }
+ }
}
}
case ipv6-prefix {
diff --git a/yang/frr-isisd.yang b/yang/frr-isisd.yang
index befdc3467d..1bb693a1ef 100644
--- a/yang/frr-isisd.yang
+++ b/yang/frr-isisd.yang
@@ -361,11 +361,18 @@ module frr-isisd {
"IS-type of this circuit.";
}
- leaf bfd-monitoring {
- type boolean;
- default "false";
- description
- "Monitor IS-IS peers on this circuit.";
+ container bfd-monitoring {
+ leaf enabled {
+ type boolean;
+ default "false";
+ description
+ "Monitor IS-IS peers on this circuit.";
+ }
+ leaf profile {
+ type string;
+ description
+ "Let BFD use a pre-configured profile.";
+ }
}
container csnp-interval {
diff --git a/yang/frr-nexthop.yang b/yang/frr-nexthop.yang
index 779c56df7f..c918a7cbfd 100644
--- a/yang/frr-nexthop.yang
+++ b/yang/frr-nexthop.yang
@@ -156,7 +156,7 @@ module frr-nexthop {
}
leaf vrf {
- type frr-vrf:vrf-ref;
+ type string;
description
"The nexthop vrf name, if different from the route.";
}
@@ -167,7 +167,7 @@ module frr-nexthop {
}
leaf interface {
- type frr-interface:interface-ref;
+ type string;
description
"The nexthop egress interface.";
}
@@ -236,7 +236,8 @@ module frr-nexthop {
grouping nexthop-grouping {
list nexthop {
- key "nh-type gateway interface";
+ key "nh-type vrf gateway interface";
+ min-elements 1;
description
"A list of nexthop objects.";
uses frr-nexthop-attributes;
diff --git a/yang/frr-ospfd.yang b/yang/frr-ospfd.yang
new file mode 100644
index 0000000000..324b66dd98
--- /dev/null
+++ b/yang/frr-ospfd.yang
@@ -0,0 +1,995 @@
+module frr-ospfd {
+ yang-version 1.1;
+ namespace "http://frrouting.org/yang/ospfd";
+ prefix frr-ospfd;
+
+ import frr-routing {
+ prefix frr-rt;
+ }
+
+ import ietf-inet-types {
+ prefix inet;
+ }
+
+ import frr-interface {
+ prefix frr-interface;
+ }
+
+ import frr-route-types {
+ prefix frr-route-types;
+ }
+
+ organization
+ "FRRouting";
+ contact
+ "FRR Users List: <mailto:frog@lists.frrouting.org>
+ FRR Development List: <mailto:dev@lists.frrouting.org>";
+ description
+ "This module defines a model for managing FRR OSPFd information.
+ This YANG module augments the basic routing with additional
+ OSPF information";
+
+ revision 2020-07-21 {
+ description
+ "Initial revision.";
+ }
+
+ identity ospf {
+ base frr-rt:routing-protocol;
+ description
+ "'OSPF' routing ospf-protocol.";
+ }
+
+ /* Policy types to be removed later, once policy Yang finalized */
+ typedef rmap-ref {
+ type string;
+ }
+
+ typedef plist-ref {
+ type string;
+ }
+
+ typedef access-list-ref {
+ type string;
+ }
+
+ typedef ospf-area-id {
+ type union {
+ type inet:ipv4-address;
+ type uint32;
+ }
+ description "OSPF Area ID.";
+ }
+
+ grouping nssa-grouping {
+ container nssa {
+ presence "Present if the nssa is enabled";
+ leaf no-summary {
+ type boolean;
+ default "false";
+ description
+ "Do not inject inter-area routes into nssa";
+ }
+
+ leaf translate-always {
+ type boolean;
+ default "false";
+ description
+ "NSSA-ABR to always translate";
+ }
+
+ leaf translate-candidate {
+ type boolean;
+ default "false";
+ description
+ "NSSA-ABR for translate election";
+ }
+
+ leaf translate-never {
+ type boolean;
+ default "false";
+ description
+ "NSSA-ABR to never translate";
+ }
+ }
+ }
+
+ grouping range-grouping {
+ container ranges {
+ list range {
+ key "prefix";
+ description
+ "A list of range objects";
+ leaf prefix {
+ type inet:ipv4-prefix;
+ description
+ "Area range prefix";
+ }
+
+ leaf advertise {
+ type boolean;
+ description
+ "Advertise this range";
+ }
+
+ leaf not-advertise {
+ type boolean;
+ default "false";
+ description
+ "Do not advertise this range";
+ }
+
+ leaf cost {
+ type uint32 {
+ range "0..16777215";
+ }
+ description
+ "Metric for this range";
+ }
+
+ leaf substitute {
+ type inet:ipv4-prefix;
+ description
+ "Network prefix to be announced instead of range";
+ }
+ }
+ }
+ }
+
+ grouping stub-grouping {
+ container stub {
+ presence "Present when area is stub";
+ leaf no-summary {
+ type boolean;
+ default "false";
+ description
+ "Do not inject inter-area routes into stub";
+ }
+ }
+ }
+
+ grouping shortcut-grouping {
+ container shortcut {
+ leaf default {
+ type boolean;
+ default "false";
+ description
+ "Default shortcutting behavior";
+ }
+
+ leaf disable {
+ type boolean;
+ description
+ "Disable shortcutting through the area";
+ }
+
+ leaf enable {
+ type boolean;
+ description
+ "Enable shortcutting through the area";
+ }
+ }
+ }
+
+ grouping authentication-group {
+ container authentication {
+ presence "Enable authentication.";
+ description
+ "Enable authentication on this virtual link.";
+ leaf message-digest {
+ type boolean;
+ description
+ "Use message-digest authentication.";
+ }
+
+ leaf null {
+ type boolean;
+ description
+ "Use null authentication.";
+ }
+ }
+
+ list message-digest-key {
+ key "key-id";
+ leaf key-id {
+ type uint8;
+ description
+ "Key id";
+ }
+
+ leaf mds-key {
+ type string;
+ description
+ "The OSPF password.";
+ }
+ }
+
+ leaf authentication-key {
+ type string;
+ description
+ "The OSPF password.";
+ }
+ }
+
+ grouping virtual-link-group {
+ list virtual-link {
+ key "neighbor area-id";
+ description
+ "Virtual link parameters.";
+ leaf neighbor {
+ type inet:ipv4-address;
+ description
+ "Router ID of the remote ABR.";
+ }
+
+ leaf area-id {
+ mandatory true;
+ type ospf-area-id;
+ }
+
+ uses authentication-group;
+
+ container timers {
+ leaf dead-interval {
+ type uint16;
+ units "seconds";
+ description
+ "Interval time after which a neighbor is declared down.";
+ }
+
+ leaf hello-interval {
+ type uint16 {
+ range "1..65535";
+ }
+ units "seconds";
+ description
+ "Time between HELLO packets.";
+ }
+
+ leaf retransmit-interval {
+ type uint16 {
+ range "1..65535";
+ }
+ units "seconds";
+ description
+ "Time between retransmitting lost link state advertisements.";
+ }
+
+ leaf transmit-delay {
+ type uint16 {
+ range "1..65535";
+ }
+ units "seconds";
+ description
+ "Link state transmit delay.";
+ }
+ }
+ }
+ }
+
+ grouping area-groupings {
+ container areas {
+ list area {
+ key "area-id";
+ description
+ "A list of area objects";
+ leaf area-id {
+ type ospf-area-id;
+ }
+
+ container authentication {
+ presence "Enable authentication";
+ leaf message-digest {
+ type boolean;
+ description
+ "Use message-digest authentication";
+ }
+ }
+
+ leaf default-cost {
+ type uint32 {
+ range "0..16777215";
+ }
+ description
+ "Advertised default summary cost";
+ }
+
+ leaf export-list {
+ type access-list-ref;
+ description
+ "Filter for networks announced to other areas.";
+ }
+
+ leaf import-list {
+ type access-list-ref;
+ description
+ "Filter for networks from other areas announced to the specified one.";
+ }
+
+ container filter-list {
+ leaf prefix {
+ type plist-ref;
+ description
+ "Filter networks between OSPF areas.";
+ }
+
+ leaf in {
+ type boolean;
+ }
+
+ leaf out {
+ type boolean;
+ }
+ }
+
+ uses nssa-grouping;
+
+ uses range-grouping;
+
+ uses stub-grouping;
+
+ uses shortcut-grouping;
+
+ uses virtual-link-group;
+ }
+ }
+ }
+
+ /* router ospf attributes */
+ grouping route-ospf-leaf-attributes {
+ leaf auto-cost-reference-bandwidth {
+ type uint32 {
+ range "1..4294967";
+ }
+ units "Mbits";
+ description
+ "The reference bandwidth in terms of Mbits per second.";
+ }
+
+ leaf capability-opaque {
+ type boolean;
+ default "false";
+ description
+ "Opaque LSA.";
+ }
+
+ leaf compatible-rfc1583 {
+ type boolean;
+ description
+ "Compatible with RFC 1583.";
+ }
+
+ leaf default-metric {
+ type uint32 {
+ range "0..16777214";
+ }
+ description
+ "Metric of redistributed routes.";
+ }
+
+ leaf write-multiplier {
+ type uint8 {
+ range "1..100";
+ }
+ description
+ "Maximum number of interfaces serviced per write.";
+ }
+
+ container router-info {
+ choice router-info {
+ case as {
+ leaf as {
+ type boolean;
+ description
+ "Enable the Router Information functionality with AS flooding scope.";
+ }
+ }
+ case area {
+ leaf area {
+ type ospf-area-id;
+ description
+ "Enable the Router Information functionality with Area flooding scope.";
+ }
+ }
+ }
+ }
+ }
+
+ grouping metric-common-group {
+ leaf metric {
+ type uint32 {
+ range "0..16777214";
+ }
+ description
+ "OSPF default metric.";
+ }
+
+ leaf metric-type {
+ type enumeration {
+ enum "type-1" {
+ value 1;
+ }
+ enum "type-2" {
+ value 2;
+ }
+ }
+ description
+ "Metric type (1/2).";
+ }
+
+ leaf route-map {
+ type rmap-ref;
+ description
+ "Route map reference.";
+ }
+ }
+
+ grouping default-info-group {
+ container default-information {
+ leaf originate {
+ type boolean;
+ description
+ "Advertise a default route";
+ }
+
+ leaf always {
+ type boolean;
+ description
+ "Always advertise default route.";
+ }
+
+ uses metric-common-group;
+ }
+ }
+
+ grouping redistribute-group {
+ list redistribute {
+ key "protocol";
+ leaf protocol {
+ type frr-route-types:frr-route-types-v4;
+ description
+ "Protocol.";
+ }
+
+ uses metric-common-group;
+ }
+ }
+
+ grouping distance-group {
+ container distance {
+ leaf admin-value {
+ type uint8 {
+ range "1..255";
+ }
+ description
+ "Admin value.";
+ }
+
+ container ospf {
+ leaf external {
+ type uint8 {
+ range "1..255";
+ }
+ description
+ "Distance for external routes.";
+ }
+
+ leaf inter-area {
+ type uint8 {
+ range "1..255";
+ }
+ description
+ "Distance for inter-area routes.";
+ }
+
+ leaf intra-area {
+ type uint8 {
+ range "1..255";
+ }
+ description
+ "Distance for intra-area routes.";
+ }
+ }
+ }
+ }
+
+ grouping distribute-list-group {
+ container distribute-list {
+ list dlist {
+ key "name protocol";
+ leaf name {
+ type string;
+ description
+ "Filter networks in routing updates.";
+ }
+
+ leaf protocol {
+ type frr-route-types:frr-route-types-v4;
+ description
+ "Out protocol.";
+ }
+ }
+ }
+ }
+
+ grouping max-metric-group {
+ container max-metric {
+ container router-lsa {
+ description
+ "Advertise own Router-LSA with infinite distance (stub router).";
+ leaf administrative {
+ type boolean;
+ description
+ "Administratively applied, for an indefinite period.";
+ }
+
+ leaf on-shutdown {
+ type uint8 {
+ range "5..100";
+ }
+ description
+ "Advertise stub-router prior to full shutdown of OSPF.";
+ }
+
+ leaf on-startup {
+ type uint32 {
+ range "5..86400";
+ }
+ description
+ "Automatically advertise stub Router-LSA on startup of OSPF.";
+ }
+ }
+ }
+ }
+
+ grouping mpls-te-group {
+ container mpls-te {
+ leaf on {
+ type boolean;
+ description
+ "Enable the MPLS-TE functionality.";
+ }
+
+ leaf router-address {
+ type inet:ipv4-address;
+ description
+ "Stable IP address of the advertising router.";
+ }
+
+ container inter-as {
+ leaf as {
+ type boolean;
+ description
+ "AS native mode self originate INTER-AS LSA with Type 11 (as flooding scope).";
+ }
+
+ leaf area {
+ type ospf-area-id;
+ description
+ "AREA native mode self originate INTER-AS LSA with Type 10 (area flooding scope).";
+ }
+ }
+ }
+ }
+
+ grouping ospf-group {
+ container ospf {
+ leaf abr-type {
+ type enumeration {
+ enum "cisco" {
+ value 1;
+ description
+ "Alternative ABR, Cisco implementation.";
+ }
+ enum "ibm" {
+ value 2;
+ description
+ "Alternative ABR, IBM implementation.";
+ }
+ enum "shortcut" {
+ value 3;
+ description
+ "Shortcut ABR.";
+ }
+ enum "standard" {
+ value 4;
+ description
+ "Standard behavior (RFC2328).";
+ }
+ }
+ }
+
+ leaf opaque-lsa {
+ type boolean;
+ description
+ "Enable the Opaque-LSA capability (RFC2370)";
+ }
+
+ leaf rfc1583compatibility {
+ type boolean;
+ description
+ "Enable the RFC 1583 compatibility flag.";
+ }
+
+ leaf router-id {
+ type inet:ipv4-address;
+ description
+ "Router-id for the OSPF process.";
+ }
+
+ leaf write-multiplier {
+ type uint8 {
+ range "1..100";
+ }
+ description
+ "Write multiplier.";
+ }
+ }
+ }
+
+ grouping timer-group {
+ container timers {
+ leaf refresh-interval {
+ type uint16 {
+ range "10..1800";
+ }
+ units "seconds";
+ description
+ "The maximum time between distinct originations of any particular
+ LSA, value in units seconds.";
+ }
+
+ leaf lsa-min-arrival {
+ type uint32 {
+ range "0..600000";
+ }
+ units "milliseconds";
+ description
+ "Minimum delay in receiving new version of an LSA.";
+ }
+
+ container throttle {
+ leaf lsa-all {
+ type uint16 {
+ range "0..5000";
+ }
+ units "milliseconds";
+ description
+ "LSA delay between transmissions.";
+ }
+
+ leaf spf {
+ type uint32 {
+ range "0..600000";
+ }
+ units "milliseconds";
+ description
+ "Delay from first change received till SPF calculation.";
+ }
+ }
+ }
+ }
+
+ grouping segment-routing-group {
+ container segment-routing {
+ container global-block {
+ description
+ "Segment Routing Global Block label range.";
+ must "./upper-bound > ./lower-bound";
+ leaf lower-bound {
+ type uint32 {
+ range "0..1048575";
+ }
+ default "16000";
+ }
+
+ leaf upper-bound {
+ type uint32 {
+ range "0..1048575";
+ }
+ default "23999";
+ }
+ }
+
+ container srlb {
+ description
+ "Local blocks to be advertised.";
+ must "./upper-bound > ./lower-bound";
+ leaf lower-bound {
+ type uint32;
+ default "15000";
+ description
+ "Lower value in the label range.";
+ }
+ leaf upper-bound {
+ type uint32;
+ default "15999";
+ description
+ "Upper value in the label range.";
+ }
+ }
+
+ leaf node-msd {
+ type uint8 {
+ range "1..16";
+ }
+ description
+ "Maximum Stack Depth for this router.";
+ }
+
+ leaf on {
+ type boolean;
+ description
+ "Enable Segment Routing.";
+ }
+
+ list prefix-sid {
+ key "index";
+ leaf index {
+ type uint16;
+ description
+ "SID index for this prefix.";
+ }
+
+ leaf prefix {
+ type inet:ipv4-prefix;
+ description
+ "Prefix SID.";
+ }
+
+ leaf last-hop-behavior {
+ type enumeration {
+ enum "explicit-null" {
+ value 0;
+ description
+ "Use explicit-null for the SID.";
+ }
+ enum "no-php" {
+ value 1;
+ description
+ "Do not use Penultimate Hop Popping (PHP)
+ for the SID.";
+ }
+ enum "php" {
+ value 2;
+ description
+ "Use PHP for the SID.";
+ }
+ }
+ default "php";
+ description
+ "Configure last hop behavior.";
+ }
+ }
+ }
+ }
+
+ grouping ospf-list-group {
+ list neighbor {
+ key "ip";
+ description
+ "Neighbor list.";
+ leaf ip {
+ type inet:ipv4-address;
+ description
+ "Neighbor IP address.";
+ }
+
+ leaf priority {
+ type uint8;
+ description
+ "Neighbor Priority.";
+ }
+
+ leaf poll-interval {
+ type uint16 {
+ range "1..65535";
+ }
+ units "seconds";
+ description
+ "Dead Neighbor Polling interval.";
+ }
+ }
+
+ list network {
+ key "prefix";
+ description
+ "Enable routing on list of IP network.";
+ leaf prefix {
+ type inet:ipv4-prefix;
+ description
+ "Prefix on which routing needs to be enabled.";
+ }
+
+ leaf area {
+ type ospf-area-id;
+ description
+ "Area ID for this network.";
+ }
+ }
+
+ list passive-interface {
+ key "interface";
+ description
+ "Suppress routing updates on list interface.";
+ leaf interface {
+ type frr-interface:interface-ref;
+ description
+ "Suppress routing updates on an interface.";
+ }
+
+ leaf address {
+ type inet:ipv4-address;
+ description
+ "Interface address.";
+ }
+ }
+ }
+
+ grouping interface-ospf-attribute-group {
+ leaf area {
+ type ospf-area-id;
+ description
+ "OSPF area ID.";
+ }
+
+ uses authentication-group;
+
+ leaf cost {
+ type uint16 {
+ range "1..65535";
+ }
+ description
+ "Interface cost";
+ }
+
+ container dead-interval {
+ leaf interval {
+ type uint16 {
+ range "1..65535";
+ }
+ units "seconds";
+ }
+
+ container minimal {
+ leaf hello-multiplier {
+ type uint8 {
+ range "1..10";
+ }
+ }
+ }
+ }
+
+ leaf hello-interval {
+ type uint16 {
+ range "1..65535";
+ }
+ units "seconds";
+ description
+ "Time between HELLO packets.";
+ }
+
+ leaf retransmit-interval {
+ type uint16 {
+ range "1..65535";
+ }
+ units "seconds";
+ description
+ "Time between retransmitting lost link state advertisements.";
+ }
+
+ leaf transmit-delay {
+ type uint16 {
+ range "1..65535";
+ }
+ units "seconds";
+ description
+ "Link state transmit delay.";
+ }
+
+ leaf mtu-ignore {
+ type boolean;
+ description
+ "Disable MTU mismatch detection on this interface.";
+ }
+
+ leaf priority {
+ type uint8;
+ description
+ "Router priority.";
+ }
+ }
+
+ grouping interface-ospf-group {
+ list instance {
+ key "id";
+ leaf id {
+ type uint16;
+ description
+ "OSPF instance ID.";
+ }
+
+ leaf bfd {
+ type boolean;
+ default "false";
+ description
+ "BFD support.";
+ }
+
+ leaf network {
+ type enumeration {
+ enum "broadcast" {
+ value 1;
+ }
+ enum "non-broadcast" {
+ value 2;
+ }
+ enum "point-to-multipoint" {
+ value 3;
+ }
+ enum "point-to-point" {
+ value 4;
+ }
+ }
+ }
+
+ uses interface-ospf-attribute-group;
+
+ list interface-address {
+ key "address";
+ leaf address {
+ type inet:ipv4-address;
+ description
+ "Address of interface";
+ }
+
+ uses interface-ospf-attribute-group;
+ }
+ }
+ }
+
+ augment "/frr-rt:routing/frr-rt:control-plane-protocols/frr-rt:control-plane-protocol" {
+ container ospf {
+ when "../frr-rt:type = 'frr-ospfd:ospf'" {
+ description
+ "This container is only valid for the 'OSPF' routing
+ protocol.";
+ }
+
+ uses route-ospf-leaf-attributes;
+
+ uses default-info-group;
+
+ uses redistribute-group;
+
+ uses distance-group;
+
+ uses distribute-list-group;
+
+ uses max-metric-group;
+
+ uses mpls-te-group;
+
+ uses ospf-group;
+
+ uses timer-group;
+
+ uses segment-routing-group;
+
+ uses ospf-list-group;
+
+ uses area-groupings;
+ }
+ }
+
+ /*
+ * Per-interface configuration data
+ */
+ augment "/frr-interface:lib/frr-interface:interface" {
+ container ospf {
+ description
+ "OSPF interface parameters.";
+ uses interface-ospf-group;
+ }
+ }
+}
diff --git a/yang/frr-route-map.yang b/yang/frr-route-map.yang
index f35a2976d1..b895cd12a4 100644
--- a/yang/frr-route-map.yang
+++ b/yang/frr-route-map.yang
@@ -6,14 +6,17 @@ module frr-route-map {
import ietf-inet-types {
prefix inet;
}
+
import frr-filter {
prefix filter;
}
+
import frr-interface {
prefix frr-interface;
}
- organization "FRRouting";
+ organization
+ "FRRouting";
contact
"FRR Users List: <mailto:frog@lists.frrouting.org>
FRR Development List: <mailto:dev@lists.frrouting.org>";
@@ -46,22 +49,34 @@ module frr-route-map {
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.";
revision 2019-07-01 {
- description "Initial revision";
+ description
+ "Initial revision";
}
/*
* Types.
*/
typedef route-map-sequence {
- description "Route map valid sequence numbers";
type uint16 {
range "1..65535";
}
+ description
+ "Route map valid sequence numbers.";
}
typedef route-map-name {
- description "Route map name format";
type string;
+ description
+ "Route map name format.";
+ }
+
+ typedef route-map-ref {
+ type leafref {
+ path "/frr-route-map:lib/frr-route-map:route-map/frr-route-map:name";
+ require-instance false;
+ }
+ description
+ "Reference to a route-map.";
}
/*
@@ -69,34 +84,33 @@ module frr-route-map {
*/
container lib {
list route-map {
- description "Route map instance";
-
key "name";
-
+ description
+ "Route map instance.";
leaf name {
- description "Route map instance name";
type route-map-name;
+ description
+ "Route map instance name.";
}
list entry {
- description "Route map entry";
-
key "sequence";
-
+ description
+ "Route map entry.";
leaf sequence {
description
- "Route map instance priority (low number means higher priority)";
+ "Route map instance priority (low number means higher priority).";
type route-map-sequence;
}
leaf description {
- description "Route map description";
+ description "Route map description.";
type string;
}
leaf action {
description
- "Route map actions: permit (executes action), deny (quits evaluation)";
+ "Route map actions: permit (executes action), deny (quits evaluation).";
mandatory true;
type enumeration {
enum permit {
@@ -120,25 +134,25 @@ module frr-route-map {
description
"Call another route map before calling `exit-policy`. If the
called route map returns deny then this route map will also
- return deny";
+ return deny.";
type route-map-name;
}
leaf exit-policy {
- description "What do to after route map successful match, set and call";
+ description "What do to after route map successful match, set and call.";
type enumeration {
enum permit-or-deny {
- description "End route map evaluation and return";
+ description "End route map evaluation and return.";
value 0;
}
enum next {
description
- "Proceed evaluating next route map entry per sequence";
+ "Proceed evaluating next route map entry per sequence.";
value 1;
}
enum goto {
description
- "Go to route map entry with the provided sequence number";
+ "Go to route map entry with the provided sequence number.";
value 2;
}
}
@@ -148,82 +162,81 @@ module frr-route-map {
leaf goto-value {
when "../exit-policy = 'goto'";
description
- "Sequence number to jump (when using `goto` exit policy)";
+ "Sequence number to jump (when using `goto` exit policy).";
mandatory true;
type route-map-sequence;
}
list match-condition {
- description "Route map match conditions";
-
key "condition";
-
+ description
+ "Route map match conditions.";
leaf condition {
- description "Match condition";
+ description "Match condition.";
type enumeration {
enum interface {
- description "Match interface";
+ description "Match interface.";
value 0;
}
enum ipv4-address-list {
- description "Match an IPv4 access-list";
+ description "Match an IPv4 access-list.";
value 1;
}
enum ipv4-prefix-list {
- description "Match an IPv4 prefix-list";
+ description "Match an IPv4 prefix-list.";
value 2;
}
enum ipv4-next-hop-list {
- description "Match an IPv4 next-hop";
+ description "Match an IPv4 next-hop.";
value 3;
}
enum ipv4-next-hop-prefix-list {
- description "Match an IPv4 next-hop prefix list";
+ description "Match an IPv4 next-hop prefix list.";
value 4;
}
enum ipv4-next-hop-type {
- description "Match an IPv4 next-hop type";
+ description "Match an IPv4 next-hop type.";
value 5;
}
enum ipv6-address-list {
- description "Match an IPv6 access-list";
+ description "Match an IPv6 access-list.";
value 6;
}
enum ipv6-prefix-list {
- description "Match an IPv6 prefix-list";
+ description "Match an IPv6 prefix-list.";
value 7;
}
enum ipv6-next-hop-type {
- description "Match an IPv6 next-hop type";
+ description "Match an IPv6 next-hop type.";
value 8;
}
enum metric {
- description "Match a route metric";
+ description "Match a route metric.";
value 9;
}
enum tag {
- description "Match a route tag";
+ description "Match a route tag.";
value 10;
}
/* zebra specific conditions. */
enum ipv4-prefix-length {
- description "Match IPv4 prefix length";
+ description "Match IPv4 prefix length.";
value 100;
}
enum ipv6-prefix-length {
- description "Match IPv6 prefix length";
+ description "Match IPv6 prefix length.";
value 101;
}
enum ipv4-next-hop-prefix-length {
- description "Match next-hop prefix length";
+ description "Match next-hop prefix length.";
value 102;
}
enum source-protocol {
- description "Match source protocol";
+ description "Match source protocol.";
value 103;
}
enum source-instance {
- description "Match source protocol instance";
+ description "Match source protocol instance.";
value 104;
}
}
@@ -231,7 +244,7 @@ module frr-route-map {
choice condition-value {
description
- "Value to match (interpretation depends on condition type)";
+ "Value to match (interpretation depends on condition type).";
mandatory true;
case interface {
when "./condition = 'interface'";
@@ -239,20 +252,7 @@ module frr-route-map {
type string;
}
}
- case access-list-num {
- when "./condition = 'ipv4-address-list' or
- ./condition = 'ipv4-next-hop-list'";
- leaf access-list-num {
- type filter:access-list-standard;
- }
- }
- case access-list-num-extended {
- when "./condition = 'ipv4-address-list' or
- ./condition = 'ipv4-next-hop-list'";
- leaf access-list-num-extended {
- type filter:access-list-extended;
- }
- }
+
case list-name {
when "./condition = 'ipv4-address-list' or
./condition = 'ipv4-prefix-list' or
@@ -264,6 +264,7 @@ module frr-route-map {
type filter:access-list-name;
}
}
+
case ipv4-next-hop-type {
when "./condition = 'ipv4-next-hop-type'";
leaf ipv4-next-hop-type {
@@ -274,6 +275,7 @@ module frr-route-map {
}
}
}
+
case ipv6-next-hop-type {
when "./condition = 'ipv6-next-hop-type'";
leaf ipv6-next-hop-type {
@@ -284,6 +286,7 @@ module frr-route-map {
}
}
}
+
case metric {
when "./condition = 'metric'";
leaf metric {
@@ -292,6 +295,7 @@ module frr-route-map {
}
}
}
+
case tag {
when "./condition = 'tag'";
leaf tag {
@@ -304,32 +308,32 @@ module frr-route-map {
}
list set-action {
- description "Route map set actions";
+ description "Route map set actions.";
key "action";
leaf action {
- description "Action to do when the route map matches";
+ description "Action to do when the route map matches.";
type enumeration {
enum ipv4-next-hop {
- description "Set IPv4 address of the next hop";
+ description "Set IPv4 address of the next hop.";
value 0;
}
enum ipv6-next-hop {
- description "Set IPv6 address of the next hop";
+ description "Set IPv6 address of the next hop.";
value 1;
}
enum metric {
- description "Set prefix/route metric";
+ description "Set prefix/route metric.";
value 2;
}
enum tag {
- description "Set tag";
+ description "Set tag.";
value 3;
}
/* zebra specific conditions. */
enum source {
- description "Set source address for route";
+ description "Set source address for route.";
value 100;
}
}
@@ -337,69 +341,77 @@ module frr-route-map {
choice action-value {
description
- "Value to set (interpretation depends on action-type)";
+ "Value to set (interpretation depends on action-type).";
case ipv4-address {
when "./action = 'ipv4-next-hop'";
leaf ipv4-address {
- description "IPv4 address";
+ description "IPv4 address.";
type inet:ipv4-address;
}
}
+
case ipv6-address {
when "./action = 'ipv6-next-hop'";
leaf ipv6-address {
- description "IPv6 address";
+ description "IPv6 address.";
type inet:ipv6-address;
}
}
+
case metric {
when "./action = 'metric'";
choice metric-value {
- description "Metric to set or use";
+ description "Metric to set or use.";
case value {
leaf value {
- description "Use the following metric value";
+ description "Use the following metric value.";
type uint32 {
range "0..4294967295";
}
}
}
+
case add-metric {
leaf add-metric {
- description "Add unit to metric";
+ description "Add unit to metric.";
type boolean;
}
}
+
case subtract-metric {
leaf subtract-metric {
- description "Subtract unit from metric";
+ description "Subtract unit from metric.";
type boolean;
}
}
+
case use-round-trip-time {
leaf use-round-trip-time {
- description "Use the round trip time as metric";
+ description "Use the round trip time as metric.";
type boolean;
}
}
+
case add-round-trip-time {
leaf add-round-trip-time {
- description "Add round trip time to metric";
+ description "Add round trip time to metric.";
type boolean;
}
}
+
case subtract-round-trip-time {
leaf subtract-round-trip-time {
- description "Subtract round trip time to metric";
+ description "Subtract round trip time to metric.";
type boolean;
}
}
}
}
+
case tag {
when "./action = 'tag'";
leaf tag {
- description "Tag value";
+ description "Tag value.";
type uint32 {
range "0..4294967295";
}
diff --git a/yang/frr-routing.yang b/yang/frr-routing.yang
index 5a06e597e5..d22e12074f 100644
--- a/yang/frr-routing.yang
+++ b/yang/frr-routing.yang
@@ -72,6 +72,35 @@ module frr-routing {
"This identity represents an IPv6 address family.";
}
+ identity afi-safi-type {
+ description
+ "Base identity type (AFI,SAFI) tuples for RIB";
+ }
+
+ identity ipv4-unicast {
+ base afi-safi-type;
+ description
+ "This identity represents the IPv4 unicast address family.";
+ }
+
+ identity ipv6-unicast {
+ base afi-safi-type;
+ description
+ "This identity represents the IPv6 unicast address family.";
+ }
+
+ identity ipv4-multicast {
+ base afi-safi-type;
+ description
+ "This identity represents the IPv4 multicast address family.";
+ }
+
+ identity ipv6-multicast {
+ base afi-safi-type;
+ description
+ "This identity represents the IPv6 multicast address family.";
+ }
+
identity control-plane-protocol {
description
"Base identity from which control-plane protocol identities are
@@ -150,7 +179,7 @@ module frr-routing {
instance.";
}
leaf vrf {
- type frr-vrf:vrf-ref;
+ type string;
description
"vrf for control-plane protocol";
}
diff --git a/yang/frr-staticd.yang b/yang/frr-staticd.yang
index f59158a0fd..281b4903c0 100644
--- a/yang/frr-staticd.yang
+++ b/yang/frr-staticd.yang
@@ -1,11 +1,10 @@
module frr-staticd {
- yang-version "1.1";
+ yang-version 1.1;
namespace "http://frrouting.org/yang/staticd";
-
prefix frr-staticd;
import frr-routing {
- prefix "frr-rt";
+ prefix frr-rt;
}
import frr-nexthop {
@@ -18,11 +17,9 @@ module frr-staticd {
organization
"FRRouting";
-
contact
"FRR Users List: <mailto:frog@lists.frrouting.org>
FRR Development List: <mailto:dev@lists.frrouting.org>";
-
description
"This module defines a model for managing FRR staticd information.
This YANG module augments the ietf-routing with additional
@@ -58,52 +55,77 @@ module frr-staticd {
"Initial revision.";
}
- identity static {
+ identity staticd {
base frr-rt:routing-protocol;
description
- "'Static' routing pseudo-protocol.";
+ "'Staticd' routing pseudo-protocol.";
+ }
+
+ grouping staticd-prefix-attributes {
+ list path-list {
+ key "distance";
+ leaf distance {
+ type frr-rt:administrative-distance;
+ description
+ "Admin distance associated with this route.";
+ }
+
+ leaf tag {
+ type uint32;
+ default "0";
+ description
+ "Route tag";
+ }
+
+ leaf table-id {
+ type uint32;
+ default "0";
+ description
+ "Table-id";
+ }
+
+ uses frr-nexthop:frr-nexthop;
+ }
}
- augment "/frr-rt:routing/frr-rt:control-plane-protocols/"
- + "frr-rt:control-plane-protocol" {
+ augment "/frr-rt:routing/frr-rt:control-plane-protocols/frr-rt:control-plane-protocol" {
container staticd {
- when "../frr-rt:type = 'frr-staticd:static'" {
+ when "../frr-rt:type = 'frr-staticd:staticd'" {
description
- "This container is only valid for the 'static' routing
+ "This container is only valid for the 'staticd' routing
protocol.";
}
description
- "Support for a 'static' pseudo-protocol instance
- consists of a list of routes.";
-
- list prefix-list {
- key "destination-prefix";
+ "Support for a 'staticd' pseudo-protocol instance
+ consists of a list of routes.";
+ list route-list {
+ key "prefix afi-safi";
description
- "List of static IP routes.";
-
- leaf destination-prefix {
- type inet:ip-address;
+ "List of staticd IP routes.";
+ leaf prefix {
+ type inet:ip-prefix;
description
- "IP destination prefix.";
+ "IP prefix.";
}
-
- leaf distance {
- type frr-rt:administrative-distance;
+ leaf afi-safi {
+ type identityref {
+ base frr-rt:afi-safi-type;
+ }
description
- "Admin distance associated with this route.";
+ "AFI-SAFI type.";
}
- leaf tag {
- type uint32 {
- range "1..4294967295";
+ uses staticd-prefix-attributes;
+
+ list src-list {
+ key "src-prefix";
+ leaf src-prefix {
+ type inet:ipv6-prefix;
+ description
+ "IPv6 source prefix";
}
- description
- "Route tag";
- }
- container frr-staticd-next-hop {
- description
- "Augment static route configuration 'nexthop-list'.";
- uses frr-nexthop:frr-nexthop;
+
+ uses staticd-prefix-attributes;
}
}
}
diff --git a/yang/frr-zebra.yang b/yang/frr-zebra.yang
index 159dd8f791..7762c75d68 100644
--- a/yang/frr-zebra.yang
+++ b/yang/frr-zebra.yang
@@ -77,35 +77,6 @@ module frr-zebra {
"Initial revision.";
}
- identity afi-safi-type {
- description
- "Base identity type (AFI,SAFI) tuples for RIB";
- }
-
- identity ipv4-unicast {
- base afi-safi-type;
- description
- "This identity represents the IPv4 unicast address family.";
- }
-
- identity ipv6-unicast {
- base afi-safi-type;
- description
- "This identity represents the IPv6 unicast address family.";
- }
-
- identity ipv4-multicast {
- base afi-safi-type;
- description
- "This identity represents the IPv4 multicast address family.";
- }
-
- identity ipv6-multicast {
- base afi-safi-type;
- description
- "This identity represents the IPv6 multicast address family.";
- }
-
typedef unix-timestamp {
type uint32;
units "seconds";
@@ -634,7 +605,7 @@ module frr-zebra {
key "afi-safi-name table-id";
leaf afi-safi-name {
type identityref {
- base afi-safi-type;
+ base frr-rt:afi-safi-type;
}
description
"AFI, SAFI name.";
@@ -677,6 +648,23 @@ module frr-zebra {
}
}
+ grouping vrf-vni-mapping {
+ description
+ "EVPN L3-VNI mapping corresponding to a VRF.";
+ leaf l3vni-id {
+ type vni-id-type;
+ description
+ "EVPN L3-VNI id to map to the VRF.";
+ }
+
+ leaf prefix-only {
+ type boolean;
+ default "false";
+ description
+ "EVPN asymmetric mode advertise prefix routes only.";
+ }
+ }
+
// End of zebra container
/*
* RPCs
@@ -2070,7 +2058,11 @@ module frr-zebra {
description
"Extends VRF model with Zebra-related parameters.";
container zebra {
+ description
+ "Zebra's vrf specific configuration and operational model.";
uses ribs;
+
+ uses vrf-vni-mapping;
}
}
@@ -2173,26 +2165,6 @@ module frr-zebra {
description
"Limit on the number of updates queued to the dataplane subsystem.";
}
- list vrf-vni-mapping {
- key "vrf-id";
- description
- "EVPN VNI mapping corresponding to a VRF.";
- leaf vrf-id {
- type uint32;
- description
- "The identifier for a VRF.";
- }
- leaf vni-id {
- type vni-id-type;
- description
- "The VNI id to map to the VRF.";
- }
- leaf prefix-only {
- type empty;
- description
- "Prefix routes only.";
- }
- }
/*
* Debug options
*/
diff --git a/yang/subdir.am b/yang/subdir.am
index 6caf9fc5f3..6aae0e4701 100644
--- a/yang/subdir.am
+++ b/yang/subdir.am
@@ -29,10 +29,7 @@ dist_yangmodels_DATA += yang/frr-vrf.yang
dist_yangmodels_DATA += yang/frr-route-types.yang
dist_yangmodels_DATA += yang/frr-routing.yang
dist_yangmodels_DATA += yang/ietf/ietf-routing-types.yang
-dist_yangmodels_DATA += yang/frr-igmp.yang
dist_yangmodels_DATA += yang/ietf/ietf-interfaces.yang
-dist_yangmodels_DATA += yang/frr-pim.yang
-dist_yangmodels_DATA += yang/frr-pim-rp.yang
if BFDD
dist_yangmodels_DATA += yang/frr-bfdd.yang
@@ -65,3 +62,9 @@ endif
if ZEBRA
dist_yangmodels_DATA += yang/frr-zebra.yang
endif
+
+if PIMD
+dist_yangmodels_DATA += yang/frr-igmp.yang
+dist_yangmodels_DATA += yang/frr-pim.yang
+dist_yangmodels_DATA += yang/frr-pim-rp.yang
+endif
diff --git a/zebra/debug.c b/zebra/debug.c
index c920fca5ff..8c53ab73e4 100644
--- a/zebra/debug.c
+++ b/zebra/debug.c
@@ -40,6 +40,7 @@ unsigned long zebra_debug_pw;
unsigned long zebra_debug_dplane;
unsigned long zebra_debug_mlag;
unsigned long zebra_debug_nexthop;
+unsigned long zebra_debug_evpn_mh;
DEFINE_HOOK(zebra_debug_show_debugging, (struct vty *vty), (vty));
@@ -109,6 +110,18 @@ DEFUN_NOSH (show_debugging_zebra,
else if (IS_ZEBRA_DEBUG_NHG)
vty_out(vty, " Zebra nexthop debugging is on\n");
+ if (IS_ZEBRA_DEBUG_EVPN_MH_ES)
+ vty_out(vty, " Zebra EVPN-MH ethernet segment debugging is on\n");
+
+ if (IS_ZEBRA_DEBUG_EVPN_MH_NH)
+ vty_out(vty, " Zebra EVPN-MH nexthop debugging is on\n");
+
+ if (IS_ZEBRA_DEBUG_EVPN_MH_MAC)
+ vty_out(vty, " Zebra EVPN-MH MAC debugging is on\n");
+
+ if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH)
+ vty_out(vty, " Zebra EVPN-MH Neigh debugging is on\n");
+
hook_call(zebra_debug_show_debugging, vty);
return CMD_SUCCESS;
}
@@ -320,6 +333,53 @@ DEFPY (debug_zebra_mlag,
return CMD_SUCCESS;
}
+DEFPY (debug_zebra_evpn_mh,
+ debug_zebra_evpn_mh_cmd,
+ "[no$no] debug zebra evpn mh <es$es|mac$mac|neigh$neigh|nh$nh>",
+ NO_STR
+ DEBUG_STR
+ "Zebra configuration\n"
+ "EVPN\n"
+ "Multihoming\n"
+ "Ethernet Segment Debugging\n"
+ "MAC Debugging\n"
+ "Neigh Debugging\n"
+ "Nexthop Debugging\n")
+{
+ if (es) {
+ if (no)
+ UNSET_FLAG(zebra_debug_evpn_mh, ZEBRA_DEBUG_EVPN_MH_ES);
+ else
+ SET_FLAG(zebra_debug_evpn_mh, ZEBRA_DEBUG_EVPN_MH_ES);
+ }
+
+ if (mac) {
+ if (no)
+ UNSET_FLAG(zebra_debug_evpn_mh,
+ ZEBRA_DEBUG_EVPN_MH_MAC);
+ else
+ SET_FLAG(zebra_debug_evpn_mh, ZEBRA_DEBUG_EVPN_MH_MAC);
+ }
+
+ if (neigh) {
+ if (no)
+ UNSET_FLAG(zebra_debug_evpn_mh,
+ ZEBRA_DEBUG_EVPN_MH_NEIGH);
+ else
+ SET_FLAG(zebra_debug_evpn_mh,
+ ZEBRA_DEBUG_EVPN_MH_NEIGH);
+ }
+
+ if (nh) {
+ if (no)
+ UNSET_FLAG(zebra_debug_evpn_mh, ZEBRA_DEBUG_EVPN_MH_NH);
+ else
+ SET_FLAG(zebra_debug_evpn_mh, ZEBRA_DEBUG_EVPN_MH_NH);
+ }
+
+ return CMD_SUCCESS;
+}
+
DEFUN (no_debug_zebra_events,
no_debug_zebra_events_cmd,
"no debug zebra events",
@@ -553,6 +613,22 @@ static int config_write_debug(struct vty *vty)
vty_out(vty, "debug zebra mlag\n");
write++;
}
+ if (IS_ZEBRA_DEBUG_EVPN_MH_ES) {
+ vty_out(vty, "debug zebra evpn mh es\n");
+ write++;
+ }
+ if (IS_ZEBRA_DEBUG_EVPN_MH_NH) {
+ vty_out(vty, "debug zebra evpn mh nh\n");
+ write++;
+ }
+ if (IS_ZEBRA_DEBUG_EVPN_MH_MAC) {
+ vty_out(vty, "debug zebra evpn mh mac\n");
+ write++;
+ }
+ if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH) {
+ vty_out(vty, "debug zebra evpn mh neigh\n");
+ write++;
+ }
if (IS_ZEBRA_DEBUG_PW) {
vty_out(vty, "debug zebra pseudowires\n");
write++;
@@ -589,6 +665,7 @@ void zebra_debug_init(void)
zebra_debug_pw = 0;
zebra_debug_dplane = 0;
zebra_debug_mlag = 0;
+ zebra_debug_evpn_mh = 0;
zebra_debug_nht = 0;
zebra_debug_nexthop = 0;
@@ -619,6 +696,7 @@ void zebra_debug_init(void)
install_element(ENABLE_NODE, &no_debug_zebra_rib_cmd);
install_element(ENABLE_NODE, &no_debug_zebra_fpm_cmd);
install_element(ENABLE_NODE, &no_debug_zebra_dplane_cmd);
+ install_element(ENABLE_NODE, &debug_zebra_evpn_mh_cmd);
install_element(CONFIG_NODE, &debug_zebra_events_cmd);
install_element(CONFIG_NODE, &debug_zebra_nht_cmd);
@@ -643,4 +721,5 @@ void zebra_debug_init(void)
install_element(CONFIG_NODE, &no_debug_zebra_fpm_cmd);
install_element(CONFIG_NODE, &no_debug_zebra_dplane_cmd);
install_element(CONFIG_NODE, &debug_zebra_mlag_cmd);
+ install_element(CONFIG_NODE, &debug_zebra_evpn_mh_cmd);
}
diff --git a/zebra/debug.h b/zebra/debug.h
index e513f8865d..8402224f19 100644
--- a/zebra/debug.h
+++ b/zebra/debug.h
@@ -62,6 +62,11 @@ extern "C" {
#define ZEBRA_DEBUG_NHG 0x01
#define ZEBRA_DEBUG_NHG_DETAILED 0x02
+#define ZEBRA_DEBUG_EVPN_MH_ES 0x01
+#define ZEBRA_DEBUG_EVPN_MH_NH 0x02
+#define ZEBRA_DEBUG_EVPN_MH_MAC 0x04
+#define ZEBRA_DEBUG_EVPN_MH_NEIGH 0x08
+
/* Debug related macro. */
#define IS_ZEBRA_DEBUG_EVENT (zebra_debug_event & ZEBRA_DEBUG_EVENT)
@@ -100,6 +105,15 @@ extern "C" {
#define IS_ZEBRA_DEBUG_NHG_DETAIL \
(zebra_debug_nexthop & ZEBRA_DEBUG_NHG_DETAILED)
+#define IS_ZEBRA_DEBUG_EVPN_MH_ES \
+ (zebra_debug_evpn_mh & ZEBRA_DEBUG_EVPN_MH_ES)
+#define IS_ZEBRA_DEBUG_EVPN_MH_NH \
+ (zebra_debug_evpn_mh & ZEBRA_DEBUG_EVPN_MH_NH)
+#define IS_ZEBRA_DEBUG_EVPN_MH_MAC \
+ (zebra_debug_evpn_mh & ZEBRA_DEBUG_EVPN_MH_MAC)
+#define IS_ZEBRA_DEBUG_EVPN_MH_NEIGH \
+ (zebra_debug_evpn_mh & ZEBRA_DEBUG_EVPN_MH_NEIGH)
+
extern unsigned long zebra_debug_event;
extern unsigned long zebra_debug_packet;
extern unsigned long zebra_debug_kernel;
@@ -112,6 +126,7 @@ extern unsigned long zebra_debug_pw;
extern unsigned long zebra_debug_dplane;
extern unsigned long zebra_debug_mlag;
extern unsigned long zebra_debug_nexthop;
+extern unsigned long zebra_debug_evpn_mh;
extern void zebra_debug_init(void);
diff --git a/zebra/dplane_fpm_nl.c b/zebra/dplane_fpm_nl.c
index ef208bdc83..4165fa1b3a 100644
--- a/zebra/dplane_fpm_nl.c
+++ b/zebra/dplane_fpm_nl.c
@@ -72,6 +72,7 @@ struct fpm_nl_ctx {
int socket;
bool disabled;
bool connecting;
+ bool nhg_complete;
bool rib_complete;
bool rmac_complete;
bool use_nhg;
@@ -149,8 +150,25 @@ enum fpm_nl_events {
FNE_RESET_COUNTERS,
/* Toggle next hop group feature. */
FNE_TOGGLE_NHG,
+ /* Reconnect request by our own code to avoid races. */
+ FNE_INTERNAL_RECONNECT,
+
+ /* Next hop groups walk finished. */
+ FNE_NHG_FINISHED,
+ /* RIB walk finished. */
+ FNE_RIB_FINISHED,
+ /* RMAC walk finished. */
+ FNE_RMAC_FINISHED,
};
+#define FPM_RECONNECT(fnc) \
+ thread_add_event((fnc)->fthread->master, fpm_process_event, (fnc), \
+ FNE_INTERNAL_RECONNECT, &(fnc)->t_event)
+
+#define WALK_FINISH(fnc, ev) \
+ thread_add_event((fnc)->fthread->master, fpm_process_event, (fnc), \
+ (ev), NULL)
+
/*
* Prototypes.
*/
@@ -428,7 +446,18 @@ static int fpm_connect(struct thread *t);
static void fpm_reconnect(struct fpm_nl_ctx *fnc)
{
- /* Grab the lock to empty the stream and stop the zebra thread. */
+ /* Cancel all zebra threads first. */
+ thread_cancel_async(zrouter.master, &fnc->t_nhgreset, NULL);
+ thread_cancel_async(zrouter.master, &fnc->t_nhgwalk, NULL);
+ thread_cancel_async(zrouter.master, &fnc->t_ribreset, NULL);
+ thread_cancel_async(zrouter.master, &fnc->t_ribwalk, NULL);
+ thread_cancel_async(zrouter.master, &fnc->t_rmacreset, NULL);
+ thread_cancel_async(zrouter.master, &fnc->t_rmacwalk, NULL);
+
+ /*
+ * Grab the lock to empty the streams (data plane might try to
+ * enqueue updates while we are closing).
+ */
frr_mutex_lock_autounlock(&fnc->obuf_mutex);
/* Avoid calling close on `-1`. */
@@ -442,13 +471,6 @@ static void fpm_reconnect(struct fpm_nl_ctx *fnc)
THREAD_OFF(fnc->t_read);
THREAD_OFF(fnc->t_write);
- thread_cancel_async(zrouter.master, &fnc->t_nhgreset, NULL);
- thread_cancel_async(zrouter.master, &fnc->t_nhgwalk, NULL);
- thread_cancel_async(zrouter.master, &fnc->t_ribreset, NULL);
- thread_cancel_async(zrouter.master, &fnc->t_ribwalk, NULL);
- thread_cancel_async(zrouter.master, &fnc->t_rmacreset, NULL);
- thread_cancel_async(zrouter.master, &fnc->t_rmacwalk, NULL);
-
/* FPM is disabled, don't attempt to connect. */
if (fnc->disabled)
return;
@@ -465,6 +487,13 @@ static int fpm_read(struct thread *t)
/* Let's ignore the input at the moment. */
rv = stream_read_try(fnc->ibuf, fnc->socket,
STREAM_WRITEABLE(fnc->ibuf));
+ /* We've got an interruption. */
+ if (rv == -2) {
+ /* Schedule next read. */
+ thread_add_read(fnc->fthread->master, fpm_read, fnc,
+ fnc->socket, &fnc->t_read);
+ return 0;
+ }
if (rv == 0) {
atomic_fetch_add_explicit(&fnc->counters.connection_closes, 1,
memory_order_relaxed);
@@ -472,19 +501,15 @@ static int fpm_read(struct thread *t)
if (IS_ZEBRA_DEBUG_FPM)
zlog_debug("%s: connection closed", __func__);
- fpm_reconnect(fnc);
+ FPM_RECONNECT(fnc);
return 0;
}
if (rv == -1) {
- if (errno == EAGAIN || errno == EWOULDBLOCK
- || errno == EINTR)
- return 0;
-
atomic_fetch_add_explicit(&fnc->counters.connection_errors, 1,
memory_order_relaxed);
zlog_warn("%s: connection failure: %s", __func__,
strerror(errno));
- fpm_reconnect(fnc);
+ FPM_RECONNECT(fnc);
return 0;
}
stream_reset(fnc->ibuf);
@@ -525,33 +550,15 @@ static int fpm_write(struct thread *t)
&fnc->counters.connection_errors, 1,
memory_order_relaxed);
- fpm_reconnect(fnc);
+ FPM_RECONNECT(fnc);
return 0;
}
fnc->connecting = false;
- /*
- * Walk the route tables to send old information before starting
- * to send updated information.
- *
- * NOTE 1:
- * RIB table walk is called after the next group table walk
- * ends.
- *
- * NOTE 2:
- * Don't attempt to go through next hop group table if we were
- * explictly told to not use it.
- */
- if (fnc->use_nhg)
- thread_add_timer(zrouter.master, fpm_nhg_send, fnc, 0,
- &fnc->t_nhgwalk);
- else
- thread_add_timer(zrouter.master, fpm_rib_send, fnc, 0,
- &fnc->t_ribwalk);
-
- thread_add_timer(zrouter.master, fpm_rmac_send, fnc, 0,
- &fnc->t_rmacwalk);
+ /* Permit receiving messages now. */
+ thread_add_read(fnc->fthread->master, fpm_read, fnc,
+ fnc->socket, &fnc->t_read);
}
frr_mutex_lock_autounlock(&fnc->obuf_mutex);
@@ -589,8 +596,9 @@ static int fpm_write(struct thread *t)
memory_order_relaxed);
zlog_warn("%s: connection failure: %s", __func__,
strerror(errno));
- fpm_reconnect(fnc);
- break;
+
+ FPM_RECONNECT(fnc);
+ return 0;
}
/* Account all bytes sent. */
@@ -661,18 +669,19 @@ static int fpm_connect(struct thread *t)
fnc->connecting = (errno == EINPROGRESS);
fnc->socket = sock;
- thread_add_read(fnc->fthread->master, fpm_read, fnc, sock,
- &fnc->t_read);
+ if (!fnc->connecting)
+ thread_add_read(fnc->fthread->master, fpm_read, fnc, sock,
+ &fnc->t_read);
thread_add_write(fnc->fthread->master, fpm_write, fnc, sock,
&fnc->t_write);
/* Mark all routes as unsent. */
- thread_add_timer(zrouter.master, fpm_nhg_reset, fnc, 0,
- &fnc->t_nhgreset);
- thread_add_timer(zrouter.master, fpm_rib_reset, fnc, 0,
- &fnc->t_ribreset);
- thread_add_timer(zrouter.master, fpm_rmac_reset, fnc, 0,
- &fnc->t_rmacreset);
+ if (fnc->use_nhg)
+ thread_add_timer(zrouter.master, fpm_nhg_reset, fnc, 0,
+ &fnc->t_nhgreset);
+ else
+ thread_add_timer(zrouter.master, fpm_rib_reset, fnc, 0,
+ &fnc->t_ribreset);
return 0;
}
@@ -904,10 +913,11 @@ static int fpm_nhg_send(struct thread *t)
dplane_ctx_fini(&fna.ctx);
/* We are done sending next hops, lets install the routes now. */
- if (fna.complete)
- thread_add_timer(zrouter.master, fpm_rib_send, fnc, 0,
- &fnc->t_ribwalk);
- else /* Otherwise reschedule next hop group again. */
+ if (fna.complete) {
+ WALK_FINISH(fnc, FNE_NHG_FINISHED);
+ thread_add_timer(zrouter.master, fpm_rib_reset, fnc, 0,
+ &fnc->t_ribreset);
+ } else /* Otherwise reschedule next hop group again. */
thread_add_timer(zrouter.master, fpm_nhg_send, fnc, 0,
&fnc->t_nhgwalk);
@@ -963,7 +973,11 @@ static int fpm_rib_send(struct thread *t)
dplane_ctx_fini(&ctx);
/* All RIB routes sent! */
- fnc->rib_complete = true;
+ WALK_FINISH(fnc, FNE_RIB_FINISHED);
+
+ /* Schedule next event: RMAC reset. */
+ thread_add_event(zrouter.master, fpm_rmac_reset, fnc, 0,
+ &fnc->t_rmacreset);
return 0;
}
@@ -975,6 +989,7 @@ struct fpm_rmac_arg {
struct zebra_dplane_ctx *ctx;
struct fpm_nl_ctx *fnc;
zebra_l3vni_t *zl3vni;
+ bool complete;
};
static void fpm_enqueue_rmac_table(struct hash_bucket *backet, void *arg)
@@ -988,7 +1003,7 @@ static void fpm_enqueue_rmac_table(struct hash_bucket *backet, void *arg)
bool sticky;
/* Entry already sent. */
- if (CHECK_FLAG(zrmac->flags, ZEBRA_MAC_FPM_SENT))
+ if (CHECK_FLAG(zrmac->flags, ZEBRA_MAC_FPM_SENT) || !fra->complete)
return;
sticky = !!CHECK_FLAG(zrmac->flags,
@@ -1000,10 +1015,12 @@ static void fpm_enqueue_rmac_table(struct hash_bucket *backet, void *arg)
dplane_ctx_set_op(fra->ctx, DPLANE_OP_MAC_INSTALL);
dplane_mac_init(fra->ctx, fra->zl3vni->vxlan_if,
zif->brslave_info.br_if, vid,
- &zrmac->macaddr, zrmac->fwd_info.r_vtep_ip, sticky);
+ &zrmac->macaddr, zrmac->fwd_info.r_vtep_ip, sticky,
+ 0 /*nhg*/, 0 /*update_flags*/);
if (fpm_nl_enqueue(fra->fnc, fra->ctx) == -1) {
thread_add_timer(zrouter.master, fpm_rmac_send,
fra->fnc, 1, &fra->fnc->t_rmacwalk);
+ fra->complete = false;
}
}
@@ -1022,9 +1039,14 @@ static int fpm_rmac_send(struct thread *t)
fra.fnc = THREAD_ARG(t);
fra.ctx = dplane_ctx_alloc();
+ fra.complete = true;
hash_iterate(zrouter.l3vni_table, fpm_enqueue_l3vni_table, &fra);
dplane_ctx_fini(&fra.ctx);
+ /* RMAC walk completed. */
+ if (fra.complete)
+ WALK_FINISH(fra.fnc, FNE_RMAC_FINISHED);
+
return 0;
}
@@ -1041,7 +1063,14 @@ static void fpm_nhg_reset_cb(struct hash_bucket *bucket, void *arg)
static int fpm_nhg_reset(struct thread *t)
{
+ struct fpm_nl_ctx *fnc = THREAD_ARG(t);
+
+ fnc->nhg_complete = false;
hash_iterate(zrouter.nhgs_id, fpm_nhg_reset_cb, NULL);
+
+ /* Schedule next step: send next hop groups. */
+ thread_add_event(zrouter.master, fpm_nhg_send, fnc, 0, &fnc->t_nhgwalk);
+
return 0;
}
@@ -1070,6 +1099,9 @@ static int fpm_rib_reset(struct thread *t)
}
}
+ /* Schedule next step: send RIB routes. */
+ thread_add_event(zrouter.master, fpm_rib_send, fnc, 0, &fnc->t_ribwalk);
+
return 0;
}
@@ -1092,8 +1124,15 @@ static void fpm_unset_l3vni_table(struct hash_bucket *backet, void *arg)
static int fpm_rmac_reset(struct thread *t)
{
+ struct fpm_nl_ctx *fnc = THREAD_ARG(t);
+
+ fnc->rmac_complete = false;
hash_iterate(zrouter.l3vni_table, fpm_unset_l3vni_table, NULL);
+ /* Schedule next event: send RMAC entries. */
+ thread_add_event(zrouter.master, fpm_rmac_send, fnc, 0,
+ &fnc->t_rmacwalk);
+
return 0;
}
@@ -1174,6 +1213,30 @@ static int fpm_process_event(struct thread *t)
fpm_reconnect(fnc);
break;
+ case FNE_INTERNAL_RECONNECT:
+ fpm_reconnect(fnc);
+ break;
+
+ case FNE_NHG_FINISHED:
+ if (IS_ZEBRA_DEBUG_FPM)
+ zlog_debug("%s: next hop groups walk finished",
+ __func__);
+
+ fnc->nhg_complete = true;
+ break;
+ case FNE_RIB_FINISHED:
+ if (IS_ZEBRA_DEBUG_FPM)
+ zlog_debug("%s: RIB walk finished", __func__);
+
+ fnc->rib_complete = true;
+ break;
+ case FNE_RMAC_FINISHED:
+ if (IS_ZEBRA_DEBUG_FPM)
+ zlog_debug("%s: RMAC walk finished", __func__);
+
+ fnc->rmac_complete = true;
+ break;
+
default:
if (IS_ZEBRA_DEBUG_FPM)
zlog_debug("%s: unhandled event %d", __func__, event);
diff --git a/zebra/if_netlink.c b/zebra/if_netlink.c
index a15f932451..81f77d4f9b 100644
--- a/zebra/if_netlink.c
+++ b/zebra/if_netlink.c
@@ -70,6 +70,7 @@
#include "zebra/if_netlink.h"
#include "zebra/zebra_errors.h"
#include "zebra/zebra_vxlan.h"
+#include "zebra/zebra_evpn_mh.h"
extern struct zebra_privs_t zserv_privs;
@@ -245,6 +246,26 @@ static enum zebra_link_type netlink_to_zebra_link_type(unsigned int hwt)
}
}
+static inline void zebra_if_set_ziftype(struct interface *ifp,
+ zebra_iftype_t zif_type,
+ zebra_slave_iftype_t 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,
zebra_iftype_t *zif_type)
{
@@ -557,6 +578,74 @@ static void netlink_interface_update_l2info(struct interface *ifp,
}
}
+static int netlink_bridge_vxlan_update(struct interface *ifp,
+ struct rtattr *af_spec)
+{
+ struct rtattr *aftb[IFLA_BRIDGE_MAX + 1];
+ struct bridge_vlan_info *vinfo;
+ vlanid_t access_vlan;
+
+ /* There is a 1-to-1 mapping of VLAN to VxLAN - hence
+ * only 1 access VLAN is accepted.
+ */
+ memset(aftb, 0, sizeof(aftb));
+ parse_rtattr_nested(aftb, IFLA_BRIDGE_MAX, af_spec);
+ if (!aftb[IFLA_BRIDGE_VLAN_INFO])
+ return 0;
+
+ vinfo = RTA_DATA(aftb[IFLA_BRIDGE_VLAN_INFO]);
+ if (!(vinfo->flags & BRIDGE_VLAN_INFO_PVID))
+ return 0;
+
+ 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);
+ return 0;
+}
+
+static void netlink_bridge_vlan_update(struct interface *ifp,
+ 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);
+
+ 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;
+
+ zebra_vlan_bitmap_compute(ifp, vid_range_start, vinfo->vid);
+ }
+
+ zebra_vlan_mbr_re_eval(ifp, old_vlan_bitmap);
+
+ bf_free(old_vlan_bitmap);
+}
+
static int netlink_bridge_interface(struct nlmsghdr *h, int len, ns_id_t ns_id,
int startup)
{
@@ -564,12 +653,8 @@ static int netlink_bridge_interface(struct nlmsghdr *h, int len, ns_id_t ns_id,
struct ifinfomsg *ifi;
struct rtattr *tb[IFLA_MAX + 1];
struct interface *ifp;
- struct rtattr *aftb[IFLA_BRIDGE_MAX + 1];
- struct {
- uint16_t flags;
- uint16_t vid;
- } * vinfo;
- vlanid_t access_vlan;
+ struct zebra_if *zif;
+ struct rtattr *af_spec;
/* Fetch name and ifindex */
ifi = NLMSG_DATA(h);
@@ -587,30 +672,22 @@ static int netlink_bridge_interface(struct nlmsghdr *h, int len, ns_id_t ns_id,
ifi->ifi_index);
return 0;
}
- if (!IS_ZEBRA_IF_VXLAN(ifp))
- return 0;
/* We are only interested in the access VLAN i.e., AF_SPEC */
- if (!tb[IFLA_AF_SPEC])
- return 0;
+ af_spec = tb[IFLA_AF_SPEC];
+ if (!af_spec)
+ return 0;
- /* There is a 1-to-1 mapping of VLAN to VxLAN - hence
- * only 1 access VLAN is accepted.
- */
- memset(aftb, 0, sizeof(aftb));
- parse_rtattr_nested(aftb, IFLA_BRIDGE_MAX, tb[IFLA_AF_SPEC]);
- if (!aftb[IFLA_BRIDGE_VLAN_INFO])
- return 0;
+ if (IS_ZEBRA_IF_VXLAN(ifp))
+ return netlink_bridge_vxlan_update(ifp, af_spec);
- vinfo = RTA_DATA(aftb[IFLA_BRIDGE_VLAN_INFO]);
- if (!(vinfo->flags & BRIDGE_VLAN_INFO_PVID))
- return 0;
+ /* 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);
- access_vlan = (vlanid_t)vinfo->vid;
- if (IS_ZEBRA_DEBUG_KERNEL)
- zlog_debug("Access VLAN %u for VxLAN IF %s(%u)", access_vlan,
- name, ifi->ifi_index);
- zebra_l2_vxlanif_update_access_vlan(ifp, access_vlan);
return 0;
}
@@ -721,10 +798,8 @@ static int netlink_interface(struct nlmsghdr *h, ns_id_t ns_id, int startup)
if (tb[IFLA_LINK])
link_ifindex = *(ifindex_t *)RTA_DATA(tb[IFLA_LINK]);
- if (tb[IFLA_LINK_NETNSID]) {
+ 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);
- }
/* Add interface.
* We add by index first because in some cases such as the master
@@ -732,9 +807,11 @@ static int netlink_interface(struct nlmsghdr *h, ns_id_t ns_id, int startup)
* back references on the slave interfaces is painful if not done
* this way, i.e. by creating by ifindex.
*/
- ifp = if_get_by_ifindex(ifi->ifi_index, vrf_id, name);
+ ifp = if_get_by_ifindex(ifi->ifi_index, vrf_id);
set_ifindex(ifp, ifi->ifi_index, zns); /* add it to ns struct */
+ if_set_name(ifp, name);
+
ifp->flags = ifi->ifi_flags & 0x0000fffff;
ifp->mtu6 = ifp->mtu = *(uint32_t *)RTA_DATA(tb[IFLA_MTU]);
ifp->metric = 0;
@@ -771,7 +848,7 @@ static int netlink_interface(struct nlmsghdr *h, ns_id_t ns_id, int startup)
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_l2if_update_bridge_slave(ifp, bridge_ifindex);
else if (IS_ZEBRA_IF_BOND_SLAVE(ifp))
zebra_l2if_update_bond_slave(ifp, bond_ifindex);
@@ -1263,10 +1340,9 @@ int netlink_link_change(struct nlmsghdr *h, ns_id_t ns_id, int startup)
if (tb[IFLA_LINK])
link_ifindex = *(ifindex_t *)RTA_DATA(tb[IFLA_LINK]);
- if (tb[IFLA_LINK_NETNSID]) {
+ 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);
- }
+
if (tb[IFLA_IFALIAS]) {
desc = (char *)RTA_DATA(tb[IFLA_IFALIAS]);
}
@@ -1354,8 +1430,7 @@ int netlink_link_change(struct nlmsghdr *h, ns_id_t ns_id, int startup)
1, link_nsid);
if (IS_ZEBRA_IF_BRIDGE_SLAVE(ifp))
zebra_l2if_update_bridge_slave(ifp,
- bridge_ifindex,
- ns_id);
+ bridge_ifindex);
else if (IS_ZEBRA_IF_BOND_SLAVE(ifp))
zebra_l2if_update_bond_slave(ifp, bond_ifindex);
} else if (ifp->vrf_id != vrf_id) {
@@ -1456,8 +1531,7 @@ int netlink_link_change(struct nlmsghdr *h, ns_id_t ns_id, int startup)
0, link_nsid);
if (IS_ZEBRA_IF_BRIDGE_SLAVE(ifp) || was_bridge_slave)
zebra_l2if_update_bridge_slave(ifp,
- bridge_ifindex,
- ns_id);
+ bridge_ifindex);
else if (IS_ZEBRA_IF_BOND_SLAVE(ifp) || was_bond_slave)
zebra_l2if_update_bond_slave(ifp, bond_ifindex);
}
diff --git a/zebra/interface.c b/zebra/interface.c
index 53ae1d2089..b824e313ec 100644
--- a/zebra/interface.c
+++ b/zebra/interface.c
@@ -51,6 +51,7 @@
#include "zebra/interface.h"
#include "zebra/zebra_vxlan.h"
#include "zebra/zebra_errors.h"
+#include "zebra/zebra_evpn_mh.h"
DEFINE_MTYPE_STATIC(ZEBRA, ZINFO, "Zebra Interface Information")
@@ -127,6 +128,7 @@ static int if_zebra_new_hook(struct interface *ifp)
struct zebra_if *zebra_if;
zebra_if = XCALLOC(MTYPE_ZINFO, sizeof(struct zebra_if));
+ zebra_if->ifp = ifp;
zebra_if->multicast = IF_ZEBRA_MULTICAST_UNSPEC;
zebra_if->shutdown = IF_ZEBRA_SHUTDOWN_OFF;
@@ -238,6 +240,8 @@ static int if_zebra_delete_hook(struct interface *ifp)
list_delete(&rtadv->AdvDNSSLList);
#endif /* HAVE_RTADV */
+ zebra_evpn_if_cleanup(zebra_if);
+
if_nhg_dependents_release(ifp);
zebra_if_nhg_dependents_free(zebra_if);
@@ -831,6 +835,7 @@ void if_delete_update(struct interface *ifp)
memset(&zif->l2info, 0, sizeof(union zebra_l2if_info));
memset(&zif->brslave_info, 0,
sizeof(struct zebra_l2info_brslave));
+ zebra_evpn_if_cleanup(zif);
}
if (!ifp->configured) {
@@ -1072,6 +1077,8 @@ void if_up(struct interface *ifp)
} else if (IS_ZEBRA_IF_MACVLAN(ifp))
zebra_vxlan_macvlan_up(ifp);
+ if (zif->es_info.es)
+ zebra_evpn_es_if_oper_state_change(zif, true /*up*/);
}
/* Interface goes down. We have to manage different behavior of based
@@ -1106,6 +1113,8 @@ void if_down(struct interface *ifp)
} else if (IS_ZEBRA_IF_MACVLAN(ifp))
zebra_vxlan_macvlan_down(ifp);
+ if (zif->es_info.es)
+ zebra_evpn_es_if_oper_state_change(zif, false /*up*/);
/* Notify to the protocol daemons. */
zebra_interface_down_update(ifp);
@@ -1233,23 +1242,6 @@ static void nbr_connected_dump_vty(struct vty *vty,
vty_out(vty, "\n");
}
-static const char *zebra_zifslavetype_2str(zebra_slave_iftype_t zif_slave_type)
-{
- switch (zif_slave_type) {
- case ZEBRA_IF_SLAVE_BRIDGE:
- return "Bridge";
- case ZEBRA_IF_SLAVE_VRF:
- return "Vrf";
- case ZEBRA_IF_SLAVE_BOND:
- return "Bond";
- case ZEBRA_IF_SLAVE_OTHER:
- return "Other";
- case ZEBRA_IF_SLAVE_NONE:
- return "None";
- }
- return "None";
-}
-
static const char *zebra_ziftype_2str(zebra_iftype_t zif_type)
{
switch (zif_type) {
@@ -1477,9 +1469,6 @@ static void if_dump_vty(struct vty *vty, struct interface *ifp)
vty_out(vty, " Interface Type %s\n",
zebra_ziftype_2str(zebra_if->zif_type));
- vty_out(vty, " Interface Slave Type %s\n",
- zebra_zifslavetype_2str(zebra_if->zif_slave_type));
-
if (IS_ZEBRA_IF_BRIDGE(ifp)) {
struct zebra_l2info_bridge *bridge_info;
@@ -1547,6 +1536,8 @@ static void if_dump_vty(struct vty *vty, struct interface *ifp)
}
}
+ zebra_evpn_if_es_print(vty, zebra_if);
+
if (zebra_if->link_ifindex != IFINDEX_INTERNAL) {
if (zebra_if->link)
vty_out(vty, " Parent interface: %s\n", zebra_if->link->name);
@@ -3588,7 +3579,7 @@ static int if_config_write(struct vty *vty)
}
hook_call(zebra_if_config_wr, vty, ifp);
-
+ zebra_evpn_mh_if_write(vty, ifp);
link_params_config_write(vty, ifp);
vty_endframe(vty, "!\n");
@@ -3664,4 +3655,7 @@ void zebra_if_init(void)
install_element(LINK_PARAMS_NODE, &link_params_use_bw_cmd);
install_element(LINK_PARAMS_NODE, &no_link_params_use_bw_cmd);
install_element(LINK_PARAMS_NODE, &exit_link_params_cmd);
+
+ /* setup EVPN MH elements */
+ zebra_evpn_interface_init();
}
diff --git a/zebra/interface.h b/zebra/interface.h
index 2dad0c3bb2..1a8e3caed5 100644
--- a/zebra/interface.h
+++ b/zebra/interface.h
@@ -25,6 +25,7 @@
#include "redistribute.h"
#include "vrf.h"
#include "hook.h"
+#include "bitfield.h"
#include "zebra/zebra_l2.h"
#include "zebra/zebra_nhg_private.h"
@@ -42,6 +43,8 @@ extern "C" {
#define IF_ZEBRA_SHUTDOWN_OFF 0
#define IF_ZEBRA_SHUTDOWN_ON 1
+#define IF_VLAN_BITMAP_MAX 4096
+
#if defined(HAVE_RTADV)
/* Router advertisement parameter. From RFC4861, RFC6275 and RFC4191. */
struct rtadvconf {
@@ -272,8 +275,19 @@ typedef enum {
struct irdp_interface;
+/* Ethernet segment info used for setting up EVPN multihoming */
+struct zebra_evpn_es;
+struct zebra_es_if_info {
+ struct ethaddr sysmac;
+ uint32_t lid; /* local-id; has to be unique per-ES-sysmac */
+ struct zebra_evpn_es *es; /* local ES */
+};
+
/* `zebra' daemon local interface structure. */
struct zebra_if {
+ /* back pointer to the interface */
+ struct interface *ifp;
+
/* Shutdown configuration. */
uint8_t shutdown;
@@ -347,6 +361,12 @@ struct zebra_if {
struct zebra_l2info_bondslave bondslave_info;
+ /* ethernet segment */
+ struct zebra_es_if_info es_info;
+
+ /* bitmap of vlans associated with this interface */
+ bitfield_t vlan_bitmap;
+
/* Link fields - for sub-interfaces. */
ifindex_t link_ifindex;
struct interface *link;
@@ -370,17 +390,6 @@ DECLARE_HOOK(zebra_if_extra_info, (struct vty * vty, struct interface *ifp),
DECLARE_HOOK(zebra_if_config_wr, (struct vty * vty, struct interface *ifp),
(vty, ifp))
-static inline void zebra_if_set_ziftype(struct interface *ifp,
- zebra_iftype_t zif_type,
- zebra_slave_iftype_t zif_slave_type)
-{
- struct zebra_if *zif;
-
- zif = (struct zebra_if *)ifp->info;
- zif->zif_type = zif_type;
- zif->zif_slave_type = zif_slave_type;
-}
-
#define IS_ZEBRA_IF_VRF(ifp) \
(((struct zebra_if *)(ifp->info))->zif_type == ZEBRA_IF_VRF)
diff --git a/zebra/main.c b/zebra/main.c
index b109c7bcc6..92e94c2a2a 100644
--- a/zebra/main.c
+++ b/zebra/main.c
@@ -35,6 +35,7 @@
#include "vrf.h"
#include "libfrr.h"
#include "routemap.h"
+#include "routing_nb.h"
#include "zebra/zebra_router.h"
#include "zebra/zebra_errors.h"
@@ -185,7 +186,7 @@ static void sigint(void)
vrf_terminate();
rtadv_terminate();
- ns_walk_func(zebra_ns_early_shutdown, NULL, NULL);
+ ns_walk_func(zebra_ns_early_shutdown);
zebra_ns_notify_close();
access_list_reset();
@@ -216,7 +217,7 @@ int zebra_finalize(struct thread *dummy)
zlog_info("Zebra final shutdown");
/* Final shutdown of ns resources */
- ns_walk_func(zebra_ns_final_shutdown, NULL, NULL);
+ ns_walk_func(zebra_ns_final_shutdown);
/* Stop dplane thread and finish any cleanup */
zebra_dplane_shutdown();
@@ -258,6 +259,7 @@ static const struct frr_yang_module_info *const zebra_yang_modules[] = {
&frr_route_map_info,
&frr_zebra_info,
&frr_vrf_info,
+ &frr_routing_info,
};
FRR_DAEMON_INFO(
diff --git a/zebra/rib.h b/zebra/rib.h
index ec992974fa..b9f4e56905 100644
--- a/zebra/rib.h
+++ b/zebra/rib.h
@@ -144,6 +144,10 @@ struct route_entry {
#define ROUTE_ENTRY_INSTALLED 0x10
/* Route has Failed installation into the Data Plane in some manner */
#define ROUTE_ENTRY_FAILED 0x20
+/* Route has a 'fib' set of nexthops, probably because the installed set
+ * differs from the rib/normal set of nexthops.
+ */
+#define ROUTE_ENTRY_USE_FIB_NHG 0x40
/* Sequence value incremented for each dataplane operation */
uint32_t dplane_sequence;
@@ -296,6 +300,7 @@ struct rib_table_info {
struct zebra_vrf *zvrf;
afi_t afi;
safi_t safi;
+ uint32_t table_id;
};
enum rib_tables_iter_state {
@@ -526,26 +531,28 @@ DECLARE_HOOK(rib_update, (struct route_node * rn, const char *reason),
(rn, reason))
/*
- * Access active nexthop-group, either RIB or FIB version
+ * Access installed/fib nexthops, which may be a subset of the
+ * rib nexthops.
*/
static inline struct nexthop_group *rib_get_fib_nhg(struct route_entry *re)
{
- if (re->fib_ng.nexthop)
+ /* If the fib set is a subset of the active rib set,
+ * use the dedicated fib list.
+ */
+ if (CHECK_FLAG(re->status, ROUTE_ENTRY_USE_FIB_NHG))
return &(re->fib_ng);
else
return &(re->nhe->nhg);
}
/*
- * Access active nexthop-group, either RIB or FIB version
+ * Access backup nexthop-group that represents the installed backup nexthops;
+ * any installed backup will be on the fib list.
*/
static inline struct nexthop_group *rib_get_fib_backup_nhg(
struct route_entry *re)
{
- if (re->fib_backup_ng.nexthop)
- return &(re->fib_backup_ng);
- else
- return zebra_nhg_get_backup_nhg(re->nhe);
+ return &(re->fib_backup_ng);
}
extern void zebra_vty_init(void);
diff --git a/zebra/rt.h b/zebra/rt.h
index 4b9a3f83fe..143e16b3ea 100644
--- a/zebra/rt.h
+++ b/zebra/rt.h
@@ -91,6 +91,11 @@ extern void neigh_read_for_vlan(struct zebra_ns *zns, struct interface *ifp);
extern void neigh_read_specific_ip(struct ipaddr *ip,
struct interface *vlan_if);
extern void route_read(struct zebra_ns *zns);
+extern int kernel_upd_mac_nh(uint32_t nh_id, struct in_addr vtep_ip);
+extern int kernel_del_mac_nh(uint32_t nh_id);
+extern int kernel_upd_mac_nhg(uint32_t nhg_id, uint32_t nh_cnt,
+ struct nh_grp *nh_ids);
+extern int kernel_del_mac_nhg(uint32_t nhg_id);
#ifdef __cplusplus
}
diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c
index 07e8e37b82..4daef42d7a 100644
--- a/zebra/rt_netlink.c
+++ b/zebra/rt_netlink.c
@@ -68,11 +68,27 @@
#include "zebra/zebra_mroute.h"
#include "zebra/zebra_vxlan.h"
#include "zebra/zebra_errors.h"
+#include "zebra/zebra_evpn_mh.h"
#ifndef AF_MPLS
#define AF_MPLS 28
#endif
+/* Re-defining as I am unable to include <linux/if_bridge.h> which has the
+ * UAPI for MAC sync. */
+#ifndef _UAPI_LINUX_IF_BRIDGE_H
+/* FDB notification bits for NDA_NOTIFY:
+ * - BR_FDB_NFY_STATIC - notify on activity/expire even for a static entry
+ * - BR_FDB_NFY_INACTIVE - mark as inactive to avoid double notification,
+ * used with BR_FDB_NFY_STATIC (kernel controlled)
+ */
+enum {
+ BR_FDB_NFY_STATIC,
+ BR_FDB_NFY_INACTIVE,
+ BR_FDB_NFY_MAX
+};
+#endif
+
static vlanid_t filter_vlan = 0;
/* We capture whether the current kernel supports nexthop ids; by
@@ -1051,14 +1067,17 @@ static bool _netlink_route_add_gateway_info(uint8_t route_family,
bytelen + 2))
return false;
} else {
- if (gw_family == AF_INET) {
- if (!nl_attr_put(nlmsg, req_size, RTA_GATEWAY,
- &nexthop->gate.ipv4, bytelen))
- return false;
- } else {
- if (!nl_attr_put(nlmsg, req_size, RTA_GATEWAY,
- &nexthop->gate.ipv6, bytelen))
- return false;
+ if (!(nexthop->rparent
+ && IS_MAPPED_IPV6(&nexthop->rparent->gate.ipv6))) {
+ if (gw_family == AF_INET) {
+ if (!nl_attr_put(nlmsg, req_size, RTA_GATEWAY,
+ &nexthop->gate.ipv4, bytelen))
+ return false;
+ } else {
+ if (!nl_attr_put(nlmsg, req_size, RTA_GATEWAY,
+ &nexthop->gate.ipv6, bytelen))
+ return false;
+ }
}
}
@@ -2518,6 +2537,15 @@ int netlink_nexthop_change(struct nlmsghdr *h, ns_id_t ns_id, int startup)
/* We use the ID key'd nhg table for kernel updates */
id = *((uint32_t *)RTA_DATA(tb[NHA_ID]));
+ if (zebra_evpn_mh_is_fdb_nh(id)) {
+ /* If this is a L2 NH just ignore it */
+ if (IS_ZEBRA_DEBUG_KERNEL || IS_ZEBRA_DEBUG_EVPN_MH_NH) {
+ zlog_debug("Ignore kernel update (%u) for fdb-nh 0x%x",
+ h->nlmsg_type, id);
+ }
+ return 0;
+ }
+
family = nhm->nh_family;
afi = family2afi(family);
@@ -2673,7 +2701,9 @@ int kernel_neigh_update(int add, int ifindex, uint32_t addr, char *lla,
static ssize_t netlink_neigh_update_msg_encode(
const struct zebra_dplane_ctx *ctx, int cmd, const struct ethaddr *mac,
const struct ipaddr *ip, bool replace_obj, uint8_t family, uint8_t type,
- uint8_t flags, uint16_t state, void *data, size_t datalen)
+ uint8_t flags, uint16_t state, uint32_t nhg_id,
+ bool nfy, uint8_t nfy_flags,
+ void *data, size_t datalen)
{
uint8_t protocol = RTPROT_ZEBRA;
struct {
@@ -2712,6 +2742,16 @@ static ssize_t netlink_neigh_update_msg_encode(
return 0;
}
+ if (nhg_id) {
+ if (!nl_attr_put32(&req->n, datalen, NDA_NH_ID, nhg_id))
+ return 0;
+ }
+ if (nfy) {
+ if (!nl_attr_put(&req->n, datalen, NDA_NOTIFY,
+ &nfy_flags, sizeof(nfy_flags)))
+ return 0;
+ }
+
ipa_len = IS_IPADDR_V4(ip) ? IPV4_MAX_BYTELEN : IPV6_MAX_BYTELEN;
if (!nl_attr_put(&req->n, datalen, NDA_DST, &ip->ip.addr, ipa_len))
return 0;
@@ -2744,8 +2784,9 @@ static int netlink_vxlan_flood_update_ctx(const struct zebra_dplane_ctx *ctx,
if (netlink_neigh_update_msg_encode(
ctx, cmd, &dst_mac, dplane_ctx_neigh_get_ipaddr(ctx), false,
- PF_BRIDGE, 0, NTF_SELF, (NUD_NOARP | NUD_PERMANENT), nl_pkt,
- sizeof(nl_pkt))
+ PF_BRIDGE, 0, NTF_SELF, (NUD_NOARP | NUD_PERMANENT),
+ 0 /*nhg*/, false /*nfy*/, 0 /*nfy_flags*/,
+ nl_pkt, sizeof(nl_pkt))
<= 0)
return -1;
@@ -2774,6 +2815,9 @@ static int netlink_macfdb_change(struct nlmsghdr *h, int len, ns_id_t ns_id)
char vid_buf[20];
char dst_buf[30];
bool sticky;
+ bool local_inactive = false;
+ bool dp_static = false;
+ uint32_t nhg_id = 0;
ndm = NLMSG_DATA(h);
@@ -2821,13 +2865,29 @@ static int netlink_macfdb_change(struct nlmsghdr *h, int len, ns_id_t ns_id)
inet_ntoa(vtep_ip));
}
+ if (tb[NDA_NH_ID])
+ nhg_id = *(uint32_t *)RTA_DATA(tb[NDA_NH_ID]);
+
+ if (ndm->ndm_state & NUD_STALE)
+ local_inactive = true;
+
+ if (tb[NDA_NOTIFY]) {
+ uint8_t nfy_flags;
+
+ dp_static = true;
+ nfy_flags = *(uint8_t *)RTA_DATA(tb[NDA_NOTIFY]);
+ /* local activity has not been detected on the entry */
+ if (nfy_flags & (1 << BR_FDB_NFY_INACTIVE))
+ local_inactive = true;
+ }
+
if (IS_ZEBRA_DEBUG_KERNEL)
- zlog_debug("Rx %s AF_BRIDGE IF %u%s st 0x%x fl 0x%x MAC %s%s",
+ zlog_debug("Rx %s AF_BRIDGE IF %u%s st 0x%x fl 0x%x MAC %s%s nhg %d",
nl_msg_type_to_str(h->nlmsg_type),
ndm->ndm_ifindex, vid_present ? vid_buf : "",
ndm->ndm_state, ndm->ndm_flags,
prefix_mac2str(&mac, buf, sizeof(buf)),
- dst_present ? dst_buf : "");
+ dst_present ? dst_buf : "", nhg_id);
/* The interface should exist. */
ifp = if_lookup_by_index_per_ns(zebra_ns_lookup(ns_id),
@@ -2850,7 +2910,7 @@ static int netlink_macfdb_change(struct nlmsghdr *h, int len, ns_id_t ns_id)
return 0;
}
- sticky = !!(ndm->ndm_state & NUD_NOARP);
+ sticky = !!(ndm->ndm_flags & NTF_STICKY);
if (filter_vlan && vid != filter_vlan) {
if (IS_ZEBRA_DEBUG_KERNEL)
@@ -2878,7 +2938,7 @@ static int netlink_macfdb_change(struct nlmsghdr *h, int len, ns_id_t ns_id)
vid);
return zebra_vxlan_local_mac_add_update(ifp, br_if, &mac, vid,
- sticky);
+ sticky, local_inactive, dp_static);
}
/* This is a delete notification.
@@ -2891,6 +2951,9 @@ static int netlink_macfdb_change(struct nlmsghdr *h, int len, ns_id_t ns_id)
* Note: We will get notifications from both bridge driver and VxLAN
* driver.
*/
+ if (nhg_id)
+ return 0;
+
if (dst_present) {
u_char zero_mac[6] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
@@ -3088,18 +3151,43 @@ netlink_macfdb_update_ctx(struct zebra_dplane_ctx *ctx, uint8_t *data,
int cmd;
uint8_t flags;
uint16_t state;
+ uint32_t nhg_id;
+ uint32_t update_flags;
+ bool nfy = false;
+ uint8_t nfy_flags = 0;
cmd = dplane_ctx_get_op(ctx) == DPLANE_OP_MAC_INSTALL
? RTM_NEWNEIGH : RTM_DELNEIGH;
- flags = (NTF_SELF | NTF_MASTER);
+ flags = NTF_MASTER;
state = NUD_REACHABLE;
- if (dplane_ctx_mac_is_sticky(ctx))
- state |= NUD_NOARP;
- else
- flags |= NTF_EXT_LEARNED;
+ update_flags = dplane_ctx_mac_get_update_flags(ctx);
+ if (update_flags & DPLANE_MAC_REMOTE) {
+ flags |= NTF_SELF;
+ if (dplane_ctx_mac_is_sticky(ctx))
+ flags |= NTF_STICKY;
+ else
+ flags |= NTF_EXT_LEARNED;
+ /* if it was static-local previously we need to clear the
+ * notify flags on replace with remote
+ */
+ if (update_flags & DPLANE_MAC_WAS_STATIC)
+ nfy = true;
+ } else {
+ /* local mac */
+ if (update_flags & DPLANE_MAC_SET_STATIC) {
+ nfy_flags |= (1 << BR_FDB_NFY_STATIC);
+ state |= NUD_NOARP;
+ }
+
+ if (update_flags & DPLANE_MAC_SET_INACTIVE)
+ nfy_flags |= (1 << BR_FDB_NFY_INACTIVE);
+
+ nfy = true;
+ }
+ nhg_id = dplane_ctx_mac_get_nhg_id(ctx);
vtep_ip.ipaddr_v4 = *(dplane_ctx_mac_get_vtep_ip(ctx));
SET_IPADDR_V4(&vtep_ip);
@@ -3107,6 +3195,7 @@ netlink_macfdb_update_ctx(struct zebra_dplane_ctx *ctx, uint8_t *data,
char ipbuf[PREFIX_STRLEN];
char buf[ETHER_ADDR_STRLEN];
char vid_buf[20];
+ const struct ethaddr *mac = dplane_ctx_mac_get_addr(ctx);
vid = dplane_ctx_mac_get_vlan(ctx);
if (vid > 0)
@@ -3114,20 +3203,30 @@ netlink_macfdb_update_ctx(struct zebra_dplane_ctx *ctx, uint8_t *data,
else
vid_buf[0] = '\0';
- const struct ethaddr *mac = dplane_ctx_mac_get_addr(ctx);
-
- zlog_debug("Tx %s family %s IF %s(%u)%s %sMAC %s dst %s",
+ zlog_debug("Tx %s family %s IF %s(%u)%s %sMAC %s dst %s nhg %u%s%s%s%s%s",
nl_msg_type_to_str(cmd), nl_family_to_str(AF_BRIDGE),
dplane_ctx_get_ifname(ctx),
dplane_ctx_get_ifindex(ctx), vid_buf,
dplane_ctx_mac_is_sticky(ctx) ? "sticky " : "",
prefix_mac2str(mac, buf, sizeof(buf)),
- ipaddr2str(&vtep_ip, ipbuf, sizeof(ipbuf)));
+ ipaddr2str(&vtep_ip, ipbuf, sizeof(ipbuf)),
+ nhg_id,
+ (update_flags &
+ DPLANE_MAC_REMOTE) ? " rem" : "",
+ (update_flags &
+ DPLANE_MAC_WAS_STATIC) ? " clr_sync" : "",
+ (update_flags &
+ DPLANE_MAC_SET_STATIC) ? " static" : "",
+ (update_flags &
+ DPLANE_MAC_SET_INACTIVE) ? " inactive" : "",
+ (nfy &
+ DPLANE_MAC_SET_INACTIVE) ? " nfy" : "");
}
total = netlink_neigh_update_msg_encode(
ctx, cmd, dplane_ctx_mac_get_addr(ctx), &vtep_ip, true,
- AF_BRIDGE, 0, flags, state, data, datalen);
+ AF_BRIDGE, 0, flags, state, nhg_id, nfy, nfy_flags,
+ data, datalen);
return total;
}
@@ -3161,6 +3260,8 @@ static void netlink_handle_5549(struct ndmsg *ndm, struct zebra_if *zif,
#define NUD_VALID \
(NUD_PERMANENT | NUD_NOARP | NUD_REACHABLE | NUD_PROBE | NUD_STALE \
| NUD_DELAY)
+#define NUD_LOCAL_ACTIVE \
+ (NUD_PERMANENT | NUD_NOARP | NUD_REACHABLE)
static int netlink_ipneigh_change(struct nlmsghdr *h, int len, ns_id_t ns_id)
{
@@ -3177,6 +3278,7 @@ static int netlink_ipneigh_change(struct nlmsghdr *h, int len, ns_id_t ns_id)
int mac_present = 0;
bool is_ext;
bool is_router;
+ bool local_inactive;
ndm = NLMSG_DATA(h);
@@ -3286,10 +3388,17 @@ static int netlink_ipneigh_change(struct nlmsghdr *h, int len, ns_id_t ns_id)
* result
* in re-adding the neighbor if it is a valid "remote" neighbor.
*/
- if (ndm->ndm_state & NUD_VALID)
+ if (ndm->ndm_state & NUD_VALID) {
+ local_inactive = !(ndm->ndm_state & NUD_LOCAL_ACTIVE);
+
+ /* XXX - populate dp-static based on the sync flags
+ * in the kernel
+ */
return zebra_vxlan_handle_kernel_neigh_update(
ifp, link_if, &ip, &mac, ndm->ndm_state,
- is_ext, is_router);
+ is_ext, is_router, local_inactive,
+ false /* dp_static */);
+ }
return zebra_vxlan_handle_kernel_neigh_del(ifp, link_if, &ip);
}
@@ -3544,8 +3653,9 @@ static int netlink_neigh_update_ctx(const struct zebra_dplane_ctx *ctx,
}
if (netlink_neigh_update_msg_encode(ctx, cmd, mac, ip, true, family,
- RTN_UNICAST, flags, state, nl_pkt,
- sizeof(nl_pkt))
+ RTN_UNICAST, flags, state,
+ 0 /*nhg*/, false /*nfy*/, 0 /*nfy_flags*/,
+ nl_pkt, sizeof(nl_pkt))
<= 0)
return -1;
@@ -3754,4 +3864,172 @@ ssize_t netlink_mpls_multipath_msg_encode(int cmd, struct zebra_dplane_ctx *ctx,
return NLMSG_ALIGN(req->n.nlmsg_len);
}
+
+/****************************************************************************
+* This code was developed in a branch that didn't have dplane APIs for
+* MAC updates. Hence the use of the legacy style. It will be moved to
+* the new dplane style pre-merge to master. XXX
+*/
+static int netlink_fdb_nh_update(uint32_t nh_id, struct in_addr vtep_ip)
+{
+ struct {
+ struct nlmsghdr n;
+ struct nhmsg nhm;
+ char buf[256];
+ } req;
+ int cmd = RTM_NEWNEXTHOP;
+ struct zebra_vrf *zvrf;
+ struct zebra_ns *zns;
+
+ zvrf = zebra_vrf_get_evpn();
+ if (!zvrf)
+ return -1;
+ zns = zvrf->zns;
+
+ memset(&req, 0, sizeof(req));
+
+ req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct nhmsg));
+ req.n.nlmsg_flags = NLM_F_REQUEST;
+ req.n.nlmsg_flags |= (NLM_F_CREATE | NLM_F_REPLACE);
+ req.n.nlmsg_type = cmd;
+ req.nhm.nh_family = AF_INET;
+
+ if (!nl_attr_put32(&req.n, sizeof(req), NHA_ID, nh_id))
+ return -1;
+ if (!nl_attr_put(&req.n, sizeof(req), NHA_FDB, NULL, 0))
+ return -1;
+ if (!nl_attr_put(&req.n, sizeof(req), NHA_GATEWAY,
+ &vtep_ip, IPV4_MAX_BYTELEN))
+ return -1;
+
+ if (IS_ZEBRA_DEBUG_KERNEL || IS_ZEBRA_DEBUG_EVPN_MH_NH) {
+ zlog_debug("Tx %s fdb-nh 0x%x %s",
+ nl_msg_type_to_str(cmd), nh_id, inet_ntoa(vtep_ip));
+ }
+
+ return netlink_talk(netlink_talk_filter, &req.n, &zns->netlink_cmd, zns,
+ 0);
+}
+
+static int netlink_fdb_nh_del(uint32_t nh_id)
+{
+ struct {
+ struct nlmsghdr n;
+ struct nhmsg nhm;
+ char buf[256];
+ } req;
+ int cmd = RTM_DELNEXTHOP;
+ struct zebra_vrf *zvrf;
+ struct zebra_ns *zns;
+
+ zvrf = zebra_vrf_get_evpn();
+ if (!zvrf)
+ return -1;
+ zns = zvrf->zns;
+
+ memset(&req, 0, sizeof(req));
+
+ req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct nhmsg));
+ req.n.nlmsg_flags = NLM_F_REQUEST;
+ req.n.nlmsg_type = cmd;
+ req.nhm.nh_family = AF_UNSPEC;
+
+ if (!nl_attr_put32(&req.n, sizeof(req), NHA_ID, nh_id))
+ return -1;
+
+ if (IS_ZEBRA_DEBUG_KERNEL || IS_ZEBRA_DEBUG_EVPN_MH_NH) {
+ zlog_debug("Tx %s fdb-nh 0x%x",
+ nl_msg_type_to_str(cmd), nh_id);
+ }
+
+ return netlink_talk(netlink_talk_filter, &req.n, &zns->netlink_cmd, zns,
+ 0);
+}
+
+static int netlink_fdb_nhg_update(uint32_t nhg_id, uint32_t nh_cnt,
+ struct nh_grp *nh_ids)
+{
+ struct {
+ struct nlmsghdr n;
+ struct nhmsg nhm;
+ char buf[256];
+ } req;
+ int cmd = RTM_NEWNEXTHOP;
+ struct zebra_vrf *zvrf;
+ struct zebra_ns *zns;
+ struct nexthop_grp grp[nh_cnt];
+ uint32_t i;
+
+ zvrf = zebra_vrf_get_evpn();
+ if (!zvrf)
+ return -1;
+ zns = zvrf->zns;
+
+ memset(&req, 0, sizeof(req));
+
+ req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct nhmsg));
+ req.n.nlmsg_flags = NLM_F_REQUEST;
+ req.n.nlmsg_flags |= (NLM_F_CREATE | NLM_F_REPLACE);
+ req.n.nlmsg_type = cmd;
+ req.nhm.nh_family = AF_UNSPEC;
+
+ if (!nl_attr_put32(&req.n, sizeof(req), NHA_ID, nhg_id))
+ return -1;
+ if (!nl_attr_put(&req.n, sizeof(req), NHA_FDB, NULL, 0))
+ return -1;
+ memset(&grp, 0, sizeof(grp));
+ for (i = 0; i < nh_cnt; ++i) {
+ grp[i].id = nh_ids[i].id;
+ grp[i].weight = nh_ids[i].weight;
+ }
+ if (!nl_attr_put(&req.n, sizeof(req), NHA_GROUP,
+ grp, nh_cnt * sizeof(struct nexthop_grp)))
+ return -1;
+
+
+ if (IS_ZEBRA_DEBUG_KERNEL || IS_ZEBRA_DEBUG_EVPN_MH_NH) {
+ char vtep_str[ES_VTEP_LIST_STR_SZ];
+ char nh_buf[16];
+
+ vtep_str[0] = '\0';
+ for (i = 0; i < nh_cnt; ++i) {
+ snprintf(nh_buf, sizeof(nh_buf), "%u ",
+ grp[i].id);
+ strlcat(vtep_str, nh_buf, sizeof(vtep_str));
+ }
+
+ zlog_debug("Tx %s fdb-nhg 0x%x %s",
+ nl_msg_type_to_str(cmd), nhg_id, vtep_str);
+ }
+
+ return netlink_talk(netlink_talk_filter, &req.n, &zns->netlink_cmd, zns,
+ 0);
+}
+
+static int netlink_fdb_nhg_del(uint32_t nhg_id)
+{
+ return netlink_fdb_nh_del(nhg_id);
+}
+
+int kernel_upd_mac_nh(uint32_t nh_id, struct in_addr vtep_ip)
+{
+ return netlink_fdb_nh_update(nh_id, vtep_ip);
+}
+
+int kernel_del_mac_nh(uint32_t nh_id)
+{
+ return netlink_fdb_nh_del(nh_id);
+}
+
+int kernel_upd_mac_nhg(uint32_t nhg_id, uint32_t nh_cnt,
+ struct nh_grp *nh_ids)
+{
+ return netlink_fdb_nhg_update(nhg_id, nh_cnt, nh_ids);
+}
+
+int kernel_del_mac_nhg(uint32_t nhg_id)
+{
+ return netlink_fdb_nhg_del(nhg_id);
+}
+
#endif /* HAVE_NETLINK */
diff --git a/zebra/rt_socket.c b/zebra/rt_socket.c
index 2eadaf48f4..0271dc7f41 100644
--- a/zebra/rt_socket.c
+++ b/zebra/rt_socket.c
@@ -417,4 +417,25 @@ uint32_t kernel_get_speed(struct interface *ifp, int *error)
return ifp->speed;
}
+int kernel_upd_mac_nh(uint32_t nh_id, struct in_addr vtep_ip)
+{
+ return 0;
+}
+
+int kernel_del_mac_nh(uint32_t nh_id)
+{
+ return 0;
+}
+
+int kernel_upd_mac_nhg(uint32_t nhg_id, uint32_t nh_cnt,
+ struct nh_grp *nh_ids)
+{
+ return 0;
+}
+
+int kernel_del_mac_nhg(uint32_t nhg_id)
+{
+ return 0;
+}
+
#endif /* !HAVE_NETLINK */
diff --git a/zebra/rule_netlink.c b/zebra/rule_netlink.c
index b7be398506..648e9eabe1 100644
--- a/zebra/rule_netlink.c
+++ b/zebra/rule_netlink.c
@@ -58,10 +58,12 @@
* Returns -1 on failure, 0 when the msg doesn't fit entirely in the buffer
* or the number of bytes written to buf.
*/
-static ssize_t netlink_rule_msg_encode(
- int cmd, const struct zebra_dplane_ctx *ctx, uint32_t filter_bm,
- uint32_t priority, uint32_t table, const struct prefix *src_ip,
- const struct prefix *dst_ip, uint32_t fwmark, void *buf, size_t buflen)
+static ssize_t
+netlink_rule_msg_encode(int cmd, const struct zebra_dplane_ctx *ctx,
+ uint32_t filter_bm, uint32_t priority, uint32_t table,
+ const struct prefix *src_ip,
+ const struct prefix *dst_ip, uint32_t fwmark,
+ uint8_t dsfield, void *buf, size_t buflen)
{
uint8_t protocol = RTPROT_ZEBRA;
int family;
@@ -122,6 +124,10 @@ static ssize_t netlink_rule_msg_encode(
return 0;
}
+ /* dsfield, if specified */
+ if (filter_bm & PBR_FILTER_DSFIELD)
+ req->frh.tos = dsfield;
+
/* Route table to use to forward, if filter criteria matches. */
if (table < 256)
req->frh.table = table;
@@ -145,16 +151,15 @@ static ssize_t netlink_rule_msg_encode(
/* Install or uninstall specified rule for a specific interface.
* Form netlink message and ship it.
*/
-static int
-netlink_rule_update_internal(int cmd, const struct zebra_dplane_ctx *ctx,
- uint32_t filter_bm, uint32_t priority,
- uint32_t table, const struct prefix *src_ip,
- const struct prefix *dst_ip, uint32_t fwmark)
+static int netlink_rule_update_internal(
+ int cmd, const struct zebra_dplane_ctx *ctx, uint32_t filter_bm,
+ uint32_t priority, uint32_t table, const struct prefix *src_ip,
+ const struct prefix *dst_ip, uint32_t fwmark, uint8_t dsfield)
{
char buf[NL_PKT_BUF_SIZE];
netlink_rule_msg_encode(cmd, ctx, filter_bm, priority, table, src_ip,
- dst_ip, fwmark, buf, sizeof(buf));
+ dst_ip, fwmark, dsfield, buf, sizeof(buf));
return netlink_talk_info(netlink_talk_filter, (void *)&buf,
dplane_ctx_get_ns(ctx), 0);
}
@@ -188,7 +193,8 @@ enum zebra_dplane_result kernel_pbr_rule_update(struct zebra_dplane_ctx *ctx)
dplane_ctx_rule_get_priority(ctx),
dplane_ctx_rule_get_table(ctx), dplane_ctx_rule_get_src_ip(ctx),
dplane_ctx_rule_get_dst_ip(ctx),
- dplane_ctx_rule_get_fwmark(ctx));
+ dplane_ctx_rule_get_fwmark(ctx),
+ dplane_ctx_rule_get_dsfield(ctx));
/**
* Delete the old one.
@@ -203,7 +209,8 @@ enum zebra_dplane_result kernel_pbr_rule_update(struct zebra_dplane_ctx *ctx)
dplane_ctx_rule_get_old_table(ctx),
dplane_ctx_rule_get_old_src_ip(ctx),
dplane_ctx_rule_get_old_dst_ip(ctx),
- dplane_ctx_rule_get_old_fwmark(ctx));
+ dplane_ctx_rule_get_old_fwmark(ctx),
+ dplane_ctx_rule_get_old_dsfield(ctx));
return (ret == 0 ? ZEBRA_DPLANE_REQUEST_SUCCESS
@@ -247,7 +254,16 @@ int netlink_rule_change(struct nlmsghdr *h, ns_id_t ns_id, int startup)
}
frh = NLMSG_DATA(h);
+
if (frh->family != AF_INET && frh->family != AF_INET6) {
+ if (frh->family == RTNL_FAMILY_IPMR
+ || frh->family == RTNL_FAMILY_IP6MR) {
+ if (IS_ZEBRA_DEBUG_KERNEL)
+ zlog_debug(
+ "Received rule netlink that we are ignoring for family %u, rule change: %u",
+ frh->family, h->nlmsg_type);
+ return 0;
+ }
flog_warn(
EC_ZEBRA_NETLINK_INVALID_AF,
"Invalid address family: %u received from kernel rule change: %u",
diff --git a/zebra/subdir.am b/zebra/subdir.am
index 49e60820bc..c552ca513e 100644
--- a/zebra/subdir.am
+++ b/zebra/subdir.am
@@ -12,6 +12,7 @@ vtysh_scan += \
zebra/rtadv.c \
zebra/zebra_gr.c \
zebra/zebra_mlag_vty.c \
+ zebra/zebra_evpn_mh.c \
zebra/zebra_mpls_vty.c \
zebra/zebra_ptm.c \
zebra/zebra_pw.c \
@@ -108,6 +109,7 @@ zebra_zebra_SOURCES = \
zebra/zebra_vrf.c \
zebra/zebra_vty.c \
zebra/zebra_vxlan.c \
+ zebra/zebra_evpn_mh.c \
zebra/zserv.c \
# end
@@ -115,6 +117,7 @@ clippy_scan += \
zebra/debug.c \
zebra/interface.c \
zebra/rtadv.c \
+ zebra/zebra_evpn_mh.c \
zebra/zebra_mlag_vty.c \
zebra/zebra_routemap.c \
zebra/zebra_vty.c \
@@ -167,6 +170,7 @@ noinst_HEADERS += \
zebra/zebra_vrf.h \
zebra/zebra_vxlan.h \
zebra/zebra_vxlan_private.h \
+ zebra/zebra_evpn_mh.h \
zebra/zserv.h \
# end
diff --git a/zebra/zapi_msg.c b/zebra/zapi_msg.c
index 13c63d5137..48aa566136 100644
--- a/zebra/zapi_msg.c
+++ b/zebra/zapi_msg.c
@@ -51,6 +51,7 @@
#include "zebra/zebra_mpls.h"
#include "zebra/zebra_mroute.h"
#include "zebra/zebra_vxlan.h"
+#include "zebra/zebra_evpn_mh.h"
#include "zebra/rt.h"
#include "zebra/zebra_pbr.h"
#include "zebra/table_manager.h"
@@ -729,9 +730,10 @@ static int route_notify_internal(const struct prefix *p, int type,
char buff[PREFIX_STRLEN];
zlog_debug(
- "Not Notifying Owner: %u about prefix %s(%u) %d vrf: %u",
- type, prefix2str(p, buff, sizeof(buff)),
- table_id, note, vrf_id);
+ "Not Notifying Owner: %s about prefix %s(%u) %d vrf: %u",
+ zebra_route_string(type),
+ prefix2str(p, buff, sizeof(buff)), table_id,
+ note, vrf_id);
}
return 0;
}
@@ -739,9 +741,10 @@ static int route_notify_internal(const struct prefix *p, int type,
if (IS_ZEBRA_DEBUG_PACKET) {
char buff[PREFIX_STRLEN];
- zlog_debug("Notifying Owner: %u about prefix %s(%u) %d vrf: %u",
- type, prefix2str(p, buff, sizeof(buff)),
- table_id, note, vrf_id);
+ zlog_debug("Notifying Owner: %s about prefix %s(%u) %d vrf: %u",
+ zebra_route_string(type),
+ prefix2str(p, buff, sizeof(buff)), table_id, note,
+ vrf_id);
}
s = stream_new(ZEBRA_MAX_PACKET_SIZ);
@@ -1417,6 +1420,7 @@ static struct nexthop *nexthop_from_zapi(struct route_entry *re,
struct nexthop *nexthop = NULL;
struct ipaddr vtep_ip;
struct interface *ifp;
+ int i;
char nhbuf[INET6_ADDRSTRLEN] = "";
switch (api_nh->type) {
@@ -1522,17 +1526,36 @@ static struct nexthop *nexthop_from_zapi(struct route_entry *re,
nexthop->weight = api_nh->weight;
if (CHECK_FLAG(api_nh->flags, ZAPI_NEXTHOP_FLAG_HAS_BACKUP)) {
- if (api_nh->backup_idx < api->backup_nexthop_num) {
- /* Capture backup info */
- SET_FLAG(nexthop->flags, NEXTHOP_FLAG_HAS_BACKUP);
- nexthop->backup_idx = api_nh->backup_idx;
- } else {
- /* Warn about invalid backup index */
+ /* Validate count */
+ if (api_nh->backup_num > NEXTHOP_MAX_BACKUPS) {
if (IS_ZEBRA_DEBUG_RECV || IS_ZEBRA_DEBUG_EVENT)
- zlog_debug("%s: invalid backup nh idx %d",
- __func__, api_nh->backup_idx);
+ zlog_debug("%s: invalid backup nh count %d",
+ __func__, api_nh->backup_num);
+ nexthop_free(nexthop);
+ nexthop = NULL;
+ goto done;
+ }
+
+ /* Copy backup info */
+ SET_FLAG(nexthop->flags, NEXTHOP_FLAG_HAS_BACKUP);
+ nexthop->backup_num = api_nh->backup_num;
+
+ for (i = 0; i < api_nh->backup_num; i++) {
+ /* Validate backup index */
+ if (api_nh->backup_idx[i] < api->backup_nexthop_num) {
+ nexthop->backup_idx[i] = api_nh->backup_idx[i];
+ } else {
+ if (IS_ZEBRA_DEBUG_RECV || IS_ZEBRA_DEBUG_EVENT)
+ zlog_debug("%s: invalid backup nh idx %d",
+ __func__,
+ api_nh->backup_idx[i]);
+ nexthop_free(nexthop);
+ nexthop = NULL;
+ goto done;
+ }
}
}
+
done:
return nexthop;
}
@@ -1704,7 +1727,7 @@ static void zread_route_add(ZAPI_HANDLER_ARGS)
__func__, nhbuf);
}
UNSET_FLAG(nexthop->flags, NEXTHOP_FLAG_HAS_BACKUP);
- nexthop->backup_idx = 0;
+ nexthop->backup_num = 0;
}
/* MPLS labels for BGP-LU or Segment Routing */
@@ -2010,6 +2033,56 @@ static void zread_vrf_unregister(ZAPI_HANDLER_ARGS)
}
/*
+ * Validate incoming zapi mpls lsp / labels message
+ */
+static int zapi_labels_validate(const struct zapi_labels *zl)
+{
+ int ret = -1;
+ int i, j, idx;
+ uint32_t bits[8];
+ uint32_t ival;
+ const struct zapi_nexthop *znh;
+
+ /* Validate backup info: no duplicates for a single primary */
+ if (zl->backup_nexthop_num == 0) {
+ ret = 0;
+ goto done;
+ }
+
+ for (j = 0; j < zl->nexthop_num; j++) {
+ znh = &zl->nexthops[j];
+
+ memset(bits, 0, sizeof(bits));
+
+ for (i = 0; i < znh->backup_num; i++) {
+ idx = znh->backup_idx[i] / 32;
+
+ ival = 1 << znh->backup_idx[i] % 32;
+
+ /* Check whether value is already used */
+ if (ival & bits[idx]) {
+ /* Fail */
+
+ if (IS_ZEBRA_DEBUG_RECV)
+ zlog_debug("%s: invalid zapi mpls message: duplicate backup nexthop index %d",
+ __func__,
+ znh->backup_idx[i]);
+ goto done;
+ }
+
+ /* Mark index value */
+ bits[idx] |= ival;
+ }
+ }
+
+ ret = 0;
+
+done:
+
+ return ret;
+}
+
+/*
* Handle request to create an MPLS LSP.
*
* A single message can fully specify an LSP with multiple nexthops.
@@ -2035,6 +2108,10 @@ static void zread_mpls_labels_add(ZAPI_HANDLER_ARGS)
if (!mpls_enabled)
return;
+ /* Validate; will debug on failure */
+ if (zapi_labels_validate(&zl) < 0)
+ return;
+
ret = mpls_zapi_labels_process(true, zvrf, &zl);
if (ret < 0) {
if (IS_ZEBRA_DEBUG_RECV)
@@ -2116,6 +2193,10 @@ static void zread_mpls_labels_replace(ZAPI_HANDLER_ARGS)
if (!mpls_enabled)
return;
+ /* Validate; will debug on failure */
+ if (zapi_labels_validate(&zl) < 0)
+ return;
+
/* This removes everything, then re-adds from the client's
* zapi message. Since the LSP will be processed later, on this
* this same pthread, all of the changes will 'appear' at once.
@@ -2555,6 +2636,7 @@ static inline void zread_rule(ZAPI_HANDLER_ARGS)
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.table);
STREAM_GETL(s, zpr.rule.ifindex);
@@ -2585,6 +2667,9 @@ static inline void zread_rule(ZAPI_HANDLER_ARGS)
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.fwmark)
zpr.rule.filter.filter_bm |= PBR_FILTER_FWMARK;
@@ -2837,6 +2922,8 @@ void (*const zserv_handlers[])(ZAPI_HANDLER_ARGS) = {
[ZEBRA_ADVERTISE_SVI_MACIP] = zebra_vxlan_advertise_svi_macip,
[ZEBRA_ADVERTISE_SUBNET] = zebra_vxlan_advertise_subnet,
[ZEBRA_ADVERTISE_ALL_VNI] = zebra_vxlan_advertise_all_vni,
+ [ZEBRA_REMOTE_ES_VTEP_ADD] = zebra_evpn_proc_remote_es,
+ [ZEBRA_REMOTE_ES_VTEP_DEL] = zebra_evpn_proc_remote_es,
[ZEBRA_REMOTE_VTEP_ADD] = zebra_vxlan_remote_vtep_add,
[ZEBRA_REMOTE_VTEP_DEL] = zebra_vxlan_remote_vtep_del,
[ZEBRA_REMOTE_MACIP_ADD] = zebra_vxlan_remote_macip_add,
diff --git a/zebra/zebra_dplane.c b/zebra/zebra_dplane.c
index 4e19e58d7a..5dcf76db15 100644
--- a/zebra/zebra_dplane.c
+++ b/zebra/zebra_dplane.c
@@ -180,6 +180,8 @@ struct dplane_mac_info {
struct ethaddr mac;
struct in_addr vtep_ip;
bool is_sticky;
+ uint32_t nhg_id;
+ uint32_t update_flags;
};
/*
@@ -190,6 +192,7 @@ struct dplane_neigh_info {
struct ethaddr mac;
uint32_t flags;
uint16_t state;
+ uint32_t update_flags;
};
/*
@@ -204,6 +207,7 @@ struct dplane_ctx_rule {
/* Filter criteria */
uint32_t filter_bm;
uint32_t fwmark;
+ uint8_t dsfield;
struct prefix src_ip;
struct prefix dst_ip;
};
@@ -440,13 +444,14 @@ static enum zebra_dplane_result mac_update_common(
enum dplane_op_e op, const struct interface *ifp,
const struct interface *br_ifp,
vlanid_t vid, const struct ethaddr *mac,
- struct in_addr vtep_ip, bool sticky);
+ struct in_addr vtep_ip, bool sticky, uint32_t nhg_id,
+ uint32_t update_flags);
static enum zebra_dplane_result neigh_update_internal(
enum dplane_op_e op,
const struct interface *ifp,
const struct ethaddr *mac,
const struct ipaddr *ip,
- uint32_t flags, uint16_t state);
+ uint32_t flags, uint16_t state, uint32_t update_flags);
/*
* Public APIs
@@ -1551,6 +1556,18 @@ bool dplane_ctx_mac_is_sticky(const struct zebra_dplane_ctx *ctx)
return ctx->u.macinfo.is_sticky;
}
+uint32_t dplane_ctx_mac_get_nhg_id(const struct zebra_dplane_ctx *ctx)
+{
+ DPLANE_CTX_VALID(ctx);
+ return ctx->u.macinfo.nhg_id;
+}
+
+uint32_t dplane_ctx_mac_get_update_flags(const struct zebra_dplane_ctx *ctx)
+{
+ DPLANE_CTX_VALID(ctx);
+ return ctx->u.macinfo.update_flags;
+}
+
const struct ethaddr *dplane_ctx_mac_get_addr(
const struct zebra_dplane_ctx *ctx)
{
@@ -1598,6 +1615,12 @@ uint16_t dplane_ctx_neigh_get_state(const struct zebra_dplane_ctx *ctx)
return ctx->u.neigh.state;
}
+uint32_t dplane_ctx_neigh_get_update_flags(const struct zebra_dplane_ctx *ctx)
+{
+ DPLANE_CTX_VALID(ctx);
+ return ctx->u.neigh.update_flags;
+}
+
/* Accessors for PBR rule information */
int dplane_ctx_rule_get_sock(const struct zebra_dplane_ctx *ctx)
{
@@ -1676,6 +1699,20 @@ uint32_t dplane_ctx_rule_get_old_fwmark(const struct zebra_dplane_ctx *ctx)
return ctx->u.rule.old.fwmark;
}
+uint8_t dplane_ctx_rule_get_dsfield(const struct zebra_dplane_ctx *ctx)
+{
+ DPLANE_CTX_VALID(ctx);
+
+ return ctx->u.rule.new.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;
+}
+
const struct prefix *
dplane_ctx_rule_get_src_ip(const struct zebra_dplane_ctx *ctx)
{
@@ -2001,10 +2038,19 @@ int dplane_ctx_lsp_init(struct zebra_dplane_ctx *ctx, enum dplane_op_e op,
break;
}
- /* Need to copy flags too */
+ /* Need to copy flags and backup info too */
new_nhlfe->flags = nhlfe->flags;
new_nhlfe->nexthop->flags = nhlfe->nexthop->flags;
+ if (CHECK_FLAG(new_nhlfe->nexthop->flags,
+ NEXTHOP_FLAG_HAS_BACKUP)) {
+ new_nhlfe->nexthop->backup_num =
+ nhlfe->nexthop->backup_num;
+ memcpy(new_nhlfe->nexthop->backup_idx,
+ nhlfe->nexthop->backup_idx,
+ new_nhlfe->nexthop->backup_num);
+ }
+
if (nhlfe == lsp->best_nhlfe)
ctx->u.lsp.best_nhlfe = new_nhlfe;
}
@@ -2104,8 +2150,15 @@ static int dplane_ctx_pw_init(struct zebra_dplane_ctx *ctx,
if (re) {
nhg = rib_get_fib_nhg(re);
- copy_nexthops(&(ctx->u.pw.nhg.nexthop),
- nhg->nexthop, NULL);
+ if (nhg && nhg->nexthop)
+ copy_nexthops(&(ctx->u.pw.nhg.nexthop),
+ nhg->nexthop, NULL);
+
+ /* Include any installed backup nexthops */
+ nhg = rib_get_fib_backup_nhg(re);
+ if (nhg && nhg->nexthop)
+ copy_nexthops(&(ctx->u.pw.nhg.nexthop),
+ nhg->nexthop, NULL);
}
route_unlock_node(rn);
}
@@ -2129,6 +2182,7 @@ static void dplane_ctx_rule_init_single(struct dplane_ctx_rule *dplane_rule,
dplane_rule->filter_bm = rule->rule.filter.filter_bm;
dplane_rule->fwmark = rule->rule.filter.fwmark;
+ dplane_rule->dsfield = rule->rule.filter.dsfield;
prefix_copy(&(dplane_rule->dst_ip), &rule->rule.filter.dst_ip);
prefix_copy(&(dplane_rule->src_ip), &rule->rule.filter.src_ip);
}
@@ -2458,9 +2512,11 @@ dplane_route_notif_update(struct route_node *rn,
enum dplane_op_e op,
struct zebra_dplane_ctx *ctx)
{
- enum zebra_dplane_result ret = ZEBRA_DPLANE_REQUEST_FAILURE;
+ enum zebra_dplane_result result = ZEBRA_DPLANE_REQUEST_FAILURE;
+ int ret = EINVAL;
struct zebra_dplane_ctx *new_ctx = NULL;
struct nexthop *nexthop;
+ struct nexthop_group *nhg;
if (rn == NULL || re == NULL)
goto done;
@@ -2482,8 +2538,17 @@ dplane_route_notif_update(struct route_node *rn,
nexthops_free(new_ctx->u.rinfo.zd_ng.nexthop);
new_ctx->u.rinfo.zd_ng.nexthop = NULL;
- copy_nexthops(&(new_ctx->u.rinfo.zd_ng.nexthop),
- (rib_get_fib_nhg(re))->nexthop, NULL);
+ nhg = rib_get_fib_nhg(re);
+ if (nhg && nhg->nexthop)
+ copy_nexthops(&(new_ctx->u.rinfo.zd_ng.nexthop),
+ nhg->nexthop, NULL);
+
+ /* Check for installed backup nexthops also */
+ nhg = rib_get_fib_backup_nhg(re);
+ if (nhg && nhg->nexthop) {
+ copy_nexthops(&(new_ctx->u.rinfo.zd_ng.nexthop),
+ nhg->nexthop, NULL);
+ }
for (ALL_NEXTHOPS(new_ctx->u.rinfo.zd_ng, nexthop))
UNSET_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB);
@@ -2494,12 +2559,15 @@ dplane_route_notif_update(struct route_node *rn,
dplane_ctx_set_notif_provider(new_ctx,
dplane_ctx_get_notif_provider(ctx));
- dplane_update_enqueue(new_ctx);
-
- ret = ZEBRA_DPLANE_REQUEST_QUEUED;
+ ret = dplane_update_enqueue(new_ctx);
done:
- return ret;
+ if (ret == AOK)
+ result = ZEBRA_DPLANE_REQUEST_QUEUED;
+ else if (new_ctx)
+ dplane_ctx_free(&new_ctx);
+
+ return result;
}
/*
@@ -2583,6 +2651,8 @@ dplane_lsp_notif_update(zebra_lsp_t *lsp,
enum zebra_dplane_result result = ZEBRA_DPLANE_REQUEST_FAILURE;
int ret = EINVAL;
struct zebra_dplane_ctx *ctx = NULL;
+ struct nhlfe_list_head *head;
+ zebra_nhlfe_t *nhlfe, *new_nhlfe;
/* Obtain context block */
ctx = dplane_ctx_alloc();
@@ -2591,10 +2661,27 @@ dplane_lsp_notif_update(zebra_lsp_t *lsp,
goto done;
}
+ /* Copy info from zebra LSP */
ret = dplane_ctx_lsp_init(ctx, op, lsp);
if (ret != AOK)
goto done;
+ /* Add any installed backup nhlfes */
+ head = &(ctx->u.lsp.backup_nhlfe_list);
+ frr_each(nhlfe_list, head, nhlfe) {
+
+ if (CHECK_FLAG(nhlfe->flags, NHLFE_FLAG_INSTALLED) &&
+ CHECK_FLAG(nhlfe->nexthop->flags, NEXTHOP_FLAG_FIB)) {
+ new_nhlfe = zebra_mpls_lsp_add_nh(&(ctx->u.lsp),
+ nhlfe->type,
+ nhlfe->nexthop);
+
+ /* Need to copy flags too */
+ new_nhlfe->flags = nhlfe->flags;
+ new_nhlfe->nexthop->flags = nhlfe->nexthop->flags;
+ }
+ }
+
/* Capture info about the source of the notification */
dplane_ctx_set_notif_provider(
ctx,
@@ -2830,35 +2917,75 @@ static enum zebra_dplane_result intf_addr_update_internal(
/*
* Enqueue vxlan/evpn mac add (or update).
*/
-enum zebra_dplane_result dplane_mac_add(const struct interface *ifp,
+enum zebra_dplane_result dplane_rem_mac_add(const struct interface *ifp,
const struct interface *bridge_ifp,
vlanid_t vid,
const struct ethaddr *mac,
struct in_addr vtep_ip,
- bool sticky)
+ bool sticky,
+ uint32_t nhg_id,
+ bool was_static)
{
enum zebra_dplane_result result;
+ uint32_t update_flags = 0;
+
+ update_flags |= DPLANE_MAC_REMOTE;
+ if (was_static)
+ update_flags |= DPLANE_MAC_WAS_STATIC;
/* Use common helper api */
result = mac_update_common(DPLANE_OP_MAC_INSTALL, ifp, bridge_ifp,
- vid, mac, vtep_ip, sticky);
+ vid, mac, vtep_ip, sticky, nhg_id, update_flags);
return result;
}
/*
* Enqueue vxlan/evpn mac delete.
*/
-enum zebra_dplane_result dplane_mac_del(const struct interface *ifp,
+enum zebra_dplane_result dplane_rem_mac_del(const struct interface *ifp,
const struct interface *bridge_ifp,
vlanid_t vid,
const struct ethaddr *mac,
struct in_addr vtep_ip)
{
enum zebra_dplane_result result;
+ uint32_t update_flags = 0;
+
+ update_flags |= DPLANE_MAC_REMOTE;
/* Use common helper api */
result = mac_update_common(DPLANE_OP_MAC_DELETE, ifp, bridge_ifp,
- vid, mac, vtep_ip, false);
+ vid, mac, vtep_ip, false, 0, update_flags);
+ return result;
+}
+
+/*
+ * Enqueue local mac add (or update).
+ */
+enum zebra_dplane_result dplane_local_mac_add(const struct interface *ifp,
+ const struct interface *bridge_ifp,
+ vlanid_t vid,
+ const struct ethaddr *mac,
+ bool sticky,
+ uint32_t set_static,
+ uint32_t set_inactive)
+{
+ enum zebra_dplane_result result;
+ uint32_t update_flags = 0;
+ struct in_addr vtep_ip;
+
+ if (set_static)
+ update_flags |= DPLANE_MAC_SET_STATIC;
+
+ if (set_inactive)
+ update_flags |= DPLANE_MAC_SET_INACTIVE;
+
+ vtep_ip.s_addr = 0;
+
+ /* Use common helper api */
+ result = mac_update_common(DPLANE_OP_MAC_INSTALL, ifp, bridge_ifp,
+ vid, mac, vtep_ip, sticky, 0,
+ update_flags);
return result;
}
@@ -2872,7 +2999,9 @@ void dplane_mac_init(struct zebra_dplane_ctx *ctx,
vlanid_t vid,
const struct ethaddr *mac,
struct in_addr vtep_ip,
- bool sticky)
+ bool sticky,
+ uint32_t nhg_id,
+ uint32_t update_flags)
{
struct zebra_ns *zns;
@@ -2893,6 +3022,8 @@ void dplane_mac_init(struct zebra_dplane_ctx *ctx,
ctx->u.macinfo.mac = *mac;
ctx->u.macinfo.vid = vid;
ctx->u.macinfo.is_sticky = sticky;
+ ctx->u.macinfo.nhg_id = nhg_id;
+ ctx->u.macinfo.update_flags = update_flags;
}
/*
@@ -2905,7 +3036,9 @@ mac_update_common(enum dplane_op_e op,
vlanid_t vid,
const struct ethaddr *mac,
struct in_addr vtep_ip,
- bool sticky)
+ bool sticky,
+ uint32_t nhg_id,
+ uint32_t update_flags)
{
enum zebra_dplane_result result = ZEBRA_DPLANE_REQUEST_FAILURE;
int ret;
@@ -2925,7 +3058,8 @@ mac_update_common(enum dplane_op_e op,
ctx->zd_op = op;
/* Common init for the ctx */
- dplane_mac_init(ctx, ifp, br_ifp, vid, mac, vtep_ip, sticky);
+ dplane_mac_init(ctx, ifp, br_ifp, vid, mac, vtep_ip, sticky,
+ nhg_id, update_flags);
/* Enqueue for processing on the dplane pthread */
ret = dplane_update_enqueue(ctx);
@@ -2949,15 +3083,56 @@ mac_update_common(enum dplane_op_e op,
/*
* Enqueue evpn neighbor add for the dataplane.
*/
-enum zebra_dplane_result dplane_neigh_add(const struct interface *ifp,
+enum zebra_dplane_result dplane_rem_neigh_add(const struct interface *ifp,
+ const struct ipaddr *ip,
+ const struct ethaddr *mac,
+ uint32_t flags, bool was_static)
+{
+ enum zebra_dplane_result result = ZEBRA_DPLANE_REQUEST_FAILURE;
+ uint32_t update_flags = 0;
+
+ update_flags |= DPLANE_NEIGH_REMOTE;
+
+ if (was_static)
+ update_flags |= DPLANE_NEIGH_WAS_STATIC;
+
+ result = neigh_update_internal(DPLANE_OP_NEIGH_INSTALL,
+ ifp, mac, ip, flags, DPLANE_NUD_NOARP,
+ update_flags);
+
+ return result;
+}
+
+/*
+ * Enqueue local neighbor add for the dataplane.
+ */
+enum zebra_dplane_result dplane_local_neigh_add(const struct interface *ifp,
const struct ipaddr *ip,
const struct ethaddr *mac,
- uint32_t flags)
+ bool set_router, bool set_static,
+ bool set_inactive)
{
enum zebra_dplane_result result = ZEBRA_DPLANE_REQUEST_FAILURE;
+ uint32_t update_flags = 0;
+ uint32_t ntf = 0;
+ uint16_t state;
+
+ if (set_static)
+ update_flags |= DPLANE_NEIGH_SET_STATIC;
+
+ if (set_inactive) {
+ update_flags |= DPLANE_NEIGH_SET_INACTIVE;
+ state = DPLANE_NUD_STALE;
+ } else {
+ state = DPLANE_NUD_REACHABLE;
+ }
+
+ if (set_router)
+ ntf |= DPLANE_NTF_ROUTER;
result = neigh_update_internal(DPLANE_OP_NEIGH_INSTALL,
- ifp, mac, ip, flags, DPLANE_NUD_NOARP);
+ ifp, mac, ip, ntf,
+ state, update_flags);
return result;
}
@@ -2965,14 +3140,18 @@ enum zebra_dplane_result dplane_neigh_add(const struct interface *ifp,
/*
* Enqueue evpn neighbor update for the dataplane.
*/
-enum zebra_dplane_result dplane_neigh_update(const struct interface *ifp,
+enum zebra_dplane_result dplane_rem_neigh_update(const struct interface *ifp,
const struct ipaddr *ip,
const struct ethaddr *mac)
{
enum zebra_dplane_result result;
+ uint32_t update_flags = 0;
+
+ update_flags |= DPLANE_NEIGH_REMOTE;
result = neigh_update_internal(DPLANE_OP_NEIGH_UPDATE,
- ifp, mac, ip, 0, DPLANE_NUD_PROBE);
+ ifp, mac, ip, 0, DPLANE_NUD_PROBE,
+ update_flags);
return result;
}
@@ -2980,13 +3159,16 @@ enum zebra_dplane_result dplane_neigh_update(const struct interface *ifp,
/*
* Enqueue evpn neighbor delete for the dataplane.
*/
-enum zebra_dplane_result dplane_neigh_delete(const struct interface *ifp,
+enum zebra_dplane_result dplane_rem_neigh_delete(const struct interface *ifp,
const struct ipaddr *ip)
{
enum zebra_dplane_result result;
+ uint32_t update_flags = 0;
+
+ update_flags |= DPLANE_NEIGH_REMOTE;
result = neigh_update_internal(DPLANE_OP_NEIGH_DELETE,
- ifp, NULL, ip, 0, 0);
+ ifp, NULL, ip, 0, 0, update_flags);
return result;
}
@@ -3010,7 +3192,7 @@ enum zebra_dplane_result dplane_vtep_add(const struct interface *ifp,
addr.ipaddr_v4 = *ip;
result = neigh_update_internal(DPLANE_OP_VTEP_ADD,
- ifp, &mac, &addr, 0, 0);
+ ifp, &mac, &addr, 0, 0, 0);
return result;
}
@@ -3035,7 +3217,7 @@ enum zebra_dplane_result dplane_vtep_delete(const struct interface *ifp,
addr.ipaddr_v4 = *ip;
result = neigh_update_internal(DPLANE_OP_VTEP_DELETE,
- ifp, &mac, &addr, 0, 0);
+ ifp, &mac, &addr, 0, 0, 0);
return result;
}
@@ -3048,7 +3230,8 @@ neigh_update_internal(enum dplane_op_e op,
const struct interface *ifp,
const struct ethaddr *mac,
const struct ipaddr *ip,
- uint32_t flags, uint16_t state)
+ uint32_t flags, uint16_t state,
+ uint32_t update_flags)
{
enum zebra_dplane_result result = ZEBRA_DPLANE_REQUEST_FAILURE;
int ret;
@@ -3085,6 +3268,7 @@ neigh_update_internal(enum dplane_op_e op,
ctx->u.neigh.mac = *mac;
ctx->u.neigh.flags = flags;
ctx->u.neigh.state = state;
+ ctx->u.neigh.update_flags = update_flags;
/* Enqueue for processing on the dplane pthread */
ret = dplane_update_enqueue(ctx);
@@ -4002,19 +4186,19 @@ bool dplane_is_in_shutdown(void)
*/
void zebra_dplane_pre_finish(void)
{
- struct zebra_dplane_provider *dp;
+ struct zebra_dplane_provider *prov;
if (IS_ZEBRA_DEBUG_DPLANE)
- zlog_debug("Zebra dataplane pre-fini called");
+ zlog_debug("Zebra dataplane pre-finish called");
zdplane_info.dg_is_shutdown = true;
/* Notify provider(s) of pending shutdown. */
- TAILQ_FOREACH(dp, &zdplane_info.dg_providers_q, dp_prov_link) {
- if (dp->dp_fini == NULL)
+ TAILQ_FOREACH(prov, &zdplane_info.dg_providers_q, dp_prov_link) {
+ if (prov->dp_fini == NULL)
continue;
- dp->dp_fini(dp, true);
+ prov->dp_fini(prov, true /* early */);
}
}
@@ -4336,7 +4520,10 @@ void zebra_dplane_shutdown(void)
zdplane_info.dg_pthread = NULL;
zdplane_info.dg_master = NULL;
- /* Notify provider(s) of final shutdown. */
+ /* Notify provider(s) of final shutdown.
+ * Note that this call is in the main pthread, so providers must
+ * be prepared for that.
+ */
TAILQ_FOREACH(dp, &zdplane_info.dg_providers_q, dp_prov_link) {
if (dp->dp_fini == NULL)
continue;
diff --git a/zebra/zebra_dplane.h b/zebra/zebra_dplane.h
index 8e873886df..32032ed77d 100644
--- a/zebra/zebra_dplane.h
+++ b/zebra/zebra_dplane.h
@@ -168,6 +168,18 @@ enum dplane_op_e {
#define DPLANE_NUD_NOARP 0x04
#define DPLANE_NUD_PROBE 0x08
+/* MAC update flags - dplane_mac_info.update_flags */
+#define DPLANE_MAC_REMOTE (1 << 0)
+#define DPLANE_MAC_WAS_STATIC (1 << 1)
+#define DPLANE_MAC_SET_STATIC (1 << 2)
+#define DPLANE_MAC_SET_INACTIVE (1 << 3)
+
+/* Neigh update flags - dplane_neigh_info.update_flags */
+#define DPLANE_NEIGH_REMOTE (1 << 0)
+#define DPLANE_NEIGH_WAS_STATIC (1 << 1)
+#define DPLANE_NEIGH_SET_STATIC (1 << 2)
+#define DPLANE_NEIGH_SET_INACTIVE (1 << 3)
+
/* Enable system route notifications */
void dplane_enable_sys_route_notifs(void);
@@ -386,6 +398,8 @@ const char *dplane_ctx_get_intf_label(const struct zebra_dplane_ctx *ctx);
/* Accessors for MAC information */
vlanid_t dplane_ctx_mac_get_vlan(const struct zebra_dplane_ctx *ctx);
bool dplane_ctx_mac_is_sticky(const struct zebra_dplane_ctx *ctx);
+uint32_t dplane_ctx_mac_get_update_flags(const struct zebra_dplane_ctx *ctx);
+uint32_t dplane_ctx_mac_get_nhg_id(const struct zebra_dplane_ctx *ctx);
const struct ethaddr *dplane_ctx_mac_get_addr(
const struct zebra_dplane_ctx *ctx);
const struct in_addr *dplane_ctx_mac_get_vtep_ip(
@@ -399,6 +413,7 @@ const struct ethaddr *dplane_ctx_neigh_get_mac(
const struct zebra_dplane_ctx *ctx);
uint32_t dplane_ctx_neigh_get_flags(const struct zebra_dplane_ctx *ctx);
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 */
int dplane_ctx_rule_get_sock(const struct zebra_dplane_ctx *ctx);
@@ -412,6 +427,8 @@ uint32_t dplane_ctx_rule_get_filter_bm(const struct zebra_dplane_ctx *ctx);
uint32_t dplane_ctx_rule_get_old_filter_bm(const struct zebra_dplane_ctx *ctx);
uint32_t dplane_ctx_rule_get_fwmark(const struct zebra_dplane_ctx *ctx);
uint32_t dplane_ctx_rule_get_old_fwmark(const struct zebra_dplane_ctx *ctx);
+uint8_t dplane_ctx_rule_get_dsfield(const struct zebra_dplane_ctx *ctx);
+uint8_t dplane_ctx_rule_get_old_dsfield(const struct zebra_dplane_ctx *ctx);
const struct prefix *
dplane_ctx_rule_get_src_ip(const struct zebra_dplane_ctx *ctx);
const struct prefix *
@@ -495,20 +512,24 @@ enum zebra_dplane_result dplane_intf_addr_unset(const struct interface *ifp,
/*
* Enqueue evpn mac operations for the dataplane.
*/
-extern struct zebra_dplane_ctx *mac_update_internal(
- enum dplane_op_e op, const struct interface *ifp,
- const struct interface *br_ifp,
- vlanid_t vid, const struct ethaddr *mac,
- struct in_addr vtep_ip, bool sticky);
-
-enum zebra_dplane_result dplane_mac_add(const struct interface *ifp,
+enum zebra_dplane_result dplane_rem_mac_add(const struct interface *ifp,
const struct interface *bridge_ifp,
vlanid_t vid,
const struct ethaddr *mac,
struct in_addr vtep_ip,
- bool sticky);
+ bool sticky,
+ uint32_t nhg_id,
+ bool was_static);
+
+enum zebra_dplane_result dplane_local_mac_add(const struct interface *ifp,
+ const struct interface *bridge_ifp,
+ vlanid_t vid,
+ const struct ethaddr *mac,
+ bool sticky,
+ uint32_t set_static,
+ uint32_t set_inactive);
-enum zebra_dplane_result dplane_mac_del(const struct interface *ifp,
+enum zebra_dplane_result dplane_rem_mac_del(const struct interface *ifp,
const struct interface *bridge_ifp,
vlanid_t vid,
const struct ethaddr *mac,
@@ -521,19 +542,25 @@ void dplane_mac_init(struct zebra_dplane_ctx *ctx,
vlanid_t vid,
const struct ethaddr *mac,
struct in_addr vtep_ip,
- bool sticky);
+ bool sticky,
+ uint32_t nhg_id, uint32_t update_flags);
/*
* Enqueue evpn neighbor updates for the dataplane.
*/
-enum zebra_dplane_result dplane_neigh_add(const struct interface *ifp,
+enum zebra_dplane_result dplane_rem_neigh_add(const struct interface *ifp,
+ const struct ipaddr *ip,
+ const struct ethaddr *mac,
+ uint32_t flags, bool was_static);
+enum zebra_dplane_result dplane_local_neigh_add(const struct interface *ifp,
const struct ipaddr *ip,
const struct ethaddr *mac,
- uint32_t flags);
-enum zebra_dplane_result dplane_neigh_update(const struct interface *ifp,
+ bool set_router, bool set_static,
+ bool set_inactive);
+enum zebra_dplane_result dplane_rem_neigh_update(const struct interface *ifp,
const struct ipaddr *ip,
const struct ethaddr *mac);
-enum zebra_dplane_result dplane_neigh_delete(const struct interface *ifp,
+enum zebra_dplane_result dplane_rem_neigh_delete(const struct interface *ifp,
const struct ipaddr *ip);
/*
diff --git a/zebra/zebra_errors.h b/zebra/zebra_errors.h
index 5f2a7a12c6..03953ed17f 100644
--- a/zebra/zebra_errors.h
+++ b/zebra/zebra_errors.h
@@ -134,6 +134,7 @@ enum zebra_log_refs {
EC_ZEBRA_BAD_NHG_MESSAGE,
EC_ZEBRA_DUPLICATE_NHG_MESSAGE,
EC_ZEBRA_VRF_MISCONFIGURED,
+ EC_ZEBRA_ES_CREATE,
};
void zebra_error_init(void);
diff --git a/zebra/zebra_evpn_mh.c b/zebra/zebra_evpn_mh.c
new file mode 100644
index 0000000000..fae36ec6fa
--- /dev/null
+++ b/zebra/zebra_evpn_mh.c
@@ -0,0 +1,2145 @@
+/*
+ * Zebra EVPN multihoming code
+ *
+ * Copyright (C) 2019 Cumulus Networks, Inc.
+ * Anuradha Karuppiah
+ *
+ * This file is part of FRR.
+ *
+ * FRR is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2, or (at your option) any
+ * later version.
+ *
+ * FRR is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ */
+
+#include <zebra.h>
+
+#include "command.h"
+#include "hash.h"
+#include "if.h"
+#include "jhash.h"
+#include "linklist.h"
+#include "log.h"
+#include "memory.h"
+#include "prefix.h"
+#include "stream.h"
+#include "table.h"
+#include "vlan.h"
+#include "vxlan.h"
+
+#include "zebra/zebra_router.h"
+#include "zebra/debug.h"
+#include "zebra/interface.h"
+#include "zebra/rib.h"
+#include "zebra/rt.h"
+#include "zebra/rt_netlink.h"
+#include "zebra/zebra_errors.h"
+#include "zebra/zebra_l2.h"
+#include "zebra/zebra_memory.h"
+#include "zebra/zebra_ns.h"
+#include "zebra/zebra_vrf.h"
+#include "zebra/zebra_vxlan.h"
+#include "zebra/zebra_vxlan_private.h"
+#include "zebra/zebra_router.h"
+#include "zebra/zebra_evpn_mh.h"
+#include "zebra/zebra_nhg.h"
+
+DEFINE_MTYPE_STATIC(ZEBRA, ZACC_BD, "Access Broadcast Domain");
+DEFINE_MTYPE_STATIC(ZEBRA, ZES, "Ethernet Segment");
+DEFINE_MTYPE_STATIC(ZEBRA, ZES_EVI, "ES info per-EVI");
+DEFINE_MTYPE_STATIC(ZEBRA, ZMH_INFO, "MH global info");
+DEFINE_MTYPE_STATIC(ZEBRA, ZES_VTEP, "VTEP attached to the ES");
+
+static void zebra_evpn_es_get_one_base_vni(void);
+static int zebra_evpn_es_evi_send_to_client(struct zebra_evpn_es *es,
+ zebra_vni_t *vni, bool add);
+static void zebra_evpn_local_es_del(struct zebra_evpn_es *es);
+static int zebra_evpn_local_es_update(struct zebra_if *zif, uint32_t lid,
+ struct ethaddr *sysmac);
+
+esi_t zero_esi_buf, *zero_esi = &zero_esi_buf;
+
+/*****************************************************************************/
+/* Ethernet Segment to EVI association -
+ * 1. The ES-EVI entry is maintained as a RB tree per L2-VNI
+ * (zebra_vni_t.es_evi_rb_tree).
+ * 2. Each local ES-EVI entry is sent to BGP which advertises it as an
+ * EAD-EVI (Type-1 EVPN) route
+ * 3. Local ES-EVI setup is re-evaluated on the following triggers -
+ * a. When an ESI is set or cleared on an access port.
+ * b. When an access port associated with an ESI is deleted.
+ * c. When VLAN member ship changes on an access port.
+ * d. When a VXLAN_IF is set or cleared on an access broadcast domain.
+ * e. When a L2-VNI is added or deleted for a VxLAN_IF.
+ * 4. Currently zebra doesn't remote ES-EVIs. Those are managed and maintained
+ * entirely in BGP which consolidates them into a remote ES. The remote ES
+ * is then sent to zebra which allocates a NHG for it.
+ */
+
+/* compare ES-IDs for the ES-EVI RB tree maintained per-VNI */
+static int zebra_es_evi_rb_cmp(const struct zebra_evpn_es_evi *es_evi1,
+ const struct zebra_evpn_es_evi *es_evi2)
+{
+ return memcmp(&es_evi1->es->esi, &es_evi2->es->esi, ESI_BYTES);
+}
+RB_GENERATE(zebra_es_evi_rb_head, zebra_evpn_es_evi,
+ rb_node, zebra_es_evi_rb_cmp);
+
+/* allocate a new ES-EVI and insert it into the per-L2-VNI and per-ES
+ * tables.
+ */
+static struct zebra_evpn_es_evi *zebra_evpn_es_evi_new(struct zebra_evpn_es *es,
+ zebra_vni_t *zvni)
+{
+ struct zebra_evpn_es_evi *es_evi;
+
+ es_evi = XCALLOC(MTYPE_ZES_EVI, sizeof(struct zebra_evpn_es_evi));
+
+ es_evi->es = es;
+ es_evi->zvni = zvni;
+
+ /* insert into the VNI-ESI rb tree */
+ if (RB_INSERT(zebra_es_evi_rb_head, &zvni->es_evi_rb_tree, es_evi)) {
+ XFREE(MTYPE_ZES_EVI, es_evi);
+ return NULL;
+ }
+
+ /* add to the ES's VNI list */
+ listnode_init(&es_evi->es_listnode, es_evi);
+ listnode_add(es->es_evi_list, &es_evi->es_listnode);
+
+ if (IS_ZEBRA_DEBUG_EVPN_MH_ES)
+ zlog_debug("es %s evi %d new",
+ es_evi->es->esi_str, es_evi->zvni->vni);
+
+ return es_evi;
+}
+
+/* returns TRUE if the VNI is ready to be sent to BGP */
+static inline bool zebra_evpn_vni_send_to_client_ok(zebra_vni_t *zvni)
+{
+ return !!(zvni->flags & ZVNI_READY_FOR_BGP);
+}
+
+/* Evaluate if the es_evi is ready to be sent BGP -
+ * 1. If it is ready an add is sent to BGP
+ * 2. If it is not ready a del is sent (if the ES had been previously added
+ * to BGP).
+ */
+static void zebra_evpn_es_evi_re_eval_send_to_client(
+ struct zebra_evpn_es_evi *es_evi)
+{
+ bool old_ready;
+ bool new_ready;
+
+ old_ready = !!(es_evi->flags & ZEBRA_EVPNES_EVI_READY_FOR_BGP);
+
+ /* ES and L2-VNI have to be individually ready for BGP */
+ if ((es_evi->flags & ZEBRA_EVPNES_EVI_LOCAL) &&
+ (es_evi->es->flags & ZEBRA_EVPNES_READY_FOR_BGP) &&
+ zebra_evpn_vni_send_to_client_ok(es_evi->zvni))
+ es_evi->flags |= ZEBRA_EVPNES_EVI_READY_FOR_BGP;
+ else
+ es_evi->flags &= ~ZEBRA_EVPNES_EVI_READY_FOR_BGP;
+
+ new_ready = !!(es_evi->flags & ZEBRA_EVPNES_EVI_READY_FOR_BGP);
+
+ if (old_ready == new_ready)
+ return;
+
+ if (new_ready)
+ zebra_evpn_es_evi_send_to_client(es_evi->es, es_evi->zvni,
+ true /* add */);
+ else
+ zebra_evpn_es_evi_send_to_client(es_evi->es, es_evi->zvni,
+ false /* add */);
+}
+
+/* remove the ES-EVI from the per-L2-VNI and per-ES tables and free
+ * up the memory.
+ */
+static void zebra_evpn_es_evi_free(struct zebra_evpn_es_evi *es_evi)
+{
+ struct zebra_evpn_es *es = es_evi->es;
+ zebra_vni_t *zvni = es_evi->zvni;
+
+ if (IS_ZEBRA_DEBUG_EVPN_MH_ES)
+ zlog_debug("es %s evi %d free",
+ es_evi->es->esi_str, es_evi->zvni->vni);
+
+ /* remove from the ES's VNI list */
+ list_delete_node(es->es_evi_list, &es_evi->es_listnode);
+
+ /* remove from the VNI-ESI rb tree */
+ RB_REMOVE(zebra_es_evi_rb_head, &zvni->es_evi_rb_tree, es_evi);
+
+ /* remove from the VNI-ESI rb tree */
+ XFREE(MTYPE_ZES_EVI, es_evi);
+}
+
+/* find the ES-EVI in the per-L2-VNI RB tree */
+static struct zebra_evpn_es_evi *zebra_evpn_es_evi_find(
+ struct zebra_evpn_es *es, zebra_vni_t *zvni)
+{
+ struct zebra_evpn_es_evi es_evi;
+
+ es_evi.es = es;
+
+ return RB_FIND(zebra_es_evi_rb_head, &zvni->es_evi_rb_tree, &es_evi);
+}
+
+/* Tell BGP about an ES-EVI deletion and then delete it */
+static void zebra_evpn_local_es_evi_do_del(struct zebra_evpn_es_evi *es_evi)
+{
+ if (!(es_evi->flags & ZEBRA_EVPNES_EVI_LOCAL))
+ return;
+
+ if (IS_ZEBRA_DEBUG_EVPN_MH_ES)
+ zlog_debug("local es %s evi %d del",
+ es_evi->es->esi_str, es_evi->zvni->vni);
+
+ if (es_evi->flags & ZEBRA_EVPNES_EVI_READY_FOR_BGP) {
+ /* send a del only if add was sent for it earlier */
+ zebra_evpn_es_evi_send_to_client(es_evi->es,
+ es_evi->zvni, false /* add */);
+ }
+
+ /* delete it from the VNI's local list */
+ list_delete_node(es_evi->zvni->local_es_evi_list,
+ &es_evi->l2vni_listnode);
+
+ es_evi->flags &= ~ZEBRA_EVPNES_EVI_LOCAL;
+ zebra_evpn_es_evi_free(es_evi);
+}
+static void zebra_evpn_local_es_evi_del(struct zebra_evpn_es *es,
+ zebra_vni_t *zvni)
+{
+ struct zebra_evpn_es_evi *es_evi;
+
+ es_evi = zebra_evpn_es_evi_find(es, zvni);
+ if (es_evi)
+ zebra_evpn_local_es_evi_do_del(es_evi);
+}
+
+/* Create an ES-EVI if it doesn't already exist and tell BGP */
+static void zebra_evpn_local_es_evi_add(struct zebra_evpn_es *es,
+ zebra_vni_t *zvni)
+{
+ struct zebra_evpn_es_evi *es_evi;
+
+ es_evi = zebra_evpn_es_evi_find(es, zvni);
+ if (!es_evi) {
+ es_evi = zebra_evpn_es_evi_new(es, zvni);
+ if (!es_evi)
+ return;
+
+ if (IS_ZEBRA_DEBUG_EVPN_MH_ES)
+ zlog_debug("local es %s evi %d add",
+ es_evi->es->esi_str, es_evi->zvni->vni);
+ es_evi->flags |= ZEBRA_EVPNES_EVI_LOCAL;
+ /* add to the VNI's local list */
+ listnode_init(&es_evi->l2vni_listnode, es_evi);
+ listnode_add(zvni->local_es_evi_list, &es_evi->l2vni_listnode);
+
+ zebra_evpn_es_evi_re_eval_send_to_client(es_evi);
+ }
+}
+
+static void zebra_evpn_es_evi_show_entry(struct vty *vty,
+ struct zebra_evpn_es_evi *es_evi, json_object *json)
+{
+ char type_str[4];
+
+ if (json) {
+ /* XXX */
+ } else {
+ type_str[0] = '\0';
+ if (es_evi->flags & ZEBRA_EVPNES_EVI_LOCAL)
+ strlcat(type_str, "L", sizeof(type_str));
+
+ vty_out(vty, "%-8d %-30s %-4s\n",
+ es_evi->zvni->vni, es_evi->es->esi_str,
+ type_str);
+ }
+}
+
+static void zebra_evpn_es_evi_show_entry_detail(struct vty *vty,
+ struct zebra_evpn_es_evi *es_evi, json_object *json)
+{
+ char type_str[4];
+
+ if (json) {
+ /* XXX */
+ } else {
+ type_str[0] = '\0';
+ if (es_evi->flags & ZEBRA_EVPNES_EVI_LOCAL)
+ strlcat(type_str, "L", sizeof(type_str));
+
+ vty_out(vty, "VNI %d ESI: %s\n",
+ es_evi->zvni->vni, es_evi->es->esi_str);
+ vty_out(vty, " Type: %s\n", type_str);
+ vty_out(vty, " Ready for BGP: %s\n",
+ (es_evi->flags &
+ ZEBRA_EVPNES_EVI_READY_FOR_BGP) ?
+ "yes" : "no");
+ vty_out(vty, "\n");
+ }
+}
+
+static void zebra_evpn_es_evi_show_one_vni(zebra_vni_t *zvni,
+ struct vty *vty, json_object *json, int detail)
+{
+ struct zebra_evpn_es_evi *es_evi;
+
+ RB_FOREACH(es_evi, zebra_es_evi_rb_head, &zvni->es_evi_rb_tree) {
+ if (detail)
+ zebra_evpn_es_evi_show_entry_detail(vty, es_evi, json);
+ else
+ zebra_evpn_es_evi_show_entry(vty, es_evi, json);
+ }
+}
+
+struct evpn_mh_show_ctx {
+ struct vty *vty;
+ json_object *json;
+ int detail;
+};
+
+static void zebra_evpn_es_evi_show_one_vni_hash_cb(struct hash_bucket *bucket,
+ void *ctxt)
+{
+ zebra_vni_t *zvni = (zebra_vni_t *)bucket->data;
+ struct evpn_mh_show_ctx *wctx = (struct evpn_mh_show_ctx *)ctxt;
+
+ zebra_evpn_es_evi_show_one_vni(zvni, wctx->vty,
+ wctx->json, wctx->detail);
+}
+
+void zebra_evpn_es_evi_show(struct vty *vty, bool uj, int detail)
+{
+ json_object *json = NULL;
+ struct zebra_vrf *zvrf;
+ struct evpn_mh_show_ctx wctx;
+
+ zvrf = zebra_vrf_get_evpn();
+
+ memset(&wctx, 0, sizeof(wctx));
+ wctx.vty = vty;
+ wctx.json = json;
+ wctx.detail = detail;
+
+ if (!detail && !json) {
+ vty_out(vty, "Type: L local, R remote\n");
+ vty_out(vty, "%-8s %-30s %-4s\n", "VNI", "ESI", "Type");
+ }
+ /* Display all L2-VNIs */
+ hash_iterate(zvrf->vni_table, zebra_evpn_es_evi_show_one_vni_hash_cb,
+ &wctx);
+}
+
+void zebra_evpn_es_evi_show_vni(struct vty *vty, bool uj, vni_t vni, int detail)
+{
+ json_object *json = NULL;
+ zebra_vni_t *zvni;
+
+ zvni = zvni_lookup(vni);
+ if (zvni) {
+ if (!detail && !json) {
+ vty_out(vty, "Type: L local, R remote\n");
+ vty_out(vty, "%-8s %-30s %-4s\n", "VNI", "ESI", "Type");
+ }
+ } else {
+ if (!uj)
+ vty_out(vty, "VNI %d doesn't exist\n", vni);
+ }
+ zebra_evpn_es_evi_show_one_vni(zvni, vty, json, detail);
+}
+
+/* Initialize the ES tables maintained per-L2_VNI */
+void zebra_evpn_vni_es_init(zebra_vni_t *zvni)
+{
+ /* Initialize the ES-EVI RB tree */
+ RB_INIT(zebra_es_evi_rb_head, &zvni->es_evi_rb_tree);
+
+ /* Initialize the local and remote ES lists maintained for quick
+ * walks by type
+ */
+ zvni->local_es_evi_list = list_new();
+ listset_app_node_mem(zvni->local_es_evi_list);
+}
+
+/* Cleanup the ES info maintained per-L2_VNI */
+void zebra_evpn_vni_es_cleanup(zebra_vni_t *zvni)
+{
+ struct zebra_evpn_es_evi *es_evi;
+ struct zebra_evpn_es_evi *es_evi_next;
+
+ RB_FOREACH_SAFE(es_evi, zebra_es_evi_rb_head,
+ &zvni->es_evi_rb_tree, es_evi_next) {
+ zebra_evpn_local_es_evi_do_del(es_evi);
+ }
+
+ list_delete(&zvni->local_es_evi_list);
+ zebra_evpn_es_clear_base_vni(zvni);
+}
+
+/* called when the oper state or bridge membership changes for the
+ * vxlan device
+ */
+void zebra_evpn_vni_update_all_es(zebra_vni_t *zvni)
+{
+ struct zebra_evpn_es_evi *es_evi;
+ struct listnode *node;
+
+ /* the VNI is now elgible as a base for EVPN-MH */
+ if (zebra_evpn_vni_send_to_client_ok(zvni))
+ zebra_evpn_es_set_base_vni(zvni);
+ else
+ zebra_evpn_es_clear_base_vni(zvni);
+
+ for (ALL_LIST_ELEMENTS_RO(zvni->local_es_evi_list, node, es_evi))
+ zebra_evpn_es_evi_re_eval_send_to_client(es_evi);
+}
+
+/*****************************************************************************/
+/* Access broadcast domains (BD)
+ * 1. These broadcast domains can be VLAN aware (in which case
+ * the key is VID) or VLAN unaware (in which case the key is
+ * 2. A VID-BD is created when a VLAN is associated with an access port or
+ * when the VLAN is associated with VXLAN_IF
+ * 3. A BD is translated into ES-EVI entries when a VNI is associated
+ * with the broadcast domain
+ */
+/* Hash key for VLAN based broadcast domains */
+static unsigned int zebra_evpn_acc_vl_hash_keymake(const void *p)
+{
+ const struct zebra_evpn_access_bd *acc_bd = p;
+
+ return jhash_1word(acc_bd->vid, 0);
+}
+
+/* Compare two VLAN based broadcast domains */
+static bool zebra_evpn_acc_vl_cmp(const void *p1, const void *p2)
+{
+ const struct zebra_evpn_access_bd *acc_bd1 = p1;
+ const struct zebra_evpn_access_bd *acc_bd2 = p2;
+
+ if (acc_bd1 == NULL && acc_bd2 == NULL)
+ return true;
+
+ if (acc_bd1 == NULL || acc_bd2 == NULL)
+ return false;
+
+ return (acc_bd1->vid == acc_bd2->vid);
+}
+
+/* Lookup VLAN based broadcast domain */
+static struct zebra_evpn_access_bd *zebra_evpn_acc_vl_find(vlanid_t vid)
+{
+ struct zebra_evpn_access_bd *acc_bd;
+ struct zebra_evpn_access_bd tmp;
+
+ tmp.vid = vid;
+ acc_bd = hash_lookup(zmh_info->evpn_vlan_table, &tmp);
+
+ return acc_bd;
+}
+
+/* A new broadcast domain can be created when a VLAN member or VLAN<=>VxLAN_IF
+ * mapping is added.
+ */
+static struct zebra_evpn_access_bd *zebra_evpn_acc_vl_new(vlanid_t vid)
+{
+ struct zebra_evpn_access_bd *acc_bd;
+
+ if (IS_ZEBRA_DEBUG_EVPN_MH_ES)
+ zlog_debug("access vlan %d add", vid);
+
+ acc_bd = XCALLOC(MTYPE_ZACC_BD, sizeof(struct zebra_evpn_access_bd));
+
+ acc_bd->vid = vid;
+
+ /* Initialize the mbr list */
+ acc_bd->mbr_zifs = list_new();
+
+ /* Add to hash */
+ if (!hash_get(zmh_info->evpn_vlan_table, acc_bd, hash_alloc_intern)) {
+ XFREE(MTYPE_ZACC_BD, acc_bd);
+ return NULL;
+ }
+
+ return acc_bd;
+}
+
+/* Free VLAN based broadcast domain -
+ * This just frees appropriate memory, caller should have taken other
+ * needed actions.
+ */
+static void zebra_evpn_acc_vl_free(struct zebra_evpn_access_bd *acc_bd)
+{
+ if (IS_ZEBRA_DEBUG_EVPN_MH_ES)
+ zlog_debug("access vlan %d del", acc_bd->vid);
+
+ /* cleanup resources maintained against the ES */
+ list_delete(&acc_bd->mbr_zifs);
+
+ /* remove EVI from various tables */
+ hash_release(zmh_info->evpn_vlan_table, acc_bd);
+
+ XFREE(MTYPE_ZACC_BD, acc_bd);
+}
+
+static void zebra_evpn_acc_vl_cleanup_all(struct hash_bucket *bucket, void *arg)
+{
+ struct zebra_evpn_access_bd *acc_bd = bucket->data;
+
+ zebra_evpn_acc_vl_free(acc_bd);
+}
+
+/* called when a bd mbr is removed or VxLAN_IF is diassociated from the access
+ * VLAN
+ */
+static void zebra_evpn_acc_bd_free_on_deref(struct zebra_evpn_access_bd *acc_bd)
+{
+ if (!list_isempty(acc_bd->mbr_zifs) || acc_bd->vxlan_zif)
+ return;
+
+ /* if there are no references free the EVI */
+ zebra_evpn_acc_vl_free(acc_bd);
+}
+
+/* called when a EVPN-L2VNI is set or cleared against a BD */
+static void zebra_evpn_acc_bd_vni_set(struct zebra_evpn_access_bd *acc_bd,
+ zebra_vni_t *zvni, zebra_vni_t *old_zvni)
+{
+ struct zebra_if *zif;
+ struct listnode *node;
+
+ if (IS_ZEBRA_DEBUG_EVPN_MH_ES)
+ zlog_debug("access vlan %d l2-vni %u set",
+ acc_bd->vid, zvni ? zvni->vni : 0);
+
+ for (ALL_LIST_ELEMENTS_RO(acc_bd->mbr_zifs, node, zif)) {
+ if (!zif->es_info.es)
+ continue;
+
+ if (zvni)
+ zebra_evpn_local_es_evi_add(zif->es_info.es, zvni);
+ else if (old_zvni)
+ zebra_evpn_local_es_evi_del(zif->es_info.es, old_zvni);
+ }
+}
+
+/* handle VLAN->VxLAN_IF association */
+void zebra_evpn_vl_vxl_ref(uint16_t vid, struct zebra_if *vxlan_zif)
+{
+ struct zebra_evpn_access_bd *acc_bd;
+ struct zebra_if *old_vxlan_zif;
+ zebra_vni_t *old_zvni;
+
+ if (!vid)
+ return;
+
+ acc_bd = zebra_evpn_acc_vl_find(vid);
+ if (!acc_bd)
+ acc_bd = zebra_evpn_acc_vl_new(vid);
+
+ old_vxlan_zif = acc_bd->vxlan_zif;
+ acc_bd->vxlan_zif = vxlan_zif;
+ if (vxlan_zif == old_vxlan_zif)
+ return;
+
+ old_zvni = acc_bd->zvni;
+ acc_bd->zvni = zvni_lookup(vxlan_zif->l2info.vxl.vni);
+ if (acc_bd->zvni == old_zvni)
+ return;
+
+ if (IS_ZEBRA_DEBUG_EVPN_MH_ES)
+ zlog_debug("access vlan %d vni %u ref",
+ acc_bd->vid, vxlan_zif->l2info.vxl.vni);
+
+ if (old_zvni)
+ zebra_evpn_acc_bd_vni_set(acc_bd, NULL, old_zvni);
+
+ if (acc_bd->zvni)
+ zebra_evpn_acc_bd_vni_set(acc_bd, acc_bd->zvni, NULL);
+}
+
+/* handle VLAN->VxLAN_IF deref */
+void zebra_evpn_vl_vxl_deref(uint16_t vid, struct zebra_if *vxlan_zif)
+{
+ struct zebra_evpn_access_bd *acc_bd;
+
+ if (!vid)
+ return;
+
+ acc_bd = zebra_evpn_acc_vl_find(vid);
+ if (!acc_bd)
+ return;
+
+ /* clear vxlan_if only if it matches */
+ if (acc_bd->vxlan_zif != vxlan_zif)
+ return;
+
+ if (IS_ZEBRA_DEBUG_EVPN_MH_ES)
+ zlog_debug("access vlan %d vni %u deref",
+ acc_bd->vid, vxlan_zif->l2info.vxl.vni);
+
+ if (acc_bd->zvni)
+ zebra_evpn_acc_bd_vni_set(acc_bd, NULL, acc_bd->zvni);
+
+ acc_bd->zvni = NULL;
+ acc_bd->vxlan_zif = NULL;
+
+ /* if there are no other references the access_bd can be freed */
+ zebra_evpn_acc_bd_free_on_deref(acc_bd);
+}
+
+/* handle EVPN L2VNI add/del */
+void zebra_evpn_vxl_vni_set(struct zebra_if *zif, zebra_vni_t *zvni,
+ bool set)
+{
+ struct zebra_l2info_vxlan *vxl;
+ struct zebra_evpn_access_bd *acc_bd;
+
+ if (!zif)
+ return;
+
+ /* locate access_bd associated with the vxlan device */
+ vxl = &zif->l2info.vxl;
+ acc_bd = zebra_evpn_acc_vl_find(vxl->access_vlan);
+ if (!acc_bd)
+ return;
+
+ if (set) {
+ zebra_evpn_es_set_base_vni(zvni);
+ if (acc_bd->zvni != zvni) {
+ acc_bd->zvni = zvni;
+ zebra_evpn_acc_bd_vni_set(acc_bd, zvni, NULL);
+ }
+ } else {
+ if (acc_bd->zvni) {
+ zebra_vni_t *old_zvni = acc_bd->zvni;
+ acc_bd->zvni = NULL;
+ zebra_evpn_acc_bd_vni_set(acc_bd, NULL, old_zvni);
+ }
+ }
+}
+
+/* handle addition of new VLAN members */
+void zebra_evpn_vl_mbr_ref(uint16_t vid, struct zebra_if *zif)
+{
+ struct zebra_evpn_access_bd *acc_bd;
+
+ if (!vid)
+ return;
+
+ acc_bd = zebra_evpn_acc_vl_find(vid);
+ if (!acc_bd)
+ acc_bd = zebra_evpn_acc_vl_new(vid);
+
+ if (listnode_lookup(acc_bd->mbr_zifs, zif))
+ return;
+
+ if (IS_ZEBRA_DEBUG_EVPN_MH_ES)
+ zlog_debug("access vlan %d mbr %s ref",
+ vid, zif->ifp->name);
+
+ listnode_add(acc_bd->mbr_zifs, zif);
+ if (acc_bd->zvni && zif->es_info.es)
+ zebra_evpn_local_es_evi_add(zif->es_info.es, acc_bd->zvni);
+}
+
+/* handle deletion of VLAN members */
+void zebra_evpn_vl_mbr_deref(uint16_t vid, struct zebra_if *zif)
+{
+ struct zebra_evpn_access_bd *acc_bd;
+ struct listnode *node;
+
+ if (!vid)
+ return;
+
+ acc_bd = zebra_evpn_acc_vl_find(vid);
+ if (!acc_bd)
+ return;
+
+ node = listnode_lookup(acc_bd->mbr_zifs, zif);
+ if (!node)
+ return;
+
+ if (IS_ZEBRA_DEBUG_EVPN_MH_ES)
+ zlog_debug("access vlan %d mbr %s deref",
+ vid, zif->ifp->name);
+
+ list_delete_node(acc_bd->mbr_zifs, node);
+
+ if (acc_bd->zvni && zif->es_info.es)
+ zebra_evpn_local_es_evi_del(zif->es_info.es, acc_bd->zvni);
+
+ /* if there are no other references the access_bd can be freed */
+ zebra_evpn_acc_bd_free_on_deref(acc_bd);
+}
+
+static void zebra_evpn_acc_vl_show_entry_detail(struct vty *vty,
+ struct zebra_evpn_access_bd *acc_bd, json_object *json)
+{
+ struct zebra_if *zif;
+ struct listnode *node;
+
+ if (json) {
+ /* XXX */
+ } else {
+ vty_out(vty, "VLAN: %u\n", acc_bd->vid);
+ vty_out(vty, " VxLAN Interface: %s\n",
+ acc_bd->vxlan_zif ?
+ acc_bd->vxlan_zif->ifp->name : "-");
+ vty_out(vty, " L2-VNI: %d\n",
+ acc_bd->zvni ? acc_bd->zvni->vni : 0);
+ vty_out(vty, " Member Count: %d\n",
+ listcount(acc_bd->mbr_zifs));
+ vty_out(vty, " Members: \n");
+ for (ALL_LIST_ELEMENTS_RO(acc_bd->mbr_zifs, node, zif))
+ vty_out(vty, " %s\n", zif->ifp->name);
+ vty_out(vty, "\n");
+ }
+}
+
+static void zebra_evpn_acc_vl_show_entry(struct vty *vty,
+ struct zebra_evpn_access_bd *acc_bd, json_object *json)
+{
+ if (!json)
+ vty_out(vty, "%-5u %21s %-8d %u\n",
+ acc_bd->vid,
+ acc_bd->vxlan_zif ?
+ acc_bd->vxlan_zif->ifp->name : "-",
+ acc_bd->zvni ? acc_bd->zvni->vni : 0,
+ listcount(acc_bd->mbr_zifs));
+}
+
+static void zebra_evpn_acc_vl_show_hash(struct hash_bucket *bucket, void *ctxt)
+{
+ struct evpn_mh_show_ctx *wctx = ctxt;
+ struct zebra_evpn_access_bd *acc_bd = bucket->data;
+
+ if (wctx->detail)
+ zebra_evpn_acc_vl_show_entry_detail(wctx->vty,
+ acc_bd, wctx->json);
+ else
+ zebra_evpn_acc_vl_show_entry(wctx->vty,
+ acc_bd, wctx->json);
+}
+
+void zebra_evpn_acc_vl_show(struct vty *vty, bool uj)
+{
+ json_object *json = NULL;
+ struct evpn_mh_show_ctx wctx;
+
+ memset(&wctx, 0, sizeof(wctx));
+ wctx.vty = vty;
+ wctx.json = json;
+ wctx.detail = false;
+
+ if (!json)
+ vty_out(vty, "%-5s %21s %-8s %s\n",
+ "VLAN", "VxLAN-IF", "L2-VNI", "# Members");
+
+ hash_iterate(zmh_info->evpn_vlan_table, zebra_evpn_acc_vl_show_hash,
+ &wctx);
+}
+
+void zebra_evpn_acc_vl_show_detail(struct vty *vty, bool uj)
+{
+ json_object *json = NULL;
+ struct evpn_mh_show_ctx wctx;
+
+ memset(&wctx, 0, sizeof(wctx));
+ wctx.vty = vty;
+ wctx.json = json;
+ wctx.detail = true;
+
+ hash_iterate(zmh_info->evpn_vlan_table, zebra_evpn_acc_vl_show_hash,
+ &wctx);
+}
+
+void zebra_evpn_acc_vl_show_vid(struct vty *vty, bool uj, vlanid_t vid)
+{
+ json_object *json = NULL;
+ struct zebra_evpn_access_bd *acc_bd;
+
+ acc_bd = zebra_evpn_acc_vl_find(vid);
+ if (!acc_bd) {
+ if (!json) {
+ vty_out(vty, "VLAN %u not present\n", vid);
+ return;
+ }
+ }
+ zebra_evpn_acc_vl_show_entry_detail(vty, acc_bd, json);
+}
+
+/* Initialize VLAN member bitmap on an interface. Although VLAN membership
+ * is independent of EVPN we only process it if its of interest to EVPN-MH
+ * i.e. on access ports that can be setup as Ethernet Segments. And that is
+ * intended as an optimization.
+ */
+void zebra_evpn_if_init(struct zebra_if *zif)
+{
+ if (!zebra_evpn_is_if_es_capable(zif))
+ return;
+
+ if (!bf_is_inited(zif->vlan_bitmap))
+ bf_init(zif->vlan_bitmap, IF_VLAN_BITMAP_MAX);
+
+ /* if an es_id and sysmac are already present against the interface
+ * activate it
+ */
+ zebra_evpn_local_es_update(zif, zif->es_info.lid, &zif->es_info.sysmac);
+}
+
+/* handle deletion of an access port by removing it from all associated
+ * broadcast domains.
+ */
+void zebra_evpn_if_cleanup(struct zebra_if *zif)
+{
+ vlanid_t vid;
+
+ if (!bf_is_inited(zif->vlan_bitmap))
+ return;
+
+ bf_for_each_set_bit(zif->vlan_bitmap, vid, IF_VLAN_BITMAP_MAX) {
+ zebra_evpn_vl_mbr_deref(vid, zif);
+ }
+
+ bf_free(zif->vlan_bitmap);
+
+ /* Delete associated Ethernet Segment */
+ if (zif->es_info.es)
+ zebra_evpn_local_es_del(zif->es_info.es);
+}
+
+/*****************************************************************************
+ * L2 NH/NHG Management
+ * A L2 NH entry is programmed in the kernel for every ES-VTEP entry. This
+ * NH is then added to the L2-ECMP-NHG associated with the ES.
+ */
+static uint32_t zebra_evpn_nhid_alloc(bool is_nhg)
+{
+ uint32_t id;
+ int type;
+
+ bf_assign_index(zmh_info->nh_id_bitmap, id);
+
+ if (!id)
+ return 0;
+
+ type = is_nhg ? EVPN_NHG_ID_TYPE_BIT : EVPN_NH_ID_TYPE_BIT;
+ return (id | type);
+}
+
+static void zebra_evpn_nhid_free(uint32_t nh_id)
+{
+ uint32_t id = (nh_id & EVPN_NH_ID_VAL_MASK);
+
+ if (!id)
+ return;
+
+ bf_release_index(zmh_info->nh_id_bitmap, id);
+}
+
+/* The MAC ECMP group is activated on the first VTEP */
+static void zebra_evpn_nhg_update(struct zebra_evpn_es *es)
+{
+ uint32_t nh_cnt = 0;
+ struct nh_grp nh_ids[ES_VTEP_MAX_CNT];
+ struct zebra_evpn_es_vtep *es_vtep;
+ struct listnode *node;
+
+ if (!es->nhg_id)
+ return;
+
+ for (ALL_LIST_ELEMENTS_RO(es->es_vtep_list, node, es_vtep)) {
+ if (!es_vtep->nh_id)
+ continue;
+
+ if (nh_cnt >= ES_VTEP_MAX_CNT)
+ break;
+
+ memset(&nh_ids[nh_cnt], 0, sizeof(struct nh_grp));
+ nh_ids[nh_cnt].id = es_vtep->nh_id;
+ ++nh_cnt;
+ }
+
+ if (nh_cnt) {
+ if (IS_ZEBRA_DEBUG_EVPN_MH_NH) {
+ char nh_str[ES_VTEP_LIST_STR_SZ];
+ uint32_t i;
+ char nh_buf[16];
+
+ nh_str[0] = '\0';
+ for (i = 0; i < nh_cnt; ++i) {
+ snprintf(nh_buf, sizeof(nh_buf), "%u ",
+ nh_ids[i].id);
+ strlcat(nh_str, nh_buf, sizeof(nh_str));
+ }
+ zlog_debug("es %s nhg 0x%x add %s",
+ es->esi_str, es->nhg_id, nh_str);
+ }
+
+ es->flags |= ZEBRA_EVPNES_NHG_ACTIVE;
+ kernel_upd_mac_nhg(es->nhg_id, nh_cnt, nh_ids);
+ } else {
+ if (es->flags & ZEBRA_EVPNES_NHG_ACTIVE) {
+ if (IS_ZEBRA_DEBUG_EVPN_MH_NH)
+ zlog_debug("es %s nhg 0x%x del",
+ es->esi_str, es->nhg_id);
+ es->flags &= ~ZEBRA_EVPNES_NHG_ACTIVE;
+ kernel_del_mac_nhg(es->nhg_id);
+ }
+ }
+
+ /* XXX - update remote macs associated with the ES */
+}
+
+static void zebra_evpn_nh_add(struct zebra_evpn_es_vtep *es_vtep)
+{
+ if (es_vtep->nh_id)
+ return;
+
+ es_vtep->nh_id = zebra_evpn_nhid_alloc(false);
+
+ if (!es_vtep->nh_id)
+ return;
+
+ if (IS_ZEBRA_DEBUG_EVPN_MH_NH)
+ zlog_debug("es %s vtep %s nh 0x%x add",
+ es_vtep->es->esi_str,
+ inet_ntoa(es_vtep->vtep_ip), es_vtep->nh_id);
+ /* install the NH */
+ kernel_upd_mac_nh(es_vtep->nh_id, es_vtep->vtep_ip);
+ /* add the NH to the parent NHG */
+ zebra_evpn_nhg_update(es_vtep->es);
+}
+
+static void zebra_evpn_nh_del(struct zebra_evpn_es_vtep *es_vtep)
+{
+ uint32_t nh_id;
+
+ if (!es_vtep->nh_id)
+ return;
+
+ if (IS_ZEBRA_DEBUG_EVPN_MH_NH)
+ zlog_debug("es %s vtep %s nh 0x%x del",
+ es_vtep->es->esi_str,
+ inet_ntoa(es_vtep->vtep_ip), es_vtep->nh_id);
+
+ nh_id = es_vtep->nh_id;
+ es_vtep->nh_id = 0;
+
+ /* remove the NH from the parent NHG */
+ zebra_evpn_nhg_update(es_vtep->es);
+ /* uninstall the NH */
+ kernel_del_mac_nh(nh_id);
+ zebra_evpn_nhid_free(nh_id);
+
+}
+
+/*****************************************************************************/
+/* Ethernet Segment Management
+ * 1. Ethernet Segment is a collection of links attached to the same
+ * server (MHD) or switch (MHN)
+ * 2. An Ethernet Segment can span multiple PEs and is identified by the
+ * 10-byte ES-ID.
+ * 3. Zebra manages the local ESI configuration.
+ * 4. It also maintains the aliasing that maps an ESI (local or remote)
+ * to one or more PEs/VTEPs.
+ * 5. remote ESs are added by BGP (on rxing EAD Type-1 routes)
+ */
+/* A list of remote VTEPs is maintained for each ES. This list includes -
+ * 1. VTEPs for which we have imported the ESR i.e. ES-peers
+ * 2. VTEPs that have an "active" ES-EVI VTEP i.e. EAD-per-ES and EAD-per-EVI
+ * have been imported into one or more VNIs
+ */
+static int zebra_evpn_es_vtep_cmp(void *p1, void *p2)
+{
+ const struct zebra_evpn_es_vtep *es_vtep1 = p1;
+ const struct zebra_evpn_es_vtep *es_vtep2 = p2;
+
+ return es_vtep1->vtep_ip.s_addr - es_vtep2->vtep_ip.s_addr;
+}
+
+static struct zebra_evpn_es_vtep *zebra_evpn_es_vtep_new(
+ struct zebra_evpn_es *es, struct in_addr vtep_ip)
+{
+ struct zebra_evpn_es_vtep *es_vtep;
+
+ es_vtep = XCALLOC(MTYPE_ZES_VTEP, sizeof(*es_vtep));
+
+ es_vtep->es = es;
+ es_vtep->vtep_ip.s_addr = vtep_ip.s_addr;
+ listnode_init(&es_vtep->es_listnode, es_vtep);
+ listnode_add_sort(es->es_vtep_list, &es_vtep->es_listnode);
+
+ return es_vtep;
+}
+
+static void zebra_evpn_es_vtep_free(struct zebra_evpn_es_vtep *es_vtep)
+{
+ struct zebra_evpn_es *es = es_vtep->es;
+
+ list_delete_node(es->es_vtep_list, &es_vtep->es_listnode);
+ /* update the L2-NHG associated with the ES */
+ zebra_evpn_nh_del(es_vtep);
+ XFREE(MTYPE_ZES_VTEP, es_vtep);
+}
+
+
+/* check if VTEP is already part of the list */
+static struct zebra_evpn_es_vtep *zebra_evpn_es_vtep_find(
+ struct zebra_evpn_es *es, struct in_addr vtep_ip)
+{
+ struct listnode *node = NULL;
+ struct zebra_evpn_es_vtep *es_vtep;
+
+ for (ALL_LIST_ELEMENTS_RO(es->es_vtep_list, node, es_vtep)) {
+ if (es_vtep->vtep_ip.s_addr == vtep_ip.s_addr)
+ return es_vtep;
+ }
+ return NULL;
+}
+
+static void zebra_evpn_es_vtep_add(struct zebra_evpn_es *es,
+ struct in_addr vtep_ip)
+{
+ struct zebra_evpn_es_vtep *es_vtep;
+
+ es_vtep = zebra_evpn_es_vtep_find(es, vtep_ip);
+
+ if (!es_vtep) {
+ if (IS_ZEBRA_DEBUG_EVPN_MH_ES)
+ zlog_debug("es %s vtep %s add",
+ es->esi_str, inet_ntoa(vtep_ip));
+ es_vtep = zebra_evpn_es_vtep_new(es, vtep_ip);
+ /* update the L2-NHG associated with the ES */
+ zebra_evpn_nh_add(es_vtep);
+ }
+}
+
+static void zebra_evpn_es_vtep_del(struct zebra_evpn_es *es,
+ struct in_addr vtep_ip)
+{
+ struct zebra_evpn_es_vtep *es_vtep;
+
+ es_vtep = zebra_evpn_es_vtep_find(es, vtep_ip);
+
+ if (es_vtep) {
+ if (IS_ZEBRA_DEBUG_EVPN_MH_ES)
+ zlog_debug("es %s vtep %s del",
+ es->esi_str, inet_ntoa(vtep_ip));
+ zebra_evpn_es_vtep_free(es_vtep);
+ }
+}
+
+/* compare ES-IDs for the global ES RB tree */
+static int zebra_es_rb_cmp(const struct zebra_evpn_es *es1,
+ const struct zebra_evpn_es *es2)
+{
+ return memcmp(&es1->esi, &es2->esi, ESI_BYTES);
+}
+RB_GENERATE(zebra_es_rb_head, zebra_evpn_es, rb_node, zebra_es_rb_cmp);
+
+/* Lookup ES */
+struct zebra_evpn_es *zebra_evpn_es_find(esi_t *esi)
+{
+ struct zebra_evpn_es tmp;
+
+ memcpy(&tmp.esi, esi, sizeof(esi_t));
+ return RB_FIND(zebra_es_rb_head, &zmh_info->es_rb_tree, &tmp);
+}
+
+/* A new local es is created when a local-es-id and sysmac is configured
+ * against an interface.
+ */
+static struct zebra_evpn_es *zebra_evpn_es_new(esi_t *esi)
+{
+ struct zebra_evpn_es *es;
+
+ es = XCALLOC(MTYPE_ZES, sizeof(struct zebra_evpn_es));
+
+ /* fill in ESI */
+ memcpy(&es->esi, esi, sizeof(esi_t));
+ esi_to_str(&es->esi, es->esi_str, sizeof(es->esi_str));
+
+ /* Add to rb_tree */
+ if (RB_INSERT(zebra_es_rb_head, &zmh_info->es_rb_tree, es)) {
+ XFREE(MTYPE_ZES, es);
+ return NULL;
+ }
+
+ /* Initialise the ES-EVI list */
+ es->es_evi_list = list_new();
+ listset_app_node_mem(es->es_evi_list);
+
+ /* Initialise the VTEP list */
+ es->es_vtep_list = list_new();
+ listset_app_node_mem(es->es_vtep_list);
+ es->es_vtep_list->cmp = zebra_evpn_es_vtep_cmp;
+
+ /* mac entries associated with the ES */
+ es->mac_list = list_new();
+ listset_app_node_mem(es->mac_list);
+
+ /* reserve a NHG */
+ es->nhg_id = zebra_evpn_nhid_alloc(true);
+
+ if (IS_ZEBRA_DEBUG_EVPN_MH_ES)
+ zlog_debug("es %s nhg 0x%x new", es->esi_str, es->nhg_id);
+
+ return es;
+}
+
+/* Free a given ES -
+ * This just frees appropriate memory, caller should have taken other
+ * needed actions.
+ */
+static struct zebra_evpn_es *zebra_evpn_es_free(struct zebra_evpn_es *es)
+{
+ /* If the ES has a local or remote reference it cannot be freed.
+ * Free is also prevented if there are MAC entries referencing
+ * it.
+ */
+ if ((es->flags & (ZEBRA_EVPNES_LOCAL | ZEBRA_EVPNES_REMOTE)) ||
+ listcount(es->mac_list))
+ return es;
+
+ if (IS_ZEBRA_DEBUG_EVPN_MH_ES)
+ zlog_debug("es %s free", es->esi_str);
+
+ /* If the NHG is still installed uninstall it and free the id */
+ if (es->flags & ZEBRA_EVPNES_NHG_ACTIVE) {
+ es->flags &= ~ZEBRA_EVPNES_NHG_ACTIVE;
+ kernel_del_mac_nhg(es->nhg_id);
+ }
+ zebra_evpn_nhid_free(es->nhg_id);
+
+ /* cleanup resources maintained against the ES */
+ list_delete(&es->es_evi_list);
+ list_delete(&es->es_vtep_list);
+ list_delete(&es->mac_list);
+
+ /* remove from the VNI-ESI rb tree */
+ RB_REMOVE(zebra_es_rb_head, &zmh_info->es_rb_tree, es);
+
+ XFREE(MTYPE_ZES, es);
+
+ return NULL;
+}
+
+/* Inform BGP about local ES addition */
+static int zebra_evpn_es_send_add_to_client(struct zebra_evpn_es *es)
+{
+ struct zserv *client;
+ struct stream *s;
+ uint8_t oper_up;
+
+ client = zserv_find_client(ZEBRA_ROUTE_BGP, 0);
+ /* BGP may not be running. */
+ if (!client)
+ return 0;
+
+ s = stream_new(ZEBRA_MAX_PACKET_SIZ);
+
+ zclient_create_header(s, ZEBRA_LOCAL_ES_ADD, zebra_vrf_get_evpn_id());
+ stream_put(s, &es->esi, sizeof(esi_t));
+ stream_put_ipv4(s, zmh_info->es_originator_ip.s_addr);
+ oper_up = !!(es->flags & ZEBRA_EVPNES_OPER_UP);
+ stream_putc(s, oper_up);
+
+ /* Write packet size. */
+ stream_putw_at(s, 0, stream_get_endp(s));
+
+ if (IS_ZEBRA_DEBUG_EVPN_MH_ES)
+ zlog_debug("send add local es %s %s to %s",
+ es->esi_str,
+ inet_ntoa(zmh_info->es_originator_ip),
+ zebra_route_string(client->proto));
+
+ client->local_es_add_cnt++;
+ return zserv_send_message(client, s);
+}
+
+/* Inform BGP about local ES deletion */
+static int zebra_evpn_es_send_del_to_client(struct zebra_evpn_es *es)
+{
+ struct zserv *client;
+ struct stream *s;
+
+ client = zserv_find_client(ZEBRA_ROUTE_BGP, 0);
+ /* BGP may not be running. */
+ if (!client)
+ return 0;
+
+ s = stream_new(ZEBRA_MAX_PACKET_SIZ);
+ stream_reset(s);
+
+ zclient_create_header(s, ZEBRA_LOCAL_ES_DEL, zebra_vrf_get_evpn_id());
+ stream_put(s, &es->esi, sizeof(esi_t));
+
+ /* Write packet size. */
+ stream_putw_at(s, 0, stream_get_endp(s));
+
+ if (IS_ZEBRA_DEBUG_EVPN_MH_ES)
+ zlog_debug("send del local es %s to %s", es->esi_str,
+ zebra_route_string(client->proto));
+
+ client->local_es_del_cnt++;
+ return zserv_send_message(client, s);
+}
+
+/* XXX - call any time ZEBRA_EVPNES_LOCAL gets set or cleared */
+static void zebra_evpn_es_re_eval_send_to_client(struct zebra_evpn_es *es,
+ bool es_evi_re_reval)
+{
+ bool old_ready;
+ bool new_ready;
+ struct listnode *node;
+ struct zebra_evpn_es_evi *es_evi;
+
+ old_ready = !!(es->flags & ZEBRA_EVPNES_READY_FOR_BGP);
+
+ if ((es->flags & ZEBRA_EVPNES_LOCAL) &&
+ zmh_info->es_originator_ip.s_addr)
+ es->flags |= ZEBRA_EVPNES_READY_FOR_BGP;
+ else
+ es->flags &= ~ZEBRA_EVPNES_READY_FOR_BGP;
+
+ new_ready = !!(es->flags & ZEBRA_EVPNES_READY_FOR_BGP);
+ if (old_ready == new_ready)
+ return;
+
+ if (new_ready)
+ zebra_evpn_es_send_add_to_client(es);
+ else
+ zebra_evpn_es_send_del_to_client(es);
+
+ /* re-eval associated EVIs */
+ if (es_evi_re_reval) {
+ for (ALL_LIST_ELEMENTS_RO(es->es_evi_list, node, es_evi)) {
+ if (!(es_evi->flags & ZEBRA_EVPNES_EVI_LOCAL))
+ continue;
+ zebra_evpn_es_evi_re_eval_send_to_client(es_evi);
+ }
+ }
+}
+
+void zebra_evpn_es_send_all_to_client(bool add)
+{
+ struct listnode *es_node;
+ struct listnode *evi_node;
+ struct zebra_evpn_es *es;
+ struct zebra_evpn_es_evi *es_evi;
+
+ if (!zmh_info)
+ return;
+
+ for (ALL_LIST_ELEMENTS_RO(zmh_info->local_es_list, es_node, es)) {
+ if (es->flags & ZEBRA_EVPNES_READY_FOR_BGP) {
+ if (add)
+ zebra_evpn_es_send_add_to_client(es);
+ for (ALL_LIST_ELEMENTS_RO(es->es_evi_list,
+ evi_node, es_evi)) {
+ if (!(es_evi->flags &
+ ZEBRA_EVPNES_EVI_READY_FOR_BGP))
+ continue;
+
+ if (add)
+ zebra_evpn_es_evi_send_to_client(
+ es, es_evi->zvni,
+ true /* add */);
+ else
+ zebra_evpn_es_evi_send_to_client(
+ es, es_evi->zvni,
+ false /* add */);
+ }
+ if (!add)
+ zebra_evpn_es_send_del_to_client(es);
+ }
+ }
+}
+
+/* walk the vlan bitmap associated with the zif and create or delete
+ * es_evis for all vlans associated with a VNI.
+ * XXX: This API is really expensive. optimize later if possible.
+ */
+static void zebra_evpn_es_setup_evis(struct zebra_evpn_es *es)
+{
+ struct zebra_if *zif = es->zif;
+ uint16_t vid;
+ struct zebra_evpn_access_bd *acc_bd;
+
+
+ bf_for_each_set_bit(zif->vlan_bitmap, vid, IF_VLAN_BITMAP_MAX) {
+ acc_bd = zebra_evpn_acc_vl_find(vid);
+ if (acc_bd->zvni)
+ zebra_evpn_local_es_evi_add(es, acc_bd->zvni);
+ }
+}
+
+static void zebra_evpn_es_local_mac_update(struct zebra_evpn_es *es,
+ bool force_clear_static)
+{
+ zebra_mac_t *mac;
+ struct listnode *node;
+
+ for (ALL_LIST_ELEMENTS_RO(es->mac_list, node, mac)) {
+ if (CHECK_FLAG(mac->flags, ZEBRA_MAC_ES_PEER_ACTIVE)) {
+ zebra_vxlan_sync_mac_dp_install(mac,
+ false /* set_inactive */,
+ force_clear_static, __func__);
+ }
+ }
+}
+
+static void zebra_evpn_es_local_info_set(struct zebra_evpn_es *es,
+ struct zebra_if *zif)
+{
+ if (es->flags & ZEBRA_EVPNES_LOCAL)
+ return;
+
+ if (IS_ZEBRA_DEBUG_EVPN_MH_ES)
+ zlog_debug("local es %s add; nhg 0x%x if %s",
+ es->esi_str, es->nhg_id, zif->ifp->name);
+
+ es->flags |= ZEBRA_EVPNES_LOCAL;
+ listnode_init(&es->local_es_listnode, es);
+ listnode_add(zmh_info->local_es_list, &es->local_es_listnode);
+
+ /* attach es to interface */
+ zif->es_info.es = es;
+
+ /* attach interface to es */
+ es->zif = zif;
+ if (if_is_operative(zif->ifp))
+ es->flags |= ZEBRA_EVPNES_OPER_UP;
+
+ /* setup base-vni if one doesn't already exist; the ES will get sent
+ * to BGP as a part of that process
+ */
+ if (!zmh_info->es_base_vni)
+ zebra_evpn_es_get_one_base_vni();
+ else
+ /* send notification to bgp */
+ zebra_evpn_es_re_eval_send_to_client(es,
+ false /* es_evi_re_reval */);
+
+ /* Setup ES-EVIs for all VxLAN stretched VLANs associated with
+ * the zif
+ */
+ zebra_evpn_es_setup_evis(es);
+ /* if there any local macs referring to the ES as dest we
+ * need to set the static reference on them if the MAC is
+ * synced from an ES peer
+ */
+ zebra_evpn_es_local_mac_update(es,
+ false /* force_clear_static */);
+}
+
+static void zebra_evpn_es_local_info_clear(struct zebra_evpn_es *es)
+{
+ struct zebra_if *zif;
+
+ if (!(es->flags & ZEBRA_EVPNES_LOCAL))
+ return;
+
+ es->flags &= ~ZEBRA_EVPNES_LOCAL;
+ /* if there any local macs referring to the ES as dest we
+ * need to clear the static reference on them
+ */
+ zebra_evpn_es_local_mac_update(es,
+ true /* force_clear_static */);
+
+ /* clear the es from the parent interface */
+ zif = es->zif;
+ zif->es_info.es = NULL;
+ es->zif = NULL;
+
+ /* remove from the ES list */
+ list_delete_node(zmh_info->local_es_list, &es->local_es_listnode);
+
+ /* free up the ES if there is no remote reference */
+ zebra_evpn_es_free(es);
+}
+
+/* Delete an ethernet segment and inform BGP */
+static void zebra_evpn_local_es_del(struct zebra_evpn_es *es)
+{
+ struct zebra_evpn_es_evi *es_evi;
+ struct listnode *node = NULL;
+ struct listnode *nnode = NULL;
+ struct zebra_if *zif;
+
+ if (!CHECK_FLAG(es->flags, ZEBRA_EVPNES_LOCAL))
+ return;
+
+ if (IS_ZEBRA_DEBUG_EVPN_MH_ES) {
+ zif = es->zif;
+ zlog_debug("local es %s del; nhg 0x%x if %s",
+ es->esi_str, es->nhg_id,
+ zif ? zif->ifp->name : "-");
+ }
+
+ /* remove all ES-EVIs associated with the ES */
+ for (ALL_LIST_ELEMENTS(es->es_evi_list, node, nnode, es_evi))
+ zebra_evpn_local_es_evi_do_del(es_evi);
+
+ /* send a del if the ES had been sent to BGP earlier */
+ if (es->flags & ZEBRA_EVPNES_READY_FOR_BGP)
+ zebra_evpn_es_send_del_to_client(es);
+
+ zebra_evpn_es_local_info_clear(es);
+}
+
+/* eval remote info associated with the ES */
+static void zebra_evpn_es_remote_info_re_eval(struct zebra_evpn_es *es)
+{
+ /* if there are remote VTEPs the ES-EVI is classified as "remote" */
+ if (listcount(es->es_vtep_list)) {
+ if (!(es->flags & ZEBRA_EVPNES_REMOTE)) {
+ es->flags |= ZEBRA_EVPNES_REMOTE;
+ if (IS_ZEBRA_DEBUG_EVPN_MH_ES)
+ zlog_debug("remote es %s add; nhg 0x%x",
+ es->esi_str, es->nhg_id);
+ }
+ } else {
+ if (es->flags & ZEBRA_EVPNES_REMOTE) {
+ es->flags &= ~ZEBRA_EVPNES_REMOTE;
+ if (IS_ZEBRA_DEBUG_EVPN_MH_ES)
+ zlog_debug("remote es %s del; nhg 0x%x",
+ es->esi_str, es->nhg_id);
+ zebra_evpn_es_free(es);
+ }
+ }
+}
+
+/* A new local es is created when a local-es-id and sysmac is configured
+ * against an interface.
+ */
+static int zebra_evpn_local_es_update(struct zebra_if *zif, uint32_t lid,
+ struct ethaddr *sysmac)
+{
+ struct zebra_evpn_es *old_es = zif->es_info.es;
+ struct zebra_evpn_es *es;
+ esi_t esi;
+ int offset = 0;
+ int field_bytes = 0;
+
+ /* Complete config of the ES-ID bootstraps the ES */
+ if (!lid || is_zero_mac(sysmac)) {
+ /* if in ES is attached to zif delete it */
+ if (old_es)
+ zebra_evpn_local_es_del(old_es);
+ return 0;
+ }
+
+ /* build 10-byte type-3-ESI -
+ * Type(1-byte), MAC(6-bytes), ES-LID (3-bytes)
+ */
+ field_bytes = 1;
+ esi.val[offset] = ESI_TYPE_MAC;
+ offset += field_bytes;
+
+ field_bytes = ETH_ALEN;
+ memcpy(&esi.val[offset], (uint8_t *)sysmac, field_bytes);
+ offset += field_bytes;
+
+ esi.val[offset++] = (uint8_t)(lid >> 16);
+ esi.val[offset++] = (uint8_t)(lid >> 8);
+ esi.val[offset++] = (uint8_t)lid;
+
+ if (old_es && !memcmp(&old_es->esi, &esi, sizeof(esi_t)))
+ /* dup - nothing to be done */
+ return 0;
+
+ /* release the old_es against the zif */
+ if (old_es)
+ zebra_evpn_local_es_del(old_es);
+
+ es = zebra_evpn_es_find(&esi);
+ if (es) {
+ /* if it exists against another interface flag an error */
+ if (es->zif && es->zif != zif)
+ return -1;
+ } else {
+ /* create new es */
+ es = zebra_evpn_es_new(&esi);
+ }
+
+ zebra_evpn_es_local_info_set(es, zif);
+
+ return 0;
+}
+
+static int zebra_evpn_remote_es_del(esi_t *esi, struct in_addr vtep_ip)
+{
+ char buf[ESI_STR_LEN];
+ struct zebra_evpn_es *es;
+
+ if (IS_ZEBRA_DEBUG_EVPN_MH_ES)
+ zlog_debug("remote es %s vtep %s del",
+ esi_to_str(esi, buf, sizeof(buf)),
+ inet_ntoa(vtep_ip));
+
+ es = zebra_evpn_es_find(esi);
+ if (!es) {
+ /* XXX - error log */
+ return -1;
+ }
+
+ zebra_evpn_es_vtep_del(es, vtep_ip);
+ zebra_evpn_es_remote_info_re_eval(es);
+
+ return 0;
+}
+
+/* force delete a remote ES on the way down */
+static void zebra_evpn_remote_es_flush(struct zebra_evpn_es *es)
+{
+ struct zebra_evpn_es_vtep *es_vtep;
+ struct listnode *node;
+ struct listnode *nnode;
+
+ for (ALL_LIST_ELEMENTS(es->es_vtep_list, node, nnode, es_vtep)) {
+ if (IS_ZEBRA_DEBUG_EVPN_MH_ES)
+ zlog_debug("es %s vtep %s flush",
+ es->esi_str,
+ inet_ntoa(es_vtep->vtep_ip));
+ zebra_evpn_es_vtep_free(es_vtep);
+ zebra_evpn_es_remote_info_re_eval(es);
+ }
+}
+
+static int zebra_evpn_remote_es_add(esi_t *esi, struct in_addr vtep_ip)
+{
+ char buf[ESI_STR_LEN];
+ struct zebra_evpn_es *es;
+
+ if (IS_ZEBRA_DEBUG_EVPN_MH_ES)
+ zlog_debug("remote es %s vtep %s add",
+ esi_to_str(esi, buf, sizeof(buf)),
+ inet_ntoa(vtep_ip));
+
+ es = zebra_evpn_es_find(esi);
+ if (!es) {
+ es = zebra_evpn_es_new(esi);
+ if (!es) {
+ /* XXX - error log */
+ return -1;
+ }
+ }
+
+ zebra_evpn_es_vtep_add(es, vtep_ip);
+ zebra_evpn_es_remote_info_re_eval(es);
+
+ return 0;
+}
+
+void zebra_evpn_proc_remote_es(ZAPI_HANDLER_ARGS)
+{
+ struct stream *s;
+ struct in_addr vtep_ip;
+ esi_t esi;
+
+ if (!is_evpn_enabled()) {
+ zlog_debug(
+ "%s: EVPN not enabled yet we received a es_add zapi call",
+ __PRETTY_FUNCTION__);
+ return;
+ }
+
+ memset(&esi, 0, sizeof(esi_t));
+ s = msg;
+
+ stream_get(&esi, s, sizeof(esi_t));
+ vtep_ip.s_addr = stream_get_ipv4(s);
+
+ if (hdr->command == ZEBRA_REMOTE_ES_VTEP_ADD)
+ zebra_evpn_remote_es_add(&esi, vtep_ip);
+ else
+ zebra_evpn_remote_es_del(&esi, vtep_ip);
+}
+
+void zebra_evpn_es_mac_deref_entry(zebra_mac_t *mac)
+{
+ struct zebra_evpn_es *es = mac->es;
+
+ mac->es = NULL;
+ if (!es)
+ return;
+
+ list_delete_node(es->mac_list, &mac->es_listnode);
+ if (!listcount(es->mac_list))
+ zebra_evpn_es_free(es);
+}
+
+/* Associate a MAC entry with a local or remote ES. Returns false if there
+ * was no ES change.
+ */
+bool zebra_evpn_es_mac_ref_entry(zebra_mac_t *mac, struct zebra_evpn_es *es)
+{
+ if (mac->es == es)
+ return false;
+
+ if (mac->es)
+ zebra_evpn_es_mac_deref_entry(mac);
+
+ if (!es)
+ return true;
+
+ mac->es = es;
+ listnode_init(&mac->es_listnode, mac);
+ listnode_add(es->mac_list, &mac->es_listnode);
+
+ return true;
+}
+
+bool zebra_evpn_es_mac_ref(zebra_mac_t *mac, esi_t *esi)
+{
+ struct zebra_evpn_es *es;
+
+ es = zebra_evpn_es_find(esi);
+ if (!es) {
+ es = zebra_evpn_es_new(esi);
+ if (IS_ZEBRA_DEBUG_EVPN_MH_ES)
+ zlog_debug("auto es %s add on mac ref", es->esi_str);
+ }
+
+ return zebra_evpn_es_mac_ref_entry(mac, es);
+}
+
+/* Inform BGP about local ES-EVI add or del */
+static int zebra_evpn_es_evi_send_to_client(struct zebra_evpn_es *es,
+ zebra_vni_t *zvni, bool add)
+{
+ struct zserv *client;
+ struct stream *s;
+
+ client = zserv_find_client(ZEBRA_ROUTE_BGP, 0);
+ /* BGP may not be running. */
+ if (!client)
+ return 0;
+
+ s = stream_new(ZEBRA_MAX_PACKET_SIZ);
+
+ zclient_create_header(s,
+ add ? ZEBRA_LOCAL_ES_EVI_ADD : ZEBRA_LOCAL_ES_EVI_DEL,
+ zebra_vrf_get_evpn_id());
+ stream_put(s, &es->esi, sizeof(esi_t));
+ stream_putl(s, zvni->vni);
+
+ /* Write packet size. */
+ stream_putw_at(s, 0, stream_get_endp(s));
+
+ if (IS_ZEBRA_DEBUG_EVPN_MH_ES)
+ zlog_debug("send %s local es %s evi %u to %s",
+ add ? "add" : "del",
+ es->esi_str, zvni->vni,
+ zebra_route_string(client->proto));
+
+ client->local_es_add_cnt++;
+ return zserv_send_message(client, s);
+}
+
+/* sysmac part of a local ESI has changed */
+static int zebra_evpn_es_sys_mac_update(struct zebra_if *zif,
+ struct ethaddr *sysmac)
+{
+ int rv;
+
+ rv = zebra_evpn_local_es_update(zif, zif->es_info.lid, sysmac);
+ if (!rv)
+ memcpy(&zif->es_info.sysmac, sysmac, sizeof(struct ethaddr));
+
+ return rv;
+}
+
+/* local-ID part of ESI has changed */
+static int zebra_evpn_es_lid_update(struct zebra_if *zif, uint32_t lid)
+{
+ int rv;
+
+ rv = zebra_evpn_local_es_update(zif, lid, &zif->es_info.sysmac);
+ if (!rv)
+ zif->es_info.lid = lid;
+
+ return rv;
+}
+
+void zebra_evpn_es_cleanup(void)
+{
+ struct zebra_evpn_es *es;
+ struct zebra_evpn_es *es_next;
+
+ RB_FOREACH_SAFE(es, zebra_es_rb_head,
+ &zmh_info->es_rb_tree, es_next) {
+ zebra_evpn_local_es_del(es);
+ zebra_evpn_remote_es_flush(es);
+ }
+}
+
+/* Only certain types of access ports can be setup as an Ethernet Segment */
+bool zebra_evpn_is_if_es_capable(struct zebra_if *zif)
+{
+ if (zif->zif_type == ZEBRA_IF_BOND)
+ return true;
+
+ /* XXX: allow swpX i.e. a regular ethernet port to be an ES link too */
+ return false;
+}
+
+void zebra_evpn_if_es_print(struct vty *vty, struct zebra_if *zif)
+{
+ char buf[ETHER_ADDR_STRLEN];
+
+ if (zif->es_info.lid || !is_zero_mac(&zif->es_info.sysmac))
+ vty_out(vty, " EVPN MH: ES id %u ES sysmac %s\n",
+ zif->es_info.lid,
+ prefix_mac2str(&zif->es_info.sysmac,
+ buf, sizeof(buf)));
+}
+
+void zebra_evpn_es_if_oper_state_change(struct zebra_if *zif, bool up)
+{
+ struct zebra_evpn_es *es = zif->es_info.es;
+ bool old_up = !!(es->flags & ZEBRA_EVPNES_OPER_UP);
+
+ if (old_up == up)
+ return;
+
+ if (IS_ZEBRA_DEBUG_EVPN_MH_ES)
+ zlog_debug("es %s state changed to %s ",
+ es->esi_str,
+ up ? "up" : "down");
+ if (up)
+ es->flags |= ZEBRA_EVPNES_OPER_UP;
+ else
+ es->flags &= ~ZEBRA_EVPNES_OPER_UP;
+
+ /* inform BGP of the ES oper state change */
+ if (es->flags & ZEBRA_EVPNES_READY_FOR_BGP)
+ zebra_evpn_es_send_add_to_client(es);
+}
+
+static char *zebra_evpn_es_vtep_str(char *vtep_str, struct zebra_evpn_es *es,
+ uint8_t vtep_str_size)
+{
+ struct zebra_evpn_es_vtep *zvtep;
+ struct listnode *node;
+ bool first = true;
+
+ vtep_str[0] = '\0';
+ for (ALL_LIST_ELEMENTS_RO(es->es_vtep_list, node, zvtep)) {
+ if (first) {
+ first = false;
+ strlcat(vtep_str, inet_ntoa(zvtep->vtep_ip),
+ vtep_str_size);
+ } else {
+ strlcat(vtep_str, ",", vtep_str_size);
+ strlcat(vtep_str, inet_ntoa(zvtep->vtep_ip),
+ vtep_str_size);
+ }
+ }
+ return vtep_str;
+}
+
+static void zebra_evpn_es_show_entry(struct vty *vty,
+ struct zebra_evpn_es *es, json_object *json)
+{
+ char type_str[4];
+ char vtep_str[ES_VTEP_LIST_STR_SZ];
+
+ if (json) {
+ /* XXX */
+ } else {
+ type_str[0] = '\0';
+ if (es->flags & ZEBRA_EVPNES_LOCAL)
+ strlcat(type_str, "L", sizeof(type_str));
+ if (es->flags & ZEBRA_EVPNES_REMOTE)
+ strlcat(type_str, "R", sizeof(type_str));
+
+ zebra_evpn_es_vtep_str(vtep_str, es, sizeof(vtep_str));
+
+ vty_out(vty, "%-30s %-4s %-21s %s\n",
+ es->esi_str, type_str,
+ es->zif ? es->zif->ifp->name : "-",
+ vtep_str);
+ }
+}
+
+static void zebra_evpn_es_show_entry_detail(struct vty *vty,
+ struct zebra_evpn_es *es, json_object *json)
+{
+ char type_str[80];
+ struct zebra_evpn_es_vtep *zvtep;
+ struct listnode *node;
+
+ if (json) {
+ /* XXX */
+ } else {
+ type_str[0] = '\0';
+ if (es->flags & ZEBRA_EVPNES_LOCAL)
+ strlcat(type_str, "Local", sizeof(type_str));
+ if (es->flags & ZEBRA_EVPNES_REMOTE) {
+ if (strnlen(type_str, sizeof(type_str)))
+ strlcat(type_str, ",", sizeof(type_str));
+ strlcat(type_str, "Remote", sizeof(type_str));
+ }
+
+ vty_out(vty, "ESI: %s\n", es->esi_str);
+ vty_out(vty, " Type: %s\n", type_str);
+ vty_out(vty, " Interface: %s\n",
+ (es->zif) ?
+ es->zif->ifp->name : "-");
+ vty_out(vty, " State: %s\n",
+ (es->flags & ZEBRA_EVPNES_OPER_UP) ?
+ "up" : "down");
+ vty_out(vty, " Ready for BGP: %s\n",
+ (es->flags & ZEBRA_EVPNES_READY_FOR_BGP) ?
+ "yes" : "no");
+ vty_out(vty, " VNI Count: %d\n", listcount(es->es_evi_list));
+ vty_out(vty, " MAC Count: %d\n", listcount(es->mac_list));
+ vty_out(vty, " Nexthop group: 0x%x\n", es->nhg_id);
+ vty_out(vty, " VTEPs:\n");
+ for (ALL_LIST_ELEMENTS_RO(es->es_vtep_list, node, zvtep))
+ vty_out(vty, " %s nh: 0x%x\n",
+ inet_ntoa(zvtep->vtep_ip),
+ zvtep->nh_id);
+
+ vty_out(vty, "\n");
+ }
+}
+
+void zebra_evpn_es_show(struct vty *vty, bool uj)
+{
+ struct zebra_evpn_es *es;
+ json_object *json = NULL;
+
+ if (uj) {
+ /* XXX */
+ } else {
+ vty_out(vty, "Type: L local, R remote\n");
+ vty_out(vty, "%-30s %-4s %-21s %s\n",
+ "ESI", "Type", "ES-IF", "VTEPs");
+ }
+
+ RB_FOREACH(es, zebra_es_rb_head, &zmh_info->es_rb_tree)
+ zebra_evpn_es_show_entry(vty, es, json);
+}
+
+void zebra_evpn_es_show_detail(struct vty *vty, bool uj)
+{
+ struct zebra_evpn_es *es;
+ json_object *json = NULL;
+
+ RB_FOREACH(es, zebra_es_rb_head, &zmh_info->es_rb_tree)
+ zebra_evpn_es_show_entry_detail(vty, es, json);
+}
+
+void zebra_evpn_es_show_esi(struct vty *vty, bool uj, esi_t *esi)
+{
+ struct zebra_evpn_es *es;
+ char esi_str[ESI_STR_LEN];
+ json_object *json = NULL;
+
+ es = zebra_evpn_es_find(esi);
+
+ if (!es) {
+ esi_to_str(esi, esi_str, sizeof(esi_str));
+ vty_out(vty, "ESI %s does not exist\n", esi_str);
+ return;
+ }
+
+ zebra_evpn_es_show_entry_detail(vty, es, json);
+}
+
+int zebra_evpn_mh_if_write(struct vty *vty, struct interface *ifp)
+{
+ struct zebra_if *zif = ifp->info;
+ char buf[ETHER_ADDR_STRLEN];
+
+ if (zif->es_info.lid)
+ vty_out(vty, " evpn mh es-id %u\n", zif->es_info.lid);
+
+ if (!is_zero_mac(&zif->es_info.sysmac))
+ vty_out(vty, " evpn mh es-sys-mac %s\n",
+ prefix_mac2str(&zif->es_info.sysmac,
+ buf, sizeof(buf)));
+ return 0;
+}
+
+#ifndef VTYSH_EXTRACT_PL
+#include "zebra/zebra_evpn_mh_clippy.c"
+#endif
+/* CLI for setting up sysmac part of ESI on an access port */
+DEFPY(zebra_evpn_es_sys_mac,
+ zebra_evpn_es_sys_mac_cmd,
+ "[no$no] evpn mh es-sys-mac [X:X:X:X:X:X$mac]",
+ NO_STR
+ "EVPN\n"
+ EVPN_MH_VTY_STR
+ "Ethernet segment system MAC\n"
+ MAC_STR
+)
+{
+ VTY_DECLVAR_CONTEXT(interface, ifp);
+ struct zebra_if *zif;
+ int ret = 0;
+
+ zif = ifp->info;
+
+ if (no) {
+ static struct ethaddr zero_mac;
+
+ ret = zebra_evpn_es_sys_mac_update(zif, &zero_mac);
+ if (ret == -1) {
+ vty_out(vty, "%%Failed to clear ES sysmac\n");
+ return CMD_WARNING;
+ }
+ } else {
+
+ if (!zebra_evpn_is_if_es_capable(zif)) {
+ vty_out(vty,
+ "%%ESI cannot be associated with this interface type\n");
+ return CMD_WARNING;
+ }
+
+ if (!mac || is_zero_mac(&mac->eth_addr)) {
+ vty_out(vty, "%%ES sysmac value is invalid\n");
+ return CMD_WARNING;
+ }
+
+ ret = zebra_evpn_es_sys_mac_update(zif, &mac->eth_addr);
+ if (ret == -1) {
+ vty_out(vty, "%%ESI already exists on a different interface\n");
+ return CMD_WARNING;
+ }
+ }
+ return CMD_SUCCESS;
+}
+
+/* CLI for setting up local-ID part of ESI on an access port */
+DEFPY(zebra_evpn_es_id,
+ zebra_evpn_es_id_cmd,
+ "[no$no] evpn mh es-id [(1-16777215)$es_lid]",
+ NO_STR
+ "EVPN\n"
+ EVPN_MH_VTY_STR
+ "Ethernet segment local identifier\n"
+ "ID\n"
+)
+{
+ VTY_DECLVAR_CONTEXT(interface, ifp);
+ struct zebra_if *zif;
+ int ret;
+
+ zif = ifp->info;
+
+ if (no) {
+ ret = zebra_evpn_es_lid_update(zif, 0);
+ if (ret == -1) {
+ vty_out(vty, "%%Failed to clear ES local id\n");
+ return CMD_WARNING;
+ }
+ } else {
+ if (!zebra_evpn_is_if_es_capable(zif)) {
+ vty_out(vty,
+ "%%ESI cannot be associated with this interface type\n");
+ return CMD_WARNING;
+ }
+
+ if (!es_lid) {
+ vty_out(vty, "%%Specify local ES ID\n");
+ return CMD_WARNING;
+ }
+ ret = zebra_evpn_es_lid_update(zif, es_lid);
+ if (ret == -1) {
+ vty_out(vty,
+ "%%ESI already exists on a different interface\n");
+ return CMD_WARNING;
+ }
+ }
+ return CMD_SUCCESS;
+}
+
+/*****************************************************************************/
+/* A base L2-VNI is maintained to derive parameters such as ES originator-IP.
+ * XXX: once single vxlan device model becomes available this will not be
+ * necessary
+ */
+/* called when a new vni is added or becomes oper up or becomes a bridge port */
+void zebra_evpn_es_set_base_vni(zebra_vni_t *zvni)
+{
+ struct listnode *node;
+ struct zebra_evpn_es *es;
+
+ if (zmh_info->es_base_vni) {
+ if (zmh_info->es_base_vni != zvni) {
+ /* unrelated VNI; ignore it */
+ return;
+ }
+ /* check if the local vtep-ip has changed */
+ } else {
+ /* check if the VNI can be used as base VNI */
+ if (!zebra_evpn_vni_send_to_client_ok(zvni))
+ return;
+
+ if (IS_ZEBRA_DEBUG_EVPN_MH_ES)
+ zlog_debug("es base vni set to %d",
+ zvni->vni);
+ zmh_info->es_base_vni = zvni;
+ }
+
+ /* update local VTEP-IP */
+ if (zmh_info->es_originator_ip.s_addr ==
+ zmh_info->es_base_vni->local_vtep_ip.s_addr)
+ return;
+
+ zmh_info->es_originator_ip.s_addr =
+ zmh_info->es_base_vni->local_vtep_ip.s_addr;
+
+ if (IS_ZEBRA_DEBUG_EVPN_MH_ES)
+ zlog_debug("es originator ip set to %s",
+ inet_ntoa(zmh_info->es_base_vni->local_vtep_ip));
+
+ /* if originator ip changes we need to update bgp */
+ for (ALL_LIST_ELEMENTS_RO(zmh_info->local_es_list, node, es)) {
+ if (es->flags & ZEBRA_EVPNES_READY_FOR_BGP)
+ zebra_evpn_es_send_add_to_client(es);
+ else
+ zebra_evpn_es_re_eval_send_to_client(es,
+ true /* es_evi_re_reval */);
+ }
+}
+
+/* called when a vni is removed or becomes oper down or is removed from a
+ * bridge
+ */
+void zebra_evpn_es_clear_base_vni(zebra_vni_t *zvni)
+{
+ struct listnode *node;
+ struct zebra_evpn_es *es;
+
+ if (zmh_info->es_base_vni != zvni)
+ return;
+
+ zmh_info->es_base_vni = NULL;
+ /* lost current base VNI; try to find a new one */
+ zebra_evpn_es_get_one_base_vni();
+
+ /* couldn't locate an eligible base vni */
+ if (!zmh_info->es_base_vni && zmh_info->es_originator_ip.s_addr) {
+ if (IS_ZEBRA_DEBUG_EVPN_MH_ES)
+ zlog_debug("es originator ip cleared");
+
+ zmh_info->es_originator_ip.s_addr = 0;
+ /* lost originator ip */
+ for (ALL_LIST_ELEMENTS_RO(zmh_info->local_es_list, node, es)) {
+ zebra_evpn_es_re_eval_send_to_client(es,
+ true /* es_evi_re_reval */);
+ }
+ }
+}
+
+/* Locate an "eligible" L2-VNI to follow */
+static int zebra_evpn_es_get_one_base_vni_cb(struct hash_bucket *b, void *data)
+{
+ zebra_vni_t *zvni = b->data;
+
+ zebra_evpn_es_set_base_vni(zvni);
+
+ if (zmh_info->es_base_vni)
+ return HASHWALK_ABORT;
+
+ return HASHWALK_CONTINUE;
+}
+
+/* locate a base_vni to follow for the purposes of common params like
+ * originator IP
+ */
+static void zebra_evpn_es_get_one_base_vni(void)
+{
+ struct zebra_vrf *zvrf;
+
+ zvrf = zebra_vrf_get_evpn();
+ hash_walk(zvrf->vni_table, zebra_evpn_es_get_one_base_vni_cb, NULL);
+}
+
+/*****************************************************************************/
+void zebra_evpn_mh_config_write(struct vty *vty)
+{
+ if (zmh_info->mac_hold_time != EVPN_MH_MAC_HOLD_TIME_DEF)
+ vty_out(vty, "evpn mh mac-holdtime %ld\n",
+ zmh_info->mac_hold_time);
+
+ if (zmh_info->neigh_hold_time != EVPN_MH_NEIGH_HOLD_TIME_DEF)
+ vty_out(vty, "evpn mh neigh-holdtime %ld\n",
+ zmh_info->neigh_hold_time);
+}
+
+int zebra_evpn_mh_neigh_holdtime_update(struct vty *vty,
+ uint32_t duration, bool set_default)
+{
+ if (set_default)
+ zmh_info->neigh_hold_time = EVPN_MH_NEIGH_HOLD_TIME_DEF;
+
+ zmh_info->neigh_hold_time = duration;
+
+ return 0;
+}
+
+int zebra_evpn_mh_mac_holdtime_update(struct vty *vty,
+ uint32_t duration, bool set_default)
+{
+ if (set_default)
+ duration = EVPN_MH_MAC_HOLD_TIME_DEF;
+
+ zmh_info->mac_hold_time = duration;
+
+ return 0;
+}
+
+void zebra_evpn_interface_init(void)
+{
+ install_element(INTERFACE_NODE, &zebra_evpn_es_id_cmd);
+ install_element(INTERFACE_NODE, &zebra_evpn_es_sys_mac_cmd);
+}
+
+void zebra_evpn_mh_init(void)
+{
+ zrouter.mh_info = XCALLOC(MTYPE_ZMH_INFO, sizeof(*zrouter.mh_info));
+
+ zmh_info->mac_hold_time = EVPN_MH_MAC_HOLD_TIME_DEF;
+ zmh_info->neigh_hold_time = EVPN_MH_NEIGH_HOLD_TIME_DEF;
+ /* setup ES tables */
+ RB_INIT(zebra_es_rb_head, &zmh_info->es_rb_tree);
+ zmh_info->local_es_list = list_new();
+ listset_app_node_mem(zmh_info->local_es_list);
+
+ bf_init(zmh_info->nh_id_bitmap, EVPN_NH_ID_MAX);
+ bf_assign_zero_index(zmh_info->nh_id_bitmap);
+
+ /* setup broadcast domain tables */
+ zmh_info->evpn_vlan_table = hash_create(zebra_evpn_acc_vl_hash_keymake,
+ zebra_evpn_acc_vl_cmp, "access VLAN hash table");
+}
+
+void zebra_evpn_mh_terminate(void)
+{
+ list_delete(&zmh_info->local_es_list);
+
+ hash_iterate(zmh_info->evpn_vlan_table,
+ zebra_evpn_acc_vl_cleanup_all, NULL);
+ hash_free(zmh_info->evpn_vlan_table);
+}
diff --git a/zebra/zebra_evpn_mh.h b/zebra/zebra_evpn_mh.h
new file mode 100644
index 0000000000..46c25a04bc
--- /dev/null
+++ b/zebra/zebra_evpn_mh.h
@@ -0,0 +1,239 @@
+/*
+ * Zebra EVPN MH Data structures and definitions
+ *
+ * Copyright (C) 2019 Cumulus Networks, Inc.
+ * Anuradha Karuppiah
+ *
+ * This file is part of FRR.
+ *
+ * FRR is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2, or (at your option) any
+ * later version.
+ *
+ * FRR is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ */
+
+#ifndef _ZEBRA_EVPN_MH_H
+#define _ZEBRA_EVPN_MH_H
+
+#include <zebra.h>
+
+#include "if.h"
+#include "linklist.h"
+#include "bitfield.h"
+#include "zebra_vxlan.h"
+#include "zebra_vxlan_private.h"
+
+#define EVPN_MH_VTY_STR "Multihoming\n"
+
+/* Ethernet Segment entry -
+ * - Local and remote ESs are maintained in a global RB tree,
+ * zmh_info->es_rb_tree using ESI as key
+ * - Local ESs are added via zebra config (ZEBRA_EVPNES_LOCAL) when an
+ * access port is associated with an ES-ID
+ * - Remotes ESs are added by BGP based on received/remote EAD/Type-1 routes
+ * (ZEBRA_EVPNES_REMOTE)
+ * - An ES can be simulatenously LOCAL and REMOTE; infact all LOCAL ESs are
+ * expected to have REMOTE ES peers.
+ */
+struct zebra_evpn_es {
+ esi_t esi;
+ char esi_str[ESI_STR_LEN];
+
+ /* ES flags */
+ uint32_t flags;
+#define ZEBRA_EVPNES_LOCAL (1 << 0) /* configured in zebra */
+#define ZEBRA_EVPNES_REMOTE (1 << 1) /* added by bgp */
+#define ZEBRA_EVPNES_OPER_UP (1 << 2) /* es->ifp is oper-up */
+#define ZEBRA_EVPNES_READY_FOR_BGP (1 << 3) /* ready to be sent to BGP */
+#define ZEBRA_EVPNES_NHG_ACTIVE (1 << 4) /* NHG has been installed */
+
+ /* memory used for adding the es to zmh_info->es_rb_tree */
+ RB_ENTRY(zebra_evpn_es) rb_node;
+
+ /* [EVPNES_LOCAL] memory used for linking the es to
+ * zmh_info->local_es_list
+ */
+ struct listnode local_es_listnode;
+
+ /* [EVPNES_LOCAL] corresponding interface */
+ struct zebra_if *zif;
+
+ /* list of ES-EVIs associated with the ES */
+ struct list *es_evi_list;
+
+ /* [!EVPNES_LOCAL] List of remote VTEPs (zebra_evpn_es_vtep) */
+ struct list *es_vtep_list;
+
+ /* list of zebra_mac entries using this ES as destination */
+ struct list *mac_list;
+
+ /* Nexthop group id */
+ uint32_t nhg_id;
+};
+RB_HEAD(zebra_es_rb_head, zebra_evpn_es);
+RB_PROTOTYPE(zebra_es_rb_head, zebra_evpn_es, rb_node, zebra_es_rb_cmp);
+
+/* ES per-EVI info
+ * - ES-EVIs are maintained per-VNI (vni->es_evi_rb_tree)
+ * - Local ES-EVIs are linked to per-VNI list for quick access
+ * - Although some infrastucture is present for remote ES-EVIs, currently
+ * BGP does NOT send remote ES-EVIs to zebra. This may change in the
+ * future (but must be changed thoughtfully and only if needed as ES-EVI
+ * can get prolific and come in the way of rapid failovers)
+ */
+struct zebra_evpn_es_evi {
+ struct zebra_evpn_es *es;
+ zebra_vni_t *zvni;
+
+ /* ES-EVI flags */
+ uint32_t flags;
+ /* local ES-EVI */
+#define ZEBRA_EVPNES_EVI_LOCAL (1 << 0) /* created by zebra */
+#define ZEBRA_EVPNES_EVI_READY_FOR_BGP (1 << 1) /* ready to be sent to BGP */
+
+ /* memory used for adding the es_evi to
+ * es_evi->zvni->es_evi_rb_tree
+ */
+ RB_ENTRY(zebra_evpn_es_evi) rb_node;
+ /* memory used for linking the es_evi to
+ * es_evi->zvni->local_es_evi_list
+ */
+ struct listnode l2vni_listnode;
+ /* memory used for linking the es_evi to
+ * es_evi->es->es_evi_list
+ */
+ struct listnode es_listnode;
+};
+
+/* PE attached to an ES */
+struct zebra_evpn_es_vtep {
+ struct zebra_evpn_es *es; /* parent ES */
+ struct in_addr vtep_ip;
+
+ /* memory used for adding the entry to es->es_vtep_list */
+ struct listnode es_listnode;
+
+ /* MAC nexthop */
+ uint32_t nh_id;
+
+ /* XXX - maintain a backpointer to zebra_vtep_t */
+};
+
+/* Local/access-side broadcast domain - zebra_evpn_access_bd is added to -
+ * zrouter->evpn_vlan_table (for VLAN aware bridges) OR
+ * zrouter->evpn_bridge_table (for VLAN unaware bridges)
+ * XXX - support for VLAN unaware bridges is yet to be flushed out
+ */
+struct zebra_evpn_access_bd {
+ vlanid_t vid;
+
+ struct zebra_if *vxlan_zif; /* vxlan device */
+ /* list of members associated with the BD i.e. (potential) ESs */
+ struct list *mbr_zifs;
+ /* presence of zvni activates the EVI on all the ESs in mbr_zifs */
+ zebra_vni_t *zvni;
+};
+
+/* multihoming information stored in zrouter */
+#define zmh_info (zrouter.mh_info)
+struct zebra_evpn_mh_info {
+ /* RB tree of Ethernet segments (used for EVPN-MH) */
+ struct zebra_es_rb_head es_rb_tree;
+ /* List of local ESs */
+ struct list *local_es_list;
+
+ /* EVPN MH broadcast domains indexed by the VID */
+ struct hash *evpn_vlan_table;
+
+ /* A base L2-VNI is maintained to derive parameters such as
+ * ES originator-IP.
+ * XXX: once single vxlan device model becomes available this will
+ * not be necessary
+ */
+ zebra_vni_t *es_base_vni;
+ struct in_addr es_originator_ip;
+
+ /* L2 NH and NHG ids -
+ * Most significant 8 bits is type. Lower 24 bits is the value
+ * allocated from the nh_id_bitmap.
+ */
+ bitfield_t nh_id_bitmap;
+#define EVPN_NH_ID_MAX (16*1024)
+#define EVPN_NH_ID_VAL_MASK 0xffffff
+#define EVPN_NH_ID_TYPE_POS 24
+/* The purpose of using different types for NHG and NH is NOT to manage the
+ * id space separately. It is simply to make debugging easier.
+ */
+#define EVPN_NH_ID_TYPE_BIT (1 << EVPN_NH_ID_TYPE_POS)
+#define EVPN_NHG_ID_TYPE_BIT (2 << EVPN_NH_ID_TYPE_POS)
+
+ /* XXX - re-visit the default hold timer value */
+#define EVPN_MH_MAC_HOLD_TIME_DEF (18 * 60)
+ long mac_hold_time;
+#define EVPN_MH_NEIGH_HOLD_TIME_DEF (18 * 60)
+ long neigh_hold_time;
+};
+
+static inline bool zebra_evpn_mac_is_es_local(zebra_mac_t *mac)
+{
+ return mac->es && (mac->es->flags & ZEBRA_EVPNES_LOCAL);
+}
+
+/* Returns true if the id is of L2-NHG or L2-NH type */
+static inline bool zebra_evpn_mh_is_fdb_nh(uint32_t id)
+{
+ return ((id & EVPN_NHG_ID_TYPE_BIT) ||
+ (id & EVPN_NH_ID_TYPE_BIT));
+}
+
+/*****************************************************************************/
+extern esi_t *zero_esi;
+extern void zebra_evpn_mh_init(void);
+extern void zebra_evpn_mh_terminate(void);
+extern bool zebra_evpn_is_if_es_capable(struct zebra_if *zif);
+extern void zebra_evpn_if_init(struct zebra_if *zif);
+extern void zebra_evpn_if_cleanup(struct zebra_if *zif);
+extern void zebra_evpn_vni_es_init(zebra_vni_t *zvni);
+extern void zebra_evpn_vni_es_cleanup(zebra_vni_t *zvni);
+extern void zebra_evpn_vxl_vni_set(struct zebra_if *zif, zebra_vni_t *zvni,
+ bool set);
+extern void zebra_evpn_es_set_base_vni(zebra_vni_t *zvni);
+extern void zebra_evpn_es_clear_base_vni(zebra_vni_t *zvni);
+extern void zebra_evpn_vl_vxl_ref(uint16_t vid, struct zebra_if *vxlan_zif);
+extern void zebra_evpn_vl_vxl_deref(uint16_t vid, struct zebra_if *vxlan_zif);
+extern void zebra_evpn_vl_mbr_ref(uint16_t vid, struct zebra_if *zif);
+extern void zebra_evpn_vl_mbr_deref(uint16_t vid, struct zebra_if *zif);
+extern void zebra_evpn_es_send_all_to_client(bool add);
+extern void zebra_evpn_es_if_oper_state_change(struct zebra_if *zif, bool up);
+extern void zebra_evpn_es_show(struct vty *vty, bool uj);
+extern void zebra_evpn_es_show_detail(struct vty *vty, bool uj);
+extern void zebra_evpn_es_show_esi(struct vty *vty, bool uj, esi_t *esi);
+extern void zebra_evpn_vni_update_all_es(zebra_vni_t *zvni);
+extern void zebra_evpn_proc_remote_es(ZAPI_HANDLER_ARGS);
+extern void zebra_evpn_es_evi_show(struct vty *vty, bool uj, int detail);
+extern void zebra_evpn_es_evi_show_vni(struct vty *vty, bool uj,
+ vni_t vni, int detail);
+extern void zebra_evpn_es_mac_deref_entry(zebra_mac_t *mac);
+extern bool zebra_evpn_es_mac_ref_entry(zebra_mac_t *mac,
+ struct zebra_evpn_es *es);
+extern bool zebra_evpn_es_mac_ref(zebra_mac_t *mac, esi_t *esi);
+extern struct zebra_evpn_es *zebra_evpn_es_find(esi_t *esi);
+extern void zebra_evpn_interface_init(void);
+extern int zebra_evpn_mh_if_write(struct vty *vty, struct interface *ifp);
+extern void zebra_evpn_acc_vl_show(struct vty *vty, bool uj);
+extern void zebra_evpn_acc_vl_show_detail(struct vty *vty, bool uj);
+extern void zebra_evpn_acc_vl_show_vid(struct vty *vty, bool uj, vlanid_t vid);
+extern void zebra_evpn_if_es_print(struct vty *vty, struct zebra_if *zif);
+extern void zebra_evpn_es_cleanup(void);
+extern int zebra_evpn_mh_mac_holdtime_update(struct vty *vty,
+ uint32_t duration, bool set_default);
+void zebra_evpn_mh_config_write(struct vty *vty);
+int zebra_evpn_mh_neigh_holdtime_update(struct vty *vty,
+ uint32_t duration, bool set_default);
+
+#endif /* _ZEBRA_EVPN_MH_H */
diff --git a/zebra/zebra_fpm_netlink.c b/zebra/zebra_fpm_netlink.c
index a18885ddb7..3e11d53b16 100644
--- a/zebra/zebra_fpm_netlink.c
+++ b/zebra/zebra_fpm_netlink.c
@@ -279,7 +279,6 @@ static int netlink_route_info_fill(struct netlink_route_info *ri, int cmd,
rib_dest_t *dest, struct route_entry *re)
{
struct nexthop *nexthop;
- struct zebra_vrf *zvrf;
memset(ri, 0, sizeof(*ri));
@@ -287,9 +286,7 @@ static int netlink_route_info_fill(struct netlink_route_info *ri, int cmd,
ri->af = rib_dest_af(dest);
ri->nlmsg_type = cmd;
- zvrf = rib_dest_vrf(dest);
- if (zvrf)
- ri->rtm_table = zvrf->table_id;
+ ri->rtm_table = rib_table_info(rib_dest_table(dest))->table_id;
ri->rtm_protocol = RTPROT_UNSPEC;
/*
@@ -364,6 +361,7 @@ static int netlink_route_info_encode(struct netlink_route_info *ri,
struct rtattr *nest, *inner_nest;
struct rtnexthop *rtnh;
struct vxlan_encap_info_t *vxlan;
+ struct in6_addr ipv6;
struct {
struct nlmsghdr n;
@@ -423,8 +421,15 @@ static int netlink_route_info_encode(struct netlink_route_info *ri,
nhi = &ri->nhs[0];
if (nhi->gateway) {
- nl_attr_put(&req->n, in_buf_len, RTA_GATEWAY,
- nhi->gateway, bytelen);
+ if (nhi->type == NEXTHOP_TYPE_IPV4_IFINDEX
+ && ri->af == AF_INET6) {
+ ipv4_to_ipv4_mapped_ipv6(&ipv6,
+ nhi->gateway->ipv4);
+ nl_attr_put(&req->n, in_buf_len, RTA_GATEWAY,
+ &ipv6, bytelen);
+ } else
+ nl_attr_put(&req->n, in_buf_len, RTA_GATEWAY,
+ nhi->gateway, bytelen);
}
if (nhi->if_index) {
diff --git a/zebra/zebra_l2.c b/zebra/zebra_l2.c
index 4c0cc62fbf..1758c8f96a 100644
--- a/zebra/zebra_l2.c
+++ b/zebra/zebra_l2.c
@@ -43,6 +43,7 @@
#include "zebra/rt_netlink.h"
#include "zebra/zebra_l2.h"
#include "zebra/zebra_vxlan.h"
+#include "zebra/zebra_evpn_mh.h"
/* definitions */
@@ -53,13 +54,7 @@ static void map_slaves_to_bridge(struct interface *br_if, int link)
{
struct vrf *vrf;
struct interface *ifp;
- struct zebra_vrf *zvrf;
- struct zebra_ns *zns;
- zvrf = zebra_vrf_lookup_by_id(br_if->vrf_id);
- assert(zvrf);
- zns = zvrf->zns;
- assert(zns);
RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
FOR_ALL_INTERFACES (vrf, ifp) {
struct zebra_if *zif;
@@ -78,8 +73,7 @@ static void map_slaves_to_bridge(struct interface *br_if, int link)
br_slave = &zif->brslave_info;
if (link) {
- if (br_slave->bridge_ifindex == br_if->ifindex &&
- br_slave->ns_id == zns->ns_id)
+ if (br_slave->bridge_ifindex == br_if->ifindex)
br_slave->br_if = br_if;
} else {
if (br_slave->br_if == br_if)
@@ -90,14 +84,12 @@ static void map_slaves_to_bridge(struct interface *br_if, int link)
}
/* Public functions */
-void zebra_l2_map_slave_to_bridge(struct zebra_l2info_brslave *br_slave,
- struct zebra_ns *zns)
+void zebra_l2_map_slave_to_bridge(struct zebra_l2info_brslave *br_slave)
{
struct interface *br_if;
/* TODO: Handle change of master */
- assert(zns);
- br_if = if_lookup_by_index_per_ns(zebra_ns_lookup(zns->ns_id),
+ br_if = if_lookup_by_index_per_ns(zebra_ns_lookup(NS_DEFAULT),
br_slave->bridge_ifindex);
if (br_if)
br_slave->br_if = br_if;
@@ -119,7 +111,7 @@ void zebra_l2_map_slave_to_bond(struct zebra_l2info_bondslave *bond_slave,
bond_slave->bond_if = bond_if;
else
bond_slave->bond_if = if_create_ifindex(bond_slave->bond_ifindex,
- vrf_id, NULL);
+ vrf_id);
}
void zebra_l2_unmap_slave_from_bond(struct zebra_l2info_bondslave *bond_slave)
@@ -191,6 +183,7 @@ void zebra_l2_vxlanif_add_update(struct interface *ifp,
if (add) {
memcpy(&zif->l2info.vxl, vxlan_info, sizeof(*vxlan_info));
+ zebra_evpn_vl_vxl_ref(zif->l2info.vxl.access_vlan, zif);
zebra_vxlan_if_add(ifp);
return;
}
@@ -229,6 +222,9 @@ void zebra_l2_vxlanif_update_access_vlan(struct interface *ifp,
return;
zif->l2info.vxl.access_vlan = access_vlan;
+
+ zebra_evpn_vl_vxl_deref(old_access_vlan, zif);
+ zebra_evpn_vl_vxl_ref(zif->l2info.vxl.access_vlan, zif);
zebra_vxlan_if_update(ifp, ZEBRA_VXLIF_VLAN_CHANGE);
}
@@ -237,6 +233,12 @@ void zebra_l2_vxlanif_update_access_vlan(struct interface *ifp,
*/
void zebra_l2_vxlanif_del(struct interface *ifp)
{
+ struct zebra_if *zif;
+
+ zif = ifp->info;
+ assert(zif);
+
+ zebra_evpn_vl_vxl_deref(zif->l2info.vxl.access_vlan, zif);
zebra_vxlan_if_del(ifp);
}
@@ -246,32 +248,23 @@ void zebra_l2_vxlanif_del(struct interface *ifp)
* from a bridge before it can be mapped to another bridge.
*/
void zebra_l2if_update_bridge_slave(struct interface *ifp,
- ifindex_t bridge_ifindex,
- ns_id_t ns_id)
+ ifindex_t bridge_ifindex)
{
struct zebra_if *zif;
ifindex_t old_bridge_ifindex;
- ns_id_t old_ns_id;
- struct zebra_vrf *zvrf;
zif = ifp->info;
assert(zif);
- zvrf = zebra_vrf_lookup_by_id(ifp->vrf_id);
- if (!zvrf)
- return;
-
old_bridge_ifindex = zif->brslave_info.bridge_ifindex;
- old_ns_id = zif->brslave_info.ns_id;
- if (old_bridge_ifindex == bridge_ifindex &&
- old_ns_id == zif->brslave_info.ns_id)
+ if (old_bridge_ifindex == bridge_ifindex)
return;
- zif->brslave_info.ns_id = ns_id;
zif->brslave_info.bridge_ifindex = bridge_ifindex;
+
/* Set up or remove link with master */
if (bridge_ifindex != IFINDEX_INTERNAL) {
- zebra_l2_map_slave_to_bridge(&zif->brslave_info, zvrf->zns);
+ zebra_l2_map_slave_to_bridge(&zif->brslave_info);
/* In the case of VxLAN, invoke the handler for EVPN. */
if (zif->zif_type == ZEBRA_IF_VXLAN)
zebra_vxlan_if_update(ifp, ZEBRA_VXLIF_MASTER_CHANGE);
@@ -307,3 +300,43 @@ void zebra_l2if_update_bond_slave(struct interface *ifp, ifindex_t bond_ifindex)
else if (old_bond_ifindex != IFINDEX_INTERNAL)
zebra_l2_unmap_slave_from_bond(&zif->bondslave_info);
}
+
+void zebra_vlan_bitmap_compute(struct interface *ifp,
+ uint32_t vid_start, uint16_t vid_end)
+{
+ uint32_t vid;
+ struct zebra_if *zif;
+
+ zif = (struct zebra_if *)ifp->info;
+ assert(zif);
+
+ for (vid = vid_start; vid <= vid_end; ++vid)
+ bf_set_bit(zif->vlan_bitmap, vid);
+}
+
+void zebra_vlan_mbr_re_eval(struct interface *ifp, bitfield_t old_vlan_bitmap)
+{
+ uint32_t vid;
+ struct zebra_if *zif;
+
+ zif = (struct zebra_if *)ifp->info;
+ assert(zif);
+
+ if (!bf_cmp(zif->vlan_bitmap, old_vlan_bitmap))
+ /* no change */
+ return;
+
+ bf_for_each_set_bit(zif->vlan_bitmap, vid, IF_VLAN_BITMAP_MAX) {
+ /* if not already set create new reference */
+ if (!bf_test_index(old_vlan_bitmap, vid))
+ zebra_evpn_vl_mbr_ref(vid, zif);
+
+ /* also clear from the old vlan bitmap */
+ bf_release_index(old_vlan_bitmap, vid);
+ }
+
+ /* any bits remaining in the old vlan bitmap are stale references */
+ bf_for_each_set_bit(old_vlan_bitmap, vid, IF_VLAN_BITMAP_MAX) {
+ zebra_evpn_vl_mbr_deref(vid, zif);
+ }
+}
diff --git a/zebra/zebra_l2.h b/zebra/zebra_l2.h
index a3c780ee09..2735d915ec 100644
--- a/zebra/zebra_l2.h
+++ b/zebra/zebra_l2.h
@@ -37,7 +37,6 @@ extern "C" {
struct zebra_l2info_brslave {
ifindex_t bridge_ifindex; /* Bridge Master */
struct interface *br_if; /* Pointer to master */
- ns_id_t ns_id; /* network namespace where bridge is */
};
/* zebra L2 interface information - bridge interface */
@@ -82,8 +81,7 @@ union zebra_l2if_info {
#define IS_ZEBRA_IF_BRIDGE_VLAN_AWARE(zif) ((zif)->l2info.br.vlan_aware == 1)
-extern void zebra_l2_map_slave_to_bridge(struct zebra_l2info_brslave *br_slave,
- struct zebra_ns *zns);
+extern void zebra_l2_map_slave_to_bridge(struct zebra_l2info_brslave *br_slave);
extern void
zebra_l2_unmap_slave_from_bridge(struct zebra_l2info_brslave *br_slave);
extern void
@@ -103,11 +101,14 @@ extern void zebra_l2_vxlanif_update_access_vlan(struct interface *ifp,
vlanid_t access_vlan);
extern void zebra_l2_vxlanif_del(struct interface *ifp);
extern void zebra_l2if_update_bridge_slave(struct interface *ifp,
- ifindex_t bridge_ifindex,
- ns_id_t ns_id);
+ ifindex_t bridge_ifindex);
extern void zebra_l2if_update_bond_slave(struct interface *ifp,
ifindex_t bond_ifindex);
+extern void zebra_vlan_bitmap_compute(struct interface *ifp,
+ uint32_t vid_start, uint16_t vid_end);
+extern void zebra_vlan_mbr_re_eval(struct interface *ifp,
+ bitfield_t vlan_bitmap);
#ifdef __cplusplus
}
diff --git a/zebra/zebra_memory.c b/zebra/zebra_memory.c
index a9c2c5fe58..da8121774e 100644
--- a/zebra/zebra_memory.c
+++ b/zebra/zebra_memory.c
@@ -28,3 +28,5 @@
DEFINE_MGROUP(ZEBRA, "zebra")
DEFINE_MTYPE(ZEBRA, RE, "Route Entry")
DEFINE_MTYPE(ZEBRA, RIB_DEST, "RIB destination")
+DEFINE_MTYPE(ZEBRA, ZVLAN, "VLAN")
+DEFINE_MTYPE(ZEBRA, ZVLAN_BITMAP, "VLAN bitmap")
diff --git a/zebra/zebra_mpls.c b/zebra/zebra_mpls.c
index 996afd12dd..1ac7bc7a2a 100644
--- a/zebra/zebra_mpls.c
+++ b/zebra/zebra_mpls.c
@@ -120,7 +120,8 @@ static int mpls_lsp_uninstall_all(struct hash *lsp_table, zebra_lsp_t *lsp,
enum lsp_types_t type);
static int mpls_static_lsp_uninstall_all(struct zebra_vrf *zvrf,
mpls_label_t in_label);
-static void nhlfe_print(zebra_nhlfe_t *nhlfe, struct vty *vty);
+static void nhlfe_print(zebra_nhlfe_t *nhlfe, struct vty *vty,
+ const char *indent);
static void lsp_print(struct vty *vty, zebra_lsp_t *lsp);
static void *slsp_alloc(void *p);
static int snhlfe_match(zebra_snhlfe_t *snhlfe, enum nexthop_types_t gtype,
@@ -1503,7 +1504,9 @@ static json_object *nhlfe_json(zebra_nhlfe_t *nhlfe)
{
char buf[BUFSIZ];
json_object *json_nhlfe = NULL;
+ json_object *json_backups = NULL;
struct nexthop *nexthop = nhlfe->nexthop;
+ int i;
json_nhlfe = json_object_new_object();
json_object_string_add(json_nhlfe, "type", nhlfe_type2str(nhlfe->type));
@@ -1534,13 +1537,27 @@ static json_object *nhlfe_json(zebra_nhlfe_t *nhlfe)
default:
break;
}
+
+ if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_HAS_BACKUP)) {
+ json_backups = json_object_new_array();
+ for (i = 0; i < nexthop->backup_num; i++) {
+ json_object_array_add(
+ json_backups,
+ json_object_new_int(nexthop->backup_idx[i]));
+ }
+
+ json_object_object_add(json_nhlfe, "backupIndex",
+ json_backups);
+ }
+
return json_nhlfe;
}
/*
* Print the NHLFE for a LSP forwarding entry.
*/
-static void nhlfe_print(zebra_nhlfe_t *nhlfe, struct vty *vty)
+static void nhlfe_print(zebra_nhlfe_t *nhlfe, struct vty *vty,
+ const char *indent)
{
struct nexthop *nexthop;
char buf[MPLS_LABEL_STRLEN];
@@ -1555,6 +1572,10 @@ static void nhlfe_print(zebra_nhlfe_t *nhlfe, struct vty *vty)
nexthop->nh_label->label,
buf, sizeof(buf), 0),
nhlfe->distance);
+
+ if (indent)
+ vty_out(vty, "%s", indent);
+
switch (nexthop->type) {
case NEXTHOP_TYPE_IPV4:
case NEXTHOP_TYPE_IPV4_IFINDEX:
@@ -1592,31 +1613,34 @@ static void nhlfe_print(zebra_nhlfe_t *nhlfe, struct vty *vty)
static void lsp_print(struct vty *vty, zebra_lsp_t *lsp)
{
zebra_nhlfe_t *nhlfe, *backup;
- int i;
+ int i, j;
vty_out(vty, "Local label: %u%s\n", lsp->ile.in_label,
CHECK_FLAG(lsp->flags, LSP_FLAG_INSTALLED) ? " (installed)"
: "");
frr_each(nhlfe_list, &lsp->nhlfe_list, nhlfe) {
- nhlfe_print(nhlfe, vty);
+ nhlfe_print(nhlfe, vty, NULL);
+
+ if (nhlfe->nexthop == NULL ||
+ !CHECK_FLAG(nhlfe->nexthop->flags,
+ NEXTHOP_FLAG_HAS_BACKUP))
+ continue;
- if (nhlfe->nexthop &&
- CHECK_FLAG(nhlfe->nexthop->flags,
- NEXTHOP_FLAG_HAS_BACKUP)) {
- /* Find backup in backup list */
+ /* Backup nhlfes: find backups in backup list */
+ for (j = 0; j < nhlfe->nexthop->backup_num; j++) {
i = 0;
backup = NULL;
frr_each(nhlfe_list, &lsp->backup_nhlfe_list, backup) {
- if (i == nhlfe->nexthop->backup_idx)
+ if (i == nhlfe->nexthop->backup_idx[j])
break;
i++;
}
if (backup) {
vty_out(vty, " [backup %d]", i);
- nhlfe_print(backup, vty);
+ nhlfe_print(backup, vty, " ");
}
}
}
@@ -1640,6 +1664,19 @@ static json_object *lsp_json(zebra_lsp_t *lsp)
json_object_array_add(json_nhlfe_list, nhlfe_json(nhlfe));
json_object_object_add(json, "nexthops", json_nhlfe_list);
+ json_nhlfe_list = NULL;
+
+
+ frr_each(nhlfe_list, &lsp->backup_nhlfe_list, nhlfe) {
+ if (json_nhlfe_list == NULL)
+ json_nhlfe_list = json_object_new_array();
+
+ json_object_array_add(json_nhlfe_list, nhlfe_json(nhlfe));
+ }
+
+ if (json_nhlfe_list)
+ json_object_object_add(json, "backupNexthops", json_nhlfe_list);
+
return json;
}
@@ -2109,6 +2146,7 @@ static int update_nhlfes_from_ctx(struct nhlfe_list_head *nhlfe_head,
__func__, buf);
SET_FLAG(nhlfe->flags, NHLFE_FLAG_INSTALLED);
+ SET_FLAG(nhlfe->flags, NHLFE_FLAG_SELECTED);
} else {
if (is_debug)
@@ -2116,6 +2154,7 @@ static int update_nhlfes_from_ctx(struct nhlfe_list_head *nhlfe_head,
__func__, buf);
UNSET_FLAG(nhlfe->flags, NHLFE_FLAG_INSTALLED);
+ UNSET_FLAG(nhlfe->flags, NHLFE_FLAG_SELECTED);
}
if (CHECK_FLAG(ctx_nhlfe->nexthop->flags,
@@ -2137,6 +2176,7 @@ static int update_nhlfes_from_ctx(struct nhlfe_list_head *nhlfe_head,
zlog_debug("%s: no match for lsp nhlfe %s",
__func__, buf);
UNSET_FLAG(nhlfe->flags, NHLFE_FLAG_INSTALLED);
+ UNSET_FLAG(nhlfe->flags, NHLFE_FLAG_SELECTED);
UNSET_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB);
UNSET_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE);
}
@@ -3281,7 +3321,7 @@ lsp_add_nhlfe(zebra_lsp_t *lsp, enum lsp_types_t type,
/*
* Install an LSP and forwarding entry; used primarily
- * from zapi message processing.
+ * from vrf zapi message processing.
*/
int mpls_lsp_install(struct zebra_vrf *zvrf, enum lsp_types_t type,
mpls_label_t in_label, uint8_t num_out_labels,
@@ -3332,8 +3372,19 @@ static int lsp_znh_install(zebra_lsp_t *lsp, enum lsp_types_t type,
/* Update backup info if present */
if (CHECK_FLAG(znh->flags, ZAPI_NEXTHOP_FLAG_HAS_BACKUP)) {
- nhlfe->nexthop->backup_idx = znh->backup_idx;
+ if (znh->backup_num > NEXTHOP_MAX_BACKUPS) {
+ nhlfe_del(nhlfe);
+ return -1;
+ }
+
+ nhlfe->nexthop->backup_num = znh->backup_num;
+ memcpy(nhlfe->nexthop->backup_idx, znh->backup_idx,
+ znh->backup_num);
SET_FLAG(nhlfe->nexthop->flags, NEXTHOP_FLAG_HAS_BACKUP);
+ } else {
+ /* Ensure there's no stale backup info */
+ UNSET_FLAG(nhlfe->nexthop->flags, NEXTHOP_FLAG_HAS_BACKUP);
+ nhlfe->nexthop->backup_num = 0;
}
/* Queue LSP for processing. */
@@ -3405,7 +3456,7 @@ int mpls_lsp_uninstall(struct zebra_vrf *zvrf, enum lsp_types_t type,
return 0;
if (IS_ZEBRA_DEBUG_MPLS) {
- nhlfe2str(nhlfe, buf, BUFSIZ);
+ nhlfe2str(nhlfe, buf, sizeof(buf));
zlog_debug("Del LSP in-label %u type %d nexthop %s flags 0x%x",
in_label, type, buf, nhlfe->flags);
}
@@ -3636,7 +3687,7 @@ int zebra_mpls_static_lsp_add(struct zebra_vrf *zvrf, mpls_label_t in_label,
return 0;
if (IS_ZEBRA_DEBUG_MPLS) {
- snhlfe2str(snhlfe, buf, BUFSIZ);
+ snhlfe2str(snhlfe, buf, sizeof(buf));
zlog_debug(
"Upd static LSP in-label %u nexthop %s out-label %u (old %u)",
in_label, buf, out_label, snhlfe->out_label);
@@ -3649,7 +3700,7 @@ int zebra_mpls_static_lsp_add(struct zebra_vrf *zvrf, mpls_label_t in_label,
return -1;
if (IS_ZEBRA_DEBUG_MPLS) {
- snhlfe2str(snhlfe, buf, BUFSIZ);
+ snhlfe2str(snhlfe, buf, sizeof(buf));
zlog_debug(
"Add static LSP in-label %u nexthop %s out-label %u",
in_label, buf, out_label);
@@ -3794,7 +3845,8 @@ void zebra_mpls_print_lsp_table(struct vty *vty, struct zebra_vrf *zvrf,
for (ALL_LIST_ELEMENTS_RO(lsp_list, node, lsp))
json_object_object_add(
- json, label2str(lsp->ile.in_label, buf, BUFSIZ),
+ json, label2str(lsp->ile.in_label, buf,
+ sizeof(buf)),
lsp_json(lsp));
vty_out(vty, "%s\n", json_object_to_json_string_ext(
@@ -3849,7 +3901,7 @@ void zebra_mpls_print_lsp_table(struct vty *vty, struct zebra_vrf *zvrf,
out_label_str = mpls_label2str(
nexthop->nh_label->num_labels,
&nexthop->nh_label->label[0],
- buf, BUFSIZ, 1);
+ buf, sizeof(buf), 1);
else
out_label_str = "-";
diff --git a/zebra/zebra_nb.c b/zebra/zebra_nb.c
index 53fe8e8e3f..a25d08f267 100644
--- a/zebra/zebra_nb.c
+++ b/zebra/zebra_nb.c
@@ -22,40 +22,6 @@
#include "libfrr.h"
#include "zebra_nb.h"
-const char *zebra_afi_safi_value2identity(afi_t afi, safi_t safi)
-{
- if (afi == AFI_IP && safi == SAFI_UNICAST)
- return "ipv4-unicast";
- if (afi == AFI_IP6 && safi == SAFI_UNICAST)
- return "ipv6-unicast";
- if (afi == AFI_IP && safi == SAFI_MULTICAST)
- return "ipv4-multicast";
- if (afi == AFI_IP6 && safi == SAFI_MULTICAST)
- return "ipv6-multicast";
-
- return " ";
-}
-
-void zebra_afi_safi_identity2value(const char *key, afi_t *afi, safi_t *safi)
-{
- if (strmatch(key, "frr-zebra:ipv4-unicast")) {
- *afi = AFI_IP;
- *safi = SAFI_UNICAST;
- } else if (strmatch(key, "frr-zebra:ipv6-unicast")) {
- *afi = AFI_IP6;
- *safi = SAFI_UNICAST;
- } else if (strmatch(key, "frr-zebra:ipv4-multicast")) {
- *afi = AFI_IP;
- *safi = SAFI_MULTICAST;
- } else if (strmatch(key, "frr-zebra:ipv6-multicast")) {
- *afi = AFI_IP6;
- *safi = SAFI_MULTICAST;
- } else {
- *afi = AFI_UNSPEC;
- *safi = SAFI_UNSPEC;
- }
-}
-
/* clang-format off */
const struct frr_yang_module_info frr_zebra_info = {
.name = "frr-zebra",
@@ -126,27 +92,6 @@ const struct frr_yang_module_info frr_zebra_info = {
}
},
{
- .xpath = "/frr-zebra:zebra/vrf-vni-mapping",
- .cbs = {
- .create = zebra_vrf_vni_mapping_create,
- .destroy = zebra_vrf_vni_mapping_destroy,
- }
- },
- {
- .xpath = "/frr-zebra:zebra/vrf-vni-mapping/vni-id",
- .cbs = {
- .modify = zebra_vrf_vni_mapping_vni_id_modify,
- .destroy = zebra_vrf_vni_mapping_vni_id_destroy,
- }
- },
- {
- .xpath = "/frr-zebra:zebra/vrf-vni-mapping/prefix-only",
- .cbs = {
- .create = zebra_vrf_vni_mapping_prefix_only_create,
- .destroy = zebra_vrf_vni_mapping_prefix_only_destroy,
- }
- },
- {
.xpath = "/frr-zebra:zebra/debugs/debug-events",
.cbs = {
.modify = zebra_debugs_debug_events_modify,
@@ -670,6 +615,19 @@ const struct frr_yang_module_info frr_zebra_info = {
}
},
{
+ .xpath = "/frr-vrf:lib/vrf/frr-zebra:zebra/l3vni-id",
+ .cbs = {
+ .modify = lib_vrf_zebra_l3vni_id_modify,
+ .destroy = lib_vrf_zebra_l3vni_id_destroy,
+ }
+ },
+ {
+ .xpath = "/frr-vrf:lib/vrf/frr-zebra:zebra/prefix-only",
+ .cbs = {
+ .modify = lib_vrf_zebra_prefix_only_modify,
+ }
+ },
+ {
.xpath = "/frr-route-map:lib/route-map/entry/match-condition/frr-zebra:ipv4-prefix-length",
.cbs = {
.modify = lib_route_map_entry_match_condition_ipv4_prefix_length_modify,
diff --git a/zebra/zebra_nb.h b/zebra/zebra_nb.h
index a9e7fd5fb0..80aeb02d2d 100644
--- a/zebra/zebra_nb.h
+++ b/zebra/zebra_nb.h
@@ -26,10 +26,6 @@ extern "C" {
extern const struct frr_yang_module_info frr_zebra_info;
-/* helper functions */
-const char *zebra_afi_safi_value2identity(afi_t afi, safi_t safi);
-void zebra_afi_safi_identity2value(const char *key, afi_t *afi, safi_t *safi);
-
/* prototypes */
int get_route_information_rpc(struct nb_cb_rpc_args *args);
int get_v6_mroute_info_rpc(struct nb_cb_rpc_args *args);
@@ -61,12 +57,6 @@ int zebra_import_kernel_table_route_map_destroy(
int zebra_allow_external_route_update_create(struct nb_cb_create_args *args);
int zebra_allow_external_route_update_destroy(struct nb_cb_destroy_args *args);
int zebra_dplane_queue_limit_modify(struct nb_cb_modify_args *args);
-int zebra_vrf_vni_mapping_create(struct nb_cb_create_args *args);
-int zebra_vrf_vni_mapping_destroy(struct nb_cb_destroy_args *args);
-int zebra_vrf_vni_mapping_vni_id_modify(struct nb_cb_modify_args *args);
-int zebra_vrf_vni_mapping_vni_id_destroy(struct nb_cb_destroy_args *args);
-int zebra_vrf_vni_mapping_prefix_only_create(struct nb_cb_create_args *args);
-int zebra_vrf_vni_mapping_prefix_only_destroy(struct nb_cb_destroy_args *args);
int zebra_debugs_debug_events_modify(struct nb_cb_modify_args *args);
int zebra_debugs_debug_events_destroy(struct nb_cb_destroy_args *args);
int zebra_debugs_debug_zapi_send_modify(struct nb_cb_modify_args *args);
@@ -320,6 +310,9 @@ lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_nexthop_fib_get_elem(
struct yang_data *
lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_nexthop_weight_get_elem(
struct nb_cb_get_elem_args *args);
+int lib_vrf_zebra_l3vni_id_modify(struct nb_cb_modify_args *args);
+int lib_vrf_zebra_l3vni_id_destroy(struct nb_cb_destroy_args *args);
+int lib_vrf_zebra_prefix_only_modify(struct nb_cb_modify_args *args);
#ifdef __cplusplus
}
diff --git a/zebra/zebra_nb_config.c b/zebra/zebra_nb_config.c
index 948ef51320..e4501273bd 100644
--- a/zebra/zebra_nb_config.c
+++ b/zebra/zebra_nb_config.c
@@ -31,6 +31,8 @@
#include "zebra/connected.h"
#include "zebra/zebra_router.h"
#include "zebra/debug.h"
+#include "zebra/zebra_vxlan_private.h"
+#include "zebra/zebra_vxlan.h"
/*
* XPath: /frr-zebra:zebra/mcast-rpf-lookup
@@ -273,99 +275,6 @@ int zebra_dplane_queue_limit_modify(struct nb_cb_modify_args *args)
}
/*
- * XPath: /frr-zebra:zebra/vrf-vni-mapping
- */
-int zebra_vrf_vni_mapping_create(struct nb_cb_create_args *args)
-{
- switch (args->event) {
- case NB_EV_VALIDATE:
- case NB_EV_PREPARE:
- case NB_EV_ABORT:
- case NB_EV_APPLY:
- /* TODO: implement me. */
- break;
- }
-
- return NB_OK;
-}
-
-int zebra_vrf_vni_mapping_destroy(struct nb_cb_destroy_args *args)
-{
- switch (args->event) {
- case NB_EV_VALIDATE:
- case NB_EV_PREPARE:
- case NB_EV_ABORT:
- case NB_EV_APPLY:
- /* TODO: implement me. */
- break;
- }
-
- return NB_OK;
-}
-
-/*
- * XPath: /frr-zebra:zebra/vrf-vni-mapping/vni-id
- */
-int zebra_vrf_vni_mapping_vni_id_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:
- /* TODO: implement me. */
- break;
- }
-
- return NB_OK;
-}
-
-int zebra_vrf_vni_mapping_vni_id_destroy(struct nb_cb_destroy_args *args)
-{
- switch (args->event) {
- case NB_EV_VALIDATE:
- case NB_EV_PREPARE:
- case NB_EV_ABORT:
- case NB_EV_APPLY:
- /* TODO: implement me. */
- break;
- }
-
- return NB_OK;
-}
-
-/*
- * XPath: /frr-zebra:zebra/vrf-vni-mapping/prefix-only
- */
-int zebra_vrf_vni_mapping_prefix_only_create(struct nb_cb_create_args *args)
-{
- switch (args->event) {
- case NB_EV_VALIDATE:
- case NB_EV_PREPARE:
- case NB_EV_ABORT:
- case NB_EV_APPLY:
- /* TODO: implement me. */
- break;
- }
-
- return NB_OK;
-}
-
-int zebra_vrf_vni_mapping_prefix_only_destroy(struct nb_cb_destroy_args *args)
-{
- switch (args->event) {
- case NB_EV_VALIDATE:
- case NB_EV_PREPARE:
- case NB_EV_ABORT:
- case NB_EV_APPLY:
- /* TODO: implement me. */
- break;
- }
-
- return NB_OK;
-}
-
-/*
* XPath: /frr-zebra:zebra/debugs/debug-events
*/
int zebra_debugs_debug_events_modify(struct nb_cb_modify_args *args)
@@ -1242,7 +1151,7 @@ int lib_vrf_zebra_ribs_rib_create(struct nb_cb_create_args *args)
table_id = zvrf->table_id;
afi_safi_name = yang_dnode_get_string(args->dnode, "./afi-safi-name");
- zebra_afi_safi_identity2value(afi_safi_name, &afi, &safi);
+ yang_afi_safi_identity2value(afi_safi_name, &afi, &safi);
zrt = zebra_router_find_zrt(zvrf, table_id, afi, safi);
@@ -1277,6 +1186,150 @@ int lib_vrf_zebra_ribs_rib_destroy(struct nb_cb_destroy_args *args)
return NB_OK;
}
+/*
+ * XPath: /frr-vrf:lib/vrf/frr-zebra:zebra/l3vni-id
+ */
+int lib_vrf_zebra_l3vni_id_modify(struct nb_cb_modify_args *args)
+{
+ struct vrf *vrf;
+ struct zebra_vrf *zvrf;
+ vni_t vni = 0;
+ zebra_l3vni_t *zl3vni = NULL;
+ struct zebra_vrf *zvrf_evpn = NULL;
+ char err[ERR_STR_SZ];
+ bool pfx_only = false;
+ const struct lyd_node *pn_dnode;
+ const char *vrfname;
+
+ switch (args->event) {
+ case NB_EV_PREPARE:
+ case NB_EV_ABORT:
+ break;
+ case NB_EV_VALIDATE:
+ zvrf_evpn = zebra_vrf_get_evpn();
+ if (!zvrf_evpn)
+ return NB_ERR_VALIDATION;
+
+ vni = yang_dnode_get_uint32(args->dnode, NULL);
+ /* Get vrf info from parent node, reject configuration
+ * if zebra vrf already mapped to different vni id.
+ */
+ pn_dnode = yang_dnode_get_parent(args->dnode, "vrf");
+ if (pn_dnode) {
+ vrfname = yang_dnode_get_string(pn_dnode, "./name");
+ vrf = vrf_lookup_by_name(vrfname);
+ zvrf = zebra_vrf_lookup_by_id(vrf->vrf_id);
+ if (zvrf->l3vni && zvrf->l3vni != vni) {
+ zlog_debug(
+ "vni %u cannot be configured as vni %u is already configured under the vrf",
+ vni, zvrf->l3vni);
+ return NB_ERR_VALIDATION;
+ }
+ }
+
+ /* Check if this VNI is already present in the system */
+ zl3vni = zl3vni_lookup(vni);
+ if (zl3vni) {
+ if (IS_ZEBRA_DEBUG_VXLAN)
+ zlog_debug(
+ "VNI %u is already configured as L3-VNI",
+ vni);
+ return NB_ERR_VALIDATION;
+ }
+
+ break;
+ case NB_EV_APPLY:
+
+ vrf = nb_running_get_entry(args->dnode, NULL, true);
+ zvrf = zebra_vrf_lookup_by_id(vrf->vrf_id);
+ vni = yang_dnode_get_uint32(args->dnode, NULL);
+ /* Note: This covers lib_vrf_zebra_prefix_only_modify() config
+ * along with l3vni config
+ */
+ pfx_only = yang_dnode_get_bool(args->dnode, "../prefix-only");
+
+ if (zebra_vxlan_process_vrf_vni_cmd(zvrf, vni, err, ERR_STR_SZ,
+ pfx_only ? 1 : 0, 1)
+ != 0) {
+ if (IS_ZEBRA_DEBUG_VXLAN)
+ zlog_debug(
+ "vrf vni %u mapping failed with error: %s",
+ vni, err);
+ return NB_ERR;
+ }
+
+ /* Mark as having FRR configuration */
+ vrf_set_user_cfged(vrf);
+
+ break;
+ }
+
+ return NB_OK;
+}
+
+int lib_vrf_zebra_l3vni_id_destroy(struct nb_cb_destroy_args *args)
+{
+ struct vrf *vrf;
+ struct zebra_vrf *zvrf;
+ vni_t vni = 0;
+ char err[ERR_STR_SZ];
+ uint8_t filter = 0;
+
+ switch (args->event) {
+ case NB_EV_PREPARE:
+ case NB_EV_ABORT:
+ case NB_EV_VALIDATE:
+ break;
+ case NB_EV_APPLY:
+ vrf = nb_running_get_entry(args->dnode, NULL, true);
+ zvrf = zebra_vrf_lookup_by_id(vrf->vrf_id);
+ vni = yang_dnode_get_uint32(args->dnode, NULL);
+
+ if (!zl3vni_lookup(vni))
+ return NB_OK;
+
+ if (zvrf->l3vni != vni)
+ return NB_ERR;
+
+ if (is_l3vni_for_prefix_routes_only(zvrf->l3vni))
+ filter = 1;
+
+ if (zebra_vxlan_process_vrf_vni_cmd(zvrf, vni, err, ERR_STR_SZ,
+ filter, 0)
+ != 0) {
+ if (IS_ZEBRA_DEBUG_VXLAN)
+ zlog_debug(
+ "vrf vni %u unmapping failed with error: %s",
+ vni, err);
+ return NB_ERR;
+ }
+
+ /* If no other FRR config for this VRF, mark accordingly. */
+ if (!zebra_vrf_has_config(zvrf))
+ vrf_reset_user_cfged(vrf);
+
+ break;
+ }
+
+ return NB_OK;
+}
+
+/*
+ * XPath: /frr-vrf:lib/vrf/frr-zebra:zebra/prefix-only
+ */
+int lib_vrf_zebra_prefix_only_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:
+ /* TODO: implement me. */
+ break;
+ }
+
+ return NB_OK;
+}
/*
* XPath:
diff --git a/zebra/zebra_nb_state.c b/zebra/zebra_nb_state.c
index 4374da360e..19ad3769eb 100644
--- a/zebra/zebra_nb_state.c
+++ b/zebra/zebra_nb_state.c
@@ -185,9 +185,8 @@ int lib_vrf_zebra_ribs_rib_get_keys(struct nb_cb_get_keys_args *args)
args->keys->num = 2;
- snprintfrr(args->keys->key[0], sizeof(args->keys->key[0]), "%s:%s",
- "frr-zebra",
- zebra_afi_safi_value2identity(zrt->afi, zrt->safi));
+ snprintfrr(args->keys->key[0], sizeof(args->keys->key[0]), "%s",
+ yang_afi_safi_value2identity(zrt->afi, zrt->safi));
snprintfrr(args->keys->key[1], sizeof(args->keys->key[1]), "%u",
zrt->tableid);
@@ -205,7 +204,7 @@ lib_vrf_zebra_ribs_rib_lookup_entry(struct nb_cb_lookup_entry_args *args)
zvrf = zebra_vrf_lookup_by_id(vrf->vrf_id);
- zebra_afi_safi_identity2value(args->keys->key[0], &afi, &safi);
+ 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)
@@ -526,54 +525,57 @@ int lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_nexthop_get_keys(
{
struct nexthop *nexthop = (struct nexthop *)args->list_entry;
- args->keys->num = 3;
+ args->keys->num = 4;
strlcpy(args->keys->key[0], yang_nexthop_type2str(nexthop->type),
sizeof(args->keys->key[0]));
+ snprintfrr(args->keys->key[1], sizeof(args->keys->key[1]), "%" PRIu32,
+ nexthop->vrf_id);
+
switch (nexthop->type) {
case NEXTHOP_TYPE_IPV4:
case NEXTHOP_TYPE_IPV4_IFINDEX:
- snprintfrr(args->keys->key[1], sizeof(args->keys->key[1]),
+ snprintfrr(args->keys->key[2], sizeof(args->keys->key[2]),
"%pI4", &nexthop->gate.ipv4);
if (nexthop->ifindex)
- strlcpy(args->keys->key[2],
+ strlcpy(args->keys->key[3],
ifindex2ifname(nexthop->ifindex,
nexthop->vrf_id),
- sizeof(args->keys->key[2]));
+ sizeof(args->keys->key[3]));
else
/* no ifindex */
- strlcpy(args->keys->key[2], " ",
- sizeof(args->keys->key[2]));
+ strlcpy(args->keys->key[3], " ",
+ sizeof(args->keys->key[3]));
break;
case NEXTHOP_TYPE_IPV6:
case NEXTHOP_TYPE_IPV6_IFINDEX:
- snprintfrr(args->keys->key[1], sizeof(args->keys->key[1]),
+ snprintfrr(args->keys->key[2], sizeof(args->keys->key[2]),
"%pI6", &nexthop->gate.ipv6);
if (nexthop->ifindex)
- strlcpy(args->keys->key[2],
+ strlcpy(args->keys->key[3],
ifindex2ifname(nexthop->ifindex,
nexthop->vrf_id),
- sizeof(args->keys->key[2]));
+ sizeof(args->keys->key[3]));
else
/* no ifindex */
- strlcpy(args->keys->key[2], " ",
- sizeof(args->keys->key[2]));
+ strlcpy(args->keys->key[3], " ",
+ sizeof(args->keys->key[3]));
break;
case NEXTHOP_TYPE_IFINDEX:
- strlcpy(args->keys->key[1], "", sizeof(args->keys->key[1]));
- strlcpy(args->keys->key[2],
+ strlcpy(args->keys->key[2], "", sizeof(args->keys->key[2]));
+ strlcpy(args->keys->key[3],
ifindex2ifname(nexthop->ifindex, nexthop->vrf_id),
- sizeof(args->keys->key[2]));
+ sizeof(args->keys->key[3]));
break;
case NEXTHOP_TYPE_BLACKHOLE:
/* Gateway IP */
- strlcpy(args->keys->key[1], "", sizeof(args->keys->key[1]));
- strlcpy(args->keys->key[2], " ", sizeof(args->keys->key[2]));
+ strlcpy(args->keys->key[2], "", sizeof(args->keys->key[2]));
+ strlcpy(args->keys->key[3], " ", sizeof(args->keys->key[3]));
break;
default:
break;
diff --git a/zebra/zebra_netns_id.c b/zebra/zebra_netns_id.c
index 79121bb086..8de4daf439 100644
--- a/zebra/zebra_netns_id.c
+++ b/zebra/zebra_netns_id.c
@@ -159,34 +159,27 @@ static ns_id_t extract_nsid(struct nlmsghdr *nlh, char *buf)
return ns_id;
}
-/* fd_param = -1 is ignored.
- * netnspath set to null is ignored.
- * one of the 2 params is mandatory. netnspath is looked in priority
- */
-ns_id_t zebra_ns_id_get(const char *netnspath, int fd_param)
+ns_id_t zebra_ns_id_get(const char *netnspath)
{
int ns_id = -1;
struct sockaddr_nl snl;
- int fd = -1, sock, ret;
+ int fd, sock, ret;
unsigned int seq;
ns_id_t return_nsid = NS_UNKNOWN;
/* netns path check */
- if (!netnspath && fd_param == -1)
+ if (!netnspath)
return NS_UNKNOWN;
- if (netnspath) {
- fd = open(netnspath, O_RDONLY);
- if (fd == -1)
- return NS_UNKNOWN;
- } else if (fd_param != -1)
- fd = fd_param;
+ fd = open(netnspath, O_RDONLY);
+ if (fd == -1)
+ return NS_UNKNOWN;
+
/* netlink socket */
sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
if (sock < 0) {
flog_err_sys(EC_LIB_SOCKET, "netlink( %u) socket() error: %s",
sock, safe_strerror(errno));
- if (fd_param == -1)
- close(fd);
+ close(fd);
return NS_UNKNOWN;
}
memset(&snl, 0, sizeof(snl));
@@ -199,8 +192,7 @@ ns_id_t zebra_ns_id_get(const char *netnspath, int fd_param)
"netlink( %u) socket() bind error: %s", sock,
safe_strerror(errno));
close(sock);
- if (fd_param == -1)
- close(fd);
+ close(fd);
return NS_UNKNOWN;
}
@@ -222,8 +214,7 @@ ns_id_t zebra_ns_id_get(const char *netnspath, int fd_param)
ret = send_receive(sock, nlh, seq, buf);
if (ret < 0) {
close(sock);
- if (fd_param == -1)
- close(fd);
+ close(fd);
return NS_UNKNOWN;
}
nlh = (struct nlmsghdr *)buf;
@@ -267,8 +258,7 @@ ns_id_t zebra_ns_id_get(const char *netnspath, int fd_param)
"netlink( %u) recvfrom() error 2 when reading: %s",
fd, safe_strerror(errno));
close(sock);
- if (fd_param == -1)
- close(fd);
+ close(fd);
if (errno == ENOTSUP) {
zlog_debug("NEWNSID locally generated");
return zebra_ns_id_get_fallback(netnspath);
@@ -289,8 +279,7 @@ ns_id_t zebra_ns_id_get(const char *netnspath, int fd_param)
ret = send_receive(sock, nlh, seq, buf);
if (ret < 0) {
close(sock);
- if (fd_param == -1)
- close(fd);
+ close(fd);
return NS_UNKNOWN;
}
nlh = (struct nlmsghdr *)buf;
@@ -321,18 +310,16 @@ ns_id_t zebra_ns_id_get(const char *netnspath, int fd_param)
} while (len != 0 && ret == 0);
}
- if (fd_param == -1)
- close(fd);
+ close(fd);
close(sock);
return return_nsid;
}
#else
-ns_id_t zebra_ns_id_get(const char *netnspath, int fd __attribute__ ((unused)))
+ns_id_t zebra_ns_id_get(const char *netnspath)
{
return zebra_ns_id_get_fallback(netnspath);
}
-
#endif /* ! defined(HAVE_NETLINK) */
#ifdef HAVE_NETNS
@@ -368,7 +355,7 @@ ns_id_t zebra_ns_id_get_default(void)
return NS_DEFAULT_INTERNAL;
}
close(fd);
- return zebra_ns_id_get((char *)NS_DEFAULT_NAME, -1);
+ return zebra_ns_id_get((char *)NS_DEFAULT_NAME);
#else /* HAVE_NETNS */
return NS_DEFAULT_INTERNAL;
#endif /* !HAVE_NETNS */
diff --git a/zebra/zebra_netns_id.h b/zebra/zebra_netns_id.h
index dd9eab18e0..7a5f6851f4 100644
--- a/zebra/zebra_netns_id.h
+++ b/zebra/zebra_netns_id.h
@@ -24,7 +24,7 @@
extern "C" {
#endif
-extern ns_id_t zebra_ns_id_get(const char *netnspath, int fd);
+extern ns_id_t zebra_ns_id_get(const char *netnspath);
extern ns_id_t zebra_ns_id_get_default(void);
#ifdef __cplusplus
diff --git a/zebra/zebra_netns_notify.c b/zebra/zebra_netns_notify.c
index 4e504c48b0..ec7681bf23 100644
--- a/zebra/zebra_netns_notify.c
+++ b/zebra/zebra_netns_notify.c
@@ -72,14 +72,13 @@ static void zebra_ns_notify_create_context_from_entry_name(const char *name)
char *netnspath = ns_netns_pathname(NULL, name);
struct vrf *vrf;
int ret;
- ns_id_t ns_id, ns_id_external, ns_id_relative = NS_UNKNOWN;
- struct ns *default_ns;
+ ns_id_t ns_id, ns_id_external;
if (netnspath == NULL)
return;
frr_with_privs(&zserv_privs) {
- ns_id = zebra_ns_id_get(netnspath, -1);
+ ns_id = zebra_ns_id_get(netnspath);
}
if (ns_id == NS_UNKNOWN)
return;
@@ -98,21 +97,9 @@ static void zebra_ns_notify_create_context_from_entry_name(const char *name)
ns_map_nsid_with_external(ns_id, false);
return;
}
-
- default_ns = ns_get_default();
-
- /* force kernel ns_id creation in that new vrf */
- frr_with_privs(&zserv_privs) {
- ns_switch_to_netns(netnspath);
- ns_id_relative = zebra_ns_id_get(NULL, default_ns->fd);
- ns_switchback_to_initial();
- }
-
frr_with_privs(&zserv_privs) {
ret = vrf_netns_handler_create(NULL, vrf, netnspath,
- ns_id_external,
- ns_id,
- ns_id_relative);
+ ns_id_external, ns_id);
}
if (ret != CMD_SUCCESS) {
flog_warn(EC_ZEBRA_NS_VRF_CREATION_FAILED,
@@ -185,7 +172,7 @@ static bool zebra_ns_notify_is_default_netns(const char *name)
{
struct stat default_netns_stat;
struct stat st;
- char netnspath[64];
+ char netnspath[PATH_MAX];
if (zebra_ns_notify_self_identify(&default_netns_stat))
return false;
diff --git a/zebra/zebra_nhg.c b/zebra/zebra_nhg.c
index 9bfd7aacb7..43bf745896 100644
--- a/zebra/zebra_nhg.c
+++ b/zebra/zebra_nhg.c
@@ -1775,6 +1775,7 @@ static int nexthop_active(afi_t afi, struct route_entry *re,
struct interface *ifp;
rib_dest_t *dest;
struct zebra_vrf *zvrf;
+ struct in_addr ipv4;
if ((nexthop->type == NEXTHOP_TYPE_IPV4)
|| nexthop->type == NEXTHOP_TYPE_IPV6)
@@ -1835,13 +1836,23 @@ static int nexthop_active(afi_t afi, struct route_entry *re,
return 0;
}
+ /* Validation for ipv4 mapped ipv6 nexthop. */
+ if (IS_MAPPED_IPV6(&nexthop->gate.ipv6)) {
+ afi = AFI_IP;
+ }
+
/* Make lookup prefix. */
memset(&p, 0, sizeof(struct prefix));
switch (afi) {
case AFI_IP:
p.family = AF_INET;
p.prefixlen = IPV4_MAX_PREFIXLEN;
- p.u.prefix4 = nexthop->gate.ipv4;
+ if (IS_MAPPED_IPV6(&nexthop->gate.ipv6)) {
+ ipv4_mapped_ipv6_to_ipv4(&nexthop->gate.ipv6, &ipv4);
+ p.u.prefix4 = ipv4;
+ } else {
+ p.u.prefix4 = nexthop->gate.ipv4;
+ }
break;
case AFI_IP6:
p.family = AF_INET6;
@@ -1951,8 +1962,11 @@ static int nexthop_active(afi_t afi, struct route_entry *re,
goto done_with_match;
}
- /* Examine installed nexthops */
- nhg = &match->nhe->nhg;
+ /* Examine installed nexthops; note that there
+ * may not be any installed primary nexthops if
+ * only backups are installed.
+ */
+ nhg = rib_get_fib_nhg(match);
for (ALL_NEXTHOPS_PTR(nhg, newhop)) {
if (!nexthop_valid_resolve(nexthop, newhop))
continue;
@@ -1973,8 +1987,7 @@ static int nexthop_active(afi_t afi, struct route_entry *re,
* dedicated fib list.
*/
nhg = rib_get_fib_backup_nhg(match);
- if (nhg == NULL ||
- nhg == zebra_nhg_get_backup_nhg(match->nhe))
+ if (nhg == NULL || nhg->nexthop == NULL)
goto done_with_match;
for (ALL_NEXTHOPS_PTR(nhg, newhop)) {
diff --git a/zebra/zebra_ns.c b/zebra/zebra_ns.c
index 6462daf687..4e51437337 100644
--- a/zebra/zebra_ns.c
+++ b/zebra/zebra_ns.c
@@ -153,25 +153,20 @@ static int zebra_ns_disable_internal(struct zebra_ns *zns, bool complete)
/* During zebra shutdown, do partial cleanup while the async dataplane
* is still running.
*/
-int zebra_ns_early_shutdown(struct ns *ns,
- void *param_in __attribute__((unused)),
- void **param_out __attribute__((unused)))
+int zebra_ns_early_shutdown(struct ns *ns)
{
struct zebra_ns *zns = ns->info;
if (zns == NULL)
return 0;
- zebra_ns_disable_internal(zns, false);
- return NS_WALK_CONTINUE;
+ return zebra_ns_disable_internal(zns, false);
}
/* During zebra shutdown, do final cleanup
* after all dataplane work is complete.
*/
-int zebra_ns_final_shutdown(struct ns *ns,
- void *param_in __attribute__((unused)),
- void **param_out __attribute__((unused)))
+int zebra_ns_final_shutdown(struct ns *ns)
{
struct zebra_ns *zns = ns->info;
@@ -180,7 +175,7 @@ int zebra_ns_final_shutdown(struct ns *ns,
kernel_terminate(zns, true);
- return NS_WALK_CONTINUE;
+ return 0;
}
int zebra_ns_init(const char *optional_default_name)
@@ -188,16 +183,12 @@ int zebra_ns_init(const char *optional_default_name)
struct ns *default_ns;
ns_id_t ns_id;
ns_id_t ns_id_external;
- struct ns *ns;
frr_with_privs(&zserv_privs) {
ns_id = zebra_ns_id_get_default();
}
ns_id_external = ns_map_nsid_with_external(ns_id, true);
ns_init_management(ns_id_external, ns_id);
- ns = ns_get_default();
- if (ns)
- ns->relative_default_ns = ns_id;
default_ns = ns_lookup(ns_get_default_id());
if (!default_ns) {
diff --git a/zebra/zebra_ns.h b/zebra/zebra_ns.h
index f7d1f40782..dc79a83db0 100644
--- a/zebra/zebra_ns.h
+++ b/zebra/zebra_ns.h
@@ -67,12 +67,9 @@ struct zebra_ns *zebra_ns_lookup(ns_id_t ns_id);
int zebra_ns_init(const char *optional_default_name);
int zebra_ns_enable(ns_id_t ns_id, void **info);
int zebra_ns_disabled(struct ns *ns);
-int zebra_ns_early_shutdown(struct ns *ns,
- void *param_in __attribute__((unused)),
- void **param_out __attribute__((unused)));
-int zebra_ns_final_shutdown(struct ns *ns,
- void *param_in __attribute__((unused)),
- void **param_out __attribute__((unused)));
+int zebra_ns_early_shutdown(struct ns *ns);
+int zebra_ns_final_shutdown(struct ns *ns);
+
int zebra_ns_config_write(struct vty *vty, struct ns *ns);
#ifdef __cplusplus
diff --git a/zebra/zebra_pbr.c b/zebra/zebra_pbr.c
index c5a7795273..1bc8d893bc 100644
--- a/zebra/zebra_pbr.c
+++ b/zebra/zebra_pbr.c
@@ -336,14 +336,20 @@ bool zebra_pbr_ipset_entry_hash_equal(const void *arg1, const void *arg2)
return true;
}
-void zebra_pbr_iptable_free(void *arg)
+/* this function gives option to flush plugin memory contexts
+ * with all parameter. set it to true to flush all
+ * set it to false to flush only passed arg argument
+ */
+static void _zebra_pbr_iptable_free_all(void *arg, bool all)
{
struct zebra_pbr_iptable *iptable;
struct listnode *node, *nnode;
char *name;
iptable = (struct zebra_pbr_iptable *)arg;
- hook_call(zebra_pbr_iptable_update, 0, iptable);
+
+ if (all)
+ hook_call(zebra_pbr_iptable_update, 0, iptable);
if (iptable->interface_name_list) {
for (ALL_LIST_ELEMENTS(iptable->interface_name_list, node,
@@ -356,6 +362,11 @@ void zebra_pbr_iptable_free(void *arg)
XFREE(MTYPE_TMP, iptable);
}
+void zebra_pbr_iptable_free(void *arg)
+{
+ _zebra_pbr_iptable_free_all(arg, false);
+}
+
uint32_t zebra_pbr_iptable_hash_key(const void *arg)
{
const struct zebra_pbr_iptable *iptable = arg;
@@ -529,7 +540,7 @@ static void zebra_pbr_cleanup_iptable(struct hash_bucket *b, void *data)
if (iptable->sock == *sock) {
if (hash_release(zrouter.iptable_hash, iptable))
- zebra_pbr_iptable_free(iptable);
+ _zebra_pbr_iptable_free_all(iptable, true);
else
hook_call(zebra_pbr_iptable_update, 0, iptable);
}
diff --git a/zebra/zebra_pbr.h b/zebra/zebra_pbr.h
index 4bc0f40037..dd2d7a190d 100644
--- a/zebra/zebra_pbr.h
+++ b/zebra/zebra_pbr.h
@@ -54,6 +54,8 @@ 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_pw.c b/zebra/zebra_pw.c
index c00cd88fe3..cdcca1e930 100644
--- a/zebra/zebra_pw.c
+++ b/zebra/zebra_pw.c
@@ -517,6 +517,7 @@ static void vty_show_mpls_pseudowire_detail(struct vty *vty)
struct zebra_pw *pw;
struct route_entry *re;
struct nexthop *nexthop;
+ struct nexthop_group *nhg;
zvrf = vrf_info_lookup(VRF_DEFAULT);
if (!zvrf)
@@ -544,22 +545,41 @@ static void vty_show_mpls_pseudowire_detail(struct vty *vty)
vty_out(vty, " VC-ID: %u\n", pw->data.ldp.pwid);
vty_out(vty, " Status: %s \n",
(zebra_pw_enabled(pw) && pw->status == PW_FORWARDING)
- ? "Up"
- : "Down");
+ ? "Up"
+ : "Down");
re = rib_match(family2afi(pw->af), SAFI_UNICAST, pw->vrf_id,
&pw->nexthop, NULL);
- if (re) {
- for (ALL_NEXTHOPS_PTR(rib_get_fib_nhg(re), nexthop)) {
- snprintfrr(buf_nh, sizeof(buf_nh), "%pNHv",
- nexthop);
- vty_out(vty, " Next Hop: %s\n", buf_nh);
- if (nexthop->nh_label)
- vty_out(vty, " Next Hop label: %u\n",
- nexthop->nh_label->label[0]);
- else
- vty_out(vty, " Next Hop label: %s\n",
- "-");
- }
+ if (re == NULL)
+ continue;
+
+ nhg = rib_get_fib_nhg(re);
+ for (ALL_NEXTHOPS_PTR(nhg, nexthop)) {
+ snprintfrr(buf_nh, sizeof(buf_nh), "%pNHv",
+ nexthop);
+ vty_out(vty, " Next Hop: %s\n", buf_nh);
+ if (nexthop->nh_label)
+ vty_out(vty, " Next Hop label: %u\n",
+ nexthop->nh_label->label[0]);
+ else
+ vty_out(vty, " Next Hop label: %s\n",
+ "-");
+ }
+
+ /* Include any installed backups */
+ nhg = rib_get_fib_backup_nhg(re);
+ if (nhg == NULL)
+ continue;
+
+ for (ALL_NEXTHOPS_PTR(nhg, nexthop)) {
+ snprintfrr(buf_nh, sizeof(buf_nh), "%pNHv",
+ nexthop);
+ vty_out(vty, " Next Hop: %s\n", buf_nh);
+ if (nexthop->nh_label)
+ vty_out(vty, " Next Hop label: %u\n",
+ nexthop->nh_label->label[0]);
+ else
+ vty_out(vty, " Next Hop label: %s\n",
+ "-");
}
}
}
@@ -568,6 +588,7 @@ static void vty_show_mpls_pseudowire(struct zebra_pw *pw, json_object *json_pws)
{
struct route_entry *re;
struct nexthop *nexthop;
+ struct nexthop_group *nhg;
char buf_nbr[INET6_ADDRSTRLEN];
char buf_nh[100];
json_object *json_pw = NULL;
@@ -602,23 +623,48 @@ static void vty_show_mpls_pseudowire(struct zebra_pw *pw, json_object *json_pws)
: "Down");
re = rib_match(family2afi(pw->af), SAFI_UNICAST, pw->vrf_id,
&pw->nexthop, NULL);
- if (re) {
- for (ALL_NEXTHOPS_PTR(rib_get_fib_nhg(re), nexthop)) {
- json_nexthop = json_object_new_object();
- snprintfrr(buf_nh, sizeof(buf_nh), "%pNHv", nexthop);
- json_object_string_add(json_nexthop, "nexthop", buf_nh);
- if (nexthop->nh_label)
- json_object_int_add(
- json_nexthop, "nhLabel",
- nexthop->nh_label->label[0]);
- else
- json_object_string_add(json_nexthop, "nhLabel",
- "-");
+ if (re == NULL)
+ goto done;
+
+ nhg = rib_get_fib_nhg(re);
+ for (ALL_NEXTHOPS_PTR(nhg, nexthop)) {
+ json_nexthop = json_object_new_object();
+ snprintfrr(buf_nh, sizeof(buf_nh), "%pNHv", nexthop);
+ json_object_string_add(json_nexthop, "nexthop", buf_nh);
+ if (nexthop->nh_label)
+ json_object_int_add(
+ json_nexthop, "nhLabel",
+ nexthop->nh_label->label[0]);
+ else
+ json_object_string_add(json_nexthop, "nhLabel",
+ "-");
- json_object_array_add(json_nexthops, json_nexthop);
- }
- json_object_object_add(json_pw, "nexthops", json_nexthops);
+ json_object_array_add(json_nexthops, json_nexthop);
+ }
+
+ /* Include installed backup nexthops also */
+ nhg = rib_get_fib_backup_nhg(re);
+ if (nhg == NULL)
+ goto done;
+
+ for (ALL_NEXTHOPS_PTR(nhg, nexthop)) {
+ json_nexthop = json_object_new_object();
+ snprintfrr(buf_nh, sizeof(buf_nh), "%pNHv", nexthop);
+ json_object_string_add(json_nexthop, "nexthop", buf_nh);
+ if (nexthop->nh_label)
+ json_object_int_add(
+ json_nexthop, "nhLabel",
+ nexthop->nh_label->label[0]);
+ else
+ json_object_string_add(json_nexthop, "nhLabel",
+ "-");
+
+ json_object_array_add(json_nexthops, json_nexthop);
}
+
+done:
+
+ json_object_object_add(json_pw, "nexthops", json_nexthops);
json_object_array_add(json_pws, json_pw);
}
diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c
index ddf2766737..ee9d5d76e0 100644
--- a/zebra/zebra_rib.c
+++ b/zebra/zebra_rib.c
@@ -472,6 +472,7 @@ void rib_install_kernel(struct route_node *rn, struct route_entry *re,
SET_FLAG(old->status, ROUTE_ENTRY_QUEUED);
/* Free old FIB nexthop group */
+ UNSET_FLAG(old->status, ROUTE_ENTRY_USE_FIB_NHG);
if (old->fib_ng.nexthop) {
nexthops_free(old->fib_ng.nexthop);
old->fib_ng.nexthop = NULL;
@@ -574,6 +575,7 @@ static void rib_uninstall(struct route_node *rn, struct route_entry *re)
nexthops_free(re->fib_ng.nexthop);
re->fib_ng.nexthop = NULL;
}
+ UNSET_FLAG(re->status, ROUTE_ENTRY_USE_FIB_NHG);
for (ALL_NEXTHOPS(re->nhe->nhg, nexthop))
UNSET_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB);
@@ -1375,7 +1377,7 @@ static bool rib_update_nhg_from_ctx(struct nexthop_group *re_nhg,
continue;
/* Check for a FIB nexthop corresponding to the RIB nexthop */
- if (nexthop_same(ctx_nexthop, nexthop) == false) {
+ if (!nexthop_same(ctx_nexthop, nexthop)) {
/* If the FIB doesn't know about the nexthop,
* it's not installed
*/
@@ -1490,7 +1492,7 @@ static bool rib_update_re_from_ctx(struct route_entry *re,
VRF_LOGNAME(vrf), re->vrf_id, dest_str);
goto check_backups;
- } else if (re->fib_ng.nexthop) {
+ } else if (CHECK_FLAG(re->status, ROUTE_ENTRY_USE_FIB_NHG)) {
/*
* Free stale fib list and move on to check the rib nhg.
*/
@@ -1501,6 +1503,8 @@ static bool rib_update_re_from_ctx(struct route_entry *re,
nexthops_free(re->fib_ng.nexthop);
re->fib_ng.nexthop = NULL;
+ UNSET_FLAG(re->status, ROUTE_ENTRY_USE_FIB_NHG);
+
/* Note that the installed nexthops have changed */
changed_p = true;
} else {
@@ -1546,20 +1550,15 @@ no_nexthops:
*/
if (IS_ZEBRA_DEBUG_RIB)
zlog_debug(
- "%s(%u):%s update_from_ctx(): changed %s, adding new fib nhg",
+ "%s(%u):%s update_from_ctx(): changed %s, adding new fib nhg%s",
VRF_LOGNAME(vrf), re->vrf_id, dest_str,
- (changed_p ? "true" : "false"));
+ (changed_p ? "true" : "false"),
+ ctxnhg->nexthop != NULL ? "" : " (empty)");
+ /* Set the flag about the dedicated fib list */
+ SET_FLAG(re->status, ROUTE_ENTRY_USE_FIB_NHG);
if (ctxnhg->nexthop)
copy_nexthops(&(re->fib_ng.nexthop), ctxnhg->nexthop, NULL);
- else {
- /* Bit of a special case when the fib has _no_ installed
- * nexthops.
- */
- nexthop = nexthop_new();
- nexthop->type = NEXTHOP_TYPE_IPV4;
- _nexthop_add(&(re->fib_ng.nexthop), nexthop);
- }
check_backups:
@@ -1611,7 +1610,7 @@ check_backups:
}
/*
- * If a FIB backup nexthop set exists: attach a copy
+ * If a FIB backup nexthop set exists, attach a copy
* to the route if any backup is installed
*/
if (ctxnhg && ctxnhg->nexthop) {
@@ -1936,7 +1935,7 @@ static int rib_count_installed_nh(struct route_entry *re)
/* The meaningful flag depends on where the installed
* nexthops reside.
*/
- if (nhg == &(re->fib_backup_ng)) {
+ if (nhg == &(re->fib_ng)) {
if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB))
count++;
} else {
@@ -1945,9 +1944,12 @@ static int rib_count_installed_nh(struct route_entry *re)
}
}
- for (ALL_NEXTHOPS_PTR(rib_get_fib_backup_nhg(re), nexthop)) {
- if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB))
- count++;
+ nhg = rib_get_fib_backup_nhg(re);
+ if (nhg) {
+ for (ALL_NEXTHOPS_PTR(nhg, nexthop)) {
+ if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB))
+ count++;
+ }
}
return count;
@@ -2629,6 +2631,8 @@ static void _route_entry_dump_nh(const struct route_entry *re,
char nhname[PREFIX_STRLEN];
char backup_str[50];
char wgt_str[50];
+ char temp_str[10];
+ int i;
struct interface *ifp;
struct vrf *vrf = vrf_lookup_by_id(nexthop->vrf_id);
@@ -2654,8 +2658,12 @@ static void _route_entry_dump_nh(const struct route_entry *re,
backup_str[0] = '\0';
if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_HAS_BACKUP)) {
- snprintf(backup_str, sizeof(backup_str), "backup %d,",
- (int)nexthop->backup_idx);
+ snprintf(backup_str, sizeof(backup_str), "backup ");
+ for (i = 0; i < nexthop->backup_num; i++) {
+ snprintf(temp_str, sizeof(temp_str), "%d, ",
+ nexthop->backup_idx[i]);
+ strlcat(backup_str, temp_str, sizeof(backup_str));
+ }
}
wgt_str[0] = '\0';
diff --git a/zebra/zebra_rnh.c b/zebra/zebra_rnh.c
index d1a5cf2a9d..b151e90a92 100644
--- a/zebra/zebra_rnh.c
+++ b/zebra/zebra_rnh.c
@@ -1040,22 +1040,10 @@ static bool compare_valid_nexthops(struct route_entry *r1,
* backups will be in the 'fib' list.
*/
nhg1 = rib_get_fib_backup_nhg(r1);
- if (nhg1 == zebra_nhg_get_backup_nhg(r1->nhe))
- nhg1 = NULL;
-
nhg2 = rib_get_fib_backup_nhg(r2);
- if (nhg2 == zebra_nhg_get_backup_nhg(r2->nhe))
- nhg2 = NULL;
-
- if (nhg1)
- nh1 = nhg1->nexthop;
- else
- nh1 = NULL;
- if (nhg2)
- nh2 = nhg2->nexthop;
- else
- nh2 = NULL;
+ nh1 = nhg1->nexthop;
+ nh2 = nhg2->nexthop;
while (1) {
/* Find each backup list's next valid nexthop */
@@ -1180,15 +1168,15 @@ static int send_client(struct rnh *rnh, struct zserv *client,
}
nhg = rib_get_fib_backup_nhg(re);
- if (nhg == zebra_nhg_get_backup_nhg(re->nhe))
- nhg = NULL;
-
if (nhg) {
for (ALL_NEXTHOPS_PTR(nhg, nh))
if (rnh_nexthop_valid(re, nh)) {
zapi_nexthop_from_nexthop(&znh, nh);
- zapi_nexthop_encode(s, &znh,
- 0 /* flags */);
+ ret = zapi_nexthop_encode(
+ s, &znh, 0 /* flags */);
+ if (ret < 0)
+ goto failure;
+
num++;
}
}
diff --git a/zebra/zebra_routemap.c b/zebra/zebra_routemap.c
index 9b2a58fd17..8155f9acfe 100644
--- a/zebra/zebra_routemap.c
+++ b/zebra/zebra_routemap.c
@@ -351,7 +351,7 @@ static int ip_nht_rm_del(struct zebra_vrf *zvrf, const char *rmap, int rtype,
return CMD_SUCCESS;
}
-DEFPY(
+DEFPY_YANG(
match_ip_address_prefix_len, match_ip_address_prefix_len_cmd,
"match ip address prefix-len (0-32)$length",
MATCH_STR
@@ -371,7 +371,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
no_match_ip_address_prefix_len, no_match_ip_address_prefix_len_cmd,
"no match ip address prefix-len [(0-32)]",
NO_STR
@@ -388,7 +388,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
match_ipv6_address_prefix_len, match_ipv6_address_prefix_len_cmd,
"match ipv6 address prefix-len (0-128)$length",
MATCH_STR
@@ -408,7 +408,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
no_match_ipv6_address_prefix_len, no_match_ipv6_address_prefix_len_cmd,
"no match ipv6 address prefix-len [(0-128)]",
NO_STR
@@ -425,7 +425,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
match_ip_nexthop_prefix_len, match_ip_nexthop_prefix_len_cmd,
"match ip next-hop prefix-len (0-32)$length",
MATCH_STR
@@ -446,7 +446,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
no_match_ip_nexthop_prefix_len, no_match_ip_nexthop_prefix_len_cmd,
"no match ip next-hop prefix-len [(0-32)]",
NO_STR
@@ -464,7 +464,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
match_source_protocol, match_source_protocol_cmd,
"match source-protocol " FRR_REDIST_STR_ZEBRA "$proto",
MATCH_STR
@@ -482,7 +482,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
no_match_source_protocol, no_match_source_protocol_cmd,
"no match source-protocol [" FRR_REDIST_STR_ZEBRA "]",
NO_STR
@@ -497,7 +497,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
match_source_instance, match_source_instance_cmd,
"match source-instance (0-255)$instance",
MATCH_STR
@@ -515,7 +515,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
no_match_source_instance, no_match_source_instance_cmd,
"no match source-instance [(0-255)]",
NO_STR MATCH_STR
@@ -531,7 +531,7 @@ DEFPY(
/* set functions */
-DEFPY(
+DEFPY_YANG(
set_src, set_src_cmd,
"set src <A.B.C.D$addrv4|X:X::X:X$addrv6>",
SET_STR
@@ -558,7 +558,7 @@ DEFPY(
return nb_cli_apply_changes(vty, NULL);
}
-DEFPY(
+DEFPY_YANG(
no_set_src, no_set_src_cmd,
"no set src [<A.B.C.D|X:X::X:X>]",
NO_STR
@@ -605,7 +605,7 @@ DEFUN (no_zebra_route_map_timer,
return (CMD_SUCCESS);
}
-DEFPY (ip_protocol,
+DEFPY_YANG (ip_protocol,
ip_protocol_cmd,
"ip protocol " FRR_IP_PROTOCOL_MAP_STR_ZEBRA
" $proto route-map ROUTE-MAP$rmap",
@@ -639,7 +639,7 @@ DEFPY (ip_protocol,
return ret;
}
-DEFPY (no_ip_protocol,
+DEFPY_YANG (no_ip_protocol,
no_ip_protocol_cmd,
"no ip protocol " FRR_IP_PROTOCOL_MAP_STR_ZEBRA
" $proto [route-map ROUTE-MAP$rmap]",
@@ -673,7 +673,7 @@ DEFPY (no_ip_protocol,
return ret;
}
-DEFPY (show_ip_protocol,
+DEFPY_YANG (show_ip_protocol,
show_ip_protocol_cmd,
"show ip protocol [vrf <NAME$vrf_name|all$vrf_all>]",
SHOW_STR
@@ -686,7 +686,7 @@ DEFPY (show_ip_protocol,
return ret;
}
-DEFPY (ipv6_protocol,
+DEFPY_YANG (ipv6_protocol,
ipv6_protocol_cmd,
"ipv6 protocol " FRR_IP6_PROTOCOL_MAP_STR_ZEBRA
" $proto route-map ROUTE-MAP$rmap",
@@ -720,7 +720,7 @@ DEFPY (ipv6_protocol,
return ret;
}
-DEFPY (no_ipv6_protocol,
+DEFPY_YANG (no_ipv6_protocol,
no_ipv6_protocol_cmd,
"no ipv6 protocol " FRR_IP6_PROTOCOL_MAP_STR_ZEBRA
" $proto [route-map ROUTE-MAP$rmap]",
@@ -754,7 +754,7 @@ DEFPY (no_ipv6_protocol,
return ret;
}
-DEFPY (show_ipv6_protocol,
+DEFPY_YANG (show_ipv6_protocol,
show_ipv6_protocol_cmd,
"show ipv6 protocol [vrf <NAME$vrf_name|all$vrf_all>]",
SHOW_STR
@@ -767,7 +767,7 @@ DEFPY (show_ipv6_protocol,
return ret;
}
-DEFPY (ip_protocol_nht_rmap,
+DEFPY_YANG (ip_protocol_nht_rmap,
ip_protocol_nht_rmap_cmd,
"ip nht " FRR_IP_PROTOCOL_MAP_STR_ZEBRA
" $proto route-map ROUTE-MAP$rmap",
@@ -802,7 +802,7 @@ DEFPY (ip_protocol_nht_rmap,
return ret;
}
-DEFPY (no_ip_protocol_nht_rmap,
+DEFPY_YANG (no_ip_protocol_nht_rmap,
no_ip_protocol_nht_rmap_cmd,
"no ip nht " FRR_IP_PROTOCOL_MAP_STR_ZEBRA
" $proto route-map [ROUTE-MAP$rmap]",
@@ -836,7 +836,7 @@ DEFPY (no_ip_protocol_nht_rmap,
return ret;
}
-DEFPY (show_ip_protocol_nht,
+DEFPY_YANG (show_ip_protocol_nht,
show_ip_protocol_nht_cmd,
"show ip nht route-map [vrf <NAME$vrf_name|all$vrf_all>]",
SHOW_STR
@@ -850,7 +850,7 @@ DEFPY (show_ip_protocol_nht,
return ret;
}
-DEFPY (ipv6_protocol_nht_rmap,
+DEFPY_YANG (ipv6_protocol_nht_rmap,
ipv6_protocol_nht_rmap_cmd,
"ipv6 nht " FRR_IP6_PROTOCOL_MAP_STR_ZEBRA
" $proto route-map ROUTE-MAP$rmap",
@@ -884,7 +884,7 @@ DEFPY (ipv6_protocol_nht_rmap,
return ret;
}
-DEFPY (no_ipv6_protocol_nht_rmap,
+DEFPY_YANG (no_ipv6_protocol_nht_rmap,
no_ipv6_protocol_nht_rmap_cmd,
"no ipv6 nht " FRR_IP6_PROTOCOL_MAP_STR_ZEBRA
" $proto [route-map ROUTE-MAP$rmap]",
@@ -918,7 +918,7 @@ DEFPY (no_ipv6_protocol_nht_rmap,
return ret;
}
-DEFPY (show_ipv6_protocol_nht,
+DEFPY_YANG (show_ipv6_protocol_nht,
show_ipv6_protocol_nht_cmd,
"show ipv6 nht route-map [vrf <NAME$vrf_name|all$vrf_all>]",
SHOW_STR
diff --git a/zebra/zebra_router.c b/zebra/zebra_router.c
index 61fef8779f..66f2924555 100644
--- a/zebra/zebra_router.c
+++ b/zebra/zebra_router.c
@@ -133,6 +133,7 @@ struct route_table *zebra_router_get_table(struct zebra_vrf *zvrf,
info->zvrf = zvrf;
info->afi = afi;
info->safi = safi;
+ info->table_id = tableid;
route_table_set_info(zrt->table, info);
zrt->table->cleanup = zebra_rtable_node_cleanup;
diff --git a/zebra/zebra_router.h b/zebra/zebra_router.h
index 863c5fa71c..f73a8f2d59 100644
--- a/zebra/zebra_router.h
+++ b/zebra/zebra_router.h
@@ -125,6 +125,12 @@ struct zebra_router {
/* L3-VNI hash table (for EVPN). Only in default instance */
struct hash *l3vni_table;
+ /* Tables and other global info maintained for EVPN multihoming */
+ struct zebra_evpn_mh_info *mh_info;
+
+ /* EVPN MH broadcast domains indexed by the VID */
+ struct hash *evpn_vlan_table;
+
struct hash *rules_hash;
struct hash *ipset_hash;
diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c
index b18871dd2a..2ea04eee2e 100644
--- a/zebra/zebra_vty.c
+++ b/zebra/zebra_vty.c
@@ -44,6 +44,7 @@
#include "zebra/zebra_routemap.h"
#include "lib/json.h"
#include "zebra/zebra_vxlan.h"
+#include "zebra/zebra_evpn_mh.h"
#ifndef VTYSH_EXTRACT_PL
#include "zebra/zebra_vty_clippy.c"
#endif
@@ -55,6 +56,7 @@
#include "zebra/zebra_nhg.h"
#include "zebra/interface.h"
#include "northbound_cli.h"
+#include "zebra/zebra_nb.h"
extern int allow_delete;
@@ -71,6 +73,12 @@ static void vty_show_ip_route_summary(struct vty *vty,
static void vty_show_ip_route_summary_prefix(struct vty *vty,
struct route_table *table,
bool use_json);
+/* Helper api to format a nexthop in the 'detailed' output path. */
+static void show_nexthop_detail_helper(struct vty *vty,
+ const struct route_entry *re,
+ const struct nexthop *nexthop,
+ bool is_backup);
+
DEFUN (ip_multicast_mode,
ip_multicast_mode_cmd,
@@ -166,11 +174,24 @@ DEFUN (show_ip_rpf_addr,
}
static char re_status_output_char(const struct route_entry *re,
- const struct nexthop *nhop)
+ const struct nexthop *nhop,
+ bool is_fib)
{
if (CHECK_FLAG(re->status, ROUTE_ENTRY_INSTALLED)) {
- if (!CHECK_FLAG(nhop->flags, NEXTHOP_FLAG_DUPLICATE) &&
- !CHECK_FLAG(nhop->flags, NEXTHOP_FLAG_RECURSIVE))
+ bool star_p = false;
+
+ if (nhop &&
+ !CHECK_FLAG(nhop->flags, NEXTHOP_FLAG_DUPLICATE) &&
+ !CHECK_FLAG(nhop->flags, NEXTHOP_FLAG_RECURSIVE)) {
+ /* More-specific test for 'fib' output */
+ if (is_fib) {
+ star_p = !!CHECK_FLAG(nhop->flags,
+ NEXTHOP_FLAG_FIB);
+ } else
+ star_p = true;
+ }
+
+ if (star_p)
return '*';
else
return ' ';
@@ -190,19 +211,51 @@ static char re_status_output_char(const struct route_entry *re,
}
/*
- * TODO -- Show backup nexthop info
+ * Show backup nexthop info, in the 'detailed' output path
*/
static void show_nh_backup_helper(struct vty *vty,
- const struct nhg_hash_entry *nhe,
+ const struct route_entry *re,
const struct nexthop *nexthop)
{
+ const struct nexthop *start, *backup, *temp;
+ int i, idx;
+
/* Double-check that there _is_ a backup */
- if (!CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_HAS_BACKUP))
+ if (!CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_HAS_BACKUP) ||
+ re->nhe->backup_info == NULL || re->nhe->backup_info->nhe == NULL ||
+ re->nhe->backup_info->nhe->nhg.nexthop == NULL)
return;
- /* Locate the backup nexthop */
+ /* Locate the backup nexthop(s) */
+ start = re->nhe->backup_info->nhe->nhg.nexthop;
+ for (i = 0; i < nexthop->backup_num; i++) {
+ /* Format the backup(s) (indented) */
+ backup = start;
+ for (idx = 0; idx < nexthop->backup_idx[i]; idx++) {
+ backup = backup->next;
+ if (backup == NULL)
+ break;
+ }
- /* Format the backup (indented) */
+ /* It's possible for backups to be recursive too,
+ * so walk the recursive resolution list if present.
+ */
+ temp = backup;
+ while (backup) {
+ vty_out(vty, " ");
+ show_nexthop_detail_helper(vty, re, backup,
+ true /*backup*/);
+ vty_out(vty, "\n");
+
+ if (backup->resolved && temp == backup)
+ backup = backup->resolved;
+ else
+ backup = nexthop_next(backup);
+
+ if (backup == temp->next)
+ break;
+ }
+ }
}
@@ -212,14 +265,20 @@ static void show_nh_backup_helper(struct vty *vty,
*/
static void show_nexthop_detail_helper(struct vty *vty,
const struct route_entry *re,
- const struct nexthop *nexthop)
+ const struct nexthop *nexthop,
+ bool is_backup)
{
char addrstr[32];
char buf[MPLS_LABEL_STRLEN];
+ int i;
- vty_out(vty, " %c%s",
- re_status_output_char(re, nexthop),
- nexthop->rparent ? " " : "");
+ if (is_backup)
+ vty_out(vty, " b%s",
+ nexthop->rparent ? " " : "");
+ else
+ vty_out(vty, " %c%s",
+ re_status_output_char(re, nexthop, false),
+ nexthop->rparent ? " " : "");
switch (nexthop->type) {
case NEXTHOP_TYPE_IPV4:
@@ -333,6 +392,13 @@ static void show_nexthop_detail_helper(struct vty *vty,
if (nexthop->weight)
vty_out(vty, ", weight %u", nexthop->weight);
+
+ if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_HAS_BACKUP)) {
+ vty_out(vty, ", backup %d", nexthop->backup_idx[0]);
+
+ for (i = 1; i < nexthop->backup_num; i++)
+ vty_out(vty, ",%d", nexthop->backup_idx[i]);
+ }
}
/* New RIB. Detailed information for IPv4 route. */
@@ -403,12 +469,13 @@ static void vty_show_ip_route_detail(struct vty *vty, struct route_node *rn,
for (ALL_NEXTHOPS(re->nhe->nhg, nexthop)) {
/* Use helper to format each nexthop */
- show_nexthop_detail_helper(vty, re, nexthop);
+ show_nexthop_detail_helper(vty, re, nexthop,
+ false /*not backup*/);
vty_out(vty, "\n");
- /* Include backup info, if present */
+ /* Include backup(s), if present */
if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_HAS_BACKUP))
- show_nh_backup_helper(vty, re->nhe, nexthop);
+ show_nh_backup_helper(vty, re, nexthop);
}
vty_out(vty, "\n");
}
@@ -422,6 +489,7 @@ static void show_route_nexthop_helper(struct vty *vty,
const struct nexthop *nexthop)
{
char buf[MPLS_LABEL_STRLEN];
+ int i;
switch (nexthop->type) {
case NEXTHOP_TYPE_IPV4:
@@ -519,8 +587,12 @@ static void show_route_nexthop_helper(struct vty *vty,
if (nexthop->weight)
vty_out(vty, ", weight %u", nexthop->weight);
- if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_HAS_BACKUP))
- vty_out(vty, ", backup %d", nexthop->backup_idx);
+ if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_HAS_BACKUP)) {
+ vty_out(vty, ", backup %d", nexthop->backup_idx[0]);
+
+ for (i = 1; i < nexthop->backup_num; i++)
+ vty_out(vty, ",%d", nexthop->backup_idx[i]);
+ }
}
/*
@@ -534,6 +606,8 @@ static void show_nexthop_json_helper(json_object *json_nexthop,
char buf[SRCDEST2STR_BUFFER];
struct vrf *vrf = NULL;
json_object *json_labels = NULL;
+ json_object *json_backups = NULL;
+ int i;
json_object_int_add(json_nexthop, "flags",
nexthop->flags);
@@ -645,9 +719,17 @@ static void show_nexthop_json_helper(json_object *json_nexthop,
json_object_boolean_true_add(json_nexthop,
"recursive");
- if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_HAS_BACKUP))
- json_object_int_add(json_nexthop, "backupIndex",
- nexthop->backup_idx);
+ if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_HAS_BACKUP)) {
+ json_backups = json_object_new_array();
+ for (i = 0; i < nexthop->backup_num; i++) {
+ json_object_array_add(
+ json_backups,
+ json_object_new_int(nexthop->backup_idx[i]));
+ }
+
+ json_object_object_add(json_nexthop, "backupIndex",
+ json_backups);
+ }
switch (nexthop->type) {
case NEXTHOP_TYPE_IPV4:
@@ -705,18 +787,19 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn,
struct route_entry *re, json_object *json,
bool is_fib)
{
- struct nexthop *nexthop;
+ const struct nexthop *nexthop;
int len = 0;
char buf[SRCDEST2STR_BUFFER];
json_object *json_nexthops = NULL;
json_object *json_nexthop = NULL;
json_object *json_route = NULL;
time_t uptime;
- struct vrf *vrf = NULL;
- rib_dest_t *dest = rib_dest_from_rnode(rn);
- struct nexthop_group *nhg;
+ const struct vrf *vrf = NULL;
+ const rib_dest_t *dest = rib_dest_from_rnode(rn);
+ const struct nexthop_group *nhg;
char up_str[MONOTIME_STRLEN];
- bool first_p;
+ bool first_p = true;
+ bool nhg_from_backup = false;
uptime = monotime(NULL);
uptime -= re->uptime;
@@ -791,9 +874,11 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn,
for (ALL_NEXTHOPS_PTR(nhg, nexthop)) {
json_nexthop = json_object_new_object();
+ show_nexthop_json_helper(json_nexthop,
+ nexthop, re);
- show_nexthop_json_helper(json_nexthop, nexthop, re);
- json_object_array_add(json_nexthops, json_nexthop);
+ json_object_array_add(json_nexthops,
+ json_nexthop);
}
json_object_object_add(json_route, "nexthops", json_nexthops);
@@ -804,7 +889,7 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn,
else
nhg = zebra_nhg_get_backup_nhg(re->nhe);
- if (nhg) {
+ if (nhg && nhg->nexthop) {
json_nexthops = json_object_new_array();
for (ALL_NEXTHOPS_PTR(nhg, nexthop)) {
@@ -824,42 +909,62 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn,
return;
}
+ /* Prefix information, and first nexthop. If we're showing 'fib',
+ * and there are no installed primary nexthops, see if there are any
+ * backup nexthops and start with those.
+ */
+ if (is_fib && nhg->nexthop == NULL) {
+ nhg = rib_get_fib_backup_nhg(re);
+ nhg_from_backup = true;
+ }
+
+ len = vty_out(vty, "%c", zebra_route_char(re->type));
+ if (re->instance)
+ len += vty_out(vty, "[%d]", re->instance);
+ if (nhg_from_backup && nhg->nexthop) {
+ len += vty_out(
+ vty, "%cb%c %s",
+ CHECK_FLAG(re->flags, ZEBRA_FLAG_SELECTED) ? '>' : ' ',
+ re_status_output_char(re, nhg->nexthop, is_fib),
+ srcdest_rnode2str(rn, buf, sizeof(buf)));
+ } else {
+ len += vty_out(
+ vty, "%c%c %s",
+ CHECK_FLAG(re->flags, ZEBRA_FLAG_SELECTED) ? '>' : ' ',
+ re_status_output_char(re, nhg->nexthop, is_fib),
+ srcdest_rnode2str(rn, buf, sizeof(buf)));
+ }
+
+ /* Distance and metric display. */
+ if (((re->type == ZEBRA_ROUTE_CONNECT) &&
+ (re->distance || re->metric)) ||
+ (re->type != ZEBRA_ROUTE_CONNECT))
+ len += vty_out(vty, " [%u/%u]", re->distance,
+ re->metric);
+
/* Nexthop information. */
- first_p = true;
for (ALL_NEXTHOPS_PTR(nhg, nexthop)) {
if (first_p) {
first_p = false;
-
- /* Prefix information. */
- len = vty_out(vty, "%c", zebra_route_char(re->type));
- if (re->instance)
- len += vty_out(vty, "[%d]", re->instance);
- len += vty_out(
- vty, "%c%c %s",
- CHECK_FLAG(re->flags, ZEBRA_FLAG_SELECTED)
- ? '>'
- : ' ',
- re_status_output_char(re, nexthop),
- srcdest_rnode2str(rn, buf, sizeof(buf)));
-
- /* Distance and metric display. */
- if (((re->type == ZEBRA_ROUTE_CONNECT) &&
- (re->distance || re->metric)) ||
- (re->type != ZEBRA_ROUTE_CONNECT))
- len += vty_out(vty, " [%u/%u]", re->distance,
- re->metric);
+ } else if (nhg_from_backup) {
+ vty_out(vty, " b%c%*c",
+ re_status_output_char(re, nexthop, is_fib),
+ len - 3 + (2 * nexthop_level(nexthop)), ' ');
} else {
vty_out(vty, " %c%*c",
- re_status_output_char(re, nexthop),
+ re_status_output_char(re, nexthop, is_fib),
len - 3 + (2 * nexthop_level(nexthop)), ' ');
}
show_route_nexthop_helper(vty, re, nexthop);
-
vty_out(vty, ", %s\n", up_str);
}
- /* Check for backup info if present */
+ /* If we only had backup nexthops, we're done */
+ if (nhg_from_backup)
+ return;
+
+ /* Check for backup nexthop info if present */
if (is_fib)
nhg = rib_get_fib_backup_nhg(re);
else
@@ -1206,7 +1311,7 @@ static void show_nexthop_group_out(struct vty *vty, struct nhg_hash_entry *nhe)
if (CHECK_FLAG(nexthop->flags,
NEXTHOP_FLAG_HAS_BACKUP))
vty_out(vty, " [backup %d]",
- nexthop->backup_idx);
+ nexthop->backup_idx[0]);
vty_out(vty, "\n");
continue;
@@ -1214,22 +1319,13 @@ static void show_nexthop_group_out(struct vty *vty, struct nhg_hash_entry *nhe)
/* TODO -- print more useful backup info */
if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_HAS_BACKUP)) {
- struct nexthop *backup;
int i;
- i = 0;
- for (ALL_NEXTHOPS(nhe->backup_info->nhe->nhg, backup)) {
- if (i == nexthop->backup_idx)
- break;
- i++;
- }
+ vty_out(vty, "[backup");
+ for (i = 0; i < nexthop->backup_num; i++)
+ vty_out(vty, " %d", nexthop->backup_idx[i]);
- /* TODO */
- if (backup)
- vty_out(vty, " [backup %d]",
- nexthop->backup_idx);
- else
- vty_out(vty, " [backup INVALID]");
+ vty_out(vty, "]");
}
vty_out(vty, "\n");
@@ -2304,12 +2400,9 @@ DEFUN (vrf_vni_mapping,
"VNI-ID\n"
"prefix-routes-only\n")
{
- int ret = 0;
int filter = 0;
ZEBRA_DECLVAR_CONTEXT(vrf, zvrf);
- vni_t vni = strtoul(argv[1]->arg, NULL, 10);
- char err[ERR_STR_SZ];
assert(vrf);
assert(zvrf);
@@ -2317,14 +2410,15 @@ DEFUN (vrf_vni_mapping,
if (argc == 3)
filter = 1;
- /* Mark as having FRR configuration */
- vrf_set_user_cfged(vrf);
- ret = zebra_vxlan_process_vrf_vni_cmd(zvrf, vni, err, ERR_STR_SZ,
- filter, 1);
- if (ret != 0) {
- vty_out(vty, "%s\n", err);
- return CMD_WARNING;
- }
+ nb_cli_enqueue_change(vty, "./frr-zebra:zebra", NB_OP_CREATE, NULL);
+ nb_cli_enqueue_change(vty, "./frr-zebra:zebra/l3vni-id", NB_OP_MODIFY,
+ argv[1]->arg);
+
+ if (filter)
+ nb_cli_enqueue_change(vty, "./frr-zebra:zebra/prefix-only",
+ NB_OP_MODIFY, "true");
+
+ nb_cli_apply_changes(vty, NULL);
return CMD_SUCCESS;
}
@@ -2337,12 +2431,10 @@ DEFUN (no_vrf_vni_mapping,
"VNI-ID\n"
"prefix-routes-only\n")
{
- int ret = 0;
int filter = 0;
- char err[ERR_STR_SZ];
- vni_t vni = strtoul(argv[2]->arg, NULL, 10);
ZEBRA_DECLVAR_CONTEXT(vrf, zvrf);
+ vni_t vni = strtoul(argv[1]->arg, NULL, 10);
assert(vrf);
assert(zvrf);
@@ -2350,16 +2442,22 @@ DEFUN (no_vrf_vni_mapping,
if (argc == 4)
filter = 1;
- ret = zebra_vxlan_process_vrf_vni_cmd(zvrf, vni, err,
- ERR_STR_SZ, filter, 0);
- if (ret != 0) {
- vty_out(vty, "%s\n", err);
+ if (zvrf->l3vni != vni) {
+ vty_out(vty, "VNI %d doesn't exist in VRF: %s \n", vni,
+ zvrf->vrf->name);
return CMD_WARNING;
}
- /* If no other FRR config for this VRF, mark accordingly. */
- if (!zebra_vrf_has_config(zvrf))
- vrf_reset_user_cfged(vrf);
+ nb_cli_enqueue_change(vty, "./frr-zebra:zebra/l3vni-id", NB_OP_DESTROY,
+ argv[2]->arg);
+
+ if (filter)
+ nb_cli_enqueue_change(vty, "./frr-zebra:zebra/prefix-only",
+ NB_OP_DESTROY, "true");
+
+ nb_cli_enqueue_change(vty, "./frr-zebra:zebra", NB_OP_DESTROY, NULL);
+
+ nb_cli_apply_changes(vty, NULL);
return CMD_SUCCESS;
}
@@ -2419,6 +2517,81 @@ DEFUN (show_evpn_global,
return CMD_SUCCESS;
}
+DEFPY(show_evpn_es,
+ show_evpn_es_cmd,
+ "show evpn es [NAME$esi_str] [json$json] [detail$detail]",
+ SHOW_STR
+ "EVPN\n"
+ "Ethernet Segment\n"
+ "ES ID\n"
+ JSON_STR
+ "Detailed information\n")
+{
+ esi_t esi;
+ bool uj = !!json;
+
+ if (esi_str) {
+ if (!str_to_esi(esi_str, &esi)) {
+ vty_out(vty, "%% Malformed ESI\n");
+ return CMD_WARNING;
+ }
+ zebra_evpn_es_show_esi(vty, uj, &esi);
+ } else {
+ if (detail)
+ zebra_evpn_es_show_detail(vty, uj);
+ else
+ zebra_evpn_es_show(vty, uj);
+ }
+
+ return CMD_SUCCESS;
+}
+
+DEFPY(show_evpn_es_evi,
+ show_evpn_es_evi_cmd,
+ "show evpn es-evi [vni (1-16777215)$vni] [json$json] [detail$detail]",
+ SHOW_STR
+ "EVPN\n"
+ "Ethernet Segment per EVI\n"
+ "VxLAN Network Identifier\n"
+ "VNI\n"
+ JSON_STR
+ "Detailed information\n")
+{
+ bool uj = !!json;
+ bool ud = !!detail;
+
+ if (vni)
+ zebra_evpn_es_evi_show_vni(vty, uj, vni, ud);
+ else
+ zebra_evpn_es_evi_show(vty, uj, ud);
+
+ return CMD_SUCCESS;
+}
+
+DEFPY(show_evpn_access_vlan,
+ show_evpn_access_vlan_cmd,
+ "show evpn access-vlan [(1-4094)$vid] [json$json] [detail$detail]",
+ SHOW_STR
+ "EVPN\n"
+ "Access VLANs\n"
+ "VLAN ID\n"
+ JSON_STR
+ "Detailed information\n")
+{
+ bool uj = !!json;
+
+ if (vid) {
+ zebra_evpn_acc_vl_show_vid(vty, uj, vid);
+ } else {
+ if (detail)
+ zebra_evpn_acc_vl_show_detail(vty, uj);
+ else
+ zebra_evpn_acc_vl_show(vty, uj);
+ }
+
+ return CMD_SUCCESS;
+}
+
DEFUN (show_evpn_vni,
show_evpn_vni_cmd,
"show evpn vni [json]",
@@ -3637,6 +3810,9 @@ void zebra_vty_init(void)
install_element(VIEW_NODE, &show_evpn_vni_cmd);
install_element(VIEW_NODE, &show_evpn_vni_detail_cmd);
install_element(VIEW_NODE, &show_evpn_vni_vni_cmd);
+ install_element(VIEW_NODE, &show_evpn_es_cmd);
+ install_element(VIEW_NODE, &show_evpn_es_evi_cmd);
+ install_element(VIEW_NODE, &show_evpn_access_vlan_cmd);
install_element(VIEW_NODE, &show_evpn_rmac_vni_mac_cmd);
install_element(VIEW_NODE, &show_evpn_rmac_vni_cmd);
install_element(VIEW_NODE, &show_evpn_rmac_vni_all_cmd);
diff --git a/zebra/zebra_vxlan.c b/zebra/zebra_vxlan.c
index 66441e1756..ff09b48dcf 100644
--- a/zebra/zebra_vxlan.c
+++ b/zebra/zebra_vxlan.c
@@ -50,6 +50,7 @@
#include "zebra/zebra_vrf.h"
#include "zebra/zebra_vxlan.h"
#include "zebra/zebra_vxlan_private.h"
+#include "zebra/zebra_evpn_mh.h"
#include "zebra/zebra_router.h"
DEFINE_MTYPE_STATIC(ZEBRA, HOST_PREFIX, "host prefix");
@@ -74,7 +75,6 @@ static const struct message zvtep_flood_str[] = {
{0}
};
-
/* static function declarations */
static int ip_prefix_send_to_client(vrf_id_t vrf_id, struct prefix *p,
uint16_t cmd);
@@ -95,22 +95,26 @@ static void zvni_print_hash(struct hash_bucket *bucket, void *ctxt[]);
static int zvni_macip_send_msg_to_client(vni_t vni, struct ethaddr *macaddr,
struct ipaddr *ip, uint8_t flags,
- uint32_t seq, int state, uint16_t cmd);
+ uint32_t seq, int state,
+ struct zebra_evpn_es *es,
+ uint16_t cmd);
static unsigned int neigh_hash_keymake(const void *p);
static void *zvni_neigh_alloc(void *p);
static zebra_neigh_t *zvni_neigh_add(zebra_vni_t *zvni, struct ipaddr *ip,
- struct ethaddr *mac);
+ struct ethaddr *mac, zebra_mac_t *zmac,
+ uint32_t n_flags);
static int zvni_neigh_del(zebra_vni_t *zvni, zebra_neigh_t *n);
static void zvni_neigh_del_all(zebra_vni_t *zvni, int uninstall, int upd_client,
uint32_t flags);
static zebra_neigh_t *zvni_neigh_lookup(zebra_vni_t *zvni, struct ipaddr *ip);
static int zvni_neigh_send_add_to_client(vni_t vni, struct ipaddr *ip,
- struct ethaddr *macaddr,
- uint8_t flags, uint32_t seq);
+ struct ethaddr *mac, zebra_mac_t *zmac,
+ uint32_t flags, uint32_t seq);
static int zvni_neigh_send_del_to_client(vni_t vni, struct ipaddr *ip,
- struct ethaddr *macaddr,
- uint8_t flags, int state);
-static int zvni_neigh_install(zebra_vni_t *zvni, zebra_neigh_t *n);
+ struct ethaddr *mac,
+ uint32_t flags, int state, bool force);
+static int zvni_rem_neigh_install(zebra_vni_t *zvni,
+ zebra_neigh_t *n, bool was_static);
static int zvni_neigh_uninstall(zebra_vni_t *zvni, zebra_neigh_t *n);
static int zvni_neigh_probe(zebra_vni_t *zvni, zebra_neigh_t *n);
static zebra_vni_t *zvni_from_svi(struct interface *ifp,
@@ -142,7 +146,6 @@ static int zl3vni_rmac_install(zebra_l3vni_t *zl3vni, zebra_mac_t *zrmac);
static int zl3vni_rmac_uninstall(zebra_l3vni_t *zl3vni, zebra_mac_t *zrmac);
/* l3-vni related APIs*/
-static zebra_l3vni_t *zl3vni_lookup(vni_t vni);
static void *zl3vni_alloc(void *p);
static zebra_l3vni_t *zl3vni_add(vni_t vni, vrf_id_t vrf_id);
static int zl3vni_del(zebra_l3vni_t *zl3vni);
@@ -158,21 +161,22 @@ static void zvni_mac_del_all(zebra_vni_t *zvni, int uninstall, int upd_client,
uint32_t flags);
static zebra_mac_t *zvni_mac_lookup(zebra_vni_t *zvni, struct ethaddr *macaddr);
static int zvni_mac_send_add_to_client(vni_t vni, struct ethaddr *macaddr,
- uint8_t flags, uint32_t seq);
-static int zvni_mac_send_del_to_client(vni_t vni, struct ethaddr *macaddr);
+ uint32_t flags, uint32_t seq, struct zebra_evpn_es *es);
+static int zvni_mac_send_del_to_client(vni_t vni, struct ethaddr *macaddr,
+ uint32_t flags, bool force);
static zebra_vni_t *zvni_map_vlan(struct interface *ifp,
struct interface *br_if, vlanid_t vid);
-static int zvni_mac_install(zebra_vni_t *zvni, zebra_mac_t *mac);
-static int zvni_mac_uninstall(zebra_vni_t *zvni, zebra_mac_t *mac);
+static int zvni_rem_mac_install(zebra_vni_t *zvni,
+ zebra_mac_t *mac, bool was_static);
+static int zvni_rem_mac_uninstall(zebra_vni_t *zvni, zebra_mac_t *mac);
static void zvni_install_mac_hash(struct hash_bucket *bucket, void *ctxt);
static unsigned int vni_hash_keymake(const void *p);
static void *zvni_alloc(void *p);
-static zebra_vni_t *zvni_lookup(vni_t vni);
static zebra_vni_t *zvni_add(vni_t vni);
static int zvni_del(zebra_vni_t *zvni);
static int zvni_send_add_to_client(zebra_vni_t *zvni);
-static int zvni_send_del_to_client(vni_t vni);
+static int zvni_send_del_to_client(zebra_vni_t *zvni);
static void zvni_build_hash_table(void);
static int zvni_vtep_match(struct in_addr *vtep_ip, zebra_vtep_t *zvtep);
static zebra_vtep_t *zvni_vtep_find(zebra_vni_t *zvni, struct in_addr *vtep_ip);
@@ -225,6 +229,22 @@ static void zebra_vxlan_sg_cleanup(struct hash_bucket *bucket, void *arg);
static void zvni_send_mac_to_client(zebra_vni_t *zvn);
static void zvni_send_neigh_to_client(zebra_vni_t *zvni);
+static void zebra_vxlan_rem_mac_del(zebra_vni_t *zvni,
+ zebra_mac_t *zmac);
+static inline void zebra_vxlan_mac_stop_hold_timer(zebra_mac_t *mac);
+static inline bool zebra_vxlan_mac_is_static(zebra_mac_t *mac);
+static void zebra_vxlan_local_neigh_ref_mac(zebra_neigh_t *n,
+ struct ethaddr *macaddr, zebra_mac_t *mac,
+ bool send_mac_update);
+static void zebra_vxlan_local_neigh_deref_mac(zebra_neigh_t *n,
+ bool send_mac_update);
+static inline bool zebra_vxlan_neigh_is_ready_for_bgp(zebra_neigh_t *n);
+static inline bool zebra_vxlan_neigh_clear_sync_info(zebra_neigh_t *n);
+static void zebra_vxlan_sync_neigh_dp_install(zebra_neigh_t *n,
+ bool set_inactive, bool force_clear_static, const char *caller);
+static inline bool zebra_vxlan_neigh_is_static(zebra_neigh_t *neigh);
+static void zebra_vxlan_neigh_send_add_del_to_client(zebra_neigh_t *n,
+ bool old_bgp_ready, bool new_bgp_ready);
/* Private functions */
static int host_rb_entry_compare(const struct host_rb_entry *hle1,
@@ -731,6 +751,7 @@ static void zvni_print_neigh(zebra_neigh_t *n, void *ctxt, json_object *json)
struct zebra_vrf *zvrf = NULL;
struct timeval detect_start_time = {0, 0};
char timebuf[MONOTIME_STRLEN];
+ char thread_buf[THREAD_TIMER_STRLEN];
zvrf = zebra_vrf_get_evpn();
if (!zvrf)
@@ -743,25 +764,75 @@ static void zvni_print_neigh(zebra_neigh_t *n, void *ctxt, json_object *json)
state_str = IS_ZEBRA_NEIGH_ACTIVE(n) ? "active" : "inactive";
vty = (struct vty *)ctxt;
if (json == NULL) {
+ bool sync_info = false;
+
vty_out(vty, "IP: %s\n",
- ipaddr2str(&n->ip, buf2, sizeof(buf2)));
+ ipaddr2str(&n->ip, buf2, sizeof(buf2)));
vty_out(vty, " Type: %s\n", type_str);
vty_out(vty, " State: %s\n", state_str);
vty_out(vty, " MAC: %s\n",
- prefix_mac2str(&n->emac, buf1, sizeof(buf1)));
+ prefix_mac2str(&n->emac, buf1, sizeof(buf1)));
+ vty_out(vty, " Sync-info:");
+ if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL_INACTIVE)) {
+ vty_out(vty, " local-inactive");
+ sync_info = true;
+ }
+ if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_PROXY)) {
+ vty_out(vty, " peer-proxy");
+ sync_info = true;
+ }
+ if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_ACTIVE)) {
+ vty_out(vty, " peer-active");
+ sync_info = true;
+ }
+ if (n->hold_timer) {
+ vty_out(vty, " (ht: %s)",
+ thread_timer_to_hhmmss(
+ thread_buf,
+ sizeof(thread_buf),
+ n->hold_timer));
+ sync_info = true;
+ }
+ if (!sync_info)
+ vty_out(vty, " -");
+ vty_out(vty, "\n");
} else {
json_object_string_add(json, "ip", buf2);
json_object_string_add(json, "type", type_str);
json_object_string_add(json, "state", state_str);
json_object_string_add(json, "mac", buf1);
+ if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL_INACTIVE))
+ json_object_boolean_true_add(json,
+ "localInactive");
+ if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_PROXY))
+ json_object_boolean_true_add(json,
+ "peerProxy");
+ if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_ACTIVE))
+ json_object_boolean_true_add(json,
+ "peerActive");
+ if (n->hold_timer)
+ json_object_string_add(json, "peerActiveHold",
+ thread_timer_to_hhmmss(
+ thread_buf,
+ sizeof(thread_buf),
+ n->hold_timer));
}
if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE)) {
- if (json == NULL) {
- vty_out(vty, " Remote VTEP: %s\n",
- inet_ntoa(n->r_vtep_ip));
- } else
- json_object_string_add(json, "remoteVtep",
- inet_ntoa(n->r_vtep_ip));
+ if (n->mac->es) {
+ if (json)
+ json_object_string_add(json, "remoteEs",
+ n->mac->es->esi_str);
+ else
+ vty_out(vty, " Remote ES: %s\n",
+ n->mac->es->esi_str);
+ } else {
+ if (json)
+ json_object_string_add(json, "remoteVtep",
+ inet_ntoa(n->r_vtep_ip));
+ else
+ vty_out(vty, " Remote VTEP: %s\n",
+ inet_ntoa(n->r_vtep_ip));
+ }
}
if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_DEF_GW)) {
if (!json) {
@@ -812,6 +883,30 @@ static void zvni_print_neigh(zebra_neigh_t *n, void *ctxt, json_object *json)
}
}
+static void zvni_print_neigh_hdr(struct vty *vty,
+ struct neigh_walk_ctx *wctx)
+{
+ vty_out(vty,
+ "Flags: I=local-inactive, P=peer-active, X=peer-proxy\n");
+ vty_out(vty, "%*s %-6s %-5s %-8s %-17s %-30s %s\n",
+ -wctx->addr_width, "Neighbor", "Type", "Flags",
+ "State", "MAC", "Remote ES/VTEP", "Seq #'s");
+}
+
+static char *zvni_print_neigh_flags(zebra_neigh_t *n, char *flags_buf,
+ uint32_t flags_buf_sz)
+{
+ snprintf(flags_buf, flags_buf_sz, "%s%s%s",
+ (n->flags & ZEBRA_NEIGH_ES_PEER_ACTIVE) ?
+ "P" : "",
+ (n->flags & ZEBRA_NEIGH_ES_PEER_PROXY) ?
+ "X" : "",
+ (n->flags & ZEBRA_NEIGH_LOCAL_INACTIVE) ?
+ "I" : "");
+
+ return flags_buf;
+}
+
/*
* Print neighbor hash entry - called for display of all neighbors.
*/
@@ -824,6 +919,7 @@ static void zvni_print_neigh_hash(struct hash_bucket *bucket, void *ctxt)
char buf2[INET6_ADDRSTRLEN];
struct neigh_walk_ctx *wctx = ctxt;
const char *state_str;
+ char flags_buf[6];
vty = wctx->vty;
json_vni = wctx->json;
@@ -840,9 +936,11 @@ static void zvni_print_neigh_hash(struct hash_bucket *bucket, void *ctxt)
return;
if (json_vni == NULL) {
- vty_out(vty, "%*s %-6s %-8s %-17s %u/%u\n",
+ vty_out(vty, "%*s %-6s %-5s %-8s %-17s %-30s %u/%u\n",
-wctx->addr_width, buf2, "local",
- state_str, buf1, n->loc_seq, n->rem_seq);
+ zvni_print_neigh_flags(n, flags_buf,
+ sizeof(flags_buf)), state_str,
+ buf1, "", n->loc_seq, n->rem_seq);
} else {
json_object_string_add(json_row, "type", "local");
json_object_string_add(json_row, "state", state_str);
@@ -872,19 +970,25 @@ static void zvni_print_neigh_hash(struct hash_bucket *bucket, void *ctxt)
if (json_vni == NULL) {
if ((wctx->flags & SHOW_REMOTE_NEIGH_FROM_VTEP) &&
(wctx->count == 0))
- vty_out(vty, "%*s %-6s %-8s %-17s %-21s %s\n",
- -wctx->addr_width, "Neighbor", "Type",
- "State", "MAC", "Remote VTEP",
- "Seq #'s");
- vty_out(vty, "%*s %-6s %-8s %-17s %-21s %u/%u\n",
- -wctx->addr_width, buf2, "remote", state_str,
- buf1, inet_ntoa(n->r_vtep_ip), n->loc_seq, n->rem_seq);
+ zvni_print_neigh_hdr(vty, wctx);
+ vty_out(vty, "%*s %-6s %-5s %-8s %-17s %-30s %u/%u\n",
+ -wctx->addr_width, buf2, "remote",
+ zvni_print_neigh_flags(n, flags_buf,
+ sizeof(flags_buf)),
+ state_str, buf1,
+ n->mac->es ? n->mac->es->esi_str :
+ inet_ntoa(n->r_vtep_ip),
+ n->loc_seq, n->rem_seq);
} else {
json_object_string_add(json_row, "type", "remote");
json_object_string_add(json_row, "state", state_str);
json_object_string_add(json_row, "mac", buf1);
- json_object_string_add(json_row, "remoteVtep",
- inet_ntoa(n->r_vtep_ip));
+ if (n->mac->es)
+ json_object_string_add(json_row, "remoteEs",
+ n->mac->es->esi_str);
+ else
+ json_object_string_add(json_row, "remoteVtep",
+ inet_ntoa(n->r_vtep_ip));
if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_DEF_GW))
json_object_boolean_true_add(json_row,
"defaultGateway");
@@ -987,11 +1091,9 @@ static void zvni_print_neigh_hash_all_vni(struct hash_bucket *bucket,
wctx.json = json_vni;
hash_iterate(zvni->neigh_table, zvni_find_neigh_addr_width, &wctx);
- if (json == NULL) {
- vty_out(vty, "%*s %-6s %-8s %-17s %-21s %s\n",
- -wctx.addr_width, "IP", "Type",
- "State", "MAC", "Remote VTEP", "Seq #'s");
- }
+ if (json == NULL)
+ zvni_print_neigh_hdr(vty, &wctx);
+
if (print_dup)
hash_iterate(zvni->neigh_table, zvni_print_dad_neigh_hash,
&wctx);
@@ -1164,6 +1266,35 @@ static void zl3vni_print_rmac(zebra_mac_t *zrmac, struct vty *vty,
}
}
+static void
+zebra_vxlan_mac_get_access_info(zebra_mac_t *mac,
+ struct interface **ifpP, vlanid_t *vid)
+{
+ /* if the mac is associated with an ES we must get the access
+ * info from the ES
+ */
+ if (mac->es) {
+ struct zebra_if *zif;
+
+ /* get the access port from the es */
+ *ifpP = mac->es->zif ? mac->es->zif->ifp : NULL;
+ /* get the vlan from the VNI */
+ if (mac->zvni->vxlan_if) {
+ zif = mac->zvni->vxlan_if->info;
+ *vid = zif->l2info.vxl.access_vlan;
+ } else {
+ *vid = 0;
+ }
+ } else {
+ struct zebra_ns *zns;
+
+ *vid = mac->fwd_info.local.vid;
+ zns = zebra_ns_lookup(NS_DEFAULT);
+ *ifpP = if_lookup_by_index_per_ns(zns,
+ mac->fwd_info.local.ifindex);
+ }
+}
+
/*
* Print a specific MAC entry.
*/
@@ -1177,6 +1308,7 @@ static void zvni_print_mac(zebra_mac_t *mac, void *ctxt, json_object *json)
struct zebra_vrf *zvrf;
struct timeval detect_start_time = {0, 0};
char timebuf[MONOTIME_STRLEN];
+ char thread_buf[THREAD_TIMER_STRLEN];
zvrf = zebra_vrf_get_evpn();
if (!zvrf)
@@ -1189,21 +1321,21 @@ static void zvni_print_mac(zebra_mac_t *mac, void *ctxt, json_object *json)
json_object *json_mac = json_object_new_object();
if (CHECK_FLAG(mac->flags, ZEBRA_MAC_LOCAL)) {
- struct zebra_ns *zns;
struct interface *ifp;
- ifindex_t ifindex;
+ vlanid_t vid;
- ifindex = mac->fwd_info.local.ifindex;
- zns = zebra_ns_lookup(mac->fwd_info.local.ns_id);
- ifp = if_lookup_by_index_per_ns(zns, ifindex);
- if (!ifp)
- return;
+ zebra_vxlan_mac_get_access_info(mac,
+ &ifp, &vid);
json_object_string_add(json_mac, "type", "local");
- json_object_string_add(json_mac, "intf", ifp->name);
- json_object_int_add(json_mac, "ifindex", ifindex);
- if (mac->fwd_info.local.vid)
+ if (ifp) {
+ json_object_string_add(json_mac,
+ "intf", ifp->name);
+ json_object_int_add(json_mac,
+ "ifindex", ifp->ifindex);
+ }
+ if (vid)
json_object_int_add(json_mac, "vlan",
- mac->fwd_info.local.vid);
+ vid);
} else if (CHECK_FLAG(mac->flags, ZEBRA_MAC_REMOTE)) {
json_object_string_add(json_mac, "type", "remote");
json_object_string_add(
@@ -1232,6 +1364,25 @@ static void zvni_print_mac(zebra_mac_t *mac, void *ctxt, json_object *json)
else
json_object_boolean_false_add(json_mac, "isDuplicate");
+ json_object_int_add(json_mac, "syncNeighCount", mac->sync_neigh_cnt);
+ if (CHECK_FLAG(mac->flags, ZEBRA_MAC_LOCAL_INACTIVE))
+ json_object_boolean_true_add(json_mac,
+ "localInactive");
+ if (CHECK_FLAG(mac->flags, ZEBRA_MAC_ES_PEER_PROXY))
+ json_object_boolean_true_add(json_mac,
+ "peerProxy");
+ if (CHECK_FLAG(mac->flags, ZEBRA_MAC_ES_PEER_ACTIVE))
+ json_object_boolean_true_add(json_mac,
+ "peerActive");
+ if (mac->hold_timer)
+ json_object_string_add(json_mac, "peerActiveHold",
+ thread_timer_to_hhmmss(
+ thread_buf,
+ sizeof(thread_buf),
+ mac->hold_timer));
+ if (mac->es)
+ json_object_string_add(json_mac, "esi",
+ mac->es->esi_str);
/* print all the associated neigh */
if (!listcount(mac->neigh_list))
json_object_string_add(json_mac, "neighbors", "none");
@@ -1271,22 +1422,28 @@ static void zvni_print_mac(zebra_mac_t *mac, void *ctxt, json_object *json)
vty_out(vty, "MAC: %s\n", buf1);
if (CHECK_FLAG(mac->flags, ZEBRA_MAC_LOCAL)) {
- struct zebra_ns *zns;
struct interface *ifp;
- ifindex_t ifindex;
+ vlanid_t vid;
- ifindex = mac->fwd_info.local.ifindex;
- zns = zebra_ns_lookup(mac->fwd_info.local.ns_id);
- ifp = if_lookup_by_index_per_ns(zns, ifindex);
- if (!ifp)
- return;
- vty_out(vty, " Intf: %s(%u)", ifp->name, ifindex);
- if (mac->fwd_info.local.vid)
- vty_out(vty, " VLAN: %u",
- mac->fwd_info.local.vid);
+ zebra_vxlan_mac_get_access_info(mac,
+ &ifp, &vid);
+
+ if (mac->es)
+ vty_out(vty, " ESI: %s\n", mac->es->esi_str);
+
+ if (ifp)
+ vty_out(vty, " Intf: %s(%u)",
+ ifp->name, ifp->ifindex);
+ else
+ vty_out(vty, " Intf: -");
+ vty_out(vty, " VLAN: %u", vid);
} else if (CHECK_FLAG(mac->flags, ZEBRA_MAC_REMOTE)) {
- vty_out(vty, " Remote VTEP: %s",
- inet_ntoa(mac->fwd_info.r_vtep_ip));
+ if (mac->es)
+ vty_out(vty, " Remote ES: %s",
+ mac->es->esi_str);
+ else
+ vty_out(vty, " Remote VTEP: %s",
+ inet_ntoa(mac->fwd_info.r_vtep_ip));
} else if (CHECK_FLAG(mac->flags, ZEBRA_MAC_AUTO)) {
vty_out(vty, " Auto Mac ");
}
@@ -1301,8 +1458,22 @@ static void zvni_print_mac(zebra_mac_t *mac, void *ctxt, json_object *json)
vty_out(vty, " Remote-gateway Mac ");
vty_out(vty, "\n");
- vty_out(vty, " Local Seq: %u Remote Seq: %u", mac->loc_seq,
- mac->rem_seq);
+ vty_out(vty, " Sync-info: neigh#: %u", mac->sync_neigh_cnt);
+ if (CHECK_FLAG(mac->flags, ZEBRA_MAC_LOCAL_INACTIVE))
+ vty_out(vty, " local-inactive");
+ if (CHECK_FLAG(mac->flags, ZEBRA_MAC_ES_PEER_PROXY))
+ vty_out(vty, " peer-proxy");
+ if (CHECK_FLAG(mac->flags, ZEBRA_MAC_ES_PEER_ACTIVE))
+ vty_out(vty, " peer-active");
+ if (mac->hold_timer)
+ vty_out(vty, " (ht: %s)",
+ thread_timer_to_hhmmss(
+ thread_buf,
+ sizeof(thread_buf),
+ mac->hold_timer));
+ vty_out(vty, "\n");
+ vty_out(vty, " Local Seq: %u Remote Seq: %u",
+ mac->loc_seq, mac->rem_seq);
vty_out(vty, "\n");
if (CHECK_FLAG(mac->flags, ZEBRA_MAC_DUPLICATE)) {
@@ -1339,6 +1510,22 @@ static void zvni_print_mac(zebra_mac_t *mac, void *ctxt, json_object *json)
}
}
+static char *zvni_print_mac_flags(zebra_mac_t *mac, char *flags_buf,
+ uint32_t flags_buf_sz)
+{
+ snprintf(flags_buf, flags_buf_sz, "%s%s%s%s",
+ mac->sync_neigh_cnt ?
+ "N" : "",
+ (mac->flags & ZEBRA_MAC_ES_PEER_ACTIVE) ?
+ "P" : "",
+ (mac->flags & ZEBRA_MAC_ES_PEER_PROXY) ?
+ "X" : "",
+ (mac->flags & ZEBRA_MAC_LOCAL_INACTIVE) ?
+ "I" : "");
+
+ return flags_buf;
+}
+
/*
* Print MAC hash entry - called for display of all MACs.
*/
@@ -1349,6 +1536,7 @@ static void zvni_print_mac_hash(struct hash_bucket *bucket, void *ctxt)
zebra_mac_t *mac;
char buf1[ETHER_ADDR_STRLEN];
struct mac_walk_ctx *wctx = ctxt;
+ char flags_buf[6];
vty = wctx->vty;
json_mac_hdr = wctx->json;
@@ -1360,26 +1548,24 @@ static void zvni_print_mac_hash(struct hash_bucket *bucket, void *ctxt)
json_mac = json_object_new_object();
if (CHECK_FLAG(mac->flags, ZEBRA_MAC_LOCAL)) {
- struct zebra_ns *zns;
- ifindex_t ifindex;
struct interface *ifp;
vlanid_t vid;
if (wctx->flags & SHOW_REMOTE_MAC_FROM_VTEP)
return;
- zns = zebra_ns_lookup(mac->fwd_info.local.ns_id);
- ifindex = mac->fwd_info.local.ifindex;
- ifp = if_lookup_by_index_per_ns(zns, ifindex);
- if (!ifp) // unexpected
- return;
- vid = mac->fwd_info.local.vid;
- if (json_mac_hdr == NULL)
- vty_out(vty, "%-17s %-6s %-21s", buf1, "local",
- ifp->name);
- else {
+ zebra_vxlan_mac_get_access_info(mac,
+ &ifp, &vid);
+ if (json_mac_hdr == NULL) {
+ vty_out(vty, "%-17s %-6s %-5s %-30s", buf1, "local",
+ zvni_print_mac_flags(mac, flags_buf,
+ sizeof(flags_buf)),
+ ifp ? ifp->name : "-");
+ } else {
json_object_string_add(json_mac, "type", "local");
- json_object_string_add(json_mac, "intf", ifp->name);
+ if (ifp)
+ json_object_string_add(json_mac,
+ "intf", ifp->name);
}
if (vid) {
if (json_mac_hdr == NULL)
@@ -1419,14 +1605,19 @@ static void zvni_print_mac_hash(struct hash_bucket *bucket, void *ctxt)
if (json_mac_hdr == NULL) {
if ((wctx->flags & SHOW_REMOTE_MAC_FROM_VTEP) &&
- (wctx->count == 0)) {
+ (wctx->count == 0)) {
vty_out(vty, "\nVNI %u\n\n", wctx->zvni->vni);
- vty_out(vty, "%-17s %-6s %-21s %-5s %s\n",
- "MAC", "Type", "Intf/Remote VTEP",
+ vty_out(vty, "%-17s %-6s %-5s%-30s %-5s %s\n",
+ "MAC", "Type", "Flags",
+ "Intf/Remote ES/VTEP",
"VLAN", "Seq #'s");
}
- vty_out(vty, "%-17s %-6s %-21s %-5s %u/%u\n", buf1,
- "remote", inet_ntoa(mac->fwd_info.r_vtep_ip),
+ vty_out(vty, "%-17s %-6s %-5s %-30s %-5s %u/%u\n", buf1,
+ "remote",
+ zvni_print_mac_flags(mac, flags_buf,
+ sizeof(flags_buf)),
+ mac->es ? mac->es->esi_str :
+ inet_ntoa(mac->fwd_info.r_vtep_ip),
"", mac->loc_seq, mac->rem_seq);
} else {
json_object_string_add(json_mac, "type", "remote");
@@ -1541,8 +1732,11 @@ static void zvni_print_mac_hash_all_vni(struct hash_bucket *bucket, void *ctxt)
if (json == NULL) {
vty_out(vty, "\nVNI %u #MACs (local and remote) %u\n\n",
zvni->vni, num_macs);
- vty_out(vty, "%-17s %-6s %-21s %-5s %s\n", "MAC",
- "Type", "Intf/Remote VTEP", "VLAN", "Seq #'s");
+ vty_out(vty,
+ "Flags: N=sync-neighs, I=local-inactive, P=peer-active, X=peer-proxy\n");
+ vty_out(vty, "%-17s %-6s %-5s %-30s %-5s %s\n", "MAC",
+ "Type", "Flags", "Intf/Remote ES/VTEP",
+ "VLAN", "Seq #'s");
} else
json_object_int_add(json_vni, "numMacs", num_macs);
}
@@ -2107,13 +2301,16 @@ static void zvni_print_hash_detail(struct hash_bucket *bucket, void *data)
*/
static int zvni_macip_send_msg_to_client(vni_t vni, struct ethaddr *macaddr,
struct ipaddr *ip, uint8_t flags,
- uint32_t seq, int state, uint16_t cmd)
+ uint32_t seq, int state,
+ struct zebra_evpn_es *es,
+ uint16_t cmd)
{
char buf[ETHER_ADDR_STRLEN];
char buf2[INET6_ADDRSTRLEN];
int ipa_len;
struct zserv *client = NULL;
struct stream *s = NULL;
+ esi_t *esi = es ? &es->esi : zero_esi;
client = zserv_find_client(ZEBRA_ROUTE_BGP, 0);
/* BGP may not be running. */
@@ -2141,6 +2338,7 @@ static int zvni_macip_send_msg_to_client(vni_t vni, struct ethaddr *macaddr,
if (cmd == ZEBRA_MACIP_ADD) {
stream_putc(s, flags); /* sticky mac/gateway mac */
stream_putl(s, seq); /* sequence number */
+ stream_put(s, esi, sizeof(esi_t));
} else {
stream_putl(s, state); /* state - active/inactive */
}
@@ -2151,10 +2349,11 @@ static int zvni_macip_send_msg_to_client(vni_t vni, struct ethaddr *macaddr,
if (IS_ZEBRA_DEBUG_VXLAN)
zlog_debug(
- "Send MACIP %s flags 0x%x MAC %s IP %s seq %u L2-VNI %u to %s",
+ "Send MACIP %s f 0x%x MAC %s IP %s seq %u L2-VNI %u ESI %s to %s",
(cmd == ZEBRA_MACIP_ADD) ? "Add" : "Del", flags,
prefix_mac2str(macaddr, buf, sizeof(buf)),
ipaddr2str(ip, buf2, sizeof(buf2)), seq, vni,
+ es ? es->esi_str : "-",
zebra_route_string(client->proto));
if (cmd == ZEBRA_MACIP_ADD)
@@ -2223,26 +2422,26 @@ static void *zvni_neigh_alloc(void *p)
* Add neighbor entry.
*/
static zebra_neigh_t *zvni_neigh_add(zebra_vni_t *zvni, struct ipaddr *ip,
- struct ethaddr *mac)
+ struct ethaddr *mac, zebra_mac_t *zmac,
+ uint32_t n_flags)
{
zebra_neigh_t tmp_n;
zebra_neigh_t *n = NULL;
- zebra_mac_t *zmac = NULL;
memset(&tmp_n, 0, sizeof(zebra_neigh_t));
memcpy(&tmp_n.ip, ip, sizeof(struct ipaddr));
n = hash_get(zvni->neigh_table, &tmp_n, zvni_neigh_alloc);
assert(n);
- memcpy(&n->emac, mac, ETH_ALEN);
n->state = ZEBRA_NEIGH_INACTIVE;
n->zvni = zvni;
n->dad_ip_auto_recovery_timer = NULL;
+ n->flags = n_flags;
- /* Associate the neigh to mac */
- zmac = zvni_mac_lookup(zvni, mac);
- if (zmac)
- listnode_add_sort(zmac->neigh_list, n);
+ if (!zmac)
+ zmac = zvni_mac_lookup(zvni, mac);
+ zebra_vxlan_local_neigh_ref_mac(n, mac,
+ zmac, false /* send_mac_update */);
return n;
}
@@ -2253,11 +2452,9 @@ static zebra_neigh_t *zvni_neigh_add(zebra_vni_t *zvni, struct ipaddr *ip,
static int zvni_neigh_del(zebra_vni_t *zvni, zebra_neigh_t *n)
{
zebra_neigh_t *tmp_n;
- zebra_mac_t *zmac = NULL;
- zmac = zvni_mac_lookup(zvni, &n->emac);
- if (zmac)
- listnode_delete(zmac->neigh_list, n);
+ if (n->mac)
+ listnode_delete(n->mac->neigh_list, n);
/* Cancel auto recovery */
THREAD_OFF(n->dad_ip_auto_recovery_timer);
@@ -2285,10 +2482,18 @@ static void zvni_neigh_del_hash_entry(struct hash_bucket *bucket, void *arg)
&& IPV4_ADDR_SAME(&n->r_vtep_ip, &wctx->r_vtep_ip))) {
if (wctx->upd_client && (n->flags & ZEBRA_NEIGH_LOCAL))
zvni_neigh_send_del_to_client(wctx->zvni->vni, &n->ip,
- &n->emac, 0, n->state);
-
- if (wctx->uninstall)
- zvni_neigh_uninstall(wctx->zvni, n);
+ &n->emac, n->flags, n->state,
+ false /*force*/);
+
+ if (wctx->uninstall) {
+ if (zebra_vxlan_neigh_is_static(n))
+ zebra_vxlan_sync_neigh_dp_install(n,
+ false /* set_inactive */,
+ true /* force_clear_static */,
+ __func__);
+ if ((n->flags & ZEBRA_NEIGH_REMOTE))
+ zvni_neigh_uninstall(wctx->zvni, n);
+ }
zvni_neigh_del(wctx->zvni, n);
}
@@ -2336,8 +2541,7 @@ static zebra_neigh_t *zvni_neigh_lookup(zebra_vni_t *zvni, struct ipaddr *ip)
* locally or undergoing any other change (such as sequence number).
*/
static void zvni_process_neigh_on_local_mac_change(zebra_vni_t *zvni,
- zebra_mac_t *zmac,
- bool seq_change)
+ zebra_mac_t *zmac, bool seq_change, bool es_change)
{
zebra_neigh_t *n = NULL;
struct listnode *node = NULL;
@@ -2359,7 +2563,8 @@ static void zvni_process_neigh_on_local_mac_change(zebra_vni_t *zvni,
*/
for (ALL_LIST_ELEMENTS_RO(zmac->neigh_list, node, n)) {
if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL)) {
- if (IS_ZEBRA_NEIGH_INACTIVE(n) || seq_change) {
+ if (IS_ZEBRA_NEIGH_INACTIVE(n) || seq_change ||
+ es_change) {
ZEBRA_NEIGH_SET_ACTIVE(n);
n->loc_seq = zmac->loc_seq;
if (!(zvrf->dup_addr_detect &&
@@ -2367,7 +2572,7 @@ static void zvni_process_neigh_on_local_mac_change(zebra_vni_t *zvni,
ZEBRA_NEIGH_DUPLICATE)))
zvni_neigh_send_add_to_client(
zvni->vni, &n->ip, &n->emac,
- n->flags, n->loc_seq);
+ n->mac, n->flags, n->loc_seq);
}
}
}
@@ -2401,7 +2606,9 @@ static void zvni_process_neigh_on_local_mac_del(zebra_vni_t *zvni,
ZEBRA_NEIGH_SET_INACTIVE(n);
n->loc_seq = 0;
zvni_neigh_send_del_to_client(zvni->vni, &n->ip,
- &n->emac, 0, ZEBRA_NEIGH_ACTIVE);
+ &n->emac, n->flags,
+ ZEBRA_NEIGH_ACTIVE,
+ false /*force*/);
}
}
}
@@ -2432,7 +2639,9 @@ static void zvni_process_neigh_on_remote_mac_add(zebra_vni_t *zvni,
ZEBRA_NEIGH_SET_INACTIVE(n);
n->loc_seq = 0;
zvni_neigh_send_del_to_client(zvni->vni, &n->ip,
- &n->emac, 0, ZEBRA_NEIGH_ACTIVE);
+ &n->emac, n->flags,
+ ZEBRA_NEIGH_ACTIVE,
+ false /* force */);
}
}
}
@@ -2465,11 +2674,27 @@ static void zvni_probe_neigh_on_mac_add(zebra_vni_t *zvni, zebra_mac_t *zmac)
*/
static int zvni_neigh_send_add_to_client(vni_t vni, struct ipaddr *ip,
struct ethaddr *macaddr,
- uint8_t neigh_flags,
+ zebra_mac_t *zmac,
+ uint32_t neigh_flags,
uint32_t seq)
{
uint8_t flags = 0;
+ if (CHECK_FLAG(neigh_flags, ZEBRA_NEIGH_LOCAL_INACTIVE)) {
+ /* host reachability has not been verified locally */
+
+ /* if no ES peer is claiming reachability we can't advertise
+ * the entry
+ */
+ if (!CHECK_FLAG(neigh_flags, ZEBRA_NEIGH_ES_PEER_ACTIVE))
+ return 0;
+
+ /* ES peers are claiming reachability; we will
+ * advertise the entry but with a proxy flag
+ */
+ SET_FLAG(flags, ZEBRA_MACIP_TYPE_PROXY_ADVERT);
+ }
+
if (CHECK_FLAG(neigh_flags, ZEBRA_NEIGH_DEF_GW))
SET_FLAG(flags, ZEBRA_MACIP_TYPE_GW);
/* Set router flag (R-bit) based on local neigh entry add */
@@ -2479,24 +2704,34 @@ static int zvni_neigh_send_add_to_client(vni_t vni, struct ipaddr *ip,
SET_FLAG(flags, ZEBRA_MACIP_TYPE_SVI_IP);
return zvni_macip_send_msg_to_client(vni, macaddr, ip, flags,
- seq, ZEBRA_NEIGH_ACTIVE, ZEBRA_MACIP_ADD);
+ seq, ZEBRA_NEIGH_ACTIVE,
+ zmac ? zmac->es : NULL,
+ ZEBRA_MACIP_ADD);
}
/*
* Inform BGP about local neighbor deletion.
*/
static int zvni_neigh_send_del_to_client(vni_t vni, struct ipaddr *ip,
- struct ethaddr *macaddr, uint8_t flags,
- int state)
+ struct ethaddr *macaddr, uint32_t flags,
+ int state, bool force)
{
+ if (!force) {
+ if (CHECK_FLAG(flags, ZEBRA_NEIGH_LOCAL_INACTIVE) &&
+ !CHECK_FLAG(flags, ZEBRA_NEIGH_ES_PEER_ACTIVE))
+ /* the neigh was not advertised - nothing to delete */
+ return 0;
+ }
+
return zvni_macip_send_msg_to_client(vni, macaddr, ip, flags,
- 0, state, ZEBRA_MACIP_DEL);
+ 0, state, NULL, ZEBRA_MACIP_DEL);
}
/*
* Install remote neighbor into the kernel.
*/
-static int zvni_neigh_install(zebra_vni_t *zvni, zebra_neigh_t *n)
+static int zvni_rem_neigh_install(zebra_vni_t *zvni, zebra_neigh_t *n,
+ bool was_static)
{
struct zebra_if *zif;
struct zebra_l2info_vxlan *vxl;
@@ -2521,7 +2756,8 @@ static int zvni_neigh_install(zebra_vni_t *zvni, zebra_neigh_t *n)
flags |= DPLANE_NTF_ROUTER;
ZEBRA_NEIGH_SET_ACTIVE(n);
- dplane_neigh_add(vlan_if, &n->ip, &n->emac, flags);
+ dplane_rem_neigh_add(vlan_if, &n->ip, &n->emac, flags,
+ was_static);
return ret;
}
@@ -2556,7 +2792,7 @@ static int zvni_neigh_uninstall(zebra_vni_t *zvni, zebra_neigh_t *n)
ZEBRA_NEIGH_SET_INACTIVE(n);
n->loc_seq = 0;
- dplane_neigh_delete(vlan_if, &n->ip);
+ dplane_rem_neigh_delete(vlan_if, &n->ip);
return 0;
}
@@ -2579,7 +2815,7 @@ static int zvni_neigh_probe(zebra_vni_t *zvni, zebra_neigh_t *n)
if (!vlan_if)
return -1;
- dplane_neigh_update(vlan_if, &n->ip, &n->emac);
+ dplane_rem_neigh_update(vlan_if, &n->ip, &n->emac);
return 0;
}
@@ -2595,7 +2831,7 @@ static void zvni_install_neigh_hash(struct hash_bucket *bucket, void *ctxt)
n = (zebra_neigh_t *)bucket->data;
if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE))
- zvni_neigh_install(wctx->zvni, n);
+ zvni_rem_neigh_install(wctx->zvni, n, false /*was_static*/);
}
/* Get the VRR interface for SVI if any */
@@ -2730,12 +2966,7 @@ static int zvni_gw_macip_add(struct interface *ifp, zebra_vni_t *zvni,
zebra_mac_t *mac = NULL;
struct zebra_if *zif = NULL;
struct zebra_l2info_vxlan *vxl = NULL;
- struct zebra_vrf *zvrf;
- ns_id_t local_ns_id = NS_DEFAULT;
- zvrf = zebra_vrf_lookup_by_id(ifp->vrf_id);
- if (zvrf && zvrf->zns)
- local_ns_id = zvrf->zns->ns_id;
zif = zvni->vxlan_if->info;
if (!zif)
return -1;
@@ -2760,12 +2991,11 @@ static int zvni_gw_macip_add(struct interface *ifp, zebra_vni_t *zvni,
SET_FLAG(mac->flags, ZEBRA_MAC_DEF_GW);
memset(&mac->fwd_info, 0, sizeof(mac->fwd_info));
mac->fwd_info.local.ifindex = ifp->ifindex;
- mac->fwd_info.local.ns_id = local_ns_id;
mac->fwd_info.local.vid = vxl->access_vlan;
n = zvni_neigh_lookup(zvni, ip);
if (!n) {
- n = zvni_neigh_add(zvni, ip, macaddr);
+ n = zvni_neigh_add(zvni, ip, macaddr, mac, 0);
if (!n) {
flog_err(
EC_ZEBRA_MAC_ADD_FAILED,
@@ -2799,7 +3029,7 @@ static int zvni_gw_macip_add(struct interface *ifp, zebra_vni_t *zvni,
prefix_mac2str(macaddr, buf, sizeof(buf)),
ipaddr2str(ip, buf2, sizeof(buf2)), n->flags);
- zvni_neigh_send_add_to_client(zvni->vni, ip, macaddr,
+ zvni_neigh_send_add_to_client(zvni->vni, ip, &n->emac, n->mac,
n->flags, n->loc_seq);
} else if (advertise_svi_macip_enabled(zvni)) {
@@ -2811,7 +3041,7 @@ static int zvni_gw_macip_add(struct interface *ifp, zebra_vni_t *zvni,
prefix_mac2str(macaddr, buf, sizeof(buf)),
ipaddr2str(ip, buf2, sizeof(buf2)), n->flags);
- zvni_neigh_send_add_to_client(zvni->vni, ip, macaddr,
+ zvni_neigh_send_add_to_client(zvni->vni, ip, &n->emac, n->mac,
n->flags, n->loc_seq);
}
@@ -2860,7 +3090,8 @@ static int zvni_gw_macip_del(struct interface *ifp, zebra_vni_t *zvni,
/* Remove neighbor from BGP. */
zvni_neigh_send_del_to_client(zvni->vni, &n->ip, &n->emac,
- ZEBRA_MACIP_TYPE_GW, ZEBRA_NEIGH_ACTIVE);
+ n->flags, ZEBRA_NEIGH_ACTIVE,
+ false /*force*/);
/* Delete this neighbor entry. */
zvni_neigh_del(zvni, n);
@@ -3008,11 +3239,36 @@ static void zvni_svi_macip_del_for_vni_hash(struct hash_bucket *bucket,
return;
}
+static inline void zvni_local_neigh_update_log(const char *pfx,
+ zebra_neigh_t *n, bool is_router, bool local_inactive,
+ bool old_bgp_ready, bool new_bgp_ready,
+ bool inform_dataplane, bool inform_bgp, const char *sfx)
+{
+ char macbuf[ETHER_ADDR_STRLEN];
+ char ipbuf[INET6_ADDRSTRLEN];
+
+ if (!IS_ZEBRA_DEBUG_EVPN_MH_NEIGH)
+ return;
+
+ zlog_debug("%s neigh vni %u ip %s mac %s f 0x%x%s%s%s%s%s%s %s",
+ pfx, n->zvni->vni,
+ ipaddr2str(&n->ip, ipbuf, sizeof(ipbuf)),
+ prefix_mac2str(&n->emac, macbuf, sizeof(macbuf)),
+ n->flags, is_router ? " router" : "",
+ local_inactive ? " local-inactive" : "",
+ old_bgp_ready ? " old_bgp_ready" : "",
+ new_bgp_ready ? " new_bgp_ready" : "",
+ inform_dataplane ? " inform_dp" : "",
+ inform_bgp ? " inform_bgp" : "",
+ sfx);
+}
+
static int zvni_local_neigh_update(zebra_vni_t *zvni,
struct interface *ifp,
struct ipaddr *ip,
struct ethaddr *macaddr,
- bool is_router)
+ bool is_router,
+ bool local_inactive, bool dp_static)
{
char buf[ETHER_ADDR_STRLEN];
char buf2[INET6_ADDRSTRLEN];
@@ -3026,6 +3282,11 @@ static int zvni_local_neigh_update(zebra_vni_t *zvni,
bool neigh_was_remote = false;
bool do_dad = false;
struct in_addr vtep_ip = {.s_addr = 0};
+ bool inform_dataplane = false;
+ bool created = false;
+ bool new_static = false;
+ bool old_bgp_ready = false;
+ bool new_bgp_ready;
/* Check if the MAC exists. */
zmac = zvni_mac_lookup(zvni, macaddr);
@@ -3073,7 +3334,7 @@ static int zvni_local_neigh_update(zebra_vni_t *zvni,
n = zvni_neigh_lookup(zvni, ip);
if (!n) {
/* New neighbor - create */
- n = zvni_neigh_add(zvni, ip, macaddr);
+ n = zvni_neigh_add(zvni, ip, macaddr, zmac, 0);
if (!n) {
flog_err(
EC_ZEBRA_MAC_ADD_FAILED,
@@ -3086,17 +3347,28 @@ static int zvni_local_neigh_update(zebra_vni_t *zvni,
/* Set "local" forwarding info. */
SET_FLAG(n->flags, ZEBRA_NEIGH_LOCAL);
n->ifindex = ifp->ifindex;
+ created = true;
} else {
if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL)) {
bool mac_different;
bool cur_is_router;
+ bool old_local_inactive;
+
+ old_local_inactive = !!CHECK_FLAG(n->flags,
+ ZEBRA_NEIGH_LOCAL_INACTIVE);
+
+ old_bgp_ready =
+ zebra_vxlan_neigh_is_ready_for_bgp(n);
/* Note any changes and see if of interest to BGP. */
- mac_different = (memcmp(n->emac.octet,
- macaddr->octet, ETH_ALEN) != 0) ? 1 : 0;
+ mac_different = !!memcmp(&n->emac,
+ macaddr, ETH_ALEN);
cur_is_router = !!CHECK_FLAG(n->flags,
ZEBRA_NEIGH_ROUTER_FLAG);
- if (!mac_different && is_router == cur_is_router) {
+ new_static = zebra_vxlan_neigh_is_static(n);
+ if (!mac_different && is_router == cur_is_router &&
+ old_local_inactive == local_inactive &&
+ dp_static != new_static) {
if (IS_ZEBRA_DEBUG_VXLAN)
zlog_debug(
" Ignoring entry mac is the same and is_router == cur_is_router");
@@ -3104,7 +3376,9 @@ static int zvni_local_neigh_update(zebra_vni_t *zvni,
return 0;
}
+ old_zmac = n->mac;
if (!mac_different) {
+ /* XXX - cleanup this code duplication */
bool is_neigh_freezed = false;
/* Only the router flag has changed. */
@@ -3115,6 +3389,15 @@ static int zvni_local_neigh_update(zebra_vni_t *zvni,
UNSET_FLAG(n->flags,
ZEBRA_NEIGH_ROUTER_FLAG);
+ if (local_inactive)
+ SET_FLAG(n->flags,
+ ZEBRA_NEIGH_LOCAL_INACTIVE);
+ else
+ UNSET_FLAG(n->flags,
+ ZEBRA_NEIGH_LOCAL_INACTIVE);
+ new_bgp_ready =
+ zebra_vxlan_neigh_is_ready_for_bgp(n);
+
/* Neigh is in freeze state and freeze action
* is enabled, do not send update to client.
*/
@@ -3123,13 +3406,20 @@ static int zvni_local_neigh_update(zebra_vni_t *zvni,
CHECK_FLAG(n->flags,
ZEBRA_NEIGH_DUPLICATE));
- if (IS_ZEBRA_NEIGH_ACTIVE(n) &&
- !is_neigh_freezed)
- return zvni_neigh_send_add_to_client(
- zvni->vni, ip, macaddr,
- n->flags, n->loc_seq);
- else {
- if (IS_ZEBRA_DEBUG_VXLAN)
+ zvni_local_neigh_update_log("local", n,
+ is_router, local_inactive,
+ old_bgp_ready, new_bgp_ready,
+ false, false, "flag-update");
+
+ /* if the neigh can no longer be advertised
+ * remove it from bgp
+ */
+ if (!is_neigh_freezed) {
+ zebra_vxlan_neigh_send_add_del_to_client(
+ n, old_bgp_ready, new_bgp_ready);
+ } else {
+ if (IS_ZEBRA_DEBUG_VXLAN &&
+ IS_ZEBRA_NEIGH_ACTIVE(n))
zlog_debug(
" Neighbor active and frozen");
}
@@ -3142,25 +3432,32 @@ static int zvni_local_neigh_update(zebra_vni_t *zvni,
* We also need to update the MAC's sequence number
* in different situations.
*/
- if (IS_ZEBRA_NEIGH_ACTIVE(n))
+ if (old_bgp_ready) {
zvni_neigh_send_del_to_client(zvni->vni, &n->ip,
- &n->emac, 0, n->state);
- old_zmac = zvni_mac_lookup(zvni, &n->emac);
+ &n->emac, n->flags, n->state,
+ false /*force*/);
+ old_bgp_ready = false;
+ }
if (old_zmac) {
old_mac_seq = CHECK_FLAG(old_zmac->flags,
ZEBRA_MAC_REMOTE) ?
old_zmac->rem_seq : old_zmac->loc_seq;
neigh_mac_change = upd_mac_seq = true;
- listnode_delete(old_zmac->neigh_list, n);
- zvni_deref_ip2mac(zvni, old_zmac);
+ zebra_vxlan_local_neigh_deref_mac(n,
+ true /* send_mac_update */);
}
+ /* if mac changes abandon peer flags and tell
+ * dataplane to clear the static flag
+ */
+ if (zebra_vxlan_neigh_clear_sync_info(n))
+ inform_dataplane = true;
/* Update the forwarding info. */
n->ifindex = ifp->ifindex;
- memcpy(&n->emac, macaddr, ETH_ALEN);
/* Link to new MAC */
- listnode_add_sort(zmac->neigh_list, n);
+ zebra_vxlan_local_neigh_ref_mac(n, macaddr, zmac,
+ true /* send_mac_update */);
} else if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE)) {
/*
* Neighbor has moved from remote to local. Its
@@ -3168,7 +3465,7 @@ static int zvni_local_neigh_update(zebra_vni_t *zvni,
*/
if (memcmp(n->emac.octet, macaddr->octet,
ETH_ALEN) != 0) {
- old_zmac = zvni_mac_lookup(zvni, &n->emac);
+ old_zmac = n->mac;
if (old_zmac) {
old_mac_seq = CHECK_FLAG(
old_zmac->flags,
@@ -3176,14 +3473,13 @@ static int zvni_local_neigh_update(zebra_vni_t *zvni,
old_zmac->rem_seq :
old_zmac->loc_seq;
neigh_mac_change = upd_mac_seq = true;
- listnode_delete(old_zmac->neigh_list,
- n);
- zvni_deref_ip2mac(zvni, old_zmac);
+ zebra_vxlan_local_neigh_deref_mac(n,
+ true /* send_update */);
}
/* Link to new MAC */
- memcpy(&n->emac, macaddr, ETH_ALEN);
- listnode_add_sort(zmac->neigh_list, n);
+ zebra_vxlan_local_neigh_ref_mac(n, macaddr,
+ zmac, true /*send_update*/);
}
/* Based on Mobility event Scenario-B from the
* draft, neigh's previous state was remote treat this
@@ -3212,12 +3508,27 @@ static int zvni_local_neigh_update(zebra_vni_t *zvni,
MAX(seq1, seq2) : zmac->loc_seq;
}
+ if (local_inactive)
+ SET_FLAG(n->flags, ZEBRA_NEIGH_LOCAL_INACTIVE);
+ else
+ UNSET_FLAG(n->flags, ZEBRA_NEIGH_LOCAL_INACTIVE);
+
/* Mark Router flag (R-bit) */
if (is_router)
SET_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG);
else
UNSET_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG);
+ /* if the dataplane thinks that this is a sync entry but
+ * zebra doesn't we need to re-concile the diff
+ * by re-installing the dataplane entry
+ */
+ if (dp_static) {
+ new_static = zebra_vxlan_neigh_is_static(n);
+ if (!new_static)
+ inform_dataplane = true;
+ }
+
/* Check old and/or new MAC detected as duplicate mark
* the neigh as duplicate
*/
@@ -3240,16 +3551,28 @@ static int zvni_local_neigh_update(zebra_vni_t *zvni,
zebra_vxlan_dup_addr_detect_for_neigh(zvrf, n, vtep_ip, do_dad,
&neigh_on_hold, true);
+ if (inform_dataplane)
+ zebra_vxlan_sync_neigh_dp_install(n, false /* set_inactive */,
+ false /* force_clear_static */, __func__);
+
/* Before we program this in BGP, we need to check if MAC is locally
* learnt. If not, force neighbor to be inactive and reset its seq.
*/
if (!CHECK_FLAG(zmac->flags, ZEBRA_MAC_LOCAL)) {
+ zvni_local_neigh_update_log("local",
+ n, is_router, local_inactive,
+ false, false, inform_dataplane, false,
+ "auto-mac");
ZEBRA_NEIGH_SET_INACTIVE(n);
n->loc_seq = 0;
zmac->loc_seq = mac_new_seq;
return 0;
}
+ zvni_local_neigh_update_log("local",
+ n, is_router, local_inactive, false, false, inform_dataplane,
+ true, created ? "created" : "updated");
+
/* If the MAC's sequence number has changed, inform the MAC and all
* neighbors associated with the MAC to BGP, else just inform this
* neighbor.
@@ -3261,9 +3584,10 @@ static int zvni_local_neigh_update(zebra_vni_t *zvni,
zvni->vni, zmac->loc_seq, mac_new_seq);
zmac->loc_seq = mac_new_seq;
if (zvni_mac_send_add_to_client(zvni->vni, macaddr,
- zmac->flags, zmac->loc_seq))
+ zmac->flags, zmac->loc_seq, zmac->es))
return -1;
- zvni_process_neigh_on_local_mac_change(zvni, zmac, 1);
+ zvni_process_neigh_on_local_mac_change(zvni, zmac, 1,
+ 0 /*es_change*/);
return 0;
}
@@ -3271,9 +3595,10 @@ static int zvni_local_neigh_update(zebra_vni_t *zvni,
if (!neigh_on_hold) {
ZEBRA_NEIGH_SET_ACTIVE(n);
-
- return zvni_neigh_send_add_to_client(zvni->vni, ip, macaddr,
- n->flags, n->loc_seq);
+ new_bgp_ready =
+ zebra_vxlan_neigh_is_ready_for_bgp(n);
+ zebra_vxlan_neigh_send_add_del_to_client(n,
+ old_bgp_ready, new_bgp_ready);
} else {
if (IS_ZEBRA_DEBUG_VXLAN)
zlog_debug(" Neighbor on hold not sending");
@@ -3301,7 +3626,7 @@ static int zvni_remote_neigh_update(zebra_vni_t *zvni,
if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE)) {
#ifdef GNU_LINUX
if (state & NUD_STALE)
- zvni_neigh_install(zvni, n);
+ zvni_rem_neigh_install(zvni, n, false /*was_static*/);
#endif
} else {
/* We got a "remote" neighbor notification for an entry
@@ -3319,7 +3644,7 @@ static int zvni_remote_neigh_update(zebra_vni_t *zvni,
return -1;
}
- UNSET_FLAG(n->flags, ZEBRA_NEIGH_LOCAL);
+ UNSET_FLAG(n->flags, ZEBRA_NEIGH_ALL_LOCAL_FLAGS);
SET_FLAG(n->flags, ZEBRA_NEIGH_REMOTE);
ZEBRA_NEIGH_SET_ACTIVE(n);
n->r_vtep_ip = zmac->fwd_info.r_vtep_ip;
@@ -3390,6 +3715,15 @@ static zebra_mac_t *zvni_mac_add(zebra_vni_t *zvni, struct ethaddr *macaddr)
mac->neigh_list = list_new();
mac->neigh_list->cmp = neigh_list_cmp;
+ if (IS_ZEBRA_DEBUG_VXLAN || IS_ZEBRA_DEBUG_EVPN_MH_MAC) {
+ char buf[ETHER_ADDR_STRLEN];
+
+ zlog_debug("%s: MAC %s flags 0x%x",
+ __func__,
+ prefix_mac2str(&mac->macaddr,
+ buf, sizeof(buf)),
+ mac->flags);
+ }
return mac;
}
@@ -3400,6 +3734,22 @@ static int zvni_mac_del(zebra_vni_t *zvni, zebra_mac_t *mac)
{
zebra_mac_t *tmp_mac;
+ if (IS_ZEBRA_DEBUG_VXLAN || IS_ZEBRA_DEBUG_EVPN_MH_MAC) {
+ char buf[ETHER_ADDR_STRLEN];
+
+ zlog_debug("%s: MAC %s flags 0x%x",
+ __func__,
+ prefix_mac2str(&mac->macaddr,
+ buf, sizeof(buf)),
+ mac->flags);
+ }
+
+ /* force de-ref any ES entry linked to the MAC */
+ zebra_evpn_es_mac_deref_entry(mac);
+
+ /* Cancel proxy hold timer */
+ zebra_vxlan_mac_stop_hold_timer(mac);
+
/* Cancel auto recovery */
THREAD_OFF(mac->dad_mac_auto_recovery_timer);
@@ -3455,10 +3805,18 @@ static void zvni_mac_del_hash_entry(struct hash_bucket *bucket, void *arg)
if (zvni_check_mac_del_from_db(wctx, mac)) {
if (wctx->upd_client && (mac->flags & ZEBRA_MAC_LOCAL)) {
zvni_mac_send_del_to_client(wctx->zvni->vni,
- &mac->macaddr);
+ &mac->macaddr, mac->flags, false);
+ }
+ if (wctx->uninstall) {
+ if (zebra_vxlan_mac_is_static(mac))
+ zebra_vxlan_sync_mac_dp_install(mac,
+ false /* set_inactive */,
+ true /* force_clear_static */,
+ __func__);
+
+ if (mac->flags & ZEBRA_MAC_REMOTE)
+ zvni_rem_mac_uninstall(wctx->zvni, mac);
}
- if (wctx->uninstall)
- zvni_mac_uninstall(wctx->zvni, mac);
zvni_mac_del(wctx->zvni, mac);
}
@@ -3505,88 +3863,51 @@ static zebra_mac_t *zvni_mac_lookup(zebra_vni_t *zvni, struct ethaddr *mac)
* Inform BGP about local MAC addition.
*/
static int zvni_mac_send_add_to_client(vni_t vni, struct ethaddr *macaddr,
- uint8_t mac_flags, uint32_t seq)
+ uint32_t mac_flags, uint32_t seq, struct zebra_evpn_es *es)
{
uint8_t flags = 0;
+ if (CHECK_FLAG(mac_flags, ZEBRA_MAC_LOCAL_INACTIVE)) {
+ /* host reachability has not been verified locally */
+
+ /* if no ES peer is claiming reachability we can't advertise the
+ * entry
+ */
+ if (!CHECK_FLAG(mac_flags, ZEBRA_MAC_ES_PEER_ACTIVE))
+ return 0;
+
+ /* ES peers are claiming reachability; we will
+ * advertise the entry but with a proxy flag
+ */
+ SET_FLAG(flags, ZEBRA_MACIP_TYPE_PROXY_ADVERT);
+ }
+
if (CHECK_FLAG(mac_flags, ZEBRA_MAC_STICKY))
SET_FLAG(flags, ZEBRA_MACIP_TYPE_STICKY);
if (CHECK_FLAG(mac_flags, ZEBRA_MAC_DEF_GW))
SET_FLAG(flags, ZEBRA_MACIP_TYPE_GW);
return zvni_macip_send_msg_to_client(vni, macaddr, NULL, flags,
- seq, ZEBRA_NEIGH_ACTIVE, ZEBRA_MACIP_ADD);
+ seq, ZEBRA_NEIGH_ACTIVE, es,
+ ZEBRA_MACIP_ADD);
}
/*
* Inform BGP about local MAC deletion.
*/
-static int zvni_mac_send_del_to_client(vni_t vni, struct ethaddr *macaddr)
-{
- return zvni_macip_send_msg_to_client(vni, macaddr, NULL, 0 /* flags */,
- 0 /* seq */, ZEBRA_NEIGH_ACTIVE, ZEBRA_MACIP_DEL);
-}
-
-struct zvni_from_svi_param {
- struct interface *br_if;
- struct interface *svi_if;
- struct zebra_if *zif;
- uint8_t bridge_vlan_aware;
- vlanid_t vid;
-};
-
-static int zvni_map_vlan_ns(struct ns *ns,
- void *_in_param,
- void **_p_zvni)
+static int zvni_mac_send_del_to_client(vni_t vni, struct ethaddr *macaddr,
+ uint32_t flags, bool force)
{
- struct zebra_ns *zns = ns->info;
- struct route_node *rn;
- struct interface *br_if;
- zebra_vni_t **p_zvni = (zebra_vni_t **)_p_zvni;
- zebra_vni_t *zvni;
- struct interface *tmp_if = NULL;
- struct zebra_if *zif;
- struct zebra_l2info_vxlan *vxl = NULL;
- struct zvni_from_svi_param *in_param =
- (struct zvni_from_svi_param *)_in_param;
- int found = 0;
-
- if (!in_param)
- return NS_WALK_STOP;
- br_if = in_param->br_if;
- zif = in_param->zif;
- assert(zif);
- assert(br_if);
-
- /* See if this interface (or interface plus VLAN Id) maps to a VxLAN */
- /* TODO: Optimize with a hash. */
- for (rn = route_top(zns->if_table); rn; rn = route_next(rn)) {
- tmp_if = (struct interface *)rn->info;
- if (!tmp_if)
- continue;
- zif = tmp_if->info;
- if (!zif || zif->zif_type != ZEBRA_IF_VXLAN)
- continue;
- if (!if_is_operative(tmp_if))
- continue;
- vxl = &zif->l2info.vxl;
-
- if (zif->brslave_info.br_if != br_if)
- continue;
-
- if (!in_param->bridge_vlan_aware
- || vxl->access_vlan == in_param->vid) {
- found = 1;
- break;
- }
+ if (!force) {
+ if (CHECK_FLAG(flags, ZEBRA_MAC_LOCAL_INACTIVE) &&
+ !CHECK_FLAG(flags, ZEBRA_MAC_ES_PEER_ACTIVE))
+ /* the host was not advertised - nothing to delete */
+ return 0;
}
- if (!found)
- return NS_WALK_CONTINUE;
- zvni = zvni_lookup(vxl->vni);
- if (p_zvni)
- *p_zvni = zvni;
- return NS_WALK_STOP;
+ return zvni_macip_send_msg_to_client(vni, macaddr, NULL, 0 /* flags */,
+ 0 /* seq */, ZEBRA_NEIGH_ACTIVE, NULL,
+ ZEBRA_MACIP_DEL);
}
/*
@@ -3596,51 +3917,25 @@ static int zvni_map_vlan_ns(struct ns *ns,
static zebra_vni_t *zvni_map_vlan(struct interface *ifp,
struct interface *br_if, vlanid_t vid)
{
- struct zebra_if *zif;
- struct zebra_l2info_bridge *br;
- zebra_vni_t **p_zvni;
- zebra_vni_t *zvni = NULL;
- struct zvni_from_svi_param in_param;
-
- /* Determine if bridge is VLAN-aware or not */
- zif = br_if->info;
- assert(zif);
- br = &zif->l2info.br;
- in_param.bridge_vlan_aware = br->vlan_aware;
- in_param.vid = vid;
- in_param.br_if = br_if;
- in_param.zif = zif;
- p_zvni = &zvni;
-
- ns_walk_func(zvni_map_vlan_ns,
- (void *)&in_param,
- (void **)p_zvni);
- return zvni;
-}
-
-static int zvni_from_svi_ns(struct ns *ns,
- void *_in_param,
- void **_p_zvni)
-{
- struct zebra_ns *zns = ns->info;
+ struct zebra_ns *zns;
struct route_node *rn;
- struct interface *br_if;
- zebra_vni_t **p_zvni = (zebra_vni_t **)_p_zvni;
- zebra_vni_t *zvni;
struct interface *tmp_if = NULL;
struct zebra_if *zif;
+ struct zebra_l2info_bridge *br;
struct zebra_l2info_vxlan *vxl = NULL;
- struct zvni_from_svi_param *in_param =
- (struct zvni_from_svi_param *)_in_param;
+ uint8_t bridge_vlan_aware;
+ zebra_vni_t *zvni;
int found = 0;
- if (!in_param)
- return NS_WALK_STOP;
- br_if = in_param->br_if;
- zif = in_param->zif;
+ /* Determine if bridge is VLAN-aware or not */
+ zif = br_if->info;
assert(zif);
+ br = &zif->l2info.br;
+ bridge_vlan_aware = br->vlan_aware;
+ /* See if this interface (or interface plus VLAN Id) maps to a VxLAN */
/* TODO: Optimize with a hash. */
+ zns = zebra_ns_lookup(NS_DEFAULT);
for (rn = route_top(zns->if_table); rn; rn = route_next(rn)) {
tmp_if = (struct interface *)rn->info;
if (!tmp_if)
@@ -3655,20 +3950,17 @@ static int zvni_from_svi_ns(struct ns *ns,
if (zif->brslave_info.br_if != br_if)
continue;
- if (!in_param->bridge_vlan_aware
- || vxl->access_vlan == !in_param->vid) {
+ if (!bridge_vlan_aware || vxl->access_vlan == vid) {
found = 1;
break;
}
}
if (!found)
- return NS_WALK_CONTINUE;
+ return NULL;
zvni = zvni_lookup(vxl->vni);
- if (p_zvni)
- *p_zvni = zvni;
- return NS_WALK_STOP;
+ return zvni;
}
/*
@@ -3678,11 +3970,16 @@ static int zvni_from_svi_ns(struct ns *ns,
static zebra_vni_t *zvni_from_svi(struct interface *ifp,
struct interface *br_if)
{
- struct zebra_l2info_bridge *br;
- zebra_vni_t *zvni = NULL;
- zebra_vni_t **p_zvni;
+ struct zebra_ns *zns;
+ struct route_node *rn;
+ struct interface *tmp_if = NULL;
struct zebra_if *zif;
- struct zvni_from_svi_param in_param;
+ struct zebra_l2info_bridge *br;
+ struct zebra_l2info_vxlan *vxl = NULL;
+ uint8_t bridge_vlan_aware;
+ vlanid_t vid = 0;
+ zebra_vni_t *zvni;
+ int found = 0;
if (!br_if)
return NULL;
@@ -3695,10 +3992,8 @@ static zebra_vni_t *zvni_from_svi(struct interface *ifp,
zif = br_if->info;
assert(zif);
br = &zif->l2info.br;
- in_param.bridge_vlan_aware = br->vlan_aware;
- in_param.vid = 0;
-
- if (in_param.bridge_vlan_aware) {
+ bridge_vlan_aware = br->vlan_aware;
+ if (bridge_vlan_aware) {
struct zebra_l2info_vlan *vl;
if (!IS_ZEBRA_IF_VLAN(ifp))
@@ -3707,54 +4002,37 @@ static zebra_vni_t *zvni_from_svi(struct interface *ifp,
zif = ifp->info;
assert(zif);
vl = &zif->l2info.vl;
- in_param.vid = vl->vid;
+ vid = vl->vid;
}
- in_param.br_if = br_if;
- in_param.zif = zif;
- p_zvni = &zvni;
/* See if this interface (or interface plus VLAN Id) maps to a VxLAN */
- ns_walk_func(zvni_from_svi_ns,
- (void *)&in_param,
- (void **)p_zvni);
- return zvni;
-}
-
-static int zvni_map_to_svi_ns(struct ns *ns,
- void *_in_param,
- void **_p_ifp)
-{
- struct zebra_ns *zns = ns->info;
- struct route_node *rn;
- struct zvni_from_svi_param *in_param =
- (struct zvni_from_svi_param *)_in_param;
- struct zebra_l2info_vlan *vl;
- struct interface *tmp_if = NULL;
- struct interface **p_ifp = (struct interface **)_p_ifp;
- struct zebra_if *zif;
-
- if (!in_param)
- return NS_WALK_STOP;
-
/* TODO: Optimize with a hash. */
+ zns = zebra_ns_lookup(NS_DEFAULT);
for (rn = route_top(zns->if_table); rn; rn = route_next(rn)) {
tmp_if = (struct interface *)rn->info;
- /* Check oper status of the SVI. */
- if (!tmp_if || !if_is_operative(tmp_if))
+ if (!tmp_if)
continue;
zif = tmp_if->info;
- if (!zif || zif->zif_type != ZEBRA_IF_VLAN
- || zif->link != in_param->br_if)
+ if (!zif || zif->zif_type != ZEBRA_IF_VXLAN)
continue;
- vl = (struct zebra_l2info_vlan *)&zif->l2info.vl;
+ if (!if_is_operative(tmp_if))
+ continue;
+ vxl = &zif->l2info.vxl;
- if (vl->vid == in_param->vid) {
- if (p_ifp)
- *p_ifp = tmp_if;
- return NS_WALK_STOP;
+ if (zif->brslave_info.br_if != br_if)
+ continue;
+
+ if (!bridge_vlan_aware || vxl->access_vlan == vid) {
+ found = 1;
+ break;
}
}
- return NS_WALK_CONTINUE;
+
+ if (!found)
+ return NULL;
+
+ zvni = zvni_lookup(vxl->vni);
+ return zvni;
}
/* Map to SVI on bridge corresponding to specified VLAN. This can be one
@@ -3766,11 +4044,15 @@ static int zvni_map_to_svi_ns(struct ns *ns,
*/
static struct interface *zvni_map_to_svi(vlanid_t vid, struct interface *br_if)
{
+ struct zebra_ns *zns;
+ struct route_node *rn;
struct interface *tmp_if = NULL;
struct zebra_if *zif;
struct zebra_l2info_bridge *br;
- struct zvni_from_svi_param in_param;
- struct interface **p_ifp;
+ struct zebra_l2info_vlan *vl;
+ uint8_t bridge_vlan_aware;
+ int found = 0;
+
/* Defensive check, caller expected to invoke only with valid bridge. */
if (!br_if)
return NULL;
@@ -3779,56 +4061,33 @@ static struct interface *zvni_map_to_svi(vlanid_t vid, struct interface *br_if)
zif = br_if->info;
assert(zif);
br = &zif->l2info.br;
- in_param.bridge_vlan_aware = br->vlan_aware;
+ bridge_vlan_aware = br->vlan_aware;
+
/* Check oper status of the SVI. */
- if (!in_param.bridge_vlan_aware)
+ if (!bridge_vlan_aware)
return if_is_operative(br_if) ? br_if : NULL;
- in_param.vid = vid;
- in_param.br_if = br_if;
- in_param.zif = NULL;
- p_ifp = &tmp_if;
- /* Identify corresponding VLAN interface. */
- ns_walk_func(zvni_map_to_svi_ns,
- (void *)&in_param,
- (void **)p_ifp);
- return tmp_if;
-}
-
-static int zvni_map_to_macvlan_ns(struct ns *ns,
- void *_in_param,
- void **_p_ifp)
-{
- struct zebra_ns *zns = ns->info;
- struct zvni_from_svi_param *in_param =
- (struct zvni_from_svi_param *)_in_param;
- struct interface **p_ifp = (struct interface **)_p_ifp;
- struct route_node *rn;
- struct interface *tmp_if = NULL;
- struct zebra_if *zif;
-
- if (!in_param)
- return NS_WALK_STOP;
-
/* Identify corresponding VLAN interface. */
+ /* TODO: Optimize with a hash. */
+ zns = zebra_ns_lookup(NS_DEFAULT);
for (rn = route_top(zns->if_table); rn; rn = route_next(rn)) {
tmp_if = (struct interface *)rn->info;
/* Check oper status of the SVI. */
if (!tmp_if || !if_is_operative(tmp_if))
continue;
zif = tmp_if->info;
-
- if (!zif || zif->zif_type != ZEBRA_IF_MACVLAN)
+ if (!zif || zif->zif_type != ZEBRA_IF_VLAN
+ || zif->link != br_if)
continue;
+ vl = &zif->l2info.vl;
- if (zif->link == in_param->svi_if) {
- if (p_ifp)
- *p_ifp = tmp_if;
- return NS_WALK_STOP;
+ if (vl->vid == vid) {
+ found = 1;
+ break;
}
}
- return NS_WALK_CONTINUE;
+ return found ? tmp_if : NULL;
}
/* Map to MAC-VLAN interface corresponding to specified SVI interface.
@@ -3836,10 +4095,11 @@ static int zvni_map_to_macvlan_ns(struct ns *ns,
static struct interface *zvni_map_to_macvlan(struct interface *br_if,
struct interface *svi_if)
{
+ struct zebra_ns *zns;
+ struct route_node *rn;
struct interface *tmp_if = NULL;
struct zebra_if *zif;
- struct interface **p_ifp;
- struct zvni_from_svi_param in_param;
+ int found = 0;
/* Defensive check, caller expected to invoke only with valid bridge. */
if (!br_if)
@@ -3854,23 +4114,33 @@ static struct interface *zvni_map_to_macvlan(struct interface *br_if,
zif = br_if->info;
assert(zif);
- in_param.vid = 0;
- in_param.br_if = br_if;
- in_param.zif = NULL;
- in_param.svi_if = svi_if;
- p_ifp = &tmp_if;
-
/* Identify corresponding VLAN interface. */
- ns_walk_func(zvni_map_to_macvlan_ns,
- (void *)&in_param,
- (void **)p_ifp);
- return tmp_if;
+ zns = zebra_ns_lookup(NS_DEFAULT);
+ for (rn = route_top(zns->if_table); rn; rn = route_next(rn)) {
+ tmp_if = (struct interface *)rn->info;
+ /* Check oper status of the SVI. */
+ if (!tmp_if || !if_is_operative(tmp_if))
+ continue;
+ zif = tmp_if->info;
+
+ if (!zif || zif->zif_type != ZEBRA_IF_MACVLAN)
+ continue;
+
+ if (zif->link == svi_if) {
+ found = 1;
+ break;
+ }
+ }
+
+ return found ? tmp_if : NULL;
}
+
/*
* Install remote MAC into the forwarding plane.
*/
-static int zvni_mac_install(zebra_vni_t *zvni, zebra_mac_t *mac)
+static int zvni_rem_mac_install(zebra_vni_t *zvni, zebra_mac_t *mac,
+ bool was_static)
{
const struct zebra_if *zif, *br_zif;
const struct zebra_l2info_vxlan *vxl;
@@ -3878,6 +4148,8 @@ static int zvni_mac_install(zebra_vni_t *zvni, zebra_mac_t *mac)
enum zebra_dplane_result res;
const struct interface *br_ifp;
vlanid_t vid;
+ uint32_t nhg_id;
+ struct in_addr vtep_ip;
if (!(mac->flags & ZEBRA_MAC_REMOTE))
return 0;
@@ -3895,6 +4167,19 @@ static int zvni_mac_install(zebra_vni_t *zvni, zebra_mac_t *mac)
sticky = !!CHECK_FLAG(mac->flags,
(ZEBRA_MAC_STICKY | ZEBRA_MAC_REMOTE_DEF_GW));
+ /* If nexthop group for the FDB entry is inactive (not programmed in
+ * the dataplane) the MAC entry cannot be installed
+ */
+ if (mac->es) {
+ if (!(mac->es->flags & ZEBRA_EVPNES_NHG_ACTIVE))
+ return -1;
+ nhg_id = mac->es->nhg_id;
+ vtep_ip.s_addr = 0;
+ } else {
+ nhg_id = 0;
+ vtep_ip = mac->fwd_info.r_vtep_ip;
+ }
+
br_zif = (const struct zebra_if *)(br_ifp->info);
if (IS_ZEBRA_IF_BRIDGE_VLAN_AWARE(br_zif))
@@ -3902,8 +4187,9 @@ static int zvni_mac_install(zebra_vni_t *zvni, zebra_mac_t *mac)
else
vid = 0;
- res = dplane_mac_add(zvni->vxlan_if, br_ifp, vid,
- &mac->macaddr, mac->fwd_info.r_vtep_ip, sticky);
+ res = dplane_rem_mac_add(zvni->vxlan_if, br_ifp, vid,
+ &mac->macaddr, vtep_ip, sticky,
+ nhg_id, was_static);
if (res != ZEBRA_DPLANE_REQUEST_FAILURE)
return 0;
else
@@ -3913,7 +4199,7 @@ static int zvni_mac_install(zebra_vni_t *zvni, zebra_mac_t *mac)
/*
* Uninstall remote MAC from the forwarding plane.
*/
-static int zvni_mac_uninstall(zebra_vni_t *zvni, zebra_mac_t *mac)
+static int zvni_rem_mac_uninstall(zebra_vni_t *zvni, zebra_mac_t *mac)
{
const struct zebra_if *zif, *br_zif;
const struct zebra_l2info_vxlan *vxl;
@@ -3952,7 +4238,7 @@ static int zvni_mac_uninstall(zebra_vni_t *zvni, zebra_mac_t *mac)
ifp = zvni->vxlan_if;
vtep_ip = mac->fwd_info.r_vtep_ip;
- res = dplane_mac_del(ifp, br_ifp, vid, &mac->macaddr, vtep_ip);
+ res = dplane_rem_mac_del(ifp, br_ifp, vid, &mac->macaddr, vtep_ip);
if (res != ZEBRA_DPLANE_REQUEST_FAILURE)
return 0;
else
@@ -3970,7 +4256,7 @@ static void zvni_install_mac_hash(struct hash_bucket *bucket, void *ctxt)
mac = (zebra_mac_t *)bucket->data;
if (CHECK_FLAG(mac->flags, ZEBRA_MAC_REMOTE))
- zvni_mac_install(wctx->zvni, mac);
+ zvni_rem_mac_install(wctx->zvni, mac, false);
}
/*
@@ -4004,7 +4290,8 @@ static void zvni_deref_ip2mac(zebra_vni_t *zvni, zebra_mac_t *mac)
*/
if (CHECK_FLAG(mac->flags, ZEBRA_MAC_REMOTE) &&
remote_neigh_count(mac) == 0) {
- zvni_mac_uninstall(zvni, mac);
+ zvni_rem_mac_uninstall(zvni, mac);
+ zebra_evpn_es_mac_deref_entry(mac);
UNSET_FLAG(mac->flags, ZEBRA_MAC_REMOTE);
}
@@ -4019,7 +4306,6 @@ static void zvni_deref_ip2mac(zebra_vni_t *zvni, zebra_mac_t *mac)
static void zvni_read_mac_neigh(zebra_vni_t *zvni, struct interface *ifp)
{
struct zebra_ns *zns;
- struct zebra_vrf *zvrf;
struct zebra_if *zif;
struct interface *vlan_if;
struct zebra_l2info_vxlan *vxl;
@@ -4027,10 +4313,7 @@ static void zvni_read_mac_neigh(zebra_vni_t *zvni, struct interface *ifp)
zif = ifp->info;
vxl = &zif->l2info.vxl;
- zvrf = zebra_vrf_lookup_by_id(zvni->vrf_id);
- if (!zvrf || !zvrf->zns)
- return;
- zns = zvrf->zns;
+ zns = zebra_ns_lookup(NS_DEFAULT);
if (IS_ZEBRA_DEBUG_VXLAN)
zlog_debug(
@@ -4075,7 +4358,7 @@ static bool vni_hash_cmp(const void *p1, const void *p2)
return (zvni1->vni == zvni2->vni);
}
-static int vni_list_cmp(void *p1, void *p2)
+int vni_list_cmp(void *p1, void *p2)
{
const zebra_vni_t *zvni1 = p1;
const zebra_vni_t *zvni2 = p2;
@@ -4101,7 +4384,7 @@ static void *zvni_alloc(void *p)
/*
* Look up VNI hash entry.
*/
-static zebra_vni_t *zvni_lookup(vni_t vni)
+zebra_vni_t *zvni_lookup(vni_t vni)
{
struct zebra_vrf *zvrf;
zebra_vni_t tmp_vni;
@@ -4132,6 +4415,8 @@ static zebra_vni_t *zvni_add(vni_t vni)
zvni = hash_get(zvrf->vni_table, &tmp_zvni, zvni_alloc);
assert(zvni);
+ zebra_evpn_vni_es_init(zvni);
+
/* Create hash table for MAC */
zvni->mac_table =
hash_create(mac_hash_keymake, mac_cmp, "Zebra VNI MAC Table");
@@ -4143,6 +4428,30 @@ static zebra_vni_t *zvni_add(vni_t vni)
return zvni;
}
+/* vni<=>vxlan_zif association */
+static void zvni_vxlan_if_set(zebra_vni_t *zvni, struct interface *ifp,
+ bool set)
+{
+ struct zebra_if *zif;
+
+ if (set) {
+ if (zvni->vxlan_if == ifp)
+ return;
+ zvni->vxlan_if = ifp;
+ } else {
+ if (!zvni->vxlan_if)
+ return;
+ zvni->vxlan_if = NULL;
+ }
+
+ if (ifp)
+ zif = ifp->info;
+ else
+ zif = NULL;
+
+ zebra_evpn_vxl_vni_set(zif, zvni, set);
+}
+
/*
* Delete VNI hash entry.
*/
@@ -4154,7 +4463,7 @@ static int zvni_del(zebra_vni_t *zvni)
zvrf = zebra_vrf_get_evpn();
assert(zvrf);
- zvni->vxlan_if = NULL;
+ zvni_vxlan_if_set(zvni, zvni->vxlan_if, false /* set */);
/* Remove references to the BUM mcast grp */
zebra_vxlan_sg_deref(zvni->local_vtep_ip, zvni->mcast_grp);
@@ -4167,6 +4476,8 @@ static int zvni_del(zebra_vni_t *zvni)
hash_free(zvni->mac_table);
zvni->mac_table = NULL;
+ zebra_evpn_vni_es_cleanup(zvni);
+
/* Free the VNI hash entry and allocated memory. */
tmp_zvni = hash_release(zvrf->vni_table, zvni);
XFREE(MTYPE_ZVNI, tmp_zvni);
@@ -4181,6 +4492,7 @@ static int zvni_send_add_to_client(zebra_vni_t *zvni)
{
struct zserv *client;
struct stream *s;
+ int rc;
client = zserv_find_client(ZEBRA_ROUTE_BGP, 0);
/* BGP may not be running. */
@@ -4205,13 +4517,22 @@ static int zvni_send_add_to_client(zebra_vni_t *zvni)
zebra_route_string(client->proto));
client->vniadd_cnt++;
- return zserv_send_message(client, s);
+ rc = zserv_send_message(client, s);
+
+ if (!(zvni->flags & ZVNI_READY_FOR_BGP)) {
+ zvni->flags |= ZVNI_READY_FOR_BGP;
+ /* once the VNI is sent the ES-EVIs can also be replayed
+ * to BGP
+ */
+ zebra_evpn_vni_update_all_es(zvni);
+ }
+ return rc;
}
/*
* Inform BGP about local VNI deletion.
*/
-static int zvni_send_del_to_client(vni_t vni)
+static int zvni_send_del_to_client(zebra_vni_t *zvni)
{
struct zserv *client;
struct stream *s;
@@ -4221,38 +4542,41 @@ static int zvni_send_del_to_client(vni_t vni)
if (!client)
return 0;
+ if (zvni->flags & ZVNI_READY_FOR_BGP) {
+ zvni->flags &= ~ZVNI_READY_FOR_BGP;
+ /* the ES-EVIs must be removed from BGP before the VNI is */
+ zebra_evpn_vni_update_all_es(zvni);
+ }
+
s = stream_new(ZEBRA_MAX_PACKET_SIZ);
stream_reset(s);
zclient_create_header(s, ZEBRA_VNI_DEL, zebra_vrf_get_evpn_id());
- stream_putl(s, vni);
+ stream_putl(s, zvni->vni);
/* Write packet size. */
stream_putw_at(s, 0, stream_get_endp(s));
if (IS_ZEBRA_DEBUG_VXLAN)
- zlog_debug("Send VNI_DEL %u to %s", vni,
+ zlog_debug("Send VNI_DEL %u to %s", zvni->vni,
zebra_route_string(client->proto));
client->vnidel_cnt++;
return zserv_send_message(client, s);
}
-static int zvni_build_hash_table_ns(struct ns *ns,
- void *param_in __attribute__((unused)),
- void **param_out __attribute__((unused)))
+/*
+ * Build the VNI hash table by going over the VxLAN interfaces. This
+ * is called when EVPN (advertise-all-vni) is enabled.
+ */
+static void zvni_build_hash_table(void)
{
- struct zebra_ns *zns = ns->info;
+ struct zebra_ns *zns;
struct route_node *rn;
struct interface *ifp;
- struct zebra_vrf *zvrf;
-
- zvrf = zebra_vrf_get_evpn();
-
- if (!zvrf)
- return NS_WALK_STOP;
/* Walk VxLAN interfaces and create VNI hash. */
+ zns = zebra_ns_lookup(NS_DEFAULT);
for (rn = route_top(zns->if_table); rn; rn = route_next(rn)) {
vni_t vni;
zebra_vni_t *zvni = NULL;
@@ -4269,14 +4593,7 @@ static int zvni_build_hash_table_ns(struct ns *ns,
vxl = &zif->l2info.vxl;
vni = vxl->vni;
- /* link of VXLAN interface should be in zebra_evpn_vrf */
- if (zvrf->zns->ns_id != vxl->link_nsid) {
- if (IS_ZEBRA_DEBUG_VXLAN)
- zlog_debug(
- "Intf %s(%u) VNI %u, link not in same namespace than BGP EVPN core instance ",
- ifp->name, ifp->ifindex, vni);
- continue;
- }
+
/* L3-VNI and L2-VNI are handled seperately */
zl3vni = zl3vni_lookup(vni);
if (zl3vni) {
@@ -4345,7 +4662,7 @@ static int zvni_build_hash_table_ns(struct ns *ns,
zlog_debug(
"Failed to add VNI hash, IF %s(%u) L2-VNI %u",
ifp->name, ifp->ifindex, vni);
- return NS_WALK_CONTINUE;
+ return;
}
if (zvni->local_vtep_ip.s_addr !=
@@ -4359,8 +4676,12 @@ static int zvni_build_hash_table_ns(struct ns *ns,
vxl->mcast_grp);
zvni->local_vtep_ip = vxl->vtep_ip;
zvni->mcast_grp = vxl->mcast_grp;
+ /* on local vtep-ip check if ES
+ * orig-ip needs to be updated
+ */
+ zebra_evpn_es_set_base_vni(zvni);
}
- zvni->vxlan_if = ifp;
+ zvni_vxlan_if_set(zvni, ifp, true /* set */);
vlan_if = zvni_map_to_svi(vxl->access_vlan,
zif->brslave_info.br_if);
if (vlan_if) {
@@ -4382,19 +4703,6 @@ static int zvni_build_hash_table_ns(struct ns *ns,
}
}
}
- return NS_WALK_CONTINUE;
-}
-
-/*
- * Build the VNI hash table by going over the VxLAN interfaces. This
- * is called when EVPN (advertise-all-vni) is enabled.
- */
-
-static void zvni_build_hash_table(void)
-{
- ns_walk_func(zvni_build_hash_table_ns,
- (void *)NULL,
- (void **)NULL);
}
/*
@@ -4720,8 +5028,9 @@ static int zl3vni_rmac_install(zebra_l3vni_t *zl3vni, zebra_mac_t *zrmac)
else
vid = 0;
- res = dplane_mac_add(zl3vni->vxlan_if, br_ifp, vid,
- &zrmac->macaddr, zrmac->fwd_info.r_vtep_ip, 0);
+ res = dplane_rem_mac_add(zl3vni->vxlan_if, br_ifp, vid,
+ &zrmac->macaddr, zrmac->fwd_info.r_vtep_ip, 0, 0,
+ false /*was_static*/);
if (res != ZEBRA_DPLANE_REQUEST_FAILURE)
return 0;
else
@@ -4770,7 +5079,7 @@ static int zl3vni_rmac_uninstall(zebra_l3vni_t *zl3vni, zebra_mac_t *zrmac)
else
vid = 0;
- res = dplane_mac_del(zl3vni->vxlan_if, br_ifp, vid,
+ res = dplane_rem_mac_del(zl3vni->vxlan_if, br_ifp, vid,
&zrmac->macaddr, zrmac->fwd_info.r_vtep_ip);
if (res != ZEBRA_DPLANE_REQUEST_FAILURE)
return 0;
@@ -4949,7 +5258,8 @@ static int zl3vni_nh_install(zebra_l3vni_t *zl3vni, zebra_neigh_t *n)
if (n->flags & ZEBRA_NEIGH_ROUTER_FLAG)
flags |= DPLANE_NTF_ROUTER;
- dplane_neigh_add(zl3vni->svi_if, &n->ip, &n->emac, flags);
+ dplane_rem_neigh_add(zl3vni->svi_if, &n->ip, &n->emac, flags,
+ false /*was_static*/);
return ret;
}
@@ -4966,7 +5276,7 @@ static int zl3vni_nh_uninstall(zebra_l3vni_t *zl3vni, zebra_neigh_t *n)
if (!zl3vni->svi_if || !if_is_operative(zl3vni->svi_if))
return 0;
- dplane_neigh_delete(zl3vni->svi_if, &n->ip);
+ dplane_rem_neigh_delete(zl3vni->svi_if, &n->ip);
return 0;
}
@@ -5110,7 +5420,7 @@ static void *zl3vni_alloc(void *p)
/*
* Look up L3 VNI hash entry.
*/
-static zebra_l3vni_t *zl3vni_lookup(vni_t vni)
+zebra_l3vni_t *zl3vni_lookup(vni_t vni)
{
zebra_l3vni_t tmp_l3vni;
zebra_l3vni_t *zl3vni = NULL;
@@ -5179,22 +5489,14 @@ static int zl3vni_del(zebra_l3vni_t *zl3vni)
return 0;
}
-static int zl3vni_map_to_vxlan_if_ns(struct ns *ns,
- void *_zl3vni,
- void **_pifp)
+struct interface *zl3vni_map_to_vxlan_if(zebra_l3vni_t *zl3vni)
{
- struct zebra_ns *zns = ns->info;
- zebra_l3vni_t *zl3vni = (zebra_l3vni_t *)_zl3vni;
+ struct zebra_ns *zns = NULL;
struct route_node *rn = NULL;
struct interface *ifp = NULL;
- struct zebra_vrf *zvrf;
-
- zvrf = zebra_vrf_get_evpn();
-
- if (!zvrf)
- return NS_WALK_STOP;
/* loop through all vxlan-interface */
+ zns = zebra_ns_lookup(NS_DEFAULT);
for (rn = route_top(zns->if_table); rn; rn = route_next(rn)) {
struct zebra_if *zif = NULL;
@@ -5209,38 +5511,13 @@ static int zl3vni_map_to_vxlan_if_ns(struct ns *ns,
continue;
vxl = &zif->l2info.vxl;
- if (vxl->vni != zl3vni->vni)
- continue;
-
- /* link of VXLAN interface should be in zebra_evpn_vrf */
- if (zvrf->zns->ns_id != vxl->link_nsid) {
- if (IS_ZEBRA_DEBUG_VXLAN)
- zlog_debug(
- "Intf %s(%u) VNI %u, link not in same namespace than BGP EVPN core instance ",
- ifp->name, ifp->ifindex, vxl->vni);
- continue;
+ if (vxl->vni == zl3vni->vni) {
+ zl3vni->local_vtep_ip = vxl->vtep_ip;
+ return ifp;
}
-
-
- zl3vni->local_vtep_ip = vxl->vtep_ip;
- if (_pifp)
- *_pifp = (void *)ifp;
- return NS_WALK_STOP;
}
- return NS_WALK_CONTINUE;
-}
-
-struct interface *zl3vni_map_to_vxlan_if(zebra_l3vni_t *zl3vni)
-{
- struct interface **p_ifp;
- struct interface *ifp = NULL;
-
- p_ifp = &ifp;
-
- ns_walk_func(zl3vni_map_to_vxlan_if_ns,
- (void *)zl3vni, (void **)p_ifp);
- return ifp;
+ return NULL;
}
struct interface *zl3vni_map_to_svi_if(zebra_l3vni_t *zl3vni)
@@ -5525,7 +5802,7 @@ static int zebra_vxlan_handle_vni_transition(struct zebra_vrf *zvrf, vni_t vni,
zlog_debug("Del L2-VNI %u - transition to L3-VNI", vni);
/* Delete VNI from BGP. */
- zvni_send_del_to_client(zvni->vni);
+ zvni_send_del_to_client(zvni);
/* Free up all neighbors and MAC, if any. */
zvni_neigh_del_all(zvni, 0, 0, DEL_ALL_NEIGH);
@@ -5633,6 +5910,1167 @@ static int zebra_vxlan_readd_remote_rmac(zebra_l3vni_t *zl3vni,
return 0;
}
+/**************************** SYNC MAC handling *****************************/
+/* if the mac has been added of a mac-route from the peer
+ * or if it is being referenced by a neigh added by the
+ * peer we cannot let it age out i.e. we set the static bit
+ * in the dataplane
+ */
+static inline bool zebra_vxlan_mac_is_static(zebra_mac_t *mac)
+{
+ return ((mac->flags & ZEBRA_MAC_ALL_PEER_FLAGS) ||
+ mac->sync_neigh_cnt);
+}
+
+/* mac needs to be locally active or active on an ES peer */
+static inline bool zebra_vxlan_mac_is_ready_for_bgp(uint32_t flags)
+{
+ return (flags & ZEBRA_MAC_LOCAL) &&
+ (!(flags & ZEBRA_MAC_LOCAL_INACTIVE) ||
+ (flags & ZEBRA_MAC_ES_PEER_ACTIVE));
+}
+
+/* program sync mac flags in the dataplane */
+void zebra_vxlan_sync_mac_dp_install(zebra_mac_t *mac, bool set_inactive,
+ bool force_clear_static, const char *caller)
+{
+ char macbuf[ETHER_ADDR_STRLEN];
+ struct interface *ifp;
+ bool sticky;
+ bool set_static;
+ zebra_vni_t *zvni = mac->zvni;
+ vlanid_t vid;
+ struct zebra_if *zif;
+ struct interface *br_ifp;
+
+ /* get the access vlan from the vxlan_device */
+ zebra_vxlan_mac_get_access_info(mac,
+ &ifp, &vid);
+
+ if (!ifp) {
+ if (IS_ZEBRA_DEBUG_EVPN_MH_MAC)
+ zlog_debug("%s: dp-install sync-mac vni %u mac %s es %s 0x%x %sskipped, no access-port",
+ caller,
+ zvni->vni,
+ prefix_mac2str(&mac->macaddr, macbuf,
+ sizeof(macbuf)),
+ mac->es ?
+ mac->es->esi_str : "-",
+ mac->flags,
+ set_inactive ? "inactive " : "");
+ return;
+ }
+
+ zif = ifp->info;
+ br_ifp = zif->brslave_info.br_if;
+ if (!br_ifp) {
+ if (IS_ZEBRA_DEBUG_EVPN_MH_MAC)
+ zlog_debug("%s: dp-install sync-mac vni %u mac %s es %s 0x%x %sskipped, no br",
+ caller,
+ zvni->vni,
+ prefix_mac2str(&mac->macaddr, macbuf,
+ sizeof(macbuf)),
+ mac->es ?
+ mac->es->esi_str : "-",
+ mac->flags,
+ set_inactive ? "inactive " : "");
+ return;
+ }
+
+ sticky = !!CHECK_FLAG(mac->flags, ZEBRA_MAC_STICKY);
+ if (force_clear_static)
+ set_static = false;
+ else
+ set_static = zebra_vxlan_mac_is_static(mac);
+
+ if (IS_ZEBRA_DEBUG_EVPN_MH_MAC)
+ zlog_debug("dp-install sync-mac vni %u mac %s es %s 0x%x %s%s",
+ zvni->vni,
+ prefix_mac2str(&mac->macaddr, macbuf,
+ sizeof(macbuf)),
+ mac->es ?
+ mac->es->esi_str : "-", mac->flags,
+ set_static ? "static " : "",
+ set_inactive ? "inactive " : "");
+
+ dplane_local_mac_add(ifp, br_ifp, vid, &mac->macaddr, sticky,
+ set_static, set_inactive);
+
+}
+
+static void zebra_vxlan_mac_send_add_del_to_client(zebra_mac_t *mac,
+ bool old_bgp_ready, bool new_bgp_ready)
+{
+ if (new_bgp_ready)
+ zvni_mac_send_add_to_client(mac->zvni->vni,
+ &mac->macaddr, mac->flags,
+ mac->loc_seq, mac->es);
+ else if (old_bgp_ready)
+ zvni_mac_send_del_to_client(mac->zvni->vni,
+ &mac->macaddr, mac->flags,
+ true /* force */);
+}
+
+/* MAC hold timer is used to age out peer-active flag.
+ *
+ * During this wait time we expect the dataplane component or an
+ * external neighmgr daemon to probe existing hosts to independently
+ * establish their presence on the ES.
+ */
+static int zebra_vxlan_mac_hold_exp_cb(struct thread *t)
+{
+ zebra_mac_t *mac;
+ bool old_bgp_ready;
+ bool new_bgp_ready;
+ bool old_static;
+ bool new_static;
+ char macbuf[ETHER_ADDR_STRLEN];
+
+ mac = THREAD_ARG(t);
+ /* the purpose of the hold timer is to age out the peer-active
+ * flag
+ */
+ if (!CHECK_FLAG(mac->flags, ZEBRA_MAC_ES_PEER_ACTIVE))
+ return 0;
+
+ old_bgp_ready = zebra_vxlan_mac_is_ready_for_bgp(mac->flags);
+ old_static = zebra_vxlan_mac_is_static(mac);
+ UNSET_FLAG(mac->flags, ZEBRA_MAC_ES_PEER_ACTIVE);
+ new_bgp_ready = zebra_vxlan_mac_is_ready_for_bgp(mac->flags);
+ new_static = zebra_vxlan_mac_is_static(mac);
+
+ if (IS_ZEBRA_DEBUG_EVPN_MH_MAC)
+ zlog_debug("sync-mac vni %u mac %s es %s 0x%x hold expired",
+ mac->zvni->vni,
+ prefix_mac2str(&mac->macaddr, macbuf,
+ sizeof(macbuf)),
+ mac->es ?
+ mac->es->esi_str : "-",
+ mac->flags);
+
+ /* re-program the local mac in the dataplane if the mac is no
+ * longer static
+ */
+ if (old_static != new_static)
+ zebra_vxlan_sync_mac_dp_install(mac, false /* set_inactive */,
+ false /* force_clear_static */, __func__);
+
+ /* inform bgp if needed */
+ if (old_bgp_ready != new_bgp_ready)
+ zebra_vxlan_mac_send_add_del_to_client(mac,
+ old_bgp_ready, new_bgp_ready);
+
+ return 0;
+}
+
+static inline void zebra_vxlan_mac_start_hold_timer(zebra_mac_t *mac)
+{
+ char macbuf[ETHER_ADDR_STRLEN];
+
+ if (mac->hold_timer)
+ return;
+
+ if (IS_ZEBRA_DEBUG_EVPN_MH_MAC)
+ zlog_debug("sync-mac vni %u mac %s es %s 0x%x hold started",
+ mac->zvni->vni,
+ prefix_mac2str(&mac->macaddr, macbuf,
+ sizeof(macbuf)),
+ mac->es ?
+ mac->es->esi_str : "-",
+ mac->flags);
+ thread_add_timer(zrouter.master,
+ zebra_vxlan_mac_hold_exp_cb,
+ mac, zmh_info->mac_hold_time,
+ &mac->hold_timer);
+}
+
+static inline void zebra_vxlan_mac_stop_hold_timer(zebra_mac_t *mac)
+{
+ char macbuf[ETHER_ADDR_STRLEN];
+
+ if (!mac->hold_timer)
+ return;
+
+ if (IS_ZEBRA_DEBUG_EVPN_MH_MAC)
+ zlog_debug("sync-mac vni %u mac %s es %s 0x%x hold stopped",
+ mac->zvni->vni,
+ prefix_mac2str(&mac->macaddr, macbuf,
+ sizeof(macbuf)),
+ mac->es ?
+ mac->es->esi_str : "-",
+ mac->flags);
+ THREAD_OFF(mac->hold_timer);
+}
+
+static inline void zebra_vxlan_mac_clear_sync_info(zebra_mac_t *mac)
+{
+ UNSET_FLAG(mac->flags, ZEBRA_MAC_ALL_PEER_FLAGS);
+ zebra_vxlan_mac_stop_hold_timer(mac);
+}
+
+static void zebra_vxlan_sync_mac_del(zebra_mac_t *mac)
+{
+ char macbuf[ETHER_ADDR_STRLEN];
+ bool old_static;
+ bool new_static;
+
+ if (IS_ZEBRA_DEBUG_EVPN_MH_MAC)
+ zlog_debug("sync-mac del vni %u mac %s es %s seq %d f 0x%x",
+ mac->zvni->vni,
+ prefix_mac2str(&mac->macaddr,
+ macbuf, sizeof(macbuf)),
+ mac->es ? mac->es->esi_str : "-",
+ mac->loc_seq,
+ mac->flags);
+ old_static = zebra_vxlan_mac_is_static(mac);
+ UNSET_FLAG(mac->flags, ZEBRA_MAC_ES_PEER_PROXY);
+ if (CHECK_FLAG(mac->flags, ZEBRA_MAC_ES_PEER_ACTIVE))
+ zebra_vxlan_mac_start_hold_timer(mac);
+ new_static = zebra_vxlan_mac_is_static(mac);
+
+ if (old_static != new_static)
+ /* program the local mac in the kernel */
+ zebra_vxlan_sync_mac_dp_install(mac, false /* set_inactive */,
+ false /* force_clear_static */, __func__);
+}
+
+static inline bool zebra_vxlan_mac_is_bgp_seq_ok(zebra_vni_t *zvni,
+ zebra_mac_t *mac, uint32_t seq, uint16_t ipa_len,
+ struct ipaddr *ipaddr)
+{
+ char macbuf[ETHER_ADDR_STRLEN];
+ char ipbuf[INET6_ADDRSTRLEN];
+ uint32_t tmp_seq;
+
+ if (CHECK_FLAG(mac->flags, ZEBRA_MAC_LOCAL))
+ tmp_seq = mac->loc_seq;
+ else
+ tmp_seq = mac->rem_seq;
+
+ if (seq < tmp_seq) {
+ /* if the mac was never advertised to bgp we must accept
+ * whatever sequence number bgp sends
+ * XXX - check with Vivek
+ */
+ if (CHECK_FLAG(mac->flags, ZEBRA_MAC_LOCAL) &&
+ !zebra_vxlan_mac_is_ready_for_bgp(mac->flags)) {
+ if (IS_ZEBRA_DEBUG_EVPN_MH_MAC)
+ zlog_debug("sync-macip accept vni %u mac %s%s%s lower seq %u f 0x%x",
+ zvni->vni,
+ prefix_mac2str(&mac->macaddr,
+ macbuf, sizeof(macbuf)),
+ ipa_len ? " IP " : "",
+ ipa_len ?
+ ipaddr2str(ipaddr,
+ ipbuf, sizeof(ipbuf)) : "",
+ tmp_seq, mac->flags);
+ return true;
+ }
+
+ if (IS_ZEBRA_DEBUG_EVPN_MH_MAC)
+ zlog_debug("sync-macip ignore vni %u mac %s%s%s as existing has higher seq %u f 0x%x",
+ zvni->vni,
+ prefix_mac2str(&mac->macaddr,
+ macbuf, sizeof(macbuf)),
+ ipa_len ? " IP " : "",
+ ipa_len ?
+ ipaddr2str(ipaddr,
+ ipbuf, sizeof(ipbuf)) : "",
+ tmp_seq, mac->flags);
+ return false;
+ }
+
+ return true;
+}
+
+/* sync-path that is active on an ES peer */
+static zebra_mac_t *zebra_vxlan_proc_sync_mac_update(zebra_vni_t *zvni,
+ struct ethaddr *macaddr, uint16_t ipa_len,
+ struct ipaddr *ipaddr, uint8_t flags,
+ uint32_t seq, esi_t *esi,
+ struct sync_mac_ip_ctx *ctx)
+{
+ zebra_mac_t *mac;
+ bool inform_bgp = false;
+ bool inform_dataplane = false;
+ bool seq_change = false;
+ bool es_change = false;
+ uint32_t tmp_seq;
+ char macbuf[ETHER_ADDR_STRLEN];
+ char ipbuf[INET6_ADDRSTRLEN];
+ bool old_local = false;
+ bool old_bgp_ready;
+ bool new_bgp_ready;
+
+ mac = zvni_mac_lookup(zvni, macaddr);
+ if (!mac) {
+ /* if it is a new local path we need to inform both
+ * the control protocol and the data-plane
+ */
+ inform_bgp = true;
+ inform_dataplane = true;
+ ctx->mac_created = true;
+ ctx->mac_inactive = true;
+
+ /* create the MAC and associate it with the dest ES */
+ mac = zvni_mac_add(zvni, macaddr);
+ zebra_evpn_es_mac_ref(mac, esi);
+
+ /* local mac activated by an ES peer */
+ SET_FLAG(mac->flags, ZEBRA_MAC_LOCAL);
+ /* if mac-only route setup peer flags */
+ if (!ipa_len) {
+ if (CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_PROXY_ADVERT))
+ SET_FLAG(mac->flags, ZEBRA_MAC_ES_PEER_PROXY);
+ else
+ SET_FLAG(mac->flags, ZEBRA_MAC_ES_PEER_ACTIVE);
+ }
+ SET_FLAG(mac->flags, ZEBRA_MAC_LOCAL_INACTIVE);
+ old_bgp_ready = false;
+ new_bgp_ready = zebra_vxlan_mac_is_ready_for_bgp(mac->flags);
+ } else {
+ uint32_t old_flags;
+ uint32_t new_flags;
+ bool old_static;
+ bool new_static;
+ bool sticky;
+ bool remote_gw;
+
+ old_flags = mac->flags;
+ sticky = !!CHECK_FLAG(old_flags, ZEBRA_MAC_STICKY);
+ remote_gw = !!CHECK_FLAG(old_flags, ZEBRA_MAC_REMOTE_DEF_GW);
+ if (sticky || remote_gw) {
+ if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH)
+ zlog_debug("Ignore sync-macip vni %u mac %s%s%s%s%s",
+ zvni->vni,
+ prefix_mac2str(macaddr,
+ macbuf, sizeof(macbuf)),
+ ipa_len ? " IP " : "",
+ ipa_len ?
+ ipaddr2str(ipaddr, ipbuf,
+ sizeof(ipbuf)) : "",
+ sticky ? " sticky" : "",
+ remote_gw ? " remote_gw" : "");
+ ctx->ignore_macip = true;
+ return NULL;
+ }
+ if (!zebra_vxlan_mac_is_bgp_seq_ok(zvni, mac, seq,
+ ipa_len, ipaddr)) {
+ ctx->ignore_macip = true;
+ return NULL;
+ }
+
+ old_local = !!CHECK_FLAG(old_flags, ZEBRA_MAC_LOCAL);
+ old_static = zebra_vxlan_mac_is_static(mac);
+
+ /* re-build the mac flags */
+ new_flags = 0;
+ SET_FLAG(new_flags, ZEBRA_MAC_LOCAL);
+ /* retain old local activity flag */
+ if (old_flags & ZEBRA_MAC_LOCAL) {
+ new_flags |= (old_flags & ZEBRA_MAC_LOCAL_INACTIVE);
+ } else {
+ new_flags |= ZEBRA_MAC_LOCAL_INACTIVE;
+ ctx->mac_inactive = true;
+ }
+ if (ipa_len) {
+ /* if mac-ip route do NOT update the peer flags
+ * i.e. retain only flags as is
+ */
+ new_flags |= (old_flags & ZEBRA_MAC_ALL_PEER_FLAGS);
+ } else {
+ /* if mac-only route update peer flags */
+ if (CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_PROXY_ADVERT)) {
+ SET_FLAG(new_flags, ZEBRA_MAC_ES_PEER_PROXY);
+ /* if the mac was peer-active previously we
+ * need to keep the flag and start the
+ * holdtimer on it. the peer-active flag is
+ * cleared on holdtimer expiry.
+ */
+ if (CHECK_FLAG(old_flags,
+ ZEBRA_MAC_ES_PEER_ACTIVE)) {
+ SET_FLAG(new_flags,
+ ZEBRA_MAC_ES_PEER_ACTIVE);
+ zebra_vxlan_mac_start_hold_timer(mac);
+ }
+ } else {
+ SET_FLAG(new_flags, ZEBRA_MAC_ES_PEER_ACTIVE);
+ /* stop hold timer if a peer has verified
+ * reachability
+ */
+ zebra_vxlan_mac_stop_hold_timer(mac);
+ }
+ }
+ mac->rem_seq = 0;
+ memset(&mac->fwd_info, 0, sizeof(mac->fwd_info));
+ mac->flags = new_flags;
+
+ if (IS_ZEBRA_DEBUG_EVPN_MH_MAC &&
+ (old_flags != new_flags))
+ zlog_debug("sync-mac vni %u mac %s old_f 0x%x new_f 0x%x",
+ zvni->vni,
+ prefix_mac2str(macaddr,
+ macbuf, sizeof(macbuf)),
+ old_flags, mac->flags);
+
+ /* update es */
+ es_change = zebra_evpn_es_mac_ref(mac, esi);
+ /* if mac dest change - inform both sides */
+ if (es_change) {
+ inform_bgp = true;
+ inform_dataplane = true;
+ ctx->mac_inactive = true;
+ }
+ /* if peer-flag is being set notify dataplane that the
+ * entry must not be expired because of local inactivity
+ */
+ new_static = zebra_vxlan_mac_is_static(mac);
+ if (old_static != new_static)
+ inform_dataplane = true;
+
+ old_bgp_ready = zebra_vxlan_mac_is_ready_for_bgp(old_flags);
+ new_bgp_ready = zebra_vxlan_mac_is_ready_for_bgp(mac->flags);
+ if (old_bgp_ready != new_bgp_ready)
+ inform_bgp = true;
+ }
+
+
+ /* update sequence number; if that results in a new local sequence
+ * inform bgp
+ */
+ tmp_seq = MAX(mac->loc_seq, seq);
+ if (tmp_seq != mac->loc_seq) {
+ mac->loc_seq = tmp_seq;
+ seq_change = true;
+ inform_bgp = true;
+ }
+
+ if (IS_ZEBRA_DEBUG_EVPN_MH_MAC)
+ zlog_debug("sync-mac %s vni %u mac %s es %s seq %d f 0x%x%s%s",
+ ctx->mac_created ?
+ "created" : "updated",
+ zvni->vni,
+ prefix_mac2str(macaddr,
+ macbuf, sizeof(macbuf)),
+ mac->es ? mac->es->esi_str : "-",
+ mac->loc_seq, mac->flags,
+ inform_bgp ? " inform_bgp" : "",
+ inform_dataplane ? " inform_dp" : "");
+
+ if (inform_bgp)
+ zebra_vxlan_mac_send_add_del_to_client(mac,
+ old_bgp_ready, new_bgp_ready);
+
+ /* neighs using the mac may need to be re-sent to
+ * bgp with updated info
+ */
+ if (seq_change || es_change || !old_local)
+ zvni_process_neigh_on_local_mac_change(zvni, mac,
+ seq_change, es_change);
+
+ if (inform_dataplane) {
+ if (ipa_len)
+ /* if the mac is being created as a part of MAC-IP
+ * route wait for the neigh to be updated or
+ * created before programming the mac
+ */
+ ctx->mac_dp_update_deferred = true;
+ else
+ /* program the local mac in the kernel. when the ES
+ * change we need to force the dataplane to reset
+ * the activity as we are yet to establish activity
+ * locally
+ */
+ zebra_vxlan_sync_mac_dp_install(mac,
+ ctx->mac_inactive,
+ false /* force_clear_static */,
+ __func__);
+ }
+
+ return mac;
+}
+
+/**************************** SYNC neigh handling **************************/
+static inline bool zebra_vxlan_neigh_is_static(zebra_neigh_t *neigh)
+{
+ return !!(neigh->flags & ZEBRA_NEIGH_ALL_PEER_FLAGS);
+}
+
+static inline bool zebra_vxlan_neigh_is_ready_for_bgp(zebra_neigh_t *n)
+{
+ bool mac_ready;
+ bool neigh_ready;
+
+ mac_ready = !!(n->mac->flags & ZEBRA_MAC_LOCAL);
+ neigh_ready = ((n->flags & ZEBRA_NEIGH_LOCAL) &&
+ IS_ZEBRA_NEIGH_ACTIVE(n) &&
+ (!(n->flags & ZEBRA_NEIGH_LOCAL_INACTIVE) ||
+ (n->flags & ZEBRA_NEIGH_ES_PEER_ACTIVE))) ?
+ true : false;
+
+ return mac_ready && neigh_ready;
+}
+
+static void zebra_vxlan_sync_neigh_dp_install(zebra_neigh_t *n,
+ bool set_inactive, bool force_clear_static, const char *caller)
+{
+ char macbuf[ETHER_ADDR_STRLEN];
+ char ipbuf[INET6_ADDRSTRLEN];
+ struct zebra_ns *zns;
+ struct interface *ifp;
+ bool set_static;
+ bool set_router;
+
+ zns = zebra_ns_lookup(NS_DEFAULT);
+ ifp = if_lookup_by_index_per_ns(zns, n->ifindex);
+ if (!ifp) {
+ if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH)
+ zlog_debug("%s: dp-install sync-neigh vni %u ip %s mac %s if %d f 0x%x skipped",
+ caller, n->zvni->vni,
+ ipaddr2str(&n->ip, ipbuf, sizeof(ipbuf)),
+ prefix_mac2str(&n->emac, macbuf,
+ sizeof(macbuf)),
+ n->ifindex, n->flags);
+ return;
+ }
+
+ if (force_clear_static)
+ set_static = false;
+ else
+ set_static = zebra_vxlan_neigh_is_static(n);
+
+ set_router = !!CHECK_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG);
+
+ /* XXX - this will change post integration with the new kernel */
+ if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL_INACTIVE))
+ set_inactive = true;
+
+ if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH)
+ zlog_debug("%s: dp-install sync-neigh vni %u ip %s mac %s if %s(%d) f 0x%x%s%s%s",
+ caller, n->zvni->vni,
+ ipaddr2str(&n->ip, ipbuf, sizeof(ipbuf)),
+ prefix_mac2str(&n->emac, macbuf,
+ sizeof(macbuf)),
+ ifp->name, n->ifindex, n->flags,
+ set_router ? " router":"",
+ set_static ? " static":"",
+ set_inactive ? " inactive":"");
+ dplane_local_neigh_add(ifp, &n->ip,
+ &n->emac, set_router, set_static, set_inactive);
+}
+
+static void zebra_vxlan_neigh_send_add_del_to_client(zebra_neigh_t *n,
+ bool old_bgp_ready, bool new_bgp_ready)
+{
+ if (new_bgp_ready)
+ zvni_neigh_send_add_to_client(n->zvni->vni, &n->ip,
+ &n->emac, n->mac, n->flags, n->loc_seq);
+ else if (old_bgp_ready)
+ zvni_neigh_send_del_to_client(n->zvni->vni, &n->ip,
+ &n->emac, n->flags, n->state, true /*force*/);
+}
+
+/* if the static flag associated with the neigh changes we need
+ * to update the sync-neigh references against the MAC
+ * and inform the dataplane about the static flag changes.
+ */
+static void zebra_vxlan_sync_neigh_static_chg(zebra_neigh_t *n,
+ bool old_n_static, bool new_n_static,
+ bool defer_n_dp, bool defer_mac_dp,
+ const char *caller)
+{
+ zebra_mac_t *mac = n->mac;
+ bool old_mac_static;
+ bool new_mac_static;
+ char macbuf[ETHER_ADDR_STRLEN];
+ char ipbuf[INET6_ADDRSTRLEN];
+
+ if (old_n_static == new_n_static)
+ return;
+
+ /* update the neigh sync references in the dataplane. if
+ * the neigh is in the middle of updates the caller can
+ * request for a defer
+ */
+ if (!defer_n_dp)
+ zebra_vxlan_sync_neigh_dp_install(n, false /* set_inactive */,
+ false /* force_clear_static */, __func__);
+
+ if (!mac)
+ return;
+
+ /* update the mac sync ref cnt */
+ old_mac_static = zebra_vxlan_mac_is_static(mac);
+ if (new_n_static) {
+ ++mac->sync_neigh_cnt;
+ } else if (old_n_static) {
+ if (mac->sync_neigh_cnt)
+ --mac->sync_neigh_cnt;
+ }
+ new_mac_static = zebra_vxlan_mac_is_static(mac);
+
+ /* update the mac sync references in the dataplane */
+ if ((old_mac_static != new_mac_static) && !defer_mac_dp)
+ zebra_vxlan_sync_mac_dp_install(mac,
+ false /* set_inactive */,
+ false /* force_clear_static */,
+ __func__);
+
+ if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH)
+ zlog_debug("sync-neigh ref-chg vni %u ip %s mac %s f 0x%x %d%s%s%s%s by %s",
+ n->zvni->vni,
+ ipaddr2str(&n->ip, ipbuf, sizeof(ipbuf)),
+ prefix_mac2str(&n->emac, macbuf,
+ sizeof(macbuf)),
+ n->flags, mac->sync_neigh_cnt,
+ old_n_static ? " old_n_static" : "",
+ new_n_static ? " new_n_static" : "",
+ old_mac_static ? " old_mac_static" : "",
+ new_mac_static ? " new_mac_static" : "",
+ caller);
+}
+
+/* Neigh hold timer is used to age out peer-active flag.
+ *
+ * During this wait time we expect the dataplane component or an
+ * external neighmgr daemon to probe existing hosts to independently
+ * establish their presence on the ES.
+ */
+static int zebra_vxlan_neigh_hold_exp_cb(struct thread *t)
+{
+ zebra_neigh_t *n;
+ bool old_bgp_ready;
+ bool new_bgp_ready;
+ bool old_n_static;
+ bool new_n_static;
+ char macbuf[ETHER_ADDR_STRLEN];
+ char ipbuf[INET6_ADDRSTRLEN];
+
+ n = THREAD_ARG(t);
+ /* the purpose of the hold timer is to age out the peer-active
+ * flag
+ */
+ if (!CHECK_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_ACTIVE))
+ return 0;
+
+ old_bgp_ready = zebra_vxlan_neigh_is_ready_for_bgp(n);
+ old_n_static = zebra_vxlan_neigh_is_static(n);
+ UNSET_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_ACTIVE);
+ new_bgp_ready = zebra_vxlan_neigh_is_ready_for_bgp(n);
+ new_n_static = zebra_vxlan_neigh_is_static(n);
+
+ if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH)
+ zlog_debug("sync-neigh vni %u ip %s mac %s 0x%x hold expired",
+ n->zvni->vni,
+ ipaddr2str(&n->ip, ipbuf, sizeof(ipbuf)),
+ prefix_mac2str(&n->emac, macbuf,
+ sizeof(macbuf)),
+ n->flags);
+
+ /* re-program the local neigh in the dataplane if the neigh is no
+ * longer static
+ */
+ if (old_n_static != new_n_static)
+ zebra_vxlan_sync_neigh_static_chg(n, old_n_static,
+ new_n_static, false /*defer_n_dp*/,
+ false /*defer_mac_dp*/, __func__);
+
+ /* inform bgp if needed */
+ if (old_bgp_ready != new_bgp_ready)
+ zebra_vxlan_neigh_send_add_del_to_client(n,
+ old_bgp_ready, new_bgp_ready);
+
+ return 0;
+}
+
+static inline void zebra_vxlan_neigh_start_hold_timer(zebra_neigh_t *n)
+{
+ char macbuf[ETHER_ADDR_STRLEN];
+ char ipbuf[INET6_ADDRSTRLEN];
+
+ if (n->hold_timer)
+ return;
+
+ if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH)
+ zlog_debug("sync-neigh vni %u ip %s mac %s 0x%x hold start",
+ n->zvni->vni,
+ ipaddr2str(&n->ip, ipbuf, sizeof(ipbuf)),
+ prefix_mac2str(&n->emac, macbuf,
+ sizeof(macbuf)),
+ n->flags);
+ thread_add_timer(zrouter.master,
+ zebra_vxlan_neigh_hold_exp_cb,
+ n, zmh_info->neigh_hold_time,
+ &n->hold_timer);
+}
+
+static inline void zebra_vxlan_neigh_stop_hold_timer(zebra_neigh_t *n)
+{
+ char macbuf[ETHER_ADDR_STRLEN];
+ char ipbuf[INET6_ADDRSTRLEN];
+
+ if (!n->hold_timer)
+ return;
+
+ if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH)
+ zlog_debug("sync-neigh vni %u ip %s mac %s 0x%x hold stop",
+ n->zvni->vni,
+ ipaddr2str(&n->ip, ipbuf, sizeof(ipbuf)),
+ prefix_mac2str(&n->emac, macbuf,
+ sizeof(macbuf)),
+ n->flags);
+ THREAD_OFF(n->hold_timer);
+}
+
+static inline bool zebra_vxlan_neigh_clear_sync_info(zebra_neigh_t *n)
+{
+ char macbuf[ETHER_ADDR_STRLEN];
+ char ipbuf[INET6_ADDRSTRLEN];
+ bool old_n_static = false;
+ bool new_n_static = false;
+
+ if (n->flags & ZEBRA_NEIGH_ALL_PEER_FLAGS) {
+ if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH)
+ zlog_debug("sync-neigh vni %u ip %s mac %s 0x%x clear",
+ n->zvni->vni,
+ ipaddr2str(&n->ip, ipbuf, sizeof(ipbuf)),
+ prefix_mac2str(&n->emac, macbuf,
+ sizeof(macbuf)),
+ n->flags);
+
+ old_n_static = zebra_vxlan_neigh_is_static(n);
+ UNSET_FLAG(n->flags, ZEBRA_NEIGH_ALL_PEER_FLAGS);
+ new_n_static = zebra_vxlan_neigh_is_static(n);
+ if (old_n_static != new_n_static)
+ zebra_vxlan_sync_neigh_static_chg(n, old_n_static,
+ new_n_static, true /*defer_dp)*/,
+ false/*defer_mac_dp*/, __func__);
+ }
+ zebra_vxlan_neigh_stop_hold_timer(n);
+
+ /* if the neigh static flag changed inform that a dp
+ * re-install maybe needed
+ */
+ return old_n_static != new_n_static;
+}
+
+static void zebra_vxlan_local_neigh_deref_mac(zebra_neigh_t *n,
+ bool send_mac_update)
+{
+ zebra_mac_t *mac = n->mac;
+ zebra_vni_t *zvni = n->zvni;
+ char macbuf[ETHER_ADDR_STRLEN];
+ char ipbuf[INET6_ADDRSTRLEN];
+ bool old_static;
+ bool new_static;
+
+ n->mac = NULL;
+ if (!mac)
+ return;
+
+ if ((n->flags & ZEBRA_NEIGH_ALL_PEER_FLAGS) &&
+ mac->sync_neigh_cnt){
+ old_static = zebra_vxlan_mac_is_static(mac);
+ --mac->sync_neigh_cnt;
+ new_static = zebra_vxlan_mac_is_static(mac);
+ if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH)
+ zlog_debug("sync-neigh deref mac vni %u ip %s mac %s ref %d",
+ n->zvni->vni,
+ ipaddr2str(&n->ip, ipbuf,
+ sizeof(ipbuf)),
+ prefix_mac2str(&n->emac, macbuf,
+ sizeof(macbuf)),
+ mac->sync_neigh_cnt);
+ if ((old_static != new_static) && send_mac_update)
+ /* program the local mac in the kernel */
+ zebra_vxlan_sync_mac_dp_install(mac,
+ false /* set_inactive */,
+ false /* force_clear_static */,
+ __func__);
+ }
+
+ listnode_delete(mac->neigh_list, n);
+ zvni_deref_ip2mac(zvni, mac);
+}
+
+static void zebra_vxlan_local_neigh_ref_mac(zebra_neigh_t *n,
+ struct ethaddr *macaddr, zebra_mac_t *mac,
+ bool send_mac_update)
+{
+ char macbuf[ETHER_ADDR_STRLEN];
+ char ipbuf[INET6_ADDRSTRLEN];
+ bool old_static;
+ bool new_static;
+
+ memcpy(&n->emac, macaddr, ETH_ALEN);
+ n->mac = mac;
+
+ /* Link to new MAC */
+ if (!mac)
+ return;
+
+ listnode_add_sort(mac->neigh_list, n);
+ if (n->flags & ZEBRA_NEIGH_ALL_PEER_FLAGS) {
+ old_static = zebra_vxlan_mac_is_static(mac);
+ ++mac->sync_neigh_cnt;
+ new_static = zebra_vxlan_mac_is_static(mac);
+ if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH)
+ zlog_debug("sync-neigh ref mac vni %u ip %s mac %s ref %d",
+ n->zvni->vni,
+ ipaddr2str(&n->ip, ipbuf,
+ sizeof(ipbuf)),
+ prefix_mac2str(&n->emac, macbuf,
+ sizeof(macbuf)),
+ mac->sync_neigh_cnt);
+ if ((old_static != new_static) && send_mac_update)
+ /* program the local mac in the kernel */
+ zebra_vxlan_sync_mac_dp_install(mac,
+ false /*set_inactive*/,
+ false /*force_clear_static*/,
+ __func__);
+ }
+}
+
+static inline bool zebra_vxlan_neigh_is_bgp_seq_ok(zebra_vni_t *zvni,
+ zebra_neigh_t *n, struct ethaddr *macaddr, uint32_t seq)
+{
+ char macbuf[ETHER_ADDR_STRLEN];
+ char ipbuf[INET6_ADDRSTRLEN];
+ uint32_t tmp_seq;
+
+ if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL))
+ tmp_seq = n->loc_seq;
+ else
+ tmp_seq = n->rem_seq;
+
+ if (seq < tmp_seq) {
+ /* if the neigh was never advertised to bgp we must accept
+ * whatever sequence number bgp sends
+ * XXX - check with Vivek
+ */
+ if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL) &&
+ !zebra_vxlan_neigh_is_ready_for_bgp(n)) {
+ if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH)
+ zlog_debug("sync-macip accept vni %u mac %s IP %s lower seq %u f 0x%x",
+ zvni->vni,
+ prefix_mac2str(macaddr,
+ macbuf, sizeof(macbuf)),
+ ipaddr2str(&n->ip,
+ ipbuf, sizeof(ipbuf)),
+ tmp_seq, n->flags);
+ return true;
+ }
+
+ if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH)
+ zlog_debug("sync-macip ignore vni %u mac %s IP %s as existing has higher seq %u f 0x%x",
+ zvni->vni,
+ prefix_mac2str(macaddr,
+ macbuf, sizeof(macbuf)),
+ ipaddr2str(&n->ip,
+ ipbuf, sizeof(ipbuf)),
+ tmp_seq, n->flags);
+ return false;
+ }
+
+ return true;
+}
+
+static void zebra_vxlan_sync_neigh_del(zebra_neigh_t *n)
+{
+ bool old_n_static;
+ bool new_n_static;
+ char macbuf[ETHER_ADDR_STRLEN];
+ char ipbuf[INET6_ADDRSTRLEN];
+
+ if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH)
+ zlog_debug("sync-neigh del vni %u ip %s mac %s f 0x%x",
+ n->zvni->vni,
+ ipaddr2str(&n->ip, ipbuf, sizeof(ipbuf)),
+ prefix_mac2str(&n->emac, macbuf,
+ sizeof(macbuf)),
+ n->flags);
+
+ old_n_static = zebra_vxlan_neigh_is_static(n);
+ UNSET_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_PROXY);
+ if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_ACTIVE))
+ zebra_vxlan_neigh_start_hold_timer(n);
+ new_n_static = zebra_vxlan_neigh_is_static(n);
+
+ if (old_n_static != new_n_static)
+ zebra_vxlan_sync_neigh_static_chg(n, old_n_static,
+ new_n_static, false /*defer-dp*/,
+ false /*defer_mac_dp*/, __func__);
+}
+
+static zebra_neigh_t *zebra_vxlan_proc_sync_neigh_update(zebra_vni_t *zvni,
+ zebra_neigh_t *n, uint16_t ipa_len,
+ struct ipaddr *ipaddr, uint8_t flags, uint32_t seq,
+ esi_t *esi, struct sync_mac_ip_ctx *ctx)
+{
+ struct interface *ifp = NULL;
+ bool is_router;
+ zebra_mac_t *mac = ctx->mac;
+ uint32_t tmp_seq;
+ bool old_router = false;
+ bool old_bgp_ready = false;
+ bool new_bgp_ready;
+ bool inform_dataplane = false;
+ bool inform_bgp = false;
+ bool old_mac_static;
+ bool new_mac_static;
+ bool set_dp_inactive = false;
+ struct zebra_if *zif;
+ char macbuf[ETHER_ADDR_STRLEN];
+ char ipbuf[INET6_ADDRSTRLEN];
+ bool created;
+ ifindex_t ifindex = 0;
+
+ /* locate l3-svi */
+ zif = zvni->vxlan_if->info;
+ if (zif) {
+ struct zebra_l2info_vxlan *vxl;
+
+ vxl = &zif->l2info.vxl;
+ ifp = zvni_map_to_svi(vxl->access_vlan,
+ zif->brslave_info.br_if);
+ if (ifp)
+ ifindex = ifp->ifindex;
+ }
+
+ is_router = !!CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_ROUTER_FLAG);
+ old_mac_static = zebra_vxlan_mac_is_static(mac);
+
+ if (!n) {
+ uint32_t n_flags = 0;
+
+ /* New neighbor - create */
+ SET_FLAG(n_flags, ZEBRA_NEIGH_LOCAL);
+ if (CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_PROXY_ADVERT))
+ SET_FLAG(n_flags, ZEBRA_NEIGH_ES_PEER_PROXY);
+ else
+ SET_FLAG(n_flags, ZEBRA_NEIGH_ES_PEER_ACTIVE);
+ SET_FLAG(n_flags, ZEBRA_NEIGH_LOCAL_INACTIVE);
+
+ n = zvni_neigh_add(zvni, ipaddr, &mac->macaddr, mac,
+ n_flags);
+ n->ifindex = ifindex;
+ ZEBRA_NEIGH_SET_ACTIVE(n);
+
+ created = true;
+ inform_dataplane = true;
+ inform_bgp = true;
+ set_dp_inactive = true;
+ } else {
+ bool mac_change;
+ uint32_t old_flags = n->flags;
+ bool old_n_static;
+ bool new_n_static;
+
+ created = false;
+ old_n_static = zebra_vxlan_neigh_is_static(n);
+ old_bgp_ready = zebra_vxlan_neigh_is_ready_for_bgp(n);
+ old_router = !!CHECK_FLAG(n->flags,
+ ZEBRA_NEIGH_ROUTER_FLAG);
+
+ mac_change = !!memcmp(&n->emac, &mac->macaddr, ETH_ALEN);
+
+ /* deref and clear old info */
+ if (mac_change) {
+ if (old_bgp_ready) {
+ zvni_neigh_send_del_to_client(zvni->vni, &n->ip,
+ &n->emac, n->flags, n->state,
+ false /*force*/);
+ old_bgp_ready = false;
+ }
+ if (n->mac)
+ zebra_vxlan_local_neigh_deref_mac(n,
+ false /*send_mac_update*/);
+ }
+ /* clear old fwd info */
+ n->rem_seq = 0;
+ n->r_vtep_ip.s_addr = 0;
+
+ /* setup new flags */
+ n->flags = 0;
+ SET_FLAG(n->flags, ZEBRA_NEIGH_LOCAL);
+ /* retain activity flag if the neigh was
+ * previously local
+ */
+ if (old_flags & ZEBRA_NEIGH_LOCAL) {
+ n->flags |= (old_flags & ZEBRA_NEIGH_LOCAL_INACTIVE);
+ } else {
+ inform_dataplane = true;
+ set_dp_inactive = true;
+ n->flags |= ZEBRA_NEIGH_LOCAL_INACTIVE;
+ }
+
+ if (CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_PROXY_ADVERT))
+ SET_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_PROXY);
+ else
+ SET_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_ACTIVE);
+
+ if (CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_PROXY_ADVERT)) {
+ SET_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_PROXY);
+ /* if the neigh was peer-active previously we
+ * need to keep the flag and start the
+ * holdtimer on it. the peer-active flag is
+ * cleared on holdtimer expiry.
+ */
+ if (CHECK_FLAG(old_flags,
+ ZEBRA_NEIGH_ES_PEER_ACTIVE)) {
+ SET_FLAG(n->flags,
+ ZEBRA_NEIGH_ES_PEER_ACTIVE);
+ zebra_vxlan_neigh_start_hold_timer(n);
+ }
+ } else {
+ SET_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_ACTIVE);
+ /* stop hold timer if a peer has verified
+ * reachability
+ */
+ zebra_vxlan_neigh_stop_hold_timer(n);
+ }
+ ZEBRA_NEIGH_SET_ACTIVE(n);
+
+ if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH &&
+ (old_flags != n->flags))
+ zlog_debug("sync-neigh vni %u ip %s mac %s old_f 0x%x new_f 0x%x",
+ n->zvni->vni,
+ ipaddr2str(&n->ip, ipbuf, sizeof(ipbuf)),
+ prefix_mac2str(&n->emac, macbuf,
+ sizeof(macbuf)),
+ old_flags, n->flags);
+
+ new_n_static = zebra_vxlan_neigh_is_static(n);
+ if (mac_change) {
+ set_dp_inactive = true;
+ n->flags |= ZEBRA_NEIGH_LOCAL_INACTIVE;
+ inform_dataplane = true;
+ zebra_vxlan_local_neigh_ref_mac(n, &mac->macaddr,
+ mac, false /*send_mac_update*/);
+ } else if (old_n_static != new_n_static) {
+ inform_dataplane = true;
+ /* if static flags have changed without a mac change
+ * we need to create the correct sync-refs against
+ * the existing mac
+ */
+ zebra_vxlan_sync_neigh_static_chg(n,
+ old_n_static, new_n_static,
+ true /*defer_dp*/, true /*defer_mac_dp*/,
+ __func__);
+ }
+
+ /* Update the forwarding info. */
+ if (n->ifindex != ifindex) {
+ n->ifindex = ifindex;
+ inform_dataplane = true;
+ }
+ }
+
+ /* update the neigh seq. we don't bother with the mac seq as
+ * sync_mac_update already took care of that
+ */
+ tmp_seq = MAX(n->loc_seq, seq);
+ if (tmp_seq != n->loc_seq) {
+ n->loc_seq = tmp_seq;
+ inform_bgp = true;
+ }
+
+ /* Mark Router flag (R-bit) */
+ if (is_router)
+ SET_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG);
+ else
+ UNSET_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG);
+
+ if (old_router != is_router)
+ inform_dataplane = true;
+
+ new_bgp_ready = zebra_vxlan_neigh_is_ready_for_bgp(n);
+ if (old_bgp_ready != new_bgp_ready)
+ inform_bgp = true;
+
+ new_mac_static = zebra_vxlan_mac_is_static(mac);
+ if ((old_mac_static != new_mac_static) ||
+ ctx->mac_dp_update_deferred)
+ zebra_vxlan_sync_mac_dp_install(mac,
+ ctx->mac_inactive,
+ false /* force_clear_static */,
+ __func__);
+
+ if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH)
+ zlog_debug("sync-neigh %s vni %u ip %s mac %s if %s(%d) seq %d f 0x%x%s%s",
+ created ?
+ "created" : "updated",
+ n->zvni->vni,
+ ipaddr2str(&n->ip, ipbuf, sizeof(ipbuf)),
+ prefix_mac2str(&n->emac, macbuf,
+ sizeof(macbuf)),
+ ifp ? ifp->name : "", ifindex,
+ n->loc_seq, n->flags,
+ inform_bgp ? " inform_bgp" : "",
+ inform_dataplane ? " inform_dp" : "");
+
+ if (inform_dataplane)
+ zebra_vxlan_sync_neigh_dp_install(n, set_dp_inactive,
+ false /* force_clear_static */, __func__);
+
+ if (inform_bgp)
+ zebra_vxlan_neigh_send_add_del_to_client(n,
+ old_bgp_ready, new_bgp_ready);
+
+ return n;
+}
+
+static void zebra_vxlan_process_sync_macip_add(zebra_vni_t *zvni,
+ struct ethaddr *macaddr,
+ uint16_t ipa_len,
+ struct ipaddr *ipaddr,
+ uint8_t flags,
+ uint32_t seq,
+ esi_t *esi)
+{
+ struct sync_mac_ip_ctx ctx;
+ char macbuf[ETHER_ADDR_STRLEN];
+ char ipbuf[INET6_ADDRSTRLEN];
+ bool sticky;
+ bool remote_gw;
+ zebra_neigh_t *n = NULL;
+
+ sticky = !!CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_STICKY);
+ remote_gw = !!CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_GW);
+ /* if sticky or remote-gw ignore updates from the peer */
+ if (sticky || remote_gw) {
+ if (IS_ZEBRA_DEBUG_VXLAN || IS_ZEBRA_DEBUG_EVPN_MH_NEIGH ||
+ IS_ZEBRA_DEBUG_EVPN_MH_MAC)
+ zlog_debug("Ignore sync-macip vni %u mac %s%s%s%s%s",
+ zvni->vni,
+ prefix_mac2str(macaddr, macbuf, sizeof(macbuf)),
+ ipa_len ? " IP " : "",
+ ipa_len ?
+ ipaddr2str(ipaddr, ipbuf, sizeof(ipbuf)) : "",
+ sticky ? " sticky" : "",
+ remote_gw ? " remote_gw" : "");
+ return;
+ }
+
+ if (ipa_len) {
+ n = zvni_neigh_lookup(zvni, ipaddr);
+ if (n &&
+ !zebra_vxlan_neigh_is_bgp_seq_ok(zvni,
+ n, macaddr, seq))
+ return;
+ }
+
+ memset(&ctx, 0, sizeof(ctx));
+ ctx.mac = zebra_vxlan_proc_sync_mac_update(zvni, macaddr, ipa_len,
+ ipaddr, flags, seq, esi, &ctx);
+ if (ctx.ignore_macip || !ctx.mac || !ipa_len)
+ return;
+
+ zebra_vxlan_proc_sync_neigh_update(zvni, n, ipa_len,
+ ipaddr, flags, seq, esi, &ctx);
+}
+
+/************************** remote mac-ip handling **************************/
/* Process a remote MACIP add from BGP. */
static void process_remote_macip_add(vni_t vni,
struct ethaddr *macaddr,
@@ -5640,7 +7078,8 @@ static void process_remote_macip_add(vni_t vni,
struct ipaddr *ipaddr,
uint8_t flags,
uint32_t seq,
- struct in_addr vtep_ip)
+ struct in_addr vtep_ip,
+ esi_t *esi)
{
zebra_vni_t *zvni;
zebra_vtep_t *zvtep;
@@ -5658,6 +7097,8 @@ static void process_remote_macip_add(vni_t vni,
bool is_router;
bool do_dad = false;
bool is_dup_detect = false;
+ esi_t *old_esi;
+ bool old_static = false;
/* Locate VNI hash entry - expected to exist. */
zvni = zvni_lookup(vni);
@@ -5678,22 +7119,36 @@ static void process_remote_macip_add(vni_t vni,
return;
}
+ /* Type-2 routes from another PE can be interpreted as remote or
+ * SYNC based on the destination ES -
+ * SYNC - if ES is local
+ * REMOTE - if ES is not local
+ */
+ if (flags & ZEBRA_MACIP_TYPE_SYNC_PATH) {
+ zebra_vxlan_process_sync_macip_add(zvni, macaddr, ipa_len,
+ ipaddr, flags, seq, esi);
+ return;
+ }
+
/* The remote VTEP specified should normally exist, but it is
* possible that when peering comes up, peer may advertise MACIP
* routes before advertising type-3 routes.
*/
- zvtep = zvni_vtep_find(zvni, &vtep_ip);
- if (!zvtep) {
- zvtep = zvni_vtep_add(zvni, &vtep_ip, VXLAN_FLOOD_DISABLED);
+ if (vtep_ip.s_addr) {
+ zvtep = zvni_vtep_find(zvni, &vtep_ip);
if (!zvtep) {
- flog_err(
- EC_ZEBRA_VTEP_ADD_FAILED,
- "Failed to add remote VTEP, VNI %u zvni %p upon remote MACIP ADD",
- vni, zvni);
- return;
- }
+ zvtep = zvni_vtep_add(zvni, &vtep_ip,
+ VXLAN_FLOOD_DISABLED);
+ if (!zvtep) {
+ flog_err(
+ EC_ZEBRA_VTEP_ADD_FAILED,
+ "Failed to add remote VTEP, VNI %u zvni %p upon remote MACIP ADD",
+ vni, zvni);
+ return;
+ }
- zvni_vtep_install(zvni, zvtep);
+ zvni_vtep_install(zvni, zvtep);
+ }
}
sticky = !!CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_STICKY);
@@ -5716,10 +7171,12 @@ static void process_remote_macip_add(vni_t vni,
return;
}
- zvrf = zebra_vrf_get_evpn();
+ zvrf = vrf_info_lookup(zvni->vxlan_if->vrf_id);
if (!zvrf)
return;
+ old_esi = (mac && mac->es) ? &mac->es->esi : zero_esi;
+
/* check if the remote MAC is unknown or has a change.
* If so, that needs to be updated first. Note that client could
* install MAC and MACIP separately or just install the latter.
@@ -5729,6 +7186,7 @@ static void process_remote_macip_add(vni_t vni,
|| sticky != !!CHECK_FLAG(mac->flags, ZEBRA_MAC_STICKY)
|| remote_gw != !!CHECK_FLAG(mac->flags, ZEBRA_MAC_REMOTE_DEF_GW)
|| !IPV4_ADDR_SAME(&mac->fwd_info.r_vtep_ip, &vtep_ip)
+ || memcmp(old_esi, esi, sizeof(esi_t))
|| seq != mac->rem_seq)
update_mac = 1;
@@ -5744,10 +7202,14 @@ static void process_remote_macip_add(vni_t vni,
return;
}
+ zebra_evpn_es_mac_ref(mac, esi);
+
/* Is this MAC created for a MACIP? */
if (ipa_len)
SET_FLAG(mac->flags, ZEBRA_MAC_AUTO);
} else {
+ zebra_evpn_es_mac_ref(mac, esi);
+
/* When host moves but changes its (MAC,IP)
* binding, BGP may install a MACIP entry that
* corresponds to "older" location of the host
@@ -5794,11 +7256,25 @@ static void process_remote_macip_add(vni_t vni,
do_dad = true;
/* Remove local MAC from BGP. */
- if (CHECK_FLAG(mac->flags, ZEBRA_MAC_LOCAL))
- zvni_mac_send_del_to_client(zvni->vni, macaddr);
+ if (CHECK_FLAG(mac->flags, ZEBRA_MAC_LOCAL)) {
+ /* force drop the sync flags */
+ old_static = zebra_vxlan_mac_is_static(mac);
+ if (IS_ZEBRA_DEBUG_EVPN_MH_MAC)
+ zlog_debug("sync-mac->remote vni %u mac %s es %s seq %d f 0x%x",
+ zvni->vni,
+ prefix_mac2str(macaddr,
+ buf, sizeof(buf)),
+ mac->es ?
+ mac->es->esi_str : "-",
+ mac->loc_seq,
+ mac->flags);
+ zebra_vxlan_mac_clear_sync_info(mac);
+ zvni_mac_send_del_to_client(zvni->vni, macaddr,
+ mac->flags, false /* force */);
+ }
/* Set "auto" and "remote" forwarding info. */
- UNSET_FLAG(mac->flags, ZEBRA_MAC_LOCAL);
+ UNSET_FLAG(mac->flags, ZEBRA_MAC_ALL_LOCAL_FLAGS);
memset(&mac->fwd_info, 0, sizeof(mac->fwd_info));
SET_FLAG(mac->flags, ZEBRA_MAC_REMOTE);
mac->fwd_info.r_vtep_ip = vtep_ip;
@@ -5821,7 +7297,7 @@ static void process_remote_macip_add(vni_t vni,
if (!is_dup_detect) {
zvni_process_neigh_on_remote_mac_add(zvni, mac);
/* Install the entry. */
- zvni_mac_install(zvni, mac);
+ zvni_rem_mac_install(zvni, mac, old_static);
}
}
@@ -5836,6 +7312,7 @@ static void process_remote_macip_add(vni_t vni,
/* Reset flag */
do_dad = false;
+ old_static = false;
/* Check if the remote neighbor itself is unknown or has a
* change. If so, create or update and then install the entry.
@@ -5851,7 +7328,7 @@ static void process_remote_macip_add(vni_t vni,
if (update_neigh) {
if (!n) {
- n = zvni_neigh_add(zvni, ipaddr, macaddr);
+ n = zvni_neigh_add(zvni, ipaddr, macaddr, mac, 0);
if (!n) {
zlog_warn(
"Failed to add Neigh %s MAC %s VNI %u Remote VTEP %s",
@@ -5893,22 +7370,31 @@ static void process_remote_macip_add(vni_t vni,
tmp_seq);
return;
}
+ if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL)) {
+ old_static = zebra_vxlan_neigh_is_static(n);
+ if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH)
+ zlog_debug("sync->remote neigh vni %u ip %s mac %s seq %d f0x%x",
+ n->zvni->vni,
+ ipaddr2str(&n->ip, buf1,
+ sizeof(buf1)),
+ prefix_mac2str(&n->emac, buf,
+ sizeof(buf)),
+ seq, n->flags);
+ zebra_vxlan_neigh_clear_sync_info(n);
+ if (IS_ZEBRA_NEIGH_ACTIVE(n))
+ zvni_mac_send_del_to_client(zvni->vni,
+ macaddr, mac->flags,
+ false /*force*/);
+ }
if (memcmp(&n->emac, macaddr, sizeof(*macaddr)) != 0) {
- /* MAC change, send a delete for old
- * neigh if learnt locally.
- */
- if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL) &&
- IS_ZEBRA_NEIGH_ACTIVE(n))
- zvni_neigh_send_del_to_client(
- zvni->vni, &n->ip,
- &n->emac, 0, n->state);
-
/* update neigh list for macs */
old_mac = zvni_mac_lookup(zvni, &n->emac);
if (old_mac) {
listnode_delete(old_mac->neigh_list, n);
+ n->mac = NULL;
zvni_deref_ip2mac(zvni, old_mac);
}
+ n->mac = mac;
listnode_add_sort(mac->neigh_list, n);
memcpy(&n->emac, macaddr, ETH_ALEN);
@@ -5934,7 +7420,7 @@ static void process_remote_macip_add(vni_t vni,
}
/* Set "remote" forwarding info. */
- UNSET_FLAG(n->flags, ZEBRA_NEIGH_LOCAL);
+ UNSET_FLAG(n->flags, ZEBRA_NEIGH_ALL_LOCAL_FLAGS);
n->r_vtep_ip = vtep_ip;
SET_FLAG(n->flags, ZEBRA_NEIGH_REMOTE);
@@ -5964,7 +7450,7 @@ static void process_remote_macip_add(vni_t vni,
false);
/* Install the entry. */
if (!is_dup_detect)
- zvni_neigh_install(zvni, n);
+ zvni_rem_neigh_install(zvni, n, old_static);
}
zvni_probe_neigh_on_mac_add(zvni, mac);
@@ -5973,6 +7459,32 @@ static void process_remote_macip_add(vni_t vni,
n->rem_seq = seq;
}
+static void zebra_vxlan_rem_mac_del(zebra_vni_t *zvni,
+ zebra_mac_t *mac)
+{
+ zvni_process_neigh_on_remote_mac_del(zvni, mac);
+ /* the remote sequence number in the auto mac entry
+ * needs to be reset to 0 as the mac entry may have
+ * been removed on all VTEPs (including
+ * the originating one)
+ */
+ mac->rem_seq = 0;
+
+ /* If all remote neighbors referencing a remote MAC
+ * go away, we need to uninstall the MAC.
+ */
+ if (remote_neigh_count(mac) == 0) {
+ zvni_rem_mac_uninstall(zvni, mac);
+ zebra_evpn_es_mac_deref_entry(mac);
+ UNSET_FLAG(mac->flags, ZEBRA_MAC_REMOTE);
+ }
+
+ if (list_isempty(mac->neigh_list))
+ zvni_mac_del(zvni, mac);
+ else
+ SET_FLAG(mac->flags, ZEBRA_MAC_AUTO);
+}
+
/* Process a remote MACIP delete from BGP. */
static void process_remote_macip_del(vni_t vni,
struct ethaddr *macaddr,
@@ -6014,11 +7526,6 @@ static void process_remote_macip_del(vni_t vni,
zns = zebra_ns_lookup(NS_DEFAULT);
vxl = &zif->l2info.vxl;
- /* It is possible remote vtep del request is processed prior to
- * remote macip route delete. remote_vtep_del does not clean up
- * the macip route delete. Explicite withdraw of the macip route
- * is expected to recieve. This handler removes the remote route.
- */
mac = zvni_mac_lookup(zvni, macaddr);
if (ipa_len)
n = zvni_neigh_lookup(zvni, ipaddr);
@@ -6077,11 +7584,14 @@ static void process_remote_macip_del(vni_t vni,
* "old" neighbor (as these are two different MACIP routes).
* Do the delete only if the MAC matches.
*/
- if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE)
- && (memcmp(n->emac.octet, macaddr->octet, ETH_ALEN) == 0)) {
- zvni_neigh_uninstall(zvni, n);
- zvni_neigh_del(zvni, n);
- zvni_deref_ip2mac(zvni, mac);
+ if (!memcmp(n->emac.octet, macaddr->octet, ETH_ALEN)) {
+ if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL)) {
+ zebra_vxlan_sync_neigh_del(n);
+ } else if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE)) {
+ zvni_neigh_uninstall(zvni, n);
+ zvni_neigh_del(zvni, n);
+ zvni_deref_ip2mac(zvni, mac);
+ }
}
} else {
/* DAD: when MAC is freeze state as remote learn event,
@@ -6104,27 +7614,11 @@ static void process_remote_macip_del(vni_t vni,
macaddr, vxl->access_vlan);
}
- if (CHECK_FLAG(mac->flags, ZEBRA_MAC_REMOTE)) {
- zvni_process_neigh_on_remote_mac_del(zvni, mac);
- /*
- * the remote sequence number in the auto mac entry
- * needs to be reset to 0 as the mac entry may have
- * been removed on all VTEPs (including
- * the originating one)
- */
- mac->rem_seq = 0;
-
- /* If all remote neighbors referencing a remote MAC
- * go away, we need to uninstall the MAC.
- */
- if (remote_neigh_count(mac) == 0) {
- zvni_mac_uninstall(zvni, mac);
- UNSET_FLAG(mac->flags, ZEBRA_MAC_REMOTE);
- }
- if (list_isempty(mac->neigh_list))
- zvni_mac_del(zvni, mac);
- else
- SET_FLAG(mac->flags, ZEBRA_MAC_AUTO);
+ if (CHECK_FLAG(mac->flags, ZEBRA_MAC_LOCAL)) {
+ if (!ipa_len)
+ zebra_vxlan_sync_mac_del(mac);
+ } else if (CHECK_FLAG(mac->flags, ZEBRA_NEIGH_REMOTE)) {
+ zebra_vxlan_rem_mac_del(zvni, mac);
}
}
}
@@ -6560,8 +8054,7 @@ void zebra_vxlan_print_neigh_vni(struct vty *vty, struct zebra_vrf *zvrf,
vty_out(vty,
"Number of ARPs (local and remote) known for this VNI: %u\n",
num_neigh);
- vty_out(vty, "%*s %-6s %-8s %-17s %-21s %s\n", -wctx.addr_width,
- "IP", "Type", "State", "MAC", "Remote VTEP", "Seq #'s");
+ zvni_print_neigh_hdr(vty, &wctx);
} else
json_object_int_add(json, "numArpNd", num_neigh);
@@ -6771,9 +8264,9 @@ void zebra_vxlan_print_neigh_vni_dad(struct vty *vty,
vty_out(vty,
"Number of ARPs (local and remote) known for this VNI: %u\n",
num_neigh);
- vty_out(vty, "%*s %-6s %-8s %-17s %-21s\n",
+ vty_out(vty, "%*s %-6s %-8s %-17s %-30s\n",
-wctx.addr_width, "IP", "Type",
- "State", "MAC", "Remote VTEP");
+ "State", "MAC", "Remote ES/VTEP");
} else
json_object_int_add(json, "numArpNd", num_neigh);
@@ -6826,8 +8319,11 @@ void zebra_vxlan_print_macs_vni(struct vty *vty, struct zebra_vrf *zvrf,
vty_out(vty,
"Number of MACs (local and remote) known for this VNI: %u\n",
num_macs);
- vty_out(vty, "%-17s %-6s %-21s %-5s %s\n", "MAC", "Type",
- "Intf/Remote VTEP", "VLAN", "Seq #'s");
+ vty_out(vty,
+ "Flags: N=sync-neighs, I=local-inactive, P=peer-active, X=peer-proxy\n");
+ vty_out(vty, "%-17s %-6s %-5s %-30s %-5s %s\n", "MAC",
+ "Type", "Flags", "Intf/Remote ES/VTEP",
+ "VLAN", "Seq #'s");
} else
json_object_int_add(json, "numMacs", num_macs);
@@ -7019,8 +8515,8 @@ void zebra_vxlan_print_macs_vni_dad(struct vty *vty,
vty_out(vty,
"Number of MACs (local and remote) known for this VNI: %u\n",
num_macs);
- vty_out(vty, "%-17s %-6s %-21s %-5s\n", "MAC", "Type",
- "Intf/Remote VTEP", "VLAN");
+ vty_out(vty, "%-17s %-6s %-5s %-30s %-5s\n", "MAC", "Type",
+ "Flags", "Intf/Remote ES/VTEP", "VLAN");
} else
json_object_int_add(json, "numMacs", num_macs);
@@ -7077,7 +8573,8 @@ int zebra_vxlan_clear_dup_detect_vni_mac(struct zebra_vrf *zvrf, vni_t vni,
if (CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_LOCAL))
ZEBRA_NEIGH_SET_INACTIVE(nbr);
else if (CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_REMOTE))
- zvni_neigh_install(zvni, nbr);
+ zvni_rem_neigh_install(zvni, nbr,
+ false /*was_static*/);
}
UNSET_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE);
@@ -7103,17 +8600,18 @@ int zebra_vxlan_clear_dup_detect_vni_mac(struct zebra_vrf *zvrf, vni_t vni,
if (zvni_mac_send_add_to_client(zvni->vni,
&mac->macaddr,
mac->flags,
- mac->loc_seq))
+ mac->loc_seq, mac->es))
return 0;
/* Process all neighbors associated with this MAC. */
- zvni_process_neigh_on_local_mac_change(zvni, mac, 0);
+ zvni_process_neigh_on_local_mac_change(zvni, mac, 0,
+ 0 /*es_change*/);
} else if (CHECK_FLAG(mac->flags, ZEBRA_MAC_REMOTE)) {
zvni_process_neigh_on_remote_mac_add(zvni, mac);
/* Install the entry. */
- zvni_mac_install(zvni, mac);
+ zvni_rem_mac_install(zvni, mac, false /* was_static */);
}
return 0;
@@ -7173,10 +8671,10 @@ int zebra_vxlan_clear_dup_detect_vni_ip(struct zebra_vrf *zvrf, vni_t vni,
if (!!CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_LOCAL)) {
zvni_neigh_send_add_to_client(zvni->vni, ip,
- &nbr->emac,
+ &nbr->emac, nbr->mac,
nbr->flags, nbr->loc_seq);
} else if (!!CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_REMOTE)) {
- zvni_neigh_install(zvni, nbr);
+ zvni_rem_neigh_install(zvni, nbr, false /*was_static*/);
}
return 0;
@@ -7223,17 +8721,18 @@ static void zvni_clear_dup_mac_hash(struct hash_bucket *bucket, void *ctxt)
/* Inform to BGP */
if (zvni_mac_send_add_to_client(zvni->vni,
&mac->macaddr,
- mac->flags, mac->loc_seq))
+ mac->flags, mac->loc_seq, mac->es))
return;
/* Process all neighbors associated with this MAC. */
- zvni_process_neigh_on_local_mac_change(zvni, mac, 0);
+ zvni_process_neigh_on_local_mac_change(zvni, mac, 0,
+ 0 /*es_change*/);
} else if (CHECK_FLAG(mac->flags, ZEBRA_MAC_REMOTE)) {
zvni_process_neigh_on_remote_mac_add(zvni, mac);
/* Install the entry. */
- zvni_mac_install(zvni, mac);
+ zvni_rem_mac_install(zvni, mac, false /* was_static */);
}
}
@@ -7268,10 +8767,10 @@ static void zvni_clear_dup_neigh_hash(struct hash_bucket *bucket, void *ctxt)
if (CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_LOCAL)) {
zvni_neigh_send_add_to_client(zvni->vni, &nbr->ip,
- &nbr->emac,
+ &nbr->emac, nbr->mac,
nbr->flags, nbr->loc_seq);
} else if (CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_REMOTE)) {
- zvni_neigh_install(zvni, nbr);
+ zvni_rem_neigh_install(zvni, nbr, false /*was_static*/);
}
}
@@ -7667,6 +9166,8 @@ int zebra_vxlan_handle_kernel_neigh_del(struct interface *ifp,
zebra_mac_t *zmac = NULL;
zebra_l3vni_t *zl3vni = NULL;
struct zebra_vrf *zvrf;
+ bool old_bgp_ready;
+ bool new_bgp_ready;
/* check if this is a remote neigh entry corresponding to remote
* next-hop
@@ -7721,7 +9222,36 @@ int zebra_vxlan_handle_kernel_neigh_del(struct interface *ifp,
* deleted it, it needs to be re-installed as Quagga is the owner.
*/
if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE)) {
- zvni_neigh_install(zvni, n);
+ zvni_rem_neigh_install(zvni, n, false /*was_static*/);
+ return 0;
+ }
+
+ /* if this is a sync entry it cannot be dropped re-install it in
+ * the dataplane
+ */
+ old_bgp_ready =
+ zebra_vxlan_neigh_is_ready_for_bgp(n);
+ if (zebra_vxlan_neigh_is_static(n)) {
+ if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH)
+ zlog_debug("re-add sync neigh vni %u ip %s mac %s 0x%x",
+ n->zvni->vni,
+ ipaddr2str(&n->ip, buf, sizeof(buf)),
+ prefix_mac2str(&n->emac, buf2,
+ sizeof(buf2)),
+ n->flags);
+
+ if (!CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL_INACTIVE))
+ SET_FLAG(n->flags, ZEBRA_NEIGH_LOCAL_INACTIVE);
+ /* inform-bgp about change in local-activity if any */
+ new_bgp_ready =
+ zebra_vxlan_neigh_is_ready_for_bgp(n);
+ zebra_vxlan_neigh_send_add_del_to_client(n,
+ old_bgp_ready, new_bgp_ready);
+
+ /* re-install the entry in the kernel */
+ zebra_vxlan_sync_neigh_dp_install(n, false /* set_inactive */,
+ false /* force_clear_static */, __func__);
+
return 0;
}
@@ -7741,7 +9271,9 @@ int zebra_vxlan_handle_kernel_neigh_del(struct interface *ifp,
ZEBRA_NEIGH_SET_INACTIVE(n);
/* Remove neighbor from BGP. */
- zvni_neigh_send_del_to_client(zvni->vni, &n->ip, &n->emac, 0, n->state);
+ zvni_neigh_send_del_to_client(zvni->vni, &n->ip,
+ &n->emac, n->flags, n->state,
+ false /* force */);
/* Delete this neighbor entry. */
zvni_neigh_del(zvni, n);
@@ -7766,7 +9298,8 @@ int zebra_vxlan_handle_kernel_neigh_update(struct interface *ifp,
struct ethaddr *macaddr,
uint16_t state,
bool is_ext,
- bool is_router)
+ bool is_router,
+ bool local_inactive, bool dp_static)
{
char buf[ETHER_ADDR_STRLEN];
char buf2[INET6_ADDRSTRLEN];
@@ -7787,19 +9320,20 @@ int zebra_vxlan_handle_kernel_neigh_update(struct interface *ifp,
if (!zvni)
return 0;
- if (IS_ZEBRA_DEBUG_VXLAN)
+ if (IS_ZEBRA_DEBUG_VXLAN || IS_ZEBRA_DEBUG_EVPN_MH_NEIGH)
zlog_debug(
- "Add/Update neighbor %s MAC %s intf %s(%u) state 0x%x %s %s-> L2-VNI %u",
+ "Add/Update neighbor %s MAC %s intf %s(%u) state 0x%x %s%s%s-> L2-VNI %u",
ipaddr2str(ip, buf2, sizeof(buf2)),
prefix_mac2str(macaddr, buf, sizeof(buf)), ifp->name,
ifp->ifindex, state, is_ext ? "ext-learned " : "",
is_router ? "router " : "",
+ local_inactive ? "local_inactive " : "",
zvni->vni);
/* Is this about a local neighbor or a remote one? */
if (!is_ext)
return zvni_local_neigh_update(zvni, ifp, ip, macaddr,
- is_router);
+ is_router, local_inactive, dp_static);
return zvni_remote_neigh_update(zvni, ifp, ip, macaddr, state);
}
@@ -7808,7 +9342,7 @@ static int32_t
zebra_vxlan_remote_macip_helper(bool add, struct stream *s, vni_t *vni,
struct ethaddr *macaddr, uint16_t *ipa_len,
struct ipaddr *ip, struct in_addr *vtep_ip,
- uint8_t *flags, uint32_t *seq)
+ uint8_t *flags, uint32_t *seq, esi_t *esi)
{
uint16_t l = 0;
@@ -7846,6 +9380,8 @@ zebra_vxlan_remote_macip_helper(bool add, struct stream *s, vni_t *vni,
STREAM_GETC(s, *flags);
STREAM_GETL(s, *seq);
l += 5;
+ STREAM_GET(esi, s, sizeof(esi_t));
+ l += sizeof(esi_t);
}
return l;
@@ -7877,7 +9413,7 @@ void zebra_vxlan_remote_macip_del(ZAPI_HANDLER_ARGS)
while (l < hdr->length) {
int res_length = zebra_vxlan_remote_macip_helper(
false, s, &vni, &macaddr, &ipa_len, &ip, &vtep_ip, NULL,
- NULL);
+ NULL, NULL);
if (res_length == -1)
goto stream_failure;
@@ -7918,6 +9454,8 @@ void zebra_vxlan_remote_macip_add(ZAPI_HANDLER_ARGS)
uint32_t seq;
char buf[ETHER_ADDR_STRLEN];
char buf1[INET6_ADDRSTRLEN];
+ esi_t esi;
+ char esi_buf[ESI_STR_LEN];
memset(&macaddr, 0, sizeof(struct ethaddr));
memset(&ip, 0, sizeof(struct ipaddr));
@@ -7933,25 +9471,32 @@ void zebra_vxlan_remote_macip_add(ZAPI_HANDLER_ARGS)
while (l < hdr->length) {
int res_length = zebra_vxlan_remote_macip_helper(
true, s, &vni, &macaddr, &ipa_len, &ip, &vtep_ip,
- &flags, &seq);
+ &flags, &seq, &esi);
if (res_length == -1)
goto stream_failure;
l += res_length;
- if (IS_ZEBRA_DEBUG_VXLAN)
+ if (IS_ZEBRA_DEBUG_VXLAN) {
+ if (memcmp(&esi, zero_esi, sizeof(esi_t)))
+ esi_to_str(&esi, esi_buf, sizeof(esi_buf));
+ else
+ strlcpy(esi_buf, "-", ESI_STR_LEN);
zlog_debug(
- "Recv MACIP ADD VNI %u MAC %s%s%s flags 0x%x seq %u VTEP %s from %s",
+ "Recv %sMACIP ADD VNI %u MAC %s%s%s flags 0x%x seq %u VTEP %s ESI %s from %s",
+ (flags & ZEBRA_MACIP_TYPE_SYNC_PATH) ?
+ "sync-" : "",
vni,
prefix_mac2str(&macaddr, buf, sizeof(buf)),
ipa_len ? " IP " : "",
ipa_len ?
ipaddr2str(&ip, buf1, sizeof(buf1)) : "",
- flags, seq, inet_ntoa(vtep_ip),
+ flags, seq, inet_ntoa(vtep_ip), esi_buf,
zebra_route_string(client->proto));
+ }
process_remote_macip_add(vni, &macaddr, ipa_len, &ip,
- flags, seq, vtep_ip);
+ flags, seq, vtep_ip, &esi);
}
stream_failure:
@@ -8050,7 +9595,8 @@ int zebra_vxlan_check_del_local_mac(struct interface *ifp,
ifp->ifindex, vni, mac->flags);
/* Remove MAC from BGP. */
- zvni_mac_send_del_to_client(zvni->vni, macaddr);
+ zvni_mac_send_del_to_client(zvni->vni, macaddr,
+ mac->flags, false /* force */);
/*
* If there are no neigh associated with the mac delete the mac
@@ -8059,7 +9605,7 @@ int zebra_vxlan_check_del_local_mac(struct interface *ifp,
if (!listcount(mac->neigh_list)) {
zvni_mac_del(zvni, mac);
} else {
- UNSET_FLAG(mac->flags, ZEBRA_MAC_LOCAL);
+ UNSET_FLAG(mac->flags, ZEBRA_MAC_ALL_LOCAL_FLAGS);
UNSET_FLAG(mac->flags, ZEBRA_MAC_STICKY);
SET_FLAG(mac->flags, ZEBRA_MAC_AUTO);
}
@@ -8117,7 +9663,7 @@ int zebra_vxlan_check_readd_remote_mac(struct interface *ifp,
prefix_mac2str(macaddr, buf, sizeof(buf)), ifp->name,
ifp->ifindex, vni);
- zvni_mac_install(zvni, mac);
+ zvni_rem_mac_install(zvni, mac, false /* was_static */);
return 0;
}
@@ -8130,6 +9676,8 @@ int zebra_vxlan_local_mac_del(struct interface *ifp, struct interface *br_if,
zebra_vni_t *zvni;
zebra_mac_t *mac;
char buf[ETHER_ADDR_STRLEN];
+ bool old_bgp_ready;
+ bool new_bgp_ready;
/* We are interested in MACs only on ports or (port, VLAN) that
* map to a VNI.
@@ -8159,11 +9707,46 @@ int zebra_vxlan_local_mac_del(struct interface *ifp, struct interface *br_if,
ifp->ifindex, vid, zvni->vni, mac->loc_seq,
mac->flags, listcount(mac->neigh_list));
+ old_bgp_ready = zebra_vxlan_mac_is_ready_for_bgp(mac->flags);
+ if (zebra_vxlan_mac_is_static(mac)) {
+ /* this is a synced entry and can only be removed when the
+ * es-peers stop advertising it.
+ */
+ memset(&mac->fwd_info, 0, sizeof(mac->fwd_info));
+
+ if (IS_ZEBRA_DEBUG_EVPN_MH_MAC)
+ zlog_debug("re-add sync-mac vni %u mac %s es %s seq %d f 0x%x",
+ zvni->vni,
+ prefix_mac2str(macaddr,
+ buf, sizeof(buf)),
+ mac->es ? mac->es->esi_str : "-",
+ mac->loc_seq,
+ mac->flags);
+
+ /* inform-bgp about change in local-activity if any */
+ if (!CHECK_FLAG(mac->flags, ZEBRA_MAC_LOCAL_INACTIVE)) {
+ SET_FLAG(mac->flags, ZEBRA_MAC_LOCAL_INACTIVE);
+ new_bgp_ready = zebra_vxlan_mac_is_ready_for_bgp(mac->flags);
+ zebra_vxlan_mac_send_add_del_to_client(mac,
+ old_bgp_ready, new_bgp_ready);
+ }
+
+ /* re-install the entry in the kernel */
+ zebra_vxlan_sync_mac_dp_install(mac, false /* set_inactive */,
+ false /* force_clear_static */,
+ __func__);
+
+ return 0;
+ }
+
/* Update all the neigh entries associated with this mac */
zvni_process_neigh_on_local_mac_del(zvni, mac);
/* Remove MAC from BGP. */
- zvni_mac_send_del_to_client(zvni->vni, macaddr);
+ zvni_mac_send_del_to_client(zvni->vni, macaddr,
+ mac->flags, false /* force */);
+
+ zebra_evpn_es_mac_deref_entry(mac);
/*
* If there are no neigh associated with the mac delete the mac
@@ -8172,7 +9755,7 @@ int zebra_vxlan_local_mac_del(struct interface *ifp, struct interface *br_if,
if (!listcount(mac->neigh_list)) {
zvni_mac_del(zvni, mac);
} else {
- UNSET_FLAG(mac->flags, ZEBRA_MAC_LOCAL);
+ UNSET_FLAG(mac->flags, ZEBRA_MAC_ALL_LOCAL_FLAGS);
UNSET_FLAG(mac->flags, ZEBRA_MAC_STICKY);
SET_FLAG(mac->flags, ZEBRA_MAC_AUTO);
}
@@ -8180,13 +9763,36 @@ int zebra_vxlan_local_mac_del(struct interface *ifp, struct interface *br_if,
return 0;
}
+/* update local fowarding info. return true if a dest-ES change
+ * is detected
+ */
+static bool zebra_vxlan_local_mac_update_fwd_info(zebra_mac_t *mac,
+ struct interface *ifp, vlanid_t vid)
+{
+ struct zebra_if *zif = ifp->info;
+ bool es_change;
+
+ memset(&mac->fwd_info, 0, sizeof(mac->fwd_info));
+
+ es_change = zebra_evpn_es_mac_ref_entry(mac, zif->es_info.es);
+
+ if (!mac->es) {
+ /* if es is set fwd_info is not-relevant/taped-out */
+ mac->fwd_info.local.ifindex = ifp->ifindex;
+ mac->fwd_info.local.vid = vid;
+ }
+
+ return es_change;
+}
+
/*
* Handle local MAC add (on a port or VLAN corresponding to this VNI).
*/
int zebra_vxlan_local_mac_add_update(struct interface *ifp,
struct interface *br_if,
struct ethaddr *macaddr, vlanid_t vid,
- bool sticky)
+ bool sticky, bool local_inactive,
+ bool dp_static)
{
zebra_vni_t *zvni;
zebra_mac_t *mac;
@@ -8197,11 +9803,13 @@ int zebra_vxlan_local_mac_add_update(struct interface *ifp,
bool upd_neigh = false;
bool is_dup_detect = false;
struct in_addr vtep_ip = {.s_addr = 0};
- ns_id_t local_ns_id = NS_DEFAULT;
-
- zvrf = zebra_vrf_lookup_by_id(ifp->vrf_id);
- if (zvrf && zvrf->zns)
- local_ns_id = zvrf->zns->ns_id;
+ bool es_change = false;
+ bool new_bgp_ready;
+ /* assume inactive if not present or if not local */
+ bool old_local_inactive = true;
+ bool old_bgp_ready = false;
+ bool inform_dataplane = false;
+ bool new_static = false;
/* We are interested in MACs only on ports or (port, VLAN) that
* map to a VNI.
@@ -8225,22 +9833,24 @@ int zebra_vxlan_local_mac_add_update(struct interface *ifp,
return -1;
}
- zvrf = zebra_vrf_get_evpn();
+ zvrf = vrf_info_lookup(zvni->vxlan_if->vrf_id);
if (!zvrf) {
if (IS_ZEBRA_DEBUG_VXLAN)
- zlog_debug(" No Evpn Global Vrf found");
+ zlog_debug(" No Vrf found for vrf_id: %d",
+ zvni->vxlan_if->vrf_id);
return -1;
}
/* Check if we need to create or update or it is a NO-OP. */
mac = zvni_mac_lookup(zvni, macaddr);
if (!mac) {
- if (IS_ZEBRA_DEBUG_VXLAN)
+ if (IS_ZEBRA_DEBUG_VXLAN || IS_ZEBRA_DEBUG_EVPN_MH_MAC)
zlog_debug(
- "ADD %sMAC %s intf %s(%u) VID %u -> VNI %u",
+ "ADD %sMAC %s intf %s(%u) VID %u -> VNI %u%s",
sticky ? "sticky " : "",
prefix_mac2str(macaddr, buf, sizeof(buf)),
- ifp->name, ifp->ifindex, vid, zvni->vni);
+ ifp->name, ifp->ifindex, vid, zvni->vni,
+ local_inactive ? " local-inactive" : "");
mac = zvni_mac_add(zvni, macaddr);
if (!mac) {
@@ -8252,23 +9862,33 @@ int zebra_vxlan_local_mac_add_update(struct interface *ifp,
return -1;
}
SET_FLAG(mac->flags, ZEBRA_MAC_LOCAL);
- mac->fwd_info.local.ifindex = ifp->ifindex;
- mac->fwd_info.local.ns_id = local_ns_id;
- mac->fwd_info.local.vid = vid;
+ es_change = zebra_vxlan_local_mac_update_fwd_info(mac,
+ ifp, vid);
if (sticky)
SET_FLAG(mac->flags, ZEBRA_MAC_STICKY);
inform_client = true;
-
} else {
- if (IS_ZEBRA_DEBUG_VXLAN)
+ if (IS_ZEBRA_DEBUG_VXLAN || IS_ZEBRA_DEBUG_EVPN_MH_MAC)
zlog_debug(
- "UPD %sMAC %s intf %s(%u) VID %u -> VNI %u curFlags 0x%x",
+ "UPD %sMAC %s intf %s(%u) VID %u -> VNI %u %scurFlags 0x%x",
sticky ? "sticky " : "",
prefix_mac2str(macaddr, buf, sizeof(buf)),
ifp->name, ifp->ifindex, vid, zvni->vni,
+ local_inactive ? "local-inactive " : "",
mac->flags);
if (CHECK_FLAG(mac->flags, ZEBRA_MAC_LOCAL)) {
+ struct interface *old_ifp;
+ vlanid_t old_vid;
+ bool old_static;
+
+ zebra_vxlan_mac_get_access_info(mac,
+ &old_ifp, &old_vid);
+ old_bgp_ready = zebra_vxlan_mac_is_ready_for_bgp(
+ mac->flags);
+ old_local_inactive = !!(mac->flags &
+ ZEBRA_MAC_LOCAL_INACTIVE);
+ old_static = zebra_vxlan_mac_is_static(mac);
if (CHECK_FLAG(mac->flags, ZEBRA_MAC_STICKY))
mac_sticky = true;
@@ -8277,17 +9897,20 @@ int zebra_vxlan_local_mac_add_update(struct interface *ifp,
* BGP, note it.
*/
if (mac_sticky == sticky
- && mac->fwd_info.local.ifindex == ifp->ifindex
- && mac->fwd_info.local.ns_id == local_ns_id
- && mac->fwd_info.local.vid == vid) {
+ && old_ifp == ifp
+ && old_vid == vid
+ && old_local_inactive == local_inactive
+ && dp_static == old_static) {
if (IS_ZEBRA_DEBUG_VXLAN)
zlog_debug(
- " Add/Update %sMAC %s intf %s(%u) VID %u -> VNI %u, entry exists and has not changed ",
+ " Add/Update %sMAC %s intf %s(%u) VID %u -> VNI %u%s, entry exists and has not changed ",
sticky ? "sticky " : "",
prefix_mac2str(macaddr, buf,
sizeof(buf)),
ifp->name, ifp->ifindex, vid,
- zvni->vni);
+ zvni->vni,
+ local_inactive ?
+ " local_inactive" : "");
return 0;
}
if (mac_sticky != sticky) {
@@ -8300,11 +9923,31 @@ int zebra_vxlan_local_mac_add_update(struct interface *ifp,
inform_client = true;
}
- memset(&mac->fwd_info, 0, sizeof(mac->fwd_info));
- mac->fwd_info.local.ifindex = ifp->ifindex;
- mac->fwd_info.local.ns_id = local_ns_id;
- mac->fwd_info.local.vid = vid;
-
+ es_change = zebra_vxlan_local_mac_update_fwd_info(mac,
+ ifp, vid);
+ /* If an es_change is detected we need to advertise
+ * the route with a sequence that is one
+ * greater. This is need to indicate a mac-move
+ * to the ES peers
+ */
+ if (es_change) {
+ mac->loc_seq = mac->loc_seq + 1;
+ /* force drop the peer/sync info as it is
+ * simply no longer relevant
+ */
+ if (CHECK_FLAG(mac->flags,
+ ZEBRA_MAC_ALL_PEER_FLAGS)) {
+ zebra_vxlan_mac_clear_sync_info(mac);
+ new_static =
+ zebra_vxlan_mac_is_static(mac);
+ /* if we clear peer-flags we
+ * also need to notify the dataplane
+ * to drop the static flag
+ */
+ if (old_static != new_static)
+ inform_dataplane = true;
+ }
+ }
} else if (CHECK_FLAG(mac->flags, ZEBRA_MAC_REMOTE) ||
CHECK_FLAG(mac->flags, ZEBRA_MAC_AUTO)) {
bool do_dad = false;
@@ -8338,10 +9981,8 @@ int zebra_vxlan_local_mac_add_update(struct interface *ifp,
UNSET_FLAG(mac->flags, ZEBRA_MAC_REMOTE);
UNSET_FLAG(mac->flags, ZEBRA_MAC_AUTO);
SET_FLAG(mac->flags, ZEBRA_MAC_LOCAL);
- memset(&mac->fwd_info, 0, sizeof(mac->fwd_info));
- mac->fwd_info.local.ifindex = ifp->ifindex;
- mac->fwd_info.local.ns_id = local_ns_id;
- mac->fwd_info.local.vid = vid;
+ es_change = zebra_vxlan_local_mac_update_fwd_info(mac,
+ ifp, vid);
if (sticky)
SET_FLAG(mac->flags, ZEBRA_MAC_STICKY);
else
@@ -8364,16 +10005,57 @@ int zebra_vxlan_local_mac_add_update(struct interface *ifp,
}
}
- /* Inform BGP if required. */
- if (inform_client) {
- if (zvni_mac_send_add_to_client(zvni->vni, macaddr,
- mac->flags, mac->loc_seq))
- return -1;
+ /* if the dataplane thinks the entry is sync but it is
+ * not sync in zebra we need to re-install to fixup
+ */
+ if (dp_static) {
+ new_static = zebra_vxlan_mac_is_static(mac);
+ if (!new_static)
+ inform_dataplane = true;
+ }
+
+ if (local_inactive)
+ SET_FLAG(mac->flags, ZEBRA_MAC_LOCAL_INACTIVE);
+ else
+ UNSET_FLAG(mac->flags, ZEBRA_MAC_LOCAL_INACTIVE);
+
+ new_bgp_ready = zebra_vxlan_mac_is_ready_for_bgp(mac->flags);
+ /* if local-activity has changed we need update bgp
+ * even if bgp already knows about the mac
+ */
+ if ((old_local_inactive != local_inactive) ||
+ (new_bgp_ready != old_bgp_ready)) {
+ if (IS_ZEBRA_DEBUG_EVPN_MH_MAC)
+ zlog_debug("local mac vni %u mac %s es %s seq %d f 0x%x%s",
+ zvni->vni,
+ prefix_mac2str(macaddr,
+ buf, sizeof(buf)),
+ mac->es ? mac->es->esi_str : "",
+ mac->loc_seq,
+ mac->flags,
+ local_inactive ?
+ " local-inactive" : "");
+ inform_client = true;
+ }
+
+ if (es_change) {
+ inform_client = true;
+ upd_neigh = true;
}
+ /* Inform dataplane if required. */
+ if (inform_dataplane)
+ zebra_vxlan_sync_mac_dp_install(mac, false /* set_inactive */,
+ false /* force_clear_static */, __func__);
+
+ /* Inform BGP if required. */
+ if (inform_client)
+ zebra_vxlan_mac_send_add_del_to_client(mac,
+ old_bgp_ready, new_bgp_ready);
+
/* Process all neighbors associated with this MAC, if required. */
if (upd_neigh)
- zvni_process_neigh_on_local_mac_change(zvni, mac, 0);
+ zvni_process_neigh_on_local_mac_change(zvni, mac, 0, es_change);
return 0;
}
@@ -8893,7 +10575,7 @@ int zebra_vxlan_if_down(struct interface *ifp)
assert(zvni->vxlan_if == ifp);
/* Delete this VNI from BGP. */
- zvni_send_del_to_client(zvni->vni);
+ zvni_send_del_to_client(zvni);
/* Free up all neighbors and MACs, if any. */
zvni_neigh_del_all(zvni, 1, 0, DEL_ALL_NEIGH);
@@ -9034,9 +10716,8 @@ int zebra_vxlan_if_del(struct interface *ifp)
zl3vni = zl3vni_from_vrf(zvni->vrf_id);
if (zl3vni)
listnode_delete(zl3vni->l2vnis, zvni);
-
/* Delete VNI from BGP. */
- zvni_send_del_to_client(zvni->vni);
+ zvni_send_del_to_client(zvni);
/* Free up all neighbors and MAC, if any. */
zvni_neigh_del_all(zvni, 0, 0, DEL_ALL_NEIGH);
@@ -9155,7 +10836,7 @@ int zebra_vxlan_if_update(struct interface *ifp, uint16_t chgflags)
&& (zif->brslave_info.bridge_ifindex == IFINDEX_INTERNAL)) {
/* Delete from client, remove all remote VTEPs */
/* Also, free up all MACs and neighbors. */
- zvni_send_del_to_client(zvni->vni);
+ zvni_send_del_to_client(zvni);
zvni_neigh_del_all(zvni, 1, 0, DEL_ALL_NEIGH);
zvni_mac_del_all(zvni, 1, 0, DEL_ALL_MAC);
zvni_vtep_del_all(zvni, 1);
@@ -9178,9 +10859,12 @@ int zebra_vxlan_if_update(struct interface *ifp, uint16_t chgflags)
zebra_vxlan_sg_ref(vxl->vtep_ip, vxl->mcast_grp);
zvni->local_vtep_ip = vxl->vtep_ip;
zvni->mcast_grp = vxl->mcast_grp;
+ /* on local vtep-ip check if ES orig-ip
+ * needs to be updated
+ */
+ zebra_evpn_es_set_base_vni(zvni);
}
- zvni->vxlan_if = ifp;
-
+ zvni_vxlan_if_set(zvni, ifp, true /* set */);
/* Take further actions needed.
* Note that if we are here, there is a change of interest.
*/
@@ -9291,8 +10975,12 @@ int zebra_vxlan_if_add(struct interface *ifp)
zebra_vxlan_sg_ref(vxl->vtep_ip, vxl->mcast_grp);
zvni->local_vtep_ip = vxl->vtep_ip;
zvni->mcast_grp = vxl->mcast_grp;
+ /* on local vtep-ip check if ES orig-ip
+ * needs to be updated
+ */
+ zebra_evpn_es_set_base_vni(zvni);
}
- zvni->vxlan_if = ifp;
+ zvni_vxlan_if_set(zvni, ifp, true /* set */);
vlan_if = zvni_map_to_svi(vxl->access_vlan,
zif->brslave_info.br_if);
if (vlan_if) {
@@ -9475,8 +11163,15 @@ int zebra_vxlan_vrf_disable(struct zebra_vrf *zvrf)
if (!zl3vni)
return 0;
- zl3vni->vrf_id = VRF_UNKNOWN;
zebra_vxlan_process_l3vni_oper_down(zl3vni);
+
+ /* delete and uninstall all rmacs */
+ hash_iterate(zl3vni->rmac_table, zl3vni_del_rmac_hash_entry, zl3vni);
+ /* delete and uninstall all next-hops */
+ hash_iterate(zl3vni->nh_table, zl3vni_del_nh_hash_entry, zl3vni);
+
+ zl3vni->vrf_id = VRF_UNKNOWN;
+
return 0;
}
@@ -9805,25 +11500,6 @@ stream_failure:
return;
}
-static int macfdb_read_ns(struct ns *ns,
- void *_in_param __attribute__((unused)),
- void **out_param __attribute__((unused)))
-{
- struct zebra_ns *zns = ns->info;
-
- macfdb_read(zns);
- return NS_WALK_CONTINUE;
-}
-
-static int neigh_read_ns(struct ns *ns,
- void *_in_param __attribute__((unused)),
- void **out_param __attribute__((unused)))
-{
- struct zebra_ns *zns = ns->info;
-
- neigh_read(zns);
- return NS_WALK_CONTINUE;
-}
/*
* Handle message from client to learn (or stop learning) about VNIs and MACs.
@@ -9865,6 +11541,9 @@ void zebra_vxlan_advertise_all_vni(ZAPI_HANDLER_ARGS)
/* Note BUM handling */
zvrf->vxlan_flood_ctrl = flood_ctrl;
+ /* Replay all ESs */
+ zebra_evpn_es_send_all_to_client(true /* add */);
+
/* Build VNI hash table and inform BGP. */
zvni_build_hash_table();
@@ -9873,16 +11552,19 @@ void zebra_vxlan_advertise_all_vni(ZAPI_HANDLER_ARGS)
NULL);
/* Read the MAC FDB */
- ns_walk_func(macfdb_read_ns, NULL, NULL);
+ macfdb_read(zvrf->zns);
/* Read neighbors */
- ns_walk_func(neigh_read_ns, NULL, NULL);
+ neigh_read(zvrf->zns);
} else {
/* Cleanup VTEPs for all VNIs - uninstall from
* kernel and free entries.
*/
hash_iterate(zvrf->vni_table, zvni_cleanup_all, zvrf);
+ /* Delete all ESs in BGP */
+ zebra_evpn_es_send_all_to_client(false /* add */);
+
/* cleanup all l3vnis */
hash_iterate(zrouter.l3vni_table, zl3vni_cleanup_all, NULL);
@@ -9911,10 +11593,15 @@ void zebra_vxlan_init_tables(struct zebra_vrf *zvrf)
/* Cleanup VNI info, but don't free the table. */
void zebra_vxlan_cleanup_tables(struct zebra_vrf *zvrf)
{
+ struct zebra_vrf *evpn_zvrf = zebra_vrf_get_evpn();
+
if (!zvrf)
return;
hash_iterate(zvrf->vni_table, zvni_cleanup_all, zvrf);
hash_iterate(zvrf->vxlan_sg_table, zebra_vxlan_sg_cleanup, NULL);
+
+ if (zvrf == evpn_zvrf)
+ zebra_evpn_es_cleanup();
}
/* Close all VNI handling */
@@ -9932,12 +11619,14 @@ void zebra_vxlan_init(void)
zrouter.l3vni_table = hash_create(l3vni_hash_keymake, l3vni_hash_cmp,
"Zebra VRF L3 VNI table");
zrouter.evpn_vrf = NULL;
+ zebra_evpn_mh_init();
}
/* free l3vni table */
void zebra_vxlan_disable(void)
{
hash_free(zrouter.l3vni_table);
+ zebra_evpn_mh_terminate();
}
/* get the l3vni svi ifindex */
@@ -9994,9 +11683,9 @@ static int zebra_vxlan_dad_ip_auto_recovery_exp(struct thread *t)
/* Send to BGP */
if (CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_LOCAL)) {
zvni_neigh_send_add_to_client(zvni->vni, &nbr->ip, &nbr->emac,
- nbr->flags, nbr->loc_seq);
+ nbr->mac, nbr->flags, nbr->loc_seq);
} else if (!!CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_REMOTE)) {
- zvni_neigh_install(zvni, nbr);
+ zvni_rem_neigh_install(zvni, nbr, false /*was_static*/);
}
return 0;
@@ -10039,7 +11728,8 @@ static int zebra_vxlan_dad_mac_auto_recovery_exp(struct thread *t)
if (CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_LOCAL))
ZEBRA_NEIGH_SET_INACTIVE(nbr);
else if (CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_REMOTE))
- zvni_neigh_install(zvni, nbr);
+ zvni_rem_neigh_install(zvni, nbr,
+ false /*was_static*/);
}
UNSET_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE);
@@ -10058,17 +11748,18 @@ static int zebra_vxlan_dad_mac_auto_recovery_exp(struct thread *t)
if (CHECK_FLAG(mac->flags, ZEBRA_MAC_LOCAL)) {
/* Inform to BGP */
if (zvni_mac_send_add_to_client(zvni->vni, &mac->macaddr,
- mac->flags, mac->loc_seq))
+ mac->flags, mac->loc_seq, mac->es))
return -1;
/* Process all neighbors associated with this MAC. */
- zvni_process_neigh_on_local_mac_change(zvni, mac, 0);
+ zvni_process_neigh_on_local_mac_change(zvni, mac, 0,
+ 0 /*es_change*/);
} else if (CHECK_FLAG(mac->flags, ZEBRA_MAC_REMOTE)) {
zvni_process_neigh_on_remote_mac_add(zvni, mac);
/* Install the entry. */
- zvni_mac_install(zvni, mac);
+ zvni_rem_mac_install(zvni, mac, false /* was_static */);
}
return 0;
@@ -10338,7 +12029,7 @@ static void zvni_send_mac_hash_entry_to_client(struct hash_bucket *bucket,
if (CHECK_FLAG(zmac->flags, ZEBRA_MAC_LOCAL))
zvni_mac_send_add_to_client(wctx->zvni->vni, &zmac->macaddr,
- zmac->flags, zmac->loc_seq);
+ zmac->flags, zmac->loc_seq, zmac->es);
}
/* Iterator to Notify Local MACs of a L2VNI */
@@ -10374,7 +12065,7 @@ static void zvni_send_neigh_hash_entry_to_client(struct hash_bucket *bucket,
return;
zvni_neigh_send_add_to_client(wctx->zvni->vni, &zn->ip,
- &zn->emac, zn->flags,
+ &zn->emac, zn->mac, zn->flags,
zn->loc_seq);
}
}
diff --git a/zebra/zebra_vxlan.h b/zebra/zebra_vxlan.h
index 064dda6cd0..9c8af9d1fc 100644
--- a/zebra/zebra_vxlan.h
+++ b/zebra/zebra_vxlan.h
@@ -165,14 +165,15 @@ extern int zebra_vxlan_svi_down(struct interface *ifp,
extern int zebra_vxlan_handle_kernel_neigh_update(
struct interface *ifp, struct interface *link_if, struct ipaddr *ip,
struct ethaddr *macaddr, uint16_t state, bool is_ext,
- bool is_router);
+ bool is_router, bool local_inactive, bool dp_static);
extern int zebra_vxlan_handle_kernel_neigh_del(struct interface *ifp,
struct interface *link_if,
struct ipaddr *ip);
extern int zebra_vxlan_local_mac_add_update(struct interface *ifp,
struct interface *br_if,
struct ethaddr *mac, vlanid_t vid,
- bool sticky);
+ bool sticky, bool local_inactive,
+ bool dp_static);
extern int zebra_vxlan_local_mac_del(struct interface *ifp,
struct interface *br_if,
struct ethaddr *mac, vlanid_t vid);
@@ -217,6 +218,7 @@ extern void zebra_vxlan_handle_result(struct zebra_dplane_ctx *ctx);
extern void zebra_evpn_init(void);
extern void zebra_vxlan_macvlan_up(struct interface *ifp);
extern void zebra_vxlan_macvlan_down(struct interface *ifp);
+extern int vni_list_cmp(void *p1, void *p2);
#ifdef __cplusplus
}
diff --git a/zebra/zebra_vxlan_private.h b/zebra/zebra_vxlan_private.h
index d2b02df2ad..e2eae56873 100644
--- a/zebra/zebra_vxlan_private.h
+++ b/zebra/zebra_vxlan_private.h
@@ -62,6 +62,9 @@ struct zebra_vtep_t_ {
struct zebra_vtep_t_ *prev;
};
+RB_HEAD(zebra_es_evi_rb_head, zebra_evpn_es_evi);
+RB_PROTOTYPE(zebra_es_evi_rb_head, zebra_evpn_es_evi, rb_node,
+ zebra_es_evi_rb_cmp);
/*
* VNI hash table
@@ -73,6 +76,10 @@ struct zebra_vni_t_ {
/* VNI - key */
vni_t vni;
+ /* ES flags */
+ uint32_t flags;
+#define ZVNI_READY_FOR_BGP (1 << 0) /* ready to be sent to BGP */
+
/* Flag for advertising gw macip */
uint8_t advertise_gw_macip;
@@ -102,6 +109,12 @@ struct zebra_vni_t_ {
/* List of local or remote neighbors (MAC+IP) */
struct hash *neigh_table;
+
+ /* RB tree of ES-EVIs */
+ struct zebra_es_evi_rb_head es_evi_rb_tree;
+
+ /* List of local ESs */
+ struct list *local_es_evi_list;
};
/* L3 VNI hash table */
@@ -302,6 +315,23 @@ struct zebra_mac_t_ {
#define ZEBRA_MAC_REMOTE_DEF_GW 0x40
#define ZEBRA_MAC_DUPLICATE 0x80
#define ZEBRA_MAC_FPM_SENT 0x100 /* whether or not this entry was sent. */
+/* MAC is locally active on an ethernet segment peer */
+#define ZEBRA_MAC_ES_PEER_ACTIVE 0x200
+/* MAC has been proxy-advertised by peers. This means we need to
+ * keep the entry for forwarding but cannot advertise it
+ */
+#define ZEBRA_MAC_ES_PEER_PROXY 0x400
+/* We have not been able to independently establish that the host is
+ * local connected but one or more ES peers claims it is.
+ * We will maintain the entry for forwarding purposes and continue
+ * to advertise it as locally attached but with a "proxy" flag
+ */
+#define ZEBRA_MAC_LOCAL_INACTIVE 0x800
+
+#define ZEBRA_MAC_ALL_LOCAL_FLAGS (ZEBRA_MAC_LOCAL |\
+ ZEBRA_MAC_LOCAL_INACTIVE)
+#define ZEBRA_MAC_ALL_PEER_FLAGS (ZEBRA_MAC_ES_PEER_PROXY |\
+ ZEBRA_MAC_ES_PEER_ACTIVE)
/* back pointer to zvni */
zebra_vni_t *zvni;
@@ -310,13 +340,17 @@ struct zebra_mac_t_ {
union {
struct {
ifindex_t ifindex;
- ns_id_t ns_id;
vlanid_t vid;
} local;
struct in_addr r_vtep_ip;
} fwd_info;
+ /* Local or remote ES */
+ struct zebra_evpn_es *es;
+ /* memory used to link the mac to the es */
+ struct listnode es_listnode;
+
/* Mobility sequence numbers associated with this entry. */
uint32_t rem_seq;
uint32_t loc_seq;
@@ -335,6 +369,14 @@ struct zebra_mac_t_ {
struct timeval detect_start_time;
time_t dad_dup_detect_time;
+
+ /* used for ageing out the PEER_ACTIVE flag */
+ struct thread *hold_timer;
+
+ /* number of neigh entries (using this mac) that have
+ * ZEBRA_MAC_ES_PEER_ACTIVE or ZEBRA_NEIGH_ES_PEER_PROXY
+ */
+ uint32_t sync_neigh_cnt;
};
/*
@@ -366,6 +408,17 @@ struct rmac_walk_ctx {
struct json_object *json;
};
+/* temporary datastruct to pass info between the mac-update and
+ * neigh-update while handling mac-ip routes
+ */
+struct sync_mac_ip_ctx {
+ bool ignore_macip;
+ bool mac_created;
+ bool mac_inactive;
+ bool mac_dp_update_deferred;
+ zebra_mac_t *mac;
+};
+
#define IS_ZEBRA_NEIGH_ACTIVE(n) (n->state == ZEBRA_NEIGH_ACTIVE)
#define IS_ZEBRA_NEIGH_INACTIVE(n) (n->state == ZEBRA_NEIGH_INACTIVE)
@@ -392,6 +445,9 @@ struct zebra_neigh_t_ {
/* MAC address. */
struct ethaddr emac;
+ /* Back pointer to MAC. Only applicable to hosts in a L2-VNI. */
+ zebra_mac_t *mac;
+
/* Underlying interface. */
ifindex_t ifindex;
@@ -405,6 +461,18 @@ struct zebra_neigh_t_ {
#define ZEBRA_NEIGH_ROUTER_FLAG 0x10
#define ZEBRA_NEIGH_DUPLICATE 0x20
#define ZEBRA_NEIGH_SVI_IP 0x40
+/* rxed from an ES peer */
+#define ZEBRA_NEIGH_ES_PEER_ACTIVE 0x80
+/* rxed from an ES peer as a proxy advertisement */
+#define ZEBRA_NEIGH_ES_PEER_PROXY 0x100
+/* We have not been able to independently establish that the host
+ * is local connected
+ */
+#define ZEBRA_NEIGH_LOCAL_INACTIVE 0x200
+#define ZEBRA_NEIGH_ALL_LOCAL_FLAGS (ZEBRA_NEIGH_LOCAL |\
+ ZEBRA_NEIGH_LOCAL_INACTIVE)
+#define ZEBRA_NEIGH_ALL_PEER_FLAGS (ZEBRA_NEIGH_ES_PEER_PROXY |\
+ ZEBRA_NEIGH_ES_PEER_ACTIVE)
enum zebra_neigh_state state;
@@ -432,6 +500,9 @@ struct zebra_neigh_t_ {
struct timeval detect_start_time;
time_t dad_dup_detect_time;
+
+ /* used for ageing out the PEER_ACTIVE flag */
+ struct thread *hold_timer;
};
/*
@@ -476,6 +547,7 @@ extern zebra_l3vni_t *zl3vni_from_vrf(vrf_id_t vrf_id);
extern struct interface *zl3vni_map_to_vxlan_if(zebra_l3vni_t *zl3vni);
extern struct interface *zl3vni_map_to_svi_if(zebra_l3vni_t *zl3vni);
extern struct interface *zl3vni_map_to_mac_vlan_if(zebra_l3vni_t *zl3vni);
+extern zebra_l3vni_t *zl3vni_lookup(vni_t vni);
DECLARE_HOOK(zebra_rmac_update, (zebra_mac_t *rmac, zebra_l3vni_t *zl3vni,
bool delete, const char *reason), (rmac, zl3vni, delete, reason))
@@ -507,4 +579,8 @@ typedef struct zebra_vxlan_sg_ {
uint32_t ref_cnt;
} zebra_vxlan_sg_t;
+extern zebra_vni_t *zvni_lookup(vni_t vni);
+extern void zebra_vxlan_sync_mac_dp_install(zebra_mac_t *mac, bool set_inactive,
+ bool force_clear_static, const char *caller);
+
#endif /* _ZEBRA_VXLAN_PRIVATE_H */
diff --git a/zebra/zserv.c b/zebra/zserv.c
index 4cccc7bfed..cded6ea12b 100644
--- a/zebra/zserv.c
+++ b/zebra/zserv.c
@@ -1075,6 +1075,12 @@ static void zebra_show_client_detail(struct vty *vty, struct zserv *client)
vty_out(vty, "L3-VNI delete notifications: %u\n", client->l3vnidel_cnt);
vty_out(vty, "MAC-IP add notifications: %u\n", client->macipadd_cnt);
vty_out(vty, "MAC-IP delete notifications: %u\n", client->macipdel_cnt);
+ vty_out(vty, "ES add notifications: %u\n", client->local_es_add_cnt);
+ vty_out(vty, "ES delete notifications: %u\n", client->local_es_del_cnt);
+ vty_out(vty, "ES-EVI add notifications: %u\n",
+ client->local_es_evi_add_cnt);
+ vty_out(vty, "ES-EVI delete notifications: %u\n",
+ client->local_es_evi_del_cnt);
TAILQ_FOREACH (info, &client->gr_info_queue, gr_info) {
vty_out(vty, "VRF : %s\n", vrf_id_to_name(info->vrf_id));
diff --git a/zebra/zserv.h b/zebra/zserv.h
index 3eb0a9151c..54e840cd56 100644
--- a/zebra/zserv.h
+++ b/zebra/zserv.h
@@ -194,6 +194,10 @@ struct zserv {
uint32_t v6_nh_watch_rem_cnt;
uint32_t vxlan_sg_add_cnt;
uint32_t vxlan_sg_del_cnt;
+ uint32_t local_es_add_cnt;
+ uint32_t local_es_del_cnt;
+ uint32_t local_es_evi_add_cnt;
+ uint32_t local_es_evi_del_cnt;
uint32_t error_cnt;
time_t nh_reg_time;