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