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"
37 #include "zebra/zserv.h"
38 #include "zebra/redistribute.h"
39 #include "zebra/debug.h"
40 #include "zebra/ipforward.h"
42 /* Event list of zebra. */
43 enum event
{ ZEBRA_SERV
, ZEBRA_READ
, ZEBRA_WRITE
};
45 /* Zebra client list. */
48 /* Default rtm_table for all clients */
49 int rtm_table_default
= 0;
51 void zebra_event (enum event event
, int sock
, struct zserv
*client
);
53 extern struct thread_master
*master
;
55 /* For logging of zebra meesages. */
56 char *zebra_command_str
[] =
59 "ZEBRA_INTERFACE_ADD",
60 "ZEBRA_INTERFACE_DELETE",
61 "ZEBRA_INTERFACE_ADDRESS_ADD",
62 "ZEBRA_INTERFACE_ADDRESS_DELETE",
64 "ZEBRA_INTERFACE_DOWN",
65 "ZEBRA_IPV4_ROUTE_ADD",
66 "ZEBRA_IPV4_ROUTE_DELETE",
67 "ZEBRA_IPV6_ROUTE_ADD",
68 "ZEBRA_IPV6_ROUTE_DELETE",
69 "ZEBRA_REDISTRIBUTE_ADD",
70 "ZEBRA_REDISTRIBUTE_DELETE",
71 "ZEBRA_REDISTRIBUTE_DEFAULT_ADD",
72 "ZEBRA_REDISTRIBUTE_DEFAULT_DELETE",
73 "ZEBRA_IPV4_NEXTHOP_LOOKUP",
74 "ZEBRA_IPV6_NEXTHOP_LOOKUP",
75 "ZEBRA_IPV4_IMPORT_LOOKUP",
76 "ZEBRA_IPV6_IMPORT_LOOKUP"
79 struct zebra_message_queue
81 struct nsm_message_queue
*next
;
82 struct nsm_message_queue
*prev
;
89 struct thread
*t_write
;
90 struct fifo message_queue
;
93 zebra_server_dequeue (struct thread
*t
)
97 struct zebra_message_queue
*queue
;
102 queue
= (struct zebra_message_queue
*) FIFO_HEAD (&message_queue
);
105 nbytes
= write (sock
, queue
->buf
+ queue
->written
,
106 queue
->length
- queue
->written
);
113 else if (nbytes
!= (queue
->length
- queue
->written
))
115 queue
->written
+= nbytes
;
120 XFREE (MTYPE_TMP
, queue
->buf
);
121 XFREE (MTYPE_TMP
, queue
);
125 if (FIFO_TOP (&message_queue
))
126 THREAD_WRITE_ON (master
, t_write
, zebra_server_dequeue
, NULL
, sock
);
131 /* Enqueu message. */
133 zebra_server_enqueue (int sock
, u_char
*buf
, unsigned long length
,
134 unsigned long written
)
136 struct zebra_message_queue
*queue
;
138 queue
= XCALLOC (MTYPE_TMP
, sizeof (struct zebra_message_queue
));
139 queue
->buf
= XMALLOC (MTYPE_TMP
, length
);
140 memcpy (queue
->buf
, buf
, length
);
141 queue
->length
= length
;
142 queue
->written
= written
;
144 FIFO_ADD (&message_queue
, queue
);
146 THREAD_WRITE_ON (master
, t_write
, zebra_server_dequeue
, NULL
, sock
);
150 zebra_server_send_message (int sock
, u_char
*buf
, unsigned long length
)
154 if (FIFO_TOP (&message_queue
))
156 zebra_server_enqueue (sock
, buf
, length
, 0);
161 nbytes
= write (sock
, buf
, length
);
166 zebra_server_enqueue (sock
, buf
, length
, 0);
170 else if (nbytes
!= length
)
171 zebra_server_enqueue (sock
, buf
, length
, nbytes
);
176 /* Interface is added. Send ZEBRA_INTERFACE_ADD to client. */
178 zsend_interface_add (struct zserv
*client
, struct interface
*ifp
)
182 /* Check this client need interface information. */
183 if (! client
->ifinfo
)
189 /* Place holder for size. */
193 stream_putc (s
, ZEBRA_INTERFACE_ADD
);
195 /* Interface information. */
196 stream_put (s
, ifp
->name
, INTERFACE_NAMSIZ
);
197 stream_putl (s
, ifp
->ifindex
);
198 stream_putc (s
, ifp
->status
);
199 stream_putl (s
, ifp
->flags
);
200 stream_putl (s
, ifp
->metric
);
201 stream_putl (s
, ifp
->mtu
);
202 stream_putl (s
, ifp
->bandwidth
);
203 #ifdef HAVE_SOCKADDR_DL
204 stream_put (s
, &ifp
->sdl
, sizeof (ifp
->sdl
));
206 stream_putl (s
, ifp
->hw_addr_len
);
207 if (ifp
->hw_addr_len
)
208 stream_put (s
, ifp
->hw_addr
, ifp
->hw_addr_len
);
209 #endif /* HAVE_SOCKADDR_DL */
211 /* Write packet size. */
212 stream_putw_at (s
, 0, stream_get_endp (s
));
214 zebra_server_send_message (client
->sock
, s
->data
, stream_get_endp (s
));
219 /* Interface deletion from zebra daemon. */
221 zsend_interface_delete (struct zserv
*client
, struct interface
*ifp
)
225 /* Check this client need interface information. */
226 if (! client
->ifinfo
)
232 /* Packet length placeholder. */
235 /* Interface information. */
236 stream_putc (s
, ZEBRA_INTERFACE_DELETE
);
237 stream_put (s
, ifp
->name
, INTERFACE_NAMSIZ
);
238 stream_putl (s
, ifp
->ifindex
);
239 stream_putc (s
, ifp
->status
);
240 stream_putl (s
, ifp
->flags
);
241 stream_putl (s
, ifp
->metric
);
242 stream_putl (s
, ifp
->mtu
);
243 stream_putl (s
, ifp
->bandwidth
);
245 /* Write packet length. */
246 stream_putw_at (s
, 0, stream_get_endp (s
));
248 zebra_server_send_message (client
->sock
, s
->data
, stream_get_endp (s
));
253 /* Interface address is added. Send ZEBRA_INTERFACE_ADDRESS_ADD to the
256 zsend_interface_address_add (struct zserv
*client
, struct interface
*ifp
,
257 struct connected
*ifc
)
263 /* Check this client need interface information. */
264 if (! client
->ifinfo
)
270 /* Place holder for size. */
273 stream_putc (s
, ZEBRA_INTERFACE_ADDRESS_ADD
);
274 stream_putl (s
, ifp
->ifindex
);
276 /* Interface address flag. */
277 stream_putc (s
, ifc
->flags
);
279 /* Prefix information. */
281 stream_putc (s
, p
->family
);
282 blen
= prefix_blen (p
);
283 stream_put (s
, &p
->u
.prefix
, blen
);
284 stream_putc (s
, p
->prefixlen
);
287 p
= ifc
->destination
;
289 stream_put (s
, &p
->u
.prefix
, blen
);
291 stream_put (s
, NULL
, blen
);
293 /* Write packet size. */
294 stream_putw_at (s
, 0, stream_get_endp (s
));
296 zebra_server_send_message (client
->sock
, s
->data
, stream_get_endp (s
));
301 /* Interface address is deleted. Send ZEBRA_INTERFACE_ADDRESS_DELETE
304 zsend_interface_address_delete (struct zserv
*client
, struct interface
*ifp
,
305 struct connected
*ifc
)
311 /* Check this client need interface information. */
312 if (! client
->ifinfo
)
318 /* Place holder for size. */
321 stream_putc (s
, ZEBRA_INTERFACE_ADDRESS_DELETE
);
322 stream_putl (s
, ifp
->ifindex
);
324 /* Interface address flag. */
325 stream_putc (s
, ifc
->flags
);
327 /* Prefix information. */
329 stream_putc (s
, p
->family
);
330 blen
= prefix_blen (p
);
331 stream_put (s
, &p
->u
.prefix
, blen
);
333 p
= ifc
->destination
;
335 stream_put (s
, &p
->u
.prefix
, blen
);
337 stream_put (s
, NULL
, blen
);
339 /* Write packet size. */
340 stream_putw_at (s
, 0, stream_get_endp (s
));
342 zebra_server_send_message (client
->sock
, s
->data
, stream_get_endp (s
));
348 zsend_interface_up (struct zserv
*client
, struct interface
*ifp
)
352 /* Check this client need interface information. */
353 if (! client
->ifinfo
)
359 /* Place holder for size. */
363 stream_putc (s
, ZEBRA_INTERFACE_UP
);
365 /* Interface information. */
366 stream_put (s
, ifp
->name
, INTERFACE_NAMSIZ
);
367 stream_putl (s
, ifp
->ifindex
);
368 stream_putc (s
, ifp
->status
);
369 stream_putl (s
, ifp
->flags
);
370 stream_putl (s
, ifp
->metric
);
371 stream_putl (s
, ifp
->mtu
);
372 stream_putl (s
, ifp
->bandwidth
);
374 /* Write packet size. */
375 stream_putw_at (s
, 0, stream_get_endp (s
));
377 zebra_server_send_message (client
->sock
, s
->data
, stream_get_endp (s
));
383 zsend_interface_down (struct zserv
*client
, struct interface
*ifp
)
387 /* Check this client need interface information. */
388 if (! client
->ifinfo
)
394 /* Place holder for size. */
398 stream_putc (s
, ZEBRA_INTERFACE_DOWN
);
400 /* Interface information. */
401 stream_put (s
, ifp
->name
, INTERFACE_NAMSIZ
);
402 stream_putl (s
, ifp
->ifindex
);
403 stream_putc (s
, ifp
->status
);
404 stream_putl (s
, ifp
->flags
);
405 stream_putl (s
, ifp
->metric
);
406 stream_putl (s
, ifp
->mtu
);
407 stream_putl (s
, ifp
->bandwidth
);
409 /* Write packet size. */
410 stream_putw_at (s
, 0, stream_get_endp (s
));
412 zebra_server_send_message (client
->sock
, s
->data
, stream_get_endp (s
));
418 zsend_ipv4_add_multipath (struct zserv
*client
, struct prefix
*p
,
423 struct nexthop
*nexthop
;
424 struct in_addr empty
;
430 /* Place holder for size. */
433 /* Put command, type and nexthop. */
434 stream_putc (s
, ZEBRA_IPV4_ROUTE_ADD
);
435 stream_putc (s
, rib
->type
);
436 stream_putc (s
, rib
->flags
);
437 stream_putc (s
, ZAPI_MESSAGE_NEXTHOP
| ZAPI_MESSAGE_IFINDEX
| ZAPI_MESSAGE_METRIC
);
440 psize
= PSIZE (p
->prefixlen
);
441 stream_putc (s
, p
->prefixlen
);
442 stream_write (s
, (u_char
*)&p
->u
.prefix
, psize
);
445 for (nexthop
= rib
->nexthop
; nexthop
; nexthop
= nexthop
->next
)
447 if (CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_FIB
))
451 if (nexthop
->type
== NEXTHOP_TYPE_IPV4
452 || nexthop
->type
== NEXTHOP_TYPE_IPV4_IFINDEX
)
453 stream_put_in_addr (s
, &nexthop
->gate
.ipv4
);
455 stream_put_in_addr (s
, &empty
);
457 /* Interface index. */
459 stream_putl (s
, nexthop
->ifindex
);
466 stream_putl (s
, rib
->metric
);
468 /* Write packet size. */
469 stream_putw_at (s
, 0, stream_get_endp (s
));
471 zebra_server_send_message (client
->sock
, s
->data
, stream_get_endp (s
));
477 zsend_ipv4_delete_multipath (struct zserv
*client
, struct prefix
*p
,
482 struct nexthop
*nexthop
;
483 struct in_addr empty
;
490 /* Place holder for size. */
493 /* Put command, type and nexthop. */
494 stream_putc (s
, ZEBRA_IPV4_ROUTE_DELETE
);
495 stream_putc (s
, rib
->type
);
496 stream_putc (s
, rib
->flags
);
497 stream_putc (s
, ZAPI_MESSAGE_NEXTHOP
|ZAPI_MESSAGE_IFINDEX
);
500 psize
= PSIZE (p
->prefixlen
);
501 stream_putc (s
, p
->prefixlen
);
502 stream_write (s
, (u_char
*)&p
->u
.prefix
, psize
);
505 for (nexthop
= rib
->nexthop
; nexthop
; nexthop
= nexthop
->next
)
507 if (CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_FIB
))
511 if (nexthop
->type
== NEXTHOP_TYPE_IPV4
)
512 stream_put_in_addr (s
, &nexthop
->gate
.ipv4
);
514 stream_put_in_addr (s
, &empty
);
516 /* Interface index. */
518 stream_putl (s
, nexthop
->ifindex
);
524 /* Write packet size. */
525 stream_putw_at (s
, 0, stream_get_endp (s
));
527 zebra_server_send_message (client
->sock
, s
->data
, stream_get_endp (s
));
533 zsend_ipv4_add (struct zserv
*client
, int type
, int flags
,
534 struct prefix_ipv4
*p
, struct in_addr
*nexthop
,
535 unsigned int ifindex
)
543 /* Place holder for size. */
546 /* Put command, type and nexthop. */
547 stream_putc (s
, ZEBRA_IPV4_ROUTE_ADD
);
548 stream_putc (s
, type
);
549 stream_putc (s
, flags
);
550 stream_putc (s
, ZAPI_MESSAGE_NEXTHOP
|ZAPI_MESSAGE_IFINDEX
);
553 psize
= PSIZE (p
->prefixlen
);
554 stream_putc (s
, p
->prefixlen
);
555 stream_write (s
, (u_char
*)&p
->prefix
, psize
);
559 stream_put_in_addr (s
, nexthop
);
561 /* Interface index. */
563 stream_putl (s
, ifindex
);
565 /* Write packet size. */
566 stream_putw_at (s
, 0, stream_get_endp (s
));
568 zebra_server_send_message (client
->sock
, s
->data
, stream_get_endp (s
));
574 zsend_ipv4_delete (struct zserv
*client
, int type
, int flags
,
575 struct prefix_ipv4
*p
, struct in_addr
*nexthop
,
576 unsigned int ifindex
)
584 /* Place holder for size. */
587 /* Put command, type and nexthop. */
588 stream_putc (s
, ZEBRA_IPV4_ROUTE_DELETE
);
589 stream_putc (s
, type
);
590 stream_putc (s
, flags
);
591 stream_putc (s
, ZAPI_MESSAGE_NEXTHOP
|ZAPI_MESSAGE_IFINDEX
);
594 psize
= PSIZE (p
->prefixlen
);
595 stream_putc (s
, p
->prefixlen
);
596 stream_write (s
, (u_char
*)&p
->prefix
, psize
);
600 stream_put_in_addr (s
, nexthop
);
602 /* Interface index. */
604 stream_putl (s
, ifindex
);
606 /* Write packet size. */
607 stream_putw_at (s
, 0, stream_get_endp (s
));
609 zebra_server_send_message (client
->sock
, s
->data
, stream_get_endp (s
));
616 zsend_ipv6_add (struct zserv
*client
, int type
, int flags
,
617 struct prefix_ipv6
*p
, struct in6_addr
*nexthop
,
618 unsigned int ifindex
)
626 /* Place holder for size. */
629 /* Put command, type and nexthop. */
630 stream_putc (s
, ZEBRA_IPV6_ROUTE_ADD
);
631 stream_putc (s
, type
);
632 stream_putc (s
, flags
);
633 stream_putc (s
, ZAPI_MESSAGE_NEXTHOP
|ZAPI_MESSAGE_IFINDEX
);
636 psize
= PSIZE (p
->prefixlen
);
637 stream_putc (s
, p
->prefixlen
);
638 stream_write (s
, (u_char
*)&p
->prefix
, psize
);
642 stream_write (s
, (u_char
*)nexthop
, 16);
644 /* Interface index. */
646 stream_putl (s
, ifindex
);
648 /* Write packet size. */
649 stream_putw_at (s
, 0, stream_get_endp (s
));
651 zebra_server_send_message (client
->sock
, s
->data
, stream_get_endp (s
));
657 zsend_ipv6_add_multipath (struct zserv
*client
, struct prefix
*p
,
662 struct nexthop
*nexthop
;
663 struct in6_addr empty
;
665 memset (&empty
, 0, sizeof (struct in6_addr
));
669 /* Place holder for size. */
672 /* Put command, type and nexthop. */
673 stream_putc (s
, ZEBRA_IPV6_ROUTE_ADD
);
674 stream_putc (s
, rib
->type
);
675 stream_putc (s
, rib
->flags
);
676 stream_putc (s
, ZAPI_MESSAGE_NEXTHOP
| ZAPI_MESSAGE_IFINDEX
| ZAPI_MESSAGE_METRIC
);
679 psize
= PSIZE (p
->prefixlen
);
680 stream_putc (s
, p
->prefixlen
);
681 stream_write (s
, (u_char
*) &p
->u
.prefix
, psize
);
684 for (nexthop
= rib
->nexthop
; nexthop
; nexthop
= nexthop
->next
)
686 if (CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_FIB
))
690 if (nexthop
->type
== NEXTHOP_TYPE_IPV6
)
691 stream_write (s
, (u_char
*) &nexthop
->gate
.ipv6
, 16);
693 stream_write (s
, (u_char
*) &empty
, 16);
695 /* Interface index. */
697 stream_putl (s
, nexthop
->ifindex
);
704 stream_putl (s
, rib
->metric
);
706 /* Write packet size. */
707 stream_putw_at (s
, 0, stream_get_endp (s
));
709 zebra_server_send_message (client
->sock
, s
->data
, stream_get_endp (s
));
715 zsend_ipv6_delete (struct zserv
*client
, int type
, int flags
,
716 struct prefix_ipv6
*p
, struct in6_addr
*nexthop
,
717 unsigned int ifindex
)
725 /* Place holder for size. */
728 /* Put command, type and nexthop. */
729 stream_putc (s
, ZEBRA_IPV6_ROUTE_DELETE
);
730 stream_putc (s
, type
);
731 stream_putc (s
, flags
);
732 stream_putc (s
, ZAPI_MESSAGE_NEXTHOP
|ZAPI_MESSAGE_IFINDEX
);
735 psize
= PSIZE (p
->prefixlen
);
736 stream_putc (s
, p
->prefixlen
);
737 stream_write (s
, (u_char
*)&p
->prefix
, psize
);
741 stream_write (s
, (u_char
*)nexthop
, 16);
743 /* Interface index. */
745 stream_putl (s
, ifindex
);
747 /* Write packet size. */
748 stream_putw_at (s
, 0, stream_get_endp (s
));
750 zebra_server_send_message (client
->sock
, s
->data
, stream_get_endp (s
));
756 zsend_ipv6_delete_multipath (struct zserv
*client
, struct prefix
*p
,
761 struct nexthop
*nexthop
;
762 struct in6_addr empty
;
764 memset (&empty
, 0, sizeof (struct in6_addr
));
768 /* Place holder for size. */
771 /* Put command, type and nexthop. */
772 stream_putc (s
, ZEBRA_IPV6_ROUTE_DELETE
);
773 stream_putc (s
, rib
->type
);
774 stream_putc (s
, rib
->flags
);
775 stream_putc (s
, ZAPI_MESSAGE_NEXTHOP
|ZAPI_MESSAGE_IFINDEX
);
778 psize
= PSIZE (p
->prefixlen
);
779 stream_putc (s
, p
->prefixlen
);
780 stream_write (s
, (u_char
*)&p
->u
.prefix
, psize
);
783 for (nexthop
= rib
->nexthop
; nexthop
; nexthop
= nexthop
->next
)
785 if (CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_FIB
))
789 if (nexthop
->type
== NEXTHOP_TYPE_IPV6
)
790 stream_write (s
, (u_char
*) &nexthop
->gate
.ipv6
, 16);
792 stream_write (s
, (u_char
*) &empty
, 16);
794 /* Interface index. */
796 stream_putl (s
, nexthop
->ifindex
);
802 /* Write packet size. */
803 stream_putw_at (s
, 0, stream_get_endp (s
));
805 zebra_server_send_message (client
->sock
, s
->data
, stream_get_endp (s
));
811 zsend_ipv6_nexthop_lookup (struct zserv
*client
, struct in6_addr
*addr
)
817 struct nexthop
*nexthop
;
819 /* Lookup nexthop. */
820 rib
= rib_match_ipv6 (addr
);
822 /* Get output stream. */
826 /* Fill in result. */
828 stream_putc (s
, ZEBRA_IPV6_NEXTHOP_LOOKUP
);
829 stream_put (s
, &addr
, 16);
833 stream_putl (s
, rib
->metric
);
837 for (nexthop
= rib
->nexthop
; nexthop
; nexthop
= nexthop
->next
)
838 if (CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_FIB
))
840 stream_putc (s
, nexthop
->type
);
841 switch (nexthop
->type
)
843 case ZEBRA_NEXTHOP_IPV6
:
844 stream_put (s
, &nexthop
->gate
.ipv6
, 16);
846 case ZEBRA_NEXTHOP_IPV6_IFINDEX
:
847 case ZEBRA_NEXTHOP_IPV6_IFNAME
:
848 stream_put (s
, &nexthop
->gate
.ipv6
, 16);
849 stream_putl (s
, nexthop
->ifindex
);
851 case ZEBRA_NEXTHOP_IFINDEX
:
852 case ZEBRA_NEXTHOP_IFNAME
:
853 stream_putl (s
, nexthop
->ifindex
);
858 stream_putc_at (s
, nump
, num
);
866 stream_putw_at (s
, 0, stream_get_endp (s
));
868 zebra_server_send_message (client
->sock
, s
->data
, stream_get_endp (s
));
872 #endif /* HAVE_IPV6 */
875 zsend_ipv4_nexthop_lookup (struct zserv
*client
, struct in_addr addr
)
881 struct nexthop
*nexthop
;
883 /* Lookup nexthop. */
884 rib
= rib_match_ipv4 (addr
);
886 /* Get output stream. */
890 /* Fill in result. */
892 stream_putc (s
, ZEBRA_IPV4_NEXTHOP_LOOKUP
);
893 stream_put_in_addr (s
, &addr
);
897 stream_putl (s
, rib
->metric
);
901 for (nexthop
= rib
->nexthop
; nexthop
; nexthop
= nexthop
->next
)
902 if (CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_FIB
))
904 stream_putc (s
, nexthop
->type
);
905 switch (nexthop
->type
)
907 case ZEBRA_NEXTHOP_IPV4
:
908 stream_put_in_addr (s
, &nexthop
->gate
.ipv4
);
910 case ZEBRA_NEXTHOP_IFINDEX
:
911 case ZEBRA_NEXTHOP_IFNAME
:
912 stream_putl (s
, nexthop
->ifindex
);
917 stream_putc_at (s
, nump
, num
);
925 stream_putw_at (s
, 0, stream_get_endp (s
));
927 zebra_server_send_message (client
->sock
, s
->data
, stream_get_endp (s
));
933 zsend_ipv4_import_lookup (struct zserv
*client
, struct prefix_ipv4
*p
)
939 struct nexthop
*nexthop
;
941 /* Lookup nexthop. */
942 rib
= rib_lookup_ipv4 (p
);
944 /* Get output stream. */
948 /* Fill in result. */
950 stream_putc (s
, ZEBRA_IPV4_IMPORT_LOOKUP
);
951 stream_put_in_addr (s
, &p
->prefix
);
955 stream_putl (s
, rib
->metric
);
959 for (nexthop
= rib
->nexthop
; nexthop
; nexthop
= nexthop
->next
)
960 if (CHECK_FLAG (nexthop
->flags
, NEXTHOP_FLAG_FIB
))
962 stream_putc (s
, nexthop
->type
);
963 switch (nexthop
->type
)
965 case ZEBRA_NEXTHOP_IPV4
:
966 stream_put_in_addr (s
, &nexthop
->gate
.ipv4
);
968 case ZEBRA_NEXTHOP_IFINDEX
:
969 case ZEBRA_NEXTHOP_IFNAME
:
970 stream_putl (s
, nexthop
->ifindex
);
975 stream_putc_at (s
, nump
, num
);
983 stream_putw_at (s
, 0, stream_get_endp (s
));
985 zebra_server_send_message (client
->sock
, s
->data
, stream_get_endp (s
));
990 /* Register zebra server interface information. Send current all
991 interface and address information. */
993 zread_interface_add (struct zserv
*client
, u_short length
)
997 struct interface
*ifp
;
1000 /* Interface information is needed. */
1003 for (ifnode
= listhead (iflist
); ifnode
; ifnode
= nextnode (ifnode
))
1005 ifp
= getdata (ifnode
);
1007 /* Skip pseudo interface. */
1008 if (! CHECK_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
))
1011 zsend_interface_add (client
, ifp
);
1013 for (cnode
= listhead (ifp
->connected
); cnode
; nextnode (cnode
))
1015 c
= getdata (cnode
);
1016 if (CHECK_FLAG (c
->conf
, ZEBRA_IFC_REAL
))
1017 zsend_interface_address_add (client
, ifp
, c
);
1022 /* Unregister zebra server interface information. */
1024 zread_interface_delete (struct zserv
*client
, u_short length
)
1029 /* This function support multiple nexthop. */
1031 zread_ipv4_add (struct zserv
*client
, u_short length
)
1035 struct prefix_ipv4 p
;
1037 struct in_addr nexthop
;
1039 u_char nexthop_type
;
1041 unsigned int ifindex
;
1044 /* Get input stream. */
1047 /* Allocate new rib. */
1048 rib
= XMALLOC (MTYPE_RIB
, sizeof (struct rib
));
1049 memset (rib
, 0, sizeof (struct rib
));
1051 /* Type, flags, message. */
1052 rib
->type
= stream_getc (s
);
1053 rib
->flags
= stream_getc (s
);
1054 message
= stream_getc (s
);
1055 rib
->uptime
= time (NULL
);
1058 memset (&p
, 0, sizeof (struct prefix_ipv4
));
1060 p
.prefixlen
= stream_getc (s
);
1061 stream_get (&p
.prefix
, s
, PSIZE (p
.prefixlen
));
1063 /* Nexthop parse. */
1064 if (CHECK_FLAG (message
, ZAPI_MESSAGE_NEXTHOP
))
1066 nexthop_num
= stream_getc (s
);
1068 for (i
= 0; i
< nexthop_num
; i
++)
1070 nexthop_type
= stream_getc (s
);
1072 switch (nexthop_type
)
1074 case ZEBRA_NEXTHOP_IFINDEX
:
1075 ifindex
= stream_getl (s
);
1076 nexthop_ifindex_add (rib
, ifindex
);
1078 case ZEBRA_NEXTHOP_IFNAME
:
1079 ifname_len
= stream_getc (s
);
1080 stream_forward (s
, ifname_len
);
1082 case ZEBRA_NEXTHOP_IPV4
:
1083 nexthop
.s_addr
= stream_get_ipv4 (s
);
1084 nexthop_ipv4_add (rib
, &nexthop
);
1086 case ZEBRA_NEXTHOP_IPV6
:
1087 stream_forward (s
, IPV6_MAX_BYTELEN
);
1094 if (CHECK_FLAG (message
, ZAPI_MESSAGE_DISTANCE
))
1095 rib
->distance
= stream_getc (s
);
1098 if (CHECK_FLAG (message
, ZAPI_MESSAGE_METRIC
))
1099 rib
->metric
= stream_getl (s
);
1101 rib_add_ipv4_multipath (&p
, rib
);
1104 /* Zebra server IPv4 prefix delete function. */
1106 zread_ipv4_delete (struct zserv
*client
, u_short length
)
1110 struct zapi_ipv4 api
;
1111 struct in_addr nexthop
;
1112 unsigned long ifindex
;
1113 struct prefix_ipv4 p
;
1115 u_char nexthop_type
;
1122 /* Type, flags, message. */
1123 api
.type
= stream_getc (s
);
1124 api
.flags
= stream_getc (s
);
1125 api
.message
= stream_getc (s
);
1128 memset (&p
, 0, sizeof (struct prefix_ipv4
));
1130 p
.prefixlen
= stream_getc (s
);
1131 stream_get (&p
.prefix
, s
, PSIZE (p
.prefixlen
));
1133 /* Nexthop, ifindex, distance, metric. */
1134 if (CHECK_FLAG (api
.message
, ZAPI_MESSAGE_NEXTHOP
))
1136 nexthop_num
= stream_getc (s
);
1138 for (i
= 0; i
< nexthop_num
; i
++)
1140 nexthop_type
= stream_getc (s
);
1142 switch (nexthop_type
)
1144 case ZEBRA_NEXTHOP_IFINDEX
:
1145 ifindex
= stream_getl (s
);
1147 case ZEBRA_NEXTHOP_IFNAME
:
1148 ifname_len
= stream_getc (s
);
1149 stream_forward (s
, ifname_len
);
1151 case ZEBRA_NEXTHOP_IPV4
:
1152 nexthop
.s_addr
= stream_get_ipv4 (s
);
1154 case ZEBRA_NEXTHOP_IPV6
:
1155 stream_forward (s
, IPV6_MAX_BYTELEN
);
1162 if (CHECK_FLAG (api
.message
, ZAPI_MESSAGE_DISTANCE
))
1163 api
.distance
= stream_getc (s
);
1168 if (CHECK_FLAG (api
.message
, ZAPI_MESSAGE_METRIC
))
1169 api
.metric
= stream_getl (s
);
1173 rib_delete_ipv4 (api
.type
, api
.flags
, &p
, &nexthop
, ifindex
,
1177 /* Nexthop lookup for IPv4. */
1179 zread_ipv4_nexthop_lookup (struct zserv
*client
, u_short length
)
1181 struct in_addr addr
;
1183 addr
.s_addr
= stream_get_ipv4 (client
->ibuf
);
1184 zsend_ipv4_nexthop_lookup (client
, addr
);
1187 /* Nexthop lookup for IPv4. */
1189 zread_ipv4_import_lookup (struct zserv
*client
, u_short length
)
1191 struct prefix_ipv4 p
;
1194 p
.prefixlen
= stream_getc (client
->ibuf
);
1195 p
.prefix
.s_addr
= stream_get_ipv4 (client
->ibuf
);
1197 zsend_ipv4_import_lookup (client
, &p
);
1201 /* Zebra server IPv6 prefix add function. */
1203 zread_ipv6_add (struct zserv
*client
, u_short length
)
1207 struct zapi_ipv6 api
;
1208 struct in6_addr nexthop
;
1209 unsigned long ifindex
;
1210 struct prefix_ipv6 p
;
1214 memset (&nexthop
, 0, sizeof (struct in6_addr
));
1216 /* Type, flags, message. */
1217 api
.type
= stream_getc (s
);
1218 api
.flags
= stream_getc (s
);
1219 api
.message
= stream_getc (s
);
1222 memset (&p
, 0, sizeof (struct prefix_ipv6
));
1223 p
.family
= AF_INET6
;
1224 p
.prefixlen
= stream_getc (s
);
1225 stream_get (&p
.prefix
, s
, PSIZE (p
.prefixlen
));
1227 /* Nexthop, ifindex, distance, metric. */
1228 if (CHECK_FLAG (api
.message
, ZAPI_MESSAGE_NEXTHOP
))
1230 u_char nexthop_type
;
1232 api
.nexthop_num
= stream_getc (s
);
1233 for (i
= 0; i
< api
.nexthop_num
; i
++)
1235 nexthop_type
= stream_getc (s
);
1237 switch (nexthop_type
)
1239 case ZEBRA_NEXTHOP_IPV6
:
1240 stream_get (&nexthop
, s
, 16);
1242 case ZEBRA_NEXTHOP_IFINDEX
:
1243 ifindex
= stream_getl (s
);
1249 if (CHECK_FLAG (api
.message
, ZAPI_MESSAGE_DISTANCE
))
1250 api
.distance
= stream_getc (s
);
1254 if (CHECK_FLAG (api
.message
, ZAPI_MESSAGE_METRIC
))
1255 api
.metric
= stream_getl (s
);
1259 if (IN6_IS_ADDR_UNSPECIFIED (&nexthop
))
1260 rib_add_ipv6 (api
.type
, api
.flags
, &p
, NULL
, ifindex
, 0);
1262 rib_add_ipv6 (api
.type
, api
.flags
, &p
, &nexthop
, ifindex
, 0);
1265 /* Zebra server IPv6 prefix delete function. */
1267 zread_ipv6_delete (struct zserv
*client
, u_short length
)
1271 struct zapi_ipv6 api
;
1272 struct in6_addr nexthop
;
1273 unsigned long ifindex
;
1274 struct prefix_ipv6 p
;
1278 memset (&nexthop
, 0, sizeof (struct in6_addr
));
1280 /* Type, flags, message. */
1281 api
.type
= stream_getc (s
);
1282 api
.flags
= stream_getc (s
);
1283 api
.message
= stream_getc (s
);
1286 memset (&p
, 0, sizeof (struct prefix_ipv6
));
1287 p
.family
= AF_INET6
;
1288 p
.prefixlen
= stream_getc (s
);
1289 stream_get (&p
.prefix
, s
, PSIZE (p
.prefixlen
));
1291 /* Nexthop, ifindex, distance, metric. */
1292 if (CHECK_FLAG (api
.message
, ZAPI_MESSAGE_NEXTHOP
))
1294 u_char nexthop_type
;
1296 api
.nexthop_num
= stream_getc (s
);
1297 for (i
= 0; i
< api
.nexthop_num
; i
++)
1299 nexthop_type
= stream_getc (s
);
1301 switch (nexthop_type
)
1303 case ZEBRA_NEXTHOP_IPV6
:
1304 stream_get (&nexthop
, s
, 16);
1306 case ZEBRA_NEXTHOP_IFINDEX
:
1307 ifindex
= stream_getl (s
);
1313 if (CHECK_FLAG (api
.message
, ZAPI_MESSAGE_DISTANCE
))
1314 api
.distance
= stream_getc (s
);
1317 if (CHECK_FLAG (api
.message
, ZAPI_MESSAGE_METRIC
))
1318 api
.metric
= stream_getl (s
);
1322 if (IN6_IS_ADDR_UNSPECIFIED (&nexthop
))
1323 rib_delete_ipv6 (api
.type
, api
.flags
, &p
, NULL
, ifindex
, 0);
1325 rib_delete_ipv6 (api
.type
, api
.flags
, &p
, &nexthop
, ifindex
, 0);
1329 zebra_read_ipv6 (int command
, struct zserv
*client
, u_short length
)
1333 struct in6_addr nexthop
, *gate
;
1336 unsigned int ifindex
;
1338 pnt
= stream_pnt (client
->ibuf
);
1341 type
= stream_getc (client
->ibuf
);
1342 flags
= stream_getc (client
->ibuf
);
1343 stream_get (&nexthop
, client
->ibuf
, sizeof (struct in6_addr
));
1345 while (stream_pnt (client
->ibuf
) < lim
)
1348 struct prefix_ipv6 p
;
1350 ifindex
= stream_getl (client
->ibuf
);
1352 memset (&p
, 0, sizeof (struct prefix_ipv6
));
1353 p
.family
= AF_INET6
;
1354 p
.prefixlen
= stream_getc (client
->ibuf
);
1355 size
= PSIZE(p
.prefixlen
);
1356 stream_get (&p
.prefix
, client
->ibuf
, size
);
1358 if (IN6_IS_ADDR_UNSPECIFIED (&nexthop
))
1363 if (command
== ZEBRA_IPV6_ROUTE_ADD
)
1364 rib_add_ipv6 (type
, flags
, &p
, gate
, ifindex
, 0);
1366 rib_delete_ipv6 (type
, flags
, &p
, gate
, ifindex
, 0);
1371 zread_ipv6_nexthop_lookup (struct zserv
*client
, u_short length
)
1373 struct in6_addr addr
;
1376 stream_get (&addr
, client
->ibuf
, 16);
1377 printf ("DEBUG %s\n", inet_ntop (AF_INET6
, &addr
, buf
, BUFSIZ
));
1379 zsend_ipv6_nexthop_lookup (client
, &addr
);
1381 #endif /* HAVE_IPV6 */
1383 /* Close zebra client. */
1385 zebra_client_close (struct zserv
*client
)
1387 /* Close file descriptor. */
1390 close (client
->sock
);
1394 /* Free stream buffers. */
1396 stream_free (client
->ibuf
);
1398 stream_free (client
->obuf
);
1400 /* Release threads. */
1402 thread_cancel (client
->t_read
);
1403 if (client
->t_write
)
1404 thread_cancel (client
->t_write
);
1406 /* Free client structure. */
1407 listnode_delete (client_list
, client
);
1411 /* Make new client. */
1413 zebra_client_create (int sock
)
1415 struct zserv
*client
;
1417 client
= XCALLOC (0, sizeof (struct zserv
));
1419 /* Make client input/output buffer. */
1420 client
->sock
= sock
;
1421 client
->ibuf
= stream_new (ZEBRA_MAX_PACKET_SIZ
);
1422 client
->obuf
= stream_new (ZEBRA_MAX_PACKET_SIZ
);
1424 /* Set table number. */
1425 client
->rtm_table
= rtm_table_default
;
1427 /* Add this client to linked list. */
1428 listnode_add (client_list
, client
);
1430 /* Make new read thread. */
1431 zebra_event (ZEBRA_READ
, sock
, client
);
1434 /* Handler of zebra service request. */
1436 zebra_client_read (struct thread
*thread
)
1439 struct zserv
*client
;
1444 /* Get thread data. Reset reading thread because I'm running. */
1445 sock
= THREAD_FD (thread
);
1446 client
= THREAD_ARG (thread
);
1447 client
->t_read
= NULL
;
1449 /* Read length and command. */
1450 nbyte
= stream_read (client
->ibuf
, sock
, 3);
1453 if (IS_ZEBRA_DEBUG_EVENT
)
1454 zlog_info ("connection closed socket [%d]", sock
);
1455 zebra_client_close (client
);
1458 length
= stream_getw (client
->ibuf
);
1459 command
= stream_getc (client
->ibuf
);
1463 if (IS_ZEBRA_DEBUG_EVENT
)
1464 zlog_info ("length %d is less than 3 ", length
);
1465 zebra_client_close (client
);
1471 /* Read rest of data. */
1474 nbyte
= stream_read (client
->ibuf
, sock
, length
);
1477 if (IS_ZEBRA_DEBUG_EVENT
)
1478 zlog_info ("connection closed [%d] when reading zebra data", sock
);
1479 zebra_client_close (client
);
1484 /* Debug packet information. */
1485 if (IS_ZEBRA_DEBUG_EVENT
)
1486 zlog_info ("zebra message comes from socket [%d]", sock
);
1488 if (IS_ZEBRA_DEBUG_PACKET
&& IS_ZEBRA_DEBUG_RECV
)
1489 zlog_info ("zebra message received [%s] %d",
1490 zebra_command_str
[command
], length
);
1494 case ZEBRA_INTERFACE_ADD
:
1495 zread_interface_add (client
, length
);
1497 case ZEBRA_INTERFACE_DELETE
:
1498 zread_interface_delete (client
, length
);
1500 case ZEBRA_IPV4_ROUTE_ADD
:
1501 zread_ipv4_add (client
, length
);
1503 case ZEBRA_IPV4_ROUTE_DELETE
:
1504 zread_ipv4_delete (client
, length
);
1507 case ZEBRA_IPV6_ROUTE_ADD
:
1508 zread_ipv6_add (client
, length
);
1510 case ZEBRA_IPV6_ROUTE_DELETE
:
1511 zread_ipv6_delete (client
, length
);
1513 #endif /* HAVE_IPV6 */
1514 case ZEBRA_REDISTRIBUTE_ADD
:
1515 zebra_redistribute_add (command
, client
, length
);
1517 case ZEBRA_REDISTRIBUTE_DELETE
:
1518 zebra_redistribute_delete (command
, client
, length
);
1520 case ZEBRA_REDISTRIBUTE_DEFAULT_ADD
:
1521 zebra_redistribute_default_add (command
, client
, length
);
1523 case ZEBRA_REDISTRIBUTE_DEFAULT_DELETE
:
1524 zebra_redistribute_default_delete (command
, client
, length
);
1526 case ZEBRA_IPV4_NEXTHOP_LOOKUP
:
1527 zread_ipv4_nexthop_lookup (client
, length
);
1530 case ZEBRA_IPV6_NEXTHOP_LOOKUP
:
1531 zread_ipv6_nexthop_lookup (client
, length
);
1533 #endif /* HAVE_IPV6 */
1534 case ZEBRA_IPV4_IMPORT_LOOKUP
:
1535 zread_ipv4_import_lookup (client
, length
);
1538 zlog_info ("Zebra received unknown command %d", command
);
1542 stream_reset (client
->ibuf
);
1543 zebra_event (ZEBRA_READ
, sock
, client
);
1548 /* Write output buffer to the socket. */
1550 zebra_write (struct thread
*thread
)
1553 struct zserv
*client
;
1555 /* Thread treatment. */
1556 sock
= THREAD_FD (thread
);
1557 client
= THREAD_ARG (thread
);
1558 client
->t_write
= NULL
;
1560 stream_flush (client
->obuf
, sock
);
1563 /* Accept code of zebra server socket. */
1565 zebra_accept (struct thread
*thread
)
1570 struct sockaddr_in client
;
1573 accept_sock
= THREAD_FD (thread
);
1575 len
= sizeof (struct sockaddr_in
);
1576 client_sock
= accept (accept_sock
, (struct sockaddr
*) &client
, &len
);
1578 if (client_sock
< 0)
1580 zlog_warn ("Can't accept zebra socket: %s", strerror (errno
));
1584 /* Make client socket non-blocking. */
1586 val
= fcntl (client_sock
, F_GETFL
, 0);
1587 fcntl (client_sock
, F_SETFL
, (val
| O_NONBLOCK
));
1589 /* Create new zebra client. */
1590 zebra_client_create (client_sock
);
1592 /* Register myself. */
1593 zebra_event (ZEBRA_SERV
, accept_sock
, NULL
);
1598 /* Make zebra's server socket. */
1604 struct sockaddr_in addr
;
1606 accept_sock
= socket (AF_INET
, SOCK_STREAM
, 0);
1608 if (accept_sock
< 0)
1610 zlog_warn ("Can't bind to socket: %s", strerror (errno
));
1611 zlog_warn ("zebra can't provice full functionality due to above error");
1615 memset (&addr
, 0, sizeof (struct sockaddr_in
));
1616 addr
.sin_family
= AF_INET
;
1617 addr
.sin_port
= htons (ZEBRA_PORT
);
1619 addr
.sin_len
= sizeof (struct sockaddr_in
);
1620 #endif /* HAVE_SIN_LEN */
1621 addr
.sin_addr
.s_addr
= htonl (INADDR_LOOPBACK
);
1623 sockopt_reuseaddr (accept_sock
);
1624 sockopt_reuseport (accept_sock
);
1626 ret
= bind (accept_sock
, (struct sockaddr
*)&addr
,
1627 sizeof (struct sockaddr_in
));
1630 zlog_warn ("Can't bind to socket: %s", strerror (errno
));
1631 zlog_warn ("zebra can't provice full functionality due to above error");
1632 close (accept_sock
); /* Avoid sd leak. */
1636 ret
= listen (accept_sock
, 1);
1639 zlog_warn ("Can't listen to socket: %s", strerror (errno
));
1640 zlog_warn ("zebra can't provice full functionality due to above error");
1641 close (accept_sock
); /* Avoid sd leak. */
1645 zebra_event (ZEBRA_SERV
, accept_sock
, NULL
);
1648 /* For sockaddr_un. */
1651 /* zebra server UNIX domain socket. */
1653 zebra_serv_un (char *path
)
1657 struct sockaddr_un serv
;
1660 /* First of all, unlink existing socket */
1664 old_mask
= umask (0077);
1666 /* Make UNIX domain socket. */
1667 sock
= socket (AF_UNIX
, SOCK_STREAM
, 0);
1674 /* Make server socket. */
1675 memset (&serv
, 0, sizeof (struct sockaddr_un
));
1676 serv
.sun_family
= AF_UNIX
;
1677 strncpy (serv
.sun_path
, path
, strlen (path
));
1679 len
= serv
.sun_len
= SUN_LEN(&serv
);
1681 len
= sizeof (serv
.sun_family
) + strlen (serv
.sun_path
);
1682 #endif /* HAVE_SUN_LEN */
1684 ret
= bind (sock
, (struct sockaddr
*) &serv
, len
);
1692 ret
= listen (sock
, 5);
1702 zebra_event (ZEBRA_SERV
, sock
, NULL
);
1705 /* Zebra's event management function. */
1706 extern struct thread_master
*master
;
1709 zebra_event (enum event event
, int sock
, struct zserv
*client
)
1714 thread_add_read (master
, zebra_accept
, client
, sock
);
1718 thread_add_read (master
, zebra_client_read
, client
, sock
);
1726 /* Display default rtm_table for all clients. */
1731 "default routing table to use for all clients\n")
1733 vty_out (vty
, "table %d%s", rtm_table_default
,
1738 DEFUN (config_table
,
1741 "Configure target kernel routing table\n"
1744 rtm_table_default
= strtol (argv
[0], (char**)0, 10);
1748 DEFUN (ip_forwarding
,
1752 "Turn on IP forwarding")
1760 vty_out (vty
, "IP forwarding is already on%s", VTY_NEWLINE
);
1761 return CMD_ERR_NOTHING_TODO
;
1764 ret
= ipforward_on ();
1767 vty_out (vty
, "Can't turn on IP forwarding%s", VTY_NEWLINE
);
1774 DEFUN (no_ip_forwarding
,
1775 no_ip_forwarding_cmd
,
1779 "Turn off IP forwarding")
1787 vty_out (vty
, "IP forwarding is already off%s", VTY_NEWLINE
);
1788 return CMD_ERR_NOTHING_TODO
;
1791 ret
= ipforward_off ();
1794 vty_out (vty
, "Can't turn off IP forwarding%s", VTY_NEWLINE
);
1801 /* This command is for debugging purpose. */
1802 DEFUN (show_zebra_client
,
1803 show_zebra_client_cmd
,
1804 "show zebra client",
1807 "Client information")
1810 struct zserv
*client
;
1812 for (node
= listhead (client_list
); node
; nextnode (node
))
1814 client
= getdata (node
);
1815 vty_out (vty
, "Client fd %d%s", client
->sock
, VTY_NEWLINE
);
1820 /* Table configuration write function. */
1822 config_write_table (struct vty
*vty
)
1824 if (rtm_table_default
)
1825 vty_out (vty
, "table %d%s", rtm_table_default
,
1830 /* table node for routing tables. */
1831 struct cmd_node table_node
=
1834 "", /* This node has no interface. */
1838 /* Only display ip forwarding is enabled or not. */
1839 DEFUN (show_ip_forwarding
,
1840 show_ip_forwarding_cmd
,
1841 "show ip forwarding",
1844 "IP forwarding status\n")
1851 vty_out (vty
, "IP forwarding is off%s", VTY_NEWLINE
);
1853 vty_out (vty
, "IP forwarding is on%s", VTY_NEWLINE
);
1858 /* Only display ipv6 forwarding is enabled or not. */
1859 DEFUN (show_ipv6_forwarding
,
1860 show_ipv6_forwarding_cmd
,
1861 "show ipv6 forwarding",
1863 "IPv6 information\n"
1864 "Forwarding status\n")
1868 ret
= ipforward_ipv6 ();
1873 vty_out (vty
, "ipv6 forwarding is unknown%s", VTY_NEWLINE
);
1876 vty_out (vty
, "ipv6 forwarding is %s%s", "off", VTY_NEWLINE
);
1879 vty_out (vty
, "ipv6 forwarding is %s%s", "on", VTY_NEWLINE
);
1882 vty_out (vty
, "ipv6 forwarding is %s%s", "off", VTY_NEWLINE
);
1888 DEFUN (no_ipv6_forwarding
,
1889 no_ipv6_forwarding_cmd
,
1890 "no ipv6 forwarding",
1893 "Doesn't forward IPv6 protocol packet")
1897 ret
= ipforward_ipv6_off ();
1900 vty_out (vty
, "Can't turn off IPv6 forwarding%s", VTY_NEWLINE
);
1907 #endif /* HAVE_IPV6 */
1909 /* IPForwarding configuration write function. */
1911 config_write_forwarding (struct vty
*vty
)
1914 vty_out (vty
, "no ip forwarding%s", VTY_NEWLINE
);
1916 if (! ipforward_ipv6 ())
1917 vty_out (vty
, "no ipv6 forwarding%s", VTY_NEWLINE
);
1918 #endif /* HAVE_IPV6 */
1919 vty_out (vty
, "!%s", VTY_NEWLINE
);
1923 /* table node for routing tables. */
1924 struct cmd_node forwarding_node
=
1927 "", /* This node has no interface. */
1932 /* Initialisation of zebra and installation of commands. */
1936 /* Client list init. */
1937 client_list
= list_new ();
1939 /* Forwarding is on by default. */
1942 ipforward_ipv6_on ();
1943 #endif /* HAVE_IPV6 */
1945 /* Make zebra server socket. */
1946 #ifdef HAVE_TCP_ZEBRA
1949 zebra_serv_un (ZEBRA_SERV_PATH
);
1950 #endif /* HAVE_TCP_ZEBRA */
1952 /* Install configuration write function. */
1953 install_node (&table_node
, config_write_table
);
1954 install_node (&forwarding_node
, config_write_forwarding
);
1956 install_element (VIEW_NODE
, &show_ip_forwarding_cmd
);
1957 install_element (ENABLE_NODE
, &show_ip_forwarding_cmd
);
1958 install_element (CONFIG_NODE
, &ip_forwarding_cmd
);
1959 install_element (CONFIG_NODE
, &no_ip_forwarding_cmd
);
1960 install_element (ENABLE_NODE
, &show_zebra_client_cmd
);
1963 install_element (VIEW_NODE
, &show_table_cmd
);
1964 install_element (ENABLE_NODE
, &show_table_cmd
);
1965 install_element (CONFIG_NODE
, &config_table_cmd
);
1966 #endif /* HAVE_NETLINK */
1969 install_element (VIEW_NODE
, &show_ipv6_forwarding_cmd
);
1970 install_element (ENABLE_NODE
, &show_ipv6_forwarding_cmd
);
1971 install_element (CONFIG_NODE
, &no_ipv6_forwarding_cmd
);
1972 #endif /* HAVE_IPV6 */
1974 FIFO_INIT(&message_queue
);