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