summaryrefslogtreecommitdiff
path: root/lib/link_state.c
AgeCommit message (Collapse)Author
2025-04-08lib: fix -Wshadow warnings in the lib modulesMark Stapp
Fix various "shadow" warnings in lib. Signed-off-by: Mark Stapp <mjs@cisco.com>
2024-07-11isis, lib: add isis srv6 end sid to ls_prefixPhilippe Guibert
According to draft-ietf-lsr-isis-srv6-extensions draft, the End SID should be available in link state prefix information. Add the SID information in the link state prefix, by getting the END SID from the locator TLV information. Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2024-04-23isis, lib: add isis srv6 capability to ls_nodePhilippe Guibert
Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2024-04-23isisd, lib: add link state support for srv6 adjacenciesPhilippe Guibert
Add support for endx_lan and endx adjacency. Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2023-09-29*: Do not cast to the same type as the destination isDonatas Abraitis
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2023-08-22lib: Fix memory leaks in LS Update FunctionsKeelan10
Previously when updating vertices, edges and subnets, when no update was required due to existing value matching the new one, memory associated with the new object was not being freed leading to memory leaks. This commit fixes memory leak by freeing memory associated with new object when update is unnecessary. The ASan leak log for reference: ``` Direct leak of 312 byte(s) in 3 object(s) allocated from: #0 0x7faf3afbfa37 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:154 #1 0x7faf3ab5dbcf in qcalloc ../lib/memory.c:105 #2 0x7faf3ab42e00 in ls_parse_prefix ../lib/link_state.c:1323 #3 0x7faf3ab43c87 in ls_parse_msg ../lib/link_state.c:1373 #4 0x7faf3ab476a5 in ls_stream2ted ../lib/link_state.c:1885 #5 0x564e045046aa in sharp_opaque_handler ../sharpd/sharp_zebra.c:792 #6 0x7faf3aca35a9 in zclient_read ../lib/zclient.c:4410 #7 0x7faf3ac47474 in event_call ../lib/event.c:1979 #8 0x7faf3ab318b4 in frr_run ../lib/libfrr.c:1213 #9 0x564e044fdc6f in main ../sharpd/sharp_main.c:177 #10 0x7faf3a6f4d8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58 SUMMARY: AddressSanitizer: 312 byte(s) leaked in 3 allocation(s). ``` Signed-off-by: Keelan Cannoo <keelan.cannoo@icloud.com>
2023-06-23lib, zebra: include source client zapi info in opaque messagesMark Stapp
Include the sending zapi client info (proto, instance, and session id) in each opaque zapi message. Add opaque 'init' apis for clients who want to encode their opaque data inline, into the zclient's internal stream buffer. Use these init apis in the TE/link-state lib code, instead of hand-coding the zapi opaque header info. Signed-off-by: Mark Stapp <mjs@labn.net>
2023-05-02Merge pull request #13235 from Orange-OpenSource/link-stateRuss White
lib: Fix memory leaks in Link State library
2023-04-21lib: Fix memory leak in in Link StateOlivier Dugeon
When using ls_stream2ted() function to parse Opaque Link State message to local TED, in case of vertex or subnet deletion, the function return a pointer to the deleted ls_element instead of NULL. This could lead into a potential pointer corruption when caller try to access to the deleted ls_element. This patch ensure that the ls_element pointer return by ls_stream2ted() function is NULL when the message event is a delete operation for vertex and subnet. Note that edge deletion was correctly handled. Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
2023-04-21lib: Link State memory corruptionOlivier Dugeon
In function ls_find_subnet(), prefix argument is directly copied into subnet.key structure to find corresponding subnet in RB Tree. This could leadr to a memory corruption. Function prefix_copy() must be used instead. This patch replaces the direct prefix copy by a call to prefix_copy() function to avoid this memory issue. Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
2023-04-20Merge pull request #12933 from Orange-OpenSource/link_statePhilippe Guibert
lib: Update edge key in link state database
2023-04-12Merge pull request #13193 from Keelan10/link_state-memory-leakJafar Al-Gharaibeh
lib: link state leak fix
2023-04-11Merge pull request #12698 from Orange-OpenSource/isisdRuss White
Isisd/Lib: Add new printfrr format facility for Intermediate System ID
2023-04-07lib: Update Edge Key in link_stateOlivier Dugeon
The original uin64_t for the edge key in link state is not always appropriate with IPv6 addresses. In some cases, 2 different edge with 2 different IPv6 addresses could conduct to the same key. The resulting TED is wrong in this case. This patch replace the uint64_t edge key by a dedicated structure. The resulting key of the edge is: - the local IPv4 address of the corresponding link - the local IPv6 address if no IPv4 address is configured on the link - the local + remote link ID for unnumbered address Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
2023-04-07lib: Fix link state memory leakKeelan10
Free link message data when a delete event is recorded. Signed-off-by: Keelan Cannoo <keelan.cannoo@icloud.com>
2023-04-06*: Use a `struct prefix *p` instead of a `struct prefix` in functionsDonald Sharp
When passing a prefix into a function let's pass by address instead of pass by value. Let's save our stack space. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-21lib: Add ISO System & Network format to printfrrOlivier Dugeon
Like for IP addresses, this patch add a new format for printfrr collection to print ISO System ID and Network address a.k.a IS-IS system ID & Network. This new format is added to the library instead of isisd because other daemons and tools need to print ISO System ID & Network Address. Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
2023-02-17Merge pull request #12780 from opensourcerouting/spdx-license-idDonald Sharp
*: convert to SPDX License identifiers
2023-02-10lib,isisd: add extended admin-group info into the tedLouis Scalbert
Add extended admin-group info into the ted. Signed-off-by: Louis Scalbert <louis.scalbert@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-31lib: Add missing enum's to switch statementDonald Sharp
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-12-13lib: fix ls_prefix memory allocationLouis Scalbert
The wrong size is allocated for struct ls_prefix memory. Fix ls_prefix memory allocation. Fixes: b0c0b43348 ("lib: Update Link State Database") Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2022-08-15lib: Ensure ls_msg2edge does not use memory after freeingDonald Sharp
ls_msg2edge calls ls_edge_del_all which will free the edge variable. Ensure that FRR properly returns NULL. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-08-01lib: Correct valgrind errorsOlivier Dugeon
In CSPF topo test, valgrind detects uninitialized bytes when exporting TE Opaque information through ZEBRA. This is due to C pragma compilation directive __attribute__(aligned(8)) in struct ls_node_id in link_state.h. Valgrind consideris that struct ls_node_id nid = {} doesn't initialized the padding bytes introduced by gcc. This patch simply removes the C pragma compilation directive and also takes opportunity to remove the transmission of remote node id for vertices and subnets which is not known. Indeed, remote node id is only pertinent for edges. Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
2022-03-31isisd, lib, ospfd, pathd: Null out free'd pointerDonald Sharp
The commands: router isis 1 mpls-te on no mpls-te on mpls-te on no mpls-te on ! Will crash Valgrind gives us this: ==652336== Invalid read of size 8 ==652336== at 0x49AB25C: typed_rb_min (typerb.c:495) ==652336== by 0x4943B54: vertices_const_first (link_state.h:424) ==652336== by 0x493DCE4: vertices_first (link_state.h:424) ==652336== by 0x493DADC: ls_ted_del_all (link_state.c:1010) ==652336== by 0x47E77B: isis_instance_mpls_te_destroy (isis_nb_config.c:1871) ==652336== by 0x495BE20: nb_callback_destroy (northbound.c:1131) ==652336== by 0x495B5AC: nb_callback_configuration (northbound.c:1356) ==652336== by 0x4958127: nb_transaction_process (northbound.c:1473) ==652336== by 0x4958275: nb_candidate_commit_apply (northbound.c:906) ==652336== by 0x49585B8: nb_candidate_commit (northbound.c:938) ==652336== by 0x495CE4A: nb_cli_classic_commit (northbound_cli.c:64) ==652336== by 0x495D6C5: nb_cli_apply_changes_internal (northbound_cli.c:250) ==652336== Address 0x6f928e0 is 272 bytes inside a block of size 320 free'd ==652336== at 0x48399AB: free (vg_replace_malloc.c:538) ==652336== by 0x494BA30: qfree (memory.c:141) ==652336== by 0x493D99D: ls_ted_del (link_state.c:997) ==652336== by 0x493DC20: ls_ted_del_all (link_state.c:1018) ==652336== by 0x47E77B: isis_instance_mpls_te_destroy (isis_nb_config.c:1871) ==652336== by 0x495BE20: nb_callback_destroy (northbound.c:1131) ==652336== by 0x495B5AC: nb_callback_configuration (northbound.c:1356) ==652336== by 0x4958127: nb_transaction_process (northbound.c:1473) ==652336== by 0x4958275: nb_candidate_commit_apply (northbound.c:906) ==652336== by 0x49585B8: nb_candidate_commit (northbound.c:938) ==652336== by 0x495CE4A: nb_cli_classic_commit (northbound_cli.c:64) ==652336== by 0x495D6C5: nb_cli_apply_changes_internal (northbound_cli.c:250) ==652336== Block was alloc'd at ==652336== at 0x483AB65: calloc (vg_replace_malloc.c:760) ==652336== by 0x494B6F8: qcalloc (memory.c:116) ==652336== by 0x493D7D2: ls_ted_new (link_state.c:967) ==652336== by 0x47E4DD: isis_instance_mpls_te_create (isis_nb_config.c:1832) ==652336== by 0x495BB29: nb_callback_create (northbound.c:1034) ==652336== by 0x495B547: nb_callback_configuration (northbound.c:1348) ==652336== by 0x4958127: nb_transaction_process (northbound.c:1473) ==652336== by 0x4958275: nb_candidate_commit_apply (northbound.c:906) ==652336== by 0x49585B8: nb_candidate_commit (northbound.c:938) ==652336== by 0x495CE4A: nb_cli_classic_commit (northbound_cli.c:64) ==652336== by 0x495D6C5: nb_cli_apply_changes_internal (northbound_cli.c:250) ==652336== by 0x495D23E: nb_cli_apply_changes (northbound_cli.c:268) Let's null out the pointer. After this change. Valgrind no longer reports issues and isisd no longer crashes. Fixes: #10939 Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-11-30lib: Update Link State functions to handle IPv6Olivier Dugeon
In order to add Link State Traffic Engineering to IS-IS, Link State library should have been updated: - Correct Node and Edge RB Tree comparison functions to support key > 32 bits - Change Subnet RB Tree comparison function to take into account host part of the prefix i.e. 10.0.0.1/24 and 10.0.0.2/24 are considered as different - Add new function to convert IS-IS ISO system ID into Vertex or Edge key that take into account Endianness architecture - Correct Vertex and Edge creation and search function accordingly - Add extra Adjacency entries in Link State Attributes for IPv6 Segment Routing - Update send/received and show TED functions accordingly Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
2021-11-18lib: use _safe iteration during link_state/ted cleanupMark Stapp
Use the _safe iterators when cleaning up the link-state module's vertices, edges, and subnets. Signed-off-by: Mark Stapp <mstapp@nvidia.com>
2021-10-29lib: Fix comparison function in link_state.cOlivier Dugeon
ls_node_same, ls_attributes_same and ls_prefix_same are not producing expected result due to a wrong usage of memcmp. In addition, if respective structures are not initialized with 0, there is a risk that the comparison failed. This patch correct usage of memcmp and expand comparison to each invidual parameters of the respective structure for safer result. Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
2021-06-29*: Do not check for XMALLOC/XCALLOC against NULLsDonatas Abraitis
We don't check this pattern anywhere in the code basically, so let's unify the code. Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-06-17lib: Do not double-assign freed pointer to NULLDonatas Abraitis
It's already done by XFREE. Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-04-23*: make sure `config.h` or `zebra.h` is firstDavid Lamparter
`config.h` has all the defines from autoconf, which may include things that switch behavior of other included headers (e.g. _GNU_SOURCE enabling prototypes for additional functions.) So, the first include in any `.c` file must be either `config.h` (with the appropriate guard) or `zebra.h` (which includes `config.h` first thing.) Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-03-23lib: Update Link State DatabaseOlivier Dugeon
Add new status for Vertex, Edge and Subnet to manage their respective states in the data base. Add new functions: - to register/unregister server and client - to show content of the Database (VTY and Json output) - to update and compare subnets - to clean vertex and ted from ORPHAN elements - to convert message or stream into a Link State Element and update Link State Database accordingly to message event Change Edge and Vertex key computation by using the host order systematically. This impact mostly key based on IPv4 addresses where `ntohl()` function must be used when searching a Vertex or Edge by key. Update the documentation accordingly Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
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-02-16*: fix format string SNAFUsDavid Lamparter
Signed-off-by: David Lamparter <equinox@diac24.net>
2021-02-14*: remove tabs & newlines from log messagesDavid Lamparter
Neither tabs nor newlines are acceptable in syslog messages. They also break line-based parsing of file logs. Signed-off-by: David Lamparter <equinox@diac24.net>
2021-01-27libs, ospfd: remove inet_ntoaMark Stapp
inet_ntoa not permitted - replace instances. Signed-off-by: Mark Stapp <mjs@voltanet.io>
2021-01-04lib: Add Link State DatabaseOlivier Dugeon
Define new models for Link State Database a.k.a TED and functions to manipulate the new database as well as exchange Link State information through ZAPI Opaque message. Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>