summaryrefslogtreecommitdiffstats
path: root/bgpd/bgp_packet.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* bgpd: Modify End of Rib notification to INFODonald Sharp2019-01-071-5/+5
| | | | | | | | 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>
* *: spelchekDavid Lamparter2018-10-251-1/+1
| | | | Signed-off-by: David Lamparter <equinox@diac24.net>
* *: style for EC replacementsQuentin Young2018-09-131-16/+16
| | | | Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
* *: LIB_[ERR|WARN] -> EC_LIBQuentin Young2018-09-131-1/+1
| | | | Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
* bgpd: BGP_[WARN|ERR] -> EC_BGPQuentin Young2018-09-131-23/+23
| | | | Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
* *: style for flog_warn conversionsQuentin Young2018-09-061-9/+12
| | | | Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
* bgpd: Convert zlog_warn to flog_warn for bgp_packet.cDonald Sharp2018-09-061-11/+9
| | | | Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
* *: rename ferr_zlog -> flog_err_sysQuentin Young2018-08-141-3/+3
| | | | Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
* *: rename zlog_fer -> flog_errQuentin Young2018-08-141-21/+21
| | | | Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
* bgpd: Convert to using LIB_ERR_XXX where possibleDonald Sharp2018-08-141-1/+2
| | | | Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
* bgpd: implement zlog_ferr facility for enhance error messages in bgpDon Slice2018-08-141-33/+53
| | | | Signed-off-by: Don Slice <dslice@cumulusnetworks.com<
* bgpd: Implement group-overrides for peer timersPascal Mathis2018-06-141-3/+3
| | | | | | | | | | | | | | | | | | | 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>
* bgpd: remove unused variableQuentin Young2018-04-131-2/+1
| | | | Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
* bgpd: double-check notify data when debuggingQuentin Young2018-04-131-2/+2
| | | | | | | | 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>
* bgpd: add flowspec featurejaydom2018-03-301-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | 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>
* *: use C99 standard fixed-width integer typesQuentin Young2018-03-271-40/+40
| | | | | | | | | | | | | | | | | | | | | | 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>
* bgpd: peer->bgp must be non NULLDonald Sharp2018-03-211-1/+1
| | | | | | | | 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>
* *: conform with COMMUNITY.md formatting rules, via 'make indent'Lou Berger2018-03-061-3/+2
| | | | Signed-off-by: Lou Berger <lberger@labn.net>
* bgpd: fix race condition causing occasional assertQuentin Young2018-01-241-21/+31
| | | | | | | | | | | 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>
* bgpd: use atomic_* ops on _Atomic variablesQuentin Young2018-01-091-7/+14
| | | | Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
* bgpd: fix potential deadlockQuentin Young2017-12-011-3/+5
| | | | | | | 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>
* bgpd: small optimization with UPDATE generationQuentin Young2017-11-301-8/+13
| | | | | | | 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>
* bgpd: use FOREACH_AFI_SAFI()Quentin Young2017-11-301-98/+85
| | | | Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
* bgpd: intelligently adjust coalesce timerQuentin Young2017-11-301-14/+0
| | | | | | | | | | | | 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>
* bgpd: turn off keepalives when sending NOTIFYQuentin Young2017-11-301-0/+9
| | | | | | | | 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>
* bgpd: yield more when generating UPDATEsQuentin Young2017-11-301-1/+6
| | | | | | | 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.
* bgpd: restore packet input limitQuentin Young2017-11-301-0/+14
| | | | | | | | | | | | | | | | | | | | 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>
* bgpd: schedule process packet as timerQuentin Young2017-11-301-2/+3
| | | | | | | 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.
* bgpd: re-add write trigger logicQuentin Young2017-11-301-0/+55
| | | | | | | | 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.
* bgpd, tests: comment formattingQuentin Young2017-11-301-55/+68
| | | | Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
* bgpd: fix uninitialized result codeQuentin Young2017-11-301-0/+10
| | | | Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
* bgpd: lift read-quanta restrictionQuentin Young2017-11-301-16/+0
| | | | | | | 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>
* bgpd: free notify packet after writingQuentin Young2017-11-301-0/+3
| | | | Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
* bgpd: fix bgp_packet.c / bgp_fsm.c organizationQuentin Young2017-11-301-245/+374
| | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* bgpd: atomize write-quanta, add read-quantaQuentin Young2017-11-301-5/+28
| | | | | | | | | | | | | | 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>
* bgpd: batched i/oQuentin Young2017-11-301-69/+82
| | | | | | | | | | | | | | | | | | | 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>
* bgpd: implement buffered readsQuentin Young2017-11-301-222/+128
| | | | | | | | | | | | | | | | * 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>
* bgpd: move bgp i/o to a separate source fileQuentin Young2017-11-301-371/+82
| | | | | | | | | | | | | | | | 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>
* bgpd: use new threading infraQuentin Young2017-11-301-0/+10
| | | | Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
* bgpd: stop pseudo-blocking in bgp_writeQuentin Young2017-11-301-3/+2
| | | | | | | 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>
* bgpd: dynamically allocate synchronization primitivesQuentin Young2017-11-301-22/+47
| | | | | | | | | | | | | | 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>
* bgpd: remove unused `struct thread` from peerQuentin Young2017-11-301-0/+4
| | | | | | | | | | | * 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>
* lib, bgpd: implement pthread lifecycle managementQuentin Young2017-11-301-0/+3
| | | | | | | | | | | 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>
* bgpd: move bgp_connect_check() to bgp_fsm.cQuentin Young2017-11-301-54/+6
| | | | | | | | | | | | | | | | | | | | 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>
* bgpd: move update group processing to main threadQuentin Young2017-11-301-29/+70
| | | | | | | | | | | 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>
* bgpd: move packet writes into dedicated pthreadQuentin Young2017-11-301-262/+319
| | | | | | | | | | * 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>
* bgpd: use FOREACH_AFI_SAFI where possibleQuentin Young2017-11-211-99/+88
| | | | | | Improves consistency and readability. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
* Merge pull request #1406 from donaldsharp/bgpd_ecommunity_crashRenato Westphal2017-11-061-1/+1
|\ | | | | bgpd: Fix crash with ecommunity string
| * bgpd: Prevent infinite loop when reading capabilitiesDonald Sharp2017-11-061-1/+1
| | | | | | | | | | | | | | | | | | | | 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>
* | Merge pull request #1370 from dslicenc/cm18408-bgp-timersRenato Westphal2017-11-061-3/+4
|\ \ | |/ |/| bgpd: fix various problems with hold/keepalive timers