summaryrefslogtreecommitdiff
path: root/lib/nexthop.c
AgeCommit message (Collapse)Author
2025-02-08lib: Add sidStructure in SRv6 SIDs JSON outputCarmine Scarpitta
The `show ipv6 route json` command displays the IPv6 routing table in JSON format, including SRv6 SIDs. For each SRv6 SID, it provides behavior and SID attributes. However, it does not include the SID structure. This commit adds the SID structure to the SRv6 SID JSON output. Signed-off-by: Carmine Scarpitta <cscarpit@cisco.com>
2025-01-29lib: clean up nexthop hashing messDavid Lamparter
We were hashing 4 bytes of the address. Even for IPv6 addresses. Oops. The reason this was done was to try to make it faster, but made a complex maze out of everything. Time for a refactor. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2024-11-22lib, zebra: Do not have duplicate memory type problemsDonald Sharp
In zebra_mpls.c it has a usage of MTYPE_NH_LABEL which is defined in both lib/nexthop.c and zebra/zebra_mpls.c. The usage in zebra_mpls.c is a realloc. This leads to a crash: (gdb) bt 0 __pthread_kill_implementation (no_tid=0, signo=6, threadid=126487246404032) at ./nptl/pthread_kill.c:44 1 __pthread_kill_internal (signo=6, threadid=126487246404032) at ./nptl/pthread_kill.c:78 2 __GI___pthread_kill (threadid=126487246404032, signo=signo@entry=6) at ./nptl/pthread_kill.c:89 3 0x0000730a1b442476 in __GI_raise (sig=6) at ../sysdeps/posix/raise.c:26 4 0x0000730a1b94fb18 in core_handler (signo=6, siginfo=0x7ffeed1e07b0, context=0x7ffeed1e0680) at lib/sigevent.c:268 5 <signal handler called> 6 __pthread_kill_implementation (no_tid=0, signo=6, threadid=126487246404032) at ./nptl/pthread_kill.c:44 7 __pthread_kill_internal (signo=6, threadid=126487246404032) at ./nptl/pthread_kill.c:78 8 __GI___pthread_kill (threadid=126487246404032, signo=signo@entry=6) at ./nptl/pthread_kill.c:89 9 0x0000730a1b442476 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26 10 0x0000730a1b4287f3 in __GI_abort () at ./stdlib/abort.c:79 11 0x0000730a1b9984f5 in _zlog_assert_failed (xref=0x730a1ba59480 <_xref.16>, extra=0x0) at lib/zlog.c:789 12 0x0000730a1b8f8908 in mt_count_free (mt=0x576e0edda520 <MTYPE_NH_LABEL>, ptr=0x576e36617b80) at lib/memory.c:74 13 0x0000730a1b8f8a59 in qrealloc (mt=0x576e0edda520 <MTYPE_NH_LABEL>, ptr=0x576e36617b80, size=16) at lib/memory.c:112 14 0x0000576e0ec85e2e in nhlfe_out_label_update (nhlfe=0x576e368895f0, nh_label=0x576e3660e9b0) at zebra/zebra_mpls.c:1462 15 0x0000576e0ec833ff in lsp_install (zvrf=0x576e3655fb50, label=17, rn=0x576e366197c0, re=0x576e3660a590) at zebra/zebra_mpls.c:224 16 0x0000576e0ec87c34 in zebra_mpls_lsp_install (zvrf=0x576e3655fb50, rn=0x576e366197c0, re=0x576e3660a590) at zebra/zebra_mpls.c:2215 17 0x0000576e0ecbb427 in rib_process_update_fib (zvrf=0x576e3655fb50, rn=0x576e366197c0, old=0x576e36619660, new=0x576e3660a590) at zebra/zebra_rib.c:1084 18 0x0000576e0ecbc230 in rib_process (rn=0x576e366197c0) at zebra/zebra_rib.c:1480 19 0x0000576e0ecbee04 in process_subq_route (lnode=0x576e368e0270, qindex=8 '\b') at zebra/zebra_rib.c:2661 20 0x0000576e0ecc0711 in process_subq (subq=0x576e3653fc80, qindex=META_QUEUE_BGP) at zebra/zebra_rib.c:3226 21 0x0000576e0ecc07f9 in meta_queue_process (dummy=0x576e3653fae0, data=0x576e3653fb80) at zebra/zebra_rib.c:3265 22 0x0000730a1b97d2a9 in work_queue_run (thread=0x7ffeed1e3f30) at lib/workqueue.c:282 23 0x0000730a1b96b039 in event_call (thread=0x7ffeed1e3f30) at lib/event.c:1996 24 0x0000730a1b8e4d2d in frr_run (master=0x576e36277e10) at lib/libfrr.c:1232 25 0x0000576e0ec35ca9 in main (argc=7, argv=0x7ffeed1e4208) at zebra/main.c:536 Clearly replacing a label stack is an operation that should be owned by lib/nexthop.c. So lets move this function into there and have zebra_mpls.c just call the function to replace the label stack. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2024-09-10Merge pull request #15259 from dmytroshytyi-6WIND/nexthop_resolutionRuss White
zebra: add LSP entry to nexthop via recursive (part 2)
2024-08-22lib, zebra: Modify nexthop_cmp to allow you to use weight or notDonald Sharp
Currently nexthop weight is a discriminator on whether or not a nexthop matches. There is a need to no use the weight as part of this comparison function so let's add a boolean to allow us to say use this or not. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2024-08-08lib: add seg6localContext json attribute in nexthop informationPhilippe Guibert
Some srv6 behaviors have a context attached that is visible if no json is requested: > # show ipv6 route > [..] > B>* 2001:db8:1:1:100::/128 [20/0] is directly connected, vrf10, seg6local End.DT6 table 10, weight 1, 00:00:14 > B>* 2001:db8:1:1:200::/128 [20/0] is directly connected, vrf20, seg6local End.DT6 table 20, weight 1, 00:00:14 > The json does not dump this attribute: > # show ipv6 route 2001:db8:1:1:100::/128 json > [..] > "nexthops":[ > { > "flags":3, > "fib":true, > "directlyConnected":true, > "interfaceIndex":6, > "interfaceName":"vrf10", > "active":true, > "weight":1, > "seg6local":{ > "action":"End.DT6" > }, > } > Add the json support for this. > "nexthops":[ > { > "flags":3, > "fib":true, > "directlyConnected":true, > "interfaceIndex":6, > "interfaceName":"vrf10", > "active":true, > "weight":1, > "seg6local":{ > "action":"End.DT6" > }, > "seg6localContext":{ > "table":10 > } > } > Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2024-06-07zebra, lib: upon lsp install, iterate nexthop accordinglyPhilippe Guibert
There are two ways of iterating over nexthops of a given route entry. - Either only the main nexthop are taken into account (which is the case today when attempting to install an LSP entry on a BGP connected labeled route. - Or by taking into account nexthops that are resolved and linked in nexthop->resolved of the previous nexthop which has RECURSIVE flag set. This second case has to be taken into account in the case where recursive routes may be used to install an LSP entry. Introduce a new API in nexthop that will parse over the appropriate nexthop, if the nexthop-resolution flag is turned on or not on the given VRF. Use that API in the lsp_install() function so as to walk over the appropriate nexthops. Co-developed-by: Dmytro Shytyi <dmytro.shytyi@6wind.com> Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com> Signed-off-by: Dmytro Shytyi <dmytro.shytyi@6wind.com>
2024-05-15zebra: fix dump SR-TE information if availablePhilippe Guibert
The SR-TE color of nexthop should be displayed in all situations. Fixes: 553c8048460a ("zebra: fix JSON fields for 'show ip/ipv6 nht'") Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2024-05-15zebra, lib: move nexthop display helper to lib folderPhilippe Guibert
The zebra_nexthop_vty_helper() and zebra_nexthop_json_helper() functions could be very helpful to display nexthop information from whatever daemon. Move the core function in the nexthop_vty_helper() and the nexthop_json_helper() function. The zebra API call remains unchanged. Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2024-04-22lib, zebra: Check for not being a blackhole routeDonald Sharp
In zebra_interface_nhg_reinstall zebra is checking that the nhg is a singleton and not a blackhole nhg. This was originally done with checking that the nexthop is a NEXTHOP_TYPE_IFINDEX, NEXTHOP_TYPE_IPV4_IFINDEX and NEXTHOP_TYPE_IPV6_IFINDEX. This was excluding NEXTHOP_TYPE_IPV4 and NEXTHOP_TYPE_IPV6. These were both possible to be received and maintained from the upper level protocol for when a route is being recursively resolved. If we have gotten to this point in zebra_interface_nhg_reinstall the nexthop group has already been installed at least once and we *know* that it is actually a valid nexthop. What the test is really trying to do is ensure that we are not reinstalling a blackhole nexthop group( Which is not possible to even be here by the way, but safety first! ). So let's change to test for that instead. Signed-off-by: Donald Sharp <sharpd@nvidia.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-09-20lib: adapt nexthop_cmp to handle multiple segs SIDsDmytro Shytyi
Extend nexthop_cmp function to process multiple segs SIDs. Signed-off-by: Dmytro Shytyi <dmytro.shytyi@6wind.com>
2023-09-20lib: update del_srv6_seg6_local to handle seg6_segsDmytro Shytyi
Adapt de_srv6_seg6local to handle seg6_segs structure. Signed-off-by: Dmytro Shytyi <dmytro.shytyi@6wind.com>
2023-09-20lib: nexthop, free the multiple seg6_segsDmytro Shytyi
Adapt the function that fees srv6 nexthop to handle multiple segs. Signed-off-by: Dmytro Shytyi <dmytro.shytyi@6wind.com>
2023-09-20lib: in nexthop adaptation pass the number of segs to jhashDmytro Shytyi
Adapt nexthop file to handle hash of multiple segments Signed-off-by: Dmytro Shytyi <dmytro.shytyi@6wind.com>
2023-09-20bgpd,lib,sharpd,zebra: srv6 introduce multiple segs/SIDs in nexthopDmytro Shytyi
Append zebra and lib to use muliple SRv6 segs SIDs, and keep one seg SID for bgpd and sharpd. Note: bgpd and sharpd compilation relies on the lib and zebra files, i.e if we separate this: lib or zebra or bgpd or sharpd in different commits - this will not compile. Signed-off-by: Dmytro Shytyi <dmytro.shytyi@6wind.com>
2023-07-27lib, zebra: Fix EVPN nexthop config orderXiao Liang
Delay EVPN route addition to synchronize with rib_delete(), which now uses early route queue. Signed-off-by: Xiao Liang <shaw.leon@gmail.com>
2023-07-25zebra: add several fields for debuganlan_cs
Two changes for debug: 1. Add a field to indicate its vrf for nexthop. When the interface changes vrf, we can't easily know the vrf of this nexthop according to current log. 2. Add a field to indicate operation type. We can't know whether to add or remove route according to current log. Before: ``` zebra_nhg_increment_ref: nhe 0x555623eb82c0 (76[if 6]) 0 => 1 zebra_interface_nhg_reinstall install nhe 75[77.75.1.75 if 6] nh type 3 flags 0x1 Route 77.75.1.0/24(8) queued for processing into sub-queue Early Route Processing Route 77.75.1.0/24(8) queued for processing into sub-queue Early Route Processing ``` After: ``` zebra_nhg_increment_ref: nhe 0x555623eb82c0 (76[if 6 vrfid 9]) 0 => 1 zebra_interface_nhg_reinstall install nhe 75[77.75.1.75 if 6 vrfid 8] nh type 3 flags 0x1 Route 77.75.1.0/24(8) (add) queued for processing into sub-queue Early Route Processing Route 77.75.1.0/24(8) (delete) queued for processing into sub-queue Early Route Processing ``` Signed-off-by: anlan_cs <anlan_cs@tom.com>
2023-05-05zebra: re-install nhg on interface upAshwini Reddy
Intermittently zebra and kernel are out of sync when interface flaps and the add's/dels are in same processing queue and zebra assumes no change in nexthop. Hence we need to bring in a reinstall to kernel of the nexthops and routes to sync their states. Upon interface flap kernel would have deleted NHGs associated to a interface (the one flapped), zebra retains NHGs for 3 mins even though upper layer protocol removes the nexthops (associated NHG). As part of interface address add , re-add singleton NHGs associated to interface. Ticket: #3173663 Issue: 3173663 Signed-off-by: Ashwini Reddy <ashred@nvidia.com> Signed-off-by: Chirag Shah <chirag@nvidia.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>
2022-06-14lib: Abstract usage of '%pNHs' so that nexthop groups can use it tooDonald Sharp
Abstract the usage of '%pNHs' so that when nexthop groups get a new special printfrr that it can take advantage of this functionality too. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-01-14*: use semicolon after printfrr_ext_autoreg_{p,d}David Lamparter
Mostly to make clang-format not format these to peak ugly. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-09-15Merge pull request #9596 from LabNConsulting/ziemba/printfrr-nexthopDonald Sharp
printfrr %pNHcg, %pNHci
2021-09-14lib: Fix usage of defaultDonald Sharp
case default has snuck into our code base for switches over enumerated types. Remove. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-09-14lib,doc,tests: printfrr %pNHcg, %pNHciG. Paul Ziemba
Signed-off-by: G. Paul Ziemba <paulz@labn.net>
2021-09-07bgpd: VRF-Lite fix nexthop typeKantesh Mundaragi
Description: Change is intended for fixing the following issues related to vrf route leaking: Routes with special nexthops i.e. blackhole/sink routes when imported, are not programmed into the FIB and corresponding nexthop is set as 'inactive', nexthop interface as 'unknown'. While importing/leaking routes between VRFs, in case of special nexthop(ipv4/ipv6) once bgp announces route(s) to zebra, nexthop type is incorrectly set as NEXTHOP_TYPE_IPV6_IFINDEX/NEXTHOP_TYPE_IFINDEX i.e. directly connected even though we are not able to resolve through an interface. This leads to nexthop_active_check marking nexthop !NEXTHOP_FLAG_ACTIVE. Unable to find the active nexthop(s), route is not programmed into the FIB. Whenever BGP leaks routes, set the correct nexthop type, so that route gets resolved and correctly programmed into the FIB, in the imported vrf. Co-authored-by: Kantesh Mundaragi <kmundaragi@vmware.com> Signed-off-by: Iqra Siddiqui <imujeebsiddi@vmware.com>
2021-06-02lib,sharpd,zebra: update nexthop object with nh_srv6Hiroki Shirokura
Signed-off-by: Hiroki Shirokura <slank.dev@gmail.com>
2021-06-02lib: add new nexthop's attributes seg6 (step3)Hiroki Shirokura
This commit add new nexthop's addional object for SRv6 routing about seg6 route. Before this commit, we can add MPLS info as additional object on nexthop. This commit make it add more support about seg6 routes. seg6 routes are ones of the LWT routing mechanism, so configuration of seg6local routes is performed by ZEBRA_ROUTE_SEND, it's same as MPLS configuration. Real configuration implementation isn't implemented at this commit. later commit add that. This commit add only nexthop additional object and some misc functions. Signed-off-by: Hiroki Shirokura <slank.dev@gmail.com>
2021-06-02lib: add new nexthop's attributes seg6local (step1)Hiroki Shirokura
This commit is a part of #5853 works that add new nexthop's addional object for SRv6 routing about seg6local route. Before this commit, we can add MPLS info as additional object on nexthop. This commit make it add more support about seg6local routes. seg6local routes are ones of the LWT routing mechanism, so configuration of seg6local routes is performed by ZEBRA_ROUTE_SEND, it's same as MPLS configuration. Real configuration implementation isn't implemented at this commit. later commit add that. This commit add only nexthop additional object and some misc functions. Signed-off-by: Hiroki Shirokura <slank.dev@gmail.com>
2021-05-04lib: add basic nexthop comparison apiMark Stapp
Add a simpler, more limited nexthop comparison function. This compares a few key attributes, such as vrf, gateway, labels. Signed-off-by: Mark Stapp <mjs@voltanet.io>
2021-05-04lib: Fix label-stack comparison for nexthopsMark Stapp
Use the correct number of octets in the comparison of nexthops' label stacks. Signed-off-by: Mark Stapp <mjs@voltanet.io>
2021-03-30lib: put printfrr extension args into structDavid Lamparter
... for easier extensibility. Add width, # and - flags while at it. Signed-off-by: David Lamparter <equinox@diac24.net>
2021-03-27lib: print `(null)` rather than `NULL`David Lamparter
... for consistency with `%s`, which also prints `(null)`. Signed-off-by: David Lamparter <equinox@diac24.net>
2021-03-27lib: rework printfrr extensions to output directlyDavid Lamparter
Allowing printfrr extensions to directly write to the output buffer has a few advantages: - there is no arbitrary length limit imposed (previously 64) - the output doesn't need to be copied another time - the extension can directly use bprintfrr() to put together pieces The downside is that the theoretical length (regardless of available buffer space) must be computed correctly. Extended unit tests to test these paths a bit more thoroughly. 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-03-01lib: print NULL for NULL nexthopsMark Stapp
Instead of crashing, print "NULL" when printfrr callback for nexthops is called for a NULL nexthop argument. Signed-off-by: Mark Stapp <mjs@voltanet.io>
2020-10-22lib: Convert inet_ntoa to %pI4Donatas Abraitis
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2020-10-02lib: remove nexthop_same_firsthop() apiStephen Worley
Remove the nexthop_same_firsthop() api and just call nexthop_same(). Not entirely sure why we were using this function in the first place, but now we are just marking dupes with it so lets just call a common function and avoid issues. Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2020-08-07lib, zebra: Add SR-TE policy infrastructure to zebraSebastien Merle
For the sake of Segment Routing (SR) and Traffic Engineering (TE) Policies there's a need for additional infrastructure within zebra. The infrastructure in this PR is supposed to manage such policies in terms of installing binding SIDs and LSPs. Also it is capable of managing MPLS labels using the label manager, keeping track of nexthops (for resolving labels) and notifying interested parties about changes of a policy/LSP state. Further it enables a route map mechanism for BGP and SR-TE colors such that learned BGP routes can be mapped onto SR-TE Policies. This PR does not introduce any usable features by now, it is just infrastructure for other upcoming PRs which will introduce 'pathd', a new SR-TE daemon. Co-authored-by: Renato Westphal <renato@opensourcerouting.org> Co-authored-by: GalaxyGorilla <sascha@netdef.org> Signed-off-by: Sebastien Merle <sebastien@netdef.org>
2020-07-17lib: use const in nexthop_level() apiMark Stapp
Use const in nexthop_level() Signed-off-by: Mark Stapp <mjs@voltanet.io>
2020-07-17lib: add nexthop_str2backupMark Stapp
Add an api to convert an input list into an array of backup nexthop indexes; useful for cli input. Signed-off-by: Mark Stapp <mjs@voltanet.io>
2020-07-17lib,sharpd,zebra: initial support for multiple backup nexthopsMark Stapp
Initial changes to support a nexthop with multiple backups. Lib changes to hold a small array in each primary, zapi message changes to support sending multiple backups, and daemon changes to show commands to support multiple backups. The config input for multiple backup indices is not present here. Signed-off-by: Mark Stapp <mjs@voltanet.io>
2020-07-07lib: test vrfs in nexthop_same_firsthop()Mark Stapp
Test the two nexthops' vrfs, and convert api to 'bool' return. Signed-off-by: Mark Stapp <mjs@voltanet.io>
2020-03-27lib: add backup-nexthop value to nexthopMark Stapp
Add a field supporting a backup nexthop. Signed-off-by: Mark Stapp <mjs@voltanet.io>
2020-03-27zebra,lib: use const in more apisMark Stapp
Use const with some args to ipaddr, zebra vxlan, mpls lsp, and nexthop apis; add some extra checks to some nexthop-related apis. Signed-off-by: Mark Stapp <mjs@voltanet.io>
2020-03-18lib: remove null check before free nh_labelsQuentin Young
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2020-01-15lib,zebra: tighten up the nexthop_copy/nexthop_dup APIsStephen Worley
Make the nexthop_copy/nexthop_dup APIs more consistent by adding a secondary, non-recursive, version of them. Before, it was inconsistent whether the APIs were expected to copy recursive info or not. Make it clear now that the default is recursive info is copied unless the _no_recurse() version is called. These APIs are not heavily used so it is fine to change them for now. Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-12-16lib: default nexthop weights to oneStephen Worley
Default all nexthop weights to one. The linux kernel does some weird stuff where it adds one to all nexthop weight values it gets. So, we added df7fb5800b3798057747873c8be245eb13f3ec36 with some special subtracing/adding to account for this. Though, that patch did not account for the default case of the weight being zero for elements in the group. Hence, this patch defaults the nexthop weight to one during creation. This should be a valid value on all platforms anyway so shouldn't affect anything. Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-12-09lib, zebra: Allow for encode/decode of nexthop weight in pass downDonald Sharp
Add code to encode/decode the nexthop weight when we pass it down into zebra. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-12-09lib, zebra: Allow for installation of a weighted nexthopDonald Sharp
Linux has the idea of allowing a weight to be sent down as part of a nexthop group to allow the kernel to weight particular nexthop paths a bit more or less than others. See: http://tldp.org/HOWTO/Adv-Routing-HOWTO/lartc.rpdb.multiple-links.html Allow for installation into the kernel using the weight attribute associated with the nexthop. This code is foundational in that it just sets up the ability to do this, we do not use it yet. Further commits will allow for the pass through of this data from upper level protocols. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>