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