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"
37 #include "zebra/interface.h"
38 #include "zebra/rtadv.h"
39 #include "zebra/rib.h"
40 #include "zebra/zserv.h"
41 #include "zebra/redistribute.h"
42 #include "zebra/debug.h"
43 #include "zebra/irdp.h"
44 #include "zebra/zebra_ptm.h"
45 #include "zebra/rt_netlink.h"
46 #include "zebra/zserv.h"
47 #include "zebra/interface.h"
49 #define ZEBRA_PTM_SUPPORT
51 #if defined (HAVE_RTADV)
52 /* Order is intentional. Matches RFC4191. This array is also used for
53 command matching, so only modify with care. */
54 const char *rtadv_pref_strs
[] = { "medium", "high", "INVALID", "low", 0 };
55 #endif /* HAVE_RTADV */
57 static void if_down_del_nbr_connected (struct interface
*ifp
);
59 struct zebra_ns
*dzns
;
61 /* Called when new interface is added. */
63 if_zebra_new_hook (struct interface
*ifp
)
65 struct zebra_if
*zebra_if
;
67 zebra_if
= XCALLOC (MTYPE_TMP
, sizeof (struct zebra_if
));
69 zebra_if
->multicast
= IF_ZEBRA_MULTICAST_UNSPEC
;
70 zebra_if
->shutdown
= IF_ZEBRA_SHUTDOWN_OFF
;
72 ifp
->ptm_enable
= zebra_ptm_get_enable_state();
73 #if defined (HAVE_RTADV)
75 /* Set default router advertise values. */
76 struct rtadvconf
*rtadv
;
78 rtadv
= &zebra_if
->rtadv
;
80 rtadv
->AdvSendAdvertisements
= 0;
81 rtadv
->MaxRtrAdvInterval
= RTADV_MAX_RTR_ADV_INTERVAL
;
82 rtadv
->MinRtrAdvInterval
= RTADV_MIN_RTR_ADV_INTERVAL
;
83 rtadv
->AdvIntervalTimer
= 0;
84 rtadv
->AdvManagedFlag
= 0;
85 rtadv
->AdvOtherConfigFlag
= 0;
86 rtadv
->AdvHomeAgentFlag
= 0;
87 rtadv
->AdvLinkMTU
= 0;
88 rtadv
->AdvReachableTime
= 0;
89 rtadv
->AdvRetransTimer
= 0;
90 rtadv
->AdvCurHopLimit
= 0;
91 rtadv
->AdvDefaultLifetime
= -1; /* derive from MaxRtrAdvInterval */
92 rtadv
->HomeAgentPreference
= 0;
93 rtadv
->HomeAgentLifetime
= -1; /* derive from AdvDefaultLifetime */
94 rtadv
->AdvIntervalOption
= 0;
95 rtadv
->DefaultPreference
= RTADV_PREF_MEDIUM
;
97 rtadv
->AdvPrefixList
= list_new ();
99 #endif /* HAVE_RTADV */
101 /* Initialize installed address chains tree. */
102 zebra_if
->ipv4_subnets
= route_table_init ();
104 ifp
->info
= zebra_if
;
108 /* Called when interface is deleted. */
110 if_zebra_delete_hook (struct interface
*ifp
)
112 struct zebra_if
*zebra_if
;
116 zebra_if
= ifp
->info
;
118 /* Free installed address chains tree. */
119 if (zebra_if
->ipv4_subnets
)
120 route_table_finish (zebra_if
->ipv4_subnets
);
122 XFREE (MTYPE_TMP
, zebra_if
);
128 /* Build the table key */
130 if_build_key (u_int32_t ifindex
, struct prefix
*p
)
133 p
->prefixlen
= IPV4_MAX_BITLEN
;
134 p
->u
.prefix4
.s_addr
= ifindex
;
137 /* Link an interface in a per NS interface tree */
139 if_link_per_ns (struct zebra_ns
*ns
, struct interface
*ifp
)
142 struct route_node
*rn
;
144 if (ifp
->ifindex
== IFINDEX_INTERNAL
)
147 if_build_key (ifp
->ifindex
, &p
);
148 rn
= route_node_get (ns
->if_table
, &p
);
151 ifp
= (struct interface
*)rn
->info
;
152 route_unlock_node (rn
); /* get */
162 /* Delete a VRF. This is called in vrf_terminate(). */
164 if_unlink_per_ns (struct interface
*ifp
)
166 ifp
->node
->info
= NULL
;
167 route_unlock_node(ifp
->node
);
170 /* Look up an interface by identifier within a NS */
172 if_lookup_by_index_per_ns (struct zebra_ns
*ns
, u_int32_t ifindex
)
175 struct route_node
*rn
;
176 struct interface
*ifp
= NULL
;
178 if_build_key (ifindex
, &p
);
179 rn
= route_node_lookup (ns
->if_table
, &p
);
182 ifp
= (struct interface
*)rn
->info
;
183 route_unlock_node (rn
); /* lookup */
189 ifindex2ifname_per_ns (struct zebra_ns
*zns
, unsigned int ifindex
)
191 struct interface
*ifp
;
193 return ((ifp
= if_lookup_by_index_per_ns (zns
, ifindex
)) != NULL
) ?
194 ifp
->name
: "unknown";
197 /* Tie an interface address to its derived subnet list of addresses. */
199 if_subnet_add (struct interface
*ifp
, struct connected
*ifc
)
201 struct route_node
*rn
;
202 struct zebra_if
*zebra_if
;
204 struct list
*addr_list
;
206 assert (ifp
&& ifp
->info
&& ifc
);
207 zebra_if
= ifp
->info
;
209 /* Get address derived subnet node and associated address list, while marking
210 address secondary attribute appropriately. */
213 rn
= route_node_get (zebra_if
->ipv4_subnets
, &cp
);
215 if ((addr_list
= rn
->info
))
216 SET_FLAG (ifc
->flags
, ZEBRA_IFA_SECONDARY
);
219 UNSET_FLAG (ifc
->flags
, ZEBRA_IFA_SECONDARY
);
220 rn
->info
= addr_list
= list_new ();
221 route_lock_node (rn
);
224 /* Tie address at the tail of address list. */
225 listnode_add (addr_list
, ifc
);
227 /* Return list element count. */
228 return (addr_list
->count
);
231 /* Untie an interface address from its derived subnet list of addresses. */
233 if_subnet_delete (struct interface
*ifp
, struct connected
*ifc
)
235 struct route_node
*rn
;
236 struct zebra_if
*zebra_if
;
237 struct list
*addr_list
;
239 assert (ifp
&& ifp
->info
&& ifc
);
240 zebra_if
= ifp
->info
;
242 /* Get address derived subnet node. */
243 rn
= route_node_lookup (zebra_if
->ipv4_subnets
, ifc
->address
);
244 if (! (rn
&& rn
->info
))
246 zlog_warn("Trying to remove an address from an unknown subnet."
247 " (please report this bug)");
250 route_unlock_node (rn
);
252 /* Untie address from subnet's address list. */
253 addr_list
= rn
->info
;
255 /* Deleting an address that is not registered is a bug.
256 * In any case, we shouldn't decrement the lock counter if the address
258 if (!listnode_lookup(addr_list
, ifc
))
260 zlog_warn("Trying to remove an address from a subnet where it is not"
261 " currently registered. (please report this bug)");
265 listnode_delete (addr_list
, ifc
);
266 route_unlock_node (rn
);
268 /* Return list element count, if not empty. */
269 if (addr_list
->count
)
271 /* If deleted address is primary, mark subsequent one as such and distribute. */
272 if (! CHECK_FLAG (ifc
->flags
, ZEBRA_IFA_SECONDARY
))
274 ifc
= listgetdata (listhead (addr_list
));
275 zebra_interface_address_delete_update (ifp
, ifc
);
276 UNSET_FLAG (ifc
->flags
, ZEBRA_IFA_SECONDARY
);
277 /* XXX: Linux kernel removes all the secondary addresses when the primary
278 * address is removed. We could try to work around that, though this is
280 zebra_interface_address_add_update (ifp
, ifc
);
283 return addr_list
->count
;
286 /* Otherwise, free list and route node. */
287 list_free (addr_list
);
289 route_unlock_node (rn
);
294 /* if_flags_mangle: A place for hacks that require mangling
295 * or tweaking the interface flags.
297 * ******************** Solaris flags hacks **************************
299 * Solaris IFF_UP flag reflects only the primary interface as the
300 * routing socket only sends IFINFO for the primary interface. Hence
301 * ~IFF_UP does not per se imply all the logical interfaces are also
302 * down - which we only know of as addresses. Instead we must determine
303 * whether the interface really is up or not according to how many
304 * addresses are still attached. (Solaris always sends RTM_DELADDR if
305 * an interface, logical or not, goes ~IFF_UP).
307 * Ie, we mangle IFF_UP to *additionally* reflect whether or not there
308 * are addresses left in struct connected, not just the actual underlying
311 * We must hence remember the real state of IFF_UP, which we do in
312 * struct zebra_if.primary_state.
314 * Setting IFF_UP within zebra to administratively shutdown the
315 * interface will affect only the primary interface/address on Solaris.
316 ************************End Solaris flags hacks ***********************
319 if_flags_mangle (struct interface
*ifp
, uint64_t *newflags
)
322 struct zebra_if
*zif
= ifp
->info
;
324 zif
->primary_state
= *newflags
& (IFF_UP
& 0xff);
326 if (CHECK_FLAG (zif
->primary_state
, IFF_UP
)
327 || listcount(ifp
->connected
) > 0)
328 SET_FLAG (*newflags
, IFF_UP
);
330 UNSET_FLAG (*newflags
, IFF_UP
);
334 /* Update the flags field of the ifp with the new flag set provided.
335 * Take whatever actions are required for any changes in flags we care
338 * newflags should be the raw value, as obtained from the OS.
341 if_flags_update (struct interface
*ifp
, uint64_t newflags
)
343 if_flags_mangle (ifp
, &newflags
);
345 if (if_is_no_ptm_operative (ifp
))
347 /* operative -> inoperative? */
348 ifp
->flags
= newflags
;
349 if (!if_is_operative (ifp
))
354 /* inoperative -> operative? */
355 ifp
->flags
= newflags
;
356 if (if_is_operative (ifp
))
361 /* Wake up configured address if it is not in current kernel
364 if_addr_wakeup (struct interface
*ifp
)
366 struct listnode
*node
, *nnode
;
367 struct connected
*ifc
;
371 for (ALL_LIST_ELEMENTS (ifp
->connected
, node
, nnode
, ifc
))
375 if (CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_CONFIGURED
)
376 && ! CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_QUEUED
))
379 if (p
->family
== AF_INET
)
381 if (! if_is_up (ifp
))
383 /* Assume zebra is configured like following:
386 * ip addr 192.0.2.1/24
389 * As soon as zebra becomes first aware that gre0 exists in the
390 * kernel, it will set gre0 up and configure its addresses.
392 * (This may happen at startup when the interface already exists
393 * or during runtime when the interface is added to the kernel)
395 * XXX: IRDP code is calling here via if_add_update - this seems
397 * XXX: RUNNING is not a settable flag on any system
398 * I (paulj) am aware of.
400 if_set_flags (ifp
, IFF_UP
| IFF_RUNNING
);
404 ret
= if_set_prefix (ifp
, ifc
);
407 zlog_warn ("Can't set interface's address: %s",
408 safe_strerror(errno
));
412 SET_FLAG (ifc
->conf
, ZEBRA_IFC_QUEUED
);
413 /* The address will be advertised to zebra clients when the notification
414 * from the kernel has been received.
415 * It will also be added to the interface's subnet list then. */
418 if (p
->family
== AF_INET6
)
420 if (! if_is_up (ifp
))
422 /* See long comment above */
423 if_set_flags (ifp
, IFF_UP
| IFF_RUNNING
);
427 ret
= if_prefix_add_ipv6 (ifp
, ifc
);
430 zlog_warn ("Can't set interface's address: %s",
431 safe_strerror(errno
));
435 SET_FLAG (ifc
->conf
, ZEBRA_IFC_QUEUED
);
436 /* The address will be advertised to zebra clients when the notification
437 * from the kernel has been received. */
439 #endif /* HAVE_IPV6 */
444 /* Handle interface addition */
446 if_add_update (struct interface
*ifp
)
448 struct zebra_if
*if_data
;
450 if_link_per_ns(dzns
, ifp
);
453 if (if_data
->multicast
== IF_ZEBRA_MULTICAST_ON
)
454 if_set_flags (ifp
, IFF_MULTICAST
);
455 else if (if_data
->multicast
== IF_ZEBRA_MULTICAST_OFF
)
456 if_unset_flags (ifp
, IFF_MULTICAST
);
458 zebra_interface_add_update (ifp
);
460 if (! CHECK_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
))
462 SET_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
);
464 if (if_data
&& if_data
->shutdown
== IF_ZEBRA_SHUTDOWN_ON
)
466 if (IS_ZEBRA_DEBUG_KERNEL
)
467 zlog_debug ("interface %s vrf %u index %d is shutdown. "
469 ifp
->name
, ifp
->vrf_id
, ifp
->ifindex
);
473 if_addr_wakeup (ifp
);
475 if (IS_ZEBRA_DEBUG_KERNEL
)
476 zlog_debug ("interface %s vrf %u index %d becomes active.",
477 ifp
->name
, ifp
->vrf_id
, ifp
->ifindex
);
481 if (IS_ZEBRA_DEBUG_KERNEL
)
482 zlog_debug ("interface %s vrf %u index %d is added.",
483 ifp
->name
, ifp
->vrf_id
, ifp
->ifindex
);
487 /* Install connected routes corresponding to an interface. */
489 if_install_connected (struct interface
*ifp
)
491 struct listnode
*node
;
492 struct listnode
*next
;
493 struct connected
*ifc
;
498 for (ALL_LIST_ELEMENTS (ifp
->connected
, node
, next
, ifc
))
502 if (p
->family
== AF_INET
)
503 connected_up_ipv4 (ifp
, ifc
);
504 else if (p
->family
== AF_INET6
)
505 connected_up_ipv6 (ifp
, ifc
);
510 /* Uninstall connected routes corresponding to an interface. */
512 if_uninstall_connected (struct interface
*ifp
)
514 struct listnode
*node
;
515 struct listnode
*next
;
516 struct connected
*ifc
;
521 for (ALL_LIST_ELEMENTS (ifp
->connected
, node
, next
, ifc
))
525 if (p
->family
== AF_INET
)
526 connected_down_ipv4 (ifp
, ifc
);
527 else if (p
->family
== AF_INET6
)
528 connected_down_ipv6 (ifp
, ifc
);
533 /* Uninstall and delete connected routes corresponding to an interface. */
534 /* TODO - Check why IPv4 handling here is different from install or if_down */
536 if_delete_connected (struct interface
*ifp
)
538 struct connected
*ifc
;
540 struct route_node
*rn
;
541 struct zebra_if
*zebra_if
;
543 zebra_if
= ifp
->info
;
547 struct listnode
*node
;
548 struct listnode
*last
= NULL
;
550 while ((node
= (last
? last
->next
: listhead (ifp
->connected
))))
552 ifc
= listgetdata (node
);
555 if (p
->family
== AF_INET
556 && (rn
= route_node_lookup (zebra_if
->ipv4_subnets
, p
)))
558 struct listnode
*anode
;
559 struct listnode
*next
;
560 struct listnode
*first
;
561 struct list
*addr_list
;
563 route_unlock_node (rn
);
564 addr_list
= (struct list
*) rn
->info
;
566 /* Remove addresses, secondaries first. */
567 first
= listhead (addr_list
);
568 for (anode
= first
->next
; anode
|| first
; anode
= next
)
577 ifc
= listgetdata (anode
);
579 connected_down_ipv4 (ifp
, ifc
);
581 /* XXX: We have to send notifications here explicitly, because we destroy
582 * the ifc before receiving the notification about the address being deleted.
584 zebra_interface_address_delete_update (ifp
, ifc
);
586 UNSET_FLAG (ifc
->conf
, ZEBRA_IFC_REAL
);
587 UNSET_FLAG (ifc
->conf
, ZEBRA_IFC_QUEUED
);
589 /* Remove from subnet chain. */
590 list_delete_node (addr_list
, anode
);
591 route_unlock_node (rn
);
593 /* Remove from interface address list (unconditionally). */
594 if (!CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
596 listnode_delete (ifp
->connected
, ifc
);
597 connected_free (ifc
);
603 /* Free chain list and respective route node. */
604 list_delete (addr_list
);
606 route_unlock_node (rn
);
608 else if (p
->family
== AF_INET6
)
610 connected_down_ipv6 (ifp
, ifc
);
612 zebra_interface_address_delete_update (ifp
, ifc
);
614 UNSET_FLAG (ifc
->conf
, ZEBRA_IFC_REAL
);
615 UNSET_FLAG (ifc
->conf
, ZEBRA_IFC_QUEUED
);
617 if (CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
621 listnode_delete (ifp
->connected
, ifc
);
622 connected_free (ifc
);
633 /* Handle an interface delete event */
635 if_delete_update (struct interface
*ifp
)
639 zlog_err ("interface %s vrf %u index %d is still up while being deleted.",
640 ifp
->name
, ifp
->vrf_id
, ifp
->ifindex
);
644 /* Mark interface as inactive */
645 UNSET_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
);
647 if (IS_ZEBRA_DEBUG_KERNEL
)
648 zlog_debug ("interface %s vrf %u index %d is now inactive.",
649 ifp
->name
, ifp
->vrf_id
, ifp
->ifindex
);
651 /* Delete connected routes from the kernel. */
652 if_delete_connected (ifp
);
654 /* Send out notification on interface delete. */
655 zebra_interface_delete_update (ifp
);
657 if_unlink_per_ns(ifp
);
659 /* Update ifindex after distributing the delete message. This is in
660 case any client needs to have the old value of ifindex available
661 while processing the deletion. Each client daemon is responsible
662 for setting ifindex to IFINDEX_INTERNAL after processing the
663 interface deletion message. */
664 ifp
->ifindex
= IFINDEX_INTERNAL
;
667 /* VRF change for an interface */
669 if_handle_vrf_change (struct interface
*ifp
, vrf_id_t vrf_id
)
673 old_vrf_id
= ifp
->vrf_id
;
675 /* Uninstall connected routes. */
676 if_uninstall_connected (ifp
);
678 /* Delete any IPv4 neighbors created to implement RFC 5549 */
679 if_nbr_ipv6ll_to_ipv4ll_neigh_del_all (ifp
);
681 /* Delete all neighbor addresses learnt through IPv6 RA */
682 if_down_del_nbr_connected (ifp
);
684 /* Suppress RAs on this interface, if enabled. */
685 ipv6_nd_suppress_ra_set (ifp
, RA_SUPPRESS
);
687 /* Send out notification on interface VRF change. */
688 /* This is to issue an UPDATE or a DELETE, as appropriate. */
689 zebra_interface_vrf_update_del (ifp
, vrf_id
);
692 if_update_vrf (ifp
, ifp
->name
, strlen (ifp
->name
), vrf_id
);
694 /* Send out notification on interface VRF change. */
695 /* This is to issue an ADD, if needed. */
696 zebra_interface_vrf_update_add (ifp
, old_vrf_id
);
698 /* Install connected routes (in new VRF). */
699 if_install_connected (ifp
);
701 /* Enable RAs on this interface, if IPv6 addresses are present. */
702 if (ipv6_address_configured(ifp
))
703 ipv6_nd_suppress_ra_set (ifp
, RA_ENABLE
);
705 /* Due to connected route change, schedule RIB processing for both old
708 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
709 zlog_debug ("%u: IF %s VRF change, scheduling RIB processing",
710 ifp
->vrf_id
, ifp
->name
);
711 rib_update (old_vrf_id
, RIB_UPDATE_IF_CHANGE
);
712 rib_update (ifp
->vrf_id
, RIB_UPDATE_IF_CHANGE
);
716 /* Handle VRF addition */
718 vrf_add_update (struct vrf
*vrfp
)
720 zebra_vrf_add_update (vrfp
);
722 if (! CHECK_FLAG (vrfp
->status
, ZEBRA_VRF_ACTIVE
))
724 SET_FLAG (vrfp
->status
, ZEBRA_VRF_ACTIVE
);
726 //Pending: Check if the equivalent of if_addr_wakeup (ifp) is needed here.
728 if (IS_ZEBRA_DEBUG_KERNEL
)
729 zlog_debug ("VRF %s id %u becomes active.",
730 vrfp
->name
, vrfp
->vrf_id
);
734 if (IS_ZEBRA_DEBUG_KERNEL
)
735 zlog_debug ("VRF %s id %u is added.",
736 vrfp
->name
, vrfp
->vrf_id
);
740 /* Handle an interface delete event */
742 vrf_delete_update (struct vrf
*vrfp
)
744 /* Mark VRF as inactive */
745 UNSET_FLAG (vrfp
->status
, ZEBRA_VRF_ACTIVE
);
747 if (IS_ZEBRA_DEBUG_KERNEL
)
748 zlog_debug ("VRF %s id %u is now inactive.",
749 vrfp
->name
, vrfp
->vrf_id
);
751 zebra_vrf_delete_update (vrfp
);
753 /* Pending: Update ifindex after distributing the delete message. This is in
754 case any client needs to have the old value of ifindex available
755 while processing the deletion. Each client daemon is responsible
756 for setting vrf-id to IFINDEX_INTERNAL after processing the
757 interface deletion message. */
763 ipv6_ll_address_to_mac (struct in6_addr
*address
, u_char
*mac
)
765 mac
[0] = address
->s6_addr
[8] ^ 0x02;
766 mac
[1] = address
->s6_addr
[9];
767 mac
[2] = address
->s6_addr
[10];
768 mac
[3] = address
->s6_addr
[13];
769 mac
[4] = address
->s6_addr
[14];
770 mac
[5] = address
->s6_addr
[15];
774 if_nbr_ipv6ll_to_ipv4ll_neigh_update (struct interface
*ifp
,
775 struct in6_addr
*address
,
778 char buf
[16] = "169.254.0.1";
779 struct in_addr ipv4_ll
;
782 inet_pton (AF_INET
, buf
, &ipv4_ll
);
784 ipv6_ll_address_to_mac(address
, (u_char
*)mac
);
785 netlink_neigh_update (add
? RTM_NEWNEIGH
: RTM_DELNEIGH
,
786 ifp
->ifindex
, ipv4_ll
.s_addr
, mac
, 6);
790 if_nbr_ipv6ll_to_ipv4ll_neigh_add_all (struct interface
*ifp
)
792 if (listhead(ifp
->nbr_connected
))
794 struct nbr_connected
*nbr_connected
;
795 struct listnode
*node
;
797 for (ALL_LIST_ELEMENTS_RO (ifp
->nbr_connected
, node
, nbr_connected
))
798 if_nbr_ipv6ll_to_ipv4ll_neigh_update (ifp
,
799 &nbr_connected
->address
->u
.prefix6
,
805 if_nbr_ipv6ll_to_ipv4ll_neigh_del_all (struct interface
*ifp
)
807 if (listhead(ifp
->nbr_connected
))
809 struct nbr_connected
*nbr_connected
;
810 struct listnode
*node
;
812 for (ALL_LIST_ELEMENTS_RO (ifp
->nbr_connected
, node
, nbr_connected
))
813 if_nbr_ipv6ll_to_ipv4ll_neigh_update (ifp
,
814 &nbr_connected
->address
->u
.prefix6
,
820 if_down_del_nbr_connected (struct interface
*ifp
)
822 struct nbr_connected
*nbr_connected
;
823 struct listnode
*node
, *nnode
;
825 for (ALL_LIST_ELEMENTS (ifp
->nbr_connected
, node
, nnode
, nbr_connected
))
827 listnode_delete (ifp
->nbr_connected
, nbr_connected
);
828 nbr_connected_free (nbr_connected
);
832 /* Interface is up. */
834 if_up (struct interface
*ifp
)
836 /* Notify the protocol daemons. */
837 if (ifp
->ptm_enable
&& (ifp
->ptm_status
== ZEBRA_PTM_STATUS_DOWN
)) {
838 zlog_warn("%s: interface %s hasn't passed ptm check\n", __func__
,
842 zebra_interface_up_update (ifp
);
844 if_nbr_ipv6ll_to_ipv4ll_neigh_add_all (ifp
);
846 /* Install connected routes to the kernel. */
847 if_install_connected (ifp
);
849 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
850 zlog_debug ("%u: IF %s up, scheduling RIB processing",
851 ifp
->vrf_id
, ifp
->name
);
852 rib_update (ifp
->vrf_id
, RIB_UPDATE_IF_CHANGE
);
855 /* Interface goes down. We have to manage different behavior of based
858 if_down (struct interface
*ifp
)
860 /* Notify to the protocol daemons. */
861 zebra_interface_down_update (ifp
);
863 /* Uninstall connected routes from the kernel. */
864 if_uninstall_connected (ifp
);
866 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
867 zlog_debug ("%u: IF %s down, scheduling RIB processing",
868 ifp
->vrf_id
, ifp
->name
);
869 rib_update (ifp
->vrf_id
, RIB_UPDATE_IF_CHANGE
);
871 if_nbr_ipv6ll_to_ipv4ll_neigh_del_all (ifp
);
873 /* Delete all neighbor addresses learnt through IPv6 RA */
874 if_down_del_nbr_connected (ifp
);
878 if_refresh (struct interface
*ifp
)
884 /* Output prefix string to vty. */
886 prefix_vty_out (struct vty
*vty
, struct prefix
*p
)
888 char str
[INET6_ADDRSTRLEN
];
890 inet_ntop (p
->family
, &p
->u
.prefix
, str
, sizeof (str
));
891 vty_out (vty
, "%s", str
);
895 /* Dump if address information to vty. */
897 connected_dump_vty (struct vty
*vty
, struct connected
*connected
)
901 /* Print interface address. */
902 p
= connected
->address
;
903 vty_out (vty
, " %s ", prefix_family_str (p
));
904 prefix_vty_out (vty
, p
);
905 vty_out (vty
, "/%d", p
->prefixlen
);
907 /* If there is destination address, print it. */
908 if (connected
->destination
)
910 vty_out (vty
, (CONNECTED_PEER(connected
) ? " peer " : " broadcast "));
911 prefix_vty_out (vty
, connected
->destination
);
914 if (CHECK_FLAG (connected
->flags
, ZEBRA_IFA_SECONDARY
))
915 vty_out (vty
, " secondary");
917 if (CHECK_FLAG (connected
->flags
, ZEBRA_IFA_UNNUMBERED
))
918 vty_out (vty
, " unnumbered");
920 if (connected
->label
)
921 vty_out (vty
, " %s", connected
->label
);
923 vty_out (vty
, "%s", VTY_NEWLINE
);
926 /* Dump interface neighbor address information to vty. */
928 nbr_connected_dump_vty (struct vty
*vty
, struct nbr_connected
*connected
)
932 /* Print interface address. */
933 p
= connected
->address
;
934 vty_out (vty
, " %s ", prefix_family_str (p
));
935 prefix_vty_out (vty
, p
);
936 vty_out (vty
, "/%d", p
->prefixlen
);
938 vty_out (vty
, "%s", VTY_NEWLINE
);
941 #if defined (HAVE_RTADV)
942 /* Dump interface ND information to vty. */
944 nd_dump_vty (struct vty
*vty
, struct interface
*ifp
)
946 struct zebra_if
*zif
;
947 struct rtadvconf
*rtadv
;
950 zif
= (struct zebra_if
*) ifp
->info
;
953 if (rtadv
->AdvSendAdvertisements
)
955 vty_out (vty
, " ND advertised reachable time is %d milliseconds%s",
956 rtadv
->AdvReachableTime
, VTY_NEWLINE
);
957 vty_out (vty
, " ND advertised retransmit interval is %d milliseconds%s",
958 rtadv
->AdvRetransTimer
, VTY_NEWLINE
);
959 interval
= rtadv
->MaxRtrAdvInterval
;
961 vty_out (vty
, " ND router advertisements are sent every "
962 "%d milliseconds%s", interval
,
965 vty_out (vty
, " ND router advertisements are sent every "
966 "%d seconds%s", interval
/ 1000,
968 if (rtadv
->AdvDefaultLifetime
!= -1)
969 vty_out (vty
, " ND router advertisements live for %d seconds%s",
970 rtadv
->AdvDefaultLifetime
, VTY_NEWLINE
);
972 vty_out (vty
, " ND router advertisements lifetime tracks ra-interval%s",
974 vty_out (vty
, " ND router advertisement default router preference is "
975 "%s%s", rtadv_pref_strs
[rtadv
->DefaultPreference
],
977 if (rtadv
->AdvManagedFlag
)
978 vty_out (vty
, " Hosts use DHCP to obtain routable addresses.%s",
981 vty_out (vty
, " Hosts use stateless autoconfig for addresses.%s",
983 if (rtadv
->AdvHomeAgentFlag
)
985 vty_out (vty
, " ND router advertisements with "
986 "Home Agent flag bit set.%s",
988 if (rtadv
->HomeAgentLifetime
!= -1)
989 vty_out (vty
, " Home Agent lifetime is %u seconds%s",
990 rtadv
->HomeAgentLifetime
, VTY_NEWLINE
);
992 vty_out (vty
, " Home Agent lifetime tracks ra-lifetime%s",
994 vty_out (vty
, " Home Agent preference is %u%s",
995 rtadv
->HomeAgentPreference
, VTY_NEWLINE
);
997 if (rtadv
->AdvIntervalOption
)
998 vty_out (vty
, " ND router advertisements with Adv. Interval option.%s",
1002 #endif /* HAVE_RTADV */
1004 /* Interface's information print out to vty interface. */
1006 if_dump_vty (struct vty
*vty
, struct interface
*ifp
)
1008 #ifdef HAVE_STRUCT_SOCKADDR_DL
1009 struct sockaddr_dl
*sdl
;
1010 #endif /* HAVE_STRUCT_SOCKADDR_DL */
1011 struct connected
*connected
;
1012 struct nbr_connected
*nbr_connected
;
1013 struct listnode
*node
;
1014 struct route_node
*rn
;
1015 struct zebra_if
*zebra_if
;
1018 zebra_if
= ifp
->info
;
1020 vty_out (vty
, "Interface %s is ", ifp
->name
);
1021 if (if_is_up(ifp
)) {
1022 vty_out (vty
, "up, line protocol ");
1024 if (CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_LINKDETECTION
)) {
1025 if (if_is_running(ifp
))
1026 vty_out (vty
, "is up%s", VTY_NEWLINE
);
1028 vty_out (vty
, "is down%s", VTY_NEWLINE
);
1030 vty_out (vty
, "detection is disabled%s", VTY_NEWLINE
);
1033 vty_out (vty
, "down%s", VTY_NEWLINE
);
1036 zebra_ptm_show_status(vty
, ifp
);
1038 vrf
= vrf_lookup(ifp
->vrf_id
);
1039 vty_out (vty
, " vrf: %s%s", vrf
->name
, VTY_NEWLINE
);
1042 vty_out (vty
, " Description: %s%s", ifp
->desc
,
1044 if (ifp
->ifindex
== IFINDEX_INTERNAL
)
1046 vty_out(vty
, " pseudo interface%s", VTY_NEWLINE
);
1049 else if (! CHECK_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
))
1051 vty_out(vty
, " index %d inactive interface%s",
1057 vty_out (vty
, " index %d metric %d mtu %d ",
1058 ifp
->ifindex
, ifp
->metric
, ifp
->mtu
);
1060 if (ifp
->mtu6
!= ifp
->mtu
)
1061 vty_out (vty
, "mtu6 %d ", ifp
->mtu6
);
1063 vty_out (vty
, "%s flags: %s%s", VTY_NEWLINE
,
1064 if_flag_dump (ifp
->flags
), VTY_NEWLINE
);
1066 /* Hardware address. */
1067 #ifdef HAVE_STRUCT_SOCKADDR_DL
1069 if (sdl
!= NULL
&& sdl
->sdl_alen
!= 0)
1074 vty_out (vty
, " HWaddr: ");
1075 for (i
= 0, ptr
= (u_char
*)LLADDR (sdl
); i
< sdl
->sdl_alen
; i
++, ptr
++)
1076 vty_out (vty
, "%s%02x", i
== 0 ? "" : ":", *ptr
);
1077 vty_out (vty
, "%s", VTY_NEWLINE
);
1080 if (ifp
->hw_addr_len
!= 0)
1084 vty_out (vty
, " HWaddr: ");
1085 for (i
= 0; i
< ifp
->hw_addr_len
; i
++)
1086 vty_out (vty
, "%s%02x", i
== 0 ? "" : ":", ifp
->hw_addr
[i
]);
1087 vty_out (vty
, "%s", VTY_NEWLINE
);
1089 #endif /* HAVE_STRUCT_SOCKADDR_DL */
1091 /* Bandwidth in kbps */
1092 if (ifp
->bandwidth
!= 0)
1094 vty_out(vty
, " bandwidth %u kbps", ifp
->bandwidth
);
1095 vty_out(vty
, "%s", VTY_NEWLINE
);
1098 for (rn
= route_top (zebra_if
->ipv4_subnets
); rn
; rn
= route_next (rn
))
1103 for (ALL_LIST_ELEMENTS_RO ((struct list
*)rn
->info
, node
, connected
))
1104 connected_dump_vty (vty
, connected
);
1107 for (ALL_LIST_ELEMENTS_RO (ifp
->connected
, node
, connected
))
1109 if (CHECK_FLAG (connected
->conf
, ZEBRA_IFC_REAL
) &&
1110 (connected
->address
->family
== AF_INET6
))
1111 connected_dump_vty (vty
, connected
);
1114 #if defined (HAVE_RTADV)
1115 nd_dump_vty (vty
, ifp
);
1116 #endif /* HAVE_RTADV */
1117 if (listhead(ifp
->nbr_connected
))
1118 vty_out (vty
, " Neighbor address(s):%s", VTY_NEWLINE
);
1119 for (ALL_LIST_ELEMENTS_RO (ifp
->nbr_connected
, node
, nbr_connected
))
1120 nbr_connected_dump_vty (vty
, nbr_connected
);
1122 #ifdef HAVE_PROC_NET_DEV
1123 /* Statistics print out using proc file system. */
1124 vty_out (vty
, " %lu input packets (%lu multicast), %lu bytes, "
1126 ifp
->stats
.rx_packets
, ifp
->stats
.rx_multicast
,
1127 ifp
->stats
.rx_bytes
, ifp
->stats
.rx_dropped
, VTY_NEWLINE
);
1129 vty_out (vty
, " %lu input errors, %lu length, %lu overrun,"
1130 " %lu CRC, %lu frame%s",
1131 ifp
->stats
.rx_errors
, ifp
->stats
.rx_length_errors
,
1132 ifp
->stats
.rx_over_errors
, ifp
->stats
.rx_crc_errors
,
1133 ifp
->stats
.rx_frame_errors
, VTY_NEWLINE
);
1135 vty_out (vty
, " %lu fifo, %lu missed%s", ifp
->stats
.rx_fifo_errors
,
1136 ifp
->stats
.rx_missed_errors
, VTY_NEWLINE
);
1138 vty_out (vty
, " %lu output packets, %lu bytes, %lu dropped%s",
1139 ifp
->stats
.tx_packets
, ifp
->stats
.tx_bytes
,
1140 ifp
->stats
.tx_dropped
, VTY_NEWLINE
);
1142 vty_out (vty
, " %lu output errors, %lu aborted, %lu carrier,"
1143 " %lu fifo, %lu heartbeat%s",
1144 ifp
->stats
.tx_errors
, ifp
->stats
.tx_aborted_errors
,
1145 ifp
->stats
.tx_carrier_errors
, ifp
->stats
.tx_fifo_errors
,
1146 ifp
->stats
.tx_heartbeat_errors
, VTY_NEWLINE
);
1148 vty_out (vty
, " %lu window, %lu collisions%s",
1149 ifp
->stats
.tx_window_errors
, ifp
->stats
.collisions
, VTY_NEWLINE
);
1150 #endif /* HAVE_PROC_NET_DEV */
1152 #ifdef HAVE_NET_RT_IFLIST
1153 #if defined (__bsdi__) || defined (__NetBSD__)
1154 /* Statistics print out using sysctl (). */
1155 vty_out (vty
, " input packets %qu, bytes %qu, dropped %qu,"
1156 " multicast packets %qu%s",
1157 ifp
->stats
.ifi_ipackets
, ifp
->stats
.ifi_ibytes
,
1158 ifp
->stats
.ifi_iqdrops
, ifp
->stats
.ifi_imcasts
,
1161 vty_out (vty
, " input errors %qu%s",
1162 ifp
->stats
.ifi_ierrors
, VTY_NEWLINE
);
1164 vty_out (vty
, " output packets %qu, bytes %qu, multicast packets %qu%s",
1165 ifp
->stats
.ifi_opackets
, ifp
->stats
.ifi_obytes
,
1166 ifp
->stats
.ifi_omcasts
, VTY_NEWLINE
);
1168 vty_out (vty
, " output errors %qu%s",
1169 ifp
->stats
.ifi_oerrors
, VTY_NEWLINE
);
1171 vty_out (vty
, " collisions %qu%s",
1172 ifp
->stats
.ifi_collisions
, VTY_NEWLINE
);
1174 /* Statistics print out using sysctl (). */
1175 vty_out (vty
, " input packets %lu, bytes %lu, dropped %lu,"
1176 " multicast packets %lu%s",
1177 ifp
->stats
.ifi_ipackets
, ifp
->stats
.ifi_ibytes
,
1178 ifp
->stats
.ifi_iqdrops
, ifp
->stats
.ifi_imcasts
,
1181 vty_out (vty
, " input errors %lu%s",
1182 ifp
->stats
.ifi_ierrors
, VTY_NEWLINE
);
1184 vty_out (vty
, " output packets %lu, bytes %lu, multicast packets %lu%s",
1185 ifp
->stats
.ifi_opackets
, ifp
->stats
.ifi_obytes
,
1186 ifp
->stats
.ifi_omcasts
, VTY_NEWLINE
);
1188 vty_out (vty
, " output errors %lu%s",
1189 ifp
->stats
.ifi_oerrors
, VTY_NEWLINE
);
1191 vty_out (vty
, " collisions %lu%s",
1192 ifp
->stats
.ifi_collisions
, VTY_NEWLINE
);
1193 #endif /* __bsdi__ || __NetBSD__ */
1194 #endif /* HAVE_NET_RT_IFLIST */
1197 /* Wrapper hook point for zebra daemon so that ifindex can be set
1198 * DEFUN macro not used as extract.pl HAS to ignore this
1199 * See also interface_cmd in lib/if.c
1201 DEFUN_NOSH (zebra_interface
,
1202 zebra_interface_cmd
,
1204 "Select an interface to configure\n"
1205 "Interface's name\n")
1208 struct interface
* ifp
;
1210 /* Call lib interface() */
1211 if ((ret
= interface_cmd
.func (self
, vty
, argc
, argv
)) != CMD_SUCCESS
)
1216 if (ifp
->ifindex
== IFINDEX_INTERNAL
)
1217 /* Is this really necessary? Shouldn't status be initialized to 0
1219 UNSET_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
);
1224 ALIAS (zebra_interface
,
1225 zebra_interface_vrf_cmd
,
1226 "interface IFNAME " VRF_CMD_STR
,
1227 "Select an interface to configure\n"
1228 "Interface's name\n"
1231 struct cmd_node interface_node
=
1238 /* Wrapper hook point for zebra daemon so that ifindex can be set
1239 * DEFUN macro not used as extract.pl HAS to ignore this
1240 * See also interface_cmd in lib/if.c
1242 DEFUN_NOSH (zebra_vrf
,
1245 "Select a VRF to configure\n"
1250 /* Call lib vrf() */
1251 if ((ret
= vrf_cmd
.func (self
, vty
, argc
, argv
)) != CMD_SUCCESS
)
1254 // vrfp = vty->index;
1259 struct cmd_node vrf_node
=
1266 /* Show all interfaces to vty. */
1267 DEFUN (show_interface
, show_interface_cmd
,
1270 "Interface status and configuration\n")
1272 struct listnode
*node
;
1273 struct interface
*ifp
;
1274 vrf_id_t vrf_id
= VRF_DEFAULT
;
1276 #ifdef HAVE_PROC_NET_DEV
1277 /* If system has interface statistics via proc file system, update
1279 ifstat_update_proc ();
1280 #endif /* HAVE_PROC_NET_DEV */
1281 #ifdef HAVE_NET_RT_IFLIST
1282 ifstat_update_sysctl ();
1283 #endif /* HAVE_NET_RT_IFLIST */
1286 VRF_GET_ID (vrf_id
, argv
[0]);
1288 /* All interface print. */
1289 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (vrf_id
), node
, ifp
))
1290 if_dump_vty (vty
, ifp
);
1295 ALIAS (show_interface
,
1296 show_interface_vrf_cmd
,
1297 "show interface " VRF_CMD_STR
,
1299 "Interface status and configuration\n"
1302 /* Show all interfaces to vty. */
1303 DEFUN (show_interface_vrf_all
, show_interface_vrf_all_cmd
,
1304 "show interface " VRF_ALL_CMD_STR
,
1306 "Interface status and configuration\n"
1307 VRF_ALL_CMD_HELP_STR
)
1309 struct listnode
*node
;
1310 struct interface
*ifp
;
1313 #ifdef HAVE_PROC_NET_DEV
1314 /* If system has interface statistics via proc file system, update
1316 ifstat_update_proc ();
1317 #endif /* HAVE_PROC_NET_DEV */
1318 #ifdef HAVE_NET_RT_IFLIST
1319 ifstat_update_sysctl ();
1320 #endif /* HAVE_NET_RT_IFLIST */
1322 /* All interface print. */
1323 for (iter
= vrf_first (); iter
!= VRF_ITER_INVALID
; iter
= vrf_next (iter
))
1324 for (ALL_LIST_ELEMENTS_RO (vrf_iter2iflist (iter
), node
, ifp
))
1325 if_dump_vty (vty
, ifp
);
1330 /* Show specified interface to vty. */
1332 DEFUN (show_interface_name_vrf
,
1333 show_interface_name_vrf_cmd
,
1334 "show interface IFNAME " VRF_CMD_STR
,
1336 "Interface status and configuration\n"
1340 struct interface
*ifp
;
1341 vrf_id_t vrf_id
= VRF_DEFAULT
;
1343 #ifdef HAVE_PROC_NET_DEV
1344 /* If system has interface statistics via proc file system, update
1346 ifstat_update_proc ();
1347 #endif /* HAVE_PROC_NET_DEV */
1348 #ifdef HAVE_NET_RT_IFLIST
1349 ifstat_update_sysctl ();
1350 #endif /* HAVE_NET_RT_IFLIST */
1353 VRF_GET_ID (vrf_id
, argv
[1]);
1355 /* Specified interface print. */
1356 ifp
= if_lookup_by_name_vrf (argv
[0], vrf_id
);
1359 vty_out (vty
, "%% Can't find interface %s%s", argv
[0],
1363 if_dump_vty (vty
, ifp
);
1368 /* Show specified interface to vty. */
1369 DEFUN (show_interface_name_vrf_all
, show_interface_name_vrf_all_cmd
,
1370 "show interface IFNAME " VRF_ALL_CMD_STR
,
1372 "Interface status and configuration\n"
1374 VRF_ALL_CMD_HELP_STR
)
1376 struct interface
*ifp
;
1380 #ifdef HAVE_PROC_NET_DEV
1381 /* If system has interface statistics via proc file system, update
1383 ifstat_update_proc ();
1384 #endif /* HAVE_PROC_NET_DEV */
1385 #ifdef HAVE_NET_RT_IFLIST
1386 ifstat_update_sysctl ();
1387 #endif /* HAVE_NET_RT_IFLIST */
1389 /* All interface print. */
1390 for (iter
= vrf_first (); iter
!= VRF_ITER_INVALID
; iter
= vrf_next (iter
))
1392 /* Specified interface print. */
1393 ifp
= if_lookup_by_name_vrf (argv
[0], vrf_iter2id (iter
));
1396 if_dump_vty (vty
, ifp
);
1403 vty_out (vty
, "%% Can't find interface %s%s", argv
[0], VTY_NEWLINE
);
1410 ALIAS (show_interface_name_vrf_all
, show_interface_name_cmd
,
1411 "show interface IFNAME",
1413 "Interface status and configuration\n"
1417 if_show_description (struct vty
*vty
, vrf_id_t vrf_id
)
1419 struct listnode
*node
;
1420 struct interface
*ifp
;
1422 vty_out (vty
, "Interface Status Protocol Description%s", VTY_NEWLINE
);
1423 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (vrf_id
), node
, ifp
))
1427 len
= vty_out (vty
, "%s", ifp
->name
);
1428 vty_out (vty
, "%*s", (16 - len
), " ");
1432 vty_out (vty
, "up ");
1433 if (CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_LINKDETECTION
))
1435 if (if_is_running(ifp
))
1436 vty_out (vty
, "up ");
1438 vty_out (vty
, "down ");
1442 vty_out (vty
, "unknown ");
1447 vty_out (vty
, "down down ");
1451 vty_out (vty
, "%s", ifp
->desc
);
1452 vty_out (vty
, "%s", VTY_NEWLINE
);
1456 DEFUN (show_interface_desc
,
1457 show_interface_desc_cmd
,
1458 "show interface description",
1460 "Interface status and configuration\n"
1461 "Interface description\n")
1463 vrf_id_t vrf_id
= VRF_DEFAULT
;
1466 VRF_GET_ID (vrf_id
, argv
[0]);
1468 if_show_description (vty
, vrf_id
);
1473 ALIAS (show_interface_desc
,
1474 show_interface_desc_vrf_cmd
,
1475 "show interface description " VRF_CMD_STR
,
1477 "Interface status and configuration\n"
1478 "Interface description\n"
1481 DEFUN (show_interface_desc_vrf_all
,
1482 show_interface_desc_vrf_all_cmd
,
1483 "show interface description " VRF_ALL_CMD_STR
,
1485 "Interface status and configuration\n"
1486 "Interface description\n"
1487 VRF_ALL_CMD_HELP_STR
)
1491 for (iter
= vrf_first (); iter
!= VRF_ITER_INVALID
; iter
= vrf_next (iter
))
1492 if (!list_isempty (vrf_iter2iflist (iter
)))
1494 vty_out (vty
, "%s\tVRF %u%s%s", VTY_NEWLINE
,
1496 VTY_NEWLINE
, VTY_NEWLINE
);
1497 if_show_description (vty
, vrf_iter2id (iter
));
1506 "Set multicast flag to interface\n")
1509 struct interface
*ifp
;
1510 struct zebra_if
*if_data
;
1512 ifp
= (struct interface
*) vty
->index
;
1513 if (CHECK_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
))
1515 ret
= if_set_flags (ifp
, IFF_MULTICAST
);
1518 vty_out (vty
, "Can't set multicast flag%s", VTY_NEWLINE
);
1523 if_data
= ifp
->info
;
1524 if_data
->multicast
= IF_ZEBRA_MULTICAST_ON
;
1529 DEFUN (no_multicast
,
1533 "Unset multicast flag to interface\n")
1536 struct interface
*ifp
;
1537 struct zebra_if
*if_data
;
1539 ifp
= (struct interface
*) vty
->index
;
1540 if (CHECK_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
))
1542 ret
= if_unset_flags (ifp
, IFF_MULTICAST
);
1545 vty_out (vty
, "Can't unset multicast flag%s", VTY_NEWLINE
);
1550 if_data
= ifp
->info
;
1551 if_data
->multicast
= IF_ZEBRA_MULTICAST_OFF
;
1559 "Enable link detection on interface\n")
1561 struct interface
*ifp
;
1562 int if_was_operative
;
1564 ifp
= (struct interface
*) vty
->index
;
1565 if_was_operative
= if_is_no_ptm_operative(ifp
);
1566 SET_FLAG(ifp
->status
, ZEBRA_INTERFACE_LINKDETECTION
);
1568 /* When linkdetection is enabled, if might come down */
1569 if (!if_is_no_ptm_operative(ifp
) && if_was_operative
) if_down(ifp
);
1571 /* FIXME: Will defer status change forwarding if interface
1572 does not come down! */
1578 DEFUN (no_linkdetect
,
1582 "Disable link detection on interface\n")
1584 struct interface
*ifp
;
1585 int if_was_operative
;
1587 ifp
= (struct interface
*) vty
->index
;
1588 if_was_operative
= if_is_no_ptm_operative(ifp
);
1589 UNSET_FLAG(ifp
->status
, ZEBRA_INTERFACE_LINKDETECTION
);
1591 /* Interface may come up after disabling link detection */
1592 if (if_is_operative(ifp
) && !if_was_operative
) if_up(ifp
);
1594 /* FIXME: see linkdetect_cmd */
1602 "Shutdown the selected interface\n")
1605 struct interface
*ifp
;
1606 struct zebra_if
*if_data
;
1608 ifp
= (struct interface
*) vty
->index
;
1609 if (ifp
->ifindex
!= IFINDEX_INTERNAL
)
1611 ret
= if_unset_flags (ifp
, IFF_UP
);
1614 vty_out (vty
, "Can't shutdown interface%s", VTY_NEWLINE
);
1619 if_data
= ifp
->info
;
1620 if_data
->shutdown
= IF_ZEBRA_SHUTDOWN_ON
;
1625 DEFUN (no_shutdown_if
,
1629 "Shutdown the selected interface\n")
1632 struct interface
*ifp
;
1633 struct zebra_if
*if_data
;
1635 ifp
= (struct interface
*) vty
->index
;
1637 if (ifp
->ifindex
!= IFINDEX_INTERNAL
)
1639 ret
= if_set_flags (ifp
, IFF_UP
| IFF_RUNNING
);
1642 vty_out (vty
, "Can't up interface%s", VTY_NEWLINE
);
1647 /* Some addresses (in particular, IPv6 addresses on Linux) get
1648 * removed when the interface goes down. They need to be readded.
1650 if_addr_wakeup(ifp
);
1653 if_data
= ifp
->info
;
1654 if_data
->shutdown
= IF_ZEBRA_SHUTDOWN_OFF
;
1659 DEFUN (bandwidth_if
,
1661 "bandwidth <1-10000000>",
1662 "Set bandwidth informational parameter\n"
1663 "Bandwidth in kilobits\n")
1665 struct interface
*ifp
;
1666 unsigned int bandwidth
;
1668 ifp
= (struct interface
*) vty
->index
;
1669 bandwidth
= strtol(argv
[0], NULL
, 10);
1671 /* bandwidth range is <1-10000000> */
1672 if (bandwidth
< 1 || bandwidth
> 10000000)
1674 vty_out (vty
, "Bandwidth is invalid%s", VTY_NEWLINE
);
1678 ifp
->bandwidth
= bandwidth
;
1680 /* force protocols to recalculate routes due to cost change */
1681 if (if_is_operative (ifp
))
1682 zebra_interface_up_update (ifp
);
1687 DEFUN (no_bandwidth_if
,
1688 no_bandwidth_if_cmd
,
1691 "Set bandwidth informational parameter\n")
1693 struct interface
*ifp
;
1695 ifp
= (struct interface
*) vty
->index
;
1699 /* force protocols to recalculate routes due to cost change */
1700 if (if_is_operative (ifp
))
1701 zebra_interface_up_update (ifp
);
1706 ALIAS (no_bandwidth_if
,
1707 no_bandwidth_if_val_cmd
,
1708 "no bandwidth <1-10000000>",
1710 "Set bandwidth informational parameter\n"
1711 "Bandwidth in kilobits\n")
1714 ip_address_install (struct vty
*vty
, struct interface
*ifp
,
1715 const char *addr_str
, const char *peer_str
,
1718 struct zebra_if
*if_data
;
1719 struct prefix_ipv4 cp
;
1720 struct connected
*ifc
;
1721 struct prefix_ipv4
*p
;
1724 if_data
= ifp
->info
;
1726 ret
= str2prefix_ipv4 (addr_str
, &cp
);
1729 vty_out (vty
, "%% Malformed address %s", VTY_NEWLINE
);
1733 if (ipv4_martian(&cp
.prefix
))
1735 vty_out (vty
, "%% Invalid address%s", VTY_NEWLINE
);
1739 ifc
= connected_check (ifp
, (struct prefix
*) &cp
);
1742 ifc
= connected_new ();
1746 p
= prefix_ipv4_new ();
1748 ifc
->address
= (struct prefix
*) p
;
1751 if (p
->prefixlen
<= IPV4_MAX_PREFIXLEN
-2)
1753 p
= prefix_ipv4_new ();
1755 p
->prefix
.s_addr
= ipv4_broadcast_addr(p
->prefix
.s_addr
,p
->prefixlen
);
1756 ifc
->destination
= (struct prefix
*) p
;
1761 ifc
->label
= XSTRDUP (MTYPE_CONNECTED_LABEL
, label
);
1763 /* Add to linked list. */
1764 listnode_add (ifp
->connected
, ifc
);
1767 /* This address is configured from zebra. */
1768 if (! CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
1769 SET_FLAG (ifc
->conf
, ZEBRA_IFC_CONFIGURED
);
1771 /* In case of this route need to install kernel. */
1772 if (! CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_QUEUED
)
1773 && CHECK_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
)
1774 && !(if_data
&& if_data
->shutdown
== IF_ZEBRA_SHUTDOWN_ON
))
1776 /* Some system need to up the interface to set IP address. */
1777 if (! if_is_up (ifp
))
1779 if_set_flags (ifp
, IFF_UP
| IFF_RUNNING
);
1783 ret
= if_set_prefix (ifp
, ifc
);
1786 vty_out (vty
, "%% Can't set interface IP address: %s.%s",
1787 safe_strerror(errno
), VTY_NEWLINE
);
1791 SET_FLAG (ifc
->conf
, ZEBRA_IFC_QUEUED
);
1792 /* The address will be advertised to zebra clients when the notification
1793 * from the kernel has been received.
1794 * It will also be added to the subnet chain list, then. */
1801 ip_address_uninstall (struct vty
*vty
, struct interface
*ifp
,
1802 const char *addr_str
, const char *peer_str
,
1805 struct prefix_ipv4 cp
;
1806 struct connected
*ifc
;
1809 /* Convert to prefix structure. */
1810 ret
= str2prefix_ipv4 (addr_str
, &cp
);
1813 vty_out (vty
, "%% Malformed address %s", VTY_NEWLINE
);
1817 /* Check current interface address. */
1818 ifc
= connected_check (ifp
, (struct prefix
*) &cp
);
1821 vty_out (vty
, "%% Can't find address%s", VTY_NEWLINE
);
1825 /* This is not configured address. */
1826 if (! CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
1829 UNSET_FLAG (ifc
->conf
, ZEBRA_IFC_CONFIGURED
);
1831 /* This is not real address or interface is not active. */
1832 if (! CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_QUEUED
)
1833 || ! CHECK_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
))
1835 listnode_delete (ifp
->connected
, ifc
);
1836 connected_free (ifc
);
1840 /* This is real route. */
1841 ret
= if_unset_prefix (ifp
, ifc
);
1844 vty_out (vty
, "%% Can't unset interface IP address: %s.%s",
1845 safe_strerror(errno
), VTY_NEWLINE
);
1848 UNSET_FLAG (ifc
->conf
, ZEBRA_IFC_QUEUED
);
1849 /* we will receive a kernel notification about this route being removed.
1850 * this will trigger its removal from the connected list. */
1856 "ip address A.B.C.D/M",
1857 "Interface Internet Protocol config commands\n"
1858 "Set the IP address of an interface\n"
1859 "IP address (e.g. 10.0.0.1/8)\n")
1861 return ip_address_install (vty
, vty
->index
, argv
[0], NULL
, NULL
);
1864 DEFUN (no_ip_address
,
1866 "no ip address A.B.C.D/M",
1868 "Interface Internet Protocol config commands\n"
1869 "Set the IP address of an interface\n"
1870 "IP Address (e.g. 10.0.0.1/8)")
1872 return ip_address_uninstall (vty
, vty
->index
, argv
[0], NULL
, NULL
);
1876 DEFUN (ip_address_label
,
1877 ip_address_label_cmd
,
1878 "ip address A.B.C.D/M label LINE",
1879 "Interface Internet Protocol config commands\n"
1880 "Set the IP address of an interface\n"
1881 "IP address (e.g. 10.0.0.1/8)\n"
1882 "Label of this address\n"
1885 return ip_address_install (vty
, vty
->index
, argv
[0], NULL
, argv
[1]);
1888 DEFUN (no_ip_address_label
,
1889 no_ip_address_label_cmd
,
1890 "no ip address A.B.C.D/M label LINE",
1892 "Interface Internet Protocol config commands\n"
1893 "Set the IP address of an interface\n"
1894 "IP address (e.g. 10.0.0.1/8)\n"
1895 "Label of this address\n"
1898 return ip_address_uninstall (vty
, vty
->index
, argv
[0], NULL
, argv
[1]);
1900 #endif /* HAVE_NETLINK */
1904 ipv6_address_install (struct vty
*vty
, struct interface
*ifp
,
1905 const char *addr_str
, const char *peer_str
,
1906 const char *label
, int secondary
)
1908 struct zebra_if
*if_data
;
1909 struct prefix_ipv6 cp
;
1910 struct connected
*ifc
;
1911 struct prefix_ipv6
*p
;
1914 if_data
= ifp
->info
;
1916 ret
= str2prefix_ipv6 (addr_str
, &cp
);
1919 vty_out (vty
, "%% Malformed address %s", VTY_NEWLINE
);
1923 if (ipv6_martian(&cp
.prefix
))
1925 vty_out (vty
, "%% Invalid address%s", VTY_NEWLINE
);
1929 ifc
= connected_check (ifp
, (struct prefix
*) &cp
);
1932 ifc
= connected_new ();
1936 p
= prefix_ipv6_new ();
1938 ifc
->address
= (struct prefix
*) p
;
1942 SET_FLAG (ifc
->flags
, ZEBRA_IFA_SECONDARY
);
1946 ifc
->label
= XSTRDUP (MTYPE_CONNECTED_LABEL
, label
);
1948 /* Add to linked list. */
1949 listnode_add (ifp
->connected
, ifc
);
1951 /* Enable RA on this interface */
1952 if (interface_ipv6_auto_ra_allowed (ifp
))
1953 ipv6_nd_suppress_ra_set (ifp
, RA_ENABLE
);
1956 /* This address is configured from zebra. */
1957 if (! CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
1958 SET_FLAG (ifc
->conf
, ZEBRA_IFC_CONFIGURED
);
1960 /* In case of this route need to install kernel. */
1961 if (! CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_QUEUED
)
1962 && CHECK_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
)
1963 && !(if_data
&& if_data
->shutdown
== IF_ZEBRA_SHUTDOWN_ON
))
1965 /* Some system need to up the interface to set IP address. */
1966 if (! if_is_up (ifp
))
1968 if_set_flags (ifp
, IFF_UP
| IFF_RUNNING
);
1972 ret
= if_prefix_add_ipv6 (ifp
, ifc
);
1976 vty_out (vty
, "%% Can't set interface IP address: %s.%s",
1977 safe_strerror(errno
), VTY_NEWLINE
);
1981 SET_FLAG (ifc
->conf
, ZEBRA_IFC_QUEUED
);
1982 /* The address will be advertised to zebra clients when the notification
1983 * from the kernel has been received. */
1989 /* Return true if an ipv6 address is configured on ifp */
1991 ipv6_address_configured (struct interface
*ifp
)
1993 struct connected
*connected
;
1994 struct listnode
*node
;
1996 for (ALL_LIST_ELEMENTS_RO (ifp
->connected
, node
, connected
))
1997 if (CHECK_FLAG (connected
->conf
, ZEBRA_IFC_REAL
) && (connected
->address
->family
== AF_INET6
))
2004 ipv6_address_uninstall (struct vty
*vty
, struct interface
*ifp
,
2005 const char *addr_str
, const char *peer_str
,
2006 const char *label
, int secondry
)
2008 struct prefix_ipv6 cp
;
2009 struct connected
*ifc
;
2012 /* Convert to prefix structure. */
2013 ret
= str2prefix_ipv6 (addr_str
, &cp
);
2016 vty_out (vty
, "%% Malformed address %s", VTY_NEWLINE
);
2020 /* Check current interface address. */
2021 ifc
= connected_check (ifp
, (struct prefix
*) &cp
);
2024 vty_out (vty
, "%% Can't find address%s", VTY_NEWLINE
);
2028 /* This is not configured address. */
2029 if (! CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
2032 UNSET_FLAG (ifc
->conf
, ZEBRA_IFC_CONFIGURED
);
2034 /* This is not real address or interface is not active. */
2035 if (! CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_QUEUED
)
2036 || ! CHECK_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
))
2038 listnode_delete (ifp
->connected
, ifc
);
2039 connected_free (ifc
);
2043 /* This is real route. */
2044 ret
= if_prefix_delete_ipv6 (ifp
, ifc
);
2047 vty_out (vty
, "%% Can't unset interface IP address: %s.%s",
2048 safe_strerror(errno
), VTY_NEWLINE
);
2052 /* Enable RA suppression if there are no IPv6 addresses on this interface */
2053 if (interface_ipv6_auto_ra_allowed (ifp
))
2055 if (! ipv6_address_configured(ifp
))
2056 ipv6_nd_suppress_ra_set (ifp
, RA_SUPPRESS
);
2059 UNSET_FLAG (ifc
->conf
, ZEBRA_IFC_QUEUED
);
2060 /* This information will be propagated to the zclients when the
2061 * kernel notification is received. */
2065 DEFUN (ipv6_address
,
2067 "ipv6 address X:X::X:X/M",
2068 "Interface IPv6 config commands\n"
2069 "Set the IP address of an interface\n"
2070 "IPv6 address (e.g. 3ffe:506::1/48)\n")
2072 return ipv6_address_install (vty
, vty
->index
, argv
[0], NULL
, NULL
, 0);
2075 DEFUN (no_ipv6_address
,
2076 no_ipv6_address_cmd
,
2077 "no ipv6 address X:X::X:X/M",
2079 "Interface IPv6 config commands\n"
2080 "Set the IP address of an interface\n"
2081 "IPv6 address (e.g. 3ffe:506::1/48)\n")
2083 return ipv6_address_uninstall (vty
, vty
->index
, argv
[0], NULL
, NULL
, 0);
2085 #endif /* HAVE_IPV6 */
2088 if_config_write (struct vty
*vty
)
2090 struct listnode
*node
;
2091 struct interface
*ifp
;
2094 zebra_ptm_write (vty
);
2096 for (iter
= vrf_first (); iter
!= VRF_ITER_INVALID
; iter
= vrf_next (iter
))
2097 for (ALL_LIST_ELEMENTS_RO (vrf_iter2iflist (iter
), node
, ifp
))
2099 struct zebra_if
*if_data
;
2100 struct listnode
*addrnode
;
2101 struct connected
*ifc
;
2105 if_data
= ifp
->info
;
2106 vrf
= vrf_lookup(ifp
->vrf_id
);
2108 if (ifp
->vrf_id
== VRF_DEFAULT
)
2109 vty_out (vty
, "interface %s%s", ifp
->name
, VTY_NEWLINE
);
2111 vty_out (vty
, "interface %s vrf %s%s", ifp
->name
, vrf
->name
,
2116 if (if_data
->shutdown
== IF_ZEBRA_SHUTDOWN_ON
)
2117 vty_out (vty
, " shutdown%s", VTY_NEWLINE
);
2121 vty_out (vty
, " description %s%s", ifp
->desc
,
2124 /* Assign bandwidth here to avoid unnecessary interface flap
2125 while processing config script */
2126 if (ifp
->bandwidth
!= 0)
2127 vty_out(vty
, " bandwidth %u%s", ifp
->bandwidth
, VTY_NEWLINE
);
2129 if (CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_LINKDETECTION
))
2130 vty_out(vty
, " link-detect%s", VTY_NEWLINE
);
2132 for (ALL_LIST_ELEMENTS_RO (ifp
->connected
, addrnode
, ifc
))
2134 if (CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
2136 char buf
[INET6_ADDRSTRLEN
];
2138 vty_out (vty
, " ip%s address %s/%d",
2139 p
->family
== AF_INET
? "" : "v6",
2140 inet_ntop (p
->family
, &p
->u
.prefix
, buf
, sizeof(buf
)),
2144 vty_out (vty
, " label %s", ifc
->label
);
2146 vty_out (vty
, "%s", VTY_NEWLINE
);
2152 if (if_data
->multicast
!= IF_ZEBRA_MULTICAST_UNSPEC
)
2153 vty_out (vty
, " %smulticast%s",
2154 if_data
->multicast
== IF_ZEBRA_MULTICAST_ON
? "" : "no ",
2158 #if defined (HAVE_RTADV)
2159 rtadv_config_write (vty
, ifp
);
2160 #endif /* HAVE_RTADV */
2163 irdp_config_write (vty
, ifp
);
2166 vty_out (vty
, "!%s", VTY_NEWLINE
);
2172 vrf_config_write (struct vty
*vty
)
2174 struct listnode
*node
;
2177 for (ALL_LIST_ELEMENTS_RO (vrf_list
, node
, vrf
))
2179 if (strcmp(vrf
->name
, VRF_DEFAULT_NAME
))
2181 vty_out (vty
, "vrf %s%s", vrf
->name
, VTY_NEWLINE
);
2182 vty_out (vty
, "!%s", VTY_NEWLINE
);
2188 /* Allocate and initialize interface vector. */
2190 zebra_if_init (void)
2192 /* Initialize interface and new hook. */
2193 if_add_hook (IF_NEW_HOOK
, if_zebra_new_hook
);
2194 if_add_hook (IF_DELETE_HOOK
, if_zebra_delete_hook
);
2196 /* Install configuration write function. */
2197 install_node (&interface_node
, if_config_write
);
2198 install_node (&vrf_node
, vrf_config_write
);
2200 install_element (VIEW_NODE
, &show_interface_cmd
);
2201 install_element (VIEW_NODE
, &show_interface_vrf_cmd
);
2202 install_element (VIEW_NODE
, &show_interface_vrf_all_cmd
);
2203 install_element (VIEW_NODE
, &show_interface_name_cmd
);
2204 install_element (VIEW_NODE
, &show_interface_name_vrf_cmd
);
2205 install_element (VIEW_NODE
, &show_interface_name_vrf_all_cmd
);
2206 install_element (ENABLE_NODE
, &show_interface_cmd
);
2207 install_element (ENABLE_NODE
, &show_interface_vrf_cmd
);
2208 install_element (ENABLE_NODE
, &show_interface_vrf_all_cmd
);
2209 install_element (ENABLE_NODE
, &show_interface_name_cmd
);
2210 install_element (ENABLE_NODE
, &show_interface_name_vrf_cmd
);
2211 install_element (ENABLE_NODE
, &show_interface_name_vrf_all_cmd
);
2212 install_element (ENABLE_NODE
, &show_interface_desc_cmd
);
2213 install_element (ENABLE_NODE
, &show_interface_desc_vrf_cmd
);
2214 install_element (ENABLE_NODE
, &show_interface_desc_vrf_all_cmd
);
2215 install_element (CONFIG_NODE
, &zebra_interface_cmd
);
2216 install_element (CONFIG_NODE
, &zebra_interface_vrf_cmd
);
2217 install_element (CONFIG_NODE
, &no_interface_cmd
);
2218 install_element (CONFIG_NODE
, &no_interface_vrf_cmd
);
2219 install_default (INTERFACE_NODE
);
2220 install_element (INTERFACE_NODE
, &interface_desc_cmd
);
2221 install_element (INTERFACE_NODE
, &no_interface_desc_cmd
);
2222 install_element (INTERFACE_NODE
, &multicast_cmd
);
2223 install_element (INTERFACE_NODE
, &no_multicast_cmd
);
2224 install_element (INTERFACE_NODE
, &linkdetect_cmd
);
2225 install_element (INTERFACE_NODE
, &no_linkdetect_cmd
);
2226 install_element (INTERFACE_NODE
, &shutdown_if_cmd
);
2227 install_element (INTERFACE_NODE
, &no_shutdown_if_cmd
);
2228 install_element (INTERFACE_NODE
, &bandwidth_if_cmd
);
2229 install_element (INTERFACE_NODE
, &no_bandwidth_if_cmd
);
2230 install_element (INTERFACE_NODE
, &no_bandwidth_if_val_cmd
);
2231 install_element (INTERFACE_NODE
, &ip_address_cmd
);
2232 install_element (INTERFACE_NODE
, &no_ip_address_cmd
);
2234 install_element (INTERFACE_NODE
, &ipv6_address_cmd
);
2235 install_element (INTERFACE_NODE
, &no_ipv6_address_cmd
);
2236 #endif /* HAVE_IPV6 */
2238 install_element (INTERFACE_NODE
, &ip_address_label_cmd
);
2239 install_element (INTERFACE_NODE
, &no_ip_address_label_cmd
);
2240 #endif /* HAVE_NETLINK */
2242 install_element (CONFIG_NODE
, &zebra_vrf_cmd
);
2243 install_element (CONFIG_NODE
, &no_vrf_cmd
);
2244 install_default (VRF_NODE
);