]> git.proxmox.com Git - mirror_frr.git/blob - zebra/interface.c
zebra: Fix interface based static routes
[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 p = ifc->address;
585 connected_down_ipv4 (ifp, ifc);
586
587 /* XXX: We have to send notifications here explicitly, because we destroy
588 * the ifc before receiving the notification about the address being deleted.
589 */
590 zebra_interface_address_delete_update (ifp, ifc);
591
592 UNSET_FLAG (ifc->conf, ZEBRA_IFC_REAL);
593 UNSET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED);
594
595 /* Remove from subnet chain. */
596 list_delete_node (addr_list, anode);
597 route_unlock_node (rn);
598
599 /* Remove from interface address list (unconditionally). */
600 if (!CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED))
601 {
602 listnode_delete (ifp->connected, ifc);
603 connected_free (ifc);
604 }
605 else
606 last = node;
607 }
608
609 /* Free chain list and respective route node. */
610 list_delete (addr_list);
611 rn->info = NULL;
612 route_unlock_node (rn);
613 }
614 else if (p->family == AF_INET6)
615 {
616 connected_down_ipv6 (ifp, ifc);
617
618 zebra_interface_address_delete_update (ifp, ifc);
619
620 UNSET_FLAG (ifc->conf, ZEBRA_IFC_REAL);
621 UNSET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED);
622
623 if (CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED))
624 last = node;
625 else
626 {
627 listnode_delete (ifp->connected, ifc);
628 connected_free (ifc);
629 }
630 }
631 else
632 {
633 last = node;
634 }
635 }
636 }
637 }
638
639 /* Handle an interface delete event */
640 void
641 if_delete_update (struct interface *ifp)
642 {
643 if (if_is_up(ifp))
644 {
645 zlog_err ("interface %s vrf %u index %d is still up while being deleted.",
646 ifp->name, ifp->vrf_id, ifp->ifindex);
647 return;
648 }
649
650 /* Mark interface as inactive */
651 UNSET_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE);
652
653 if (IS_ZEBRA_DEBUG_KERNEL)
654 zlog_debug ("interface %s vrf %u index %d is now inactive.",
655 ifp->name, ifp->vrf_id, ifp->ifindex);
656
657 /* Delete connected routes from the kernel. */
658 if_delete_connected (ifp);
659
660 /* Send out notification on interface delete. */
661 zebra_interface_delete_update (ifp);
662
663 if_unlink_per_ns(ifp);
664
665 /* Update ifindex after distributing the delete message. This is in
666 case any client needs to have the old value of ifindex available
667 while processing the deletion. Each client daemon is responsible
668 for setting ifindex to IFINDEX_INTERNAL after processing the
669 interface deletion message. */
670 ifp->ifindex = IFINDEX_INTERNAL;
671 }
672
673 /* VRF change for an interface */
674 void
675 if_handle_vrf_change (struct interface *ifp, vrf_id_t vrf_id)
676 {
677 vrf_id_t old_vrf_id;
678
679 old_vrf_id = ifp->vrf_id;
680
681 /* Uninstall connected routes. */
682 if_uninstall_connected (ifp);
683
684 /* Delete any IPv4 neighbors created to implement RFC 5549 */
685 if_nbr_ipv6ll_to_ipv4ll_neigh_del_all (ifp);
686
687 /* Delete all neighbor addresses learnt through IPv6 RA */
688 if_down_del_nbr_connected (ifp);
689
690 /* Send out notification on interface VRF change. */
691 /* This is to issue an UPDATE or a DELETE, as appropriate. */
692 zebra_interface_vrf_update_del (ifp, vrf_id);
693
694 /* update VRF */
695 if_update_vrf (ifp, ifp->name, strlen (ifp->name), vrf_id);
696
697 /* Send out notification on interface VRF change. */
698 /* This is to issue an ADD, if needed. */
699 zebra_interface_vrf_update_add (ifp, old_vrf_id);
700
701 /* Install connected routes (in new VRF). */
702 if_install_connected (ifp);
703
704 /* Due to connected route change, schedule RIB processing for both old
705 * and new VRF.
706 */
707 if (IS_ZEBRA_DEBUG_RIB_DETAILED)
708 zlog_debug ("%u: IF %s VRF change, scheduling RIB processing",
709 ifp->vrf_id, ifp->name);
710 rib_update (old_vrf_id, RIB_UPDATE_IF_CHANGE);
711 rib_update (ifp->vrf_id, RIB_UPDATE_IF_CHANGE);
712
713 zebra_vrf_static_route_interface_fixup (ifp);
714 }
715
716 static void
717 ipv6_ll_address_to_mac (struct in6_addr *address, u_char *mac)
718 {
719 mac[0] = address->s6_addr[8] ^ 0x02;
720 mac[1] = address->s6_addr[9];
721 mac[2] = address->s6_addr[10];
722 mac[3] = address->s6_addr[13];
723 mac[4] = address->s6_addr[14];
724 mac[5] = address->s6_addr[15];
725 }
726
727 void
728 if_nbr_ipv6ll_to_ipv4ll_neigh_update (struct interface *ifp,
729 struct in6_addr *address,
730 int add)
731 {
732 char buf[16] = "169.254.0.1";
733 struct in_addr ipv4_ll;
734 char mac[6];
735
736 inet_pton (AF_INET, buf, &ipv4_ll);
737
738 ipv6_ll_address_to_mac(address, (u_char *)mac);
739 netlink_neigh_update (add ? RTM_NEWNEIGH : RTM_DELNEIGH,
740 ifp->ifindex, ipv4_ll.s_addr, mac, 6);
741 }
742
743 static void
744 if_nbr_ipv6ll_to_ipv4ll_neigh_add_all (struct interface *ifp)
745 {
746 if (listhead(ifp->nbr_connected))
747 {
748 struct nbr_connected *nbr_connected;
749 struct listnode *node;
750
751 for (ALL_LIST_ELEMENTS_RO (ifp->nbr_connected, node, nbr_connected))
752 if_nbr_ipv6ll_to_ipv4ll_neigh_update (ifp,
753 &nbr_connected->address->u.prefix6,
754 1);
755 }
756 }
757
758 void
759 if_nbr_ipv6ll_to_ipv4ll_neigh_del_all (struct interface *ifp)
760 {
761 if (listhead(ifp->nbr_connected))
762 {
763 struct nbr_connected *nbr_connected;
764 struct listnode *node;
765
766 for (ALL_LIST_ELEMENTS_RO (ifp->nbr_connected, node, nbr_connected))
767 if_nbr_ipv6ll_to_ipv4ll_neigh_update (ifp,
768 &nbr_connected->address->u.prefix6,
769 0);
770 }
771 }
772
773 static void
774 if_down_del_nbr_connected (struct interface *ifp)
775 {
776 struct nbr_connected *nbr_connected;
777 struct listnode *node, *nnode;
778
779 for (ALL_LIST_ELEMENTS (ifp->nbr_connected, node, nnode, nbr_connected))
780 {
781 listnode_delete (ifp->nbr_connected, nbr_connected);
782 nbr_connected_free (nbr_connected);
783 }
784 }
785
786 /* Interface is up. */
787 void
788 if_up (struct interface *ifp)
789 {
790 struct zebra_if *zif;
791
792 zif = ifp->info;
793 zif->up_count++;
794 quagga_timestamp (2, zif->up_last, sizeof (zif->up_last));
795
796 /* Notify the protocol daemons. */
797 if (ifp->ptm_enable && (ifp->ptm_status == ZEBRA_PTM_STATUS_DOWN)) {
798 zlog_warn("%s: interface %s hasn't passed ptm check\n", __func__,
799 ifp->name);
800 return;
801 }
802 zebra_interface_up_update (ifp);
803
804 if_nbr_ipv6ll_to_ipv4ll_neigh_add_all (ifp);
805
806 /* Enable fast tx of RA if enabled && RA interval is not in msecs */
807 if (zif->rtadv.AdvSendAdvertisements &&
808 (zif->rtadv.MaxRtrAdvInterval >= 1000))
809 {
810 zif->rtadv.inFastRexmit = 1;
811 zif->rtadv.NumFastReXmitsRemain = RTADV_NUM_FAST_REXMITS;
812 }
813
814 /* Install connected routes to the kernel. */
815 if_install_connected (ifp);
816
817 if (IS_ZEBRA_DEBUG_RIB_DETAILED)
818 zlog_debug ("%u: IF %s up, scheduling RIB processing",
819 ifp->vrf_id, ifp->name);
820 rib_update (ifp->vrf_id, RIB_UPDATE_IF_CHANGE);
821
822 zebra_vrf_static_route_interface_fixup (ifp);
823 }
824
825 /* Interface goes down. We have to manage different behavior of based
826 OS. */
827 void
828 if_down (struct interface *ifp)
829 {
830 struct zebra_if *zif;
831
832 zif = ifp->info;
833 zif->down_count++;
834 quagga_timestamp (2, zif->down_last, sizeof (zif->down_last));
835
836 /* Notify to the protocol daemons. */
837 zebra_interface_down_update (ifp);
838
839 /* Uninstall connected routes from the kernel. */
840 if_uninstall_connected (ifp);
841
842 if (IS_ZEBRA_DEBUG_RIB_DETAILED)
843 zlog_debug ("%u: IF %s down, scheduling RIB processing",
844 ifp->vrf_id, ifp->name);
845 rib_update (ifp->vrf_id, RIB_UPDATE_IF_CHANGE);
846
847 if_nbr_ipv6ll_to_ipv4ll_neigh_del_all (ifp);
848
849 /* Delete all neighbor addresses learnt through IPv6 RA */
850 if_down_del_nbr_connected (ifp);
851 }
852
853 void
854 if_refresh (struct interface *ifp)
855 {
856 if_get_flags (ifp);
857 }
858
859
860 /* Output prefix string to vty. */
861 static int
862 prefix_vty_out (struct vty *vty, struct prefix *p)
863 {
864 char str[INET6_ADDRSTRLEN];
865
866 inet_ntop (p->family, &p->u.prefix, str, sizeof (str));
867 vty_out (vty, "%s", str);
868 return strlen (str);
869 }
870
871 /* Dump if address information to vty. */
872 static void
873 connected_dump_vty (struct vty *vty, struct connected *connected)
874 {
875 struct prefix *p;
876
877 /* Print interface address. */
878 p = connected->address;
879 vty_out (vty, " %s ", prefix_family_str (p));
880 prefix_vty_out (vty, p);
881 vty_out (vty, "/%d", p->prefixlen);
882
883 /* If there is destination address, print it. */
884 if (connected->destination)
885 {
886 vty_out (vty, (CONNECTED_PEER(connected) ? " peer " : " broadcast "));
887 prefix_vty_out (vty, connected->destination);
888 }
889
890 if (CHECK_FLAG (connected->flags, ZEBRA_IFA_SECONDARY))
891 vty_out (vty, " secondary");
892
893 if (CHECK_FLAG (connected->flags, ZEBRA_IFA_UNNUMBERED))
894 vty_out (vty, " unnumbered");
895
896 if (connected->label)
897 vty_out (vty, " %s", connected->label);
898
899 vty_out (vty, "%s", VTY_NEWLINE);
900 }
901
902 /* Dump interface neighbor address information to vty. */
903 static void
904 nbr_connected_dump_vty (struct vty *vty, struct nbr_connected *connected)
905 {
906 struct prefix *p;
907
908 /* Print interface address. */
909 p = connected->address;
910 vty_out (vty, " %s ", prefix_family_str (p));
911 prefix_vty_out (vty, p);
912 vty_out (vty, "/%d", p->prefixlen);
913
914 vty_out (vty, "%s", VTY_NEWLINE);
915 }
916
917 #if defined (HAVE_RTADV)
918 /* Dump interface ND information to vty. */
919 static void
920 nd_dump_vty (struct vty *vty, struct interface *ifp)
921 {
922 struct zebra_if *zif;
923 struct rtadvconf *rtadv;
924 int interval;
925
926 zif = (struct zebra_if *) ifp->info;
927 rtadv = &zif->rtadv;
928
929 if (rtadv->AdvSendAdvertisements)
930 {
931 vty_out (vty, " ND advertised reachable time is %d milliseconds%s",
932 rtadv->AdvReachableTime, VTY_NEWLINE);
933 vty_out (vty, " ND advertised retransmit interval is %d milliseconds%s",
934 rtadv->AdvRetransTimer, VTY_NEWLINE);
935 interval = rtadv->MaxRtrAdvInterval;
936 if (interval % 1000)
937 vty_out (vty, " ND router advertisements are sent every "
938 "%d milliseconds%s", interval,
939 VTY_NEWLINE);
940 else
941 vty_out (vty, " ND router advertisements are sent every "
942 "%d seconds%s", interval / 1000,
943 VTY_NEWLINE);
944 if (rtadv->AdvDefaultLifetime != -1)
945 vty_out (vty, " ND router advertisements live for %d seconds%s",
946 rtadv->AdvDefaultLifetime, VTY_NEWLINE);
947 else
948 vty_out (vty, " ND router advertisements lifetime tracks ra-interval%s",
949 VTY_NEWLINE);
950 vty_out (vty, " ND router advertisement default router preference is "
951 "%s%s", rtadv_pref_strs[rtadv->DefaultPreference],
952 VTY_NEWLINE);
953 if (rtadv->AdvManagedFlag)
954 vty_out (vty, " Hosts use DHCP to obtain routable addresses.%s",
955 VTY_NEWLINE);
956 else
957 vty_out (vty, " Hosts use stateless autoconfig for addresses.%s",
958 VTY_NEWLINE);
959 if (rtadv->AdvHomeAgentFlag)
960 {
961 vty_out (vty, " ND router advertisements with "
962 "Home Agent flag bit set.%s",
963 VTY_NEWLINE);
964 if (rtadv->HomeAgentLifetime != -1)
965 vty_out (vty, " Home Agent lifetime is %u seconds%s",
966 rtadv->HomeAgentLifetime, VTY_NEWLINE);
967 else
968 vty_out (vty, " Home Agent lifetime tracks ra-lifetime%s",
969 VTY_NEWLINE);
970 vty_out (vty, " Home Agent preference is %u%s",
971 rtadv->HomeAgentPreference, VTY_NEWLINE);
972 }
973 if (rtadv->AdvIntervalOption)
974 vty_out (vty, " ND router advertisements with Adv. Interval option.%s",
975 VTY_NEWLINE);
976 }
977 }
978 #endif /* HAVE_RTADV */
979
980 /* Interface's information print out to vty interface. */
981 static void
982 if_dump_vty (struct vty *vty, struct interface *ifp)
983 {
984 #ifdef HAVE_STRUCT_SOCKADDR_DL
985 struct sockaddr_dl *sdl;
986 #endif /* HAVE_STRUCT_SOCKADDR_DL */
987 struct connected *connected;
988 struct nbr_connected *nbr_connected;
989 struct listnode *node;
990 struct route_node *rn;
991 struct zebra_if *zebra_if;
992 struct vrf *vrf;
993
994 zebra_if = ifp->info;
995
996 vty_out (vty, "Interface %s is ", ifp->name);
997 if (if_is_up(ifp)) {
998 vty_out (vty, "up, line protocol ");
999
1000 if (CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION)) {
1001 if (if_is_running(ifp))
1002 vty_out (vty, "is up%s", VTY_NEWLINE);
1003 else
1004 vty_out (vty, "is down%s", VTY_NEWLINE);
1005 } else {
1006 vty_out (vty, "detection is disabled%s", VTY_NEWLINE);
1007 }
1008 } else {
1009 vty_out (vty, "down%s", VTY_NEWLINE);
1010 }
1011
1012 vty_out (vty, " Link ups: %5u last: %s%s", zebra_if->up_count,
1013 zebra_if->up_last[0] ? zebra_if->up_last : "(never)", VTY_NEWLINE);
1014 vty_out (vty, " Link downs: %5u last: %s%s", zebra_if->down_count,
1015 zebra_if->down_last[0] ? zebra_if->down_last : "(never)", VTY_NEWLINE);
1016
1017 zebra_ptm_show_status(vty, ifp);
1018
1019 vrf = vrf_lookup(ifp->vrf_id);
1020 vty_out (vty, " vrf: %s%s", vrf->name, VTY_NEWLINE);
1021
1022 if (ifp->desc)
1023 vty_out (vty, " Description: %s%s", ifp->desc,
1024 VTY_NEWLINE);
1025 if (ifp->ifindex == IFINDEX_INTERNAL)
1026 {
1027 vty_out(vty, " pseudo interface%s", VTY_NEWLINE);
1028 return;
1029 }
1030 else if (! CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE))
1031 {
1032 vty_out(vty, " index %d inactive interface%s",
1033 ifp->ifindex,
1034 VTY_NEWLINE);
1035 return;
1036 }
1037
1038 vty_out (vty, " index %d metric %d mtu %d ",
1039 ifp->ifindex, ifp->metric, ifp->mtu);
1040 #ifdef HAVE_IPV6
1041 if (ifp->mtu6 != ifp->mtu)
1042 vty_out (vty, "mtu6 %d ", ifp->mtu6);
1043 #endif
1044 vty_out (vty, "%s flags: %s%s", VTY_NEWLINE,
1045 if_flag_dump (ifp->flags), VTY_NEWLINE);
1046
1047 /* Hardware address. */
1048 #ifdef HAVE_STRUCT_SOCKADDR_DL
1049 sdl = &ifp->sdl;
1050 if (sdl != NULL && sdl->sdl_alen != 0)
1051 {
1052 int i;
1053 u_char *ptr;
1054
1055 vty_out (vty, " HWaddr: ");
1056 for (i = 0, ptr = (u_char *)LLADDR (sdl); i < sdl->sdl_alen; i++, ptr++)
1057 vty_out (vty, "%s%02x", i == 0 ? "" : ":", *ptr);
1058 vty_out (vty, "%s", VTY_NEWLINE);
1059 }
1060 #else
1061 if (ifp->hw_addr_len != 0)
1062 {
1063 int i;
1064
1065 vty_out (vty, " HWaddr: ");
1066 for (i = 0; i < ifp->hw_addr_len; i++)
1067 vty_out (vty, "%s%02x", i == 0 ? "" : ":", ifp->hw_addr[i]);
1068 vty_out (vty, "%s", VTY_NEWLINE);
1069 }
1070 #endif /* HAVE_STRUCT_SOCKADDR_DL */
1071
1072 /* Bandwidth in kbps */
1073 if (ifp->bandwidth != 0)
1074 {
1075 vty_out(vty, " bandwidth %u kbps", ifp->bandwidth);
1076 vty_out(vty, "%s", VTY_NEWLINE);
1077 }
1078
1079 for (rn = route_top (zebra_if->ipv4_subnets); rn; rn = route_next (rn))
1080 {
1081 if (! rn->info)
1082 continue;
1083
1084 for (ALL_LIST_ELEMENTS_RO ((struct list *)rn->info, node, connected))
1085 connected_dump_vty (vty, connected);
1086 }
1087
1088 for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, connected))
1089 {
1090 if (CHECK_FLAG (connected->conf, ZEBRA_IFC_REAL) &&
1091 (connected->address->family == AF_INET6))
1092 connected_dump_vty (vty, connected);
1093 }
1094
1095 #if defined (HAVE_RTADV)
1096 nd_dump_vty (vty, ifp);
1097 #endif /* HAVE_RTADV */
1098 if (listhead(ifp->nbr_connected))
1099 vty_out (vty, " Neighbor address(s):%s", VTY_NEWLINE);
1100 for (ALL_LIST_ELEMENTS_RO (ifp->nbr_connected, node, nbr_connected))
1101 nbr_connected_dump_vty (vty, nbr_connected);
1102
1103 #ifdef HAVE_PROC_NET_DEV
1104 /* Statistics print out using proc file system. */
1105 vty_out (vty, " %lu input packets (%lu multicast), %lu bytes, "
1106 "%lu dropped%s",
1107 ifp->stats.rx_packets, ifp->stats.rx_multicast,
1108 ifp->stats.rx_bytes, ifp->stats.rx_dropped, VTY_NEWLINE);
1109
1110 vty_out (vty, " %lu input errors, %lu length, %lu overrun,"
1111 " %lu CRC, %lu frame%s",
1112 ifp->stats.rx_errors, ifp->stats.rx_length_errors,
1113 ifp->stats.rx_over_errors, ifp->stats.rx_crc_errors,
1114 ifp->stats.rx_frame_errors, VTY_NEWLINE);
1115
1116 vty_out (vty, " %lu fifo, %lu missed%s", ifp->stats.rx_fifo_errors,
1117 ifp->stats.rx_missed_errors, VTY_NEWLINE);
1118
1119 vty_out (vty, " %lu output packets, %lu bytes, %lu dropped%s",
1120 ifp->stats.tx_packets, ifp->stats.tx_bytes,
1121 ifp->stats.tx_dropped, VTY_NEWLINE);
1122
1123 vty_out (vty, " %lu output errors, %lu aborted, %lu carrier,"
1124 " %lu fifo, %lu heartbeat%s",
1125 ifp->stats.tx_errors, ifp->stats.tx_aborted_errors,
1126 ifp->stats.tx_carrier_errors, ifp->stats.tx_fifo_errors,
1127 ifp->stats.tx_heartbeat_errors, VTY_NEWLINE);
1128
1129 vty_out (vty, " %lu window, %lu collisions%s",
1130 ifp->stats.tx_window_errors, ifp->stats.collisions, VTY_NEWLINE);
1131 #endif /* HAVE_PROC_NET_DEV */
1132
1133 #ifdef HAVE_NET_RT_IFLIST
1134 #if defined (__bsdi__) || defined (__NetBSD__)
1135 /* Statistics print out using sysctl (). */
1136 vty_out (vty, " input packets %qu, bytes %qu, dropped %qu,"
1137 " multicast packets %qu%s",
1138 ifp->stats.ifi_ipackets, ifp->stats.ifi_ibytes,
1139 ifp->stats.ifi_iqdrops, ifp->stats.ifi_imcasts,
1140 VTY_NEWLINE);
1141
1142 vty_out (vty, " input errors %qu%s",
1143 ifp->stats.ifi_ierrors, VTY_NEWLINE);
1144
1145 vty_out (vty, " output packets %qu, bytes %qu, multicast packets %qu%s",
1146 ifp->stats.ifi_opackets, ifp->stats.ifi_obytes,
1147 ifp->stats.ifi_omcasts, VTY_NEWLINE);
1148
1149 vty_out (vty, " output errors %qu%s",
1150 ifp->stats.ifi_oerrors, VTY_NEWLINE);
1151
1152 vty_out (vty, " collisions %qu%s",
1153 ifp->stats.ifi_collisions, VTY_NEWLINE);
1154 #else
1155 /* Statistics print out using sysctl (). */
1156 vty_out (vty, " input packets %lu, bytes %lu, dropped %lu,"
1157 " multicast packets %lu%s",
1158 ifp->stats.ifi_ipackets, ifp->stats.ifi_ibytes,
1159 ifp->stats.ifi_iqdrops, ifp->stats.ifi_imcasts,
1160 VTY_NEWLINE);
1161
1162 vty_out (vty, " input errors %lu%s",
1163 ifp->stats.ifi_ierrors, VTY_NEWLINE);
1164
1165 vty_out (vty, " output packets %lu, bytes %lu, multicast packets %lu%s",
1166 ifp->stats.ifi_opackets, ifp->stats.ifi_obytes,
1167 ifp->stats.ifi_omcasts, VTY_NEWLINE);
1168
1169 vty_out (vty, " output errors %lu%s",
1170 ifp->stats.ifi_oerrors, VTY_NEWLINE);
1171
1172 vty_out (vty, " collisions %lu%s",
1173 ifp->stats.ifi_collisions, VTY_NEWLINE);
1174 #endif /* __bsdi__ || __NetBSD__ */
1175 #endif /* HAVE_NET_RT_IFLIST */
1176 }
1177
1178 /* Wrapper hook point for zebra daemon so that ifindex can be set
1179 * DEFUN macro not used as extract.pl HAS to ignore this
1180 * See also interface_cmd in lib/if.c
1181 */
1182 DEFUN_NOSH (zebra_interface,
1183 zebra_interface_cmd,
1184 "interface IFNAME",
1185 "Select an interface to configure\n"
1186 "Interface's name\n")
1187 {
1188 int ret;
1189 struct interface * ifp;
1190
1191 /* Call lib interface() */
1192 if ((ret = interface_cmd.func (self, vty, argc, argv)) != CMD_SUCCESS)
1193 return ret;
1194
1195 ifp = vty->index;
1196
1197 if (ifp->ifindex == IFINDEX_INTERNAL)
1198 /* Is this really necessary? Shouldn't status be initialized to 0
1199 in that case? */
1200 UNSET_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE);
1201
1202 return ret;
1203 }
1204
1205 ALIAS (zebra_interface,
1206 zebra_interface_vrf_cmd,
1207 "interface IFNAME " VRF_CMD_STR,
1208 "Select an interface to configure\n"
1209 "Interface's name\n"
1210 VRF_CMD_HELP_STR)
1211
1212 struct cmd_node interface_node =
1213 {
1214 INTERFACE_NODE,
1215 "%s(config-if)# ",
1216 1
1217 };
1218
1219 /* Wrapper hook point for zebra daemon so that ifindex can be set
1220 * DEFUN macro not used as extract.pl HAS to ignore this
1221 * See also interface_cmd in lib/if.c
1222 */
1223 DEFUN_NOSH (zebra_vrf,
1224 zebra_vrf_cmd,
1225 "vrf NAME",
1226 "Select a VRF to configure\n"
1227 "VRF's name\n")
1228 {
1229 int ret;
1230
1231 /* Call lib vrf() */
1232 if ((ret = vrf_cmd.func (self, vty, argc, argv)) != CMD_SUCCESS)
1233 return ret;
1234
1235 // vrfp = vty->index;
1236
1237 return ret;
1238 }
1239
1240 struct cmd_node vrf_node =
1241 {
1242 VRF_NODE,
1243 "%s(config-vrf)# ",
1244 1
1245 };
1246
1247 /* Show all interfaces to vty. */
1248 DEFUN (show_interface, show_interface_cmd,
1249 "show interface",
1250 SHOW_STR
1251 "Interface status and configuration\n")
1252 {
1253 struct listnode *node;
1254 struct interface *ifp;
1255 vrf_id_t vrf_id = VRF_DEFAULT;
1256
1257 #ifdef HAVE_PROC_NET_DEV
1258 /* If system has interface statistics via proc file system, update
1259 statistics. */
1260 ifstat_update_proc ();
1261 #endif /* HAVE_PROC_NET_DEV */
1262 #ifdef HAVE_NET_RT_IFLIST
1263 ifstat_update_sysctl ();
1264 #endif /* HAVE_NET_RT_IFLIST */
1265
1266 if (argc > 0)
1267 VRF_GET_ID (vrf_id, argv[0]);
1268
1269 /* All interface print. */
1270 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (vrf_id), node, ifp))
1271 if_dump_vty (vty, ifp);
1272
1273 return CMD_SUCCESS;
1274 }
1275
1276 ALIAS (show_interface,
1277 show_interface_vrf_cmd,
1278 "show interface " VRF_CMD_STR,
1279 SHOW_STR
1280 "Interface status and configuration\n"
1281 VRF_CMD_HELP_STR)
1282
1283 /* Show all interfaces to vty. */
1284 DEFUN (show_interface_vrf_all, show_interface_vrf_all_cmd,
1285 "show interface " VRF_ALL_CMD_STR,
1286 SHOW_STR
1287 "Interface status and configuration\n"
1288 VRF_ALL_CMD_HELP_STR)
1289 {
1290 struct listnode *node;
1291 struct interface *ifp;
1292 vrf_iter_t iter;
1293
1294 #ifdef HAVE_PROC_NET_DEV
1295 /* If system has interface statistics via proc file system, update
1296 statistics. */
1297 ifstat_update_proc ();
1298 #endif /* HAVE_PROC_NET_DEV */
1299 #ifdef HAVE_NET_RT_IFLIST
1300 ifstat_update_sysctl ();
1301 #endif /* HAVE_NET_RT_IFLIST */
1302
1303 /* All interface print. */
1304 for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
1305 for (ALL_LIST_ELEMENTS_RO (vrf_iter2iflist (iter), node, ifp))
1306 if_dump_vty (vty, ifp);
1307
1308 return CMD_SUCCESS;
1309 }
1310
1311 /* Show specified interface to vty. */
1312
1313 DEFUN (show_interface_name_vrf,
1314 show_interface_name_vrf_cmd,
1315 "show interface IFNAME " VRF_CMD_STR,
1316 SHOW_STR
1317 "Interface status and configuration\n"
1318 "Interface name\n"
1319 VRF_CMD_HELP_STR)
1320 {
1321 struct interface *ifp;
1322 vrf_id_t vrf_id = VRF_DEFAULT;
1323
1324 #ifdef HAVE_PROC_NET_DEV
1325 /* If system has interface statistics via proc file system, update
1326 statistics. */
1327 ifstat_update_proc ();
1328 #endif /* HAVE_PROC_NET_DEV */
1329 #ifdef HAVE_NET_RT_IFLIST
1330 ifstat_update_sysctl ();
1331 #endif /* HAVE_NET_RT_IFLIST */
1332
1333 if (argc > 1)
1334 VRF_GET_ID (vrf_id, argv[1]);
1335
1336 /* Specified interface print. */
1337 ifp = if_lookup_by_name_vrf (argv[0], vrf_id);
1338 if (ifp == NULL)
1339 {
1340 vty_out (vty, "%% Can't find interface %s%s", argv[0],
1341 VTY_NEWLINE);
1342 return CMD_WARNING;
1343 }
1344 if_dump_vty (vty, ifp);
1345
1346 return CMD_SUCCESS;
1347 }
1348
1349 /* Show specified interface to vty. */
1350 DEFUN (show_interface_name_vrf_all, show_interface_name_vrf_all_cmd,
1351 "show interface IFNAME " VRF_ALL_CMD_STR,
1352 SHOW_STR
1353 "Interface status and configuration\n"
1354 "Interface name\n"
1355 VRF_ALL_CMD_HELP_STR)
1356 {
1357 struct interface *ifp;
1358 vrf_iter_t iter;
1359 int found = 0;
1360
1361 #ifdef HAVE_PROC_NET_DEV
1362 /* If system has interface statistics via proc file system, update
1363 statistics. */
1364 ifstat_update_proc ();
1365 #endif /* HAVE_PROC_NET_DEV */
1366 #ifdef HAVE_NET_RT_IFLIST
1367 ifstat_update_sysctl ();
1368 #endif /* HAVE_NET_RT_IFLIST */
1369
1370 /* All interface print. */
1371 for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
1372 {
1373 /* Specified interface print. */
1374 ifp = if_lookup_by_name_vrf (argv[0], vrf_iter2id (iter));
1375 if (ifp)
1376 {
1377 if_dump_vty (vty, ifp);
1378 found++;
1379 }
1380 }
1381
1382 if (!found)
1383 {
1384 vty_out (vty, "%% Can't find interface %s%s", argv[0], VTY_NEWLINE);
1385 return CMD_WARNING;
1386 }
1387
1388 return CMD_SUCCESS;
1389 }
1390
1391 ALIAS (show_interface_name_vrf_all, show_interface_name_cmd,
1392 "show interface IFNAME",
1393 SHOW_STR
1394 "Interface status and configuration\n"
1395 "Interface name\n")
1396
1397 static void
1398 if_show_description (struct vty *vty, vrf_id_t vrf_id)
1399 {
1400 struct listnode *node;
1401 struct interface *ifp;
1402
1403 vty_out (vty, "Interface Status Protocol Description%s", VTY_NEWLINE);
1404 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (vrf_id), node, ifp))
1405 {
1406 int len;
1407
1408 len = vty_out (vty, "%s", ifp->name);
1409 vty_out (vty, "%*s", (16 - len), " ");
1410
1411 if (if_is_up(ifp))
1412 {
1413 vty_out (vty, "up ");
1414 if (CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION))
1415 {
1416 if (if_is_running(ifp))
1417 vty_out (vty, "up ");
1418 else
1419 vty_out (vty, "down ");
1420 }
1421 else
1422 {
1423 vty_out (vty, "unknown ");
1424 }
1425 }
1426 else
1427 {
1428 vty_out (vty, "down down ");
1429 }
1430
1431 if (ifp->desc)
1432 vty_out (vty, "%s", ifp->desc);
1433 vty_out (vty, "%s", VTY_NEWLINE);
1434 }
1435 }
1436
1437 DEFUN (show_interface_desc,
1438 show_interface_desc_cmd,
1439 "show interface description",
1440 SHOW_STR
1441 "Interface status and configuration\n"
1442 "Interface description\n")
1443 {
1444 vrf_id_t vrf_id = VRF_DEFAULT;
1445
1446 if (argc > 0)
1447 VRF_GET_ID (vrf_id, argv[0]);
1448
1449 if_show_description (vty, vrf_id);
1450
1451 return CMD_SUCCESS;
1452 }
1453
1454 ALIAS (show_interface_desc,
1455 show_interface_desc_vrf_cmd,
1456 "show interface description " VRF_CMD_STR,
1457 SHOW_STR
1458 "Interface status and configuration\n"
1459 "Interface description\n"
1460 VRF_CMD_HELP_STR)
1461
1462 DEFUN (show_interface_desc_vrf_all,
1463 show_interface_desc_vrf_all_cmd,
1464 "show interface description " VRF_ALL_CMD_STR,
1465 SHOW_STR
1466 "Interface status and configuration\n"
1467 "Interface description\n"
1468 VRF_ALL_CMD_HELP_STR)
1469 {
1470 vrf_iter_t iter;
1471
1472 for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
1473 if (!list_isempty (vrf_iter2iflist (iter)))
1474 {
1475 vty_out (vty, "%s\tVRF %u%s%s", VTY_NEWLINE,
1476 vrf_iter2id (iter),
1477 VTY_NEWLINE, VTY_NEWLINE);
1478 if_show_description (vty, vrf_iter2id (iter));
1479 }
1480
1481 return CMD_SUCCESS;
1482 }
1483
1484 DEFUN (multicast,
1485 multicast_cmd,
1486 "multicast",
1487 "Set multicast flag to interface\n")
1488 {
1489 int ret;
1490 struct interface *ifp;
1491 struct zebra_if *if_data;
1492
1493 ifp = (struct interface *) vty->index;
1494 if (CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE))
1495 {
1496 ret = if_set_flags (ifp, IFF_MULTICAST);
1497 if (ret < 0)
1498 {
1499 vty_out (vty, "Can't set multicast flag%s", VTY_NEWLINE);
1500 return CMD_WARNING;
1501 }
1502 if_refresh (ifp);
1503 }
1504 if_data = ifp->info;
1505 if_data->multicast = IF_ZEBRA_MULTICAST_ON;
1506
1507 return CMD_SUCCESS;
1508 }
1509
1510 DEFUN (no_multicast,
1511 no_multicast_cmd,
1512 "no multicast",
1513 NO_STR
1514 "Unset multicast flag to interface\n")
1515 {
1516 int ret;
1517 struct interface *ifp;
1518 struct zebra_if *if_data;
1519
1520 ifp = (struct interface *) vty->index;
1521 if (CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE))
1522 {
1523 ret = if_unset_flags (ifp, IFF_MULTICAST);
1524 if (ret < 0)
1525 {
1526 vty_out (vty, "Can't unset multicast flag%s", VTY_NEWLINE);
1527 return CMD_WARNING;
1528 }
1529 if_refresh (ifp);
1530 }
1531 if_data = ifp->info;
1532 if_data->multicast = IF_ZEBRA_MULTICAST_OFF;
1533
1534 return CMD_SUCCESS;
1535 }
1536
1537 DEFUN (linkdetect,
1538 linkdetect_cmd,
1539 "link-detect",
1540 "Enable link detection on interface\n")
1541 {
1542 struct interface *ifp;
1543 int if_was_operative;
1544
1545 ifp = (struct interface *) vty->index;
1546 if_was_operative = if_is_no_ptm_operative(ifp);
1547 SET_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION);
1548
1549 /* When linkdetection is enabled, if might come down */
1550 if (!if_is_no_ptm_operative(ifp) && if_was_operative) if_down(ifp);
1551
1552 /* FIXME: Will defer status change forwarding if interface
1553 does not come down! */
1554
1555 return CMD_SUCCESS;
1556 }
1557
1558
1559 DEFUN (no_linkdetect,
1560 no_linkdetect_cmd,
1561 "no link-detect",
1562 NO_STR
1563 "Disable link detection on interface\n")
1564 {
1565 struct interface *ifp;
1566 int if_was_operative;
1567
1568 ifp = (struct interface *) vty->index;
1569 if_was_operative = if_is_no_ptm_operative(ifp);
1570 UNSET_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION);
1571
1572 /* Interface may come up after disabling link detection */
1573 if (if_is_operative(ifp) && !if_was_operative) if_up(ifp);
1574
1575 /* FIXME: see linkdetect_cmd */
1576
1577 return CMD_SUCCESS;
1578 }
1579
1580 DEFUN (shutdown_if,
1581 shutdown_if_cmd,
1582 "shutdown",
1583 "Shutdown the selected interface\n")
1584 {
1585 int ret;
1586 struct interface *ifp;
1587 struct zebra_if *if_data;
1588
1589 ifp = (struct interface *) vty->index;
1590 if (ifp->ifindex != IFINDEX_INTERNAL)
1591 {
1592 ret = if_unset_flags (ifp, IFF_UP);
1593 if (ret < 0)
1594 {
1595 vty_out (vty, "Can't shutdown interface%s", VTY_NEWLINE);
1596 return CMD_WARNING;
1597 }
1598 if_refresh (ifp);
1599 }
1600 if_data = ifp->info;
1601 if_data->shutdown = IF_ZEBRA_SHUTDOWN_ON;
1602
1603 return CMD_SUCCESS;
1604 }
1605
1606 DEFUN (no_shutdown_if,
1607 no_shutdown_if_cmd,
1608 "no shutdown",
1609 NO_STR
1610 "Shutdown the selected interface\n")
1611 {
1612 int ret;
1613 struct interface *ifp;
1614 struct zebra_if *if_data;
1615
1616 ifp = (struct interface *) vty->index;
1617
1618 if (ifp->ifindex != IFINDEX_INTERNAL)
1619 {
1620 ret = if_set_flags (ifp, IFF_UP | IFF_RUNNING);
1621 if (ret < 0)
1622 {
1623 vty_out (vty, "Can't up interface%s", VTY_NEWLINE);
1624 return CMD_WARNING;
1625 }
1626 if_refresh (ifp);
1627
1628 /* Some addresses (in particular, IPv6 addresses on Linux) get
1629 * removed when the interface goes down. They need to be readded.
1630 */
1631 if_addr_wakeup(ifp);
1632 }
1633
1634 if_data = ifp->info;
1635 if_data->shutdown = IF_ZEBRA_SHUTDOWN_OFF;
1636
1637 return CMD_SUCCESS;
1638 }
1639
1640 DEFUN (bandwidth_if,
1641 bandwidth_if_cmd,
1642 "bandwidth <1-10000000>",
1643 "Set bandwidth informational parameter\n"
1644 "Bandwidth in kilobits\n")
1645 {
1646 struct interface *ifp;
1647 unsigned int bandwidth;
1648
1649 ifp = (struct interface *) vty->index;
1650 bandwidth = strtol(argv[0], NULL, 10);
1651
1652 /* bandwidth range is <1-10000000> */
1653 if (bandwidth < 1 || bandwidth > 10000000)
1654 {
1655 vty_out (vty, "Bandwidth is invalid%s", VTY_NEWLINE);
1656 return CMD_WARNING;
1657 }
1658
1659 ifp->bandwidth = bandwidth;
1660
1661 /* force protocols to recalculate routes due to cost change */
1662 if (if_is_operative (ifp))
1663 zebra_interface_up_update (ifp);
1664
1665 return CMD_SUCCESS;
1666 }
1667
1668 DEFUN (no_bandwidth_if,
1669 no_bandwidth_if_cmd,
1670 "no bandwidth",
1671 NO_STR
1672 "Set bandwidth informational parameter\n")
1673 {
1674 struct interface *ifp;
1675
1676 ifp = (struct interface *) vty->index;
1677
1678 ifp->bandwidth = 0;
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 ALIAS (no_bandwidth_if,
1688 no_bandwidth_if_val_cmd,
1689 "no bandwidth <1-10000000>",
1690 NO_STR
1691 "Set bandwidth informational parameter\n"
1692 "Bandwidth in kilobits\n")
1693
1694 static int
1695 ip_address_install (struct vty *vty, struct interface *ifp,
1696 const char *addr_str, const char *peer_str,
1697 const char *label)
1698 {
1699 struct zebra_if *if_data;
1700 struct prefix_ipv4 cp;
1701 struct connected *ifc;
1702 struct prefix_ipv4 *p;
1703 int ret;
1704
1705 if_data = ifp->info;
1706
1707 ret = str2prefix_ipv4 (addr_str, &cp);
1708 if (ret <= 0)
1709 {
1710 vty_out (vty, "%% Malformed address %s", VTY_NEWLINE);
1711 return CMD_WARNING;
1712 }
1713
1714 if (ipv4_martian(&cp.prefix))
1715 {
1716 vty_out (vty, "%% Invalid address%s", VTY_NEWLINE);
1717 return CMD_WARNING;
1718 }
1719
1720 ifc = connected_check (ifp, (struct prefix *) &cp);
1721 if (! ifc)
1722 {
1723 ifc = connected_new ();
1724 ifc->ifp = ifp;
1725
1726 /* Address. */
1727 p = prefix_ipv4_new ();
1728 *p = cp;
1729 ifc->address = (struct prefix *) p;
1730
1731 /* Broadcast. */
1732 if (p->prefixlen <= IPV4_MAX_PREFIXLEN-2)
1733 {
1734 p = prefix_ipv4_new ();
1735 *p = cp;
1736 p->prefix.s_addr = ipv4_broadcast_addr(p->prefix.s_addr,p->prefixlen);
1737 ifc->destination = (struct prefix *) p;
1738 }
1739
1740 /* Label. */
1741 if (label)
1742 ifc->label = XSTRDUP (MTYPE_CONNECTED_LABEL, label);
1743
1744 /* Add to linked list. */
1745 listnode_add (ifp->connected, ifc);
1746 }
1747
1748 /* This address is configured from zebra. */
1749 if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED))
1750 SET_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED);
1751
1752 /* In case of this route need to install kernel. */
1753 if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_QUEUED)
1754 && CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE)
1755 && !(if_data && if_data->shutdown == IF_ZEBRA_SHUTDOWN_ON))
1756 {
1757 /* Some system need to up the interface to set IP address. */
1758 if (! if_is_up (ifp))
1759 {
1760 if_set_flags (ifp, IFF_UP | IFF_RUNNING);
1761 if_refresh (ifp);
1762 }
1763
1764 ret = if_set_prefix (ifp, ifc);
1765 if (ret < 0)
1766 {
1767 vty_out (vty, "%% Can't set interface IP address: %s.%s",
1768 safe_strerror(errno), VTY_NEWLINE);
1769 return CMD_WARNING;
1770 }
1771
1772 SET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED);
1773 /* The address will be advertised to zebra clients when the notification
1774 * from the kernel has been received.
1775 * It will also be added to the subnet chain list, then. */
1776 }
1777
1778 return CMD_SUCCESS;
1779 }
1780
1781 static int
1782 ip_address_uninstall (struct vty *vty, struct interface *ifp,
1783 const char *addr_str, const char *peer_str,
1784 const char *label)
1785 {
1786 struct prefix_ipv4 cp;
1787 struct connected *ifc;
1788 int ret;
1789
1790 /* Convert to prefix structure. */
1791 ret = str2prefix_ipv4 (addr_str, &cp);
1792 if (ret <= 0)
1793 {
1794 vty_out (vty, "%% Malformed address %s", VTY_NEWLINE);
1795 return CMD_WARNING;
1796 }
1797
1798 /* Check current interface address. */
1799 ifc = connected_check (ifp, (struct prefix *) &cp);
1800 if (! ifc)
1801 {
1802 vty_out (vty, "%% Can't find address%s", VTY_NEWLINE);
1803 return CMD_WARNING;
1804 }
1805
1806 /* This is not configured address. */
1807 if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED))
1808 return CMD_WARNING;
1809
1810 UNSET_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED);
1811
1812 /* This is not real address or interface is not active. */
1813 if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_QUEUED)
1814 || ! CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE))
1815 {
1816 listnode_delete (ifp->connected, ifc);
1817 connected_free (ifc);
1818 return CMD_WARNING;
1819 }
1820
1821 /* This is real route. */
1822 ret = if_unset_prefix (ifp, ifc);
1823 if (ret < 0)
1824 {
1825 vty_out (vty, "%% Can't unset interface IP address: %s.%s",
1826 safe_strerror(errno), VTY_NEWLINE);
1827 return CMD_WARNING;
1828 }
1829 UNSET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED);
1830 /* we will receive a kernel notification about this route being removed.
1831 * this will trigger its removal from the connected list. */
1832 return CMD_SUCCESS;
1833 }
1834
1835 DEFUN (ip_address,
1836 ip_address_cmd,
1837 "ip address A.B.C.D/M",
1838 "Interface Internet Protocol config commands\n"
1839 "Set the IP address of an interface\n"
1840 "IP address (e.g. 10.0.0.1/8)\n")
1841 {
1842 return ip_address_install (vty, vty->index, argv[0], NULL, NULL);
1843 }
1844
1845 DEFUN (no_ip_address,
1846 no_ip_address_cmd,
1847 "no ip address A.B.C.D/M",
1848 NO_STR
1849 "Interface Internet Protocol config commands\n"
1850 "Set the IP address of an interface\n"
1851 "IP Address (e.g. 10.0.0.1/8)")
1852 {
1853 return ip_address_uninstall (vty, vty->index, argv[0], NULL, NULL);
1854 }
1855
1856
1857 #ifdef HAVE_NETLINK
1858 DEFUN (ip_address_label,
1859 ip_address_label_cmd,
1860 "ip address A.B.C.D/M label LINE",
1861 "Interface Internet Protocol config commands\n"
1862 "Set the IP address of an interface\n"
1863 "IP address (e.g. 10.0.0.1/8)\n"
1864 "Label of this address\n"
1865 "Label\n")
1866 {
1867 return ip_address_install (vty, vty->index, argv[0], NULL, argv[1]);
1868 }
1869
1870 DEFUN (no_ip_address_label,
1871 no_ip_address_label_cmd,
1872 "no ip address A.B.C.D/M label LINE",
1873 NO_STR
1874 "Interface Internet Protocol config commands\n"
1875 "Set the IP address of an interface\n"
1876 "IP address (e.g. 10.0.0.1/8)\n"
1877 "Label of this address\n"
1878 "Label\n")
1879 {
1880 return ip_address_uninstall (vty, vty->index, argv[0], NULL, argv[1]);
1881 }
1882 #endif /* HAVE_NETLINK */
1883
1884 #ifdef HAVE_IPV6
1885 static int
1886 ipv6_address_install (struct vty *vty, struct interface *ifp,
1887 const char *addr_str, const char *peer_str,
1888 const char *label, int secondary)
1889 {
1890 struct zebra_if *if_data;
1891 struct prefix_ipv6 cp;
1892 struct connected *ifc;
1893 struct prefix_ipv6 *p;
1894 int ret;
1895
1896 if_data = ifp->info;
1897
1898 ret = str2prefix_ipv6 (addr_str, &cp);
1899 if (ret <= 0)
1900 {
1901 vty_out (vty, "%% Malformed address %s", VTY_NEWLINE);
1902 return CMD_WARNING;
1903 }
1904
1905 if (ipv6_martian(&cp.prefix))
1906 {
1907 vty_out (vty, "%% Invalid address%s", VTY_NEWLINE);
1908 return CMD_WARNING;
1909 }
1910
1911 ifc = connected_check (ifp, (struct prefix *) &cp);
1912 if (! ifc)
1913 {
1914 ifc = connected_new ();
1915 ifc->ifp = ifp;
1916
1917 /* Address. */
1918 p = prefix_ipv6_new ();
1919 *p = cp;
1920 ifc->address = (struct prefix *) p;
1921
1922 /* Secondary. */
1923 if (secondary)
1924 SET_FLAG (ifc->flags, ZEBRA_IFA_SECONDARY);
1925
1926 /* Label. */
1927 if (label)
1928 ifc->label = XSTRDUP (MTYPE_CONNECTED_LABEL, label);
1929
1930 /* Add to linked list. */
1931 listnode_add (ifp->connected, ifc);
1932 }
1933
1934 /* This address is configured from zebra. */
1935 if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED))
1936 SET_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED);
1937
1938 /* In case of this route need to install kernel. */
1939 if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_QUEUED)
1940 && CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE)
1941 && !(if_data && if_data->shutdown == IF_ZEBRA_SHUTDOWN_ON))
1942 {
1943 /* Some system need to up the interface to set IP address. */
1944 if (! if_is_up (ifp))
1945 {
1946 if_set_flags (ifp, IFF_UP | IFF_RUNNING);
1947 if_refresh (ifp);
1948 }
1949
1950 ret = if_prefix_add_ipv6 (ifp, ifc);
1951
1952 if (ret < 0)
1953 {
1954 vty_out (vty, "%% Can't set interface IP address: %s.%s",
1955 safe_strerror(errno), VTY_NEWLINE);
1956 return CMD_WARNING;
1957 }
1958
1959 SET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED);
1960 /* The address will be advertised to zebra clients when the notification
1961 * from the kernel has been received. */
1962 }
1963
1964 return CMD_SUCCESS;
1965 }
1966
1967 /* Return true if an ipv6 address is configured on ifp */
1968 int
1969 ipv6_address_configured (struct interface *ifp)
1970 {
1971 struct connected *connected;
1972 struct listnode *node;
1973
1974 for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, connected))
1975 if (CHECK_FLAG (connected->conf, ZEBRA_IFC_REAL) && (connected->address->family == AF_INET6))
1976 return 1;
1977
1978 return 0;
1979 }
1980
1981 static int
1982 ipv6_address_uninstall (struct vty *vty, struct interface *ifp,
1983 const char *addr_str, const char *peer_str,
1984 const char *label, int secondry)
1985 {
1986 struct prefix_ipv6 cp;
1987 struct connected *ifc;
1988 int ret;
1989
1990 /* Convert to prefix structure. */
1991 ret = str2prefix_ipv6 (addr_str, &cp);
1992 if (ret <= 0)
1993 {
1994 vty_out (vty, "%% Malformed address %s", VTY_NEWLINE);
1995 return CMD_WARNING;
1996 }
1997
1998 /* Check current interface address. */
1999 ifc = connected_check (ifp, (struct prefix *) &cp);
2000 if (! ifc)
2001 {
2002 vty_out (vty, "%% Can't find address%s", VTY_NEWLINE);
2003 return CMD_WARNING;
2004 }
2005
2006 /* This is not configured address. */
2007 if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED))
2008 return CMD_WARNING;
2009
2010 UNSET_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED);
2011
2012 /* This is not real address or interface is not active. */
2013 if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_QUEUED)
2014 || ! CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE))
2015 {
2016 listnode_delete (ifp->connected, ifc);
2017 connected_free (ifc);
2018 return CMD_WARNING;
2019 }
2020
2021 /* This is real route. */
2022 ret = if_prefix_delete_ipv6 (ifp, ifc);
2023 if (ret < 0)
2024 {
2025 vty_out (vty, "%% Can't unset interface IP address: %s.%s",
2026 safe_strerror(errno), VTY_NEWLINE);
2027 return CMD_WARNING;
2028 }
2029
2030 UNSET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED);
2031 /* This information will be propagated to the zclients when the
2032 * kernel notification is received. */
2033 return CMD_SUCCESS;
2034 }
2035
2036 DEFUN (ipv6_address,
2037 ipv6_address_cmd,
2038 "ipv6 address X:X::X:X/M",
2039 "Interface IPv6 config commands\n"
2040 "Set the IP address of an interface\n"
2041 "IPv6 address (e.g. 3ffe:506::1/48)\n")
2042 {
2043 return ipv6_address_install (vty, vty->index, argv[0], NULL, NULL, 0);
2044 }
2045
2046 DEFUN (no_ipv6_address,
2047 no_ipv6_address_cmd,
2048 "no ipv6 address X:X::X:X/M",
2049 NO_STR
2050 "Interface IPv6 config commands\n"
2051 "Set the IP address of an interface\n"
2052 "IPv6 address (e.g. 3ffe:506::1/48)\n")
2053 {
2054 return ipv6_address_uninstall (vty, vty->index, argv[0], NULL, NULL, 0);
2055 }
2056 #endif /* HAVE_IPV6 */
2057
2058 static int
2059 if_config_write (struct vty *vty)
2060 {
2061 struct listnode *node;
2062 struct interface *ifp;
2063 vrf_iter_t iter;
2064
2065 zebra_ptm_write (vty);
2066
2067 for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
2068 for (ALL_LIST_ELEMENTS_RO (vrf_iter2iflist (iter), node, ifp))
2069 {
2070 struct zebra_if *if_data;
2071 struct listnode *addrnode;
2072 struct connected *ifc;
2073 struct prefix *p;
2074 struct vrf *vrf;
2075
2076 if_data = ifp->info;
2077 vrf = vrf_lookup(ifp->vrf_id);
2078
2079 if (ifp->vrf_id == VRF_DEFAULT)
2080 vty_out (vty, "interface %s%s", ifp->name, VTY_NEWLINE);
2081 else
2082 vty_out (vty, "interface %s vrf %s%s", ifp->name, vrf->name,
2083 VTY_NEWLINE);
2084
2085 if (if_data)
2086 {
2087 if (if_data->shutdown == IF_ZEBRA_SHUTDOWN_ON)
2088 vty_out (vty, " shutdown%s", VTY_NEWLINE);
2089
2090 zebra_ptm_if_write(vty, if_data);
2091 }
2092
2093 if (ifp->desc)
2094 vty_out (vty, " description %s%s", ifp->desc,
2095 VTY_NEWLINE);
2096
2097 /* Assign bandwidth here to avoid unnecessary interface flap
2098 while processing config script */
2099 if (ifp->bandwidth != 0)
2100 vty_out(vty, " bandwidth %u%s", ifp->bandwidth, VTY_NEWLINE);
2101
2102 if (CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION))
2103 vty_out(vty, " link-detect%s", VTY_NEWLINE);
2104
2105 for (ALL_LIST_ELEMENTS_RO (ifp->connected, addrnode, ifc))
2106 {
2107 if (CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED))
2108 {
2109 char buf[INET6_ADDRSTRLEN];
2110 p = ifc->address;
2111 vty_out (vty, " ip%s address %s/%d",
2112 p->family == AF_INET ? "" : "v6",
2113 inet_ntop (p->family, &p->u.prefix, buf, sizeof(buf)),
2114 p->prefixlen);
2115
2116 if (ifc->label)
2117 vty_out (vty, " label %s", ifc->label);
2118
2119 vty_out (vty, "%s", VTY_NEWLINE);
2120 }
2121 }
2122
2123 if (if_data)
2124 {
2125 if (if_data->multicast != IF_ZEBRA_MULTICAST_UNSPEC)
2126 vty_out (vty, " %smulticast%s",
2127 if_data->multicast == IF_ZEBRA_MULTICAST_ON ? "" : "no ",
2128 VTY_NEWLINE);
2129 }
2130
2131 #if defined (HAVE_RTADV)
2132 rtadv_config_write (vty, ifp);
2133 #endif /* HAVE_RTADV */
2134
2135 #ifdef HAVE_IRDP
2136 irdp_config_write (vty, ifp);
2137 #endif /* IRDP */
2138
2139 vty_out (vty, "!%s", VTY_NEWLINE);
2140 }
2141 return 0;
2142 }
2143
2144 static int
2145 vrf_config_write (struct vty *vty)
2146 {
2147 struct listnode *node;
2148 struct zebra_vrf *zvrf;
2149
2150 for (ALL_LIST_ELEMENTS_RO (zvrf_list, node, zvrf))
2151 {
2152 if (strcmp(zvrf->name, VRF_DEFAULT_NAME))
2153 {
2154 vty_out (vty, "vrf %s%s", zvrf->name, VTY_NEWLINE);
2155 vty_out (vty, "!%s", VTY_NEWLINE);
2156 }
2157 }
2158 return 0;
2159 }
2160
2161 /* Allocate and initialize interface vector. */
2162 void
2163 zebra_if_init (void)
2164 {
2165 /* Initialize interface and new hook. */
2166 if_add_hook (IF_NEW_HOOK, if_zebra_new_hook);
2167 if_add_hook (IF_DELETE_HOOK, if_zebra_delete_hook);
2168
2169 /* Install configuration write function. */
2170 install_node (&interface_node, if_config_write);
2171 install_node (&vrf_node, vrf_config_write);
2172
2173 install_element (VIEW_NODE, &show_interface_cmd);
2174 install_element (VIEW_NODE, &show_interface_vrf_cmd);
2175 install_element (VIEW_NODE, &show_interface_vrf_all_cmd);
2176 install_element (VIEW_NODE, &show_interface_name_cmd);
2177 install_element (VIEW_NODE, &show_interface_name_vrf_cmd);
2178 install_element (VIEW_NODE, &show_interface_name_vrf_all_cmd);
2179 install_element (ENABLE_NODE, &show_interface_cmd);
2180 install_element (ENABLE_NODE, &show_interface_vrf_cmd);
2181 install_element (ENABLE_NODE, &show_interface_vrf_all_cmd);
2182 install_element (ENABLE_NODE, &show_interface_name_cmd);
2183 install_element (ENABLE_NODE, &show_interface_name_vrf_cmd);
2184 install_element (ENABLE_NODE, &show_interface_name_vrf_all_cmd);
2185 install_element (ENABLE_NODE, &show_interface_desc_cmd);
2186 install_element (ENABLE_NODE, &show_interface_desc_vrf_cmd);
2187 install_element (ENABLE_NODE, &show_interface_desc_vrf_all_cmd);
2188 install_element (CONFIG_NODE, &zebra_interface_cmd);
2189 install_element (CONFIG_NODE, &zebra_interface_vrf_cmd);
2190 install_element (CONFIG_NODE, &no_interface_cmd);
2191 install_element (CONFIG_NODE, &no_interface_vrf_cmd);
2192 install_default (INTERFACE_NODE);
2193 install_element (INTERFACE_NODE, &interface_desc_cmd);
2194 install_element (INTERFACE_NODE, &no_interface_desc_cmd);
2195 install_element (INTERFACE_NODE, &multicast_cmd);
2196 install_element (INTERFACE_NODE, &no_multicast_cmd);
2197 install_element (INTERFACE_NODE, &linkdetect_cmd);
2198 install_element (INTERFACE_NODE, &no_linkdetect_cmd);
2199 install_element (INTERFACE_NODE, &shutdown_if_cmd);
2200 install_element (INTERFACE_NODE, &no_shutdown_if_cmd);
2201 install_element (INTERFACE_NODE, &bandwidth_if_cmd);
2202 install_element (INTERFACE_NODE, &no_bandwidth_if_cmd);
2203 install_element (INTERFACE_NODE, &no_bandwidth_if_val_cmd);
2204 install_element (INTERFACE_NODE, &ip_address_cmd);
2205 install_element (INTERFACE_NODE, &no_ip_address_cmd);
2206 #ifdef HAVE_IPV6
2207 install_element (INTERFACE_NODE, &ipv6_address_cmd);
2208 install_element (INTERFACE_NODE, &no_ipv6_address_cmd);
2209 #endif /* HAVE_IPV6 */
2210 #ifdef HAVE_NETLINK
2211 install_element (INTERFACE_NODE, &ip_address_label_cmd);
2212 install_element (INTERFACE_NODE, &no_ip_address_label_cmd);
2213 #endif /* HAVE_NETLINK */
2214
2215 install_element (CONFIG_NODE, &zebra_vrf_cmd);
2216 install_element (CONFIG_NODE, &no_vrf_cmd);
2217 install_default (VRF_NODE);
2218
2219 }