]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_io.h
bgpd: update I/O docs
[mirror_frr.git] / bgpd / bgp_io.h
1 /* BGP I/O.
2 * Implements packet I/O in a pthread.
3 * Copyright (C) 2017 Cumulus Networks
4 * Quentin Young
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; see the file COPYING; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
19 * MA 02110-1301 USA
20 */
21
22 #ifndef _FRR_BGP_IO_H
23 #define _FRR_BGP_IO_H
24
25 #define BGP_WRITE_PACKET_MAX 10U
26 #define BGP_READ_PACKET_MAX 10U
27
28 #include "bgpd/bgpd.h"
29 #include "frr_pthread.h"
30
31 /**
32 * Control variable for write thread.
33 *
34 * Setting this variable to false will eventually result in thread termination.
35 */
36 extern bool bgp_packet_writes_thread_run;
37
38 /**
39 * Initializes data structures and flags for the write thread.
40 *
41 * This function should be called from the main thread before
42 * bgp_writes_start() is invoked.
43 */
44 extern void bgp_io_init(void);
45
46 /**
47 * Start function for write thread.
48 *
49 * @param arg - unused
50 */
51 extern void *bgp_io_start(void *arg);
52
53 /**
54 * Start function for write thread.
55 *
56 * Uninitializes all resources and stops the thread.
57 *
58 * @param result - where to store data result, unused
59 */
60 extern int bgp_io_stop(void **result, struct frr_pthread *fpt);
61
62 /**
63 * Turns on packet writing for a peer.
64 *
65 * After this function is called, any packets placed on peer->obuf will be
66 * written to peer->fd until no more packets remain.
67 *
68 * Additionally, it becomes unsafe to perform socket actions on peer->fd.
69 *
70 * @param peer - peer to register
71 */
72 extern void bgp_writes_on(struct peer *peer);
73
74 /**
75 * Turns off packet writing for a peer.
76 *
77 * After this function returns, packets placed on peer->obuf will not be
78 * written to peer->fd by the I/O thread.
79 *
80 * After this function returns it becomes safe to perform socket actions on
81 * peer->fd.
82 *
83 * @param peer - peer to deregister
84 * @param flush - as described
85 */
86 extern void bgp_writes_off(struct peer *peer);
87
88 /**
89 * Turns on packet reading for a peer.
90 *
91 * After this function is called, any packets received on peer->fd will be read
92 * and copied into the FIFO queue peer->ibuf.
93 *
94 * Additionally, it becomes unsafe to perform socket actions on peer->fd.
95 *
96 * Whenever one or more packets are placed onto peer->ibuf, a task of type
97 * THREAD_EVENT will be placed on the main thread whose handler is
98 *
99 * bgp_packet.c:bgp_process_packet()
100 *
101 * @param peer - peer to register
102 */
103 extern void bgp_reads_on(struct peer *peer);
104
105 /**
106 * Turns off packet reading for a peer.
107 *
108 * After this function is called, any packets received on peer->fd will not be
109 * read by the I/O thread.
110 *
111 * After this function returns it becomes safe to perform socket actions on
112 * peer->fd.
113 *
114 * @param peer - peer to deregister
115 */
116 extern void bgp_reads_off(struct peer *peer);
117
118 #endif /* _FRR_BGP_IO_H */