]> git.proxmox.com Git - mirror_frr.git/blame - lib/zclient.h
Merge pull request #5600 from sworleys/NHG-Depend-Crash
[mirror_frr.git] / lib / zclient.h
CommitLineData
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
DS
39#include "mlag.h"
40
03edc41d
DS
41/* Zebra types. Used in Zserv message header. */
42typedef uint16_t zebra_size_t;
43
8ee06b2c
DS
44/* Marker value used in new Zserv, in the byte location corresponding
45 * the command value in the old zserv header. To allow old and new
46 * Zserv headers to be distinguished from each other.
47 */
48#define ZEBRA_HEADER_MARKER 254
49
718e3744 50/* For input/output buffer to zebra. */
f3f45626 51#define ZEBRA_MAX_PACKET_SIZ 16384U
718e3744 52
53/* Zebra header size. */
a9ff90c4 54#define ZEBRA_HEADER_SIZE 10
718e3744 55
689f5a8c
DL
56/* special socket path name to use TCP
57 * @ is used as first character because that's abstract socket names on Linux
58 */
59#define ZAPI_TCP_PATHNAME "@tcp"
60
7661461a
PG
61/* IPset size name stands for the name of the ipset entry
62 * that can be created by using some zapi interfaces
63 */
64#define ZEBRA_IPSET_NAME_SIZE 32
65
7abd6c4f
PG
66/* IPTable action is defined by two values: either
67 * forward or drop
68 */
69#define ZEBRA_IPTABLES_FORWARD 0
70#define ZEBRA_IPTABLES_DROP 1
71
57592a53
AD
72/* Zebra FEC register command flags. */
73#define ZEBRA_FEC_REGISTER_LABEL 0x1
74#define ZEBRA_FEC_REGISTER_LABEL_INDEX 0x2
75
689f5a8c
DL
76extern struct sockaddr_storage zclient_addr;
77extern socklen_t zclient_addr_len;
78
8613585e
DS
79/* Zebra message types. */
80typedef enum {
d62a17ae 81 ZEBRA_INTERFACE_ADD,
82 ZEBRA_INTERFACE_DELETE,
83 ZEBRA_INTERFACE_ADDRESS_ADD,
84 ZEBRA_INTERFACE_ADDRESS_DELETE,
85 ZEBRA_INTERFACE_UP,
86 ZEBRA_INTERFACE_DOWN,
e0ae31b8 87 ZEBRA_INTERFACE_SET_MASTER,
c3bd894e 88 ZEBRA_INTERFACE_SET_PROTODOWN,
0e51b4a3
RW
89 ZEBRA_ROUTE_ADD,
90 ZEBRA_ROUTE_DELETE,
7ea7b86e 91 ZEBRA_ROUTE_NOTIFY_OWNER,
d62a17ae 92 ZEBRA_REDISTRIBUTE_ADD,
93 ZEBRA_REDISTRIBUTE_DELETE,
94 ZEBRA_REDISTRIBUTE_DEFAULT_ADD,
95 ZEBRA_REDISTRIBUTE_DEFAULT_DELETE,
96 ZEBRA_ROUTER_ID_ADD,
97 ZEBRA_ROUTER_ID_DELETE,
98 ZEBRA_ROUTER_ID_UPDATE,
99 ZEBRA_HELLO,
09924cff 100 ZEBRA_CAPABILITIES,
d62a17ae 101 ZEBRA_NEXTHOP_REGISTER,
102 ZEBRA_NEXTHOP_UNREGISTER,
103 ZEBRA_NEXTHOP_UPDATE,
104 ZEBRA_INTERFACE_NBR_ADDRESS_ADD,
105 ZEBRA_INTERFACE_NBR_ADDRESS_DELETE,
106 ZEBRA_INTERFACE_BFD_DEST_UPDATE,
107 ZEBRA_IMPORT_ROUTE_REGISTER,
108 ZEBRA_IMPORT_ROUTE_UNREGISTER,
109 ZEBRA_IMPORT_CHECK_UPDATE,
d62a17ae 110 ZEBRA_BFD_DEST_REGISTER,
111 ZEBRA_BFD_DEST_DEREGISTER,
112 ZEBRA_BFD_DEST_UPDATE,
113 ZEBRA_BFD_DEST_REPLAY,
74489921
RW
114 ZEBRA_REDISTRIBUTE_ROUTE_ADD,
115 ZEBRA_REDISTRIBUTE_ROUTE_DEL,
d62a17ae 116 ZEBRA_VRF_UNREGISTER,
117 ZEBRA_VRF_ADD,
118 ZEBRA_VRF_DELETE,
c83c5e44 119 ZEBRA_VRF_LABEL,
d62a17ae 120 ZEBRA_INTERFACE_VRF_UPDATE,
121 ZEBRA_BFD_CLIENT_REGISTER,
d3af6147 122 ZEBRA_BFD_CLIENT_DEREGISTER,
d62a17ae 123 ZEBRA_INTERFACE_ENABLE_RADV,
124 ZEBRA_INTERFACE_DISABLE_RADV,
125 ZEBRA_IPV4_NEXTHOP_LOOKUP_MRIB,
126 ZEBRA_INTERFACE_LINK_PARAMS,
127 ZEBRA_MPLS_LABELS_ADD,
128 ZEBRA_MPLS_LABELS_DELETE,
ea6b290b 129 ZEBRA_MPLS_LABELS_REPLACE,
d62a17ae 130 ZEBRA_IPMR_ROUTE_STATS,
131 ZEBRA_LABEL_MANAGER_CONNECT,
f533be73 132 ZEBRA_LABEL_MANAGER_CONNECT_ASYNC,
d62a17ae 133 ZEBRA_GET_LABEL_CHUNK,
134 ZEBRA_RELEASE_LABEL_CHUNK,
135 ZEBRA_FEC_REGISTER,
136 ZEBRA_FEC_UNREGISTER,
137 ZEBRA_FEC_UPDATE,
1a98c087 138 ZEBRA_ADVERTISE_DEFAULT_GW,
fc08a52f 139 ZEBRA_ADVERTISE_SVI_MACIP,
31310b25 140 ZEBRA_ADVERTISE_SUBNET,
d62a17ae 141 ZEBRA_ADVERTISE_ALL_VNI,
50f74cf1 142 ZEBRA_LOCAL_ES_ADD,
143 ZEBRA_LOCAL_ES_DEL,
d62a17ae 144 ZEBRA_VNI_ADD,
145 ZEBRA_VNI_DEL,
b7cfce93
MK
146 ZEBRA_L3VNI_ADD,
147 ZEBRA_L3VNI_DEL,
d62a17ae 148 ZEBRA_REMOTE_VTEP_ADD,
149 ZEBRA_REMOTE_VTEP_DEL,
150 ZEBRA_MACIP_ADD,
151 ZEBRA_MACIP_DEL,
31310b25
MK
152 ZEBRA_IP_PREFIX_ROUTE_ADD,
153 ZEBRA_IP_PREFIX_ROUTE_DEL,
d62a17ae 154 ZEBRA_REMOTE_MACIP_ADD,
155 ZEBRA_REMOTE_MACIP_DEL,
3950b52c 156 ZEBRA_DUPLICATE_ADDR_DETECTION,
6833ae01 157 ZEBRA_PW_ADD,
158 ZEBRA_PW_DELETE,
159 ZEBRA_PW_SET,
160 ZEBRA_PW_UNSET,
161 ZEBRA_PW_STATUS_UPDATE,
e16abbb3
DS
162 ZEBRA_RULE_ADD,
163 ZEBRA_RULE_DELETE,
164 ZEBRA_RULE_NOTIFY_OWNER,
75fb51c1
PG
165 ZEBRA_TABLE_MANAGER_CONNECT,
166 ZEBRA_GET_TABLE_CHUNK,
167 ZEBRA_RELEASE_TABLE_CHUNK,
d59c13af
PG
168 ZEBRA_IPSET_CREATE,
169 ZEBRA_IPSET_DESTROY,
170 ZEBRA_IPSET_ENTRY_ADD,
171 ZEBRA_IPSET_ENTRY_DELETE,
425bdd6b
PG
172 ZEBRA_IPSET_NOTIFY_OWNER,
173 ZEBRA_IPSET_ENTRY_NOTIFY_OWNER,
7abd6c4f
PG
174 ZEBRA_IPTABLE_ADD,
175 ZEBRA_IPTABLE_DELETE,
176 ZEBRA_IPTABLE_NOTIFY_OWNER,
fbac9605 177 ZEBRA_VXLAN_FLOOD_CONTROL,
4ab3321f
AK
178 ZEBRA_VXLAN_SG_ADD,
179 ZEBRA_VXLAN_SG_DEL,
ecbbc3a7 180 ZEBRA_VXLAN_SG_REPLAY,
46c2687c
SK
181 ZEBRA_MLAG_PROCESS_UP,
182 ZEBRA_MLAG_PROCESS_DOWN,
36b5b98f
SK
183 ZEBRA_MLAG_CLIENT_REGISTER,
184 ZEBRA_MLAG_CLIENT_UNREGISTER,
185 ZEBRA_MLAG_FORWARD_MSG,
9ab0b2a3 186 ZEBRA_ERROR,
8613585e
DS
187} zebra_message_types_t;
188
9ab0b2a3
SW
189enum zebra_error_types {
190 ZEBRA_UNKNOWN_ERROR, /* Error of unknown type */
191 ZEBRA_NO_VRF, /* Vrf in header was not found */
192 ZEBRA_INVALID_MSG_TYPE, /* No handler found for msg type */
193};
194
195static inline const char *zebra_error_type2str(enum zebra_error_types type)
196{
197 const char *ret = "UNKNOWN";
198
199 switch (type) {
200 case ZEBRA_UNKNOWN_ERROR:
201 ret = "ZEBRA_UNKNOWN_ERROR";
202 break;
203 case ZEBRA_NO_VRF:
204 ret = "ZEBRA_NO_VRF";
205 break;
206 case ZEBRA_INVALID_MSG_TYPE:
207 ret = "ZEBRA_INVALID_MSG_TYPE";
208 break;
209 }
210
211 return ret;
212}
213
d62a17ae 214struct redist_proto {
d7c0a89a 215 uint8_t enabled;
d62a17ae 216 struct list *instances;
7c8ff89e
DS
217};
218
09924cff
DS
219struct zclient_capabilities {
220 uint32_t ecmp;
221 bool mpls_enabled;
02c0866d 222 enum mlag_role role;
09924cff
DS
223};
224
718e3744 225/* Structure for the zebra client. */
d62a17ae 226struct zclient {
227 /* The thread master we schedule ourselves on */
228 struct thread_master *master;
229
342213ea
DS
230 /* Priviledges to change socket values */
231 struct zebra_privs_t *privs;
232
e1a1880d
DS
233 /* Do we care about failure events for route install? */
234 bool receive_notify;
235
d62a17ae 236 /* Socket to zebra daemon. */
237 int sock;
238
d62a17ae 239 /* Connection failure count. */
240 int fail;
241
242 /* Input buffer for zebra message. */
243 struct stream *ibuf;
244
245 /* Output buffer for zebra message. */
246 struct stream *obuf;
247
248 /* Buffer of data waiting to be written to zebra. */
249 struct buffer *wb;
250
251 /* Read and connect thread. */
252 struct thread *t_read;
253 struct thread *t_connect;
254
255 /* Thread to write buffered data to zebra. */
256 struct thread *t_write;
257
258 /* Redistribute information. */
d7c0a89a
QY
259 uint8_t redist_default; /* clients protocol */
260 unsigned short instance;
d62a17ae 261 struct redist_proto mi_redist[AFI_MAX][ZEBRA_ROUTE_MAX];
262 vrf_bitmap_t redist[AFI_MAX][ZEBRA_ROUTE_MAX];
263
264 /* Redistribute defauilt. */
49db7a7b 265 vrf_bitmap_t default_information[AFI_MAX];
d62a17ae 266
6c33ca97
QY
267#define ZAPI_CALLBACK_ARGS \
268 int cmd, struct zclient *zclient, uint16_t length, vrf_id_t vrf_id
269
d62a17ae 270 /* Pointer to the callback functions. */
271 void (*zebra_connected)(struct zclient *);
09924cff 272 void (*zebra_capabilities)(struct zclient_capabilities *cap);
6c33ca97 273 int (*router_id_update)(ZAPI_CALLBACK_ARGS);
6c33ca97
QY
274 int (*interface_address_add)(ZAPI_CALLBACK_ARGS);
275 int (*interface_address_delete)(ZAPI_CALLBACK_ARGS);
276 int (*interface_link_params)(ZAPI_CALLBACK_ARGS);
277 int (*interface_bfd_dest_update)(ZAPI_CALLBACK_ARGS);
278 int (*interface_nbr_address_add)(ZAPI_CALLBACK_ARGS);
279 int (*interface_nbr_address_delete)(ZAPI_CALLBACK_ARGS);
280 int (*interface_vrf_update)(ZAPI_CALLBACK_ARGS);
281 int (*nexthop_update)(ZAPI_CALLBACK_ARGS);
282 int (*import_check_update)(ZAPI_CALLBACK_ARGS);
283 int (*bfd_dest_replay)(ZAPI_CALLBACK_ARGS);
284 int (*redistribute_route_add)(ZAPI_CALLBACK_ARGS);
285 int (*redistribute_route_del)(ZAPI_CALLBACK_ARGS);
d62a17ae 286 int (*fec_update)(int, struct zclient *, uint16_t);
6c33ca97
QY
287 int (*local_es_add)(ZAPI_CALLBACK_ARGS);
288 int (*local_es_del)(ZAPI_CALLBACK_ARGS);
289 int (*local_vni_add)(ZAPI_CALLBACK_ARGS);
290 int (*local_vni_del)(ZAPI_CALLBACK_ARGS);
291 int (*local_l3vni_add)(ZAPI_CALLBACK_ARGS);
292 int (*local_l3vni_del)(ZAPI_CALLBACK_ARGS);
293 void (*local_ip_prefix_add)(ZAPI_CALLBACK_ARGS);
294 void (*local_ip_prefix_del)(ZAPI_CALLBACK_ARGS);
295 int (*local_macip_add)(ZAPI_CALLBACK_ARGS);
296 int (*local_macip_del)(ZAPI_CALLBACK_ARGS);
297 int (*pw_status_update)(ZAPI_CALLBACK_ARGS);
298 int (*route_notify_owner)(ZAPI_CALLBACK_ARGS);
299 int (*rule_notify_owner)(ZAPI_CALLBACK_ARGS);
300 void (*label_chunk)(ZAPI_CALLBACK_ARGS);
301 int (*ipset_notify_owner)(ZAPI_CALLBACK_ARGS);
302 int (*ipset_entry_notify_owner)(ZAPI_CALLBACK_ARGS);
303 int (*iptable_notify_owner)(ZAPI_CALLBACK_ARGS);
304 int (*vxlan_sg_add)(ZAPI_CALLBACK_ARGS);
305 int (*vxlan_sg_del)(ZAPI_CALLBACK_ARGS);
46c2687c
SK
306 int (*mlag_process_up)(void);
307 int (*mlag_process_down)(void);
308 int (*mlag_handle_msg)(struct stream *msg, int len);
9ab0b2a3 309 int (*handle_error)(enum zebra_error_types error);
718e3744 310};
311
312/* Zebra API message flag. */
313#define ZAPI_MESSAGE_NEXTHOP 0x01
74489921
RW
314#define ZAPI_MESSAGE_DISTANCE 0x02
315#define ZAPI_MESSAGE_METRIC 0x04
316#define ZAPI_MESSAGE_TAG 0x08
317#define ZAPI_MESSAGE_MTU 0x10
318#define ZAPI_MESSAGE_SRCPFX 0x20
ba1849ef
DS
319/*
320 * This should only be used by a DAEMON that needs to communicate
321 * the table being used is not in the VRF. You must pass the
322 * default vrf, else this will be ignored.
323 */
324#define ZAPI_MESSAGE_TABLEID 0x80
718e3744 325
04772760 326#define ZSERV_VERSION 6
c1b9800a 327/* Zserv protocol message header */
124ead27 328struct zmsghdr {
d62a17ae 329 uint16_t length;
5530922e 330 /* Always set to 255 in new zserv */
124ead27 331 uint8_t marker;
d62a17ae 332 uint8_t version;
d62a17ae 333 vrf_id_t vrf_id;
334 uint16_t command;
6e8e0925
DS
335} __attribute__((packed));
336#define ZAPI_HEADER_CMD_LOCATION offsetof(struct zmsghdr, command)
c1b9800a 337
bb1b9c47
RW
338struct zapi_nexthop {
339 enum nexthop_types_t type;
4a7371e9 340 vrf_id_t vrf_id;
bb1b9c47 341 ifindex_t ifindex;
68a02e06 342 uint8_t flags;
09a484dd
DL
343 union {
344 union g_addr gate;
345 enum blackhole_type bh_type;
346 };
52dd3aa4
RW
347
348 /* MPLS labels for BGP-LU or Segment Routing */
349 uint8_t label_num;
350 mpls_label_t labels[MPLS_MAX_LABELS];
a317a9b9 351
352 struct ethaddr rmac;
bd054c1a
DS
353
354 uint32_t weight;
bb1b9c47
RW
355};
356
68a02e06
MS
357/*
358 * ZAPI nexthop flags values
359 */
360#define ZAPI_NEXTHOP_FLAG_ONLINK 0x01
361#define ZAPI_NEXTHOP_FLAG_LABEL 0x02
bd054c1a 362#define ZAPI_NEXTHOP_FLAG_WEIGHT 0x04
68a02e06 363
832d0f56
DS
364/*
365 * Some of these data structures do not map easily to
366 * a actual data structure size giving different compilers
367 * and systems. For those data structures we need
368 * to use the smallest available stream_getX/putX functions
369 * to encode/decode.
370 */
d62a17ae 371struct zapi_route {
d7c0a89a
QY
372 uint8_t type;
373 unsigned short instance;
657cde12 374
d7c0a89a 375 uint32_t flags;
da01a37a
DS
376/*
377 * Cause Zebra to consider this routes nexthops recursively
378 */
379#define ZEBRA_FLAG_ALLOW_RECURSION 0x01
380/*
381 * This is a route that is read in on startup that was left around
382 * from a previous run of FRR
383 */
384#define ZEBRA_FLAG_SELFROUTE 0x02
385/*
386 * This flag is used to tell Zebra that the BGP route being passed
387 * down is a IBGP route
388 */
389#define ZEBRA_FLAG_IBGP 0x04
390/*
391 * This is a route that has been selected for FIB installation.
392 * This flag is set in zebra and can be passed up to routing daemons
393 */
394#define ZEBRA_FLAG_SELECTED 0x08
395/*
396 * This is a route that we are telling Zebra that this route *must*
397 * win and will be installed even over ZEBRA_FLAG_SELECTED
398 */
399#define ZEBRA_FLAG_FIB_OVERRIDE 0x10
400/*
401 * This flag tells Zebra that the route is a EVPN route and should
402 * be treated specially
403 */
404#define ZEBRA_FLAG_EVPN_ROUTE 0x20
405/*
406 * This flag tells Zebra that it should treat the distance passed
407 * down as an additional discriminator for route selection of the
408 * route entry. This mainly is used for backup static routes.
409 */
410#define ZEBRA_FLAG_RR_USE_DISTANCE 0x40
657cde12 411
d7c0a89a 412 uint8_t message;
657cde12 413
832d0f56
DS
414 /*
415 * This is an enum but we are going to treat it as a uint8_t
416 * for purpose of encoding/decoding
417 */
d62a17ae 418 safi_t safi;
657cde12 419
bb1b9c47
RW
420 struct prefix prefix;
421 struct prefix_ipv6 src_prefix;
422
d7c0a89a 423 uint16_t nexthop_num;
bb1b9c47 424 struct zapi_nexthop nexthops[MULTIPATH_NUM];
657cde12 425
d7c0a89a 426 uint8_t distance;
657cde12 427
d7c0a89a 428 uint32_t metric;
657cde12 429
d62a17ae 430 route_tag_t tag;
657cde12 431
d7c0a89a 432 uint32_t mtu;
657cde12 433
d62a17ae 434 vrf_id_t vrf_id;
2dbad57f 435
ba1849ef 436 uint32_t tableid;
657cde12
DS
437};
438
ea6b290b
RW
439struct zapi_nexthop_label {
440 enum nexthop_types_t type;
441 int family;
442 union g_addr address;
443 ifindex_t ifindex;
444 mpls_label_t label;
445};
446
bad6b0e7 447struct zapi_labels {
b3c49d0e
RW
448 uint8_t message;
449#define ZAPI_LABELS_FTN 0x01
bad6b0e7 450 enum lsp_types_t type;
bad6b0e7 451 mpls_label_t local_label;
b3c49d0e
RW
452 struct {
453 struct prefix prefix;
454 uint8_t type;
455 unsigned short instance;
456 } route;
ea6b290b
RW
457 uint16_t nexthop_num;
458 struct zapi_nexthop_label nexthops[MULTIPATH_NUM];
bad6b0e7
RW
459};
460
6833ae01 461struct zapi_pw {
462 char ifname[IF_NAMESIZE];
463 ifindex_t ifindex;
464 int type;
465 int af;
466 union g_addr nexthop;
467 uint32_t local_label;
468 uint32_t remote_label;
469 uint8_t flags;
470 union pw_protocol_fields data;
471 uint8_t protocol;
472};
473
474struct zapi_pw_status {
475 char ifname[IF_NAMESIZE];
476 ifindex_t ifindex;
477 uint32_t status;
478};
479
7ea7b86e
DS
480enum zapi_route_notify_owner {
481 ZAPI_ROUTE_FAIL_INSTALL,
482 ZAPI_ROUTE_BETTER_ADMIN_WON,
483 ZAPI_ROUTE_INSTALLED,
5e54c602
DS
484 ZAPI_ROUTE_REMOVED,
485 ZAPI_ROUTE_REMOVE_FAIL,
7ea7b86e
DS
486};
487
0031a6bb
PG
488enum zapi_rule_notify_owner {
489 ZAPI_RULE_FAIL_INSTALL,
490 ZAPI_RULE_INSTALLED,
491 ZAPI_RULE_REMOVED,
34d9d5be 492 ZAPI_RULE_FAIL_REMOVE,
0031a6bb
PG
493};
494
7661461a
PG
495enum ipset_type {
496 IPSET_NET_NET = 1,
497 IPSET_NET_PORT_NET,
498 IPSET_NET_PORT,
499 IPSET_NET
500};
501
425bdd6b
PG
502enum zapi_ipset_notify_owner {
503 ZAPI_IPSET_FAIL_INSTALL,
504 ZAPI_IPSET_INSTALLED,
505 ZAPI_IPSET_REMOVED,
34d9d5be 506 ZAPI_IPSET_FAIL_REMOVE,
425bdd6b
PG
507};
508
509enum zapi_ipset_entry_notify_owner {
510 ZAPI_IPSET_ENTRY_FAIL_INSTALL,
511 ZAPI_IPSET_ENTRY_INSTALLED,
512 ZAPI_IPSET_ENTRY_REMOVED,
34d9d5be 513 ZAPI_IPSET_ENTRY_FAIL_REMOVE,
425bdd6b
PG
514};
515
7abd6c4f
PG
516enum zapi_iptable_notify_owner {
517 ZAPI_IPTABLE_FAIL_INSTALL,
518 ZAPI_IPTABLE_INSTALLED,
519 ZAPI_IPTABLE_REMOVED,
34d9d5be 520 ZAPI_IPTABLE_FAIL_REMOVE,
7abd6c4f
PG
521};
522
eb5d458b
SW
523static inline const char *
524zapi_rule_notify_owner2str(enum zapi_rule_notify_owner note)
525{
526 const char *ret = "UNKNOWN";
527
528 switch (note) {
529 case ZAPI_RULE_FAIL_INSTALL:
530 ret = "ZAPI_RULE_FAIL_INSTALL";
531 break;
532 case ZAPI_RULE_INSTALLED:
533 ret = "ZAPI_RULE_INSTALLED";
534 break;
535 case ZAPI_RULE_FAIL_REMOVE:
536 ret = "ZAPI_RULE_FAIL_REMOVE";
537 break;
538 case ZAPI_RULE_REMOVED:
539 ret = "ZAPI_RULE_REMOVED";
540 break;
541 }
542
543 return ret;
544}
545
1a98c087 546/* Zebra MAC types */
ead40654
MK
547#define ZEBRA_MACIP_TYPE_STICKY 0x01 /* Sticky MAC*/
548#define ZEBRA_MACIP_TYPE_GW 0x02 /* gateway (SVI) mac*/
68e33151
CS
549#define ZEBRA_MACIP_TYPE_ROUTER_FLAG 0x04 /* Router Flag - proxy NA */
550#define ZEBRA_MACIP_TYPE_OVERRIDE_FLAG 0x08 /* Override Flag */
0ca10580 551#define ZEBRA_MACIP_TYPE_SVI_IP 0x10 /* SVI MAC-IP */
1a98c087 552
2c476b72
AK
553enum zebra_neigh_state { ZEBRA_NEIGH_INACTIVE = 0, ZEBRA_NEIGH_ACTIVE = 1 };
554
e1a1880d
DS
555struct zclient_options {
556 bool receive_notify;
557};
558
e1a1880d
DS
559extern struct zclient_options zclient_options_default;
560
26f63a1e
DS
561extern struct zclient *zclient_new(struct thread_master *m,
562 struct zclient_options *opt);
e1a1880d 563
d7c0a89a 564extern void zclient_init(struct zclient *, int, unsigned short,
996c9314 565 struct zebra_privs_t *privs);
d62a17ae 566extern int zclient_start(struct zclient *);
567extern void zclient_stop(struct zclient *);
568extern void zclient_reset(struct zclient *);
569extern void zclient_free(struct zclient *);
634f9ea2 570
d62a17ae 571extern int zclient_socket_connect(struct zclient *);
718e3744 572
d7c0a89a
QY
573extern unsigned short *redist_check_instance(struct redist_proto *,
574 unsigned short);
575extern void redist_add_instance(struct redist_proto *, unsigned short);
576extern void redist_del_instance(struct redist_proto *, unsigned short);
7c8ff89e 577
c83c5e44
DS
578/*
579 * Send to zebra that the specified vrf is using label to resolve
580 * itself for L3VPN's. Repeated calls of this function with
581 * different labels will cause an effective update of the
42567e00 582 * label for lookup. If you pass in MPLS_LABEL_NONE
c83c5e44
DS
583 * we will cause a delete action and remove this label pop
584 * operation.
7d061b3c
DS
585 *
586 * The underlying AF_MPLS doesn't care about afi's
587 * but we can make the zebra_vrf keep track of what
588 * we have installed and play some special games
589 * to get them both installed.
c83c5e44
DS
590 */
591extern void zclient_send_vrf_label(struct zclient *zclient, vrf_id_t vrf_id,
7d061b3c
DS
592 afi_t afi, mpls_label_t label,
593 enum lsp_types_t ltype);
c83c5e44 594
d62a17ae 595extern void zclient_send_reg_requests(struct zclient *, vrf_id_t);
596extern void zclient_send_dereg_requests(struct zclient *, vrf_id_t);
7076bb2f 597
d62a17ae 598extern void zclient_send_interface_radv_req(struct zclient *zclient,
599 vrf_id_t vrf_id,
600 struct interface *ifp, int enable,
601 int ra_interval);
c3bd894e
QY
602extern int zclient_send_interface_protodown(struct zclient *zclient,
603 vrf_id_t vrf_id,
604 struct interface *ifp, bool down);
4a04e5f7 605
634f9ea2 606/* Send redistribute command to zebra daemon. Do not update zclient state. */
d62a17ae 607extern int zebra_redistribute_send(int command, struct zclient *, afi_t,
d7c0a89a
QY
608 int type, unsigned short instance,
609 vrf_id_t vrf_id);
634f9ea2 610
49db7a7b
RW
611extern int zebra_redistribute_default_send(int command, struct zclient *zclient,
612 afi_t afi, vrf_id_t vrf_id);
613
634f9ea2 614/* If state has changed, update state and call zebra_redistribute_send. */
d62a17ae 615extern void zclient_redistribute(int command, struct zclient *, afi_t, int type,
d7c0a89a 616 unsigned short instance, vrf_id_t vrf_id);
634f9ea2 617
618/* If state has changed, update state and send the command to zebra. */
d62a17ae 619extern void zclient_redistribute_default(int command, struct zclient *,
49db7a7b 620 afi_t, vrf_id_t vrf_id);
718e3744 621
634f9ea2 622/* Send the message in zclient->obuf to the zebra daemon (or enqueue it).
623 Returns 0 for success or -1 on an I/O error. */
624extern int zclient_send_message(struct zclient *);
718e3744 625
d211086a 626/* create header for command, length to be filled in by user later */
d62a17ae 627extern void zclient_create_header(struct stream *, uint16_t, vrf_id_t);
124ead27
QY
628/*
629 * Read sizeof(struct zmsghdr) bytes from the provided socket and parse the
630 * received data into the specified fields. If this is successful, read the
631 * rest of the packet into the provided stream.
632 *
633 * s
634 * The stream to read into
635 *
636 * sock
637 * The socket to read from
638 *
639 * size
640 * Parsed message size will be placed in the pointed-at integer
641 *
642 * marker
643 * Parsed marker will be placed in the pointed-at byte
644 *
645 * version
646 * Parsed version will be placed in the pointed-at byte
647 *
648 * vrf_id
649 * Parsed VRF ID will be placed in the pointed-at vrf_id_t
650 *
651 * cmd
652 * Parsed command number will be placed in the pointed-at integer
653 *
654 * Returns:
655 * -1 if:
656 * - insufficient data for header was read
657 * - a version mismatch was detected
658 * - a marker mismatch was detected
659 * - header size field specified more data than could be read
660 */
d7c0a89a
QY
661extern int zclient_read_header(struct stream *s, int sock, uint16_t *size,
662 uint8_t *marker, uint8_t *version,
663 vrf_id_t *vrf_id, uint16_t *cmd);
124ead27
QY
664/*
665 * Parse header from ZAPI message stream into struct zmsghdr.
666 * This function assumes the stream getp points at the first byte of the header.
667 * If the function is successful then the stream getp will point to the byte
668 * immediately after the last byte of the header.
669 *
670 * zmsg
671 * The stream containing the header
672 *
673 * hdr
674 * The header struct to parse into.
675 *
676 * Returns:
677 * true if parsing succeeded, false otherwise
678 */
679extern bool zapi_parse_header(struct stream *zmsg, struct zmsghdr *hdr);
d62a17ae 680
e0ae31b8
DS
681extern void zclient_interface_set_master(struct zclient *client,
682 struct interface *master,
683 struct interface *slave);
d62a17ae 684extern struct interface *zebra_interface_state_read(struct stream *s, vrf_id_t);
685extern struct connected *zebra_interface_address_read(int, struct stream *,
686 vrf_id_t);
687extern struct nbr_connected *
688zebra_interface_nbr_address_read(int, struct stream *, vrf_id_t);
689extern struct interface *zebra_interface_vrf_update_read(struct stream *s,
690 vrf_id_t vrf_id,
691 vrf_id_t *new_vrf_id);
d62a17ae 692extern void zebra_router_id_update_read(struct stream *s, struct prefix *rid);
0cb76b9d 693
edc12762
RW
694extern struct interface *zebra_interface_link_params_read(struct stream *s,
695 vrf_id_t vrf_id);
d62a17ae 696extern size_t zebra_interface_link_params_write(struct stream *,
697 struct interface *);
0e3b6a92
EDP
698extern int zclient_send_get_label_chunk(struct zclient *zclient, uint8_t keep,
699 uint32_t chunk_size, uint32_t base);
955bfd98 700
f533be73 701extern int lm_label_manager_connect(struct zclient *zclient, int async);
d7c0a89a 702extern int lm_get_label_chunk(struct zclient *zclient, uint8_t keep,
0e3b6a92
EDP
703 uint32_t base, uint32_t chunk_size,
704 uint32_t *start, uint32_t *end);
d62a17ae 705extern int lm_release_label_chunk(struct zclient *zclient, uint32_t start,
706 uint32_t end);
75fb51c1
PG
707extern int tm_table_manager_connect(struct zclient *zclient);
708extern int tm_get_table_chunk(struct zclient *zclient, uint32_t chunk_size,
709 uint32_t *start, uint32_t *end);
710extern int tm_release_table_chunk(struct zclient *zclient, uint32_t start,
711 uint32_t end);
712
bad6b0e7
RW
713extern int zebra_send_mpls_labels(struct zclient *zclient, int cmd,
714 struct zapi_labels *zl);
715extern int zapi_labels_encode(struct stream *s, int cmd,
716 struct zapi_labels *zl);
717extern int zapi_labels_decode(struct stream *s, struct zapi_labels *zl);
718
6833ae01 719extern int zebra_send_pw(struct zclient *zclient, int command,
720 struct zapi_pw *pw);
121f9dee 721extern void zebra_read_pw_status_update(ZAPI_CALLBACK_ARGS, struct zapi_pw_status *pw);
6833ae01 722
d7c0a89a 723extern int zclient_route_send(uint8_t, struct zclient *, struct zapi_route *);
3c192540
DS
724extern int zclient_send_rnh(struct zclient *zclient, int command,
725 struct prefix *p, bool exact_match,
726 vrf_id_t vrf_id);
68a02e06
MS
727int zapi_nexthop_encode(struct stream *s, const struct zapi_nexthop *api_nh,
728 uint32_t api_flags);
d7c0a89a 729extern int zapi_route_encode(uint8_t, struct stream *, struct zapi_route *);
0e51b4a3 730extern int zapi_route_decode(struct stream *, struct zapi_route *);
7ea7b86e 731bool zapi_route_notify_decode(struct stream *s, struct prefix *p,
28610f7e 732 uint32_t *tableid,
7ea7b86e 733 enum zapi_route_notify_owner *note);
b6c5d343
DS
734bool zapi_rule_notify_decode(struct stream *s, uint32_t *seqno,
735 uint32_t *priority, uint32_t *unique,
736 ifindex_t *ifindex,
737 enum zapi_rule_notify_owner *note);
425bdd6b
PG
738bool zapi_ipset_notify_decode(struct stream *s,
739 uint32_t *unique,
740 enum zapi_ipset_notify_owner *note);
741
742#define ZEBRA_IPSET_NAME_SIZE 32
743
744bool zapi_ipset_entry_notify_decode(struct stream *s,
745 uint32_t *unique,
746 char *ipset_name,
747 enum zapi_ipset_entry_notify_owner *note);
c16a0a62
PG
748bool zapi_iptable_notify_decode(struct stream *s,
749 uint32_t *unique,
750 enum zapi_iptable_notify_owner *note);
425bdd6b 751
4a749e2c 752extern struct nexthop *nexthop_from_zapi_nexthop(struct zapi_nexthop *znh);
68a02e06
MS
753int zapi_nexthop_from_nexthop(struct zapi_nexthop *znh,
754 const struct nexthop *nh);
4a749e2c
DS
755extern bool zapi_nexthop_update_decode(struct stream *s,
756 struct zapi_route *nhr);
718e3744 757
9ab0b2a3
SW
758/* Decode the zebra error message */
759extern bool zapi_error_decode(struct stream *s, enum zebra_error_types *error);
760
09a484dd 761static inline void zapi_route_set_blackhole(struct zapi_route *api,
60466a63 762 enum blackhole_type bh_type)
09a484dd
DL
763{
764 api->nexthop_num = 1;
765 api->nexthops[0].type = NEXTHOP_TYPE_BLACKHOLE;
4a7371e9 766 api->nexthops[0].vrf_id = VRF_DEFAULT;
09a484dd
DL
767 api->nexthops[0].bh_type = bh_type;
768 SET_FLAG(api->message, ZAPI_MESSAGE_NEXTHOP);
769};
770
36b5b98f
SK
771extern void zclient_send_mlag_register(struct zclient *client,
772 uint32_t bit_map);
773extern void zclient_send_mlag_deregister(struct zclient *client);
774
775extern void zclient_send_mlag_data(struct zclient *client,
776 struct stream *client_s);
09a484dd 777
718e3744 778#endif /* _ZEBRA_ZCLIENT_H */