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