summaryrefslogtreecommitdiff
path: root/bgpd/bgp_aspath.c
diff options
context:
space:
mode:
authorFrancois Dumontet <francois.dumontet@6wind.com>2024-04-23 11:16:24 +0200
committerFrancois Dumontet <francois.dumontet@6wind.com>2024-05-16 17:49:42 +0200
commit094dcc3cdac19d3da65b38effc45aa88d960909f (patch)
tree8da1a3534f32b35c5b2973ea5f681f4163ee4d1c /bgpd/bgp_aspath.c
parentdb1e2a094d3a24b5bbf515c1d5b61ba48d85a43a (diff)
bgpd: fix "bgp as-pah access-list" with "set aspath exclude" set/unset issues
whith the following config router bgp 65001 no bgp ebgp-requires-policy neighbor 192.168.1.2 remote-as external neighbor 192.168.1.2 timers 3 10 ! address-family ipv4 unicast neighbor 192.168.1.2 route-map r2 in exit-address-family exit ! bgp as-path access-list FIRST seq 5 permit ^65 bgp as-path access-list SECOND seq 5 permit 2$ ! route-map r2 permit 6 match ip address prefix-list p2 set as-path exclude as-path-access-list SECOND exit ! route-map r2 permit 10 match ip address prefix-list p1 set as-path exclude 65003 exit ! route-map r2 permit 20 match ip address prefix-list p3 set as-path exclude all exit making some no bgp as-path access-list SECOND permit 2$ bgp as-path access-list SECOND permit 3$ clear bgp * no bgp as-path access-list SECOND permit 3$ bgp as-path access-list SECOND permit 2$ clear bgp * will induce some crashes thus we rework the links between aslists and aspath_exclude Signed-off-by: Francois Dumontet <francois.dumontet@6wind.com>
Diffstat (limited to 'bgpd/bgp_aspath.c')
-rw-r--r--bgpd/bgp_aspath.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/bgpd/bgp_aspath.c b/bgpd/bgp_aspath.c
index 9dcd0ad1d6..4c1615a5c6 100644
--- a/bgpd/bgp_aspath.c
+++ b/bgpd/bgp_aspath.c
@@ -77,6 +77,9 @@ static struct hash *ashash;
/* Stream for SNMP. See aspath_snmp_pathseg */
static struct stream *snmp_stream;
+/* as-path orphan exclude list */
+static struct as_list_list_head as_exclude_list_orphan;
+
/* Callers are required to initialize the memory */
static as_t *assegment_data_new(int num)
{
@@ -1558,6 +1561,38 @@ struct aspath *aspath_prepend(struct aspath *as1, struct aspath *as2)
/* Not reached */
}
+/* insert aspath exclude in head of orphan exclude list*/
+void as_exclude_set_orphan(struct aspath_exclude *ase)
+{
+ ase->exclude_aspath_acl = NULL;
+ as_list_list_add_head(&as_exclude_list_orphan, ase);
+}
+
+void as_exclude_remove_orphan(struct aspath_exclude *ase)
+{
+ if (as_list_list_count(&as_exclude_list_orphan))
+ as_list_list_del(&as_exclude_list_orphan, ase);
+}
+
+/* currently provide only one exclude, not a list */
+struct aspath_exclude *as_exclude_lookup_orphan(const char *acl_name)
+{
+ struct aspath_exclude *ase = NULL;
+ char *name = NULL;
+
+ frr_each (as_list_list, &as_exclude_list_orphan, ase) {
+ if (ase->exclude_aspath_acl_name) {
+ name = ase->exclude_aspath_acl_name;
+ if (!strcmp(name, acl_name))
+ break;
+ }
+ }
+ if (ase)
+ as_exclude_remove_orphan(ase);
+
+ return ase;
+}
+
/* Iterate over AS_PATH segments and wipe all occurrences of the
* listed AS numbers. Hence some segments may lose some or even
* all data on the way, the operation is implemented as a smarter
@@ -2236,14 +2271,26 @@ void aspath_init(void)
{
ashash = hash_create_size(32768, aspath_key_make, aspath_cmp,
"BGP AS Path");
+
+ as_list_list_init(&as_exclude_list_orphan);
}
void aspath_finish(void)
{
+ struct aspath_exclude *ase;
+
hash_clean_and_free(&ashash, (void (*)(void *))aspath_free);
if (snmp_stream)
stream_free(snmp_stream);
+
+ while ((ase = as_list_list_pop(&as_exclude_list_orphan))) {
+ aspath_free(ase->aspath);
+ if (ase->exclude_aspath_acl_name)
+ XFREE(MTYPE_TMP, ase->exclude_aspath_acl_name);
+ XFREE(MTYPE_ROUTE_MAP_COMPILED, ase);
+ }
+ as_list_list_fini(&as_exclude_list_orphan);
}
/* return and as path value */