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 route_table_delegate_t zebra_if_table_delegate
= {
111 .create_node
= route_node_create
,
112 .destroy_node
= zebra_if_node_destroy
};
114 /* Called when new interface is added. */
115 static int if_zebra_new_hook(struct interface
*ifp
)
117 struct zebra_if
*zebra_if
;
119 zebra_if
= XCALLOC(MTYPE_ZINFO
, sizeof(struct zebra_if
));
121 zebra_if
->multicast
= IF_ZEBRA_MULTICAST_UNSPEC
;
122 zebra_if
->shutdown
= IF_ZEBRA_SHUTDOWN_OFF
;
123 zebra_ptm_if_init(zebra_if
);
125 ifp
->ptm_enable
= zebra_ptm_get_enable_state();
126 #if defined(HAVE_RTADV)
128 /* Set default router advertise values. */
129 struct rtadvconf
*rtadv
;
131 rtadv
= &zebra_if
->rtadv
;
133 rtadv
->AdvSendAdvertisements
= 0;
134 rtadv
->MaxRtrAdvInterval
= RTADV_MAX_RTR_ADV_INTERVAL
;
135 rtadv
->MinRtrAdvInterval
= RTADV_MIN_RTR_ADV_INTERVAL
;
136 rtadv
->AdvIntervalTimer
= 0;
137 rtadv
->AdvManagedFlag
= 0;
138 rtadv
->AdvOtherConfigFlag
= 0;
139 rtadv
->AdvHomeAgentFlag
= 0;
140 rtadv
->AdvLinkMTU
= 0;
141 rtadv
->AdvReachableTime
= 0;
142 rtadv
->AdvRetransTimer
= 0;
143 rtadv
->AdvCurHopLimit
= 0;
144 rtadv
->AdvDefaultLifetime
=
145 -1; /* derive from MaxRtrAdvInterval */
146 rtadv
->HomeAgentPreference
= 0;
147 rtadv
->HomeAgentLifetime
=
148 -1; /* derive from AdvDefaultLifetime */
149 rtadv
->AdvIntervalOption
= 0;
150 rtadv
->DefaultPreference
= RTADV_PREF_MEDIUM
;
152 rtadv
->AdvPrefixList
= list_new();
153 rtadv
->AdvRDNSSList
= list_new();
154 rtadv
->AdvDNSSLList
= list_new();
156 #endif /* HAVE_RTADV */
158 memset(&zebra_if
->neigh_mac
[0], 0, 6);
160 /* Initialize installed address chains tree. */
161 zebra_if
->ipv4_subnets
=
162 route_table_init_with_delegate(&zebra_if_table_delegate
);
164 ifp
->info
= zebra_if
;
167 * Some platforms are telling us that the interface is
168 * up and ready to go. When we check the speed we
169 * sometimes get the wrong value. Wait a couple
170 * of seconds and ask again. Hopefully it's all settled
173 thread_add_timer(zrouter
.master
, if_zebra_speed_update
, ifp
, 15,
174 &zebra_if
->speed_update
);
178 /* Called when interface is deleted. */
179 static int if_zebra_delete_hook(struct interface
*ifp
)
181 struct zebra_if
*zebra_if
;
184 zebra_if
= ifp
->info
;
186 /* Free installed address chains tree. */
187 if (zebra_if
->ipv4_subnets
)
188 route_table_finish(zebra_if
->ipv4_subnets
);
189 #if defined(HAVE_RTADV)
191 struct rtadvconf
*rtadv
;
193 rtadv
= &zebra_if
->rtadv
;
194 list_delete(&rtadv
->AdvPrefixList
);
195 list_delete(&rtadv
->AdvRDNSSList
);
196 list_delete(&rtadv
->AdvDNSSLList
);
197 #endif /* HAVE_RTADV */
199 XFREE(MTYPE_TMP
, zebra_if
->desc
);
200 THREAD_OFF(zebra_if
->speed_update
);
202 XFREE(MTYPE_ZINFO
, zebra_if
);
208 /* Build the table key */
209 static void if_build_key(uint32_t ifindex
, struct prefix
*p
)
212 p
->prefixlen
= IPV4_MAX_BITLEN
;
213 p
->u
.prefix4
.s_addr
= ifindex
;
216 /* Link an interface in a per NS interface tree */
217 struct interface
*if_link_per_ns(struct zebra_ns
*ns
, struct interface
*ifp
)
220 struct route_node
*rn
;
222 if (ifp
->ifindex
== IFINDEX_INTERNAL
)
225 if_build_key(ifp
->ifindex
, &p
);
226 rn
= route_node_get(ns
->if_table
, &p
);
228 ifp
= (struct interface
*)rn
->info
;
229 route_unlock_node(rn
); /* get */
239 /* Delete a VRF. This is called in vrf_terminate(). */
240 void if_unlink_per_ns(struct interface
*ifp
)
242 ifp
->node
->info
= NULL
;
243 route_unlock_node(ifp
->node
);
247 /* Look up an interface by identifier within a NS */
248 struct interface
*if_lookup_by_index_per_ns(struct zebra_ns
*ns
,
252 struct route_node
*rn
;
253 struct interface
*ifp
= NULL
;
255 if_build_key(ifindex
, &p
);
256 rn
= route_node_lookup(ns
->if_table
, &p
);
258 ifp
= (struct interface
*)rn
->info
;
259 route_unlock_node(rn
); /* lookup */
264 /* Look up an interface by name within a NS */
265 struct interface
*if_lookup_by_name_per_ns(struct zebra_ns
*ns
,
268 struct route_node
*rn
;
269 struct interface
*ifp
;
271 for (rn
= route_top(ns
->if_table
); rn
; rn
= route_next(rn
)) {
272 ifp
= (struct interface
*)rn
->info
;
273 if (ifp
&& strcmp(ifp
->name
, ifname
) == 0)
280 const char *ifindex2ifname_per_ns(struct zebra_ns
*zns
, unsigned int ifindex
)
282 struct interface
*ifp
;
284 return ((ifp
= if_lookup_by_index_per_ns(zns
, ifindex
)) != NULL
)
289 /* Tie an interface address to its derived subnet list of addresses. */
290 int if_subnet_add(struct interface
*ifp
, struct connected
*ifc
)
292 struct route_node
*rn
;
293 struct zebra_if
*zebra_if
;
295 struct list
*addr_list
;
297 assert(ifp
&& ifp
->info
&& ifc
);
298 zebra_if
= ifp
->info
;
300 /* Get address derived subnet node and associated address list, while
302 address secondary attribute appropriately. */
303 cp
= *CONNECTED_PREFIX(ifc
);
305 rn
= route_node_get(zebra_if
->ipv4_subnets
, &cp
);
307 if ((addr_list
= rn
->info
))
308 SET_FLAG(ifc
->flags
, ZEBRA_IFA_SECONDARY
);
310 UNSET_FLAG(ifc
->flags
, ZEBRA_IFA_SECONDARY
);
311 rn
->info
= addr_list
= list_new();
315 /* Tie address at the tail of address list. */
316 listnode_add(addr_list
, ifc
);
318 /* Return list element count. */
319 return (addr_list
->count
);
322 /* Untie an interface address from its derived subnet list of addresses. */
323 int if_subnet_delete(struct interface
*ifp
, struct connected
*ifc
)
325 struct route_node
*rn
;
326 struct zebra_if
*zebra_if
;
327 struct list
*addr_list
;
330 assert(ifp
&& ifp
->info
&& ifc
);
331 zebra_if
= ifp
->info
;
333 cp
= *CONNECTED_PREFIX(ifc
);
336 /* Get address derived subnet node. */
337 rn
= route_node_lookup(zebra_if
->ipv4_subnets
, &cp
);
338 if (!(rn
&& rn
->info
)) {
339 flog_warn(EC_ZEBRA_REMOVE_ADDR_UNKNOWN_SUBNET
,
340 "Trying to remove an address from an unknown subnet."
341 " (please report this bug)");
344 route_unlock_node(rn
);
346 /* Untie address from subnet's address list. */
347 addr_list
= rn
->info
;
349 /* Deleting an address that is not registered is a bug.
350 * In any case, we shouldn't decrement the lock counter if the address
352 if (!listnode_lookup(addr_list
, ifc
)) {
354 EC_ZEBRA_REMOVE_UNREGISTERED_ADDR
,
355 "Trying to remove an address from a subnet where it is not"
356 " currently registered. (please report this bug)");
360 listnode_delete(addr_list
, ifc
);
361 route_unlock_node(rn
);
363 /* Return list element count, if not empty. */
364 if (addr_list
->count
) {
365 /* If deleted address is primary, mark subsequent one as such
367 if (!CHECK_FLAG(ifc
->flags
, ZEBRA_IFA_SECONDARY
)) {
369 (struct listnode
*)listhead(addr_list
));
370 zebra_interface_address_delete_update(ifp
, ifc
);
371 UNSET_FLAG(ifc
->flags
, ZEBRA_IFA_SECONDARY
);
372 /* XXX: Linux kernel removes all the secondary addresses
374 * address is removed. We could try to work around that,
377 zebra_interface_address_add_update(ifp
, ifc
);
380 return addr_list
->count
;
383 /* Otherwise, free list and route node. */
384 list_delete(&addr_list
);
386 route_unlock_node(rn
);
391 /* if_flags_mangle: A place for hacks that require mangling
392 * or tweaking the interface flags.
394 * ******************** Solaris flags hacks **************************
396 * Solaris IFF_UP flag reflects only the primary interface as the
397 * routing socket only sends IFINFO for the primary interface. Hence
398 * ~IFF_UP does not per se imply all the logical interfaces are also
399 * down - which we only know of as addresses. Instead we must determine
400 * whether the interface really is up or not according to how many
401 * addresses are still attached. (Solaris always sends RTM_DELADDR if
402 * an interface, logical or not, goes ~IFF_UP).
404 * Ie, we mangle IFF_UP to *additionally* reflect whether or not there
405 * are addresses left in struct connected, not just the actual underlying
408 * We must hence remember the real state of IFF_UP, which we do in
409 * struct zebra_if.primary_state.
411 * Setting IFF_UP within zebra to administratively shutdown the
412 * interface will affect only the primary interface/address on Solaris.
413 ************************End Solaris flags hacks ***********************
415 static void if_flags_mangle(struct interface
*ifp
, uint64_t *newflags
)
418 struct zebra_if
*zif
= ifp
->info
;
420 zif
->primary_state
= *newflags
& (IFF_UP
& 0xff);
422 if (CHECK_FLAG(zif
->primary_state
, IFF_UP
)
423 || listcount(ifp
->connected
) > 0)
424 SET_FLAG(*newflags
, IFF_UP
);
426 UNSET_FLAG(*newflags
, IFF_UP
);
430 /* Update the flags field of the ifp with the new flag set provided.
431 * Take whatever actions are required for any changes in flags we care
434 * newflags should be the raw value, as obtained from the OS.
436 void if_flags_update(struct interface
*ifp
, uint64_t newflags
)
438 if_flags_mangle(ifp
, &newflags
);
440 if (if_is_no_ptm_operative(ifp
)) {
441 /* operative -> inoperative? */
442 ifp
->flags
= newflags
;
443 if (!if_is_operative(ifp
))
446 /* inoperative -> operative? */
447 ifp
->flags
= newflags
;
448 if (if_is_operative(ifp
))
453 /* Wake up configured address if it is not in current kernel
455 static void if_addr_wakeup(struct interface
*ifp
)
457 struct listnode
*node
, *nnode
;
458 struct connected
*ifc
;
460 enum zebra_dplane_result dplane_res
;
462 for (ALL_LIST_ELEMENTS(ifp
->connected
, node
, nnode
, ifc
)) {
465 if (CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_CONFIGURED
)
466 && !CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
)) {
468 if (p
->family
== AF_INET
) {
469 if (!if_is_up(ifp
)) {
470 /* Assume zebra is configured like
474 * ip addr 192.0.2.1/24
477 * As soon as zebra becomes first aware
478 * that gre0 exists in the
479 * kernel, it will set gre0 up and
480 * configure its addresses.
482 * (This may happen at startup when the
483 * interface already exists
484 * or during runtime when the interface
485 * is added to the kernel)
487 * XXX: IRDP code is calling here via
488 * if_add_update - this seems
490 * XXX: RUNNING is not a settable flag
492 * I (paulj) am aware of.
494 if_set_flags(ifp
, IFF_UP
| IFF_RUNNING
);
498 dplane_res
= dplane_intf_addr_set(ifp
, ifc
);
500 ZEBRA_DPLANE_REQUEST_FAILURE
) {
502 EC_ZEBRA_IFACE_ADDR_ADD_FAILED
,
503 "Can't set interface's address: %s",
504 dplane_res2str(dplane_res
));
508 SET_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
);
509 /* The address will be advertised to zebra
510 * clients when the notification
511 * from the kernel has been received.
512 * It will also be added to the interface's
513 * subnet list then. */
515 if (p
->family
== AF_INET6
) {
516 if (!if_is_up(ifp
)) {
517 /* See long comment above */
518 if_set_flags(ifp
, IFF_UP
| IFF_RUNNING
);
523 dplane_res
= dplane_intf_addr_set(ifp
, ifc
);
525 ZEBRA_DPLANE_REQUEST_FAILURE
) {
527 EC_ZEBRA_IFACE_ADDR_ADD_FAILED
,
528 "Can't set interface's address: %s",
529 dplane_res2str(dplane_res
));
533 SET_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
);
534 /* The address will be advertised to zebra
535 * clients when the notification
536 * from the kernel has been received. */
542 /* Handle interface addition */
543 void if_add_update(struct interface
*ifp
)
545 struct zebra_if
*if_data
;
546 struct zebra_ns
*zns
;
547 struct zebra_vrf
*zvrf
= vrf_info_lookup(ifp
->vrf_id
);
549 /* case interface populate before vrf enabled */
553 zns
= zebra_ns_lookup(NS_DEFAULT
);
554 if_link_per_ns(zns
, ifp
);
558 if (if_data
->multicast
== IF_ZEBRA_MULTICAST_ON
)
559 if_set_flags(ifp
, IFF_MULTICAST
);
560 else if (if_data
->multicast
== IF_ZEBRA_MULTICAST_OFF
)
561 if_unset_flags(ifp
, IFF_MULTICAST
);
563 zebra_ptm_if_set_ptm_state(ifp
, if_data
);
565 zebra_interface_add_update(ifp
);
567 if (!CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
)) {
568 SET_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
);
570 if (if_data
->shutdown
== IF_ZEBRA_SHUTDOWN_ON
) {
571 if (IS_ZEBRA_DEBUG_KERNEL
)
573 "interface %s vrf %u index %d is shutdown. "
575 ifp
->name
, ifp
->vrf_id
, ifp
->ifindex
);
581 if (IS_ZEBRA_DEBUG_KERNEL
)
583 "interface %s vrf %u index %d becomes active.",
584 ifp
->name
, ifp
->vrf_id
, ifp
->ifindex
);
587 if (IS_ZEBRA_DEBUG_KERNEL
)
588 zlog_debug("interface %s vrf %u index %d is added.",
589 ifp
->name
, ifp
->vrf_id
, ifp
->ifindex
);
593 /* Install connected routes corresponding to an interface. */
594 static void if_install_connected(struct interface
*ifp
)
596 struct listnode
*node
;
597 struct listnode
*next
;
598 struct connected
*ifc
;
600 if (ifp
->connected
) {
601 for (ALL_LIST_ELEMENTS(ifp
->connected
, node
, next
, ifc
)) {
602 if (CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_REAL
))
603 zebra_interface_address_add_update(ifp
, ifc
);
605 connected_up(ifp
, ifc
);
610 /* Uninstall connected routes corresponding to an interface. */
611 static void if_uninstall_connected(struct interface
*ifp
)
613 struct listnode
*node
;
614 struct listnode
*next
;
615 struct connected
*ifc
;
617 if (ifp
->connected
) {
618 for (ALL_LIST_ELEMENTS(ifp
->connected
, node
, next
, ifc
)) {
619 zebra_interface_address_delete_update(ifp
, ifc
);
620 connected_down(ifp
, ifc
);
625 /* Uninstall and delete connected routes corresponding to an interface. */
626 /* TODO - Check why IPv4 handling here is different from install or if_down */
627 static void if_delete_connected(struct interface
*ifp
)
629 struct connected
*ifc
;
631 struct route_node
*rn
;
632 struct zebra_if
*zebra_if
;
633 struct listnode
*node
;
634 struct listnode
*last
= NULL
;
636 zebra_if
= ifp
->info
;
641 while ((node
= (last
? last
->next
: listhead(ifp
->connected
)))) {
642 ifc
= listgetdata(node
);
644 cp
= *CONNECTED_PREFIX(ifc
);
647 if (cp
.family
== AF_INET
648 && (rn
= route_node_lookup(zebra_if
->ipv4_subnets
, &cp
))) {
649 struct listnode
*anode
;
650 struct listnode
*next
;
651 struct listnode
*first
;
652 struct list
*addr_list
;
654 route_unlock_node(rn
);
655 addr_list
= (struct list
*)rn
->info
;
657 /* Remove addresses, secondaries first. */
658 first
= listhead(addr_list
);
660 for (anode
= first
->next
; anode
|| first
;
668 ifc
= listgetdata(anode
);
669 connected_down(ifp
, ifc
);
671 /* XXX: We have to send notifications
672 * here explicitly, because we destroy
673 * the ifc before receiving the
674 * notification about the address being
677 zebra_interface_address_delete_update(
680 UNSET_FLAG(ifc
->conf
, ZEBRA_IFC_REAL
);
681 UNSET_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
);
683 /* Remove from subnet chain. */
684 list_delete_node(addr_list
, anode
);
685 route_unlock_node(rn
);
687 /* Remove from interface address list
688 * (unconditionally). */
689 if (!CHECK_FLAG(ifc
->conf
,
690 ZEBRA_IFC_CONFIGURED
)) {
691 listnode_delete(ifp
->connected
,
698 /* Free chain list and respective route node. */
699 list_delete(&addr_list
);
701 route_unlock_node(rn
);
702 } else if (cp
.family
== AF_INET6
) {
703 connected_down(ifp
, ifc
);
705 zebra_interface_address_delete_update(ifp
, ifc
);
707 UNSET_FLAG(ifc
->conf
, ZEBRA_IFC_REAL
);
708 UNSET_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
);
710 if (CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
713 listnode_delete(ifp
->connected
, ifc
);
722 /* Handle an interface delete event */
723 void if_delete_update(struct interface
*ifp
)
725 struct zebra_if
*zif
;
730 "interface %s vrf %u index %d is still up while being deleted.",
731 ifp
->name
, ifp
->vrf_id
, ifp
->ifindex
);
735 if (!CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
))
738 /* Mark interface as inactive */
739 UNSET_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
);
741 if (IS_ZEBRA_DEBUG_KERNEL
)
742 zlog_debug("interface %s vrf %u index %d is now inactive.",
743 ifp
->name
, ifp
->vrf_id
, ifp
->ifindex
);
745 /* Delete connected routes from the kernel. */
746 if_delete_connected(ifp
);
748 /* Send out notification on interface delete. */
749 zebra_interface_delete_update(ifp
);
751 if_unlink_per_ns(ifp
);
753 /* Update ifindex after distributing the delete message. This is in
754 case any client needs to have the old value of ifindex available
755 while processing the deletion. Each client daemon is responsible
756 for setting ifindex to IFINDEX_INTERNAL after processing the
757 interface deletion message. */
758 if_set_index(ifp
, IFINDEX_INTERNAL
);
761 /* if the ifp is in a vrf, move it to default so vrf can be deleted if
762 * desired. This operation is not done for netns implementation to avoid
763 * collision with interface with the same name in the default vrf (can
764 * occur with this implementation whereas it is not possible with
767 if (ifp
->vrf_id
&& !vrf_is_backend_netns())
768 if_handle_vrf_change(ifp
, VRF_DEFAULT
);
770 /* Reset some zebra interface params to default values. */
773 zif
->zif_type
= ZEBRA_IF_OTHER
;
774 zif
->zif_slave_type
= ZEBRA_IF_SLAVE_NONE
;
775 memset(&zif
->l2info
, 0, sizeof(union zebra_l2if_info
));
776 memset(&zif
->brslave_info
, 0,
777 sizeof(struct zebra_l2info_brslave
));
781 /* VRF change for an interface */
782 void if_handle_vrf_change(struct interface
*ifp
, vrf_id_t vrf_id
)
786 old_vrf_id
= ifp
->vrf_id
;
788 /* Uninstall connected routes. */
789 if_uninstall_connected(ifp
);
791 /* Delete any IPv4 neighbors created to implement RFC 5549 */
792 if_nbr_ipv6ll_to_ipv4ll_neigh_del_all(ifp
);
794 /* Delete all neighbor addresses learnt through IPv6 RA */
795 if_down_del_nbr_connected(ifp
);
797 /* Send out notification on interface VRF change. */
798 /* This is to issue an UPDATE or a DELETE, as appropriate. */
799 zebra_interface_vrf_update_del(ifp
, vrf_id
);
802 if_update_to_new_vrf(ifp
, vrf_id
);
804 /* Send out notification on interface VRF change. */
805 /* This is to issue an ADD, if needed. */
806 zebra_interface_vrf_update_add(ifp
, old_vrf_id
);
808 /* Install connected routes (in new VRF). */
809 if (if_is_operative(ifp
))
810 if_install_connected(ifp
);
813 static void ipv6_ll_address_to_mac(struct in6_addr
*address
, uint8_t *mac
)
815 mac
[0] = address
->s6_addr
[8] ^ 0x02;
816 mac
[1] = address
->s6_addr
[9];
817 mac
[2] = address
->s6_addr
[10];
818 mac
[3] = address
->s6_addr
[13];
819 mac
[4] = address
->s6_addr
[14];
820 mac
[5] = address
->s6_addr
[15];
823 void if_nbr_mac_to_ipv4ll_neigh_update(struct interface
*ifp
,
825 struct in6_addr
*address
,
828 struct zebra_vrf
*zvrf
= vrf_info_lookup(ifp
->vrf_id
);
829 struct zebra_if
*zif
= ifp
->info
;
830 char buf
[16] = "169.254.0.1";
831 struct in_addr ipv4_ll
;
834 inet_pton(AF_INET
, buf
, &ipv4_ll
);
836 ns_id
= zvrf
->zns
->ns_id
;
839 * Remove and re-add any existing neighbor entry for this address,
840 * since Netlink doesn't currently offer update message types.
842 kernel_neigh_update(0, ifp
->ifindex
, ipv4_ll
.s_addr
, mac
, 6, ns_id
);
844 /* Add new neighbor entry.
846 * We force installation even if current neighbor entry is the same.
847 * Since this function is used to refresh our MAC entries after an
848 * interface flap, if we don't force in our custom entries with their
849 * state set to PERMANENT or REACHABLE then the kernel will attempt to
850 * resolve our leftover entries, fail, mark them unreachable and then
851 * they'll be useless to us.
854 kernel_neigh_update(add
, ifp
->ifindex
, ipv4_ll
.s_addr
, mac
, 6,
857 memcpy(&zif
->neigh_mac
[0], &mac
[0], 6);
860 * We need to note whether or not we originated a v6
861 * neighbor entry for this interface. So that when
862 * someone unwisely accidently deletes this entry
863 * we can shove it back in.
865 zif
->v6_2_v4_ll_neigh_entry
= !!add
;
866 memcpy(&zif
->v6_2_v4_ll_addr6
, address
, sizeof(*address
));
868 zvrf
->neigh_updates
++;
871 void if_nbr_ipv6ll_to_ipv4ll_neigh_update(struct interface
*ifp
,
872 struct in6_addr
*address
, int add
)
877 ipv6_ll_address_to_mac(address
, (uint8_t *)mac
);
878 if_nbr_mac_to_ipv4ll_neigh_update(ifp
, mac
, address
, add
);
881 static void if_nbr_ipv6ll_to_ipv4ll_neigh_add_all(struct interface
*ifp
)
883 if (listhead(ifp
->nbr_connected
)) {
884 struct nbr_connected
*nbr_connected
;
885 struct listnode
*node
;
887 for (ALL_LIST_ELEMENTS_RO(ifp
->nbr_connected
, node
,
889 if_nbr_ipv6ll_to_ipv4ll_neigh_update(
890 ifp
, &nbr_connected
->address
->u
.prefix6
, 1);
894 void if_nbr_ipv6ll_to_ipv4ll_neigh_del_all(struct interface
*ifp
)
896 if (listhead(ifp
->nbr_connected
)) {
897 struct nbr_connected
*nbr_connected
;
898 struct listnode
*node
;
900 for (ALL_LIST_ELEMENTS_RO(ifp
->nbr_connected
, node
,
902 if_nbr_ipv6ll_to_ipv4ll_neigh_update(
903 ifp
, &nbr_connected
->address
->u
.prefix6
, 0);
907 static void if_down_del_nbr_connected(struct interface
*ifp
)
909 struct nbr_connected
*nbr_connected
;
910 struct listnode
*node
, *nnode
;
912 for (ALL_LIST_ELEMENTS(ifp
->nbr_connected
, node
, nnode
,
914 listnode_delete(ifp
->nbr_connected
, nbr_connected
);
915 nbr_connected_free(nbr_connected
);
919 /* Interface is up. */
920 void if_up(struct interface
*ifp
)
922 struct zebra_if
*zif
;
923 struct interface
*link_if
;
924 struct zebra_vrf
*zvrf
= vrf_info_lookup(ifp
->vrf_id
);
928 quagga_timestamp(2, zif
->up_last
, sizeof(zif
->up_last
));
930 /* Notify the protocol daemons. */
931 if (ifp
->ptm_enable
&& (ifp
->ptm_status
== ZEBRA_PTM_STATUS_DOWN
)) {
932 flog_warn(EC_ZEBRA_PTM_NOT_READY
,
933 "%s: interface %s hasn't passed ptm check\n",
934 __func__
, ifp
->name
);
937 zebra_interface_up_update(ifp
);
939 if_nbr_ipv6ll_to_ipv4ll_neigh_add_all(ifp
);
941 #if defined(HAVE_RTADV)
942 /* Enable fast tx of RA if enabled && RA interval is not in msecs */
943 if (zif
->rtadv
.AdvSendAdvertisements
944 && (zif
->rtadv
.MaxRtrAdvInterval
>= 1000)) {
945 zif
->rtadv
.inFastRexmit
= 1;
946 zif
->rtadv
.NumFastReXmitsRemain
= RTADV_NUM_FAST_REXMITS
;
950 /* Install connected routes to the kernel. */
951 if_install_connected(ifp
);
953 /* Handle interface up for specific types for EVPN. Non-VxLAN interfaces
954 * are checked to see if (remote) neighbor entries need to be installed
955 * on them for ARP suppression.
957 if (IS_ZEBRA_IF_VXLAN(ifp
))
958 zebra_vxlan_if_up(ifp
);
959 else if (IS_ZEBRA_IF_BRIDGE(ifp
)) {
961 zebra_vxlan_svi_up(ifp
, link_if
);
962 } else if (IS_ZEBRA_IF_VLAN(ifp
)) {
963 link_if
= if_lookup_by_index_per_ns(zvrf
->zns
,
966 zebra_vxlan_svi_up(ifp
, link_if
);
970 /* Interface goes down. We have to manage different behavior of based
972 void if_down(struct interface
*ifp
)
974 struct zebra_if
*zif
;
975 struct interface
*link_if
;
976 struct zebra_vrf
*zvrf
= vrf_info_lookup(ifp
->vrf_id
);
980 quagga_timestamp(2, zif
->down_last
, sizeof(zif
->down_last
));
982 /* Handle interface down for specific types for EVPN. Non-VxLAN
984 * are checked to see if (remote) neighbor entries need to be purged
985 * for ARP suppression.
987 if (IS_ZEBRA_IF_VXLAN(ifp
))
988 zebra_vxlan_if_down(ifp
);
989 else if (IS_ZEBRA_IF_BRIDGE(ifp
)) {
991 zebra_vxlan_svi_down(ifp
, link_if
);
992 } else if (IS_ZEBRA_IF_VLAN(ifp
)) {
993 link_if
= if_lookup_by_index_per_ns(zvrf
->zns
,
996 zebra_vxlan_svi_down(ifp
, link_if
);
1000 /* Notify to the protocol daemons. */
1001 zebra_interface_down_update(ifp
);
1003 /* Uninstall connected routes from the kernel. */
1004 if_uninstall_connected(ifp
);
1006 if_nbr_ipv6ll_to_ipv4ll_neigh_del_all(ifp
);
1008 /* Delete all neighbor addresses learnt through IPv6 RA */
1009 if_down_del_nbr_connected(ifp
);
1012 void if_refresh(struct interface
*ifp
)
1017 void zebra_if_update_link(struct interface
*ifp
, ifindex_t link_ifindex
,
1020 struct zebra_if
*zif
;
1022 if (IS_ZEBRA_IF_VETH(ifp
))
1024 zif
= (struct zebra_if
*)ifp
->info
;
1025 zif
->link_ifindex
= link_ifindex
;
1026 zif
->link
= if_lookup_by_index_per_ns(zebra_ns_lookup(ns_id
),
1031 * during initial link dump kernel does not order lower devices before
1032 * upper devices so we need to fixup link dependencies at the end of dump
1034 void zebra_if_update_all_links(void)
1036 struct route_node
*rn
;
1037 struct interface
*ifp
;
1038 struct zebra_if
*zif
;
1039 struct zebra_ns
*ns
;
1041 if (IS_ZEBRA_DEBUG_KERNEL
)
1042 zlog_info("fixup link dependencies");
1044 ns
= zebra_ns_lookup(NS_DEFAULT
);
1045 for (rn
= route_top(ns
->if_table
); rn
; rn
= route_next(rn
)) {
1046 ifp
= (struct interface
*)rn
->info
;
1050 if ((zif
->link_ifindex
!= IFINDEX_INTERNAL
) && !zif
->link
) {
1051 zif
->link
= if_lookup_by_index_per_ns(ns
,
1053 if (IS_ZEBRA_DEBUG_KERNEL
)
1054 zlog_debug("interface %s/%d's lower fixup to %s/%d",
1055 ifp
->name
, ifp
->ifindex
,
1056 zif
->link
?zif
->link
->name
:"unk",
1062 void zebra_if_set_protodown(struct interface
*ifp
, bool down
)
1065 netlink_protodown(ifp
, down
);
1067 zlog_warn("Protodown is not supported on this platform");
1071 /* Output prefix string to vty. */
1072 static int prefix_vty_out(struct vty
*vty
, struct prefix
*p
)
1074 char str
[INET6_ADDRSTRLEN
];
1076 inet_ntop(p
->family
, &p
->u
.prefix
, str
, sizeof(str
));
1077 vty_out(vty
, "%s", str
);
1081 /* Dump if address information to vty. */
1082 static void connected_dump_vty(struct vty
*vty
, struct connected
*connected
)
1086 /* Print interface address. */
1087 p
= connected
->address
;
1088 vty_out(vty
, " %s ", prefix_family_str(p
));
1089 prefix_vty_out(vty
, p
);
1090 vty_out(vty
, "/%d", p
->prefixlen
);
1092 /* If there is destination address, print it. */
1093 if (CONNECTED_PEER(connected
) && connected
->destination
) {
1094 vty_out(vty
, " peer ");
1095 prefix_vty_out(vty
, connected
->destination
);
1096 vty_out(vty
, "/%d", connected
->destination
->prefixlen
);
1099 if (CHECK_FLAG(connected
->flags
, ZEBRA_IFA_SECONDARY
))
1100 vty_out(vty
, " secondary");
1102 if (CHECK_FLAG(connected
->flags
, ZEBRA_IFA_UNNUMBERED
))
1103 vty_out(vty
, " unnumbered");
1105 if (connected
->label
)
1106 vty_out(vty
, " %s", connected
->label
);
1111 /* Dump interface neighbor address information to vty. */
1112 static void nbr_connected_dump_vty(struct vty
*vty
,
1113 struct nbr_connected
*connected
)
1117 /* Print interface address. */
1118 p
= connected
->address
;
1119 vty_out(vty
, " %s ", prefix_family_str(p
));
1120 prefix_vty_out(vty
, p
);
1121 vty_out(vty
, "/%d", p
->prefixlen
);
1126 static const char *zebra_ziftype_2str(zebra_iftype_t zif_type
)
1129 case ZEBRA_IF_OTHER
:
1133 case ZEBRA_IF_BRIDGE
:
1141 case ZEBRA_IF_VXLAN
:
1156 case ZEBRA_IF_BOND_SLAVE
:
1157 return "bond_slave";
1159 case ZEBRA_IF_MACVLAN
:
1168 /* Interface's brief information print out to vty interface. */
1169 static void ifs_dump_brief_vty(struct vty
*vty
, struct vrf
*vrf
)
1171 struct connected
*connected
;
1172 struct listnode
*node
;
1173 struct route_node
*rn
;
1174 struct zebra_if
*zebra_if
;
1176 struct interface
*ifp
;
1177 bool print_header
= true;
1179 FOR_ALL_INTERFACES (vrf
, ifp
) {
1180 char global_pfx
[PREFIX_STRLEN
] = {0};
1181 char buf
[PREFIX_STRLEN
] = {0};
1182 bool first_pfx_printed
= false;
1185 vty_out(vty
, "%-16s%-8s%-16s%s\n", "Interface",
1186 "Status", "VRF", "Addresses");
1187 vty_out(vty
, "%-16s%-8s%-16s%s\n", "---------",
1188 "------", "---", "---------");
1189 print_header
= false; /* We have at least 1 iface */
1191 zebra_if
= ifp
->info
;
1193 vty_out(vty
, "%-16s", ifp
->name
);
1196 vty_out(vty
, "%-8s", "up");
1198 vty_out(vty
, "%-8s", "down");
1200 vty_out(vty
, "%-16s", vrf
->name
);
1202 for (rn
= route_top(zebra_if
->ipv4_subnets
); rn
;
1203 rn
= route_next(rn
)) {
1206 uint32_t list_size
= listcount((struct list
*)rn
->info
);
1208 for (ALL_LIST_ELEMENTS_RO((struct list
*)rn
->info
, node
,
1210 if (!CHECK_FLAG(connected
->flags
,
1211 ZEBRA_IFA_SECONDARY
)) {
1212 p
= connected
->address
;
1213 prefix2str(p
, buf
, sizeof(buf
));
1214 if (first_pfx_printed
) {
1215 /* padding to prepare row only for ip addr */
1216 vty_out(vty
, "%-40s", "");
1219 vty_out(vty
, "%s\n", buf
);
1223 vty_out(vty
, "%s\n", buf
);
1225 first_pfx_printed
= true;
1231 uint32_t v6_list_size
= 0;
1232 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, node
, connected
)) {
1233 if (CHECK_FLAG(connected
->conf
, ZEBRA_IFC_REAL
)
1234 && (connected
->address
->family
== AF_INET6
))
1237 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, node
, connected
)) {
1238 if (CHECK_FLAG(connected
->conf
, ZEBRA_IFC_REAL
)
1239 && !CHECK_FLAG(connected
->flags
,
1240 ZEBRA_IFA_SECONDARY
)
1241 && (connected
->address
->family
== AF_INET6
)) {
1242 p
= connected
->address
;
1243 /* Don't print link local pfx */
1244 if (!IN6_IS_ADDR_LINKLOCAL(&p
->u
.prefix6
)) {
1245 prefix2str(p
, global_pfx
, PREFIX_STRLEN
);
1246 if (first_pfx_printed
) {
1247 /* padding to prepare row only for ip addr */
1248 vty_out(vty
, "%-40s", "");
1249 if (v6_list_size
> 1)
1251 vty_out(vty
, "%s\n", global_pfx
);
1253 if (v6_list_size
> 1)
1255 vty_out(vty
, "%s\n", global_pfx
);
1257 first_pfx_printed
= true;
1262 if (!first_pfx_printed
)
1268 /* Interface's information print out to vty interface. */
1269 static void if_dump_vty(struct vty
*vty
, struct interface
*ifp
)
1271 struct connected
*connected
;
1272 struct nbr_connected
*nbr_connected
;
1273 struct listnode
*node
;
1274 struct route_node
*rn
;
1275 struct zebra_if
*zebra_if
;
1278 zebra_if
= ifp
->info
;
1280 vty_out(vty
, "Interface %s is ", ifp
->name
);
1281 if (if_is_up(ifp
)) {
1282 vty_out(vty
, "up, line protocol ");
1284 if (CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_LINKDETECTION
)) {
1285 if (if_is_running(ifp
))
1286 vty_out(vty
, "is up\n");
1288 vty_out(vty
, "is down\n");
1290 vty_out(vty
, "detection is disabled\n");
1293 vty_out(vty
, "down\n");
1296 vty_out(vty
, " Link ups: %5u last: %s\n", zebra_if
->up_count
,
1297 zebra_if
->up_last
[0] ? zebra_if
->up_last
: "(never)");
1298 vty_out(vty
, " Link downs: %5u last: %s\n", zebra_if
->down_count
,
1299 zebra_if
->down_last
[0] ? zebra_if
->down_last
: "(never)");
1301 zebra_ptm_show_status(vty
, ifp
);
1303 vrf
= vrf_lookup_by_id(ifp
->vrf_id
);
1304 vty_out(vty
, " vrf: %s\n", vrf
->name
);
1307 vty_out(vty
, " Description: %s\n", ifp
->desc
);
1309 vty_out(vty
, " OS Description: %s\n", zebra_if
->desc
);
1311 if (ifp
->ifindex
== IFINDEX_INTERNAL
) {
1312 vty_out(vty
, " pseudo interface\n");
1314 } else if (!CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
)) {
1315 vty_out(vty
, " index %d inactive interface\n", ifp
->ifindex
);
1319 vty_out(vty
, " index %d metric %d mtu %d speed %u ", ifp
->ifindex
,
1320 ifp
->metric
, ifp
->mtu
, ifp
->speed
);
1321 if (ifp
->mtu6
!= ifp
->mtu
)
1322 vty_out(vty
, "mtu6 %d ", ifp
->mtu6
);
1323 vty_out(vty
, "\n flags: %s\n", if_flag_dump(ifp
->flags
));
1325 /* Hardware address. */
1326 vty_out(vty
, " Type: %s\n", if_link_type_str(ifp
->ll_type
));
1327 if (ifp
->hw_addr_len
!= 0) {
1330 vty_out(vty
, " HWaddr: ");
1331 for (i
= 0; i
< ifp
->hw_addr_len
; i
++)
1332 vty_out(vty
, "%s%02x", i
== 0 ? "" : ":",
1337 /* Bandwidth in Mbps */
1338 if (ifp
->bandwidth
!= 0) {
1339 vty_out(vty
, " bandwidth %u Mbps", ifp
->bandwidth
);
1343 for (rn
= route_top(zebra_if
->ipv4_subnets
); rn
; rn
= route_next(rn
)) {
1347 for (ALL_LIST_ELEMENTS_RO((struct list
*)rn
->info
, node
,
1349 connected_dump_vty(vty
, connected
);
1352 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, node
, connected
)) {
1353 if (CHECK_FLAG(connected
->conf
, ZEBRA_IFC_REAL
)
1354 && (connected
->address
->family
== AF_INET6
))
1355 connected_dump_vty(vty
, connected
);
1358 vty_out(vty
, " Interface Type %s\n",
1359 zebra_ziftype_2str(zebra_if
->zif_type
));
1360 if (IS_ZEBRA_IF_BRIDGE(ifp
)) {
1361 struct zebra_l2info_bridge
*bridge_info
;
1363 bridge_info
= &zebra_if
->l2info
.br
;
1364 vty_out(vty
, " Bridge VLAN-aware: %s\n",
1365 bridge_info
->vlan_aware
? "yes" : "no");
1366 } else if (IS_ZEBRA_IF_VLAN(ifp
)) {
1367 struct zebra_l2info_vlan
*vlan_info
;
1369 vlan_info
= &zebra_if
->l2info
.vl
;
1370 vty_out(vty
, " VLAN Id %u\n", vlan_info
->vid
);
1371 } else if (IS_ZEBRA_IF_VXLAN(ifp
)) {
1372 struct zebra_l2info_vxlan
*vxlan_info
;
1374 vxlan_info
= &zebra_if
->l2info
.vxl
;
1375 vty_out(vty
, " VxLAN Id %u", vxlan_info
->vni
);
1376 if (vxlan_info
->vtep_ip
.s_addr
!= INADDR_ANY
)
1377 vty_out(vty
, " VTEP IP: %s",
1378 inet_ntoa(vxlan_info
->vtep_ip
));
1379 if (vxlan_info
->access_vlan
)
1380 vty_out(vty
, " Access VLAN Id %u\n",
1381 vxlan_info
->access_vlan
);
1382 if (vxlan_info
->mcast_grp
.s_addr
!= INADDR_ANY
)
1383 vty_out(vty
, " Mcast Group %s",
1384 inet_ntoa(vxlan_info
->mcast_grp
));
1388 if (IS_ZEBRA_IF_BRIDGE_SLAVE(ifp
)) {
1389 struct zebra_l2info_brslave
*br_slave
;
1391 br_slave
= &zebra_if
->brslave_info
;
1392 if (br_slave
->bridge_ifindex
!= IFINDEX_INTERNAL
) {
1393 if (br_slave
->br_if
)
1394 vty_out(vty
, " Master interface: %s\n",
1395 br_slave
->br_if
->name
);
1397 vty_out(vty
, " Master ifindex: %u\n",
1398 br_slave
->bridge_ifindex
);
1402 if (IS_ZEBRA_IF_BOND_SLAVE(ifp
)) {
1403 struct zebra_l2info_bondslave
*bond_slave
;
1405 bond_slave
= &zebra_if
->bondslave_info
;
1406 if (bond_slave
->bond_ifindex
!= IFINDEX_INTERNAL
) {
1407 if (bond_slave
->bond_if
)
1408 vty_out(vty
, " Master interface: %s\n",
1409 bond_slave
->bond_if
->name
);
1411 vty_out(vty
, " Master ifindex: %u\n",
1412 bond_slave
->bond_ifindex
);
1416 if (zebra_if
->link_ifindex
!= IFINDEX_INTERNAL
) {
1418 vty_out(vty
, " Parent interface: %s\n", zebra_if
->link
->name
);
1420 vty_out(vty
, " Parent ifindex: %d\n", zebra_if
->link_ifindex
);
1423 if (HAS_LINK_PARAMS(ifp
)) {
1425 struct if_link_params
*iflp
= ifp
->link_params
;
1426 vty_out(vty
, " Traffic Engineering Link Parameters:\n");
1427 if (IS_PARAM_SET(iflp
, LP_TE_METRIC
))
1428 vty_out(vty
, " TE metric %u\n", iflp
->te_metric
);
1429 if (IS_PARAM_SET(iflp
, LP_MAX_BW
))
1430 vty_out(vty
, " Maximum Bandwidth %g (Byte/s)\n",
1432 if (IS_PARAM_SET(iflp
, LP_MAX_RSV_BW
))
1434 " Maximum Reservable Bandwidth %g (Byte/s)\n",
1436 if (IS_PARAM_SET(iflp
, LP_UNRSV_BW
)) {
1438 " Unreserved Bandwidth per Class Type in Byte/s:\n");
1439 for (i
= 0; i
< MAX_CLASS_TYPE
; i
+= 2)
1441 " [%d]: %g (Bytes/sec),\t[%d]: %g (Bytes/sec)\n",
1442 i
, iflp
->unrsv_bw
[i
], i
+ 1,
1443 iflp
->unrsv_bw
[i
+ 1]);
1446 if (IS_PARAM_SET(iflp
, LP_ADM_GRP
))
1447 vty_out(vty
, " Administrative Group:%u\n",
1449 if (IS_PARAM_SET(iflp
, LP_DELAY
)) {
1450 vty_out(vty
, " Link Delay Average: %u (micro-sec.)",
1452 if (IS_PARAM_SET(iflp
, LP_MM_DELAY
)) {
1453 vty_out(vty
, " Min: %u (micro-sec.)",
1455 vty_out(vty
, " Max: %u (micro-sec.)",
1460 if (IS_PARAM_SET(iflp
, LP_DELAY_VAR
))
1462 " Link Delay Variation %u (micro-sec.)\n",
1464 if (IS_PARAM_SET(iflp
, LP_PKT_LOSS
))
1465 vty_out(vty
, " Link Packet Loss %g (in %%)\n",
1467 if (IS_PARAM_SET(iflp
, LP_AVA_BW
))
1468 vty_out(vty
, " Available Bandwidth %g (Byte/s)\n",
1470 if (IS_PARAM_SET(iflp
, LP_RES_BW
))
1471 vty_out(vty
, " Residual Bandwidth %g (Byte/s)\n",
1473 if (IS_PARAM_SET(iflp
, LP_USE_BW
))
1474 vty_out(vty
, " Utilized Bandwidth %g (Byte/s)\n",
1476 if (IS_PARAM_SET(iflp
, LP_RMT_AS
))
1477 vty_out(vty
, " Neighbor ASBR IP: %s AS: %u \n",
1478 inet_ntoa(iflp
->rmt_ip
), iflp
->rmt_as
);
1481 hook_call(zebra_if_extra_info
, vty
, ifp
);
1483 if (listhead(ifp
->nbr_connected
))
1484 vty_out(vty
, " Neighbor address(s):\n");
1485 for (ALL_LIST_ELEMENTS_RO(ifp
->nbr_connected
, node
, nbr_connected
))
1486 nbr_connected_dump_vty(vty
, nbr_connected
);
1488 #ifdef HAVE_PROC_NET_DEV
1489 /* Statistics print out using proc file system. */
1491 " %lu input packets (%lu multicast), %lu bytes, "
1493 ifp
->stats
.rx_packets
, ifp
->stats
.rx_multicast
,
1494 ifp
->stats
.rx_bytes
, ifp
->stats
.rx_dropped
);
1497 " %lu input errors, %lu length, %lu overrun,"
1498 " %lu CRC, %lu frame\n",
1499 ifp
->stats
.rx_errors
, ifp
->stats
.rx_length_errors
,
1500 ifp
->stats
.rx_over_errors
, ifp
->stats
.rx_crc_errors
,
1501 ifp
->stats
.rx_frame_errors
);
1503 vty_out(vty
, " %lu fifo, %lu missed\n", ifp
->stats
.rx_fifo_errors
,
1504 ifp
->stats
.rx_missed_errors
);
1506 vty_out(vty
, " %lu output packets, %lu bytes, %lu dropped\n",
1507 ifp
->stats
.tx_packets
, ifp
->stats
.tx_bytes
,
1508 ifp
->stats
.tx_dropped
);
1511 " %lu output errors, %lu aborted, %lu carrier,"
1512 " %lu fifo, %lu heartbeat\n",
1513 ifp
->stats
.tx_errors
, ifp
->stats
.tx_aborted_errors
,
1514 ifp
->stats
.tx_carrier_errors
, ifp
->stats
.tx_fifo_errors
,
1515 ifp
->stats
.tx_heartbeat_errors
);
1517 vty_out(vty
, " %lu window, %lu collisions\n",
1518 ifp
->stats
.tx_window_errors
, ifp
->stats
.collisions
);
1519 #endif /* HAVE_PROC_NET_DEV */
1521 #ifdef HAVE_NET_RT_IFLIST
1522 /* Statistics print out using sysctl (). */
1524 " input packets %llu, bytes %llu, dropped %llu,"
1525 " multicast packets %llu\n",
1526 (unsigned long long)ifp
->stats
.ifi_ipackets
,
1527 (unsigned long long)ifp
->stats
.ifi_ibytes
,
1528 (unsigned long long)ifp
->stats
.ifi_iqdrops
,
1529 (unsigned long long)ifp
->stats
.ifi_imcasts
);
1531 vty_out(vty
, " input errors %llu\n",
1532 (unsigned long long)ifp
->stats
.ifi_ierrors
);
1535 " output packets %llu, bytes %llu,"
1536 " multicast packets %llu\n",
1537 (unsigned long long)ifp
->stats
.ifi_opackets
,
1538 (unsigned long long)ifp
->stats
.ifi_obytes
,
1539 (unsigned long long)ifp
->stats
.ifi_omcasts
);
1541 vty_out(vty
, " output errors %llu\n",
1542 (unsigned long long)ifp
->stats
.ifi_oerrors
);
1544 vty_out(vty
, " collisions %llu\n",
1545 (unsigned long long)ifp
->stats
.ifi_collisions
);
1546 #endif /* HAVE_NET_RT_IFLIST */
1549 static void interface_update_stats(void)
1551 #ifdef HAVE_PROC_NET_DEV
1552 /* If system has interface statistics via proc file system, update
1554 ifstat_update_proc();
1555 #endif /* HAVE_PROC_NET_DEV */
1556 #ifdef HAVE_NET_RT_IFLIST
1557 ifstat_update_sysctl();
1558 #endif /* HAVE_NET_RT_IFLIST */
1561 struct cmd_node interface_node
= {INTERFACE_NODE
, "%s(config-if)# ", 1};
1563 #ifndef VTYSH_EXTRACT_PL
1564 #include "zebra/interface_clippy.c"
1566 /* Show all interfaces to vty. */
1567 DEFPY(show_interface
, show_interface_cmd
,
1568 "show interface [vrf NAME$name] [brief$brief]",
1570 "Interface status and configuration\n"
1572 "Interface status and configuration summary\n")
1575 struct interface
*ifp
;
1576 vrf_id_t vrf_id
= VRF_DEFAULT
;
1578 interface_update_stats();
1581 VRF_GET_ID(vrf_id
, name
, false);
1583 /* All interface print. */
1584 vrf
= vrf_lookup_by_id(vrf_id
);
1586 ifs_dump_brief_vty(vty
, vrf
);
1588 FOR_ALL_INTERFACES (vrf
, ifp
) {
1589 if_dump_vty(vty
, ifp
);
1597 /* Show all interfaces to vty. */
1598 DEFPY (show_interface_vrf_all
,
1599 show_interface_vrf_all_cmd
,
1600 "show interface vrf all [brief$brief]",
1602 "Interface status and configuration\n"
1603 VRF_ALL_CMD_HELP_STR
1604 "Interface status and configuration summary\n")
1607 struct interface
*ifp
;
1609 interface_update_stats();
1611 /* All interface print. */
1612 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
1614 ifs_dump_brief_vty(vty
, vrf
);
1616 FOR_ALL_INTERFACES (vrf
, ifp
)
1617 if_dump_vty(vty
, ifp
);
1624 /* Show specified interface to vty. */
1626 DEFUN (show_interface_name_vrf
,
1627 show_interface_name_vrf_cmd
,
1628 "show interface IFNAME vrf NAME",
1630 "Interface status and configuration\n"
1636 struct interface
*ifp
;
1639 interface_update_stats();
1641 VRF_GET_ID(vrf_id
, argv
[idx_name
]->arg
, false);
1643 /* Specified interface print. */
1644 ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
, vrf_id
);
1646 vty_out(vty
, "%% Can't find interface %s\n",
1647 argv
[idx_ifname
]->arg
);
1650 if_dump_vty(vty
, ifp
);
1655 /* Show specified interface to vty. */
1656 DEFUN (show_interface_name_vrf_all
,
1657 show_interface_name_vrf_all_cmd
,
1658 "show interface IFNAME [vrf all]",
1660 "Interface status and configuration\n"
1662 VRF_ALL_CMD_HELP_STR
)
1666 struct interface
*ifp
;
1669 interface_update_stats();
1671 /* All interface print. */
1672 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
1673 /* Specified interface print. */
1674 ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
, vrf
->vrf_id
);
1676 if_dump_vty(vty
, ifp
);
1682 vty_out(vty
, "%% Can't find interface %s\n",
1683 argv
[idx_ifname
]->arg
);
1691 static void if_show_description(struct vty
*vty
, vrf_id_t vrf_id
)
1693 struct vrf
*vrf
= vrf_lookup_by_id(vrf_id
);
1694 struct interface
*ifp
;
1696 vty_out(vty
, "Interface Status Protocol Description\n");
1697 FOR_ALL_INTERFACES (vrf
, ifp
) {
1699 struct zebra_if
*zif
;
1704 len
= vty_out(vty
, "%s", ifp
->name
);
1705 vty_out(vty
, "%*s", (16 - len
), " ");
1707 if (if_is_up(ifp
)) {
1708 vty_out(vty
, "up ");
1709 if (CHECK_FLAG(ifp
->status
,
1710 ZEBRA_INTERFACE_LINKDETECTION
)) {
1711 if (if_is_running(ifp
))
1712 vty_out(vty
, "up ");
1714 vty_out(vty
, "down ");
1716 vty_out(vty
, "unknown ");
1719 vty_out(vty
, "down down ");
1724 vty_out(vty
, "%s", ifp
->desc
);
1727 if (zif
&& zif
->desc
) {
1728 vty_out(vty
, "%s%s",
1739 DEFUN (show_interface_desc
,
1740 show_interface_desc_cmd
,
1741 "show interface description [vrf NAME]",
1743 "Interface status and configuration\n"
1744 "Interface description\n"
1747 vrf_id_t vrf_id
= VRF_DEFAULT
;
1750 VRF_GET_ID(vrf_id
, argv
[4]->arg
, false);
1752 if_show_description(vty
, vrf_id
);
1758 DEFUN (show_interface_desc_vrf_all
,
1759 show_interface_desc_vrf_all_cmd
,
1760 "show interface description vrf all",
1762 "Interface status and configuration\n"
1763 "Interface description\n"
1764 VRF_ALL_CMD_HELP_STR
)
1768 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
1769 if (!RB_EMPTY(if_name_head
, &vrf
->ifaces_by_name
)) {
1770 vty_out(vty
, "\n\tVRF %u\n\n", vrf
->vrf_id
);
1771 if_show_description(vty
, vrf
->vrf_id
);
1780 "Set multicast flag to interface\n")
1782 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1784 struct zebra_if
*if_data
;
1786 if (CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
)) {
1787 ret
= if_set_flags(ifp
, IFF_MULTICAST
);
1789 vty_out(vty
, "Can't set multicast flag\n");
1790 return CMD_WARNING_CONFIG_FAILED
;
1794 if_data
= ifp
->info
;
1795 if_data
->multicast
= IF_ZEBRA_MULTICAST_ON
;
1800 DEFUN (no_multicast
,
1804 "Unset multicast flag to interface\n")
1806 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1808 struct zebra_if
*if_data
;
1810 if (CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
)) {
1811 ret
= if_unset_flags(ifp
, IFF_MULTICAST
);
1813 vty_out(vty
, "Can't unset multicast flag\n");
1814 return CMD_WARNING_CONFIG_FAILED
;
1818 if_data
= ifp
->info
;
1819 if_data
->multicast
= IF_ZEBRA_MULTICAST_OFF
;
1827 "Enable link detection on interface\n")
1829 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1830 int if_was_operative
;
1832 if_was_operative
= if_is_no_ptm_operative(ifp
);
1833 SET_FLAG(ifp
->status
, ZEBRA_INTERFACE_LINKDETECTION
);
1835 /* When linkdetection is enabled, if might come down */
1836 if (!if_is_no_ptm_operative(ifp
) && if_was_operative
)
1839 /* FIXME: Will defer status change forwarding if interface
1840 does not come down! */
1846 DEFUN (no_linkdetect
,
1850 "Disable link detection on interface\n")
1852 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1853 int if_was_operative
;
1855 if_was_operative
= if_is_no_ptm_operative(ifp
);
1856 UNSET_FLAG(ifp
->status
, ZEBRA_INTERFACE_LINKDETECTION
);
1858 /* Interface may come up after disabling link detection */
1859 if (if_is_operative(ifp
) && !if_was_operative
)
1862 /* FIXME: see linkdetect_cmd */
1870 "Shutdown the selected interface\n")
1872 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1874 struct zebra_if
*if_data
;
1876 if (ifp
->ifindex
!= IFINDEX_INTERNAL
) {
1877 ret
= if_unset_flags(ifp
, IFF_UP
);
1879 vty_out(vty
, "Can't shutdown interface\n");
1880 return CMD_WARNING_CONFIG_FAILED
;
1884 if_data
= ifp
->info
;
1885 if_data
->shutdown
= IF_ZEBRA_SHUTDOWN_ON
;
1890 DEFUN (no_shutdown_if
,
1894 "Shutdown the selected interface\n")
1896 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1898 struct zebra_if
*if_data
;
1900 if (ifp
->ifindex
!= IFINDEX_INTERNAL
) {
1901 ret
= if_set_flags(ifp
, IFF_UP
| IFF_RUNNING
);
1903 vty_out(vty
, "Can't up interface\n");
1904 return CMD_WARNING_CONFIG_FAILED
;
1908 /* Some addresses (in particular, IPv6 addresses on Linux) get
1909 * removed when the interface goes down. They need to be
1912 if_addr_wakeup(ifp
);
1915 if_data
= ifp
->info
;
1916 if_data
->shutdown
= IF_ZEBRA_SHUTDOWN_OFF
;
1921 DEFUN (bandwidth_if
,
1923 "bandwidth (1-100000)",
1924 "Set bandwidth informational parameter\n"
1925 "Bandwidth in megabits\n")
1928 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1929 unsigned int bandwidth
;
1931 bandwidth
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
1933 /* bandwidth range is <1-100000> */
1934 if (bandwidth
< 1 || bandwidth
> 100000) {
1935 vty_out(vty
, "Bandwidth is invalid\n");
1936 return CMD_WARNING_CONFIG_FAILED
;
1939 ifp
->bandwidth
= bandwidth
;
1941 /* force protocols to recalculate routes due to cost change */
1942 if (if_is_operative(ifp
))
1943 zebra_interface_up_update(ifp
);
1948 DEFUN (no_bandwidth_if
,
1949 no_bandwidth_if_cmd
,
1950 "no bandwidth [(1-100000)]",
1952 "Set bandwidth informational parameter\n"
1953 "Bandwidth in megabits\n")
1955 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1959 /* force protocols to recalculate routes due to cost change */
1960 if (if_is_operative(ifp
))
1961 zebra_interface_up_update(ifp
);
1967 struct cmd_node link_params_node
= {
1968 LINK_PARAMS_NODE
, "%s(config-link-params)# ", 1,
1971 static void link_param_cmd_set_uint32(struct interface
*ifp
, uint32_t *field
,
1972 uint32_t type
, uint32_t value
)
1974 /* Update field as needed */
1975 if (IS_PARAM_UNSET(ifp
->link_params
, type
) || *field
!= value
) {
1977 SET_PARAM(ifp
->link_params
, type
);
1979 /* force protocols to update LINK STATE due to parameters change
1981 if (if_is_operative(ifp
))
1982 zebra_interface_parameters_update(ifp
);
1985 static void link_param_cmd_set_float(struct interface
*ifp
, float *field
,
1986 uint32_t type
, float value
)
1989 /* Update field as needed */
1990 if (IS_PARAM_UNSET(ifp
->link_params
, type
) || *field
!= value
) {
1992 SET_PARAM(ifp
->link_params
, type
);
1994 /* force protocols to update LINK STATE due to parameters change
1996 if (if_is_operative(ifp
))
1997 zebra_interface_parameters_update(ifp
);
2001 static void link_param_cmd_unset(struct interface
*ifp
, uint32_t type
)
2003 if (ifp
->link_params
== NULL
)
2007 UNSET_PARAM(ifp
->link_params
, type
);
2009 /* force protocols to update LINK STATE due to parameters change */
2010 if (if_is_operative(ifp
))
2011 zebra_interface_parameters_update(ifp
);
2014 DEFUN_NOSH (link_params
,
2019 /* vty->qobj_index stays the same @ interface pointer */
2020 vty
->node
= LINK_PARAMS_NODE
;
2025 DEFUN_NOSH (exit_link_params
,
2026 exit_link_params_cmd
,
2028 "Exit from Link Params configuration mode\n")
2030 if (vty
->node
== LINK_PARAMS_NODE
)
2031 vty
->node
= INTERFACE_NODE
;
2035 /* Specific Traffic Engineering parameters commands */
2036 DEFUN (link_params_enable
,
2037 link_params_enable_cmd
,
2039 "Activate link parameters on this interface\n")
2041 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2043 /* This command could be issue at startup, when activate MPLS TE */
2044 /* on a new interface or after a ON / OFF / ON toggle */
2045 /* In all case, TE parameters are reset to their default factory */
2046 if (IS_ZEBRA_DEBUG_EVENT
)
2048 "Link-params: enable TE link parameters on interface %s",
2051 if (!if_link_params_get(ifp
)) {
2052 if (IS_ZEBRA_DEBUG_EVENT
)
2054 "Link-params: failed to init TE link parameters %s",
2057 return CMD_WARNING_CONFIG_FAILED
;
2060 /* force protocols to update LINK STATE due to parameters change */
2061 if (if_is_operative(ifp
))
2062 zebra_interface_parameters_update(ifp
);
2067 DEFUN (no_link_params_enable
,
2068 no_link_params_enable_cmd
,
2071 "Disable link parameters on this interface\n")
2073 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2075 zlog_debug("MPLS-TE: disable TE link parameters on interface %s",
2078 if_link_params_free(ifp
);
2080 /* force protocols to update LINK STATE due to parameters change */
2081 if (if_is_operative(ifp
))
2082 zebra_interface_parameters_update(ifp
);
2087 /* STANDARD TE metrics */
2088 DEFUN (link_params_metric
,
2089 link_params_metric_cmd
,
2090 "metric (0-4294967295)",
2091 "Link metric for MPLS-TE purpose\n"
2092 "Metric value in decimal\n")
2095 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2096 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2099 metric
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2101 /* Update TE metric if needed */
2102 link_param_cmd_set_uint32(ifp
, &iflp
->te_metric
, LP_TE_METRIC
, metric
);
2107 DEFUN (no_link_params_metric
,
2108 no_link_params_metric_cmd
,
2111 "Disable Link Metric on this interface\n")
2113 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2115 /* Unset TE Metric */
2116 link_param_cmd_unset(ifp
, LP_TE_METRIC
);
2121 DEFUN (link_params_maxbw
,
2122 link_params_maxbw_cmd
,
2124 "Maximum bandwidth that can be used\n"
2125 "Bytes/second (IEEE floating point format)\n")
2127 int idx_bandwidth
= 1;
2128 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2129 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2133 if (sscanf(argv
[idx_bandwidth
]->arg
, "%g", &bw
) != 1) {
2134 vty_out(vty
, "link_params_maxbw: fscanf: %s\n",
2135 safe_strerror(errno
));
2136 return CMD_WARNING_CONFIG_FAILED
;
2139 /* Check that Maximum bandwidth is not lower than other bandwidth
2141 if ((bw
<= iflp
->max_rsv_bw
) || (bw
<= iflp
->unrsv_bw
[0])
2142 || (bw
<= iflp
->unrsv_bw
[1]) || (bw
<= iflp
->unrsv_bw
[2])
2143 || (bw
<= iflp
->unrsv_bw
[3]) || (bw
<= iflp
->unrsv_bw
[4])
2144 || (bw
<= iflp
->unrsv_bw
[5]) || (bw
<= iflp
->unrsv_bw
[6])
2145 || (bw
<= iflp
->unrsv_bw
[7]) || (bw
<= iflp
->ava_bw
)
2146 || (bw
<= iflp
->res_bw
) || (bw
<= iflp
->use_bw
)) {
2148 "Maximum Bandwidth could not be lower than others bandwidth\n");
2149 return CMD_WARNING_CONFIG_FAILED
;
2152 /* Update Maximum Bandwidth if needed */
2153 link_param_cmd_set_float(ifp
, &iflp
->max_bw
, LP_MAX_BW
, bw
);
2158 DEFUN (link_params_max_rsv_bw
,
2159 link_params_max_rsv_bw_cmd
,
2160 "max-rsv-bw BANDWIDTH",
2161 "Maximum bandwidth that may be reserved\n"
2162 "Bytes/second (IEEE floating point format)\n")
2164 int idx_bandwidth
= 1;
2165 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2166 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2169 if (sscanf(argv
[idx_bandwidth
]->arg
, "%g", &bw
) != 1) {
2170 vty_out(vty
, "link_params_max_rsv_bw: fscanf: %s\n",
2171 safe_strerror(errno
));
2172 return CMD_WARNING_CONFIG_FAILED
;
2175 /* Check that bandwidth is not greater than maximum bandwidth parameter
2177 if (bw
> iflp
->max_bw
) {
2179 "Maximum Reservable Bandwidth could not be greater than Maximum Bandwidth (%g)\n",
2181 return CMD_WARNING_CONFIG_FAILED
;
2184 /* Update Maximum Reservable Bandwidth if needed */
2185 link_param_cmd_set_float(ifp
, &iflp
->max_rsv_bw
, LP_MAX_RSV_BW
, bw
);
2190 DEFUN (link_params_unrsv_bw
,
2191 link_params_unrsv_bw_cmd
,
2192 "unrsv-bw (0-7) BANDWIDTH",
2193 "Unreserved bandwidth at each priority level\n"
2195 "Bytes/second (IEEE floating point format)\n")
2198 int idx_bandwidth
= 2;
2199 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2200 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2204 /* We don't have to consider about range check here. */
2205 if (sscanf(argv
[idx_number
]->arg
, "%d", &priority
) != 1) {
2206 vty_out(vty
, "link_params_unrsv_bw: fscanf: %s\n",
2207 safe_strerror(errno
));
2208 return CMD_WARNING_CONFIG_FAILED
;
2211 if (sscanf(argv
[idx_bandwidth
]->arg
, "%g", &bw
) != 1) {
2212 vty_out(vty
, "link_params_unrsv_bw: fscanf: %s\n",
2213 safe_strerror(errno
));
2214 return CMD_WARNING_CONFIG_FAILED
;
2217 /* Check that bandwidth is not greater than maximum bandwidth parameter
2219 if (bw
> iflp
->max_bw
) {
2221 "UnReserved Bandwidth could not be greater than Maximum Bandwidth (%g)\n",
2223 return CMD_WARNING_CONFIG_FAILED
;
2226 /* Update Unreserved Bandwidth if needed */
2227 link_param_cmd_set_float(ifp
, &iflp
->unrsv_bw
[priority
], LP_UNRSV_BW
,
2233 DEFUN (link_params_admin_grp
,
2234 link_params_admin_grp_cmd
,
2235 "admin-grp BITPATTERN",
2236 "Administrative group membership\n"
2237 "32-bit Hexadecimal value (e.g. 0xa1)\n")
2239 int idx_bitpattern
= 1;
2240 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2241 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2242 unsigned long value
;
2244 if (sscanf(argv
[idx_bitpattern
]->arg
, "0x%lx", &value
) != 1) {
2245 vty_out(vty
, "link_params_admin_grp: fscanf: %s\n",
2246 safe_strerror(errno
));
2247 return CMD_WARNING_CONFIG_FAILED
;
2250 /* Update Administrative Group if needed */
2251 link_param_cmd_set_uint32(ifp
, &iflp
->admin_grp
, LP_ADM_GRP
, value
);
2256 DEFUN (no_link_params_admin_grp
,
2257 no_link_params_admin_grp_cmd
,
2260 "Disable Administrative group membership on this interface\n")
2262 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2264 /* Unset Admin Group */
2265 link_param_cmd_unset(ifp
, LP_ADM_GRP
);
2270 /* RFC5392 & RFC5316: INTER-AS */
2271 DEFUN (link_params_inter_as
,
2272 link_params_inter_as_cmd
,
2273 "neighbor A.B.C.D as (1-4294967295)",
2274 "Configure remote ASBR information (Neighbor IP address and AS number)\n"
2275 "Remote IP address in dot decimal A.B.C.D\n"
2276 "Remote AS number\n"
2277 "AS number in the range <1-4294967295>\n")
2282 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2283 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2284 struct in_addr addr
;
2287 if (!inet_aton(argv
[idx_ipv4
]->arg
, &addr
)) {
2288 vty_out(vty
, "Please specify Router-Addr by A.B.C.D\n");
2289 return CMD_WARNING_CONFIG_FAILED
;
2292 as
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2294 /* Update Remote IP and Remote AS fields if needed */
2295 if (IS_PARAM_UNSET(iflp
, LP_RMT_AS
) || iflp
->rmt_as
!= as
2296 || iflp
->rmt_ip
.s_addr
!= addr
.s_addr
) {
2299 iflp
->rmt_ip
.s_addr
= addr
.s_addr
;
2300 SET_PARAM(iflp
, LP_RMT_AS
);
2302 /* force protocols to update LINK STATE due to parameters change
2304 if (if_is_operative(ifp
))
2305 zebra_interface_parameters_update(ifp
);
2310 DEFUN (no_link_params_inter_as
,
2311 no_link_params_inter_as_cmd
,
2314 "Remove Neighbor IP address and AS number for Inter-AS TE\n")
2316 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2317 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2319 /* Reset Remote IP and AS neighbor */
2321 iflp
->rmt_ip
.s_addr
= 0;
2322 UNSET_PARAM(iflp
, LP_RMT_AS
);
2324 /* force protocols to update LINK STATE due to parameters change */
2325 if (if_is_operative(ifp
))
2326 zebra_interface_parameters_update(ifp
);
2331 /* RFC7471: OSPF Traffic Engineering (TE) Metric extensions &
2332 * draft-ietf-isis-metric-extensions-07.txt */
2333 DEFUN (link_params_delay
,
2334 link_params_delay_cmd
,
2335 "delay (0-16777215) [min (0-16777215) max (0-16777215)]",
2336 "Unidirectional Average Link Delay\n"
2337 "Average delay in micro-second as decimal (0...16777215)\n"
2339 "Minimum delay in micro-second as decimal (0...16777215)\n"
2341 "Maximum delay in micro-second as decimal (0...16777215)\n")
2343 /* Get and Check new delay values */
2344 uint32_t delay
= 0, low
= 0, high
= 0;
2345 delay
= strtoul(argv
[1]->arg
, NULL
, 10);
2347 low
= strtoul(argv
[3]->arg
, NULL
, 10);
2348 high
= strtoul(argv
[5]->arg
, NULL
, 10);
2351 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2352 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2356 /* Check new delay value against old Min and Max delays if set
2358 if (IS_PARAM_SET(iflp
, LP_MM_DELAY
)
2359 && (delay
<= iflp
->min_delay
|| delay
>= iflp
->max_delay
)) {
2361 "Average delay should be comprise between Min (%d) and Max (%d) delay\n",
2362 iflp
->min_delay
, iflp
->max_delay
);
2363 return CMD_WARNING_CONFIG_FAILED
;
2365 /* Update delay if value is not set or change */
2366 if (IS_PARAM_UNSET(iflp
, LP_DELAY
) || iflp
->av_delay
!= delay
) {
2367 iflp
->av_delay
= delay
;
2368 SET_PARAM(iflp
, LP_DELAY
);
2371 /* Unset Min and Max delays if already set */
2372 if (IS_PARAM_SET(iflp
, LP_MM_DELAY
)) {
2373 iflp
->min_delay
= 0;
2374 iflp
->max_delay
= 0;
2375 UNSET_PARAM(iflp
, LP_MM_DELAY
);
2379 /* Check new delays value coherency */
2380 if (delay
<= low
|| delay
>= high
) {
2382 "Average delay should be comprise between Min (%d) and Max (%d) delay\n",
2384 return CMD_WARNING_CONFIG_FAILED
;
2386 /* Update Delays if needed */
2387 if (IS_PARAM_UNSET(iflp
, LP_DELAY
)
2388 || IS_PARAM_UNSET(iflp
, LP_MM_DELAY
)
2389 || iflp
->av_delay
!= delay
|| iflp
->min_delay
!= low
2390 || iflp
->max_delay
!= high
) {
2391 iflp
->av_delay
= delay
;
2392 SET_PARAM(iflp
, LP_DELAY
);
2393 iflp
->min_delay
= low
;
2394 iflp
->max_delay
= high
;
2395 SET_PARAM(iflp
, LP_MM_DELAY
);
2400 /* force protocols to update LINK STATE due to parameters change */
2401 if (update
== 1 && if_is_operative(ifp
))
2402 zebra_interface_parameters_update(ifp
);
2407 DEFUN (no_link_params_delay
,
2408 no_link_params_delay_cmd
,
2411 "Disable Unidirectional Average, Min & Max Link Delay on this interface\n")
2413 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2414 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2418 UNSET_PARAM(iflp
, LP_DELAY
);
2419 iflp
->min_delay
= 0;
2420 iflp
->max_delay
= 0;
2421 UNSET_PARAM(iflp
, LP_MM_DELAY
);
2423 /* force protocols to update LINK STATE due to parameters change */
2424 if (if_is_operative(ifp
))
2425 zebra_interface_parameters_update(ifp
);
2430 DEFUN (link_params_delay_var
,
2431 link_params_delay_var_cmd
,
2432 "delay-variation (0-16777215)",
2433 "Unidirectional Link Delay Variation\n"
2434 "delay variation in micro-second as decimal (0...16777215)\n")
2437 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2438 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2441 value
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2443 /* Update Delay Variation if needed */
2444 link_param_cmd_set_uint32(ifp
, &iflp
->delay_var
, LP_DELAY_VAR
, value
);
2449 DEFUN (no_link_params_delay_var
,
2450 no_link_params_delay_var_cmd
,
2451 "no delay-variation",
2453 "Disable Unidirectional Delay Variation on this interface\n")
2455 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2457 /* Unset Delay Variation */
2458 link_param_cmd_unset(ifp
, LP_DELAY_VAR
);
2463 DEFUN (link_params_pkt_loss
,
2464 link_params_pkt_loss_cmd
,
2465 "packet-loss PERCENTAGE",
2466 "Unidirectional Link Packet Loss\n"
2467 "percentage of total traffic by 0.000003% step and less than 50.331642%\n")
2469 int idx_percentage
= 1;
2470 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2471 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2474 if (sscanf(argv
[idx_percentage
]->arg
, "%g", &fval
) != 1) {
2475 vty_out(vty
, "link_params_pkt_loss: fscanf: %s\n",
2476 safe_strerror(errno
));
2477 return CMD_WARNING_CONFIG_FAILED
;
2480 if (fval
> MAX_PKT_LOSS
)
2481 fval
= MAX_PKT_LOSS
;
2483 /* Update Packet Loss if needed */
2484 link_param_cmd_set_float(ifp
, &iflp
->pkt_loss
, LP_PKT_LOSS
, fval
);
2489 DEFUN (no_link_params_pkt_loss
,
2490 no_link_params_pkt_loss_cmd
,
2493 "Disable Unidirectional Link Packet Loss on this interface\n")
2495 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2497 /* Unset Packet Loss */
2498 link_param_cmd_unset(ifp
, LP_PKT_LOSS
);
2503 DEFUN (link_params_res_bw
,
2504 link_params_res_bw_cmd
,
2506 "Unidirectional Residual Bandwidth\n"
2507 "Bytes/second (IEEE floating point format)\n")
2509 int idx_bandwidth
= 1;
2510 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2511 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2514 if (sscanf(argv
[idx_bandwidth
]->arg
, "%g", &bw
) != 1) {
2515 vty_out(vty
, "link_params_res_bw: fscanf: %s\n",
2516 safe_strerror(errno
));
2517 return CMD_WARNING_CONFIG_FAILED
;
2520 /* Check that bandwidth is not greater than maximum bandwidth parameter
2522 if (bw
> iflp
->max_bw
) {
2524 "Residual Bandwidth could not be greater than Maximum Bandwidth (%g)\n",
2526 return CMD_WARNING_CONFIG_FAILED
;
2529 /* Update Residual Bandwidth if needed */
2530 link_param_cmd_set_float(ifp
, &iflp
->res_bw
, LP_RES_BW
, bw
);
2535 DEFUN (no_link_params_res_bw
,
2536 no_link_params_res_bw_cmd
,
2539 "Disable Unidirectional Residual Bandwidth on this interface\n")
2541 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2543 /* Unset Residual Bandwidth */
2544 link_param_cmd_unset(ifp
, LP_RES_BW
);
2549 DEFUN (link_params_ava_bw
,
2550 link_params_ava_bw_cmd
,
2552 "Unidirectional Available Bandwidth\n"
2553 "Bytes/second (IEEE floating point format)\n")
2555 int idx_bandwidth
= 1;
2556 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2557 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2560 if (sscanf(argv
[idx_bandwidth
]->arg
, "%g", &bw
) != 1) {
2561 vty_out(vty
, "link_params_ava_bw: fscanf: %s\n",
2562 safe_strerror(errno
));
2563 return CMD_WARNING_CONFIG_FAILED
;
2566 /* Check that bandwidth is not greater than maximum bandwidth parameter
2568 if (bw
> iflp
->max_bw
) {
2570 "Available Bandwidth could not be greater than Maximum Bandwidth (%g)\n",
2572 return CMD_WARNING_CONFIG_FAILED
;
2575 /* Update Residual Bandwidth if needed */
2576 link_param_cmd_set_float(ifp
, &iflp
->ava_bw
, LP_AVA_BW
, bw
);
2581 DEFUN (no_link_params_ava_bw
,
2582 no_link_params_ava_bw_cmd
,
2585 "Disable Unidirectional Available Bandwidth on this interface\n")
2587 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2589 /* Unset Available Bandwidth */
2590 link_param_cmd_unset(ifp
, LP_AVA_BW
);
2595 DEFUN (link_params_use_bw
,
2596 link_params_use_bw_cmd
,
2598 "Unidirectional Utilised Bandwidth\n"
2599 "Bytes/second (IEEE floating point format)\n")
2601 int idx_bandwidth
= 1;
2602 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2603 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2606 if (sscanf(argv
[idx_bandwidth
]->arg
, "%g", &bw
) != 1) {
2607 vty_out(vty
, "link_params_use_bw: fscanf: %s\n",
2608 safe_strerror(errno
));
2609 return CMD_WARNING_CONFIG_FAILED
;
2612 /* Check that bandwidth is not greater than maximum bandwidth parameter
2614 if (bw
> iflp
->max_bw
) {
2616 "Utilised Bandwidth could not be greater than Maximum Bandwidth (%g)\n",
2618 return CMD_WARNING_CONFIG_FAILED
;
2621 /* Update Utilized Bandwidth if needed */
2622 link_param_cmd_set_float(ifp
, &iflp
->use_bw
, LP_USE_BW
, bw
);
2627 DEFUN (no_link_params_use_bw
,
2628 no_link_params_use_bw_cmd
,
2631 "Disable Unidirectional Utilised Bandwidth on this interface\n")
2633 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2635 /* Unset Utilised Bandwidth */
2636 link_param_cmd_unset(ifp
, LP_USE_BW
);
2641 static int ip_address_install(struct vty
*vty
, struct interface
*ifp
,
2642 const char *addr_str
, const char *peer_str
,
2645 struct zebra_if
*if_data
;
2646 struct prefix_ipv4 lp
, pp
;
2647 struct connected
*ifc
;
2648 struct prefix_ipv4
*p
;
2650 enum zebra_dplane_result dplane_res
;
2652 if_data
= ifp
->info
;
2654 ret
= str2prefix_ipv4(addr_str
, &lp
);
2656 vty_out(vty
, "%% Malformed address \n");
2657 return CMD_WARNING_CONFIG_FAILED
;
2660 if (ipv4_martian(&lp
.prefix
)) {
2661 vty_out(vty
, "%% Invalid address\n");
2662 return CMD_WARNING_CONFIG_FAILED
;
2666 if (lp
.prefixlen
!= 32) {
2668 "%% Local prefix length for P-t-P address must be /32\n");
2669 return CMD_WARNING_CONFIG_FAILED
;
2672 ret
= str2prefix_ipv4(peer_str
, &pp
);
2674 vty_out(vty
, "%% Malformed peer address\n");
2675 return CMD_WARNING_CONFIG_FAILED
;
2679 ifc
= connected_check_ptp(ifp
, &lp
, peer_str
? &pp
: NULL
);
2681 ifc
= connected_new();
2685 p
= prefix_ipv4_new();
2687 ifc
->address
= (struct prefix
*)p
;
2690 SET_FLAG(ifc
->flags
, ZEBRA_IFA_PEER
);
2691 p
= prefix_ipv4_new();
2693 ifc
->destination
= (struct prefix
*)p
;
2698 ifc
->label
= XSTRDUP(MTYPE_CONNECTED_LABEL
, label
);
2700 /* Add to linked list. */
2701 listnode_add(ifp
->connected
, ifc
);
2704 /* This address is configured from zebra. */
2705 if (!CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
2706 SET_FLAG(ifc
->conf
, ZEBRA_IFC_CONFIGURED
);
2708 /* In case of this route need to install kernel. */
2709 if (!CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
)
2710 && CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
)
2711 && !(if_data
&& if_data
->shutdown
== IF_ZEBRA_SHUTDOWN_ON
)) {
2712 /* Some system need to up the interface to set IP address. */
2713 if (!if_is_up(ifp
)) {
2714 if_set_flags(ifp
, IFF_UP
| IFF_RUNNING
);
2718 dplane_res
= dplane_intf_addr_set(ifp
, ifc
);
2719 if (dplane_res
== ZEBRA_DPLANE_REQUEST_FAILURE
) {
2720 vty_out(vty
, "%% Can't set interface IP address: %s.\n",
2721 dplane_res2str(dplane_res
));
2722 return CMD_WARNING_CONFIG_FAILED
;
2725 SET_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
);
2726 /* The address will be advertised to zebra clients when the
2728 * from the kernel has been received.
2729 * It will also be added to the subnet chain list, then. */
2735 static int ip_address_uninstall(struct vty
*vty
, struct interface
*ifp
,
2736 const char *addr_str
, const char *peer_str
,
2739 struct prefix_ipv4 lp
, pp
;
2740 struct connected
*ifc
;
2742 enum zebra_dplane_result dplane_res
;
2744 /* Convert to prefix structure. */
2745 ret
= str2prefix_ipv4(addr_str
, &lp
);
2747 vty_out(vty
, "%% Malformed address \n");
2748 return CMD_WARNING_CONFIG_FAILED
;
2752 if (lp
.prefixlen
!= 32) {
2754 "%% Local prefix length for P-t-P address must be /32\n");
2755 return CMD_WARNING_CONFIG_FAILED
;
2758 ret
= str2prefix_ipv4(peer_str
, &pp
);
2760 vty_out(vty
, "%% Malformed peer address\n");
2761 return CMD_WARNING_CONFIG_FAILED
;
2765 /* Check current interface address. */
2766 ifc
= connected_check_ptp(ifp
, &lp
, peer_str
? &pp
: NULL
);
2768 vty_out(vty
, "%% Can't find address\n");
2769 return CMD_WARNING_CONFIG_FAILED
;
2772 /* This is not configured address. */
2773 if (!CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
2774 return CMD_WARNING_CONFIG_FAILED
;
2776 UNSET_FLAG(ifc
->conf
, ZEBRA_IFC_CONFIGURED
);
2778 /* This is not real address or interface is not active. */
2779 if (!CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
)
2780 || !CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
)) {
2781 listnode_delete(ifp
->connected
, ifc
);
2782 connected_free(ifc
);
2783 return CMD_WARNING_CONFIG_FAILED
;
2786 /* This is real route. */
2787 dplane_res
= dplane_intf_addr_unset(ifp
, ifc
);
2788 if (dplane_res
== ZEBRA_DPLANE_REQUEST_FAILURE
) {
2789 vty_out(vty
, "%% Can't unset interface IP address: %s.\n",
2790 dplane_res2str(dplane_res
));
2791 return CMD_WARNING_CONFIG_FAILED
;
2793 UNSET_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
);
2794 /* we will receive a kernel notification about this route being removed.
2795 * this will trigger its removal from the connected list. */
2801 "ip address A.B.C.D/M",
2802 "Interface Internet Protocol config commands\n"
2803 "Set the IP address of an interface\n"
2804 "IP address (e.g. 10.0.0.1/8)\n")
2806 int idx_ipv4_prefixlen
= 2;
2807 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2808 return ip_address_install(vty
, ifp
, argv
[idx_ipv4_prefixlen
]->arg
, NULL
,
2812 DEFUN (no_ip_address
,
2814 "no ip address A.B.C.D/M",
2816 "Interface Internet Protocol config commands\n"
2817 "Set the IP address of an interface\n"
2818 "IP Address (e.g. 10.0.0.1/8)\n")
2820 int idx_ipv4_prefixlen
= 3;
2821 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2822 return ip_address_uninstall(vty
, ifp
, argv
[idx_ipv4_prefixlen
]->arg
,
2826 DEFUN(ip_address_peer
,
2827 ip_address_peer_cmd
,
2828 "ip address A.B.C.D peer A.B.C.D/M",
2829 "Interface Internet Protocol config commands\n"
2830 "Set the IP address of an interface\n"
2831 "Local IP (e.g. 10.0.0.1) for P-t-P address\n"
2832 "Specify P-t-P address\n"
2833 "Peer IP address (e.g. 10.0.0.1/8)\n")
2835 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2836 return ip_address_install(vty
, ifp
, argv
[2]->arg
, argv
[4]->arg
, NULL
);
2839 DEFUN(no_ip_address_peer
,
2840 no_ip_address_peer_cmd
,
2841 "no ip address A.B.C.D peer A.B.C.D/M",
2843 "Interface Internet Protocol config commands\n"
2844 "Set the IP address of an interface\n"
2845 "Local IP (e.g. 10.0.0.1) for P-t-P address\n"
2846 "Specify P-t-P address\n"
2847 "Peer IP address (e.g. 10.0.0.1/8)\n")
2849 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2850 return ip_address_uninstall(vty
, ifp
, argv
[3]->arg
, argv
[5]->arg
, NULL
);
2854 DEFUN (ip_address_label
,
2855 ip_address_label_cmd
,
2856 "ip address A.B.C.D/M label LINE",
2857 "Interface Internet Protocol config commands\n"
2858 "Set the IP address of an interface\n"
2859 "IP address (e.g. 10.0.0.1/8)\n"
2860 "Label of this address\n"
2863 int idx_ipv4_prefixlen
= 2;
2865 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2866 return ip_address_install(vty
, ifp
, argv
[idx_ipv4_prefixlen
]->arg
, NULL
,
2867 argv
[idx_line
]->arg
);
2870 DEFUN (no_ip_address_label
,
2871 no_ip_address_label_cmd
,
2872 "no ip address A.B.C.D/M label LINE",
2874 "Interface Internet Protocol config commands\n"
2875 "Set the IP address of an interface\n"
2876 "IP address (e.g. 10.0.0.1/8)\n"
2877 "Label of this address\n"
2880 int idx_ipv4_prefixlen
= 3;
2882 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2883 return ip_address_uninstall(vty
, ifp
, argv
[idx_ipv4_prefixlen
]->arg
,
2884 NULL
, argv
[idx_line
]->arg
);
2886 #endif /* HAVE_NETLINK */
2888 static int ipv6_address_install(struct vty
*vty
, struct interface
*ifp
,
2889 const char *addr_str
, const char *peer_str
,
2892 struct zebra_if
*if_data
;
2893 struct prefix_ipv6 cp
;
2894 struct connected
*ifc
;
2895 struct prefix_ipv6
*p
;
2897 enum zebra_dplane_result dplane_res
;
2899 if_data
= ifp
->info
;
2901 ret
= str2prefix_ipv6(addr_str
, &cp
);
2903 vty_out(vty
, "%% Malformed address \n");
2904 return CMD_WARNING_CONFIG_FAILED
;
2907 if (ipv6_martian(&cp
.prefix
)) {
2908 vty_out(vty
, "%% Invalid address\n");
2909 return CMD_WARNING_CONFIG_FAILED
;
2912 ifc
= connected_check(ifp
, (struct prefix
*)&cp
);
2914 ifc
= connected_new();
2918 p
= prefix_ipv6_new();
2920 ifc
->address
= (struct prefix
*)p
;
2924 ifc
->label
= XSTRDUP(MTYPE_CONNECTED_LABEL
, label
);
2926 /* Add to linked list. */
2927 listnode_add(ifp
->connected
, ifc
);
2930 /* This address is configured from zebra. */
2931 if (!CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
2932 SET_FLAG(ifc
->conf
, ZEBRA_IFC_CONFIGURED
);
2934 /* In case of this route need to install kernel. */
2935 if (!CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
)
2936 && CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
)
2937 && !(if_data
&& if_data
->shutdown
== IF_ZEBRA_SHUTDOWN_ON
)) {
2938 /* Some system need to up the interface to set IP address. */
2939 if (!if_is_up(ifp
)) {
2940 if_set_flags(ifp
, IFF_UP
| IFF_RUNNING
);
2944 dplane_res
= dplane_intf_addr_set(ifp
, ifc
);
2945 if (dplane_res
== ZEBRA_DPLANE_REQUEST_FAILURE
) {
2946 vty_out(vty
, "%% Can't set interface IP address: %s.\n",
2947 dplane_res2str(dplane_res
));
2948 return CMD_WARNING_CONFIG_FAILED
;
2951 SET_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
);
2952 /* The address will be advertised to zebra clients when the
2954 * from the kernel has been received. */
2960 /* Return true if an ipv6 address is configured on ifp */
2961 int ipv6_address_configured(struct interface
*ifp
)
2963 struct connected
*connected
;
2964 struct listnode
*node
;
2966 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, node
, connected
))
2967 if (CHECK_FLAG(connected
->conf
, ZEBRA_IFC_REAL
)
2968 && (connected
->address
->family
== AF_INET6
))
2974 static int ipv6_address_uninstall(struct vty
*vty
, struct interface
*ifp
,
2975 const char *addr_str
, const char *peer_str
,
2978 struct prefix_ipv6 cp
;
2979 struct connected
*ifc
;
2981 enum zebra_dplane_result dplane_res
;
2983 /* Convert to prefix structure. */
2984 ret
= str2prefix_ipv6(addr_str
, &cp
);
2986 vty_out(vty
, "%% Malformed address \n");
2987 return CMD_WARNING_CONFIG_FAILED
;
2990 /* Check current interface address. */
2991 ifc
= connected_check(ifp
, (struct prefix
*)&cp
);
2993 vty_out(vty
, "%% Can't find address\n");
2994 return CMD_WARNING_CONFIG_FAILED
;
2997 /* This is not configured address. */
2998 if (!CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
2999 return CMD_WARNING_CONFIG_FAILED
;
3001 UNSET_FLAG(ifc
->conf
, ZEBRA_IFC_CONFIGURED
);
3003 /* This is not real address or interface is not active. */
3004 if (!CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
)
3005 || !CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
)) {
3006 listnode_delete(ifp
->connected
, ifc
);
3007 connected_free(ifc
);
3008 return CMD_WARNING_CONFIG_FAILED
;
3011 /* This is real route. */
3012 dplane_res
= dplane_intf_addr_unset(ifp
, ifc
);
3013 if (dplane_res
== ZEBRA_DPLANE_REQUEST_FAILURE
) {
3014 vty_out(vty
, "%% Can't unset interface IP address: %s.\n",
3015 dplane_res2str(dplane_res
));
3016 return CMD_WARNING_CONFIG_FAILED
;
3019 UNSET_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
);
3020 /* This information will be propagated to the zclients when the
3021 * kernel notification is received. */
3025 DEFUN (ipv6_address
,
3027 "ipv6 address X:X::X:X/M",
3028 "Interface IPv6 config commands\n"
3029 "Set the IP address of an interface\n"
3030 "IPv6 address (e.g. 3ffe:506::1/48)\n")
3032 int idx_ipv6_prefixlen
= 2;
3033 VTY_DECLVAR_CONTEXT(interface
, ifp
);
3034 return ipv6_address_install(vty
, ifp
, argv
[idx_ipv6_prefixlen
]->arg
,
3038 DEFUN (no_ipv6_address
,
3039 no_ipv6_address_cmd
,
3040 "no ipv6 address X:X::X:X/M",
3042 "Interface IPv6 config commands\n"
3043 "Set the IP address of an interface\n"
3044 "IPv6 address (e.g. 3ffe:506::1/48)\n")
3046 int idx_ipv6_prefixlen
= 3;
3047 VTY_DECLVAR_CONTEXT(interface
, ifp
);
3048 return ipv6_address_uninstall(vty
, ifp
, argv
[idx_ipv6_prefixlen
]->arg
,
3052 static int link_params_config_write(struct vty
*vty
, struct interface
*ifp
)
3056 if ((ifp
== NULL
) || !HAS_LINK_PARAMS(ifp
))
3059 struct if_link_params
*iflp
= ifp
->link_params
;
3061 vty_out(vty
, " link-params\n");
3062 vty_out(vty
, " enable\n");
3063 if (IS_PARAM_SET(iflp
, LP_TE_METRIC
) && iflp
->te_metric
!= ifp
->metric
)
3064 vty_out(vty
, " metric %u\n", iflp
->te_metric
);
3065 if (IS_PARAM_SET(iflp
, LP_MAX_BW
) && iflp
->max_bw
!= iflp
->default_bw
)
3066 vty_out(vty
, " max-bw %g\n", iflp
->max_bw
);
3067 if (IS_PARAM_SET(iflp
, LP_MAX_RSV_BW
)
3068 && iflp
->max_rsv_bw
!= iflp
->default_bw
)
3069 vty_out(vty
, " max-rsv-bw %g\n", iflp
->max_rsv_bw
);
3070 if (IS_PARAM_SET(iflp
, LP_UNRSV_BW
)) {
3071 for (i
= 0; i
< 8; i
++)
3072 if (iflp
->unrsv_bw
[i
] != iflp
->default_bw
)
3073 vty_out(vty
, " unrsv-bw %d %g\n", i
,
3076 if (IS_PARAM_SET(iflp
, LP_ADM_GRP
))
3077 vty_out(vty
, " admin-grp 0x%x\n", iflp
->admin_grp
);
3078 if (IS_PARAM_SET(iflp
, LP_DELAY
)) {
3079 vty_out(vty
, " delay %u", iflp
->av_delay
);
3080 if (IS_PARAM_SET(iflp
, LP_MM_DELAY
)) {
3081 vty_out(vty
, " min %u", iflp
->min_delay
);
3082 vty_out(vty
, " max %u", iflp
->max_delay
);
3086 if (IS_PARAM_SET(iflp
, LP_DELAY_VAR
))
3087 vty_out(vty
, " delay-variation %u\n", iflp
->delay_var
);
3088 if (IS_PARAM_SET(iflp
, LP_PKT_LOSS
))
3089 vty_out(vty
, " packet-loss %g\n", iflp
->pkt_loss
);
3090 if (IS_PARAM_SET(iflp
, LP_AVA_BW
))
3091 vty_out(vty
, " ava-bw %g\n", iflp
->ava_bw
);
3092 if (IS_PARAM_SET(iflp
, LP_RES_BW
))
3093 vty_out(vty
, " res-bw %g\n", iflp
->res_bw
);
3094 if (IS_PARAM_SET(iflp
, LP_USE_BW
))
3095 vty_out(vty
, " use-bw %g\n", iflp
->use_bw
);
3096 if (IS_PARAM_SET(iflp
, LP_RMT_AS
))
3097 vty_out(vty
, " neighbor %s as %u\n", inet_ntoa(iflp
->rmt_ip
),
3099 vty_out(vty
, " exit-link-params\n");
3103 static int if_config_write(struct vty
*vty
)
3106 struct interface
*ifp
;
3108 zebra_ptm_write(vty
);
3110 RB_FOREACH (vrf0
, vrf_name_head
, &vrfs_by_name
)
3111 FOR_ALL_INTERFACES (vrf0
, ifp
) {
3112 struct zebra_if
*if_data
;
3113 struct listnode
*addrnode
;
3114 struct connected
*ifc
;
3118 if_data
= ifp
->info
;
3119 vrf
= vrf_lookup_by_id(ifp
->vrf_id
);
3121 if (ifp
->vrf_id
== VRF_DEFAULT
)
3122 vty_frame(vty
, "interface %s\n", ifp
->name
);
3124 vty_frame(vty
, "interface %s vrf %s\n",
3125 ifp
->name
, vrf
->name
);
3128 if (if_data
->shutdown
== IF_ZEBRA_SHUTDOWN_ON
)
3129 vty_out(vty
, " shutdown\n");
3131 zebra_ptm_if_write(vty
, if_data
);
3135 vty_out(vty
, " description %s\n", ifp
->desc
);
3137 /* Assign bandwidth here to avoid unnecessary interface
3139 while processing config script */
3140 if (ifp
->bandwidth
!= 0)
3141 vty_out(vty
, " bandwidth %u\n", ifp
->bandwidth
);
3143 if (!CHECK_FLAG(ifp
->status
,
3144 ZEBRA_INTERFACE_LINKDETECTION
))
3145 vty_out(vty
, " no link-detect\n");
3147 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, addrnode
,
3149 if (CHECK_FLAG(ifc
->conf
,
3150 ZEBRA_IFC_CONFIGURED
)) {
3151 char buf
[INET6_ADDRSTRLEN
];
3153 vty_out(vty
, " ip%s address %s",
3154 p
->family
== AF_INET
? ""
3156 inet_ntop(p
->family
,
3159 if (CONNECTED_PEER(ifc
)) {
3160 p
= ifc
->destination
;
3161 vty_out(vty
, " peer %s",
3162 inet_ntop(p
->family
,
3167 vty_out(vty
, "/%d", p
->prefixlen
);
3170 vty_out(vty
, " label %s",
3178 if (if_data
->multicast
3179 != IF_ZEBRA_MULTICAST_UNSPEC
)
3180 vty_out(vty
, " %smulticast\n",
3182 == IF_ZEBRA_MULTICAST_ON
3187 hook_call(zebra_if_config_wr
, vty
, ifp
);
3189 link_params_config_write(vty
, ifp
);
3191 vty_endframe(vty
, "!\n");
3196 /* Allocate and initialize interface vector. */
3197 void zebra_if_init(void)
3199 /* Initialize interface and new hook. */
3200 hook_register_prio(if_add
, 0, if_zebra_new_hook
);
3201 hook_register_prio(if_del
, 0, if_zebra_delete_hook
);
3203 /* Install configuration write function. */
3204 install_node(&interface_node
, if_config_write
);
3205 install_node(&link_params_node
, NULL
);
3208 install_element(VIEW_NODE
, &show_interface_cmd
);
3209 install_element(VIEW_NODE
, &show_interface_vrf_all_cmd
);
3210 install_element(VIEW_NODE
, &show_interface_name_vrf_cmd
);
3211 install_element(VIEW_NODE
, &show_interface_name_vrf_all_cmd
);
3213 install_element(ENABLE_NODE
, &show_interface_desc_cmd
);
3214 install_element(ENABLE_NODE
, &show_interface_desc_vrf_all_cmd
);
3215 install_element(INTERFACE_NODE
, &multicast_cmd
);
3216 install_element(INTERFACE_NODE
, &no_multicast_cmd
);
3217 install_element(INTERFACE_NODE
, &linkdetect_cmd
);
3218 install_element(INTERFACE_NODE
, &no_linkdetect_cmd
);
3219 install_element(INTERFACE_NODE
, &shutdown_if_cmd
);
3220 install_element(INTERFACE_NODE
, &no_shutdown_if_cmd
);
3221 install_element(INTERFACE_NODE
, &bandwidth_if_cmd
);
3222 install_element(INTERFACE_NODE
, &no_bandwidth_if_cmd
);
3223 install_element(INTERFACE_NODE
, &ip_address_cmd
);
3224 install_element(INTERFACE_NODE
, &no_ip_address_cmd
);
3225 install_element(INTERFACE_NODE
, &ip_address_peer_cmd
);
3226 install_element(INTERFACE_NODE
, &no_ip_address_peer_cmd
);
3227 install_element(INTERFACE_NODE
, &ipv6_address_cmd
);
3228 install_element(INTERFACE_NODE
, &no_ipv6_address_cmd
);
3230 install_element(INTERFACE_NODE
, &ip_address_label_cmd
);
3231 install_element(INTERFACE_NODE
, &no_ip_address_label_cmd
);
3232 #endif /* HAVE_NETLINK */
3233 install_element(INTERFACE_NODE
, &link_params_cmd
);
3234 install_default(LINK_PARAMS_NODE
);
3235 install_element(LINK_PARAMS_NODE
, &link_params_enable_cmd
);
3236 install_element(LINK_PARAMS_NODE
, &no_link_params_enable_cmd
);
3237 install_element(LINK_PARAMS_NODE
, &link_params_metric_cmd
);
3238 install_element(LINK_PARAMS_NODE
, &no_link_params_metric_cmd
);
3239 install_element(LINK_PARAMS_NODE
, &link_params_maxbw_cmd
);
3240 install_element(LINK_PARAMS_NODE
, &link_params_max_rsv_bw_cmd
);
3241 install_element(LINK_PARAMS_NODE
, &link_params_unrsv_bw_cmd
);
3242 install_element(LINK_PARAMS_NODE
, &link_params_admin_grp_cmd
);
3243 install_element(LINK_PARAMS_NODE
, &no_link_params_admin_grp_cmd
);
3244 install_element(LINK_PARAMS_NODE
, &link_params_inter_as_cmd
);
3245 install_element(LINK_PARAMS_NODE
, &no_link_params_inter_as_cmd
);
3246 install_element(LINK_PARAMS_NODE
, &link_params_delay_cmd
);
3247 install_element(LINK_PARAMS_NODE
, &no_link_params_delay_cmd
);
3248 install_element(LINK_PARAMS_NODE
, &link_params_delay_var_cmd
);
3249 install_element(LINK_PARAMS_NODE
, &no_link_params_delay_var_cmd
);
3250 install_element(LINK_PARAMS_NODE
, &link_params_pkt_loss_cmd
);
3251 install_element(LINK_PARAMS_NODE
, &no_link_params_pkt_loss_cmd
);
3252 install_element(LINK_PARAMS_NODE
, &link_params_ava_bw_cmd
);
3253 install_element(LINK_PARAMS_NODE
, &no_link_params_ava_bw_cmd
);
3254 install_element(LINK_PARAMS_NODE
, &link_params_res_bw_cmd
);
3255 install_element(LINK_PARAMS_NODE
, &no_link_params_res_bw_cmd
);
3256 install_element(LINK_PARAMS_NODE
, &link_params_use_bw_cmd
);
3257 install_element(LINK_PARAMS_NODE
, &no_link_params_use_bw_cmd
);
3258 install_element(LINK_PARAMS_NODE
, &exit_link_params_cmd
);