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