1 /* Zebra's client library.
2 * Copyright (C) 1999 Kunihiro Ishiguro
3 * Copyright (C) 2005 Andrew J. Schorr
5 * This file is part of GNU Zebra.
7 * GNU Zebra is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published
9 * by the Free Software Foundation; either version 2, or (at your
10 * option) any later version.
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; see the file COPYING; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
40 #include "nexthop_group.h"
41 #include "lib_errors.h"
43 DEFINE_MTYPE_STATIC(LIB
, ZCLIENT
, "Zclient")
44 DEFINE_MTYPE_STATIC(LIB
, REDIST_INST
, "Redistribution instance IDs")
46 /* Zebra client events. */
47 enum event
{ ZCLIENT_SCHEDULE
, ZCLIENT_READ
, ZCLIENT_CONNECT
};
49 /* Prototype for event manager. */
50 static void zclient_event(enum event
, struct zclient
*);
52 static void zebra_interface_if_set_value(struct stream
*s
,
53 struct interface
*ifp
);
55 struct zclient_options zclient_options_default
= {.receive_notify
= false};
57 struct sockaddr_storage zclient_addr
;
58 socklen_t zclient_addr_len
;
60 /* This file local debug flag. */
61 static int zclient_debug
;
63 /* Allocate zclient structure. */
64 struct zclient
*zclient_new(struct thread_master
*master
,
65 struct zclient_options
*opt
)
67 struct zclient
*zclient
;
69 MAX(ZEBRA_MAX_PACKET_SIZ
, sizeof(struct zapi_route
));
71 zclient
= XCALLOC(MTYPE_ZCLIENT
, sizeof(struct zclient
));
73 zclient
->ibuf
= stream_new(stream_size
);
74 zclient
->obuf
= stream_new(stream_size
);
75 zclient
->wb
= buffer_new(0);
76 zclient
->master
= master
;
78 zclient
->receive_notify
= opt
->receive_notify
;
83 /* This function is only called when exiting, because
84 many parts of the code do not check for I/O errors, so they could
85 reference an invalid pointer if the structure was ever freed.
87 Free zclient structure. */
88 void zclient_free(struct zclient
*zclient
)
91 stream_free(zclient
->ibuf
);
93 stream_free(zclient
->obuf
);
95 buffer_free(zclient
->wb
);
97 XFREE(MTYPE_ZCLIENT
, zclient
);
100 unsigned short *redist_check_instance(struct redist_proto
*red
,
101 unsigned short instance
)
103 struct listnode
*node
;
109 for (ALL_LIST_ELEMENTS_RO(red
->instances
, node
, id
))
116 void redist_add_instance(struct redist_proto
*red
, unsigned short instance
)
123 red
->instances
= list_new();
125 in
= XMALLOC(MTYPE_REDIST_INST
, sizeof(unsigned short));
127 listnode_add(red
->instances
, in
);
130 void redist_del_instance(struct redist_proto
*red
, unsigned short instance
)
134 id
= redist_check_instance(red
, instance
);
138 listnode_delete(red
->instances
, id
);
139 XFREE(MTYPE_REDIST_INST
, id
);
140 if (!red
->instances
->count
) {
142 list_delete(&red
->instances
);
146 /* Stop zebra client services. */
147 void zclient_stop(struct zclient
*zclient
)
153 zlog_debug("zclient stopped");
156 THREAD_OFF(zclient
->t_read
);
157 THREAD_OFF(zclient
->t_connect
);
158 THREAD_OFF(zclient
->t_write
);
161 stream_reset(zclient
->ibuf
);
162 stream_reset(zclient
->obuf
);
164 /* Empty the write buffer. */
165 buffer_reset(zclient
->wb
);
168 if (zclient
->sock
>= 0) {
169 close(zclient
->sock
);
174 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++) {
175 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++) {
176 vrf_bitmap_free(zclient
->redist
[afi
][i
]);
177 zclient
->redist
[afi
][i
] = VRF_BITMAP_NULL
;
180 &zclient
->mi_redist
[afi
][zclient
->redist_default
],
183 vrf_bitmap_free(zclient
->default_information
[afi
]);
184 zclient
->default_information
[afi
] = VRF_BITMAP_NULL
;
188 void zclient_reset(struct zclient
*zclient
)
192 zclient_stop(zclient
);
194 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
196 &zclient
->mi_redist
[afi
][zclient
->redist_default
],
199 zclient_init(zclient
, zclient
->redist_default
, zclient
->instance
,
204 * Connect to zebra daemon.
205 * @param zclient a pointer to zclient structure
206 * @return socket fd just to make sure that connection established
210 int zclient_socket_connect(struct zclient
*zclient
)
215 /* We should think about IPv6 connection. */
216 sock
= socket(zclient_addr
.ss_family
, SOCK_STREAM
, 0);
221 setsockopt_so_sendbuf(sock
, 1048576);
223 /* Connect to zebra. */
224 ret
= connect(sock
, (struct sockaddr
*)&zclient_addr
, zclient_addr_len
);
227 zlog_debug("%s connect failure: %d(%s)",
228 __PRETTY_FUNCTION__
, errno
,
229 safe_strerror(errno
));
234 zclient
->sock
= sock
;
238 static int zclient_failed(struct zclient
*zclient
)
241 zclient_stop(zclient
);
242 zclient_event(ZCLIENT_CONNECT
, zclient
);
246 static int zclient_flush_data(struct thread
*thread
)
248 struct zclient
*zclient
= THREAD_ARG(thread
);
250 zclient
->t_write
= NULL
;
251 if (zclient
->sock
< 0)
253 switch (buffer_flush_available(zclient
->wb
, zclient
->sock
)) {
257 "%s: buffer_flush_available failed on zclient fd %d, closing",
258 __func__
, zclient
->sock
);
259 return zclient_failed(zclient
);
262 zclient
->t_write
= NULL
;
263 thread_add_write(zclient
->master
, zclient_flush_data
, zclient
,
264 zclient
->sock
, &zclient
->t_write
);
272 int zclient_send_message(struct zclient
*zclient
)
274 if (zclient
->sock
< 0)
276 switch (buffer_write(zclient
->wb
, zclient
->sock
,
277 STREAM_DATA(zclient
->obuf
),
278 stream_get_endp(zclient
->obuf
))) {
280 flog_err(EC_LIB_ZAPI_SOCKET
,
281 "%s: buffer_write failed to zclient fd %d, closing",
282 __func__
, zclient
->sock
);
283 return zclient_failed(zclient
);
286 THREAD_OFF(zclient
->t_write
);
289 thread_add_write(zclient
->master
, zclient_flush_data
, zclient
,
290 zclient
->sock
, &zclient
->t_write
);
297 * If we add more data to this structure please ensure that
298 * struct zmsghdr in lib/zclient.h is updated as appropriate.
300 void zclient_create_header(struct stream
*s
, uint16_t command
, vrf_id_t vrf_id
)
302 /* length placeholder, caller can update */
303 stream_putw(s
, ZEBRA_HEADER_SIZE
);
304 stream_putc(s
, ZEBRA_HEADER_MARKER
);
305 stream_putc(s
, ZSERV_VERSION
);
306 stream_putl(s
, vrf_id
);
307 stream_putw(s
, command
);
310 int zclient_read_header(struct stream
*s
, int sock
, uint16_t *size
,
311 uint8_t *marker
, uint8_t *version
, vrf_id_t
*vrf_id
,
314 if (stream_read(s
, sock
, ZEBRA_HEADER_SIZE
) != ZEBRA_HEADER_SIZE
)
317 STREAM_GETW(s
, *size
);
318 *size
-= ZEBRA_HEADER_SIZE
;
319 STREAM_GETC(s
, *marker
);
320 STREAM_GETC(s
, *version
);
321 STREAM_GETL(s
, *vrf_id
);
322 STREAM_GETW(s
, *cmd
);
324 if (*version
!= ZSERV_VERSION
|| *marker
!= ZEBRA_HEADER_MARKER
) {
326 EC_LIB_ZAPI_MISSMATCH
,
327 "%s: socket %d version mismatch, marker %d, version %d",
328 __func__
, sock
, *marker
, *version
);
332 if (*size
&& stream_read(s
, sock
, *size
) != *size
)
340 bool zapi_parse_header(struct stream
*zmsg
, struct zmsghdr
*hdr
)
342 STREAM_GETW(zmsg
, hdr
->length
);
343 STREAM_GETC(zmsg
, hdr
->marker
);
344 STREAM_GETC(zmsg
, hdr
->version
);
345 STREAM_GETL(zmsg
, hdr
->vrf_id
);
346 STREAM_GETW(zmsg
, hdr
->command
);
352 /* Send simple Zebra message. */
353 static int zebra_message_send(struct zclient
*zclient
, int command
,
358 /* Get zclient output buffer. */
362 /* Send very simple command only Zebra message. */
363 zclient_create_header(s
, command
, vrf_id
);
365 return zclient_send_message(zclient
);
368 static int zebra_hello_send(struct zclient
*zclient
)
372 if (zclient
->redist_default
) {
376 /* The VRF ID in the HELLO message is always 0. */
377 zclient_create_header(s
, ZEBRA_HELLO
, VRF_DEFAULT
);
378 stream_putc(s
, zclient
->redist_default
);
379 stream_putw(s
, zclient
->instance
);
380 if (zclient
->receive_notify
)
385 stream_putw_at(s
, 0, stream_get_endp(s
));
386 return zclient_send_message(zclient
);
392 void zclient_send_vrf_label(struct zclient
*zclient
, vrf_id_t vrf_id
, afi_t afi
,
393 mpls_label_t label
, enum lsp_types_t ltype
)
400 zclient_create_header(s
, ZEBRA_VRF_LABEL
, vrf_id
);
401 stream_putl(s
, label
);
403 stream_putc(s
, ltype
);
404 stream_putw_at(s
, 0, stream_get_endp(s
));
405 zclient_send_message(zclient
);
408 /* Send register requests to zebra daemon for the information in a VRF. */
409 void zclient_send_reg_requests(struct zclient
*zclient
, vrf_id_t vrf_id
)
414 /* If not connected to the zebra yet. */
415 if (zclient
->sock
< 0)
419 zlog_debug("%s: send register messages for VRF %u", __func__
,
422 /* We need router-id information. */
423 zebra_message_send(zclient
, ZEBRA_ROUTER_ID_ADD
, vrf_id
);
425 /* We need interface information. */
426 zebra_message_send(zclient
, ZEBRA_INTERFACE_ADD
, vrf_id
);
428 /* Set unwanted redistribute route. */
429 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
430 vrf_bitmap_set(zclient
->redist
[afi
][zclient
->redist_default
],
433 /* Flush all redistribute request. */
434 if (vrf_id
== VRF_DEFAULT
) {
435 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++) {
436 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++) {
437 if (!zclient
->mi_redist
[afi
][i
].enabled
)
440 struct listnode
*node
;
443 for (ALL_LIST_ELEMENTS_RO(
444 zclient
->mi_redist
[afi
][i
]
447 if (!(i
== zclient
->redist_default
448 && *id
== zclient
->instance
))
449 zebra_redistribute_send(
450 ZEBRA_REDISTRIBUTE_ADD
,
451 zclient
, afi
, i
, *id
,
457 /* Resend all redistribute request. */
458 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++) {
459 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++)
460 if (i
!= zclient
->redist_default
461 && vrf_bitmap_check(zclient
->redist
[afi
][i
],
463 zebra_redistribute_send(ZEBRA_REDISTRIBUTE_ADD
,
467 /* If default information is needed. */
468 if (vrf_bitmap_check(zclient
->default_information
[afi
], vrf_id
))
469 zebra_redistribute_default_send(
470 ZEBRA_REDISTRIBUTE_DEFAULT_ADD
, zclient
, afi
,
475 /* Send unregister requests to zebra daemon for the information in a VRF. */
476 void zclient_send_dereg_requests(struct zclient
*zclient
, vrf_id_t vrf_id
)
481 /* If not connected to the zebra yet. */
482 if (zclient
->sock
< 0)
486 zlog_debug("%s: send deregister messages for VRF %u", __func__
,
489 /* We need router-id information. */
490 zebra_message_send(zclient
, ZEBRA_ROUTER_ID_DELETE
, vrf_id
);
492 zebra_message_send(zclient
, ZEBRA_INTERFACE_DELETE
, vrf_id
);
494 /* Set unwanted redistribute route. */
495 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
496 vrf_bitmap_unset(zclient
->redist
[afi
][zclient
->redist_default
],
499 /* Flush all redistribute request. */
500 if (vrf_id
== VRF_DEFAULT
) {
501 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++) {
502 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++) {
503 if (!zclient
->mi_redist
[afi
][i
].enabled
)
506 struct listnode
*node
;
509 for (ALL_LIST_ELEMENTS_RO(
510 zclient
->mi_redist
[afi
][i
]
513 if (!(i
== zclient
->redist_default
514 && *id
== zclient
->instance
))
515 zebra_redistribute_send(
516 ZEBRA_REDISTRIBUTE_DELETE
,
517 zclient
, afi
, i
, *id
,
523 /* Flush all redistribute request. */
524 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++) {
525 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++)
526 if (i
!= zclient
->redist_default
527 && vrf_bitmap_check(zclient
->redist
[afi
][i
],
529 zebra_redistribute_send(
530 ZEBRA_REDISTRIBUTE_DELETE
, zclient
, afi
,
533 /* If default information is needed. */
534 if (vrf_bitmap_check(zclient
->default_information
[afi
], vrf_id
))
535 zebra_redistribute_default_send(
536 ZEBRA_REDISTRIBUTE_DEFAULT_DELETE
, zclient
, afi
,
541 /* Send request to zebra daemon to start or stop RA. */
542 void zclient_send_interface_radv_req(struct zclient
*zclient
, vrf_id_t vrf_id
,
543 struct interface
*ifp
, int enable
,
548 /* If not connected to the zebra yet. */
549 if (zclient
->sock
< 0)
552 /* Form and send message. */
557 zclient_create_header(s
, ZEBRA_INTERFACE_ENABLE_RADV
, vrf_id
);
559 zclient_create_header(s
, ZEBRA_INTERFACE_DISABLE_RADV
, vrf_id
);
561 stream_putl(s
, ifp
->ifindex
);
562 stream_putl(s
, ra_interval
);
564 stream_putw_at(s
, 0, stream_get_endp(s
));
566 zclient_send_message(zclient
);
569 int zclient_send_interface_protodown(struct zclient
*zclient
, vrf_id_t vrf_id
,
570 struct interface
*ifp
, bool down
)
574 if (zclient
->sock
< 0)
579 zclient_create_header(s
, ZEBRA_INTERFACE_SET_PROTODOWN
, vrf_id
);
580 stream_putl(s
, ifp
->ifindex
);
581 stream_putc(s
, !!down
);
582 stream_putw_at(s
, 0, stream_get_endp(s
));
583 zclient_send_message(zclient
);
588 /* Make connection to zebra daemon. */
589 int zclient_start(struct zclient
*zclient
)
592 zlog_info("zclient_start is called");
594 /* If already connected to the zebra. */
595 if (zclient
->sock
>= 0)
598 /* Check connect thread. */
599 if (zclient
->t_connect
)
602 if (zclient_socket_connect(zclient
) < 0) {
604 zlog_debug("zclient connection fail");
606 zclient_event(ZCLIENT_CONNECT
, zclient
);
610 if (set_nonblocking(zclient
->sock
) < 0)
611 flog_err(EC_LIB_ZAPI_SOCKET
, "%s: set_nonblocking(%d) failed",
612 __func__
, zclient
->sock
);
614 /* Clear fail count. */
617 zlog_debug("zclient connect success with socket [%d]",
620 /* Create read thread. */
621 zclient_event(ZCLIENT_READ
, zclient
);
623 zebra_hello_send(zclient
);
625 zebra_message_send(zclient
, ZEBRA_INTERFACE_ADD
, VRF_DEFAULT
);
627 /* Inform the successful connection. */
628 if (zclient
->zebra_connected
)
629 (*zclient
->zebra_connected
)(zclient
);
634 /* Initialize zebra client. Argument redist_default is unwanted
635 redistribute route type. */
636 void zclient_init(struct zclient
*zclient
, int redist_default
,
637 unsigned short instance
, struct zebra_privs_t
*privs
)
641 /* Set -1 to the default socket value. */
643 zclient
->privs
= privs
;
645 /* Clear redistribution flags. */
646 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
647 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++)
648 zclient
->redist
[afi
][i
] = vrf_bitmap_init();
650 /* Set unwanted redistribute route. bgpd does not need BGP route
652 zclient
->redist_default
= redist_default
;
653 zclient
->instance
= instance
;
654 /* Pending: make afi(s) an arg. */
655 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++) {
656 redist_add_instance(&zclient
->mi_redist
[afi
][redist_default
],
659 /* Set default-information redistribute to zero. */
660 zclient
->default_information
[afi
] = vrf_bitmap_init();
664 zlog_debug("scheduling zclient connection");
666 zclient_event(ZCLIENT_SCHEDULE
, zclient
);
669 /* This function is a wrapper function for calling zclient_start from
670 timer or event thread. */
671 static int zclient_connect(struct thread
*t
)
673 struct zclient
*zclient
;
675 zclient
= THREAD_ARG(t
);
676 zclient
->t_connect
= NULL
;
679 zlog_debug("zclient_connect is called");
681 return zclient_start(zclient
);
684 int zclient_send_rnh(struct zclient
*zclient
, int command
, struct prefix
*p
,
685 bool exact_match
, vrf_id_t vrf_id
)
691 zclient_create_header(s
, command
, vrf_id
);
692 stream_putc(s
, (exact_match
) ? 1 : 0);
694 stream_putw(s
, PREFIX_FAMILY(p
));
695 stream_putc(s
, p
->prefixlen
);
696 switch (PREFIX_FAMILY(p
)) {
698 stream_put_in_addr(s
, &p
->u
.prefix4
);
701 stream_put(s
, &(p
->u
.prefix6
), 16);
706 stream_putw_at(s
, 0, stream_get_endp(s
));
708 return zclient_send_message(zclient
);
712 * "xdr_encode"-like interface that allows daemon (client) to send
713 * a message to zebra server for a route that needs to be
714 * added/deleted to the kernel. Info about the route is specified
715 * by the caller in a struct zapi_route. zapi_route_encode() then writes
716 * the info down the zclient socket using the stream_* functions.
718 * The corresponding read ("xdr_decode") function on the server
719 * side is zapi_route_decode().
721 * 0 1 2 3 4 5 6 7 8 9 A B C D E F 0 1 2 3 4 5 6 7 8 9 A B C D E F
722 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
723 * | Length (2) | Command | Route Type |
724 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
725 * | ZEBRA Flags | Message Flags | Prefix length |
726 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
727 * | Destination IPv4 Prefix for route |
728 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
733 * A number of IPv4 nexthop(s) or nexthop interface index(es) are then
734 * described, as per the Nexthop count. Each nexthop described as:
737 * | Nexthop Type | Set to one of ZEBRA_NEXTHOP_*
738 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
739 * | IPv4 Nexthop address or Interface Index number |
740 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
742 * Alternatively, if the route is a blackhole route, then Nexthop count
743 * is set to 1 and a nexthop of type NEXTHOP_TYPE_BLACKHOLE is the sole
746 * The original struct zapi_route_*() infrastructure was built around
747 * the traditional (32-bit "gate OR ifindex") nexthop data unit.
748 * A special encoding can be used to feed onlink (64-bit "gate AND ifindex")
749 * nexthops into zapi_route_encode() using the same zapi_route structure.
750 * This is done by setting zapi_route fields as follows:
751 * - .message |= ZAPI_MESSAGE_NEXTHOP | ZAPI_MESSAGE_ONLINK
752 * - .nexthop_num == .ifindex_num
753 * - .nexthop and .ifindex are filled with gate and ifindex parts of
754 * each compound nexthop, both in the same order
756 * If ZAPI_MESSAGE_DISTANCE is set, the distance value is written as a 1
759 * If ZAPI_MESSAGE_METRIC is set, the metric value is written as an 8
762 * If ZAPI_MESSAGE_TAG is set, the tag value is written as a 4 byte value
764 * If ZAPI_MESSAGE_MTU is set, the mtu value is written as a 4 byte value
766 * XXX: No attention paid to alignment.
768 int zclient_route_send(uint8_t cmd
, struct zclient
*zclient
,
769 struct zapi_route
*api
)
771 if (zapi_route_encode(cmd
, zclient
->obuf
, api
) < 0)
773 return zclient_send_message(zclient
);
776 static int zapi_nexthop_labels_cmp(const struct zapi_nexthop
*next1
,
777 const struct zapi_nexthop
*next2
)
779 if (next1
->label_num
> next2
->label_num
)
782 if (next1
->label_num
< next2
->label_num
)
785 return memcmp(next1
->labels
, next2
->labels
, next1
->label_num
);
788 static int zapi_nexthop_cmp_no_labels(const struct zapi_nexthop
*next1
,
789 const struct zapi_nexthop
*next2
)
793 if (next1
->vrf_id
< next2
->vrf_id
)
796 if (next1
->vrf_id
> next2
->vrf_id
)
799 if (next1
->type
< next2
->type
)
802 if (next1
->type
> next2
->type
)
805 if (next1
->weight
< next2
->weight
)
808 if (next1
->weight
> next2
->weight
)
811 switch (next1
->type
) {
812 case NEXTHOP_TYPE_IPV4
:
813 case NEXTHOP_TYPE_IPV6
:
814 ret
= nexthop_g_addr_cmp(next1
->type
, &next1
->gate
,
819 case NEXTHOP_TYPE_IPV4_IFINDEX
:
820 case NEXTHOP_TYPE_IPV6_IFINDEX
:
821 ret
= nexthop_g_addr_cmp(next1
->type
, &next1
->gate
,
825 /* Intentional Fall-Through */
826 case NEXTHOP_TYPE_IFINDEX
:
827 if (next1
->ifindex
< next2
->ifindex
)
830 if (next1
->ifindex
> next2
->ifindex
)
833 case NEXTHOP_TYPE_BLACKHOLE
:
834 if (next1
->bh_type
< next2
->bh_type
)
837 if (next1
->bh_type
> next2
->bh_type
)
845 static int zapi_nexthop_cmp(const void *item1
, const void *item2
)
849 const struct zapi_nexthop
*next1
= item1
;
850 const struct zapi_nexthop
*next2
= item2
;
852 ret
= zapi_nexthop_cmp_no_labels(next1
, next2
);
856 ret
= zapi_nexthop_labels_cmp(next1
, next2
);
861 static void zapi_nexthop_group_sort(struct zapi_nexthop
*nh_grp
,
862 uint16_t nexthop_num
)
864 qsort(nh_grp
, nexthop_num
, sizeof(struct zapi_nexthop
),
869 * Encode a single zapi nexthop
871 int zapi_nexthop_encode(struct stream
*s
, const struct zapi_nexthop
*api_nh
,
875 int nh_flags
= api_nh
->flags
;
877 stream_putl(s
, api_nh
->vrf_id
);
878 stream_putc(s
, api_nh
->type
);
880 /* If needed, set 'labelled nexthop' flag */
881 if (api_nh
->label_num
> 0) {
882 SET_FLAG(nh_flags
, ZAPI_NEXTHOP_FLAG_LABEL
);
884 /* Validate label count */
885 if (api_nh
->label_num
> MPLS_MAX_LABELS
) {
892 SET_FLAG(nh_flags
, ZAPI_NEXTHOP_FLAG_WEIGHT
);
894 /* Note that we're only encoding a single octet */
895 stream_putc(s
, nh_flags
);
897 switch (api_nh
->type
) {
898 case NEXTHOP_TYPE_BLACKHOLE
:
899 stream_putc(s
, api_nh
->bh_type
);
901 case NEXTHOP_TYPE_IPV4
:
902 stream_put_in_addr(s
, &api_nh
->gate
.ipv4
);
904 case NEXTHOP_TYPE_IPV4_IFINDEX
:
905 stream_put_in_addr(s
, &api_nh
->gate
.ipv4
);
906 stream_putl(s
, api_nh
->ifindex
);
908 case NEXTHOP_TYPE_IFINDEX
:
909 stream_putl(s
, api_nh
->ifindex
);
911 case NEXTHOP_TYPE_IPV6
:
912 stream_write(s
, (uint8_t *)&api_nh
->gate
.ipv6
,
915 case NEXTHOP_TYPE_IPV6_IFINDEX
:
916 stream_write(s
, (uint8_t *)&api_nh
->gate
.ipv6
,
918 stream_putl(s
, api_nh
->ifindex
);
922 /* We only encode labels if we have >0 - we use
923 * the per-nexthop flag above to signal that the count
924 * is present in the payload.
926 if (api_nh
->label_num
> 0) {
927 stream_putc(s
, api_nh
->label_num
);
928 stream_put(s
, &api_nh
->labels
[0],
929 api_nh
->label_num
* sizeof(mpls_label_t
));
933 stream_putl(s
, api_nh
->weight
);
935 /* Router MAC for EVPN routes. */
936 if (CHECK_FLAG(api_flags
, ZEBRA_FLAG_EVPN_ROUTE
))
937 stream_put(s
, &(api_nh
->rmac
),
938 sizeof(struct ethaddr
));
944 int zapi_route_encode(uint8_t cmd
, struct stream
*s
, struct zapi_route
*api
)
946 struct zapi_nexthop
*api_nh
;
951 zclient_create_header(s
, cmd
, api
->vrf_id
);
953 if (api
->type
>= ZEBRA_ROUTE_MAX
) {
954 flog_err(EC_LIB_ZAPI_ENCODE
,
955 "%s: Specified route type (%u) is not a legal value\n",
956 __PRETTY_FUNCTION__
, api
->type
);
959 stream_putc(s
, api
->type
);
961 stream_putw(s
, api
->instance
);
962 stream_putl(s
, api
->flags
);
963 stream_putc(s
, api
->message
);
965 if (api
->safi
< SAFI_UNICAST
|| api
->safi
>= SAFI_MAX
) {
966 flog_err(EC_LIB_ZAPI_ENCODE
,
967 "%s: Specified route SAFI (%u) is not a legal value\n",
968 __PRETTY_FUNCTION__
, api
->safi
);
971 stream_putc(s
, api
->safi
);
973 /* Put prefix information. */
974 stream_putc(s
, api
->prefix
.family
);
975 psize
= PSIZE(api
->prefix
.prefixlen
);
976 stream_putc(s
, api
->prefix
.prefixlen
);
977 stream_write(s
, (uint8_t *)&api
->prefix
.u
.prefix
, psize
);
979 if (CHECK_FLAG(api
->message
, ZAPI_MESSAGE_SRCPFX
)) {
980 psize
= PSIZE(api
->src_prefix
.prefixlen
);
981 stream_putc(s
, api
->src_prefix
.prefixlen
);
982 stream_write(s
, (uint8_t *)&api
->src_prefix
.prefix
, psize
);
986 if (CHECK_FLAG(api
->message
, ZAPI_MESSAGE_NEXTHOP
)) {
987 /* limit the number of nexthops if necessary */
988 if (api
->nexthop_num
> MULTIPATH_NUM
) {
989 char buf
[PREFIX2STR_BUFFER
];
991 prefix2str(&api
->prefix
, buf
, sizeof(buf
));
994 "%s: prefix %s: can't encode %u nexthops (maximum is %u)",
995 __func__
, buf
, api
->nexthop_num
, MULTIPATH_NUM
);
999 zapi_nexthop_group_sort(api
->nexthops
, api
->nexthop_num
);
1001 stream_putw(s
, api
->nexthop_num
);
1003 for (i
= 0; i
< api
->nexthop_num
; i
++) {
1004 api_nh
= &api
->nexthops
[i
];
1006 /* MPLS labels for BGP-LU or Segment Routing */
1007 if (api_nh
->label_num
> MPLS_MAX_LABELS
) {
1008 char buf
[PREFIX2STR_BUFFER
];
1010 prefix2str(&api
->prefix
, buf
, sizeof(buf
));
1012 flog_err(EC_LIB_ZAPI_ENCODE
,
1013 "%s: prefix %s: can't encode %u labels (maximum is %u)",
1020 if (zapi_nexthop_encode(s
, api_nh
, api
->flags
) != 0)
1026 if (CHECK_FLAG(api
->message
, ZAPI_MESSAGE_DISTANCE
))
1027 stream_putc(s
, api
->distance
);
1028 if (CHECK_FLAG(api
->message
, ZAPI_MESSAGE_METRIC
))
1029 stream_putl(s
, api
->metric
);
1030 if (CHECK_FLAG(api
->message
, ZAPI_MESSAGE_TAG
))
1031 stream_putl(s
, api
->tag
);
1032 if (CHECK_FLAG(api
->message
, ZAPI_MESSAGE_MTU
))
1033 stream_putl(s
, api
->mtu
);
1034 if (CHECK_FLAG(api
->message
, ZAPI_MESSAGE_TABLEID
))
1035 stream_putl(s
, api
->tableid
);
1037 /* Put length at the first point of the stream. */
1038 stream_putw_at(s
, 0, stream_get_endp(s
));
1044 * Decode a single zapi nexthop object
1046 static int zapi_nexthop_decode(struct stream
*s
, struct zapi_nexthop
*api_nh
,
1051 STREAM_GETL(s
, api_nh
->vrf_id
);
1052 STREAM_GETC(s
, api_nh
->type
);
1054 /* Note that we're only using a single octet of flags */
1055 STREAM_GETC(s
, api_nh
->flags
);
1057 switch (api_nh
->type
) {
1058 case NEXTHOP_TYPE_BLACKHOLE
:
1059 STREAM_GETC(s
, api_nh
->bh_type
);
1061 case NEXTHOP_TYPE_IPV4
:
1062 STREAM_GET(&api_nh
->gate
.ipv4
.s_addr
, s
,
1065 case NEXTHOP_TYPE_IPV4_IFINDEX
:
1066 STREAM_GET(&api_nh
->gate
.ipv4
.s_addr
, s
,
1068 STREAM_GETL(s
, api_nh
->ifindex
);
1070 case NEXTHOP_TYPE_IFINDEX
:
1071 STREAM_GETL(s
, api_nh
->ifindex
);
1073 case NEXTHOP_TYPE_IPV6
:
1074 STREAM_GET(&api_nh
->gate
.ipv6
, s
, 16);
1076 case NEXTHOP_TYPE_IPV6_IFINDEX
:
1077 STREAM_GET(&api_nh
->gate
.ipv6
, s
, 16);
1078 STREAM_GETL(s
, api_nh
->ifindex
);
1082 /* MPLS labels for BGP-LU or Segment Routing */
1083 if (CHECK_FLAG(api_nh
->flags
, ZAPI_NEXTHOP_FLAG_LABEL
)) {
1084 STREAM_GETC(s
, api_nh
->label_num
);
1085 if (api_nh
->label_num
> MPLS_MAX_LABELS
) {
1088 "%s: invalid number of MPLS labels (%u)",
1089 __func__
, api_nh
->label_num
);
1093 STREAM_GET(&api_nh
->labels
[0], s
,
1094 api_nh
->label_num
* sizeof(mpls_label_t
));
1097 if (CHECK_FLAG(api_nh
->flags
, ZAPI_NEXTHOP_FLAG_WEIGHT
))
1098 STREAM_GETL(s
, api_nh
->weight
);
1100 /* Router MAC for EVPN routes. */
1101 if (CHECK_FLAG(api_flags
, ZEBRA_FLAG_EVPN_ROUTE
))
1102 STREAM_GET(&(api_nh
->rmac
), s
,
1103 sizeof(struct ethaddr
));
1113 int zapi_route_decode(struct stream
*s
, struct zapi_route
*api
)
1115 struct zapi_nexthop
*api_nh
;
1118 memset(api
, 0, sizeof(*api
));
1120 /* Type, flags, message. */
1121 STREAM_GETC(s
, api
->type
);
1122 if (api
->type
>= ZEBRA_ROUTE_MAX
) {
1123 flog_err(EC_LIB_ZAPI_ENCODE
,
1124 "%s: Specified route type: %d is not a legal value\n",
1125 __PRETTY_FUNCTION__
, api
->type
);
1129 STREAM_GETW(s
, api
->instance
);
1130 STREAM_GETL(s
, api
->flags
);
1131 STREAM_GETC(s
, api
->message
);
1132 STREAM_GETC(s
, api
->safi
);
1133 if (api
->safi
< SAFI_UNICAST
|| api
->safi
>= SAFI_MAX
) {
1134 flog_err(EC_LIB_ZAPI_ENCODE
,
1135 "%s: Specified route SAFI (%u) is not a legal value\n",
1136 __PRETTY_FUNCTION__
, api
->safi
);
1141 STREAM_GETC(s
, api
->prefix
.family
);
1142 STREAM_GETC(s
, api
->prefix
.prefixlen
);
1143 switch (api
->prefix
.family
) {
1145 if (api
->prefix
.prefixlen
> IPV4_MAX_PREFIXLEN
) {
1148 "%s: V4 prefixlen is %d which should not be more than 32",
1149 __PRETTY_FUNCTION__
, api
->prefix
.prefixlen
);
1154 if (api
->prefix
.prefixlen
> IPV6_MAX_PREFIXLEN
) {
1157 "%s: v6 prefixlen is %d which should not be more than 128",
1158 __PRETTY_FUNCTION__
, api
->prefix
.prefixlen
);
1163 flog_err(EC_LIB_ZAPI_ENCODE
,
1164 "%s: Specified family %d is not v4 or v6",
1165 __PRETTY_FUNCTION__
, api
->prefix
.family
);
1168 STREAM_GET(&api
->prefix
.u
.prefix
, s
, PSIZE(api
->prefix
.prefixlen
));
1170 if (CHECK_FLAG(api
->message
, ZAPI_MESSAGE_SRCPFX
)) {
1171 api
->src_prefix
.family
= AF_INET6
;
1172 STREAM_GETC(s
, api
->src_prefix
.prefixlen
);
1173 if (api
->src_prefix
.prefixlen
> IPV6_MAX_PREFIXLEN
) {
1176 "%s: SRC Prefix prefixlen received: %d is too large",
1177 __PRETTY_FUNCTION__
, api
->src_prefix
.prefixlen
);
1180 STREAM_GET(&api
->src_prefix
.prefix
, s
,
1181 PSIZE(api
->src_prefix
.prefixlen
));
1183 if (api
->prefix
.family
!= AF_INET6
1184 || api
->src_prefix
.prefixlen
== 0) {
1187 "%s: SRC prefix specified in some manner that makes no sense",
1188 __PRETTY_FUNCTION__
);
1194 if (CHECK_FLAG(api
->message
, ZAPI_MESSAGE_NEXTHOP
)) {
1195 STREAM_GETW(s
, api
->nexthop_num
);
1196 if (api
->nexthop_num
> MULTIPATH_NUM
) {
1197 flog_err(EC_LIB_ZAPI_ENCODE
,
1198 "%s: invalid number of nexthops (%u)",
1199 __func__
, api
->nexthop_num
);
1203 for (i
= 0; i
< api
->nexthop_num
; i
++) {
1204 api_nh
= &api
->nexthops
[i
];
1206 if (zapi_nexthop_decode(s
, api_nh
, api
->flags
) != 0)
1212 if (CHECK_FLAG(api
->message
, ZAPI_MESSAGE_DISTANCE
))
1213 STREAM_GETC(s
, api
->distance
);
1214 if (CHECK_FLAG(api
->message
, ZAPI_MESSAGE_METRIC
))
1215 STREAM_GETL(s
, api
->metric
);
1216 if (CHECK_FLAG(api
->message
, ZAPI_MESSAGE_TAG
))
1217 STREAM_GETL(s
, api
->tag
);
1218 if (CHECK_FLAG(api
->message
, ZAPI_MESSAGE_MTU
))
1219 STREAM_GETL(s
, api
->mtu
);
1220 if (CHECK_FLAG(api
->message
, ZAPI_MESSAGE_TABLEID
))
1221 STREAM_GETL(s
, api
->tableid
);
1228 static void zapi_encode_prefix(struct stream
*s
, struct prefix
*p
,
1234 memset(&any
, 0, sizeof(any
));
1235 any
.family
= family
;
1239 stream_putc(s
, p
->family
);
1240 stream_putc(s
, p
->prefixlen
);
1241 stream_put(s
, &p
->u
.prefix
, prefix_blen(p
));
1244 int zapi_pbr_rule_encode(uint8_t cmd
, struct stream
*s
, struct pbr_rule
*zrule
)
1247 zclient_create_header(s
, cmd
, zrule
->vrf_id
);
1250 * We are sending one item at a time at the moment
1254 stream_putl(s
, zrule
->seq
);
1255 stream_putl(s
, zrule
->priority
);
1256 stream_putl(s
, zrule
->unique
);
1258 zapi_encode_prefix(s
, &(zrule
->filter
.src_ip
),
1259 zrule
->filter
.src_ip
.family
);
1260 stream_putw(s
, zrule
->filter
.src_port
); /* src port */
1261 zapi_encode_prefix(s
, &(zrule
->filter
.dst_ip
),
1262 zrule
->filter
.src_ip
.family
);
1263 stream_putw(s
, zrule
->filter
.dst_port
); /* dst port */
1264 stream_putw(s
, zrule
->filter
.fwmark
); /* fwmark */
1266 stream_putl(s
, zrule
->action
.table
);
1267 stream_putl(s
, zrule
->ifindex
);
1269 /* Put length at the first point of the stream. */
1270 stream_putw_at(s
, 0, stream_get_endp(s
));
1275 bool zapi_route_notify_decode(struct stream
*s
, struct prefix
*p
,
1277 enum zapi_route_notify_owner
*note
)
1281 STREAM_GET(note
, s
, sizeof(*note
));
1283 STREAM_GETC(s
, p
->family
);
1284 STREAM_GETC(s
, p
->prefixlen
);
1285 STREAM_GET(&p
->u
.prefix
, s
, prefix_blen(p
));
1296 bool zapi_rule_notify_decode(struct stream
*s
, uint32_t *seqno
,
1297 uint32_t *priority
, uint32_t *unique
,
1299 enum zapi_rule_notify_owner
*note
)
1301 uint32_t prio
, seq
, uni
;
1304 STREAM_GET(note
, s
, sizeof(*note
));
1306 STREAM_GETL(s
, seq
);
1307 STREAM_GETL(s
, prio
);
1308 STREAM_GETL(s
, uni
);
1309 STREAM_GETL(s
, ifi
);
1312 zlog_debug("%s: %u %u %u %u", __PRETTY_FUNCTION__
, seq
, prio
,
1325 bool zapi_ipset_notify_decode(struct stream
*s
, uint32_t *unique
,
1326 enum zapi_ipset_notify_owner
*note
)
1330 STREAM_GET(note
, s
, sizeof(*note
));
1332 STREAM_GETL(s
, uni
);
1335 zlog_debug("%s: %u", __PRETTY_FUNCTION__
, uni
);
1344 bool zapi_ipset_entry_notify_decode(struct stream
*s
, uint32_t *unique
,
1346 enum zapi_ipset_entry_notify_owner
*note
)
1350 STREAM_GET(note
, s
, sizeof(*note
));
1352 STREAM_GETL(s
, uni
);
1354 STREAM_GET(ipset_name
, s
, ZEBRA_IPSET_NAME_SIZE
);
1357 zlog_debug("%s: %u", __PRETTY_FUNCTION__
, uni
);
1366 bool zapi_iptable_notify_decode(struct stream
*s
,
1368 enum zapi_iptable_notify_owner
*note
)
1372 STREAM_GET(note
, s
, sizeof(*note
));
1374 STREAM_GETL(s
, uni
);
1377 zlog_debug("%s: %u", __PRETTY_FUNCTION__
, uni
);
1386 struct nexthop
*nexthop_from_zapi_nexthop(struct zapi_nexthop
*znh
)
1388 struct nexthop
*n
= nexthop_new();
1390 n
->type
= znh
->type
;
1391 n
->vrf_id
= znh
->vrf_id
;
1392 n
->ifindex
= znh
->ifindex
;
1393 n
->gate
= znh
->gate
;
1396 * This function currently handles labels
1398 if (znh
->label_num
) {
1399 nexthop_add_labels(n
, ZEBRA_LSP_NONE
, znh
->label_num
,
1407 * Convert nexthop to zapi nexthop
1409 int zapi_nexthop_from_nexthop(struct zapi_nexthop
*znh
,
1410 const struct nexthop
*nh
)
1414 memset(znh
, 0, sizeof(*znh
));
1416 znh
->type
= nh
->type
;
1417 znh
->vrf_id
= nh
->vrf_id
;
1418 znh
->ifindex
= nh
->ifindex
;
1419 znh
->gate
= nh
->gate
;
1421 if (nh
->nh_label
&& (nh
->nh_label
->num_labels
> 0)) {
1422 for (i
= 0; i
< nh
->nh_label
->num_labels
; i
++)
1423 znh
->labels
[i
] = nh
->nh_label
->label
[i
];
1426 SET_FLAG(znh
->flags
, ZAPI_NEXTHOP_FLAG_LABEL
);
1433 * Decode the nexthop-tracking update message
1435 bool zapi_nexthop_update_decode(struct stream
*s
, struct zapi_route
*nhr
)
1439 memset(nhr
, 0, sizeof(*nhr
));
1441 STREAM_GETW(s
, nhr
->prefix
.family
);
1442 STREAM_GETC(s
, nhr
->prefix
.prefixlen
);
1443 switch (nhr
->prefix
.family
) {
1445 STREAM_GET(&nhr
->prefix
.u
.prefix4
.s_addr
, s
, IPV4_MAX_BYTELEN
);
1448 STREAM_GET(&nhr
->prefix
.u
.prefix6
, s
, IPV6_MAX_BYTELEN
);
1454 STREAM_GETC(s
, nhr
->type
);
1455 STREAM_GETW(s
, nhr
->instance
);
1456 STREAM_GETC(s
, nhr
->distance
);
1457 STREAM_GETL(s
, nhr
->metric
);
1458 STREAM_GETC(s
, nhr
->nexthop_num
);
1460 for (i
= 0; i
< nhr
->nexthop_num
; i
++) {
1461 if (zapi_nexthop_decode(s
, &(nhr
->nexthops
[i
]), 0) != 0)
1471 * send a ZEBRA_REDISTRIBUTE_ADD or ZEBRA_REDISTRIBUTE_DELETE
1472 * for the route type (ZEBRA_ROUTE_KERNEL etc.). The zebra server will
1473 * then set/unset redist[type] in the client handle (a struct zserv) for the
1476 int zebra_redistribute_send(int command
, struct zclient
*zclient
, afi_t afi
,
1477 int type
, unsigned short instance
, vrf_id_t vrf_id
)
1484 zclient_create_header(s
, command
, vrf_id
);
1485 stream_putc(s
, afi
);
1486 stream_putc(s
, type
);
1487 stream_putw(s
, instance
);
1489 stream_putw_at(s
, 0, stream_get_endp(s
));
1491 return zclient_send_message(zclient
);
1494 int zebra_redistribute_default_send(int command
, struct zclient
*zclient
,
1495 afi_t afi
, vrf_id_t vrf_id
)
1502 zclient_create_header(s
, command
, vrf_id
);
1503 stream_putc(s
, afi
);
1505 stream_putw_at(s
, 0, stream_get_endp(s
));
1507 return zclient_send_message(zclient
);
1510 /* Get prefix in ZServ format; family should be filled in on prefix */
1511 static void zclient_stream_get_prefix(struct stream
*s
, struct prefix
*p
)
1513 size_t plen
= prefix_blen(p
);
1520 stream_get(&p
->u
.prefix
, s
, plen
);
1522 p
->prefixlen
= MIN(plen
* 8, c
);
1528 /* Router-id update from zebra daemon. */
1529 void zebra_router_id_update_read(struct stream
*s
, struct prefix
*rid
)
1531 /* Fetch interface address. */
1532 STREAM_GETC(s
, rid
->family
);
1534 zclient_stream_get_prefix(s
, rid
);
1540 /* Interface addition from zebra daemon. */
1542 * The format of the message sent with type ZEBRA_INTERFACE_ADD or
1543 * ZEBRA_INTERFACE_DELETE from zebra to the client is:
1545 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1546 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1552 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1554 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1556 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1559 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1561 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1563 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1565 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1567 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1569 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1570 * | parent ifindex |
1571 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1572 * | Link Layer Type |
1573 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1574 * | Harware Address Length |
1575 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1576 * | Hardware Address if HW lenght different from 0 |
1577 * | ... max INTERFACE_HWADDR_MAX |
1578 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1579 * | Link_params? | Whether a link-params follows: 1 or 0.
1580 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1581 * | Link_params 0 or 1 INTERFACE_LINK_PARAMS_SIZE sized |
1582 * | .... (struct if_link_params). |
1583 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1586 static void zclient_vrf_add(struct zclient
*zclient
, vrf_id_t vrf_id
)
1589 char vrfname_tmp
[VRF_NAMSIZ
];
1590 struct vrf_data data
;
1592 stream_get(&data
, zclient
->ibuf
, sizeof(struct vrf_data
));
1593 /* Read interface name. */
1594 stream_get(vrfname_tmp
, zclient
->ibuf
, VRF_NAMSIZ
);
1596 /* Lookup/create vrf by vrf_id. */
1597 vrf
= vrf_get(vrf_id
, vrfname_tmp
);
1598 vrf
->data
.l
.table_id
= data
.l
.table_id
;
1599 memcpy(vrf
->data
.l
.netns_name
, data
.l
.netns_name
, NS_NAMSIZ
);
1600 /* overwrite default vrf */
1601 if (vrf_id
== VRF_DEFAULT
)
1602 vrf_set_default_name(vrfname_tmp
, false);
1606 static void zclient_vrf_delete(struct zclient
*zclient
, vrf_id_t vrf_id
)
1610 /* Lookup vrf by vrf_id. */
1611 vrf
= vrf_lookup_by_id(vrf_id
);
1614 * If a routing protocol doesn't know about a
1615 * vrf that is about to be deleted. There is
1616 * no point in attempting to delete it.
1624 static void zclient_interface_add(struct zclient
*zclient
, vrf_id_t vrf_id
)
1626 struct interface
*ifp
;
1627 char ifname_tmp
[INTERFACE_NAMSIZ
];
1628 struct stream
*s
= zclient
->ibuf
;
1630 /* Read interface name. */
1631 stream_get(ifname_tmp
, s
, INTERFACE_NAMSIZ
);
1633 /* Lookup/create interface by name. */
1634 ifp
= if_get_by_name(ifname_tmp
, vrf_id
);
1636 zebra_interface_if_set_value(s
, ifp
);
1638 if_new_via_zapi(ifp
);
1642 * Read interface up/down msg (ZEBRA_INTERFACE_UP/ZEBRA_INTERFACE_DOWN)
1643 * from zebra server. The format of this message is the same as
1644 * that sent for ZEBRA_INTERFACE_ADD/ZEBRA_INTERFACE_DELETE,
1645 * except that no sockaddr_dl is sent at the tail of the message.
1647 struct interface
*zebra_interface_state_read(struct stream
*s
, vrf_id_t vrf_id
)
1649 struct interface
*ifp
;
1650 char ifname_tmp
[INTERFACE_NAMSIZ
];
1652 /* Read interface name. */
1653 stream_get(ifname_tmp
, s
, INTERFACE_NAMSIZ
);
1655 /* Lookup this by interface index. */
1656 ifp
= if_lookup_by_name(ifname_tmp
, vrf_id
);
1658 flog_err(EC_LIB_ZAPI_ENCODE
,
1659 "INTERFACE_STATE: Cannot find IF %s in VRF %d",
1660 ifname_tmp
, vrf_id
);
1664 zebra_interface_if_set_value(s
, ifp
);
1669 static void zclient_interface_delete(struct zclient
*zclient
, vrf_id_t vrf_id
)
1671 struct interface
*ifp
;
1672 struct stream
*s
= zclient
->ibuf
;
1674 ifp
= zebra_interface_state_read(s
, vrf_id
);
1679 if_destroy_via_zapi(ifp
);
1683 static void zclient_interface_up(struct zclient
*zclient
, vrf_id_t vrf_id
)
1685 struct interface
*ifp
;
1686 struct stream
*s
= zclient
->ibuf
;
1688 ifp
= zebra_interface_state_read(s
, vrf_id
);
1693 if_up_via_zapi(ifp
);
1696 static void zclient_interface_down(struct zclient
*zclient
, vrf_id_t vrf_id
)
1698 struct interface
*ifp
;
1699 struct stream
*s
= zclient
->ibuf
;
1701 ifp
= zebra_interface_state_read(s
, vrf_id
);
1706 if_down_via_zapi(ifp
);
1709 static void link_params_set_value(struct stream
*s
, struct if_link_params
*iflp
)
1715 iflp
->lp_status
= stream_getl(s
);
1716 iflp
->te_metric
= stream_getl(s
);
1717 iflp
->max_bw
= stream_getf(s
);
1718 iflp
->max_rsv_bw
= stream_getf(s
);
1719 uint32_t bwclassnum
= stream_getl(s
);
1722 for (i
= 0; i
< bwclassnum
&& i
< MAX_CLASS_TYPE
; i
++)
1723 iflp
->unrsv_bw
[i
] = stream_getf(s
);
1726 EC_LIB_ZAPI_MISSMATCH
,
1727 "%s: received %d > %d (MAX_CLASS_TYPE) bw entries"
1728 " - outdated library?",
1729 __func__
, bwclassnum
, MAX_CLASS_TYPE
);
1731 iflp
->admin_grp
= stream_getl(s
);
1732 iflp
->rmt_as
= stream_getl(s
);
1733 iflp
->rmt_ip
.s_addr
= stream_get_ipv4(s
);
1735 iflp
->av_delay
= stream_getl(s
);
1736 iflp
->min_delay
= stream_getl(s
);
1737 iflp
->max_delay
= stream_getl(s
);
1738 iflp
->delay_var
= stream_getl(s
);
1740 iflp
->pkt_loss
= stream_getf(s
);
1741 iflp
->res_bw
= stream_getf(s
);
1742 iflp
->ava_bw
= stream_getf(s
);
1743 iflp
->use_bw
= stream_getf(s
);
1746 struct interface
*zebra_interface_link_params_read(struct stream
*s
,
1749 struct if_link_params
*iflp
;
1754 ifindex
= stream_getl(s
);
1756 struct interface
*ifp
= if_lookup_by_index(ifindex
, vrf_id
);
1759 flog_err(EC_LIB_ZAPI_ENCODE
,
1760 "%s: unknown ifindex %u, shouldn't happen", __func__
,
1765 if ((iflp
= if_link_params_get(ifp
)) == NULL
)
1768 link_params_set_value(s
, iflp
);
1773 static void zebra_interface_if_set_value(struct stream
*s
,
1774 struct interface
*ifp
)
1776 uint8_t link_params_status
= 0;
1777 ifindex_t old_ifindex
;
1779 old_ifindex
= ifp
->ifindex
;
1780 /* Read interface's index. */
1781 if_set_index(ifp
, stream_getl(s
));
1782 ifp
->status
= stream_getc(s
);
1784 /* Read interface's value. */
1785 ifp
->flags
= stream_getq(s
);
1786 ifp
->ptm_enable
= stream_getc(s
);
1787 ifp
->ptm_status
= stream_getc(s
);
1788 ifp
->metric
= stream_getl(s
);
1789 ifp
->speed
= stream_getl(s
);
1790 ifp
->mtu
= stream_getl(s
);
1791 ifp
->mtu6
= stream_getl(s
);
1792 ifp
->bandwidth
= stream_getl(s
);
1793 ifp
->link_ifindex
= stream_getl(s
);
1794 ifp
->ll_type
= stream_getl(s
);
1795 ifp
->hw_addr_len
= stream_getl(s
);
1796 if (ifp
->hw_addr_len
)
1797 stream_get(ifp
->hw_addr
, s
,
1798 MIN(ifp
->hw_addr_len
, INTERFACE_HWADDR_MAX
));
1800 /* Read Traffic Engineering status */
1801 link_params_status
= stream_getc(s
);
1802 /* Then, Traffic Engineering parameters if any */
1803 if (link_params_status
) {
1804 struct if_link_params
*iflp
= if_link_params_get(ifp
);
1805 link_params_set_value(s
, iflp
);
1808 nexthop_group_interface_state_change(ifp
, old_ifindex
);
1811 size_t zebra_interface_link_params_write(struct stream
*s
,
1812 struct interface
*ifp
)
1815 struct if_link_params
*iflp
;
1818 if (s
== NULL
|| ifp
== NULL
|| ifp
->link_params
== NULL
)
1821 iflp
= ifp
->link_params
;
1824 w
+= stream_putl(s
, iflp
->lp_status
);
1826 w
+= stream_putl(s
, iflp
->te_metric
);
1827 w
+= stream_putf(s
, iflp
->max_bw
);
1828 w
+= stream_putf(s
, iflp
->max_rsv_bw
);
1830 w
+= stream_putl(s
, MAX_CLASS_TYPE
);
1831 for (i
= 0; i
< MAX_CLASS_TYPE
; i
++)
1832 w
+= stream_putf(s
, iflp
->unrsv_bw
[i
]);
1834 w
+= stream_putl(s
, iflp
->admin_grp
);
1835 w
+= stream_putl(s
, iflp
->rmt_as
);
1836 w
+= stream_put_in_addr(s
, &iflp
->rmt_ip
);
1838 w
+= stream_putl(s
, iflp
->av_delay
);
1839 w
+= stream_putl(s
, iflp
->min_delay
);
1840 w
+= stream_putl(s
, iflp
->max_delay
);
1841 w
+= stream_putl(s
, iflp
->delay_var
);
1843 w
+= stream_putf(s
, iflp
->pkt_loss
);
1844 w
+= stream_putf(s
, iflp
->res_bw
);
1845 w
+= stream_putf(s
, iflp
->ava_bw
);
1846 w
+= stream_putf(s
, iflp
->use_bw
);
1852 * format of message for address additon is:
1856 * | type | ZEBRA_INTERFACE_ADDRESS_ADD or
1857 * +-+-+-+-+-+-+-+-+ ZEBRA_INTERFACE_ADDRES_DELETE
1866 * | ifc_flags | flags for connected address
1874 * | addr_len | len of addr. E.g., addr_len = 4 for ipv4 addrs.
1882 static int memconstant(const void *s
, int c
, size_t n
)
1884 const uint8_t *p
= s
;
1893 struct connected
*zebra_interface_address_read(int type
, struct stream
*s
,
1897 struct interface
*ifp
;
1898 struct connected
*ifc
;
1899 struct prefix p
, d
, *dp
;
1903 memset(&p
, 0, sizeof(p
));
1904 memset(&d
, 0, sizeof(d
));
1906 /* Get interface index. */
1907 ifindex
= stream_getl(s
);
1910 ifp
= if_lookup_by_index(ifindex
, vrf_id
);
1912 flog_err(EC_LIB_ZAPI_ENCODE
,
1913 "INTERFACE_ADDRESS_%s: Cannot find IF %u in VRF %d",
1914 (type
== ZEBRA_INTERFACE_ADDRESS_ADD
) ? "ADD" : "DEL",
1920 ifc_flags
= stream_getc(s
);
1922 /* Fetch interface address. */
1923 d
.family
= p
.family
= stream_getc(s
);
1924 plen
= prefix_blen(&d
);
1926 zclient_stream_get_prefix(s
, &p
);
1928 /* Fetch destination address. */
1929 stream_get(&d
.u
.prefix
, s
, plen
);
1931 /* N.B. NULL destination pointers are encoded as all zeroes */
1932 dp
= memconstant(&d
.u
.prefix
, 0, plen
) ? NULL
: &d
;
1934 if (type
== ZEBRA_INTERFACE_ADDRESS_ADD
) {
1935 ifc
= connected_lookup_prefix_exact(ifp
, &p
);
1937 /* N.B. NULL destination pointers are encoded as all
1939 ifc
= connected_add_by_prefix(ifp
, &p
, dp
);
1942 ifc
->flags
= ifc_flags
;
1943 if (ifc
->destination
)
1944 ifc
->destination
->prefixlen
=
1945 ifc
->address
->prefixlen
;
1946 else if (CHECK_FLAG(ifc
->flags
, ZEBRA_IFA_PEER
)) {
1947 /* carp interfaces on OpenBSD with 0.0.0.0/0 as
1949 char buf
[PREFIX_STRLEN
];
1952 "warning: interface %s address %s with peer flag set, but no peer address!",
1954 prefix2str(ifc
->address
, buf
,
1956 UNSET_FLAG(ifc
->flags
, ZEBRA_IFA_PEER
);
1960 assert(type
== ZEBRA_INTERFACE_ADDRESS_DELETE
);
1961 ifc
= connected_delete_by_prefix(ifp
, &p
);
1968 * format of message for neighbor connected address is:
1972 * | type | ZEBRA_INTERFACE_NBR_ADDRESS_ADD or
1973 * +-+-+-+-+-+-+-+-+ ZEBRA_INTERFACE_NBR_ADDRES_DELETE
1988 * | addr_len | len of addr.
1991 struct nbr_connected
*
1992 zebra_interface_nbr_address_read(int type
, struct stream
*s
, vrf_id_t vrf_id
)
1994 unsigned int ifindex
;
1995 struct interface
*ifp
;
1997 struct nbr_connected
*ifc
;
1999 /* Get interface index. */
2000 ifindex
= stream_getl(s
);
2003 ifp
= if_lookup_by_index(ifindex
, vrf_id
);
2005 flog_err(EC_LIB_ZAPI_ENCODE
,
2006 "INTERFACE_NBR_%s: Cannot find IF %u in VRF %d",
2007 (type
== ZEBRA_INTERFACE_NBR_ADDRESS_ADD
) ? "ADD"
2013 p
.family
= stream_getc(s
);
2014 stream_get(&p
.u
.prefix
, s
, prefix_blen(&p
));
2015 p
.prefixlen
= stream_getc(s
);
2017 if (type
== ZEBRA_INTERFACE_NBR_ADDRESS_ADD
) {
2018 /* Currently only supporting P2P links, so any new RA source
2020 considered as the replacement of the previously learnt
2021 Link-Local address. */
2022 if (!(ifc
= listnode_head(ifp
->nbr_connected
))) {
2023 ifc
= nbr_connected_new();
2024 ifc
->address
= prefix_new();
2026 listnode_add(ifp
->nbr_connected
, ifc
);
2029 prefix_copy(ifc
->address
, &p
);
2031 assert(type
== ZEBRA_INTERFACE_NBR_ADDRESS_DELETE
);
2033 ifc
= nbr_connected_check(ifp
, &p
);
2035 listnode_delete(ifp
->nbr_connected
, ifc
);
2041 struct interface
*zebra_interface_vrf_update_read(struct stream
*s
,
2043 vrf_id_t
*new_vrf_id
)
2045 char ifname
[INTERFACE_NAMSIZ
];
2046 struct interface
*ifp
;
2049 /* Read interface name. */
2050 stream_get(ifname
, s
, INTERFACE_NAMSIZ
);
2052 /* Lookup interface. */
2053 ifp
= if_lookup_by_name(ifname
, vrf_id
);
2055 flog_err(EC_LIB_ZAPI_ENCODE
,
2056 "INTERFACE_VRF_UPDATE: Cannot find IF %s in VRF %d",
2061 /* Fetch new VRF Id. */
2062 new_id
= stream_getl(s
);
2064 *new_vrf_id
= new_id
;
2068 /* filter unwanted messages until the expected one arrives */
2069 static int zclient_read_sync_response(struct zclient
*zclient
,
2070 uint16_t expected_cmd
)
2082 cmd
= expected_cmd
+ 1;
2083 while (ret
== 0 && cmd
!= expected_cmd
) {
2087 /* wait until response arrives */
2089 FD_SET(zclient
->sock
, &readfds
);
2090 select(zclient
->sock
+ 1, &readfds
, NULL
, NULL
, NULL
);
2091 if (!FD_ISSET(zclient
->sock
, &readfds
))
2094 ret
= zclient_read_header(s
, zclient
->sock
, &size
, &marker
,
2095 &version
, &vrf_id
, &cmd
);
2097 zlog_debug("%s: Response (%d bytes) received", __func__
,
2101 flog_err(EC_LIB_ZAPI_ENCODE
, "%s: Invalid Sync Message Reply",
2109 * Connect to label manager in a syncronous way
2111 * It first writes the request to zcient output buffer and then
2112 * immediately reads the answer from the input buffer.
2114 * @param zclient Zclient used to connect to label manager (zebra)
2115 * @param async Synchronous (0) or asynchronous (1) operation
2116 * @result Result of response
2118 int lm_label_manager_connect(struct zclient
*zclient
, int async
)
2123 uint16_t cmd
= async
? ZEBRA_LABEL_MANAGER_CONNECT_ASYNC
:
2124 ZEBRA_LABEL_MANAGER_CONNECT
;
2127 zlog_debug("Connecting to Label Manager (LM)");
2129 if (zclient
->sock
< 0) {
2130 zlog_debug("%s: invalid zclient socket", __func__
);
2137 zclient_create_header(s
, cmd
, VRF_DEFAULT
);
2140 stream_putc(s
, zclient
->redist_default
);
2142 stream_putw(s
, zclient
->instance
);
2144 /* Put length at the first point of the stream. */
2145 stream_putw_at(s
, 0, stream_get_endp(s
));
2147 ret
= writen(zclient
->sock
, s
->data
, stream_get_endp(s
));
2149 flog_err(EC_LIB_ZAPI_SOCKET
, "Can't write to zclient sock");
2150 close(zclient
->sock
);
2155 flog_err(EC_LIB_ZAPI_SOCKET
, "Zclient sock closed");
2156 close(zclient
->sock
);
2161 zlog_debug("LM connect request sent (%d bytes)", ret
);
2167 if (zclient_read_sync_response(zclient
, cmd
)
2173 /* read instance and proto */
2174 uint8_t proto
= stream_getc(s
);
2175 uint16_t instance
= stream_getw(s
);
2178 if (proto
!= zclient
->redist_default
)
2181 "Wrong proto (%u) in LM connect response. Should be %u",
2182 proto
, zclient
->redist_default
);
2183 if (instance
!= zclient
->instance
)
2186 "Wrong instId (%u) in LM connect response. Should be %u",
2187 instance
, zclient
->instance
);
2190 result
= stream_getc(s
);
2192 zlog_debug("LM connect-response received, result %u", result
);
2198 * Asynchronous label chunk request
2200 * @param zclient Zclient used to connect to label manager (zebra)
2201 * @param keep Avoid garbage collection
2202 * @param chunk_size Amount of labels requested
2203 * @param base Base for the label chunk. if MPLS_LABEL_BASE_ANY we do not care
2204 * @result 0 on success, -1 otherwise
2206 int zclient_send_get_label_chunk(struct zclient
*zclient
, uint8_t keep
,
2207 uint32_t chunk_size
, uint32_t base
)
2212 zlog_debug("Getting Label Chunk");
2214 if (zclient
->sock
< 0)
2220 zclient_create_header(s
, ZEBRA_GET_LABEL_CHUNK
, VRF_DEFAULT
);
2222 stream_putc(s
, zclient
->redist_default
);
2224 stream_putw(s
, zclient
->instance
);
2225 stream_putc(s
, keep
);
2226 stream_putl(s
, chunk_size
);
2227 stream_putl(s
, base
);
2229 /* Put length at the first point of the stream. */
2230 stream_putw_at(s
, 0, stream_get_endp(s
));
2232 return zclient_send_message(zclient
);
2236 * Function to request a label chunk in a syncronous way
2238 * It first writes the request to zlcient output buffer and then
2239 * immediately reads the answer from the input buffer.
2241 * @param zclient Zclient used to connect to label manager (zebra)
2242 * @param keep Avoid garbage collection
2243 * @param chunk_size Amount of labels requested
2244 * @param start To write first assigned chunk label to
2245 * @param end To write last assigned chunk label to
2246 * @result 0 on success, -1 otherwise
2248 int lm_get_label_chunk(struct zclient
*zclient
, uint8_t keep
, uint32_t base
,
2249 uint32_t chunk_size
, uint32_t *start
, uint32_t *end
)
2253 uint8_t response_keep
;
2256 zlog_debug("Getting Label Chunk");
2258 if (zclient
->sock
< 0)
2264 zclient_create_header(s
, ZEBRA_GET_LABEL_CHUNK
, VRF_DEFAULT
);
2266 stream_putc(s
, zclient
->redist_default
);
2268 stream_putw(s
, zclient
->instance
);
2270 stream_putc(s
, keep
);
2272 stream_putl(s
, chunk_size
);
2273 /* requested chunk base */
2274 stream_putl(s
, base
);
2275 /* Put length at the first point of the stream. */
2276 stream_putw_at(s
, 0, stream_get_endp(s
));
2278 ret
= writen(zclient
->sock
, s
->data
, stream_get_endp(s
));
2280 flog_err(EC_LIB_ZAPI_SOCKET
, "Can't write to zclient sock");
2281 close(zclient
->sock
);
2286 flog_err(EC_LIB_ZAPI_SOCKET
, "Zclient sock closed");
2287 close(zclient
->sock
);
2292 zlog_debug("Label chunk request (%d bytes) sent", ret
);
2295 if (zclient_read_sync_response(zclient
, ZEBRA_GET_LABEL_CHUNK
) != 0)
2298 /* parse response */
2301 /* read proto and instance */
2302 uint8_t proto
= stream_getc(s
);
2303 uint16_t instance
= stream_getw(s
);
2306 if (proto
!= zclient
->redist_default
)
2307 flog_err(EC_LIB_ZAPI_ENCODE
,
2308 "Wrong proto (%u) in get chunk response. Should be %u",
2309 proto
, zclient
->redist_default
);
2310 if (instance
!= zclient
->instance
)
2311 flog_err(EC_LIB_ZAPI_ENCODE
,
2312 "Wrong instId (%u) in get chunk response Should be %u",
2313 instance
, zclient
->instance
);
2315 /* if we requested a specific chunk and it could not be allocated, the
2316 * response message will end here
2318 if (!STREAM_READABLE(s
)) {
2319 zlog_info("Unable to assign Label Chunk to %s instance %u",
2320 zebra_route_string(proto
), instance
);
2325 response_keep
= stream_getc(s
);
2326 /* start and end labels */
2327 *start
= stream_getl(s
);
2328 *end
= stream_getl(s
);
2330 /* not owning this response */
2331 if (keep
!= response_keep
) {
2334 "Invalid Label chunk: %u - %u, keeps mismatch %u != %u",
2335 *start
, *end
, keep
, response_keep
);
2338 if (*start
> *end
|| *start
< MPLS_LABEL_UNRESERVED_MIN
2339 || *end
> MPLS_LABEL_UNRESERVED_MAX
) {
2340 flog_err(EC_LIB_ZAPI_ENCODE
, "Invalid Label chunk: %u - %u",
2346 zlog_debug("Label Chunk assign: %u - %u (%u)", *start
, *end
,
2353 * Function to release a label chunk
2355 * @param zclient Zclient used to connect to label manager (zebra)
2356 * @param start First label of chunk
2357 * @param end Last label of chunk
2358 * @result 0 on success, -1 otherwise
2360 int lm_release_label_chunk(struct zclient
*zclient
, uint32_t start
,
2367 zlog_debug("Releasing Label Chunk %u - %u", start
, end
);
2369 if (zclient
->sock
< 0)
2375 zclient_create_header(s
, ZEBRA_RELEASE_LABEL_CHUNK
, VRF_DEFAULT
);
2378 stream_putc(s
, zclient
->redist_default
);
2380 stream_putw(s
, zclient
->instance
);
2382 stream_putl(s
, start
);
2384 stream_putl(s
, end
);
2386 /* Put length at the first point of the stream. */
2387 stream_putw_at(s
, 0, stream_get_endp(s
));
2389 ret
= writen(zclient
->sock
, s
->data
, stream_get_endp(s
));
2391 flog_err(EC_LIB_ZAPI_SOCKET
, "Can't write to zclient sock");
2392 close(zclient
->sock
);
2397 flog_err(EC_LIB_ZAPI_SOCKET
, "Zclient sock connection closed");
2398 close(zclient
->sock
);
2407 * Connect to table manager in a syncronous way
2409 * It first writes the request to zcient output buffer and then
2410 * immediately reads the answer from the input buffer.
2412 * @param zclient Zclient used to connect to table manager (zebra)
2413 * @result Result of response
2415 int tm_table_manager_connect(struct zclient
*zclient
)
2422 zlog_debug("Connecting to Table Manager");
2424 if (zclient
->sock
< 0)
2430 zclient_create_header(s
, ZEBRA_TABLE_MANAGER_CONNECT
, VRF_DEFAULT
);
2433 stream_putc(s
, zclient
->redist_default
);
2435 stream_putw(s
, zclient
->instance
);
2437 /* Put length at the first point of the stream. */
2438 stream_putw_at(s
, 0, stream_get_endp(s
));
2440 ret
= zclient_send_message(zclient
);
2445 zlog_debug("%s: Table manager connect request sent", __func__
);
2448 if (zclient_read_sync_response(zclient
, ZEBRA_TABLE_MANAGER_CONNECT
)
2454 STREAM_GETC(s
, result
);
2457 "%s: Table Manager connect response received, result %u",
2466 * Function to request a table chunk in a syncronous way
2468 * It first writes the request to zclient output buffer and then
2469 * immediately reads the answer from the input buffer.
2471 * @param zclient Zclient used to connect to table manager (zebra)
2472 * @param chunk_size Amount of table requested
2473 * @param start to write first assigned chunk table RT ID to
2474 * @param end To write last assigned chunk table RT ID to
2475 * @result 0 on success, -1 otherwise
2477 int tm_get_table_chunk(struct zclient
*zclient
, uint32_t chunk_size
,
2478 uint32_t *start
, uint32_t *end
)
2484 zlog_debug("Getting Table Chunk");
2486 if (zclient
->sock
< 0)
2492 zclient_create_header(s
, ZEBRA_GET_TABLE_CHUNK
, VRF_DEFAULT
);
2494 stream_putl(s
, chunk_size
);
2495 /* Put length at the first point of the stream. */
2496 stream_putw_at(s
, 0, stream_get_endp(s
));
2498 ret
= writen(zclient
->sock
, s
->data
, stream_get_endp(s
));
2500 flog_err(EC_LIB_ZAPI_SOCKET
, "%s: can't write to zclient->sock",
2502 close(zclient
->sock
);
2507 flog_err(EC_LIB_ZAPI_SOCKET
,
2508 "%s: zclient->sock connection closed", __func__
);
2509 close(zclient
->sock
);
2514 zlog_debug("%s: Table chunk request (%d bytes) sent", __func__
,
2518 if (zclient_read_sync_response(zclient
, ZEBRA_GET_TABLE_CHUNK
) != 0)
2522 /* start and end table IDs */
2523 STREAM_GETL(s
, *start
);
2524 STREAM_GETL(s
, *end
);
2527 zlog_debug("Table Chunk assign: %u - %u ", *start
, *end
);
2535 * Function to release a table chunk
2537 * @param zclient Zclient used to connect to table manager (zebra)
2538 * @param start First label of table
2539 * @param end Last label of chunk
2540 * @result 0 on success, -1 otherwise
2542 int tm_release_table_chunk(struct zclient
*zclient
, uint32_t start
,
2548 zlog_debug("Releasing Table Chunk");
2550 if (zclient
->sock
< 0)
2556 zclient_create_header(s
, ZEBRA_RELEASE_TABLE_CHUNK
, VRF_DEFAULT
);
2559 stream_putl(s
, start
);
2561 stream_putl(s
, end
);
2563 /* Put length at the first point of the stream. */
2564 stream_putw_at(s
, 0, stream_get_endp(s
));
2566 return zclient_send_message(zclient
);
2569 int zebra_send_mpls_labels(struct zclient
*zclient
, int cmd
,
2570 struct zapi_labels
*zl
)
2572 if (zapi_labels_encode(zclient
->obuf
, cmd
, zl
) < 0)
2574 return zclient_send_message(zclient
);
2577 int zapi_labels_encode(struct stream
*s
, int cmd
, struct zapi_labels
*zl
)
2579 struct zapi_nexthop_label
*znh
;
2583 zclient_create_header(s
, cmd
, VRF_DEFAULT
);
2584 stream_putc(s
, zl
->message
);
2585 stream_putc(s
, zl
->type
);
2586 stream_putl(s
, zl
->local_label
);
2588 if (CHECK_FLAG(zl
->message
, ZAPI_LABELS_FTN
)) {
2589 stream_putw(s
, zl
->route
.prefix
.family
);
2590 stream_put_prefix(s
, &zl
->route
.prefix
);
2591 stream_putc(s
, zl
->route
.type
);
2592 stream_putw(s
, zl
->route
.instance
);
2595 if (zl
->nexthop_num
> MULTIPATH_NUM
) {
2598 "%s: label %u: can't encode %u nexthops (maximum is %u)",
2599 __func__
, zl
->local_label
, zl
->nexthop_num
,
2603 stream_putw(s
, zl
->nexthop_num
);
2605 for (int i
= 0; i
< zl
->nexthop_num
; i
++) {
2606 znh
= &zl
->nexthops
[i
];
2608 stream_putc(s
, znh
->type
);
2609 stream_putw(s
, znh
->family
);
2610 switch (znh
->family
) {
2612 stream_put_in_addr(s
, &znh
->address
.ipv4
);
2615 stream_write(s
, (uint8_t *)&znh
->address
.ipv6
, 16);
2620 stream_putl(s
, znh
->ifindex
);
2621 stream_putl(s
, znh
->label
);
2624 /* Put length at the first point of the stream. */
2625 stream_putw_at(s
, 0, stream_get_endp(s
));
2630 int zapi_labels_decode(struct stream
*s
, struct zapi_labels
*zl
)
2632 struct zapi_nexthop_label
*znh
;
2634 memset(zl
, 0, sizeof(*zl
));
2637 STREAM_GETC(s
, zl
->message
);
2638 STREAM_GETC(s
, zl
->type
);
2639 STREAM_GETL(s
, zl
->local_label
);
2641 if (CHECK_FLAG(zl
->message
, ZAPI_LABELS_FTN
)) {
2644 STREAM_GETW(s
, zl
->route
.prefix
.family
);
2645 STREAM_GETC(s
, zl
->route
.prefix
.prefixlen
);
2647 psize
= PSIZE(zl
->route
.prefix
.prefixlen
);
2648 switch (zl
->route
.prefix
.family
) {
2650 if (zl
->route
.prefix
.prefixlen
> IPV4_MAX_BITLEN
) {
2652 "%s: Specified prefix length %d is greater than a v4 address can support",
2653 __PRETTY_FUNCTION__
,
2654 zl
->route
.prefix
.prefixlen
);
2657 STREAM_GET(&zl
->route
.prefix
.u
.prefix4
.s_addr
, s
,
2661 if (zl
->route
.prefix
.prefixlen
> IPV6_MAX_BITLEN
) {
2663 "%s: Specified prefix length %d is greater than a v6 address can support",
2664 __PRETTY_FUNCTION__
,
2665 zl
->route
.prefix
.prefixlen
);
2668 STREAM_GET(&zl
->route
.prefix
.u
.prefix6
, s
, psize
);
2671 flog_err(EC_LIB_ZAPI_ENCODE
,
2672 "%s: Specified family %u is not v4 or v6",
2673 __PRETTY_FUNCTION__
, zl
->route
.prefix
.family
);
2677 STREAM_GETC(s
, zl
->route
.type
);
2678 STREAM_GETW(s
, zl
->route
.instance
);
2681 STREAM_GETW(s
, zl
->nexthop_num
);
2683 if (zl
->nexthop_num
> MULTIPATH_NUM
) {
2686 "%s: Prefix %pFX has %d nexthops, but we can only use the first %d",
2687 __func__
, &zl
->route
.prefix
, zl
->nexthop_num
,
2691 zl
->nexthop_num
= MIN(MULTIPATH_NUM
, zl
->nexthop_num
);
2693 for (int i
= 0; i
< zl
->nexthop_num
; i
++) {
2694 znh
= &zl
->nexthops
[i
];
2696 STREAM_GETC(s
, znh
->type
);
2697 STREAM_GETW(s
, znh
->family
);
2698 switch (znh
->family
) {
2700 STREAM_GET(&znh
->address
.ipv4
.s_addr
, s
,
2704 STREAM_GET(&znh
->address
.ipv6
, s
, 16);
2709 STREAM_GETL(s
, znh
->ifindex
);
2710 STREAM_GETL(s
, znh
->label
);
2718 int zebra_send_pw(struct zclient
*zclient
, int command
, struct zapi_pw
*pw
)
2726 zclient_create_header(s
, command
, VRF_DEFAULT
);
2727 stream_write(s
, pw
->ifname
, IF_NAMESIZE
);
2728 stream_putl(s
, pw
->ifindex
);
2731 stream_putl(s
, pw
->type
);
2734 stream_putl(s
, pw
->af
);
2737 stream_put_in_addr(s
, &pw
->nexthop
.ipv4
);
2740 stream_write(s
, (uint8_t *)&pw
->nexthop
.ipv6
, 16);
2743 flog_err(EC_LIB_ZAPI_ENCODE
, "%s: unknown af", __func__
);
2748 stream_putl(s
, pw
->local_label
);
2749 stream_putl(s
, pw
->remote_label
);
2752 stream_putc(s
, pw
->flags
);
2754 /* Protocol specific fields */
2755 stream_write(s
, &pw
->data
, sizeof(union pw_protocol_fields
));
2757 /* Put length at the first point of the stream. */
2758 stream_putw_at(s
, 0, stream_get_endp(s
));
2760 return zclient_send_message(zclient
);
2764 * Receive PW status update from Zebra and send it to LDE process.
2766 void zebra_read_pw_status_update(ZAPI_CALLBACK_ARGS
, struct zapi_pw_status
*pw
)
2770 memset(pw
, 0, sizeof(struct zapi_pw_status
));
2774 stream_get(pw
->ifname
, s
, IF_NAMESIZE
);
2775 pw
->ifindex
= stream_getl(s
);
2776 pw
->status
= stream_getl(s
);
2779 static void zclient_capability_decode(ZAPI_CALLBACK_ARGS
)
2781 struct zclient_capabilities cap
;
2782 struct stream
*s
= zclient
->ibuf
;
2784 uint8_t mpls_enabled
;
2786 STREAM_GETL(s
, vrf_backend
);
2787 vrf_configure_backend(vrf_backend
);
2789 memset(&cap
, 0, sizeof(cap
));
2790 STREAM_GETC(s
, mpls_enabled
);
2791 cap
.mpls_enabled
= !!mpls_enabled
;
2792 STREAM_GETL(s
, cap
.ecmp
);
2793 STREAM_GETC(s
, cap
.role
);
2795 if (zclient
->zebra_capabilities
)
2796 (*zclient
->zebra_capabilities
)(&cap
);
2802 void zclient_send_mlag_register(struct zclient
*client
, uint32_t bit_map
)
2809 zclient_create_header(s
, ZEBRA_MLAG_CLIENT_REGISTER
, VRF_DEFAULT
);
2810 stream_putl(s
, bit_map
);
2812 stream_putw_at(s
, 0, stream_get_endp(s
));
2813 zclient_send_message(client
);
2816 void zclient_send_mlag_deregister(struct zclient
*client
)
2818 zebra_message_send(client
, ZEBRA_MLAG_CLIENT_UNREGISTER
, VRF_DEFAULT
);
2821 void zclient_send_mlag_data(struct zclient
*client
, struct stream
*client_s
)
2828 zclient_create_header(s
, ZEBRA_MLAG_FORWARD_MSG
, VRF_DEFAULT
);
2829 stream_put(s
, client_s
->data
, client_s
->endp
);
2831 stream_putw_at(s
, 0, stream_get_endp(s
));
2832 zclient_send_message(client
);
2835 static void zclient_mlag_process_up(ZAPI_CALLBACK_ARGS
)
2837 if (zclient
->mlag_process_up
)
2838 (*zclient
->mlag_process_up
)();
2841 static void zclient_mlag_process_down(ZAPI_CALLBACK_ARGS
)
2843 if (zclient
->mlag_process_down
)
2844 (*zclient
->mlag_process_down
)();
2847 static void zclient_mlag_handle_msg(ZAPI_CALLBACK_ARGS
)
2849 if (zclient
->mlag_handle_msg
)
2850 (*zclient
->mlag_handle_msg
)(zclient
->ibuf
, length
);
2853 /* Zebra client message read function. */
2854 static int zclient_read(struct thread
*thread
)
2857 uint16_t length
, command
;
2858 uint8_t marker
, version
;
2860 struct zclient
*zclient
;
2862 /* Get socket to zebra. */
2863 zclient
= THREAD_ARG(thread
);
2864 zclient
->t_read
= NULL
;
2866 /* Read zebra header (if we don't have it already). */
2867 if ((already
= stream_get_endp(zclient
->ibuf
)) < ZEBRA_HEADER_SIZE
) {
2869 if (((nbyte
= stream_read_try(zclient
->ibuf
, zclient
->sock
,
2870 ZEBRA_HEADER_SIZE
- already
))
2875 "zclient connection closed socket [%d].",
2877 return zclient_failed(zclient
);
2879 if (nbyte
!= (ssize_t
)(ZEBRA_HEADER_SIZE
- already
)) {
2880 /* Try again later. */
2881 zclient_event(ZCLIENT_READ
, zclient
);
2884 already
= ZEBRA_HEADER_SIZE
;
2887 /* Reset to read from the beginning of the incoming packet. */
2888 stream_set_getp(zclient
->ibuf
, 0);
2890 /* Fetch header values. */
2891 length
= stream_getw(zclient
->ibuf
);
2892 marker
= stream_getc(zclient
->ibuf
);
2893 version
= stream_getc(zclient
->ibuf
);
2894 vrf_id
= stream_getl(zclient
->ibuf
);
2895 command
= stream_getw(zclient
->ibuf
);
2897 if (marker
!= ZEBRA_HEADER_MARKER
|| version
!= ZSERV_VERSION
) {
2899 EC_LIB_ZAPI_MISSMATCH
,
2900 "%s: socket %d version mismatch, marker %d, version %d",
2901 __func__
, zclient
->sock
, marker
, version
);
2902 return zclient_failed(zclient
);
2905 if (length
< ZEBRA_HEADER_SIZE
) {
2906 flog_err(EC_LIB_ZAPI_MISSMATCH
,
2907 "%s: socket %d message length %u is less than %d ",
2908 __func__
, zclient
->sock
, length
, ZEBRA_HEADER_SIZE
);
2909 return zclient_failed(zclient
);
2913 if (length
> STREAM_SIZE(zclient
->ibuf
)) {
2917 "%s: message size %u exceeds buffer size %lu, expanding...",
2919 (unsigned long)STREAM_SIZE(zclient
->ibuf
));
2920 ns
= stream_new(length
);
2921 stream_copy(ns
, zclient
->ibuf
);
2922 stream_free(zclient
->ibuf
);
2926 /* Read rest of zebra packet. */
2927 if (already
< length
) {
2929 if (((nbyte
= stream_read_try(zclient
->ibuf
, zclient
->sock
,
2935 "zclient connection closed socket [%d].",
2937 return zclient_failed(zclient
);
2939 if (nbyte
!= (ssize_t
)(length
- already
)) {
2940 /* Try again later. */
2941 zclient_event(ZCLIENT_READ
, zclient
);
2946 length
-= ZEBRA_HEADER_SIZE
;
2949 zlog_debug("zclient 0x%p command %s VRF %u",
2950 (void *)zclient
, zserv_command_string(command
),
2954 case ZEBRA_CAPABILITIES
:
2955 zclient_capability_decode(command
, zclient
, length
, vrf_id
);
2957 case ZEBRA_ROUTER_ID_UPDATE
:
2958 if (zclient
->router_id_update
)
2959 (*zclient
->router_id_update
)(command
, zclient
, length
,
2963 zclient_vrf_add(zclient
, vrf_id
);
2965 case ZEBRA_VRF_DELETE
:
2966 zclient_vrf_delete(zclient
, vrf_id
);
2968 case ZEBRA_INTERFACE_ADD
:
2969 zclient_interface_add(zclient
, vrf_id
);
2971 case ZEBRA_INTERFACE_DELETE
:
2972 zclient_interface_delete(zclient
, vrf_id
);
2974 case ZEBRA_INTERFACE_ADDRESS_ADD
:
2975 if (zclient
->interface_address_add
)
2976 (*zclient
->interface_address_add
)(command
, zclient
,
2979 case ZEBRA_INTERFACE_ADDRESS_DELETE
:
2980 if (zclient
->interface_address_delete
)
2981 (*zclient
->interface_address_delete
)(command
, zclient
,
2984 case ZEBRA_INTERFACE_BFD_DEST_UPDATE
:
2985 if (zclient
->interface_bfd_dest_update
)
2986 (*zclient
->interface_bfd_dest_update
)(command
, zclient
,
2989 case ZEBRA_INTERFACE_NBR_ADDRESS_ADD
:
2990 if (zclient
->interface_nbr_address_add
)
2991 (*zclient
->interface_nbr_address_add
)(command
, zclient
,
2994 case ZEBRA_INTERFACE_NBR_ADDRESS_DELETE
:
2995 if (zclient
->interface_nbr_address_delete
)
2996 (*zclient
->interface_nbr_address_delete
)(
2997 command
, zclient
, length
, vrf_id
);
2999 case ZEBRA_INTERFACE_UP
:
3000 zclient_interface_up(zclient
, vrf_id
);
3002 case ZEBRA_INTERFACE_DOWN
:
3003 zclient_interface_down(zclient
, vrf_id
);
3005 case ZEBRA_INTERFACE_VRF_UPDATE
:
3006 if (zclient
->interface_vrf_update
)
3007 (*zclient
->interface_vrf_update
)(command
, zclient
,
3010 case ZEBRA_NEXTHOP_UPDATE
:
3012 zlog_debug("zclient rcvd nexthop update");
3013 if (zclient
->nexthop_update
)
3014 (*zclient
->nexthop_update
)(command
, zclient
, length
,
3017 case ZEBRA_IMPORT_CHECK_UPDATE
:
3019 zlog_debug("zclient rcvd import check update");
3020 if (zclient
->import_check_update
)
3021 (*zclient
->import_check_update
)(command
, zclient
,
3024 case ZEBRA_BFD_DEST_REPLAY
:
3025 if (zclient
->bfd_dest_replay
)
3026 (*zclient
->bfd_dest_replay
)(command
, zclient
, length
,
3029 case ZEBRA_REDISTRIBUTE_ROUTE_ADD
:
3030 if (zclient
->redistribute_route_add
)
3031 (*zclient
->redistribute_route_add
)(command
, zclient
,
3034 case ZEBRA_REDISTRIBUTE_ROUTE_DEL
:
3035 if (zclient
->redistribute_route_del
)
3036 (*zclient
->redistribute_route_del
)(command
, zclient
,
3039 case ZEBRA_INTERFACE_LINK_PARAMS
:
3040 if (zclient
->interface_link_params
)
3041 (*zclient
->interface_link_params
)(command
, zclient
,
3044 case ZEBRA_FEC_UPDATE
:
3046 zlog_debug("zclient rcvd fec update");
3047 if (zclient
->fec_update
)
3048 (*zclient
->fec_update
)(command
, zclient
, length
);
3050 case ZEBRA_LOCAL_ES_ADD
:
3051 if (zclient
->local_es_add
)
3052 (*zclient
->local_es_add
)(command
, zclient
, length
,
3055 case ZEBRA_LOCAL_ES_DEL
:
3056 if (zclient
->local_es_del
)
3057 (*zclient
->local_es_del
)(command
, zclient
, length
,
3061 if (zclient
->local_vni_add
)
3062 (*zclient
->local_vni_add
)(command
, zclient
, length
,
3066 if (zclient
->local_vni_del
)
3067 (*zclient
->local_vni_del
)(command
, zclient
, length
,
3070 case ZEBRA_L3VNI_ADD
:
3071 if (zclient
->local_l3vni_add
)
3072 (*zclient
->local_l3vni_add
)(command
, zclient
, length
,
3075 case ZEBRA_L3VNI_DEL
:
3076 if (zclient
->local_l3vni_del
)
3077 (*zclient
->local_l3vni_del
)(command
, zclient
, length
,
3080 case ZEBRA_MACIP_ADD
:
3081 if (zclient
->local_macip_add
)
3082 (*zclient
->local_macip_add
)(command
, zclient
, length
,
3085 case ZEBRA_MACIP_DEL
:
3086 if (zclient
->local_macip_del
)
3087 (*zclient
->local_macip_del
)(command
, zclient
, length
,
3090 case ZEBRA_IP_PREFIX_ROUTE_ADD
:
3091 if (zclient
->local_ip_prefix_add
)
3092 (*zclient
->local_ip_prefix_add
)(command
, zclient
,
3095 case ZEBRA_IP_PREFIX_ROUTE_DEL
:
3096 if (zclient
->local_ip_prefix_del
)
3097 (*zclient
->local_ip_prefix_del
)(command
, zclient
,
3100 case ZEBRA_PW_STATUS_UPDATE
:
3101 if (zclient
->pw_status_update
)
3102 (*zclient
->pw_status_update
)(command
, zclient
, length
,
3105 case ZEBRA_ROUTE_NOTIFY_OWNER
:
3106 if (zclient
->route_notify_owner
)
3107 (*zclient
->route_notify_owner
)(command
, zclient
, length
,
3110 case ZEBRA_RULE_NOTIFY_OWNER
:
3111 if (zclient
->rule_notify_owner
)
3112 (*zclient
->rule_notify_owner
)(command
, zclient
, length
,
3115 case ZEBRA_GET_LABEL_CHUNK
:
3116 if (zclient
->label_chunk
)
3117 (*zclient
->label_chunk
)(command
, zclient
, length
,
3120 case ZEBRA_IPSET_NOTIFY_OWNER
:
3121 if (zclient
->ipset_notify_owner
)
3122 (*zclient
->ipset_notify_owner
)(command
, zclient
, length
,
3125 case ZEBRA_IPSET_ENTRY_NOTIFY_OWNER
:
3126 if (zclient
->ipset_entry_notify_owner
)
3127 (*zclient
->ipset_entry_notify_owner
)(command
,
3131 case ZEBRA_IPTABLE_NOTIFY_OWNER
:
3132 if (zclient
->iptable_notify_owner
)
3133 (*zclient
->iptable_notify_owner
)(command
,
3137 case ZEBRA_VXLAN_SG_ADD
:
3138 if (zclient
->vxlan_sg_add
)
3139 (*zclient
->vxlan_sg_add
)(command
, zclient
, length
,
3142 case ZEBRA_VXLAN_SG_DEL
:
3143 if (zclient
->vxlan_sg_del
)
3144 (*zclient
->vxlan_sg_del
)(command
, zclient
, length
,
3147 case ZEBRA_MLAG_PROCESS_UP
:
3148 zclient_mlag_process_up(command
, zclient
, length
, vrf_id
);
3150 case ZEBRA_MLAG_PROCESS_DOWN
:
3151 zclient_mlag_process_down(command
, zclient
, length
, vrf_id
);
3153 case ZEBRA_MLAG_FORWARD_MSG
:
3154 zclient_mlag_handle_msg(command
, zclient
, length
, vrf_id
);
3160 if (zclient
->sock
< 0)
3161 /* Connection was closed during packet processing. */
3164 /* Register read thread. */
3165 stream_reset(zclient
->ibuf
);
3166 zclient_event(ZCLIENT_READ
, zclient
);
3171 void zclient_redistribute(int command
, struct zclient
*zclient
, afi_t afi
,
3172 int type
, unsigned short instance
, vrf_id_t vrf_id
)
3176 if (command
== ZEBRA_REDISTRIBUTE_ADD
) {
3177 if (redist_check_instance(
3178 &zclient
->mi_redist
[afi
][type
], instance
))
3180 redist_add_instance(&zclient
->mi_redist
[afi
][type
],
3183 if (!redist_check_instance(
3184 &zclient
->mi_redist
[afi
][type
], instance
))
3186 redist_del_instance(&zclient
->mi_redist
[afi
][type
],
3191 if (command
== ZEBRA_REDISTRIBUTE_ADD
) {
3192 if (vrf_bitmap_check(zclient
->redist
[afi
][type
],
3195 vrf_bitmap_set(zclient
->redist
[afi
][type
], vrf_id
);
3197 if (!vrf_bitmap_check(zclient
->redist
[afi
][type
],
3200 vrf_bitmap_unset(zclient
->redist
[afi
][type
], vrf_id
);
3204 if (zclient
->sock
> 0)
3205 zebra_redistribute_send(command
, zclient
, afi
, type
, instance
,
3210 void zclient_redistribute_default(int command
, struct zclient
*zclient
,
3211 afi_t afi
, vrf_id_t vrf_id
)
3214 if (command
== ZEBRA_REDISTRIBUTE_DEFAULT_ADD
) {
3215 if (vrf_bitmap_check(zclient
->default_information
[afi
], vrf_id
))
3217 vrf_bitmap_set(zclient
->default_information
[afi
], vrf_id
);
3219 if (!vrf_bitmap_check(zclient
->default_information
[afi
],
3222 vrf_bitmap_unset(zclient
->default_information
[afi
], vrf_id
);
3225 if (zclient
->sock
> 0)
3226 zebra_redistribute_default_send(command
, zclient
, afi
, vrf_id
);
3229 static void zclient_event(enum event event
, struct zclient
*zclient
)
3232 case ZCLIENT_SCHEDULE
:
3233 thread_add_event(zclient
->master
, zclient_connect
, zclient
, 0,
3234 &zclient
->t_connect
);
3236 case ZCLIENT_CONNECT
:
3239 "zclient connect failures: %d schedule interval is now %d",
3240 zclient
->fail
, zclient
->fail
< 3 ? 10 : 60);
3241 thread_add_timer(zclient
->master
, zclient_connect
, zclient
,
3242 zclient
->fail
< 3 ? 10 : 60,
3243 &zclient
->t_connect
);
3246 zclient
->t_read
= NULL
;
3247 thread_add_read(zclient
->master
, zclient_read
, zclient
,
3248 zclient
->sock
, &zclient
->t_read
);
3253 void zclient_interface_set_master(struct zclient
*client
,
3254 struct interface
*master
,
3255 struct interface
*slave
)
3262 zclient_create_header(s
, ZEBRA_INTERFACE_SET_MASTER
, master
->vrf_id
);
3264 stream_putl(s
, master
->vrf_id
);
3265 stream_putl(s
, master
->ifindex
);
3266 stream_putl(s
, slave
->vrf_id
);
3267 stream_putl(s
, slave
->ifindex
);
3269 stream_putw_at(s
, 0, stream_get_endp(s
));
3270 zclient_send_message(client
);