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