Commit Graph

267 Commits

Author SHA1 Message Date
David Lamparter
6fd04594bb bgpd: add packet send hook
Unlike MRT dumps, BMP also provides packets sent by the router.  Add
another hook for that.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2019-07-03 16:59:12 +02:00
David Lamparter
584470fb5f bgpd: add & use bgp packet dump hook
The MRT dump code is already hooked in at the right places to write out
packets;  the BMP code needs exactly the same access so let's make this
a hook.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2019-07-03 16:58:26 +02:00
David Lamparter
b4d46cc9b1 bgpd: count some per-peer stats (for BMP)
These counters are accessible through BMP and may be useful to monitor
bgpd.  A CLI to show them could also be added if people are interested.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2019-07-03 16:53:12 +02:00
David Lamparter
1a1f453436 bgpd: fix last_reset_cause setup
last_reset_cause_size is the length *used* in last_reset_cause[].  It's
straight up used wrong here; we're saving off a reset cause and need to
check against the *available* size in last_reset_cause[].

This could actually have led to (hopefully rare) crashes in the assert
there, since the assert condition might fail incorrectly.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2019-07-03 16:50:36 +02:00
Donald Sharp
7ec5e2bf70
Merge pull request #4514 from opensourcerouting/warnings-20190612
*: kill more warnings
2019-06-17 15:19:42 -04:00
David Lamparter
6dcef54cbf bgpd: fix uninitialized & wrong endian NOTIFY
notify_data_remote_as4 would contain garbage if optlen == 0, and also
as4 is in host byte order while the notify needs network byte order.

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-06-13 20:43:13 +02:00
Donald Sharp
748a041f09 bgpd, lib: Add iana_afi2str and iana_safi2str for eye pleasing strings
Modify the code such that we can auto turn the iana values of afi
and safi to pleasant to read strings.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-06-02 14:51:52 -04:00
Quentin Young
5041dc4fbf bgpd: suppress dead store warning
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-05-29 18:03:26 +00:00
Quentin Young
552d6491f0 bgpd: remove strcpy, strcat
Replace with strlcpy, strlcat

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-05-29 18:02:57 +00:00
Quentin Young
db878db01a bgpd: fix false compiler warning
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-05-29 18:02:57 +00:00
nikos
9738e9aa36 bgpd: IPv6 session flapping with MP_REACH_NLRI and 0.0.0.0 in NEXT_HOP attribute
This is causing interop issues with vendors. According to the RFC,
receiver should ignore the NEXT_HOP attribute with MP_REACH_NLRI
present.

Signed-off-by: nikos <ntriantafillis@gmail.com>
2019-05-10 12:52:17 -07:00
Donatas Abraitis
513386b57f bgpd: Do not send UPDATE message with maximum-prefix
When using maximum-prefix and count is overflow BGP
sends UPDATE message:

Apr 15 20:45:06 exit1-debian-9 bgpd[9818]: 192.168.0.2 [Error] Error parsing NLRI
Apr 15 20:45:06 exit1-debian-9 bgpd[9818]: %NOTIFICATION: sent to neighbor 192.168.0.2 3/10 (UPDATE Message Error/Invalid Network Field) 0 bytes

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2019-04-24 14:51:06 +03:00
Donald Sharp
e82d19a3d4 bgpd: Modify End of Rib notification to INFO
The End of Rib notification in BGP is useful to know no matter
the circumstances.  So change this from a debug message to
an info and cleanup the message a bit and add vrf we are in.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-01-07 17:51:27 +01:00
David Lamparter
0437e10517 *: spelchek
Signed-off-by: David Lamparter <equinox@diac24.net>
2018-10-25 20:10:57 +02:00
Quentin Young
1c50c1c0d6 *: style for EC replacements
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2018-09-13 19:38:57 +00:00
Quentin Young
450971aa99 *: LIB_[ERR|WARN] -> EC_LIB
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2018-09-13 19:34:28 +00:00
Quentin Young
e50f7cfdbd bgpd: BGP_[WARN|ERR] -> EC_BGP
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2018-09-13 18:51:04 +00:00
Quentin Young
ade6974def *: style for flog_warn conversions
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2018-09-06 20:56:41 +00:00
Donald Sharp
63d430ceee bgpd: Convert zlog_warn to flog_warn for bgp_packet.c
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2018-09-06 20:50:58 +00:00
Quentin Young
09c866e34d *: rename ferr_zlog -> flog_err_sys
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2018-08-14 20:02:05 +00:00
Quentin Young
af4c27286d *: rename zlog_fer -> flog_err
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2018-08-14 20:02:05 +00:00
Donald Sharp
02705213b1 bgpd: Convert to using LIB_ERR_XXX where possible
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2018-08-14 20:02:05 +00:00
Don Slice
14454c9fdd bgpd: implement zlog_ferr facility for enhance error messages in bgp
Signed-off-by: Don Slice <dslice@cumulusnetworks.com<
2018-08-14 20:02:05 +00:00
Pascal Mathis
b90a8e13ee
bgpd: Implement group-overrides for peer timers
This commit implements BGP peer-group overrides for the timer flags,
which control the value of the hold, keepalive, advertisement-interval
and connect connect timers. It was kept separated on purpose as the
whole timer implementation is quite complex and merging this commit
together with with the other flag implementations did not seem right.

Basically three new peer flags were introduced, namely
*PEER_FLAG_ROUTEADV*, *PEER_FLAG_TIMER* and *PEER_FLAG_TIMER_CONNECT*.
The overrides work exactly the same way as they did before, but
introducing these flags made a few conditionals simpler as they no
longer had to compare internal data structures against eachother.

Last but not least, the test suite has been adjusted accordingly to test
the newly implemented flag overrides.

Signed-off-by: Pascal Mathis <mail@pascalmathis.com>
2018-06-14 18:55:30 +02:00
Quentin Young
bd6b2706b3 bgpd: remove unused variable
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2018-04-13 17:17:42 -04:00
Quentin Young
e0981960cd bgpd: double-check notify data when debugging
clang-analyze complains that data may be null, and since we didn't
explicitly check it (although we did check the overall packet length
minus the header length) it has a point.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2018-04-13 17:17:42 -04:00
jaydom
7c40bf391c bgpd: add flowspec feature
This work is derived from a work done by China-Telecom.
That initial work can be found in [0].
As the gap between frr and quagga is important, a reworks has been
done in the meantime.
The initial work consists of bringing the following:
- Bringing the client side of flowspec.
- the enhancement of address-family ipv4/ipv6 flowspec
- partial data path handling at reception has been prepared
- the support for ipv4 flowspec or ipv6 flowspec in BGP open messages,
  and the internals of BGP has been done.
- the memory contexts necessary for flowspec has been provisioned

In addition to this work, the following has been done:
- the complement of adaptation for FS safi in bgp code
- the code checkstyle has been reworked so as to match frr checkstyle
- the processing of IPv6 FS NLRI is prevented
- the processing of FS NLRI is stopped ( temporary)

[0] https://github.com/chinatelecom-sdn-group/quagga_flowspec/

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
Signed-off-by: jaydom <chinatelecom-sdn-group@github.com>
2018-03-30 14:00:47 +02:00
Quentin Young
d7c0a89a3a
*: use C99 standard fixed-width integer types
The following types are nonstandard:
- u_char
- u_short
- u_int
- u_long
- u_int8_t
- u_int16_t
- u_int32_t

Replace them with the C99 standard types:
- uint8_t
- unsigned short
- unsigned int
- unsigned long
- uint8_t
- uint16_t
- uint32_t

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2018-03-27 15:13:34 -04:00
Donald Sharp
5410015a79 bgpd: peer->bgp must be non NULL
We lock and set peer->bgp at peer creation and only
remove it at deletion.  Therefore these tests are
not needed.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2018-03-20 19:09:06 -04:00
Lou Berger
996c93142d *: conform with COMMUNITY.md formatting rules, via 'make indent'
Signed-off-by: Lou Berger <lberger@labn.net>
2018-03-06 14:04:32 -05:00
Quentin Young
a127f33b97
bgpd: fix race condition causing occasional assert
If a BGP message header fails validation we send a BGP NOTIFICATION from
the I/O thread. At this time we clear the output buffer, push a
NOTIFICATION and then call the manual write function for errors. But in
between the push and the write the main thread could have pushed some
other message. Thus we need to hold the lock for the duration of the
function. TOCTTOU.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2018-01-23 18:51:34 -05:00
Quentin Young
0112e9e0b9
bgpd: use atomic_* ops on _Atomic variables
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2018-01-09 15:40:48 -05:00
Quentin Young
8ec586b01b
bgpd: fix potential deadlock
With the way things are set up, this bit of code would never actually
cause a deadlock, but would be highly likely in the future.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-12-01 13:41:27 -05:00
Quentin Young
6ec98a2f37
bgpd: small optimization with UPDATE generation
After a batch of generated UPDATEs, call bgp_writes_on() once instead of
after generating each packet.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-11-30 17:17:16 -05:00
Quentin Young
c58b0f46dd
bgpd: use FOREACH_AFI_SAFI()
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-11-30 16:58:37 -05:00
Quentin Young
4961a5a2eb
bgpd: intelligently adjust coalesce timer
The subgroup coalesce timer controls how long updates to a particular
subgroup are delayed in order to allow additional peers to join the
subgroup. Presently the timer value is 200 ms. Increase it to 1 second
and adjust up as peers are configured, with an upper cap at 10s.

This cuts convergence time by a factor of 3 at large scale (300+ peers,
1000+ prefixes per peer).

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-11-30 16:47:51 -05:00
Quentin Young
934af4587f
bgpd: turn off keepalives when sending NOTIFY
This is necessary because otherwise between the time we wipe the output
buffer and the time we push the NOTIFY onto it, the KA generation thread
could have pushed a KEEPALIVE in the middle.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-11-30 16:18:07 -05:00
Quentin Young
d0ad6d8e5f
bgpd: yield more when generating UPDATEs
In the same vein as the round-robin input commit, this re-adds logic for
limiting the amount of time spent generating UPDATEs per generation
cycle. Missed this when shifting around wpkt_quanta; prior to MT it
limited both calls to write() as well as UPDATE generation.
2017-11-30 16:18:07 -05:00
Quentin Young
9773a576bd
bgpd: restore packet input limit
Unfortunately, batching input processing severely impacts BGP initial
convergence times. As a consequence of the way update-groups were
implemented, advancing the state of the routing table based on prefixes
learned from one peer prior to all (or at least most) peers establishing
connections will cause us to start generating outbound UPDATEs, which is
a very expensive operation at present. This intensive processing starves
out bgp_accept(), delaying connection of additional peers. When
additional peers do connect the problem gets worse and worse, yielding
approximately exponential growth in convergence time dependent on both
peering and prefix counts. This behavior is present pre-multithreading
as well, but batched input exacerbates it.

Round-robin input processing marginally harms convergence times for
small topologies but should allow much larger topologies to function
within reasonable performance thresholds.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-11-30 16:18:06 -05:00
Quentin Young
4af766600a
bgpd: schedule process packet as timer
Different places scheduling the same thread should use the same
semantics and thread type. Additionally providing the back reference
here makes sure we only schedule the job once and avoids flooding the
event queue with jobs to process an empty buffer.
2017-11-30 16:18:06 -05:00
Quentin Young
af1e1dc69e
bgpd: re-add write trigger logic
Apparently I didn't fully understand how subgroup packets make their way
out to individual peers. Turns out (on the base branch) we just busy
poll while waiting for packets to make their way onto subgroup queues.
While this needs to be fixed in the future, for now readding this logic
fixes performance issues with convergence.
2017-11-30 16:18:06 -05:00
Quentin Young
becedef6c3
bgpd, tests: comment formatting
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-11-30 16:18:05 -05:00
Quentin Young
e3c7270d49
bgpd: fix uninitialized result code
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-11-30 16:18:04 -05:00
Quentin Young
3b73658c7c
bgpd: lift read-quanta restriction
Per previous work to ensure all FSM state is updated after processing
each message, read-quanta should be safe to set > 1.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-11-30 16:18:03 -05:00
Quentin Young
3735936bda
bgpd: free notify packet after writing
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-11-30 16:18:02 -05:00
Quentin Young
d815168795
bgpd: fix bgp_packet.c / bgp_fsm.c organization
Despaghettification of bgp_packet.c and bgp_fsm.c

Sometimes we call bgp_event_update() inline packet parsing.
Sometimes we post events instead.
Sometimes we increment packet counters in the FSM.
Sometimes we do it in packet routines.
Sometimes we update EOR's in FSM.
Sometimes we do it in packet routines.

Fix the madness.

bgp_process_packet() is now the centralized place to:
- Update message counters
- Execute FSM events in response to incoming packets

FSM events are now executed directly from this function instead of being
queued on the thread_master. This is to ensure that the FSM contains the
proper state after each packet is parsed. Otherwise there could be race
conditions where two packets are parsed in succession without the
appropriate FSM update in between, leading to session closure due to
receiving inappropriate messages for the current FSM state.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-11-30 16:18:02 -05:00
Quentin Young
555e09d4a2
bgpd: atomize write-quanta, add read-quanta
bgpd supports setting a write-quanta that serves as a hint on how many
packets to write per I/O cycle. Now that input is buffered, it makes
sense to add the equivalent parameter for how many packets are processed
per cycle. This is *not* how many packets are read off the wire per I/O
cycle; rather it is how many packets are processed from the input buffer
in a given cycle after having been read off the wire and sanitized.

Since these values must be used from multiple threads, they have also
been made atomic.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-11-30 16:18:00 -05:00
Quentin Young
9eb217ff69
bgpd: batched i/o
Instead of reading a packet header and the rest of the packet in two
separate i/o cycles, instead read a chunk of data at one time and then
parse as many packets as possible out of the chunk.

Also changes bgp_packet.c to batch process packets.

To avoid thrashing on useless mutex locks, the scheduling call for
bgp_process_packet has been changed to always succeed at the cost of no
longer being cancel-able. In this case this is acceptable; following the
pattern of other event-based callbacks, an additional check in
bgp_process_packet to ignore stray events is sufficient. Before deleting
the peer all events are cleared which provides the requisite ordering.

XXX: chunk hardcoded to 5, should use something similar to wpkt_quanta

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-11-30 16:18:00 -05:00
Quentin Young
424ab01d0f
bgpd: implement buffered reads
* Move and modify all network input related code to bgp_io.c
* Add a real input buffer to `struct peer`
* Move connection initialization to its own thread.c task instead of
  piggybacking off of bgp_read()
* Tons of little fixups

Primary changes are in bgp_packet.[ch], bgp_io.[ch], bgp_fsm.[ch].
Changes made elsewhere are almost exclusively refactoring peer->ibuf to
peer->curr since peer->ibuf is now the true FIFO packet input buffer
while peer->curr represents the packet currently being processed by the
main pthread.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-11-30 16:17:59 -05:00
Quentin Young
56257a44e4
bgpd: move bgp i/o to a separate source file
After implement threading, bgp_packet.c was serving the double purpose
of consolidating packet parsing functionality and handling actual I/O
operations. This is somewhat messy and difficult to understand. I've
thus moved all code and data structures for handling threaded packet
writes to bgp_io.[ch].

Although bgp_io.[ch] only handles writes at the moment to keep the noise
on this commit series down, for organization purposes, it's probably
best to move bgp_read() and its trappings into here as well and
restructure that code so that read()'s happen in the pthread and packet
processing happens on the main thread.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-11-30 16:17:59 -05:00
Quentin Young
0ca8b79f38
bgpd: use new threading infra
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-11-30 16:17:59 -05:00
Quentin Young
2bb745fe02
bgpd: stop pseudo-blocking in bgp_write
If write() indicates that we should retry, just move along to the next
peer and come back later. No need to burn write() in a loop.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-11-30 16:17:58 -05:00
Quentin Young
419dfe6a70
bgpd: dynamically allocate synchronization primitives
Changes all synchronization primitives to be dynamically allocated. This
should help catch any subtle errors in pthread lifecycles.

This change also pre-initializes synchronization primitives before
threads begin to run, eliminating a potential race condition that
probably would have caused a segfault on startup on a very fast box.

Also changes mutex and condition variable allocations to use
MTYPE_PTHREAD and updates tests to do the proper initializations.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-11-30 16:17:58 -05:00
Quentin Young
49507a6f6a
bgpd: remove unused struct thread from peer
* Remove t_write
* Remove t_keepalive

These have been replaced by pthreads and are no longer needed. Since
some code looks at these values to determine if the threads are
scheduled, also add a new bitfield to store the same information.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-11-30 16:17:58 -05:00
Quentin Young
2d4ee77490
lib, bgpd: implement pthread lifecycle management
Removes the WiP shim and implements proper thread lifecycle management.

* Declare necessary pthread_t's in bgp_master
* Define new MTYPE in lib/thread.c for pthreads
* Allocate and free BGP's pthreads appropriately
* Terminate and join threads appropriately

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-11-30 16:17:57 -05:00
Quentin Young
07a1652682
bgpd: move bgp_connect_check() to bgp_fsm.c
Prior to this change, after initiating a nonblocking connection to the
remote peer bgpd would call both BGP_READ_ON and BGP_WRITE_ON on the
peer's socket. This resulted in a call to select(), so that when some
event (either a connection success or failure) occurred on the socket,
one of bgp_read() or bgp_write() would run. At the beginning of each of
those functions was a hook into bgp_connect_check(), which checked the
socket status and issued the correct connection event onto the BGP FSM.

This code is better suited for bgp_fsm.c. Placing it there avoids
scheduling packet reads or writes when we don't know if the socket has
established a connection yet, and the specific functionality is a better
fit for the responsibility scope of this unit.

This change also helps isolate the responsibilities of the
packet-writing kernel thread.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-11-30 16:17:57 -05:00
Quentin Young
80bd61c416
bgpd: move update group processing to main thread
Prior to this change, packets generated for update groups were taken off
of the (independent) buffer for the update group, reformatted for the
specific peer under question and sent off inline with bgp_write(). Since
the operations of this code path can include the merging and pruning of
subgroups and are too large to safely synchronize, this change moves
that logic to execute after each tick of the write thread.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-11-30 16:17:57 -05:00
Quentin Young
d3ecc69e5f
bgpd: move packet writes into dedicated pthread
* BGP_WRITE_ON() removed
* BGP_WRITE_OFF() removed
* peer_writes_on() added
* peer_writes_off() added
* bgp_write_proceed_actions() removed

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-11-30 16:17:57 -05:00
Quentin Young
05c7a1cc93
bgpd: use FOREACH_AFI_SAFI where possible
Improves consistency and readability.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-11-21 13:02:06 -05:00
Renato Westphal
965a99f58a
Merge pull request #1406 from donaldsharp/bgpd_ecommunity_crash
bgpd: Fix crash with ecommunity string
2017-11-06 15:08:07 -02:00
Renato Westphal
f498ca82bd
Merge pull request #1370 from dslicenc/cm18408-bgp-timers
bgpd: fix various problems with hold/keepalive timers
2017-11-06 14:06:12 -02:00
Donald Sharp
d2b6417bd6 bgpd: Prevent infinite loop when reading capabilities
If the user has configured the ability to override
the capabilities or if the afi/safi passed as part
of the _MP capability is not understood, then we
can enter into an infinite loop as part of the
capability parsing.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2017-11-06 10:38:05 -05:00
Don Slice
d25e4efc52 bgpd: fix various problems with hold/keepalive timers
Problem reported that we weren't adjusting the keepalive timer
correctly when we negotiated a lower hold time learned from a
peer.  While working on this, found we didn't do inheritance
correctly at all.  This fix solves the first problem and also
ensures that the timers are configured correctly based on this
priority order - peer defined > peer-group defined > global config.
This fix also displays the timers as "configured" regardless of
which of the three locations above is used.

Ticket: CM-18408
Signed-off-by: Don Slice <dslice@cumulusnetworks.com>
Reviewed-by: CCR-6807
Testing-performed:  Manual testing successful, fix tested by
submitter, bgp-smoke completed successfully
2017-10-26 11:55:31 -04:00
Donald Sharp
9b9df9892d bgpd: Treat empty reachable NLRI as a EOR
This issue was discovered on a live session with an extremely
old cisco 7206VXR router running 12.2(33)SRE4.  The sending router
is sending us an empty NLRI that is MP_REACH.  From RFC
exploration(thanks Russ!) it appears that this was
considered a 'valid' way to send EOR.

Following discussion decided that we should treat
this situation as a EOR marker instead of bringing
down the session.

Applying this fix on the FRR router seeing this issue
allows it to continue it's peering relationship with
the ASR.  Since this is a point fix I do not see
a high likelihood of further fallout.

Fixes: #1258
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2017-10-26 07:31:17 -04:00
Renato Westphal
5c5255381e lib/bgpd: introduce the iana_safi_t enum
We had afi_t/iana_afi_t for AFIs but only safi_t for SAFIs. Fix this
inconsistency.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2017-07-31 23:44:42 -03:00
David Lamparter
9d303b37d7 Revert "*: reindent pt. 2"
This reverts commit c14777c6bf.

clang 5 is not widely available enough for people to indent with.  This
is particularly problematic when rebasing/adjusting branches.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-07-22 14:52:33 +02:00
Don Slice
e5f22b3036 bgpd: fix peer startup for labeled-unicast if linklocal address not found
Problem found in testing where ipv6 labeled-unicast prefixes were not received
on the peers if a "service networking restart" was issued.  Same problem would
happen with an ifdown/ifup on the link to the peer.  Found the problem to be
that peers would establish for labeled-unicast even if a link-local address was
not yet available on the interface toward the peer, causing updates to be sent
without a nexthop value. These were then rejected by the peer. Fix is to delay
peer establishment until after the link-local addresses are available.

Ticket: CM-16779
Signed-off-by: Don Slice <dslice@cumulusnetworks.com>
Reviewed By: Donald Sharp <sharpd@cumulusnetworks.com>
Testing Done: Manual testing successful.  Bgp-smoke completed with no new failures
2017-07-18 13:09:34 +00:00
whitespace / reindent
c14777c6bf
*: reindent pt. 2
w/ clang 5

* reflow comments
* struct members go 1 per line
* binpack algo was adjusted
2017-07-17 15:26:02 -04:00
whitespace / reindent
d62a17aede *: reindent
indent.py `git ls-files | pcregrep '\.[ch]$' | pcregrep -v '^(ldpd|babeld|nhrpd)/'`

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-07-17 14:04:07 +02:00
Donald Sharp
aadc090505 bgpd: Refactor 'struct attr_extra' into 'struct attr'
Most of the attributes in 'struct attr_extra' allow for
the more interesting cases of using bgp.  The extra
overhead of managing it will induce errors as we add
more attributes and the extra memory overhead is
negligible on anything but full bgp feeds.

Additionally this greatly simplifies the code for
the handling of data.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>

bgpd: Fix missing label set

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2017-07-12 15:23:18 -04:00
David Lamparter
21bb7c8774 Merge commit '3d22338f04d9554fa' into evpn-prep
Conflicts:
	lib/Makefile.am

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-07-10 22:15:19 +02:00
Daniel Walton
4fbf55e986 Merge branch 'master' of https://github.com/dwalton76/frr into bgpd-ipv4-plus-label-misc3 2017-06-26 17:24:44 +00:00
Quentin Young
56b4067930 *: simplify log message lookup
log.c provides functionality for associating a constant (typically a
protocol constant) with a string and finding the string given the
constant. However this is highly delicate code that is extremely prone
to stack overflows and off-by-one's due to requiring the developer to
always remember to update the array size constant and to do so correctly
which, as shown by example, is never a good idea.b

The original goal of this code was to try to implement lookups in O(1)
time without a linear search through the message array. Since this code
is used 99% of the time for debugs, it's worth the 5-6 additional cmp's
worst case if it means we avoid explitable bugs due to oversights...

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-06-21 15:22:21 +00:00
Daniel Walton
9bedbb1e52 bgpd: Install SAFI_LABELED_UNICAST routes in SAFI_UNICAST table
Signed-off-by: Daniel Walton <dwalton@cumulusnetworks.com>

- All ipv4 labeled-unicast routes are now installed in the ipv4 unicast
  table. This allows us to do things like take routes from an ipv4
  unicast peer, allocate a label for them and TX them to a ipv4
  labeled-unicast peer. We can do the opposite where we take routes from
  a labeled-unicast peer, remove the label and advertise them to an ipv4
  unicast peer.

- Multipath over a labeled route and non-labeled route is not allowed.

- You cannot activate a peer for both 'ipv4 unicast' and 'ipv4
  labeled-unicast'

- The 'tag' variable was overloaded for zebra's route tag feature as
  well as the mpls label. I added a 'mpls_label_t mpls' variable to
  avoid this.  This is much cleaner but resulted in touching a lot of
  code.
2017-06-16 19:12:57 +00:00
vivek
3d22338f04 bgpd: Fixes related to use of L2VPN/EVPN
Add checks related to AFI_L2VPN/SAFI_EVPN that were missing in some parts
of the code. Fix incorrect check skipping EVPN when sending End of RIB.

Signed-off-by: Vivek Venkatraman <vivek@cumulusnetworks.com>
2017-05-25 10:20:04 -07:00
Lou Berger
1ec1afd6cb bgpd: remove encap safi vty related files bgp_encap.h|c
Signed-off-by: Lou Berger <lberger@labn.net>
2017-05-23 15:58:50 -04:00
Lou Berger
eedae49501 bgpd: remove encap_safi rx processing
Signed-off-by: Lou Berger <lberger@labn.net>
2017-05-23 15:58:50 -04:00
David Lamparter
57463530f3 Merge branch 'stable/3.0'
Conflicts:
	ospf6d/ospf6_lsa.c
	ospfd/ospf_vty.c
	zebra/interface.c

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-05-18 12:28:12 +02:00
David Lamparter
92eedda1fb Merge branch stable/2.0 into stable/3.0
Conflicts:
	bgpd/bgp_fsm.c
	ospf6d/ospf6_lsa.c
	ospfd/ospf_vty.c
	zebra/redistribute.c

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-05-18 12:23:13 +02:00
Daniel Walton
10a6a98b0a bgpd: does not honor configured keepalive timer
Signed-off-by: Daniel Walton <dwalton@cumulusnetworks.com>
Reviewed-by:   Donald Sharp <sharpd@cumulusnetworks.com>
2017-05-16 23:56:31 +00:00
David Lamparter
896014f4bc *: make consistent & update GPLv2 file headers
The FSF's address changed, and we had a mixture of comment styles for
the GPL file header.  (The style with * at the beginning won out with
580 to 141 in existing files.)

Note: I've intentionally left intact other "variations" of the copyright
header, e.g. whether it says "Zebra", "Quagga", "FRR", or nothing.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-05-15 16:37:41 +02:00
Renato Westphal
9ff63e6f55 bgpd: removed unused parameter from bgp_dump_attr()
Originally we used the 'peer' parameter for this:

  if (peer_sort (peer) == BGP_PEER_IBGP)
    snprintf (buf + strlen (buf), size - strlen (buf), ", localpref %d",
              attr->local_pref);

Now we have this:

  if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF)))
    snprintf (buf + strlen (buf), size - strlen (buf), ", localpref %u",
              attr->local_pref);

Remove the now useless 'peer' parameter.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2017-05-12 11:48:02 -03:00
Donald Sharp
0ce5d20e46 bgpd: When receiving a route set the label to invalid
When we are receiving a route the attr->extra->label_index
is being set to 0.  This should be BGP_INVALID_LABEL_INDEX
instead since we cannot rely on 0 to be correct for labels.

I believe that there are probably other spots that need this
type of fix, but I will let testing snuggle-bump them out.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2017-05-02 22:34:29 -04:00
Don Slice
ea47f948b9 bgpd: correct labeled-unicast withdraw update
Signed-off-by: Don Slice <dslice@cumulusnetworks.com>
Reviewed-by: Donald Sharp <sharpd@cumulusnetworks.com>
2017-04-06 10:32:08 -04:00
Don Slice
cd1964ff38 bgpd: labeled unicast processing
Implement support for negotiating IPv4 or IPv6 labeled-unicast address
family, exchanging prefixes and installing them in the routing table, as
well as interactions with Zebra for FEC registration. This is the
implementation of RFC 3107.

Signed-off-by: Don Slice <dslice@cumulusnetworks.com>
2017-04-06 10:32:07 -04:00
David Lamparter
38de8d0229 bgpd: RX shutdown message in "show bgp neighbor"
Signed-off-by: Christian Franke <chris@opensourcerouting.org>
2017-03-06 19:40:26 -05:00
Philippe Guibert
b18825ebc7 bgpd: evpn NLRI route type 5 forging
This patch introduces the ability to make route type 5 message
when EVPN is enabled. Picked up paramters are collected from the
bgp extra attribute structure and are the ESI, the ethernet tag
information. In addition to this, nexthop attribute is collected too.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2017-02-14 13:58:58 +01:00
Philippe Guibert
7ef5a23288 bgpd: handling EVPN Route Type 5 NLRI message
This patch introduces code to receive a NLRI message with route type
5, as defined in draft-ietf-bess-evpn-prefix-advertisement-02. It
It increases the number of parameters to extract from the NLRI and
to store into bgp extra information structure. Those parameters are
the ESI (ethernet segment identifier), the gateway IP Address (which
acts like nexthop attribute but is contained inside the NLRI itself)
and the ethernet tag identifier ( that acts for the VXLan Identifier)
This patch updates bgp_update() and bgp_withdraw() api, and then does the
necessary adapations for rfapi.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2017-02-14 13:58:57 +01:00
Philippe Guibert
3d6c0dfa87 bgpd: basic support for EVPN
To handle BGP NLRI EVPN messages, bgp is modified to handle AFI_L2VPN
and SAFI_EVPN values.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2017-02-14 13:58:57 +01:00
David Lamparter
dcb817fd27 Merge branch 'frr/pull/92' (BGP Large Community support)
Acked-by: Donald Sharp <sharpd@cumulusnetworks.com>
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-01-25 23:04:29 +01:00
Donald Sharp
ac9ddce37d Merge pull request #104 from opensourcerouting/time-cleanup
Time cleanup
2017-01-24 11:43:32 -05:00
David Lamparter
6ced0e7f10 lib: time: remove recent_relative_time()
Replace with monotime() [which is not cached].

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-01-23 18:26:32 +01:00
Job Snijders
57d187bc77 Support for BGP Large Communities
BGP Large Communities are a novel way to signal information between
networks. An example of a Large Community is: "2914:65400:38016". Large
BGP Communities are composed of three 4-byte integers, separated by a
colon. This is easy to remember and accommodates advanced routing
policies in relation to 4-Byte ASNs.

This feature was developed by:
Keyur Patel <keyur@arrcus.com> (Arrcus, Inc.),
Job Snijders <job@ntt.net> (NTT Communications),
David Lamparter <equinox@opensourcerouting.org>
and Donald Sharp <sharpd@cumulusnetworks.com>

Signed-off-by: Job Snijders <job@ntt.net>
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2017-01-18 18:38:53 -05:00
Donald Sharp
b58ed1f8a8 Merge remote-tracking branch 'origin/master' into pim_lib_work2 2017-01-17 21:01:56 -05:00
vivek
9cabb64b32 Quagga: AFI/SAFI mappings IANA to/from internal values
Introduce internal and IANA defintions for AFI/SAFI and mapping
functions and modify code to use these. This refactoring will
facilitate adding support for other AFI/SAFI whose IANA values
won't be suitable for internal data structure definitions (e.g.,
they are not contiguous).
The commit adds some fixes related to afi/safi testing with 'make check
' command.

Signed-off-by: Vivek Venkatraman <vivek@cumulusnetworks.com>
Reviewed-by:   Donald Sharp <sharpd@cumulusnetworks.com>
Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>

Ticket: CM-11416
Reviewed By: CCR-3594 (mpls branch)
Testing Done: Not tested now, tested earlier on mpls branch
2017-01-12 09:28:43 +01:00
Julien Courtat
440129913d bgpd: support End-Of-Rib of VPNv4 address family
After graceful restart procedure, when BGP speaker has finished to send
its VPNv4 routes to the restarting peer, it also sends End-Of-Rib
message for afi=AFI_IPv4 safi=SAFI_MPLS_VPN.

Signed-off-by: Julien Courtat <julien.courtat@6wind.com>
2017-01-04 18:02:57 +01:00
Paul Jakma
8628876f66 bgpd: Squash spurious "unknown afi" log messages
* bgp_packet.c: (bgp_update_receive) doesn't differentiate between NLRIs that
  are 0 AFI/SAFI cause they weren't set, and those because a peer sent a
  bogus AFI/SAFI, before sending sending what may be a misleading, spurious
  log message.  Check the .nlri pointer is set and avoid this.

Incorporating a suggestion from: G. Paul Ziemba <unp@ziemba.us>
2016-10-26 09:36:09 -04:00
Paul Jakma
ebd12e62a9 bgpd: Remove the double-pass parsing of NLRIs
* bgpd parses NLRIs twice, a first pass "sanity check" and then a second pass
  that changes actual state. For most AFI/SAFIs this is done by
  bgp_nlri_sanity_check and bgp_nlri_parse, which are almost identical.

  As the required action on a syntactic error in an NLRI is to NOTIFY and
  shut down the session, it should be acceptable to just do a one pass
  parse.  There is no need to atomically handle the NLRIs.

* bgp_route.h: (bgp_nlri_sanity_check) Delete
* bgp_route.c: (bgp_nlri_parse) Make the prefixlen size check more general
  and don't hard-code AFI/SAFI details, e.g. use prefix_blen library function.

  Add error logs consistent with bgp_nlri_sanity_check as much as possible.

  Add a "defense in depth" type check of the prefixlen against the sizeof
  the (struct prefix) storage - ala bgp_nlri_parse_vpn.
  Update standards text from draft RFC4271 to the actual RFC4271 text.

  Extend the semantic consistency test of IPv6. E.g. it should skip mcast
  NLRIs for unicast safi as v4 does.

* bgp_mplsvpn.{c,h}: Delete bgp_nlri_sanity_check_vpn and make
  bgp_nlri_parse_vpn_body the bgp_nlri_parse_vpn function again.

  (bgp_nlri_parse_vpn) Remove the notifies.  The sanity checks were
  responsible for this, but bgp_update_receive handles sending NOTIFY
  generically for bgp_nlri_parse.

* bgp_attr.c: (bgp_mp_reach_parse,bgp_mp_unreach_parse) Delete sanity check.
  NLRI parsing done after attr parsing by bgp_update_receive.

Arising out of discussions on the need for two-pass NLRI parse with:

Lou Berger <lberger@labn.net>
Donald Sharp <sharpd@cumulusnetworks.com>
2016-10-26 09:36:09 -04:00
Donald Sharp
18ef625f95 bgpd: Fix non v4 EOR parsing
When we receive a non v4 EOR, we were parsing it but
incorrectly applying the test for the flag for it.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
Reviewed-by: Daniel Walton <dwalton@cumulusnetworks.com>
2016-10-26 09:36:09 -04:00
Paul Jakma
96e52474fd bgpd: Regularise bgp_update_receive, add missing notifies and checks
* bgp_packet.c: (bgp_update_receive) Lots of repeated code, doing same
  thing for each AFI/SAFI.  Except when it doesn't, e.g.  the IPv4/VPN
  case was missing the EoR bgp_clear_stale_route call - the only action
  really needed for EoR.

  Make this function a lot more regular, using common, AFI/SAFI
  independent blocks so far as possible.

  Replace the 4 separate bgp_nlris with an array, indexed by an enum.

  The distinct blocks that handle calling bgp_nlri_parse for each
  different AFI/SAFI can now be replaced with a loop.

  Transmogrify the nlri SAFI from the SAFI_MPLS_LABELED_VPN code-point
  used on the wire, to the SAFI_MPLS_VPN safi_t enum we use internally
  as early as possible.

  The existing code was not necessarily sending a NOTIFY for NLRI
  parsing errors, if they arose via bgp_nlri_sanity_check.  Send the
  correct NOTIFY - INVAL_NETWORK for the classic NLRIs and OPT_ATTR_ERR
  for the MP ones.

  EoR can now be handled in one block.  The existing code seemed broken
  for EoR recognition in a number of ways:

  1.  A v4/unicast EoR should be an empty UPDATE.  However, it seemed
     to be treating an UPDATE with attributes, inc.  MP REACH/UNREACH,
     but no classic NLRIs, as a v4/uni EoR.

  2.  For other AFI/SAFIs, it was treating UPDATEs with no classic
     withraw and with a zero-length MP withdraw as EoRs.  However, that
     would mean an UPDATE packet _with_ update NLRIs and a 0-len MP
     withdraw could be classed as an EoR.

  This seems to be loose coding leading to ambiguous protocol
  situations and likely incorrect behaviour, rather than simply being
  liberal.  Be more strict about checking that an UPDATE really is an
  EoR and definitely is not trying to update any NLRIs.

  This same loose EoR parsing was noted by Chris Hall previously on
  list.

  (bgp_nlri_parse) Front end NLRI parse function, to fan-out to the correct
  parser for the AFI/SAFI.

* bgp_route.c: (bgp_nlri_sanity_check) We try convert NLRI safi to
  internal code-point ASAP, adjust switch for that.  Leave the wire
  code point in for defensive coding.

  (bgp_nlri_parse) rename to bgp_nlri_parse_ip.

* tests/bgp_mp_attr_test.c: Can just use bgp_nlri_parse frontend.
2016-10-26 09:36:08 -04:00