]> git.proxmox.com Git - mirror_frr.git/blob - zebra/interface.c
zebra: Move the master thread handler to the zrouter structure
[mirror_frr.git] / zebra / interface.c
1 /*
2 * Interface function.
3 * Copyright (C) 1997, 1999 Kunihiro Ishiguro
4 *
5 * This file is part of GNU Zebra.
6 *
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
10 * later version.
11 *
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.
16 *
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
20 */
21
22 #include <zebra.h>
23
24 #include "if.h"
25 #include "lib_errors.h"
26 #include "vty.h"
27 #include "sockunion.h"
28 #include "prefix.h"
29 #include "command.h"
30 #include "memory.h"
31 #include "zebra_memory.h"
32 #include "ioctl.h"
33 #include "connected.h"
34 #include "log.h"
35 #include "zclient.h"
36 #include "vrf.h"
37
38 #include "zebra/rtadv.h"
39 #include "zebra_ns.h"
40 #include "zebra_vrf.h"
41 #include "zebra/interface.h"
42 #include "zebra/rib.h"
43 #include "zebra/rt.h"
44 #include "zebra/zebra_router.h"
45 #include "zebra/redistribute.h"
46 #include "zebra/debug.h"
47 #include "zebra/irdp.h"
48 #include "zebra/zebra_ptm.h"
49 #include "zebra/rt_netlink.h"
50 #include "zebra/interface.h"
51 #include "zebra/zebra_vxlan.h"
52 #include "zebra/zebra_errors.h"
53
54 DEFINE_MTYPE_STATIC(ZEBRA, ZINFO, "Zebra Interface Information")
55
56 #define ZEBRA_PTM_SUPPORT
57
58 DEFINE_HOOK(zebra_if_extra_info, (struct vty * vty, struct interface *ifp),
59 (vty, ifp))
60 DEFINE_HOOK(zebra_if_config_wr, (struct vty * vty, struct interface *ifp),
61 (vty, ifp))
62
63
64 static void if_down_del_nbr_connected(struct interface *ifp);
65
66 static int if_zebra_speed_update(struct thread *thread)
67 {
68 struct interface *ifp = THREAD_ARG(thread);
69 struct zebra_if *zif = ifp->info;
70 uint32_t new_speed;
71
72 zif->speed_update = NULL;
73
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,
78 new_speed);
79 ifp->speed = new_speed;
80 if_add_update(ifp);
81 }
82
83 return 1;
84 }
85
86 static void zebra_if_node_destroy(route_table_delegate_t *delegate,
87 struct route_table *table,
88 struct route_node *node)
89 {
90 if (node->info)
91 list_delete((struct list **)&node->info);
92 route_node_destroy(delegate, table, node);
93 }
94
95 route_table_delegate_t zebra_if_table_delegate = {
96 .create_node = route_node_create,
97 .destroy_node = zebra_if_node_destroy};
98
99 /* Called when new interface is added. */
100 static int if_zebra_new_hook(struct interface *ifp)
101 {
102 struct zebra_if *zebra_if;
103
104 zebra_if = XCALLOC(MTYPE_ZINFO, sizeof(struct zebra_if));
105
106 zebra_if->multicast = IF_ZEBRA_MULTICAST_UNSPEC;
107 zebra_if->shutdown = IF_ZEBRA_SHUTDOWN_OFF;
108 zebra_ptm_if_init(zebra_if);
109
110 ifp->ptm_enable = zebra_ptm_get_enable_state();
111 #if defined(HAVE_RTADV)
112 {
113 /* Set default router advertise values. */
114 struct rtadvconf *rtadv;
115
116 rtadv = &zebra_if->rtadv;
117
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;
136
137 rtadv->AdvPrefixList = list_new();
138 }
139 #endif /* HAVE_RTADV */
140
141 memset(&zebra_if->neigh_mac[0], 0, 6);
142
143 /* Initialize installed address chains tree. */
144 zebra_if->ipv4_subnets =
145 route_table_init_with_delegate(&zebra_if_table_delegate);
146
147 ifp->info = zebra_if;
148
149 /*
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
154 * down upon startup.
155 */
156 thread_add_timer(zrouter.master, if_zebra_speed_update, ifp, 15,
157 &zebra_if->speed_update);
158 return 0;
159 }
160
161 /* Called when interface is deleted. */
162 static int if_zebra_delete_hook(struct interface *ifp)
163 {
164 struct zebra_if *zebra_if;
165
166 if (ifp->info) {
167 zebra_if = ifp->info;
168
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)
173
174 struct rtadvconf *rtadv;
175
176 rtadv = &zebra_if->rtadv;
177 list_delete(&rtadv->AdvPrefixList);
178 #endif /* HAVE_RTADV */
179
180 THREAD_OFF(zebra_if->speed_update);
181
182 XFREE(MTYPE_ZINFO, zebra_if);
183 }
184
185 return 0;
186 }
187
188 /* Build the table key */
189 static void if_build_key(uint32_t ifindex, struct prefix *p)
190 {
191 p->family = AF_INET;
192 p->prefixlen = IPV4_MAX_BITLEN;
193 p->u.prefix4.s_addr = ifindex;
194 }
195
196 /* Link an interface in a per NS interface tree */
197 struct interface *if_link_per_ns(struct zebra_ns *ns, struct interface *ifp)
198 {
199 struct prefix p;
200 struct route_node *rn;
201
202 if (ifp->ifindex == IFINDEX_INTERNAL)
203 return NULL;
204
205 if_build_key(ifp->ifindex, &p);
206 rn = route_node_get(ns->if_table, &p);
207 if (rn->info) {
208 ifp = (struct interface *)rn->info;
209 route_unlock_node(rn); /* get */
210 return ifp;
211 }
212
213 rn->info = ifp;
214 ifp->node = rn;
215
216 return ifp;
217 }
218
219 /* Delete a VRF. This is called in vrf_terminate(). */
220 void if_unlink_per_ns(struct interface *ifp)
221 {
222 ifp->node->info = NULL;
223 route_unlock_node(ifp->node);
224 ifp->node = NULL;
225 }
226
227 /* Look up an interface by identifier within a NS */
228 struct interface *if_lookup_by_index_per_ns(struct zebra_ns *ns,
229 uint32_t ifindex)
230 {
231 struct prefix p;
232 struct route_node *rn;
233 struct interface *ifp = NULL;
234
235 if_build_key(ifindex, &p);
236 rn = route_node_lookup(ns->if_table, &p);
237 if (rn) {
238 ifp = (struct interface *)rn->info;
239 route_unlock_node(rn); /* lookup */
240 }
241 return ifp;
242 }
243
244 /* Look up an interface by name within a NS */
245 struct interface *if_lookup_by_name_per_ns(struct zebra_ns *ns,
246 const char *ifname)
247 {
248 struct route_node *rn;
249 struct interface *ifp;
250
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)
254 return (ifp);
255 }
256
257 return NULL;
258 }
259
260 const char *ifindex2ifname_per_ns(struct zebra_ns *zns, unsigned int ifindex)
261 {
262 struct interface *ifp;
263
264 return ((ifp = if_lookup_by_index_per_ns(zns, ifindex)) != NULL)
265 ? ifp->name
266 : "unknown";
267 }
268
269 /* Tie an interface address to its derived subnet list of addresses. */
270 int if_subnet_add(struct interface *ifp, struct connected *ifc)
271 {
272 struct route_node *rn;
273 struct zebra_if *zebra_if;
274 struct prefix cp;
275 struct list *addr_list;
276
277 assert(ifp && ifp->info && ifc);
278 zebra_if = ifp->info;
279
280 /* Get address derived subnet node and associated address list, while
281 marking
282 address secondary attribute appropriately. */
283 cp = *CONNECTED_PREFIX(ifc);
284 apply_mask(&cp);
285 rn = route_node_get(zebra_if->ipv4_subnets, &cp);
286
287 if ((addr_list = rn->info))
288 SET_FLAG(ifc->flags, ZEBRA_IFA_SECONDARY);
289 else {
290 UNSET_FLAG(ifc->flags, ZEBRA_IFA_SECONDARY);
291 rn->info = addr_list = list_new();
292 route_lock_node(rn);
293 }
294
295 /* Tie address at the tail of address list. */
296 listnode_add(addr_list, ifc);
297
298 /* Return list element count. */
299 return (addr_list->count);
300 }
301
302 /* Untie an interface address from its derived subnet list of addresses. */
303 int if_subnet_delete(struct interface *ifp, struct connected *ifc)
304 {
305 struct route_node *rn;
306 struct zebra_if *zebra_if;
307 struct list *addr_list;
308 struct prefix cp;
309
310 assert(ifp && ifp->info && ifc);
311 zebra_if = ifp->info;
312
313 cp = *CONNECTED_PREFIX(ifc);
314 apply_mask(&cp);
315
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)");
322 return -1;
323 }
324 route_unlock_node(rn);
325
326 /* Untie address from subnet's address list. */
327 addr_list = rn->info;
328
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
331 * is unknown. */
332 if (!listnode_lookup(addr_list, ifc)) {
333 flog_warn(
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)");
337 return -1;
338 }
339
340 listnode_delete(addr_list, ifc);
341 route_unlock_node(rn);
342
343 /* Return list element count, if not empty. */
344 if (addr_list->count) {
345 /* If deleted address is primary, mark subsequent one as such
346 * and distribute. */
347 if (!CHECK_FLAG(ifc->flags, ZEBRA_IFA_SECONDARY)) {
348 ifc = listgetdata(
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
353 * when the primary
354 * address is removed. We could try to work around that,
355 * though this is
356 * non-trivial. */
357 zebra_interface_address_add_update(ifp, ifc);
358 }
359
360 return addr_list->count;
361 }
362
363 /* Otherwise, free list and route node. */
364 list_delete(&addr_list);
365 rn->info = NULL;
366 route_unlock_node(rn);
367
368 return 0;
369 }
370
371 /* if_flags_mangle: A place for hacks that require mangling
372 * or tweaking the interface flags.
373 *
374 * ******************** Solaris flags hacks **************************
375 *
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).
383 *
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
386 * IFF_UP flag.
387 *
388 * We must hence remember the real state of IFF_UP, which we do in
389 * struct zebra_if.primary_state.
390 *
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 ***********************
394 */
395 static void if_flags_mangle(struct interface *ifp, uint64_t *newflags)
396 {
397 #ifdef SUNOS_5
398 struct zebra_if *zif = ifp->info;
399
400 zif->primary_state = *newflags & (IFF_UP & 0xff);
401
402 if (CHECK_FLAG(zif->primary_state, IFF_UP)
403 || listcount(ifp->connected) > 0)
404 SET_FLAG(*newflags, IFF_UP);
405 else
406 UNSET_FLAG(*newflags, IFF_UP);
407 #endif /* SUNOS_5 */
408 }
409
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
412 * about.
413 *
414 * newflags should be the raw value, as obtained from the OS.
415 */
416 void if_flags_update(struct interface *ifp, uint64_t newflags)
417 {
418 if_flags_mangle(ifp, &newflags);
419
420 if (if_is_no_ptm_operative(ifp)) {
421 /* operative -> inoperative? */
422 ifp->flags = newflags;
423 if (!if_is_operative(ifp))
424 if_down(ifp);
425 } else {
426 /* inoperative -> operative? */
427 ifp->flags = newflags;
428 if (if_is_operative(ifp))
429 if_up(ifp);
430 }
431 }
432
433 /* Wake up configured address if it is not in current kernel
434 address. */
435 static void if_addr_wakeup(struct interface *ifp)
436 {
437 struct listnode *node, *nnode;
438 struct connected *ifc;
439 struct prefix *p;
440 int ret;
441
442 for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, ifc)) {
443 p = ifc->address;
444
445 if (CHECK_FLAG(ifc->conf, ZEBRA_IFC_CONFIGURED)
446 && !CHECK_FLAG(ifc->conf, ZEBRA_IFC_QUEUED)) {
447 /* Address check. */
448 if (p->family == AF_INET) {
449 if (!if_is_up(ifp)) {
450 /* Assume zebra is configured like
451 * following:
452 *
453 * interface gre0
454 * ip addr 192.0.2.1/24
455 * !
456 *
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.
461 *
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)
466 *
467 * XXX: IRDP code is calling here via
468 * if_add_update - this seems
469 * somewhat weird.
470 * XXX: RUNNING is not a settable flag
471 * on any system
472 * I (paulj) am aware of.
473 */
474 if_set_flags(ifp, IFF_UP | IFF_RUNNING);
475 if_refresh(ifp);
476 }
477
478 ret = if_set_prefix(ifp, ifc);
479 if (ret < 0) {
480 flog_err_sys(
481 EC_ZEBRA_IFACE_ADDR_ADD_FAILED,
482 "Can't set interface's address: %s",
483 safe_strerror(errno));
484 continue;
485 }
486
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. */
493 }
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);
498 if_refresh(ifp);
499 }
500
501 ret = if_prefix_add_ipv6(ifp, ifc);
502 if (ret < 0) {
503 flog_err_sys(
504 EC_ZEBRA_IFACE_ADDR_ADD_FAILED,
505 "Can't set interface's address: %s",
506 safe_strerror(errno));
507 continue;
508 }
509
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. */
514 }
515 }
516 }
517 }
518
519 /* Handle interface addition */
520 void if_add_update(struct interface *ifp)
521 {
522 struct zebra_if *if_data;
523 struct zebra_ns *zns;
524 struct zebra_vrf *zvrf = vrf_info_lookup(ifp->vrf_id);
525
526 /* case interface populate before vrf enabled */
527 if (zvrf->zns)
528 zns = zvrf->zns;
529 else
530 zns = zebra_ns_lookup(NS_DEFAULT);
531 if_link_per_ns(zns, ifp);
532 if_data = ifp->info;
533 assert(if_data);
534
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);
539
540 zebra_ptm_if_set_ptm_state(ifp, if_data);
541
542 zebra_interface_add_update(ifp);
543
544 if (!CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE)) {
545 SET_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE);
546
547 if (if_data->shutdown == IF_ZEBRA_SHUTDOWN_ON) {
548 if (IS_ZEBRA_DEBUG_KERNEL)
549 zlog_debug(
550 "interface %s vrf %u index %d is shutdown. "
551 "Won't wake it up.",
552 ifp->name, ifp->vrf_id, ifp->ifindex);
553 return;
554 }
555
556 if_addr_wakeup(ifp);
557
558 if (IS_ZEBRA_DEBUG_KERNEL)
559 zlog_debug(
560 "interface %s vrf %u index %d becomes active.",
561 ifp->name, ifp->vrf_id, ifp->ifindex);
562
563 } else {
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);
567 }
568 }
569
570 /* Install connected routes corresponding to an interface. */
571 static void if_install_connected(struct interface *ifp)
572 {
573 struct listnode *node;
574 struct listnode *next;
575 struct connected *ifc;
576
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);
581
582 connected_up(ifp, ifc);
583 }
584 }
585 }
586
587 /* Uninstall connected routes corresponding to an interface. */
588 static void if_uninstall_connected(struct interface *ifp)
589 {
590 struct listnode *node;
591 struct listnode *next;
592 struct connected *ifc;
593
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);
598 }
599 }
600 }
601
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)
605 {
606 struct connected *ifc;
607 struct prefix cp;
608 struct route_node *rn;
609 struct zebra_if *zebra_if;
610 struct listnode *node;
611 struct listnode *last = NULL;
612
613 zebra_if = ifp->info;
614
615 if (!ifp->connected)
616 return;
617
618 while ((node = (last ? last->next : listhead(ifp->connected)))) {
619 ifc = listgetdata(node);
620
621 cp = *CONNECTED_PREFIX(ifc);
622 apply_mask(&cp);
623
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;
630
631 route_unlock_node(rn);
632 addr_list = (struct list *)rn->info;
633
634 /* Remove addresses, secondaries first. */
635 first = listhead(addr_list);
636 if (first)
637 for (anode = first->next; anode || first;
638 anode = next) {
639 if (!anode) {
640 anode = first;
641 first = NULL;
642 }
643 next = anode->next;
644
645 ifc = listgetdata(anode);
646 connected_down(ifp, ifc);
647
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
652 * deleted.
653 */
654 zebra_interface_address_delete_update(
655 ifp, ifc);
656
657 UNSET_FLAG(ifc->conf, ZEBRA_IFC_REAL);
658 UNSET_FLAG(ifc->conf, ZEBRA_IFC_QUEUED);
659
660 /* Remove from subnet chain. */
661 list_delete_node(addr_list, anode);
662 route_unlock_node(rn);
663
664 /* Remove from interface address list
665 * (unconditionally). */
666 if (!CHECK_FLAG(ifc->conf,
667 ZEBRA_IFC_CONFIGURED)) {
668 listnode_delete(ifp->connected,
669 ifc);
670 connected_free(ifc);
671 } else
672 last = node;
673 }
674
675 /* Free chain list and respective route node. */
676 list_delete(&addr_list);
677 rn->info = NULL;
678 route_unlock_node(rn);
679 } else if (cp.family == AF_INET6) {
680 connected_down(ifp, ifc);
681
682 zebra_interface_address_delete_update(ifp, ifc);
683
684 UNSET_FLAG(ifc->conf, ZEBRA_IFC_REAL);
685 UNSET_FLAG(ifc->conf, ZEBRA_IFC_QUEUED);
686
687 if (CHECK_FLAG(ifc->conf, ZEBRA_IFC_CONFIGURED))
688 last = node;
689 else {
690 listnode_delete(ifp->connected, ifc);
691 connected_free(ifc);
692 }
693 } else {
694 last = node;
695 }
696 }
697 }
698
699 /* Handle an interface delete event */
700 void if_delete_update(struct interface *ifp)
701 {
702 struct zebra_if *zif;
703
704 if (if_is_up(ifp)) {
705 flog_err(
706 EC_LIB_INTERFACE,
707 "interface %s vrf %u index %d is still up while being deleted.",
708 ifp->name, ifp->vrf_id, ifp->ifindex);
709 return;
710 }
711
712 if (!CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE))
713 return;
714
715 /* Mark interface as inactive */
716 UNSET_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE);
717
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);
721
722 /* Delete connected routes from the kernel. */
723 if_delete_connected(ifp);
724
725 /* Send out notification on interface delete. */
726 zebra_interface_delete_update(ifp);
727
728 if_unlink_per_ns(ifp);
729
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);
736 ifp->node = NULL;
737
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
742 * vrf-lite).
743 */
744 if (ifp->vrf_id && !vrf_is_backend_netns())
745 if_handle_vrf_change(ifp, VRF_DEFAULT);
746
747 /* Reset some zebra interface params to default values. */
748 zif = ifp->info;
749 if (zif) {
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));
755 }
756 }
757
758 /* VRF change for an interface */
759 void if_handle_vrf_change(struct interface *ifp, vrf_id_t vrf_id)
760 {
761 vrf_id_t old_vrf_id;
762
763 old_vrf_id = ifp->vrf_id;
764
765 /* Uninstall connected routes. */
766 if_uninstall_connected(ifp);
767
768 /* Delete any IPv4 neighbors created to implement RFC 5549 */
769 if_nbr_ipv6ll_to_ipv4ll_neigh_del_all(ifp);
770
771 /* Delete all neighbor addresses learnt through IPv6 RA */
772 if_down_del_nbr_connected(ifp);
773
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);
777
778 /* update VRF */
779 if_update_to_new_vrf(ifp, vrf_id);
780
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);
784
785 /* Install connected routes (in new VRF). */
786 if (if_is_operative(ifp))
787 if_install_connected(ifp);
788
789 /* Due to connected route change, schedule RIB processing for both old
790 * and new VRF.
791 */
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);
797 }
798
799 static void ipv6_ll_address_to_mac(struct in6_addr *address, uint8_t *mac)
800 {
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];
807 }
808
809 void if_nbr_mac_to_ipv4ll_neigh_update(struct interface *ifp,
810 char mac[6],
811 struct in6_addr *address,
812 int add)
813 {
814 struct zebra_vrf *zvrf = vrf_info_lookup(ifp->vrf_id);
815 struct zebra_if *zif = ifp->info;
816 char buf[16] = "169.254.0.1";
817 struct in_addr ipv4_ll;
818 ns_id_t ns_id;
819
820 inet_pton(AF_INET, buf, &ipv4_ll);
821
822 ns_id = zvrf->zns->ns_id;
823
824 /*
825 * Remove and re-add any existing neighbor entry for this address,
826 * since Netlink doesn't currently offer update message types.
827 */
828 kernel_neigh_update(0, ifp->ifindex, ipv4_ll.s_addr, mac, 6, ns_id);
829
830 /* Add new neighbor entry.
831 *
832 * We force installation even if current neighbor entry is the same.
833 * Since this function is used to refresh our MAC entries after an
834 * interface flap, if we don't force in our custom entries with their
835 * state set to PERMANENT or REACHABLE then the kernel will attempt to
836 * resolve our leftover entries, fail, mark them unreachable and then
837 * they'll be useless to us.
838 */
839 if (add)
840 kernel_neigh_update(add, ifp->ifindex, ipv4_ll.s_addr, mac, 6,
841 ns_id);
842
843 memcpy(&zif->neigh_mac[0], &mac[0], 6);
844
845 /*
846 * We need to note whether or not we originated a v6
847 * neighbor entry for this interface. So that when
848 * someone unwisely accidently deletes this entry
849 * we can shove it back in.
850 */
851 zif->v6_2_v4_ll_neigh_entry = !!add;
852 memcpy(&zif->v6_2_v4_ll_addr6, address, sizeof(*address));
853
854 zvrf->neigh_updates++;
855 }
856
857 void if_nbr_ipv6ll_to_ipv4ll_neigh_update(struct interface *ifp,
858 struct in6_addr *address, int add)
859 {
860
861 char mac[6];
862
863 ipv6_ll_address_to_mac(address, (uint8_t *)mac);
864 if_nbr_mac_to_ipv4ll_neigh_update(ifp, mac, address, add);
865 }
866
867 static void if_nbr_ipv6ll_to_ipv4ll_neigh_add_all(struct interface *ifp)
868 {
869 if (listhead(ifp->nbr_connected)) {
870 struct nbr_connected *nbr_connected;
871 struct listnode *node;
872
873 for (ALL_LIST_ELEMENTS_RO(ifp->nbr_connected, node,
874 nbr_connected))
875 if_nbr_ipv6ll_to_ipv4ll_neigh_update(
876 ifp, &nbr_connected->address->u.prefix6, 1);
877 }
878 }
879
880 void if_nbr_ipv6ll_to_ipv4ll_neigh_del_all(struct interface *ifp)
881 {
882 if (listhead(ifp->nbr_connected)) {
883 struct nbr_connected *nbr_connected;
884 struct listnode *node;
885
886 for (ALL_LIST_ELEMENTS_RO(ifp->nbr_connected, node,
887 nbr_connected))
888 if_nbr_ipv6ll_to_ipv4ll_neigh_update(
889 ifp, &nbr_connected->address->u.prefix6, 0);
890 }
891 }
892
893 static void if_down_del_nbr_connected(struct interface *ifp)
894 {
895 struct nbr_connected *nbr_connected;
896 struct listnode *node, *nnode;
897
898 for (ALL_LIST_ELEMENTS(ifp->nbr_connected, node, nnode,
899 nbr_connected)) {
900 listnode_delete(ifp->nbr_connected, nbr_connected);
901 nbr_connected_free(nbr_connected);
902 }
903 }
904
905 /* Interface is up. */
906 void if_up(struct interface *ifp)
907 {
908 struct zebra_if *zif;
909 struct interface *link_if;
910 struct zebra_vrf *zvrf = vrf_info_lookup(ifp->vrf_id);
911
912 zif = ifp->info;
913 zif->up_count++;
914 quagga_timestamp(2, zif->up_last, sizeof(zif->up_last));
915
916 /* Notify the protocol daemons. */
917 if (ifp->ptm_enable && (ifp->ptm_status == ZEBRA_PTM_STATUS_DOWN)) {
918 flog_warn(EC_ZEBRA_PTM_NOT_READY,
919 "%s: interface %s hasn't passed ptm check\n",
920 __func__, ifp->name);
921 return;
922 }
923 zebra_interface_up_update(ifp);
924
925 if_nbr_ipv6ll_to_ipv4ll_neigh_add_all(ifp);
926
927 #if defined(HAVE_RTADV)
928 /* Enable fast tx of RA if enabled && RA interval is not in msecs */
929 if (zif->rtadv.AdvSendAdvertisements
930 && (zif->rtadv.MaxRtrAdvInterval >= 1000)) {
931 zif->rtadv.inFastRexmit = 1;
932 zif->rtadv.NumFastReXmitsRemain = RTADV_NUM_FAST_REXMITS;
933 }
934 #endif
935
936 /* Install connected routes to the kernel. */
937 if_install_connected(ifp);
938
939 if (IS_ZEBRA_DEBUG_RIB_DETAILED)
940 zlog_debug("%u: IF %s up, scheduling RIB processing",
941 ifp->vrf_id, ifp->name);
942 rib_update(ifp->vrf_id, RIB_UPDATE_IF_CHANGE);
943
944 /* Handle interface up for specific types for EVPN. Non-VxLAN interfaces
945 * are checked to see if (remote) neighbor entries need to be installed
946 * on them for ARP suppression.
947 */
948 if (IS_ZEBRA_IF_VXLAN(ifp))
949 zebra_vxlan_if_up(ifp);
950 else if (IS_ZEBRA_IF_BRIDGE(ifp)) {
951 link_if = ifp;
952 zebra_vxlan_svi_up(ifp, link_if);
953 } else if (IS_ZEBRA_IF_VLAN(ifp)) {
954 link_if = if_lookup_by_index_per_ns(zvrf->zns,
955 zif->link_ifindex);
956 if (link_if)
957 zebra_vxlan_svi_up(ifp, link_if);
958 }
959 }
960
961 /* Interface goes down. We have to manage different behavior of based
962 OS. */
963 void if_down(struct interface *ifp)
964 {
965 struct zebra_if *zif;
966 struct interface *link_if;
967 struct zebra_vrf *zvrf = vrf_info_lookup(ifp->vrf_id);
968
969 zif = ifp->info;
970 zif->down_count++;
971 quagga_timestamp(2, zif->down_last, sizeof(zif->down_last));
972
973 /* Handle interface down for specific types for EVPN. Non-VxLAN
974 * interfaces
975 * are checked to see if (remote) neighbor entries need to be purged
976 * for ARP suppression.
977 */
978 if (IS_ZEBRA_IF_VXLAN(ifp))
979 zebra_vxlan_if_down(ifp);
980 else if (IS_ZEBRA_IF_BRIDGE(ifp)) {
981 link_if = ifp;
982 zebra_vxlan_svi_down(ifp, link_if);
983 } else if (IS_ZEBRA_IF_VLAN(ifp)) {
984 link_if = if_lookup_by_index_per_ns(zvrf->zns,
985 zif->link_ifindex);
986 if (link_if)
987 zebra_vxlan_svi_down(ifp, link_if);
988 }
989
990
991 /* Notify to the protocol daemons. */
992 zebra_interface_down_update(ifp);
993
994 /* Uninstall connected routes from the kernel. */
995 if_uninstall_connected(ifp);
996
997 if (IS_ZEBRA_DEBUG_RIB_DETAILED)
998 zlog_debug("%u: IF %s down, scheduling RIB processing",
999 ifp->vrf_id, ifp->name);
1000 rib_update(ifp->vrf_id, RIB_UPDATE_IF_CHANGE);
1001
1002 if_nbr_ipv6ll_to_ipv4ll_neigh_del_all(ifp);
1003
1004 /* Delete all neighbor addresses learnt through IPv6 RA */
1005 if_down_del_nbr_connected(ifp);
1006 }
1007
1008 void if_refresh(struct interface *ifp)
1009 {
1010 if_get_flags(ifp);
1011 }
1012
1013 void zebra_if_update_link(struct interface *ifp, ifindex_t link_ifindex,
1014 ns_id_t ns_id)
1015 {
1016 struct zebra_if *zif;
1017
1018 if (IS_ZEBRA_IF_VETH(ifp))
1019 return;
1020 zif = (struct zebra_if *)ifp->info;
1021 zif->link_ifindex = link_ifindex;
1022 zif->link = if_lookup_by_index_per_ns(zebra_ns_lookup(ns_id),
1023 link_ifindex);
1024 }
1025
1026 /*
1027 * during initial link dump kernel does not order lower devices before
1028 * upper devices so we need to fixup link dependencies at the end of dump
1029 */
1030 void zebra_if_update_all_links(void)
1031 {
1032 struct route_node *rn;
1033 struct interface *ifp;
1034 struct zebra_if *zif;
1035 struct zebra_ns *ns;
1036
1037 if (IS_ZEBRA_DEBUG_KERNEL)
1038 zlog_info("fixup link dependencies");
1039
1040 ns = zebra_ns_lookup(NS_DEFAULT);
1041 for (rn = route_top(ns->if_table); rn; rn = route_next(rn)) {
1042 ifp = (struct interface *)rn->info;
1043 if (!ifp)
1044 continue;
1045 zif = ifp->info;
1046 if ((zif->link_ifindex != IFINDEX_INTERNAL) && !zif->link) {
1047 zif->link = if_lookup_by_index_per_ns(ns,
1048 zif->link_ifindex);
1049 if (IS_ZEBRA_DEBUG_KERNEL)
1050 zlog_debug("interface %s/%d's lower fixup to %s/%d",
1051 ifp->name, ifp->ifindex,
1052 zif->link?zif->link->name:"unk",
1053 zif->link_ifindex);
1054 }
1055 }
1056 }
1057
1058
1059
1060 /* Output prefix string to vty. */
1061 static int prefix_vty_out(struct vty *vty, struct prefix *p)
1062 {
1063 char str[INET6_ADDRSTRLEN];
1064
1065 inet_ntop(p->family, &p->u.prefix, str, sizeof(str));
1066 vty_out(vty, "%s", str);
1067 return strlen(str);
1068 }
1069
1070 /* Dump if address information to vty. */
1071 static void connected_dump_vty(struct vty *vty, struct connected *connected)
1072 {
1073 struct prefix *p;
1074
1075 /* Print interface address. */
1076 p = connected->address;
1077 vty_out(vty, " %s ", prefix_family_str(p));
1078 prefix_vty_out(vty, p);
1079 vty_out(vty, "/%d", p->prefixlen);
1080
1081 /* If there is destination address, print it. */
1082 if (connected->destination) {
1083 vty_out(vty,
1084 (CONNECTED_PEER(connected) ? " peer " : " broadcast "));
1085 prefix_vty_out(vty, connected->destination);
1086 if (CONNECTED_PEER(connected))
1087 vty_out(vty, "/%d", connected->destination->prefixlen);
1088 }
1089
1090 if (CHECK_FLAG(connected->flags, ZEBRA_IFA_SECONDARY))
1091 vty_out(vty, " secondary");
1092
1093 if (CHECK_FLAG(connected->flags, ZEBRA_IFA_UNNUMBERED))
1094 vty_out(vty, " unnumbered");
1095
1096 if (connected->label)
1097 vty_out(vty, " %s", connected->label);
1098
1099 vty_out(vty, "\n");
1100 }
1101
1102 /* Dump interface neighbor address information to vty. */
1103 static void nbr_connected_dump_vty(struct vty *vty,
1104 struct nbr_connected *connected)
1105 {
1106 struct prefix *p;
1107
1108 /* Print interface address. */
1109 p = connected->address;
1110 vty_out(vty, " %s ", prefix_family_str(p));
1111 prefix_vty_out(vty, p);
1112 vty_out(vty, "/%d", p->prefixlen);
1113
1114 vty_out(vty, "\n");
1115 }
1116
1117 static const char *zebra_ziftype_2str(zebra_iftype_t zif_type)
1118 {
1119 switch (zif_type) {
1120 case ZEBRA_IF_OTHER:
1121 return "Other";
1122 break;
1123
1124 case ZEBRA_IF_BRIDGE:
1125 return "Bridge";
1126 break;
1127
1128 case ZEBRA_IF_VLAN:
1129 return "Vlan";
1130 break;
1131
1132 case ZEBRA_IF_VXLAN:
1133 return "Vxlan";
1134 break;
1135
1136 case ZEBRA_IF_VRF:
1137 return "VRF";
1138 break;
1139
1140 case ZEBRA_IF_VETH:
1141 return "VETH";
1142 break;
1143
1144 case ZEBRA_IF_BOND:
1145 return "bond";
1146
1147 case ZEBRA_IF_BOND_SLAVE:
1148 return "bond_slave";
1149
1150 case ZEBRA_IF_MACVLAN:
1151 return "macvlan";
1152
1153 default:
1154 return "Unknown";
1155 break;
1156 }
1157 }
1158
1159 /* Interface's brief information print out to vty interface. */
1160 static void ifs_dump_brief_vty(struct vty *vty, struct vrf *vrf)
1161 {
1162 struct connected *connected;
1163 struct listnode *node;
1164 struct route_node *rn;
1165 struct zebra_if *zebra_if;
1166 struct prefix *p;
1167 struct interface *ifp;
1168 bool print_header = true;
1169
1170 FOR_ALL_INTERFACES (vrf, ifp) {
1171 char global_pfx[PREFIX_STRLEN] = {0};
1172 char buf[PREFIX_STRLEN] = {0};
1173 bool first_pfx_printed = false;
1174
1175 if (print_header) {
1176 vty_out(vty, "%-16s%-8s%-16s%s\n", "Interface",
1177 "Status", "VRF", "Addresses");
1178 vty_out(vty, "%-16s%-8s%-16s%s\n", "---------",
1179 "------", "---", "---------");
1180 print_header = false; /* We have at least 1 iface */
1181 }
1182 zebra_if = ifp->info;
1183
1184 vty_out(vty, "%-16s", ifp->name);
1185
1186 if (if_is_up(ifp))
1187 vty_out(vty, "%-8s", "up");
1188 else
1189 vty_out(vty, "%-8s", "down");
1190
1191 vty_out(vty, "%-16s", vrf->name);
1192
1193 for (rn = route_top(zebra_if->ipv4_subnets); rn;
1194 rn = route_next(rn)) {
1195 if (!rn->info)
1196 continue;
1197 uint32_t list_size = listcount((struct list *)rn->info);
1198
1199 for (ALL_LIST_ELEMENTS_RO((struct list *)rn->info, node,
1200 connected)) {
1201 if (!CHECK_FLAG(connected->flags,
1202 ZEBRA_IFA_SECONDARY)) {
1203 p = connected->address;
1204 prefix2str(p, buf, sizeof(buf));
1205 if (first_pfx_printed) {
1206 /* padding to prepare row only for ip addr */
1207 vty_out(vty, "%-40s", "");
1208 if (list_size > 1)
1209 vty_out(vty, "+ ");
1210 vty_out(vty, "%s\n", buf);
1211 } else {
1212 if (list_size > 1)
1213 vty_out(vty, "+ ");
1214 vty_out(vty, "%s\n", buf);
1215 }
1216 first_pfx_printed = true;
1217 break;
1218 }
1219 }
1220 }
1221
1222 uint32_t v6_list_size = 0;
1223 for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, connected)) {
1224 if (CHECK_FLAG(connected->conf, ZEBRA_IFC_REAL)
1225 && (connected->address->family == AF_INET6))
1226 v6_list_size++;
1227 }
1228 for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, connected)) {
1229 if (CHECK_FLAG(connected->conf, ZEBRA_IFC_REAL)
1230 && !CHECK_FLAG(connected->flags,
1231 ZEBRA_IFA_SECONDARY)
1232 && (connected->address->family == AF_INET6)) {
1233 p = connected->address;
1234 /* Don't print link local pfx */
1235 if (!IN6_IS_ADDR_LINKLOCAL(&p->u.prefix6)) {
1236 prefix2str(p, global_pfx, PREFIX_STRLEN);
1237 if (first_pfx_printed) {
1238 /* padding to prepare row only for ip addr */
1239 vty_out(vty, "%-40s", "");
1240 if (v6_list_size > 1)
1241 vty_out(vty, "+ ");
1242 vty_out(vty, "%s\n", global_pfx);
1243 } else {
1244 if (v6_list_size > 1)
1245 vty_out(vty, "+ ");
1246 vty_out(vty, "%s\n", global_pfx);
1247 }
1248 first_pfx_printed = true;
1249 break;
1250 }
1251 }
1252 }
1253 if (!first_pfx_printed)
1254 vty_out(vty, "\n");
1255 }
1256 vty_out(vty, "\n");
1257 }
1258
1259 /* Interface's information print out to vty interface. */
1260 static void if_dump_vty(struct vty *vty, struct interface *ifp)
1261 {
1262 struct connected *connected;
1263 struct nbr_connected *nbr_connected;
1264 struct listnode *node;
1265 struct route_node *rn;
1266 struct zebra_if *zebra_if;
1267 struct vrf *vrf;
1268
1269 zebra_if = ifp->info;
1270
1271 vty_out(vty, "Interface %s is ", ifp->name);
1272 if (if_is_up(ifp)) {
1273 vty_out(vty, "up, line protocol ");
1274
1275 if (CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION)) {
1276 if (if_is_running(ifp))
1277 vty_out(vty, "is up\n");
1278 else
1279 vty_out(vty, "is down\n");
1280 } else {
1281 vty_out(vty, "detection is disabled\n");
1282 }
1283 } else {
1284 vty_out(vty, "down\n");
1285 }
1286
1287 vty_out(vty, " Link ups: %5u last: %s\n", zebra_if->up_count,
1288 zebra_if->up_last[0] ? zebra_if->up_last : "(never)");
1289 vty_out(vty, " Link downs: %5u last: %s\n", zebra_if->down_count,
1290 zebra_if->down_last[0] ? zebra_if->down_last : "(never)");
1291
1292 zebra_ptm_show_status(vty, ifp);
1293
1294 vrf = vrf_lookup_by_id(ifp->vrf_id);
1295 vty_out(vty, " vrf: %s\n", vrf->name);
1296
1297 if (ifp->desc)
1298 vty_out(vty, " Description: %s\n", ifp->desc);
1299 if (ifp->ifindex == IFINDEX_INTERNAL) {
1300 vty_out(vty, " pseudo interface\n");
1301 return;
1302 } else if (!CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE)) {
1303 vty_out(vty, " index %d inactive interface\n", ifp->ifindex);
1304 return;
1305 }
1306
1307 vty_out(vty, " index %d metric %d mtu %d speed %u ", ifp->ifindex,
1308 ifp->metric, ifp->mtu, ifp->speed);
1309 if (ifp->mtu6 != ifp->mtu)
1310 vty_out(vty, "mtu6 %d ", ifp->mtu6);
1311 vty_out(vty, "\n flags: %s\n", if_flag_dump(ifp->flags));
1312
1313 /* Hardware address. */
1314 vty_out(vty, " Type: %s\n", if_link_type_str(ifp->ll_type));
1315 if (ifp->hw_addr_len != 0) {
1316 int i;
1317
1318 vty_out(vty, " HWaddr: ");
1319 for (i = 0; i < ifp->hw_addr_len; i++)
1320 vty_out(vty, "%s%02x", i == 0 ? "" : ":",
1321 ifp->hw_addr[i]);
1322 vty_out(vty, "\n");
1323 }
1324
1325 /* Bandwidth in Mbps */
1326 if (ifp->bandwidth != 0) {
1327 vty_out(vty, " bandwidth %u Mbps", ifp->bandwidth);
1328 vty_out(vty, "\n");
1329 }
1330
1331 for (rn = route_top(zebra_if->ipv4_subnets); rn; rn = route_next(rn)) {
1332 if (!rn->info)
1333 continue;
1334
1335 for (ALL_LIST_ELEMENTS_RO((struct list *)rn->info, node,
1336 connected))
1337 connected_dump_vty(vty, connected);
1338 }
1339
1340 for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, connected)) {
1341 if (CHECK_FLAG(connected->conf, ZEBRA_IFC_REAL)
1342 && (connected->address->family == AF_INET6))
1343 connected_dump_vty(vty, connected);
1344 }
1345
1346 vty_out(vty, " Interface Type %s\n",
1347 zebra_ziftype_2str(zebra_if->zif_type));
1348 if (IS_ZEBRA_IF_BRIDGE(ifp)) {
1349 struct zebra_l2info_bridge *bridge_info;
1350
1351 bridge_info = &zebra_if->l2info.br;
1352 vty_out(vty, " Bridge VLAN-aware: %s\n",
1353 bridge_info->vlan_aware ? "yes" : "no");
1354 } else if (IS_ZEBRA_IF_VLAN(ifp)) {
1355 struct zebra_l2info_vlan *vlan_info;
1356
1357 vlan_info = &zebra_if->l2info.vl;
1358 vty_out(vty, " VLAN Id %u\n", vlan_info->vid);
1359 } else if (IS_ZEBRA_IF_VXLAN(ifp)) {
1360 struct zebra_l2info_vxlan *vxlan_info;
1361
1362 vxlan_info = &zebra_if->l2info.vxl;
1363 vty_out(vty, " VxLAN Id %u", vxlan_info->vni);
1364 if (vxlan_info->vtep_ip.s_addr != INADDR_ANY)
1365 vty_out(vty, " VTEP IP: %s",
1366 inet_ntoa(vxlan_info->vtep_ip));
1367 if (vxlan_info->access_vlan)
1368 vty_out(vty, " Access VLAN Id %u",
1369 vxlan_info->access_vlan);
1370 vty_out(vty, "\n");
1371 }
1372
1373 if (IS_ZEBRA_IF_BRIDGE_SLAVE(ifp)) {
1374 struct zebra_l2info_brslave *br_slave;
1375
1376 br_slave = &zebra_if->brslave_info;
1377 if (br_slave->bridge_ifindex != IFINDEX_INTERNAL)
1378 vty_out(vty, " Master (bridge) ifindex %u\n",
1379 br_slave->bridge_ifindex);
1380 }
1381
1382 if (IS_ZEBRA_IF_BOND_SLAVE(ifp)) {
1383 struct zebra_l2info_bondslave *bond_slave;
1384
1385 bond_slave = &zebra_if->bondslave_info;
1386 if (bond_slave->bond_ifindex != IFINDEX_INTERNAL)
1387 vty_out(vty, " Master (bond) ifindex %u\n",
1388 bond_slave->bond_ifindex);
1389 }
1390
1391 if (zebra_if->link_ifindex != IFINDEX_INTERNAL) {
1392 vty_out(vty, " Link ifindex %u", zebra_if->link_ifindex);
1393 if (zebra_if->link)
1394 vty_out(vty, "(%s)\n", zebra_if->link->name);
1395 else
1396 vty_out(vty, "(Unknown)\n");
1397 }
1398
1399 if (HAS_LINK_PARAMS(ifp)) {
1400 int i;
1401 struct if_link_params *iflp = ifp->link_params;
1402 vty_out(vty, " Traffic Engineering Link Parameters:\n");
1403 if (IS_PARAM_SET(iflp, LP_TE_METRIC))
1404 vty_out(vty, " TE metric %u\n", iflp->te_metric);
1405 if (IS_PARAM_SET(iflp, LP_MAX_BW))
1406 vty_out(vty, " Maximum Bandwidth %g (Byte/s)\n",
1407 iflp->max_bw);
1408 if (IS_PARAM_SET(iflp, LP_MAX_RSV_BW))
1409 vty_out(vty,
1410 " Maximum Reservable Bandwidth %g (Byte/s)\n",
1411 iflp->max_rsv_bw);
1412 if (IS_PARAM_SET(iflp, LP_UNRSV_BW)) {
1413 vty_out(vty,
1414 " Unreserved Bandwidth per Class Type in Byte/s:\n");
1415 for (i = 0; i < MAX_CLASS_TYPE; i += 2)
1416 vty_out(vty,
1417 " [%d]: %g (Bytes/sec),\t[%d]: %g (Bytes/sec)\n",
1418 i, iflp->unrsv_bw[i], i + 1,
1419 iflp->unrsv_bw[i + 1]);
1420 }
1421
1422 if (IS_PARAM_SET(iflp, LP_ADM_GRP))
1423 vty_out(vty, " Administrative Group:%u\n",
1424 iflp->admin_grp);
1425 if (IS_PARAM_SET(iflp, LP_DELAY)) {
1426 vty_out(vty, " Link Delay Average: %u (micro-sec.)",
1427 iflp->av_delay);
1428 if (IS_PARAM_SET(iflp, LP_MM_DELAY)) {
1429 vty_out(vty, " Min: %u (micro-sec.)",
1430 iflp->min_delay);
1431 vty_out(vty, " Max: %u (micro-sec.)",
1432 iflp->max_delay);
1433 }
1434 vty_out(vty, "\n");
1435 }
1436 if (IS_PARAM_SET(iflp, LP_DELAY_VAR))
1437 vty_out(vty,
1438 " Link Delay Variation %u (micro-sec.)\n",
1439 iflp->delay_var);
1440 if (IS_PARAM_SET(iflp, LP_PKT_LOSS))
1441 vty_out(vty, " Link Packet Loss %g (in %%)\n",
1442 iflp->pkt_loss);
1443 if (IS_PARAM_SET(iflp, LP_AVA_BW))
1444 vty_out(vty, " Available Bandwidth %g (Byte/s)\n",
1445 iflp->ava_bw);
1446 if (IS_PARAM_SET(iflp, LP_RES_BW))
1447 vty_out(vty, " Residual Bandwidth %g (Byte/s)\n",
1448 iflp->res_bw);
1449 if (IS_PARAM_SET(iflp, LP_USE_BW))
1450 vty_out(vty, " Utilized Bandwidth %g (Byte/s)\n",
1451 iflp->use_bw);
1452 if (IS_PARAM_SET(iflp, LP_RMT_AS))
1453 vty_out(vty, " Neighbor ASBR IP: %s AS: %u \n",
1454 inet_ntoa(iflp->rmt_ip), iflp->rmt_as);
1455 }
1456
1457 hook_call(zebra_if_extra_info, vty, ifp);
1458
1459 if (listhead(ifp->nbr_connected))
1460 vty_out(vty, " Neighbor address(s):\n");
1461 for (ALL_LIST_ELEMENTS_RO(ifp->nbr_connected, node, nbr_connected))
1462 nbr_connected_dump_vty(vty, nbr_connected);
1463
1464 #ifdef HAVE_PROC_NET_DEV
1465 /* Statistics print out using proc file system. */
1466 vty_out(vty,
1467 " %lu input packets (%lu multicast), %lu bytes, "
1468 "%lu dropped\n",
1469 ifp->stats.rx_packets, ifp->stats.rx_multicast,
1470 ifp->stats.rx_bytes, ifp->stats.rx_dropped);
1471
1472 vty_out(vty,
1473 " %lu input errors, %lu length, %lu overrun,"
1474 " %lu CRC, %lu frame\n",
1475 ifp->stats.rx_errors, ifp->stats.rx_length_errors,
1476 ifp->stats.rx_over_errors, ifp->stats.rx_crc_errors,
1477 ifp->stats.rx_frame_errors);
1478
1479 vty_out(vty, " %lu fifo, %lu missed\n", ifp->stats.rx_fifo_errors,
1480 ifp->stats.rx_missed_errors);
1481
1482 vty_out(vty, " %lu output packets, %lu bytes, %lu dropped\n",
1483 ifp->stats.tx_packets, ifp->stats.tx_bytes,
1484 ifp->stats.tx_dropped);
1485
1486 vty_out(vty,
1487 " %lu output errors, %lu aborted, %lu carrier,"
1488 " %lu fifo, %lu heartbeat\n",
1489 ifp->stats.tx_errors, ifp->stats.tx_aborted_errors,
1490 ifp->stats.tx_carrier_errors, ifp->stats.tx_fifo_errors,
1491 ifp->stats.tx_heartbeat_errors);
1492
1493 vty_out(vty, " %lu window, %lu collisions\n",
1494 ifp->stats.tx_window_errors, ifp->stats.collisions);
1495 #endif /* HAVE_PROC_NET_DEV */
1496
1497 #ifdef HAVE_NET_RT_IFLIST
1498 #if defined(__bsdi__) || defined(__NetBSD__)
1499 /* Statistics print out using sysctl (). */
1500 vty_out(vty,
1501 " input packets %llu, bytes %llu, dropped %llu,"
1502 " multicast packets %llu\n",
1503 (unsigned long long)ifp->stats.ifi_ipackets,
1504 (unsigned long long)ifp->stats.ifi_ibytes,
1505 (unsigned long long)ifp->stats.ifi_iqdrops,
1506 (unsigned long long)ifp->stats.ifi_imcasts);
1507
1508 vty_out(vty, " input errors %llu\n",
1509 (unsigned long long)ifp->stats.ifi_ierrors);
1510
1511 vty_out(vty,
1512 " output packets %llu, bytes %llu,"
1513 " multicast packets %llu\n",
1514 (unsigned long long)ifp->stats.ifi_opackets,
1515 (unsigned long long)ifp->stats.ifi_obytes,
1516 (unsigned long long)ifp->stats.ifi_omcasts);
1517
1518 vty_out(vty, " output errors %llu\n",
1519 (unsigned long long)ifp->stats.ifi_oerrors);
1520
1521 vty_out(vty, " collisions %llu\n",
1522 (unsigned long long)ifp->stats.ifi_collisions);
1523 #else
1524 /* Statistics print out using sysctl (). */
1525 vty_out(vty,
1526 " input packets %lu, bytes %lu, dropped %lu,"
1527 " multicast packets %lu\n",
1528 ifp->stats.ifi_ipackets, ifp->stats.ifi_ibytes,
1529 ifp->stats.ifi_iqdrops, ifp->stats.ifi_imcasts);
1530
1531 vty_out(vty, " input errors %lu\n", ifp->stats.ifi_ierrors);
1532
1533 vty_out(vty,
1534 " output packets %lu, bytes %lu, multicast packets %lu\n",
1535 ifp->stats.ifi_opackets, ifp->stats.ifi_obytes,
1536 ifp->stats.ifi_omcasts);
1537
1538 vty_out(vty, " output errors %lu\n", ifp->stats.ifi_oerrors);
1539
1540 vty_out(vty, " collisions %lu\n", ifp->stats.ifi_collisions);
1541 #endif /* __bsdi__ || __NetBSD__ */
1542 #endif /* HAVE_NET_RT_IFLIST */
1543 }
1544
1545 static void interface_update_stats(void)
1546 {
1547 #ifdef HAVE_PROC_NET_DEV
1548 /* If system has interface statistics via proc file system, update
1549 statistics. */
1550 ifstat_update_proc();
1551 #endif /* HAVE_PROC_NET_DEV */
1552 #ifdef HAVE_NET_RT_IFLIST
1553 ifstat_update_sysctl();
1554 #endif /* HAVE_NET_RT_IFLIST */
1555 }
1556
1557 struct cmd_node interface_node = {INTERFACE_NODE, "%s(config-if)# ", 1};
1558
1559 #ifndef VTYSH_EXTRACT_PL
1560 #include "zebra/interface_clippy.c"
1561 #endif
1562 /* Show all interfaces to vty. */
1563 DEFPY(show_interface, show_interface_cmd,
1564 "show interface [vrf NAME$name] [brief$brief]",
1565 SHOW_STR
1566 "Interface status and configuration\n"
1567 VRF_CMD_HELP_STR
1568 "Interface status and configuration summary\n")
1569 {
1570 struct vrf *vrf;
1571 struct interface *ifp;
1572 vrf_id_t vrf_id = VRF_DEFAULT;
1573
1574 interface_update_stats();
1575
1576 if (name)
1577 VRF_GET_ID(vrf_id, name, false);
1578
1579 /* All interface print. */
1580 vrf = vrf_lookup_by_id(vrf_id);
1581 if (brief) {
1582 ifs_dump_brief_vty(vty, vrf);
1583 } else {
1584 FOR_ALL_INTERFACES (vrf, ifp) {
1585 if_dump_vty(vty, ifp);
1586 }
1587 }
1588
1589 return CMD_SUCCESS;
1590 }
1591
1592
1593 /* Show all interfaces to vty. */
1594 DEFUN (show_interface_vrf_all,
1595 show_interface_vrf_all_cmd,
1596 "show interface vrf all",
1597 SHOW_STR
1598 "Interface status and configuration\n"
1599 VRF_ALL_CMD_HELP_STR)
1600 {
1601 struct vrf *vrf;
1602 struct interface *ifp;
1603
1604 interface_update_stats();
1605
1606 /* All interface print. */
1607 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name)
1608 FOR_ALL_INTERFACES (vrf, ifp)
1609 if_dump_vty(vty, ifp);
1610
1611 return CMD_SUCCESS;
1612 }
1613
1614 /* Show specified interface to vty. */
1615
1616 DEFUN (show_interface_name_vrf,
1617 show_interface_name_vrf_cmd,
1618 "show interface IFNAME vrf NAME",
1619 SHOW_STR
1620 "Interface status and configuration\n"
1621 "Interface name\n"
1622 VRF_CMD_HELP_STR)
1623 {
1624 int idx_ifname = 2;
1625 int idx_name = 4;
1626 struct interface *ifp;
1627 vrf_id_t vrf_id;
1628
1629 interface_update_stats();
1630
1631 VRF_GET_ID(vrf_id, argv[idx_name]->arg, false);
1632
1633 /* Specified interface print. */
1634 ifp = if_lookup_by_name(argv[idx_ifname]->arg, vrf_id);
1635 if (ifp == NULL) {
1636 vty_out(vty, "%% Can't find interface %s\n",
1637 argv[idx_ifname]->arg);
1638 return CMD_WARNING;
1639 }
1640 if_dump_vty(vty, ifp);
1641
1642 return CMD_SUCCESS;
1643 }
1644
1645 /* Show specified interface to vty. */
1646 DEFUN (show_interface_name_vrf_all,
1647 show_interface_name_vrf_all_cmd,
1648 "show interface IFNAME [vrf all]",
1649 SHOW_STR
1650 "Interface status and configuration\n"
1651 "Interface name\n"
1652 VRF_ALL_CMD_HELP_STR)
1653 {
1654 int idx_ifname = 2;
1655 struct vrf *vrf;
1656 struct interface *ifp;
1657 int found = 0;
1658
1659 interface_update_stats();
1660
1661 /* All interface print. */
1662 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
1663 /* Specified interface print. */
1664 ifp = if_lookup_by_name(argv[idx_ifname]->arg, vrf->vrf_id);
1665 if (ifp) {
1666 if_dump_vty(vty, ifp);
1667 found++;
1668 }
1669 }
1670
1671 if (!found) {
1672 vty_out(vty, "%% Can't find interface %s\n",
1673 argv[idx_ifname]->arg);
1674 return CMD_WARNING;
1675 }
1676
1677 return CMD_SUCCESS;
1678 }
1679
1680
1681 static void if_show_description(struct vty *vty, vrf_id_t vrf_id)
1682 {
1683 struct vrf *vrf = vrf_lookup_by_id(vrf_id);
1684 struct interface *ifp;
1685
1686 vty_out(vty, "Interface Status Protocol Description\n");
1687 FOR_ALL_INTERFACES (vrf, ifp) {
1688 int len;
1689
1690 len = vty_out(vty, "%s", ifp->name);
1691 vty_out(vty, "%*s", (16 - len), " ");
1692
1693 if (if_is_up(ifp)) {
1694 vty_out(vty, "up ");
1695 if (CHECK_FLAG(ifp->status,
1696 ZEBRA_INTERFACE_LINKDETECTION)) {
1697 if (if_is_running(ifp))
1698 vty_out(vty, "up ");
1699 else
1700 vty_out(vty, "down ");
1701 } else {
1702 vty_out(vty, "unknown ");
1703 }
1704 } else {
1705 vty_out(vty, "down down ");
1706 }
1707
1708 if (ifp->desc)
1709 vty_out(vty, "%s", ifp->desc);
1710 vty_out(vty, "\n");
1711 }
1712 }
1713
1714 DEFUN (show_interface_desc,
1715 show_interface_desc_cmd,
1716 "show interface description [vrf NAME]",
1717 SHOW_STR
1718 "Interface status and configuration\n"
1719 "Interface description\n"
1720 VRF_CMD_HELP_STR)
1721 {
1722 vrf_id_t vrf_id = VRF_DEFAULT;
1723
1724 if (argc > 3)
1725 VRF_GET_ID(vrf_id, argv[4]->arg, false);
1726
1727 if_show_description(vty, vrf_id);
1728
1729 return CMD_SUCCESS;
1730 }
1731
1732
1733 DEFUN (show_interface_desc_vrf_all,
1734 show_interface_desc_vrf_all_cmd,
1735 "show interface description vrf all",
1736 SHOW_STR
1737 "Interface status and configuration\n"
1738 "Interface description\n"
1739 VRF_ALL_CMD_HELP_STR)
1740 {
1741 struct vrf *vrf;
1742
1743 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name)
1744 if (!RB_EMPTY(if_name_head, &vrf->ifaces_by_name)) {
1745 vty_out(vty, "\n\tVRF %u\n\n", vrf->vrf_id);
1746 if_show_description(vty, vrf->vrf_id);
1747 }
1748
1749 return CMD_SUCCESS;
1750 }
1751
1752 DEFUN (multicast,
1753 multicast_cmd,
1754 "multicast",
1755 "Set multicast flag to interface\n")
1756 {
1757 VTY_DECLVAR_CONTEXT(interface, ifp);
1758 int ret;
1759 struct zebra_if *if_data;
1760
1761 if (CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE)) {
1762 ret = if_set_flags(ifp, IFF_MULTICAST);
1763 if (ret < 0) {
1764 vty_out(vty, "Can't set multicast flag\n");
1765 return CMD_WARNING_CONFIG_FAILED;
1766 }
1767 if_refresh(ifp);
1768 }
1769 if_data = ifp->info;
1770 if_data->multicast = IF_ZEBRA_MULTICAST_ON;
1771
1772 return CMD_SUCCESS;
1773 }
1774
1775 DEFUN (no_multicast,
1776 no_multicast_cmd,
1777 "no multicast",
1778 NO_STR
1779 "Unset multicast flag to interface\n")
1780 {
1781 VTY_DECLVAR_CONTEXT(interface, ifp);
1782 int ret;
1783 struct zebra_if *if_data;
1784
1785 if (CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE)) {
1786 ret = if_unset_flags(ifp, IFF_MULTICAST);
1787 if (ret < 0) {
1788 vty_out(vty, "Can't unset multicast flag\n");
1789 return CMD_WARNING_CONFIG_FAILED;
1790 }
1791 if_refresh(ifp);
1792 }
1793 if_data = ifp->info;
1794 if_data->multicast = IF_ZEBRA_MULTICAST_OFF;
1795
1796 return CMD_SUCCESS;
1797 }
1798
1799 DEFUN (linkdetect,
1800 linkdetect_cmd,
1801 "link-detect",
1802 "Enable link detection on interface\n")
1803 {
1804 VTY_DECLVAR_CONTEXT(interface, ifp);
1805 int if_was_operative;
1806
1807 if_was_operative = if_is_no_ptm_operative(ifp);
1808 SET_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION);
1809
1810 /* When linkdetection is enabled, if might come down */
1811 if (!if_is_no_ptm_operative(ifp) && if_was_operative)
1812 if_down(ifp);
1813
1814 /* FIXME: Will defer status change forwarding if interface
1815 does not come down! */
1816
1817 return CMD_SUCCESS;
1818 }
1819
1820
1821 DEFUN (no_linkdetect,
1822 no_linkdetect_cmd,
1823 "no link-detect",
1824 NO_STR
1825 "Disable link detection on interface\n")
1826 {
1827 VTY_DECLVAR_CONTEXT(interface, ifp);
1828 int if_was_operative;
1829
1830 if_was_operative = if_is_no_ptm_operative(ifp);
1831 UNSET_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION);
1832
1833 /* Interface may come up after disabling link detection */
1834 if (if_is_operative(ifp) && !if_was_operative)
1835 if_up(ifp);
1836
1837 /* FIXME: see linkdetect_cmd */
1838
1839 return CMD_SUCCESS;
1840 }
1841
1842 DEFUN (shutdown_if,
1843 shutdown_if_cmd,
1844 "shutdown",
1845 "Shutdown the selected interface\n")
1846 {
1847 VTY_DECLVAR_CONTEXT(interface, ifp);
1848 int ret;
1849 struct zebra_if *if_data;
1850
1851 if (ifp->ifindex != IFINDEX_INTERNAL) {
1852 ret = if_unset_flags(ifp, IFF_UP);
1853 if (ret < 0) {
1854 vty_out(vty, "Can't shutdown interface\n");
1855 return CMD_WARNING_CONFIG_FAILED;
1856 }
1857 if_refresh(ifp);
1858 }
1859 if_data = ifp->info;
1860 if_data->shutdown = IF_ZEBRA_SHUTDOWN_ON;
1861
1862 return CMD_SUCCESS;
1863 }
1864
1865 DEFUN (no_shutdown_if,
1866 no_shutdown_if_cmd,
1867 "no shutdown",
1868 NO_STR
1869 "Shutdown the selected interface\n")
1870 {
1871 VTY_DECLVAR_CONTEXT(interface, ifp);
1872 int ret;
1873 struct zebra_if *if_data;
1874
1875 if (ifp->ifindex != IFINDEX_INTERNAL) {
1876 ret = if_set_flags(ifp, IFF_UP | IFF_RUNNING);
1877 if (ret < 0) {
1878 vty_out(vty, "Can't up interface\n");
1879 return CMD_WARNING_CONFIG_FAILED;
1880 }
1881 if_refresh(ifp);
1882
1883 /* Some addresses (in particular, IPv6 addresses on Linux) get
1884 * removed when the interface goes down. They need to be
1885 * readded.
1886 */
1887 if_addr_wakeup(ifp);
1888 }
1889
1890 if_data = ifp->info;
1891 if_data->shutdown = IF_ZEBRA_SHUTDOWN_OFF;
1892
1893 return CMD_SUCCESS;
1894 }
1895
1896 DEFUN (bandwidth_if,
1897 bandwidth_if_cmd,
1898 "bandwidth (1-100000)",
1899 "Set bandwidth informational parameter\n"
1900 "Bandwidth in megabits\n")
1901 {
1902 int idx_number = 1;
1903 VTY_DECLVAR_CONTEXT(interface, ifp);
1904 unsigned int bandwidth;
1905
1906 bandwidth = strtol(argv[idx_number]->arg, NULL, 10);
1907
1908 /* bandwidth range is <1-100000> */
1909 if (bandwidth < 1 || bandwidth > 100000) {
1910 vty_out(vty, "Bandwidth is invalid\n");
1911 return CMD_WARNING_CONFIG_FAILED;
1912 }
1913
1914 ifp->bandwidth = bandwidth;
1915
1916 /* force protocols to recalculate routes due to cost change */
1917 if (if_is_operative(ifp))
1918 zebra_interface_up_update(ifp);
1919
1920 return CMD_SUCCESS;
1921 }
1922
1923 DEFUN (no_bandwidth_if,
1924 no_bandwidth_if_cmd,
1925 "no bandwidth [(1-100000)]",
1926 NO_STR
1927 "Set bandwidth informational parameter\n"
1928 "Bandwidth in megabits\n")
1929 {
1930 VTY_DECLVAR_CONTEXT(interface, ifp);
1931
1932 ifp->bandwidth = 0;
1933
1934 /* force protocols to recalculate routes due to cost change */
1935 if (if_is_operative(ifp))
1936 zebra_interface_up_update(ifp);
1937
1938 return CMD_SUCCESS;
1939 }
1940
1941
1942 struct cmd_node link_params_node = {
1943 LINK_PARAMS_NODE, "%s(config-link-params)# ", 1,
1944 };
1945
1946 static void link_param_cmd_set_uint32(struct interface *ifp, uint32_t *field,
1947 uint32_t type, uint32_t value)
1948 {
1949 /* Update field as needed */
1950 if (IS_PARAM_UNSET(ifp->link_params, type) || *field != value) {
1951 *field = value;
1952 SET_PARAM(ifp->link_params, type);
1953
1954 /* force protocols to update LINK STATE due to parameters change
1955 */
1956 if (if_is_operative(ifp))
1957 zebra_interface_parameters_update(ifp);
1958 }
1959 }
1960 static void link_param_cmd_set_float(struct interface *ifp, float *field,
1961 uint32_t type, float value)
1962 {
1963
1964 /* Update field as needed */
1965 if (IS_PARAM_UNSET(ifp->link_params, type) || *field != value) {
1966 *field = value;
1967 SET_PARAM(ifp->link_params, type);
1968
1969 /* force protocols to update LINK STATE due to parameters change
1970 */
1971 if (if_is_operative(ifp))
1972 zebra_interface_parameters_update(ifp);
1973 }
1974 }
1975
1976 static void link_param_cmd_unset(struct interface *ifp, uint32_t type)
1977 {
1978 if (ifp->link_params == NULL)
1979 return;
1980
1981 /* Unset field */
1982 UNSET_PARAM(ifp->link_params, type);
1983
1984 /* force protocols to update LINK STATE due to parameters change */
1985 if (if_is_operative(ifp))
1986 zebra_interface_parameters_update(ifp);
1987 }
1988
1989 DEFUN_NOSH (link_params,
1990 link_params_cmd,
1991 "link-params",
1992 LINK_PARAMS_STR)
1993 {
1994 /* vty->qobj_index stays the same @ interface pointer */
1995 vty->node = LINK_PARAMS_NODE;
1996
1997 return CMD_SUCCESS;
1998 }
1999
2000 DEFUN_NOSH (exit_link_params,
2001 exit_link_params_cmd,
2002 "exit-link-params",
2003 "Exit from Link Params configuration mode\n")
2004 {
2005 if (vty->node == LINK_PARAMS_NODE)
2006 vty->node = INTERFACE_NODE;
2007 return CMD_SUCCESS;
2008 }
2009
2010 /* Specific Traffic Engineering parameters commands */
2011 DEFUN (link_params_enable,
2012 link_params_enable_cmd,
2013 "enable",
2014 "Activate link parameters on this interface\n")
2015 {
2016 VTY_DECLVAR_CONTEXT(interface, ifp);
2017
2018 /* This command could be issue at startup, when activate MPLS TE */
2019 /* on a new interface or after a ON / OFF / ON toggle */
2020 /* In all case, TE parameters are reset to their default factory */
2021 if (IS_ZEBRA_DEBUG_EVENT)
2022 zlog_debug(
2023 "Link-params: enable TE link parameters on interface %s",
2024 ifp->name);
2025
2026 if (!if_link_params_get(ifp)) {
2027 if (IS_ZEBRA_DEBUG_EVENT)
2028 zlog_debug(
2029 "Link-params: failed to init TE link parameters %s",
2030 ifp->name);
2031
2032 return CMD_WARNING_CONFIG_FAILED;
2033 }
2034
2035 /* force protocols to update LINK STATE due to parameters change */
2036 if (if_is_operative(ifp))
2037 zebra_interface_parameters_update(ifp);
2038
2039 return CMD_SUCCESS;
2040 }
2041
2042 DEFUN (no_link_params_enable,
2043 no_link_params_enable_cmd,
2044 "no enable",
2045 NO_STR
2046 "Disable link parameters on this interface\n")
2047 {
2048 VTY_DECLVAR_CONTEXT(interface, ifp);
2049
2050 zlog_debug("MPLS-TE: disable TE link parameters on interface %s",
2051 ifp->name);
2052
2053 if_link_params_free(ifp);
2054
2055 /* force protocols to update LINK STATE due to parameters change */
2056 if (if_is_operative(ifp))
2057 zebra_interface_parameters_update(ifp);
2058
2059 return CMD_SUCCESS;
2060 }
2061
2062 /* STANDARD TE metrics */
2063 DEFUN (link_params_metric,
2064 link_params_metric_cmd,
2065 "metric (0-4294967295)",
2066 "Link metric for MPLS-TE purpose\n"
2067 "Metric value in decimal\n")
2068 {
2069 int idx_number = 1;
2070 VTY_DECLVAR_CONTEXT(interface, ifp);
2071 struct if_link_params *iflp = if_link_params_get(ifp);
2072 uint32_t metric;
2073
2074 metric = strtoul(argv[idx_number]->arg, NULL, 10);
2075
2076 /* Update TE metric if needed */
2077 link_param_cmd_set_uint32(ifp, &iflp->te_metric, LP_TE_METRIC, metric);
2078
2079 return CMD_SUCCESS;
2080 }
2081
2082 DEFUN (no_link_params_metric,
2083 no_link_params_metric_cmd,
2084 "no metric",
2085 NO_STR
2086 "Disable Link Metric on this interface\n")
2087 {
2088 VTY_DECLVAR_CONTEXT(interface, ifp);
2089
2090 /* Unset TE Metric */
2091 link_param_cmd_unset(ifp, LP_TE_METRIC);
2092
2093 return CMD_SUCCESS;
2094 }
2095
2096 DEFUN (link_params_maxbw,
2097 link_params_maxbw_cmd,
2098 "max-bw BANDWIDTH",
2099 "Maximum bandwidth that can be used\n"
2100 "Bytes/second (IEEE floating point format)\n")
2101 {
2102 int idx_bandwidth = 1;
2103 VTY_DECLVAR_CONTEXT(interface, ifp);
2104 struct if_link_params *iflp = if_link_params_get(ifp);
2105
2106 float bw;
2107
2108 if (sscanf(argv[idx_bandwidth]->arg, "%g", &bw) != 1) {
2109 vty_out(vty, "link_params_maxbw: fscanf: %s\n",
2110 safe_strerror(errno));
2111 return CMD_WARNING_CONFIG_FAILED;
2112 }
2113
2114 /* Check that Maximum bandwidth is not lower than other bandwidth
2115 * parameters */
2116 if ((bw <= iflp->max_rsv_bw) || (bw <= iflp->unrsv_bw[0])
2117 || (bw <= iflp->unrsv_bw[1]) || (bw <= iflp->unrsv_bw[2])
2118 || (bw <= iflp->unrsv_bw[3]) || (bw <= iflp->unrsv_bw[4])
2119 || (bw <= iflp->unrsv_bw[5]) || (bw <= iflp->unrsv_bw[6])
2120 || (bw <= iflp->unrsv_bw[7]) || (bw <= iflp->ava_bw)
2121 || (bw <= iflp->res_bw) || (bw <= iflp->use_bw)) {
2122 vty_out(vty,
2123 "Maximum Bandwidth could not be lower than others bandwidth\n");
2124 return CMD_WARNING_CONFIG_FAILED;
2125 }
2126
2127 /* Update Maximum Bandwidth if needed */
2128 link_param_cmd_set_float(ifp, &iflp->max_bw, LP_MAX_BW, bw);
2129
2130 return CMD_SUCCESS;
2131 }
2132
2133 DEFUN (link_params_max_rsv_bw,
2134 link_params_max_rsv_bw_cmd,
2135 "max-rsv-bw BANDWIDTH",
2136 "Maximum bandwidth that may be reserved\n"
2137 "Bytes/second (IEEE floating point format)\n")
2138 {
2139 int idx_bandwidth = 1;
2140 VTY_DECLVAR_CONTEXT(interface, ifp);
2141 struct if_link_params *iflp = if_link_params_get(ifp);
2142 float bw;
2143
2144 if (sscanf(argv[idx_bandwidth]->arg, "%g", &bw) != 1) {
2145 vty_out(vty, "link_params_max_rsv_bw: fscanf: %s\n",
2146 safe_strerror(errno));
2147 return CMD_WARNING_CONFIG_FAILED;
2148 }
2149
2150 /* Check that bandwidth is not greater than maximum bandwidth parameter
2151 */
2152 if (bw > iflp->max_bw) {
2153 vty_out(vty,
2154 "Maximum Reservable Bandwidth could not be greater than Maximum Bandwidth (%g)\n",
2155 iflp->max_bw);
2156 return CMD_WARNING_CONFIG_FAILED;
2157 }
2158
2159 /* Update Maximum Reservable Bandwidth if needed */
2160 link_param_cmd_set_float(ifp, &iflp->max_rsv_bw, LP_MAX_RSV_BW, bw);
2161
2162 return CMD_SUCCESS;
2163 }
2164
2165 DEFUN (link_params_unrsv_bw,
2166 link_params_unrsv_bw_cmd,
2167 "unrsv-bw (0-7) BANDWIDTH",
2168 "Unreserved bandwidth at each priority level\n"
2169 "Priority\n"
2170 "Bytes/second (IEEE floating point format)\n")
2171 {
2172 int idx_number = 1;
2173 int idx_bandwidth = 2;
2174 VTY_DECLVAR_CONTEXT(interface, ifp);
2175 struct if_link_params *iflp = if_link_params_get(ifp);
2176 int priority;
2177 float bw;
2178
2179 /* We don't have to consider about range check here. */
2180 if (sscanf(argv[idx_number]->arg, "%d", &priority) != 1) {
2181 vty_out(vty, "link_params_unrsv_bw: fscanf: %s\n",
2182 safe_strerror(errno));
2183 return CMD_WARNING_CONFIG_FAILED;
2184 }
2185
2186 if (sscanf(argv[idx_bandwidth]->arg, "%g", &bw) != 1) {
2187 vty_out(vty, "link_params_unrsv_bw: fscanf: %s\n",
2188 safe_strerror(errno));
2189 return CMD_WARNING_CONFIG_FAILED;
2190 }
2191
2192 /* Check that bandwidth is not greater than maximum bandwidth parameter
2193 */
2194 if (bw > iflp->max_bw) {
2195 vty_out(vty,
2196 "UnReserved Bandwidth could not be greater than Maximum Bandwidth (%g)\n",
2197 iflp->max_bw);
2198 return CMD_WARNING_CONFIG_FAILED;
2199 }
2200
2201 /* Update Unreserved Bandwidth if needed */
2202 link_param_cmd_set_float(ifp, &iflp->unrsv_bw[priority], LP_UNRSV_BW,
2203 bw);
2204
2205 return CMD_SUCCESS;
2206 }
2207
2208 DEFUN (link_params_admin_grp,
2209 link_params_admin_grp_cmd,
2210 "admin-grp BITPATTERN",
2211 "Administrative group membership\n"
2212 "32-bit Hexadecimal value (e.g. 0xa1)\n")
2213 {
2214 int idx_bitpattern = 1;
2215 VTY_DECLVAR_CONTEXT(interface, ifp);
2216 struct if_link_params *iflp = if_link_params_get(ifp);
2217 unsigned long value;
2218
2219 if (sscanf(argv[idx_bitpattern]->arg, "0x%lx", &value) != 1) {
2220 vty_out(vty, "link_params_admin_grp: fscanf: %s\n",
2221 safe_strerror(errno));
2222 return CMD_WARNING_CONFIG_FAILED;
2223 }
2224
2225 /* Update Administrative Group if needed */
2226 link_param_cmd_set_uint32(ifp, &iflp->admin_grp, LP_ADM_GRP, value);
2227
2228 return CMD_SUCCESS;
2229 }
2230
2231 DEFUN (no_link_params_admin_grp,
2232 no_link_params_admin_grp_cmd,
2233 "no admin-grp",
2234 NO_STR
2235 "Disable Administrative group membership on this interface\n")
2236 {
2237 VTY_DECLVAR_CONTEXT(interface, ifp);
2238
2239 /* Unset Admin Group */
2240 link_param_cmd_unset(ifp, LP_ADM_GRP);
2241
2242 return CMD_SUCCESS;
2243 }
2244
2245 /* RFC5392 & RFC5316: INTER-AS */
2246 DEFUN (link_params_inter_as,
2247 link_params_inter_as_cmd,
2248 "neighbor A.B.C.D as (1-4294967295)",
2249 "Configure remote ASBR information (Neighbor IP address and AS number)\n"
2250 "Remote IP address in dot decimal A.B.C.D\n"
2251 "Remote AS number\n"
2252 "AS number in the range <1-4294967295>\n")
2253 {
2254 int idx_ipv4 = 1;
2255 int idx_number = 3;
2256
2257 VTY_DECLVAR_CONTEXT(interface, ifp);
2258 struct if_link_params *iflp = if_link_params_get(ifp);
2259 struct in_addr addr;
2260 uint32_t as;
2261
2262 if (!inet_aton(argv[idx_ipv4]->arg, &addr)) {
2263 vty_out(vty, "Please specify Router-Addr by A.B.C.D\n");
2264 return CMD_WARNING_CONFIG_FAILED;
2265 }
2266
2267 as = strtoul(argv[idx_number]->arg, NULL, 10);
2268
2269 /* Update Remote IP and Remote AS fields if needed */
2270 if (IS_PARAM_UNSET(iflp, LP_RMT_AS) || iflp->rmt_as != as
2271 || iflp->rmt_ip.s_addr != addr.s_addr) {
2272
2273 iflp->rmt_as = as;
2274 iflp->rmt_ip.s_addr = addr.s_addr;
2275 SET_PARAM(iflp, LP_RMT_AS);
2276
2277 /* force protocols to update LINK STATE due to parameters change
2278 */
2279 if (if_is_operative(ifp))
2280 zebra_interface_parameters_update(ifp);
2281 }
2282 return CMD_SUCCESS;
2283 }
2284
2285 DEFUN (no_link_params_inter_as,
2286 no_link_params_inter_as_cmd,
2287 "no neighbor",
2288 NO_STR
2289 "Remove Neighbor IP address and AS number for Inter-AS TE\n")
2290 {
2291 VTY_DECLVAR_CONTEXT(interface, ifp);
2292 struct if_link_params *iflp = if_link_params_get(ifp);
2293
2294 /* Reset Remote IP and AS neighbor */
2295 iflp->rmt_as = 0;
2296 iflp->rmt_ip.s_addr = 0;
2297 UNSET_PARAM(iflp, LP_RMT_AS);
2298
2299 /* force protocols to update LINK STATE due to parameters change */
2300 if (if_is_operative(ifp))
2301 zebra_interface_parameters_update(ifp);
2302
2303 return CMD_SUCCESS;
2304 }
2305
2306 /* RFC7471: OSPF Traffic Engineering (TE) Metric extensions &
2307 * draft-ietf-isis-metric-extensions-07.txt */
2308 DEFUN (link_params_delay,
2309 link_params_delay_cmd,
2310 "delay (0-16777215) [min (0-16777215) max (0-16777215)]",
2311 "Unidirectional Average Link Delay\n"
2312 "Average delay in micro-second as decimal (0...16777215)\n"
2313 "Minimum delay\n"
2314 "Minimum delay in micro-second as decimal (0...16777215)\n"
2315 "Maximum delay\n"
2316 "Maximum delay in micro-second as decimal (0...16777215)\n")
2317 {
2318 /* Get and Check new delay values */
2319 uint32_t delay = 0, low = 0, high = 0;
2320 delay = strtoul(argv[1]->arg, NULL, 10);
2321 if (argc == 6) {
2322 low = strtoul(argv[3]->arg, NULL, 10);
2323 high = strtoul(argv[5]->arg, NULL, 10);
2324 }
2325
2326 VTY_DECLVAR_CONTEXT(interface, ifp);
2327 struct if_link_params *iflp = if_link_params_get(ifp);
2328 uint8_t update = 0;
2329
2330 if (argc == 2) {
2331 /* Check new delay value against old Min and Max delays if set
2332 */
2333 if (IS_PARAM_SET(iflp, LP_MM_DELAY)
2334 && (delay <= iflp->min_delay || delay >= iflp->max_delay)) {
2335 vty_out(vty,
2336 "Average delay should be comprise between Min (%d) and Max (%d) delay\n",
2337 iflp->min_delay, iflp->max_delay);
2338 return CMD_WARNING_CONFIG_FAILED;
2339 }
2340 /* Update delay if value is not set or change */
2341 if (IS_PARAM_UNSET(iflp, LP_DELAY) || iflp->av_delay != delay) {
2342 iflp->av_delay = delay;
2343 SET_PARAM(iflp, LP_DELAY);
2344 update = 1;
2345 }
2346 /* Unset Min and Max delays if already set */
2347 if (IS_PARAM_SET(iflp, LP_MM_DELAY)) {
2348 iflp->min_delay = 0;
2349 iflp->max_delay = 0;
2350 UNSET_PARAM(iflp, LP_MM_DELAY);
2351 update = 1;
2352 }
2353 } else {
2354 /* Check new delays value coherency */
2355 if (delay <= low || delay >= high) {
2356 vty_out(vty,
2357 "Average delay should be comprise between Min (%d) and Max (%d) delay\n",
2358 low, high);
2359 return CMD_WARNING_CONFIG_FAILED;
2360 }
2361 /* Update Delays if needed */
2362 if (IS_PARAM_UNSET(iflp, LP_DELAY)
2363 || IS_PARAM_UNSET(iflp, LP_MM_DELAY)
2364 || iflp->av_delay != delay || iflp->min_delay != low
2365 || iflp->max_delay != high) {
2366 iflp->av_delay = delay;
2367 SET_PARAM(iflp, LP_DELAY);
2368 iflp->min_delay = low;
2369 iflp->max_delay = high;
2370 SET_PARAM(iflp, LP_MM_DELAY);
2371 update = 1;
2372 }
2373 }
2374
2375 /* force protocols to update LINK STATE due to parameters change */
2376 if (update == 1 && if_is_operative(ifp))
2377 zebra_interface_parameters_update(ifp);
2378
2379 return CMD_SUCCESS;
2380 }
2381
2382 DEFUN (no_link_params_delay,
2383 no_link_params_delay_cmd,
2384 "no delay",
2385 NO_STR
2386 "Disable Unidirectional Average, Min & Max Link Delay on this interface\n")
2387 {
2388 VTY_DECLVAR_CONTEXT(interface, ifp);
2389 struct if_link_params *iflp = if_link_params_get(ifp);
2390
2391 /* Unset Delays */
2392 iflp->av_delay = 0;
2393 UNSET_PARAM(iflp, LP_DELAY);
2394 iflp->min_delay = 0;
2395 iflp->max_delay = 0;
2396 UNSET_PARAM(iflp, LP_MM_DELAY);
2397
2398 /* force protocols to update LINK STATE due to parameters change */
2399 if (if_is_operative(ifp))
2400 zebra_interface_parameters_update(ifp);
2401
2402 return CMD_SUCCESS;
2403 }
2404
2405 DEFUN (link_params_delay_var,
2406 link_params_delay_var_cmd,
2407 "delay-variation (0-16777215)",
2408 "Unidirectional Link Delay Variation\n"
2409 "delay variation in micro-second as decimal (0...16777215)\n")
2410 {
2411 int idx_number = 1;
2412 VTY_DECLVAR_CONTEXT(interface, ifp);
2413 struct if_link_params *iflp = if_link_params_get(ifp);
2414 uint32_t value;
2415
2416 value = strtoul(argv[idx_number]->arg, NULL, 10);
2417
2418 /* Update Delay Variation if needed */
2419 link_param_cmd_set_uint32(ifp, &iflp->delay_var, LP_DELAY_VAR, value);
2420
2421 return CMD_SUCCESS;
2422 }
2423
2424 DEFUN (no_link_params_delay_var,
2425 no_link_params_delay_var_cmd,
2426 "no delay-variation",
2427 NO_STR
2428 "Disable Unidirectional Delay Variation on this interface\n")
2429 {
2430 VTY_DECLVAR_CONTEXT(interface, ifp);
2431
2432 /* Unset Delay Variation */
2433 link_param_cmd_unset(ifp, LP_DELAY_VAR);
2434
2435 return CMD_SUCCESS;
2436 }
2437
2438 DEFUN (link_params_pkt_loss,
2439 link_params_pkt_loss_cmd,
2440 "packet-loss PERCENTAGE",
2441 "Unidirectional Link Packet Loss\n"
2442 "percentage of total traffic by 0.000003% step and less than 50.331642%\n")
2443 {
2444 int idx_percentage = 1;
2445 VTY_DECLVAR_CONTEXT(interface, ifp);
2446 struct if_link_params *iflp = if_link_params_get(ifp);
2447 float fval;
2448
2449 if (sscanf(argv[idx_percentage]->arg, "%g", &fval) != 1) {
2450 vty_out(vty, "link_params_pkt_loss: fscanf: %s\n",
2451 safe_strerror(errno));
2452 return CMD_WARNING_CONFIG_FAILED;
2453 }
2454
2455 if (fval > MAX_PKT_LOSS)
2456 fval = MAX_PKT_LOSS;
2457
2458 /* Update Packet Loss if needed */
2459 link_param_cmd_set_float(ifp, &iflp->pkt_loss, LP_PKT_LOSS, fval);
2460
2461 return CMD_SUCCESS;
2462 }
2463
2464 DEFUN (no_link_params_pkt_loss,
2465 no_link_params_pkt_loss_cmd,
2466 "no packet-loss",
2467 NO_STR
2468 "Disable Unidirectional Link Packet Loss on this interface\n")
2469 {
2470 VTY_DECLVAR_CONTEXT(interface, ifp);
2471
2472 /* Unset Packet Loss */
2473 link_param_cmd_unset(ifp, LP_PKT_LOSS);
2474
2475 return CMD_SUCCESS;
2476 }
2477
2478 DEFUN (link_params_res_bw,
2479 link_params_res_bw_cmd,
2480 "res-bw BANDWIDTH",
2481 "Unidirectional Residual Bandwidth\n"
2482 "Bytes/second (IEEE floating point format)\n")
2483 {
2484 int idx_bandwidth = 1;
2485 VTY_DECLVAR_CONTEXT(interface, ifp);
2486 struct if_link_params *iflp = if_link_params_get(ifp);
2487 float bw;
2488
2489 if (sscanf(argv[idx_bandwidth]->arg, "%g", &bw) != 1) {
2490 vty_out(vty, "link_params_res_bw: fscanf: %s\n",
2491 safe_strerror(errno));
2492 return CMD_WARNING_CONFIG_FAILED;
2493 }
2494
2495 /* Check that bandwidth is not greater than maximum bandwidth parameter
2496 */
2497 if (bw > iflp->max_bw) {
2498 vty_out(vty,
2499 "Residual Bandwidth could not be greater than Maximum Bandwidth (%g)\n",
2500 iflp->max_bw);
2501 return CMD_WARNING_CONFIG_FAILED;
2502 }
2503
2504 /* Update Residual Bandwidth if needed */
2505 link_param_cmd_set_float(ifp, &iflp->res_bw, LP_RES_BW, bw);
2506
2507 return CMD_SUCCESS;
2508 }
2509
2510 DEFUN (no_link_params_res_bw,
2511 no_link_params_res_bw_cmd,
2512 "no res-bw",
2513 NO_STR
2514 "Disable Unidirectional Residual Bandwidth on this interface\n")
2515 {
2516 VTY_DECLVAR_CONTEXT(interface, ifp);
2517
2518 /* Unset Residual Bandwidth */
2519 link_param_cmd_unset(ifp, LP_RES_BW);
2520
2521 return CMD_SUCCESS;
2522 }
2523
2524 DEFUN (link_params_ava_bw,
2525 link_params_ava_bw_cmd,
2526 "ava-bw BANDWIDTH",
2527 "Unidirectional Available Bandwidth\n"
2528 "Bytes/second (IEEE floating point format)\n")
2529 {
2530 int idx_bandwidth = 1;
2531 VTY_DECLVAR_CONTEXT(interface, ifp);
2532 struct if_link_params *iflp = if_link_params_get(ifp);
2533 float bw;
2534
2535 if (sscanf(argv[idx_bandwidth]->arg, "%g", &bw) != 1) {
2536 vty_out(vty, "link_params_ava_bw: fscanf: %s\n",
2537 safe_strerror(errno));
2538 return CMD_WARNING_CONFIG_FAILED;
2539 }
2540
2541 /* Check that bandwidth is not greater than maximum bandwidth parameter
2542 */
2543 if (bw > iflp->max_bw) {
2544 vty_out(vty,
2545 "Available Bandwidth could not be greater than Maximum Bandwidth (%g)\n",
2546 iflp->max_bw);
2547 return CMD_WARNING_CONFIG_FAILED;
2548 }
2549
2550 /* Update Residual Bandwidth if needed */
2551 link_param_cmd_set_float(ifp, &iflp->ava_bw, LP_AVA_BW, bw);
2552
2553 return CMD_SUCCESS;
2554 }
2555
2556 DEFUN (no_link_params_ava_bw,
2557 no_link_params_ava_bw_cmd,
2558 "no ava-bw",
2559 NO_STR
2560 "Disable Unidirectional Available Bandwidth on this interface\n")
2561 {
2562 VTY_DECLVAR_CONTEXT(interface, ifp);
2563
2564 /* Unset Available Bandwidth */
2565 link_param_cmd_unset(ifp, LP_AVA_BW);
2566
2567 return CMD_SUCCESS;
2568 }
2569
2570 DEFUN (link_params_use_bw,
2571 link_params_use_bw_cmd,
2572 "use-bw BANDWIDTH",
2573 "Unidirectional Utilised Bandwidth\n"
2574 "Bytes/second (IEEE floating point format)\n")
2575 {
2576 int idx_bandwidth = 1;
2577 VTY_DECLVAR_CONTEXT(interface, ifp);
2578 struct if_link_params *iflp = if_link_params_get(ifp);
2579 float bw;
2580
2581 if (sscanf(argv[idx_bandwidth]->arg, "%g", &bw) != 1) {
2582 vty_out(vty, "link_params_use_bw: fscanf: %s\n",
2583 safe_strerror(errno));
2584 return CMD_WARNING_CONFIG_FAILED;
2585 }
2586
2587 /* Check that bandwidth is not greater than maximum bandwidth parameter
2588 */
2589 if (bw > iflp->max_bw) {
2590 vty_out(vty,
2591 "Utilised Bandwidth could not be greater than Maximum Bandwidth (%g)\n",
2592 iflp->max_bw);
2593 return CMD_WARNING_CONFIG_FAILED;
2594 }
2595
2596 /* Update Utilized Bandwidth if needed */
2597 link_param_cmd_set_float(ifp, &iflp->use_bw, LP_USE_BW, bw);
2598
2599 return CMD_SUCCESS;
2600 }
2601
2602 DEFUN (no_link_params_use_bw,
2603 no_link_params_use_bw_cmd,
2604 "no use-bw",
2605 NO_STR
2606 "Disable Unidirectional Utilised Bandwidth on this interface\n")
2607 {
2608 VTY_DECLVAR_CONTEXT(interface, ifp);
2609
2610 /* Unset Utilised Bandwidth */
2611 link_param_cmd_unset(ifp, LP_USE_BW);
2612
2613 return CMD_SUCCESS;
2614 }
2615
2616 static int ip_address_install(struct vty *vty, struct interface *ifp,
2617 const char *addr_str, const char *peer_str,
2618 const char *label)
2619 {
2620 struct zebra_if *if_data;
2621 struct prefix_ipv4 lp, pp;
2622 struct connected *ifc;
2623 struct prefix_ipv4 *p;
2624 int ret;
2625
2626 if_data = ifp->info;
2627
2628 ret = str2prefix_ipv4(addr_str, &lp);
2629 if (ret <= 0) {
2630 vty_out(vty, "%% Malformed address \n");
2631 return CMD_WARNING_CONFIG_FAILED;
2632 }
2633
2634 if (ipv4_martian(&lp.prefix)) {
2635 vty_out(vty, "%% Invalid address\n");
2636 return CMD_WARNING_CONFIG_FAILED;
2637 }
2638
2639 if (peer_str) {
2640 if (lp.prefixlen != 32) {
2641 vty_out(vty,
2642 "%% Local prefix length for P-t-P address must be /32\n");
2643 return CMD_WARNING_CONFIG_FAILED;
2644 }
2645
2646 ret = str2prefix_ipv4(peer_str, &pp);
2647 if (ret <= 0) {
2648 vty_out(vty, "%% Malformed peer address\n");
2649 return CMD_WARNING_CONFIG_FAILED;
2650 }
2651 }
2652
2653 ifc = connected_check_ptp(ifp, &lp, peer_str ? &pp : NULL);
2654 if (!ifc) {
2655 ifc = connected_new();
2656 ifc->ifp = ifp;
2657
2658 /* Address. */
2659 p = prefix_ipv4_new();
2660 *p = lp;
2661 ifc->address = (struct prefix *)p;
2662
2663 if (peer_str) {
2664 SET_FLAG(ifc->flags, ZEBRA_IFA_PEER);
2665 p = prefix_ipv4_new();
2666 *p = pp;
2667 ifc->destination = (struct prefix *)p;
2668 } else if (p->prefixlen <= IPV4_MAX_PREFIXLEN - 2) {
2669 p = prefix_ipv4_new();
2670 *p = lp;
2671 p->prefix.s_addr = ipv4_broadcast_addr(p->prefix.s_addr,
2672 p->prefixlen);
2673 ifc->destination = (struct prefix *)p;
2674 }
2675
2676 /* Label. */
2677 if (label)
2678 ifc->label = XSTRDUP(MTYPE_CONNECTED_LABEL, label);
2679
2680 /* Add to linked list. */
2681 listnode_add(ifp->connected, ifc);
2682 }
2683
2684 /* This address is configured from zebra. */
2685 if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_CONFIGURED))
2686 SET_FLAG(ifc->conf, ZEBRA_IFC_CONFIGURED);
2687
2688 /* In case of this route need to install kernel. */
2689 if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_QUEUED)
2690 && CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE)
2691 && !(if_data && if_data->shutdown == IF_ZEBRA_SHUTDOWN_ON)) {
2692 /* Some system need to up the interface to set IP address. */
2693 if (!if_is_up(ifp)) {
2694 if_set_flags(ifp, IFF_UP | IFF_RUNNING);
2695 if_refresh(ifp);
2696 }
2697
2698 ret = if_set_prefix(ifp, ifc);
2699 if (ret < 0) {
2700 vty_out(vty, "%% Can't set interface IP address: %s.\n",
2701 safe_strerror(errno));
2702 return CMD_WARNING_CONFIG_FAILED;
2703 }
2704
2705 SET_FLAG(ifc->conf, ZEBRA_IFC_QUEUED);
2706 /* The address will be advertised to zebra clients when the
2707 * notification
2708 * from the kernel has been received.
2709 * It will also be added to the subnet chain list, then. */
2710 }
2711
2712 return CMD_SUCCESS;
2713 }
2714
2715 static int ip_address_uninstall(struct vty *vty, struct interface *ifp,
2716 const char *addr_str, const char *peer_str,
2717 const char *label)
2718 {
2719 struct prefix_ipv4 lp, pp;
2720 struct connected *ifc;
2721 int ret;
2722
2723 /* Convert to prefix structure. */
2724 ret = str2prefix_ipv4(addr_str, &lp);
2725 if (ret <= 0) {
2726 vty_out(vty, "%% Malformed address \n");
2727 return CMD_WARNING_CONFIG_FAILED;
2728 }
2729
2730 if (peer_str) {
2731 if (lp.prefixlen != 32) {
2732 vty_out(vty,
2733 "%% Local prefix length for P-t-P address must be /32\n");
2734 return CMD_WARNING_CONFIG_FAILED;
2735 }
2736
2737 ret = str2prefix_ipv4(peer_str, &pp);
2738 if (ret <= 0) {
2739 vty_out(vty, "%% Malformed peer address\n");
2740 return CMD_WARNING_CONFIG_FAILED;
2741 }
2742 }
2743
2744 /* Check current interface address. */
2745 ifc = connected_check_ptp(ifp, &lp, peer_str ? &pp : NULL);
2746 if (!ifc) {
2747 vty_out(vty, "%% Can't find address\n");
2748 return CMD_WARNING_CONFIG_FAILED;
2749 }
2750
2751 /* This is not configured address. */
2752 if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_CONFIGURED))
2753 return CMD_WARNING_CONFIG_FAILED;
2754
2755 UNSET_FLAG(ifc->conf, ZEBRA_IFC_CONFIGURED);
2756
2757 /* This is not real address or interface is not active. */
2758 if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_QUEUED)
2759 || !CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE)) {
2760 listnode_delete(ifp->connected, ifc);
2761 connected_free(ifc);
2762 return CMD_WARNING_CONFIG_FAILED;
2763 }
2764
2765 /* This is real route. */
2766 ret = if_unset_prefix(ifp, ifc);
2767 if (ret < 0) {
2768 vty_out(vty, "%% Can't unset interface IP address: %s.\n",
2769 safe_strerror(errno));
2770 return CMD_WARNING_CONFIG_FAILED;
2771 }
2772 UNSET_FLAG(ifc->conf, ZEBRA_IFC_QUEUED);
2773 /* we will receive a kernel notification about this route being removed.
2774 * this will trigger its removal from the connected list. */
2775 return CMD_SUCCESS;
2776 }
2777
2778 DEFUN (ip_address,
2779 ip_address_cmd,
2780 "ip address A.B.C.D/M",
2781 "Interface Internet Protocol config commands\n"
2782 "Set the IP address of an interface\n"
2783 "IP address (e.g. 10.0.0.1/8)\n")
2784 {
2785 int idx_ipv4_prefixlen = 2;
2786 VTY_DECLVAR_CONTEXT(interface, ifp);
2787 return ip_address_install(vty, ifp, argv[idx_ipv4_prefixlen]->arg, NULL,
2788 NULL);
2789 }
2790
2791 DEFUN (no_ip_address,
2792 no_ip_address_cmd,
2793 "no ip address A.B.C.D/M",
2794 NO_STR
2795 "Interface Internet Protocol config commands\n"
2796 "Set the IP address of an interface\n"
2797 "IP Address (e.g. 10.0.0.1/8)\n")
2798 {
2799 int idx_ipv4_prefixlen = 3;
2800 VTY_DECLVAR_CONTEXT(interface, ifp);
2801 return ip_address_uninstall(vty, ifp, argv[idx_ipv4_prefixlen]->arg,
2802 NULL, NULL);
2803 }
2804
2805 DEFUN(ip_address_peer,
2806 ip_address_peer_cmd,
2807 "ip address A.B.C.D peer A.B.C.D/M",
2808 "Interface Internet Protocol config commands\n"
2809 "Set the IP address of an interface\n"
2810 "Local IP (e.g. 10.0.0.1) for P-t-P address\n"
2811 "Specify P-t-P address\n"
2812 "Peer IP address (e.g. 10.0.0.1/8)\n")
2813 {
2814 VTY_DECLVAR_CONTEXT(interface, ifp);
2815 return ip_address_install(vty, ifp, argv[2]->arg, argv[4]->arg, NULL);
2816 }
2817
2818 DEFUN(no_ip_address_peer,
2819 no_ip_address_peer_cmd,
2820 "no ip address A.B.C.D peer A.B.C.D/M",
2821 NO_STR
2822 "Interface Internet Protocol config commands\n"
2823 "Set the IP address of an interface\n"
2824 "Local IP (e.g. 10.0.0.1) for P-t-P address\n"
2825 "Specify P-t-P address\n"
2826 "Peer IP address (e.g. 10.0.0.1/8)\n")
2827 {
2828 VTY_DECLVAR_CONTEXT(interface, ifp);
2829 return ip_address_uninstall(vty, ifp, argv[3]->arg, argv[5]->arg, NULL);
2830 }
2831
2832 #ifdef HAVE_NETLINK
2833 DEFUN (ip_address_label,
2834 ip_address_label_cmd,
2835 "ip address A.B.C.D/M label LINE",
2836 "Interface Internet Protocol config commands\n"
2837 "Set the IP address of an interface\n"
2838 "IP address (e.g. 10.0.0.1/8)\n"
2839 "Label of this address\n"
2840 "Label\n")
2841 {
2842 int idx_ipv4_prefixlen = 2;
2843 int idx_line = 4;
2844 VTY_DECLVAR_CONTEXT(interface, ifp);
2845 return ip_address_install(vty, ifp, argv[idx_ipv4_prefixlen]->arg, NULL,
2846 argv[idx_line]->arg);
2847 }
2848
2849 DEFUN (no_ip_address_label,
2850 no_ip_address_label_cmd,
2851 "no ip address A.B.C.D/M label LINE",
2852 NO_STR
2853 "Interface Internet Protocol config commands\n"
2854 "Set the IP address of an interface\n"
2855 "IP address (e.g. 10.0.0.1/8)\n"
2856 "Label of this address\n"
2857 "Label\n")
2858 {
2859 int idx_ipv4_prefixlen = 3;
2860 int idx_line = 5;
2861 VTY_DECLVAR_CONTEXT(interface, ifp);
2862 return ip_address_uninstall(vty, ifp, argv[idx_ipv4_prefixlen]->arg,
2863 NULL, argv[idx_line]->arg);
2864 }
2865 #endif /* HAVE_NETLINK */
2866
2867 static int ipv6_address_install(struct vty *vty, struct interface *ifp,
2868 const char *addr_str, const char *peer_str,
2869 const char *label)
2870 {
2871 struct zebra_if *if_data;
2872 struct prefix_ipv6 cp;
2873 struct connected *ifc;
2874 struct prefix_ipv6 *p;
2875 int ret;
2876
2877 if_data = ifp->info;
2878
2879 ret = str2prefix_ipv6(addr_str, &cp);
2880 if (ret <= 0) {
2881 vty_out(vty, "%% Malformed address \n");
2882 return CMD_WARNING_CONFIG_FAILED;
2883 }
2884
2885 if (ipv6_martian(&cp.prefix)) {
2886 vty_out(vty, "%% Invalid address\n");
2887 return CMD_WARNING_CONFIG_FAILED;
2888 }
2889
2890 ifc = connected_check(ifp, (struct prefix *)&cp);
2891 if (!ifc) {
2892 ifc = connected_new();
2893 ifc->ifp = ifp;
2894
2895 /* Address. */
2896 p = prefix_ipv6_new();
2897 *p = cp;
2898 ifc->address = (struct prefix *)p;
2899
2900 /* Label. */
2901 if (label)
2902 ifc->label = XSTRDUP(MTYPE_CONNECTED_LABEL, label);
2903
2904 /* Add to linked list. */
2905 listnode_add(ifp->connected, ifc);
2906 }
2907
2908 /* This address is configured from zebra. */
2909 if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_CONFIGURED))
2910 SET_FLAG(ifc->conf, ZEBRA_IFC_CONFIGURED);
2911
2912 /* In case of this route need to install kernel. */
2913 if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_QUEUED)
2914 && CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE)
2915 && !(if_data && if_data->shutdown == IF_ZEBRA_SHUTDOWN_ON)) {
2916 /* Some system need to up the interface to set IP address. */
2917 if (!if_is_up(ifp)) {
2918 if_set_flags(ifp, IFF_UP | IFF_RUNNING);
2919 if_refresh(ifp);
2920 }
2921
2922 ret = if_prefix_add_ipv6(ifp, ifc);
2923
2924 if (ret < 0) {
2925 vty_out(vty, "%% Can't set interface IP address: %s.\n",
2926 safe_strerror(errno));
2927 return CMD_WARNING_CONFIG_FAILED;
2928 }
2929
2930 SET_FLAG(ifc->conf, ZEBRA_IFC_QUEUED);
2931 /* The address will be advertised to zebra clients when the
2932 * notification
2933 * from the kernel has been received. */
2934 }
2935
2936 return CMD_SUCCESS;
2937 }
2938
2939 /* Return true if an ipv6 address is configured on ifp */
2940 int ipv6_address_configured(struct interface *ifp)
2941 {
2942 struct connected *connected;
2943 struct listnode *node;
2944
2945 for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, connected))
2946 if (CHECK_FLAG(connected->conf, ZEBRA_IFC_REAL)
2947 && (connected->address->family == AF_INET6))
2948 return 1;
2949
2950 return 0;
2951 }
2952
2953 static int ipv6_address_uninstall(struct vty *vty, struct interface *ifp,
2954 const char *addr_str, const char *peer_str,
2955 const char *label)
2956 {
2957 struct prefix_ipv6 cp;
2958 struct connected *ifc;
2959 int ret;
2960
2961 /* Convert to prefix structure. */
2962 ret = str2prefix_ipv6(addr_str, &cp);
2963 if (ret <= 0) {
2964 vty_out(vty, "%% Malformed address \n");
2965 return CMD_WARNING_CONFIG_FAILED;
2966 }
2967
2968 /* Check current interface address. */
2969 ifc = connected_check(ifp, (struct prefix *)&cp);
2970 if (!ifc) {
2971 vty_out(vty, "%% Can't find address\n");
2972 return CMD_WARNING_CONFIG_FAILED;
2973 }
2974
2975 /* This is not configured address. */
2976 if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_CONFIGURED))
2977 return CMD_WARNING_CONFIG_FAILED;
2978
2979 UNSET_FLAG(ifc->conf, ZEBRA_IFC_CONFIGURED);
2980
2981 /* This is not real address or interface is not active. */
2982 if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_QUEUED)
2983 || !CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE)) {
2984 listnode_delete(ifp->connected, ifc);
2985 connected_free(ifc);
2986 return CMD_WARNING_CONFIG_FAILED;
2987 }
2988
2989 /* This is real route. */
2990 ret = if_prefix_delete_ipv6(ifp, ifc);
2991 if (ret < 0) {
2992 vty_out(vty, "%% Can't unset interface IP address: %s.\n",
2993 safe_strerror(errno));
2994 return CMD_WARNING_CONFIG_FAILED;
2995 }
2996
2997 UNSET_FLAG(ifc->conf, ZEBRA_IFC_QUEUED);
2998 /* This information will be propagated to the zclients when the
2999 * kernel notification is received. */
3000 return CMD_SUCCESS;
3001 }
3002
3003 DEFUN (ipv6_address,
3004 ipv6_address_cmd,
3005 "ipv6 address X:X::X:X/M",
3006 "Interface IPv6 config commands\n"
3007 "Set the IP address of an interface\n"
3008 "IPv6 address (e.g. 3ffe:506::1/48)\n")
3009 {
3010 int idx_ipv6_prefixlen = 2;
3011 VTY_DECLVAR_CONTEXT(interface, ifp);
3012 return ipv6_address_install(vty, ifp, argv[idx_ipv6_prefixlen]->arg,
3013 NULL, NULL);
3014 }
3015
3016 DEFUN (no_ipv6_address,
3017 no_ipv6_address_cmd,
3018 "no ipv6 address X:X::X:X/M",
3019 NO_STR
3020 "Interface IPv6 config commands\n"
3021 "Set the IP address of an interface\n"
3022 "IPv6 address (e.g. 3ffe:506::1/48)\n")
3023 {
3024 int idx_ipv6_prefixlen = 3;
3025 VTY_DECLVAR_CONTEXT(interface, ifp);
3026 return ipv6_address_uninstall(vty, ifp, argv[idx_ipv6_prefixlen]->arg,
3027 NULL, NULL);
3028 }
3029
3030 static int link_params_config_write(struct vty *vty, struct interface *ifp)
3031 {
3032 int i;
3033
3034 if ((ifp == NULL) || !HAS_LINK_PARAMS(ifp))
3035 return -1;
3036
3037 struct if_link_params *iflp = ifp->link_params;
3038
3039 vty_out(vty, " link-params\n");
3040 vty_out(vty, " enable\n");
3041 if (IS_PARAM_SET(iflp, LP_TE_METRIC) && iflp->te_metric != ifp->metric)
3042 vty_out(vty, " metric %u\n", iflp->te_metric);
3043 if (IS_PARAM_SET(iflp, LP_MAX_BW) && iflp->max_bw != iflp->default_bw)
3044 vty_out(vty, " max-bw %g\n", iflp->max_bw);
3045 if (IS_PARAM_SET(iflp, LP_MAX_RSV_BW)
3046 && iflp->max_rsv_bw != iflp->default_bw)
3047 vty_out(vty, " max-rsv-bw %g\n", iflp->max_rsv_bw);
3048 if (IS_PARAM_SET(iflp, LP_UNRSV_BW)) {
3049 for (i = 0; i < 8; i++)
3050 if (iflp->unrsv_bw[i] != iflp->default_bw)
3051 vty_out(vty, " unrsv-bw %d %g\n", i,
3052 iflp->unrsv_bw[i]);
3053 }
3054 if (IS_PARAM_SET(iflp, LP_ADM_GRP))
3055 vty_out(vty, " admin-grp 0x%x\n", iflp->admin_grp);
3056 if (IS_PARAM_SET(iflp, LP_DELAY)) {
3057 vty_out(vty, " delay %u", iflp->av_delay);
3058 if (IS_PARAM_SET(iflp, LP_MM_DELAY)) {
3059 vty_out(vty, " min %u", iflp->min_delay);
3060 vty_out(vty, " max %u", iflp->max_delay);
3061 }
3062 vty_out(vty, "\n");
3063 }
3064 if (IS_PARAM_SET(iflp, LP_DELAY_VAR))
3065 vty_out(vty, " delay-variation %u\n", iflp->delay_var);
3066 if (IS_PARAM_SET(iflp, LP_PKT_LOSS))
3067 vty_out(vty, " packet-loss %g\n", iflp->pkt_loss);
3068 if (IS_PARAM_SET(iflp, LP_AVA_BW))
3069 vty_out(vty, " ava-bw %g\n", iflp->ava_bw);
3070 if (IS_PARAM_SET(iflp, LP_RES_BW))
3071 vty_out(vty, " res-bw %g\n", iflp->res_bw);
3072 if (IS_PARAM_SET(iflp, LP_USE_BW))
3073 vty_out(vty, " use-bw %g\n", iflp->use_bw);
3074 if (IS_PARAM_SET(iflp, LP_RMT_AS))
3075 vty_out(vty, " neighbor %s as %u\n", inet_ntoa(iflp->rmt_ip),
3076 iflp->rmt_as);
3077 vty_out(vty, " exit-link-params\n");
3078 return 0;
3079 }
3080
3081 static int if_config_write(struct vty *vty)
3082 {
3083 struct vrf *vrf0;
3084 struct interface *ifp;
3085
3086 zebra_ptm_write(vty);
3087
3088 RB_FOREACH (vrf0, vrf_name_head, &vrfs_by_name)
3089 FOR_ALL_INTERFACES (vrf0, ifp) {
3090 struct zebra_if *if_data;
3091 struct listnode *addrnode;
3092 struct connected *ifc;
3093 struct prefix *p;
3094 struct vrf *vrf;
3095
3096 if_data = ifp->info;
3097 vrf = vrf_lookup_by_id(ifp->vrf_id);
3098
3099 if (ifp->vrf_id == VRF_DEFAULT)
3100 vty_frame(vty, "interface %s\n", ifp->name);
3101 else
3102 vty_frame(vty, "interface %s vrf %s\n",
3103 ifp->name, vrf->name);
3104
3105 if (if_data) {
3106 if (if_data->shutdown == IF_ZEBRA_SHUTDOWN_ON)
3107 vty_out(vty, " shutdown\n");
3108
3109 zebra_ptm_if_write(vty, if_data);
3110 }
3111
3112 if (ifp->desc)
3113 vty_out(vty, " description %s\n", ifp->desc);
3114
3115 /* Assign bandwidth here to avoid unnecessary interface
3116 flap
3117 while processing config script */
3118 if (ifp->bandwidth != 0)
3119 vty_out(vty, " bandwidth %u\n", ifp->bandwidth);
3120
3121 if (!CHECK_FLAG(ifp->status,
3122 ZEBRA_INTERFACE_LINKDETECTION))
3123 vty_out(vty, " no link-detect\n");
3124
3125 for (ALL_LIST_ELEMENTS_RO(ifp->connected, addrnode,
3126 ifc)) {
3127 if (CHECK_FLAG(ifc->conf,
3128 ZEBRA_IFC_CONFIGURED)) {
3129 char buf[INET6_ADDRSTRLEN];
3130 p = ifc->address;
3131 vty_out(vty, " ip%s address %s",
3132 p->family == AF_INET ? ""
3133 : "v6",
3134 inet_ntop(p->family,
3135 &p->u.prefix, buf,
3136 sizeof(buf)));
3137 if (CONNECTED_PEER(ifc)) {
3138 p = ifc->destination;
3139 vty_out(vty, " peer %s",
3140 inet_ntop(p->family,
3141 &p->u.prefix,
3142 buf,
3143 sizeof(buf)));
3144 }
3145 vty_out(vty, "/%d", p->prefixlen);
3146
3147 if (ifc->label)
3148 vty_out(vty, " label %s",
3149 ifc->label);
3150
3151 vty_out(vty, "\n");
3152 }
3153 }
3154
3155 if (if_data) {
3156 if (if_data->multicast
3157 != IF_ZEBRA_MULTICAST_UNSPEC)
3158 vty_out(vty, " %smulticast\n",
3159 if_data->multicast
3160 == IF_ZEBRA_MULTICAST_ON
3161 ? ""
3162 : "no ");
3163 }
3164
3165 hook_call(zebra_if_config_wr, vty, ifp);
3166
3167 link_params_config_write(vty, ifp);
3168
3169 vty_endframe(vty, "!\n");
3170 }
3171 return 0;
3172 }
3173
3174 /* Allocate and initialize interface vector. */
3175 void zebra_if_init(void)
3176 {
3177 /* Initialize interface and new hook. */
3178 hook_register_prio(if_add, 0, if_zebra_new_hook);
3179 hook_register_prio(if_del, 0, if_zebra_delete_hook);
3180
3181 /* Install configuration write function. */
3182 install_node(&interface_node, if_config_write);
3183 install_node(&link_params_node, NULL);
3184 if_cmd_init();
3185
3186 install_element(VIEW_NODE, &show_interface_cmd);
3187 install_element(VIEW_NODE, &show_interface_vrf_all_cmd);
3188 install_element(VIEW_NODE, &show_interface_name_vrf_cmd);
3189 install_element(VIEW_NODE, &show_interface_name_vrf_all_cmd);
3190
3191 install_element(ENABLE_NODE, &show_interface_desc_cmd);
3192 install_element(ENABLE_NODE, &show_interface_desc_vrf_all_cmd);
3193 install_element(INTERFACE_NODE, &multicast_cmd);
3194 install_element(INTERFACE_NODE, &no_multicast_cmd);
3195 install_element(INTERFACE_NODE, &linkdetect_cmd);
3196 install_element(INTERFACE_NODE, &no_linkdetect_cmd);
3197 install_element(INTERFACE_NODE, &shutdown_if_cmd);
3198 install_element(INTERFACE_NODE, &no_shutdown_if_cmd);
3199 install_element(INTERFACE_NODE, &bandwidth_if_cmd);
3200 install_element(INTERFACE_NODE, &no_bandwidth_if_cmd);
3201 install_element(INTERFACE_NODE, &ip_address_cmd);
3202 install_element(INTERFACE_NODE, &no_ip_address_cmd);
3203 install_element(INTERFACE_NODE, &ip_address_peer_cmd);
3204 install_element(INTERFACE_NODE, &no_ip_address_peer_cmd);
3205 install_element(INTERFACE_NODE, &ipv6_address_cmd);
3206 install_element(INTERFACE_NODE, &no_ipv6_address_cmd);
3207 #ifdef HAVE_NETLINK
3208 install_element(INTERFACE_NODE, &ip_address_label_cmd);
3209 install_element(INTERFACE_NODE, &no_ip_address_label_cmd);
3210 #endif /* HAVE_NETLINK */
3211 install_element(INTERFACE_NODE, &link_params_cmd);
3212 install_default(LINK_PARAMS_NODE);
3213 install_element(LINK_PARAMS_NODE, &link_params_enable_cmd);
3214 install_element(LINK_PARAMS_NODE, &no_link_params_enable_cmd);
3215 install_element(LINK_PARAMS_NODE, &link_params_metric_cmd);
3216 install_element(LINK_PARAMS_NODE, &no_link_params_metric_cmd);
3217 install_element(LINK_PARAMS_NODE, &link_params_maxbw_cmd);
3218 install_element(LINK_PARAMS_NODE, &link_params_max_rsv_bw_cmd);
3219 install_element(LINK_PARAMS_NODE, &link_params_unrsv_bw_cmd);
3220 install_element(LINK_PARAMS_NODE, &link_params_admin_grp_cmd);
3221 install_element(LINK_PARAMS_NODE, &no_link_params_admin_grp_cmd);
3222 install_element(LINK_PARAMS_NODE, &link_params_inter_as_cmd);
3223 install_element(LINK_PARAMS_NODE, &no_link_params_inter_as_cmd);
3224 install_element(LINK_PARAMS_NODE, &link_params_delay_cmd);
3225 install_element(LINK_PARAMS_NODE, &no_link_params_delay_cmd);
3226 install_element(LINK_PARAMS_NODE, &link_params_delay_var_cmd);
3227 install_element(LINK_PARAMS_NODE, &no_link_params_delay_var_cmd);
3228 install_element(LINK_PARAMS_NODE, &link_params_pkt_loss_cmd);
3229 install_element(LINK_PARAMS_NODE, &no_link_params_pkt_loss_cmd);
3230 install_element(LINK_PARAMS_NODE, &link_params_ava_bw_cmd);
3231 install_element(LINK_PARAMS_NODE, &no_link_params_ava_bw_cmd);
3232 install_element(LINK_PARAMS_NODE, &link_params_res_bw_cmd);
3233 install_element(LINK_PARAMS_NODE, &no_link_params_res_bw_cmd);
3234 install_element(LINK_PARAMS_NODE, &link_params_use_bw_cmd);
3235 install_element(LINK_PARAMS_NODE, &no_link_params_use_bw_cmd);
3236 install_element(LINK_PARAMS_NODE, &exit_link_params_cmd);
3237 }