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"
43 #include "zebra/zebra_ptm.h"
45 #define ZEBRA_PTM_SUPPORT
48 /* Order is intentional. Matches RFC4191. This array is also used for
49 command matching, so only modify with care. */
50 const char *rtadv_pref_strs
[] = { "medium", "high", "INVALID", "low", 0 };
53 /* Called when new interface is added. */
55 if_zebra_new_hook (struct interface
*ifp
)
57 struct zebra_if
*zebra_if
;
59 zebra_if
= XCALLOC (MTYPE_TMP
, sizeof (struct zebra_if
));
61 zebra_if
->multicast
= IF_ZEBRA_MULTICAST_UNSPEC
;
62 zebra_if
->shutdown
= IF_ZEBRA_SHUTDOWN_OFF
;
64 ifp
->ptm_enable
= ptm_enable
;
67 /* Set default router advertise values. */
68 struct rtadvconf
*rtadv
;
70 rtadv
= &zebra_if
->rtadv
;
72 rtadv
->AdvSendAdvertisements
= 0;
73 rtadv
->MaxRtrAdvInterval
= RTADV_MAX_RTR_ADV_INTERVAL
;
74 rtadv
->MinRtrAdvInterval
= RTADV_MIN_RTR_ADV_INTERVAL
;
75 rtadv
->AdvIntervalTimer
= 0;
76 rtadv
->AdvManagedFlag
= 0;
77 rtadv
->AdvOtherConfigFlag
= 0;
78 rtadv
->AdvHomeAgentFlag
= 0;
79 rtadv
->AdvLinkMTU
= 0;
80 rtadv
->AdvReachableTime
= 0;
81 rtadv
->AdvRetransTimer
= 0;
82 rtadv
->AdvCurHopLimit
= 0;
83 rtadv
->AdvDefaultLifetime
= -1; /* derive from MaxRtrAdvInterval */
84 rtadv
->HomeAgentPreference
= 0;
85 rtadv
->HomeAgentLifetime
= -1; /* derive from AdvDefaultLifetime */
86 rtadv
->AdvIntervalOption
= 0;
87 rtadv
->DefaultPreference
= RTADV_PREF_MEDIUM
;
89 rtadv
->AdvPrefixList
= list_new ();
93 /* Initialize installed address chains tree. */
94 zebra_if
->ipv4_subnets
= route_table_init ();
100 /* Called when interface is deleted. */
102 if_zebra_delete_hook (struct interface
*ifp
)
104 struct zebra_if
*zebra_if
;
108 zebra_if
= ifp
->info
;
110 /* Free installed address chains tree. */
111 if (zebra_if
->ipv4_subnets
)
112 route_table_finish (zebra_if
->ipv4_subnets
);
114 XFREE (MTYPE_TMP
, zebra_if
);
120 /* Tie an interface address to its derived subnet list of addresses. */
122 if_subnet_add (struct interface
*ifp
, struct connected
*ifc
)
124 struct route_node
*rn
;
125 struct zebra_if
*zebra_if
;
127 struct list
*addr_list
;
129 assert (ifp
&& ifp
->info
&& ifc
);
130 zebra_if
= ifp
->info
;
132 /* Get address derived subnet node and associated address list, while marking
133 address secondary attribute appropriately. */
136 rn
= route_node_get (zebra_if
->ipv4_subnets
, &cp
);
138 if ((addr_list
= rn
->info
))
139 SET_FLAG (ifc
->flags
, ZEBRA_IFA_SECONDARY
);
142 UNSET_FLAG (ifc
->flags
, ZEBRA_IFA_SECONDARY
);
143 rn
->info
= addr_list
= list_new ();
144 route_lock_node (rn
);
147 /* Tie address at the tail of address list. */
148 listnode_add (addr_list
, ifc
);
150 /* Return list element count. */
151 return (addr_list
->count
);
154 /* Untie an interface address from its derived subnet list of addresses. */
156 if_subnet_delete (struct interface
*ifp
, struct connected
*ifc
)
158 struct route_node
*rn
;
159 struct zebra_if
*zebra_if
;
160 struct list
*addr_list
;
162 assert (ifp
&& ifp
->info
&& ifc
);
163 zebra_if
= ifp
->info
;
165 /* Get address derived subnet node. */
166 rn
= route_node_lookup (zebra_if
->ipv4_subnets
, ifc
->address
);
167 if (! (rn
&& rn
->info
))
169 zlog_warn("Trying to remove an address from an unknown subnet."
170 " (please report this bug)");
173 route_unlock_node (rn
);
175 /* Untie address from subnet's address list. */
176 addr_list
= rn
->info
;
178 /* Deleting an address that is not registered is a bug.
179 * In any case, we shouldn't decrement the lock counter if the address
181 if (!listnode_lookup(addr_list
, ifc
))
183 zlog_warn("Trying to remove an address from a subnet where it is not"
184 " currently registered. (please report this bug)");
188 listnode_delete (addr_list
, ifc
);
189 route_unlock_node (rn
);
191 /* Return list element count, if not empty. */
192 if (addr_list
->count
)
194 /* If deleted address is primary, mark subsequent one as such and distribute. */
195 if (! CHECK_FLAG (ifc
->flags
, ZEBRA_IFA_SECONDARY
))
197 ifc
= listgetdata (listhead (addr_list
));
198 zebra_interface_address_delete_update (ifp
, ifc
);
199 UNSET_FLAG (ifc
->flags
, ZEBRA_IFA_SECONDARY
);
200 /* XXX: Linux kernel removes all the secondary addresses when the primary
201 * address is removed. We could try to work around that, though this is
203 zebra_interface_address_add_update (ifp
, ifc
);
206 return addr_list
->count
;
209 /* Otherwise, free list and route node. */
210 list_free (addr_list
);
212 route_unlock_node (rn
);
217 /* if_flags_mangle: A place for hacks that require mangling
218 * or tweaking the interface flags.
220 * ******************** Solaris flags hacks **************************
222 * Solaris IFF_UP flag reflects only the primary interface as the
223 * routing socket only sends IFINFO for the primary interface. Hence
224 * ~IFF_UP does not per se imply all the logical interfaces are also
225 * down - which we only know of as addresses. Instead we must determine
226 * whether the interface really is up or not according to how many
227 * addresses are still attached. (Solaris always sends RTM_DELADDR if
228 * an interface, logical or not, goes ~IFF_UP).
230 * Ie, we mangle IFF_UP to *additionally* reflect whether or not there
231 * are addresses left in struct connected, not just the actual underlying
234 * We must hence remember the real state of IFF_UP, which we do in
235 * struct zebra_if.primary_state.
237 * Setting IFF_UP within zebra to administratively shutdown the
238 * interface will affect only the primary interface/address on Solaris.
239 ************************End Solaris flags hacks ***********************
242 if_flags_mangle (struct interface
*ifp
, uint64_t *newflags
)
245 struct zebra_if
*zif
= ifp
->info
;
247 zif
->primary_state
= *newflags
& (IFF_UP
& 0xff);
249 if (CHECK_FLAG (zif
->primary_state
, IFF_UP
)
250 || listcount(ifp
->connected
) > 0)
251 SET_FLAG (*newflags
, IFF_UP
);
253 UNSET_FLAG (*newflags
, IFF_UP
);
257 /* Update the flags field of the ifp with the new flag set provided.
258 * Take whatever actions are required for any changes in flags we care
261 * newflags should be the raw value, as obtained from the OS.
264 if_flags_update (struct interface
*ifp
, uint64_t newflags
)
266 if_flags_mangle (ifp
, &newflags
);
268 if (if_is_no_ptm_operative (ifp
))
270 /* operative -> inoperative? */
271 ifp
->flags
= newflags
;
272 if (!if_is_operative (ifp
))
277 /* inoperative -> operative? */
278 ifp
->flags
= newflags
;
279 if (if_is_operative (ifp
))
284 /* Wake up configured address if it is not in current kernel
287 if_addr_wakeup (struct interface
*ifp
)
289 struct listnode
*node
, *nnode
;
290 struct connected
*ifc
;
294 for (ALL_LIST_ELEMENTS (ifp
->connected
, node
, nnode
, ifc
))
298 if (CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_CONFIGURED
)
299 && ! CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_QUEUED
))
302 if (p
->family
== AF_INET
)
304 if (! if_is_up (ifp
))
306 /* Assume zebra is configured like following:
309 * ip addr 192.0.2.1/24
312 * As soon as zebra becomes first aware that gre0 exists in the
313 * kernel, it will set gre0 up and configure its addresses.
315 * (This may happen at startup when the interface already exists
316 * or during runtime when the interface is added to the kernel)
318 * XXX: IRDP code is calling here via if_add_update - this seems
320 * XXX: RUNNING is not a settable flag on any system
321 * I (paulj) am aware of.
323 if_set_flags (ifp
, IFF_UP
| IFF_RUNNING
);
327 ret
= if_set_prefix (ifp
, ifc
);
330 zlog_warn ("Can't set interface's address: %s",
331 safe_strerror(errno
));
335 SET_FLAG (ifc
->conf
, ZEBRA_IFC_QUEUED
);
336 /* The address will be advertised to zebra clients when the notification
337 * from the kernel has been received.
338 * It will also be added to the interface's subnet list then. */
341 if (p
->family
== AF_INET6
)
343 if (! if_is_up (ifp
))
345 /* See long comment above */
346 if_set_flags (ifp
, IFF_UP
| IFF_RUNNING
);
350 ret
= if_prefix_add_ipv6 (ifp
, ifc
);
353 zlog_warn ("Can't set interface's address: %s",
354 safe_strerror(errno
));
358 SET_FLAG (ifc
->conf
, ZEBRA_IFC_QUEUED
);
359 /* The address will be advertised to zebra clients when the notification
360 * from the kernel has been received. */
362 #endif /* HAVE_IPV6 */
367 /* Handle interface addition */
369 if_add_update (struct interface
*ifp
)
371 struct zebra_if
*if_data
;
374 if (if_data
->multicast
== IF_ZEBRA_MULTICAST_ON
)
375 if_set_flags (ifp
, IFF_MULTICAST
);
376 else if (if_data
->multicast
== IF_ZEBRA_MULTICAST_OFF
)
377 if_unset_flags (ifp
, IFF_MULTICAST
);
379 zebra_interface_add_update (ifp
);
381 if (! CHECK_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
))
383 SET_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
);
385 if (if_data
&& if_data
->shutdown
== IF_ZEBRA_SHUTDOWN_ON
)
387 if (IS_ZEBRA_DEBUG_KERNEL
)
388 zlog_debug ("interface %s index %d is shutdown. Won't wake it up.",
389 ifp
->name
, ifp
->ifindex
);
393 if_addr_wakeup (ifp
);
395 if (IS_ZEBRA_DEBUG_KERNEL
)
396 zlog_debug ("interface %s index %d becomes active.",
397 ifp
->name
, ifp
->ifindex
);
401 if (IS_ZEBRA_DEBUG_KERNEL
)
402 zlog_debug ("interface %s index %d is added.", ifp
->name
, ifp
->ifindex
);
406 /* Handle an interface delete event */
408 if_delete_update (struct interface
*ifp
)
410 struct connected
*ifc
;
412 struct route_node
*rn
;
413 struct zebra_if
*zebra_if
;
415 zebra_if
= ifp
->info
;
419 zlog_err ("interface %s index %d is still up while being deleted.",
420 ifp
->name
, ifp
->ifindex
);
424 /* Mark interface as inactive */
425 UNSET_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
);
427 if (IS_ZEBRA_DEBUG_KERNEL
)
428 zlog_debug ("interface %s index %d is now inactive.",
429 ifp
->name
, ifp
->ifindex
);
431 /* Delete connected routes from the kernel. */
434 struct listnode
*node
;
435 struct listnode
*last
= NULL
;
437 while ((node
= (last
? last
->next
: listhead (ifp
->connected
))))
439 ifc
= listgetdata (node
);
442 if (p
->family
== AF_INET
443 && (rn
= route_node_lookup (zebra_if
->ipv4_subnets
, p
)))
445 struct listnode
*anode
;
446 struct listnode
*next
;
447 struct listnode
*first
;
448 struct list
*addr_list
;
450 route_unlock_node (rn
);
451 addr_list
= (struct list
*) rn
->info
;
453 /* Remove addresses, secondaries first. */
454 first
= listhead (addr_list
);
455 for (anode
= first
->next
; anode
|| first
; anode
= next
)
464 ifc
= listgetdata (anode
);
466 connected_down_ipv4 (ifp
, ifc
);
468 /* XXX: We have to send notifications here explicitly, because we destroy
469 * the ifc before receiving the notification about the address being deleted.
471 zebra_interface_address_delete_update (ifp
, ifc
);
473 UNSET_FLAG (ifc
->conf
, ZEBRA_IFC_REAL
);
474 UNSET_FLAG (ifc
->conf
, ZEBRA_IFC_QUEUED
);
476 /* Remove from subnet chain. */
477 list_delete_node (addr_list
, anode
);
478 route_unlock_node (rn
);
480 /* Remove from interface address list (unconditionally). */
481 if (!CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
483 listnode_delete (ifp
->connected
, ifc
);
484 connected_free (ifc
);
490 /* Free chain list and respective route node. */
491 list_delete (addr_list
);
493 route_unlock_node (rn
);
496 else if (p
->family
== AF_INET6
)
498 connected_down_ipv6 (ifp
, ifc
);
500 zebra_interface_address_delete_update (ifp
, ifc
);
502 UNSET_FLAG (ifc
->conf
, ZEBRA_IFC_REAL
);
503 UNSET_FLAG (ifc
->conf
, ZEBRA_IFC_QUEUED
);
505 if (CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
509 listnode_delete (ifp
->connected
, ifc
);
510 connected_free (ifc
);
513 #endif /* HAVE_IPV6 */
520 zebra_interface_delete_update (ifp
);
522 /* Update ifindex after distributing the delete message. This is in
523 case any client needs to have the old value of ifindex available
524 while processing the deletion. Each client daemon is responsible
525 for setting ifindex to IFINDEX_INTERNAL after processing the
526 interface deletion message. */
527 ifp
->ifindex
= IFINDEX_INTERNAL
;
530 /* Interface is up. */
532 if_up (struct interface
*ifp
)
534 struct listnode
*node
;
535 struct listnode
*next
;
536 struct connected
*ifc
;
539 /* Notify the protocol daemons. */
540 if (ifp
->ptm_enable
&& !ifp
->ptm_status
) {
541 zlog_warn("%s: interface %s hasn't passed ptm check\n", __func__
,
545 zebra_interface_up_update (ifp
);
548 /* Install connected routes to the kernel. */
551 for (ALL_LIST_ELEMENTS (ifp
->connected
, node
, next
, ifc
))
555 if (p
->family
== AF_INET
)
556 connected_up_ipv4 (ifp
, ifc
);
558 else if (p
->family
== AF_INET6
)
559 connected_up_ipv6 (ifp
, ifc
);
560 #endif /* HAVE_IPV6 */
564 /* Examine all static routes. */
568 /* Interface goes down. We have to manage different behavior of based
571 if_down (struct interface
*ifp
)
573 struct listnode
*node
;
574 struct listnode
*next
;
575 struct connected
*ifc
;
578 /* Notify to the protocol daemons. */
579 zebra_interface_down_update (ifp
);
581 /* Delete connected routes from the kernel. */
584 for (ALL_LIST_ELEMENTS (ifp
->connected
, node
, next
, ifc
))
588 if (p
->family
== AF_INET
)
589 connected_down_ipv4 (ifp
, ifc
);
591 else if (p
->family
== AF_INET6
)
592 connected_down_ipv6 (ifp
, ifc
);
593 #endif /* HAVE_IPV6 */
597 /* Examine all static routes which direct to the interface. */
602 if_refresh (struct interface
*ifp
)
607 /* BFD session goes down, send message to the protocols. */
609 if_bfd_session_down (struct interface
*ifp
, struct prefix
*p
)
611 if (IS_ZEBRA_DEBUG_EVENT
)
613 char buf
[INET6_ADDRSTRLEN
];
615 zlog_debug ("MESSAGE: ZEBRA_INTERFACE_BFD_DEST_DOWN %s/%d on %s",
616 inet_ntop (p
->family
, &p
->u
.prefix
, buf
, INET6_ADDRSTRLEN
),
617 p
->prefixlen
, ifp
->name
);
620 zebra_interface_bfd_update (ifp
, p
);
624 /* Output prefix string to vty. */
626 prefix_vty_out (struct vty
*vty
, struct prefix
*p
)
628 char str
[INET6_ADDRSTRLEN
];
630 inet_ntop (p
->family
, &p
->u
.prefix
, str
, sizeof (str
));
631 vty_out (vty
, "%s", str
);
635 /* Dump if address information to vty. */
637 connected_dump_vty (struct vty
*vty
, struct connected
*connected
)
641 /* Print interface address. */
642 p
= connected
->address
;
643 vty_out (vty
, " %s ", prefix_family_str (p
));
644 prefix_vty_out (vty
, p
);
645 vty_out (vty
, "/%d", p
->prefixlen
);
647 /* If there is destination address, print it. */
648 if (connected
->destination
)
650 vty_out (vty
, (CONNECTED_PEER(connected
) ? " peer " : " broadcast "));
651 prefix_vty_out (vty
, connected
->destination
);
654 if (CHECK_FLAG (connected
->flags
, ZEBRA_IFA_SECONDARY
))
655 vty_out (vty
, " secondary");
657 if (connected
->label
)
658 vty_out (vty
, " %s", connected
->label
);
660 vty_out (vty
, "%s", VTY_NEWLINE
);
663 /* Dump interface neighbor address information to vty. */
665 nbr_connected_dump_vty (struct vty
*vty
, struct nbr_connected
*connected
)
669 /* Print interface address. */
670 p
= connected
->address
;
671 vty_out (vty
, " %s ", prefix_family_str (p
));
672 prefix_vty_out (vty
, p
);
673 vty_out (vty
, "/%d", p
->prefixlen
);
675 vty_out (vty
, "%s", VTY_NEWLINE
);
679 /* Dump interface ND information to vty. */
681 nd_dump_vty (struct vty
*vty
, struct interface
*ifp
)
683 struct zebra_if
*zif
;
684 struct rtadvconf
*rtadv
;
687 zif
= (struct zebra_if
*) ifp
->info
;
690 if (rtadv
->AdvSendAdvertisements
)
692 vty_out (vty
, " ND advertised reachable time is %d milliseconds%s",
693 rtadv
->AdvReachableTime
, VTY_NEWLINE
);
694 vty_out (vty
, " ND advertised retransmit interval is %d milliseconds%s",
695 rtadv
->AdvRetransTimer
, VTY_NEWLINE
);
696 interval
= rtadv
->MaxRtrAdvInterval
;
698 vty_out (vty
, " ND router advertisements are sent every "
699 "%d milliseconds%s", interval
,
702 vty_out (vty
, " ND router advertisements are sent every "
703 "%d seconds%s", interval
/ 1000,
705 if (rtadv
->AdvDefaultLifetime
!= -1)
706 vty_out (vty
, " ND router advertisements live for %d seconds%s",
707 rtadv
->AdvDefaultLifetime
, VTY_NEWLINE
);
709 vty_out (vty
, " ND router advertisements lifetime tracks ra-interval%s",
711 vty_out (vty
, " ND router advertisement default router preference is "
712 "%s%s", rtadv_pref_strs
[rtadv
->DefaultPreference
],
714 if (rtadv
->AdvManagedFlag
)
715 vty_out (vty
, " Hosts use DHCP to obtain routable addresses.%s",
718 vty_out (vty
, " Hosts use stateless autoconfig for addresses.%s",
720 if (rtadv
->AdvHomeAgentFlag
)
722 vty_out (vty
, " ND router advertisements with "
723 "Home Agent flag bit set.%s",
725 if (rtadv
->HomeAgentLifetime
!= -1)
726 vty_out (vty
, " Home Agent lifetime is %u seconds%s",
727 rtadv
->HomeAgentLifetime
, VTY_NEWLINE
);
729 vty_out (vty
, " Home Agent lifetime tracks ra-lifetime%s",
731 vty_out (vty
, " Home Agent preference is %u%s",
732 rtadv
->HomeAgentPreference
, VTY_NEWLINE
);
734 if (rtadv
->AdvIntervalOption
)
735 vty_out (vty
, " ND router advertisements with Adv. Interval option.%s",
741 /* Interface's information print out to vty interface. */
743 if_dump_vty (struct vty
*vty
, struct interface
*ifp
)
745 #ifdef HAVE_STRUCT_SOCKADDR_DL
746 struct sockaddr_dl
*sdl
;
747 #endif /* HAVE_STRUCT_SOCKADDR_DL */
748 struct connected
*connected
;
749 struct nbr_connected
*nbr_connected
;
750 struct listnode
*node
;
751 struct route_node
*rn
;
752 struct zebra_if
*zebra_if
;
754 zebra_if
= ifp
->info
;
756 vty_out (vty
, "Interface %s is ", ifp
->name
);
758 vty_out (vty
, "up, line protocol ");
760 if (CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_LINKDETECTION
)) {
761 if (if_is_running(ifp
))
762 vty_out (vty
, "is up%s", VTY_NEWLINE
);
764 vty_out (vty
, "is down%s", VTY_NEWLINE
);
766 vty_out (vty
, "detection is disabled%s", VTY_NEWLINE
);
769 vty_out (vty
, "down%s", VTY_NEWLINE
);
772 vty_out (vty
, " PTM status: ");
773 if (ifp
->ptm_enable
) {
774 if (ifp
->ptm_status
) {
775 vty_out (vty
, "pass%s", VTY_NEWLINE
);
777 vty_out (vty
, "fail%s", VTY_NEWLINE
);
780 vty_out (vty
, "disabled%s", VTY_NEWLINE
);
784 vty_out (vty
, " Description: %s%s", ifp
->desc
,
786 if (ifp
->ifindex
== IFINDEX_INTERNAL
)
788 vty_out(vty
, " pseudo interface%s", VTY_NEWLINE
);
791 else if (! CHECK_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
))
793 vty_out(vty
, " index %d inactive interface%s",
799 vty_out (vty
, " index %d metric %d mtu %d ",
800 ifp
->ifindex
, ifp
->metric
, ifp
->mtu
);
802 if (ifp
->mtu6
!= ifp
->mtu
)
803 vty_out (vty
, "mtu6 %d ", ifp
->mtu6
);
805 vty_out (vty
, "%s flags: %s%s", VTY_NEWLINE
,
806 if_flag_dump (ifp
->flags
), VTY_NEWLINE
);
808 /* Hardware address. */
809 #ifdef HAVE_STRUCT_SOCKADDR_DL
811 if (sdl
!= NULL
&& sdl
->sdl_alen
!= 0)
816 vty_out (vty
, " HWaddr: ");
817 for (i
= 0, ptr
= (u_char
*)LLADDR (sdl
); i
< sdl
->sdl_alen
; i
++, ptr
++)
818 vty_out (vty
, "%s%02x", i
== 0 ? "" : ":", *ptr
);
819 vty_out (vty
, "%s", VTY_NEWLINE
);
822 if (ifp
->hw_addr_len
!= 0)
826 vty_out (vty
, " HWaddr: ");
827 for (i
= 0; i
< ifp
->hw_addr_len
; i
++)
828 vty_out (vty
, "%s%02x", i
== 0 ? "" : ":", ifp
->hw_addr
[i
]);
829 vty_out (vty
, "%s", VTY_NEWLINE
);
831 #endif /* HAVE_STRUCT_SOCKADDR_DL */
833 /* Bandwidth in kbps */
834 if (ifp
->bandwidth
!= 0)
836 vty_out(vty
, " bandwidth %u kbps", ifp
->bandwidth
);
837 vty_out(vty
, "%s", VTY_NEWLINE
);
840 for (rn
= route_top (zebra_if
->ipv4_subnets
); rn
; rn
= route_next (rn
))
845 for (ALL_LIST_ELEMENTS_RO ((struct list
*)rn
->info
, node
, connected
))
846 connected_dump_vty (vty
, connected
);
849 for (ALL_LIST_ELEMENTS_RO (ifp
->connected
, node
, connected
))
851 if (CHECK_FLAG (connected
->conf
, ZEBRA_IFC_REAL
) &&
852 (connected
->address
->family
== AF_INET6
))
853 connected_dump_vty (vty
, connected
);
857 nd_dump_vty (vty
, ifp
);
859 if (listhead(ifp
->nbr_connected
))
860 vty_out (vty
, " Neighbor address(s):%s", VTY_NEWLINE
);
861 for (ALL_LIST_ELEMENTS_RO (ifp
->nbr_connected
, node
, nbr_connected
))
862 nbr_connected_dump_vty (vty
, nbr_connected
);
864 #ifdef HAVE_PROC_NET_DEV
865 /* Statistics print out using proc file system. */
866 vty_out (vty
, " %lu input packets (%lu multicast), %lu bytes, "
868 ifp
->stats
.rx_packets
, ifp
->stats
.rx_multicast
,
869 ifp
->stats
.rx_bytes
, ifp
->stats
.rx_dropped
, VTY_NEWLINE
);
871 vty_out (vty
, " %lu input errors, %lu length, %lu overrun,"
872 " %lu CRC, %lu frame%s",
873 ifp
->stats
.rx_errors
, ifp
->stats
.rx_length_errors
,
874 ifp
->stats
.rx_over_errors
, ifp
->stats
.rx_crc_errors
,
875 ifp
->stats
.rx_frame_errors
, VTY_NEWLINE
);
877 vty_out (vty
, " %lu fifo, %lu missed%s", ifp
->stats
.rx_fifo_errors
,
878 ifp
->stats
.rx_missed_errors
, VTY_NEWLINE
);
880 vty_out (vty
, " %lu output packets, %lu bytes, %lu dropped%s",
881 ifp
->stats
.tx_packets
, ifp
->stats
.tx_bytes
,
882 ifp
->stats
.tx_dropped
, VTY_NEWLINE
);
884 vty_out (vty
, " %lu output errors, %lu aborted, %lu carrier,"
885 " %lu fifo, %lu heartbeat%s",
886 ifp
->stats
.tx_errors
, ifp
->stats
.tx_aborted_errors
,
887 ifp
->stats
.tx_carrier_errors
, ifp
->stats
.tx_fifo_errors
,
888 ifp
->stats
.tx_heartbeat_errors
, VTY_NEWLINE
);
890 vty_out (vty
, " %lu window, %lu collisions%s",
891 ifp
->stats
.tx_window_errors
, ifp
->stats
.collisions
, VTY_NEWLINE
);
892 #endif /* HAVE_PROC_NET_DEV */
894 #ifdef HAVE_NET_RT_IFLIST
895 #if defined (__bsdi__) || defined (__NetBSD__)
896 /* Statistics print out using sysctl (). */
897 vty_out (vty
, " input packets %qu, bytes %qu, dropped %qu,"
898 " multicast packets %qu%s",
899 ifp
->stats
.ifi_ipackets
, ifp
->stats
.ifi_ibytes
,
900 ifp
->stats
.ifi_iqdrops
, ifp
->stats
.ifi_imcasts
,
903 vty_out (vty
, " input errors %qu%s",
904 ifp
->stats
.ifi_ierrors
, VTY_NEWLINE
);
906 vty_out (vty
, " output packets %qu, bytes %qu, multicast packets %qu%s",
907 ifp
->stats
.ifi_opackets
, ifp
->stats
.ifi_obytes
,
908 ifp
->stats
.ifi_omcasts
, VTY_NEWLINE
);
910 vty_out (vty
, " output errors %qu%s",
911 ifp
->stats
.ifi_oerrors
, VTY_NEWLINE
);
913 vty_out (vty
, " collisions %qu%s",
914 ifp
->stats
.ifi_collisions
, VTY_NEWLINE
);
916 /* Statistics print out using sysctl (). */
917 vty_out (vty
, " input packets %lu, bytes %lu, dropped %lu,"
918 " multicast packets %lu%s",
919 ifp
->stats
.ifi_ipackets
, ifp
->stats
.ifi_ibytes
,
920 ifp
->stats
.ifi_iqdrops
, ifp
->stats
.ifi_imcasts
,
923 vty_out (vty
, " input errors %lu%s",
924 ifp
->stats
.ifi_ierrors
, VTY_NEWLINE
);
926 vty_out (vty
, " output packets %lu, bytes %lu, multicast packets %lu%s",
927 ifp
->stats
.ifi_opackets
, ifp
->stats
.ifi_obytes
,
928 ifp
->stats
.ifi_omcasts
, VTY_NEWLINE
);
930 vty_out (vty
, " output errors %lu%s",
931 ifp
->stats
.ifi_oerrors
, VTY_NEWLINE
);
933 vty_out (vty
, " collisions %lu%s",
934 ifp
->stats
.ifi_collisions
, VTY_NEWLINE
);
935 #endif /* __bsdi__ || __NetBSD__ */
936 #endif /* HAVE_NET_RT_IFLIST */
939 /* Wrapper hook point for zebra daemon so that ifindex can be set
940 * DEFUN macro not used as extract.pl HAS to ignore this
941 * See also interface_cmd in lib/if.c
943 DEFUN_NOSH (zebra_interface
,
946 "Select an interface to configure\n"
947 "Interface's name\n")
950 struct interface
* ifp
;
952 /* Call lib interface() */
953 if ((ret
= interface_cmd
.func (self
, vty
, argc
, argv
)) != CMD_SUCCESS
)
958 if (ifp
->ifindex
== IFINDEX_INTERNAL
)
959 /* Is this really necessary? Shouldn't status be initialized to 0
961 UNSET_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
);
966 struct cmd_node interface_node
=
973 /* Show all or specified interface to vty. */
974 DEFUN (show_interface
, show_interface_cmd
,
975 "show interface [IFNAME]",
977 "Interface status and configuration\n"
980 struct listnode
*node
;
981 struct interface
*ifp
;
983 #ifdef HAVE_PROC_NET_DEV
984 /* If system has interface statistics via proc file system, update
986 ifstat_update_proc ();
987 #endif /* HAVE_PROC_NET_DEV */
988 #ifdef HAVE_NET_RT_IFLIST
989 ifstat_update_sysctl ();
990 #endif /* HAVE_NET_RT_IFLIST */
992 /* Specified interface print. */
995 ifp
= if_lookup_by_name (argv
[0]);
998 vty_out (vty
, "%% Can't find interface %s%s", argv
[0],
1002 if_dump_vty (vty
, ifp
);
1006 /* All interface print. */
1007 for (ALL_LIST_ELEMENTS_RO (iflist
, node
, ifp
))
1008 if_dump_vty (vty
, ifp
);
1013 DEFUN (show_interface_desc
,
1014 show_interface_desc_cmd
,
1015 "show interface description",
1017 "Interface status and configuration\n"
1018 "Interface description\n")
1020 struct listnode
*node
;
1021 struct interface
*ifp
;
1023 vty_out (vty
, "Interface Status Protocol Description%s", VTY_NEWLINE
);
1024 for (ALL_LIST_ELEMENTS_RO (iflist
, node
, ifp
))
1028 len
= vty_out (vty
, "%s", ifp
->name
);
1029 vty_out (vty
, "%*s", (16 - len
), " ");
1033 vty_out (vty
, "up ");
1034 if (CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_LINKDETECTION
))
1036 if (if_is_running(ifp
))
1037 vty_out (vty
, "up ");
1039 vty_out (vty
, "down ");
1043 vty_out (vty
, "unknown ");
1048 vty_out (vty
, "down down ");
1052 vty_out (vty
, "%s", ifp
->desc
);
1053 vty_out (vty
, "%s", VTY_NEWLINE
);
1061 "Set multicast flag to interface\n")
1064 struct interface
*ifp
;
1065 struct zebra_if
*if_data
;
1067 ifp
= (struct interface
*) vty
->index
;
1068 if (CHECK_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
))
1070 ret
= if_set_flags (ifp
, IFF_MULTICAST
);
1073 vty_out (vty
, "Can't set multicast flag%s", VTY_NEWLINE
);
1078 if_data
= ifp
->info
;
1079 if_data
->multicast
= IF_ZEBRA_MULTICAST_ON
;
1084 DEFUN (no_multicast
,
1088 "Unset multicast flag to interface\n")
1091 struct interface
*ifp
;
1092 struct zebra_if
*if_data
;
1094 ifp
= (struct interface
*) vty
->index
;
1095 if (CHECK_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
))
1097 ret
= if_unset_flags (ifp
, IFF_MULTICAST
);
1100 vty_out (vty
, "Can't unset multicast flag%s", VTY_NEWLINE
);
1105 if_data
= ifp
->info
;
1106 if_data
->multicast
= IF_ZEBRA_MULTICAST_OFF
;
1114 "Enable link detection on interface\n")
1116 struct interface
*ifp
;
1117 int if_was_operative
;
1119 ifp
= (struct interface
*) vty
->index
;
1120 if_was_operative
= if_is_no_ptm_operative(ifp
);
1121 SET_FLAG(ifp
->status
, ZEBRA_INTERFACE_LINKDETECTION
);
1123 /* When linkdetection is enabled, if might come down */
1124 if (!if_is_no_ptm_operative(ifp
) && if_was_operative
) if_down(ifp
);
1126 /* FIXME: Will defer status change forwarding if interface
1127 does not come down! */
1133 DEFUN (no_linkdetect
,
1137 "Disable link detection on interface\n")
1139 struct interface
*ifp
;
1140 int if_was_operative
;
1142 ifp
= (struct interface
*) vty
->index
;
1143 if_was_operative
= if_is_no_ptm_operative(ifp
);
1144 UNSET_FLAG(ifp
->status
, ZEBRA_INTERFACE_LINKDETECTION
);
1146 /* Interface may come up after disabling link detection */
1147 if (if_is_operative(ifp
) && !if_was_operative
) if_up(ifp
);
1149 /* FIXME: see linkdetect_cmd */
1157 "Shutdown the selected interface\n")
1160 struct interface
*ifp
;
1161 struct zebra_if
*if_data
;
1163 ifp
= (struct interface
*) vty
->index
;
1164 if (ifp
->ifindex
!= IFINDEX_INTERNAL
)
1166 ret
= if_unset_flags (ifp
, IFF_UP
);
1169 vty_out (vty
, "Can't shutdown interface%s", VTY_NEWLINE
);
1174 if_data
= ifp
->info
;
1175 if_data
->shutdown
= IF_ZEBRA_SHUTDOWN_ON
;
1180 DEFUN (no_shutdown_if
,
1184 "Shutdown the selected interface\n")
1187 struct interface
*ifp
;
1188 struct zebra_if
*if_data
;
1190 ifp
= (struct interface
*) vty
->index
;
1192 if (ifp
->ifindex
!= IFINDEX_INTERNAL
)
1194 ret
= if_set_flags (ifp
, IFF_UP
| IFF_RUNNING
);
1197 vty_out (vty
, "Can't up interface%s", VTY_NEWLINE
);
1202 /* Some addresses (in particular, IPv6 addresses on Linux) get
1203 * removed when the interface goes down. They need to be readded.
1205 if_addr_wakeup(ifp
);
1208 if_data
= ifp
->info
;
1209 if_data
->shutdown
= IF_ZEBRA_SHUTDOWN_OFF
;
1214 DEFUN (bandwidth_if
,
1216 "bandwidth <1-10000000>",
1217 "Set bandwidth informational parameter\n"
1218 "Bandwidth in kilobits\n")
1220 struct interface
*ifp
;
1221 unsigned int bandwidth
;
1223 ifp
= (struct interface
*) vty
->index
;
1224 bandwidth
= strtol(argv
[0], NULL
, 10);
1226 /* bandwidth range is <1-10000000> */
1227 if (bandwidth
< 1 || bandwidth
> 10000000)
1229 vty_out (vty
, "Bandwidth is invalid%s", VTY_NEWLINE
);
1233 ifp
->bandwidth
= bandwidth
;
1235 /* force protocols to recalculate routes due to cost change */
1236 if (if_is_operative (ifp
))
1237 zebra_interface_up_update (ifp
);
1242 DEFUN (no_bandwidth_if
,
1243 no_bandwidth_if_cmd
,
1246 "Set bandwidth informational parameter\n")
1248 struct interface
*ifp
;
1250 ifp
= (struct interface
*) vty
->index
;
1254 /* force protocols to recalculate routes due to cost change */
1255 if (if_is_operative (ifp
))
1256 zebra_interface_up_update (ifp
);
1261 ALIAS (no_bandwidth_if
,
1262 no_bandwidth_if_val_cmd
,
1263 "no bandwidth <1-10000000>",
1265 "Set bandwidth informational parameter\n"
1266 "Bandwidth in kilobits\n")
1269 ip_address_install (struct vty
*vty
, struct interface
*ifp
,
1270 const char *addr_str
, const char *peer_str
,
1273 struct zebra_if
*if_data
;
1274 struct prefix_ipv4 cp
;
1275 struct connected
*ifc
;
1276 struct prefix_ipv4
*p
;
1279 if_data
= ifp
->info
;
1281 ret
= str2prefix_ipv4 (addr_str
, &cp
);
1284 vty_out (vty
, "%% Malformed address %s", VTY_NEWLINE
);
1288 ifc
= connected_check (ifp
, (struct prefix
*) &cp
);
1291 ifc
= connected_new ();
1295 p
= prefix_ipv4_new ();
1297 ifc
->address
= (struct prefix
*) p
;
1300 if (p
->prefixlen
<= IPV4_MAX_PREFIXLEN
-2)
1302 p
= prefix_ipv4_new ();
1304 p
->prefix
.s_addr
= ipv4_broadcast_addr(p
->prefix
.s_addr
,p
->prefixlen
);
1305 ifc
->destination
= (struct prefix
*) p
;
1310 ifc
->label
= XSTRDUP (MTYPE_CONNECTED_LABEL
, label
);
1312 /* Add to linked list. */
1313 listnode_add (ifp
->connected
, ifc
);
1316 /* This address is configured from zebra. */
1317 if (! CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
1318 SET_FLAG (ifc
->conf
, ZEBRA_IFC_CONFIGURED
);
1320 /* In case of this route need to install kernel. */
1321 if (! CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_QUEUED
)
1322 && CHECK_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
)
1323 && !(if_data
&& if_data
->shutdown
== IF_ZEBRA_SHUTDOWN_ON
))
1325 /* Some system need to up the interface to set IP address. */
1326 if (! if_is_up (ifp
))
1328 if_set_flags (ifp
, IFF_UP
| IFF_RUNNING
);
1332 ret
= if_set_prefix (ifp
, ifc
);
1335 vty_out (vty
, "%% Can't set interface IP address: %s.%s",
1336 safe_strerror(errno
), VTY_NEWLINE
);
1340 SET_FLAG (ifc
->conf
, ZEBRA_IFC_QUEUED
);
1341 /* The address will be advertised to zebra clients when the notification
1342 * from the kernel has been received.
1343 * It will also be added to the subnet chain list, then. */
1350 ip_address_uninstall (struct vty
*vty
, struct interface
*ifp
,
1351 const char *addr_str
, const char *peer_str
,
1354 struct prefix_ipv4 cp
;
1355 struct connected
*ifc
;
1358 /* Convert to prefix structure. */
1359 ret
= str2prefix_ipv4 (addr_str
, &cp
);
1362 vty_out (vty
, "%% Malformed address %s", VTY_NEWLINE
);
1366 /* Check current interface address. */
1367 ifc
= connected_check (ifp
, (struct prefix
*) &cp
);
1370 vty_out (vty
, "%% Can't find address%s", VTY_NEWLINE
);
1374 /* This is not configured address. */
1375 if (! CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
1378 UNSET_FLAG (ifc
->conf
, ZEBRA_IFC_CONFIGURED
);
1380 /* This is not real address or interface is not active. */
1381 if (! CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_QUEUED
)
1382 || ! CHECK_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
))
1384 listnode_delete (ifp
->connected
, ifc
);
1385 connected_free (ifc
);
1389 /* This is real route. */
1390 ret
= if_unset_prefix (ifp
, ifc
);
1393 vty_out (vty
, "%% Can't unset interface IP address: %s.%s",
1394 safe_strerror(errno
), VTY_NEWLINE
);
1397 UNSET_FLAG (ifc
->conf
, ZEBRA_IFC_QUEUED
);
1398 /* we will receive a kernel notification about this route being removed.
1399 * this will trigger its removal from the connected list. */
1405 "ip address A.B.C.D/M",
1406 "Interface Internet Protocol config commands\n"
1407 "Set the IP address of an interface\n"
1408 "IP address (e.g. 10.0.0.1/8)\n")
1410 return ip_address_install (vty
, vty
->index
, argv
[0], NULL
, NULL
);
1413 DEFUN (no_ip_address
,
1415 "no ip address A.B.C.D/M",
1417 "Interface Internet Protocol config commands\n"
1418 "Set the IP address of an interface\n"
1419 "IP Address (e.g. 10.0.0.1/8)")
1421 return ip_address_uninstall (vty
, vty
->index
, argv
[0], NULL
, NULL
);
1425 DEFUN (ip_address_label
,
1426 ip_address_label_cmd
,
1427 "ip address A.B.C.D/M label LINE",
1428 "Interface Internet Protocol config commands\n"
1429 "Set the IP address of an interface\n"
1430 "IP address (e.g. 10.0.0.1/8)\n"
1431 "Label of this address\n"
1434 return ip_address_install (vty
, vty
->index
, argv
[0], NULL
, argv
[1]);
1437 DEFUN (no_ip_address_label
,
1438 no_ip_address_label_cmd
,
1439 "no ip address A.B.C.D/M label LINE",
1441 "Interface Internet Protocol config commands\n"
1442 "Set the IP address of an interface\n"
1443 "IP address (e.g. 10.0.0.1/8)\n"
1444 "Label of this address\n"
1447 return ip_address_uninstall (vty
, vty
->index
, argv
[0], NULL
, argv
[1]);
1449 #endif /* HAVE_NETLINK */
1453 ipv6_address_install (struct vty
*vty
, struct interface
*ifp
,
1454 const char *addr_str
, const char *peer_str
,
1455 const char *label
, int secondary
)
1457 struct zebra_if
*if_data
;
1458 struct prefix_ipv6 cp
;
1459 struct connected
*ifc
;
1460 struct prefix_ipv6
*p
;
1463 if_data
= ifp
->info
;
1465 ret
= str2prefix_ipv6 (addr_str
, &cp
);
1468 vty_out (vty
, "%% Malformed address %s", VTY_NEWLINE
);
1472 ifc
= connected_check (ifp
, (struct prefix
*) &cp
);
1475 ifc
= connected_new ();
1479 p
= prefix_ipv6_new ();
1481 ifc
->address
= (struct prefix
*) p
;
1485 SET_FLAG (ifc
->flags
, ZEBRA_IFA_SECONDARY
);
1489 ifc
->label
= XSTRDUP (MTYPE_CONNECTED_LABEL
, label
);
1491 /* Add to linked list. */
1492 listnode_add (ifp
->connected
, ifc
);
1495 /* This address is configured from zebra. */
1496 if (! CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
1497 SET_FLAG (ifc
->conf
, ZEBRA_IFC_CONFIGURED
);
1499 /* In case of this route need to install kernel. */
1500 if (! CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_QUEUED
)
1501 && CHECK_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
)
1502 && !(if_data
&& if_data
->shutdown
== IF_ZEBRA_SHUTDOWN_ON
))
1504 /* Some system need to up the interface to set IP address. */
1505 if (! if_is_up (ifp
))
1507 if_set_flags (ifp
, IFF_UP
| IFF_RUNNING
);
1511 ret
= if_prefix_add_ipv6 (ifp
, ifc
);
1515 vty_out (vty
, "%% Can't set interface IP address: %s.%s",
1516 safe_strerror(errno
), VTY_NEWLINE
);
1520 SET_FLAG (ifc
->conf
, ZEBRA_IFC_QUEUED
);
1521 /* The address will be advertised to zebra clients when the notification
1522 * from the kernel has been received. */
1529 ipv6_address_uninstall (struct vty
*vty
, struct interface
*ifp
,
1530 const char *addr_str
, const char *peer_str
,
1531 const char *label
, int secondry
)
1533 struct prefix_ipv6 cp
;
1534 struct connected
*ifc
;
1537 /* Convert to prefix structure. */
1538 ret
= str2prefix_ipv6 (addr_str
, &cp
);
1541 vty_out (vty
, "%% Malformed address %s", VTY_NEWLINE
);
1545 /* Check current interface address. */
1546 ifc
= connected_check (ifp
, (struct prefix
*) &cp
);
1549 vty_out (vty
, "%% Can't find address%s", VTY_NEWLINE
);
1553 /* This is not configured address. */
1554 if (! CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
1557 UNSET_FLAG (ifc
->conf
, ZEBRA_IFC_CONFIGURED
);
1559 /* This is not real address or interface is not active. */
1560 if (! CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_QUEUED
)
1561 || ! CHECK_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
))
1563 listnode_delete (ifp
->connected
, ifc
);
1564 connected_free (ifc
);
1568 /* This is real route. */
1569 ret
= if_prefix_delete_ipv6 (ifp
, ifc
);
1572 vty_out (vty
, "%% Can't unset interface IP address: %s.%s",
1573 safe_strerror(errno
), VTY_NEWLINE
);
1577 UNSET_FLAG (ifc
->conf
, ZEBRA_IFC_QUEUED
);
1578 /* This information will be propagated to the zclients when the
1579 * kernel notification is received. */
1583 DEFUN (ipv6_address
,
1585 "ipv6 address X:X::X:X/M",
1586 "Interface IPv6 config commands\n"
1587 "Set the IP address of an interface\n"
1588 "IPv6 address (e.g. 3ffe:506::1/48)\n")
1590 return ipv6_address_install (vty
, vty
->index
, argv
[0], NULL
, NULL
, 0);
1593 DEFUN (no_ipv6_address
,
1594 no_ipv6_address_cmd
,
1595 "no ipv6 address X:X::X:X/M",
1597 "Interface IPv6 config commands\n"
1598 "Set the IP address of an interface\n"
1599 "IPv6 address (e.g. 3ffe:506::1/48)\n")
1601 return ipv6_address_uninstall (vty
, vty
->index
, argv
[0], NULL
, NULL
, 0);
1603 #endif /* HAVE_IPV6 */
1606 if_config_write (struct vty
*vty
)
1608 struct listnode
*node
;
1609 struct interface
*ifp
;
1611 zebra_ptm_write (vty
);
1613 for (ALL_LIST_ELEMENTS_RO (iflist
, node
, ifp
))
1615 struct zebra_if
*if_data
;
1616 struct listnode
*addrnode
;
1617 struct connected
*ifc
;
1620 if_data
= ifp
->info
;
1622 vty_out (vty
, "interface %s%s", ifp
->name
,
1627 if (if_data
->shutdown
== IF_ZEBRA_SHUTDOWN_ON
)
1628 vty_out (vty
, " shutdown%s", VTY_NEWLINE
);
1632 vty_out (vty
, " description %s%s", ifp
->desc
,
1635 /* Assign bandwidth here to avoid unnecessary interface flap
1636 while processing config script */
1637 if (ifp
->bandwidth
!= 0)
1638 vty_out(vty
, " bandwidth %u%s", ifp
->bandwidth
, VTY_NEWLINE
);
1640 if (CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_LINKDETECTION
))
1641 vty_out(vty
, " link-detect%s", VTY_NEWLINE
);
1643 for (ALL_LIST_ELEMENTS_RO (ifp
->connected
, addrnode
, ifc
))
1645 if (CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
1647 char buf
[INET6_ADDRSTRLEN
];
1649 vty_out (vty
, " ip%s address %s/%d",
1650 p
->family
== AF_INET
? "" : "v6",
1651 inet_ntop (p
->family
, &p
->u
.prefix
, buf
, sizeof(buf
)),
1655 vty_out (vty
, " label %s", ifc
->label
);
1657 vty_out (vty
, "%s", VTY_NEWLINE
);
1663 if (if_data
->multicast
!= IF_ZEBRA_MULTICAST_UNSPEC
)
1664 vty_out (vty
, " %smulticast%s",
1665 if_data
->multicast
== IF_ZEBRA_MULTICAST_ON
? "" : "no ",
1670 rtadv_config_write (vty
, ifp
);
1674 irdp_config_write (vty
, ifp
);
1677 vty_out (vty
, "!%s", VTY_NEWLINE
);
1682 /* Allocate and initialize interface vector. */
1684 zebra_if_init (void)
1686 /* Initialize interface and new hook. */
1688 if_add_hook (IF_NEW_HOOK
, if_zebra_new_hook
);
1689 if_add_hook (IF_DELETE_HOOK
, if_zebra_delete_hook
);
1691 /* Install configuration write function. */
1692 install_node (&interface_node
, if_config_write
);
1694 install_element (VIEW_NODE
, &show_interface_cmd
);
1695 install_element (ENABLE_NODE
, &show_interface_cmd
);
1696 install_element (ENABLE_NODE
, &show_interface_desc_cmd
);
1697 install_element (CONFIG_NODE
, &zebra_interface_cmd
);
1698 install_element (CONFIG_NODE
, &no_interface_cmd
);
1699 install_default (INTERFACE_NODE
);
1700 install_element (INTERFACE_NODE
, &interface_desc_cmd
);
1701 install_element (INTERFACE_NODE
, &no_interface_desc_cmd
);
1702 install_element (INTERFACE_NODE
, &multicast_cmd
);
1703 install_element (INTERFACE_NODE
, &no_multicast_cmd
);
1704 install_element (INTERFACE_NODE
, &linkdetect_cmd
);
1705 install_element (INTERFACE_NODE
, &no_linkdetect_cmd
);
1706 install_element (INTERFACE_NODE
, &shutdown_if_cmd
);
1707 install_element (INTERFACE_NODE
, &no_shutdown_if_cmd
);
1708 install_element (INTERFACE_NODE
, &bandwidth_if_cmd
);
1709 install_element (INTERFACE_NODE
, &no_bandwidth_if_cmd
);
1710 install_element (INTERFACE_NODE
, &no_bandwidth_if_val_cmd
);
1711 install_element (INTERFACE_NODE
, &ip_address_cmd
);
1712 install_element (INTERFACE_NODE
, &no_ip_address_cmd
);
1714 install_element (INTERFACE_NODE
, &ipv6_address_cmd
);
1715 install_element (INTERFACE_NODE
, &no_ipv6_address_cmd
);
1716 #endif /* HAVE_IPV6 */
1718 install_element (INTERFACE_NODE
, &ip_address_label_cmd
);
1719 install_element (INTERFACE_NODE
, &no_ip_address_label_cmd
);
1720 #endif /* HAVE_NETLINK */