From 9a84cb612e8532d6f14d4702ecd9dfd6af408be5 Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Fri, 18 Nov 2022 15:40:45 +0200 Subject: [PATCH 1/5] tests: Check if we can override IPv6 next-hop for VPN networks in route-map Signed-off-by: Donatas Abraitis --- .../bgp_vpn_5549_route_map/__init__.py | 0 .../bgp_vpn_5549_route_map/cpe1/bgpd.conf | 9 ++ .../bgp_vpn_5549_route_map/cpe1/zebra.conf | 9 ++ .../bgp_vpn_5549_route_map/cpe2/bgpd.conf | 6 + .../bgp_vpn_5549_route_map/cpe2/zebra.conf | 6 + .../bgp_vpn_5549_route_map/pe1/bgpd.conf | 38 +++++ .../bgp_vpn_5549_route_map/pe1/ldpd.conf | 10 ++ .../bgp_vpn_5549_route_map/pe1/ospf6d.conf | 12 ++ .../bgp_vpn_5549_route_map/pe1/zebra.conf | 14 ++ .../bgp_vpn_5549_route_map/pe2/bgpd.conf | 29 ++++ .../bgp_vpn_5549_route_map/pe2/ldpd.conf | 10 ++ .../bgp_vpn_5549_route_map/pe2/ospf6d.conf | 12 ++ .../bgp_vpn_5549_route_map/pe2/zebra.conf | 14 ++ .../test_bgp_vpn_5549_route_map.py | 138 ++++++++++++++++++ 14 files changed, 307 insertions(+) create mode 100644 tests/topotests/bgp_vpn_5549_route_map/__init__.py create mode 100644 tests/topotests/bgp_vpn_5549_route_map/cpe1/bgpd.conf create mode 100644 tests/topotests/bgp_vpn_5549_route_map/cpe1/zebra.conf create mode 100644 tests/topotests/bgp_vpn_5549_route_map/cpe2/bgpd.conf create mode 100644 tests/topotests/bgp_vpn_5549_route_map/cpe2/zebra.conf create mode 100644 tests/topotests/bgp_vpn_5549_route_map/pe1/bgpd.conf create mode 100644 tests/topotests/bgp_vpn_5549_route_map/pe1/ldpd.conf create mode 100644 tests/topotests/bgp_vpn_5549_route_map/pe1/ospf6d.conf create mode 100644 tests/topotests/bgp_vpn_5549_route_map/pe1/zebra.conf create mode 100644 tests/topotests/bgp_vpn_5549_route_map/pe2/bgpd.conf create mode 100644 tests/topotests/bgp_vpn_5549_route_map/pe2/ldpd.conf create mode 100644 tests/topotests/bgp_vpn_5549_route_map/pe2/ospf6d.conf create mode 100644 tests/topotests/bgp_vpn_5549_route_map/pe2/zebra.conf create mode 100644 tests/topotests/bgp_vpn_5549_route_map/test_bgp_vpn_5549_route_map.py diff --git a/tests/topotests/bgp_vpn_5549_route_map/__init__.py b/tests/topotests/bgp_vpn_5549_route_map/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/topotests/bgp_vpn_5549_route_map/cpe1/bgpd.conf b/tests/topotests/bgp_vpn_5549_route_map/cpe1/bgpd.conf new file mode 100644 index 0000000000..013cd8c258 --- /dev/null +++ b/tests/topotests/bgp_vpn_5549_route_map/cpe1/bgpd.conf @@ -0,0 +1,9 @@ +router bgp 65000 + no bgp ebgp-requires-policy + neighbor 192.168.1.2 remote-as external + neighbor 192.168.1.2 timers 1 3 + neighbor 192.168.1.2 timers connect 1 + address-family ipv4 unicast + redistribute connected + exit-address-family +! diff --git a/tests/topotests/bgp_vpn_5549_route_map/cpe1/zebra.conf b/tests/topotests/bgp_vpn_5549_route_map/cpe1/zebra.conf new file mode 100644 index 0000000000..49dcfc3b02 --- /dev/null +++ b/tests/topotests/bgp_vpn_5549_route_map/cpe1/zebra.conf @@ -0,0 +1,9 @@ +! +interface lo + ip address 172.16.255.1/32 +! +interface cpe1-eth0 + ip address 192.168.1.1/24 +! +ip forwarding +! diff --git a/tests/topotests/bgp_vpn_5549_route_map/cpe2/bgpd.conf b/tests/topotests/bgp_vpn_5549_route_map/cpe2/bgpd.conf new file mode 100644 index 0000000000..d65d507bf4 --- /dev/null +++ b/tests/topotests/bgp_vpn_5549_route_map/cpe2/bgpd.conf @@ -0,0 +1,6 @@ +router bgp 65000 + no bgp ebgp-requires-policy + neighbor 192.168.2.2 remote-as external + neighbor 192.168.2.2 timers 1 3 + neighbor 192.168.2.2 timers connect 1 +! diff --git a/tests/topotests/bgp_vpn_5549_route_map/cpe2/zebra.conf b/tests/topotests/bgp_vpn_5549_route_map/cpe2/zebra.conf new file mode 100644 index 0000000000..a47319e45f --- /dev/null +++ b/tests/topotests/bgp_vpn_5549_route_map/cpe2/zebra.conf @@ -0,0 +1,6 @@ +! +interface cpe2-eth0 + ip address 192.168.2.1/24 +! +ip forwarding +! diff --git a/tests/topotests/bgp_vpn_5549_route_map/pe1/bgpd.conf b/tests/topotests/bgp_vpn_5549_route_map/pe1/bgpd.conf new file mode 100644 index 0000000000..93da025463 --- /dev/null +++ b/tests/topotests/bgp_vpn_5549_route_map/pe1/bgpd.conf @@ -0,0 +1,38 @@ +router bgp 65001 + bgp router-id 10.10.10.10 + no bgp ebgp-requires-policy + no bgp default ipv4-unicast + neighbor 2001:db8:1::2 remote-as internal + neighbor 2001:db8:1::2 update-source 2001:db8:1::1 + neighbor 2001:db8:1::2 timers 1 3 + neighbor 2001:db8:1::2 timers connect 1 + neighbor 2001:db8:1::2 capability extended-nexthop + address-family ipv4 vpn + neighbor 2001:db8:1::2 activate + neighbor 2001:db8:1::2 route-map pe2 out + exit-address-family +! +router bgp 65001 vrf RED + bgp router-id 192.168.1.2 + no bgp ebgp-requires-policy + neighbor 192.168.1.1 remote-as external + neighbor 192.168.1.1 timers 1 3 + neighbor 192.168.1.1 timers connect 1 + address-family ipv4 unicast + label vpn export 1111 + rd vpn export 192.168.1.2:2 + rt vpn import 192.168.2.2:2 192.168.1.2:2 + rt vpn export 192.168.1.2:2 + export vpn + import vpn + exit-address-family +! +ip prefix-list cpe1 seq 5 permit 172.16.255.1/32 +! +route-map pe2 permit 10 + match ip address prefix-list cpe1 + set ipv6 vpn next-hop 2001:db8::1 +! +route-map pe2 permit 20 +exit +! diff --git a/tests/topotests/bgp_vpn_5549_route_map/pe1/ldpd.conf b/tests/topotests/bgp_vpn_5549_route_map/pe1/ldpd.conf new file mode 100644 index 0000000000..fb40f06fa7 --- /dev/null +++ b/tests/topotests/bgp_vpn_5549_route_map/pe1/ldpd.conf @@ -0,0 +1,10 @@ +mpls ldp + router-id 10.10.10.10 + ! + address-family ipv4 + discovery transport-address 10.10.10.10 + ! + interface pe1-eth1 + ! + ! +! diff --git a/tests/topotests/bgp_vpn_5549_route_map/pe1/ospf6d.conf b/tests/topotests/bgp_vpn_5549_route_map/pe1/ospf6d.conf new file mode 100644 index 0000000000..0053d1ecb5 --- /dev/null +++ b/tests/topotests/bgp_vpn_5549_route_map/pe1/ospf6d.conf @@ -0,0 +1,12 @@ +! +interface lo + ipv6 ospf6 area 0 +! +interface pe1-eth1 + ipv6 ospf6 area 0 + ipv6 ospf6 hello-interval 1 + ipv6 ospf6 dead-interval 3 +! +router ospf6 + ospf6 router-id 10.10.10.10 +! diff --git a/tests/topotests/bgp_vpn_5549_route_map/pe1/zebra.conf b/tests/topotests/bgp_vpn_5549_route_map/pe1/zebra.conf new file mode 100644 index 0000000000..da91055135 --- /dev/null +++ b/tests/topotests/bgp_vpn_5549_route_map/pe1/zebra.conf @@ -0,0 +1,14 @@ +! +interface lo + ip address 10.10.10.10/32 + ipv6 address 2001:db8:1::1/128 +! +interface pe1-eth0 vrf RED + ip address 192.168.1.2/24 +! +interface pe1-eth1 + ip address 10.0.1.1/24 + ipv6 address 2001:db8::1/64 +! +ip forwarding +! diff --git a/tests/topotests/bgp_vpn_5549_route_map/pe2/bgpd.conf b/tests/topotests/bgp_vpn_5549_route_map/pe2/bgpd.conf new file mode 100644 index 0000000000..6db1eef993 --- /dev/null +++ b/tests/topotests/bgp_vpn_5549_route_map/pe2/bgpd.conf @@ -0,0 +1,29 @@ +router bgp 65001 + bgp router-id 10.10.10.20 + no bgp ebgp-requires-policy + no bgp default ipv4-unicast + neighbor 2001:db8:1::1 remote-as internal + neighbor 2001:db8:1::1 update-source 2001:db8:1::2 + neighbor 2001:db8:1::1 timers 1 3 + neighbor 2001:db8:1::1 timers connect 1 + neighbor 2001:db8:1::1 capability extended-nexthop + address-family ipv4 vpn + neighbor 2001:db8:1::1 activate + exit-address-family +! +router bgp 65001 vrf RED + bgp router-id 192.168.2.2 + no bgp ebgp-requires-policy + neighbor 192.168.2.1 remote-as external + neighbor 192.168.2.1 timers 1 3 + neighbor 192.168.2.1 timers connect 1 + address-family ipv4 unicast + label vpn export 2222 + rd vpn export 192.168.2.2:2 + rt vpn import 192.168.2.2:2 192.168.1.2:2 + rt vpn export 192.168.2.2:2 + export vpn + import vpn + exit-address-family +! + diff --git a/tests/topotests/bgp_vpn_5549_route_map/pe2/ldpd.conf b/tests/topotests/bgp_vpn_5549_route_map/pe2/ldpd.conf new file mode 100644 index 0000000000..e2b5359993 --- /dev/null +++ b/tests/topotests/bgp_vpn_5549_route_map/pe2/ldpd.conf @@ -0,0 +1,10 @@ +mpls ldp + router-id 10.10.10.20 + ! + address-family ipv4 + discovery transport-address 10.10.10.20 + ! + interface pe2-eth0 + ! + ! +! diff --git a/tests/topotests/bgp_vpn_5549_route_map/pe2/ospf6d.conf b/tests/topotests/bgp_vpn_5549_route_map/pe2/ospf6d.conf new file mode 100644 index 0000000000..f79bb4f5f7 --- /dev/null +++ b/tests/topotests/bgp_vpn_5549_route_map/pe2/ospf6d.conf @@ -0,0 +1,12 @@ +! +interface lo + ipv6 ospf6 area 0 +! +interface pe2-eth0 + ipv6 ospf6 area 0 + ipv6 ospf6 hello-interval 1 + ipv6 ospf6 dead-interval 3 +! +router ospf6 + ospf6 router-id 10.10.10.20 +! diff --git a/tests/topotests/bgp_vpn_5549_route_map/pe2/zebra.conf b/tests/topotests/bgp_vpn_5549_route_map/pe2/zebra.conf new file mode 100644 index 0000000000..19ef7bf911 --- /dev/null +++ b/tests/topotests/bgp_vpn_5549_route_map/pe2/zebra.conf @@ -0,0 +1,14 @@ +! +interface lo + ip address 10.10.10.20/32 + ipv6 address 2001:db8:1::2/128 +! +interface pe2-eth1 vrf RED + ip address 192.168.2.2/24 +! +interface pe2-eth0 + ip address 10.0.1.2/24 + ipv6 address 2001:db8::2/64 +! +ip forwarding +! diff --git a/tests/topotests/bgp_vpn_5549_route_map/test_bgp_vpn_5549_route_map.py b/tests/topotests/bgp_vpn_5549_route_map/test_bgp_vpn_5549_route_map.py new file mode 100644 index 0000000000..e567d3654f --- /dev/null +++ b/tests/topotests/bgp_vpn_5549_route_map/test_bgp_vpn_5549_route_map.py @@ -0,0 +1,138 @@ +#!/usr/bin/env python + +# +# Copyright (c) 2022 by +# Donatas Abraitis +# +# 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. +# + +""" +Check if we can override VPN underlay next-hop from PE1 to PE2. +""" + +import os +import sys +import json +import pytest +import functools + +CWD = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(CWD, "../")) + +# pylint: disable=C0413 +from lib import topotest +from lib.topogen import Topogen, TopoRouter, get_topogen +from lib.common_config import step + +pytestmark = [pytest.mark.bgpd] + + +def build_topo(tgen): + tgen.add_router("cpe1") + tgen.add_router("cpe2") + tgen.add_router("pe1") + tgen.add_router("pe2") + + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["cpe1"]) + switch.add_link(tgen.gears["pe1"]) + + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["pe1"]) + switch.add_link(tgen.gears["pe2"]) + + switch = tgen.add_switch("s3") + switch.add_link(tgen.gears["pe2"]) + switch.add_link(tgen.gears["cpe2"]) + + +def setup_module(mod): + tgen = Topogen(build_topo, mod.__name__) + tgen.start_topology() + + pe1 = tgen.gears["pe1"] + pe2 = tgen.gears["pe2"] + + pe1.run("ip link add RED type vrf table 1001") + pe1.run("ip link set up dev RED") + pe2.run("ip link add RED type vrf table 1001") + pe2.run("ip link set up dev RED") + pe1.run("ip link set pe1-eth0 master RED") + pe2.run("ip link set pe2-eth1 master RED") + + pe1.run("sysctl -w net.ipv4.ip_forward=1") + pe2.run("sysctl -w net.ipv4.ip_forward=1") + pe1.run("sysctl -w net.mpls.conf.pe1-eth0.input=1") + pe2.run("sysctl -w net.mpls.conf.pe2-eth1.input=1") + + router_list = tgen.routers() + + for i, (rname, router) in enumerate(router_list.items(), 1): + router.load_config( + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) + ) + router.load_config( + TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname)) + ) + router.load_config( + TopoRouter.RD_OSPF6, os.path.join(CWD, "{}/ospf6d.conf".format(rname)) + ) + router.load_config( + TopoRouter.RD_LDP, os.path.join(CWD, "{}/ldpd.conf".format(rname)) + ) + + tgen.start_router() + + +def teardown_module(mod): + tgen = get_topogen() + tgen.stop_topology() + + +def test_bgp_vpn_5549(): + tgen = get_topogen() + + pe2 = tgen.gears["pe2"] + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + def _bgp_vpn_nexthop_changed(): + output = json.loads(pe2.vtysh_cmd("show bgp ipv4 vpn json")) + expected = { + "routes": { + "routeDistinguishers": { + "192.168.1.2:2": { + "172.16.255.1/32": [ + {"valid": True, "nexthops": [{"ip": "2001:db8::1"}]} + ], + "192.168.1.0/24": [ + {"valid": True, "nexthops": [{"ip": "2001:db8:1::1"}]} + ], + } + } + } + } + return topotest.json_cmp(output, expected) + + test_func = functools.partial(_bgp_vpn_nexthop_changed) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert result is None, "Failed overriding IPv6 next-hop for VPN underlay" + + +if __name__ == "__main__": + args = ["-s"] + sys.argv[1:] + sys.exit(pytest.main(args)) From 6eeb9255450020cb90abf2d4e7de6c31a646e609 Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Fri, 18 Nov 2022 15:47:50 +0200 Subject: [PATCH 2/5] bgpd: Allow overriding MPLS VPN next-hops via route-maps Just do not reset next-hop for MPLS VPN routes. Example of 172.16.255.1/32 (using extended next-hop capability): ``` pe2# sh bgp ipv4 vpn BGP table version is 4, local router ID is 10.10.10.20, vrf id 0 Default local pref 100, local AS 65001 Status codes: s suppressed, d damped, h history, * valid, > best, = multipath, i internal, r RIB-failure, S Stale, R Removed Nexthop codes: @NNN nexthop's vrf id, < announce-nh-self Origin codes: i - IGP, e - EGP, ? - incomplete RPKI validation codes: V valid, I invalid, N Not found Network Next Hop Metric LocPrf Weight Path Route Distinguisher: 192.168.1.2:2 *>i10.0.0.0/24 2001:db8:1::1 0 100 0 65000 ? UN=2001:db8:1::1 EC{192.168.1.2:2} label=1111 type=bgp, subtype=0 *>i172.16.255.1/32 2001:db8::1 0 100 0 65000 ? UN=2001:db8::1 EC{192.168.1.2:2} label=1111 type=bgp, subtype=0 *>i192.168.1.0/24 2001:db8:1::1 0 100 0 65000 ? UN=2001:db8:1::1 EC{192.168.1.2:2} label=1111 type=bgp, subtype=0 *>i192.168.2.0/24 2001:db8:1::1 100 0 65000 ? UN=2001:db8:1::1 EC{192.168.1.2:2} label=1111 type=bgp, subtype=0 Route Distinguisher: 192.168.2.2:2 *> 10.0.0.0/24 192.168.2.1@4< 0 50 0 65000 ? UN=192.168.2.1 EC{192.168.2.2:2} label=2222 type=bgp, subtype=5 *> 172.16.255.1/32 192.168.2.1@4< 50 0 65000 ? UN=192.168.2.1 EC{192.168.2.2:2} label=2222 type=bgp, subtype=5 *> 192.168.1.0/24 192.168.2.1@4< 50 0 65000 ? UN=192.168.2.1 EC{192.168.2.2:2} label=2222 type=bgp, subtype=5 *> 192.168.2.0/24 192.168.2.1@4< 0 50 0 65000 ? UN=192.168.2.1 EC{192.168.2.2:2} label=2222 type=bgp, subtype=5 Displayed 8 routes and 8 total paths ``` Signed-off-by: Donatas Abraitis --- bgpd/bgp_attr.h | 23 ++++++++++++++--------- bgpd/bgp_routemap.c | 5 +++++ bgpd/bgp_updgrp.h | 2 ++ bgpd/bgp_updgrp_packet.c | 26 +++++++++++++++++++------- 4 files changed, 40 insertions(+), 16 deletions(-) diff --git a/bgpd/bgp_attr.h b/bgpd/bgp_attr.h index bc82d0c6ed..d5f26f240d 100644 --- a/bgpd/bgp_attr.h +++ b/bgpd/bgp_attr.h @@ -344,6 +344,8 @@ struct attr { #define BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED (1 << 6) #define BATTR_RMAP_LINK_BW_SET (1 << 7) #define BATTR_RMAP_L3VPN_ACCEPT_GRE (1 << 8) +#define BATTR_RMAP_VPNV4_NHOP_CHANGED (1 << 9) +#define BATTR_RMAP_VPNV6_GLOBAL_NHOP_CHANGED (1 << 10) /* Router Reflector related structure. */ struct cluster_list { @@ -476,15 +478,18 @@ extern enum bgp_attr_parse_ret bgp_attr_nexthop_valid(struct peer *peer, static inline int bgp_rmap_nhop_changed(uint32_t out_rmap_flags, uint32_t in_rmap_flags) { - return ((CHECK_FLAG(out_rmap_flags, BATTR_RMAP_NEXTHOP_PEER_ADDRESS) - || CHECK_FLAG(out_rmap_flags, BATTR_RMAP_NEXTHOP_UNCHANGED) - || CHECK_FLAG(out_rmap_flags, BATTR_RMAP_IPV4_NHOP_CHANGED) - || CHECK_FLAG(out_rmap_flags, - BATTR_RMAP_IPV6_GLOBAL_NHOP_CHANGED) - || CHECK_FLAG(out_rmap_flags, - BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED) - || CHECK_FLAG(out_rmap_flags, BATTR_RMAP_IPV6_LL_NHOP_CHANGED) - || CHECK_FLAG(in_rmap_flags, BATTR_RMAP_NEXTHOP_UNCHANGED)) + return ((CHECK_FLAG(out_rmap_flags, BATTR_RMAP_NEXTHOP_PEER_ADDRESS) || + CHECK_FLAG(out_rmap_flags, BATTR_RMAP_NEXTHOP_UNCHANGED) || + CHECK_FLAG(out_rmap_flags, BATTR_RMAP_IPV4_NHOP_CHANGED) || + CHECK_FLAG(out_rmap_flags, BATTR_RMAP_VPNV4_NHOP_CHANGED) || + CHECK_FLAG(out_rmap_flags, + BATTR_RMAP_VPNV6_GLOBAL_NHOP_CHANGED) || + CHECK_FLAG(out_rmap_flags, + BATTR_RMAP_IPV6_GLOBAL_NHOP_CHANGED) || + CHECK_FLAG(out_rmap_flags, + BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED) || + CHECK_FLAG(out_rmap_flags, BATTR_RMAP_IPV6_LL_NHOP_CHANGED) || + CHECK_FLAG(in_rmap_flags, BATTR_RMAP_NEXTHOP_UNCHANGED)) ? 1 : 0); } diff --git a/bgpd/bgp_routemap.c b/bgpd/bgp_routemap.c index b736e6c38a..9422469bca 100644 --- a/bgpd/bgp_routemap.c +++ b/bgpd/bgp_routemap.c @@ -3725,6 +3725,8 @@ route_set_vpnv4_nexthop(void *rule, const struct prefix *prefix, void *object) path->attr->mp_nexthop_global_in = *address; path->attr->mp_nexthop_len = BGP_ATTR_NHLEN_IPV4; + SET_FLAG(path->attr->rmap_change_flags, BATTR_RMAP_VPNV4_NHOP_CHANGED); + return RMAP_OKAY; } @@ -3762,6 +3764,9 @@ route_set_vpnv6_nexthop(void *rule, const struct prefix *prefix, void *object) sizeof(struct in6_addr)); path->attr->mp_nexthop_len = BGP_ATTR_NHLEN_VPNV6_GLOBAL; + SET_FLAG(path->attr->rmap_change_flags, + BATTR_RMAP_VPNV6_GLOBAL_NHOP_CHANGED); + return RMAP_OKAY; } diff --git a/bgpd/bgp_updgrp.h b/bgpd/bgp_updgrp.h index 56289d399d..ecd92a996e 100644 --- a/bgpd/bgp_updgrp.h +++ b/bgpd/bgp_updgrp.h @@ -88,6 +88,8 @@ typedef struct { #define BPKT_ATTRVEC_FLAGS_RMAP_IPV4_NH_CHANGED (1 << 4) #define BPKT_ATTRVEC_FLAGS_RMAP_IPV6_GNH_CHANGED (1 << 5) #define BPKT_ATTRVEC_FLAGS_RMAP_IPV6_LNH_CHANGED (1 << 6) +#define BPKT_ATTRVEC_FLAGS_RMAP_VPNV4_NH_CHANGED (1 << 7) +#define BPKT_ATTRVEC_FLAGS_RMAP_VPNV6_GNH_CHANGED (1 << 8) typedef struct bpacket_attr_vec_arr { bpacket_attr_vec entries[BGP_ATTR_VEC_MAX]; diff --git a/bgpd/bgp_updgrp_packet.c b/bgpd/bgp_updgrp_packet.c index 9de97cf060..b52d67ed3c 100644 --- a/bgpd/bgp_updgrp_packet.c +++ b/bgpd/bgp_updgrp_packet.c @@ -379,10 +379,11 @@ struct stream *bpacket_reformat_for_peer(struct bpacket *pkt, route_map_sets_nh = (CHECK_FLAG(vec->flags, - BPKT_ATTRVEC_FLAGS_RMAP_IPV4_NH_CHANGED) - || CHECK_FLAG( - vec->flags, - BPKT_ATTRVEC_FLAGS_RMAP_NH_PEER_ADDRESS)); + BPKT_ATTRVEC_FLAGS_RMAP_IPV4_NH_CHANGED) || + CHECK_FLAG(vec->flags, + BPKT_ATTRVEC_FLAGS_RMAP_VPNV4_NH_CHANGED) || + CHECK_FLAG(vec->flags, + BPKT_ATTRVEC_FLAGS_RMAP_NH_PEER_ADDRESS)); switch (nhlen) { case BGP_ATTR_NHLEN_IPV4: @@ -468,10 +469,12 @@ struct stream *bpacket_reformat_for_peer(struct bpacket *pkt, route_map_sets_nh = (CHECK_FLAG(vec->flags, - BPKT_ATTRVEC_FLAGS_RMAP_IPV6_GNH_CHANGED) - || CHECK_FLAG( + BPKT_ATTRVEC_FLAGS_RMAP_IPV6_GNH_CHANGED) || + CHECK_FLAG( vec->flags, - BPKT_ATTRVEC_FLAGS_RMAP_NH_PEER_ADDRESS)); + BPKT_ATTRVEC_FLAGS_RMAP_VPNV6_GNH_CHANGED) || + CHECK_FLAG(vec->flags, + BPKT_ATTRVEC_FLAGS_RMAP_NH_PEER_ADDRESS)); /* * The logic here is rather similar to that for IPv4, the @@ -1276,6 +1279,15 @@ bpacket_vec_arr_inherit_attr_flags(struct bpacket_attr_vec_arr *vecarr, SET_FLAG(vecarr->entries[BGP_ATTR_VEC_NH].flags, BPKT_ATTRVEC_FLAGS_RMAP_IPV6_GNH_CHANGED); + if (CHECK_FLAG(attr->rmap_change_flags, BATTR_RMAP_VPNV4_NHOP_CHANGED)) + SET_FLAG(vecarr->entries[BGP_ATTR_VEC_NH].flags, + BPKT_ATTRVEC_FLAGS_RMAP_VPNV4_NH_CHANGED); + + if (CHECK_FLAG(attr->rmap_change_flags, + BATTR_RMAP_VPNV6_GLOBAL_NHOP_CHANGED)) + SET_FLAG(vecarr->entries[BGP_ATTR_VEC_NH].flags, + BPKT_ATTRVEC_FLAGS_RMAP_VPNV6_GNH_CHANGED); + if (CHECK_FLAG(attr->rmap_change_flags, BATTR_RMAP_IPV6_LL_NHOP_CHANGED)) SET_FLAG(vecarr->entries[BGP_ATTR_VEC_NH].flags, From 6cf8a4bf428d6830eb506fa10c5854c88ca99be0 Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Fri, 18 Nov 2022 16:02:46 +0200 Subject: [PATCH 3/5] bgpd: Print prefix in logs messages with BGP_PATH_ANNC_NH_SELF Signed-off-by: Donatas Abraitis --- bgpd/bgp_route.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 6eb1a556b1..4997468ce2 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -2583,8 +2583,8 @@ bool subgroup_announce_check(struct bgp_dest *dest, struct bgp_path_info *pi, if (bgp_debug_update(NULL, p, subgrp->update_group, 0)) zlog_debug( - "%s: BGP_PATH_ANNC_NH_SELF, family=%s", - __func__, family2str(family)); + "%s: %pFX BGP_PATH_ANNC_NH_SELF, family=%s", + __func__, p, family2str(family)); subgroup_announce_reset_nhop(family, attr); nh_reset = true; } From 0224b3296c320e0b0c82b0377f44b1cbbb5582dd Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Fri, 18 Nov 2022 16:06:43 +0200 Subject: [PATCH 4/5] bgpd: Print empty JSON `{}` if no entries under `show bgp ipv4 vpn json` Before this, the application fails that is parsing JSON (expecting). Signed-off-by: Donatas Abraitis --- bgpd/bgp_route.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 4997468ce2..c3cfcef502 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -11719,6 +11719,9 @@ int bgp_show_table_rd(struct vty *vty, struct bgp *bgp, safi_t safi, vty_out(vty, "\nDisplayed %ld routes and %ld total paths\n", output_cum, total_cum); + } else { + if (use_json && output_cum == 0) + vty_out(vty, "{}\n"); } return CMD_SUCCESS; } From 6dad190d561882507c8a566f4a2099ebd7d973cd Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Fri, 18 Nov 2022 16:09:19 +0200 Subject: [PATCH 5/5] bgpd: Convert bgp_rmap_nhop_changed to bool from int Signed-off-by: Donatas Abraitis --- bgpd/bgp_attr.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bgpd/bgp_attr.h b/bgpd/bgp_attr.h index d5f26f240d..a34da1a6de 100644 --- a/bgpd/bgp_attr.h +++ b/bgpd/bgp_attr.h @@ -475,8 +475,8 @@ extern void bgp_packet_mpunreach_end(struct stream *s, size_t attrlen_pnt); extern enum bgp_attr_parse_ret bgp_attr_nexthop_valid(struct peer *peer, struct attr *attr); -static inline int bgp_rmap_nhop_changed(uint32_t out_rmap_flags, - uint32_t in_rmap_flags) +static inline bool bgp_rmap_nhop_changed(uint32_t out_rmap_flags, + uint32_t in_rmap_flags) { return ((CHECK_FLAG(out_rmap_flags, BATTR_RMAP_NEXTHOP_PEER_ADDRESS) || CHECK_FLAG(out_rmap_flags, BATTR_RMAP_NEXTHOP_UNCHANGED) || @@ -490,8 +490,8 @@ static inline int bgp_rmap_nhop_changed(uint32_t out_rmap_flags, BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED) || CHECK_FLAG(out_rmap_flags, BATTR_RMAP_IPV6_LL_NHOP_CHANGED) || CHECK_FLAG(in_rmap_flags, BATTR_RMAP_NEXTHOP_UNCHANGED)) - ? 1 - : 0); + ? true + : false); } static inline uint32_t mac_mobility_seqnum(struct attr *attr)