]>
Commit | Line | Data |
---|---|---|
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 | |
51e94aa7 EDP |
43 | #ifdef __cplusplus |
44 | extern "C" { | |
45 | #endif | |
46 | ||
718e3744 | 47 | /* Default port information. */ |
718e3744 | 48 | #define ZEBRA_VTY_PORT 2601 |
718e3744 | 49 | |
50 | /* Default configuration filename. */ | |
51 | #define DEFAULT_CONFIG_FILE "zebra.conf" | |
52 | ||
518f0eb1 DS |
53 | #define ZEBRA_RMAP_DEFAULT_UPDATE_TIMER 5 /* disabled by default */ |
54 | ||
8062cbe2 S |
55 | |
56 | /* Stale route marker timer */ | |
57 | #define ZEBRA_DEFAULT_STALE_UPDATE_DELAY 1 | |
58 | ||
59 | /* Count of stale routes processed in timer context */ | |
60 | #define ZEBRA_MAX_STALE_ROUTE_COUNT 50000 | |
61 | ||
62 | /* Graceful Restart information */ | |
63 | struct client_gr_info { | |
64 | /* VRF for which GR enabled */ | |
65 | vrf_id_t vrf_id; | |
66 | ||
67 | /* AFI */ | |
68 | afi_t current_afi; | |
69 | ||
70 | /* Stale time and GR cap */ | |
71 | uint32_t stale_removal_time; | |
72 | enum zserv_client_capabilities capabilities; | |
73 | ||
74 | /* GR commands */ | |
75 | bool delete; | |
76 | bool gr_enable; | |
77 | bool stale_client; | |
78 | ||
79 | /* Route sync and enable flags for AFI/SAFI */ | |
80 | bool af_enabled[AFI_MAX][SAFI_MAX]; | |
81 | bool route_sync[AFI_MAX][SAFI_MAX]; | |
82 | ||
83 | /* Book keeping */ | |
84 | struct prefix *current_prefix; | |
85 | void *stale_client_ptr; | |
86 | struct thread *t_stale_removal; | |
87 | ||
88 | TAILQ_ENTRY(client_gr_info) gr_info; | |
89 | }; | |
90 | ||
718e3744 | 91 | /* Client structure. */ |
d62a17ae | 92 | struct zserv { |
329e35da QY |
93 | /* Client pthread */ |
94 | struct frr_pthread *pthread; | |
95 | ||
d62a17ae | 96 | /* Client file descriptor. */ |
97 | int sock; | |
98 | ||
99 | /* Input/output buffer to the client. */ | |
329e35da | 100 | pthread_mutex_t ibuf_mtx; |
1002497a | 101 | struct stream_fifo *ibuf_fifo; |
329e35da | 102 | pthread_mutex_t obuf_mtx; |
1002497a QY |
103 | struct stream_fifo *obuf_fifo; |
104 | ||
105 | /* Private I/O buffers */ | |
106 | struct stream *ibuf_work; | |
107 | struct stream *obuf_work; | |
d62a17ae | 108 | |
109 | /* Buffer of data waiting to be written to client. */ | |
110 | struct buffer *wb; | |
111 | ||
112 | /* Threads for read/write. */ | |
113 | struct thread *t_read; | |
114 | struct thread *t_write; | |
115 | ||
dded2aba MS |
116 | /* Event for message processing, for the main pthread */ |
117 | struct thread *t_process; | |
118 | ||
f3e33b69 QY |
119 | /* Threads for the main pthread */ |
120 | struct thread *t_cleanup; | |
121 | ||
d62a17ae | 122 | /* This client's redistribute flag. */ |
123 | struct redist_proto mi_redist[AFI_MAX][ZEBRA_ROUTE_MAX]; | |
124 | vrf_bitmap_t redist[AFI_MAX][ZEBRA_ROUTE_MAX]; | |
125 | ||
126 | /* Redistribute default route flag. */ | |
49db7a7b | 127 | vrf_bitmap_t redist_default[AFI_MAX]; |
d62a17ae | 128 | |
d62a17ae | 129 | /* Router-id information. */ |
130 | vrf_bitmap_t ridinfo; | |
131 | ||
e1a1880d DS |
132 | bool notify_owner; |
133 | ||
d62a17ae | 134 | /* client's protocol */ |
d7c0a89a | 135 | uint8_t proto; |
453844ab | 136 | uint16_t instance; |
d62a17ae | 137 | |
ee235396 SK |
138 | /* |
139 | * Interested for MLAG Updates, and also stores the client | |
140 | * interested message mask | |
141 | */ | |
142 | bool mlag_updates_interested; | |
143 | uint32_t mlag_reg_mask1; | |
144 | ||
d62a17ae | 145 | /* Statistics */ |
d7c0a89a QY |
146 | uint32_t redist_v4_add_cnt; |
147 | uint32_t redist_v4_del_cnt; | |
148 | uint32_t redist_v6_add_cnt; | |
149 | uint32_t redist_v6_del_cnt; | |
150 | uint32_t v4_route_add_cnt; | |
151 | uint32_t v4_route_upd8_cnt; | |
152 | uint32_t v4_route_del_cnt; | |
153 | uint32_t v6_route_add_cnt; | |
154 | uint32_t v6_route_del_cnt; | |
155 | uint32_t v6_route_upd8_cnt; | |
156 | uint32_t connected_rt_add_cnt; | |
157 | uint32_t connected_rt_del_cnt; | |
158 | uint32_t ifup_cnt; | |
159 | uint32_t ifdown_cnt; | |
160 | uint32_t ifadd_cnt; | |
161 | uint32_t ifdel_cnt; | |
162 | uint32_t if_bfd_cnt; | |
163 | uint32_t bfd_peer_add_cnt; | |
164 | uint32_t bfd_peer_upd8_cnt; | |
165 | uint32_t bfd_peer_del_cnt; | |
166 | uint32_t bfd_peer_replay_cnt; | |
167 | uint32_t vrfadd_cnt; | |
168 | uint32_t vrfdel_cnt; | |
169 | uint32_t if_vrfchg_cnt; | |
170 | uint32_t bfd_client_reg_cnt; | |
171 | uint32_t vniadd_cnt; | |
172 | uint32_t vnidel_cnt; | |
173 | uint32_t l3vniadd_cnt; | |
174 | uint32_t l3vnidel_cnt; | |
175 | uint32_t macipadd_cnt; | |
176 | uint32_t macipdel_cnt; | |
177 | uint32_t prefixadd_cnt; | |
178 | uint32_t prefixdel_cnt; | |
ab5990d8 DS |
179 | uint32_t v4_nh_watch_add_cnt; |
180 | uint32_t v4_nh_watch_rem_cnt; | |
181 | uint32_t v6_nh_watch_add_cnt; | |
182 | uint32_t v6_nh_watch_rem_cnt; | |
4ab3321f AK |
183 | uint32_t vxlan_sg_add_cnt; |
184 | uint32_t vxlan_sg_del_cnt; | |
9ab0b2a3 | 185 | uint32_t error_cnt; |
d62a17ae | 186 | |
d62a17ae | 187 | time_t nh_reg_time; |
188 | time_t nh_dereg_time; | |
189 | time_t nh_last_upd_time; | |
190 | ||
52f6868d QY |
191 | /* |
192 | * Session information. | |
193 | * | |
194 | * These are not synchronous with respect to each other. For instance, | |
195 | * last_read_cmd may contain a value that has been read in the future | |
196 | * relative to last_read_time. | |
197 | */ | |
198 | ||
199 | /* monotime of client creation */ | |
200 | _Atomic uint32_t connect_time; | |
201 | /* monotime of last message received */ | |
202 | _Atomic uint32_t last_read_time; | |
203 | /* monotime of last message sent */ | |
204 | _Atomic uint32_t last_write_time; | |
205 | /* command code of last message read */ | |
0545c373 | 206 | _Atomic uint32_t last_read_cmd; |
52f6868d | 207 | /* command code of last message written */ |
0545c373 | 208 | _Atomic uint32_t last_write_cmd; |
8062cbe2 S |
209 | |
210 | /* | |
211 | * Number of instances configured with | |
212 | * graceful restart | |
213 | */ | |
214 | uint32_t gr_instance_count; | |
215 | time_t restart_time; | |
216 | ||
217 | /* | |
218 | * Graceful restart information for | |
219 | * each instance | |
220 | */ | |
221 | TAILQ_HEAD(info_list, client_gr_info) gr_info_queue; | |
718e3744 | 222 | }; |
223 | ||
89f4e507 | 224 | #define ZAPI_HANDLER_ARGS \ |
1002497a QY |
225 | struct zserv *client, struct zmsghdr *hdr, struct stream *msg, \ |
226 | struct zebra_vrf *zvrf | |
89f4e507 | 227 | |
453844ab | 228 | /* Hooks for client connect / disconnect */ |
21ccc0cf QY |
229 | DECLARE_HOOK(zserv_client_connect, (struct zserv *client), (client)); |
230 | DECLARE_KOOH(zserv_client_close, (struct zserv *client), (client)); | |
453844ab | 231 | |
21ccc0cf QY |
232 | /* |
233 | * Initialize Zebra API server. | |
234 | * | |
235 | * Installs CLI commands and creates the client list. | |
236 | */ | |
5f145fb8 | 237 | extern void zserv_init(void); |
fb018d25 | 238 | |
41674562 DS |
239 | /* |
240 | * Stop the Zebra API server. | |
241 | * | |
242 | * closes the socket | |
243 | */ | |
244 | extern void zserv_close(void); | |
245 | ||
21ccc0cf QY |
246 | /* |
247 | * Start Zebra API server. | |
248 | * | |
249 | * Allocates resources, creates the server socket and begins listening on the | |
250 | * socket. | |
251 | * | |
252 | * path | |
253 | * where to place the Unix domain socket | |
254 | */ | |
255 | extern void zserv_start(char *path); | |
256 | ||
257 | /* | |
258 | * Send a message to a connected Zebra API client. | |
259 | * | |
260 | * client | |
261 | * the client to send to | |
262 | * | |
263 | * msg | |
264 | * the message to send | |
265 | */ | |
266 | extern int zserv_send_message(struct zserv *client, struct stream *msg); | |
267 | ||
268 | /* | |
269 | * Retrieve a client by its protocol and instance number. | |
270 | * | |
271 | * proto | |
272 | * protocol number | |
273 | * | |
274 | * instance | |
275 | * instance number | |
276 | * | |
277 | * Returns: | |
278 | * The Zebra API client. | |
279 | */ | |
280 | extern struct zserv *zserv_find_client(uint8_t proto, unsigned short instance); | |
8ed6821e | 281 | |
f3e33b69 QY |
282 | /* |
283 | * Close a client. | |
284 | * | |
285 | * Kills a client's thread, removes the client from the client list and cleans | |
286 | * up its resources. | |
287 | * | |
288 | * client | |
289 | * the client to close | |
290 | */ | |
291 | extern void zserv_close_client(struct zserv *client); | |
292 | ||
49b3b01f QY |
293 | /* |
294 | * Log a ZAPI message hexdump. | |
295 | * | |
296 | * errmsg | |
297 | * Error message to include with packet hexdump | |
298 | * | |
299 | * msg | |
300 | * Message to log | |
301 | * | |
302 | * hdr | |
303 | * Message header | |
304 | */ | |
305 | void zserv_log_message(const char *errmsg, struct stream *msg, | |
306 | struct zmsghdr *hdr); | |
307 | ||
411314ed DS |
308 | #if defined(HANDLE_ZAPI_FUZZING) |
309 | extern void zserv_read_file(char *input); | |
310 | #endif | |
311 | ||
4dfd7a02 MS |
312 | /* TODO */ |
313 | int zebra_finalize(struct thread *event); | |
314 | ||
851140a7 S |
315 | /* |
316 | * Graceful restart functions. | |
317 | */ | |
318 | extern int zebra_gr_client_disconnect(struct zserv *client); | |
319 | extern void zebra_gr_client_reconnect(struct zserv *client); | |
b9e6727a S |
320 | extern void zebra_gr_stale_client_cleanup(struct list *client_list); |
321 | extern void zread_client_capabilities(struct zserv *client, struct zmsghdr *hdr, | |
322 | struct stream *msg, | |
323 | struct zebra_vrf *zvrf); | |
851140a7 | 324 | |
51e94aa7 EDP |
325 | #ifdef __cplusplus |
326 | } | |
327 | #endif | |
328 | ||
718e3744 | 329 | #endif /* _ZEBRA_ZEBRA_H */ |