]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_io.h
Merge pull request #1664 from chiragshah6/ospfv3_dev
[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 *
f09a656d 34 * This function must 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 39/**
f09a656d 40 * Start function for write thread.
88b24dee 41 *
f09a656d 42 * @param arg - unused
88b24dee 43 */
f09a656d 44extern void *bgp_io_start(void *arg);
88b24dee 45
56257a44 46/**
f09a656d 47 * Wait until the IO thread is ready to accept jobs.
56257a44 48 *
f09a656d
QY
49 * This function must be called immediately after the thread has been created
50 * for running. Use of other functions before calling this one will result in
51 * undefined behavior.
56257a44 52 */
f09a656d 53extern void bgp_io_wait_running(void);
56257a44
QY
54
55/**
56 * Start function for write thread.
57 *
58 * Uninitializes all resources and stops the thread.
59 *
424ab01d 60 * @param result - where to store data result, unused
56257a44 61 */
424ab01d 62extern int bgp_io_stop(void **result, struct frr_pthread *fpt);
56257a44
QY
63
64/**
424ab01d 65 * Turns on packet writing for a peer.
56257a44
QY
66 *
67 * After this function is called, any packets placed on peer->obuf will be
51abb4b4 68 * written to peer->fd until no more packets remain.
56257a44 69 *
51abb4b4 70 * Additionally, it becomes unsafe to perform socket actions on peer->fd.
56257a44
QY
71 *
72 * @param peer - peer to register
73 */
424ab01d 74extern void bgp_writes_on(struct peer *peer);
56257a44
QY
75
76/**
424ab01d 77 * Turns off packet writing for a peer.
56257a44 78 *
51abb4b4
QY
79 * After this function returns, packets placed on peer->obuf will not be
80 * written to peer->fd by the I/O thread.
56257a44 81 *
51abb4b4
QY
82 * After this function returns it becomes safe to perform socket actions on
83 * peer->fd.
56257a44
QY
84 *
85 * @param peer - peer to deregister
424ab01d
QY
86 * @param flush - as described
87 */
88extern void bgp_writes_off(struct peer *peer);
89
90/**
91 * Turns on packet reading for a peer.
92 *
93 * After this function is called, any packets received on peer->fd will be read
51abb4b4 94 * and copied into the FIFO queue peer->ibuf.
424ab01d 95 *
51abb4b4 96 * Additionally, it becomes unsafe to perform socket actions on peer->fd.
424ab01d 97 *
51abb4b4
QY
98 * Whenever one or more packets are placed onto peer->ibuf, a task of type
99 * THREAD_EVENT will be placed on the main thread whose handler is
424ab01d 100 *
51abb4b4 101 * bgp_packet.c:bgp_process_packet()
424ab01d
QY
102 *
103 * @param peer - peer to register
56257a44 104 */
424ab01d 105extern void bgp_reads_on(struct peer *peer);
56257a44
QY
106
107/**
424ab01d
QY
108 * Turns off packet reading for a peer.
109 *
110 * After this function is called, any packets received on peer->fd will not be
51abb4b4 111 * read by the I/O thread.
424ab01d 112 *
51abb4b4
QY
113 * After this function returns it becomes safe to perform socket actions on
114 * peer->fd.
424ab01d
QY
115 *
116 * @param peer - peer to deregister
56257a44 117 */
424ab01d 118extern void bgp_reads_off(struct peer *peer);
56257a44
QY
119
120#endif /* _FRR_BGP_IO_H */