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
26 #include "sockunion.h"
30 #include "zebra_memory.h"
32 #include "connected.h"
37 #include "zebra/rtadv.h"
39 #include "zebra_vrf.h"
40 #include "zebra/interface.h"
41 #include "zebra/rib.h"
43 #include "zebra/zserv.h"
44 #include "zebra/redistribute.h"
45 #include "zebra/debug.h"
46 #include "zebra/irdp.h"
47 #include "zebra/zebra_ptm.h"
48 #include "zebra/rt_netlink.h"
49 #include "zebra/interface.h"
50 #include "zebra/zebra_vxlan.h"
51 #include "zebra/zebra_static.h"
53 #define ZEBRA_PTM_SUPPORT
55 DEFINE_HOOK(zebra_if_extra_info
, (struct vty
*vty
, struct interface
*ifp
),
57 DEFINE_HOOK(zebra_if_config_wr
, (struct vty
*vty
, struct interface
*ifp
),
61 static void if_down_del_nbr_connected(struct interface
*ifp
);
63 static int if_zebra_speed_update(struct thread
*thread
)
65 struct interface
*ifp
= THREAD_ARG(thread
);
66 struct zebra_if
*zif
= ifp
->info
;
69 zif
->speed_update
= NULL
;
71 new_speed
= kernel_get_speed(ifp
);
72 if (new_speed
!= ifp
->speed
) {
73 zlog_info("%s: %s old speed: %u new speed: %u",
74 __PRETTY_FUNCTION__
, ifp
->name
,
75 ifp
->speed
, new_speed
);
76 ifp
->speed
= new_speed
;
83 static void zebra_if_node_destroy(route_table_delegate_t
*delegate
,
84 struct route_table
*table
,
85 struct route_node
*node
)
88 list_delete_and_null((struct list
**)&node
->info
);
89 route_node_destroy(delegate
, table
, node
);
92 route_table_delegate_t zebra_if_table_delegate
= {
93 .create_node
= route_node_create
,
94 .destroy_node
= zebra_if_node_destroy
};
96 /* Called when new interface is added. */
97 static int if_zebra_new_hook(struct interface
*ifp
)
99 struct zebra_if
*zebra_if
;
101 zebra_if
= XCALLOC(MTYPE_TMP
, sizeof(struct zebra_if
));
103 zebra_if
->multicast
= IF_ZEBRA_MULTICAST_UNSPEC
;
104 zebra_if
->shutdown
= IF_ZEBRA_SHUTDOWN_OFF
;
105 zebra_ptm_if_init(zebra_if
);
107 ifp
->ptm_enable
= zebra_ptm_get_enable_state();
108 #if defined(HAVE_RTADV)
110 /* Set default router advertise values. */
111 struct rtadvconf
*rtadv
;
113 rtadv
= &zebra_if
->rtadv
;
115 rtadv
->AdvSendAdvertisements
= 0;
116 rtadv
->MaxRtrAdvInterval
= RTADV_MAX_RTR_ADV_INTERVAL
;
117 rtadv
->MinRtrAdvInterval
= RTADV_MIN_RTR_ADV_INTERVAL
;
118 rtadv
->AdvIntervalTimer
= 0;
119 rtadv
->AdvManagedFlag
= 0;
120 rtadv
->AdvOtherConfigFlag
= 0;
121 rtadv
->AdvHomeAgentFlag
= 0;
122 rtadv
->AdvLinkMTU
= 0;
123 rtadv
->AdvReachableTime
= 0;
124 rtadv
->AdvRetransTimer
= 0;
125 rtadv
->AdvCurHopLimit
= 0;
126 rtadv
->AdvDefaultLifetime
=
127 -1; /* derive from MaxRtrAdvInterval */
128 rtadv
->HomeAgentPreference
= 0;
129 rtadv
->HomeAgentLifetime
=
130 -1; /* derive from AdvDefaultLifetime */
131 rtadv
->AdvIntervalOption
= 0;
132 rtadv
->DefaultPreference
= RTADV_PREF_MEDIUM
;
134 rtadv
->AdvPrefixList
= list_new();
136 #endif /* HAVE_RTADV */
138 /* Initialize installed address chains tree. */
139 zebra_if
->ipv4_subnets
=
140 route_table_init_with_delegate(&zebra_if_table_delegate
);
142 ifp
->info
= zebra_if
;
145 * Some platforms are telling us that the interface is
146 * up and ready to go. When we check the speed we
147 * sometimes get the wrong value. Wait a couple
148 * of seconds and ask again. Hopefully it's all settled
151 thread_add_timer(zebrad
.master
, if_zebra_speed_update
,
152 ifp
, 15, &zebra_if
->speed_update
);
156 /* Called when interface is deleted. */
157 static int if_zebra_delete_hook(struct interface
*ifp
)
159 struct zebra_if
*zebra_if
;
162 zebra_if
= ifp
->info
;
164 /* Free installed address chains tree. */
165 if (zebra_if
->ipv4_subnets
)
166 route_table_finish(zebra_if
->ipv4_subnets
);
167 #if defined(HAVE_RTADV)
169 struct rtadvconf
*rtadv
;
171 rtadv
= &zebra_if
->rtadv
;
172 list_delete_and_null(&rtadv
->AdvPrefixList
);
173 #endif /* HAVE_RTADV */
175 THREAD_OFF(zebra_if
->speed_update
);
177 XFREE(MTYPE_TMP
, zebra_if
);
183 /* Build the table key */
184 static void if_build_key(u_int32_t ifindex
, struct prefix
*p
)
187 p
->prefixlen
= IPV4_MAX_BITLEN
;
188 p
->u
.prefix4
.s_addr
= ifindex
;
191 /* Link an interface in a per NS interface tree */
192 struct interface
*if_link_per_ns(struct zebra_ns
*ns
, struct interface
*ifp
)
195 struct route_node
*rn
;
197 if (ifp
->ifindex
== IFINDEX_INTERNAL
)
200 if_build_key(ifp
->ifindex
, &p
);
201 rn
= route_node_get(ns
->if_table
, &p
);
203 ifp
= (struct interface
*)rn
->info
;
204 route_unlock_node(rn
); /* get */
214 /* Delete a VRF. This is called in vrf_terminate(). */
215 void if_unlink_per_ns(struct interface
*ifp
)
217 ifp
->node
->info
= NULL
;
218 route_unlock_node(ifp
->node
);
222 /* Look up an interface by identifier within a NS */
223 struct interface
*if_lookup_by_index_per_ns(struct zebra_ns
*ns
,
227 struct route_node
*rn
;
228 struct interface
*ifp
= NULL
;
230 if_build_key(ifindex
, &p
);
231 rn
= route_node_lookup(ns
->if_table
, &p
);
233 ifp
= (struct interface
*)rn
->info
;
234 route_unlock_node(rn
); /* lookup */
239 /* Look up an interface by name within a NS */
240 struct interface
*if_lookup_by_name_per_ns(struct zebra_ns
*ns
,
243 struct route_node
*rn
;
244 struct interface
*ifp
;
246 for (rn
= route_top(ns
->if_table
); rn
; rn
= route_next(rn
)) {
247 ifp
= (struct interface
*)rn
->info
;
248 if (ifp
&& strcmp(ifp
->name
, ifname
) == 0)
255 const char *ifindex2ifname_per_ns(struct zebra_ns
*zns
, unsigned int ifindex
)
257 struct interface
*ifp
;
259 return ((ifp
= if_lookup_by_index_per_ns(zns
, ifindex
)) != NULL
)
264 /* Tie an interface address to its derived subnet list of addresses. */
265 int if_subnet_add(struct interface
*ifp
, struct connected
*ifc
)
267 struct route_node
*rn
;
268 struct zebra_if
*zebra_if
;
270 struct list
*addr_list
;
272 assert(ifp
&& ifp
->info
&& ifc
);
273 zebra_if
= ifp
->info
;
275 /* Get address derived subnet node and associated address list, while
277 address secondary attribute appropriately. */
278 cp
= *CONNECTED_PREFIX(ifc
);
280 rn
= route_node_get(zebra_if
->ipv4_subnets
, &cp
);
282 if ((addr_list
= rn
->info
))
283 SET_FLAG(ifc
->flags
, ZEBRA_IFA_SECONDARY
);
285 UNSET_FLAG(ifc
->flags
, ZEBRA_IFA_SECONDARY
);
286 rn
->info
= addr_list
= list_new();
290 /* Tie address at the tail of address list. */
291 listnode_add(addr_list
, ifc
);
293 /* Return list element count. */
294 return (addr_list
->count
);
297 /* Untie an interface address from its derived subnet list of addresses. */
298 int if_subnet_delete(struct interface
*ifp
, struct connected
*ifc
)
300 struct route_node
*rn
;
301 struct zebra_if
*zebra_if
;
302 struct list
*addr_list
;
305 assert(ifp
&& ifp
->info
&& ifc
);
306 zebra_if
= ifp
->info
;
308 cp
= *CONNECTED_PREFIX(ifc
);
311 /* Get address derived subnet node. */
312 rn
= route_node_lookup(zebra_if
->ipv4_subnets
, &cp
);
313 if (!(rn
&& rn
->info
)) {
315 "Trying to remove an address from an unknown subnet."
316 " (please report this bug)");
319 route_unlock_node(rn
);
321 /* Untie address from subnet's address list. */
322 addr_list
= rn
->info
;
324 /* Deleting an address that is not registered is a bug.
325 * In any case, we shouldn't decrement the lock counter if the address
327 if (!listnode_lookup(addr_list
, ifc
)) {
329 "Trying to remove an address from a subnet where it is not"
330 " currently registered. (please report this bug)");
334 listnode_delete(addr_list
, ifc
);
335 route_unlock_node(rn
);
337 /* Return list element count, if not empty. */
338 if (addr_list
->count
) {
339 /* If deleted address is primary, mark subsequent one as such
341 if (!CHECK_FLAG(ifc
->flags
, ZEBRA_IFA_SECONDARY
)) {
343 (struct listnode
*)listhead(addr_list
));
344 zebra_interface_address_delete_update(ifp
, ifc
);
345 UNSET_FLAG(ifc
->flags
, ZEBRA_IFA_SECONDARY
);
346 /* XXX: Linux kernel removes all the secondary addresses
348 * address is removed. We could try to work around that,
351 zebra_interface_address_add_update(ifp
, ifc
);
354 return addr_list
->count
;
357 /* Otherwise, free list and route node. */
358 list_delete_and_null(&addr_list
);
360 route_unlock_node(rn
);
365 /* if_flags_mangle: A place for hacks that require mangling
366 * or tweaking the interface flags.
368 * ******************** Solaris flags hacks **************************
370 * Solaris IFF_UP flag reflects only the primary interface as the
371 * routing socket only sends IFINFO for the primary interface. Hence
372 * ~IFF_UP does not per se imply all the logical interfaces are also
373 * down - which we only know of as addresses. Instead we must determine
374 * whether the interface really is up or not according to how many
375 * addresses are still attached. (Solaris always sends RTM_DELADDR if
376 * an interface, logical or not, goes ~IFF_UP).
378 * Ie, we mangle IFF_UP to *additionally* reflect whether or not there
379 * are addresses left in struct connected, not just the actual underlying
382 * We must hence remember the real state of IFF_UP, which we do in
383 * struct zebra_if.primary_state.
385 * Setting IFF_UP within zebra to administratively shutdown the
386 * interface will affect only the primary interface/address on Solaris.
387 ************************End Solaris flags hacks ***********************
389 static void if_flags_mangle(struct interface
*ifp
, uint64_t *newflags
)
392 struct zebra_if
*zif
= ifp
->info
;
394 zif
->primary_state
= *newflags
& (IFF_UP
& 0xff);
396 if (CHECK_FLAG(zif
->primary_state
, IFF_UP
)
397 || listcount(ifp
->connected
) > 0)
398 SET_FLAG(*newflags
, IFF_UP
);
400 UNSET_FLAG(*newflags
, IFF_UP
);
404 /* Update the flags field of the ifp with the new flag set provided.
405 * Take whatever actions are required for any changes in flags we care
408 * newflags should be the raw value, as obtained from the OS.
410 void if_flags_update(struct interface
*ifp
, uint64_t newflags
)
412 if_flags_mangle(ifp
, &newflags
);
414 if (if_is_no_ptm_operative(ifp
)) {
415 /* operative -> inoperative? */
416 ifp
->flags
= newflags
;
417 if (!if_is_operative(ifp
))
420 /* inoperative -> operative? */
421 ifp
->flags
= newflags
;
422 if (if_is_operative(ifp
))
427 /* Wake up configured address if it is not in current kernel
429 static void if_addr_wakeup(struct interface
*ifp
)
431 struct listnode
*node
, *nnode
;
432 struct connected
*ifc
;
436 for (ALL_LIST_ELEMENTS(ifp
->connected
, node
, nnode
, ifc
)) {
439 if (CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_CONFIGURED
)
440 && !CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
)) {
442 if (p
->family
== AF_INET
) {
443 if (!if_is_up(ifp
)) {
444 /* Assume zebra is configured like
448 * ip addr 192.0.2.1/24
451 * As soon as zebra becomes first aware
452 * that gre0 exists in the
453 * kernel, it will set gre0 up and
454 * configure its addresses.
456 * (This may happen at startup when the
457 * interface already exists
458 * or during runtime when the interface
459 * is added to the kernel)
461 * XXX: IRDP code is calling here via
462 * if_add_update - this seems
464 * XXX: RUNNING is not a settable flag
466 * I (paulj) am aware of.
468 if_set_flags(ifp
, IFF_UP
| IFF_RUNNING
);
472 ret
= if_set_prefix(ifp
, ifc
);
475 "Can't set interface's address: %s",
476 safe_strerror(errno
));
480 SET_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
);
481 /* The address will be advertised to zebra
482 * clients when the notification
483 * from the kernel has been received.
484 * It will also be added to the interface's
485 * subnet list then. */
487 if (p
->family
== AF_INET6
) {
488 if (!if_is_up(ifp
)) {
489 /* See long comment above */
490 if_set_flags(ifp
, IFF_UP
| IFF_RUNNING
);
494 ret
= if_prefix_add_ipv6(ifp
, ifc
);
497 "Can't set interface's address: %s",
498 safe_strerror(errno
));
502 SET_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
);
503 /* The address will be advertised to zebra
504 * clients when the notification
505 * from the kernel has been received. */
511 /* Handle interface addition */
512 void if_add_update(struct interface
*ifp
)
514 struct zebra_if
*if_data
;
516 if_link_per_ns(zebra_ns_lookup(NS_DEFAULT
), ifp
);
521 if (if_data
->multicast
== IF_ZEBRA_MULTICAST_ON
)
522 if_set_flags(ifp
, IFF_MULTICAST
);
523 else if (if_data
->multicast
== IF_ZEBRA_MULTICAST_OFF
)
524 if_unset_flags(ifp
, IFF_MULTICAST
);
526 zebra_ptm_if_set_ptm_state(ifp
, if_data
);
528 zebra_interface_add_update(ifp
);
530 if (!CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
)) {
531 SET_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
);
533 if (if_data
->shutdown
== IF_ZEBRA_SHUTDOWN_ON
) {
534 if (IS_ZEBRA_DEBUG_KERNEL
)
536 "interface %s vrf %u index %d is shutdown. "
538 ifp
->name
, ifp
->vrf_id
, ifp
->ifindex
);
544 if (IS_ZEBRA_DEBUG_KERNEL
)
546 "interface %s vrf %u index %d becomes active.",
547 ifp
->name
, ifp
->vrf_id
, ifp
->ifindex
);
549 static_ifindex_update(ifp
, true);
551 if (IS_ZEBRA_DEBUG_KERNEL
)
552 zlog_debug("interface %s vrf %u index %d is added.",
553 ifp
->name
, ifp
->vrf_id
, ifp
->ifindex
);
557 /* Install connected routes corresponding to an interface. */
558 static void if_install_connected(struct interface
*ifp
)
560 struct listnode
*node
;
561 struct listnode
*next
;
562 struct connected
*ifc
;
564 if (ifp
->connected
) {
565 for (ALL_LIST_ELEMENTS(ifp
->connected
, node
, next
, ifc
)) {
566 if (CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_REAL
))
567 zebra_interface_address_add_update(ifp
, ifc
);
569 connected_up(ifp
, ifc
);
574 /* Uninstall connected routes corresponding to an interface. */
575 static void if_uninstall_connected(struct interface
*ifp
)
577 struct listnode
*node
;
578 struct listnode
*next
;
579 struct connected
*ifc
;
581 if (ifp
->connected
) {
582 for (ALL_LIST_ELEMENTS(ifp
->connected
, node
, next
, ifc
)) {
583 zebra_interface_address_delete_update(ifp
, ifc
);
584 connected_down(ifp
, ifc
);
589 /* Uninstall and delete connected routes corresponding to an interface. */
590 /* TODO - Check why IPv4 handling here is different from install or if_down */
591 static void if_delete_connected(struct interface
*ifp
)
593 struct connected
*ifc
;
595 struct route_node
*rn
;
596 struct zebra_if
*zebra_if
;
597 struct listnode
*node
;
598 struct listnode
*last
= NULL
;
600 zebra_if
= ifp
->info
;
605 while ((node
= (last
? last
->next
606 : listhead(ifp
->connected
)))) {
607 ifc
= listgetdata(node
);
609 cp
= *CONNECTED_PREFIX(ifc
);
612 if (cp
.family
== AF_INET
613 && (rn
= route_node_lookup(zebra_if
->ipv4_subnets
,
615 struct listnode
*anode
;
616 struct listnode
*next
;
617 struct listnode
*first
;
618 struct list
*addr_list
;
620 route_unlock_node(rn
);
621 addr_list
= (struct list
*)rn
->info
;
623 /* Remove addresses, secondaries first. */
624 first
= listhead(addr_list
);
626 for (anode
= first
->next
; anode
|| first
;
634 ifc
= listgetdata(anode
);
635 connected_down(ifp
, ifc
);
637 /* XXX: We have to send notifications
638 * here explicitly, because we destroy
639 * the ifc before receiving the
640 * notification about the address being
643 zebra_interface_address_delete_update(
646 UNSET_FLAG(ifc
->conf
, ZEBRA_IFC_REAL
);
647 UNSET_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
);
649 /* Remove from subnet chain. */
650 list_delete_node(addr_list
, anode
);
651 route_unlock_node(rn
);
653 /* Remove from interface address list
654 * (unconditionally). */
655 if (!CHECK_FLAG(ifc
->conf
,
656 ZEBRA_IFC_CONFIGURED
)) {
657 listnode_delete(ifp
->connected
,
664 /* Free chain list and respective route node. */
665 list_delete_and_null(&addr_list
);
667 route_unlock_node(rn
);
668 } else if (cp
.family
== AF_INET6
) {
669 connected_down(ifp
, ifc
);
671 zebra_interface_address_delete_update(ifp
, ifc
);
673 UNSET_FLAG(ifc
->conf
, ZEBRA_IFC_REAL
);
674 UNSET_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
);
676 if (CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
679 listnode_delete(ifp
->connected
, ifc
);
688 /* Handle an interface delete event */
689 void if_delete_update(struct interface
*ifp
)
691 struct zebra_if
*zif
;
695 "interface %s vrf %u index %d is still up while being deleted.",
696 ifp
->name
, ifp
->vrf_id
, ifp
->ifindex
);
700 /* Mark interface as inactive */
701 UNSET_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
);
703 if (IS_ZEBRA_DEBUG_KERNEL
)
704 zlog_debug("interface %s vrf %u index %d is now inactive.",
705 ifp
->name
, ifp
->vrf_id
, ifp
->ifindex
);
707 static_ifindex_update(ifp
, false);
709 /* Delete connected routes from the kernel. */
710 if_delete_connected(ifp
);
712 /* Send out notification on interface delete. */
713 zebra_interface_delete_update(ifp
);
715 if_unlink_per_ns(ifp
);
717 /* Update ifindex after distributing the delete message. This is in
718 case any client needs to have the old value of ifindex available
719 while processing the deletion. Each client daemon is responsible
720 for setting ifindex to IFINDEX_INTERNAL after processing the
721 interface deletion message. */
722 if_set_index(ifp
, IFINDEX_INTERNAL
);
725 /* if the ifp is in a vrf, move it to default so vrf can be deleted if
728 if_handle_vrf_change(ifp
, VRF_DEFAULT
);
730 /* Reset some zebra interface params to default values. */
733 zif
->zif_type
= ZEBRA_IF_OTHER
;
734 zif
->zif_slave_type
= ZEBRA_IF_SLAVE_NONE
;
735 memset(&zif
->l2info
, 0, sizeof(union zebra_l2if_info
));
736 memset(&zif
->brslave_info
, 0,
737 sizeof(struct zebra_l2info_brslave
));
741 /* VRF change for an interface */
742 void if_handle_vrf_change(struct interface
*ifp
, vrf_id_t vrf_id
)
746 old_vrf_id
= ifp
->vrf_id
;
748 static_ifindex_update(ifp
, false);
750 /* Uninstall connected routes. */
751 if_uninstall_connected(ifp
);
753 /* Delete any IPv4 neighbors created to implement RFC 5549 */
754 if_nbr_ipv6ll_to_ipv4ll_neigh_del_all(ifp
);
756 /* Delete all neighbor addresses learnt through IPv6 RA */
757 if_down_del_nbr_connected(ifp
);
759 /* Send out notification on interface VRF change. */
760 /* This is to issue an UPDATE or a DELETE, as appropriate. */
761 zebra_interface_vrf_update_del(ifp
, vrf_id
);
764 if_update_to_new_vrf(ifp
, vrf_id
);
766 /* Send out notification on interface VRF change. */
767 /* This is to issue an ADD, if needed. */
768 zebra_interface_vrf_update_add(ifp
, old_vrf_id
);
770 /* Install connected routes (in new VRF). */
771 if (if_is_operative(ifp
))
772 if_install_connected(ifp
);
774 static_ifindex_update(ifp
, true);
776 /* Due to connected route change, schedule RIB processing for both old
779 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
780 zlog_debug("%u: IF %s VRF change, scheduling RIB processing",
781 ifp
->vrf_id
, ifp
->name
);
782 rib_update(old_vrf_id
, RIB_UPDATE_IF_CHANGE
);
783 rib_update(ifp
->vrf_id
, RIB_UPDATE_IF_CHANGE
);
786 static void ipv6_ll_address_to_mac(struct in6_addr
*address
, u_char
*mac
)
788 mac
[0] = address
->s6_addr
[8] ^ 0x02;
789 mac
[1] = address
->s6_addr
[9];
790 mac
[2] = address
->s6_addr
[10];
791 mac
[3] = address
->s6_addr
[13];
792 mac
[4] = address
->s6_addr
[14];
793 mac
[5] = address
->s6_addr
[15];
796 void if_nbr_ipv6ll_to_ipv4ll_neigh_update(struct interface
*ifp
,
797 struct in6_addr
*address
, int add
)
799 struct zebra_vrf
*zvrf
= vrf_info_lookup(ifp
->vrf_id
);
800 char buf
[16] = "169.254.0.1";
801 struct in_addr ipv4_ll
;
804 inet_pton(AF_INET
, buf
, &ipv4_ll
);
806 ipv6_ll_address_to_mac(address
, (u_char
*)mac
);
809 * Remove existed arp record for the interface as netlink
810 * protocol does not have update message types
812 * supported message types are RTM_NEWNEIGH and RTM_DELNEIGH
814 kernel_neigh_update (0, ifp
->ifindex
, ipv4_ll
.s_addr
, mac
, 6);
817 kernel_neigh_update (add
, ifp
->ifindex
, ipv4_ll
.s_addr
, mac
, 6);
818 zvrf
->neigh_updates
++;
821 static void if_nbr_ipv6ll_to_ipv4ll_neigh_add_all(struct interface
*ifp
)
823 if (listhead(ifp
->nbr_connected
)) {
824 struct nbr_connected
*nbr_connected
;
825 struct listnode
*node
;
827 for (ALL_LIST_ELEMENTS_RO(ifp
->nbr_connected
, node
,
829 if_nbr_ipv6ll_to_ipv4ll_neigh_update(
830 ifp
, &nbr_connected
->address
->u
.prefix6
, 1);
834 void if_nbr_ipv6ll_to_ipv4ll_neigh_del_all(struct interface
*ifp
)
836 if (listhead(ifp
->nbr_connected
)) {
837 struct nbr_connected
*nbr_connected
;
838 struct listnode
*node
;
840 for (ALL_LIST_ELEMENTS_RO(ifp
->nbr_connected
, node
,
842 if_nbr_ipv6ll_to_ipv4ll_neigh_update(
843 ifp
, &nbr_connected
->address
->u
.prefix6
, 0);
847 static void if_down_del_nbr_connected(struct interface
*ifp
)
849 struct nbr_connected
*nbr_connected
;
850 struct listnode
*node
, *nnode
;
852 for (ALL_LIST_ELEMENTS(ifp
->nbr_connected
, node
, nnode
,
854 listnode_delete(ifp
->nbr_connected
, nbr_connected
);
855 nbr_connected_free(nbr_connected
);
859 /* Interface is up. */
860 void if_up(struct interface
*ifp
)
862 struct zebra_if
*zif
;
863 struct interface
*link_if
;
867 quagga_timestamp(2, zif
->up_last
, sizeof(zif
->up_last
));
869 /* Notify the protocol daemons. */
870 if (ifp
->ptm_enable
&& (ifp
->ptm_status
== ZEBRA_PTM_STATUS_DOWN
)) {
871 zlog_warn("%s: interface %s hasn't passed ptm check\n",
872 __func__
, ifp
->name
);
875 zebra_interface_up_update(ifp
);
877 if_nbr_ipv6ll_to_ipv4ll_neigh_add_all(ifp
);
879 #if defined(HAVE_RTADV)
880 /* Enable fast tx of RA if enabled && RA interval is not in msecs */
881 if (zif
->rtadv
.AdvSendAdvertisements
882 && (zif
->rtadv
.MaxRtrAdvInterval
>= 1000)) {
883 zif
->rtadv
.inFastRexmit
= 1;
884 zif
->rtadv
.NumFastReXmitsRemain
= RTADV_NUM_FAST_REXMITS
;
888 /* Install connected routes to the kernel. */
889 if_install_connected(ifp
);
891 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
892 zlog_debug("%u: IF %s up, scheduling RIB processing",
893 ifp
->vrf_id
, ifp
->name
);
894 rib_update(ifp
->vrf_id
, RIB_UPDATE_IF_CHANGE
);
896 /* Handle interface up for specific types for EVPN. Non-VxLAN interfaces
897 * are checked to see if (remote) neighbor entries need to be installed
898 * on them for ARP suppression.
900 if (IS_ZEBRA_IF_VXLAN(ifp
))
901 zebra_vxlan_if_up(ifp
);
902 else if (IS_ZEBRA_IF_BRIDGE(ifp
)) {
904 zebra_vxlan_svi_up(ifp
, link_if
);
905 } else if (IS_ZEBRA_IF_VLAN(ifp
)) {
906 link_if
= if_lookup_by_index_per_ns(zebra_ns_lookup(NS_DEFAULT
),
909 zebra_vxlan_svi_up(ifp
, link_if
);
913 /* Interface goes down. We have to manage different behavior of based
915 void if_down(struct interface
*ifp
)
917 struct zebra_if
*zif
;
918 struct interface
*link_if
;
922 quagga_timestamp(2, zif
->down_last
, sizeof(zif
->down_last
));
924 /* Handle interface down for specific types for EVPN. Non-VxLAN
926 * are checked to see if (remote) neighbor entries need to be purged
927 * for ARP suppression.
929 if (IS_ZEBRA_IF_VXLAN(ifp
))
930 zebra_vxlan_if_down(ifp
);
931 else if (IS_ZEBRA_IF_BRIDGE(ifp
)) {
933 zebra_vxlan_svi_down(ifp
, link_if
);
934 } else if (IS_ZEBRA_IF_VLAN(ifp
)) {
935 link_if
= if_lookup_by_index_per_ns(zebra_ns_lookup(NS_DEFAULT
),
938 zebra_vxlan_svi_down(ifp
, link_if
);
942 /* Notify to the protocol daemons. */
943 zebra_interface_down_update(ifp
);
945 /* Uninstall connected routes from the kernel. */
946 if_uninstall_connected(ifp
);
948 if (IS_ZEBRA_DEBUG_RIB_DETAILED
)
949 zlog_debug("%u: IF %s down, scheduling RIB processing",
950 ifp
->vrf_id
, ifp
->name
);
951 rib_update(ifp
->vrf_id
, RIB_UPDATE_IF_CHANGE
);
953 if_nbr_ipv6ll_to_ipv4ll_neigh_del_all(ifp
);
955 /* Delete all neighbor addresses learnt through IPv6 RA */
956 if_down_del_nbr_connected(ifp
);
959 void if_refresh(struct interface
*ifp
)
964 void zebra_if_update_link(struct interface
*ifp
, ifindex_t link_ifindex
)
966 struct zebra_if
*zif
;
968 zif
= (struct zebra_if
*)ifp
->info
;
969 zif
->link_ifindex
= link_ifindex
;
970 zif
->link
= if_lookup_by_index_per_ns(zebra_ns_lookup(NS_DEFAULT
),
975 /* Output prefix string to vty. */
976 static int prefix_vty_out(struct vty
*vty
, struct prefix
*p
)
978 char str
[INET6_ADDRSTRLEN
];
980 inet_ntop(p
->family
, &p
->u
.prefix
, str
, sizeof(str
));
981 vty_out(vty
, "%s", str
);
985 /* Dump if address information to vty. */
986 static void connected_dump_vty(struct vty
*vty
, struct connected
*connected
)
990 /* Print interface address. */
991 p
= connected
->address
;
992 vty_out(vty
, " %s ", prefix_family_str(p
));
993 prefix_vty_out(vty
, p
);
994 vty_out(vty
, "/%d", p
->prefixlen
);
996 /* If there is destination address, print it. */
997 if (connected
->destination
) {
999 (CONNECTED_PEER(connected
) ? " peer " : " broadcast "));
1000 prefix_vty_out(vty
, connected
->destination
);
1001 if (CONNECTED_PEER(connected
))
1002 vty_out(vty
, "/%d", connected
->destination
->prefixlen
);
1005 if (CHECK_FLAG(connected
->flags
, ZEBRA_IFA_SECONDARY
))
1006 vty_out(vty
, " secondary");
1008 if (CHECK_FLAG(connected
->flags
, ZEBRA_IFA_UNNUMBERED
))
1009 vty_out(vty
, " unnumbered");
1011 if (connected
->label
)
1012 vty_out(vty
, " %s", connected
->label
);
1017 /* Dump interface neighbor address information to vty. */
1018 static void nbr_connected_dump_vty(struct vty
*vty
,
1019 struct nbr_connected
*connected
)
1023 /* Print interface address. */
1024 p
= connected
->address
;
1025 vty_out(vty
, " %s ", prefix_family_str(p
));
1026 prefix_vty_out(vty
, p
);
1027 vty_out(vty
, "/%d", p
->prefixlen
);
1032 static const char *zebra_ziftype_2str(zebra_iftype_t zif_type
)
1035 case ZEBRA_IF_OTHER
:
1039 case ZEBRA_IF_BRIDGE
:
1047 case ZEBRA_IF_VXLAN
:
1061 /* Interface's information print out to vty interface. */
1062 static void if_dump_vty(struct vty
*vty
, struct interface
*ifp
)
1064 struct connected
*connected
;
1065 struct nbr_connected
*nbr_connected
;
1066 struct listnode
*node
;
1067 struct route_node
*rn
;
1068 struct zebra_if
*zebra_if
;
1071 zebra_if
= ifp
->info
;
1073 vty_out(vty
, "Interface %s is ", ifp
->name
);
1074 if (if_is_up(ifp
)) {
1075 vty_out(vty
, "up, line protocol ");
1077 if (CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_LINKDETECTION
)) {
1078 if (if_is_running(ifp
))
1079 vty_out(vty
, "is up\n");
1081 vty_out(vty
, "is down\n");
1083 vty_out(vty
, "detection is disabled\n");
1086 vty_out(vty
, "down\n");
1089 vty_out(vty
, " Link ups: %5u last: %s\n", zebra_if
->up_count
,
1090 zebra_if
->up_last
[0] ? zebra_if
->up_last
: "(never)");
1091 vty_out(vty
, " Link downs: %5u last: %s\n", zebra_if
->down_count
,
1092 zebra_if
->down_last
[0] ? zebra_if
->down_last
: "(never)");
1094 zebra_ptm_show_status(vty
, ifp
);
1096 vrf
= vrf_lookup_by_id(ifp
->vrf_id
);
1097 vty_out(vty
, " vrf: %s\n", vrf
->name
);
1100 vty_out(vty
, " Description: %s\n", ifp
->desc
);
1101 if (ifp
->ifindex
== IFINDEX_INTERNAL
) {
1102 vty_out(vty
, " pseudo interface\n");
1104 } else if (!CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
)) {
1105 vty_out(vty
, " index %d inactive interface\n", ifp
->ifindex
);
1109 vty_out(vty
, " index %d metric %d mtu %d speed %u ", ifp
->ifindex
,
1110 ifp
->metric
, ifp
->mtu
, ifp
->speed
);
1111 if (ifp
->mtu6
!= ifp
->mtu
)
1112 vty_out(vty
, "mtu6 %d ", ifp
->mtu6
);
1113 vty_out(vty
, "\n flags: %s\n", if_flag_dump(ifp
->flags
));
1115 /* Hardware address. */
1116 vty_out(vty
, " Type: %s\n", if_link_type_str(ifp
->ll_type
));
1117 if (ifp
->hw_addr_len
!= 0) {
1120 vty_out(vty
, " HWaddr: ");
1121 for (i
= 0; i
< ifp
->hw_addr_len
; i
++)
1122 vty_out(vty
, "%s%02x", i
== 0 ? "" : ":",
1127 /* Bandwidth in Mbps */
1128 if (ifp
->bandwidth
!= 0) {
1129 vty_out(vty
, " bandwidth %u Mbps", ifp
->bandwidth
);
1133 for (rn
= route_top(zebra_if
->ipv4_subnets
); rn
; rn
= route_next(rn
)) {
1137 for (ALL_LIST_ELEMENTS_RO((struct list
*)rn
->info
, node
,
1139 connected_dump_vty(vty
, connected
);
1142 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, node
, connected
)) {
1143 if (CHECK_FLAG(connected
->conf
, ZEBRA_IFC_REAL
)
1144 && (connected
->address
->family
== AF_INET6
))
1145 connected_dump_vty(vty
, connected
);
1148 vty_out(vty
, " Interface Type %s\n",
1149 zebra_ziftype_2str(zebra_if
->zif_type
));
1150 if (IS_ZEBRA_IF_BRIDGE(ifp
)) {
1151 struct zebra_l2info_bridge
*bridge_info
;
1153 bridge_info
= &zebra_if
->l2info
.br
;
1154 vty_out(vty
, " Bridge VLAN-aware: %s\n",
1155 bridge_info
->vlan_aware
? "yes" : "no");
1156 } else if (IS_ZEBRA_IF_VLAN(ifp
)) {
1157 struct zebra_l2info_vlan
*vlan_info
;
1159 vlan_info
= &zebra_if
->l2info
.vl
;
1160 vty_out(vty
, " VLAN Id %u\n", vlan_info
->vid
);
1161 } else if (IS_ZEBRA_IF_VXLAN(ifp
)) {
1162 struct zebra_l2info_vxlan
*vxlan_info
;
1164 vxlan_info
= &zebra_if
->l2info
.vxl
;
1165 vty_out(vty
, " VxLAN Id %u", vxlan_info
->vni
);
1166 if (vxlan_info
->vtep_ip
.s_addr
!= INADDR_ANY
)
1167 vty_out(vty
, " VTEP IP: %s",
1168 inet_ntoa(vxlan_info
->vtep_ip
));
1169 if (vxlan_info
->access_vlan
)
1170 vty_out(vty
, " Access VLAN Id %u",
1171 vxlan_info
->access_vlan
);
1175 if (IS_ZEBRA_IF_BRIDGE_SLAVE(ifp
)) {
1176 struct zebra_l2info_brslave
*br_slave
;
1178 br_slave
= &zebra_if
->brslave_info
;
1179 if (br_slave
->bridge_ifindex
!= IFINDEX_INTERNAL
)
1180 vty_out(vty
, " Master (bridge) ifindex %u\n",
1181 br_slave
->bridge_ifindex
);
1184 if (zebra_if
->link_ifindex
!= IFINDEX_INTERNAL
)
1185 vty_out(vty
, " Link ifindex %u\n", zebra_if
->link_ifindex
);
1187 if (HAS_LINK_PARAMS(ifp
)) {
1189 struct if_link_params
*iflp
= ifp
->link_params
;
1190 vty_out(vty
, " Traffic Engineering Link Parameters:\n");
1191 if (IS_PARAM_SET(iflp
, LP_TE_METRIC
))
1192 vty_out(vty
, " TE metric %u\n", iflp
->te_metric
);
1193 if (IS_PARAM_SET(iflp
, LP_MAX_BW
))
1194 vty_out(vty
, " Maximum Bandwidth %g (Byte/s)\n",
1196 if (IS_PARAM_SET(iflp
, LP_MAX_RSV_BW
))
1198 " Maximum Reservable Bandwidth %g (Byte/s)\n",
1200 if (IS_PARAM_SET(iflp
, LP_UNRSV_BW
)) {
1202 " Unreserved Bandwidth per Class Type in Byte/s:\n");
1203 for (i
= 0; i
< MAX_CLASS_TYPE
; i
+= 2)
1205 " [%d]: %g (Bytes/sec),\t[%d]: %g (Bytes/sec)\n",
1206 i
, iflp
->unrsv_bw
[i
], i
+ 1,
1207 iflp
->unrsv_bw
[i
+ 1]);
1210 if (IS_PARAM_SET(iflp
, LP_ADM_GRP
))
1211 vty_out(vty
, " Administrative Group:%u\n",
1213 if (IS_PARAM_SET(iflp
, LP_DELAY
)) {
1214 vty_out(vty
, " Link Delay Average: %u (micro-sec.)",
1216 if (IS_PARAM_SET(iflp
, LP_MM_DELAY
)) {
1217 vty_out(vty
, " Min: %u (micro-sec.)",
1219 vty_out(vty
, " Max: %u (micro-sec.)",
1224 if (IS_PARAM_SET(iflp
, LP_DELAY_VAR
))
1226 " Link Delay Variation %u (micro-sec.)\n",
1228 if (IS_PARAM_SET(iflp
, LP_PKT_LOSS
))
1229 vty_out(vty
, " Link Packet Loss %g (in %%)\n",
1231 if (IS_PARAM_SET(iflp
, LP_AVA_BW
))
1232 vty_out(vty
, " Available Bandwidth %g (Byte/s)\n",
1234 if (IS_PARAM_SET(iflp
, LP_RES_BW
))
1235 vty_out(vty
, " Residual Bandwidth %g (Byte/s)\n",
1237 if (IS_PARAM_SET(iflp
, LP_USE_BW
))
1238 vty_out(vty
, " Utilized Bandwidth %g (Byte/s)\n",
1240 if (IS_PARAM_SET(iflp
, LP_RMT_AS
))
1241 vty_out(vty
, " Neighbor ASBR IP: %s AS: %u \n",
1242 inet_ntoa(iflp
->rmt_ip
), iflp
->rmt_as
);
1245 hook_call(zebra_if_extra_info
, vty
, ifp
);
1247 if (listhead(ifp
->nbr_connected
))
1248 vty_out(vty
, " Neighbor address(s):\n");
1249 for (ALL_LIST_ELEMENTS_RO(ifp
->nbr_connected
, node
, nbr_connected
))
1250 nbr_connected_dump_vty(vty
, nbr_connected
);
1252 #ifdef HAVE_PROC_NET_DEV
1253 /* Statistics print out using proc file system. */
1255 " %lu input packets (%lu multicast), %lu bytes, "
1257 ifp
->stats
.rx_packets
, ifp
->stats
.rx_multicast
,
1258 ifp
->stats
.rx_bytes
, ifp
->stats
.rx_dropped
);
1261 " %lu input errors, %lu length, %lu overrun,"
1262 " %lu CRC, %lu frame\n",
1263 ifp
->stats
.rx_errors
, ifp
->stats
.rx_length_errors
,
1264 ifp
->stats
.rx_over_errors
, ifp
->stats
.rx_crc_errors
,
1265 ifp
->stats
.rx_frame_errors
);
1267 vty_out(vty
, " %lu fifo, %lu missed\n", ifp
->stats
.rx_fifo_errors
,
1268 ifp
->stats
.rx_missed_errors
);
1270 vty_out(vty
, " %lu output packets, %lu bytes, %lu dropped\n",
1271 ifp
->stats
.tx_packets
, ifp
->stats
.tx_bytes
,
1272 ifp
->stats
.tx_dropped
);
1275 " %lu output errors, %lu aborted, %lu carrier,"
1276 " %lu fifo, %lu heartbeat\n",
1277 ifp
->stats
.tx_errors
, ifp
->stats
.tx_aborted_errors
,
1278 ifp
->stats
.tx_carrier_errors
, ifp
->stats
.tx_fifo_errors
,
1279 ifp
->stats
.tx_heartbeat_errors
);
1281 vty_out(vty
, " %lu window, %lu collisions\n",
1282 ifp
->stats
.tx_window_errors
, ifp
->stats
.collisions
);
1283 #endif /* HAVE_PROC_NET_DEV */
1285 #ifdef HAVE_NET_RT_IFLIST
1286 #if defined(__bsdi__) || defined(__NetBSD__)
1287 /* Statistics print out using sysctl (). */
1289 " input packets %llu, bytes %llu, dropped %llu,"
1290 " multicast packets %llu\n",
1291 (unsigned long long)ifp
->stats
.ifi_ipackets
,
1292 (unsigned long long)ifp
->stats
.ifi_ibytes
,
1293 (unsigned long long)ifp
->stats
.ifi_iqdrops
,
1294 (unsigned long long)ifp
->stats
.ifi_imcasts
);
1296 vty_out(vty
, " input errors %llu\n",
1297 (unsigned long long)ifp
->stats
.ifi_ierrors
);
1300 " output packets %llu, bytes %llu,"
1301 " multicast packets %llu\n",
1302 (unsigned long long)ifp
->stats
.ifi_opackets
,
1303 (unsigned long long)ifp
->stats
.ifi_obytes
,
1304 (unsigned long long)ifp
->stats
.ifi_omcasts
);
1306 vty_out(vty
, " output errors %llu\n",
1307 (unsigned long long)ifp
->stats
.ifi_oerrors
);
1309 vty_out(vty
, " collisions %llu\n",
1310 (unsigned long long)ifp
->stats
.ifi_collisions
);
1312 /* Statistics print out using sysctl (). */
1314 " input packets %lu, bytes %lu, dropped %lu,"
1315 " multicast packets %lu\n",
1316 ifp
->stats
.ifi_ipackets
, ifp
->stats
.ifi_ibytes
,
1317 ifp
->stats
.ifi_iqdrops
, ifp
->stats
.ifi_imcasts
);
1319 vty_out(vty
, " input errors %lu\n", ifp
->stats
.ifi_ierrors
);
1322 " output packets %lu, bytes %lu, multicast packets %lu\n",
1323 ifp
->stats
.ifi_opackets
, ifp
->stats
.ifi_obytes
,
1324 ifp
->stats
.ifi_omcasts
);
1326 vty_out(vty
, " output errors %lu\n", ifp
->stats
.ifi_oerrors
);
1328 vty_out(vty
, " collisions %lu\n", ifp
->stats
.ifi_collisions
);
1329 #endif /* __bsdi__ || __NetBSD__ */
1330 #endif /* HAVE_NET_RT_IFLIST */
1333 static void interface_update_stats(void)
1335 #ifdef HAVE_PROC_NET_DEV
1336 /* If system has interface statistics via proc file system, update
1338 ifstat_update_proc();
1339 #endif /* HAVE_PROC_NET_DEV */
1340 #ifdef HAVE_NET_RT_IFLIST
1341 ifstat_update_sysctl();
1342 #endif /* HAVE_NET_RT_IFLIST */
1345 struct cmd_node interface_node
= {INTERFACE_NODE
, "%s(config-if)# ", 1};
1347 /* Show all interfaces to vty. */
1348 DEFUN (show_interface
,
1350 "show interface [vrf NAME]",
1352 "Interface status and configuration\n"
1356 struct interface
*ifp
;
1357 vrf_id_t vrf_id
= VRF_DEFAULT
;
1359 interface_update_stats();
1362 VRF_GET_ID(vrf_id
, argv
[3]->arg
);
1364 /* All interface print. */
1365 vrf
= vrf_lookup_by_id(vrf_id
);
1366 FOR_ALL_INTERFACES (vrf
, ifp
)
1367 if_dump_vty(vty
, ifp
);
1373 /* Show all interfaces to vty. */
1374 DEFUN (show_interface_vrf_all
,
1375 show_interface_vrf_all_cmd
,
1376 "show interface vrf all",
1378 "Interface status and configuration\n"
1379 VRF_ALL_CMD_HELP_STR
)
1382 struct interface
*ifp
;
1384 interface_update_stats();
1386 /* All interface print. */
1387 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
1388 FOR_ALL_INTERFACES (vrf
, ifp
)
1389 if_dump_vty(vty
, ifp
);
1394 /* Show specified interface to vty. */
1396 DEFUN (show_interface_name_vrf
,
1397 show_interface_name_vrf_cmd
,
1398 "show interface IFNAME vrf NAME",
1400 "Interface status and configuration\n"
1406 struct interface
*ifp
;
1407 vrf_id_t vrf_id
= VRF_DEFAULT
;
1409 interface_update_stats();
1411 VRF_GET_ID(vrf_id
, argv
[idx_name
]->arg
);
1413 /* Specified interface print. */
1414 ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
, vrf_id
);
1416 vty_out(vty
, "%% Can't find interface %s\n",
1417 argv
[idx_ifname
]->arg
);
1420 if_dump_vty(vty
, ifp
);
1425 /* Show specified interface to vty. */
1426 DEFUN (show_interface_name_vrf_all
,
1427 show_interface_name_vrf_all_cmd
,
1428 "show interface IFNAME [vrf all]",
1430 "Interface status and configuration\n"
1432 VRF_ALL_CMD_HELP_STR
)
1436 struct interface
*ifp
;
1439 interface_update_stats();
1441 /* All interface print. */
1442 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
1443 /* Specified interface print. */
1444 ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
, vrf
->vrf_id
);
1446 if_dump_vty(vty
, ifp
);
1452 vty_out(vty
, "%% Can't find interface %s\n",
1453 argv
[idx_ifname
]->arg
);
1461 static void if_show_description(struct vty
*vty
, vrf_id_t vrf_id
)
1463 struct vrf
*vrf
= vrf_lookup_by_id(vrf_id
);
1464 struct interface
*ifp
;
1466 vty_out(vty
, "Interface Status Protocol Description\n");
1467 FOR_ALL_INTERFACES (vrf
, ifp
) {
1470 len
= vty_out(vty
, "%s", ifp
->name
);
1471 vty_out(vty
, "%*s", (16 - len
), " ");
1473 if (if_is_up(ifp
)) {
1474 vty_out(vty
, "up ");
1475 if (CHECK_FLAG(ifp
->status
,
1476 ZEBRA_INTERFACE_LINKDETECTION
)) {
1477 if (if_is_running(ifp
))
1478 vty_out(vty
, "up ");
1480 vty_out(vty
, "down ");
1482 vty_out(vty
, "unknown ");
1485 vty_out(vty
, "down down ");
1489 vty_out(vty
, "%s", ifp
->desc
);
1494 DEFUN (show_interface_desc
,
1495 show_interface_desc_cmd
,
1496 "show interface description [vrf NAME]",
1498 "Interface status and configuration\n"
1499 "Interface description\n"
1502 vrf_id_t vrf_id
= VRF_DEFAULT
;
1505 VRF_GET_ID(vrf_id
, argv
[4]->arg
);
1507 if_show_description(vty
, vrf_id
);
1513 DEFUN (show_interface_desc_vrf_all
,
1514 show_interface_desc_vrf_all_cmd
,
1515 "show interface description vrf all",
1517 "Interface status and configuration\n"
1518 "Interface description\n"
1519 VRF_ALL_CMD_HELP_STR
)
1523 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
1524 if (!RB_EMPTY (if_name_head
, &vrf
->ifaces_by_name
)) {
1525 vty_out(vty
, "\n\tVRF %u\n\n", vrf
->vrf_id
);
1526 if_show_description(vty
, vrf
->vrf_id
);
1535 "Set multicast flag to interface\n")
1537 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1539 struct zebra_if
*if_data
;
1541 if (CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
)) {
1542 ret
= if_set_flags(ifp
, IFF_MULTICAST
);
1544 vty_out(vty
, "Can't set multicast flag\n");
1545 return CMD_WARNING_CONFIG_FAILED
;
1549 if_data
= ifp
->info
;
1550 if_data
->multicast
= IF_ZEBRA_MULTICAST_ON
;
1555 DEFUN (no_multicast
,
1559 "Unset multicast flag to interface\n")
1561 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1563 struct zebra_if
*if_data
;
1565 if (CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
)) {
1566 ret
= if_unset_flags(ifp
, IFF_MULTICAST
);
1568 vty_out(vty
, "Can't unset multicast flag\n");
1569 return CMD_WARNING_CONFIG_FAILED
;
1573 if_data
= ifp
->info
;
1574 if_data
->multicast
= IF_ZEBRA_MULTICAST_OFF
;
1582 "Enable link detection on interface\n")
1584 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1585 int if_was_operative
;
1587 if_was_operative
= if_is_no_ptm_operative(ifp
);
1588 SET_FLAG(ifp
->status
, ZEBRA_INTERFACE_LINKDETECTION
);
1590 /* When linkdetection is enabled, if might come down */
1591 if (!if_is_no_ptm_operative(ifp
) && if_was_operative
)
1594 /* FIXME: Will defer status change forwarding if interface
1595 does not come down! */
1601 DEFUN (no_linkdetect
,
1605 "Disable link detection on interface\n")
1607 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1608 int if_was_operative
;
1610 if_was_operative
= if_is_no_ptm_operative(ifp
);
1611 UNSET_FLAG(ifp
->status
, ZEBRA_INTERFACE_LINKDETECTION
);
1613 /* Interface may come up after disabling link detection */
1614 if (if_is_operative(ifp
) && !if_was_operative
)
1617 /* FIXME: see linkdetect_cmd */
1625 "Shutdown the selected interface\n")
1627 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1629 struct zebra_if
*if_data
;
1631 if (ifp
->ifindex
!= IFINDEX_INTERNAL
) {
1632 ret
= if_unset_flags(ifp
, IFF_UP
);
1634 vty_out(vty
, "Can't shutdown interface\n");
1635 return CMD_WARNING_CONFIG_FAILED
;
1639 if_data
= ifp
->info
;
1640 if_data
->shutdown
= IF_ZEBRA_SHUTDOWN_ON
;
1645 DEFUN (no_shutdown_if
,
1649 "Shutdown the selected interface\n")
1651 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1653 struct zebra_if
*if_data
;
1655 if (ifp
->ifindex
!= IFINDEX_INTERNAL
) {
1656 ret
= if_set_flags(ifp
, IFF_UP
| IFF_RUNNING
);
1658 vty_out(vty
, "Can't up interface\n");
1659 return CMD_WARNING_CONFIG_FAILED
;
1663 /* Some addresses (in particular, IPv6 addresses on Linux) get
1664 * removed when the interface goes down. They need to be
1667 if_addr_wakeup(ifp
);
1670 if_data
= ifp
->info
;
1671 if_data
->shutdown
= IF_ZEBRA_SHUTDOWN_OFF
;
1676 DEFUN (bandwidth_if
,
1678 "bandwidth (1-100000)",
1679 "Set bandwidth informational parameter\n"
1680 "Bandwidth in megabits\n")
1683 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1684 unsigned int bandwidth
;
1686 bandwidth
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
1688 /* bandwidth range is <1-100000> */
1689 if (bandwidth
< 1 || bandwidth
> 100000) {
1690 vty_out(vty
, "Bandwidth is invalid\n");
1691 return CMD_WARNING_CONFIG_FAILED
;
1694 ifp
->bandwidth
= bandwidth
;
1696 /* force protocols to recalculate routes due to cost change */
1697 if (if_is_operative(ifp
))
1698 zebra_interface_up_update(ifp
);
1703 DEFUN (no_bandwidth_if
,
1704 no_bandwidth_if_cmd
,
1705 "no bandwidth [(1-100000)]",
1707 "Set bandwidth informational parameter\n"
1708 "Bandwidth in megabits\n")
1710 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1714 /* force protocols to recalculate routes due to cost change */
1715 if (if_is_operative(ifp
))
1716 zebra_interface_up_update(ifp
);
1722 struct cmd_node link_params_node
= {
1723 LINK_PARAMS_NODE
, "%s(config-link-params)# ", 1,
1726 static void link_param_cmd_set_uint32(struct interface
*ifp
, uint32_t *field
,
1727 uint32_t type
, uint32_t value
)
1729 /* Update field as needed */
1730 if (IS_PARAM_UNSET(ifp
->link_params
, type
) || *field
!= value
) {
1732 SET_PARAM(ifp
->link_params
, type
);
1734 /* force protocols to update LINK STATE due to parameters change
1736 if (if_is_operative(ifp
))
1737 zebra_interface_parameters_update(ifp
);
1740 static void link_param_cmd_set_float(struct interface
*ifp
, float *field
,
1741 uint32_t type
, float value
)
1744 /* Update field as needed */
1745 if (IS_PARAM_UNSET(ifp
->link_params
, type
) || *field
!= value
) {
1747 SET_PARAM(ifp
->link_params
, type
);
1749 /* force protocols to update LINK STATE due to parameters change
1751 if (if_is_operative(ifp
))
1752 zebra_interface_parameters_update(ifp
);
1756 static void link_param_cmd_unset(struct interface
*ifp
, uint32_t type
)
1758 if (ifp
->link_params
== NULL
)
1762 UNSET_PARAM(ifp
->link_params
, type
);
1764 /* force protocols to update LINK STATE due to parameters change */
1765 if (if_is_operative(ifp
))
1766 zebra_interface_parameters_update(ifp
);
1769 DEFUN_NOSH (link_params
,
1774 /* vty->qobj_index stays the same @ interface pointer */
1775 vty
->node
= LINK_PARAMS_NODE
;
1780 DEFUN_NOSH (exit_link_params
,
1781 exit_link_params_cmd
,
1783 "Exit from Link Params configuration mode\n")
1785 if (vty
->node
== LINK_PARAMS_NODE
)
1786 vty
->node
= INTERFACE_NODE
;
1790 /* Specific Traffic Engineering parameters commands */
1791 DEFUN (link_params_enable
,
1792 link_params_enable_cmd
,
1794 "Activate link parameters on this interface\n")
1796 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1798 /* This command could be issue at startup, when activate MPLS TE */
1799 /* on a new interface or after a ON / OFF / ON toggle */
1800 /* In all case, TE parameters are reset to their default factory */
1801 if (IS_ZEBRA_DEBUG_EVENT
)
1803 "Link-params: enable TE link parameters on interface %s",
1806 if (!if_link_params_get(ifp
)) {
1807 if (IS_ZEBRA_DEBUG_EVENT
)
1809 "Link-params: failed to init TE link parameters %s",
1812 return CMD_WARNING_CONFIG_FAILED
;
1815 /* force protocols to update LINK STATE due to parameters change */
1816 if (if_is_operative(ifp
))
1817 zebra_interface_parameters_update(ifp
);
1822 DEFUN (no_link_params_enable
,
1823 no_link_params_enable_cmd
,
1826 "Disable link parameters on this interface\n")
1828 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1830 zlog_debug("MPLS-TE: disable TE link parameters on interface %s",
1833 if_link_params_free(ifp
);
1835 /* force protocols to update LINK STATE due to parameters change */
1836 if (if_is_operative(ifp
))
1837 zebra_interface_parameters_update(ifp
);
1842 /* STANDARD TE metrics */
1843 DEFUN (link_params_metric
,
1844 link_params_metric_cmd
,
1845 "metric (0-4294967295)",
1846 "Link metric for MPLS-TE purpose\n"
1847 "Metric value in decimal\n")
1850 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1851 struct if_link_params
*iflp
= if_link_params_get(ifp
);
1854 metric
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1856 /* Update TE metric if needed */
1857 link_param_cmd_set_uint32(ifp
, &iflp
->te_metric
, LP_TE_METRIC
, metric
);
1862 DEFUN (no_link_params_metric
,
1863 no_link_params_metric_cmd
,
1866 "Disable Link Metric on this interface\n")
1868 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1870 /* Unset TE Metric */
1871 link_param_cmd_unset(ifp
, LP_TE_METRIC
);
1876 DEFUN (link_params_maxbw
,
1877 link_params_maxbw_cmd
,
1879 "Maximum bandwidth that can be used\n"
1880 "Bytes/second (IEEE floating point format)\n")
1882 int idx_bandwidth
= 1;
1883 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1884 struct if_link_params
*iflp
= if_link_params_get(ifp
);
1888 if (sscanf(argv
[idx_bandwidth
]->arg
, "%g", &bw
) != 1) {
1889 vty_out(vty
, "link_params_maxbw: fscanf: %s\n",
1890 safe_strerror(errno
));
1891 return CMD_WARNING_CONFIG_FAILED
;
1894 /* Check that Maximum bandwidth is not lower than other bandwidth
1896 if ((bw
<= iflp
->max_rsv_bw
) || (bw
<= iflp
->unrsv_bw
[0])
1897 || (bw
<= iflp
->unrsv_bw
[1]) || (bw
<= iflp
->unrsv_bw
[2])
1898 || (bw
<= iflp
->unrsv_bw
[3]) || (bw
<= iflp
->unrsv_bw
[4])
1899 || (bw
<= iflp
->unrsv_bw
[5]) || (bw
<= iflp
->unrsv_bw
[6])
1900 || (bw
<= iflp
->unrsv_bw
[7]) || (bw
<= iflp
->ava_bw
)
1901 || (bw
<= iflp
->res_bw
) || (bw
<= iflp
->use_bw
)) {
1903 "Maximum Bandwidth could not be lower than others bandwidth\n");
1904 return CMD_WARNING_CONFIG_FAILED
;
1907 /* Update Maximum Bandwidth if needed */
1908 link_param_cmd_set_float(ifp
, &iflp
->max_bw
, LP_MAX_BW
, bw
);
1913 DEFUN (link_params_max_rsv_bw
,
1914 link_params_max_rsv_bw_cmd
,
1915 "max-rsv-bw BANDWIDTH",
1916 "Maximum bandwidth that may be reserved\n"
1917 "Bytes/second (IEEE floating point format)\n")
1919 int idx_bandwidth
= 1;
1920 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1921 struct if_link_params
*iflp
= if_link_params_get(ifp
);
1924 if (sscanf(argv
[idx_bandwidth
]->arg
, "%g", &bw
) != 1) {
1925 vty_out(vty
, "link_params_max_rsv_bw: fscanf: %s\n",
1926 safe_strerror(errno
));
1927 return CMD_WARNING_CONFIG_FAILED
;
1930 /* Check that bandwidth is not greater than maximum bandwidth parameter
1932 if (bw
> iflp
->max_bw
) {
1934 "Maximum Reservable Bandwidth could not be greater than Maximum Bandwidth (%g)\n",
1936 return CMD_WARNING_CONFIG_FAILED
;
1939 /* Update Maximum Reservable Bandwidth if needed */
1940 link_param_cmd_set_float(ifp
, &iflp
->max_rsv_bw
, LP_MAX_RSV_BW
, bw
);
1945 DEFUN (link_params_unrsv_bw
,
1946 link_params_unrsv_bw_cmd
,
1947 "unrsv-bw (0-7) BANDWIDTH",
1948 "Unreserved bandwidth at each priority level\n"
1950 "Bytes/second (IEEE floating point format)\n")
1953 int idx_bandwidth
= 2;
1954 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1955 struct if_link_params
*iflp
= if_link_params_get(ifp
);
1959 /* We don't have to consider about range check here. */
1960 if (sscanf(argv
[idx_number
]->arg
, "%d", &priority
) != 1) {
1961 vty_out(vty
, "link_params_unrsv_bw: fscanf: %s\n",
1962 safe_strerror(errno
));
1963 return CMD_WARNING_CONFIG_FAILED
;
1966 if (sscanf(argv
[idx_bandwidth
]->arg
, "%g", &bw
) != 1) {
1967 vty_out(vty
, "link_params_unrsv_bw: fscanf: %s\n",
1968 safe_strerror(errno
));
1969 return CMD_WARNING_CONFIG_FAILED
;
1972 /* Check that bandwidth is not greater than maximum bandwidth parameter
1974 if (bw
> iflp
->max_bw
) {
1976 "UnReserved Bandwidth could not be greater than Maximum Bandwidth (%g)\n",
1978 return CMD_WARNING_CONFIG_FAILED
;
1981 /* Update Unreserved Bandwidth if needed */
1982 link_param_cmd_set_float(ifp
, &iflp
->unrsv_bw
[priority
], LP_UNRSV_BW
,
1988 DEFUN (link_params_admin_grp
,
1989 link_params_admin_grp_cmd
,
1990 "admin-grp BITPATTERN",
1991 "Administrative group membership\n"
1992 "32-bit Hexadecimal value (e.g. 0xa1)\n")
1994 int idx_bitpattern
= 1;
1995 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1996 struct if_link_params
*iflp
= if_link_params_get(ifp
);
1997 unsigned long value
;
1999 if (sscanf(argv
[idx_bitpattern
]->arg
, "0x%lx", &value
) != 1) {
2000 vty_out(vty
, "link_params_admin_grp: fscanf: %s\n",
2001 safe_strerror(errno
));
2002 return CMD_WARNING_CONFIG_FAILED
;
2005 /* Update Administrative Group if needed */
2006 link_param_cmd_set_uint32(ifp
, &iflp
->admin_grp
, LP_ADM_GRP
, value
);
2011 DEFUN (no_link_params_admin_grp
,
2012 no_link_params_admin_grp_cmd
,
2015 "Disable Administrative group membership on this interface\n")
2017 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2019 /* Unset Admin Group */
2020 link_param_cmd_unset(ifp
, LP_ADM_GRP
);
2025 /* RFC5392 & RFC5316: INTER-AS */
2026 DEFUN (link_params_inter_as
,
2027 link_params_inter_as_cmd
,
2028 "neighbor A.B.C.D as (1-4294967295)",
2029 "Configure remote ASBR information (Neighbor IP address and AS number)\n"
2030 "Remote IP address in dot decimal A.B.C.D\n"
2031 "Remote AS number\n"
2032 "AS number in the range <1-4294967295>\n")
2037 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2038 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2039 struct in_addr addr
;
2042 if (!inet_aton(argv
[idx_ipv4
]->arg
, &addr
)) {
2043 vty_out(vty
, "Please specify Router-Addr by A.B.C.D\n");
2044 return CMD_WARNING_CONFIG_FAILED
;
2047 as
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2049 /* Update Remote IP and Remote AS fields if needed */
2050 if (IS_PARAM_UNSET(iflp
, LP_RMT_AS
) || iflp
->rmt_as
!= as
2051 || iflp
->rmt_ip
.s_addr
!= addr
.s_addr
) {
2054 iflp
->rmt_ip
.s_addr
= addr
.s_addr
;
2055 SET_PARAM(iflp
, LP_RMT_AS
);
2057 /* force protocols to update LINK STATE due to parameters change
2059 if (if_is_operative(ifp
))
2060 zebra_interface_parameters_update(ifp
);
2065 DEFUN (no_link_params_inter_as
,
2066 no_link_params_inter_as_cmd
,
2069 "Remove Neighbor IP address and AS number for Inter-AS TE\n")
2071 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2072 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2074 /* Reset Remote IP and AS neighbor */
2076 iflp
->rmt_ip
.s_addr
= 0;
2077 UNSET_PARAM(iflp
, LP_RMT_AS
);
2079 /* force protocols to update LINK STATE due to parameters change */
2080 if (if_is_operative(ifp
))
2081 zebra_interface_parameters_update(ifp
);
2086 /* RFC7471: OSPF Traffic Engineering (TE) Metric extensions &
2087 * draft-ietf-isis-metric-extensions-07.txt */
2088 DEFUN (link_params_delay
,
2089 link_params_delay_cmd
,
2090 "delay (0-16777215) [min (0-16777215) max (0-16777215)]",
2091 "Unidirectional Average Link Delay\n"
2092 "Average delay in micro-second as decimal (0...16777215)\n"
2094 "Minimum delay in micro-second as decimal (0...16777215)\n"
2096 "Maximum delay in micro-second as decimal (0...16777215)\n")
2098 /* Get and Check new delay values */
2099 u_int32_t delay
= 0, low
= 0, high
= 0;
2100 delay
= strtoul(argv
[1]->arg
, NULL
, 10);
2102 low
= strtoul(argv
[3]->arg
, NULL
, 10);
2103 high
= strtoul(argv
[5]->arg
, NULL
, 10);
2106 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2107 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2108 u_int8_t update
= 0;
2111 /* Check new delay value against old Min and Max delays if set
2113 if (IS_PARAM_SET(iflp
, LP_MM_DELAY
)
2114 && (delay
<= iflp
->min_delay
|| delay
>= iflp
->max_delay
)) {
2116 "Average delay should be comprise between Min (%d) and Max (%d) delay\n",
2117 iflp
->min_delay
, iflp
->max_delay
);
2118 return CMD_WARNING_CONFIG_FAILED
;
2120 /* Update delay if value is not set or change */
2121 if (IS_PARAM_UNSET(iflp
, LP_DELAY
) || iflp
->av_delay
!= delay
) {
2122 iflp
->av_delay
= delay
;
2123 SET_PARAM(iflp
, LP_DELAY
);
2126 /* Unset Min and Max delays if already set */
2127 if (IS_PARAM_SET(iflp
, LP_MM_DELAY
)) {
2128 iflp
->min_delay
= 0;
2129 iflp
->max_delay
= 0;
2130 UNSET_PARAM(iflp
, LP_MM_DELAY
);
2134 /* Check new delays value coherency */
2135 if (delay
<= low
|| delay
>= high
) {
2137 "Average delay should be comprise between Min (%d) and Max (%d) delay\n",
2139 return CMD_WARNING_CONFIG_FAILED
;
2141 /* Update Delays if needed */
2142 if (IS_PARAM_UNSET(iflp
, LP_DELAY
)
2143 || IS_PARAM_UNSET(iflp
, LP_MM_DELAY
)
2144 || iflp
->av_delay
!= delay
|| iflp
->min_delay
!= low
2145 || iflp
->max_delay
!= high
) {
2146 iflp
->av_delay
= delay
;
2147 SET_PARAM(iflp
, LP_DELAY
);
2148 iflp
->min_delay
= low
;
2149 iflp
->max_delay
= high
;
2150 SET_PARAM(iflp
, LP_MM_DELAY
);
2155 /* force protocols to update LINK STATE due to parameters change */
2156 if (update
== 1 && if_is_operative(ifp
))
2157 zebra_interface_parameters_update(ifp
);
2162 DEFUN (no_link_params_delay
,
2163 no_link_params_delay_cmd
,
2166 "Disable Unidirectional Average, Min & Max Link Delay on this interface\n")
2168 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2169 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2173 UNSET_PARAM(iflp
, LP_DELAY
);
2174 iflp
->min_delay
= 0;
2175 iflp
->max_delay
= 0;
2176 UNSET_PARAM(iflp
, LP_MM_DELAY
);
2178 /* force protocols to update LINK STATE due to parameters change */
2179 if (if_is_operative(ifp
))
2180 zebra_interface_parameters_update(ifp
);
2185 DEFUN (link_params_delay_var
,
2186 link_params_delay_var_cmd
,
2187 "delay-variation (0-16777215)",
2188 "Unidirectional Link Delay Variation\n"
2189 "delay variation in micro-second as decimal (0...16777215)\n")
2192 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2193 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2196 value
= strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2198 /* Update Delay Variation if needed */
2199 link_param_cmd_set_uint32(ifp
, &iflp
->delay_var
, LP_DELAY_VAR
, value
);
2204 DEFUN (no_link_params_delay_var
,
2205 no_link_params_delay_var_cmd
,
2206 "no delay-variation",
2208 "Disable Unidirectional Delay Variation on this interface\n")
2210 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2212 /* Unset Delay Variation */
2213 link_param_cmd_unset(ifp
, LP_DELAY_VAR
);
2218 DEFUN (link_params_pkt_loss
,
2219 link_params_pkt_loss_cmd
,
2220 "packet-loss PERCENTAGE",
2221 "Unidirectional Link Packet Loss\n"
2222 "percentage of total traffic by 0.000003% step and less than 50.331642%\n")
2224 int idx_percentage
= 1;
2225 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2226 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2229 if (sscanf(argv
[idx_percentage
]->arg
, "%g", &fval
) != 1) {
2230 vty_out(vty
, "link_params_pkt_loss: fscanf: %s\n",
2231 safe_strerror(errno
));
2232 return CMD_WARNING_CONFIG_FAILED
;
2235 if (fval
> MAX_PKT_LOSS
)
2236 fval
= MAX_PKT_LOSS
;
2238 /* Update Packet Loss if needed */
2239 link_param_cmd_set_float(ifp
, &iflp
->pkt_loss
, LP_PKT_LOSS
, fval
);
2244 DEFUN (no_link_params_pkt_loss
,
2245 no_link_params_pkt_loss_cmd
,
2248 "Disable Unidirectional Link Packet Loss on this interface\n")
2250 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2252 /* Unset Packet Loss */
2253 link_param_cmd_unset(ifp
, LP_PKT_LOSS
);
2258 DEFUN (link_params_res_bw
,
2259 link_params_res_bw_cmd
,
2261 "Unidirectional Residual Bandwidth\n"
2262 "Bytes/second (IEEE floating point format)\n")
2264 int idx_bandwidth
= 1;
2265 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2266 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2269 if (sscanf(argv
[idx_bandwidth
]->arg
, "%g", &bw
) != 1) {
2270 vty_out(vty
, "link_params_res_bw: fscanf: %s\n",
2271 safe_strerror(errno
));
2272 return CMD_WARNING_CONFIG_FAILED
;
2275 /* Check that bandwidth is not greater than maximum bandwidth parameter
2277 if (bw
> iflp
->max_bw
) {
2279 "Residual Bandwidth could not be greater than Maximum Bandwidth (%g)\n",
2281 return CMD_WARNING_CONFIG_FAILED
;
2284 /* Update Residual Bandwidth if needed */
2285 link_param_cmd_set_float(ifp
, &iflp
->res_bw
, LP_RES_BW
, bw
);
2290 DEFUN (no_link_params_res_bw
,
2291 no_link_params_res_bw_cmd
,
2294 "Disable Unidirectional Residual Bandwidth on this interface\n")
2296 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2298 /* Unset Residual Bandwidth */
2299 link_param_cmd_unset(ifp
, LP_RES_BW
);
2304 DEFUN (link_params_ava_bw
,
2305 link_params_ava_bw_cmd
,
2307 "Unidirectional Available Bandwidth\n"
2308 "Bytes/second (IEEE floating point format)\n")
2310 int idx_bandwidth
= 1;
2311 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2312 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2315 if (sscanf(argv
[idx_bandwidth
]->arg
, "%g", &bw
) != 1) {
2316 vty_out(vty
, "link_params_ava_bw: fscanf: %s\n",
2317 safe_strerror(errno
));
2318 return CMD_WARNING_CONFIG_FAILED
;
2321 /* Check that bandwidth is not greater than maximum bandwidth parameter
2323 if (bw
> iflp
->max_bw
) {
2325 "Available Bandwidth could not be greater than Maximum Bandwidth (%g)\n",
2327 return CMD_WARNING_CONFIG_FAILED
;
2330 /* Update Residual Bandwidth if needed */
2331 link_param_cmd_set_float(ifp
, &iflp
->ava_bw
, LP_AVA_BW
, bw
);
2336 DEFUN (no_link_params_ava_bw
,
2337 no_link_params_ava_bw_cmd
,
2340 "Disable Unidirectional Available Bandwidth on this interface\n")
2342 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2344 /* Unset Available Bandwidth */
2345 link_param_cmd_unset(ifp
, LP_AVA_BW
);
2350 DEFUN (link_params_use_bw
,
2351 link_params_use_bw_cmd
,
2353 "Unidirectional Utilised Bandwidth\n"
2354 "Bytes/second (IEEE floating point format)\n")
2356 int idx_bandwidth
= 1;
2357 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2358 struct if_link_params
*iflp
= if_link_params_get(ifp
);
2361 if (sscanf(argv
[idx_bandwidth
]->arg
, "%g", &bw
) != 1) {
2362 vty_out(vty
, "link_params_use_bw: fscanf: %s\n",
2363 safe_strerror(errno
));
2364 return CMD_WARNING_CONFIG_FAILED
;
2367 /* Check that bandwidth is not greater than maximum bandwidth parameter
2369 if (bw
> iflp
->max_bw
) {
2371 "Utilised Bandwidth could not be greater than Maximum Bandwidth (%g)\n",
2373 return CMD_WARNING_CONFIG_FAILED
;
2376 /* Update Utilized Bandwidth if needed */
2377 link_param_cmd_set_float(ifp
, &iflp
->use_bw
, LP_USE_BW
, bw
);
2382 DEFUN (no_link_params_use_bw
,
2383 no_link_params_use_bw_cmd
,
2386 "Disable Unidirectional Utilised Bandwidth on this interface\n")
2388 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2390 /* Unset Utilised Bandwidth */
2391 link_param_cmd_unset(ifp
, LP_USE_BW
);
2396 static int ip_address_install(struct vty
*vty
, struct interface
*ifp
,
2397 const char *addr_str
, const char *peer_str
,
2400 struct zebra_if
*if_data
;
2401 struct prefix_ipv4 lp
, pp
;
2402 struct connected
*ifc
;
2403 struct prefix_ipv4
*p
;
2406 if_data
= ifp
->info
;
2408 ret
= str2prefix_ipv4(addr_str
, &lp
);
2410 vty_out(vty
, "%% Malformed address \n");
2411 return CMD_WARNING_CONFIG_FAILED
;
2414 if (ipv4_martian(&lp
.prefix
)) {
2415 vty_out(vty
, "%% Invalid address\n");
2416 return CMD_WARNING_CONFIG_FAILED
;
2420 if (lp
.prefixlen
!= 32) {
2422 "%% Local prefix length for P-t-P address must be /32\n");
2423 return CMD_WARNING_CONFIG_FAILED
;
2426 ret
= str2prefix_ipv4(peer_str
, &pp
);
2428 vty_out(vty
, "%% Malformed peer address\n");
2429 return CMD_WARNING_CONFIG_FAILED
;
2433 ifc
= connected_check_ptp(ifp
, &lp
, peer_str
? &pp
: NULL
);
2435 ifc
= connected_new();
2439 p
= prefix_ipv4_new();
2441 ifc
->address
= (struct prefix
*)p
;
2444 SET_FLAG(ifc
->flags
, ZEBRA_IFA_PEER
);
2445 p
= prefix_ipv4_new();
2447 ifc
->destination
= (struct prefix
*)p
;
2448 } else if (p
->prefixlen
<= IPV4_MAX_PREFIXLEN
- 2) {
2449 p
= prefix_ipv4_new();
2451 p
->prefix
.s_addr
= ipv4_broadcast_addr(p
->prefix
.s_addr
,
2453 ifc
->destination
= (struct prefix
*)p
;
2458 ifc
->label
= XSTRDUP(MTYPE_CONNECTED_LABEL
, label
);
2460 /* Add to linked list. */
2461 listnode_add(ifp
->connected
, ifc
);
2464 /* This address is configured from zebra. */
2465 if (!CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
2466 SET_FLAG(ifc
->conf
, ZEBRA_IFC_CONFIGURED
);
2468 /* In case of this route need to install kernel. */
2469 if (!CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
)
2470 && CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
)
2471 && !(if_data
&& if_data
->shutdown
== IF_ZEBRA_SHUTDOWN_ON
)) {
2472 /* Some system need to up the interface to set IP address. */
2473 if (!if_is_up(ifp
)) {
2474 if_set_flags(ifp
, IFF_UP
| IFF_RUNNING
);
2478 ret
= if_set_prefix(ifp
, ifc
);
2480 vty_out(vty
, "%% Can't set interface IP address: %s.\n",
2481 safe_strerror(errno
));
2482 return CMD_WARNING_CONFIG_FAILED
;
2485 SET_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
);
2486 /* The address will be advertised to zebra clients when the
2488 * from the kernel has been received.
2489 * It will also be added to the subnet chain list, then. */
2495 static int ip_address_uninstall(struct vty
*vty
, struct interface
*ifp
,
2496 const char *addr_str
, const char *peer_str
,
2499 struct prefix_ipv4 lp
, pp
;
2500 struct connected
*ifc
;
2503 /* Convert to prefix structure. */
2504 ret
= str2prefix_ipv4(addr_str
, &lp
);
2506 vty_out(vty
, "%% Malformed address \n");
2507 return CMD_WARNING_CONFIG_FAILED
;
2511 if (lp
.prefixlen
!= 32) {
2513 "%% Local prefix length for P-t-P address must be /32\n");
2514 return CMD_WARNING_CONFIG_FAILED
;
2517 ret
= str2prefix_ipv4(peer_str
, &pp
);
2519 vty_out(vty
, "%% Malformed peer address\n");
2520 return CMD_WARNING_CONFIG_FAILED
;
2524 /* Check current interface address. */
2525 ifc
= connected_check_ptp(ifp
, &lp
, peer_str
? &pp
: NULL
);
2527 vty_out(vty
, "%% Can't find address\n");
2528 return CMD_WARNING_CONFIG_FAILED
;
2531 /* This is not configured address. */
2532 if (!CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
2533 return CMD_WARNING_CONFIG_FAILED
;
2535 UNSET_FLAG(ifc
->conf
, ZEBRA_IFC_CONFIGURED
);
2537 /* This is not real address or interface is not active. */
2538 if (!CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
)
2539 || !CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
)) {
2540 listnode_delete(ifp
->connected
, ifc
);
2541 connected_free(ifc
);
2542 return CMD_WARNING_CONFIG_FAILED
;
2545 /* This is real route. */
2546 ret
= if_unset_prefix(ifp
, ifc
);
2548 vty_out(vty
, "%% Can't unset interface IP address: %s.\n",
2549 safe_strerror(errno
));
2550 return CMD_WARNING_CONFIG_FAILED
;
2552 UNSET_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
);
2553 /* we will receive a kernel notification about this route being removed.
2554 * this will trigger its removal from the connected list. */
2560 "ip address A.B.C.D/M",
2561 "Interface Internet Protocol config commands\n"
2562 "Set the IP address of an interface\n"
2563 "IP address (e.g. 10.0.0.1/8)\n")
2565 int idx_ipv4_prefixlen
= 2;
2566 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2567 return ip_address_install(vty
, ifp
, argv
[idx_ipv4_prefixlen
]->arg
, NULL
,
2571 DEFUN (no_ip_address
,
2573 "no ip address A.B.C.D/M",
2575 "Interface Internet Protocol config commands\n"
2576 "Set the IP address of an interface\n"
2577 "IP Address (e.g. 10.0.0.1/8)\n")
2579 int idx_ipv4_prefixlen
= 3;
2580 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2581 return ip_address_uninstall(vty
, ifp
, argv
[idx_ipv4_prefixlen
]->arg
,
2585 DEFUN(ip_address_peer
,
2586 ip_address_peer_cmd
,
2587 "ip address A.B.C.D peer A.B.C.D/M",
2588 "Interface Internet Protocol config commands\n"
2589 "Set the IP address of an interface\n"
2590 "Local IP (e.g. 10.0.0.1) for P-t-P address\n"
2591 "Specify P-t-P address\n"
2592 "Peer IP address (e.g. 10.0.0.1/8)\n")
2594 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2595 return ip_address_install(vty
, ifp
, argv
[2]->arg
, argv
[4]->arg
, NULL
);
2598 DEFUN(no_ip_address_peer
,
2599 no_ip_address_peer_cmd
,
2600 "no ip address A.B.C.D peer A.B.C.D/M",
2602 "Interface Internet Protocol config commands\n"
2603 "Set the IP address of an interface\n"
2604 "Local IP (e.g. 10.0.0.1) for P-t-P address\n"
2605 "Specify P-t-P address\n"
2606 "Peer IP address (e.g. 10.0.0.1/8)\n")
2608 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2609 return ip_address_uninstall(vty
, ifp
, argv
[3]->arg
, argv
[5]->arg
, NULL
);
2613 DEFUN (ip_address_label
,
2614 ip_address_label_cmd
,
2615 "ip address A.B.C.D/M label LINE",
2616 "Interface Internet Protocol config commands\n"
2617 "Set the IP address of an interface\n"
2618 "IP address (e.g. 10.0.0.1/8)\n"
2619 "Label of this address\n"
2622 int idx_ipv4_prefixlen
= 2;
2624 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2625 return ip_address_install(vty
, ifp
, argv
[idx_ipv4_prefixlen
]->arg
, NULL
,
2626 argv
[idx_line
]->arg
);
2629 DEFUN (no_ip_address_label
,
2630 no_ip_address_label_cmd
,
2631 "no ip address A.B.C.D/M label LINE",
2633 "Interface Internet Protocol config commands\n"
2634 "Set the IP address of an interface\n"
2635 "IP address (e.g. 10.0.0.1/8)\n"
2636 "Label of this address\n"
2639 int idx_ipv4_prefixlen
= 3;
2641 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2642 return ip_address_uninstall(vty
, ifp
, argv
[idx_ipv4_prefixlen
]->arg
,
2643 NULL
, argv
[idx_line
]->arg
);
2645 #endif /* HAVE_NETLINK */
2647 static int ipv6_address_install(struct vty
*vty
, struct interface
*ifp
,
2648 const char *addr_str
, const char *peer_str
,
2649 const char *label
, int secondary
)
2651 struct zebra_if
*if_data
;
2652 struct prefix_ipv6 cp
;
2653 struct connected
*ifc
;
2654 struct prefix_ipv6
*p
;
2657 if_data
= ifp
->info
;
2659 ret
= str2prefix_ipv6(addr_str
, &cp
);
2661 vty_out(vty
, "%% Malformed address \n");
2662 return CMD_WARNING_CONFIG_FAILED
;
2665 if (ipv6_martian(&cp
.prefix
)) {
2666 vty_out(vty
, "%% Invalid address\n");
2667 return CMD_WARNING_CONFIG_FAILED
;
2670 ifc
= connected_check(ifp
, (struct prefix
*)&cp
);
2672 ifc
= connected_new();
2676 p
= prefix_ipv6_new();
2678 ifc
->address
= (struct prefix
*)p
;
2682 SET_FLAG(ifc
->flags
, ZEBRA_IFA_SECONDARY
);
2686 ifc
->label
= XSTRDUP(MTYPE_CONNECTED_LABEL
, label
);
2688 /* Add to linked list. */
2689 listnode_add(ifp
->connected
, ifc
);
2692 /* This address is configured from zebra. */
2693 if (!CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
2694 SET_FLAG(ifc
->conf
, ZEBRA_IFC_CONFIGURED
);
2696 /* In case of this route need to install kernel. */
2697 if (!CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
)
2698 && CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
)
2699 && !(if_data
&& if_data
->shutdown
== IF_ZEBRA_SHUTDOWN_ON
)) {
2700 /* Some system need to up the interface to set IP address. */
2701 if (!if_is_up(ifp
)) {
2702 if_set_flags(ifp
, IFF_UP
| IFF_RUNNING
);
2706 ret
= if_prefix_add_ipv6(ifp
, ifc
);
2709 vty_out(vty
, "%% Can't set interface IP address: %s.\n",
2710 safe_strerror(errno
));
2711 return CMD_WARNING_CONFIG_FAILED
;
2714 SET_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
);
2715 /* The address will be advertised to zebra clients when the
2717 * from the kernel has been received. */
2723 /* Return true if an ipv6 address is configured on ifp */
2724 int ipv6_address_configured(struct interface
*ifp
)
2726 struct connected
*connected
;
2727 struct listnode
*node
;
2729 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, node
, connected
))
2730 if (CHECK_FLAG(connected
->conf
, ZEBRA_IFC_REAL
)
2731 && (connected
->address
->family
== AF_INET6
))
2737 static int ipv6_address_uninstall(struct vty
*vty
, struct interface
*ifp
,
2738 const char *addr_str
, const char *peer_str
,
2739 const char *label
, int secondry
)
2741 struct prefix_ipv6 cp
;
2742 struct connected
*ifc
;
2745 /* Convert to prefix structure. */
2746 ret
= str2prefix_ipv6(addr_str
, &cp
);
2748 vty_out(vty
, "%% Malformed address \n");
2749 return CMD_WARNING_CONFIG_FAILED
;
2752 /* Check current interface address. */
2753 ifc
= connected_check(ifp
, (struct prefix
*)&cp
);
2755 vty_out(vty
, "%% Can't find address\n");
2756 return CMD_WARNING_CONFIG_FAILED
;
2759 /* This is not configured address. */
2760 if (!CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_CONFIGURED
))
2761 return CMD_WARNING_CONFIG_FAILED
;
2763 UNSET_FLAG(ifc
->conf
, ZEBRA_IFC_CONFIGURED
);
2765 /* This is not real address or interface is not active. */
2766 if (!CHECK_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
)
2767 || !CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
)) {
2768 listnode_delete(ifp
->connected
, ifc
);
2769 connected_free(ifc
);
2770 return CMD_WARNING_CONFIG_FAILED
;
2773 /* This is real route. */
2774 ret
= if_prefix_delete_ipv6(ifp
, ifc
);
2776 vty_out(vty
, "%% Can't unset interface IP address: %s.\n",
2777 safe_strerror(errno
));
2778 return CMD_WARNING_CONFIG_FAILED
;
2781 UNSET_FLAG(ifc
->conf
, ZEBRA_IFC_QUEUED
);
2782 /* This information will be propagated to the zclients when the
2783 * kernel notification is received. */
2787 DEFUN (ipv6_address
,
2789 "ipv6 address X:X::X:X/M",
2790 "Interface IPv6 config commands\n"
2791 "Set the IP address of an interface\n"
2792 "IPv6 address (e.g. 3ffe:506::1/48)\n")
2794 int idx_ipv6_prefixlen
= 2;
2795 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2796 return ipv6_address_install(vty
, ifp
, argv
[idx_ipv6_prefixlen
]->arg
,
2800 DEFUN (no_ipv6_address
,
2801 no_ipv6_address_cmd
,
2802 "no ipv6 address X:X::X:X/M",
2804 "Interface IPv6 config commands\n"
2805 "Set the IP address of an interface\n"
2806 "IPv6 address (e.g. 3ffe:506::1/48)\n")
2808 int idx_ipv6_prefixlen
= 3;
2809 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2810 return ipv6_address_uninstall(vty
, ifp
, argv
[idx_ipv6_prefixlen
]->arg
,
2814 static int link_params_config_write(struct vty
*vty
, struct interface
*ifp
)
2818 if ((ifp
== NULL
) || !HAS_LINK_PARAMS(ifp
))
2821 struct if_link_params
*iflp
= ifp
->link_params
;
2823 vty_out(vty
, " link-params\n");
2824 vty_out(vty
, " enable\n");
2825 if (IS_PARAM_SET(iflp
, LP_TE_METRIC
) && iflp
->te_metric
!= ifp
->metric
)
2826 vty_out(vty
, " metric %u\n", iflp
->te_metric
);
2827 if (IS_PARAM_SET(iflp
, LP_MAX_BW
) && iflp
->max_bw
!= iflp
->default_bw
)
2828 vty_out(vty
, " max-bw %g\n", iflp
->max_bw
);
2829 if (IS_PARAM_SET(iflp
, LP_MAX_RSV_BW
)
2830 && iflp
->max_rsv_bw
!= iflp
->default_bw
)
2831 vty_out(vty
, " max-rsv-bw %g\n", iflp
->max_rsv_bw
);
2832 if (IS_PARAM_SET(iflp
, LP_UNRSV_BW
)) {
2833 for (i
= 0; i
< 8; i
++)
2834 if (iflp
->unrsv_bw
[i
] != iflp
->default_bw
)
2835 vty_out(vty
, " unrsv-bw %d %g\n", i
,
2838 if (IS_PARAM_SET(iflp
, LP_ADM_GRP
))
2839 vty_out(vty
, " admin-grp 0x%x\n", iflp
->admin_grp
);
2840 if (IS_PARAM_SET(iflp
, LP_DELAY
)) {
2841 vty_out(vty
, " delay %u", iflp
->av_delay
);
2842 if (IS_PARAM_SET(iflp
, LP_MM_DELAY
)) {
2843 vty_out(vty
, " min %u", iflp
->min_delay
);
2844 vty_out(vty
, " max %u", iflp
->max_delay
);
2848 if (IS_PARAM_SET(iflp
, LP_DELAY_VAR
))
2849 vty_out(vty
, " delay-variation %u\n", iflp
->delay_var
);
2850 if (IS_PARAM_SET(iflp
, LP_PKT_LOSS
))
2851 vty_out(vty
, " packet-loss %g\n", iflp
->pkt_loss
);
2852 if (IS_PARAM_SET(iflp
, LP_AVA_BW
))
2853 vty_out(vty
, " ava-bw %g\n", iflp
->ava_bw
);
2854 if (IS_PARAM_SET(iflp
, LP_RES_BW
))
2855 vty_out(vty
, " res-bw %g\n", iflp
->res_bw
);
2856 if (IS_PARAM_SET(iflp
, LP_USE_BW
))
2857 vty_out(vty
, " use-bw %g\n", iflp
->use_bw
);
2858 if (IS_PARAM_SET(iflp
, LP_RMT_AS
))
2859 vty_out(vty
, " neighbor %s as %u\n", inet_ntoa(iflp
->rmt_ip
),
2861 vty_out(vty
, " exit-link-params\n");
2865 static int if_config_write(struct vty
*vty
)
2868 struct interface
*ifp
;
2870 zebra_ptm_write(vty
);
2872 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
2873 FOR_ALL_INTERFACES (vrf
, ifp
) {
2874 struct zebra_if
*if_data
;
2875 struct listnode
*addrnode
;
2876 struct connected
*ifc
;
2880 if_data
= ifp
->info
;
2881 vrf
= vrf_lookup_by_id(ifp
->vrf_id
);
2883 if (ifp
->vrf_id
== VRF_DEFAULT
)
2884 vty_frame(vty
, "interface %s\n", ifp
->name
);
2886 vty_frame(vty
, "interface %s vrf %s\n",
2887 ifp
->name
, vrf
->name
);
2890 if (if_data
->shutdown
== IF_ZEBRA_SHUTDOWN_ON
)
2891 vty_out(vty
, " shutdown\n");
2893 zebra_ptm_if_write(vty
, if_data
);
2897 vty_out(vty
, " description %s\n", ifp
->desc
);
2899 /* Assign bandwidth here to avoid unnecessary interface
2901 while processing config script */
2902 if (ifp
->bandwidth
!= 0)
2903 vty_out(vty
, " bandwidth %u\n", ifp
->bandwidth
);
2905 if (!CHECK_FLAG(ifp
->status
,
2906 ZEBRA_INTERFACE_LINKDETECTION
))
2907 vty_out(vty
, " no link-detect\n");
2909 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, addrnode
,
2911 if (CHECK_FLAG(ifc
->conf
,
2912 ZEBRA_IFC_CONFIGURED
)) {
2913 char buf
[INET6_ADDRSTRLEN
];
2915 vty_out(vty
, " ip%s address %s",
2916 p
->family
== AF_INET
? ""
2918 inet_ntop(p
->family
,
2921 if (CONNECTED_PEER(ifc
)) {
2922 p
= ifc
->destination
;
2923 vty_out(vty
, " peer %s",
2924 inet_ntop(p
->family
,
2929 vty_out(vty
, "/%d", p
->prefixlen
);
2932 vty_out(vty
, " label %s",
2940 if (if_data
->multicast
2941 != IF_ZEBRA_MULTICAST_UNSPEC
)
2942 vty_out(vty
, " %smulticast\n",
2944 == IF_ZEBRA_MULTICAST_ON
2949 hook_call(zebra_if_config_wr
, vty
, ifp
);
2951 link_params_config_write(vty
, ifp
);
2953 vty_endframe(vty
, "!\n");
2958 /* Allocate and initialize interface vector. */
2959 void zebra_if_init(void)
2961 /* Initialize interface and new hook. */
2962 hook_register_prio(if_add
, 0, if_zebra_new_hook
);
2963 hook_register_prio(if_del
, 0, if_zebra_delete_hook
);
2965 /* Install configuration write function. */
2966 install_node(&interface_node
, if_config_write
);
2967 install_node(&link_params_node
, NULL
);
2970 install_element(VIEW_NODE
, &show_interface_cmd
);
2971 install_element(VIEW_NODE
, &show_interface_vrf_all_cmd
);
2972 install_element(VIEW_NODE
, &show_interface_name_vrf_cmd
);
2973 install_element(VIEW_NODE
, &show_interface_name_vrf_all_cmd
);
2975 install_element(ENABLE_NODE
, &show_interface_desc_cmd
);
2976 install_element(ENABLE_NODE
, &show_interface_desc_vrf_all_cmd
);
2977 install_element(INTERFACE_NODE
, &multicast_cmd
);
2978 install_element(INTERFACE_NODE
, &no_multicast_cmd
);
2979 install_element(INTERFACE_NODE
, &linkdetect_cmd
);
2980 install_element(INTERFACE_NODE
, &no_linkdetect_cmd
);
2981 install_element(INTERFACE_NODE
, &shutdown_if_cmd
);
2982 install_element(INTERFACE_NODE
, &no_shutdown_if_cmd
);
2983 install_element(INTERFACE_NODE
, &bandwidth_if_cmd
);
2984 install_element(INTERFACE_NODE
, &no_bandwidth_if_cmd
);
2985 install_element(INTERFACE_NODE
, &ip_address_cmd
);
2986 install_element(INTERFACE_NODE
, &no_ip_address_cmd
);
2987 install_element(INTERFACE_NODE
, &ip_address_peer_cmd
);
2988 install_element(INTERFACE_NODE
, &no_ip_address_peer_cmd
);
2989 install_element(INTERFACE_NODE
, &ipv6_address_cmd
);
2990 install_element(INTERFACE_NODE
, &no_ipv6_address_cmd
);
2992 install_element(INTERFACE_NODE
, &ip_address_label_cmd
);
2993 install_element(INTERFACE_NODE
, &no_ip_address_label_cmd
);
2994 #endif /* HAVE_NETLINK */
2995 install_element(INTERFACE_NODE
, &link_params_cmd
);
2996 install_default(LINK_PARAMS_NODE
);
2997 install_element(LINK_PARAMS_NODE
, &link_params_enable_cmd
);
2998 install_element(LINK_PARAMS_NODE
, &no_link_params_enable_cmd
);
2999 install_element(LINK_PARAMS_NODE
, &link_params_metric_cmd
);
3000 install_element(LINK_PARAMS_NODE
, &no_link_params_metric_cmd
);
3001 install_element(LINK_PARAMS_NODE
, &link_params_maxbw_cmd
);
3002 install_element(LINK_PARAMS_NODE
, &link_params_max_rsv_bw_cmd
);
3003 install_element(LINK_PARAMS_NODE
, &link_params_unrsv_bw_cmd
);
3004 install_element(LINK_PARAMS_NODE
, &link_params_admin_grp_cmd
);
3005 install_element(LINK_PARAMS_NODE
, &no_link_params_admin_grp_cmd
);
3006 install_element(LINK_PARAMS_NODE
, &link_params_inter_as_cmd
);
3007 install_element(LINK_PARAMS_NODE
, &no_link_params_inter_as_cmd
);
3008 install_element(LINK_PARAMS_NODE
, &link_params_delay_cmd
);
3009 install_element(LINK_PARAMS_NODE
, &no_link_params_delay_cmd
);
3010 install_element(LINK_PARAMS_NODE
, &link_params_delay_var_cmd
);
3011 install_element(LINK_PARAMS_NODE
, &no_link_params_delay_var_cmd
);
3012 install_element(LINK_PARAMS_NODE
, &link_params_pkt_loss_cmd
);
3013 install_element(LINK_PARAMS_NODE
, &no_link_params_pkt_loss_cmd
);
3014 install_element(LINK_PARAMS_NODE
, &link_params_ava_bw_cmd
);
3015 install_element(LINK_PARAMS_NODE
, &no_link_params_ava_bw_cmd
);
3016 install_element(LINK_PARAMS_NODE
, &link_params_res_bw_cmd
);
3017 install_element(LINK_PARAMS_NODE
, &no_link_params_res_bw_cmd
);
3018 install_element(LINK_PARAMS_NODE
, &link_params_use_bw_cmd
);
3019 install_element(LINK_PARAMS_NODE
, &no_link_params_use_bw_cmd
);
3020 install_element(LINK_PARAMS_NODE
, &exit_link_params_cmd
);