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_IPV4_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
457 * ZAPI Nexthop Group. For use with protocol creation of nexthop groups.
463 uint16_t nexthop_num
;
464 struct zapi_nexthop nexthops
[MULTIPATH_NUM
];
466 uint16_t backup_nexthop_num
;
467 struct zapi_nexthop backup_nexthops
[MULTIPATH_NUM
];
471 * Some of these data structures do not map easily to
472 * a actual data structure size giving different compilers
473 * and systems. For those data structures we need
474 * to use the smallest available stream_getX/putX functions
479 unsigned short instance
;
481 /* If you add flags, update zclient_dump_route_flags */
484 * Cause Zebra to consider this routes nexthops recursively
486 #define ZEBRA_FLAG_ALLOW_RECURSION 0x01
488 * This is a route that is read in on startup that was left around
489 * from a previous run of FRR
491 #define ZEBRA_FLAG_SELFROUTE 0x02
493 * This flag is used to tell Zebra that the BGP route being passed
494 * down is a IBGP route
496 #define ZEBRA_FLAG_IBGP 0x04
498 * This is a route that has been selected for FIB installation.
499 * This flag is set in zebra and can be passed up to routing daemons
501 #define ZEBRA_FLAG_SELECTED 0x08
503 * This is a route that we are telling Zebra that this route *must*
504 * win and will be installed even over ZEBRA_FLAG_SELECTED
506 #define ZEBRA_FLAG_FIB_OVERRIDE 0x10
508 * This flag tells Zebra that the route is a EVPN route and should
509 * be treated specially
511 #define ZEBRA_FLAG_EVPN_ROUTE 0x20
513 * This flag tells Zebra that it should treat the distance passed
514 * down as an additional discriminator for route selection of the
515 * route entry. This mainly is used for backup static routes.
517 #define ZEBRA_FLAG_RR_USE_DISTANCE 0x40
519 * This flag tells everyone that the route was intentionally
520 * not offloaded and the route will be sent to the cpu for
521 * forwarding. This flag makes no sense unless you are in
522 * an asic offload situation
524 #define ZEBRA_FLAG_TRAPPED 0x80
526 * This flag tells everyone that the route has been
527 * successfully offloaded to an asic for forwarding.
528 * This flag makes no sense unless you are in an asic
531 #define ZEBRA_FLAG_OFFLOADED 0x100
533 * This flag tells everyone that the route has
535 * This flag makes no sense unless you are in an asic
538 #define ZEBRA_FLAG_OFFLOAD_FAILED 0x200
540 /* The older XXX_MESSAGE flags live here */
544 * This is an enum but we are going to treat it as a uint8_t
545 * for purpose of encoding/decoding
549 struct prefix prefix
;
550 struct prefix_ipv6 src_prefix
;
552 uint16_t nexthop_num
;
553 struct zapi_nexthop nexthops
[MULTIPATH_NUM
];
555 /* Support backup routes for IP FRR, TI-LFA, traffic engineering */
556 uint16_t backup_nexthop_num
;
557 struct zapi_nexthop backup_nexthops
[MULTIPATH_NUM
];
573 /* SR-TE color (used for nexthop updates only). */
576 #define ZAPI_MESSAGE_OPAQUE_LENGTH 1024
579 uint8_t data
[ZAPI_MESSAGE_OPAQUE_LENGTH
];
583 extern char *zclient_dump_route_flags(uint32_t flags
, char *buf
, size_t len
);
587 #define ZAPI_LABELS_FTN 0x01
588 #define ZAPI_LABELS_HAS_BACKUPS 0x02
589 enum lsp_types_t type
;
590 mpls_label_t local_label
;
592 struct prefix prefix
;
594 unsigned short instance
;
597 uint16_t nexthop_num
;
598 struct zapi_nexthop nexthops
[MULTIPATH_NUM
];
600 /* Backup nexthops, if present */
601 uint16_t backup_nexthop_num
;
602 struct zapi_nexthop backup_nexthops
[MULTIPATH_NUM
];
605 struct zapi_srte_tunnel
{
606 enum lsp_types_t type
;
607 mpls_label_t local_label
;
609 mpls_label_t labels
[MPLS_MAX_LABELS
];
612 struct zapi_sr_policy
{
614 struct ipaddr endpoint
;
615 char name
[SRTE_POLICY_NAME_MAX_LENGTH
];
616 struct zapi_srte_tunnel segment_list
;
621 char ifname
[IF_NAMESIZE
];
625 union g_addr nexthop
;
626 uint32_t local_label
;
627 uint32_t remote_label
;
629 union pw_protocol_fields data
;
633 struct zapi_pw_status
{
634 char ifname
[IF_NAMESIZE
];
639 /* IGP instance data associated to a RLFA. */
640 struct zapi_rlfa_igp
{
655 /* IGP -> LDP RLFA (un)registration message. */
656 struct zapi_rlfa_request
{
657 /* IGP instance data. */
658 struct zapi_rlfa_igp igp
;
660 /* Destination prefix. */
661 struct prefix destination
;
663 /* PQ node address. */
664 struct in_addr pq_address
;
667 /* LDP -> IGP RLFA label update. */
668 struct zapi_rlfa_response
{
669 /* IGP instance data. */
670 struct zapi_rlfa_igp igp
;
672 /* Destination prefix. */
673 struct prefix destination
;
675 /* Resolved LDP labels. */
676 mpls_label_t pq_label
;
677 uint16_t nexthop_num
;
682 } nexthops
[MULTIPATH_NUM
];
685 enum zapi_route_notify_owner
{
686 ZAPI_ROUTE_FAIL_INSTALL
,
687 ZAPI_ROUTE_BETTER_ADMIN_WON
,
688 ZAPI_ROUTE_INSTALLED
,
690 ZAPI_ROUTE_REMOVE_FAIL
,
693 enum zapi_nhg_notify_owner
{
694 ZAPI_NHG_FAIL_INSTALL
,
697 ZAPI_NHG_REMOVE_FAIL
,
700 enum zapi_rule_notify_owner
{
701 ZAPI_RULE_FAIL_INSTALL
,
704 ZAPI_RULE_FAIL_REMOVE
,
714 enum zapi_ipset_notify_owner
{
715 ZAPI_IPSET_FAIL_INSTALL
= 0,
716 ZAPI_IPSET_INSTALLED
,
718 ZAPI_IPSET_FAIL_REMOVE
,
721 enum zapi_ipset_entry_notify_owner
{
722 ZAPI_IPSET_ENTRY_FAIL_INSTALL
= 0,
723 ZAPI_IPSET_ENTRY_INSTALLED
,
724 ZAPI_IPSET_ENTRY_REMOVED
,
725 ZAPI_IPSET_ENTRY_FAIL_REMOVE
,
728 enum zapi_iptable_notify_owner
{
729 ZAPI_IPTABLE_FAIL_INSTALL
= 0,
730 ZAPI_IPTABLE_INSTALLED
,
731 ZAPI_IPTABLE_REMOVED
,
732 ZAPI_IPTABLE_FAIL_REMOVE
,
735 enum zclient_send_status
{
736 ZCLIENT_SEND_FAILURE
= -1,
737 ZCLIENT_SEND_SUCCESS
= 0,
738 ZCLIENT_SEND_BUFFERED
= 1
741 static inline const char *
742 zapi_nhg_notify_owner2str(enum zapi_nhg_notify_owner note
)
744 const char *ret
= "UNKNOWN";
747 case ZAPI_NHG_FAIL_INSTALL
:
748 ret
= "ZAPI_NHG_FAIL_INSTALL";
750 case ZAPI_NHG_INSTALLED
:
751 ret
= "ZAPI_NHG_INSTALLED";
753 case ZAPI_NHG_REMOVE_FAIL
:
754 ret
= "ZAPI_NHG_REMOVE_FAIL";
756 case ZAPI_NHG_REMOVED
:
757 ret
= "ZAPI_NHG_REMOVED";
764 static inline const char *
765 zapi_rule_notify_owner2str(enum zapi_rule_notify_owner note
)
767 const char *ret
= "UNKNOWN";
770 case ZAPI_RULE_FAIL_INSTALL
:
771 ret
= "ZAPI_RULE_FAIL_INSTALL";
773 case ZAPI_RULE_INSTALLED
:
774 ret
= "ZAPI_RULE_INSTALLED";
776 case ZAPI_RULE_FAIL_REMOVE
:
777 ret
= "ZAPI_RULE_FAIL_REMOVE";
779 case ZAPI_RULE_REMOVED
:
780 ret
= "ZAPI_RULE_REMOVED";
787 /* Zebra MAC types */
788 #define ZEBRA_MACIP_TYPE_STICKY 0x01 /* Sticky MAC*/
789 #define ZEBRA_MACIP_TYPE_GW 0x02 /* gateway (SVI) mac*/
790 #define ZEBRA_MACIP_TYPE_ROUTER_FLAG 0x04 /* Router Flag - proxy NA */
791 #define ZEBRA_MACIP_TYPE_OVERRIDE_FLAG 0x08 /* Override Flag */
792 #define ZEBRA_MACIP_TYPE_SVI_IP 0x10 /* SVI MAC-IP */
793 #define ZEBRA_MACIP_TYPE_PROXY_ADVERT 0x20 /* Not locally active */
794 #define ZEBRA_MACIP_TYPE_SYNC_PATH 0x40 /* sync path */
795 /* XXX - flags is an u8; that needs to be changed to u32 if you need
796 * to allocate past 0x80. Additionally touch zclient_evpn_dump_macip_flags
798 #define MACIP_BUF_SIZE 128
799 extern char *zclient_evpn_dump_macip_flags(uint8_t flags
, char *buf
,
802 /* Zebra ES VTEP flags (ZEBRA_REMOTE_ES_VTEP_ADD) */
803 /* ESR has been rxed from the VTEP. Only VTEPs that have advertised the
804 * Type-4 route can participate in DF election.
806 #define ZAPI_ES_VTEP_FLAG_ESR_RXED (1 << 0)
808 enum zebra_neigh_state
{ ZEBRA_NEIGH_INACTIVE
= 0, ZEBRA_NEIGH_ACTIVE
= 1 };
810 struct zclient_options
{
815 extern struct zclient_options zclient_options_default
;
817 /* link layer representation for GRE like interfaces
818 * ip_in is the underlay IP, ip_out is the tunnel dest
819 * index stands for the index of the interface
820 * ndm state stands for the NDM value in netlink
821 * (see linux/neighbour.h)
823 #define ZEBRA_NEIGH_STATE_INCOMPLETE (0x01)
824 #define ZEBRA_NEIGH_STATE_REACHABLE (0x02)
825 #define ZEBRA_NEIGH_STATE_STALE (0x04)
826 #define ZEBRA_NEIGH_STATE_DELAY (0x08)
827 #define ZEBRA_NEIGH_STATE_PROBE (0x10)
828 #define ZEBRA_NEIGH_STATE_FAILED (0x20)
829 #define ZEBRA_NEIGH_STATE_NOARP (0x40)
830 #define ZEBRA_NEIGH_STATE_PERMANENT (0x80)
831 #define ZEBRA_NEIGH_STATE_NONE (0x00)
833 struct zapi_neigh_ip
{
836 struct ipaddr ip_out
;
840 int zclient_neigh_ip_decode(struct stream
*s
, struct zapi_neigh_ip
*api
);
841 int zclient_neigh_ip_encode(struct stream
*s
, uint16_t cmd
, union sockunion
*in
,
842 union sockunion
*out
, struct interface
*ifp
,
846 * We reserve the top 4 bits for l2-NHG, everything else
847 * is for zebra/proto l3-NHG.
849 * Each client is going to get it's own nexthop group space
850 * and we'll separate them, we'll figure out where to start based upon
853 #define ZEBRA_NHG_PROTO_UPPER \
854 ((uint32_t)250000000) /* Bottom 28 bits then rounded down */
855 #define ZEBRA_NHG_PROTO_SPACING (ZEBRA_NHG_PROTO_UPPER / ZEBRA_ROUTE_MAX)
856 #define ZEBRA_NHG_PROTO_LOWER \
857 (ZEBRA_NHG_PROTO_SPACING * (ZEBRA_ROUTE_CONNECT + 1))
859 extern uint32_t zclient_get_nhg_start(uint32_t proto
);
861 extern struct zclient
*zclient_new(struct thread_master
*m
,
862 struct zclient_options
*opt
,
863 zclient_handler
*const *handlers
,
866 extern void zclient_init(struct zclient
*, int, unsigned short,
867 struct zebra_privs_t
*privs
);
868 extern int zclient_start(struct zclient
*);
869 extern void zclient_stop(struct zclient
*);
870 extern void zclient_reset(struct zclient
*);
871 extern void zclient_free(struct zclient
*);
873 extern int zclient_socket_connect(struct zclient
*);
875 extern unsigned short *redist_check_instance(struct redist_proto
*,
877 extern void redist_add_instance(struct redist_proto
*, unsigned short);
878 extern void redist_del_instance(struct redist_proto
*, unsigned short);
879 extern void redist_del_all_instances(struct redist_proto
*red
);
882 * Send to zebra that the specified vrf is using label to resolve
883 * itself for L3VPN's. Repeated calls of this function with
884 * different labels will cause an effective update of the
885 * label for lookup. If you pass in MPLS_LABEL_NONE
886 * we will cause a delete action and remove this label pop
889 * The underlying AF_MPLS doesn't care about afi's
890 * but we can make the zebra_vrf keep track of what
891 * we have installed and play some special games
892 * to get them both installed.
894 extern enum zclient_send_status
895 zclient_send_vrf_label(struct zclient
*zclient
, vrf_id_t vrf_id
, afi_t afi
,
896 mpls_label_t label
, enum lsp_types_t ltype
);
898 extern enum zclient_send_status
899 zclient_send_localsid(struct zclient
*zclient
, const struct in6_addr
*sid
,
900 ifindex_t oif
, enum seg6local_action_t action
,
901 const struct seg6local_context
*context
);
903 extern void zclient_send_reg_requests(struct zclient
*, vrf_id_t
);
904 extern void zclient_send_dereg_requests(struct zclient
*, vrf_id_t
);
905 extern enum zclient_send_status
906 zclient_send_router_id_update(struct zclient
*zclient
,
907 zebra_message_types_t type
, afi_t afi
,
910 extern enum zclient_send_status
911 zclient_send_interface_radv_req(struct zclient
*zclient
, vrf_id_t vrf_id
,
912 struct interface
*ifp
, int enable
,
913 uint32_t ra_interval
);
914 extern enum zclient_send_status
915 zclient_send_interface_protodown(struct zclient
*zclient
, vrf_id_t vrf_id
,
916 struct interface
*ifp
, bool down
);
918 /* Send redistribute command to zebra daemon. Do not update zclient state. */
919 extern enum zclient_send_status
920 zebra_redistribute_send(int command
, struct zclient
*, afi_t
, int type
,
921 unsigned short instance
, vrf_id_t vrf_id
);
923 extern enum zclient_send_status
924 zebra_redistribute_default_send(int command
, struct zclient
*zclient
, afi_t afi
,
927 /* Send route notify request to zebra */
928 extern int zebra_route_notify_send(int command
, struct zclient
*zclient
,
931 /* If state has changed, update state and call zebra_redistribute_send. */
932 extern void zclient_redistribute(int command
, struct zclient
*, afi_t
, int type
,
933 unsigned short instance
, vrf_id_t vrf_id
);
935 /* If state has changed, update state and send the command to zebra. */
936 extern void zclient_redistribute_default(int command
, struct zclient
*,
937 afi_t
, vrf_id_t vrf_id
);
940 * Send the message in zclient->obuf to the zebra daemon (or enqueue it).
943 * 0 data was successfully sent
944 * 1 data was buffered for future usage
946 extern enum zclient_send_status
zclient_send_message(struct zclient
*);
948 /* create header for command, length to be filled in by user later */
949 extern void zclient_create_header(struct stream
*, uint16_t, vrf_id_t
);
951 * Read sizeof(struct zmsghdr) bytes from the provided socket and parse the
952 * received data into the specified fields. If this is successful, read the
953 * rest of the packet into the provided stream.
956 * The stream to read into
959 * The socket to read from
962 * Parsed message size will be placed in the pointed-at integer
965 * Parsed marker will be placed in the pointed-at byte
968 * Parsed version will be placed in the pointed-at byte
971 * Parsed VRF ID will be placed in the pointed-at vrf_id_t
974 * Parsed command number will be placed in the pointed-at integer
978 * - insufficient data for header was read
979 * - a version mismatch was detected
980 * - a marker mismatch was detected
981 * - header size field specified more data than could be read
983 extern int zclient_read_header(struct stream
*s
, int sock
, uint16_t *size
,
984 uint8_t *marker
, uint8_t *version
,
985 vrf_id_t
*vrf_id
, uint16_t *cmd
);
987 * Parse header from ZAPI message stream into struct zmsghdr.
988 * This function assumes the stream getp points at the first byte of the header.
989 * If the function is successful then the stream getp will point to the byte
990 * immediately after the last byte of the header.
993 * The stream containing the header
996 * The header struct to parse into.
999 * true if parsing succeeded, false otherwise
1001 extern bool zapi_parse_header(struct stream
*zmsg
, struct zmsghdr
*hdr
);
1003 extern enum zclient_send_status
1004 zclient_interface_set_master(struct zclient
*client
, struct interface
*master
,
1005 struct interface
*slave
);
1006 extern struct interface
*zebra_interface_state_read(struct stream
*s
, vrf_id_t
);
1007 extern struct connected
*zebra_interface_address_read(int, struct stream
*,
1009 extern struct nbr_connected
*
1010 zebra_interface_nbr_address_read(int, struct stream
*, vrf_id_t
);
1011 extern struct interface
*zebra_interface_vrf_update_read(struct stream
*s
,
1013 vrf_id_t
*new_vrf_id
);
1014 extern int zebra_router_id_update_read(struct stream
*s
, struct prefix
*rid
);
1016 extern struct interface
*zebra_interface_link_params_read(struct stream
*s
,
1019 extern size_t zebra_interface_link_params_write(struct stream
*,
1020 struct interface
*);
1021 extern enum zclient_send_status
1022 zclient_send_get_label_chunk(struct zclient
*zclient
, uint8_t keep
,
1023 uint32_t chunk_size
, uint32_t base
);
1025 extern int lm_label_manager_connect(struct zclient
*zclient
, int async
);
1026 extern int lm_get_label_chunk(struct zclient
*zclient
, uint8_t keep
,
1027 uint32_t base
, uint32_t chunk_size
,
1028 uint32_t *start
, uint32_t *end
);
1029 extern int lm_release_label_chunk(struct zclient
*zclient
, uint32_t start
,
1031 extern int tm_table_manager_connect(struct zclient
*zclient
);
1032 extern int tm_get_table_chunk(struct zclient
*zclient
, uint32_t chunk_size
,
1033 uint32_t *start
, uint32_t *end
);
1034 extern int tm_release_table_chunk(struct zclient
*zclient
, uint32_t start
,
1036 extern int srv6_manager_get_locator_chunk(struct zclient
*zclient
,
1037 const char *locator_name
);
1038 extern int srv6_manager_release_locator_chunk(struct zclient
*zclient
,
1039 const char *locator_name
);
1041 extern enum zclient_send_status
zebra_send_sr_policy(struct zclient
*zclient
,
1043 struct zapi_sr_policy
*zp
);
1044 extern int zapi_sr_policy_encode(struct stream
*s
, int cmd
,
1045 struct zapi_sr_policy
*zp
);
1046 extern int zapi_sr_policy_decode(struct stream
*s
, struct zapi_sr_policy
*zp
);
1047 extern int zapi_sr_policy_notify_status_decode(struct stream
*s
,
1048 struct zapi_sr_policy
*zp
);
1050 extern enum zclient_send_status
zebra_send_mpls_labels(struct zclient
*zclient
,
1052 struct zapi_labels
*zl
);
1053 extern int zapi_labels_encode(struct stream
*s
, int cmd
,
1054 struct zapi_labels
*zl
);
1055 extern int zapi_labels_decode(struct stream
*s
, struct zapi_labels
*zl
);
1057 extern int zapi_srv6_locator_encode(struct stream
*s
,
1058 const struct srv6_locator
*l
);
1059 extern int zapi_srv6_locator_decode(struct stream
*s
, struct srv6_locator
*l
);
1060 extern int zapi_srv6_locator_chunk_encode(struct stream
*s
,
1061 const struct srv6_locator_chunk
*c
);
1062 extern int zapi_srv6_locator_chunk_decode(struct stream
*s
,
1063 struct srv6_locator_chunk
*c
);
1065 extern enum zclient_send_status
zebra_send_pw(struct zclient
*zclient
,
1066 int command
, struct zapi_pw
*pw
);
1067 extern int zebra_read_pw_status_update(ZAPI_CALLBACK_ARGS
,
1068 struct zapi_pw_status
*pw
);
1070 extern enum zclient_send_status
zclient_route_send(uint8_t, struct zclient
*,
1071 struct zapi_route
*);
1072 extern enum zclient_send_status
1073 zclient_send_rnh(struct zclient
*zclient
, int command
, const struct prefix
*p
,
1074 safi_t safi
, bool connected
, bool resolve_via_default
,
1076 int zapi_nexthop_encode(struct stream
*s
, const struct zapi_nexthop
*api_nh
,
1077 uint32_t api_flags
, uint32_t api_message
);
1078 extern int zapi_route_encode(uint8_t, struct stream
*, struct zapi_route
*);
1079 extern int zapi_route_decode(struct stream
*s
, struct zapi_route
*api
);
1080 extern int zapi_nexthop_decode(struct stream
*s
, struct zapi_nexthop
*api_nh
,
1081 uint32_t api_flags
, uint32_t api_message
);
1082 bool zapi_nhg_notify_decode(struct stream
*s
, uint32_t *id
,
1083 enum zapi_nhg_notify_owner
*note
);
1084 bool zapi_route_notify_decode(struct stream
*s
, struct prefix
*p
,
1086 enum zapi_route_notify_owner
*note
,
1087 afi_t
*afi
, safi_t
*safi
);
1088 bool zapi_rule_notify_decode(struct stream
*s
, uint32_t *seqno
,
1089 uint32_t *priority
, uint32_t *unique
, char *ifname
,
1090 enum zapi_rule_notify_owner
*note
);
1091 bool zapi_ipset_notify_decode(struct stream
*s
,
1093 enum zapi_ipset_notify_owner
*note
);
1095 /* Nexthop-group message apis */
1096 extern enum zclient_send_status
1097 zclient_nhg_send(struct zclient
*zclient
, int cmd
, struct zapi_nhg
*api_nhg
);
1099 #define ZEBRA_IPSET_NAME_SIZE 32
1101 bool zapi_ipset_entry_notify_decode(struct stream
*s
,
1104 enum zapi_ipset_entry_notify_owner
*note
);
1105 bool zapi_iptable_notify_decode(struct stream
*s
,
1107 enum zapi_iptable_notify_owner
*note
);
1109 extern struct nexthop
*
1110 nexthop_from_zapi_nexthop(const struct zapi_nexthop
*znh
);
1111 int zapi_nexthop_from_nexthop(struct zapi_nexthop
*znh
,
1112 const struct nexthop
*nh
);
1113 int zapi_backup_nexthop_from_nexthop(struct zapi_nexthop
*znh
,
1114 const struct nexthop
*nh
);
1116 * match -> is the prefix that the calling daemon asked to be matched
1118 * nhr->prefix -> is the actual prefix that was matched against in the
1121 * This distinction is made because a LPM can be made if there is a
1122 * covering route. This way the upper level protocol can make a decision
1123 * point about whether or not it wants to use the match or not.
1125 extern bool zapi_nexthop_update_decode(struct stream
*s
, struct prefix
*match
,
1126 struct zapi_route
*nhr
);
1127 const char *zapi_nexthop2str(const struct zapi_nexthop
*znh
, char *buf
,
1130 /* Decode the zebra error message */
1131 extern bool zapi_error_decode(struct stream
*s
, enum zebra_error_types
*error
);
1133 /* Encode and decode restart capabilities */
1134 extern enum zclient_send_status
1135 zclient_capabilities_send(uint32_t cmd
, struct zclient
*zclient
,
1136 struct zapi_cap
*api
);
1137 extern int32_t zapi_capabilities_decode(struct stream
*s
, struct zapi_cap
*api
);
1139 static inline void zapi_route_set_blackhole(struct zapi_route
*api
,
1140 enum blackhole_type bh_type
)
1142 api
->nexthop_num
= 1;
1143 api
->nexthops
[0].type
= NEXTHOP_TYPE_BLACKHOLE
;
1144 api
->nexthops
[0].vrf_id
= VRF_DEFAULT
;
1145 api
->nexthops
[0].bh_type
= bh_type
;
1146 SET_FLAG(api
->message
, ZAPI_MESSAGE_NEXTHOP
);
1149 extern enum zclient_send_status
1150 zclient_send_mlag_register(struct zclient
*client
, uint32_t bit_map
);
1151 extern enum zclient_send_status
1152 zclient_send_mlag_deregister(struct zclient
*client
);
1154 extern enum zclient_send_status
zclient_send_mlag_data(struct zclient
*client
,
1155 struct stream
*client_s
);
1158 * Send an OPAQUE message, contents opaque to zebra - but note that
1159 * the length of the payload is restricted by the zclient's
1160 * outgoing message buffer.
1161 * The message header is a message subtype; please use the registry
1162 * below to avoid sub-type collisions. Clients use the registration
1163 * apis to manage the specific opaque subtypes they want to receive.
1165 enum zclient_send_status
zclient_send_opaque(struct zclient
*zclient
,
1166 uint32_t type
, const uint8_t *data
,
1169 enum zclient_send_status
1170 zclient_send_opaque_unicast(struct zclient
*zclient
, uint32_t type
,
1171 uint8_t proto
, uint16_t instance
,
1172 uint32_t session_id
, const uint8_t *data
,
1175 /* Struct representing the decoded opaque header info */
1176 struct zapi_opaque_msg
{
1177 uint32_t type
; /* Subtype */
1178 uint16_t len
; /* len after zapi header and this info */
1181 /* Client-specific info - *if* UNICAST flag is set */
1184 uint32_t session_id
;
1187 #define ZAPI_OPAQUE_FLAG_UNICAST 0x01
1189 /* Simple struct to convey registration/unreg requests */
1190 struct zapi_opaque_reg_info
{
1191 /* Message subtype */
1194 /* Client session tuple */
1197 uint32_t session_id
;
1200 /* Decode incoming opaque */
1201 int zclient_opaque_decode(struct stream
*msg
, struct zapi_opaque_msg
*info
);
1203 enum zclient_send_status
zclient_register_opaque(struct zclient
*zclient
,
1205 enum zclient_send_status
zclient_unregister_opaque(struct zclient
*zclient
,
1207 int zapi_opaque_reg_decode(struct stream
*msg
,
1208 struct zapi_opaque_reg_info
*info
);
1211 * Registry of opaque message types. Please do not reuse an in-use
1212 * type code; some daemons are likely relying on it.
1214 enum zapi_opaque_registry
{
1215 /* Request link-state database dump, at restart for example */
1216 LINK_STATE_SYNC
= 1,
1217 /* Update containing link-state db info */
1218 LINK_STATE_UPDATE
= 2,
1219 /* Request LDP-SYNC state from LDP */
1220 LDP_IGP_SYNC_IF_STATE_REQUEST
= 3,
1221 /* Update containing LDP IGP Sync State info */
1222 LDP_IGP_SYNC_IF_STATE_UPDATE
= 4,
1223 /* Announce that LDP is up */
1224 LDP_IGP_SYNC_ANNOUNCE_UPDATE
= 5,
1225 /* Register RLFA with LDP */
1226 LDP_RLFA_REGISTER
= 7,
1227 /* Unregister all RLFAs with LDP */
1228 LDP_RLFA_UNREGISTER_ALL
= 8,
1229 /* Announce LDP labels associated to a previously registered RLFA */
1230 LDP_RLFA_LABELS
= 9,
1233 /* Send the hello message.
1234 * Returns 0 for success or -1 on an I/O error.
1236 extern enum zclient_send_status
zclient_send_hello(struct zclient
*client
);
1238 extern enum zclient_send_status
1239 zclient_send_neigh_discovery_req(struct zclient
*zclient
,
1240 const struct interface
*ifp
,
1241 const struct prefix
*p
);
1243 struct zapi_client_close_info
{
1244 /* Client session tuple */
1247 uint32_t session_id
;
1250 /* Decode incoming client close notify */
1251 extern int zapi_client_close_notify_decode(struct stream
*s
,
1252 struct zapi_client_close_info
*info
);
1254 extern int zclient_send_zebra_gre_request(struct zclient
*client
,
1255 struct interface
*ifp
);
1260 #endif /* _ZEBRA_ZCLIENT_H */