]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_io.h
lib: add MTYPE for synchronization primitives
[mirror_frr.git] / bgpd / bgp_io.h
CommitLineData
51abb4b4
QY
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
56257a44
QY
20 */
21
22#ifndef _FRR_BGP_IO_H
23#define _FRR_BGP_IO_H
24
555e09d4
QY
25#define BGP_WRITE_PACKET_MAX 10U
26#define BGP_READ_PACKET_MAX 10U
27
56257a44 28#include "bgpd/bgpd.h"
42cf651e 29#include "frr_pthread.h"
56257a44 30
56257a44
QY
31/**
32 * Initializes data structures and flags for the write thread.
33 *
34 * This function should be called from the main thread before
424ab01d 35 * bgp_writes_start() is invoked.
56257a44 36 */
424ab01d 37extern void bgp_io_init(void);
56257a44 38
88b24dee
DS
39/**
40 * Ensure that the BGP IO thread is actually up and running
41 *
42 * This function must be called immediately after the thread
43 * has been created for running. This is because we want
44 * to make sure that the io thread is ready before other
45 * threads start attempting to use it.
46 */
47extern void bgp_io_running(void);
48
56257a44
QY
49/**
50 * Start function for write thread.
51 *
424ab01d 52 * @param arg - unused
56257a44 53 */
424ab01d 54extern void *bgp_io_start(void *arg);
56257a44
QY
55
56/**
57 * Start function for write thread.
58 *
59 * Uninitializes all resources and stops the thread.
60 *
424ab01d 61 * @param result - where to store data result, unused
56257a44 62 */
424ab01d 63extern int bgp_io_stop(void **result, struct frr_pthread *fpt);
56257a44
QY
64
65/**
424ab01d 66 * Turns on packet writing for a peer.
56257a44
QY
67 *
68 * After this function is called, any packets placed on peer->obuf will be
51abb4b4 69 * written to peer->fd until no more packets remain.
56257a44 70 *
51abb4b4 71 * Additionally, it becomes unsafe to perform socket actions on peer->fd.
56257a44
QY
72 *
73 * @param peer - peer to register
74 */
424ab01d 75extern void bgp_writes_on(struct peer *peer);
56257a44
QY
76
77/**
424ab01d 78 * Turns off packet writing for a peer.
56257a44 79 *
51abb4b4
QY
80 * After this function returns, packets placed on peer->obuf will not be
81 * written to peer->fd by the I/O thread.
56257a44 82 *
51abb4b4
QY
83 * After this function returns it becomes safe to perform socket actions on
84 * peer->fd.
56257a44
QY
85 *
86 * @param peer - peer to deregister
424ab01d
QY
87 * @param flush - as described
88 */
89extern void bgp_writes_off(struct peer *peer);
90
91/**
92 * Turns on packet reading for a peer.
93 *
94 * After this function is called, any packets received on peer->fd will be read
51abb4b4 95 * and copied into the FIFO queue peer->ibuf.
424ab01d 96 *
51abb4b4 97 * Additionally, it becomes unsafe to perform socket actions on peer->fd.
424ab01d 98 *
51abb4b4
QY
99 * Whenever one or more packets are placed onto peer->ibuf, a task of type
100 * THREAD_EVENT will be placed on the main thread whose handler is
424ab01d 101 *
51abb4b4 102 * bgp_packet.c:bgp_process_packet()
424ab01d
QY
103 *
104 * @param peer - peer to register
56257a44 105 */
424ab01d 106extern void bgp_reads_on(struct peer *peer);
56257a44
QY
107
108/**
424ab01d
QY
109 * Turns off packet reading for a peer.
110 *
111 * After this function is called, any packets received on peer->fd will not be
51abb4b4 112 * read by the I/O thread.
424ab01d 113 *
51abb4b4
QY
114 * After this function returns it becomes safe to perform socket actions on
115 * peer->fd.
424ab01d
QY
116 *
117 * @param peer - peer to deregister
56257a44 118 */
424ab01d 119extern void bgp_reads_off(struct peer *peer);
56257a44
QY
120
121#endif /* _FRR_BGP_IO_H */