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 /* For union pw_protocol_fields */
50 /* Zebra types. Used in Zserv message header. */
51 typedef uint16_t zebra_size_t
;
53 /* Marker value used in new Zserv, in the byte location corresponding
54 * the command value in the old zserv header. To allow old and new
55 * Zserv headers to be distinguished from each other.
57 #define ZEBRA_HEADER_MARKER 254
59 /* For input/output buffer to zebra. */
60 #define ZEBRA_MAX_PACKET_SIZ 16384U
61 #define ZEBRA_SMALL_PACKET_SIZE 200U
63 /* Zebra header size. */
64 #define ZEBRA_HEADER_SIZE 10
66 /* special socket path name to use TCP
67 * @ is used as first character because that's abstract socket names on Linux
69 #define ZAPI_TCP_PATHNAME "@tcp"
71 /* IPset size name stands for the name of the ipset entry
72 * that can be created by using some zapi interfaces
74 #define ZEBRA_IPSET_NAME_SIZE 32
76 /* IPTable action is defined by two values: either
79 #define ZEBRA_IPTABLES_FORWARD 0
80 #define ZEBRA_IPTABLES_DROP 1
82 /* Zebra FEC register command flags. */
83 #define ZEBRA_FEC_REGISTER_LABEL 0x1
84 #define ZEBRA_FEC_REGISTER_LABEL_INDEX 0x2
86 /* Client capabilities */
87 enum zserv_client_capabilities
{
88 ZEBRA_CLIENT_GR_CAPABILITIES
= 1,
89 ZEBRA_CLIENT_ROUTE_UPDATE_COMPLETE
= 2,
90 ZEBRA_CLIENT_ROUTE_UPDATE_PENDING
= 3,
91 ZEBRA_CLIENT_GR_DISABLE
= 4,
92 ZEBRA_CLIENT_RIB_STALE_TIME
95 /* Macro to check if there GR enabled. */
96 #define ZEBRA_CLIENT_GR_ENABLED(X) (X == ZEBRA_CLIENT_GR_CAPABILITIES)
98 #define ZEBRA_SR_POLICY_NAME_MAX_LENGTH 100
100 extern struct sockaddr_storage zclient_addr
;
101 extern socklen_t zclient_addr_len
;
103 /* Zebra message types. */
106 ZEBRA_INTERFACE_DELETE
,
107 ZEBRA_INTERFACE_ADDRESS_ADD
,
108 ZEBRA_INTERFACE_ADDRESS_DELETE
,
110 ZEBRA_INTERFACE_DOWN
,
111 ZEBRA_INTERFACE_SET_MASTER
,
112 ZEBRA_INTERFACE_SET_PROTODOWN
,
115 ZEBRA_ROUTE_NOTIFY_OWNER
,
116 ZEBRA_REDISTRIBUTE_ADD
,
117 ZEBRA_REDISTRIBUTE_DELETE
,
118 ZEBRA_REDISTRIBUTE_DEFAULT_ADD
,
119 ZEBRA_REDISTRIBUTE_DEFAULT_DELETE
,
121 ZEBRA_ROUTER_ID_DELETE
,
122 ZEBRA_ROUTER_ID_UPDATE
,
125 ZEBRA_NEXTHOP_REGISTER
,
126 ZEBRA_NEXTHOP_UNREGISTER
,
127 ZEBRA_NEXTHOP_UPDATE
,
128 ZEBRA_INTERFACE_NBR_ADDRESS_ADD
,
129 ZEBRA_INTERFACE_NBR_ADDRESS_DELETE
,
130 ZEBRA_INTERFACE_BFD_DEST_UPDATE
,
131 ZEBRA_BFD_DEST_REGISTER
,
132 ZEBRA_BFD_DEST_DEREGISTER
,
133 ZEBRA_BFD_DEST_UPDATE
,
134 ZEBRA_BFD_DEST_REPLAY
,
135 ZEBRA_REDISTRIBUTE_ROUTE_ADD
,
136 ZEBRA_REDISTRIBUTE_ROUTE_DEL
,
137 ZEBRA_VRF_UNREGISTER
,
141 ZEBRA_INTERFACE_VRF_UPDATE
,
142 ZEBRA_BFD_CLIENT_REGISTER
,
143 ZEBRA_BFD_CLIENT_DEREGISTER
,
144 ZEBRA_INTERFACE_ENABLE_RADV
,
145 ZEBRA_INTERFACE_DISABLE_RADV
,
146 ZEBRA_NEXTHOP_LOOKUP_MRIB
,
147 ZEBRA_INTERFACE_LINK_PARAMS
,
148 ZEBRA_MPLS_LABELS_ADD
,
149 ZEBRA_MPLS_LABELS_DELETE
,
150 ZEBRA_MPLS_LABELS_REPLACE
,
152 ZEBRA_SR_POLICY_DELETE
,
153 ZEBRA_SR_POLICY_NOTIFY_STATUS
,
154 ZEBRA_IPMR_ROUTE_STATS
,
155 ZEBRA_LABEL_MANAGER_CONNECT
,
156 ZEBRA_LABEL_MANAGER_CONNECT_ASYNC
,
157 ZEBRA_GET_LABEL_CHUNK
,
158 ZEBRA_RELEASE_LABEL_CHUNK
,
160 ZEBRA_FEC_UNREGISTER
,
162 ZEBRA_ADVERTISE_DEFAULT_GW
,
163 ZEBRA_ADVERTISE_SVI_MACIP
,
164 ZEBRA_ADVERTISE_SUBNET
,
165 ZEBRA_ADVERTISE_ALL_VNI
,
168 ZEBRA_REMOTE_ES_VTEP_ADD
,
169 ZEBRA_REMOTE_ES_VTEP_DEL
,
170 ZEBRA_LOCAL_ES_EVI_ADD
,
171 ZEBRA_LOCAL_ES_EVI_DEL
,
176 ZEBRA_REMOTE_VTEP_ADD
,
177 ZEBRA_REMOTE_VTEP_DEL
,
180 ZEBRA_IP_PREFIX_ROUTE_ADD
,
181 ZEBRA_IP_PREFIX_ROUTE_DEL
,
182 ZEBRA_REMOTE_MACIP_ADD
,
183 ZEBRA_REMOTE_MACIP_DEL
,
184 ZEBRA_DUPLICATE_ADDR_DETECTION
,
189 ZEBRA_PW_STATUS_UPDATE
,
192 ZEBRA_RULE_NOTIFY_OWNER
,
193 ZEBRA_TABLE_MANAGER_CONNECT
,
194 ZEBRA_GET_TABLE_CHUNK
,
195 ZEBRA_RELEASE_TABLE_CHUNK
,
198 ZEBRA_IPSET_ENTRY_ADD
,
199 ZEBRA_IPSET_ENTRY_DELETE
,
200 ZEBRA_IPSET_NOTIFY_OWNER
,
201 ZEBRA_IPSET_ENTRY_NOTIFY_OWNER
,
203 ZEBRA_IPTABLE_DELETE
,
204 ZEBRA_IPTABLE_NOTIFY_OWNER
,
205 ZEBRA_VXLAN_FLOOD_CONTROL
,
208 ZEBRA_VXLAN_SG_REPLAY
,
209 ZEBRA_MLAG_PROCESS_UP
,
210 ZEBRA_MLAG_PROCESS_DOWN
,
211 ZEBRA_MLAG_CLIENT_REGISTER
,
212 ZEBRA_MLAG_CLIENT_UNREGISTER
,
213 ZEBRA_MLAG_FORWARD_MSG
,
216 ZEBRA_NHG_NOTIFY_OWNER
,
217 ZEBRA_EVPN_REMOTE_NH_ADD
,
218 ZEBRA_EVPN_REMOTE_NH_DEL
,
219 ZEBRA_SRV6_LOCATOR_ADD
,
220 ZEBRA_SRV6_LOCATOR_DELETE
,
221 ZEBRA_SRV6_MANAGER_GET_LOCATOR_CHUNK
,
222 ZEBRA_SRV6_MANAGER_RELEASE_LOCATOR_CHUNK
,
224 ZEBRA_CLIENT_CAPABILITIES
,
225 ZEBRA_OPAQUE_MESSAGE
,
226 ZEBRA_OPAQUE_REGISTER
,
227 ZEBRA_OPAQUE_UNREGISTER
,
228 ZEBRA_NEIGH_DISCOVER
,
229 ZEBRA_ROUTE_NOTIFY_REQUEST
,
230 ZEBRA_CLIENT_CLOSE_NOTIFY
,
231 ZEBRA_NHRP_NEIGH_ADDED
,
232 ZEBRA_NHRP_NEIGH_REMOVED
,
233 ZEBRA_NHRP_NEIGH_GET
,
234 ZEBRA_NHRP_NEIGH_REGISTER
,
235 ZEBRA_NHRP_NEIGH_UNREGISTER
,
241 ZEBRA_GRE_SOURCE_SET
,
242 } zebra_message_types_t
;
244 enum zebra_error_types
{
245 ZEBRA_UNKNOWN_ERROR
, /* Error of unknown type */
246 ZEBRA_NO_VRF
, /* Vrf in header was not found */
247 ZEBRA_INVALID_MSG_TYPE
, /* No handler found for msg type */
250 static inline const char *zebra_error_type2str(enum zebra_error_types type
)
252 const char *ret
= "UNKNOWN";
255 case ZEBRA_UNKNOWN_ERROR
:
256 ret
= "ZEBRA_UNKNOWN_ERROR";
259 ret
= "ZEBRA_NO_VRF";
261 case ZEBRA_INVALID_MSG_TYPE
:
262 ret
= "ZEBRA_INVALID_MSG_TYPE";
269 struct redist_proto
{
271 struct list
*instances
;
274 struct zclient_capabilities
{
280 /* Graceful Restart Capabilities message */
282 enum zserv_client_capabilities cap
;
283 uint32_t stale_removal_time
;
289 /* clang-format off */
290 #define ZAPI_CALLBACK_ARGS \
291 int cmd, struct zclient *zclient, uint16_t length, vrf_id_t vrf_id
293 /* function-type typedef (pointer not included) */
294 typedef int (zclient_handler
)(ZAPI_CALLBACK_ARGS
);
295 /* clang-format on */
297 /* Structure for the zebra client. */
299 /* The thread master we schedule ourselves on */
300 struct thread_master
*master
;
302 /* Privileges to change socket values */
303 struct zebra_privs_t
*privs
;
305 /* Do we care about failure events for route install? */
308 /* Is this a synchronous client? */
311 /* BFD enabled with bfd_protocol_integration_init() */
312 bool bfd_integration
;
314 /* Session id (optional) to support clients with multiple sessions */
317 /* Socket to zebra daemon. */
320 /* Connection failure count. */
323 /* Input buffer for zebra message. */
326 /* Output buffer for zebra message. */
329 /* Buffer of data waiting to be written to zebra. */
332 /* Read and connect thread. */
333 struct thread
*t_read
;
334 struct thread
*t_connect
;
336 /* Thread to write buffered data to zebra. */
337 struct thread
*t_write
;
339 /* Redistribute information. */
340 uint8_t redist_default
; /* clients protocol */
341 unsigned short instance
;
342 struct redist_proto mi_redist
[AFI_MAX
][ZEBRA_ROUTE_MAX
];
343 vrf_bitmap_t redist
[AFI_MAX
][ZEBRA_ROUTE_MAX
];
345 /* Redistribute default. */
346 vrf_bitmap_t default_information
[AFI_MAX
];
348 /* Pointer to the callback functions. */
349 void (*zebra_connected
)(struct zclient
*);
350 void (*zebra_capabilities
)(struct zclient_capabilities
*cap
);
352 int (*handle_error
)(enum zebra_error_types error
);
355 * When the zclient attempts to write the stream data to
356 * it's named pipe to/from zebra, we may have a situation
357 * where the other daemon has not fully drained the data
358 * from the socket. In this case provide a mechanism
359 * where we will *still* buffer the data to be sent
360 * and also provide a callback mechanism to the appropriate
361 * place where we can signal that we're ready to receive
364 void (*zebra_buffer_write_ready
)(void);
366 zclient_handler
*const *handlers
;
370 /* lib handlers added in bfd.c */
371 extern int zclient_bfd_session_replay(ZAPI_CALLBACK_ARGS
);
372 extern int zclient_bfd_session_update(ZAPI_CALLBACK_ARGS
);
374 /* Zebra API message flag. */
375 #define ZAPI_MESSAGE_NEXTHOP 0x01
376 #define ZAPI_MESSAGE_DISTANCE 0x02
377 #define ZAPI_MESSAGE_METRIC 0x04
378 #define ZAPI_MESSAGE_TAG 0x08
379 #define ZAPI_MESSAGE_MTU 0x10
380 #define ZAPI_MESSAGE_SRCPFX 0x20
381 /* Backup nexthops are present */
382 #define ZAPI_MESSAGE_BACKUP_NEXTHOPS 0x40
383 #define ZAPI_MESSAGE_NHG 0x80
385 * This should only be used by a DAEMON that needs to communicate
386 * the table being used is not in the VRF. You must pass the
387 * default vrf, else this will be ignored.
389 #define ZAPI_MESSAGE_TABLEID 0x0100
390 #define ZAPI_MESSAGE_SRTE 0x0200
391 #define ZAPI_MESSAGE_OPAQUE 0x0400
393 #define ZSERV_VERSION 6
394 /* Zserv protocol message header */
397 /* Always set to 255 in new zserv */
402 } __attribute__((packed
));
403 #define ZAPI_HEADER_CMD_LOCATION offsetof(struct zmsghdr, command)
406 * ZAPI nexthop. Note that these are sorted when associated with ZAPI routes,
407 * and that sorting must be aligned with the sorting of nexthops in
408 * lib/nexthop.c. Any new fields must be accounted for in zapi_nexthop_cmp().
410 struct zapi_nexthop
{
411 enum nexthop_types_t type
;
417 enum blackhole_type bh_type
;
420 /* MPLS labels for BGP-LU or Segment Routing */
422 mpls_label_t labels
[MPLS_MAX_LABELS
];
428 /* Backup nexthops, for IP-FRR, TI-LFA, etc */
430 uint8_t backup_idx
[NEXTHOP_MAX_BACKUPS
];
435 /* SRv6 localsid info for Endpoint-behaviour */
436 uint32_t seg6local_action
;
437 struct seg6local_context seg6local_ctx
;
439 /* SRv6 Headend-behaviour */
440 struct in6_addr seg6_segs
;
444 * ZAPI nexthop flags values - we're encoding a single octet
445 * initially, so ensure that the on-the-wire encoding continues
446 * to match the number of valid flags.
449 #define ZAPI_NEXTHOP_FLAG_ONLINK 0x01
450 #define ZAPI_NEXTHOP_FLAG_LABEL 0x02
451 #define ZAPI_NEXTHOP_FLAG_WEIGHT 0x04
452 #define ZAPI_NEXTHOP_FLAG_HAS_BACKUP 0x08 /* Nexthop has a backup */
453 #define ZAPI_NEXTHOP_FLAG_SEG6 0x10
454 #define ZAPI_NEXTHOP_FLAG_SEG6LOCAL 0x20
455 #define ZAPI_NEXTHOP_FLAG_EVPN 0x40
458 * ZAPI Nexthop Group. For use with protocol creation of nexthop groups.
464 uint16_t nexthop_num
;
465 struct zapi_nexthop nexthops
[MULTIPATH_NUM
];
467 uint16_t backup_nexthop_num
;
468 struct zapi_nexthop backup_nexthops
[MULTIPATH_NUM
];
472 * Some of these data structures do not map easily to
473 * a actual data structure size giving different compilers
474 * and systems. For those data structures we need
475 * to use the smallest available stream_getX/putX functions
480 unsigned short instance
;
482 /* If you add flags, update zclient_dump_route_flags */
485 * Cause Zebra to consider this routes nexthops recursively
487 #define ZEBRA_FLAG_ALLOW_RECURSION 0x01
489 * This is a route that is read in on startup that was left around
490 * from a previous run of FRR
492 #define ZEBRA_FLAG_SELFROUTE 0x02
494 * This flag is used to tell Zebra that the BGP route being passed
495 * down is a IBGP route
497 #define ZEBRA_FLAG_IBGP 0x04
499 * This is a route that has been selected for FIB installation.
500 * This flag is set in zebra and can be passed up to routing daemons
502 #define ZEBRA_FLAG_SELECTED 0x08
504 * This is a route that we are telling Zebra that this route *must*
505 * win and will be installed even over ZEBRA_FLAG_SELECTED
507 #define ZEBRA_FLAG_FIB_OVERRIDE 0x10
509 * This flag tells Zebra that the route is a EVPN route and should
510 * be treated specially
512 #define ZEBRA_FLAG_EVPN_ROUTE 0x20
514 * This flag tells Zebra that it should treat the distance passed
515 * down as an additional discriminator for route selection of the
516 * route entry. This mainly is used for backup static routes.
518 #define ZEBRA_FLAG_RR_USE_DISTANCE 0x40
520 * This flag tells everyone that the route was intentionally
521 * not offloaded and the route will be sent to the cpu for
522 * forwarding. This flag makes no sense unless you are in
523 * an asic offload situation
525 #define ZEBRA_FLAG_TRAPPED 0x80
527 * This flag tells everyone that the route has been
528 * successfully offloaded to an asic for forwarding.
529 * This flag makes no sense unless you are in an asic
532 #define ZEBRA_FLAG_OFFLOADED 0x100
534 * This flag tells everyone that the route has
536 * This flag makes no sense unless you are in an asic
539 #define ZEBRA_FLAG_OFFLOAD_FAILED 0x200
541 /* The older XXX_MESSAGE flags live here */
545 * This is an enum but we are going to treat it as a uint8_t
546 * for purpose of encoding/decoding
550 struct prefix prefix
;
551 struct prefix_ipv6 src_prefix
;
553 uint16_t nexthop_num
;
554 struct zapi_nexthop nexthops
[MULTIPATH_NUM
];
556 /* Support backup routes for IP FRR, TI-LFA, traffic engineering */
557 uint16_t backup_nexthop_num
;
558 struct zapi_nexthop backup_nexthops
[MULTIPATH_NUM
];
574 /* SR-TE color (used for nexthop updates only). */
577 #define ZAPI_MESSAGE_OPAQUE_LENGTH 1024
580 uint8_t data
[ZAPI_MESSAGE_OPAQUE_LENGTH
];
584 extern char *zclient_dump_route_flags(uint32_t flags
, char *buf
, size_t len
);
588 #define ZAPI_LABELS_FTN 0x01
589 #define ZAPI_LABELS_HAS_BACKUPS 0x02
590 enum lsp_types_t type
;
591 mpls_label_t local_label
;
593 struct prefix prefix
;
595 unsigned short instance
;
598 uint16_t nexthop_num
;
599 struct zapi_nexthop nexthops
[MULTIPATH_NUM
];
601 /* Backup nexthops, if present */
602 uint16_t backup_nexthop_num
;
603 struct zapi_nexthop backup_nexthops
[MULTIPATH_NUM
];
606 struct zapi_srte_tunnel
{
607 enum lsp_types_t type
;
608 mpls_label_t local_label
;
610 mpls_label_t labels
[MPLS_MAX_LABELS
];
613 struct zapi_sr_policy
{
615 struct ipaddr endpoint
;
616 char name
[SRTE_POLICY_NAME_MAX_LENGTH
];
617 struct zapi_srte_tunnel segment_list
;
622 char ifname
[INTERFACE_NAMSIZ
];
626 union g_addr nexthop
;
627 uint32_t local_label
;
628 uint32_t remote_label
;
630 union pw_protocol_fields data
;
634 struct zapi_pw_status
{
635 char ifname
[INTERFACE_NAMSIZ
];
640 /* IGP instance data associated to a RLFA. */
641 struct zapi_rlfa_igp
{
656 /* IGP -> LDP RLFA (un)registration message. */
657 struct zapi_rlfa_request
{
658 /* IGP instance data. */
659 struct zapi_rlfa_igp igp
;
661 /* Destination prefix. */
662 struct prefix destination
;
664 /* PQ node address. */
665 struct in_addr pq_address
;
668 /* LDP -> IGP RLFA label update. */
669 struct zapi_rlfa_response
{
670 /* IGP instance data. */
671 struct zapi_rlfa_igp igp
;
673 /* Destination prefix. */
674 struct prefix destination
;
676 /* Resolved LDP labels. */
677 mpls_label_t pq_label
;
678 uint16_t nexthop_num
;
683 } nexthops
[MULTIPATH_NUM
];
686 enum zapi_route_notify_owner
{
687 ZAPI_ROUTE_FAIL_INSTALL
,
688 ZAPI_ROUTE_BETTER_ADMIN_WON
,
689 ZAPI_ROUTE_INSTALLED
,
691 ZAPI_ROUTE_REMOVE_FAIL
,
694 enum zapi_nhg_notify_owner
{
695 ZAPI_NHG_FAIL_INSTALL
,
698 ZAPI_NHG_REMOVE_FAIL
,
701 enum zapi_rule_notify_owner
{
702 ZAPI_RULE_FAIL_INSTALL
,
705 ZAPI_RULE_FAIL_REMOVE
,
715 enum zapi_ipset_notify_owner
{
716 ZAPI_IPSET_FAIL_INSTALL
= 0,
717 ZAPI_IPSET_INSTALLED
,
719 ZAPI_IPSET_FAIL_REMOVE
,
722 enum zapi_ipset_entry_notify_owner
{
723 ZAPI_IPSET_ENTRY_FAIL_INSTALL
= 0,
724 ZAPI_IPSET_ENTRY_INSTALLED
,
725 ZAPI_IPSET_ENTRY_REMOVED
,
726 ZAPI_IPSET_ENTRY_FAIL_REMOVE
,
729 enum zapi_iptable_notify_owner
{
730 ZAPI_IPTABLE_FAIL_INSTALL
= 0,
731 ZAPI_IPTABLE_INSTALLED
,
732 ZAPI_IPTABLE_REMOVED
,
733 ZAPI_IPTABLE_FAIL_REMOVE
,
736 enum zclient_send_status
{
737 ZCLIENT_SEND_FAILURE
= -1,
738 ZCLIENT_SEND_SUCCESS
= 0,
739 ZCLIENT_SEND_BUFFERED
= 1
742 static inline const char *
743 zapi_nhg_notify_owner2str(enum zapi_nhg_notify_owner note
)
745 const char *ret
= "UNKNOWN";
748 case ZAPI_NHG_FAIL_INSTALL
:
749 ret
= "ZAPI_NHG_FAIL_INSTALL";
751 case ZAPI_NHG_INSTALLED
:
752 ret
= "ZAPI_NHG_INSTALLED";
754 case ZAPI_NHG_REMOVE_FAIL
:
755 ret
= "ZAPI_NHG_REMOVE_FAIL";
757 case ZAPI_NHG_REMOVED
:
758 ret
= "ZAPI_NHG_REMOVED";
765 static inline const char *
766 zapi_rule_notify_owner2str(enum zapi_rule_notify_owner note
)
768 const char *ret
= "UNKNOWN";
771 case ZAPI_RULE_FAIL_INSTALL
:
772 ret
= "ZAPI_RULE_FAIL_INSTALL";
774 case ZAPI_RULE_INSTALLED
:
775 ret
= "ZAPI_RULE_INSTALLED";
777 case ZAPI_RULE_FAIL_REMOVE
:
778 ret
= "ZAPI_RULE_FAIL_REMOVE";
780 case ZAPI_RULE_REMOVED
:
781 ret
= "ZAPI_RULE_REMOVED";
788 /* Zebra MAC types */
789 #define ZEBRA_MACIP_TYPE_STICKY 0x01 /* Sticky MAC*/
790 #define ZEBRA_MACIP_TYPE_GW 0x02 /* gateway (SVI) mac*/
791 #define ZEBRA_MACIP_TYPE_ROUTER_FLAG 0x04 /* Router Flag - proxy NA */
792 #define ZEBRA_MACIP_TYPE_OVERRIDE_FLAG 0x08 /* Override Flag */
793 #define ZEBRA_MACIP_TYPE_SVI_IP 0x10 /* SVI MAC-IP */
794 #define ZEBRA_MACIP_TYPE_PROXY_ADVERT 0x20 /* Not locally active */
795 #define ZEBRA_MACIP_TYPE_SYNC_PATH 0x40 /* sync path */
796 /* XXX - flags is an u8; that needs to be changed to u32 if you need
797 * to allocate past 0x80. Additionally touch zclient_evpn_dump_macip_flags
799 #define MACIP_BUF_SIZE 128
800 extern char *zclient_evpn_dump_macip_flags(uint8_t flags
, char *buf
,
803 /* Zebra ES VTEP flags (ZEBRA_REMOTE_ES_VTEP_ADD) */
804 /* ESR has been rxed from the VTEP. Only VTEPs that have advertised the
805 * Type-4 route can participate in DF election.
807 #define ZAPI_ES_VTEP_FLAG_ESR_RXED (1 << 0)
809 enum zebra_neigh_state
{ ZEBRA_NEIGH_INACTIVE
= 0, ZEBRA_NEIGH_ACTIVE
= 1 };
811 struct zclient_options
{
816 extern struct zclient_options zclient_options_default
;
818 /* link layer representation for GRE like interfaces
819 * ip_in is the underlay IP, ip_out is the tunnel dest
820 * index stands for the index of the interface
821 * ndm state stands for the NDM value in netlink
822 * (see linux/neighbour.h)
824 #define ZEBRA_NEIGH_STATE_INCOMPLETE (0x01)
825 #define ZEBRA_NEIGH_STATE_REACHABLE (0x02)
826 #define ZEBRA_NEIGH_STATE_STALE (0x04)
827 #define ZEBRA_NEIGH_STATE_DELAY (0x08)
828 #define ZEBRA_NEIGH_STATE_PROBE (0x10)
829 #define ZEBRA_NEIGH_STATE_FAILED (0x20)
830 #define ZEBRA_NEIGH_STATE_NOARP (0x40)
831 #define ZEBRA_NEIGH_STATE_PERMANENT (0x80)
832 #define ZEBRA_NEIGH_STATE_NONE (0x00)
834 struct zapi_neigh_ip
{
837 struct ipaddr ip_out
;
841 int zclient_neigh_ip_decode(struct stream
*s
, struct zapi_neigh_ip
*api
);
842 int zclient_neigh_ip_encode(struct stream
*s
, uint16_t cmd
, union sockunion
*in
,
843 union sockunion
*out
, struct interface
*ifp
,
847 * We reserve the top 4 bits for l2-NHG, everything else
848 * is for zebra/proto l3-NHG.
850 * Each client is going to get it's own nexthop group space
851 * and we'll separate them, we'll figure out where to start based upon
854 #define ZEBRA_NHG_PROTO_UPPER \
855 ((uint32_t)250000000) /* Bottom 28 bits then rounded down */
856 #define ZEBRA_NHG_PROTO_SPACING (ZEBRA_NHG_PROTO_UPPER / ZEBRA_ROUTE_MAX)
857 #define ZEBRA_NHG_PROTO_LOWER \
858 (ZEBRA_NHG_PROTO_SPACING * (ZEBRA_ROUTE_CONNECT + 1))
860 extern uint32_t zclient_get_nhg_start(uint32_t proto
);
862 extern struct zclient
*zclient_new(struct thread_master
*m
,
863 struct zclient_options
*opt
,
864 zclient_handler
*const *handlers
,
867 extern void zclient_init(struct zclient
*, int, unsigned short,
868 struct zebra_privs_t
*privs
);
869 extern int zclient_start(struct zclient
*);
870 extern void zclient_stop(struct zclient
*);
871 extern void zclient_reset(struct zclient
*);
872 extern void zclient_free(struct zclient
*);
874 extern int zclient_socket_connect(struct zclient
*);
876 extern unsigned short *redist_check_instance(struct redist_proto
*,
878 extern void redist_add_instance(struct redist_proto
*, unsigned short);
879 extern void redist_del_instance(struct redist_proto
*, unsigned short);
880 extern void redist_del_all_instances(struct redist_proto
*red
);
883 * Send to zebra that the specified vrf is using label to resolve
884 * itself for L3VPN's. Repeated calls of this function with
885 * different labels will cause an effective update of the
886 * label for lookup. If you pass in MPLS_LABEL_NONE
887 * we will cause a delete action and remove this label pop
890 * The underlying AF_MPLS doesn't care about afi's
891 * but we can make the zebra_vrf keep track of what
892 * we have installed and play some special games
893 * to get them both installed.
895 extern enum zclient_send_status
896 zclient_send_vrf_label(struct zclient
*zclient
, vrf_id_t vrf_id
, afi_t afi
,
897 mpls_label_t label
, enum lsp_types_t ltype
);
899 extern enum zclient_send_status
900 zclient_send_localsid(struct zclient
*zclient
, const struct in6_addr
*sid
,
901 ifindex_t oif
, enum seg6local_action_t action
,
902 const struct seg6local_context
*context
);
904 extern void zclient_send_reg_requests(struct zclient
*, vrf_id_t
);
905 extern void zclient_send_dereg_requests(struct zclient
*, vrf_id_t
);
906 extern enum zclient_send_status
907 zclient_send_router_id_update(struct zclient
*zclient
,
908 zebra_message_types_t type
, afi_t afi
,
911 extern enum zclient_send_status
912 zclient_send_interface_radv_req(struct zclient
*zclient
, vrf_id_t vrf_id
,
913 struct interface
*ifp
, int enable
,
914 uint32_t ra_interval
);
915 extern enum zclient_send_status
916 zclient_send_interface_protodown(struct zclient
*zclient
, vrf_id_t vrf_id
,
917 struct interface
*ifp
, bool down
);
919 /* Send redistribute command to zebra daemon. Do not update zclient state. */
920 extern enum zclient_send_status
921 zebra_redistribute_send(int command
, struct zclient
*, afi_t
, int type
,
922 unsigned short instance
, vrf_id_t vrf_id
);
924 extern enum zclient_send_status
925 zebra_redistribute_default_send(int command
, struct zclient
*zclient
, afi_t afi
,
928 /* Send route notify request to zebra */
929 extern int zebra_route_notify_send(int command
, struct zclient
*zclient
,
932 /* If state has changed, update state and call zebra_redistribute_send. */
933 extern void zclient_redistribute(int command
, struct zclient
*, afi_t
, int type
,
934 unsigned short instance
, vrf_id_t vrf_id
);
936 /* If state has changed, update state and send the command to zebra. */
937 extern void zclient_redistribute_default(int command
, struct zclient
*,
938 afi_t
, vrf_id_t vrf_id
);
941 * Send the message in zclient->obuf to the zebra daemon (or enqueue it).
944 * 0 data was successfully sent
945 * 1 data was buffered for future usage
947 extern enum zclient_send_status
zclient_send_message(struct zclient
*);
949 /* create header for command, length to be filled in by user later */
950 extern void zclient_create_header(struct stream
*, uint16_t, vrf_id_t
);
952 * Read sizeof(struct zmsghdr) bytes from the provided socket and parse the
953 * received data into the specified fields. If this is successful, read the
954 * rest of the packet into the provided stream.
957 * The stream to read into
960 * The socket to read from
963 * Parsed message size will be placed in the pointed-at integer
966 * Parsed marker will be placed in the pointed-at byte
969 * Parsed version will be placed in the pointed-at byte
972 * Parsed VRF ID will be placed in the pointed-at vrf_id_t
975 * Parsed command number will be placed in the pointed-at integer
979 * - insufficient data for header was read
980 * - a version mismatch was detected
981 * - a marker mismatch was detected
982 * - header size field specified more data than could be read
984 extern int zclient_read_header(struct stream
*s
, int sock
, uint16_t *size
,
985 uint8_t *marker
, uint8_t *version
,
986 vrf_id_t
*vrf_id
, uint16_t *cmd
);
988 * Parse header from ZAPI message stream into struct zmsghdr.
989 * This function assumes the stream getp points at the first byte of the header.
990 * If the function is successful then the stream getp will point to the byte
991 * immediately after the last byte of the header.
994 * The stream containing the header
997 * The header struct to parse into.
1000 * true if parsing succeeded, false otherwise
1002 extern bool zapi_parse_header(struct stream
*zmsg
, struct zmsghdr
*hdr
);
1004 extern enum zclient_send_status
1005 zclient_interface_set_master(struct zclient
*client
, struct interface
*master
,
1006 struct interface
*slave
);
1007 extern struct interface
*zebra_interface_state_read(struct stream
*s
, vrf_id_t
);
1008 extern struct connected
*zebra_interface_address_read(int, struct stream
*,
1010 extern struct nbr_connected
*
1011 zebra_interface_nbr_address_read(int, struct stream
*, vrf_id_t
);
1012 extern struct interface
*zebra_interface_vrf_update_read(struct stream
*s
,
1014 vrf_id_t
*new_vrf_id
);
1015 extern int zebra_router_id_update_read(struct stream
*s
, struct prefix
*rid
);
1017 extern struct interface
*zebra_interface_link_params_read(struct stream
*s
,
1020 extern size_t zebra_interface_link_params_write(struct stream
*,
1021 struct interface
*);
1022 extern enum zclient_send_status
1023 zclient_send_get_label_chunk(struct zclient
*zclient
, uint8_t keep
,
1024 uint32_t chunk_size
, uint32_t base
);
1026 extern int lm_label_manager_connect(struct zclient
*zclient
, int async
);
1027 extern int lm_get_label_chunk(struct zclient
*zclient
, uint8_t keep
,
1028 uint32_t base
, uint32_t chunk_size
,
1029 uint32_t *start
, uint32_t *end
);
1030 extern int lm_release_label_chunk(struct zclient
*zclient
, uint32_t start
,
1032 extern int tm_table_manager_connect(struct zclient
*zclient
);
1033 extern int tm_get_table_chunk(struct zclient
*zclient
, uint32_t chunk_size
,
1034 uint32_t *start
, uint32_t *end
);
1035 extern int tm_release_table_chunk(struct zclient
*zclient
, uint32_t start
,
1037 extern int srv6_manager_get_locator_chunk(struct zclient
*zclient
,
1038 const char *locator_name
);
1039 extern int srv6_manager_release_locator_chunk(struct zclient
*zclient
,
1040 const char *locator_name
);
1042 extern enum zclient_send_status
zebra_send_sr_policy(struct zclient
*zclient
,
1044 struct zapi_sr_policy
*zp
);
1045 extern int zapi_sr_policy_encode(struct stream
*s
, int cmd
,
1046 struct zapi_sr_policy
*zp
);
1047 extern int zapi_sr_policy_decode(struct stream
*s
, struct zapi_sr_policy
*zp
);
1048 extern int zapi_sr_policy_notify_status_decode(struct stream
*s
,
1049 struct zapi_sr_policy
*zp
);
1051 extern enum zclient_send_status
zebra_send_mpls_labels(struct zclient
*zclient
,
1053 struct zapi_labels
*zl
);
1054 extern int zapi_labels_encode(struct stream
*s
, int cmd
,
1055 struct zapi_labels
*zl
);
1056 extern int zapi_labels_decode(struct stream
*s
, struct zapi_labels
*zl
);
1058 extern int zapi_srv6_locator_encode(struct stream
*s
,
1059 const struct srv6_locator
*l
);
1060 extern int zapi_srv6_locator_decode(struct stream
*s
, struct srv6_locator
*l
);
1061 extern int zapi_srv6_locator_chunk_encode(struct stream
*s
,
1062 const struct srv6_locator_chunk
*c
);
1063 extern int zapi_srv6_locator_chunk_decode(struct stream
*s
,
1064 struct srv6_locator_chunk
*c
);
1066 extern enum zclient_send_status
zebra_send_pw(struct zclient
*zclient
,
1067 int command
, struct zapi_pw
*pw
);
1068 extern int zebra_read_pw_status_update(ZAPI_CALLBACK_ARGS
,
1069 struct zapi_pw_status
*pw
);
1071 extern enum zclient_send_status
zclient_route_send(uint8_t, struct zclient
*,
1072 struct zapi_route
*);
1073 extern enum zclient_send_status
1074 zclient_send_rnh(struct zclient
*zclient
, int command
, const struct prefix
*p
,
1075 safi_t safi
, bool connected
, bool resolve_via_default
,
1077 int zapi_nexthop_encode(struct stream
*s
, const struct zapi_nexthop
*api_nh
,
1078 uint32_t api_flags
, uint32_t api_message
);
1079 extern int zapi_route_encode(uint8_t, struct stream
*, struct zapi_route
*);
1080 extern int zapi_route_decode(struct stream
*s
, struct zapi_route
*api
);
1081 extern int zapi_nexthop_decode(struct stream
*s
, struct zapi_nexthop
*api_nh
,
1082 uint32_t api_flags
, uint32_t api_message
);
1083 bool zapi_nhg_notify_decode(struct stream
*s
, uint32_t *id
,
1084 enum zapi_nhg_notify_owner
*note
);
1085 bool zapi_route_notify_decode(struct stream
*s
, struct prefix
*p
,
1087 enum zapi_route_notify_owner
*note
,
1088 afi_t
*afi
, safi_t
*safi
);
1089 bool zapi_rule_notify_decode(struct stream
*s
, uint32_t *seqno
,
1090 uint32_t *priority
, uint32_t *unique
, char *ifname
,
1091 enum zapi_rule_notify_owner
*note
);
1092 bool zapi_ipset_notify_decode(struct stream
*s
,
1094 enum zapi_ipset_notify_owner
*note
);
1096 /* Nexthop-group message apis */
1097 extern enum zclient_send_status
1098 zclient_nhg_send(struct zclient
*zclient
, int cmd
, struct zapi_nhg
*api_nhg
);
1100 #define ZEBRA_IPSET_NAME_SIZE 32
1102 bool zapi_ipset_entry_notify_decode(struct stream
*s
,
1105 enum zapi_ipset_entry_notify_owner
*note
);
1106 bool zapi_iptable_notify_decode(struct stream
*s
,
1108 enum zapi_iptable_notify_owner
*note
);
1110 extern struct nexthop
*
1111 nexthop_from_zapi_nexthop(const struct zapi_nexthop
*znh
);
1112 int zapi_nexthop_from_nexthop(struct zapi_nexthop
*znh
,
1113 const struct nexthop
*nh
);
1114 int zapi_backup_nexthop_from_nexthop(struct zapi_nexthop
*znh
,
1115 const struct nexthop
*nh
);
1117 * match -> is the prefix that the calling daemon asked to be matched
1119 * nhr->prefix -> is the actual prefix that was matched against in the
1122 * This distinction is made because a LPM can be made if there is a
1123 * covering route. This way the upper level protocol can make a decision
1124 * point about whether or not it wants to use the match or not.
1126 extern bool zapi_nexthop_update_decode(struct stream
*s
, struct prefix
*match
,
1127 struct zapi_route
*nhr
);
1128 const char *zapi_nexthop2str(const struct zapi_nexthop
*znh
, char *buf
,
1131 /* Decode the zebra error message */
1132 extern bool zapi_error_decode(struct stream
*s
, enum zebra_error_types
*error
);
1134 /* Encode and decode restart capabilities */
1135 extern enum zclient_send_status
1136 zclient_capabilities_send(uint32_t cmd
, struct zclient
*zclient
,
1137 struct zapi_cap
*api
);
1138 extern int32_t zapi_capabilities_decode(struct stream
*s
, struct zapi_cap
*api
);
1140 static inline void zapi_route_set_blackhole(struct zapi_route
*api
,
1141 enum blackhole_type bh_type
)
1143 api
->nexthop_num
= 1;
1144 api
->nexthops
[0].type
= NEXTHOP_TYPE_BLACKHOLE
;
1145 api
->nexthops
[0].vrf_id
= VRF_DEFAULT
;
1146 api
->nexthops
[0].bh_type
= bh_type
;
1147 SET_FLAG(api
->message
, ZAPI_MESSAGE_NEXTHOP
);
1150 extern enum zclient_send_status
1151 zclient_send_mlag_register(struct zclient
*client
, uint32_t bit_map
);
1152 extern enum zclient_send_status
1153 zclient_send_mlag_deregister(struct zclient
*client
);
1155 extern enum zclient_send_status
zclient_send_mlag_data(struct zclient
*client
,
1156 struct stream
*client_s
);
1159 * Send an OPAQUE message, contents opaque to zebra - but note that
1160 * the length of the payload is restricted by the zclient's
1161 * outgoing message buffer.
1162 * The message header is a message subtype; please use the registry
1163 * below to avoid sub-type collisions. Clients use the registration
1164 * apis to manage the specific opaque subtypes they want to receive.
1166 enum zclient_send_status
zclient_send_opaque(struct zclient
*zclient
,
1167 uint32_t type
, const uint8_t *data
,
1170 enum zclient_send_status
1171 zclient_send_opaque_unicast(struct zclient
*zclient
, uint32_t type
,
1172 uint8_t proto
, uint16_t instance
,
1173 uint32_t session_id
, const uint8_t *data
,
1176 /* Struct representing the decoded opaque header info */
1177 struct zapi_opaque_msg
{
1178 uint32_t type
; /* Subtype */
1179 uint16_t len
; /* len after zapi header and this info */
1182 /* Client-specific info - *if* UNICAST flag is set */
1185 uint32_t session_id
;
1188 #define ZAPI_OPAQUE_FLAG_UNICAST 0x01
1190 /* Simple struct to convey registration/unreg requests */
1191 struct zapi_opaque_reg_info
{
1192 /* Message subtype */
1195 /* Client session tuple */
1198 uint32_t session_id
;
1201 /* Decode incoming opaque */
1202 int zclient_opaque_decode(struct stream
*msg
, struct zapi_opaque_msg
*info
);
1204 enum zclient_send_status
zclient_register_opaque(struct zclient
*zclient
,
1206 enum zclient_send_status
zclient_unregister_opaque(struct zclient
*zclient
,
1208 int zapi_opaque_reg_decode(struct stream
*msg
,
1209 struct zapi_opaque_reg_info
*info
);
1212 * Registry of opaque message types. Please do not reuse an in-use
1213 * type code; some daemons are likely relying on it.
1215 enum zapi_opaque_registry
{
1216 /* Request link-state database dump, at restart for example */
1217 LINK_STATE_SYNC
= 1,
1218 /* Update containing link-state db info */
1219 LINK_STATE_UPDATE
= 2,
1220 /* Request LDP-SYNC state from LDP */
1221 LDP_IGP_SYNC_IF_STATE_REQUEST
= 3,
1222 /* Update containing LDP IGP Sync State info */
1223 LDP_IGP_SYNC_IF_STATE_UPDATE
= 4,
1224 /* Announce that LDP is up */
1225 LDP_IGP_SYNC_ANNOUNCE_UPDATE
= 5,
1226 /* Register RLFA with LDP */
1227 LDP_RLFA_REGISTER
= 7,
1228 /* Unregister all RLFAs with LDP */
1229 LDP_RLFA_UNREGISTER_ALL
= 8,
1230 /* Announce LDP labels associated to a previously registered RLFA */
1231 LDP_RLFA_LABELS
= 9,
1234 /* Send the hello message.
1235 * Returns 0 for success or -1 on an I/O error.
1237 extern enum zclient_send_status
zclient_send_hello(struct zclient
*client
);
1239 extern enum zclient_send_status
1240 zclient_send_neigh_discovery_req(struct zclient
*zclient
,
1241 const struct interface
*ifp
,
1242 const struct prefix
*p
);
1244 struct zapi_client_close_info
{
1245 /* Client session tuple */
1248 uint32_t session_id
;
1251 /* Decode incoming client close notify */
1252 extern int zapi_client_close_notify_decode(struct stream
*s
,
1253 struct zapi_client_close_info
*info
);
1255 extern int zclient_send_zebra_gre_request(struct zclient
*client
,
1256 struct interface
*ifp
);
1261 #endif /* _ZEBRA_ZCLIENT_H */