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
39 DEFINE_MTYPE_STATIC(LIB
, ZCLIENT
, "Zclient")
40 DEFINE_MTYPE_STATIC(LIB
, REDIST_INST
, "Redistribution instance IDs")
42 /* Zebra client events. */
43 enum event
{ ZCLIENT_SCHEDULE
, ZCLIENT_READ
, ZCLIENT_CONNECT
};
45 /* Prototype for event manager. */
46 static void zclient_event(enum event
, struct zclient
*);
48 struct sockaddr_storage zclient_addr
;
49 socklen_t zclient_addr_len
;
51 /* This file local debug flag. */
52 int zclient_debug
= 0;
54 /* Allocate zclient structure. */
55 struct zclient
*zclient_new(struct thread_master
*master
)
57 struct zclient
*zclient
;
58 zclient
= XCALLOC(MTYPE_ZCLIENT
, sizeof(struct zclient
));
60 zclient
->ibuf
= stream_new(ZEBRA_MAX_PACKET_SIZ
);
61 zclient
->obuf
= stream_new(ZEBRA_MAX_PACKET_SIZ
);
62 zclient
->wb
= buffer_new(0);
63 zclient
->master
= master
;
68 /* This function is only called when exiting, because
69 many parts of the code do not check for I/O errors, so they could
70 reference an invalid pointer if the structure was ever freed.
72 Free zclient structure. */
73 void zclient_free(struct zclient
*zclient
)
76 stream_free(zclient
->ibuf
);
78 stream_free(zclient
->obuf
);
80 buffer_free(zclient
->wb
);
82 XFREE(MTYPE_ZCLIENT
, zclient
);
85 u_short
*redist_check_instance(struct redist_proto
*red
, u_short instance
)
87 struct listnode
*node
;
93 for (ALL_LIST_ELEMENTS_RO(red
->instances
, node
, id
))
100 void redist_add_instance(struct redist_proto
*red
, u_short instance
)
107 red
->instances
= list_new();
109 in
= XMALLOC(MTYPE_REDIST_INST
, sizeof(u_short
));
111 listnode_add(red
->instances
, in
);
114 void redist_del_instance(struct redist_proto
*red
, u_short instance
)
118 id
= redist_check_instance(red
, instance
);
122 listnode_delete(red
->instances
, id
);
123 XFREE(MTYPE_REDIST_INST
, id
);
124 if (!red
->instances
->count
) {
126 list_free(red
->instances
);
127 red
->instances
= NULL
;
131 /* Stop zebra client services. */
132 void zclient_stop(struct zclient
*zclient
)
138 zlog_debug("zclient stopped");
141 THREAD_OFF(zclient
->t_read
);
142 THREAD_OFF(zclient
->t_connect
);
143 THREAD_OFF(zclient
->t_write
);
146 stream_reset(zclient
->ibuf
);
147 stream_reset(zclient
->obuf
);
149 /* Empty the write buffer. */
150 buffer_reset(zclient
->wb
);
153 if (zclient
->sock
>= 0) {
154 close(zclient
->sock
);
159 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++) {
160 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++) {
161 vrf_bitmap_free(zclient
->redist
[afi
][i
]);
162 zclient
->redist
[afi
][i
] = VRF_BITMAP_NULL
;
165 &zclient
->mi_redist
[afi
][zclient
->redist_default
],
169 vrf_bitmap_free(zclient
->default_information
);
170 zclient
->default_information
= VRF_BITMAP_NULL
;
173 void zclient_reset(struct zclient
*zclient
)
177 zclient_stop(zclient
);
179 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
181 &zclient
->mi_redist
[afi
][zclient
->redist_default
],
184 zclient_init(zclient
, zclient
->redist_default
, zclient
->instance
);
188 * Connect to zebra daemon.
189 * @param zclient a pointer to zclient structure
190 * @return socket fd just to make sure that connection established
194 int zclient_socket_connect(struct zclient
*zclient
)
199 /* We should think about IPv6 connection. */
200 sock
= socket(zclient_addr
.ss_family
, SOCK_STREAM
, 0);
206 /* Connect to zebra. */
207 ret
= connect(sock
, (struct sockaddr
*)&zclient_addr
,
211 zlog_warn("%s connect failure: %d(%s)",
212 __PRETTY_FUNCTION__
, errno
,
213 safe_strerror(errno
));
218 zclient
->sock
= sock
;
222 static int zclient_failed(struct zclient
*zclient
)
225 zclient_stop(zclient
);
226 zclient_event(ZCLIENT_CONNECT
, zclient
);
230 static int zclient_flush_data(struct thread
*thread
)
232 struct zclient
*zclient
= THREAD_ARG(thread
);
234 zclient
->t_write
= NULL
;
235 if (zclient
->sock
< 0)
237 switch (buffer_flush_available(zclient
->wb
, zclient
->sock
)) {
240 "%s: buffer_flush_available failed on zclient fd %d, closing",
241 __func__
, zclient
->sock
);
242 return zclient_failed(zclient
);
245 zclient
->t_write
= NULL
;
246 thread_add_write(zclient
->master
, zclient_flush_data
, zclient
,
247 zclient
->sock
, &zclient
->t_write
);
255 int zclient_send_message(struct zclient
*zclient
)
257 if (zclient
->sock
< 0)
259 switch (buffer_write(zclient
->wb
, zclient
->sock
,
260 STREAM_DATA(zclient
->obuf
),
261 stream_get_endp(zclient
->obuf
))) {
263 zlog_warn("%s: buffer_write failed to zclient fd %d, closing",
264 __func__
, zclient
->sock
);
265 return zclient_failed(zclient
);
268 THREAD_OFF(zclient
->t_write
);
271 thread_add_write(zclient
->master
, zclient_flush_data
, zclient
,
272 zclient
->sock
, &zclient
->t_write
);
278 void zclient_create_header(struct stream
*s
, uint16_t command
, vrf_id_t vrf_id
)
280 /* length placeholder, caller can update */
281 stream_putw(s
, ZEBRA_HEADER_SIZE
);
282 stream_putc(s
, ZEBRA_HEADER_MARKER
);
283 stream_putc(s
, ZSERV_VERSION
);
284 stream_putw(s
, vrf_id
);
285 stream_putw(s
, command
);
288 int zclient_read_header(struct stream
*s
, int sock
, u_int16_t
*size
,
289 u_char
*marker
, u_char
*version
, vrf_id_t
*vrf_id
,
292 if (stream_read(s
, sock
, ZEBRA_HEADER_SIZE
) != ZEBRA_HEADER_SIZE
)
295 *size
= stream_getw(s
) - ZEBRA_HEADER_SIZE
;
296 *marker
= stream_getc(s
);
297 *version
= stream_getc(s
);
298 *vrf_id
= stream_getw(s
);
299 *cmd
= stream_getw(s
);
301 if (*version
!= ZSERV_VERSION
|| *marker
!= ZEBRA_HEADER_MARKER
) {
303 "%s: socket %d version mismatch, marker %d, version %d",
304 __func__
, sock
, *marker
, *version
);
308 if (*size
&& stream_read(s
, sock
, *size
) != *size
)
314 /* Send simple Zebra message. */
315 static int zebra_message_send(struct zclient
*zclient
, int command
,
320 /* Get zclient output buffer. */
324 /* Send very simple command only Zebra message. */
325 zclient_create_header(s
, command
, vrf_id
);
327 return zclient_send_message(zclient
);
330 static int zebra_hello_send(struct zclient
*zclient
)
334 if (zclient
->redist_default
) {
338 /* The VRF ID in the HELLO message is always 0. */
339 zclient_create_header(s
, ZEBRA_HELLO
, VRF_DEFAULT
);
340 stream_putc(s
, zclient
->redist_default
);
341 stream_putw(s
, zclient
->instance
);
342 stream_putw_at(s
, 0, stream_get_endp(s
));
343 return zclient_send_message(zclient
);
349 /* Send register requests to zebra daemon for the information in a VRF. */
350 void zclient_send_reg_requests(struct zclient
*zclient
, vrf_id_t vrf_id
)
355 /* If not connected to the zebra yet. */
356 if (zclient
->sock
< 0)
360 zlog_debug("%s: send register messages for VRF %u", __func__
,
363 /* We need router-id information. */
364 zebra_message_send(zclient
, ZEBRA_ROUTER_ID_ADD
, vrf_id
);
366 /* We need interface information. */
367 zebra_message_send(zclient
, ZEBRA_INTERFACE_ADD
, vrf_id
);
369 /* Set unwanted redistribute route. */
370 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
371 vrf_bitmap_set(zclient
->redist
[afi
][zclient
->redist_default
],
374 /* Flush all redistribute request. */
375 if (vrf_id
== VRF_DEFAULT
)
376 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
377 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++)
378 if (zclient
->mi_redist
[afi
][i
].enabled
) {
379 struct listnode
*node
;
382 for (ALL_LIST_ELEMENTS_RO(
383 zclient
->mi_redist
[afi
][i
]
386 if (!(i
== zclient
->redist_default
387 && *id
== zclient
->instance
))
388 zebra_redistribute_send(
389 ZEBRA_REDISTRIBUTE_ADD
,
395 /* Flush all redistribute request. */
396 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
397 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++)
398 if (i
!= zclient
->redist_default
399 && vrf_bitmap_check(zclient
->redist
[afi
][i
],
401 zebra_redistribute_send(ZEBRA_REDISTRIBUTE_ADD
,
405 /* If default information is needed. */
406 if (vrf_bitmap_check(zclient
->default_information
, VRF_DEFAULT
))
407 zebra_message_send(zclient
, ZEBRA_REDISTRIBUTE_DEFAULT_ADD
,
411 /* Send unregister requests to zebra daemon for the information in a VRF. */
412 void zclient_send_dereg_requests(struct zclient
*zclient
, vrf_id_t vrf_id
)
417 /* If not connected to the zebra yet. */
418 if (zclient
->sock
< 0)
422 zlog_debug("%s: send deregister messages for VRF %u", __func__
,
425 /* We need router-id information. */
426 zebra_message_send(zclient
, ZEBRA_ROUTER_ID_DELETE
, vrf_id
);
428 /* We need interface information. */
429 zebra_message_send(zclient
, ZEBRA_INTERFACE_DELETE
, vrf_id
);
431 /* Set unwanted redistribute route. */
432 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
433 vrf_bitmap_set(zclient
->redist
[afi
][zclient
->redist_default
],
436 /* Flush all redistribute request. */
437 if (vrf_id
== VRF_DEFAULT
)
438 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
439 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++)
440 if (zclient
->mi_redist
[afi
][i
].enabled
) {
441 struct listnode
*node
;
444 for (ALL_LIST_ELEMENTS_RO(
445 zclient
->mi_redist
[afi
][i
]
448 if (!(i
== zclient
->redist_default
449 && *id
== zclient
->instance
))
450 zebra_redistribute_send(
451 ZEBRA_REDISTRIBUTE_DELETE
,
457 /* Flush 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(
464 ZEBRA_REDISTRIBUTE_DELETE
, zclient
, afi
,
467 /* If default information is needed. */
468 if (vrf_bitmap_check(zclient
->default_information
, VRF_DEFAULT
))
469 zebra_message_send(zclient
, ZEBRA_REDISTRIBUTE_DEFAULT_DELETE
,
473 /* Send request to zebra daemon to start or stop RA. */
474 void zclient_send_interface_radv_req(struct zclient
*zclient
, vrf_id_t vrf_id
,
475 struct interface
*ifp
, int enable
,
480 /* If not connected to the zebra yet. */
481 if (zclient
->sock
< 0)
484 /* Form and send message. */
489 zclient_create_header(s
, ZEBRA_INTERFACE_ENABLE_RADV
, vrf_id
);
491 zclient_create_header(s
, ZEBRA_INTERFACE_DISABLE_RADV
, vrf_id
);
493 stream_putl(s
, ifp
->ifindex
);
494 stream_putl(s
, ra_interval
);
496 stream_putw_at(s
, 0, stream_get_endp(s
));
498 zclient_send_message(zclient
);
501 /* Make connection to zebra daemon. */
502 int zclient_start(struct zclient
*zclient
)
505 zlog_info("zclient_start is called");
507 /* If already connected to the zebra. */
508 if (zclient
->sock
>= 0)
511 /* Check connect thread. */
512 if (zclient
->t_connect
)
515 if (zclient_socket_connect(zclient
) < 0) {
517 zlog_debug("zclient connection fail");
519 zclient_event(ZCLIENT_CONNECT
, zclient
);
523 if (set_nonblocking(zclient
->sock
) < 0)
524 zlog_warn("%s: set_nonblocking(%d) failed", __func__
,
527 /* Clear fail count. */
530 zlog_debug("zclient connect success with socket [%d]",
533 /* Create read thread. */
534 zclient_event(ZCLIENT_READ
, zclient
);
536 zebra_hello_send(zclient
);
538 /* Inform the successful connection. */
539 if (zclient
->zebra_connected
)
540 (*zclient
->zebra_connected
)(zclient
);
545 /* Initialize zebra client. Argument redist_default is unwanted
546 redistribute route type. */
547 void zclient_init(struct zclient
*zclient
, int redist_default
, u_short instance
)
551 /* Set -1 to the default socket value. */
554 /* Clear redistribution flags. */
555 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
556 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++)
557 zclient
->redist
[afi
][i
] = vrf_bitmap_init();
559 /* Set unwanted redistribute route. bgpd does not need BGP route
561 zclient
->redist_default
= redist_default
;
562 zclient
->instance
= instance
;
563 /* Pending: make afi(s) an arg. */
564 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
565 redist_add_instance(&zclient
->mi_redist
[afi
][redist_default
],
568 /* Set default-information redistribute to zero. */
569 zclient
->default_information
= vrf_bitmap_init();
573 zlog_debug("zclient_start is called");
575 zclient_event(ZCLIENT_SCHEDULE
, zclient
);
578 /* This function is a wrapper function for calling zclient_start from
579 timer or event thread. */
580 static int zclient_connect(struct thread
*t
)
582 struct zclient
*zclient
;
584 zclient
= THREAD_ARG(t
);
585 zclient
->t_connect
= NULL
;
588 zlog_debug("zclient_connect is called");
590 return zclient_start(zclient
);
594 * "xdr_encode"-like interface that allows daemon (client) to send
595 * a message to zebra server for a route that needs to be
596 * added/deleted to the kernel. Info about the route is specified
597 * by the caller in a struct zapi_ipv4. zapi_ipv4_read() then writes
598 * the info down the zclient socket using the stream_* functions.
600 * The corresponding read ("xdr_decode") function on the server
601 * side is zread_ipv4_add()/zread_ipv4_delete().
603 * 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
604 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
605 * | Length (2) | Command | Route Type |
606 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
607 * | ZEBRA Flags | Message Flags | Prefix length |
608 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
609 * | Destination IPv4 Prefix for route |
610 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
615 * A number of IPv4 nexthop(s) or nexthop interface index(es) are then
616 * described, as per the Nexthop count. Each nexthop described as:
619 * | Nexthop Type | Set to one of ZEBRA_NEXTHOP_*
620 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
621 * | IPv4 Nexthop address or Interface Index number |
622 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
624 * Alternatively, if the flags field has ZEBRA_FLAG_BLACKHOLE or
625 * ZEBRA_FLAG_REJECT is set then Nexthop count is set to 1, then _no_
626 * nexthop information is provided, and the message describes a prefix
627 * to blackhole or reject route.
629 * The original struct zapi_ipv4, zapi_ipv4_route() and zread_ipv4_*()
630 * infrastructure was built around the traditional (32-bit "gate OR
631 * ifindex") nexthop data unit. A special encoding can be used to feed
632 * onlink (64-bit "gate AND ifindex") nexthops into zapi_ipv4_route()
633 * using the same zapi_ipv4 structure. This is done by setting zapi_ipv4
635 * - .message |= ZAPI_MESSAGE_NEXTHOP | ZAPI_MESSAGE_ONLINK
636 * - .nexthop_num == .ifindex_num
637 * - .nexthop and .ifindex are filled with gate and ifindex parts of
638 * each compound nexthop, both in the same order
640 * zapi_ipv4_route() will produce two nexthop data units for each such
641 * interleaved 64-bit nexthop. On the zserv side of the socket it will be
642 * mapped to a singlle NEXTHOP_TYPE_IPV4_IFINDEX_OL RIB nexthop structure.
644 * If ZAPI_MESSAGE_DISTANCE is set, the distance value is written as a 1
647 * If ZAPI_MESSAGE_METRIC is set, the metric value is written as an 8
650 * If ZAPI_MESSAGE_TAG is set, the tag value is written as a 4 byte value
652 * If ZAPI_MESSAGE_MTU is set, the mtu value is written as a 4 byte value
654 * XXX: No attention paid to alignment.
656 int zapi_ipv4_route(u_char cmd
, struct zclient
*zclient
, struct prefix_ipv4
*p
,
657 struct zapi_ipv4
*api
)
667 /* Some checks for labeled-unicast. The current expectation is that each
668 * nexthop is accompanied by a label in the case of labeled-unicast.
670 if (CHECK_FLAG(api
->message
, ZAPI_MESSAGE_LABEL
)
671 && CHECK_FLAG(api
->message
, ZAPI_MESSAGE_NEXTHOP
)) {
672 /* We expect prefixes installed with labels and the number to
674 * the number of nexthops.
676 assert(api
->label_num
== api
->nexthop_num
);
679 zclient_create_header(s
, cmd
, api
->vrf_id
);
681 /* Put type and nexthop. */
682 stream_putc(s
, api
->type
);
683 stream_putw(s
, api
->instance
);
684 stream_putl(s
, api
->flags
);
685 stream_putc(s
, api
->message
);
686 stream_putw(s
, api
->safi
);
688 /* Put prefix information. */
689 psize
= PSIZE(p
->prefixlen
);
690 stream_putc(s
, p
->prefixlen
);
691 stream_write(s
, (u_char
*)&p
->prefix
, psize
);
693 /* Nexthop, ifindex, distance and metric information. */
694 if (CHECK_FLAG(api
->message
, ZAPI_MESSAGE_NEXTHOP
)) {
695 /* traditional 32-bit data units */
696 if (CHECK_FLAG(api
->flags
, ZEBRA_FLAG_BLACKHOLE
)) {
698 stream_putc(s
, NEXTHOP_TYPE_BLACKHOLE
);
699 /* XXX assert(api->nexthop_num == 0); */
700 /* XXX assert(api->ifindex_num == 0); */
702 stream_putc(s
, api
->nexthop_num
+ api
->ifindex_num
);
704 for (i
= 0; i
< api
->nexthop_num
; i
++) {
705 stream_putc(s
, NEXTHOP_TYPE_IPV4
);
706 stream_put_in_addr(s
, api
->nexthop
[i
]);
707 /* For labeled-unicast, each nexthop is followed by
709 if (CHECK_FLAG(api
->message
, ZAPI_MESSAGE_LABEL
))
710 stream_putl(s
, api
->label
[i
]);
712 for (i
= 0; i
< api
->ifindex_num
; i
++) {
713 stream_putc(s
, NEXTHOP_TYPE_IFINDEX
);
714 stream_putl(s
, api
->ifindex
[i
]);
718 if (CHECK_FLAG(api
->message
, ZAPI_MESSAGE_DISTANCE
))
719 stream_putc(s
, api
->distance
);
720 if (CHECK_FLAG(api
->message
, ZAPI_MESSAGE_METRIC
))
721 stream_putl(s
, api
->metric
);
722 if (CHECK_FLAG(api
->message
, ZAPI_MESSAGE_TAG
))
723 stream_putl(s
, api
->tag
);
724 if (CHECK_FLAG(api
->message
, ZAPI_MESSAGE_MTU
))
725 stream_putl(s
, api
->mtu
);
727 /* Put length at the first point of the stream. */
728 stream_putw_at(s
, 0, stream_get_endp(s
));
730 return zclient_send_message(zclient
);
733 int zapi_ipv4_route_ipv6_nexthop(u_char cmd
, struct zclient
*zclient
,
734 struct prefix_ipv4
*p
, struct zapi_ipv6
*api
)
744 /* Some checks for labeled-unicast. The current expectation is that each
745 * nexthop is accompanied by a label in the case of labeled-unicast.
747 if (CHECK_FLAG(api
->message
, ZAPI_MESSAGE_LABEL
)
748 && CHECK_FLAG(api
->message
, ZAPI_MESSAGE_NEXTHOP
)) {
749 /* We expect prefixes installed with labels and the number to
751 * the number of nexthops.
753 assert(api
->label_num
== api
->nexthop_num
);
756 zclient_create_header(s
, cmd
, api
->vrf_id
);
758 /* Put type and nexthop. */
759 stream_putc(s
, api
->type
);
760 stream_putw(s
, api
->instance
);
761 stream_putl(s
, api
->flags
);
762 stream_putc(s
, api
->message
);
763 stream_putw(s
, api
->safi
);
765 /* Put prefix information. */
766 psize
= PSIZE(p
->prefixlen
);
767 stream_putc(s
, p
->prefixlen
);
768 stream_write(s
, (u_char
*)&p
->prefix
, psize
);
770 /* Nexthop, ifindex, distance and metric information. */
771 if (CHECK_FLAG(api
->message
, ZAPI_MESSAGE_NEXTHOP
)) {
772 if (CHECK_FLAG(api
->flags
, ZEBRA_FLAG_BLACKHOLE
)) {
774 stream_putc(s
, NEXTHOP_TYPE_BLACKHOLE
);
775 /* XXX assert(api->nexthop_num == 0); */
776 /* XXX assert(api->ifindex_num == 0); */
778 stream_putc(s
, api
->nexthop_num
+ api
->ifindex_num
);
780 for (i
= 0; i
< api
->nexthop_num
; i
++) {
781 stream_putc(s
, NEXTHOP_TYPE_IPV6
);
782 stream_write(s
, (u_char
*)api
->nexthop
[i
], 16);
783 /* For labeled-unicast, each nexthop is followed by
785 if (CHECK_FLAG(api
->message
, ZAPI_MESSAGE_LABEL
))
786 stream_putl(s
, api
->label
[i
]);
788 for (i
= 0; i
< api
->ifindex_num
; i
++) {
789 stream_putc(s
, NEXTHOP_TYPE_IFINDEX
);
790 stream_putl(s
, api
->ifindex
[i
]);
794 if (CHECK_FLAG(api
->message
, ZAPI_MESSAGE_DISTANCE
))
795 stream_putc(s
, api
->distance
);
796 if (CHECK_FLAG(api
->message
, ZAPI_MESSAGE_METRIC
))
797 stream_putl(s
, api
->metric
);
798 if (CHECK_FLAG(api
->message
, ZAPI_MESSAGE_TAG
))
799 stream_putl(s
, api
->tag
);
800 if (CHECK_FLAG(api
->message
, ZAPI_MESSAGE_MTU
))
801 stream_putl(s
, api
->mtu
);
803 /* Put length at the first point of the stream. */
804 stream_putw_at(s
, 0, stream_get_endp(s
));
806 return zclient_send_message(zclient
);
809 int zapi_ipv6_route(u_char cmd
, struct zclient
*zclient
, struct prefix_ipv6
*p
,
810 struct prefix_ipv6
*src_p
, struct zapi_ipv6
*api
)
816 /* either we have !SRCPFX && src_p == NULL, or SRCPFX && src_p != NULL
818 assert(!(api
->message
& ZAPI_MESSAGE_SRCPFX
) == !src_p
);
824 /* Some checks for labeled-unicast. The current expectation is that each
825 * nexthop is accompanied by a label in the case of labeled-unicast.
827 if (CHECK_FLAG(api
->message
, ZAPI_MESSAGE_LABEL
)
828 && CHECK_FLAG(api
->message
, ZAPI_MESSAGE_NEXTHOP
)) {
829 /* We expect prefixes installed with labels and the number to
831 * the number of nexthops.
833 assert(api
->label_num
== api
->nexthop_num
);
836 zclient_create_header(s
, cmd
, api
->vrf_id
);
838 /* Put type and nexthop. */
839 stream_putc(s
, api
->type
);
840 stream_putw(s
, api
->instance
);
841 stream_putl(s
, api
->flags
);
842 stream_putc(s
, api
->message
);
843 stream_putw(s
, api
->safi
);
845 /* Put prefix information. */
846 psize
= PSIZE(p
->prefixlen
);
847 stream_putc(s
, p
->prefixlen
);
848 stream_write(s
, (u_char
*)&p
->prefix
, psize
);
850 if (CHECK_FLAG(api
->message
, ZAPI_MESSAGE_SRCPFX
)) {
851 psize
= PSIZE(src_p
->prefixlen
);
852 stream_putc(s
, src_p
->prefixlen
);
853 stream_write(s
, (u_char
*)&src_p
->prefix
, psize
);
856 /* Nexthop, ifindex, distance and metric information. */
857 if (CHECK_FLAG(api
->message
, ZAPI_MESSAGE_NEXTHOP
)) {
858 if (CHECK_FLAG(api
->flags
, ZEBRA_FLAG_BLACKHOLE
)) {
860 stream_putc(s
, NEXTHOP_TYPE_BLACKHOLE
);
861 /* XXX assert(api->nexthop_num == 0); */
862 /* XXX assert(api->ifindex_num == 0); */
864 stream_putc(s
, api
->nexthop_num
+ api
->ifindex_num
);
866 for (i
= 0; i
< api
->nexthop_num
; i
++) {
867 stream_putc(s
, NEXTHOP_TYPE_IPV6
);
868 stream_write(s
, (u_char
*)api
->nexthop
[i
], 16);
869 /* For labeled-unicast, each nexthop is followed by
871 if (CHECK_FLAG(api
->message
, ZAPI_MESSAGE_LABEL
))
872 stream_putl(s
, api
->label
[i
]);
874 for (i
= 0; i
< api
->ifindex_num
; i
++) {
875 stream_putc(s
, NEXTHOP_TYPE_IFINDEX
);
876 stream_putl(s
, api
->ifindex
[i
]);
880 if (CHECK_FLAG(api
->message
, ZAPI_MESSAGE_DISTANCE
))
881 stream_putc(s
, api
->distance
);
882 if (CHECK_FLAG(api
->message
, ZAPI_MESSAGE_METRIC
))
883 stream_putl(s
, api
->metric
);
884 if (CHECK_FLAG(api
->message
, ZAPI_MESSAGE_TAG
))
885 stream_putl(s
, api
->tag
);
886 if (CHECK_FLAG(api
->message
, ZAPI_MESSAGE_MTU
))
887 stream_putl(s
, api
->mtu
);
889 /* Put length at the first point of the stream. */
890 stream_putw_at(s
, 0, stream_get_endp(s
));
892 return zclient_send_message(zclient
);
895 int zclient_route_send(u_char cmd
, struct zclient
*zclient
,
896 struct zapi_route
*api
)
898 if (zapi_route_encode(cmd
, zclient
->obuf
, api
) < 0)
900 return zclient_send_message(zclient
);
903 int zapi_route_encode(u_char cmd
, struct stream
*s
, struct zapi_route
*api
)
905 struct zapi_nexthop
*api_nh
;
910 zclient_create_header(s
, cmd
, api
->vrf_id
);
912 stream_putc(s
, api
->type
);
913 stream_putw(s
, api
->instance
);
914 stream_putl(s
, api
->flags
);
915 stream_putc(s
, api
->message
);
916 stream_putw(s
, api
->safi
);
918 /* Put prefix information. */
919 stream_putc(s
, api
->prefix
.family
);
920 psize
= PSIZE(api
->prefix
.prefixlen
);
921 stream_putc(s
, api
->prefix
.prefixlen
);
922 stream_write(s
, (u_char
*)&api
->prefix
.u
.prefix
, psize
);
924 if (CHECK_FLAG(api
->message
, ZAPI_MESSAGE_SRCPFX
)) {
925 psize
= PSIZE(api
->src_prefix
.prefixlen
);
926 stream_putc(s
, api
->src_prefix
.prefixlen
);
927 stream_write(s
, (u_char
*)&api
->src_prefix
.prefix
, psize
);
931 if (CHECK_FLAG(api
->message
, ZAPI_MESSAGE_NEXTHOP
)) {
932 /* limit the number of nexthops if necessary */
933 if (api
->nexthop_num
> MULTIPATH_NUM
) {
934 char buf
[PREFIX2STR_BUFFER
];
936 prefix2str(&api
->prefix
, buf
, sizeof(buf
));
938 "%s: prefix %s: encoding %u nexthops out of %u",
939 __func__
, buf
, MULTIPATH_NUM
, api
->nexthop_num
);
940 api
->nexthop_num
= MULTIPATH_NUM
;
943 stream_putc(s
, api
->nexthop_num
);
945 for (i
= 0; i
< api
->nexthop_num
; i
++) {
946 api_nh
= &api
->nexthops
[i
];
948 stream_putc(s
, api_nh
->type
);
949 switch (api_nh
->type
) {
950 case NEXTHOP_TYPE_BLACKHOLE
:
952 case NEXTHOP_TYPE_IPV4
:
953 stream_put_in_addr(s
, &api_nh
->gate
.ipv4
);
955 case NEXTHOP_TYPE_IPV4_IFINDEX
:
956 stream_put_in_addr(s
, &api_nh
->gate
.ipv4
);
957 stream_putl(s
, api_nh
->ifindex
);
959 case NEXTHOP_TYPE_IFINDEX
:
960 stream_putl(s
, api_nh
->ifindex
);
962 case NEXTHOP_TYPE_IPV6
:
963 stream_write(s
, (u_char
*)&api_nh
->gate
.ipv6
,
966 case NEXTHOP_TYPE_IPV6_IFINDEX
:
967 stream_write(s
, (u_char
*)&api_nh
->gate
.ipv6
,
969 stream_putl(s
, api_nh
->ifindex
);
973 /* MPLS labels for BGP-LU or Segment Routing */
974 if (CHECK_FLAG(api
->message
, ZAPI_MESSAGE_LABEL
)) {
975 if (api_nh
->label_num
> MPLS_MAX_LABELS
) {
976 char buf
[PREFIX2STR_BUFFER
];
977 prefix2str(&api
->prefix
, buf
,
980 "%s: prefix %s: can't encode "
981 "%u labels (maximum is %u)",
988 stream_putc(s
, api_nh
->label_num
);
989 stream_put(s
, &api_nh
->labels
[0],
991 * sizeof(mpls_label_t
));
997 if (CHECK_FLAG(api
->message
, ZAPI_MESSAGE_DISTANCE
))
998 stream_putc(s
, api
->distance
);
999 if (CHECK_FLAG(api
->message
, ZAPI_MESSAGE_METRIC
))
1000 stream_putl(s
, api
->metric
);
1001 if (CHECK_FLAG(api
->message
, ZAPI_MESSAGE_TAG
))
1002 stream_putl(s
, api
->tag
);
1003 if (CHECK_FLAG(api
->message
, ZAPI_MESSAGE_MTU
))
1004 stream_putl(s
, api
->mtu
);
1006 /* Put length at the first point of the stream. */
1007 stream_putw_at(s
, 0, stream_get_endp(s
));
1012 int zapi_route_decode(struct stream
*s
, struct zapi_route
*api
)
1014 struct zapi_nexthop
*api_nh
;
1017 memset(api
, 0, sizeof(*api
));
1019 /* Type, flags, message. */
1020 api
->type
= stream_getc(s
);
1021 api
->instance
= stream_getw(s
);
1022 api
->flags
= stream_getl(s
);
1023 api
->message
= stream_getc(s
);
1024 api
->safi
= stream_getw(s
);
1027 api
->prefix
.family
= stream_getc(s
);
1028 switch (api
->prefix
.family
) {
1030 api
->prefix
.prefixlen
= MIN(IPV4_MAX_PREFIXLEN
, stream_getc(s
));
1033 api
->prefix
.prefixlen
= MIN(IPV6_MAX_PREFIXLEN
, stream_getc(s
));
1036 stream_get(&api
->prefix
.u
.prefix
, s
, PSIZE(api
->prefix
.prefixlen
));
1037 if (CHECK_FLAG(api
->message
, ZAPI_MESSAGE_SRCPFX
)) {
1038 api
->src_prefix
.family
= AF_INET6
;
1039 api
->src_prefix
.prefixlen
= stream_getc(s
);
1040 stream_get(&api
->src_prefix
.prefix
, s
,
1041 PSIZE(api
->src_prefix
.prefixlen
));
1043 if (api
->prefix
.family
!= AF_INET6
1044 || api
->src_prefix
.prefixlen
== 0)
1045 UNSET_FLAG(api
->message
, ZAPI_MESSAGE_SRCPFX
);
1049 if (CHECK_FLAG(api
->message
, ZAPI_MESSAGE_NEXTHOP
)) {
1050 api
->nexthop_num
= stream_getc(s
);
1051 if (api
->nexthop_num
> MULTIPATH_NUM
) {
1052 zlog_warn("%s: invalid number of nexthops (%u)",
1053 __func__
, api
->nexthop_num
);
1057 for (i
= 0; i
< api
->nexthop_num
; i
++) {
1058 api_nh
= &api
->nexthops
[i
];
1060 api_nh
->type
= stream_getc(s
);
1061 switch (api_nh
->type
) {
1062 case NEXTHOP_TYPE_BLACKHOLE
:
1064 case NEXTHOP_TYPE_IPV4
:
1065 api_nh
->gate
.ipv4
.s_addr
= stream_get_ipv4(s
);
1067 case NEXTHOP_TYPE_IPV4_IFINDEX
:
1068 api_nh
->gate
.ipv4
.s_addr
= stream_get_ipv4(s
);
1069 api_nh
->ifindex
= stream_getl(s
);
1071 case NEXTHOP_TYPE_IFINDEX
:
1072 api_nh
->ifindex
= stream_getl(s
);
1074 case NEXTHOP_TYPE_IPV6
:
1075 stream_get(&api_nh
->gate
.ipv6
, s
, 16);
1077 case NEXTHOP_TYPE_IPV6_IFINDEX
:
1078 stream_get(&api_nh
->gate
.ipv6
, s
, 16);
1079 api_nh
->ifindex
= stream_getl(s
);
1083 /* MPLS labels for BGP-LU or Segment Routing */
1084 if (CHECK_FLAG(api
->message
, ZAPI_MESSAGE_LABEL
)) {
1085 api_nh
->label_num
= stream_getc(s
);
1087 if (api_nh
->label_num
> MPLS_MAX_LABELS
) {
1089 "%s: invalid number of MPLS "
1091 __func__
, api_nh
->label_num
);
1095 stream_get(&api_nh
->labels
[0], s
,
1097 * sizeof(mpls_label_t
));
1103 if (CHECK_FLAG(api
->message
, ZAPI_MESSAGE_DISTANCE
))
1104 api
->distance
= stream_getc(s
);
1105 if (CHECK_FLAG(api
->message
, ZAPI_MESSAGE_METRIC
))
1106 api
->metric
= stream_getl(s
);
1107 if (CHECK_FLAG(api
->message
, ZAPI_MESSAGE_TAG
))
1108 api
->tag
= stream_getl(s
);
1109 if (CHECK_FLAG(api
->message
, ZAPI_MESSAGE_MTU
))
1110 api
->mtu
= stream_getl(s
);
1116 * send a ZEBRA_REDISTRIBUTE_ADD or ZEBRA_REDISTRIBUTE_DELETE
1117 * for the route type (ZEBRA_ROUTE_KERNEL etc.). The zebra server will
1118 * then set/unset redist[type] in the client handle (a struct zserv) for the
1121 int zebra_redistribute_send(int command
, struct zclient
*zclient
, afi_t afi
,
1122 int type
, u_short instance
, vrf_id_t vrf_id
)
1129 zclient_create_header(s
, command
, vrf_id
);
1130 stream_putc(s
, afi
);
1131 stream_putc(s
, type
);
1132 stream_putw(s
, instance
);
1134 stream_putw_at(s
, 0, stream_get_endp(s
));
1136 return zclient_send_message(zclient
);
1139 /* Get prefix in ZServ format; family should be filled in on prefix */
1140 static void zclient_stream_get_prefix(struct stream
*s
, struct prefix
*p
)
1142 size_t plen
= prefix_blen(p
);
1149 stream_get(&p
->u
.prefix
, s
, plen
);
1151 p
->prefixlen
= MIN(plen
* 8, c
);
1154 /* Router-id update from zebra daemon. */
1155 void zebra_router_id_update_read(struct stream
*s
, struct prefix
*rid
)
1157 /* Fetch interface address. */
1158 rid
->family
= stream_getc(s
);
1160 zclient_stream_get_prefix(s
, rid
);
1163 /* Interface addition from zebra daemon. */
1165 * The format of the message sent with type ZEBRA_INTERFACE_ADD or
1166 * ZEBRA_INTERFACE_DELETE from zebra to the client is:
1168 * 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
1169 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1175 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1177 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1179 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1182 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1184 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1186 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1188 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1190 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1192 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1193 * | Link Layer Type |
1194 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1195 * | Harware Address Length |
1196 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1197 * | Hardware Address if HW lenght different from 0 |
1198 * | ... max INTERFACE_HWADDR_MAX |
1199 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1200 * | Link_params? | Whether a link-params follows: 1 or 0.
1201 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1202 * | Link_params 0 or 1 INTERFACE_LINK_PARAMS_SIZE sized |
1203 * | .... (struct if_link_params). |
1204 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1207 static void zclient_vrf_add(struct zclient
*zclient
, vrf_id_t vrf_id
)
1210 char vrfname_tmp
[VRF_NAMSIZ
];
1211 struct vrf_data data
;
1213 stream_get(&data
, zclient
->ibuf
, sizeof(struct vrf_data
));
1214 /* Read interface name. */
1215 stream_get(vrfname_tmp
, zclient
->ibuf
, VRF_NAMSIZ
);
1217 /* Lookup/create vrf by vrf_id. */
1218 vrf
= vrf_get(vrf_id
, vrfname_tmp
);
1224 static void zclient_vrf_delete(struct zclient
*zclient
, vrf_id_t vrf_id
)
1228 /* Lookup vrf by vrf_id. */
1229 vrf
= vrf_lookup_by_id(vrf_id
);
1232 * If a routing protocol doesn't know about a
1233 * vrf that is about to be deleted. There is
1234 * no point in attempting to delete it.
1242 struct interface
*zebra_interface_add_read(struct stream
*s
, vrf_id_t vrf_id
)
1244 struct interface
*ifp
;
1245 char ifname_tmp
[INTERFACE_NAMSIZ
];
1247 /* Read interface name. */
1248 stream_get(ifname_tmp
, s
, INTERFACE_NAMSIZ
);
1250 /* Lookup/create interface by name. */
1251 ifp
= if_get_by_name_len(
1252 ifname_tmp
, strnlen(ifname_tmp
, INTERFACE_NAMSIZ
), vrf_id
, 0);
1254 zebra_interface_if_set_value(s
, ifp
);
1260 * Read interface up/down msg (ZEBRA_INTERFACE_UP/ZEBRA_INTERFACE_DOWN)
1261 * from zebra server. The format of this message is the same as
1262 * that sent for ZEBRA_INTERFACE_ADD/ZEBRA_INTERFACE_DELETE (see
1263 * comments for zebra_interface_add_read), except that no sockaddr_dl
1264 * is sent at the tail of the message.
1266 struct interface
*zebra_interface_state_read(struct stream
*s
, vrf_id_t vrf_id
)
1268 struct interface
*ifp
;
1269 char ifname_tmp
[INTERFACE_NAMSIZ
];
1271 /* Read interface name. */
1272 stream_get(ifname_tmp
, s
, INTERFACE_NAMSIZ
);
1274 /* Lookup this by interface index. */
1275 ifp
= if_lookup_by_name_len(
1276 ifname_tmp
, strnlen(ifname_tmp
, INTERFACE_NAMSIZ
), vrf_id
);
1278 zlog_warn("INTERFACE_STATE: Cannot find IF %s in VRF %d",
1279 ifname_tmp
, vrf_id
);
1283 zebra_interface_if_set_value(s
, ifp
);
1288 static void link_params_set_value(struct stream
*s
, struct if_link_params
*iflp
)
1294 iflp
->lp_status
= stream_getl(s
);
1295 iflp
->te_metric
= stream_getl(s
);
1296 iflp
->max_bw
= stream_getf(s
);
1297 iflp
->max_rsv_bw
= stream_getf(s
);
1298 uint32_t bwclassnum
= stream_getl(s
);
1301 for (i
= 0; i
< bwclassnum
&& i
< MAX_CLASS_TYPE
; i
++)
1302 iflp
->unrsv_bw
[i
] = stream_getf(s
);
1305 "%s: received %d > %d (MAX_CLASS_TYPE) bw entries"
1306 " - outdated library?",
1307 __func__
, bwclassnum
, MAX_CLASS_TYPE
);
1309 iflp
->admin_grp
= stream_getl(s
);
1310 iflp
->rmt_as
= stream_getl(s
);
1311 iflp
->rmt_ip
.s_addr
= stream_get_ipv4(s
);
1313 iflp
->av_delay
= stream_getl(s
);
1314 iflp
->min_delay
= stream_getl(s
);
1315 iflp
->max_delay
= stream_getl(s
);
1316 iflp
->delay_var
= stream_getl(s
);
1318 iflp
->pkt_loss
= stream_getf(s
);
1319 iflp
->res_bw
= stream_getf(s
);
1320 iflp
->ava_bw
= stream_getf(s
);
1321 iflp
->use_bw
= stream_getf(s
);
1324 struct interface
*zebra_interface_link_params_read(struct stream
*s
)
1326 struct if_link_params
*iflp
;
1331 ifindex
= stream_getl(s
);
1333 struct interface
*ifp
= if_lookup_by_index(ifindex
, VRF_DEFAULT
);
1336 zlog_err("%s: unknown ifindex %u, shouldn't happen", __func__
,
1341 if ((iflp
= if_link_params_get(ifp
)) == NULL
)
1344 link_params_set_value(s
, iflp
);
1349 void zebra_interface_if_set_value(struct stream
*s
, struct interface
*ifp
)
1351 u_char link_params_status
= 0;
1353 /* Read interface's index. */
1354 ifp
->ifindex
= stream_getl(s
);
1355 ifp
->status
= stream_getc(s
);
1357 /* Read interface's value. */
1358 ifp
->flags
= stream_getq(s
);
1359 ifp
->ptm_enable
= stream_getc(s
);
1360 ifp
->ptm_status
= stream_getc(s
);
1361 ifp
->metric
= stream_getl(s
);
1362 ifp
->speed
= stream_getl(s
);
1363 ifp
->mtu
= stream_getl(s
);
1364 ifp
->mtu6
= stream_getl(s
);
1365 ifp
->bandwidth
= stream_getl(s
);
1366 ifp
->ll_type
= stream_getl(s
);
1367 ifp
->hw_addr_len
= stream_getl(s
);
1368 if (ifp
->hw_addr_len
)
1369 stream_get(ifp
->hw_addr
, s
,
1370 MIN(ifp
->hw_addr_len
, INTERFACE_HWADDR_MAX
));
1372 /* Read Traffic Engineering status */
1373 link_params_status
= stream_getc(s
);
1374 /* Then, Traffic Engineering parameters if any */
1375 if (link_params_status
) {
1376 struct if_link_params
*iflp
= if_link_params_get(ifp
);
1377 link_params_set_value(s
, iflp
);
1381 size_t zebra_interface_link_params_write(struct stream
*s
,
1382 struct interface
*ifp
)
1385 struct if_link_params
*iflp
;
1388 if (s
== NULL
|| ifp
== NULL
|| ifp
->link_params
== NULL
)
1391 iflp
= ifp
->link_params
;
1394 w
+= stream_putl(s
, iflp
->lp_status
);
1396 w
+= stream_putl(s
, iflp
->te_metric
);
1397 w
+= stream_putf(s
, iflp
->max_bw
);
1398 w
+= stream_putf(s
, iflp
->max_rsv_bw
);
1400 w
+= stream_putl(s
, MAX_CLASS_TYPE
);
1401 for (i
= 0; i
< MAX_CLASS_TYPE
; i
++)
1402 w
+= stream_putf(s
, iflp
->unrsv_bw
[i
]);
1404 w
+= stream_putl(s
, iflp
->admin_grp
);
1405 w
+= stream_putl(s
, iflp
->rmt_as
);
1406 w
+= stream_put_in_addr(s
, &iflp
->rmt_ip
);
1408 w
+= stream_putl(s
, iflp
->av_delay
);
1409 w
+= stream_putl(s
, iflp
->min_delay
);
1410 w
+= stream_putl(s
, iflp
->max_delay
);
1411 w
+= stream_putl(s
, iflp
->delay_var
);
1413 w
+= stream_putf(s
, iflp
->pkt_loss
);
1414 w
+= stream_putf(s
, iflp
->res_bw
);
1415 w
+= stream_putf(s
, iflp
->ava_bw
);
1416 w
+= stream_putf(s
, iflp
->use_bw
);
1422 * format of message for address additon is:
1426 * | type | ZEBRA_INTERFACE_ADDRESS_ADD or
1427 * +-+-+-+-+-+-+-+-+ ZEBRA_INTERFACE_ADDRES_DELETE
1436 * | ifc_flags | flags for connected address
1444 * | addr_len | len of addr. E.g., addr_len = 4 for ipv4 addrs.
1452 static int memconstant(const void *s
, int c
, size_t n
)
1454 const u_char
*p
= s
;
1463 struct connected
*zebra_interface_address_read(int type
, struct stream
*s
,
1467 struct interface
*ifp
;
1468 struct connected
*ifc
;
1469 struct prefix p
, d
, *dp
;
1473 memset(&p
, 0, sizeof(p
));
1474 memset(&d
, 0, sizeof(d
));
1476 /* Get interface index. */
1477 ifindex
= stream_getl(s
);
1480 ifp
= if_lookup_by_index(ifindex
, vrf_id
);
1482 zlog_warn("INTERFACE_ADDRESS_%s: Cannot find IF %u in VRF %d",
1483 (type
== ZEBRA_INTERFACE_ADDRESS_ADD
) ? "ADD" : "DEL",
1489 ifc_flags
= stream_getc(s
);
1491 /* Fetch interface address. */
1492 d
.family
= p
.family
= stream_getc(s
);
1493 plen
= prefix_blen(&d
);
1495 zclient_stream_get_prefix(s
, &p
);
1497 /* Fetch destination address. */
1498 stream_get(&d
.u
.prefix
, s
, plen
);
1500 /* N.B. NULL destination pointers are encoded as all zeroes */
1501 dp
= memconstant(&d
.u
.prefix
, 0, plen
) ? NULL
: &d
;
1503 if (type
== ZEBRA_INTERFACE_ADDRESS_ADD
) {
1504 ifc
= connected_lookup_prefix_exact(ifp
, &p
);
1506 /* N.B. NULL destination pointers are encoded as all
1508 ifc
= connected_add_by_prefix(ifp
, &p
, dp
);
1511 ifc
->flags
= ifc_flags
;
1512 if (ifc
->destination
)
1513 ifc
->destination
->prefixlen
=
1514 ifc
->address
->prefixlen
;
1515 else if (CHECK_FLAG(ifc
->flags
, ZEBRA_IFA_PEER
)) {
1516 /* carp interfaces on OpenBSD with 0.0.0.0/0 as
1518 char buf
[PREFIX_STRLEN
];
1520 "warning: interface %s address %s "
1521 "with peer flag set, but no peer address!",
1522 ifp
->name
, prefix2str(ifc
->address
, buf
,
1524 UNSET_FLAG(ifc
->flags
, ZEBRA_IFA_PEER
);
1528 assert(type
== ZEBRA_INTERFACE_ADDRESS_DELETE
);
1529 ifc
= connected_delete_by_prefix(ifp
, &p
);
1536 * format of message for neighbor connected address is:
1540 * | type | ZEBRA_INTERFACE_NBR_ADDRESS_ADD or
1541 * +-+-+-+-+-+-+-+-+ ZEBRA_INTERFACE_NBR_ADDRES_DELETE
1556 * | addr_len | len of addr.
1559 struct nbr_connected
*
1560 zebra_interface_nbr_address_read(int type
, struct stream
*s
, vrf_id_t vrf_id
)
1562 unsigned int ifindex
;
1563 struct interface
*ifp
;
1565 struct nbr_connected
*ifc
;
1567 /* Get interface index. */
1568 ifindex
= stream_getl(s
);
1571 ifp
= if_lookup_by_index(ifindex
, vrf_id
);
1573 zlog_warn("INTERFACE_NBR_%s: Cannot find IF %u in VRF %d",
1574 (type
== ZEBRA_INTERFACE_NBR_ADDRESS_ADD
) ? "ADD"
1580 p
.family
= stream_getc(s
);
1581 stream_get(&p
.u
.prefix
, s
, prefix_blen(&p
));
1582 p
.prefixlen
= stream_getc(s
);
1584 if (type
== ZEBRA_INTERFACE_NBR_ADDRESS_ADD
) {
1585 /* Currently only supporting P2P links, so any new RA source
1587 considered as the replacement of the previously learnt
1588 Link-Local address. */
1589 if (!(ifc
= listnode_head(ifp
->nbr_connected
))) {
1590 ifc
= nbr_connected_new();
1591 ifc
->address
= prefix_new();
1593 listnode_add(ifp
->nbr_connected
, ifc
);
1596 prefix_copy(ifc
->address
, &p
);
1598 assert(type
== ZEBRA_INTERFACE_NBR_ADDRESS_DELETE
);
1600 ifc
= nbr_connected_check(ifp
, &p
);
1602 listnode_delete(ifp
->nbr_connected
, ifc
);
1608 struct interface
*zebra_interface_vrf_update_read(struct stream
*s
,
1610 vrf_id_t
*new_vrf_id
)
1612 unsigned int ifindex
;
1613 struct interface
*ifp
;
1614 vrf_id_t new_id
= VRF_DEFAULT
;
1616 /* Get interface index. */
1617 ifindex
= stream_getl(s
);
1619 /* Lookup interface. */
1620 ifp
= if_lookup_by_index(ifindex
, vrf_id
);
1622 zlog_warn("INTERFACE_VRF_UPDATE: Cannot find IF %u in VRF %d",
1627 /* Fetch new VRF Id. */
1628 new_id
= stream_getw(s
);
1630 *new_vrf_id
= new_id
;
1634 /* filter unwanted messages until the expected one arrives */
1635 static int zclient_read_sync_response(struct zclient
*zclient
,
1636 u_int16_t expected_cmd
)
1648 cmd
= expected_cmd
+ 1;
1649 while (ret
== 0 && cmd
!= expected_cmd
) {
1653 /* wait until response arrives */
1655 FD_SET(zclient
->sock
, &readfds
);
1656 select(zclient
->sock
+ 1, &readfds
, NULL
, NULL
, NULL
);
1657 if (!FD_ISSET(zclient
->sock
, &readfds
))
1660 ret
= zclient_read_header(s
, zclient
->sock
, &size
, &marker
,
1661 &version
, &vrf_id
, &cmd
);
1663 zlog_debug("%s: Response (%d bytes) received", __func__
,
1667 zlog_err("%s: Invalid Sync Message Reply", __func__
);
1674 * Connect to label manager in a syncronous way
1676 * It first writes the request to zcient output buffer and then
1677 * immediately reads the answer from the input buffer.
1679 * @param zclient Zclient used to connect to label manager (zebra)
1680 * @result Result of response
1682 int lm_label_manager_connect(struct zclient
*zclient
)
1689 zlog_debug("Connecting to Label Manager");
1691 if (zclient
->sock
< 0)
1697 zclient_create_header(s
, ZEBRA_LABEL_MANAGER_CONNECT
, VRF_DEFAULT
);
1700 stream_putc(s
, zclient
->redist_default
);
1702 stream_putw(s
, zclient
->instance
);
1704 /* Put length at the first point of the stream. */
1705 stream_putw_at(s
, 0, stream_get_endp(s
));
1707 ret
= writen(zclient
->sock
, s
->data
, stream_get_endp(s
));
1709 zlog_err("%s: can't write to zclient->sock", __func__
);
1710 close(zclient
->sock
);
1715 zlog_err("%s: zclient->sock connection closed", __func__
);
1716 close(zclient
->sock
);
1721 zlog_debug("%s: Label manager connect request (%d bytes) sent",
1725 if (zclient_read_sync_response(zclient
, ZEBRA_LABEL_MANAGER_CONNECT
)
1731 result
= stream_getc(s
);
1734 "%s: Label Manager connect response received, result %u",
1741 * Function to request a label chunk in a syncronous way
1743 * It first writes the request to zlcient output buffer and then
1744 * immediately reads the answer from the input buffer.
1746 * @param zclient Zclient used to connect to label manager (zebra)
1747 * @param keep Avoid garbage collection
1748 * @param chunk_size Amount of labels requested
1749 * @param start To write first assigned chunk label to
1750 * @param end To write last assigned chunk label to
1751 * @result 0 on success, -1 otherwise
1753 int lm_get_label_chunk(struct zclient
*zclient
, u_char keep
,
1754 uint32_t chunk_size
, uint32_t *start
, uint32_t *end
)
1758 u_char response_keep
;
1761 zlog_debug("Getting Label Chunk");
1763 if (zclient
->sock
< 0)
1769 zclient_create_header(s
, ZEBRA_GET_LABEL_CHUNK
, VRF_DEFAULT
);
1771 stream_putc(s
, keep
);
1773 stream_putl(s
, chunk_size
);
1774 /* Put length at the first point of the stream. */
1775 stream_putw_at(s
, 0, stream_get_endp(s
));
1777 ret
= writen(zclient
->sock
, s
->data
, stream_get_endp(s
));
1779 zlog_err("%s: can't write to zclient->sock", __func__
);
1780 close(zclient
->sock
);
1785 zlog_err("%s: zclient->sock connection closed", __func__
);
1786 close(zclient
->sock
);
1791 zlog_debug("%s: Label chunk request (%d bytes) sent", __func__
,
1795 if (zclient_read_sync_response(zclient
, ZEBRA_GET_LABEL_CHUNK
) != 0)
1800 response_keep
= stream_getc(s
);
1801 /* start and end labels */
1802 *start
= stream_getl(s
);
1803 *end
= stream_getl(s
);
1805 /* not owning this response */
1806 if (keep
!= response_keep
) {
1808 "%s: Invalid Label chunk: %u - %u, keeps mismatch %u != %u",
1809 __func__
, *start
, *end
, keep
, response_keep
);
1812 if (*start
> *end
|| *start
< MPLS_MIN_UNRESERVED_LABEL
1813 || *end
> MPLS_MAX_UNRESERVED_LABEL
) {
1814 zlog_err("%s: Invalid Label chunk: %u - %u", __func__
, *start
,
1820 zlog_debug("Label Chunk assign: %u - %u (%u) ", *start
, *end
,
1827 * Function to release a label chunk
1829 * @param zclient Zclient used to connect to label manager (zebra)
1830 * @param start First label of chunk
1831 * @param end Last label of chunk
1832 * @result 0 on success, -1 otherwise
1834 int lm_release_label_chunk(struct zclient
*zclient
, uint32_t start
,
1841 zlog_debug("Releasing Label Chunk");
1843 if (zclient
->sock
< 0)
1849 zclient_create_header(s
, ZEBRA_RELEASE_LABEL_CHUNK
, VRF_DEFAULT
);
1852 stream_putl(s
, start
);
1854 stream_putl(s
, end
);
1856 /* Put length at the first point of the stream. */
1857 stream_putw_at(s
, 0, stream_get_endp(s
));
1859 ret
= writen(zclient
->sock
, s
->data
, stream_get_endp(s
));
1861 zlog_err("%s: can't write to zclient->sock", __func__
);
1862 close(zclient
->sock
);
1867 zlog_err("%s: zclient->sock connection closed", __func__
);
1868 close(zclient
->sock
);
1876 int zebra_send_pw(struct zclient
*zclient
, int command
, struct zapi_pw
*pw
)
1884 zclient_create_header(s
, command
, VRF_DEFAULT
);
1885 stream_write(s
, pw
->ifname
, IF_NAMESIZE
);
1886 stream_putl(s
, pw
->ifindex
);
1889 stream_putl(s
, pw
->type
);
1892 stream_putl(s
, pw
->af
);
1895 stream_put_in_addr(s
, &pw
->nexthop
.ipv4
);
1898 stream_write(s
, (u_char
*)&pw
->nexthop
.ipv6
, 16);
1901 zlog_err("%s: unknown af", __func__
);
1906 stream_putl(s
, pw
->local_label
);
1907 stream_putl(s
, pw
->remote_label
);
1910 stream_putc(s
, pw
->flags
);
1912 /* Protocol specific fields */
1913 stream_write(s
, &pw
->data
, sizeof(union pw_protocol_fields
));
1915 /* Put length at the first point of the stream. */
1916 stream_putw_at(s
, 0, stream_get_endp(s
));
1918 return zclient_send_message(zclient
);
1922 * Receive PW status update from Zebra and send it to LDE process.
1924 void zebra_read_pw_status_update(int command
, struct zclient
*zclient
,
1925 zebra_size_t length
, vrf_id_t vrf_id
,
1926 struct zapi_pw_status
*pw
)
1930 memset(pw
, 0, sizeof(struct zapi_pw_status
));
1934 stream_get(pw
->ifname
, s
, IF_NAMESIZE
);
1935 pw
->ifindex
= stream_getl(s
);
1936 pw
->status
= stream_getl(s
);
1939 /* Zebra client message read function. */
1940 static int zclient_read(struct thread
*thread
)
1943 uint16_t length
, command
;
1944 uint8_t marker
, version
;
1946 struct zclient
*zclient
;
1948 /* Get socket to zebra. */
1949 zclient
= THREAD_ARG(thread
);
1950 zclient
->t_read
= NULL
;
1952 /* Read zebra header (if we don't have it already). */
1953 if ((already
= stream_get_endp(zclient
->ibuf
)) < ZEBRA_HEADER_SIZE
) {
1955 if (((nbyte
= stream_read_try(zclient
->ibuf
, zclient
->sock
,
1956 ZEBRA_HEADER_SIZE
- already
))
1961 "zclient connection closed socket [%d].",
1963 return zclient_failed(zclient
);
1965 if (nbyte
!= (ssize_t
)(ZEBRA_HEADER_SIZE
- already
)) {
1966 /* Try again later. */
1967 zclient_event(ZCLIENT_READ
, zclient
);
1970 already
= ZEBRA_HEADER_SIZE
;
1973 /* Reset to read from the beginning of the incoming packet. */
1974 stream_set_getp(zclient
->ibuf
, 0);
1976 /* Fetch header values. */
1977 length
= stream_getw(zclient
->ibuf
);
1978 marker
= stream_getc(zclient
->ibuf
);
1979 version
= stream_getc(zclient
->ibuf
);
1980 vrf_id
= stream_getw(zclient
->ibuf
);
1981 command
= stream_getw(zclient
->ibuf
);
1983 if (marker
!= ZEBRA_HEADER_MARKER
|| version
!= ZSERV_VERSION
) {
1985 "%s: socket %d version mismatch, marker %d, version %d",
1986 __func__
, zclient
->sock
, marker
, version
);
1987 return zclient_failed(zclient
);
1990 if (length
< ZEBRA_HEADER_SIZE
) {
1991 zlog_err("%s: socket %d message length %u is less than %d ",
1992 __func__
, zclient
->sock
, length
, ZEBRA_HEADER_SIZE
);
1993 return zclient_failed(zclient
);
1997 if (length
> STREAM_SIZE(zclient
->ibuf
)) {
2000 "%s: message size %u exceeds buffer size %lu, expanding...",
2001 __func__
, length
, (u_long
)STREAM_SIZE(zclient
->ibuf
));
2002 ns
= stream_new(length
);
2003 stream_copy(ns
, zclient
->ibuf
);
2004 stream_free(zclient
->ibuf
);
2008 /* Read rest of zebra packet. */
2009 if (already
< length
) {
2011 if (((nbyte
= stream_read_try(zclient
->ibuf
, zclient
->sock
,
2017 "zclient connection closed socket [%d].",
2019 return zclient_failed(zclient
);
2021 if (nbyte
!= (ssize_t
)(length
- already
)) {
2022 /* Try again later. */
2023 zclient_event(ZCLIENT_READ
, zclient
);
2028 length
-= ZEBRA_HEADER_SIZE
;
2031 zlog_debug("zclient 0x%p command 0x%x VRF %u\n",
2032 (void *)zclient
, command
, vrf_id
);
2035 case ZEBRA_ROUTER_ID_UPDATE
:
2036 if (zclient
->router_id_update
)
2037 (*zclient
->router_id_update
)(command
, zclient
, length
,
2041 zclient_vrf_add(zclient
, vrf_id
);
2043 case ZEBRA_VRF_DELETE
:
2044 zclient_vrf_delete(zclient
, vrf_id
);
2046 case ZEBRA_INTERFACE_ADD
:
2047 if (zclient
->interface_add
)
2048 (*zclient
->interface_add
)(command
, zclient
, length
,
2051 case ZEBRA_INTERFACE_DELETE
:
2052 if (zclient
->interface_delete
)
2053 (*zclient
->interface_delete
)(command
, zclient
, length
,
2056 case ZEBRA_INTERFACE_ADDRESS_ADD
:
2057 if (zclient
->interface_address_add
)
2058 (*zclient
->interface_address_add
)(command
, zclient
,
2061 case ZEBRA_INTERFACE_ADDRESS_DELETE
:
2062 if (zclient
->interface_address_delete
)
2063 (*zclient
->interface_address_delete
)(command
, zclient
,
2066 case ZEBRA_INTERFACE_BFD_DEST_UPDATE
:
2067 if (zclient
->interface_bfd_dest_update
)
2068 (*zclient
->interface_bfd_dest_update
)(command
, zclient
,
2071 case ZEBRA_INTERFACE_NBR_ADDRESS_ADD
:
2072 if (zclient
->interface_nbr_address_add
)
2073 (*zclient
->interface_nbr_address_add
)(command
, zclient
,
2076 case ZEBRA_INTERFACE_NBR_ADDRESS_DELETE
:
2077 if (zclient
->interface_nbr_address_delete
)
2078 (*zclient
->interface_nbr_address_delete
)(
2079 command
, zclient
, length
, vrf_id
);
2081 case ZEBRA_INTERFACE_UP
:
2082 if (zclient
->interface_up
)
2083 (*zclient
->interface_up
)(command
, zclient
, length
,
2086 case ZEBRA_INTERFACE_DOWN
:
2087 if (zclient
->interface_down
)
2088 (*zclient
->interface_down
)(command
, zclient
, length
,
2091 case ZEBRA_INTERFACE_VRF_UPDATE
:
2092 if (zclient
->interface_vrf_update
)
2093 (*zclient
->interface_vrf_update
)(command
, zclient
,
2096 case ZEBRA_NEXTHOP_UPDATE
:
2098 zlog_debug("zclient rcvd nexthop update\n");
2099 if (zclient
->nexthop_update
)
2100 (*zclient
->nexthop_update
)(command
, zclient
, length
,
2103 case ZEBRA_IMPORT_CHECK_UPDATE
:
2105 zlog_debug("zclient rcvd import check update\n");
2106 if (zclient
->import_check_update
)
2107 (*zclient
->import_check_update
)(command
, zclient
,
2110 case ZEBRA_BFD_DEST_REPLAY
:
2111 if (zclient
->bfd_dest_replay
)
2112 (*zclient
->bfd_dest_replay
)(command
, zclient
, length
,
2115 case ZEBRA_REDISTRIBUTE_IPV4_ADD
:
2116 if (zclient
->redistribute_route_ipv4_add
)
2117 (*zclient
->redistribute_route_ipv4_add
)(
2118 command
, zclient
, length
, vrf_id
);
2120 case ZEBRA_REDISTRIBUTE_IPV4_DEL
:
2121 if (zclient
->redistribute_route_ipv4_del
)
2122 (*zclient
->redistribute_route_ipv4_del
)(
2123 command
, zclient
, length
, vrf_id
);
2125 case ZEBRA_REDISTRIBUTE_IPV6_ADD
:
2126 if (zclient
->redistribute_route_ipv6_add
)
2127 (*zclient
->redistribute_route_ipv6_add
)(
2128 command
, zclient
, length
, vrf_id
);
2130 case ZEBRA_REDISTRIBUTE_IPV6_DEL
:
2131 if (zclient
->redistribute_route_ipv6_del
)
2132 (*zclient
->redistribute_route_ipv6_del
)(
2133 command
, zclient
, length
, vrf_id
);
2135 case ZEBRA_INTERFACE_LINK_PARAMS
:
2136 if (zclient
->interface_link_params
)
2137 (*zclient
->interface_link_params
)(command
, zclient
,
2140 case ZEBRA_FEC_UPDATE
:
2142 zlog_debug("zclient rcvd fec update\n");
2143 if (zclient
->fec_update
)
2144 (*zclient
->fec_update
)(command
, zclient
, length
);
2147 if (zclient
->local_vni_add
)
2148 (*zclient
->local_vni_add
)(command
, zclient
, length
,
2152 if (zclient
->local_vni_del
)
2153 (*zclient
->local_vni_del
)(command
, zclient
, length
,
2156 case ZEBRA_MACIP_ADD
:
2157 if (zclient
->local_macip_add
)
2158 (*zclient
->local_macip_add
)(command
, zclient
, length
,
2161 case ZEBRA_MACIP_DEL
:
2162 if (zclient
->local_macip_del
)
2163 (*zclient
->local_macip_del
)(command
, zclient
, length
,
2166 case ZEBRA_PW_STATUS_UPDATE
:
2167 if (zclient
->pw_status_update
)
2168 (*zclient
->pw_status_update
)(command
, zclient
, length
,
2175 if (zclient
->sock
< 0)
2176 /* Connection was closed during packet processing. */
2179 /* Register read thread. */
2180 stream_reset(zclient
->ibuf
);
2181 zclient_event(ZCLIENT_READ
, zclient
);
2186 void zclient_redistribute(int command
, struct zclient
*zclient
, afi_t afi
,
2187 int type
, u_short instance
, vrf_id_t vrf_id
)
2191 if (command
== ZEBRA_REDISTRIBUTE_ADD
) {
2192 if (redist_check_instance(
2193 &zclient
->mi_redist
[afi
][type
], instance
))
2195 redist_add_instance(&zclient
->mi_redist
[afi
][type
],
2198 if (!redist_check_instance(
2199 &zclient
->mi_redist
[afi
][type
], instance
))
2201 redist_del_instance(&zclient
->mi_redist
[afi
][type
],
2206 if (command
== ZEBRA_REDISTRIBUTE_ADD
) {
2207 if (vrf_bitmap_check(zclient
->redist
[afi
][type
],
2210 vrf_bitmap_set(zclient
->redist
[afi
][type
], vrf_id
);
2212 if (!vrf_bitmap_check(zclient
->redist
[afi
][type
],
2215 vrf_bitmap_unset(zclient
->redist
[afi
][type
], vrf_id
);
2219 if (zclient
->sock
> 0)
2220 zebra_redistribute_send(command
, zclient
, afi
, type
, instance
,
2225 void zclient_redistribute_default(int command
, struct zclient
*zclient
,
2229 if (command
== ZEBRA_REDISTRIBUTE_DEFAULT_ADD
) {
2230 if (vrf_bitmap_check(zclient
->default_information
, vrf_id
))
2232 vrf_bitmap_set(zclient
->default_information
, vrf_id
);
2234 if (!vrf_bitmap_check(zclient
->default_information
, vrf_id
))
2236 vrf_bitmap_unset(zclient
->default_information
, vrf_id
);
2239 if (zclient
->sock
> 0)
2240 zebra_message_send(zclient
, command
, vrf_id
);
2243 static void zclient_event(enum event event
, struct zclient
*zclient
)
2246 case ZCLIENT_SCHEDULE
:
2247 thread_add_event(zclient
->master
, zclient_connect
, zclient
, 0,
2248 &zclient
->t_connect
);
2250 case ZCLIENT_CONNECT
:
2253 "zclient connect failures: %d schedule interval is now %d",
2254 zclient
->fail
, zclient
->fail
< 3 ? 10 : 60);
2255 thread_add_timer(zclient
->master
, zclient_connect
, zclient
,
2256 zclient
->fail
< 3 ? 10 : 60,
2257 &zclient
->t_connect
);
2260 zclient
->t_read
= NULL
;
2261 thread_add_read(zclient
->master
, zclient_read
, zclient
,
2262 zclient
->sock
, &zclient
->t_read
);
2267 void zclient_interface_set_master(struct zclient
*client
,
2268 struct interface
*master
,
2269 struct interface
*slave
)
2276 zclient_create_header(s
, ZEBRA_INTERFACE_SET_MASTER
, master
->vrf_id
);
2278 stream_putw(s
, master
->vrf_id
);
2279 stream_putl(s
, master
->ifindex
);
2280 stream_putw(s
, slave
->vrf_id
);
2281 stream_putl(s
, slave
->ifindex
);
2283 stream_putw_at(s
, 0, stream_get_endp(s
));
2284 zclient_send_message(client
);