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