summaryrefslogtreecommitdiffstats
path: root/bgpd/bgp_io.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* *: Change thread->func to return void instead of intDonald Sharp2022-02-241-10/+6
| | | | | | | The int return value is never used. Modify the code base to just return a void instead. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
* bgpd: bgp_packet_process_error can access peer after deletionDonald Sharp2021-08-081-1/+2
| | | | | | | | | | | | | | | in bgp_io.c upon packet read of some error we are storing the peer pointer on a thread to call bgp_packet_process_error. In this case an event is generated that is not guaranteed to be run immediately. It could come in *after* the peer data structure is deleted and as such we now are writing into memory that we no longer possibly own as a peer data structure. Modify the code so that the peer can track the thread associated with the read error and then it can wisely kill that thread when deleting the peer data structure. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
* Merge pull request #8545 from opensourcerouting/assert-our-ownMark Stapp2021-05-031-1/+0
|\ | | | | *: make our own assert() actually work
| * *: drop zassert.hDavid Lamparter2021-04-231-1/+0
| | | | | | | | | | | | It's not actually working properly... Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
* | bgpd: avoid allocating very large stack bufferQuentin Young2021-04-291-4/+4
| | | | | | | | | | | | | | | | | | As pointed out on code review of BGP extended messages, increasing the maximum BGP message size has the consequence of growing the dynamically sized stack buffer up to 650K. While unlikely to exceed modern stack sizes it is still unreasonably large. Remedy this with a heap buffer. Signed-off-by: Quentin Young <qlyoung@nvidia.com>
* | Revert "bgpd: improve socket read performance"Quentin Young2021-04-291-1/+7
|/ | | | This reverts commit 97a16e648115919aab3784a6511807e35c20ee20.
* bgpd: fix uninit value when handling bgp read errsQuentin Young2021-04-161-1/+4
| | | | | | | | | Compiler warns about uninitialized value, although in practice it is unreachable. Also updates a function comment explaining what that value does. Signed-off-by: Quentin Young <qlyoung@nvidia.com>
* bgpd: use add_event instead of add_timer with zero timeoutMark Stapp2021-03-171-2/+2
| | | | | | | Just use events in a few places where timers with zero timeout were being used. Signed-off-by: Mark Stapp <mjs@voltanet.io>
* bgpd: handle socket read errors in the main pthreadMark Stapp2021-03-091-27/+20
| | | | | | | | | Add a handler for socket errors that runs in the main pthread, rather than the io pthread. When the io pthread encounters a read error, capture the error and schedule a task for the main pthread. Signed-off-by: Mark Stapp <mjs@voltanet.io>
* bgpd: improve socket read performanceRafael Zalamena2021-03-051-7/+1
| | | | | | | Use the new ringbuffer API function to read file descriptors directly to the ringbuffer instead of using intermediary buffers. Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
* bgpd: Add BGP Extended message supportDonatas Abraitis2021-03-041-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Implement https://www.rfc-editor.org/rfc/rfc8654.txt ``` > | jq '."192.168.10.25".neighborCapabilities.extendedMessage' "advertisedAndReceived" ``` Another side is Bird: ``` BIRD 2.0.7 ready. Name Proto Table State Since Info v4 BGP --- up 19:39:15.689 Established BGP state: Established Neighbor address: 192.168.10.123 Neighbor AS: 65534 Local AS: 65025 Neighbor ID: 192.168.100.1 Local capabilities Multiprotocol AF announced: ipv4 Route refresh Extended message Graceful restart 4-octet AS numbers Enhanced refresh Long-lived graceful restart Neighbor capabilities Multiprotocol AF announced: ipv4 Route refresh Extended message Graceful restart 4-octet AS numbers ADD-PATH RX: ipv4 TX: Enhanced refresh Session: external AS4 Source address: 192.168.10.25 Hold timer: 140.139/180 Keepalive timer: 9.484/60 Channel ipv4 State: UP Table: master4 Preference: 100 Input filter: ACCEPT Output filter: ACCEPT Routes: 9 imported, 3 exported, 8 preferred Route change stats: received rejected filtered ignored accepted Import updates: 9 0 0 0 9 Import withdraws: 2 0 --- 2 0 Export updates: 11 8 0 --- 3 Export withdraws: 0 --- --- --- 0 BGP Next hop: 192.168.10.25 ``` Tested at least as well with to make sure it works with backward compat.: ExaBGP 4.0.2-1c737d99. Arista vEOS 4.21.14M Testing by injecint 10k routes with: ``` sharp install routes 172.16.0.1 nexthop 192.168.10.123 10000 ``` Before extended message support: ``` 2021/03/01 07:18:51 BGP: u1:s1 send UPDATE len 4096 (max message len: 4096) numpfx 809 2021/03/01 07:18:51 BGP: u1:s1 send UPDATE len 4096 (max message len: 4096) numpfx 809 2021/03/01 07:18:51 BGP: u1:s1 send UPDATE len 4096 (max message len: 4096) numpfx 809 2021/03/01 07:18:51 BGP: u1:s1 send UPDATE len 4096 (max message len: 4096) numpfx 809 2021/03/01 07:18:51 BGP: u1:s1 send UPDATE len 4096 (max message len: 4096) numpfx 809 2021/03/01 07:18:51 BGP: u1:s1 send UPDATE len 4096 (max message len: 4096) numpfx 809 2021/03/01 07:18:52 BGP: u1:s1 send UPDATE len 4096 (max message len: 4096) numpfx 809 2021/03/01 07:18:52 BGP: u1:s1 send UPDATE len 4096 (max message len: 4096) numpfx 809 2021/03/01 07:18:52 BGP: u1:s1 send UPDATE len 4096 (max message len: 4096) numpfx 809 2021/03/01 07:18:52 BGP: u1:s1 send UPDATE len 4096 (max message len: 4096) numpfx 809 2021/03/01 07:18:52 BGP: u1:s1 send UPDATE len 4096 (max message len: 4096) numpfx 809 2021/03/01 07:18:52 BGP: u1:s1 send UPDATE len 2186 (max message len: 4096) numpfx 427 2021/03/01 07:18:53 BGP: u1:s1 send UPDATE len 3421 (max message len: 4096) numpfx 674 ``` After extended message support: ``` 2021/03/01 07:20:11 BGP: u1:s1 send UPDATE len 50051 (max message len: 65535) numpfx 10000 ``` Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
* bgpd: Advertise FIB installed routes to bgp peers (Part 3)Soman K S2020-11-061-2/+7
| | | | | | | | | | | | | | | | | * Process FIB update in bgp_zebra_route_notify_owner() and call group_announce_route() if route is installed * When bgp update is received for a route which is not installed earlier (flag BGP_NODE_FIB_INSTALLED is not set) and suppress fib is enabled set the flag BGP_NODE_FIB_INSTALL_PENDING to indicate fib install is pending for the route. The route will be advertised when zebra send ZAPI_ROUTE_INSTALLED status. * The advertisement delay (BGP_DEFAULT_UPDATE_ADVERTISEMENT_TIME) is added to allow more routes to be sent in single update message. This is required since zebra sends route notify message for each route. The delay will be applied to update group timer which advertises routes to peers. Signed-off-by: kssoman <somanks@gmail.com>
* Merge pull request #7194 from qlyoung/tracingMark Stapp2020-10-241-0/+2
|\ | | | | Tracing
| * bgpd: move packet read tracepoint out of mutexQuentin Young2020-10-231-1/+1
| | | | | | | | Signed-off-by: Quentin Young <qlyoung@nvidia.com>
| * lib, bgpd: convert lttng tracepoints to frrtrace()Quentin Young2020-10-231-2/+2
| | | | | | | | | | | | | | | | | | | | | | - tracepoint() -> frrtrace() - tracelog() -> frrtracelog() - tracepoint_enabled() -> frrtrace_enabled() Also removes copypasta'd #ifdefs for those LTTng macros, those are handled in lib/trace.h Signed-off-by: Quentin Young <qlyoung@nvidia.com>
| * bgpd: add basic packet-related tracepointsQuentin Young2020-10-231-0/+2
| | | | | | | | | | | | | | | | Add tracepoints for: - packet pushed to internal rx queue - packet dequeued from rx queue and processed Signed-off-by: Quentin Young <qlyoung@nvidia.com>
* | *: unify thread/event cancel macrosMark Stapp2020-10-231-1/+1
|/ | | | | | | | | Replace all lib/thread cancel macros, use thread_cancel() everywhere. Only the THREAD_OFF macro and thread_cancel() api are supported. Also adjust thread_cancel_async() to NULL caller's pointer (if present). Signed-off-by: Mark Stapp <mjs@voltanet.io>
* bgpd: Avoid extra copy of received data to bufferSoman K S2020-05-301-3/+3
| | | | | | | | When received packet is processed in bgp_process_reads(), the data is copied to static buffer and then copied to stream buffer. The data can be copied directly to stream buffer which will avoid extra memcpy Signed-off-by: kssoman <somanks@gmail.com>
* bgpd, lib: fix style from BGP GR codeQuentin Young2020-02-041-13/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch fixes the noncompliant style for the following commit range: 4a6e80fbf 2ba1fe695 efcb2ebbb 8c48b3b69 dc95985fe 0f0444fbd 85ef4179a eb451ee58 2d3dd828d 9e3b51a7f d6e3c15b6 34aa74486 6102cb7fe d7b3cda6f 2bb5d39b1 5f9c1aa29 5cce3f054 3a75afa4b f009ff269 cfd47646b 2986cac29 055679e91 034e185dc 794b37d52 b0965c44e 949b0f24f 63696f1d8 Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
* bgpd: BGP tcp session failed to apply GR configuration on the transferredbisdhdh2020-01-231-3/+13
| | | | | | | | | | | | | | | | | | | | bgp tcp connection. When the BGP peer is configured between two bgp routes both routers would create peer structure , when they receive each other’s open message. In this event both speakers, open duplicate TCP sessions and send OPEN messages on each socket simultaneously, the BGP Identifier is used to resolve which socket should be closed. If BGP GR is enabled the old tcp session is dumped and the new session is retained. So while this transfer of connection is happening, if all the bgp gr config is not migrated to the new connection, the new bgp gr mode will never get applied. Fix Summary: 1. Replicate GR configuration from the old session to the new session in bgp_accept(). 2. Replicate GR configuration from stub to full-fledged peer in bgp_establish(). 3. Disable all NSF flags, clear stale routes (if present), stop restart & stale timers (if they are running) when the bgp GR mode is changed to “Disabled”. 4. Disable R-bit in cap, if it is not set the received open message. Signed-off-by: Biswajit Sadhu <sadhub@vmware.com>
* *: generously apply constDavid Lamparter2019-12-021-1/+1
| | | | | | const const const your boat, merrily down the stream... Signed-off-by: David Lamparter <equinox@diac24.net>
* bgpd: speak soothing words to scanbuildQuentin Young2019-10-151-0/+2
| | | | Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
* bgpd: vector I/OQuentin Young2019-10-141-21/+80
| | | | Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
* bgpd: move assert out of error caseQuentin Young2019-10-141-2/+2
| | | | | | | | | | bgp_process_packets has an assert to make sure an appropriate amount of working space in the input buffer has been freed up for future reads. However, this assert shouldn't be made when we have encountered an error that's going to tear down the session, because in this case we may not be able to process the full contents of the input buffer. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
* lib: add frr_with_mutex() block-wrapperDavid Lamparter2019-09-031-9/+3
| | | | | | | | | frr_with_mutex(...) { ... } locks and automatically unlocks the listed mutex(es) when the block is exited. This adds a bit of safety against forgetting the unlock in error paths & co. and makes the code a slight bit more readable. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
* lib,bgpd: remove deprecated stream lib macrosMark Stapp2018-11-291-1/+1
| | | | | | | A couple of deprecated lib/stream macros have aged out; remove them, and replace the one remaining use. Signed-off-by: Mark Stapp <mjs@voltanet.io>
* lib: remove frr_pthread->idDavid Lamparter2018-09-191-7/+7
| | | | | | | All I can see is an unneccessary complication. If there's some purpose here it needs to be documented... Signed-off-by: David Lamparter <equinox@diac24.net>
* *: style for EC replacementsQuentin Young2018-09-131-2/+2
| | | | Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
* bgpd: BGP_[WARN|ERR] -> EC_BGPQuentin Young2018-09-131-1/+1
| | | | Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
* *: rename zlog_fer -> flog_errQuentin Young2018-08-141-1/+1
| | | | Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
* bgpd: implement zlog_ferr facility for enhance error messages in bgpDon Slice2018-08-141-2/+4
| | | | Signed-off-by: Don Slice <dslice@cumulusnetworks.com<
* bgpd isisd ldpd lib ospfd pimd: redundancy (infer)paco2018-06-201-5/+2
| | | | Signed-off-by: F. Aragon <paco@voltanet.io>
* bgpd: block io thread reads once shutdown has startedLou Berger2018-05-101-1/+1
| | | | Signed-off-by: Lou Berger <lberger@labn.net>
* *: use C99 standard fixed-width integer typesQuentin Young2018-03-271-1/+1
| | | | | | | | | | | | | | | | | | | | | | 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>
* *: conform with COMMUNITY.md formatting rules, via 'make indent'Lou Berger2018-03-061-8/+8
| | | | Signed-off-by: Lou Berger <lberger@labn.net>
* bgpd: update pthreads to use lib changesQuentin Young2018-01-241-113/+25
| | | | | | | | | | | | Use the new threading facilities provided in lib/ to streamline the threads used in bgpd. In particular, all of the lifecycle code has been removed from the I/O thread and replaced with the default loop. Did not do the same to the keepalives thread as it is much smaller (doesn't need the event system). Also cleaned up some comments to match the style guide. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
* bgpd: update last_update whenever obuf sentLou Berger2018-01-221-8/+8
| | | | | | (to be consistent with last_write updates) Signed-off-by: Lou Berger <lberger@labn.net>
* Merge pull request #1614 from qlyoung/imp-bgpd-pthread-startup-syncLou Berger2018-01-161-19/+52
|\ | | | | improve bgpd thread startup characteristics
| * bgpd: move startup sync lock aroundQuentin Young2018-01-101-2/+5
| | | | | | | | | | | | | | | | Condition needs to be set inside critical section, otherwise i/o thread can deadlock. Also unlock mutex once finished with it, no need to hold the lock for the life of the program. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
| * bgpd: improve bgp thread startup characteristicsQuentin Young2018-01-091-19/+49
| | | | | | | | | | | | Replace atomic spinlock with condition variable. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
* | Merge pull request #1591 from qlyoung/bgpd-ringbufRuss White2018-01-111-51/+39
|\ \ | |/ |/| bgpd: use ring buffer for network input
| * bgpd: use ring buffer for network inputQuentin Young2018-01-031-51/+39
| | | | | | | | | | | | | | | | | | The multithreading code has a comment that reads: "XXX: Heavy abuse of stream API. This needs a ring buffer." This patch makes the relevant code use a ring buffer. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
* | bgpd: Ensure that io thread is running after startDonald Sharp2018-01-061-16/+6
|/ | | | | | | | | The BGP IO thread must be running before other threads can start using it. So at startup check to see that it running once, instead of before every function call into. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
* bgpd: schedule UPDATE generation smarterQuentin Young2017-11-301-6/+3
| | | | | No need to schedule a job to generate more packets until we're done with the ones we've got. Shaves a few percent off convergence time.
* bgpd: properly set peer->last_updateQuentin Young2017-11-301-3/+8
| | | | | | | | | Instead of checking whether the post-write number of updates sent was greater than the pre-write number of updates sent, it was comparing post to zero. In effect this meant every time we wrote a packet it was counted as an update for route advertisement timer purposes. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
* bgpd: schedule packet job after connection xferQuentin Young2017-11-301-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | During initial session establishment, bgpd performs a "connection transfer" to a new peer struct if the connection was initiated passively (i.e. by the remote peer). With the addition of buffered input and a reorganized packet processor, the following race condition manifests: 1. Remote peer initiates a connection. After exchanging OPEN messages, we send them a KEEPALIVE. They send us a KEEPALIVE followed by 10,000 UPDATE messages. The I/O thread pushes these onto our local peer's input buffer and schedules a packet processing job on the main thread. 2. The packet job runs and processes the KEEPALIVE, which completes the handshake on our end. As part of transferring to ESTABLISHED we transfer all peer state to a new struct, as mentioned. Upon returning from the KEEPALIVE processing routing, the peer context we had has now been destroyed. We notice this and stop processing. Meanwhile 10k UPDATE messages are sitting on the input buffer. 3. N seconds later, the remote peer sends us a KEEPALIVE. The I/O thread schedules another process job, which finds 10k UPDATEs waiting for it. Convergence is achieved, but has been delayed by the value of the KEEPALIVE timer. The racey part is that if the remote peer takes a little bit of time to send UPDATEs after KEEPALIVEs -- somewhere on the order of a few hundred milliseconds -- we complete the transfer successfully and the packet processing job is scheduled on the new peer upon arrival of the UPDATE messages. Yuck. The solution is to schedule a packet processing job on the new peer struct after transferring state. Lengthy commit message in case someone has to debug similar problems in the future... Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
* bgpd: transfer raw input buffer to new peerQuentin Young2017-11-301-1/+0
| | | | | | | | | | | During initial session establishment, bgpd performs a "connection transfer" to a new peer struct if the connection was initiated passively (i.e. by the remote peer). With the addition of buffered input, I forgot to transfer the raw input buffer to the new peer. This resulted in infrequent failures during session handshaking whereby half of a packet would be thrown away in the middle of a read causing us to send a NOTIFY for an unsynchronized header. Usually the transfer coincided with a clean input buffer, hence why it only showed up once in a while.
* bgpd: fix bgp active openQuentin Young2017-11-301-2/+4
| | | | | | | | | At some point when rearranging FSM code, bgpd lost the ability to perform active opens because it was only paying attention to POLLIN and not POLLOUT, when the latter is used to signify a successful connection in the active case. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
* bgpd: use correct byte order for notify dataQuentin Young2017-11-301-8/+9
| | | | | | Broke this when rewriting header validation. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
* bgpd, tests: comment formattingQuentin Young2017-11-301-7/+4
| | | | Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>