1 /* Zebra's client header.
2 * Copyright (C) 1999 Kunihiro Ishiguro
4 * This file is part of GNU Zebra.
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)
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.
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
21 #ifndef _ZEBRA_ZCLIENT_H
22 #define _ZEBRA_ZCLIENT_H
24 /* For struct zapi_route. */
28 /* For struct interface and struct connected. */
31 /* For vrf_bitmap_t. */
34 /* For union g_addr */
37 /* For union pw_protocol_fields */
48 /* Zebra types. Used in Zserv message header. */
49 typedef uint16_t zebra_size_t
;
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.
55 #define ZEBRA_HEADER_MARKER 254
57 /* For input/output buffer to zebra. */
58 #define ZEBRA_MAX_PACKET_SIZ 16384U
59 #define ZEBRA_SMALL_PACKET_SIZE 200U
61 /* Zebra header size. */
62 #define ZEBRA_HEADER_SIZE 10
64 /* special socket path name to use TCP
65 * @ is used as first character because that's abstract socket names on Linux
67 #define ZAPI_TCP_PATHNAME "@tcp"
69 /* IPset size name stands for the name of the ipset entry
70 * that can be created by using some zapi interfaces
72 #define ZEBRA_IPSET_NAME_SIZE 32
74 /* IPTable action is defined by two values: either
77 #define ZEBRA_IPTABLES_FORWARD 0
78 #define ZEBRA_IPTABLES_DROP 1
80 /* Zebra FEC register command flags. */
81 #define ZEBRA_FEC_REGISTER_LABEL 0x1
82 #define ZEBRA_FEC_REGISTER_LABEL_INDEX 0x2
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
93 /* Macro to check if there GR enabled. */
94 #define ZEBRA_CLIENT_GR_ENABLED(X) (X == ZEBRA_CLIENT_GR_CAPABILITIES)
96 #define ZEBRA_SR_POLICY_NAME_MAX_LENGTH 100
98 extern struct sockaddr_storage zclient_addr
;
99 extern socklen_t zclient_addr_len
;
101 /* Zebra message types. */
104 ZEBRA_INTERFACE_DELETE
,
105 ZEBRA_INTERFACE_ADDRESS_ADD
,
106 ZEBRA_INTERFACE_ADDRESS_DELETE
,
108 ZEBRA_INTERFACE_DOWN
,
109 ZEBRA_INTERFACE_SET_MASTER
,
110 ZEBRA_INTERFACE_SET_PROTODOWN
,
113 ZEBRA_ROUTE_NOTIFY_OWNER
,
114 ZEBRA_REDISTRIBUTE_ADD
,
115 ZEBRA_REDISTRIBUTE_DELETE
,
116 ZEBRA_REDISTRIBUTE_DEFAULT_ADD
,
117 ZEBRA_REDISTRIBUTE_DEFAULT_DELETE
,
119 ZEBRA_ROUTER_ID_DELETE
,
120 ZEBRA_ROUTER_ID_UPDATE
,
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
,
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
,
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
,
158 ZEBRA_FEC_UNREGISTER
,
160 ZEBRA_ADVERTISE_DEFAULT_GW
,
161 ZEBRA_ADVERTISE_SVI_MACIP
,
162 ZEBRA_ADVERTISE_SUBNET
,
163 ZEBRA_ADVERTISE_ALL_VNI
,
166 ZEBRA_REMOTE_ES_VTEP_ADD
,
167 ZEBRA_REMOTE_ES_VTEP_DEL
,
168 ZEBRA_LOCAL_ES_EVI_ADD
,
169 ZEBRA_LOCAL_ES_EVI_DEL
,
174 ZEBRA_REMOTE_VTEP_ADD
,
175 ZEBRA_REMOTE_VTEP_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
,
187 ZEBRA_PW_STATUS_UPDATE
,
190 ZEBRA_RULE_NOTIFY_OWNER
,
191 ZEBRA_TABLE_MANAGER_CONNECT
,
192 ZEBRA_GET_TABLE_CHUNK
,
193 ZEBRA_RELEASE_TABLE_CHUNK
,
196 ZEBRA_IPSET_ENTRY_ADD
,
197 ZEBRA_IPSET_ENTRY_DELETE
,
198 ZEBRA_IPSET_NOTIFY_OWNER
,
199 ZEBRA_IPSET_ENTRY_NOTIFY_OWNER
,
201 ZEBRA_IPTABLE_DELETE
,
202 ZEBRA_IPTABLE_NOTIFY_OWNER
,
203 ZEBRA_VXLAN_FLOOD_CONTROL
,
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
,
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
,
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
,
239 ZEBRA_GRE_SOURCE_SET
,
240 } zebra_message_types_t
;
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 */
248 static inline const char *zebra_error_type2str(enum zebra_error_types type
)
250 const char *ret
= "UNKNOWN";
253 case ZEBRA_UNKNOWN_ERROR
:
254 ret
= "ZEBRA_UNKNOWN_ERROR";
257 ret
= "ZEBRA_NO_VRF";
259 case ZEBRA_INVALID_MSG_TYPE
:
260 ret
= "ZEBRA_INVALID_MSG_TYPE";
267 struct redist_proto
{
269 struct list
*instances
;
272 struct zclient_capabilities
{
278 /* Graceful Restart Capabilities message */
280 enum zserv_client_capabilities cap
;
281 uint32_t stale_removal_time
;
287 /* Structure for the zebra client. */
289 /* The thread master we schedule ourselves on */
290 struct thread_master
*master
;
292 /* Priviledges to change socket values */
293 struct zebra_privs_t
*privs
;
295 /* Do we care about failure events for route install? */
298 /* Is this a synchronous client? */
301 /* Session id (optional) to support clients with multiple sessions */
304 /* Socket to zebra daemon. */
307 /* Connection failure count. */
310 /* Input buffer for zebra message. */
313 /* Output buffer for zebra message. */
316 /* Buffer of data waiting to be written to zebra. */
319 /* Read and connect thread. */
320 struct thread
*t_read
;
321 struct thread
*t_connect
;
323 /* Thread to write buffered data to zebra. */
324 struct thread
*t_write
;
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
];
332 /* Redistribute defauilt. */
333 vrf_bitmap_t default_information
[AFI_MAX
];
335 #define ZAPI_CALLBACK_ARGS \
336 int cmd, struct zclient *zclient, uint16_t length, vrf_id_t vrf_id
338 /* Pointer to the callback functions. */
339 void (*zebra_connected
)(struct zclient
*);
340 void (*zebra_capabilities
)(struct zclient_capabilities
*cap
);
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
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
);
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
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.
423 #define ZAPI_MESSAGE_TABLEID 0x0100
424 #define ZAPI_MESSAGE_SRTE 0x0200
425 #define ZAPI_MESSAGE_OPAQUE 0x0400
427 #define ZSERV_VERSION 6
428 /* Zserv protocol message header */
431 /* Always set to 255 in new zserv */
436 } __attribute__((packed
));
437 #define ZAPI_HEADER_CMD_LOCATION offsetof(struct zmsghdr, command)
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().
444 struct zapi_nexthop
{
445 enum nexthop_types_t type
;
451 enum blackhole_type bh_type
;
454 /* MPLS labels for BGP-LU or Segment Routing */
456 mpls_label_t labels
[MPLS_MAX_LABELS
];
462 /* Backup nexthops, for IP-FRR, TI-LFA, etc */
464 uint8_t backup_idx
[NEXTHOP_MAX_BACKUPS
];
469 /* SRv6 localsid info for Endpoint-behaviour */
470 uint32_t seg6local_action
;
471 struct seg6local_context seg6local_ctx
;
473 /* SRv6 Headend-behaviour */
474 struct in6_addr seg6_segs
;
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.
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
491 * ZAPI Nexthop Group. For use with protocol creation of nexthop groups.
497 uint16_t nexthop_num
;
498 struct zapi_nexthop nexthops
[MULTIPATH_NUM
];
500 uint16_t backup_nexthop_num
;
501 struct zapi_nexthop backup_nexthops
[MULTIPATH_NUM
];
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
513 unsigned short instance
;
515 /* If you add flags, update zclient_dump_route_flags */
518 * Cause Zebra to consider this routes nexthops recursively
520 #define ZEBRA_FLAG_ALLOW_RECURSION 0x01
522 * This is a route that is read in on startup that was left around
523 * from a previous run of FRR
525 #define ZEBRA_FLAG_SELFROUTE 0x02
527 * This flag is used to tell Zebra that the BGP route being passed
528 * down is a IBGP route
530 #define ZEBRA_FLAG_IBGP 0x04
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
535 #define ZEBRA_FLAG_SELECTED 0x08
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
540 #define ZEBRA_FLAG_FIB_OVERRIDE 0x10
542 * This flag tells Zebra that the route is a EVPN route and should
543 * be treated specially
545 #define ZEBRA_FLAG_EVPN_ROUTE 0x20
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.
551 #define ZEBRA_FLAG_RR_USE_DISTANCE 0x40
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
558 #define ZEBRA_FLAG_TRAPPED 0x80
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
565 #define ZEBRA_FLAG_OFFLOADED 0x100
567 * This flag tells everyone that the route has
569 * This flag makes no sense unless you are in an asic
572 #define ZEBRA_FLAG_OFFLOAD_FAILED 0x200
574 /* The older XXX_MESSAGE flags live here */
578 * This is an enum but we are going to treat it as a uint8_t
579 * for purpose of encoding/decoding
583 struct prefix prefix
;
584 struct prefix_ipv6 src_prefix
;
586 uint16_t nexthop_num
;
587 struct zapi_nexthop nexthops
[MULTIPATH_NUM
];
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
];
607 /* SR-TE color (used for nexthop updates only). */
610 #define ZAPI_MESSAGE_OPAQUE_LENGTH 1024
613 uint8_t data
[ZAPI_MESSAGE_OPAQUE_LENGTH
];
617 extern char *zclient_dump_route_flags(uint32_t flags
, char *buf
, size_t len
);
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
;
626 struct prefix prefix
;
628 unsigned short instance
;
631 uint16_t nexthop_num
;
632 struct zapi_nexthop nexthops
[MULTIPATH_NUM
];
634 /* Backup nexthops, if present */
635 uint16_t backup_nexthop_num
;
636 struct zapi_nexthop backup_nexthops
[MULTIPATH_NUM
];
639 struct zapi_srte_tunnel
{
640 enum lsp_types_t type
;
641 mpls_label_t local_label
;
643 mpls_label_t labels
[MPLS_MAX_LABELS
];
646 struct zapi_sr_policy
{
648 struct ipaddr endpoint
;
649 char name
[SRTE_POLICY_NAME_MAX_LENGTH
];
650 struct zapi_srte_tunnel segment_list
;
655 char ifname
[IF_NAMESIZE
];
659 union g_addr nexthop
;
660 uint32_t local_label
;
661 uint32_t remote_label
;
663 union pw_protocol_fields data
;
667 struct zapi_pw_status
{
668 char ifname
[IF_NAMESIZE
];
673 /* IGP instance data associated to a RLFA. */
674 struct zapi_rlfa_igp
{
689 /* IGP -> LDP RLFA (un)registration message. */
690 struct zapi_rlfa_request
{
691 /* IGP instance data. */
692 struct zapi_rlfa_igp igp
;
694 /* Destination prefix. */
695 struct prefix destination
;
697 /* PQ node address. */
698 struct in_addr pq_address
;
701 /* LDP -> IGP RLFA label update. */
702 struct zapi_rlfa_response
{
703 /* IGP instance data. */
704 struct zapi_rlfa_igp igp
;
706 /* Destination prefix. */
707 struct prefix destination
;
709 /* Resolved LDP labels. */
710 mpls_label_t pq_label
;
711 uint16_t nexthop_num
;
716 } nexthops
[MULTIPATH_NUM
];
719 enum zapi_route_notify_owner
{
720 ZAPI_ROUTE_FAIL_INSTALL
,
721 ZAPI_ROUTE_BETTER_ADMIN_WON
,
722 ZAPI_ROUTE_INSTALLED
,
724 ZAPI_ROUTE_REMOVE_FAIL
,
727 enum zapi_nhg_notify_owner
{
728 ZAPI_NHG_FAIL_INSTALL
,
731 ZAPI_NHG_REMOVE_FAIL
,
734 enum zapi_rule_notify_owner
{
735 ZAPI_RULE_FAIL_INSTALL
,
738 ZAPI_RULE_FAIL_REMOVE
,
748 enum zapi_ipset_notify_owner
{
749 ZAPI_IPSET_FAIL_INSTALL
= 0,
750 ZAPI_IPSET_INSTALLED
,
752 ZAPI_IPSET_FAIL_REMOVE
,
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
,
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
,
769 enum zclient_send_status
{
770 ZCLIENT_SEND_FAILURE
= -1,
771 ZCLIENT_SEND_SUCCESS
= 0,
772 ZCLIENT_SEND_BUFFERED
= 1
775 static inline const char *
776 zapi_nhg_notify_owner2str(enum zapi_nhg_notify_owner note
)
778 const char *ret
= "UNKNOWN";
781 case ZAPI_NHG_FAIL_INSTALL
:
782 ret
= "ZAPI_NHG_FAIL_INSTALL";
784 case ZAPI_NHG_INSTALLED
:
785 ret
= "ZAPI_NHG_INSTALLED";
787 case ZAPI_NHG_REMOVE_FAIL
:
788 ret
= "ZAPI_NHG_REMOVE_FAIL";
790 case ZAPI_NHG_REMOVED
:
791 ret
= "ZAPI_NHG_REMOVED";
798 static inline const char *
799 zapi_rule_notify_owner2str(enum zapi_rule_notify_owner note
)
801 const char *ret
= "UNKNOWN";
804 case ZAPI_RULE_FAIL_INSTALL
:
805 ret
= "ZAPI_RULE_FAIL_INSTALL";
807 case ZAPI_RULE_INSTALLED
:
808 ret
= "ZAPI_RULE_INSTALLED";
810 case ZAPI_RULE_FAIL_REMOVE
:
811 ret
= "ZAPI_RULE_FAIL_REMOVE";
813 case ZAPI_RULE_REMOVED
:
814 ret
= "ZAPI_RULE_REMOVED";
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
832 #define MACIP_BUF_SIZE 128
833 extern char *zclient_evpn_dump_macip_flags(uint8_t flags
, char *buf
,
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.
840 #define ZAPI_ES_VTEP_FLAG_ESR_RXED (1 << 0)
842 enum zebra_neigh_state
{ ZEBRA_NEIGH_INACTIVE
= 0, ZEBRA_NEIGH_ACTIVE
= 1 };
844 struct zclient_options
{
849 extern struct zclient_options zclient_options_default
;
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)
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)
867 struct zapi_neigh_ip
{
870 struct ipaddr ip_out
;
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
,
880 * We reserve the top 4 bits for l2-NHG, everything else
881 * is for zebra/proto l3-NHG.
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
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))
893 extern uint32_t zclient_get_nhg_start(uint32_t proto
);
895 extern struct zclient
*zclient_new(struct thread_master
*m
,
896 struct zclient_options
*opt
);
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
*);
905 extern int zclient_socket_connect(struct zclient
*);
907 extern unsigned short *redist_check_instance(struct redist_proto
*,
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
);
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
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.
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
);
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
);
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
,
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
);
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
);
955 extern enum zclient_send_status
956 zebra_redistribute_default_send(int command
, struct zclient
*zclient
, afi_t afi
,
959 /* Send route notify request to zebra */
960 extern int zebra_route_notify_send(int command
, struct zclient
*zclient
,
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
);
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
);
972 * Send the message in zclient->obuf to the zebra daemon (or enqueue it).
975 * 0 data was successfully sent
976 * 1 data was buffered for future usage
978 extern enum zclient_send_status
zclient_send_message(struct zclient
*);
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
);
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.
988 * The stream to read into
991 * The socket to read from
994 * Parsed message size will be placed in the pointed-at integer
997 * Parsed marker will be placed in the pointed-at byte
1000 * Parsed version will be placed in the pointed-at byte
1003 * Parsed VRF ID will be placed in the pointed-at vrf_id_t
1006 * Parsed command number will be placed in the pointed-at integer
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
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
);
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.
1025 * The stream containing the header
1028 * The header struct to parse into.
1031 * true if parsing succeeded, false otherwise
1033 extern bool zapi_parse_header(struct stream
*zmsg
, struct zmsghdr
*hdr
);
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
*,
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
,
1045 vrf_id_t
*new_vrf_id
);
1046 extern int zebra_router_id_update_read(struct stream
*s
, struct prefix
*rid
);
1048 extern struct interface
*zebra_interface_link_params_read(struct stream
*s
,
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
);
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
,
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
,
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
);
1073 extern enum zclient_send_status
zebra_send_sr_policy(struct zclient
*zclient
,
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
);
1082 extern enum zclient_send_status
zebra_send_mpls_labels(struct zclient
*zclient
,
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
);
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
);
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
);
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
,
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
,
1124 enum zapi_ipset_notify_owner
*note
);
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
);
1130 #define ZEBRA_IPSET_NAME_SIZE 32
1132 bool zapi_ipset_entry_notify_decode(struct stream
*s
,
1135 enum zapi_ipset_entry_notify_owner
*note
);
1136 bool zapi_iptable_notify_decode(struct stream
*s
,
1138 enum zapi_iptable_notify_owner
*note
);
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
,
1151 /* Decode the zebra error message */
1152 extern bool zapi_error_decode(struct stream
*s
, enum zebra_error_types
*error
);
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
);
1160 static inline void zapi_route_set_blackhole(struct zapi_route
*api
,
1161 enum blackhole_type bh_type
)
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
);
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
);
1175 extern enum zclient_send_status
zclient_send_mlag_data(struct zclient
*client
,
1176 struct stream
*client_s
);
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.
1186 enum zclient_send_status
zclient_send_opaque(struct zclient
*zclient
,
1187 uint32_t type
, const uint8_t *data
,
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
,
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 */
1202 /* Client-specific info - *if* UNICAST flag is set */
1205 uint32_t session_id
;
1208 #define ZAPI_OPAQUE_FLAG_UNICAST 0x01
1210 /* Simple struct to convey registration/unreg requests */
1211 struct zapi_opaque_reg_info
{
1212 /* Message subtype */
1215 /* Client session tuple */
1218 uint32_t session_id
;
1221 /* Decode incoming opaque */
1222 int zclient_opaque_decode(struct stream
*msg
, struct zapi_opaque_msg
*info
);
1224 enum zclient_send_status
zclient_register_opaque(struct zclient
*zclient
,
1226 enum zclient_send_status
zclient_unregister_opaque(struct zclient
*zclient
,
1228 int zapi_opaque_reg_decode(struct stream
*msg
,
1229 struct zapi_opaque_reg_info
*info
);
1232 * Registry of opaque message types. Please do not reuse an in-use
1233 * type code; some daemons are likely relying on it.
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,
1254 /* Send the hello message.
1255 * Returns 0 for success or -1 on an I/O error.
1257 extern enum zclient_send_status
zclient_send_hello(struct zclient
*client
);
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
);
1264 struct zapi_client_close_info
{
1265 /* Client session tuple */
1268 uint32_t session_id
;
1271 /* Decode incoming client close notify */
1272 extern int zapi_client_close_notify_decode(struct stream
*s
,
1273 struct zapi_client_close_info
*info
);
1275 extern int zclient_send_zebra_gre_request(struct zclient
*client
,
1276 struct interface
*ifp
);
1281 #endif /* _ZEBRA_ZCLIENT_H */