1 /* Zebra daemon server routine.
2 * Copyright (C) 1997, 98, 99 Kunihiro Ishiguro
4 * This file is part of GNU Zebra.
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GNU Zebra; see the file COPYING. If not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
33 #include "sockunion.h"
41 #include "zebra/zserv.h"
42 #include "zebra/router-id.h"
43 #include "zebra/redistribute.h"
44 #include "zebra/debug.h"
45 #include "zebra/ipforward.h"
46 #include "zebra/zebra_rnh.h"
48 /* Event list of zebra. */
49 enum event
{ ZEBRA_SERV
, ZEBRA_READ
, ZEBRA_WRITE
};
51 extern struct zebra_t zebrad
;
53 static void zebra_event (enum event event
, int sock
, struct zserv
*client
);
55 extern struct zebra_privs_t zserv_privs
;
57 static void zebra_client_close (struct zserv
*client
);
60 zserv_delayed_close(struct thread
*thread
)
62 struct zserv
*client
= THREAD_ARG(thread
);
64 client
->t_suicide
= NULL
;
65 zebra_client_close(client
);
70 zserv_flush_data(struct thread
*thread
)
72 struct zserv
*client
= THREAD_ARG(thread
);
74 client
->t_write
= NULL
;
75 if (client
->t_suicide
)
77 zebra_client_close(client
);
80 switch (buffer_flush_available(client
->wb
, client
->sock
))
83 zlog_warn("%s: buffer_flush_available failed on zserv client fd %d, "
84 "closing", __func__
, client
->sock
);
85 zebra_client_close(client
);
88 client
->t_write
= thread_add_write(zebrad
.master
, zserv_flush_data
,
89 client
, client
->sock
);
95 client
->last_write_time
= quagga_time(NULL
);
100 zebra_server_send_message(struct zserv
*client
)
102 if (client
->t_suicide
)
105 stream_set_getp(client
->obuf
, 0);
106 client
->last_write_cmd
= stream_getw_from(client
->obuf
, 4);
107 switch (buffer_write(client
->wb
, client
->sock
, STREAM_DATA(client
->obuf
),
108 stream_get_endp(client
->obuf
)))
111 zlog_warn("%s: buffer_write failed to zserv client fd %d, closing",
112 __func__
, client
->sock
);
113 /* Schedule a delayed close since many of the functions that call this
114 one do not check the return code. They do not allow for the
115 possibility that an I/O error may have caused the client to be
117 client
->t_suicide
= thread_add_event(zebrad
.master
, zserv_delayed_close
,
121 THREAD_OFF(client
->t_write
);
124 THREAD_WRITE_ON(zebrad
.master
, client
->t_write
,
125 zserv_flush_data
, client
, client
->sock
);
129 client
->last_write_time
= quagga_time(NULL
);
134 zserv_create_header (struct stream
*s
, uint16_t cmd
)
136 /* length placeholder, caller can update */
137 stream_putw (s
, ZEBRA_HEADER_SIZE
);
138 stream_putc (s
, ZEBRA_HEADER_MARKER
);
139 stream_putc (s
, ZSERV_VERSION
);
140 stream_putw (s
, cmd
);
144 zserv_encode_interface (struct stream
*s
, struct interface
*ifp
)
146 /* Interface information. */
147 stream_put (s
, ifp
->name
, INTERFACE_NAMSIZ
);
148 stream_putl (s
, ifp
->ifindex
);
149 stream_putc (s
, ifp
->status
);
150 stream_putq (s
, ifp
->flags
);
151 stream_putc (s
, ifp
->ptm_enable
);
152 stream_putc (s
, ifp
->ptm_status
);
153 stream_putl (s
, ifp
->metric
);
154 stream_putl (s
, ifp
->mtu
);
155 stream_putl (s
, ifp
->mtu6
);
156 stream_putl (s
, ifp
->bandwidth
);
157 #ifdef HAVE_STRUCT_SOCKADDR_DL
158 stream_put (s
, &ifp
->sdl
, sizeof (ifp
->sdl_storage
));
160 stream_putl (s
, ifp
->hw_addr_len
);
161 if (ifp
->hw_addr_len
)
162 stream_put (s
, ifp
->hw_addr
, ifp
->hw_addr_len
);
163 #endif /* HAVE_STRUCT_SOCKADDR_DL */
165 /* Write packet size. */
166 stream_putw_at (s
, 0, stream_get_endp (s
));
169 /* Interface is added. Send ZEBRA_INTERFACE_ADD to client. */
171 * This function is called in the following situations:
172 * - in response to a 3-byte ZEBRA_INTERFACE_ADD request
174 * - at startup, when zebra figures out the available interfaces
175 * - when an interface is added (where support for
176 * RTM_IFANNOUNCE or AF_NETLINK sockets is available), or when
177 * an interface is marked IFF_UP (i.e., an RTM_IFINFO message is
181 zsend_interface_add (struct zserv
*client
, struct interface
*ifp
)
185 /* Check this client need interface information. */
186 if (! client
->ifinfo
)
192 zserv_create_header (s
, ZEBRA_INTERFACE_ADD
);
193 zserv_encode_interface (s
, ifp
);
196 return zebra_server_send_message(client
);
199 /* Interface deletion from zebra daemon. */
201 zsend_interface_delete (struct zserv
*client
, struct interface
*ifp
)
205 /* Check this client need interface information. */
206 if (! client
->ifinfo
)
212 zserv_create_header (s
, ZEBRA_INTERFACE_DELETE
);
213 zserv_encode_interface (s
, ifp
);
216 return zebra_server_send_message (client
);
219 /* Interface address is added/deleted. Send ZEBRA_INTERFACE_ADDRESS_ADD or
220 * ZEBRA_INTERFACE_ADDRESS_DELETE to the client.
222 * A ZEBRA_INTERFACE_ADDRESS_ADD is sent in the following situations:
223 * - in response to a 3-byte ZEBRA_INTERFACE_ADD request
224 * from the client, after the ZEBRA_INTERFACE_ADD has been
225 * sent from zebra to the client
226 * - redistribute new address info to all clients in the following situations
227 * - at startup, when zebra figures out the available interfaces
228 * - when an interface is added (where support for
229 * RTM_IFANNOUNCE or AF_NETLINK sockets is available), or when
230 * an interface is marked IFF_UP (i.e., an RTM_IFINFO message is
232 * - for the vty commands "ip address A.B.C.D/M [<secondary>|<label LINE>]"
233 * and "no bandwidth <1-10000000>", "ipv6 address X:X::X:X/M"
234 * - when an RTM_NEWADDR message is received from the kernel,
236 * The call tree that triggers ZEBRA_INTERFACE_ADDRESS_DELETE:
238 * zsend_interface_address(DELETE)
241 * zebra_interface_address_delete_update
243 * | | if_delete_update
245 * ip_address_uninstall connected_delete_ipv4
246 * [ipv6_addresss_uninstall] [connected_delete_ipv6]
249 * | RTM_NEWADDR on routing/netlink socket
252 * "no ip address A.B.C.D/M [label LINE]"
253 * "no ip address A.B.C.D/M secondary"
254 * ["no ipv6 address X:X::X:X/M"]
258 zsend_interface_address (int cmd
, struct zserv
*client
,
259 struct interface
*ifp
, struct connected
*ifc
)
265 /* Check this client need interface information. */
266 if (! client
->ifinfo
)
272 zserv_create_header (s
, cmd
);
273 stream_putl (s
, ifp
->ifindex
);
275 /* Interface address flag. */
276 stream_putc (s
, ifc
->flags
);
278 /* Prefix information. */
280 stream_putc (s
, p
->family
);
281 blen
= prefix_blen (p
);
282 stream_put (s
, &p
->u
.prefix
, blen
);
285 * XXX gnu version does not send prefixlen for ZEBRA_INTERFACE_ADDRESS_DELETE
286 * but zebra_interface_address_delete_read() in the gnu version
289 stream_putc (s
, p
->prefixlen
);
292 p
= ifc
->destination
;
294 stream_put (s
, &p
->u
.prefix
, blen
);
296 stream_put (s
, NULL
, blen
);
298 /* Write packet size. */
299 stream_putw_at (s
, 0, stream_get_endp (s
));
301 client
->connected_rt_add_cnt
++;
302 return zebra_server_send_message(client
);
306 zsend_interface_nbr_address (int cmd
, struct zserv
*client
,
307 struct interface
*ifp
, struct nbr_connected
*ifc
)
313 /* Check this client need interface information. */
314 if (! client
->ifinfo
)
320 zserv_create_header (s
, cmd
);
321 stream_putl (s
, ifp
->ifindex
);
323 /* Prefix information. */
325 stream_putc (s
, p
->family
);
326 blen
= prefix_blen (p
);
327 stream_put (s
, &p
->u
.prefix
, blen
);
330 * XXX gnu version does not send prefixlen for ZEBRA_INTERFACE_ADDRESS_DELETE
331 * but zebra_interface_address_delete_read() in the gnu version
334 stream_putc (s
, p
->prefixlen
);
336 /* Write packet size. */
337 stream_putw_at (s
, 0, stream_get_endp (s
));
339 return zebra_server_send_message(client
);
342 /* Interface address addition. */
344 zebra_interface_nbr_address_add_update (struct interface
*ifp
,
345 struct nbr_connected
*ifc
)
347 struct listnode
*node
, *nnode
;
348 struct zserv
*client
;
351 if (IS_ZEBRA_DEBUG_EVENT
)
353 char buf
[INET6_ADDRSTRLEN
];
356 zlog_debug ("MESSAGE: ZEBRA_INTERFACE_NBR_ADDRESS_ADD %s/%d on %s",
357 inet_ntop (p
->family
, &p
->u
.prefix
, buf
, INET6_ADDRSTRLEN
),
358 p
->prefixlen
, ifc
->ifp
->name
);
361 for (ALL_LIST_ELEMENTS (zebrad
.client_list
, node
, nnode
, client
))
363 zsend_interface_nbr_address (ZEBRA_INTERFACE_NBR_ADDRESS_ADD
, client
, ifp
, ifc
);
366 /* Interface address deletion. */
368 zebra_interface_nbr_address_delete_update (struct interface
*ifp
,
369 struct nbr_connected
*ifc
)
371 struct listnode
*node
, *nnode
;
372 struct zserv
*client
;
375 if (IS_ZEBRA_DEBUG_EVENT
)
377 char buf
[INET6_ADDRSTRLEN
];
380 zlog_debug ("MESSAGE: ZEBRA_INTERFACE_NBR_ADDRESS_DELETE %s/%d on %s",
381 inet_ntop (p
->family
, &p
->u
.prefix
, buf
, INET6_ADDRSTRLEN
),
382 p
->prefixlen
, ifc
->ifp
->name
);
385 for (ALL_LIST_ELEMENTS (zebrad
.client_list
, node
, nnode
, client
))
387 zsend_interface_nbr_address (ZEBRA_INTERFACE_NBR_ADDRESS_DELETE
, client
, ifp
, ifc
);
390 /* Add new nbr connected IPv6 address if none exists already, or replace the
391 existing one if an ifc entry is found on the interface. */
393 nbr_connected_replacement_add_ipv6 (struct interface
*ifp
, struct in6_addr
*address
,
396 struct nbr_connected
*ifc
;
400 IPV6_ADDR_COPY (&p
.u
.prefix
, address
);
401 p
.prefixlen
= prefixlen
;
403 if (nbr_connected_check(ifp
, &p
))
406 if (!(ifc
= listnode_head(ifp
->nbr_connected
)))
409 ifc
= nbr_connected_new ();
410 ifc
->address
= prefix_new();
412 listnode_add (ifp
->nbr_connected
, ifc
);
415 prefix_copy(ifc
->address
, &p
);
417 zebra_interface_nbr_address_add_update (ifp
, ifc
);
421 nbr_connected_delete_ipv6 (struct interface
*ifp
, struct in6_addr
*address
,
424 struct nbr_connected
*ifc
;
428 IPV6_ADDR_COPY (&p
.u
.prefix
, address
);
429 p
.prefixlen
= prefixlen
;
431 ifc
= nbr_connected_check(ifp
, &p
);
435 listnode_delete (ifp
->nbr_connected
, ifc
);
437 zebra_interface_nbr_address_delete_update (ifp
, ifc
);
439 nbr_connected_free (ifc
);
443 * The cmd passed to zsend_interface_update may be ZEBRA_INTERFACE_UP or
444 * ZEBRA_INTERFACE_DOWN.
446 * The ZEBRA_INTERFACE_UP message is sent from the zebra server to
447 * the clients in one of 2 situations:
448 * - an if_up is detected e.g., as a result of an RTM_IFINFO message
449 * - a vty command modifying the bandwidth of an interface is received.
450 * The ZEBRA_INTERFACE_DOWN message is sent when an if_down is detected.
453 zsend_interface_update (int cmd
, struct zserv
*client
, struct interface
*ifp
)
457 /* Check this client need interface information. */
458 if (! client
->ifinfo
)
464 zserv_create_header (s
, cmd
);
465 zserv_encode_interface (s
, ifp
);
467 if (cmd
== ZEBRA_INTERFACE_UP
)
470 client
->ifdown_cnt
++;
472 return zebra_server_send_message(client
);
476 zsend_interface_bfd_update (int cmd
, struct zserv
*client
,
477 struct interface
*ifp
, struct prefix
*p
)
482 /* Check this client need interface information. */
483 if (! client
->ifinfo
)
489 zserv_create_header (s
, cmd
);
490 stream_putl (s
, ifp
->ifindex
);
492 /* BFD destination prefix information. */
493 stream_putc (s
, p
->family
);
494 blen
= prefix_blen (p
);
495 stream_put (s
, &p
->u
.prefix
, blen
);
496 stream_putc (s
, p
->prefixlen
);
498 /* Write packet size. */
499 stream_putw_at (s
, 0, stream_get_endp (s
));
501 client
->if_bfd_cnt
++;
502 return zebra_server_send_message(client
);
506 * The zebra server sends the clients a ZEBRA_IPV4_ROUTE_ADD or a
507 * ZEBRA_IPV6_ROUTE_ADD via zsend_route_multipath in the following
509 * - when the client starts up, and requests default information
510 * by sending a ZEBRA_REDISTRIBUTE_DEFAULT_ADD to the zebra server, in the
511 * - case of rip, ripngd, ospfd and ospf6d, when the client sends a
512 * ZEBRA_REDISTRIBUTE_ADD as a result of the "redistribute" vty cmd,
513 * - when the zebra server redistributes routes after it updates its rib
515 * The zebra server sends clients a ZEBRA_IPV4_ROUTE_DELETE or a
516 * ZEBRA_IPV6_ROUTE_DELETE via zsend_route_multipath when:
517 * - a "ip route" or "ipv6 route" vty command is issued, a prefix is
518 * - deleted from zebra's rib, and this info
519 * has to be redistributed to the clients
521 * XXX The ZEBRA_IPV*_ROUTE_ADD message is also sent by the client to the
522 * zebra server when the client wants to tell the zebra server to add a
523 * route to the kernel (zapi_ipv4_add etc. ). Since it's essentially the
524 * same message being sent back and forth, this function and
525 * zapi_ipv{4,6}_{add, delete} should be re-written to avoid code
529 zsend_route_multipath (int cmd
, struct zserv
*client
, struct prefix
*p
,
534 struct nexthop
*nexthop
;
535 unsigned long nhnummark
= 0, messmark
= 0;
537 u_char zapi_flags
= 0;
542 zserv_create_header (s
, cmd
);
544 /* Put type and nexthop. */
545 stream_putc (s
, rib
->type
);
546 stream_putw (s
, rib
->instance
);
547 stream_putc (s
, rib
->flags
);
549 /* marker for message flags field */
550 messmark
= stream_get_endp (s
);
554 psize
= PSIZE (p
->prefixlen
);
555 stream_putc (s
, p
->prefixlen
);
556 stream_write (s
, (u_char
*) & p
->u
.prefix
, psize
);
559 * XXX The message format sent by zebra below does not match the format
560 * of the corresponding message expected by the zebra server
561 * itself (e.g., see zread_ipv4_add). The nexthop_num is not set correctly,
562 * (is there a bug on the client side if more than one segment is sent?)
563 * nexthop ZEBRA_NEXTHOP_IPV4 is never set, ZEBRA_NEXTHOP_IFINDEX
568 for (nexthop
= rib
->nexthop
; nexthop
; nexthop
= nexthop
->next
)
570 if (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
)
571 || nexthop_has_fib_child(nexthop
))
573 SET_FLAG (zapi_flags
, ZAPI_MESSAGE_NEXTHOP
);
574 SET_FLAG (zapi_flags
, ZAPI_MESSAGE_IFINDEX
);
578 nhnummark
= stream_get_endp (s
);
579 stream_putc (s
, 1); /* placeholder */
584 switch(nexthop
->type
)
586 case NEXTHOP_TYPE_IPV4
:
587 case NEXTHOP_TYPE_IPV4_IFINDEX
:
588 stream_put_in_addr (s
, &nexthop
->gate
.ipv4
);
591 case NEXTHOP_TYPE_IPV6
:
592 case NEXTHOP_TYPE_IPV6_IFINDEX
:
593 case NEXTHOP_TYPE_IPV6_IFNAME
:
594 stream_write (s
, (u_char
*) &nexthop
->gate
.ipv6
, 16);
598 if (cmd
== ZEBRA_IPV4_ROUTE_ADD
599 || cmd
== ZEBRA_IPV4_ROUTE_DELETE
)
601 struct in_addr empty
;
602 memset (&empty
, 0, sizeof (struct in_addr
));
603 stream_write (s
, (u_char
*) &empty
, IPV4_MAX_BYTELEN
);
607 struct in6_addr empty
;
608 memset (&empty
, 0, sizeof (struct in6_addr
));
609 stream_write (s
, (u_char
*) &empty
, IPV6_MAX_BYTELEN
);
613 /* Interface index. */
615 stream_putl (s
, nexthop
->ifindex
);
622 if (cmd
== ZEBRA_IPV4_ROUTE_ADD
|| cmd
== ZEBRA_IPV6_ROUTE_ADD
)
624 SET_FLAG (zapi_flags
, ZAPI_MESSAGE_DISTANCE
);
625 stream_putc (s
, rib
->distance
);
626 SET_FLAG (zapi_flags
, ZAPI_MESSAGE_METRIC
);
627 stream_putl (s
, rib
->metric
);
632 SET_FLAG(zapi_flags
, ZAPI_MESSAGE_TAG
);
633 stream_putw(s
, rib
->tag
);
637 /* write real message flags value */
638 stream_putc_at (s
, messmark
, zapi_flags
);
640 /* Write next-hop number */
642 stream_putc_at (s
, nhnummark
, nhnum
);
644 /* Write packet size. */
645 stream_putw_at (s
, 0, stream_get_endp (s
));
647 return zebra_server_send_message(client
);
652 zsend_ipv6_nexthop_lookup (struct zserv
*client
, struct in6_addr
*addr
)
658 struct nexthop
*nexthop
;
660 /* Lookup nexthop. */
661 rib
= rib_match_ipv6 (addr
);
663 /* Get output stream. */
667 /* Fill in result. */
668 zserv_create_header (s
, ZEBRA_IPV6_NEXTHOP_LOOKUP
);
669 stream_put (s
, &addr
, 16);
673 stream_putl (s
, rib
->metric
);
675 nump
= stream_get_endp(s
);
677 /* Only non-recursive routes are elegible to resolve nexthop we
678 * are looking up. Therefore, we will just iterate over the top
679 * chain of nexthops. */
680 for (nexthop
= rib
->nexthop
; nexthop
; nexthop
= nexthop
->next
)
681 if (CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_FIB
))
683 stream_putc (s
, nexthop
->type
);
684 switch (nexthop
->type
)
686 case ZEBRA_NEXTHOP_IPV6
:
687 stream_put (s
, &nexthop
->gate
.ipv6
, 16);
689 case ZEBRA_NEXTHOP_IPV6_IFINDEX
:
690 case ZEBRA_NEXTHOP_IPV6_IFNAME
:
691 stream_put (s
, &nexthop
->gate
.ipv6
, 16);
692 stream_putl (s
, nexthop
->ifindex
);
694 case ZEBRA_NEXTHOP_IFINDEX
:
695 case ZEBRA_NEXTHOP_IFNAME
:
696 stream_putl (s
, nexthop
->ifindex
);
704 stream_putc_at (s
, nump
, num
);
712 stream_putw_at (s
, 0, stream_get_endp (s
));
714 return zebra_server_send_message(client
);
716 #endif /* HAVE_IPV6 */
719 zsend_ipv4_nexthop_lookup (struct zserv
*client
, struct in_addr addr
)
725 struct nexthop
*nexthop
;
727 /* Lookup nexthop. */
728 rib
= rib_match_ipv4 (addr
);
730 /* Get output stream. */
734 /* Fill in result. */
735 zserv_create_header (s
, ZEBRA_IPV4_NEXTHOP_LOOKUP
);
736 stream_put_in_addr (s
, &addr
);
740 if (IS_ZEBRA_DEBUG_PACKET
&& IS_ZEBRA_DEBUG_RECV
)
741 zlog_debug("%s: Matching rib entry found.", __func__
);
742 stream_putl (s
, rib
->metric
);
744 nump
= stream_get_endp(s
);
746 /* Only non-recursive routes are elegible to resolve the nexthop we
747 * are looking up. Therefore, we will just iterate over the top
748 * chain of nexthops. */
749 for (nexthop
= rib
->nexthop
; nexthop
; nexthop
= nexthop
->next
)
750 if (CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_FIB
))
752 stream_putc (s
, nexthop
->type
);
753 switch (nexthop
->type
)
755 case ZEBRA_NEXTHOP_IPV4
:
756 stream_put_in_addr (s
, &nexthop
->gate
.ipv4
);
758 case ZEBRA_NEXTHOP_IPV4_IFINDEX
:
759 stream_put_in_addr (s
, &nexthop
->gate
.ipv4
);
760 stream_putl (s
, nexthop
->ifindex
);
762 case ZEBRA_NEXTHOP_IFINDEX
:
763 case ZEBRA_NEXTHOP_IFNAME
:
764 stream_putl (s
, nexthop
->ifindex
);
772 stream_putc_at (s
, nump
, num
);
776 if (IS_ZEBRA_DEBUG_PACKET
&& IS_ZEBRA_DEBUG_RECV
)
777 zlog_debug("%s: No matching rib entry found.", __func__
);
782 stream_putw_at (s
, 0, stream_get_endp (s
));
784 return zebra_server_send_message(client
);
787 /* Nexthop register */
789 zserv_rnh_register (struct zserv
*client
, int sock
, u_short length
,
798 if (IS_ZEBRA_DEBUG_NHT
)
799 zlog_debug("rnh_register msg from client %s: length=%d, type=%s\n",
800 zebra_route_string(client
->proto
), length
,
801 (type
== RNH_NEXTHOP_TYPE
) ? "nexthop" : "route");
805 client
->nh_reg_time
= quagga_time(NULL
);
809 flags
= stream_getc(s
);
810 p
.family
= stream_getw(s
);
811 p
.prefixlen
= stream_getc(s
);
813 if (p
.family
== AF_INET
)
815 p
.u
.prefix4
.s_addr
= stream_get_ipv4(s
);
816 l
+= IPV4_MAX_BYTELEN
;
818 else if (p
.family
== AF_INET6
)
820 stream_get(&p
.u
.prefix6
, s
, IPV6_MAX_BYTELEN
);
821 l
+= IPV6_MAX_BYTELEN
;
825 zlog_err("rnh_register: Received unknown family type %d\n",
829 rnh
= zebra_add_rnh(&p
, 0, type
);
830 if (type
== RNH_NEXTHOP_TYPE
)
832 if (flags
&& !CHECK_FLAG(rnh
->flags
, ZEBRA_NHT_CONNECTED
))
833 SET_FLAG(rnh
->flags
, ZEBRA_NHT_CONNECTED
);
834 else if (!flags
&& CHECK_FLAG(rnh
->flags
, ZEBRA_NHT_CONNECTED
))
835 UNSET_FLAG(rnh
->flags
, ZEBRA_NHT_CONNECTED
);
837 else if (type
== RNH_IMPORT_CHECK_TYPE
)
839 if (flags
&& !CHECK_FLAG(rnh
->flags
, ZEBRA_NHT_EXACT_MATCH
))
840 SET_FLAG(rnh
->flags
, ZEBRA_NHT_EXACT_MATCH
);
841 else if (!flags
&& CHECK_FLAG(rnh
->flags
, ZEBRA_NHT_EXACT_MATCH
))
842 UNSET_FLAG(rnh
->flags
, ZEBRA_NHT_EXACT_MATCH
);
845 zebra_add_rnh_client(rnh
, client
, type
);
846 /* Anything not AF_INET/INET6 has been filtered out above */
847 zebra_evaluate_rnh(0, p
.family
, 1, type
, &p
);
852 /* Nexthop register */
854 zserv_rnh_unregister (struct zserv
*client
, int sock
, u_short length
,
862 if (IS_ZEBRA_DEBUG_NHT
)
863 zlog_debug("rnh_unregister msg from client %s: length=%d\n",
864 zebra_route_string(client
->proto
), length
);
870 (void)stream_getc(s
); //Connected or not. Not used in this function
871 p
.family
= stream_getw(s
);
872 p
.prefixlen
= stream_getc(s
);
874 if (p
.family
== AF_INET
)
876 p
.u
.prefix4
.s_addr
= stream_get_ipv4(s
);
877 l
+= IPV4_MAX_BYTELEN
;
879 else if (p
.family
== AF_INET6
)
881 stream_get(&p
.u
.prefix6
, s
, IPV6_MAX_BYTELEN
);
882 l
+= IPV6_MAX_BYTELEN
;
886 zlog_err("rnh_register: Received unknown family type %d\n",
890 rnh
= zebra_lookup_rnh(&p
, 0, type
);
893 client
->nh_dereg_time
= quagga_time(NULL
);
894 zebra_remove_rnh_client(rnh
, client
, type
);
901 zsend_ipv4_import_lookup (struct zserv
*client
, struct prefix_ipv4
*p
)
907 struct nexthop
*nexthop
;
909 /* Lookup nexthop. */
910 rib
= rib_lookup_ipv4 (p
);
912 /* Get output stream. */
916 /* Fill in result. */
917 zserv_create_header (s
, ZEBRA_IPV4_IMPORT_LOOKUP
);
918 stream_put_in_addr (s
, &p
->prefix
);
922 stream_putl (s
, rib
->metric
);
924 nump
= stream_get_endp(s
);
926 for (nexthop
= rib
->nexthop
; nexthop
; nexthop
= nexthop
->next
)
927 if (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_FIB
)
928 || nexthop_has_fib_child(nexthop
))
930 stream_putc (s
, nexthop
->type
);
931 switch (nexthop
->type
)
933 case ZEBRA_NEXTHOP_IPV4
:
934 stream_put_in_addr (s
, &nexthop
->gate
.ipv4
);
936 case ZEBRA_NEXTHOP_IPV4_IFINDEX
:
937 stream_put_in_addr (s
, &nexthop
->gate
.ipv4
);
938 stream_putl (s
, nexthop
->ifindex
);
940 case ZEBRA_NEXTHOP_IFINDEX
:
941 case ZEBRA_NEXTHOP_IFNAME
:
942 stream_putl (s
, nexthop
->ifindex
);
950 stream_putc_at (s
, nump
, num
);
958 stream_putw_at (s
, 0, stream_get_endp (s
));
960 return zebra_server_send_message(client
);
963 /* Router-id is updated. Send ZEBRA_ROUTER_ID_ADD to client. */
965 zsend_router_id_update (struct zserv
*client
, struct prefix
*p
)
970 /* Check this client need interface information. */
971 if (!client
->ridinfo
)
978 zserv_create_header (s
, ZEBRA_ROUTER_ID_UPDATE
);
980 /* Prefix information. */
981 stream_putc (s
, p
->family
);
982 blen
= prefix_blen (p
);
983 stream_put (s
, &p
->u
.prefix
, blen
);
984 stream_putc (s
, p
->prefixlen
);
986 /* Write packet size. */
987 stream_putw_at (s
, 0, stream_get_endp (s
));
989 return zebra_server_send_message(client
);
992 /* Register zebra server interface information. Send current all
993 interface and address information. */
995 zread_interface_add (struct zserv
*client
, u_short length
)
997 struct listnode
*ifnode
, *ifnnode
;
998 struct listnode
*cnode
, *cnnode
;
999 struct interface
*ifp
;
1000 struct connected
*c
;
1001 struct nbr_connected
*nc
;
1003 /* Interface information is needed. */
1006 for (ALL_LIST_ELEMENTS (iflist
, ifnode
, ifnnode
, ifp
))
1008 /* Skip pseudo interface. */
1009 if (! CHECK_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
))
1012 if (zsend_interface_add (client
, ifp
) < 0)
1015 for (ALL_LIST_ELEMENTS (ifp
->connected
, cnode
, cnnode
, c
))
1017 if (CHECK_FLAG (c
->conf
, ZEBRA_IFC_REAL
) &&
1018 (zsend_interface_address (ZEBRA_INTERFACE_ADDRESS_ADD
, client
,
1022 for (ALL_LIST_ELEMENTS (ifp
->nbr_connected
, cnode
, cnnode
, nc
))
1024 if (zsend_interface_nbr_address (ZEBRA_INTERFACE_NBR_ADDRESS_ADD
, client
,
1033 /* Unregister zebra server interface information. */
1035 zread_interface_delete (struct zserv
*client
, u_short length
)
1041 /* This function support multiple nexthop. */
1043 * Parse the ZEBRA_IPV4_ROUTE_ADD sent from client. Update rib and
1047 zread_ipv4_add (struct zserv
*client
, u_short length
)
1051 struct prefix_ipv4 p
;
1053 struct in_addr nexthop
;
1055 u_char nexthop_type
;
1057 unsigned int ifindex
;
1062 /* Get input stream. */
1065 /* Allocate new rib. */
1066 rib
= XCALLOC (MTYPE_RIB
, sizeof (struct rib
));
1068 /* Type, flags, message. */
1069 rib
->type
= stream_getc (s
);
1070 rib
->instance
= stream_getw (s
);
1071 rib
->flags
= stream_getc (s
);
1072 message
= stream_getc (s
);
1073 safi
= stream_getw (s
);
1074 rib
->uptime
= time (NULL
);
1077 memset (&p
, 0, sizeof (struct prefix_ipv4
));
1079 p
.prefixlen
= stream_getc (s
);
1080 stream_get (&p
.prefix
, s
, PSIZE (p
.prefixlen
));
1082 /* Nexthop parse. */
1083 if (CHECK_FLAG (message
, ZAPI_MESSAGE_NEXTHOP
))
1085 nexthop_num
= stream_getc (s
);
1087 for (i
= 0; i
< nexthop_num
; i
++)
1089 nexthop_type
= stream_getc (s
);
1091 switch (nexthop_type
)
1093 case ZEBRA_NEXTHOP_IFINDEX
:
1094 ifindex
= stream_getl (s
);
1095 nexthop_ifindex_add (rib
, ifindex
);
1097 case ZEBRA_NEXTHOP_IFNAME
:
1098 ifname_len
= stream_getc (s
);
1099 stream_forward_getp (s
, ifname_len
);
1101 case ZEBRA_NEXTHOP_IPV4
:
1102 nexthop
.s_addr
= stream_get_ipv4 (s
);
1103 nexthop_ipv4_add (rib
, &nexthop
, NULL
);
1105 case ZEBRA_NEXTHOP_IPV4_IFINDEX
:
1106 nexthop
.s_addr
= stream_get_ipv4 (s
);
1107 ifindex
= stream_getl (s
);
1108 nexthop_ipv4_ifindex_add (rib
, &nexthop
, NULL
, ifindex
);
1110 case ZEBRA_NEXTHOP_IPV6
:
1111 stream_forward_getp (s
, IPV6_MAX_BYTELEN
);
1113 case ZEBRA_NEXTHOP_BLACKHOLE
:
1114 nexthop_blackhole_add (rib
);
1116 case ZEBRA_NEXTHOP_IPV4_ONLINK
:
1117 nexthop
.s_addr
= stream_get_ipv4 (s
);
1118 ifindex
= stream_getl (s
);
1119 nexthop_ipv4_ifindex_ol_add (rib
, &nexthop
, NULL
, ifindex
);
1126 if (CHECK_FLAG (message
, ZAPI_MESSAGE_DISTANCE
))
1127 rib
->distance
= stream_getc (s
);
1130 if (CHECK_FLAG (message
, ZAPI_MESSAGE_METRIC
))
1131 rib
->metric
= stream_getl (s
);
1134 if (CHECK_FLAG (message
, ZAPI_MESSAGE_TAG
))
1135 rib
->tag
= stream_getw (s
);
1140 rib
->table
=zebrad
.rtm_table_default
;
1141 ret
= rib_add_ipv4_multipath (&p
, rib
, safi
);
1145 client
->v4_route_add_cnt
++;
1147 client
->v4_route_upd8_cnt
++;
1151 /* Zebra server IPv4 prefix delete function. */
1153 zread_ipv4_delete (struct zserv
*client
, u_short length
)
1157 struct zapi_ipv4 api
;
1158 struct in_addr nexthop
, *nexthop_p
;
1159 unsigned long ifindex
;
1160 struct prefix_ipv4 p
;
1162 u_char nexthop_type
;
1170 /* Type, flags, message. */
1171 api
.type
= stream_getc (s
);
1172 api
.instance
= stream_getw (s
);
1173 api
.flags
= stream_getc (s
);
1174 api
.message
= stream_getc (s
);
1175 api
.safi
= stream_getw (s
);
1178 memset (&p
, 0, sizeof (struct prefix_ipv4
));
1180 p
.prefixlen
= stream_getc (s
);
1181 stream_get (&p
.prefix
, s
, PSIZE (p
.prefixlen
));
1183 /* Nexthop, ifindex, distance, metric. */
1184 if (CHECK_FLAG (api
.message
, ZAPI_MESSAGE_NEXTHOP
))
1186 nexthop_num
= stream_getc (s
);
1188 for (i
= 0; i
< nexthop_num
; i
++)
1190 nexthop_type
= stream_getc (s
);
1192 switch (nexthop_type
)
1194 case ZEBRA_NEXTHOP_IFINDEX
:
1195 ifindex
= stream_getl (s
);
1197 case ZEBRA_NEXTHOP_IFNAME
:
1198 ifname_len
= stream_getc (s
);
1199 stream_forward_getp (s
, ifname_len
);
1201 case ZEBRA_NEXTHOP_IPV4
:
1202 nexthop
.s_addr
= stream_get_ipv4 (s
);
1203 nexthop_p
= &nexthop
;
1205 case ZEBRA_NEXTHOP_IPV4_IFINDEX
:
1206 nexthop
.s_addr
= stream_get_ipv4 (s
);
1207 nexthop_p
= &nexthop
;
1208 ifindex
= stream_getl (s
);
1210 case ZEBRA_NEXTHOP_IPV6
:
1211 stream_forward_getp (s
, IPV6_MAX_BYTELEN
);
1218 if (CHECK_FLAG (api
.message
, ZAPI_MESSAGE_DISTANCE
))
1219 api
.distance
= stream_getc (s
);
1224 if (CHECK_FLAG (api
.message
, ZAPI_MESSAGE_METRIC
))
1225 api
.metric
= stream_getl (s
);
1230 if (CHECK_FLAG (api
.message
, ZAPI_MESSAGE_TAG
))
1231 api
.tag
= stream_getw (s
);
1235 rib_delete_ipv4 (api
.type
, api
.instance
, api
.flags
, &p
, nexthop_p
, ifindex
,
1236 client
->rtm_table
, api
.safi
);
1237 client
->v4_route_del_cnt
++;
1241 /* Nexthop lookup for IPv4. */
1243 zread_ipv4_nexthop_lookup (struct zserv
*client
, u_short length
)
1245 struct in_addr addr
;
1248 addr
.s_addr
= stream_get_ipv4 (client
->ibuf
);
1249 if (IS_ZEBRA_DEBUG_PACKET
&& IS_ZEBRA_DEBUG_RECV
)
1250 zlog_debug("%s: looking up %s", __func__
,
1251 inet_ntop (AF_INET
, &addr
, buf
, BUFSIZ
));
1252 return zsend_ipv4_nexthop_lookup (client
, addr
);
1255 /* Nexthop lookup for IPv4. */
1257 zread_ipv4_import_lookup (struct zserv
*client
, u_short length
)
1259 struct prefix_ipv4 p
;
1262 p
.prefixlen
= stream_getc (client
->ibuf
);
1263 p
.prefix
.s_addr
= stream_get_ipv4 (client
->ibuf
);
1265 return zsend_ipv4_import_lookup (client
, &p
);
1269 /* Zebra server IPv6 prefix add function. */
1271 zread_ipv4_route_ipv6_nexthop_add (struct zserv
*client
, u_short length
)
1275 struct in6_addr nexthop
;
1279 u_char nexthop_type
;
1280 unsigned long ifindex
;
1281 struct prefix_ipv4 p
;
1284 static struct in6_addr nexthops
[MULTIPATH_NUM
];
1285 static unsigned int ifindices
[MULTIPATH_NUM
];
1288 /* Get input stream. */
1292 memset (&nexthop
, 0, sizeof (struct in6_addr
));
1294 /* Allocate new rib. */
1295 rib
= XCALLOC (MTYPE_RIB
, sizeof (struct rib
));
1297 /* Type, flags, message. */
1298 rib
->type
= stream_getc (s
);
1299 rib
->instance
= stream_getw (s
);
1300 rib
->flags
= stream_getc (s
);
1301 message
= stream_getc (s
);
1302 safi
= stream_getw (s
);
1303 rib
->uptime
= time (NULL
);
1306 memset (&p
, 0, sizeof (struct prefix_ipv4
));
1308 p
.prefixlen
= stream_getc (s
);
1309 stream_get (&p
.prefix
, s
, PSIZE (p
.prefixlen
));
1311 /* We need to give nh-addr, nh-ifindex with the same next-hop object
1312 * to the rib to ensure that IPv6 multipathing works; need to coalesce
1313 * these. Clients should send the same number of paired set of
1314 * next-hop-addr/next-hop-ifindices. */
1315 if (CHECK_FLAG (message
, ZAPI_MESSAGE_NEXTHOP
))
1321 nexthop_num
= stream_getc (s
);
1322 for (i
= 0; i
< nexthop_num
; i
++)
1324 nexthop_type
= stream_getc (s
);
1326 switch (nexthop_type
)
1328 case ZEBRA_NEXTHOP_IPV6
:
1329 stream_get (&nexthop
, s
, 16);
1330 if (nh_count
< MULTIPATH_NUM
) {
1331 nexthops
[nh_count
++] = nexthop
;
1334 case ZEBRA_NEXTHOP_IFINDEX
:
1335 if (if_count
< MULTIPATH_NUM
) {
1336 ifindices
[if_count
++] = stream_getl (s
);
1339 case ZEBRA_NEXTHOP_BLACKHOLE
:
1340 nexthop_blackhole_add (rib
);
1345 max_nh_if
= (nh_count
> if_count
) ? nh_count
: if_count
;
1346 for (i
= 0; i
< max_nh_if
; i
++)
1348 if ((i
< nh_count
) && !IN6_IS_ADDR_UNSPECIFIED (&nexthops
[i
])) {
1349 if ((i
< if_count
) && ifindices
[i
]) {
1350 nexthop_ipv6_ifindex_add (rib
, &nexthops
[i
], ifindices
[i
]);
1353 nexthop_ipv6_add (rib
, &nexthops
[i
]);
1357 if ((i
< if_count
) && ifindices
[i
]) {
1358 nexthop_ifindex_add (rib
, ifindices
[i
]);
1365 if (CHECK_FLAG (message
, ZAPI_MESSAGE_DISTANCE
))
1366 rib
->distance
= stream_getc (s
);
1369 if (CHECK_FLAG (message
, ZAPI_MESSAGE_METRIC
))
1370 rib
->metric
= stream_getl (s
);
1373 if (CHECK_FLAG (message
, ZAPI_MESSAGE_TAG
))
1374 rib
->tag
= stream_getw (s
);
1379 rib
->table
=zebrad
.rtm_table_default
;
1380 ret
= rib_add_ipv6_multipath ((struct prefix
*)&p
, rib
, safi
, ifindex
);
1383 client
->v4_route_add_cnt
++;
1385 client
->v4_route_upd8_cnt
++;
1390 /* Zebra server IPv6 prefix add function. */
1392 zread_ipv6_add (struct zserv
*client
, u_short length
)
1396 struct in6_addr nexthop
;
1400 u_char nexthop_type
;
1401 unsigned long ifindex
;
1402 struct prefix_ipv6 p
;
1404 static struct in6_addr nexthops
[MULTIPATH_NUM
];
1405 static unsigned int ifindices
[MULTIPATH_NUM
];
1408 /* Get input stream. */
1412 memset (&nexthop
, 0, sizeof (struct in6_addr
));
1414 /* Allocate new rib. */
1415 rib
= XCALLOC (MTYPE_RIB
, sizeof (struct rib
));
1417 /* Type, flags, message. */
1418 rib
->type
= stream_getc (s
);
1419 rib
->instance
= stream_getw (s
);
1420 rib
->flags
= stream_getc (s
);
1421 message
= stream_getc (s
);
1422 safi
= stream_getw (s
);
1423 rib
->uptime
= time (NULL
);
1426 memset (&p
, 0, sizeof (struct prefix_ipv6
));
1427 p
.family
= AF_INET6
;
1428 p
.prefixlen
= stream_getc (s
);
1429 stream_get (&p
.prefix
, s
, PSIZE (p
.prefixlen
));
1431 /* We need to give nh-addr, nh-ifindex with the same next-hop object
1432 * to the rib to ensure that IPv6 multipathing works; need to coalesce
1433 * these. Clients should send the same number of paired set of
1434 * next-hop-addr/next-hop-ifindices. */
1435 if (CHECK_FLAG (message
, ZAPI_MESSAGE_NEXTHOP
))
1441 nexthop_num
= stream_getc (s
);
1442 for (i
= 0; i
< nexthop_num
; i
++)
1444 nexthop_type
= stream_getc (s
);
1446 switch (nexthop_type
)
1448 case ZEBRA_NEXTHOP_IPV6
:
1449 stream_get (&nexthop
, s
, 16);
1450 if (nh_count
< MULTIPATH_NUM
) {
1451 nexthops
[nh_count
++] = nexthop
;
1454 case ZEBRA_NEXTHOP_IFINDEX
:
1455 if (if_count
< MULTIPATH_NUM
) {
1456 ifindices
[if_count
++] = stream_getl (s
);
1459 case ZEBRA_NEXTHOP_BLACKHOLE
:
1460 nexthop_blackhole_add (rib
);
1465 max_nh_if
= (nh_count
> if_count
) ? nh_count
: if_count
;
1466 for (i
= 0; i
< max_nh_if
; i
++)
1468 if ((i
< nh_count
) && !IN6_IS_ADDR_UNSPECIFIED (&nexthops
[i
])) {
1469 if ((i
< if_count
) && ifindices
[i
]) {
1470 if (rib_bogus_ipv6 (rib
->type
, &p
, &nexthops
[i
], ifindices
[i
], 0)) {
1473 nexthop_ipv6_ifindex_add (rib
, &nexthops
[i
], ifindices
[i
]);
1476 if (rib_bogus_ipv6 (rib
->type
, &p
, &nexthops
[i
], 0, 0)) {
1479 nexthop_ipv6_add (rib
, &nexthops
[i
]);
1483 if ((i
< if_count
) && ifindices
[i
]) {
1484 if (rib_bogus_ipv6 (rib
->type
, &p
, NULL
, ifindices
[i
], 0)) {
1487 nexthop_ifindex_add (rib
, ifindices
[i
]);
1494 if (CHECK_FLAG (message
, ZAPI_MESSAGE_DISTANCE
))
1495 rib
->distance
= stream_getc (s
);
1498 if (CHECK_FLAG (message
, ZAPI_MESSAGE_METRIC
))
1499 rib
->metric
= stream_getl (s
);
1502 if (CHECK_FLAG (message
, ZAPI_MESSAGE_TAG
))
1503 rib
->tag
= stream_getw (s
);
1508 rib
->table
=zebrad
.rtm_table_default
;
1509 ret
= rib_add_ipv6_multipath ((struct prefix
*)&p
, rib
, safi
, ifindex
);
1512 client
->v6_route_add_cnt
++;
1514 client
->v6_route_upd8_cnt
++;
1519 /* Zebra server IPv6 prefix delete function. */
1521 zread_ipv6_delete (struct zserv
*client
, u_short length
)
1525 struct zapi_ipv6 api
;
1526 struct in6_addr nexthop
;
1527 unsigned long ifindex
;
1528 struct prefix_ipv6 p
;
1532 memset (&nexthop
, 0, sizeof (struct in6_addr
));
1534 /* Type, flags, message. */
1535 api
.type
= stream_getc (s
);
1536 api
.instance
= stream_getw (s
);
1537 api
.flags
= stream_getc (s
);
1538 api
.message
= stream_getc (s
);
1539 api
.safi
= stream_getw (s
);
1542 memset (&p
, 0, sizeof (struct prefix_ipv6
));
1543 p
.family
= AF_INET6
;
1544 p
.prefixlen
= stream_getc (s
);
1545 stream_get (&p
.prefix
, s
, PSIZE (p
.prefixlen
));
1547 /* Nexthop, ifindex, distance, metric. */
1548 if (CHECK_FLAG (api
.message
, ZAPI_MESSAGE_NEXTHOP
))
1550 u_char nexthop_type
;
1552 api
.nexthop_num
= stream_getc (s
);
1553 for (i
= 0; i
< api
.nexthop_num
; i
++)
1555 nexthop_type
= stream_getc (s
);
1557 switch (nexthop_type
)
1559 case ZEBRA_NEXTHOP_IPV6
:
1560 stream_get (&nexthop
, s
, 16);
1562 case ZEBRA_NEXTHOP_IFINDEX
:
1563 ifindex
= stream_getl (s
);
1570 if (CHECK_FLAG (api
.message
, ZAPI_MESSAGE_DISTANCE
))
1571 api
.distance
= stream_getc (s
);
1576 if (CHECK_FLAG (api
.message
, ZAPI_MESSAGE_METRIC
))
1577 api
.metric
= stream_getl (s
);
1582 if (CHECK_FLAG (api
.message
, ZAPI_MESSAGE_TAG
))
1583 api
.tag
= stream_getw (s
);
1587 if (IN6_IS_ADDR_UNSPECIFIED (&nexthop
))
1588 rib_delete_ipv6 (api
.type
, api
.instance
, api
.flags
, &p
, NULL
, ifindex
, client
->rtm_table
, api
.safi
);
1590 rib_delete_ipv6 (api
.type
, api
.instance
, api
.flags
, &p
, &nexthop
, ifindex
, client
->rtm_table
, api
.safi
);
1592 client
->v6_route_del_cnt
++;
1597 zread_ipv6_nexthop_lookup (struct zserv
*client
, u_short length
)
1599 struct in6_addr addr
;
1602 stream_get (&addr
, client
->ibuf
, 16);
1603 if (IS_ZEBRA_DEBUG_PACKET
&& IS_ZEBRA_DEBUG_RECV
)
1604 zlog_debug("%s: looking up %s", __func__
,
1605 inet_ntop (AF_INET6
, &addr
, buf
, BUFSIZ
));
1607 return zsend_ipv6_nexthop_lookup (client
, &addr
);
1609 #endif /* HAVE_IPV6 */
1611 /* Register zebra server router-id information. Send current router-id */
1613 zread_router_id_add (struct zserv
*client
, u_short length
)
1617 /* Router-id information is needed. */
1618 client
->ridinfo
= 1;
1622 return zsend_router_id_update (client
,&p
);
1625 /* Unregister zebra server router-id information. */
1627 zread_router_id_delete (struct zserv
*client
, u_short length
)
1629 client
->ridinfo
= 0;
1633 /* Tie up route-type and client->sock */
1635 zread_hello (struct zserv
*client
)
1637 /* type of protocol (lib/zebra.h) */
1641 proto
= stream_getc (client
->ibuf
);
1642 instance
= stream_getw (client
->ibuf
);
1644 /* accept only dynamic routing protocols */
1645 if ((proto
< ZEBRA_ROUTE_MAX
)
1646 && (proto
> ZEBRA_ROUTE_STATIC
))
1648 zlog_notice ("client %d says hello and bids fair to announce only %s routes",
1649 client
->sock
, zebra_route_string(proto
));
1651 zlog_notice ("client protocol instance %d", instance
);
1653 client
->proto
= proto
;
1654 client
->instance
= instance
;
1658 /* Close zebra client. */
1660 zebra_client_close (struct zserv
*client
)
1662 zebra_cleanup_rnh_client(0, AF_INET
, client
, RNH_NEXTHOP_TYPE
);
1663 zebra_cleanup_rnh_client(0, AF_INET6
, client
, RNH_NEXTHOP_TYPE
);
1664 zebra_cleanup_rnh_client(0, AF_INET
, client
, RNH_IMPORT_CHECK_TYPE
);
1665 zebra_cleanup_rnh_client(0, AF_INET6
, client
, RNH_IMPORT_CHECK_TYPE
);
1667 /* Close file descriptor. */
1670 unsigned long nroutes
;
1672 close (client
->sock
);
1673 nroutes
= rib_score_proto (client
->proto
, client
->instance
);
1674 zlog_notice ("client %d disconnected. %lu %s routes removed from the rib",
1675 client
->sock
, nroutes
, zebra_route_string (client
->proto
));
1679 /* Free stream buffers. */
1681 stream_free (client
->ibuf
);
1683 stream_free (client
->obuf
);
1685 buffer_free(client
->wb
);
1687 /* Release threads. */
1689 thread_cancel (client
->t_read
);
1690 if (client
->t_write
)
1691 thread_cancel (client
->t_write
);
1692 if (client
->t_suicide
)
1693 thread_cancel (client
->t_suicide
);
1695 /* Free client structure. */
1696 listnode_delete (zebrad
.client_list
, client
);
1700 /* Make new client. */
1702 zebra_client_create (int sock
)
1704 struct zserv
*client
;
1706 client
= XCALLOC (0, sizeof (struct zserv
));
1708 /* Make client input/output buffer. */
1709 client
->sock
= sock
;
1710 client
->ibuf
= stream_new (ZEBRA_MAX_PACKET_SIZ
);
1711 client
->obuf
= stream_new (ZEBRA_MAX_PACKET_SIZ
);
1712 client
->wb
= buffer_new(0);
1714 /* Set table number. */
1715 client
->rtm_table
= zebrad
.rtm_table_default
;
1717 client
->connect_time
= quagga_time(NULL
);
1719 /* Add this client to linked list. */
1720 listnode_add (zebrad
.client_list
, client
);
1722 /* Make new read thread. */
1723 zebra_event (ZEBRA_READ
, sock
, client
);
1726 /* Handler of zebra service request. */
1728 zebra_client_read (struct thread
*thread
)
1731 struct zserv
*client
;
1733 uint16_t length
, command
;
1734 uint8_t marker
, version
;
1736 /* Get thread data. Reset reading thread because I'm running. */
1737 sock
= THREAD_FD (thread
);
1738 client
= THREAD_ARG (thread
);
1739 client
->t_read
= NULL
;
1741 if (client
->t_suicide
)
1743 zebra_client_close(client
);
1747 /* Read length and command (if we don't have it already). */
1748 if ((already
= stream_get_endp(client
->ibuf
)) < ZEBRA_HEADER_SIZE
)
1751 if (((nbyte
= stream_read_try (client
->ibuf
, sock
,
1752 ZEBRA_HEADER_SIZE
-already
)) == 0) ||
1755 if (IS_ZEBRA_DEBUG_EVENT
)
1756 zlog_debug ("connection closed socket [%d]", sock
);
1757 zebra_client_close (client
);
1760 if (nbyte
!= (ssize_t
)(ZEBRA_HEADER_SIZE
-already
))
1762 /* Try again later. */
1763 zebra_event (ZEBRA_READ
, sock
, client
);
1766 already
= ZEBRA_HEADER_SIZE
;
1769 /* Reset to read from the beginning of the incoming packet. */
1770 stream_set_getp(client
->ibuf
, 0);
1772 /* Fetch header values */
1773 length
= stream_getw (client
->ibuf
);
1774 marker
= stream_getc (client
->ibuf
);
1775 version
= stream_getc (client
->ibuf
);
1776 command
= stream_getw (client
->ibuf
);
1778 if (marker
!= ZEBRA_HEADER_MARKER
|| version
!= ZSERV_VERSION
)
1780 zlog_err("%s: socket %d version mismatch, marker %d, version %d",
1781 __func__
, sock
, marker
, version
);
1782 zebra_client_close (client
);
1785 if (length
< ZEBRA_HEADER_SIZE
)
1787 zlog_warn("%s: socket %d message length %u is less than header size %d",
1788 __func__
, sock
, length
, ZEBRA_HEADER_SIZE
);
1789 zebra_client_close (client
);
1792 if (length
> STREAM_SIZE(client
->ibuf
))
1794 zlog_warn("%s: socket %d message length %u exceeds buffer size %lu",
1795 __func__
, sock
, length
, (u_long
)STREAM_SIZE(client
->ibuf
));
1796 zebra_client_close (client
);
1800 /* Read rest of data. */
1801 if (already
< length
)
1804 if (((nbyte
= stream_read_try (client
->ibuf
, sock
,
1805 length
-already
)) == 0) ||
1808 if (IS_ZEBRA_DEBUG_EVENT
)
1809 zlog_debug ("connection closed [%d] when reading zebra data", sock
);
1810 zebra_client_close (client
);
1813 if (nbyte
!= (ssize_t
)(length
-already
))
1815 /* Try again later. */
1816 zebra_event (ZEBRA_READ
, sock
, client
);
1821 length
-= ZEBRA_HEADER_SIZE
;
1823 /* Debug packet information. */
1824 if (IS_ZEBRA_DEBUG_EVENT
)
1825 zlog_debug ("zebra message comes from socket [%d]", sock
);
1827 if (IS_ZEBRA_DEBUG_PACKET
&& IS_ZEBRA_DEBUG_RECV
)
1828 zlog_debug ("zebra message received [%s] %d",
1829 zserv_command_string (command
), length
);
1831 client
->last_read_time
= quagga_time(NULL
);
1832 client
->last_read_cmd
= command
;
1836 case ZEBRA_ROUTER_ID_ADD
:
1837 zread_router_id_add (client
, length
);
1839 case ZEBRA_ROUTER_ID_DELETE
:
1840 zread_router_id_delete (client
, length
);
1842 case ZEBRA_INTERFACE_ADD
:
1843 zread_interface_add (client
, length
);
1845 case ZEBRA_INTERFACE_DELETE
:
1846 zread_interface_delete (client
, length
);
1848 case ZEBRA_IPV4_ROUTE_ADD
:
1849 zread_ipv4_add (client
, length
);
1851 case ZEBRA_IPV4_ROUTE_DELETE
:
1852 zread_ipv4_delete (client
, length
);
1855 case ZEBRA_IPV4_ROUTE_IPV6_NEXTHOP_ADD
:
1856 zread_ipv4_route_ipv6_nexthop_add (client
, length
);
1858 case ZEBRA_IPV6_ROUTE_ADD
:
1859 zread_ipv6_add (client
, length
);
1861 case ZEBRA_IPV6_ROUTE_DELETE
:
1862 zread_ipv6_delete (client
, length
);
1864 #endif /* HAVE_IPV6 */
1865 case ZEBRA_REDISTRIBUTE_ADD
:
1866 zebra_redistribute_add (command
, client
, length
);
1868 case ZEBRA_REDISTRIBUTE_DELETE
:
1869 zebra_redistribute_delete (command
, client
, length
);
1871 case ZEBRA_REDISTRIBUTE_DEFAULT_ADD
:
1872 zebra_redistribute_default_add (command
, client
, length
);
1874 case ZEBRA_REDISTRIBUTE_DEFAULT_DELETE
:
1875 zebra_redistribute_default_delete (command
, client
, length
);
1877 case ZEBRA_IPV4_NEXTHOP_LOOKUP
:
1878 zread_ipv4_nexthop_lookup (client
, length
);
1881 case ZEBRA_IPV6_NEXTHOP_LOOKUP
:
1882 zread_ipv6_nexthop_lookup (client
, length
);
1884 #endif /* HAVE_IPV6 */
1885 case ZEBRA_IPV4_IMPORT_LOOKUP
:
1886 zread_ipv4_import_lookup (client
, length
);
1889 zread_hello (client
);
1891 case ZEBRA_NEXTHOP_REGISTER
:
1892 zserv_rnh_register(client
, sock
, length
, RNH_NEXTHOP_TYPE
);
1894 case ZEBRA_NEXTHOP_UNREGISTER
:
1895 zserv_rnh_unregister(client
, sock
, length
, RNH_NEXTHOP_TYPE
);
1897 case ZEBRA_IMPORT_ROUTE_REGISTER
:
1898 zserv_rnh_register(client
, sock
, length
, RNH_IMPORT_CHECK_TYPE
);
1900 case ZEBRA_IMPORT_ROUTE_UNREGISTER
:
1901 zserv_rnh_unregister(client
, sock
, length
, RNH_IMPORT_CHECK_TYPE
);
1904 zlog_info ("Zebra received unknown command %d", command
);
1908 if (client
->t_suicide
)
1910 /* No need to wait for thread callback, just kill immediately. */
1911 zebra_client_close(client
);
1915 stream_reset (client
->ibuf
);
1916 zebra_event (ZEBRA_READ
, sock
, client
);
1921 /* Accept code of zebra server socket. */
1923 zebra_accept (struct thread
*thread
)
1927 struct sockaddr_in client
;
1930 accept_sock
= THREAD_FD (thread
);
1932 /* Reregister myself. */
1933 zebra_event (ZEBRA_SERV
, accept_sock
, NULL
);
1935 len
= sizeof (struct sockaddr_in
);
1936 client_sock
= accept (accept_sock
, (struct sockaddr
*) &client
, &len
);
1938 if (client_sock
< 0)
1940 zlog_warn ("Can't accept zebra socket: %s", safe_strerror (errno
));
1944 /* Make client socket non-blocking. */
1945 set_nonblocking(client_sock
);
1947 /* Create new zebra client. */
1948 zebra_client_create (client_sock
);
1953 #ifdef HAVE_TCP_ZEBRA
1954 /* Make zebra's server socket. */
1960 struct sockaddr_in addr
;
1962 accept_sock
= socket (AF_INET
, SOCK_STREAM
, 0);
1964 if (accept_sock
< 0)
1966 zlog_warn ("Can't create zserv stream socket: %s",
1967 safe_strerror (errno
));
1968 zlog_warn ("zebra can't provice full functionality due to above error");
1972 memset (&addr
, 0, sizeof (struct sockaddr_in
));
1973 addr
.sin_family
= AF_INET
;
1974 addr
.sin_port
= htons (ZEBRA_PORT
);
1975 #ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
1976 addr
.sin_len
= sizeof (struct sockaddr_in
);
1977 #endif /* HAVE_STRUCT_SOCKADDR_IN_SIN_LEN */
1978 addr
.sin_addr
.s_addr
= htonl (INADDR_LOOPBACK
);
1980 sockopt_reuseaddr (accept_sock
);
1981 sockopt_reuseport (accept_sock
);
1983 if ( zserv_privs
.change(ZPRIVS_RAISE
) )
1984 zlog (NULL
, LOG_ERR
, "Can't raise privileges");
1986 ret
= bind (accept_sock
, (struct sockaddr
*)&addr
,
1987 sizeof (struct sockaddr_in
));
1990 zlog_warn ("Can't bind to stream socket: %s",
1991 safe_strerror (errno
));
1992 zlog_warn ("zebra can't provice full functionality due to above error");
1993 close (accept_sock
); /* Avoid sd leak. */
1997 if ( zserv_privs
.change(ZPRIVS_LOWER
) )
1998 zlog (NULL
, LOG_ERR
, "Can't lower privileges");
2000 ret
= listen (accept_sock
, 1);
2003 zlog_warn ("Can't listen to stream socket: %s",
2004 safe_strerror (errno
));
2005 zlog_warn ("zebra can't provice full functionality due to above error");
2006 close (accept_sock
); /* Avoid sd leak. */
2010 zebra_event (ZEBRA_SERV
, accept_sock
, NULL
);
2012 #endif /* HAVE_TCP_ZEBRA */
2014 /* For sockaddr_un. */
2017 /* zebra server UNIX domain socket. */
2019 zebra_serv_un (const char *path
)
2023 struct sockaddr_un serv
;
2026 /* First of all, unlink existing socket */
2030 old_mask
= umask (0077);
2032 /* Make UNIX domain socket. */
2033 sock
= socket (AF_UNIX
, SOCK_STREAM
, 0);
2036 zlog_warn ("Can't create zserv unix socket: %s",
2037 safe_strerror (errno
));
2038 zlog_warn ("zebra can't provide full functionality due to above error");
2042 /* Make server socket. */
2043 memset (&serv
, 0, sizeof (struct sockaddr_un
));
2044 serv
.sun_family
= AF_UNIX
;
2045 strncpy (serv
.sun_path
, path
, strlen (path
));
2046 #ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
2047 len
= serv
.sun_len
= SUN_LEN(&serv
);
2049 len
= sizeof (serv
.sun_family
) + strlen (serv
.sun_path
);
2050 #endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */
2052 ret
= bind (sock
, (struct sockaddr
*) &serv
, len
);
2055 zlog_warn ("Can't bind to unix socket %s: %s",
2056 path
, safe_strerror (errno
));
2057 zlog_warn ("zebra can't provide full functionality due to above error");
2062 ret
= listen (sock
, 5);
2065 zlog_warn ("Can't listen to unix socket %s: %s",
2066 path
, safe_strerror (errno
));
2067 zlog_warn ("zebra can't provide full functionality due to above error");
2074 zebra_event (ZEBRA_SERV
, sock
, NULL
);
2079 zebra_event (enum event event
, int sock
, struct zserv
*client
)
2084 thread_add_read (zebrad
.master
, zebra_accept
, client
, sock
);
2088 thread_add_read (zebrad
.master
, zebra_client_read
, client
, sock
);
2096 #define ZEBRA_TIME_BUF 32
2098 zserv_time_buf(time_t *time1
, char *buf
, int buflen
)
2103 assert (buf
!= NULL
);
2104 assert (buflen
>= ZEBRA_TIME_BUF
);
2105 assert (time1
!= NULL
);
2109 snprintf(buf
, buflen
, "never ");
2113 now
= quagga_time(NULL
);
2117 /* Making formatted timer strings. */
2118 #define ONE_DAY_SECOND 60*60*24
2119 #define ONE_WEEK_SECOND 60*60*24*7
2121 if (now
< ONE_DAY_SECOND
)
2122 snprintf (buf
, buflen
, "%02d:%02d:%02d",
2123 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
2124 else if (now
< ONE_WEEK_SECOND
)
2125 snprintf (buf
, buflen
, "%dd%02dh%02dm",
2126 tm
->tm_yday
, tm
->tm_hour
, tm
->tm_min
);
2128 snprintf (buf
, buflen
, "%02dw%dd%02dh",
2129 tm
->tm_yday
/7, tm
->tm_yday
- ((tm
->tm_yday
/7) * 7), tm
->tm_hour
);
2134 zebra_show_client_detail (struct vty
*vty
, struct zserv
*client
)
2136 char cbuf
[ZEBRA_TIME_BUF
], rbuf
[ZEBRA_TIME_BUF
];
2137 char wbuf
[ZEBRA_TIME_BUF
], nhbuf
[ZEBRA_TIME_BUF
], mbuf
[ZEBRA_TIME_BUF
];
2139 vty_out (vty
, "Client: %s", zebra_route_string(client
->proto
));
2140 if (client
->instance
)
2141 vty_out (vty
, " Instance: %d", client
->instance
);
2142 vty_out (vty
, "%s", VTY_NEWLINE
);
2144 vty_out (vty
, "------------------------ %s", VTY_NEWLINE
);
2145 vty_out (vty
, "FD: %d %s", client
->sock
, VTY_NEWLINE
);
2146 vty_out (vty
, "Route Table ID: %d %s", client
->rtm_table
, VTY_NEWLINE
);
2148 vty_out (vty
, "Connect Time: %s %s",
2149 zserv_time_buf(&client
->connect_time
, cbuf
, ZEBRA_TIME_BUF
),
2151 if (client
->nh_reg_time
)
2153 vty_out (vty
, "Nexthop Registry Time: %s %s",
2154 zserv_time_buf(&client
->nh_reg_time
, nhbuf
, ZEBRA_TIME_BUF
),
2156 if (client
->nh_last_upd_time
)
2157 vty_out (vty
, "Nexthop Last Update Time: %s %s",
2158 zserv_time_buf(&client
->nh_last_upd_time
, mbuf
, ZEBRA_TIME_BUF
),
2161 vty_out (vty
, "No Nexthop Update sent%s", VTY_NEWLINE
);
2164 vty_out (vty
, "Not registered for Nexthop Updates%s", VTY_NEWLINE
);
2166 vty_out (vty
, "Last Msg Rx Time: %s %s",
2167 zserv_time_buf(&client
->last_read_time
, rbuf
, ZEBRA_TIME_BUF
),
2169 vty_out (vty
, "Last Msg Tx Time: %s %s",
2170 zserv_time_buf(&client
->last_write_time
, wbuf
, ZEBRA_TIME_BUF
),
2172 if (client
->last_read_time
)
2173 vty_out (vty
, "Last Rcvd Cmd: %s %s",
2174 zserv_command_string(client
->last_read_cmd
), VTY_NEWLINE
);
2175 if (client
->last_write_time
)
2176 vty_out (vty
, "Last Sent Cmd: %s %s",
2177 zserv_command_string(client
->last_write_cmd
), VTY_NEWLINE
);
2178 vty_out (vty
, "%s", VTY_NEWLINE
);
2180 vty_out (vty
, "Type Add Update Del %s", VTY_NEWLINE
);
2181 vty_out (vty
, "================================================== %s", VTY_NEWLINE
);
2182 vty_out (vty
, "IPv4 %-12d%-12d%-12d%s", client
->v4_route_add_cnt
,
2183 client
->v4_route_upd8_cnt
, client
->v4_route_del_cnt
, VTY_NEWLINE
);
2184 vty_out (vty
, "IPv6 %-12d%-12d%-12d%s", client
->v6_route_add_cnt
,
2185 client
->v6_route_upd8_cnt
, client
->v6_route_del_cnt
, VTY_NEWLINE
);
2186 vty_out (vty
, "Redist:v4 %-12d%-12d%-12d%s", client
->redist_v4_add_cnt
, 0,
2187 client
->redist_v4_del_cnt
, VTY_NEWLINE
);
2188 vty_out (vty
, "Redist:v6 %-12d%-12d%-12d%s", client
->redist_v6_add_cnt
, 0,
2189 client
->redist_v6_del_cnt
, VTY_NEWLINE
);
2190 vty_out (vty
, "Connected %-12d%-12d%-12d%s", client
->ifadd_cnt
, 0,
2191 client
->ifdel_cnt
, VTY_NEWLINE
);
2192 vty_out (vty
, "Interface Up Notifications: %d%s", client
->ifup_cnt
,
2194 vty_out (vty
, "Interface Down Notifications: %d%s", client
->ifdown_cnt
,
2197 vty_out (vty
, "%s", VTY_NEWLINE
);
2202 zebra_show_client_brief (struct vty
*vty
, struct zserv
*client
)
2204 char cbuf
[ZEBRA_TIME_BUF
], rbuf
[ZEBRA_TIME_BUF
];
2205 char wbuf
[ZEBRA_TIME_BUF
];
2207 vty_out (vty
, "%-8s%12s %12s%12s%8d/%-8d%8d/%-8d%s",
2208 zebra_route_string(client
->proto
),
2209 zserv_time_buf(&client
->connect_time
, cbuf
, ZEBRA_TIME_BUF
),
2210 zserv_time_buf(&client
->last_read_time
, rbuf
, ZEBRA_TIME_BUF
),
2211 zserv_time_buf(&client
->last_write_time
, wbuf
, ZEBRA_TIME_BUF
),
2212 client
->v4_route_add_cnt
+client
->v4_route_upd8_cnt
,
2213 client
->v4_route_del_cnt
,
2214 client
->v6_route_add_cnt
+client
->v6_route_upd8_cnt
,
2215 client
->v6_route_del_cnt
, VTY_NEWLINE
);
2220 /* Display default rtm_table for all clients. */
2225 "default routing table to use for all clients\n")
2227 vty_out (vty
, "table %d%s", zebrad
.rtm_table_default
,
2232 DEFUN (config_table
,
2235 "Configure target kernel routing table\n"
2238 zebrad
.rtm_table_default
= strtol (argv
[0], (char**)0, 10);
2242 DEFUN (ip_forwarding
,
2246 "Turn on IP forwarding")
2252 ret
= ipforward_on ();
2256 vty_out (vty
, "Can't turn on IP forwarding%s", VTY_NEWLINE
);
2263 DEFUN (no_ip_forwarding
,
2264 no_ip_forwarding_cmd
,
2268 "Turn off IP forwarding")
2274 ret
= ipforward_off ();
2278 vty_out (vty
, "Can't turn off IP forwarding%s", VTY_NEWLINE
);
2285 /* This command is for debugging purpose. */
2286 DEFUN (show_zebra_client
,
2287 show_zebra_client_cmd
,
2288 "show zebra client",
2291 "Client information")
2293 struct listnode
*node
;
2294 struct zserv
*client
;
2296 for (ALL_LIST_ELEMENTS_RO (zebrad
.client_list
, node
, client
))
2297 zebra_show_client_detail(vty
, client
);
2302 /* This command is for debugging purpose. */
2303 DEFUN (show_zebra_client_summary
,
2304 show_zebra_client_summary_cmd
,
2305 "show zebra client summary",
2307 "Zebra information brief"
2308 "Client information brief")
2310 struct listnode
*node
;
2311 struct zserv
*client
;
2313 vty_out (vty
, "Name Connect Time Last Read Last Write IPv4 Routes IPv6 Routes %s",
2315 vty_out (vty
,"--------------------------------------------------------------------------------%s",
2318 for (ALL_LIST_ELEMENTS_RO (zebrad
.client_list
, node
, client
))
2319 zebra_show_client_brief(vty
, client
);
2321 vty_out (vty
, "Routes column shows (added+updated)/deleted%s", VTY_NEWLINE
);
2325 /* Table configuration write function. */
2327 config_write_table (struct vty
*vty
)
2329 if (zebrad
.rtm_table_default
)
2330 vty_out (vty
, "table %d%s", zebrad
.rtm_table_default
,
2335 /* table node for routing tables. */
2336 static struct cmd_node table_node
=
2339 "", /* This node has no interface. */
2343 /* Only display ip forwarding is enabled or not. */
2344 DEFUN (show_ip_forwarding
,
2345 show_ip_forwarding_cmd
,
2346 "show ip forwarding",
2349 "IP forwarding status\n")
2356 vty_out (vty
, "IP forwarding is off%s", VTY_NEWLINE
);
2358 vty_out (vty
, "IP forwarding is on%s", VTY_NEWLINE
);
2363 /* Only display ipv6 forwarding is enabled or not. */
2364 DEFUN (show_ipv6_forwarding
,
2365 show_ipv6_forwarding_cmd
,
2366 "show ipv6 forwarding",
2368 "IPv6 information\n"
2369 "Forwarding status\n")
2373 ret
= ipforward_ipv6 ();
2378 vty_out (vty
, "ipv6 forwarding is unknown%s", VTY_NEWLINE
);
2381 vty_out (vty
, "ipv6 forwarding is %s%s", "off", VTY_NEWLINE
);
2384 vty_out (vty
, "ipv6 forwarding is %s%s", "on", VTY_NEWLINE
);
2387 vty_out (vty
, "ipv6 forwarding is %s%s", "off", VTY_NEWLINE
);
2393 DEFUN (ipv6_forwarding
,
2394 ipv6_forwarding_cmd
,
2397 "Turn on IPv6 forwarding")
2401 ret
= ipforward_ipv6 ();
2403 ret
= ipforward_ipv6_on ();
2407 vty_out (vty
, "Can't turn on IPv6 forwarding%s", VTY_NEWLINE
);
2414 DEFUN (no_ipv6_forwarding
,
2415 no_ipv6_forwarding_cmd
,
2416 "no ipv6 forwarding",
2419 "Turn off IPv6 forwarding")
2423 ret
= ipforward_ipv6 ();
2425 ret
= ipforward_ipv6_off ();
2429 vty_out (vty
, "Can't turn off IPv6 forwarding%s", VTY_NEWLINE
);
2436 #endif /* HAVE_IPV6 */
2438 /* IPForwarding configuration write function. */
2440 config_write_forwarding (struct vty
*vty
)
2442 /* FIXME: Find better place for that. */
2443 router_id_write (vty
);
2446 vty_out (vty
, "ip forwarding%s", VTY_NEWLINE
);
2448 if (ipforward_ipv6 ())
2449 vty_out (vty
, "ipv6 forwarding%s", VTY_NEWLINE
);
2450 #endif /* HAVE_IPV6 */
2451 vty_out (vty
, "!%s", VTY_NEWLINE
);
2455 /* table node for routing tables. */
2456 static struct cmd_node forwarding_node
=
2459 "", /* This node has no interface. */
2464 /* Initialisation of zebra and installation of commands. */
2468 /* Client list init. */
2469 zebrad
.client_list
= list_new ();
2471 /* Install configuration write function. */
2472 install_node (&table_node
, config_write_table
);
2473 install_node (&forwarding_node
, config_write_forwarding
);
2475 install_element (VIEW_NODE
, &show_ip_forwarding_cmd
);
2476 install_element (ENABLE_NODE
, &show_ip_forwarding_cmd
);
2477 install_element (CONFIG_NODE
, &ip_forwarding_cmd
);
2478 install_element (CONFIG_NODE
, &no_ip_forwarding_cmd
);
2479 install_element (ENABLE_NODE
, &show_zebra_client_cmd
);
2480 install_element (ENABLE_NODE
, &show_zebra_client_summary_cmd
);
2483 install_element (VIEW_NODE
, &show_table_cmd
);
2484 install_element (ENABLE_NODE
, &show_table_cmd
);
2485 install_element (CONFIG_NODE
, &config_table_cmd
);
2486 #endif /* HAVE_NETLINK */
2489 install_element (VIEW_NODE
, &show_ipv6_forwarding_cmd
);
2490 install_element (ENABLE_NODE
, &show_ipv6_forwarding_cmd
);
2491 install_element (CONFIG_NODE
, &ipv6_forwarding_cmd
);
2492 install_element (CONFIG_NODE
, &no_ipv6_forwarding_cmd
);
2493 #endif /* HAVE_IPV6 */
2496 zebra_route_map_init ();
2499 /* Make zebra server socket, wiping any existing one (see bug #403). */
2501 zebra_zserv_socket_init (char *path
)
2503 #ifdef HAVE_TCP_ZEBRA
2506 zebra_serv_un (path
? path
: ZEBRA_SERV_PATH
);
2507 #endif /* HAVE_TCP_ZEBRA */