summaryrefslogtreecommitdiff
path: root/lib/stream.c
AgeCommit message (Collapse)Author
2025-03-20lib: Add support for stream buffer to expandSoumya Roy
Issue: Currently, during encode time, if required memory is more than available space in stream buffer, stream buffer can't be expanded. This fix introduces new apis to support stream buffer expansion. Testing: Tested with zebra nexthop encoding with 512 nexthops, which triggers this new code changes, it works fine. Without fix, for same trigger it asserts. Signed-off-by: Soumya Roy <souroy@nvidia.com>
2024-05-31lib: Make the ip arg const in stream_put_ipaddrMike RE Mallin
Signed-off-by: Mike RE Mallin <mremallin@gmail.com>
2024-04-16zebra: Actually display I/O buffer sizes (part-2)Rajasekar Raja
An extension of commit-8d8f12ba8e5cd11c189b8475b05539fa8415ccb9 Removing ifdef DEV_BUILD in stream_fifo_push as well to make the 'sh zebra client' display the current I/O fifo along with max fifo items. TICKET :#3390099 Signed-off-by: Rajasekar Raja <rajasekarr@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>
2023-01-31lib: Add missing enum's to switch statementDonald Sharp
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-07-20*: frr_with_mutex change to follow our standardDonald Sharp
convert: frr_with_mutex(..) to: frr_with_mutex (..) To make all our code agree with what clang-format is going to produce Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-06-16Merge pull request #11419 from anlancs/fix/minor-1Donald Sharp
zebra, lib: minor changes
2022-06-16lib: correct two commentsanlan_cs
Signed-off-by: anlan_cs <vic.lan@pica8.com>
2022-06-15lib: stream_dup memory alloc cannot failDonald Sharp
If stream_dup calls stream_new, stream_new can never return a NULL pointer so the check is unneeded. Signed-off-by: Donald Sharp <sharpd@nvidia.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>
2021-06-29lib: Avoid using assignments within checksDonatas Abraitis
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.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-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>
2020-11-24lib: add new stream function to reorganize bufferRafael Zalamena
The function was originally implemented for zebra data plane FPM plugin, but another code places could use it. Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2020-09-03lib: add stream_rewind_getp()Quentin Young
stream_forward_getp() cannot be used with negative numbers due to the size_t argument, we'll end up doing overflow arithmetic. Signed-off-by: Quentin Young <qlyoung@nvidia.com>
2020-08-15lib: add STREAM_FORWARD_[GET|ENDP]Quentin Young
Safe stream macros for adjusting buffer pointers Signed-off-by: Quentin Young <qlyoung@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-20lib: add a backtrace when stream bounds check failsMark Stapp
Add a backtrace call when the stream code detects a bounds error, to help with debugging. Signed-off-by: Mark Stapp <mjs@voltanet.io>
2020-06-02lib: add stream_fifo_init, more constMark Stapp
Add utilities that init and deinit a stream_fifo - this lets us use an on-stack fifo in some places, avoiding malloc'ing. Also add const to some apis (no functional changes there). Signed-off-by: Mark Stapp <mjs@voltanet.io>
2020-05-28lib: stream_hexdump takes const structWesley Coakley
Signed-off-by: Wesley Coakley <wcoakley@cumulusnetworks.com>
2020-05-28zebra, lib: bugfix on zebra packet debuggingWesley Coakley
`debug zebra packet detail` dumps the full message whereas it had been dropping exactly 10 bytes, the size of the zebra header Signed-off-by: Wesley Coakley <wcoakley@cumulusnetworks.com>
2020-04-13lib: add STREAM_GETQ, STREAM_GETFQuentin Young
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2020-03-26lib, bgpd: Another round of `struct const prefix` cleanupDonald Sharp
Cleanup another set of functions that need to respect the const'ness of a prefix. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-12-06lib: use const in several stream lib apisMark Stapp
Add some const to some stream apis. Signed-off-by: Mark Stapp <mjs@voltanet.io>
2019-09-03lib: add frr_with_mutex() block-wrapperDavid Lamparter
frr_with_mutex(...) { ... } locks and automatically unlocks the listed mutex(es) when the block is exited. This adds a bit of safety against forgetting the unlock in error paths & co. and makes the code a slight bit more readable. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2019-08-22lib: remove deprecated stream_resize apiMark Stapp
Signed-off-by: Mark Stapp <mjs@voltanet.io>
2019-08-06bgpd: tx addpath info for labeled unicastQuentin Young
Labeled unicast needs path IDs too! Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2018-09-13*: style for EC replacementsQuentin Young
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2018-09-13*: LIB_[ERR|WARN] -> EC_LIBQuentin Young
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2018-09-12Merge remote-tracking branch 'frr/master' into warningsDavid Lamparter
Conflicts: zebra/if_ioctl_solaris.c zebra/rtread_getmsg.c Signed-off-by: David Lamparter <equinox@diac24.net>
2018-09-09*: fix some random warningsDavid Lamparter
Signed-off-by: David Lamparter <equinox@diac24.net>
2018-09-06lib: Convert stream.c to use new error code subsystemDonald Sharp
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2018-08-22lib: Convert stream_new to use one mallocDonald Sharp
Modify stream.c to have stream_new call one malloc call instead of two. Also change stream_resize_orig to use stream_resize_inplace and to send an error to the developer to switch over. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2018-08-22lib: Add stream_resize_orig and stream_resize_inplaceDonald Sharp
Start setup for handling of stream_resize into old and new functions. Create a stream_resize_inplace function that takes a double pointer to allow for a realloc operation to return the possibly moved pointer. Add a CONFDATE for removal as well. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2018-08-02lib: Increase stream allocation speed.Donald Sharp
Modify stream_new in this way: 1) ALLOC allocations do not fail, they cause a crash so remove if tests for it. 2) Modify usage of XCALLOC to XMALLOC and then hand set all the relevant data in the stream pointer. With this modification stream allocation of 10000000 streams at 10k bytes each reduced from on average 1.43 seconds to 0.65 seconds. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2018-06-27lib, zebra: Add a bit of code to look at fifoDonald Sharp
When in a dev build add a bit of code to track max depth of a fifo and to allow zebra to report on it. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2018-05-07lib: add mt-safe variants for stream_fifo opsQuentin Young
stream_fifo is used as our standard internal message queue. Message queues are useful in multithreaded environments. Up until now I have been doing my own synchronization when using stream_fifo in this way; this patch gets rid of the need for that boilerplate and decreases the risk of locking mistakes when working with this datastructure. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2018-04-25lib: fix heap corruption in stream_fifo_freeQuentin Young
When popping a stream from a stream_fifo, the stream->next pointer is not NULL'd out. If this same stream is subsequently pushed onto a stream_fifo (either the same one or a different one), because stream_fifo's use tail insertion the ->next pointer is not updated and thus will point to whatever the next stream in the first stream_fifo was. stream_fifo_free does not check the count of the stream_fifo when freeing its constituent elements, and instead walks the linked list. Consequently it will continue walking into the first stream_fifo from which the last stream was popped, freeing each stream contained there. This leads to use-after-free errors. This patch makes sure to set the ->next pointer to NULL when doing tail insertion in stream_fifo_push and when popping a stream from a stream_fifo. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2018-03-27*: use C99 standard fixed-width integer typesQuentin Young
The following types are nonstandard: - u_char - u_short - u_int - u_long - u_int8_t - u_int16_t - u_int32_t Replace them with the C99 standard types: - uint8_t - unsigned short - unsigned int - unsigned long - uint8_t - uint16_t - uint32_t Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2018-03-06*: conform with COMMUNITY.md formatting rules, via 'make indent'Lou Berger
Signed-off-by: Lou Berger <lberger@labn.net>
2017-11-13lib: Add STREAM_GETX functionsDonald Sharp
Currently when stream reads fail, for any reason, we assert. While a *great* debugging tool, Asserting on production code is not a good thing. So this is the start of a conversion over to a series of STREAM_GETX functions that do not assert and allow the developer a way to program this gracefully and still clean up. Current code is something like this( taken from redistribute.c because this is dead simple ): afi = stream_getc(client->ibuf); type = stream_getc(client->ibuf); instance = stream_getw(client->ibuf); This code has several issues: 1) There is no failure mode for the stream read other than assert. if afi fails to be read the code stops. 2) stream_getX functions cannot be converted to a failure mode because it is impossible to tell a failure from good data with this api. So this new code will convert to this: STREAM_GETC(client->ibuf, afi); STREAM_GETC(client->ibuf, type); STREAM_GETW(client->ibuf, instance); .... stream_failure: return; We've created a stream_getc2( which does not assert ), but we need a way to allow clean failure mode handling. This is done by macro'ing stream_getX2 functions with the equivalent all uppercase STREAM_GETX functions that include a goto. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2017-09-09*: fix be32 reading / 24-bit left shiftDavid Lamparter
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-07-17*: reindentreindent-master-afterwhitespace / reindent
indent.py `git ls-files | pcregrep '\.[ch]$' | pcregrep -v '^(ldpd|babeld|nhrpd)/'` Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-06-16bgpd: Install SAFI_LABELED_UNICAST routes in SAFI_UNICAST tableDaniel Walton
Signed-off-by: Daniel Walton <dwalton@cumulusnetworks.com> - All ipv4 labeled-unicast routes are now installed in the ipv4 unicast table. This allows us to do things like take routes from an ipv4 unicast peer, allocate a label for them and TX them to a ipv4 labeled-unicast peer. We can do the opposite where we take routes from a labeled-unicast peer, remove the label and advertise them to an ipv4 unicast peer. - Multipath over a labeled route and non-labeled route is not allowed. - You cannot activate a peer for both 'ipv4 unicast' and 'ipv4 labeled-unicast' - The 'tag' variable was overloaded for zebra's route tag feature as well as the mpls label. I added a 'mpls_label_t mpls' variable to avoid this. This is much cleaner but resulted in touching a lot of code.
2017-05-15*: make consistent & update GPLv2 file headersDavid Lamparter
The FSF's address changed, and we had a mixture of comment styles for the GPL file header. (The style with * at the beginning won out with 580 to 141 in existing files.) Note: I've intentionally left intact other "variations" of the copyright header, e.g. whether it says "Zebra", "Quagga", "FRR", or nothing. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-04-06bgpd: labeled unicast processingDon Slice
Implement support for negotiating IPv4 or IPv6 labeled-unicast address family, exchanging prefixes and installing them in the routing table, as well as interactions with Zebra for FEC registration. This is the implementation of RFC 3107. Signed-off-by: Don Slice <dslice@cumulusnetworks.com>
2016-09-19*: split & distribute memtypes and stop (re|ab)using lib/ MTYPEsDavid Lamparter
This is a rather large mechanical commit that splits up the memory types defined in lib/memtypes.c and distributes them into *_memory.[ch] files in the individual daemons. The zebra change is slightly annoying because there is no nice place to put the #include "zebra_memory.h" statement. bgpd, ospf6d, isisd and some tests were reusing MTYPEs defined in the library for its own use. This is bad practice and would break when the memtype are made static. Acked-by: Vincent JARDIN <vincent.jardin@6wind.com> Acked-by: Donald Sharp <sharpd@cumulusnetworks.com> [CF: rebased for cmaster-next] Signed-off-by: David Lamparter <equinox@opensourcerouting.org> Signed-off-by: Christian Franke <chris@opensourcerouting.org>
2016-09-03Update Traffic Engineering Support for OSPFDOlivier Dugeon
NOTE: I am squashing several commits together because they do not independently compile and we need this ability to do any type of sane testing on the patches. Since this series builds together I am doing this. -DBS This new structure is the basis to get new link parameters for Traffic Engineering from Zebra/interface layer to OSPFD and ISISD for the support of Traffic Engineering * lib/if.[c,h]: link parameters struture and get/set functions * lib/command.[c,h]: creation of a new link-node * lib/zclient.[c,h]: modification to the ZBUS message to convey the link parameters structure * lib/zebra.h: New ZBUS message Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com> Add support for IEEE 754 format * lib/stream.[c,h]: Add stream_get{f,d} and stream_put{f,d}) demux and muxers to safely convert between big-endian IEEE-754 single and double binary format, as used in IETF RFCs, and C99. Implementation depends on host using __STDC_IEC_559__, which should be everything we care about. Should correctly error out otherwise. * lib/network.[c,h]: Add ntohf and htonf converter * lib/memtypes.c: Add new memeory type for Traffic Engineering support Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com> Add link parameters support to Zebra * zebra/interface.c: - Add new link-params CLI commands - Add new functions to set/get link parameters for interface * zebra/redistribute.[c,h]: Add new function to propagate link parameters to routing daemon (essentially OSPFD and ISISD) for Traffic Engineering. * zebra/redistribute_null.c: Add new function zebra_interface_parameters_update() * zebra/zserv.[c,h]: Add new functions to send link parameters Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com> Add support of new link-params CLI to vtysh In vtysh_config.c/vtysh_config_parse_line(), it is not possible to continue to use the ordered version for adding line i.e. config_add_line_uniq() to print Interface CLI commands as it completely break the new LINK_PARAMS_NODE. Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com> Update Traffic Engineering support for OSPFD These patches update original code to RFC3630 (OSPF-TE) and add support of RFC5392 (Inter-AS v2) & RFC7471 (TE metric extensions) and partial support of RFC6827 (ASON - GMPLS). * ospfd/ospf_dump.[c,h]: Add new dump functions for Traffic Engineering * ospfd/ospf_opaque.[c,h]: Add new TLV code points for RFC5392 * ospfd/ospf_packet.c: Update checking of OSPF_OPTION * ospfd/ospf_vty.[c,h]: Update ospf_str2area_id * ospfd/ospf_zebra.c: Add new function ospf_interface_link_params() to get Link Parameters information from the interface to populate Traffic Engineering metrics * ospfd/ospfd.[c,h]: Update OSPF_OPTION flags (T -> MT and new DN) * ospfd/ospf_te.[c,h]: Major modifications to update the code to new link parameters structure and new RFCs Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com> tmp
2016-07-28lib: add 3-byte stream functionsDavid Lamparter
This will be used for BGP MPLS labels. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2016-06-09*: make sure zebra.h is always included firstDavid Lamparter
zebra.h pulls in config.h, which results in fiddling with things like __FILE_OFFSET_BITS. It must always be included first, in order to set flags that influence the compiler via <features.h>. Signed-off-by: David Lamparter <equinox@opensourcerouting.org> (cherry picked from commit 821df2cf18e5978cc7ab532a8695444380d08270)