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_MTYPE_STATIC(ZEBRA
, ZINFO
, "Zebra Interface Information")
56 #define ZEBRA_PTM_SUPPORT
58 DEFINE_HOOK(zebra_if_extra_info
, (struct vty
* vty
, struct interface
*ifp
),
60 DEFINE_HOOK(zebra_if_config_wr
, (struct vty
* vty
, struct interface
*ifp
),
64 static void if_down_del_nbr_connected(struct interface
*ifp
);
66 static int if_zebra_speed_update(struct thread
*thread
)
68 struct interface
*ifp
= THREAD_ARG(thread
);
69 struct zebra_if
*zif
= ifp
->info
;
72 zif
->speed_update
= NULL
;
74 new_speed
= kernel_get_speed(ifp
);
75 if (new_speed
!= ifp
->speed
) {
76 zlog_info("%s: %s old speed: %u new speed: %u",
77 __PRETTY_FUNCTION__
, ifp
->name
, ifp
->speed
,
79 ifp
->speed
= new_speed
;
86 static void zebra_if_node_destroy(route_table_delegate_t
*delegate
,
87 struct route_table
*table
,
88 struct route_node
*node
)
91 list_delete((struct list
**)&node
->info
);
92 route_node_destroy(delegate
, table
, node
);
95 route_table_delegate_t zebra_if_table_delegate
= {
96 .create_node
= route_node_create
,
97 .destroy_node
= zebra_if_node_destroy
};
99 /* Called when new interface is added. */
100 static int if_zebra_new_hook(struct interface
*ifp
)
102 struct zebra_if
*zebra_if
;
104 zebra_if
= XCALLOC(MTYPE_ZINFO
, sizeof(struct zebra_if
));
106 zebra_if
->multicast
= IF_ZEBRA_MULTICAST_UNSPEC
;
107 zebra_if
->shutdown
= IF_ZEBRA_SHUTDOWN_OFF
;
108 zebra_ptm_if_init(zebra_if
);
110 ifp
->ptm_enable
= zebra_ptm_get_enable_state();
111 #if defined(HAVE_RTADV)
113 /* Set default router advertise values. */
114 struct rtadvconf
*rtadv
;
116 rtadv
= &zebra_if
->rtadv
;
118 rtadv
->AdvSendAdvertisements
= 0;
119 rtadv
->MaxRtrAdvInterval
= RTADV_MAX_RTR_ADV_INTERVAL
;
120 rtadv
->MinRtrAdvInterval
= RTADV_MIN_RTR_ADV_INTERVAL
;
121 rtadv
->AdvIntervalTimer
= 0;
122 rtadv
->AdvManagedFlag
= 0;
123 rtadv
->AdvOtherConfigFlag
= 0;
124 rtadv
->AdvHomeAgentFlag
= 0;
125 rtadv
->AdvLinkMTU
= 0;
126 rtadv
->AdvReachableTime
= 0;
127 rtadv
->AdvRetransTimer
= 0;
128 rtadv
->AdvCurHopLimit
= 0;
129 rtadv
->AdvDefaultLifetime
=
130 -1; /* derive from MaxRtrAdvInterval */
131 rtadv
->HomeAgentPreference
= 0;
132 rtadv
->HomeAgentLifetime
=
133 -1; /* derive from AdvDefaultLifetime */
134 rtadv
->AdvIntervalOption
= 0;
135 rtadv
->DefaultPreference
= RTADV_PREF_MEDIUM
;
137 rtadv
->AdvPrefixList
= list_new();
139 #endif /* HAVE_RTADV */
141 memset(&zebra_if
->neigh_mac
[0], 0, 6);
143 /* Initialize installed address chains tree. */
144 zebra_if
->ipv4_subnets
=
145 route_table_init_with_delegate(&zebra_if_table_delegate
);
147 ifp
->info
= zebra_if
;
150 * Some platforms are telling us that the interface is
151 * up and ready to go. When we check the speed we
152 * sometimes get the wrong value. Wait a couple
153 * of seconds and ask again. Hopefully it's all settled
156 thread_add_timer(zebrad
.master
, if_zebra_speed_update
, ifp
, 15,
157 &zebra_if
->speed_update
);
161 /* Called when interface is deleted. */
162 static int if_zebra_delete_hook(struct interface
*ifp
)
164 struct zebra_if
*zebra_if
;
167 zebra_if
= ifp
->info
;
169 /* Free installed address chains tree. */
170 if (zebra_if
->ipv4_subnets
)
171 route_table_finish(zebra_if
->ipv4_subnets
);
172 #if defined(HAVE_RTADV)
174 struct rtadvconf
*rtadv
;
176 rtadv
= &zebra_if
->rtadv
;
177 list_delete(&rtadv
->AdvPrefixList
);
178 #endif /* HAVE_RTADV */
180 THREAD_OFF(zebra_if
->speed_update
);
182 XFREE(MTYPE_ZINFO
, zebra_if
);
188 /* Build the table key */
189 static void if_build_key(uint32_t ifindex
, struct prefix
*p
)
192 p
->prefixlen
= IPV4_MAX_BITLEN
;
193 p
->u
.prefix4
.s_addr
= ifindex
;
196 /* Link an interface in a per NS interface tree */
197 struct interface
*if_link_per_ns(struct zebra_ns
*ns
, struct interface
*ifp
)
200 struct route_node
*rn
;
202 if (ifp
->ifindex
== IFINDEX_INTERNAL
)
205 if_build_key(ifp
->ifindex
, &p
);
206 rn
= route_node_get(ns
->if_table
, &p
);
208 ifp
= (struct interface
*)rn
->info
;
209 route_unlock_node(rn
); /* get */
219 /* Delete a VRF. This is called in vrf_terminate(). */
220 void if_unlink_per_ns(struct interface
*ifp
)
222 ifp
->node
->info
= NULL
;
223 route_unlock_node(ifp
->node
);
227 /* Look up an interface by identifier within a NS */
228 struct interface
*if_lookup_by_index_per_ns(struct zebra_ns
*ns
,
232 struct route_node
*rn
;
233 struct interface
*ifp
= NULL
;
235 if_build_key(ifindex
, &p
);
236 rn
= route_node_lookup(ns
->if_table
, &p
);
238 ifp
= (struct interface
*)rn
->info
;
239 route_unlock_node(rn
); /* lookup */
244 /* Look up an interface by name within a NS */
245 struct interface
*if_lookup_by_name_per_ns(struct zebra_ns
*ns
,
248 struct route_node
*rn
;
249 struct interface
*ifp
;
251 for (rn
= route_top(ns
->if_table
); rn
; rn
= route_next(rn
)) {
252 ifp
= (struct interface
*)rn
->info
;
253 if (ifp
&& strcmp(ifp
->name
, ifname
) == 0)
260 const char *ifindex2ifname_per_ns(struct zebra_ns
*zns
, unsigned int ifindex
)
262 struct interface
*ifp
;
264 return ((ifp
= if_lookup_by_index_per_ns(zns
, ifindex
)) != NULL
)
269 /* Tie an interface address to its derived subnet list of addresses. */
270 int if_subnet_add(struct interface
*ifp
, struct connected
*ifc
)
272 struct route_node
*rn
;
273 struct zebra_if
*zebra_if
;
275 struct list
*addr_list
;
277 assert(ifp
&& ifp
->info
&& ifc
);
278 zebra_if
= ifp
->info
;
280 /* Get address derived subnet node and associated address list, while
282 address secondary attribute appropriately. */
283 cp
= *CONNECTED_PREFIX(ifc
);
285 rn
= route_node_get(zebra_if
->ipv4_subnets
, &cp
);
287 if ((addr_list
= rn
->info
))
288 SET_FLAG(ifc
->flags
, ZEBRA_IFA_SECONDARY
);
290 UNSET_FLAG(ifc
->flags
, ZEBRA_IFA_SECONDARY
);
291 rn
->info
= addr_list
= list_new();
295 /* Tie address at the tail of address list. */
296 listnode_add(addr_list
, ifc
);
298 /* Return list element count. */
299 return (addr_list
->count
);
302 /* Untie an interface address from its derived subnet list of addresses. */
303 int if_subnet_delete(struct interface
*ifp
, struct connected
*ifc
)
305 struct route_node
*rn
;
306 struct zebra_if
*zebra_if
;
307 struct list
*addr_list
;
310 assert(ifp
&& ifp
->info
&& ifc
);
311 zebra_if
= ifp
->info
;
313 cp
= *CONNECTED_PREFIX(ifc
);
316 /* Get address derived subnet node. */
317 rn
= route_node_lookup(zebra_if
->ipv4_subnets
, &cp
);
318 if (!(rn
&& rn
->info
)) {
319 flog_warn(EC_ZEBRA_REMOVE_ADDR_UNKNOWN_SUBNET
,
320 "Trying to remove an address from an unknown subnet."
321 " (please report this bug)");
324 route_unlock_node(rn
);
326 /* Untie address from subnet's address list. */
327 addr_list
= rn
->info
;
329 /* Deleting an address that is not registered is a bug.
330 * In any case, we shouldn't decrement the lock counter if the address
332 if (!listnode_lookup(addr_list
, ifc
)) {
334 EC_ZEBRA_REMOVE_UNREGISTERED_ADDR
,
335 "Trying to remove an address from a subnet where it is not"
336 " currently registered. (please report this bug)");
340 listnode_delete(addr_list
, ifc
);
341 route_unlock_node(rn
);
343 /* Return list element count, if not empty. */
344 if (addr_list
->count
) {
345 /* If deleted address is primary, mark subsequent one as such
347 if (!CHECK_FLAG(ifc
->flags
, ZEBRA_IFA_SECONDARY
)) {
349 (struct listnode
*)listhead(addr_list
));
350 zebra_interface_address_delete_update(ifp
, ifc
);
351 UNSET_FLAG(ifc
->flags
, ZEBRA_IFA_SECONDARY
);
352 /* XXX: Linux kernel removes all the secondary addresses
354 * address is removed. We could try to work around that,
357 zebra_interface_address_add_update(ifp
, ifc
);
360 return addr_list
->count
;
363 /* Otherwise, free list and route node. */
364 list_delete(&addr_list
);
366 route_unlock_node(rn
);
371 /* if_flags_mangle: A place for hacks that require mangling
372 * or tweaking the interface flags.
374 * ******************** Solaris flags hacks **************************
376 * Solaris IFF_UP flag reflects only the primary interface as the
377 * routing socket only sends IFINFO for the primary interface. Hence
378 * ~IFF_UP does not per se imply all the logical interfaces are also
379 * down - which we only know of as addresses. Instead we must determine
380 * whether the interface really is up or not according to how many
381 * addresses are still attached. (Solaris always sends RTM_DELADDR if
382 * an interface, logical or not, goes ~IFF_UP).
384 * Ie, we mangle IFF_UP to *additionally* reflect whether or not there
385 * are addresses left in struct connected, not just the actual underlying
388 * We must hence remember the real state of IFF_UP, which we do in
389 * struct zebra_if.primary_state.
391 * Setting IFF_UP within zebra to administratively shutdown the
392 * interface will affect only the primary interface/address on Solaris.
393 ************************End Solaris flags hacks ***********************
395 static void if_flags_mangle(struct interface
*ifp
, uint64_t *newflags
)
398 struct zebra_if
*zif
= ifp
->info
;
400 zif
->primary_state
= *newflags
& (IFF_UP
& 0xff);
402 if (CHECK_FLAG(zif
->primary_state
, IFF_UP
)
403 || listcount(ifp
->connected
) > 0)
404 SET_FLAG(*newflags
, IFF_UP
);
406 UNSET_FLAG(*newflags
, IFF_UP
);
410 /* Update the flags field of the ifp with the new flag set provided.
411 * Take whatever actions are required for any changes in flags we care
414 * newflags should be the raw value, as obtained from the OS.
416 void if_flags_update(struct interface
*ifp
, uint64_t newflags
)
418 if_flags_mangle(ifp
, &newflags
);
420 if (if_is_no_ptm_operative(ifp
)) {
421 /* operative -> inoperative? */
422 ifp
->flags
= newflags
;
423 if (!if_is_operative(ifp
))
426 /* inoperative -> operative? */
427 ifp
->flags
= newflags
;
428 if (if_is_operative(ifp
))
433 /* Wake up configured address if it is not in current kernel
435 static void if_addr_wakeup(struct interface
*ifp
)
437 struct listnode
*node
, *nnode
;
438 struct connected
*ifc
;
442 for (ALL_LIST_ELEMENTS(ifp
->connected
, node
, nnode
, ifc
)) {
445 if (CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_CONFIGURED
)
446 && !CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
)) {
448 if (p
->family
== AF_INET
) {
449 if (!if_is_up(ifp
)) {
450 /* Assume zebra is configured like
454 * ip addr 192.0.2.1/24
457 * As soon as zebra becomes first aware
458 * that gre0 exists in the
459 * kernel, it will set gre0 up and
460 * configure its addresses.
462 * (This may happen at startup when the
463 * interface already exists
464 * or during runtime when the interface
465 * is added to the kernel)
467 * XXX: IRDP code is calling here via
468 * if_add_update - this seems
470 * XXX: RUNNING is not a settable flag
472 * I (paulj) am aware of.
474 if_set_flags(ifp
, IFF_UP
| IFF_RUNNING
);
478 ret
= if_set_prefix(ifp
, ifc
);
481 EC_ZEBRA_IFACE_ADDR_ADD_FAILED
,
482 "Can't set interface's address: %s",
483 safe_strerror(errno
));
487 SET_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
);
488 /* The address will be advertised to zebra
489 * clients when the notification
490 * from the kernel has been received.
491 * It will also be added to the interface's
492 * subnet list then. */
494 if (p
->family
== AF_INET6
) {
495 if (!if_is_up(ifp
)) {
496 /* See long comment above */
497 if_set_flags(ifp
, IFF_UP
| IFF_RUNNING
);
501 ret
= if_prefix_add_ipv6(ifp
, ifc
);
504 EC_ZEBRA_IFACE_ADDR_ADD_FAILED
,
505 "Can't set interface's address: %s",
506 safe_strerror(errno
));
510 SET_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
);
511 /* The address will be advertised to zebra
512 * clients when the notification
513 * from the kernel has been received. */
519 /* Handle interface addition */
520 void if_add_update(struct interface
*ifp
)
522 struct zebra_if
*if_data
;
523 struct zebra_ns
*zns
;
524 struct zebra_vrf
*zvrf
= vrf_info_lookup(ifp
->vrf_id
);
526 /* case interface populate before vrf enabled */
530 zns
= zebra_ns_lookup(NS_DEFAULT
);
531 if_link_per_ns(zns
, ifp
);
535 if (if_data
->multicast
== IF_ZEBRA_MULTICAST_ON
)
536 if_set_flags(ifp
, IFF_MULTICAST
);
537 else if (if_data
->multicast
== IF_ZEBRA_MULTICAST_OFF
)
538 if_unset_flags(ifp
, IFF_MULTICAST
);
540 zebra_ptm_if_set_ptm_state(ifp
, if_data
);
542 zebra_interface_add_update(ifp
);
544 if (!CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
)) {
545 SET_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
);
547 if (if_data
->shutdown
== IF_ZEBRA_SHUTDOWN_ON
) {
548 if (IS_ZEBRA_DEBUG_KERNEL
)
550 "interface %s vrf %u index %d is shutdown. "
552 ifp
->name
, ifp
->vrf_id
, ifp
->ifindex
);
558 if (IS_ZEBRA_DEBUG_KERNEL
)
560 "interface %s vrf %u index %d becomes active.",
561 ifp
->name
, ifp
->vrf_id
, ifp
->ifindex
);
564 if (IS_ZEBRA_DEBUG_KERNEL
)
565 zlog_debug("interface %s vrf %u index %d is added.",
566 ifp
->name
, ifp
->vrf_id
, ifp
->ifindex
);
570 /* Install connected routes corresponding to an interface. */
571 static void if_install_connected(struct interface
*ifp
)
573 struct listnode
*node
;
574 struct listnode
*next
;
575 struct connected
*ifc
;
577 if (ifp
->connected
) {
578 for (ALL_LIST_ELEMENTS(ifp
->connected
, node
, next
, ifc
)) {
579 if (CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_REAL
))
580 zebra_interface_address_add_update(ifp
, ifc
);
582 connected_up(ifp
, ifc
);
587 /* Uninstall connected routes corresponding to an interface. */
588 static void if_uninstall_connected(struct interface
*ifp
)
590 struct listnode
*node
;
591 struct listnode
*next
;
592 struct connected
*ifc
;
594 if (ifp
->connected
) {
595 for (ALL_LIST_ELEMENTS(ifp
->connected
, node
, next
, ifc
)) {
596 zebra_interface_address_delete_update(ifp
, ifc
);
597 connected_down(ifp
, ifc
);
602 /* Uninstall and delete connected routes corresponding to an interface. */
603 /* TODO - Check why IPv4 handling here is different from install or if_down */
604 static void if_delete_connected(struct interface
*ifp
)
606 struct connected
*ifc
;
608 struct route_node
*rn
;
609 struct zebra_if
*zebra_if
;
610 struct listnode
*node
;
611 struct listnode
*last
= NULL
;
613 zebra_if
= ifp
->info
;
618 while ((node
= (last
? last
->next
: listhead(ifp
->connected
)))) {
619 ifc
= listgetdata(node
);
621 cp
= *CONNECTED_PREFIX(ifc
);
624 if (cp
.family
== AF_INET
625 && (rn
= route_node_lookup(zebra_if
->ipv4_subnets
, &cp
))) {
626 struct listnode
*anode
;
627 struct listnode
*next
;
628 struct listnode
*first
;
629 struct list
*addr_list
;
631 route_unlock_node(rn
);
632 addr_list
= (struct list
*)rn
->info
;
634 /* Remove addresses, secondaries first. */
635 first
= listhead(addr_list
);
637 for (anode
= first
->next
; anode
|| first
;
645 ifc
= listgetdata(anode
);
646 connected_down(ifp
, ifc
);
648 /* XXX: We have to send notifications
649 * here explicitly, because we destroy
650 * the ifc before receiving the
651 * notification about the address being
654 zebra_interface_address_delete_update(
657 UNSET_FLAG(ifc
->conf
, ZEBRA_IFC_REAL
);
658 UNSET_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
);
660 /* Remove from subnet chain. */
661 list_delete_node(addr_list
, anode
);
662 route_unlock_node(rn
);
664 /* Remove from interface address list
665 * (unconditionally). */
666 if (!CHECK_FLAG(ifc
->conf
,
667 ZEBRA_IFC_CONFIGURED
)) {
668 listnode_delete(ifp
->connected
,
675 /* Free chain list and respective route node. */
676 list_delete(&addr_list
);
678 route_unlock_node(rn
);
679 } else if (cp
.family
== AF_INET6
) {
680 connected_down(ifp
, ifc
);
682 zebra_interface_address_delete_update(ifp
, ifc
);
684 UNSET_FLAG(ifc
->conf
, ZEBRA_IFC_REAL
);
685 UNSET_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
);
687 if (CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
690 listnode_delete(ifp
->connected
, ifc
);
699 /* Handle an interface delete event */
700 void if_delete_update(struct interface
*ifp
)
702 struct zebra_if
*zif
;
707 "interface %s vrf %u index %d is still up while being deleted.",
708 ifp
->name
, ifp
->vrf_id
, ifp
->ifindex
);
712 if (!CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
))
715 /* Mark interface as inactive */
716 UNSET_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
);
718 if (IS_ZEBRA_DEBUG_KERNEL
)
719 zlog_debug("interface %s vrf %u index %d is now inactive.",
720 ifp
->name
, ifp
->vrf_id
, ifp
->ifindex
);
722 /* Delete connected routes from the kernel. */
723 if_delete_connected(ifp
);
725 /* Send out notification on interface delete. */
726 zebra_interface_delete_update(ifp
);
728 if_unlink_per_ns(ifp
);
730 /* Update ifindex after distributing the delete message. This is in
731 case any client needs to have the old value of ifindex available
732 while processing the deletion. Each client daemon is responsible
733 for setting ifindex to IFINDEX_INTERNAL after processing the
734 interface deletion message. */
735 if_set_index(ifp
, IFINDEX_INTERNAL
);
738 /* if the ifp is in a vrf, move it to default so vrf can be deleted if
739 * desired. This operation is not done for netns implementation to avoid
740 * collision with interface with the same name in the default vrf (can
741 * occur with this implementation whereas it is not possible with
744 if (ifp
->vrf_id
&& !vrf_is_backend_netns())
745 if_handle_vrf_change(ifp
, VRF_DEFAULT
);
747 /* Reset some zebra interface params to default values. */
750 zif
->zif_type
= ZEBRA_IF_OTHER
;
751 zif
->zif_slave_type
= ZEBRA_IF_SLAVE_NONE
;
752 memset(&zif
->l2info
, 0, sizeof(union zebra_l2if_info
));
753 memset(&zif
->brslave_info
, 0,
754 sizeof(struct zebra_l2info_brslave
));
758 /* VRF change for an interface */
759 void if_handle_vrf_change(struct interface
*ifp
, vrf_id_t vrf_id
)
763 old_vrf_id
= ifp
->vrf_id
;
765 /* Uninstall connected routes. */
766 if_uninstall_connected(ifp
);
768 /* Delete any IPv4 neighbors created to implement RFC 5549 */
769 if_nbr_ipv6ll_to_ipv4ll_neigh_del_all(ifp
);
771 /* Delete all neighbor addresses learnt through IPv6 RA */
772 if_down_del_nbr_connected(ifp
);
774 /* Send out notification on interface VRF change. */
775 /* This is to issue an UPDATE or a DELETE, as appropriate. */
776 zebra_interface_vrf_update_del(ifp
, vrf_id
);
779 if_update_to_new_vrf(ifp
, vrf_id
);
781 /* Send out notification on interface VRF change. */
782 /* This is to issue an ADD, if needed. */
783 zebra_interface_vrf_update_add(ifp
, old_vrf_id
);
785 /* Install connected routes (in new VRF). */
786 if (if_is_operative(ifp
))
787 if_install_connected(ifp
);
789 /* Due to connected route change, schedule RIB processing for both old
792 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
793 zlog_debug("%u: IF %s VRF change, scheduling RIB processing",
794 ifp
->vrf_id
, ifp
->name
);
795 rib_update(old_vrf_id
, RIB_UPDATE_IF_CHANGE
);
796 rib_update(ifp
->vrf_id
, RIB_UPDATE_IF_CHANGE
);
799 static void ipv6_ll_address_to_mac(struct in6_addr
*address
, uint8_t *mac
)
801 mac
[0] = address
->s6_addr
[8] ^ 0x02;
802 mac
[1] = address
->s6_addr
[9];
803 mac
[2] = address
->s6_addr
[10];
804 mac
[3] = address
->s6_addr
[13];
805 mac
[4] = address
->s6_addr
[14];
806 mac
[5] = address
->s6_addr
[15];
809 static bool mac_is_same(char *mac1
, char *mac2
)
811 if (mac1
[0] == mac2
[0] &&
812 mac1
[1] == mac2
[1] &&
813 mac1
[2] == mac2
[2] &&
814 mac1
[3] == mac2
[3] &&
815 mac1
[4] == mac2
[4] &&
822 void if_nbr_mac_to_ipv4ll_neigh_update(struct interface
*ifp
,
824 struct in6_addr
*address
,
827 struct zebra_vrf
*zvrf
= vrf_info_lookup(ifp
->vrf_id
);
828 struct zebra_if
*zif
= ifp
->info
;
829 char buf
[16] = "169.254.0.1";
830 struct in_addr ipv4_ll
;
833 inet_pton(AF_INET
, buf
, &ipv4_ll
);
835 ns_id
= zvrf
->zns
->ns_id
;
838 * Remove existed arp record for the interface as netlink
839 * protocol does not have update message types
841 * supported message types are RTM_NEWNEIGH and RTM_DELNEIGH
843 if (!mac_is_same(zif
->neigh_mac
, mac
)) {
844 kernel_neigh_update(0, ifp
->ifindex
, ipv4_ll
.s_addr
,
848 kernel_neigh_update(add
, ifp
->ifindex
, ipv4_ll
.s_addr
,
852 memcpy(&zif
->neigh_mac
[0], &mac
[0], 6);
855 * We need to note whether or not we originated a v6
856 * neighbor entry for this interface. So that when
857 * someone unwisely accidently deletes this entry
858 * we can shove it back in.
860 zif
->v6_2_v4_ll_neigh_entry
= !!add
;
861 memcpy(&zif
->v6_2_v4_ll_addr6
, address
, sizeof(*address
));
863 zvrf
->neigh_updates
++;
866 void if_nbr_ipv6ll_to_ipv4ll_neigh_update(struct interface
*ifp
,
867 struct in6_addr
*address
, int add
)
872 ipv6_ll_address_to_mac(address
, (uint8_t *)mac
);
873 if_nbr_mac_to_ipv4ll_neigh_update(ifp
, mac
, address
, add
);
876 static void if_nbr_ipv6ll_to_ipv4ll_neigh_add_all(struct interface
*ifp
)
878 if (listhead(ifp
->nbr_connected
)) {
879 struct nbr_connected
*nbr_connected
;
880 struct listnode
*node
;
882 for (ALL_LIST_ELEMENTS_RO(ifp
->nbr_connected
, node
,
884 if_nbr_ipv6ll_to_ipv4ll_neigh_update(
885 ifp
, &nbr_connected
->address
->u
.prefix6
, 1);
889 void if_nbr_ipv6ll_to_ipv4ll_neigh_del_all(struct interface
*ifp
)
891 if (listhead(ifp
->nbr_connected
)) {
892 struct nbr_connected
*nbr_connected
;
893 struct listnode
*node
;
895 for (ALL_LIST_ELEMENTS_RO(ifp
->nbr_connected
, node
,
897 if_nbr_ipv6ll_to_ipv4ll_neigh_update(
898 ifp
, &nbr_connected
->address
->u
.prefix6
, 0);
902 static void if_down_del_nbr_connected(struct interface
*ifp
)
904 struct nbr_connected
*nbr_connected
;
905 struct listnode
*node
, *nnode
;
907 for (ALL_LIST_ELEMENTS(ifp
->nbr_connected
, node
, nnode
,
909 listnode_delete(ifp
->nbr_connected
, nbr_connected
);
910 nbr_connected_free(nbr_connected
);
914 /* Interface is up. */
915 void if_up(struct interface
*ifp
)
917 struct zebra_if
*zif
;
918 struct interface
*link_if
;
919 struct zebra_vrf
*zvrf
= vrf_info_lookup(ifp
->vrf_id
);
923 quagga_timestamp(2, zif
->up_last
, sizeof(zif
->up_last
));
925 /* Notify the protocol daemons. */
926 if (ifp
->ptm_enable
&& (ifp
->ptm_status
== ZEBRA_PTM_STATUS_DOWN
)) {
927 flog_warn(EC_ZEBRA_PTM_NOT_READY
,
928 "%s: interface %s hasn't passed ptm check\n",
929 __func__
, ifp
->name
);
932 zebra_interface_up_update(ifp
);
934 if_nbr_ipv6ll_to_ipv4ll_neigh_add_all(ifp
);
936 #if defined(HAVE_RTADV)
937 /* Enable fast tx of RA if enabled && RA interval is not in msecs */
938 if (zif
->rtadv
.AdvSendAdvertisements
939 && (zif
->rtadv
.MaxRtrAdvInterval
>= 1000)) {
940 zif
->rtadv
.inFastRexmit
= 1;
941 zif
->rtadv
.NumFastReXmitsRemain
= RTADV_NUM_FAST_REXMITS
;
945 /* Install connected routes to the kernel. */
946 if_install_connected(ifp
);
948 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
949 zlog_debug("%u: IF %s up, scheduling RIB processing",
950 ifp
->vrf_id
, ifp
->name
);
951 rib_update(ifp
->vrf_id
, RIB_UPDATE_IF_CHANGE
);
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 (IS_ZEBRA_DEBUG_RIB_DETAILED
)
1007 zlog_debug("%u: IF %s down, scheduling RIB processing",
1008 ifp
->vrf_id
, ifp
->name
);
1009 rib_update(ifp
->vrf_id
, RIB_UPDATE_IF_CHANGE
);
1011 if_nbr_ipv6ll_to_ipv4ll_neigh_del_all(ifp
);
1013 /* Delete all neighbor addresses learnt through IPv6 RA */
1014 if_down_del_nbr_connected(ifp
);
1017 void if_refresh(struct interface
*ifp
)
1022 void zebra_if_update_link(struct interface
*ifp
, ifindex_t link_ifindex
,
1025 struct zebra_if
*zif
;
1027 if (IS_ZEBRA_IF_VETH(ifp
))
1029 zif
= (struct zebra_if
*)ifp
->info
;
1030 zif
->link_ifindex
= link_ifindex
;
1031 zif
->link
= if_lookup_by_index_per_ns(zebra_ns_lookup(ns_id
),
1036 * during initial link dump kernel does not order lower devices before
1037 * upper devices so we need to fixup link dependencies at the end of dump
1039 void zebra_if_update_all_links(void)
1041 struct route_node
*rn
;
1042 struct interface
*ifp
;
1043 struct zebra_if
*zif
;
1044 struct zebra_ns
*ns
;
1046 if (IS_ZEBRA_DEBUG_KERNEL
)
1047 zlog_info("fixup link dependencies");
1049 ns
= zebra_ns_lookup(NS_DEFAULT
);
1050 for (rn
= route_top(ns
->if_table
); rn
; rn
= route_next(rn
)) {
1051 ifp
= (struct interface
*)rn
->info
;
1055 if ((zif
->link_ifindex
!= IFINDEX_INTERNAL
) && !zif
->link
) {
1056 zif
->link
= if_lookup_by_index_per_ns(ns
,
1058 if (IS_ZEBRA_DEBUG_KERNEL
)
1059 zlog_debug("interface %s/%d's lower fixup to %s/%d",
1060 ifp
->name
, ifp
->ifindex
,
1061 zif
->link
?zif
->link
->name
:"unk",
1069 /* Output prefix string to vty. */
1070 static int prefix_vty_out(struct vty
*vty
, struct prefix
*p
)
1072 char str
[INET6_ADDRSTRLEN
];
1074 inet_ntop(p
->family
, &p
->u
.prefix
, str
, sizeof(str
));
1075 vty_out(vty
, "%s", str
);
1079 /* Dump if address information to vty. */
1080 static void connected_dump_vty(struct vty
*vty
, struct connected
*connected
)
1084 /* Print interface address. */
1085 p
= connected
->address
;
1086 vty_out(vty
, " %s ", prefix_family_str(p
));
1087 prefix_vty_out(vty
, p
);
1088 vty_out(vty
, "/%d", p
->prefixlen
);
1090 /* If there is destination address, print it. */
1091 if (connected
->destination
) {
1093 (CONNECTED_PEER(connected
) ? " peer " : " broadcast "));
1094 prefix_vty_out(vty
, connected
->destination
);
1095 if (CONNECTED_PEER(connected
))
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
:
1159 /* Interface's information print out to vty interface. */
1160 static void if_dump_vty(struct vty
*vty
, struct interface
*ifp
)
1162 struct connected
*connected
;
1163 struct nbr_connected
*nbr_connected
;
1164 struct listnode
*node
;
1165 struct route_node
*rn
;
1166 struct zebra_if
*zebra_if
;
1169 zebra_if
= ifp
->info
;
1171 vty_out(vty
, "Interface %s is ", ifp
->name
);
1172 if (if_is_up(ifp
)) {
1173 vty_out(vty
, "up, line protocol ");
1175 if (CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_LINKDETECTION
)) {
1176 if (if_is_running(ifp
))
1177 vty_out(vty
, "is up\n");
1179 vty_out(vty
, "is down\n");
1181 vty_out(vty
, "detection is disabled\n");
1184 vty_out(vty
, "down\n");
1187 vty_out(vty
, " Link ups: %5u last: %s\n", zebra_if
->up_count
,
1188 zebra_if
->up_last
[0] ? zebra_if
->up_last
: "(never)");
1189 vty_out(vty
, " Link downs: %5u last: %s\n", zebra_if
->down_count
,
1190 zebra_if
->down_last
[0] ? zebra_if
->down_last
: "(never)");
1192 zebra_ptm_show_status(vty
, ifp
);
1194 vrf
= vrf_lookup_by_id(ifp
->vrf_id
);
1195 vty_out(vty
, " vrf: %s\n", vrf
->name
);
1198 vty_out(vty
, " Description: %s\n", ifp
->desc
);
1199 if (ifp
->ifindex
== IFINDEX_INTERNAL
) {
1200 vty_out(vty
, " pseudo interface\n");
1202 } else if (!CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
)) {
1203 vty_out(vty
, " index %d inactive interface\n", ifp
->ifindex
);
1207 vty_out(vty
, " index %d metric %d mtu %d speed %u ", ifp
->ifindex
,
1208 ifp
->metric
, ifp
->mtu
, ifp
->speed
);
1209 if (ifp
->mtu6
!= ifp
->mtu
)
1210 vty_out(vty
, "mtu6 %d ", ifp
->mtu6
);
1211 vty_out(vty
, "\n flags: %s\n", if_flag_dump(ifp
->flags
));
1213 /* Hardware address. */
1214 vty_out(vty
, " Type: %s\n", if_link_type_str(ifp
->ll_type
));
1215 if (ifp
->hw_addr_len
!= 0) {
1218 vty_out(vty
, " HWaddr: ");
1219 for (i
= 0; i
< ifp
->hw_addr_len
; i
++)
1220 vty_out(vty
, "%s%02x", i
== 0 ? "" : ":",
1225 /* Bandwidth in Mbps */
1226 if (ifp
->bandwidth
!= 0) {
1227 vty_out(vty
, " bandwidth %u Mbps", ifp
->bandwidth
);
1231 for (rn
= route_top(zebra_if
->ipv4_subnets
); rn
; rn
= route_next(rn
)) {
1235 for (ALL_LIST_ELEMENTS_RO((struct list
*)rn
->info
, node
,
1237 connected_dump_vty(vty
, connected
);
1240 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, node
, connected
)) {
1241 if (CHECK_FLAG(connected
->conf
, ZEBRA_IFC_REAL
)
1242 && (connected
->address
->family
== AF_INET6
))
1243 connected_dump_vty(vty
, connected
);
1246 vty_out(vty
, " Interface Type %s\n",
1247 zebra_ziftype_2str(zebra_if
->zif_type
));
1248 if (IS_ZEBRA_IF_BRIDGE(ifp
)) {
1249 struct zebra_l2info_bridge
*bridge_info
;
1251 bridge_info
= &zebra_if
->l2info
.br
;
1252 vty_out(vty
, " Bridge VLAN-aware: %s\n",
1253 bridge_info
->vlan_aware
? "yes" : "no");
1254 } else if (IS_ZEBRA_IF_VLAN(ifp
)) {
1255 struct zebra_l2info_vlan
*vlan_info
;
1257 vlan_info
= &zebra_if
->l2info
.vl
;
1258 vty_out(vty
, " VLAN Id %u\n", vlan_info
->vid
);
1259 } else if (IS_ZEBRA_IF_VXLAN(ifp
)) {
1260 struct zebra_l2info_vxlan
*vxlan_info
;
1262 vxlan_info
= &zebra_if
->l2info
.vxl
;
1263 vty_out(vty
, " VxLAN Id %u", vxlan_info
->vni
);
1264 if (vxlan_info
->vtep_ip
.s_addr
!= INADDR_ANY
)
1265 vty_out(vty
, " VTEP IP: %s",
1266 inet_ntoa(vxlan_info
->vtep_ip
));
1267 if (vxlan_info
->access_vlan
)
1268 vty_out(vty
, " Access VLAN Id %u",
1269 vxlan_info
->access_vlan
);
1273 if (IS_ZEBRA_IF_BRIDGE_SLAVE(ifp
)) {
1274 struct zebra_l2info_brslave
*br_slave
;
1276 br_slave
= &zebra_if
->brslave_info
;
1277 if (br_slave
->bridge_ifindex
!= IFINDEX_INTERNAL
)
1278 vty_out(vty
, " Master (bridge) ifindex %u\n",
1279 br_slave
->bridge_ifindex
);
1282 if (zebra_if
->link_ifindex
!= IFINDEX_INTERNAL
) {
1283 vty_out(vty
, " Link ifindex %u", zebra_if
->link_ifindex
);
1285 vty_out(vty
, "(%s)\n", zebra_if
->link
->name
);
1287 vty_out(vty
, "(Unknown)\n");
1290 if (HAS_LINK_PARAMS(ifp
)) {
1292 struct if_link_params
*iflp
= ifp
->link_params
;
1293 vty_out(vty
, " Traffic Engineering Link Parameters:\n");
1294 if (IS_PARAM_SET(iflp
, LP_TE_METRIC
))
1295 vty_out(vty
, " TE metric %u\n", iflp
->te_metric
);
1296 if (IS_PARAM_SET(iflp
, LP_MAX_BW
))
1297 vty_out(vty
, " Maximum Bandwidth %g (Byte/s)\n",
1299 if (IS_PARAM_SET(iflp
, LP_MAX_RSV_BW
))
1301 " Maximum Reservable Bandwidth %g (Byte/s)\n",
1303 if (IS_PARAM_SET(iflp
, LP_UNRSV_BW
)) {
1305 " Unreserved Bandwidth per Class Type in Byte/s:\n");
1306 for (i
= 0; i
< MAX_CLASS_TYPE
; i
+= 2)
1308 " [%d]: %g (Bytes/sec),\t[%d]: %g (Bytes/sec)\n",
1309 i
, iflp
->unrsv_bw
[i
], i
+ 1,
1310 iflp
->unrsv_bw
[i
+ 1]);
1313 if (IS_PARAM_SET(iflp
, LP_ADM_GRP
))
1314 vty_out(vty
, " Administrative Group:%u\n",
1316 if (IS_PARAM_SET(iflp
, LP_DELAY
)) {
1317 vty_out(vty
, " Link Delay Average: %u (micro-sec.)",
1319 if (IS_PARAM_SET(iflp
, LP_MM_DELAY
)) {
1320 vty_out(vty
, " Min: %u (micro-sec.)",
1322 vty_out(vty
, " Max: %u (micro-sec.)",
1327 if (IS_PARAM_SET(iflp
, LP_DELAY_VAR
))
1329 " Link Delay Variation %u (micro-sec.)\n",
1331 if (IS_PARAM_SET(iflp
, LP_PKT_LOSS
))
1332 vty_out(vty
, " Link Packet Loss %g (in %%)\n",
1334 if (IS_PARAM_SET(iflp
, LP_AVA_BW
))
1335 vty_out(vty
, " Available Bandwidth %g (Byte/s)\n",
1337 if (IS_PARAM_SET(iflp
, LP_RES_BW
))
1338 vty_out(vty
, " Residual Bandwidth %g (Byte/s)\n",
1340 if (IS_PARAM_SET(iflp
, LP_USE_BW
))
1341 vty_out(vty
, " Utilized Bandwidth %g (Byte/s)\n",
1343 if (IS_PARAM_SET(iflp
, LP_RMT_AS
))
1344 vty_out(vty
, " Neighbor ASBR IP: %s AS: %u \n",
1345 inet_ntoa(iflp
->rmt_ip
), iflp
->rmt_as
);
1348 hook_call(zebra_if_extra_info
, vty
, ifp
);
1350 if (listhead(ifp
->nbr_connected
))
1351 vty_out(vty
, " Neighbor address(s):\n");
1352 for (ALL_LIST_ELEMENTS_RO(ifp
->nbr_connected
, node
, nbr_connected
))
1353 nbr_connected_dump_vty(vty
, nbr_connected
);
1355 #ifdef HAVE_PROC_NET_DEV
1356 /* Statistics print out using proc file system. */
1358 " %lu input packets (%lu multicast), %lu bytes, "
1360 ifp
->stats
.rx_packets
, ifp
->stats
.rx_multicast
,
1361 ifp
->stats
.rx_bytes
, ifp
->stats
.rx_dropped
);
1364 " %lu input errors, %lu length, %lu overrun,"
1365 " %lu CRC, %lu frame\n",
1366 ifp
->stats
.rx_errors
, ifp
->stats
.rx_length_errors
,
1367 ifp
->stats
.rx_over_errors
, ifp
->stats
.rx_crc_errors
,
1368 ifp
->stats
.rx_frame_errors
);
1370 vty_out(vty
, " %lu fifo, %lu missed\n", ifp
->stats
.rx_fifo_errors
,
1371 ifp
->stats
.rx_missed_errors
);
1373 vty_out(vty
, " %lu output packets, %lu bytes, %lu dropped\n",
1374 ifp
->stats
.tx_packets
, ifp
->stats
.tx_bytes
,
1375 ifp
->stats
.tx_dropped
);
1378 " %lu output errors, %lu aborted, %lu carrier,"
1379 " %lu fifo, %lu heartbeat\n",
1380 ifp
->stats
.tx_errors
, ifp
->stats
.tx_aborted_errors
,
1381 ifp
->stats
.tx_carrier_errors
, ifp
->stats
.tx_fifo_errors
,
1382 ifp
->stats
.tx_heartbeat_errors
);
1384 vty_out(vty
, " %lu window, %lu collisions\n",
1385 ifp
->stats
.tx_window_errors
, ifp
->stats
.collisions
);
1386 #endif /* HAVE_PROC_NET_DEV */
1388 #ifdef HAVE_NET_RT_IFLIST
1389 #if defined(__bsdi__) || defined(__NetBSD__)
1390 /* Statistics print out using sysctl (). */
1392 " input packets %llu, bytes %llu, dropped %llu,"
1393 " multicast packets %llu\n",
1394 (unsigned long long)ifp
->stats
.ifi_ipackets
,
1395 (unsigned long long)ifp
->stats
.ifi_ibytes
,
1396 (unsigned long long)ifp
->stats
.ifi_iqdrops
,
1397 (unsigned long long)ifp
->stats
.ifi_imcasts
);
1399 vty_out(vty
, " input errors %llu\n",
1400 (unsigned long long)ifp
->stats
.ifi_ierrors
);
1403 " output packets %llu, bytes %llu,"
1404 " multicast packets %llu\n",
1405 (unsigned long long)ifp
->stats
.ifi_opackets
,
1406 (unsigned long long)ifp
->stats
.ifi_obytes
,
1407 (unsigned long long)ifp
->stats
.ifi_omcasts
);
1409 vty_out(vty
, " output errors %llu\n",
1410 (unsigned long long)ifp
->stats
.ifi_oerrors
);
1412 vty_out(vty
, " collisions %llu\n",
1413 (unsigned long long)ifp
->stats
.ifi_collisions
);
1415 /* Statistics print out using sysctl (). */
1417 " input packets %lu, bytes %lu, dropped %lu,"
1418 " multicast packets %lu\n",
1419 ifp
->stats
.ifi_ipackets
, ifp
->stats
.ifi_ibytes
,
1420 ifp
->stats
.ifi_iqdrops
, ifp
->stats
.ifi_imcasts
);
1422 vty_out(vty
, " input errors %lu\n", ifp
->stats
.ifi_ierrors
);
1425 " output packets %lu, bytes %lu, multicast packets %lu\n",
1426 ifp
->stats
.ifi_opackets
, ifp
->stats
.ifi_obytes
,
1427 ifp
->stats
.ifi_omcasts
);
1429 vty_out(vty
, " output errors %lu\n", ifp
->stats
.ifi_oerrors
);
1431 vty_out(vty
, " collisions %lu\n", ifp
->stats
.ifi_collisions
);
1432 #endif /* __bsdi__ || __NetBSD__ */
1433 #endif /* HAVE_NET_RT_IFLIST */
1436 static void interface_update_stats(void)
1438 #ifdef HAVE_PROC_NET_DEV
1439 /* If system has interface statistics via proc file system, update
1441 ifstat_update_proc();
1442 #endif /* HAVE_PROC_NET_DEV */
1443 #ifdef HAVE_NET_RT_IFLIST
1444 ifstat_update_sysctl();
1445 #endif /* HAVE_NET_RT_IFLIST */
1448 struct cmd_node interface_node
= {INTERFACE_NODE
, "%s(config-if)# ", 1};
1450 /* Show all interfaces to vty. */
1451 DEFUN (show_interface
,
1453 "show interface [vrf NAME]",
1455 "Interface status and configuration\n"
1459 struct interface
*ifp
;
1460 vrf_id_t vrf_id
= VRF_DEFAULT
;
1462 interface_update_stats();
1465 VRF_GET_ID(vrf_id
, argv
[3]->arg
, false);
1467 /* All interface print. */
1468 vrf
= vrf_lookup_by_id(vrf_id
);
1469 FOR_ALL_INTERFACES (vrf
, ifp
)
1470 if_dump_vty(vty
, ifp
);
1476 /* Show all interfaces to vty. */
1477 DEFUN (show_interface_vrf_all
,
1478 show_interface_vrf_all_cmd
,
1479 "show interface vrf all",
1481 "Interface status and configuration\n"
1482 VRF_ALL_CMD_HELP_STR
)
1485 struct interface
*ifp
;
1487 interface_update_stats();
1489 /* All interface print. */
1490 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
1491 FOR_ALL_INTERFACES (vrf
, ifp
)
1492 if_dump_vty(vty
, ifp
);
1497 /* Show specified interface to vty. */
1499 DEFUN (show_interface_name_vrf
,
1500 show_interface_name_vrf_cmd
,
1501 "show interface IFNAME vrf NAME",
1503 "Interface status and configuration\n"
1509 struct interface
*ifp
;
1512 interface_update_stats();
1514 VRF_GET_ID(vrf_id
, argv
[idx_name
]->arg
, false);
1516 /* Specified interface print. */
1517 ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
, vrf_id
);
1519 vty_out(vty
, "%% Can't find interface %s\n",
1520 argv
[idx_ifname
]->arg
);
1523 if_dump_vty(vty
, ifp
);
1528 /* Show specified interface to vty. */
1529 DEFUN (show_interface_name_vrf_all
,
1530 show_interface_name_vrf_all_cmd
,
1531 "show interface IFNAME [vrf all]",
1533 "Interface status and configuration\n"
1535 VRF_ALL_CMD_HELP_STR
)
1539 struct interface
*ifp
;
1542 interface_update_stats();
1544 /* All interface print. */
1545 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
1546 /* Specified interface print. */
1547 ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
, vrf
->vrf_id
);
1549 if_dump_vty(vty
, ifp
);
1555 vty_out(vty
, "%% Can't find interface %s\n",
1556 argv
[idx_ifname
]->arg
);
1564 static void if_show_description(struct vty
*vty
, vrf_id_t vrf_id
)
1566 struct vrf
*vrf
= vrf_lookup_by_id(vrf_id
);
1567 struct interface
*ifp
;
1569 vty_out(vty
, "Interface Status Protocol Description\n");
1570 FOR_ALL_INTERFACES (vrf
, ifp
) {
1573 len
= vty_out(vty
, "%s", ifp
->name
);
1574 vty_out(vty
, "%*s", (16 - len
), " ");
1576 if (if_is_up(ifp
)) {
1577 vty_out(vty
, "up ");
1578 if (CHECK_FLAG(ifp
->status
,
1579 ZEBRA_INTERFACE_LINKDETECTION
)) {
1580 if (if_is_running(ifp
))
1581 vty_out(vty
, "up ");
1583 vty_out(vty
, "down ");
1585 vty_out(vty
, "unknown ");
1588 vty_out(vty
, "down down ");
1592 vty_out(vty
, "%s", ifp
->desc
);
1597 DEFUN (show_interface_desc
,
1598 show_interface_desc_cmd
,
1599 "show interface description [vrf NAME]",
1601 "Interface status and configuration\n"
1602 "Interface description\n"
1605 vrf_id_t vrf_id
= VRF_DEFAULT
;
1608 VRF_GET_ID(vrf_id
, argv
[4]->arg
, false);
1610 if_show_description(vty
, vrf_id
);
1616 DEFUN (show_interface_desc_vrf_all
,
1617 show_interface_desc_vrf_all_cmd
,
1618 "show interface description vrf all",
1620 "Interface status and configuration\n"
1621 "Interface description\n"
1622 VRF_ALL_CMD_HELP_STR
)
1626 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
1627 if (!RB_EMPTY(if_name_head
, &vrf
->ifaces_by_name
)) {
1628 vty_out(vty
, "\n\tVRF %u\n\n", vrf
->vrf_id
);
1629 if_show_description(vty
, vrf
->vrf_id
);
1638 "Set multicast flag to interface\n")
1640 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1642 struct zebra_if
*if_data
;
1644 if (CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
)) {
1645 ret
= if_set_flags(ifp
, IFF_MULTICAST
);
1647 vty_out(vty
, "Can't set multicast flag\n");
1648 return CMD_WARNING_CONFIG_FAILED
;
1652 if_data
= ifp
->info
;
1653 if_data
->multicast
= IF_ZEBRA_MULTICAST_ON
;
1658 DEFUN (no_multicast
,
1662 "Unset multicast flag to interface\n")
1664 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1666 struct zebra_if
*if_data
;
1668 if (CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
)) {
1669 ret
= if_unset_flags(ifp
, IFF_MULTICAST
);
1671 vty_out(vty
, "Can't unset multicast flag\n");
1672 return CMD_WARNING_CONFIG_FAILED
;
1676 if_data
= ifp
->info
;
1677 if_data
->multicast
= IF_ZEBRA_MULTICAST_OFF
;
1685 "Enable link detection on interface\n")
1687 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1688 int if_was_operative
;
1690 if_was_operative
= if_is_no_ptm_operative(ifp
);
1691 SET_FLAG(ifp
->status
, ZEBRA_INTERFACE_LINKDETECTION
);
1693 /* When linkdetection is enabled, if might come down */
1694 if (!if_is_no_ptm_operative(ifp
) && if_was_operative
)
1697 /* FIXME: Will defer status change forwarding if interface
1698 does not come down! */
1704 DEFUN (no_linkdetect
,
1708 "Disable link detection on interface\n")
1710 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1711 int if_was_operative
;
1713 if_was_operative
= if_is_no_ptm_operative(ifp
);
1714 UNSET_FLAG(ifp
->status
, ZEBRA_INTERFACE_LINKDETECTION
);
1716 /* Interface may come up after disabling link detection */
1717 if (if_is_operative(ifp
) && !if_was_operative
)
1720 /* FIXME: see linkdetect_cmd */
1728 "Shutdown the selected interface\n")
1730 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1732 struct zebra_if
*if_data
;
1734 if (ifp
->ifindex
!= IFINDEX_INTERNAL
) {
1735 ret
= if_unset_flags(ifp
, IFF_UP
);
1737 vty_out(vty
, "Can't shutdown interface\n");
1738 return CMD_WARNING_CONFIG_FAILED
;
1742 if_data
= ifp
->info
;
1743 if_data
->shutdown
= IF_ZEBRA_SHUTDOWN_ON
;
1748 DEFUN (no_shutdown_if
,
1752 "Shutdown the selected interface\n")
1754 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1756 struct zebra_if
*if_data
;
1758 if (ifp
->ifindex
!= IFINDEX_INTERNAL
) {
1759 ret
= if_set_flags(ifp
, IFF_UP
| IFF_RUNNING
);
1761 vty_out(vty
, "Can't up interface\n");
1762 return CMD_WARNING_CONFIG_FAILED
;
1766 /* Some addresses (in particular, IPv6 addresses on Linux) get
1767 * removed when the interface goes down. They need to be
1770 if_addr_wakeup(ifp
);
1773 if_data
= ifp
->info
;
1774 if_data
->shutdown
= IF_ZEBRA_SHUTDOWN_OFF
;
1779 DEFUN (bandwidth_if
,
1781 "bandwidth (1-100000)",
1782 "Set bandwidth informational parameter\n"
1783 "Bandwidth in megabits\n")
1786 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1787 unsigned int bandwidth
;
1789 bandwidth
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
1791 /* bandwidth range is <1-100000> */
1792 if (bandwidth
< 1 || bandwidth
> 100000) {
1793 vty_out(vty
, "Bandwidth is invalid\n");
1794 return CMD_WARNING_CONFIG_FAILED
;
1797 ifp
->bandwidth
= bandwidth
;
1799 /* force protocols to recalculate routes due to cost change */
1800 if (if_is_operative(ifp
))
1801 zebra_interface_up_update(ifp
);
1806 DEFUN (no_bandwidth_if
,
1807 no_bandwidth_if_cmd
,
1808 "no bandwidth [(1-100000)]",
1810 "Set bandwidth informational parameter\n"
1811 "Bandwidth in megabits\n")
1813 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1817 /* force protocols to recalculate routes due to cost change */
1818 if (if_is_operative(ifp
))
1819 zebra_interface_up_update(ifp
);
1825 struct cmd_node link_params_node
= {
1826 LINK_PARAMS_NODE
, "%s(config-link-params)# ", 1,
1829 static void link_param_cmd_set_uint32(struct interface
*ifp
, uint32_t *field
,
1830 uint32_t type
, uint32_t value
)
1832 /* Update field as needed */
1833 if (IS_PARAM_UNSET(ifp
->link_params
, type
) || *field
!= value
) {
1835 SET_PARAM(ifp
->link_params
, type
);
1837 /* force protocols to update LINK STATE due to parameters change
1839 if (if_is_operative(ifp
))
1840 zebra_interface_parameters_update(ifp
);
1843 static void link_param_cmd_set_float(struct interface
*ifp
, float *field
,
1844 uint32_t type
, float value
)
1847 /* Update field as needed */
1848 if (IS_PARAM_UNSET(ifp
->link_params
, type
) || *field
!= value
) {
1850 SET_PARAM(ifp
->link_params
, type
);
1852 /* force protocols to update LINK STATE due to parameters change
1854 if (if_is_operative(ifp
))
1855 zebra_interface_parameters_update(ifp
);
1859 static void link_param_cmd_unset(struct interface
*ifp
, uint32_t type
)
1861 if (ifp
->link_params
== NULL
)
1865 UNSET_PARAM(ifp
->link_params
, type
);
1867 /* force protocols to update LINK STATE due to parameters change */
1868 if (if_is_operative(ifp
))
1869 zebra_interface_parameters_update(ifp
);
1872 DEFUN_NOSH (link_params
,
1877 /* vty->qobj_index stays the same @ interface pointer */
1878 vty
->node
= LINK_PARAMS_NODE
;
1883 DEFUN_NOSH (exit_link_params
,
1884 exit_link_params_cmd
,
1886 "Exit from Link Params configuration mode\n")
1888 if (vty
->node
== LINK_PARAMS_NODE
)
1889 vty
->node
= INTERFACE_NODE
;
1893 /* Specific Traffic Engineering parameters commands */
1894 DEFUN (link_params_enable
,
1895 link_params_enable_cmd
,
1897 "Activate link parameters on this interface\n")
1899 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1901 /* This command could be issue at startup, when activate MPLS TE */
1902 /* on a new interface or after a ON / OFF / ON toggle */
1903 /* In all case, TE parameters are reset to their default factory */
1904 if (IS_ZEBRA_DEBUG_EVENT
)
1906 "Link-params: enable TE link parameters on interface %s",
1909 if (!if_link_params_get(ifp
)) {
1910 if (IS_ZEBRA_DEBUG_EVENT
)
1912 "Link-params: failed to init TE link parameters %s",
1915 return CMD_WARNING_CONFIG_FAILED
;
1918 /* force protocols to update LINK STATE due to parameters change */
1919 if (if_is_operative(ifp
))
1920 zebra_interface_parameters_update(ifp
);
1925 DEFUN (no_link_params_enable
,
1926 no_link_params_enable_cmd
,
1929 "Disable link parameters on this interface\n")
1931 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1933 zlog_debug("MPLS-TE: disable TE link parameters on interface %s",
1936 if_link_params_free(ifp
);
1938 /* force protocols to update LINK STATE due to parameters change */
1939 if (if_is_operative(ifp
))
1940 zebra_interface_parameters_update(ifp
);
1945 /* STANDARD TE metrics */
1946 DEFUN (link_params_metric
,
1947 link_params_metric_cmd
,
1948 "metric (0-4294967295)",
1949 "Link metric for MPLS-TE purpose\n"
1950 "Metric value in decimal\n")
1953 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1954 struct if_link_params
*iflp
= if_link_params_get(ifp
);
1957 metric
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1959 /* Update TE metric if needed */
1960 link_param_cmd_set_uint32(ifp
, &iflp
->te_metric
, LP_TE_METRIC
, metric
);
1965 DEFUN (no_link_params_metric
,
1966 no_link_params_metric_cmd
,
1969 "Disable Link Metric on this interface\n")
1971 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1973 /* Unset TE Metric */
1974 link_param_cmd_unset(ifp
, LP_TE_METRIC
);
1979 DEFUN (link_params_maxbw
,
1980 link_params_maxbw_cmd
,
1982 "Maximum bandwidth that can be used\n"
1983 "Bytes/second (IEEE floating point format)\n")
1985 int idx_bandwidth
= 1;
1986 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1987 struct if_link_params
*iflp
= if_link_params_get(ifp
);
1991 if (sscanf(argv
[idx_bandwidth
]->arg
, "%g", &bw
) != 1) {
1992 vty_out(vty
, "link_params_maxbw: fscanf: %s\n",
1993 safe_strerror(errno
));
1994 return CMD_WARNING_CONFIG_FAILED
;
1997 /* Check that Maximum bandwidth is not lower than other bandwidth
1999 if ((bw
<= iflp
->max_rsv_bw
) || (bw
<= iflp
->unrsv_bw
[0])
2000 || (bw
<= iflp
->unrsv_bw
[1]) || (bw
<= iflp
->unrsv_bw
[2])
2001 || (bw
<= iflp
->unrsv_bw
[3]) || (bw
<= iflp
->unrsv_bw
[4])
2002 || (bw
<= iflp
->unrsv_bw
[5]) || (bw
<= iflp
->unrsv_bw
[6])
2003 || (bw
<= iflp
->unrsv_bw
[7]) || (bw
<= iflp
->ava_bw
)
2004 || (bw
<= iflp
->res_bw
) || (bw
<= iflp
->use_bw
)) {
2006 "Maximum Bandwidth could not be lower than others bandwidth\n");
2007 return CMD_WARNING_CONFIG_FAILED
;
2010 /* Update Maximum Bandwidth if needed */
2011 link_param_cmd_set_float(ifp
, &iflp
->max_bw
, LP_MAX_BW
, bw
);
2016 DEFUN (link_params_max_rsv_bw
,
2017 link_params_max_rsv_bw_cmd
,
2018 "max-rsv-bw BANDWIDTH",
2019 "Maximum bandwidth that may be reserved\n"
2020 "Bytes/second (IEEE floating point format)\n")
2022 int idx_bandwidth
= 1;
2023 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2024 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2027 if (sscanf(argv
[idx_bandwidth
]->arg
, "%g", &bw
) != 1) {
2028 vty_out(vty
, "link_params_max_rsv_bw: fscanf: %s\n",
2029 safe_strerror(errno
));
2030 return CMD_WARNING_CONFIG_FAILED
;
2033 /* Check that bandwidth is not greater than maximum bandwidth parameter
2035 if (bw
> iflp
->max_bw
) {
2037 "Maximum Reservable Bandwidth could not be greater than Maximum Bandwidth (%g)\n",
2039 return CMD_WARNING_CONFIG_FAILED
;
2042 /* Update Maximum Reservable Bandwidth if needed */
2043 link_param_cmd_set_float(ifp
, &iflp
->max_rsv_bw
, LP_MAX_RSV_BW
, bw
);
2048 DEFUN (link_params_unrsv_bw
,
2049 link_params_unrsv_bw_cmd
,
2050 "unrsv-bw (0-7) BANDWIDTH",
2051 "Unreserved bandwidth at each priority level\n"
2053 "Bytes/second (IEEE floating point format)\n")
2056 int idx_bandwidth
= 2;
2057 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2058 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2062 /* We don't have to consider about range check here. */
2063 if (sscanf(argv
[idx_number
]->arg
, "%d", &priority
) != 1) {
2064 vty_out(vty
, "link_params_unrsv_bw: fscanf: %s\n",
2065 safe_strerror(errno
));
2066 return CMD_WARNING_CONFIG_FAILED
;
2069 if (sscanf(argv
[idx_bandwidth
]->arg
, "%g", &bw
) != 1) {
2070 vty_out(vty
, "link_params_unrsv_bw: fscanf: %s\n",
2071 safe_strerror(errno
));
2072 return CMD_WARNING_CONFIG_FAILED
;
2075 /* Check that bandwidth is not greater than maximum bandwidth parameter
2077 if (bw
> iflp
->max_bw
) {
2079 "UnReserved Bandwidth could not be greater than Maximum Bandwidth (%g)\n",
2081 return CMD_WARNING_CONFIG_FAILED
;
2084 /* Update Unreserved Bandwidth if needed */
2085 link_param_cmd_set_float(ifp
, &iflp
->unrsv_bw
[priority
], LP_UNRSV_BW
,
2091 DEFUN (link_params_admin_grp
,
2092 link_params_admin_grp_cmd
,
2093 "admin-grp BITPATTERN",
2094 "Administrative group membership\n"
2095 "32-bit Hexadecimal value (e.g. 0xa1)\n")
2097 int idx_bitpattern
= 1;
2098 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2099 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2100 unsigned long value
;
2102 if (sscanf(argv
[idx_bitpattern
]->arg
, "0x%lx", &value
) != 1) {
2103 vty_out(vty
, "link_params_admin_grp: fscanf: %s\n",
2104 safe_strerror(errno
));
2105 return CMD_WARNING_CONFIG_FAILED
;
2108 /* Update Administrative Group if needed */
2109 link_param_cmd_set_uint32(ifp
, &iflp
->admin_grp
, LP_ADM_GRP
, value
);
2114 DEFUN (no_link_params_admin_grp
,
2115 no_link_params_admin_grp_cmd
,
2118 "Disable Administrative group membership on this interface\n")
2120 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2122 /* Unset Admin Group */
2123 link_param_cmd_unset(ifp
, LP_ADM_GRP
);
2128 /* RFC5392 & RFC5316: INTER-AS */
2129 DEFUN (link_params_inter_as
,
2130 link_params_inter_as_cmd
,
2131 "neighbor A.B.C.D as (1-4294967295)",
2132 "Configure remote ASBR information (Neighbor IP address and AS number)\n"
2133 "Remote IP address in dot decimal A.B.C.D\n"
2134 "Remote AS number\n"
2135 "AS number in the range <1-4294967295>\n")
2140 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2141 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2142 struct in_addr addr
;
2145 if (!inet_aton(argv
[idx_ipv4
]->arg
, &addr
)) {
2146 vty_out(vty
, "Please specify Router-Addr by A.B.C.D\n");
2147 return CMD_WARNING_CONFIG_FAILED
;
2150 as
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2152 /* Update Remote IP and Remote AS fields if needed */
2153 if (IS_PARAM_UNSET(iflp
, LP_RMT_AS
) || iflp
->rmt_as
!= as
2154 || iflp
->rmt_ip
.s_addr
!= addr
.s_addr
) {
2157 iflp
->rmt_ip
.s_addr
= addr
.s_addr
;
2158 SET_PARAM(iflp
, LP_RMT_AS
);
2160 /* force protocols to update LINK STATE due to parameters change
2162 if (if_is_operative(ifp
))
2163 zebra_interface_parameters_update(ifp
);
2168 DEFUN (no_link_params_inter_as
,
2169 no_link_params_inter_as_cmd
,
2172 "Remove Neighbor IP address and AS number for Inter-AS TE\n")
2174 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2175 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2177 /* Reset Remote IP and AS neighbor */
2179 iflp
->rmt_ip
.s_addr
= 0;
2180 UNSET_PARAM(iflp
, LP_RMT_AS
);
2182 /* force protocols to update LINK STATE due to parameters change */
2183 if (if_is_operative(ifp
))
2184 zebra_interface_parameters_update(ifp
);
2189 /* RFC7471: OSPF Traffic Engineering (TE) Metric extensions &
2190 * draft-ietf-isis-metric-extensions-07.txt */
2191 DEFUN (link_params_delay
,
2192 link_params_delay_cmd
,
2193 "delay (0-16777215) [min (0-16777215) max (0-16777215)]",
2194 "Unidirectional Average Link Delay\n"
2195 "Average delay in micro-second as decimal (0...16777215)\n"
2197 "Minimum delay in micro-second as decimal (0...16777215)\n"
2199 "Maximum delay in micro-second as decimal (0...16777215)\n")
2201 /* Get and Check new delay values */
2202 uint32_t delay
= 0, low
= 0, high
= 0;
2203 delay
= strtoul(argv
[1]->arg
, NULL
, 10);
2205 low
= strtoul(argv
[3]->arg
, NULL
, 10);
2206 high
= strtoul(argv
[5]->arg
, NULL
, 10);
2209 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2210 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2214 /* Check new delay value against old Min and Max delays if set
2216 if (IS_PARAM_SET(iflp
, LP_MM_DELAY
)
2217 && (delay
<= iflp
->min_delay
|| delay
>= iflp
->max_delay
)) {
2219 "Average delay should be comprise between Min (%d) and Max (%d) delay\n",
2220 iflp
->min_delay
, iflp
->max_delay
);
2221 return CMD_WARNING_CONFIG_FAILED
;
2223 /* Update delay if value is not set or change */
2224 if (IS_PARAM_UNSET(iflp
, LP_DELAY
) || iflp
->av_delay
!= delay
) {
2225 iflp
->av_delay
= delay
;
2226 SET_PARAM(iflp
, LP_DELAY
);
2229 /* Unset Min and Max delays if already set */
2230 if (IS_PARAM_SET(iflp
, LP_MM_DELAY
)) {
2231 iflp
->min_delay
= 0;
2232 iflp
->max_delay
= 0;
2233 UNSET_PARAM(iflp
, LP_MM_DELAY
);
2237 /* Check new delays value coherency */
2238 if (delay
<= low
|| delay
>= high
) {
2240 "Average delay should be comprise between Min (%d) and Max (%d) delay\n",
2242 return CMD_WARNING_CONFIG_FAILED
;
2244 /* Update Delays if needed */
2245 if (IS_PARAM_UNSET(iflp
, LP_DELAY
)
2246 || IS_PARAM_UNSET(iflp
, LP_MM_DELAY
)
2247 || iflp
->av_delay
!= delay
|| iflp
->min_delay
!= low
2248 || iflp
->max_delay
!= high
) {
2249 iflp
->av_delay
= delay
;
2250 SET_PARAM(iflp
, LP_DELAY
);
2251 iflp
->min_delay
= low
;
2252 iflp
->max_delay
= high
;
2253 SET_PARAM(iflp
, LP_MM_DELAY
);
2258 /* force protocols to update LINK STATE due to parameters change */
2259 if (update
== 1 && if_is_operative(ifp
))
2260 zebra_interface_parameters_update(ifp
);
2265 DEFUN (no_link_params_delay
,
2266 no_link_params_delay_cmd
,
2269 "Disable Unidirectional Average, Min & Max Link Delay on this interface\n")
2271 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2272 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2276 UNSET_PARAM(iflp
, LP_DELAY
);
2277 iflp
->min_delay
= 0;
2278 iflp
->max_delay
= 0;
2279 UNSET_PARAM(iflp
, LP_MM_DELAY
);
2281 /* force protocols to update LINK STATE due to parameters change */
2282 if (if_is_operative(ifp
))
2283 zebra_interface_parameters_update(ifp
);
2288 DEFUN (link_params_delay_var
,
2289 link_params_delay_var_cmd
,
2290 "delay-variation (0-16777215)",
2291 "Unidirectional Link Delay Variation\n"
2292 "delay variation in micro-second as decimal (0...16777215)\n")
2295 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2296 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2299 value
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2301 /* Update Delay Variation if needed */
2302 link_param_cmd_set_uint32(ifp
, &iflp
->delay_var
, LP_DELAY_VAR
, value
);
2307 DEFUN (no_link_params_delay_var
,
2308 no_link_params_delay_var_cmd
,
2309 "no delay-variation",
2311 "Disable Unidirectional Delay Variation on this interface\n")
2313 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2315 /* Unset Delay Variation */
2316 link_param_cmd_unset(ifp
, LP_DELAY_VAR
);
2321 DEFUN (link_params_pkt_loss
,
2322 link_params_pkt_loss_cmd
,
2323 "packet-loss PERCENTAGE",
2324 "Unidirectional Link Packet Loss\n"
2325 "percentage of total traffic by 0.000003% step and less than 50.331642%\n")
2327 int idx_percentage
= 1;
2328 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2329 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2332 if (sscanf(argv
[idx_percentage
]->arg
, "%g", &fval
) != 1) {
2333 vty_out(vty
, "link_params_pkt_loss: fscanf: %s\n",
2334 safe_strerror(errno
));
2335 return CMD_WARNING_CONFIG_FAILED
;
2338 if (fval
> MAX_PKT_LOSS
)
2339 fval
= MAX_PKT_LOSS
;
2341 /* Update Packet Loss if needed */
2342 link_param_cmd_set_float(ifp
, &iflp
->pkt_loss
, LP_PKT_LOSS
, fval
);
2347 DEFUN (no_link_params_pkt_loss
,
2348 no_link_params_pkt_loss_cmd
,
2351 "Disable Unidirectional Link Packet Loss on this interface\n")
2353 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2355 /* Unset Packet Loss */
2356 link_param_cmd_unset(ifp
, LP_PKT_LOSS
);
2361 DEFUN (link_params_res_bw
,
2362 link_params_res_bw_cmd
,
2364 "Unidirectional Residual Bandwidth\n"
2365 "Bytes/second (IEEE floating point format)\n")
2367 int idx_bandwidth
= 1;
2368 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2369 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2372 if (sscanf(argv
[idx_bandwidth
]->arg
, "%g", &bw
) != 1) {
2373 vty_out(vty
, "link_params_res_bw: fscanf: %s\n",
2374 safe_strerror(errno
));
2375 return CMD_WARNING_CONFIG_FAILED
;
2378 /* Check that bandwidth is not greater than maximum bandwidth parameter
2380 if (bw
> iflp
->max_bw
) {
2382 "Residual Bandwidth could not be greater than Maximum Bandwidth (%g)\n",
2384 return CMD_WARNING_CONFIG_FAILED
;
2387 /* Update Residual Bandwidth if needed */
2388 link_param_cmd_set_float(ifp
, &iflp
->res_bw
, LP_RES_BW
, bw
);
2393 DEFUN (no_link_params_res_bw
,
2394 no_link_params_res_bw_cmd
,
2397 "Disable Unidirectional Residual Bandwidth on this interface\n")
2399 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2401 /* Unset Residual Bandwidth */
2402 link_param_cmd_unset(ifp
, LP_RES_BW
);
2407 DEFUN (link_params_ava_bw
,
2408 link_params_ava_bw_cmd
,
2410 "Unidirectional Available Bandwidth\n"
2411 "Bytes/second (IEEE floating point format)\n")
2413 int idx_bandwidth
= 1;
2414 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2415 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2418 if (sscanf(argv
[idx_bandwidth
]->arg
, "%g", &bw
) != 1) {
2419 vty_out(vty
, "link_params_ava_bw: fscanf: %s\n",
2420 safe_strerror(errno
));
2421 return CMD_WARNING_CONFIG_FAILED
;
2424 /* Check that bandwidth is not greater than maximum bandwidth parameter
2426 if (bw
> iflp
->max_bw
) {
2428 "Available Bandwidth could not be greater than Maximum Bandwidth (%g)\n",
2430 return CMD_WARNING_CONFIG_FAILED
;
2433 /* Update Residual Bandwidth if needed */
2434 link_param_cmd_set_float(ifp
, &iflp
->ava_bw
, LP_AVA_BW
, bw
);
2439 DEFUN (no_link_params_ava_bw
,
2440 no_link_params_ava_bw_cmd
,
2443 "Disable Unidirectional Available Bandwidth on this interface\n")
2445 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2447 /* Unset Available Bandwidth */
2448 link_param_cmd_unset(ifp
, LP_AVA_BW
);
2453 DEFUN (link_params_use_bw
,
2454 link_params_use_bw_cmd
,
2456 "Unidirectional Utilised Bandwidth\n"
2457 "Bytes/second (IEEE floating point format)\n")
2459 int idx_bandwidth
= 1;
2460 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2461 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2464 if (sscanf(argv
[idx_bandwidth
]->arg
, "%g", &bw
) != 1) {
2465 vty_out(vty
, "link_params_use_bw: fscanf: %s\n",
2466 safe_strerror(errno
));
2467 return CMD_WARNING_CONFIG_FAILED
;
2470 /* Check that bandwidth is not greater than maximum bandwidth parameter
2472 if (bw
> iflp
->max_bw
) {
2474 "Utilised Bandwidth could not be greater than Maximum Bandwidth (%g)\n",
2476 return CMD_WARNING_CONFIG_FAILED
;
2479 /* Update Utilized Bandwidth if needed */
2480 link_param_cmd_set_float(ifp
, &iflp
->use_bw
, LP_USE_BW
, bw
);
2485 DEFUN (no_link_params_use_bw
,
2486 no_link_params_use_bw_cmd
,
2489 "Disable Unidirectional Utilised Bandwidth on this interface\n")
2491 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2493 /* Unset Utilised Bandwidth */
2494 link_param_cmd_unset(ifp
, LP_USE_BW
);
2499 static int ip_address_install(struct vty
*vty
, struct interface
*ifp
,
2500 const char *addr_str
, const char *peer_str
,
2503 struct zebra_if
*if_data
;
2504 struct prefix_ipv4 lp
, pp
;
2505 struct connected
*ifc
;
2506 struct prefix_ipv4
*p
;
2509 if_data
= ifp
->info
;
2511 ret
= str2prefix_ipv4(addr_str
, &lp
);
2513 vty_out(vty
, "%% Malformed address \n");
2514 return CMD_WARNING_CONFIG_FAILED
;
2517 if (ipv4_martian(&lp
.prefix
)) {
2518 vty_out(vty
, "%% Invalid address\n");
2519 return CMD_WARNING_CONFIG_FAILED
;
2523 if (lp
.prefixlen
!= 32) {
2525 "%% Local prefix length for P-t-P address must be /32\n");
2526 return CMD_WARNING_CONFIG_FAILED
;
2529 ret
= str2prefix_ipv4(peer_str
, &pp
);
2531 vty_out(vty
, "%% Malformed peer address\n");
2532 return CMD_WARNING_CONFIG_FAILED
;
2536 ifc
= connected_check_ptp(ifp
, &lp
, peer_str
? &pp
: NULL
);
2538 ifc
= connected_new();
2542 p
= prefix_ipv4_new();
2544 ifc
->address
= (struct prefix
*)p
;
2547 SET_FLAG(ifc
->flags
, ZEBRA_IFA_PEER
);
2548 p
= prefix_ipv4_new();
2550 ifc
->destination
= (struct prefix
*)p
;
2551 } else if (p
->prefixlen
<= IPV4_MAX_PREFIXLEN
- 2) {
2552 p
= prefix_ipv4_new();
2554 p
->prefix
.s_addr
= ipv4_broadcast_addr(p
->prefix
.s_addr
,
2556 ifc
->destination
= (struct prefix
*)p
;
2561 ifc
->label
= XSTRDUP(MTYPE_CONNECTED_LABEL
, label
);
2563 /* Add to linked list. */
2564 listnode_add(ifp
->connected
, ifc
);
2567 /* This address is configured from zebra. */
2568 if (!CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
2569 SET_FLAG(ifc
->conf
, ZEBRA_IFC_CONFIGURED
);
2571 /* In case of this route need to install kernel. */
2572 if (!CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
)
2573 && CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
)
2574 && !(if_data
&& if_data
->shutdown
== IF_ZEBRA_SHUTDOWN_ON
)) {
2575 /* Some system need to up the interface to set IP address. */
2576 if (!if_is_up(ifp
)) {
2577 if_set_flags(ifp
, IFF_UP
| IFF_RUNNING
);
2581 ret
= if_set_prefix(ifp
, ifc
);
2583 vty_out(vty
, "%% Can't set interface IP address: %s.\n",
2584 safe_strerror(errno
));
2585 return CMD_WARNING_CONFIG_FAILED
;
2588 SET_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
);
2589 /* The address will be advertised to zebra clients when the
2591 * from the kernel has been received.
2592 * It will also be added to the subnet chain list, then. */
2598 static int ip_address_uninstall(struct vty
*vty
, struct interface
*ifp
,
2599 const char *addr_str
, const char *peer_str
,
2602 struct prefix_ipv4 lp
, pp
;
2603 struct connected
*ifc
;
2606 /* Convert to prefix structure. */
2607 ret
= str2prefix_ipv4(addr_str
, &lp
);
2609 vty_out(vty
, "%% Malformed address \n");
2610 return CMD_WARNING_CONFIG_FAILED
;
2614 if (lp
.prefixlen
!= 32) {
2616 "%% Local prefix length for P-t-P address must be /32\n");
2617 return CMD_WARNING_CONFIG_FAILED
;
2620 ret
= str2prefix_ipv4(peer_str
, &pp
);
2622 vty_out(vty
, "%% Malformed peer address\n");
2623 return CMD_WARNING_CONFIG_FAILED
;
2627 /* Check current interface address. */
2628 ifc
= connected_check_ptp(ifp
, &lp
, peer_str
? &pp
: NULL
);
2630 vty_out(vty
, "%% Can't find address\n");
2631 return CMD_WARNING_CONFIG_FAILED
;
2634 /* This is not configured address. */
2635 if (!CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
2636 return CMD_WARNING_CONFIG_FAILED
;
2638 UNSET_FLAG(ifc
->conf
, ZEBRA_IFC_CONFIGURED
);
2640 /* This is not real address or interface is not active. */
2641 if (!CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
)
2642 || !CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
)) {
2643 listnode_delete(ifp
->connected
, ifc
);
2644 connected_free(ifc
);
2645 return CMD_WARNING_CONFIG_FAILED
;
2648 /* This is real route. */
2649 ret
= if_unset_prefix(ifp
, ifc
);
2651 vty_out(vty
, "%% Can't unset interface IP address: %s.\n",
2652 safe_strerror(errno
));
2653 return CMD_WARNING_CONFIG_FAILED
;
2655 UNSET_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
);
2656 /* we will receive a kernel notification about this route being removed.
2657 * this will trigger its removal from the connected list. */
2663 "ip address A.B.C.D/M",
2664 "Interface Internet Protocol config commands\n"
2665 "Set the IP address of an interface\n"
2666 "IP address (e.g. 10.0.0.1/8)\n")
2668 int idx_ipv4_prefixlen
= 2;
2669 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2670 return ip_address_install(vty
, ifp
, argv
[idx_ipv4_prefixlen
]->arg
, NULL
,
2674 DEFUN (no_ip_address
,
2676 "no ip address A.B.C.D/M",
2678 "Interface Internet Protocol config commands\n"
2679 "Set the IP address of an interface\n"
2680 "IP Address (e.g. 10.0.0.1/8)\n")
2682 int idx_ipv4_prefixlen
= 3;
2683 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2684 return ip_address_uninstall(vty
, ifp
, argv
[idx_ipv4_prefixlen
]->arg
,
2688 DEFUN(ip_address_peer
,
2689 ip_address_peer_cmd
,
2690 "ip address A.B.C.D peer A.B.C.D/M",
2691 "Interface Internet Protocol config commands\n"
2692 "Set the IP address of an interface\n"
2693 "Local IP (e.g. 10.0.0.1) for P-t-P address\n"
2694 "Specify P-t-P address\n"
2695 "Peer IP address (e.g. 10.0.0.1/8)\n")
2697 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2698 return ip_address_install(vty
, ifp
, argv
[2]->arg
, argv
[4]->arg
, NULL
);
2701 DEFUN(no_ip_address_peer
,
2702 no_ip_address_peer_cmd
,
2703 "no ip address A.B.C.D peer A.B.C.D/M",
2705 "Interface Internet Protocol config commands\n"
2706 "Set the IP address of an interface\n"
2707 "Local IP (e.g. 10.0.0.1) for P-t-P address\n"
2708 "Specify P-t-P address\n"
2709 "Peer IP address (e.g. 10.0.0.1/8)\n")
2711 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2712 return ip_address_uninstall(vty
, ifp
, argv
[3]->arg
, argv
[5]->arg
, NULL
);
2716 DEFUN (ip_address_label
,
2717 ip_address_label_cmd
,
2718 "ip address A.B.C.D/M label LINE",
2719 "Interface Internet Protocol config commands\n"
2720 "Set the IP address of an interface\n"
2721 "IP address (e.g. 10.0.0.1/8)\n"
2722 "Label of this address\n"
2725 int idx_ipv4_prefixlen
= 2;
2727 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2728 return ip_address_install(vty
, ifp
, argv
[idx_ipv4_prefixlen
]->arg
, NULL
,
2729 argv
[idx_line
]->arg
);
2732 DEFUN (no_ip_address_label
,
2733 no_ip_address_label_cmd
,
2734 "no ip address A.B.C.D/M label LINE",
2736 "Interface Internet Protocol config commands\n"
2737 "Set the IP address of an interface\n"
2738 "IP address (e.g. 10.0.0.1/8)\n"
2739 "Label of this address\n"
2742 int idx_ipv4_prefixlen
= 3;
2744 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2745 return ip_address_uninstall(vty
, ifp
, argv
[idx_ipv4_prefixlen
]->arg
,
2746 NULL
, argv
[idx_line
]->arg
);
2748 #endif /* HAVE_NETLINK */
2750 static int ipv6_address_install(struct vty
*vty
, struct interface
*ifp
,
2751 const char *addr_str
, const char *peer_str
,
2752 const char *label
, int secondary
)
2754 struct zebra_if
*if_data
;
2755 struct prefix_ipv6 cp
;
2756 struct connected
*ifc
;
2757 struct prefix_ipv6
*p
;
2760 if_data
= ifp
->info
;
2762 ret
= str2prefix_ipv6(addr_str
, &cp
);
2764 vty_out(vty
, "%% Malformed address \n");
2765 return CMD_WARNING_CONFIG_FAILED
;
2768 if (ipv6_martian(&cp
.prefix
)) {
2769 vty_out(vty
, "%% Invalid address\n");
2770 return CMD_WARNING_CONFIG_FAILED
;
2773 ifc
= connected_check(ifp
, (struct prefix
*)&cp
);
2775 ifc
= connected_new();
2779 p
= prefix_ipv6_new();
2781 ifc
->address
= (struct prefix
*)p
;
2785 SET_FLAG(ifc
->flags
, ZEBRA_IFA_SECONDARY
);
2789 ifc
->label
= XSTRDUP(MTYPE_CONNECTED_LABEL
, label
);
2791 /* Add to linked list. */
2792 listnode_add(ifp
->connected
, ifc
);
2795 /* This address is configured from zebra. */
2796 if (!CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
2797 SET_FLAG(ifc
->conf
, ZEBRA_IFC_CONFIGURED
);
2799 /* In case of this route need to install kernel. */
2800 if (!CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
)
2801 && CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
)
2802 && !(if_data
&& if_data
->shutdown
== IF_ZEBRA_SHUTDOWN_ON
)) {
2803 /* Some system need to up the interface to set IP address. */
2804 if (!if_is_up(ifp
)) {
2805 if_set_flags(ifp
, IFF_UP
| IFF_RUNNING
);
2809 ret
= if_prefix_add_ipv6(ifp
, ifc
);
2812 vty_out(vty
, "%% Can't set interface IP address: %s.\n",
2813 safe_strerror(errno
));
2814 return CMD_WARNING_CONFIG_FAILED
;
2817 SET_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
);
2818 /* The address will be advertised to zebra clients when the
2820 * from the kernel has been received. */
2826 /* Return true if an ipv6 address is configured on ifp */
2827 int ipv6_address_configured(struct interface
*ifp
)
2829 struct connected
*connected
;
2830 struct listnode
*node
;
2832 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, node
, connected
))
2833 if (CHECK_FLAG(connected
->conf
, ZEBRA_IFC_REAL
)
2834 && (connected
->address
->family
== AF_INET6
))
2840 static int ipv6_address_uninstall(struct vty
*vty
, struct interface
*ifp
,
2841 const char *addr_str
, const char *peer_str
,
2842 const char *label
, int secondry
)
2844 struct prefix_ipv6 cp
;
2845 struct connected
*ifc
;
2848 /* Convert to prefix structure. */
2849 ret
= str2prefix_ipv6(addr_str
, &cp
);
2851 vty_out(vty
, "%% Malformed address \n");
2852 return CMD_WARNING_CONFIG_FAILED
;
2855 /* Check current interface address. */
2856 ifc
= connected_check(ifp
, (struct prefix
*)&cp
);
2858 vty_out(vty
, "%% Can't find address\n");
2859 return CMD_WARNING_CONFIG_FAILED
;
2862 /* This is not configured address. */
2863 if (!CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
2864 return CMD_WARNING_CONFIG_FAILED
;
2866 UNSET_FLAG(ifc
->conf
, ZEBRA_IFC_CONFIGURED
);
2868 /* This is not real address or interface is not active. */
2869 if (!CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
)
2870 || !CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
)) {
2871 listnode_delete(ifp
->connected
, ifc
);
2872 connected_free(ifc
);
2873 return CMD_WARNING_CONFIG_FAILED
;
2876 /* This is real route. */
2877 ret
= if_prefix_delete_ipv6(ifp
, ifc
);
2879 vty_out(vty
, "%% Can't unset interface IP address: %s.\n",
2880 safe_strerror(errno
));
2881 return CMD_WARNING_CONFIG_FAILED
;
2884 UNSET_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
);
2885 /* This information will be propagated to the zclients when the
2886 * kernel notification is received. */
2890 DEFUN (ipv6_address
,
2892 "ipv6 address X:X::X:X/M",
2893 "Interface IPv6 config commands\n"
2894 "Set the IP address of an interface\n"
2895 "IPv6 address (e.g. 3ffe:506::1/48)\n")
2897 int idx_ipv6_prefixlen
= 2;
2898 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2899 return ipv6_address_install(vty
, ifp
, argv
[idx_ipv6_prefixlen
]->arg
,
2903 DEFUN (no_ipv6_address
,
2904 no_ipv6_address_cmd
,
2905 "no ipv6 address X:X::X:X/M",
2907 "Interface IPv6 config commands\n"
2908 "Set the IP address of an interface\n"
2909 "IPv6 address (e.g. 3ffe:506::1/48)\n")
2911 int idx_ipv6_prefixlen
= 3;
2912 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2913 return ipv6_address_uninstall(vty
, ifp
, argv
[idx_ipv6_prefixlen
]->arg
,
2917 static int link_params_config_write(struct vty
*vty
, struct interface
*ifp
)
2921 if ((ifp
== NULL
) || !HAS_LINK_PARAMS(ifp
))
2924 struct if_link_params
*iflp
= ifp
->link_params
;
2926 vty_out(vty
, " link-params\n");
2927 vty_out(vty
, " enable\n");
2928 if (IS_PARAM_SET(iflp
, LP_TE_METRIC
) && iflp
->te_metric
!= ifp
->metric
)
2929 vty_out(vty
, " metric %u\n", iflp
->te_metric
);
2930 if (IS_PARAM_SET(iflp
, LP_MAX_BW
) && iflp
->max_bw
!= iflp
->default_bw
)
2931 vty_out(vty
, " max-bw %g\n", iflp
->max_bw
);
2932 if (IS_PARAM_SET(iflp
, LP_MAX_RSV_BW
)
2933 && iflp
->max_rsv_bw
!= iflp
->default_bw
)
2934 vty_out(vty
, " max-rsv-bw %g\n", iflp
->max_rsv_bw
);
2935 if (IS_PARAM_SET(iflp
, LP_UNRSV_BW
)) {
2936 for (i
= 0; i
< 8; i
++)
2937 if (iflp
->unrsv_bw
[i
] != iflp
->default_bw
)
2938 vty_out(vty
, " unrsv-bw %d %g\n", i
,
2941 if (IS_PARAM_SET(iflp
, LP_ADM_GRP
))
2942 vty_out(vty
, " admin-grp 0x%x\n", iflp
->admin_grp
);
2943 if (IS_PARAM_SET(iflp
, LP_DELAY
)) {
2944 vty_out(vty
, " delay %u", iflp
->av_delay
);
2945 if (IS_PARAM_SET(iflp
, LP_MM_DELAY
)) {
2946 vty_out(vty
, " min %u", iflp
->min_delay
);
2947 vty_out(vty
, " max %u", iflp
->max_delay
);
2951 if (IS_PARAM_SET(iflp
, LP_DELAY_VAR
))
2952 vty_out(vty
, " delay-variation %u\n", iflp
->delay_var
);
2953 if (IS_PARAM_SET(iflp
, LP_PKT_LOSS
))
2954 vty_out(vty
, " packet-loss %g\n", iflp
->pkt_loss
);
2955 if (IS_PARAM_SET(iflp
, LP_AVA_BW
))
2956 vty_out(vty
, " ava-bw %g\n", iflp
->ava_bw
);
2957 if (IS_PARAM_SET(iflp
, LP_RES_BW
))
2958 vty_out(vty
, " res-bw %g\n", iflp
->res_bw
);
2959 if (IS_PARAM_SET(iflp
, LP_USE_BW
))
2960 vty_out(vty
, " use-bw %g\n", iflp
->use_bw
);
2961 if (IS_PARAM_SET(iflp
, LP_RMT_AS
))
2962 vty_out(vty
, " neighbor %s as %u\n", inet_ntoa(iflp
->rmt_ip
),
2964 vty_out(vty
, " exit-link-params\n");
2968 static int if_config_write(struct vty
*vty
)
2971 struct interface
*ifp
;
2973 zebra_ptm_write(vty
);
2975 RB_FOREACH (vrf0
, vrf_name_head
, &vrfs_by_name
)
2976 FOR_ALL_INTERFACES (vrf0
, ifp
) {
2977 struct zebra_if
*if_data
;
2978 struct listnode
*addrnode
;
2979 struct connected
*ifc
;
2983 if_data
= ifp
->info
;
2984 vrf
= vrf_lookup_by_id(ifp
->vrf_id
);
2986 if (ifp
->vrf_id
== VRF_DEFAULT
)
2987 vty_frame(vty
, "interface %s\n", ifp
->name
);
2989 vty_frame(vty
, "interface %s vrf %s\n",
2990 ifp
->name
, vrf
->name
);
2993 if (if_data
->shutdown
== IF_ZEBRA_SHUTDOWN_ON
)
2994 vty_out(vty
, " shutdown\n");
2996 zebra_ptm_if_write(vty
, if_data
);
3000 vty_out(vty
, " description %s\n", ifp
->desc
);
3002 /* Assign bandwidth here to avoid unnecessary interface
3004 while processing config script */
3005 if (ifp
->bandwidth
!= 0)
3006 vty_out(vty
, " bandwidth %u\n", ifp
->bandwidth
);
3008 if (!CHECK_FLAG(ifp
->status
,
3009 ZEBRA_INTERFACE_LINKDETECTION
))
3010 vty_out(vty
, " no link-detect\n");
3012 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, addrnode
,
3014 if (CHECK_FLAG(ifc
->conf
,
3015 ZEBRA_IFC_CONFIGURED
)) {
3016 char buf
[INET6_ADDRSTRLEN
];
3018 vty_out(vty
, " ip%s address %s",
3019 p
->family
== AF_INET
? ""
3021 inet_ntop(p
->family
,
3024 if (CONNECTED_PEER(ifc
)) {
3025 p
= ifc
->destination
;
3026 vty_out(vty
, " peer %s",
3027 inet_ntop(p
->family
,
3032 vty_out(vty
, "/%d", p
->prefixlen
);
3035 vty_out(vty
, " label %s",
3043 if (if_data
->multicast
3044 != IF_ZEBRA_MULTICAST_UNSPEC
)
3045 vty_out(vty
, " %smulticast\n",
3047 == IF_ZEBRA_MULTICAST_ON
3052 hook_call(zebra_if_config_wr
, vty
, ifp
);
3054 link_params_config_write(vty
, ifp
);
3056 vty_endframe(vty
, "!\n");
3061 /* Allocate and initialize interface vector. */
3062 void zebra_if_init(void)
3064 /* Initialize interface and new hook. */
3065 hook_register_prio(if_add
, 0, if_zebra_new_hook
);
3066 hook_register_prio(if_del
, 0, if_zebra_delete_hook
);
3068 /* Install configuration write function. */
3069 install_node(&interface_node
, if_config_write
);
3070 install_node(&link_params_node
, NULL
);
3073 install_element(VIEW_NODE
, &show_interface_cmd
);
3074 install_element(VIEW_NODE
, &show_interface_vrf_all_cmd
);
3075 install_element(VIEW_NODE
, &show_interface_name_vrf_cmd
);
3076 install_element(VIEW_NODE
, &show_interface_name_vrf_all_cmd
);
3078 install_element(ENABLE_NODE
, &show_interface_desc_cmd
);
3079 install_element(ENABLE_NODE
, &show_interface_desc_vrf_all_cmd
);
3080 install_element(INTERFACE_NODE
, &multicast_cmd
);
3081 install_element(INTERFACE_NODE
, &no_multicast_cmd
);
3082 install_element(INTERFACE_NODE
, &linkdetect_cmd
);
3083 install_element(INTERFACE_NODE
, &no_linkdetect_cmd
);
3084 install_element(INTERFACE_NODE
, &shutdown_if_cmd
);
3085 install_element(INTERFACE_NODE
, &no_shutdown_if_cmd
);
3086 install_element(INTERFACE_NODE
, &bandwidth_if_cmd
);
3087 install_element(INTERFACE_NODE
, &no_bandwidth_if_cmd
);
3088 install_element(INTERFACE_NODE
, &ip_address_cmd
);
3089 install_element(INTERFACE_NODE
, &no_ip_address_cmd
);
3090 install_element(INTERFACE_NODE
, &ip_address_peer_cmd
);
3091 install_element(INTERFACE_NODE
, &no_ip_address_peer_cmd
);
3092 install_element(INTERFACE_NODE
, &ipv6_address_cmd
);
3093 install_element(INTERFACE_NODE
, &no_ipv6_address_cmd
);
3095 install_element(INTERFACE_NODE
, &ip_address_label_cmd
);
3096 install_element(INTERFACE_NODE
, &no_ip_address_label_cmd
);
3097 #endif /* HAVE_NETLINK */
3098 install_element(INTERFACE_NODE
, &link_params_cmd
);
3099 install_default(LINK_PARAMS_NODE
);
3100 install_element(LINK_PARAMS_NODE
, &link_params_enable_cmd
);
3101 install_element(LINK_PARAMS_NODE
, &no_link_params_enable_cmd
);
3102 install_element(LINK_PARAMS_NODE
, &link_params_metric_cmd
);
3103 install_element(LINK_PARAMS_NODE
, &no_link_params_metric_cmd
);
3104 install_element(LINK_PARAMS_NODE
, &link_params_maxbw_cmd
);
3105 install_element(LINK_PARAMS_NODE
, &link_params_max_rsv_bw_cmd
);
3106 install_element(LINK_PARAMS_NODE
, &link_params_unrsv_bw_cmd
);
3107 install_element(LINK_PARAMS_NODE
, &link_params_admin_grp_cmd
);
3108 install_element(LINK_PARAMS_NODE
, &no_link_params_admin_grp_cmd
);
3109 install_element(LINK_PARAMS_NODE
, &link_params_inter_as_cmd
);
3110 install_element(LINK_PARAMS_NODE
, &no_link_params_inter_as_cmd
);
3111 install_element(LINK_PARAMS_NODE
, &link_params_delay_cmd
);
3112 install_element(LINK_PARAMS_NODE
, &no_link_params_delay_cmd
);
3113 install_element(LINK_PARAMS_NODE
, &link_params_delay_var_cmd
);
3114 install_element(LINK_PARAMS_NODE
, &no_link_params_delay_var_cmd
);
3115 install_element(LINK_PARAMS_NODE
, &link_params_pkt_loss_cmd
);
3116 install_element(LINK_PARAMS_NODE
, &no_link_params_pkt_loss_cmd
);
3117 install_element(LINK_PARAMS_NODE
, &link_params_ava_bw_cmd
);
3118 install_element(LINK_PARAMS_NODE
, &no_link_params_ava_bw_cmd
);
3119 install_element(LINK_PARAMS_NODE
, &link_params_res_bw_cmd
);
3120 install_element(LINK_PARAMS_NODE
, &no_link_params_res_bw_cmd
);
3121 install_element(LINK_PARAMS_NODE
, &link_params_use_bw_cmd
);
3122 install_element(LINK_PARAMS_NODE
, &no_link_params_use_bw_cmd
);
3123 install_element(LINK_PARAMS_NODE
, &exit_link_params_cmd
);