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
26 /* For struct zapi_route. */
30 /* For struct interface and struct connected. */
33 /* For vrf_bitmap_t. */
36 /* For union g_addr */
39 #include "nexthop_group.h"
41 /* For union pw_protocol_fields */
52 /* Zebra types. Used in Zserv message header. */
53 typedef uint16_t zebra_size_t
;
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.
59 #define ZEBRA_HEADER_MARKER 254
61 /* For input/output buffer to zebra. */
62 #define ZEBRA_MAX_PACKET_SIZ 16384U
63 #define ZEBRA_SMALL_PACKET_SIZE 200U
65 /* Zebra header size. */
66 #define ZEBRA_HEADER_SIZE 10
68 /* special socket path name to use TCP
69 * @ is used as first character because that's abstract socket names on Linux
71 #define ZAPI_TCP_PATHNAME "@tcp"
73 /* IPset size name stands for the name of the ipset entry
74 * that can be created by using some zapi interfaces
76 #define ZEBRA_IPSET_NAME_SIZE 32
78 /* IPTable action is defined by two values: either
81 #define ZEBRA_IPTABLES_FORWARD 0
82 #define ZEBRA_IPTABLES_DROP 1
84 /* Zebra FEC register command flags. */
85 #define ZEBRA_FEC_REGISTER_LABEL 0x1
86 #define ZEBRA_FEC_REGISTER_LABEL_INDEX 0x2
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
97 /* Macro to check if there GR enabled. */
98 #define ZEBRA_CLIENT_GR_ENABLED(X) (X == ZEBRA_CLIENT_GR_CAPABILITIES)
100 #define ZEBRA_SR_POLICY_NAME_MAX_LENGTH 100
102 extern struct sockaddr_storage zclient_addr
;
103 extern socklen_t zclient_addr_len
;
105 /* Zebra message types. */
108 ZEBRA_INTERFACE_DELETE
,
109 ZEBRA_INTERFACE_ADDRESS_ADD
,
110 ZEBRA_INTERFACE_ADDRESS_DELETE
,
112 ZEBRA_INTERFACE_DOWN
,
113 ZEBRA_INTERFACE_SET_MASTER
,
114 ZEBRA_INTERFACE_SET_PROTODOWN
,
117 ZEBRA_ROUTE_NOTIFY_OWNER
,
118 ZEBRA_REDISTRIBUTE_ADD
,
119 ZEBRA_REDISTRIBUTE_DELETE
,
120 ZEBRA_REDISTRIBUTE_DEFAULT_ADD
,
121 ZEBRA_REDISTRIBUTE_DEFAULT_DELETE
,
123 ZEBRA_ROUTER_ID_DELETE
,
124 ZEBRA_ROUTER_ID_UPDATE
,
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
,
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
,
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
,
162 ZEBRA_FEC_UNREGISTER
,
164 ZEBRA_ADVERTISE_DEFAULT_GW
,
165 ZEBRA_ADVERTISE_SVI_MACIP
,
166 ZEBRA_ADVERTISE_SUBNET
,
167 ZEBRA_ADVERTISE_ALL_VNI
,
170 ZEBRA_REMOTE_ES_VTEP_ADD
,
171 ZEBRA_REMOTE_ES_VTEP_DEL
,
172 ZEBRA_LOCAL_ES_EVI_ADD
,
173 ZEBRA_LOCAL_ES_EVI_DEL
,
178 ZEBRA_REMOTE_VTEP_ADD
,
179 ZEBRA_REMOTE_VTEP_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
,
191 ZEBRA_PW_STATUS_UPDATE
,
194 ZEBRA_RULE_NOTIFY_OWNER
,
195 ZEBRA_TABLE_MANAGER_CONNECT
,
196 ZEBRA_GET_TABLE_CHUNK
,
197 ZEBRA_RELEASE_TABLE_CHUNK
,
200 ZEBRA_IPSET_ENTRY_ADD
,
201 ZEBRA_IPSET_ENTRY_DELETE
,
202 ZEBRA_IPSET_NOTIFY_OWNER
,
203 ZEBRA_IPSET_ENTRY_NOTIFY_OWNER
,
205 ZEBRA_IPTABLE_DELETE
,
206 ZEBRA_IPTABLE_NOTIFY_OWNER
,
207 ZEBRA_VXLAN_FLOOD_CONTROL
,
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
,
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
,
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
,
243 ZEBRA_GRE_SOURCE_SET
,
244 ZEBRA_TC_QDISC_INSTALL
,
245 ZEBRA_TC_QDISC_UNINSTALL
,
247 ZEBRA_TC_CLASS_DELETE
,
249 ZEBRA_TC_FILTER_DELETE
,
250 } zebra_message_types_t
;
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 */
258 static inline const char *zebra_error_type2str(enum zebra_error_types type
)
260 const char *ret
= "UNKNOWN";
263 case ZEBRA_UNKNOWN_ERROR
:
264 ret
= "ZEBRA_UNKNOWN_ERROR";
267 ret
= "ZEBRA_NO_VRF";
269 case ZEBRA_INVALID_MSG_TYPE
:
270 ret
= "ZEBRA_INVALID_MSG_TYPE";
277 struct redist_proto
{
279 struct list
*instances
;
282 struct zclient_capabilities
{
288 /* Graceful Restart Capabilities message */
290 enum zserv_client_capabilities cap
;
291 uint32_t stale_removal_time
;
297 /* clang-format off */
298 #define ZAPI_CALLBACK_ARGS \
299 int cmd, struct zclient *zclient, uint16_t length, vrf_id_t vrf_id
301 /* function-type typedef (pointer not included) */
302 typedef int (zclient_handler
)(ZAPI_CALLBACK_ARGS
);
303 /* clang-format on */
305 /* Structure for the zebra client. */
307 /* The thread master we schedule ourselves on */
308 struct thread_master
*master
;
310 /* Privileges to change socket values */
311 struct zebra_privs_t
*privs
;
313 /* Do we care about failure events for route install? */
316 /* Is this a synchronous client? */
319 /* BFD enabled with bfd_protocol_integration_init() */
320 bool bfd_integration
;
322 /* Session id (optional) to support clients with multiple sessions */
325 /* Socket to zebra daemon. */
328 /* Connection failure count. */
331 /* Input buffer for zebra message. */
334 /* Output buffer for zebra message. */
337 /* Buffer of data waiting to be written to zebra. */
340 /* Read and connect thread. */
341 struct thread
*t_read
;
342 struct thread
*t_connect
;
344 /* Thread to write buffered data to zebra. */
345 struct thread
*t_write
;
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
];
353 /* Redistribute default. */
354 vrf_bitmap_t default_information
[AFI_MAX
];
356 /* Pointer to the callback functions. */
357 void (*zebra_connected
)(struct zclient
*);
358 void (*zebra_capabilities
)(struct zclient_capabilities
*cap
);
360 int (*handle_error
)(enum zebra_error_types error
);
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
372 void (*zebra_buffer_write_ready
)(void);
374 zclient_handler
*const *handlers
;
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
);
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
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.
397 #define ZAPI_MESSAGE_TABLEID 0x0100
398 #define ZAPI_MESSAGE_SRTE 0x0200
399 #define ZAPI_MESSAGE_OPAQUE 0x0400
401 #define ZSERV_VERSION 6
402 /* Zserv protocol message header */
405 /* Always set to 255 in new zserv */
410 } __attribute__((packed
));
411 #define ZAPI_HEADER_CMD_LOCATION offsetof(struct zmsghdr, command)
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().
418 struct zapi_nexthop
{
419 enum nexthop_types_t type
;
425 enum blackhole_type bh_type
;
428 /* MPLS labels for BGP-LU or Segment Routing */
430 enum lsp_types_t label_type
;
431 mpls_label_t labels
[MPLS_MAX_LABELS
];
437 /* Backup nexthops, for IP-FRR, TI-LFA, etc */
439 uint8_t backup_idx
[NEXTHOP_MAX_BACKUPS
];
444 /* SRv6 localsid info for Endpoint-behaviour */
445 uint32_t seg6local_action
;
446 struct seg6local_context seg6local_ctx
;
448 /* SRv6 Headend-behaviour */
449 struct in6_addr seg6_segs
;
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.
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
467 * ZAPI Nexthop Group. For use with protocol creation of nexthop groups.
473 struct nhg_resilience resilience
;
475 uint16_t nexthop_num
;
476 struct zapi_nexthop nexthops
[MULTIPATH_NUM
];
478 uint16_t backup_nexthop_num
;
479 struct zapi_nexthop backup_nexthops
[MULTIPATH_NUM
];
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
491 unsigned short instance
;
493 /* If you add flags, update zclient_dump_route_flags */
496 * Cause Zebra to consider this routes nexthops recursively
498 #define ZEBRA_FLAG_ALLOW_RECURSION 0x01
500 * This is a route that is read in on startup that was left around
501 * from a previous run of FRR
503 #define ZEBRA_FLAG_SELFROUTE 0x02
505 * This flag is used to tell Zebra that the BGP route being passed
506 * down is a IBGP route
508 #define ZEBRA_FLAG_IBGP 0x04
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
513 #define ZEBRA_FLAG_SELECTED 0x08
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
518 #define ZEBRA_FLAG_FIB_OVERRIDE 0x10
520 * This flag tells Zebra that the route is a EVPN route and should
521 * be treated specially
523 #define ZEBRA_FLAG_EVPN_ROUTE 0x20
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.
529 #define ZEBRA_FLAG_RR_USE_DISTANCE 0x40
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
536 #define ZEBRA_FLAG_TRAPPED 0x80
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
543 #define ZEBRA_FLAG_OFFLOADED 0x100
545 * This flag tells everyone that the route has
547 * This flag makes no sense unless you are in an asic
550 #define ZEBRA_FLAG_OFFLOAD_FAILED 0x200
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 )
557 #define ZEBRA_FLAG_OUTOFSYNC 0x400
559 /* The older XXX_MESSAGE flags live here */
563 * This is an enum but we are going to treat it as a uint8_t
564 * for purpose of encoding/decoding
568 struct prefix prefix
;
569 struct prefix_ipv6 src_prefix
;
571 uint16_t nexthop_num
;
572 struct zapi_nexthop nexthops
[MULTIPATH_NUM
];
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
];
592 /* SR-TE color (used for nexthop updates only). */
595 #define ZAPI_MESSAGE_OPAQUE_LENGTH 1024
598 uint8_t data
[ZAPI_MESSAGE_OPAQUE_LENGTH
];
602 extern char *zclient_dump_route_flags(uint32_t flags
, char *buf
, size_t len
);
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
;
611 struct prefix prefix
;
613 unsigned short instance
;
616 uint16_t nexthop_num
;
617 struct zapi_nexthop nexthops
[MULTIPATH_NUM
];
619 /* Backup nexthops, if present */
620 uint16_t backup_nexthop_num
;
621 struct zapi_nexthop backup_nexthops
[MULTIPATH_NUM
];
624 struct zapi_srte_tunnel
{
625 enum lsp_types_t type
;
626 mpls_label_t local_label
;
628 mpls_label_t labels
[MPLS_MAX_LABELS
];
631 struct zapi_sr_policy
{
633 struct ipaddr endpoint
;
634 char name
[SRTE_POLICY_NAME_MAX_LENGTH
];
635 struct zapi_srte_tunnel segment_list
;
640 char ifname
[INTERFACE_NAMSIZ
];
644 union g_addr nexthop
;
645 uint32_t local_label
;
646 uint32_t remote_label
;
648 union pw_protocol_fields data
;
652 struct zapi_pw_status
{
653 char ifname
[INTERFACE_NAMSIZ
];
658 /* IGP instance data associated to a RLFA. */
659 struct zapi_rlfa_igp
{
674 /* IGP -> LDP RLFA (un)registration message. */
675 struct zapi_rlfa_request
{
676 /* IGP instance data. */
677 struct zapi_rlfa_igp igp
;
679 /* Destination prefix. */
680 struct prefix destination
;
682 /* PQ node address. */
683 struct in_addr pq_address
;
686 /* LDP -> IGP RLFA label update. */
687 struct zapi_rlfa_response
{
688 /* IGP instance data. */
689 struct zapi_rlfa_igp igp
;
691 /* Destination prefix. */
692 struct prefix destination
;
694 /* Resolved LDP labels. */
695 mpls_label_t pq_label
;
696 uint16_t nexthop_num
;
701 } nexthops
[MULTIPATH_NUM
];
704 enum zapi_route_notify_owner
{
705 ZAPI_ROUTE_FAIL_INSTALL
,
706 ZAPI_ROUTE_BETTER_ADMIN_WON
,
707 ZAPI_ROUTE_INSTALLED
,
709 ZAPI_ROUTE_REMOVE_FAIL
,
712 enum zapi_nhg_notify_owner
{
713 ZAPI_NHG_FAIL_INSTALL
,
716 ZAPI_NHG_REMOVE_FAIL
,
719 enum zapi_rule_notify_owner
{
720 ZAPI_RULE_FAIL_INSTALL
,
723 ZAPI_RULE_FAIL_REMOVE
,
733 enum zapi_ipset_notify_owner
{
734 ZAPI_IPSET_FAIL_INSTALL
= 0,
735 ZAPI_IPSET_INSTALLED
,
737 ZAPI_IPSET_FAIL_REMOVE
,
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
,
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
,
754 enum zclient_send_status
{
755 ZCLIENT_SEND_FAILURE
= -1,
756 ZCLIENT_SEND_SUCCESS
= 0,
757 ZCLIENT_SEND_BUFFERED
= 1
760 static inline const char *
761 zapi_nhg_notify_owner2str(enum zapi_nhg_notify_owner note
)
763 const char *ret
= "UNKNOWN";
766 case ZAPI_NHG_FAIL_INSTALL
:
767 ret
= "ZAPI_NHG_FAIL_INSTALL";
769 case ZAPI_NHG_INSTALLED
:
770 ret
= "ZAPI_NHG_INSTALLED";
772 case ZAPI_NHG_REMOVE_FAIL
:
773 ret
= "ZAPI_NHG_REMOVE_FAIL";
775 case ZAPI_NHG_REMOVED
:
776 ret
= "ZAPI_NHG_REMOVED";
783 static inline const char *
784 zapi_rule_notify_owner2str(enum zapi_rule_notify_owner note
)
786 const char *ret
= "UNKNOWN";
789 case ZAPI_RULE_FAIL_INSTALL
:
790 ret
= "ZAPI_RULE_FAIL_INSTALL";
792 case ZAPI_RULE_INSTALLED
:
793 ret
= "ZAPI_RULE_INSTALLED";
795 case ZAPI_RULE_FAIL_REMOVE
:
796 ret
= "ZAPI_RULE_FAIL_REMOVE";
798 case ZAPI_RULE_REMOVED
:
799 ret
= "ZAPI_RULE_REMOVED";
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
817 #define MACIP_BUF_SIZE 128
818 extern char *zclient_evpn_dump_macip_flags(uint8_t flags
, char *buf
,
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.
825 #define ZAPI_ES_VTEP_FLAG_ESR_RXED (1 << 0)
827 enum zebra_neigh_state
{ ZEBRA_NEIGH_INACTIVE
= 0, ZEBRA_NEIGH_ACTIVE
= 1 };
829 struct zclient_options
{
834 extern struct zclient_options zclient_options_default
;
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)
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)
852 struct zapi_neigh_ip
{
855 struct ipaddr ip_out
;
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
,
865 * We reserve the top 4 bits for l2-NHG, everything else
866 * is for zebra/proto l3-NHG.
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
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))
878 extern uint32_t zclient_get_nhg_start(uint32_t proto
);
880 extern struct zclient
*zclient_new(struct thread_master
*m
,
881 struct zclient_options
*opt
,
882 zclient_handler
*const *handlers
,
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
*);
892 extern int zclient_socket_connect(struct zclient
*);
894 extern unsigned short *redist_check_instance(struct redist_proto
*,
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
);
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
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.
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
);
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
);
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
,
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
);
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
);
942 extern enum zclient_send_status
943 zebra_redistribute_default_send(int command
, struct zclient
*zclient
, afi_t afi
,
946 /* Send route notify request to zebra */
947 extern int zebra_route_notify_send(int command
, struct zclient
*zclient
,
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
);
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
);
959 * Send the message in zclient->obuf to the zebra daemon (or enqueue it).
962 * 0 data was successfully sent
963 * 1 data was buffered for future usage
965 extern enum zclient_send_status
zclient_send_message(struct zclient
*);
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
);
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.
975 * The stream to read into
978 * The socket to read from
981 * Parsed message size will be placed in the pointed-at integer
984 * Parsed marker will be placed in the pointed-at byte
987 * Parsed version will be placed in the pointed-at byte
990 * Parsed VRF ID will be placed in the pointed-at vrf_id_t
993 * Parsed command number will be placed in the pointed-at integer
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
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
);
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.
1012 * The stream containing the header
1015 * The header struct to parse into.
1018 * true if parsing succeeded, false otherwise
1020 extern bool zapi_parse_header(struct stream
*zmsg
, struct zmsghdr
*hdr
);
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
*,
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
,
1032 vrf_id_t
*new_vrf_id
);
1033 extern int zebra_router_id_update_read(struct stream
*s
, struct prefix
*rid
);
1035 extern struct interface
*zebra_interface_link_params_read(struct stream
*s
,
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
);
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
,
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
,
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
);
1060 extern enum zclient_send_status
zebra_send_sr_policy(struct zclient
*zclient
,
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
);
1069 extern enum zclient_send_status
zebra_send_mpls_labels(struct zclient
*zclient
,
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
);
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
);
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
);
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
,
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
,
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
,
1112 enum zapi_ipset_notify_owner
*note
);
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
);
1118 #define ZEBRA_IPSET_NAME_SIZE 32
1120 bool zapi_ipset_entry_notify_decode(struct stream
*s
,
1123 enum zapi_ipset_entry_notify_owner
*note
);
1124 bool zapi_iptable_notify_decode(struct stream
*s
,
1126 enum zapi_iptable_notify_owner
*note
);
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
);
1135 * match -> is the prefix that the calling daemon asked to be matched
1137 * nhr->prefix -> is the actual prefix that was matched against in the
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.
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
,
1149 /* Decode the zebra error message */
1150 extern bool zapi_error_decode(struct stream
*s
, enum zebra_error_types
*error
);
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
);
1158 static inline void zapi_route_set_blackhole(struct zapi_route
*api
,
1159 enum blackhole_type bh_type
)
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
);
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
);
1173 extern enum zclient_send_status
zclient_send_mlag_data(struct zclient
*client
,
1174 struct stream
*client_s
);
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.
1184 enum zclient_send_status
zclient_send_opaque(struct zclient
*zclient
,
1185 uint32_t type
, const uint8_t *data
,
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
,
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 */
1200 /* Client-specific info - *if* UNICAST flag is set */
1203 uint32_t session_id
;
1206 #define ZAPI_OPAQUE_FLAG_UNICAST 0x01
1208 /* Simple struct to convey registration/unreg requests */
1209 struct zapi_opaque_reg_info
{
1210 /* Message subtype */
1213 /* Client session tuple */
1216 uint32_t session_id
;
1219 /* Decode incoming opaque */
1220 int zclient_opaque_decode(struct stream
*msg
, struct zapi_opaque_msg
*info
);
1222 enum zclient_send_status
zclient_register_opaque(struct zclient
*zclient
,
1224 enum zclient_send_status
zclient_unregister_opaque(struct zclient
*zclient
,
1226 int zapi_opaque_reg_decode(struct stream
*msg
,
1227 struct zapi_opaque_reg_info
*info
);
1230 * Registry of opaque message types. Please do not reuse an in-use
1231 * type code; some daemons are likely relying on it.
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,
1252 /* Send the hello message.
1253 * Returns 0 for success or -1 on an I/O error.
1255 extern enum zclient_send_status
zclient_send_hello(struct zclient
*client
);
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
);
1262 struct zapi_client_close_info
{
1263 /* Client session tuple */
1266 uint32_t session_id
;
1269 /* Decode incoming client close notify */
1270 extern int zapi_client_close_notify_decode(struct stream
*s
,
1271 struct zapi_client_close_info
*info
);
1273 extern int zclient_send_zebra_gre_request(struct zclient
*client
,
1274 struct interface
*ifp
);
1279 #endif /* _ZEBRA_ZCLIENT_H */