]> git.proxmox.com Git - mirror_frr.git/blame - zebra/zserv.h
Merge pull request #3344 from ton31337/fix/optional_args_for_community-lists
[mirror_frr.git] / zebra / zserv.h
CommitLineData
bf094f69
QY
1/*
2 * Zebra API server.
3 * Portions:
4 * Copyright (C) 1997-1999 Kunihiro Ishiguro
5 * Copyright (C) 2015-2018 Cumulus Networks, Inc.
6 * et al.
718e3744 7 *
bf094f69
QY
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free
10 * Software Foundation; either version 2 of the License, or (at your option)
11 * any later version.
718e3744 12 *
bf094f69
QY
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * more details.
718e3744 17 *
896014f4
DL
18 * You should have received a copy of the GNU General Public License along
19 * with this program; see the file COPYING; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
718e3744 21 */
22
23#ifndef _ZEBRA_ZSERV_H
24#define _ZEBRA_ZSERV_H
25
d8647095 26/* clang-format off */
bf094f69
QY
27#include <stdint.h> /* for uint32_t, uint8_t */
28#include <time.h> /* for time_t */
29
30#include "lib/route_types.h" /* for ZEBRA_ROUTE_MAX */
31#include "lib/zebra.h" /* for AFI_MAX */
32#include "lib/vrf.h" /* for vrf_bitmap_t */
33#include "lib/zclient.h" /* for redist_proto */
34#include "lib/stream.h" /* for stream, stream_fifo */
35#include "lib/thread.h" /* for thread, thread_master */
36#include "lib/linklist.h" /* for list */
37#include "lib/workqueue.h" /* for work_queue */
453844ab 38#include "lib/hook.h" /* for DECLARE_HOOK, DECLARE_KOOH */
5b73a671 39
bf094f69 40#include "zebra/zebra_vrf.h" /* for zebra_vrf */
d8647095 41/* clang-format on */
6833ae01 42
718e3744 43/* Default port information. */
718e3744 44#define ZEBRA_VTY_PORT 2601
718e3744 45
46/* Default configuration filename. */
47#define DEFAULT_CONFIG_FILE "zebra.conf"
48
518f0eb1
DS
49#define ZEBRA_RMAP_DEFAULT_UPDATE_TIMER 5 /* disabled by default */
50
718e3744 51/* Client structure. */
d62a17ae 52struct zserv {
329e35da
QY
53 /* Client pthread */
54 struct frr_pthread *pthread;
55
d62a17ae 56 /* Client file descriptor. */
57 int sock;
58
59 /* Input/output buffer to the client. */
329e35da 60 pthread_mutex_t ibuf_mtx;
1002497a 61 struct stream_fifo *ibuf_fifo;
329e35da 62 pthread_mutex_t obuf_mtx;
1002497a
QY
63 struct stream_fifo *obuf_fifo;
64
65 /* Private I/O buffers */
66 struct stream *ibuf_work;
67 struct stream *obuf_work;
d62a17ae 68
69 /* Buffer of data waiting to be written to client. */
70 struct buffer *wb;
71
72 /* Threads for read/write. */
73 struct thread *t_read;
74 struct thread *t_write;
75
f3e33b69
QY
76 /* Threads for the main pthread */
77 struct thread *t_cleanup;
78
d62a17ae 79 /* default routing table this client munges */
80 int rtm_table;
81
82 /* This client's redistribute flag. */
83 struct redist_proto mi_redist[AFI_MAX][ZEBRA_ROUTE_MAX];
84 vrf_bitmap_t redist[AFI_MAX][ZEBRA_ROUTE_MAX];
85
86 /* Redistribute default route flag. */
87 vrf_bitmap_t redist_default;
88
89 /* Interface information. */
90 vrf_bitmap_t ifinfo;
91
92 /* Router-id information. */
93 vrf_bitmap_t ridinfo;
94
e1a1880d
DS
95 bool notify_owner;
96
d62a17ae 97 /* client's protocol */
d7c0a89a 98 uint8_t proto;
453844ab 99 uint16_t instance;
d7c0a89a 100 uint8_t is_synchronous;
d62a17ae 101
102 /* Statistics */
d7c0a89a
QY
103 uint32_t redist_v4_add_cnt;
104 uint32_t redist_v4_del_cnt;
105 uint32_t redist_v6_add_cnt;
106 uint32_t redist_v6_del_cnt;
107 uint32_t v4_route_add_cnt;
108 uint32_t v4_route_upd8_cnt;
109 uint32_t v4_route_del_cnt;
110 uint32_t v6_route_add_cnt;
111 uint32_t v6_route_del_cnt;
112 uint32_t v6_route_upd8_cnt;
113 uint32_t connected_rt_add_cnt;
114 uint32_t connected_rt_del_cnt;
115 uint32_t ifup_cnt;
116 uint32_t ifdown_cnt;
117 uint32_t ifadd_cnt;
118 uint32_t ifdel_cnt;
119 uint32_t if_bfd_cnt;
120 uint32_t bfd_peer_add_cnt;
121 uint32_t bfd_peer_upd8_cnt;
122 uint32_t bfd_peer_del_cnt;
123 uint32_t bfd_peer_replay_cnt;
124 uint32_t vrfadd_cnt;
125 uint32_t vrfdel_cnt;
126 uint32_t if_vrfchg_cnt;
127 uint32_t bfd_client_reg_cnt;
128 uint32_t vniadd_cnt;
129 uint32_t vnidel_cnt;
130 uint32_t l3vniadd_cnt;
131 uint32_t l3vnidel_cnt;
132 uint32_t macipadd_cnt;
133 uint32_t macipdel_cnt;
134 uint32_t prefixadd_cnt;
135 uint32_t prefixdel_cnt;
ab5990d8
DS
136 uint32_t v4_nh_watch_add_cnt;
137 uint32_t v4_nh_watch_rem_cnt;
138 uint32_t v6_nh_watch_add_cnt;
139 uint32_t v6_nh_watch_rem_cnt;
d62a17ae 140
d62a17ae 141 time_t nh_reg_time;
142 time_t nh_dereg_time;
143 time_t nh_last_upd_time;
144
52f6868d
QY
145 /*
146 * Session information.
147 *
148 * These are not synchronous with respect to each other. For instance,
149 * last_read_cmd may contain a value that has been read in the future
150 * relative to last_read_time.
151 */
152
153 /* monotime of client creation */
154 _Atomic uint32_t connect_time;
155 /* monotime of last message received */
156 _Atomic uint32_t last_read_time;
157 /* monotime of last message sent */
158 _Atomic uint32_t last_write_time;
159 /* command code of last message read */
160 _Atomic uint16_t last_read_cmd;
161 /* command code of last message written */
162 _Atomic uint16_t last_write_cmd;
718e3744 163};
164
89f4e507 165#define ZAPI_HANDLER_ARGS \
1002497a
QY
166 struct zserv *client, struct zmsghdr *hdr, struct stream *msg, \
167 struct zebra_vrf *zvrf
89f4e507 168
453844ab 169/* Hooks for client connect / disconnect */
21ccc0cf
QY
170DECLARE_HOOK(zserv_client_connect, (struct zserv *client), (client));
171DECLARE_KOOH(zserv_client_close, (struct zserv *client), (client));
453844ab 172
b21b19c5 173/* Zebra instance */
d62a17ae 174struct zebra_t {
175 /* Thread master */
176 struct thread_master *master;
177 struct list *client_list;
b21b19c5 178
21ccc0cf
QY
179 /* Socket */
180 int sock;
181
d62a17ae 182 /* default table */
d7c0a89a 183 uint32_t rtm_table_default;
4d38fdb4 184
996c9314
LB
185/* rib work queue */
186#define ZEBRA_RIB_PROCESS_HOLD_TIME 10
d62a17ae 187 struct work_queue *ribq;
188 struct meta_queue *mq;
40c7bdb0 189
d62a17ae 190 /* LSP work queue */
191 struct work_queue *lsp_process_q;
a37ef435 192
ccd51bd2 193#define ZEBRA_ZAPI_PACKETS_TO_PROCESS 1000
1572d9af 194 _Atomic uint32_t packets_to_process;
b21b19c5 195};
44e9909d 196extern struct zebra_t zebrad;
37fe7731 197extern unsigned int multipath_num;
b21b19c5 198
21ccc0cf
QY
199/*
200 * Initialize Zebra API server.
201 *
202 * Installs CLI commands and creates the client list.
203 */
5f145fb8 204extern void zserv_init(void);
fb018d25 205
21ccc0cf
QY
206/*
207 * Start Zebra API server.
208 *
209 * Allocates resources, creates the server socket and begins listening on the
210 * socket.
211 *
212 * path
213 * where to place the Unix domain socket
214 */
215extern void zserv_start(char *path);
216
217/*
218 * Send a message to a connected Zebra API client.
219 *
220 * client
221 * the client to send to
222 *
223 * msg
224 * the message to send
225 */
226extern int zserv_send_message(struct zserv *client, struct stream *msg);
227
228/*
229 * Retrieve a client by its protocol and instance number.
230 *
231 * proto
232 * protocol number
233 *
234 * instance
235 * instance number
236 *
237 * Returns:
238 * The Zebra API client.
239 */
240extern struct zserv *zserv_find_client(uint8_t proto, unsigned short instance);
8ed6821e 241
f3e33b69
QY
242
243/*
244 * Close a client.
245 *
246 * Kills a client's thread, removes the client from the client list and cleans
247 * up its resources.
248 *
249 * client
250 * the client to close
251 */
252extern void zserv_close_client(struct zserv *client);
253
411314ed
DS
254#if defined(HANDLE_ZAPI_FUZZING)
255extern void zserv_read_file(char *input);
256#endif
257
4dfd7a02
MS
258/* TODO */
259int zebra_finalize(struct thread *event);
260
718e3744 261#endif /* _ZEBRA_ZEBRA_H */