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 along
18 * with this program; see the file COPYING; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 #include "lib_errors.h"
27 #include "sockunion.h"
31 #include "zebra_memory.h"
33 #include "connected.h"
38 #include "zebra/rtadv.h"
40 #include "zebra_vrf.h"
41 #include "zebra/interface.h"
42 #include "zebra/rib.h"
44 #include "zebra/zebra_router.h"
45 #include "zebra/redistribute.h"
46 #include "zebra/debug.h"
47 #include "zebra/irdp.h"
48 #include "zebra/zebra_ptm.h"
49 #include "zebra/rt_netlink.h"
50 #include "zebra/if_netlink.h"
51 #include "zebra/interface.h"
52 #include "zebra/zebra_vxlan.h"
53 #include "zebra/zebra_errors.h"
55 DEFINE_MTYPE_STATIC(ZEBRA
, ZINFO
, "Zebra Interface Information")
57 #define ZEBRA_PTM_SUPPORT
59 DEFINE_HOOK(zebra_if_extra_info
, (struct vty
* vty
, struct interface
*ifp
),
61 DEFINE_HOOK(zebra_if_config_wr
, (struct vty
* vty
, struct interface
*ifp
),
65 static void if_down_del_nbr_connected(struct interface
*ifp
);
67 static int if_zebra_speed_update(struct thread
*thread
)
69 struct interface
*ifp
= THREAD_ARG(thread
);
70 struct zebra_if
*zif
= ifp
->info
;
75 zif
->speed_update
= NULL
;
77 new_speed
= kernel_get_speed(ifp
, &error
);
79 /* error may indicate vrf not available or
80 * interfaces not available.
81 * note that loopback & virtual interfaces can return 0 as speed
86 if (new_speed
!= ifp
->speed
) {
87 zlog_info("%s: %s old speed: %u new speed: %u",
88 __PRETTY_FUNCTION__
, ifp
->name
, ifp
->speed
,
90 ifp
->speed
= new_speed
;
95 if (changed
|| new_speed
== UINT32_MAX
)
96 thread_add_timer(zrouter
.master
, if_zebra_speed_update
, ifp
, 5,
101 static void zebra_if_node_destroy(route_table_delegate_t
*delegate
,
102 struct route_table
*table
,
103 struct route_node
*node
)
106 list_delete((struct list
**)&node
->info
);
107 route_node_destroy(delegate
, table
, node
);
110 static void zebra_if_nhg_dependents_free(struct zebra_if
*zebra_if
)
112 nhg_connected_tree_free(&zebra_if
->nhg_dependents
);
115 static void zebra_if_nhg_dependents_init(struct zebra_if
*zebra_if
)
117 nhg_connected_tree_init(&zebra_if
->nhg_dependents
);
121 route_table_delegate_t zebra_if_table_delegate
= {
122 .create_node
= route_node_create
,
123 .destroy_node
= zebra_if_node_destroy
};
125 /* Called when new interface is added. */
126 static int if_zebra_new_hook(struct interface
*ifp
)
128 struct zebra_if
*zebra_if
;
130 zebra_if
= XCALLOC(MTYPE_ZINFO
, sizeof(struct zebra_if
));
132 zebra_if
->multicast
= IF_ZEBRA_MULTICAST_UNSPEC
;
133 zebra_if
->shutdown
= IF_ZEBRA_SHUTDOWN_OFF
;
135 zebra_if_nhg_dependents_init(zebra_if
);
137 zebra_ptm_if_init(zebra_if
);
139 ifp
->ptm_enable
= zebra_ptm_get_enable_state();
140 #if defined(HAVE_RTADV)
142 /* Set default router advertise values. */
143 struct rtadvconf
*rtadv
;
145 rtadv
= &zebra_if
->rtadv
;
147 rtadv
->AdvSendAdvertisements
= 0;
148 rtadv
->MaxRtrAdvInterval
= RTADV_MAX_RTR_ADV_INTERVAL
;
149 rtadv
->MinRtrAdvInterval
= RTADV_MIN_RTR_ADV_INTERVAL
;
150 rtadv
->AdvIntervalTimer
= 0;
151 rtadv
->AdvManagedFlag
= 0;
152 rtadv
->AdvOtherConfigFlag
= 0;
153 rtadv
->AdvHomeAgentFlag
= 0;
154 rtadv
->AdvLinkMTU
= 0;
155 rtadv
->AdvReachableTime
= 0;
156 rtadv
->AdvRetransTimer
= 0;
157 rtadv
->AdvCurHopLimit
= 0;
158 rtadv
->AdvDefaultLifetime
=
159 -1; /* derive from MaxRtrAdvInterval */
160 rtadv
->HomeAgentPreference
= 0;
161 rtadv
->HomeAgentLifetime
=
162 -1; /* derive from AdvDefaultLifetime */
163 rtadv
->AdvIntervalOption
= 0;
164 rtadv
->UseFastRexmit
= true;
165 rtadv
->DefaultPreference
= RTADV_PREF_MEDIUM
;
167 rtadv
->AdvPrefixList
= list_new();
168 rtadv
->AdvRDNSSList
= list_new();
169 rtadv
->AdvDNSSLList
= list_new();
171 #endif /* HAVE_RTADV */
173 memset(&zebra_if
->neigh_mac
[0], 0, 6);
175 /* Initialize installed address chains tree. */
176 zebra_if
->ipv4_subnets
=
177 route_table_init_with_delegate(&zebra_if_table_delegate
);
179 ifp
->info
= zebra_if
;
182 * Some platforms are telling us that the interface is
183 * up and ready to go. When we check the speed we
184 * sometimes get the wrong value. Wait a couple
185 * of seconds and ask again. Hopefully it's all settled
188 thread_add_timer(zrouter
.master
, if_zebra_speed_update
, ifp
, 15,
189 &zebra_if
->speed_update
);
193 static void if_nhg_dependents_check_valid(struct nhg_hash_entry
*nhe
)
195 zebra_nhg_check_valid(nhe
);
196 if (!CHECK_FLAG(nhe
->flags
, NEXTHOP_GROUP_VALID
))
197 /* Assuming uninstalled as well here */
198 UNSET_FLAG(nhe
->flags
, NEXTHOP_GROUP_INSTALLED
);
201 static void if_down_nhg_dependents(const struct interface
*ifp
)
203 struct nhg_connected
*rb_node_dep
= NULL
;
204 struct zebra_if
*zif
= (struct zebra_if
*)ifp
->info
;
206 frr_each(nhg_connected_tree
, &zif
->nhg_dependents
, rb_node_dep
)
207 if_nhg_dependents_check_valid(rb_node_dep
->nhe
);
210 static void if_nhg_dependents_release(const struct interface
*ifp
)
212 struct nhg_connected
*rb_node_dep
= NULL
;
213 struct zebra_if
*zif
= (struct zebra_if
*)ifp
->info
;
215 frr_each(nhg_connected_tree
, &zif
->nhg_dependents
, rb_node_dep
) {
216 rb_node_dep
->nhe
->ifp
= NULL
; /* Null it out */
217 if_nhg_dependents_check_valid(rb_node_dep
->nhe
);
221 /* Called when interface is deleted. */
222 static int if_zebra_delete_hook(struct interface
*ifp
)
224 struct zebra_if
*zebra_if
;
227 zebra_if
= ifp
->info
;
229 /* Free installed address chains tree. */
230 if (zebra_if
->ipv4_subnets
)
231 route_table_finish(zebra_if
->ipv4_subnets
);
232 #if defined(HAVE_RTADV)
234 struct rtadvconf
*rtadv
;
236 rtadv
= &zebra_if
->rtadv
;
237 list_delete(&rtadv
->AdvPrefixList
);
238 list_delete(&rtadv
->AdvRDNSSList
);
239 list_delete(&rtadv
->AdvDNSSLList
);
240 #endif /* HAVE_RTADV */
242 if_nhg_dependents_release(ifp
);
243 zebra_if_nhg_dependents_free(zebra_if
);
245 XFREE(MTYPE_TMP
, zebra_if
->desc
);
247 THREAD_OFF(zebra_if
->speed_update
);
249 XFREE(MTYPE_ZINFO
, zebra_if
);
255 /* Build the table key */
256 static void if_build_key(uint32_t ifindex
, struct prefix
*p
)
259 p
->prefixlen
= IPV4_MAX_BITLEN
;
260 p
->u
.prefix4
.s_addr
= ifindex
;
263 /* Link an interface in a per NS interface tree */
264 struct interface
*if_link_per_ns(struct zebra_ns
*ns
, struct interface
*ifp
)
267 struct route_node
*rn
;
269 if (ifp
->ifindex
== IFINDEX_INTERNAL
)
272 if_build_key(ifp
->ifindex
, &p
);
273 rn
= route_node_get(ns
->if_table
, &p
);
275 ifp
= (struct interface
*)rn
->info
;
276 route_unlock_node(rn
); /* get */
286 /* Delete a VRF. This is called in vrf_terminate(). */
287 void if_unlink_per_ns(struct interface
*ifp
)
289 ifp
->node
->info
= NULL
;
290 route_unlock_node(ifp
->node
);
294 /* Look up an interface by identifier within a NS */
295 struct interface
*if_lookup_by_index_per_ns(struct zebra_ns
*ns
,
299 struct route_node
*rn
;
300 struct interface
*ifp
= NULL
;
302 if_build_key(ifindex
, &p
);
303 rn
= route_node_lookup(ns
->if_table
, &p
);
305 ifp
= (struct interface
*)rn
->info
;
306 route_unlock_node(rn
); /* lookup */
311 /* Look up an interface by name within a NS */
312 struct interface
*if_lookup_by_name_per_ns(struct zebra_ns
*ns
,
315 struct route_node
*rn
;
316 struct interface
*ifp
;
318 for (rn
= route_top(ns
->if_table
); rn
; rn
= route_next(rn
)) {
319 ifp
= (struct interface
*)rn
->info
;
320 if (ifp
&& strcmp(ifp
->name
, ifname
) == 0) {
321 route_unlock_node(rn
);
329 const char *ifindex2ifname_per_ns(struct zebra_ns
*zns
, unsigned int ifindex
)
331 struct interface
*ifp
;
333 return ((ifp
= if_lookup_by_index_per_ns(zns
, ifindex
)) != NULL
)
338 /* Tie an interface address to its derived subnet list of addresses. */
339 int if_subnet_add(struct interface
*ifp
, struct connected
*ifc
)
341 struct route_node
*rn
;
342 struct zebra_if
*zebra_if
;
344 struct list
*addr_list
;
346 assert(ifp
&& ifp
->info
&& ifc
);
347 zebra_if
= ifp
->info
;
349 /* Get address derived subnet node and associated address list, while
351 address secondary attribute appropriately. */
352 cp
= *CONNECTED_PREFIX(ifc
);
354 rn
= route_node_get(zebra_if
->ipv4_subnets
, &cp
);
356 if ((addr_list
= rn
->info
))
357 SET_FLAG(ifc
->flags
, ZEBRA_IFA_SECONDARY
);
359 UNSET_FLAG(ifc
->flags
, ZEBRA_IFA_SECONDARY
);
360 rn
->info
= addr_list
= list_new();
364 /* Tie address at the tail of address list. */
365 listnode_add(addr_list
, ifc
);
367 /* Return list element count. */
368 return (addr_list
->count
);
371 /* Untie an interface address from its derived subnet list of addresses. */
372 int if_subnet_delete(struct interface
*ifp
, struct connected
*ifc
)
374 struct route_node
*rn
;
375 struct zebra_if
*zebra_if
;
376 struct list
*addr_list
;
379 assert(ifp
&& ifp
->info
&& ifc
);
380 zebra_if
= ifp
->info
;
382 cp
= *CONNECTED_PREFIX(ifc
);
385 /* Get address derived subnet node. */
386 rn
= route_node_lookup(zebra_if
->ipv4_subnets
, &cp
);
387 if (!(rn
&& rn
->info
)) {
388 flog_warn(EC_ZEBRA_REMOVE_ADDR_UNKNOWN_SUBNET
,
389 "Trying to remove an address from an unknown subnet."
390 " (please report this bug)");
393 route_unlock_node(rn
);
395 /* Untie address from subnet's address list. */
396 addr_list
= rn
->info
;
398 /* Deleting an address that is not registered is a bug.
399 * In any case, we shouldn't decrement the lock counter if the address
401 if (!listnode_lookup(addr_list
, ifc
)) {
403 EC_ZEBRA_REMOVE_UNREGISTERED_ADDR
,
404 "Trying to remove an address from a subnet where it is not"
405 " currently registered. (please report this bug)");
409 listnode_delete(addr_list
, ifc
);
410 route_unlock_node(rn
);
412 /* Return list element count, if not empty. */
413 if (addr_list
->count
) {
414 /* If deleted address is primary, mark subsequent one as such
416 if (!CHECK_FLAG(ifc
->flags
, ZEBRA_IFA_SECONDARY
)) {
418 (struct listnode
*)listhead(addr_list
));
419 zebra_interface_address_delete_update(ifp
, ifc
);
420 UNSET_FLAG(ifc
->flags
, ZEBRA_IFA_SECONDARY
);
421 /* XXX: Linux kernel removes all the secondary addresses
423 * address is removed. We could try to work around that,
426 zebra_interface_address_add_update(ifp
, ifc
);
429 return addr_list
->count
;
432 /* Otherwise, free list and route node. */
433 list_delete(&addr_list
);
435 route_unlock_node(rn
);
440 /* if_flags_mangle: A place for hacks that require mangling
441 * or tweaking the interface flags.
443 * ******************** Solaris flags hacks **************************
445 * Solaris IFF_UP flag reflects only the primary interface as the
446 * routing socket only sends IFINFO for the primary interface. Hence
447 * ~IFF_UP does not per se imply all the logical interfaces are also
448 * down - which we only know of as addresses. Instead we must determine
449 * whether the interface really is up or not according to how many
450 * addresses are still attached. (Solaris always sends RTM_DELADDR if
451 * an interface, logical or not, goes ~IFF_UP).
453 * Ie, we mangle IFF_UP to *additionally* reflect whether or not there
454 * are addresses left in struct connected, not just the actual underlying
457 * We must hence remember the real state of IFF_UP, which we do in
458 * struct zebra_if.primary_state.
460 * Setting IFF_UP within zebra to administratively shutdown the
461 * interface will affect only the primary interface/address on Solaris.
462 ************************End Solaris flags hacks ***********************
464 static void if_flags_mangle(struct interface
*ifp
, uint64_t *newflags
)
467 struct zebra_if
*zif
= ifp
->info
;
469 zif
->primary_state
= *newflags
& (IFF_UP
& 0xff);
471 if (CHECK_FLAG(zif
->primary_state
, IFF_UP
)
472 || listcount(ifp
->connected
) > 0)
473 SET_FLAG(*newflags
, IFF_UP
);
475 UNSET_FLAG(*newflags
, IFF_UP
);
479 /* Update the flags field of the ifp with the new flag set provided.
480 * Take whatever actions are required for any changes in flags we care
483 * newflags should be the raw value, as obtained from the OS.
485 void if_flags_update(struct interface
*ifp
, uint64_t newflags
)
487 if_flags_mangle(ifp
, &newflags
);
489 if (if_is_no_ptm_operative(ifp
)) {
490 /* operative -> inoperative? */
491 ifp
->flags
= newflags
;
492 if (!if_is_operative(ifp
))
495 /* inoperative -> operative? */
496 ifp
->flags
= newflags
;
497 if (if_is_operative(ifp
))
502 /* Wake up configured address if it is not in current kernel
504 static void if_addr_wakeup(struct interface
*ifp
)
506 struct listnode
*node
, *nnode
;
507 struct connected
*ifc
;
509 enum zebra_dplane_result dplane_res
;
511 for (ALL_LIST_ELEMENTS(ifp
->connected
, node
, nnode
, ifc
)) {
514 if (CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_CONFIGURED
)
515 && !CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
)) {
517 if (p
->family
== AF_INET
) {
518 if (!if_is_up(ifp
)) {
519 /* Assume zebra is configured like
523 * ip addr 192.0.2.1/24
526 * As soon as zebra becomes first aware
527 * that gre0 exists in the
528 * kernel, it will set gre0 up and
529 * configure its addresses.
531 * (This may happen at startup when the
532 * interface already exists
533 * or during runtime when the interface
534 * is added to the kernel)
536 * XXX: IRDP code is calling here via
537 * if_add_update - this seems
539 * XXX: RUNNING is not a settable flag
541 * I (paulj) am aware of.
543 if_set_flags(ifp
, IFF_UP
| IFF_RUNNING
);
547 dplane_res
= dplane_intf_addr_set(ifp
, ifc
);
549 ZEBRA_DPLANE_REQUEST_FAILURE
) {
551 EC_ZEBRA_IFACE_ADDR_ADD_FAILED
,
552 "Can't set interface's address: %s",
553 dplane_res2str(dplane_res
));
557 SET_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
);
558 /* The address will be advertised to zebra
559 * clients when the notification
560 * from the kernel has been received.
561 * It will also be added to the interface's
562 * subnet list then. */
564 if (p
->family
== AF_INET6
) {
565 if (!if_is_up(ifp
)) {
566 /* See long comment above */
567 if_set_flags(ifp
, IFF_UP
| IFF_RUNNING
);
572 dplane_res
= dplane_intf_addr_set(ifp
, ifc
);
574 ZEBRA_DPLANE_REQUEST_FAILURE
) {
576 EC_ZEBRA_IFACE_ADDR_ADD_FAILED
,
577 "Can't set interface's address: %s",
578 dplane_res2str(dplane_res
));
582 SET_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
);
583 /* The address will be advertised to zebra
584 * clients when the notification
585 * from the kernel has been received. */
591 /* Handle interface addition */
592 void if_add_update(struct interface
*ifp
)
594 struct zebra_if
*if_data
;
595 struct zebra_ns
*zns
;
596 struct zebra_vrf
*zvrf
= vrf_info_lookup(ifp
->vrf_id
);
598 /* case interface populate before vrf enabled */
602 zns
= zebra_ns_lookup(NS_DEFAULT
);
603 if_link_per_ns(zns
, ifp
);
607 if (if_data
->multicast
== IF_ZEBRA_MULTICAST_ON
)
608 if_set_flags(ifp
, IFF_MULTICAST
);
609 else if (if_data
->multicast
== IF_ZEBRA_MULTICAST_OFF
)
610 if_unset_flags(ifp
, IFF_MULTICAST
);
612 zebra_ptm_if_set_ptm_state(ifp
, if_data
);
614 zebra_interface_add_update(ifp
);
616 if (!CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
)) {
617 SET_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
);
619 if (if_data
->shutdown
== IF_ZEBRA_SHUTDOWN_ON
) {
620 if (IS_ZEBRA_DEBUG_KERNEL
)
622 "interface %s vrf %u index %d is shutdown. "
624 ifp
->name
, ifp
->vrf_id
, ifp
->ifindex
);
630 if (IS_ZEBRA_DEBUG_KERNEL
)
632 "interface %s vrf %u index %d becomes active.",
633 ifp
->name
, ifp
->vrf_id
, ifp
->ifindex
);
636 if (IS_ZEBRA_DEBUG_KERNEL
)
637 zlog_debug("interface %s vrf %u index %d is added.",
638 ifp
->name
, ifp
->vrf_id
, ifp
->ifindex
);
642 /* Install connected routes corresponding to an interface. */
643 static void if_install_connected(struct interface
*ifp
)
645 struct listnode
*node
;
646 struct listnode
*next
;
647 struct connected
*ifc
;
649 if (ifp
->connected
) {
650 for (ALL_LIST_ELEMENTS(ifp
->connected
, node
, next
, ifc
)) {
651 if (CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_REAL
))
652 zebra_interface_address_add_update(ifp
, ifc
);
654 connected_up(ifp
, ifc
);
659 /* Uninstall connected routes corresponding to an interface. */
660 static void if_uninstall_connected(struct interface
*ifp
)
662 struct listnode
*node
;
663 struct listnode
*next
;
664 struct connected
*ifc
;
666 if (ifp
->connected
) {
667 for (ALL_LIST_ELEMENTS(ifp
->connected
, node
, next
, ifc
)) {
668 zebra_interface_address_delete_update(ifp
, ifc
);
669 connected_down(ifp
, ifc
);
674 /* Uninstall and delete connected routes corresponding to an interface. */
675 /* TODO - Check why IPv4 handling here is different from install or if_down */
676 static void if_delete_connected(struct interface
*ifp
)
678 struct connected
*ifc
;
680 struct route_node
*rn
;
681 struct zebra_if
*zebra_if
;
682 struct listnode
*node
;
683 struct listnode
*last
= NULL
;
685 zebra_if
= ifp
->info
;
690 while ((node
= (last
? last
->next
: listhead(ifp
->connected
)))) {
691 ifc
= listgetdata(node
);
693 cp
= *CONNECTED_PREFIX(ifc
);
696 if (cp
.family
== AF_INET
697 && (rn
= route_node_lookup(zebra_if
->ipv4_subnets
, &cp
))) {
698 struct listnode
*anode
;
699 struct listnode
*next
;
700 struct listnode
*first
;
701 struct list
*addr_list
;
703 route_unlock_node(rn
);
704 addr_list
= (struct list
*)rn
->info
;
706 /* Remove addresses, secondaries first. */
707 first
= listhead(addr_list
);
709 for (anode
= first
->next
; anode
|| first
;
717 ifc
= listgetdata(anode
);
718 connected_down(ifp
, ifc
);
720 /* XXX: We have to send notifications
721 * here explicitly, because we destroy
722 * the ifc before receiving the
723 * notification about the address being
726 zebra_interface_address_delete_update(
729 UNSET_FLAG(ifc
->conf
, ZEBRA_IFC_REAL
);
730 UNSET_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
);
732 /* Remove from subnet chain. */
733 list_delete_node(addr_list
, anode
);
734 route_unlock_node(rn
);
736 /* Remove from interface address list
737 * (unconditionally). */
738 if (!CHECK_FLAG(ifc
->conf
,
739 ZEBRA_IFC_CONFIGURED
)) {
740 listnode_delete(ifp
->connected
,
742 connected_free(&ifc
);
747 /* Free chain list and respective route node. */
748 list_delete(&addr_list
);
750 route_unlock_node(rn
);
751 } else if (cp
.family
== AF_INET6
) {
752 connected_down(ifp
, ifc
);
754 zebra_interface_address_delete_update(ifp
, ifc
);
756 UNSET_FLAG(ifc
->conf
, ZEBRA_IFC_REAL
);
757 UNSET_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
);
759 if (CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
762 listnode_delete(ifp
->connected
, ifc
);
763 connected_free(&ifc
);
771 /* Handle an interface delete event */
772 void if_delete_update(struct interface
*ifp
)
774 struct zebra_if
*zif
;
779 "interface %s vrf %u index %d is still up while being deleted.",
780 ifp
->name
, ifp
->vrf_id
, ifp
->ifindex
);
784 if (!CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
))
787 /* Mark interface as inactive */
788 UNSET_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
);
790 if (IS_ZEBRA_DEBUG_KERNEL
)
791 zlog_debug("interface %s vrf %u index %d is now inactive.",
792 ifp
->name
, ifp
->vrf_id
, ifp
->ifindex
);
794 /* Delete connected routes from the kernel. */
795 if_delete_connected(ifp
);
797 /* Send out notification on interface delete. */
798 zebra_interface_delete_update(ifp
);
800 if_unlink_per_ns(ifp
);
802 /* Update ifindex after distributing the delete message. This is in
803 case any client needs to have the old value of ifindex available
804 while processing the deletion. Each client daemon is responsible
805 for setting ifindex to IFINDEX_INTERNAL after processing the
806 interface deletion message. */
807 if_set_index(ifp
, IFINDEX_INTERNAL
);
810 /* if the ifp is in a vrf, move it to default so vrf can be deleted if
811 * desired. This operation is not done for netns implementation to avoid
812 * collision with interface with the same name in the default vrf (can
813 * occur with this implementation whereas it is not possible with
816 if (ifp
->vrf_id
&& !vrf_is_backend_netns())
817 if_handle_vrf_change(ifp
, VRF_DEFAULT
);
819 /* Reset some zebra interface params to default values. */
822 zif
->zif_type
= ZEBRA_IF_OTHER
;
823 zif
->zif_slave_type
= ZEBRA_IF_SLAVE_NONE
;
824 memset(&zif
->l2info
, 0, sizeof(union zebra_l2if_info
));
825 memset(&zif
->brslave_info
, 0,
826 sizeof(struct zebra_l2info_brslave
));
829 if (!ifp
->configured
) {
830 if (IS_ZEBRA_DEBUG_KERNEL
)
831 zlog_debug("interface %s is being deleted from the system",
837 /* VRF change for an interface */
838 void if_handle_vrf_change(struct interface
*ifp
, vrf_id_t vrf_id
)
842 old_vrf_id
= ifp
->vrf_id
;
844 /* Uninstall connected routes. */
845 if_uninstall_connected(ifp
);
847 /* Delete any IPv4 neighbors created to implement RFC 5549 */
848 if_nbr_ipv6ll_to_ipv4ll_neigh_del_all(ifp
);
850 /* Delete all neighbor addresses learnt through IPv6 RA */
851 if_down_del_nbr_connected(ifp
);
853 /* Send out notification on interface VRF change. */
854 /* This is to issue an UPDATE or a DELETE, as appropriate. */
855 zebra_interface_vrf_update_del(ifp
, vrf_id
);
858 if_update_to_new_vrf(ifp
, vrf_id
);
860 /* Send out notification on interface VRF change. */
861 /* This is to issue an ADD, if needed. */
862 zebra_interface_vrf_update_add(ifp
, old_vrf_id
);
864 /* Install connected routes (in new VRF). */
865 if (if_is_operative(ifp
))
866 if_install_connected(ifp
);
869 static void ipv6_ll_address_to_mac(struct in6_addr
*address
, uint8_t *mac
)
871 mac
[0] = address
->s6_addr
[8] ^ 0x02;
872 mac
[1] = address
->s6_addr
[9];
873 mac
[2] = address
->s6_addr
[10];
874 mac
[3] = address
->s6_addr
[13];
875 mac
[4] = address
->s6_addr
[14];
876 mac
[5] = address
->s6_addr
[15];
879 void if_nbr_mac_to_ipv4ll_neigh_update(struct interface
*ifp
,
881 struct in6_addr
*address
,
884 struct zebra_vrf
*zvrf
= vrf_info_lookup(ifp
->vrf_id
);
885 struct zebra_if
*zif
= ifp
->info
;
886 char buf
[16] = "169.254.0.1";
887 struct in_addr ipv4_ll
;
890 inet_pton(AF_INET
, buf
, &ipv4_ll
);
892 ns_id
= zvrf
->zns
->ns_id
;
895 * Remove and re-add any existing neighbor entry for this address,
896 * since Netlink doesn't currently offer update message types.
898 kernel_neigh_update(0, ifp
->ifindex
, ipv4_ll
.s_addr
, mac
, 6, ns_id
);
900 /* Add new neighbor entry.
902 * We force installation even if current neighbor entry is the same.
903 * Since this function is used to refresh our MAC entries after an
904 * interface flap, if we don't force in our custom entries with their
905 * state set to PERMANENT or REACHABLE then the kernel will attempt to
906 * resolve our leftover entries, fail, mark them unreachable and then
907 * they'll be useless to us.
910 kernel_neigh_update(add
, ifp
->ifindex
, ipv4_ll
.s_addr
, mac
, 6,
913 memcpy(&zif
->neigh_mac
[0], &mac
[0], 6);
916 * We need to note whether or not we originated a v6
917 * neighbor entry for this interface. So that when
918 * someone unwisely accidently deletes this entry
919 * we can shove it back in.
921 zif
->v6_2_v4_ll_neigh_entry
= !!add
;
922 memcpy(&zif
->v6_2_v4_ll_addr6
, address
, sizeof(*address
));
924 zvrf
->neigh_updates
++;
927 void if_nbr_ipv6ll_to_ipv4ll_neigh_update(struct interface
*ifp
,
928 struct in6_addr
*address
, int add
)
933 ipv6_ll_address_to_mac(address
, (uint8_t *)mac
);
934 if_nbr_mac_to_ipv4ll_neigh_update(ifp
, mac
, address
, add
);
937 static void if_nbr_ipv6ll_to_ipv4ll_neigh_add_all(struct interface
*ifp
)
939 if (listhead(ifp
->nbr_connected
)) {
940 struct nbr_connected
*nbr_connected
;
941 struct listnode
*node
;
943 for (ALL_LIST_ELEMENTS_RO(ifp
->nbr_connected
, node
,
945 if_nbr_ipv6ll_to_ipv4ll_neigh_update(
946 ifp
, &nbr_connected
->address
->u
.prefix6
, 1);
950 void if_nbr_ipv6ll_to_ipv4ll_neigh_del_all(struct interface
*ifp
)
952 if (listhead(ifp
->nbr_connected
)) {
953 struct nbr_connected
*nbr_connected
;
954 struct listnode
*node
;
956 for (ALL_LIST_ELEMENTS_RO(ifp
->nbr_connected
, node
,
958 if_nbr_ipv6ll_to_ipv4ll_neigh_update(
959 ifp
, &nbr_connected
->address
->u
.prefix6
, 0);
963 static void if_down_del_nbr_connected(struct interface
*ifp
)
965 struct nbr_connected
*nbr_connected
;
966 struct listnode
*node
, *nnode
;
968 for (ALL_LIST_ELEMENTS(ifp
->nbr_connected
, node
, nnode
,
970 listnode_delete(ifp
->nbr_connected
, nbr_connected
);
971 nbr_connected_free(nbr_connected
);
975 void if_nhg_dependents_add(struct interface
*ifp
, struct nhg_hash_entry
*nhe
)
978 struct zebra_if
*zif
= (struct zebra_if
*)ifp
->info
;
980 nhg_connected_tree_add_nhe(&zif
->nhg_dependents
, nhe
);
984 void if_nhg_dependents_del(struct interface
*ifp
, struct nhg_hash_entry
*nhe
)
987 struct zebra_if
*zif
= (struct zebra_if
*)ifp
->info
;
989 nhg_connected_tree_del_nhe(&zif
->nhg_dependents
, nhe
);
993 unsigned int if_nhg_dependents_count(const struct interface
*ifp
)
996 struct zebra_if
*zif
= (struct zebra_if
*)ifp
->info
;
998 return nhg_connected_tree_count(&zif
->nhg_dependents
);
1005 bool if_nhg_dependents_is_empty(const struct interface
*ifp
)
1008 struct zebra_if
*zif
= (struct zebra_if
*)ifp
->info
;
1010 return nhg_connected_tree_is_empty(&zif
->nhg_dependents
);
1016 /* Interface is up. */
1017 void if_up(struct interface
*ifp
)
1019 struct zebra_if
*zif
;
1020 struct interface
*link_if
;
1021 struct zebra_vrf
*zvrf
= vrf_info_lookup(ifp
->vrf_id
);
1025 quagga_timestamp(2, zif
->up_last
, sizeof(zif
->up_last
));
1027 /* Notify the protocol daemons. */
1028 if (ifp
->ptm_enable
&& (ifp
->ptm_status
== ZEBRA_PTM_STATUS_DOWN
)) {
1029 flog_warn(EC_ZEBRA_PTM_NOT_READY
,
1030 "%s: interface %s hasn't passed ptm check\n",
1031 __func__
, ifp
->name
);
1034 zebra_interface_up_update(ifp
);
1036 if_nbr_ipv6ll_to_ipv4ll_neigh_add_all(ifp
);
1038 #if defined(HAVE_RTADV)
1039 /* Enable fast tx of RA if enabled && RA interval is not in msecs */
1040 if (zif
->rtadv
.AdvSendAdvertisements
1041 && (zif
->rtadv
.MaxRtrAdvInterval
>= 1000)
1042 && zif
->rtadv
.UseFastRexmit
) {
1043 zif
->rtadv
.inFastRexmit
= 1;
1044 zif
->rtadv
.NumFastReXmitsRemain
= RTADV_NUM_FAST_REXMITS
;
1048 /* Install connected routes to the kernel. */
1049 if_install_connected(ifp
);
1051 /* Handle interface up for specific types for EVPN. Non-VxLAN interfaces
1052 * are checked to see if (remote) neighbor entries need to be installed
1053 * on them for ARP suppression.
1055 if (IS_ZEBRA_IF_VXLAN(ifp
))
1056 zebra_vxlan_if_up(ifp
);
1057 else if (IS_ZEBRA_IF_BRIDGE(ifp
)) {
1059 zebra_vxlan_svi_up(ifp
, link_if
);
1060 } else if (IS_ZEBRA_IF_VLAN(ifp
)) {
1061 link_if
= if_lookup_by_index_per_ns(zvrf
->zns
,
1064 zebra_vxlan_svi_up(ifp
, link_if
);
1068 /* Interface goes down. We have to manage different behavior of based
1070 void if_down(struct interface
*ifp
)
1072 struct zebra_if
*zif
;
1073 struct interface
*link_if
;
1074 struct zebra_vrf
*zvrf
= vrf_info_lookup(ifp
->vrf_id
);
1078 quagga_timestamp(2, zif
->down_last
, sizeof(zif
->down_last
));
1080 if_down_nhg_dependents(ifp
);
1082 /* Handle interface down for specific types for EVPN. Non-VxLAN
1084 * are checked to see if (remote) neighbor entries need to be purged
1085 * for ARP suppression.
1087 if (IS_ZEBRA_IF_VXLAN(ifp
))
1088 zebra_vxlan_if_down(ifp
);
1089 else if (IS_ZEBRA_IF_BRIDGE(ifp
)) {
1091 zebra_vxlan_svi_down(ifp
, link_if
);
1092 } else if (IS_ZEBRA_IF_VLAN(ifp
)) {
1093 link_if
= if_lookup_by_index_per_ns(zvrf
->zns
,
1096 zebra_vxlan_svi_down(ifp
, link_if
);
1100 /* Notify to the protocol daemons. */
1101 zebra_interface_down_update(ifp
);
1103 /* Uninstall connected routes from the kernel. */
1104 if_uninstall_connected(ifp
);
1106 if_nbr_ipv6ll_to_ipv4ll_neigh_del_all(ifp
);
1108 /* Delete all neighbor addresses learnt through IPv6 RA */
1109 if_down_del_nbr_connected(ifp
);
1112 void if_refresh(struct interface
*ifp
)
1117 void zebra_if_update_link(struct interface
*ifp
, ifindex_t link_ifindex
,
1120 struct zebra_if
*zif
;
1122 if (IS_ZEBRA_IF_VETH(ifp
))
1124 zif
= (struct zebra_if
*)ifp
->info
;
1125 zif
->link_ifindex
= link_ifindex
;
1126 zif
->link
= if_lookup_by_index_per_ns(zebra_ns_lookup(ns_id
),
1131 * during initial link dump kernel does not order lower devices before
1132 * upper devices so we need to fixup link dependencies at the end of dump
1134 void zebra_if_update_all_links(void)
1136 struct route_node
*rn
;
1137 struct interface
*ifp
;
1138 struct zebra_if
*zif
;
1139 struct zebra_ns
*ns
;
1141 if (IS_ZEBRA_DEBUG_KERNEL
)
1142 zlog_info("fixup link dependencies");
1144 ns
= zebra_ns_lookup(NS_DEFAULT
);
1145 for (rn
= route_top(ns
->if_table
); rn
; rn
= route_next(rn
)) {
1146 ifp
= (struct interface
*)rn
->info
;
1150 if ((zif
->link_ifindex
!= IFINDEX_INTERNAL
) && !zif
->link
) {
1151 zif
->link
= if_lookup_by_index_per_ns(ns
,
1153 if (IS_ZEBRA_DEBUG_KERNEL
)
1154 zlog_debug("interface %s/%d's lower fixup to %s/%d",
1155 ifp
->name
, ifp
->ifindex
,
1156 zif
->link
?zif
->link
->name
:"unk",
1162 void zebra_if_set_protodown(struct interface
*ifp
, bool down
)
1165 netlink_protodown(ifp
, down
);
1167 zlog_warn("Protodown is not supported on this platform");
1171 /* Output prefix string to vty. */
1172 static int prefix_vty_out(struct vty
*vty
, struct prefix
*p
)
1174 char str
[INET6_ADDRSTRLEN
];
1176 inet_ntop(p
->family
, &p
->u
.prefix
, str
, sizeof(str
));
1177 vty_out(vty
, "%s", str
);
1181 /* Dump if address information to vty. */
1182 static void connected_dump_vty(struct vty
*vty
, struct connected
*connected
)
1186 /* Print interface address. */
1187 p
= connected
->address
;
1188 vty_out(vty
, " %s ", prefix_family_str(p
));
1189 prefix_vty_out(vty
, p
);
1190 vty_out(vty
, "/%d", p
->prefixlen
);
1192 /* If there is destination address, print it. */
1193 if (CONNECTED_PEER(connected
) && connected
->destination
) {
1194 vty_out(vty
, " peer ");
1195 prefix_vty_out(vty
, connected
->destination
);
1196 vty_out(vty
, "/%d", connected
->destination
->prefixlen
);
1199 if (CHECK_FLAG(connected
->flags
, ZEBRA_IFA_SECONDARY
))
1200 vty_out(vty
, " secondary");
1202 if (CHECK_FLAG(connected
->flags
, ZEBRA_IFA_UNNUMBERED
))
1203 vty_out(vty
, " unnumbered");
1205 if (connected
->label
)
1206 vty_out(vty
, " %s", connected
->label
);
1211 /* Dump interface neighbor address information to vty. */
1212 static void nbr_connected_dump_vty(struct vty
*vty
,
1213 struct nbr_connected
*connected
)
1217 /* Print interface address. */
1218 p
= connected
->address
;
1219 vty_out(vty
, " %s ", prefix_family_str(p
));
1220 prefix_vty_out(vty
, p
);
1221 vty_out(vty
, "/%d", p
->prefixlen
);
1226 static const char *zebra_ziftype_2str(zebra_iftype_t zif_type
)
1229 case ZEBRA_IF_OTHER
:
1233 case ZEBRA_IF_BRIDGE
:
1241 case ZEBRA_IF_VXLAN
:
1256 case ZEBRA_IF_BOND_SLAVE
:
1257 return "bond_slave";
1259 case ZEBRA_IF_MACVLAN
:
1268 /* Interface's brief information print out to vty interface. */
1269 static void ifs_dump_brief_vty(struct vty
*vty
, struct vrf
*vrf
)
1271 struct connected
*connected
;
1272 struct listnode
*node
;
1273 struct route_node
*rn
;
1274 struct zebra_if
*zebra_if
;
1276 struct interface
*ifp
;
1277 bool print_header
= true;
1279 FOR_ALL_INTERFACES (vrf
, ifp
) {
1280 char global_pfx
[PREFIX_STRLEN
] = {0};
1281 char buf
[PREFIX_STRLEN
] = {0};
1282 bool first_pfx_printed
= false;
1285 vty_out(vty
, "%-16s%-8s%-16s%s\n", "Interface",
1286 "Status", "VRF", "Addresses");
1287 vty_out(vty
, "%-16s%-8s%-16s%s\n", "---------",
1288 "------", "---", "---------");
1289 print_header
= false; /* We have at least 1 iface */
1291 zebra_if
= ifp
->info
;
1293 vty_out(vty
, "%-16s", ifp
->name
);
1296 vty_out(vty
, "%-8s", "up");
1298 vty_out(vty
, "%-8s", "down");
1300 vty_out(vty
, "%-16s", vrf
->name
);
1302 for (rn
= route_top(zebra_if
->ipv4_subnets
); rn
;
1303 rn
= route_next(rn
)) {
1306 uint32_t list_size
= listcount((struct list
*)rn
->info
);
1308 for (ALL_LIST_ELEMENTS_RO((struct list
*)rn
->info
, node
,
1310 if (!CHECK_FLAG(connected
->flags
,
1311 ZEBRA_IFA_SECONDARY
)) {
1312 p
= connected
->address
;
1313 prefix2str(p
, buf
, sizeof(buf
));
1314 if (first_pfx_printed
) {
1315 /* padding to prepare row only for ip addr */
1316 vty_out(vty
, "%-40s", "");
1319 vty_out(vty
, "%s\n", buf
);
1323 vty_out(vty
, "%s\n", buf
);
1325 first_pfx_printed
= true;
1331 uint32_t v6_list_size
= 0;
1332 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, node
, connected
)) {
1333 if (CHECK_FLAG(connected
->conf
, ZEBRA_IFC_REAL
)
1334 && (connected
->address
->family
== AF_INET6
))
1337 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, node
, connected
)) {
1338 if (CHECK_FLAG(connected
->conf
, ZEBRA_IFC_REAL
)
1339 && !CHECK_FLAG(connected
->flags
,
1340 ZEBRA_IFA_SECONDARY
)
1341 && (connected
->address
->family
== AF_INET6
)) {
1342 p
= connected
->address
;
1343 /* Don't print link local pfx */
1344 if (!IN6_IS_ADDR_LINKLOCAL(&p
->u
.prefix6
)) {
1345 prefix2str(p
, global_pfx
, PREFIX_STRLEN
);
1346 if (first_pfx_printed
) {
1347 /* padding to prepare row only for ip addr */
1348 vty_out(vty
, "%-40s", "");
1349 if (v6_list_size
> 1)
1351 vty_out(vty
, "%s\n", global_pfx
);
1353 if (v6_list_size
> 1)
1355 vty_out(vty
, "%s\n", global_pfx
);
1357 first_pfx_printed
= true;
1362 if (!first_pfx_printed
)
1368 /* Interface's information print out to vty interface. */
1369 static void if_dump_vty(struct vty
*vty
, struct interface
*ifp
)
1371 struct connected
*connected
;
1372 struct nbr_connected
*nbr_connected
;
1373 struct listnode
*node
;
1374 struct route_node
*rn
;
1375 struct zebra_if
*zebra_if
;
1378 zebra_if
= ifp
->info
;
1380 vty_out(vty
, "Interface %s is ", ifp
->name
);
1381 if (if_is_up(ifp
)) {
1382 vty_out(vty
, "up, line protocol ");
1384 if (CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_LINKDETECTION
)) {
1385 if (if_is_running(ifp
))
1386 vty_out(vty
, "is up\n");
1388 vty_out(vty
, "is down\n");
1390 vty_out(vty
, "detection is disabled\n");
1393 vty_out(vty
, "down\n");
1396 vty_out(vty
, " Link ups: %5u last: %s\n", zebra_if
->up_count
,
1397 zebra_if
->up_last
[0] ? zebra_if
->up_last
: "(never)");
1398 vty_out(vty
, " Link downs: %5u last: %s\n", zebra_if
->down_count
,
1399 zebra_if
->down_last
[0] ? zebra_if
->down_last
: "(never)");
1401 zebra_ptm_show_status(vty
, ifp
);
1403 vrf
= vrf_lookup_by_id(ifp
->vrf_id
);
1404 vty_out(vty
, " vrf: %s\n", vrf
->name
);
1407 vty_out(vty
, " Description: %s\n", ifp
->desc
);
1409 vty_out(vty
, " OS Description: %s\n", zebra_if
->desc
);
1411 if (ifp
->ifindex
== IFINDEX_INTERNAL
) {
1412 vty_out(vty
, " pseudo interface\n");
1414 } else if (!CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
)) {
1415 vty_out(vty
, " index %d inactive interface\n", ifp
->ifindex
);
1419 vty_out(vty
, " index %d metric %d mtu %d speed %u ", ifp
->ifindex
,
1420 ifp
->metric
, ifp
->mtu
, ifp
->speed
);
1421 if (ifp
->mtu6
!= ifp
->mtu
)
1422 vty_out(vty
, "mtu6 %d ", ifp
->mtu6
);
1423 vty_out(vty
, "\n flags: %s\n", if_flag_dump(ifp
->flags
));
1425 /* Hardware address. */
1426 vty_out(vty
, " Type: %s\n", if_link_type_str(ifp
->ll_type
));
1427 if (ifp
->hw_addr_len
!= 0) {
1430 vty_out(vty
, " HWaddr: ");
1431 for (i
= 0; i
< ifp
->hw_addr_len
; i
++)
1432 vty_out(vty
, "%s%02x", i
== 0 ? "" : ":",
1437 /* Bandwidth in Mbps */
1438 if (ifp
->bandwidth
!= 0) {
1439 vty_out(vty
, " bandwidth %u Mbps", ifp
->bandwidth
);
1443 for (rn
= route_top(zebra_if
->ipv4_subnets
); rn
; rn
= route_next(rn
)) {
1447 for (ALL_LIST_ELEMENTS_RO((struct list
*)rn
->info
, node
,
1449 connected_dump_vty(vty
, connected
);
1452 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, node
, connected
)) {
1453 if (CHECK_FLAG(connected
->conf
, ZEBRA_IFC_REAL
)
1454 && (connected
->address
->family
== AF_INET6
))
1455 connected_dump_vty(vty
, connected
);
1458 vty_out(vty
, " Interface Type %s\n",
1459 zebra_ziftype_2str(zebra_if
->zif_type
));
1460 if (IS_ZEBRA_IF_BRIDGE(ifp
)) {
1461 struct zebra_l2info_bridge
*bridge_info
;
1463 bridge_info
= &zebra_if
->l2info
.br
;
1464 vty_out(vty
, " Bridge VLAN-aware: %s\n",
1465 bridge_info
->vlan_aware
? "yes" : "no");
1466 } else if (IS_ZEBRA_IF_VLAN(ifp
)) {
1467 struct zebra_l2info_vlan
*vlan_info
;
1469 vlan_info
= &zebra_if
->l2info
.vl
;
1470 vty_out(vty
, " VLAN Id %u\n", vlan_info
->vid
);
1471 } else if (IS_ZEBRA_IF_VXLAN(ifp
)) {
1472 struct zebra_l2info_vxlan
*vxlan_info
;
1474 vxlan_info
= &zebra_if
->l2info
.vxl
;
1475 vty_out(vty
, " VxLAN Id %u", vxlan_info
->vni
);
1476 if (vxlan_info
->vtep_ip
.s_addr
!= INADDR_ANY
)
1477 vty_out(vty
, " VTEP IP: %s",
1478 inet_ntoa(vxlan_info
->vtep_ip
));
1479 if (vxlan_info
->access_vlan
)
1480 vty_out(vty
, " Access VLAN Id %u\n",
1481 vxlan_info
->access_vlan
);
1482 if (vxlan_info
->mcast_grp
.s_addr
!= INADDR_ANY
)
1483 vty_out(vty
, " Mcast Group %s",
1484 inet_ntoa(vxlan_info
->mcast_grp
));
1488 if (IS_ZEBRA_IF_BRIDGE_SLAVE(ifp
)) {
1489 struct zebra_l2info_brslave
*br_slave
;
1491 br_slave
= &zebra_if
->brslave_info
;
1492 if (br_slave
->bridge_ifindex
!= IFINDEX_INTERNAL
) {
1493 if (br_slave
->br_if
)
1494 vty_out(vty
, " Master interface: %s\n",
1495 br_slave
->br_if
->name
);
1497 vty_out(vty
, " Master ifindex: %u\n",
1498 br_slave
->bridge_ifindex
);
1502 if (IS_ZEBRA_IF_BOND_SLAVE(ifp
)) {
1503 struct zebra_l2info_bondslave
*bond_slave
;
1505 bond_slave
= &zebra_if
->bondslave_info
;
1506 if (bond_slave
->bond_ifindex
!= IFINDEX_INTERNAL
) {
1507 if (bond_slave
->bond_if
)
1508 vty_out(vty
, " Master interface: %s\n",
1509 bond_slave
->bond_if
->name
);
1511 vty_out(vty
, " Master ifindex: %u\n",
1512 bond_slave
->bond_ifindex
);
1516 if (zebra_if
->link_ifindex
!= IFINDEX_INTERNAL
) {
1518 vty_out(vty
, " Parent interface: %s\n", zebra_if
->link
->name
);
1520 vty_out(vty
, " Parent ifindex: %d\n", zebra_if
->link_ifindex
);
1523 if (HAS_LINK_PARAMS(ifp
)) {
1525 struct if_link_params
*iflp
= ifp
->link_params
;
1526 vty_out(vty
, " Traffic Engineering Link Parameters:\n");
1527 if (IS_PARAM_SET(iflp
, LP_TE_METRIC
))
1528 vty_out(vty
, " TE metric %u\n", iflp
->te_metric
);
1529 if (IS_PARAM_SET(iflp
, LP_MAX_BW
))
1530 vty_out(vty
, " Maximum Bandwidth %g (Byte/s)\n",
1532 if (IS_PARAM_SET(iflp
, LP_MAX_RSV_BW
))
1534 " Maximum Reservable Bandwidth %g (Byte/s)\n",
1536 if (IS_PARAM_SET(iflp
, LP_UNRSV_BW
)) {
1538 " Unreserved Bandwidth per Class Type in Byte/s:\n");
1539 for (i
= 0; i
< MAX_CLASS_TYPE
; i
+= 2)
1541 " [%d]: %g (Bytes/sec),\t[%d]: %g (Bytes/sec)\n",
1542 i
, iflp
->unrsv_bw
[i
], i
+ 1,
1543 iflp
->unrsv_bw
[i
+ 1]);
1546 if (IS_PARAM_SET(iflp
, LP_ADM_GRP
))
1547 vty_out(vty
, " Administrative Group:%u\n",
1549 if (IS_PARAM_SET(iflp
, LP_DELAY
)) {
1550 vty_out(vty
, " Link Delay Average: %u (micro-sec.)",
1552 if (IS_PARAM_SET(iflp
, LP_MM_DELAY
)) {
1553 vty_out(vty
, " Min: %u (micro-sec.)",
1555 vty_out(vty
, " Max: %u (micro-sec.)",
1560 if (IS_PARAM_SET(iflp
, LP_DELAY_VAR
))
1562 " Link Delay Variation %u (micro-sec.)\n",
1564 if (IS_PARAM_SET(iflp
, LP_PKT_LOSS
))
1565 vty_out(vty
, " Link Packet Loss %g (in %%)\n",
1567 if (IS_PARAM_SET(iflp
, LP_AVA_BW
))
1568 vty_out(vty
, " Available Bandwidth %g (Byte/s)\n",
1570 if (IS_PARAM_SET(iflp
, LP_RES_BW
))
1571 vty_out(vty
, " Residual Bandwidth %g (Byte/s)\n",
1573 if (IS_PARAM_SET(iflp
, LP_USE_BW
))
1574 vty_out(vty
, " Utilized Bandwidth %g (Byte/s)\n",
1576 if (IS_PARAM_SET(iflp
, LP_RMT_AS
))
1577 vty_out(vty
, " Neighbor ASBR IP: %s AS: %u \n",
1578 inet_ntoa(iflp
->rmt_ip
), iflp
->rmt_as
);
1581 hook_call(zebra_if_extra_info
, vty
, ifp
);
1583 if (listhead(ifp
->nbr_connected
))
1584 vty_out(vty
, " Neighbor address(s):\n");
1585 for (ALL_LIST_ELEMENTS_RO(ifp
->nbr_connected
, node
, nbr_connected
))
1586 nbr_connected_dump_vty(vty
, nbr_connected
);
1588 #ifdef HAVE_PROC_NET_DEV
1589 /* Statistics print out using proc file system. */
1591 " %lu input packets (%lu multicast), %lu bytes, "
1593 ifp
->stats
.rx_packets
, ifp
->stats
.rx_multicast
,
1594 ifp
->stats
.rx_bytes
, ifp
->stats
.rx_dropped
);
1597 " %lu input errors, %lu length, %lu overrun,"
1598 " %lu CRC, %lu frame\n",
1599 ifp
->stats
.rx_errors
, ifp
->stats
.rx_length_errors
,
1600 ifp
->stats
.rx_over_errors
, ifp
->stats
.rx_crc_errors
,
1601 ifp
->stats
.rx_frame_errors
);
1603 vty_out(vty
, " %lu fifo, %lu missed\n", ifp
->stats
.rx_fifo_errors
,
1604 ifp
->stats
.rx_missed_errors
);
1606 vty_out(vty
, " %lu output packets, %lu bytes, %lu dropped\n",
1607 ifp
->stats
.tx_packets
, ifp
->stats
.tx_bytes
,
1608 ifp
->stats
.tx_dropped
);
1611 " %lu output errors, %lu aborted, %lu carrier,"
1612 " %lu fifo, %lu heartbeat\n",
1613 ifp
->stats
.tx_errors
, ifp
->stats
.tx_aborted_errors
,
1614 ifp
->stats
.tx_carrier_errors
, ifp
->stats
.tx_fifo_errors
,
1615 ifp
->stats
.tx_heartbeat_errors
);
1617 vty_out(vty
, " %lu window, %lu collisions\n",
1618 ifp
->stats
.tx_window_errors
, ifp
->stats
.collisions
);
1619 #endif /* HAVE_PROC_NET_DEV */
1621 #ifdef HAVE_NET_RT_IFLIST
1622 /* Statistics print out using sysctl (). */
1624 " input packets %llu, bytes %llu, dropped %llu,"
1625 " multicast packets %llu\n",
1626 (unsigned long long)ifp
->stats
.ifi_ipackets
,
1627 (unsigned long long)ifp
->stats
.ifi_ibytes
,
1628 (unsigned long long)ifp
->stats
.ifi_iqdrops
,
1629 (unsigned long long)ifp
->stats
.ifi_imcasts
);
1631 vty_out(vty
, " input errors %llu\n",
1632 (unsigned long long)ifp
->stats
.ifi_ierrors
);
1635 " output packets %llu, bytes %llu,"
1636 " multicast packets %llu\n",
1637 (unsigned long long)ifp
->stats
.ifi_opackets
,
1638 (unsigned long long)ifp
->stats
.ifi_obytes
,
1639 (unsigned long long)ifp
->stats
.ifi_omcasts
);
1641 vty_out(vty
, " output errors %llu\n",
1642 (unsigned long long)ifp
->stats
.ifi_oerrors
);
1644 vty_out(vty
, " collisions %llu\n",
1645 (unsigned long long)ifp
->stats
.ifi_collisions
);
1646 #endif /* HAVE_NET_RT_IFLIST */
1649 static void interface_update_stats(void)
1651 #ifdef HAVE_PROC_NET_DEV
1652 /* If system has interface statistics via proc file system, update
1654 ifstat_update_proc();
1655 #endif /* HAVE_PROC_NET_DEV */
1656 #ifdef HAVE_NET_RT_IFLIST
1657 ifstat_update_sysctl();
1658 #endif /* HAVE_NET_RT_IFLIST */
1661 struct cmd_node interface_node
= {INTERFACE_NODE
, "%s(config-if)# ", 1};
1663 #ifndef VTYSH_EXTRACT_PL
1664 #include "zebra/interface_clippy.c"
1666 /* Show all interfaces to vty. */
1667 DEFPY(show_interface
, show_interface_cmd
,
1668 "show interface [vrf NAME$vrf_name] [brief$brief]",
1670 "Interface status and configuration\n"
1672 "Interface status and configuration summary\n")
1675 struct interface
*ifp
;
1676 vrf_id_t vrf_id
= VRF_DEFAULT
;
1678 interface_update_stats();
1681 VRF_GET_ID(vrf_id
, vrf_name
, false);
1683 /* All interface print. */
1684 vrf
= vrf_lookup_by_id(vrf_id
);
1686 ifs_dump_brief_vty(vty
, vrf
);
1688 FOR_ALL_INTERFACES (vrf
, ifp
) {
1689 if_dump_vty(vty
, ifp
);
1697 /* Show all interfaces to vty. */
1698 DEFPY (show_interface_vrf_all
,
1699 show_interface_vrf_all_cmd
,
1700 "show interface vrf all [brief$brief]",
1702 "Interface status and configuration\n"
1703 VRF_ALL_CMD_HELP_STR
1704 "Interface status and configuration summary\n")
1707 struct interface
*ifp
;
1709 interface_update_stats();
1711 /* All interface print. */
1712 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
1714 ifs_dump_brief_vty(vty
, vrf
);
1716 FOR_ALL_INTERFACES (vrf
, ifp
)
1717 if_dump_vty(vty
, ifp
);
1724 /* Show specified interface to vty. */
1726 DEFUN (show_interface_name_vrf
,
1727 show_interface_name_vrf_cmd
,
1728 "show interface IFNAME vrf NAME",
1730 "Interface status and configuration\n"
1736 struct interface
*ifp
;
1739 interface_update_stats();
1741 VRF_GET_ID(vrf_id
, argv
[idx_name
]->arg
, false);
1743 /* Specified interface print. */
1744 ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
, vrf_id
);
1746 vty_out(vty
, "%% Can't find interface %s\n",
1747 argv
[idx_ifname
]->arg
);
1750 if_dump_vty(vty
, ifp
);
1755 /* Show specified interface to vty. */
1756 DEFUN (show_interface_name_vrf_all
,
1757 show_interface_name_vrf_all_cmd
,
1758 "show interface IFNAME [vrf all]",
1760 "Interface status and configuration\n"
1762 VRF_ALL_CMD_HELP_STR
)
1766 struct interface
*ifp
;
1769 interface_update_stats();
1771 /* All interface print. */
1772 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
1773 /* Specified interface print. */
1774 ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
, vrf
->vrf_id
);
1776 if_dump_vty(vty
, ifp
);
1782 vty_out(vty
, "%% Can't find interface %s\n",
1783 argv
[idx_ifname
]->arg
);
1791 static void if_show_description(struct vty
*vty
, vrf_id_t vrf_id
)
1793 struct vrf
*vrf
= vrf_lookup_by_id(vrf_id
);
1794 struct interface
*ifp
;
1796 vty_out(vty
, "Interface Status Protocol Description\n");
1797 FOR_ALL_INTERFACES (vrf
, ifp
) {
1799 struct zebra_if
*zif
;
1804 len
= vty_out(vty
, "%s", ifp
->name
);
1805 vty_out(vty
, "%*s", (16 - len
), " ");
1807 if (if_is_up(ifp
)) {
1808 vty_out(vty
, "up ");
1809 if (CHECK_FLAG(ifp
->status
,
1810 ZEBRA_INTERFACE_LINKDETECTION
)) {
1811 if (if_is_running(ifp
))
1812 vty_out(vty
, "up ");
1814 vty_out(vty
, "down ");
1816 vty_out(vty
, "unknown ");
1819 vty_out(vty
, "down down ");
1824 vty_out(vty
, "%s", ifp
->desc
);
1827 if (zif
&& zif
->desc
) {
1828 vty_out(vty
, "%s%s",
1839 DEFUN (show_interface_desc
,
1840 show_interface_desc_cmd
,
1841 "show interface description [vrf NAME]",
1843 "Interface status and configuration\n"
1844 "Interface description\n"
1847 vrf_id_t vrf_id
= VRF_DEFAULT
;
1850 VRF_GET_ID(vrf_id
, argv
[4]->arg
, false);
1852 if_show_description(vty
, vrf_id
);
1858 DEFUN (show_interface_desc_vrf_all
,
1859 show_interface_desc_vrf_all_cmd
,
1860 "show interface description vrf all",
1862 "Interface status and configuration\n"
1863 "Interface description\n"
1864 VRF_ALL_CMD_HELP_STR
)
1868 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
1869 if (!RB_EMPTY(if_name_head
, &vrf
->ifaces_by_name
)) {
1870 vty_out(vty
, "\n\tVRF %u\n\n", vrf
->vrf_id
);
1871 if_show_description(vty
, vrf
->vrf_id
);
1880 "Set multicast flag to interface\n")
1882 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1884 struct zebra_if
*if_data
;
1886 if (CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
)) {
1887 ret
= if_set_flags(ifp
, IFF_MULTICAST
);
1889 vty_out(vty
, "Can't set multicast flag\n");
1890 return CMD_WARNING_CONFIG_FAILED
;
1894 if_data
= ifp
->info
;
1895 if_data
->multicast
= IF_ZEBRA_MULTICAST_ON
;
1900 DEFUN (no_multicast
,
1904 "Unset multicast flag to interface\n")
1906 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1908 struct zebra_if
*if_data
;
1910 if (CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
)) {
1911 ret
= if_unset_flags(ifp
, IFF_MULTICAST
);
1913 vty_out(vty
, "Can't unset multicast flag\n");
1914 return CMD_WARNING_CONFIG_FAILED
;
1918 if_data
= ifp
->info
;
1919 if_data
->multicast
= IF_ZEBRA_MULTICAST_OFF
;
1927 "Enable link detection on interface\n")
1929 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1930 int if_was_operative
;
1932 if_was_operative
= if_is_no_ptm_operative(ifp
);
1933 SET_FLAG(ifp
->status
, ZEBRA_INTERFACE_LINKDETECTION
);
1935 /* When linkdetection is enabled, if might come down */
1936 if (!if_is_no_ptm_operative(ifp
) && if_was_operative
)
1939 /* FIXME: Will defer status change forwarding if interface
1940 does not come down! */
1946 DEFUN (no_linkdetect
,
1950 "Disable link detection on interface\n")
1952 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1953 int if_was_operative
;
1955 if_was_operative
= if_is_no_ptm_operative(ifp
);
1956 UNSET_FLAG(ifp
->status
, ZEBRA_INTERFACE_LINKDETECTION
);
1958 /* Interface may come up after disabling link detection */
1959 if (if_is_operative(ifp
) && !if_was_operative
)
1962 /* FIXME: see linkdetect_cmd */
1970 "Shutdown the selected interface\n")
1972 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1974 struct zebra_if
*if_data
;
1976 if (ifp
->ifindex
!= IFINDEX_INTERNAL
) {
1977 ret
= if_unset_flags(ifp
, IFF_UP
);
1979 vty_out(vty
, "Can't shutdown interface\n");
1980 return CMD_WARNING_CONFIG_FAILED
;
1984 if_data
= ifp
->info
;
1985 if_data
->shutdown
= IF_ZEBRA_SHUTDOWN_ON
;
1990 DEFUN (no_shutdown_if
,
1994 "Shutdown the selected interface\n")
1996 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1998 struct zebra_if
*if_data
;
2000 if (ifp
->ifindex
!= IFINDEX_INTERNAL
) {
2001 ret
= if_set_flags(ifp
, IFF_UP
| IFF_RUNNING
);
2003 vty_out(vty
, "Can't up interface\n");
2004 return CMD_WARNING_CONFIG_FAILED
;
2008 /* Some addresses (in particular, IPv6 addresses on Linux) get
2009 * removed when the interface goes down. They need to be
2012 if_addr_wakeup(ifp
);
2015 if_data
= ifp
->info
;
2016 if_data
->shutdown
= IF_ZEBRA_SHUTDOWN_OFF
;
2021 DEFUN (bandwidth_if
,
2023 "bandwidth (1-100000)",
2024 "Set bandwidth informational parameter\n"
2025 "Bandwidth in megabits\n")
2028 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2029 unsigned int bandwidth
;
2031 bandwidth
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
2033 /* bandwidth range is <1-100000> */
2034 if (bandwidth
< 1 || bandwidth
> 100000) {
2035 vty_out(vty
, "Bandwidth is invalid\n");
2036 return CMD_WARNING_CONFIG_FAILED
;
2039 ifp
->bandwidth
= bandwidth
;
2041 /* force protocols to recalculate routes due to cost change */
2042 if (if_is_operative(ifp
))
2043 zebra_interface_up_update(ifp
);
2048 DEFUN (no_bandwidth_if
,
2049 no_bandwidth_if_cmd
,
2050 "no bandwidth [(1-100000)]",
2052 "Set bandwidth informational parameter\n"
2053 "Bandwidth in megabits\n")
2055 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2059 /* force protocols to recalculate routes due to cost change */
2060 if (if_is_operative(ifp
))
2061 zebra_interface_up_update(ifp
);
2067 struct cmd_node link_params_node
= {
2068 LINK_PARAMS_NODE
, "%s(config-link-params)# ", 1,
2071 static void link_param_cmd_set_uint32(struct interface
*ifp
, uint32_t *field
,
2072 uint32_t type
, uint32_t value
)
2074 /* Update field as needed */
2075 if (IS_PARAM_UNSET(ifp
->link_params
, type
) || *field
!= value
) {
2077 SET_PARAM(ifp
->link_params
, type
);
2079 /* force protocols to update LINK STATE due to parameters change
2081 if (if_is_operative(ifp
))
2082 zebra_interface_parameters_update(ifp
);
2085 static void link_param_cmd_set_float(struct interface
*ifp
, float *field
,
2086 uint32_t type
, float value
)
2089 /* Update field as needed */
2090 if (IS_PARAM_UNSET(ifp
->link_params
, type
) || *field
!= value
) {
2092 SET_PARAM(ifp
->link_params
, type
);
2094 /* force protocols to update LINK STATE due to parameters change
2096 if (if_is_operative(ifp
))
2097 zebra_interface_parameters_update(ifp
);
2101 static void link_param_cmd_unset(struct interface
*ifp
, uint32_t type
)
2103 if (ifp
->link_params
== NULL
)
2107 UNSET_PARAM(ifp
->link_params
, type
);
2109 /* force protocols to update LINK STATE due to parameters change */
2110 if (if_is_operative(ifp
))
2111 zebra_interface_parameters_update(ifp
);
2114 DEFUN_NOSH (link_params
,
2119 /* vty->qobj_index stays the same @ interface pointer */
2120 vty
->node
= LINK_PARAMS_NODE
;
2125 DEFUN_NOSH (exit_link_params
,
2126 exit_link_params_cmd
,
2128 "Exit from Link Params configuration mode\n")
2130 if (vty
->node
== LINK_PARAMS_NODE
)
2131 vty
->node
= INTERFACE_NODE
;
2135 /* Specific Traffic Engineering parameters commands */
2136 DEFUN (link_params_enable
,
2137 link_params_enable_cmd
,
2139 "Activate link parameters on this interface\n")
2141 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2143 /* This command could be issue at startup, when activate MPLS TE */
2144 /* on a new interface or after a ON / OFF / ON toggle */
2145 /* In all case, TE parameters are reset to their default factory */
2146 if (IS_ZEBRA_DEBUG_EVENT
|| IS_ZEBRA_DEBUG_MPLS
)
2148 "Link-params: enable TE link parameters on interface %s",
2151 if (!if_link_params_get(ifp
)) {
2152 if (IS_ZEBRA_DEBUG_EVENT
|| IS_ZEBRA_DEBUG_MPLS
)
2154 "Link-params: failed to init TE link parameters %s",
2157 return CMD_WARNING_CONFIG_FAILED
;
2160 /* force protocols to update LINK STATE due to parameters change */
2161 if (if_is_operative(ifp
))
2162 zebra_interface_parameters_update(ifp
);
2167 DEFUN (no_link_params_enable
,
2168 no_link_params_enable_cmd
,
2171 "Disable link parameters on this interface\n")
2173 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2175 if (IS_ZEBRA_DEBUG_EVENT
|| IS_ZEBRA_DEBUG_MPLS
)
2176 zlog_debug("MPLS-TE: disable TE link parameters on interface %s",
2179 if_link_params_free(ifp
);
2181 /* force protocols to update LINK STATE due to parameters change */
2182 if (if_is_operative(ifp
))
2183 zebra_interface_parameters_update(ifp
);
2188 /* STANDARD TE metrics */
2189 DEFUN (link_params_metric
,
2190 link_params_metric_cmd
,
2191 "metric (0-4294967295)",
2192 "Link metric for MPLS-TE purpose\n"
2193 "Metric value in decimal\n")
2196 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2197 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2200 metric
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2202 /* Update TE metric if needed */
2203 link_param_cmd_set_uint32(ifp
, &iflp
->te_metric
, LP_TE_METRIC
, metric
);
2208 DEFUN (no_link_params_metric
,
2209 no_link_params_metric_cmd
,
2212 "Disable Link Metric on this interface\n")
2214 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2216 /* Unset TE Metric */
2217 link_param_cmd_unset(ifp
, LP_TE_METRIC
);
2222 DEFUN (link_params_maxbw
,
2223 link_params_maxbw_cmd
,
2225 "Maximum bandwidth that can be used\n"
2226 "Bytes/second (IEEE floating point format)\n")
2228 int idx_bandwidth
= 1;
2229 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2230 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2234 if (sscanf(argv
[idx_bandwidth
]->arg
, "%g", &bw
) != 1) {
2235 vty_out(vty
, "link_params_maxbw: fscanf: %s\n",
2236 safe_strerror(errno
));
2237 return CMD_WARNING_CONFIG_FAILED
;
2240 /* Check that Maximum bandwidth is not lower than other bandwidth
2242 if ((bw
<= iflp
->max_rsv_bw
) || (bw
<= iflp
->unrsv_bw
[0])
2243 || (bw
<= iflp
->unrsv_bw
[1]) || (bw
<= iflp
->unrsv_bw
[2])
2244 || (bw
<= iflp
->unrsv_bw
[3]) || (bw
<= iflp
->unrsv_bw
[4])
2245 || (bw
<= iflp
->unrsv_bw
[5]) || (bw
<= iflp
->unrsv_bw
[6])
2246 || (bw
<= iflp
->unrsv_bw
[7]) || (bw
<= iflp
->ava_bw
)
2247 || (bw
<= iflp
->res_bw
) || (bw
<= iflp
->use_bw
)) {
2249 "Maximum Bandwidth could not be lower than others bandwidth\n");
2250 return CMD_WARNING_CONFIG_FAILED
;
2253 /* Update Maximum Bandwidth if needed */
2254 link_param_cmd_set_float(ifp
, &iflp
->max_bw
, LP_MAX_BW
, bw
);
2259 DEFUN (link_params_max_rsv_bw
,
2260 link_params_max_rsv_bw_cmd
,
2261 "max-rsv-bw BANDWIDTH",
2262 "Maximum bandwidth that may be reserved\n"
2263 "Bytes/second (IEEE floating point format)\n")
2265 int idx_bandwidth
= 1;
2266 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2267 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2270 if (sscanf(argv
[idx_bandwidth
]->arg
, "%g", &bw
) != 1) {
2271 vty_out(vty
, "link_params_max_rsv_bw: fscanf: %s\n",
2272 safe_strerror(errno
));
2273 return CMD_WARNING_CONFIG_FAILED
;
2276 /* Check that bandwidth is not greater than maximum bandwidth parameter
2278 if (bw
> iflp
->max_bw
) {
2280 "Maximum Reservable Bandwidth could not be greater than Maximum Bandwidth (%g)\n",
2282 return CMD_WARNING_CONFIG_FAILED
;
2285 /* Update Maximum Reservable Bandwidth if needed */
2286 link_param_cmd_set_float(ifp
, &iflp
->max_rsv_bw
, LP_MAX_RSV_BW
, bw
);
2291 DEFUN (link_params_unrsv_bw
,
2292 link_params_unrsv_bw_cmd
,
2293 "unrsv-bw (0-7) BANDWIDTH",
2294 "Unreserved bandwidth at each priority level\n"
2296 "Bytes/second (IEEE floating point format)\n")
2299 int idx_bandwidth
= 2;
2300 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2301 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2305 /* We don't have to consider about range check here. */
2306 if (sscanf(argv
[idx_number
]->arg
, "%d", &priority
) != 1) {
2307 vty_out(vty
, "link_params_unrsv_bw: fscanf: %s\n",
2308 safe_strerror(errno
));
2309 return CMD_WARNING_CONFIG_FAILED
;
2312 if (sscanf(argv
[idx_bandwidth
]->arg
, "%g", &bw
) != 1) {
2313 vty_out(vty
, "link_params_unrsv_bw: fscanf: %s\n",
2314 safe_strerror(errno
));
2315 return CMD_WARNING_CONFIG_FAILED
;
2318 /* Check that bandwidth is not greater than maximum bandwidth parameter
2320 if (bw
> iflp
->max_bw
) {
2322 "UnReserved Bandwidth could not be greater than Maximum Bandwidth (%g)\n",
2324 return CMD_WARNING_CONFIG_FAILED
;
2327 /* Update Unreserved Bandwidth if needed */
2328 link_param_cmd_set_float(ifp
, &iflp
->unrsv_bw
[priority
], LP_UNRSV_BW
,
2334 DEFUN (link_params_admin_grp
,
2335 link_params_admin_grp_cmd
,
2336 "admin-grp BITPATTERN",
2337 "Administrative group membership\n"
2338 "32-bit Hexadecimal value (e.g. 0xa1)\n")
2340 int idx_bitpattern
= 1;
2341 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2342 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2343 unsigned long value
;
2345 if (sscanf(argv
[idx_bitpattern
]->arg
, "0x%lx", &value
) != 1) {
2346 vty_out(vty
, "link_params_admin_grp: fscanf: %s\n",
2347 safe_strerror(errno
));
2348 return CMD_WARNING_CONFIG_FAILED
;
2351 /* Update Administrative Group if needed */
2352 link_param_cmd_set_uint32(ifp
, &iflp
->admin_grp
, LP_ADM_GRP
, value
);
2357 DEFUN (no_link_params_admin_grp
,
2358 no_link_params_admin_grp_cmd
,
2361 "Disable Administrative group membership on this interface\n")
2363 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2365 /* Unset Admin Group */
2366 link_param_cmd_unset(ifp
, LP_ADM_GRP
);
2371 /* RFC5392 & RFC5316: INTER-AS */
2372 DEFUN (link_params_inter_as
,
2373 link_params_inter_as_cmd
,
2374 "neighbor A.B.C.D as (1-4294967295)",
2375 "Configure remote ASBR information (Neighbor IP address and AS number)\n"
2376 "Remote IP address in dot decimal A.B.C.D\n"
2377 "Remote AS number\n"
2378 "AS number in the range <1-4294967295>\n")
2383 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2384 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2385 struct in_addr addr
;
2388 if (!inet_aton(argv
[idx_ipv4
]->arg
, &addr
)) {
2389 vty_out(vty
, "Please specify Router-Addr by A.B.C.D\n");
2390 return CMD_WARNING_CONFIG_FAILED
;
2393 as
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2395 /* Update Remote IP and Remote AS fields if needed */
2396 if (IS_PARAM_UNSET(iflp
, LP_RMT_AS
) || iflp
->rmt_as
!= as
2397 || iflp
->rmt_ip
.s_addr
!= addr
.s_addr
) {
2400 iflp
->rmt_ip
.s_addr
= addr
.s_addr
;
2401 SET_PARAM(iflp
, LP_RMT_AS
);
2403 /* force protocols to update LINK STATE due to parameters change
2405 if (if_is_operative(ifp
))
2406 zebra_interface_parameters_update(ifp
);
2411 DEFUN (no_link_params_inter_as
,
2412 no_link_params_inter_as_cmd
,
2415 "Remove Neighbor IP address and AS number for Inter-AS TE\n")
2417 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2418 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2420 /* Reset Remote IP and AS neighbor */
2422 iflp
->rmt_ip
.s_addr
= 0;
2423 UNSET_PARAM(iflp
, LP_RMT_AS
);
2425 /* force protocols to update LINK STATE due to parameters change */
2426 if (if_is_operative(ifp
))
2427 zebra_interface_parameters_update(ifp
);
2432 /* RFC7471: OSPF Traffic Engineering (TE) Metric extensions &
2433 * draft-ietf-isis-metric-extensions-07.txt */
2434 DEFUN (link_params_delay
,
2435 link_params_delay_cmd
,
2436 "delay (0-16777215) [min (0-16777215) max (0-16777215)]",
2437 "Unidirectional Average Link Delay\n"
2438 "Average delay in micro-second as decimal (0...16777215)\n"
2440 "Minimum delay in micro-second as decimal (0...16777215)\n"
2442 "Maximum delay in micro-second as decimal (0...16777215)\n")
2444 /* Get and Check new delay values */
2445 uint32_t delay
= 0, low
= 0, high
= 0;
2446 delay
= strtoul(argv
[1]->arg
, NULL
, 10);
2448 low
= strtoul(argv
[3]->arg
, NULL
, 10);
2449 high
= strtoul(argv
[5]->arg
, NULL
, 10);
2452 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2453 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2457 /* Check new delay value against old Min and Max delays if set
2459 if (IS_PARAM_SET(iflp
, LP_MM_DELAY
)
2460 && (delay
<= iflp
->min_delay
|| delay
>= iflp
->max_delay
)) {
2462 "Average delay should be comprise between Min (%d) and Max (%d) delay\n",
2463 iflp
->min_delay
, iflp
->max_delay
);
2464 return CMD_WARNING_CONFIG_FAILED
;
2466 /* Update delay if value is not set or change */
2467 if (IS_PARAM_UNSET(iflp
, LP_DELAY
) || iflp
->av_delay
!= delay
) {
2468 iflp
->av_delay
= delay
;
2469 SET_PARAM(iflp
, LP_DELAY
);
2472 /* Unset Min and Max delays if already set */
2473 if (IS_PARAM_SET(iflp
, LP_MM_DELAY
)) {
2474 iflp
->min_delay
= 0;
2475 iflp
->max_delay
= 0;
2476 UNSET_PARAM(iflp
, LP_MM_DELAY
);
2480 /* Check new delays value coherency */
2481 if (delay
<= low
|| delay
>= high
) {
2483 "Average delay should be comprise between Min (%d) and Max (%d) delay\n",
2485 return CMD_WARNING_CONFIG_FAILED
;
2487 /* Update Delays if needed */
2488 if (IS_PARAM_UNSET(iflp
, LP_DELAY
)
2489 || IS_PARAM_UNSET(iflp
, LP_MM_DELAY
)
2490 || iflp
->av_delay
!= delay
|| iflp
->min_delay
!= low
2491 || iflp
->max_delay
!= high
) {
2492 iflp
->av_delay
= delay
;
2493 SET_PARAM(iflp
, LP_DELAY
);
2494 iflp
->min_delay
= low
;
2495 iflp
->max_delay
= high
;
2496 SET_PARAM(iflp
, LP_MM_DELAY
);
2501 /* force protocols to update LINK STATE due to parameters change */
2502 if (update
== 1 && if_is_operative(ifp
))
2503 zebra_interface_parameters_update(ifp
);
2508 DEFUN (no_link_params_delay
,
2509 no_link_params_delay_cmd
,
2512 "Disable Unidirectional Average, Min & Max Link Delay on this interface\n")
2514 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2515 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2519 UNSET_PARAM(iflp
, LP_DELAY
);
2520 iflp
->min_delay
= 0;
2521 iflp
->max_delay
= 0;
2522 UNSET_PARAM(iflp
, LP_MM_DELAY
);
2524 /* force protocols to update LINK STATE due to parameters change */
2525 if (if_is_operative(ifp
))
2526 zebra_interface_parameters_update(ifp
);
2531 DEFUN (link_params_delay_var
,
2532 link_params_delay_var_cmd
,
2533 "delay-variation (0-16777215)",
2534 "Unidirectional Link Delay Variation\n"
2535 "delay variation in micro-second as decimal (0...16777215)\n")
2538 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2539 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2542 value
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2544 /* Update Delay Variation if needed */
2545 link_param_cmd_set_uint32(ifp
, &iflp
->delay_var
, LP_DELAY_VAR
, value
);
2550 DEFUN (no_link_params_delay_var
,
2551 no_link_params_delay_var_cmd
,
2552 "no delay-variation",
2554 "Disable Unidirectional Delay Variation on this interface\n")
2556 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2558 /* Unset Delay Variation */
2559 link_param_cmd_unset(ifp
, LP_DELAY_VAR
);
2564 DEFUN (link_params_pkt_loss
,
2565 link_params_pkt_loss_cmd
,
2566 "packet-loss PERCENTAGE",
2567 "Unidirectional Link Packet Loss\n"
2568 "percentage of total traffic by 0.000003% step and less than 50.331642%\n")
2570 int idx_percentage
= 1;
2571 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2572 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2575 if (sscanf(argv
[idx_percentage
]->arg
, "%g", &fval
) != 1) {
2576 vty_out(vty
, "link_params_pkt_loss: fscanf: %s\n",
2577 safe_strerror(errno
));
2578 return CMD_WARNING_CONFIG_FAILED
;
2581 if (fval
> MAX_PKT_LOSS
)
2582 fval
= MAX_PKT_LOSS
;
2584 /* Update Packet Loss if needed */
2585 link_param_cmd_set_float(ifp
, &iflp
->pkt_loss
, LP_PKT_LOSS
, fval
);
2590 DEFUN (no_link_params_pkt_loss
,
2591 no_link_params_pkt_loss_cmd
,
2594 "Disable Unidirectional Link Packet Loss on this interface\n")
2596 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2598 /* Unset Packet Loss */
2599 link_param_cmd_unset(ifp
, LP_PKT_LOSS
);
2604 DEFUN (link_params_res_bw
,
2605 link_params_res_bw_cmd
,
2607 "Unidirectional Residual Bandwidth\n"
2608 "Bytes/second (IEEE floating point format)\n")
2610 int idx_bandwidth
= 1;
2611 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2612 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2615 if (sscanf(argv
[idx_bandwidth
]->arg
, "%g", &bw
) != 1) {
2616 vty_out(vty
, "link_params_res_bw: fscanf: %s\n",
2617 safe_strerror(errno
));
2618 return CMD_WARNING_CONFIG_FAILED
;
2621 /* Check that bandwidth is not greater than maximum bandwidth parameter
2623 if (bw
> iflp
->max_bw
) {
2625 "Residual Bandwidth could not be greater than Maximum Bandwidth (%g)\n",
2627 return CMD_WARNING_CONFIG_FAILED
;
2630 /* Update Residual Bandwidth if needed */
2631 link_param_cmd_set_float(ifp
, &iflp
->res_bw
, LP_RES_BW
, bw
);
2636 DEFUN (no_link_params_res_bw
,
2637 no_link_params_res_bw_cmd
,
2640 "Disable Unidirectional Residual Bandwidth on this interface\n")
2642 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2644 /* Unset Residual Bandwidth */
2645 link_param_cmd_unset(ifp
, LP_RES_BW
);
2650 DEFUN (link_params_ava_bw
,
2651 link_params_ava_bw_cmd
,
2653 "Unidirectional Available Bandwidth\n"
2654 "Bytes/second (IEEE floating point format)\n")
2656 int idx_bandwidth
= 1;
2657 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2658 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2661 if (sscanf(argv
[idx_bandwidth
]->arg
, "%g", &bw
) != 1) {
2662 vty_out(vty
, "link_params_ava_bw: fscanf: %s\n",
2663 safe_strerror(errno
));
2664 return CMD_WARNING_CONFIG_FAILED
;
2667 /* Check that bandwidth is not greater than maximum bandwidth parameter
2669 if (bw
> iflp
->max_bw
) {
2671 "Available Bandwidth could not be greater than Maximum Bandwidth (%g)\n",
2673 return CMD_WARNING_CONFIG_FAILED
;
2676 /* Update Residual Bandwidth if needed */
2677 link_param_cmd_set_float(ifp
, &iflp
->ava_bw
, LP_AVA_BW
, bw
);
2682 DEFUN (no_link_params_ava_bw
,
2683 no_link_params_ava_bw_cmd
,
2686 "Disable Unidirectional Available Bandwidth on this interface\n")
2688 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2690 /* Unset Available Bandwidth */
2691 link_param_cmd_unset(ifp
, LP_AVA_BW
);
2696 DEFUN (link_params_use_bw
,
2697 link_params_use_bw_cmd
,
2699 "Unidirectional Utilised Bandwidth\n"
2700 "Bytes/second (IEEE floating point format)\n")
2702 int idx_bandwidth
= 1;
2703 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2704 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2707 if (sscanf(argv
[idx_bandwidth
]->arg
, "%g", &bw
) != 1) {
2708 vty_out(vty
, "link_params_use_bw: fscanf: %s\n",
2709 safe_strerror(errno
));
2710 return CMD_WARNING_CONFIG_FAILED
;
2713 /* Check that bandwidth is not greater than maximum bandwidth parameter
2715 if (bw
> iflp
->max_bw
) {
2717 "Utilised Bandwidth could not be greater than Maximum Bandwidth (%g)\n",
2719 return CMD_WARNING_CONFIG_FAILED
;
2722 /* Update Utilized Bandwidth if needed */
2723 link_param_cmd_set_float(ifp
, &iflp
->use_bw
, LP_USE_BW
, bw
);
2728 DEFUN (no_link_params_use_bw
,
2729 no_link_params_use_bw_cmd
,
2732 "Disable Unidirectional Utilised Bandwidth on this interface\n")
2734 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2736 /* Unset Utilised Bandwidth */
2737 link_param_cmd_unset(ifp
, LP_USE_BW
);
2742 static int ip_address_install(struct vty
*vty
, struct interface
*ifp
,
2743 const char *addr_str
, const char *peer_str
,
2746 struct zebra_if
*if_data
;
2747 struct prefix_ipv4 lp
, pp
;
2748 struct connected
*ifc
;
2749 struct prefix_ipv4
*p
;
2751 enum zebra_dplane_result dplane_res
;
2753 if_data
= ifp
->info
;
2755 ret
= str2prefix_ipv4(addr_str
, &lp
);
2757 vty_out(vty
, "%% Malformed address \n");
2758 return CMD_WARNING_CONFIG_FAILED
;
2761 if (ipv4_martian(&lp
.prefix
)) {
2762 vty_out(vty
, "%% Invalid address\n");
2763 return CMD_WARNING_CONFIG_FAILED
;
2767 if (lp
.prefixlen
!= 32) {
2769 "%% Local prefix length for P-t-P address must be /32\n");
2770 return CMD_WARNING_CONFIG_FAILED
;
2773 ret
= str2prefix_ipv4(peer_str
, &pp
);
2775 vty_out(vty
, "%% Malformed peer address\n");
2776 return CMD_WARNING_CONFIG_FAILED
;
2780 ifc
= connected_check_ptp(ifp
, &lp
, peer_str
? &pp
: NULL
);
2782 ifc
= connected_new();
2786 p
= prefix_ipv4_new();
2788 ifc
->address
= (struct prefix
*)p
;
2791 SET_FLAG(ifc
->flags
, ZEBRA_IFA_PEER
);
2792 p
= prefix_ipv4_new();
2794 ifc
->destination
= (struct prefix
*)p
;
2799 ifc
->label
= XSTRDUP(MTYPE_CONNECTED_LABEL
, label
);
2801 /* Add to linked list. */
2802 listnode_add(ifp
->connected
, ifc
);
2805 /* This address is configured from zebra. */
2806 if (!CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
2807 SET_FLAG(ifc
->conf
, ZEBRA_IFC_CONFIGURED
);
2809 /* In case of this route need to install kernel. */
2810 if (!CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
)
2811 && CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
)
2812 && !(if_data
&& if_data
->shutdown
== IF_ZEBRA_SHUTDOWN_ON
)) {
2813 /* Some system need to up the interface to set IP address. */
2814 if (!if_is_up(ifp
)) {
2815 if_set_flags(ifp
, IFF_UP
| IFF_RUNNING
);
2819 dplane_res
= dplane_intf_addr_set(ifp
, ifc
);
2820 if (dplane_res
== ZEBRA_DPLANE_REQUEST_FAILURE
) {
2821 vty_out(vty
, "%% Can't set interface IP address: %s.\n",
2822 dplane_res2str(dplane_res
));
2823 return CMD_WARNING_CONFIG_FAILED
;
2826 SET_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
);
2827 /* The address will be advertised to zebra clients when the
2829 * from the kernel has been received.
2830 * It will also be added to the subnet chain list, then. */
2836 static int ip_address_uninstall(struct vty
*vty
, struct interface
*ifp
,
2837 const char *addr_str
, const char *peer_str
,
2840 struct prefix_ipv4 lp
, pp
;
2841 struct connected
*ifc
;
2843 enum zebra_dplane_result dplane_res
;
2845 /* Convert to prefix structure. */
2846 ret
= str2prefix_ipv4(addr_str
, &lp
);
2848 vty_out(vty
, "%% Malformed address \n");
2849 return CMD_WARNING_CONFIG_FAILED
;
2853 if (lp
.prefixlen
!= 32) {
2855 "%% Local prefix length for P-t-P address must be /32\n");
2856 return CMD_WARNING_CONFIG_FAILED
;
2859 ret
= str2prefix_ipv4(peer_str
, &pp
);
2861 vty_out(vty
, "%% Malformed peer address\n");
2862 return CMD_WARNING_CONFIG_FAILED
;
2866 /* Check current interface address. */
2867 ifc
= connected_check_ptp(ifp
, &lp
, peer_str
? &pp
: NULL
);
2869 vty_out(vty
, "%% Can't find address\n");
2870 return CMD_WARNING_CONFIG_FAILED
;
2873 /* This is not configured address. */
2874 if (!CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
2875 return CMD_WARNING_CONFIG_FAILED
;
2877 UNSET_FLAG(ifc
->conf
, ZEBRA_IFC_CONFIGURED
);
2879 /* This is not real address or interface is not active. */
2880 if (!CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
)
2881 || !CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
)) {
2882 listnode_delete(ifp
->connected
, ifc
);
2883 connected_free(&ifc
);
2884 return CMD_WARNING_CONFIG_FAILED
;
2887 /* This is real route. */
2888 dplane_res
= dplane_intf_addr_unset(ifp
, ifc
);
2889 if (dplane_res
== ZEBRA_DPLANE_REQUEST_FAILURE
) {
2890 vty_out(vty
, "%% Can't unset interface IP address: %s.\n",
2891 dplane_res2str(dplane_res
));
2892 return CMD_WARNING_CONFIG_FAILED
;
2894 UNSET_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
);
2895 /* we will receive a kernel notification about this route being removed.
2896 * this will trigger its removal from the connected list. */
2902 "ip address A.B.C.D/M",
2903 "Interface Internet Protocol config commands\n"
2904 "Set the IP address of an interface\n"
2905 "IP address (e.g. 10.0.0.1/8)\n")
2907 int idx_ipv4_prefixlen
= 2;
2908 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2909 return ip_address_install(vty
, ifp
, argv
[idx_ipv4_prefixlen
]->arg
, NULL
,
2913 DEFUN (no_ip_address
,
2915 "no ip address A.B.C.D/M",
2917 "Interface Internet Protocol config commands\n"
2918 "Set the IP address of an interface\n"
2919 "IP Address (e.g. 10.0.0.1/8)\n")
2921 int idx_ipv4_prefixlen
= 3;
2922 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2923 return ip_address_uninstall(vty
, ifp
, argv
[idx_ipv4_prefixlen
]->arg
,
2927 DEFUN(ip_address_peer
,
2928 ip_address_peer_cmd
,
2929 "ip address A.B.C.D peer A.B.C.D/M",
2930 "Interface Internet Protocol config commands\n"
2931 "Set the IP address of an interface\n"
2932 "Local IP (e.g. 10.0.0.1) for P-t-P address\n"
2933 "Specify P-t-P address\n"
2934 "Peer IP address (e.g. 10.0.0.1/8)\n")
2936 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2937 return ip_address_install(vty
, ifp
, argv
[2]->arg
, argv
[4]->arg
, NULL
);
2940 DEFUN(no_ip_address_peer
,
2941 no_ip_address_peer_cmd
,
2942 "no ip address A.B.C.D peer A.B.C.D/M",
2944 "Interface Internet Protocol config commands\n"
2945 "Set the IP address of an interface\n"
2946 "Local IP (e.g. 10.0.0.1) for P-t-P address\n"
2947 "Specify P-t-P address\n"
2948 "Peer IP address (e.g. 10.0.0.1/8)\n")
2950 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2951 return ip_address_uninstall(vty
, ifp
, argv
[3]->arg
, argv
[5]->arg
, NULL
);
2955 DEFUN (ip_address_label
,
2956 ip_address_label_cmd
,
2957 "ip address A.B.C.D/M label LINE",
2958 "Interface Internet Protocol config commands\n"
2959 "Set the IP address of an interface\n"
2960 "IP address (e.g. 10.0.0.1/8)\n"
2961 "Label of this address\n"
2964 int idx_ipv4_prefixlen
= 2;
2966 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2967 return ip_address_install(vty
, ifp
, argv
[idx_ipv4_prefixlen
]->arg
, NULL
,
2968 argv
[idx_line
]->arg
);
2971 DEFUN (no_ip_address_label
,
2972 no_ip_address_label_cmd
,
2973 "no ip address A.B.C.D/M label LINE",
2975 "Interface Internet Protocol config commands\n"
2976 "Set the IP address of an interface\n"
2977 "IP address (e.g. 10.0.0.1/8)\n"
2978 "Label of this address\n"
2981 int idx_ipv4_prefixlen
= 3;
2983 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2984 return ip_address_uninstall(vty
, ifp
, argv
[idx_ipv4_prefixlen
]->arg
,
2985 NULL
, argv
[idx_line
]->arg
);
2987 #endif /* HAVE_NETLINK */
2989 static int ipv6_address_install(struct vty
*vty
, struct interface
*ifp
,
2990 const char *addr_str
, const char *peer_str
,
2993 struct zebra_if
*if_data
;
2994 struct prefix_ipv6 cp
;
2995 struct connected
*ifc
;
2996 struct prefix_ipv6
*p
;
2998 enum zebra_dplane_result dplane_res
;
3000 if_data
= ifp
->info
;
3002 ret
= str2prefix_ipv6(addr_str
, &cp
);
3004 vty_out(vty
, "%% Malformed address \n");
3005 return CMD_WARNING_CONFIG_FAILED
;
3008 if (ipv6_martian(&cp
.prefix
)) {
3009 vty_out(vty
, "%% Invalid address\n");
3010 return CMD_WARNING_CONFIG_FAILED
;
3013 ifc
= connected_check(ifp
, (struct prefix
*)&cp
);
3015 ifc
= connected_new();
3019 p
= prefix_ipv6_new();
3021 ifc
->address
= (struct prefix
*)p
;
3025 ifc
->label
= XSTRDUP(MTYPE_CONNECTED_LABEL
, label
);
3027 /* Add to linked list. */
3028 listnode_add(ifp
->connected
, ifc
);
3031 /* This address is configured from zebra. */
3032 if (!CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
3033 SET_FLAG(ifc
->conf
, ZEBRA_IFC_CONFIGURED
);
3035 /* In case of this route need to install kernel. */
3036 if (!CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
)
3037 && CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
)
3038 && !(if_data
&& if_data
->shutdown
== IF_ZEBRA_SHUTDOWN_ON
)) {
3039 /* Some system need to up the interface to set IP address. */
3040 if (!if_is_up(ifp
)) {
3041 if_set_flags(ifp
, IFF_UP
| IFF_RUNNING
);
3045 dplane_res
= dplane_intf_addr_set(ifp
, ifc
);
3046 if (dplane_res
== ZEBRA_DPLANE_REQUEST_FAILURE
) {
3047 vty_out(vty
, "%% Can't set interface IP address: %s.\n",
3048 dplane_res2str(dplane_res
));
3049 return CMD_WARNING_CONFIG_FAILED
;
3052 SET_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
);
3053 /* The address will be advertised to zebra clients when the
3055 * from the kernel has been received. */
3061 /* Return true if an ipv6 address is configured on ifp */
3062 int ipv6_address_configured(struct interface
*ifp
)
3064 struct connected
*connected
;
3065 struct listnode
*node
;
3067 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, node
, connected
))
3068 if (CHECK_FLAG(connected
->conf
, ZEBRA_IFC_REAL
)
3069 && (connected
->address
->family
== AF_INET6
))
3075 static int ipv6_address_uninstall(struct vty
*vty
, struct interface
*ifp
,
3076 const char *addr_str
, const char *peer_str
,
3079 struct prefix_ipv6 cp
;
3080 struct connected
*ifc
;
3082 enum zebra_dplane_result dplane_res
;
3084 /* Convert to prefix structure. */
3085 ret
= str2prefix_ipv6(addr_str
, &cp
);
3087 vty_out(vty
, "%% Malformed address \n");
3088 return CMD_WARNING_CONFIG_FAILED
;
3091 /* Check current interface address. */
3092 ifc
= connected_check(ifp
, (struct prefix
*)&cp
);
3094 vty_out(vty
, "%% Can't find address\n");
3095 return CMD_WARNING_CONFIG_FAILED
;
3098 /* This is not configured address. */
3099 if (!CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
3100 return CMD_WARNING_CONFIG_FAILED
;
3102 UNSET_FLAG(ifc
->conf
, ZEBRA_IFC_CONFIGURED
);
3104 /* This is not real address or interface is not active. */
3105 if (!CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
)
3106 || !CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
)) {
3107 listnode_delete(ifp
->connected
, ifc
);
3108 connected_free(&ifc
);
3109 return CMD_WARNING_CONFIG_FAILED
;
3112 /* This is real route. */
3113 dplane_res
= dplane_intf_addr_unset(ifp
, ifc
);
3114 if (dplane_res
== ZEBRA_DPLANE_REQUEST_FAILURE
) {
3115 vty_out(vty
, "%% Can't unset interface IP address: %s.\n",
3116 dplane_res2str(dplane_res
));
3117 return CMD_WARNING_CONFIG_FAILED
;
3120 UNSET_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
);
3121 /* This information will be propagated to the zclients when the
3122 * kernel notification is received. */
3126 DEFUN (ipv6_address
,
3128 "ipv6 address X:X::X:X/M",
3129 "Interface IPv6 config commands\n"
3130 "Set the IP address of an interface\n"
3131 "IPv6 address (e.g. 3ffe:506::1/48)\n")
3133 int idx_ipv6_prefixlen
= 2;
3134 VTY_DECLVAR_CONTEXT(interface
, ifp
);
3135 return ipv6_address_install(vty
, ifp
, argv
[idx_ipv6_prefixlen
]->arg
,
3139 DEFUN (no_ipv6_address
,
3140 no_ipv6_address_cmd
,
3141 "no ipv6 address X:X::X:X/M",
3143 "Interface IPv6 config commands\n"
3144 "Set the IP address of an interface\n"
3145 "IPv6 address (e.g. 3ffe:506::1/48)\n")
3147 int idx_ipv6_prefixlen
= 3;
3148 VTY_DECLVAR_CONTEXT(interface
, ifp
);
3149 return ipv6_address_uninstall(vty
, ifp
, argv
[idx_ipv6_prefixlen
]->arg
,
3153 static int link_params_config_write(struct vty
*vty
, struct interface
*ifp
)
3157 if ((ifp
== NULL
) || !HAS_LINK_PARAMS(ifp
))
3160 struct if_link_params
*iflp
= ifp
->link_params
;
3162 vty_out(vty
, " link-params\n");
3163 vty_out(vty
, " enable\n");
3164 if (IS_PARAM_SET(iflp
, LP_TE_METRIC
) && iflp
->te_metric
!= ifp
->metric
)
3165 vty_out(vty
, " metric %u\n", iflp
->te_metric
);
3166 if (IS_PARAM_SET(iflp
, LP_MAX_BW
) && iflp
->max_bw
!= iflp
->default_bw
)
3167 vty_out(vty
, " max-bw %g\n", iflp
->max_bw
);
3168 if (IS_PARAM_SET(iflp
, LP_MAX_RSV_BW
)
3169 && iflp
->max_rsv_bw
!= iflp
->default_bw
)
3170 vty_out(vty
, " max-rsv-bw %g\n", iflp
->max_rsv_bw
);
3171 if (IS_PARAM_SET(iflp
, LP_UNRSV_BW
)) {
3172 for (i
= 0; i
< 8; i
++)
3173 if (iflp
->unrsv_bw
[i
] != iflp
->default_bw
)
3174 vty_out(vty
, " unrsv-bw %d %g\n", i
,
3177 if (IS_PARAM_SET(iflp
, LP_ADM_GRP
))
3178 vty_out(vty
, " admin-grp 0x%x\n", iflp
->admin_grp
);
3179 if (IS_PARAM_SET(iflp
, LP_DELAY
)) {
3180 vty_out(vty
, " delay %u", iflp
->av_delay
);
3181 if (IS_PARAM_SET(iflp
, LP_MM_DELAY
)) {
3182 vty_out(vty
, " min %u", iflp
->min_delay
);
3183 vty_out(vty
, " max %u", iflp
->max_delay
);
3187 if (IS_PARAM_SET(iflp
, LP_DELAY_VAR
))
3188 vty_out(vty
, " delay-variation %u\n", iflp
->delay_var
);
3189 if (IS_PARAM_SET(iflp
, LP_PKT_LOSS
))
3190 vty_out(vty
, " packet-loss %g\n", iflp
->pkt_loss
);
3191 if (IS_PARAM_SET(iflp
, LP_AVA_BW
))
3192 vty_out(vty
, " ava-bw %g\n", iflp
->ava_bw
);
3193 if (IS_PARAM_SET(iflp
, LP_RES_BW
))
3194 vty_out(vty
, " res-bw %g\n", iflp
->res_bw
);
3195 if (IS_PARAM_SET(iflp
, LP_USE_BW
))
3196 vty_out(vty
, " use-bw %g\n", iflp
->use_bw
);
3197 if (IS_PARAM_SET(iflp
, LP_RMT_AS
))
3198 vty_out(vty
, " neighbor %s as %u\n", inet_ntoa(iflp
->rmt_ip
),
3200 vty_out(vty
, " exit-link-params\n");
3204 static int if_config_write(struct vty
*vty
)
3207 struct interface
*ifp
;
3209 zebra_ptm_write(vty
);
3211 RB_FOREACH (vrf0
, vrf_name_head
, &vrfs_by_name
)
3212 FOR_ALL_INTERFACES (vrf0
, ifp
) {
3213 struct zebra_if
*if_data
;
3214 struct listnode
*addrnode
;
3215 struct connected
*ifc
;
3219 if_data
= ifp
->info
;
3220 vrf
= vrf_lookup_by_id(ifp
->vrf_id
);
3222 if (ifp
->vrf_id
== VRF_DEFAULT
)
3223 vty_frame(vty
, "interface %s\n", ifp
->name
);
3225 vty_frame(vty
, "interface %s vrf %s\n",
3226 ifp
->name
, vrf
->name
);
3229 if (if_data
->shutdown
== IF_ZEBRA_SHUTDOWN_ON
)
3230 vty_out(vty
, " shutdown\n");
3232 zebra_ptm_if_write(vty
, if_data
);
3236 vty_out(vty
, " description %s\n", ifp
->desc
);
3238 /* Assign bandwidth here to avoid unnecessary interface
3240 while processing config script */
3241 if (ifp
->bandwidth
!= 0)
3242 vty_out(vty
, " bandwidth %u\n", ifp
->bandwidth
);
3244 if (!CHECK_FLAG(ifp
->status
,
3245 ZEBRA_INTERFACE_LINKDETECTION
))
3246 vty_out(vty
, " no link-detect\n");
3248 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, addrnode
,
3250 if (CHECK_FLAG(ifc
->conf
,
3251 ZEBRA_IFC_CONFIGURED
)) {
3252 char buf
[INET6_ADDRSTRLEN
];
3254 vty_out(vty
, " ip%s address %s",
3255 p
->family
== AF_INET
? ""
3257 inet_ntop(p
->family
,
3260 if (CONNECTED_PEER(ifc
)) {
3261 p
= ifc
->destination
;
3262 vty_out(vty
, " peer %s",
3263 inet_ntop(p
->family
,
3268 vty_out(vty
, "/%d", p
->prefixlen
);
3271 vty_out(vty
, " label %s",
3279 if (if_data
->multicast
3280 != IF_ZEBRA_MULTICAST_UNSPEC
)
3281 vty_out(vty
, " %smulticast\n",
3283 == IF_ZEBRA_MULTICAST_ON
3288 hook_call(zebra_if_config_wr
, vty
, ifp
);
3290 link_params_config_write(vty
, ifp
);
3292 vty_endframe(vty
, "!\n");
3297 /* Allocate and initialize interface vector. */
3298 void zebra_if_init(void)
3300 /* Initialize interface and new hook. */
3301 hook_register_prio(if_add
, 0, if_zebra_new_hook
);
3302 hook_register_prio(if_del
, 0, if_zebra_delete_hook
);
3304 /* Install configuration write function. */
3305 install_node(&interface_node
, if_config_write
);
3306 install_node(&link_params_node
, NULL
);
3309 * This is *intentionally* setting this to NULL, signaling
3310 * that interface creation for zebra acts differently
3312 if_zapi_callbacks(NULL
, NULL
, NULL
, NULL
);
3314 install_element(VIEW_NODE
, &show_interface_cmd
);
3315 install_element(VIEW_NODE
, &show_interface_vrf_all_cmd
);
3316 install_element(VIEW_NODE
, &show_interface_name_vrf_cmd
);
3317 install_element(VIEW_NODE
, &show_interface_name_vrf_all_cmd
);
3319 install_element(ENABLE_NODE
, &show_interface_desc_cmd
);
3320 install_element(ENABLE_NODE
, &show_interface_desc_vrf_all_cmd
);
3321 install_element(INTERFACE_NODE
, &multicast_cmd
);
3322 install_element(INTERFACE_NODE
, &no_multicast_cmd
);
3323 install_element(INTERFACE_NODE
, &linkdetect_cmd
);
3324 install_element(INTERFACE_NODE
, &no_linkdetect_cmd
);
3325 install_element(INTERFACE_NODE
, &shutdown_if_cmd
);
3326 install_element(INTERFACE_NODE
, &no_shutdown_if_cmd
);
3327 install_element(INTERFACE_NODE
, &bandwidth_if_cmd
);
3328 install_element(INTERFACE_NODE
, &no_bandwidth_if_cmd
);
3329 install_element(INTERFACE_NODE
, &ip_address_cmd
);
3330 install_element(INTERFACE_NODE
, &no_ip_address_cmd
);
3331 install_element(INTERFACE_NODE
, &ip_address_peer_cmd
);
3332 install_element(INTERFACE_NODE
, &no_ip_address_peer_cmd
);
3333 install_element(INTERFACE_NODE
, &ipv6_address_cmd
);
3334 install_element(INTERFACE_NODE
, &no_ipv6_address_cmd
);
3336 install_element(INTERFACE_NODE
, &ip_address_label_cmd
);
3337 install_element(INTERFACE_NODE
, &no_ip_address_label_cmd
);
3338 #endif /* HAVE_NETLINK */
3339 install_element(INTERFACE_NODE
, &link_params_cmd
);
3340 install_default(LINK_PARAMS_NODE
);
3341 install_element(LINK_PARAMS_NODE
, &link_params_enable_cmd
);
3342 install_element(LINK_PARAMS_NODE
, &no_link_params_enable_cmd
);
3343 install_element(LINK_PARAMS_NODE
, &link_params_metric_cmd
);
3344 install_element(LINK_PARAMS_NODE
, &no_link_params_metric_cmd
);
3345 install_element(LINK_PARAMS_NODE
, &link_params_maxbw_cmd
);
3346 install_element(LINK_PARAMS_NODE
, &link_params_max_rsv_bw_cmd
);
3347 install_element(LINK_PARAMS_NODE
, &link_params_unrsv_bw_cmd
);
3348 install_element(LINK_PARAMS_NODE
, &link_params_admin_grp_cmd
);
3349 install_element(LINK_PARAMS_NODE
, &no_link_params_admin_grp_cmd
);
3350 install_element(LINK_PARAMS_NODE
, &link_params_inter_as_cmd
);
3351 install_element(LINK_PARAMS_NODE
, &no_link_params_inter_as_cmd
);
3352 install_element(LINK_PARAMS_NODE
, &link_params_delay_cmd
);
3353 install_element(LINK_PARAMS_NODE
, &no_link_params_delay_cmd
);
3354 install_element(LINK_PARAMS_NODE
, &link_params_delay_var_cmd
);
3355 install_element(LINK_PARAMS_NODE
, &no_link_params_delay_var_cmd
);
3356 install_element(LINK_PARAMS_NODE
, &link_params_pkt_loss_cmd
);
3357 install_element(LINK_PARAMS_NODE
, &no_link_params_pkt_loss_cmd
);
3358 install_element(LINK_PARAMS_NODE
, &link_params_ava_bw_cmd
);
3359 install_element(LINK_PARAMS_NODE
, &no_link_params_ava_bw_cmd
);
3360 install_element(LINK_PARAMS_NODE
, &link_params_res_bw_cmd
);
3361 install_element(LINK_PARAMS_NODE
, &no_link_params_res_bw_cmd
);
3362 install_element(LINK_PARAMS_NODE
, &link_params_use_bw_cmd
);
3363 install_element(LINK_PARAMS_NODE
, &no_link_params_use_bw_cmd
);
3364 install_element(LINK_PARAMS_NODE
, &exit_link_params_cmd
);