3 * Copyright (C) 1997, 1999 Kunihiro Ishiguro
5 * This file is part of GNU Zebra.
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Zebra; see the file COPYING. If not, write to the Free
19 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 #include "sockunion.h"
32 #include "connected.h"
36 #include "zebra/interface.h"
37 #include "zebra/rtadv.h"
38 #include "zebra/rib.h"
39 #include "zebra/zserv.h"
40 #include "zebra/redistribute.h"
41 #include "zebra/debug.h"
42 #include "zebra/irdp.h"
44 /* Allocate a new internal interface index
45 * This works done from the top so that %d macros
49 if_new_intern_ifindex (void)
51 /* Start here so that first one assigned is 0xFFFFFFFF */
52 static unsigned int ifindex
= IFINDEX_INTERNBASE
+ 1;
57 if ( ifindex
<= IFINDEX_INTERNBASE
)
60 if (if_lookup_by_index(ifindex
) == NULL
)
65 /* Called when new interface is added. */
67 if_zebra_new_hook (struct interface
*ifp
)
69 struct zebra_if
*zebra_if
;
71 zebra_if
= XMALLOC (MTYPE_TMP
, sizeof (struct zebra_if
));
72 memset (zebra_if
, 0, sizeof (struct zebra_if
));
74 zebra_if
->multicast
= IF_ZEBRA_MULTICAST_UNSPEC
;
75 zebra_if
->shutdown
= IF_ZEBRA_SHUTDOWN_UNSPEC
;
79 /* Set default router advertise values. */
80 struct rtadvconf
*rtadv
;
82 rtadv
= &zebra_if
->rtadv
;
84 rtadv
->AdvSendAdvertisements
= 0;
85 rtadv
->MaxRtrAdvInterval
= RTADV_MAX_RTR_ADV_INTERVAL
;
86 rtadv
->MinRtrAdvInterval
= RTADV_MIN_RTR_ADV_INTERVAL
;
87 rtadv
->AdvIntervalTimer
= 0;
88 rtadv
->AdvManagedFlag
= 0;
89 rtadv
->AdvOtherConfigFlag
= 0;
90 rtadv
->AdvLinkMTU
= 0;
91 rtadv
->AdvReachableTime
= 0;
92 rtadv
->AdvRetransTimer
= 0;
93 rtadv
->AdvCurHopLimit
= 0;
94 rtadv
->AdvDefaultLifetime
= RTADV_ADV_DEFAULT_LIFETIME
;
96 rtadv
->AdvPrefixList
= list_new ();
100 ifp
->info
= zebra_if
;
104 /* Called when interface is deleted. */
106 if_zebra_delete_hook (struct interface
*ifp
)
109 XFREE (MTYPE_TMP
, ifp
->info
);
113 /* Wake up configured address if it is not in current kernel
116 if_addr_wakeup (struct interface
*ifp
)
118 struct listnode
*node
;
119 struct connected
*ifc
;
123 for (node
= listhead (ifp
->connected
); node
; nextnode (node
))
125 ifc
= getdata (node
);
128 if (CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_CONFIGURED
)
129 && ! CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_REAL
))
132 if (p
->family
== AF_INET
)
134 if (! if_is_up (ifp
))
136 if_set_flags (ifp
, IFF_UP
| IFF_RUNNING
);
140 ret
= if_set_prefix (ifp
, ifc
);
143 zlog_warn ("Can't set interface's address: %s",
147 SET_FLAG (ifc
->conf
, ZEBRA_IFC_REAL
);
149 zebra_interface_address_add_update (ifp
, ifc
);
151 if (if_is_operative(ifp
))
152 connected_up_ipv4 (ifp
, ifc
);
155 if (p
->family
== AF_INET6
)
157 if (! if_is_up (ifp
))
159 if_set_flags (ifp
, IFF_UP
| IFF_RUNNING
);
163 ret
= if_prefix_add_ipv6 (ifp
, ifc
);
166 zlog_warn ("Can't set interface's address: %s",
170 SET_FLAG (ifc
->conf
, ZEBRA_IFC_REAL
);
172 zebra_interface_address_add_update (ifp
, ifc
);
174 if (if_is_operative(ifp
))
175 connected_up_ipv6 (ifp
, ifc
);
177 #endif /* HAVE_IPV6 */
182 /* Handle interface addition */
184 if_add_update (struct interface
*ifp
)
186 struct zebra_if
*if_data
;
189 if (if_data
->multicast
== IF_ZEBRA_MULTICAST_ON
)
190 if_set_flags (ifp
, IFF_MULTICAST
);
191 else if (if_data
->multicast
== IF_ZEBRA_MULTICAST_OFF
)
192 if_unset_flags (ifp
, IFF_MULTICAST
);
194 zebra_interface_add_update (ifp
);
196 if (! CHECK_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
))
198 SET_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
);
200 if_addr_wakeup (ifp
);
202 if (IS_ZEBRA_DEBUG_KERNEL
)
203 zlog_info ("interface %s index %d becomes active.",
204 ifp
->name
, ifp
->ifindex
);
208 if (IS_ZEBRA_DEBUG_KERNEL
)
209 zlog_info ("interface %s index %d is added.", ifp
->name
, ifp
->ifindex
);
214 /* Handle an interface delete event
216 * This function is only called when support for
217 * RTM_IFANNOUNCE or AF_NETLINK sockets (RTM_DELLINK message)
218 * is available. It is not called on, eg, Solaris.
220 #if (defined(RTM_IFANNOUNCE) || defined(HAVE_NETLINK))
222 if_delete_update (struct interface
*ifp
)
224 struct listnode
*node
;
225 struct listnode
*next
;
226 struct connected
*ifc
;
231 zlog_err ("interface %s index %d is still up while being deleted.",
232 ifp
->name
, ifp
->ifindex
);
236 /* Mark interface as inactive */
237 UNSET_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
);
239 if (IS_ZEBRA_DEBUG_KERNEL
)
240 zlog_info ("interface %s index %d is now inactive.",
241 ifp
->name
, ifp
->ifindex
);
243 /* Delete connected routes from the kernel. */
246 for (node
= listhead (ifp
->connected
); node
; node
= next
)
249 ifc
= getdata (node
);
252 if (p
->family
== AF_INET
)
253 connected_down_ipv4 (ifp
, ifc
);
255 else if (p
->family
== AF_INET6
)
256 connected_down_ipv6 (ifp
, ifc
);
257 #endif /* HAVE_IPV6 */
259 zebra_interface_address_delete_update (ifp
, ifc
);
261 UNSET_FLAG (ifc
->conf
, ZEBRA_IFC_REAL
);
263 if (! CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
265 listnode_delete (ifp
->connected
, ifc
);
266 connected_free (ifc
);
270 zebra_interface_delete_update (ifp
);
272 #endif /* (defined(RTM_IFANNOUNCE) || defined(HAVE_NETLINK) */
274 /* Interface is up. */
276 if_up (struct interface
*ifp
)
280 struct connected
*ifc
;
283 /* Notify the protocol daemons. */
284 zebra_interface_up_update (ifp
);
286 /* Install connected routes to the kernel. */
289 for (node
= listhead (ifp
->connected
); node
; node
= next
)
292 ifc
= getdata (node
);
295 if (p
->family
== AF_INET
)
296 connected_up_ipv4 (ifp
, ifc
);
298 else if (p
->family
== AF_INET6
)
299 connected_up_ipv6 (ifp
, ifc
);
300 #endif /* HAVE_IPV6 */
304 /* Examine all static routes. */
308 /* Interface goes down. We have to manage different behavior of based
311 if_down (struct interface
*ifp
)
315 struct connected
*ifc
;
318 /* Notify to the protocol daemons. */
319 zebra_interface_down_update (ifp
);
321 /* Delete connected routes from the kernel. */
324 for (node
= listhead (ifp
->connected
); node
; node
= next
)
327 ifc
= getdata (node
);
330 if (p
->family
== AF_INET
)
331 connected_down_ipv4 (ifp
, ifc
);
333 else if (p
->family
== AF_INET6
)
334 connected_down_ipv6 (ifp
, ifc
);
335 #endif /* HAVE_IPV6 */
339 /* Examine all static routes which direct to the interface. */
344 if_refresh (struct interface
*ifp
)
346 if (if_is_operative (ifp
))
349 if (! if_is_operative (ifp
))
355 if (if_is_operative (ifp
))
360 /* Printout flag information into vty */
362 if_flag_dump_vty (struct vty
*vty
, unsigned long flag
)
366 #define IFF_OUT_VTY(X, Y) \
367 if ((X) && (flag & (X))) \
370 vty_out (vty, ","); \
377 IFF_OUT_VTY (IFF_UP
, "UP");
378 IFF_OUT_VTY (IFF_BROADCAST
, "BROADCAST");
379 IFF_OUT_VTY (IFF_DEBUG
, "DEBUG");
380 IFF_OUT_VTY (IFF_LOOPBACK
, "LOOPBACK");
381 IFF_OUT_VTY (IFF_POINTOPOINT
, "POINTOPOINT");
382 IFF_OUT_VTY (IFF_NOTRAILERS
, "NOTRAILERS");
383 IFF_OUT_VTY (IFF_RUNNING
, "RUNNING");
384 IFF_OUT_VTY (IFF_NOARP
, "NOARP");
385 IFF_OUT_VTY (IFF_PROMISC
, "PROMISC");
386 IFF_OUT_VTY (IFF_ALLMULTI
, "ALLMULTI");
387 IFF_OUT_VTY (IFF_OACTIVE
, "OACTIVE");
388 IFF_OUT_VTY (IFF_SIMPLEX
, "SIMPLEX");
389 IFF_OUT_VTY (IFF_LINK0
, "LINK0");
390 IFF_OUT_VTY (IFF_LINK1
, "LINK1");
391 IFF_OUT_VTY (IFF_LINK2
, "LINK2");
392 IFF_OUT_VTY (IFF_MULTICAST
, "MULTICAST");
394 IFF_OUT_VTY (IFF_IPV4
, "IFF_IPv4");
395 IFF_OUT_VTY (IFF_IPV6
, "IFF_IPv6");
396 #endif /* SOLARIS_IPV6 */
400 /* Output prefix string to vty. */
402 prefix_vty_out (struct vty
*vty
, struct prefix
*p
)
404 char str
[INET6_ADDRSTRLEN
];
406 inet_ntop (p
->family
, &p
->u
.prefix
, str
, sizeof (str
));
407 vty_out (vty
, "%s", str
);
411 /* Dump if address information to vty. */
413 connected_dump_vty (struct vty
*vty
, struct connected
*connected
)
416 struct interface
*ifp
;
418 /* Set interface pointer. */
419 ifp
= connected
->ifp
;
421 /* Print interface address. */
422 p
= connected
->address
;
423 vty_out (vty
, " %s ", prefix_family_str (p
));
424 prefix_vty_out (vty
, p
);
425 vty_out (vty
, "/%d", p
->prefixlen
);
427 /* If there is destination address, print it. */
428 p
= connected
->destination
;
431 if (p
->family
== AF_INET
)
432 if (ifp
->flags
& IFF_BROADCAST
)
434 vty_out (vty
, " broadcast ");
435 prefix_vty_out (vty
, p
);
438 if (ifp
->flags
& IFF_POINTOPOINT
)
440 vty_out (vty
, " pointopoint ");
441 prefix_vty_out (vty
, p
);
445 if (CHECK_FLAG (connected
->flags
, ZEBRA_IFA_SECONDARY
))
446 vty_out (vty
, " secondary");
448 if (connected
->label
)
449 vty_out (vty
, " %s", connected
->label
);
451 vty_out (vty
, "%s", VTY_NEWLINE
);
455 /* Dump interface ND information to vty. */
457 nd_dump_vty (struct vty
*vty
, struct interface
*ifp
)
459 struct zebra_if
*zif
;
460 struct rtadvconf
*rtadv
;
462 zif
= (struct zebra_if
*) ifp
->info
;
465 if (rtadv
->AdvSendAdvertisements
)
467 vty_out (vty
, " ND advertised reachable time is %d milliseconds%s",
468 rtadv
->AdvReachableTime
, VTY_NEWLINE
);
469 vty_out (vty
, " ND advertised retransmit interval is %d milliseconds%s",
470 rtadv
->AdvRetransTimer
, VTY_NEWLINE
);
471 vty_out (vty
, " ND router advertisements are sent every %d seconds%s",
472 rtadv
->MaxRtrAdvInterval
, VTY_NEWLINE
);
473 vty_out (vty
, " ND router advertisements live for %d seconds%s",
474 rtadv
->AdvDefaultLifetime
, VTY_NEWLINE
);
475 if (rtadv
->AdvManagedFlag
)
476 vty_out (vty
, " Hosts use DHCP to obtain routable addresses.%s",
479 vty_out (vty
, " Hosts use stateless autoconfig for addresses.%s",
485 /* Interface's information print out to vty interface. */
487 if_dump_vty (struct vty
*vty
, struct interface
*ifp
)
489 #ifdef HAVE_SOCKADDR_DL
490 struct sockaddr_dl
*sdl
;
491 #endif /* HAVE_SOCKADDR_DL */
492 struct connected
*connected
;
495 vty_out (vty
, "Interface %s is ", ifp
->name
);
497 vty_out (vty
, "up, line protocol ");
499 if (CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_LINKDETECTION
)) {
500 if (if_is_running(ifp
))
501 vty_out (vty
, "is up%s", VTY_NEWLINE
);
503 vty_out (vty
, "is down%s", VTY_NEWLINE
);
505 vty_out (vty
, "detection is disabled%s", VTY_NEWLINE
);
508 vty_out (vty
, "down%s", VTY_NEWLINE
);
512 vty_out (vty
, " Description: %s%s", ifp
->desc
,
514 if (ifp
->ifindex
<= 0)
516 vty_out(vty
, " index %d pseudo interface%s", ifp
->ifindex
, VTY_NEWLINE
);
519 else if (! CHECK_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
))
521 vty_out(vty
, " index %d inactive interface%s",
527 vty_out (vty
, " index %d metric %d mtu %d ",
528 ifp
->ifindex
, ifp
->metric
, ifp
->mtu
);
529 if_flag_dump_vty (vty
, ifp
->flags
);
531 if (ifp
->mtu6
!= ifp
->mtu
)
532 vty_out (vty
, "mtu6 %d ", ifp
->mtu6
);
535 vty_out (vty
, "%s", VTY_NEWLINE
);
537 /* Hardware address. */
538 #ifdef HAVE_SOCKADDR_DL
540 if (sdl
!= NULL
&& sdl
->sdl_alen
!= 0)
545 vty_out (vty
, " HWaddr: ");
546 for (i
= 0, ptr
= (u_char
*)LLADDR (sdl
); i
< sdl
->sdl_alen
; i
++, ptr
++)
547 vty_out (vty
, "%s%02x", i
== 0 ? "" : ":", *ptr
);
548 vty_out (vty
, "%s", VTY_NEWLINE
);
551 if (ifp
->hw_addr_len
!= 0)
555 vty_out (vty
, " HWaddr: ");
556 for (i
= 0; i
< ifp
->hw_addr_len
; i
++)
557 vty_out (vty
, "%s%02x", i
== 0 ? "" : ":", ifp
->hw_addr
[i
]);
558 vty_out (vty
, "%s", VTY_NEWLINE
);
560 #endif /* HAVE_SOCKADDR_DL */
562 /* Bandwidth in kbps */
563 if (ifp
->bandwidth
!= 0)
565 vty_out(vty
, " bandwidth %u kbps", ifp
->bandwidth
);
566 vty_out(vty
, "%s", VTY_NEWLINE
);
569 for (node
= listhead (ifp
->connected
); node
; nextnode (node
))
571 connected
= getdata (node
);
572 if (CHECK_FLAG (connected
->conf
, ZEBRA_IFC_REAL
))
573 connected_dump_vty (vty
, connected
);
577 nd_dump_vty (vty
, ifp
);
580 #ifdef HAVE_PROC_NET_DEV
581 /* Statistics print out using proc file system. */
582 vty_out (vty
, " input packets %lu, bytes %lu, dropped %lu,"
583 " multicast packets %lu%s",
584 ifp
->stats
.rx_packets
, ifp
->stats
.rx_bytes
,
585 ifp
->stats
.rx_dropped
, ifp
->stats
.rx_multicast
, VTY_NEWLINE
);
587 vty_out (vty
, " input errors %lu, length %lu, overrun %lu,"
588 " CRC %lu, frame %lu, fifo %lu, missed %lu%s",
589 ifp
->stats
.rx_errors
, ifp
->stats
.rx_length_errors
,
590 ifp
->stats
.rx_over_errors
, ifp
->stats
.rx_crc_errors
,
591 ifp
->stats
.rx_frame_errors
, ifp
->stats
.rx_fifo_errors
,
592 ifp
->stats
.rx_missed_errors
, VTY_NEWLINE
);
594 vty_out (vty
, " output packets %lu, bytes %lu, dropped %lu%s",
595 ifp
->stats
.tx_packets
, ifp
->stats
.tx_bytes
,
596 ifp
->stats
.tx_dropped
, VTY_NEWLINE
);
598 vty_out (vty
, " output errors %lu, aborted %lu, carrier %lu,"
599 " fifo %lu, heartbeat %lu, window %lu%s",
600 ifp
->stats
.tx_errors
, ifp
->stats
.tx_aborted_errors
,
601 ifp
->stats
.tx_carrier_errors
, ifp
->stats
.tx_fifo_errors
,
602 ifp
->stats
.tx_heartbeat_errors
, ifp
->stats
.tx_window_errors
,
605 vty_out (vty
, " collisions %lu%s", ifp
->stats
.collisions
, VTY_NEWLINE
);
606 #endif /* HAVE_PROC_NET_DEV */
608 #ifdef HAVE_NET_RT_IFLIST
609 #if defined (__bsdi__) || defined (__NetBSD__)
610 /* Statistics print out using sysctl (). */
611 vty_out (vty
, " input packets %qu, bytes %qu, dropped %qu,"
612 " multicast packets %qu%s",
613 ifp
->stats
.ifi_ipackets
, ifp
->stats
.ifi_ibytes
,
614 ifp
->stats
.ifi_iqdrops
, ifp
->stats
.ifi_imcasts
,
617 vty_out (vty
, " input errors %qu%s",
618 ifp
->stats
.ifi_ierrors
, VTY_NEWLINE
);
620 vty_out (vty
, " output packets %qu, bytes %qu, multicast packets %qu%s",
621 ifp
->stats
.ifi_opackets
, ifp
->stats
.ifi_obytes
,
622 ifp
->stats
.ifi_omcasts
, VTY_NEWLINE
);
624 vty_out (vty
, " output errors %qu%s",
625 ifp
->stats
.ifi_oerrors
, VTY_NEWLINE
);
627 vty_out (vty
, " collisions %qu%s",
628 ifp
->stats
.ifi_collisions
, VTY_NEWLINE
);
630 /* Statistics print out using sysctl (). */
631 vty_out (vty
, " input packets %lu, bytes %lu, dropped %lu,"
632 " multicast packets %lu%s",
633 ifp
->stats
.ifi_ipackets
, ifp
->stats
.ifi_ibytes
,
634 ifp
->stats
.ifi_iqdrops
, ifp
->stats
.ifi_imcasts
,
637 vty_out (vty
, " input errors %lu%s",
638 ifp
->stats
.ifi_ierrors
, VTY_NEWLINE
);
640 vty_out (vty
, " output packets %lu, bytes %lu, multicast packets %lu%s",
641 ifp
->stats
.ifi_opackets
, ifp
->stats
.ifi_obytes
,
642 ifp
->stats
.ifi_omcasts
, VTY_NEWLINE
);
644 vty_out (vty
, " output errors %lu%s",
645 ifp
->stats
.ifi_oerrors
, VTY_NEWLINE
);
647 vty_out (vty
, " collisions %lu%s",
648 ifp
->stats
.ifi_collisions
, VTY_NEWLINE
);
649 #endif /* __bsdi__ || __NetBSD__ */
650 #endif /* HAVE_NET_RT_IFLIST */
653 /* Check supported address family. */
655 if_supported_family (int family
)
657 if (family
== AF_INET
)
660 if (family
== AF_INET6
)
662 #endif /* HAVE_IPV6 */
666 /* Wrapper hook point for zebra daemon so that ifindex can be set
667 * DEFUN macro not used as extract.pl HAS to ignore this
668 * See also interface_cmd in lib/if.c
670 DEFUN_NOSH (zebra_interface
,
673 "Select an interface to configure\n"
674 "Interface's name\n")
677 struct interface
* ifp
;
679 /* Call lib interface() */
680 ret
= interface_cmd
.func (self
, vty
, argc
, argv
);
685 this only happens if interface is NOT in kernel */
686 if (ifp
->ifindex
== 0)
688 ifp
->ifindex
= if_new_intern_ifindex ();
689 UNSET_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
);
695 struct cmd_node interface_node
=
702 /* Show all or specified interface to vty. */
703 DEFUN (show_interface
, show_interface_cmd
,
704 "show interface [IFNAME]",
706 "Interface status and configuration\n"
710 struct interface
*ifp
;
712 #ifdef HAVE_PROC_NET_DEV
713 /* If system has interface statistics via proc file system, update
715 ifstat_update_proc ();
716 #endif /* HAVE_PROC_NET_DEV */
717 #ifdef HAVE_NET_RT_IFLIST
718 ifstat_update_sysctl ();
719 #endif /* HAVE_NET_RT_IFLIST */
721 /* Specified interface print. */
724 ifp
= if_lookup_by_name (argv
[0]);
727 vty_out (vty
, "%% Can't find interface %s%s", argv
[0],
731 if_dump_vty (vty
, ifp
);
735 /* All interface print. */
736 for (node
= listhead (iflist
); node
; nextnode (node
))
737 if_dump_vty (vty
, getdata (node
));
745 "Set multicast flag to interface\n")
748 struct interface
*ifp
;
749 struct zebra_if
*if_data
;
751 ifp
= (struct interface
*) vty
->index
;
752 if (CHECK_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
))
754 ret
= if_set_flags (ifp
, IFF_MULTICAST
);
757 vty_out (vty
, "Can't set multicast flag%s", VTY_NEWLINE
);
763 if_data
->multicast
= IF_ZEBRA_MULTICAST_ON
;
772 "Unset multicast flag to interface\n")
775 struct interface
*ifp
;
776 struct zebra_if
*if_data
;
778 ifp
= (struct interface
*) vty
->index
;
779 if (CHECK_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
))
781 ret
= if_unset_flags (ifp
, IFF_MULTICAST
);
784 vty_out (vty
, "Can't unset multicast flag%s", VTY_NEWLINE
);
790 if_data
->multicast
= IF_ZEBRA_MULTICAST_OFF
;
798 "Enable link detection on interface\n")
800 struct interface
*ifp
;
801 int if_was_operative
;
803 ifp
= (struct interface
*) vty
->index
;
804 if_was_operative
= if_is_operative(ifp
);
805 SET_FLAG(ifp
->status
, ZEBRA_INTERFACE_LINKDETECTION
);
807 /* When linkdetection is enabled, if might come down */
808 if (!if_is_operative(ifp
) && if_was_operative
) if_down(ifp
);
810 /* FIXME: Will defer status change forwarding if interface
811 does not come down! */
817 DEFUN (no_linkdetect
,
821 "Disable link detection on interface\n")
823 struct interface
*ifp
;
824 int if_was_operative
;
826 ifp
= (struct interface
*) vty
->index
;
827 if_was_operative
= if_is_operative(ifp
);
828 UNSET_FLAG(ifp
->status
, ZEBRA_INTERFACE_LINKDETECTION
);
830 /* Interface may come up after disabling link detection */
831 if (if_is_operative(ifp
) && !if_was_operative
) if_up(ifp
);
833 /* FIXME: see linkdetect_cmd */
841 "Shutdown the selected interface\n")
844 struct interface
*ifp
;
845 struct zebra_if
*if_data
;
847 ifp
= (struct interface
*) vty
->index
;
848 ret
= if_unset_flags (ifp
, IFF_UP
);
851 vty_out (vty
, "Can't shutdown interface%s", VTY_NEWLINE
);
856 if_data
->shutdown
= IF_ZEBRA_SHUTDOWN_ON
;
861 DEFUN (no_shutdown_if
,
865 "Shutdown the selected interface\n")
868 struct interface
*ifp
;
869 struct zebra_if
*if_data
;
871 ifp
= (struct interface
*) vty
->index
;
872 ret
= if_set_flags (ifp
, IFF_UP
| IFF_RUNNING
);
875 vty_out (vty
, "Can't up interface%s", VTY_NEWLINE
);
880 if_data
->shutdown
= IF_ZEBRA_SHUTDOWN_OFF
;
887 "bandwidth <1-10000000>",
888 "Set bandwidth informational parameter\n"
889 "Bandwidth in kilobits\n")
891 struct interface
*ifp
;
892 unsigned int bandwidth
;
894 ifp
= (struct interface
*) vty
->index
;
895 bandwidth
= strtol(argv
[0], NULL
, 10);
897 /* bandwidth range is <1-10000000> */
898 if (bandwidth
< 1 || bandwidth
> 10000000)
900 vty_out (vty
, "Bandwidth is invalid%s", VTY_NEWLINE
);
904 ifp
->bandwidth
= bandwidth
;
906 /* force protocols to recalculate routes due to cost change */
907 if (if_is_operative (ifp
))
908 zebra_interface_up_update (ifp
);
913 DEFUN (no_bandwidth_if
,
917 "Set bandwidth informational parameter\n")
919 struct interface
*ifp
;
921 ifp
= (struct interface
*) vty
->index
;
925 /* force protocols to recalculate routes due to cost change */
926 if (if_is_operative (ifp
))
927 zebra_interface_up_update (ifp
);
932 ALIAS (no_bandwidth_if
,
933 no_bandwidth_if_val_cmd
,
934 "no bandwidth <1-10000000>",
936 "Set bandwidth informational parameter\n"
937 "Bandwidth in kilobits\n")
940 ip_address_install (struct vty
*vty
, struct interface
*ifp
, char *addr_str
,
941 char *peer_str
, char *label
, int secondary
)
943 struct prefix_ipv4 cp
;
944 struct connected
*ifc
;
945 struct prefix_ipv4
*p
;
949 ret
= str2prefix_ipv4 (addr_str
, &cp
);
952 vty_out (vty
, "%% Malformed address %s", VTY_NEWLINE
);
956 ifc
= connected_check_ipv4 (ifp
, (struct prefix
*) &cp
);
959 ifc
= connected_new ();
963 p
= prefix_ipv4_new ();
965 ifc
->address
= (struct prefix
*) p
;
968 if (p
->prefixlen
<= 30)
970 p
= prefix_ipv4_new ();
972 masklen2ip (p
->prefixlen
, &mask
);
973 p
->prefix
.s_addr
|= ~mask
.s_addr
;
974 ifc
->destination
= (struct prefix
*) p
;
979 SET_FLAG (ifc
->flags
, ZEBRA_IFA_SECONDARY
);
983 ifc
->label
= strdup (label
);
985 /* Add to linked list. */
986 listnode_add (ifp
->connected
, ifc
);
989 /* This address is configured from zebra. */
990 if (! CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
991 SET_FLAG (ifc
->conf
, ZEBRA_IFC_CONFIGURED
);
993 /* In case of this route need to install kernel. */
994 if (! CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_REAL
)
995 && CHECK_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
))
997 /* Some system need to up the interface to set IP address. */
998 if (! if_is_up (ifp
))
1000 if_set_flags (ifp
, IFF_UP
| IFF_RUNNING
);
1004 ret
= if_set_prefix (ifp
, ifc
);
1007 vty_out (vty
, "%% Can't set interface IP address: %s.%s",
1008 strerror(errno
), VTY_NEWLINE
);
1012 /* IP address propery set. */
1013 SET_FLAG (ifc
->conf
, ZEBRA_IFC_REAL
);
1015 /* Update interface address information to protocol daemon. */
1016 zebra_interface_address_add_update (ifp
, ifc
);
1018 /* If interface is up register connected route. */
1019 if (if_is_operative(ifp
))
1020 connected_up_ipv4 (ifp
, ifc
);
1027 ip_address_uninstall (struct vty
*vty
, struct interface
*ifp
, char *addr_str
,
1028 char *peer_str
, char *label
, int secondry
)
1030 struct prefix_ipv4 cp
;
1031 struct connected
*ifc
;
1034 /* Convert to prefix structure. */
1035 ret
= str2prefix_ipv4 (addr_str
, &cp
);
1038 vty_out (vty
, "%% Malformed address %s", VTY_NEWLINE
);
1042 /* Check current interface address. */
1043 ifc
= connected_check_ipv4 (ifp
, (struct prefix
*) &cp
);
1046 vty_out (vty
, "%% Can't find address%s", VTY_NEWLINE
);
1050 /* This is not configured address. */
1051 if (! CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
1054 /* This is not real address or interface is not active. */
1055 if (! CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_REAL
)
1056 || ! CHECK_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
))
1058 listnode_delete (ifp
->connected
, ifc
);
1059 connected_free (ifc
);
1063 /* This is real route. */
1064 ret
= if_unset_prefix (ifp
, ifc
);
1067 vty_out (vty
, "%% Can't unset interface IP address: %s.%s",
1068 strerror(errno
), VTY_NEWLINE
);
1072 /* Redistribute this information. */
1073 zebra_interface_address_delete_update (ifp
, ifc
);
1075 /* Remove connected route. */
1076 connected_down_ipv4 (ifp
, ifc
);
1078 /* Free address information. */
1079 listnode_delete (ifp
->connected
, ifc
);
1080 connected_free (ifc
);
1087 "ip address A.B.C.D/M",
1088 "Interface Internet Protocol config commands\n"
1089 "Set the IP address of an interface\n"
1090 "IP address (e.g. 10.0.0.1/8)\n")
1092 return ip_address_install (vty
, vty
->index
, argv
[0], NULL
, NULL
, 0);
1095 DEFUN (no_ip_address
,
1097 "no ip address A.B.C.D/M",
1099 "Interface Internet Protocol config commands\n"
1100 "Set the IP address of an interface\n"
1101 "IP Address (e.g. 10.0.0.1/8)")
1103 return ip_address_uninstall (vty
, vty
->index
, argv
[0], NULL
, NULL
, 0);
1107 DEFUN (ip_address_secondary
,
1108 ip_address_secondary_cmd
,
1109 "ip address A.B.C.D/M secondary",
1110 "Interface Internet Protocol config commands\n"
1111 "Set the IP address of an interface\n"
1112 "IP address (e.g. 10.0.0.1/8)\n"
1113 "Secondary IP address\n")
1115 return ip_address_install (vty
, vty
->index
, argv
[0], NULL
, NULL
, 1);
1118 DEFUN (ip_address_label
,
1119 ip_address_label_cmd
,
1120 "ip address A.B.C.D/M label LINE",
1121 "Interface Internet Protocol config commands\n"
1122 "Set the IP address of an interface\n"
1123 "IP address (e.g. 10.0.0.1/8)\n"
1124 "Label of this address\n"
1127 return ip_address_install (vty
, vty
->index
, argv
[0], NULL
, argv
[1], 1);
1130 ALIAS (ip_address_label
,
1131 ip_address_secondary_label_cmd
,
1132 "ip address A.B.C.D/M secondary label LINE",
1133 "Interface Internet Protocol config commands\n"
1134 "Set the IP address of an interface\n"
1135 "IP address (e.g. 10.0.0.1/8)\n"
1136 "Secondary IP address\n"
1137 "Label of this address\n"
1140 DEFUN (no_ip_address_secondary
,
1141 no_ip_address_secondary_cmd
,
1142 "no ip address A.B.C.D/M secondary",
1144 "Interface Internet Protocol config commands\n"
1145 "Set the IP address of an interface\n"
1146 "IP address (e.g. 10.0.0.1/8)\n"
1147 "Secondary IP address\n")
1149 return ip_address_uninstall (vty
, vty
->index
, argv
[0], NULL
, NULL
, 1);
1152 DEFUN (no_ip_address_label
,
1153 no_ip_address_label_cmd
,
1154 "no ip address A.B.C.D/M label LINE",
1156 "Interface Internet Protocol config commands\n"
1157 "Set the IP address of an interface\n"
1158 "IP address (e.g. 10.0.0.1/8)\n"
1159 "Label of this address\n"
1162 return ip_address_uninstall (vty
, vty
->index
, argv
[0], NULL
, argv
[1], 1);
1165 ALIAS (no_ip_address_label
,
1166 no_ip_address_secondary_label_cmd
,
1167 "no ip address A.B.C.D/M secondary label LINE",
1169 "Interface Internet Protocol config commands\n"
1170 "Set the IP address of an interface\n"
1171 "IP address (e.g. 10.0.0.1/8)\n"
1172 "Secondary IP address\n"
1173 "Label of this address\n"
1175 #endif /* HAVE_NETLINK */
1179 ipv6_address_install (struct vty
*vty
, struct interface
*ifp
, char *addr_str
,
1180 char *peer_str
, char *label
, int secondary
)
1182 struct prefix_ipv6 cp
;
1183 struct connected
*ifc
;
1184 struct prefix_ipv6
*p
;
1187 ret
= str2prefix_ipv6 (addr_str
, &cp
);
1190 vty_out (vty
, "%% Malformed address %s", VTY_NEWLINE
);
1194 ifc
= connected_check_ipv6 (ifp
, (struct prefix
*) &cp
);
1197 ifc
= connected_new ();
1201 p
= prefix_ipv6_new ();
1203 ifc
->address
= (struct prefix
*) p
;
1207 SET_FLAG (ifc
->flags
, ZEBRA_IFA_SECONDARY
);
1211 ifc
->label
= strdup (label
);
1213 /* Add to linked list. */
1214 listnode_add (ifp
->connected
, ifc
);
1217 /* This address is configured from zebra. */
1218 if (! CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
1219 SET_FLAG (ifc
->conf
, ZEBRA_IFC_CONFIGURED
);
1221 /* In case of this route need to install kernel. */
1222 if (! CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_REAL
)
1223 && CHECK_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
))
1225 /* Some system need to up the interface to set IP address. */
1226 if (! if_is_up (ifp
))
1228 if_set_flags (ifp
, IFF_UP
| IFF_RUNNING
);
1232 ret
= if_prefix_add_ipv6 (ifp
, ifc
);
1236 vty_out (vty
, "%% Can't set interface IP address: %s.%s",
1237 strerror(errno
), VTY_NEWLINE
);
1241 /* IP address propery set. */
1242 SET_FLAG (ifc
->conf
, ZEBRA_IFC_REAL
);
1244 /* Update interface address information to protocol daemon. */
1245 zebra_interface_address_add_update (ifp
, ifc
);
1247 /* If interface is up register connected route. */
1248 if (if_is_operative(ifp
))
1249 connected_up_ipv6 (ifp
, ifc
);
1256 ipv6_address_uninstall (struct vty
*vty
, struct interface
*ifp
, char *addr_str
,
1257 char *peer_str
, char *label
, int secondry
)
1259 struct prefix_ipv6 cp
;
1260 struct connected
*ifc
;
1263 /* Convert to prefix structure. */
1264 ret
= str2prefix_ipv6 (addr_str
, &cp
);
1267 vty_out (vty
, "%% Malformed address %s", VTY_NEWLINE
);
1271 /* Check current interface address. */
1272 ifc
= connected_check_ipv6 (ifp
, (struct prefix
*) &cp
);
1275 vty_out (vty
, "%% Can't find address%s", VTY_NEWLINE
);
1279 /* This is not configured address. */
1280 if (! CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
1283 /* This is not real address or interface is not active. */
1284 if (! CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_REAL
)
1285 || ! CHECK_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
))
1287 listnode_delete (ifp
->connected
, ifc
);
1288 connected_free (ifc
);
1292 /* This is real route. */
1293 ret
= if_prefix_delete_ipv6 (ifp
, ifc
);
1296 vty_out (vty
, "%% Can't unset interface IP address: %s.%s",
1297 strerror(errno
), VTY_NEWLINE
);
1301 /* Redistribute this information. */
1302 zebra_interface_address_delete_update (ifp
, ifc
);
1304 /* Remove connected route. */
1305 connected_down_ipv6 (ifp
, ifc
);
1307 /* Free address information. */
1308 listnode_delete (ifp
->connected
, ifc
);
1309 connected_free (ifc
);
1314 DEFUN (ipv6_address
,
1316 "ipv6 address X:X::X:X/M",
1317 "Interface IPv6 config commands\n"
1318 "Set the IP address of an interface\n"
1319 "IPv6 address (e.g. 3ffe:506::1/48)\n")
1321 return ipv6_address_install (vty
, vty
->index
, argv
[0], NULL
, NULL
, 0);
1324 DEFUN (no_ipv6_address
,
1325 no_ipv6_address_cmd
,
1326 "no ipv6 address X:X::X:X/M",
1328 "Interface IPv6 config commands\n"
1329 "Set the IP address of an interface\n"
1330 "IPv6 address (e.g. 3ffe:506::1/48)\n")
1332 return ipv6_address_uninstall (vty
, vty
->index
, argv
[0], NULL
, NULL
, 0);
1334 #endif /* HAVE_IPV6 */
1339 "ip tunnel IP_address IP_address",
1340 "KAME ip tunneling configuration commands\n"
1341 "Set FROM IP address and TO IP address\n")
1346 DEFUN (no_ip_tunnel
, no_ip_tunnel_cmd
,
1349 "Set FROM IP address and TO IP address\n")
1356 if_config_write (struct vty
*vty
)
1359 struct interface
*ifp
;
1362 for (node
= listhead (iflist
); node
; nextnode (node
))
1364 struct zebra_if
*if_data
;
1366 struct connected
*ifc
;
1369 ifp
= getdata (node
);
1370 if_data
= ifp
->info
;
1372 vty_out (vty
, "interface %s%s", ifp
->name
,
1376 vty_out (vty
, " description %s%s", ifp
->desc
,
1379 /* Assign bandwidth here to avoid unnecessary interface flap
1380 while processing config script */
1381 if (ifp
->bandwidth
!= 0)
1382 vty_out(vty
, " bandwidth %u%s", ifp
->bandwidth
, VTY_NEWLINE
);
1384 if (CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_LINKDETECTION
))
1385 vty_out(vty
, " link-detect%s", VTY_NEWLINE
);
1387 for (addrnode
= listhead (ifp
->connected
); addrnode
; nextnode (addrnode
))
1389 ifc
= getdata (addrnode
);
1390 if (CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
1393 vty_out (vty
, " ip%s address %s/%d",
1394 p
->family
== AF_INET
? "" : "v6",
1395 inet_ntop (p
->family
, &p
->u
.prefix
, buf
, BUFSIZ
),
1398 if (CHECK_FLAG (ifc
->flags
, ZEBRA_IFA_SECONDARY
))
1399 vty_out (vty
, " secondary");
1402 vty_out (vty
, " label %s", ifc
->label
);
1404 vty_out (vty
, "%s", VTY_NEWLINE
);
1410 if (if_data
->shutdown
== IF_ZEBRA_SHUTDOWN_ON
)
1411 vty_out (vty
, " shutdown%s", VTY_NEWLINE
);
1413 if (if_data
->multicast
!= IF_ZEBRA_MULTICAST_UNSPEC
)
1414 vty_out (vty
, " %smulticast%s",
1415 if_data
->multicast
== IF_ZEBRA_MULTICAST_ON
? "" : "no ",
1420 rtadv_config_write (vty
, ifp
);
1424 irdp_config_write (vty
, ifp
);
1427 vty_out (vty
, "!%s", VTY_NEWLINE
);
1432 /* Allocate and initialize interface vector. */
1436 /* Initialize interface and new hook. */
1438 if_add_hook (IF_NEW_HOOK
, if_zebra_new_hook
);
1439 if_add_hook (IF_DELETE_HOOK
, if_zebra_delete_hook
);
1441 /* Install configuration write function. */
1442 install_node (&interface_node
, if_config_write
);
1444 install_element (VIEW_NODE
, &show_interface_cmd
);
1445 install_element (ENABLE_NODE
, &show_interface_cmd
);
1446 install_element (CONFIG_NODE
, &zebra_interface_cmd
);
1447 install_element (CONFIG_NODE
, &no_interface_cmd
);
1448 install_default (INTERFACE_NODE
);
1449 install_element (INTERFACE_NODE
, &interface_desc_cmd
);
1450 install_element (INTERFACE_NODE
, &no_interface_desc_cmd
);
1451 install_element (INTERFACE_NODE
, &multicast_cmd
);
1452 install_element (INTERFACE_NODE
, &no_multicast_cmd
);
1453 install_element (INTERFACE_NODE
, &linkdetect_cmd
);
1454 install_element (INTERFACE_NODE
, &no_linkdetect_cmd
);
1455 install_element (INTERFACE_NODE
, &shutdown_if_cmd
);
1456 install_element (INTERFACE_NODE
, &no_shutdown_if_cmd
);
1457 install_element (INTERFACE_NODE
, &bandwidth_if_cmd
);
1458 install_element (INTERFACE_NODE
, &no_bandwidth_if_cmd
);
1459 install_element (INTERFACE_NODE
, &no_bandwidth_if_val_cmd
);
1460 install_element (INTERFACE_NODE
, &ip_address_cmd
);
1461 install_element (INTERFACE_NODE
, &no_ip_address_cmd
);
1463 install_element (INTERFACE_NODE
, &ipv6_address_cmd
);
1464 install_element (INTERFACE_NODE
, &no_ipv6_address_cmd
);
1465 #endif /* HAVE_IPV6 */
1467 install_element (INTERFACE_NODE
, &ip_tunnel_cmd
);
1468 install_element (INTERFACE_NODE
, &no_ip_tunnel_cmd
);
1471 install_element (INTERFACE_NODE
, &ip_address_secondary_cmd
);
1472 install_element (INTERFACE_NODE
, &ip_address_label_cmd
);
1473 install_element (INTERFACE_NODE
, &ip_address_secondary_label_cmd
);
1474 install_element (INTERFACE_NODE
, &no_ip_address_secondary_cmd
);
1475 install_element (INTERFACE_NODE
, &no_ip_address_label_cmd
);
1476 install_element (INTERFACE_NODE
, &no_ip_address_secondary_label_cmd
);
1477 #endif /* HAVE_NETLINK */