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"
43 /* Allocate a new internal interface index
44 * This works done from the top so that %d macros
48 if_new_intern_ifindex (void)
50 /* Start here so that first one assigned is 0xFFFFFFFF */
51 static unsigned int ifindex
= IFINDEX_INTERNBASE
+ 1;
56 if ( ifindex
<= IFINDEX_INTERNBASE
)
59 if (if_lookup_by_index(ifindex
) == NULL
)
64 /* Called when new interface is added. */
66 if_zebra_new_hook (struct interface
*ifp
)
68 struct zebra_if
*zebra_if
;
70 zebra_if
= XMALLOC (MTYPE_TMP
, sizeof (struct zebra_if
));
71 memset (zebra_if
, 0, sizeof (struct zebra_if
));
73 zebra_if
->multicast
= IF_ZEBRA_MULTICAST_UNSPEC
;
74 zebra_if
->shutdown
= IF_ZEBRA_SHUTDOWN_UNSPEC
;
78 /* Set default router advertise values. */
79 struct rtadvconf
*rtadv
;
81 rtadv
= &zebra_if
->rtadv
;
83 rtadv
->AdvSendAdvertisements
= 0;
84 rtadv
->MaxRtrAdvInterval
= RTADV_MAX_RTR_ADV_INTERVAL
;
85 rtadv
->MinRtrAdvInterval
= RTADV_MIN_RTR_ADV_INTERVAL
;
86 rtadv
->AdvIntervalTimer
= 0;
87 rtadv
->AdvManagedFlag
= 0;
88 rtadv
->AdvOtherConfigFlag
= 0;
89 rtadv
->AdvLinkMTU
= 0;
90 rtadv
->AdvReachableTime
= 0;
91 rtadv
->AdvRetransTimer
= 0;
92 rtadv
->AdvCurHopLimit
= 0;
93 rtadv
->AdvDefaultLifetime
= RTADV_ADV_DEFAULT_LIFETIME
;
95 rtadv
->AdvPrefixList
= list_new ();
103 /* Called when interface is deleted. */
105 if_zebra_delete_hook (struct interface
*ifp
)
108 XFREE (MTYPE_TMP
, ifp
->info
);
112 /* Wake up configured address if it is not in current kernel
115 if_addr_wakeup (struct interface
*ifp
)
117 struct listnode
*node
;
118 struct connected
*ifc
;
122 for (node
= listhead (ifp
->connected
); node
; nextnode (node
))
124 ifc
= getdata (node
);
127 if (CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_CONFIGURED
)
128 && ! CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_REAL
))
131 if (p
->family
== AF_INET
)
133 if (! if_is_up (ifp
))
135 if_set_flags (ifp
, IFF_UP
| IFF_RUNNING
);
139 ret
= if_set_prefix (ifp
, ifc
);
142 zlog_warn ("Can't set interface's address: %s",
146 SET_FLAG (ifc
->conf
, ZEBRA_IFC_REAL
);
148 zebra_interface_address_add_update (ifp
, ifc
);
150 if (if_is_operative(ifp
))
151 connected_up_ipv4 (ifp
, ifc
);
154 if (p
->family
== AF_INET6
)
156 if (! if_is_up (ifp
))
158 if_set_flags (ifp
, IFF_UP
| IFF_RUNNING
);
162 ret
= if_prefix_add_ipv6 (ifp
, ifc
);
165 zlog_warn ("Can't set interface's address: %s",
169 SET_FLAG (ifc
->conf
, ZEBRA_IFC_REAL
);
171 zebra_interface_address_add_update (ifp
, ifc
);
173 if (if_is_operative(ifp
))
174 connected_up_ipv6 (ifp
, ifc
);
176 #endif /* HAVE_IPV6 */
181 /* Handle interface addition */
183 if_add_update (struct interface
*ifp
)
185 struct zebra_if
*if_data
;
188 if (if_data
->multicast
== IF_ZEBRA_MULTICAST_ON
)
189 if_set_flags (ifp
, IFF_MULTICAST
);
190 else if (if_data
->multicast
== IF_ZEBRA_MULTICAST_OFF
)
191 if_unset_flags (ifp
, IFF_MULTICAST
);
193 zebra_interface_add_update (ifp
);
195 if (! CHECK_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
))
197 SET_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
);
199 if_addr_wakeup (ifp
);
201 if (IS_ZEBRA_DEBUG_KERNEL
)
202 zlog_info ("interface %s index %d becomes active.",
203 ifp
->name
, ifp
->ifindex
);
207 if (IS_ZEBRA_DEBUG_KERNEL
)
208 zlog_info ("interface %s index %d is added.", ifp
->name
, ifp
->ifindex
);
212 /* Handle an interface delete event */
214 if_delete_update (struct interface
*ifp
)
216 struct listnode
*node
;
217 struct listnode
*next
;
218 struct connected
*ifc
;
223 zlog_err ("interface %s index %d is still up while being deleted.",
224 ifp
->name
, ifp
->ifindex
);
228 /* Mark interface as inactive */
229 UNSET_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
);
231 if (IS_ZEBRA_DEBUG_KERNEL
)
232 zlog_info ("interface %s index %d is now inactive.",
233 ifp
->name
, ifp
->ifindex
);
235 /* Delete connected routes from the kernel. */
238 for (node
= listhead (ifp
->connected
); node
; node
= next
)
241 ifc
= getdata (node
);
244 if (p
->family
== AF_INET
)
245 connected_down_ipv4 (ifp
, ifc
);
247 else if (p
->family
== AF_INET6
)
248 connected_down_ipv6 (ifp
, ifc
);
249 #endif /* HAVE_IPV6 */
251 zebra_interface_address_delete_update (ifp
, ifc
);
253 UNSET_FLAG (ifc
->conf
, ZEBRA_IFC_REAL
);
255 if (! CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
257 listnode_delete (ifp
->connected
, ifc
);
258 connected_free (ifc
);
262 zebra_interface_delete_update (ifp
);
265 /* Interface is up. */
267 if_up (struct interface
*ifp
)
271 struct connected
*ifc
;
274 /* Notify the protocol daemons. */
275 zebra_interface_up_update (ifp
);
277 /* Install connected routes to the kernel. */
280 for (node
= listhead (ifp
->connected
); node
; node
= next
)
283 ifc
= getdata (node
);
286 if (p
->family
== AF_INET
)
287 connected_up_ipv4 (ifp
, ifc
);
289 else if (p
->family
== AF_INET6
)
290 connected_up_ipv6 (ifp
, ifc
);
291 #endif /* HAVE_IPV6 */
295 /* Examine all static routes. */
299 /* Interface goes down. We have to manage different behavior of based
302 if_down (struct interface
*ifp
)
306 struct connected
*ifc
;
309 /* Notify to the protocol daemons. */
310 zebra_interface_down_update (ifp
);
312 /* Delete connected routes from the kernel. */
315 for (node
= listhead (ifp
->connected
); node
; node
= next
)
318 ifc
= getdata (node
);
321 if (p
->family
== AF_INET
)
322 connected_down_ipv4 (ifp
, ifc
);
324 else if (p
->family
== AF_INET6
)
325 connected_down_ipv6 (ifp
, ifc
);
326 #endif /* HAVE_IPV6 */
330 /* Examine all static routes which direct to the interface. */
335 if_refresh (struct interface
*ifp
)
337 if (if_is_operative (ifp
))
340 if (! if_is_operative (ifp
))
346 if (if_is_operative (ifp
))
351 /* Printout flag information into vty */
353 if_flag_dump_vty (struct vty
*vty
, unsigned long flag
)
357 #define IFF_OUT_VTY(X, Y) \
358 if ((X) && (flag & (X))) \
361 vty_out (vty, ","); \
368 IFF_OUT_VTY (IFF_UP
, "UP");
369 IFF_OUT_VTY (IFF_BROADCAST
, "BROADCAST");
370 IFF_OUT_VTY (IFF_DEBUG
, "DEBUG");
371 IFF_OUT_VTY (IFF_LOOPBACK
, "LOOPBACK");
372 IFF_OUT_VTY (IFF_POINTOPOINT
, "POINTOPOINT");
373 IFF_OUT_VTY (IFF_NOTRAILERS
, "NOTRAILERS");
374 IFF_OUT_VTY (IFF_RUNNING
, "RUNNING");
375 IFF_OUT_VTY (IFF_NOARP
, "NOARP");
376 IFF_OUT_VTY (IFF_PROMISC
, "PROMISC");
377 IFF_OUT_VTY (IFF_ALLMULTI
, "ALLMULTI");
378 IFF_OUT_VTY (IFF_OACTIVE
, "OACTIVE");
379 IFF_OUT_VTY (IFF_SIMPLEX
, "SIMPLEX");
380 IFF_OUT_VTY (IFF_LINK0
, "LINK0");
381 IFF_OUT_VTY (IFF_LINK1
, "LINK1");
382 IFF_OUT_VTY (IFF_LINK2
, "LINK2");
383 IFF_OUT_VTY (IFF_MULTICAST
, "MULTICAST");
387 /* Output prefix string to vty. */
389 prefix_vty_out (struct vty
*vty
, struct prefix
*p
)
391 char str
[INET6_ADDRSTRLEN
];
393 inet_ntop (p
->family
, &p
->u
.prefix
, str
, sizeof (str
));
394 vty_out (vty
, "%s", str
);
398 /* Dump if address information to vty. */
400 connected_dump_vty (struct vty
*vty
, struct connected
*connected
)
403 struct interface
*ifp
;
405 /* Set interface pointer. */
406 ifp
= connected
->ifp
;
408 /* Print interface address. */
409 p
= connected
->address
;
410 vty_out (vty
, " %s ", prefix_family_str (p
));
411 prefix_vty_out (vty
, p
);
412 vty_out (vty
, "/%d", p
->prefixlen
);
414 /* If there is destination address, print it. */
415 p
= connected
->destination
;
418 if (p
->family
== AF_INET
)
419 if (ifp
->flags
& IFF_BROADCAST
)
421 vty_out (vty
, " broadcast ");
422 prefix_vty_out (vty
, p
);
425 if (ifp
->flags
& IFF_POINTOPOINT
)
427 vty_out (vty
, " pointopoint ");
428 prefix_vty_out (vty
, p
);
432 if (CHECK_FLAG (connected
->flags
, ZEBRA_IFA_SECONDARY
))
433 vty_out (vty
, " secondary");
435 if (connected
->label
)
436 vty_out (vty
, " %s", connected
->label
);
438 vty_out (vty
, "%s", VTY_NEWLINE
);
442 /* Dump interface ND information to vty. */
444 nd_dump_vty (struct vty
*vty
, struct interface
*ifp
)
446 struct zebra_if
*zif
;
447 struct rtadvconf
*rtadv
;
449 zif
= (struct zebra_if
*) ifp
->info
;
452 if (rtadv
->AdvSendAdvertisements
)
454 vty_out (vty
, " ND advertised reachable time is %d milliseconds%s",
455 rtadv
->AdvReachableTime
, VTY_NEWLINE
);
456 vty_out (vty
, " ND advertised retransmit interval is %d milliseconds%s",
457 rtadv
->AdvRetransTimer
, VTY_NEWLINE
);
458 vty_out (vty
, " ND router advertisements are sent every %d seconds%s",
459 rtadv
->MaxRtrAdvInterval
, VTY_NEWLINE
);
460 vty_out (vty
, " ND router advertisements live for %d seconds%s",
461 rtadv
->AdvDefaultLifetime
, VTY_NEWLINE
);
462 if (rtadv
->AdvManagedFlag
)
463 vty_out (vty
, " Hosts use DHCP to obtain routable addresses.%s",
466 vty_out (vty
, " Hosts use stateless autoconfig for addresses.%s",
472 /* Interface's information print out to vty interface. */
474 if_dump_vty (struct vty
*vty
, struct interface
*ifp
)
476 #ifdef HAVE_SOCKADDR_DL
477 struct sockaddr_dl
*sdl
;
478 #endif /* HAVE_SOCKADDR_DL */
479 struct connected
*connected
;
482 vty_out (vty
, "Interface %s is ", ifp
->name
);
484 vty_out (vty
, "up, line protocol ");
486 if (CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_LINKDETECTION
)) {
487 if (if_is_running(ifp
))
488 vty_out (vty
, "is up%s", VTY_NEWLINE
);
490 vty_out (vty
, "is down%s", VTY_NEWLINE
);
492 vty_out (vty
, "detection is disabled%s", VTY_NEWLINE
);
495 vty_out (vty
, "down%s", VTY_NEWLINE
);
499 vty_out (vty
, " Description: %s%s", ifp
->desc
,
501 if (ifp
->ifindex
<= 0)
503 vty_out(vty
, " index %d pseudo interface%s", ifp
->ifindex
, VTY_NEWLINE
);
506 else if (! CHECK_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
))
508 vty_out(vty
, " index %d inactive interface%s",
514 vty_out (vty
, " index %d metric %d mtu %d ",
515 ifp
->ifindex
, ifp
->metric
, ifp
->mtu
);
516 if_flag_dump_vty (vty
, ifp
->flags
);
517 vty_out (vty
, "%s", VTY_NEWLINE
);
519 /* Hardware address. */
520 #ifdef HAVE_SOCKADDR_DL
522 if (sdl
!= NULL
&& sdl
->sdl_alen
!= 0)
527 vty_out (vty
, " HWaddr: ");
528 for (i
= 0, ptr
= LLADDR (sdl
); i
< sdl
->sdl_alen
; i
++, ptr
++)
529 vty_out (vty
, "%s%02x", i
== 0 ? "" : ":", *ptr
);
530 vty_out (vty
, "%s", VTY_NEWLINE
);
533 if (ifp
->hw_addr_len
!= 0)
537 vty_out (vty
, " HWaddr: ");
538 for (i
= 0; i
< ifp
->hw_addr_len
; i
++)
539 vty_out (vty
, "%s%02x", i
== 0 ? "" : ":", ifp
->hw_addr
[i
]);
540 vty_out (vty
, "%s", VTY_NEWLINE
);
542 #endif /* HAVE_SOCKADDR_DL */
544 /* Bandwidth in kbps */
545 if (ifp
->bandwidth
!= 0)
547 vty_out(vty
, " bandwidth %u kbps", ifp
->bandwidth
);
548 vty_out(vty
, "%s", VTY_NEWLINE
);
551 for (node
= listhead (ifp
->connected
); node
; nextnode (node
))
553 connected
= getdata (node
);
554 if (CHECK_FLAG (connected
->conf
, ZEBRA_IFC_REAL
))
555 connected_dump_vty (vty
, connected
);
559 nd_dump_vty (vty
, ifp
);
562 #ifdef HAVE_PROC_NET_DEV
563 /* Statistics print out using proc file system. */
564 vty_out (vty
, " input packets %lu, bytes %lu, dropped %lu,"
565 " multicast packets %lu%s",
566 ifp
->stats
.rx_packets
, ifp
->stats
.rx_bytes
,
567 ifp
->stats
.rx_dropped
, ifp
->stats
.rx_multicast
, VTY_NEWLINE
);
569 vty_out (vty
, " input errors %lu, length %lu, overrun %lu,"
570 " CRC %lu, frame %lu, fifo %lu, missed %lu%s",
571 ifp
->stats
.rx_errors
, ifp
->stats
.rx_length_errors
,
572 ifp
->stats
.rx_over_errors
, ifp
->stats
.rx_crc_errors
,
573 ifp
->stats
.rx_frame_errors
, ifp
->stats
.rx_fifo_errors
,
574 ifp
->stats
.rx_missed_errors
, VTY_NEWLINE
);
576 vty_out (vty
, " output packets %lu, bytes %lu, dropped %lu%s",
577 ifp
->stats
.tx_packets
, ifp
->stats
.tx_bytes
,
578 ifp
->stats
.tx_dropped
, VTY_NEWLINE
);
580 vty_out (vty
, " output errors %lu, aborted %lu, carrier %lu,"
581 " fifo %lu, heartbeat %lu, window %lu%s",
582 ifp
->stats
.tx_errors
, ifp
->stats
.tx_aborted_errors
,
583 ifp
->stats
.tx_carrier_errors
, ifp
->stats
.tx_fifo_errors
,
584 ifp
->stats
.tx_heartbeat_errors
, ifp
->stats
.tx_window_errors
,
587 vty_out (vty
, " collisions %lu%s", ifp
->stats
.collisions
, VTY_NEWLINE
);
588 #endif /* HAVE_PROC_NET_DEV */
590 #ifdef HAVE_NET_RT_IFLIST
591 #if defined (__bsdi__) || defined (__NetBSD__)
592 /* Statistics print out using sysctl (). */
593 vty_out (vty
, " input packets %qu, bytes %qu, dropped %qu,"
594 " multicast packets %qu%s",
595 ifp
->stats
.ifi_ipackets
, ifp
->stats
.ifi_ibytes
,
596 ifp
->stats
.ifi_iqdrops
, ifp
->stats
.ifi_imcasts
,
599 vty_out (vty
, " input errors %qu%s",
600 ifp
->stats
.ifi_ierrors
, VTY_NEWLINE
);
602 vty_out (vty
, " output packets %qu, bytes %qu, multicast packets %qu%s",
603 ifp
->stats
.ifi_opackets
, ifp
->stats
.ifi_obytes
,
604 ifp
->stats
.ifi_omcasts
, VTY_NEWLINE
);
606 vty_out (vty
, " output errors %qu%s",
607 ifp
->stats
.ifi_oerrors
, VTY_NEWLINE
);
609 vty_out (vty
, " collisions %qu%s",
610 ifp
->stats
.ifi_collisions
, VTY_NEWLINE
);
612 /* Statistics print out using sysctl (). */
613 vty_out (vty
, " input packets %lu, bytes %lu, dropped %lu,"
614 " multicast packets %lu%s",
615 ifp
->stats
.ifi_ipackets
, ifp
->stats
.ifi_ibytes
,
616 ifp
->stats
.ifi_iqdrops
, ifp
->stats
.ifi_imcasts
,
619 vty_out (vty
, " input errors %lu%s",
620 ifp
->stats
.ifi_ierrors
, VTY_NEWLINE
);
622 vty_out (vty
, " output packets %lu, bytes %lu, multicast packets %lu%s",
623 ifp
->stats
.ifi_opackets
, ifp
->stats
.ifi_obytes
,
624 ifp
->stats
.ifi_omcasts
, VTY_NEWLINE
);
626 vty_out (vty
, " output errors %lu%s",
627 ifp
->stats
.ifi_oerrors
, VTY_NEWLINE
);
629 vty_out (vty
, " collisions %lu%s",
630 ifp
->stats
.ifi_collisions
, VTY_NEWLINE
);
631 #endif /* __bsdi__ || __NetBSD__ */
632 #endif /* HAVE_NET_RT_IFLIST */
635 /* Check supported address family. */
637 if_supported_family (int family
)
639 if (family
== AF_INET
)
642 if (family
== AF_INET6
)
644 #endif /* HAVE_IPV6 */
648 /* Wrapper hook point for zebra daemon so that ifindex can be set
649 * DEFUN macro not used as extract.pl HAS to ignore this
650 * See also interface_cmd in lib/if.c
652 DEFUN_NOSH (zebra_interface
,
655 "Select an interface to configure\n"
656 "Interface's name\n")
659 struct interface
* ifp
;
661 /* Call lib interface() */
662 ret
= interface_cmd
.func (self
, vty
, argc
, argv
);
667 this only happens if interface is NOT in kernel */
668 if (ifp
->ifindex
== 0)
670 ifp
->ifindex
= if_new_intern_ifindex ();
671 UNSET_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
);
677 DEFUN (no_zebra_interface
,
678 no_zebra_interface_cmd
,
679 "no interface IFNAME",
680 "Delete a pseudo interface's configuration\n"
681 "Interface's name\n")
683 struct interface
*ifp
;
685 ifp
= if_lookup_by_name(argv
[0]);
689 vty_out (vty
, "Inteface %s does not exist%s",
695 if (CHECK_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
))
697 vty_out(vty
, "Only inactive interfaces can be deleted%s", VTY_NEWLINE
);
701 /* Delete interface */
707 struct cmd_node interface_node
=
714 /* Show all or specified interface to vty. */
715 DEFUN (show_interface
, show_interface_cmd
,
716 "show interface [IFNAME]",
718 "Interface status and configuration\n"
722 struct interface
*ifp
;
724 #ifdef HAVE_PROC_NET_DEV
725 /* If system has interface statistics via proc file system, update
727 ifstat_update_proc ();
728 #endif /* HAVE_PROC_NET_DEV */
729 #ifdef HAVE_NET_RT_IFLIST
730 ifstat_update_sysctl ();
731 #endif /* HAVE_NET_RT_IFLIST */
733 /* Specified interface print. */
736 ifp
= if_lookup_by_name (argv
[0]);
739 vty_out (vty
, "%% Can't find interface %s%s", argv
[0],
743 if_dump_vty (vty
, ifp
);
747 /* All interface print. */
748 for (node
= listhead (iflist
); node
; nextnode (node
))
749 if_dump_vty (vty
, getdata (node
));
757 "Set multicast flag to interface\n")
760 struct interface
*ifp
;
761 struct zebra_if
*if_data
;
763 ifp
= (struct interface
*) vty
->index
;
764 if (CHECK_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
))
766 ret
= if_set_flags (ifp
, IFF_MULTICAST
);
769 vty_out (vty
, "Can't set multicast flag%s", VTY_NEWLINE
);
775 if_data
->multicast
= IF_ZEBRA_MULTICAST_ON
;
784 "Unset multicast flag to interface\n")
787 struct interface
*ifp
;
788 struct zebra_if
*if_data
;
790 ifp
= (struct interface
*) vty
->index
;
791 if (CHECK_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
))
793 ret
= if_unset_flags (ifp
, IFF_MULTICAST
);
796 vty_out (vty
, "Can't unset multicast flag%s", VTY_NEWLINE
);
802 if_data
->multicast
= IF_ZEBRA_MULTICAST_OFF
;
810 "Enable link detection on interface\n")
812 struct interface
*ifp
;
813 int if_was_operative
;
815 ifp
= (struct interface
*) vty
->index
;
816 if_was_operative
= if_is_operative(ifp
);
817 SET_FLAG(ifp
->status
, ZEBRA_INTERFACE_LINKDETECTION
);
819 /* When linkdetection is enabled, if might come down */
820 if (!if_is_operative(ifp
) && if_was_operative
) if_down(ifp
);
822 /* FIXME: Will defer status change forwarding if interface
823 does not come down! */
829 DEFUN (no_linkdetect
,
833 "Disable link detection on interface\n")
835 struct interface
*ifp
;
836 int if_was_operative
;
838 ifp
= (struct interface
*) vty
->index
;
839 if_was_operative
= if_is_operative(ifp
);
840 UNSET_FLAG(ifp
->status
, ZEBRA_INTERFACE_LINKDETECTION
);
842 /* Interface may come up after disabling link detection */
843 if (if_is_operative(ifp
) && !if_was_operative
) if_up(ifp
);
845 /* FIXME: see linkdetect_cmd */
853 "Shutdown the selected interface\n")
856 struct interface
*ifp
;
857 struct zebra_if
*if_data
;
859 ifp
= (struct interface
*) vty
->index
;
860 ret
= if_unset_flags (ifp
, IFF_UP
);
863 vty_out (vty
, "Can't shutdown interface%s", VTY_NEWLINE
);
868 if_data
->shutdown
= IF_ZEBRA_SHUTDOWN_ON
;
873 DEFUN (no_shutdown_if
,
877 "Shutdown the selected interface\n")
880 struct interface
*ifp
;
881 struct zebra_if
*if_data
;
883 ifp
= (struct interface
*) vty
->index
;
884 ret
= if_set_flags (ifp
, IFF_UP
| IFF_RUNNING
);
887 vty_out (vty
, "Can't up interface%s", VTY_NEWLINE
);
892 if_data
->shutdown
= IF_ZEBRA_SHUTDOWN_OFF
;
899 "bandwidth <1-10000000>",
900 "Set bandwidth informational parameter\n"
901 "Bandwidth in kilobits\n")
903 struct interface
*ifp
;
904 unsigned int bandwidth
;
906 ifp
= (struct interface
*) vty
->index
;
907 bandwidth
= strtol(argv
[0], NULL
, 10);
909 /* bandwidth range is <1-10000000> */
910 if (bandwidth
< 1 || bandwidth
> 10000000)
912 vty_out (vty
, "Bandwidth is invalid%s", VTY_NEWLINE
);
916 ifp
->bandwidth
= bandwidth
;
918 /* force protocols to recalculate routes due to cost change */
919 if (if_is_operative (ifp
))
920 zebra_interface_up_update (ifp
);
925 DEFUN (no_bandwidth_if
,
929 "Set bandwidth informational parameter\n")
931 struct interface
*ifp
;
933 ifp
= (struct interface
*) vty
->index
;
937 /* force protocols to recalculate routes due to cost change */
938 if (if_is_operative (ifp
))
939 zebra_interface_up_update (ifp
);
944 ALIAS (no_bandwidth_if
,
945 no_bandwidth_if_val_cmd
,
946 "no bandwidth <1-10000000>",
948 "Set bandwidth informational parameter\n"
949 "Bandwidth in kilobits\n")
952 ip_address_install (struct vty
*vty
, struct interface
*ifp
, char *addr_str
,
953 char *peer_str
, char *label
, int secondary
)
955 struct prefix_ipv4 cp
;
956 struct connected
*ifc
;
957 struct prefix_ipv4
*p
;
961 ret
= str2prefix_ipv4 (addr_str
, &cp
);
964 vty_out (vty
, "%% Malformed address %s", VTY_NEWLINE
);
968 ifc
= connected_check_ipv4 (ifp
, (struct prefix
*) &cp
);
971 ifc
= connected_new ();
975 p
= prefix_ipv4_new ();
977 ifc
->address
= (struct prefix
*) p
;
980 if (p
->prefixlen
<= 30)
982 p
= prefix_ipv4_new ();
984 masklen2ip (p
->prefixlen
, &mask
);
985 p
->prefix
.s_addr
|= ~mask
.s_addr
;
986 ifc
->destination
= (struct prefix
*) p
;
991 SET_FLAG (ifc
->flags
, ZEBRA_IFA_SECONDARY
);
995 ifc
->label
= strdup (label
);
997 /* Add to linked list. */
998 listnode_add (ifp
->connected
, ifc
);
1001 /* This address is configured from zebra. */
1002 if (! CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
1003 SET_FLAG (ifc
->conf
, ZEBRA_IFC_CONFIGURED
);
1005 /* In case of this route need to install kernel. */
1006 if (! CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_REAL
)
1007 && CHECK_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
))
1009 /* Some system need to up the interface to set IP address. */
1010 if (! if_is_up (ifp
))
1012 if_set_flags (ifp
, IFF_UP
| IFF_RUNNING
);
1016 ret
= if_set_prefix (ifp
, ifc
);
1019 vty_out (vty
, "%% Can't set interface IP address: %s.%s",
1020 strerror(errno
), VTY_NEWLINE
);
1024 /* IP address propery set. */
1025 SET_FLAG (ifc
->conf
, ZEBRA_IFC_REAL
);
1027 /* Update interface address information to protocol daemon. */
1028 zebra_interface_address_add_update (ifp
, ifc
);
1030 /* If interface is up register connected route. */
1031 if (if_is_operative(ifp
))
1032 connected_up_ipv4 (ifp
, ifc
);
1039 ip_address_uninstall (struct vty
*vty
, struct interface
*ifp
, char *addr_str
,
1040 char *peer_str
, char *label
, int secondry
)
1042 struct prefix_ipv4 cp
;
1043 struct connected
*ifc
;
1046 /* Convert to prefix structure. */
1047 ret
= str2prefix_ipv4 (addr_str
, &cp
);
1050 vty_out (vty
, "%% Malformed address %s", VTY_NEWLINE
);
1054 /* Check current interface address. */
1055 ifc
= connected_check_ipv4 (ifp
, (struct prefix
*) &cp
);
1058 vty_out (vty
, "%% Can't find address%s", VTY_NEWLINE
);
1062 /* This is not configured address. */
1063 if (! CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
1066 /* This is not real address or interface is not active. */
1067 if (! CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_REAL
)
1068 || ! CHECK_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
))
1070 listnode_delete (ifp
->connected
, ifc
);
1071 connected_free (ifc
);
1075 /* This is real route. */
1076 ret
= if_unset_prefix (ifp
, ifc
);
1079 vty_out (vty
, "%% Can't unset interface IP address: %s.%s",
1080 strerror(errno
), VTY_NEWLINE
);
1084 /* Redistribute this information. */
1085 zebra_interface_address_delete_update (ifp
, ifc
);
1087 /* Remove connected route. */
1088 connected_down_ipv4 (ifp
, ifc
);
1090 /* Free address information. */
1091 listnode_delete (ifp
->connected
, ifc
);
1092 connected_free (ifc
);
1099 "ip address A.B.C.D/M",
1100 "Interface Internet Protocol config commands\n"
1101 "Set the IP address of an interface\n"
1102 "IP address (e.g. 10.0.0.1/8)\n")
1104 return ip_address_install (vty
, vty
->index
, argv
[0], NULL
, NULL
, 0);
1107 DEFUN (no_ip_address
,
1109 "no ip address A.B.C.D/M",
1111 "Interface Internet Protocol config commands\n"
1112 "Set the IP address of an interface\n"
1113 "IP Address (e.g. 10.0.0.1/8)")
1115 return ip_address_uninstall (vty
, vty
->index
, argv
[0], NULL
, NULL
, 0);
1119 DEFUN (ip_address_secondary
,
1120 ip_address_secondary_cmd
,
1121 "ip address A.B.C.D/M secondary",
1122 "Interface Internet Protocol config commands\n"
1123 "Set the IP address of an interface\n"
1124 "IP address (e.g. 10.0.0.1/8)\n"
1125 "Secondary IP address\n")
1127 return ip_address_install (vty
, vty
->index
, argv
[0], NULL
, NULL
, 1);
1130 DEFUN (ip_address_label
,
1131 ip_address_label_cmd
,
1132 "ip address A.B.C.D/M 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 "Label of this address\n"
1139 return ip_address_install (vty
, vty
->index
, argv
[0], NULL
, argv
[1], 1);
1142 DEFUN (no_ip_address_secondary
,
1143 no_ip_address_secondary_cmd
,
1144 "no ip address A.B.C.D/M secondary",
1146 "Interface Internet Protocol config commands\n"
1147 "Set the IP address of an interface\n"
1148 "IP address (e.g. 10.0.0.1/8)\n"
1149 "Secondary IP address\n")
1151 return ip_address_uninstall (vty
, vty
->index
, argv
[0], NULL
, NULL
, 1);
1154 DEFUN (no_ip_address_label
,
1155 no_ip_address_label_cmd
,
1156 "no ip address A.B.C.D/M label LINE",
1158 "Interface Internet Protocol config commands\n"
1159 "Set the IP address of an interface\n"
1160 "IP address (e.g. 10.0.0.1/8)\n"
1161 "Label of this address\n"
1164 return ip_address_uninstall (vty
, vty
->index
, argv
[0], NULL
, argv
[1], 1);
1166 #endif /* HAVE_NETLINK */
1170 ipv6_address_install (struct vty
*vty
, struct interface
*ifp
, char *addr_str
,
1171 char *peer_str
, char *label
, int secondary
)
1173 struct prefix_ipv6 cp
;
1174 struct connected
*ifc
;
1175 struct prefix_ipv6
*p
;
1178 ret
= str2prefix_ipv6 (addr_str
, &cp
);
1181 vty_out (vty
, "%% Malformed address %s", VTY_NEWLINE
);
1185 ifc
= connected_check_ipv6 (ifp
, (struct prefix
*) &cp
);
1188 ifc
= connected_new ();
1192 p
= prefix_ipv6_new ();
1194 ifc
->address
= (struct prefix
*) p
;
1198 SET_FLAG (ifc
->flags
, ZEBRA_IFA_SECONDARY
);
1202 ifc
->label
= strdup (label
);
1204 /* Add to linked list. */
1205 listnode_add (ifp
->connected
, ifc
);
1208 /* This address is configured from zebra. */
1209 if (! CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
1210 SET_FLAG (ifc
->conf
, ZEBRA_IFC_CONFIGURED
);
1212 /* In case of this route need to install kernel. */
1213 if (! CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_REAL
)
1214 && CHECK_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
))
1216 /* Some system need to up the interface to set IP address. */
1217 if (! if_is_up (ifp
))
1219 if_set_flags (ifp
, IFF_UP
| IFF_RUNNING
);
1223 ret
= if_prefix_add_ipv6 (ifp
, ifc
);
1227 vty_out (vty
, "%% Can't set interface IP address: %s.%s",
1228 strerror(errno
), VTY_NEWLINE
);
1232 /* IP address propery set. */
1233 SET_FLAG (ifc
->conf
, ZEBRA_IFC_REAL
);
1235 /* Update interface address information to protocol daemon. */
1236 zebra_interface_address_add_update (ifp
, ifc
);
1238 /* If interface is up register connected route. */
1239 if (if_is_operative(ifp
))
1240 connected_up_ipv6 (ifp
, ifc
);
1247 ipv6_address_uninstall (struct vty
*vty
, struct interface
*ifp
, char *addr_str
,
1248 char *peer_str
, char *label
, int secondry
)
1250 struct prefix_ipv6 cp
;
1251 struct connected
*ifc
;
1254 /* Convert to prefix structure. */
1255 ret
= str2prefix_ipv6 (addr_str
, &cp
);
1258 vty_out (vty
, "%% Malformed address %s", VTY_NEWLINE
);
1262 /* Check current interface address. */
1263 ifc
= connected_check_ipv6 (ifp
, (struct prefix
*) &cp
);
1266 vty_out (vty
, "%% Can't find address%s", VTY_NEWLINE
);
1270 /* This is not configured address. */
1271 if (! CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
1274 /* This is not real address or interface is not active. */
1275 if (! CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_REAL
)
1276 || ! CHECK_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
))
1278 listnode_delete (ifp
->connected
, ifc
);
1279 connected_free (ifc
);
1283 /* This is real route. */
1284 ret
= if_prefix_delete_ipv6 (ifp
, ifc
);
1287 vty_out (vty
, "%% Can't unset interface IP address: %s.%s",
1288 strerror(errno
), VTY_NEWLINE
);
1292 /* Redistribute this information. */
1293 zebra_interface_address_delete_update (ifp
, ifc
);
1295 /* Remove connected route. */
1296 connected_down_ipv6 (ifp
, ifc
);
1298 /* Free address information. */
1299 listnode_delete (ifp
->connected
, ifc
);
1300 connected_free (ifc
);
1305 DEFUN (ipv6_address
,
1307 "ipv6 address X:X::X:X/M",
1308 "Interface Internet Protocol config commands\n"
1309 "Set the IP address of an interface\n"
1310 "IPv6 address (e.g. 3ffe:506::1/48)\n")
1312 return ipv6_address_install (vty
, vty
->index
, argv
[0], NULL
, NULL
, 0);
1315 DEFUN (no_ipv6_address
,
1316 no_ipv6_address_cmd
,
1317 "no ipv6 address X:X::X:X/M",
1319 "Interface Internet Protocol config commands\n"
1320 "Set the IP address of an interface\n"
1321 "IPv6 address (e.g. 3ffe:506::1/48)\n")
1323 return ipv6_address_uninstall (vty
, vty
->index
, argv
[0], NULL
, NULL
, 0);
1325 #endif /* HAVE_IPV6 */
1330 "ip tunnel IP_address IP_address",
1331 "KAME ip tunneling configuration commands\n"
1332 "Set FROM IP address and TO IP address\n")
1337 DEFUN (no_ip_tunnel
, no_ip_tunnel_cmd
,
1340 "Set FROM IP address and TO IP address\n")
1347 if_config_write (struct vty
*vty
)
1350 struct interface
*ifp
;
1353 for (node
= listhead (iflist
); node
; nextnode (node
))
1355 struct zebra_if
*if_data
;
1357 struct connected
*ifc
;
1360 ifp
= getdata (node
);
1361 if_data
= ifp
->info
;
1363 vty_out (vty
, "interface %s%s", ifp
->name
,
1367 vty_out (vty
, " description %s%s", ifp
->desc
,
1370 /* Assign bandwidth here to avoid unnecessary interface flap
1371 while processing config script */
1372 if (ifp
->bandwidth
!= 0)
1373 vty_out(vty
, " bandwidth %u%s", ifp
->bandwidth
, VTY_NEWLINE
);
1375 if (CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_LINKDETECTION
))
1376 vty_out(vty
, " link-detect%s", VTY_NEWLINE
);
1378 for (addrnode
= listhead (ifp
->connected
); addrnode
; nextnode (addrnode
))
1380 ifc
= getdata (addrnode
);
1381 if (CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
1384 vty_out (vty
, " ip%s address %s/%d",
1385 p
->family
== AF_INET
? "" : "v6",
1386 inet_ntop (p
->family
, &p
->u
.prefix
, buf
, BUFSIZ
),
1389 if (CHECK_FLAG (ifc
->flags
, ZEBRA_IFA_SECONDARY
))
1390 vty_out (vty
, " secondary");
1393 vty_out (vty
, " label %s", ifc
->label
);
1395 vty_out (vty
, "%s", VTY_NEWLINE
);
1401 if (if_data
->shutdown
== IF_ZEBRA_SHUTDOWN_ON
)
1402 vty_out (vty
, " shutdown%s", VTY_NEWLINE
);
1404 if (if_data
->multicast
!= IF_ZEBRA_MULTICAST_UNSPEC
)
1405 vty_out (vty
, " %smulticast%s",
1406 if_data
->multicast
== IF_ZEBRA_MULTICAST_ON
? "" : "no ",
1411 rtadv_config_write (vty
, ifp
);
1414 vty_out (vty
, "!%s", VTY_NEWLINE
);
1419 /* Allocate and initialize interface vector. */
1423 /* Initialize interface and new hook. */
1425 if_add_hook (IF_NEW_HOOK
, if_zebra_new_hook
);
1426 if_add_hook (IF_DELETE_HOOK
, if_zebra_delete_hook
);
1428 /* Install configuration write function. */
1429 install_node (&interface_node
, if_config_write
);
1431 install_element (VIEW_NODE
, &show_interface_cmd
);
1432 install_element (ENABLE_NODE
, &show_interface_cmd
);
1433 install_element (CONFIG_NODE
, &zebra_interface_cmd
);
1434 install_element (CONFIG_NODE
, &no_zebra_interface_cmd
);
1435 install_default (INTERFACE_NODE
);
1436 install_element (INTERFACE_NODE
, &interface_desc_cmd
);
1437 install_element (INTERFACE_NODE
, &no_interface_desc_cmd
);
1438 install_element (INTERFACE_NODE
, &multicast_cmd
);
1439 install_element (INTERFACE_NODE
, &no_multicast_cmd
);
1440 install_element (INTERFACE_NODE
, &linkdetect_cmd
);
1441 install_element (INTERFACE_NODE
, &no_linkdetect_cmd
);
1442 install_element (INTERFACE_NODE
, &shutdown_if_cmd
);
1443 install_element (INTERFACE_NODE
, &no_shutdown_if_cmd
);
1444 install_element (INTERFACE_NODE
, &bandwidth_if_cmd
);
1445 install_element (INTERFACE_NODE
, &no_bandwidth_if_cmd
);
1446 install_element (INTERFACE_NODE
, &no_bandwidth_if_val_cmd
);
1447 install_element (INTERFACE_NODE
, &ip_address_cmd
);
1448 install_element (INTERFACE_NODE
, &no_ip_address_cmd
);
1450 install_element (INTERFACE_NODE
, &ipv6_address_cmd
);
1451 install_element (INTERFACE_NODE
, &no_ipv6_address_cmd
);
1452 #endif /* HAVE_IPV6 */
1454 install_element (INTERFACE_NODE
, &ip_tunnel_cmd
);
1455 install_element (INTERFACE_NODE
, &no_ip_tunnel_cmd
);
1458 install_element (INTERFACE_NODE
, &ip_address_secondary_cmd
);
1459 install_element (INTERFACE_NODE
, &ip_address_label_cmd
);
1460 install_element (INTERFACE_NODE
, &no_ip_address_secondary_cmd
);
1461 install_element (INTERFACE_NODE
, &no_ip_address_label_cmd
);
1462 #endif /* HAVE_NETLINK */