Compare commits

...

578 Commits

Author SHA1 Message Date
256e198fee
add drone pipeline
Some checks reported errors
continuous-integration/drone/push Build is passing
continuous-integration/drone Build encountered an error
2021-12-30 13:19:02 +00:00
18853a82c6
Reset Extendend Length flag when encoding BGP attributes 2021-03-27 14:29:55 +00:00
e6133456c1
Bump version in build script 2021-03-22 09:09:19 +00:00
b86d3f9a2e
Revert "Add patch from JRB0001 to reload protocols on RPKI change"
This reverts commit 3155bb34bed49c909f00e5d3aadc9a74c2e6ef5c.
2021-03-22 09:05:39 +00:00
910f9127f0
Add additional error information on NETLINK failures 2021-03-22 09:03:24 +00:00
ce7a2736e9
add tag to build 2021-03-22 09:03:24 +00:00
397c52070a
Add build script 2021-03-22 09:03:24 +00:00
Simon Marsh
4aecc5f8cd
Add patch from JRB0001 to provide more verbose error logging on bad next hop. 2021-03-22 09:03:23 +00:00
Simon Marsh
3155bb34be
Add patch from JRB0001 to reload protocols on RPKI change 2021-03-22 09:03:23 +00:00
Ondrej Zajicek (work)
82f19ba95e NEWS and version update 2021-03-18 20:18:38 +01:00
Ondrej Zajicek (work)
f1ffe6a231 Add new BGP tests 2021-03-18 15:54:44 +01:00
Ondrej Zajicek (work)
5a6e8380f8 BGP: Do not show statistics
BGP statistics code was preliminary and i wanted to replace it by
separate 'show X stats' command. The patch hides the preliminary
output in 'show protocols all' so it is not part of the released
version.
2021-03-18 15:44:04 +01:00
Ondrej Zajicek (work)
454ae30445 RPKI: Improve error handling of DNS resolver 2021-03-17 17:24:00 +01:00
Ondrej Zajicek (work)
0a3db4c680 Minor fixes for restricted builds 2021-03-17 15:56:12 +01:00
Ondrej Zajicek (work)
2f98153490 Pipe: Propagate debug flags from protocol to channels
Pipe channels are kind-of implicit, so setting protocol debug flags
should also set pipe debug flags.
2021-03-16 20:10:00 +01:00
Ondrej Zajicek (work)
ae9ae864d3 OSPFv3: Update neighbor authentication state from Hello packets
In OSPFv3, only Hello and DBDes packets contain flags specifying whether
RFC 7166 authentication trailer is used. Other packets are processed
based on stored authentication state in neighbor structure. Update this
state with each received Hello to handle authentication change from
reconfigurations.

Thanks to Joakim Tjernlund and Kenth Eriksson for the bugreport.
2021-03-16 16:34:42 +01:00
Ondrej Zajicek (work)
94abefc00b Filter: Update 'gw' to handle IPv6 link-local addresses
When a link-local address is set, use the existing iface for scope.

Thanks to Marcel Krüger for the bugreport.
2021-03-15 18:37:18 +01:00
Ondrej Zajicek (work)
0d1a11cca3 Doc: Document automatic RPKI reload 2021-03-15 17:51:33 +01:00
Ondrej Zajicek (work)
6489a2450e Doc: Document channel debug options 2021-03-15 16:16:32 +01:00
Ondrej Zajicek (work)
7be3af7fa6 Rate-limit scheduling of work-events
In general, events are code handling some some condition, which is
scheduled when such condition happened and executed independently from
I/O loop. Work-events are a subgroup of events that are scheduled
repeatedly until some (often significant) work is done (e.g. feeding
routes to protocol). All scheduled events are executed during each
I/O loop iteration.

Separate work-events from regular events to a separate queue and
rate limit their execution to a fixed number per I/O loop iteration.
That should prevent excess latency when many work-events are
scheduled at one time (e.g. simultaneous reload of many BGP sessions).
2021-03-12 15:35:56 +01:00
Ondrej Zajicek (work)
9cf3d53311 Static: Implement reload hook 2021-03-10 15:07:19 +01:00
Ondrej Zajicek (work)
211fe69c98 Nest: No automatic ROA reload on non-reloadable channels 2021-03-09 18:37:52 +01:00
Ondrej Zajicek (work)
d3782c72b9 Nest: Add option to control automatic RPKI reload
Also, no automatic reload for BGP channels without import/export table.
2021-02-12 05:05:18 +01:00
Ondrej Zajicek (work)
77ce849ecf Tests: Add missing mockup function to tests 2021-02-10 17:29:14 +01:00
Vincent Bernat
714238716e BGP: Add support for BGP hostname capability
This is an implementation of draft-walton-bgp-hostname-capability-02.
It is implemented since quite some time for FRR and in datacenter, this
gives a nice output to avoid using IP addresses.

It is disabled by default. The hostname is retrieved from uname(2) and
can be overriden with "hostname" option. The domain name is never set
nor displayed.

Minor changes by committer.
2021-02-10 16:53:57 +01:00
Ondrej Zajicek (work)
00b85905b9 Nest: Automatic channel reloads based on RPKI changes
If there are roa_check() calls in channel filters, then the channel
subscribes to ROA table notifications, which are sent when ROA tables
are updated (subject to settle time) and trigger channel reload or
refeed.
2021-02-10 03:09:57 +01:00
Ondrej Zajicek (work)
d06a875b04 Filter: Recursive filter iteration code
Add macros for recursive filter iteration that allows to examine
all instructions reachable from a filter.
2021-02-07 19:21:42 +01:00
Ondrej Zajicek (work)
5d414309ec MRT: Fix MP-BGP next hops
Flag signalling that MP-BGP mode should be used got reset after first
batch of routes, so remaining routes were processed without that, leading
to missing MP_REACH_NLRI attribute.

Thanks to Piotr Wydrych for the bugreport.
2021-01-22 04:34:15 +01:00
Ondrej Zajicek (work)
df83f62697 Netlink: Ignore dead routes
With net.ipv4.conf.XXX.ignore_routes_with_linkdown sysctl, a user can
ensure the kernel does not use a route whose target interface is down.
Such route is marked with a 'dead' / RTNH_F_DEAD flag.

Ignore these routes or multipath nexthops during scan.

Thanks to Vincent Bernat for the original patch.
2021-01-14 02:01:07 +01:00
Ondrej Zajicek (work)
a40ddf5c61 Build: Fix tags generation 2021-01-12 15:43:54 +01:00
Ondrej Zajicek (work)
d774f6d721 MRT: Fix IPv6 table dumps
Add fake MP_REACH_NLRI attribute with BGP next hop when encoding MRT
table dumps for IPv6 routes. That is necessary to encode next hop as
NEXT_HOP attribute is not used for MP-BGP.

Thanks to Santiago Aggio for the bugreport.
2021-01-12 15:37:01 +01:00
Ondrej Zajicek (work)
910adaa08b BFD: Dispatch sessions also by interface index
Direct BFD sessions needs to be dispatched not only by IP addresses, but
also by interfaces, in order to avoid collisions between neighbors with
the same IPv6 link-local addresses.

Extend BFD session hash_ip key by interface index to handle that. Use 0
for multihop sessions.

Thanks to Sebastian Hahn for the original patch.
2021-01-10 15:29:02 +01:00
Ondrej Zajicek (work)
17663b6a7c RPKI: Remove port (and SSH username) from 'Cache server' output line
It was mixed-up if hostname is IPv6 address, and reporting separate
values (like port) on separate lines fits better into key-value style
of 'show protocols all' output. Also, the patch simplifies transport
identification formatting (although it is unused now).

Thanks to Alarig Le Lay for the suggestion.
2021-01-07 06:04:31 +01:00
Ondrej Zajicek (work)
2a8cc7259e Kernel: Do not check templates
So one can define kernel protocol template without channels.
For other protocols, it is either irrelevant or already done.

Thanks to Clemens Schrimpe for the bugreport.
2021-01-07 01:56:00 +01:00
Ondrej Zajicek (work)
a141959f07 Doc: Describe per-nexthop static route options
Also remove description of (no longer supported) per-route 'bfd' option,
and add examples of IPv6 routes with link-local nexthops.
2021-01-07 01:20:56 +01:00
Ondrej Zajicek (work)
7a1f4baac1 Nest: remove last_tx_filter_change
No longer needed after redesign of export handling.
2021-01-06 14:51:49 +01:00
Ondrej Zajicek (work)
4155104c90 BGP: Deprecate 'missing lladdr' option
The option is not implemented since transition to 2.0 and no plan to add it.
Also remove some deprecated RTS_* valus from documentation.

Thanks to Sébastien Parisot for notification.
2021-01-06 14:44:23 +01:00
Ondrej Zajicek (work)
21f9acd2a0 Kernel: Fix handling of krt_realm with ECMP routes
For ECMP routes, RTA_FLOW attribute must be set per-nexthop, not
per-route. Our corresponding krt_realm attribute is per-route.

Thanks to Mikhail Petrov for the bugreport.
2021-01-06 05:25:59 +01:00
James Lu
455c13dc99 Nest: Read Babel metric as IGP metric
(Minor syntactic changes by committer)
2020-12-29 02:25:21 +01:00
Ondrej Zajicek (work)
ea3c6c1a15 Static: Fix handling of 'net' attribute in per-route filters
We need to define 'net' field temporarily as it may be accessed by
per-route filters.

Thanks to Damian Zaremba for the bugreport.
2020-12-28 21:19:27 +01:00
Ondrej Zajicek (work)
9e2635505a Filter: Fix return on top-level
Broken detection of top-level case caused crash when return was called
from top-of-stack position. It should behave as reject/accept.

Thanks to Damian Zaremba for the bugreport.
2020-12-28 15:23:28 +01:00
Ondrej Zajicek (work)
61dae32b29 Nest: Per-channel debug flags
The patch add support for per-channel debug flags, currently just
'states', 'routes', and 'filters'. Flag 'states' is used for channel
state changes, remaining two for routes passed through the channel.
The per-protocol debug flags 'routes'/'filters' still enable reporting
of routes for all channels, to keep existing behavior.

The patch causes minor changes in some log messages.
2020-12-07 22:19:40 +01:00
Ondrej Zajicek (work)
8cc5bb09e3 Filter: Add 'weight' route attribute
Add 'weight' route attribute that allows to get and set ECMP weight of
nexthops. Similar to 'gw' attribute, it is limited to the first nexthop,
but it is useful for handling BGP multipath, where an ECMP route is
merged from multiple regular routes.
2020-12-02 05:02:26 +01:00
Ondrej Zajicek (work)
2465867712 BGP: Zero the newly allocated bucket structure
This fixes an issue with dirty node passed to add_tail().

Thanks to Andreas Rammhold for the initial patch.
2020-11-25 15:48:22 +01:00
Ondrej Zajicek (work)
62d57b9bdf Log: Fix locking during log reconfiguration
The log subsystem should be locked earlier, as default_log_list() may
internally manipulate with the current_log_list (if it is also a default
log list).
2020-11-25 15:15:13 +01:00
Ondrej Zajicek (work)
0ef082c51e Log: Reinitialize the static logging structures
The static logging structures are reused, we need to reinitialize them
otherwise add_tail() would fail in debug build. Reinitializing these
structures should be fine as the list they belong to is being
reinitialized on entry to the very same function.

Thanks to Andreas Rammhold and Mikael Magnusson for patches.
2020-11-25 15:04:34 +01:00
Ondrej Zajicek (work)
30b8468269 Minor cleanups with cfg_allocz()
Also fixes some more failed asserts due to add_tail().
2020-11-24 04:09:11 +01:00
Ondrej Zajicek (work)
1678bc0746 Fix some failed asserts due to add_tail()
When config structures are copied due to template application,
we need to reset list node structure before calling add_tail().

Thanks to Mikael Magnusson for patches.
2020-11-24 03:42:23 +01:00
Ondrej Zajicek (work)
c9ae81656f Some minor sl_allocz() cleanups 2020-11-24 03:21:44 +01:00
Toke Høiland-Jørgensen
db2d29073a lib/slab: introduce sl_allocz() function and use it in Babel
The babel protocol code was initialising objects returned from the slab
allocator by assigning to each of the struct members individually, but
wasn't touching the NODE member while doing so. This leads to warnings on
debug builds since commit:

baac7009063d ("List expensive check.")

To fix this, introduce an sl_allocz() variant of the slab allocator which
will zero out the memory before returning it, and switch all the babel call
sites to use this version. The overhead for doing this should be negligible
for small objects, and in the case of babel, the largest object being
allocated was being zeroed anyway, so we can drop the memset in
babel_read_tlv().
2020-11-24 02:36:31 +01:00
Ondrej Zajicek (work)
3347aaafec Static: Support for multiple routes with the same network
Add support for proper handling of multiple routes with the same network
to the static protocol. Routes are distinguished by internal index, which
is assigned automatically (sequentially for routes within each network).
Having different route preference or igp_metric attribute is optional.
2020-11-19 16:38:39 +01:00
Nigel Kukard
df65d519d6 Doc: Added example of static routes with BGP large communities 2020-11-18 18:00:12 +01:00
Ondrej Zajicek (work)
00ddd18b02 OSPFv3: Fix intra-area-prefix-LSA origination on DR
When a new link-LSA is originated, we need to notify intra-area-prefix-LSA
handling, like when a new link-LSA is received. Otherwise a new network
prefix added to a DR is not propagated immediately.

Thanks to Bala Sajja for the bugreport.
2020-11-18 17:37:29 +01:00
Ondrej Zajicek (work)
6ea8a46ccb Doc: Fix typo
Thanks to Hexhu for the bugreport.
2020-11-15 16:28:13 +01:00
Ondrej Zajicek (work)
b962967e20 Nest: Fix crash in receive limit handling in import table
Logging as a result of triggered receive limit in import table code
accesset rte->net, which was not filed yet.

Thanks to Pier Carlo Chiodi for the bugreport.
2020-11-15 16:01:19 +01:00
Ondrej Zajicek (work)
4a42e7e925 BFD: Update documentation about per-session options 2020-11-12 04:50:45 +01:00
Ondrej Zajicek (work)
3b56bf8849 BFD: Better handling of BFD options in BGP configs
Merge multiple BFD option blocks in BGP configs instead of using the last
one. That is necessary for proper handling of templates when BFD options
are used both in a BGP template and in a BGP protocol derived from that
template.
2020-11-12 04:02:38 +01:00
Ondrej Zajicek (work)
99ad208dd7 BFD: Fix superfluous reconfiguration of sessions 2020-11-12 02:48:35 +01:00
Ondrej Zajicek (work)
9d3fc3062b BFD: Allow per-request session options
BFD session options are configured per interface in BFD protocol. This
patch allows to specify them also per-request in protocols requesting
sessions (currently limited to BGP).
2020-11-08 15:33:22 +01:00
Ondrej Zajicek (work)
fc1e3211b1 RPKI: Add 'ignore max length' option
Add 'ignore max length' option to RPKI protocol, which ignores received
max length in ROA records and instead uses max value (32 or 128). This
may be useful for implementing loose RPKI check for blackholes.
2020-10-11 01:00:54 +02:00
Ondrej Zajicek (work)
6c11dbcf28 Doc: Fix missing semicolons
Thanks to Marco Gartmann for the bugreport.
2020-10-05 14:52:55 +02:00
Ondrej Zajicek (work)
14ce8904e7 Doc: Fix typo
Thanks to Sergey Kulikov for the bugreport.
2020-10-05 14:45:01 +02:00
Maria Matejka
600eb695b1 OSPF: Fixed a debug assert 2020-08-31 15:41:39 +02:00
Ondrej Zajicek (work)
dc8d9dec4a OSPF: Skip out-of-state packets earlier
Sometimes multicast OSPF packet is received when neighbor adjacency is
not established. Such packet should be ignored earlier in packet
processing as otherwise it causes strange error messages when OSPFv3
authentication is enabled.
2020-08-12 19:42:44 +02:00
Ondrej Zajicek (work)
c0e1f534c9 Nest: Keep route ordering during route updates
Put new non-best routes to the end of list instead of the second
position. Put updated routes to their old position. Position is changed
just by best route selection.
2020-07-16 15:02:10 +02:00
Ondrej Zajicek (work)
c26c6bc2d7 Show info from multiple protocols when protocol is not specified
Most commands like 'show ospf neighbors' fail when protocol is not
specified and there are multiple instances of given protocol type.
This is annoying in BIRD 2, as many protocols have IPv4 and IPv6
instances. The patch changes that by showing output from all protocol
instances of appropriate type.

Note that the patch also removes terminating cli_msg() call from these
commands and moves it to the common iterating code.
2020-06-28 15:38:47 +02:00
Kazuki Yamaguchi
a948cf9a5c Filter: Improve handling of sets in BGP path masks
Compare the content of PM_ASN_SET in path masks. A reconfiguration
was not properly triggering a reload of affected protocols when the
members of a set in a path mask change.

Also, update the printing code to so that it can display sets in a path
mask.
2020-06-28 15:37:01 +02:00
Kazuki Yamaguchi
4ef0a96639 Filter: Fix comparison of BGP path mask
Add a missing return statement. Path masks with the same length were all
considered the same. Comparing two with different length would cause
out-of-bounds memory access.
2020-06-28 15:33:26 +02:00
Ondrej Zajicek (work)
82937b465b OSPF: Fix bad header length test
Thanks to Slava Aseev for the thorough bugreport.
2020-06-10 13:27:14 +02:00
Kenth Eriksson
71e08edd94 Doc: Add 'ptp address' to OSPF doc overview 2020-06-03 23:05:29 +02:00
Ondrej Zajicek (work)
63451c1961 Test: Fix unit test mockups 2020-06-03 16:15:29 +02:00
Kazuki Yamaguchi
f1b5f179db Netlink: Fix parsing of MPLS multipath routes
Add support for RTA_MULTIPATH attribute parsing for AF_MPLS routes.

BIRD is capable of installing a multipath route into kernel on Linux,
but it would not be seen because parsing fails. This made BIRD attempt
to install the same route repeatedly.

(The patch minorly updated by committer)
2020-06-03 15:18:02 +02:00
Kazuki Yamaguchi
19f8f17320 RPKI: Fix unnecessary reconnection on reconfiguration
Compare the new timing parameters with the old configuration, not with
the temporary state of the current connection.

The timing values in struct rpki_cache is updated by a version 1 End Of
Data PDU, unless this behavior is suppressed by the configuration
explicitly by the "keep" keyword. Consequently, every reconfiguration
of BIRD triggers a reconnection even if it is not necessary.
2020-06-03 15:05:35 +02:00
Ondrej Zajicek (work)
fae5448134 Log: Do not open logfiles when parse-and-exit option is active
This is a quick workaround for an issue where configured logfiles are
opened/created during parsing of a config file even when parse-and-exit
option is active. We should later refactor the logging code to avoid
opening log during parsing altogether.
2020-06-03 14:59:20 +02:00
Maria Matejka
eee8af4db2 OSPF: setting list node to zero before enlisting 2020-06-02 16:58:06 +02:00
Ondrej Zajicek (work)
4e8f8afc68 Babel: Set onlink flag for IPv4 routes with unreachable next hop
If the next hop of a route is not a reachable address, the route should be
installed as onlink. This enables a configuration common in mesh networks
where the mesh interface is assigned a /32 and babel handles the routing by
installing onlink routes.

Thanks to Toke Hoiland-Jorgensen for the patch.
2020-05-26 23:43:13 +02:00
Ondrej Zajicek (work)
c1632ad0f3 OSPF: Fix handling of unnumbered PtPs
This issue has a long history. In 2012, we changed data field for
unnumbered PtP links from iface id (specified by RFC) to IP address based
on reports of bugs in Quagga that required it, and we used out-of-band
information to distinquish unnumberred PtPs with the same local IP
address.

Then with OSPF graceful restart implementation, we found that we can no
longer use out-of-band information, and we need to use only LSAdb info
for routing table calculation, but i forgot to finish handling of this
case, so multiple unnumbered PtPs with the same local IP addresses were
broken.

Considering that even recent Mikrotik RouterOS has broken next hop
calculation that depends on IP address in PtP link data field, we
cannot just switch back to the iface id for unnumbered PtP links.

The patch makes two changes: First, it goes back to use out-of-band
(position) info for distinguishing local interfaces in SPF when graceful
restart is not enabled, while still uses LSAdb-only approach for SPF
calculation when graceful restart is enabled.

Second, it adds OSPF interface option 'ptp address', which controls
whether IP address or iface id is used in data field. It is enabled
by default except for unnumbered PtP links with enabled graceful
restart.

Thanks to Kenth Eriksson for the bugreport and Joakim Tjernlund for
suggestions.
2020-05-26 18:21:43 +02:00
Ondrej Zajicek (work)
1ca7665fa4 Nest: Allow key id 0
There is nothing in RFCs specifying that id 0 is not allowed. Some
implementations does not support it, while some other use key id 0 by
default. We allow it but start with key id 1 by default.

Thanks to Kenth Eriksson for the bugreport.
2020-05-19 02:50:47 +02:00
Ondrej Zajicek (work)
b729e731f9 RIP: Triggered RIP (demand circuit) documentation 2020-05-19 02:42:22 +02:00
Ondrej Zajicek (work)
ec430a7fee Nest: Implement BGP path mask loop operator
Implement regex-like '+' operator in BGP path masks to match previous
path mask item multiple times. This is useful as ASNs may appear
multiple times in paths due to path prepending for traffic engineering
purposes.
2020-05-18 16:25:08 +02:00
Ondrej Zajicek (work)
5fc8407177 RIP: Fix handling of passive mode for demand circuit interfaces 2020-05-12 03:46:47 +02:00
Ondrej Zajicek (work)
b8bbbbaf56 Nest: Fix neighbor handling for colliding ranges
Resolve neighbors using longest prefix match. Although interface ranges
should not generally collide, it may happen for unnumbered links.

Thanks to Kenth Eriksson for the bugreport.
2020-05-11 04:29:36 +02:00
Ondrej Zajicek (work)
f7c34aa227 Tests: Activate BGP-int test 2020-05-05 02:20:30 +02:00
Matous Holinka
e6785c469b Tests: Change unsupported Ubuntu 19.04 for supported version 19.10 2020-05-05 02:16:28 +02:00
Ondrej Zajicek (work)
82bfee76f0 Filter: Remove quitbird command
No need for this debug filter command and it can be abused from CLI.
2020-05-02 02:47:18 +02:00
Maria Matejka
b12442c985 Fixed a harmless warning in production build 2020-05-01 15:41:42 +02:00
Maria Matejka
048eb2ddf1 Merge remote-tracking branch 'origin/mq-static-analysis' 2020-05-01 15:34:17 +02:00
Maria Matejka
59238768b3 Slab: Init node in slab head to NULLs. 2020-05-01 15:19:12 +02:00
Maria Matejka
ea259d6201 Timer: Adding missing initializer. 2020-05-01 15:19:12 +02:00
Maria Matejka
0c3b8ffe25 Lexer: strtoul shall never set endptr to NULL; it should be an error 2020-05-01 15:19:12 +02:00
Maria Matejka
cdde3550dc Unix socket: Path length check directly before copying the path.
This is not needed as the string is always short enough, anyway
it may be needed in future and one strlen during BIRD start is
cheap enough.
2020-05-01 15:19:12 +02:00
Maria Matejka
9ac13d7af2 Lists: Replaced replace_node() by update_node() which is the only use of that function. 2020-05-01 15:19:12 +02:00
Maria Matejka
e26a5195dd Lists: fix a stupid sanitizer bug 2020-05-01 15:19:12 +02:00
Maria Matejka
3bb10b4d31 Uninitialized list nodes fixes 2020-05-01 15:19:12 +02:00
Maria Matejka
258be56539 Nest: Added const to ea_show just to declare that this shouldn't really change anything 2020-05-01 15:19:12 +02:00
Maria Matejka
a7d9b8f116 OSPF: Zero-initialization of a temporary neighbor 2020-05-01 15:19:12 +02:00
Maria Matejka
0fa8bf91cd Nest: Several assumptions to tame the static analyzer 2020-05-01 15:19:12 +02:00
Maria Matejka
bbe49ae569 Nest: Assumption in rt-show for not-so-intuitive invariant. 2020-05-01 15:19:12 +02:00
Maria Matejka
a08853a269 Static scanner and expensive debugging setup fix 2020-05-01 15:19:12 +02:00
Maria Matejka
5f60d14ede RPKI: fixed rare va_list leak 2020-05-01 15:19:12 +02:00
Maria Matejka
b748220906 Static check: Don't report dead code 2020-05-01 15:19:12 +02:00
Maria Matejka
9e64ac4b7c OSPF: Adding a note about a static analyzer result. 2020-05-01 15:19:12 +02:00
Maria Matejka
dccee40826 OSPF: variable-length array of size 0 replaced by alloca()'d pointer
NULL pointer is safer than a random pointer onto stack if this function
gets changed and eventually broken.
2020-05-01 15:19:12 +02:00
Maria Matejka
baac700906 List expensive check. 2020-05-01 15:19:12 +02:00
Maria Matejka
a0d0a71a18 Expensive check declaration
Intended to be run at every operation with complex data structures
to check their consistency and validity.
2020-05-01 15:19:12 +02:00
Maria Matejka
a1b61a271a IPv6 address parser: fail on incomplete addresses 2020-05-01 15:19:12 +02:00
Maria Matejka
d65a926a67 Filter: Don't alloc varargs array if its length would be zero 2020-05-01 15:19:12 +02:00
Maria Matejka
30ba7c1661 Filter: Removed forgotten dead code 2020-05-01 15:19:12 +02:00
Maria Matejka
bf9486bf20 Non-null function argument declaration 2020-05-01 15:18:48 +02:00
Ondrej Zajicek (work)
17de3a023f BGP: Fix handling of strange IPv6 link-local-only next hops
There are three common ways how to encode IPv6 link-local-only next hops:
(:: ll), (ll), and (ll ll). We use the first one but we should accept all
three. The patch fixes handling of the last one.

Thanks to Sebastian Hahn for the bugreport.
2020-04-29 02:50:29 +02:00
Maria Matejka
8029ae527e More assertion categories 2020-04-28 16:21:06 +02:00
Maria Matejka
d607205486 Not calling memcpy with n=0. 2020-04-28 16:21:06 +02:00
Maria Matejka
124d860f64 Filter: fixed omitted overflow check in EC constructor 2020-04-28 16:21:06 +02:00
Maria Matejka
59a86cbc7c Makefile rule for static analyzer 2020-04-28 16:21:06 +02:00
Ondrej Zajicek (work)
b465604eb1 Tests: Activate BGP-auth test 2020-04-28 15:26:26 +02:00
Ondrej Zajicek (work)
716e11a584 Tests: Activate OSPF-VRF test 2020-04-28 03:52:47 +02:00
Ondrej Zajicek (work)
3c838ad9fd Tests: Activate BGP test 2020-04-22 17:14:02 +02:00
Nasato Goto
a6548d5b5b BGP: Fix handling of 16bit-only ASN translation
The bug generated invalid AGGREGATOR attribute during translation of
32bit ASN to 16bit-only BGP peer. The patch fixes that.
2020-04-15 03:46:53 +02:00
Maria Matejka
fd9f0c0640 Configuration strings are constant.
This is merely a const propagation. There was no problem in there.
2020-04-09 15:37:14 +02:00
Ondrej Zajicek (work)
a109056145 Doc: Update prefix set comment 2020-04-08 13:11:51 +02:00
Maria Matejka
2928c5bcc7 Fletcher16 test fixed to work at bigendian architectures.
To be honest, it was wrong in concept, anyway it accidentally worked.
2020-04-05 01:15:26 +02:00
Ondrej Zajicek (work)
c9d11e6230 Filter: Remove mixed address tests and fix formatting 2020-03-26 04:59:15 +01:00
Ondrej Zajicek (work)
2755002890 Filter: Optimize IPv4 prefix sets
Use separate IPv4 and IPv6 implementation of prefix sets. Just this
change makes IPv4 prefix sets 60% smaller and 50% faster.
2020-03-26 03:57:48 +01:00
Ondrej Zajicek (work)
d516c68ad8 RIP: Improvements to demand circuit mode
Restart iface after changing demand circuit mode during reconfiguration.
Fix next_regular interval reset during reconfiguration. Send flushing
response when iface goes down.
2020-03-14 17:04:49 +01:00
Maria Matejka
dc042d87cb Perf: changed route update pattern to be more like common protocols 2020-03-12 09:26:05 +01:00
Ondrej Zajicek (work)
e2630a494e Netlink: Handle interfaces with missing broadcast addresses 2020-03-07 05:11:21 +01:00
Ondrej Zajicek (work)
1ad98965c5 Tests: Enforce cleanup before running a test 2020-03-05 22:01:30 +01:00
Ondrej Zajicek (work)
ead531ffef Tests: Activate OSPF tests 2020-03-05 17:39:52 +01:00
Ondrej Zajicek (work)
e6746da6de Flowspec: Fix tests
Missing dst no longer generates error.
2020-03-03 19:04:33 +01:00
Ondrej Zajicek (work)
78e4a123bb BGP: Handle flowspec rules without dst part
The RFC 5575 does not explicitly reject flowspec rules without dst part,
it just requires dst part in validation procedure for feasibility, which
we do not implement anyway. Thus flow without dst prefix is syntactically
valid, but unfeasible (if feasibilty testing is done).

Thanks to Alex D. for the bugreport.
2020-03-03 17:45:16 +01:00
Ondrej Zajicek (work)
757cab18d6 BGP: Support for MD5SIG together with remote range
When dynamic BGP with remote range is configured, MD5SIG needs to use
newer socket option (TCP_MD5SIG_EXT) to specify remote addres range for
listening socket.

Thanks to Adam Kułagowski for the suggestion.
2020-02-27 17:29:17 +01:00
Ondrej Zajicek (work)
22c3cf955d RIP: Demand circuit support (RFC 2091) 2020-02-21 02:35:50 +01:00
Ondrej Zajicek (work)
3343088a71 RIP: Fix crash when interface is removed
Recent changes in neighbor code caused RIP to access neighbor field which
is NULL during interface/neighbor removal and caused crash when debug
messages are enabled. Use correct field to get iface from neighbor.
2020-02-14 22:43:27 +01:00
Maria Matejka
ab089f4fb5 Conf: Better error message when reading iproute2 config
Reported by: Martin Weinelt <martin@darmstadt.freifunk.net>
2020-02-04 10:34:46 +01:00
Maria Matejka
027a3e66f7 RPKI: Allow build without libSSH 2020-02-04 10:15:35 +01:00
Maria Matejka
4bbc10614f Added missing extern
Thanks to Robert Scheck <bird@robert-scheck.de> who reported it
and Toke Høiland-Jørgensen <toke@toke.dk> who suggested this patch.
2020-02-04 10:11:16 +01:00
Ondrej Zajicek (work)
7f9adafc10 BFD: Option to specify which class of BFD sessions are accepted
Allows to configure IPv4/IPv6-only or direct/multihop-only BFD protocol
instances.
2020-01-28 18:07:25 +01:00
Ondrej Zajicek (work)
9f2670277c OSPF: Fix bad initialization of tx_hdrlen field
Function ifa_tx_hdrlen() uses fields autype and passwords, so it must be
called after these are set.

Thanks to Kenth Eriksson for the bugreport.
2020-01-09 03:02:15 +01:00
Ondrej Zajicek (work)
7d767c5a3d KRT: Improve syncer code to avoid using temporary data in rtable
The old code stored route verdicts and temporary routes directly in
rtable. The new code do not store received routes (it immediately
compares them with exported routes and resolves conflicts) and uses
internal bitmap to keep track of which routes were received and which
needs to be reinstalled.

By not putting 'invalid' temporary routes to rtable, we keep rtable
in consistent state, therefore scan no longer needs to be atomic
operation and could be splitted to multiple events.
2020-01-07 18:35:03 +01:00
Ondrej Zajicek (work)
ef8c45749c Filter: Fix typecheck for AND/OR.
Do not apply dynamic type check for second argument of AND/OR, as it is
not evaluated immediately like regular argument would be.

Thanks to Mikael for the bugreport.
2020-01-07 01:24:30 +01:00
Ondrej Zajicek (work)
cc75b3e1dc KRT: Remove KRF_SYNC_ERROR flag
This info is now stored in an internal bmap. Unfortunately, net.flags
is still needed for temporary kernel data.
2019-12-19 16:34:35 +01:00
Ondrej Zajicek (work)
90a9c97e38 KRT: Fix removal of KRF_INSTALLED
Use route id from net->routes to check export_map. Route received from
sysdep KRT code does not have proper id.
2019-12-17 16:30:29 +01:00
Ondrej Zajicek (work)
3dabf7b8d0 Test: Improve filter_test
Initial parsing of test.conf must be done directly in filter_test main,
while reconfiguration is handled as a regular test. Also fix several
minor issues in test code.
2019-12-17 00:01:53 +01:00
Ondrej Zajicek (work)
3232d17186 Doc: Fix documentation of BGP gateway option
Thanks to Nico Schottelius for the bugreport.
2019-12-16 18:08:40 +01:00
Ondrej Zajicek (work)
c132acae36 KRT: Remove KRF_INSTALLED flag
The same information is stored in export_map of kernel protocol.
2019-12-16 02:42:24 +01:00
Maria Matejka
d3aa4f2aed Filter: fix filter comparison test 2019-12-12 15:42:46 +01:00
Ondrej Zajicek (work)
dfb3eb7716 Filter: Fix function comparison
Check the SYM_FLAG_SAME in new symbols. The old code checked that
in old symbols (f2).
2019-12-10 18:53:16 +01:00
Ondrej Zajicek (work)
4ab54f1aef Nest: Fix bitmap cleanup
Channel currently does not have independent pool and uses protocol pool,
which is freed when protocol changes state to down, while channel is
still in flushing. Move some some cleanup code to channel_do_flush()
so it is done before freeing of protocol pool.
2019-12-10 18:18:02 +01:00
Ondrej Zajicek (work)
ff2ca10cba Filter: Add support for src/dst accessors for Flowspec and SADR 2019-12-09 04:23:01 +01:00
Ondrej Zajicek (work)
21d09632a5 BGP: Add some statistics
Add some statistic counters to BGP consistent with BGP MIB (RFC 4273),
including persistent 'FSM established transitions'.
2019-12-03 18:05:41 +01:00
Matous Holinka
92249894b3 CI: Add more build tests
Add more Docker images with distributions (CentOS 8, Debian 10,
Fedora 27-31, OpenSUSE 15.0 & 15.1, and Ubuntu 18.04 & 19.04).
Fix some issues with older ones.
2019-11-26 19:43:56 +01:00
Ondrej Zajicek (work)
0adfa0ec07 CI: Cleanup of job templates
Env templates were used for separate IPv4/IPv6 build, that is no longer
needed.
2019-11-26 19:43:56 +01:00
Ondrej Zajicek (work)
6a314d26cb CI: Update new netlab location 2019-11-26 19:43:56 +01:00
Ondrej Zajicek (work)
148bd9ee92 CI: Minor update 2019-11-26 19:43:56 +01:00
Ondrej Zajicek (work)
faa43a755e Apply relevant changes from branch mh-test-gitlab 2019-11-26 19:43:56 +01:00
Ondrej Zajicek (work)
5176455f1a Gitlab test 2019-11-26 19:43:56 +01:00
Ondrej Zajicek (work)
5ea39eaa96 Nest: Use bitmaps to keep track of exported routes
Use a hierarchical bitmap in a routing table to assign ids to routes, and
then use bitmaps (indexed by route id) in channels to keep track whether
routes were exported. This avoids unreliable and inefficient re-evaluation
of filters for old routes in order to determine whether they were exported.
2019-11-26 18:39:25 +01:00
Ondrej Zajicek (work)
af02b83b88 Lib: Basic and hierarchical bitmaps
Basic bitmap is obvious. Hierarchical bitmap is structure of several
bitmaps, where higher levels are conjunctions of intervals on level
below, allowing for efficient lookup of first unset bit.
2019-11-26 18:39:02 +01:00
Ondrej Zajicek (work)
d033e6327d CLI: Fix continuation lines after final one
Continuation lines may use short form (with space instead of message
number), but this should not be done when previous line is final.

Thanks to Kenth Eriksson for the bugreport and analysis.
2019-11-26 16:43:09 +01:00
Ondrej Zajicek (work)
0f88200247 BGP: Fix processing of IPv6 Flowspec
During NLRI parsing of IPv6 Flowspec, dst prefix was not properly
extracted from NLRI, therefore a received flow was stored in a different
position in flowspec routing table, and was not reachable by command
'show route <flow>'.

Add proper prefix part accessors to flowspec code and use them from BGP
NLRI parsing code.

Thanks to Alex D. for the bugreport.
2019-11-18 17:56:51 +01:00
Ondrej Zajicek
53401bef63 Netlink: Handle IPv4 routes with IPv6 nexthops
Accept RTA_VIA attribute in all cases. The old code always used
RTA_GATEWAY for IPv4 / IPv6 and RTA_VIA for MPLS. The new code uses
RTA_VIA in cases where AF of network and AF of nexthop differs.
2019-11-12 18:13:21 +01:00
Ondrej Zajicek (work)
0b228fca04 BGP: Add option to enforce first AS in AS_PATH
This is optional check described in RFC 4271. Although this can be also
done by filters, it is widely implemented option in BGP implementations.

Thanks to Eugene Bogomazov for the original patch.
2019-11-10 02:06:07 +01:00
Ondrej Zajicek (work)
becda5638a Doc: Minor fix 2019-11-05 16:29:47 +01:00
Ondrej Zajicek (work)
d54a69ac7f Doc: Add documentation for BGP option 'allow as sets' 2019-11-05 16:00:25 +01:00
Ondrej Zajicek (work)
10c4cd9677 Filter: Add type info for more instructions 2019-11-05 15:30:20 +01:00
Ondrej Zajicek (work)
87512e9751 Filter: Improve typecheck error messages 2019-11-05 15:30:16 +01:00
Ondrej Zajicek (work)
c00c20a799 Filter: Better constant promotion
We use constant promotion from IPv4 to Router-ID values, as they have
same literals. Instead of ad-hoc code in filter instructions, add
constant promotion code to parse-time typecheck code.
2019-11-05 15:28:47 +01:00
Ondrej Zajicek (work)
26194bd684 Filter: Improved parse-time typechecks 2019-11-05 15:28:47 +01:00
Ondrej Zajicek
6fbcd8914a Filter: Parse-time typechecks
Most expressions can be type-validated in parse time. It is not
strong enough to eliminate runtime checks, but at least one gets
errors immediately during reconfigure.
2019-11-05 15:28:47 +01:00
Ondrej Zajicek (work)
a52476c9be BGP: Add option to reject AS_SETs
There is a pending draft to make them obsolete
2019-11-04 22:09:35 +01:00
Ondrej Zajicek (work)
0edf0c8cd9 Support for address family constants
We already had them defined on BGP level, but they are more general.
2019-11-03 22:25:44 +01:00
Ondrej Zajicek (work)
08c4c9a30b Nest: Fix bug in export table
For regular channels do not compare src in export table, as we want to
keep here only the best (exported) route per network.
2019-11-03 20:25:42 +01:00
Ondrej Zajicek (work)
be7c1aef42 BGP: RFC 8654 got released 2019-10-26 01:32:24 +02:00
Ondrej Zajicek (work)
498d8145c0 Nest: Fix primary flag in show route
The route is changed by rte_make_tmp_attrs(), so we need to compare
net->routes to the original one.

Thanks to Kenth Eriksson for the bugreport.
2019-10-25 13:28:51 +02:00
Ondrej Zajicek (work)
ec331acf48 BGP: Fix handling of transitive extended communities
Transitive extended communities should be removed on external sessions,
the old code them in all cases.

Thanks to Jean-Daniel Pauget for the original patch.
2019-10-24 17:50:19 +02:00
Ondrej Zajicek
5ce881be82 Accept uppercase letters in iproute2 names
Names read from texfiles in /etc/iproute2/* are normalized by replacing
non-alphanumeric chars with underscore. The patch fixes handling of
uppercase letters, which were handled as non-alphanumberic.

Thanks to Igor Gavrilov for the bugreport.
2019-10-22 16:25:38 +02:00
Fabrice Fontaine
f9eb9b4cab Nest: Fix build without protocols
(CHECK keyword added by commiter)
2019-10-19 12:50:27 +02:00
Ondrej Zajicek (work)
4e23b49969 RPKI: Fix handling of IPv6 cache addresses
The old code used just sizeof(struct sockaddr) bytes of IP address.
2019-10-19 03:39:07 +02:00
Ondrej Zajicek (work)
b000a94275 NEWS and version update 2019-10-11 00:18:38 +02:00
Ondrej Zajicek (work)
6c9cda6f92 BGP: Fix reconfiguration with import table
Change of some options requires route refresh, but when import table is
active, channel reload is done from it instead of doing full route
refresh. So in this case we request it internally.
2019-10-10 23:33:40 +02:00
Ondrej Zajicek (work)
eeb2c61653 Doc: Minor documentation fixes
Thanks to Christoph for the bugreport.
2019-10-10 22:43:41 +02:00
Ondrej Zajicek (work)
843b10c8b0 Nest: Handle non-MPLS on MPLS case in recursive route update
When non-MPLS recursive route resolves to MPLS underlying route,
then it should get MPLS labels from the the underlying route.
2019-10-10 15:25:36 +02:00
Ondrej Zajicek (work)
9eace84342 Nest: Handle PtP links in recursive route update
Underlying (IGP) route may lead to PtP link, in this case it does not
need gateway. Which is different than direct route without gateway.

When recursive (BGP) route uses PtP route, it should not use recursive
next hop as immediate next hop, while for direct routes it should.
2019-10-10 15:06:32 +02:00
Ondrej Zajicek (work)
cb2b6e0494 Nest: Fix recursive route update
Missing cleanup can lead to dangling pointer to old next hops.
2019-10-10 14:01:16 +02:00
Ondrej Zajicek (work)
09ee846d92 BGP: AIGP metric support (RFC 7311) 2019-10-09 17:53:23 +02:00
Ondrej Zajicek (work)
759b204be3 Lib: Support for 64-bit numbers in bvsnprintf()
Use 'l' for s64/u64 instead of for long/ulong, as that is much more
useful. Also make number() correct with regard to signed/unsigned
typecasts.
2019-10-09 17:53:23 +02:00
Maria Matejka
cc95b4594a Build: Pass -g to cc called as linker to explicitly keep debug info 2019-10-09 17:47:14 +02:00
Maria Matejka
d6eea6caee Testing measures times 2019-10-09 17:47:14 +02:00
Maria Matejka
368f70604f LTO: debug info also kept with the final binary 2019-10-09 17:47:14 +02:00
Maria Matejka
6dda6931d1 Perf: allow testing with cached route attributes. 2019-10-09 17:47:14 +02:00
Ondrej Zajicek
15a7583787 Doc: Fix duplicated lines
Thanks to elados93 for the patch.
2019-10-08 14:20:25 +02:00
Maria Matejka
c41a914d6e Testing: Don't call vsnprintf with NULL format 2019-10-04 20:52:07 +02:00
Maria Matejka
24493e9169 Fixed undefined behavior on signals.
The C11 specification allows only sig_atomic_t and _Atomic variable
access. All other accesses to global variables are undefined behavior.

Using int was probably OK on x86 and x86_64; yet there were some reports
from other architectures (especially some MIPS) that in rare cases,
after issuing SIGHUP, BIRD did strange things.
2019-10-04 20:52:07 +02:00
Ondrej Zajicek (work)
4821251ebb BFD: Fix reconfiguration of neighbors
The bfd_reconfigure_neighbors() returned after first reconfigured
neighbor instead of continuing with the next one.

Thanks to Winston Chen for the bugreport and a patch.
2019-09-30 19:10:14 +02:00
Ondrej Zajicek (work)
ca2dacfcee Nest: Fix bug in export table
Exported route may be in modified state, we need to get cached one for
rte_same() and rta_clone() to work properly.
2019-09-24 17:17:37 +02:00
Ondrej Zajicek (work)
ea0917bcba Filter: Fix eval command 2019-09-24 00:18:48 +02:00
Ondrej Zajicek (work)
9c79022153 Nest: Fix help for 'graceful restart' command
Multi-worded commands are not automatically added to top-level
help output.

Thanks to Christoph for the bugreport.
2019-09-23 14:52:31 +02:00
Maria Matejka
3f477ccb03 Filters: Function body comparison result now used.
Function bodies were compared in post-parse time, yet the result was not
used and the functions were incorrectly considered the same as before.

Now the result is used to reload affected protocols.
2019-09-23 14:03:26 +02:00
Ondrej Zajicek (work)
eb1e43a9af BGP: Fix setup with multiple dynamic BGP ranges
Based on a patch from Liam Nattrass, thanks.
2019-09-17 14:45:14 +02:00
Ondrej Zajicek (work)
5235c3f78d NEWS and version update 2019-09-10 17:34:41 +02:00
Ondrej Zajicek (work)
532471967e Doc: Update BGP mask documentation 2019-09-10 17:28:06 +02:00
Ondrej Zajicek (work)
452e90ba72 Filter: Fix crash with 'where' filters and function calls
The old 'where' code computed size value incorrectly, which leads
to invalid instruction lines and filter errors or crashes.
2019-09-10 13:45:18 +02:00
Ondrej Zajicek (work)
1127887a8b BGP: Fix handling of bgp_aggregator atttribute
The attribute should not be modifiable by filters as we do not
support its type.
2019-09-09 13:17:30 +02:00
Ondrej Zajicek (work)
8388f5a7e1 BGP: Fix bugs in handling of shutdown messages
There is an improper check for valid message size, which may lead to
stack overflow and buffer leaks to log when a large message is received.

Thanks to Daniel McCarney for bugreport and analysis.
2019-09-09 03:13:35 +02:00
Ondrej Zajicek (work)
56d8b1e7f6 OSPF: Fix 'show ospf lsadb' cmd without proto arg
It crashed when used without protocol argument.

Thanks to Alexander for the bugreport.
2019-08-29 20:58:16 +02:00
Maria Matejka
32a254050d Channel refeed with import table splitting between routes for one prefix 2019-08-27 19:14:15 +02:00
Ondrej Zajicek (work)
5ab3447de1 Sysdep: Drop supplementary groups when dropping GID
We forgot to do that. Oops.
2019-08-21 17:30:00 +02:00
Ondrej Zajicek (work)
4fa0e472cf BGP: Use reallocation for capability structure
Instead of having large stack buffer for max amount of AFI/SAFI pairs.
The old code is not correct w.r.t. extendeded option length, as more
AFI/SAFI pairs may fit into the capability option.
2019-08-21 17:16:08 +02:00
Ondrej Zajicek (work)
524d253853 BGP: Implement extended optional parameters length
Extends BGP options/capabilities data length to 16bit, to avoid issues
with too many capabilities. See draft-ietf-idr-ext-opt-param-07
2019-08-20 19:15:50 +02:00
Ondrej Zajicek (work)
a297a4f044 Nest: Fix crash in route reload when some channels are not up.
Only channels that are up can be reloaded.
2019-08-14 06:02:33 +02:00
Ondrej Zajicek (work)
b7d7599ce3 BGP: implement Adj-RIB-Out
The patch implements optional internal export table to a channel and
hooks it to BGP so it can be used as Adj-RIB-Out. When enabled, all
exported (post-filtered) routes are stored there. An export table can be
examined using e.g. 'show route export table bgp1.ipv4'.
2019-08-14 06:02:33 +02:00
Maria Matejka
dfe63ed84d Filter: Fixing empty block and never-executed-statement bug 2019-08-13 16:45:27 +02:00
Ondrej Zajicek (work)
70a4320bdd RAdv: Allow solicited RAs to be sent as unicast
Add option to send solicited router advertisements as unicast directly
to soliciting nodes instead of as multicast to all-nodes group.
2019-08-12 00:43:19 +02:00
Ondrej Zajicek (work)
9f3e098320 Filter: Allow to use set constants / expressions in path masks
Allow to not only use set literals in path masks, but also existing
set constants or set expressions.
2019-08-06 18:54:19 +02:00
Ondrej Zajicek (work)
ef113c6f72 Filter: Allow to use sets in path masks 2019-08-06 16:58:13 +02:00
Ondrej Zajicek (work)
e2b530aa72 BGP: Improve reconfiguration
Several BGP channel options (including 'next hop self') could be
reconfigured without session reset, with just route refeed/refresh.
The patch improves reconfiguration code to do it that way.
2019-08-06 15:29:06 +02:00
Ondrej Zajicek (work)
f6a6a77640 BGP: Fix 'deterministic med' to work with 'merge paths'
The 'deterministic med' option is implemented by suppressing other than
best-in-group routes (grouped by ASN) from best route selection. This
interferes with 'merge paths' as supressed routes are no longer mergable
with best route. This is fixed by suppressing only those routes that are
not mergable with best-in-group route.
2019-08-06 15:09:42 +02:00
Ondrej Zajicek (work)
8c42205e35 Configure: CFLAGS update
- add -flto only to default CFLAGS
 - add -fno-strict-aliasing, -fno-strict-overflow always
 - remove -Wno-implicit-fallthrough
2019-08-06 14:54:36 +02:00
Ondrej Zajicek
cc02da816f Show LDFLAGS in configure 2019-08-01 14:49:03 +02:00
Ondrej Zajicek
3ffb0c4f25 Enable more threads for flto 2019-08-01 14:45:23 +02:00
Ondrej Zajicek
de41d24a3d Fix output of CFLAGS in configure script 2019-08-01 14:27:20 +02:00
Ondrej Zajicek (work)
543875e080 NEWS and version update 2019-07-31 23:35:29 +02:00
Ondrej Zajicek (work)
96e4d0960c Change 'graceful down' command to 'graceful restart' and update docs
The command initiating planned graceful restart including bird shutdown
should be called 'graceful restart' instead of 'graceful down', as the
later should be reserved for graceful shutdown in style of RFC 8326.
2019-07-31 19:45:29 +02:00
Ondrej Zajicek (work)
8c703ecf73 Doc: Update documentation about VRFs and BFD 2019-07-30 19:21:06 +02:00
Maria Matejka
2de1e2062e Conf: Fixed symbol redefinition 2019-07-30 14:28:40 +02:00
Maria Matejka
48addc88be Log: Fixed race condition in reconfigure while BFD is running 2019-07-30 12:26:37 +02:00
Vincent Bernat
3b62417c35 RPKI: Fix allocation of hostname when using an IPv6 address 2019-07-29 15:42:30 +02:00
Ondrej Zajicek (work)
00284f0ed6 BFD: Fix formatting of 'show bfd sessions'
The formatting was broken due to longer date in 'since' column.
2019-07-25 14:24:16 +02:00
Ondrej Zajicek (work)
cec40a7467 Merge remote-tracking branch 'origin/mq-filter-stack' 2019-07-24 15:38:32 +02:00
Ondrej Zajicek (work)
18f70a6229 Nest: VRF of protocol can be explicitly specified as 'default'
Protocol can have specified VRF, in such case it is restricted to a set
of ifaces associated with the VRF, otherwise it can use all interfaces.

The patch allows to specify VRF as 'default', in which case it is
restricted to a set of iface not associated with any VRF.
2019-07-24 15:08:03 +02:00
Ondrej Zajicek (work)
048c2f0e8c OSPF: Fix formatting of 'show ospf neighbors'
The formatting was broken when too short router-id was used.
2019-07-23 17:02:41 +02:00
Ondrej Zajicek (work)
15b0a92294 RPKI: Fix reconfiguration when ssh parameters are undefined 2019-07-23 01:52:18 +02:00
Ondrej Zajicek (work)
d843c27478 Lib: Improve printf() tests
Includes patch from Maximilian Eschenbacher
2019-07-18 02:39:35 +02:00
Ondrej Zajicek (work)
39edf4abca Lib: Fix print of 64-bit router id
Mismatched types to printf(). The old code coincidentally worked on amd64
due to its calling conventions.

Thanks to Maximilian Eschenbacher for the bugreport.
2019-07-18 01:57:26 +02:00
Ondrej Zajicek (work)
cf7ff99513 BFD: Support for VRFs
Allow multiple BFD instances in separate VRFs, dispatch BFD requests
according to VRFs.

Thanks to Alexander Zubkov for notice and patches.
2019-07-17 16:20:35 +02:00
Ondrej Zajicek (work)
2eaf65ec60 Netlink: Fix parsing of multipath routes with MPLS labels 2019-07-15 18:16:55 +02:00
Ondrej Zajicek (work)
8235c4747d Netlink: Use route replace for IPv4
Use route replace netlink op instead of delete+add netlink ops for kernel
IPv4 route replace. This avoids some packetloss during route replace.
Still use the old behavior for IPv6, as some kernel bugs are hidden in
IPv6 ECMP handling.
2019-07-15 16:23:18 +02:00
Maria Matejka
8263690e75 Merge remote-tracking branch 'origin/master' into mq-filter-stack 2019-07-15 16:07:16 +02:00
Maria Matejka
efd7c87b5b Filter: further split of print & die to FI_PRINT, FI_FLUSH and FI_DIE 2019-07-15 15:46:36 +02:00
Maria Matejka
3782454e8d Filter: Simpler filter context allocation 2019-07-15 15:46:36 +02:00
Maria Matejka
f634adc7dc Filter: FID_MEMBER debug string is a C constant string 2019-07-15 15:17:04 +02:00
Maria Matejka
c0999a149c Filter: Converted FI_PRINT and FI_PATHMASK_CONSTRUCT to VARARG 2019-07-15 15:12:18 +02:00
Maria Matejka
c29d73a06a Filter: fixed excessive stack allocation in functions with args but no local vars 2019-07-15 15:06:52 +02:00
Maria Matejka
0da06b7103 Filter: lots of documentation 2019-07-15 13:19:01 +02:00
Maria Matejka
1b9db6d4a7 Filter: Don't write out when re-evaluating filter for internal purposes. 2019-07-15 12:03:47 +02:00
Maria Matejka
547be53b8c Filter: Don't fail badly when trying to access non-existent route in config time 2019-07-15 12:03:13 +02:00
Ondrej Zajicek (work)
1aec7112f7 OSPF: Fix handling of NSSA option flags
Per RFC 3101, N-bit signalling NSSA support should be used only in Hello
packets, not in DBDES packets. BIRD since 2.0.4 verifies N-bit in
neighbor structure, which is learned from DBDES packets, therefore
NSSA-LSAs are not propagated to proper implementations of RFC 3101.

This patch fixes that. Both removing the check and removing N-bit from
DBDES packet. This will fix compatibility issues with proper
implementations, but causes compatibility issues with BIRD 2.0.4.
2019-07-10 18:25:36 +02:00
Ondrej Zajicek (work)
bfa15a642f Filter: Minor cleanups 2019-07-10 16:47:17 +02:00
Maria Matejka
b2a4feeb4c Merge branch 'master' into mq-filter-stack 2019-07-10 11:27:08 +02:00
Maria Matejka
422a933429 Debug: growing message format buffer
This led in corner cases to undefined buffer content
and garbage output.
2019-07-10 11:12:41 +02:00
Ondrej Zajicek (work)
deb84d7989 OSPF: Minor fix in graceful restart
Most LSA origination is blocked in ospf_update_topology(), this fix
blocks LSA origination from ospf_rt_spf().
2019-07-09 15:57:46 +02:00
Vincent Bernat
e840cb9cd5 Doc: Fix typo in BGP dynamic names feature description 2019-07-09 15:30:45 +02:00
Maria Matejka
74a38adb6b Merge branch 'master' of gitlab.labs.nic.cz:labs/bird 2019-07-09 14:53:15 +02:00
Maria Matejka
1322e205e2 Test: Fixed annoying warnings (and possible obscure bugs). 2019-07-09 14:37:14 +02:00
Maria Matejka
bb001af0e8 Test: better random u64 generator 2019-07-09 14:37:14 +02:00
Ondrej Zajicek (work)
2872ab927e OSPF: Update DR when local priority changes
When priority is reconfigured locally, we need to trigger DR election.

(recommiting, was reset by the previous commit)
2019-07-09 03:48:02 +02:00
Ondrej Zajicek (work)
85840d4c03 OSPF: Fix handling of external routes on graceful restart
We need to flush learned external LSAs a bit later than other LSAs (after
first feed after end of the graceful restart) to avoid flap of external
routes.
2019-07-09 03:39:19 +02:00
Maria Matejka
05e3933c06 Nest: Uninitialized variable fix
Thanks to Vincent Bernat for reporting this.
2019-07-08 13:05:14 +02:00
Maria Matejka
2ce25ebbef Libdmalloc macros fixed 2019-07-08 13:00:13 +02:00
Ondrej Zajicek (work)
fa1e0ba354 OSPF: Update DR when local priority changes
When priority is reconfigured locally, we need to trigger DR election.
2019-07-04 13:34:42 +02:00
Maria Matejka
eac9250fd5 Merge branch 'master' into mq-filter-stack 2019-07-03 11:12:25 +02:00
Maria Matejka
8816b6cdd9 Merge branch 'mq-filter-stack' of gitlab.labs.nic.cz:labs/bird into mq-filter-stack 2019-07-03 08:44:42 +02:00
Maria Matejka
84ac62d396 Filter: CLI command to dump all the linearized filters 2019-07-03 08:27:56 +02:00
Maria Matejka
0206c070ac Filter: Split printing and dying 2019-07-03 08:27:56 +02:00
Maria Matejka
3265c9169d Removed obsolete comment at as_path_cut() 2019-07-03 00:04:24 +02:00
Maria Matejka
78976974e7 Dynamic attributes definition split whether it is bitmask or not. 2019-07-03 00:00:11 +02:00
Maria Matejka
263fa2c4a6 Filter: Dropped some more irrelevant whitespace from generated files 2019-07-02 22:57:00 +02:00
Ondrej Zajicek (work)
59d3a3611f Netlink: Handle alien routes with unsorted nexthops
Nest requires that nexthops are sorted, the kernel protocol have to
ensure that for alien routes.
2019-07-02 18:23:06 +02:00
Maria Matejka
84c58aabd0 Filter: Nicer whitespaces in generated inst-gen.h 2019-07-02 17:59:21 +02:00
Maria Matejka
550a6488c9 Filter: documentation of the M4 preprocessor 2019-07-02 17:39:56 +02:00
Ondrej Zajicek (work)
1187627a1d Netlink: Do unified scan for both IPv4 and IPv6
Instead of separate scans for IPv4, IPv6 and MPLS, do one AF_UNSPEC scan.

This also avoids kernel issue when kernel reported IPv4 and IPv6 routes
during MPLS scan if MPLS is not active.
2019-07-02 16:30:36 +02:00
Maria Matejka
c376555cec Filter: GCC, don't complain about indentation in generated code. 2019-07-02 13:13:29 +02:00
Maria Matejka
b40c0f028f Filter: Pre-evaluation of constant expressions 2019-07-02 10:45:53 +02:00
Maria Matejka
30667d5041 Filter: Resolving of defined constants in config time 2019-07-01 14:12:05 +02:00
Maria Matejka
26bfe59f45 Filter: Moved singleton member definitions to f-inst.c 2019-07-01 13:13:06 +02:00
Maria Matejka
4212c0e7e5 Filter: Moved f_inst allocation to separate function 2019-07-01 12:49:02 +02:00
Maria Matejka
f74d19765e Filter: Getting rid of RESULT_OK. Adding RESULT_VOID.
This is a preparation for filter pre-evaluation.
2019-07-01 12:07:06 +02:00
Maria Matejka
236828d06f Filter: The interpreter code now shares its diversion with constructor
This is a preparation for filter pre-evaluation.
2019-07-01 11:57:35 +02:00
Maria Jan Matejka
026bfedb33 BGP: Prefix hash is too small, increase its max size.
This doesn't make any change for you until you have
millions of updates waiting to be sent. Increasing
the max hash size from 2^20 to 2^24.
2019-07-01 09:05:54 +02:00
Maria Jan Matejka
9dac814ee8 BGP: split tx explicitly
If BGP has too many data to send and BIRD is slower than the link, TX is
always possible until all data is sent. This patch limits maximum number
of generated BGP messages in one iteration of TX hook.
2019-07-01 09:05:50 +02:00
Ondrej Zajicek (work)
bb57d9171f Add mock-up function for unit tests
They failed without it.
2019-06-30 22:30:56 +02:00
Ondrej Zajicek (work)
6c0f85d5de Doc: OSPF graceful restart options 2019-06-30 22:11:29 +02:00
Ondrej Zajicek (work)
1a2ad348f6 OSPF: Support for graceful restart
Implement OSPFv2 (RFC 3623) and OSPFv3 (RFC 5187) graceful restart,
for both restarting and helper sides. Graceful restart is initiated
by 'graceful down' command.
2019-06-30 21:30:41 +02:00
Ondrej Zajicek (work)
8a68316eb9 Nest: Add command to request graceful restart
When 'graceful down' command is entered, protocols are shut down
with regard to graceful restart. Namely Kernel protocol does
not remove routes and BGP protocol does not send notification,
just closes the connection.
2019-06-30 21:29:24 +02:00
Maria Matejka
63f49457dc Filter: renaming pointers for consistency
The struct f_inst * is now always "what"
and the union member pointer is always "whati".
2019-06-28 11:26:36 +02:00
Maria Matejka
64bb1346c7 Filter: A little cleanup of M4 interpreter generator 2019-06-27 23:57:59 +02:00
Maria Matejka
a8ab54d18d Merge remote-tracking branch 'refs/remotes/origin/mq-filter-stack' into mq-filter-stack 2019-06-25 22:40:05 +02:00
Maria Matejka
63e7620462 Conf/Filters: Moved argument count to conf scope 2019-06-25 16:18:06 +02:00
Maria Matejka
2e0777317f Filter instructions don't confuse now v1 and res. 2019-06-21 11:33:28 +02:00
Maria Matejka
a84b8b6ebb Revert "Filter: Dropped the setter instructions in favor of direct result storage."
This reverts commit bd91338246c1ba40358243f1bdf5a6dbd3a29f35.
2019-06-19 14:09:57 +02:00
Maria Matejka
5c864e2cfa String: bstrtoul macro expanded to bstrtoul10 and 16 2019-06-13 14:27:58 +02:00
Maria Matejka
87c82334a7 Filter: removal of semantically insane consts in filter_commit 2019-06-13 14:24:48 +02:00
Ondrej Zajicek (work)
bdf2e55d98 Add mock-up function for unit tests
They failed without it.
2019-06-12 18:02:01 +02:00
Ondrej Zajicek (work)
9106a750cd Add CLI command to test reconfiguration status
Based on patch from Kenth Eriksson <kenth.eriksson@infinera.com>.
2019-06-12 17:15:35 +02:00
Kenth Eriksson
8a2cbb88d1 BIRD coding conventions
Added Emacs config file describing BIRD coding conventions, as suggested
by Kenth Eriksson based on existing practice.
2019-06-12 16:37:12 +02:00
Ondrej Zajicek (work)
d35fb9d732 BGP: Fix bug introduced in one of last patches 2019-06-12 16:37:12 +02:00
Maria Matejka
bd91338246 Filter: Dropped the setter instructions in favor of direct result storage.
This should help filter performance a bit.
2019-06-03 10:41:35 +02:00
Maria Matejka
aa6c5f4d92 Filter: Just a little comments in filter structure 2019-05-30 14:42:54 +02:00
Maria Matejka
1757a6fce5 Filter: Stacks moved to thread-local storage if available. 2019-05-29 21:03:52 +02:00
Jan Maria Matejka
6479e403ef Filters: If somebody doesn't like _Thread_local, don't fail for now, just be a little slower.
When the parallel execution comes into place, we'll likely enforce this
C11 feature. It's much simpler and also faster than pthread_[sg]etspecific().
2019-05-23 11:27:24 +00:00
Jan Maria Matejka
23e3b1e665 Filter: Some people can't pronounce "postfixify" correctly. Let's try "linearize" instead.
This is just a naming change.
2019-05-22 15:20:02 +00:00
Jan Maria Matejka
96d757c13f Filter: Store variables and function arguments on stack 2019-05-21 16:33:37 +00:00
Jan Maria Matejka
20c6ea70cc Filter: Making the filter state thread local.
While having the filter code still reentrant if we really need,
the compiler can now do constant propagation and address the
thread local storage directly to save some computation time.
2019-05-20 17:53:10 +00:00
Maria Matejka
9eef9c648c Lexer now returns known sym / unknown sym / keyword 2019-05-17 22:26:21 +02:00
Ondrej Zajicek (work)
dbbe4a783b Doc: Dynamic BGP 2019-04-30 16:16:50 +02:00
Alexander Azimov
7ff34ca2cb BGP: Compliance with RFC8203bis 2019-04-30 13:55:43 +02:00
Ondrej Zajicek (work)
0b1e1e1a00 BGP: Output Local AS number in show protocol
Useful for implementation of agents implementing the SNMP-BGP MIB, which
requires the local AS of a session to be specified.

Thanks to Jan-Philipp Litza for the patch.
2019-04-30 13:44:11 +02:00
Ondrej Zajicek (work)
e0835db4f1 BGP: Dynamic BGP
Support for dynamically spawning BGP protocols for incoming connections.
Use 'neighbor range' to specify range of valid neighbor addresses, then
incoming connections from these addresses spawn new BGP instances.
2019-04-30 13:32:39 +02:00
Ondrej Filip
df092aa1de Small type in doc. 2019-04-24 13:49:18 +02:00
Ondrej Zajicek (work)
6ff8119765 OSPFv3: Fix some overlooked cases in IPv4 mode
Prefixes with max length (/32) were not handled properly.

Thanks to bauen1 for the bugreport.
2019-04-12 14:11:23 +02:00
Ondrej Zajicek (work)
4a50c8bd03 BGP: Handle corner cases in event ordering
When BGP connection is opened, it may happen that rx hook (with remote
OPEN) is called before tx hook (for local OPEN). Therefore, we need to do
internal changes (like setting local_caps) synchronously with OPENSENT
transition and we need to ensure that OPEN is sent before KEEPALIVE.
2019-04-08 16:56:56 +02:00
Ondrej Zajicek (work)
23ee6b1cd6 BGP: Promiscuous ASN mode
Allow to specify just 'internal' or 'external' for remote neighbor
instead of specific ASN. In the second case that means BGP peers with
any non-local ASNs are accepted.
2019-04-03 15:54:50 +02:00
Ondrej Zajicek (work)
a22c3e5968 BGP: Separate runtime and config usage of local/remote ip and as fields 2019-04-02 17:22:31 +02:00
Maria Matejka
fe503c7c06 Filter: fixed error-checking bug in !~ operator 2019-03-23 13:32:14 +01:00
Maria Matejka
7078aa63ae Fixed one warning and one undefined value. 2019-03-22 21:40:35 +01:00
Maria Matejka
2ab680c697 Fixed an undefined symbol bug in CLI introduced by filter refactoring 2019-03-20 16:50:58 +01:00
Ondrej Zajicek (work)
3a22a6e858 Doc: Route attribute cleanups 2019-03-19 19:38:32 +01:00
Ondrej Zajicek (work)
3c3605818f BGP: Mandatory option for channels
Allow to mark channel to be mandatory, and do not allow BGP sessions if
no common AFI/SAFI is established.
2019-03-19 17:44:50 +01:00
Ondrej Zajicek (work)
7e5f769d91 BGP: Handle case where capabilites are not used
If peer does not announce capabilities at all, or when we have
capabilities disabled, handle that as implicit IPv4 unicast.
2019-03-18 14:29:12 +01:00
Maria Matejka
8d65add626 Merge branch 'master' into HEAD 2019-03-18 12:54:40 +01:00
Maria Matejka
5d511948cd Build: Automatic dependency tracking for generated files 2019-03-18 12:32:11 +01:00
Maria Matejka
2f02c25e36 Perf: fixed stupid allocation bug 2019-03-15 16:34:26 +01:00
Maria Matejka
d638c1794a Gitlab CI: Drop CentOS 6 test build as unsupported.
If someone wants to maintain BIRD for CentOS 6,
feel free to send patches.
2019-03-15 16:34:19 +01:00
Ondrej Zajicek (work)
875cc073b0 Nest: Update handling of temporary attributes
The temporary atttributes are no longer removed by ea_do_prune(), but
they are undefined by store_tmp_attrs() protocol hooks. This fixes
several bugs where temporary attributes were removed when they should
not or not removed when they should be. The flag EAF_TEMP is no longer
needed and was removed.

Update all protocol make_tmp_attrs() / store_tmp_attrs() hooks to use
helper functions and to handle unset attributes properly.

Also fix some related bugs like improper handling of empty eattr list.
2019-03-14 17:31:40 +01:00
Ondrej Zajicek (work)
9aa77fcceb OSPF: Improved handling of tmpattrs
Keep track of whether OSPF tmpattrs are actually defined for given route
(using flags in rte->pflags). That makes them behave more like real
eattrs so a protocol can define just a subset of them or they can be
undefined by filters.

Do not set ospf_metric2 for other than type 2 external OSPF routes and do
not set ospf_tag for non-external OSPF routes. That also fixes a bug
where internal/inter-area route propagated from one OSPF instance to
another is initiated with infinity ospf_metric2.

Thanks to Yaroslav Dronskii for the bugreport.
2019-03-06 18:28:00 +01:00
Maria Matejka
e1ac6f1e30 Faster filters: documentation on what is happening there 2019-03-06 15:01:39 +01:00
Maria Matejka
a68442e056 Fixed link time optimizer check for FreeBSD 2019-02-27 14:40:05 +01:00
Ondrej Zajicek (work)
b9deced219 NEWS and version update 2019-02-26 18:21:39 +01:00
Maria Matejka
f249d0b84c Filters: comparison of functions and filters caching 2019-02-26 16:44:24 +01:00
Maria Matejka
0d12aa4836 Build: No link time optimization when debug is enabled 2019-02-26 16:11:40 +01:00
Maria Matejka
2915e711f7 Custom number parser to speed up config parsing
The glibc's generic parser is slow due to its versatility. Specialized
parsers for base-10 and base-16 are much faster and we don't use other
bases.
2019-02-25 23:28:36 +01:00
Maria Matejka
99911873a1 Conf: Lexer parses quoted strings in a more descriptive way 2019-02-25 17:22:59 +01:00
Maria Matejka
7c36eb3e8b Conf: Switch for faster (and slightly bigger) lexer 2019-02-22 12:43:43 +01:00
Maria Matejka
412614c700 Conf: Switch for faster (and slightly bigger) lexer 2019-02-22 12:41:51 +01:00
Ondrej Zajicek (work)
93af78d2d2 Nest: Do not compare rte.flags during rte_update()
Route flags are mosty internal state of rtable, they are not significant
to whether a route has changed. With the old code, all routes received as
a part of enhanced route refresh are always re-announced to other peers
due to change in REF_STALE.
2019-02-22 02:16:39 +01:00
Maria Matejka
ad702bae0c Enabled link time optimization. 2019-02-20 22:30:55 +01:00
Maria Matejka
d1039926f5 Filter: Interpreter merged into the common m4 generator.
The config-time partial evaluation of constant expressions in filters is nearby.
2019-02-20 22:30:55 +01:00
Maria Matejka
32793ab685 Filter: Fixed bugs in FI_CALL and FI_SWITCH 2019-02-20 22:30:55 +01:00
Maria Matejka
d348a916f5 Test: Added -d flag to die directly after first error. 2019-02-20 22:30:55 +01:00
Maria Matejka
d4bf74816f GDB: Added more pretty printers for filters 2019-02-20 22:30:55 +01:00
Maria Matejka
ea4f55e3dc Filter: More cleanup -- customized structures also in struct f_line_item 2019-02-20 22:30:55 +01:00
Maria Matejka
0b39b1cbb7 Conf: Symbol implementation converted from void pointers to union
... and consted some declarations.
2019-02-20 22:30:55 +01:00
Maria Matejka
132529ce89 Filter: merged filter compare functions into common M4 file 2019-02-20 22:30:55 +01:00
Maria Matejka
dd4d409551 Filter: Merged postfixify routine 2019-02-20 22:30:54 +01:00
Maria Matejka
de12cd18fb Filter: Merged filter line item dumpers into common generated source 2019-02-20 22:30:54 +01:00
Maria Matejka
b256f24145 Filter: auto-generating enum-to-string 2019-02-20 22:30:54 +01:00
Maria Matejka
041608129a Filter generator: workaround for M4 claiming all the put-around code be on one line 2019-02-20 22:30:54 +01:00
Maria Matejka
5289304519 Filter data manipulation functions separated to their file 2019-02-20 22:30:54 +01:00
Maria Matejka
87bd7cd7b0 Filter: split the constructors to a separate file 2019-02-20 22:30:54 +01:00
Maria Matejka
75206f266f Conf: Fixed makefiles 2019-02-20 22:30:54 +01:00
Maria Matejka
4f082dfa89 Filter: merged filter instruction constructors, counting line size on instruction construct 2019-02-20 22:30:54 +01:00
Maria Matejka
0a793ebc60 Test: Fixed annoying warnings (and possible obscure bugs). 2019-02-20 22:30:54 +01:00
Maria Matejka
8bdb05edb2 Filters: split the large filter.h file to smaller files.
This should be revised, there are still ugly things in the filter API.
2019-02-20 22:30:54 +01:00
Maria Matejka
c1e97169cd Filter: M4 convertors polished a bit. 2019-02-20 22:30:54 +01:00
Maria Matejka
c0e958e022 Filter + Config: Fix bugs, tests and split symbols by type 2019-02-20 22:30:54 +01:00
Maria Matejka
713658798d GDB pretty printers: f_inst and f_val. 2019-02-20 22:30:54 +01:00
Maria Matejka
9b46748d5b Filter: refactoring of instruction constructors 2019-02-20 22:30:54 +01:00
Maria Matejka
4c553c5a5b Filter refactoring: dropped the recursion from the interpreter
This is a major change of how the filters are interpreted. If everything
works how it should, it should not affect you unless you are hacking the
filters themselves.

Anyway, this change should make a huge improvement in the filter performance
as previous benchmarks showed that our major problem lies in the
recursion itself.

There are also some changes in nest and protocols, related mostly to
spreading const declarations throughout the whole BIRD and also to
refactored dynamic attribute definitions. The need of these came up
during the whole work and it is too difficult to split out these
not-so-related changes.
2019-02-20 22:30:54 +01:00
Maria Matejka
967b88d938 Filter refactoring: The instructions are converted to the switch body by M4 2019-02-20 22:30:54 +01:00
Maria Matejka
8436040735 Filter refactoring: Drop the roa check specific f_inst 2019-02-20 22:30:54 +01:00
Maria Matejka
ca2ee91a80 Filter refactoring: The constant f_val is simply included inside the instruction
With 32 bits, size of the args is 12 bytes, the f_val is 20 bytes.
With 64 bits, size of the args is 24 bytes, the f_val the same.

This is not so nice on 32 bits, anyway the f_inst itself is
24 vs. 32 bytes and the overall size of filters must be 32k of
instructions to get to one megabyte of RAM eaten by f_inst.

Therefore it seems to be improbable for common user to get into
problems with this change.
2019-02-20 22:30:54 +01:00
Maria Matejka
7f0ac73724 Filter refactoring: Changed arguments from separate unions to an array 2019-02-20 22:30:54 +01:00
Maria Matejka
224b77d4f7 Filter refactoring: Converted condition to three-args instruction 2019-02-20 22:30:54 +01:00
Maria Matejka
8e8b1fe48c Filter refactoring: Some instructions eat up excessively much space. 2019-02-20 22:30:54 +01:00
Maria Matejka
c577493908 Filter refactoring: Expanded the short instructions with common code.
This will make the further changes more straightforward.
2019-02-20 22:30:54 +01:00
Maria Matejka
a8740d6c09 Filter refactoring: indentation fix 2019-02-20 22:30:54 +01:00
Jan Maria Matejka
fc8df41ec6 Filter refactoring: The values are now saved on a custom stack.
This shall help with performance.
2019-02-20 22:30:54 +01:00
Jan Maria Matejka
7afa143886 Filter refactoring: Passing the resulting struct f_val as a pointer.
This also drops the multiplexing of errors with the f_val itself
together with the T_RETURN f_val type flag.
2019-02-20 22:30:54 +01:00
Jan Maria Matejka
f62a369fb4 Filter refactoring: Moved filter instruction definition to a separate file 2019-02-20 22:30:54 +01:00
Jan Maria Matejka
25566c6810 Filter refactoring: Moved the bitfield bit position formula to route.h 2019-02-20 22:30:54 +01:00
Jan Maria Matejka
aca8263926 Filter refactoring: Moved the interpret macros inside the block 2019-02-20 22:30:54 +01:00
Jan Maria Matejka
02dcbf343d Configure: Don't check for implicit fallthrough unless when debugging. 2019-02-20 22:30:53 +01:00
Jan Maria Matejka
a946317fab Filter: Converted static global variables to a filter_state struct.
The static filter state was messy and blocked the planned parallel
execution of filters. Anyway, this will be also slower as the state
structure must be passed almost everywhere with us.
2019-02-20 22:30:53 +01:00
Ondrej Zajicek (work)
ae294cc2d0 HTML are no longer generated in srcdir 2019-02-19 18:30:28 +01:00
Ondrej Zajicek (work)
900fda4411 Doc: Detect SP/OpenSP automatically 2019-02-19 18:20:07 +01:00
Ondrej Zajicek (work)
3a8ca7abbc Nest: Prevent withdraws from propagation back to source protocol (for accepted mode)
Update for one of previous patches, handles the the issue for
first-accepted mode of route propagation.
2019-02-19 16:26:09 +01:00
Ondrej Zajicek (work)
bf8d7bba9e OSPF: Reset LSAs during area type change
When area is reconfigured to a different type, we need to flush LSAs as
they may not be valid (e.g. NSSA-LSA for non-NSSA area). Also, when we
have have just one OSPF area and that changes type, we could restart OSPF
as there is no state to keep anyway. That solves issue with different
handling of external routes exported to OSPF based of main area type.
2019-02-17 01:54:01 +01:00
Ondrej Zajicek (work)
4a3f5b3617 OSPF: Basic support for DN-bit handling (RFC 4576)
External LSAs originated by OSPF routers with VPN-PE behavior enabled are
marked by DN flag and they are ignored by other OSPF routers with VPN-PE
enabled.
2019-02-13 15:53:36 +01:00
Ondrej Zajicek (work)
1e958e52d3 OSPF: Do not originate Router-Information LSA
As we do not have much usage for it yet.
2019-02-09 16:15:01 +01:00
Ondrej Zajicek (work)
cd16538fc9 Merge remote-tracking branch 'origin/mq-opt' 2019-02-09 15:53:16 +01:00
Ondrej Zajicek (work)
6e8fb66859 Nest: Improve export counter handling
One of previous workarounds for phantom route avoidance breaks export
counters by expanding sending of spurious withdraws, which are send when
we are not sure whether we have advertised that routes in the past.
If not, then export counter is decreased, but it was not increased
before, so it overflows under zero.

The patch fixes that by sendung spurious withdraws, but not counting them
on export counter. That may lead to error in the other direction, but that
happens only as a race condition (i.e., in normal operation filters
return proper values about old route export state).
2019-02-05 19:00:43 +01:00
Ondrej Zajicek (work)
52fdd1cb76 Nest: Report preferred counters also when 'import keep filtered' is enabled
Thanks to Michal Nowak for reporting the issue.
2019-02-05 15:59:26 +01:00
Ondrej Zajicek (work)
a9b97cbcb7 OSPF: Send direct acknowledgements as unicast
Direct acknowledgements should be send as unicast to a corresponding
neighbor. Only delayed acks should be send as multicast to all/designated
routers.
2019-02-03 20:22:40 +01:00
Ondrej Zajicek (work)
16605f2fda OSPF: Reject duplicate DBDES packets after dead interval
Master may free last DBDES packet immediately. Slave must wait dead
interval before freeing last DBDES packet and then reject duplicate
DBDES packets with SeqNumberMismatch.
2019-02-03 17:31:27 +01:00
Ondrej Zajicek (work)
9c94583a3d OSPF: DD seqnum should be initialized only for first attempts
After SeqNumberMismatch/BadLSReq, we should continue with the old
seqnum++. The old code tries to do that by n->adj, but it was set
nowhere.
2019-02-03 16:20:37 +01:00
Ondrej Zajicek (work)
267da8138d OSPF: Reject DBDES packets with non-matching MTU
As it is specified in RFC 2328. The old code just provided warning.
2019-02-03 15:45:43 +01:00
Ondrej Zajicek (work)
e1c275d87b Nest: Reestablish preferred counters 2019-02-02 13:28:16 +01:00
Maria Matejka
f9b97f1c62 Perf: Added forgotten all-protocol options 2019-02-01 14:09:01 +01:00
Maria Matejka
a8d0f2516c Nest: FIB rehash values tweaked for better performance 2019-01-31 15:10:51 +01:00
Maria Matejka
e85e37d91d Perf: Prune the table after every loop to have clean state. 2019-01-31 15:05:40 +01:00
Maria Matejka
7411b694c3 Perf: Write also BIRD version to have all the needed data in the logfile 2019-01-31 15:03:43 +01:00
Maria Matejka
c65a9a05f9 Nest: Don't lookup net in table before filters are run.
Using dummy net instead. This should help with performance on rejected
routes.
2019-01-31 15:02:15 +01:00
Ondrej Zajicek (work)
e84c81b76f Nest: Prevent withdraws from propagation back to source protocol
The earlier fix loosen conditions for not running filters on old
route when deciding about route propagation to a protocol to avoid
issues with ghost routes in some race conditions.

Unfortunately, the fix also caused back-propagation of withdraws. For
regular updates, back-propagation is prevented in import_control hooks,
but these are not called on withdraws. For them, import_control hooks
are called on old routes instead, changing (old, NULL) notification
to (NULL, NULL), which is ignored. By not calling export processing
in some cases, the withdraw is not ignored and is back-propagated.

This patch fixes that by contract conditions so the earlier fix is not
applied to back-propagated updates.
2019-01-30 17:25:21 +01:00
Ondrej Zajicek (work)
ee95f281f0 Doc: Add documentation for OSPF retransmit delay option
Thanks to Igor Podlesny for notification.
2019-01-26 21:02:35 +01:00
Ondrej Zajicek (work)
1c730ee761 Doc: Remove doc for already removed option 2019-01-26 20:44:37 +01:00
Ondrej Zajicek (work)
b8a3608aa5 BGP: Cleanup channels when going down
When going up, uncleaned old channel state may trigger unexpected
conditions crashing bird.
2019-01-26 19:48:16 +01:00
Ondrej Zajicek (work)
5a50a98980 OSPF: Opaque LSAs and Router Information LSA
Add support for OSPFv2 Opaque LSAs (RFC 5250) and for Router Information
LSA (RFC 7770). The second part is here mainly for testing opaque LSAs.
2019-01-24 22:45:27 +01:00
Jan Maria Matejka
9548888599 Nest: Don't make tmp_attr before preexport is called 2019-01-17 13:50:47 +01:00
Ondrej Zajicek (work)
3e60932a28 NEWS and version update 2019-01-05 00:38:37 +01:00
Ondrej Zajicek (work)
d7e8f00e7e Unix: Remove removed option from help
Also includes minor cleanup of help.
2019-01-04 23:49:26 +01:00
Ondrej Zajicek (work)
a1ee5eb2aa BSD: Fix TCP-MD5 code on current FreeBSD kernels
Current FreeBSD kernels require SA records for both directions.

Thanks to Joseph Mulloy and Andrey V. Elsukov for reporting and
solving the issue.
2019-01-04 18:21:27 +01:00
Ondrej Zajicek (work)
4d9049dc1a Doc: README and INSTALL update
Minor cleanups, updates and clarifications. Also removes (incomplete
and well-known) build steps from README, as they are better described
in INSTALL.
2019-01-03 17:26:52 +01:00
Ondrej Zajicek (work)
470740f97b BGP: Better dispatch of incoming connections
Since v2 we have multiple listening BGP sockets, and each BGP protocol
has associated one of them. Use listening socket that accepted the
incoming connection as a key in the dispatch process so only BGP
protocols assocaited with that listening socket can be selected.
This is necesary for proper dispatch when VRFs are used.
2019-01-02 16:01:21 +01:00
Ondrej Zajicek (work)
e16b0aef31 BGP: Postpone setting link_addr
It may happen that the LLv6 address for given iface is not defined during
BGP start, so we postpone the check to the the session establishment.
2019-01-02 15:57:14 +01:00
Arthur Gautier
4659b2ae45 KRT: Fix debug messages in netlink code 2018-12-28 19:41:18 +01:00
Ondrej Zajicek (work)
c2d29dd197 IO: Workaround for broken FreeBSD behavior
FreeBSD silently changes TTL to 1 when MSG_DONTROUTE is used, even when
it is explicitly set to another value. That breaks TTL security sockets,
including BFD which always uses TTL 255. Bad FreeBSD!
2018-12-18 19:17:17 +01:00
Maria Matějka
82b742533b Perf: Protocol to measure BIRD performance internally
This protocol is highly experimental and nobody should use it in
production. Anyway it may help you getting some insight into what eats
so much time in filter processing.
2018-12-18 15:08:31 +01:00
Jan Maria Matejka
78131eee64 Debug: support for -gdwarf-4 is not available everywhere 2018-12-18 14:55:29 +01:00
Ondrej Zajicek (work)
bda5863425 Nest: Handle labels_orig correctly in attribute cache 2018-12-18 14:41:12 +01:00
Ondrej Zajicek (work)
cea2e25f41 OSPF: Fix wrong LSA collisions detection
In some circumstances (old LSA flushed but not acknowledged and not
removed) origination of a new LSA may wrongly triggers LSA collision
code. The patch fixes that.

Thanks to Asbjorn Mikkelsen for the bugreport and @mdelagueronniere
for the original patch.
2018-12-17 17:01:08 +01:00
Ondrej Zajicek (work)
1cab2b4a7c BGP: Extend 'next hop keep' and 'next hop self' options
Extend 'next hop keep' and 'next hop self' options to have boolean values
(enabled / disabled) and also values 'ibgp'/ 'ebgp' to restrict it to
routes received from IBGP / EBGP. This allows to have it enabled by
default in some cases, matches features of other implementations, and
allows to handle some strange cases like EBGP border router with 'next
hop self' also doing IBGP route reflecting.

Change default of 'next hop keep' to enabled for route servers, and
'ibgp' for route reflectors.

Update documentation for these options.
2018-12-16 23:44:24 +01:00
Ondrej Zajicek (work)
337165959c Nest: Fix handling of ECMP next hop flags
Flag field was not copied when next hop was cached.
2018-12-16 23:39:53 +01:00
Ondrej Zajicek (work)
cfa6ff9569 Nest: fix bug in previous patches related to channel reconfiguration
The patch d506263d... blocked adding channel during reconfiguration,
that broke protocols which use the same functiona also during init.
This patch fixes that.
2018-12-16 22:48:13 +01:00
Ondrej Zajicek (work)
cb311b441a BGP: Better handling of non-matching AFI in nexthops 2018-12-16 15:43:58 +01:00
Ondrej Zajicek (work)
3a2a3c7325 Doc: Rename code documentation files back to Doc 2018-12-14 02:03:42 +01:00
Ondrej Zajicek (work)
1e0fccd1af Doc: Move root of code documentation to doc dir
It reduces clutter in root and also avoid collision with doc dir on
case-insensitive filesystems when name back to Doc.
2018-12-14 01:53:32 +01:00
Ondrej Zajicek (work)
532116e7e3 BGP: Do not prepend ASN in export from non-RS EBGP to RS EBGP
When route is exported to regular EBGP, local ASN should be prepended to
AS_PATH. When route is propagated by route server (between RS-marked
EBGP peers), it should not change AS_PATH. Question is what to do in
other cases (from non-RS EBGP, IBGP, or locally originated to RS EBGP).

In 1.6.x, we did not prepend ASN in non-RS EBGP or IBGP to RS EBGP, but
we prepended in local to RS EBGP.

In 2.0.x, we changed that so only RS-EBGP to RS-EBGP is not prepended.
We received some negative responses (thanks to heisenbug and Alexander
Zubkov), we decided to change it back. One reason is that it is simple
to modify the AS_PATH by filters, but not possible to un-modify
changes done by BGP itself. Also, as 1.6.x behavior was not really
consistent, the final behavior is that ASN is never prepended when
exported to RS EBGP, like to IBGP.

Note that i do not express an opinion about whether such configurations
are even reasonable.
2018-12-12 17:36:54 +01:00
Ondrej Zajicek (work)
6b5ad2066a Doc: Document log rotation feature 2018-12-12 16:54:23 +01:00
Ondrej Zajicek (work)
0f40405fc9 Update RFC references
Progdoc comments do not allow SGML tags
2018-12-12 16:38:30 +01:00
Ondrej Zajicek (work)
9e92f357be Doc: Document BGP import table option 2018-12-12 16:04:15 +01:00
Ondrej Zajicek (work)
67d8665af5 Nest: Update statistics and rx-limit for Adj-RIB-In 2018-12-12 14:46:24 +01:00
Ondrej Zajicek (work)
682d3f7de0 BGP: implement Adj-RIB-In
The patch implements optional internal import table to a channel and
hooks it to BGP so it can be used as Adj-RIB-In. When enabled, all
received (pre-filtered) routes are stored there and import filters can
be re-evaluated without explicit route refresh. An import table can be
examined using e.g. 'show route import table bgp1.ipv4'.
2018-12-12 14:46:24 +01:00
Ondrej Zajicek (work)
01fd00f5ed Doc: Fix typo in previous LinuxDoc change 2018-12-11 18:43:58 +01:00
Ondrej Zajicek (work)
d506263da7 Nest: Forbid adding channels during reconfiguration
When a new channel is found during reconfiguration, do force restart
of the protocol, like with any other un-reconfigurable change.

The old behavior was that the new channel was added but remained in down
state, even if the protocol was up, so a manual protocol restart was
often necessary.

In the future this should be improved such that a reconfigurable
channel addition (e.g. direct) is accepted and channel is started,
while an un-reconfigurable addition forces protocol restart.
2018-12-11 17:57:14 +01:00
Ondrej Zajicek (work)
baeacdcfd3 OSPF: Fix reconfiguration of vlinks
Fix crash during reconfiguration of OSPF config with vlinks. When vlink
is reconfigured, a generic iface-reconfiguration code is used, which in
one place supposes that it is running on a regular iface.

Thanks to Cybertinus for a bugreport.
2018-12-10 02:15:06 +01:00
Jan Maria Matejka
9a5ef043c1 Merge branch 'mq-custom' into int-new 2018-12-06 09:55:34 +01:00
Maria Matejka
265419a369 Custom route attributes
For local route marking purposes, local custom route attributes may be
defined. These attributes are seamlessly stripped after export filter to
every real protocol like Kernel, BGP or OSPF, they however pass through
pipes. We currently allow at most 256 custom attributes.

This should be much faster than currently used bgp communities
for marking routes.
2018-12-06 09:55:21 +01:00
Robert Scheck
0e4920632a Doc: Allow overriding $SGML_CATALOG_FILES using distribution specific paths 2018-12-04 18:14:04 +01:00
Robert Scheck
f26bf60fb5 Doc: Add alternative path for SGML ISO entities 8879.1986 to $SGML_CATALOG_FILES
The existing paths are valid for Debian, alternative paths are necessary
for Fedora and RHEL/CentOS.
2018-12-04 18:11:42 +01:00
Ondrej Zajicek (work)
3fda08e405 Unix: Change debugging options
The old behavior was that enabling debugging did many nontrivial changes
in BIRD behavior. The patch changes it that these changes are generally
independent. Compiling with --enable-debug now just enables compile-time
debug macros, but do not automatically activate debug mode (-d) nor local
mode (-l). Debug mode with output to file (-D) do not force foreground
mode (-f), therefore there is no need for backgroud option (-b), which is
removed. Also fixes a bug when the default log target in -D mode was
stderr instead of given debug file.
2018-12-04 16:55:25 +01:00
Jan Maria Matejka
0642fb4d45 Hash: mem_hash doesn't modify the memory, declared constant 2018-12-04 14:00:53 +01:00
Jan Maria Matejka
d73c4ac869 Route table max hash size raised to 2^24.
This is still OK for everybody to fit into RAM and also probably enough
to keep a little collision rate for full BGP table.
2018-12-04 14:00:44 +01:00
Jan Maria Matejka
84661bf6da Changed IPv4 hash function to simple multiplication. 2018-12-04 14:00:28 +01:00
Jan Maria Matejka
14375237f6 Terminology cleanup: The import_control hook is now called preexport.
Once upon a time, far far away, there were the old Bird developers
discussing what direction of route flow shall be called import and
export. They decided to say "import to protocol" and "export to table"
when speaking about a protocol. When speaking about a table, they
spoke about "importing to table" and "exporting to protocol".

The latter terminology was adopted in configuration, then also the
bird CLI in commit ea2ae6dd0 started to use it (in year 2009). Now
it's 2018 and the terminology is the latter. Import is from protocol to
table, export is from table to protocol. Anyway, there was still an
import_control hook which executed right before route export.

One thing is funny. There are two commits in April 1999 with just two
minutes between them. The older announces the final settlement
on config terminology, the newer uses the other definition. Let's see
their commit messages as the git-log tool shows them (the newer first):

    commit 9e0e485e50ea74c4f1c5cb65bdfe6ce819c2cee2
    Author: Martin Mares <mj@ucw.cz>
    Date:   Mon Apr 5 20:17:59 1999 +0000

	Added some new protocol hooks (look at the comments for better explanation):

		make_tmp_attrs          Convert inline attributes to ea_list
		store_tmp_attrs         Convert ea_list to inline attributes
		import_control          Pre-import decisions

    commit 5056c559c4eb253a4eee10cf35b694faec5265eb
    Author: Martin Mares <mj@ucw.cz>
    Date:   Mon Apr 5 20:15:31 1999 +0000

	Changed syntax of attaching filters to protocols to hopefully the final
	version:

		EXPORT <filter-spec>    for outbound routes (i.e., those announced
					by BIRD to the rest of the world).
		IMPORT <filter-spec>    for inbound routes (i.e., those imported
					by BIRD from the rest of the world).

	where <filter-spec> is one of:

		ALL                     pass all routes
		NONE                    drop all routes
		FILTER <name>           use named filter
		FILTER { <filter> }     use explicitly defined filter

	For all protocols, the default is IMPORT ALL, EXPORT NONE. This includes
	the kernel protocol, so that you need to add EXPORT ALL to get the previous
	configuration of kernel syncer (as usually, see doc/bird.conf.example for
	a bird.conf example :)).

Let's say RIP to this almost 19-years-old inconsistency. For now, if you
import a route, it is always from protocol to table. If you export a
route, it is always from table to protocol.

And they lived happily ever after.
2018-12-04 10:53:01 +01:00
Ondrej Zajicek (work)
e2ae08694e Nest: Do not hard-reset interface when preferred address is changed
Modify protocols to use preferred address change notification instead on
depending on hard-reset of interfaces in that case, and remove hard-reset
in that case. This avoids issue when e.g. IPv6 protocol restarts
interface when IPv4 preferred address changed (as hard-reset is
unavoidable and common for whole iface).

The patch also fixes a bug when removing last address does not send
preferred address change notification.
2018-11-28 16:55:32 +01:00
Ondrej Zajicek (work)
66934aceff Autoconf: Minor cleanup 2018-11-21 16:30:22 +01:00
Ondrej Zajicek (work)
fc1b933304 MRT documentation 2018-11-21 16:00:22 +01:00
Ondrej Zajicek (work)
863ecfc785 The MRT protocol
The new MRT protocol is responsible for periodic RIB table dumps in the
MRT format (RFC 6396). Also the existing code for BGP4MP MRT dumps is
refactored and splitted between BGP to MRT protocols, will be more
integrated into MRT in the future.

Example:

protocol mrt {
        table "*";
        filename "%N_%F_%T.mrt";
        period 60;
}

It is partially based on the old MRT code from Pavel Tvrdik.
2018-11-20 17:45:35 +01:00
Ondrej Zajicek (work)
6712e77271 Unix: Implement log file size limit / log rotation
Allow to specify log file size limit and ensure that log file is rotated
to secondary name to avoid exceeding of log size limit.

The patch also fixes a bug related to keeping old fds open after
reconfiguration and using old fds after 'configure undo'.
2018-11-18 14:03:50 +01:00
Ondrej Zajicek (work)
c68ba7d093 Unix: Refactor tracked files
We need access to resource in order to free it.
2018-11-18 14:03:50 +01:00
Ondrej Zajicek (work)
d0b4597842 Configure: Use standard --runstatedir option
Newer Autoconf defines --runstatedir option for setting directory for
run-time variable data. Use it instead our old --with-runtimedir.
2018-11-18 01:22:09 +01:00
Ondrej Zajicek (work)
f2d8e6801e Filter: Make ifname attribute modifiable
Allow to change an interface associated with a route by setting
ifname attribute. It will also change the route to a direct one.
2018-11-05 22:03:21 +01:00
Ondrej Zajicek (work)
69b2f63d9a Nest: Fix crash in rta_show() for RPKI and Babel routes
Some new route source values did not have associated string
in rta_show(), which might caused crash in some cases.
2018-11-05 13:56:59 +01:00
Ondrej Zajicek (work)
e19d08055a BGP: Fix VRF for listening socket
Listening socket should be bound to specified interface and VRF.

Thanks to Alexander Zubkov for the bugreport.
2018-10-26 19:11:33 +02:00
Ondrej Zajicek (work)
0ac9cb2c1f OSPF: Fix some trace messages
Missing argument in MTU change trace message can crash bird when MTU
change happens and trace messages are active.

Thanks to Alexander Velkov for the bugreport.
2018-10-25 17:22:37 +02:00
Ondrej Zajicek (work)
df50598f1c Lib: Force output type in ip4_addr constructor
Fixes type issue when u64 is pushed into it.
2018-10-25 12:39:13 +02:00
Ondrej Zajicek (work)
83715aa829 Filter: Add support for VPN_RD sets 2018-10-25 11:26:58 +02:00
Ondrej Zajicek (work)
41b83e52f7 Filter: Fix minor bug in accessing bgp_path
Not relevant for regular BGP paths, just for BGP paths added by filters
to e.g. static routes.
2018-10-25 11:23:15 +02:00
Ondrej Zajicek (work)
01dd78f9e9 Fix installation with --disable-client
The old check assumed that @CLIENT@ does not contain
birdc, which is not true in 2.0 branc.

Thanks to Thomas Petazzoni for the bugreport and original patch.
2018-10-11 15:03:09 +02:00
Ondrej Zajicek (work)
addb1bcd86 Nest: Fix 'show interfaces summary' command
The command showed interfaces that were removed / in shutdown.
2018-10-11 14:39:13 +02:00
Ondrej Zajicek (work)
961671c0f5 Lib: Add and use ev_new_init() 2018-10-01 15:55:23 +02:00
Ondrej Zajicek (work)
0db7a1d69c BGP: Fix bug in show protocol related to LLGR
When channel is not active due to not be negotiated during sessino
establishment, the LLGR timer is not allocated, so we should not show it.
2018-10-01 15:35:43 +02:00
Jan Maria Matejka
d4cebc6bbe No more warnings ...
no more warnings
No more warnings over me
And while it is being compiled all the log is black and white
Release BIRD now and then let it flee

(use the melody of well-known Oh Freedom!)
2018-09-18 14:21:11 +02:00
Jan Maria Matejka
d50b0bc437 Conf: Show the line:char position where the syntax error happens 2018-09-11 17:35:13 +02:00
Jan Maria Matejka
89b0af3978 Main: Add -b to force background even in debug mode 2018-08-28 16:48:52 +02:00
Ondrej Zajicek (work)
a043f2d794 Doc: Fix description of 'description'
Thanks to Clemens Schrimpe for the bugreport.
2018-08-24 18:58:06 +02:00
Jan Maria Matejka
64c5ad58d2 Lib: recursive printf
Use like this:

void func(const char *msg, va_list args) {
  ...
  bvsnprintf(buf, len, "file %s, line %d: %V (foo %d, bar %d)", file, line, msg, &args, foo, bar);
  ...
}
2018-08-22 15:14:06 +02:00
Ondrej Zajicek (work)
765f400f6b DOC: Remove pipe mode reference
Pipe mode was removed in 2.0, remove reference to it in the documentation.

Thanks to Piotr Wydrych for the bugreport.
2018-08-21 15:24:55 +02:00
Jan Maria Matejka
7ffc0a6534 Bison: A bit more verbose error messages in config. 2018-08-14 14:36:44 +02:00
Jan Maria Matejka
78ca6ea8f0 Make: Add option to force colors in compiler output 2018-08-14 14:01:39 +02:00
Jan Maria Matejka
86b9e8e39a M4: generate synchronization lines
This also includes Bison version check. Versions before 3.0 don't
support them in a reliable way and we don't promise to work with
versions older than 2.4.
2018-08-14 14:01:39 +02:00
Pavel Tvrdik
1279a83103 sysdep/unix/main.c: Remove trailing spaces 2018-08-13 14:10:00 +02:00
Ondrej Zajicek (work)
d33cf3f4c3 Doc: Fix notes related to obsolete option
Thanks to Julien Dessaux for the report.
2018-08-07 14:46:24 +02:00
Ondrej Zajicek (work)
5bd734317c BGP: Long-lived graceful restart
The patch implements long-lived graceful restart for BGP, namely
draft-uttaro-idr-bgp-persistence-03.
2018-07-31 18:40:38 +02:00
Ondrej Zajicek (work)
318acb0f6c BSD: Use MSG_DONTROUTE for unicast packets on FreeBSD
BSD systems cannot use SO_DONTROUTE, because it does not work properly
with multicast packets (perhaps it tries to find iface based on multicast
group address). But we can use MSG_DONTROUTE sendmsg() flag for unicast
packets. Works on FreeBSD, is ignored on OpenBSD and is broken on NetBSD
(i guess due to integrated routing table and ARP table).
2018-07-28 16:54:06 +02:00
Ondrej Zajicek (work)
0ed3129f6b RAdv: Fix crash during prefix change
Thanks to Julian Schuh for the bugreport.
2018-07-19 20:54:55 +02:00
Ondrej Zajicek (work)
8bd718b3ba OSPF: Fix crash during route removal
The bug was introduced by an earler patch which removed additional eattr
argument to rt_notify hook.
2018-07-19 20:48:13 +02:00
Ondrej Zajicek (work)
092c493027 Nest: Fix race condition during reconfiguration, part 2
If export filter is changed during reconfiguration and a route disappears
between reconfiguration and refeed (e.g., if the route is a static route
also removed during the reconfiguration), the route is not withdrawn.

The issue was fixed for regular channels by an earlier patch. This patch
fixes the issue for channels in RA_ACCEPTED mode (first-pass-the-filter),
used by BGP with 'secondary' option.
2018-07-06 02:04:45 +02:00
Ondrej Zajicek (work)
7b9b0c0a00 Cleanup some warnings 2018-07-03 18:08:35 +02:00
Ondrej Zajicek (work)
a81e18da25 Nest: Fix race condition during reconfiguration
If export filter is changed during reconfiguration and a route disappears
between reconfiguration and refeed (e.g., if the route is a static route
also removed during the reconfiguration), the route is not withdrawn.
The patch fixes that by adding tx reconfiguration timestamp.
2018-07-03 18:00:52 +02:00
Ondrej Zajicek (work)
8e86ffce82 BGP: Use implicit-NULL label when announcing MPLS routes with local next-hop
We currently cannot assing local labels, but we can still be LSP egress
router. Therefore when we announce labeled route with local next-hop, we
should announce implicit-NULL label instead of rejecting it completely.
2018-07-01 01:03:16 +02:00
Ondrej Zajicek (work)
93c1defdb0 BGP: Fix parsing of MPLS withdrawals
RFC 3107 was bit vague with regard to labeled withdrawals, RFC 8277
clarified that. The old code was incompatible with some implementations,
namely with Juniper.

Thanks to Vadim Fedorenko for the original patch.
2018-07-01 00:43:24 +02:00
Maria Jan Matejka
daf113ac66 BGP: Attribute set function merged with its common counterpart 2018-06-29 17:26:28 +02:00
Ondrej Zajicek (work)
d8e816c150 BSD: Fix of the previous commit 2018-06-27 17:10:01 +02:00
Ondrej Zajicek (work)
586c1800c4 Nest: Neighbor cache cleanups
Simplify neighbor cache code, fix several minor bugs, and improve
handling of ONLINK flag.
2018-06-27 16:57:07 +02:00
Maria Matejka
45f28d8581 Autotools: updated config.guess and config.sub
Updated to version 63b4ce2e8c28aee6a32133e400436e4ca885215a
from git://git.savannah.gnu.org/config.git

Previous version was 93b5037172b15ad28952481933517f1ba93d125b
2018-06-26 17:14:16 +02:00
Maria Matejka
da16b33ab9 Android: check for extra libs needed for build 2018-06-26 17:11:27 +02:00
Maria Matejka
c2fc4c10ac Doc: renamed progdoc files Doc -> progdoc to fix collision with doc/ folder on case-insensitive filesystems 2018-06-26 17:09:12 +02:00
Jan Maria Matejka
f851f0d7e3 Config: Dropping CF_ADDTO. 2018-06-26 14:29:03 +02:00
Jan Maria Matejka
1771f70d74 Filter: fixed eattr cached pointer
Use ACCESS_RTE to guard **f_rte, use ACCESS_EATTRS to guard **f_eattrs.
Use f_rta_cow() before writing to rta or eattrs, use f_rte_cow() before
writing preference (stored in rte).

Do not access eattrs indirectly through (*f_rte)->attrs->eattrs, it is
way too slow. The cached pointer is faster.
2018-06-19 16:51:40 +02:00
Jan Maria Matejka
1ef23f05ee Merge branch 'int-new' into HEAD 2018-06-19 14:32:16 +02:00
Ondrej Zajicek (work)
caa9d03d65 Babel: Fix handling of missing IPv4 next hops
In case of missing IPv4 next hop, we should skip such routes
on transmit and ignore such routes on receive.

Thanks to Julian Schuh for the bugreport and Toke Hoiland-Jorgensen
for the original patch.
2018-06-13 15:22:29 +02:00
Ondrej Zajicek (work)
9c9050ff12 BGP: Handle missing NEXT_HOP attribute properly
RFC 7606 specifies handle-as-withdraw instead of session reset.
2018-06-13 14:47:37 +02:00
Jan Maria Matejka
13c0be19d3 Nest: Removing separate tmpa from route propagation
This is a fundamental change of an original (1999) concept of route
processing inside BIRD. During import/export, there was a temporary
ea_list created which was to be used instead of the another one inside
the route itself.

This led to some confusion, quirks, and strange filter code that handled
extended route attributes. Dropping it now.

The protocol interface has changed in an uniform way -- the
`struct ea_list *attrs` argument has been removed from store_tmp_attrs(),
import_control(), rt_notify() and get_route_info().
2018-05-30 17:08:49 +02:00
Ondrej Zajicek (work)
18b4f2082c OSPF: Fix invalid NSSA RFC references 2018-05-29 14:23:14 +02:00
Jan Maria Matejka
ee7e2ffd26 Protocol: Introducing an enum protocol_class
This supersedes the EAP_* constants.
2018-05-29 12:35:06 +02:00
Jan Maria Matejka
c3becfe193 Filter: macro for recursive interpretation of instructions 2018-05-29 12:35:06 +02:00
Jan Maria Matejka
0ec6b5ecd3 Filter: Simple type checks converted to ARG() macro 2018-05-29 12:35:06 +02:00
Jan Maria Matejka
478f9babed Filter: Removing the third argument hack
Just to make the code a bit more clean and easier to maintain.
2018-05-29 11:53:51 +02:00
Jan Maria Matejka
cff9e937fd Filter: instruction names 2018-05-29 11:53:51 +02:00
Jan Maria Matejka
31d6939cde Filter: Instruction codes linearized 2018-05-29 11:53:51 +02:00
Jan Maria Matejka
906092534b Macro: Added a bunch of dirty C preprocessor tricks
Included are Makefile implicit rules to show the preprocessed source.
When debugging something around this, it may be handy.
2018-05-29 11:53:51 +02:00
Ondrej Zajicek (work)
feae132e0f Do not initialize route metrics in import_control hook
During route export, the receiving protocol often initialized route
metrics to default value in its import_control hook before export filter
was executed. This is inconsistent with the expectation that an export
filter would process the same route as one in the routing table and it
breaks setting these metrics before (e.g. for static routes directly in
static protocol).

The patch removes the initialization of route metrics in import_control
hook, the default values are already handled in rt_notify hook called
after export filters.

The patch also changed the behavior of OSPF to keep metrics when a route
is reannounced between OSPF instances (to be consistent with other
protocols) and the behavior when both ospf_metric1 and ospf_metric2
are specified (to have more expected behavior).
2018-05-24 14:51:05 +02:00
Ondrej Zajicek (work)
b24b781117 Filter: Add support for src filter op to access SADR source prefix
The patch allows to use 'net.src' to access SADR source prefix
from filters.

Thanks to Toke Hoiland-Jorgensen for the original patch for srclen.
2018-05-16 11:19:29 +02:00
Ondrej Zajicek (work)
eaf63d314d Better initialization of random generator
Use full time precision to initialize random generator. The old
code was prone to initialize it to the same values in specific
circumstances (boot without RTC, multiple VMs starting at once).
2018-05-03 17:07:39 +02:00
Ondrej Zajicek (work)
70fab17837 Babel: Add option to randomize router ID
When a Babel node restarts, it loses its sequence number, which can cause
its routes to be rejected by peers until the state is cleared out by other
nodes in the network (which can take on the order of minutes).

There are two ways to fix this: Having stable storage to keep the sequence
number across restarts, or picking a different router ID each time.

This implements the latter, by introducing a new option that will cause
BIRD to randomize a high 32 bits of router ID every time it starts up.
This avoids the problem at the cost of not having stable router IDs in
the network.

Thanks to Toke Hoiland-Jorgensen for the patch.
2018-05-03 16:55:11 +02:00
Ondrej Zajicek (work)
23b079043b Babel: Fix type of route entry router ID
The router ID being assigned to routes was a uint, which discards the
upper 32 bits. This also has the nice side effect of echoing the wrong
router ID back to other routers.

Thanks to Toke Hoiland-Jorgensen for the patch.
2018-05-03 16:02:29 +02:00
Jan Maria Matejka
29958745c8 Makefile: Only set git version if BIRD is build from its repository.
Thanks to Toke Høiland-Jørgensen <toke@toke.dk> for reporting this bug.
2018-05-03 11:14:49 +02:00
Jan Maria Matejka
823ad12191 Filter: Added missing instruction comparators.
These instructions caused SIGABORTs on reconfiguration.
2018-04-27 14:38:41 +02:00
Ondrej Zajicek (work)
4727d1db9d OSPF: Support of authentication trailer for OSPFv3
Implement RFC 7166, crypthographic authentication for OSPFv3
analogous to authentication used for OSPFv2.
2018-04-25 15:54:53 +02:00
Ondrej Zajicek (work)
f3a8cf050e BGP: Fix extended next hop handling
For IPv4 with extended next hop, we use MP-BGP format and therefore no
independent NEXT_HOP attribute.

Thanks to Arvin Gan for the bugreport.
2018-04-12 16:55:56 +02:00
Ondrej Zajicek (work)
c408d807a3 Doc: Documentation for BGP disable after cease option 2018-04-03 17:31:45 +02:00
Ondrej Zajicek (work)
a63d20aa87 Doc: Documentation for BGP extended next hop feature
Thanks to Arvin Gan for the bugreport.
2018-04-03 16:53:58 +02:00
Ondrej Zajicek (work)
157f6c2aad Doc: Remove some superfluous slashes 2018-03-24 02:05:47 +01:00
Ondrej Filip
6807320a0f Autoconf replaced by autoreconf 2018-03-23 17:24:58 +01:00
Ondrej Filip
4d3d34f599 Date added. 2018-03-22 13:30:10 +01:00
Ondrej Filip
966602602a Merge branch 'int-new' of ssh://gitlab.labs.nic.cz/labs/bird into int-new 2018-03-22 13:25:58 +01:00
Ondrej Zajicek (work)
4841804fff NEWS and version update 2018-03-21 16:33:08 +01:00
Ondrej Zajicek (work)
a177e4dd04 Doc: Minor update 2018-03-21 16:33:08 +01:00
Ondrej Zajicek (work)
3b522a1e5c Doc: Redesign default config file
The old one does not work with 2.0.x.
2018-03-20 19:28:26 +01:00
Ondrej Zajicek (work)
89ac4dd3c4 Merge remote-tracking branch 'birdlab-tmp/int-new' into int-new 2018-03-19 13:29:39 +01:00
Ondrej Zajicek (work)
bcb4af81fc Nest: Fix table reconfiguration when nettype changes
Thanks to Toke Hoiland-Jorgensen for the bugreport.
2018-03-18 13:48:47 +01:00
Ondrej Zajicek (work)
364d5823ea Nest: SADR support for Direct 2018-03-18 02:56:51 +01:00
Ondrej Zajicek (work)
159d619caf Doc: SADR documentation 2018-03-17 22:25:06 +01:00
Ondrej Zajicek (work)
7a8ae228f9 Doc: Update BGP documentation
Thanks to Joshua McQuistan for the bugreport.
2018-03-17 17:14:38 +01:00
Jan Maria Matejka
8a871e890a Merge branch 'master' into int-new 2018-03-14 12:57:16 +01:00
Jan Maria Matejka
e8bc64e308 Filter: make bgpmask literals real constructors
The bgpmask literals can include expressions. This is OK but they have
to be interpreted as soon as the code is run, not in the time the code
is used as value.

This led to strange behavior like rewriting bgpmasks when they shan't
be rewritten:

	function mask_generator(int as)
	{
		return [= * as * =];
	}

	function another()
	bgpmask m1;
	bgpmask m2;
	{
		m1 = mask_generator(10);
		m2 = mask_generator(20);
		if (m1 == m2) {
			print("strange"); # this would happen
		}
	}

Moreover, sending this to CLI would cause stack overflow and knock down the
whole BIRD, as soon as there is at least one route to execute the given
filter on.

	show route filter bgpmask mmm; bgppath ppp; { ppp = +empty+; mmm = [= (ppp ~ mmm) =]; print(mmm); accept; }

The magic match operator (~) inside the bgpmask literal would try to
resolve mmm, which points to the same bgpmask so it would resolve
itself, call the magic match operator and vice versa.

After this patch, the bgpmask literal will get resolved as soon as it's
assigned to mmm and it also will return a type error as bool is not
convertible to ASN in BIRD.
2018-03-14 11:34:29 +01:00
Jan Maria Matejka
e95705f00c Merge branch 'master' into int-new 2018-03-13 17:02:49 +01:00
Jan Maria Matejka
74bfd2f97c Filters: Removed FI_COMMA, not used for 19 years.
This instruction was removed in the commit linked below
and never used ever again. Rest in peace.

commit 84c7e1943f0dbf896b1dd8d02a21120aa00463f4
Author: Pavel Machek <pavel@ucw.cz>
Date:   Tue Mar 2 19:49:28 1999 +0000
2018-03-13 17:01:37 +01:00
Jan Maria Matejka
d1ba927b36 Merge branch 'master' into int-new 2018-03-13 16:51:04 +01:00
Jan Maria Matejka
7c601e6b7b Filter: recursion to loop
It was supposed to do tail-recursion in interpret() but it didn't
compile as such. Converting it to loop makes a significant filter
performance improvement for flat filters.
2018-03-13 16:29:33 +01:00
Maria Jan Matejka
5a14df3950 Filter: Instruction codes named as enum
The two-letter instructions were quite messy but they could be easily
read from memory dumps. Now GDB (since 2012) supports pretty printing
enum values and GCC checks the switch construction for missing enum
values so we are converting the nice two-byte values to enums.

Anyway, the enum still keeps the old two-byte values to be able to read
the instruction codes even without GDB from plain memory dump.
2018-03-13 16:29:33 +01:00
Jan Maria Matejka
f2f5a7d945 Filter: the test conf checks also a bit of BGP args
Uncommented an old test.
2018-03-08 12:57:39 +01:00
Jan Maria Matejka
0575c7db72 Config: Dropped the ipv4:netmask4 syntax for IPv4 prefixes. 2018-03-08 12:57:39 +01:00
Ondrej Zajicek (work)
d0f47327f8 Merge branch 'master' into int-new 2018-03-07 17:41:49 +01:00
Ondrej Zajicek (work)
2d6d4b8053 Babel: Fix build with restricted protocol set
All keywords used in Babel config have to be declared locally.

Thanks to Leo Vandewoestijne for the bugreport.
2018-03-07 17:35:24 +01:00
Ondrej Filip
4406281260 Merge branch 'int-new' of ssh://gitlab.labs.nic.cz/labs/bird into int-new 2018-02-27 06:08:03 +01:00
Ondrej Zajicek (work)
1561ee799c Handle properly enums for extended attributes 2018-02-13 19:52:22 +01:00
Ondrej Zajicek (work)
d5144ea9bf Add cscope Makefile target
For those who prefer cscope to etags

Thanks to Toke Hoiland-Jorgensen for the patch.
2018-02-13 17:00:24 +01:00
Ondrej Zajicek (work)
5ce7adfcf9 Babel: Fix accidental bitwise or assignment
Fix an accidental bitwise or assignment that was supposed to be a
comparison.

Thanks to Toke Hoiland-Jorgensen for the patch.
2018-02-13 16:42:03 +01:00
Ondrej Zajicek (work)
185a0a51f8 Babel: Add source-specific routing support
This patch adds support for source-specific routing to the Babel protocol.
It changes the protocol to support both NET_IP6 and NET_IP6_SADR channels
for IPv6 addresses. If only a NET_IP6 channel is configured,
source-specific updates are ignored. Otherwise, non-source-specific
routes are simply treated as source-specific routes with SADR prefix 0.

Thanks to Toke Hoiland-Jorgensen for the original patch.
Minor changes by Ondrej Santiago Zajicek.
2018-02-13 16:40:14 +01:00
Ondrej Zajicek (work)
be17805c0b Add support for source-specific IPv6 routes to BIRD core
This patch adds support for source-specific IPv6 routes to BIRD core.
This is based on Dean Luga's original patch, with the review comments
addressed. SADR support is added to network address parsing in confbase.Y
and to the kernel protocol on Linux.

Currently there is no way to mix source-specific and non-source-specific
routes (i.e., SADR tables cannot be connected to non-SADR tables).

Thanks to Toke Hoiland-Jorgensen for the original patch.
Minor changes by Ondrej Santiago Zajicek.
2018-02-13 16:39:07 +01:00
Ondrej Zajicek (work)
a82f692e58 Nest: Trivial whitespace cleanup 2018-02-07 17:12:33 +01:00
Ondrej Zajicek (work)
28b3b55122 KRT: Fix IPv6 route learn
Internal table used for route learn was created with non-matching net
type for IPv6 kernel proto.

Thanks to Toke Hoiland-Jorgensen for the bugreport
2018-02-06 16:08:45 +01:00
Ondrej Zajicek (work)
85ad5855a0 Nest: Fix corner case in recursive next hop lookup
Thanks to Svenne Krap for the bugreport.
2018-01-29 12:49:37 +01:00
Ondrej Zajicek (work)
345e50d59f Nest: remove duplicate function 2018-01-24 13:55:12 +01:00
Ondrej Zajicek (work)
75d98b6013 Merge branch 'master' into int-new 2018-01-23 18:29:32 +01:00
Ondrej Zajicek (work)
d6cf996151 IO: Fix socket priority
On Linux, setting the ToS will also set the priority and the range of
accepted values is quite limited (masked by 0x1e). Therefore, 0xc0 is
translated to a priority of 0, not something we want, overriding the
"7" priority which was set previously explicitely. To avoid that, just
move setting priority later in the code.

Thanks to Vincent Bernat for the patch.
2018-01-23 17:05:45 +01:00
Ondrej Zajicek (work)
ace3072e09 KRT: Fix option 'merge paths' 2018-01-23 15:12:43 +01:00
Ondrej Zajicek (work)
e5ff7929c4 KRT: Remove useless option 2018-01-23 14:48:07 +01:00
Ondrej Zajicek (work)
def6efa1ef Doc: Fix example 2018-01-23 14:26:18 +01:00
Jan Maria Matejka
8adaf730c0 Pipe: show export state 2018-01-23 13:52:17 +01:00
Jan Maria Matejka
c591810d46 Pipe: fixed template bug
When pipe inherited from template, every channel config was lost.
2018-01-23 13:52:01 +01:00
Ondrej Zajicek (work)
63472779ad BGP: Implement 'disable after cease' option
The option allows to specify that some cease subcodes should
disable the protocol when received.
2018-01-16 19:17:04 +01:00
Ondrej Zajicek (work)
b940579115 Filter: Allow silent filter execution
A filter should log messages only if executed explicitly (e.g., during
route export or route import). When a filter is executed for technical
reasons (e.g., to establish whether a route was exported before), it
should run silently.
2018-01-16 16:20:01 +01:00
Ondrej Filip
6f46465af1 Error in version guessing 2018-01-16 14:36:46 +01:00
Ondrej Zajicek (work)
c2febfa332 Add note to NEWS 2018-01-16 14:18:57 +01:00
Ondrej Filip
68d0048b3d Notice about RFC 8212 added 2018-01-16 10:45:03 +01:00
Ondrej Zajicek (work)
3831b61966 BGP: Require explicit import and export policies for EBGP channels
To comply with RFC 8212 requirements.
2018-01-16 04:14:49 +01:00
Ondrej Zajicek (work)
4db4ac7243 NEWS and version update 2018-01-14 21:52:58 +01:00
Ondrej Zajicek (work)
4d36796131 KRT: Fix direct routes for BSD
Old way to set direct routes is to use local IP as gateway, but that does
not work properly on newer FreeBSDs. Now we use sockaddr_dl containing
interface index as gateway.
2018-01-14 19:21:39 +01:00
Ondrej Zajicek (work)
2e507a7457 Use non-fatal asserts even for regular build 2018-01-10 16:17:37 +01:00
Ondrej Zajicek (work)
72163bd5f3 Nest: Allow modification of channels inherited from templates
Multiple definitions of same channels are forbidden, but inherited
channel can be redefined. In such case channel options are merged.
2018-01-09 18:42:22 +01:00
Jan Maria Matejka
09c1e370b3 Moved freebsd cflags and ldflags to configure 2018-01-09 16:46:00 +01:00
Ondrej Zajicek (work)
94f9be80c3 Nest: Fix filter reconfiguration
Function filter_same() must be called with arguments in proper order,
otherwise it breaks the new filter, causing crash during route
processing.
2018-01-09 14:36:11 +01:00
Ondrej Zajicek (work)
8f8671bcde Filter: Handle undefined BGP paths as empty
The same is already done for clists. Also fixes defined() to work
properly for paths and clists.
2018-01-03 15:44:05 +01:00
Ondrej Zajicek (work)
0ff86d054e ROA: Fix reconfiguration 2018-01-03 14:12:00 +01:00
Ondrej Zajicek (work)
9bd8cb7c3c Merge branch 'master' into int-new 2018-01-02 16:59:59 +01:00
Ondrej Zajicek (work)
d493d0f180 BGP: Fix unknown attribute handling 2018-01-02 16:57:45 +01:00
Ondrej Zajicek (work)
e62cd03307 BGP: Fix graceful restart timer
Should use remote value, not local value.
2018-01-02 14:30:08 +01:00
Ondrej Zajicek (work)
cce6ba4daa Remove libhistory check
According to GNU Readline developers, if we link with libreadline then
there is no need to link with libhistory at all.
2018-01-02 14:11:59 +01:00
Ondrej Zajicek (work)
4842eeaad3 Minor fix in documentation 2017-12-21 00:16:52 +01:00
Ondrej Zajicek (work)
a63e78c31a Fix build without limited protocol set 2017-12-18 23:15:07 +01:00
Ondrej Zajicek (work)
e87a95d97d Minor fixes for debug mode 2017-12-16 16:31:43 +01:00
Ondrej Zajicek (work)
3013fc57bd Netlink: Fix memory leak 2017-12-16 00:42:56 +01:00
Ondrej Zajicek (work)
8396094156 Minor cleanups 2017-12-14 22:15:01 +01:00
Ondrej Zajicek (work)
abd4367f48 Minor cleanup 2017-12-14 21:52:07 +01:00
Ondrej Zajicek (work)
c36a298c21 Use git describe for BIRD version
Based on patch from Pavel Tvrdik
2017-12-13 19:18:30 +01:00
Ondrej Zajicek (work)
d807ea087f BGP: Fix non-transitive ext communities 2017-12-13 15:57:44 +01:00
Ondrej Zajicek (work)
3e7923507b Netlink: Use linpool instead of static buffer 2017-12-13 15:27:33 +01:00
Ondrej Zajicek (work)
772beb7308 Lib: Minor fix 2017-12-13 15:27:33 +01:00
Jan Maria Matejka
cb21c5ffa9 Merge branch 'int-new' of gitlab.labs.nic.cz:labs/bird into int-new 2017-12-13 10:29:10 +01:00
Jan Maria Matejka
71c51aa4ab Doc: Fixed misc sgml bugs, no content change 2017-12-13 10:28:50 +01:00
Ondrej Zajicek (work)
1e11918c8c Lib: Save/restore state for linpools
Also change linpool.current ptr to really point to thr current chunk.
2017-12-12 19:57:52 +01:00
Ondrej Zajicek (work)
ac48e72bf6 Fix some minor issues 2017-12-12 15:57:14 +01:00
Ondrej Zajicek (work)
cb5df823ac Minor CI tweak 2017-12-12 15:22:36 +01:00
Ondrej Filip
b5257bea85 Removed '--enable-ipv6' reference. 2017-12-12 10:43:56 +01:00
Ondrej Zajicek (work)
66acbc8d7f Revive FIB and kernel MPLS code 2017-12-12 00:05:49 +01:00
218 changed files with 19569 additions and 8013 deletions

7
.dir-locals.el Normal file
View File

@ -0,0 +1,7 @@
; BIRD project coding conventions
((c-mode
(c-file-style . "bsd")
(c-basic-offset . 2)
(fill-column . 80)
(show-trailing-whitespace . t)))

57
.drone.yml Normal file
View File

@ -0,0 +1,57 @@
---
kind: pipeline
type: docker
name: deploy
steps:
- name: build alpine
image: c8n.io/simonburblecom/bird-build:alpine
commands:
- /build.sh
- name: build ubuntu
image: c8n.io/simonburblecom/bird-build:ubuntu
commands:
- /build.sh
- name: upload
image: plugins/s3
settings:
bucket: artifacts
access_key:
from_secret: MINIO_ACCESS_KEY
secret_key:
from_secret: MINIO_SECRET_KEY
endpoint: https://minio.burble.dn42
region: uk-lon3
path_style: true
source: artifacts/**/*
strip_prefix: artifacts/
target: /bird/${DRONE_BRANCH}
image_pull_secrets:
- CONFIG_JSON
---
kind: secret
name: CONFIG_JSON
get:
path: burble.dn42/kv/data/drone/docker
name: configjson
---
kind: secret
name: MINIO_ACCESS_KEY
get:
path: burble.dn42/kv/data/drone/minio
name: ACCESS_KEY
---
kind: secret
name: MINIO_SECRET_KEY
get:
path: burble.dn42/kv/data/drone/minio
name: SECRET_KEY

2
.gitignore vendored
View File

@ -1,5 +1,4 @@
/autom4te.cache/
/doc/*.html
/obj/
/Makefile
/bird
@ -12,3 +11,4 @@
/configure
/sysdep/autoconf.h.in
/sysdep/autoconf.h.in~
/cscope.*

View File

@ -4,10 +4,12 @@ variables:
GIT_STRATEGY: fetch
DOCKER_CMD: docker --config="$HOME/.docker/$CI_JOB_ID/"
IMG_BASE: registry.labs.nic.cz/labs/bird
TOOLS_DIR: /var/lib/gitlab-runner/bird-tools
stages:
- image
- build
- test
.docker: &docker_build
stage: image
@ -34,36 +36,46 @@ docker_debian-7-amd64:
IMG_NAME: "debian-7-amd64"
<<: *docker_build
docker_debian-8-amd64:
variables:
IMG_NAME: "debian-8-amd64"
<<: *docker_build
docker_debian-9-amd64:
variables:
IMG_NAME: "debian-9-amd64"
<<: *docker_build
docker_debian-testing-amd64:
variables:
IMG_NAME: "debian-testing-amd64"
<<: *docker_build
docker_debian-7-i386:
variables:
IMG_NAME: "debian-7-i386"
<<: *docker_build
docker_debian-8-amd64:
variables:
IMG_NAME: "debian-8-amd64"
<<: *docker_build
docker_debian-8-i386:
variables:
IMG_NAME: "debian-8-i386"
<<: *docker_build
docker_debian-9-amd64:
variables:
IMG_NAME: "debian-9-amd64"
<<: *docker_build
docker_debian-9-i386:
variables:
IMG_NAME: "debian-9-i386"
<<: *docker_build
docker_debian-10-amd64:
variables:
IMG_NAME: "debian-10-amd64"
<<: *docker_build
docker_debian-10-i386:
variables:
IMG_NAME: "debian-10-i386"
<<: *docker_build
docker_debian-testing-amd64:
variables:
IMG_NAME: "debian-testing-amd64"
<<: *docker_build
docker_debian-testing-i386:
variables:
IMG_NAME: "debian-testing-i386"
@ -79,9 +91,29 @@ docker_fedora-26-amd64:
IMG_NAME: "fedora-26-amd64"
<<: *docker_build
docker_centos-6-amd64:
docker_fedora-27-amd64:
variables:
IMG_NAME: "centos-6-amd64"
IMG_NAME: "fedora-27-amd64"
<<: *docker_build
docker_fedora-28-amd64:
variables:
IMG_NAME: "fedora-28-amd64"
<<: *docker_build
docker_fedora-29-amd64:
variables:
IMG_NAME: "fedora-29-amd64"
<<: *docker_build
docker_fedora-30-amd64:
variables:
IMG_NAME: "fedora-30-amd64"
<<: *docker_build
docker_fedora-31-amd64:
variables:
IMG_NAME: "fedora-31-amd64"
<<: *docker_build
docker_centos-7-amd64:
@ -89,131 +121,44 @@ docker_centos-7-amd64:
IMG_NAME: "centos-7-amd64"
<<: *docker_build
docker_opensuse-42_3-amd64:
docker_centos-8-amd64:
variables:
IMG_NAME: "opensuse-42.3-amd64"
IMG_NAME: "centos-8-amd64"
<<: *docker_build
docker_ubuntu-14_04-amd64:
variables:
IMG_NAME: "ubuntu-14.04-amd64"
<<: *docker_build
docker_ubuntu-16_04-amd64:
variables:
IMG_NAME: "ubuntu-16.04-amd64"
<<: *docker_build
.debian-7-i386: &debian-7-i386_env
image: registry.labs.nic.cz/labs/bird:debian-7-i386
tags:
- docker
- linux
- amd64
.debian-8-i386: &debian-8-i386_env
image: registry.labs.nic.cz/labs/bird:debian-8-i386
tags:
- docker
- linux
- amd64
.debian-9-i386: &debian-9-i386_env
image: registry.labs.nic.cz/labs/bird:debian-9-i386
tags:
- docker
- linux
- amd64
.debian-testing-i386: &debian-testing-i386_env
image: registry.labs.nic.cz/labs/bird:debian-testing-i386
tags:
- docker
- linux
- amd64
.debian-7-amd64: &debian-7-amd64_env
image: registry.labs.nic.cz/labs/bird:debian-7-amd64
tags:
- docker
- linux
- amd64
.debian-8-amd64: &debian-8-amd64_env
image: registry.labs.nic.cz/labs/bird:debian-8-amd64
tags:
- docker
- linux
- amd64
.debian-9-amd64: &debian-9-amd64_env
image: registry.labs.nic.cz/labs/bird:debian-9-amd64
tags:
- docker
- linux
- amd64
.debian-testing-amd64: &debian-testing-amd64_env
image: registry.labs.nic.cz/labs/bird:debian-testing-amd64
tags:
- docker
- linux
- amd64
.fedora-25-amd64: &fedora-25-amd64_env
image: registry.labs.nic.cz/labs/bird:fedora-25-amd64
tags:
- docker
- linux
- amd64
.fedora-26-amd64: &fedora-26-amd64_env
image: registry.labs.nic.cz/labs/bird:fedora-26-amd64
tags:
- docker
- linux
- amd64
.centos-6-amd64: &centos-6-amd64_env
image: registry.labs.nic.cz/labs/bird:centos-6-amd64
tags:
- docker
- linux
- amd64
.centos-7-amd64: &centos-7-amd64_env
image: registry.labs.nic.cz/labs/bird:centos-7-amd64
tags:
- docker
- linux
- amd64
.opensuse-42_3-amd64: &opensuse-42_3-amd64_env
image: registry.labs.nic.cz/labs/bird:opensuse-42.3-amd64
tags:
- docker
- linux
- amd64
.ubuntu-14_04-amd64: &ubuntu-14_04-amd64_env
image: registry.labs.nic.cz/labs/bird:ubuntu-14.04-amd64
tags:
- docker
- linux
- amd64
.ubuntu-16_04-amd64: &ubuntu-16_04-amd64_env
image: registry.labs.nic.cz/labs/bird:ubuntu-16.04-amd64
tags:
- docker
- linux
- amd64
# TODO We want to copy these BSDs to our own virtual machines, to make sure someone doesn't update them by accident.
.freebsd-11-i386: &freebsd-11-i386_env
docker_ubuntu-18_04-amd64:
variables:
CPPFLAGS: "-I/usr/local/include"
LDFLAGS: "-L/usr/local/lib"
IMG_NAME: "ubuntu-18.04-amd64"
<<: *docker_build
docker_ubuntu-19_10-amd64:
variables:
IMG_NAME: "ubuntu-19.10-amd64"
<<: *docker_build
docker_opensuse-15.0-amd64:
variables:
IMG_NAME: "opensuse-15.0-amd64"
<<: *docker_build
docker_opensuse-15.1-amd64:
variables:
IMG_NAME: "opensuse-15.1-amd64"
<<: *docker_build
# TODO We want to copy these BSDs to our own virtual machines, to make sure
# someone doesn't update them by accident.
.freebsd-11-i386: &freebsd-11-i386_env
tags:
- freebsd
- i386
@ -223,18 +168,11 @@ docker_ubuntu-16_04-amd64:
#- tags
.freebsd-11-amd64: &freebsd-11-amd64_env
variables:
CPPFLAGS: "-I/usr/local/include"
LDFLAGS: "-L/usr/local/lib"
tags:
- freebsd
- amd64
#only:
#- master
#- triggers
#- tags
.build: &build_job
.build: &build-base
stage: build
script:
- autoreconf
@ -243,107 +181,235 @@ docker_ubuntu-16_04-amd64:
- MAKE=make
- which gmake 2>/dev/null >/dev/null && MAKE=gmake
- $MAKE
# Run tests if they are available (eg. don't fail if "check" isn't a valid make target)
- $MAKE check || [ "$?" = 2 ]
# Run tests if they are available
- $MAKE check
.build-linux: &build-linux
<<: *build-base
tags:
- docker
- linux
- amd64
build-debian-7-amd64:
variables:
IPV6: "no"
<<: *debian-7-amd64_env
<<: *build_job
build-debian-8-amd64:
variables:
IPV6: "no"
<<: *debian-8-amd64_env
<<: *build_job
build-debian-9-amd64:
variables:
IPV6: "no"
<<: *debian-9-amd64_env
<<: *build_job
build-debian-testing-amd64:
variables:
IPV6: "no"
<<: *debian-testing-amd64_env
<<: *build_job
build-fedora-25-amd64:
variables:
IPV6: "no"
<<: *fedora-25-amd64_env
<<: *build_job
build-fedora-26-amd64:
variables:
IPV6: "no"
<<: *fedora-26-amd64_env
<<: *build_job
build-centos-6-amd64:
variables:
IPV6: "no"
<<: *centos-6-amd64_env
<<: *build_job
build-centos-7-amd64:
variables:
IPV6: "no"
<<: *centos-7-amd64_env
<<: *build_job
build-opensuse-42_3-amd64:
variables:
IPV6: "no"
<<: *opensuse-42_3-amd64_env
<<: *build_job
build-ubuntu-14_04-amd64:
variables:
IPV6: "no"
<<: *ubuntu-14_04-amd64_env
<<: *build_job
build-ubuntu-16_04-amd64:
variables:
IPV6: "no"
<<: *ubuntu-16_04-amd64_env
<<: *build_job
<<: *build-linux
image: registry.labs.nic.cz/labs/bird:debian-7-amd64
build-debian-7-i386:
variables:
IPV6: "no"
<<: *debian-7-i386_env
<<: *build_job
<<: *build-linux
image: registry.labs.nic.cz/labs/bird:debian-7-i386
build-debian-8-amd64:
<<: *build-linux
image: registry.labs.nic.cz/labs/bird:debian-8-amd64
build-debian-8-i386:
variables:
IPV6: "no"
<<: *debian-8-i386_env
<<: *build_job
<<: *build-linux
image: registry.labs.nic.cz/labs/bird:debian-8-i386
build-debian-9-amd64:
<<: *build-linux
image: registry.labs.nic.cz/labs/bird:debian-9-amd64
build-debian-9-i386:
variables:
IPV6: "no"
<<: *debian-9-i386_env
<<: *build_job
<<: *build-linux
image: registry.labs.nic.cz/labs/bird:debian-9-i386
build-debian-10-amd64:
<<: *build-linux
image: registry.labs.nic.cz/labs/bird:debian-10-amd64
build-debian-10-i386:
<<: *build-linux
image: registry.labs.nic.cz/labs/bird:debian-10-i386
build-debian-testing-amd64:
<<: *build-linux
image: registry.labs.nic.cz/labs/bird:debian-testing-amd64
build-debian-testing-i386:
variables:
IPV6: "no"
<<: *debian-testing-i386_env
<<: *build_job
<<: *build-linux
image: registry.labs.nic.cz/labs/bird:debian-testing-i386
build-fedora-25-amd64:
<<: *build-linux
image: registry.labs.nic.cz/labs/bird:fedora-25-amd64
build-fedora-26-amd64:
<<: *build-linux
image: registry.labs.nic.cz/labs/bird:fedora-26-amd64
build-fedora-27-amd64:
<<: *build-linux
image: registry.labs.nic.cz/labs/bird:fedora-27-amd64
build-fedora-28-amd64:
<<: *build-linux
image: registry.labs.nic.cz/labs/bird:fedora-28-amd64
build-fedora-29-amd64:
<<: *build-linux
image: registry.labs.nic.cz/labs/bird:fedora-29-amd64
build-fedora-30-amd64:
<<: *build-linux
image: registry.labs.nic.cz/labs/bird:fedora-30-amd64
build-fedora-31-amd64:
<<: *build-linux
image: registry.labs.nic.cz/labs/bird:fedora-31-amd64
build-centos-7-amd64:
<<: *build-linux
image: registry.labs.nic.cz/labs/bird:centos-7-amd64
build-centos-8-amd64:
<<: *build-linux
image: registry.labs.nic.cz/labs/bird:centos-8-amd64
build-ubuntu-14_04-amd64:
<<: *build-linux
image: registry.labs.nic.cz/labs/bird:ubuntu-14.04-amd64
build-ubuntu-16_04-amd64:
<<: *build-linux
image: registry.labs.nic.cz/labs/bird:ubuntu-16.04-amd64
build-ubuntu-18_04-amd64:
<<: *build-linux
image: registry.labs.nic.cz/labs/bird:ubuntu-18.04-amd64
build-ubuntu-19_04-amd64:
<<: *build-linux
image: registry.labs.nic.cz/labs/bird:ubuntu-19.04-amd64
build-opensuse-15.0-amd64:
<<: *build-linux
image: registry.labs.nic.cz/labs/bird:opensuse-15.0-amd64
build-opensuse-15.1-amd64:
<<: *build-linux
image: registry.labs.nic.cz/labs/bird:opensuse-15.1-amd64
build-freebsd-11-amd64:
variables:
IPV6: "no"
<<: *freebsd-11-amd64_env
<<: *build_job
<<: *build-base
tags:
- freebsd
- amd64
build-freebsd-11-i386:
<<: *build-base
tags:
- freebsd
- i386
build-birdlab:
stage: build
tags:
- birdlab
- amd64
script:
- DIR=$(pwd)
- autoreconf
- ./configure
- make
- cd $TOOLS_DIR
- sudo git clean -fx
- git pull --ff-only
- mv $DIR/bird $DIR/birdc netlab/common
.test: &test-base
stage: test
needs: [build-birdlab]
tags:
- birdlab
- amd64
script:
- cd $TOOLS_DIR/netlab
- sudo ./stop
- sudo ./runtest -m check $TEST_NAME
test-ospf-base:
<<: *test-base
variables:
IPV6: "no"
<<: *freebsd-11-i386_env
<<: *build_job
TEST_NAME: cf-ospf-base
test-ospf-default:
<<: *test-base
variables:
TEST_NAME: cf-ospf-default
test-ospf-priority:
<<: *test-base
variables:
TEST_NAME: cf-ospf-priority
test-ospf-nbma:
<<: *test-base
variables:
TEST_NAME: cf-ospf-nbma
test-ospf-ptmp:
<<: *test-base
variables:
TEST_NAME: cf-ospf-ptmp
test-ospf-authentication:
<<: *test-base
variables:
TEST_NAME: cf-ospf-authentication
test-ospf-bfd:
<<: *test-base
variables:
TEST_NAME: cf-ospf-bfd
test-ospf-custom:
<<: *test-base
variables:
TEST_NAME: cf-ospf-custom
test-ospf-vrf:
<<: *test-base
variables:
TEST_NAME: cf-ospf-vrf
test-bgp-base:
<<: *test-base
variables:
TEST_NAME: cf-bgp-base
test-bgp-auth:
<<: *test-base
variables:
TEST_NAME: cf-bgp-auth
test-bgp-int:
<<: *test-base
variables:
TEST_NAME: cf-bgp-int
test-bgp-merged:
<<: *test-base
variables:
TEST_NAME: cf-bgp-merged
test-ebgp-loop:
<<: *test-base
variables:
TEST_NAME: cf-ebgp-loop
test-ebgp-star:
<<: *test-base
variables:
TEST_NAME: cf-ebgp-star
test-ibgp-loop:
<<: *test-base
variables:
TEST_NAME: cf-ibgp-loop
test-ibgp-star:
<<: *test-base
variables:
TEST_NAME: cf-ibgp-flat

View File

@ -7,13 +7,15 @@ $ make
Default location for configuration file is /usr/local/etc/bird.conf and
for control socket is /usr/local/var/run/bird.ctl . You can change that
by --sysconfdir and --localstatedir configure options.
by --prefix, --sysconfdir and --runstatedir configure options, e.g.:
$ ./configure --prefix=/usr --sysconfdir=/etc --runstatedir=/run
To compile current development BIRD source code from Git repository, you
also need Git (to download the source code) and Autoconf (to generate
the configure script and associated files using 'autoreconf' tool):
$ git clone git://git.nic.cz/bird.git
$ git clone https://gitlab.labs.nic.cz/labs/bird/
$ cd bird
$ autoreconf
@ -32,7 +34,8 @@ For compiling BIRD you need these programs and libraries:
- Flex
- ncurses library
- GNU Readline library (2.1 or newer)
- GNU Readline library
- libssh library (optional, for RPKI-Router protocol)
For compiling BIRD documentation you also need:

View File

@ -9,6 +9,8 @@ MAKEFLAGS += -r
CPPFLAGS=-I$(objdir) -I$(srcdir) @CPPFLAGS@
CFLAGS=$(CPPFLAGS) @CFLAGS@
LDFLAGS=@LDFLAGS@
M4FLAGS=@M4FLAGS@
BISONFLAGS=@BISONFLAGS@
LIBS=@LIBS@
DAEMON_LIBS=@DAEMON_LIBS@
CLIENT_LIBS=@CLIENT_LIBS@
@ -31,12 +33,18 @@ bindir=@bindir@
sbindir=@sbindir@
sysconfdir=@sysconfdir@
localstatedir=@localstatedir@
runstatedir=@runstatedir@
docdir=@prefix@/doc
srcdir := @srcdir@
objdir := @objdir@
exedir := @exedir@
git-label:=$(strip $(shell cd $(srcdir) && [ "$$(git rev-parse --show-toplevel)" = "$$(readlink -f .)" ] && git describe --always --dirty=-x 2>/dev/null))
ifneq ($(git-label),)
CFLAGS += -DGIT_LABEL="$(git-label)"
endif
ifeq ($(objdir),.)
objdir := $(realpath .)
endif
@ -49,11 +57,16 @@ else
Q:=
endif
ifneq ($(COLOR),)
CFLAGS += -fdiagnostics-color=always
endif
# Meta rules
docgoals := docs userdocs progdocs
testgoals := check test tests tests_run
cleangoals := clean distclean testsclean
.PHONY: all daemon cli $(docgoals) $(testgoals) $(cleangoals) tags
.PHONY: all daemon cli $(docgoals) $(testgoals) $(cleangoals) tags cscope prepare
all: daemon cli
daemon: $(daemon)
@ -64,6 +77,8 @@ $(daemon): LIBS += $(DAEMON_LIBS)
# Include directories
dirs := client conf doc filter lib nest test $(addprefix proto/,$(protocols)) @sysdep_dirs@
# conf/Makefile declarations needed for all other modules
conf-lex-targets := $(addprefix $(objdir)/conf/,cf-lex.o)
conf-y-targets := $(addprefix $(objdir)/conf/,cf-parse.y keywords.h commands.h)
cf-local = $(conf-y-targets): $(s)config.Y
@ -87,30 +102,55 @@ endef
clean = $(eval $(call clean_in,$(1)))
# Include main Makefiles of the directories
include $(addsuffix /Makefile,$(addprefix $(srcdir)/,$(dirs)))
# Generic rules
$(objdir)/%.o: $(srcdir)/%.c $(objdir)/.dir-stamp $(objdir)/sysdep/paths.h
# Object file rules
$(objdir)/%.o: $(srcdir)/%.c | prepare
$(E)echo CC -o $@ -c $<
$(Q)$(CC) $(CFLAGS) -MMD -MP -o $@ -c $<
$(objdir)/%.o: $(objdir)/%.c $(objdir)/.dir-stamp $(objdir)/sysdep/paths.h
$(objdir)/%.o: $(objdir)/%.c | prepare
$(E)echo CC -o $@ -c $<
$(Q)$(CC) $(CFLAGS) -MMD -MP -o $@ -c $<
# Debug: Preprocessed source rules
$(objdir)/%.E: $(srcdir)/%.c | prepare
$(E)echo CC -o $@ -E $<
$(Q)$(CC) $(CFLAGS) -MMD -MP -o $@ -E $<
$(objdir)/%.S: $(srcdir)/%.c $(objdir)/.dir-stamp $(objdir)/sysdep/paths.h
$(objdir)/%.E: $(objdir)/%.c | prepare
$(E)echo CC -o $@ -E $<
$(Q)$(CC) $(CFLAGS) -MMD -MP -o $@ -E $<
# Debug: Assembler object rules
$(objdir)/%.S: $(srcdir)/%.c | prepare
$(E)echo CC -o $@ -S $<
$(Q)$(CC) $(CFLAGS) -MMD -MP -o $@ -S $<
$(objdir)/%.S: $(objdir)/%.c $(objdir)/.dir-stamp $(objdir)/sysdep/paths.h
$(objdir)/%.S: $(objdir)/%.c | prepare
$(E)echo CC -o $@ -S $<
$(Q)$(CC) $(CFLAGS) -MMD -MP -o $@ -S $<
# Finally include the computed dependencies:
DEPS = $(shell find $(objdir) -name '*.d')
# ## if there is at least one non-clean goal
ifneq ($(filter-out $(cleangoals),$(MAKECMDGOALS)),)
-include $(DEPS)
endif
$(objdir)/.dir-stamp:
# ## if the implicit goal is called
ifeq ($(MAKECMDGOALS),)
-include $(DEPS)
endif
# Rule for pre-generating all generated includables
# before compiling any C file
prepare: $(objdir)/sysdep/paths.h | $(objdir)/.dir-stamp
$(objdir)/.dir-stamp: Makefile
$(E)echo MKDIR -p $(addprefix $(objdir)/,$(dirs) doc)
$(Q)mkdir -p $(addprefix $(objdir)/,$(dirs) doc)
$(Q)touch $@
@ -129,7 +169,7 @@ $(objdir)/sysdep/paths.h: Makefile
tests_targets_ok = $(addsuffix .ok,$(tests_targets))
$(tests_targets): %: %.o $(tests_objs)
$(tests_targets): %: %.o $(tests_objs) | prepare
$(E)echo LD $(LDFLAGS) -o $@ $< "..." $(LIBS)
$(Q)$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
@ -144,28 +184,28 @@ check: tests tests_run
tests: $(tests_targets)
tests_run: $(tests_targets_ok)
# Finally include the computed dependencies
STATIC_CHECKERS_ENABLE := nullability.NullableDereferenced nullability.NullablePassedToNonnull nullability.NullableReturnedFromNonnull optin.portability.UnixAPI valist.CopyToSelf valist.Uninitialized valist.Unterminated
STATIC_CHECKERS_DISABLE := deadcode.DeadStores
STATIC_SCAN_FLAGS := -o $(objdir)/static-scan/ $(addprefix -enable-checker ,$(STATIC_CHECKERS_ENABLE)) $(addprefix -disable-checker ,$(STATIC_CHECKERS_DISABLE))
ifneq ($(filter-out $(cleangoals),$(MAKECMDGOALS)),)
-include $(shell find $(objdir) -name "*.d")
endif
ifeq ($(MAKECMDGOALS),)
-include $(shell find $(objdir) -name "*.d")
endif
static-scan:
$(E)echo Running static code analysis
$(Q)$(MAKE) clean
$(Q)scan-build $(STATIC_SCAN_FLAGS) $(MAKE) -$(MAKEFLAGS)
tags:
cd $(srcdir) ; etags -lc `find $(dirs) -name *.[chY]`
cd $(srcdir) ; etags -lc `find $(dirs) -name '*.[chY]'`
cscope:
cd $(srcdir) ; find $(dirs) -name '*.[chY]' > cscope.files ; cscope -b
# Install
install: all
$(INSTALL) -d $(DESTDIR)/$(sbindir) $(DESTDIR)/$(sysconfdir) $(DESTDIR)/@runtimedir@
$(INSTALL_PROGRAM) $(exedir)/bird $(DESTDIR)/$(sbindir)/bird
$(INSTALL_PROGRAM) $(exedir)/birdcl $(DESTDIR)/$(sbindir)/birdcl
if test -n "@CLIENT@" ; then \
$(INSTALL_PROGRAM) $(exedir)/birdc $(DESTDIR)/$(sbindir)/birdc ; \
fi
$(INSTALL) -d $(DESTDIR)/$(sbindir) $(DESTDIR)/$(sysconfdir) $(DESTDIR)/$(runstatedir)
for BIN in bird @CLIENT@ ; do \
$(INSTALL_PROGRAM) $(exedir)/$$BIN $(DESTDIR)/$(sbindir)/$$BIN ; \
done
if ! test -f $(DESTDIR)/@CONFIG_FILE@ ; then \
$(INSTALL_DATA) $(srcdir)/doc/bird.conf.example $(DESTDIR)/@CONFIG_FILE@ ; \
else \

144
NEWS
View File

@ -1,3 +1,147 @@
Version 2.0.8 (2021-03-18)
o Automatic channel reloads based on RPKI changes
o Multiple static routes with the same network
o Use bitmaps to keep track of exported routes
o Per-channel debug flags
o CLI commands show info from multiple protocols
o Linux: IPv4 routes with IPv6 nexthops
o Filter: Optimized redesign of prefix sets
o Filter: Improved type checking of user filters
o Filter: New src/dst accessors for Flowspec and SADR
o Filter: New 'weight' route attribute
o Filter: BGP path mask loop operator
o Filter: Remove quitbird command
o RIP: Demand circuit support (RFC 2091)
o BGP: New 'allow as sets' and 'enforce first as' options
o BGP: Support for BGP hostname capability
o BGP: Support for MD5SIG with dynamic BGP
o BFD: Optional separation of IPv4 / IPv6 BFD instances
o BFD: Per-peer session options
o RPKI: Allow build without libSSH
o RPKI: New 'ignore max length' option
o OSPF: Redesign of handling of unnumbered PtPs
o OSPF: Allow key id 0 in authentication
o Babel: Use onlink flag for routes with unreachable next hop
o Many bugfixes
Notes:
Automatic channel reloads based on RPKI changes are enabled by default,
but require import table enabled when used in BGP import filter.
BIRD now uses bitmaps to keep track of exported routes instead of
re-evaluation of export filters. That should improve speed and accuracy in
route export handling during reconfiguration, but takes some more memory.
Per-channel debug logging and some CLI commands (like 'show ospf neighbors')
defaulting to all protocol instances lead to some minor changes in log and
CLI output. Caution is recommended when logs or CLI output are monitored by
scripts.
Version 2.0.7 (2019-10-11)
o BGP: Accumulated IGP metric (RFC 7311)
o Important filter reconfiguration bugfix
o Several other bugfixes
Version 2.0.6 (2019-09-10)
o RAdv: Solicited unicast RAs
o BGP: Optional Adj-RIB-Out
o BGP: Extended optional parameters length
o Filter: Sets and set expressions in path masks
o Several important bugfixes
Version 2.0.5 (2019-08-01)
o OSPF Graceful restart (RFC 3623, RFC 5187)
o BGP: Dynamic BGP
o BGP: Promiscuous ASN mode
o BGP: Mandatory option for channels
o BFD: Support for VRFs
o Graceful restart command
o Redesigned filtering code
o Many bugfixes
Notes:
Previous version introduced an error in handling of OSPF NSSA-LSA, causing
compatibility issues with proper implementations. The error is fixed in this
version, therefore there are compatibility issues in OSPF NSSA areas between
this and previous version.
Version 2.0.4 (2019-02-27)
o OSPF: Opaque LSAs (RFC 5250)
o OSPF: DN-bit handling (RFC 4576)
o Preferred route counters are back
o Important BGP bugfix
o Several bugfixes related to route propagation
o some minor bugfixes
Version 2.0.3 (2019-01-05)
o MRT table dumps (RFC 6396)
o BGP Long-lived graceful restart
o BGP: Optional import table (Adj-RIB-In)
o BGP: Extend 'next hop keep' and 'next hop self' options
o BGP: Improved VRF support
o OSPF: Authentication trailer for OSPFv3 (RFC 7166)
o Babel: New option to randomize router ID
o Filter: Custom route attributes
o Filter: Support for src accessor to SADR source prefix
o Filter: Support for VPN_RD sets
o Filter: Make ifname attribute modifiable
o Perf: Protocol to measure BIRD performance internally
o More verbose error messages in config processing
o Log file size limit / log rotation
o Many bugfixes
Notes:
Export of routes to RS EBGP (route server) sessions from other sources than
RS EBGP sessions was changed that ASN is no longer prepended to BGP_PATH in
that case. The change does not affect regular BGP configurations or regular
route servers that have only RS EBGP peers.
For BGP route servers and route reflectors, the default value of option
'next hop keep' was changed to a more appropriate value.
Attributes for OSPF and Babel metrics are no longer reset when exported to
these protocols and could be set anywhere in BIRD. As a result, OSPF metric is
kept when a route is reannounced between OSPF instances. Also, when route is
exported to OSPF with both ospf_metric1 and ospf_metric2 attributes it is now
propagated as OSPF-E2 route instead of as OSPF-E1 route.
Compiling BIRD with --enable-debug no longer automatically activates debug
mode (-d option) nor local mode (-l option). Also, debug mode with output to
file (-D option) no longer not forces foreground mode (-f option).
The configure script now uses standard option --runstatedir, the old option
--with-runtimedir is deprecated.
Version 2.0.2 (2018-03-22)
o Source-specific routing support for Linux kernel and Babel
o BGP: New option 'disable after cease'
o Filter: Allow silent filter execution
o Filter: Fixed stack overflow in BGP mask expressions.
o Several bugfixes
Notes:
Syntax prefix:netmask for IPv4 prefixes was dropped. Just use prefix/pxlen.
Version 2.0.1 (2018-01-16)
o Linux MPLS kernel support
o Better handling of channels inherited from templates
o Default EBGP Route Propagation Behavior without Policies (RFC 8212)
o Many bugfixes
Notes:
To satisfy requirements of RFC 8212, external BGP protocols now require
explicit configuration of import and export policies.
Version 2.0.0 (2017-12-11)
o Integrated IPv4 + IPv6 design
o Support for MPLS next hops

20
README
View File

@ -6,7 +6,7 @@
(c) 1998--2008 Martin Mares <mj@ucw.cz>
(c) 1998--2000 Pavel Machek <pavel@ucw.cz>
(c) 1998--2008 Ondrej Filip <feela@network.cz>
(c) 2009--2016 CZ.NIC z.s.p.o.
(c) 2009--2019 CZ.NIC z.s.p.o.
================================================================================
@ -19,7 +19,7 @@ Public License.
What do we support
==================
o Both IPv4 and IPv6 (use --enable-ipv6 when configuring)
o Both IPv4 and IPv6
o Multiple routing tables
o Border Gateway Protocol (BGPv4)
o Routing Information Protocol (RIPv2, RIPng)
@ -48,20 +48,10 @@ How to install BIRD
ftp://bird.network.cz/pub/bird/redhat/
o From source code of the latest stable release version
ftp://bird.network.cz/pub/bird/
o From source code of the actual development version
git://git.nic.cz/bird.git
o From current development code in Git repository
https://gitlab.labs.nic.cz/labs/bird/
How to install BIRD from source code
------------------------------------
$ ./configure
$ make
$ su
# make install
# vi /usr/local/etc/bird.conf
See the file INSTALL for more information about installation from source code.
See the file INSTALL for information about installation from source code.
Documentation
=============
@ -69,7 +59,7 @@ Documentation
Online documentation is available at http://bird.network.cz/?get_doc or as HTML
files in the doc directory, you can install it by `make install-docs' and
rebuild it by `make docs', but you'll need SGMLtools and LaTeX to be installed
on your machine. You can also download a neatly formatted PostScript version as
on your machine. You can also download a neatly formatted PDF version as
a separate archive (bird-doc-*.tar.gz) from ftp://bird.network.cz/pub/bird/
User support

129
aclocal.m4 vendored
View File

@ -1,6 +1,25 @@
dnl ** Additional Autoconf tests for BIRD configure script
dnl ** (c) 1999 Martin Mares <mj@ucw.cz>
AC_DEFUN([BIRD_CHECK_THREAD_LOCAL],
[
AC_CACHE_CHECK(
[whether _Thread_local is known],
[bird_cv_thread_local],
AC_COMPILE_IFELSE([
AC_LANG_PROGRAM(
[
_Thread_local static int x = 42;
],
[]
)
],
[bird_cv_thread_local=yes],
[bird_cv_thread_local=no]
)
)
])
AC_DEFUN([BIRD_CHECK_PTHREADS],
[
bird_tmp_cflags="$CFLAGS"
@ -65,6 +84,95 @@ AC_DEFUN([BIRD_CHECK_MPLS_KERNEL],
)
])
AC_DEFUN([BIRD_CHECK_ANDROID_GLOB],
[
AC_CACHE_CHECK(
[for glob.h],
[bird_cv_lib_glob],
AC_LINK_IFELSE([
AC_LANG_PROGRAM(
[
#include <glob.h>
#include <stdlib.h>
],
[ glob(NULL, 0, NULL, NULL); ]
)
],
[bird_cv_lib_glob=yes],
[
bird_tmp_libs="$LIBS"
LIBS="$LIBS -landroid-glob"
AC_LINK_IFELSE([
AC_LANG_PROGRAM(
[
#include <glob.h>
#include <stdlib.h>
],
[ glob(NULL, 0, NULL, NULL); ]
)
],
[bird_cv_lib_glob=-landroid-glob],
[bird_cv_lib_glob=no]
)
LIBS="$bird_tmp_libs"
]
)
)
])
AC_DEFUN([BIRD_CHECK_ANDROID_LOG],
[
AC_CACHE_CHECK(
[for syslog lib flags],
[bird_cv_lib_log],
AC_LINK_IFELSE([
AC_LANG_PROGRAM(
[ #include <sys/syslog.h> ],
[ syslog(0, ""); ]
)
],
[bird_cv_lib_log=yes],
[
bird_tmp_libs="$LIBS"
LIBS="$LIBS -llog"
AC_LINK_IFELSE([
AC_LANG_PROGRAM(
[ #include <sys/syslog.h> ],
[ syslog(0, ""); ]
)
],
[bird_cv_lib_log=-llog],
[bird_cv_lib_log=no]
)
LIBS="$bird_tmp_libs"
]
)
)
])
AC_DEFUN([BIRD_CHECK_LTO],
[
bird_tmp_cflags="$CFLAGS"
bird_tmp_ldflags="$LDFLAGS"
CFLAGS="-flto"
LDFLAGS="-flto=4"
AC_CACHE_CHECK(
[whether link time optimizer is available],
[bird_cv_c_lto],
[
AC_LINK_IFELSE(
[AC_LANG_PROGRAM()],
[bird_cv_c_lto=yes],
[bird_cv_c_lto=no]
)
]
)
CFLAGS="$bird_tmp_cflags"
LDFLAGS="$bird_tmp_ldflags"
])
AC_DEFUN([BIRD_CHECK_GCC_OPTION],
[
@ -110,3 +218,24 @@ AC_DEFUN([BIRD_CHECK_PROG_FLAVOR_GNU],
)
esac
])
AC_DEFUN([BIRD_CHECK_BISON_VERSION],
[
$1=`bison --version | ( read line; echo ${line##* } )`
case "$$1" in
1.* | 2.0* | 2.1* | 2.2* | 2.3*)
AC_MSG_ERROR([Provided Bison version $$1 is too old, need at least 2.4])
;;
2.*)
bird_bison_synclines=no
bird_bison_enhanced_error=no
;;
3.* | 4.* | 5.* | 6.* | 7.* | 8.* | 9.*)
bird_bison_synclines=yes
bird_bison_enhanced_error=yes
;;
*)
AC_MSG_ERROR([Couldn't parse Bison version $$1. Call the developers for help.])
;;
esac
])

154
bird-gdb.py Normal file
View File

@ -0,0 +1,154 @@
class BIRDPrinter:
def __init__(self, val):
self.val = val
@classmethod
def lookup(cls, val):
if val.type.code != cls.typeCode:
return None
if val.type.tag != cls.typeTag:
return None
return cls(val)
class BIRDFValPrinter(BIRDPrinter):
"Print BIRD\s struct f_val"
typeCode = gdb.TYPE_CODE_STRUCT
typeTag = "f_val"
codemap = {
"T_INT": "i",
"T_BOOL": "i",
"T_PAIR": "i",
"T_QUAD": "i",
"T_ENUM_RTS": "i",
"T_ENUM_BGP_ORIGIN": "i",
"T_ENUM_SCOPE": "i",
"T_ENUM_RTC": "i",
"T_ENUM_RTD": "i",
"T_ENUM_ROA": "i",
"T_ENUM_NETTYPE": "i",
"T_ENUM_RA_PREFERENCE": "i",
"T_ENUM_AF": "i",
"T_IP": "ip",
"T_NET": "net",
"T_STRING": "s",
"T_PATH_MASK": "path_mask",
"T_PATH": "ad",
"T_CLIST": "ad",
"T_EC": "ec",
"T_ECLIST": "ad",
"T_LC": "lc",
"T_LCLIST": "ad",
"T_RD": "ec",
"T_PATH_MASK_ITEM": "pmi",
"T_SET": "t",
"T_PREFIX_SET": "ti",
}
def to_string(self):
code = self.val['type']
if code.type.code != gdb.TYPE_CODE_ENUM or code.type.tag != "f_type":
raise Exception("Strange 'type' element in f_val")
if str(code) == "T_VOID":
return "T_VOID"
else:
return "(%(c)s) %(v)s" % { "c": code, "v": self.val['val'][self.codemap[str(code)]] }
def display_hint(self):
return "map"
class BIRDFValStackPrinter(BIRDPrinter):
"Print BIRD's struct f_val_stack"
typeCode = gdb.TYPE_CODE_STRUCT
typeTag = "f_val_stack"
def to_string(self):
cnt = self.val['cnt']
return ("Value stack (%(cnt)d):\n\t" % { "cnt": cnt }) + \
"\n\t".join([ (".val[%(n) 3d] = " % { "n": n}) + str(self.val['val'][n]) for n in range(cnt-1, -1, -1) ])
def display_hint(self):
return "map"
class BIRDFInstPrinter(BIRDPrinter):
"Print BIRD's struct f_inst"
typeCode = gdb.TYPE_CODE_STRUCT
typeTag = "f_inst"
def to_string(self):
code = self.val['fi_code']
if str(code) == "FI_NOP":
return str(code) + ": " + str(self.val.cast(gdb.lookup_type("const char [%(siz)d]" % { "siz": self.val.type.sizeof })))
return "%(code)s:\t%(lineno) 6dL\t%(size)6dS\tnext = %(next)s: .i_%(code)s = %(union)s" % {
"code": str(code),
"lineno": self.val['lineno'],
"size": self.val['size'],
"next": str(self.val['next']),
"union": str(self.val['i_' + str(code)])
}
# def children(self): # children iterator
def display_hint(self):
return "map"
class BIRDFLineItemPrinter(BIRDPrinter):
"Print BIRD's struct f_line_item"
typeCode = gdb.TYPE_CODE_STRUCT
typeTag = "f_line_item"
def to_string(self):
code = self.val['fi_code']
if str(code) == "FI_NOP":
return str(code) + ": " + str(self.val.cast(gdb.lookup_type("const char [%(siz)d]" % { "siz": self.val.type.sizeof })))
return "%(code)s:\t%(lineno) 6dL\t%(flags)2dF: .i_%(code)s = %(union)s" % {
"code": str(code),
"lineno": self.val['lineno'],
"flags": self.val['flags'],
"union": str(self.val['i_' + str(code)])
}
class BIRDFLinePrinter(BIRDPrinter):
"Print BIRD's struct f_line"
typeCode = gdb.TYPE_CODE_STRUCT
typeTag = "f_line"
def to_string(self):
cnt = self.val['len']
return ("FLine (%(cnt)d, args=%(args)d): " % { "cnt": cnt, "args" : self.val['args'] } + \
", ".join([
".items[%(n) 3d] = %(code)s" % {
"n": n,
"code": str(self.val['items'][n]['fi_code']),
} if n % 8 == 0 else str(self.val['items'][n]['fi_code']) for n in range(cnt)]))
class BIRDFExecStackPrinter(BIRDPrinter):
"Print BIRD's struct f_exec_stack"
typeCode = gdb.TYPE_CODE_STRUCT
typeTag = "f_exec_stack"
def to_string(self):
cnt = self.val['cnt']
return ("Exec stack (%(cnt)d):\n\t" % { "cnt": cnt }) + \
"\n\t".join([ ".item[%(n) 3d] = %(retflag)d V%(ventry) 3d P%(pos) 4d %(line)s" % {
"retflag": self.val['item'][n]['emask'],
"ventry": self.val['item'][n]['ventry'],
"pos": self.val['item'][n]['pos'],
"line": str(self.val['item'][n]['line'].dereference()),
"n": n
} for n in range(cnt-1, -1, -1) ])
def register_printers(objfile):
objfile.pretty_printers.append(BIRDFInstPrinter.lookup)
objfile.pretty_printers.append(BIRDFValPrinter.lookup)
objfile.pretty_printers.append(BIRDFValStackPrinter.lookup)
objfile.pretty_printers.append(BIRDFLineItemPrinter.lookup)
objfile.pretty_printers.append(BIRDFLinePrinter.lookup)
objfile.pretty_printers.append(BIRDFExecStackPrinter.lookup)
register_printers(gdb.current_objfile())
print("BIRD pretty printers loaded OK.")

View File

@ -22,13 +22,14 @@ protocol direct {
# Feed routes to kernel FIB
protocol kernel {
ipv4 { export all; };
# learn; # Learn all routes from the kernel
ipv4 { export all; import all; };
learn; # Learn all routes from the kernel
# scan time 10; # Scan kernel tables every 10 seconds
}
protocol kernel {
ipv6;
ipv6 { import all; };
learn;
}
# Static route feed

View File

@ -2,8 +2,7 @@ src := commands.c util.c client.c
obj := $(src-o-files)
$(all-client)
$(o)commands.o: $(objdir)/conf/commands.h
$(conf-y-targets): $(s)cmds.Y
$(exedir)/birdc: $(o)birdc.o
$(exedir)/birdc: LIBS += $(CLIENT_LIBS)

View File

@ -10,24 +10,25 @@ BISON_DEBUG=-t
#FLEX_DEBUG=-d
endif
$(conf-y-targets): $(s)confbase.Y $(s)flowspec.Y
$(M4) -P $| $^ >$@
$(o)cf-parse.y: $(s)gen_parser.m4
$(o)keywords.h: $(s)gen_keywords.m4
$(o)commands.h: $(s)gen_commands.m4
$(o)cf-parse.y: | $(s)gen_parser.m4
$(o)keywords.h: | $(s)gen_keywords.m4
$(o)commands.h: | $(s)gen_commands.m4 $(srcdir)/client/cmds.m4
$(conf-y-targets): $(s)confbase.Y $(s)flowspec.Y
$(M4) $(M4FLAGS) -P $(if $(word 2,$(filter %.m4,$^)),$(error "Too many M4 scripts for one target"),$(filter %.m4,$^)) $(filter %.Y,$^) >$@
$(o)cf-parse.tab.h: $(o)cf-parse.tab.c
$(o)cf-parse.tab.c: $(o)cf-parse.y
$(BISON) $(BISON_DEBUG) -dv -pcf_ -b $(@:.tab.c=) $<
$(BISON) $(BISON_DEBUG) $(BISONFLAGS) -dv -pcf_ -b $(@:.tab.c=) $<
$(o)cf-lex.c: $(s)cf-lex.l
$(FLEX) $(FLEX_DEBUG) -s -B -8 -Pcf_ -o$@ $<
$(FLEX) $(FLEX_DEBUG) -f -s -B -8 -Pcf_ -o$@ $<
$(o)cf-lex.o: $(o)cf-parse.tab.h $(o)keywords.h
$(o)cf-lex.o: CFLAGS+=-Wno-sign-compare -Wno-unused-function
prepare: $(o)keywords.h $(o)commands.h $(o)cf-parse.tab.h
$(addprefix $(o), cf-parse.y keywords.h commands.h cf-parse.tab.h cf-parse.tab.c cf-lex.c): $(objdir)/.dir-stamp
$(call clean,cf-parse.tab.h cf-parse.tab.c cf-parse.y keywords.h commands.h cf-lex.c cf-parse.output)

View File

@ -45,6 +45,7 @@
#include "nest/route.h"
#include "nest/protocol.h"
#include "filter/filter.h"
#include "filter/f-inst.h"
#include "conf/conf.h"
#include "conf/cf-parse.tab.h"
#include "lib/string.h"
@ -64,7 +65,7 @@ struct keyword {
#endif
static uint cf_hash(byte *c);
static uint cf_hash(const byte *c);
#define KW_KEY(n) n->name
#define KW_NEXT(n) n->next
@ -87,7 +88,7 @@ HASH_DEFINE_REHASH_FN(SYM, struct symbol)
HASH(struct keyword) kw_hash;
static struct sym_scope *conf_this_scope;
struct sym_scope *conf_this_scope;
linpool *cfg_mem;
@ -95,15 +96,27 @@ int (*cf_read_hook)(byte *buf, unsigned int max, int fd);
struct include_file_stack *ifs;
static struct include_file_stack *ifs_head;
#define QUOTED_BUFFER_SIZE 4096
static BUFFER_(char) quoted_buffer;
static char quoted_buffer_data[QUOTED_BUFFER_SIZE];
static inline void quoted_buffer_init(void) {
quoted_buffer.used = 0;
quoted_buffer.size = QUOTED_BUFFER_SIZE;
quoted_buffer.data = quoted_buffer_data;
}
#define MAX_INCLUDE_DEPTH 8
#define YY_INPUT(buf,result,max) result = cf_read_hook(buf, max, ifs->fd);
#define YY_NO_UNPUT
#define YY_FATAL_ERROR(msg) cf_error(msg)
#define YY_USER_ACTION ifs->chno += yyleng; ifs->toklen = yyleng;
static void cf_include(char *arg, int alen);
static int check_eof(void);
static enum yytokentype cf_lex_symbol(const char *data);
%}
%option noyywrap
@ -111,24 +124,26 @@ static int check_eof(void);
%option nounput
%option noreject
%x COMMENT CCOMM CLI
%x COMMENT CCOMM CLI QUOTED APOSTROPHED INCLUDE
ALPHA [a-zA-Z_]
DIGIT [0-9]
XIGIT [0-9a-fA-F]
ALNUM [a-zA-Z_0-9]
WHITE [ \t]
include ^{WHITE}*include{WHITE}*\".*\"{WHITE}*;
%%
{include} {
char *start, *end;
^{WHITE}*include{WHITE}*\" {
if (!ifs->depth)
cf_error("Include not allowed in CLI");
start = strchr(yytext, '"');
start++;
BEGIN(INCLUDE);
}
<INCLUDE>[^"\n]+["]{WHITE}*; {
char *start, *end;
start = yytext;
end = strchr(start, '"');
*end = 0;
@ -137,16 +152,24 @@ include ^{WHITE}*include{WHITE}*\".*\"{WHITE}*;
cf_error("Include with empty argument");
cf_include(start, end-start);
BEGIN(INITIAL);
}
<INCLUDE>["] cf_error("Include with empty argument");
<INCLUDE>. cf_error("Unterminated include");
<INCLUDE>\n cf_error("Unterminated include");
<INCLUDE><<EOF>> cf_error("Unterminated include");
{DIGIT}+:{DIGIT}+ {
uint len1 UNUSED, len2;
u64 l;
char *e;
errno = 0;
l = strtoul(yytext, &e, 10);
if (e && (*e != ':') || (errno == ERANGE) || (l >> 32))
l = bstrtoul10(yytext, &e);
if (!e || (*e != ':') || (errno == ERANGE) || (l >> 32))
cf_error("ASN out of range");
if (l >> 16)
@ -163,8 +186,8 @@ include ^{WHITE}*include{WHITE}*\".*\"{WHITE}*;
}
errno = 0;
l = strtoul(e+1, &e, 10);
if (e && *e || (errno == ERANGE) || (l >> len2))
l = bstrtoul10(e+1, &e);
if (!e || *e || (errno == ERANGE) || (l >> len2))
cf_error("Number out of range");
cf_lval.i64 |= l;
@ -190,14 +213,14 @@ include ^{WHITE}*include{WHITE}*\".*\"{WHITE}*;
}
errno = 0;
l = strtoul(yytext+2, &e, 10);
if (e && (*e != ':') || (errno == ERANGE) || (l >> len1))
l = bstrtoul10(yytext+2, &e);
if (!e || (*e != ':') || (errno == ERANGE) || (l >> len1))
cf_error("ASN out of range");
cf_lval.i64 |= ((u64) l) << len2;
errno = 0;
l = strtoul(e+1, &e, 10);
if (e && *e || (errno == ERANGE) || (l >> len2))
l = bstrtoul10(e+1, &e);
if (!e || *e || (errno == ERANGE) || (l >> len2))
cf_error("Number out of range");
cf_lval.i64 |= l;
@ -218,8 +241,8 @@ include ^{WHITE}*include{WHITE}*\".*\"{WHITE}*;
cf_lval.i64 |= ((u64) ip4_to_u32(ip4)) << 16;
errno = 0;
l = strtoul(e, &e, 10);
if (e && *e || (errno == ERANGE) || (l >> 16))
l = bstrtoul10(e, &e);
if (!e || *e || (errno == ERANGE) || (l >> 16))
cf_error("Number out of range");
cf_lval.i64 |= l;
@ -242,8 +265,8 @@ include ^{WHITE}*include{WHITE}*\".*\"{WHITE}*;
char *e;
unsigned long int l;
errno = 0;
l = strtoul(yytext+2, &e, 16);
if (e && *e || errno == ERANGE || (unsigned long int)(unsigned int) l != l)
l = bstrtoul16(yytext+2, &e);
if (!e || *e || errno == ERANGE || (unsigned long int)(unsigned int) l != l)
cf_error("Number out of range");
cf_lval.i = l;
return NUM;
@ -253,8 +276,8 @@ include ^{WHITE}*include{WHITE}*\".*\"{WHITE}*;
char *e;
unsigned long int l;
errno = 0;
l = strtoul(yytext, &e, 10);
if (e && *e || errno == ERANGE || (unsigned long int)(unsigned int) l != l)
l = bstrtoul10(yytext, &e);
if (!e || *e || errno == ERANGE || (unsigned long int)(unsigned int) l != l)
cf_error("Number out of range");
cf_lval.i = l;
return NUM;
@ -265,26 +288,23 @@ else: {
return ELSECOL;
}
({ALPHA}{ALNUM}*|[']({ALNUM}|[-]|[\.]|[:])*[']) {
if(*yytext == '\'') {
yytext[yyleng-1] = 0;
yytext++;
}
['] {
BEGIN(APOSTROPHED);
quoted_buffer_init();
}
struct keyword *k = HASH_FIND(kw_hash, KW, yytext);
if (k)
{
if (k->value > 0)
return k->value;
else
{
cf_lval.i = -k->value;
return ENUM;
}
}
<APOSTROPHED>{ALNUM}|[-]|[.:] BUFFER_PUSH(quoted_buffer) = yytext[0];
<APOSTROPHED>\n cf_error("Unterminated symbol");
<APOSTROPHED><<EOF>> cf_error("Unterminated symbol");
<APOSTROPHED>['] {
BEGIN(INITIAL);
BUFFER_PUSH(quoted_buffer) = 0;
return cf_lex_symbol(quoted_buffer_data);
}
<APOSTROPHED>. cf_error("Invalid character in apostrophed symbol");
cf_lval.s = cf_get_symbol(yytext);
return SYM;
({ALPHA}{ALNUM}*) {
return cf_lex_symbol(yytext);
}
<CLI>(.|\n) {
@ -300,20 +320,27 @@ else: {
return yytext[0];
}
["][^"\n]*["] {
yytext[yyleng-1] = 0;
cf_lval.t = cfg_strdup(yytext+1);
yytext[yyleng-1] = '"';
["] {
BEGIN(QUOTED);
quoted_buffer_init();
}
<QUOTED>\n cf_error("Unterminated string");
<QUOTED><<EOF>> cf_error("Unterminated string");
<QUOTED>["] {
BEGIN(INITIAL);
BUFFER_PUSH(quoted_buffer) = 0;
cf_lval.t = cfg_strdup(quoted_buffer_data);
return TEXT;
}
["][^"\n]*\n cf_error("Unterminated string");
<QUOTED>. BUFFER_PUSH(quoted_buffer) = yytext[0];
<INITIAL,COMMENT><<EOF>> { if (check_eof()) return END; }
{WHITE}+
\n ifs->lino++;
\n ifs->lino++; ifs->chno = 0;
# BEGIN(COMMENT);
@ -323,13 +350,14 @@ else: {
<COMMENT>\n {
ifs->lino++;
ifs->chno = 0;
BEGIN(INITIAL);
}
<COMMENT>.
<CCOMM>\*\/ BEGIN(INITIAL);
<CCOMM>\n ifs->lino++;
<CCOMM>\n ifs->lino++; ifs->chno = 0;
<CCOMM>\/\* cf_error("Comment nesting not supported");
<CCOMM><<EOF>> cf_error("Unterminated comment");
<CCOMM>.
@ -347,7 +375,7 @@ else: {
%%
static uint
cf_hash(byte *c)
cf_hash(const byte *c)
{
uint h = 13 << 24;
@ -356,7 +384,6 @@ cf_hash(byte *c)
return h;
}
/*
* IFS stack - it contains structures needed for recursive processing
* of include in config files. On the top of the stack is a structure
@ -517,7 +544,7 @@ check_eof(void)
}
static struct symbol *
cf_new_symbol(byte *c)
cf_new_symbol(const byte *c)
{
struct symbol *s;
@ -525,11 +552,8 @@ cf_new_symbol(byte *c)
if (l > SYM_MAX_LEN)
cf_error("Symbol too long");
s = cfg_alloc(sizeof(struct symbol) + l);
s->scope = conf_this_scope;
s->class = SYM_VOID;
s->def = NULL;
s->aux = 0;
s = cfg_allocz(sizeof(struct symbol) + l + 1);
*s = (struct symbol) { .scope = conf_this_scope, .class = SYM_VOID, };
strcpy(s->name, c);
if (!new_config->sym_hash.data)
@ -537,6 +561,8 @@ cf_new_symbol(byte *c)
HASH_INSERT2(new_config->sym_hash, SYM, new_config->pool, s);
add_tail(&(new_config->symbols), &(s->n));
return s;
}
@ -552,7 +578,7 @@ cf_new_symbol(byte *c)
* signify no match.
*/
struct symbol *
cf_find_symbol(struct config *cfg, byte *c)
cf_find_symbol(const struct config *cfg, const byte *c)
{
struct symbol *s;
@ -560,6 +586,7 @@ cf_find_symbol(struct config *cfg, byte *c)
(s = HASH_FIND(cfg->sym_hash, SYM, c, 1)))
return s;
/* In CLI command parsing, fallback points to the current config, otherwise it is NULL. */
if (cfg->fallback &&
cfg->fallback->sym_hash.data &&
(s = HASH_FIND(cfg->fallback->sym_hash, SYM, c, 1)))
@ -578,11 +605,33 @@ cf_find_symbol(struct config *cfg, byte *c)
* existing symbol is found.
*/
struct symbol *
cf_get_symbol(byte *c)
cf_get_symbol(const byte *c)
{
return cf_find_symbol(new_config, c) ?: cf_new_symbol(c);
}
/**
* cf_localize_symbol - get the local instance of given symbol
* @sym: the symbol to localize
*
* This functions finds the symbol that is local to current scope
* for purposes of cf_define_symbol().
*/
struct symbol *
cf_localize_symbol(struct symbol *sym)
{
/* If the symbol type is void, it has been recently allocated just in this scope. */
if (!sym->class)
return sym;
/* If the scope is the current, it is already defined in this scope. */
if (sym->scope == conf_this_scope)
cf_error("Symbol already defined");
/* Not allocated here yet, doing it now. */
return cf_new_symbol(sym->name);
}
struct symbol *
cf_default_name(char *template, int *counter)
{
@ -602,33 +651,32 @@ cf_default_name(char *template, int *counter)
cf_error("Unable to generate default name");
}
/**
* cf_define_symbol - define meaning of a symbol
* @sym: symbol to be defined
* @type: symbol class to assign
* @def: class dependent data
*
* Defines new meaning of a symbol. If the symbol is an undefined
* one (%SYM_VOID), it's just re-defined to the new type. If it's defined
* in different scope, a new symbol in current scope is created and the
* meaning is assigned to it. If it's already defined in the current scope,
* an error is reported via cf_error().
*
* Result: Pointer to the newly defined symbol. If we are in the top-level
* scope, it's the same @sym as passed to the function.
*/
struct symbol *
cf_define_symbol(struct symbol *sym, int type, void *def)
static enum yytokentype
cf_lex_symbol(const char *data)
{
if (sym->class)
/* Have we defined such a symbol? */
struct symbol *sym = cf_get_symbol(data);
cf_lval.s = sym;
if (sym->class != SYM_VOID)
return CF_SYM_KNOWN;
/* Is it a keyword? */
struct keyword *k = HASH_FIND(kw_hash, KW, data);
if (k)
{
if (k->value > 0)
return k->value;
else
{
if (sym->scope == conf_this_scope)
cf_error("Symbol already defined");
sym = cf_new_symbol(sym->name);
cf_lval.i = -k->value;
return ENUM;
}
sym->class = type;
sym->def = def;
return sym;
}
/* OK, undefined symbol */
cf_lval.s = sym;
return CF_SYM_UNDEFINED;
}
static void
@ -671,7 +719,8 @@ cf_lex_init(int is_cli, struct config *c)
else
BEGIN(INITIAL);
conf_this_scope = cfg_allocz(sizeof(struct sym_scope));
c->root_scope = cfg_allocz(sizeof(struct sym_scope));
conf_this_scope = c->root_scope;
conf_this_scope->active = 1;
}
@ -688,12 +737,13 @@ cf_lex_init(int is_cli, struct config *c)
void
cf_push_scope(struct symbol *sym)
{
struct sym_scope *s = cfg_alloc(sizeof(struct sym_scope));
struct sym_scope *s = cfg_allocz(sizeof(struct sym_scope));
s->next = conf_this_scope;
conf_this_scope = s;
s->active = 1;
s->name = sym;
s->slots = 0;
}
/**
@ -708,6 +758,7 @@ cf_pop_scope(void)
{
conf_this_scope->active = 0;
conf_this_scope = conf_this_scope->next;
ASSERT(conf_this_scope);
}
@ -721,9 +772,6 @@ cf_pop_scope(void)
char *
cf_symbol_class_name(struct symbol *sym)
{
if (cf_symbol_is_constant(sym))
return "constant";
switch (sym->class)
{
case SYM_VOID:
@ -738,6 +786,12 @@ cf_symbol_class_name(struct symbol *sym)
return "filter";
case SYM_TABLE:
return "routing table";
case SYM_ATTRIBUTE:
return "custom attribute";
case SYM_CONSTANT_RANGE:
return "constant";
case SYM_VARIABLE_RANGE:
return "variable";
default:
return "unknown type";
}

View File

@ -55,6 +55,7 @@
#include "lib/timer.h"
#include "conf/conf.h"
#include "filter/filter.h"
#include "sysdep/unix/unix.h"
static jmp_buf conf_jmpbuf;
@ -98,6 +99,7 @@ config_alloc(const char *name)
memcpy(ndup, name, nlen);
init_list(&c->tests);
init_list(&c->symbols);
c->mrtdump_file = -1; /* Hack, this should be sysdep-specific */
c->pool = p;
c->mem = l;
@ -209,13 +211,21 @@ config_del_obstacle(struct config *c)
{
DBG("+++ deleting obstacle %d\n", c->obstacle_count);
c->obstacle_count--;
if (!c->obstacle_count)
if (!c->obstacle_count && (c != config))
ev_schedule(config_event);
}
static int
global_commit(struct config *new, struct config *old)
{
if (!new->hostname)
{
new->hostname = get_hostname(new->mem);
if (!new->hostname)
log(L_WARN "Cannot determine hostname");
}
if (!old)
return 0;
@ -258,6 +268,8 @@ config_do_commit(struct config *c, int type)
if (old_config)
old_config->obstacle_count++;
DBG("filter_commit\n");
filter_commit(c, old_config);
DBG("sysdep_commit\n");
int force_restart = sysdep_commit(c, old_config);
DBG("global_commit\n");
@ -444,6 +456,24 @@ config_undo(void)
return CONF_PROGRESS;
}
int
config_status(void)
{
if (shutting_down)
return CONF_SHUTDOWN;
if (configuring)
return future_cftype ? CONF_QUEUED : CONF_PROGRESS;
return CONF_DONE;
}
btime
config_timer_status(void)
{
return tm_active(config_timer) ? tm_remains(config_timer) : -1;
}
extern void cmd_reconfig_undo_notify(void);
static void
@ -474,19 +504,24 @@ config_init(void)
* for switching to an empty configuration.
*/
void
order_shutdown(void)
order_shutdown(int gr)
{
struct config *c;
if (shutting_down)
return;
log(L_INFO "Shutting down");
if (!gr)
log(L_INFO "Shutting down");
else
log(L_INFO "Shutting down for graceful restart");
c = lp_alloc(config->mem, sizeof(struct config));
memcpy(c, config, sizeof(struct config));
init_list(&c->protos);
init_list(&c->tables);
c->shutdown = 1;
c->gr_down = gr;
config_commit(c, RECONFIG_HARD, 0);
shutting_down = 1;
@ -512,6 +547,7 @@ cf_error(const char *msg, ...)
va_end(args);
new_config->err_msg = cfg_strdup(buf);
new_config->err_lino = ifs->lino;
new_config->err_chno = ifs->chno - ifs->toklen + 1;
new_config->err_file_name = ifs->file_name;
cf_lex_unwind();
longjmp(conf_jmpbuf, 1);
@ -546,6 +582,7 @@ cfg_copy_list(list *dest, list *src, unsigned node_size)
{
dn = cfg_alloc(node_size);
memcpy(dn, sn, node_size);
memset(dn, 0, sizeof(node));
add_tail(dest, dn);
}
}

View File

@ -15,7 +15,6 @@
#include "lib/resource.h"
#include "lib/timer.h"
/* Configuration structure */
struct config {
@ -25,20 +24,23 @@ struct config {
list tables; /* Configured routing tables (struct rtable_config) */
list logfiles; /* Configured log files (sysdep) */
list tests; /* Configured unit tests (f_bt_test_suite) */
list symbols; /* Configured symbols in config order */
int mrtdump_file; /* Configured MRTDump file (sysdep, fd in unix) */
char *syslog_name; /* Name used for syslog (NULL -> no syslog) */
const char *syslog_name; /* Name used for syslog (NULL -> no syslog) */
struct rtable_config *def_tables[NET_MAX]; /* Default routing tables for each network */
struct iface_patt *router_id_from; /* Configured list of router ID iface patterns */
u32 router_id; /* Our Router ID */
unsigned proto_default_debug; /* Default protocol debug mask */
unsigned proto_default_mrtdump; /* Default protocol mrtdump mask */
u32 proto_default_debug; /* Default protocol debug mask */
u32 proto_default_mrtdump; /* Default protocol mrtdump mask */
u32 channel_default_debug; /* Default channel debug mask */
struct timeformat tf_route; /* Time format for 'show route' */
struct timeformat tf_proto; /* Time format for 'show protocol' */
struct timeformat tf_log; /* Time format for the logfile */
struct timeformat tf_base; /* Time format for other purposes */
u32 gr_wait; /* Graceful restart wait timeout (sec) */
const char *hostname; /* Hostname */
int cli_debug; /* Tracing of CLI connections and commands */
int latency_debug; /* I/O loop tracks duration of each event */
@ -47,13 +49,16 @@ struct config {
u32 watchdog_timeout; /* Watchdog timeout (in seconds, 0 = disabled) */
char *err_msg; /* Parser error message */
int err_lino; /* Line containing error */
int err_chno; /* Character where the parser stopped */
char *err_file_name; /* File name containing error */
char *file_name; /* Name of main configuration file */
int file_fd; /* File descriptor of main configuration file */
HASH(struct symbol) sym_hash; /* Lexer: symbol hash table */
struct config *fallback; /* Link to regular config for CLI parsing */
struct sym_scope *root_scope; /* Scope for root symbols */
int obstacle_count; /* Number of items blocking freeing of this config */
int shutdown; /* This is a pseudo-config for daemon shutdown */
int gr_down; /* This is a pseudo-config for graceful restart */
btime load_time; /* When we've got this configuration */
};
@ -68,11 +73,13 @@ void config_free(struct config *);
int config_commit(struct config *, int type, uint timeout);
int config_confirm(void);
int config_undo(void);
int config_status(void);
btime config_timer_status(void);
void config_init(void);
void cf_error(const char *msg, ...) NORET;
void config_add_obstacle(struct config *);
void config_del_obstacle(struct config *);
void order_shutdown(void);
void order_shutdown(int gr);
#define RECONFIG_NONE 0
#define RECONFIG_HARD 1
@ -103,18 +110,29 @@ void cfg_copy_list(list *dest, list *src, unsigned node_size);
extern int (*cf_read_hook)(byte *buf, uint max, int fd);
struct symbol {
node n; /* In list of symbols in config */
struct symbol *next;
struct sym_scope *scope;
int class;
int aux;
void *aux2;
void *def;
char name[1];
int class; /* SYM_* */
uint flags; /* SYM_FLAG_* */
union {
struct proto_config *proto; /* For SYM_PROTO and SYM_TEMPLATE */
const struct f_line *function; /* For SYM_FUNCTION */
const struct filter *filter; /* For SYM_FILTER */
struct rtable_config *table; /* For SYM_TABLE */
struct f_dynamic_attr *attribute; /* For SYM_ATTRIBUTE */
struct f_val *val; /* For SYM_CONSTANT */
uint offset; /* For SYM_VARIABLE */
};
char name[0];
};
struct sym_scope {
struct sym_scope *next; /* Next on scope stack */
struct symbol *name; /* Name of this scope */
uint slots; /* Variable slots */
int active; /* Currently entered */
};
@ -127,18 +145,26 @@ struct sym_scope {
#define SYM_FUNCTION 3
#define SYM_FILTER 4
#define SYM_TABLE 5
#define SYM_ATTRIBUTE 6
#define SYM_VARIABLE 0x100 /* 0x100-0x1ff are variable types */
#define SYM_VARIABLE_RANGE SYM_VARIABLE ... (SYM_VARIABLE | 0xff)
#define SYM_CONSTANT 0x200 /* 0x200-0x2ff are variable types */
#define SYM_CONSTANT_RANGE SYM_CONSTANT ... (SYM_CONSTANT | 0xff)
#define SYM_TYPE(s) (((struct f_val *) (s)->def)->type)
#define SYM_VAL(s) (((struct f_val *) (s)->def)->val)
#define SYM_TYPE(s) ((s)->val->type)
#define SYM_VAL(s) ((s)->val->val)
/* Symbol flags */
#define SYM_FLAG_SAME 0x1 /* For SYM_FUNCTION and SYM_FILTER */
struct include_file_stack {
void *buffer; /* Internal lexer state */
char *file_name; /* File name */
int fd; /* File descriptor */
int lino; /* Current line num */
int chno; /* Current char num (on current line) */
int toklen; /* Current token length */
int depth; /* Include depth, 0 = cannot include */
struct include_file_stack *prev; /* Previous record in stack */
@ -147,24 +173,43 @@ struct include_file_stack {
extern struct include_file_stack *ifs;
extern struct sym_scope *conf_this_scope;
int cf_lex(void);
void cf_lex_init(int is_cli, struct config *c);
void cf_lex_unwind(void);
struct symbol *cf_find_symbol(struct config *cfg, byte *c);
struct symbol *cf_find_symbol(const struct config *cfg, const byte *c);
struct symbol *cf_get_symbol(byte *c);
struct symbol *cf_get_symbol(const byte *c);
struct symbol *cf_default_name(char *template, int *counter);
struct symbol *cf_define_symbol(struct symbol *symbol, int type, void *def);
struct symbol *cf_localize_symbol(struct symbol *sym);
/**
* cf_define_symbol - define meaning of a symbol
* @sym: symbol to be defined
* @type: symbol class to assign
* @def: class dependent data
*
* Defines new meaning of a symbol. If the symbol is an undefined
* one (%SYM_VOID), it's just re-defined to the new type. If it's defined
* in different scope, a new symbol in current scope is created and the
* meaning is assigned to it. If it's already defined in the current scope,
* an error is reported via cf_error().
*
* Result: Pointer to the newly defined symbol. If we are in the top-level
* scope, it's the same @sym as passed to the function.
*/
#define cf_define_symbol(osym_, type_, var_, def_) ({ \
struct symbol *sym_ = cf_localize_symbol(osym_); \
sym_->class = type_; \
sym_->var_ = def_; \
sym_; })
void cf_push_scope(struct symbol *);
void cf_pop_scope(void);
char *cf_symbol_class_name(struct symbol *sym);
static inline int cf_symbol_is_constant(struct symbol *sym)
{ return (sym->class & 0xff00) == SYM_CONSTANT; }
/* Parser */
extern char *cf_text;

View File

@ -19,6 +19,7 @@ CF_HDR
#include "nest/protocol.h"
#include "nest/iface.h"
#include "nest/route.h"
#include "nest/bfd.h"
#include "nest/cli.h"
#include "filter/filter.h"
@ -33,6 +34,21 @@ check_u16(uint val)
cf_error("Value %u out of range (0-65535)", val);
}
#define cf_assert(cond, ...) do { if (!(cond)) cf_error(__VA_ARGS__); } while (0)
static inline void cf_assert_symbol(const struct symbol *sym, uint class) {
switch (class) {
case SYM_PROTO: cf_assert(sym->class == SYM_PROTO, "Protocol name required"); break;
case SYM_TEMPLATE: cf_assert(sym->class == SYM_TEMPLATE, "Protocol template name required"); break;
case SYM_FUNCTION: cf_assert(sym->class == SYM_FUNCTION, "Function name required"); break;
case SYM_FILTER: cf_assert(sym->class == SYM_FILTER, "Filter name required"); break;
case SYM_TABLE: cf_assert(sym->class == SYM_TABLE, "Table name required"); break;
case SYM_ATTRIBUTE: cf_assert(sym->class == SYM_ATTRIBUTE, "Custom attribute name required"); break;
case SYM_VARIABLE: cf_assert((sym->class & ~0xff) == SYM_VARIABLE, "Variable name required"); break;
case SYM_CONSTANT: cf_assert((sym->class & ~0xff) == SYM_CONSTANT, "Constant name required"); break;
default: bug("This shall not happen");
}
}
CF_DECLS
%union {
@ -45,19 +61,29 @@ CF_DECLS
net_addr net;
net_addr *net_ptr;
struct symbol *s;
char *t;
const char *t;
struct rtable_config *r;
struct channel_config *cc;
struct channel *c;
struct f_inst *x;
struct filter *f;
struct {
struct f_inst *begin, *end;
} xp;
enum filter_return fret;
enum ec_subtype ecs;
struct f_dynamic_attr fda;
struct f_static_attr fsa;
struct f_lval flv;
struct f_line *fl;
const struct filter *f;
struct f_tree *e;
struct f_trie *trie;
struct f_val v;
struct f_path_mask *h;
struct password_item *p;
struct rt_show_data *ra;
struct sym_show_data *sd;
struct lsadb_show_data *ld;
struct mrt_dump_data *md;
struct iface *iface;
void *g;
btime time;
@ -75,7 +101,7 @@ CF_DECLS
%token <ip4> IP4
%token <ip6> IP6
%token <i64> VPN_RD
%token <s> SYM
%token <s> CF_SYM_KNOWN CF_SYM_UNDEFINED
%token <t> TEXT
%type <iface> ipa_scope
@ -83,10 +109,11 @@ CF_DECLS
%type <time> expr_us time
%type <a> ipa
%type <net> net_ip4_ net_ip6_ net_ip6 net_ip_ net_ip net_or_ipa
%type <net_ptr> net_ net_any net_vpn4_ net_vpn6_ net_vpn_ net_roa4_ net_roa6_ net_roa_
%type <net_ptr> net_ net_any net_vpn4_ net_vpn6_ net_vpn_ net_roa4_ net_roa6_ net_roa_ net_ip6_sadr_ net_mpls_
%type <mls> label_stack_start label_stack
%type <t> text opttext
%type <s> symbol
%nonassoc PREFIX_DUMMY
%left AND OR
@ -96,7 +123,9 @@ CF_DECLS
%left '!'
%nonassoc '.'
CF_KEYWORDS(DEFINE, ON, OFF, YES, NO, S, MS, US, PORT, VPN)
%start config
CF_KEYWORDS(DEFINE, ON, OFF, YES, NO, S, MS, US, PORT, VPN, MPLS, FROM)
CF_GRAMMAR
@ -111,36 +140,37 @@ conf_entries:
| conf_entries conf
;
CF_ADDTO(conf, ';')
conf: ';' ;
/* Constant expressions */
CF_ADDTO(conf, definition)
conf: definition ;
definition:
DEFINE SYM '=' term ';' {
struct f_val *val = cfg_alloc(sizeof(struct f_val));
*val = f_eval($4, cfg_mem);
if (val->type == T_RETURN) cf_error("Runtime error");
cf_define_symbol($2, SYM_CONSTANT | val->type, val);
DEFINE symbol '=' term ';' {
struct f_val *val = cfg_allocz(sizeof(struct f_val));
if (f_eval(f_linearize($4), cfg_mem, val) > F_RETURN) cf_error("Runtime error");
cf_define_symbol($2, SYM_CONSTANT | val->type, val, val);
}
;
expr:
NUM
| '(' term ')' { $$ = f_eval_int($2); }
| SYM {
if ($1->class != (SYM_CONSTANT | T_INT)) cf_error("Number expected");
| '(' term ')' { $$ = f_eval_int(f_linearize($2)); }
| CF_SYM_KNOWN {
if ($1->class != (SYM_CONSTANT | T_INT)) cf_error("Number constant expected");
$$ = SYM_VAL($1).i; }
;
expr_us:
expr S { $$ = $1 S_; }
| expr MS { $$ = $1 MS_; }
| expr US { $$ = $1 US_; }
;
symbol: CF_SYM_UNDEFINED | CF_SYM_KNOWN ;
/* Switches */
bool:
@ -158,15 +188,15 @@ bool:
ipa:
IP4 { $$ = ipa_from_ip4($1); }
| IP6 { $$ = ipa_from_ip6($1); }
| SYM {
if ($1->class != (SYM_CONSTANT | T_IP)) cf_error("IP address expected");
| CF_SYM_KNOWN {
if ($1->class != (SYM_CONSTANT | T_IP)) cf_error("IP address constant expected");
$$ = SYM_VAL($1).ip;
}
;
ipa_scope:
/* empty */ { $$ = NULL; }
| '%' SYM { $$ = if_get_by_name($2->name); }
| '%' symbol { $$ = if_get_by_name($2->name); }
;
@ -177,10 +207,6 @@ pxlen4:
if ($2 > IP4_MAX_PREFIX_LENGTH) cf_error("Invalid prefix length %u", $2);
$$ = $2;
}
| ':' IP4 {
$$ = ip4_masklen($2);
if ($$ == 255) cf_error("Invalid netmask %I4", $2);
}
;
net_ip4_: IP4 pxlen4
@ -206,6 +232,25 @@ net_ip6_: IP6 '/' NUM
n->prefix, n->pxlen, ip6_and(n->prefix, ip6_mkmask(n->pxlen)), n->pxlen);
};
net_ip6_sadr_: IP6 '/' NUM FROM IP6 '/' NUM
{
if ($3 > IP6_MAX_PREFIX_LENGTH)
cf_error("Invalid prefix length %u", $3);
if ($7 > IP6_MAX_PREFIX_LENGTH)
cf_error("Invalid prefix length %u", $7);
$$ = cfg_alloc(sizeof(net_addr_ip6_sadr));
net_fill_ip6_sadr($$, $1, $3, $5, $7);
net_addr_ip6_sadr *n = (void *) $$;
if (!net_validate_ip6_sadr(n))
cf_error("Invalid SADR IPv6 prefix %I6/%d from %I6/%d, maybe you wanted %I6/%d from %I6/%d",
n->dst_prefix, n->dst_pxlen, n->src_prefix, n->src_pxlen,
ip6_and(n->dst_prefix, ip6_mkmask(n->dst_pxlen)), n->dst_pxlen,
ip6_and(n->src_prefix, ip6_mkmask(n->src_pxlen)), n->src_pxlen);
};
net_vpn4_: VPN_RD net_ip4_
{
$$ = cfg_alloc(sizeof(net_addr_vpn4));
@ -234,6 +279,12 @@ net_roa6_: net_ip6_ MAX NUM AS NUM
cf_error("Invalid max prefix length %u", $3);
};
net_mpls_: MPLS NUM
{
$$ = cfg_alloc(sizeof(net_addr_roa6));
net_fill_mpls($$, $2);
}
net_ip_: net_ip4_ | net_ip6_ ;
net_vpn_: net_vpn4_ | net_vpn6_ ;
net_roa_: net_roa4_ | net_roa6_ ;
@ -243,6 +294,8 @@ net_:
| net_vpn_
| net_roa_
| net_flow_
| net_ip6_sadr_
| net_mpls_
;
@ -250,27 +303,27 @@ net_:
net_ip6:
net_ip6_
| SYM {
| CF_SYM_KNOWN {
if (($1->class != (SYM_CONSTANT | T_NET)) || (SYM_VAL($1).net->type != NET_IP6))
cf_error("IPv6 network expected");
cf_error("IPv6 network constant expected");
$$ = * SYM_VAL($1).net;
}
;
net_ip:
net_ip_
| SYM {
| CF_SYM_KNOWN {
if (($1->class != (SYM_CONSTANT | T_NET)) || !net_is_ip(SYM_VAL($1).net))
cf_error("IP network expected");
cf_error("IP network constant expected");
$$ = * SYM_VAL($1).net;
}
;
net_any:
net_
| SYM {
| CF_SYM_KNOWN {
if ($1->class != (SYM_CONSTANT | T_NET))
cf_error("Network expected");
cf_error("Network constant expected");
$$ = (net_addr *) SYM_VAL($1).net; /* Avoid const warning */
}
;
@ -280,13 +333,13 @@ net_or_ipa:
| net_ip6_
| IP4 { net_fill_ip4(&($$), $1, IP4_MAX_PREFIX_LENGTH); }
| IP6 { net_fill_ip6(&($$), $1, IP6_MAX_PREFIX_LENGTH); }
| SYM {
| CF_SYM_KNOWN {
if ($1->class == (SYM_CONSTANT | T_IP))
net_fill_ip_host(&($$), SYM_VAL($1).ip);
else if (($1->class == (SYM_CONSTANT | T_NET)) && net_is_ip(SYM_VAL($1).net))
$$ = * SYM_VAL($1).net;
else
cf_error("IP address or network expected");
cf_error("IP address or network constant expected");
}
;
@ -317,8 +370,8 @@ time:
text:
TEXT
| SYM {
if ($1->class != (SYM_CONSTANT | T_STRING)) cf_error("String expected");
| CF_SYM_KNOWN {
if ($1->class != (SYM_CONSTANT | T_STRING)) cf_error("String constant expected");
$$ = SYM_VAL($1).s;
}
;

View File

@ -34,9 +34,11 @@ m4_define(CF_CLI, `CF_KEYWORDS(m4_translit($1, [[ ]], [[,]]))
')
# Enums are translated to C initializers: use CF_ENUM(typename, prefix, values)
m4_define(CF_enum, `m4_divert(1){ "CF_enum_prefix[[]]$1", -((CF_enum_type<<16) | CF_enum_prefix[[]]$1), NULL },
# For different prefix: CF_ENUM_PX(typename, external prefix, C prefix, values)
m4_define(CF_enum, `m4_divert(1){ "CF_enum_prefix_ext[[]]$1", -((CF_enum_type<<16) | CF_enum_prefix_int[[]]$1), NULL },
m4_divert(-1)')
m4_define(CF_ENUM, `m4_define([[CF_enum_type]],$1)m4_define([[CF_enum_prefix]],$2)CF_iterate([[CF_enum]], [[m4_shift(m4_shift($@))]])DNL')
m4_define(CF_ENUM, `m4_define([[CF_enum_type]],$1)m4_define([[CF_enum_prefix_ext]],$2)m4_define([[CF_enum_prefix_int]],$2)CF_iterate([[CF_enum]], [[m4_shift(m4_shift($@))]])DNL')
m4_define(CF_ENUM_PX, `m4_define([[CF_enum_type]],$1)m4_define([[CF_enum_prefix_ext]],$2)m4_define([[CF_enum_prefix_int]],$3)CF_iterate([[CF_enum]], [[m4_shift(m4_shift(m4_shift($@)))]])DNL')
# After all configuration templates end, we generate the
m4_m4wrap(`

View File

@ -34,21 +34,17 @@ m4_define(CF_keywd, `m4_ifdef([[CF_tok_$1]],,[[m4_define([[CF_tok_$1]],1)m4_defi
m4_define(CF_KEYWORDS, `m4_define([[CF_toks]],[[]])CF_iterate([[CF_keywd]], [[$@]])m4_ifelse(CF_toks,,,%token[[]]CF_toks
)DNL')
# Dynamic syntax rules
m4_define(CF_dyn_rules,)
m4_define(CF_ADDTO, `m4_define([[CF_rule_$1]],m4_ifdef([[CF_rule_$1]],CF_rule_$1 | ,[[m4_define([[CF_dyn_rules]],CF_dyn_rules[[CF_RULE($1)
]])]])$2)DNL')
# CLI commands
m4_define(CF_CLI, `m4_define([[CF_cmd]], cmd_[[]]m4_translit($1, [[ ]], _))DNL
m4_divert(2)CF_KEYWORDS(m4_translit($1, [[ ]], [[,]]))
m4_divert(3)CF_ADDTO(cli_cmd, CF_cmd)
m4_divert(3)cli_cmd: CF_cmd
CF_cmd: $1 $2 END')
m4_define(CF_CLI_CMD, `')
m4_define(CF_CLI_HELP, `')
# ENUM declarations are ignored
m4_define(CF_ENUM, `')
m4_define(CF_ENUM_PX, `')
# After all configuration templates end, we finally generate the grammar file.
m4_m4wrap(`
@ -62,10 +58,6 @@ m4_undivert(2)DNL
%%
m4_undivert(3)DNL
/* Dynamic rules */
m4_define(CF_RULE, [[$1: CF_rule_$1 ;]])
CF_dyn_rules
%%
m4_undivert(4)DNL
')

View File

@ -18,6 +18,18 @@ AC_ARG_ENABLE([debug],
[enable_debug=no]
)
AC_ARG_ENABLE([debug-generated],
[AS_HELP_STRING([--enable-debug-generated], [enable this to abstain from generating #line @<:@no@:>@])],
[],
[enable_debug_generated=no]
)
AC_ARG_ENABLE([debug-expensive],
[AS_HELP_STRING([--enable-debug-expensive], [enable expensive consistency checks (implies --enable-debug) @<:@no@:>@])],
[],
[enable_debug_expensive=no]
)
AC_ARG_ENABLE([memcheck],
[AS_HELP_STRING([--enable-memcheck], [check memory allocations when debugging @<:@yes@:>@])],
[],
@ -31,7 +43,7 @@ AC_ARG_ENABLE([pthreads],
)
AC_ARG_ENABLE([libssh],
[AS_HELP_STRING([--enable-libssh], [enable LibSSH support together with RPKI @<:@try@:>@])],
[AS_HELP_STRING([--enable-libssh], [enable LibSSH support in RPKI @<:@try@:>@])],
[],
[enable_libssh=try]
)
@ -49,14 +61,12 @@ AC_ARG_WITH([protocols],
)
AC_ARG_WITH([sysconfig],
[AS_HELP_STRING([--with-sysconfig=FILE], [use specified BIRD system configuration file])],
[]
[AS_HELP_STRING([--with-sysconfig=FILE], [use specified BIRD system configuration file])]
)
AC_ARG_WITH([runtimedir],
[AS_HELP_STRING([--with-runtimedir=PATH], [path for runtime files @<:@LOCALSTATEDIR/run@:>@])],
[runtimedir="$with_runtimedir"],
[runtimedir="\$(localstatedir)/run"]
[AS_HELP_STRING([--with-runtimedir=PATH], [run-state data, obsolete variant of --runstatedir])],
[runstatedir="$with_runtimedir"]
)
AC_ARG_WITH([iproutedir],
@ -68,6 +78,9 @@ AC_ARG_VAR([FLEX], [location of the Flex program])
AC_ARG_VAR([BISON], [location of the Bison program])
AC_ARG_VAR([M4], [location of the M4 program])
if test "$enable_debug_expensive" = yes; then
enable_debug=yes
fi
if test "$srcdir" = . ; then
# Building in current directory => create obj directory holding all objects
@ -82,17 +95,15 @@ exedir=.
AC_SUBST([objdir])
AC_SUBST([exedir])
AC_SUBST([srcdir])
AC_SUBST([runtimedir])
# Workaround for older Autoconfs that do not define runstatedir
AS_IF([test -z "${runstatedir}"], [runstatedir='${localstatedir}/run'])
AC_SUBST([runstatedir])
if test "$enable_debug" = yes ; then
CONFIG_FILE="bird.conf"
CONTROL_SOCKET="bird.ctl"
else
CONFIG_FILE="\$(sysconfdir)/bird.conf"
CONTROL_SOCKET="$runtimedir/bird.ctl"
fi
CONFIG_FILE="\$(sysconfdir)/bird.conf"
AC_SUBST([CONFIG_FILE])
CONTROL_SOCKET="\$(runstatedir)/bird.ctl"
AC_SUBST([CONTROL_SOCKET])
AC_SEARCH_LIBS([clock_gettime], [rt posix4],
@ -113,6 +124,11 @@ if test -z "$GCC" ; then
AC_MSG_ERROR([This program requires the GNU C Compiler.])
fi
BIRD_CHECK_THREAD_LOCAL
if test "$bird_cv_thread_local" = yes ; then
AC_DEFINE([HAVE_THREAD_LOCAL], [1], [Define to 1 if _Thread_local is available])
fi
if test "$enable_pthreads" != no ; then
BIRD_CHECK_PTHREADS
@ -130,21 +146,35 @@ if test "$enable_pthreads" != no ; then
fi
fi
# This is assumed to be necessary for proper BIRD build
CFLAGS="$CFLAGS -fno-strict-aliasing -fno-strict-overflow"
if test "$bird_cflags_default" = yes ; then
BIRD_CHECK_GCC_OPTION([bird_cv_c_option_wno_pointer_sign], [-Wno-pointer-sign], [-Wall])
BIRD_CHECK_GCC_OPTION([bird_cv_c_option_wno_missing_init], [-Wno-missing-field-initializers], [-Wall -Wextra])
BIRD_CHECK_GCC_OPTION([bird_cv_c_option_fno_strict_aliasing], [-fno-strict-aliasing])
BIRD_CHECK_GCC_OPTION([bird_cv_c_option_fno_strict_overflow], [-fno-strict-overflow])
if test "$enable_debug" = no; then
BIRD_CHECK_LTO
fi
if test "$bird_cv_c_lto" = yes; then
CFLAGS="$CFLAGS -flto"
LDFLAGS="$LDFLAGS -flto=4 -g"
else
LDFLAGS="$LDFLAGS -g"
fi
CFLAGS="$CFLAGS -Wall -Wextra -Wstrict-prototypes -Wno-parentheses"
BIRD_ADD_GCC_OPTION([bird_cv_c_option_wno_pointer_sign], [-Wno-pointer-sign])
BIRD_ADD_GCC_OPTION([bird_cv_c_option_wno_missing_init], [-Wno-missing-field-initializers])
BIRD_ADD_GCC_OPTION([bird_cv_c_option_fno_strict_aliasing], [-fno-strict-aliasing])
BIRD_ADD_GCC_OPTION([bird_cv_c_option_fno_strict_overflow], [-fno-strict-overflow])
fi
AC_MSG_CHECKING([CFLAGS])
AC_MSG_RESULT([$CFLAGS])
AC_MSG_CHECKING([LDFLAGS])
AC_MSG_RESULT([$LDFLAGS])
AC_PROG_CPP
AC_PROG_INSTALL
@ -157,6 +187,20 @@ test -z "$FLEX" && AC_MSG_ERROR([Flex is missing.])
test -z "$BISON" && AC_MSG_ERROR([Bison is missing.])
test -z "$M4" && AC_MSG_ERROR([M4 is missing.])
AC_MSG_CHECKING([bison version])
BIRD_CHECK_BISON_VERSION(BISON_VERSION)
AC_MSG_RESULT([$BISON_VERSION])
if test "$bird_bison_synclines" = yes && test "$enable_debug_generated" = no; then
M4FLAGS="$M4FLAGS -s"
fi
if test "$bird_bison_enhanced_error" = yes; then
BISONFLAGS="$BISONFLAGS -Dparse.lac=full -Dparse.error=verbose"
fi
AC_SUBST([M4FLAGS])
AC_SUBST([BISONFLAGS])
BIRD_CHECK_PROG_FLAVOR_GNU([$M4],
[],
[AC_MSG_ERROR([Provided M4 is not GNU M4.])]
@ -181,6 +225,8 @@ else
;;
freebsd*)
sysdesc=bsd
CPPFLAGS="$CPPFLAGS -I/usr/local/include"
LDFLAGS="$LDFLAGS -L/usr/local/lib"
;;
kfreebsd*)
sysdesc=bsd
@ -234,7 +280,6 @@ if test "$enable_libssh" != no ; then
if test "$fail" != yes ; then
AC_DEFINE([HAVE_LIBSSH], [1], [Define to 1 if you have the `ssh' library (-lssh).])
DAEMON_LIBS="-lssh $DAEMON_LIBS"
proto_rpki=rpki
enable_libssh=yes
else
if test "$enable_libssh" = yes ; then
@ -259,7 +304,7 @@ if test "$enable_mpls_kernel" != no ; then
fi
fi
all_protocols="$proto_bfd babel bgp ospf pipe radv rip $proto_rpki static"
all_protocols="$proto_bfd babel bgp mrt ospf perf pipe radv rip rpki static"
all_protocols=`echo $all_protocols | sed 's/ /,/g'`
@ -270,6 +315,7 @@ fi
AH_TEMPLATE([CONFIG_BABEL], [Babel protocol])
AH_TEMPLATE([CONFIG_BFD], [BFD protocol])
AH_TEMPLATE([CONFIG_BGP], [BGP protocol])
AH_TEMPLATE([CONFIG_MRT], [MRT protocol])
AH_TEMPLATE([CONFIG_OSPF], [OSPF protocol])
AH_TEMPLATE([CONFIG_PIPE], [Pipe protocol])
AH_TEMPLATE([CONFIG_RADV], [RAdv protocol])
@ -313,10 +359,27 @@ AC_C_BIGENDIAN(
[AC_MSG_ERROR([Cannot determine CPU endianity.])]
)
BIRD_CHECK_ANDROID_GLOB
if test "$bird_cv_lib_glob" = no ; then
AC_MSG_ERROR([glob.h not found.])
elif test "$bird_cv_lib_glob" != yes ; then
LIBS="$LIBS $bird_cv_lib_glob"
fi
BIRD_CHECK_ANDROID_LOG
if test "$bird_cv_lib_log" = no ; then
AC_MSG_ERROR([don't know how to link syslog.])
elif test "$bird_cv_lib_log" != yes ; then
LIBS="$LIBS $bird_cv_lib_log"
fi
if test "$enable_debug" = yes ; then
AC_DEFINE([DEBUGGING], [1], [Define to 1 if debugging is enabled])
LDFLAGS="$LDFLAGS -rdynamic"
CFLAGS="$CFLAGS -O0 -ggdb -g3 -gdwarf-4"
CFLAGS="$CFLAGS -O0 -ggdb -g3"
BIRD_CHECK_GCC_OPTION([bird_cv_c_option_dwarf4], [-gdwarf-4], [])
BIRD_ADD_GCC_OPTION([bird_cv_c_option_dwarf4], [-gdwarf-4])
AC_CHECK_HEADER([execinfo.h],
[
@ -334,6 +397,10 @@ if test "$enable_debug" = yes ; then
AC_CHECK_LIB([efence], [malloc])
fi
fi
if test "enable_debug_expensive" = yes ; then
AC_DEFINE([ENABLE_EXPENSIVE_CHECKS], [1], [Define to 1 if you want to run expensive consistency checks.])
fi
fi
CLIENT=birdcl
@ -366,12 +433,6 @@ if test "$enable_client" = yes ; then
[$TINFO_LIBS]
)
AC_SEARCH_LIBS([add_history], [history readline],
[HISTORY_LIBS="$LIBS"; LIBS=""],
[AC_MSG_ERROR([The client requires GNU Readline library. Either install the library or use --disable-client to compile without the client.])],
[$TINFO_LIBS]
)
AC_CHECK_LIB([readline], [rl_crlf],
[AC_DEFINE([HAVE_RL_CRLF], [1], [Define to 1 if you have rl_crlf()])],
[],
@ -385,7 +446,7 @@ if test "$enable_client" = yes ; then
)
LIBS="$BASE_LIBS"
CLIENT_LIBS="$HISTORY_LIBS $READLINE_LIBS $TINFO_LIBS"
CLIENT_LIBS="$READLINE_LIBS $TINFO_LIBS"
fi
AC_SUBST([CLIENT])
AC_SUBST([CLIENT_LIBS])
@ -404,6 +465,7 @@ AC_MSG_RESULT([ System configuration: $sysdesc])
AC_MSG_RESULT([ Debugging: $enable_debug])
AC_MSG_RESULT([ POSIX threads: $enable_pthreads])
AC_MSG_RESULT([ Routing protocols: $protocols])
AC_MSG_RESULT([ LibSSH support in RPKI: $enable_libssh])
AC_MSG_RESULT([ Kernel MPLS support: $enable_mpls_kernel])
AC_MSG_RESULT([ Client: $enable_client])

View File

@ -1 +0,0 @@
D prog-intro.sgml

View File

@ -242,6 +242,7 @@ sub process_options
# removes iso-entites sub directory after doing make install.)
#
$ENV{SGML_CATALOG_FILES} .= (defined $ENV{SGML_CATALOG_FILES} ? ":" : "") .
"$main::prefix/share/sgml/sgml-iso-entities-8879.1986/catalog:" .
"$main::prefix/share/sgml/entities/sgml-iso-entities-8879.1986/catalog";
$ENV{SGML_CATALOG_FILES} .= ":$main::DataDir/linuxdoc-tools.catalog";
$ENV{SGML_CATALOG_FILES} .= ":$main::/etc/sgml.catalog";

View File

@ -1,222 +1,204 @@
/*
* This is an example configuration file
* (for version 1.x.x, obsolete)
*/
# Yes, even shell-like comments work...
# This is a basic configuration file, which contains boilerplate options and
# some basic examples. It allows the BIRD daemon to start but will not cause
# anything else to happen.
#
# Please refer to the BIRD User's Guide documentation, which is also available
# online at http://bird.network.cz/ in HTML format, for more information on
# configuring BIRD and adding routing protocols.
# Configure logging
#log syslog { debug, trace, info, remote, warning, error, auth, fatal, bug };
#log stderr all;
#log "tmp" all;
log syslog all;
# log "/var/log/bird.log" { debug, trace, info, remote, warning, error, auth, fatal, bug };
# Override router ID
#router id 198.51.100.1;
# Set router ID. It is a unique identification of your router, usually one of
# IPv4 addresses of the router. It is recommended to configure it explicitly.
# router id 198.51.100.1;
# You can define your own symbols...
#define xyzzy = (120+10);
#define '1a-a1' = (30+40);
# Define a route filter...
#filter test_filter {
# if net ~ 10.0.0.0/16 then accept;
# else reject;
#}
#filter sink { reject; }
#filter okay { accept; }
#include "filters.conf";
# Define another routing table
#table testable;
# Turn on global debugging of all protocols
#debug protocols all;
# Turn on global debugging of all protocols (all messages or just selected classes)
# debug protocols all;
# debug protocols { events, states };
# Turn on internal watchdog
#watchdog warning 5 s;
#watchdog timeout 30 s;
# watchdog warning 5 s;
# watchdog timeout 30 s;
# The direct protocol automatically generates device routes to
# all network interfaces. Can exist in as many instances as you wish
# if you want to populate multiple routing tables with device routes.
#protocol direct {
# interface "-eth*", "*"; # Restrict network interfaces it works with
#}
# You can define your own constants
# define my_asn = 65000;
# define my_addr = 198.51.100.1;
# This pseudo-protocol performs synchronization between BIRD's routing
# tables and the kernel. If your kernel supports multiple routing tables
# (as Linux 2.2.x does), you can run multiple instances of the kernel
# protocol and synchronize different kernel tables with different BIRD tables.
protocol kernel {
# learn; # Learn all alien routes from the kernel
persist; # Don't remove routes on bird shutdown
scan time 20; # Scan kernel routing table every 20 seconds
# import none; # Default is import all
export all; # Default is export none
# kernel table 5; # Kernel table to synchronize with (default: main)
}
# Tables master4 and master6 are defined by default
# ipv4 table master4;
# ipv6 table master6;
# This pseudo-protocol watches all interface up/down events.
# Define more tables, e.g. for policy routing or as MRIB
# ipv4 table mrib4;
# ipv6 table mrib6;
# The Device protocol is not a real routing protocol. It does not generate any
# routes and it only serves as a module for getting information about network
# interfaces from the kernel. It is necessary in almost any configuration.
protocol device {
scan time 10; # Scan interfaces every 10 seconds
}
# Static routes (again, there can be multiple instances, so that you
# can disable/enable various groups of static routes on the fly).
# The direct protocol is not a real routing protocol. It automatically generates
# direct routes to all network interfaces. Can exist in as many instances as you
# wish if you want to populate multiple routing tables with direct routes.
protocol direct {
disabled; # Disable by default
ipv4; # Connect to default IPv4 table
ipv6; # ... and to default IPv6 table
}
# The Kernel protocol is not a real routing protocol. Instead of communicating
# with other routers in the network, it performs synchronization of BIRD
# routing tables with the OS kernel. One instance per table.
protocol kernel {
ipv4 { # Connect protocol to IPv4 table by channel
# table master4; # Default IPv4 table is master4
# import all; # Import to table, default is import all
export all; # Export to protocol. default is export none
};
# learn; # Learn alien routes from the kernel
# kernel table 10; # Kernel table to synchronize with (default: main)
}
# Another instance for IPv6, skipping default options
protocol kernel {
ipv6 { export all; };
}
# Static routes (Again, there can be multiple instances, for different address
# families and to disable/enable various groups of static routes on the fly).
protocol static {
# disabled; # Disable by default
# table testable; # Connect to a non-default table
# preference 1000; # Default preference of routes
# debug { states, routes, filters, interfaces, events, packets };
# debug all;
# route 0.0.0.0/0 via 198.51.100.13;
# route 198.51.100.0/25 unreachable;
ipv4; # Again, IPv4 channel with default options
# route 0.0.0.0/0 via 198.51.100.10;
# route 192.0.2.0/24 blackhole;
# route 10.0.0.0/8 unreachable;
# route 10.1.1.0:255.255.255.0 via 198.51.100.3;
# route 10.1.2.0:255.255.255.0 via 198.51.100.3;
# route 10.1.3.0:255.255.255.0 via 198.51.100.4;
# route 10.2.0.0/24 via "arc0";
# route 10.2.0.0/24 via "eth0";
# # Static routes can be defined with optional attributes
# route 10.1.1.0/24 via 198.51.100.3 { rip_metric = 3; };
# route 10.1.2.0/24 via 198.51.100.3 { ospf_metric1 = 100; };
# route 10.1.3.0/24 via 198.51.100.4 { ospf_metric2 = 100; };
}
# Pipe protocol connects two routing tables... Beware of loops.
#protocol pipe {
# peer table testable;
# Define what routes do we export to this protocol / import from it.
# import all; # default is all
# export all; # default is none
# import none; # If you wish to disable imports
# import filter test_filter; # Use named filter
# import where source = RTS_DEVICE; # Use explicit filter
#}
# Pipe protocol connects two routing tables. Beware of loops.
# protocol pipe {
# table master4; # No ipv4/ipv6 channel definition like in other protocols
# peer table mrib4;
# import all; # Direction peer table -> table
# export all; # Direction table -> peer table
# }
# RIP aka Rest In Pieces...
#protocol rip MyRIP { # You can also use an explicit name
# preference xyzzy;
# debug all;
# port 1520;
# period 7;
# infinity 16;
# garbage time 60;
# interface "*" { mode broadcast; };
# honor neighbor; # To whom do we agree to send the routing table
# honor always;
# honor never;
# passwords {
# password "nazdar";
# RIP example, both RIP and RIPng are supported
# protocol rip {
# ipv4 {
# # Export direct, static routes and ones from RIP itself
# import all;
# export where source ~ [ RTS_DEVICE, RTS_STATIC, RTS_RIP ];
# };
# authentication none;
# import filter { print "importing"; accept; };
# export filter { print "exporting"; accept; };
#}
# interface "eth*" {
# update time 10; # Default period is 30
# timeout time 60; # Default timeout is 180
# authentication cryptographic; # No authentication by default
# password "hello" { algorithm hmac sha256; }; # Default is MD5
# };
# }
#protocol ospf MyOSPF {
# tick 2;
# rfc1583compat yes;
# area 0.0.0.0 {
# stub no;
# OSPF example, both OSPFv2 and OSPFv3 are supported
# protocol ospf v3 {
# ipv6 {
# import all;
# export where source = RTS_STATIC;
# };
# area 0 {
# interface "eth*" {
# hello 9;
# retransmit 6;
# cost 10;
# transmit delay 5;
# dead count 5;
# wait 50;
# type broadcast;
# authentication simple;
# password "pass";
# type broadcast; # Detected by default
# cost 10; # Interface metric
# hello 5; # Default hello perid 10 is too long
# };
# interface "arc0" {
# rx buffer large;
# type nonbroadcast;
# poll 14;
# dead 75;
# neighbors {
# 10.1.1.2 eligible;
# 10.1.1.4;
# };
# strict nonbroadcast yes;
# interface "tun*" {
# type ptp; # PtP mode, avoids DR selection
# cost 100; # Interface metric
# hello 5; # Default hello perid 10 is too long
# };
# interface "xxx0" {
# passwords {
# password "abc" {
# id 1;
# generate to "22-04-2003 11:00:06";
# accept to "17-01-2004 12:01:05";
# };
# password "def" {
# id 2;
# generate from "22-04-2003 11:00:07";
# accept from "17-01-2003 12:01:05";
# };
# };
# authentication cryptographic;
# interface "dummy0" {
# stub; # Stub interface, just propagate it
# };
# };
# area 20 {
# stub 1;
# interface "ppp1" {
# hello 8;
# authentication none;
# };
# interface "fr*";
# virtual link 192.168.0.1 {
# password "sdsdffsdfg";
# authentication cryptographic;
# };
# };
#}
# Define simple filter as an example for BGP import filter
# See https://gitlab.labs.nic.cz/labs/bird/wikis/BGP_filtering for more examples
# filter rt_import
# {
# if bgp_path.first != 64496 then accept;
# if bgp_path.len > 64 then accept;
# if bgp_next_hop != from then accept;
# reject;
# }
#protocol bgp {
# disabled;
# BGP example, explicit name 'uplink1' is used instead of default 'bgp1'
# protocol bgp uplink1 {
# description "My BGP uplink";
# local as 65000;
# neighbor 198.51.100.130 as 64496;
# multihop;
# hold time 240;
# startup hold time 240;
# connect retry time 120;
# keepalive time 80; # defaults to hold time / 3
# start delay time 5; # How long do we wait before initial connect
# error wait time 60, 300;# Minimum and maximum time we wait after an error (when consecutive
# # errors occur, we increase the delay exponentially ...
# error forget time 300; # ... until this timeout expires)
# disable after error; # Disable the protocol automatically when an error occurs
# next hop self; # Disable next hop processing and always advertise our local address as nexthop
# path metric 1; # Prefer routes with shorter paths (like Cisco does)
# default bgp_med 0; # MED value we use for comparison when none is defined
# default bgp_local_pref 0; # The same for local preference
# source address 198.51.100.14; # What local address we use for the TCP connection
# local 198.51.100.1 as 65000;
# neighbor 198.51.100.10 as 64496;
# hold time 90; # Default is 240
# password "secret"; # Password used for MD5 authentication
# rr client; # I am a route reflector and the neighor is my client
# rr cluster id 1.0.0.1; # Use this value for cluster id instead of my router id
# export where source=RTS_STATIC;
# export filter {
# if source = RTS_STATIC then {
# bgp_community = -empty-; bgp_community = add(bgp_community,(65000,5678));
# bgp_origin = 0;
# bgp_community = -empty-; bgp_community.add((65000,5678));
# if (65000,64501) ~ bgp_community then
# bgp_community.add((0, 1));
# if bgp_path ~ [= 65000 =] then
# bgp_path.prepend(65000);
# accept;
# }
# reject;
#
# ipv4 { # regular IPv4 unicast (1/1)
# import filter rt_import;
# export where source ~ [ RTS_STATIC, RTS_BGP ];
# };
#
# ipv6 { # regular IPv6 unicast (2/1)
# import filter rt_import;
# export filter { # The same as 'where' expression above
# if source ~ [ RTS_STATIC, RTS_BGP ]
# then accept;
# else reject;
# };
# };
#
# ipv4 multicast { # IPv4 multicast topology (1/2)
# table mrib4; # explicit IPv4 table
# import filter rt_import;
# export all;
# };
#
# ipv6 multicast { # IPv6 multicast topology (2/2)
# table mrib6; # explicit IPv6 table
# import filter rt_import;
# export all;
# };
#}
#
# Template usage example
#template bgp rr_client {
# disabled;
# local as 65000;
# multihop;
# Template example. Using templates to define IBGP route reflector clients.
# template bgp rr_clients {
# local 10.0.0.1 as 65000;
# neighbor as 65000;
# rr client;
# rr cluster id 1.0.0.1;
#}
#
#protocol bgp rr_abcd from rr_client {
# neighbor 10.1.4.7 as 65000;
#}
# ipv4 {
# import all;
# export where source = RTS_BGP;
# };
#
# ipv6 {
# import all;
# export where source = RTS_BGP;
# };
# }
#
# protocol bgp client1 from rr_clients {
# neighbor 10.0.1.1;
# }
#
# protocol bgp client2 from rr_clients {
# neighbor 10.0.2.1;
# }
#
# protocol bgp client3 from rr_clients {
# neighbor 10.0.3.1;
# }

View File

@ -1,5 +1,5 @@
/*
* This is an example configuration file for MB-BGP setting
* This is an example configuration file for MP-BGP setting
*/
@ -28,20 +28,15 @@ flow6 table flowtab6;
protocol device {
scan time 10;
}
protocol kernel kernel4 {
scan time 20;
ipv4 {
export all;
};
}
protocol kernel kernel6 {
scan time 20;
ipv6 {
export all;
};
@ -169,8 +164,6 @@ protocol pipe {
}
protocol ospf v2 ospf4 {
# ecmp;
ipv4 {
import all;
# export where source = RTS_STATIC;
@ -186,8 +179,6 @@ protocol ospf v2 ospf4 {
protocol ospf v3 ospf6 {
# ecmp;
ipv6 {
import all;
# export where source = RTS_STATIC;
@ -251,7 +242,7 @@ protocol bgp {
};
# IPv6 with MPLS labels (2/4)
ipv6 multicast {
ipv6 mpls {
# explicit IPv6 table
table mtab6;
import all;

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
D doc/prog-head.sgml
C doc
D doc/prog-intro.sgml
C nest
C conf
C filter

View File

@ -33,6 +33,7 @@ Reply codes of BIRD command-line interface
0022 Undo scheduled
0023 Evaluation of expression
0024 Graceful restart status report
0025 Graceful restart ordered
1000 BIRD version
1001 Interface list

View File

@ -34,7 +34,12 @@ $progs = {
"GROFFMACRO" => "-ms",
"AWK" => "/usr/share/linuxdoc-tools/awkwhich"
};
$ENV{"SGML_CATALOG_FILES"} = "$DataDir/dtd/catalog";
if (! -x $progs->{"NSGMLS"})
{ $progs->{"NSGMLS"} = "/usr/bin/onsgmls"; }
$ENV{"SGML_CATALOG_FILES"} = "$DataDir/dtd/catalog" .
(defined $ENV{SGML_CATALOG_FILES} ? ":$ENV{SGML_CATALOG_FILES}" : "");
require "$FindBin::Bin/LinuxDocTools.pm";
&LinuxDocTools::init;

View File

@ -34,7 +34,12 @@ $progs = {
"GROFFMACRO" => "-ms",
"AWK" => "/usr/share/linuxdoc-tools/awkwhich"
};
$ENV{"SGML_CATALOG_FILES"} = "$DataDir/dtd/catalog";
if (! -x $progs->{"NSGMLS"})
{ $progs->{"NSGMLS"} = "/usr/bin/onsgmls"; }
$ENV{"SGML_CATALOG_FILES"} = "$DataDir/dtd/catalog" .
(defined $ENV{SGML_CATALOG_FILES} ? ":$ENV{SGML_CATALOG_FILES}" : "");
require "$FindBin::Bin/LinuxDocTools.pm";
&LinuxDocTools::init;

View File

@ -34,7 +34,12 @@ $progs = {
"GROFFMACRO" => "-ms",
"AWK" => "/usr/share/linuxdoc-tools/awkwhich"
};
$ENV{"SGML_CATALOG_FILES"} = "$DataDir/dtd/catalog";
if (! -x $progs->{"NSGMLS"})
{ $progs->{"NSGMLS"} = "/usr/bin/onsgmls"; }
$ENV{"SGML_CATALOG_FILES"} = "$DataDir/dtd/catalog" .
(defined $ENV{SGML_CATALOG_FILES} ? ":$ENV{SGML_CATALOG_FILES}" : "");
require "$FindBin::Bin/LinuxDocTools.pm";
&LinuxDocTools::init;

View File

@ -1,8 +1,24 @@
src := filter.c f-util.c tree.c trie.c
src := filter.c data.c f-util.c tree.c trie.c inst-gen.c
obj := $(src-o-files)
$(all-daemon)
$(cf-local)
#M4FLAGS_FILTERS=$(filter-out -s,$(M4FLAGS))
M4FLAGS_FILTERS=$(M4FLAGS)
$(o)inst-gen.h: $(s)decl.m4 $(s)f-inst.c $(objdir)/.dir-stamp
$(M4) $(M4FLAGS_FILTERS) -DTARGET=H -P $^ >$@
$(o)inst-gen.c: $(s)decl.m4 $(s)f-inst.c $(objdir)/.dir-stamp
$(M4) $(M4FLAGS_FILTERS) -DTARGET=C -P $^ >$@
$(o)inst-interpret.c: $(s)decl.m4 $(s)f-inst.c $(objdir)/.dir-stamp
$(M4) $(M4FLAGS_FILTERS) -DTARGET=I -P $^ >$@
prepare: $(o)inst-interpret.c $(o)inst-gen.h
tests_src := tree_test.c filter_test.c trie_test.c
tests_targets := $(tests_targets) $(tests-target-files)
tests_objs := $(tests_objs) $(src-o-files)
$(call clean,inst-gen.h inst-gen.c inst-interpret.c)

File diff suppressed because it is too large Load Diff

601
filter/data.c Normal file
View File

@ -0,0 +1,601 @@
/*
* Filters: utility functions
*
* (c) 1998 Pavel Machek <pavel@ucw.cz>
* (c) 2019 Maria Matejka <mq@jmq.cz>
*
* Can be freely distributed and used under the terms of the GNU GPL.
*
*/
#include "nest/bird.h"
#include "lib/lists.h"
#include "lib/resource.h"
#include "lib/socket.h"
#include "lib/string.h"
#include "lib/unaligned.h"
#include "lib/net.h"
#include "lib/ip.h"
#include "nest/route.h"
#include "nest/protocol.h"
#include "nest/iface.h"
#include "nest/attrs.h"
#include "conf/conf.h"
#include "filter/filter.h"
#include "filter/f-inst.h"
#include "filter/data.h"
static const char * const f_type_str[] = {
[T_VOID] = "void",
[T_INT] = "int",
[T_BOOL] = "bool",
[T_PAIR] = "pair",
[T_QUAD] = "quad",
[T_ENUM_RTS] = "enum rts",
[T_ENUM_BGP_ORIGIN] = "enum bgp_origin",
[T_ENUM_SCOPE] = "enum scope",
[T_ENUM_RTC] = "enum rtc",
[T_ENUM_RTD] = "enum rtd",
[T_ENUM_ROA] = "enum roa",
[T_ENUM_NETTYPE] = "enum nettype",
[T_ENUM_RA_PREFERENCE] = "enum ra_preference",
[T_ENUM_AF] = "enum af",
[T_IP] = "ip",
[T_NET] = "prefix",
[T_STRING] = "string",
[T_PATH_MASK] = "bgpmask",
[T_PATH] = "bgppath",
[T_CLIST] = "clist",
[T_EC] = "ec",
[T_ECLIST] = "eclist",
[T_LC] = "lc",
[T_LCLIST] = "lclist",
[T_RD] = "rd",
};
const char *
f_type_name(enum f_type t)
{
if (t < ARRAY_SIZE(f_type_str))
return f_type_str[t] ?: "?";
if ((t == T_SET) || (t == T_PREFIX_SET))
return "set";
return "?";
}
const struct f_val f_const_empty_path = {
.type = T_PATH,
.val.ad = &null_adata,
}, f_const_empty_clist = {
.type = T_CLIST,
.val.ad = &null_adata,
}, f_const_empty_eclist = {
.type = T_ECLIST,
.val.ad = &null_adata,
}, f_const_empty_lclist = {
.type = T_LCLIST,
.val.ad = &null_adata,
};
static struct adata *
adata_empty(struct linpool *pool, int l)
{
struct adata *res = lp_alloc(pool, sizeof(struct adata) + l);
res->length = l;
return res;
}
static void
pm_format(const struct f_path_mask *p, buffer *buf)
{
int loop = 0;
buffer_puts(buf, "[= ");
for (uint i=0; i<p->len; i++)
{
switch(p->item[i].kind)
{
case PM_ASN:
buffer_print(buf, "%u ", p->item[i].asn);
break;
case PM_QUESTION:
buffer_puts(buf, "? ");
break;
case PM_ASTERISK:
buffer_puts(buf, "* ");
break;
case PM_LOOP:
loop = 1;
break;
case PM_ASN_RANGE:
buffer_print(buf, "%u..%u ", p->item[i].from, p->item[i].to);
break;
case PM_ASN_SET:
tree_format(p->item[i].set, buf);
buffer_puts(buf, " ");
break;
case PM_ASN_EXPR:
ASSERT(0);
}
if (loop && (p->item[i].kind != PM_LOOP))
{
buffer_puts(buf, "+ ");
loop = 0;
}
}
buffer_puts(buf, "=]");
}
static inline int
lcomm_cmp(lcomm v1, lcomm v2)
{
if (v1.asn != v2.asn)
return (v1.asn > v2.asn) ? 1 : -1;
if (v1.ldp1 != v2.ldp1)
return (v1.ldp1 > v2.ldp1) ? 1 : -1;
if (v1.ldp2 != v2.ldp2)
return (v1.ldp2 > v2.ldp2) ? 1 : -1;
return 0;
}
/**
* val_compare - compare two values
* @v1: first value
* @v2: second value
*
* Compares two values and returns -1, 0, 1 on <, =, > or F_CMP_ERROR on
* error. Tree module relies on this giving consistent results so
* that it can be used for building balanced trees.
*/
int
val_compare(const struct f_val *v1, const struct f_val *v2)
{
if (v1->type != v2->type) {
if (v1->type == T_VOID) /* Hack for else */
return -1;
if (v2->type == T_VOID)
return 1;
/* IP->Quad implicit conversion */
if ((v1->type == T_QUAD) && val_is_ip4(v2))
return uint_cmp(v1->val.i, ipa_to_u32(v2->val.ip));
if (val_is_ip4(v1) && (v2->type == T_QUAD))
return uint_cmp(ipa_to_u32(v1->val.ip), v2->val.i);
debug( "Types do not match in val_compare\n" );
return F_CMP_ERROR;
}
switch (v1->type) {
case T_VOID:
return 0;
case T_ENUM:
case T_INT:
case T_BOOL:
case T_PAIR:
case T_QUAD:
return uint_cmp(v1->val.i, v2->val.i);
case T_EC:
case T_RD:
return u64_cmp(v1->val.ec, v2->val.ec);
case T_LC:
return lcomm_cmp(v1->val.lc, v2->val.lc);
case T_IP:
return ipa_compare(v1->val.ip, v2->val.ip);
case T_NET:
return net_compare(v1->val.net, v2->val.net);
case T_STRING:
return strcmp(v1->val.s, v2->val.s);
default:
return F_CMP_ERROR;
}
}
static inline int
pmi_same(const struct f_path_mask_item *mi1, const struct f_path_mask_item *mi2)
{
if (mi1->kind != mi2->kind)
return 0;
switch (mi1->kind) {
case PM_ASN:
if (mi1->asn != mi2->asn)
return 0;
break;
case PM_ASN_EXPR:
if (!f_same(mi1->expr, mi2->expr))
return 0;
break;
case PM_ASN_RANGE:
if (mi1->from != mi2->from)
return 0;
if (mi1->to != mi2->to)
return 0;
break;
case PM_ASN_SET:
if (!same_tree(mi1->set, mi2->set))
return 0;
break;
}
return 1;
}
static int
pm_same(const struct f_path_mask *m1, const struct f_path_mask *m2)
{
if (m1->len != m2->len)
return 0;
for (uint i=0; i<m1->len; i++)
if (!pmi_same(&(m1->item[i]), &(m2->item[i])))
return 0;
return 1;
}
/**
* val_same - compare two values
* @v1: first value
* @v2: second value
*
* Compares two values and returns 1 if they are same and 0 if not.
* Comparison of values of different types is valid and returns 0.
*/
int
val_same(const struct f_val *v1, const struct f_val *v2)
{
int rc;
rc = val_compare(v1, v2);
if (rc != F_CMP_ERROR)
return !rc;
if (v1->type != v2->type)
return 0;
switch (v1->type) {
case T_PATH_MASK:
return pm_same(v1->val.path_mask, v2->val.path_mask);
case T_PATH_MASK_ITEM:
return pmi_same(&(v1->val.pmi), &(v2->val.pmi));
case T_PATH:
case T_CLIST:
case T_ECLIST:
case T_LCLIST:
return adata_same(v1->val.ad, v2->val.ad);
case T_SET:
return same_tree(v1->val.t, v2->val.t);
case T_PREFIX_SET:
return trie_same(v1->val.ti, v2->val.ti);
default:
bug("Invalid type in val_same(): %x", v1->type);
}
}
int
clist_set_type(const struct f_tree *set, struct f_val *v)
{
switch (set->from.type)
{
case T_PAIR:
v->type = T_PAIR;
return 1;
case T_QUAD:
v->type = T_QUAD;
return 1;
case T_IP:
if (val_is_ip4(&(set->from)) && val_is_ip4(&(set->to)))
{
v->type = T_QUAD;
return 1;
}
/* Fall through */
default:
v->type = T_VOID;
return 0;
}
}
static int
clist_match_set(const struct adata *clist, const struct f_tree *set)
{
if (!clist)
return 0;
struct f_val v;
if (!clist_set_type(set, &v))
return F_CMP_ERROR;
u32 *l = (u32 *) clist->data;
u32 *end = l + clist->length/4;
while (l < end) {
v.val.i = *l++;
if (find_tree(set, &v))
return 1;
}
return 0;
}
static int
eclist_match_set(const struct adata *list, const struct f_tree *set)
{
if (!list)
return 0;
if (!eclist_set_type(set))
return F_CMP_ERROR;
struct f_val v;
u32 *l = int_set_get_data(list);
int len = int_set_get_size(list);
int i;
v.type = T_EC;
for (i = 0; i < len; i += 2) {
v.val.ec = ec_get(l, i);
if (find_tree(set, &v))
return 1;
}
return 0;
}
static int
lclist_match_set(const struct adata *list, const struct f_tree *set)
{
if (!list)
return 0;
if (!lclist_set_type(set))
return F_CMP_ERROR;
struct f_val v;
u32 *l = int_set_get_data(list);
int len = int_set_get_size(list);
int i;
v.type = T_LC;
for (i = 0; i < len; i += 3) {
v.val.lc = lc_get(l, i);
if (find_tree(set, &v))
return 1;
}
return 0;
}
const struct adata *
clist_filter(struct linpool *pool, const struct adata *list, const struct f_val *set, int pos)
{
if (!list)
return NULL;
int tree = (set->type == T_SET); /* 1 -> set is T_SET, 0 -> set is T_CLIST */
struct f_val v;
if (tree)
clist_set_type(set->val.t, &v);
else
v.type = T_PAIR;
int len = int_set_get_size(list);
u32 *l = int_set_get_data(list);
u32 tmp[len];
u32 *k = tmp;
u32 *end = l + len;
while (l < end) {
v.val.i = *l++;
/* pos && member(val, set) || !pos && !member(val, set), member() depends on tree */
if ((tree ? !!find_tree(set->val.t, &v) : int_set_contains(set->val.ad, v.val.i)) == pos)
*k++ = v.val.i;
}
uint nl = (k - tmp) * sizeof(u32);
if (nl == list->length)
return list;
struct adata *res = adata_empty(pool, nl);
memcpy(res->data, tmp, nl);
return res;
}
const struct adata *
eclist_filter(struct linpool *pool, const struct adata *list, const struct f_val *set, int pos)
{
if (!list)
return NULL;
int tree = (set->type == T_SET); /* 1 -> set is T_SET, 0 -> set is T_CLIST */
struct f_val v;
int len = int_set_get_size(list);
u32 *l = int_set_get_data(list);
u32 tmp[len];
u32 *k = tmp;
int i;
v.type = T_EC;
for (i = 0; i < len; i += 2) {
v.val.ec = ec_get(l, i);
/* pos && member(val, set) || !pos && !member(val, set), member() depends on tree */
if ((tree ? !!find_tree(set->val.t, &v) : ec_set_contains(set->val.ad, v.val.ec)) == pos) {
*k++ = l[i];
*k++ = l[i+1];
}
}
uint nl = (k - tmp) * sizeof(u32);
if (nl == list->length)
return list;
struct adata *res = adata_empty(pool, nl);
memcpy(res->data, tmp, nl);
return res;
}
const struct adata *
lclist_filter(struct linpool *pool, const struct adata *list, const struct f_val *set, int pos)
{
if (!list)
return NULL;
int tree = (set->type == T_SET); /* 1 -> set is T_SET, 0 -> set is T_CLIST */
struct f_val v;
int len = int_set_get_size(list);
u32 *l = int_set_get_data(list);
u32 tmp[len];
u32 *k = tmp;
int i;
v.type = T_LC;
for (i = 0; i < len; i += 3) {
v.val.lc = lc_get(l, i);
/* pos && member(val, set) || !pos && !member(val, set), member() depends on tree */
if ((tree ? !!find_tree(set->val.t, &v) : lc_set_contains(set->val.ad, v.val.lc)) == pos)
k = lc_copy(k, l+i);
}
uint nl = (k - tmp) * sizeof(u32);
if (nl == list->length)
return list;
struct adata *res = adata_empty(pool, nl);
memcpy(res->data, tmp, nl);
return res;
}
/**
* val_in_range - implement |~| operator
* @v1: element
* @v2: set
*
* Checks if @v1 is element (|~| operator) of @v2.
*/
int
val_in_range(const struct f_val *v1, const struct f_val *v2)
{
if ((v1->type == T_PATH) && (v2->type == T_PATH_MASK))
return as_path_match(v1->val.ad, v2->val.path_mask);
if ((v1->type == T_INT) && (v2->type == T_PATH))
return as_path_contains(v2->val.ad, v1->val.i, 1);
if (((v1->type == T_PAIR) || (v1->type == T_QUAD)) && (v2->type == T_CLIST))
return int_set_contains(v2->val.ad, v1->val.i);
/* IP->Quad implicit conversion */
if (val_is_ip4(v1) && (v2->type == T_CLIST))
return int_set_contains(v2->val.ad, ipa_to_u32(v1->val.ip));
if ((v1->type == T_EC) && (v2->type == T_ECLIST))
return ec_set_contains(v2->val.ad, v1->val.ec);
if ((v1->type == T_LC) && (v2->type == T_LCLIST))
return lc_set_contains(v2->val.ad, v1->val.lc);
if ((v1->type == T_STRING) && (v2->type == T_STRING))
return patmatch(v2->val.s, v1->val.s);
if ((v1->type == T_IP) && (v2->type == T_NET))
return ipa_in_netX(v1->val.ip, v2->val.net);
if ((v1->type == T_NET) && (v2->type == T_NET))
return net_in_netX(v1->val.net, v2->val.net);
if ((v1->type == T_NET) && (v2->type == T_PREFIX_SET))
return trie_match_net(v2->val.ti, v1->val.net);
if (v2->type != T_SET)
return F_CMP_ERROR;
/* With integrated Quad<->IP implicit conversion */
if ((v1->type == v2->val.t->from.type) ||
((v1->type == T_QUAD) && val_is_ip4(&(v2->val.t->from)) && val_is_ip4(&(v2->val.t->to))))
return !!find_tree(v2->val.t, v1);
if (v1->type == T_CLIST)
return clist_match_set(v1->val.ad, v2->val.t);
if (v1->type == T_ECLIST)
return eclist_match_set(v1->val.ad, v2->val.t);
if (v1->type == T_LCLIST)
return lclist_match_set(v1->val.ad, v2->val.t);
if (v1->type == T_PATH)
return as_path_match_set(v1->val.ad, v2->val.t);
return F_CMP_ERROR;
}
/*
* val_format - format filter value
*/
void
val_format(const struct f_val *v, buffer *buf)
{
char buf2[1024];
switch (v->type)
{
case T_VOID: buffer_puts(buf, "(void)"); return;
case T_BOOL: buffer_puts(buf, v->val.i ? "TRUE" : "FALSE"); return;
case T_INT: buffer_print(buf, "%u", v->val.i); return;
case T_STRING: buffer_print(buf, "%s", v->val.s); return;
case T_IP: buffer_print(buf, "%I", v->val.ip); return;
case T_NET: buffer_print(buf, "%N", v->val.net); return;
case T_PAIR: buffer_print(buf, "(%u,%u)", v->val.i >> 16, v->val.i & 0xffff); return;
case T_QUAD: buffer_print(buf, "%R", v->val.i); return;
case T_EC: ec_format(buf2, v->val.ec); buffer_print(buf, "%s", buf2); return;
case T_LC: lc_format(buf2, v->val.lc); buffer_print(buf, "%s", buf2); return;
case T_RD: rd_format(v->val.ec, buf2, 1024); buffer_print(buf, "%s", buf2); return;
case T_PREFIX_SET: trie_format(v->val.ti, buf); return;
case T_SET: tree_format(v->val.t, buf); return;
case T_ENUM: buffer_print(buf, "(enum %x)%u", v->type, v->val.i); return;
case T_PATH: as_path_format(v->val.ad, buf2, 1000); buffer_print(buf, "(path %s)", buf2); return;
case T_CLIST: int_set_format(v->val.ad, 1, -1, buf2, 1000); buffer_print(buf, "(clist %s)", buf2); return;
case T_ECLIST: ec_set_format(v->val.ad, -1, buf2, 1000); buffer_print(buf, "(eclist %s)", buf2); return;
case T_LCLIST: lc_set_format(v->val.ad, -1, buf2, 1000); buffer_print(buf, "(lclist %s)", buf2); return;
case T_PATH_MASK: pm_format(v->val.path_mask, buf); return;
default: buffer_print(buf, "[unknown type %x]", v->type); return;
}
}
char *
val_format_str(struct linpool *lp, const struct f_val *v) {
buffer b;
LOG_BUFFER_INIT(b);
val_format(v, &b);
return lp_strdup(lp, b.start);
}
static char val_dump_buffer[1024];
const char *
val_dump(const struct f_val *v) {
static buffer b = {
.start = val_dump_buffer,
.end = val_dump_buffer + 1024,
};
b.pos = b.start;
val_format(v, &b);
return val_dump_buffer;
}

224
filter/data.h Normal file
View File

@ -0,0 +1,224 @@
/*
* BIRD Internet Routing Daemon -- Dynamic data structures
*
* (c) 1999 Pavel Machek <pavel@ucw.cz>
* (c) 2018--2019 Maria Matejka <mq@jmq.cz>
*
* Can be freely distributed and used under the terms of the GNU GPL.
*/
#ifndef _BIRD_FILTER_DATA_H_
#define _BIRD_FILTER_DATA_H_
#include "nest/bird.h"
/* Type numbers must be in 0..0xff range */
#define T_MASK 0xff
/* Internal types */
enum f_type {
/* Nothing. Simply nothing. */
T_VOID = 0,
/* User visible types, which fit in int */
T_INT = 0x10,
T_BOOL = 0x11,
T_PAIR = 0x12, /* Notice that pair is stored as integer: first << 16 | second */
T_QUAD = 0x13,
/* Put enumerational types in 0x30..0x3f range */
T_ENUM_LO = 0x30,
T_ENUM_HI = 0x3f,
T_ENUM_RTS = 0x30,
T_ENUM_BGP_ORIGIN = 0x31,
T_ENUM_SCOPE = 0x32,
T_ENUM_RTC = 0x33,
T_ENUM_RTD = 0x34,
T_ENUM_ROA = 0x35,
T_ENUM_NETTYPE = 0x36,
T_ENUM_RA_PREFERENCE = 0x37,
T_ENUM_AF = 0x38,
/* new enums go here */
T_ENUM_EMPTY = 0x3f, /* Special hack for atomic_aggr */
#define T_ENUM T_ENUM_LO ... T_ENUM_HI
/* Bigger ones */
T_IP = 0x20,
T_NET = 0x21,
T_STRING = 0x22,
T_PATH_MASK = 0x23, /* mask for BGP path */
T_PATH = 0x24, /* BGP path */
T_CLIST = 0x25, /* Community list */
T_EC = 0x26, /* Extended community value, u64 */
T_ECLIST = 0x27, /* Extended community list */
T_LC = 0x28, /* Large community value, lcomm */
T_LCLIST = 0x29, /* Large community list */
T_RD = 0x2a, /* Route distinguisher for VPN addresses */
T_PATH_MASK_ITEM = 0x2b, /* Path mask item for path mask constructors */
T_SET = 0x80,
T_PREFIX_SET = 0x81,
} PACKED;
/* Filter value; size of this affects filter memory consumption */
struct f_val {
enum f_type type; /* T_* */
union {
uint i;
u64 ec;
lcomm lc;
ip_addr ip;
const net_addr *net;
const char *s;
const struct f_tree *t;
const struct f_trie *ti;
const struct adata *ad;
const struct f_path_mask *path_mask;
struct f_path_mask_item pmi;
} val;
};
/* Dynamic attribute definition (eattrs) */
struct f_dynamic_attr {
u8 type; /* EA type (EAF_*) */
u8 bit; /* For bitfield accessors */
enum f_type f_type; /* Filter type */
uint ea_code; /* EA code */
};
enum f_sa_code {
SA_FROM = 1,
SA_GW,
SA_NET,
SA_PROTO,
SA_SOURCE,
SA_SCOPE,
SA_DEST,
SA_IFNAME,
SA_IFINDEX,
SA_WEIGHT,
} PACKED;
/* Static attribute definition (members of struct rta) */
struct f_static_attr {
enum f_type f_type; /* Filter type */
enum f_sa_code sa_code; /* Static attribute id */
int readonly:1; /* Don't allow writing */
};
/* Filter l-value type */
enum f_lval_type {
F_LVAL_VARIABLE,
F_LVAL_PREFERENCE,
F_LVAL_SA,
F_LVAL_EA,
};
/* Filter l-value */
struct f_lval {
enum f_lval_type type;
union {
struct symbol *sym;
struct f_dynamic_attr da;
struct f_static_attr sa;
};
};
/* IP prefix range structure */
struct f_prefix {
net_addr net; /* The matching prefix must match this net */
u8 lo, hi; /* And its length must fit between lo and hi */
};
struct f_tree {
struct f_tree *left, *right;
struct f_val from, to;
void *data;
};
struct f_trie_node4
{
ip4_addr addr, mask, accept;
uint plen;
struct f_trie_node4 *c[2];
};
struct f_trie_node6
{
ip6_addr addr, mask, accept;
uint plen;
struct f_trie_node6 *c[2];
};
struct f_trie_node
{
union {
struct f_trie_node4 v4;
struct f_trie_node6 v6;
};
};
struct f_trie
{
linpool *lp;
u8 zero;
s8 ipv4; /* -1 for undefined / empty */
u16 data_size; /* Additional data for each trie node */
struct f_trie_node root; /* Root trie node */
};
struct f_tree *f_new_tree(void);
struct f_tree *build_tree(struct f_tree *);
const struct f_tree *find_tree(const struct f_tree *t, const struct f_val *val);
int same_tree(const struct f_tree *t0, const struct f_tree *t2);
void tree_format(const struct f_tree *t, buffer *buf);
void tree_walk(const struct f_tree *t, void (*hook)(const struct f_tree *, void *), void *data);
struct f_trie *f_new_trie(linpool *lp, uint data_size);
void *trie_add_prefix(struct f_trie *t, const net_addr *n, uint l, uint h);
int trie_match_net(const struct f_trie *t, const net_addr *n);
int trie_same(const struct f_trie *t1, const struct f_trie *t2);
void trie_format(const struct f_trie *t, buffer *buf);
#define F_CMP_ERROR 999
const char *f_type_name(enum f_type t);
int val_same(const struct f_val *v1, const struct f_val *v2);
int val_compare(const struct f_val *v1, const struct f_val *v2);
void val_format(const struct f_val *v, buffer *buf);
char *val_format_str(struct linpool *lp, const struct f_val *v);
const char *val_dump(const struct f_val *v);
static inline int val_is_ip4(const struct f_val *v)
{ return (v->type == T_IP) && ipa_is_ip4(v->val.ip); }
int val_in_range(const struct f_val *v1, const struct f_val *v2);
int clist_set_type(const struct f_tree *set, struct f_val *v);
static inline int eclist_set_type(const struct f_tree *set)
{ return set->from.type == T_EC; }
static inline int lclist_set_type(const struct f_tree *set)
{ return set->from.type == T_LC; }
const struct adata *clist_filter(struct linpool *pool, const struct adata *list, const struct f_val *set, int pos);
const struct adata *eclist_filter(struct linpool *pool, const struct adata *list, const struct f_val *set, int pos);
const struct adata *lclist_filter(struct linpool *pool, const struct adata *list, const struct f_val *set, int pos);
/* Special undef value for paths and clists */
static inline int
undef_value(struct f_val v)
{
return ((v.type == T_PATH) || (v.type == T_CLIST) ||
(v.type == T_ECLIST) || (v.type == T_LCLIST)) &&
(v.val.ad == &null_adata);
}
extern const struct f_val f_const_empty_path, f_const_empty_clist, f_const_empty_eclist, f_const_empty_lclist;
enum filter_return f_eval(const struct f_line *expr, struct linpool *tmp_pool, struct f_val *pres);
#endif

673
filter/decl.m4 Normal file
View File

@ -0,0 +1,673 @@
m4_divert(-1)m4_dnl
#
# BIRD -- Construction of per-instruction structures
#
# (c) 2018 Maria Matejka <mq@jmq.cz>
#
# Can be freely distributed and used under the terms of the GNU GPL.
#
# THIS IS A M4 MACRO FILE GENERATING 3 FILES ALTOGETHER.
# KEEP YOUR HANDS OFF UNLESS YOU KNOW WHAT YOU'RE DOING.
# EDITING AND DEBUGGING THIS FILE MAY DAMAGE YOUR BRAIN SERIOUSLY.
#
# But you're welcome to read and edit and debug if you aren't scared.
#
# Uncomment the following line to get exhaustive debug output.
# m4_debugmode(aceflqtx)
#
# How it works:
# 1) Instruction to code conversion (uses diversions 100..199)
# 2) Code wrapping (uses diversions 1..99)
# 3) Final preparation (uses diversions 200..299)
# 4) Shipout
#
# See below for detailed description.
#
#
# 1) Instruction to code conversion
# The code provided in f-inst.c between consecutive INST() calls
# is interleaved for many different places. It is here processed
# and split into separate instances where split-by-instruction
# happens. These parts are stored in temporary diversions listed:
#
# 101 content of per-inst struct
# 102 constructor arguments
# 103 constructor body
# 104 dump line item content
# (there may be nothing in dump-line content and
# it must be handled specially in phase 2)
# 105 linearize body
# 106 comparator body
# 107 struct f_line_item content
# 108 interpreter body
# 109 iterator body
#
# Here are macros to allow you to _divert to the right directions.
m4_define(FID_STRUCT_IN, `m4_divert(101)')
m4_define(FID_NEW_ARGS, `m4_divert(102)')
m4_define(FID_NEW_BODY, `m4_divert(103)')
m4_define(FID_DUMP_BODY, `m4_divert(104)m4_define([[FID_DUMP_BODY_EXISTS]])')
m4_define(FID_LINEARIZE_BODY, `m4_divert(105)')
m4_define(FID_SAME_BODY, `m4_divert(106)')
m4_define(FID_LINE_IN, `m4_divert(107)')
m4_define(FID_INTERPRET_BODY, `m4_divert(108)')
m4_define(FID_ITERATE_BODY, `m4_divert(109)')
# Sometimes you want slightly different code versions in different
# outputs.
# Use FID_HIC(code for inst-gen.h, code for inst-gen.c, code for inst-interpret.c)
# and put it into [[ ]] quotes if it shall contain commas.
m4_define(FID_HIC, `m4_ifelse(TARGET, [[H]], [[$1]], TARGET, [[I]], [[$2]], TARGET, [[C]], [[$3]])')
# In interpreter code, this is quite common.
m4_define(FID_INTERPRET_EXEC, `FID_HIC(,[[FID_INTERPRET_BODY()]],[[m4_divert(-1)]])')
m4_define(FID_INTERPRET_NEW, `FID_HIC(,[[m4_divert(-1)]],[[FID_INTERPRET_BODY()]])')
# If the instruction is never converted to constant, the interpret
# code is not produced at all for constructor
m4_define(NEVER_CONSTANT, `m4_define([[INST_NEVER_CONSTANT]])')
m4_define(FID_IFCONST, `m4_ifdef([[INST_NEVER_CONSTANT]],[[$2]],[[$1]])')
# If the instruction has some attributes (here called members),
# these are typically carried with the instruction from constructor
# to interpreter. This yields a line of code everywhere on the path.
# FID_MEMBER is a macro to help with this task.
m4_define(FID_MEMBER, `m4_dnl
FID_LINE_IN()m4_dnl
$1 $2;
FID_STRUCT_IN()m4_dnl
$1 $2;
FID_NEW_ARGS()m4_dnl
, $1 $2
FID_NEW_BODY()m4_dnl
whati->$2 = $2;
FID_LINEARIZE_BODY()m4_dnl
item->$2 = whati->$2;
m4_ifelse($3,,,[[
FID_SAME_BODY()m4_dnl
if ($3) return 0;
]])
m4_ifelse($4,,,[[
FID_DUMP_BODY()m4_dnl
debug("%s" $4 "\n", INDENT, $5);
]])
FID_INTERPRET_EXEC()m4_dnl
const $1 $2 = whati->$2
FID_INTERPRET_BODY')
# Instruction arguments are needed only until linearization is done.
# This puts the arguments into the filter line to be executed before
# the instruction itself.
#
# To achieve this, ARG_ANY must be called before anything writes into
# the instruction line as it moves the instruction pointer forward.
m4_define(ARG_ANY, `
FID_STRUCT_IN()m4_dnl
struct f_inst * f$1;
FID_NEW_ARGS()m4_dnl
, struct f_inst * f$1
FID_NEW_BODY()m4_dnl
whati->f$1 = f$1;
for (const struct f_inst *child = f$1; child; child = child->next) {
what->size += child->size;
FID_IFCONST([[
if (child->fi_code != FI_CONSTANT)
constargs = 0;
]])
}
FID_LINEARIZE_BODY
pos = linearize(dest, whati->f$1, pos);
FID_INTERPRET_BODY()')
# Some instructions accept variable number of arguments.
m4_define(VARARG, `
FID_NEW_ARGS()m4_dnl
, struct f_inst * fvar
FID_STRUCT_IN()m4_dnl
struct f_inst * fvar;
uint varcount;
FID_LINE_IN()m4_dnl
uint varcount;
FID_NEW_BODY()m4_dnl
whati->varcount = 0;
whati->fvar = fvar;
for (const struct f_inst *child = fvar; child; child = child->next, whati->varcount++) {
what->size += child->size;
FID_IFCONST([[
if (child->fi_code != FI_CONSTANT)
constargs = 0;
]])
}
FID_IFCONST([[
const struct f_inst **items = NULL;
if (constargs && whati->varcount) {
items = alloca(whati->varcount * sizeof(struct f_inst *));
const struct f_inst *child = fvar;
for (uint i=0; child; i++)
child = (items[i] = child)->next;
}
]])
FID_LINEARIZE_BODY()m4_dnl
pos = linearize(dest, whati->fvar, pos);
item->varcount = whati->varcount;
FID_DUMP_BODY()m4_dnl
debug("%snumber of varargs %u\n", INDENT, item->varcount);
FID_SAME_BODY()m4_dnl
if (f1->varcount != f2->varcount) return 0;
FID_INTERPRET_BODY()
FID_HIC(,[[
if (fstk->vcnt < whati->varcount) runtime("Stack underflow");
fstk->vcnt -= whati->varcount;
]],)
')
# Some arguments need to check their type. After that, ARG_ANY is called.
m4_define(ARG, `ARG_ANY($1) ARG_TYPE($1,$2)')
m4_define(ARG_TYPE, `ARG_TYPE_STATIC($1,$2) ARG_TYPE_DYNAMIC($1,$2)')
m4_define(ARG_TYPE_STATIC, `
FID_NEW_BODY()m4_dnl
if (f$1->type && (f$1->type != ($2)) && !f_const_promotion(f$1, ($2)))
cf_error("Argument $1 of %s must be of type %s, got type %s",
f_instruction_name(what->fi_code), f_type_name($2), f_type_name(f$1->type));
FID_INTERPRET_BODY()')
m4_define(ARG_TYPE_DYNAMIC, `
FID_INTERPRET_EXEC()m4_dnl
if (v$1.type != ($2))
runtime("Argument $1 of %s must be of type %s, got type %s",
f_instruction_name(what->fi_code), f_type_name($2), f_type_name(v$1.type));
FID_INTERPRET_BODY()')
m4_define(ARG_SAME_TYPE, `
FID_NEW_BODY()m4_dnl
if (f$1->type && f$2->type && (f$1->type != f$2->type) &&
!f_const_promotion(f$2, f$1->type) && !f_const_promotion(f$1, f$2->type))
cf_error("Arguments $1 and $2 of %s must be of the same type", f_instruction_name(what->fi_code));
FID_INTERPRET_BODY()')
# Executing another filter line. This replaces the recursion
# that was needed in the former implementation.
m4_define(LINEX, `FID_INTERPRET_EXEC()LINEX_($1)FID_INTERPRET_NEW()return $1 FID_INTERPRET_BODY()')
m4_define(LINEX_, `do {
fstk->estk[fstk->ecnt].pos = 0;
fstk->estk[fstk->ecnt].line = $1;
fstk->estk[fstk->ecnt].ventry = fstk->vcnt;
fstk->estk[fstk->ecnt].vbase = fstk->estk[fstk->ecnt-1].vbase;
fstk->estk[fstk->ecnt].emask = 0;
fstk->ecnt++;
} while (0)')
m4_define(LINE, `
FID_LINE_IN()m4_dnl
const struct f_line * fl$1;
FID_STRUCT_IN()m4_dnl
struct f_inst * f$1;
FID_NEW_ARGS()m4_dnl
, struct f_inst * f$1
FID_NEW_BODY()m4_dnl
whati->f$1 = f$1;
FID_DUMP_BODY()m4_dnl
f_dump_line(item->fl$1, indent + 1);
FID_LINEARIZE_BODY()m4_dnl
item->fl$1 = f_linearize(whati->f$1);
FID_SAME_BODY()m4_dnl
if (!f_same(f1->fl$1, f2->fl$1)) return 0;
FID_ITERATE_BODY()m4_dnl
if (whati->fl$1) BUFFER_PUSH(fit->lines) = whati->fl$1;
FID_INTERPRET_EXEC()m4_dnl
do { if (whati->fl$1) {
LINEX_(whati->fl$1);
} } while(0)
FID_INTERPRET_NEW()m4_dnl
return whati->f$1
FID_INTERPRET_BODY()')
# Some of the instructions have a result. These constructions
# state the result and put it to the right place.
m4_define(RESULT, `RESULT_TYPE([[$1]]) RESULT_([[$1]],[[$2]],[[$3]])')
m4_define(RESULT_, `RESULT_VAL([[ (struct f_val) { .type = $1, .val.$2 = $3 } ]])')
m4_define(RESULT_VAL, `FID_HIC(, [[do { res = $1; fstk->vcnt++; } while (0)]],
[[return fi_constant(what, $1)]])')
m4_define(RESULT_VOID, `RESULT_VAL([[ (struct f_val) { .type = T_VOID } ]])')
m4_define(ERROR,
`m4_errprint(m4___file__:m4___line__: $*
)m4_m4exit(1)')
# This macro specifies result type and makes there are no conflicting definitions
m4_define(RESULT_TYPE,
`m4_ifdef([[INST_RESULT_TYPE]],
[[m4_ifelse(INST_RESULT_TYPE,$1,,[[ERROR([[Multiple type definitons]])]])]],
[[m4_define(INST_RESULT_TYPE,$1) RESULT_TYPE_($1)]])')
m4_define(RESULT_TYPE_, `
FID_NEW_BODY()m4_dnl
what->type = $1;
FID_INTERPRET_BODY()')
# Some common filter instruction members
m4_define(SYMBOL, `FID_MEMBER(struct symbol *, sym, [[strcmp(f1->sym->name, f2->sym->name) || (f1->sym->class != f2->sym->class)]], "symbol %s", item->sym->name)')
m4_define(RTC, `FID_MEMBER(struct rtable_config *, rtc, [[strcmp(f1->rtc->name, f2->rtc->name)]], "route table %s", item->rtc->name)')
m4_define(STATIC_ATTR, `FID_MEMBER(struct f_static_attr, sa, f1->sa.sa_code != f2->sa.sa_code,,)')
m4_define(DYNAMIC_ATTR, `FID_MEMBER(struct f_dynamic_attr, da, f1->da.ea_code != f2->da.ea_code,,)')
m4_define(ACCESS_RTE, `FID_HIC(,[[do { if (!fs->rte) runtime("No route to access"); } while (0)]],NEVER_CONSTANT())')
# 2) Code wrapping
# The code produced in 1xx temporary diversions is a raw code without
# any auxiliary commands and syntactical structures around. When the
# instruction is done, INST_FLUSH is called. More precisely, it is called
# at the beginning of INST() call and at the end of file.
#
# INST_FLUSH picks all the temporary diversions, wraps their content
# into appropriate headers and structures and saves them into global
# diversions listed:
#
# 4 enum fi_code
# 5 enum fi_code to string
# 6 dump line item
# 7 dump line item callers
# 8 linearize
# 9 same (filter comparator)
# 10 iterate
# 1 union in struct f_inst
# 3 constructors + interpreter
#
# These global diversions contain blocks of code that can be directly
# put into the final file, yet it still can't be written out now as
# every instruction writes to all of these diversions.
# Code wrapping diversion names. Here we want an explicit newline
# after the C comment.
m4_define(FID_ZONE, `m4_divert($1) /* $2 for INST_NAME() */
')
m4_define(FID_INST, `FID_ZONE(1, Instruction structure for config)')
m4_define(FID_LINE, `FID_ZONE(2, Instruction structure for interpreter)')
m4_define(FID_NEW, `FID_ZONE(3, Constructor)')
m4_define(FID_ENUM, `FID_ZONE(4, Code enum)')
m4_define(FID_ENUM_STR, `FID_ZONE(5, Code enum to string)')
m4_define(FID_DUMP, `FID_ZONE(6, Dump line)')
m4_define(FID_DUMP_CALLER, `FID_ZONE(7, Dump line caller)')
m4_define(FID_LINEARIZE, `FID_ZONE(8, Linearize)')
m4_define(FID_SAME, `FID_ZONE(9, Comparison)')
m4_define(FID_ITERATE, `FID_ZONE(10, Iteration)')
# This macro does all the code wrapping. See inline comments.
m4_define(INST_FLUSH, `m4_ifdef([[INST_NAME]], [[
FID_ENUM()m4_dnl Contents of enum fi_code { ... }
INST_NAME(),
FID_ENUM_STR()m4_dnl Contents of const char * indexed by enum fi_code
[INST_NAME()] = "INST_NAME()",
FID_INST()m4_dnl Anonymous structure inside struct f_inst
struct {
m4_undivert(101)m4_dnl
} i_[[]]INST_NAME();
FID_LINE()m4_dnl Anonymous structure inside struct f_line_item
struct {
m4_undivert(107)m4_dnl
} i_[[]]INST_NAME();
FID_NEW()m4_dnl Constructor and interpreter code together
FID_HIC(
[[m4_dnl Public declaration of constructor in H file
struct f_inst *f_new_inst_]]INST_NAME()[[(enum f_instruction_code fi_code
m4_undivert(102)m4_dnl
);]],
[[m4_dnl The one case in The Big Switch inside interpreter
case INST_NAME():
#define whati (&(what->i_]]INST_NAME()[[))
m4_ifelse(m4_eval(INST_INVAL() > 0), 1, [[if (fstk->vcnt < INST_INVAL()) runtime("Stack underflow"); fstk->vcnt -= INST_INVAL(); ]])
m4_undivert(108)m4_dnl
#undef whati
break;
]],
[[m4_dnl Constructor itself
struct f_inst *f_new_inst_]]INST_NAME()[[(enum f_instruction_code fi_code
m4_undivert(102)m4_dnl
)
{
/* Allocate the structure */
struct f_inst *what = fi_new(fi_code);
FID_IFCONST([[uint constargs = 1;]])
/* Initialize all the members */
#define whati (&(what->i_]]INST_NAME()[[))
m4_undivert(103)m4_dnl
/* If not constant, return the instruction itself */
FID_IFCONST([[if (!constargs)]])
return what;
/* Try to pre-calculate the result */
FID_IFCONST([[m4_undivert(108)]])m4_dnl
#undef whati
}
]])
FID_DUMP_CALLER()m4_dnl Case in another big switch used in instruction dumping (debug)
case INST_NAME(): f_dump_line_item_]]INST_NAME()[[(item, indent + 1); break;
FID_DUMP()m4_dnl The dumper itself
m4_ifdef([[FID_DUMP_BODY_EXISTS]],
[[static inline void f_dump_line_item_]]INST_NAME()[[(const struct f_line_item *item_, const int indent)]],
[[static inline void f_dump_line_item_]]INST_NAME()[[(const struct f_line_item *item UNUSED, const int indent UNUSED)]])
m4_undefine([[FID_DUMP_BODY_EXISTS]])
{
#define item (&(item_->i_]]INST_NAME()[[))
m4_undivert(104)m4_dnl
#undef item
}
FID_LINEARIZE()m4_dnl The linearizer
case INST_NAME(): {
#define whati (&(what->i_]]INST_NAME()[[))
#define item (&(dest->items[pos].i_]]INST_NAME()[[))
m4_undivert(105)m4_dnl
#undef whati
#undef item
dest->items[pos].fi_code = what->fi_code;
dest->items[pos].lineno = what->lineno;
break;
}
FID_SAME()m4_dnl This code compares two f_line"s while reconfiguring
case INST_NAME():
#define f1 (&(f1_->i_]]INST_NAME()[[))
#define f2 (&(f2_->i_]]INST_NAME()[[))
m4_undivert(106)m4_dnl
#undef f1
#undef f2
break;
FID_ITERATE()m4_dnl The iterator
case INST_NAME():
#define whati (&(what->i_]]INST_NAME()[[))
m4_undivert(109)m4_dnl
#undef whati
break;
m4_divert(-1)FID_FLUSH(101,200)m4_dnl And finally this flushes all the unused diversions
]])')
m4_define(INST, `m4_dnl This macro is called on beginning of each instruction.
INST_FLUSH()m4_dnl First, old data is flushed
m4_define([[INST_NAME]], [[$1]])m4_dnl Then we store instruction name,
m4_define([[INST_INVAL]], [[$2]])m4_dnl instruction input value count,
m4_undefine([[INST_NEVER_CONSTANT]])m4_dnl reset NEVER_CONSTANT trigger,
m4_undefine([[INST_RESULT_TYPE]])m4_dnl and reset RESULT_TYPE value.
FID_INTERPRET_BODY()m4_dnl By default, every code is interpreter code.
')
# 3) Final preparation
#
# Now we prepare all the code around the global diversions.
# It must be here, not in m4wrap, as we want M4 to mark the code
# by #line directives correctly, not to claim that every single line
# is at the beginning of the m4wrap directive.
#
# This part is split by the final file.
# H for inst-gen.h
# I for inst-interpret.c
# C for inst-gen.c
#
# So we in cycle:
# A. open a diversion
# B. send there some code
# C. close that diversion
# D. flush a global diversion
# E. open another diversion and goto B.
#
# Final diversions
# 200+ completed text before it is flushed to output
# This is a list of output diversions
m4_define(FID_WR_PUT_LIST)
# This macro does the steps C to E, see before.
m4_define(FID_WR_PUT_ALSO, `m4_define([[FID_WR_PUT_LIST]],FID_WR_PUT_LIST()[[FID_WR_DPUT(]]FID_WR_DIDX[[)FID_WR_DPUT(]]$1[[)]])m4_define([[FID_WR_DIDX]],m4_eval(FID_WR_DIDX+1))m4_divert(FID_WR_DIDX)')
# These macros do the splitting between H/I/C
m4_define(FID_WR_DIRECT, `m4_ifelse(TARGET,[[$1]],[[FID_WR_INIT()]],[[FID_WR_STOP()]])')
m4_define(FID_WR_INIT, `m4_define([[FID_WR_DIDX]],200)m4_define([[FID_WR_PUT]],[[FID_WR_PUT_ALSO($]][[@)]])m4_divert(200)')
m4_define(FID_WR_STOP, `m4_define([[FID_WR_PUT]])m4_divert(-1)')
# Here is the direct code to be put into the output files
# together with the undiversions, being hidden under FID_WR_PUT()
m4_changequote([[,]])
FID_WR_DIRECT(I)
FID_WR_PUT(3)
FID_WR_DIRECT(C)
#if defined(__GNUC__) && __GNUC__ >= 6
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmisleading-indentation"
#endif
#include "nest/bird.h"
#include "filter/filter.h"
#include "filter/f-inst.h"
/* Instruction codes to string */
static const char * const f_instruction_name_str[] = {
FID_WR_PUT(5)
};
const char *
f_instruction_name_(enum f_instruction_code fi)
{
if (fi < (sizeof(f_instruction_name_str) / sizeof(f_instruction_name_str[0])))
return f_instruction_name_str[fi];
else
bug("Got unknown instruction code: %d", fi);
}
static inline struct f_inst *
fi_new(enum f_instruction_code fi_code)
{
struct f_inst *what = cfg_allocz(sizeof(struct f_inst));
what->lineno = ifs->lino;
what->size = 1;
what->fi_code = fi_code;
return what;
}
static inline struct f_inst *
fi_constant(struct f_inst *what, struct f_val val)
{
what->fi_code = FI_CONSTANT;
what->i_FI_CONSTANT.val = val;
return what;
}
static int
f_const_promotion(struct f_inst *arg, enum f_type want)
{
if (arg->fi_code != FI_CONSTANT)
return 0;
struct f_val *c = &arg->i_FI_CONSTANT.val;
if ((c->type == T_IP) && ipa_is_ip4(c->val.ip) && (want == T_QUAD)) {
*c = (struct f_val) {
.type = T_QUAD,
.val.i = ipa_to_u32(c->val.ip),
};
return 1;
}
return 0;
}
#define v1 whati->f1->i_FI_CONSTANT.val
#define v2 whati->f2->i_FI_CONSTANT.val
#define v3 whati->f3->i_FI_CONSTANT.val
#define vv(i) items[i]->i_FI_CONSTANT.val
#define runtime(fmt, ...) cf_error("filter preevaluation, line %d: " fmt, ifs->lino, ##__VA_ARGS__)
#define fpool cfg_mem
#define falloc(size) cfg_alloc(size)
/* Instruction constructors */
FID_WR_PUT(3)
#undef v1
#undef v2
#undef v3
#undef vv
/* Line dumpers */
#define INDENT (((const char *) f_dump_line_indent_str) + sizeof(f_dump_line_indent_str) - (indent) - 1)
static const char f_dump_line_indent_str[] = " ";
FID_WR_PUT(6)
void f_dump_line(const struct f_line *dest, uint indent)
{
if (!dest) {
debug("%sNo filter line (NULL)\n", INDENT);
return;
}
debug("%sFilter line %p (len=%u)\n", INDENT, dest, dest->len);
for (uint i=0; i<dest->len; i++) {
const struct f_line_item *item = &dest->items[i];
debug("%sInstruction %s at line %u\n", INDENT, f_instruction_name_(item->fi_code), item->lineno);
switch (item->fi_code) {
FID_WR_PUT(7)
default: bug("Unknown instruction %x in f_dump_line", item->fi_code);
}
}
debug("%sFilter line %p dump done\n", INDENT, dest);
}
/* Linearize */
static uint
linearize(struct f_line *dest, const struct f_inst *what, uint pos)
{
for ( ; what; what = what->next) {
switch (what->fi_code) {
FID_WR_PUT(8)
}
pos++;
}
return pos;
}
struct f_line *
f_linearize_concat(const struct f_inst * const inst[], uint count)
{
uint len = 0;
for (uint i=0; i<count; i++)
for (const struct f_inst *what = inst[i]; what; what = what->next)
len += what->size;
struct f_line *out = cfg_allocz(sizeof(struct f_line) + sizeof(struct f_line_item)*len);
for (uint i=0; i<count; i++)
out->len = linearize(out, inst[i], out->len);
#ifdef LOCAL_DEBUG
f_dump_line(out, 0);
#endif
return out;
}
/* Filter line comparison */
int
f_same(const struct f_line *fl1, const struct f_line *fl2)
{
if ((!fl1) && (!fl2))
return 1;
if ((!fl1) || (!fl2))
return 0;
if (fl1->len != fl2->len)
return 0;
for (uint i=0; i<fl1->len; i++) {
#define f1_ (&(fl1->items[i]))
#define f2_ (&(fl2->items[i]))
if (f1_->fi_code != f2_->fi_code)
return 0;
if (f1_->flags != f2_->flags)
return 0;
switch(f1_->fi_code) {
FID_WR_PUT(9)
}
}
#undef f1_
#undef f2_
return 1;
}
/* Part of FI_SWITCH filter iterator */
static void
f_add_tree_lines(const struct f_tree *t, void *fit_)
{
struct filter_iterator * fit = fit_;
if (t->data)
BUFFER_PUSH(fit->lines) = t->data;
}
/* Filter line iterator */
void
f_add_lines(const struct f_line_item *what, struct filter_iterator *fit)
{
switch(what->fi_code) {
FID_WR_PUT(10)
}
}
#if defined(__GNUC__) && __GNUC__ >= 6
#pragma GCC diagnostic pop
#endif
FID_WR_DIRECT(H)
/* Filter instruction codes */
enum f_instruction_code {
FID_WR_PUT(4)m4_dnl
} PACKED;
/* Filter instruction structure for config */
struct f_inst {
struct f_inst *next; /* Next instruction */
enum f_instruction_code fi_code; /* Instruction code */
enum f_type type; /* Type of returned value, if known */
int size; /* How many instructions are underneath */
int lineno; /* Line number */
union {
FID_WR_PUT(1)m4_dnl
};
};
/* Filter line item */
struct f_line_item {
enum f_instruction_code fi_code; /* What to do */
enum f_instruction_flags flags; /* Flags, instruction-specific */
uint lineno; /* Where */
union {
FID_WR_PUT(2)m4_dnl
};
};
/* Instruction constructors */
FID_WR_PUT(3)
m4_divert(-1)
# 4) Shipout
#
# Everything is prepared in FID_WR_PUT_LIST now. Let's go!
m4_changequote(`,')
# Flusher auxiliary macro
m4_define(FID_FLUSH, `m4_ifelse($1,$2,,[[m4_undivert($1)FID_FLUSH(m4_eval($1+1),$2)]])')
# Defining the macro used in FID_WR_PUT_LIST
m4_define(FID_WR_DPUT, `m4_undivert($1)')
# After the code is read and parsed, we:
m4_m4wrap(`INST_FLUSH()m4_divert(0)FID_WR_PUT_LIST()m4_divert(-1)FID_FLUSH(1,200)')
m4_changequote([[,]])
# And now M4 is going to parse f-inst.c, fill the diversions
# and after the file is done, the content of m4_m4wrap (see before)
# is executed.

1269
filter/f-inst.c Normal file

File diff suppressed because it is too large Load Diff

112
filter/f-inst.h Normal file
View File

@ -0,0 +1,112 @@
/*
* BIRD Internet Routing Daemon -- Filter instructions
*
* (c) 1999 Pavel Machek <pavel@ucw.cz>
* (c) 2018--2019 Maria Matejka <mq@jmq.cz>
*
* Can be freely distributed and used under the terms of the GNU GPL.
*
* Filter interpreter data structures and internal API.
* See filter/f-inst.c for documentation.
*/
#ifndef _BIRD_F_INST_H_
#define _BIRD_F_INST_H_
#include "nest/bird.h"
#include "conf/conf.h"
#include "filter/filter.h"
#include "filter/data.h"
#include "lib/buffer.h"
#include "lib/flowspec.h"
/* Flags for instructions */
enum f_instruction_flags {
FIF_PRINTED = 1, /* FI_PRINT_AND_DIE: message put in buffer */
} PACKED;
/* Include generated filter instruction declarations */
#include "filter/inst-gen.h"
#define f_new_inst(...) MACRO_CONCAT_AFTER(f_new_inst_, MACRO_FIRST(__VA_ARGS__))(__VA_ARGS__)
/* Convert the instruction back to the enum name */
const char *f_instruction_name_(enum f_instruction_code fi);
static inline const char *f_instruction_name(enum f_instruction_code fi)
{ return f_instruction_name_(fi) + 3; }
/* Filter structures for execution */
/* Line of instructions to be unconditionally executed one after another */
struct f_line {
uint len; /* Line length */
u8 args; /* Function: Args required */
u8 vars;
struct f_line_item items[0]; /* The items themselves */
};
/* Convert the f_inst infix tree to the f_line structures */
struct f_line *f_linearize_concat(const struct f_inst * const inst[], uint count);
static inline struct f_line *f_linearize(const struct f_inst *root)
{ return f_linearize_concat(&root, 1); }
void f_dump_line(const struct f_line *, uint indent);
/* Recursive iteration over filter instructions */
struct filter_iterator {
BUFFER_(const struct f_line *) lines;
};
void f_add_lines(const struct f_line_item *what, struct filter_iterator *fit);
#define FILTER_ITERATE_INIT(fit, filter, pool) \
({ \
BUFFER_INIT((fit)->lines, (pool), 32); \
BUFFER_PUSH((fit)->lines) = (filter)->root; \
})
#define FILTER_ITERATE(fit, fi) ({ \
const struct f_line *fl_; \
while (!BUFFER_EMPTY((fit)->lines)) \
{ \
BUFFER_POP((fit)->lines); \
fl_ = (fit)->lines.data[(fit)->lines.used]; \
for (uint i_ = 0; i_ < fl_->len; i_++) \
{ \
const struct f_line_item *fi = &fl_->items[i_]; \
f_add_lines(fi, (fit));
#define FILTER_ITERATE_END } } })
#define FILTER_ITERATE_CLEANUP(fit) \
({ \
mb_free((fit)->lines.data); \
memset((fit), 0, sizeof(struct filter_iterator)); \
})
struct filter *f_new_where(struct f_inst *);
static inline struct f_dynamic_attr f_new_dynamic_attr(u8 type, enum f_type f_type, uint code) /* Type as core knows it, type as filters know it, and code of dynamic attribute */
{ return (struct f_dynamic_attr) { .type = type, .f_type = f_type, .ea_code = code }; } /* f_type currently unused; will be handy for static type checking */
static inline struct f_dynamic_attr f_new_dynamic_attr_bit(u8 bit, enum f_type f_type, uint code) /* Type as core knows it, type as filters know it, and code of dynamic attribute */
{ return (struct f_dynamic_attr) { .type = EAF_TYPE_BITFIELD, .bit = bit, .f_type = f_type, .ea_code = code }; } /* f_type currently unused; will be handy for static type checking */
static inline struct f_static_attr f_new_static_attr(int f_type, int code, int readonly)
{ return (struct f_static_attr) { .f_type = f_type, .sa_code = code, .readonly = readonly }; }
struct f_inst *f_generate_complex(enum f_instruction_code fi_code, struct f_dynamic_attr da, struct f_inst *argument);
struct f_inst *f_generate_roa_check(struct rtable_config *table, struct f_inst *prefix, struct f_inst *asn);
/* Hook for call bt_assert() function in configuration */
extern void (*bt_assert_hook)(int result, const struct f_line_item *assert);
/* Bird Tests */
struct f_bt_test_suite {
node n; /* Node in config->tests */
const struct f_line *fn; /* Root of function */
const struct f_line *cmp; /* Compare to this function */
const char *fn_name; /* Name of test */
const char *dsc; /* Description */
int result; /* Desired result */
};
#endif

View File

@ -2,6 +2,7 @@
* Filters: utility functions
*
* Copyright 1998 Pavel Machek <pavel@ucw.cz>
* 2017 Jan Maria Matejka <mq@ucw.cz>
*
* Can be freely distributed and used under the terms of the GNU GPL.
*/
@ -9,77 +10,174 @@
#include "nest/bird.h"
#include "conf/conf.h"
#include "filter/filter.h"
#include "filter/f-inst.h"
#include "lib/idm.h"
#include "nest/protocol.h"
#include "nest/route.h"
#define P(a,b) ((a<<8) | b)
struct f_inst *
f_new_inst(void)
{
struct f_inst * ret;
ret = cfg_alloc(sizeof(struct f_inst));
ret->code = ret->aux = 0;
ret->arg1 = ret->arg2 = ret->next = NULL;
ret->lineno = ifs->lino;
return ret;
}
struct f_inst *
f_new_dynamic_attr(int type, int f_type UNUSED, int code)
{
/* FIXME: Remove the f_type parameter? */
struct f_inst *f = f_new_inst();
f->aux = type;
f->a2.i = code;
return f;
}
/*
* Generate set_dynamic( operation( get_dynamic(), argument ) )
*/
struct f_inst *
f_generate_complex(int operation, int operation_aux, struct f_inst *dyn, struct f_inst *argument)
{
struct f_inst *set_dyn = f_new_inst(),
*oper = f_new_inst(),
*get_dyn = dyn;
*set_dyn = *get_dyn;
get_dyn->code = P('e','a');
oper->code = operation;
oper->aux = operation_aux;
oper->a1.p = get_dyn;
oper->a2.p = argument;
set_dyn->code = P('e','S');
set_dyn->a1.p = oper;
return set_dyn;
}
struct f_inst *
f_generate_roa_check(struct rtable_config *table, struct f_inst *prefix, struct f_inst *asn)
{
struct f_inst_roa_check *ret = cfg_allocz(sizeof(struct f_inst_roa_check));
ret->i.code = P('R','C');
ret->i.lineno = ifs->lino;
ret->i.arg1 = prefix;
ret->i.arg2 = asn;
/* prefix == NULL <-> asn == NULL */
if (table->addr_type != NET_ROA4 && table->addr_type != NET_ROA6)
cf_error("%s is not a ROA table", table->name);
ret->rtc = table;
return &ret->i;
}
char *
filter_name(struct filter *filter)
const char *
filter_name(const struct filter *filter)
{
if (!filter)
return "ACCEPT";
else if (filter == FILTER_REJECT)
return "REJECT";
else if (!filter->name)
else if (!filter->sym)
return "(unnamed)";
else
return filter->name;
return filter->sym->name;
}
struct filter *f_new_where(struct f_inst *where)
{
struct f_inst *cond = f_new_inst(FI_CONDITION, where,
f_new_inst(FI_DIE, F_ACCEPT),
f_new_inst(FI_DIE, F_REJECT));
struct filter *f = cfg_allocz(sizeof(struct filter));
f->root = f_linearize(cond);
return f;
}
#define CA_KEY(n) n->name, n->fda.type
#define CA_NEXT(n) n->next
#define CA_EQ(na,ta,nb,tb) (!strcmp(na,nb) && (ta == tb))
#define CA_FN(n,t) (mem_hash(n, strlen(n)) ^ (t*0xaae99453U))
#define CA_ORDER 8 /* Fixed */
struct ca_storage {
struct ca_storage *next;
struct f_dynamic_attr fda;
u32 uc;
char name[0];
};
HASH(struct ca_storage) ca_hash;
static struct idm ca_idm;
static struct ca_storage **ca_storage;
static uint ca_storage_max;
static void
ca_free(resource *r)
{
struct custom_attribute *ca = (void *) r;
struct ca_storage *cas = HASH_FIND(ca_hash, CA, ca->name, ca->fda->type);
ASSERT(cas);
ca->name = NULL;
ca->fda = NULL;
if (!--cas->uc) {
uint id = EA_CUSTOM_ID(cas->fda.ea_code);
idm_free(&ca_idm, id);
HASH_REMOVE(ca_hash, CA, cas);
ca_storage[id] = NULL;
mb_free(cas);
}
}
static void
ca_dump(resource *r)
{
struct custom_attribute *ca = (void *) r;
debug("name \"%s\" id 0x%04x ea_type 0x%02x f_type 0x%02x\n",
ca->name, ca->fda->ea_code, ca->fda->type, ca->fda->f_type);
}
static struct resclass ca_class = {
.name = "Custom attribute",
.size = sizeof(struct custom_attribute),
.free = ca_free,
.dump = ca_dump,
.lookup = NULL,
.memsize = NULL,
};
struct custom_attribute *
ca_lookup(pool *p, const char *name, int f_type)
{
int ea_type;
switch (f_type) {
case T_INT:
ea_type = EAF_TYPE_INT;
break;
case T_IP:
ea_type = EAF_TYPE_IP_ADDRESS;
break;
case T_QUAD:
ea_type = EAF_TYPE_ROUTER_ID;
break;
case T_PATH:
ea_type = EAF_TYPE_AS_PATH;
break;
case T_CLIST:
ea_type = EAF_TYPE_INT_SET;
break;
case T_ECLIST:
ea_type = EAF_TYPE_EC_SET;
break;
case T_LCLIST:
ea_type = EAF_TYPE_LC_SET;
break;
default:
cf_error("Custom route attribute of unsupported type");
}
static int inited = 0;
if (!inited) {
idm_init(&ca_idm, &root_pool, 8);
HASH_INIT(ca_hash, &root_pool, CA_ORDER);
ca_storage_max = 256;
ca_storage = mb_allocz(&root_pool, sizeof(struct ca_storage *) * ca_storage_max);
inited++;
}
struct ca_storage *cas = HASH_FIND(ca_hash, CA, name, ea_type);
if (cas) {
cas->uc++;
} else {
uint id = idm_alloc(&ca_idm);
if (id >= EA_CUSTOM_BIT)
cf_error("Too many custom attributes.");
if (id >= ca_storage_max) {
ca_storage_max *= 2;
ca_storage = mb_realloc(ca_storage, sizeof(struct ca_storage *) * ca_storage_max * 2);
}
cas = mb_allocz(&root_pool, sizeof(struct ca_storage) + strlen(name) + 1);
cas->fda = f_new_dynamic_attr(ea_type, f_type, EA_CUSTOM(id));
cas->uc = 1;
strcpy(cas->name, name);
ca_storage[id] = cas;
HASH_INSERT(ca_hash, CA, cas);
}
struct custom_attribute *ca = ralloc(p, &ca_class);
ca->fda = &(cas->fda);
ca->name = cas->name;
return ca;
}
const char *
ea_custom_name(uint ea)
{
uint id = EA_CUSTOM_ID(ea);
if (id >= ca_storage_max)
return NULL;
if (!ca_storage[id])
return NULL;
return ca_storage[id]->name;
}

File diff suppressed because it is too large Load Diff

View File

@ -2,6 +2,7 @@
* BIRD Internet Routing Daemon -- Filters
*
* (c) 1999 Pavel Machek <pavel@ucw.cz>
* (c) 2018--2019 Maria Matejka <mq@jmq.cz>
*
* Can be freely distributed and used under the terms of the GNU GPL.
*/
@ -11,212 +12,71 @@
#include "lib/resource.h"
#include "lib/ip.h"
#include "lib/macro.h"
#include "nest/route.h"
#include "nest/attrs.h"
struct f_inst { /* Instruction */
struct f_inst *next; /* Structure is 16 bytes, anyway */
u16 code; /* Instruction code, see the interpret() function and P() macro */
u16 aux; /* Extension to instruction code, T_*, EA_*, EAF_* */
union {
uint i;
void *p;
} a1; /* The first argument */
union {
uint i;
void *p;
} a2; /* The second argument */
int lineno;
/* Possible return values of filter execution */
enum filter_return {
F_NOP = 0,
F_NONL,
F_RETURN,
F_ACCEPT, /* Need to preserve ordering: accepts < rejects! */
F_REJECT,
F_ERROR,
};
#define arg1 a1.p
#define arg2 a2.p
static inline const char *filter_return_str(const enum filter_return fret) {
switch (fret) {
#define FRS(x) case x: return #x
FRS(F_NOP);
FRS(F_NONL);
FRS(F_RETURN);
FRS(F_ACCEPT);
FRS(F_REJECT);
FRS(F_ERROR);
#undef FRS
default: bug("This shall not happen");
}
}
/* Not enough fields in f_inst for three args used by roa_check() */
struct f_inst_roa_check {
struct f_inst i;
struct rtable_config *rtc;
};
struct f_inst3 {
struct f_inst i;
union {
int i;
void *p;
} a3;
};
#define INST3(x) (((struct f_inst3 *) x)->a3)
struct f_prefix {
net_addr net;
u8 lo, hi;
};
struct f_val {
int type; /* T_* */
union {
uint i;
u64 ec;
lcomm lc;
ip_addr ip;
const net_addr *net;
char *s;
struct f_tree *t;
struct f_trie *ti;
struct adata *ad;
struct f_path_mask *path_mask;
} val;
};
struct f_val;
/* The filter encapsulating structure to be pointed-to from outside */
struct f_line;
struct filter {
char *name;
struct f_inst *root;
struct symbol *sym;
const struct f_line *root;
};
struct f_inst *f_new_inst(void);
struct f_inst *f_new_dynamic_attr(int type, int f_type, int code); /* Type as core knows it, type as filters know it, and code of dynamic attribute */
struct f_tree *f_new_tree(void);
struct f_inst *f_generate_complex(int operation, int operation_aux, struct f_inst *dyn, struct f_inst *argument);
struct f_inst *f_generate_roa_check(struct rtable_config *table, struct f_inst *prefix, struct f_inst *asn);
struct f_tree *build_tree(struct f_tree *);
struct f_tree *find_tree(struct f_tree *t, struct f_val val);
int same_tree(struct f_tree *t1, struct f_tree *t2);
void tree_format(struct f_tree *t, buffer *buf);
struct f_trie *f_new_trie(linpool *lp, uint node_size);
void *trie_add_prefix(struct f_trie *t, const net_addr *n, uint l, uint h);
int trie_match_net(struct f_trie *t, const net_addr *n);
int trie_same(struct f_trie *t1, struct f_trie *t2);
void trie_format(struct f_trie *t, buffer *buf);
struct ea_list;
struct rte;
int f_run(struct filter *filter, struct rte **rte, struct ea_list **tmp_attrs, struct linpool *tmp_pool, int flags);
struct f_val f_eval_rte(struct f_inst *expr, struct rte **rte, struct linpool *tmp_pool);
struct f_val f_eval(struct f_inst *expr, struct linpool *tmp_pool);
uint f_eval_int(struct f_inst *expr);
u32 f_eval_asn(struct f_inst *expr);
enum filter_return f_run(const struct filter *filter, struct rte **rte, struct linpool *tmp_pool, int flags);
enum filter_return f_eval_rte(const struct f_line *expr, struct rte **rte, struct linpool *tmp_pool);
uint f_eval_int(const struct f_line *expr);
enum filter_return f_eval_buf(const struct f_line *expr, struct linpool *tmp_pool, buffer *buf);
char *filter_name(struct filter *filter);
int filter_same(struct filter *new, struct filter *old);
const char *filter_name(const struct filter *filter);
int filter_same(const struct filter *new, const struct filter *old);
int f_same(const struct f_line *f1, const struct f_line *f2);
int i_same(struct f_inst *f1, struct f_inst *f2);
void filter_commit(struct config *new, struct config *old);
int val_compare(struct f_val v1, struct f_val v2);
int val_same(struct f_val v1, struct f_val v2);
void val_format(struct f_val v, buffer *buf);
#define F_NOP 0
#define F_NONL 1
#define F_ACCEPT 2 /* Need to preserve ordering: accepts < rejects! */
#define F_REJECT 3
#define F_ERROR 4
#define F_QUITBIRD 5
void filters_dump_all(void);
#define FILTER_ACCEPT NULL
#define FILTER_REJECT ((void *) 1)
#define FILTER_REJECT ((struct filter *) 1)
#define FILTER_UNDEF ((struct filter *) 2) /* Used in BGP */
/* Type numbers must be in 0..0xff range */
#define T_MASK 0xff
#define FF_SILENT 2 /* Silent filter execution */
/* Internal types */
/* Do not use type of zero, that way we'll see errors easier. */
#define T_VOID 1
/* User visible types, which fit in int */
#define T_INT 0x10
#define T_BOOL 0x11
#define T_PAIR 0x12 /* Notice that pair is stored as integer: first << 16 | second */
#define T_QUAD 0x13
/* Put enumerational types in 0x30..0x3f range */
#define T_ENUM_LO 0x30
#define T_ENUM_HI 0x3f
#define T_ENUM_RTS 0x30
#define T_ENUM_BGP_ORIGIN 0x31
#define T_ENUM_SCOPE 0x32
#define T_ENUM_RTC 0x33
#define T_ENUM_RTD 0x34
#define T_ENUM_ROA 0x35
#define T_ENUM_NETTYPE 0x36
#define T_ENUM_RA_PREFERENCE 0x37
/* new enums go here */
#define T_ENUM_EMPTY 0x3f /* Special hack for atomic_aggr */
#define T_ENUM T_ENUM_LO ... T_ENUM_HI
/* Bigger ones */
#define T_IP 0x20
#define T_NET 0x21
#define T_STRING 0x22
#define T_PATH_MASK 0x23 /* mask for BGP path */
#define T_PATH 0x24 /* BGP path */
#define T_CLIST 0x25 /* Community list */
#define T_EC 0x26 /* Extended community value, u64 */
#define T_ECLIST 0x27 /* Extended community list */
#define T_LC 0x28 /* Large community value, lcomm */
#define T_LCLIST 0x29 /* Large community list */
#define T_RD 0x2a /* Route distinguisher for VPN addresses */
#define T_RETURN 0x40
#define T_SET 0x80
#define T_PREFIX_SET 0x81
#define SA_FROM 1
#define SA_GW 2
#define SA_NET 3
#define SA_PROTO 4
#define SA_SOURCE 5
#define SA_SCOPE 6
#define SA_DEST 7
#define SA_IFNAME 8
#define SA_IFINDEX 9
struct f_tree {
struct f_tree *left, *right;
struct f_val from, to;
void *data;
/* Custom route attributes */
struct custom_attribute {
resource r;
struct f_dynamic_attr *fda;
const char *name;
};
struct f_trie_node
{
ip_addr addr, mask, accept;
uint plen;
struct f_trie_node *c[2];
};
struct f_trie
{
linpool *lp;
int zero;
uint node_size;
struct f_trie_node root[0]; /* Root trie node follows */
};
#define NEW_F_VAL struct f_val * val; val = cfg_alloc(sizeof(struct f_val));
#define FF_FORCE_TMPATTR 1 /* Force all attributes to be temporary */
/* Bird Tests */
struct f_bt_test_suite {
node n; /* Node in config->tests */
struct f_inst *fn; /* Root of function */
const char *fn_name; /* Name of test */
const char *dsc; /* Description */
};
/* Hook for call bt_assert() function in configuration */
extern void (*bt_assert_hook)(int result, struct f_inst *assert);
struct custom_attribute *ca_lookup(pool *p, const char *name, int ea_type);
#endif

View File

@ -17,44 +17,44 @@
#include "test/bt-utils.h"
#include "filter/filter.h"
#include "filter/data.h"
#include "filter/f-inst.h"
#include "conf/conf.h"
#define BT_CONFIG_FILE "filter/test.conf"
static struct config *
parse_config_file(const void *filename_void)
{
bt_bird_init();
size_t fn_size = strlen((const char *) filename_void) + 1;
char *filename = alloca(fn_size);
strncpy(filename, filename_void, fn_size);
struct config *c = bt_config_file_parse(filename);
bt_bird_cleanup();
return c;
}
static int
run_function(const void *parsed_fn_def)
t_reconfig(void)
{
/* XXX: const -> non-const */
struct f_inst *f = (struct f_inst *) parsed_fn_def;
linpool *tmp = lp_new_default(&root_pool);
struct f_val res = f_eval(f, tmp);
rfree(tmp);
if (res.type == T_RETURN && res.val.i >= F_REJECT)
if (!bt_config_file_parse(BT_CONFIG_FILE))
return 0;
struct symbol *s;
WALK_LIST(s, config->symbols)
if ((s->class == SYM_FUNCTION) || (s->class == SYM_FILTER))
bt_assert_msg((s->flags & SYM_FLAG_SAME), "Symbol %s same check", s->name);
return 1;
}
static int
run_function(const void *arg)
{
const struct f_bt_test_suite *t = arg;
if (t->cmp)
return t->result == f_same(t->fn, t->cmp);
linpool *tmp = lp_new_default(&root_pool);
enum filter_return fret = f_eval(t->fn, tmp, NULL);
rfree(tmp);
return (fret < F_REJECT);
}
static void
bt_assert_filter(int result, struct f_inst *assert)
bt_assert_filter(int result, const struct f_line_item *assert)
{
int bt_suit_case_result = 1;
if (!result)
@ -64,24 +64,28 @@ bt_assert_filter(int result, struct f_inst *assert)
bt_suit_case_result = 0;
}
bt_log_suite_case_result(bt_suit_case_result, "Assertion at line %d (%s)", assert->lineno, (char *) assert->a2.p);
bt_log_suite_case_result(bt_suit_case_result, "Assertion at line %d (%s)",
assert->lineno, assert->i_FI_ASSERT.s);
}
int
main(int argc, char *argv[])
{
bt_init(argc, argv);
bt_bird_init();
struct config *c = parse_config_file(BT_CONFIG_FILE);
bt_assert_hook = bt_assert_filter;
if (c)
{
bt_assert_hook = bt_assert_filter;
/* Initial test.conf parsing, must be done here */
if (!bt_config_file_parse(BT_CONFIG_FILE))
abort();
struct f_bt_test_suite *t;
WALK_LIST(t, c->tests)
bt_test_suite_base(run_function, t->fn_name, t->fn, BT_FORKING, BT_TIMEOUT, "%s", t->dsc);
}
bt_test_suite(t_reconfig, "Testing reconfiguration");
struct f_bt_test_suite *t;
WALK_LIST(t, config->tests)
bt_test_suite_base(run_function, t->fn_name, t, BT_FORKING, BT_TIMEOUT, "%s", t->dsc);
bt_bird_cleanup();
return bt_exit_value();
}

View File

@ -0,0 +1,23 @@
router id 1.1.1.1;
protocol device {}
function a() {
return true;
}
function b() {
return a();
}
function c() {
return b();
}
filter d {
if c() then accept; else reject;
}
protocol static {
ipv4 { import filter d; };
route 10.0.0.0/24 unreachable;
}

View File

@ -0,0 +1,23 @@
router id 1.1.1.1;
protocol device {}
function a() {
return false;
}
function b() {
return a();
}
function c() {
return b();
}
filter d {
if c() then accept; else reject;
}
protocol static {
ipv4 { import filter d; };
route 10.0.0.0/24 unreachable;
}

View File

@ -7,8 +7,7 @@
router id 62.168.0.1;
/* We have to setup any protocol */
protocol static { ipv4; }
protocol device { }
@ -25,8 +24,19 @@ function onef(int a)
return 1;
}
function twof(int a)
{
return 2;
}
function oneg(int a)
{
return 1;
}
bt_test_same(onef, onef, 1);
bt_test_same(onef, oneg, 1);
bt_test_same(onef, twof, 0);
/*
* Testing boolean expressions
@ -53,8 +63,8 @@ bool b;
bt_assert(! false && ! false && true);
bt_assert(1 < 2 && 1 != 3);
bt_assert(true && true && ! false);
bt_assert(true || 1+"a");
bt_assert(!(false && 1+"a"));
# bt_assert(true || 1+"a");
# bt_assert(!(false && 1+"a"));
bt_assert(!(true && false));
}
@ -62,7 +72,6 @@ bt_test_suite(t_bool, "Testing boolean expressions");
/*
* Testing integers
* ----------------
@ -126,6 +135,7 @@ int set is;
bt_assert(2 ~ [ 1, 2, 3 ]);
bt_assert(5 ~ [ 4 .. 7 ]);
bt_assert(1 !~ [ 2, 3, 4 ]);
bt_assert(999 !~ [ 666, 333 ]);
is = [ 2, 3, 4, 7..11 ];
bt_assert(10 ~ is);
@ -370,6 +380,9 @@ function t_enum()
{
bt_assert(format(RTS_DUMMY) = "(enum 30)0");
bt_assert(format(RTS_STATIC) = "(enum 30)1");
bt_assert(format(NET_IP4) = "(enum 36)1");
bt_assert(format(NET_VPN6) = "(enum 36)4");
bt_assert(RTS_STATIC ~ [RTS_STATIC, RTS_DEVICE]);
bt_assert(RTS_BGP !~ [RTS_STATIC, RTS_DEVICE]);
}
@ -448,7 +461,8 @@ function t_prefix_set()
prefix set pxs;
{
pxs = [ 1.2.0.0/16, 1.4.0.0/16+, 44.66.88.64/30{24,28}, 12.34.56.0/24{8,16} ];
bt_assert(format(pxs) = "[1.2.0.0/112{::0.1.0.0}, 1.4.0.0/112{::0.1.255.255}, 12.34.0.0/112{::1.255.0.0}, 44.66.88.64/124{::1f0}]");
bt_assert(format(pxs) = "[1.2.0.0/16{0.1.0.0}, 1.4.0.0/16{0.1.255.255}, 12.34.0.0/16{1.255.0.0}, 44.66.88.64/28{0.0.1.240}]");
bt_assert(1.2.0.0/16 ~ pxs);
bt_assert(1.4.0.0/16 ~ pxs);
bt_assert(1.4.0.0/18 ~ pxs);
@ -587,11 +601,15 @@ function mkpath(int a; int b)
return [= a b 3 2 1 =];
}
define set35 = [3 .. 5];
function t_path()
bgpmask pm1;
bgppath p2;
int set set12;
{
pm1 = [= 4 3 2 1 =];
set12 = [1, 2];
bt_assert(format(pm1) = "[= 4 3 2 1 =]");
@ -616,6 +634,8 @@ bgppath p2;
bt_assert(p2 !~ [8, ten..(2*ten)]);
bt_assert(p2 ~ [= * 4 3 * 1 =]);
bt_assert(p2 ~ [= (3+2) (2*2) 3 2 1 =]);
bt_assert(p2 ~ [= 5 [2, 4, 6] 3 [1..2] 1 =]);
bt_assert(p2 ~ [= 5 set35 3 set12 set12 =]);
bt_assert(p2 ~ mkpath(5, 4));
bt_assert(p2.len = 5);
@ -626,7 +646,6 @@ bgppath p2;
bt_assert(delete(p2, 3) = prepend(prepend(prepend(prepend(+empty+, 1), 2), 4), 5));
bt_assert(filter(p2, [1..3]) = prepend(prepend(prepend(+empty+, 1), 2), 3));
pm1 = [= 1 2 * 3 4 5 =];
p2 = prepend( + empty +, 5 );
p2 = prepend( p2, 4 );
p2 = prepend( p2, 3 );
@ -634,9 +653,17 @@ bgppath p2;
p2 = prepend( p2, 2 );
p2 = prepend( p2, 1 );
bt_assert(p2 ~ pm1);
bt_assert(p2 !~ [= 1 2 3 4 5 =]);
bt_assert(p2 ~ [= 1 2 * 4 5 =]);
bt_assert(p2 ~ [= 1 2 * 3 4 5 =]);
bt_assert(p2 ~ [= 1 2 3+ 4 5 =]);
bt_assert(p2 ~ [= 1 2 3+ 4+ 5 =]);
bt_assert(p2 !~ [= 1 2 3+ 5+ 4 5 =]);
bt_assert(p2 !~ [= 1 2 3 3 5+ 4 5 =]);
bt_assert(delete(p2, 3) = prepend(prepend(prepend(prepend(+empty+, 5), 4), 2), 1));
bt_assert(delete(p2, [4..5]) = prepend(prepend(prepend(prepend(+empty+, 3), 3), 2), 1));
bt_assert(format([= 1 2+ 3 =]) = "[= 1 2 + 3 =]");
}
bt_test_suite(t_path, "Testing paths");
@ -1005,6 +1032,60 @@ bt_test_suite(t_lclist_set, "Testing sets of large communities");
/*
* Testing Route Distinguishers
* ----------------------------
*/
function t_rd()
rd x;
{
x = 12345:20000;
bt_assert(format(x) = "12345:20000");
bt_assert(x = 12345:20000);
bt_assert(x < 12345:20010);
bt_assert(x != 12346:20000);
bt_assert(x != 2:12345:20000);
bt_assert(!(x > 12345:200010));
bt_assert(format(0:1:2) = "1:2");
bt_assert(format(10.0.0.1:1000) = "10.0.0.1:1000");
bt_assert(format(100000:20000) = "100000:20000");
bt_assert(format(2:100000:20000) = "100000:20000");
bt_assert(format(2:1000:1000) = "2:1000:1000");
}
bt_test_suite(t_rd, "Testing route distinguishers");
/*
* Testing sets of Route Distinguishers
* ------------------------------------
*/
function t_rd_set()
rd set rds;
{
rds = [10:20, 100000:100..100000:200];
bt_assert(format(rds) = "[10:20, 100000:100..100000:200]");
bt_assert(10:20 ~ rds);
bt_assert(10:21 !~ rds);
bt_assert(100000:90 !~ rds);
bt_assert(100000:100 ~ rds);
bt_assert(100000:128 ~ rds);
bt_assert(100000:200 ~ rds);
bt_assert(100010:150 !~ rds);
}
bt_test_suite(t_rd_set, "Testing sets of route distinguishers");
/*
* Testing defined() function
* --------------------------
@ -1054,6 +1135,11 @@ int i;
return 0;
}
function callmeagain(int a; int b; int c)
{
return a + b + c;
}
function fifteen()
{
return 15;
@ -1070,6 +1156,7 @@ function t_call_function()
bt_assert(callme(3, 2) = 6);
bt_assert(callme(4, 4) = 16);
bt_assert(callme(7, 2) = 14);
bt_assert(callmeagain(1, 2, 3) = 6);
}
bt_test_suite(t_call_function, "Testing calling functions");
@ -1103,6 +1190,10 @@ bt_test_suite(t_include, "Testing including another config file");
function t_if_else()
int i;
{
/* Empty blocks regression test */
if true then {}
else {}
if true then
bt_assert(true);
@ -1112,6 +1203,10 @@ int i;
bt_assert(true);
else
bt_assert(false);
/* Empty blocks regression test */
if true then {}
else {}
}
bt_test_suite(t_if_else, "Testing if-else statement");
@ -1164,7 +1259,7 @@ int j;
filter roa_filter
{
if net ~ [ 10.0.0.0/8{16,24}, 2000::/3{16,96} ] then {
if net ~ [ 10.0.0.0/8{16,24} ] || net ~ [ 2000::/3{16,96} ] then {
accept;
}
reject;
@ -1188,10 +1283,9 @@ protocol static
route 2001:0db8:85a3:8a2e::/64 max 96 as 1000;
}
function test_roa_check()
function t_roa_check()
prefix pfx;
{
# cannot be tested in __startup(), sorry
bt_assert(roa_check(r4, 10.10.0.0/16, 1000) = ROA_UNKNOWN);
bt_assert(roa_check(r4, 10.0.0.0/8, 1000) = ROA_UNKNOWN);
bt_assert(roa_check(r4, 10.110.0.0/16, 1000) = ROA_VALID);
@ -1246,44 +1340,14 @@ prefix pfx;
bt_assert(pfx.asn = 1234);
}
bt_test_suite(test_roa_check, "Testing ROA");
bt_test_suite(t_roa_check, "Testing ROA");
/*
* Testing Mixed Net Types
* -----------------------
*/
function t_mixed_prefix()
prefix set pxs;
prefix set pxt;
{
pxs = [ 98.45.0.0/16, 128.128.0.0/12+, 2200::/42-, ::ffff:d000:0/100{98,102}];
bt_assert(format(pxs) = "[::/0, ::/2{c000::}, 98.45.0.0/112{::0.1.0.0}, 128.128.0.0/108{::0.31.255.255}, 208.0.0.0/100{::124.0.0.0}, 2200::/42{ffff:ffff:ffc0::}]");
bt_assert(::fe00:0:0/88 !~ pxs);
bt_assert(::fffe:0:0/95 !~ pxs);
bt_assert(::ffff:d800:0/101 ~ pxs);
bt_assert(216.0.0.0/5 ~ pxs);
bt_assert(212.0.0.0/6 ~ pxs);
bt_assert(212.0.0.0/7 !~ pxs);
bt_assert(::ffff:8080:8080/121 ~ pxs);
bt_assert(::/0 ~ pxs);
bt_assert(0.0.0.0/0 !~ pxs);
bt_assert(128.135.64.17/32 ~ pxs);
# pxt = [ 0:1:2 10.1.10.0/24, 0:5:10000 10.1.10.0/24 ];
# print pxt;
bt_assert(format(NET_IP4) = "(enum 36)1"); ## if (net.type = NET_IP4) ...
bt_assert(format(NET_VPN6) = "(enum 36)4");
bt_assert(format(0:1:2) = "1:2");
}
bt_test_suite(t_mixed_prefix, "Testing mixed net types");
filter vpn_filter
{
bt_assert(format(net) = "0:1:2 10.1.10.0/24");
bt_assert(format(net) = "1:2 10.1.10.0/24");
bt_assert(net.type = NET_VPN4);
bt_assert(net.type != NET_IP4);
bt_assert(net.type != NET_IP6);
@ -1294,6 +1358,13 @@ filter vpn_filter
NET_IP6: print "IPV6";
}
bt_check_assign(from, 10.20.30.40);
bt_check_assign(gw, 55.55.55.44);
bgp_community.add((3,5));
bgp_ext_community.add((ro, 135, 999));
bgp_large_community.add((6464156, 89646354, 8675643));
accept;
}
@ -1305,3 +1376,9 @@ protocol static
vpn4 { table v4; import filter vpn_filter; };
route 0:1:2 10.1.10.0/24 unreachable;
}
protocol static
{
ipv6 { import where false; };
route fd01::/48 unreachable;
}

View File

@ -43,7 +43,6 @@ protocol static {
print scope;
if !(scope ~ [ SCOPE_HOST, SCOPE_SITE ]) then {
print "Failed in test";
quitbird;
}
preference = 15;
@ -55,29 +54,28 @@ protocol static {
rip_metric = rip_metric + 5;
print rip_metric;
#
# TODO: uncomment this part after finishing BGP integration version
#
# bgp_community = -empty-;
# print "hi";
# bgp_community = add(bgp_community, (1,2));
# print "hello";
# bgp_community = add(bgp_community, (2,3));
# bgp_community.add((4,5));
# print "community = ", bgp_community;
# bgp_community.delete((2,3));
# print "community = ", bgp_community;
# bgp_community.empty;
# print "community = ", bgp_community;
# print "done";
bgp_community = -empty-;
print "hi";
bgp_community = add(bgp_community, (1,2));
print "hello";
bgp_community = add(bgp_community, (2,3));
bgp_community.add((4,5));
print "community = ", bgp_community;
bgp_community.delete((2,3));
print "community = ", bgp_community;
bgp_community.empty;
print "community = ", bgp_community;
print "done";
accept;
};
};
route 0.0.0.0/0 via 195.113.31.113;
route 62.168.0.0/25 reject;
route 1.2.3.4/32 via 195.113.31.124;
route 10.0.0.0/8 reject;
route 10.1.1.0:255.255.255.0 via 62.168.0.3;
route 10.1.2.0:255.255.255.0 via 62.168.0.3;
route 10.1.3.0:255.255.255.0 via 62.168.0.4;
route 10.1.1.0/24 via 62.168.0.3;
route 10.1.2.0/24 via 62.168.0.3;
route 10.1.3.0/24 via 62.168.0.4;
route 10.2.0.0/24 via "arc0";
}

View File

@ -10,6 +10,7 @@
#include "nest/bird.h"
#include "conf/conf.h"
#include "filter/filter.h"
#include "filter/data.h"
/**
* find_tree
@ -23,15 +24,15 @@
* Both set matching and |switch() { }| construction is implemented using this function,
* thus both are as fast as they can be.
*/
struct f_tree *
find_tree(struct f_tree *t, struct f_val val)
const struct f_tree *
find_tree(const struct f_tree *t, const struct f_val *val)
{
if (!t)
return NULL;
if ((val_compare(t->from, val) != 1) &&
(val_compare(t->to, val) != -1))
if ((val_compare(&(t->from), val) != 1) &&
(val_compare(&(t->to), val) != -1))
return t;
if (val_compare(t->from, val) == -1)
if (val_compare(&(t->from), val) == -1)
return find_tree(t->right, val);
else
return find_tree(t->left, val);
@ -56,7 +57,7 @@ build_tree_rec(struct f_tree **buf, int l, int h)
static int
tree_compare(const void *p1, const void *p2)
{
return val_compare((* (struct f_tree **) p1)->from, (* (struct f_tree **) p2)->from);
return val_compare(&((* (struct f_tree **) p1)->from), &((* (struct f_tree **) p2)->from));
}
/**
@ -102,12 +103,7 @@ build_tree(struct f_tree *from)
struct f_tree *
f_new_tree(void)
{
struct f_tree * ret;
ret = cfg_alloc(sizeof(struct f_tree));
ret->left = ret->right = NULL;
ret->from.type = ret->to.type = T_VOID;
ret->from.val.i = ret->to.val.i = 0;
ret->data = NULL;
struct f_tree *ret = cfg_allocz(sizeof(struct f_tree));
return ret;
}
@ -119,39 +115,39 @@ f_new_tree(void)
* Compares two trees and returns 1 if they are same
*/
int
same_tree(struct f_tree *t1, struct f_tree *t2)
same_tree(const struct f_tree *t1, const struct f_tree *t2)
{
if ((!!t1) != (!!t2))
return 0;
if (!t1)
return 1;
if (val_compare(t1->from, t2->from))
if (val_compare(&(t1->from), &(t2->from)))
return 0;
if (val_compare(t1->to, t2->to))
if (val_compare(&(t1->to), &(t2->to)))
return 0;
if (!same_tree(t1->left, t2->left))
return 0;
if (!same_tree(t1->right, t2->right))
return 0;
if (!i_same(t1->data, t2->data))
if (!f_same(t1->data, t2->data))
return 0;
return 1;
}
static void
tree_node_format(struct f_tree *t, buffer *buf)
tree_node_format(const struct f_tree *t, buffer *buf)
{
if (t == NULL)
return;
tree_node_format(t->left, buf);
val_format(t->from, buf);
if (val_compare(t->from, t->to) != 0)
val_format(&(t->from), buf);
if (val_compare(&(t->from), &(t->to)) != 0)
{
buffer_puts(buf, "..");
val_format(t->to, buf);
val_format(&(t->to), buf);
}
buffer_puts(buf, ", ");
@ -159,7 +155,7 @@ tree_node_format(struct f_tree *t, buffer *buf)
}
void
tree_format(struct f_tree *t, buffer *buf)
tree_format(const struct f_tree *t, buffer *buf)
{
buffer_puts(buf, "[");
@ -174,3 +170,14 @@ tree_format(struct f_tree *t, buffer *buf)
buffer_puts(buf, "]");
}
void
tree_walk(const struct f_tree *t, void (*hook)(const struct f_tree *, void *), void *data)
{
if (!t)
return;
tree_walk(t->left, hook, data);
hook(t, data);
tree_walk(t->right, hook, data);
}

View File

@ -10,6 +10,7 @@
#include "test/bt-utils.h"
#include "filter/filter.h"
#include "filter/data.h"
#include "conf/conf.h"
#define MAX_TREE_HEIGHT 13
@ -226,8 +227,8 @@ t_find(void)
};
for(looking_up_value.val.i = 0; looking_up_value.val.i < nodes_count; looking_up_value.val.i++)
{
struct f_tree *found_tree = find_tree(tree, looking_up_value);
bt_assert((val_compare(looking_up_value, found_tree->from) == 0) && (val_compare(looking_up_value, found_tree->to) == 0));
const struct f_tree *found_tree = find_tree(tree, &looking_up_value);
bt_assert((val_compare(&looking_up_value, &(found_tree->from)) == 0) && (val_compare(&looking_up_value, &(found_tree->to)) == 0));
}
}
@ -278,11 +279,11 @@ t_find_ranges(void)
for(*i = 0; *i <= max_value; *i += (uint)bt_random()/nodes_count)
{
struct f_tree *found_tree = find_tree(tree, needle);
const struct f_tree *found_tree = find_tree(tree, &needle);
bt_debug("searching: %u \n", *i);
bt_assert(
(val_compare(needle, found_tree->from) == 0) || (val_compare(needle, found_tree->to) == 0) ||
((val_compare(needle, found_tree->from) == 1) && (val_compare(needle, found_tree->to) == -1))
(val_compare(&needle, &(found_tree->from)) == 0) || (val_compare(&needle, &(found_tree->to)) == 0) ||
((val_compare(&needle, &(found_tree->from)) == 1) && (val_compare(&needle, &(found_tree->to)) == -1))
);
}
}

View File

@ -73,12 +73,14 @@
#include "lib/string.h"
#include "conf/conf.h"
#include "filter/filter.h"
#include "filter/data.h"
/*
* In the trie code, the prefix length is internally treated as for the whole
* ip_addr, regardless whether it contains an IPv4 or IPv6 address. Therefore,
* remaining definitions make sense.
* In the trie_add_prefix(), we use ip_addr (assuming that it is the same as
* ip6_addr) to handle both IPv4 and IPv6 prefixes. In contrast to rest of the
* BIRD, IPv4 addresses are just zero-padded from right. That is why we have
* ipt_from_ip4() and ipt_to_ip4() macros below.
*/
#define ipa_mkmask(x) ip6_mkmask(x)
@ -86,26 +88,30 @@
#define ipa_pxlen(x,y) ip6_pxlen(x,y)
#define ipa_getbit(x,n) ip6_getbit(x,n)
#define ipt_from_ip4(x) _MI6(_I(x), 0, 0, 0)
#define ipt_to_ip4(x) _MI4(_I0(x))
/**
* f_new_trie - allocates and returns a new empty trie
* @lp: linear pool to allocate items from
* @node_size: node size to be used (&f_trie_node and user data)
* @data_size: user data attached to node
*/
struct f_trie *
f_new_trie(linpool *lp, uint node_size)
f_new_trie(linpool *lp, uint data_size)
{
struct f_trie * ret;
ret = lp_allocz(lp, sizeof(struct f_trie) + node_size);
ret = lp_allocz(lp, sizeof(struct f_trie) + data_size);
ret->lp = lp;
ret->node_size = node_size;
ret->ipv4 = -1;
ret->data_size = data_size;
return ret;
}
static inline struct f_trie_node *
new_node(struct f_trie *t, int plen, ip_addr paddr, ip_addr pmask, ip_addr amask)
static inline struct f_trie_node4 *
new_node4(struct f_trie *t, int plen, ip4_addr paddr, ip4_addr pmask, ip4_addr amask)
{
struct f_trie_node *n = lp_allocz(t->lp, t->node_size);
struct f_trie_node4 *n = lp_allocz(t->lp, sizeof(struct f_trie_node4) + t->data_size);
n->plen = plen;
n->addr = paddr;
n->mask = pmask;
@ -113,12 +119,51 @@ new_node(struct f_trie *t, int plen, ip_addr paddr, ip_addr pmask, ip_addr amask
return n;
}
static inline void
attach_node(struct f_trie_node *parent, struct f_trie_node *child)
static inline struct f_trie_node6 *
new_node6(struct f_trie *t, int plen, ip6_addr paddr, ip6_addr pmask, ip6_addr amask)
{
parent->c[ipa_getbit(child->addr, parent->plen) ? 1 : 0] = child;
struct f_trie_node6 *n = lp_allocz(t->lp, sizeof(struct f_trie_node6) + t->data_size);
n->plen = plen;
n->addr = paddr;
n->mask = pmask;
n->accept = amask;
return n;
}
static inline struct f_trie_node *
new_node(struct f_trie *t, int plen, ip_addr paddr, ip_addr pmask, ip_addr amask)
{
if (t->ipv4)
return (struct f_trie_node *) new_node4(t, plen, ipt_to_ip4(paddr), ipt_to_ip4(pmask), ipt_to_ip4(amask));
else
return (struct f_trie_node *) new_node6(t, plen, ipa_to_ip6(paddr), ipa_to_ip6(pmask), ipa_to_ip6(amask));
}
static inline void
attach_node4(struct f_trie_node4 *parent, struct f_trie_node4 *child)
{
parent->c[ip4_getbit(child->addr, parent->plen) ? 1 : 0] = child;
}
static inline void
attach_node6(struct f_trie_node6 *parent, struct f_trie_node6 *child)
{
parent->c[ip6_getbit(child->addr, parent->plen) ? 1 : 0] = child;
}
static inline void
attach_node(struct f_trie_node *parent, struct f_trie_node *child, int v4)
{
if (v4)
attach_node4(&parent->v4, &child->v4);
else
attach_node6(&parent->v6, &child->v6);
}
#define GET_ADDR(N,F,X) ((X) ? ipt_from_ip4((N)->v4.F) : ipa_from_ip6((N)->v6.F))
#define SET_ADDR(N,F,X,V) ({ if (X) (N)->v4.F =ipt_to_ip4(V); else (N)->v6.F =ipa_to_ip6(V); })
#define GET_CHILD(N,F,X,I) ((X) ? (struct f_trie_node *) (N)->v4.c[I] : (struct f_trie_node *) (N)->v6.c[I])
/**
* trie_add_prefix
* @t: trie to add to
@ -132,21 +177,30 @@ attach_node(struct f_trie_node *parent, struct f_trie_node *child)
*
* Returns a pointer to the allocated node. The function can return a pointer to
* an existing node if @px and @plen are the same. If px/plen == 0/0 (or ::/0),
* a pointer to the root node is returned.
* a pointer to the root node is returned. Returns NULL when called with
* mismatched IPv4/IPv6 net type.
*/
void *
trie_add_prefix(struct f_trie *t, const net_addr *net, uint l, uint h)
{
ip_addr px = net_prefix(net);
uint plen = net_pxlen(net);
ip_addr px;
int v4;
if (net->type == NET_IP4)
switch (net->type)
{
const uint delta = IP6_MAX_PREFIX_LENGTH - IP4_MAX_PREFIX_LENGTH;
plen += delta;
l += delta;
h += delta;
case NET_IP4: px = ipt_from_ip4(net4_prefix(net)); v4 = 1; break;
case NET_IP6: px = ipa_from_ip6(net6_prefix(net)); v4 = 0; break;
default: bug("invalid type");
}
if (t->ipv4 != v4)
{
if (t->ipv4 < 0)
t->ipv4 = v4;
else
return NULL;
}
if (l == 0)
@ -161,95 +215,136 @@ trie_add_prefix(struct f_trie *t, const net_addr *net, uint l, uint h)
ip_addr pmask = ipa_mkmask(plen);
ip_addr paddr = ipa_and(px, pmask);
struct f_trie_node *o = NULL;
struct f_trie_node *n = t->root;
struct f_trie_node *n = &t->root;
while (n)
{
ip_addr cmask = ipa_and(n->mask, pmask);
ip_addr naddr = GET_ADDR(n, addr, v4);
ip_addr nmask = GET_ADDR(n, mask, v4);
ip_addr accept = GET_ADDR(n, accept, v4);
ip_addr cmask = ipa_and(nmask, pmask);
uint nlen = v4 ? n->v4.plen : n->v6.plen;
if (ipa_compare(ipa_and(paddr, cmask), ipa_and(n->addr, cmask)))
{
if (ipa_compare(ipa_and(paddr, cmask), ipa_and(naddr, cmask)))
{
/* We are out of path - we have to add branching node 'b'
between node 'o' and node 'n', and attach new node 'a'
as the other child of 'b'. */
int blen = ipa_pxlen(paddr, n->addr);
int blen = ipa_pxlen(paddr, naddr);
ip_addr bmask = ipa_mkmask(blen);
ip_addr baddr = ipa_and(px, bmask);
/* Merge accept masks from children to get accept mask for node 'b' */
ip_addr baccm = ipa_and(ipa_or(amask, n->accept), bmask);
ip_addr baccm = ipa_and(ipa_or(amask, accept), bmask);
struct f_trie_node *a = new_node(t, plen, paddr, pmask, amask);
struct f_trie_node *b = new_node(t, blen, baddr, bmask, baccm);
attach_node(o, b);
attach_node(b, n);
attach_node(b, a);
attach_node(o, b, v4);
attach_node(b, n, v4);
attach_node(b, a, v4);
return a;
}
if (plen < n->plen)
if (plen < nlen)
{
/* We add new node 'a' between node 'o' and node 'n' */
amask = ipa_or(amask, ipa_and(n->accept, pmask));
amask = ipa_or(amask, ipa_and(accept, pmask));
struct f_trie_node *a = new_node(t, plen, paddr, pmask, amask);
attach_node(o, a);
attach_node(a, n);
attach_node(o, a, v4);
attach_node(a, n, v4);
return a;
}
if (plen == n->plen)
if (plen == nlen)
{
/* We already found added node in trie. Just update accept mask */
n->accept = ipa_or(n->accept, amask);
accept = ipa_or(accept, amask);
SET_ADDR(n, accept, v4, accept);
return n;
}
/* Update accept mask part M2 and go deeper */
n->accept = ipa_or(n->accept, ipa_and(amask, n->mask));
accept = ipa_or(accept, ipa_and(amask, nmask));
SET_ADDR(n, accept, v4, accept);
/* n->plen < plen and plen <= 32 (128) */
o = n;
n = n->c[ipa_getbit(paddr, n->plen) ? 1 : 0];
n = GET_CHILD(n, c, v4, ipa_getbit(paddr, nlen) ? 1 : 0);
}
/* We add new tail node 'a' after node 'o' */
struct f_trie_node *a = new_node(t, plen, paddr, pmask, amask);
attach_node(o, a);
attach_node(o, a, v4);
return a;
}
static int
trie_match_prefix(struct f_trie *t, ip_addr px, uint plen)
trie_match_net4(const struct f_trie *t, ip4_addr px, uint plen)
{
ip_addr pmask = ipa_mkmask(plen);
ip_addr paddr = ipa_and(px, pmask);
ip4_addr pmask = ip4_mkmask(plen);
ip4_addr paddr = ip4_and(px, pmask);
if (plen == 0)
return t->zero;
int plentest = plen - 1;
struct f_trie_node *n = t->root;
const struct f_trie_node4 *n = &t->root.v4;
while(n)
{
ip_addr cmask = ipa_and(n->mask, pmask);
while (n)
{
ip4_addr cmask = ip4_and(n->mask, pmask);
/* We are out of path */
if (ipa_compare(ipa_and(paddr, cmask), ipa_and(n->addr, cmask)))
return 0;
/* We are out of path */
if (ip4_compare(ip4_and(paddr, cmask), ip4_and(n->addr, cmask)))
return 0;
/* Check accept mask */
if (ipa_getbit(n->accept, plentest))
return 1;
/* Check accept mask */
if (ip4_getbit(n->accept, plentest))
return 1;
/* We finished trie walk and still no match */
if (plen <= n->plen)
return 0;
/* We finished trie walk and still no match */
if (plen <= n->plen)
return 0;
/* Choose children */
n = n->c[(ipa_getbit(paddr, n->plen)) ? 1 : 0];
}
/* Choose children */
n = n->c[(ip4_getbit(paddr, n->plen)) ? 1 : 0];
}
return 0;
}
static int
trie_match_net6(const struct f_trie *t, ip6_addr px, uint plen)
{
ip6_addr pmask = ip6_mkmask(plen);
ip6_addr paddr = ip6_and(px, pmask);
if (plen == 0)
return t->zero;
int plentest = plen - 1;
const struct f_trie_node6 *n = &t->root.v6;
while (n)
{
ip6_addr cmask = ip6_and(n->mask, pmask);
/* We are out of path */
if (ip6_compare(ip6_and(paddr, cmask), ip6_and(n->addr, cmask)))
return 0;
/* Check accept mask */
if (ip6_getbit(n->accept, plentest))
return 1;
/* We finished trie walk and still no match */
if (plen <= n->plen)
return 0;
/* Choose children */
n = n->c[(ip6_getbit(paddr, n->plen)) ? 1 : 0];
}
return 0;
}
@ -264,22 +359,27 @@ trie_match_prefix(struct f_trie *t, ip_addr px, uint plen)
* is such prefix pattern in the trie.
*/
int
trie_match_net(struct f_trie *t, const net_addr *n)
trie_match_net(const struct f_trie *t, const net_addr *n)
{
uint add = 0;
switch (n->type)
{
case NET_IP4:
case NET_VPN4:
case NET_ROA4:
return t->ipv4 ? trie_match_net4(t, net4_prefix(n), net_pxlen(n)) : 0;
switch (n->type) {
case NET_IP4:
case NET_VPN4:
case NET_ROA4:
add = IP6_MAX_PREFIX_LENGTH - IP4_MAX_PREFIX_LENGTH;
case NET_IP6:
case NET_VPN6:
case NET_ROA6:
return !t->ipv4 ? trie_match_net6(t, net6_prefix(n), net_pxlen(n)) : 0;
default:
return 0;
}
return trie_match_prefix(t, net_prefix(n), net_pxlen(n) + add);
}
static int
trie_node_same(struct f_trie_node *t1, struct f_trie_node *t2)
trie_node_same4(const struct f_trie_node4 *t1, const struct f_trie_node4 *t2)
{
if ((t1 == NULL) && (t2 == NULL))
return 1;
@ -288,11 +388,28 @@ trie_node_same(struct f_trie_node *t1, struct f_trie_node *t2)
return 0;
if ((t1->plen != t2->plen) ||
(! ipa_equal(t1->addr, t2->addr)) ||
(! ipa_equal(t1->accept, t2->accept)))
(! ip4_equal(t1->addr, t2->addr)) ||
(! ip4_equal(t1->accept, t2->accept)))
return 0;
return trie_node_same(t1->c[0], t2->c[0]) && trie_node_same(t1->c[1], t2->c[1]);
return trie_node_same4(t1->c[0], t2->c[0]) && trie_node_same4(t1->c[1], t2->c[1]);
}
static int
trie_node_same6(const struct f_trie_node6 *t1, const struct f_trie_node6 *t2)
{
if ((t1 == NULL) && (t2 == NULL))
return 1;
if ((t1 == NULL) || (t2 == NULL))
return 0;
if ((t1->plen != t2->plen) ||
(! ip6_equal(t1->addr, t2->addr)) ||
(! ip6_equal(t1->accept, t2->accept)))
return 0;
return trie_node_same6(t1->c[0], t2->c[0]) && trie_node_same6(t1->c[1], t2->c[1]);
}
/**
@ -303,22 +420,41 @@ trie_node_same(struct f_trie_node *t1, struct f_trie_node *t2)
* Compares two tries and returns 1 if they are same
*/
int
trie_same(struct f_trie *t1, struct f_trie *t2)
trie_same(const struct f_trie *t1, const struct f_trie *t2)
{
return (t1->zero == t2->zero) && trie_node_same(t1->root, t2->root);
if ((t1->zero != t2->zero) || (t1->ipv4 != t2->ipv4))
return 0;
if (t1->ipv4)
return trie_node_same4(&t1->root.v4, &t2->root.v4);
else
return trie_node_same6(&t1->root.v6, &t2->root.v6);
}
static void
trie_node_format(struct f_trie_node *t, buffer *buf)
trie_node_format4(const struct f_trie_node4 *t, buffer *buf)
{
if (t == NULL)
return;
if (ipa_nonzero(t->accept))
buffer_print(buf, "%I/%d{%I}, ", t->addr, t->plen, t->accept);
if (ip4_nonzero(t->accept))
buffer_print(buf, "%I4/%d{%I4}, ", t->addr, t->plen, t->accept);
trie_node_format(t->c[0], buf);
trie_node_format(t->c[1], buf);
trie_node_format4(t->c[0], buf);
trie_node_format4(t->c[1], buf);
}
static void
trie_node_format6(const struct f_trie_node6 *t, buffer *buf)
{
if (t == NULL)
return;
if (ip6_nonzero(t->accept))
buffer_print(buf, "%I6/%d{%I6}, ", t->addr, t->plen, t->accept);
trie_node_format6(t->c[0], buf);
trie_node_format6(t->c[1], buf);
}
/**
@ -329,13 +465,17 @@ trie_node_format(struct f_trie_node *t, buffer *buf)
* Prints the trie to the supplied buffer.
*/
void
trie_format(struct f_trie *t, buffer *buf)
trie_format(const struct f_trie *t, buffer *buf)
{
buffer_puts(buf, "[");
if (t->zero)
buffer_print(buf, "%I/%d, ", IPA_NONE, 0);
trie_node_format(t->root, buf);
buffer_print(buf, "%I/%d, ", t->ipv4 ? IPA_NONE4 : IPA_NONE6, 0);
if (t->ipv4)
trie_node_format4(&t->root.v4, buf);
else
trie_node_format6(&t->root.v6, buf);
if (buf->pos == buf->end)
return;

View File

@ -10,6 +10,7 @@
#include "test/bt-utils.h"
#include "filter/filter.h"
#include "filter/data.h"
#include "conf/conf.h"
#define TESTS_NUM 10
@ -102,7 +103,7 @@ t_match_net(void)
{
list prefixes; /* of structs f_extended_prefix */
init_list(&prefixes);
struct f_trie *trie = f_new_trie(config->mem, sizeof(struct f_trie_node));
struct f_trie *trie = f_new_trie(config->mem, 0);
generate_random_ipv6_prefixes(&prefixes);
struct f_prefix_node *n;
@ -142,8 +143,8 @@ t_trie_same(void)
int round;
for (round = 0; round < TESTS_NUM*4; round++)
{
struct f_trie * trie1 = f_new_trie(config->mem, sizeof(struct f_trie_node));
struct f_trie * trie2 = f_new_trie(config->mem, sizeof(struct f_trie_node));
struct f_trie * trie1 = f_new_trie(config->mem, 0);
struct f_trie * trie2 = f_new_trie(config->mem, 0);
list prefixes; /* a list of f_extended_prefix structures */
init_list(&prefixes);

View File

@ -1,7 +1,7 @@
src := bitops.c checksum.c event.c flowspec.c idm.c ip.c lists.c mac.c md5.c mempool.c net.c patmatch.c printf.c resource.c sha1.c sha256.c sha512.c slab.c slists.c tbf.c timer.c xmalloc.c
src := bitmap.c bitops.c checksum.c event.c flowspec.c idm.c ip.c lists.c mac.c md5.c mempool.c net.c patmatch.c printf.c resource.c sha1.c sha256.c sha512.c slab.c slists.c strtoul.c tbf.c timer.c xmalloc.c
obj := $(src-o-files)
$(all-daemon)
tests_src := heap_test.c buffer_test.c event_test.c flowspec_test.c bitops_test.c patmatch_test.c fletcher16_test.c slist_test.c checksum_test.c lists_test.c mac_test.c ip_test.c hash_test.c printf_test.c
tests_src := bitmap_test.c heap_test.c buffer_test.c event_test.c flowspec_test.c bitops_test.c patmatch_test.c fletcher16_test.c slist_test.c checksum_test.c lists_test.c mac_test.c ip_test.c hash_test.c printf_test.c
tests_targets := $(tests_targets) $(tests-target-files)
tests_objs := $(tests_objs) $(src-o-files)

View File

@ -38,7 +38,7 @@ struct align_probe { char x; long int y; };
#define ARRAY_SIZE(a) (sizeof(a)/sizeof(*(a)))
#define BYTES(n) ((((uint) (n)) + 7) / 8)
#define CALL(fn, args...) ({ if (fn) fn(args); })
#define ADVANCE(w, r, l) ({ r -= l; w += l; })
#define ADVANCE(w, r, l) ({ r -= (l); w += (l); })
static inline int uint_cmp(uint i1, uint i2)
{ return (int)(i1 > i2) - (int)(i1 < i2); }
@ -56,6 +56,13 @@ static inline int u64_cmp(u64 i1, u64 i2)
#define BIT32_CLR(b,p) ((b)[(p)/32] &= ~BIT32_VAL(p))
#define BIT32_ZERO(b,l) memset((b), 0, (l)/8)
/* The same, but counting bits from MSB */
#define BIT32R_VAL(p) ((((u32) 1) << 31) >> ((p) % 32))
#define BIT32R_TEST(b,p) ((b)[(p)/32] & BIT32R_VAL(p))
#define BIT32R_SET(b,p) ((b)[(p)/32] |= BIT32R_VAL(p))
#define BIT32R_CLR(b,p) ((b)[(p)/32] &= ~BIT32R_VAL(p))
#define BIT32R_ZERO(b,l) memset((b), 0, (l)/8)
#ifndef NULL
#define NULL ((void *) 0)
#endif
@ -65,6 +72,11 @@ static inline int u64_cmp(u64 i1, u64 i2)
#define NORET __attribute__((noreturn))
#define UNUSED __attribute__((unused))
#define PACKED __attribute__((packed))
#define NONNULL(...) __attribute__((nonnull((__VA_ARGS__))))
#ifndef HAVE_THREAD_LOCAL
#define _Thread_local
#endif
/* Microsecond time */
@ -151,10 +163,30 @@ void debug(const char *msg, ...); /* Printf to debug output */
#define DBG(x, y...) do { } while(0)
#endif
#define ASSERT_DIE(x) do { if (!(x)) bug("Assertion '%s' failed at %s:%d", #x, __FILE__, __LINE__); } while(0)
#define EXPENSIVE_CHECK(x) /* intentionally left blank */
#ifdef DEBUGGING
#define ASSERT(x) do { if (!(x)) bug("Assertion `%s' failed at %s:%d", #x, __FILE__, __LINE__); } while(0)
#define ASSERT(x) ASSERT_DIE(x)
#define ASSUME(x) ASSERT_DIE(x)
#ifdef ENABLE_EXPENSIVE_CHECKS
#undef EXPENSIVE_CHECK
#define EXPENSIVE_CHECK(x) ASSERT_DIE(x)
#endif
#else
#define ASSERT(x) do { } while(0)
#define ASSERT(x) do { if (!(x)) log(L_BUG "Assertion '%s' failed at %s:%d", #x, __FILE__, __LINE__); } while(0)
#define ASSUME(x) /* intentionally left blank */
#endif
#ifdef DEBUGGING
asm(
".pushsection \".debug_gdb_scripts\", \"MS\",@progbits,1\n"
".byte 1\n" /* Python */
".asciz \"bird-gdb.py\"\n"
".popsection\n"
);
#endif
/* Pseudorandom numbers */

197
lib/bitmap.c Normal file
View File

@ -0,0 +1,197 @@
/*
* BIRD Library -- Bitmaps
*
* (c) 2019 Ondrej Zajicek <santiago@crfreenet.org>
* (c) 2019 CZ.NIC z.s.p.o.
*
* Can be freely distributed and used under the terms of the GNU GPL.
*/
#include <stdlib.h>
#include "nest/bird.h"
#include "lib/bitmap.h"
#include "lib/bitops.h"
#include "lib/resource.h"
/*
* Basic bitmap
*/
void
bmap_init(struct bmap *b, pool *p, uint size)
{
b->size = BIRD_ALIGN(size, 4);
b->data = mb_allocz(p, b->size);
}
void
bmap_reset(struct bmap *b, uint size)
{
b->size = BIRD_ALIGN(size, 4);
memset(b->data, 0, b->size);
}
void
bmap_grow(struct bmap *b, uint need)
{
uint size = b->size * 2;
while (size < need)
size *= 2;
uint old_size = b->size;
b->size = size;
b->data = mb_realloc(b->data, b->size);
ASSERT(size >= old_size);
memset(b->data + (old_size / 4), 0, size - old_size);
}
void
bmap_free(struct bmap *b)
{
mb_free(b->data);
b->size = 0;
b->data = NULL;
}
/*
* Hierarchical bitmap
*/
#define B256_SIZE(b) BIRD_ALIGN(b, 32)
#define B256_STEP(b) (BIRD_ALIGN(b, 8192) >> 8)
void
hmap_init(struct hmap *b, pool *p, uint size)
{
b->size[0] = B256_SIZE(size);
b->size[1] = B256_STEP(b->size[0]);
b->size[2] = B256_STEP(b->size[1]);
b->size[3] = sizeof(b->root);
b->data[0] = mb_allocz(p, b->size[0]);
b->data[1] = mb_allocz(p, b->size[1]);
b->data[2] = mb_allocz(p, b->size[2]);
b->data[3] = b->root;
memset(b->root, 0, sizeof(b->root));
}
static void
hmap_grow(struct hmap *b, uint need)
{
uint size = b->size[0] * 2;
while (size < need)
size *= 2;
for (uint i = 0; i < 3; i++)
{
uint old_size = b->size[i];
b->size[i] = size;
b->data[i] = mb_realloc(b->data[i], b->size[i]);
ASSERT(size >= old_size);
memset(b->data[i] + (old_size / 4), 0, size - old_size);
size = B256_STEP(size);
}
}
void
hmap_free(struct hmap *b)
{
mb_free(b->data[0]);
mb_free(b->data[1]);
mb_free(b->data[2]);
memset(b, 0, sizeof(struct hmap));
}
static inline int
b256_and(u32 *p)
{
for (int i = 0; i < 8; i++)
if (~p[i])
return 0;
return 1;
}
void
hmap_set(struct hmap *b, uint n)
{
if (n >= hmap_max(b))
hmap_grow(b, n/8 + 1);
for (int i = 0; i < 4; i++)
{
BIT32_SET(b->data[i], n);
n = n >> 8;
/* Continue if all bits in 256-bit block are set */
if (! b256_and(b->data[i] + 8*n))
break;
}
}
void
hmap_clear(struct hmap *b, uint n)
{
if (n >= hmap_max(b))
return;
for (int i = 0; i < 4; i++)
{
BIT32_CLR(b->data[i], n);
n = n >> 8;
}
}
static inline int
b256_first_zero(u32 *p)
{
for (int i = 0; i < 8; i++)
if (~p[i])
return 32*i + u32_ctz(~p[i]);
return 256;
}
u32
hmap_first_zero(struct hmap *b)
{
u32 n = 0;
for (int i = 3; i >= 0; i--)
{
if (32*n >= b->size[i])
return hmap_max(b);
u32 *p = b->data[i] + 8*n;
n = (n << 8) + b256_first_zero(p);
}
return n;
}
void
hmap_check(struct hmap *b)
{
for (int i = 0; i < 2; i++)
{
int max = b->size[i] / 32;
for (int j = 0; j < max; j++)
{
int x = b256_and(b->data[i] + 8*j);
int y = !!BIT32_TEST(b->data[i+1], j);
if (x != y)
bug("Inconsistent data on %d:%d (%d vs %d)", i, j, x, y);
}
}
}

63
lib/bitmap.h Normal file
View File

@ -0,0 +1,63 @@
/*
* BIRD Library -- Bitmaps
*
* (c) 2019 Ondrej Zajicek <santiago@crfreenet.org>
* (c) 2019 CZ.NIC z.s.p.o.
*
* Can be freely distributed and used under the terms of the GNU GPL.
*/
#ifndef _BIRD_BITMAP_H_
#define _BIRD_BITMAP_H_
struct bmap
{
u32 size;
u32 *data;
};
void bmap_init(struct bmap *b, pool *p, uint size);
void bmap_reset(struct bmap *b, uint size);
void bmap_grow(struct bmap *b, uint need);
void bmap_free(struct bmap *b);
static inline uint bmap_max(struct bmap *b)
{ return 8 * b->size; }
static inline int bmap_test(struct bmap *b, uint n)
{ return (n < bmap_max(b)) && BIT32_TEST(b->data, n); }
static inline void bmap_set(struct bmap *b, uint n)
{
if (n >= bmap_max(b)) bmap_grow(b, n/8 + 1);
BIT32_SET(b->data, n);
}
static inline void bmap_clear(struct bmap *b, uint n)
{
if (n >= bmap_max(b)) return;
BIT32_CLR(b->data, n);
}
struct hmap
{
u32 size[4];
u32 *data[4];
u32 root[8];
};
static inline uint hmap_max(struct hmap *b)
{ return 8 * b->size[0]; }
static inline int hmap_test(struct hmap *b, uint n)
{ return (n < hmap_max(b)) && BIT32_TEST(b->data[0], n); }
void hmap_init(struct hmap *b, pool *p, uint size);
void hmap_free(struct hmap *b);
void hmap_set(struct hmap *b, uint n);
void hmap_clear(struct hmap *b, uint n);
u32 hmap_first_zero(struct hmap *b);
void hmap_check(struct hmap *b);
#endif

186
lib/bitmap_test.c Normal file
View File

@ -0,0 +1,186 @@
/*
* BIRD Library -- Bitmap Tests
*
* (c) 2019 Ondrej Zajicek <santiago@crfreenet.org>
* (c) 2019 CZ.NIC z.s.p.o.
*
* Can be freely distributed and used under the terms of the GNU GPL.
*/
#include "test/birdtest.h"
#include "sysdep/config.h"
#include "lib/bitmap.h"
#define MAX_NUM (1 << 20)
#define MAX_SET (1 << 19)
#define MAX_CLR (1 << 17)
#define STEP_NUM 1000
#define STEP_SET 1000
#define STEP_CLR 500
static int
t_bmap_set_clear_random(void)
{
struct bmap b;
resource_init();
bmap_init(&b, &root_pool, 1024);
char expected[MAX_NUM] = {};
uint i, n;
for (i = 0; i < MAX_SET; i++)
{
do n = bt_random() % MAX_NUM;
while (expected[n]);
bmap_set(&b, n);
expected[n] = 1;
}
for (i = 0; i < MAX_CLR; i++)
{
do n = bt_random() % MAX_NUM;
while (!expected[n]);
bmap_clear(&b, n);
expected[n] = 0;
}
for (i = 0; i < MAX_NUM; i++)
if (bmap_test(&b, i) != expected[i])
bt_abort_msg("Bitmap mismatch on %d (should be %d %d)", i, bmap_test(&b, i), expected[i]);
return 1;
}
static int
t_hmap_set_clear_random(void)
{
struct hmap b;
resource_init();
hmap_init(&b, &root_pool, 1024);
char expected[MAX_NUM] = {};
uint i, n;
for (i = 0; i < MAX_SET; i++)
{
do n = bt_random() % MAX_NUM;
while (expected[n]);
hmap_set(&b, n);
expected[n] = 1;
}
hmap_check(&b);
for (i = 0; i < MAX_CLR; i++)
{
do n = bt_random() % MAX_NUM;
while (!expected[n]);
hmap_clear(&b, n);
expected[n] = 0;
}
hmap_check(&b);
for (i = 0; i < MAX_NUM; i++)
if (hmap_test(&b, i) != expected[i])
bt_abort_msg("Bitmap mismatch on %d (should be %d %d)", i, hmap_test(&b, i), expected[i]);
for (i = 0; 1; i++)
{
n = hmap_first_zero(&b);
bt_assert(n >= i);
bt_assert(n <= MAX_NUM);
for (; i < n; i++)
bt_assert(expected[i]);
if (n == MAX_NUM)
break;
bt_assert(!expected[i]);
hmap_set(&b, n);
}
hmap_check(&b);
return 1;
}
static int
t_hmap_set_clear_fill(void)
{
struct hmap b;
resource_init();
hmap_init(&b, &root_pool, 1024);
char expected[MAX_NUM] = {};
uint i, j, n, max = 0;
for (i = 0; i < STEP_NUM; i++)
{
uint last = 0;
uint step_set = bt_random() % STEP_SET;
uint step_clr = bt_random() % STEP_CLR;
for (j = 0; j < step_set; j++)
{
n = hmap_first_zero(&b);
bt_assert(n > last || !last);
bt_assert(n < MAX_NUM);
if (!last)
last = n;
for (; last < n; last++)
bt_assert(expected[last]);
bt_assert(!expected[n]);
hmap_set(&b, n);
expected[n] = 1;
max = MAX(max, n);
}
for (j = 0; j < step_clr; j++)
{
uint k = 0;
do n = bt_random() % max;
while (!expected[n] && (k++ < 8));
if (!expected[n])
continue;
hmap_clear(&b, n);
expected[n] = 0;
}
}
for (i = 0; i < MAX_NUM; i++)
if (hmap_test(&b, i) != expected[i])
bt_abort_msg("Bitmap mismatch on %d (should be %d %d)", i, hmap_test(&b, i), expected[i]);
hmap_check(&b);
return 1;
}
int
main(int argc, char *argv[])
{
bt_init(argc, argv);
bt_test_suite(t_bmap_set_clear_random, "BMap - random sequence of sets / clears");
bt_test_suite(t_hmap_set_clear_random, "HMap - random sequence of sets / clears");
bt_test_suite(t_hmap_set_clear_fill, "HMap - linear sets and random clears");
return bt_exit_value();
}

View File

@ -29,4 +29,9 @@ static inline u32 u32_hash(u32 v) { return v * 2902958171u; }
static inline u8 u32_popcount(u32 v) { return __builtin_popcount(v); }
static inline int u32_clz(u32 v) { return __builtin_clz(v); }
static inline int u32_ctz(u32 v) { return __builtin_ctz(v); }
static inline int uint_is_pow2(uint n) { return n && !(n & (n-1)); }
#endif

View File

@ -50,6 +50,8 @@
#define BUFFER_FLUSH(v) ({ (v).used = 0; })
#define BUFFER_EMPTY(v) ({ (v).used == 0; })
#define BUFFER_WALK(v,n) \
for (BUFFER_TYPE(v) *_n = (v).data, n; _n < ((v).data + (v).used) && (n = *_n, 1); _n++)

View File

@ -23,6 +23,7 @@
#include "lib/event.h"
event_list global_event_list;
event_list global_work_list;
inline void
ev_postpone(event *e)
@ -114,6 +115,22 @@ ev_schedule(event *e)
ev_enqueue(&global_event_list, e);
}
/**
* ev_schedule_work - schedule a work-event.
* @e: an event
*
* This function schedules an event by enqueueing it to a system-wide work-event
* list which is run by the platform dependent code whenever appropriate. This
* is designated for work-events instead of regular events. They are executed
* less often in order to not clog I/O loop.
*/
void
ev_schedule_work(event *e)
{
if (!ev_active(e))
add_tail(&global_work_list, &e->n);
}
void io_log_event(void *hook, void *data);
/**
@ -136,10 +153,47 @@ ev_run_list(event_list *l)
event *e = SKIP_BACK(event, n, n);
/* This is ugly hack, we want to log just events executed from the main I/O loop */
if (l == &global_event_list)
if ((l == &global_event_list) || (l == &global_work_list))
io_log_event(e->hook, e->data);
ev_run(e);
}
return !EMPTY_LIST(*l);
}
int
ev_run_list_limited(event_list *l, uint limit)
{
node *n;
list tmp_list;
init_list(&tmp_list);
add_tail_list(&tmp_list, l);
init_list(l);
WALK_LIST_FIRST(n, tmp_list)
{
event *e = SKIP_BACK(event, n, n);
if (!limit)
break;
/* This is ugly hack, we want to log just events executed from the main I/O loop */
if ((l == &global_event_list) || (l == &global_work_list))
io_log_event(e->hook, e->data);
ev_run(e);
limit--;
}
if (!EMPTY_LIST(tmp_list))
{
/* Attach new items after the unprocessed old items */
add_tail_list(&tmp_list, l);
init_list(l);
add_tail_list(l, &tmp_list);
}
return !EMPTY_LIST(*l);
}

View File

@ -21,14 +21,17 @@ typedef struct event {
typedef list event_list;
extern event_list global_event_list;
extern event_list global_work_list;
event *ev_new(pool *);
void ev_run(event *);
#define ev_init_list(el) init_list(el)
void ev_enqueue(event_list *, event *);
void ev_schedule(event *);
void ev_schedule_work(event *);
void ev_postpone(event *);
int ev_run_list(event_list *);
int ev_run_list_limited(event_list *, uint);
static inline int
ev_active(event *e)
@ -36,5 +39,14 @@ ev_active(event *e)
return e->n.next != NULL;
}
static inline event*
ev_new_init(pool *p, void (*hook)(void *), void *data)
{
event *e = ev_new(p);
e->hook = hook;
e->data = data;
return e;
}
#endif

View File

@ -24,24 +24,33 @@ straightforward_fletcher16_compute(const char *data)
sum2 = (sum2 + sum1) % 255;
}
return (sum2 << 8) | sum1;
sum2 = (sum2 + sum1) % 255;
sum2 = (sum2 + sum1) % 255;
return (sum1 << 8) | sum2;
}
static u16
straightforward_fletcher16_checksum(const char *data)
{
u16 csum;
u8 c0,c1,f0,f1;
u16 c0,c1,x,y;
csum = straightforward_fletcher16_compute(data);
f0 = csum & 0xff;
f1 = (csum >> 8) & 0xff;
c0 = 0xff - ((f0 + f1) % 0xff);
c1 = 0xff - ((f0 + c0) % 0xff);
c0 = (csum >> 8) & 0xff;
c1 = csum & 0xff;
return (c1 << 8) | c0;
x = (255 + c0 - c1) % 255;
y = (510 - 2*c0 + c1) % 255;
if (!x) x = 255;
if (!y) y = 255;
return (x << 8) | y;
}
const u8 zero16[2] = {};
static int
test_fletcher16(void *out_, const void *in_, const void *expected_out_)
{
@ -53,7 +62,8 @@ test_fletcher16(void *out_, const void *in_, const void *expected_out_)
fletcher16_init(&ctxt);
fletcher16_update(&ctxt, in, strlen(in));
put_u16(out, fletcher16_compute(&ctxt));
fletcher16_update(&ctxt, zero16, 2);
*out = fletcher16_compute(&ctxt);
return *out == *expected_out;
}
@ -70,7 +80,8 @@ test_fletcher16_checksum(void *out_, const void *in_, const void *expected_out_)
fletcher16_init(&ctxt);
fletcher16_update(&ctxt, in, len);
put_u16(out, fletcher16_final(&ctxt, len, len));
fletcher16_update(&ctxt, zero16, 2);
*out = fletcher16_final(&ctxt, len+2, len);
return *out == *expected_out;
}
@ -81,7 +92,7 @@ t_fletcher16_compute(void)
struct bt_pair test_vectors[] = {
{
.in = "\001\002",
.out = & (const u16) { 0x0403 },
.out = & ((const u16) { straightforward_fletcher16_compute("\001\002") }),
},
{
.in = "",

View File

@ -112,7 +112,6 @@ get_value_length(const byte *op)
}
/*
* Flowspec iterators
*/
@ -244,6 +243,69 @@ flow6_next_part(const byte *pos, const byte *end)
return flow_next_part(pos, end, 1);
}
static const byte *
flow_get_part(const byte *data, uint dlen, uint type, int ipv6)
{
const byte *part;
for (part = flow_first_part(data);
part && (part[0] <= type);
part = flow_next_part(part, data+dlen, ipv6))
if (part[0] == type)
return part;
return NULL;
}
const byte *
flow4_get_part(const net_addr_flow4 *f, uint type)
{
return flow_get_part(f->data, f->length - sizeof(net_addr_flow4), type, 0);
}
const byte *
flow6_get_part(const net_addr_flow6 *f, uint type)
{
return flow_get_part(f->data, f->length - sizeof(net_addr_flow6), type, 1);
}
/*
* Flowspec accessors
*/
static inline ip4_addr
flow_read_ip4(const byte *px, uint pxlen)
{
ip4_addr ip = IP4_NONE;
memcpy(&ip, px, BYTES(pxlen));
return ip4_ntoh(ip);
}
ip4_addr
flow_read_ip4_part(const byte *part)
{
return flow_read_ip4(part + 2, part[1]);
}
static inline ip6_addr
flow_read_ip6(const byte *px, uint pxlen, uint pxoffset)
{
uint floor_offset = BYTES(pxoffset - (pxoffset % 8));
uint ceil_len = BYTES(pxlen);
ip6_addr ip = IP6_NONE;
memcpy(((byte *) &ip) + floor_offset, px, ceil_len - floor_offset);
return ip6_ntoh(ip);
}
ip6_addr
flow_read_ip6_part(const byte *part)
{
return flow_read_ip6(part + 3, part[1], part[2]);
}
/*
* Flowspec validation
@ -374,7 +436,6 @@ flow_validate(const byte *nlri, uint len, int ipv6)
enum flow_type type = 0;
const byte *pos = nlri;
const byte *end = nlri + len;
int met_dst_pfx = 0;
while (pos < end)
{
@ -386,8 +447,6 @@ flow_validate(const byte *nlri, uint len, int ipv6)
switch (type)
{
case FLOW_TYPE_DST_PREFIX:
met_dst_pfx = 1;
/* Fall through */
case FLOW_TYPE_SRC_PREFIX:
{
uint pxlen = *pos++;
@ -494,9 +553,6 @@ flow_validate(const byte *nlri, uint len, int ipv6)
if (pos != end)
return FLOW_ST_NOT_COMPLETE;
if (!ipv6 && !met_dst_pfx)
return FLOW_ST_DEST_PREFIX_REQUIRED;
return FLOW_ST_VALID;
}
@ -779,26 +835,6 @@ flow_builder_set_type(struct flow_builder *fb, enum flow_type type)
fb->this_type = type;
}
static ip4_addr
flow_read_ip4(const byte *px, uint pxlen)
{
ip4_addr ip = IP4_NONE;
memcpy(&ip, px, BYTES(pxlen));
return ip4_ntoh(ip);
}
static ip6_addr
flow_read_ip6(const byte *px, uint pxlen, uint pxoffset)
{
uint floor_offset = BYTES(pxoffset - (pxoffset % 8));
uint ceil_len = BYTES(pxlen);
ip6_addr ip = IP6_NONE;
memcpy(((byte *) &ip) + floor_offset, px, ceil_len - floor_offset);
return ip6_ntoh(ip);
}
static void
builder_write_parts(struct flow_builder *fb, byte *buf)
{
@ -831,9 +867,9 @@ flow_builder4_finalize(struct flow_builder *fb, linpool *lpool)
if (fb->parts[FLOW_TYPE_DST_PREFIX].length)
{
byte *p = fb->data.data + fb->parts[FLOW_TYPE_DST_PREFIX].offset + 1;
pxlen = *p++;
prefix = flow_read_ip4(p, pxlen);
byte *part = fb->data.data + fb->parts[FLOW_TYPE_DST_PREFIX].offset;
prefix = flow_read_ip4_part(part);
pxlen = flow_read_pxlen(part);
}
*f = NET_ADDR_FLOW4(prefix, pxlen, data_len);
@ -861,10 +897,9 @@ flow_builder6_finalize(struct flow_builder *fb, linpool *lpool)
if (fb->parts[FLOW_TYPE_DST_PREFIX].length)
{
byte *p = fb->data.data + fb->parts[FLOW_TYPE_DST_PREFIX].offset + 1;
pxlen = *p++;
uint pxoffset = *p++;
prefix = flow_read_ip6(p, pxlen, pxoffset);
byte *part = fb->data.data + fb->parts[FLOW_TYPE_DST_PREFIX].offset;
prefix = flow_read_ip6_part(part);
pxlen = flow_read_pxlen(part);
}
*n = NET_ADDR_FLOW6(prefix, pxlen, data_len);
@ -947,18 +982,18 @@ fragment_val_str(u8 val)
static void
net_format_flow_ip(buffer *b, const byte *part, int ipv6)
{
uint pxlen = *(part+1);
uint pxlen = part[1];
if (ipv6)
{
uint pxoffset = *(part+2);
uint pxoffset = part[2];
if (pxoffset)
buffer_print(b, "%I6/%u offset %u; ", flow_read_ip6(part+3,pxlen,pxoffset), pxlen, pxoffset);
buffer_print(b, "%I6/%u offset %u; ", flow_read_ip6_part(part), pxlen, pxoffset);
else
buffer_print(b, "%I6/%u; ", flow_read_ip6(part+3,pxlen,0), pxlen);
buffer_print(b, "%I6/%u; ", flow_read_ip6_part(part), pxlen);
}
else
{
buffer_print(b, "%I4/%u; ", flow_read_ip4(part+2,pxlen), pxlen);
buffer_print(b, "%I4/%u; ", flow_read_ip4_part(part), pxlen);
}
}

View File

@ -83,6 +83,17 @@ const byte *flow4_first_part(const net_addr_flow4 *f);
const byte *flow6_first_part(const net_addr_flow6 *f);
const byte *flow4_next_part(const byte *pos, const byte *end);
const byte *flow6_next_part(const byte *pos, const byte *end);
const byte *flow4_get_part(const net_addr_flow4 *f, uint type);
const byte *flow6_get_part(const net_addr_flow6 *f, uint type);
/*
* Flowspec accessors
*/
ip4_addr flow_read_ip4_part(const byte *part);
ip6_addr flow_read_ip6_part(const byte *part);
static inline int flow_read_pxlen(const byte *part) { return part[1]; }
/*

View File

@ -70,8 +70,8 @@ t_first_part(void)
net_addr_flow4 *f;
NET_ADDR_FLOW4_(f, ip4_build(10,0,0,1), 24, ((byte[]) { 0x00, 0x00, 0xab }));
const byte const *under240 = &f->data[1];
const byte const *above240 = &f->data[2];
const byte *under240 = &f->data[1];
const byte *above240 = &f->data[2];
/* Case 0x00 0x00 */
bt_assert(flow4_first_part(f) == NULL);
@ -137,7 +137,7 @@ static int
t_iterators6(void)
{
net_addr_flow6 *f;
NET_ADDR_FLOW6_(f, ip6_build(0,0,0x12345678,0x9a000000), 64, ((byte[]) {
NET_ADDR_FLOW6_(f, ip6_build(0,0,0x12345678,0x9a000000), 0x68, ((byte[]) {
26, /* Length */
FLOW_TYPE_DST_PREFIX, 0x68, 0x40, 0x12, 0x34, 0x56, 0x78, 0x9a,
FLOW_TYPE_SRC_PREFIX, 0x08, 0x0, 0xc0,
@ -166,6 +166,56 @@ t_iterators6(void)
return 1;
}
static int
t_accessors4(void)
{
net_addr_flow4 *f;
NET_ADDR_FLOW4_(f, ip4_build(5,6,7,0), 24, ((byte[]) {
25, /* Length */
FLOW_TYPE_DST_PREFIX, 24, 5, 6, 7,
FLOW_TYPE_SRC_PREFIX, 32, 10, 11, 12, 13,
FLOW_TYPE_IP_PROTOCOL, 0x81, 0x06,
FLOW_TYPE_PORT, 0x03, 0x89, 0x45, 0x8b, 0x91, 0x1f, 0x90,
FLOW_TYPE_TCP_FLAGS, 0x80, 0x55,
}));
const byte *p1_dst_px = &f->data[1];
const ip4_addr p1_dst_addr = ip4_build(5,6,7,0);
const byte *p2_src_px = &f->data[6];
const ip4_addr p2_src_addr = ip4_build(10,11,12,13);
bt_assert(ip4_equal(flow_read_ip4_part(p1_dst_px), p1_dst_addr));
bt_assert(ip4_equal(flow_read_ip4_part(p2_src_px), p2_src_addr));
return 1;
}
static int
t_accessors6(void)
{
net_addr_flow6 *f;
NET_ADDR_FLOW6_(f, ip6_build(0,0,0x12345678,0x9a000000), 0x68, ((byte[]) {
26, /* Length */
FLOW_TYPE_DST_PREFIX, 0x68, 0x40, 0x12, 0x34, 0x56, 0x78, 0x9a,
FLOW_TYPE_SRC_PREFIX, 0x08, 0x0, 0xc0,
FLOW_TYPE_NEXT_HEADER, 0x81, 0x06,
FLOW_TYPE_PORT, 0x03, 0x89, 0x45, 0x8b, 0x91, 0x1f, 0x90,
FLOW_TYPE_LABEL, 0x80, 0x55,
}));
const byte *p1_dst_px = &f->data[1];
const ip6_addr p1_dst_addr = ip6_build(0,0,0x12345678,0x9a000000);
const byte *p2_src_px = &f->data[9];
const ip6_addr p2_src_addr = ip6_build(0xc0000000, 0, 0, 0);
bt_assert(ip6_equal(flow_read_ip6_part(p1_dst_px), p1_dst_addr));
bt_assert(ip6_equal(flow_read_ip6_part(p2_src_px), p2_src_addr));
return 1;
}
static int
t_validation4(void)
{
@ -179,11 +229,9 @@ t_validation4(void)
FLOW_TYPE_TCP_FLAGS, 0x80, 0x55,
};
/* Isn't included destination prefix */
/* Empty NLRI */
res = flow4_validate(nlri1, 0);
bt_assert(res == FLOW_ST_DEST_PREFIX_REQUIRED);
res = flow4_validate(&nlri1[5], sizeof(nlri1)-5);
bt_assert(res == FLOW_ST_DEST_PREFIX_REQUIRED);
bt_assert(res == FLOW_ST_VALID);
/* Valid / Not Complete testing */
uint valid_sizes[] = {5, 11, 14, 22, 25, 0};
@ -628,6 +676,8 @@ main(int argc, char *argv[])
bt_test_suite(t_first_part, "Searching first part in net_addr_flow");
bt_test_suite(t_iterators4, "Testing iterators (IPv4)");
bt_test_suite(t_iterators6, "Testing iterators (IPv6)");
bt_test_suite(t_accessors4, "Testing accessors (IPv4)");
bt_test_suite(t_accessors6, "Testing accessors (IPv6)");
bt_test_suite(t_validation4, "Testing validation (IPv4)");
bt_test_suite(t_validation6, "Testing validation (IPv6)");
bt_test_suite(t_builder4, "Inserting components into existing Flow Specification (IPv4)");

View File

@ -202,7 +202,7 @@ mem_hash_init(u64 *h)
}
static inline void
mem_hash_mix(u64 *h, void *p, uint s)
mem_hash_mix(u64 *h, const void *p, uint s)
{
const u64 multiplier = 0xb38bc09a61202731ULL;
const char *pp = p;
@ -222,7 +222,7 @@ mem_hash_value(u64 *h)
}
static inline uint
mem_hash(void *p, uint s)
mem_hash(const void *p, uint s)
{
static u64 h;
mem_hash_init(&h);
@ -230,4 +230,11 @@ mem_hash(void *p, uint s)
return mem_hash_value(&h);
}
static inline uint
ptr_hash(void *ptr)
{
uintptr_t p = (uintptr_t) ptr;
return p ^ (p << 8) ^ (p >> 16);
}
#endif

View File

@ -245,7 +245,7 @@ ip4_pton(const char *a, ip4_addr *o)
char *d, *c = strchr(a, '.');
if (!c != !i)
return 0;
l = strtoul(a, &d, 10);
l = bstrtoul10(a, &d);
if (((d != c) && *d) || (l > 255))
return 0;
ia = (ia << 8) | l;
@ -264,6 +264,9 @@ ip6_pton(const char *a, ip6_addr *o)
int i, j, k, l, hfil;
const char *start;
if (!a[0]) /* Empty string check */
return 0;
if (a[0] == ':') /* Leading :: */
{
if (a[1] != ':')
@ -333,6 +336,8 @@ ip6_pton(const char *a, ip6_addr *o)
for (; i>=hfil; i--)
words[i] = 0;
}
else if (i != 8) /* Incomplete address */
return 0;
/* Convert the address to ip6_addr format */
for (i=0; i<4; i++)

View File

@ -48,6 +48,13 @@
#define UDP_HEADER_LENGTH 8
/* IANA Address Family Numbers */
/* https://www.iana.org/assignments/address-family-numbers/address-family-numbers.xhtml */
/* Would use AF_ prefix, but that collides with POSIX address family numbers */
#define AFI_IPV4 1
#define AFI_IPV6 2
#ifdef DEBUGGING
typedef struct ip4_addr {
@ -61,7 +68,7 @@ typedef struct ip4_addr {
typedef u32 ip4_addr;
#define _MI4(x) (x)
#define _MI4(x) ((u32) (x))
#define _I(x) (x)
#endif
@ -186,13 +193,7 @@ static inline int ipa_nonzero2(ip_addr a)
*/
static inline u32 ip4_hash(ip4_addr a)
{
/* Returns a 32-bit value, although low-order bits are not mixed */
u32 x = _I(a);
x ^= x << 16;
x ^= x << 12;
return x;
}
{ return u32_hash(_I(a)); }
static inline u32 ip6_hash(ip6_addr a)
{
@ -241,6 +242,9 @@ static inline int ip6_is_v4mapped(ip6_addr a)
#define ipa_classify(x) ip6_classify(&(x))
#define ipa_is_link_local(x) ip6_is_link_local(x)
static inline int ip4_is_unicast(ip4_addr a)
{ return _I(a) < 0xe0000000; }
/* XXXX remove */
static inline int ipa_classify_net(ip_addr a)
{ return ipa_zero2(a) ? (IADDR_HOST | SCOPE_UNIVERSE) : ipa_classify(a); }
@ -357,12 +361,12 @@ mpls_put(char *buf, int len, u32 *stack)
* Unaligned data access (in network order)
*/
static inline ip4_addr get_ip4(void *buf)
static inline ip4_addr get_ip4(const void *buf)
{
return _MI4(get_u32(buf));
}
static inline ip6_addr get_ip6(void *buf)
static inline ip6_addr get_ip6(const void *buf)
{
ip6_addr a;
memcpy(&a, buf, 16);

View File

@ -13,25 +13,38 @@
#define IP4_MAX_LEN 16
static int
test_ipa_pton(void *out_, const void *in_, const void *expected_out_)
test_ip4_pton(void *out_, const void *in_, const void *expected_out_)
{
ip_addr *out = out_;
const char *in = in_;
const ip_addr *expected_out = expected_out_;
ip4_addr ip4;
if (expected_out)
{
bt_assert(ip4_pton(in, &ip4));
*out = ipa_from_ip4(ip4);
return ipa_equal(*out, *expected_out);
}
else
return !ip4_pton(in, &ip4);
}
static int
test_ip6_pton(void *out_, const void *in_, const void *expected_out_)
{
ip_addr *out = out_;
const char *in = in_;
const ip_addr *expected_out = expected_out_;
if (ipa_is_ip4(*expected_out))
{
ip4_addr ip4;
bt_assert(ip4_pton(in, &ip4));
*out = ipa_from_ip4(ip4);
}
else
if (expected_out)
{
bt_assert(ip6_pton(in, out));
/* ip_addr == ip6_addr */
return ipa_equal(*out, *expected_out);
}
return ipa_equal(*out, *expected_out);
else
return !ip6_pton(in, out);
}
static int
@ -52,7 +65,7 @@ t_ip4_pton(void)
},
};
return bt_assert_batch(test_vectors, test_ipa_pton, bt_fmt_str, bt_fmt_ipa);
return bt_assert_batch(test_vectors, test_ip4_pton, bt_fmt_str, bt_fmt_ipa);
}
static int
@ -87,9 +100,17 @@ t_ip6_pton(void)
.in = "2605:2700:0:3::4713:93e3",
.out = & ipa_build6(0x26052700, 0x00000003, 0x00000000, 0x471393E3),
},
{
.in = "2605:2700:0:3:4713:93e3",
.out = NULL,
},
{
.in = "2",
.out = NULL,
},
};
return bt_assert_batch(test_vectors, test_ipa_pton, bt_fmt_str, bt_fmt_ipa);
return bt_assert_batch(test_vectors, test_ip6_pton, bt_fmt_str, bt_fmt_ipa);
}
static int

View File

@ -29,6 +29,42 @@
#include "nest/bird.h"
#include "lib/lists.h"
LIST_INLINE int
check_list(list *l, node *n)
{
if (!l)
{
ASSERT_DIE(n);
ASSERT_DIE(n->prev);
do { n = n->prev; } while (n->prev);
l = SKIP_BACK(list, head_node, n);
}
int seen = 0;
ASSERT_DIE(l->null == NULL);
ASSERT_DIE(l->head != NULL);
ASSERT_DIE(l->tail != NULL);
node *prev = &l->head_node, *cur = l->head, *next = l->head->next;
while (next)
{
if (cur == n)
seen++;
ASSERT_DIE(cur->prev == prev);
prev = cur;
cur = next;
next = next->next;
}
ASSERT_DIE(cur == &(l->tail_node));
ASSERT_DIE(!n || (seen == 1));
return 1;
}
/**
* add_tail - append a node to a list
* @l: linked list
@ -39,6 +75,10 @@
LIST_INLINE void
add_tail(list *l, node *n)
{
EXPENSIVE_CHECK(check_list(l, NULL));
ASSUME(n->prev == NULL);
ASSUME(n->next == NULL);
node *z = l->tail;
n->next = &l->tail_node;
@ -57,6 +97,10 @@ add_tail(list *l, node *n)
LIST_INLINE void
add_head(list *l, node *n)
{
EXPENSIVE_CHECK(check_list(l, NULL));
ASSUME(n->prev == NULL);
ASSUME(n->next == NULL);
node *z = l->head;
n->next = z;
@ -76,6 +120,10 @@ add_head(list *l, node *n)
LIST_INLINE void
insert_node(node *n, node *after)
{
EXPENSIVE_CHECK(check_list(l, after));
ASSUME(n->prev == NULL);
ASSUME(n->next == NULL);
node *z = after->next;
n->next = z;
@ -93,6 +141,8 @@ insert_node(node *n, node *after)
LIST_INLINE void
rem_node(node *n)
{
EXPENSIVE_CHECK(check_list(NULL, n));
node *z = n->prev;
node *x = n->next;
@ -103,24 +153,20 @@ rem_node(node *n)
}
/**
* replace_node - replace a node in a list with another one
* @old: node to be removed
* @new: node to be inserted
* update_node - update node after calling realloc on it
* @n: node to be updated
*
* Replaces node @old in the list it's linked in with node @new. Node
* @old may be a copy of the original node, which is not accessed
* through the list. The function could be called with @old == @new,
* which just fixes neighbors' pointers in the case that the node
* was reallocated.
* Fixes neighbor pointers.
*/
LIST_INLINE void
replace_node(node *old, node *new)
update_node(node *n)
{
old->next->prev = new;
old->prev->next = new;
ASSUME(n->next->prev == n->prev->next);
new->prev = old->prev;
new->next = old->next;
n->next->prev = n;
n->prev->next = n;
EXPENSIVE_CHECK(check_list(NULL, n));
}
/**
@ -149,6 +195,9 @@ init_list(list *l)
LIST_INLINE void
add_tail_list(list *to, list *l)
{
EXPENSIVE_CHECK(check_list(to, NULL));
EXPENSIVE_CHECK(check_list(l, NULL));
node *p = to->tail;
node *q = l->head;
@ -157,6 +206,8 @@ add_tail_list(list *to, list *l)
q = l->tail;
q->next = &to->tail_node;
to->tail = q;
EXPENSIVE_CHECK(check_list(to, NULL));
}
LIST_INLINE uint
@ -165,6 +216,8 @@ list_length(list *l)
uint len = 0;
node *n;
EXPENSIVE_CHECK(check_list(l, NULL));
WALK_LIST(n, *l)
len++;

View File

@ -222,26 +222,29 @@ t_remove_node(void)
}
static int
t_replace_node(void)
t_update_node(void)
{
node head, inside, tail;
init_list_();
fill_list();
replace_node(&nodes[0], &head);
head = nodes[0];
update_node(&head);
bt_assert(l.head == &head);
bt_assert(head.prev == NODE &l.head);
bt_assert(head.next == &nodes[1]);
bt_assert(nodes[1].prev == &head);
replace_node(&nodes[MAX_NUM/2], &inside);
inside = nodes[MAX_NUM/2];
update_node(&inside);
bt_assert(nodes[MAX_NUM/2-1].next == &inside);
bt_assert(nodes[MAX_NUM/2+1].prev == &inside);
bt_assert(inside.prev == &nodes[MAX_NUM/2-1]);
bt_assert(inside.next == &nodes[MAX_NUM/2+1]);
replace_node(&nodes[MAX_NUM-1], &tail);
tail = nodes[MAX_NUM-1];
update_node(&tail);
bt_assert(l.tail == &tail);
bt_assert(tail.prev == &nodes[MAX_NUM-2]);
bt_assert(tail.next == NODE &l.null);
@ -280,7 +283,7 @@ main(int argc, char *argv[])
bt_test_suite(t_add_head, "Adding nodes to head of list");
bt_test_suite(t_insert_node, "Inserting nodes to list");
bt_test_suite(t_remove_node, "Removing nodes from list");
bt_test_suite(t_replace_node, "Replacing nodes in list");
bt_test_suite(t_update_node, "Updating nodes in list");
bt_test_suite(t_add_tail_list, "At the tail of a list adding the another list");
return bt_exit_value();

98
lib/macro.h Normal file
View File

@ -0,0 +1,98 @@
/*
* BIRD Macro Tricks
*
* (c) 2018 Jan Maria Matejka <mq@jmq.cz>
*
* Can be freely distributed and used under the terms of the GNU GPL.
*
* Contains useful but dirty macro tricks:
* MACRO_CONCAT(a, b) -> concatenates a##b
* MACRO_BOOL(x) -> convert 0 to 0, anything else to 1
* MACRO_IFELSE(b)(true-branch)(false-branch)
* -> b shall be 0 or 1; expands to the appropriate branch
* MACRO_ISEMPTY(...) -> 1 for empty argument list, 0 otherwise
* MACRO_FOREACH(func, ...)
* -> calling FOREACH(func, a, b, c, d) expands to
* func(a) func(b) func(c) func(d)
* MACRO_RPACK(func, terminator, ...)
* -> packs the list into recursive calls:
* func(func(func(func(terminator, a), b), c), d)
*/
#ifndef _BIRD_MACRO_H_
#define _BIRD_MACRO_H_
/* What to do with args */
#define MACRO_DROP(...)
#define MACRO_UNPAREN(...) __VA_ARGS__
#define MACRO_SEP(a, b, sep) a sep b
/* Aliases for some special chars */
#define MACRO_COMMA ,
#define MACRO_LPAREN (
#define MACRO_RPAREN )
#define MACRO_LPAREN_() (
#define MACRO_RPAREN_() )
/* Multiple expansion trick */
#define MACRO_EXPAND0(...) __VA_ARGS__
#define MACRO_EXPAND1(...) MACRO_EXPAND0(MACRO_EXPAND0(__VA_ARGS__))
#define MACRO_EXPAND2(...) MACRO_EXPAND1(MACRO_EXPAND1(__VA_ARGS__))
#define MACRO_EXPAND3(...) MACRO_EXPAND2(MACRO_EXPAND2(__VA_ARGS__))
#define MACRO_EXPAND(...) MACRO_EXPAND3(MACRO_EXPAND3(__VA_ARGS__))
/* Deferring expansion in the expansion trick */
#define MACRO_EMPTY()
#define MACRO_DEFER(t) t MACRO_EMPTY()
#define MACRO_DEFER2(t) t MACRO_EMPTY MACRO_EMPTY()()
#define MACRO_DEFER3(t) t MACRO_EMPTY MACRO_EMPTY MACRO_EMPTY()()()
/* Token concatenation */
#define MACRO_CONCAT(prefix, ...) prefix##__VA_ARGS__
#define MACRO_CONCAT_AFTER(...) MACRO_CONCAT(__VA_ARGS__)
/* Get first or second argument only */
#define MACRO_FIRST(a, ...) a
#define MACRO_SECOND(a, b, ...) b
#define MACRO_SECOND_OR_ZERO(...) MACRO_SECOND(__VA_ARGS__, 0,)
/* Macro Boolean auxiliary macros */
#define MACRO_BOOL_CHECK_0 ~, 1
#define MACRO_BOOL_NEG(x) MACRO_SECOND_OR_ZERO(MACRO_CONCAT(MACRO_BOOL_CHECK_, x))
#define MACRO_BOOL_NOT_0 1
#define MACRO_BOOL_NOT_1 0
/* Macro Boolean negation */
#define MACRO_NOT(x) MACRO_CONCAT(MACRO_BOOL_NOT_, x)
/* Convert anything to bool (anything -> 1, 0 -> 0) */
#define MACRO_BOOL(x) MACRO_NOT(MACRO_BOOL_NEG(x))
/*
* Macro If/Else condition
* Usage: MACRO_IFELSE(condition)(true-branch)(false-branch)
* Expands to true-branch if condition is true, otherwise to false-branch.
*/
#define MACRO_IFELSE(b) MACRO_CONCAT(MACRO_IFELSE_, b)
#define MACRO_IFELSE_0(...) MACRO_UNPAREN
#define MACRO_IFELSE_1(...) __VA_ARGS__ MACRO_DROP
/* Auxiliary macros for MACRO_FOREACH */
#define MACRO_ISLAST(...) MACRO_BOOL_NEG(MACRO_FIRST(MACRO_ISLAST_CHECK __VA_ARGS__)())
#define MACRO_ISLAST_CHECK() 0
#define MACRO_FOREACH_EXPAND(call, a, ...) MACRO_IFELSE(MACRO_ISLAST(__VA_ARGS__))(call(a))(call(a) MACRO_DEFER2(MACRO_FOREACH_PAREN)()(call, __VA_ARGS__))
#define MACRO_FOREACH_PAREN() MACRO_FOREACH_EXPAND
#define MACRO_RPACK_EXPAND(call, terminator, a, ...) MACRO_IFELSE(MACRO_ISLAST(__VA_ARGS__))(call(terminator, a))(call(MACRO_DEFER2(MACRO_RPACK_PAREN)()(call, terminator, __VA_ARGS__), a))
#define MACRO_RPACK_PAREN() MACRO_RPACK_EXPAND
/*
* Call the first argument for each following:
* MACRO_FOREACH(func, a, b, c, d) expands to func(a) func(b) func(c) func(d).
* It supports also macros as func.
*/
#define MACRO_FOREACH(call, ...) MACRO_EXPAND(MACRO_FOREACH_EXPAND(call, __VA_ARGS__))
#define MACRO_RPACK(call, terminator, ...) MACRO_EXPAND(MACRO_RPACK_EXPAND(call, terminator, __VA_ARGS__))
#endif

View File

@ -11,7 +11,7 @@
*
* Linear memory pools are collections of memory blocks which
* support very fast allocation of new blocks, but are able to free only
* the whole collection at once.
* the whole collection at once (or in stack order).
*
* Example: Each configuration is described by a complex system of structures,
* linked lists and function trees which are all allocated from a single linear
@ -37,7 +37,7 @@ const int lp_chunk_size = sizeof(struct lp_chunk);
struct linpool {
resource r;
byte *ptr, *end;
struct lp_chunk *first, *current, **plast; /* Normal (reusable) chunks */
struct lp_chunk *first, *current; /* Normal (reusable) chunks */
struct lp_chunk *first_large; /* Large chunks */
uint chunk_size, threshold, total, total_large;
};
@ -69,7 +69,6 @@ linpool
*lp_new(pool *p, uint blk)
{
linpool *m = ralloc(p, &lp_class);
m->plast = &m->first;
m->chunk_size = blk;
m->threshold = 3*blk/4;
return m;
@ -114,22 +113,25 @@ lp_alloc(linpool *m, uint size)
}
else
{
if (m->current)
if (m->current && m->current->next)
{
/* Still have free chunks from previous incarnation (before lp_flush()) */
c = m->current;
m->current = c->next;
c = m->current->next;
}
else
{
/* Need to allocate a new chunk */
c = xmalloc(sizeof(struct lp_chunk) + m->chunk_size);
m->total += m->chunk_size;
*m->plast = c;
m->plast = &c->next;
c->next = NULL;
c->size = m->chunk_size;
if (m->current)
m->current->next = c;
else
m->first = c;
}
m->current = c;
m->ptr = c->data + size;
m->end = c->data + m->chunk_size;
}
@ -190,9 +192,11 @@ lp_flush(linpool *m)
{
struct lp_chunk *c;
/* Relink all normal chunks to free list and free all large chunks */
m->ptr = m->end = NULL;
m->current = m->first;
/* Move ptr to the first chunk and free all large chunks */
m->current = c = m->first;
m->ptr = c ? c->data : NULL;
m->end = c ? c->data + m->chunk_size : NULL;
while (c = m->first_large)
{
m->first_large = c->next;
@ -201,6 +205,50 @@ lp_flush(linpool *m)
m->total_large = 0;
}
/**
* lp_save - save the state of a linear memory pool
* @m: linear memory pool
* @p: state buffer
*
* This function saves the state of a linear memory pool. Saved state can be
* used later to restore the pool (to free memory allocated since).
*/
void
lp_save(linpool *m, lp_state *p)
{
p->current = m->current;
p->large = m->first_large;
p->ptr = m->ptr;
}
/**
* lp_restore - restore the state of a linear memory pool
* @m: linear memory pool
* @p: saved state
*
* This function restores the state of a linear memory pool, freeing all memory
* allocated since the state was saved. Note that the function cannot un-free
* the memory, therefore the function also invalidates other states that were
* saved between (on the same pool).
*/
void
lp_restore(linpool *m, lp_state *p)
{
struct lp_chunk *c;
/* Move ptr to the saved pos and free all newer large chunks */
m->current = c = p->current;
m->ptr = p->ptr;
m->end = c ? c->data + m->chunk_size : NULL;
while ((c = m->first_large) && (c != p->large))
{
m->first_large = c->next;
m->total_large -= c->size;
xfree(c);
}
}
static void
lp_free(resource *r)
{

View File

@ -6,50 +6,54 @@
const char * const net_label[] = {
[NET_IP4] = "ipv4",
[NET_IP6] = "ipv6",
[NET_VPN4] = "vpn4",
[NET_VPN6] = "vpn6",
[NET_ROA4] = "roa4",
[NET_ROA6] = "roa6",
[NET_FLOW4] = "flow4",
[NET_FLOW6] = "flow6",
[NET_IP4] = "ipv4",
[NET_IP6] = "ipv6",
[NET_VPN4] = "vpn4",
[NET_VPN6] = "vpn6",
[NET_ROA4] = "roa4",
[NET_ROA6] = "roa6",
[NET_FLOW4] = "flow4",
[NET_FLOW6] = "flow6",
[NET_IP6_SADR]= "ipv6-sadr",
[NET_MPLS] = "mpls",
};
const u16 net_addr_length[] = {
[NET_IP4] = sizeof(net_addr_ip4),
[NET_IP6] = sizeof(net_addr_ip6),
[NET_VPN4] = sizeof(net_addr_vpn4),
[NET_VPN6] = sizeof(net_addr_vpn6),
[NET_ROA4] = sizeof(net_addr_roa4),
[NET_ROA6] = sizeof(net_addr_roa6),
[NET_FLOW4] = 0,
[NET_FLOW6] = 0,
[NET_IP4] = sizeof(net_addr_ip4),
[NET_IP6] = sizeof(net_addr_ip6),
[NET_VPN4] = sizeof(net_addr_vpn4),
[NET_VPN6] = sizeof(net_addr_vpn6),
[NET_ROA4] = sizeof(net_addr_roa4),
[NET_ROA6] = sizeof(net_addr_roa6),
[NET_FLOW4] = 0,
[NET_FLOW6] = 0,
[NET_IP6_SADR]= sizeof(net_addr_ip6_sadr),
[NET_MPLS] = sizeof(net_addr_mpls),
};
const u8 net_max_prefix_length[] = {
[NET_IP4] = IP4_MAX_PREFIX_LENGTH,
[NET_IP6] = IP6_MAX_PREFIX_LENGTH,
[NET_VPN4] = IP4_MAX_PREFIX_LENGTH,
[NET_VPN6] = IP6_MAX_PREFIX_LENGTH,
[NET_ROA4] = IP4_MAX_PREFIX_LENGTH,
[NET_ROA6] = IP6_MAX_PREFIX_LENGTH,
[NET_FLOW4] = IP4_MAX_PREFIX_LENGTH,
[NET_FLOW6] = IP6_MAX_PREFIX_LENGTH,
[NET_IP4] = IP4_MAX_PREFIX_LENGTH,
[NET_IP6] = IP6_MAX_PREFIX_LENGTH,
[NET_VPN4] = IP4_MAX_PREFIX_LENGTH,
[NET_VPN6] = IP6_MAX_PREFIX_LENGTH,
[NET_ROA4] = IP4_MAX_PREFIX_LENGTH,
[NET_ROA6] = IP6_MAX_PREFIX_LENGTH,
[NET_FLOW4] = IP4_MAX_PREFIX_LENGTH,
[NET_FLOW6] = IP6_MAX_PREFIX_LENGTH,
[NET_IP6_SADR]= IP6_MAX_PREFIX_LENGTH,
[NET_MPLS] = 0,
};
const u16 net_max_text_length[] = {
[NET_IP4] = 18, /* "255.255.255.255/32" */
[NET_IP6] = 43, /* "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128" */
[NET_VPN4] = 40, /* "4294967296:4294967296 255.255.255.255/32" */
[NET_VPN6] = 65, /* "4294967296:4294967296 ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128" */
[NET_ROA4] = 34, /* "255.255.255.255/32-32 AS4294967295" */
[NET_ROA6] = 60, /* "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128-128 AS4294967295" */
[NET_FLOW4] = 0, /* "flow4 { ... }" */
[NET_FLOW6] = 0, /* "flow6 { ... }" */
[NET_IP4] = 18, /* "255.255.255.255/32" */
[NET_IP6] = 43, /* "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128" */
[NET_VPN4] = 40, /* "4294967296:4294967296 255.255.255.255/32" */
[NET_VPN6] = 65, /* "4294967296:4294967296 ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128" */
[NET_ROA4] = 34, /* "255.255.255.255/32-32 AS4294967295" */
[NET_ROA6] = 60, /* "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128-128 AS4294967295" */
[NET_FLOW4] = 0, /* "flow4 { ... }" */
[NET_FLOW6] = 0, /* "flow6 { ... }" */
[NET_IP6_SADR]= 92, /* "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128 from ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128" */
[NET_MPLS] = 7, /* "1048575" */
};
@ -102,6 +106,8 @@ net_format(const net_addr *N, char *buf, int buflen)
return flow4_net_format(buf, buflen, &n->flow4);
case NET_FLOW6:
return flow6_net_format(buf, buflen, &n->flow6);
case NET_IP6_SADR:
return bsnprintf(buf, buflen, "%I6/%d from %I6/%d", n->ip6_sadr.dst_prefix, n->ip6_sadr.dst_pxlen, n->ip6_sadr.src_prefix, n->ip6_sadr.src_pxlen);
case NET_MPLS:
return bsnprintf(buf, buflen, "%u", n->mpls.label);
}
@ -124,6 +130,7 @@ net_pxmask(const net_addr *a)
case NET_VPN6:
case NET_ROA6:
case NET_FLOW6:
case NET_IP6_SADR:
return ipa_from_ip6(ip6_mkmask(net6_pxlen(a)));
case NET_MPLS:
@ -156,6 +163,8 @@ net_compare(const net_addr *a, const net_addr *b)
return net_compare_flow4((const net_addr_flow4 *) a, (const net_addr_flow4 *) b);
case NET_FLOW6:
return net_compare_flow6((const net_addr_flow6 *) a, (const net_addr_flow6 *) b);
case NET_IP6_SADR:
return net_compare_ip6_sadr((const net_addr_ip6_sadr *) a, (const net_addr_ip6_sadr *) b);
case NET_MPLS:
return net_compare_mpls((const net_addr_mpls *) a, (const net_addr_mpls *) b);
}
@ -177,6 +186,7 @@ net_hash(const net_addr *n)
case NET_ROA6: return NET_HASH(n, roa6);
case NET_FLOW4: return NET_HASH(n, flow4);
case NET_FLOW6: return NET_HASH(n, flow6);
case NET_IP6_SADR: return NET_HASH(n, ip6_sadr);
case NET_MPLS: return NET_HASH(n, mpls);
default: bug("invalid type");
}
@ -198,6 +208,7 @@ net_validate(const net_addr *n)
case NET_ROA6: return NET_VALIDATE(n, roa6);
case NET_FLOW4: return NET_VALIDATE(n, flow4);
case NET_FLOW6: return NET_VALIDATE(n, flow6);
case NET_IP6_SADR: return NET_VALIDATE(n, ip6_sadr);
case NET_MPLS: return NET_VALIDATE(n, mpls);
default: return 0;
}
@ -222,6 +233,9 @@ net_normalize(net_addr *N)
case NET_FLOW6:
return net_normalize_ip6(&n->ip6);
case NET_IP6_SADR:
return net_normalize_ip6_sadr(&n->ip6_sadr);
case NET_MPLS:
return;
}
@ -246,6 +260,9 @@ net_classify(const net_addr *N)
case NET_FLOW6:
return ip6_zero(n->ip6.prefix) ? (IADDR_HOST | SCOPE_UNIVERSE) : ip6_classify(&n->ip6.prefix);
case NET_IP6_SADR:
return ip6_zero(n->ip6_sadr.dst_prefix) ? (IADDR_HOST | SCOPE_UNIVERSE) : ip6_classify(&n->ip6_sadr.dst_prefix);
case NET_MPLS:
return IADDR_HOST | SCOPE_UNIVERSE;
}
@ -274,6 +291,11 @@ ipa_in_netX(const ip_addr a, const net_addr *n)
return ip6_zero(ip6_and(ip6_xor(ipa_to_ip6(a), net6_prefix(n)),
ip6_mkmask(net6_pxlen(n))));
case NET_IP6_SADR:
if (ipa_is_ip4(a)) return 0;
return ip6_zero(ip6_and(ip6_xor(ipa_to_ip6(a), net6_prefix(n)),
ip6_mkmask(net6_pxlen(n))));
case NET_MPLS:
default:
return 0;
@ -304,5 +326,6 @@ net_init(void)
CHECK_NET(net_addr_roa6, 28);
CHECK_NET(net_addr_flow4, 8);
CHECK_NET(net_addr_flow6, 20);
CHECK_NET(net_addr_ip6_sadr, 40);
CHECK_NET(net_addr_mpls, 8);
}

100
lib/net.h
View File

@ -21,8 +21,9 @@
#define NET_ROA6 6
#define NET_FLOW4 7
#define NET_FLOW6 8
#define NET_MPLS 9
#define NET_MAX 10
#define NET_IP6_SADR 9
#define NET_MPLS 10
#define NET_MAX 11
#define NB_IP4 (1 << NET_IP4)
#define NB_IP6 (1 << NET_IP6)
@ -32,12 +33,13 @@
#define NB_ROA6 (1 << NET_ROA6)
#define NB_FLOW4 (1 << NET_FLOW4)
#define NB_FLOW6 (1 << NET_FLOW6)
#define NB_IP6_SADR (1 << NET_IP6_SADR)
#define NB_MPLS (1 << NET_MPLS)
#define NB_IP (NB_IP4 | NB_IP6)
#define NB_VPN (NB_VPN4 | NB_VPN6)
#define NB_FLOW (NB_FLOW4 | NB_FLOW6)
#define NB_DEST (NB_IP | NB_VPN | NB_MPLS)
#define NB_DEST (NB_IP | NB_IP6_SADR | NB_VPN | NB_MPLS)
#define NB_ANY 0xffffffff
@ -121,6 +123,15 @@ typedef struct net_addr_mpls {
u32 label;
} net_addr_mpls;
typedef struct net_addr_ip6_sadr {
u8 type;
u8 dst_pxlen;
u16 length;
ip6_addr dst_prefix;
s32 src_pxlen; /* s32 to avoid padding */
ip6_addr src_prefix;
} net_addr_ip6_sadr;
typedef union net_addr_union {
net_addr n;
net_addr_ip4 ip4;
@ -131,6 +142,7 @@ typedef union net_addr_union {
net_addr_roa6 roa6;
net_addr_flow4 flow4;
net_addr_flow6 flow6;
net_addr_ip6_sadr ip6_sadr;
net_addr_mpls mpls;
} net_addr_union;
@ -162,10 +174,13 @@ extern const u16 net_max_text_length[];
((net_addr_roa6) { NET_ROA6, pxlen, sizeof(net_addr_roa6), prefix, max_pxlen, asn })
#define NET_ADDR_FLOW4(prefix,pxlen,dlen) \
((net_addr_flow4) { NET_FLOW4, pxlen, sizeof(net_addr_ip4) + dlen, prefix })
((net_addr_flow4) { NET_FLOW4, pxlen, sizeof(net_addr_flow4) + dlen, prefix })
#define NET_ADDR_FLOW6(prefix,pxlen,dlen) \
((net_addr_flow6) { NET_FLOW6, pxlen, sizeof(net_addr_ip6) + dlen, prefix })
((net_addr_flow6) { NET_FLOW6, pxlen, sizeof(net_addr_flow6) + dlen, prefix })
#define NET_ADDR_IP6_SADR(dst_prefix,dst_pxlen,src_prefix,src_pxlen) \
((net_addr_ip6_sadr) { NET_IP6_SADR, dst_pxlen, sizeof(net_addr_ip6_sadr), dst_prefix, src_pxlen, src_prefix })
#define NET_ADDR_MPLS(label) \
((net_addr_mpls) { NET_MPLS, 20, sizeof(net_addr_mpls), label })
@ -189,6 +204,9 @@ static inline void net_fill_roa4(net_addr *a, ip4_addr prefix, uint pxlen, uint
static inline void net_fill_roa6(net_addr *a, ip6_addr prefix, uint pxlen, uint max_pxlen, u32 asn)
{ *(net_addr_roa6 *)a = NET_ADDR_ROA6(prefix, pxlen, max_pxlen, asn); }
static inline void net_fill_ip6_sadr(net_addr *a, ip6_addr dst_prefix, uint dst_pxlen, ip6_addr src_prefix, uint src_pxlen)
{ *(net_addr_ip6_sadr *)a = NET_ADDR_IP6_SADR(dst_prefix, dst_pxlen, src_prefix, src_pxlen); }
static inline void net_fill_mpls(net_addr *a, u32 label)
{ *(net_addr_mpls *)a = NET_ADDR_MPLS(label); }
@ -222,6 +240,16 @@ static inline void net_fill_flow6(net_addr *a, ip6_addr prefix, uint pxlen, byte
memcpy(f->data, data, dlen);
}
/* Make NET_IP6_SADR from NET_IP6, assuming there is enough space */
static inline void net_make_ip6_sadr(net_addr *a)
{
net_addr_ip6_sadr *n = (void *) a;
n->type = NET_IP6_SADR;
n->length = sizeof(net_addr_ip6_sadr);
n->src_pxlen = 0;
n->src_prefix = IP6_NONE;
}
static inline int net_val_match(u8 type, u32 mask)
{ return !!((1 << type) & mask); }
@ -240,6 +268,8 @@ static inline int net_is_roa(const net_addr *a)
static inline int net_is_flow(const net_addr *a)
{ return (a->type == NET_FLOW4) || (a->type == NET_FLOW6); }
static inline int net_is_sadr(const net_addr *a)
{ return (a->type == NET_IP6_SADR); }
static inline ip4_addr net4_prefix(const net_addr *a)
{ return ((net_addr_ip4 *) a)->prefix; }
@ -261,6 +291,7 @@ static inline ip_addr net_prefix(const net_addr *a)
case NET_VPN6:
case NET_ROA6:
case NET_FLOW6:
case NET_IP6_SADR:
return ipa_from_ip6(net6_prefix(a));
case NET_MPLS:
@ -328,6 +359,9 @@ static inline int net_equal_flow4(const net_addr_flow4 *a, const net_addr_flow4
static inline int net_equal_flow6(const net_addr_flow6 *a, const net_addr_flow6 *b)
{ return net_equal((const net_addr *) a, (const net_addr *) b); }
static inline int net_equal_ip6_sadr(const net_addr_ip6_sadr *a, const net_addr_ip6_sadr *b)
{ return !memcmp(a, b, sizeof(net_addr_ip6_sadr)); }
static inline int net_equal_mpls(const net_addr_mpls *a, const net_addr_mpls *b)
{ return !memcmp(a, b, sizeof(net_addr_mpls)); }
@ -338,6 +372,12 @@ static inline int net_equal_prefix_roa4(const net_addr_roa4 *a, const net_addr_r
static inline int net_equal_prefix_roa6(const net_addr_roa6 *a, const net_addr_roa6 *b)
{ return ip6_equal(a->prefix, b->prefix) && (a->pxlen == b->pxlen); }
static inline int net_equal_dst_ip6_sadr(const net_addr_ip6_sadr *a, const net_addr_ip6_sadr *b)
{ return ip6_equal(a->dst_prefix, b->dst_prefix) && (a->dst_pxlen == b->dst_pxlen); }
static inline int net_equal_src_ip6_sadr(const net_addr_ip6_sadr *a, const net_addr_ip6_sadr *b)
{ return ip6_equal(a->src_prefix, b->src_prefix) && (a->src_pxlen == b->src_pxlen); }
static inline int net_zero_ip4(const net_addr_ip4 *a)
{ return !a->pxlen && ip4_zero(a->prefix); }
@ -358,10 +398,10 @@ static inline int net_zero_roa6(const net_addr_roa6 *a)
{ return !a->pxlen && ip6_zero(a->prefix) && !a->max_pxlen && !a->asn; }
static inline int net_zero_flow4(const net_addr_flow4 *a)
{ return !a->pxlen && ip4_zero(a->prefix) && !a->data; }
{ return !a->pxlen && ip4_zero(a->prefix) && (a->length == sizeof(net_addr_flow4)); }
static inline int net_zero_flow6(const net_addr_flow6 *a)
{ return !a->pxlen && ip6_zero(a->prefix) && !a->data; }
{ return !a->pxlen && ip6_zero(a->prefix) && (a->length == sizeof(net_addr_flow6)); }
static inline int net_zero_mpls(const net_addr_mpls *a)
{ return !a->label; }
@ -391,6 +431,13 @@ static inline int net_compare_flow4(const net_addr_flow4 *a, const net_addr_flow
static inline int net_compare_flow6(const net_addr_flow6 *a, const net_addr_flow6 *b)
{ return ip6_compare(a->prefix, b->prefix) ?: uint_cmp(a->pxlen, b->pxlen) ?: uint_cmp(a->length, b->length) ?: memcmp(a->data, b->data, a->length - sizeof(net_addr_flow6)); }
static inline int net_compare_ip6_sadr(const net_addr_ip6_sadr *a, const net_addr_ip6_sadr *b)
{
return
ip6_compare(a->dst_prefix, b->dst_prefix) ?: uint_cmp(a->dst_pxlen, b->dst_pxlen) ?:
ip6_compare(a->src_prefix, b->src_prefix) ?: uint_cmp(a->src_pxlen, b->src_pxlen);
}
static inline int net_compare_mpls(const net_addr_mpls *a, const net_addr_mpls *b)
{ return uint_cmp(a->label, b->label); }
@ -424,6 +471,9 @@ static inline void net_copy_flow4(net_addr_flow4 *dst, const net_addr_flow4 *src
static inline void net_copy_flow6(net_addr_flow6 *dst, const net_addr_flow6 *src)
{ memcpy(dst, src, src->length); }
static inline void net_copy_ip6_sadr(net_addr_ip6_sadr *dst, const net_addr_ip6_sadr *src)
{ memcpy(dst, src, sizeof(net_addr_ip6_sadr)); }
static inline void net_copy_mpls(net_addr_mpls *dst, const net_addr_mpls *src)
{ memcpy(dst, src, sizeof(net_addr_mpls)); }
@ -456,6 +506,9 @@ static inline u32 net_hash_flow4(const net_addr_flow4 *n)
static inline u32 net_hash_flow6(const net_addr_flow6 *n)
{ return ip6_hash(n->prefix) ^ ((u32) n->pxlen << 26); }
static inline u32 net_hash_ip6_sadr(const net_addr_ip6_sadr *n)
{ return net_hash_ip6((net_addr_ip6 *) n); }
static inline u32 net_hash_mpls(const net_addr_mpls *n)
{ return n->label; }
@ -508,6 +561,9 @@ static inline int net_validate_flow6(const net_addr_flow6 *n)
static inline int net_validate_mpls(const net_addr_mpls *n)
{ return n->label < (1 << 20); }
static inline int net_validate_ip6_sadr(const net_addr_ip6_sadr *n)
{ return net_validate_px6(n->dst_prefix, n->dst_pxlen) && net_validate_px6(n->src_prefix, n->src_pxlen); }
int net_validate(const net_addr *N);
@ -523,6 +579,12 @@ static inline void net_normalize_vpn4(net_addr_vpn4 *n)
static inline void net_normalize_vpn6(net_addr_vpn6 *n)
{ net_normalize_ip6((net_addr_ip6 *) n); }
static inline void net_normalize_ip6_sadr(net_addr_ip6_sadr *n)
{
n->dst_prefix = ip6_and(n->dst_prefix, ip6_mkmask(n->dst_pxlen));
n->src_prefix = ip6_and(n->src_prefix, ip6_mkmask(n->src_pxlen));
}
void net_normalize(net_addr *N);
@ -530,17 +592,29 @@ int net_classify(const net_addr *N);
int net_format(const net_addr *N, char *buf, int buflen);
int rd_format(const u64 rd, char *buf, int buflen);
static inline int ipa_in_net_ip4(ip4_addr a, const net_addr_ip4 *n)
{ return ip4_zero(ip4_and(ip4_xor(a, n->prefix), ip4_mkmask(n->pxlen))); }
static inline int ipa_in_px4(ip4_addr a, ip4_addr prefix, uint pxlen)
{ return ip4_zero(ip4_and(ip4_xor(a, prefix), ip4_mkmask(pxlen))); }
static inline int net_in_net_ip4(const net_addr_ip4 *a, const net_addr_ip4 *b)
{ return (a->pxlen >= b->pxlen) && ipa_in_net_ip4(a->prefix, b); }
static inline int ipa_in_px6(ip6_addr a, ip6_addr prefix, uint pxlen)
{ return ip6_zero(ip6_and(ip6_xor(a, prefix), ip6_mkmask(pxlen))); }
static inline int ipa_in_net_ip4(ip4_addr a, const net_addr_ip4 *n)
{ return ipa_in_px4(a, n->prefix, n->pxlen); }
static inline int ipa_in_net_ip6(ip6_addr a, const net_addr_ip6 *n)
{ return ip6_zero(ip6_and(ip6_xor(a, n->prefix), ip6_mkmask(n->pxlen))); }
{ return ipa_in_px6(a, n->prefix, n->pxlen); }
static inline int net_in_net_ip4(const net_addr_ip4 *a, const net_addr_ip4 *b)
{ return (a->pxlen >= b->pxlen) && ipa_in_px4(a->prefix, b->prefix, b->pxlen); }
static inline int net_in_net_ip6(const net_addr_ip6 *a, const net_addr_ip6 *b)
{ return (a->pxlen >= b->pxlen) && ipa_in_net_ip6(a->prefix, b); }
{ return (a->pxlen >= b->pxlen) && ipa_in_px6(a->prefix, b->prefix, b->pxlen); }
static inline int net_in_net_dst_ip6_sadr(const net_addr_ip6_sadr *a, const net_addr_ip6_sadr *b)
{ return (a->dst_pxlen >= b->dst_pxlen) && ipa_in_px6(a->dst_prefix, b->dst_prefix, b->dst_pxlen); }
static inline int net_in_net_src_ip6_sadr(const net_addr_ip6_sadr *a, const net_addr_ip6_sadr *b)
{ return (a->src_pxlen >= b->src_pxlen) && ipa_in_px6(a->src_prefix, b->src_prefix, b->src_pxlen); }
int ipa_in_netX(const ip_addr A, const net_addr *N);
int net_in_netX(const net_addr *A, const net_addr *N);

View File

@ -34,13 +34,7 @@ static int skip_atoi(const char **s)
#define SPECIAL 32 /* 0x */
#define LARGE 64 /* use 'ABCDEF' instead of 'abcdef' */
#define do_div(n,base) ({ \
int __res; \
__res = ((unsigned long) n) % (unsigned) base; \
n = ((unsigned long) n) / (unsigned) base; \
__res; })
static char * number(char * str, long num, int base, int size, int precision,
static char * number(char * str, u64 num, uint base, int size, int precision,
int type, int remains)
{
char c,sign,tmp[66];
@ -58,7 +52,7 @@ static char * number(char * str, long num, int base, int size, int precision,
c = (type & ZEROPAD) ? '0' : ' ';
sign = 0;
if (type & SIGN) {
if (num < 0) {
if (num > (u64) INT64_MAX) {
sign = '-';
num = -num;
size--;
@ -79,8 +73,11 @@ static char * number(char * str, long num, int base, int size, int precision,
i = 0;
if (num == 0)
tmp[i++]='0';
else while (num != 0)
tmp[i++] = digits[do_div(num,base)];
else while (num != 0) {
uint res = num % base;
num = num / base;
tmp[i++] = digits[res];
}
if (i > precision)
precision = i;
size -= precision;
@ -128,16 +125,17 @@ static char * number(char * str, long num, int base, int size, int precision,
* value printed as eight :-separated octets), |%t| for time values (btime) with
* specified subsecond precision, and |%m| resp. |%M| for error messages (uses
* strerror() to translate @errno code to message text). On the other hand, it
* doesn't support floating point numbers.
* doesn't support floating point numbers. The bvsnprintf() supports |%h| and
* |%l| qualifiers, but |%l| is used for s64/u64 instead of long/ulong.
*
* Result: number of characters of the output string or -1 if
* the buffer space was insufficient.
*/
int bvsnprintf(char *buf, int size, const char *fmt, va_list args)
{
int len;
unsigned long num;
int i, base;
int len, i;
u64 num;
uint base;
u32 x;
u64 X;
btime t;
@ -152,7 +150,7 @@ int bvsnprintf(char *buf, int size, const char *fmt, va_list args)
int field_width; /* width of output field */
int precision; /* min. # of digits for integers; max
number of chars for from string */
int qualifier; /* 'h', 'l', or 'L' for integer fields */
int qualifier; /* 'h' or 'l' for integer fields */
for (start=str=buf ; *fmt ; ++fmt, size-=(str-start), start=str) {
if (*fmt != '%') {
@ -270,21 +268,31 @@ int bvsnprintf(char *buf, int size, const char *fmt, va_list args)
*str++ = ' ';
continue;
case 'V': {
const char *vfmt = va_arg(args, const char *);
va_list *vargs = va_arg(args, va_list *);
int res = bvsnprintf(str, size, vfmt, *vargs);
if (res < 0)
return -1;
str += res;
size -= res;
continue;
}
case 'p':
if (field_width == -1) {
field_width = 2*sizeof(void *);
flags |= ZEROPAD;
}
str = number(str,
(unsigned long) va_arg(args, void *), 16,
field_width, precision, flags, size);
str = number(str, (uintptr_t) va_arg(args, void *), 16,
field_width, precision, flags, size);
if (!str)
return -1;
continue;
case 'n':
if (qualifier == 'l') {
long * ip = va_arg(args, long *);
s64 * ip = va_arg(args, s64 *);
*ip = (str - buf);
} else {
int * ip = va_arg(args, int *);
@ -345,14 +353,14 @@ int bvsnprintf(char *buf, int size, const char *fmt, va_list args)
if (qualifier == 'l') {
X = va_arg(args, u64);
bsprintf(ipbuf, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
((X >> 56) & 0xff),
((X >> 48) & 0xff),
((X >> 40) & 0xff),
((X >> 32) & 0xff),
((X >> 24) & 0xff),
((X >> 16) & 0xff),
((X >> 8) & 0xff),
(X & 0xff));
(uint) ((X >> 56) & 0xff),
(uint) ((X >> 48) & 0xff),
(uint) ((X >> 40) & 0xff),
(uint) ((X >> 32) & 0xff),
(uint) ((X >> 24) & 0xff),
(uint) ((X >> 16) & 0xff),
(uint) ((X >> 8) & 0xff),
(uint) (X & 0xff));
}
else
{
@ -382,7 +390,7 @@ int bvsnprintf(char *buf, int size, const char *fmt, va_list args)
/* Print seconds */
flags |= SIGN;
str = number(str, t1, 10, field_width, 0, flags, size);
str = number(str, (u64) t1, 10, field_width, 0, flags, size);
if (!str)
return -1;
@ -400,7 +408,7 @@ int bvsnprintf(char *buf, int size, const char *fmt, va_list args)
/* Print sub-seconds */
*str++ = '.';
str = number(str, t2, 10, precision, 0, ZEROPAD, size - 1);
str = number(str, (u64) t2, 10, precision, 0, ZEROPAD, size - 1);
if (!str)
return -1;
}
@ -413,6 +421,7 @@ int bvsnprintf(char *buf, int size, const char *fmt, va_list args)
case 'X':
flags |= LARGE;
/* fallthrough */
case 'x':
base = 16;
break;
@ -434,16 +443,22 @@ int bvsnprintf(char *buf, int size, const char *fmt, va_list args)
--fmt;
continue;
}
if (qualifier == 'l')
num = va_arg(args, unsigned long);
else if (qualifier == 'h') {
num = (unsigned short) va_arg(args, int);
if (flags & SIGN)
num = (short) num;
} else if (flags & SIGN)
num = va_arg(args, int);
else
num = va_arg(args, uint);
if (flags & SIGN) {
/* Conversions valid per ISO C99 6.3.1.3 (2) */
if (qualifier == 'l')
num = (u64) va_arg(args, s64);
else if (qualifier == 'h')
num = (u64) (short) va_arg(args, int);
else
num = (u64) va_arg(args, int);
} else {
if (qualifier == 'l')
num = va_arg(args, u64);
else if (qualifier == 'h')
num = (unsigned short) va_arg(args, int);
else
num = va_arg(args, uint);
}
str = number(str, num, base, field_width, precision, flags, size);
if (!str)
return -1;

View File

@ -45,7 +45,7 @@ t_simple(void)
else
BSPRINTF(16, "00000fee1a15600d", buf, "%p", (void *) 0xfee1a15600d);
long ln = 0;
s64 ln = 0;
BSPRINTF(10, "TeStStRiNg", buf, "TeStS%lntRiNg", &ln);
bt_assert_msg(ln == 5, "fmt=\"TeStS%%lntRiNg\", &ln makes ln=%ld, want 5", ln);
@ -54,7 +54,40 @@ t_simple(void)
BSPRINTF(2, "+1", buf, "%+d", 1);
BSPRINTF(2, " 1", buf, "% d", 1);
BSPRINTF(2, "-1", buf, "%d", -1);
BSPRINTF(11, "-2147483648", buf, "%d", -2147483648);
BSPRINTF(11, "-2147483648", buf, "%d", INT32_MIN);
BSPRINTF(10, "2147483647", buf, "%d", INT32_MAX);
BSPRINTF(1, "0", buf, "%u", 0x0);
BSPRINTF(10, "4294967295", buf, "%u", 0xFFFFFFFF);
BSPRINTF(4, "-100", buf, "%ld", (s64) -100);
BSPRINTF(3, "100", buf, "%ld", (s64) 100);
BSPRINTF(20, "-9223372036854775808", buf, "%ld", INT64_MIN);
BSPRINTF(19, "9223372036854775807", buf, "%ld", INT64_MAX);
BSPRINTF(3, "0 8", buf, "%lu %lu", U64(0), U64(8));
BSPRINTF(20, "18446744073709551615", buf, "%lu", UINT64_MAX);
return 1;
}
static int
t_router_id(void)
{
char buf[256];
BSPRINTF(7, "1.2.3.4", buf, "%R", (u32) 0x01020304);
BSPRINTF(15, "240.224.208.192", buf, "%R", (u32) 0xF0E0D0C0);
BSPRINTF(23, "01:02:03:04:05:06:07:08", buf, "%lR", (u64) 0x0102030405060708);
BSPRINTF(23, "f0:e0:d0:c0:b0:a0:90:80", buf, "%lR", (u64) 0xF0E0D0C0B0A09080);
return 1;
}
static int
t_time(void)
{
char buf[256];
BSPRINTF(7, "123.456", buf, "%t", (btime) 123456789);
BSPRINTF(7, "123.456", buf, "%2t", (btime) 123456789);
@ -68,12 +101,28 @@ t_simple(void)
return 1;
}
static int
t_bstrcmp(void)
{
bt_assert(bstrcmp("aa", "aa") == 0);
bt_assert(bstrcmp("aa", "bb") == -1);
bt_assert(bstrcmp("bb", "aa") == 1);
bt_assert(bstrcmp(NULL, NULL) == 0);
bt_assert(bstrcmp(NULL, "bb") == -1);
bt_assert(bstrcmp("bb", NULL) == 1);
return 1;
}
int
main(int argc, char *argv[])
{
bt_init(argc, argv);
bt_test_suite(t_simple, "printf without varargs");
bt_test_suite(t_router_id, "print router id");
bt_test_suite(t_time, "print time");
bt_test_suite(t_bstrcmp, "bstrcmp");
return bt_exit_value();
}

View File

@ -340,6 +340,7 @@ mb_alloc(pool *p, unsigned size)
struct mblock *b = xmalloc(sizeof(struct mblock) + size);
b->r.class = &mb_class;
b->r.n = (node) {};
add_tail(&p->inside, &b->r.n);
b->size = size;
return b->data;
@ -387,7 +388,7 @@ mb_realloc(void *m, unsigned size)
struct mblock *b = SKIP_BACK(struct mblock, data, m);
b = xrealloc(b, sizeof(struct mblock) + size);
replace_node(&b->r.n, &b->r.n);
update_node(&b->r.n);
b->size = size;
return b->data;
}

View File

@ -59,11 +59,18 @@ void mb_free(void *);
typedef struct linpool linpool;
typedef struct lp_state {
void *current, *large;
byte *ptr;
} lp_state;
linpool *lp_new(pool *, unsigned blk);
void *lp_alloc(linpool *, unsigned size); /* Aligned */
void *lp_allocu(linpool *, unsigned size); /* Unaligned */
void *lp_allocz(linpool *, unsigned size); /* With clear */
void lp_flush(linpool *); /* Free everything, but leave linpool */
void lp_save(linpool *m, lp_state *p); /* Save state */
void lp_restore(linpool *m, lp_state *p); /* Restore state */
extern const int lp_chunk_size;
#define LP_GAS 1024
@ -76,6 +83,7 @@ typedef struct slab slab;
slab *sl_new(pool *, unsigned size);
void *sl_alloc(slab *);
void *sl_allocz(slab *);
void sl_free(slab *, void *);
/*
@ -94,9 +102,13 @@ void buffer_realloc(void **buf, unsigned *size, unsigned need, unsigned item_siz
*/
#define DMALLOC_DISABLE
#include <dmalloc.h>
#define xmalloc(size) _xmalloc_leap(__FILE__, __LINE__, size)
#define xrealloc(size) _xrealloc_leap(__FILE__, __LINE__, size)
#define xfree(ptr) _xfree_leap(__FILE__, __LINE__, ptr)
#define xmalloc(size) \
dmalloc_malloc(__FILE__, __LINE__, (size), DMALLOC_FUNC_MALLOC, 0, 1)
#define xrealloc(ptr, size) \
dmalloc_realloc(__FILE__, __LINE__, (ptr), (size), DMALLOC_FUNC_REALLOC, 1)
#define xfree(ptr) \
dmalloc_free(__FILE__, __LINE__, (ptr), DMALLOC_FUNC_FREE)
#else
/*
* Unfortunately, several libraries we might want to link to define

View File

@ -88,6 +88,14 @@ sl_alloc(slab *s)
return o->data;
}
void *
sl_allocz(slab *s)
{
void *obj = sl_alloc(s);
memset(obj, 0, s->size);
return obj;
}
void
sl_free(slab *s, void *oo)
{
@ -216,8 +224,11 @@ sl_new_head(slab *s)
struct sl_obj *no;
uint n = s->objs_per_slab;
h->first_free = o;
h->num_full = 0;
*h = (struct sl_head) {
.first_free = o,
.num_full = 0,
};
while (n--)
{
o->slab = h;
@ -275,6 +286,22 @@ no_partial:
goto okay;
}
/**
* sl_allocz - allocate an object from Slab and zero it
* @s: slab
*
* sl_allocz() allocates space for a single object from the
* Slab and returns a pointer to the object after zeroing out
* the object memory.
*/
void *
sl_allocz(slab *s)
{
void *obj = sl_alloc(s);
memset(obj, 0, s->data_size);
return obj;
}
/**
* sl_free - return a free object back to a Slab
* @s: slab

View File

@ -76,7 +76,7 @@ typedef struct birdsock {
int rcv_ttl; /* TTL of last received datagram */
node n;
void *rbuf_alloc, *tbuf_alloc;
char *password; /* Password for MD5 authentication */
const char *password; /* Password for MD5 authentication */
const char *err; /* Error message */
struct ssh_sock *ssh; /* Used in SK_SSH */
} sock;
@ -97,7 +97,7 @@ void sk_dump_all(void);
int sk_is_ipv4(sock *s); /* True if socket is IPv4 */
int sk_is_ipv6(sock *s); /* True if socket is IPv6 */
static inline int sk_send_buffer_empty(sock *sk)
static inline int sk_tx_buffer_empty(sock *sk)
{ return sk->tbuf == sk->tpos; }
int sk_setup_multicast(sock *s); /* Prepare UDP or IP socket for multicasting */
@ -106,7 +106,7 @@ int sk_leave_group(sock *s, ip_addr maddr); /* Leave multicast group on sk iface
int sk_setup_broadcast(sock *s);
int sk_set_ttl(sock *s, int ttl); /* Set transmit TTL for given socket */
int sk_set_min_ttl(sock *s, int ttl); /* Set minimal accepted TTL for given socket */
int sk_set_md5_auth(sock *s, ip_addr local, ip_addr remote, struct iface *ifa, char *passwd, int setkey);
int sk_set_md5_auth(sock *s, ip_addr local, ip_addr remote, int pxlen, struct iface *ifa, const char *passwd, int setkey);
int sk_set_ipv6_checksum(sock *s, int offset);
int sk_set_icmp6_filter(sock *s, int p1, int p2);
void sk_log_error(sock *s, const char *p);

View File

@ -24,6 +24,9 @@ int buffer_vprint(buffer *buf, const char *fmt, va_list args);
int buffer_print(buffer *buf, const char *fmt, ...);
void buffer_puts(buffer *buf, const char *str);
u64 bstrtoul10(const char *str, char **end);
u64 bstrtoul16(const char *str, char **end);
int patmatch(const byte *pat, const byte *str);
static inline char *xbasename(const char *str)
@ -60,6 +63,24 @@ memset32(void *D, u32 val, uint n)
dst[i] = val;
}
static inline int
bstrcmp(const char *s1, const char *s2)
{
if (s1 && s2)
return strcmp(s1, s2);
else
return !s2 - !s1;
}
static inline void *
bmemcpy(void *dest, const void *src, size_t n)
{
if (n)
return memcpy(dest, src, n);
else
return dest;
}
#define ROUTER_ID_64_LENGTH 23
#endif

61
lib/strtoul.c Normal file
View File

@ -0,0 +1,61 @@
/*
* BIRD Library -- Parse numbers
*
* (c) 2019 Maria Matejka <mq@jmq.cz>
*
* Can be freely distributed and used under the terms of the GNU GPL.
*/
#include "nest/bird.h"
#include "lib/string.h"
#include <errno.h>
#define ULI_MAX_DIV10 (UINT64_MAX / 10)
#define ULI_MAX_MOD10 (UINT64_MAX % 10)
u64
bstrtoul10(const char *str, char **end)
{
u64 out = 0;
for (*end = (char *) str; (**end >= '0') && (**end <= '9'); (*end)++) {
u64 digit = **end - '0';
if ((out > ULI_MAX_DIV10) ||
(out == ULI_MAX_DIV10) && (digit > ULI_MAX_MOD10)) {
errno = ERANGE;
return UINT64_MAX;
}
out *= 10;
out += (**end) - '0';
}
return out;
}
u64
bstrtoul16(const char *str, char **end)
{
u64 out = 0;
for (int i=0; i<=(64/4); i++) {
switch (str[i]) {
case '0' ... '9':
out *= 16;
out += str[i] - '0';
break;
case 'a' ... 'f':
out *= 16;
out += str[i] + 10 - 'a';
break;
case 'A' ... 'F':
out *= 16;
out += str[i] + 10 - 'A';
break;
default:
*end = (char *) &(str[i]);
return out;
}
}
errno = ERANGE;
return UINT64_MAX;
}

View File

@ -28,6 +28,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "nest/bird.h"
@ -252,9 +253,9 @@ timer_init(void)
* type &btime.
*/
btime
tm_parse_time(char *x)
tm_parse_time(const char *x)
{
struct tm tm;
struct tm tm = {};
int usec, n1, n2, n3, r;
r = sscanf(x, "%d-%d-%d%n %d:%d:%d%n.%d%n",
@ -304,7 +305,8 @@ tm_format_time(char *x, struct timeformat *fmt, btime t)
btime rt = current_real_time() - dt;
int v1 = !fmt->limit || (dt < fmt->limit);
tm_format_real_time(x, v1 ? fmt->fmt1 : fmt->fmt2, rt);
if (!tm_format_real_time(x, TM_DATETIME_BUFFER_SIZE, v1 ? fmt->fmt1 : fmt->fmt2, rt))
strcpy(x, "<error>");
}
/* Replace %f in format string with usec scaled to requested precision */
@ -352,8 +354,8 @@ strfusec(char *buf, int size, const char *fmt, uint usec)
return str - buf;
}
void
tm_format_real_time(char *x, const char *fmt, btime t)
int
tm_format_real_time(char *x, size_t max, const char *fmt, btime t)
{
s64 t1 = t TO_S;
s64 t2 = t - t1 S;
@ -361,17 +363,14 @@ tm_format_real_time(char *x, const char *fmt, btime t)
time_t ts = t1;
struct tm tm;
if (!localtime_r(&ts, &tm))
goto err;
return 0;
byte tbuf[TM_DATETIME_BUFFER_SIZE];
if (!strfusec(tbuf, TM_DATETIME_BUFFER_SIZE, fmt, t2))
goto err;
if (!strfusec(tbuf, max, fmt, t2))
return 0;
if (!strftime(x, TM_DATETIME_BUFFER_SIZE, tbuf, &tm))
goto err;
if (!strftime(x, max, tbuf, &tm))
return 0;
return;
err:
strcpy(x, "<error>");
return 1;
}

View File

@ -106,7 +106,7 @@ void timer_init(void);
struct timeformat {
char *fmt1, *fmt2;
const char *fmt1, *fmt2;
btime limit;
};
@ -120,8 +120,8 @@ struct timeformat {
#define TM_DATETIME_BUFFER_SIZE 32 /* Buffer size required by tm_format_time() */
btime tm_parse_time(char *x);
btime tm_parse_time(const char *x);
void tm_format_time(char *x, struct timeformat *fmt, btime t);
void tm_format_real_time(char *x, const char *fmt, btime t);
int tm_format_real_time(char *x, size_t max, const char *fmt, btime t);
#endif

View File

@ -20,6 +20,12 @@
#include "sysdep/unix/endian.h"
#include "lib/string.h"
static inline u8
get_u8(const void *p)
{
return * (u8 *) p;
}
static inline u16
get_u16(const void *p)
{
@ -52,6 +58,12 @@ get_u64(const void *p)
return (((u64) ntohl(xh)) << 32) | ntohl(xl);
}
static inline void
put_u8(void *p, u8 x)
{
memcpy(p, &x, 1);
}
static inline void
put_u16(void *p, u16 x)
{

View File

@ -1,6 +1,6 @@
Summary: BIRD Internet Routing Daemon
Name: bird
Version: 2.0.0
Version: 2.0.8
Release: 1
Copyright: GPL
Group: Networking/Daemons

View File

@ -0,0 +1,11 @@
FROM centos:8
RUN yum -y upgrade
RUN yum -y install \
autoconf \
flex \
bison \
pkgconfig \
'readline-devel' \
'pkgconfig(ncurses)' \
gcc \
make

View File

@ -0,0 +1,12 @@
FROM debian:buster-slim
ENV DEBIAN_FRONTEND noninteractive
RUN sed -i 's/deb.debian.org/ftp.cz.debian.org/' /etc/apt/sources.list
RUN apt-get -y update
RUN apt-get -y upgrade
RUN apt-get -y install \
autoconf \
build-essential \
flex \
bison \
ncurses-dev \
libreadline-dev

View File

@ -0,0 +1,12 @@
FROM i386/debian:stretch-slim
ENV DEBIAN_FRONTEND noninteractive
RUN sed -i 's/deb.debian.org/ftp.cz.debian.org/' /etc/apt/sources.list
RUN apt-get -y update
RUN apt-get -y upgrade
RUN apt-get -y install \
autoconf \
build-essential \
flex \
bison \
ncurses-dev \
libreadline-dev

View File

@ -1,7 +1,8 @@
FROM debian:wheezy-slim
ENV DEBIAN_FRONTEND noninteractive
RUN sed -i 's/deb.debian.org/ftp.cz.debian.org/' /etc/apt/sources.list
RUN apt-get -y update
RUN echo 'deb http://archive.debian.org/debian/ wheezy main' > /etc/apt/sources.list
RUN echo 'deb http://archive.debian.org/debian-security/ wheezy/updates main' >> /etc/apt/sources.list
RUN apt-get -y update -o Acquire::Check-Valid-Until=false
RUN apt-get -y upgrade
RUN apt-get -y install \
autoconf \

View File

@ -1,7 +1,8 @@
FROM i386/debian:wheezy-slim
ENV DEBIAN_FRONTEND noninteractive
RUN sed -i 's/deb.debian.org/ftp.cz.debian.org/' /etc/apt/sources.list
RUN apt-get -y update
RUN echo 'deb http://archive.debian.org/debian/ wheezy main' > /etc/apt/sources.list
RUN echo 'deb http://archive.debian.org/debian-security/ wheezy/updates main' >> /etc/apt/sources.list
RUN apt-get -y update -o Acquire::Check-Valid-Until=false
RUN apt-get -y upgrade
RUN apt-get -y install \
autoconf \

View File

@ -1,6 +1,7 @@
FROM fedora:25
RUN dnf -y upgrade
RUN dnf -y install \
make \
autoconf \
flex \
bison \

View File

@ -1,6 +1,7 @@
FROM fedora:26
RUN dnf -y upgrade
RUN dnf -y install \
make \
autoconf \
flex \
bison \

View File

@ -0,0 +1,11 @@
FROM fedora:27
RUN dnf -y upgrade
RUN dnf -y install \
make \
autoconf \
flex \
bison \
pkgconfig \
'readline-devel' \
'pkgconfig(ncurses)' \
gcc

View File

@ -0,0 +1,11 @@
FROM fedora:28
RUN dnf -y upgrade
RUN dnf -y install \
make \
autoconf \
flex \
bison \
pkgconfig \
'readline-devel' \
'pkgconfig(ncurses)' \
gcc

View File

@ -0,0 +1,11 @@
FROM fedora:29
RUN dnf -y upgrade
RUN dnf -y install \
make \
autoconf \
flex \
bison \
pkgconfig \
'readline-devel' \
'pkgconfig(ncurses)' \
gcc

View File

@ -0,0 +1,11 @@
FROM fedora:30
RUN dnf -y upgrade
RUN dnf -y install \
make \
autoconf \
flex \
bison \
pkgconfig \
'readline-devel' \
'pkgconfig(ncurses)' \
gcc

View File

@ -0,0 +1,11 @@
FROM fedora:31
RUN dnf -y upgrade
RUN dnf -y install \
make \
autoconf \
flex \
bison \
pkgconfig \
'readline-devel' \
'pkgconfig(ncurses)' \
gcc

View File

@ -1,4 +1,4 @@
FROM opensuse:42.3
FROM opensuse/leap:15.0
RUN zypper -n up
RUN zypper -n install \
autoconf \

View File

@ -0,0 +1,11 @@
FROM opensuse/leap:15.1
RUN zypper -n up
RUN zypper -n install \
autoconf \
flex \
bison \
pkgconfig \
readline-devel \
ncurses-devel \
gcc \
gmake

View File

@ -0,0 +1,12 @@
FROM ubuntu:18.04
ENV DEBIAN_FRONTEND noninteractive
RUN sed -i 's/deb.debian.org/ftp.cz.debian.org/' /etc/apt/sources.list
RUN apt-get -y update
RUN apt-get -y upgrade
RUN apt-get -y install \
autoconf \
build-essential \
flex \
bison \
ncurses-dev \
libreadline-dev

Some files were not shown because too many files have changed in this diff Show More