]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_io.h
bgpd: move bgp i/o to a separate source file
[mirror_frr.git] / bgpd / bgp_io.h
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
26 #include "bgpd/bgpd.h"
27
28 /**
29 * Control variable for write thread.
30 *
31 * Setting this variable to false and calling peer_writes_wake() will
32 * eventually result in thread termination.
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
40 * peer_writes_start() is invoked.
41 */
42 extern void peer_writes_init(void);
43
44 /**
45 * Start function for write thread.
46 *
47 * This function should be passed to pthread_create() during BGP startup.
48 */
49 extern void *peer_writes_start(void *arg);
50
51 /**
52 * Start function for write thread.
53 *
54 * Uninitializes all resources and stops the thread.
55 *
56 * @param result -- where to store data result, unused
57 */
58 extern int peer_writes_stop(void **result);
59
60 /**
61 * Registers a peer with the write thread.
62 *
63 * This function adds the peer to an internal data structure, which must be
64 * locked for write access. This call will block until the structure can be
65 * locked.
66 *
67 * After this function is called, any packets placed on peer->obuf will be
68 * written to peer->fd at regular intervals.
69 *
70 * This function increments the peer reference counter with peer_lock().
71 *
72 * If the peer is already registered, nothing happens.
73 *
74 * @param peer - peer to register
75 */
76 extern void peer_writes_on(struct peer *peer);
77
78 /**
79 * Deregisters a peer with the write thread.
80 *
81 * This function removes the peer from an internal data structure, which must
82 * be locked for write access. This call will block until the structure can be
83 * locked.
84 *
85 * After this function is called, any packets placed on peer->obuf will not be
86 * written to peer->fd.
87 *
88 * This function decrements the peer reference counter with peer_unlock().
89 *
90 * If the peer is not registered, nothing happens.
91 *
92 * @param peer - peer to deregister
93 */
94 extern void peer_writes_off(struct peer *peer);
95
96 /**
97 * Notifies the write thread that there is work to be done.
98 *
99 * This function has the effect of waking the write thread if it is sleeping.
100 * If the thread is not sleeping, this signal will be ignored.
101 */
102 extern void peer_writes_wake(void);
103
104 #endif /* _FRR_BGP_IO_H */