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