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