blob: ac064992bd5fbf71375d0c694360923f27614933 [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{
812 int ret;
813 struct interface *ifp;
814 int if_was_operative;
815
816 ifp = (struct interface *) vty->index;
817 if_was_operative = if_is_operative(ifp);
818 SET_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION);
819
820 /* When linkdetection is enabled, if might come down */
821 if (!if_is_operative(ifp) && if_was_operative) if_down(ifp);
822
823 /* FIXME: Will defer status change forwarding if interface
824 does not come down! */
825
826 return CMD_SUCCESS;
827}
828
829
830DEFUN (no_linkdetect,
831 no_linkdetect_cmd,
832 "no link-detect",
833 NO_STR
834 "Disable link detection on interface\n")
835{
836 int ret;
837 struct interface *ifp;
838 int if_was_operative;
839
840 ifp = (struct interface *) vty->index;
841 if_was_operative = if_is_operative(ifp);
842 UNSET_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION);
843
844 /* Interface may come up after disabling link detection */
845 if (if_is_operative(ifp) && !if_was_operative) if_up(ifp);
846
847 /* FIXME: see linkdetect_cmd */
848
849 return CMD_SUCCESS;
850}
851
paul718e3742002-12-13 20:15:29 +0000852DEFUN (shutdown_if,
853 shutdown_if_cmd,
854 "shutdown",
855 "Shutdown the selected interface\n")
856{
857 int ret;
858 struct interface *ifp;
859 struct zebra_if *if_data;
860
861 ifp = (struct interface *) vty->index;
862 ret = if_unset_flags (ifp, IFF_UP);
863 if (ret < 0)
864 {
865 vty_out (vty, "Can't shutdown interface%s", VTY_NEWLINE);
866 return CMD_WARNING;
867 }
868 if_refresh (ifp);
869 if_data = ifp->info;
870 if_data->shutdown = IF_ZEBRA_SHUTDOWN_ON;
871
872 return CMD_SUCCESS;
873}
874
875DEFUN (no_shutdown_if,
876 no_shutdown_if_cmd,
877 "no shutdown",
878 NO_STR
879 "Shutdown the selected interface\n")
880{
881 int ret;
882 struct interface *ifp;
883 struct zebra_if *if_data;
884
885 ifp = (struct interface *) vty->index;
886 ret = if_set_flags (ifp, IFF_UP | IFF_RUNNING);
887 if (ret < 0)
888 {
889 vty_out (vty, "Can't up interface%s", VTY_NEWLINE);
890 return CMD_WARNING;
891 }
892 if_refresh (ifp);
893 if_data = ifp->info;
894 if_data->shutdown = IF_ZEBRA_SHUTDOWN_OFF;
895
896 return CMD_SUCCESS;
897}
898
899DEFUN (bandwidth_if,
900 bandwidth_if_cmd,
901 "bandwidth <1-10000000>",
902 "Set bandwidth informational parameter\n"
903 "Bandwidth in kilobits\n")
904{
905 struct interface *ifp;
906 unsigned int bandwidth;
907
908 ifp = (struct interface *) vty->index;
909 bandwidth = strtol(argv[0], NULL, 10);
910
911 /* bandwidth range is <1-10000000> */
912 if (bandwidth < 1 || bandwidth > 10000000)
913 {
914 vty_out (vty, "Bandwidth is invalid%s", VTY_NEWLINE);
915 return CMD_WARNING;
916 }
917
918 ifp->bandwidth = bandwidth;
919
920 /* force protocols to recalculate routes due to cost change */
paul2e3b2e42002-12-13 21:03:13 +0000921 if (if_is_operative (ifp))
paul718e3742002-12-13 20:15:29 +0000922 zebra_interface_up_update (ifp);
923
924 return CMD_SUCCESS;
925}
926
927DEFUN (no_bandwidth_if,
928 no_bandwidth_if_cmd,
929 "no bandwidth",
930 NO_STR
931 "Set bandwidth informational parameter\n")
932{
933 struct interface *ifp;
934
935 ifp = (struct interface *) vty->index;
936
937 ifp->bandwidth = 0;
938
939 /* force protocols to recalculate routes due to cost change */
paul2e3b2e42002-12-13 21:03:13 +0000940 if (if_is_operative (ifp))
paul718e3742002-12-13 20:15:29 +0000941 zebra_interface_up_update (ifp);
942
943 return CMD_SUCCESS;
944}
945
946ALIAS (no_bandwidth_if,
947 no_bandwidth_if_val_cmd,
948 "no bandwidth <1-10000000>",
949 NO_STR
950 "Set bandwidth informational parameter\n"
951 "Bandwidth in kilobits\n")
952
953int
954ip_address_install (struct vty *vty, struct interface *ifp, char *addr_str,
955 char *peer_str, char *label, int secondary)
956{
957 struct prefix_ipv4 cp;
958 struct connected *ifc;
959 struct prefix_ipv4 *p;
960 struct in_addr mask;
961 int ret;
962
963 ret = str2prefix_ipv4 (addr_str, &cp);
964 if (ret <= 0)
965 {
966 vty_out (vty, "%% Malformed address %s", VTY_NEWLINE);
967 return CMD_WARNING;
968 }
969
970 ifc = connected_check_ipv4 (ifp, (struct prefix *) &cp);
971 if (! ifc)
972 {
973 ifc = connected_new ();
974 ifc->ifp = ifp;
975
976 /* Address. */
977 p = prefix_ipv4_new ();
978 *p = cp;
979 ifc->address = (struct prefix *) p;
980
981 /* Broadcast. */
982 if (p->prefixlen <= 30)
983 {
984 p = prefix_ipv4_new ();
985 *p = cp;
986 masklen2ip (p->prefixlen, &mask);
987 p->prefix.s_addr |= ~mask.s_addr;
988 ifc->destination = (struct prefix *) p;
989 }
990
991 /* Secondary. */
992 if (secondary)
993 SET_FLAG (ifc->flags, ZEBRA_IFA_SECONDARY);
994
995 /* Label. */
996 if (label)
997 ifc->label = strdup (label);
998
999 /* Add to linked list. */
1000 listnode_add (ifp->connected, ifc);
1001 }
1002
1003 /* This address is configured from zebra. */
1004 if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED))
1005 SET_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED);
1006
1007 /* In case of this route need to install kernel. */
1008 if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_REAL)
1009 && CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE))
1010 {
1011 /* Some system need to up the interface to set IP address. */
1012 if (! if_is_up (ifp))
1013 {
1014 if_set_flags (ifp, IFF_UP | IFF_RUNNING);
1015 if_refresh (ifp);
1016 }
1017
1018 ret = if_set_prefix (ifp, ifc);
1019 if (ret < 0)
1020 {
1021 vty_out (vty, "%% Can't set interface IP address: %s.%s",
1022 strerror(errno), VTY_NEWLINE);
1023 return CMD_WARNING;
1024 }
1025
1026 /* IP address propery set. */
1027 SET_FLAG (ifc->conf, ZEBRA_IFC_REAL);
1028
1029 /* Update interface address information to protocol daemon. */
1030 zebra_interface_address_add_update (ifp, ifc);
1031
1032 /* If interface is up register connected route. */
paul2e3b2e42002-12-13 21:03:13 +00001033 if (if_is_operative(ifp))
paul718e3742002-12-13 20:15:29 +00001034 connected_up_ipv4 (ifp, ifc);
1035 }
1036
1037 return CMD_SUCCESS;
1038}
1039
1040int
1041ip_address_uninstall (struct vty *vty, struct interface *ifp, char *addr_str,
1042 char *peer_str, char *label, int secondry)
1043{
1044 struct prefix_ipv4 cp;
1045 struct connected *ifc;
1046 int ret;
1047
1048 /* Convert to prefix structure. */
1049 ret = str2prefix_ipv4 (addr_str, &cp);
1050 if (ret <= 0)
1051 {
1052 vty_out (vty, "%% Malformed address %s", VTY_NEWLINE);
1053 return CMD_WARNING;
1054 }
1055
1056 /* Check current interface address. */
1057 ifc = connected_check_ipv4 (ifp, (struct prefix *) &cp);
1058 if (! ifc)
1059 {
1060 vty_out (vty, "%% Can't find address%s", VTY_NEWLINE);
1061 return CMD_WARNING;
1062 }
1063
1064 /* This is not configured address. */
1065 if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED))
1066 return CMD_WARNING;
1067
1068 /* This is not real address or interface is not active. */
1069 if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_REAL)
1070 || ! CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE))
1071 {
1072 listnode_delete (ifp->connected, ifc);
1073 connected_free (ifc);
1074 return CMD_WARNING;
1075 }
1076
1077 /* This is real route. */
1078 ret = if_unset_prefix (ifp, ifc);
1079 if (ret < 0)
1080 {
1081 vty_out (vty, "%% Can't unset interface IP address: %s.%s",
1082 strerror(errno), VTY_NEWLINE);
1083 return CMD_WARNING;
1084 }
1085
1086 /* Redistribute this information. */
1087 zebra_interface_address_delete_update (ifp, ifc);
1088
1089 /* Remove connected route. */
1090 connected_down_ipv4 (ifp, ifc);
1091
1092 /* Free address information. */
1093 listnode_delete (ifp->connected, ifc);
1094 connected_free (ifc);
1095
1096 return CMD_SUCCESS;
1097}
1098
1099DEFUN (ip_address,
1100 ip_address_cmd,
1101 "ip address A.B.C.D/M",
1102 "Interface Internet Protocol config commands\n"
1103 "Set the IP address of an interface\n"
1104 "IP address (e.g. 10.0.0.1/8)\n")
1105{
1106 return ip_address_install (vty, vty->index, argv[0], NULL, NULL, 0);
1107}
1108
1109DEFUN (no_ip_address,
1110 no_ip_address_cmd,
1111 "no ip address A.B.C.D/M",
1112 NO_STR
1113 "Interface Internet Protocol config commands\n"
1114 "Set the IP address of an interface\n"
1115 "IP Address (e.g. 10.0.0.1/8)")
1116{
1117 return ip_address_uninstall (vty, vty->index, argv[0], NULL, NULL, 0);
1118}
1119
1120#ifdef HAVE_NETLINK
1121DEFUN (ip_address_secondary,
1122 ip_address_secondary_cmd,
1123 "ip address A.B.C.D/M secondary",
1124 "Interface Internet Protocol config commands\n"
1125 "Set the IP address of an interface\n"
1126 "IP address (e.g. 10.0.0.1/8)\n"
1127 "Secondary IP address\n")
1128{
1129 return ip_address_install (vty, vty->index, argv[0], NULL, NULL, 1);
1130}
1131
1132DEFUN (ip_address_label,
1133 ip_address_label_cmd,
1134 "ip address A.B.C.D/M label LINE",
1135 "Interface Internet Protocol config commands\n"
1136 "Set the IP address of an interface\n"
1137 "IP address (e.g. 10.0.0.1/8)\n"
1138 "Label of this address\n"
1139 "Label\n")
1140{
1141 return ip_address_install (vty, vty->index, argv[0], NULL, argv[1], 1);
1142}
1143
1144DEFUN (no_ip_address_secondary,
1145 no_ip_address_secondary_cmd,
1146 "no ip address A.B.C.D/M secondary",
1147 NO_STR
1148 "Interface Internet Protocol config commands\n"
1149 "Set the IP address of an interface\n"
1150 "IP address (e.g. 10.0.0.1/8)\n"
1151 "Secondary IP address\n")
1152{
1153 return ip_address_uninstall (vty, vty->index, argv[0], NULL, NULL, 1);
1154}
1155
1156DEFUN (no_ip_address_label,
1157 no_ip_address_label_cmd,
1158 "no ip address A.B.C.D/M label LINE",
1159 NO_STR
1160 "Interface Internet Protocol config commands\n"
1161 "Set the IP address of an interface\n"
1162 "IP address (e.g. 10.0.0.1/8)\n"
1163 "Label of this address\n"
1164 "Label\n")
1165{
1166 return ip_address_uninstall (vty, vty->index, argv[0], NULL, argv[1], 1);
1167}
1168#endif /* HAVE_NETLINK */
1169
1170#ifdef HAVE_IPV6
1171int
1172ipv6_address_install (struct vty *vty, struct interface *ifp, char *addr_str,
1173 char *peer_str, char *label, int secondary)
1174{
1175 struct prefix_ipv6 cp;
1176 struct connected *ifc;
1177 struct prefix_ipv6 *p;
1178 int ret;
1179
1180 ret = str2prefix_ipv6 (addr_str, &cp);
1181 if (ret <= 0)
1182 {
1183 vty_out (vty, "%% Malformed address %s", VTY_NEWLINE);
1184 return CMD_WARNING;
1185 }
1186
1187 ifc = connected_check_ipv6 (ifp, (struct prefix *) &cp);
1188 if (! ifc)
1189 {
1190 ifc = connected_new ();
1191 ifc->ifp = ifp;
1192
1193 /* Address. */
1194 p = prefix_ipv6_new ();
1195 *p = cp;
1196 ifc->address = (struct prefix *) p;
1197
1198 /* Secondary. */
1199 if (secondary)
1200 SET_FLAG (ifc->flags, ZEBRA_IFA_SECONDARY);
1201
1202 /* Label. */
1203 if (label)
1204 ifc->label = strdup (label);
1205
1206 /* Add to linked list. */
1207 listnode_add (ifp->connected, ifc);
1208 }
1209
1210 /* This address is configured from zebra. */
1211 if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED))
1212 SET_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED);
1213
1214 /* In case of this route need to install kernel. */
1215 if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_REAL)
1216 && CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE))
1217 {
1218 /* Some system need to up the interface to set IP address. */
1219 if (! if_is_up (ifp))
1220 {
1221 if_set_flags (ifp, IFF_UP | IFF_RUNNING);
1222 if_refresh (ifp);
1223 }
1224
1225 ret = if_prefix_add_ipv6 (ifp, ifc);
1226
1227 if (ret < 0)
1228 {
1229 vty_out (vty, "%% Can't set interface IP address: %s.%s",
1230 strerror(errno), VTY_NEWLINE);
1231 return CMD_WARNING;
1232 }
1233
1234 /* IP address propery set. */
1235 SET_FLAG (ifc->conf, ZEBRA_IFC_REAL);
1236
1237 /* Update interface address information to protocol daemon. */
1238 zebra_interface_address_add_update (ifp, ifc);
1239
1240 /* If interface is up register connected route. */
paul2e3b2e42002-12-13 21:03:13 +00001241 if (if_is_operative(ifp))
paul718e3742002-12-13 20:15:29 +00001242 connected_up_ipv6 (ifp, ifc);
1243 }
1244
1245 return CMD_SUCCESS;
1246}
1247
1248int
1249ipv6_address_uninstall (struct vty *vty, struct interface *ifp, char *addr_str,
1250 char *peer_str, char *label, int secondry)
1251{
1252 struct prefix_ipv6 cp;
1253 struct connected *ifc;
1254 int ret;
1255
1256 /* Convert to prefix structure. */
1257 ret = str2prefix_ipv6 (addr_str, &cp);
1258 if (ret <= 0)
1259 {
1260 vty_out (vty, "%% Malformed address %s", VTY_NEWLINE);
1261 return CMD_WARNING;
1262 }
1263
1264 /* Check current interface address. */
1265 ifc = connected_check_ipv6 (ifp, (struct prefix *) &cp);
1266 if (! ifc)
1267 {
1268 vty_out (vty, "%% Can't find address%s", VTY_NEWLINE);
1269 return CMD_WARNING;
1270 }
1271
1272 /* This is not configured address. */
1273 if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED))
1274 return CMD_WARNING;
1275
1276 /* This is not real address or interface is not active. */
1277 if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_REAL)
1278 || ! CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE))
1279 {
1280 listnode_delete (ifp->connected, ifc);
1281 connected_free (ifc);
1282 return CMD_WARNING;
1283 }
1284
1285 /* This is real route. */
1286 ret = if_prefix_delete_ipv6 (ifp, ifc);
1287 if (ret < 0)
1288 {
1289 vty_out (vty, "%% Can't unset interface IP address: %s.%s",
1290 strerror(errno), VTY_NEWLINE);
1291 return CMD_WARNING;
1292 }
1293
1294 /* Redistribute this information. */
1295 zebra_interface_address_delete_update (ifp, ifc);
1296
1297 /* Remove connected route. */
1298 connected_down_ipv6 (ifp, ifc);
1299
1300 /* Free address information. */
1301 listnode_delete (ifp->connected, ifc);
1302 connected_free (ifc);
1303
1304 return CMD_SUCCESS;
1305}
1306
1307DEFUN (ipv6_address,
1308 ipv6_address_cmd,
1309 "ipv6 address X:X::X:X/M",
1310 "Interface Internet Protocol config commands\n"
1311 "Set the IP address of an interface\n"
1312 "IPv6 address (e.g. 3ffe:506::1/48)\n")
1313{
1314 return ipv6_address_install (vty, vty->index, argv[0], NULL, NULL, 0);
1315}
1316
1317DEFUN (no_ipv6_address,
1318 no_ipv6_address_cmd,
1319 "no ipv6 address X:X::X:X/M",
1320 NO_STR
1321 "Interface Internet Protocol config commands\n"
1322 "Set the IP address of an interface\n"
1323 "IPv6 address (e.g. 3ffe:506::1/48)\n")
1324{
1325 return ipv6_address_uninstall (vty, vty->index, argv[0], NULL, NULL, 0);
1326}
1327#endif /* HAVE_IPV6 */
1328
1329#ifdef KAME
1330DEFUN (ip_tunnel,
1331 ip_tunnel_cmd,
1332 "ip tunnel IP_address IP_address",
1333 "KAME ip tunneling configuration commands\n"
1334 "Set FROM IP address and TO IP address\n")
1335{
1336 return CMD_SUCCESS;
1337}
1338
1339DEFUN (no_ip_tunnel, no_ip_tunnel_cmd,
1340 "no ip tunnel",
1341 NO_STR
1342 "Set FROM IP address and TO IP address\n")
1343{
1344 return CMD_SUCCESS;
1345}
1346#endif /* KAME */
1347
1348int
1349if_config_write (struct vty *vty)
1350{
1351 listnode node;
1352 struct interface *ifp;
1353 char buf[BUFSIZ];
1354
1355 for (node = listhead (iflist); node; nextnode (node))
1356 {
1357 struct zebra_if *if_data;
1358 listnode addrnode;
1359 struct connected *ifc;
1360 struct prefix *p;
1361
1362 ifp = getdata (node);
1363 if_data = ifp->info;
1364
1365 vty_out (vty, "interface %s%s", ifp->name,
1366 VTY_NEWLINE);
1367
1368 if (ifp->desc)
1369 vty_out (vty, " description %s%s", ifp->desc,
1370 VTY_NEWLINE);
1371
1372 /* Assign bandwidth here to avoid unnecessary interface flap
1373 while processing config script */
1374 if (ifp->bandwidth != 0)
1375 vty_out(vty, " bandwidth %u%s", ifp->bandwidth, VTY_NEWLINE);
1376
paul2e3b2e42002-12-13 21:03:13 +00001377 if (CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION))
1378 vty_out(vty, " link-detect%s", VTY_NEWLINE);
1379
paul718e3742002-12-13 20:15:29 +00001380 for (addrnode = listhead (ifp->connected); addrnode; nextnode (addrnode))
1381 {
1382 ifc = getdata (addrnode);
1383 if (CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED))
1384 {
1385 p = ifc->address;
1386 vty_out (vty, " ip%s address %s/%d",
1387 p->family == AF_INET ? "" : "v6",
1388 inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
1389 p->prefixlen);
1390
1391 if (CHECK_FLAG (ifc->flags, ZEBRA_IFA_SECONDARY))
1392 vty_out (vty, " secondary");
1393
1394 if (ifc->label)
1395 vty_out (vty, " label %s", ifc->label);
1396
1397 vty_out (vty, "%s", VTY_NEWLINE);
1398 }
1399 }
1400
1401 if (if_data)
1402 {
1403 if (if_data->shutdown == IF_ZEBRA_SHUTDOWN_ON)
1404 vty_out (vty, " shutdown%s", VTY_NEWLINE);
1405
1406 if (if_data->multicast != IF_ZEBRA_MULTICAST_UNSPEC)
1407 vty_out (vty, " %smulticast%s",
1408 if_data->multicast == IF_ZEBRA_MULTICAST_ON ? "" : "no ",
1409 VTY_NEWLINE);
1410 }
1411
1412#ifdef RTADV
1413 rtadv_config_write (vty, ifp);
1414#endif /* RTADV */
1415
1416 vty_out (vty, "!%s", VTY_NEWLINE);
1417 }
1418 return 0;
1419}
1420
1421/* Allocate and initialize interface vector. */
1422void
1423zebra_if_init ()
1424{
1425 /* Initialize interface and new hook. */
1426 if_init ();
1427 if_add_hook (IF_NEW_HOOK, if_zebra_new_hook);
1428 if_add_hook (IF_DELETE_HOOK, if_zebra_delete_hook);
1429
1430 /* Install configuration write function. */
1431 install_node (&interface_node, if_config_write);
1432
1433 install_element (VIEW_NODE, &show_interface_cmd);
1434 install_element (ENABLE_NODE, &show_interface_cmd);
1435 install_element (CONFIG_NODE, &zebra_interface_cmd);
1436 install_element (CONFIG_NODE, &no_zebra_interface_cmd);
1437 install_default (INTERFACE_NODE);
1438 install_element (INTERFACE_NODE, &interface_desc_cmd);
1439 install_element (INTERFACE_NODE, &no_interface_desc_cmd);
1440 install_element (INTERFACE_NODE, &multicast_cmd);
1441 install_element (INTERFACE_NODE, &no_multicast_cmd);
paul2e3b2e42002-12-13 21:03:13 +00001442 install_element (INTERFACE_NODE, &linkdetect_cmd);
1443 install_element (INTERFACE_NODE, &no_linkdetect_cmd);
paul718e3742002-12-13 20:15:29 +00001444 install_element (INTERFACE_NODE, &shutdown_if_cmd);
1445 install_element (INTERFACE_NODE, &no_shutdown_if_cmd);
1446 install_element (INTERFACE_NODE, &bandwidth_if_cmd);
1447 install_element (INTERFACE_NODE, &no_bandwidth_if_cmd);
1448 install_element (INTERFACE_NODE, &no_bandwidth_if_val_cmd);
1449 install_element (INTERFACE_NODE, &ip_address_cmd);
1450 install_element (INTERFACE_NODE, &no_ip_address_cmd);
1451#ifdef HAVE_IPV6
1452 install_element (INTERFACE_NODE, &ipv6_address_cmd);
1453 install_element (INTERFACE_NODE, &no_ipv6_address_cmd);
1454#endif /* HAVE_IPV6 */
1455#ifdef KAME
1456 install_element (INTERFACE_NODE, &ip_tunnel_cmd);
1457 install_element (INTERFACE_NODE, &no_ip_tunnel_cmd);
1458#endif /* KAME */
1459#ifdef HAVE_NETLINK
1460 install_element (INTERFACE_NODE, &ip_address_secondary_cmd);
1461 install_element (INTERFACE_NODE, &ip_address_label_cmd);
1462 install_element (INTERFACE_NODE, &no_ip_address_secondary_cmd);
1463 install_element (INTERFACE_NODE, &no_ip_address_label_cmd);
1464#endif /* HAVE_NETLINK */
1465}