summaryrefslogtreecommitdiff
path: root/bgpd/bgp_labelpool.c
AgeCommit message (Collapse)Author
2025-02-10bgpd: Fix crash in bgp_labelpoolDonald Sharp
The bgp labelpool code is grabbing the vpn policy data structure. This vpn_policy has a pointer to the bgp data structure. If a item placed on the bgp label pool workqueue happens to sit there for the microsecond or so and the operator issues a `no router bgp...` command that corresponds to the vpn_policy bgp pointer, when the workqueue is run it will crash because the bgp pointer is now freed and something else owns it. Modify the labelpool code to store the vrf id associated with the request on the workqueue. When you wake up if the vrf id still has a bgp pointer allow the request to continue, else drop it. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2024-12-20bgpd: Replace ctime_r() to time_to_string[_json]() to handle JSON/non-JSONDonatas Abraitis
For JSON output we don't need newline to be printed. Before: ``` "lastUpdate":{"epoch":1734490463,"string":"Wed Dec 18 04:54:23 2024\n" ``` After: ``` "lastUpdate":{"epoch":1734678560,"string":"Fri Dec 20 09:09:20 2024" ``` Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2024-01-06bgpd: bgp_sync_label_manager failure caseDonald Sharp
There are several problems with the bgp_sync_label_manager function: a) It is possible that a request in the lp->requests fifo will be unable to be filled at this point in time and the lf will be leaked and not ever fullfilled. b) The bgp_sync_label_manager runs one time a second irrelevant if there is work to do or not. To fix (a) just add the request back to the requests fifo and set the timer to pop in the future. To fix (b) just every time something is put into the request pool start a timer to run in 1 second and do not restart it if all the work is done. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-11-02bgpd: Fix UNINTENDED_INTEGER_DIVISION for bgp_lp_event_zebra_up()Donatas Abraitis
CID 1570864. Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2023-10-18bgpd: fix wrong 'pending' labelpool counter value at startupPhilippe Guibert
If BGP starts with a l3vpn configuration, the 'pending' value of the 'show bgp labelpool summary' command is set to 128, whereas the 'pending' value is 0 if the l3vpn configuration is applied after. with no config at startup: > show bgp labelpool summary > Labelpool Summary > ----------------- > Ledger: 1 > InUse: 1 > Requests: 0 > LabelChunks: 1 > Pending: 0 > Reconnects: 1 with config at startup: > show bgp labelpool summary > Labelpool Summary > ----------------- > Ledger: 1 > InUse: 1 > Requests: 0 > LabelChunks: 1 > Pending: 128 > Reconnects: 1 When BGP configuration is applied at startup, the label request fails, because the zapi connection with zebra is not yet up. At zebra up event, the label request is done again, succeeds, decrements the 'pending_count' value in 'bgp_lp_event_chunk() function, then sets the 'pending_count' value to the 'labels_needed' value. This method was correct when label requests were asyncronous: the 'pending_count' value was first set, then decremented. In syncronous label requests, the operations are swapped. Fix this by incrementing the expected 'labels_needed' value instead. Fixes: 0043ebab996e ("bgpd: Use synchronous way to get labels from Zebra") Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2023-10-18bgpd: fix release label chunk when label pool unusedPhilippe Guibert
A label chunk is used by BGP for L3VPN or LU purposes, by picking up labels from that chunk; but when those labels are release, the label chunks are never released. The below configuration sequence shows that the label chunks are not released. > router bgp 65500 > bgp router-id 1.1.1.1 > ! > address-family ipv4 unicast > label vpn export auto > rd vpn export 55:1 > rt vpn both 55:1 > export vpn > import vpn > [..] > no label vpn export auto > [..] > # show bgp labelpool summary > [..] > LabelChunks: 1 > Pending: 128 > [..] The '128' value stands for the default label chunk size, which is not released after unconfiguration. Fix this by checking after each label release, that the label chunk is still used. If not, release it. Reset the 'next_chunksize' value to the default value. Fixes: 955bfd984ffd ("bgpd: dynamic mpls label pool") Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2023-10-18bgpd: fix label allocation should not be allocated at startupPhilippe Guibert
BGP always asks zebra for a chunk of MPLS label even if it doesn't need it. Fix this by correcting the rounding up "labels_needed" formula. Fixes: 80853c2ec7f8 ("bgpd: improve labelpool performance at scale") Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2023-10-18bgpd: fix hardset l3vpn label available in mpls poolPhilippe Guibert
Today, when configuring BGP L3VPN mpls, the operator may use that command to hardset a label value: > router bgp 65500 vrf vrf1 > address-family ipv4 unicast > label vpn export <hardset_label_value> Today, BGP uses this value without checks, leading to potential conflicts with other control planes like LDP. For instance, if LDP initiates with a label chunk of [16;72] and BGP also uses the 50 label value, a conflict arises. The 'label manager' service in zebra oversees label allocations. While all the control plane daemons use it, BGP doesn't when a hardset label is in place. This update fixes this problem. Now, when a hardset label is set for l3vpn export, a request is made to the label manager for approval, ensuring no conflicts with other daemons. But, this means some existing BGP configurations might become non-operational if they conflict with labels already allocated to another daemon but not used. note: Labels below 16 are reserved and won't be checked for consistency by the label manager. Fixes: ddb5b4880ba8 ("bgpd: vpn-vrf route leaking") Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2023-09-19bgpd: replace ctime with ctime_rMark Stapp
No ctime, use ctime_r. Signed-off-by: Mark Stapp <mjs@labn.net>
2023-08-09bgpd: fix whitespace/indent in bgp_labelpool moduleMark Stapp
Fix some weird indentation in the bgp labelpool module. Signed-off-by: Mark Stapp <mjs@labn.net>
2023-06-20bgpd: Retry connecting to synchronouse label manager if not readyDonatas Abraitis
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2023-06-20bgpd: Use synchronous way to get labels from ZebraDonatas Abraitis
Both the label manager and table manager zapi code send data requests via zapi to zebra and then immediately listen for a response from zebra. The problem here is of course that the listen part is throwing away any zapi command that is not the one it is looking for. ISIS/OSPF and PIM all have synchronous abilities via zapi, which they all do through a special zapi connection to zebra. BGP needs to follow this model as well. Additionally the new zclient_sync connection that should be created, a once a second timer should wake up and read any data on the socket to prevent problems too much data accumulating in the socket. ``` r3# sh bgp labelpool summary Labelpool Summary ----------------- Ledger: 3 InUse: 3 Requests: 0 LabelChunks: 1 Pending: 128 Reconnects: 1 r3# sh bgp labelpool inuse Prefix Label --------------------------- 10.0.0.1/32 16 192.168.31.0/24 17 192.168.32.0/24 18 r3# ``` Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2023-06-16bgpd: update the mpls entry to handle return trafficPhilippe Guibert
When advertising an mpls vpn entry with a new label, the return traffic is redirected to the local machine, but the MPLS traffic is dropped. Add an MPLS entry to handle MPLS packets which have the new label value. Traffic is swapped to the original label value from the mpls vpn next-hop entry; then it is sent to the resolved next-hop of the original next-hop from the mpls vpn next-hop entry. Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2023-06-16bgpd: move the label per nexthop structs of bgp_path to an unionPhilippe Guibert
The label per nexthop attributes take 24 bytes per bgp path entry on AMD64 platform, and are only used for unicast paths. The current patch-set introduces a similar attributes, but that will be used only for l3vpn paths. To gain some memory on the bgp_path_info structure in the next commit, do some changes. Create an 'mplsvpn' union structure that will either include the label per nexthop structs for ipv4 paths, or the l3vpn paths structures. The 'label_nexthop_cache' and the 'label_nh_thread' attributes of the 'bgp_path_info' structure are moved into an union under a new structure called 'bgp_mplsvpn_label_nh_blnc'. The flags attribute of 'bgp_path_info' is increased from 16 bits to 32 bits, and the BGP_PATH_MPLSVPN_LABEL_NH flag is added to know the 'mplsvpn' usage. Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2023-06-16bgpd: add LP_TYPE_BGP_L3VPN_BIND label typeLouis Scalbert
Redistributing mpls vpn prefixes with a new label requires picking up unused MPLS local labels. Today, there is an MPLS label pool which is owned by the zebra daemon. BGP gets a chunk of labels that are shared with the multiple usage of the BGP daemon. A label type attribute is used whenever BGP needs a new label value. The 'LP_TYPE_BGP_L3VPN_BIND' label type will be used to allocate the MPLS labels that will be bound to the original next-hop, and label value of an L3VPN update. Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com> Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2023-05-09bgpd: add 'show bgp label-nexthop [detail]' commandPhilippe Guibert
The following command is made available to list the labels allocated per-nexthop, along with the paths registered to it. > # show bgp vrf vrf1 label-nexthop > Current BGP label nexthop cache for IP, VRF vrf1 > 192.0.2.11, label 20 #paths 3 > if r1-eth1 > Last update: Mon Jan 16 18:52:11 2023 > 192.0.2.12, label 17 #paths 2 > if r1-eth1 > Last update: Mon Jan 16 18:52:08 2023 > 192.0.2.14, label 18 #paths 1 > if r1-eth1 > Last update: Mon Jan 16 18:52:07 2023 > 192.168.255.13, label 19 #paths 1 > if r1-eth2 > Last update: Mon Jan 16 18:52:10 2023 Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2023-05-09bgpd: use nexthop interface when adding LSP in BGP MPLSVPNPhilippe Guibert
BGP MPLSVPN next hop label allocation was using only the next-hop IP address. As MPLSVPN contexts rely on bnc contexts, the real nexthop interface is known, and the LSP entry to enter can apply to the specific interface. To illustrate, the BGP service is able to handle the following two iproute2 commands: > ip -f mpls route add 105 via inet 192.0.2.45 dev r1-eth1 > ip -f mpls route add 105 via inet 192.0.2.46 dev r1-eth2 Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2023-05-09bgpd: add the bgp_label_per_nexthop_cache struct and apisPhilippe Guibert
This commit introduces the necessary structs and apis to create the cache entries that store the label information associated to a given nexthop. A hash table is created in each BGP instance for all the AFIs: IPv4 and IPv6. That hash table is initialised. An API to look and/or create an entry based on a given nexthop. Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2023-05-09bgpd: introduce LP_TYPE_NEXTHOP label typePhilippe Guibert
A new label type is introduced: LP_TYPE_NEXTHOP. This new label type will be used in next commits to allocate labels for a specific nexthop IP address. The commit changes add vty and json outputs to display the new label type and the label values associated. Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2023-05-03Revert "MPLS allocation mode per next hop"Donatas Abraitis
Broken tests, let's revert now. Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2023-05-02Merge pull request #12646 from pguibert6WIND/mpls_alloc_per_nhDonatas Abraitis
MPLS allocation mode per next hop
2023-03-24*: Convert `struct event_master` to `struct event_loop`Donald Sharp
Let's find a better name for it. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24*: Convert struct thread_master to struct event_master and it's ilkDonald Sharp
Convert the `struct thread_master` to `struct event_master` across the code base. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24*: Convert thread_cancelXXX to event_cancelXXXDonald Sharp
Modify the code base so that thread_cancel becomes event_cancel 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-22bgpd: add 'show bgp label-nexthop [detail]' commandPhilippe Guibert
The following command is made available to list the labels allocated per-nexthop, along with the paths registered to it. > # show bgp vrf vrf1 label-nexthop > Current BGP label nexthop cache for IP, VRF vrf1 > 192.0.2.11, label 20 #paths 3 > if r1-eth1 > Last update: Mon Jan 16 18:52:11 2023 > 192.0.2.12, label 17 #paths 2 > if r1-eth1 > Last update: Mon Jan 16 18:52:08 2023 > 192.0.2.14, label 18 #paths 1 > if r1-eth1 > Last update: Mon Jan 16 18:52:07 2023 > 192.168.255.13, label 19 #paths 1 > if r1-eth2 > Last update: Mon Jan 16 18:52:10 2023 Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2023-03-22bgpd: use nexthop interface when adding LSP in BGP MPLSVPNPhilippe Guibert
BGP MPLSVPN next hop label allocation was using only the next-hop IP address. As MPLSVPN contexts rely on bnc contexts, the real nexthop interface is known, and the LSP entry to enter can apply to the specific interface. To illustrate, the BGP service is able to handle the following two iproute2 commands: > ip -f mpls route add 105 via inet 192.0.2.45 dev r1-eth1 > ip -f mpls route add 105 via inet 192.0.2.46 dev r1-eth2 Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2023-03-22bgpd: add the bgp_label_per_nexthop_cache struct and apisPhilippe Guibert
This commit introduces the necessary structs and apis to create the cache entries that store the label information associated to a given nexthop. A hash table is created in each BGP instance for all the AFIs: IPv4 and IPv6. That hash table is initialised. An API to look and/or create an entry based on a given nexthop. Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2023-03-22bgpd: introduce LP_TYPE_NEXTHOP label typePhilippe Guibert
A new label type is introduced: LP_TYPE_NEXTHOP. This new label type will be used in next commits to allocate labels for a specific nexthop IP address. The commit changes add vty and json outputs to display the new label type and the label values associated. 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-31*: Drop deprecated incorrect JSON fields with wrong namingDonatas Abraitis
Deprecation cycle already passed. Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-10-26build, vtysh: extract vtysh commands from .xrefDavid Lamparter
Rather than running selected source files through the preprocessor and a bunch of perl regex'ing to get the list of all DEFUNs, use the data collected in frr.xref. This not only eliminates issues we've been having with preprocessor failures due to nonexistent header files, but is also much faster. Where extract.pl would take 5s, this now finishes in 0.2s. And since this is a non-parallelizable build step towards the end of the build (dependent on a lot of other things being done already), the speedup is actually noticeable. Also files containing CLI no longer need to be listed in `vtysh_scan` since the .xref data covers everything. `#ifndef VTYSH_EXTRACT_PL` checks are equally obsolete. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2022-08-31bgpd: improve labelpool performance at scaleG. Paul Ziemba
- double the size of each new chunk request from zebra - use bitfields to track label allocations in a chunk - When allocating: - skip chunks with no free labels - search biggest chunks first - start search in chunk where last search ended - Improve API documentation in comments (bgp_lp_get() and callback) - Tweak formatting of "show bgp labelpool chunks" - Add test features (compiled conditionally on BGP_LABELPOOL_ENABLE_TESTS) Signed-off-by: G. Paul Ziemba <paulz@labn.net>
2022-08-25bgpd: Convert prefix2str to %pFXDonatas Abraitis
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-02-03*: Add camelCase JSON keys in addition to PascalCaseDonatas Abraitis
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-11-27*: Remove redundand braces for single statement blocksDonatas Abraitis
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-11-25bgpd: Convert vty_out to vty_json for JSONDonatas Abraitis
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-03-17*: require semicolon after DEFINE_<typesafe...>David Lamparter
Again, see previous commits. Signed-off-by: David Lamparter <equinox@diac24.net>
2021-03-17*: require semicolon after DEFINE_MTYPE & coDavid Lamparter
Back when I put this together in 2015, ISO C11 was still reasonably new and we couldn't require it just yet. Without ISO C11, there is no "good" way (only bad hacks) to require a semicolon after a macro that ends with a function definition. And if you added one anyway, you'd get "spurious semicolon" warnings on some compilers... With C11, `_Static_assert()` at the end of a macro will make it so that the semicolon is properly required, consumed, and not warned about. Consistently requiring semicolons after "file-level" macros matches Linux kernel coding style and helps some editors against mis-syntax'ing these macros. Signed-off-by: David Lamparter <equinox@diac24.net>
2021-01-04bgpd: fix zclient return code damage in labelpoolPat Ruddy
The check for the return code for zclient_send_get_label_chunk is reversed and therefore the pending count does not get incremented for each successful label chunk request. This has the effect of requesting a 50 label chunk per label request from BGP i.e we request 50 times the labels we require. Signed-off-by: Pat Ruddy <pat@voltanet.io>
2021-01-04bgpd: refactor label allocation codePat Ruddy
To prepare for fixing an issue where labels do not get released back to the labelpool when the route is deleted some refactoring is necessary. There are 2 parts to this. 1. restructure the code to remove the circular nature of label allocations via the labelpool and decouple the label type decision from the notification fo the FEC. The code to notify the FEC association to zebra has been split out into a separate function so that it can be called from the synchronous path (for registration of index-based labels and de-registration of all labels), and from the asynchronous path where we need to wait for a callback from the labelpool code with a label allocation. The decision about whether we are using an index-based label or an allocated label is reflected in the state of the BGP_NODE_LABEL_REQUESTED flag so the checks on the path_info in the labelpool callback code are no longer required. 2. change the owned of a labelpool allocated label from the path info structure to the bgp_dest structure. This allows labels to be released (in a subsequent commit) when the owner (bgp_dest) goes away. Signed-off-by: Pat Ruddy <pat@voltanet.io>
2021-01-04bgpd: add missing unlock of path_infoPat Ruddy
when the path info information is queued on the work queue it is protected by a lock to avoid the rug being pulled whilst it resides on the queue add an unlock in the error case where we do no queue the reference to the workqueue. Signed-off-by: Pat Ruddy <pat@voltanet.io>
2021-01-04bgpd: add show commands for bgp labelpoolPat Ruddy
These commands allow the bgp labelpool lists and counts to be viewed for debug purposes. Signed-off-by: Pat Ruddy <pat@voltanet.io>
2020-11-15*: Convert all usage of zclient_send_message to new enumDonald Sharp
The `enum zclient_send_status` enum needs to be extended throughout the code base to use the new states and to fix up places where we tested against the return value being non zero. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2019-07-10lib, zebra: support label chunk requests for SRGBEmanuele Di Pascale
For SRGB, we need to support chunk requests starting at a specific point in the label space, rather than just asking for any sufficiently large chunk. To this purpose, we extend the label manager api to request a chunk with a base value; if the base is set to 0, the label manager will behave as it currently does, i.e. fetching the first free chunk big enough to satisfy the request. update all the existing calls to get chunks from the label manager so that they use MPLS_LABEL_BASE_ANY as the base for the requested chunk Signed-off-by: Emanuele Di Pascale <emanuele@voltanet.io>
2019-07-08bgpd: fix implicit declaration warningEmanuele Di Pascale
Add header with prototype for bgp_path_info_unlock Signed-off-by: Emanuele Di Pascale <emanuele@voltanet.io>
2019-06-24bgpd: fix LU label callback crashEmanuele Di Pascale
under some conditions, the callback to get a label for a LU bgp path could be called after the path had already been freed. In this case we would be reading garbage and potentially crash. Lock the path info before queueing the callback, and unlock as the first step of the callback, exiting gracefully if the path info is now NULL. Signed-off-by: Emanuele Di Pascale <emanuele@voltanet.io>
2019-04-27bgpd: replace label pool fifo with DECLARE_LISTDavid Lamparter
Again, the FIFO_* stuff in lib/fifo.h is no different from a simple unsorted list. Just use DECLARE_LIST here so we can get rid of FIFO_*. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2019-02-25*: remove null check before XFREEQuentin Young
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2018-10-02*: list_delete_and_null() -> list_delete()David Lamparter
Signed-off-by: David Lamparter <equinox@diac24.net>