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