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