]> git.proxmox.com Git - mirror_frr.git/blob - zebra/zserv.h
Merge pull request #5192 from donaldsharp/zebra_rejection
[mirror_frr.git] / zebra / zserv.h
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.
7 *
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.
12 *
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.
17 *
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
21 */
22
23 #ifndef _ZEBRA_ZSERV_H
24 #define _ZEBRA_ZSERV_H
25
26 /* clang-format off */
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 */
38 #include "lib/hook.h" /* for DECLARE_HOOK, DECLARE_KOOH */
39
40 #include "zebra/zebra_vrf.h" /* for zebra_vrf */
41 /* clang-format on */
42
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46
47 /* Default port information. */
48 #define ZEBRA_VTY_PORT 2601
49
50 /* Default configuration filename. */
51 #define DEFAULT_CONFIG_FILE "zebra.conf"
52
53 #define ZEBRA_RMAP_DEFAULT_UPDATE_TIMER 5 /* disabled by default */
54
55 /* Client structure. */
56 struct zserv {
57 /* Client pthread */
58 struct frr_pthread *pthread;
59
60 /* Client file descriptor. */
61 int sock;
62
63 /* Input/output buffer to the client. */
64 pthread_mutex_t ibuf_mtx;
65 struct stream_fifo *ibuf_fifo;
66 pthread_mutex_t obuf_mtx;
67 struct stream_fifo *obuf_fifo;
68
69 /* Private I/O buffers */
70 struct stream *ibuf_work;
71 struct stream *obuf_work;
72
73 /* Buffer of data waiting to be written to client. */
74 struct buffer *wb;
75
76 /* Threads for read/write. */
77 struct thread *t_read;
78 struct thread *t_write;
79
80 /* Event for message processing, for the main pthread */
81 struct thread *t_process;
82
83 /* Threads for the main pthread */
84 struct thread *t_cleanup;
85
86 /* This client's redistribute flag. */
87 struct redist_proto mi_redist[AFI_MAX][ZEBRA_ROUTE_MAX];
88 vrf_bitmap_t redist[AFI_MAX][ZEBRA_ROUTE_MAX];
89
90 /* Redistribute default route flag. */
91 vrf_bitmap_t redist_default[AFI_MAX];
92
93 /* Router-id information. */
94 vrf_bitmap_t ridinfo;
95
96 bool notify_owner;
97
98 /* client's protocol */
99 uint8_t proto;
100 uint16_t instance;
101
102 /*
103 * Interested for MLAG Updates, and also stores the client
104 * interested message mask
105 */
106 bool mlag_updates_interested;
107 uint32_t mlag_reg_mask1;
108
109 /* Statistics */
110 uint32_t redist_v4_add_cnt;
111 uint32_t redist_v4_del_cnt;
112 uint32_t redist_v6_add_cnt;
113 uint32_t redist_v6_del_cnt;
114 uint32_t v4_route_add_cnt;
115 uint32_t v4_route_upd8_cnt;
116 uint32_t v4_route_del_cnt;
117 uint32_t v6_route_add_cnt;
118 uint32_t v6_route_del_cnt;
119 uint32_t v6_route_upd8_cnt;
120 uint32_t connected_rt_add_cnt;
121 uint32_t connected_rt_del_cnt;
122 uint32_t ifup_cnt;
123 uint32_t ifdown_cnt;
124 uint32_t ifadd_cnt;
125 uint32_t ifdel_cnt;
126 uint32_t if_bfd_cnt;
127 uint32_t bfd_peer_add_cnt;
128 uint32_t bfd_peer_upd8_cnt;
129 uint32_t bfd_peer_del_cnt;
130 uint32_t bfd_peer_replay_cnt;
131 uint32_t vrfadd_cnt;
132 uint32_t vrfdel_cnt;
133 uint32_t if_vrfchg_cnt;
134 uint32_t bfd_client_reg_cnt;
135 uint32_t vniadd_cnt;
136 uint32_t vnidel_cnt;
137 uint32_t l3vniadd_cnt;
138 uint32_t l3vnidel_cnt;
139 uint32_t macipadd_cnt;
140 uint32_t macipdel_cnt;
141 uint32_t prefixadd_cnt;
142 uint32_t prefixdel_cnt;
143 uint32_t v4_nh_watch_add_cnt;
144 uint32_t v4_nh_watch_rem_cnt;
145 uint32_t v6_nh_watch_add_cnt;
146 uint32_t v6_nh_watch_rem_cnt;
147 uint32_t vxlan_sg_add_cnt;
148 uint32_t vxlan_sg_del_cnt;
149
150 time_t nh_reg_time;
151 time_t nh_dereg_time;
152 time_t nh_last_upd_time;
153
154 /*
155 * Session information.
156 *
157 * These are not synchronous with respect to each other. For instance,
158 * last_read_cmd may contain a value that has been read in the future
159 * relative to last_read_time.
160 */
161
162 /* monotime of client creation */
163 _Atomic uint32_t connect_time;
164 /* monotime of last message received */
165 _Atomic uint32_t last_read_time;
166 /* monotime of last message sent */
167 _Atomic uint32_t last_write_time;
168 /* command code of last message read */
169 _Atomic uint32_t last_read_cmd;
170 /* command code of last message written */
171 _Atomic uint32_t last_write_cmd;
172 };
173
174 #define ZAPI_HANDLER_ARGS \
175 struct zserv *client, struct zmsghdr *hdr, struct stream *msg, \
176 struct zebra_vrf *zvrf
177
178 /* Hooks for client connect / disconnect */
179 DECLARE_HOOK(zserv_client_connect, (struct zserv *client), (client));
180 DECLARE_KOOH(zserv_client_close, (struct zserv *client), (client));
181
182 /*
183 * Initialize Zebra API server.
184 *
185 * Installs CLI commands and creates the client list.
186 */
187 extern void zserv_init(void);
188
189 /*
190 * Stop the Zebra API server.
191 *
192 * closes the socket
193 */
194 extern void zserv_close(void);
195
196 /*
197 * Start Zebra API server.
198 *
199 * Allocates resources, creates the server socket and begins listening on the
200 * socket.
201 *
202 * path
203 * where to place the Unix domain socket
204 */
205 extern void zserv_start(char *path);
206
207 /*
208 * Send a message to a connected Zebra API client.
209 *
210 * client
211 * the client to send to
212 *
213 * msg
214 * the message to send
215 */
216 extern int zserv_send_message(struct zserv *client, struct stream *msg);
217
218 /*
219 * Retrieve a client by its protocol and instance number.
220 *
221 * proto
222 * protocol number
223 *
224 * instance
225 * instance number
226 *
227 * Returns:
228 * The Zebra API client.
229 */
230 extern struct zserv *zserv_find_client(uint8_t proto, unsigned short instance);
231
232
233 /*
234 * Close a client.
235 *
236 * Kills a client's thread, removes the client from the client list and cleans
237 * up its resources.
238 *
239 * client
240 * the client to close
241 */
242 extern void zserv_close_client(struct zserv *client);
243
244
245 /*
246 * Log a ZAPI message hexdump.
247 *
248 * errmsg
249 * Error message to include with packet hexdump
250 *
251 * msg
252 * Message to log
253 *
254 * hdr
255 * Message header
256 */
257 void zserv_log_message(const char *errmsg, struct stream *msg,
258 struct zmsghdr *hdr);
259
260 #if defined(HANDLE_ZAPI_FUZZING)
261 extern void zserv_read_file(char *input);
262 #endif
263
264 /* TODO */
265 int zebra_finalize(struct thread *event);
266
267 #ifdef __cplusplus
268 }
269 #endif
270
271 #endif /* _ZEBRA_ZEBRA_H */