]>
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 | ||
718e3744 | 55 | /* Client structure. */ |
d62a17ae | 56 | struct zserv { |
329e35da QY |
57 | /* Client pthread */ |
58 | struct frr_pthread *pthread; | |
59 | ||
d62a17ae | 60 | /* Client file descriptor. */ |
61 | int sock; | |
62 | ||
63 | /* Input/output buffer to the client. */ | |
329e35da | 64 | pthread_mutex_t ibuf_mtx; |
1002497a | 65 | struct stream_fifo *ibuf_fifo; |
329e35da | 66 | pthread_mutex_t obuf_mtx; |
1002497a QY |
67 | struct stream_fifo *obuf_fifo; |
68 | ||
69 | /* Private I/O buffers */ | |
70 | struct stream *ibuf_work; | |
71 | struct stream *obuf_work; | |
d62a17ae | 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 | ||
dded2aba MS |
80 | /* Event for message processing, for the main pthread */ |
81 | struct thread *t_process; | |
82 | ||
f3e33b69 QY |
83 | /* Threads for the main pthread */ |
84 | struct thread *t_cleanup; | |
85 | ||
d62a17ae | 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. */ | |
49db7a7b | 91 | vrf_bitmap_t redist_default[AFI_MAX]; |
d62a17ae | 92 | |
d62a17ae | 93 | /* Router-id information. */ |
94 | vrf_bitmap_t ridinfo; | |
95 | ||
e1a1880d DS |
96 | bool notify_owner; |
97 | ||
d62a17ae | 98 | /* client's protocol */ |
d7c0a89a | 99 | uint8_t proto; |
453844ab | 100 | uint16_t instance; |
d7c0a89a | 101 | uint8_t is_synchronous; |
d62a17ae | 102 | |
103 | /* Statistics */ | |
d7c0a89a QY |
104 | uint32_t redist_v4_add_cnt; |
105 | uint32_t redist_v4_del_cnt; | |
106 | uint32_t redist_v6_add_cnt; | |
107 | uint32_t redist_v6_del_cnt; | |
108 | uint32_t v4_route_add_cnt; | |
109 | uint32_t v4_route_upd8_cnt; | |
110 | uint32_t v4_route_del_cnt; | |
111 | uint32_t v6_route_add_cnt; | |
112 | uint32_t v6_route_del_cnt; | |
113 | uint32_t v6_route_upd8_cnt; | |
114 | uint32_t connected_rt_add_cnt; | |
115 | uint32_t connected_rt_del_cnt; | |
116 | uint32_t ifup_cnt; | |
117 | uint32_t ifdown_cnt; | |
118 | uint32_t ifadd_cnt; | |
119 | uint32_t ifdel_cnt; | |
120 | uint32_t if_bfd_cnt; | |
121 | uint32_t bfd_peer_add_cnt; | |
122 | uint32_t bfd_peer_upd8_cnt; | |
123 | uint32_t bfd_peer_del_cnt; | |
124 | uint32_t bfd_peer_replay_cnt; | |
125 | uint32_t vrfadd_cnt; | |
126 | uint32_t vrfdel_cnt; | |
127 | uint32_t if_vrfchg_cnt; | |
128 | uint32_t bfd_client_reg_cnt; | |
129 | uint32_t vniadd_cnt; | |
130 | uint32_t vnidel_cnt; | |
131 | uint32_t l3vniadd_cnt; | |
132 | uint32_t l3vnidel_cnt; | |
133 | uint32_t macipadd_cnt; | |
134 | uint32_t macipdel_cnt; | |
135 | uint32_t prefixadd_cnt; | |
136 | uint32_t prefixdel_cnt; | |
ab5990d8 DS |
137 | uint32_t v4_nh_watch_add_cnt; |
138 | uint32_t v4_nh_watch_rem_cnt; | |
139 | uint32_t v6_nh_watch_add_cnt; | |
140 | uint32_t v6_nh_watch_rem_cnt; | |
4ab3321f AK |
141 | uint32_t vxlan_sg_add_cnt; |
142 | uint32_t vxlan_sg_del_cnt; | |
d62a17ae | 143 | |
d62a17ae | 144 | time_t nh_reg_time; |
145 | time_t nh_dereg_time; | |
146 | time_t nh_last_upd_time; | |
147 | ||
52f6868d QY |
148 | /* |
149 | * Session information. | |
150 | * | |
151 | * These are not synchronous with respect to each other. For instance, | |
152 | * last_read_cmd may contain a value that has been read in the future | |
153 | * relative to last_read_time. | |
154 | */ | |
155 | ||
156 | /* monotime of client creation */ | |
157 | _Atomic uint32_t connect_time; | |
158 | /* monotime of last message received */ | |
159 | _Atomic uint32_t last_read_time; | |
160 | /* monotime of last message sent */ | |
161 | _Atomic uint32_t last_write_time; | |
162 | /* command code of last message read */ | |
0545c373 | 163 | _Atomic uint32_t last_read_cmd; |
52f6868d | 164 | /* command code of last message written */ |
0545c373 | 165 | _Atomic uint32_t last_write_cmd; |
718e3744 | 166 | }; |
167 | ||
89f4e507 | 168 | #define ZAPI_HANDLER_ARGS \ |
1002497a QY |
169 | struct zserv *client, struct zmsghdr *hdr, struct stream *msg, \ |
170 | struct zebra_vrf *zvrf | |
89f4e507 | 171 | |
453844ab | 172 | /* Hooks for client connect / disconnect */ |
21ccc0cf QY |
173 | DECLARE_HOOK(zserv_client_connect, (struct zserv *client), (client)); |
174 | DECLARE_KOOH(zserv_client_close, (struct zserv *client), (client)); | |
453844ab | 175 | |
37fe7731 | 176 | extern unsigned int multipath_num; |
b21b19c5 | 177 | |
21ccc0cf QY |
178 | /* |
179 | * Initialize Zebra API server. | |
180 | * | |
181 | * Installs CLI commands and creates the client list. | |
182 | */ | |
5f145fb8 | 183 | extern void zserv_init(void); |
fb018d25 | 184 | |
41674562 DS |
185 | /* |
186 | * Stop the Zebra API server. | |
187 | * | |
188 | * closes the socket | |
189 | */ | |
190 | extern void zserv_close(void); | |
191 | ||
21ccc0cf QY |
192 | /* |
193 | * Start Zebra API server. | |
194 | * | |
195 | * Allocates resources, creates the server socket and begins listening on the | |
196 | * socket. | |
197 | * | |
198 | * path | |
199 | * where to place the Unix domain socket | |
200 | */ | |
201 | extern void zserv_start(char *path); | |
202 | ||
203 | /* | |
204 | * Send a message to a connected Zebra API client. | |
205 | * | |
206 | * client | |
207 | * the client to send to | |
208 | * | |
209 | * msg | |
210 | * the message to send | |
211 | */ | |
212 | extern int zserv_send_message(struct zserv *client, struct stream *msg); | |
213 | ||
214 | /* | |
215 | * Retrieve a client by its protocol and instance number. | |
216 | * | |
217 | * proto | |
218 | * protocol number | |
219 | * | |
220 | * instance | |
221 | * instance number | |
222 | * | |
223 | * Returns: | |
224 | * The Zebra API client. | |
225 | */ | |
226 | extern struct zserv *zserv_find_client(uint8_t proto, unsigned short instance); | |
8ed6821e | 227 | |
f3e33b69 QY |
228 | |
229 | /* | |
230 | * Close a client. | |
231 | * | |
232 | * Kills a client's thread, removes the client from the client list and cleans | |
233 | * up its resources. | |
234 | * | |
235 | * client | |
236 | * the client to close | |
237 | */ | |
238 | extern void zserv_close_client(struct zserv *client); | |
239 | ||
49b3b01f QY |
240 | |
241 | /* | |
242 | * Log a ZAPI message hexdump. | |
243 | * | |
244 | * errmsg | |
245 | * Error message to include with packet hexdump | |
246 | * | |
247 | * msg | |
248 | * Message to log | |
249 | * | |
250 | * hdr | |
251 | * Message header | |
252 | */ | |
253 | void zserv_log_message(const char *errmsg, struct stream *msg, | |
254 | struct zmsghdr *hdr); | |
255 | ||
411314ed DS |
256 | #if defined(HANDLE_ZAPI_FUZZING) |
257 | extern void zserv_read_file(char *input); | |
258 | #endif | |
259 | ||
4dfd7a02 MS |
260 | /* TODO */ |
261 | int zebra_finalize(struct thread *event); | |
262 | ||
51e94aa7 EDP |
263 | #ifdef __cplusplus |
264 | } | |
265 | #endif | |
266 | ||
718e3744 | 267 | #endif /* _ZEBRA_ZEBRA_H */ |