]> git.proxmox.com Git - mirror_frr.git/blob - zebra/interface.c
Quagga: Implement VRF change semantics for an interface
[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 "ioctl.h"
32 #include "connected.h"
33 #include "log.h"
34 #include "zclient.h"
35 #include "vrf.h"
36
37 #include "zebra/interface.h"
38 #include "zebra/rtadv.h"
39 #include "zebra/rib.h"
40 #include "zebra/zserv.h"
41 #include "zebra/redistribute.h"
42 #include "zebra/debug.h"
43 #include "zebra/irdp.h"
44 #include "zebra/zebra_ptm.h"
45 #include "zebra/rt_netlink.h"
46 #include "zebra/zserv.h"
47 #include "zebra/interface.h"
48
49 #define ZEBRA_PTM_SUPPORT
50
51 #if defined (HAVE_RTADV)
52 /* Order is intentional. Matches RFC4191. This array is also used for
53 command matching, so only modify with care. */
54 const char *rtadv_pref_strs[] = { "medium", "high", "INVALID", "low", 0 };
55 #endif /* HAVE_RTADV */
56
57 static void if_down_del_nbr_connected (struct interface *ifp);
58
59 struct zebra_ns *dzns;
60
61 /* Called when new interface is added. */
62 static int
63 if_zebra_new_hook (struct interface *ifp)
64 {
65 struct zebra_if *zebra_if;
66
67 zebra_if = XCALLOC (MTYPE_TMP, sizeof (struct zebra_if));
68
69 zebra_if->multicast = IF_ZEBRA_MULTICAST_UNSPEC;
70 zebra_if->shutdown = IF_ZEBRA_SHUTDOWN_OFF;
71
72 ifp->ptm_enable = zebra_ptm_get_enable_state();
73 #if defined (HAVE_RTADV)
74 {
75 /* Set default router advertise values. */
76 struct rtadvconf *rtadv;
77
78 rtadv = &zebra_if->rtadv;
79
80 rtadv->AdvSendAdvertisements = 0;
81 rtadv->MaxRtrAdvInterval = RTADV_MAX_RTR_ADV_INTERVAL;
82 rtadv->MinRtrAdvInterval = RTADV_MIN_RTR_ADV_INTERVAL;
83 rtadv->AdvIntervalTimer = 0;
84 rtadv->AdvManagedFlag = 0;
85 rtadv->AdvOtherConfigFlag = 0;
86 rtadv->AdvHomeAgentFlag = 0;
87 rtadv->AdvLinkMTU = 0;
88 rtadv->AdvReachableTime = 0;
89 rtadv->AdvRetransTimer = 0;
90 rtadv->AdvCurHopLimit = 0;
91 rtadv->AdvDefaultLifetime = -1; /* derive from MaxRtrAdvInterval */
92 rtadv->HomeAgentPreference = 0;
93 rtadv->HomeAgentLifetime = -1; /* derive from AdvDefaultLifetime */
94 rtadv->AdvIntervalOption = 0;
95 rtadv->DefaultPreference = RTADV_PREF_MEDIUM;
96
97 rtadv->AdvPrefixList = list_new ();
98 }
99 #endif /* HAVE_RTADV */
100
101 /* Initialize installed address chains tree. */
102 zebra_if->ipv4_subnets = route_table_init ();
103
104 ifp->info = zebra_if;
105 return 0;
106 }
107
108 /* Called when interface is deleted. */
109 static int
110 if_zebra_delete_hook (struct interface *ifp)
111 {
112 struct zebra_if *zebra_if;
113
114 if (ifp->info)
115 {
116 zebra_if = ifp->info;
117
118 /* Free installed address chains tree. */
119 if (zebra_if->ipv4_subnets)
120 route_table_finish (zebra_if->ipv4_subnets);
121
122 XFREE (MTYPE_TMP, zebra_if);
123 }
124
125 return 0;
126 }
127
128 /* Build the table key */
129 static void
130 if_build_key (u_int32_t ifindex, struct prefix *p)
131 {
132 p->family = AF_INET;
133 p->prefixlen = IPV4_MAX_BITLEN;
134 p->u.prefix4.s_addr = ifindex;
135 }
136
137 /* Link an interface in a per NS interface tree */
138 struct interface *
139 if_link_per_ns (struct zebra_ns *ns, struct interface *ifp)
140 {
141 struct prefix p;
142 struct route_node *rn;
143
144 if (ifp->ifindex == IFINDEX_INTERNAL)
145 return NULL;
146
147 if_build_key (ifp->ifindex, &p);
148 rn = route_node_get (ns->if_table, &p);
149 if (rn->info)
150 {
151 ifp = (struct interface *)rn->info;
152 route_unlock_node (rn); /* get */
153 return ifp;
154 }
155
156 rn->info = ifp;
157 ifp->node = rn;
158
159 return ifp;
160 }
161
162 /* Delete a VRF. This is called in vrf_terminate(). */
163 void
164 if_unlink_per_ns (struct interface *ifp)
165 {
166 ifp->node->info = NULL;
167 route_unlock_node(ifp->node);
168 }
169
170 /* Look up an interface by identifier within a NS */
171 struct interface *
172 if_lookup_by_index_per_ns (struct zebra_ns *ns, u_int32_t ifindex)
173 {
174 struct prefix p;
175 struct route_node *rn;
176 struct interface *ifp = NULL;
177
178 if_build_key (ifindex, &p);
179 rn = route_node_lookup (ns->if_table, &p);
180 if (rn)
181 {
182 ifp = (struct interface *)rn->info;
183 route_unlock_node (rn); /* lookup */
184 }
185 return ifp;
186 }
187
188 const char *
189 ifindex2ifname_per_ns (struct zebra_ns *zns, unsigned int ifindex)
190 {
191 struct interface *ifp;
192
193 return ((ifp = if_lookup_by_index_per_ns (zns, ifindex)) != NULL) ?
194 ifp->name : "unknown";
195 }
196
197 /* Tie an interface address to its derived subnet list of addresses. */
198 int
199 if_subnet_add (struct interface *ifp, struct connected *ifc)
200 {
201 struct route_node *rn;
202 struct zebra_if *zebra_if;
203 struct prefix cp;
204 struct list *addr_list;
205
206 assert (ifp && ifp->info && ifc);
207 zebra_if = ifp->info;
208
209 /* Get address derived subnet node and associated address list, while marking
210 address secondary attribute appropriately. */
211 cp = *ifc->address;
212 apply_mask (&cp);
213 rn = route_node_get (zebra_if->ipv4_subnets, &cp);
214
215 if ((addr_list = rn->info))
216 SET_FLAG (ifc->flags, ZEBRA_IFA_SECONDARY);
217 else
218 {
219 UNSET_FLAG (ifc->flags, ZEBRA_IFA_SECONDARY);
220 rn->info = addr_list = list_new ();
221 route_lock_node (rn);
222 }
223
224 /* Tie address at the tail of address list. */
225 listnode_add (addr_list, ifc);
226
227 /* Return list element count. */
228 return (addr_list->count);
229 }
230
231 /* Untie an interface address from its derived subnet list of addresses. */
232 int
233 if_subnet_delete (struct interface *ifp, struct connected *ifc)
234 {
235 struct route_node *rn;
236 struct zebra_if *zebra_if;
237 struct list *addr_list;
238
239 assert (ifp && ifp->info && ifc);
240 zebra_if = ifp->info;
241
242 /* Get address derived subnet node. */
243 rn = route_node_lookup (zebra_if->ipv4_subnets, ifc->address);
244 if (! (rn && rn->info))
245 {
246 zlog_warn("Trying to remove an address from an unknown subnet."
247 " (please report this bug)");
248 return -1;
249 }
250 route_unlock_node (rn);
251
252 /* Untie address from subnet's address list. */
253 addr_list = rn->info;
254
255 /* Deleting an address that is not registered is a bug.
256 * In any case, we shouldn't decrement the lock counter if the address
257 * is unknown. */
258 if (!listnode_lookup(addr_list, ifc))
259 {
260 zlog_warn("Trying to remove an address from a subnet where it is not"
261 " currently registered. (please report this bug)");
262 return -1;
263 }
264
265 listnode_delete (addr_list, ifc);
266 route_unlock_node (rn);
267
268 /* Return list element count, if not empty. */
269 if (addr_list->count)
270 {
271 /* If deleted address is primary, mark subsequent one as such and distribute. */
272 if (! CHECK_FLAG (ifc->flags, ZEBRA_IFA_SECONDARY))
273 {
274 ifc = listgetdata (listhead (addr_list));
275 zebra_interface_address_delete_update (ifp, ifc);
276 UNSET_FLAG (ifc->flags, ZEBRA_IFA_SECONDARY);
277 /* XXX: Linux kernel removes all the secondary addresses when the primary
278 * address is removed. We could try to work around that, though this is
279 * non-trivial. */
280 zebra_interface_address_add_update (ifp, ifc);
281 }
282
283 return addr_list->count;
284 }
285
286 /* Otherwise, free list and route node. */
287 list_free (addr_list);
288 rn->info = NULL;
289 route_unlock_node (rn);
290
291 return 0;
292 }
293
294 /* if_flags_mangle: A place for hacks that require mangling
295 * or tweaking the interface flags.
296 *
297 * ******************** Solaris flags hacks **************************
298 *
299 * Solaris IFF_UP flag reflects only the primary interface as the
300 * routing socket only sends IFINFO for the primary interface. Hence
301 * ~IFF_UP does not per se imply all the logical interfaces are also
302 * down - which we only know of as addresses. Instead we must determine
303 * whether the interface really is up or not according to how many
304 * addresses are still attached. (Solaris always sends RTM_DELADDR if
305 * an interface, logical or not, goes ~IFF_UP).
306 *
307 * Ie, we mangle IFF_UP to *additionally* reflect whether or not there
308 * are addresses left in struct connected, not just the actual underlying
309 * IFF_UP flag.
310 *
311 * We must hence remember the real state of IFF_UP, which we do in
312 * struct zebra_if.primary_state.
313 *
314 * Setting IFF_UP within zebra to administratively shutdown the
315 * interface will affect only the primary interface/address on Solaris.
316 ************************End Solaris flags hacks ***********************
317 */
318 static void
319 if_flags_mangle (struct interface *ifp, uint64_t *newflags)
320 {
321 #ifdef SUNOS_5
322 struct zebra_if *zif = ifp->info;
323
324 zif->primary_state = *newflags & (IFF_UP & 0xff);
325
326 if (CHECK_FLAG (zif->primary_state, IFF_UP)
327 || listcount(ifp->connected) > 0)
328 SET_FLAG (*newflags, IFF_UP);
329 else
330 UNSET_FLAG (*newflags, IFF_UP);
331 #endif /* SUNOS_5 */
332 }
333
334 /* Update the flags field of the ifp with the new flag set provided.
335 * Take whatever actions are required for any changes in flags we care
336 * about.
337 *
338 * newflags should be the raw value, as obtained from the OS.
339 */
340 void
341 if_flags_update (struct interface *ifp, uint64_t newflags)
342 {
343 if_flags_mangle (ifp, &newflags);
344
345 if (if_is_no_ptm_operative (ifp))
346 {
347 /* operative -> inoperative? */
348 ifp->flags = newflags;
349 if (!if_is_operative (ifp))
350 if_down (ifp);
351 }
352 else
353 {
354 /* inoperative -> operative? */
355 ifp->flags = newflags;
356 if (if_is_operative (ifp))
357 if_up (ifp);
358 }
359 }
360
361 /* Wake up configured address if it is not in current kernel
362 address. */
363 static void
364 if_addr_wakeup (struct interface *ifp)
365 {
366 struct listnode *node, *nnode;
367 struct connected *ifc;
368 struct prefix *p;
369 int ret;
370
371 for (ALL_LIST_ELEMENTS (ifp->connected, node, nnode, ifc))
372 {
373 p = ifc->address;
374
375 if (CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED)
376 && ! CHECK_FLAG (ifc->conf, ZEBRA_IFC_QUEUED))
377 {
378 /* Address check. */
379 if (p->family == AF_INET)
380 {
381 if (! if_is_up (ifp))
382 {
383 /* Assume zebra is configured like following:
384 *
385 * interface gre0
386 * ip addr 192.0.2.1/24
387 * !
388 *
389 * As soon as zebra becomes first aware that gre0 exists in the
390 * kernel, it will set gre0 up and configure its addresses.
391 *
392 * (This may happen at startup when the interface already exists
393 * or during runtime when the interface is added to the kernel)
394 *
395 * XXX: IRDP code is calling here via if_add_update - this seems
396 * somewhat weird.
397 * XXX: RUNNING is not a settable flag on any system
398 * I (paulj) am aware of.
399 */
400 if_set_flags (ifp, IFF_UP | IFF_RUNNING);
401 if_refresh (ifp);
402 }
403
404 ret = if_set_prefix (ifp, ifc);
405 if (ret < 0)
406 {
407 zlog_warn ("Can't set interface's address: %s",
408 safe_strerror(errno));
409 continue;
410 }
411
412 SET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED);
413 /* The address will be advertised to zebra clients when the notification
414 * from the kernel has been received.
415 * It will also be added to the interface's subnet list then. */
416 }
417 #ifdef HAVE_IPV6
418 if (p->family == AF_INET6)
419 {
420 if (! if_is_up (ifp))
421 {
422 /* See long comment above */
423 if_set_flags (ifp, IFF_UP | IFF_RUNNING);
424 if_refresh (ifp);
425 }
426
427 ret = if_prefix_add_ipv6 (ifp, ifc);
428 if (ret < 0)
429 {
430 zlog_warn ("Can't set interface's address: %s",
431 safe_strerror(errno));
432 continue;
433 }
434
435 SET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED);
436 /* The address will be advertised to zebra clients when the notification
437 * from the kernel has been received. */
438 }
439 #endif /* HAVE_IPV6 */
440 }
441 }
442 }
443
444 /* Handle interface addition */
445 void
446 if_add_update (struct interface *ifp)
447 {
448 struct zebra_if *if_data;
449
450 if_link_per_ns(dzns, ifp);
451
452 if_data = ifp->info;
453 if (if_data->multicast == IF_ZEBRA_MULTICAST_ON)
454 if_set_flags (ifp, IFF_MULTICAST);
455 else if (if_data->multicast == IF_ZEBRA_MULTICAST_OFF)
456 if_unset_flags (ifp, IFF_MULTICAST);
457
458 zebra_interface_add_update (ifp);
459
460 if (! CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE))
461 {
462 SET_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE);
463
464 if (if_data && if_data->shutdown == IF_ZEBRA_SHUTDOWN_ON)
465 {
466 if (IS_ZEBRA_DEBUG_KERNEL)
467 zlog_debug ("interface %s vrf %u index %d is shutdown. "
468 "Won't wake it up.",
469 ifp->name, ifp->vrf_id, ifp->ifindex);
470 return;
471 }
472
473 if_addr_wakeup (ifp);
474
475 if (IS_ZEBRA_DEBUG_KERNEL)
476 zlog_debug ("interface %s vrf %u index %d becomes active.",
477 ifp->name, ifp->vrf_id, ifp->ifindex);
478 }
479 else
480 {
481 if (IS_ZEBRA_DEBUG_KERNEL)
482 zlog_debug ("interface %s vrf %u index %d is added.",
483 ifp->name, ifp->vrf_id, ifp->ifindex);
484 }
485 }
486
487 /* Install connected routes corresponding to an interface. */
488 static void
489 if_install_connected (struct interface *ifp)
490 {
491 struct listnode *node;
492 struct listnode *next;
493 struct connected *ifc;
494 struct prefix *p;
495
496 if (ifp->connected)
497 {
498 for (ALL_LIST_ELEMENTS (ifp->connected, node, next, ifc))
499 {
500 p = ifc->address;
501
502 if (p->family == AF_INET)
503 connected_up_ipv4 (ifp, ifc);
504 else if (p->family == AF_INET6)
505 connected_up_ipv6 (ifp, ifc);
506 }
507 }
508 }
509
510 /* Uninstall connected routes corresponding to an interface. */
511 static void
512 if_uninstall_connected (struct interface *ifp)
513 {
514 struct listnode *node;
515 struct listnode *next;
516 struct connected *ifc;
517 struct prefix *p;
518
519 if (ifp->connected)
520 {
521 for (ALL_LIST_ELEMENTS (ifp->connected, node, next, ifc))
522 {
523 p = ifc->address;
524
525 if (p->family == AF_INET)
526 connected_down_ipv4 (ifp, ifc);
527 else if (p->family == AF_INET6)
528 connected_down_ipv6 (ifp, ifc);
529 }
530 }
531 }
532
533 /* Uninstall and delete connected routes corresponding to an interface. */
534 /* TODO - Check why IPv4 handling here is different from install or if_down */
535 static void
536 if_delete_connected (struct interface *ifp)
537 {
538 struct connected *ifc;
539 struct prefix *p;
540 struct route_node *rn;
541 struct zebra_if *zebra_if;
542
543 zebra_if = ifp->info;
544
545 if (ifp->connected)
546 {
547 struct listnode *node;
548 struct listnode *last = NULL;
549
550 while ((node = (last ? last->next : listhead (ifp->connected))))
551 {
552 ifc = listgetdata (node);
553 p = ifc->address;
554
555 if (p->family == AF_INET
556 && (rn = route_node_lookup (zebra_if->ipv4_subnets, p)))
557 {
558 struct listnode *anode;
559 struct listnode *next;
560 struct listnode *first;
561 struct list *addr_list;
562
563 route_unlock_node (rn);
564 addr_list = (struct list *) rn->info;
565
566 /* Remove addresses, secondaries first. */
567 first = listhead (addr_list);
568 for (anode = first->next; anode || first; anode = next)
569 {
570 if (!anode)
571 {
572 anode = first;
573 first = NULL;
574 }
575 next = anode->next;
576
577 ifc = listgetdata (anode);
578 p = ifc->address;
579 connected_down_ipv4 (ifp, ifc);
580
581 /* XXX: We have to send notifications here explicitly, because we destroy
582 * the ifc before receiving the notification about the address being deleted.
583 */
584 zebra_interface_address_delete_update (ifp, ifc);
585
586 UNSET_FLAG (ifc->conf, ZEBRA_IFC_REAL);
587 UNSET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED);
588
589 /* Remove from subnet chain. */
590 list_delete_node (addr_list, anode);
591 route_unlock_node (rn);
592
593 /* Remove from interface address list (unconditionally). */
594 if (!CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED))
595 {
596 listnode_delete (ifp->connected, ifc);
597 connected_free (ifc);
598 }
599 else
600 last = node;
601 }
602
603 /* Free chain list and respective route node. */
604 list_delete (addr_list);
605 rn->info = NULL;
606 route_unlock_node (rn);
607 }
608 else if (p->family == AF_INET6)
609 {
610 connected_down_ipv6 (ifp, ifc);
611
612 zebra_interface_address_delete_update (ifp, ifc);
613
614 UNSET_FLAG (ifc->conf, ZEBRA_IFC_REAL);
615 UNSET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED);
616
617 if (CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED))
618 last = node;
619 else
620 {
621 listnode_delete (ifp->connected, ifc);
622 connected_free (ifc);
623 }
624 }
625 else
626 {
627 last = node;
628 }
629 }
630 }
631 }
632
633 /* Handle an interface delete event */
634 void
635 if_delete_update (struct interface *ifp)
636 {
637 if (if_is_up(ifp))
638 {
639 zlog_err ("interface %s vrf %u index %d is still up while being deleted.",
640 ifp->name, ifp->vrf_id, ifp->ifindex);
641 return;
642 }
643
644 /* Mark interface as inactive */
645 UNSET_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE);
646
647 if (IS_ZEBRA_DEBUG_KERNEL)
648 zlog_debug ("interface %s vrf %u index %d is now inactive.",
649 ifp->name, ifp->vrf_id, ifp->ifindex);
650
651 /* Delete connected routes from the kernel. */
652 if_delete_connected (ifp);
653
654 /* Send out notification on interface delete. */
655 zebra_interface_delete_update (ifp);
656
657 if_unlink_per_ns(ifp);
658
659 /* Update ifindex after distributing the delete message. This is in
660 case any client needs to have the old value of ifindex available
661 while processing the deletion. Each client daemon is responsible
662 for setting ifindex to IFINDEX_INTERNAL after processing the
663 interface deletion message. */
664 ifp->ifindex = IFINDEX_INTERNAL;
665 }
666
667 /* VRF change for an interface */
668 void
669 if_handle_vrf_change (struct interface *ifp, vrf_id_t vrf_id)
670 {
671 vrf_id_t old_vrf_id;
672
673 old_vrf_id = ifp->vrf_id;
674
675 /* Uninstall connected routes. */
676 if_uninstall_connected (ifp);
677
678 /* Delete any IPv4 neighbors created to implement RFC 5549 */
679 if_nbr_ipv6ll_to_ipv4ll_neigh_del_all (ifp);
680
681 /* Delete all neighbor addresses learnt through IPv6 RA */
682 if_down_del_nbr_connected (ifp);
683
684 /* Suppress RAs on this interface, if enabled. */
685 ipv6_nd_suppress_ra_set (ifp, RA_SUPPRESS);
686
687 /* Send out notification on interface VRF change. */
688 /* This is to issue an UPDATE or a DELETE, as appropriate. */
689 zebra_interface_vrf_update_del (ifp, vrf_id);
690
691 /* update VRF */
692 if_update_vrf (ifp, ifp->name, strlen (ifp->name), vrf_id);
693
694 /* Send out notification on interface VRF change. */
695 /* This is to issue an ADD, if needed. */
696 zebra_interface_vrf_update_add (ifp, old_vrf_id);
697
698 /* Install connected routes (in new VRF). */
699 if_install_connected (ifp);
700
701 /* Enable RAs on this interface, if IPv6 addresses are present. */
702 if (ipv6_address_configured(ifp))
703 ipv6_nd_suppress_ra_set (ifp, RA_ENABLE);
704
705 /* Due to connected route change, schedule RIB processing for both old
706 * and new VRF.
707 */
708 if (IS_ZEBRA_DEBUG_RIB_DETAILED)
709 zlog_debug ("%u: IF %s VRF change, scheduling RIB processing",
710 ifp->vrf_id, ifp->name);
711 rib_update (old_vrf_id, RIB_UPDATE_IF_CHANGE);
712 rib_update (ifp->vrf_id, RIB_UPDATE_IF_CHANGE);
713 }
714
715
716 /* Handle VRF addition */
717 void
718 vrf_add_update (struct vrf *vrfp)
719 {
720 zebra_vrf_add_update (vrfp);
721
722 if (! CHECK_FLAG (vrfp->status, ZEBRA_VRF_ACTIVE))
723 {
724 SET_FLAG (vrfp->status, ZEBRA_VRF_ACTIVE);
725
726 //Pending: Check if the equivalent of if_addr_wakeup (ifp) is needed here.
727
728 if (IS_ZEBRA_DEBUG_KERNEL)
729 zlog_debug ("VRF %s id %u becomes active.",
730 vrfp->name, vrfp->vrf_id);
731 }
732 else
733 {
734 if (IS_ZEBRA_DEBUG_KERNEL)
735 zlog_debug ("VRF %s id %u is added.",
736 vrfp->name, vrfp->vrf_id);
737 }
738 }
739
740 /* Handle an interface delete event */
741 void
742 vrf_delete_update (struct vrf *vrfp)
743 {
744 /* Mark VRF as inactive */
745 UNSET_FLAG (vrfp->status, ZEBRA_VRF_ACTIVE);
746
747 if (IS_ZEBRA_DEBUG_KERNEL)
748 zlog_debug ("VRF %s id %u is now inactive.",
749 vrfp->name, vrfp->vrf_id);
750
751 zebra_vrf_delete_update (vrfp);
752
753 /* Pending: Update ifindex after distributing the delete message. This is in
754 case any client needs to have the old value of ifindex available
755 while processing the deletion. Each client daemon is responsible
756 for setting vrf-id to IFINDEX_INTERNAL after processing the
757 interface deletion message. */
758 vrfp->vrf_id = 0;
759 }
760
761
762 static void
763 ipv6_ll_address_to_mac (struct in6_addr *address, u_char *mac)
764 {
765 mac[0] = address->s6_addr[8] ^ 0x02;
766 mac[1] = address->s6_addr[9];
767 mac[2] = address->s6_addr[10];
768 mac[3] = address->s6_addr[13];
769 mac[4] = address->s6_addr[14];
770 mac[5] = address->s6_addr[15];
771 }
772
773 void
774 if_nbr_ipv6ll_to_ipv4ll_neigh_update (struct interface *ifp,
775 struct in6_addr *address,
776 int add)
777 {
778 char buf[16] = "169.254.0.1";
779 struct in_addr ipv4_ll;
780 char mac[6];
781
782 inet_pton (AF_INET, buf, &ipv4_ll);
783
784 ipv6_ll_address_to_mac(address, (u_char *)mac);
785 netlink_neigh_update (add ? RTM_NEWNEIGH : RTM_DELNEIGH,
786 ifp->ifindex, ipv4_ll.s_addr, mac, 6);
787 }
788
789 static void
790 if_nbr_ipv6ll_to_ipv4ll_neigh_add_all (struct interface *ifp)
791 {
792 if (listhead(ifp->nbr_connected))
793 {
794 struct nbr_connected *nbr_connected;
795 struct listnode *node;
796
797 for (ALL_LIST_ELEMENTS_RO (ifp->nbr_connected, node, nbr_connected))
798 if_nbr_ipv6ll_to_ipv4ll_neigh_update (ifp,
799 &nbr_connected->address->u.prefix6,
800 1);
801 }
802 }
803
804 void
805 if_nbr_ipv6ll_to_ipv4ll_neigh_del_all (struct interface *ifp)
806 {
807 if (listhead(ifp->nbr_connected))
808 {
809 struct nbr_connected *nbr_connected;
810 struct listnode *node;
811
812 for (ALL_LIST_ELEMENTS_RO (ifp->nbr_connected, node, nbr_connected))
813 if_nbr_ipv6ll_to_ipv4ll_neigh_update (ifp,
814 &nbr_connected->address->u.prefix6,
815 0);
816 }
817 }
818
819 static void
820 if_down_del_nbr_connected (struct interface *ifp)
821 {
822 struct nbr_connected *nbr_connected;
823 struct listnode *node, *nnode;
824
825 for (ALL_LIST_ELEMENTS (ifp->nbr_connected, node, nnode, nbr_connected))
826 {
827 listnode_delete (ifp->nbr_connected, nbr_connected);
828 nbr_connected_free (nbr_connected);
829 }
830 }
831
832 /* Interface is up. */
833 void
834 if_up (struct interface *ifp)
835 {
836 /* Notify the protocol daemons. */
837 if (ifp->ptm_enable && (ifp->ptm_status == ZEBRA_PTM_STATUS_DOWN)) {
838 zlog_warn("%s: interface %s hasn't passed ptm check\n", __func__,
839 ifp->name);
840 return;
841 }
842 zebra_interface_up_update (ifp);
843
844 if_nbr_ipv6ll_to_ipv4ll_neigh_add_all (ifp);
845
846 /* Install connected routes to the kernel. */
847 if_install_connected (ifp);
848
849 if (IS_ZEBRA_DEBUG_RIB_DETAILED)
850 zlog_debug ("%u: IF %s up, scheduling RIB processing",
851 ifp->vrf_id, ifp->name);
852 rib_update (ifp->vrf_id, RIB_UPDATE_IF_CHANGE);
853 }
854
855 /* Interface goes down. We have to manage different behavior of based
856 OS. */
857 void
858 if_down (struct interface *ifp)
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 interval = rtadv->MaxRtrAdvInterval;
960 if (interval % 1000)
961 vty_out (vty, " ND router advertisements are sent every "
962 "%d milliseconds%s", interval,
963 VTY_NEWLINE);
964 else
965 vty_out (vty, " ND router advertisements are sent every "
966 "%d seconds%s", interval / 1000,
967 VTY_NEWLINE);
968 if (rtadv->AdvDefaultLifetime != -1)
969 vty_out (vty, " ND router advertisements live for %d seconds%s",
970 rtadv->AdvDefaultLifetime, VTY_NEWLINE);
971 else
972 vty_out (vty, " ND router advertisements lifetime tracks ra-interval%s",
973 VTY_NEWLINE);
974 vty_out (vty, " ND router advertisement default router preference is "
975 "%s%s", rtadv_pref_strs[rtadv->DefaultPreference],
976 VTY_NEWLINE);
977 if (rtadv->AdvManagedFlag)
978 vty_out (vty, " Hosts use DHCP to obtain routable addresses.%s",
979 VTY_NEWLINE);
980 else
981 vty_out (vty, " Hosts use stateless autoconfig for addresses.%s",
982 VTY_NEWLINE);
983 if (rtadv->AdvHomeAgentFlag)
984 {
985 vty_out (vty, " ND router advertisements with "
986 "Home Agent flag bit set.%s",
987 VTY_NEWLINE);
988 if (rtadv->HomeAgentLifetime != -1)
989 vty_out (vty, " Home Agent lifetime is %u seconds%s",
990 rtadv->HomeAgentLifetime, VTY_NEWLINE);
991 else
992 vty_out (vty, " Home Agent lifetime tracks ra-lifetime%s",
993 VTY_NEWLINE);
994 vty_out (vty, " Home Agent preference is %u%s",
995 rtadv->HomeAgentPreference, VTY_NEWLINE);
996 }
997 if (rtadv->AdvIntervalOption)
998 vty_out (vty, " ND router advertisements with Adv. Interval option.%s",
999 VTY_NEWLINE);
1000 }
1001 }
1002 #endif /* HAVE_RTADV */
1003
1004 /* Interface's information print out to vty interface. */
1005 static void
1006 if_dump_vty (struct vty *vty, struct interface *ifp)
1007 {
1008 #ifdef HAVE_STRUCT_SOCKADDR_DL
1009 struct sockaddr_dl *sdl;
1010 #endif /* HAVE_STRUCT_SOCKADDR_DL */
1011 struct connected *connected;
1012 struct nbr_connected *nbr_connected;
1013 struct listnode *node;
1014 struct route_node *rn;
1015 struct zebra_if *zebra_if;
1016 struct vrf *vrf;
1017
1018 zebra_if = ifp->info;
1019
1020 vty_out (vty, "Interface %s is ", ifp->name);
1021 if (if_is_up(ifp)) {
1022 vty_out (vty, "up, line protocol ");
1023
1024 if (CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION)) {
1025 if (if_is_running(ifp))
1026 vty_out (vty, "is up%s", VTY_NEWLINE);
1027 else
1028 vty_out (vty, "is down%s", VTY_NEWLINE);
1029 } else {
1030 vty_out (vty, "detection is disabled%s", VTY_NEWLINE);
1031 }
1032 } else {
1033 vty_out (vty, "down%s", VTY_NEWLINE);
1034 }
1035
1036 zebra_ptm_show_status(vty, ifp);
1037
1038 vrf = vrf_lookup(ifp->vrf_id);
1039 vty_out (vty, " vrf: %s%s", vrf->name, VTY_NEWLINE);
1040
1041 if (ifp->desc)
1042 vty_out (vty, " Description: %s%s", ifp->desc,
1043 VTY_NEWLINE);
1044 if (ifp->ifindex == IFINDEX_INTERNAL)
1045 {
1046 vty_out(vty, " pseudo interface%s", VTY_NEWLINE);
1047 return;
1048 }
1049 else if (! CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE))
1050 {
1051 vty_out(vty, " index %d inactive interface%s",
1052 ifp->ifindex,
1053 VTY_NEWLINE);
1054 return;
1055 }
1056
1057 vty_out (vty, " index %d metric %d mtu %d ",
1058 ifp->ifindex, ifp->metric, ifp->mtu);
1059 #ifdef HAVE_IPV6
1060 if (ifp->mtu6 != ifp->mtu)
1061 vty_out (vty, "mtu6 %d ", ifp->mtu6);
1062 #endif
1063 vty_out (vty, "%s flags: %s%s", VTY_NEWLINE,
1064 if_flag_dump (ifp->flags), VTY_NEWLINE);
1065
1066 /* Hardware address. */
1067 #ifdef HAVE_STRUCT_SOCKADDR_DL
1068 sdl = &ifp->sdl;
1069 if (sdl != NULL && sdl->sdl_alen != 0)
1070 {
1071 int i;
1072 u_char *ptr;
1073
1074 vty_out (vty, " HWaddr: ");
1075 for (i = 0, ptr = (u_char *)LLADDR (sdl); i < sdl->sdl_alen; i++, ptr++)
1076 vty_out (vty, "%s%02x", i == 0 ? "" : ":", *ptr);
1077 vty_out (vty, "%s", VTY_NEWLINE);
1078 }
1079 #else
1080 if (ifp->hw_addr_len != 0)
1081 {
1082 int i;
1083
1084 vty_out (vty, " HWaddr: ");
1085 for (i = 0; i < ifp->hw_addr_len; i++)
1086 vty_out (vty, "%s%02x", i == 0 ? "" : ":", ifp->hw_addr[i]);
1087 vty_out (vty, "%s", VTY_NEWLINE);
1088 }
1089 #endif /* HAVE_STRUCT_SOCKADDR_DL */
1090
1091 /* Bandwidth in kbps */
1092 if (ifp->bandwidth != 0)
1093 {
1094 vty_out(vty, " bandwidth %u kbps", ifp->bandwidth);
1095 vty_out(vty, "%s", VTY_NEWLINE);
1096 }
1097
1098 for (rn = route_top (zebra_if->ipv4_subnets); rn; rn = route_next (rn))
1099 {
1100 if (! rn->info)
1101 continue;
1102
1103 for (ALL_LIST_ELEMENTS_RO ((struct list *)rn->info, node, connected))
1104 connected_dump_vty (vty, connected);
1105 }
1106
1107 for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, connected))
1108 {
1109 if (CHECK_FLAG (connected->conf, ZEBRA_IFC_REAL) &&
1110 (connected->address->family == AF_INET6))
1111 connected_dump_vty (vty, connected);
1112 }
1113
1114 #if defined (HAVE_RTADV)
1115 nd_dump_vty (vty, ifp);
1116 #endif /* HAVE_RTADV */
1117 if (listhead(ifp->nbr_connected))
1118 vty_out (vty, " Neighbor address(s):%s", VTY_NEWLINE);
1119 for (ALL_LIST_ELEMENTS_RO (ifp->nbr_connected, node, nbr_connected))
1120 nbr_connected_dump_vty (vty, nbr_connected);
1121
1122 #ifdef HAVE_PROC_NET_DEV
1123 /* Statistics print out using proc file system. */
1124 vty_out (vty, " %lu input packets (%lu multicast), %lu bytes, "
1125 "%lu dropped%s",
1126 ifp->stats.rx_packets, ifp->stats.rx_multicast,
1127 ifp->stats.rx_bytes, ifp->stats.rx_dropped, VTY_NEWLINE);
1128
1129 vty_out (vty, " %lu input errors, %lu length, %lu overrun,"
1130 " %lu CRC, %lu frame%s",
1131 ifp->stats.rx_errors, ifp->stats.rx_length_errors,
1132 ifp->stats.rx_over_errors, ifp->stats.rx_crc_errors,
1133 ifp->stats.rx_frame_errors, VTY_NEWLINE);
1134
1135 vty_out (vty, " %lu fifo, %lu missed%s", ifp->stats.rx_fifo_errors,
1136 ifp->stats.rx_missed_errors, VTY_NEWLINE);
1137
1138 vty_out (vty, " %lu output packets, %lu bytes, %lu dropped%s",
1139 ifp->stats.tx_packets, ifp->stats.tx_bytes,
1140 ifp->stats.tx_dropped, VTY_NEWLINE);
1141
1142 vty_out (vty, " %lu output errors, %lu aborted, %lu carrier,"
1143 " %lu fifo, %lu heartbeat%s",
1144 ifp->stats.tx_errors, ifp->stats.tx_aborted_errors,
1145 ifp->stats.tx_carrier_errors, ifp->stats.tx_fifo_errors,
1146 ifp->stats.tx_heartbeat_errors, VTY_NEWLINE);
1147
1148 vty_out (vty, " %lu window, %lu collisions%s",
1149 ifp->stats.tx_window_errors, ifp->stats.collisions, VTY_NEWLINE);
1150 #endif /* HAVE_PROC_NET_DEV */
1151
1152 #ifdef HAVE_NET_RT_IFLIST
1153 #if defined (__bsdi__) || defined (__NetBSD__)
1154 /* Statistics print out using sysctl (). */
1155 vty_out (vty, " input packets %qu, bytes %qu, dropped %qu,"
1156 " multicast packets %qu%s",
1157 ifp->stats.ifi_ipackets, ifp->stats.ifi_ibytes,
1158 ifp->stats.ifi_iqdrops, ifp->stats.ifi_imcasts,
1159 VTY_NEWLINE);
1160
1161 vty_out (vty, " input errors %qu%s",
1162 ifp->stats.ifi_ierrors, VTY_NEWLINE);
1163
1164 vty_out (vty, " output packets %qu, bytes %qu, multicast packets %qu%s",
1165 ifp->stats.ifi_opackets, ifp->stats.ifi_obytes,
1166 ifp->stats.ifi_omcasts, VTY_NEWLINE);
1167
1168 vty_out (vty, " output errors %qu%s",
1169 ifp->stats.ifi_oerrors, VTY_NEWLINE);
1170
1171 vty_out (vty, " collisions %qu%s",
1172 ifp->stats.ifi_collisions, VTY_NEWLINE);
1173 #else
1174 /* Statistics print out using sysctl (). */
1175 vty_out (vty, " input packets %lu, bytes %lu, dropped %lu,"
1176 " multicast packets %lu%s",
1177 ifp->stats.ifi_ipackets, ifp->stats.ifi_ibytes,
1178 ifp->stats.ifi_iqdrops, ifp->stats.ifi_imcasts,
1179 VTY_NEWLINE);
1180
1181 vty_out (vty, " input errors %lu%s",
1182 ifp->stats.ifi_ierrors, VTY_NEWLINE);
1183
1184 vty_out (vty, " output packets %lu, bytes %lu, multicast packets %lu%s",
1185 ifp->stats.ifi_opackets, ifp->stats.ifi_obytes,
1186 ifp->stats.ifi_omcasts, VTY_NEWLINE);
1187
1188 vty_out (vty, " output errors %lu%s",
1189 ifp->stats.ifi_oerrors, VTY_NEWLINE);
1190
1191 vty_out (vty, " collisions %lu%s",
1192 ifp->stats.ifi_collisions, VTY_NEWLINE);
1193 #endif /* __bsdi__ || __NetBSD__ */
1194 #endif /* HAVE_NET_RT_IFLIST */
1195 }
1196
1197 /* Wrapper hook point for zebra daemon so that ifindex can be set
1198 * DEFUN macro not used as extract.pl HAS to ignore this
1199 * See also interface_cmd in lib/if.c
1200 */
1201 DEFUN_NOSH (zebra_interface,
1202 zebra_interface_cmd,
1203 "interface IFNAME",
1204 "Select an interface to configure\n"
1205 "Interface's name\n")
1206 {
1207 int ret;
1208 struct interface * ifp;
1209
1210 /* Call lib interface() */
1211 if ((ret = interface_cmd.func (self, vty, argc, argv)) != CMD_SUCCESS)
1212 return ret;
1213
1214 ifp = vty->index;
1215
1216 if (ifp->ifindex == IFINDEX_INTERNAL)
1217 /* Is this really necessary? Shouldn't status be initialized to 0
1218 in that case? */
1219 UNSET_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE);
1220
1221 return ret;
1222 }
1223
1224 ALIAS (zebra_interface,
1225 zebra_interface_vrf_cmd,
1226 "interface IFNAME " VRF_CMD_STR,
1227 "Select an interface to configure\n"
1228 "Interface's name\n"
1229 VRF_CMD_HELP_STR)
1230
1231 struct cmd_node interface_node =
1232 {
1233 INTERFACE_NODE,
1234 "%s(config-if)# ",
1235 1
1236 };
1237
1238 /* Wrapper hook point for zebra daemon so that ifindex can be set
1239 * DEFUN macro not used as extract.pl HAS to ignore this
1240 * See also interface_cmd in lib/if.c
1241 */
1242 DEFUN_NOSH (zebra_vrf,
1243 zebra_vrf_cmd,
1244 "vrf NAME",
1245 "Select a VRF to configure\n"
1246 "VRF's name\n")
1247 {
1248 int ret;
1249
1250 /* Call lib vrf() */
1251 if ((ret = vrf_cmd.func (self, vty, argc, argv)) != CMD_SUCCESS)
1252 return ret;
1253
1254 // vrfp = vty->index;
1255
1256 return ret;
1257 }
1258
1259 struct cmd_node vrf_node =
1260 {
1261 VRF_NODE,
1262 "%s(config-vrf)# ",
1263 1
1264 };
1265
1266 /* Show all interfaces to vty. */
1267 DEFUN (show_interface, show_interface_cmd,
1268 "show interface",
1269 SHOW_STR
1270 "Interface status and configuration\n")
1271 {
1272 struct listnode *node;
1273 struct interface *ifp;
1274 vrf_id_t vrf_id = VRF_DEFAULT;
1275
1276 #ifdef HAVE_PROC_NET_DEV
1277 /* If system has interface statistics via proc file system, update
1278 statistics. */
1279 ifstat_update_proc ();
1280 #endif /* HAVE_PROC_NET_DEV */
1281 #ifdef HAVE_NET_RT_IFLIST
1282 ifstat_update_sysctl ();
1283 #endif /* HAVE_NET_RT_IFLIST */
1284
1285 if (argc > 0)
1286 VRF_GET_ID (vrf_id, argv[0]);
1287
1288 /* All interface print. */
1289 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (vrf_id), node, ifp))
1290 if_dump_vty (vty, ifp);
1291
1292 return CMD_SUCCESS;
1293 }
1294
1295 ALIAS (show_interface,
1296 show_interface_vrf_cmd,
1297 "show interface " VRF_CMD_STR,
1298 SHOW_STR
1299 "Interface status and configuration\n"
1300 VRF_CMD_HELP_STR)
1301
1302 /* Show all interfaces to vty. */
1303 DEFUN (show_interface_vrf_all, show_interface_vrf_all_cmd,
1304 "show interface " VRF_ALL_CMD_STR,
1305 SHOW_STR
1306 "Interface status and configuration\n"
1307 VRF_ALL_CMD_HELP_STR)
1308 {
1309 struct listnode *node;
1310 struct interface *ifp;
1311 vrf_iter_t iter;
1312
1313 #ifdef HAVE_PROC_NET_DEV
1314 /* If system has interface statistics via proc file system, update
1315 statistics. */
1316 ifstat_update_proc ();
1317 #endif /* HAVE_PROC_NET_DEV */
1318 #ifdef HAVE_NET_RT_IFLIST
1319 ifstat_update_sysctl ();
1320 #endif /* HAVE_NET_RT_IFLIST */
1321
1322 /* All interface print. */
1323 for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
1324 for (ALL_LIST_ELEMENTS_RO (vrf_iter2iflist (iter), node, ifp))
1325 if_dump_vty (vty, ifp);
1326
1327 return CMD_SUCCESS;
1328 }
1329
1330 /* Show specified interface to vty. */
1331
1332 DEFUN (show_interface_name_vrf,
1333 show_interface_name_vrf_cmd,
1334 "show interface IFNAME " VRF_CMD_STR,
1335 SHOW_STR
1336 "Interface status and configuration\n"
1337 "Interface name\n"
1338 VRF_CMD_HELP_STR)
1339 {
1340 struct interface *ifp;
1341 vrf_id_t vrf_id = VRF_DEFAULT;
1342
1343 #ifdef HAVE_PROC_NET_DEV
1344 /* If system has interface statistics via proc file system, update
1345 statistics. */
1346 ifstat_update_proc ();
1347 #endif /* HAVE_PROC_NET_DEV */
1348 #ifdef HAVE_NET_RT_IFLIST
1349 ifstat_update_sysctl ();
1350 #endif /* HAVE_NET_RT_IFLIST */
1351
1352 if (argc > 1)
1353 VRF_GET_ID (vrf_id, argv[1]);
1354
1355 /* Specified interface print. */
1356 ifp = if_lookup_by_name_vrf (argv[0], vrf_id);
1357 if (ifp == NULL)
1358 {
1359 vty_out (vty, "%% Can't find interface %s%s", argv[0],
1360 VTY_NEWLINE);
1361 return CMD_WARNING;
1362 }
1363 if_dump_vty (vty, ifp);
1364
1365 return CMD_SUCCESS;
1366 }
1367
1368 /* Show specified interface to vty. */
1369 DEFUN (show_interface_name_vrf_all, show_interface_name_vrf_all_cmd,
1370 "show interface IFNAME " VRF_ALL_CMD_STR,
1371 SHOW_STR
1372 "Interface status and configuration\n"
1373 "Interface name\n"
1374 VRF_ALL_CMD_HELP_STR)
1375 {
1376 struct interface *ifp;
1377 vrf_iter_t iter;
1378 int found = 0;
1379
1380 #ifdef HAVE_PROC_NET_DEV
1381 /* If system has interface statistics via proc file system, update
1382 statistics. */
1383 ifstat_update_proc ();
1384 #endif /* HAVE_PROC_NET_DEV */
1385 #ifdef HAVE_NET_RT_IFLIST
1386 ifstat_update_sysctl ();
1387 #endif /* HAVE_NET_RT_IFLIST */
1388
1389 /* All interface print. */
1390 for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
1391 {
1392 /* Specified interface print. */
1393 ifp = if_lookup_by_name_vrf (argv[0], vrf_iter2id (iter));
1394 if (ifp)
1395 {
1396 if_dump_vty (vty, ifp);
1397 found++;
1398 }
1399 }
1400
1401 if (!found)
1402 {
1403 vty_out (vty, "%% Can't find interface %s%s", argv[0], VTY_NEWLINE);
1404 return CMD_WARNING;
1405 }
1406
1407 return CMD_SUCCESS;
1408 }
1409
1410 ALIAS (show_interface_name_vrf_all, show_interface_name_cmd,
1411 "show interface IFNAME",
1412 SHOW_STR
1413 "Interface status and configuration\n"
1414 "Interface name\n")
1415
1416 static void
1417 if_show_description (struct vty *vty, vrf_id_t vrf_id)
1418 {
1419 struct listnode *node;
1420 struct interface *ifp;
1421
1422 vty_out (vty, "Interface Status Protocol Description%s", VTY_NEWLINE);
1423 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (vrf_id), node, ifp))
1424 {
1425 int len;
1426
1427 len = vty_out (vty, "%s", ifp->name);
1428 vty_out (vty, "%*s", (16 - len), " ");
1429
1430 if (if_is_up(ifp))
1431 {
1432 vty_out (vty, "up ");
1433 if (CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION))
1434 {
1435 if (if_is_running(ifp))
1436 vty_out (vty, "up ");
1437 else
1438 vty_out (vty, "down ");
1439 }
1440 else
1441 {
1442 vty_out (vty, "unknown ");
1443 }
1444 }
1445 else
1446 {
1447 vty_out (vty, "down down ");
1448 }
1449
1450 if (ifp->desc)
1451 vty_out (vty, "%s", ifp->desc);
1452 vty_out (vty, "%s", VTY_NEWLINE);
1453 }
1454 }
1455
1456 DEFUN (show_interface_desc,
1457 show_interface_desc_cmd,
1458 "show interface description",
1459 SHOW_STR
1460 "Interface status and configuration\n"
1461 "Interface description\n")
1462 {
1463 vrf_id_t vrf_id = VRF_DEFAULT;
1464
1465 if (argc > 0)
1466 VRF_GET_ID (vrf_id, argv[0]);
1467
1468 if_show_description (vty, vrf_id);
1469
1470 return CMD_SUCCESS;
1471 }
1472
1473 ALIAS (show_interface_desc,
1474 show_interface_desc_vrf_cmd,
1475 "show interface description " VRF_CMD_STR,
1476 SHOW_STR
1477 "Interface status and configuration\n"
1478 "Interface description\n"
1479 VRF_CMD_HELP_STR)
1480
1481 DEFUN (show_interface_desc_vrf_all,
1482 show_interface_desc_vrf_all_cmd,
1483 "show interface description " VRF_ALL_CMD_STR,
1484 SHOW_STR
1485 "Interface status and configuration\n"
1486 "Interface description\n"
1487 VRF_ALL_CMD_HELP_STR)
1488 {
1489 vrf_iter_t iter;
1490
1491 for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
1492 if (!list_isempty (vrf_iter2iflist (iter)))
1493 {
1494 vty_out (vty, "%s\tVRF %u%s%s", VTY_NEWLINE,
1495 vrf_iter2id (iter),
1496 VTY_NEWLINE, VTY_NEWLINE);
1497 if_show_description (vty, vrf_iter2id (iter));
1498 }
1499
1500 return CMD_SUCCESS;
1501 }
1502
1503 DEFUN (multicast,
1504 multicast_cmd,
1505 "multicast",
1506 "Set multicast flag to interface\n")
1507 {
1508 int ret;
1509 struct interface *ifp;
1510 struct zebra_if *if_data;
1511
1512 ifp = (struct interface *) vty->index;
1513 if (CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE))
1514 {
1515 ret = if_set_flags (ifp, IFF_MULTICAST);
1516 if (ret < 0)
1517 {
1518 vty_out (vty, "Can't set multicast flag%s", VTY_NEWLINE);
1519 return CMD_WARNING;
1520 }
1521 if_refresh (ifp);
1522 }
1523 if_data = ifp->info;
1524 if_data->multicast = IF_ZEBRA_MULTICAST_ON;
1525
1526 return CMD_SUCCESS;
1527 }
1528
1529 DEFUN (no_multicast,
1530 no_multicast_cmd,
1531 "no multicast",
1532 NO_STR
1533 "Unset multicast flag to interface\n")
1534 {
1535 int ret;
1536 struct interface *ifp;
1537 struct zebra_if *if_data;
1538
1539 ifp = (struct interface *) vty->index;
1540 if (CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE))
1541 {
1542 ret = if_unset_flags (ifp, IFF_MULTICAST);
1543 if (ret < 0)
1544 {
1545 vty_out (vty, "Can't unset multicast flag%s", VTY_NEWLINE);
1546 return CMD_WARNING;
1547 }
1548 if_refresh (ifp);
1549 }
1550 if_data = ifp->info;
1551 if_data->multicast = IF_ZEBRA_MULTICAST_OFF;
1552
1553 return CMD_SUCCESS;
1554 }
1555
1556 DEFUN (linkdetect,
1557 linkdetect_cmd,
1558 "link-detect",
1559 "Enable link detection on interface\n")
1560 {
1561 struct interface *ifp;
1562 int if_was_operative;
1563
1564 ifp = (struct interface *) vty->index;
1565 if_was_operative = if_is_no_ptm_operative(ifp);
1566 SET_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION);
1567
1568 /* When linkdetection is enabled, if might come down */
1569 if (!if_is_no_ptm_operative(ifp) && if_was_operative) if_down(ifp);
1570
1571 /* FIXME: Will defer status change forwarding if interface
1572 does not come down! */
1573
1574 return CMD_SUCCESS;
1575 }
1576
1577
1578 DEFUN (no_linkdetect,
1579 no_linkdetect_cmd,
1580 "no link-detect",
1581 NO_STR
1582 "Disable link detection on interface\n")
1583 {
1584 struct interface *ifp;
1585 int if_was_operative;
1586
1587 ifp = (struct interface *) vty->index;
1588 if_was_operative = if_is_no_ptm_operative(ifp);
1589 UNSET_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION);
1590
1591 /* Interface may come up after disabling link detection */
1592 if (if_is_operative(ifp) && !if_was_operative) if_up(ifp);
1593
1594 /* FIXME: see linkdetect_cmd */
1595
1596 return CMD_SUCCESS;
1597 }
1598
1599 DEFUN (shutdown_if,
1600 shutdown_if_cmd,
1601 "shutdown",
1602 "Shutdown the selected interface\n")
1603 {
1604 int ret;
1605 struct interface *ifp;
1606 struct zebra_if *if_data;
1607
1608 ifp = (struct interface *) vty->index;
1609 if (ifp->ifindex != IFINDEX_INTERNAL)
1610 {
1611 ret = if_unset_flags (ifp, IFF_UP);
1612 if (ret < 0)
1613 {
1614 vty_out (vty, "Can't shutdown interface%s", VTY_NEWLINE);
1615 return CMD_WARNING;
1616 }
1617 if_refresh (ifp);
1618 }
1619 if_data = ifp->info;
1620 if_data->shutdown = IF_ZEBRA_SHUTDOWN_ON;
1621
1622 return CMD_SUCCESS;
1623 }
1624
1625 DEFUN (no_shutdown_if,
1626 no_shutdown_if_cmd,
1627 "no shutdown",
1628 NO_STR
1629 "Shutdown the selected interface\n")
1630 {
1631 int ret;
1632 struct interface *ifp;
1633 struct zebra_if *if_data;
1634
1635 ifp = (struct interface *) vty->index;
1636
1637 if (ifp->ifindex != IFINDEX_INTERNAL)
1638 {
1639 ret = if_set_flags (ifp, IFF_UP | IFF_RUNNING);
1640 if (ret < 0)
1641 {
1642 vty_out (vty, "Can't up interface%s", VTY_NEWLINE);
1643 return CMD_WARNING;
1644 }
1645 if_refresh (ifp);
1646
1647 /* Some addresses (in particular, IPv6 addresses on Linux) get
1648 * removed when the interface goes down. They need to be readded.
1649 */
1650 if_addr_wakeup(ifp);
1651 }
1652
1653 if_data = ifp->info;
1654 if_data->shutdown = IF_ZEBRA_SHUTDOWN_OFF;
1655
1656 return CMD_SUCCESS;
1657 }
1658
1659 DEFUN (bandwidth_if,
1660 bandwidth_if_cmd,
1661 "bandwidth <1-10000000>",
1662 "Set bandwidth informational parameter\n"
1663 "Bandwidth in kilobits\n")
1664 {
1665 struct interface *ifp;
1666 unsigned int bandwidth;
1667
1668 ifp = (struct interface *) vty->index;
1669 bandwidth = strtol(argv[0], NULL, 10);
1670
1671 /* bandwidth range is <1-10000000> */
1672 if (bandwidth < 1 || bandwidth > 10000000)
1673 {
1674 vty_out (vty, "Bandwidth is invalid%s", VTY_NEWLINE);
1675 return CMD_WARNING;
1676 }
1677
1678 ifp->bandwidth = bandwidth;
1679
1680 /* force protocols to recalculate routes due to cost change */
1681 if (if_is_operative (ifp))
1682 zebra_interface_up_update (ifp);
1683
1684 return CMD_SUCCESS;
1685 }
1686
1687 DEFUN (no_bandwidth_if,
1688 no_bandwidth_if_cmd,
1689 "no bandwidth",
1690 NO_STR
1691 "Set bandwidth informational parameter\n")
1692 {
1693 struct interface *ifp;
1694
1695 ifp = (struct interface *) vty->index;
1696
1697 ifp->bandwidth = 0;
1698
1699 /* force protocols to recalculate routes due to cost change */
1700 if (if_is_operative (ifp))
1701 zebra_interface_up_update (ifp);
1702
1703 return CMD_SUCCESS;
1704 }
1705
1706 ALIAS (no_bandwidth_if,
1707 no_bandwidth_if_val_cmd,
1708 "no bandwidth <1-10000000>",
1709 NO_STR
1710 "Set bandwidth informational parameter\n"
1711 "Bandwidth in kilobits\n")
1712
1713 static int
1714 ip_address_install (struct vty *vty, struct interface *ifp,
1715 const char *addr_str, const char *peer_str,
1716 const char *label)
1717 {
1718 struct zebra_if *if_data;
1719 struct prefix_ipv4 cp;
1720 struct connected *ifc;
1721 struct prefix_ipv4 *p;
1722 int ret;
1723
1724 if_data = ifp->info;
1725
1726 ret = str2prefix_ipv4 (addr_str, &cp);
1727 if (ret <= 0)
1728 {
1729 vty_out (vty, "%% Malformed address %s", VTY_NEWLINE);
1730 return CMD_WARNING;
1731 }
1732
1733 if (ipv4_martian(&cp.prefix))
1734 {
1735 vty_out (vty, "%% Invalid address%s", VTY_NEWLINE);
1736 return CMD_WARNING;
1737 }
1738
1739 ifc = connected_check (ifp, (struct prefix *) &cp);
1740 if (! ifc)
1741 {
1742 ifc = connected_new ();
1743 ifc->ifp = ifp;
1744
1745 /* Address. */
1746 p = prefix_ipv4_new ();
1747 *p = cp;
1748 ifc->address = (struct prefix *) p;
1749
1750 /* Broadcast. */
1751 if (p->prefixlen <= IPV4_MAX_PREFIXLEN-2)
1752 {
1753 p = prefix_ipv4_new ();
1754 *p = cp;
1755 p->prefix.s_addr = ipv4_broadcast_addr(p->prefix.s_addr,p->prefixlen);
1756 ifc->destination = (struct prefix *) p;
1757 }
1758
1759 /* Label. */
1760 if (label)
1761 ifc->label = XSTRDUP (MTYPE_CONNECTED_LABEL, label);
1762
1763 /* Add to linked list. */
1764 listnode_add (ifp->connected, ifc);
1765 }
1766
1767 /* This address is configured from zebra. */
1768 if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED))
1769 SET_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED);
1770
1771 /* In case of this route need to install kernel. */
1772 if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_QUEUED)
1773 && CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE)
1774 && !(if_data && if_data->shutdown == IF_ZEBRA_SHUTDOWN_ON))
1775 {
1776 /* Some system need to up the interface to set IP address. */
1777 if (! if_is_up (ifp))
1778 {
1779 if_set_flags (ifp, IFF_UP | IFF_RUNNING);
1780 if_refresh (ifp);
1781 }
1782
1783 ret = if_set_prefix (ifp, ifc);
1784 if (ret < 0)
1785 {
1786 vty_out (vty, "%% Can't set interface IP address: %s.%s",
1787 safe_strerror(errno), VTY_NEWLINE);
1788 return CMD_WARNING;
1789 }
1790
1791 SET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED);
1792 /* The address will be advertised to zebra clients when the notification
1793 * from the kernel has been received.
1794 * It will also be added to the subnet chain list, then. */
1795 }
1796
1797 return CMD_SUCCESS;
1798 }
1799
1800 static int
1801 ip_address_uninstall (struct vty *vty, struct interface *ifp,
1802 const char *addr_str, const char *peer_str,
1803 const char *label)
1804 {
1805 struct prefix_ipv4 cp;
1806 struct connected *ifc;
1807 int ret;
1808
1809 /* Convert to prefix structure. */
1810 ret = str2prefix_ipv4 (addr_str, &cp);
1811 if (ret <= 0)
1812 {
1813 vty_out (vty, "%% Malformed address %s", VTY_NEWLINE);
1814 return CMD_WARNING;
1815 }
1816
1817 /* Check current interface address. */
1818 ifc = connected_check (ifp, (struct prefix *) &cp);
1819 if (! ifc)
1820 {
1821 vty_out (vty, "%% Can't find address%s", VTY_NEWLINE);
1822 return CMD_WARNING;
1823 }
1824
1825 /* This is not configured address. */
1826 if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED))
1827 return CMD_WARNING;
1828
1829 UNSET_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED);
1830
1831 /* This is not real address or interface is not active. */
1832 if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_QUEUED)
1833 || ! CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE))
1834 {
1835 listnode_delete (ifp->connected, ifc);
1836 connected_free (ifc);
1837 return CMD_WARNING;
1838 }
1839
1840 /* This is real route. */
1841 ret = if_unset_prefix (ifp, ifc);
1842 if (ret < 0)
1843 {
1844 vty_out (vty, "%% Can't unset interface IP address: %s.%s",
1845 safe_strerror(errno), VTY_NEWLINE);
1846 return CMD_WARNING;
1847 }
1848 UNSET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED);
1849 /* we will receive a kernel notification about this route being removed.
1850 * this will trigger its removal from the connected list. */
1851 return CMD_SUCCESS;
1852 }
1853
1854 DEFUN (ip_address,
1855 ip_address_cmd,
1856 "ip address A.B.C.D/M",
1857 "Interface Internet Protocol config commands\n"
1858 "Set the IP address of an interface\n"
1859 "IP address (e.g. 10.0.0.1/8)\n")
1860 {
1861 return ip_address_install (vty, vty->index, argv[0], NULL, NULL);
1862 }
1863
1864 DEFUN (no_ip_address,
1865 no_ip_address_cmd,
1866 "no ip address A.B.C.D/M",
1867 NO_STR
1868 "Interface Internet Protocol config commands\n"
1869 "Set the IP address of an interface\n"
1870 "IP Address (e.g. 10.0.0.1/8)")
1871 {
1872 return ip_address_uninstall (vty, vty->index, argv[0], NULL, NULL);
1873 }
1874
1875 #ifdef HAVE_NETLINK
1876 DEFUN (ip_address_label,
1877 ip_address_label_cmd,
1878 "ip address A.B.C.D/M label LINE",
1879 "Interface Internet Protocol config commands\n"
1880 "Set the IP address of an interface\n"
1881 "IP address (e.g. 10.0.0.1/8)\n"
1882 "Label of this address\n"
1883 "Label\n")
1884 {
1885 return ip_address_install (vty, vty->index, argv[0], NULL, argv[1]);
1886 }
1887
1888 DEFUN (no_ip_address_label,
1889 no_ip_address_label_cmd,
1890 "no ip address A.B.C.D/M label LINE",
1891 NO_STR
1892 "Interface Internet Protocol config commands\n"
1893 "Set the IP address of an interface\n"
1894 "IP address (e.g. 10.0.0.1/8)\n"
1895 "Label of this address\n"
1896 "Label\n")
1897 {
1898 return ip_address_uninstall (vty, vty->index, argv[0], NULL, argv[1]);
1899 }
1900 #endif /* HAVE_NETLINK */
1901
1902 #ifdef HAVE_IPV6
1903 static int
1904 ipv6_address_install (struct vty *vty, struct interface *ifp,
1905 const char *addr_str, const char *peer_str,
1906 const char *label, int secondary)
1907 {
1908 struct zebra_if *if_data;
1909 struct prefix_ipv6 cp;
1910 struct connected *ifc;
1911 struct prefix_ipv6 *p;
1912 int ret;
1913
1914 if_data = ifp->info;
1915
1916 ret = str2prefix_ipv6 (addr_str, &cp);
1917 if (ret <= 0)
1918 {
1919 vty_out (vty, "%% Malformed address %s", VTY_NEWLINE);
1920 return CMD_WARNING;
1921 }
1922
1923 if (ipv6_martian(&cp.prefix))
1924 {
1925 vty_out (vty, "%% Invalid address%s", VTY_NEWLINE);
1926 return CMD_WARNING;
1927 }
1928
1929 ifc = connected_check (ifp, (struct prefix *) &cp);
1930 if (! ifc)
1931 {
1932 ifc = connected_new ();
1933 ifc->ifp = ifp;
1934
1935 /* Address. */
1936 p = prefix_ipv6_new ();
1937 *p = cp;
1938 ifc->address = (struct prefix *) p;
1939
1940 /* Secondary. */
1941 if (secondary)
1942 SET_FLAG (ifc->flags, ZEBRA_IFA_SECONDARY);
1943
1944 /* Label. */
1945 if (label)
1946 ifc->label = XSTRDUP (MTYPE_CONNECTED_LABEL, label);
1947
1948 /* Add to linked list. */
1949 listnode_add (ifp->connected, ifc);
1950
1951 /* Enable RA on this interface */
1952 if (interface_ipv6_auto_ra_allowed (ifp))
1953 ipv6_nd_suppress_ra_set (ifp, RA_ENABLE);
1954 }
1955
1956 /* This address is configured from zebra. */
1957 if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED))
1958 SET_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED);
1959
1960 /* In case of this route need to install kernel. */
1961 if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_QUEUED)
1962 && CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE)
1963 && !(if_data && if_data->shutdown == IF_ZEBRA_SHUTDOWN_ON))
1964 {
1965 /* Some system need to up the interface to set IP address. */
1966 if (! if_is_up (ifp))
1967 {
1968 if_set_flags (ifp, IFF_UP | IFF_RUNNING);
1969 if_refresh (ifp);
1970 }
1971
1972 ret = if_prefix_add_ipv6 (ifp, ifc);
1973
1974 if (ret < 0)
1975 {
1976 vty_out (vty, "%% Can't set interface IP address: %s.%s",
1977 safe_strerror(errno), VTY_NEWLINE);
1978 return CMD_WARNING;
1979 }
1980
1981 SET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED);
1982 /* The address will be advertised to zebra clients when the notification
1983 * from the kernel has been received. */
1984 }
1985
1986 return CMD_SUCCESS;
1987 }
1988
1989 /* Return true if an ipv6 address is configured on ifp */
1990 int
1991 ipv6_address_configured (struct interface *ifp)
1992 {
1993 struct connected *connected;
1994 struct listnode *node;
1995
1996 for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, connected))
1997 if (CHECK_FLAG (connected->conf, ZEBRA_IFC_REAL) && (connected->address->family == AF_INET6))
1998 return 1;
1999
2000 return 0;
2001 }
2002
2003 static int
2004 ipv6_address_uninstall (struct vty *vty, struct interface *ifp,
2005 const char *addr_str, const char *peer_str,
2006 const char *label, int secondry)
2007 {
2008 struct prefix_ipv6 cp;
2009 struct connected *ifc;
2010 int ret;
2011
2012 /* Convert to prefix structure. */
2013 ret = str2prefix_ipv6 (addr_str, &cp);
2014 if (ret <= 0)
2015 {
2016 vty_out (vty, "%% Malformed address %s", VTY_NEWLINE);
2017 return CMD_WARNING;
2018 }
2019
2020 /* Check current interface address. */
2021 ifc = connected_check (ifp, (struct prefix *) &cp);
2022 if (! ifc)
2023 {
2024 vty_out (vty, "%% Can't find address%s", VTY_NEWLINE);
2025 return CMD_WARNING;
2026 }
2027
2028 /* This is not configured address. */
2029 if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED))
2030 return CMD_WARNING;
2031
2032 UNSET_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED);
2033
2034 /* This is not real address or interface is not active. */
2035 if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_QUEUED)
2036 || ! CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE))
2037 {
2038 listnode_delete (ifp->connected, ifc);
2039 connected_free (ifc);
2040 return CMD_WARNING;
2041 }
2042
2043 /* This is real route. */
2044 ret = if_prefix_delete_ipv6 (ifp, ifc);
2045 if (ret < 0)
2046 {
2047 vty_out (vty, "%% Can't unset interface IP address: %s.%s",
2048 safe_strerror(errno), VTY_NEWLINE);
2049 return CMD_WARNING;
2050 }
2051
2052 /* Enable RA suppression if there are no IPv6 addresses on this interface */
2053 if (interface_ipv6_auto_ra_allowed (ifp))
2054 {
2055 if (! ipv6_address_configured(ifp))
2056 ipv6_nd_suppress_ra_set (ifp, RA_SUPPRESS);
2057 }
2058
2059 UNSET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED);
2060 /* This information will be propagated to the zclients when the
2061 * kernel notification is received. */
2062 return CMD_SUCCESS;
2063 }
2064
2065 DEFUN (ipv6_address,
2066 ipv6_address_cmd,
2067 "ipv6 address X:X::X:X/M",
2068 "Interface IPv6 config commands\n"
2069 "Set the IP address of an interface\n"
2070 "IPv6 address (e.g. 3ffe:506::1/48)\n")
2071 {
2072 return ipv6_address_install (vty, vty->index, argv[0], NULL, NULL, 0);
2073 }
2074
2075 DEFUN (no_ipv6_address,
2076 no_ipv6_address_cmd,
2077 "no ipv6 address X:X::X:X/M",
2078 NO_STR
2079 "Interface IPv6 config commands\n"
2080 "Set the IP address of an interface\n"
2081 "IPv6 address (e.g. 3ffe:506::1/48)\n")
2082 {
2083 return ipv6_address_uninstall (vty, vty->index, argv[0], NULL, NULL, 0);
2084 }
2085 #endif /* HAVE_IPV6 */
2086
2087 static int
2088 if_config_write (struct vty *vty)
2089 {
2090 struct listnode *node;
2091 struct interface *ifp;
2092 vrf_iter_t iter;
2093
2094 zebra_ptm_write (vty);
2095
2096 for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
2097 for (ALL_LIST_ELEMENTS_RO (vrf_iter2iflist (iter), node, ifp))
2098 {
2099 struct zebra_if *if_data;
2100 struct listnode *addrnode;
2101 struct connected *ifc;
2102 struct prefix *p;
2103 struct vrf *vrf;
2104
2105 if_data = ifp->info;
2106 vrf = vrf_lookup(ifp->vrf_id);
2107
2108 if (ifp->vrf_id == VRF_DEFAULT)
2109 vty_out (vty, "interface %s%s", ifp->name, VTY_NEWLINE);
2110 else
2111 vty_out (vty, "interface %s vrf %s%s", ifp->name, vrf->name,
2112 VTY_NEWLINE);
2113
2114 if (if_data)
2115 {
2116 if (if_data->shutdown == IF_ZEBRA_SHUTDOWN_ON)
2117 vty_out (vty, " shutdown%s", VTY_NEWLINE);
2118 }
2119
2120 if (ifp->desc)
2121 vty_out (vty, " description %s%s", ifp->desc,
2122 VTY_NEWLINE);
2123
2124 /* Assign bandwidth here to avoid unnecessary interface flap
2125 while processing config script */
2126 if (ifp->bandwidth != 0)
2127 vty_out(vty, " bandwidth %u%s", ifp->bandwidth, VTY_NEWLINE);
2128
2129 if (CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION))
2130 vty_out(vty, " link-detect%s", VTY_NEWLINE);
2131
2132 for (ALL_LIST_ELEMENTS_RO (ifp->connected, addrnode, ifc))
2133 {
2134 if (CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED))
2135 {
2136 char buf[INET6_ADDRSTRLEN];
2137 p = ifc->address;
2138 vty_out (vty, " ip%s address %s/%d",
2139 p->family == AF_INET ? "" : "v6",
2140 inet_ntop (p->family, &p->u.prefix, buf, sizeof(buf)),
2141 p->prefixlen);
2142
2143 if (ifc->label)
2144 vty_out (vty, " label %s", ifc->label);
2145
2146 vty_out (vty, "%s", VTY_NEWLINE);
2147 }
2148 }
2149
2150 if (if_data)
2151 {
2152 if (if_data->multicast != IF_ZEBRA_MULTICAST_UNSPEC)
2153 vty_out (vty, " %smulticast%s",
2154 if_data->multicast == IF_ZEBRA_MULTICAST_ON ? "" : "no ",
2155 VTY_NEWLINE);
2156 }
2157
2158 #if defined (HAVE_RTADV)
2159 rtadv_config_write (vty, ifp);
2160 #endif /* HAVE_RTADV */
2161
2162 #ifdef HAVE_IRDP
2163 irdp_config_write (vty, ifp);
2164 #endif /* IRDP */
2165
2166 vty_out (vty, "!%s", VTY_NEWLINE);
2167 }
2168 return 0;
2169 }
2170
2171 static int
2172 vrf_config_write (struct vty *vty)
2173 {
2174 struct listnode *node;
2175 struct vrf *vrf;
2176
2177 for (ALL_LIST_ELEMENTS_RO (vrf_list, node, vrf))
2178 {
2179 if (strcmp(vrf->name, VRF_DEFAULT_NAME))
2180 {
2181 vty_out (vty, "vrf %s%s", vrf->name, VTY_NEWLINE);
2182 vty_out (vty, "!%s", VTY_NEWLINE);
2183 }
2184 }
2185 return 0;
2186 }
2187
2188 /* Allocate and initialize interface vector. */
2189 void
2190 zebra_if_init (void)
2191 {
2192 /* Initialize interface and new hook. */
2193 if_add_hook (IF_NEW_HOOK, if_zebra_new_hook);
2194 if_add_hook (IF_DELETE_HOOK, if_zebra_delete_hook);
2195
2196 /* Install configuration write function. */
2197 install_node (&interface_node, if_config_write);
2198 install_node (&vrf_node, vrf_config_write);
2199
2200 install_element (VIEW_NODE, &show_interface_cmd);
2201 install_element (VIEW_NODE, &show_interface_vrf_cmd);
2202 install_element (VIEW_NODE, &show_interface_vrf_all_cmd);
2203 install_element (VIEW_NODE, &show_interface_name_cmd);
2204 install_element (VIEW_NODE, &show_interface_name_vrf_cmd);
2205 install_element (VIEW_NODE, &show_interface_name_vrf_all_cmd);
2206 install_element (ENABLE_NODE, &show_interface_cmd);
2207 install_element (ENABLE_NODE, &show_interface_vrf_cmd);
2208 install_element (ENABLE_NODE, &show_interface_vrf_all_cmd);
2209 install_element (ENABLE_NODE, &show_interface_name_cmd);
2210 install_element (ENABLE_NODE, &show_interface_name_vrf_cmd);
2211 install_element (ENABLE_NODE, &show_interface_name_vrf_all_cmd);
2212 install_element (ENABLE_NODE, &show_interface_desc_cmd);
2213 install_element (ENABLE_NODE, &show_interface_desc_vrf_cmd);
2214 install_element (ENABLE_NODE, &show_interface_desc_vrf_all_cmd);
2215 install_element (CONFIG_NODE, &zebra_interface_cmd);
2216 install_element (CONFIG_NODE, &zebra_interface_vrf_cmd);
2217 install_element (CONFIG_NODE, &no_interface_cmd);
2218 install_element (CONFIG_NODE, &no_interface_vrf_cmd);
2219 install_default (INTERFACE_NODE);
2220 install_element (INTERFACE_NODE, &interface_desc_cmd);
2221 install_element (INTERFACE_NODE, &no_interface_desc_cmd);
2222 install_element (INTERFACE_NODE, &multicast_cmd);
2223 install_element (INTERFACE_NODE, &no_multicast_cmd);
2224 install_element (INTERFACE_NODE, &linkdetect_cmd);
2225 install_element (INTERFACE_NODE, &no_linkdetect_cmd);
2226 install_element (INTERFACE_NODE, &shutdown_if_cmd);
2227 install_element (INTERFACE_NODE, &no_shutdown_if_cmd);
2228 install_element (INTERFACE_NODE, &bandwidth_if_cmd);
2229 install_element (INTERFACE_NODE, &no_bandwidth_if_cmd);
2230 install_element (INTERFACE_NODE, &no_bandwidth_if_val_cmd);
2231 install_element (INTERFACE_NODE, &ip_address_cmd);
2232 install_element (INTERFACE_NODE, &no_ip_address_cmd);
2233 #ifdef HAVE_IPV6
2234 install_element (INTERFACE_NODE, &ipv6_address_cmd);
2235 install_element (INTERFACE_NODE, &no_ipv6_address_cmd);
2236 #endif /* HAVE_IPV6 */
2237 #ifdef HAVE_NETLINK
2238 install_element (INTERFACE_NODE, &ip_address_label_cmd);
2239 install_element (INTERFACE_NODE, &no_ip_address_label_cmd);
2240 #endif /* HAVE_NETLINK */
2241
2242 install_element (CONFIG_NODE, &zebra_vrf_cmd);
2243 install_element (CONFIG_NODE, &no_vrf_cmd);
2244 install_default (VRF_NODE);
2245
2246 }