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