Add the ability to store link-state prefixes in the BGP table.
Store a raw copy of the BGP link state NLRI TLVs as received in the
packet in 'p.u.prefix_linkstate.ptr'.
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
Add to the library the link-state type of prefixes.
Link-state prefixes contain much more data than the current prefixes and
they only make sense for BGP Link-State. Storing all the data in "struct
prefix" is not relevant because it would increase the memory usage of
all daemons. Instead a pointer to a structure that contains all the
information is used. Printing link-state prefixes can be delegated to a
hook function.
Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
This is based on @donaldsharp's work
The current code base is the struct bgp_node data structure.
The problem with this is that it creates a bunch of
extra data per route_node.
The table structure generates ‘holder’ nodes
that are never going to receive bgp routes,
and now the memory of those nodes is allocated
as if they are a full bgp_node.
After splitting up the bgp_node into bgp_dest and route_node,
the memory of ‘holder’ node which does not have any bgp data
will be allocated as the route_node, not the bgp_node,
and the memory usage is reduced.
The memory usage of BGP node will be reduced from 200B to 96B.
The total memory usage optimization of this part is ~16.00%.
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
Signed-off-by: Yuqing Zhao <xiaopanghu99@163.com>
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>
- tracepoint() -> frrtrace()
- tracelog() -> frrtracelog()
- tracepoint_enabled() -> frrtrace_enabled()
Also removes copypasta'd #ifdefs for those LTTng macros, those are
handled in lib/trace.h
Signed-off-by: Quentin Young <qlyoung@nvidia.com>
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>
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>
Working with a proper struct route_node gets us around a bunch of weird
casts here and makes the code slightly more robust.
Signed-off-by: David Lamparter <equinox@diac24.net>
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>
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>
The ->hash_cmp and linked list ->cmp functions were sometimes
being used interchangeably and this really is not a good
thing. So let's modify the hash_cmp function pointer to return
a boolean and convert everything to use the new syntax.
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
prefix structure is used to handle flowspec prefixes. A new AFI is
introduced: AF_FLOWSPEC. A sub structure named flowspec_prefix is
used in prefix to host the flowspec entry.
Reason to introduce that new kind is that prefixlen from prefix
structure is too short to all the flowspec needs, since NLRI can go over
0xff bytes.
Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
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>
route_node_set is only called by route_node_get
which calls apply_mask. There is no need to do
this again.
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
Most read accesses of route_table are actually exact matches where
walking down the tree is wildly inefficient. Use a parallel hash
structure instead.
This significantly speeds up processes that are performance-bound by
table accesses, e.g. BGP withdraw processing. In other locations, the
improvement is not seen as strongly, e.g. when filter processing is the
limiting factor.
[includes fix to ignore prefix host bits in hash comparison]
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
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>
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>
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>
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]
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>
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>