blob: ed3ece2580d75df7040327b1d20c9658131c51c2 [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/*
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
36#include "zebra/interface.h"
37#include "zebra/rtadv.h"
38#include "zebra/rib.h"
39#include "zebra/zserv.h"
40#include "zebra/redistribute.h"
41#include "zebra/debug.h"
42
43/* Allocate a new internal interface index
44 * This works done from the top so that %d macros
45 * print a - sign!
46 */
47static unsigned int
48if_new_intern_ifindex (void)
49{
50 /* Start here so that first one assigned is 0xFFFFFFFF */
51 static unsigned int ifindex = IFINDEX_INTERNBASE + 1;
52
53 for (;;)
54 {
55 ifindex--;
56 if ( ifindex <= IFINDEX_INTERNBASE )
57 ifindex = 0xFFFFFFFF;
58
59 if (if_lookup_by_index(ifindex) == NULL)
60 return ifindex;
61 }
62}
63
64/* Called when new interface is added. */
65int
66if_zebra_new_hook (struct interface *ifp)
67{
68 struct zebra_if *zebra_if;
69
70 zebra_if = XMALLOC (MTYPE_TMP, sizeof (struct zebra_if));
71 memset (zebra_if, 0, sizeof (struct zebra_if));
72
73 zebra_if->multicast = IF_ZEBRA_MULTICAST_UNSPEC;
74 zebra_if->shutdown = IF_ZEBRA_SHUTDOWN_UNSPEC;
75
76#ifdef RTADV
77 {
78 /* Set default router advertise values. */
79 struct rtadvconf *rtadv;
80
81 rtadv = &zebra_if->rtadv;
82
83 rtadv->AdvSendAdvertisements = 0;
84 rtadv->MaxRtrAdvInterval = RTADV_MAX_RTR_ADV_INTERVAL;
85 rtadv->MinRtrAdvInterval = RTADV_MIN_RTR_ADV_INTERVAL;
86 rtadv->AdvIntervalTimer = 0;
87 rtadv->AdvManagedFlag = 0;
88 rtadv->AdvOtherConfigFlag = 0;
89 rtadv->AdvLinkMTU = 0;
90 rtadv->AdvReachableTime = 0;
91 rtadv->AdvRetransTimer = 0;
92 rtadv->AdvCurHopLimit = 0;
93 rtadv->AdvDefaultLifetime = RTADV_ADV_DEFAULT_LIFETIME;
94
95 rtadv->AdvPrefixList = list_new ();
96 }
97#endif /* RTADV */
98
99 ifp->info = zebra_if;
100 return 0;
101}
102
103/* Called when interface is deleted. */
104int
105if_zebra_delete_hook (struct interface *ifp)
106{
107 if (ifp->info)
108 XFREE (MTYPE_TMP, ifp->info);
109 return 0;
110}
111
112/* Wake up configured address if it is not in current kernel
113 address. */
114void
115if_addr_wakeup (struct interface *ifp)
116{
117 struct listnode *node;
118 struct connected *ifc;
119 struct prefix *p;
120 int ret;
121
122 for (node = listhead (ifp->connected); node; nextnode (node))
123 {
124 ifc = getdata (node);
125 p = ifc->address;
126
127 if (CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED)
128 && ! CHECK_FLAG (ifc->conf, ZEBRA_IFC_REAL))
129 {
130 /* Address check. */
131 if (p->family == AF_INET)
132 {
133 if (! if_is_up (ifp))
134 {
135 if_set_flags (ifp, IFF_UP | IFF_RUNNING);
136 if_refresh (ifp);
137 }
138
139 ret = if_set_prefix (ifp, ifc);
140 if (ret < 0)
141 {
142 zlog_warn ("Can't set interface's address: %s",
143 strerror(errno));
144 continue;
145 }
146 SET_FLAG (ifc->conf, ZEBRA_IFC_REAL);
147
148 zebra_interface_address_add_update (ifp, ifc);
149
paul2e3b2e42002-12-13 21:03:13 +0000150 if (if_is_operative(ifp))
paul718e3742002-12-13 20:15:29 +0000151 connected_up_ipv4 (ifp, ifc);
152 }
153#ifdef HAVE_IPV6
154 if (p->family == AF_INET6)
155 {
156 if (! if_is_up (ifp))
157 {
158 if_set_flags (ifp, IFF_UP | IFF_RUNNING);
159 if_refresh (ifp);
160 }
161
162 ret = if_prefix_add_ipv6 (ifp, ifc);
163 if (ret < 0)
164 {
165 zlog_warn ("Can't set interface's address: %s",
166 strerror(errno));
167 continue;
168 }
169 SET_FLAG (ifc->conf, ZEBRA_IFC_REAL);
170
171 zebra_interface_address_add_update (ifp, ifc);
172
paul2e3b2e42002-12-13 21:03:13 +0000173 if (if_is_operative(ifp))
paul718e3742002-12-13 20:15:29 +0000174 connected_up_ipv6 (ifp, ifc);
175 }
176#endif /* HAVE_IPV6 */
177 }
178 }
179}
180
181/* Handle interface addition */
182void
183if_add_update (struct interface *ifp)
184{
paul48b33aa2002-12-13 20:52:52 +0000185 struct zebra_if *if_data;
186
187 if_data = ifp->info;
188 if (if_data->multicast == IF_ZEBRA_MULTICAST_ON)
189 if_set_flags (ifp, IFF_MULTICAST);
190 else if (if_data->multicast == IF_ZEBRA_MULTICAST_OFF)
191 if_unset_flags (ifp, IFF_MULTICAST);
192
paul718e3742002-12-13 20:15:29 +0000193 zebra_interface_add_update (ifp);
194
195 if (! CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE))
196 {
197 SET_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE);
198
199 if_addr_wakeup (ifp);
200
201 if (IS_ZEBRA_DEBUG_KERNEL)
202 zlog_info ("interface %s index %d becomes active.",
203 ifp->name, ifp->ifindex);
204 }
205 else
206 {
207 if (IS_ZEBRA_DEBUG_KERNEL)
208 zlog_info ("interface %s index %d is added.", ifp->name, ifp->ifindex);
209 }
210}
211
212/* Handle an interface delete event */
213void
214if_delete_update (struct interface *ifp)
215{
216 struct listnode *node;
217 struct listnode *next;
218 struct connected *ifc;
219 struct prefix *p;
220
221 if (if_is_up(ifp))
222 {
223 zlog_err ("interface %s index %d is still up while being deleted.",
224 ifp->name, ifp->ifindex);
225 return;
226 }
227
228 /* Mark interface as inactive */
229 UNSET_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE);
230
231 if (IS_ZEBRA_DEBUG_KERNEL)
232 zlog_info ("interface %s index %d is now inactive.",
233 ifp->name, ifp->ifindex);
234
235 /* Delete connected routes from the kernel. */
236 if (ifp->connected)
237 {
238 for (node = listhead (ifp->connected); node; node = next)
239 {
240 next = node->next;
241 ifc = getdata (node);
242 p = ifc->address;
243
244 if (p->family == AF_INET)
245 connected_down_ipv4 (ifp, ifc);
246#ifdef HAVE_IPV6
247 else if (p->family == AF_INET6)
248 connected_down_ipv6 (ifp, ifc);
249#endif /* HAVE_IPV6 */
250
251 zebra_interface_address_delete_update (ifp, ifc);
252
253 UNSET_FLAG (ifc->conf, ZEBRA_IFC_REAL);
254
255 if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED))
256 {
257 listnode_delete (ifp->connected, ifc);
258 connected_free (ifc);
259 }
260 }
261 }
262 zebra_interface_delete_update (ifp);
263}
264
265/* Interface is up. */
266void
267if_up (struct interface *ifp)
268{
269 listnode node;
270 listnode next;
271 struct connected *ifc;
272 struct prefix *p;
273
274 /* Notify the protocol daemons. */
275 zebra_interface_up_update (ifp);
276
277 /* Install connected routes to the kernel. */
278 if (ifp->connected)
279 {
280 for (node = listhead (ifp->connected); node; node = next)
281 {
282 next = node->next;
283 ifc = getdata (node);
284 p = ifc->address;
285
286 if (p->family == AF_INET)
287 connected_up_ipv4 (ifp, ifc);
288#ifdef HAVE_IPV6
289 else if (p->family == AF_INET6)
290 connected_up_ipv6 (ifp, ifc);
291#endif /* HAVE_IPV6 */
292 }
293 }
294
295 /* Examine all static routes. */
296 rib_update ();
297}
298
299/* Interface goes down. We have to manage different behavior of based
300 OS. */
301void
302if_down (struct interface *ifp)
303{
304 listnode node;
305 listnode next;
306 struct connected *ifc;
307 struct prefix *p;
308
309 /* Notify to the protocol daemons. */
310 zebra_interface_down_update (ifp);
311
312 /* Delete connected routes from the kernel. */
313 if (ifp->connected)
314 {
315 for (node = listhead (ifp->connected); node; node = next)
316 {
317 next = node->next;
318 ifc = getdata (node);
319 p = ifc->address;
320
321 if (p->family == AF_INET)
322 connected_down_ipv4 (ifp, ifc);
323#ifdef HAVE_IPV6
324 else if (p->family == AF_INET6)
325 connected_down_ipv6 (ifp, ifc);
326#endif /* HAVE_IPV6 */
327 }
328 }
329
330 /* Examine all static routes which direct to the interface. */
331 rib_update ();
332}
333
334void
335if_refresh (struct interface *ifp)
336{
paul2e3b2e42002-12-13 21:03:13 +0000337 if (if_is_operative (ifp))
paul718e3742002-12-13 20:15:29 +0000338 {
339 if_get_flags (ifp);
paul2e3b2e42002-12-13 21:03:13 +0000340 if (! if_is_operative (ifp))
paul718e3742002-12-13 20:15:29 +0000341 if_down (ifp);
342 }
343 else
344 {
345 if_get_flags (ifp);
paul2e3b2e42002-12-13 21:03:13 +0000346 if (if_is_operative (ifp))
paul718e3742002-12-13 20:15:29 +0000347 if_up (ifp);
348 }
349}
350
351/* Printout flag information into vty */
352void
353if_flag_dump_vty (struct vty *vty, unsigned long flag)
354{
355 int separator = 0;
356
357#define IFF_OUT_VTY(X, Y) \
358 if ((X) && (flag & (X))) \
359 { \
360 if (separator) \
361 vty_out (vty, ","); \
362 else \
363 separator = 1; \
364 vty_out (vty, Y); \
365 }
366
367 vty_out (vty, "<");
368 IFF_OUT_VTY (IFF_UP, "UP");
369 IFF_OUT_VTY (IFF_BROADCAST, "BROADCAST");
370 IFF_OUT_VTY (IFF_DEBUG, "DEBUG");
371 IFF_OUT_VTY (IFF_LOOPBACK, "LOOPBACK");
372 IFF_OUT_VTY (IFF_POINTOPOINT, "POINTOPOINT");
373 IFF_OUT_VTY (IFF_NOTRAILERS, "NOTRAILERS");
374 IFF_OUT_VTY (IFF_RUNNING, "RUNNING");
375 IFF_OUT_VTY (IFF_NOARP, "NOARP");
376 IFF_OUT_VTY (IFF_PROMISC, "PROMISC");
377 IFF_OUT_VTY (IFF_ALLMULTI, "ALLMULTI");
378 IFF_OUT_VTY (IFF_OACTIVE, "OACTIVE");
379 IFF_OUT_VTY (IFF_SIMPLEX, "SIMPLEX");
380 IFF_OUT_VTY (IFF_LINK0, "LINK0");
381 IFF_OUT_VTY (IFF_LINK1, "LINK1");
382 IFF_OUT_VTY (IFF_LINK2, "LINK2");
383 IFF_OUT_VTY (IFF_MULTICAST, "MULTICAST");
384 vty_out (vty, ">");
385}
386
387/* Output prefix string to vty. */
388int
389prefix_vty_out (struct vty *vty, struct prefix *p)
390{
391 char str[INET6_ADDRSTRLEN];
392
393 inet_ntop (p->family, &p->u.prefix, str, sizeof (str));
394 vty_out (vty, "%s", str);
395 return strlen (str);
396}
397
398/* Dump if address information to vty. */
399void
400connected_dump_vty (struct vty *vty, struct connected *connected)
401{
402 struct prefix *p;
403 struct interface *ifp;
404
405 /* Set interface pointer. */
406 ifp = connected->ifp;
407
408 /* Print interface address. */
409 p = connected->address;
410 vty_out (vty, " %s ", prefix_family_str (p));
411 prefix_vty_out (vty, p);
412 vty_out (vty, "/%d", p->prefixlen);
413
414 /* If there is destination address, print it. */
415 p = connected->destination;
416 if (p)
417 {
418 if (p->family == AF_INET)
419 if (ifp->flags & IFF_BROADCAST)
420 {
421 vty_out (vty, " broadcast ");
422 prefix_vty_out (vty, p);
423 }
424
425 if (ifp->flags & IFF_POINTOPOINT)
426 {
427 vty_out (vty, " pointopoint ");
428 prefix_vty_out (vty, p);
429 }
430 }
431
432 if (CHECK_FLAG (connected->flags, ZEBRA_IFA_SECONDARY))
433 vty_out (vty, " secondary");
434
435 if (connected->label)
436 vty_out (vty, " %s", connected->label);
437
438 vty_out (vty, "%s", VTY_NEWLINE);
439}
440
441#ifdef RTADV
442/* Dump interface ND information to vty. */
443void
444nd_dump_vty (struct vty *vty, struct interface *ifp)
445{
446 struct zebra_if *zif;
447 struct rtadvconf *rtadv;
448
449 zif = (struct zebra_if *) ifp->info;
450 rtadv = &zif->rtadv;
451
452 if (rtadv->AdvSendAdvertisements)
453 {
454 vty_out (vty, " ND advertised reachable time is %d milliseconds%s",
455 rtadv->AdvReachableTime, VTY_NEWLINE);
456 vty_out (vty, " ND advertised retransmit interval is %d milliseconds%s",
457 rtadv->AdvRetransTimer, VTY_NEWLINE);
458 vty_out (vty, " ND router advertisements are sent every %d seconds%s",
459 rtadv->MaxRtrAdvInterval, VTY_NEWLINE);
460 vty_out (vty, " ND router advertisements live for %d seconds%s",
461 rtadv->AdvDefaultLifetime, VTY_NEWLINE);
462 if (rtadv->AdvManagedFlag)
463 vty_out (vty, " Hosts use DHCP to obtain routable addresses.%s",
464 VTY_NEWLINE);
465 else
466 vty_out (vty, " Hosts use stateless autoconfig for addresses.%s",
467 VTY_NEWLINE);
468 }
469}
470#endif /* RTADV */
471
472/* Interface's information print out to vty interface. */
473void
474if_dump_vty (struct vty *vty, struct interface *ifp)
475{
476#ifdef HAVE_SOCKADDR_DL
477 struct sockaddr_dl *sdl;
478#endif /* HAVE_SOCKADDR_DL */
479 struct connected *connected;
480 listnode node;
481
paul2e3b2e42002-12-13 21:03:13 +0000482 vty_out (vty, "Interface %s is ", ifp->name);
483 if (if_is_up(ifp)) {
484 vty_out (vty, "up, line protocol ");
485
486 if (CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION)) {
487 if (if_is_running(ifp))
488 vty_out (vty, "is up%s", VTY_NEWLINE);
489 else
490 vty_out (vty, "is down%s", VTY_NEWLINE);
491 } else {
492 vty_out (vty, "detection is disabled%s", VTY_NEWLINE);
493 }
494 } else {
495 vty_out (vty, "down%s", VTY_NEWLINE);
496 }
497
paul718e3742002-12-13 20:15:29 +0000498 if (ifp->desc)
499 vty_out (vty, " Description: %s%s", ifp->desc,
500 VTY_NEWLINE);
501 if (ifp->ifindex <= 0)
502 {
503 vty_out(vty, " index %d pseudo interface%s", ifp->ifindex, VTY_NEWLINE);
504 return;
505 }
506 else if (! CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE))
507 {
508 vty_out(vty, " index %d inactive interface%s",
509 ifp->ifindex,
510 VTY_NEWLINE);
511 return;
512 }
513
514 vty_out (vty, " index %d metric %d mtu %d ",
515 ifp->ifindex, ifp->metric, ifp->mtu);
516 if_flag_dump_vty (vty, ifp->flags);
517 vty_out (vty, "%s", VTY_NEWLINE);
518
519 /* Hardware address. */
520#ifdef HAVE_SOCKADDR_DL
521 sdl = &ifp->sdl;
522 if (sdl != NULL && sdl->sdl_alen != 0)
523 {
524 int i;
525 u_char *ptr;
526
527 vty_out (vty, " HWaddr: ");
528 for (i = 0, ptr = LLADDR (sdl); i < sdl->sdl_alen; i++, ptr++)
529 vty_out (vty, "%s%02x", i == 0 ? "" : ":", *ptr);
530 vty_out (vty, "%s", VTY_NEWLINE);
531 }
532#else
533 if (ifp->hw_addr_len != 0)
534 {
535 int i;
536
537 vty_out (vty, " HWaddr: ");
538 for (i = 0; i < ifp->hw_addr_len; i++)
539 vty_out (vty, "%s%02x", i == 0 ? "" : ":", ifp->hw_addr[i]);
540 vty_out (vty, "%s", VTY_NEWLINE);
541 }
542#endif /* HAVE_SOCKADDR_DL */
543
544 /* Bandwidth in kbps */
545 if (ifp->bandwidth != 0)
546 {
547 vty_out(vty, " bandwidth %u kbps", ifp->bandwidth);
548 vty_out(vty, "%s", VTY_NEWLINE);
549 }
550
551 for (node = listhead (ifp->connected); node; nextnode (node))
552 {
553 connected = getdata (node);
554 if (CHECK_FLAG (connected->conf, ZEBRA_IFC_REAL))
555 connected_dump_vty (vty, connected);
556 }
557
558#ifdef RTADV
559 nd_dump_vty (vty, ifp);
560#endif /* RTADV */
561
562#ifdef HAVE_PROC_NET_DEV
563 /* Statistics print out using proc file system. */
564 vty_out (vty, " input packets %lu, bytes %lu, dropped %lu,"
565 " multicast packets %lu%s",
566 ifp->stats.rx_packets, ifp->stats.rx_bytes,
567 ifp->stats.rx_dropped, ifp->stats.rx_multicast, VTY_NEWLINE);
568
569 vty_out (vty, " input errors %lu, length %lu, overrun %lu,"
570 " CRC %lu, frame %lu, fifo %lu, missed %lu%s",
571 ifp->stats.rx_errors, ifp->stats.rx_length_errors,
572 ifp->stats.rx_over_errors, ifp->stats.rx_crc_errors,
573 ifp->stats.rx_frame_errors, ifp->stats.rx_fifo_errors,
574 ifp->stats.rx_missed_errors, VTY_NEWLINE);
575
576 vty_out (vty, " output packets %lu, bytes %lu, dropped %lu%s",
577 ifp->stats.tx_packets, ifp->stats.tx_bytes,
578 ifp->stats.tx_dropped, VTY_NEWLINE);
579
580 vty_out (vty, " output errors %lu, aborted %lu, carrier %lu,"
581 " fifo %lu, heartbeat %lu, window %lu%s",
582 ifp->stats.tx_errors, ifp->stats.tx_aborted_errors,
583 ifp->stats.tx_carrier_errors, ifp->stats.tx_fifo_errors,
584 ifp->stats.tx_heartbeat_errors, ifp->stats.tx_window_errors,
585 VTY_NEWLINE);
586
587 vty_out (vty, " collisions %lu%s", ifp->stats.collisions, VTY_NEWLINE);
588#endif /* HAVE_PROC_NET_DEV */
589
590#ifdef HAVE_NET_RT_IFLIST
591#if defined (__bsdi__) || defined (__NetBSD__)
592 /* Statistics print out using sysctl (). */
593 vty_out (vty, " input packets %qu, bytes %qu, dropped %qu,"
594 " multicast packets %qu%s",
595 ifp->stats.ifi_ipackets, ifp->stats.ifi_ibytes,
596 ifp->stats.ifi_iqdrops, ifp->stats.ifi_imcasts,
597 VTY_NEWLINE);
598
599 vty_out (vty, " input errors %qu%s",
600 ifp->stats.ifi_ierrors, VTY_NEWLINE);
601
602 vty_out (vty, " output packets %qu, bytes %qu, multicast packets %qu%s",
603 ifp->stats.ifi_opackets, ifp->stats.ifi_obytes,
604 ifp->stats.ifi_omcasts, VTY_NEWLINE);
605
606 vty_out (vty, " output errors %qu%s",
607 ifp->stats.ifi_oerrors, VTY_NEWLINE);
608
609 vty_out (vty, " collisions %qu%s",
610 ifp->stats.ifi_collisions, VTY_NEWLINE);
611#else
612 /* Statistics print out using sysctl (). */
613 vty_out (vty, " input packets %lu, bytes %lu, dropped %lu,"
614 " multicast packets %lu%s",
615 ifp->stats.ifi_ipackets, ifp->stats.ifi_ibytes,
616 ifp->stats.ifi_iqdrops, ifp->stats.ifi_imcasts,
617 VTY_NEWLINE);
618
619 vty_out (vty, " input errors %lu%s",
620 ifp->stats.ifi_ierrors, VTY_NEWLINE);
621
622 vty_out (vty, " output packets %lu, bytes %lu, multicast packets %lu%s",
623 ifp->stats.ifi_opackets, ifp->stats.ifi_obytes,
624 ifp->stats.ifi_omcasts, VTY_NEWLINE);
625
626 vty_out (vty, " output errors %lu%s",
627 ifp->stats.ifi_oerrors, VTY_NEWLINE);
628
629 vty_out (vty, " collisions %lu%s",
630 ifp->stats.ifi_collisions, VTY_NEWLINE);
631#endif /* __bsdi__ || __NetBSD__ */
632#endif /* HAVE_NET_RT_IFLIST */
633}
634
635/* Check supported address family. */
636int
637if_supported_family (int family)
638{
639 if (family == AF_INET)
640 return 1;
641#ifdef HAVE_IPV6
642 if (family == AF_INET6)
643 return 1;
644#endif /* HAVE_IPV6 */
645 return 0;
646}
647
648/* Wrapper hook point for zebra daemon so that ifindex can be set
649 * DEFUN macro not used as extract.pl HAS to ignore this
650 * See also interface_cmd in lib/if.c
651 */
652DEFUN_NOSH (zebra_interface,
653 zebra_interface_cmd,
654 "interface IFNAME",
655 "Select an interface to configure\n"
656 "Interface's name\n")
657{
658 int ret;
659 struct interface * ifp;
660
661 /* Call lib interface() */
662 ret = interface_cmd.func (self, vty, argc, argv);
663
664 ifp = vty->index;
665
666 /* Set ifindex
667 this only happens if interface is NOT in kernel */
668 if (ifp->ifindex == 0)
669 {
670 ifp->ifindex = if_new_intern_ifindex ();
671 UNSET_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE);
672 }
673
674 return ret;
675}
676
677DEFUN (no_zebra_interface,
678 no_zebra_interface_cmd,
679 "no interface IFNAME",
680 "Delete a pseudo interface's configuration\n"
681 "Interface's name\n")
682{
683 struct interface *ifp;
684
685 ifp = if_lookup_by_name(argv[0]);
686
687 if (ifp == NULL)
688 {
689 vty_out (vty, "Inteface %s does not exist%s",
690 argv[0],
691 VTY_NEWLINE);
692 return CMD_WARNING;
693 }
694
695 if (CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE))
696 {
697 vty_out(vty, "Only inactive interfaces can be deleted%s", VTY_NEWLINE);
698 return CMD_WARNING;
699 }
700
701 /* Delete interface */
702 if_delete(ifp);
703
704 return CMD_SUCCESS;
705}
706
707struct cmd_node interface_node =
708{
709 INTERFACE_NODE,
710 "%s(config-if)# ",
711 1
712};
713
714/* Show all or specified interface to vty. */
715DEFUN (show_interface, show_interface_cmd,
716 "show interface [IFNAME]",
717 SHOW_STR
718 "Interface status and configuration\n"
719 "Inteface name\n")
720{
721 listnode node;
722 struct interface *ifp;
723
724#ifdef HAVE_PROC_NET_DEV
725 /* If system has interface statistics via proc file system, update
726 statistics. */
727 ifstat_update_proc ();
728#endif /* HAVE_PROC_NET_DEV */
729#ifdef HAVE_NET_RT_IFLIST
730 ifstat_update_sysctl ();
731#endif /* HAVE_NET_RT_IFLIST */
732
733 /* Specified interface print. */
734 if (argc != 0)
735 {
736 ifp = if_lookup_by_name (argv[0]);
737 if (ifp == NULL)
738 {
739 vty_out (vty, "%% Can't find interface %s%s", argv[0],
740 VTY_NEWLINE);
741 return CMD_WARNING;
742 }
743 if_dump_vty (vty, ifp);
744 return CMD_SUCCESS;
745 }
746
747 /* All interface print. */
748 for (node = listhead (iflist); node; nextnode (node))
749 if_dump_vty (vty, getdata (node));
750
751 return CMD_SUCCESS;
752}
753
754DEFUN (multicast,
755 multicast_cmd,
756 "multicast",
757 "Set multicast flag to interface\n")
758{
759 int ret;
760 struct interface *ifp;
761 struct zebra_if *if_data;
762
763 ifp = (struct interface *) vty->index;
paul48b33aa2002-12-13 20:52:52 +0000764 if (CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE))
paul718e3742002-12-13 20:15:29 +0000765 {
paul48b33aa2002-12-13 20:52:52 +0000766 ret = if_set_flags (ifp, IFF_MULTICAST);
767 if (ret < 0)
768 {
769 vty_out (vty, "Can't set multicast flag%s", VTY_NEWLINE);
770 return CMD_WARNING;
771 }
772 if_refresh (ifp);
paul718e3742002-12-13 20:15:29 +0000773 }
paul718e3742002-12-13 20:15:29 +0000774 if_data = ifp->info;
775 if_data->multicast = IF_ZEBRA_MULTICAST_ON;
paul48b33aa2002-12-13 20:52:52 +0000776
paul718e3742002-12-13 20:15:29 +0000777 return CMD_SUCCESS;
778}
779
780DEFUN (no_multicast,
781 no_multicast_cmd,
782 "no multicast",
783 NO_STR
784 "Unset multicast flag to interface\n")
785{
786 int ret;
787 struct interface *ifp;
788 struct zebra_if *if_data;
789
790 ifp = (struct interface *) vty->index;
paul48b33aa2002-12-13 20:52:52 +0000791 if (CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE))
paul718e3742002-12-13 20:15:29 +0000792 {
paul48b33aa2002-12-13 20:52:52 +0000793 ret = if_unset_flags (ifp, IFF_MULTICAST);
794 if (ret < 0)
795 {
796 vty_out (vty, "Can't unset multicast flag%s", VTY_NEWLINE);
797 return CMD_WARNING;
798 }
799 if_refresh (ifp);
paul718e3742002-12-13 20:15:29 +0000800 }
paul718e3742002-12-13 20:15:29 +0000801 if_data = ifp->info;
802 if_data->multicast = IF_ZEBRA_MULTICAST_OFF;
803
804 return CMD_SUCCESS;
805}
806
paul2e3b2e42002-12-13 21:03:13 +0000807DEFUN (linkdetect,
808 linkdetect_cmd,
809 "link-detect",
810 "Enable link detection on interface\n")
811{
paul2e3b2e42002-12-13 21:03:13 +0000812 struct interface *ifp;
813 int if_was_operative;
814
815 ifp = (struct interface *) vty->index;
816 if_was_operative = if_is_operative(ifp);
817 SET_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION);
818
819 /* When linkdetection is enabled, if might come down */
820 if (!if_is_operative(ifp) && if_was_operative) if_down(ifp);
821
822 /* FIXME: Will defer status change forwarding if interface
823 does not come down! */
824
825 return CMD_SUCCESS;
826}
827
828
829DEFUN (no_linkdetect,
830 no_linkdetect_cmd,
831 "no link-detect",
832 NO_STR
833 "Disable link detection on interface\n")
834{
paul2e3b2e42002-12-13 21:03:13 +0000835 struct interface *ifp;
836 int if_was_operative;
837
838 ifp = (struct interface *) vty->index;
839 if_was_operative = if_is_operative(ifp);
840 UNSET_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION);
841
842 /* Interface may come up after disabling link detection */
843 if (if_is_operative(ifp) && !if_was_operative) if_up(ifp);
844
845 /* FIXME: see linkdetect_cmd */
846
847 return CMD_SUCCESS;
848}
849
paul718e3742002-12-13 20:15:29 +0000850DEFUN (shutdown_if,
851 shutdown_if_cmd,
852 "shutdown",
853 "Shutdown the selected interface\n")
854{
855 int ret;
856 struct interface *ifp;
857 struct zebra_if *if_data;
858
859 ifp = (struct interface *) vty->index;
860 ret = if_unset_flags (ifp, IFF_UP);
861 if (ret < 0)
862 {
863 vty_out (vty, "Can't shutdown interface%s", VTY_NEWLINE);
864 return CMD_WARNING;
865 }
866 if_refresh (ifp);
867 if_data = ifp->info;
868 if_data->shutdown = IF_ZEBRA_SHUTDOWN_ON;
869
870 return CMD_SUCCESS;
871}
872
873DEFUN (no_shutdown_if,
874 no_shutdown_if_cmd,
875 "no shutdown",
876 NO_STR
877 "Shutdown the selected interface\n")
878{
879 int ret;
880 struct interface *ifp;
881 struct zebra_if *if_data;
882
883 ifp = (struct interface *) vty->index;
884 ret = if_set_flags (ifp, IFF_UP | IFF_RUNNING);
885 if (ret < 0)
886 {
887 vty_out (vty, "Can't up interface%s", VTY_NEWLINE);
888 return CMD_WARNING;
889 }
890 if_refresh (ifp);
891 if_data = ifp->info;
892 if_data->shutdown = IF_ZEBRA_SHUTDOWN_OFF;
893
894 return CMD_SUCCESS;
895}
896
897DEFUN (bandwidth_if,
898 bandwidth_if_cmd,
899 "bandwidth <1-10000000>",
900 "Set bandwidth informational parameter\n"
901 "Bandwidth in kilobits\n")
902{
903 struct interface *ifp;
904 unsigned int bandwidth;
905
906 ifp = (struct interface *) vty->index;
907 bandwidth = strtol(argv[0], NULL, 10);
908
909 /* bandwidth range is <1-10000000> */
910 if (bandwidth < 1 || bandwidth > 10000000)
911 {
912 vty_out (vty, "Bandwidth is invalid%s", VTY_NEWLINE);
913 return CMD_WARNING;
914 }
915
916 ifp->bandwidth = bandwidth;
917
918 /* force protocols to recalculate routes due to cost change */
paul2e3b2e42002-12-13 21:03:13 +0000919 if (if_is_operative (ifp))
paul718e3742002-12-13 20:15:29 +0000920 zebra_interface_up_update (ifp);
921
922 return CMD_SUCCESS;
923}
924
925DEFUN (no_bandwidth_if,
926 no_bandwidth_if_cmd,
927 "no bandwidth",
928 NO_STR
929 "Set bandwidth informational parameter\n")
930{
931 struct interface *ifp;
932
933 ifp = (struct interface *) vty->index;
934
935 ifp->bandwidth = 0;
936
937 /* force protocols to recalculate routes due to cost change */
paul2e3b2e42002-12-13 21:03:13 +0000938 if (if_is_operative (ifp))
paul718e3742002-12-13 20:15:29 +0000939 zebra_interface_up_update (ifp);
940
941 return CMD_SUCCESS;
942}
943
944ALIAS (no_bandwidth_if,
945 no_bandwidth_if_val_cmd,
946 "no bandwidth <1-10000000>",
947 NO_STR
948 "Set bandwidth informational parameter\n"
949 "Bandwidth in kilobits\n")
950
951int
952ip_address_install (struct vty *vty, struct interface *ifp, char *addr_str,
953 char *peer_str, char *label, int secondary)
954{
955 struct prefix_ipv4 cp;
956 struct connected *ifc;
957 struct prefix_ipv4 *p;
958 struct in_addr mask;
959 int ret;
960
961 ret = str2prefix_ipv4 (addr_str, &cp);
962 if (ret <= 0)
963 {
964 vty_out (vty, "%% Malformed address %s", VTY_NEWLINE);
965 return CMD_WARNING;
966 }
967
968 ifc = connected_check_ipv4 (ifp, (struct prefix *) &cp);
969 if (! ifc)
970 {
971 ifc = connected_new ();
972 ifc->ifp = ifp;
973
974 /* Address. */
975 p = prefix_ipv4_new ();
976 *p = cp;
977 ifc->address = (struct prefix *) p;
978
979 /* Broadcast. */
980 if (p->prefixlen <= 30)
981 {
982 p = prefix_ipv4_new ();
983 *p = cp;
984 masklen2ip (p->prefixlen, &mask);
985 p->prefix.s_addr |= ~mask.s_addr;
986 ifc->destination = (struct prefix *) p;
987 }
988
989 /* Secondary. */
990 if (secondary)
991 SET_FLAG (ifc->flags, ZEBRA_IFA_SECONDARY);
992
993 /* Label. */
994 if (label)
995 ifc->label = strdup (label);
996
997 /* Add to linked list. */
998 listnode_add (ifp->connected, ifc);
999 }
1000
1001 /* This address is configured from zebra. */
1002 if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED))
1003 SET_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED);
1004
1005 /* In case of this route need to install kernel. */
1006 if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_REAL)
1007 && CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE))
1008 {
1009 /* Some system need to up the interface to set IP address. */
1010 if (! if_is_up (ifp))
1011 {
1012 if_set_flags (ifp, IFF_UP | IFF_RUNNING);
1013 if_refresh (ifp);
1014 }
1015
1016 ret = if_set_prefix (ifp, ifc);
1017 if (ret < 0)
1018 {
1019 vty_out (vty, "%% Can't set interface IP address: %s.%s",
1020 strerror(errno), VTY_NEWLINE);
1021 return CMD_WARNING;
1022 }
1023
1024 /* IP address propery set. */
1025 SET_FLAG (ifc->conf, ZEBRA_IFC_REAL);
1026
1027 /* Update interface address information to protocol daemon. */
1028 zebra_interface_address_add_update (ifp, ifc);
1029
1030 /* If interface is up register connected route. */
paul2e3b2e42002-12-13 21:03:13 +00001031 if (if_is_operative(ifp))
paul718e3742002-12-13 20:15:29 +00001032 connected_up_ipv4 (ifp, ifc);
1033 }
1034
1035 return CMD_SUCCESS;
1036}
1037
1038int
1039ip_address_uninstall (struct vty *vty, struct interface *ifp, char *addr_str,
1040 char *peer_str, char *label, int secondry)
1041{
1042 struct prefix_ipv4 cp;
1043 struct connected *ifc;
1044 int ret;
1045
1046 /* Convert to prefix structure. */
1047 ret = str2prefix_ipv4 (addr_str, &cp);
1048 if (ret <= 0)
1049 {
1050 vty_out (vty, "%% Malformed address %s", VTY_NEWLINE);
1051 return CMD_WARNING;
1052 }
1053
1054 /* Check current interface address. */
1055 ifc = connected_check_ipv4 (ifp, (struct prefix *) &cp);
1056 if (! ifc)
1057 {
1058 vty_out (vty, "%% Can't find address%s", VTY_NEWLINE);
1059 return CMD_WARNING;
1060 }
1061
1062 /* This is not configured address. */
1063 if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED))
1064 return CMD_WARNING;
1065
1066 /* This is not real address or interface is not active. */
1067 if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_REAL)
1068 || ! CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE))
1069 {
1070 listnode_delete (ifp->connected, ifc);
1071 connected_free (ifc);
1072 return CMD_WARNING;
1073 }
1074
1075 /* This is real route. */
1076 ret = if_unset_prefix (ifp, ifc);
1077 if (ret < 0)
1078 {
1079 vty_out (vty, "%% Can't unset interface IP address: %s.%s",
1080 strerror(errno), VTY_NEWLINE);
1081 return CMD_WARNING;
1082 }
1083
1084 /* Redistribute this information. */
1085 zebra_interface_address_delete_update (ifp, ifc);
1086
1087 /* Remove connected route. */
1088 connected_down_ipv4 (ifp, ifc);
1089
1090 /* Free address information. */
1091 listnode_delete (ifp->connected, ifc);
1092 connected_free (ifc);
1093
1094 return CMD_SUCCESS;
1095}
1096
1097DEFUN (ip_address,
1098 ip_address_cmd,
1099 "ip address A.B.C.D/M",
1100 "Interface Internet Protocol config commands\n"
1101 "Set the IP address of an interface\n"
1102 "IP address (e.g. 10.0.0.1/8)\n")
1103{
1104 return ip_address_install (vty, vty->index, argv[0], NULL, NULL, 0);
1105}
1106
1107DEFUN (no_ip_address,
1108 no_ip_address_cmd,
1109 "no ip address A.B.C.D/M",
1110 NO_STR
1111 "Interface Internet Protocol config commands\n"
1112 "Set the IP address of an interface\n"
1113 "IP Address (e.g. 10.0.0.1/8)")
1114{
1115 return ip_address_uninstall (vty, vty->index, argv[0], NULL, NULL, 0);
1116}
1117
1118#ifdef HAVE_NETLINK
1119DEFUN (ip_address_secondary,
1120 ip_address_secondary_cmd,
1121 "ip address A.B.C.D/M secondary",
1122 "Interface Internet Protocol config commands\n"
1123 "Set the IP address of an interface\n"
1124 "IP address (e.g. 10.0.0.1/8)\n"
1125 "Secondary IP address\n")
1126{
1127 return ip_address_install (vty, vty->index, argv[0], NULL, NULL, 1);
1128}
1129
1130DEFUN (ip_address_label,
1131 ip_address_label_cmd,
1132 "ip address A.B.C.D/M label LINE",
1133 "Interface Internet Protocol config commands\n"
1134 "Set the IP address of an interface\n"
1135 "IP address (e.g. 10.0.0.1/8)\n"
1136 "Label of this address\n"
1137 "Label\n")
1138{
1139 return ip_address_install (vty, vty->index, argv[0], NULL, argv[1], 1);
1140}
1141
1142DEFUN (no_ip_address_secondary,
1143 no_ip_address_secondary_cmd,
1144 "no ip address A.B.C.D/M secondary",
1145 NO_STR
1146 "Interface Internet Protocol config commands\n"
1147 "Set the IP address of an interface\n"
1148 "IP address (e.g. 10.0.0.1/8)\n"
1149 "Secondary IP address\n")
1150{
1151 return ip_address_uninstall (vty, vty->index, argv[0], NULL, NULL, 1);
1152}
1153
1154DEFUN (no_ip_address_label,
1155 no_ip_address_label_cmd,
1156 "no ip address A.B.C.D/M label LINE",
1157 NO_STR
1158 "Interface Internet Protocol config commands\n"
1159 "Set the IP address of an interface\n"
1160 "IP address (e.g. 10.0.0.1/8)\n"
1161 "Label of this address\n"
1162 "Label\n")
1163{
1164 return ip_address_uninstall (vty, vty->index, argv[0], NULL, argv[1], 1);
1165}
1166#endif /* HAVE_NETLINK */
1167
1168#ifdef HAVE_IPV6
1169int
1170ipv6_address_install (struct vty *vty, struct interface *ifp, char *addr_str,
1171 char *peer_str, char *label, int secondary)
1172{
1173 struct prefix_ipv6 cp;
1174 struct connected *ifc;
1175 struct prefix_ipv6 *p;
1176 int ret;
1177
1178 ret = str2prefix_ipv6 (addr_str, &cp);
1179 if (ret <= 0)
1180 {
1181 vty_out (vty, "%% Malformed address %s", VTY_NEWLINE);
1182 return CMD_WARNING;
1183 }
1184
1185 ifc = connected_check_ipv6 (ifp, (struct prefix *) &cp);
1186 if (! ifc)
1187 {
1188 ifc = connected_new ();
1189 ifc->ifp = ifp;
1190
1191 /* Address. */
1192 p = prefix_ipv6_new ();
1193 *p = cp;
1194 ifc->address = (struct prefix *) p;
1195
1196 /* Secondary. */
1197 if (secondary)
1198 SET_FLAG (ifc->flags, ZEBRA_IFA_SECONDARY);
1199
1200 /* Label. */
1201 if (label)
1202 ifc->label = strdup (label);
1203
1204 /* Add to linked list. */
1205 listnode_add (ifp->connected, ifc);
1206 }
1207
1208 /* This address is configured from zebra. */
1209 if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED))
1210 SET_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED);
1211
1212 /* In case of this route need to install kernel. */
1213 if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_REAL)
1214 && CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE))
1215 {
1216 /* Some system need to up the interface to set IP address. */
1217 if (! if_is_up (ifp))
1218 {
1219 if_set_flags (ifp, IFF_UP | IFF_RUNNING);
1220 if_refresh (ifp);
1221 }
1222
1223 ret = if_prefix_add_ipv6 (ifp, ifc);
1224
1225 if (ret < 0)
1226 {
1227 vty_out (vty, "%% Can't set interface IP address: %s.%s",
1228 strerror(errno), VTY_NEWLINE);
1229 return CMD_WARNING;
1230 }
1231
1232 /* IP address propery set. */
1233 SET_FLAG (ifc->conf, ZEBRA_IFC_REAL);
1234
1235 /* Update interface address information to protocol daemon. */
1236 zebra_interface_address_add_update (ifp, ifc);
1237
1238 /* If interface is up register connected route. */
paul2e3b2e42002-12-13 21:03:13 +00001239 if (if_is_operative(ifp))
paul718e3742002-12-13 20:15:29 +00001240 connected_up_ipv6 (ifp, ifc);
1241 }
1242
1243 return CMD_SUCCESS;
1244}
1245
1246int
1247ipv6_address_uninstall (struct vty *vty, struct interface *ifp, char *addr_str,
1248 char *peer_str, char *label, int secondry)
1249{
1250 struct prefix_ipv6 cp;
1251 struct connected *ifc;
1252 int ret;
1253
1254 /* Convert to prefix structure. */
1255 ret = str2prefix_ipv6 (addr_str, &cp);
1256 if (ret <= 0)
1257 {
1258 vty_out (vty, "%% Malformed address %s", VTY_NEWLINE);
1259 return CMD_WARNING;
1260 }
1261
1262 /* Check current interface address. */
1263 ifc = connected_check_ipv6 (ifp, (struct prefix *) &cp);
1264 if (! ifc)
1265 {
1266 vty_out (vty, "%% Can't find address%s", VTY_NEWLINE);
1267 return CMD_WARNING;
1268 }
1269
1270 /* This is not configured address. */
1271 if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED))
1272 return CMD_WARNING;
1273
1274 /* This is not real address or interface is not active. */
1275 if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_REAL)
1276 || ! CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE))
1277 {
1278 listnode_delete (ifp->connected, ifc);
1279 connected_free (ifc);
1280 return CMD_WARNING;
1281 }
1282
1283 /* This is real route. */
1284 ret = if_prefix_delete_ipv6 (ifp, ifc);
1285 if (ret < 0)
1286 {
1287 vty_out (vty, "%% Can't unset interface IP address: %s.%s",
1288 strerror(errno), VTY_NEWLINE);
1289 return CMD_WARNING;
1290 }
1291
1292 /* Redistribute this information. */
1293 zebra_interface_address_delete_update (ifp, ifc);
1294
1295 /* Remove connected route. */
1296 connected_down_ipv6 (ifp, ifc);
1297
1298 /* Free address information. */
1299 listnode_delete (ifp->connected, ifc);
1300 connected_free (ifc);
1301
1302 return CMD_SUCCESS;
1303}
1304
1305DEFUN (ipv6_address,
1306 ipv6_address_cmd,
1307 "ipv6 address X:X::X:X/M",
1308 "Interface Internet Protocol config commands\n"
1309 "Set the IP address of an interface\n"
1310 "IPv6 address (e.g. 3ffe:506::1/48)\n")
1311{
1312 return ipv6_address_install (vty, vty->index, argv[0], NULL, NULL, 0);
1313}
1314
1315DEFUN (no_ipv6_address,
1316 no_ipv6_address_cmd,
1317 "no ipv6 address X:X::X:X/M",
1318 NO_STR
1319 "Interface Internet Protocol config commands\n"
1320 "Set the IP address of an interface\n"
1321 "IPv6 address (e.g. 3ffe:506::1/48)\n")
1322{
1323 return ipv6_address_uninstall (vty, vty->index, argv[0], NULL, NULL, 0);
1324}
1325#endif /* HAVE_IPV6 */
1326
1327#ifdef KAME
1328DEFUN (ip_tunnel,
1329 ip_tunnel_cmd,
1330 "ip tunnel IP_address IP_address",
1331 "KAME ip tunneling configuration commands\n"
1332 "Set FROM IP address and TO IP address\n")
1333{
1334 return CMD_SUCCESS;
1335}
1336
1337DEFUN (no_ip_tunnel, no_ip_tunnel_cmd,
1338 "no ip tunnel",
1339 NO_STR
1340 "Set FROM IP address and TO IP address\n")
1341{
1342 return CMD_SUCCESS;
1343}
1344#endif /* KAME */
1345
1346int
1347if_config_write (struct vty *vty)
1348{
1349 listnode node;
1350 struct interface *ifp;
1351 char buf[BUFSIZ];
1352
1353 for (node = listhead (iflist); node; nextnode (node))
1354 {
1355 struct zebra_if *if_data;
1356 listnode addrnode;
1357 struct connected *ifc;
1358 struct prefix *p;
1359
1360 ifp = getdata (node);
1361 if_data = ifp->info;
1362
1363 vty_out (vty, "interface %s%s", ifp->name,
1364 VTY_NEWLINE);
1365
1366 if (ifp->desc)
1367 vty_out (vty, " description %s%s", ifp->desc,
1368 VTY_NEWLINE);
1369
1370 /* Assign bandwidth here to avoid unnecessary interface flap
1371 while processing config script */
1372 if (ifp->bandwidth != 0)
1373 vty_out(vty, " bandwidth %u%s", ifp->bandwidth, VTY_NEWLINE);
1374
paul2e3b2e42002-12-13 21:03:13 +00001375 if (CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION))
1376 vty_out(vty, " link-detect%s", VTY_NEWLINE);
1377
paul718e3742002-12-13 20:15:29 +00001378 for (addrnode = listhead (ifp->connected); addrnode; nextnode (addrnode))
1379 {
1380 ifc = getdata (addrnode);
1381 if (CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED))
1382 {
1383 p = ifc->address;
1384 vty_out (vty, " ip%s address %s/%d",
1385 p->family == AF_INET ? "" : "v6",
1386 inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
1387 p->prefixlen);
1388
1389 if (CHECK_FLAG (ifc->flags, ZEBRA_IFA_SECONDARY))
1390 vty_out (vty, " secondary");
1391
1392 if (ifc->label)
1393 vty_out (vty, " label %s", ifc->label);
1394
1395 vty_out (vty, "%s", VTY_NEWLINE);
1396 }
1397 }
1398
1399 if (if_data)
1400 {
1401 if (if_data->shutdown == IF_ZEBRA_SHUTDOWN_ON)
1402 vty_out (vty, " shutdown%s", VTY_NEWLINE);
1403
1404 if (if_data->multicast != IF_ZEBRA_MULTICAST_UNSPEC)
1405 vty_out (vty, " %smulticast%s",
1406 if_data->multicast == IF_ZEBRA_MULTICAST_ON ? "" : "no ",
1407 VTY_NEWLINE);
1408 }
1409
1410#ifdef RTADV
1411 rtadv_config_write (vty, ifp);
1412#endif /* RTADV */
1413
1414 vty_out (vty, "!%s", VTY_NEWLINE);
1415 }
1416 return 0;
1417}
1418
1419/* Allocate and initialize interface vector. */
1420void
1421zebra_if_init ()
1422{
1423 /* Initialize interface and new hook. */
1424 if_init ();
1425 if_add_hook (IF_NEW_HOOK, if_zebra_new_hook);
1426 if_add_hook (IF_DELETE_HOOK, if_zebra_delete_hook);
1427
1428 /* Install configuration write function. */
1429 install_node (&interface_node, if_config_write);
1430
1431 install_element (VIEW_NODE, &show_interface_cmd);
1432 install_element (ENABLE_NODE, &show_interface_cmd);
1433 install_element (CONFIG_NODE, &zebra_interface_cmd);
1434 install_element (CONFIG_NODE, &no_zebra_interface_cmd);
1435 install_default (INTERFACE_NODE);
1436 install_element (INTERFACE_NODE, &interface_desc_cmd);
1437 install_element (INTERFACE_NODE, &no_interface_desc_cmd);
1438 install_element (INTERFACE_NODE, &multicast_cmd);
1439 install_element (INTERFACE_NODE, &no_multicast_cmd);
paul2e3b2e42002-12-13 21:03:13 +00001440 install_element (INTERFACE_NODE, &linkdetect_cmd);
1441 install_element (INTERFACE_NODE, &no_linkdetect_cmd);
paul718e3742002-12-13 20:15:29 +00001442 install_element (INTERFACE_NODE, &shutdown_if_cmd);
1443 install_element (INTERFACE_NODE, &no_shutdown_if_cmd);
1444 install_element (INTERFACE_NODE, &bandwidth_if_cmd);
1445 install_element (INTERFACE_NODE, &no_bandwidth_if_cmd);
1446 install_element (INTERFACE_NODE, &no_bandwidth_if_val_cmd);
1447 install_element (INTERFACE_NODE, &ip_address_cmd);
1448 install_element (INTERFACE_NODE, &no_ip_address_cmd);
1449#ifdef HAVE_IPV6
1450 install_element (INTERFACE_NODE, &ipv6_address_cmd);
1451 install_element (INTERFACE_NODE, &no_ipv6_address_cmd);
1452#endif /* HAVE_IPV6 */
1453#ifdef KAME
1454 install_element (INTERFACE_NODE, &ip_tunnel_cmd);
1455 install_element (INTERFACE_NODE, &no_ip_tunnel_cmd);
1456#endif /* KAME */
1457#ifdef HAVE_NETLINK
1458 install_element (INTERFACE_NODE, &ip_address_secondary_cmd);
1459 install_element (INTERFACE_NODE, &ip_address_label_cmd);
1460 install_element (INTERFACE_NODE, &no_ip_address_secondary_cmd);
1461 install_element (INTERFACE_NODE, &no_ip_address_label_cmd);
1462#endif /* HAVE_NETLINK */
1463}