From 85d93b166ecace984542739c19d82509db0a2e8a Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Tue, 15 Jun 2021 14:55:17 +0300 Subject: [PATCH 1/2] bgpd: Allow aspath prepending for default-originate with route-maps The initial idea was to deny prepending and just use _self_. This patch at least allows prepending aspath with route-maps, but drops all non-self ASNs in the path. Signed-off-by: Donatas Abraitis --- bgpd/bgp_updgrp_adv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bgpd/bgp_updgrp_adv.c b/bgpd/bgp_updgrp_adv.c index bb0c95e32f..1ba462e2f0 100644 --- a/bgpd/bgp_updgrp_adv.c +++ b/bgpd/bgp_updgrp_adv.c @@ -829,6 +829,7 @@ void subgroup_default_originate(struct update_subgroup *subgrp, int withdraw) struct bgp_path_info_extra tmp_pie; tmp_attr = *pi->attr; + tmp_attr.aspath = attr.aspath; prep_for_rmap_apply(&tmp_pi, &tmp_pie, dest, pi, pi->peer, &tmp_attr); @@ -842,7 +843,6 @@ void subgroup_default_originate(struct update_subgroup *subgrp, int withdraw) continue; } else { new_attr = bgp_attr_intern(&tmp_attr); - new_attr->aspath = attr.aspath; subgroup_announce_reset_nhop( (peer_cap_enhe(peer, afi, safi) From cc54c0729815164eb2b078e4fc09c725ad5c4ff8 Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Tue, 15 Jun 2021 15:49:24 +0300 Subject: [PATCH 2/2] tests: Check if as-path prepends work with route-maps and default-originate Signed-off-by: Donatas Abraitis --- .../bgp_default_route_route_map_match_set/r1/bgpd.conf | 1 + .../test_bgp_default-originate_route-map_match_set.py | 4 +++- tests/topotests/bgp_default_route_route_map_set/r1/bgpd.conf | 1 + .../test_bgp_default-originate_route-map_set.py | 4 +++- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/topotests/bgp_default_route_route_map_match_set/r1/bgpd.conf b/tests/topotests/bgp_default_route_route_map_match_set/r1/bgpd.conf index 6ef8b1c0f4..32ac7c517b 100644 --- a/tests/topotests/bgp_default_route_route_map_match_set/r1/bgpd.conf +++ b/tests/topotests/bgp_default_route_route_map_match_set/r1/bgpd.conf @@ -12,6 +12,7 @@ bgp community-list standard default seq 5 permit 65000:1 route-map default permit 10 match community default set metric 123 + set as-path prepend 65000 65000 65000 ! route-map internal permit 10 set community 65000:1 diff --git a/tests/topotests/bgp_default_route_route_map_match_set/test_bgp_default-originate_route-map_match_set.py b/tests/topotests/bgp_default_route_route_map_match_set/test_bgp_default-originate_route-map_match_set.py index d9ea5db278..12d1d01bfb 100644 --- a/tests/topotests/bgp_default_route_route_map_match_set/test_bgp_default-originate_route-map_match_set.py +++ b/tests/topotests/bgp_default_route_route_map_match_set/test_bgp_default-originate_route-map_match_set.py @@ -94,7 +94,9 @@ def test_bgp_default_originate_route_map(): def _bgp_default_route_has_metric(router): output = json.loads(router.vtysh_cmd("show ip bgp 0.0.0.0/0 json")) - expected = {"paths": [{"metric": 123}]} + expected = { + "paths": [{"aspath": {"string": "65000 65000 65000 65000"}, "metric": 123}] + } return topotest.json_cmp(output, expected) test_func = functools.partial(_bgp_converge, router) diff --git a/tests/topotests/bgp_default_route_route_map_set/r1/bgpd.conf b/tests/topotests/bgp_default_route_route_map_set/r1/bgpd.conf index cb07ea9fdf..6f6d394402 100644 --- a/tests/topotests/bgp_default_route_route_map_set/r1/bgpd.conf +++ b/tests/topotests/bgp_default_route_route_map_set/r1/bgpd.conf @@ -8,4 +8,5 @@ router bgp 65000 ! route-map default permit 10 set metric 123 + set as-path prepend 65000 65000 65000 ! diff --git a/tests/topotests/bgp_default_route_route_map_set/test_bgp_default-originate_route-map_set.py b/tests/topotests/bgp_default_route_route_map_set/test_bgp_default-originate_route-map_set.py index 9a22c58b16..2622c33f5b 100644 --- a/tests/topotests/bgp_default_route_route_map_set/test_bgp_default-originate_route-map_set.py +++ b/tests/topotests/bgp_default_route_route_map_set/test_bgp_default-originate_route-map_set.py @@ -93,7 +93,9 @@ def test_bgp_default_originate_route_map(): def _bgp_default_route_has_metric(router): output = json.loads(router.vtysh_cmd("show ip bgp 0.0.0.0/0 json")) - expected = {"paths": [{"metric": 123}]} + expected = { + "paths": [{"aspath": {"string": "65000 65000 65000 65000"}, "metric": 123}] + } return topotest.json_cmp(output, expected) test_func = functools.partial(_bgp_converge, router)