]>
Commit | Line | Data |
---|---|---|
56257a44 QY |
1 | /* |
2 | BGP I/O. | |
3 | Implements a consumer thread to flush packets destined for remote peers. | |
4 | ||
5 | Copyright (C) 2017 Cumulus Networks | |
6 | ||
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. | |
11 | ||
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. | |
16 | ||
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, | |
20 | MA 02110-1301 USA | |
21 | */ | |
22 | ||
23 | #ifndef _FRR_BGP_IO_H | |
24 | #define _FRR_BGP_IO_H | |
25 | ||
424ab01d | 26 | #include "frr_pthread.h" |
56257a44 QY |
27 | #include "bgpd/bgpd.h" |
28 | ||
29 | /** | |
30 | * Control variable for write thread. | |
31 | * | |
424ab01d | 32 | * Setting this variable to false will eventually result in thread termination. |
56257a44 QY |
33 | */ |
34 | extern bool bgp_packet_writes_thread_run; | |
35 | ||
36 | /** | |
37 | * Initializes data structures and flags for the write thread. | |
38 | * | |
39 | * This function should be called from the main thread before | |
424ab01d | 40 | * bgp_writes_start() is invoked. |
56257a44 | 41 | */ |
424ab01d | 42 | extern void bgp_io_init(void); |
56257a44 QY |
43 | |
44 | /** | |
45 | * Start function for write thread. | |
46 | * | |
424ab01d | 47 | * @param arg - unused |
56257a44 | 48 | */ |
424ab01d | 49 | extern void *bgp_io_start(void *arg); |
56257a44 QY |
50 | |
51 | /** | |
52 | * Start function for write thread. | |
53 | * | |
54 | * Uninitializes all resources and stops the thread. | |
55 | * | |
424ab01d | 56 | * @param result - where to store data result, unused |
56257a44 | 57 | */ |
424ab01d | 58 | extern int bgp_io_stop(void **result, struct frr_pthread *fpt); |
56257a44 QY |
59 | |
60 | /** | |
424ab01d | 61 | * Turns on packet writing for a peer. |
56257a44 QY |
62 | * |
63 | * After this function is called, any packets placed on peer->obuf will be | |
424ab01d QY |
64 | * written to peer->fd at regular intervals. Additionally it becomes unsafe to |
65 | * use peer->fd with select() or poll(). | |
56257a44 QY |
66 | * |
67 | * This function increments the peer reference counter with peer_lock(). | |
68 | * | |
69 | * If the peer is already registered, nothing happens. | |
70 | * | |
71 | * @param peer - peer to register | |
72 | */ | |
424ab01d | 73 | extern void bgp_writes_on(struct peer *peer); |
56257a44 QY |
74 | |
75 | /** | |
424ab01d | 76 | * Turns off packet writing for a peer. |
56257a44 QY |
77 | * |
78 | * After this function is called, any packets placed on peer->obuf will not be | |
424ab01d QY |
79 | * written to peer->fd. After this function returns it is safe to use peer->fd |
80 | * with select() or poll(). | |
56257a44 | 81 | * |
424ab01d QY |
82 | * If the flush = true, a last-ditch effort will be made to flush any remaining |
83 | * packets to peer->fd. Upon encountering any error whatsoever, the attempt | |
84 | * will abort. If the caller wishes to know whether the flush succeeded they | |
85 | * may check peer->obuf->count against zero. | |
56257a44 QY |
86 | * |
87 | * If the peer is not registered, nothing happens. | |
88 | * | |
89 | * @param peer - peer to deregister | |
424ab01d QY |
90 | * @param flush - as described |
91 | */ | |
92 | extern void bgp_writes_off(struct peer *peer); | |
93 | ||
94 | /** | |
95 | * Turns on packet reading for a peer. | |
96 | * | |
97 | * After this function is called, any packets received on peer->fd will be read | |
98 | * and copied into the FIFO queue peer->ibuf. Additionally it becomes unsafe to | |
99 | * use peer->fd with select() or poll(). | |
100 | * | |
101 | * When a full packet is read, bgp_process_packet() will be scheduled on the | |
102 | * main thread. | |
103 | * | |
104 | * This function increments the peer reference counter with peer_lock(). | |
105 | * | |
106 | * If the peer is already registered, nothing happens. | |
107 | * | |
108 | * @param peer - peer to register | |
56257a44 | 109 | */ |
424ab01d | 110 | extern void bgp_reads_on(struct peer *peer); |
56257a44 QY |
111 | |
112 | /** | |
424ab01d QY |
113 | * Turns off packet reading for a peer. |
114 | * | |
115 | * After this function is called, any packets received on peer->fd will not be | |
116 | * read. After this function returns it is safe to use peer->fd with select() | |
117 | * or poll(). | |
56257a44 | 118 | * |
424ab01d QY |
119 | * This function decrements the peer reference counter with peer_unlock(). |
120 | * | |
121 | * If the peer is not registered, nothing happens. | |
122 | * | |
123 | * @param peer - peer to deregister | |
56257a44 | 124 | */ |
424ab01d | 125 | extern void bgp_reads_off(struct peer *peer); |
56257a44 QY |
126 | |
127 | #endif /* _FRR_BGP_IO_H */ |