diff options
author | Quentin Young <qlyoung@cumulusnetworks.com> | 2017-05-02 02:37:45 +0200 |
---|---|---|
committer | Quentin Young <qlyoung@cumulusnetworks.com> | 2017-11-30 22:17:59 +0100 |
commit | 424ab01d0f69a71b865e5f2d817baea7ce263e44 (patch) | |
tree | 82f06cf1dae116f6db05cd5409475a6f8b6dcf1e /bgpd/bgp_io.h | |
parent | bgpd: move bgp i/o to a separate source file (diff) | |
download | frr-424ab01d0f69a71b865e5f2d817baea7ce263e44.tar.xz frr-424ab01d0f69a71b865e5f2d817baea7ce263e44.zip |
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>
Diffstat (limited to 'bgpd/bgp_io.h')
-rw-r--r-- | bgpd/bgp_io.h | 77 |
1 files changed, 50 insertions, 27 deletions
diff --git a/bgpd/bgp_io.h b/bgpd/bgp_io.h index 7b81b8ee3..fd5f7659d 100644 --- a/bgpd/bgp_io.h +++ b/bgpd/bgp_io.h @@ -23,13 +23,13 @@ #ifndef _FRR_BGP_IO_H #define _FRR_BGP_IO_H +#include "frr_pthread.h" #include "bgpd/bgpd.h" /** * Control variable for write thread. * - * Setting this variable to false and calling peer_writes_wake() will - * eventually result in thread termination. + * Setting this variable to false will eventually result in thread termination. */ extern bool bgp_packet_writes_thread_run; @@ -37,35 +37,32 @@ extern bool bgp_packet_writes_thread_run; * Initializes data structures and flags for the write thread. * * This function should be called from the main thread before - * peer_writes_start() is invoked. + * bgp_writes_start() is invoked. */ -extern void peer_writes_init(void); +extern void bgp_io_init(void); /** * Start function for write thread. * - * This function should be passed to pthread_create() during BGP startup. + * @param arg - unused */ -extern void *peer_writes_start(void *arg); +extern void *bgp_io_start(void *arg); /** * Start function for write thread. * * Uninitializes all resources and stops the thread. * - * @param result -- where to store data result, unused + * @param result - where to store data result, unused */ -extern int peer_writes_stop(void **result); +extern int bgp_io_stop(void **result, struct frr_pthread *fpt); /** - * Registers a peer with the write thread. - * - * This function adds the peer to an internal data structure, which must be - * locked for write access. This call will block until the structure can be - * locked. + * Turns on packet writing for a peer. * * After this function is called, any packets placed on peer->obuf will be - * written to peer->fd at regular intervals. + * written to peer->fd at regular intervals. Additionally it becomes unsafe to + * use peer->fd with select() or poll(). * * This function increments the peer reference counter with peer_lock(). * @@ -73,32 +70,58 @@ extern int peer_writes_stop(void **result); * * @param peer - peer to register */ -extern void peer_writes_on(struct peer *peer); +extern void bgp_writes_on(struct peer *peer); /** - * Deregisters a peer with the write thread. - * - * This function removes the peer from an internal data structure, which must - * be locked for write access. This call will block until the structure can be - * locked. + * Turns off packet writing for a peer. * * After this function is called, any packets placed on peer->obuf will not be - * written to peer->fd. + * written to peer->fd. After this function returns it is safe to use peer->fd + * with select() or poll(). * - * This function decrements the peer reference counter with peer_unlock(). + * If the flush = true, a last-ditch effort will be made to flush any remaining + * packets to peer->fd. Upon encountering any error whatsoever, the attempt + * will abort. If the caller wishes to know whether the flush succeeded they + * may check peer->obuf->count against zero. * * If the peer is not registered, nothing happens. * * @param peer - peer to deregister + * @param flush - as described + */ +extern void bgp_writes_off(struct peer *peer); + +/** + * Turns on packet reading for a peer. + * + * After this function is called, any packets received on peer->fd will be read + * and copied into the FIFO queue peer->ibuf. Additionally it becomes unsafe to + * use peer->fd with select() or poll(). + * + * When a full packet is read, bgp_process_packet() will be scheduled on the + * main thread. + * + * This function increments the peer reference counter with peer_lock(). + * + * If the peer is already registered, nothing happens. + * + * @param peer - peer to register */ -extern void peer_writes_off(struct peer *peer); +extern void bgp_reads_on(struct peer *peer); /** - * Notifies the write thread that there is work to be done. + * Turns off packet reading for a peer. + * + * After this function is called, any packets received on peer->fd will not be + * read. After this function returns it is safe to use peer->fd with select() + * or poll(). * - * This function has the effect of waking the write thread if it is sleeping. - * If the thread is not sleeping, this signal will be ignored. + * This function decrements the peer reference counter with peer_unlock(). + * + * If the peer is not registered, nothing happens. + * + * @param peer - peer to deregister */ -extern void peer_writes_wake(void); +extern void bgp_reads_off(struct peer *peer); #endif /* _FRR_BGP_IO_H */ |