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/zserv.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/interface.h"
51 #include "zebra/zebra_vxlan.h"
52 #include "zebra/zebra_errors.h"
54 #define ZEBRA_PTM_SUPPORT
56 DEFINE_HOOK(zebra_if_extra_info
, (struct vty
* vty
, struct interface
*ifp
),
58 DEFINE_HOOK(zebra_if_config_wr
, (struct vty
* vty
, struct interface
*ifp
),
62 static void if_down_del_nbr_connected(struct interface
*ifp
);
64 static int if_zebra_speed_update(struct thread
*thread
)
66 struct interface
*ifp
= THREAD_ARG(thread
);
67 struct zebra_if
*zif
= ifp
->info
;
70 zif
->speed_update
= NULL
;
72 new_speed
= kernel_get_speed(ifp
);
73 if (new_speed
!= ifp
->speed
) {
74 zlog_info("%s: %s old speed: %u new speed: %u",
75 __PRETTY_FUNCTION__
, ifp
->name
, ifp
->speed
,
77 ifp
->speed
= new_speed
;
84 static void zebra_if_node_destroy(route_table_delegate_t
*delegate
,
85 struct route_table
*table
,
86 struct route_node
*node
)
89 list_delete_and_null((struct list
**)&node
->info
);
90 route_node_destroy(delegate
, table
, node
);
93 route_table_delegate_t zebra_if_table_delegate
= {
94 .create_node
= route_node_create
,
95 .destroy_node
= zebra_if_node_destroy
};
97 /* Called when new interface is added. */
98 static int if_zebra_new_hook(struct interface
*ifp
)
100 struct zebra_if
*zebra_if
;
102 zebra_if
= XCALLOC(MTYPE_TMP
, sizeof(struct zebra_if
));
104 zebra_if
->multicast
= IF_ZEBRA_MULTICAST_UNSPEC
;
105 zebra_if
->shutdown
= IF_ZEBRA_SHUTDOWN_OFF
;
106 zebra_ptm_if_init(zebra_if
);
108 ifp
->ptm_enable
= zebra_ptm_get_enable_state();
109 #if defined(HAVE_RTADV)
111 /* Set default router advertise values. */
112 struct rtadvconf
*rtadv
;
114 rtadv
= &zebra_if
->rtadv
;
116 rtadv
->AdvSendAdvertisements
= 0;
117 rtadv
->MaxRtrAdvInterval
= RTADV_MAX_RTR_ADV_INTERVAL
;
118 rtadv
->MinRtrAdvInterval
= RTADV_MIN_RTR_ADV_INTERVAL
;
119 rtadv
->AdvIntervalTimer
= 0;
120 rtadv
->AdvManagedFlag
= 0;
121 rtadv
->AdvOtherConfigFlag
= 0;
122 rtadv
->AdvHomeAgentFlag
= 0;
123 rtadv
->AdvLinkMTU
= 0;
124 rtadv
->AdvReachableTime
= 0;
125 rtadv
->AdvRetransTimer
= 0;
126 rtadv
->AdvCurHopLimit
= 0;
127 rtadv
->AdvDefaultLifetime
=
128 -1; /* derive from MaxRtrAdvInterval */
129 rtadv
->HomeAgentPreference
= 0;
130 rtadv
->HomeAgentLifetime
=
131 -1; /* derive from AdvDefaultLifetime */
132 rtadv
->AdvIntervalOption
= 0;
133 rtadv
->DefaultPreference
= RTADV_PREF_MEDIUM
;
135 rtadv
->AdvPrefixList
= list_new();
137 #endif /* HAVE_RTADV */
139 memset(&zebra_if
->neigh_mac
[0], 0, 6);
141 /* Initialize installed address chains tree. */
142 zebra_if
->ipv4_subnets
=
143 route_table_init_with_delegate(&zebra_if_table_delegate
);
145 ifp
->info
= zebra_if
;
148 * Some platforms are telling us that the interface is
149 * up and ready to go. When we check the speed we
150 * sometimes get the wrong value. Wait a couple
151 * of seconds and ask again. Hopefully it's all settled
154 thread_add_timer(zebrad
.master
, if_zebra_speed_update
, ifp
, 15,
155 &zebra_if
->speed_update
);
159 /* Called when interface is deleted. */
160 static int if_zebra_delete_hook(struct interface
*ifp
)
162 struct zebra_if
*zebra_if
;
165 zebra_if
= ifp
->info
;
167 /* Free installed address chains tree. */
168 if (zebra_if
->ipv4_subnets
)
169 route_table_finish(zebra_if
->ipv4_subnets
);
170 #if defined(HAVE_RTADV)
172 struct rtadvconf
*rtadv
;
174 rtadv
= &zebra_if
->rtadv
;
175 list_delete_and_null(&rtadv
->AdvPrefixList
);
176 #endif /* HAVE_RTADV */
178 THREAD_OFF(zebra_if
->speed_update
);
180 XFREE(MTYPE_TMP
, zebra_if
);
186 /* Build the table key */
187 static void if_build_key(uint32_t ifindex
, struct prefix
*p
)
190 p
->prefixlen
= IPV4_MAX_BITLEN
;
191 p
->u
.prefix4
.s_addr
= ifindex
;
194 /* Link an interface in a per NS interface tree */
195 struct interface
*if_link_per_ns(struct zebra_ns
*ns
, struct interface
*ifp
)
198 struct route_node
*rn
;
200 if (ifp
->ifindex
== IFINDEX_INTERNAL
)
203 if_build_key(ifp
->ifindex
, &p
);
204 rn
= route_node_get(ns
->if_table
, &p
);
206 ifp
= (struct interface
*)rn
->info
;
207 route_unlock_node(rn
); /* get */
217 /* Delete a VRF. This is called in vrf_terminate(). */
218 void if_unlink_per_ns(struct interface
*ifp
)
220 ifp
->node
->info
= NULL
;
221 route_unlock_node(ifp
->node
);
225 /* Look up an interface by identifier within a NS */
226 struct interface
*if_lookup_by_index_per_ns(struct zebra_ns
*ns
,
230 struct route_node
*rn
;
231 struct interface
*ifp
= NULL
;
233 if_build_key(ifindex
, &p
);
234 rn
= route_node_lookup(ns
->if_table
, &p
);
236 ifp
= (struct interface
*)rn
->info
;
237 route_unlock_node(rn
); /* lookup */
242 /* Look up an interface by name within a NS */
243 struct interface
*if_lookup_by_name_per_ns(struct zebra_ns
*ns
,
246 struct route_node
*rn
;
247 struct interface
*ifp
;
249 for (rn
= route_top(ns
->if_table
); rn
; rn
= route_next(rn
)) {
250 ifp
= (struct interface
*)rn
->info
;
251 if (ifp
&& strcmp(ifp
->name
, ifname
) == 0)
258 const char *ifindex2ifname_per_ns(struct zebra_ns
*zns
, unsigned int ifindex
)
260 struct interface
*ifp
;
262 return ((ifp
= if_lookup_by_index_per_ns(zns
, ifindex
)) != NULL
)
267 /* Tie an interface address to its derived subnet list of addresses. */
268 int if_subnet_add(struct interface
*ifp
, struct connected
*ifc
)
270 struct route_node
*rn
;
271 struct zebra_if
*zebra_if
;
273 struct list
*addr_list
;
275 assert(ifp
&& ifp
->info
&& ifc
);
276 zebra_if
= ifp
->info
;
278 /* Get address derived subnet node and associated address list, while
280 address secondary attribute appropriately. */
281 cp
= *CONNECTED_PREFIX(ifc
);
283 rn
= route_node_get(zebra_if
->ipv4_subnets
, &cp
);
285 if ((addr_list
= rn
->info
))
286 SET_FLAG(ifc
->flags
, ZEBRA_IFA_SECONDARY
);
288 UNSET_FLAG(ifc
->flags
, ZEBRA_IFA_SECONDARY
);
289 rn
->info
= addr_list
= list_new();
293 /* Tie address at the tail of address list. */
294 listnode_add(addr_list
, ifc
);
296 /* Return list element count. */
297 return (addr_list
->count
);
300 /* Untie an interface address from its derived subnet list of addresses. */
301 int if_subnet_delete(struct interface
*ifp
, struct connected
*ifc
)
303 struct route_node
*rn
;
304 struct zebra_if
*zebra_if
;
305 struct list
*addr_list
;
308 assert(ifp
&& ifp
->info
&& ifc
);
309 zebra_if
= ifp
->info
;
311 cp
= *CONNECTED_PREFIX(ifc
);
314 /* Get address derived subnet node. */
315 rn
= route_node_lookup(zebra_if
->ipv4_subnets
, &cp
);
316 if (!(rn
&& rn
->info
)) {
317 flog_warn(EC_ZEBRA_REMOVE_ADDR_UNKNOWN_SUBNET
,
318 "Trying to remove an address from an unknown subnet."
319 " (please report this bug)");
322 route_unlock_node(rn
);
324 /* Untie address from subnet's address list. */
325 addr_list
= rn
->info
;
327 /* Deleting an address that is not registered is a bug.
328 * In any case, we shouldn't decrement the lock counter if the address
330 if (!listnode_lookup(addr_list
, ifc
)) {
332 EC_ZEBRA_REMOVE_UNREGISTERED_ADDR
,
333 "Trying to remove an address from a subnet where it is not"
334 " currently registered. (please report this bug)");
338 listnode_delete(addr_list
, ifc
);
339 route_unlock_node(rn
);
341 /* Return list element count, if not empty. */
342 if (addr_list
->count
) {
343 /* If deleted address is primary, mark subsequent one as such
345 if (!CHECK_FLAG(ifc
->flags
, ZEBRA_IFA_SECONDARY
)) {
347 (struct listnode
*)listhead(addr_list
));
348 zebra_interface_address_delete_update(ifp
, ifc
);
349 UNSET_FLAG(ifc
->flags
, ZEBRA_IFA_SECONDARY
);
350 /* XXX: Linux kernel removes all the secondary addresses
352 * address is removed. We could try to work around that,
355 zebra_interface_address_add_update(ifp
, ifc
);
358 return addr_list
->count
;
361 /* Otherwise, free list and route node. */
362 list_delete_and_null(&addr_list
);
364 route_unlock_node(rn
);
369 /* if_flags_mangle: A place for hacks that require mangling
370 * or tweaking the interface flags.
372 * ******************** Solaris flags hacks **************************
374 * Solaris IFF_UP flag reflects only the primary interface as the
375 * routing socket only sends IFINFO for the primary interface. Hence
376 * ~IFF_UP does not per se imply all the logical interfaces are also
377 * down - which we only know of as addresses. Instead we must determine
378 * whether the interface really is up or not according to how many
379 * addresses are still attached. (Solaris always sends RTM_DELADDR if
380 * an interface, logical or not, goes ~IFF_UP).
382 * Ie, we mangle IFF_UP to *additionally* reflect whether or not there
383 * are addresses left in struct connected, not just the actual underlying
386 * We must hence remember the real state of IFF_UP, which we do in
387 * struct zebra_if.primary_state.
389 * Setting IFF_UP within zebra to administratively shutdown the
390 * interface will affect only the primary interface/address on Solaris.
391 ************************End Solaris flags hacks ***********************
393 static void if_flags_mangle(struct interface
*ifp
, uint64_t *newflags
)
396 struct zebra_if
*zif
= ifp
->info
;
398 zif
->primary_state
= *newflags
& (IFF_UP
& 0xff);
400 if (CHECK_FLAG(zif
->primary_state
, IFF_UP
)
401 || listcount(ifp
->connected
) > 0)
402 SET_FLAG(*newflags
, IFF_UP
);
404 UNSET_FLAG(*newflags
, IFF_UP
);
408 /* Update the flags field of the ifp with the new flag set provided.
409 * Take whatever actions are required for any changes in flags we care
412 * newflags should be the raw value, as obtained from the OS.
414 void if_flags_update(struct interface
*ifp
, uint64_t newflags
)
416 if_flags_mangle(ifp
, &newflags
);
418 if (if_is_no_ptm_operative(ifp
)) {
419 /* operative -> inoperative? */
420 ifp
->flags
= newflags
;
421 if (!if_is_operative(ifp
))
424 /* inoperative -> operative? */
425 ifp
->flags
= newflags
;
426 if (if_is_operative(ifp
))
431 /* Wake up configured address if it is not in current kernel
433 static void if_addr_wakeup(struct interface
*ifp
)
435 struct listnode
*node
, *nnode
;
436 struct connected
*ifc
;
440 for (ALL_LIST_ELEMENTS(ifp
->connected
, node
, nnode
, ifc
)) {
443 if (CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_CONFIGURED
)
444 && !CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
)) {
446 if (p
->family
== AF_INET
) {
447 if (!if_is_up(ifp
)) {
448 /* Assume zebra is configured like
452 * ip addr 192.0.2.1/24
455 * As soon as zebra becomes first aware
456 * that gre0 exists in the
457 * kernel, it will set gre0 up and
458 * configure its addresses.
460 * (This may happen at startup when the
461 * interface already exists
462 * or during runtime when the interface
463 * is added to the kernel)
465 * XXX: IRDP code is calling here via
466 * if_add_update - this seems
468 * XXX: RUNNING is not a settable flag
470 * I (paulj) am aware of.
472 if_set_flags(ifp
, IFF_UP
| IFF_RUNNING
);
476 ret
= if_set_prefix(ifp
, ifc
);
479 EC_ZEBRA_IFACE_ADDR_ADD_FAILED
,
480 "Can't set interface's address: %s",
481 safe_strerror(errno
));
485 SET_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
);
486 /* The address will be advertised to zebra
487 * clients when the notification
488 * from the kernel has been received.
489 * It will also be added to the interface's
490 * subnet list then. */
492 if (p
->family
== AF_INET6
) {
493 if (!if_is_up(ifp
)) {
494 /* See long comment above */
495 if_set_flags(ifp
, IFF_UP
| IFF_RUNNING
);
499 ret
= if_prefix_add_ipv6(ifp
, ifc
);
502 EC_ZEBRA_IFACE_ADDR_ADD_FAILED
,
503 "Can't set interface's address: %s",
504 safe_strerror(errno
));
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. */
517 /* Handle interface addition */
518 void if_add_update(struct interface
*ifp
)
520 struct zebra_if
*if_data
;
521 struct zebra_ns
*zns
;
522 struct zebra_vrf
*zvrf
= vrf_info_lookup(ifp
->vrf_id
);
524 /* case interface populate before vrf enabled */
528 zns
= zebra_ns_lookup(NS_DEFAULT
);
529 if_link_per_ns(zns
, ifp
);
533 if (if_data
->multicast
== IF_ZEBRA_MULTICAST_ON
)
534 if_set_flags(ifp
, IFF_MULTICAST
);
535 else if (if_data
->multicast
== IF_ZEBRA_MULTICAST_OFF
)
536 if_unset_flags(ifp
, IFF_MULTICAST
);
538 zebra_ptm_if_set_ptm_state(ifp
, if_data
);
540 zebra_interface_add_update(ifp
);
542 if (!CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
)) {
543 SET_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
);
545 if (if_data
->shutdown
== IF_ZEBRA_SHUTDOWN_ON
) {
546 if (IS_ZEBRA_DEBUG_KERNEL
)
548 "interface %s vrf %u index %d is shutdown. "
550 ifp
->name
, ifp
->vrf_id
, ifp
->ifindex
);
556 if (IS_ZEBRA_DEBUG_KERNEL
)
558 "interface %s vrf %u index %d becomes active.",
559 ifp
->name
, ifp
->vrf_id
, ifp
->ifindex
);
562 if (IS_ZEBRA_DEBUG_KERNEL
)
563 zlog_debug("interface %s vrf %u index %d is added.",
564 ifp
->name
, ifp
->vrf_id
, ifp
->ifindex
);
568 /* Install connected routes corresponding to an interface. */
569 static void if_install_connected(struct interface
*ifp
)
571 struct listnode
*node
;
572 struct listnode
*next
;
573 struct connected
*ifc
;
575 if (ifp
->connected
) {
576 for (ALL_LIST_ELEMENTS(ifp
->connected
, node
, next
, ifc
)) {
577 if (CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_REAL
))
578 zebra_interface_address_add_update(ifp
, ifc
);
580 connected_up(ifp
, ifc
);
585 /* Uninstall connected routes corresponding to an interface. */
586 static void if_uninstall_connected(struct interface
*ifp
)
588 struct listnode
*node
;
589 struct listnode
*next
;
590 struct connected
*ifc
;
592 if (ifp
->connected
) {
593 for (ALL_LIST_ELEMENTS(ifp
->connected
, node
, next
, ifc
)) {
594 zebra_interface_address_delete_update(ifp
, ifc
);
595 connected_down(ifp
, ifc
);
600 /* Uninstall and delete connected routes corresponding to an interface. */
601 /* TODO - Check why IPv4 handling here is different from install or if_down */
602 static void if_delete_connected(struct interface
*ifp
)
604 struct connected
*ifc
;
606 struct route_node
*rn
;
607 struct zebra_if
*zebra_if
;
608 struct listnode
*node
;
609 struct listnode
*last
= NULL
;
611 zebra_if
= ifp
->info
;
616 while ((node
= (last
? last
->next
: listhead(ifp
->connected
)))) {
617 ifc
= listgetdata(node
);
619 cp
= *CONNECTED_PREFIX(ifc
);
622 if (cp
.family
== AF_INET
623 && (rn
= route_node_lookup(zebra_if
->ipv4_subnets
, &cp
))) {
624 struct listnode
*anode
;
625 struct listnode
*next
;
626 struct listnode
*first
;
627 struct list
*addr_list
;
629 route_unlock_node(rn
);
630 addr_list
= (struct list
*)rn
->info
;
632 /* Remove addresses, secondaries first. */
633 first
= listhead(addr_list
);
635 for (anode
= first
->next
; anode
|| first
;
643 ifc
= listgetdata(anode
);
644 connected_down(ifp
, ifc
);
646 /* XXX: We have to send notifications
647 * here explicitly, because we destroy
648 * the ifc before receiving the
649 * notification about the address being
652 zebra_interface_address_delete_update(
655 UNSET_FLAG(ifc
->conf
, ZEBRA_IFC_REAL
);
656 UNSET_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
);
658 /* Remove from subnet chain. */
659 list_delete_node(addr_list
, anode
);
660 route_unlock_node(rn
);
662 /* Remove from interface address list
663 * (unconditionally). */
664 if (!CHECK_FLAG(ifc
->conf
,
665 ZEBRA_IFC_CONFIGURED
)) {
666 listnode_delete(ifp
->connected
,
673 /* Free chain list and respective route node. */
674 list_delete_and_null(&addr_list
);
676 route_unlock_node(rn
);
677 } else if (cp
.family
== AF_INET6
) {
678 connected_down(ifp
, ifc
);
680 zebra_interface_address_delete_update(ifp
, ifc
);
682 UNSET_FLAG(ifc
->conf
, ZEBRA_IFC_REAL
);
683 UNSET_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
);
685 if (CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
688 listnode_delete(ifp
->connected
, ifc
);
697 /* Handle an interface delete event */
698 void if_delete_update(struct interface
*ifp
)
700 struct zebra_if
*zif
;
705 "interface %s vrf %u index %d is still up while being deleted.",
706 ifp
->name
, ifp
->vrf_id
, ifp
->ifindex
);
710 if (!CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
))
713 /* Mark interface as inactive */
714 UNSET_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
);
716 if (IS_ZEBRA_DEBUG_KERNEL
)
717 zlog_debug("interface %s vrf %u index %d is now inactive.",
718 ifp
->name
, ifp
->vrf_id
, ifp
->ifindex
);
720 /* Delete connected routes from the kernel. */
721 if_delete_connected(ifp
);
723 /* Send out notification on interface delete. */
724 zebra_interface_delete_update(ifp
);
726 if_unlink_per_ns(ifp
);
728 /* Update ifindex after distributing the delete message. This is in
729 case any client needs to have the old value of ifindex available
730 while processing the deletion. Each client daemon is responsible
731 for setting ifindex to IFINDEX_INTERNAL after processing the
732 interface deletion message. */
733 if_set_index(ifp
, IFINDEX_INTERNAL
);
736 /* if the ifp is in a vrf, move it to default so vrf can be deleted if
737 * desired. This operation is not done for netns implementation to avoid
738 * collision with interface with the same name in the default vrf (can
739 * occur with this implementation whereas it is not possible with
742 if (ifp
->vrf_id
&& !vrf_is_backend_netns())
743 if_handle_vrf_change(ifp
, VRF_DEFAULT
);
745 /* Reset some zebra interface params to default values. */
748 zif
->zif_type
= ZEBRA_IF_OTHER
;
749 zif
->zif_slave_type
= ZEBRA_IF_SLAVE_NONE
;
750 memset(&zif
->l2info
, 0, sizeof(union zebra_l2if_info
));
751 memset(&zif
->brslave_info
, 0,
752 sizeof(struct zebra_l2info_brslave
));
756 /* VRF change for an interface */
757 void if_handle_vrf_change(struct interface
*ifp
, vrf_id_t vrf_id
)
761 old_vrf_id
= ifp
->vrf_id
;
763 /* Uninstall connected routes. */
764 if_uninstall_connected(ifp
);
766 /* Delete any IPv4 neighbors created to implement RFC 5549 */
767 if_nbr_ipv6ll_to_ipv4ll_neigh_del_all(ifp
);
769 /* Delete all neighbor addresses learnt through IPv6 RA */
770 if_down_del_nbr_connected(ifp
);
772 /* Send out notification on interface VRF change. */
773 /* This is to issue an UPDATE or a DELETE, as appropriate. */
774 zebra_interface_vrf_update_del(ifp
, vrf_id
);
777 if_update_to_new_vrf(ifp
, vrf_id
);
779 /* Send out notification on interface VRF change. */
780 /* This is to issue an ADD, if needed. */
781 zebra_interface_vrf_update_add(ifp
, old_vrf_id
);
783 /* Install connected routes (in new VRF). */
784 if (if_is_operative(ifp
))
785 if_install_connected(ifp
);
787 /* Due to connected route change, schedule RIB processing for both old
790 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
791 zlog_debug("%u: IF %s VRF change, scheduling RIB processing",
792 ifp
->vrf_id
, ifp
->name
);
793 rib_update(old_vrf_id
, RIB_UPDATE_IF_CHANGE
);
794 rib_update(ifp
->vrf_id
, RIB_UPDATE_IF_CHANGE
);
797 static void ipv6_ll_address_to_mac(struct in6_addr
*address
, uint8_t *mac
)
799 mac
[0] = address
->s6_addr
[8] ^ 0x02;
800 mac
[1] = address
->s6_addr
[9];
801 mac
[2] = address
->s6_addr
[10];
802 mac
[3] = address
->s6_addr
[13];
803 mac
[4] = address
->s6_addr
[14];
804 mac
[5] = address
->s6_addr
[15];
807 static bool mac_is_same(char *mac1
, char *mac2
)
809 if (mac1
[0] == mac2
[0] &&
810 mac1
[1] == mac2
[1] &&
811 mac1
[2] == mac2
[2] &&
812 mac1
[3] == mac2
[3] &&
813 mac1
[4] == mac2
[4] &&
820 void if_nbr_mac_to_ipv4ll_neigh_update(struct interface
*ifp
,
822 struct in6_addr
*address
,
825 struct zebra_vrf
*zvrf
= vrf_info_lookup(ifp
->vrf_id
);
826 struct zebra_if
*zif
= ifp
->info
;
827 char buf
[16] = "169.254.0.1";
828 struct in_addr ipv4_ll
;
831 inet_pton(AF_INET
, buf
, &ipv4_ll
);
833 ns_id
= zvrf
->zns
->ns_id
;
836 * Remove existed arp record for the interface as netlink
837 * protocol does not have update message types
839 * supported message types are RTM_NEWNEIGH and RTM_DELNEIGH
841 if (!mac_is_same(zif
->neigh_mac
, mac
)) {
842 kernel_neigh_update(0, ifp
->ifindex
, ipv4_ll
.s_addr
,
846 kernel_neigh_update(add
, ifp
->ifindex
, ipv4_ll
.s_addr
,
850 memcpy(&zif
->neigh_mac
[0], &mac
[0], 6);
853 * We need to note whether or not we originated a v6
854 * neighbor entry for this interface. So that when
855 * someone unwisely accidently deletes this entry
856 * we can shove it back in.
858 zif
->v6_2_v4_ll_neigh_entry
= !!add
;
859 memcpy(&zif
->v6_2_v4_ll_addr6
, address
, sizeof(*address
));
861 zvrf
->neigh_updates
++;
864 void if_nbr_ipv6ll_to_ipv4ll_neigh_update(struct interface
*ifp
,
865 struct in6_addr
*address
, int add
)
870 ipv6_ll_address_to_mac(address
, (uint8_t *)mac
);
871 if_nbr_mac_to_ipv4ll_neigh_update(ifp
, mac
, address
, add
);
874 static void if_nbr_ipv6ll_to_ipv4ll_neigh_add_all(struct interface
*ifp
)
876 if (listhead(ifp
->nbr_connected
)) {
877 struct nbr_connected
*nbr_connected
;
878 struct listnode
*node
;
880 for (ALL_LIST_ELEMENTS_RO(ifp
->nbr_connected
, node
,
882 if_nbr_ipv6ll_to_ipv4ll_neigh_update(
883 ifp
, &nbr_connected
->address
->u
.prefix6
, 1);
887 void if_nbr_ipv6ll_to_ipv4ll_neigh_del_all(struct interface
*ifp
)
889 if (listhead(ifp
->nbr_connected
)) {
890 struct nbr_connected
*nbr_connected
;
891 struct listnode
*node
;
893 for (ALL_LIST_ELEMENTS_RO(ifp
->nbr_connected
, node
,
895 if_nbr_ipv6ll_to_ipv4ll_neigh_update(
896 ifp
, &nbr_connected
->address
->u
.prefix6
, 0);
900 static void if_down_del_nbr_connected(struct interface
*ifp
)
902 struct nbr_connected
*nbr_connected
;
903 struct listnode
*node
, *nnode
;
905 for (ALL_LIST_ELEMENTS(ifp
->nbr_connected
, node
, nnode
,
907 listnode_delete(ifp
->nbr_connected
, nbr_connected
);
908 nbr_connected_free(nbr_connected
);
912 /* Interface is up. */
913 void if_up(struct interface
*ifp
)
915 struct zebra_if
*zif
;
916 struct interface
*link_if
;
917 struct zebra_vrf
*zvrf
= vrf_info_lookup(ifp
->vrf_id
);
921 quagga_timestamp(2, zif
->up_last
, sizeof(zif
->up_last
));
923 /* Notify the protocol daemons. */
924 if (ifp
->ptm_enable
&& (ifp
->ptm_status
== ZEBRA_PTM_STATUS_DOWN
)) {
925 flog_warn(EC_ZEBRA_PTM_NOT_READY
,
926 "%s: interface %s hasn't passed ptm check\n",
927 __func__
, ifp
->name
);
930 zebra_interface_up_update(ifp
);
932 if_nbr_ipv6ll_to_ipv4ll_neigh_add_all(ifp
);
934 #if defined(HAVE_RTADV)
935 /* Enable fast tx of RA if enabled && RA interval is not in msecs */
936 if (zif
->rtadv
.AdvSendAdvertisements
937 && (zif
->rtadv
.MaxRtrAdvInterval
>= 1000)) {
938 zif
->rtadv
.inFastRexmit
= 1;
939 zif
->rtadv
.NumFastReXmitsRemain
= RTADV_NUM_FAST_REXMITS
;
943 /* Install connected routes to the kernel. */
944 if_install_connected(ifp
);
946 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
947 zlog_debug("%u: IF %s up, scheduling RIB processing",
948 ifp
->vrf_id
, ifp
->name
);
949 rib_update(ifp
->vrf_id
, RIB_UPDATE_IF_CHANGE
);
951 /* Handle interface up for specific types for EVPN. Non-VxLAN interfaces
952 * are checked to see if (remote) neighbor entries need to be installed
953 * on them for ARP suppression.
955 if (IS_ZEBRA_IF_VXLAN(ifp
))
956 zebra_vxlan_if_up(ifp
);
957 else if (IS_ZEBRA_IF_BRIDGE(ifp
)) {
959 zebra_vxlan_svi_up(ifp
, link_if
);
960 } else if (IS_ZEBRA_IF_VLAN(ifp
)) {
961 link_if
= if_lookup_by_index_per_ns(zvrf
->zns
,
964 zebra_vxlan_svi_up(ifp
, link_if
);
968 /* Interface goes down. We have to manage different behavior of based
970 void if_down(struct interface
*ifp
)
972 struct zebra_if
*zif
;
973 struct interface
*link_if
;
974 struct zebra_vrf
*zvrf
= vrf_info_lookup(ifp
->vrf_id
);
978 quagga_timestamp(2, zif
->down_last
, sizeof(zif
->down_last
));
980 /* Handle interface down for specific types for EVPN. Non-VxLAN
982 * are checked to see if (remote) neighbor entries need to be purged
983 * for ARP suppression.
985 if (IS_ZEBRA_IF_VXLAN(ifp
))
986 zebra_vxlan_if_down(ifp
);
987 else if (IS_ZEBRA_IF_BRIDGE(ifp
)) {
989 zebra_vxlan_svi_down(ifp
, link_if
);
990 } else if (IS_ZEBRA_IF_VLAN(ifp
)) {
991 link_if
= if_lookup_by_index_per_ns(zvrf
->zns
,
994 zebra_vxlan_svi_down(ifp
, link_if
);
998 /* Notify to the protocol daemons. */
999 zebra_interface_down_update(ifp
);
1001 /* Uninstall connected routes from the kernel. */
1002 if_uninstall_connected(ifp
);
1004 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
1005 zlog_debug("%u: IF %s down, scheduling RIB processing",
1006 ifp
->vrf_id
, ifp
->name
);
1007 rib_update(ifp
->vrf_id
, RIB_UPDATE_IF_CHANGE
);
1009 if_nbr_ipv6ll_to_ipv4ll_neigh_del_all(ifp
);
1011 /* Delete all neighbor addresses learnt through IPv6 RA */
1012 if_down_del_nbr_connected(ifp
);
1015 void if_refresh(struct interface
*ifp
)
1020 void zebra_if_update_link(struct interface
*ifp
, ifindex_t link_ifindex
,
1023 struct zebra_if
*zif
;
1025 if (IS_ZEBRA_IF_VETH(ifp
))
1027 zif
= (struct zebra_if
*)ifp
->info
;
1028 zif
->link_ifindex
= link_ifindex
;
1029 zif
->link
= if_lookup_by_index_per_ns(zebra_ns_lookup(ns_id
),
1034 /* Output prefix string to vty. */
1035 static int prefix_vty_out(struct vty
*vty
, struct prefix
*p
)
1037 char str
[INET6_ADDRSTRLEN
];
1039 inet_ntop(p
->family
, &p
->u
.prefix
, str
, sizeof(str
));
1040 vty_out(vty
, "%s", str
);
1044 /* Dump if address information to vty. */
1045 static void connected_dump_vty(struct vty
*vty
, struct connected
*connected
)
1049 /* Print interface address. */
1050 p
= connected
->address
;
1051 vty_out(vty
, " %s ", prefix_family_str(p
));
1052 prefix_vty_out(vty
, p
);
1053 vty_out(vty
, "/%d", p
->prefixlen
);
1055 /* If there is destination address, print it. */
1056 if (connected
->destination
) {
1058 (CONNECTED_PEER(connected
) ? " peer " : " broadcast "));
1059 prefix_vty_out(vty
, connected
->destination
);
1060 if (CONNECTED_PEER(connected
))
1061 vty_out(vty
, "/%d", connected
->destination
->prefixlen
);
1064 if (CHECK_FLAG(connected
->flags
, ZEBRA_IFA_SECONDARY
))
1065 vty_out(vty
, " secondary");
1067 if (CHECK_FLAG(connected
->flags
, ZEBRA_IFA_UNNUMBERED
))
1068 vty_out(vty
, " unnumbered");
1070 if (connected
->label
)
1071 vty_out(vty
, " %s", connected
->label
);
1076 /* Dump interface neighbor address information to vty. */
1077 static void nbr_connected_dump_vty(struct vty
*vty
,
1078 struct nbr_connected
*connected
)
1082 /* Print interface address. */
1083 p
= connected
->address
;
1084 vty_out(vty
, " %s ", prefix_family_str(p
));
1085 prefix_vty_out(vty
, p
);
1086 vty_out(vty
, "/%d", p
->prefixlen
);
1091 static const char *zebra_ziftype_2str(zebra_iftype_t zif_type
)
1094 case ZEBRA_IF_OTHER
:
1098 case ZEBRA_IF_BRIDGE
:
1106 case ZEBRA_IF_VXLAN
:
1124 /* Interface's information print out to vty interface. */
1125 static void if_dump_vty(struct vty
*vty
, struct interface
*ifp
)
1127 struct connected
*connected
;
1128 struct nbr_connected
*nbr_connected
;
1129 struct listnode
*node
;
1130 struct route_node
*rn
;
1131 struct zebra_if
*zebra_if
;
1134 zebra_if
= ifp
->info
;
1136 vty_out(vty
, "Interface %s is ", ifp
->name
);
1137 if (if_is_up(ifp
)) {
1138 vty_out(vty
, "up, line protocol ");
1140 if (CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_LINKDETECTION
)) {
1141 if (if_is_running(ifp
))
1142 vty_out(vty
, "is up\n");
1144 vty_out(vty
, "is down\n");
1146 vty_out(vty
, "detection is disabled\n");
1149 vty_out(vty
, "down\n");
1152 vty_out(vty
, " Link ups: %5u last: %s\n", zebra_if
->up_count
,
1153 zebra_if
->up_last
[0] ? zebra_if
->up_last
: "(never)");
1154 vty_out(vty
, " Link downs: %5u last: %s\n", zebra_if
->down_count
,
1155 zebra_if
->down_last
[0] ? zebra_if
->down_last
: "(never)");
1157 zebra_ptm_show_status(vty
, ifp
);
1159 vrf
= vrf_lookup_by_id(ifp
->vrf_id
);
1160 vty_out(vty
, " vrf: %s\n", vrf
->name
);
1163 vty_out(vty
, " Description: %s\n", ifp
->desc
);
1164 if (ifp
->ifindex
== IFINDEX_INTERNAL
) {
1165 vty_out(vty
, " pseudo interface\n");
1167 } else if (!CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
)) {
1168 vty_out(vty
, " index %d inactive interface\n", ifp
->ifindex
);
1172 vty_out(vty
, " index %d metric %d mtu %d speed %u ", ifp
->ifindex
,
1173 ifp
->metric
, ifp
->mtu
, ifp
->speed
);
1174 if (ifp
->mtu6
!= ifp
->mtu
)
1175 vty_out(vty
, "mtu6 %d ", ifp
->mtu6
);
1176 vty_out(vty
, "\n flags: %s\n", if_flag_dump(ifp
->flags
));
1178 /* Hardware address. */
1179 vty_out(vty
, " Type: %s\n", if_link_type_str(ifp
->ll_type
));
1180 if (ifp
->hw_addr_len
!= 0) {
1183 vty_out(vty
, " HWaddr: ");
1184 for (i
= 0; i
< ifp
->hw_addr_len
; i
++)
1185 vty_out(vty
, "%s%02x", i
== 0 ? "" : ":",
1190 /* Bandwidth in Mbps */
1191 if (ifp
->bandwidth
!= 0) {
1192 vty_out(vty
, " bandwidth %u Mbps", ifp
->bandwidth
);
1196 for (rn
= route_top(zebra_if
->ipv4_subnets
); rn
; rn
= route_next(rn
)) {
1200 for (ALL_LIST_ELEMENTS_RO((struct list
*)rn
->info
, node
,
1202 connected_dump_vty(vty
, connected
);
1205 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, node
, connected
)) {
1206 if (CHECK_FLAG(connected
->conf
, ZEBRA_IFC_REAL
)
1207 && (connected
->address
->family
== AF_INET6
))
1208 connected_dump_vty(vty
, connected
);
1211 vty_out(vty
, " Interface Type %s\n",
1212 zebra_ziftype_2str(zebra_if
->zif_type
));
1213 if (IS_ZEBRA_IF_BRIDGE(ifp
)) {
1214 struct zebra_l2info_bridge
*bridge_info
;
1216 bridge_info
= &zebra_if
->l2info
.br
;
1217 vty_out(vty
, " Bridge VLAN-aware: %s\n",
1218 bridge_info
->vlan_aware
? "yes" : "no");
1219 } else if (IS_ZEBRA_IF_VLAN(ifp
)) {
1220 struct zebra_l2info_vlan
*vlan_info
;
1222 vlan_info
= &zebra_if
->l2info
.vl
;
1223 vty_out(vty
, " VLAN Id %u\n", vlan_info
->vid
);
1224 } else if (IS_ZEBRA_IF_VXLAN(ifp
)) {
1225 struct zebra_l2info_vxlan
*vxlan_info
;
1227 vxlan_info
= &zebra_if
->l2info
.vxl
;
1228 vty_out(vty
, " VxLAN Id %u", vxlan_info
->vni
);
1229 if (vxlan_info
->vtep_ip
.s_addr
!= INADDR_ANY
)
1230 vty_out(vty
, " VTEP IP: %s",
1231 inet_ntoa(vxlan_info
->vtep_ip
));
1232 if (vxlan_info
->access_vlan
)
1233 vty_out(vty
, " Access VLAN Id %u",
1234 vxlan_info
->access_vlan
);
1238 if (IS_ZEBRA_IF_BRIDGE_SLAVE(ifp
)) {
1239 struct zebra_l2info_brslave
*br_slave
;
1241 br_slave
= &zebra_if
->brslave_info
;
1242 if (br_slave
->bridge_ifindex
!= IFINDEX_INTERNAL
)
1243 vty_out(vty
, " Master (bridge) ifindex %u\n",
1244 br_slave
->bridge_ifindex
);
1247 if (zebra_if
->link_ifindex
!= IFINDEX_INTERNAL
) {
1248 vty_out(vty
, " Link ifindex %u", zebra_if
->link_ifindex
);
1250 vty_out(vty
, "(%s)\n", zebra_if
->link
->name
);
1252 vty_out(vty
, "(Unknown)\n");
1255 if (HAS_LINK_PARAMS(ifp
)) {
1257 struct if_link_params
*iflp
= ifp
->link_params
;
1258 vty_out(vty
, " Traffic Engineering Link Parameters:\n");
1259 if (IS_PARAM_SET(iflp
, LP_TE_METRIC
))
1260 vty_out(vty
, " TE metric %u\n", iflp
->te_metric
);
1261 if (IS_PARAM_SET(iflp
, LP_MAX_BW
))
1262 vty_out(vty
, " Maximum Bandwidth %g (Byte/s)\n",
1264 if (IS_PARAM_SET(iflp
, LP_MAX_RSV_BW
))
1266 " Maximum Reservable Bandwidth %g (Byte/s)\n",
1268 if (IS_PARAM_SET(iflp
, LP_UNRSV_BW
)) {
1270 " Unreserved Bandwidth per Class Type in Byte/s:\n");
1271 for (i
= 0; i
< MAX_CLASS_TYPE
; i
+= 2)
1273 " [%d]: %g (Bytes/sec),\t[%d]: %g (Bytes/sec)\n",
1274 i
, iflp
->unrsv_bw
[i
], i
+ 1,
1275 iflp
->unrsv_bw
[i
+ 1]);
1278 if (IS_PARAM_SET(iflp
, LP_ADM_GRP
))
1279 vty_out(vty
, " Administrative Group:%u\n",
1281 if (IS_PARAM_SET(iflp
, LP_DELAY
)) {
1282 vty_out(vty
, " Link Delay Average: %u (micro-sec.)",
1284 if (IS_PARAM_SET(iflp
, LP_MM_DELAY
)) {
1285 vty_out(vty
, " Min: %u (micro-sec.)",
1287 vty_out(vty
, " Max: %u (micro-sec.)",
1292 if (IS_PARAM_SET(iflp
, LP_DELAY_VAR
))
1294 " Link Delay Variation %u (micro-sec.)\n",
1296 if (IS_PARAM_SET(iflp
, LP_PKT_LOSS
))
1297 vty_out(vty
, " Link Packet Loss %g (in %%)\n",
1299 if (IS_PARAM_SET(iflp
, LP_AVA_BW
))
1300 vty_out(vty
, " Available Bandwidth %g (Byte/s)\n",
1302 if (IS_PARAM_SET(iflp
, LP_RES_BW
))
1303 vty_out(vty
, " Residual Bandwidth %g (Byte/s)\n",
1305 if (IS_PARAM_SET(iflp
, LP_USE_BW
))
1306 vty_out(vty
, " Utilized Bandwidth %g (Byte/s)\n",
1308 if (IS_PARAM_SET(iflp
, LP_RMT_AS
))
1309 vty_out(vty
, " Neighbor ASBR IP: %s AS: %u \n",
1310 inet_ntoa(iflp
->rmt_ip
), iflp
->rmt_as
);
1313 hook_call(zebra_if_extra_info
, vty
, ifp
);
1315 if (listhead(ifp
->nbr_connected
))
1316 vty_out(vty
, " Neighbor address(s):\n");
1317 for (ALL_LIST_ELEMENTS_RO(ifp
->nbr_connected
, node
, nbr_connected
))
1318 nbr_connected_dump_vty(vty
, nbr_connected
);
1320 #ifdef HAVE_PROC_NET_DEV
1321 /* Statistics print out using proc file system. */
1323 " %lu input packets (%lu multicast), %lu bytes, "
1325 ifp
->stats
.rx_packets
, ifp
->stats
.rx_multicast
,
1326 ifp
->stats
.rx_bytes
, ifp
->stats
.rx_dropped
);
1329 " %lu input errors, %lu length, %lu overrun,"
1330 " %lu CRC, %lu frame\n",
1331 ifp
->stats
.rx_errors
, ifp
->stats
.rx_length_errors
,
1332 ifp
->stats
.rx_over_errors
, ifp
->stats
.rx_crc_errors
,
1333 ifp
->stats
.rx_frame_errors
);
1335 vty_out(vty
, " %lu fifo, %lu missed\n", ifp
->stats
.rx_fifo_errors
,
1336 ifp
->stats
.rx_missed_errors
);
1338 vty_out(vty
, " %lu output packets, %lu bytes, %lu dropped\n",
1339 ifp
->stats
.tx_packets
, ifp
->stats
.tx_bytes
,
1340 ifp
->stats
.tx_dropped
);
1343 " %lu output errors, %lu aborted, %lu carrier,"
1344 " %lu fifo, %lu heartbeat\n",
1345 ifp
->stats
.tx_errors
, ifp
->stats
.tx_aborted_errors
,
1346 ifp
->stats
.tx_carrier_errors
, ifp
->stats
.tx_fifo_errors
,
1347 ifp
->stats
.tx_heartbeat_errors
);
1349 vty_out(vty
, " %lu window, %lu collisions\n",
1350 ifp
->stats
.tx_window_errors
, ifp
->stats
.collisions
);
1351 #endif /* HAVE_PROC_NET_DEV */
1353 #ifdef HAVE_NET_RT_IFLIST
1354 #if defined(__bsdi__) || defined(__NetBSD__)
1355 /* Statistics print out using sysctl (). */
1357 " input packets %llu, bytes %llu, dropped %llu,"
1358 " multicast packets %llu\n",
1359 (unsigned long long)ifp
->stats
.ifi_ipackets
,
1360 (unsigned long long)ifp
->stats
.ifi_ibytes
,
1361 (unsigned long long)ifp
->stats
.ifi_iqdrops
,
1362 (unsigned long long)ifp
->stats
.ifi_imcasts
);
1364 vty_out(vty
, " input errors %llu\n",
1365 (unsigned long long)ifp
->stats
.ifi_ierrors
);
1368 " output packets %llu, bytes %llu,"
1369 " multicast packets %llu\n",
1370 (unsigned long long)ifp
->stats
.ifi_opackets
,
1371 (unsigned long long)ifp
->stats
.ifi_obytes
,
1372 (unsigned long long)ifp
->stats
.ifi_omcasts
);
1374 vty_out(vty
, " output errors %llu\n",
1375 (unsigned long long)ifp
->stats
.ifi_oerrors
);
1377 vty_out(vty
, " collisions %llu\n",
1378 (unsigned long long)ifp
->stats
.ifi_collisions
);
1380 /* Statistics print out using sysctl (). */
1382 " input packets %lu, bytes %lu, dropped %lu,"
1383 " multicast packets %lu\n",
1384 ifp
->stats
.ifi_ipackets
, ifp
->stats
.ifi_ibytes
,
1385 ifp
->stats
.ifi_iqdrops
, ifp
->stats
.ifi_imcasts
);
1387 vty_out(vty
, " input errors %lu\n", ifp
->stats
.ifi_ierrors
);
1390 " output packets %lu, bytes %lu, multicast packets %lu\n",
1391 ifp
->stats
.ifi_opackets
, ifp
->stats
.ifi_obytes
,
1392 ifp
->stats
.ifi_omcasts
);
1394 vty_out(vty
, " output errors %lu\n", ifp
->stats
.ifi_oerrors
);
1396 vty_out(vty
, " collisions %lu\n", ifp
->stats
.ifi_collisions
);
1397 #endif /* __bsdi__ || __NetBSD__ */
1398 #endif /* HAVE_NET_RT_IFLIST */
1401 static void interface_update_stats(void)
1403 #ifdef HAVE_PROC_NET_DEV
1404 /* If system has interface statistics via proc file system, update
1406 ifstat_update_proc();
1407 #endif /* HAVE_PROC_NET_DEV */
1408 #ifdef HAVE_NET_RT_IFLIST
1409 ifstat_update_sysctl();
1410 #endif /* HAVE_NET_RT_IFLIST */
1413 struct cmd_node interface_node
= {INTERFACE_NODE
, "%s(config-if)# ", 1};
1415 /* Show all interfaces to vty. */
1416 DEFUN (show_interface
,
1418 "show interface [vrf NAME]",
1420 "Interface status and configuration\n"
1424 struct interface
*ifp
;
1425 vrf_id_t vrf_id
= VRF_DEFAULT
;
1427 interface_update_stats();
1430 VRF_GET_ID(vrf_id
, argv
[3]->arg
, false);
1432 /* All interface print. */
1433 vrf
= vrf_lookup_by_id(vrf_id
);
1434 FOR_ALL_INTERFACES (vrf
, ifp
)
1435 if_dump_vty(vty
, ifp
);
1441 /* Show all interfaces to vty. */
1442 DEFUN (show_interface_vrf_all
,
1443 show_interface_vrf_all_cmd
,
1444 "show interface vrf all",
1446 "Interface status and configuration\n"
1447 VRF_ALL_CMD_HELP_STR
)
1450 struct interface
*ifp
;
1452 interface_update_stats();
1454 /* All interface print. */
1455 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
1456 FOR_ALL_INTERFACES (vrf
, ifp
)
1457 if_dump_vty(vty
, ifp
);
1462 /* Show specified interface to vty. */
1464 DEFUN (show_interface_name_vrf
,
1465 show_interface_name_vrf_cmd
,
1466 "show interface IFNAME vrf NAME",
1468 "Interface status and configuration\n"
1474 struct interface
*ifp
;
1477 interface_update_stats();
1479 VRF_GET_ID(vrf_id
, argv
[idx_name
]->arg
, false);
1481 /* Specified interface print. */
1482 ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
, vrf_id
);
1484 vty_out(vty
, "%% Can't find interface %s\n",
1485 argv
[idx_ifname
]->arg
);
1488 if_dump_vty(vty
, ifp
);
1493 /* Show specified interface to vty. */
1494 DEFUN (show_interface_name_vrf_all
,
1495 show_interface_name_vrf_all_cmd
,
1496 "show interface IFNAME [vrf all]",
1498 "Interface status and configuration\n"
1500 VRF_ALL_CMD_HELP_STR
)
1504 struct interface
*ifp
;
1507 interface_update_stats();
1509 /* All interface print. */
1510 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
1511 /* Specified interface print. */
1512 ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
, vrf
->vrf_id
);
1514 if_dump_vty(vty
, ifp
);
1520 vty_out(vty
, "%% Can't find interface %s\n",
1521 argv
[idx_ifname
]->arg
);
1529 static void if_show_description(struct vty
*vty
, vrf_id_t vrf_id
)
1531 struct vrf
*vrf
= vrf_lookup_by_id(vrf_id
);
1532 struct interface
*ifp
;
1534 vty_out(vty
, "Interface Status Protocol Description\n");
1535 FOR_ALL_INTERFACES (vrf
, ifp
) {
1538 len
= vty_out(vty
, "%s", ifp
->name
);
1539 vty_out(vty
, "%*s", (16 - len
), " ");
1541 if (if_is_up(ifp
)) {
1542 vty_out(vty
, "up ");
1543 if (CHECK_FLAG(ifp
->status
,
1544 ZEBRA_INTERFACE_LINKDETECTION
)) {
1545 if (if_is_running(ifp
))
1546 vty_out(vty
, "up ");
1548 vty_out(vty
, "down ");
1550 vty_out(vty
, "unknown ");
1553 vty_out(vty
, "down down ");
1557 vty_out(vty
, "%s", ifp
->desc
);
1562 DEFUN (show_interface_desc
,
1563 show_interface_desc_cmd
,
1564 "show interface description [vrf NAME]",
1566 "Interface status and configuration\n"
1567 "Interface description\n"
1570 vrf_id_t vrf_id
= VRF_DEFAULT
;
1573 VRF_GET_ID(vrf_id
, argv
[4]->arg
, false);
1575 if_show_description(vty
, vrf_id
);
1581 DEFUN (show_interface_desc_vrf_all
,
1582 show_interface_desc_vrf_all_cmd
,
1583 "show interface description vrf all",
1585 "Interface status and configuration\n"
1586 "Interface description\n"
1587 VRF_ALL_CMD_HELP_STR
)
1591 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
1592 if (!RB_EMPTY(if_name_head
, &vrf
->ifaces_by_name
)) {
1593 vty_out(vty
, "\n\tVRF %u\n\n", vrf
->vrf_id
);
1594 if_show_description(vty
, vrf
->vrf_id
);
1603 "Set multicast flag to interface\n")
1605 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1607 struct zebra_if
*if_data
;
1609 if (CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
)) {
1610 ret
= if_set_flags(ifp
, IFF_MULTICAST
);
1612 vty_out(vty
, "Can't set multicast flag\n");
1613 return CMD_WARNING_CONFIG_FAILED
;
1617 if_data
= ifp
->info
;
1618 if_data
->multicast
= IF_ZEBRA_MULTICAST_ON
;
1623 DEFUN (no_multicast
,
1627 "Unset multicast flag to interface\n")
1629 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1631 struct zebra_if
*if_data
;
1633 if (CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
)) {
1634 ret
= if_unset_flags(ifp
, IFF_MULTICAST
);
1636 vty_out(vty
, "Can't unset multicast flag\n");
1637 return CMD_WARNING_CONFIG_FAILED
;
1641 if_data
= ifp
->info
;
1642 if_data
->multicast
= IF_ZEBRA_MULTICAST_OFF
;
1650 "Enable link detection on interface\n")
1652 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1653 int if_was_operative
;
1655 if_was_operative
= if_is_no_ptm_operative(ifp
);
1656 SET_FLAG(ifp
->status
, ZEBRA_INTERFACE_LINKDETECTION
);
1658 /* When linkdetection is enabled, if might come down */
1659 if (!if_is_no_ptm_operative(ifp
) && if_was_operative
)
1662 /* FIXME: Will defer status change forwarding if interface
1663 does not come down! */
1669 DEFUN (no_linkdetect
,
1673 "Disable link detection on interface\n")
1675 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1676 int if_was_operative
;
1678 if_was_operative
= if_is_no_ptm_operative(ifp
);
1679 UNSET_FLAG(ifp
->status
, ZEBRA_INTERFACE_LINKDETECTION
);
1681 /* Interface may come up after disabling link detection */
1682 if (if_is_operative(ifp
) && !if_was_operative
)
1685 /* FIXME: see linkdetect_cmd */
1693 "Shutdown the selected interface\n")
1695 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1697 struct zebra_if
*if_data
;
1699 if (ifp
->ifindex
!= IFINDEX_INTERNAL
) {
1700 ret
= if_unset_flags(ifp
, IFF_UP
);
1702 vty_out(vty
, "Can't shutdown interface\n");
1703 return CMD_WARNING_CONFIG_FAILED
;
1707 if_data
= ifp
->info
;
1708 if_data
->shutdown
= IF_ZEBRA_SHUTDOWN_ON
;
1713 DEFUN (no_shutdown_if
,
1717 "Shutdown the selected interface\n")
1719 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1721 struct zebra_if
*if_data
;
1723 if (ifp
->ifindex
!= IFINDEX_INTERNAL
) {
1724 ret
= if_set_flags(ifp
, IFF_UP
| IFF_RUNNING
);
1726 vty_out(vty
, "Can't up interface\n");
1727 return CMD_WARNING_CONFIG_FAILED
;
1731 /* Some addresses (in particular, IPv6 addresses on Linux) get
1732 * removed when the interface goes down. They need to be
1735 if_addr_wakeup(ifp
);
1738 if_data
= ifp
->info
;
1739 if_data
->shutdown
= IF_ZEBRA_SHUTDOWN_OFF
;
1744 DEFUN (bandwidth_if
,
1746 "bandwidth (1-100000)",
1747 "Set bandwidth informational parameter\n"
1748 "Bandwidth in megabits\n")
1751 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1752 unsigned int bandwidth
;
1754 bandwidth
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
1756 /* bandwidth range is <1-100000> */
1757 if (bandwidth
< 1 || bandwidth
> 100000) {
1758 vty_out(vty
, "Bandwidth is invalid\n");
1759 return CMD_WARNING_CONFIG_FAILED
;
1762 ifp
->bandwidth
= bandwidth
;
1764 /* force protocols to recalculate routes due to cost change */
1765 if (if_is_operative(ifp
))
1766 zebra_interface_up_update(ifp
);
1771 DEFUN (no_bandwidth_if
,
1772 no_bandwidth_if_cmd
,
1773 "no bandwidth [(1-100000)]",
1775 "Set bandwidth informational parameter\n"
1776 "Bandwidth in megabits\n")
1778 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1782 /* force protocols to recalculate routes due to cost change */
1783 if (if_is_operative(ifp
))
1784 zebra_interface_up_update(ifp
);
1790 struct cmd_node link_params_node
= {
1791 LINK_PARAMS_NODE
, "%s(config-link-params)# ", 1,
1794 static void link_param_cmd_set_uint32(struct interface
*ifp
, uint32_t *field
,
1795 uint32_t type
, uint32_t value
)
1797 /* Update field as needed */
1798 if (IS_PARAM_UNSET(ifp
->link_params
, type
) || *field
!= value
) {
1800 SET_PARAM(ifp
->link_params
, type
);
1802 /* force protocols to update LINK STATE due to parameters change
1804 if (if_is_operative(ifp
))
1805 zebra_interface_parameters_update(ifp
);
1808 static void link_param_cmd_set_float(struct interface
*ifp
, float *field
,
1809 uint32_t type
, float value
)
1812 /* Update field as needed */
1813 if (IS_PARAM_UNSET(ifp
->link_params
, type
) || *field
!= value
) {
1815 SET_PARAM(ifp
->link_params
, type
);
1817 /* force protocols to update LINK STATE due to parameters change
1819 if (if_is_operative(ifp
))
1820 zebra_interface_parameters_update(ifp
);
1824 static void link_param_cmd_unset(struct interface
*ifp
, uint32_t type
)
1826 if (ifp
->link_params
== NULL
)
1830 UNSET_PARAM(ifp
->link_params
, type
);
1832 /* force protocols to update LINK STATE due to parameters change */
1833 if (if_is_operative(ifp
))
1834 zebra_interface_parameters_update(ifp
);
1837 DEFUN_NOSH (link_params
,
1842 /* vty->qobj_index stays the same @ interface pointer */
1843 vty
->node
= LINK_PARAMS_NODE
;
1848 DEFUN_NOSH (exit_link_params
,
1849 exit_link_params_cmd
,
1851 "Exit from Link Params configuration mode\n")
1853 if (vty
->node
== LINK_PARAMS_NODE
)
1854 vty
->node
= INTERFACE_NODE
;
1858 /* Specific Traffic Engineering parameters commands */
1859 DEFUN (link_params_enable
,
1860 link_params_enable_cmd
,
1862 "Activate link parameters on this interface\n")
1864 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1866 /* This command could be issue at startup, when activate MPLS TE */
1867 /* on a new interface or after a ON / OFF / ON toggle */
1868 /* In all case, TE parameters are reset to their default factory */
1869 if (IS_ZEBRA_DEBUG_EVENT
)
1871 "Link-params: enable TE link parameters on interface %s",
1874 if (!if_link_params_get(ifp
)) {
1875 if (IS_ZEBRA_DEBUG_EVENT
)
1877 "Link-params: failed to init TE link parameters %s",
1880 return CMD_WARNING_CONFIG_FAILED
;
1883 /* force protocols to update LINK STATE due to parameters change */
1884 if (if_is_operative(ifp
))
1885 zebra_interface_parameters_update(ifp
);
1890 DEFUN (no_link_params_enable
,
1891 no_link_params_enable_cmd
,
1894 "Disable link parameters on this interface\n")
1896 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1898 zlog_debug("MPLS-TE: disable TE link parameters on interface %s",
1901 if_link_params_free(ifp
);
1903 /* force protocols to update LINK STATE due to parameters change */
1904 if (if_is_operative(ifp
))
1905 zebra_interface_parameters_update(ifp
);
1910 /* STANDARD TE metrics */
1911 DEFUN (link_params_metric
,
1912 link_params_metric_cmd
,
1913 "metric (0-4294967295)",
1914 "Link metric for MPLS-TE purpose\n"
1915 "Metric value in decimal\n")
1918 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1919 struct if_link_params
*iflp
= if_link_params_get(ifp
);
1922 metric
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1924 /* Update TE metric if needed */
1925 link_param_cmd_set_uint32(ifp
, &iflp
->te_metric
, LP_TE_METRIC
, metric
);
1930 DEFUN (no_link_params_metric
,
1931 no_link_params_metric_cmd
,
1934 "Disable Link Metric on this interface\n")
1936 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1938 /* Unset TE Metric */
1939 link_param_cmd_unset(ifp
, LP_TE_METRIC
);
1944 DEFUN (link_params_maxbw
,
1945 link_params_maxbw_cmd
,
1947 "Maximum bandwidth that can be used\n"
1948 "Bytes/second (IEEE floating point format)\n")
1950 int idx_bandwidth
= 1;
1951 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1952 struct if_link_params
*iflp
= if_link_params_get(ifp
);
1956 if (sscanf(argv
[idx_bandwidth
]->arg
, "%g", &bw
) != 1) {
1957 vty_out(vty
, "link_params_maxbw: fscanf: %s\n",
1958 safe_strerror(errno
));
1959 return CMD_WARNING_CONFIG_FAILED
;
1962 /* Check that Maximum bandwidth is not lower than other bandwidth
1964 if ((bw
<= iflp
->max_rsv_bw
) || (bw
<= iflp
->unrsv_bw
[0])
1965 || (bw
<= iflp
->unrsv_bw
[1]) || (bw
<= iflp
->unrsv_bw
[2])
1966 || (bw
<= iflp
->unrsv_bw
[3]) || (bw
<= iflp
->unrsv_bw
[4])
1967 || (bw
<= iflp
->unrsv_bw
[5]) || (bw
<= iflp
->unrsv_bw
[6])
1968 || (bw
<= iflp
->unrsv_bw
[7]) || (bw
<= iflp
->ava_bw
)
1969 || (bw
<= iflp
->res_bw
) || (bw
<= iflp
->use_bw
)) {
1971 "Maximum Bandwidth could not be lower than others bandwidth\n");
1972 return CMD_WARNING_CONFIG_FAILED
;
1975 /* Update Maximum Bandwidth if needed */
1976 link_param_cmd_set_float(ifp
, &iflp
->max_bw
, LP_MAX_BW
, bw
);
1981 DEFUN (link_params_max_rsv_bw
,
1982 link_params_max_rsv_bw_cmd
,
1983 "max-rsv-bw BANDWIDTH",
1984 "Maximum bandwidth that may be reserved\n"
1985 "Bytes/second (IEEE floating point format)\n")
1987 int idx_bandwidth
= 1;
1988 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1989 struct if_link_params
*iflp
= if_link_params_get(ifp
);
1992 if (sscanf(argv
[idx_bandwidth
]->arg
, "%g", &bw
) != 1) {
1993 vty_out(vty
, "link_params_max_rsv_bw: fscanf: %s\n",
1994 safe_strerror(errno
));
1995 return CMD_WARNING_CONFIG_FAILED
;
1998 /* Check that bandwidth is not greater than maximum bandwidth parameter
2000 if (bw
> iflp
->max_bw
) {
2002 "Maximum Reservable Bandwidth could not be greater than Maximum Bandwidth (%g)\n",
2004 return CMD_WARNING_CONFIG_FAILED
;
2007 /* Update Maximum Reservable Bandwidth if needed */
2008 link_param_cmd_set_float(ifp
, &iflp
->max_rsv_bw
, LP_MAX_RSV_BW
, bw
);
2013 DEFUN (link_params_unrsv_bw
,
2014 link_params_unrsv_bw_cmd
,
2015 "unrsv-bw (0-7) BANDWIDTH",
2016 "Unreserved bandwidth at each priority level\n"
2018 "Bytes/second (IEEE floating point format)\n")
2021 int idx_bandwidth
= 2;
2022 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2023 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2027 /* We don't have to consider about range check here. */
2028 if (sscanf(argv
[idx_number
]->arg
, "%d", &priority
) != 1) {
2029 vty_out(vty
, "link_params_unrsv_bw: fscanf: %s\n",
2030 safe_strerror(errno
));
2031 return CMD_WARNING_CONFIG_FAILED
;
2034 if (sscanf(argv
[idx_bandwidth
]->arg
, "%g", &bw
) != 1) {
2035 vty_out(vty
, "link_params_unrsv_bw: fscanf: %s\n",
2036 safe_strerror(errno
));
2037 return CMD_WARNING_CONFIG_FAILED
;
2040 /* Check that bandwidth is not greater than maximum bandwidth parameter
2042 if (bw
> iflp
->max_bw
) {
2044 "UnReserved Bandwidth could not be greater than Maximum Bandwidth (%g)\n",
2046 return CMD_WARNING_CONFIG_FAILED
;
2049 /* Update Unreserved Bandwidth if needed */
2050 link_param_cmd_set_float(ifp
, &iflp
->unrsv_bw
[priority
], LP_UNRSV_BW
,
2056 DEFUN (link_params_admin_grp
,
2057 link_params_admin_grp_cmd
,
2058 "admin-grp BITPATTERN",
2059 "Administrative group membership\n"
2060 "32-bit Hexadecimal value (e.g. 0xa1)\n")
2062 int idx_bitpattern
= 1;
2063 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2064 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2065 unsigned long value
;
2067 if (sscanf(argv
[idx_bitpattern
]->arg
, "0x%lx", &value
) != 1) {
2068 vty_out(vty
, "link_params_admin_grp: fscanf: %s\n",
2069 safe_strerror(errno
));
2070 return CMD_WARNING_CONFIG_FAILED
;
2073 /* Update Administrative Group if needed */
2074 link_param_cmd_set_uint32(ifp
, &iflp
->admin_grp
, LP_ADM_GRP
, value
);
2079 DEFUN (no_link_params_admin_grp
,
2080 no_link_params_admin_grp_cmd
,
2083 "Disable Administrative group membership on this interface\n")
2085 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2087 /* Unset Admin Group */
2088 link_param_cmd_unset(ifp
, LP_ADM_GRP
);
2093 /* RFC5392 & RFC5316: INTER-AS */
2094 DEFUN (link_params_inter_as
,
2095 link_params_inter_as_cmd
,
2096 "neighbor A.B.C.D as (1-4294967295)",
2097 "Configure remote ASBR information (Neighbor IP address and AS number)\n"
2098 "Remote IP address in dot decimal A.B.C.D\n"
2099 "Remote AS number\n"
2100 "AS number in the range <1-4294967295>\n")
2105 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2106 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2107 struct in_addr addr
;
2110 if (!inet_aton(argv
[idx_ipv4
]->arg
, &addr
)) {
2111 vty_out(vty
, "Please specify Router-Addr by A.B.C.D\n");
2112 return CMD_WARNING_CONFIG_FAILED
;
2115 as
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2117 /* Update Remote IP and Remote AS fields if needed */
2118 if (IS_PARAM_UNSET(iflp
, LP_RMT_AS
) || iflp
->rmt_as
!= as
2119 || iflp
->rmt_ip
.s_addr
!= addr
.s_addr
) {
2122 iflp
->rmt_ip
.s_addr
= addr
.s_addr
;
2123 SET_PARAM(iflp
, LP_RMT_AS
);
2125 /* force protocols to update LINK STATE due to parameters change
2127 if (if_is_operative(ifp
))
2128 zebra_interface_parameters_update(ifp
);
2133 DEFUN (no_link_params_inter_as
,
2134 no_link_params_inter_as_cmd
,
2137 "Remove Neighbor IP address and AS number for Inter-AS TE\n")
2139 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2140 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2142 /* Reset Remote IP and AS neighbor */
2144 iflp
->rmt_ip
.s_addr
= 0;
2145 UNSET_PARAM(iflp
, LP_RMT_AS
);
2147 /* force protocols to update LINK STATE due to parameters change */
2148 if (if_is_operative(ifp
))
2149 zebra_interface_parameters_update(ifp
);
2154 /* RFC7471: OSPF Traffic Engineering (TE) Metric extensions &
2155 * draft-ietf-isis-metric-extensions-07.txt */
2156 DEFUN (link_params_delay
,
2157 link_params_delay_cmd
,
2158 "delay (0-16777215) [min (0-16777215) max (0-16777215)]",
2159 "Unidirectional Average Link Delay\n"
2160 "Average delay in micro-second as decimal (0...16777215)\n"
2162 "Minimum delay in micro-second as decimal (0...16777215)\n"
2164 "Maximum delay in micro-second as decimal (0...16777215)\n")
2166 /* Get and Check new delay values */
2167 uint32_t delay
= 0, low
= 0, high
= 0;
2168 delay
= strtoul(argv
[1]->arg
, NULL
, 10);
2170 low
= strtoul(argv
[3]->arg
, NULL
, 10);
2171 high
= strtoul(argv
[5]->arg
, NULL
, 10);
2174 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2175 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2179 /* Check new delay value against old Min and Max delays if set
2181 if (IS_PARAM_SET(iflp
, LP_MM_DELAY
)
2182 && (delay
<= iflp
->min_delay
|| delay
>= iflp
->max_delay
)) {
2184 "Average delay should be comprise between Min (%d) and Max (%d) delay\n",
2185 iflp
->min_delay
, iflp
->max_delay
);
2186 return CMD_WARNING_CONFIG_FAILED
;
2188 /* Update delay if value is not set or change */
2189 if (IS_PARAM_UNSET(iflp
, LP_DELAY
) || iflp
->av_delay
!= delay
) {
2190 iflp
->av_delay
= delay
;
2191 SET_PARAM(iflp
, LP_DELAY
);
2194 /* Unset Min and Max delays if already set */
2195 if (IS_PARAM_SET(iflp
, LP_MM_DELAY
)) {
2196 iflp
->min_delay
= 0;
2197 iflp
->max_delay
= 0;
2198 UNSET_PARAM(iflp
, LP_MM_DELAY
);
2202 /* Check new delays value coherency */
2203 if (delay
<= low
|| delay
>= high
) {
2205 "Average delay should be comprise between Min (%d) and Max (%d) delay\n",
2207 return CMD_WARNING_CONFIG_FAILED
;
2209 /* Update Delays if needed */
2210 if (IS_PARAM_UNSET(iflp
, LP_DELAY
)
2211 || IS_PARAM_UNSET(iflp
, LP_MM_DELAY
)
2212 || iflp
->av_delay
!= delay
|| iflp
->min_delay
!= low
2213 || iflp
->max_delay
!= high
) {
2214 iflp
->av_delay
= delay
;
2215 SET_PARAM(iflp
, LP_DELAY
);
2216 iflp
->min_delay
= low
;
2217 iflp
->max_delay
= high
;
2218 SET_PARAM(iflp
, LP_MM_DELAY
);
2223 /* force protocols to update LINK STATE due to parameters change */
2224 if (update
== 1 && if_is_operative(ifp
))
2225 zebra_interface_parameters_update(ifp
);
2230 DEFUN (no_link_params_delay
,
2231 no_link_params_delay_cmd
,
2234 "Disable Unidirectional Average, Min & Max Link Delay on this interface\n")
2236 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2237 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2241 UNSET_PARAM(iflp
, LP_DELAY
);
2242 iflp
->min_delay
= 0;
2243 iflp
->max_delay
= 0;
2244 UNSET_PARAM(iflp
, LP_MM_DELAY
);
2246 /* force protocols to update LINK STATE due to parameters change */
2247 if (if_is_operative(ifp
))
2248 zebra_interface_parameters_update(ifp
);
2253 DEFUN (link_params_delay_var
,
2254 link_params_delay_var_cmd
,
2255 "delay-variation (0-16777215)",
2256 "Unidirectional Link Delay Variation\n"
2257 "delay variation in micro-second as decimal (0...16777215)\n")
2260 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2261 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2264 value
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2266 /* Update Delay Variation if needed */
2267 link_param_cmd_set_uint32(ifp
, &iflp
->delay_var
, LP_DELAY_VAR
, value
);
2272 DEFUN (no_link_params_delay_var
,
2273 no_link_params_delay_var_cmd
,
2274 "no delay-variation",
2276 "Disable Unidirectional Delay Variation on this interface\n")
2278 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2280 /* Unset Delay Variation */
2281 link_param_cmd_unset(ifp
, LP_DELAY_VAR
);
2286 DEFUN (link_params_pkt_loss
,
2287 link_params_pkt_loss_cmd
,
2288 "packet-loss PERCENTAGE",
2289 "Unidirectional Link Packet Loss\n"
2290 "percentage of total traffic by 0.000003% step and less than 50.331642%\n")
2292 int idx_percentage
= 1;
2293 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2294 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2297 if (sscanf(argv
[idx_percentage
]->arg
, "%g", &fval
) != 1) {
2298 vty_out(vty
, "link_params_pkt_loss: fscanf: %s\n",
2299 safe_strerror(errno
));
2300 return CMD_WARNING_CONFIG_FAILED
;
2303 if (fval
> MAX_PKT_LOSS
)
2304 fval
= MAX_PKT_LOSS
;
2306 /* Update Packet Loss if needed */
2307 link_param_cmd_set_float(ifp
, &iflp
->pkt_loss
, LP_PKT_LOSS
, fval
);
2312 DEFUN (no_link_params_pkt_loss
,
2313 no_link_params_pkt_loss_cmd
,
2316 "Disable Unidirectional Link Packet Loss on this interface\n")
2318 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2320 /* Unset Packet Loss */
2321 link_param_cmd_unset(ifp
, LP_PKT_LOSS
);
2326 DEFUN (link_params_res_bw
,
2327 link_params_res_bw_cmd
,
2329 "Unidirectional Residual Bandwidth\n"
2330 "Bytes/second (IEEE floating point format)\n")
2332 int idx_bandwidth
= 1;
2333 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2334 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2337 if (sscanf(argv
[idx_bandwidth
]->arg
, "%g", &bw
) != 1) {
2338 vty_out(vty
, "link_params_res_bw: fscanf: %s\n",
2339 safe_strerror(errno
));
2340 return CMD_WARNING_CONFIG_FAILED
;
2343 /* Check that bandwidth is not greater than maximum bandwidth parameter
2345 if (bw
> iflp
->max_bw
) {
2347 "Residual Bandwidth could not be greater than Maximum Bandwidth (%g)\n",
2349 return CMD_WARNING_CONFIG_FAILED
;
2352 /* Update Residual Bandwidth if needed */
2353 link_param_cmd_set_float(ifp
, &iflp
->res_bw
, LP_RES_BW
, bw
);
2358 DEFUN (no_link_params_res_bw
,
2359 no_link_params_res_bw_cmd
,
2362 "Disable Unidirectional Residual Bandwidth on this interface\n")
2364 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2366 /* Unset Residual Bandwidth */
2367 link_param_cmd_unset(ifp
, LP_RES_BW
);
2372 DEFUN (link_params_ava_bw
,
2373 link_params_ava_bw_cmd
,
2375 "Unidirectional Available Bandwidth\n"
2376 "Bytes/second (IEEE floating point format)\n")
2378 int idx_bandwidth
= 1;
2379 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2380 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2383 if (sscanf(argv
[idx_bandwidth
]->arg
, "%g", &bw
) != 1) {
2384 vty_out(vty
, "link_params_ava_bw: fscanf: %s\n",
2385 safe_strerror(errno
));
2386 return CMD_WARNING_CONFIG_FAILED
;
2389 /* Check that bandwidth is not greater than maximum bandwidth parameter
2391 if (bw
> iflp
->max_bw
) {
2393 "Available Bandwidth could not be greater than Maximum Bandwidth (%g)\n",
2395 return CMD_WARNING_CONFIG_FAILED
;
2398 /* Update Residual Bandwidth if needed */
2399 link_param_cmd_set_float(ifp
, &iflp
->ava_bw
, LP_AVA_BW
, bw
);
2404 DEFUN (no_link_params_ava_bw
,
2405 no_link_params_ava_bw_cmd
,
2408 "Disable Unidirectional Available Bandwidth on this interface\n")
2410 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2412 /* Unset Available Bandwidth */
2413 link_param_cmd_unset(ifp
, LP_AVA_BW
);
2418 DEFUN (link_params_use_bw
,
2419 link_params_use_bw_cmd
,
2421 "Unidirectional Utilised Bandwidth\n"
2422 "Bytes/second (IEEE floating point format)\n")
2424 int idx_bandwidth
= 1;
2425 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2426 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2429 if (sscanf(argv
[idx_bandwidth
]->arg
, "%g", &bw
) != 1) {
2430 vty_out(vty
, "link_params_use_bw: fscanf: %s\n",
2431 safe_strerror(errno
));
2432 return CMD_WARNING_CONFIG_FAILED
;
2435 /* Check that bandwidth is not greater than maximum bandwidth parameter
2437 if (bw
> iflp
->max_bw
) {
2439 "Utilised Bandwidth could not be greater than Maximum Bandwidth (%g)\n",
2441 return CMD_WARNING_CONFIG_FAILED
;
2444 /* Update Utilized Bandwidth if needed */
2445 link_param_cmd_set_float(ifp
, &iflp
->use_bw
, LP_USE_BW
, bw
);
2450 DEFUN (no_link_params_use_bw
,
2451 no_link_params_use_bw_cmd
,
2454 "Disable Unidirectional Utilised Bandwidth on this interface\n")
2456 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2458 /* Unset Utilised Bandwidth */
2459 link_param_cmd_unset(ifp
, LP_USE_BW
);
2464 static int ip_address_install(struct vty
*vty
, struct interface
*ifp
,
2465 const char *addr_str
, const char *peer_str
,
2468 struct zebra_if
*if_data
;
2469 struct prefix_ipv4 lp
, pp
;
2470 struct connected
*ifc
;
2471 struct prefix_ipv4
*p
;
2474 if_data
= ifp
->info
;
2476 ret
= str2prefix_ipv4(addr_str
, &lp
);
2478 vty_out(vty
, "%% Malformed address \n");
2479 return CMD_WARNING_CONFIG_FAILED
;
2482 if (ipv4_martian(&lp
.prefix
)) {
2483 vty_out(vty
, "%% Invalid address\n");
2484 return CMD_WARNING_CONFIG_FAILED
;
2488 if (lp
.prefixlen
!= 32) {
2490 "%% Local prefix length for P-t-P address must be /32\n");
2491 return CMD_WARNING_CONFIG_FAILED
;
2494 ret
= str2prefix_ipv4(peer_str
, &pp
);
2496 vty_out(vty
, "%% Malformed peer address\n");
2497 return CMD_WARNING_CONFIG_FAILED
;
2501 ifc
= connected_check_ptp(ifp
, &lp
, peer_str
? &pp
: NULL
);
2503 ifc
= connected_new();
2507 p
= prefix_ipv4_new();
2509 ifc
->address
= (struct prefix
*)p
;
2512 SET_FLAG(ifc
->flags
, ZEBRA_IFA_PEER
);
2513 p
= prefix_ipv4_new();
2515 ifc
->destination
= (struct prefix
*)p
;
2516 } else if (p
->prefixlen
<= IPV4_MAX_PREFIXLEN
- 2) {
2517 p
= prefix_ipv4_new();
2519 p
->prefix
.s_addr
= ipv4_broadcast_addr(p
->prefix
.s_addr
,
2521 ifc
->destination
= (struct prefix
*)p
;
2526 ifc
->label
= XSTRDUP(MTYPE_CONNECTED_LABEL
, label
);
2528 /* Add to linked list. */
2529 listnode_add(ifp
->connected
, ifc
);
2532 /* This address is configured from zebra. */
2533 if (!CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
2534 SET_FLAG(ifc
->conf
, ZEBRA_IFC_CONFIGURED
);
2536 /* In case of this route need to install kernel. */
2537 if (!CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
)
2538 && CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
)
2539 && !(if_data
&& if_data
->shutdown
== IF_ZEBRA_SHUTDOWN_ON
)) {
2540 /* Some system need to up the interface to set IP address. */
2541 if (!if_is_up(ifp
)) {
2542 if_set_flags(ifp
, IFF_UP
| IFF_RUNNING
);
2546 ret
= if_set_prefix(ifp
, ifc
);
2548 vty_out(vty
, "%% Can't set interface IP address: %s.\n",
2549 safe_strerror(errno
));
2550 return CMD_WARNING_CONFIG_FAILED
;
2553 SET_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
);
2554 /* The address will be advertised to zebra clients when the
2556 * from the kernel has been received.
2557 * It will also be added to the subnet chain list, then. */
2563 static int ip_address_uninstall(struct vty
*vty
, struct interface
*ifp
,
2564 const char *addr_str
, const char *peer_str
,
2567 struct prefix_ipv4 lp
, pp
;
2568 struct connected
*ifc
;
2571 /* Convert to prefix structure. */
2572 ret
= str2prefix_ipv4(addr_str
, &lp
);
2574 vty_out(vty
, "%% Malformed address \n");
2575 return CMD_WARNING_CONFIG_FAILED
;
2579 if (lp
.prefixlen
!= 32) {
2581 "%% Local prefix length for P-t-P address must be /32\n");
2582 return CMD_WARNING_CONFIG_FAILED
;
2585 ret
= str2prefix_ipv4(peer_str
, &pp
);
2587 vty_out(vty
, "%% Malformed peer address\n");
2588 return CMD_WARNING_CONFIG_FAILED
;
2592 /* Check current interface address. */
2593 ifc
= connected_check_ptp(ifp
, &lp
, peer_str
? &pp
: NULL
);
2595 vty_out(vty
, "%% Can't find address\n");
2596 return CMD_WARNING_CONFIG_FAILED
;
2599 /* This is not configured address. */
2600 if (!CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
2601 return CMD_WARNING_CONFIG_FAILED
;
2603 UNSET_FLAG(ifc
->conf
, ZEBRA_IFC_CONFIGURED
);
2605 /* This is not real address or interface is not active. */
2606 if (!CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
)
2607 || !CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
)) {
2608 listnode_delete(ifp
->connected
, ifc
);
2609 connected_free(ifc
);
2610 return CMD_WARNING_CONFIG_FAILED
;
2613 /* This is real route. */
2614 ret
= if_unset_prefix(ifp
, ifc
);
2616 vty_out(vty
, "%% Can't unset interface IP address: %s.\n",
2617 safe_strerror(errno
));
2618 return CMD_WARNING_CONFIG_FAILED
;
2620 UNSET_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
);
2621 /* we will receive a kernel notification about this route being removed.
2622 * this will trigger its removal from the connected list. */
2628 "ip address A.B.C.D/M",
2629 "Interface Internet Protocol config commands\n"
2630 "Set the IP address of an interface\n"
2631 "IP address (e.g. 10.0.0.1/8)\n")
2633 int idx_ipv4_prefixlen
= 2;
2634 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2635 return ip_address_install(vty
, ifp
, argv
[idx_ipv4_prefixlen
]->arg
, NULL
,
2639 DEFUN (no_ip_address
,
2641 "no ip address A.B.C.D/M",
2643 "Interface Internet Protocol config commands\n"
2644 "Set the IP address of an interface\n"
2645 "IP Address (e.g. 10.0.0.1/8)\n")
2647 int idx_ipv4_prefixlen
= 3;
2648 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2649 return ip_address_uninstall(vty
, ifp
, argv
[idx_ipv4_prefixlen
]->arg
,
2653 DEFUN(ip_address_peer
,
2654 ip_address_peer_cmd
,
2655 "ip address A.B.C.D peer A.B.C.D/M",
2656 "Interface Internet Protocol config commands\n"
2657 "Set the IP address of an interface\n"
2658 "Local IP (e.g. 10.0.0.1) for P-t-P address\n"
2659 "Specify P-t-P address\n"
2660 "Peer IP address (e.g. 10.0.0.1/8)\n")
2662 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2663 return ip_address_install(vty
, ifp
, argv
[2]->arg
, argv
[4]->arg
, NULL
);
2666 DEFUN(no_ip_address_peer
,
2667 no_ip_address_peer_cmd
,
2668 "no ip address A.B.C.D peer A.B.C.D/M",
2670 "Interface Internet Protocol config commands\n"
2671 "Set the IP address of an interface\n"
2672 "Local IP (e.g. 10.0.0.1) for P-t-P address\n"
2673 "Specify P-t-P address\n"
2674 "Peer IP address (e.g. 10.0.0.1/8)\n")
2676 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2677 return ip_address_uninstall(vty
, ifp
, argv
[3]->arg
, argv
[5]->arg
, NULL
);
2681 DEFUN (ip_address_label
,
2682 ip_address_label_cmd
,
2683 "ip address A.B.C.D/M label LINE",
2684 "Interface Internet Protocol config commands\n"
2685 "Set the IP address of an interface\n"
2686 "IP address (e.g. 10.0.0.1/8)\n"
2687 "Label of this address\n"
2690 int idx_ipv4_prefixlen
= 2;
2692 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2693 return ip_address_install(vty
, ifp
, argv
[idx_ipv4_prefixlen
]->arg
, NULL
,
2694 argv
[idx_line
]->arg
);
2697 DEFUN (no_ip_address_label
,
2698 no_ip_address_label_cmd
,
2699 "no ip address A.B.C.D/M label LINE",
2701 "Interface Internet Protocol config commands\n"
2702 "Set the IP address of an interface\n"
2703 "IP address (e.g. 10.0.0.1/8)\n"
2704 "Label of this address\n"
2707 int idx_ipv4_prefixlen
= 3;
2709 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2710 return ip_address_uninstall(vty
, ifp
, argv
[idx_ipv4_prefixlen
]->arg
,
2711 NULL
, argv
[idx_line
]->arg
);
2713 #endif /* HAVE_NETLINK */
2715 static int ipv6_address_install(struct vty
*vty
, struct interface
*ifp
,
2716 const char *addr_str
, const char *peer_str
,
2717 const char *label
, int secondary
)
2719 struct zebra_if
*if_data
;
2720 struct prefix_ipv6 cp
;
2721 struct connected
*ifc
;
2722 struct prefix_ipv6
*p
;
2725 if_data
= ifp
->info
;
2727 ret
= str2prefix_ipv6(addr_str
, &cp
);
2729 vty_out(vty
, "%% Malformed address \n");
2730 return CMD_WARNING_CONFIG_FAILED
;
2733 if (ipv6_martian(&cp
.prefix
)) {
2734 vty_out(vty
, "%% Invalid address\n");
2735 return CMD_WARNING_CONFIG_FAILED
;
2738 ifc
= connected_check(ifp
, (struct prefix
*)&cp
);
2740 ifc
= connected_new();
2744 p
= prefix_ipv6_new();
2746 ifc
->address
= (struct prefix
*)p
;
2750 SET_FLAG(ifc
->flags
, ZEBRA_IFA_SECONDARY
);
2754 ifc
->label
= XSTRDUP(MTYPE_CONNECTED_LABEL
, label
);
2756 /* Add to linked list. */
2757 listnode_add(ifp
->connected
, ifc
);
2760 /* This address is configured from zebra. */
2761 if (!CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
2762 SET_FLAG(ifc
->conf
, ZEBRA_IFC_CONFIGURED
);
2764 /* In case of this route need to install kernel. */
2765 if (!CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
)
2766 && CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
)
2767 && !(if_data
&& if_data
->shutdown
== IF_ZEBRA_SHUTDOWN_ON
)) {
2768 /* Some system need to up the interface to set IP address. */
2769 if (!if_is_up(ifp
)) {
2770 if_set_flags(ifp
, IFF_UP
| IFF_RUNNING
);
2774 ret
= if_prefix_add_ipv6(ifp
, ifc
);
2777 vty_out(vty
, "%% Can't set interface IP address: %s.\n",
2778 safe_strerror(errno
));
2779 return CMD_WARNING_CONFIG_FAILED
;
2782 SET_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
);
2783 /* The address will be advertised to zebra clients when the
2785 * from the kernel has been received. */
2791 /* Return true if an ipv6 address is configured on ifp */
2792 int ipv6_address_configured(struct interface
*ifp
)
2794 struct connected
*connected
;
2795 struct listnode
*node
;
2797 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, node
, connected
))
2798 if (CHECK_FLAG(connected
->conf
, ZEBRA_IFC_REAL
)
2799 && (connected
->address
->family
== AF_INET6
))
2805 static int ipv6_address_uninstall(struct vty
*vty
, struct interface
*ifp
,
2806 const char *addr_str
, const char *peer_str
,
2807 const char *label
, int secondry
)
2809 struct prefix_ipv6 cp
;
2810 struct connected
*ifc
;
2813 /* Convert to prefix structure. */
2814 ret
= str2prefix_ipv6(addr_str
, &cp
);
2816 vty_out(vty
, "%% Malformed address \n");
2817 return CMD_WARNING_CONFIG_FAILED
;
2820 /* Check current interface address. */
2821 ifc
= connected_check(ifp
, (struct prefix
*)&cp
);
2823 vty_out(vty
, "%% Can't find address\n");
2824 return CMD_WARNING_CONFIG_FAILED
;
2827 /* This is not configured address. */
2828 if (!CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
2829 return CMD_WARNING_CONFIG_FAILED
;
2831 UNSET_FLAG(ifc
->conf
, ZEBRA_IFC_CONFIGURED
);
2833 /* This is not real address or interface is not active. */
2834 if (!CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
)
2835 || !CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
)) {
2836 listnode_delete(ifp
->connected
, ifc
);
2837 connected_free(ifc
);
2838 return CMD_WARNING_CONFIG_FAILED
;
2841 /* This is real route. */
2842 ret
= if_prefix_delete_ipv6(ifp
, ifc
);
2844 vty_out(vty
, "%% Can't unset interface IP address: %s.\n",
2845 safe_strerror(errno
));
2846 return CMD_WARNING_CONFIG_FAILED
;
2849 UNSET_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
);
2850 /* This information will be propagated to the zclients when the
2851 * kernel notification is received. */
2855 DEFUN (ipv6_address
,
2857 "ipv6 address X:X::X:X/M",
2858 "Interface IPv6 config commands\n"
2859 "Set the IP address of an interface\n"
2860 "IPv6 address (e.g. 3ffe:506::1/48)\n")
2862 int idx_ipv6_prefixlen
= 2;
2863 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2864 return ipv6_address_install(vty
, ifp
, argv
[idx_ipv6_prefixlen
]->arg
,
2868 DEFUN (no_ipv6_address
,
2869 no_ipv6_address_cmd
,
2870 "no ipv6 address X:X::X:X/M",
2872 "Interface IPv6 config commands\n"
2873 "Set the IP address of an interface\n"
2874 "IPv6 address (e.g. 3ffe:506::1/48)\n")
2876 int idx_ipv6_prefixlen
= 3;
2877 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2878 return ipv6_address_uninstall(vty
, ifp
, argv
[idx_ipv6_prefixlen
]->arg
,
2882 static int link_params_config_write(struct vty
*vty
, struct interface
*ifp
)
2886 if ((ifp
== NULL
) || !HAS_LINK_PARAMS(ifp
))
2889 struct if_link_params
*iflp
= ifp
->link_params
;
2891 vty_out(vty
, " link-params\n");
2892 vty_out(vty
, " enable\n");
2893 if (IS_PARAM_SET(iflp
, LP_TE_METRIC
) && iflp
->te_metric
!= ifp
->metric
)
2894 vty_out(vty
, " metric %u\n", iflp
->te_metric
);
2895 if (IS_PARAM_SET(iflp
, LP_MAX_BW
) && iflp
->max_bw
!= iflp
->default_bw
)
2896 vty_out(vty
, " max-bw %g\n", iflp
->max_bw
);
2897 if (IS_PARAM_SET(iflp
, LP_MAX_RSV_BW
)
2898 && iflp
->max_rsv_bw
!= iflp
->default_bw
)
2899 vty_out(vty
, " max-rsv-bw %g\n", iflp
->max_rsv_bw
);
2900 if (IS_PARAM_SET(iflp
, LP_UNRSV_BW
)) {
2901 for (i
= 0; i
< 8; i
++)
2902 if (iflp
->unrsv_bw
[i
] != iflp
->default_bw
)
2903 vty_out(vty
, " unrsv-bw %d %g\n", i
,
2906 if (IS_PARAM_SET(iflp
, LP_ADM_GRP
))
2907 vty_out(vty
, " admin-grp 0x%x\n", iflp
->admin_grp
);
2908 if (IS_PARAM_SET(iflp
, LP_DELAY
)) {
2909 vty_out(vty
, " delay %u", iflp
->av_delay
);
2910 if (IS_PARAM_SET(iflp
, LP_MM_DELAY
)) {
2911 vty_out(vty
, " min %u", iflp
->min_delay
);
2912 vty_out(vty
, " max %u", iflp
->max_delay
);
2916 if (IS_PARAM_SET(iflp
, LP_DELAY_VAR
))
2917 vty_out(vty
, " delay-variation %u\n", iflp
->delay_var
);
2918 if (IS_PARAM_SET(iflp
, LP_PKT_LOSS
))
2919 vty_out(vty
, " packet-loss %g\n", iflp
->pkt_loss
);
2920 if (IS_PARAM_SET(iflp
, LP_AVA_BW
))
2921 vty_out(vty
, " ava-bw %g\n", iflp
->ava_bw
);
2922 if (IS_PARAM_SET(iflp
, LP_RES_BW
))
2923 vty_out(vty
, " res-bw %g\n", iflp
->res_bw
);
2924 if (IS_PARAM_SET(iflp
, LP_USE_BW
))
2925 vty_out(vty
, " use-bw %g\n", iflp
->use_bw
);
2926 if (IS_PARAM_SET(iflp
, LP_RMT_AS
))
2927 vty_out(vty
, " neighbor %s as %u\n", inet_ntoa(iflp
->rmt_ip
),
2929 vty_out(vty
, " exit-link-params\n");
2933 static int if_config_write(struct vty
*vty
)
2936 struct interface
*ifp
;
2938 zebra_ptm_write(vty
);
2940 RB_FOREACH (vrf0
, vrf_name_head
, &vrfs_by_name
)
2941 FOR_ALL_INTERFACES (vrf0
, ifp
) {
2942 struct zebra_if
*if_data
;
2943 struct listnode
*addrnode
;
2944 struct connected
*ifc
;
2948 if_data
= ifp
->info
;
2949 vrf
= vrf_lookup_by_id(ifp
->vrf_id
);
2951 if (ifp
->vrf_id
== VRF_DEFAULT
)
2952 vty_frame(vty
, "interface %s\n", ifp
->name
);
2954 vty_frame(vty
, "interface %s vrf %s\n",
2955 ifp
->name
, vrf
->name
);
2958 if (if_data
->shutdown
== IF_ZEBRA_SHUTDOWN_ON
)
2959 vty_out(vty
, " shutdown\n");
2961 zebra_ptm_if_write(vty
, if_data
);
2965 vty_out(vty
, " description %s\n", ifp
->desc
);
2967 /* Assign bandwidth here to avoid unnecessary interface
2969 while processing config script */
2970 if (ifp
->bandwidth
!= 0)
2971 vty_out(vty
, " bandwidth %u\n", ifp
->bandwidth
);
2973 if (!CHECK_FLAG(ifp
->status
,
2974 ZEBRA_INTERFACE_LINKDETECTION
))
2975 vty_out(vty
, " no link-detect\n");
2977 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, addrnode
,
2979 if (CHECK_FLAG(ifc
->conf
,
2980 ZEBRA_IFC_CONFIGURED
)) {
2981 char buf
[INET6_ADDRSTRLEN
];
2983 vty_out(vty
, " ip%s address %s",
2984 p
->family
== AF_INET
? ""
2986 inet_ntop(p
->family
,
2989 if (CONNECTED_PEER(ifc
)) {
2990 p
= ifc
->destination
;
2991 vty_out(vty
, " peer %s",
2992 inet_ntop(p
->family
,
2997 vty_out(vty
, "/%d", p
->prefixlen
);
3000 vty_out(vty
, " label %s",
3008 if (if_data
->multicast
3009 != IF_ZEBRA_MULTICAST_UNSPEC
)
3010 vty_out(vty
, " %smulticast\n",
3012 == IF_ZEBRA_MULTICAST_ON
3017 hook_call(zebra_if_config_wr
, vty
, ifp
);
3019 link_params_config_write(vty
, ifp
);
3021 vty_endframe(vty
, "!\n");
3026 /* Allocate and initialize interface vector. */
3027 void zebra_if_init(void)
3029 /* Initialize interface and new hook. */
3030 hook_register_prio(if_add
, 0, if_zebra_new_hook
);
3031 hook_register_prio(if_del
, 0, if_zebra_delete_hook
);
3033 /* Install configuration write function. */
3034 install_node(&interface_node
, if_config_write
);
3035 install_node(&link_params_node
, NULL
);
3038 install_element(VIEW_NODE
, &show_interface_cmd
);
3039 install_element(VIEW_NODE
, &show_interface_vrf_all_cmd
);
3040 install_element(VIEW_NODE
, &show_interface_name_vrf_cmd
);
3041 install_element(VIEW_NODE
, &show_interface_name_vrf_all_cmd
);
3043 install_element(ENABLE_NODE
, &show_interface_desc_cmd
);
3044 install_element(ENABLE_NODE
, &show_interface_desc_vrf_all_cmd
);
3045 install_element(INTERFACE_NODE
, &multicast_cmd
);
3046 install_element(INTERFACE_NODE
, &no_multicast_cmd
);
3047 install_element(INTERFACE_NODE
, &linkdetect_cmd
);
3048 install_element(INTERFACE_NODE
, &no_linkdetect_cmd
);
3049 install_element(INTERFACE_NODE
, &shutdown_if_cmd
);
3050 install_element(INTERFACE_NODE
, &no_shutdown_if_cmd
);
3051 install_element(INTERFACE_NODE
, &bandwidth_if_cmd
);
3052 install_element(INTERFACE_NODE
, &no_bandwidth_if_cmd
);
3053 install_element(INTERFACE_NODE
, &ip_address_cmd
);
3054 install_element(INTERFACE_NODE
, &no_ip_address_cmd
);
3055 install_element(INTERFACE_NODE
, &ip_address_peer_cmd
);
3056 install_element(INTERFACE_NODE
, &no_ip_address_peer_cmd
);
3057 install_element(INTERFACE_NODE
, &ipv6_address_cmd
);
3058 install_element(INTERFACE_NODE
, &no_ipv6_address_cmd
);
3060 install_element(INTERFACE_NODE
, &ip_address_label_cmd
);
3061 install_element(INTERFACE_NODE
, &no_ip_address_label_cmd
);
3062 #endif /* HAVE_NETLINK */
3063 install_element(INTERFACE_NODE
, &link_params_cmd
);
3064 install_default(LINK_PARAMS_NODE
);
3065 install_element(LINK_PARAMS_NODE
, &link_params_enable_cmd
);
3066 install_element(LINK_PARAMS_NODE
, &no_link_params_enable_cmd
);
3067 install_element(LINK_PARAMS_NODE
, &link_params_metric_cmd
);
3068 install_element(LINK_PARAMS_NODE
, &no_link_params_metric_cmd
);
3069 install_element(LINK_PARAMS_NODE
, &link_params_maxbw_cmd
);
3070 install_element(LINK_PARAMS_NODE
, &link_params_max_rsv_bw_cmd
);
3071 install_element(LINK_PARAMS_NODE
, &link_params_unrsv_bw_cmd
);
3072 install_element(LINK_PARAMS_NODE
, &link_params_admin_grp_cmd
);
3073 install_element(LINK_PARAMS_NODE
, &no_link_params_admin_grp_cmd
);
3074 install_element(LINK_PARAMS_NODE
, &link_params_inter_as_cmd
);
3075 install_element(LINK_PARAMS_NODE
, &no_link_params_inter_as_cmd
);
3076 install_element(LINK_PARAMS_NODE
, &link_params_delay_cmd
);
3077 install_element(LINK_PARAMS_NODE
, &no_link_params_delay_cmd
);
3078 install_element(LINK_PARAMS_NODE
, &link_params_delay_var_cmd
);
3079 install_element(LINK_PARAMS_NODE
, &no_link_params_delay_var_cmd
);
3080 install_element(LINK_PARAMS_NODE
, &link_params_pkt_loss_cmd
);
3081 install_element(LINK_PARAMS_NODE
, &no_link_params_pkt_loss_cmd
);
3082 install_element(LINK_PARAMS_NODE
, &link_params_ava_bw_cmd
);
3083 install_element(LINK_PARAMS_NODE
, &no_link_params_ava_bw_cmd
);
3084 install_element(LINK_PARAMS_NODE
, &link_params_res_bw_cmd
);
3085 install_element(LINK_PARAMS_NODE
, &no_link_params_res_bw_cmd
);
3086 install_element(LINK_PARAMS_NODE
, &link_params_use_bw_cmd
);
3087 install_element(LINK_PARAMS_NODE
, &no_link_params_use_bw_cmd
);
3088 install_element(LINK_PARAMS_NODE
, &exit_link_params_cmd
);