]>
Commit | Line | Data |
---|---|---|
718e3744 | 1 | /* Zebra's client header. |
2 | * Copyright (C) 1999 Kunihiro Ishiguro | |
3 | * | |
4 | * This file is part of GNU Zebra. | |
5 | * | |
6 | * GNU Zebra is free software; you can redistribute it and/or modify it | |
7 | * under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation; either version 2, or (at your option) | |
9 | * any later version. | |
896014f4 | 10 | * |
718e3744 | 11 | * GNU Zebra 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. | |
896014f4 DL |
15 | * |
16 | * You should have received a copy of the GNU General Public License along | |
17 | * with this program; see the file COPYING; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
718e3744 | 19 | */ |
20 | ||
21 | #ifndef _ZEBRA_ZCLIENT_H | |
22 | #define _ZEBRA_ZCLIENT_H | |
23 | ||
74489921 | 24 | /* For struct zapi_route. */ |
5734509c PJ |
25 | #include "prefix.h" |
26 | ||
718e3744 | 27 | /* For struct interface and struct connected. */ |
28 | #include "if.h" | |
29 | ||
7076bb2f FL |
30 | /* For vrf_bitmap_t. */ |
31 | #include "vrf.h" | |
32 | ||
6833ae01 | 33 | /* For union g_addr */ |
34 | #include "nexthop.h" | |
35 | ||
36 | /* For union pw_protocol_fields */ | |
37 | #include "pw.h" | |
38 | ||
02c0866d | 39 | #include "mlag.h" |
31f937fb | 40 | #include "srte.h" |
02c0866d | 41 | |
17e38209 RW |
42 | #ifdef __cplusplus |
43 | extern "C" { | |
44 | #endif | |
45 | ||
03edc41d DS |
46 | /* Zebra types. Used in Zserv message header. */ |
47 | typedef uint16_t zebra_size_t; | |
48 | ||
8ee06b2c DS |
49 | /* Marker value used in new Zserv, in the byte location corresponding |
50 | * the command value in the old zserv header. To allow old and new | |
51 | * Zserv headers to be distinguished from each other. | |
52 | */ | |
53 | #define ZEBRA_HEADER_MARKER 254 | |
54 | ||
718e3744 | 55 | /* For input/output buffer to zebra. */ |
f3f45626 | 56 | #define ZEBRA_MAX_PACKET_SIZ 16384U |
718e3744 | 57 | |
58 | /* Zebra header size. */ | |
a9ff90c4 | 59 | #define ZEBRA_HEADER_SIZE 10 |
718e3744 | 60 | |
689f5a8c DL |
61 | /* special socket path name to use TCP |
62 | * @ is used as first character because that's abstract socket names on Linux | |
63 | */ | |
64 | #define ZAPI_TCP_PATHNAME "@tcp" | |
65 | ||
7661461a PG |
66 | /* IPset size name stands for the name of the ipset entry |
67 | * that can be created by using some zapi interfaces | |
68 | */ | |
69 | #define ZEBRA_IPSET_NAME_SIZE 32 | |
70 | ||
7abd6c4f PG |
71 | /* IPTable action is defined by two values: either |
72 | * forward or drop | |
73 | */ | |
74 | #define ZEBRA_IPTABLES_FORWARD 0 | |
75 | #define ZEBRA_IPTABLES_DROP 1 | |
76 | ||
57592a53 AD |
77 | /* Zebra FEC register command flags. */ |
78 | #define ZEBRA_FEC_REGISTER_LABEL 0x1 | |
79 | #define ZEBRA_FEC_REGISTER_LABEL_INDEX 0x2 | |
80 | ||
be7bbe52 S |
81 | /* Client capabilities */ |
82 | enum zserv_client_capabilities { | |
83 | ZEBRA_CLIENT_GR_CAPABILITIES = 1, | |
84 | ZEBRA_CLIENT_ROUTE_UPDATE_COMPLETE = 2, | |
85 | ZEBRA_CLIENT_ROUTE_UPDATE_PENDING = 3, | |
86 | ZEBRA_CLIENT_GR_DISABLE = 4, | |
87 | ZEBRA_CLIENT_RIB_STALE_TIME | |
88 | }; | |
89 | ||
90 | /* Macro to check if there GR enabled. */ | |
91 | #define ZEBRA_CLIENT_GR_ENABLED(X) (X == ZEBRA_CLIENT_GR_CAPABILITIES) | |
eb451ee5 | 92 | |
31f937fb SM |
93 | #define ZEBRA_SR_POLICY_NAME_MAX_LENGTH 100 |
94 | ||
689f5a8c DL |
95 | extern struct sockaddr_storage zclient_addr; |
96 | extern socklen_t zclient_addr_len; | |
97 | ||
8613585e DS |
98 | /* Zebra message types. */ |
99 | typedef enum { | |
d62a17ae | 100 | ZEBRA_INTERFACE_ADD, |
101 | ZEBRA_INTERFACE_DELETE, | |
102 | ZEBRA_INTERFACE_ADDRESS_ADD, | |
103 | ZEBRA_INTERFACE_ADDRESS_DELETE, | |
104 | ZEBRA_INTERFACE_UP, | |
105 | ZEBRA_INTERFACE_DOWN, | |
e0ae31b8 | 106 | ZEBRA_INTERFACE_SET_MASTER, |
c3bd894e | 107 | ZEBRA_INTERFACE_SET_PROTODOWN, |
0e51b4a3 RW |
108 | ZEBRA_ROUTE_ADD, |
109 | ZEBRA_ROUTE_DELETE, | |
7ea7b86e | 110 | ZEBRA_ROUTE_NOTIFY_OWNER, |
d62a17ae | 111 | ZEBRA_REDISTRIBUTE_ADD, |
112 | ZEBRA_REDISTRIBUTE_DELETE, | |
113 | ZEBRA_REDISTRIBUTE_DEFAULT_ADD, | |
114 | ZEBRA_REDISTRIBUTE_DEFAULT_DELETE, | |
115 | ZEBRA_ROUTER_ID_ADD, | |
116 | ZEBRA_ROUTER_ID_DELETE, | |
117 | ZEBRA_ROUTER_ID_UPDATE, | |
118 | ZEBRA_HELLO, | |
09924cff | 119 | ZEBRA_CAPABILITIES, |
d62a17ae | 120 | ZEBRA_NEXTHOP_REGISTER, |
121 | ZEBRA_NEXTHOP_UNREGISTER, | |
122 | ZEBRA_NEXTHOP_UPDATE, | |
123 | ZEBRA_INTERFACE_NBR_ADDRESS_ADD, | |
124 | ZEBRA_INTERFACE_NBR_ADDRESS_DELETE, | |
125 | ZEBRA_INTERFACE_BFD_DEST_UPDATE, | |
126 | ZEBRA_IMPORT_ROUTE_REGISTER, | |
127 | ZEBRA_IMPORT_ROUTE_UNREGISTER, | |
128 | ZEBRA_IMPORT_CHECK_UPDATE, | |
d62a17ae | 129 | ZEBRA_BFD_DEST_REGISTER, |
130 | ZEBRA_BFD_DEST_DEREGISTER, | |
131 | ZEBRA_BFD_DEST_UPDATE, | |
132 | ZEBRA_BFD_DEST_REPLAY, | |
74489921 RW |
133 | ZEBRA_REDISTRIBUTE_ROUTE_ADD, |
134 | ZEBRA_REDISTRIBUTE_ROUTE_DEL, | |
d62a17ae | 135 | ZEBRA_VRF_UNREGISTER, |
136 | ZEBRA_VRF_ADD, | |
137 | ZEBRA_VRF_DELETE, | |
c83c5e44 | 138 | ZEBRA_VRF_LABEL, |
d62a17ae | 139 | ZEBRA_INTERFACE_VRF_UPDATE, |
140 | ZEBRA_BFD_CLIENT_REGISTER, | |
d3af6147 | 141 | ZEBRA_BFD_CLIENT_DEREGISTER, |
d62a17ae | 142 | ZEBRA_INTERFACE_ENABLE_RADV, |
143 | ZEBRA_INTERFACE_DISABLE_RADV, | |
144 | ZEBRA_IPV4_NEXTHOP_LOOKUP_MRIB, | |
145 | ZEBRA_INTERFACE_LINK_PARAMS, | |
146 | ZEBRA_MPLS_LABELS_ADD, | |
147 | ZEBRA_MPLS_LABELS_DELETE, | |
ea6b290b | 148 | ZEBRA_MPLS_LABELS_REPLACE, |
31f937fb SM |
149 | ZEBRA_SR_POLICY_SET, |
150 | ZEBRA_SR_POLICY_DELETE, | |
151 | ZEBRA_SR_POLICY_NOTIFY_STATUS, | |
d62a17ae | 152 | ZEBRA_IPMR_ROUTE_STATS, |
153 | ZEBRA_LABEL_MANAGER_CONNECT, | |
f533be73 | 154 | ZEBRA_LABEL_MANAGER_CONNECT_ASYNC, |
d62a17ae | 155 | ZEBRA_GET_LABEL_CHUNK, |
156 | ZEBRA_RELEASE_LABEL_CHUNK, | |
157 | ZEBRA_FEC_REGISTER, | |
158 | ZEBRA_FEC_UNREGISTER, | |
159 | ZEBRA_FEC_UPDATE, | |
1a98c087 | 160 | ZEBRA_ADVERTISE_DEFAULT_GW, |
fc08a52f | 161 | ZEBRA_ADVERTISE_SVI_MACIP, |
31310b25 | 162 | ZEBRA_ADVERTISE_SUBNET, |
d62a17ae | 163 | ZEBRA_ADVERTISE_ALL_VNI, |
50f74cf1 | 164 | ZEBRA_LOCAL_ES_ADD, |
165 | ZEBRA_LOCAL_ES_DEL, | |
ce5160c0 AK |
166 | ZEBRA_REMOTE_ES_VTEP_ADD, |
167 | ZEBRA_REMOTE_ES_VTEP_DEL, | |
168 | ZEBRA_LOCAL_ES_EVI_ADD, | |
169 | ZEBRA_LOCAL_ES_EVI_DEL, | |
d62a17ae | 170 | ZEBRA_VNI_ADD, |
171 | ZEBRA_VNI_DEL, | |
b7cfce93 MK |
172 | ZEBRA_L3VNI_ADD, |
173 | ZEBRA_L3VNI_DEL, | |
d62a17ae | 174 | ZEBRA_REMOTE_VTEP_ADD, |
175 | ZEBRA_REMOTE_VTEP_DEL, | |
176 | ZEBRA_MACIP_ADD, | |
177 | ZEBRA_MACIP_DEL, | |
31310b25 MK |
178 | ZEBRA_IP_PREFIX_ROUTE_ADD, |
179 | ZEBRA_IP_PREFIX_ROUTE_DEL, | |
d62a17ae | 180 | ZEBRA_REMOTE_MACIP_ADD, |
181 | ZEBRA_REMOTE_MACIP_DEL, | |
3950b52c | 182 | ZEBRA_DUPLICATE_ADDR_DETECTION, |
6833ae01 | 183 | ZEBRA_PW_ADD, |
184 | ZEBRA_PW_DELETE, | |
185 | ZEBRA_PW_SET, | |
186 | ZEBRA_PW_UNSET, | |
187 | ZEBRA_PW_STATUS_UPDATE, | |
e16abbb3 DS |
188 | ZEBRA_RULE_ADD, |
189 | ZEBRA_RULE_DELETE, | |
190 | ZEBRA_RULE_NOTIFY_OWNER, | |
75fb51c1 PG |
191 | ZEBRA_TABLE_MANAGER_CONNECT, |
192 | ZEBRA_GET_TABLE_CHUNK, | |
193 | ZEBRA_RELEASE_TABLE_CHUNK, | |
d59c13af PG |
194 | ZEBRA_IPSET_CREATE, |
195 | ZEBRA_IPSET_DESTROY, | |
196 | ZEBRA_IPSET_ENTRY_ADD, | |
197 | ZEBRA_IPSET_ENTRY_DELETE, | |
425bdd6b PG |
198 | ZEBRA_IPSET_NOTIFY_OWNER, |
199 | ZEBRA_IPSET_ENTRY_NOTIFY_OWNER, | |
7abd6c4f PG |
200 | ZEBRA_IPTABLE_ADD, |
201 | ZEBRA_IPTABLE_DELETE, | |
202 | ZEBRA_IPTABLE_NOTIFY_OWNER, | |
fbac9605 | 203 | ZEBRA_VXLAN_FLOOD_CONTROL, |
4ab3321f AK |
204 | ZEBRA_VXLAN_SG_ADD, |
205 | ZEBRA_VXLAN_SG_DEL, | |
ecbbc3a7 | 206 | ZEBRA_VXLAN_SG_REPLAY, |
46c2687c SK |
207 | ZEBRA_MLAG_PROCESS_UP, |
208 | ZEBRA_MLAG_PROCESS_DOWN, | |
36b5b98f SK |
209 | ZEBRA_MLAG_CLIENT_REGISTER, |
210 | ZEBRA_MLAG_CLIENT_UNREGISTER, | |
211 | ZEBRA_MLAG_FORWARD_MSG, | |
9ab0b2a3 | 212 | ZEBRA_ERROR, |
ff491140 MS |
213 | ZEBRA_CLIENT_CAPABILITIES, |
214 | ZEBRA_OPAQUE_MESSAGE, | |
215 | ZEBRA_OPAQUE_REGISTER, | |
216 | ZEBRA_OPAQUE_UNREGISTER, | |
8613585e DS |
217 | } zebra_message_types_t; |
218 | ||
9ab0b2a3 | 219 | enum zebra_error_types { |
be7bbe52 | 220 | ZEBRA_UNKNOWN_ERROR, /* Error of unknown type */ |
9ab0b2a3 SW |
221 | ZEBRA_NO_VRF, /* Vrf in header was not found */ |
222 | ZEBRA_INVALID_MSG_TYPE, /* No handler found for msg type */ | |
223 | }; | |
224 | ||
225 | static inline const char *zebra_error_type2str(enum zebra_error_types type) | |
226 | { | |
227 | const char *ret = "UNKNOWN"; | |
228 | ||
229 | switch (type) { | |
230 | case ZEBRA_UNKNOWN_ERROR: | |
231 | ret = "ZEBRA_UNKNOWN_ERROR"; | |
232 | break; | |
233 | case ZEBRA_NO_VRF: | |
234 | ret = "ZEBRA_NO_VRF"; | |
235 | break; | |
236 | case ZEBRA_INVALID_MSG_TYPE: | |
237 | ret = "ZEBRA_INVALID_MSG_TYPE"; | |
238 | break; | |
239 | } | |
240 | ||
241 | return ret; | |
242 | } | |
243 | ||
d62a17ae | 244 | struct redist_proto { |
d7c0a89a | 245 | uint8_t enabled; |
d62a17ae | 246 | struct list *instances; |
7c8ff89e DS |
247 | }; |
248 | ||
09924cff DS |
249 | struct zclient_capabilities { |
250 | uint32_t ecmp; | |
251 | bool mpls_enabled; | |
02c0866d | 252 | enum mlag_role role; |
09924cff DS |
253 | }; |
254 | ||
eb451ee5 | 255 | /* Graceful Restart Capabilities message */ |
256 | struct zapi_cap { | |
be7bbe52 S |
257 | enum zserv_client_capabilities cap; |
258 | uint32_t stale_removal_time; | |
259 | afi_t afi; | |
260 | safi_t safi; | |
261 | vrf_id_t vrf_id; | |
eb451ee5 | 262 | }; |
263 | ||
718e3744 | 264 | /* Structure for the zebra client. */ |
d62a17ae | 265 | struct zclient { |
266 | /* The thread master we schedule ourselves on */ | |
267 | struct thread_master *master; | |
268 | ||
342213ea DS |
269 | /* Priviledges to change socket values */ |
270 | struct zebra_privs_t *privs; | |
271 | ||
e1a1880d DS |
272 | /* Do we care about failure events for route install? */ |
273 | bool receive_notify; | |
274 | ||
17da84a4 KS |
275 | /* Is this a synchronous client? */ |
276 | bool synchronous; | |
277 | ||
4e0b5b31 MS |
278 | /* Session id (optional) to support clients with multiple sessions */ |
279 | uint32_t session_id; | |
280 | ||
d62a17ae | 281 | /* Socket to zebra daemon. */ |
282 | int sock; | |
283 | ||
d62a17ae | 284 | /* Connection failure count. */ |
285 | int fail; | |
286 | ||
287 | /* Input buffer for zebra message. */ | |
288 | struct stream *ibuf; | |
289 | ||
290 | /* Output buffer for zebra message. */ | |
291 | struct stream *obuf; | |
292 | ||
293 | /* Buffer of data waiting to be written to zebra. */ | |
294 | struct buffer *wb; | |
295 | ||
296 | /* Read and connect thread. */ | |
297 | struct thread *t_read; | |
298 | struct thread *t_connect; | |
299 | ||
300 | /* Thread to write buffered data to zebra. */ | |
301 | struct thread *t_write; | |
302 | ||
303 | /* Redistribute information. */ | |
d7c0a89a QY |
304 | uint8_t redist_default; /* clients protocol */ |
305 | unsigned short instance; | |
d62a17ae | 306 | struct redist_proto mi_redist[AFI_MAX][ZEBRA_ROUTE_MAX]; |
307 | vrf_bitmap_t redist[AFI_MAX][ZEBRA_ROUTE_MAX]; | |
308 | ||
309 | /* Redistribute defauilt. */ | |
49db7a7b | 310 | vrf_bitmap_t default_information[AFI_MAX]; |
d62a17ae | 311 | |
6c33ca97 QY |
312 | #define ZAPI_CALLBACK_ARGS \ |
313 | int cmd, struct zclient *zclient, uint16_t length, vrf_id_t vrf_id | |
314 | ||
d62a17ae | 315 | /* Pointer to the callback functions. */ |
316 | void (*zebra_connected)(struct zclient *); | |
09924cff | 317 | void (*zebra_capabilities)(struct zclient_capabilities *cap); |
6c33ca97 | 318 | int (*router_id_update)(ZAPI_CALLBACK_ARGS); |
6c33ca97 QY |
319 | int (*interface_address_add)(ZAPI_CALLBACK_ARGS); |
320 | int (*interface_address_delete)(ZAPI_CALLBACK_ARGS); | |
321 | int (*interface_link_params)(ZAPI_CALLBACK_ARGS); | |
322 | int (*interface_bfd_dest_update)(ZAPI_CALLBACK_ARGS); | |
323 | int (*interface_nbr_address_add)(ZAPI_CALLBACK_ARGS); | |
324 | int (*interface_nbr_address_delete)(ZAPI_CALLBACK_ARGS); | |
325 | int (*interface_vrf_update)(ZAPI_CALLBACK_ARGS); | |
326 | int (*nexthop_update)(ZAPI_CALLBACK_ARGS); | |
327 | int (*import_check_update)(ZAPI_CALLBACK_ARGS); | |
328 | int (*bfd_dest_replay)(ZAPI_CALLBACK_ARGS); | |
329 | int (*redistribute_route_add)(ZAPI_CALLBACK_ARGS); | |
330 | int (*redistribute_route_del)(ZAPI_CALLBACK_ARGS); | |
d62a17ae | 331 | int (*fec_update)(int, struct zclient *, uint16_t); |
6c33ca97 QY |
332 | int (*local_es_add)(ZAPI_CALLBACK_ARGS); |
333 | int (*local_es_del)(ZAPI_CALLBACK_ARGS); | |
ce5160c0 AK |
334 | int (*local_es_evi_add)(ZAPI_CALLBACK_ARGS); |
335 | int (*local_es_evi_del)(ZAPI_CALLBACK_ARGS); | |
6c33ca97 QY |
336 | int (*local_vni_add)(ZAPI_CALLBACK_ARGS); |
337 | int (*local_vni_del)(ZAPI_CALLBACK_ARGS); | |
338 | int (*local_l3vni_add)(ZAPI_CALLBACK_ARGS); | |
339 | int (*local_l3vni_del)(ZAPI_CALLBACK_ARGS); | |
340 | void (*local_ip_prefix_add)(ZAPI_CALLBACK_ARGS); | |
341 | void (*local_ip_prefix_del)(ZAPI_CALLBACK_ARGS); | |
342 | int (*local_macip_add)(ZAPI_CALLBACK_ARGS); | |
343 | int (*local_macip_del)(ZAPI_CALLBACK_ARGS); | |
344 | int (*pw_status_update)(ZAPI_CALLBACK_ARGS); | |
345 | int (*route_notify_owner)(ZAPI_CALLBACK_ARGS); | |
346 | int (*rule_notify_owner)(ZAPI_CALLBACK_ARGS); | |
347 | void (*label_chunk)(ZAPI_CALLBACK_ARGS); | |
348 | int (*ipset_notify_owner)(ZAPI_CALLBACK_ARGS); | |
349 | int (*ipset_entry_notify_owner)(ZAPI_CALLBACK_ARGS); | |
350 | int (*iptable_notify_owner)(ZAPI_CALLBACK_ARGS); | |
351 | int (*vxlan_sg_add)(ZAPI_CALLBACK_ARGS); | |
352 | int (*vxlan_sg_del)(ZAPI_CALLBACK_ARGS); | |
46c2687c SK |
353 | int (*mlag_process_up)(void); |
354 | int (*mlag_process_down)(void); | |
355 | int (*mlag_handle_msg)(struct stream *msg, int len); | |
9ab0b2a3 | 356 | int (*handle_error)(enum zebra_error_types error); |
ff491140 MS |
357 | int (*opaque_msg_handler)(ZAPI_CALLBACK_ARGS); |
358 | int (*opaque_register_handler)(ZAPI_CALLBACK_ARGS); | |
359 | int (*opaque_unregister_handler)(ZAPI_CALLBACK_ARGS); | |
31f937fb | 360 | int (*sr_policy_notify_status)(ZAPI_CALLBACK_ARGS); |
718e3744 | 361 | }; |
362 | ||
363 | /* Zebra API message flag. */ | |
364 | #define ZAPI_MESSAGE_NEXTHOP 0x01 | |
74489921 RW |
365 | #define ZAPI_MESSAGE_DISTANCE 0x02 |
366 | #define ZAPI_MESSAGE_METRIC 0x04 | |
367 | #define ZAPI_MESSAGE_TAG 0x08 | |
368 | #define ZAPI_MESSAGE_MTU 0x10 | |
369 | #define ZAPI_MESSAGE_SRCPFX 0x20 | |
018c6488 MS |
370 | /* Backup nexthops are present */ |
371 | #define ZAPI_MESSAGE_BACKUP_NEXTHOPS 0x40 | |
372 | ||
ba1849ef DS |
373 | /* |
374 | * This should only be used by a DAEMON that needs to communicate | |
375 | * the table being used is not in the VRF. You must pass the | |
376 | * default vrf, else this will be ignored. | |
377 | */ | |
31f937fb SM |
378 | #define ZAPI_MESSAGE_TABLEID 0x0080 |
379 | #define ZAPI_MESSAGE_SRTE 0x0100 | |
718e3744 | 380 | |
04772760 | 381 | #define ZSERV_VERSION 6 |
c1b9800a | 382 | /* Zserv protocol message header */ |
124ead27 | 383 | struct zmsghdr { |
d62a17ae | 384 | uint16_t length; |
5530922e | 385 | /* Always set to 255 in new zserv */ |
124ead27 | 386 | uint8_t marker; |
d62a17ae | 387 | uint8_t version; |
d62a17ae | 388 | vrf_id_t vrf_id; |
389 | uint16_t command; | |
6e8e0925 DS |
390 | } __attribute__((packed)); |
391 | #define ZAPI_HEADER_CMD_LOCATION offsetof(struct zmsghdr, command) | |
c1b9800a | 392 | |
bb1b9c47 RW |
393 | struct zapi_nexthop { |
394 | enum nexthop_types_t type; | |
4a7371e9 | 395 | vrf_id_t vrf_id; |
bb1b9c47 | 396 | ifindex_t ifindex; |
68a02e06 | 397 | uint8_t flags; |
09a484dd DL |
398 | union { |
399 | union g_addr gate; | |
400 | enum blackhole_type bh_type; | |
401 | }; | |
52dd3aa4 RW |
402 | |
403 | /* MPLS labels for BGP-LU or Segment Routing */ | |
404 | uint8_t label_num; | |
405 | mpls_label_t labels[MPLS_MAX_LABELS]; | |
a317a9b9 | 406 | |
407 | struct ethaddr rmac; | |
bd054c1a DS |
408 | |
409 | uint32_t weight; | |
018c6488 | 410 | |
474aebd9 MS |
411 | /* Backup nexthops, for IP-FRR, TI-LFA, etc */ |
412 | uint8_t backup_num; | |
413 | uint8_t backup_idx[NEXTHOP_MAX_BACKUPS]; | |
31f937fb SM |
414 | |
415 | /* SR-TE color. */ | |
416 | uint32_t srte_color; | |
bb1b9c47 RW |
417 | }; |
418 | ||
68a02e06 | 419 | /* |
018c6488 MS |
420 | * ZAPI nexthop flags values - we're encoding a single octet |
421 | * initially, so ensure that the on-the-wire encoding continues | |
422 | * to match the number of valid flags. | |
68a02e06 | 423 | */ |
018c6488 | 424 | |
68a02e06 MS |
425 | #define ZAPI_NEXTHOP_FLAG_ONLINK 0x01 |
426 | #define ZAPI_NEXTHOP_FLAG_LABEL 0x02 | |
bd054c1a | 427 | #define ZAPI_NEXTHOP_FLAG_WEIGHT 0x04 |
018c6488 | 428 | #define ZAPI_NEXTHOP_FLAG_HAS_BACKUP 0x08 /* Nexthop has a backup */ |
68a02e06 | 429 | |
832d0f56 DS |
430 | /* |
431 | * Some of these data structures do not map easily to | |
432 | * a actual data structure size giving different compilers | |
433 | * and systems. For those data structures we need | |
434 | * to use the smallest available stream_getX/putX functions | |
435 | * to encode/decode. | |
436 | */ | |
d62a17ae | 437 | struct zapi_route { |
d7c0a89a QY |
438 | uint8_t type; |
439 | unsigned short instance; | |
657cde12 | 440 | |
d7c0a89a | 441 | uint32_t flags; |
da01a37a DS |
442 | /* |
443 | * Cause Zebra to consider this routes nexthops recursively | |
444 | */ | |
445 | #define ZEBRA_FLAG_ALLOW_RECURSION 0x01 | |
446 | /* | |
447 | * This is a route that is read in on startup that was left around | |
448 | * from a previous run of FRR | |
449 | */ | |
450 | #define ZEBRA_FLAG_SELFROUTE 0x02 | |
451 | /* | |
452 | * This flag is used to tell Zebra that the BGP route being passed | |
453 | * down is a IBGP route | |
454 | */ | |
455 | #define ZEBRA_FLAG_IBGP 0x04 | |
456 | /* | |
457 | * This is a route that has been selected for FIB installation. | |
458 | * This flag is set in zebra and can be passed up to routing daemons | |
459 | */ | |
460 | #define ZEBRA_FLAG_SELECTED 0x08 | |
461 | /* | |
462 | * This is a route that we are telling Zebra that this route *must* | |
463 | * win and will be installed even over ZEBRA_FLAG_SELECTED | |
464 | */ | |
465 | #define ZEBRA_FLAG_FIB_OVERRIDE 0x10 | |
466 | /* | |
467 | * This flag tells Zebra that the route is a EVPN route and should | |
468 | * be treated specially | |
469 | */ | |
470 | #define ZEBRA_FLAG_EVPN_ROUTE 0x20 | |
471 | /* | |
472 | * This flag tells Zebra that it should treat the distance passed | |
473 | * down as an additional discriminator for route selection of the | |
474 | * route entry. This mainly is used for backup static routes. | |
475 | */ | |
476 | #define ZEBRA_FLAG_RR_USE_DISTANCE 0x40 | |
657cde12 | 477 | |
387831ff | 478 | /* The older XXX_MESSAGE flags live here */ |
31f937fb | 479 | uint32_t message; |
657cde12 | 480 | |
832d0f56 DS |
481 | /* |
482 | * This is an enum but we are going to treat it as a uint8_t | |
483 | * for purpose of encoding/decoding | |
484 | */ | |
d62a17ae | 485 | safi_t safi; |
657cde12 | 486 | |
bb1b9c47 RW |
487 | struct prefix prefix; |
488 | struct prefix_ipv6 src_prefix; | |
489 | ||
d7c0a89a | 490 | uint16_t nexthop_num; |
bb1b9c47 | 491 | struct zapi_nexthop nexthops[MULTIPATH_NUM]; |
657cde12 | 492 | |
018c6488 MS |
493 | /* Support backup routes for IP FRR, TI-LFA, traffic engineering */ |
494 | uint16_t backup_nexthop_num; | |
495 | struct zapi_nexthop backup_nexthops[MULTIPATH_NUM]; | |
496 | ||
d7c0a89a | 497 | uint8_t distance; |
657cde12 | 498 | |
d7c0a89a | 499 | uint32_t metric; |
657cde12 | 500 | |
d62a17ae | 501 | route_tag_t tag; |
657cde12 | 502 | |
d7c0a89a | 503 | uint32_t mtu; |
657cde12 | 504 | |
d62a17ae | 505 | vrf_id_t vrf_id; |
2dbad57f | 506 | |
ba1849ef | 507 | uint32_t tableid; |
31f937fb SM |
508 | |
509 | /* SR-TE color (used for nexthop updates only). */ | |
510 | uint32_t srte_color; | |
657cde12 DS |
511 | }; |
512 | ||
bad6b0e7 | 513 | struct zapi_labels { |
b3c49d0e | 514 | uint8_t message; |
34f86754 MS |
515 | #define ZAPI_LABELS_FTN 0x01 |
516 | #define ZAPI_LABELS_HAS_BACKUPS 0x02 | |
bad6b0e7 | 517 | enum lsp_types_t type; |
bad6b0e7 | 518 | mpls_label_t local_label; |
b3c49d0e RW |
519 | struct { |
520 | struct prefix prefix; | |
521 | uint8_t type; | |
522 | unsigned short instance; | |
523 | } route; | |
4945002d | 524 | |
ea6b290b | 525 | uint16_t nexthop_num; |
4945002d | 526 | struct zapi_nexthop nexthops[MULTIPATH_NUM]; |
34f86754 MS |
527 | |
528 | /* Backup nexthops, if present */ | |
529 | uint16_t backup_nexthop_num; | |
530 | struct zapi_nexthop backup_nexthops[MULTIPATH_NUM]; | |
bad6b0e7 RW |
531 | }; |
532 | ||
31f937fb SM |
533 | struct zapi_srte_tunnel { |
534 | enum lsp_types_t type; | |
535 | mpls_label_t local_label; | |
536 | uint8_t label_num; | |
537 | mpls_label_t labels[MPLS_MAX_LABELS]; | |
538 | }; | |
539 | ||
540 | struct zapi_sr_policy { | |
541 | uint32_t color; | |
542 | struct ipaddr endpoint; | |
543 | char name[SRTE_POLICY_NAME_MAX_LENGTH]; | |
544 | struct zapi_srte_tunnel segment_list; | |
545 | int status; | |
546 | }; | |
547 | ||
6833ae01 | 548 | struct zapi_pw { |
549 | char ifname[IF_NAMESIZE]; | |
550 | ifindex_t ifindex; | |
551 | int type; | |
552 | int af; | |
553 | union g_addr nexthop; | |
554 | uint32_t local_label; | |
555 | uint32_t remote_label; | |
556 | uint8_t flags; | |
557 | union pw_protocol_fields data; | |
558 | uint8_t protocol; | |
559 | }; | |
560 | ||
561 | struct zapi_pw_status { | |
562 | char ifname[IF_NAMESIZE]; | |
563 | ifindex_t ifindex; | |
564 | uint32_t status; | |
565 | }; | |
566 | ||
7ea7b86e DS |
567 | enum zapi_route_notify_owner { |
568 | ZAPI_ROUTE_FAIL_INSTALL, | |
569 | ZAPI_ROUTE_BETTER_ADMIN_WON, | |
570 | ZAPI_ROUTE_INSTALLED, | |
5e54c602 DS |
571 | ZAPI_ROUTE_REMOVED, |
572 | ZAPI_ROUTE_REMOVE_FAIL, | |
7ea7b86e DS |
573 | }; |
574 | ||
0031a6bb PG |
575 | enum zapi_rule_notify_owner { |
576 | ZAPI_RULE_FAIL_INSTALL, | |
577 | ZAPI_RULE_INSTALLED, | |
578 | ZAPI_RULE_REMOVED, | |
34d9d5be | 579 | ZAPI_RULE_FAIL_REMOVE, |
0031a6bb PG |
580 | }; |
581 | ||
7661461a PG |
582 | enum ipset_type { |
583 | IPSET_NET_NET = 1, | |
584 | IPSET_NET_PORT_NET, | |
585 | IPSET_NET_PORT, | |
586 | IPSET_NET | |
587 | }; | |
588 | ||
425bdd6b PG |
589 | enum zapi_ipset_notify_owner { |
590 | ZAPI_IPSET_FAIL_INSTALL, | |
591 | ZAPI_IPSET_INSTALLED, | |
592 | ZAPI_IPSET_REMOVED, | |
34d9d5be | 593 | ZAPI_IPSET_FAIL_REMOVE, |
425bdd6b PG |
594 | }; |
595 | ||
596 | enum zapi_ipset_entry_notify_owner { | |
597 | ZAPI_IPSET_ENTRY_FAIL_INSTALL, | |
598 | ZAPI_IPSET_ENTRY_INSTALLED, | |
599 | ZAPI_IPSET_ENTRY_REMOVED, | |
34d9d5be | 600 | ZAPI_IPSET_ENTRY_FAIL_REMOVE, |
425bdd6b PG |
601 | }; |
602 | ||
7abd6c4f PG |
603 | enum zapi_iptable_notify_owner { |
604 | ZAPI_IPTABLE_FAIL_INSTALL, | |
605 | ZAPI_IPTABLE_INSTALLED, | |
606 | ZAPI_IPTABLE_REMOVED, | |
34d9d5be | 607 | ZAPI_IPTABLE_FAIL_REMOVE, |
7abd6c4f PG |
608 | }; |
609 | ||
eb5d458b SW |
610 | static inline const char * |
611 | zapi_rule_notify_owner2str(enum zapi_rule_notify_owner note) | |
612 | { | |
613 | const char *ret = "UNKNOWN"; | |
614 | ||
615 | switch (note) { | |
616 | case ZAPI_RULE_FAIL_INSTALL: | |
617 | ret = "ZAPI_RULE_FAIL_INSTALL"; | |
618 | break; | |
619 | case ZAPI_RULE_INSTALLED: | |
620 | ret = "ZAPI_RULE_INSTALLED"; | |
621 | break; | |
622 | case ZAPI_RULE_FAIL_REMOVE: | |
623 | ret = "ZAPI_RULE_FAIL_REMOVE"; | |
624 | break; | |
625 | case ZAPI_RULE_REMOVED: | |
626 | ret = "ZAPI_RULE_REMOVED"; | |
627 | break; | |
628 | } | |
629 | ||
630 | return ret; | |
631 | } | |
632 | ||
1a98c087 | 633 | /* Zebra MAC types */ |
ead40654 MK |
634 | #define ZEBRA_MACIP_TYPE_STICKY 0x01 /* Sticky MAC*/ |
635 | #define ZEBRA_MACIP_TYPE_GW 0x02 /* gateway (SVI) mac*/ | |
68e33151 CS |
636 | #define ZEBRA_MACIP_TYPE_ROUTER_FLAG 0x04 /* Router Flag - proxy NA */ |
637 | #define ZEBRA_MACIP_TYPE_OVERRIDE_FLAG 0x08 /* Override Flag */ | |
0ca10580 | 638 | #define ZEBRA_MACIP_TYPE_SVI_IP 0x10 /* SVI MAC-IP */ |
d0f699b5 AK |
639 | #define ZEBRA_MACIP_TYPE_PROXY_ADVERT 0x20 /* Not locally active */ |
640 | #define ZEBRA_MACIP_TYPE_SYNC_PATH 0x40 /* sync path */ | |
641 | /* XXX - flags is an u8; that needs to be changed to u32 if you need | |
642 | * to allocate past 0x80 | |
643 | */ | |
1a98c087 | 644 | |
2c476b72 AK |
645 | enum zebra_neigh_state { ZEBRA_NEIGH_INACTIVE = 0, ZEBRA_NEIGH_ACTIVE = 1 }; |
646 | ||
e1a1880d DS |
647 | struct zclient_options { |
648 | bool receive_notify; | |
17da84a4 | 649 | bool synchronous; |
e1a1880d DS |
650 | }; |
651 | ||
e1a1880d DS |
652 | extern struct zclient_options zclient_options_default; |
653 | ||
26f63a1e DS |
654 | extern struct zclient *zclient_new(struct thread_master *m, |
655 | struct zclient_options *opt); | |
e1a1880d | 656 | |
d7c0a89a | 657 | extern void zclient_init(struct zclient *, int, unsigned short, |
996c9314 | 658 | struct zebra_privs_t *privs); |
d62a17ae | 659 | extern int zclient_start(struct zclient *); |
660 | extern void zclient_stop(struct zclient *); | |
661 | extern void zclient_reset(struct zclient *); | |
662 | extern void zclient_free(struct zclient *); | |
634f9ea2 | 663 | |
d62a17ae | 664 | extern int zclient_socket_connect(struct zclient *); |
718e3744 | 665 | |
d7c0a89a QY |
666 | extern unsigned short *redist_check_instance(struct redist_proto *, |
667 | unsigned short); | |
668 | extern void redist_add_instance(struct redist_proto *, unsigned short); | |
669 | extern void redist_del_instance(struct redist_proto *, unsigned short); | |
24c370dd | 670 | extern void redist_del_all_instances(struct redist_proto *red); |
7c8ff89e | 671 | |
c83c5e44 DS |
672 | /* |
673 | * Send to zebra that the specified vrf is using label to resolve | |
674 | * itself for L3VPN's. Repeated calls of this function with | |
675 | * different labels will cause an effective update of the | |
42567e00 | 676 | * label for lookup. If you pass in MPLS_LABEL_NONE |
c83c5e44 DS |
677 | * we will cause a delete action and remove this label pop |
678 | * operation. | |
7d061b3c DS |
679 | * |
680 | * The underlying AF_MPLS doesn't care about afi's | |
681 | * but we can make the zebra_vrf keep track of what | |
682 | * we have installed and play some special games | |
683 | * to get them both installed. | |
c83c5e44 DS |
684 | */ |
685 | extern void zclient_send_vrf_label(struct zclient *zclient, vrf_id_t vrf_id, | |
7d061b3c DS |
686 | afi_t afi, mpls_label_t label, |
687 | enum lsp_types_t ltype); | |
c83c5e44 | 688 | |
d62a17ae | 689 | extern void zclient_send_reg_requests(struct zclient *, vrf_id_t); |
690 | extern void zclient_send_dereg_requests(struct zclient *, vrf_id_t); | |
7076bb2f | 691 | |
d62a17ae | 692 | extern void zclient_send_interface_radv_req(struct zclient *zclient, |
693 | vrf_id_t vrf_id, | |
694 | struct interface *ifp, int enable, | |
695 | int ra_interval); | |
c3bd894e QY |
696 | extern int zclient_send_interface_protodown(struct zclient *zclient, |
697 | vrf_id_t vrf_id, | |
698 | struct interface *ifp, bool down); | |
4a04e5f7 | 699 | |
634f9ea2 | 700 | /* Send redistribute command to zebra daemon. Do not update zclient state. */ |
d62a17ae | 701 | extern int zebra_redistribute_send(int command, struct zclient *, afi_t, |
d7c0a89a QY |
702 | int type, unsigned short instance, |
703 | vrf_id_t vrf_id); | |
634f9ea2 | 704 | |
49db7a7b RW |
705 | extern int zebra_redistribute_default_send(int command, struct zclient *zclient, |
706 | afi_t afi, vrf_id_t vrf_id); | |
707 | ||
634f9ea2 | 708 | /* If state has changed, update state and call zebra_redistribute_send. */ |
d62a17ae | 709 | extern void zclient_redistribute(int command, struct zclient *, afi_t, int type, |
d7c0a89a | 710 | unsigned short instance, vrf_id_t vrf_id); |
634f9ea2 | 711 | |
712 | /* If state has changed, update state and send the command to zebra. */ | |
d62a17ae | 713 | extern void zclient_redistribute_default(int command, struct zclient *, |
49db7a7b | 714 | afi_t, vrf_id_t vrf_id); |
718e3744 | 715 | |
634f9ea2 | 716 | /* Send the message in zclient->obuf to the zebra daemon (or enqueue it). |
717 | Returns 0 for success or -1 on an I/O error. */ | |
718 | extern int zclient_send_message(struct zclient *); | |
718e3744 | 719 | |
d211086a | 720 | /* create header for command, length to be filled in by user later */ |
d62a17ae | 721 | extern void zclient_create_header(struct stream *, uint16_t, vrf_id_t); |
124ead27 QY |
722 | /* |
723 | * Read sizeof(struct zmsghdr) bytes from the provided socket and parse the | |
724 | * received data into the specified fields. If this is successful, read the | |
725 | * rest of the packet into the provided stream. | |
726 | * | |
727 | * s | |
728 | * The stream to read into | |
729 | * | |
730 | * sock | |
731 | * The socket to read from | |
732 | * | |
733 | * size | |
734 | * Parsed message size will be placed in the pointed-at integer | |
735 | * | |
736 | * marker | |
737 | * Parsed marker will be placed in the pointed-at byte | |
738 | * | |
739 | * version | |
740 | * Parsed version will be placed in the pointed-at byte | |
741 | * | |
742 | * vrf_id | |
743 | * Parsed VRF ID will be placed in the pointed-at vrf_id_t | |
744 | * | |
745 | * cmd | |
746 | * Parsed command number will be placed in the pointed-at integer | |
747 | * | |
748 | * Returns: | |
749 | * -1 if: | |
750 | * - insufficient data for header was read | |
751 | * - a version mismatch was detected | |
752 | * - a marker mismatch was detected | |
753 | * - header size field specified more data than could be read | |
754 | */ | |
d7c0a89a QY |
755 | extern int zclient_read_header(struct stream *s, int sock, uint16_t *size, |
756 | uint8_t *marker, uint8_t *version, | |
757 | vrf_id_t *vrf_id, uint16_t *cmd); | |
124ead27 QY |
758 | /* |
759 | * Parse header from ZAPI message stream into struct zmsghdr. | |
760 | * This function assumes the stream getp points at the first byte of the header. | |
761 | * If the function is successful then the stream getp will point to the byte | |
762 | * immediately after the last byte of the header. | |
763 | * | |
764 | * zmsg | |
765 | * The stream containing the header | |
766 | * | |
767 | * hdr | |
768 | * The header struct to parse into. | |
769 | * | |
770 | * Returns: | |
771 | * true if parsing succeeded, false otherwise | |
772 | */ | |
773 | extern bool zapi_parse_header(struct stream *zmsg, struct zmsghdr *hdr); | |
d62a17ae | 774 | |
e0ae31b8 DS |
775 | extern void zclient_interface_set_master(struct zclient *client, |
776 | struct interface *master, | |
777 | struct interface *slave); | |
d62a17ae | 778 | extern struct interface *zebra_interface_state_read(struct stream *s, vrf_id_t); |
779 | extern struct connected *zebra_interface_address_read(int, struct stream *, | |
780 | vrf_id_t); | |
781 | extern struct nbr_connected * | |
782 | zebra_interface_nbr_address_read(int, struct stream *, vrf_id_t); | |
783 | extern struct interface *zebra_interface_vrf_update_read(struct stream *s, | |
784 | vrf_id_t vrf_id, | |
785 | vrf_id_t *new_vrf_id); | |
efc7191b | 786 | extern int zebra_router_id_update_read(struct stream *s, struct prefix *rid); |
0cb76b9d | 787 | |
edc12762 RW |
788 | extern struct interface *zebra_interface_link_params_read(struct stream *s, |
789 | vrf_id_t vrf_id); | |
d62a17ae | 790 | extern size_t zebra_interface_link_params_write(struct stream *, |
791 | struct interface *); | |
0e3b6a92 EDP |
792 | extern int zclient_send_get_label_chunk(struct zclient *zclient, uint8_t keep, |
793 | uint32_t chunk_size, uint32_t base); | |
955bfd98 | 794 | |
f533be73 | 795 | extern int lm_label_manager_connect(struct zclient *zclient, int async); |
d7c0a89a | 796 | extern int lm_get_label_chunk(struct zclient *zclient, uint8_t keep, |
0e3b6a92 EDP |
797 | uint32_t base, uint32_t chunk_size, |
798 | uint32_t *start, uint32_t *end); | |
d62a17ae | 799 | extern int lm_release_label_chunk(struct zclient *zclient, uint32_t start, |
800 | uint32_t end); | |
75fb51c1 PG |
801 | extern int tm_table_manager_connect(struct zclient *zclient); |
802 | extern int tm_get_table_chunk(struct zclient *zclient, uint32_t chunk_size, | |
803 | uint32_t *start, uint32_t *end); | |
804 | extern int tm_release_table_chunk(struct zclient *zclient, uint32_t start, | |
805 | uint32_t end); | |
806 | ||
31f937fb SM |
807 | extern int zebra_send_sr_policy(struct zclient *zclient, int cmd, |
808 | struct zapi_sr_policy *zp); | |
809 | extern int zapi_sr_policy_encode(struct stream *s, int cmd, | |
810 | struct zapi_sr_policy *zp); | |
811 | extern int zapi_sr_policy_decode(struct stream *s, struct zapi_sr_policy *zp); | |
812 | extern int zapi_sr_policy_notify_status_decode(struct stream *s, | |
813 | struct zapi_sr_policy *zp); | |
814 | ||
bad6b0e7 RW |
815 | extern int zebra_send_mpls_labels(struct zclient *zclient, int cmd, |
816 | struct zapi_labels *zl); | |
817 | extern int zapi_labels_encode(struct stream *s, int cmd, | |
818 | struct zapi_labels *zl); | |
819 | extern int zapi_labels_decode(struct stream *s, struct zapi_labels *zl); | |
820 | ||
6833ae01 | 821 | extern int zebra_send_pw(struct zclient *zclient, int command, |
822 | struct zapi_pw *pw); | |
efc7191b QY |
823 | extern int zebra_read_pw_status_update(ZAPI_CALLBACK_ARGS, |
824 | struct zapi_pw_status *pw); | |
6833ae01 | 825 | |
d7c0a89a | 826 | extern int zclient_route_send(uint8_t, struct zclient *, struct zapi_route *); |
3c192540 | 827 | extern int zclient_send_rnh(struct zclient *zclient, int command, |
46f56dad | 828 | const struct prefix *p, bool exact_match, |
3c192540 | 829 | vrf_id_t vrf_id); |
68a02e06 | 830 | int zapi_nexthop_encode(struct stream *s, const struct zapi_nexthop *api_nh, |
31f937fb | 831 | uint32_t api_flags, uint32_t api_message); |
d7c0a89a | 832 | extern int zapi_route_encode(uint8_t, struct stream *, struct zapi_route *); |
0e51b4a3 | 833 | extern int zapi_route_decode(struct stream *, struct zapi_route *); |
7ea7b86e | 834 | bool zapi_route_notify_decode(struct stream *s, struct prefix *p, |
28610f7e | 835 | uint32_t *tableid, |
7ea7b86e | 836 | enum zapi_route_notify_owner *note); |
b6c5d343 DS |
837 | bool zapi_rule_notify_decode(struct stream *s, uint32_t *seqno, |
838 | uint32_t *priority, uint32_t *unique, | |
839 | ifindex_t *ifindex, | |
840 | enum zapi_rule_notify_owner *note); | |
425bdd6b PG |
841 | bool zapi_ipset_notify_decode(struct stream *s, |
842 | uint32_t *unique, | |
843 | enum zapi_ipset_notify_owner *note); | |
844 | ||
845 | #define ZEBRA_IPSET_NAME_SIZE 32 | |
846 | ||
847 | bool zapi_ipset_entry_notify_decode(struct stream *s, | |
848 | uint32_t *unique, | |
849 | char *ipset_name, | |
850 | enum zapi_ipset_entry_notify_owner *note); | |
c16a0a62 PG |
851 | bool zapi_iptable_notify_decode(struct stream *s, |
852 | uint32_t *unique, | |
853 | enum zapi_iptable_notify_owner *note); | |
425bdd6b | 854 | |
0a8881b4 MS |
855 | extern struct nexthop * |
856 | nexthop_from_zapi_nexthop(const struct zapi_nexthop *znh); | |
68a02e06 MS |
857 | int zapi_nexthop_from_nexthop(struct zapi_nexthop *znh, |
858 | const struct nexthop *nh); | |
0a8881b4 MS |
859 | int zapi_backup_nexthop_from_nexthop(struct zapi_nexthop *znh, |
860 | const struct nexthop *nh); | |
4a749e2c DS |
861 | extern bool zapi_nexthop_update_decode(struct stream *s, |
862 | struct zapi_route *nhr); | |
ae076fc2 MS |
863 | const char *zapi_nexthop2str(const struct zapi_nexthop *znh, char *buf, |
864 | int bufsize); | |
718e3744 | 865 | |
9ab0b2a3 SW |
866 | /* Decode the zebra error message */ |
867 | extern bool zapi_error_decode(struct stream *s, enum zebra_error_types *error); | |
868 | ||
be7bbe52 S |
869 | /* Encode and decode restart capabilities */ |
870 | extern int32_t zclient_capabilities_send(uint32_t cmd, struct zclient *zclient, | |
871 | struct zapi_cap *api); | |
872 | extern int32_t zapi_capabilities_decode(struct stream *s, struct zapi_cap *api); | |
873 | ||
09a484dd | 874 | static inline void zapi_route_set_blackhole(struct zapi_route *api, |
60466a63 | 875 | enum blackhole_type bh_type) |
09a484dd DL |
876 | { |
877 | api->nexthop_num = 1; | |
878 | api->nexthops[0].type = NEXTHOP_TYPE_BLACKHOLE; | |
4a7371e9 | 879 | api->nexthops[0].vrf_id = VRF_DEFAULT; |
09a484dd DL |
880 | api->nexthops[0].bh_type = bh_type; |
881 | SET_FLAG(api->message, ZAPI_MESSAGE_NEXTHOP); | |
882 | }; | |
883 | ||
36b5b98f SK |
884 | extern void zclient_send_mlag_register(struct zclient *client, |
885 | uint32_t bit_map); | |
886 | extern void zclient_send_mlag_deregister(struct zclient *client); | |
887 | ||
888 | extern void zclient_send_mlag_data(struct zclient *client, | |
889 | struct stream *client_s); | |
09a484dd | 890 | |
ff491140 MS |
891 | /* |
892 | * Send an OPAQUE message, contents opaque to zebra - but note that | |
893 | * the length of the payload is restricted by the zclient's | |
894 | * outgoing message buffer. | |
895 | * The message header is a message subtype; please use the registry | |
896 | * below to avoid sub-type collisions. Clients use the registration | |
897 | * apis to manage the specific opaque subtypes they want to receive. | |
898 | */ | |
899 | int zclient_send_opaque(struct zclient *zclient, uint32_t type, | |
900 | const uint8_t *data, size_t datasize); | |
901 | ||
387831ff MS |
902 | int zclient_send_opaque_unicast(struct zclient *zclient, uint32_t type, |
903 | uint8_t proto, uint16_t instance, | |
904 | uint32_t session_id, const uint8_t *data, | |
905 | size_t datasize); | |
906 | ||
907 | /* Struct representing the decoded opaque header info */ | |
908 | struct zapi_opaque_msg { | |
909 | uint32_t type; /* Subtype */ | |
910 | uint16_t len; /* len after zapi header and this info */ | |
911 | uint16_t flags; | |
912 | ||
913 | /* Client-specific info - *if* UNICAST flag is set */ | |
914 | uint8_t proto; | |
915 | uint16_t instance; | |
916 | uint32_t session_id; | |
917 | }; | |
918 | ||
919 | #define ZAPI_OPAQUE_FLAG_UNICAST 0x01 | |
920 | ||
ff491140 MS |
921 | /* Simple struct to convey registration/unreg requests */ |
922 | struct zapi_opaque_reg_info { | |
923 | /* Message subtype */ | |
924 | uint32_t type; | |
925 | ||
926 | /* Client session tuple */ | |
927 | uint8_t proto; | |
928 | uint16_t instance; | |
929 | uint32_t session_id; | |
930 | }; | |
931 | ||
387831ff MS |
932 | /* Decode incoming opaque */ |
933 | int zclient_opaque_decode(struct stream *msg, struct zapi_opaque_msg *info); | |
934 | ||
ff491140 MS |
935 | int zclient_register_opaque(struct zclient *zclient, uint32_t type); |
936 | int zclient_unregister_opaque(struct zclient *zclient, uint32_t type); | |
d2ddc141 MS |
937 | int zapi_opaque_reg_decode(struct stream *msg, |
938 | struct zapi_opaque_reg_info *info); | |
ff491140 MS |
939 | |
940 | /* | |
941 | * Registry of opaque message types. Please do not reuse an in-use | |
942 | * type code; some daemons are likely relying on it. | |
943 | */ | |
944 | enum zapi_opaque_registry { | |
945 | /* Request link-state database dump, at restart for example */ | |
946 | LINK_STATE_REQUEST = 1, | |
947 | /* Update containing link-state db info */ | |
948 | LINK_STATE_UPDATE = 2, | |
949 | }; | |
950 | ||
17da84a4 KS |
951 | /* Send the hello message. |
952 | * Returns 0 for success or -1 on an I/O error. | |
953 | */ | |
954 | extern int zclient_send_hello(struct zclient *client); | |
955 | ||
17e38209 RW |
956 | #ifdef __cplusplus |
957 | } | |
958 | #endif | |
959 | ||
718e3744 | 960 | #endif /* _ZEBRA_ZCLIENT_H */ |