summaryrefslogtreecommitdiff
path: root/bgpd/bgp_aspath.c
AgeCommit message (Collapse)Author
2024-10-24bgpd: Store aspath count after aspath has changedDonald Sharp
When running bestpath on a very large number of ecmp. BGP ends up calling aspath_count a very very large number of times, which results in ~15% cpu runtime in aspath_count_hops. Modify the aspath to keep track of it's own count. This results in the function now taking up ~1.5% of the cpu runtime. Enough for the moment to be ignored. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2024-05-16bgpd: fix "bgp as-pah access-list" with "set aspath exclude" set/unset issuesFrancois Dumontet
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>
2024-03-14bgpd: Add some missing data to `show bgp attribute-info`Donald Sharp
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-11-14bgpd:aspath leak fixryndia
The function aspath_remove_private_asns was using an aspath to perform some operation and didnt free it after usage leading to the leak below. *********************************************************************************** Address Sanitizer Error detected in bgp_remove_private_as_route_map.test_bgp_remove_private_as_route_map/r2.asan.bgpd.27074 ================================================================= ==27074==ERROR: LeakSanitizer: detected memory leaks Direct leak of 80 byte(s) in 2 object(s) allocated from: #0 0x7fd0a4b95d28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28) #1 0x7fd0a45932ff in qcalloc lib/memory.c:105 #2 0x562b630b44cc in aspath_dup bgpd/bgp_aspath.c:689 #3 0x562b62f48498 in route_set_aspath_prepend bgpd/bgp_routemap.c:2283 #4 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690 #5 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434 #6 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990 #7 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765 #8 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818 #9 0x562b62f6ae90 in subgroup_coalesce_timer bgpd/bgp_updgrp_adv.c:368 #10 0x7fd0a463322a in event_call lib/event.c:1970 #11 0x7fd0a4576566 in frr_run lib/libfrr.c:1214 #12 0x562b62dbd8f1 in main bgpd/bgp_main.c:510 #13 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86) Direct leak of 80 byte(s) in 2 object(s) allocated from: #0 0x7fd0a4b95d28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28) #1 0x7fd0a45932ff in qcalloc lib/memory.c:105 #2 0x562b630b44cc in aspath_dup bgpd/bgp_aspath.c:689 #3 0x562b62f48498 in route_set_aspath_prepend bgpd/bgp_routemap.c:2283 #4 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690 #5 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434 #6 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990 #7 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765 #8 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818 #9 0x562b62f5b844 in updgrp_policy_update_walkcb bgpd/bgp_updgrp.c:1685 #10 0x562b62f59442 in update_group_walkcb bgpd/bgp_updgrp.c:1721 #11 0x7fd0a455a7aa in hash_walk lib/hash.c:270 #12 0x562b62f64a48 in update_group_af_walk bgpd/bgp_updgrp.c:2062 #13 0x562b62f6508c in update_group_walk bgpd/bgp_updgrp.c:2071 #14 0x562b62f6520c in update_group_policy_update bgpd/bgp_updgrp.c:1769 #15 0x562b62f4c2be in bgp_route_map_process_update bgpd/bgp_routemap.c:4501 #16 0x562b62f4d81a in bgp_route_map_process_update_cb bgpd/bgp_routemap.c:4683 #17 0x7fd0a45ed7e8 in route_map_walk_update_list lib/routemap.c:870 #18 0x562b62f337a2 in bgp_route_map_update_timer bgpd/bgp_routemap.c:4695 #19 0x7fd0a463322a in event_call lib/event.c:1970 #20 0x7fd0a4576566 in frr_run lib/libfrr.c:1214 #21 0x562b62dbd8f1 in main bgpd/bgp_main.c:510 #22 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86) Indirect leak of 64 byte(s) in 2 object(s) allocated from: #0 0x7fd0a4b95b40 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb40) #1 0x7fd0a459301f in qmalloc lib/memory.c:100 #2 0x562b630b313f in aspath_make_str_count bgpd/bgp_aspath.c:551 #3 0x562b630b3ecf in aspath_str_update bgpd/bgp_aspath.c:659 #4 0x562b630b88b7 in aspath_prepend bgpd/bgp_aspath.c:1484 #5 0x562b62f484a8 in route_set_aspath_prepend bgpd/bgp_routemap.c:2289 #6 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690 #7 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434 #8 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990 #9 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765 #10 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818 #11 0x562b62f6ae90 in subgroup_coalesce_timer bgpd/bgp_updgrp_adv.c:368 #12 0x7fd0a463322a in event_call lib/event.c:1970 #13 0x7fd0a4576566 in frr_run lib/libfrr.c:1214 #14 0x562b62dbd8f1 in main bgpd/bgp_main.c:510 #15 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86) Indirect leak of 64 byte(s) in 2 object(s) allocated from: #0 0x7fd0a4b95b40 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb40) #1 0x7fd0a459301f in qmalloc lib/memory.c:100 #2 0x562b630b313f in aspath_make_str_count bgpd/bgp_aspath.c:551 #3 0x562b630b3ecf in aspath_str_update bgpd/bgp_aspath.c:659 #4 0x562b630b88b7 in aspath_prepend bgpd/bgp_aspath.c:1484 #5 0x562b62f484a8 in route_set_aspath_prepend bgpd/bgp_routemap.c:2289 #6 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690 #7 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434 #8 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990 #9 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765 #10 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818 #11 0x562b62f5b844 in updgrp_policy_update_walkcb bgpd/bgp_updgrp.c:1685 #12 0x562b62f59442 in update_group_walkcb bgpd/bgp_updgrp.c:1721 #13 0x7fd0a455a7aa in hash_walk lib/hash.c:270 #14 0x562b62f64a48 in update_group_af_walk bgpd/bgp_updgrp.c:2062 #15 0x562b62f6508c in update_group_walk bgpd/bgp_updgrp.c:2071 #16 0x562b62f6520c in update_group_policy_update bgpd/bgp_updgrp.c:1769 #17 0x562b62f4c2be in bgp_route_map_process_update bgpd/bgp_routemap.c:4501 #18 0x562b62f4d81a in bgp_route_map_process_update_cb bgpd/bgp_routemap.c:4683 #19 0x7fd0a45ed7e8 in route_map_walk_update_list lib/routemap.c:870 #20 0x562b62f337a2 in bgp_route_map_update_timer bgpd/bgp_routemap.c:4695 #21 0x7fd0a463322a in event_call lib/event.c:1970 #22 0x7fd0a4576566 in frr_run lib/libfrr.c:1214 #23 0x562b62dbd8f1 in main bgpd/bgp_main.c:510 #24 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86) Indirect leak of 48 byte(s) in 2 object(s) allocated from: #0 0x7fd0a4b95d28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28) #1 0x7fd0a45932ff in qcalloc lib/memory.c:105 #2 0x562b630b280d in assegment_new bgpd/bgp_aspath.c:105 #3 0x562b630b28f7 in assegment_dup bgpd/bgp_aspath.c:145 #4 0x562b630b29e8 in assegment_dup_all bgpd/bgp_aspath.c:162 #5 0x562b630b8895 in aspath_prepend bgpd/bgp_aspath.c:1483 #6 0x562b62f484a8 in route_set_aspath_prepend bgpd/bgp_routemap.c:2289 #7 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690 #8 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434 #9 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990 #10 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765 #11 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818 #12 0x562b62f5b844 in updgrp_policy_update_walkcb bgpd/bgp_updgrp.c:1685 #13 0x562b62f59442 in update_group_walkcb bgpd/bgp_updgrp.c:1721 #14 0x7fd0a455a7aa in hash_walk lib/hash.c:270 #15 0x562b62f64a48 in update_group_af_walk bgpd/bgp_updgrp.c:2062 #16 0x562b62f6508c in update_group_walk bgpd/bgp_updgrp.c:2071 #17 0x562b62f6520c in update_group_policy_update bgpd/bgp_updgrp.c:1769 #18 0x562b62f4c2be in bgp_route_map_process_update bgpd/bgp_routemap.c:4501 #19 0x562b62f4d81a in bgp_route_map_process_update_cb bgpd/bgp_routemap.c:4683 #20 0x7fd0a45ed7e8 in route_map_walk_update_list lib/routemap.c:870 #21 0x562b62f337a2 in bgp_route_map_update_timer bgpd/bgp_routemap.c:4695 #22 0x7fd0a463322a in event_call lib/event.c:1970 #23 0x7fd0a4576566 in frr_run lib/libfrr.c:1214 #24 0x562b62dbd8f1 in main bgpd/bgp_main.c:510 #25 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86) Indirect leak of 48 byte(s) in 2 object(s) allocated from: #0 0x7fd0a4b95d28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28) #1 0x7fd0a45932ff in qcalloc lib/memory.c:105 #2 0x562b630b280d in assegment_new bgpd/bgp_aspath.c:105 #3 0x562b630b28f7 in assegment_dup bgpd/bgp_aspath.c:145 #4 0x562b630b29e8 in assegment_dup_all bgpd/bgp_aspath.c:162 #5 0x562b630b8895 in aspath_prepend bgpd/bgp_aspath.c:1483 #6 0x562b62f484a8 in route_set_aspath_prepend bgpd/bgp_routemap.c:2289 #7 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690 #8 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434 #9 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990 #10 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765 #11 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818 #12 0x562b62f6ae90 in subgroup_coalesce_timer bgpd/bgp_updgrp_adv.c:368 #13 0x7fd0a463322a in event_call lib/event.c:1970 #14 0x7fd0a4576566 in frr_run lib/libfrr.c:1214 #15 0x562b62dbd8f1 in main bgpd/bgp_main.c:510 #16 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86) Indirect leak of 16 byte(s) in 2 object(s) allocated from: #0 0x7fd0a4b95b40 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb40) #1 0x7fd0a459301f in qmalloc lib/memory.c:100 #2 0x562b630b2879 in assegment_data_new bgpd/bgp_aspath.c:83 #3 0x562b630b2879 in assegment_new bgpd/bgp_aspath.c:108 #4 0x562b630b28f7 in assegment_dup bgpd/bgp_aspath.c:145 #5 0x562b630b29e8 in assegment_dup_all bgpd/bgp_aspath.c:162 #6 0x562b630b8895 in aspath_prepend bgpd/bgp_aspath.c:1483 #7 0x562b62f484a8 in route_set_aspath_prepend bgpd/bgp_routemap.c:2289 #8 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690 #9 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434 #10 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990 #11 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765 #12 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818 #13 0x562b62f6ae90 in subgroup_coalesce_timer bgpd/bgp_updgrp_adv.c:368 #14 0x7fd0a463322a in event_call lib/event.c:1970 #15 0x7fd0a4576566 in frr_run lib/libfrr.c:1214 #16 0x562b62dbd8f1 in main bgpd/bgp_main.c:510 #17 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86) Indirect leak of 16 byte(s) in 2 object(s) allocated from: #0 0x7fd0a4b95b40 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb40) #1 0x7fd0a459301f in qmalloc lib/memory.c:100 #2 0x562b630b2879 in assegment_data_new bgpd/bgp_aspath.c:83 #3 0x562b630b2879 in assegment_new bgpd/bgp_aspath.c:108 #4 0x562b630b28f7 in assegment_dup bgpd/bgp_aspath.c:145 #5 0x562b630b29e8 in assegment_dup_all bgpd/bgp_aspath.c:162 #6 0x562b630b8895 in aspath_prepend bgpd/bgp_aspath.c:1483 #7 0x562b62f484a8 in route_set_aspath_prepend bgpd/bgp_routemap.c:2289 #8 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690 #9 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434 #10 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990 #11 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765 #12 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818 #13 0x562b62f5b844 in updgrp_policy_update_walkcb bgpd/bgp_updgrp.c:1685 #14 0x562b62f59442 in update_group_walkcb bgpd/bgp_updgrp.c:1721 #15 0x7fd0a455a7aa in hash_walk lib/hash.c:270 #16 0x562b62f64a48 in update_group_af_walk bgpd/bgp_updgrp.c:2062 #17 0x562b62f6508c in update_group_walk bgpd/bgp_updgrp.c:2071 #18 0x562b62f6520c in update_group_policy_update bgpd/bgp_updgrp.c:1769 #19 0x562b62f4c2be in bgp_route_map_process_update bgpd/bgp_routemap.c:4501 #20 0x562b62f4d81a in bgp_route_map_process_update_cb bgpd/bgp_routemap.c:4683 #21 0x7fd0a45ed7e8 in route_map_walk_update_list lib/routemap.c:870 #22 0x562b62f337a2 in bgp_route_map_update_timer bgpd/bgp_routemap.c:4695 #23 0x7fd0a463322a in event_call lib/event.c:1970 #24 0x7fd0a4576566 in frr_run lib/libfrr.c:1214 #25 0x562b62dbd8f1 in main bgpd/bgp_main.c:510 #26 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86) SUMMARY: AddressSanitizer: 416 byte(s) leaked in 16 allocation(s). *********************************************************************************** Signed-off-by: ryndia <dindyalsarvesh@gmail.com>
2023-10-12build: add -Wimplicit-fallthroughIgor Ryzhov
Also: - replace all /* fallthrough */ comments with portable fallthrough; pseudo keyword to accomodate both gcc and clang - add missing break; statements as required by older versions of gcc - cleanup some code to remove unnecessary fallthrough Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2023-10-05bgpd: Drop redundant assignment for aspath segment type and lengthDonatas Abraitis
They are already initialized via assegment_new(). Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2023-09-20bgpd: fix coverity issue on aspath_filter_exclude_aclFrancois Dumontet
CID 1566378 (#1-4 of 4): Use after free (USE_AFTER_FREE)76. use_after_free: Using freed pointer cur_seg. now the prev_seg pointer is set with always existaing values. Link: https://scan7.scan.coverity.com/reports.htm#v39104/p13747/fileInstanceId=146858993&defectInstanceId=18968273&mergedDefectId=1566378&fileStart=1376&fileEnd=1625 Fixes: 4685db418e3a861205a28f975afeb9869f674337 (bgpd: add set as-path exclude acl-list command) Signed-off-by: Francois Dumontet <francois.dumontet@6wind.com>
2023-08-07bgpd: add set as-path exclude acl-list commandFrancois Dumontet
A route-map applied on incoming BGP updates is not able to replace an unwanted as segments by another one. unwanted as segment are based on an AS path access-list. The below configuration illustrates the case: router bgp 65001 address-family ipv4 unicast neighbor 192.168.1.2 route-map rule_2 in exit-address-family bgp as-path access-list RULE permit ^65 route-map rule_2 permit 10 set as-path replace as-path-access-list RULE 6000 ``` BGP routing table entry for 10.10.10.10/32, version 13 Paths: (1 available, best #1, table default) Advertised to non peer-group peers: 192.168.10.65 65000 1 2 3 123 192.168.10.65 from 192.168.10.65 (10.10.10.11) Origin IGP, metric 0, valid, external, best (First path received) ``` After: ``` do show ip bgp 10.10.10.10/32 BGP routing table entry for 10.10.10.10/32, version 15 Paths: (1 available, best #1, table default) Advertised to non peer-group peers: 192.168.10.65 6000 1 2 3 123 192.168.10.65 from 192.168.10.65 (10.10.10.11) Origin IGP, metric 0, valid, external, best (First path received) ``` Signed-off-by: Francois Dumontet <francois.dumontet@6wind.com>
2023-07-19bgpd: add set as-path exclude acl-list commandFrancois Dumontet
A route-map applied on incoming BGP updates is not able to exclude the unwanted as segments, based on an AS path access-list. The below configuration illustrates the case: router bgp 65001 address-family ipv4 unicast neighbor 192.168.1.2 route-map rule_2 in exit-address-family bgp as-path access-list RULE permit ^65 route-map rule_2 permit 10 set as-path exclude as-path-access-list RULE ``` BGP routing table entry for 10.10.10.10/32, version 13 Paths: (1 available, best #1, table default) Advertised to non peer-group peers: 192.168.10.65 65000 1 2 3 123 192.168.10.65 from 192.168.10.65 (10.10.10.11) Origin IGP, metric 0, valid, external, best (First path received) ``` After: ``` do show ip bgp 10.10.10.10/32 BGP routing table entry for 10.10.10.10/32, version 15 Paths: (1 available, best #1, table default) Advertised to non peer-group peers: 192.168.10.65 2 3 123 192.168.10.65 from 192.168.10.65 (10.10.10.11) Origin IGP, metric 0, valid, external, best (First path received) ``` Signed-off-by: Francois Dumontet <francois.dumontet@6wind.com>
2023-06-19bgpd: add 'set as-path exclude all' commandPhilippe Guibert
It is not possible to flush all the incoming as-path list from a given BGP update. Add a route-map set command to remove all as-paths from a given AS path. Add the necessary tests. Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2023-03-21*: Add a hash_clean_and_free() functionDonald Sharp
Add a hash_clean_and_free() function as well as convert the code to use it. This function also takes a double pointer to the hash to set it NULL. Also it cleanly does nothing if the pointer is NULL( as a bunch of code tested for ). Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-15bgpd: Free previously dup'ed aspath attribute for aggregate routesDonatas Abraitis
Fixes memory leak: ``` ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.653233:Direct leak of 80 byte(s) in 2 object(s) allocated f rom: ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.653233- 0 0x7fcce641b037 in __interceptor_calloc ../../ ../../src/libsanitizer/asan/asan_malloc_linux.cpp:154 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.653233- 1 0x7fcce601f874 in qcalloc lib/memory.c:105 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.653233- 2 0x55a9594c805e in aspath_dup bgpd/bgp_aspath.c:688 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.653233- 3 0x55a9594cf55b in bgp_aggr_aspath_prepare bgpd/bgp_aspath.c:2164 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.653233- 4 0x7fcce5fbc95a in hash_iterate lib/hash.c:252 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.653233- 5 0x55a9594cf82f in bgp_compute_aggregate_aspath_val bgpd/bgp_aspath.c:2223 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.653233- 6 0x55a9594cf5db in bgp_compute_aggregate_aspath bgpd/bgp_aspath.c:2179 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.653233- 7 0x55a9592740fb in bgp_add_route_to_aggregate bgpd/bgp_route.c:8035 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.653233- 8 0x55a9592750ec in bgp_aggregate_increment bgpd/bgp_route.c:8234 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.653233- 9 0x55a959263174 in bgp_update bgpd/bgp_route.c:4797 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.653233- 10 0x55a9592696c9 in bgp_nlri_parse_ip bgpd/bgp_route.c:6070 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.653233- 11 0x55a959210649 in bgp_nlri_parse bgpd/bgp_packet.c:339 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.653233- 12 0x55a95921a3a1 in bgp_update_receive bgpd/bgp_packet.c:2023 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.653233- 13 0x55a95922159b in bgp_process_packet bgpd/bgp_packet.c:2933 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.653233- 14 0x7fcce60eaa50 in thread_call lib/thread.c:1991 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.653233- 15 0x7fcce5fe2e54 in frr_run lib/libfrr.c:1185 ./bgp_local_asn_dot.test_bgp_local_asn_dot_agg/r3.bgpd.asan.653233- 16 0x55a9590d256d in main bgpd/bgp_main.c:505 ``` Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2023-02-21Merge pull request #12248 from pguibert6WIND/bgpasdotRuss White
lib, bgp: add initial support for asdot format
2023-02-10bgpd: aspath list format binds on as-notation formatPhilippe Guibert
Each BGP prefix may have an as-path list attached. A forged string is stored in the BGP attribute and shows the as-path list output. Before this commit, the as-path list output was expressed as a list of AS values in plain format. Now, if a given BGP instance uses a specific asnotation, then the output is changed: new output: router bgp 1.1 asnotation dot ! address-family ipv4 unicast network 10.200.0.0/24 route-map rmap network 10.201.0.0/24 route-map rmap redistribute connected route-map rmap exit-address-family exit ! route-map rmap permit 1 set as-path prepend 1.1 5433.55 264564564 exit ubuntu2004# do show bgp ipv4 BGP table version is 2, local router ID is 10.0.2.15, vrf id 0 Default local pref 100, local AS 1.1 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 *> 4.4.4.4/32 0.0.0.0 0 32768 1.1 5433.55 4036.61268 ? *> 10.0.2.0/24 0.0.0.0 0 32768 1.1 5433.55 4036.61268 ? 10.200.0.0/24 0.0.0.0 0 32768 1.1 5433.55 4036.61268 i 10.201.0.0/24 0.0.0.0 0 32768 1.1 5433.55 4036.61268 i The changes include: - the aspath structure has a new field: asnotation type The ashash list will differentiate 2 aspaths using a different asnotation. - 3 new printf extensions display the as number in the wished format: pASP, pASD, pASE for plain, dot, or dot+ format (extended). Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2023-02-10lib, bgp: add initial support for asdot formatPhilippe Guibert
AS number can be defined as an unsigned long number, or two uint16 values separated by a period (.). The possible valus are: - usual 32 bit values : [1;2^32 -1] - <1.65535>.<0.65535> for dot notation - <0.65535>.<0.65535> for dot+ notation. The 0.0 value is forbidden when configuring BGP instances or peer configurations. A new ASN type is added for parsing in the vty. The following commands use that new identifier: - router bgp .. - bgp confederation .. - neighbor <> remote-as <> - neighbor <> local-as <> - clear ip bgp <> - route-map / set as-path <> An asn library is available in lib/ and provides some services: - convert an as string into an as number. - parse an as path list string and extract a number. - convert an as number into a string. Also, the bgp tests forge an as_zero_path, and to do that, an API to relax the possibility to have a 0 as value is specifically called from the tests. Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2023-02-09*: auto-convert to SPDX License IDsDavid Lamparter
Done with a combination of regex'ing and banging my head against a wall. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2023-01-27bgpd: fix format string mess in AS-path printingDavid Lamparter
This was done *very* weirdly. Make it slightly less so. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2022-11-25bgp: fix case where confederation id same as member-asFrancois Dumontet
currently the following configuration dut: ! interface ntfp2 ip router isis 1 ! router bgp 200 no bgp ebgp-requires-policy bgp confederation identifier 300 bgp confederation peers 300 neighbor 192.168.1.1 remote-as 100 neighbor 192.168.2.2 remote-as 300 ! address-family ipv4 unicast neighbor 192.168.2.2 default-originate exit-address-family ! router isis 1 is-type level-2-only net 49.0001.0002.0002.0002.00 redistribute ipv4 connected level-2 ! end router: ! interface ntfp2 ip router isis 1 isis circuit-type level-2-only ! router bgp 300 no bgp ebgp-requires-policy bgp confederation identifier 300 bgp confederation peers 200 neighbor 192.168.2.1 remote-as 200 neighbor 192.168.3.2 remote-as 400 ! address-family ipv4 unicast network 3.3.3.0/24 exit-address-family ! router isis 1 is-type level-2-only net 49.0001.0003.0003.0003.00 redistribute ipv4 connected level-2 ! end on dut result of show bgp ipv4 unicast command is: show bgp ipv4 unicast BGP table version is 1, local router ID is 192.168.2.1, vrf id 0 Default local pref 100, local AS 200 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 *> 1.1.1.0/24 192.168.1.1 0 0 100 i instead of sho bgp ipv4 unicast BGP table version is 3, local router ID is 192.168.2.1, vrf id 0 Default local pref 100, local AS 200 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 *> 1.1.1.0/24 192.168.1.1 0 0 100 i *> 3.3.3.0/24 192.168.2.2 0 100 0 (300) i *> 4.4.4.0/24 192.168.3.2 0 100 0 (300) 400 i Displayed 3 routes and 3 total paths According to RFC 5065:the usage of one of the member AS number as the confederation identifier is not forbidden. fixes are the following in bgp_route.c: in bgp_update remove the test for presence of confederation id in as_path since, this case is allowed; in bgp_vty.c bgp_confederation_peers, remove the test on peer as value in bgpd.c bgp_confederation_peers_add remove the test on peer as value invert the order of setting peer->sort value and peer->local_as, since peer->sort is depending from current peer->local_as value bgp_confederation_peers_remove invert the order of setting peer->sort value and peer->local_as, since peer->sort is depending from current peer->local_as value Signed-off-by: Francois Dumontet <francois.dumontet@6wind.com>
2022-07-29bgpd: Do not check if the whole as-path has target ASN when using as-overrideDonatas Abraitis
as-override didn't work if the entire as-path is not a single ASN (as a target). Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-05-11*: Properly use memset() when zeroingDonatas Abraitis
Wrong: memset(&a, 0, sizeof(struct ...)); Good: memset(&a, 0, sizeof(a)); Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-05-03*: remove the checking returned value for hash_get()anlan_cs
Firstly, *keep no change* for `hash_get()` with NULL `alloc_func`. Only focus on cases with non-NULL `alloc_func` of `hash_get()`. Since `hash_get()` with non-NULL `alloc_func` parameter shall not fail, just ignore the returned value of it. The returned value must not be NULL. So in this case, remove the unnecessary checking NULL or not for the returned value and add `void` in front of it. Importantly, also *keep no change* for the two cases with non-NULL `alloc_func` - 1) Use `assert(<returned_data> == <searching_data>)` to ensure it is a created node, not a found node. Refer to `isis_vertex_queue_insert()` of isisd, there are many examples of this case in isid. 2) Use `<returned_data> != <searching_data>` to judge it is a found node, then free <searching_data>. Refer to `aspath_intern()` of bgpd, there are many examples of this case in bgpd. Here, <returned_data> is the returned value from `hash_get()`, and <searching_data> is the data, which is to be put into hash table. Signed-off-by: anlan_cs <vic.lan@pica8.com>
2022-04-25bgpd: Add `set as-path replace <any|ASN>` cmd for route-mapsDonatas Abraitis
``` route-map tstas permit 10 set as-path replace 1 exit ``` Before: ``` donatas-laptop(config-router-af)# do show ip bgp 10.10.10.10/32 BGP routing table entry for 10.10.10.10/32, version 13 Paths: (1 available, best #1, table default) Advertised to non peer-group peers: 192.168.10.65 65000 1 2 3 123 192.168.10.65 from 192.168.10.65 (10.10.10.11) Origin IGP, metric 0, valid, external, best (First path received) Last update: Mon Apr 25 10:39:50 2022 ``` After: ``` donatas-laptop(config-router-af)# do show ip bgp 10.10.10.10/32 BGP routing table entry for 10.10.10.10/32, version 15 Paths: (1 available, best #1, table default) Advertised to non peer-group peers: 192.168.10.65 65000 65010 2 3 123 192.168.10.65 from 192.168.10.65 (10.10.10.11) Origin IGP, metric 0, valid, external, best (First path received) Last update: Mon Apr 25 10:40:16 2022 ``` Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-04-19*: Fix spelling of seperatorDonald Sharp
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-02-09bgpd: Check for NULL inside aspath_unintern()Donatas Abraitis
It's not always guarded, just check inside. Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2022-01-24bgpd: retain peer asn even with remove-private-ASTrey Aspelund
In situations where remove-private-AS is configured for eBGP peers residing in a private ASN, the peer's ASN was not being retained in the AS-Path which can allow loops to occur. This was addressed in a prior commit but it only addressed cases where the "replace-AS" keyword was configured. This commit ensures we retain the peer's ASN when using "remove-private-AS" for eBGP peers in a private ASN regardless of other keywords. Setup: ========= router bgp 4200000002 neighbor enp1s0 interface v6only remote-as external neighbor enp6s0 interface v6only remote-as external ! address-family ipv4 unicast neighbor enp6s0 remove-private-AS exit-address-family ub18# show ip bgp sum | include 420000 BGP router identifier 100.64.0.111, local AS number 4200000002 vrf-id 0 <<<<< local asn 4200000002 ub20(enp1s0) 4 4200000001 22 22 0 0 0 00:00:57 1 1 ub20(enp6s0) 4 4200000001 21 22 0 0 0 00:00:57 0 1 <<<< peer asn 4200000001 ub18# show ip bgp | include 0.2 Default local pref 100, local AS 4200000002 *> 100.64.0.2/32 enp1s0 0 0 4200000001 4200000004 4200000005 4200000001 i Before ("remote-private-AS" only): ========= ub18# show ip bgp neighbors enp6s0 advertised-routes | include 100.64.0.2 *> 100.64.0.2/32 :: 0 i <<<<< empty as-path, no way to prevent loop After ("remote-private-AS" only): ========= ub18# show ip bgp neighbors enp6s0 advertised-routes | include 100.64.0.2 *> 100.64.0.2/32 :: 0 4200000001 4200000001 i <<<< retain peer's asn, breaks loop Ticket: 2857047 Signed-off-by: Trey Aspelund <taspelund@nvidia.com>
2021-11-11*: use compiler.h MIN/MAX macros instead of everyone having oneDonald Sharp
We had various forms of min/max macros across multiple daemons all of which duplicated what we have in compiler.h. Convert everyone to use the `correct` ones Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-06-29bgpd: Avoid more assignments within checks (round 2)Donatas Abraitis
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-06-17bgpd: Do not check against aspath `seg` which is already checked beforeDonatas Abraitis
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2020-07-14*: un-split strings across linesDavid Lamparter
Remove mid-string line breaks, cf. workflow doc: .. [#tool_style_conflicts] For example, lines over 80 characters are allowed for text strings to make it possible to search the code for them: please see `Linux kernel style (breaking long lines and strings) <https://www.kernel.org/doc/html/v4.10/process/coding-style.html#breaking-long-lines-and-strings>`_ and `Issue #1794 <https://github.com/FRRouting/frr/issues/1794>`_. Scripted commit, idempotent to running: ``` python3 tools/stringmangle.py --unwrap `git ls-files | egrep '\.[ch]$'` ``` Signed-off-by: David Lamparter <equinox@diac24.net>
2020-03-17Merge pull request #5954 from ton31337/feature/rfc7607Russ White
bgpd: Proscribe the use of AS 0 (zero)
2020-03-17bgpd: Proscribe the use of AS 0 (zero)Donatas Abraitis
Implements https://tools.ietf.org/html/rfc7607 Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2020-03-12Merge pull request #5979 from ton31337/fix/convert_to_bool_some_functionsSri Mohana Singamsetty
bgpd: Convert type int functions to bool which return 0/1 only
2020-03-11*: Remove tests for some XFREE-family functionsDonatas Abraitis
XFREE() covers that. Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2020-03-11bgpd: Convert type int functions to bool which return 0/1 onlyDonatas Abraitis
This is only for bgp_aspath.[ch] Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2020-03-08*: Replace `sizeof something` to sizeof(something)Donatas Abraitis
Satisfy checkpatch.pl requirements (check for sizeof without parenthesis) Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2020-02-28*: change hash_backet to hash_bucketDonald Sharp
It's been a year search and destroy. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com> Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2020-02-27bgpd: Cleanup set but unused variablesDonald Sharp
There existed some variables set but never used. Clean this up. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-12-03Merge pull request #5305 from ↵Donald Sharp
ton31337/feature/draft-ietf-idr-deprecate-as-set-confed-set bgpd: Reject incoming and outgoing UPDATES for AS_SET and AS_CONFED_SET
2019-12-02*: generously apply constDavid Lamparter
const const const your boat, merrily down the stream... Signed-off-by: David Lamparter <equinox@diac24.net>
2019-11-14bgpd: Reject routes having AS_SET or AS_CONFED_SETDonatas Abraitis
This is the first step towards eliminating AS_SET and AS_CONFED_SET types and obsolete them in the future. More information: https://datatracker.ietf.org/doc/html/draft-ietf-idr-deprecate-as-set-confed-set-02 Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2019-10-09bgpd: AS paths are uint32_t instead of integersDonald Sharp
We have some JSON output that was displaying high order AS path data as negative numbers: { "paths":[ { "aspath":{ "string":"4200010118 4200010000 20473 1299", "segments":[ { "type":"as-sequence", "list":[ -94957178, -94957296, 20473, 1299 ] } ], Notice "String" output -vs- the list. With fixed code: "paths":[ { "aspath":{ "string":"64539 4294967000 15096 6939 7922 7332 4249", "segments":[ { "type":"as-sequence", "list":[ 64539, 4294967000, 15096, 6939, 7922, 7332, 4249 ] } ], Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-09-24bgpd : route agg. with aspath attribute is consuming lot of cycles.vdhingra
While configuring aggregate route prepare the hash table first, then prepare the aggregated aspath value just like lcomm, ecomm and standard community. Signed-off-by: vishaldhingra<vdhingra@vmware.com>
2019-08-19*: Fix spelling errors pointed out by debian packagingDonald Sharp
Debian packaging when run finds a bunch of spelling errors: I: frr: spelling-error-in-binary usr/bin/vtysh occurences occurrences I: frr: spelling-error-in-binary usr/lib/frr/bfdd Amount of times Number of times I: frr: spelling-error-in-binary usr/lib/frr/bgpd occurences occurrences I: frr: spelling-error-in-binary usr/lib/frr/bgpd recieved received I: frr: spelling-error-in-binary usr/lib/frr/isisd betweeen between I: frr: spelling-error-in-binary usr/lib/frr/ospf6d Infomation Information I: frr: spelling-error-in-binary usr/lib/frr/ospfd missmatch mismatch I: frr: spelling-error-in-binary usr/lib/frr/pimd bootsrap bootstrap I: frr: spelling-error-in-binary usr/lib/frr/pimd Unknwon Unknown I: frr: spelling-error-in-binary usr/lib/frr/zebra Requsted Requested I: frr: spelling-error-in-binary usr/lib/frr/zebra uknown unknown I: frr: spelling-error-in-binary usr/lib/x86_64-linux-gnu/frr/libfrr.so.0.0.0 overriden overridden This commit fixes all of them except the bgp `recieved` issue due to it being part of json output. That one will need to go through a deprecation cycle. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-08-06*: fix ctype (isalpha & co.) castsDavid Lamparter
The correct cast for these is (unsigned char), because "char" could be signed and thus have some negative value. isalpha & co. expect an int arg that is positive, i.e. 0-255. So we need to cast to (unsigned char) when calling any of these. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2019-07-29bgpd: stop removing and replacing private asn if it matches the peerDon Slice
Problems reported that if multiple peers have "remove-private-AS replace-AS" with each other and all are using private asns, the as-path gets hosed and continues to grow when a prefix is removed. This fix disallows removing and replacing the private asn if it matches the peer's ASN so that normal as-path loop prevention will operate correctly. Ticket: CM-25489 Signed-off-by: Don Slice <dslice@cumulusnetworks.com>
2019-05-14lib: hashing functions should take const argumentsQuentin Young
It doesn't make much sense for a hash function to modify its argument, so const the hash input. BGP does it in a couple places, those cast away the const. Not great but not any worse than it was. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-03-06Merge pull request #3869 from qlyoung/cocci-fixesDavid Lamparter
Assorted Coccinelle fixes
2019-03-01Merge pull request #3743 from NaveenThanikachalam/2990_NewDonald Sharp
bgpd: Address performance issues in BGP route aggregation.
2019-02-28bgpd: Code to handle BGP aggregate's as-path.Naveen Thanikachalam
With this commit: 1) 'struct bgp_aggregate' is moved to bgp_route.h from bgp_route.c 2) Hashes to accommodate the as-path, communities, extended-communities and large-communities attributes of all the routes aggregated by an aggregate route is introduced in 'struct bgp_aggregate'. 3) Place-holders for the aggregate route's as-path, communities, extended-communities and large-communities attributes are introduced in 'struct bgp_aggregate'. 4) The code to manage the as-path of the routes that are aggregatable under a configured aggregate-address is introduced. 5) The code to compute the aggregate-route's as-path is introduced. Signed-off-by: NaveenThanikachalam <nthanikachal@vmware.com>
2019-02-25*: remove null check before XFREEQuentin Young
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>