blob: c23d32a20aae8ef813e017917c2bb154a966af10 [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/*
2 * Interface related function for RIPng.
3 * Copyright (C) 1998 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 "linklist.h"
26#include "if.h"
27#include "prefix.h"
28#include "memory.h"
29#include "network.h"
30#include "filter.h"
31#include "log.h"
32#include "stream.h"
33#include "zclient.h"
34#include "command.h"
35#include "table.h"
36#include "thread.h"
gdt4d4653a2004-07-01 19:26:33 +000037#include "privs.h"
paul718e3742002-12-13 20:15:29 +000038
39#include "ripngd/ripngd.h"
40#include "ripngd/ripng_debug.h"
41
42/* If RFC2133 definition is used. */
43#ifndef IPV6_JOIN_GROUP
44#define IPV6_JOIN_GROUP IPV6_ADD_MEMBERSHIP
45#endif
46#ifndef IPV6_LEAVE_GROUP
47#define IPV6_LEAVE_GROUP IPV6_DROP_MEMBERSHIP
48#endif
49
gdt4d4653a2004-07-01 19:26:33 +000050extern struct zebra_privs_t ripngd_privs;
51
paul718e3742002-12-13 20:15:29 +000052/* Static utility function. */
53static void ripng_enable_apply (struct interface *);
54static void ripng_passive_interface_apply (struct interface *);
Paul Jakma6ac29a52008-08-15 13:45:30 +010055static int ripng_enable_if_lookup (const char *);
56static int ripng_enable_network_lookup2 (struct connected *);
57static void ripng_enable_apply_all (void);
paul718e3742002-12-13 20:15:29 +000058
59/* Join to the all rip routers multicast group. */
Paul Jakma6ac29a52008-08-15 13:45:30 +010060static int
paul718e3742002-12-13 20:15:29 +000061ripng_multicast_join (struct interface *ifp)
62{
63 int ret;
64 struct ipv6_mreq mreq;
ajs656b4ee2005-01-30 18:08:12 +000065 int save_errno;
paul718e3742002-12-13 20:15:29 +000066
hassoa94434b2003-05-25 17:10:12 +000067 if (if_is_up (ifp) && if_is_multicast (ifp)) {
68 memset (&mreq, 0, sizeof (mreq));
69 inet_pton(AF_INET6, RIPNG_GROUP, &mreq.ipv6mr_multiaddr);
70 mreq.ipv6mr_interface = ifp->ifindex;
paul718e3742002-12-13 20:15:29 +000071
gdt4d4653a2004-07-01 19:26:33 +000072 /*
73 * NetBSD 1.6.2 requires root to join groups on gif(4).
74 * While this is bogus, privs are available and easy to use
75 * for this call as a workaround.
76 */
77 if (ripngd_privs.change (ZPRIVS_RAISE))
78 zlog_err ("ripng_multicast_join: could not raise privs");
79
hassoa94434b2003-05-25 17:10:12 +000080 ret = setsockopt (ripng->sock, IPPROTO_IPV6, IPV6_JOIN_GROUP,
81 (char *) &mreq, sizeof (mreq));
ajs656b4ee2005-01-30 18:08:12 +000082 save_errno = errno;
gdtddf1c262004-01-04 01:02:55 +000083
gdt4d4653a2004-07-01 19:26:33 +000084 if (ripngd_privs.change (ZPRIVS_LOWER))
85 zlog_err ("ripng_multicast_join: could not lower privs");
86
ajs656b4ee2005-01-30 18:08:12 +000087 if (ret < 0 && save_errno == EADDRINUSE)
gdtddf1c262004-01-04 01:02:55 +000088 {
89 /*
90 * Group is already joined. This occurs due to sloppy group
91 * management, in particular declining to leave the group on
92 * an interface that has just gone down.
93 */
94 zlog_warn ("ripng join on %s EADDRINUSE (ignoring)\n", ifp->name);
95 return 0; /* not an error */
96 }
97
hassoa94434b2003-05-25 17:10:12 +000098 if (ret < 0)
ajs656b4ee2005-01-30 18:08:12 +000099 zlog_warn ("can't setsockopt IPV6_JOIN_GROUP: %s",
100 safe_strerror (save_errno));
paul718e3742002-12-13 20:15:29 +0000101
hassoa94434b2003-05-25 17:10:12 +0000102 if (IS_RIPNG_DEBUG_EVENT)
ajs2e23ab22004-12-08 19:46:50 +0000103 zlog_debug ("RIPng %s join to all-rip-routers multicast group", ifp->name);
paul718e3742002-12-13 20:15:29 +0000104
hassoa94434b2003-05-25 17:10:12 +0000105 if (ret < 0)
106 return -1;
107 }
108 return 0;
paul718e3742002-12-13 20:15:29 +0000109}
110
111/* Leave from the all rip routers multicast group. */
Paul Jakma6ac29a52008-08-15 13:45:30 +0100112static int
paul718e3742002-12-13 20:15:29 +0000113ripng_multicast_leave (struct interface *ifp)
114{
115 int ret;
116 struct ipv6_mreq mreq;
117
hassoa94434b2003-05-25 17:10:12 +0000118 if (if_is_up (ifp) && if_is_multicast (ifp)) {
119 memset (&mreq, 0, sizeof (mreq));
120 inet_pton(AF_INET6, RIPNG_GROUP, &mreq.ipv6mr_multiaddr);
121 mreq.ipv6mr_interface = ifp->ifindex;
paul718e3742002-12-13 20:15:29 +0000122
hassoa94434b2003-05-25 17:10:12 +0000123 ret = setsockopt (ripng->sock, IPPROTO_IPV6, IPV6_LEAVE_GROUP,
124 (char *) &mreq, sizeof (mreq));
125 if (ret < 0)
ajs6099b3b2004-11-20 02:06:59 +0000126 zlog_warn ("can't setsockopt IPV6_LEAVE_GROUP: %s\n", safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +0000127
hassoa94434b2003-05-25 17:10:12 +0000128 if (IS_RIPNG_DEBUG_EVENT)
ajs2e23ab22004-12-08 19:46:50 +0000129 zlog_debug ("RIPng %s leave from all-rip-routers multicast group",
hassoa94434b2003-05-25 17:10:12 +0000130 ifp->name);
paul718e3742002-12-13 20:15:29 +0000131
hassoa94434b2003-05-25 17:10:12 +0000132 if (ret < 0)
133 return -1;
134 }
135
136 return 0;
137}
138
139/* How many link local IPv6 address could be used on the interface ? */
Paul Jakma6ac29a52008-08-15 13:45:30 +0100140static int
hassoa94434b2003-05-25 17:10:12 +0000141ripng_if_ipv6_lladdress_check (struct interface *ifp)
142{
143 struct listnode *nn;
144 struct connected *connected;
145 int count = 0;
146
paul1eb8ef22005-04-07 07:30:20 +0000147 for (ALL_LIST_ELEMENTS_RO (ifp->connected, nn, connected))
148 {
hassoa94434b2003-05-25 17:10:12 +0000149 struct prefix *p;
150 p = connected->address;
151
152 if ((p->family == AF_INET6) &&
153 IN6_IS_ADDR_LINKLOCAL (&p->u.prefix6))
154 count++;
155 }
156
157 return count;
paul718e3742002-12-13 20:15:29 +0000158}
159
160/* Check max mtu size. */
Paul Jakma6ac29a52008-08-15 13:45:30 +0100161static unsigned int
162ripng_check_max_mtu (void)
paul718e3742002-12-13 20:15:29 +0000163{
hasso52dc7ee2004-09-23 19:18:23 +0000164 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000165 struct interface *ifp;
hasso98b718a2004-10-11 12:57:57 +0000166 unsigned int mtu;
paul718e3742002-12-13 20:15:29 +0000167
168 mtu = 0;
paul1eb8ef22005-04-07 07:30:20 +0000169 for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp))
170 if (mtu < ifp->mtu6)
171 mtu = ifp->mtu6;
172
paul718e3742002-12-13 20:15:29 +0000173 return mtu;
174}
175
Paul Jakma6ac29a52008-08-15 13:45:30 +0100176static int
paul718e3742002-12-13 20:15:29 +0000177ripng_if_down (struct interface *ifp)
178{
179 struct route_node *rp;
180 struct ripng_info *rinfo;
181 struct ripng_interface *ri;
182
hassoa94434b2003-05-25 17:10:12 +0000183 if (ripng)
paul718e3742002-12-13 20:15:29 +0000184 {
185 for (rp = route_top (ripng->table); rp; rp = route_next (rp))
186 if ((rinfo = rp->info) != NULL)
187 {
188 /* Routes got through this interface. */
189 if (rinfo->ifindex == ifp->ifindex
190 && rinfo->type == ZEBRA_ROUTE_RIPNG
191 && rinfo->sub_type == RIPNG_ROUTE_RTE)
192 {
193 ripng_zebra_ipv6_delete ((struct prefix_ipv6 *) &rp->p,
194 &rinfo->nexthop,
195 rinfo->ifindex);
196
hassoa94434b2003-05-25 17:10:12 +0000197 ripng_redistribute_delete (rinfo->type, rinfo->sub_type,
198 (struct prefix_ipv6 *)&rp->p,
199 rinfo->ifindex);
paul718e3742002-12-13 20:15:29 +0000200 }
201 else
202 {
hassoa94434b2003-05-25 17:10:12 +0000203 /* All redistributed routes got through this interface,
204 * but the static and system ones are kept. */
205 if ((rinfo->ifindex == ifp->ifindex) &&
206 (rinfo->type != ZEBRA_ROUTE_STATIC) &&
207 (rinfo->type != ZEBRA_ROUTE_SYSTEM))
paul718e3742002-12-13 20:15:29 +0000208 ripng_redistribute_delete (rinfo->type, rinfo->sub_type,
209 (struct prefix_ipv6 *) &rp->p,
210 rinfo->ifindex);
211 }
212 }
213 }
214
215 ri = ifp->info;
216
hassoa94434b2003-05-25 17:10:12 +0000217 if (ri->running)
paul718e3742002-12-13 20:15:29 +0000218 {
219 if (IS_RIPNG_DEBUG_EVENT)
ajs2e23ab22004-12-08 19:46:50 +0000220 zlog_debug ("turn off %s", ifp->name);
paul718e3742002-12-13 20:15:29 +0000221
222 /* Leave from multicast group. */
223 ripng_multicast_leave (ifp);
224
225 ri->running = 0;
226 }
227
228 return 0;
229}
230
231/* Inteface link up message processing. */
232int
233ripng_interface_up (int command, struct zclient *zclient, zebra_size_t length)
234{
235 struct stream *s;
236 struct interface *ifp;
237
238 /* zebra_interface_state_read() updates interface structure in iflist. */
239 s = zclient->ibuf;
240 ifp = zebra_interface_state_read (s);
241
242 if (ifp == NULL)
243 return 0;
244
245 if (IS_RIPNG_DEBUG_ZEBRA)
Stephen Hemminger30d20592009-07-28 11:58:51 +0100246 zlog_debug ("interface up %s index %d flags %llx metric %d mtu %d",
247 ifp->name, ifp->ifindex, (unsigned long long)ifp->flags,
248 ifp->metric, ifp->mtu6);
paul718e3742002-12-13 20:15:29 +0000249
250 /* Check if this interface is RIPng enabled or not. */
251 ripng_enable_apply (ifp);
252
253 /* Check for a passive interface. */
254 ripng_passive_interface_apply (ifp);
255
256 /* Apply distribute list to the all interface. */
257 ripng_distribute_update_interface (ifp);
258
259 return 0;
260}
261
262/* Inteface link down message processing. */
263int
264ripng_interface_down (int command, struct zclient *zclient,
265 zebra_size_t length)
266{
267 struct stream *s;
268 struct interface *ifp;
269
270 /* zebra_interface_state_read() updates interface structure in iflist. */
271 s = zclient->ibuf;
272 ifp = zebra_interface_state_read (s);
273
274 if (ifp == NULL)
275 return 0;
276
277 ripng_if_down (ifp);
278
279 if (IS_RIPNG_DEBUG_ZEBRA)
Stephen Hemminger30d20592009-07-28 11:58:51 +0100280 zlog_debug ("interface down %s index %d flags %lld metric %d mtu %d",
hasso1203e1c2004-07-23 21:34:27 +0000281 ifp->name, ifp->ifindex, ifp->flags, ifp->metric, ifp->mtu6);
paul718e3742002-12-13 20:15:29 +0000282
283 return 0;
284}
285
286/* Inteface addition message from zebra. */
287int
288ripng_interface_add (int command, struct zclient *zclient, zebra_size_t length)
289{
290 struct interface *ifp;
291
292 ifp = zebra_interface_add_read (zclient->ibuf);
293
294 if (IS_RIPNG_DEBUG_ZEBRA)
Stephen Hemminger30d20592009-07-28 11:58:51 +0100295 zlog_debug ("RIPng interface add %s index %d flags %lld metric %d mtu %d",
hasso1203e1c2004-07-23 21:34:27 +0000296 ifp->name, ifp->ifindex, ifp->flags, ifp->metric, ifp->mtu6);
paul718e3742002-12-13 20:15:29 +0000297
298 /* Check is this interface is RIP enabled or not.*/
299 ripng_enable_apply (ifp);
300
301 /* Apply distribute list to the interface. */
302 ripng_distribute_update_interface (ifp);
303
304 /* Check interface routemap. */
305 ripng_if_rmap_update_interface (ifp);
306
307 return 0;
308}
309
310int
311ripng_interface_delete (int command, struct zclient *zclient,
312 zebra_size_t length)
313{
hassoa94434b2003-05-25 17:10:12 +0000314 struct interface *ifp;
315 struct stream *s;
316
317 s = zclient->ibuf;
318 /* zebra_interface_state_read() updates interface structure in iflist */
319 ifp = zebra_interface_state_read(s);
320
321 if (ifp == NULL)
322 return 0;
323
324 if (if_is_up (ifp)) {
325 ripng_if_down(ifp);
326 }
327
Stephen Hemminger30d20592009-07-28 11:58:51 +0100328 zlog_info("interface delete %s index %d flags %lld metric %d mtu %d",
hasso1203e1c2004-07-23 21:34:27 +0000329 ifp->name, ifp->ifindex, ifp->flags, ifp->metric, ifp->mtu6);
hassoa94434b2003-05-25 17:10:12 +0000330
331 /* To support pseudo interface do not free interface structure. */
332 /* if_delete(ifp); */
ajsd2fc8892005-04-02 18:38:43 +0000333 ifp->ifindex = IFINDEX_INTERNAL;
hassoa94434b2003-05-25 17:10:12 +0000334
paul718e3742002-12-13 20:15:29 +0000335 return 0;
336}
337
hassoa94434b2003-05-25 17:10:12 +0000338void
Paul Jakma6ac29a52008-08-15 13:45:30 +0100339ripng_interface_clean (void)
hassoa94434b2003-05-25 17:10:12 +0000340{
paul1eb8ef22005-04-07 07:30:20 +0000341 struct listnode *node, *nnode;
hassoa94434b2003-05-25 17:10:12 +0000342 struct interface *ifp;
343 struct ripng_interface *ri;
344
paul1eb8ef22005-04-07 07:30:20 +0000345 for (ALL_LIST_ELEMENTS (iflist, node, nnode, ifp))
hassoa94434b2003-05-25 17:10:12 +0000346 {
hassoa94434b2003-05-25 17:10:12 +0000347 ri = ifp->info;
348
349 ri->enable_network = 0;
350 ri->enable_interface = 0;
351 ri->running = 0;
352
353 if (ri->t_wakeup)
354 {
355 thread_cancel (ri->t_wakeup);
356 ri->t_wakeup = NULL;
357 }
358 }
359}
360
361void
Paul Jakma6ac29a52008-08-15 13:45:30 +0100362ripng_interface_reset (void)
363{
hasso52dc7ee2004-09-23 19:18:23 +0000364 struct listnode *node;
hassoa94434b2003-05-25 17:10:12 +0000365 struct interface *ifp;
366 struct ripng_interface *ri;
367
paul1eb8ef22005-04-07 07:30:20 +0000368 for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp))
hassoa94434b2003-05-25 17:10:12 +0000369 {
hassoa94434b2003-05-25 17:10:12 +0000370 ri = ifp->info;
371
372 ri->enable_network = 0;
373 ri->enable_interface = 0;
374 ri->running = 0;
375
376 ri->split_horizon = RIPNG_NO_SPLIT_HORIZON;
377 ri->split_horizon_default = RIPNG_NO_SPLIT_HORIZON;
378
379 ri->list[RIPNG_FILTER_IN] = NULL;
380 ri->list[RIPNG_FILTER_OUT] = NULL;
381
382 ri->prefix[RIPNG_FILTER_IN] = NULL;
383 ri->prefix[RIPNG_FILTER_OUT] = NULL;
384
385 if (ri->t_wakeup)
386 {
387 thread_cancel (ri->t_wakeup);
388 ri->t_wakeup = NULL;
389 }
390
391 ri->passive = 0;
392 }
393}
394
395static void
396ripng_apply_address_add (struct connected *ifc) {
397 struct prefix_ipv6 address;
398 struct prefix *p;
399
400 if (!ripng)
401 return;
402
403 if (! if_is_up(ifc->ifp))
404 return;
405
406 p = ifc->address;
407
408 memset (&address, 0, sizeof (address));
409 address.family = p->family;
410 address.prefix = p->u.prefix6;
411 address.prefixlen = p->prefixlen;
412 apply_mask_ipv6(&address);
413
414 /* Check if this interface is RIP enabled or not
415 or Check if this address's prefix is RIP enabled */
416 if ((ripng_enable_if_lookup(ifc->ifp->name) >= 0) ||
417 (ripng_enable_network_lookup2(ifc) >= 0))
418 ripng_redistribute_add(ZEBRA_ROUTE_CONNECT, RIPNG_ROUTE_INTERFACE,
419 &address, ifc->ifp->ifindex, NULL);
420
421}
422
paul718e3742002-12-13 20:15:29 +0000423int
424ripng_interface_address_add (int command, struct zclient *zclient,
425 zebra_size_t length)
426{
427 struct connected *c;
428 struct prefix *p;
paul718e3742002-12-13 20:15:29 +0000429
paul0a589352004-05-08 11:48:26 +0000430 c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_ADD,
431 zclient->ibuf);
paul718e3742002-12-13 20:15:29 +0000432
433 if (c == NULL)
434 return 0;
435
436 p = c->address;
437
438 if (p->family == AF_INET6)
439 {
Paul Jakma995b9652006-05-11 13:20:47 +0000440 struct ripng_interface *ri = c->ifp->info;
441
paul718e3742002-12-13 20:15:29 +0000442 if (IS_RIPNG_DEBUG_ZEBRA)
ajs2e23ab22004-12-08 19:46:50 +0000443 zlog_debug ("RIPng connected address %s/%d add",
hasso3a2ce6a2005-04-08 01:30:51 +0000444 inet6_ntoa(p->u.prefix6),
paul718e3742002-12-13 20:15:29 +0000445 p->prefixlen);
446
hassoa94434b2003-05-25 17:10:12 +0000447 /* Check is this prefix needs to be redistributed. */
448 ripng_apply_address_add(c);
449
450 /* Let's try once again whether the interface could be activated */
Paul Jakma995b9652006-05-11 13:20:47 +0000451 if (!ri->running) {
452 /* Check if this interface is RIP enabled or not.*/
453 ripng_enable_apply (c->ifp);
hassoa94434b2003-05-25 17:10:12 +0000454
Paul Jakma995b9652006-05-11 13:20:47 +0000455 /* Apply distribute list to the interface. */
456 ripng_distribute_update_interface (c->ifp);
hassoa94434b2003-05-25 17:10:12 +0000457
Paul Jakma995b9652006-05-11 13:20:47 +0000458 /* Check interface routemap. */
459 ripng_if_rmap_update_interface (c->ifp);
hassoa94434b2003-05-25 17:10:12 +0000460 }
461
paul718e3742002-12-13 20:15:29 +0000462 }
463
464 return 0;
465}
466
hassoa94434b2003-05-25 17:10:12 +0000467static void
468ripng_apply_address_del (struct connected *ifc) {
469 struct prefix_ipv6 address;
470 struct prefix *p;
471
472 if (!ripng)
473 return;
474
475 if (! if_is_up(ifc->ifp))
476 return;
477
478 p = ifc->address;
479
480 memset (&address, 0, sizeof (address));
481 address.family = p->family;
482 address.prefix = p->u.prefix6;
483 address.prefixlen = p->prefixlen;
484 apply_mask_ipv6(&address);
485
486 ripng_redistribute_delete(ZEBRA_ROUTE_CONNECT, RIPNG_ROUTE_INTERFACE,
487 &address, ifc->ifp->ifindex);
488}
489
paul718e3742002-12-13 20:15:29 +0000490int
491ripng_interface_address_delete (int command, struct zclient *zclient,
492 zebra_size_t length)
493{
494 struct connected *ifc;
495 struct prefix *p;
496 char buf[INET6_ADDRSTRLEN];
497
paul0a589352004-05-08 11:48:26 +0000498 ifc = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_DELETE,
499 zclient->ibuf);
paul718e3742002-12-13 20:15:29 +0000500
501 if (ifc)
502 {
503 p = ifc->address;
504
505 if (p->family == AF_INET6)
506 {
507 if (IS_RIPNG_DEBUG_ZEBRA)
ajs2e23ab22004-12-08 19:46:50 +0000508 zlog_debug ("RIPng connected address %s/%d delete",
paul718e3742002-12-13 20:15:29 +0000509 inet_ntop (AF_INET6, &p->u.prefix6, buf,
510 INET6_ADDRSTRLEN),
511 p->prefixlen);
512
hassoa94434b2003-05-25 17:10:12 +0000513 /* Check wether this prefix needs to be removed. */
514 ripng_apply_address_del(ifc);
paul718e3742002-12-13 20:15:29 +0000515 }
516 connected_free (ifc);
517 }
518
519 return 0;
520}
521
522/* RIPng enable interface vector. */
523vector ripng_enable_if;
524
525/* RIPng enable network table. */
526struct route_table *ripng_enable_network;
527
528/* Lookup RIPng enable network. */
hassoa94434b2003-05-25 17:10:12 +0000529/* Check wether the interface has at least a connected prefix that
530 * is within the ripng_enable_network table. */
Paul Jakma6ac29a52008-08-15 13:45:30 +0100531static int
hassoa94434b2003-05-25 17:10:12 +0000532ripng_enable_network_lookup_if (struct interface *ifp)
paul718e3742002-12-13 20:15:29 +0000533{
paul1eb8ef22005-04-07 07:30:20 +0000534 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000535 struct connected *connected;
hassoa94434b2003-05-25 17:10:12 +0000536 struct prefix_ipv6 address;
paul718e3742002-12-13 20:15:29 +0000537
paul1eb8ef22005-04-07 07:30:20 +0000538 for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, connected))
539 {
540 struct prefix *p;
541 struct route_node *node;
paul718e3742002-12-13 20:15:29 +0000542
paul1eb8ef22005-04-07 07:30:20 +0000543 p = connected->address;
paul718e3742002-12-13 20:15:29 +0000544
paul1eb8ef22005-04-07 07:30:20 +0000545 if (p->family == AF_INET6)
546 {
547 address.family = AF_INET6;
548 address.prefix = p->u.prefix6;
549 address.prefixlen = IPV6_MAX_BITLEN;
hassoa94434b2003-05-25 17:10:12 +0000550
paul1eb8ef22005-04-07 07:30:20 +0000551 node = route_node_match (ripng_enable_network,
552 (struct prefix *)&address);
553 if (node)
554 {
555 route_unlock_node (node);
556 return 1;
557 }
558 }
559 }
paul718e3742002-12-13 20:15:29 +0000560 return -1;
561}
562
hassoa94434b2003-05-25 17:10:12 +0000563/* Check wether connected is within the ripng_enable_network table. */
Paul Jakma6ac29a52008-08-15 13:45:30 +0100564static int
hassoa94434b2003-05-25 17:10:12 +0000565ripng_enable_network_lookup2 (struct connected *connected)
566{
567 struct prefix_ipv6 address;
568 struct prefix *p;
569
570 p = connected->address;
571
572 if (p->family == AF_INET6) {
573 struct route_node *node;
574
575 address.family = p->family;
576 address.prefix = p->u.prefix6;
577 address.prefixlen = IPV6_MAX_BITLEN;
578
579 /* LPM on p->family, p->u.prefix6/IPV6_MAX_BITLEN within ripng_enable_network */
580 node = route_node_match (ripng_enable_network,
581 (struct prefix *)&address);
582
583 if (node) {
584 route_unlock_node (node);
585 return 1;
586 }
587 }
588
589 return -1;
590}
591
paul718e3742002-12-13 20:15:29 +0000592/* Add RIPng enable network. */
Paul Jakma6ac29a52008-08-15 13:45:30 +0100593static int
paul718e3742002-12-13 20:15:29 +0000594ripng_enable_network_add (struct prefix *p)
595{
596 struct route_node *node;
597
598 node = route_node_get (ripng_enable_network, p);
599
600 if (node->info)
601 {
602 route_unlock_node (node);
603 return -1;
604 }
605 else
hasso7a1d5832004-10-08 06:32:23 +0000606 node->info = (char *) "enabled";
paul718e3742002-12-13 20:15:29 +0000607
hassoa94434b2003-05-25 17:10:12 +0000608 /* XXX: One should find a better solution than a generic one */
609 ripng_enable_apply_all();
610
paul718e3742002-12-13 20:15:29 +0000611 return 1;
612}
613
614/* Delete RIPng enable network. */
Paul Jakma6ac29a52008-08-15 13:45:30 +0100615static int
paul718e3742002-12-13 20:15:29 +0000616ripng_enable_network_delete (struct prefix *p)
617{
618 struct route_node *node;
619
620 node = route_node_lookup (ripng_enable_network, p);
621 if (node)
622 {
623 node->info = NULL;
624
625 /* Unlock info lock. */
626 route_unlock_node (node);
627
628 /* Unlock lookup lock. */
629 route_unlock_node (node);
630
631 return 1;
632 }
633 return -1;
634}
635
636/* Lookup function. */
Paul Jakma6ac29a52008-08-15 13:45:30 +0100637static int
hasso98b718a2004-10-11 12:57:57 +0000638ripng_enable_if_lookup (const char *ifname)
paul718e3742002-12-13 20:15:29 +0000639{
hasso7a1d5832004-10-08 06:32:23 +0000640 unsigned int i;
paul718e3742002-12-13 20:15:29 +0000641 char *str;
642
paul55468c82005-03-14 20:19:01 +0000643 for (i = 0; i < vector_active (ripng_enable_if); i++)
paul718e3742002-12-13 20:15:29 +0000644 if ((str = vector_slot (ripng_enable_if, i)) != NULL)
645 if (strcmp (str, ifname) == 0)
646 return i;
647 return -1;
648}
649
650/* Add interface to ripng_enable_if. */
Paul Jakma6ac29a52008-08-15 13:45:30 +0100651static int
hasso98b718a2004-10-11 12:57:57 +0000652ripng_enable_if_add (const char *ifname)
paul718e3742002-12-13 20:15:29 +0000653{
654 int ret;
655
656 ret = ripng_enable_if_lookup (ifname);
657 if (ret >= 0)
658 return -1;
659
660 vector_set (ripng_enable_if, strdup (ifname));
661
hassoa94434b2003-05-25 17:10:12 +0000662 ripng_enable_apply_all();
663
paul718e3742002-12-13 20:15:29 +0000664 return 1;
665}
666
667/* Delete interface from ripng_enable_if. */
Paul Jakma6ac29a52008-08-15 13:45:30 +0100668static int
hasso98b718a2004-10-11 12:57:57 +0000669ripng_enable_if_delete (const char *ifname)
paul718e3742002-12-13 20:15:29 +0000670{
671 int index;
672 char *str;
673
674 index = ripng_enable_if_lookup (ifname);
675 if (index < 0)
676 return -1;
677
678 str = vector_slot (ripng_enable_if, index);
679 free (str);
680 vector_unset (ripng_enable_if, index);
681
hassoa94434b2003-05-25 17:10:12 +0000682 ripng_enable_apply_all();
683
paul718e3742002-12-13 20:15:29 +0000684 return 1;
685}
686
687/* Wake up interface. */
Paul Jakma6ac29a52008-08-15 13:45:30 +0100688static int
paul718e3742002-12-13 20:15:29 +0000689ripng_interface_wakeup (struct thread *t)
690{
691 struct interface *ifp;
692 struct ripng_interface *ri;
693
694 /* Get interface. */
695 ifp = THREAD_ARG (t);
696
697 ri = ifp->info;
698 ri->t_wakeup = NULL;
699
700 /* Join to multicast group. */
hassoa94434b2003-05-25 17:10:12 +0000701 if (ripng_multicast_join (ifp) < 0) {
702 zlog_err ("multicast join failed, interface %s not running", ifp->name);
703 return 0;
704 }
705
706 /* Set running flag. */
707 ri->running = 1;
paul718e3742002-12-13 20:15:29 +0000708
709 /* Send RIP request to the interface. */
710 ripng_request (ifp);
711
712 return 0;
713}
714
Paul Jakma6ac29a52008-08-15 13:45:30 +0100715static void
hassoa94434b2003-05-25 17:10:12 +0000716ripng_connect_set (struct interface *ifp, int set)
717{
paul1eb8ef22005-04-07 07:30:20 +0000718 struct listnode *node, *nnode;
hassoa94434b2003-05-25 17:10:12 +0000719 struct connected *connected;
720 struct prefix_ipv6 address;
721
paul1eb8ef22005-04-07 07:30:20 +0000722 for (ALL_LIST_ELEMENTS (ifp->connected, node, nnode, connected))
723 {
hassoa94434b2003-05-25 17:10:12 +0000724 struct prefix *p;
725 p = connected->address;
726
727 if (p->family != AF_INET6)
728 continue;
729
730 address.family = AF_INET6;
731 address.prefix = p->u.prefix6;
732 address.prefixlen = p->prefixlen;
733 apply_mask_ipv6 (&address);
734
735 if (set) {
736 /* Check once more wether this prefix is within a "network IF_OR_PREF" one */
737 if ((ripng_enable_if_lookup(connected->ifp->name) >= 0) ||
738 (ripng_enable_network_lookup2(connected) >= 0))
739 ripng_redistribute_add (ZEBRA_ROUTE_CONNECT, RIPNG_ROUTE_INTERFACE,
740 &address, connected->ifp->ifindex, NULL);
741 } else {
742 ripng_redistribute_delete (ZEBRA_ROUTE_CONNECT, RIPNG_ROUTE_INTERFACE,
743 &address, connected->ifp->ifindex);
744 if (ripng_redistribute_check (ZEBRA_ROUTE_CONNECT))
745 ripng_redistribute_add (ZEBRA_ROUTE_CONNECT, RIPNG_ROUTE_REDISTRIBUTE,
746 &address, connected->ifp->ifindex, NULL);
747 }
748 }
749}
750
paul718e3742002-12-13 20:15:29 +0000751/* Check RIPng is enabed on this interface. */
752void
753ripng_enable_apply (struct interface *ifp)
754{
755 int ret;
756 struct ripng_interface *ri = NULL;
757
758 /* Check interface. */
paul718e3742002-12-13 20:15:29 +0000759 if (! if_is_up (ifp))
760 return;
761
762 ri = ifp->info;
763
hassoa94434b2003-05-25 17:10:12 +0000764 /* Is this interface a candidate for RIPng ? */
765 ret = ripng_enable_network_lookup_if (ifp);
paul718e3742002-12-13 20:15:29 +0000766
767 /* If the interface is matched. */
768 if (ret > 0)
769 ri->enable_network = 1;
770 else
771 ri->enable_network = 0;
772
773 /* Check interface name configuration. */
774 ret = ripng_enable_if_lookup (ifp->name);
775 if (ret >= 0)
776 ri->enable_interface = 1;
777 else
778 ri->enable_interface = 0;
779
hassoa94434b2003-05-25 17:10:12 +0000780 /* any candidate interface MUST have a link-local IPv6 address */
781 if ((! ripng_if_ipv6_lladdress_check (ifp)) &&
782 (ri->enable_network || ri->enable_interface)) {
783 ri->enable_network = 0;
784 ri->enable_interface = 0;
785 zlog_warn("Interface %s does not have any link-local address",
786 ifp->name);
787 }
788
paul718e3742002-12-13 20:15:29 +0000789 /* Update running status of the interface. */
790 if (ri->enable_network || ri->enable_interface)
791 {
paul718e3742002-12-13 20:15:29 +0000792 {
793 if (IS_RIPNG_DEBUG_EVENT)
ajs2e23ab22004-12-08 19:46:50 +0000794 zlog_debug ("RIPng turn on %s", ifp->name);
paul718e3742002-12-13 20:15:29 +0000795
796 /* Add interface wake up thread. */
797 if (! ri->t_wakeup)
798 ri->t_wakeup = thread_add_timer (master, ripng_interface_wakeup,
799 ifp, 1);
paul718e3742002-12-13 20:15:29 +0000800
hassoa94434b2003-05-25 17:10:12 +0000801 ripng_connect_set (ifp, 1);
paul718e3742002-12-13 20:15:29 +0000802 }
803 }
804 else
805 {
806 if (ri->running)
807 {
hassoa94434b2003-05-25 17:10:12 +0000808 /* Might as well clean up the route table as well
809 * ripng_if_down sets to 0 ri->running, and displays "turn off %s"
810 **/
811 ripng_if_down(ifp);
paul718e3742002-12-13 20:15:29 +0000812
hassoa94434b2003-05-25 17:10:12 +0000813 ripng_connect_set (ifp, 0);
paul718e3742002-12-13 20:15:29 +0000814 }
815 }
816}
817
818/* Set distribute list to all interfaces. */
Paul Jakma6ac29a52008-08-15 13:45:30 +0100819static void
820ripng_enable_apply_all (void)
paul718e3742002-12-13 20:15:29 +0000821{
822 struct interface *ifp;
hasso52dc7ee2004-09-23 19:18:23 +0000823 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000824
paul1eb8ef22005-04-07 07:30:20 +0000825 for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp))
826 ripng_enable_apply (ifp);
paul718e3742002-12-13 20:15:29 +0000827}
828
hassoa94434b2003-05-25 17:10:12 +0000829/* Clear all network and neighbor configuration */
830void
831ripng_clean_network ()
832{
hasso7a1d5832004-10-08 06:32:23 +0000833 unsigned int i;
hassoa94434b2003-05-25 17:10:12 +0000834 char *str;
835 struct route_node *rn;
836
837 /* ripng_enable_network */
838 for (rn = route_top (ripng_enable_network); rn; rn = route_next (rn))
839 if (rn->info) {
840 rn->info = NULL;
841 route_unlock_node(rn);
842 }
843
844 /* ripng_enable_if */
paul55468c82005-03-14 20:19:01 +0000845 for (i = 0; i < vector_active (ripng_enable_if); i++)
hassoa94434b2003-05-25 17:10:12 +0000846 if ((str = vector_slot (ripng_enable_if, i)) != NULL) {
847 free (str);
848 vector_slot (ripng_enable_if, i) = NULL;
849 }
850}
851
paul718e3742002-12-13 20:15:29 +0000852/* Vector to store passive-interface name. */
853vector Vripng_passive_interface;
854
855/* Utility function for looking up passive interface settings. */
Paul Jakma6ac29a52008-08-15 13:45:30 +0100856static int
hasso98b718a2004-10-11 12:57:57 +0000857ripng_passive_interface_lookup (const char *ifname)
paul718e3742002-12-13 20:15:29 +0000858{
hasso7a1d5832004-10-08 06:32:23 +0000859 unsigned int i;
paul718e3742002-12-13 20:15:29 +0000860 char *str;
861
paul55468c82005-03-14 20:19:01 +0000862 for (i = 0; i < vector_active (Vripng_passive_interface); i++)
paul718e3742002-12-13 20:15:29 +0000863 if ((str = vector_slot (Vripng_passive_interface, i)) != NULL)
864 if (strcmp (str, ifname) == 0)
865 return i;
866 return -1;
867}
868
869void
870ripng_passive_interface_apply (struct interface *ifp)
871{
872 int ret;
873 struct ripng_interface *ri;
874
875 ri = ifp->info;
876
877 ret = ripng_passive_interface_lookup (ifp->name);
878 if (ret < 0)
879 ri->passive = 0;
880 else
881 ri->passive = 1;
882}
883
Paul Jakma6ac29a52008-08-15 13:45:30 +0100884static void
paul718e3742002-12-13 20:15:29 +0000885ripng_passive_interface_apply_all (void)
886{
887 struct interface *ifp;
hasso52dc7ee2004-09-23 19:18:23 +0000888 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000889
paul1eb8ef22005-04-07 07:30:20 +0000890 for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp))
891 ripng_passive_interface_apply (ifp);
paul718e3742002-12-13 20:15:29 +0000892}
893
894/* Passive interface. */
Paul Jakma6ac29a52008-08-15 13:45:30 +0100895static int
hasso98b718a2004-10-11 12:57:57 +0000896ripng_passive_interface_set (struct vty *vty, const char *ifname)
paul718e3742002-12-13 20:15:29 +0000897{
898 if (ripng_passive_interface_lookup (ifname) >= 0)
899 return CMD_WARNING;
900
901 vector_set (Vripng_passive_interface, strdup (ifname));
902
903 ripng_passive_interface_apply_all ();
904
905 return CMD_SUCCESS;
906}
907
Paul Jakma6ac29a52008-08-15 13:45:30 +0100908static int
hasso98b718a2004-10-11 12:57:57 +0000909ripng_passive_interface_unset (struct vty *vty, const char *ifname)
paul718e3742002-12-13 20:15:29 +0000910{
911 int i;
912 char *str;
913
914 i = ripng_passive_interface_lookup (ifname);
915 if (i < 0)
916 return CMD_WARNING;
917
918 str = vector_slot (Vripng_passive_interface, i);
919 free (str);
920 vector_unset (Vripng_passive_interface, i);
921
922 ripng_passive_interface_apply_all ();
923
924 return CMD_SUCCESS;
925}
926
927/* Free all configured RIP passive-interface settings. */
928void
929ripng_passive_interface_clean (void)
930{
hasso7a1d5832004-10-08 06:32:23 +0000931 unsigned int i;
paul718e3742002-12-13 20:15:29 +0000932 char *str;
933
paul55468c82005-03-14 20:19:01 +0000934 for (i = 0; i < vector_active (Vripng_passive_interface); i++)
paul718e3742002-12-13 20:15:29 +0000935 if ((str = vector_slot (Vripng_passive_interface, i)) != NULL)
936 {
937 free (str);
938 vector_slot (Vripng_passive_interface, i) = NULL;
939 }
940 ripng_passive_interface_apply_all ();
941}
942
943/* Write RIPng enable network and interface to the vty. */
944int
hassoa94434b2003-05-25 17:10:12 +0000945ripng_network_write (struct vty *vty, int config_mode)
paul718e3742002-12-13 20:15:29 +0000946{
hasso7a1d5832004-10-08 06:32:23 +0000947 unsigned int i;
hasso98b718a2004-10-11 12:57:57 +0000948 const char *ifname;
paul718e3742002-12-13 20:15:29 +0000949 struct route_node *node;
950 char buf[BUFSIZ];
951
952 /* Write enable network. */
953 for (node = route_top (ripng_enable_network); node; node = route_next (node))
954 if (node->info)
955 {
956 struct prefix *p = &node->p;
hassoa94434b2003-05-25 17:10:12 +0000957 vty_out (vty, "%s%s/%d%s",
958 config_mode ? " network " : " ",
paul718e3742002-12-13 20:15:29 +0000959 inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
960 p->prefixlen,
961 VTY_NEWLINE);
962
963 }
964
965 /* Write enable interface. */
paul55468c82005-03-14 20:19:01 +0000966 for (i = 0; i < vector_active (ripng_enable_if); i++)
hassoa94434b2003-05-25 17:10:12 +0000967 if ((ifname = vector_slot (ripng_enable_if, i)) != NULL)
968 vty_out (vty, "%s%s%s",
969 config_mode ? " network " : " ",
970 ifname,
paul718e3742002-12-13 20:15:29 +0000971 VTY_NEWLINE);
972
973 /* Write passive interface. */
hassoa94434b2003-05-25 17:10:12 +0000974 if (config_mode)
paul55468c82005-03-14 20:19:01 +0000975 for (i = 0; i < vector_active (Vripng_passive_interface); i++)
hassoa94434b2003-05-25 17:10:12 +0000976 if ((ifname = vector_slot (Vripng_passive_interface, i)) != NULL)
977 vty_out (vty, " passive-interface %s%s", ifname, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +0000978
979 return 0;
980}
981
982/* RIPng enable on specified interface or matched network. */
983DEFUN (ripng_network,
984 ripng_network_cmd,
985 "network IF_OR_ADDR",
986 "RIPng enable on specified interface or network.\n"
987 "Interface or address")
988{
989 int ret;
990 struct prefix p;
991
992 ret = str2prefix (argv[0], &p);
993
994 /* Given string is IPv6 network or interface name. */
995 if (ret)
996 ret = ripng_enable_network_add (&p);
997 else
998 ret = ripng_enable_if_add (argv[0]);
999
1000 if (ret < 0)
1001 {
1002 vty_out (vty, "There is same network configuration %s%s", argv[0],
1003 VTY_NEWLINE);
1004 return CMD_WARNING;
1005 }
1006
paul718e3742002-12-13 20:15:29 +00001007 return CMD_SUCCESS;
1008}
1009
1010/* RIPng enable on specified interface or matched network. */
1011DEFUN (no_ripng_network,
1012 no_ripng_network_cmd,
1013 "no network IF_OR_ADDR",
1014 NO_STR
1015 "RIPng enable on specified interface or network.\n"
1016 "Interface or address")
1017{
1018 int ret;
1019 struct prefix p;
1020
1021 ret = str2prefix (argv[0], &p);
1022
1023 /* Given string is interface name. */
1024 if (ret)
1025 ret = ripng_enable_network_delete (&p);
1026 else
1027 ret = ripng_enable_if_delete (argv[0]);
1028
1029 if (ret < 0)
1030 {
1031 vty_out (vty, "can't find network %s%s", argv[0],
1032 VTY_NEWLINE);
1033 return CMD_WARNING;
1034 }
1035
paul718e3742002-12-13 20:15:29 +00001036 return CMD_SUCCESS;
1037}
1038
hassoa94434b2003-05-25 17:10:12 +00001039DEFUN (ipv6_ripng_split_horizon,
1040 ipv6_ripng_split_horizon_cmd,
1041 "ipv6 ripng split-horizon",
1042 IPV6_STR
1043 "Routing Information Protocol\n"
1044 "Perform split horizon\n")
1045{
1046 struct interface *ifp;
1047 struct ripng_interface *ri;
1048
1049 ifp = vty->index;
1050 ri = ifp->info;
1051
1052 ri->split_horizon = RIPNG_SPLIT_HORIZON;
1053 return CMD_SUCCESS;
1054}
1055
1056DEFUN (ipv6_ripng_split_horizon_poisoned_reverse,
1057 ipv6_ripng_split_horizon_poisoned_reverse_cmd,
1058 "ipv6 ripng split-horizon poisoned-reverse",
1059 IPV6_STR
1060 "Routing Information Protocol\n"
1061 "Perform split horizon\n"
1062 "With poisoned-reverse\n")
1063{
1064 struct interface *ifp;
1065 struct ripng_interface *ri;
1066
1067 ifp = vty->index;
1068 ri = ifp->info;
1069
1070 ri->split_horizon = RIPNG_SPLIT_HORIZON_POISONED_REVERSE;
1071 return CMD_SUCCESS;
1072}
1073
1074DEFUN (no_ipv6_ripng_split_horizon,
1075 no_ipv6_ripng_split_horizon_cmd,
1076 "no ipv6 ripng split-horizon",
1077 NO_STR
1078 IPV6_STR
1079 "Routing Information Protocol\n"
1080 "Perform split horizon\n")
1081{
1082 struct interface *ifp;
1083 struct ripng_interface *ri;
1084
1085 ifp = vty->index;
1086 ri = ifp->info;
1087
1088 ri->split_horizon = RIPNG_NO_SPLIT_HORIZON;
1089 return CMD_SUCCESS;
1090}
1091
1092ALIAS (no_ipv6_ripng_split_horizon,
1093 no_ipv6_ripng_split_horizon_poisoned_reverse_cmd,
1094 "no ipv6 ripng split-horizon poisoned-reverse",
1095 NO_STR
1096 IPV6_STR
1097 "Routing Information Protocol\n"
1098 "Perform split horizon\n"
1099 "With poisoned-reverse\n")
1100
paul718e3742002-12-13 20:15:29 +00001101DEFUN (ripng_passive_interface,
1102 ripng_passive_interface_cmd,
1103 "passive-interface IFNAME",
1104 "Suppress routing updates on an interface\n"
1105 "Interface name\n")
1106{
1107 return ripng_passive_interface_set (vty, argv[0]);
1108}
1109
1110DEFUN (no_ripng_passive_interface,
1111 no_ripng_passive_interface_cmd,
1112 "no passive-interface IFNAME",
1113 NO_STR
1114 "Suppress routing updates on an interface\n"
1115 "Interface name\n")
1116{
1117 return ripng_passive_interface_unset (vty, argv[0]);
1118}
1119
Paul Jakma6ac29a52008-08-15 13:45:30 +01001120static struct ripng_interface *
1121ri_new (void)
paul718e3742002-12-13 20:15:29 +00001122{
1123 struct ripng_interface *ri;
1124 ri = XCALLOC (MTYPE_IF, sizeof (struct ripng_interface));
hassoa94434b2003-05-25 17:10:12 +00001125
1126 /* Set default split-horizon behavior. If the interface is Frame
1127 Relay or SMDS is enabled, the default value for split-horizon is
1128 off. But currently Zebra does detect Frame Relay or SMDS
1129 interface. So all interface is set to split horizon. */
1130 ri->split_horizon_default = RIPNG_SPLIT_HORIZON;
1131 ri->split_horizon = ri->split_horizon_default;
1132
paul718e3742002-12-13 20:15:29 +00001133 return ri;
1134}
1135
Paul Jakma6ac29a52008-08-15 13:45:30 +01001136static int
paul718e3742002-12-13 20:15:29 +00001137ripng_if_new_hook (struct interface *ifp)
1138{
1139 ifp->info = ri_new ();
1140 return 0;
1141}
1142
hassoa94434b2003-05-25 17:10:12 +00001143/* Called when interface structure deleted. */
Paul Jakma6ac29a52008-08-15 13:45:30 +01001144static int
hassoa94434b2003-05-25 17:10:12 +00001145ripng_if_delete_hook (struct interface *ifp)
1146{
1147 XFREE (MTYPE_IF, ifp->info);
1148 ifp->info = NULL;
1149 return 0;
1150}
1151
paul718e3742002-12-13 20:15:29 +00001152/* Configuration write function for ripngd. */
Paul Jakma6ac29a52008-08-15 13:45:30 +01001153static int
paul718e3742002-12-13 20:15:29 +00001154interface_config_write (struct vty *vty)
1155{
hasso52dc7ee2004-09-23 19:18:23 +00001156 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001157 struct interface *ifp;
1158 struct ripng_interface *ri;
1159 int write = 0;
1160
paul1eb8ef22005-04-07 07:30:20 +00001161 for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp))
paul718e3742002-12-13 20:15:29 +00001162 {
paul718e3742002-12-13 20:15:29 +00001163 ri = ifp->info;
1164
hassoa94434b2003-05-25 17:10:12 +00001165 /* Do not display the interface if there is no
1166 * configuration about it.
1167 **/
1168 if ((!ifp->desc) &&
1169 (ri->split_horizon == ri->split_horizon_default))
1170 continue;
1171
paul718e3742002-12-13 20:15:29 +00001172 vty_out (vty, "interface %s%s", ifp->name,
1173 VTY_NEWLINE);
1174 if (ifp->desc)
1175 vty_out (vty, " description %s%s", ifp->desc,
1176 VTY_NEWLINE);
1177
hassoa94434b2003-05-25 17:10:12 +00001178 /* Split horizon. */
1179 if (ri->split_horizon != ri->split_horizon_default)
1180 {
1181 switch (ri->split_horizon) {
1182 case RIPNG_SPLIT_HORIZON:
1183 vty_out (vty, " ipv6 ripng split-horizon%s", VTY_NEWLINE);
1184 break;
1185 case RIPNG_SPLIT_HORIZON_POISONED_REVERSE:
1186 vty_out (vty, " ipv6 ripng split-horizon poisoned-reverse%s",
1187 VTY_NEWLINE);
1188 break;
1189 case RIPNG_NO_SPLIT_HORIZON:
1190 default:
1191 vty_out (vty, " no ipv6 ripng split-horizon%s", VTY_NEWLINE);
1192 break;
1193 }
1194 }
1195
paul718e3742002-12-13 20:15:29 +00001196 vty_out (vty, "!%s", VTY_NEWLINE);
1197
1198 write++;
1199 }
1200 return write;
1201}
1202
1203/* ripngd's interface node. */
Stephen Hemminger7fc626d2008-12-01 11:10:34 -08001204static struct cmd_node interface_node =
paul718e3742002-12-13 20:15:29 +00001205{
1206 INTERFACE_NODE,
1207 "%s(config-if)# ",
hassoa94434b2003-05-25 17:10:12 +00001208 1 /* VTYSH */
paul718e3742002-12-13 20:15:29 +00001209};
1210
1211/* Initialization of interface. */
1212void
1213ripng_if_init ()
1214{
1215 /* Interface initialize. */
1216 iflist = list_new ();
1217 if_add_hook (IF_NEW_HOOK, ripng_if_new_hook);
hassoa94434b2003-05-25 17:10:12 +00001218 if_add_hook (IF_DELETE_HOOK, ripng_if_delete_hook);
paul718e3742002-12-13 20:15:29 +00001219
1220 /* RIPng enable network init. */
1221 ripng_enable_network = route_table_init ();
1222
1223 /* RIPng enable interface init. */
1224 ripng_enable_if = vector_init (1);
1225
1226 /* RIPng passive interface. */
1227 Vripng_passive_interface = vector_init (1);
1228
1229 /* Install interface node. */
1230 install_node (&interface_node, interface_config_write);
hassoa94434b2003-05-25 17:10:12 +00001231
1232 /* Install commands. */
paul718e3742002-12-13 20:15:29 +00001233 install_element (CONFIG_NODE, &interface_cmd);
paul32d24632003-05-23 09:25:20 +00001234 install_element (CONFIG_NODE, &no_interface_cmd);
hassoa94434b2003-05-25 17:10:12 +00001235 install_default (INTERFACE_NODE);
paul718e3742002-12-13 20:15:29 +00001236 install_element (INTERFACE_NODE, &interface_desc_cmd);
1237 install_element (INTERFACE_NODE, &no_interface_desc_cmd);
1238
1239 install_element (RIPNG_NODE, &ripng_network_cmd);
1240 install_element (RIPNG_NODE, &no_ripng_network_cmd);
1241 install_element (RIPNG_NODE, &ripng_passive_interface_cmd);
1242 install_element (RIPNG_NODE, &no_ripng_passive_interface_cmd);
hassoa94434b2003-05-25 17:10:12 +00001243
1244 install_element (INTERFACE_NODE, &ipv6_ripng_split_horizon_cmd);
1245 install_element (INTERFACE_NODE, &ipv6_ripng_split_horizon_poisoned_reverse_cmd);
1246 install_element (INTERFACE_NODE, &no_ipv6_ripng_split_horizon_cmd);
1247 install_element (INTERFACE_NODE, &no_ipv6_ripng_split_horizon_poisoned_reverse_cmd);
paul718e3742002-12-13 20:15:29 +00001248}