summaryrefslogtreecommitdiff
path: root/bgpd/bgp_updgrp_adv.c
AgeCommit message (Collapse)Author
2024-12-18bgpd: Withdraw routes without waiting for the coalescing timer to expireDonatas Abraitis
TL;DR; BGP keeps advertising prefixes which were already removed via `network` command. This was happening randomly, but with this patch, no issues happened. Before: ``` frr# sh ip bgp neighbors 10.0.5.1 advertised-routes BGP table version is 586, local router ID is 44.44.33.43, vrf id 0 Default local pref 100, local AS 2 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 *> 15.15.15.0/24 0.0.0.0 0 32768 2 i ============> stale entry *> 15.15.16.0/24 0.0.0.0 0 32768 2 i *> 15.15.17.0/24 0.0.0.0 0 32768 2 i frr# sh ip bgp 15.15.15.0/24 % Network not in table ``` Logs: ``` root@b03d1542-0215-5ecf-013d-af2a7150a4f5:~# cat /log/syslog/frr.log | grep 15.15.15.0 2024/12/08 07:56:58 BGP: [K423X-ETGCQ] group_announce_route_walkcb: afi=IPv4, safi=unicast, p=15.15.15.0/24 2024/12/08 07:56:58 BGP: [T5JFA-13199] subgroup_process_announce_selected: p=15.15.15.0/24, selected=0xde4060 2024/12/08 07:56:58 BGP: [K423X-ETGCQ] group_announce_route_walkcb: afi=IPv4, safi=unicast, p=15.15.15.0/24 2024/12/08 07:56:58 BGP: [T5JFA-13199] subgroup_process_announce_selected: p=15.15.15.0/24, selected=0xde4060 2024/12/08 07:56:58 BGP: [HVRWP-5R9NQ] u78:s77 send UPDATE 15.15.15.0/24 IPv4 unicast ``` Or imagine the situation where withdrawals are postponed for 20-30s., blackholing happens. Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2024-12-17Merge pull request #16830 from louis-6wind/fix-addpath-raceRuss White
bgpd: fix missing addpath withdrawal race condition
2024-12-11bgpd: Show which prefix is suppressed if debug out is enabledDonatas Abraitis
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2024-10-15bgpd: Set MED using a helper bgp_attr_set_med()Donatas Abraitis
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2024-09-14bgpd: fix missing addpath withdrawal race conditionLouis Scalbert
There is a race condition with addpath withdrawal. The withdrawal never happens if it was request when coalesce timer running. It can be demonstrated by adding to bgp_snmp_bgp4v2mib/rr/bgpd.conf: > router bgp 65004 > + coalesce-time 10000 But it also happens in other conditions. For example, when using "vtysh -f" to load the configuration. It results in having two identical paths but with different addpath on r2: > r2# sh bgp ipv4 10.0.0.0/31 > BGP routing table entry for 10.0.0.0/31, version 3 > Paths: (3 available, best #1, table default) > 65004 > 192.168.12.4 from 192.168.12.4 (192.168.12.4) > Origin IGP, metric 1, valid, external, multipath, best (AS Path) > AddPath ID: RX 0, TX-All 2 TX-Best-Per-AS 0 TX-Best-Selected 0 > Advertised to: 192.168.12.4 > Last update: Thu Sep 12 16:13:59 2024 > 65004 > 192.168.12.4 from 192.168.12.4 (192.168.12.4) > Origin IGP, metric 1, valid, external, multipath > AddPath ID: RX 3, TX-All 4 TX-Best-Per-AS 0 TX-Best-Selected 0 > Advertised to: 192.168.12.4 > Last update: Thu Sep 12 16:13:59 2024 The first path has been created first but should be withdrawn later. Withdraw the stale addpath even the coalesce timer is running. Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2024-06-05bgpd: fix label in adj-rib-outPhilippe Guibert
After modifying the "label vpn export value", the vpn label information of the VRF is not updated to the peers. For example, the 192.168.0.0/24 prefix is announced to the peer with a label value of 222. > router bgp 65500 > [..] > neighbor 192.0.2.2 remote-as 65501 > address-family ipv4-vpn > neighbor 192.0.2.2 activate > exit-address-family > exit > router bgp 65500 vrf vrf2 > address-family ipv4 unicast > network 192.168.0.0/24 > label vpn export 222 > rd vpn export 444:444 > rt vpn both 53:100 > export vpn > import vpn > exit-address-family Changing the label with "label vpn export" does not update the label value to the peer unless the BGP sessions is re-established. No labels are stored are stored struct bgp_adj_out so that it is impossible to compare the current value with the previous value in adj-RIB-out. Reference the bgp_labels pointer in struct bgp_adj_out and compare the values when updating adj-RIB-out. Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com> Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2024-04-15bgpd: Fix display when using `missing-as-worst`Donald Sharp
The usage of the `bgp bestpath med missing-as-worst` command was being accepted and applied during bestpath, but during output of the routes affected by this it would not give any indication that this was happening or what med value was being used. Fixes: #15718 Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2024-03-26bgpd: Optimize the path for suppressed announcementsDonatas Abraitis
If supress-duplicates is turned of (which is turned on by default), do not calculate attribute hash key, that consumes CPU quite a lot. Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2024-03-13bgpd: Ensure community data is freed in some cases.Donald Sharp
Customer has this valgrind trace: Direct leak of 2829120 byte(s) in 70728 object(s) allocated from: 0 in community_new ../bgpd/bgp_community.c:39 1 in community_uniq_sort ../bgpd/bgp_community.c:170 2 in route_set_community ../bgpd/bgp_routemap.c:2342 3 in route_map_apply_ext ../lib/routemap.c:2673 4 in subgroup_announce_check ../bgpd/bgp_route.c:2367 5 in subgroup_process_announce_selected ../bgpd/bgp_route.c:2914 6 in group_announce_route_walkcb ../bgpd/bgp_updgrp_adv.c:199 7 in hash_walk ../lib/hash.c:285 8 in update_group_af_walk ../bgpd/bgp_updgrp.c:2061 9 in group_announce_route ../bgpd/bgp_updgrp_adv.c:1059 10 in bgp_process_main_one ../bgpd/bgp_route.c:3221 11 in bgp_process_wq ../bgpd/bgp_route.c:3221 12 in work_queue_run ../lib/workqueue.c:282 The above leak detected by valgrind was from a screenshot so I copied it by hand. Any mistakes in line numbers are purely from my transcription. Additionally this is against a slightly modified 8.5.1 version of FRR. Code inspection of 8.5.1 -vs- latest master shows the same problem exists. Code should be able to be followed from there to here. What is happening: There is a route-map being applied that modifes the outgoing community to a peer. This is saved in the attr copy created in subgroup_process_announce_selected. This community pointer is not interned. So the community->refcount is still 0. Normally when a prefix is announced, the attr and the prefix are placed on a adjency out structure where the attribute is interned. This will cause the community to be saved in the community hash list as well. In a non-normal operation when the decision to send is aborted after the route-map application, the attribute is just dropped and the pointer to the community is just dropped too, leading to situations where the memory is leaked. The usage of bgp suppress-fib would would be a case where the community is caused to be leaked. Additionally the previous commit where an unsuppress-map is used to modify the outgoing attribute but since unsuppress-map was not considered part of outgoing policy the attribute would be dropped as well. This pointer drop also extends to any dynamically allocated memory saved by the attribute pointer that was not interned yet as well. So let's modify the return case where the decision is made to not send the prefix to the peer to always just flush the attribute to ensure memory is not leaked. Fixes: #15459 Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2024-03-13bgpd: Ensure that the correct aspath is free'dDonald Sharp
Currently in subgroup_default_originate the attr.aspath is set in bgp_attr_default_set, which hashs the aspath and creates a refcount for it. If this is a withdraw the subgroup_announce_check and bgp_adj_out_set_subgroup is called which will intern the attribute. This will cause the the attr.aspath to be set to a new value finally at the bottom of the function it intentionally uninterns the aspath which is not the one that was created for this function. This reduces the other aspath's refcount by 1 and if a clear bgp * is issued fast enough the aspath for that will be removed and the system will crash. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2024-02-13bgpd: Implement Paths-Limit capabilityDonatas Abraitis
https://datatracker.ietf.org/doc/html/draft-abraitis-idr-addpath-paths-limit Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2024-01-08bgpd: Fix memory leak for default-originate with route-mapDonatas Abraitis
``` Direct leak of 40 byte(s) in 1 object(s) allocated from: 0 0x7fc4b81eed28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28) 1 0x7fc4b7bd60bb in qcalloc lib/memory.c:105 2 0x56221dc19207 in aspath_dup bgpd/bgp_aspath.c:689 3 0x56221daacd42 in route_set_aspath_prepend bgpd/bgp_routemap.c:2283 4 0x7fc4b7c3891a in route_map_apply_ext lib/routemap.c:2687 5 0x56221dace552 in subgroup_default_originate bgpd/bgp_updgrp_adv.c:906 6 0x56221dabf79c in update_group_default_originate_route_map_walkcb bgpd/bgp_updgrp.c:2105 7 0x56221dabde4e in update_group_walkcb bgpd/bgp_updgrp.c:1721 8 0x7fc4b7b9d398 in hash_walk lib/hash.c:270 9 0x56221dac94cb in update_group_af_walk bgpd/bgp_updgrp.c:2062 10 0x56221dac9b0f in update_group_walk bgpd/bgp_updgrp.c:2071 11 0x56221dac9fd5 in update_group_refresh_default_originate_route_map bgpd/bgp_updgrp.c:2118 12 0x7fc4b7c7fc54 in event_call lib/event.c:1974 13 0x7fc4b7bb9276 in frr_run lib/libfrr.c:1214 14 0x56221d9217fd in main bgpd/bgp_main.c:510 15 0x7fc4b6bf2c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86) ``` tmp_pi.attr should be flushed since it's already interned (new_attr) or the origin value is used (attr). Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2023-12-08bgpd: Convert variable `withdraw` integer to boolDonatas Abraitis
It holds only 0/1. Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2023-11-13bgpd: Used %pBD instead of %pRNDonald Sharp
Let's use the natural data structure in bgp for the prefix display instead of a bunch of places where we call a translator function. The %pBD does this and actually ensures data is correct. Also fix a few spots in bgp_zebra.c where the cast to a NULL pointer causes the catcher functionality to not work and fix the resulting crash that resulted. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-10-10bgpd: Convert the bgp_advertise_attr->adv to a fifoDonald Sharp
BGP is storing outgoing updates in a couple of different fifo's. This is to ensure proper packet packing of all bgp_dests that happen to use the same attribute. How it's all put together currently: On initial update BGP walks through all the bgp_dest's in a table. For each path being sent a bgp_advertise is created. This bgp_advertise is placed in fifo order on the bgp_synchronize->update queue. The bgp_advertise has a pointer to the bgp_advertise_attr which is associated iwth the actual attribute that is being sent to it's peer. In turn this bgp_advertise is placed in a fifo off of the bgp_advertise_attr structure. As such as we have paths that share an attribute, the path/dest is placed on the bgp_syncrhonize->update fifo as well as being placed on the fifo associated with the advertised attribute. On actual creation of a packet. The first item in the bgp_synchronize->update fifo is popped. The bgp_advertise_attr pointer is grabbed, we fill out the nlri part of the bgp packet and then walk the bgp_advertise_attr fifo to place paths/dests in the packet. As each path/dest is placed in the packet it is removed from both the bgp_synchronize->update fifo and the bgp_advertise_attr fifo. The whole point of this change is to switch the *next, *prev pointers in the bgp_advertise structure with a typesafe data structure. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-09-10bgpd: bgp_fsm_change_status/BGP_TIMER_ON and BGP_EVENT_ADDDonald Sharp
Modify bgp_fsm_change_status to be connection oriented and also make the BGP_TIMER_ON and BGP_EVENT_ADD macros connection oriented as well. Attempt to make peer_xfer_conn a bit more understandable because, frankly it was/is confusing. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-09-09bgpd: move t_routeadv to peer_connectionDonald Sharp
The t_routeadv belongs to the peer_connection data structure Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-06-20Merge pull request #13728 from ↵Russ White
opensourcerouting/fix/addpath_drop_non_best_addpaths bgpd: Implement neighbor X addpath-tx-best-selected command
2023-06-14bgpd: some safi's do not mix with bgp suppress-fibDonald Sharp
BGP cannot decide to disseminate the safi based upon the bgp suppress-fib command. Modify the code to look at the safi for the decision to communicate to a peer the particular node. Ticket: #3402926 Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-06-07bgpd: Implement `neighbor X addpath-tx-best-selected` commandDonatas Abraitis
When using `addpath-tx-all` BGP announces all known paths instead of announcing only an arbitrary number of best paths. With this new command we can send N best paths to the neighbor. That means, we send the best path, then send the second best path excluding the previous one, and so on. In other words, we run best path selection algorithm N times before we finish. Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2023-05-25bgpd: Refactor subgroup_announce_table() to reuse an existing helpersDonatas Abraitis
Reuse subgroup_process_announce_selected(). It does the same as we do here duplicating the logic. Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2023-03-24*: Convert event.h to frrevent.hDonald Sharp
We should probably prevent any type of namespace collision with something else. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24*: Convert THREAD_XXX macros to EVENT_XXX macrosDonald Sharp
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24*: Convert thread_add_XXX functions to event_add_XXXDonald Sharp
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24*: Rename `struct thread` to `struct event`Donald Sharp
Effectively a massive search and replace of `struct thread` to `struct event`. Using the term `thread` gives people the thought that this event system is a pthread when it is not Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24*: Rename thread.[ch] to event.[ch]Donald Sharp
This is a first in a series of commits, whose goal is to rename the thread system in FRR to an event system. There is a continual problem where people are confusing `struct thread` with a true pthread. In reality, our entire thread.c is an event system. In this commit rename the thread.[ch] files to event.[ch]. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-14bgpd: Rename bgp_afi_node_lookup() to bgp_safi_node_lookup()Donatas Abraitis
afi not used in this function, reduce a bit. Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2023-03-11bgpd: Increment version number even when no data is sentDonald Sharp
When an update group decides to not send a prefix announcement because it has not changed, still increment the version number. Why? To allow for the situation where you have say 2 peers in 1 peer group and shortly after they come up a 3rd peer comes up. It will be placed into a separate update group and could be coalesced down, when it finishes updating all data to it. Now imagine that a single prefix changes at this point in time as well. Then first 2 peers may decide to not send the data, since nothing has changed. While the 3rd peer will and since the versions numbers never match they will never coalesce. So when the decision is made to skip, update the version number as well. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-02-27bgpd: Intern attributes before putting into rib-outDonatas Abraitis
After we call subgroup_announce_check(), we leave communities, large-communities that are modified by route-maps uninterned, and here we have a memory leak. ``` ./bgp_large_community.test_bgp_large_community_topo_2/r1.bgpd.asan.2465323:Direct leak of 80 byte(s) in 2 object(s) allocated from: ./bgp_large_community.test_bgp_large_community_topo_2/r1.bgpd.asan.2465323- #0 0x7f0858d90037 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:154 ./bgp_large_community.test_bgp_large_community_topo_2/r1.bgpd.asan.2465323- #1 0x7f08589b15b2 in qcalloc lib/memory.c:105 ./bgp_large_community.test_bgp_large_community_topo_2/r1.bgpd.asan.2465323- #2 0x561f5c4e08d2 in lcommunity_new bgpd/bgp_lcommunity.c:28 ./bgp_large_community.test_bgp_large_community_topo_2/r1.bgpd.asan.2465323- #3 0x561f5c4e11d9 in lcommunity_dup bgpd/bgp_lcommunity.c:141 ./bgp_large_community.test_bgp_large_community_topo_2/r1.bgpd.asan.2465323- #4 0x561f5c5c3b8b in route_set_lcommunity bgpd/bgp_routemap.c:2491 ./bgp_large_community.test_bgp_large_community_topo_2/r1.bgpd.asan.2465323- #5 0x7f0858a177a5 in route_map_apply_ext lib/routemap.c:2675 ./bgp_large_community.test_bgp_large_community_topo_2/r1.bgpd.asan.2465323- #6 0x561f5c5696f9 in subgroup_announce_check bgpd/bgp_route.c:2352 ./bgp_large_community.test_bgp_large_community_topo_2/r1.bgpd.asan.2465323- #7 0x561f5c5fb728 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:682 ./bgp_large_community.test_bgp_large_community_topo_2/r1.bgpd.asan.2465323- #8 0x561f5c5fbd95 in subgroup_announce_route bgpd/bgp_updgrp_adv.c:765 ./bgp_large_community.test_bgp_large_community_topo_2/r1.bgpd.asan.2465323- #9 0x561f5c5f6105 in peer_af_announce_route bgpd/bgp_updgrp.c:2187 ./bgp_large_community.test_bgp_large_community_topo_2/r1.bgpd.asan.2465323- #10 0x561f5c5790be in bgp_announce_route_timer_expired bgpd/bgp_route.c:5032 ./bgp_large_community.test_bgp_large_community_topo_2/r1.bgpd.asan.2465323- #11 0x7f0858a76e4e in thread_call lib/thread.c:1991 ./bgp_large_community.test_bgp_large_community_topo_2/r1.bgpd.asan.2465323- #12 0x7f0858974c24 in frr_run lib/libfrr.c:1185 ./bgp_large_community.test_bgp_large_community_topo_2/r1.bgpd.asan.2465323- #13 0x561f5c3e955d in main bgpd/bgp_main.c:505 ./bgp_large_community.test_bgp_large_community_topo_2/r1.bgpd.asan.2465323- #14 0x7f08583a9d09 in __libc_start_main ../csu/libc-start.c:308 ./bgp_large_community.test_bgp_large_community_topo_2/r1.bgpd.asan.2465323- ./bgp_large_community.test_bgp_large_community_topo_2/r1.bgpd.asan.2465323:Indirect leak of 144 byte(s) in 2 object(s) allocated from: ./bgp_large_community.test_bgp_large_community_topo_2/r1.bgpd.asan.2465323- #0 0x7f0858d8fe8f in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:145 ./bgp_large_community.test_bgp_large_community_topo_2/r1.bgpd.asan.2465323- #1 0x7f08589b1579 in qmalloc lib/memory.c:100 ./bgp_large_community.test_bgp_large_community_topo_2/r1.bgpd.asan.2465323- #2 0x561f5c4e1282 in lcommunity_dup bgpd/bgp_lcommunity.c:144 ./bgp_large_community.test_bgp_large_community_topo_2/r1.bgpd.asan.2465323- #3 0x561f5c5c3b8b in route_set_lcommunity bgpd/bgp_routemap.c:2491 ./bgp_large_community.test_bgp_large_community_topo_2/r1.bgpd.asan.2465323- #4 0x7f0858a177a5 in route_map_apply_ext lib/routemap.c:2675 ./bgp_large_community.test_bgp_large_community_topo_2/r1.bgpd.asan.2465323- #5 0x561f5c5696f9 in subgroup_announce_check bgpd/bgp_route.c:2352 ./bgp_large_community.test_bgp_large_community_topo_2/r1.bgpd.asan.2465323- #6 0x561f5c5fb728 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:682 ./bgp_large_community.test_bgp_large_community_topo_2/r1.bgpd.asan.2465323- #7 0x561f5c5fbd95 in subgroup_announce_route bgpd/bgp_updgrp_adv.c:765 ./bgp_large_community.test_bgp_large_community_topo_2/r1.bgpd.asan.2465323- #8 0x561f5c5f6105 in peer_af_announce_route bgpd/bgp_updgrp.c:2187 ./bgp_large_community.test_bgp_large_community_topo_2/r1.bgpd.asan.2465323- #9 0x561f5c5790be in bgp_announce_route_timer_expired bgpd/bgp_route.c:5032 ./bgp_large_community.test_bgp_large_community_topo_2/r1.bgpd.asan.2465323- #10 0x7f0858a76e4e in thread_call lib/thread.c:1991 ./bgp_large_community.test_bgp_large_community_topo_2/r1.bgpd.asan.2465323- #11 0x7f0858974c24 in frr_run lib/libfrr.c:1185 ./bgp_large_community.test_bgp_large_community_topo_2/r1.bgpd.asan.2465323- #12 0x561f5c3e955d in main bgpd/bgp_main.c:505 ./bgp_large_community.test_bgp_large_community_topo_2/r1.bgpd.asan.2465323- #13 0x7f08583a9d09 in __libc_start_main ../csu/libc-start.c:308 ./bgp_large_community.test_bgp_large_community_topo_2/r1.bgpd.asan.2465323- ./bgp_large_community.test_bgp_large_community_topo_2/r1.bgpd.asan.2465323-SUMMARY: AddressSanitizer: 224 byte(s) leaked in 4 allocation(s). ``` Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2023-02-17Merge pull request #12780 from opensourcerouting/spdx-license-idDonald Sharp
*: convert to SPDX License identifiers
2023-02-09bgpd: Intern default-originate attributes to avoid use-after-freeDonatas Abraitis
When we receive a default route from a peer and we originate default route using `neighbor default-originate`, we do not track of struct attr we use, and when we do `no neighbor default-originate` we withdraw our generated default route, but we announce default-route from the peer. After we do this, we unintern aspath (which was used for default-originate), BUT it was used also for peer's default route we received. And here we have a use-after-free crash, because bgp_process_main_one() reaps old paths that are marked as BGP_PATH_REMOVED with aspath->refcnt > 0, but here it's 0. ``` 0 0x55c24bbcd022 in aspath_key_make bgpd/bgp_aspath.c:2070 1 0x55c24b8f1140 in attrhash_key_make bgpd/bgp_attr.c:777 2 0x7f52322e66c9 in hash_release lib/hash.c:220 3 0x55c24b8f6017 in bgp_attr_unintern bgpd/bgp_attr.c:1271 4 0x55c24ba0acaa in bgp_path_info_free_with_caller bgpd/bgp_route.c:283 5 0x55c24ba0a7de in bgp_path_info_unlock bgpd/bgp_route.c:309 6 0x55c24ba0af6d in bgp_path_info_reap bgpd/bgp_route.c:426 7 0x55c24ba17b9a in bgp_process_main_one bgpd/bgp_route.c:3333 8 0x55c24ba18a1d in bgp_process_wq bgpd/bgp_route.c:3425 9 0x7f52323c2cd5 in work_queue_run lib/workqueue.c:282 10 0x7f52323aab92 in thread_call lib/thread.c:2006 11 0x7f5232300dc7 in frr_run lib/libfrr.c:1198 12 0x55c24b8ea792 in main bgpd/bgp_main.c:520 13 0x7f5231c3a082 in __libc_start_main ../csu/libc-start.c:308 14 0x55c24b8ef0bd in _start (/usr/lib/frr/bgpd+0x2c90bd) ``` Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
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>
2022-12-07bgpd: Announce labeled-unicast default-originateDonatas Abraitis
Without this patch, this just crashes: ``` (gdb) bt 0 raise (sig=sig@entry=11) at ../sysdeps/unix/sysv/linux/raise.c:51 1 0x00007f66d977b10c in core_handler (signo=11, siginfo=0x7ffd87aa0430, context=<optimized out>) at lib/sigevent.c:261 2 <signal handler called> 3 stream_put_labeled_prefix (s=s@entry=0x55bd3ce53050, p=p@entry=0x7ffd87aa0a20, label=label@entry=0x0, addpath_capable=<optimized out>, addpath_tx_id=addpath_tx_id@entry=1) at lib/stream.c:1057 4 0x000055bd3bfba176 in bgp_packet_mpattr_prefix (s=s@entry=0x55bd3ce53050, afi=afi@entry=AFI_IP, safi=safi@entry=SAFI_LABELED_UNICAST, p=p@entry=0x7ffd87aa0a20, prd=prd@entry=0x0, label=label@entry=0x0, num_labels=0, addpath_capable=true, addpath_tx_id=1, attr=0x7ffd87aa2c20) at bgpd/bgp_attr.c:3964 5 0x000055bd3bfba2b5 in bgp_packet_attribute (bgp=0x55bd3cd8e470, bgp@entry=0x0, peer=peer@entry=0x55bd3cf21fc0, s=s@entry=0x55bd3ce53050, attr=attr@entry=0x7ffd87aa2c20, vecarr=vecarr@entry=0x7ffd87aa0a10, p=p@entry=0x7ffd87aa0a20, afi=AFI_IP, safi=SAFI_LABELED_UNICAST, from=0x7f66d9ba9010, prd=0x0, label=0x0, num_labels=0, addpath_capable=true, addpath_tx_id=1, bpi=0x0) at bgpd/bgp_attr.c:4139 6 0x000055bd3c04d455 in subgroup_default_update_packet (subgrp=subgrp@entry=0x55bd3cd885b0, attr=attr@entry=0x7ffd87aa2c20, from=from@entry=0x7f66d9ba9010) at bgpd/bgp_updgrp_packet.c:1129 7 0x000055bd3c04a9a5 in subgroup_default_originate (subgrp=0x55bd3cd885b0, withdraw=withdraw@entry=0) at bgpd/bgp_updgrp_adv.c:972 8 0x000055bd3c022668 in bgp_default_originate (peer=peer@entry=0x7f66d574a010, afi=afi@entry=AFI_IP, safi=safi@entry=SAFI_LABELED_UNICAST, withdraw=withdraw@entry=0) at bgpd/bgp_route.c:5037 9 0x000055bd3c0922e0 in peer_default_originate_set (peer=0x7f66d574a010, afi=afi@entry=AFI_IP, safi=safi@entry=SAFI_LABELED_UNICAST, rmap=rmap@entry=0x0, route_map=route_map@entry=0x0) at bgpd/bgpd.c:5428 10 0x000055bd3c076c07 in peer_default_originate_set_vty (set=1, rmap=0x0, safi=SAFI_LABELED_UNICAST, afi=AFI_IP, peer_str=<optimized out>, vty=0x55bd3ce4c900) at bgpd/bgp_vty.c:6941 11 neighbor_default_originate (self=<optimized out>, vty=0x55bd3ce4c900, argc=<optimized out>, argv=<optimized out>) at bgpd/bgp_vty.c:6958 12 0x00007f66d9721dc0 in cmd_execute_command_real (vline=vline@entry=0x55bd3cd874d0, vty=vty@entry=0x55bd3ce4c900, cmd=cmd@entry=0x0, up_level=up_level@entry=0, filter=FILTER_RELAXED) at lib/command.c:996 13 0x00007f66d9721f39 in cmd_execute_command (vline=vline@entry=0x55bd3cd874d0, vty=vty@entry=0x55bd3ce4c900, cmd=cmd@entry=0x0, vtysh=vtysh@entry=0) at lib/command.c:1055 14 0x00007f66d9722162 in cmd_execute (vty=vty@entry=0x55bd3ce4c900, cmd=cmd@entry=0x55bd3cd8a230 "neighbor 192.168.34.4 default-originate ", matched=matched@entry=0x0, vtysh=vtysh@entry=0) at lib/command.c:1223 15 0x00007f66d9792337 in vty_command (vty=vty@entry=0x55bd3ce4c900, buf=<optimized out>) at lib/vty.c:486 16 0x00007f66d9792570 in vty_execute (vty=0x55bd3ce4c900) at lib/vty.c:1249 ``` Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-10-11bgpd: fix "bgp max-med on-startup"Alexander Chernavin
Currently, if `bgp max-med on-startup` is configured, after BGP session is established for the first time, a timer for the specified time is started. When the timer is expired, an UPDATE message should be sent to reflect changes in the routes' MED value. The problem is that the routes are being suppressed because based on the attributes they look like they have not changed. However, in the case of max-med, the value is copied to the packet directly from `bgp->maxmed_value`, not from the attributes. Thus, changes in this case cannot be detected by comparing attributes. With this fix, avoid route suppressing when the `max-med on-startup` timer expires and initiates an UPDATE. Signed-off-by: Alexander Chernavin <achernavin@netgate.com>
2022-07-27bgpd: Improve indentation in bgp_updgrp_adv.cDonald Sharp
This file was hard to read due to heavy indentation. Let's fix it up some. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-07-25bgpd: Rename baa_new/baa_free/etc functions to be human-readableDonatas Abraitis
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-07-21bgpd: Remove various macros that overlap THREAD_OFFDonald Sharp
Let's just use THREAD_OFF consistently in the code base instead of each daemon having a special macro that needs to be looked at and remembered what it does. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-07-06bgpd: Fix insonsistencies with default-originate route-mapIqra Siddiqui
Description: - When there are multiple policies configured with route-map then the first matching policy is not getting applied on default route originated with default-originate. - In BGP we first run through the BGP RIB and then pass it to the route-map to find if its permit or deny. Due to this behaviour the first route in BGP RIB that passes the route-map will be applied. Fix: - Passing extra parameter to routemap_apply so that we can get the preference of the matching policy, keep comparing it with the old preference and finally consider the policy with less preference. Co-authored-by: Abhinay Ramesh <rabhinay@vmware.com> Signed-off-by: Iqra Siddiqui <imujeebsiddi@vmware.com>
2022-07-06bgpd: fix route-map update and delete route-mapAbhinay Ramesh
Description: - When there is change in route-map properties after setting the route-map with default route, changes will not reflect. - When route-map associated with default-originate is deleted, default route doesn't get withdrawn. - When there is change in route-map default-originate flow does not get triggered. Fix: - One of the flags needs to be unset for default-originate flow to get triggered after change in route-map. Have unset the flag, so that default originate flow can be triggered. Co-authored-by: Abhinay Ramesh <rabhinay@vmware.com> Signed-off-by: Iqra Siddiqui <imujeebsiddi@vmware.com>
2022-06-06bgpd: Initialize attr->local_pref to the configured default valueDonatas Abraitis
When we use network/redistribute local_preference is configured inproperly when using route-maps something like: ``` network 100.100.100.100/32 route-map rm1 network 100.100.100.200/32 route-map rm2 route-map rm1 permit 10 set local-preference +10 route-map rm2 permit 10 set local-preference -10 ``` Before: ``` root@spine1-debian-11:~# vtysh -c 'show bgp ipv4 unicast 100.100.100.100/32 json' | jq '.paths[].locPrf' 10 root@spine1-debian-11:~# vtysh -c 'show bgp ipv4 unicast 100.100.100.200/32 json' | jq '.paths[].locPrf' 0 ``` After: ``` root@spine1-debian-11:~# vtysh -c 'show bgp ipv4 unicast 100.100.100.100/32 json' | jq '.paths[].locPrf' 110 root@spine1-debian-11:~# vtysh -c 'show bgp ipv4 unicast 100.100.100.200/32 json' | jq '.paths[].locPrf' 90 ``` Set local-preference as the default value configured per BGP instance, but do not set LOCAL_PREF flag by default. Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-04-12bgpd: Metric not set with default route.Abhinay Ramesh
Description: - When default route is originated using the neighbor default-originate command, MED is not set as part of the update message attribute. - Changes are done to set the MED value and MED flag for default route. Co-authored-by: Abhinay Ramesh <rabhinay@vmware.com> Signed-off-by: Iqra Siddiqui <imujeebsiddi@vmware.com>
2022-02-23*: Change thread->func to return void instead of intDonald Sharp
The int return value is never used. Modify the code base to just return a void instead. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-02-18bgpd: Allow setting attributes over route-maps for conditional advertisementsDonatas Abraitis
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2022-02-10bgpd: remove bgp_attr_undupIgor Ryzhov
bgp_attr_undup does the same thing as bgp_attr_flush – frees the temporary data that might be allocated when applying a route-map. There is no need to have two separate functions for that. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2022-02-01bgpd: Add bgp_check_selected() helper for abstractionDonatas Abraitis
Just check if the path is selected to be advertised: best path or addpath capable. Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2022-02-01bgpd: Convert bgp_addpath_encode_[tr]x() to bool from intDonatas Abraitis
Rename addpath_encode[d] to addpath_capable to be consistent. Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2022-01-20bgpd: apply maximum-prefix-out without clearing the neighborLouis Scalbert
Abstract: - The command "neighbor PEER maximum-prefix-out NUMBER" cannot be applied without clearing the BGP neighbor. - Apply the maximum-prefix-out value as soon as it is modified without clearing the neighbor. subgroup_update_packet() and subgroup_withdraw_packet() respectively manages the announcement and withdrawal BGP message to the peer. subgrp->scount counter counts the number of sent prefixes. Before the patch, the maximum out prefix limitation was applied in subgroup_update_packet() in order that subgrp->scount never exceeds the limit. Setting a limit inferior to the effective number of sent prefix did not result in sending any withdrawal message to reduce the number of sent prefixes. Without clearing the BGP neighbor, the limitation only applied to the announcement of new prefixes when the limitation was over. With the patch, the limitation is checked in subgroup_announce_check(). The function is intended to say whether a prefix has to be announced in regards to the prefix-list, route-map... Now when a maximum-prefix-out value is changed/removed, the neighbor AFI/SAFI table is re-parsed in the same way as for the application of route-map, prefix-lists... Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2021-12-17bgpd, tests: Add code to handle failed installationsDonald Sharp
Currently the Wait for Install code ( bgp_suppress_fib ) does not properly handle two states from zebra: ROUTE_INSTALL_FAILED and BETTER_ADMIN_DISTANCE_WON. Pre this change the WFI code would just never notify our peers about a route install failure but more is needed. In the ROUTE_INSTALL_FAILED and the BETTER_ADMIN_DISTANCE_WON we need to notify our peers with a withdrawal about the route, else we will continue to draw traffic to us when we cannot legally do so. Why is this needed? In either case imagine that we've already received a bgp route, installed it and sent to our peers. In the Better admin distance won case, say a static route is installed at this point in time we must stop advertising the route through us since we are not installed. As such a withdrawal must be sent. In the ROUTE_INSTALL_FAILED case, the code was not properly handling the situation where we have Route A, it was successfully installed and then we received a update to Route A that was attempted to be installed but failed. In this case we also need to send a withdrawal Finally update the bgp_suppress_fib topotest to test both of these situations. Signed-off-by: Donald Sharp <sharpd@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-09-15bgpd: fix coverity warningIgor Ryzhov
CID 1506874. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>