3 Implements a consumer thread to flush packets destined for remote peers.
5 Copyright (C) 2017 Cumulus Networks
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; see the file COPYING; if not, write to the
19 Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
26 #define BGP_WRITE_PACKET_MAX 10U
27 #define BGP_READ_PACKET_MAX 10U
29 #include "bgpd/bgpd.h"
30 #include "frr_pthread.h"
33 * Control variable for write thread.
35 * Setting this variable to false will eventually result in thread termination.
37 extern bool bgp_packet_writes_thread_run
;
40 * Initializes data structures and flags for the write thread.
42 * This function should be called from the main thread before
43 * bgp_writes_start() is invoked.
45 extern void bgp_io_init(void);
48 * Start function for write thread.
52 extern void *bgp_io_start(void *arg
);
55 * Start function for write thread.
57 * Uninitializes all resources and stops the thread.
59 * @param result - where to store data result, unused
61 extern int bgp_io_stop(void **result
, struct frr_pthread
*fpt
);
64 * Turns on packet writing for a peer.
66 * After this function is called, any packets placed on peer->obuf will be
67 * written to peer->fd at regular intervals. Additionally it becomes unsafe to
68 * use peer->fd with select() or poll().
70 * This function increments the peer reference counter with peer_lock().
72 * If the peer is already registered, nothing happens.
74 * @param peer - peer to register
76 extern void bgp_writes_on(struct peer
*peer
);
79 * Turns off packet writing for a peer.
81 * After this function is called, any packets placed on peer->obuf will not be
82 * written to peer->fd. After this function returns it is safe to use peer->fd
83 * with select() or poll().
85 * If the flush = true, a last-ditch effort will be made to flush any remaining
86 * packets to peer->fd. Upon encountering any error whatsoever, the attempt
87 * will abort. If the caller wishes to know whether the flush succeeded they
88 * may check peer->obuf->count against zero.
90 * If the peer is not registered, nothing happens.
92 * @param peer - peer to deregister
93 * @param flush - as described
95 extern void bgp_writes_off(struct peer
*peer
);
98 * Turns on packet reading for a peer.
100 * After this function is called, any packets received on peer->fd will be read
101 * and copied into the FIFO queue peer->ibuf. Additionally it becomes unsafe to
102 * use peer->fd with select() or poll().
104 * When a full packet is read, bgp_process_packet() will be scheduled on the
107 * This function increments the peer reference counter with peer_lock().
109 * If the peer is already registered, nothing happens.
111 * @param peer - peer to register
113 extern void bgp_reads_on(struct peer
*peer
);
116 * Turns off packet reading for a peer.
118 * After this function is called, any packets received on peer->fd will not be
119 * read. After this function returns it is safe to use peer->fd with select()
122 * This function decrements the peer reference counter with peer_unlock().
124 * If the peer is not registered, nothing happens.
126 * @param peer - peer to deregister
128 extern void bgp_reads_off(struct peer
*peer
);
130 #endif /* _FRR_BGP_IO_H */