From 275a4b508a559aaafa0d6095a59a35ae690d9a5e Mon Sep 17 00:00:00 2001 From: Xiao Liang Date: Fri, 15 Dec 2023 18:27:39 +0800 Subject: [PATCH 1/2] bgpd: "default-originate" shouldn't withdraw non-default routes Prevent "default-originate" from withdrawing non-default routes like 0.0.0.0/1 by checking prefix length. Signed-off-by: Xiao Liang (cherry picked from commit 4d74ba929daa6e6b2fe15f9df6e61d5e4808b64c) --- bgpd/bgp_route.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index c1040c525..d9f1eda3e 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -2162,9 +2162,7 @@ bool subgroup_announce_check(struct bgp_dest *dest, struct bgp_path_info *pi, * configured for default-originate */ if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE)) { - if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY) - return false; - else if (p->family == AF_INET6 && p->prefixlen == 0) + if ((p->family == AF_INET || p->family == AF_INET6) && p->prefixlen == 0) return false; } From 2330ed61e78d21138a3d7f6122d4f80cc6a979c7 Mon Sep 17 00:00:00 2001 From: Xiao Liang Date: Mon, 18 Dec 2023 14:57:22 +0800 Subject: [PATCH 2/2] tests: Check for 0.0.0.0/1 in bgp_default_route Ensure that 0.0.0.0/1 route can be advertised along with default-originate. Signed-off-by: Xiao Liang (cherry picked from commit 4538247c995e551aed0c08c4bb20b187ce95f5f2) --- tests/topotests/bgp_default_route/r1/bgpd.conf | 1 + tests/topotests/bgp_default_route/r1/zebra.conf | 2 ++ .../test_bgp_default-originate.py | 14 +++++++++----- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/tests/topotests/bgp_default_route/r1/bgpd.conf b/tests/topotests/bgp_default_route/r1/bgpd.conf index 8699d62ff..10ced3610 100644 --- a/tests/topotests/bgp_default_route/r1/bgpd.conf +++ b/tests/topotests/bgp_default_route/r1/bgpd.conf @@ -3,6 +3,7 @@ router bgp 65000 neighbor 192.168.255.2 remote-as 65001 neighbor 192.168.255.2 timers 3 10 address-family ipv4 unicast + network 0.0.0.0/1 neighbor 192.168.255.2 default-originate exit-address-family ! diff --git a/tests/topotests/bgp_default_route/r1/zebra.conf b/tests/topotests/bgp_default_route/r1/zebra.conf index 0a283c06d..fbf97b052 100644 --- a/tests/topotests/bgp_default_route/r1/zebra.conf +++ b/tests/topotests/bgp_default_route/r1/zebra.conf @@ -1,4 +1,6 @@ ! +ip route 0.0.0.0/1 blackhole +! interface lo ip address 172.16.255.254/32 ! diff --git a/tests/topotests/bgp_default_route/test_bgp_default-originate.py b/tests/topotests/bgp_default_route/test_bgp_default-originate.py index 2463b0546..333beb067 100644 --- a/tests/topotests/bgp_default_route/test_bgp_default-originate.py +++ b/tests/topotests/bgp_default_route/test_bgp_default-originate.py @@ -69,18 +69,18 @@ def _bgp_check_if_received(): expected = { "192.168.255.1": { "bgpState": "Established", - "addressFamilyInfo": {"ipv4Unicast": {"acceptedPrefixCounter": 1}}, + "addressFamilyInfo": {"ipv4Unicast": {"acceptedPrefixCounter": 2}}, } } return topotest.json_cmp(output, expected) def _bgp_check_if_originated(): output = json.loads(tgen.gears["r1"].vtysh_cmd("show ip bgp summary json")) - expected = {"ipv4Unicast": {"peers": {"192.168.255.2": {"pfxSnt": 1}}}} + expected = {"ipv4Unicast": {"peers": {"192.168.255.2": {"pfxSnt": 2}}}} return topotest.json_cmp(output, expected) - def _bgp_default_route_is_valid(router): - output = json.loads(router.vtysh_cmd("show ip bgp 0.0.0.0/0 json")) + def _bgp_route_is_valid(router, prefix): + output = json.loads(router.vtysh_cmd("show ip bgp {} json".format(prefix))) expected = {"paths": [{"valid": True}]} return topotest.json_cmp(output, expected) @@ -92,10 +92,14 @@ def _bgp_default_route_is_valid(router): success, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5) assert result is None, "No 0.0.0.0/0 from r1 to r2" - test_func = functools.partial(_bgp_default_route_is_valid, tgen.gears["r2"]) + test_func = functools.partial(_bgp_route_is_valid, tgen.gears["r2"], "0.0.0.0/0") success, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5) assert result is None, "Failed to see 0.0.0.0/0 in r2" + test_func = functools.partial(_bgp_route_is_valid, tgen.gears["r2"], "0.0.0.0/1") + success, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5) + assert result is None, "Failed to see 0.0.0.0/1 in r2" + if __name__ == "__main__": args = ["-s"] + sys.argv[1:]