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/rtadv.h"
39 #include "zebra_vrf.h"
40 #include "zebra/interface.h"
41 #include "zebra/rib.h"
43 #include "zebra/zserv.h"
44 #include "zebra/redistribute.h"
45 #include "zebra/debug.h"
46 #include "zebra/irdp.h"
47 #include "zebra/zebra_ptm.h"
48 #include "zebra/rt_netlink.h"
49 #include "zebra/interface.h"
51 #define ZEBRA_PTM_SUPPORT
53 #if defined (HAVE_RTADV)
54 /* Order is intentional. Matches RFC4191. This array is also used for
55 command matching, so only modify with care. */
56 const char *rtadv_pref_strs
[] = { "medium", "high", "INVALID", "low", 0 };
57 #endif /* HAVE_RTADV */
59 static void if_down_del_nbr_connected (struct interface
*ifp
);
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
;
71 zebra_ptm_if_init(zebra_if
);
73 ifp
->ptm_enable
= zebra_ptm_get_enable_state();
74 #if defined (HAVE_RTADV)
76 /* Set default router advertise values. */
77 struct rtadvconf
*rtadv
;
79 rtadv
= &zebra_if
->rtadv
;
81 rtadv
->AdvSendAdvertisements
= 0;
82 rtadv
->MaxRtrAdvInterval
= RTADV_MAX_RTR_ADV_INTERVAL
;
83 rtadv
->MinRtrAdvInterval
= RTADV_MIN_RTR_ADV_INTERVAL
;
84 rtadv
->AdvIntervalTimer
= 0;
85 rtadv
->AdvManagedFlag
= 0;
86 rtadv
->AdvOtherConfigFlag
= 0;
87 rtadv
->AdvHomeAgentFlag
= 0;
88 rtadv
->AdvLinkMTU
= 0;
89 rtadv
->AdvReachableTime
= 0;
90 rtadv
->AdvRetransTimer
= 0;
91 rtadv
->AdvCurHopLimit
= 0;
92 rtadv
->AdvDefaultLifetime
= -1; /* derive from MaxRtrAdvInterval */
93 rtadv
->HomeAgentPreference
= 0;
94 rtadv
->HomeAgentLifetime
= -1; /* derive from AdvDefaultLifetime */
95 rtadv
->AdvIntervalOption
= 0;
96 rtadv
->DefaultPreference
= RTADV_PREF_MEDIUM
;
98 rtadv
->AdvPrefixList
= list_new ();
100 #endif /* HAVE_RTADV */
102 /* Initialize installed address chains tree. */
103 zebra_if
->ipv4_subnets
= route_table_init ();
105 ifp
->info
= zebra_if
;
107 zebra_vrf_static_route_interface_fixup (ifp
);
111 /* Called when interface is deleted. */
113 if_zebra_delete_hook (struct interface
*ifp
)
115 struct zebra_if
*zebra_if
;
119 zebra_if
= ifp
->info
;
121 /* Free installed address chains tree. */
122 if (zebra_if
->ipv4_subnets
)
123 route_table_finish (zebra_if
->ipv4_subnets
);
124 #if defined (HAVE_RTADV)
126 struct rtadvconf
*rtadv
;
128 rtadv
= &zebra_if
->rtadv
;
129 list_free (rtadv
->AdvPrefixList
);
130 #endif /* HAVE_RTADV */
132 XFREE (MTYPE_TMP
, zebra_if
);
138 /* Build the table key */
140 if_build_key (u_int32_t ifindex
, struct prefix
*p
)
143 p
->prefixlen
= IPV4_MAX_BITLEN
;
144 p
->u
.prefix4
.s_addr
= ifindex
;
147 /* Link an interface in a per NS interface tree */
149 if_link_per_ns (struct zebra_ns
*ns
, struct interface
*ifp
)
152 struct route_node
*rn
;
154 if (ifp
->ifindex
== IFINDEX_INTERNAL
)
157 if_build_key (ifp
->ifindex
, &p
);
158 rn
= route_node_get (ns
->if_table
, &p
);
161 ifp
= (struct interface
*)rn
->info
;
162 route_unlock_node (rn
); /* get */
172 /* Delete a VRF. This is called in vrf_terminate(). */
174 if_unlink_per_ns (struct interface
*ifp
)
176 ifp
->node
->info
= NULL
;
177 route_unlock_node(ifp
->node
);
180 /* Look up an interface by identifier within a NS */
182 if_lookup_by_index_per_ns (struct zebra_ns
*ns
, u_int32_t ifindex
)
185 struct route_node
*rn
;
186 struct interface
*ifp
= NULL
;
188 if_build_key (ifindex
, &p
);
189 rn
= route_node_lookup (ns
->if_table
, &p
);
192 ifp
= (struct interface
*)rn
->info
;
193 route_unlock_node (rn
); /* lookup */
199 ifindex2ifname_per_ns (struct zebra_ns
*zns
, unsigned int ifindex
)
201 struct interface
*ifp
;
203 return ((ifp
= if_lookup_by_index_per_ns (zns
, ifindex
)) != NULL
) ?
204 ifp
->name
: "unknown";
207 /* Tie an interface address to its derived subnet list of addresses. */
209 if_subnet_add (struct interface
*ifp
, struct connected
*ifc
)
211 struct route_node
*rn
;
212 struct zebra_if
*zebra_if
;
214 struct list
*addr_list
;
216 assert (ifp
&& ifp
->info
&& ifc
);
217 zebra_if
= ifp
->info
;
219 /* Get address derived subnet node and associated address list, while marking
220 address secondary attribute appropriately. */
223 rn
= route_node_get (zebra_if
->ipv4_subnets
, &cp
);
225 if ((addr_list
= rn
->info
))
226 SET_FLAG (ifc
->flags
, ZEBRA_IFA_SECONDARY
);
229 UNSET_FLAG (ifc
->flags
, ZEBRA_IFA_SECONDARY
);
230 rn
->info
= addr_list
= list_new ();
231 route_lock_node (rn
);
234 /* Tie address at the tail of address list. */
235 listnode_add (addr_list
, ifc
);
237 /* Return list element count. */
238 return (addr_list
->count
);
241 /* Untie an interface address from its derived subnet list of addresses. */
243 if_subnet_delete (struct interface
*ifp
, struct connected
*ifc
)
245 struct route_node
*rn
;
246 struct zebra_if
*zebra_if
;
247 struct list
*addr_list
;
249 assert (ifp
&& ifp
->info
&& ifc
);
250 zebra_if
= ifp
->info
;
252 /* Get address derived subnet node. */
253 rn
= route_node_lookup (zebra_if
->ipv4_subnets
, ifc
->address
);
254 if (! (rn
&& rn
->info
))
256 zlog_warn("Trying to remove an address from an unknown subnet."
257 " (please report this bug)");
260 route_unlock_node (rn
);
262 /* Untie address from subnet's address list. */
263 addr_list
= rn
->info
;
265 /* Deleting an address that is not registered is a bug.
266 * In any case, we shouldn't decrement the lock counter if the address
268 if (!listnode_lookup(addr_list
, ifc
))
270 zlog_warn("Trying to remove an address from a subnet where it is not"
271 " currently registered. (please report this bug)");
275 listnode_delete (addr_list
, ifc
);
276 route_unlock_node (rn
);
278 /* Return list element count, if not empty. */
279 if (addr_list
->count
)
281 /* If deleted address is primary, mark subsequent one as such and distribute. */
282 if (! CHECK_FLAG (ifc
->flags
, ZEBRA_IFA_SECONDARY
))
284 ifc
= listgetdata (listhead (addr_list
));
285 zebra_interface_address_delete_update (ifp
, ifc
);
286 UNSET_FLAG (ifc
->flags
, ZEBRA_IFA_SECONDARY
);
287 /* XXX: Linux kernel removes all the secondary addresses when the primary
288 * address is removed. We could try to work around that, though this is
290 zebra_interface_address_add_update (ifp
, ifc
);
293 return addr_list
->count
;
296 /* Otherwise, free list and route node. */
297 list_free (addr_list
);
299 route_unlock_node (rn
);
304 /* if_flags_mangle: A place for hacks that require mangling
305 * or tweaking the interface flags.
307 * ******************** Solaris flags hacks **************************
309 * Solaris IFF_UP flag reflects only the primary interface as the
310 * routing socket only sends IFINFO for the primary interface. Hence
311 * ~IFF_UP does not per se imply all the logical interfaces are also
312 * down - which we only know of as addresses. Instead we must determine
313 * whether the interface really is up or not according to how many
314 * addresses are still attached. (Solaris always sends RTM_DELADDR if
315 * an interface, logical or not, goes ~IFF_UP).
317 * Ie, we mangle IFF_UP to *additionally* reflect whether or not there
318 * are addresses left in struct connected, not just the actual underlying
321 * We must hence remember the real state of IFF_UP, which we do in
322 * struct zebra_if.primary_state.
324 * Setting IFF_UP within zebra to administratively shutdown the
325 * interface will affect only the primary interface/address on Solaris.
326 ************************End Solaris flags hacks ***********************
329 if_flags_mangle (struct interface
*ifp
, uint64_t *newflags
)
332 struct zebra_if
*zif
= ifp
->info
;
334 zif
->primary_state
= *newflags
& (IFF_UP
& 0xff);
336 if (CHECK_FLAG (zif
->primary_state
, IFF_UP
)
337 || listcount(ifp
->connected
) > 0)
338 SET_FLAG (*newflags
, IFF_UP
);
340 UNSET_FLAG (*newflags
, IFF_UP
);
344 /* Update the flags field of the ifp with the new flag set provided.
345 * Take whatever actions are required for any changes in flags we care
348 * newflags should be the raw value, as obtained from the OS.
351 if_flags_update (struct interface
*ifp
, uint64_t newflags
)
353 if_flags_mangle (ifp
, &newflags
);
355 if (if_is_no_ptm_operative (ifp
))
357 /* operative -> inoperative? */
358 ifp
->flags
= newflags
;
359 if (!if_is_operative (ifp
))
364 /* inoperative -> operative? */
365 ifp
->flags
= newflags
;
366 if (if_is_operative (ifp
))
371 /* Wake up configured address if it is not in current kernel
374 if_addr_wakeup (struct interface
*ifp
)
376 struct listnode
*node
, *nnode
;
377 struct connected
*ifc
;
381 for (ALL_LIST_ELEMENTS (ifp
->connected
, node
, nnode
, ifc
))
385 if (CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_CONFIGURED
)
386 && ! CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_QUEUED
))
389 if (p
->family
== AF_INET
)
391 if (! if_is_up (ifp
))
393 /* Assume zebra is configured like following:
396 * ip addr 192.0.2.1/24
399 * As soon as zebra becomes first aware that gre0 exists in the
400 * kernel, it will set gre0 up and configure its addresses.
402 * (This may happen at startup when the interface already exists
403 * or during runtime when the interface is added to the kernel)
405 * XXX: IRDP code is calling here via if_add_update - this seems
407 * XXX: RUNNING is not a settable flag on any system
408 * I (paulj) am aware of.
410 if_set_flags (ifp
, IFF_UP
| IFF_RUNNING
);
414 ret
= if_set_prefix (ifp
, ifc
);
417 zlog_warn ("Can't set interface's address: %s",
418 safe_strerror(errno
));
422 SET_FLAG (ifc
->conf
, ZEBRA_IFC_QUEUED
);
423 /* The address will be advertised to zebra clients when the notification
424 * from the kernel has been received.
425 * It will also be added to the interface's subnet list then. */
428 if (p
->family
== AF_INET6
)
430 if (! if_is_up (ifp
))
432 /* See long comment above */
433 if_set_flags (ifp
, IFF_UP
| IFF_RUNNING
);
437 ret
= if_prefix_add_ipv6 (ifp
, ifc
);
440 zlog_warn ("Can't set interface's address: %s",
441 safe_strerror(errno
));
445 SET_FLAG (ifc
->conf
, ZEBRA_IFC_QUEUED
);
446 /* The address will be advertised to zebra clients when the notification
447 * from the kernel has been received. */
449 #endif /* HAVE_IPV6 */
454 /* Handle interface addition */
456 if_add_update (struct interface
*ifp
)
458 struct zebra_if
*if_data
;
460 if_link_per_ns(zebra_ns_lookup (NS_DEFAULT
), ifp
);
465 if (if_data
->multicast
== IF_ZEBRA_MULTICAST_ON
)
466 if_set_flags (ifp
, IFF_MULTICAST
);
467 else if (if_data
->multicast
== IF_ZEBRA_MULTICAST_OFF
)
468 if_unset_flags (ifp
, IFF_MULTICAST
);
470 zebra_ptm_if_set_ptm_state(ifp
, if_data
);
472 zebra_interface_add_update (ifp
);
474 if (! CHECK_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
))
476 SET_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
);
478 if (if_data
&& if_data
->shutdown
== IF_ZEBRA_SHUTDOWN_ON
)
480 if (IS_ZEBRA_DEBUG_KERNEL
)
481 zlog_debug ("interface %s vrf %u index %d is shutdown. "
483 ifp
->name
, ifp
->vrf_id
, ifp
->ifindex
);
487 if_addr_wakeup (ifp
);
489 if (IS_ZEBRA_DEBUG_KERNEL
)
490 zlog_debug ("interface %s vrf %u index %d becomes active.",
491 ifp
->name
, ifp
->vrf_id
, ifp
->ifindex
);
495 if (IS_ZEBRA_DEBUG_KERNEL
)
496 zlog_debug ("interface %s vrf %u index %d is added.",
497 ifp
->name
, ifp
->vrf_id
, ifp
->ifindex
);
501 /* Install connected routes corresponding to an interface. */
503 if_install_connected (struct interface
*ifp
)
505 struct listnode
*node
;
506 struct listnode
*next
;
507 struct connected
*ifc
;
512 for (ALL_LIST_ELEMENTS (ifp
->connected
, node
, next
, ifc
))
515 zebra_interface_address_add_update (ifp
, ifc
);
517 if (p
->family
== AF_INET
)
518 connected_up_ipv4 (ifp
, ifc
);
519 else if (p
->family
== AF_INET6
)
520 connected_up_ipv6 (ifp
, ifc
);
525 /* Uninstall connected routes corresponding to an interface. */
527 if_uninstall_connected (struct interface
*ifp
)
529 struct listnode
*node
;
530 struct listnode
*next
;
531 struct connected
*ifc
;
536 for (ALL_LIST_ELEMENTS (ifp
->connected
, node
, next
, ifc
))
539 zebra_interface_address_delete_update (ifp
, ifc
);
541 if (p
->family
== AF_INET
)
542 connected_down_ipv4 (ifp
, ifc
);
543 else if (p
->family
== AF_INET6
)
544 connected_down_ipv6 (ifp
, ifc
);
549 /* Uninstall and delete connected routes corresponding to an interface. */
550 /* TODO - Check why IPv4 handling here is different from install or if_down */
552 if_delete_connected (struct interface
*ifp
)
554 struct connected
*ifc
;
556 struct route_node
*rn
;
557 struct zebra_if
*zebra_if
;
559 zebra_if
= ifp
->info
;
563 struct listnode
*node
;
564 struct listnode
*last
= NULL
;
566 while ((node
= (last
? last
->next
: listhead (ifp
->connected
))))
568 ifc
= listgetdata (node
);
571 if (p
->family
== AF_INET
572 && (rn
= route_node_lookup (zebra_if
->ipv4_subnets
, p
)))
574 struct listnode
*anode
;
575 struct listnode
*next
;
576 struct listnode
*first
;
577 struct list
*addr_list
;
579 route_unlock_node (rn
);
580 addr_list
= (struct list
*) rn
->info
;
582 /* Remove addresses, secondaries first. */
583 first
= listhead (addr_list
);
584 for (anode
= first
->next
; anode
|| first
; anode
= next
)
593 ifc
= listgetdata (anode
);
594 connected_down_ipv4 (ifp
, ifc
);
596 /* XXX: We have to send notifications here explicitly, because we destroy
597 * the ifc before receiving the notification about the address being deleted.
599 zebra_interface_address_delete_update (ifp
, ifc
);
601 UNSET_FLAG (ifc
->conf
, ZEBRA_IFC_REAL
);
602 UNSET_FLAG (ifc
->conf
, ZEBRA_IFC_QUEUED
);
604 /* Remove from subnet chain. */
605 list_delete_node (addr_list
, anode
);
606 route_unlock_node (rn
);
608 /* Remove from interface address list (unconditionally). */
609 if (!CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
611 listnode_delete (ifp
->connected
, ifc
);
612 connected_free (ifc
);
618 /* Free chain list and respective route node. */
619 list_delete (addr_list
);
621 route_unlock_node (rn
);
623 else if (p
->family
== AF_INET6
)
625 connected_down_ipv6 (ifp
, ifc
);
627 zebra_interface_address_delete_update (ifp
, ifc
);
629 UNSET_FLAG (ifc
->conf
, ZEBRA_IFC_REAL
);
630 UNSET_FLAG (ifc
->conf
, ZEBRA_IFC_QUEUED
);
632 if (CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
636 listnode_delete (ifp
->connected
, ifc
);
637 connected_free (ifc
);
648 /* Handle an interface delete event */
650 if_delete_update (struct interface
*ifp
)
654 zlog_err ("interface %s vrf %u index %d is still up while being deleted.",
655 ifp
->name
, ifp
->vrf_id
, ifp
->ifindex
);
659 /* Mark interface as inactive */
660 UNSET_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
);
662 if (IS_ZEBRA_DEBUG_KERNEL
)
663 zlog_debug ("interface %s vrf %u index %d is now inactive.",
664 ifp
->name
, ifp
->vrf_id
, ifp
->ifindex
);
666 /* Delete connected routes from the kernel. */
667 if_delete_connected (ifp
);
669 /* Send out notification on interface delete. */
670 zebra_interface_delete_update (ifp
);
672 if_unlink_per_ns(ifp
);
674 /* Update ifindex after distributing the delete message. This is in
675 case any client needs to have the old value of ifindex available
676 while processing the deletion. Each client daemon is responsible
677 for setting ifindex to IFINDEX_INTERNAL after processing the
678 interface deletion message. */
679 ifp
->ifindex
= IFINDEX_INTERNAL
;
682 /* VRF change for an interface */
684 if_handle_vrf_change (struct interface
*ifp
, vrf_id_t vrf_id
)
688 old_vrf_id
= ifp
->vrf_id
;
690 /* Uninstall connected routes. */
691 if_uninstall_connected (ifp
);
693 /* Delete any IPv4 neighbors created to implement RFC 5549 */
694 if_nbr_ipv6ll_to_ipv4ll_neigh_del_all (ifp
);
696 /* Delete all neighbor addresses learnt through IPv6 RA */
697 if_down_del_nbr_connected (ifp
);
699 /* Send out notification on interface VRF change. */
700 /* This is to issue an UPDATE or a DELETE, as appropriate. */
701 zebra_interface_vrf_update_del (ifp
, vrf_id
);
704 if_update_vrf (ifp
, ifp
->name
, strlen (ifp
->name
), vrf_id
);
706 /* Send out notification on interface VRF change. */
707 /* This is to issue an ADD, if needed. */
708 zebra_interface_vrf_update_add (ifp
, old_vrf_id
);
710 /* Install connected routes (in new VRF). */
711 if_install_connected (ifp
);
713 /* Due to connected route change, schedule RIB processing for both old
716 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
717 zlog_debug ("%u: IF %s VRF change, scheduling RIB processing",
718 ifp
->vrf_id
, ifp
->name
);
719 rib_update (old_vrf_id
, RIB_UPDATE_IF_CHANGE
);
720 rib_update (ifp
->vrf_id
, RIB_UPDATE_IF_CHANGE
);
722 zebra_vrf_static_route_interface_fixup (ifp
);
726 ipv6_ll_address_to_mac (struct in6_addr
*address
, u_char
*mac
)
728 mac
[0] = address
->s6_addr
[8] ^ 0x02;
729 mac
[1] = address
->s6_addr
[9];
730 mac
[2] = address
->s6_addr
[10];
731 mac
[3] = address
->s6_addr
[13];
732 mac
[4] = address
->s6_addr
[14];
733 mac
[5] = address
->s6_addr
[15];
737 if_nbr_ipv6ll_to_ipv4ll_neigh_update (struct interface
*ifp
,
738 struct in6_addr
*address
,
741 char buf
[16] = "169.254.0.1";
742 struct in_addr ipv4_ll
;
745 inet_pton (AF_INET
, buf
, &ipv4_ll
);
747 ipv6_ll_address_to_mac(address
, (u_char
*)mac
);
748 kernel_neigh_update (add
, ifp
->ifindex
, ipv4_ll
.s_addr
, mac
, 6);
752 if_nbr_ipv6ll_to_ipv4ll_neigh_add_all (struct interface
*ifp
)
754 if (listhead(ifp
->nbr_connected
))
756 struct nbr_connected
*nbr_connected
;
757 struct listnode
*node
;
759 for (ALL_LIST_ELEMENTS_RO (ifp
->nbr_connected
, node
, nbr_connected
))
760 if_nbr_ipv6ll_to_ipv4ll_neigh_update (ifp
,
761 &nbr_connected
->address
->u
.prefix6
,
767 if_nbr_ipv6ll_to_ipv4ll_neigh_del_all (struct interface
*ifp
)
769 if (listhead(ifp
->nbr_connected
))
771 struct nbr_connected
*nbr_connected
;
772 struct listnode
*node
;
774 for (ALL_LIST_ELEMENTS_RO (ifp
->nbr_connected
, node
, nbr_connected
))
775 if_nbr_ipv6ll_to_ipv4ll_neigh_update (ifp
,
776 &nbr_connected
->address
->u
.prefix6
,
782 if_down_del_nbr_connected (struct interface
*ifp
)
784 struct nbr_connected
*nbr_connected
;
785 struct listnode
*node
, *nnode
;
787 for (ALL_LIST_ELEMENTS (ifp
->nbr_connected
, node
, nnode
, nbr_connected
))
789 listnode_delete (ifp
->nbr_connected
, nbr_connected
);
790 nbr_connected_free (nbr_connected
);
794 /* Interface is up. */
796 if_up (struct interface
*ifp
)
798 struct zebra_if
*zif
;
802 quagga_timestamp (2, zif
->up_last
, sizeof (zif
->up_last
));
804 /* Notify the protocol daemons. */
805 if (ifp
->ptm_enable
&& (ifp
->ptm_status
== ZEBRA_PTM_STATUS_DOWN
)) {
806 zlog_warn("%s: interface %s hasn't passed ptm check\n", __func__
,
810 zebra_interface_up_update (ifp
);
812 if_nbr_ipv6ll_to_ipv4ll_neigh_add_all (ifp
);
814 /* Enable fast tx of RA if enabled && RA interval is not in msecs */
815 if (zif
->rtadv
.AdvSendAdvertisements
&&
816 (zif
->rtadv
.MaxRtrAdvInterval
>= 1000))
818 zif
->rtadv
.inFastRexmit
= 1;
819 zif
->rtadv
.NumFastReXmitsRemain
= RTADV_NUM_FAST_REXMITS
;
822 /* Install connected routes to the kernel. */
823 if_install_connected (ifp
);
825 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
826 zlog_debug ("%u: IF %s up, scheduling RIB processing",
827 ifp
->vrf_id
, ifp
->name
);
828 rib_update (ifp
->vrf_id
, RIB_UPDATE_IF_CHANGE
);
830 zebra_vrf_static_route_interface_fixup (ifp
);
833 /* Interface goes down. We have to manage different behavior of based
836 if_down (struct interface
*ifp
)
838 struct zebra_if
*zif
;
842 quagga_timestamp (2, zif
->down_last
, sizeof (zif
->down_last
));
844 /* Notify to the protocol daemons. */
845 zebra_interface_down_update (ifp
);
847 /* Uninstall connected routes from the kernel. */
848 if_uninstall_connected (ifp
);
850 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
851 zlog_debug ("%u: IF %s down, scheduling RIB processing",
852 ifp
->vrf_id
, ifp
->name
);
853 rib_update (ifp
->vrf_id
, RIB_UPDATE_IF_CHANGE
);
855 if_nbr_ipv6ll_to_ipv4ll_neigh_del_all (ifp
);
857 /* Delete all neighbor addresses learnt through IPv6 RA */
858 if_down_del_nbr_connected (ifp
);
862 if_refresh (struct interface
*ifp
)
868 /* Output prefix string to vty. */
870 prefix_vty_out (struct vty
*vty
, struct prefix
*p
)
872 char str
[INET6_ADDRSTRLEN
];
874 inet_ntop (p
->family
, &p
->u
.prefix
, str
, sizeof (str
));
875 vty_out (vty
, "%s", str
);
879 /* Dump if address information to vty. */
881 connected_dump_vty (struct vty
*vty
, struct connected
*connected
)
885 /* Print interface address. */
886 p
= connected
->address
;
887 vty_out (vty
, " %s ", prefix_family_str (p
));
888 prefix_vty_out (vty
, p
);
889 vty_out (vty
, "/%d", p
->prefixlen
);
891 /* If there is destination address, print it. */
892 if (connected
->destination
)
894 vty_out (vty
, (CONNECTED_PEER(connected
) ? " peer " : " broadcast "));
895 prefix_vty_out (vty
, connected
->destination
);
898 if (CHECK_FLAG (connected
->flags
, ZEBRA_IFA_SECONDARY
))
899 vty_out (vty
, " secondary");
901 if (CHECK_FLAG (connected
->flags
, ZEBRA_IFA_UNNUMBERED
))
902 vty_out (vty
, " unnumbered");
904 if (connected
->label
)
905 vty_out (vty
, " %s", connected
->label
);
907 vty_out (vty
, "%s", VTY_NEWLINE
);
910 /* Dump interface neighbor address information to vty. */
912 nbr_connected_dump_vty (struct vty
*vty
, struct nbr_connected
*connected
)
916 /* Print interface address. */
917 p
= connected
->address
;
918 vty_out (vty
, " %s ", prefix_family_str (p
));
919 prefix_vty_out (vty
, p
);
920 vty_out (vty
, "/%d", p
->prefixlen
);
922 vty_out (vty
, "%s", VTY_NEWLINE
);
925 #if defined (HAVE_RTADV)
926 /* Dump interface ND information to vty. */
928 nd_dump_vty (struct vty
*vty
, struct interface
*ifp
)
930 struct zebra_if
*zif
;
931 struct rtadvconf
*rtadv
;
934 zif
= (struct zebra_if
*) ifp
->info
;
937 if (rtadv
->AdvSendAdvertisements
)
939 vty_out (vty
, " ND advertised reachable time is %d milliseconds%s",
940 rtadv
->AdvReachableTime
, VTY_NEWLINE
);
941 vty_out (vty
, " ND advertised retransmit interval is %d milliseconds%s",
942 rtadv
->AdvRetransTimer
, VTY_NEWLINE
);
943 vty_out (vty
, " ND router advertisements sent: %d rcvd: %d%s",
944 zif
->ra_sent
, zif
->ra_rcvd
, VTY_NEWLINE
);
945 interval
= rtadv
->MaxRtrAdvInterval
;
947 vty_out (vty
, " ND router advertisements are sent every "
948 "%d milliseconds%s", interval
,
951 vty_out (vty
, " ND router advertisements are sent every "
952 "%d seconds%s", interval
/ 1000,
954 if (rtadv
->AdvDefaultLifetime
!= -1)
955 vty_out (vty
, " ND router advertisements live for %d seconds%s",
956 rtadv
->AdvDefaultLifetime
, VTY_NEWLINE
);
958 vty_out (vty
, " ND router advertisements lifetime tracks ra-interval%s",
960 vty_out (vty
, " ND router advertisement default router preference is "
961 "%s%s", rtadv_pref_strs
[rtadv
->DefaultPreference
],
963 if (rtadv
->AdvManagedFlag
)
964 vty_out (vty
, " Hosts use DHCP to obtain routable addresses.%s",
967 vty_out (vty
, " Hosts use stateless autoconfig for addresses.%s",
969 if (rtadv
->AdvHomeAgentFlag
)
971 vty_out (vty
, " ND router advertisements with "
972 "Home Agent flag bit set.%s",
974 if (rtadv
->HomeAgentLifetime
!= -1)
975 vty_out (vty
, " Home Agent lifetime is %u seconds%s",
976 rtadv
->HomeAgentLifetime
, VTY_NEWLINE
);
978 vty_out (vty
, " Home Agent lifetime tracks ra-lifetime%s",
980 vty_out (vty
, " Home Agent preference is %u%s",
981 rtadv
->HomeAgentPreference
, VTY_NEWLINE
);
983 if (rtadv
->AdvIntervalOption
)
984 vty_out (vty
, " ND router advertisements with Adv. Interval option.%s",
988 #endif /* HAVE_RTADV */
990 /* Interface's information print out to vty interface. */
992 if_dump_vty (struct vty
*vty
, struct interface
*ifp
)
994 struct connected
*connected
;
995 struct nbr_connected
*nbr_connected
;
996 struct listnode
*node
;
997 struct route_node
*rn
;
998 struct zebra_if
*zebra_if
;
1001 zebra_if
= ifp
->info
;
1003 vty_out (vty
, "Interface %s is ", ifp
->name
);
1004 if (if_is_up(ifp
)) {
1005 vty_out (vty
, "up, line protocol ");
1007 if (CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_LINKDETECTION
)) {
1008 if (if_is_running(ifp
))
1009 vty_out (vty
, "is up%s", VTY_NEWLINE
);
1011 vty_out (vty
, "is down%s", VTY_NEWLINE
);
1013 vty_out (vty
, "detection is disabled%s", VTY_NEWLINE
);
1016 vty_out (vty
, "down%s", VTY_NEWLINE
);
1019 vty_out (vty
, " Link ups: %5u last: %s%s", zebra_if
->up_count
,
1020 zebra_if
->up_last
[0] ? zebra_if
->up_last
: "(never)", VTY_NEWLINE
);
1021 vty_out (vty
, " Link downs: %5u last: %s%s", zebra_if
->down_count
,
1022 zebra_if
->down_last
[0] ? zebra_if
->down_last
: "(never)", VTY_NEWLINE
);
1024 zebra_ptm_show_status(vty
, ifp
);
1026 vrf
= vrf_lookup(ifp
->vrf_id
);
1027 vty_out (vty
, " vrf: %s%s", vrf
->name
, VTY_NEWLINE
);
1030 vty_out (vty
, " Description: %s%s", ifp
->desc
,
1032 if (ifp
->ifindex
== IFINDEX_INTERNAL
)
1034 vty_out(vty
, " pseudo interface%s", VTY_NEWLINE
);
1037 else if (! CHECK_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
))
1039 vty_out(vty
, " index %d inactive interface%s",
1045 vty_out (vty
, " index %d metric %d mtu %d ",
1046 ifp
->ifindex
, ifp
->metric
, ifp
->mtu
);
1048 if (ifp
->mtu6
!= ifp
->mtu
)
1049 vty_out (vty
, "mtu6 %d ", ifp
->mtu6
);
1051 vty_out (vty
, "%s flags: %s%s", VTY_NEWLINE
,
1052 if_flag_dump (ifp
->flags
), VTY_NEWLINE
);
1054 /* Hardware address. */
1055 vty_out (vty
, " Type: %s%s", if_link_type_str (ifp
->ll_type
), VTY_NEWLINE
);
1056 if (ifp
->hw_addr_len
!= 0)
1060 vty_out (vty
, " HWaddr: ");
1061 for (i
= 0; i
< ifp
->hw_addr_len
; i
++)
1062 vty_out (vty
, "%s%02x", i
== 0 ? "" : ":", ifp
->hw_addr
[i
]);
1063 vty_out (vty
, "%s", VTY_NEWLINE
);
1066 /* Bandwidth in Mbps */
1067 if (ifp
->bandwidth
!= 0)
1069 vty_out(vty
, " bandwidth %u Mbps", ifp
->bandwidth
);
1070 vty_out(vty
, "%s", VTY_NEWLINE
);
1073 for (rn
= route_top (zebra_if
->ipv4_subnets
); rn
; rn
= route_next (rn
))
1078 for (ALL_LIST_ELEMENTS_RO ((struct list
*)rn
->info
, node
, connected
))
1079 connected_dump_vty (vty
, connected
);
1082 for (ALL_LIST_ELEMENTS_RO (ifp
->connected
, node
, connected
))
1084 if (CHECK_FLAG (connected
->conf
, ZEBRA_IFC_REAL
) &&
1085 (connected
->address
->family
== AF_INET6
))
1086 connected_dump_vty (vty
, connected
);
1089 #if defined (HAVE_RTADV)
1090 nd_dump_vty (vty
, ifp
);
1091 #endif /* HAVE_RTADV */
1092 if (listhead(ifp
->nbr_connected
))
1093 vty_out (vty
, " Neighbor address(s):%s", VTY_NEWLINE
);
1094 for (ALL_LIST_ELEMENTS_RO (ifp
->nbr_connected
, node
, nbr_connected
))
1095 nbr_connected_dump_vty (vty
, nbr_connected
);
1097 #ifdef HAVE_PROC_NET_DEV
1098 /* Statistics print out using proc file system. */
1099 vty_out (vty
, " %lu input packets (%lu multicast), %lu bytes, "
1101 ifp
->stats
.rx_packets
, ifp
->stats
.rx_multicast
,
1102 ifp
->stats
.rx_bytes
, ifp
->stats
.rx_dropped
, VTY_NEWLINE
);
1104 vty_out (vty
, " %lu input errors, %lu length, %lu overrun,"
1105 " %lu CRC, %lu frame%s",
1106 ifp
->stats
.rx_errors
, ifp
->stats
.rx_length_errors
,
1107 ifp
->stats
.rx_over_errors
, ifp
->stats
.rx_crc_errors
,
1108 ifp
->stats
.rx_frame_errors
, VTY_NEWLINE
);
1110 vty_out (vty
, " %lu fifo, %lu missed%s", ifp
->stats
.rx_fifo_errors
,
1111 ifp
->stats
.rx_missed_errors
, VTY_NEWLINE
);
1113 vty_out (vty
, " %lu output packets, %lu bytes, %lu dropped%s",
1114 ifp
->stats
.tx_packets
, ifp
->stats
.tx_bytes
,
1115 ifp
->stats
.tx_dropped
, VTY_NEWLINE
);
1117 vty_out (vty
, " %lu output errors, %lu aborted, %lu carrier,"
1118 " %lu fifo, %lu heartbeat%s",
1119 ifp
->stats
.tx_errors
, ifp
->stats
.tx_aborted_errors
,
1120 ifp
->stats
.tx_carrier_errors
, ifp
->stats
.tx_fifo_errors
,
1121 ifp
->stats
.tx_heartbeat_errors
, VTY_NEWLINE
);
1123 vty_out (vty
, " %lu window, %lu collisions%s",
1124 ifp
->stats
.tx_window_errors
, ifp
->stats
.collisions
, VTY_NEWLINE
);
1125 #endif /* HAVE_PROC_NET_DEV */
1127 #ifdef HAVE_NET_RT_IFLIST
1128 #if defined (__bsdi__) || defined (__NetBSD__)
1129 /* Statistics print out using sysctl (). */
1130 vty_out (vty
, " input packets %llu, bytes %llu, dropped %llu,"
1131 " multicast packets %llu%s",
1132 (unsigned long long)ifp
->stats
.ifi_ipackets
,
1133 (unsigned long long)ifp
->stats
.ifi_ibytes
,
1134 (unsigned long long)ifp
->stats
.ifi_iqdrops
,
1135 (unsigned long long)ifp
->stats
.ifi_imcasts
,
1138 vty_out (vty
, " input errors %llu%s",
1139 (unsigned long long)ifp
->stats
.ifi_ierrors
, VTY_NEWLINE
);
1141 vty_out (vty
, " output packets %llu, bytes %llu,"
1142 " multicast packets %llu%s",
1143 (unsigned long long)ifp
->stats
.ifi_opackets
,
1144 (unsigned long long)ifp
->stats
.ifi_obytes
,
1145 (unsigned long long)ifp
->stats
.ifi_omcasts
,
1148 vty_out (vty
, " output errors %llu%s",
1149 (unsigned long long)ifp
->stats
.ifi_oerrors
, VTY_NEWLINE
);
1151 vty_out (vty
, " collisions %llu%s",
1152 (unsigned long long)ifp
->stats
.ifi_collisions
, VTY_NEWLINE
);
1154 /* Statistics print out using sysctl (). */
1155 vty_out (vty
, " input packets %lu, bytes %lu, dropped %lu,"
1156 " multicast packets %lu%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 %lu%s",
1162 ifp
->stats
.ifi_ierrors
, VTY_NEWLINE
);
1164 vty_out (vty
, " output packets %lu, bytes %lu, multicast packets %lu%s",
1165 ifp
->stats
.ifi_opackets
, ifp
->stats
.ifi_obytes
,
1166 ifp
->stats
.ifi_omcasts
, VTY_NEWLINE
);
1168 vty_out (vty
, " output errors %lu%s",
1169 ifp
->stats
.ifi_oerrors
, VTY_NEWLINE
);
1171 vty_out (vty
, " collisions %lu%s",
1172 ifp
->stats
.ifi_collisions
, VTY_NEWLINE
);
1173 #endif /* __bsdi__ || __NetBSD__ */
1174 #endif /* HAVE_NET_RT_IFLIST */
1177 /* Wrapper hook point for zebra daemon so that ifindex can be set
1178 * DEFUN macro not used as extract.pl HAS to ignore this
1179 * See also interface_cmd in lib/if.c
1181 DEFUN_NOSH (zebra_interface
,
1182 zebra_interface_cmd
,
1184 "Select an interface to configure\n"
1185 "Interface's name\n")
1188 struct interface
* ifp
;
1190 /* Call lib interface() */
1191 if ((ret
= interface_cmd
.func (self
, vty
, argc
, argv
)) != CMD_SUCCESS
)
1196 if (ifp
->ifindex
== IFINDEX_INTERNAL
)
1197 /* Is this really necessary? Shouldn't status be initialized to 0
1199 UNSET_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
);
1204 ALIAS (zebra_interface
,
1205 zebra_interface_vrf_cmd
,
1206 "interface IFNAME " VRF_CMD_STR
,
1207 "Select an interface to configure\n"
1208 "Interface's name\n"
1211 struct cmd_node interface_node
=
1218 /* Wrapper hook point for zebra daemon so that ifindex can be set
1219 * DEFUN macro not used as extract.pl HAS to ignore this
1220 * See also interface_cmd in lib/if.c
1222 DEFUN_NOSH (zebra_vrf
,
1225 "Select a VRF to configure\n"
1230 /* Call lib vrf() */
1231 if ((ret
= vrf_cmd
.func (self
, vty
, argc
, argv
)) != CMD_SUCCESS
)
1234 // vrfp = vty->index;
1239 struct cmd_node vrf_node
=
1246 /* Show all interfaces to vty. */
1247 DEFUN (show_interface
, show_interface_cmd
,
1250 "Interface status and configuration\n")
1252 struct listnode
*node
;
1253 struct interface
*ifp
;
1254 vrf_id_t vrf_id
= VRF_DEFAULT
;
1256 #ifdef HAVE_PROC_NET_DEV
1257 /* If system has interface statistics via proc file system, update
1259 ifstat_update_proc ();
1260 #endif /* HAVE_PROC_NET_DEV */
1261 #ifdef HAVE_NET_RT_IFLIST
1262 ifstat_update_sysctl ();
1263 #endif /* HAVE_NET_RT_IFLIST */
1266 VRF_GET_ID (vrf_id
, argv
[0]);
1268 /* All interface print. */
1269 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (vrf_id
), node
, ifp
))
1270 if_dump_vty (vty
, ifp
);
1275 ALIAS (show_interface
,
1276 show_interface_vrf_cmd
,
1277 "show interface " VRF_CMD_STR
,
1279 "Interface status and configuration\n"
1282 /* Show all interfaces to vty. */
1283 DEFUN (show_interface_vrf_all
, show_interface_vrf_all_cmd
,
1284 "show interface " VRF_ALL_CMD_STR
,
1286 "Interface status and configuration\n"
1287 VRF_ALL_CMD_HELP_STR
)
1289 struct listnode
*node
;
1290 struct interface
*ifp
;
1293 #ifdef HAVE_PROC_NET_DEV
1294 /* If system has interface statistics via proc file system, update
1296 ifstat_update_proc ();
1297 #endif /* HAVE_PROC_NET_DEV */
1298 #ifdef HAVE_NET_RT_IFLIST
1299 ifstat_update_sysctl ();
1300 #endif /* HAVE_NET_RT_IFLIST */
1302 /* All interface print. */
1303 for (iter
= vrf_first (); iter
!= VRF_ITER_INVALID
; iter
= vrf_next (iter
))
1304 for (ALL_LIST_ELEMENTS_RO (vrf_iter2iflist (iter
), node
, ifp
))
1305 if_dump_vty (vty
, ifp
);
1310 /* Show specified interface to vty. */
1312 DEFUN (show_interface_name_vrf
,
1313 show_interface_name_vrf_cmd
,
1314 "show interface IFNAME " VRF_CMD_STR
,
1316 "Interface status and configuration\n"
1320 struct interface
*ifp
;
1321 vrf_id_t vrf_id
= VRF_DEFAULT
;
1323 #ifdef HAVE_PROC_NET_DEV
1324 /* If system has interface statistics via proc file system, update
1326 ifstat_update_proc ();
1327 #endif /* HAVE_PROC_NET_DEV */
1328 #ifdef HAVE_NET_RT_IFLIST
1329 ifstat_update_sysctl ();
1330 #endif /* HAVE_NET_RT_IFLIST */
1333 VRF_GET_ID (vrf_id
, argv
[1]);
1335 /* Specified interface print. */
1336 ifp
= if_lookup_by_name_vrf (argv
[0], vrf_id
);
1339 vty_out (vty
, "%% Can't find interface %s%s", argv
[0],
1343 if_dump_vty (vty
, ifp
);
1348 /* Show specified interface to vty. */
1349 DEFUN (show_interface_name_vrf_all
, show_interface_name_vrf_all_cmd
,
1350 "show interface IFNAME " VRF_ALL_CMD_STR
,
1352 "Interface status and configuration\n"
1354 VRF_ALL_CMD_HELP_STR
)
1356 struct interface
*ifp
;
1360 #ifdef HAVE_PROC_NET_DEV
1361 /* If system has interface statistics via proc file system, update
1363 ifstat_update_proc ();
1364 #endif /* HAVE_PROC_NET_DEV */
1365 #ifdef HAVE_NET_RT_IFLIST
1366 ifstat_update_sysctl ();
1367 #endif /* HAVE_NET_RT_IFLIST */
1369 /* All interface print. */
1370 for (iter
= vrf_first (); iter
!= VRF_ITER_INVALID
; iter
= vrf_next (iter
))
1372 /* Specified interface print. */
1373 ifp
= if_lookup_by_name_vrf (argv
[0], vrf_iter2id (iter
));
1376 if_dump_vty (vty
, ifp
);
1383 vty_out (vty
, "%% Can't find interface %s%s", argv
[0], VTY_NEWLINE
);
1390 ALIAS (show_interface_name_vrf_all
, show_interface_name_cmd
,
1391 "show interface IFNAME",
1393 "Interface status and configuration\n"
1397 if_show_description (struct vty
*vty
, vrf_id_t vrf_id
)
1399 struct listnode
*node
;
1400 struct interface
*ifp
;
1402 vty_out (vty
, "Interface Status Protocol Description%s", VTY_NEWLINE
);
1403 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (vrf_id
), node
, ifp
))
1407 len
= vty_out (vty
, "%s", ifp
->name
);
1408 vty_out (vty
, "%*s", (16 - len
), " ");
1412 vty_out (vty
, "up ");
1413 if (CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_LINKDETECTION
))
1415 if (if_is_running(ifp
))
1416 vty_out (vty
, "up ");
1418 vty_out (vty
, "down ");
1422 vty_out (vty
, "unknown ");
1427 vty_out (vty
, "down down ");
1431 vty_out (vty
, "%s", ifp
->desc
);
1432 vty_out (vty
, "%s", VTY_NEWLINE
);
1436 DEFUN (show_interface_desc
,
1437 show_interface_desc_cmd
,
1438 "show interface description",
1440 "Interface status and configuration\n"
1441 "Interface description\n")
1443 vrf_id_t vrf_id
= VRF_DEFAULT
;
1446 VRF_GET_ID (vrf_id
, argv
[0]);
1448 if_show_description (vty
, vrf_id
);
1453 ALIAS (show_interface_desc
,
1454 show_interface_desc_vrf_cmd
,
1455 "show interface description " VRF_CMD_STR
,
1457 "Interface status and configuration\n"
1458 "Interface description\n"
1461 DEFUN (show_interface_desc_vrf_all
,
1462 show_interface_desc_vrf_all_cmd
,
1463 "show interface description " VRF_ALL_CMD_STR
,
1465 "Interface status and configuration\n"
1466 "Interface description\n"
1467 VRF_ALL_CMD_HELP_STR
)
1471 for (iter
= vrf_first (); iter
!= VRF_ITER_INVALID
; iter
= vrf_next (iter
))
1472 if (!list_isempty (vrf_iter2iflist (iter
)))
1474 vty_out (vty
, "%s\tVRF %u%s%s", VTY_NEWLINE
,
1476 VTY_NEWLINE
, VTY_NEWLINE
);
1477 if_show_description (vty
, vrf_iter2id (iter
));
1486 "Set multicast flag to interface\n")
1489 struct interface
*ifp
;
1490 struct zebra_if
*if_data
;
1492 ifp
= (struct interface
*) vty
->index
;
1493 if (CHECK_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
))
1495 ret
= if_set_flags (ifp
, IFF_MULTICAST
);
1498 vty_out (vty
, "Can't set multicast flag%s", VTY_NEWLINE
);
1503 if_data
= ifp
->info
;
1504 if_data
->multicast
= IF_ZEBRA_MULTICAST_ON
;
1509 DEFUN (no_multicast
,
1513 "Unset multicast flag to interface\n")
1516 struct interface
*ifp
;
1517 struct zebra_if
*if_data
;
1519 ifp
= (struct interface
*) vty
->index
;
1520 if (CHECK_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
))
1522 ret
= if_unset_flags (ifp
, IFF_MULTICAST
);
1525 vty_out (vty
, "Can't unset multicast flag%s", VTY_NEWLINE
);
1530 if_data
= ifp
->info
;
1531 if_data
->multicast
= IF_ZEBRA_MULTICAST_OFF
;
1539 "Enable link detection on interface\n")
1541 struct interface
*ifp
;
1542 int if_was_operative
;
1544 ifp
= (struct interface
*) vty
->index
;
1545 if_was_operative
= if_is_no_ptm_operative(ifp
);
1546 SET_FLAG(ifp
->status
, ZEBRA_INTERFACE_LINKDETECTION
);
1548 /* When linkdetection is enabled, if might come down */
1549 if (!if_is_no_ptm_operative(ifp
) && if_was_operative
) if_down(ifp
);
1551 /* FIXME: Will defer status change forwarding if interface
1552 does not come down! */
1558 DEFUN (no_linkdetect
,
1562 "Disable link detection on interface\n")
1564 struct interface
*ifp
;
1565 int if_was_operative
;
1567 ifp
= (struct interface
*) vty
->index
;
1568 if_was_operative
= if_is_no_ptm_operative(ifp
);
1569 UNSET_FLAG(ifp
->status
, ZEBRA_INTERFACE_LINKDETECTION
);
1571 /* Interface may come up after disabling link detection */
1572 if (if_is_operative(ifp
) && !if_was_operative
) if_up(ifp
);
1574 /* FIXME: see linkdetect_cmd */
1582 "Shutdown the selected interface\n")
1585 struct interface
*ifp
;
1586 struct zebra_if
*if_data
;
1588 ifp
= (struct interface
*) vty
->index
;
1589 if (ifp
->ifindex
!= IFINDEX_INTERNAL
)
1591 ret
= if_unset_flags (ifp
, IFF_UP
);
1594 vty_out (vty
, "Can't shutdown interface%s", VTY_NEWLINE
);
1599 if_data
= ifp
->info
;
1600 if_data
->shutdown
= IF_ZEBRA_SHUTDOWN_ON
;
1605 DEFUN (no_shutdown_if
,
1609 "Shutdown the selected interface\n")
1612 struct interface
*ifp
;
1613 struct zebra_if
*if_data
;
1615 ifp
= (struct interface
*) vty
->index
;
1617 if (ifp
->ifindex
!= IFINDEX_INTERNAL
)
1619 ret
= if_set_flags (ifp
, IFF_UP
| IFF_RUNNING
);
1622 vty_out (vty
, "Can't up interface%s", VTY_NEWLINE
);
1627 /* Some addresses (in particular, IPv6 addresses on Linux) get
1628 * removed when the interface goes down. They need to be readded.
1630 if_addr_wakeup(ifp
);
1633 if_data
= ifp
->info
;
1634 if_data
->shutdown
= IF_ZEBRA_SHUTDOWN_OFF
;
1639 DEFUN (bandwidth_if
,
1641 "bandwidth <1-100000>",
1642 "Set bandwidth informational parameter\n"
1643 "Bandwidth in megabits\n")
1645 struct interface
*ifp
;
1646 unsigned int bandwidth
;
1648 ifp
= (struct interface
*) vty
->index
;
1649 bandwidth
= strtol(argv
[0], NULL
, 10);
1651 /* bandwidth range is <1-100000> */
1652 if (bandwidth
< 1 || bandwidth
> 100000)
1654 vty_out (vty
, "Bandwidth is invalid%s", VTY_NEWLINE
);
1658 ifp
->bandwidth
= bandwidth
;
1660 /* force protocols to recalculate routes due to cost change */
1661 if (if_is_operative (ifp
))
1662 zebra_interface_up_update (ifp
);
1667 DEFUN (no_bandwidth_if
,
1668 no_bandwidth_if_cmd
,
1671 "Set bandwidth informational parameter\n")
1673 struct interface
*ifp
;
1675 ifp
= (struct interface
*) vty
->index
;
1679 /* force protocols to recalculate routes due to cost change */
1680 if (if_is_operative (ifp
))
1681 zebra_interface_up_update (ifp
);
1686 ALIAS (no_bandwidth_if
,
1687 no_bandwidth_if_val_cmd
,
1688 "no bandwidth <1-100000>",
1690 "Set bandwidth informational parameter\n"
1691 "Bandwidth in megabits\n")
1694 ip_address_install (struct vty
*vty
, struct interface
*ifp
,
1695 const char *addr_str
, const char *peer_str
,
1698 struct zebra_if
*if_data
;
1699 struct prefix_ipv4 cp
;
1700 struct connected
*ifc
;
1701 struct prefix_ipv4
*p
;
1704 if_data
= ifp
->info
;
1706 ret
= str2prefix_ipv4 (addr_str
, &cp
);
1709 vty_out (vty
, "%% Malformed address %s", VTY_NEWLINE
);
1713 if (ipv4_martian(&cp
.prefix
))
1715 vty_out (vty
, "%% Invalid address%s", VTY_NEWLINE
);
1719 ifc
= connected_check (ifp
, (struct prefix
*) &cp
);
1722 ifc
= connected_new ();
1726 p
= prefix_ipv4_new ();
1728 ifc
->address
= (struct prefix
*) p
;
1731 if (p
->prefixlen
<= IPV4_MAX_PREFIXLEN
-2)
1733 p
= prefix_ipv4_new ();
1735 p
->prefix
.s_addr
= ipv4_broadcast_addr(p
->prefix
.s_addr
,p
->prefixlen
);
1736 ifc
->destination
= (struct prefix
*) p
;
1741 ifc
->label
= XSTRDUP (MTYPE_CONNECTED_LABEL
, label
);
1743 /* Add to linked list. */
1744 listnode_add (ifp
->connected
, ifc
);
1747 /* This address is configured from zebra. */
1748 if (! CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
1749 SET_FLAG (ifc
->conf
, ZEBRA_IFC_CONFIGURED
);
1751 /* In case of this route need to install kernel. */
1752 if (! CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_QUEUED
)
1753 && CHECK_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
)
1754 && !(if_data
&& if_data
->shutdown
== IF_ZEBRA_SHUTDOWN_ON
))
1756 /* Some system need to up the interface to set IP address. */
1757 if (! if_is_up (ifp
))
1759 if_set_flags (ifp
, IFF_UP
| IFF_RUNNING
);
1763 ret
= if_set_prefix (ifp
, ifc
);
1766 vty_out (vty
, "%% Can't set interface IP address: %s.%s",
1767 safe_strerror(errno
), VTY_NEWLINE
);
1771 SET_FLAG (ifc
->conf
, ZEBRA_IFC_QUEUED
);
1772 /* The address will be advertised to zebra clients when the notification
1773 * from the kernel has been received.
1774 * It will also be added to the subnet chain list, then. */
1781 ip_address_uninstall (struct vty
*vty
, struct interface
*ifp
,
1782 const char *addr_str
, const char *peer_str
,
1785 struct prefix_ipv4 cp
;
1786 struct connected
*ifc
;
1789 /* Convert to prefix structure. */
1790 ret
= str2prefix_ipv4 (addr_str
, &cp
);
1793 vty_out (vty
, "%% Malformed address %s", VTY_NEWLINE
);
1797 /* Check current interface address. */
1798 ifc
= connected_check (ifp
, (struct prefix
*) &cp
);
1801 vty_out (vty
, "%% Can't find address%s", VTY_NEWLINE
);
1805 /* This is not configured address. */
1806 if (! CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
1809 UNSET_FLAG (ifc
->conf
, ZEBRA_IFC_CONFIGURED
);
1811 /* This is not real address or interface is not active. */
1812 if (! CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_QUEUED
)
1813 || ! CHECK_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
))
1815 listnode_delete (ifp
->connected
, ifc
);
1816 connected_free (ifc
);
1820 /* This is real route. */
1821 ret
= if_unset_prefix (ifp
, ifc
);
1824 vty_out (vty
, "%% Can't unset interface IP address: %s.%s",
1825 safe_strerror(errno
), VTY_NEWLINE
);
1828 UNSET_FLAG (ifc
->conf
, ZEBRA_IFC_QUEUED
);
1829 /* we will receive a kernel notification about this route being removed.
1830 * this will trigger its removal from the connected list. */
1836 "ip address A.B.C.D/M",
1837 "Interface Internet Protocol config commands\n"
1838 "Set the IP address of an interface\n"
1839 "IP address (e.g. 10.0.0.1/8)\n")
1841 return ip_address_install (vty
, vty
->index
, argv
[0], NULL
, NULL
);
1844 DEFUN (no_ip_address
,
1846 "no ip address A.B.C.D/M",
1848 "Interface Internet Protocol config commands\n"
1849 "Set the IP address of an interface\n"
1850 "IP Address (e.g. 10.0.0.1/8)")
1852 return ip_address_uninstall (vty
, vty
->index
, argv
[0], NULL
, NULL
);
1857 DEFUN (ip_address_label
,
1858 ip_address_label_cmd
,
1859 "ip address A.B.C.D/M label LINE",
1860 "Interface Internet Protocol config commands\n"
1861 "Set the IP address of an interface\n"
1862 "IP address (e.g. 10.0.0.1/8)\n"
1863 "Label of this address\n"
1866 return ip_address_install (vty
, vty
->index
, argv
[0], NULL
, argv
[1]);
1869 DEFUN (no_ip_address_label
,
1870 no_ip_address_label_cmd
,
1871 "no ip address A.B.C.D/M label LINE",
1873 "Interface Internet Protocol config commands\n"
1874 "Set the IP address of an interface\n"
1875 "IP address (e.g. 10.0.0.1/8)\n"
1876 "Label of this address\n"
1879 return ip_address_uninstall (vty
, vty
->index
, argv
[0], NULL
, argv
[1]);
1881 #endif /* HAVE_NETLINK */
1885 ipv6_address_install (struct vty
*vty
, struct interface
*ifp
,
1886 const char *addr_str
, const char *peer_str
,
1887 const char *label
, int secondary
)
1889 struct zebra_if
*if_data
;
1890 struct prefix_ipv6 cp
;
1891 struct connected
*ifc
;
1892 struct prefix_ipv6
*p
;
1895 if_data
= ifp
->info
;
1897 ret
= str2prefix_ipv6 (addr_str
, &cp
);
1900 vty_out (vty
, "%% Malformed address %s", VTY_NEWLINE
);
1904 if (ipv6_martian(&cp
.prefix
))
1906 vty_out (vty
, "%% Invalid address%s", VTY_NEWLINE
);
1910 ifc
= connected_check (ifp
, (struct prefix
*) &cp
);
1913 ifc
= connected_new ();
1917 p
= prefix_ipv6_new ();
1919 ifc
->address
= (struct prefix
*) p
;
1923 SET_FLAG (ifc
->flags
, ZEBRA_IFA_SECONDARY
);
1927 ifc
->label
= XSTRDUP (MTYPE_CONNECTED_LABEL
, label
);
1929 /* Add to linked list. */
1930 listnode_add (ifp
->connected
, ifc
);
1933 /* This address is configured from zebra. */
1934 if (! CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
1935 SET_FLAG (ifc
->conf
, ZEBRA_IFC_CONFIGURED
);
1937 /* In case of this route need to install kernel. */
1938 if (! CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_QUEUED
)
1939 && CHECK_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
)
1940 && !(if_data
&& if_data
->shutdown
== IF_ZEBRA_SHUTDOWN_ON
))
1942 /* Some system need to up the interface to set IP address. */
1943 if (! if_is_up (ifp
))
1945 if_set_flags (ifp
, IFF_UP
| IFF_RUNNING
);
1949 ret
= if_prefix_add_ipv6 (ifp
, ifc
);
1953 vty_out (vty
, "%% Can't set interface IP address: %s.%s",
1954 safe_strerror(errno
), VTY_NEWLINE
);
1958 SET_FLAG (ifc
->conf
, ZEBRA_IFC_QUEUED
);
1959 /* The address will be advertised to zebra clients when the notification
1960 * from the kernel has been received. */
1966 /* Return true if an ipv6 address is configured on ifp */
1968 ipv6_address_configured (struct interface
*ifp
)
1970 struct connected
*connected
;
1971 struct listnode
*node
;
1973 for (ALL_LIST_ELEMENTS_RO (ifp
->connected
, node
, connected
))
1974 if (CHECK_FLAG (connected
->conf
, ZEBRA_IFC_REAL
) && (connected
->address
->family
== AF_INET6
))
1981 ipv6_address_uninstall (struct vty
*vty
, struct interface
*ifp
,
1982 const char *addr_str
, const char *peer_str
,
1983 const char *label
, int secondry
)
1985 struct prefix_ipv6 cp
;
1986 struct connected
*ifc
;
1989 /* Convert to prefix structure. */
1990 ret
= str2prefix_ipv6 (addr_str
, &cp
);
1993 vty_out (vty
, "%% Malformed address %s", VTY_NEWLINE
);
1997 /* Check current interface address. */
1998 ifc
= connected_check (ifp
, (struct prefix
*) &cp
);
2001 vty_out (vty
, "%% Can't find address%s", VTY_NEWLINE
);
2005 /* This is not configured address. */
2006 if (! CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
2009 UNSET_FLAG (ifc
->conf
, ZEBRA_IFC_CONFIGURED
);
2011 /* This is not real address or interface is not active. */
2012 if (! CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_QUEUED
)
2013 || ! CHECK_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
))
2015 listnode_delete (ifp
->connected
, ifc
);
2016 connected_free (ifc
);
2020 /* This is real route. */
2021 ret
= if_prefix_delete_ipv6 (ifp
, ifc
);
2024 vty_out (vty
, "%% Can't unset interface IP address: %s.%s",
2025 safe_strerror(errno
), VTY_NEWLINE
);
2029 UNSET_FLAG (ifc
->conf
, ZEBRA_IFC_QUEUED
);
2030 /* This information will be propagated to the zclients when the
2031 * kernel notification is received. */
2035 DEFUN (ipv6_address
,
2037 "ipv6 address X:X::X:X/M",
2038 "Interface IPv6 config commands\n"
2039 "Set the IP address of an interface\n"
2040 "IPv6 address (e.g. 3ffe:506::1/48)\n")
2042 return ipv6_address_install (vty
, vty
->index
, argv
[0], NULL
, NULL
, 0);
2045 DEFUN (no_ipv6_address
,
2046 no_ipv6_address_cmd
,
2047 "no ipv6 address X:X::X:X/M",
2049 "Interface IPv6 config commands\n"
2050 "Set the IP address of an interface\n"
2051 "IPv6 address (e.g. 3ffe:506::1/48)\n")
2053 return ipv6_address_uninstall (vty
, vty
->index
, argv
[0], NULL
, NULL
, 0);
2055 #endif /* HAVE_IPV6 */
2058 if_config_write (struct vty
*vty
)
2060 struct listnode
*node
;
2061 struct interface
*ifp
;
2064 zebra_ptm_write (vty
);
2066 for (iter
= vrf_first (); iter
!= VRF_ITER_INVALID
; iter
= vrf_next (iter
))
2067 for (ALL_LIST_ELEMENTS_RO (vrf_iter2iflist (iter
), node
, ifp
))
2069 struct zebra_if
*if_data
;
2070 struct listnode
*addrnode
;
2071 struct connected
*ifc
;
2075 if_data
= ifp
->info
;
2076 vrf
= vrf_lookup(ifp
->vrf_id
);
2078 if (ifp
->vrf_id
== VRF_DEFAULT
)
2079 vty_out (vty
, "interface %s%s", ifp
->name
, VTY_NEWLINE
);
2081 vty_out (vty
, "interface %s vrf %s%s", ifp
->name
, vrf
->name
,
2086 if (if_data
->shutdown
== IF_ZEBRA_SHUTDOWN_ON
)
2087 vty_out (vty
, " shutdown%s", VTY_NEWLINE
);
2089 zebra_ptm_if_write(vty
, if_data
);
2093 vty_out (vty
, " description %s%s", ifp
->desc
,
2096 /* Assign bandwidth here to avoid unnecessary interface flap
2097 while processing config script */
2098 if (ifp
->bandwidth
!= 0)
2099 vty_out(vty
, " bandwidth %u%s", ifp
->bandwidth
, VTY_NEWLINE
);
2101 if (!CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_LINKDETECTION
))
2102 vty_out(vty
, " no link-detect%s", VTY_NEWLINE
);
2104 for (ALL_LIST_ELEMENTS_RO (ifp
->connected
, addrnode
, ifc
))
2106 if (CHECK_FLAG (ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
2108 char buf
[INET6_ADDRSTRLEN
];
2110 vty_out (vty
, " ip%s address %s",
2111 p
->family
== AF_INET
? "" : "v6",
2112 prefix2str (p
, buf
, sizeof(buf
)));
2115 vty_out (vty
, " label %s", ifc
->label
);
2117 vty_out (vty
, "%s", VTY_NEWLINE
);
2123 if (if_data
->multicast
!= IF_ZEBRA_MULTICAST_UNSPEC
)
2124 vty_out (vty
, " %smulticast%s",
2125 if_data
->multicast
== IF_ZEBRA_MULTICAST_ON
? "" : "no ",
2129 #if defined (HAVE_RTADV)
2130 rtadv_config_write (vty
, ifp
);
2131 #endif /* HAVE_RTADV */
2134 irdp_config_write (vty
, ifp
);
2137 vty_out (vty
, "!%s", VTY_NEWLINE
);
2143 vrf_config_write (struct vty
*vty
)
2145 struct listnode
*node
;
2146 struct zebra_vrf
*zvrf
;
2148 for (ALL_LIST_ELEMENTS_RO (zvrf_list
, node
, zvrf
))
2150 if (strcmp(zvrf
->name
, VRF_DEFAULT_NAME
))
2152 vty_out (vty
, "vrf %s%s", zvrf
->name
, VTY_NEWLINE
);
2153 vty_out (vty
, "!%s", VTY_NEWLINE
);
2159 /* Allocate and initialize interface vector. */
2161 zebra_if_init (void)
2163 /* Initialize interface and new hook. */
2164 if_add_hook (IF_NEW_HOOK
, if_zebra_new_hook
);
2165 if_add_hook (IF_DELETE_HOOK
, if_zebra_delete_hook
);
2167 /* Install configuration write function. */
2168 install_node (&interface_node
, if_config_write
);
2169 install_node (&vrf_node
, vrf_config_write
);
2171 install_element (VIEW_NODE
, &show_interface_cmd
);
2172 install_element (VIEW_NODE
, &show_interface_vrf_cmd
);
2173 install_element (VIEW_NODE
, &show_interface_vrf_all_cmd
);
2174 install_element (VIEW_NODE
, &show_interface_name_cmd
);
2175 install_element (VIEW_NODE
, &show_interface_name_vrf_cmd
);
2176 install_element (VIEW_NODE
, &show_interface_name_vrf_all_cmd
);
2177 install_element (ENABLE_NODE
, &show_interface_cmd
);
2178 install_element (ENABLE_NODE
, &show_interface_vrf_cmd
);
2179 install_element (ENABLE_NODE
, &show_interface_vrf_all_cmd
);
2180 install_element (ENABLE_NODE
, &show_interface_name_cmd
);
2181 install_element (ENABLE_NODE
, &show_interface_name_vrf_cmd
);
2182 install_element (ENABLE_NODE
, &show_interface_name_vrf_all_cmd
);
2183 install_element (ENABLE_NODE
, &show_interface_desc_cmd
);
2184 install_element (ENABLE_NODE
, &show_interface_desc_vrf_cmd
);
2185 install_element (ENABLE_NODE
, &show_interface_desc_vrf_all_cmd
);
2186 install_element (CONFIG_NODE
, &zebra_interface_cmd
);
2187 install_element (CONFIG_NODE
, &zebra_interface_vrf_cmd
);
2188 install_element (CONFIG_NODE
, &no_interface_cmd
);
2189 install_element (CONFIG_NODE
, &no_interface_vrf_cmd
);
2190 install_default (INTERFACE_NODE
);
2191 install_element (INTERFACE_NODE
, &interface_desc_cmd
);
2192 install_element (INTERFACE_NODE
, &no_interface_desc_cmd
);
2193 install_element (INTERFACE_NODE
, &multicast_cmd
);
2194 install_element (INTERFACE_NODE
, &no_multicast_cmd
);
2195 install_element (INTERFACE_NODE
, &linkdetect_cmd
);
2196 install_element (INTERFACE_NODE
, &no_linkdetect_cmd
);
2197 install_element (INTERFACE_NODE
, &shutdown_if_cmd
);
2198 install_element (INTERFACE_NODE
, &no_shutdown_if_cmd
);
2199 install_element (INTERFACE_NODE
, &bandwidth_if_cmd
);
2200 install_element (INTERFACE_NODE
, &no_bandwidth_if_cmd
);
2201 install_element (INTERFACE_NODE
, &no_bandwidth_if_val_cmd
);
2202 install_element (INTERFACE_NODE
, &ip_address_cmd
);
2203 install_element (INTERFACE_NODE
, &no_ip_address_cmd
);
2205 install_element (INTERFACE_NODE
, &ipv6_address_cmd
);
2206 install_element (INTERFACE_NODE
, &no_ipv6_address_cmd
);
2207 #endif /* HAVE_IPV6 */
2209 install_element (INTERFACE_NODE
, &ip_address_label_cmd
);
2210 install_element (INTERFACE_NODE
, &no_ip_address_label_cmd
);
2211 #endif /* HAVE_NETLINK */
2213 install_element (CONFIG_NODE
, &zebra_vrf_cmd
);
2214 install_element (CONFIG_NODE
, &no_vrf_cmd
);
2215 install_default (VRF_NODE
);