summaryrefslogtreecommitdiff
path: root/lib/table.h
AgeCommit message (Collapse)Author
2021-06-18lib: remove pure attribute from functions that modify memoryIgor Ryzhov
Almost all functions currently marked with pure attribute acquire a route_node lock. By marking them pure we allow compiler to optimize the code and not call them when it already knows the return value. This is completely incorrect. Only two of eleven functions can be marked as pure. And they still won't be optimized because they are never called from the same function twice. Let's remove the ext_pure macro completely to reduce the chance of repeating this mistake in the future. Fixes #8866, #8809, #8595, #6992. Signed-off-by: Igor Ryzhov <iryzhov@nfware.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>
2020-10-17*: Create/Use accessor functions for lock countDonald Sharp
Create appropriate accessor functions for the rn->lock data. We should be accessing this data through accessor functions since it is private data to the data structure. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2020-03-29lib: prepare for plugin-based frr_format checkDavid Lamparter
Signed-off-by: David Lamparter <equinox@diac24.net>
2019-12-02*: generously apply constDavid Lamparter
const const const your boat, merrily down the stream... Signed-off-by: David Lamparter <equinox@diac24.net>
2019-07-01*: s/TRUE/true/, s/FALSE/false/Quentin Young
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-06-21lib: use MTYPE_STATICDavid Lamparter
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2019-05-29lib: fix false compiler warningQuentin Young
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-05-21lib/table: remove nonsensical const, add pureDavid Lamparter
Passing the struct route_table *ptr as const doesn't really help; if anything it semantically would imply that the returned route_node is const too since constness should propagate (but it doesn't in C.) The right thing to do here - which actually helps the compiler optimize the code too - is to tag functions with __attribute__((pure)). The compiler does this automatically if it has the function body (and the body of all called functions) available. That should cover most "static inline" functions in headers, as well as functions in the same file. However, this doesn't work (at least without LTO) for extern functions. Hence, add "ext_pure" for this case. (Built-in "extern" to make lines shorter.) Signed-off-by: David Lamparter <equinox@diac24.net>
2019-05-02lib: Convert table code to use new hash typeDonald Sharp
This converts the new table code to use the new hash type provided by David. The following test is 1 million routes installed and how much memory we are using: Old mem usage: Memory statistics for zebra: System allocator statistics: Total heap allocated: 574 MiB Holding block headers: 0 bytes Used small blocks: 0 bytes Used ordinary blocks: 536 MiB Free small blocks: 33 MiB Free ordinary blocks: 4600 KiB Ordinary blocks: 0 Small blocks: 0 Holding blocks: 0 New Memory usage: Memory statistics for zebra: System allocator statistics: Total heap allocated: 542 MiB Holding block headers: 0 bytes Used small blocks: 0 bytes Used ordinary blocks: 506 MiB Free small blocks: 3374 KiB Free ordinary blocks: 33 MiB Ordinary blocks: 0 Small blocks: 0 Holding blocks: 0 Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-05-02Revert "Zebra diet"Lou Berger
2019-05-01lib: Convert table code to use new hash typeDonald Sharp
This converts the new table code to use the new hash type provided by David. The following test is 1 million routes installed and how much memory we are using: Old mem usage: Memory statistics for zebra: System allocator statistics: Total heap allocated: 574 MiB Holding block headers: 0 bytes Used small blocks: 0 bytes Used ordinary blocks: 536 MiB Free small blocks: 33 MiB Free ordinary blocks: 4600 KiB Ordinary blocks: 0 Small blocks: 0 Holding blocks: 0 New Memory usage: Memory statistics for zebra: System allocator statistics: Total heap allocated: 542 MiB Holding block headers: 0 bytes Used small blocks: 0 bytes Used ordinary blocks: 506 MiB Free small blocks: 3374 KiB Free ordinary blocks: 33 MiB Ordinary blocks: 0 Small blocks: 0 Holding blocks: 0 Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-02-11lib: add extern "C" {} blocks to all libfrr headersRenato Westphal
These are necessary to use functions defined in these headers from C++. Signed-off-by: David Lamparter <equinox@diac24.net> Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-02-11lib: revert table.h change for C++David Lamparter
This reverts the lib/table.h change from commit 049b31f7d810fd70069e3edbbd3fea6b5c7af98f. Signed-off-by: David Lamparter <equinox@diac24.net>
2019-02-11libs, daemons: changes to permit c++ compilationMark Stapp
Some misc changes to resolve some c++ compilation errors. The goal is only to permit an external module - a plugin, for example - to see frr headers, not to support or encourage contributions in c++. The changes include: avoiding use of keywords like 'new', 'delete'; cleaning up implicit type-casting from 'void *' in several places. Signed-off-by: Mark Stapp <mjs@voltanet.io>
2018-09-23bgpd, lib, zebra: Wrapper get/set of table->info pointerDonald Sharp
Wrapper the get/set of the table->info pointer so that people are not directly accessing this data. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2018-08-30lib: Move aggregate pointer into aggregate route/tableDonald Sharp
Move the aggregate pointer from the route_node into agg_node so that people using struct route_node will see a savings in data size. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2018-08-22lib/bgpd: re-fix bgp_info_extra_free()David Lamparter
Make the wart slightly less bad... also there is still a possible write after free here. This needs to be fixed again, properly, by some structure changes. Signed-off-by: David Lamparter <equinox@diac24.net>
2018-07-29Merge pull request #2728 from donaldsharp/table_cleanupRuss White
lib: Add parameter names as a hint of what is expected.
2018-07-27lib: Modify route unlock code to return appropriate pointerDonald Sharp
Modify the unlock code for a route_node to return NULL on pointer freed or to return the node itself again. We'll need to go through the code and fix this pattern, but this is a problem for another day. Get this fix in place and we can make it a low hanging problem to fix. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2018-07-25lib: Add parameter names as a hint of what is expected.Donald Sharp
Add some parameter names to functions in table.h to give a clue as to what we expect people to pass in. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2018-04-22lib: table.h needs to include prefix.hQuentin Young
For the last six years this source file has been using a type defined in a header it did not include. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-08-22lib: fix const-check in route_nodeDavid Lamparter
route_node->lock is "const" if --enable-dev-build is used. This is done to deter people from messing with internals of the route_table... unfortunately, the inline'd route_[un]lock_node runs into this. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-08-17lib: inline route_node_lock()/route_node_unlock()Jorge Boncompte
Avoid function calls. Signed-off-by: Jorge Boncompte <jbonor@gmail.com>
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-07-11lib: table: maintain parallel hash for route_tableDavid Lamparter
See next commit for description. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-07-11lib: add some abstraction guards for table codeDavid Lamparter
route_node->parent and route_node->link shouldn't be touched by user code since that is a recipe for trouble once we have a hash table in parallel. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-07-11lib: use "union prefixconstptr" in table codeDavid Lamparter
This allows passing struct prefix_{ipv4,ipv6,evpn} * in addition to struct prefix * without an extra cast (since the union uses the gcc transparent-union extension present in all compilers that we support.) Also applies some "const" while we're at it. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
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-01-30lib: add cleanup hook to route tableChristian Franke
2017-01-30lib: add second-level route_table for srcdestDavid Lamparter
IPv6 srcdest routes need to be keyed by both destination and source prefix. Since the lookup order is destination first, the simplest thing to do here is to add a second route_table to destination entries, which then contain source entries. Sadly, the result is somewhat confusing since a route_node might now be either a source node or a destination node. There are helper functions to get source and destination prefix from a given route node (which can be either a destination or a source route). The following bits have been added by Christian Franke <chris@opensourcerouting.org>: - make srcdest routing table reusable by moving it into lib - make the srcdest routing table structure more opaque - implement a srcdest routing table iterator - fix a refcounting issue in src_node_lookup - match route_node_lookup behavior with srcdest_rnode_lookup - add accessor for the route_node table and table_info - add string formatter srcdest_rnode2str Signed-off-by: David Lamparter <equinox@opensourcerouting.org> Signed-off-by: Christian Franke <chris@opensourcerouting.org> [v3: adapted for cmaster-next as of 2016-12-05]
2017-01-30lib: add route_node_lookup_maynullDavid Lamparter
The sourcedest code needs to get the route_node even if its info pointer is NULL (which occurs when there are srcdest routes, but no general destination route.) Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-01-13frr: Remove HAVE_IPV6 from code baseDonald Sharp
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2016-11-28zebra/lib: plug several memleaksRenato Westphal
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2016-09-30lib: add route_table_get_default_delegateLou Berger
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-05-26route table: constify some APIsTimo Teräs
Signed-off-by: Timo Teräs <timo.teras@iki.fi> Signed-off-by: David Lamparter <equinox@opensourcerouting.org> (cherry picked from commit 3293bc280f15d8e3c04e0bf9b0a8d54d342a87a9)
2016-05-26*: remove stray extra semicolonsDavid Lamparter
Some places had extra semicolons where none belong. Remove them. Signed-off-by: David Lamparter <equinox@opensourcerouting.org> (cherry picked from commit b7d5021bfa161f797cbfb1e92bf5b94327fb1b71)
2012-09-26lib/table: add route_table_get_next() and iteratorAvneesh Sachdev
* lib/table.[ch] - Add a function (route_table_get_next()) to get the route_node in a tree that succeeds a given prefix in iteration order. This allows one to reliably walk nodes in a tree while allowing modifications, and is useful for achieving scale and performance. Other approaches are also possible -- the main plus point of this one is that it does not require any state about the walk to be maintained in the table data structures. - Add an iterator for walking the nodes in a tree. This introduces a new structure (route_table_iter_t) and the following main functions. route_table_iter_init() route_table_iter_pause() route_table_iter_next() route_table_iter_cleanup() The iterator normally uses node pointers and the existing route_next() function to walk nodes efficiently. When an iteration is 'paused' with route_table_iter_pause(), it stores the last prefix processed. The next call to route_table_iter_next() transparently invokes route_table_get_next() with the prefix to resume iteration. * bgpd/bgp_table.[ch] Add wrappers for the new table features described above. * tests/table_test.c Add tests for the new table code. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2012-09-26lib: prepare table code for reuse by bgp_tableAvneesh Sachdev
* lib/table.[ch] - Add a macro (ROUTE_NODE_FIELDS) that expands to all the fields of a route_node structure. - Add the route_table_delegate_t structure, a function vector which allows clients to customize the behavior of one or more tables. The delegate currently contains the 'create_node' and 'destroy_node' functions, and hence enables a table to use an alternative node structure. The alternative node is expected to embed the fields of a route_node using ROUTE_NODE_FIELDS. - Add route_table_init_with_delegate() to create a new table with a given delegate. - Make route_table_init() a thin wrapper around route_table_init_with_delegate(). The delegate it passes in simply creates/destroys route_node structures as before. - Add a user data pointer (info) to the route_table structure. This can be used by a client to keep per-table state. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2012-09-26lib: bring some changes over from bgp_table to tableAvneesh Sachdev
* lib/table.c - Maintain table node count. Expose it via the route_table_count() function (from revision cbdfbaa5). - route_unlock_node(): Add assertion (from revision 228da428). - route_table_free(): Make static and fix up cleanup code (from revision 228da428). - route_node_delete(): Change to be static. - Add 'const' qualifier in a couple places. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2009-12-08lib: make match functions take const argsStephen Hemminger
* table.c: general type safety and compiler help: * maskbit[]: become const * route_node_match(): take const args * route_node_match_ipv4(): idem * route_node_match_ipv6(): idem * check_bit(): idem, plus adjust local vars typing
2005-05-062005-05-06 Paul Jakma <paul@dishone.st>paul
* (general) extern and static'ification of functions in code and header. Cleanup any definitions with unspecified arguments. Add casts for callback assignments where the callback is defined, typically, as passing void *, but the function being assigned has some other pointer type defined as its argument, as gcc complains about casts from void * to X* via function arguments. Fix some old K&R style function argument definitions. Add noreturn gcc attribute to some functions, as appropriate. Add unused gcc attribute to some functions (eg ones meant to help while debugging) Add guard defines to headers which were missing them. * command.c: (install_node) add const qualifier, still doesnt shut up the warning though, because of the double pointer. (cmp_node) ditto * keychain.c: (key_str2time) Add GET_LONG_RANGE() macro, derived fromn vty.h ones to fix some of the (long) < 0 warnings. * thread.c: (various) use thread_empty (cpu_record_hash_key) should cast to uintptr_t, a stdint.h type * vty.h: Add VTY_GET_IPV4_ADDRESS and VTY_GET_IPV4_PREFIX so they removed from ospfd/ospf_vty.h * zebra.h: Move definition of ZEBRA_PORT to here, to remove dependence of lib on zebra/zserv.h
2002-12-13Initial revisionpaul