]> git.proxmox.com Git - mirror_frr.git/blame - lib/zclient.h
Merge pull request #13649 from donaldsharp/unlock_the_node_or_else
[mirror_frr.git] / lib / zclient.h
CommitLineData
acddc0ed 1// SPDX-License-Identifier: GPL-2.0-or-later
718e3744 2/* Zebra's client header.
3 * Copyright (C) 1999 Kunihiro Ishiguro
718e3744 4 */
5
6#ifndef _ZEBRA_ZCLIENT_H
7#define _ZEBRA_ZCLIENT_H
8
a243d1db
DL
9struct zclient;
10
74489921 11/* For struct zapi_route. */
5734509c 12#include "prefix.h"
0a27a2fe 13#include "ipaddr.h"
5734509c 14
718e3744 15/* For struct interface and struct connected. */
16#include "if.h"
17
7076bb2f
FL
18/* For vrf_bitmap_t. */
19#include "vrf.h"
20
6833ae01 21/* For union g_addr */
22#include "nexthop.h"
ca2b3467
DS
23/* For resilience */
24#include "nexthop_group.h"
6833ae01 25
26/* For union pw_protocol_fields */
27#include "pw.h"
28
02c0866d 29#include "mlag.h"
31f937fb 30#include "srte.h"
f2867068 31#include "srv6.h"
02c0866d 32
17e38209
RW
33#ifdef __cplusplus
34extern "C" {
35#endif
36
03edc41d
DS
37/* Zebra types. Used in Zserv message header. */
38typedef uint16_t zebra_size_t;
39
8ee06b2c
DS
40/* Marker value used in new Zserv, in the byte location corresponding
41 * the command value in the old zserv header. To allow old and new
42 * Zserv headers to be distinguished from each other.
43 */
44#define ZEBRA_HEADER_MARKER 254
45
718e3744 46/* For input/output buffer to zebra. */
f3f45626 47#define ZEBRA_MAX_PACKET_SIZ 16384U
55e74ca9 48#define ZEBRA_SMALL_PACKET_SIZE 200U
718e3744 49
50/* Zebra header size. */
a9ff90c4 51#define ZEBRA_HEADER_SIZE 10
718e3744 52
689f5a8c
DL
53/* special socket path name to use TCP
54 * @ is used as first character because that's abstract socket names on Linux
55 */
56#define ZAPI_TCP_PATHNAME "@tcp"
57
7661461a
PG
58/* IPset size name stands for the name of the ipset entry
59 * that can be created by using some zapi interfaces
60 */
61#define ZEBRA_IPSET_NAME_SIZE 32
62
7abd6c4f
PG
63/* IPTable action is defined by two values: either
64 * forward or drop
65 */
66#define ZEBRA_IPTABLES_FORWARD 0
67#define ZEBRA_IPTABLES_DROP 1
68
57592a53
AD
69/* Zebra FEC register command flags. */
70#define ZEBRA_FEC_REGISTER_LABEL 0x1
71#define ZEBRA_FEC_REGISTER_LABEL_INDEX 0x2
72
be7bbe52
S
73/* Client capabilities */
74enum zserv_client_capabilities {
75 ZEBRA_CLIENT_GR_CAPABILITIES = 1,
76 ZEBRA_CLIENT_ROUTE_UPDATE_COMPLETE = 2,
77 ZEBRA_CLIENT_ROUTE_UPDATE_PENDING = 3,
78 ZEBRA_CLIENT_GR_DISABLE = 4,
79 ZEBRA_CLIENT_RIB_STALE_TIME
80};
81
82/* Macro to check if there GR enabled. */
83#define ZEBRA_CLIENT_GR_ENABLED(X) (X == ZEBRA_CLIENT_GR_CAPABILITIES)
eb451ee5 84
31f937fb
SM
85#define ZEBRA_SR_POLICY_NAME_MAX_LENGTH 100
86
689f5a8c
DL
87extern struct sockaddr_storage zclient_addr;
88extern socklen_t zclient_addr_len;
89
8613585e
DS
90/* Zebra message types. */
91typedef enum {
d62a17ae 92 ZEBRA_INTERFACE_ADD,
93 ZEBRA_INTERFACE_DELETE,
94 ZEBRA_INTERFACE_ADDRESS_ADD,
95 ZEBRA_INTERFACE_ADDRESS_DELETE,
96 ZEBRA_INTERFACE_UP,
97 ZEBRA_INTERFACE_DOWN,
e0ae31b8 98 ZEBRA_INTERFACE_SET_MASTER,
c3bd894e 99 ZEBRA_INTERFACE_SET_PROTODOWN,
0e51b4a3
RW
100 ZEBRA_ROUTE_ADD,
101 ZEBRA_ROUTE_DELETE,
7ea7b86e 102 ZEBRA_ROUTE_NOTIFY_OWNER,
d62a17ae 103 ZEBRA_REDISTRIBUTE_ADD,
104 ZEBRA_REDISTRIBUTE_DELETE,
105 ZEBRA_REDISTRIBUTE_DEFAULT_ADD,
106 ZEBRA_REDISTRIBUTE_DEFAULT_DELETE,
107 ZEBRA_ROUTER_ID_ADD,
108 ZEBRA_ROUTER_ID_DELETE,
109 ZEBRA_ROUTER_ID_UPDATE,
110 ZEBRA_HELLO,
09924cff 111 ZEBRA_CAPABILITIES,
d62a17ae 112 ZEBRA_NEXTHOP_REGISTER,
113 ZEBRA_NEXTHOP_UNREGISTER,
114 ZEBRA_NEXTHOP_UPDATE,
115 ZEBRA_INTERFACE_NBR_ADDRESS_ADD,
116 ZEBRA_INTERFACE_NBR_ADDRESS_DELETE,
117 ZEBRA_INTERFACE_BFD_DEST_UPDATE,
d62a17ae 118 ZEBRA_BFD_DEST_REGISTER,
119 ZEBRA_BFD_DEST_DEREGISTER,
120 ZEBRA_BFD_DEST_UPDATE,
121 ZEBRA_BFD_DEST_REPLAY,
74489921
RW
122 ZEBRA_REDISTRIBUTE_ROUTE_ADD,
123 ZEBRA_REDISTRIBUTE_ROUTE_DEL,
d62a17ae 124 ZEBRA_VRF_UNREGISTER,
125 ZEBRA_VRF_ADD,
126 ZEBRA_VRF_DELETE,
c83c5e44 127 ZEBRA_VRF_LABEL,
d62a17ae 128 ZEBRA_INTERFACE_VRF_UPDATE,
129 ZEBRA_BFD_CLIENT_REGISTER,
d3af6147 130 ZEBRA_BFD_CLIENT_DEREGISTER,
d62a17ae 131 ZEBRA_INTERFACE_ENABLE_RADV,
132 ZEBRA_INTERFACE_DISABLE_RADV,
34ee41c6 133 ZEBRA_NEXTHOP_LOOKUP_MRIB,
d62a17ae 134 ZEBRA_INTERFACE_LINK_PARAMS,
135 ZEBRA_MPLS_LABELS_ADD,
136 ZEBRA_MPLS_LABELS_DELETE,
ea6b290b 137 ZEBRA_MPLS_LABELS_REPLACE,
31f937fb
SM
138 ZEBRA_SR_POLICY_SET,
139 ZEBRA_SR_POLICY_DELETE,
140 ZEBRA_SR_POLICY_NOTIFY_STATUS,
d62a17ae 141 ZEBRA_IPMR_ROUTE_STATS,
142 ZEBRA_LABEL_MANAGER_CONNECT,
f533be73 143 ZEBRA_LABEL_MANAGER_CONNECT_ASYNC,
d62a17ae 144 ZEBRA_GET_LABEL_CHUNK,
145 ZEBRA_RELEASE_LABEL_CHUNK,
146 ZEBRA_FEC_REGISTER,
147 ZEBRA_FEC_UNREGISTER,
148 ZEBRA_FEC_UPDATE,
1a98c087 149 ZEBRA_ADVERTISE_DEFAULT_GW,
fc08a52f 150 ZEBRA_ADVERTISE_SVI_MACIP,
31310b25 151 ZEBRA_ADVERTISE_SUBNET,
d62a17ae 152 ZEBRA_ADVERTISE_ALL_VNI,
50f74cf1 153 ZEBRA_LOCAL_ES_ADD,
154 ZEBRA_LOCAL_ES_DEL,
ce5160c0
AK
155 ZEBRA_REMOTE_ES_VTEP_ADD,
156 ZEBRA_REMOTE_ES_VTEP_DEL,
157 ZEBRA_LOCAL_ES_EVI_ADD,
158 ZEBRA_LOCAL_ES_EVI_DEL,
d62a17ae 159 ZEBRA_VNI_ADD,
160 ZEBRA_VNI_DEL,
b7cfce93
MK
161 ZEBRA_L3VNI_ADD,
162 ZEBRA_L3VNI_DEL,
d62a17ae 163 ZEBRA_REMOTE_VTEP_ADD,
164 ZEBRA_REMOTE_VTEP_DEL,
165 ZEBRA_MACIP_ADD,
166 ZEBRA_MACIP_DEL,
31310b25
MK
167 ZEBRA_IP_PREFIX_ROUTE_ADD,
168 ZEBRA_IP_PREFIX_ROUTE_DEL,
d62a17ae 169 ZEBRA_REMOTE_MACIP_ADD,
170 ZEBRA_REMOTE_MACIP_DEL,
3950b52c 171 ZEBRA_DUPLICATE_ADDR_DETECTION,
6833ae01 172 ZEBRA_PW_ADD,
173 ZEBRA_PW_DELETE,
174 ZEBRA_PW_SET,
175 ZEBRA_PW_UNSET,
176 ZEBRA_PW_STATUS_UPDATE,
e16abbb3
DS
177 ZEBRA_RULE_ADD,
178 ZEBRA_RULE_DELETE,
179 ZEBRA_RULE_NOTIFY_OWNER,
75fb51c1
PG
180 ZEBRA_TABLE_MANAGER_CONNECT,
181 ZEBRA_GET_TABLE_CHUNK,
182 ZEBRA_RELEASE_TABLE_CHUNK,
d59c13af
PG
183 ZEBRA_IPSET_CREATE,
184 ZEBRA_IPSET_DESTROY,
185 ZEBRA_IPSET_ENTRY_ADD,
186 ZEBRA_IPSET_ENTRY_DELETE,
425bdd6b
PG
187 ZEBRA_IPSET_NOTIFY_OWNER,
188 ZEBRA_IPSET_ENTRY_NOTIFY_OWNER,
7abd6c4f
PG
189 ZEBRA_IPTABLE_ADD,
190 ZEBRA_IPTABLE_DELETE,
191 ZEBRA_IPTABLE_NOTIFY_OWNER,
fbac9605 192 ZEBRA_VXLAN_FLOOD_CONTROL,
4ab3321f
AK
193 ZEBRA_VXLAN_SG_ADD,
194 ZEBRA_VXLAN_SG_DEL,
ecbbc3a7 195 ZEBRA_VXLAN_SG_REPLAY,
46c2687c
SK
196 ZEBRA_MLAG_PROCESS_UP,
197 ZEBRA_MLAG_PROCESS_DOWN,
36b5b98f
SK
198 ZEBRA_MLAG_CLIENT_REGISTER,
199 ZEBRA_MLAG_CLIENT_UNREGISTER,
200 ZEBRA_MLAG_FORWARD_MSG,
2f35a820
DS
201 ZEBRA_NHG_ADD,
202 ZEBRA_NHG_DEL,
203 ZEBRA_NHG_NOTIFY_OWNER,
7bfa7d02
AK
204 ZEBRA_EVPN_REMOTE_NH_ADD,
205 ZEBRA_EVPN_REMOTE_NH_DEL,
f2867068
HS
206 ZEBRA_SRV6_LOCATOR_ADD,
207 ZEBRA_SRV6_LOCATOR_DELETE,
f2867068
HS
208 ZEBRA_SRV6_MANAGER_GET_LOCATOR_CHUNK,
209 ZEBRA_SRV6_MANAGER_RELEASE_LOCATOR_CHUNK,
9ab0b2a3 210 ZEBRA_ERROR,
ff491140
MS
211 ZEBRA_CLIENT_CAPABILITIES,
212 ZEBRA_OPAQUE_MESSAGE,
213 ZEBRA_OPAQUE_REGISTER,
214 ZEBRA_OPAQUE_UNREGISTER,
d68e74b4 215 ZEBRA_NEIGH_DISCOVER,
77b38a4a 216 ZEBRA_ROUTE_NOTIFY_REQUEST,
581e797e 217 ZEBRA_CLIENT_CLOSE_NOTIFY,
fda64ab4
PG
218 ZEBRA_NHRP_NEIGH_ADDED,
219 ZEBRA_NHRP_NEIGH_REMOVED,
220 ZEBRA_NHRP_NEIGH_GET,
7723e8d3
PG
221 ZEBRA_NHRP_NEIGH_REGISTER,
222 ZEBRA_NHRP_NEIGH_UNREGISTER,
d603c077
PG
223 ZEBRA_NEIGH_IP_ADD,
224 ZEBRA_NEIGH_IP_DEL,
451e2b8c 225 ZEBRA_CONFIGURE_ARP,
632d8306
PG
226 ZEBRA_GRE_GET,
227 ZEBRA_GRE_UPDATE,
228 ZEBRA_GRE_SOURCE_SET,
dfacea4a
SY
229 ZEBRA_TC_QDISC_INSTALL,
230 ZEBRA_TC_QDISC_UNINSTALL,
231 ZEBRA_TC_CLASS_ADD,
232 ZEBRA_TC_CLASS_DELETE,
233 ZEBRA_TC_FILTER_ADD,
234 ZEBRA_TC_FILTER_DELETE,
8613585e
DS
235} zebra_message_types_t;
236
9ab0b2a3 237enum zebra_error_types {
be7bbe52 238 ZEBRA_UNKNOWN_ERROR, /* Error of unknown type */
9ab0b2a3
SW
239 ZEBRA_NO_VRF, /* Vrf in header was not found */
240 ZEBRA_INVALID_MSG_TYPE, /* No handler found for msg type */
241};
242
243static inline const char *zebra_error_type2str(enum zebra_error_types type)
244{
245 const char *ret = "UNKNOWN";
246
247 switch (type) {
248 case ZEBRA_UNKNOWN_ERROR:
249 ret = "ZEBRA_UNKNOWN_ERROR";
250 break;
251 case ZEBRA_NO_VRF:
252 ret = "ZEBRA_NO_VRF";
253 break;
254 case ZEBRA_INVALID_MSG_TYPE:
255 ret = "ZEBRA_INVALID_MSG_TYPE";
256 break;
257 }
258
259 return ret;
260}
261
d62a17ae 262struct redist_proto {
d7c0a89a 263 uint8_t enabled;
d62a17ae 264 struct list *instances;
7c8ff89e
DS
265};
266
09924cff
DS
267struct zclient_capabilities {
268 uint32_t ecmp;
269 bool mpls_enabled;
02c0866d 270 enum mlag_role role;
09924cff
DS
271};
272
eb451ee5 273/* Graceful Restart Capabilities message */
274struct zapi_cap {
be7bbe52
S
275 enum zserv_client_capabilities cap;
276 uint32_t stale_removal_time;
277 afi_t afi;
278 safi_t safi;
279 vrf_id_t vrf_id;
eb451ee5 280};
281
a243d1db
DL
282/* clang-format off */
283#define ZAPI_CALLBACK_ARGS \
284 int cmd, struct zclient *zclient, uint16_t length, vrf_id_t vrf_id
285
286/* function-type typedef (pointer not included) */
287typedef int (zclient_handler)(ZAPI_CALLBACK_ARGS);
288/* clang-format on */
289
718e3744 290/* Structure for the zebra client. */
d62a17ae 291struct zclient {
292 /* The thread master we schedule ourselves on */
cd9d0537 293 struct event_loop *master;
d62a17ae 294
03bad95a 295 /* Privileges to change socket values */
342213ea
DS
296 struct zebra_privs_t *privs;
297
e1a1880d
DS
298 /* Do we care about failure events for route install? */
299 bool receive_notify;
300
17da84a4
KS
301 /* Is this a synchronous client? */
302 bool synchronous;
303
a243d1db
DL
304 /* BFD enabled with bfd_protocol_integration_init() */
305 bool bfd_integration;
306
4e0b5b31
MS
307 /* Session id (optional) to support clients with multiple sessions */
308 uint32_t session_id;
309
d62a17ae 310 /* Socket to zebra daemon. */
311 int sock;
312
d62a17ae 313 /* Connection failure count. */
314 int fail;
315
316 /* Input buffer for zebra message. */
317 struct stream *ibuf;
318
319 /* Output buffer for zebra message. */
320 struct stream *obuf;
321
322 /* Buffer of data waiting to be written to zebra. */
323 struct buffer *wb;
324
325 /* Read and connect thread. */
e6685141
DS
326 struct event *t_read;
327 struct event *t_connect;
d62a17ae 328
329 /* Thread to write buffered data to zebra. */
e6685141 330 struct event *t_write;
d62a17ae 331
332 /* Redistribute information. */
d7c0a89a
QY
333 uint8_t redist_default; /* clients protocol */
334 unsigned short instance;
d62a17ae 335 struct redist_proto mi_redist[AFI_MAX][ZEBRA_ROUTE_MAX];
336 vrf_bitmap_t redist[AFI_MAX][ZEBRA_ROUTE_MAX];
337
03bad95a 338 /* Redistribute default. */
49db7a7b 339 vrf_bitmap_t default_information[AFI_MAX];
d62a17ae 340
341 /* Pointer to the callback functions. */
342 void (*zebra_connected)(struct zclient *);
09924cff 343 void (*zebra_capabilities)(struct zclient_capabilities *cap);
db71415b 344
a243d1db
DL
345 int (*handle_error)(enum zebra_error_types error);
346
db71415b
DS
347 /*
348 * When the zclient attempts to write the stream data to
349 * it's named pipe to/from zebra, we may have a situation
350 * where the other daemon has not fully drained the data
351 * from the socket. In this case provide a mechanism
352 * where we will *still* buffer the data to be sent
353 * and also provide a callback mechanism to the appropriate
354 * place where we can signal that we're ready to receive
355 * more data.
356 */
357 void (*zebra_buffer_write_ready)(void);
a243d1db
DL
358
359 zclient_handler *const *handlers;
360 size_t n_handlers;
718e3744 361};
362
a243d1db 363/* lib handlers added in bfd.c */
3e51a84a 364extern int zclient_bfd_session_replay(ZAPI_CALLBACK_ARGS);
a243d1db
DL
365extern int zclient_bfd_session_update(ZAPI_CALLBACK_ARGS);
366
718e3744 367/* Zebra API message flag. */
368#define ZAPI_MESSAGE_NEXTHOP 0x01
74489921
RW
369#define ZAPI_MESSAGE_DISTANCE 0x02
370#define ZAPI_MESSAGE_METRIC 0x04
371#define ZAPI_MESSAGE_TAG 0x08
372#define ZAPI_MESSAGE_MTU 0x10
373#define ZAPI_MESSAGE_SRCPFX 0x20
018c6488
MS
374/* Backup nexthops are present */
375#define ZAPI_MESSAGE_BACKUP_NEXTHOPS 0x40
ff9aca4f 376#define ZAPI_MESSAGE_NHG 0x80
ba1849ef
DS
377/*
378 * This should only be used by a DAEMON that needs to communicate
379 * the table being used is not in the VRF. You must pass the
380 * default vrf, else this will be ignored.
381 */
aab4eca1
DS
382#define ZAPI_MESSAGE_TABLEID 0x0100
383#define ZAPI_MESSAGE_SRTE 0x0200
71c4870b 384#define ZAPI_MESSAGE_OPAQUE 0x0400
718e3744 385
04772760 386#define ZSERV_VERSION 6
c1b9800a 387/* Zserv protocol message header */
124ead27 388struct zmsghdr {
d62a17ae 389 uint16_t length;
5530922e 390 /* Always set to 255 in new zserv */
124ead27 391 uint8_t marker;
d62a17ae 392 uint8_t version;
d62a17ae 393 vrf_id_t vrf_id;
394 uint16_t command;
6e8e0925
DS
395} __attribute__((packed));
396#define ZAPI_HEADER_CMD_LOCATION offsetof(struct zmsghdr, command)
c1b9800a 397
38fd3eda
MS
398/*
399 * ZAPI nexthop. Note that these are sorted when associated with ZAPI routes,
400 * and that sorting must be aligned with the sorting of nexthops in
401 * lib/nexthop.c. Any new fields must be accounted for in zapi_nexthop_cmp().
402 */
bb1b9c47
RW
403struct zapi_nexthop {
404 enum nexthop_types_t type;
4a7371e9 405 vrf_id_t vrf_id;
bb1b9c47 406 ifindex_t ifindex;
68a02e06 407 uint8_t flags;
09a484dd
DL
408 union {
409 union g_addr gate;
410 enum blackhole_type bh_type;
411 };
52dd3aa4
RW
412
413 /* MPLS labels for BGP-LU or Segment Routing */
414 uint8_t label_num;
d5ea1185 415 enum lsp_types_t label_type;
52dd3aa4 416 mpls_label_t labels[MPLS_MAX_LABELS];
a317a9b9 417
418 struct ethaddr rmac;
bd054c1a
DS
419
420 uint32_t weight;
018c6488 421
474aebd9
MS
422 /* Backup nexthops, for IP-FRR, TI-LFA, etc */
423 uint8_t backup_num;
424 uint8_t backup_idx[NEXTHOP_MAX_BACKUPS];
31f937fb
SM
425
426 /* SR-TE color. */
427 uint32_t srte_color;
cb7775a9
HS
428
429 /* SRv6 localsid info for Endpoint-behaviour */
430 uint32_t seg6local_action;
431 struct seg6local_context seg6local_ctx;
2aa01034
HS
432
433 /* SRv6 Headend-behaviour */
434 struct in6_addr seg6_segs;
bb1b9c47
RW
435};
436
68a02e06 437/*
018c6488
MS
438 * ZAPI nexthop flags values - we're encoding a single octet
439 * initially, so ensure that the on-the-wire encoding continues
440 * to match the number of valid flags.
68a02e06 441 */
018c6488 442
68a02e06
MS
443#define ZAPI_NEXTHOP_FLAG_ONLINK 0x01
444#define ZAPI_NEXTHOP_FLAG_LABEL 0x02
bd054c1a 445#define ZAPI_NEXTHOP_FLAG_WEIGHT 0x04
018c6488 446#define ZAPI_NEXTHOP_FLAG_HAS_BACKUP 0x08 /* Nexthop has a backup */
c60c1ade
HS
447#define ZAPI_NEXTHOP_FLAG_SEG6 0x10
448#define ZAPI_NEXTHOP_FLAG_SEG6LOCAL 0x20
5609e70f 449#define ZAPI_NEXTHOP_FLAG_EVPN 0x40
68a02e06 450
c6ce9334
SW
451/*
452 * ZAPI Nexthop Group. For use with protocol creation of nexthop groups.
453 */
454struct zapi_nhg {
21735352 455 uint16_t proto;
c6ce9334 456 uint32_t id;
21735352 457
ca2b3467
DS
458 struct nhg_resilience resilience;
459
c6ce9334
SW
460 uint16_t nexthop_num;
461 struct zapi_nexthop nexthops[MULTIPATH_NUM];
21735352
SW
462
463 uint16_t backup_nexthop_num;
464 struct zapi_nexthop backup_nexthops[MULTIPATH_NUM];
c6ce9334
SW
465};
466
832d0f56
DS
467/*
468 * Some of these data structures do not map easily to
469 * a actual data structure size giving different compilers
470 * and systems. For those data structures we need
471 * to use the smallest available stream_getX/putX functions
472 * to encode/decode.
473 */
d62a17ae 474struct zapi_route {
d7c0a89a
QY
475 uint8_t type;
476 unsigned short instance;
657cde12 477
61e6de9d 478 /* If you add flags, update zclient_dump_route_flags */
d7c0a89a 479 uint32_t flags;
da01a37a
DS
480/*
481 * Cause Zebra to consider this routes nexthops recursively
482 */
483#define ZEBRA_FLAG_ALLOW_RECURSION 0x01
484/*
485 * This is a route that is read in on startup that was left around
486 * from a previous run of FRR
487 */
488#define ZEBRA_FLAG_SELFROUTE 0x02
489/*
490 * This flag is used to tell Zebra that the BGP route being passed
491 * down is a IBGP route
492 */
493#define ZEBRA_FLAG_IBGP 0x04
494/*
495 * This is a route that has been selected for FIB installation.
496 * This flag is set in zebra and can be passed up to routing daemons
497 */
498#define ZEBRA_FLAG_SELECTED 0x08
499/*
500 * This is a route that we are telling Zebra that this route *must*
501 * win and will be installed even over ZEBRA_FLAG_SELECTED
502 */
503#define ZEBRA_FLAG_FIB_OVERRIDE 0x10
504/*
505 * This flag tells Zebra that the route is a EVPN route and should
506 * be treated specially
507 */
508#define ZEBRA_FLAG_EVPN_ROUTE 0x20
509/*
510 * This flag tells Zebra that it should treat the distance passed
511 * down as an additional discriminator for route selection of the
512 * route entry. This mainly is used for backup static routes.
513 */
514#define ZEBRA_FLAG_RR_USE_DISTANCE 0x40
5a3cf853
DS
515/*
516 * This flag tells everyone that the route was intentionally
517 * not offloaded and the route will be sent to the cpu for
518 * forwarding. This flag makes no sense unless you are in
519 * an asic offload situation
520 */
521#define ZEBRA_FLAG_TRAPPED 0x80
522/*
523 * This flag tells everyone that the route has been
524 * successfully offloaded to an asic for forwarding.
525 * This flag makes no sense unless you are in an asic
526 * offload situation.
527 */
528#define ZEBRA_FLAG_OFFLOADED 0x100
0d32fbee
DS
529/*
530 * This flag tells everyone that the route has
531 * failed offloading.
532 * This flag makes no sense unless you are in an asic
533 * offload situation.
534 */
535#define ZEBRA_FLAG_OFFLOAD_FAILED 0x200
657cde12 536
a048d523
DS
537/*
538 * This flag lets us know that we think the route entry
539 * received has caused us to be out of sync with the
540 * kernel (NLM_F_APPEND at the very least )
541 */
542#define ZEBRA_FLAG_OUTOFSYNC 0x400
543
387831ff 544 /* The older XXX_MESSAGE flags live here */
31f937fb 545 uint32_t message;
657cde12 546
832d0f56
DS
547 /*
548 * This is an enum but we are going to treat it as a uint8_t
549 * for purpose of encoding/decoding
550 */
d62a17ae 551 safi_t safi;
657cde12 552
bb1b9c47
RW
553 struct prefix prefix;
554 struct prefix_ipv6 src_prefix;
555
d7c0a89a 556 uint16_t nexthop_num;
bb1b9c47 557 struct zapi_nexthop nexthops[MULTIPATH_NUM];
657cde12 558
018c6488
MS
559 /* Support backup routes for IP FRR, TI-LFA, traffic engineering */
560 uint16_t backup_nexthop_num;
561 struct zapi_nexthop backup_nexthops[MULTIPATH_NUM];
562
27141ea9
DS
563 uint32_t nhgid;
564
d7c0a89a 565 uint8_t distance;
657cde12 566
d7c0a89a 567 uint32_t metric;
657cde12 568
d62a17ae 569 route_tag_t tag;
657cde12 570
d7c0a89a 571 uint32_t mtu;
657cde12 572
d62a17ae 573 vrf_id_t vrf_id;
2dbad57f 574
ba1849ef 575 uint32_t tableid;
31f937fb
SM
576
577 /* SR-TE color (used for nexthop updates only). */
578 uint32_t srte_color;
71c4870b
DS
579
580#define ZAPI_MESSAGE_OPAQUE_LENGTH 1024
581 struct {
582 uint16_t length;
583 uint8_t data[ZAPI_MESSAGE_OPAQUE_LENGTH];
584 } opaque;
657cde12
DS
585};
586
61e6de9d
DS
587extern char *zclient_dump_route_flags(uint32_t flags, char *buf, size_t len);
588
bad6b0e7 589struct zapi_labels {
b3c49d0e 590 uint8_t message;
34f86754
MS
591#define ZAPI_LABELS_FTN 0x01
592#define ZAPI_LABELS_HAS_BACKUPS 0x02
bad6b0e7 593 enum lsp_types_t type;
bad6b0e7 594 mpls_label_t local_label;
b3c49d0e
RW
595 struct {
596 struct prefix prefix;
597 uint8_t type;
598 unsigned short instance;
599 } route;
4945002d 600
ea6b290b 601 uint16_t nexthop_num;
4945002d 602 struct zapi_nexthop nexthops[MULTIPATH_NUM];
34f86754
MS
603
604 /* Backup nexthops, if present */
605 uint16_t backup_nexthop_num;
606 struct zapi_nexthop backup_nexthops[MULTIPATH_NUM];
bad6b0e7
RW
607};
608
31f937fb
SM
609struct zapi_srte_tunnel {
610 enum lsp_types_t type;
611 mpls_label_t local_label;
612 uint8_t label_num;
613 mpls_label_t labels[MPLS_MAX_LABELS];
614};
615
616struct zapi_sr_policy {
617 uint32_t color;
618 struct ipaddr endpoint;
619 char name[SRTE_POLICY_NAME_MAX_LENGTH];
620 struct zapi_srte_tunnel segment_list;
621 int status;
622};
623
6833ae01 624struct zapi_pw {
3682bd90 625 char ifname[INTERFACE_NAMSIZ];
6833ae01 626 ifindex_t ifindex;
627 int type;
628 int af;
629 union g_addr nexthop;
630 uint32_t local_label;
631 uint32_t remote_label;
632 uint8_t flags;
633 union pw_protocol_fields data;
634 uint8_t protocol;
635};
636
637struct zapi_pw_status {
3682bd90 638 char ifname[INTERFACE_NAMSIZ];
6833ae01 639 ifindex_t ifindex;
640 uint32_t status;
641};
642
077d336a
RW
643/* IGP instance data associated to a RLFA. */
644struct zapi_rlfa_igp {
645 vrf_id_t vrf_id;
646 int protocol;
647 union {
648 struct {
649 char area_tag[32];
650 struct {
651 int tree_id;
652 int level;
653 unsigned int run_id;
654 } spf;
655 } isis;
656 };
657};
658
659/* IGP -> LDP RLFA (un)registration message. */
660struct zapi_rlfa_request {
661 /* IGP instance data. */
662 struct zapi_rlfa_igp igp;
663
664 /* Destination prefix. */
665 struct prefix destination;
666
667 /* PQ node address. */
668 struct in_addr pq_address;
669};
670
671/* LDP -> IGP RLFA label update. */
672struct zapi_rlfa_response {
673 /* IGP instance data. */
674 struct zapi_rlfa_igp igp;
675
676 /* Destination prefix. */
677 struct prefix destination;
678
679 /* Resolved LDP labels. */
680 mpls_label_t pq_label;
681 uint16_t nexthop_num;
682 struct {
683 int family;
684 union g_addr gate;
685 mpls_label_t label;
686 } nexthops[MULTIPATH_NUM];
687};
688
7ea7b86e
DS
689enum zapi_route_notify_owner {
690 ZAPI_ROUTE_FAIL_INSTALL,
691 ZAPI_ROUTE_BETTER_ADMIN_WON,
692 ZAPI_ROUTE_INSTALLED,
5e54c602
DS
693 ZAPI_ROUTE_REMOVED,
694 ZAPI_ROUTE_REMOVE_FAIL,
7ea7b86e
DS
695};
696
2f35a820
DS
697enum zapi_nhg_notify_owner {
698 ZAPI_NHG_FAIL_INSTALL,
699 ZAPI_NHG_INSTALLED,
700 ZAPI_NHG_REMOVED,
701 ZAPI_NHG_REMOVE_FAIL,
702};
703
0031a6bb
PG
704enum zapi_rule_notify_owner {
705 ZAPI_RULE_FAIL_INSTALL,
706 ZAPI_RULE_INSTALLED,
707 ZAPI_RULE_REMOVED,
34d9d5be 708 ZAPI_RULE_FAIL_REMOVE,
0031a6bb
PG
709};
710
7661461a
PG
711enum ipset_type {
712 IPSET_NET_NET = 1,
713 IPSET_NET_PORT_NET,
714 IPSET_NET_PORT,
715 IPSET_NET
716};
717
425bdd6b 718enum zapi_ipset_notify_owner {
ef524230 719 ZAPI_IPSET_FAIL_INSTALL = 0,
425bdd6b
PG
720 ZAPI_IPSET_INSTALLED,
721 ZAPI_IPSET_REMOVED,
34d9d5be 722 ZAPI_IPSET_FAIL_REMOVE,
425bdd6b
PG
723};
724
725enum zapi_ipset_entry_notify_owner {
ef524230 726 ZAPI_IPSET_ENTRY_FAIL_INSTALL = 0,
425bdd6b
PG
727 ZAPI_IPSET_ENTRY_INSTALLED,
728 ZAPI_IPSET_ENTRY_REMOVED,
34d9d5be 729 ZAPI_IPSET_ENTRY_FAIL_REMOVE,
425bdd6b
PG
730};
731
7abd6c4f 732enum zapi_iptable_notify_owner {
ef524230 733 ZAPI_IPTABLE_FAIL_INSTALL = 0,
7abd6c4f
PG
734 ZAPI_IPTABLE_INSTALLED,
735 ZAPI_IPTABLE_REMOVED,
34d9d5be 736 ZAPI_IPTABLE_FAIL_REMOVE,
7abd6c4f
PG
737};
738
8a3f8f2e
DS
739enum zclient_send_status {
740 ZCLIENT_SEND_FAILURE = -1,
741 ZCLIENT_SEND_SUCCESS = 0,
742 ZCLIENT_SEND_BUFFERED = 1
743};
744
90b0718e
MS
745static inline const char *
746zapi_nhg_notify_owner2str(enum zapi_nhg_notify_owner note)
747{
748 const char *ret = "UNKNOWN";
749
750 switch (note) {
751 case ZAPI_NHG_FAIL_INSTALL:
752 ret = "ZAPI_NHG_FAIL_INSTALL";
753 break;
754 case ZAPI_NHG_INSTALLED:
755 ret = "ZAPI_NHG_INSTALLED";
756 break;
757 case ZAPI_NHG_REMOVE_FAIL:
758 ret = "ZAPI_NHG_REMOVE_FAIL";
759 break;
760 case ZAPI_NHG_REMOVED:
761 ret = "ZAPI_NHG_REMOVED";
762 break;
763 }
764
765 return ret;
766}
767
eb5d458b
SW
768static inline const char *
769zapi_rule_notify_owner2str(enum zapi_rule_notify_owner note)
770{
771 const char *ret = "UNKNOWN";
772
773 switch (note) {
774 case ZAPI_RULE_FAIL_INSTALL:
775 ret = "ZAPI_RULE_FAIL_INSTALL";
776 break;
777 case ZAPI_RULE_INSTALLED:
778 ret = "ZAPI_RULE_INSTALLED";
779 break;
780 case ZAPI_RULE_FAIL_REMOVE:
781 ret = "ZAPI_RULE_FAIL_REMOVE";
782 break;
783 case ZAPI_RULE_REMOVED:
784 ret = "ZAPI_RULE_REMOVED";
785 break;
786 }
787
788 return ret;
789}
790
1a98c087 791/* Zebra MAC types */
ead40654
MK
792#define ZEBRA_MACIP_TYPE_STICKY 0x01 /* Sticky MAC*/
793#define ZEBRA_MACIP_TYPE_GW 0x02 /* gateway (SVI) mac*/
68e33151
CS
794#define ZEBRA_MACIP_TYPE_ROUTER_FLAG 0x04 /* Router Flag - proxy NA */
795#define ZEBRA_MACIP_TYPE_OVERRIDE_FLAG 0x08 /* Override Flag */
0ca10580 796#define ZEBRA_MACIP_TYPE_SVI_IP 0x10 /* SVI MAC-IP */
d0f699b5
AK
797#define ZEBRA_MACIP_TYPE_PROXY_ADVERT 0x20 /* Not locally active */
798#define ZEBRA_MACIP_TYPE_SYNC_PATH 0x40 /* sync path */
799/* XXX - flags is an u8; that needs to be changed to u32 if you need
bf902d4c 800 * to allocate past 0x80. Additionally touch zclient_evpn_dump_macip_flags
d0f699b5 801 */
bf902d4c
DS
802#define MACIP_BUF_SIZE 128
803extern char *zclient_evpn_dump_macip_flags(uint8_t flags, char *buf,
804 size_t len);
1a98c087 805
74e2bd89
AK
806/* Zebra ES VTEP flags (ZEBRA_REMOTE_ES_VTEP_ADD) */
807/* ESR has been rxed from the VTEP. Only VTEPs that have advertised the
808 * Type-4 route can participate in DF election.
809 */
810#define ZAPI_ES_VTEP_FLAG_ESR_RXED (1 << 0)
811
2c476b72
AK
812enum zebra_neigh_state { ZEBRA_NEIGH_INACTIVE = 0, ZEBRA_NEIGH_ACTIVE = 1 };
813
e1a1880d
DS
814struct zclient_options {
815 bool receive_notify;
17da84a4 816 bool synchronous;
e1a1880d
DS
817};
818
e1a1880d
DS
819extern struct zclient_options zclient_options_default;
820
05657ec2 821/* link layer representation for GRE like interfaces
0a27a2fe 822 * ip_in is the underlay IP, ip_out is the tunnel dest
05657ec2 823 * index stands for the index of the interface
d603c077 824 * ndm state stands for the NDM value in netlink
80f6b5fa 825 * (see linux/neighbour.h)
05657ec2 826 */
80f6b5fa 827#define ZEBRA_NEIGH_STATE_INCOMPLETE (0x01)
d603c077 828#define ZEBRA_NEIGH_STATE_REACHABLE (0x02)
80f6b5fa
PG
829#define ZEBRA_NEIGH_STATE_STALE (0x04)
830#define ZEBRA_NEIGH_STATE_DELAY (0x08)
831#define ZEBRA_NEIGH_STATE_PROBE (0x10)
832#define ZEBRA_NEIGH_STATE_FAILED (0x20)
833#define ZEBRA_NEIGH_STATE_NOARP (0x40)
834#define ZEBRA_NEIGH_STATE_PERMANENT (0x80)
835#define ZEBRA_NEIGH_STATE_NONE (0x00)
836
d603c077 837struct zapi_neigh_ip {
05657ec2 838 int cmd;
0a27a2fe
PG
839 struct ipaddr ip_in;
840 struct ipaddr ip_out;
05657ec2 841 ifindex_t index;
d603c077 842 uint32_t ndm_state;
05657ec2 843};
d603c077 844int zclient_neigh_ip_decode(struct stream *s, struct zapi_neigh_ip *api);
c4e1fd52
PG
845int zclient_neigh_ip_encode(struct stream *s, uint16_t cmd, union sockunion *in,
846 union sockunion *out, struct interface *ifp,
847 int ndm_state);
05657ec2 848
224b3c8a 849/*
54c89c93
SW
850 * We reserve the top 4 bits for l2-NHG, everything else
851 * is for zebra/proto l3-NHG.
852 *
224b3c8a 853 * Each client is going to get it's own nexthop group space
54c89c93
SW
854 * and we'll separate them, we'll figure out where to start based upon
855 * the route_types.h
224b3c8a 856 */
54c89c93
SW
857#define ZEBRA_NHG_PROTO_UPPER \
858 ((uint32_t)250000000) /* Bottom 28 bits then rounded down */
859#define ZEBRA_NHG_PROTO_SPACING (ZEBRA_NHG_PROTO_UPPER / ZEBRA_ROUTE_MAX)
860#define ZEBRA_NHG_PROTO_LOWER \
861 (ZEBRA_NHG_PROTO_SPACING * (ZEBRA_ROUTE_CONNECT + 1))
862
224b3c8a
DS
863extern uint32_t zclient_get_nhg_start(uint32_t proto);
864
cd9d0537 865extern struct zclient *zclient_new(struct event_loop *m,
a243d1db
DL
866 struct zclient_options *opt,
867 zclient_handler *const *handlers,
868 size_t n_handlers);
e1a1880d 869
d7c0a89a 870extern void zclient_init(struct zclient *, int, unsigned short,
996c9314 871 struct zebra_privs_t *privs);
d62a17ae 872extern int zclient_start(struct zclient *);
873extern void zclient_stop(struct zclient *);
874extern void zclient_reset(struct zclient *);
875extern void zclient_free(struct zclient *);
634f9ea2 876
d62a17ae 877extern int zclient_socket_connect(struct zclient *);
718e3744 878
d7c0a89a
QY
879extern unsigned short *redist_check_instance(struct redist_proto *,
880 unsigned short);
881extern void redist_add_instance(struct redist_proto *, unsigned short);
882extern void redist_del_instance(struct redist_proto *, unsigned short);
24c370dd 883extern void redist_del_all_instances(struct redist_proto *red);
7c8ff89e 884
c83c5e44
DS
885/*
886 * Send to zebra that the specified vrf is using label to resolve
887 * itself for L3VPN's. Repeated calls of this function with
888 * different labels will cause an effective update of the
42567e00 889 * label for lookup. If you pass in MPLS_LABEL_NONE
c83c5e44
DS
890 * we will cause a delete action and remove this label pop
891 * operation.
7d061b3c
DS
892 *
893 * The underlying AF_MPLS doesn't care about afi's
894 * but we can make the zebra_vrf keep track of what
895 * we have installed and play some special games
896 * to get them both installed.
c83c5e44 897 */
7cfdb485
DS
898extern enum zclient_send_status
899zclient_send_vrf_label(struct zclient *zclient, vrf_id_t vrf_id, afi_t afi,
900 mpls_label_t label, enum lsp_types_t ltype);
c83c5e44 901
618538f8
HS
902extern enum zclient_send_status
903zclient_send_localsid(struct zclient *zclient, const struct in6_addr *sid,
c37812dd 904 vrf_id_t vrf_id, enum seg6local_action_t action,
618538f8
HS
905 const struct seg6local_context *context);
906
d62a17ae 907extern void zclient_send_reg_requests(struct zclient *, vrf_id_t);
908extern void zclient_send_dereg_requests(struct zclient *, vrf_id_t);
7cfdb485
DS
909extern enum zclient_send_status
910zclient_send_router_id_update(struct zclient *zclient,
911 zebra_message_types_t type, afi_t afi,
912 vrf_id_t vrf_id);
913
914extern enum zclient_send_status
915zclient_send_interface_radv_req(struct zclient *zclient, vrf_id_t vrf_id,
916 struct interface *ifp, int enable,
bbad0276 917 uint32_t ra_interval);
7cfdb485
DS
918extern enum zclient_send_status
919zclient_send_interface_protodown(struct zclient *zclient, vrf_id_t vrf_id,
920 struct interface *ifp, bool down);
4a04e5f7 921
634f9ea2 922/* Send redistribute command to zebra daemon. Do not update zclient state. */
7cfdb485
DS
923extern enum zclient_send_status
924zebra_redistribute_send(int command, struct zclient *, afi_t, int type,
925 unsigned short instance, vrf_id_t vrf_id);
634f9ea2 926
7cfdb485
DS
927extern enum zclient_send_status
928zebra_redistribute_default_send(int command, struct zclient *zclient, afi_t afi,
929 vrf_id_t vrf_id);
49db7a7b 930
77b38a4a
S
931/* Send route notify request to zebra */
932extern int zebra_route_notify_send(int command, struct zclient *zclient,
933 bool set);
934
634f9ea2 935/* If state has changed, update state and call zebra_redistribute_send. */
d62a17ae 936extern void zclient_redistribute(int command, struct zclient *, afi_t, int type,
d7c0a89a 937 unsigned short instance, vrf_id_t vrf_id);
634f9ea2 938
939/* If state has changed, update state and send the command to zebra. */
d62a17ae 940extern void zclient_redistribute_default(int command, struct zclient *,
49db7a7b 941 afi_t, vrf_id_t vrf_id);
718e3744 942
db71415b
DS
943/*
944 * Send the message in zclient->obuf to the zebra daemon (or enqueue it).
945 * Returns:
946 * -1 on a I/O error
947 * 0 data was successfully sent
948 * 1 data was buffered for future usage
949 */
8a3f8f2e 950extern enum zclient_send_status zclient_send_message(struct zclient *);
718e3744 951
d211086a 952/* create header for command, length to be filled in by user later */
d62a17ae 953extern void zclient_create_header(struct stream *, uint16_t, vrf_id_t);
124ead27
QY
954/*
955 * Read sizeof(struct zmsghdr) bytes from the provided socket and parse the
956 * received data into the specified fields. If this is successful, read the
957 * rest of the packet into the provided stream.
958 *
959 * s
960 * The stream to read into
961 *
962 * sock
963 * The socket to read from
964 *
965 * size
966 * Parsed message size will be placed in the pointed-at integer
967 *
968 * marker
969 * Parsed marker will be placed in the pointed-at byte
970 *
971 * version
972 * Parsed version will be placed in the pointed-at byte
973 *
974 * vrf_id
975 * Parsed VRF ID will be placed in the pointed-at vrf_id_t
976 *
977 * cmd
978 * Parsed command number will be placed in the pointed-at integer
979 *
980 * Returns:
981 * -1 if:
982 * - insufficient data for header was read
983 * - a version mismatch was detected
984 * - a marker mismatch was detected
985 * - header size field specified more data than could be read
986 */
d7c0a89a
QY
987extern int zclient_read_header(struct stream *s, int sock, uint16_t *size,
988 uint8_t *marker, uint8_t *version,
989 vrf_id_t *vrf_id, uint16_t *cmd);
124ead27
QY
990/*
991 * Parse header from ZAPI message stream into struct zmsghdr.
992 * This function assumes the stream getp points at the first byte of the header.
993 * If the function is successful then the stream getp will point to the byte
994 * immediately after the last byte of the header.
995 *
996 * zmsg
997 * The stream containing the header
998 *
999 * hdr
1000 * The header struct to parse into.
1001 *
1002 * Returns:
1003 * true if parsing succeeded, false otherwise
1004 */
1005extern bool zapi_parse_header(struct stream *zmsg, struct zmsghdr *hdr);
d62a17ae 1006
7cfdb485
DS
1007extern enum zclient_send_status
1008zclient_interface_set_master(struct zclient *client, struct interface *master,
1009 struct interface *slave);
d62a17ae 1010extern struct interface *zebra_interface_state_read(struct stream *s, vrf_id_t);
1011extern struct connected *zebra_interface_address_read(int, struct stream *,
1012 vrf_id_t);
1013extern struct nbr_connected *
1014zebra_interface_nbr_address_read(int, struct stream *, vrf_id_t);
1015extern struct interface *zebra_interface_vrf_update_read(struct stream *s,
1016 vrf_id_t vrf_id,
1017 vrf_id_t *new_vrf_id);
efc7191b 1018extern int zebra_router_id_update_read(struct stream *s, struct prefix *rid);
0cb76b9d 1019
edc12762 1020extern struct interface *zebra_interface_link_params_read(struct stream *s,
0b4124c1
KS
1021 vrf_id_t vrf_id,
1022 bool *changed);
d62a17ae 1023extern size_t zebra_interface_link_params_write(struct stream *,
1024 struct interface *);
7cfdb485
DS
1025extern enum zclient_send_status
1026zclient_send_get_label_chunk(struct zclient *zclient, uint8_t keep,
1027 uint32_t chunk_size, uint32_t base);
955bfd98 1028
f533be73 1029extern int lm_label_manager_connect(struct zclient *zclient, int async);
d7c0a89a 1030extern int lm_get_label_chunk(struct zclient *zclient, uint8_t keep,
0e3b6a92
EDP
1031 uint32_t base, uint32_t chunk_size,
1032 uint32_t *start, uint32_t *end);
d62a17ae 1033extern int lm_release_label_chunk(struct zclient *zclient, uint32_t start,
1034 uint32_t end);
75fb51c1
PG
1035extern int tm_table_manager_connect(struct zclient *zclient);
1036extern int tm_get_table_chunk(struct zclient *zclient, uint32_t chunk_size,
1037 uint32_t *start, uint32_t *end);
1038extern int tm_release_table_chunk(struct zclient *zclient, uint32_t start,
1039 uint32_t end);
f2867068
HS
1040extern int srv6_manager_get_locator_chunk(struct zclient *zclient,
1041 const char *locator_name);
1042extern int srv6_manager_release_locator_chunk(struct zclient *zclient,
1043 const char *locator_name);
75fb51c1 1044
7cfdb485
DS
1045extern enum zclient_send_status zebra_send_sr_policy(struct zclient *zclient,
1046 int cmd,
1047 struct zapi_sr_policy *zp);
31f937fb
SM
1048extern int zapi_sr_policy_encode(struct stream *s, int cmd,
1049 struct zapi_sr_policy *zp);
1050extern int zapi_sr_policy_decode(struct stream *s, struct zapi_sr_policy *zp);
1051extern int zapi_sr_policy_notify_status_decode(struct stream *s,
1052 struct zapi_sr_policy *zp);
1053
7cfdb485
DS
1054extern enum zclient_send_status zebra_send_mpls_labels(struct zclient *zclient,
1055 int cmd,
1056 struct zapi_labels *zl);
bad6b0e7
RW
1057extern int zapi_labels_encode(struct stream *s, int cmd,
1058 struct zapi_labels *zl);
1059extern int zapi_labels_decode(struct stream *s, struct zapi_labels *zl);
1060
15588d7b
HS
1061extern int zapi_srv6_locator_encode(struct stream *s,
1062 const struct srv6_locator *l);
1063extern int zapi_srv6_locator_decode(struct stream *s, struct srv6_locator *l);
ac6a9479
HS
1064extern int zapi_srv6_locator_chunk_encode(struct stream *s,
1065 const struct srv6_locator_chunk *c);
1066extern int zapi_srv6_locator_chunk_decode(struct stream *s,
1067 struct srv6_locator_chunk *c);
1068
7cfdb485
DS
1069extern enum zclient_send_status zebra_send_pw(struct zclient *zclient,
1070 int command, struct zapi_pw *pw);
efc7191b
QY
1071extern int zebra_read_pw_status_update(ZAPI_CALLBACK_ARGS,
1072 struct zapi_pw_status *pw);
6833ae01 1073
8a3f8f2e
DS
1074extern enum zclient_send_status zclient_route_send(uint8_t, struct zclient *,
1075 struct zapi_route *);
7cfdb485
DS
1076extern enum zclient_send_status
1077zclient_send_rnh(struct zclient *zclient, int command, const struct prefix *p,
eb3c9d97
DL
1078 safi_t safi, bool connected, bool resolve_via_default,
1079 vrf_id_t vrf_id);
68a02e06 1080int zapi_nexthop_encode(struct stream *s, const struct zapi_nexthop *api_nh,
31f937fb 1081 uint32_t api_flags, uint32_t api_message);
d7c0a89a 1082extern int zapi_route_encode(uint8_t, struct stream *, struct zapi_route *);
2f35a820
DS
1083extern int zapi_route_decode(struct stream *s, struct zapi_route *api);
1084extern int zapi_nexthop_decode(struct stream *s, struct zapi_nexthop *api_nh,
1085 uint32_t api_flags, uint32_t api_message);
1086bool zapi_nhg_notify_decode(struct stream *s, uint32_t *id,
1087 enum zapi_nhg_notify_owner *note);
7ea7b86e 1088bool zapi_route_notify_decode(struct stream *s, struct prefix *p,
28610f7e 1089 uint32_t *tableid,
77b38a4a
S
1090 enum zapi_route_notify_owner *note,
1091 afi_t *afi, safi_t *safi);
b6c5d343 1092bool zapi_rule_notify_decode(struct stream *s, uint32_t *seqno,
58a1d249 1093 uint32_t *priority, uint32_t *unique, char *ifname,
b6c5d343 1094 enum zapi_rule_notify_owner *note);
425bdd6b
PG
1095bool zapi_ipset_notify_decode(struct stream *s,
1096 uint32_t *unique,
1097 enum zapi_ipset_notify_owner *note);
1098
5898ce6f 1099/* Nexthop-group message apis */
7cfdb485
DS
1100extern enum zclient_send_status
1101zclient_nhg_send(struct zclient *zclient, int cmd, struct zapi_nhg *api_nhg);
2f35a820 1102
425bdd6b
PG
1103#define ZEBRA_IPSET_NAME_SIZE 32
1104
1105bool zapi_ipset_entry_notify_decode(struct stream *s,
1106 uint32_t *unique,
1107 char *ipset_name,
1108 enum zapi_ipset_entry_notify_owner *note);
c16a0a62
PG
1109bool zapi_iptable_notify_decode(struct stream *s,
1110 uint32_t *unique,
1111 enum zapi_iptable_notify_owner *note);
425bdd6b 1112
0a8881b4
MS
1113extern struct nexthop *
1114nexthop_from_zapi_nexthop(const struct zapi_nexthop *znh);
68a02e06
MS
1115int zapi_nexthop_from_nexthop(struct zapi_nexthop *znh,
1116 const struct nexthop *nh);
0a8881b4
MS
1117int zapi_backup_nexthop_from_nexthop(struct zapi_nexthop *znh,
1118 const struct nexthop *nh);
06e4e901
DS
1119/*
1120 * match -> is the prefix that the calling daemon asked to be matched
1121 * against.
1122 * nhr->prefix -> is the actual prefix that was matched against in the
1123 * rib itself.
1124 *
1125 * This distinction is made because a LPM can be made if there is a
1126 * covering route. This way the upper level protocol can make a decision
1127 * point about whether or not it wants to use the match or not.
1128 */
1129extern bool zapi_nexthop_update_decode(struct stream *s, struct prefix *match,
4a749e2c 1130 struct zapi_route *nhr);
ae076fc2
MS
1131const char *zapi_nexthop2str(const struct zapi_nexthop *znh, char *buf,
1132 int bufsize);
718e3744 1133
9ab0b2a3
SW
1134/* Decode the zebra error message */
1135extern bool zapi_error_decode(struct stream *s, enum zebra_error_types *error);
1136
be7bbe52 1137/* Encode and decode restart capabilities */
7cfdb485
DS
1138extern enum zclient_send_status
1139zclient_capabilities_send(uint32_t cmd, struct zclient *zclient,
1140 struct zapi_cap *api);
be7bbe52
S
1141extern int32_t zapi_capabilities_decode(struct stream *s, struct zapi_cap *api);
1142
09a484dd 1143static inline void zapi_route_set_blackhole(struct zapi_route *api,
60466a63 1144 enum blackhole_type bh_type)
09a484dd
DL
1145{
1146 api->nexthop_num = 1;
1147 api->nexthops[0].type = NEXTHOP_TYPE_BLACKHOLE;
4a7371e9 1148 api->nexthops[0].vrf_id = VRF_DEFAULT;
09a484dd
DL
1149 api->nexthops[0].bh_type = bh_type;
1150 SET_FLAG(api->message, ZAPI_MESSAGE_NEXTHOP);
1151};
1152
7cfdb485
DS
1153extern enum zclient_send_status
1154zclient_send_mlag_register(struct zclient *client, uint32_t bit_map);
1155extern enum zclient_send_status
1156zclient_send_mlag_deregister(struct zclient *client);
36b5b98f 1157
7cfdb485
DS
1158extern enum zclient_send_status zclient_send_mlag_data(struct zclient *client,
1159 struct stream *client_s);
09a484dd 1160
ff491140
MS
1161/*
1162 * Send an OPAQUE message, contents opaque to zebra - but note that
1163 * the length of the payload is restricted by the zclient's
1164 * outgoing message buffer.
1165 * The message header is a message subtype; please use the registry
1166 * below to avoid sub-type collisions. Clients use the registration
1167 * apis to manage the specific opaque subtypes they want to receive.
1168 */
7cfdb485
DS
1169enum zclient_send_status zclient_send_opaque(struct zclient *zclient,
1170 uint32_t type, const uint8_t *data,
1171 size_t datasize);
ff491140 1172
7cfdb485
DS
1173enum zclient_send_status
1174zclient_send_opaque_unicast(struct zclient *zclient, uint32_t type,
1175 uint8_t proto, uint16_t instance,
1176 uint32_t session_id, const uint8_t *data,
1177 size_t datasize);
387831ff
MS
1178
1179/* Struct representing the decoded opaque header info */
1180struct zapi_opaque_msg {
1181 uint32_t type; /* Subtype */
1182 uint16_t len; /* len after zapi header and this info */
1183 uint16_t flags;
1184
1185 /* Client-specific info - *if* UNICAST flag is set */
1186 uint8_t proto;
1187 uint16_t instance;
1188 uint32_t session_id;
1189};
1190
1191#define ZAPI_OPAQUE_FLAG_UNICAST 0x01
1192
ff491140
MS
1193/* Simple struct to convey registration/unreg requests */
1194struct zapi_opaque_reg_info {
1195 /* Message subtype */
1196 uint32_t type;
1197
1198 /* Client session tuple */
1199 uint8_t proto;
1200 uint16_t instance;
1201 uint32_t session_id;
1202};
1203
387831ff
MS
1204/* Decode incoming opaque */
1205int zclient_opaque_decode(struct stream *msg, struct zapi_opaque_msg *info);
1206
7cfdb485
DS
1207enum zclient_send_status zclient_register_opaque(struct zclient *zclient,
1208 uint32_t type);
1209enum zclient_send_status zclient_unregister_opaque(struct zclient *zclient,
1210 uint32_t type);
d2ddc141
MS
1211int zapi_opaque_reg_decode(struct stream *msg,
1212 struct zapi_opaque_reg_info *info);
ff491140
MS
1213
1214/*
1215 * Registry of opaque message types. Please do not reuse an in-use
1216 * type code; some daemons are likely relying on it.
1217 */
1218enum zapi_opaque_registry {
1219 /* Request link-state database dump, at restart for example */
b0c0b433 1220 LINK_STATE_SYNC = 1,
ff491140
MS
1221 /* Update containing link-state db info */
1222 LINK_STATE_UPDATE = 2,
e1894ff7
KS
1223 /* Request LDP-SYNC state from LDP */
1224 LDP_IGP_SYNC_IF_STATE_REQUEST = 3,
1225 /* Update containing LDP IGP Sync State info */
1226 LDP_IGP_SYNC_IF_STATE_UPDATE = 4,
1227 /* Announce that LDP is up */
1228 LDP_IGP_SYNC_ANNOUNCE_UPDATE = 5,
077d336a
RW
1229 /* Register RLFA with LDP */
1230 LDP_RLFA_REGISTER = 7,
1231 /* Unregister all RLFAs with LDP */
1232 LDP_RLFA_UNREGISTER_ALL = 8,
1233 /* Announce LDP labels associated to a previously registered RLFA */
1234 LDP_RLFA_LABELS = 9,
ff491140
MS
1235};
1236
17da84a4
KS
1237/* Send the hello message.
1238 * Returns 0 for success or -1 on an I/O error.
1239 */
7cfdb485 1240extern enum zclient_send_status zclient_send_hello(struct zclient *client);
17da84a4 1241
7cfdb485
DS
1242extern enum zclient_send_status
1243zclient_send_neigh_discovery_req(struct zclient *zclient,
1244 const struct interface *ifp,
1245 const struct prefix *p);
d68e74b4 1246
581e797e
KS
1247struct zapi_client_close_info {
1248 /* Client session tuple */
1249 uint8_t proto;
1250 uint16_t instance;
1251 uint32_t session_id;
1252};
1253
1254/* Decode incoming client close notify */
1255extern int zapi_client_close_notify_decode(struct stream *s,
1256 struct zapi_client_close_info *info);
1257
d17af8dd
PG
1258extern int zclient_send_zebra_gre_request(struct zclient *client,
1259 struct interface *ifp);
17e38209
RW
1260#ifdef __cplusplus
1261}
1262#endif
1263
718e3744 1264#endif /* _ZEBRA_ZCLIENT_H */