]> git.proxmox.com Git - mirror_frr.git/blob - lib/zclient.h
Merge pull request #6279 from opensourcerouting/nb-cb-args
[mirror_frr.git] / lib / zclient.h
1 /* Zebra's client header.
2 * Copyright (C) 1999 Kunihiro Ishiguro
3 *
4 * This file is part of GNU Zebra.
5 *
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)
9 * any later version.
10 *
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.
15 *
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
19 */
20
21 #ifndef _ZEBRA_ZCLIENT_H
22 #define _ZEBRA_ZCLIENT_H
23
24 /* For struct zapi_route. */
25 #include "prefix.h"
26
27 /* For struct interface and struct connected. */
28 #include "if.h"
29
30 /* For vrf_bitmap_t. */
31 #include "vrf.h"
32
33 /* For union g_addr */
34 #include "nexthop.h"
35
36 /* For union pw_protocol_fields */
37 #include "pw.h"
38
39 #include "mlag.h"
40
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44
45 /* Zebra types. Used in Zserv message header. */
46 typedef uint16_t zebra_size_t;
47
48 /* Marker value used in new Zserv, in the byte location corresponding
49 * the command value in the old zserv header. To allow old and new
50 * Zserv headers to be distinguished from each other.
51 */
52 #define ZEBRA_HEADER_MARKER 254
53
54 /* For input/output buffer to zebra. */
55 #define ZEBRA_MAX_PACKET_SIZ 16384U
56
57 /* Zebra header size. */
58 #define ZEBRA_HEADER_SIZE 10
59
60 /* special socket path name to use TCP
61 * @ is used as first character because that's abstract socket names on Linux
62 */
63 #define ZAPI_TCP_PATHNAME "@tcp"
64
65 /* IPset size name stands for the name of the ipset entry
66 * that can be created by using some zapi interfaces
67 */
68 #define ZEBRA_IPSET_NAME_SIZE 32
69
70 /* IPTable action is defined by two values: either
71 * forward or drop
72 */
73 #define ZEBRA_IPTABLES_FORWARD 0
74 #define ZEBRA_IPTABLES_DROP 1
75
76 /* Zebra FEC register command flags. */
77 #define ZEBRA_FEC_REGISTER_LABEL 0x1
78 #define ZEBRA_FEC_REGISTER_LABEL_INDEX 0x2
79
80 /* Client capabilities */
81 enum zserv_client_capabilities {
82 ZEBRA_CLIENT_GR_CAPABILITIES = 1,
83 ZEBRA_CLIENT_ROUTE_UPDATE_COMPLETE = 2,
84 ZEBRA_CLIENT_ROUTE_UPDATE_PENDING = 3,
85 ZEBRA_CLIENT_GR_DISABLE = 4,
86 ZEBRA_CLIENT_RIB_STALE_TIME
87 };
88
89 /* Macro to check if there GR enabled. */
90 #define ZEBRA_CLIENT_GR_ENABLED(X) (X == ZEBRA_CLIENT_GR_CAPABILITIES)
91
92 extern struct sockaddr_storage zclient_addr;
93 extern socklen_t zclient_addr_len;
94
95 /* Zebra message types. */
96 typedef enum {
97 ZEBRA_INTERFACE_ADD,
98 ZEBRA_INTERFACE_DELETE,
99 ZEBRA_INTERFACE_ADDRESS_ADD,
100 ZEBRA_INTERFACE_ADDRESS_DELETE,
101 ZEBRA_INTERFACE_UP,
102 ZEBRA_INTERFACE_DOWN,
103 ZEBRA_INTERFACE_SET_MASTER,
104 ZEBRA_INTERFACE_SET_PROTODOWN,
105 ZEBRA_ROUTE_ADD,
106 ZEBRA_ROUTE_DELETE,
107 ZEBRA_ROUTE_NOTIFY_OWNER,
108 ZEBRA_REDISTRIBUTE_ADD,
109 ZEBRA_REDISTRIBUTE_DELETE,
110 ZEBRA_REDISTRIBUTE_DEFAULT_ADD,
111 ZEBRA_REDISTRIBUTE_DEFAULT_DELETE,
112 ZEBRA_ROUTER_ID_ADD,
113 ZEBRA_ROUTER_ID_DELETE,
114 ZEBRA_ROUTER_ID_UPDATE,
115 ZEBRA_HELLO,
116 ZEBRA_CAPABILITIES,
117 ZEBRA_NEXTHOP_REGISTER,
118 ZEBRA_NEXTHOP_UNREGISTER,
119 ZEBRA_NEXTHOP_UPDATE,
120 ZEBRA_INTERFACE_NBR_ADDRESS_ADD,
121 ZEBRA_INTERFACE_NBR_ADDRESS_DELETE,
122 ZEBRA_INTERFACE_BFD_DEST_UPDATE,
123 ZEBRA_IMPORT_ROUTE_REGISTER,
124 ZEBRA_IMPORT_ROUTE_UNREGISTER,
125 ZEBRA_IMPORT_CHECK_UPDATE,
126 ZEBRA_BFD_DEST_REGISTER,
127 ZEBRA_BFD_DEST_DEREGISTER,
128 ZEBRA_BFD_DEST_UPDATE,
129 ZEBRA_BFD_DEST_REPLAY,
130 ZEBRA_REDISTRIBUTE_ROUTE_ADD,
131 ZEBRA_REDISTRIBUTE_ROUTE_DEL,
132 ZEBRA_VRF_UNREGISTER,
133 ZEBRA_VRF_ADD,
134 ZEBRA_VRF_DELETE,
135 ZEBRA_VRF_LABEL,
136 ZEBRA_INTERFACE_VRF_UPDATE,
137 ZEBRA_BFD_CLIENT_REGISTER,
138 ZEBRA_BFD_CLIENT_DEREGISTER,
139 ZEBRA_INTERFACE_ENABLE_RADV,
140 ZEBRA_INTERFACE_DISABLE_RADV,
141 ZEBRA_IPV4_NEXTHOP_LOOKUP_MRIB,
142 ZEBRA_INTERFACE_LINK_PARAMS,
143 ZEBRA_MPLS_LABELS_ADD,
144 ZEBRA_MPLS_LABELS_DELETE,
145 ZEBRA_MPLS_LABELS_REPLACE,
146 ZEBRA_IPMR_ROUTE_STATS,
147 ZEBRA_LABEL_MANAGER_CONNECT,
148 ZEBRA_LABEL_MANAGER_CONNECT_ASYNC,
149 ZEBRA_GET_LABEL_CHUNK,
150 ZEBRA_RELEASE_LABEL_CHUNK,
151 ZEBRA_FEC_REGISTER,
152 ZEBRA_FEC_UNREGISTER,
153 ZEBRA_FEC_UPDATE,
154 ZEBRA_ADVERTISE_DEFAULT_GW,
155 ZEBRA_ADVERTISE_SVI_MACIP,
156 ZEBRA_ADVERTISE_SUBNET,
157 ZEBRA_ADVERTISE_ALL_VNI,
158 ZEBRA_LOCAL_ES_ADD,
159 ZEBRA_LOCAL_ES_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_ERROR,
203 ZEBRA_CLIENT_CAPABILITIES
204 } zebra_message_types_t;
205
206 enum zebra_error_types {
207 ZEBRA_UNKNOWN_ERROR, /* Error of unknown type */
208 ZEBRA_NO_VRF, /* Vrf in header was not found */
209 ZEBRA_INVALID_MSG_TYPE, /* No handler found for msg type */
210 };
211
212 static inline const char *zebra_error_type2str(enum zebra_error_types type)
213 {
214 const char *ret = "UNKNOWN";
215
216 switch (type) {
217 case ZEBRA_UNKNOWN_ERROR:
218 ret = "ZEBRA_UNKNOWN_ERROR";
219 break;
220 case ZEBRA_NO_VRF:
221 ret = "ZEBRA_NO_VRF";
222 break;
223 case ZEBRA_INVALID_MSG_TYPE:
224 ret = "ZEBRA_INVALID_MSG_TYPE";
225 break;
226 }
227
228 return ret;
229 }
230
231 struct redist_proto {
232 uint8_t enabled;
233 struct list *instances;
234 };
235
236 struct zclient_capabilities {
237 uint32_t ecmp;
238 bool mpls_enabled;
239 enum mlag_role role;
240 };
241
242 /* Graceful Restart Capabilities message */
243 struct zapi_cap {
244 enum zserv_client_capabilities cap;
245 uint32_t stale_removal_time;
246 afi_t afi;
247 safi_t safi;
248 vrf_id_t vrf_id;
249 };
250
251 /* Structure for the zebra client. */
252 struct zclient {
253 /* The thread master we schedule ourselves on */
254 struct thread_master *master;
255
256 /* Priviledges to change socket values */
257 struct zebra_privs_t *privs;
258
259 /* Do we care about failure events for route install? */
260 bool receive_notify;
261
262 /* Is this a synchronous client? */
263 bool synchronous;
264
265 /* Session id (optional) to support clients with multiple sessions */
266 uint32_t session_id;
267
268 /* Socket to zebra daemon. */
269 int sock;
270
271 /* Connection failure count. */
272 int fail;
273
274 /* Input buffer for zebra message. */
275 struct stream *ibuf;
276
277 /* Output buffer for zebra message. */
278 struct stream *obuf;
279
280 /* Buffer of data waiting to be written to zebra. */
281 struct buffer *wb;
282
283 /* Read and connect thread. */
284 struct thread *t_read;
285 struct thread *t_connect;
286
287 /* Thread to write buffered data to zebra. */
288 struct thread *t_write;
289
290 /* Redistribute information. */
291 uint8_t redist_default; /* clients protocol */
292 unsigned short instance;
293 struct redist_proto mi_redist[AFI_MAX][ZEBRA_ROUTE_MAX];
294 vrf_bitmap_t redist[AFI_MAX][ZEBRA_ROUTE_MAX];
295
296 /* Redistribute defauilt. */
297 vrf_bitmap_t default_information[AFI_MAX];
298
299 #define ZAPI_CALLBACK_ARGS \
300 int cmd, struct zclient *zclient, uint16_t length, vrf_id_t vrf_id
301
302 /* Pointer to the callback functions. */
303 void (*zebra_connected)(struct zclient *);
304 void (*zebra_capabilities)(struct zclient_capabilities *cap);
305 int (*router_id_update)(ZAPI_CALLBACK_ARGS);
306 int (*interface_address_add)(ZAPI_CALLBACK_ARGS);
307 int (*interface_address_delete)(ZAPI_CALLBACK_ARGS);
308 int (*interface_link_params)(ZAPI_CALLBACK_ARGS);
309 int (*interface_bfd_dest_update)(ZAPI_CALLBACK_ARGS);
310 int (*interface_nbr_address_add)(ZAPI_CALLBACK_ARGS);
311 int (*interface_nbr_address_delete)(ZAPI_CALLBACK_ARGS);
312 int (*interface_vrf_update)(ZAPI_CALLBACK_ARGS);
313 int (*nexthop_update)(ZAPI_CALLBACK_ARGS);
314 int (*import_check_update)(ZAPI_CALLBACK_ARGS);
315 int (*bfd_dest_replay)(ZAPI_CALLBACK_ARGS);
316 int (*redistribute_route_add)(ZAPI_CALLBACK_ARGS);
317 int (*redistribute_route_del)(ZAPI_CALLBACK_ARGS);
318 int (*fec_update)(int, struct zclient *, uint16_t);
319 int (*local_es_add)(ZAPI_CALLBACK_ARGS);
320 int (*local_es_del)(ZAPI_CALLBACK_ARGS);
321 int (*local_vni_add)(ZAPI_CALLBACK_ARGS);
322 int (*local_vni_del)(ZAPI_CALLBACK_ARGS);
323 int (*local_l3vni_add)(ZAPI_CALLBACK_ARGS);
324 int (*local_l3vni_del)(ZAPI_CALLBACK_ARGS);
325 void (*local_ip_prefix_add)(ZAPI_CALLBACK_ARGS);
326 void (*local_ip_prefix_del)(ZAPI_CALLBACK_ARGS);
327 int (*local_macip_add)(ZAPI_CALLBACK_ARGS);
328 int (*local_macip_del)(ZAPI_CALLBACK_ARGS);
329 int (*pw_status_update)(ZAPI_CALLBACK_ARGS);
330 int (*route_notify_owner)(ZAPI_CALLBACK_ARGS);
331 int (*rule_notify_owner)(ZAPI_CALLBACK_ARGS);
332 void (*label_chunk)(ZAPI_CALLBACK_ARGS);
333 int (*ipset_notify_owner)(ZAPI_CALLBACK_ARGS);
334 int (*ipset_entry_notify_owner)(ZAPI_CALLBACK_ARGS);
335 int (*iptable_notify_owner)(ZAPI_CALLBACK_ARGS);
336 int (*vxlan_sg_add)(ZAPI_CALLBACK_ARGS);
337 int (*vxlan_sg_del)(ZAPI_CALLBACK_ARGS);
338 int (*mlag_process_up)(void);
339 int (*mlag_process_down)(void);
340 int (*mlag_handle_msg)(struct stream *msg, int len);
341 int (*handle_error)(enum zebra_error_types error);
342 };
343
344 /* Zebra API message flag. */
345 #define ZAPI_MESSAGE_NEXTHOP 0x01
346 #define ZAPI_MESSAGE_DISTANCE 0x02
347 #define ZAPI_MESSAGE_METRIC 0x04
348 #define ZAPI_MESSAGE_TAG 0x08
349 #define ZAPI_MESSAGE_MTU 0x10
350 #define ZAPI_MESSAGE_SRCPFX 0x20
351 /* Backup nexthops are present */
352 #define ZAPI_MESSAGE_BACKUP_NEXTHOPS 0x40
353
354 /*
355 * This should only be used by a DAEMON that needs to communicate
356 * the table being used is not in the VRF. You must pass the
357 * default vrf, else this will be ignored.
358 */
359 #define ZAPI_MESSAGE_TABLEID 0x80
360
361 #define ZSERV_VERSION 6
362 /* Zserv protocol message header */
363 struct zmsghdr {
364 uint16_t length;
365 /* Always set to 255 in new zserv */
366 uint8_t marker;
367 uint8_t version;
368 vrf_id_t vrf_id;
369 uint16_t command;
370 } __attribute__((packed));
371 #define ZAPI_HEADER_CMD_LOCATION offsetof(struct zmsghdr, command)
372
373 struct zapi_nexthop {
374 enum nexthop_types_t type;
375 vrf_id_t vrf_id;
376 ifindex_t ifindex;
377 uint8_t flags;
378 union {
379 union g_addr gate;
380 enum blackhole_type bh_type;
381 };
382
383 /* MPLS labels for BGP-LU or Segment Routing */
384 uint8_t label_num;
385 mpls_label_t labels[MPLS_MAX_LABELS];
386
387 struct ethaddr rmac;
388
389 uint32_t weight;
390
391 /* Index of backup nexthop */
392 uint8_t backup_idx;
393 };
394
395 /*
396 * ZAPI nexthop flags values - we're encoding a single octet
397 * initially, so ensure that the on-the-wire encoding continues
398 * to match the number of valid flags.
399 */
400
401 #define ZAPI_NEXTHOP_FLAG_ONLINK 0x01
402 #define ZAPI_NEXTHOP_FLAG_LABEL 0x02
403 #define ZAPI_NEXTHOP_FLAG_WEIGHT 0x04
404 #define ZAPI_NEXTHOP_FLAG_HAS_BACKUP 0x08 /* Nexthop has a backup */
405
406 /*
407 * Some of these data structures do not map easily to
408 * a actual data structure size giving different compilers
409 * and systems. For those data structures we need
410 * to use the smallest available stream_getX/putX functions
411 * to encode/decode.
412 */
413 struct zapi_route {
414 uint8_t type;
415 unsigned short instance;
416
417 uint32_t flags;
418 /*
419 * Cause Zebra to consider this routes nexthops recursively
420 */
421 #define ZEBRA_FLAG_ALLOW_RECURSION 0x01
422 /*
423 * This is a route that is read in on startup that was left around
424 * from a previous run of FRR
425 */
426 #define ZEBRA_FLAG_SELFROUTE 0x02
427 /*
428 * This flag is used to tell Zebra that the BGP route being passed
429 * down is a IBGP route
430 */
431 #define ZEBRA_FLAG_IBGP 0x04
432 /*
433 * This is a route that has been selected for FIB installation.
434 * This flag is set in zebra and can be passed up to routing daemons
435 */
436 #define ZEBRA_FLAG_SELECTED 0x08
437 /*
438 * This is a route that we are telling Zebra that this route *must*
439 * win and will be installed even over ZEBRA_FLAG_SELECTED
440 */
441 #define ZEBRA_FLAG_FIB_OVERRIDE 0x10
442 /*
443 * This flag tells Zebra that the route is a EVPN route and should
444 * be treated specially
445 */
446 #define ZEBRA_FLAG_EVPN_ROUTE 0x20
447 /*
448 * This flag tells Zebra that it should treat the distance passed
449 * down as an additional discriminator for route selection of the
450 * route entry. This mainly is used for backup static routes.
451 */
452 #define ZEBRA_FLAG_RR_USE_DISTANCE 0x40
453
454 uint8_t message;
455
456 /*
457 * This is an enum but we are going to treat it as a uint8_t
458 * for purpose of encoding/decoding
459 */
460 safi_t safi;
461
462 struct prefix prefix;
463 struct prefix_ipv6 src_prefix;
464
465 uint16_t nexthop_num;
466 struct zapi_nexthop nexthops[MULTIPATH_NUM];
467
468 /* Support backup routes for IP FRR, TI-LFA, traffic engineering */
469 uint16_t backup_nexthop_num;
470 struct zapi_nexthop backup_nexthops[MULTIPATH_NUM];
471
472 uint8_t distance;
473
474 uint32_t metric;
475
476 route_tag_t tag;
477
478 uint32_t mtu;
479
480 vrf_id_t vrf_id;
481
482 uint32_t tableid;
483 };
484
485 struct zapi_labels {
486 uint8_t message;
487 #define ZAPI_LABELS_FTN 0x01
488 enum lsp_types_t type;
489 mpls_label_t local_label;
490 struct {
491 struct prefix prefix;
492 uint8_t type;
493 unsigned short instance;
494 } route;
495
496 uint16_t nexthop_num;
497 struct zapi_nexthop nexthops[MULTIPATH_NUM];
498 };
499
500 struct zapi_pw {
501 char ifname[IF_NAMESIZE];
502 ifindex_t ifindex;
503 int type;
504 int af;
505 union g_addr nexthop;
506 uint32_t local_label;
507 uint32_t remote_label;
508 uint8_t flags;
509 union pw_protocol_fields data;
510 uint8_t protocol;
511 };
512
513 struct zapi_pw_status {
514 char ifname[IF_NAMESIZE];
515 ifindex_t ifindex;
516 uint32_t status;
517 };
518
519 enum zapi_route_notify_owner {
520 ZAPI_ROUTE_FAIL_INSTALL,
521 ZAPI_ROUTE_BETTER_ADMIN_WON,
522 ZAPI_ROUTE_INSTALLED,
523 ZAPI_ROUTE_REMOVED,
524 ZAPI_ROUTE_REMOVE_FAIL,
525 };
526
527 enum zapi_rule_notify_owner {
528 ZAPI_RULE_FAIL_INSTALL,
529 ZAPI_RULE_INSTALLED,
530 ZAPI_RULE_REMOVED,
531 ZAPI_RULE_FAIL_REMOVE,
532 };
533
534 enum ipset_type {
535 IPSET_NET_NET = 1,
536 IPSET_NET_PORT_NET,
537 IPSET_NET_PORT,
538 IPSET_NET
539 };
540
541 enum zapi_ipset_notify_owner {
542 ZAPI_IPSET_FAIL_INSTALL,
543 ZAPI_IPSET_INSTALLED,
544 ZAPI_IPSET_REMOVED,
545 ZAPI_IPSET_FAIL_REMOVE,
546 };
547
548 enum zapi_ipset_entry_notify_owner {
549 ZAPI_IPSET_ENTRY_FAIL_INSTALL,
550 ZAPI_IPSET_ENTRY_INSTALLED,
551 ZAPI_IPSET_ENTRY_REMOVED,
552 ZAPI_IPSET_ENTRY_FAIL_REMOVE,
553 };
554
555 enum zapi_iptable_notify_owner {
556 ZAPI_IPTABLE_FAIL_INSTALL,
557 ZAPI_IPTABLE_INSTALLED,
558 ZAPI_IPTABLE_REMOVED,
559 ZAPI_IPTABLE_FAIL_REMOVE,
560 };
561
562 static inline const char *
563 zapi_rule_notify_owner2str(enum zapi_rule_notify_owner note)
564 {
565 const char *ret = "UNKNOWN";
566
567 switch (note) {
568 case ZAPI_RULE_FAIL_INSTALL:
569 ret = "ZAPI_RULE_FAIL_INSTALL";
570 break;
571 case ZAPI_RULE_INSTALLED:
572 ret = "ZAPI_RULE_INSTALLED";
573 break;
574 case ZAPI_RULE_FAIL_REMOVE:
575 ret = "ZAPI_RULE_FAIL_REMOVE";
576 break;
577 case ZAPI_RULE_REMOVED:
578 ret = "ZAPI_RULE_REMOVED";
579 break;
580 }
581
582 return ret;
583 }
584
585 /* Zebra MAC types */
586 #define ZEBRA_MACIP_TYPE_STICKY 0x01 /* Sticky MAC*/
587 #define ZEBRA_MACIP_TYPE_GW 0x02 /* gateway (SVI) mac*/
588 #define ZEBRA_MACIP_TYPE_ROUTER_FLAG 0x04 /* Router Flag - proxy NA */
589 #define ZEBRA_MACIP_TYPE_OVERRIDE_FLAG 0x08 /* Override Flag */
590 #define ZEBRA_MACIP_TYPE_SVI_IP 0x10 /* SVI MAC-IP */
591
592 enum zebra_neigh_state { ZEBRA_NEIGH_INACTIVE = 0, ZEBRA_NEIGH_ACTIVE = 1 };
593
594 struct zclient_options {
595 bool receive_notify;
596 bool synchronous;
597 };
598
599 extern struct zclient_options zclient_options_default;
600
601 extern struct zclient *zclient_new(struct thread_master *m,
602 struct zclient_options *opt);
603
604 extern void zclient_init(struct zclient *, int, unsigned short,
605 struct zebra_privs_t *privs);
606 extern int zclient_start(struct zclient *);
607 extern void zclient_stop(struct zclient *);
608 extern void zclient_reset(struct zclient *);
609 extern void zclient_free(struct zclient *);
610
611 extern int zclient_socket_connect(struct zclient *);
612
613 extern unsigned short *redist_check_instance(struct redist_proto *,
614 unsigned short);
615 extern void redist_add_instance(struct redist_proto *, unsigned short);
616 extern void redist_del_instance(struct redist_proto *, unsigned short);
617 extern void redist_del_all_instances(struct redist_proto *red);
618
619 /*
620 * Send to zebra that the specified vrf is using label to resolve
621 * itself for L3VPN's. Repeated calls of this function with
622 * different labels will cause an effective update of the
623 * label for lookup. If you pass in MPLS_LABEL_NONE
624 * we will cause a delete action and remove this label pop
625 * operation.
626 *
627 * The underlying AF_MPLS doesn't care about afi's
628 * but we can make the zebra_vrf keep track of what
629 * we have installed and play some special games
630 * to get them both installed.
631 */
632 extern void zclient_send_vrf_label(struct zclient *zclient, vrf_id_t vrf_id,
633 afi_t afi, mpls_label_t label,
634 enum lsp_types_t ltype);
635
636 extern void zclient_send_reg_requests(struct zclient *, vrf_id_t);
637 extern void zclient_send_dereg_requests(struct zclient *, vrf_id_t);
638
639 extern void zclient_send_interface_radv_req(struct zclient *zclient,
640 vrf_id_t vrf_id,
641 struct interface *ifp, int enable,
642 int ra_interval);
643 extern int zclient_send_interface_protodown(struct zclient *zclient,
644 vrf_id_t vrf_id,
645 struct interface *ifp, bool down);
646
647 /* Send redistribute command to zebra daemon. Do not update zclient state. */
648 extern int zebra_redistribute_send(int command, struct zclient *, afi_t,
649 int type, unsigned short instance,
650 vrf_id_t vrf_id);
651
652 extern int zebra_redistribute_default_send(int command, struct zclient *zclient,
653 afi_t afi, vrf_id_t vrf_id);
654
655 /* If state has changed, update state and call zebra_redistribute_send. */
656 extern void zclient_redistribute(int command, struct zclient *, afi_t, int type,
657 unsigned short instance, vrf_id_t vrf_id);
658
659 /* If state has changed, update state and send the command to zebra. */
660 extern void zclient_redistribute_default(int command, struct zclient *,
661 afi_t, vrf_id_t vrf_id);
662
663 /* Send the message in zclient->obuf to the zebra daemon (or enqueue it).
664 Returns 0 for success or -1 on an I/O error. */
665 extern int zclient_send_message(struct zclient *);
666
667 /* create header for command, length to be filled in by user later */
668 extern void zclient_create_header(struct stream *, uint16_t, vrf_id_t);
669 /*
670 * Read sizeof(struct zmsghdr) bytes from the provided socket and parse the
671 * received data into the specified fields. If this is successful, read the
672 * rest of the packet into the provided stream.
673 *
674 * s
675 * The stream to read into
676 *
677 * sock
678 * The socket to read from
679 *
680 * size
681 * Parsed message size will be placed in the pointed-at integer
682 *
683 * marker
684 * Parsed marker will be placed in the pointed-at byte
685 *
686 * version
687 * Parsed version will be placed in the pointed-at byte
688 *
689 * vrf_id
690 * Parsed VRF ID will be placed in the pointed-at vrf_id_t
691 *
692 * cmd
693 * Parsed command number will be placed in the pointed-at integer
694 *
695 * Returns:
696 * -1 if:
697 * - insufficient data for header was read
698 * - a version mismatch was detected
699 * - a marker mismatch was detected
700 * - header size field specified more data than could be read
701 */
702 extern int zclient_read_header(struct stream *s, int sock, uint16_t *size,
703 uint8_t *marker, uint8_t *version,
704 vrf_id_t *vrf_id, uint16_t *cmd);
705 /*
706 * Parse header from ZAPI message stream into struct zmsghdr.
707 * This function assumes the stream getp points at the first byte of the header.
708 * If the function is successful then the stream getp will point to the byte
709 * immediately after the last byte of the header.
710 *
711 * zmsg
712 * The stream containing the header
713 *
714 * hdr
715 * The header struct to parse into.
716 *
717 * Returns:
718 * true if parsing succeeded, false otherwise
719 */
720 extern bool zapi_parse_header(struct stream *zmsg, struct zmsghdr *hdr);
721
722 extern void zclient_interface_set_master(struct zclient *client,
723 struct interface *master,
724 struct interface *slave);
725 extern struct interface *zebra_interface_state_read(struct stream *s, vrf_id_t);
726 extern struct connected *zebra_interface_address_read(int, struct stream *,
727 vrf_id_t);
728 extern struct nbr_connected *
729 zebra_interface_nbr_address_read(int, struct stream *, vrf_id_t);
730 extern struct interface *zebra_interface_vrf_update_read(struct stream *s,
731 vrf_id_t vrf_id,
732 vrf_id_t *new_vrf_id);
733 extern int zebra_router_id_update_read(struct stream *s, struct prefix *rid);
734
735 extern struct interface *zebra_interface_link_params_read(struct stream *s,
736 vrf_id_t vrf_id);
737 extern size_t zebra_interface_link_params_write(struct stream *,
738 struct interface *);
739 extern int zclient_send_get_label_chunk(struct zclient *zclient, uint8_t keep,
740 uint32_t chunk_size, uint32_t base);
741
742 extern int lm_label_manager_connect(struct zclient *zclient, int async);
743 extern int lm_get_label_chunk(struct zclient *zclient, uint8_t keep,
744 uint32_t base, uint32_t chunk_size,
745 uint32_t *start, uint32_t *end);
746 extern int lm_release_label_chunk(struct zclient *zclient, uint32_t start,
747 uint32_t end);
748 extern int tm_table_manager_connect(struct zclient *zclient);
749 extern int tm_get_table_chunk(struct zclient *zclient, uint32_t chunk_size,
750 uint32_t *start, uint32_t *end);
751 extern int tm_release_table_chunk(struct zclient *zclient, uint32_t start,
752 uint32_t end);
753
754 extern int zebra_send_mpls_labels(struct zclient *zclient, int cmd,
755 struct zapi_labels *zl);
756 extern int zapi_labels_encode(struct stream *s, int cmd,
757 struct zapi_labels *zl);
758 extern int zapi_labels_decode(struct stream *s, struct zapi_labels *zl);
759
760 extern int zebra_send_pw(struct zclient *zclient, int command,
761 struct zapi_pw *pw);
762 extern int zebra_read_pw_status_update(ZAPI_CALLBACK_ARGS,
763 struct zapi_pw_status *pw);
764
765 extern int zclient_route_send(uint8_t, struct zclient *, struct zapi_route *);
766 extern int zclient_send_rnh(struct zclient *zclient, int command,
767 const struct prefix *p, bool exact_match,
768 vrf_id_t vrf_id);
769 int zapi_nexthop_encode(struct stream *s, const struct zapi_nexthop *api_nh,
770 uint32_t api_flags);
771 extern int zapi_route_encode(uint8_t, struct stream *, struct zapi_route *);
772 extern int zapi_route_decode(struct stream *, struct zapi_route *);
773 bool zapi_route_notify_decode(struct stream *s, struct prefix *p,
774 uint32_t *tableid,
775 enum zapi_route_notify_owner *note);
776 bool zapi_rule_notify_decode(struct stream *s, uint32_t *seqno,
777 uint32_t *priority, uint32_t *unique,
778 ifindex_t *ifindex,
779 enum zapi_rule_notify_owner *note);
780 bool zapi_ipset_notify_decode(struct stream *s,
781 uint32_t *unique,
782 enum zapi_ipset_notify_owner *note);
783
784 #define ZEBRA_IPSET_NAME_SIZE 32
785
786 bool zapi_ipset_entry_notify_decode(struct stream *s,
787 uint32_t *unique,
788 char *ipset_name,
789 enum zapi_ipset_entry_notify_owner *note);
790 bool zapi_iptable_notify_decode(struct stream *s,
791 uint32_t *unique,
792 enum zapi_iptable_notify_owner *note);
793
794 extern struct nexthop *
795 nexthop_from_zapi_nexthop(const struct zapi_nexthop *znh);
796 int zapi_nexthop_from_nexthop(struct zapi_nexthop *znh,
797 const struct nexthop *nh);
798 int zapi_backup_nexthop_from_nexthop(struct zapi_nexthop *znh,
799 const struct nexthop *nh);
800 extern bool zapi_nexthop_update_decode(struct stream *s,
801 struct zapi_route *nhr);
802
803 /* Decode the zebra error message */
804 extern bool zapi_error_decode(struct stream *s, enum zebra_error_types *error);
805
806 /* Encode and decode restart capabilities */
807 extern int32_t zclient_capabilities_send(uint32_t cmd, struct zclient *zclient,
808 struct zapi_cap *api);
809 extern int32_t zapi_capabilities_decode(struct stream *s, struct zapi_cap *api);
810
811 static inline void zapi_route_set_blackhole(struct zapi_route *api,
812 enum blackhole_type bh_type)
813 {
814 api->nexthop_num = 1;
815 api->nexthops[0].type = NEXTHOP_TYPE_BLACKHOLE;
816 api->nexthops[0].vrf_id = VRF_DEFAULT;
817 api->nexthops[0].bh_type = bh_type;
818 SET_FLAG(api->message, ZAPI_MESSAGE_NEXTHOP);
819 };
820
821 extern void zclient_send_mlag_register(struct zclient *client,
822 uint32_t bit_map);
823 extern void zclient_send_mlag_deregister(struct zclient *client);
824
825 extern void zclient_send_mlag_data(struct zclient *client,
826 struct stream *client_s);
827
828 /* Send the hello message.
829 * Returns 0 for success or -1 on an I/O error.
830 */
831 extern int zclient_send_hello(struct zclient *client);
832
833 #ifdef __cplusplus
834 }
835 #endif
836
837 #endif /* _ZEBRA_ZCLIENT_H */