blob: d70c299d3e784c4b4bd3eb641c33111df9008fe6 [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)
ajs2e23ab22004-12-08 19:46:50 +0000246 zlog_debug ("interface up %s index %d flags %ld metric %d mtu %d",
hasso1203e1c2004-07-23 21:34:27 +0000247 ifp->name, ifp->ifindex, ifp->flags, ifp->metric, ifp->mtu6);
paul718e3742002-12-13 20:15:29 +0000248
249 /* Check if this interface is RIPng enabled or not. */
250 ripng_enable_apply (ifp);
251
252 /* Check for a passive interface. */
253 ripng_passive_interface_apply (ifp);
254
255 /* Apply distribute list to the all interface. */
256 ripng_distribute_update_interface (ifp);
257
258 return 0;
259}
260
261/* Inteface link down message processing. */
262int
263ripng_interface_down (int command, struct zclient *zclient,
264 zebra_size_t length)
265{
266 struct stream *s;
267 struct interface *ifp;
268
269 /* zebra_interface_state_read() updates interface structure in iflist. */
270 s = zclient->ibuf;
271 ifp = zebra_interface_state_read (s);
272
273 if (ifp == NULL)
274 return 0;
275
276 ripng_if_down (ifp);
277
278 if (IS_RIPNG_DEBUG_ZEBRA)
ajs2e23ab22004-12-08 19:46:50 +0000279 zlog_debug ("interface down %s index %d flags %ld metric %d mtu %d",
hasso1203e1c2004-07-23 21:34:27 +0000280 ifp->name, ifp->ifindex, ifp->flags, ifp->metric, ifp->mtu6);
paul718e3742002-12-13 20:15:29 +0000281
282 return 0;
283}
284
285/* Inteface addition message from zebra. */
286int
287ripng_interface_add (int command, struct zclient *zclient, zebra_size_t length)
288{
289 struct interface *ifp;
290
291 ifp = zebra_interface_add_read (zclient->ibuf);
292
293 if (IS_RIPNG_DEBUG_ZEBRA)
ajs2e23ab22004-12-08 19:46:50 +0000294 zlog_debug ("RIPng interface add %s index %d flags %ld metric %d mtu %d",
hasso1203e1c2004-07-23 21:34:27 +0000295 ifp->name, ifp->ifindex, ifp->flags, ifp->metric, ifp->mtu6);
paul718e3742002-12-13 20:15:29 +0000296
297 /* Check is this interface is RIP enabled or not.*/
298 ripng_enable_apply (ifp);
299
300 /* Apply distribute list to the interface. */
301 ripng_distribute_update_interface (ifp);
302
303 /* Check interface routemap. */
304 ripng_if_rmap_update_interface (ifp);
305
306 return 0;
307}
308
309int
310ripng_interface_delete (int command, struct zclient *zclient,
311 zebra_size_t length)
312{
hassoa94434b2003-05-25 17:10:12 +0000313 struct interface *ifp;
314 struct stream *s;
315
316 s = zclient->ibuf;
317 /* zebra_interface_state_read() updates interface structure in iflist */
318 ifp = zebra_interface_state_read(s);
319
320 if (ifp == NULL)
321 return 0;
322
323 if (if_is_up (ifp)) {
324 ripng_if_down(ifp);
325 }
326
327 zlog_info("interface delete %s index %d flags %ld metric %d mtu %d",
hasso1203e1c2004-07-23 21:34:27 +0000328 ifp->name, ifp->ifindex, ifp->flags, ifp->metric, ifp->mtu6);
hassoa94434b2003-05-25 17:10:12 +0000329
330 /* To support pseudo interface do not free interface structure. */
331 /* if_delete(ifp); */
ajsd2fc8892005-04-02 18:38:43 +0000332 ifp->ifindex = IFINDEX_INTERNAL;
hassoa94434b2003-05-25 17:10:12 +0000333
paul718e3742002-12-13 20:15:29 +0000334 return 0;
335}
336
hassoa94434b2003-05-25 17:10:12 +0000337void
Paul Jakma6ac29a52008-08-15 13:45:30 +0100338ripng_interface_clean (void)
hassoa94434b2003-05-25 17:10:12 +0000339{
paul1eb8ef22005-04-07 07:30:20 +0000340 struct listnode *node, *nnode;
hassoa94434b2003-05-25 17:10:12 +0000341 struct interface *ifp;
342 struct ripng_interface *ri;
343
paul1eb8ef22005-04-07 07:30:20 +0000344 for (ALL_LIST_ELEMENTS (iflist, node, nnode, ifp))
hassoa94434b2003-05-25 17:10:12 +0000345 {
hassoa94434b2003-05-25 17:10:12 +0000346 ri = ifp->info;
347
348 ri->enable_network = 0;
349 ri->enable_interface = 0;
350 ri->running = 0;
351
352 if (ri->t_wakeup)
353 {
354 thread_cancel (ri->t_wakeup);
355 ri->t_wakeup = NULL;
356 }
357 }
358}
359
360void
Paul Jakma6ac29a52008-08-15 13:45:30 +0100361ripng_interface_reset (void)
362{
hasso52dc7ee2004-09-23 19:18:23 +0000363 struct listnode *node;
hassoa94434b2003-05-25 17:10:12 +0000364 struct interface *ifp;
365 struct ripng_interface *ri;
366
paul1eb8ef22005-04-07 07:30:20 +0000367 for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp))
hassoa94434b2003-05-25 17:10:12 +0000368 {
hassoa94434b2003-05-25 17:10:12 +0000369 ri = ifp->info;
370
371 ri->enable_network = 0;
372 ri->enable_interface = 0;
373 ri->running = 0;
374
375 ri->split_horizon = RIPNG_NO_SPLIT_HORIZON;
376 ri->split_horizon_default = RIPNG_NO_SPLIT_HORIZON;
377
378 ri->list[RIPNG_FILTER_IN] = NULL;
379 ri->list[RIPNG_FILTER_OUT] = NULL;
380
381 ri->prefix[RIPNG_FILTER_IN] = NULL;
382 ri->prefix[RIPNG_FILTER_OUT] = NULL;
383
384 if (ri->t_wakeup)
385 {
386 thread_cancel (ri->t_wakeup);
387 ri->t_wakeup = NULL;
388 }
389
390 ri->passive = 0;
391 }
392}
393
394static void
395ripng_apply_address_add (struct connected *ifc) {
396 struct prefix_ipv6 address;
397 struct prefix *p;
398
399 if (!ripng)
400 return;
401
402 if (! if_is_up(ifc->ifp))
403 return;
404
405 p = ifc->address;
406
407 memset (&address, 0, sizeof (address));
408 address.family = p->family;
409 address.prefix = p->u.prefix6;
410 address.prefixlen = p->prefixlen;
411 apply_mask_ipv6(&address);
412
413 /* Check if this interface is RIP enabled or not
414 or Check if this address's prefix is RIP enabled */
415 if ((ripng_enable_if_lookup(ifc->ifp->name) >= 0) ||
416 (ripng_enable_network_lookup2(ifc) >= 0))
417 ripng_redistribute_add(ZEBRA_ROUTE_CONNECT, RIPNG_ROUTE_INTERFACE,
418 &address, ifc->ifp->ifindex, NULL);
419
420}
421
paul718e3742002-12-13 20:15:29 +0000422int
423ripng_interface_address_add (int command, struct zclient *zclient,
424 zebra_size_t length)
425{
426 struct connected *c;
427 struct prefix *p;
paul718e3742002-12-13 20:15:29 +0000428
paul0a589352004-05-08 11:48:26 +0000429 c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_ADD,
430 zclient->ibuf);
paul718e3742002-12-13 20:15:29 +0000431
432 if (c == NULL)
433 return 0;
434
435 p = c->address;
436
437 if (p->family == AF_INET6)
438 {
Paul Jakma995b9652006-05-11 13:20:47 +0000439 struct ripng_interface *ri = c->ifp->info;
440
paul718e3742002-12-13 20:15:29 +0000441 if (IS_RIPNG_DEBUG_ZEBRA)
ajs2e23ab22004-12-08 19:46:50 +0000442 zlog_debug ("RIPng connected address %s/%d add",
hasso3a2ce6a2005-04-08 01:30:51 +0000443 inet6_ntoa(p->u.prefix6),
paul718e3742002-12-13 20:15:29 +0000444 p->prefixlen);
445
hassoa94434b2003-05-25 17:10:12 +0000446 /* Check is this prefix needs to be redistributed. */
447 ripng_apply_address_add(c);
448
449 /* Let's try once again whether the interface could be activated */
Paul Jakma995b9652006-05-11 13:20:47 +0000450 if (!ri->running) {
451 /* Check if this interface is RIP enabled or not.*/
452 ripng_enable_apply (c->ifp);
hassoa94434b2003-05-25 17:10:12 +0000453
Paul Jakma995b9652006-05-11 13:20:47 +0000454 /* Apply distribute list to the interface. */
455 ripng_distribute_update_interface (c->ifp);
hassoa94434b2003-05-25 17:10:12 +0000456
Paul Jakma995b9652006-05-11 13:20:47 +0000457 /* Check interface routemap. */
458 ripng_if_rmap_update_interface (c->ifp);
hassoa94434b2003-05-25 17:10:12 +0000459 }
460
paul718e3742002-12-13 20:15:29 +0000461 }
462
463 return 0;
464}
465
hassoa94434b2003-05-25 17:10:12 +0000466static void
467ripng_apply_address_del (struct connected *ifc) {
468 struct prefix_ipv6 address;
469 struct prefix *p;
470
471 if (!ripng)
472 return;
473
474 if (! if_is_up(ifc->ifp))
475 return;
476
477 p = ifc->address;
478
479 memset (&address, 0, sizeof (address));
480 address.family = p->family;
481 address.prefix = p->u.prefix6;
482 address.prefixlen = p->prefixlen;
483 apply_mask_ipv6(&address);
484
485 ripng_redistribute_delete(ZEBRA_ROUTE_CONNECT, RIPNG_ROUTE_INTERFACE,
486 &address, ifc->ifp->ifindex);
487}
488
paul718e3742002-12-13 20:15:29 +0000489int
490ripng_interface_address_delete (int command, struct zclient *zclient,
491 zebra_size_t length)
492{
493 struct connected *ifc;
494 struct prefix *p;
495 char buf[INET6_ADDRSTRLEN];
496
paul0a589352004-05-08 11:48:26 +0000497 ifc = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_DELETE,
498 zclient->ibuf);
paul718e3742002-12-13 20:15:29 +0000499
500 if (ifc)
501 {
502 p = ifc->address;
503
504 if (p->family == AF_INET6)
505 {
506 if (IS_RIPNG_DEBUG_ZEBRA)
ajs2e23ab22004-12-08 19:46:50 +0000507 zlog_debug ("RIPng connected address %s/%d delete",
paul718e3742002-12-13 20:15:29 +0000508 inet_ntop (AF_INET6, &p->u.prefix6, buf,
509 INET6_ADDRSTRLEN),
510 p->prefixlen);
511
hassoa94434b2003-05-25 17:10:12 +0000512 /* Check wether this prefix needs to be removed. */
513 ripng_apply_address_del(ifc);
paul718e3742002-12-13 20:15:29 +0000514 }
515 connected_free (ifc);
516 }
517
518 return 0;
519}
520
521/* RIPng enable interface vector. */
522vector ripng_enable_if;
523
524/* RIPng enable network table. */
525struct route_table *ripng_enable_network;
526
527/* Lookup RIPng enable network. */
hassoa94434b2003-05-25 17:10:12 +0000528/* Check wether the interface has at least a connected prefix that
529 * is within the ripng_enable_network table. */
Paul Jakma6ac29a52008-08-15 13:45:30 +0100530static int
hassoa94434b2003-05-25 17:10:12 +0000531ripng_enable_network_lookup_if (struct interface *ifp)
paul718e3742002-12-13 20:15:29 +0000532{
paul1eb8ef22005-04-07 07:30:20 +0000533 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000534 struct connected *connected;
hassoa94434b2003-05-25 17:10:12 +0000535 struct prefix_ipv6 address;
paul718e3742002-12-13 20:15:29 +0000536
paul1eb8ef22005-04-07 07:30:20 +0000537 for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, connected))
538 {
539 struct prefix *p;
540 struct route_node *node;
paul718e3742002-12-13 20:15:29 +0000541
paul1eb8ef22005-04-07 07:30:20 +0000542 p = connected->address;
paul718e3742002-12-13 20:15:29 +0000543
paul1eb8ef22005-04-07 07:30:20 +0000544 if (p->family == AF_INET6)
545 {
546 address.family = AF_INET6;
547 address.prefix = p->u.prefix6;
548 address.prefixlen = IPV6_MAX_BITLEN;
hassoa94434b2003-05-25 17:10:12 +0000549
paul1eb8ef22005-04-07 07:30:20 +0000550 node = route_node_match (ripng_enable_network,
551 (struct prefix *)&address);
552 if (node)
553 {
554 route_unlock_node (node);
555 return 1;
556 }
557 }
558 }
paul718e3742002-12-13 20:15:29 +0000559 return -1;
560}
561
hassoa94434b2003-05-25 17:10:12 +0000562/* Check wether connected is within the ripng_enable_network table. */
Paul Jakma6ac29a52008-08-15 13:45:30 +0100563static int
hassoa94434b2003-05-25 17:10:12 +0000564ripng_enable_network_lookup2 (struct connected *connected)
565{
566 struct prefix_ipv6 address;
567 struct prefix *p;
568
569 p = connected->address;
570
571 if (p->family == AF_INET6) {
572 struct route_node *node;
573
574 address.family = p->family;
575 address.prefix = p->u.prefix6;
576 address.prefixlen = IPV6_MAX_BITLEN;
577
578 /* LPM on p->family, p->u.prefix6/IPV6_MAX_BITLEN within ripng_enable_network */
579 node = route_node_match (ripng_enable_network,
580 (struct prefix *)&address);
581
582 if (node) {
583 route_unlock_node (node);
584 return 1;
585 }
586 }
587
588 return -1;
589}
590
paul718e3742002-12-13 20:15:29 +0000591/* Add RIPng enable network. */
Paul Jakma6ac29a52008-08-15 13:45:30 +0100592static int
paul718e3742002-12-13 20:15:29 +0000593ripng_enable_network_add (struct prefix *p)
594{
595 struct route_node *node;
596
597 node = route_node_get (ripng_enable_network, p);
598
599 if (node->info)
600 {
601 route_unlock_node (node);
602 return -1;
603 }
604 else
hasso7a1d5832004-10-08 06:32:23 +0000605 node->info = (char *) "enabled";
paul718e3742002-12-13 20:15:29 +0000606
hassoa94434b2003-05-25 17:10:12 +0000607 /* XXX: One should find a better solution than a generic one */
608 ripng_enable_apply_all();
609
paul718e3742002-12-13 20:15:29 +0000610 return 1;
611}
612
613/* Delete RIPng enable network. */
Paul Jakma6ac29a52008-08-15 13:45:30 +0100614static int
paul718e3742002-12-13 20:15:29 +0000615ripng_enable_network_delete (struct prefix *p)
616{
617 struct route_node *node;
618
619 node = route_node_lookup (ripng_enable_network, p);
620 if (node)
621 {
622 node->info = NULL;
623
624 /* Unlock info lock. */
625 route_unlock_node (node);
626
627 /* Unlock lookup lock. */
628 route_unlock_node (node);
629
630 return 1;
631 }
632 return -1;
633}
634
635/* Lookup function. */
Paul Jakma6ac29a52008-08-15 13:45:30 +0100636static int
hasso98b718a2004-10-11 12:57:57 +0000637ripng_enable_if_lookup (const char *ifname)
paul718e3742002-12-13 20:15:29 +0000638{
hasso7a1d5832004-10-08 06:32:23 +0000639 unsigned int i;
paul718e3742002-12-13 20:15:29 +0000640 char *str;
641
paul55468c82005-03-14 20:19:01 +0000642 for (i = 0; i < vector_active (ripng_enable_if); i++)
paul718e3742002-12-13 20:15:29 +0000643 if ((str = vector_slot (ripng_enable_if, i)) != NULL)
644 if (strcmp (str, ifname) == 0)
645 return i;
646 return -1;
647}
648
649/* Add interface to ripng_enable_if. */
Paul Jakma6ac29a52008-08-15 13:45:30 +0100650static int
hasso98b718a2004-10-11 12:57:57 +0000651ripng_enable_if_add (const char *ifname)
paul718e3742002-12-13 20:15:29 +0000652{
653 int ret;
654
655 ret = ripng_enable_if_lookup (ifname);
656 if (ret >= 0)
657 return -1;
658
659 vector_set (ripng_enable_if, strdup (ifname));
660
hassoa94434b2003-05-25 17:10:12 +0000661 ripng_enable_apply_all();
662
paul718e3742002-12-13 20:15:29 +0000663 return 1;
664}
665
666/* Delete interface from ripng_enable_if. */
Paul Jakma6ac29a52008-08-15 13:45:30 +0100667static int
hasso98b718a2004-10-11 12:57:57 +0000668ripng_enable_if_delete (const char *ifname)
paul718e3742002-12-13 20:15:29 +0000669{
670 int index;
671 char *str;
672
673 index = ripng_enable_if_lookup (ifname);
674 if (index < 0)
675 return -1;
676
677 str = vector_slot (ripng_enable_if, index);
678 free (str);
679 vector_unset (ripng_enable_if, index);
680
hassoa94434b2003-05-25 17:10:12 +0000681 ripng_enable_apply_all();
682
paul718e3742002-12-13 20:15:29 +0000683 return 1;
684}
685
686/* Wake up interface. */
Paul Jakma6ac29a52008-08-15 13:45:30 +0100687static int
paul718e3742002-12-13 20:15:29 +0000688ripng_interface_wakeup (struct thread *t)
689{
690 struct interface *ifp;
691 struct ripng_interface *ri;
692
693 /* Get interface. */
694 ifp = THREAD_ARG (t);
695
696 ri = ifp->info;
697 ri->t_wakeup = NULL;
698
699 /* Join to multicast group. */
hassoa94434b2003-05-25 17:10:12 +0000700 if (ripng_multicast_join (ifp) < 0) {
701 zlog_err ("multicast join failed, interface %s not running", ifp->name);
702 return 0;
703 }
704
705 /* Set running flag. */
706 ri->running = 1;
paul718e3742002-12-13 20:15:29 +0000707
708 /* Send RIP request to the interface. */
709 ripng_request (ifp);
710
711 return 0;
712}
713
Paul Jakma6ac29a52008-08-15 13:45:30 +0100714static void
hassoa94434b2003-05-25 17:10:12 +0000715ripng_connect_set (struct interface *ifp, int set)
716{
paul1eb8ef22005-04-07 07:30:20 +0000717 struct listnode *node, *nnode;
hassoa94434b2003-05-25 17:10:12 +0000718 struct connected *connected;
719 struct prefix_ipv6 address;
720
paul1eb8ef22005-04-07 07:30:20 +0000721 for (ALL_LIST_ELEMENTS (ifp->connected, node, nnode, connected))
722 {
hassoa94434b2003-05-25 17:10:12 +0000723 struct prefix *p;
724 p = connected->address;
725
726 if (p->family != AF_INET6)
727 continue;
728
729 address.family = AF_INET6;
730 address.prefix = p->u.prefix6;
731 address.prefixlen = p->prefixlen;
732 apply_mask_ipv6 (&address);
733
734 if (set) {
735 /* Check once more wether this prefix is within a "network IF_OR_PREF" one */
736 if ((ripng_enable_if_lookup(connected->ifp->name) >= 0) ||
737 (ripng_enable_network_lookup2(connected) >= 0))
738 ripng_redistribute_add (ZEBRA_ROUTE_CONNECT, RIPNG_ROUTE_INTERFACE,
739 &address, connected->ifp->ifindex, NULL);
740 } else {
741 ripng_redistribute_delete (ZEBRA_ROUTE_CONNECT, RIPNG_ROUTE_INTERFACE,
742 &address, connected->ifp->ifindex);
743 if (ripng_redistribute_check (ZEBRA_ROUTE_CONNECT))
744 ripng_redistribute_add (ZEBRA_ROUTE_CONNECT, RIPNG_ROUTE_REDISTRIBUTE,
745 &address, connected->ifp->ifindex, NULL);
746 }
747 }
748}
749
paul718e3742002-12-13 20:15:29 +0000750/* Check RIPng is enabed on this interface. */
751void
752ripng_enable_apply (struct interface *ifp)
753{
754 int ret;
755 struct ripng_interface *ri = NULL;
756
757 /* Check interface. */
paul718e3742002-12-13 20:15:29 +0000758 if (! if_is_up (ifp))
759 return;
760
761 ri = ifp->info;
762
hassoa94434b2003-05-25 17:10:12 +0000763 /* Is this interface a candidate for RIPng ? */
764 ret = ripng_enable_network_lookup_if (ifp);
paul718e3742002-12-13 20:15:29 +0000765
766 /* If the interface is matched. */
767 if (ret > 0)
768 ri->enable_network = 1;
769 else
770 ri->enable_network = 0;
771
772 /* Check interface name configuration. */
773 ret = ripng_enable_if_lookup (ifp->name);
774 if (ret >= 0)
775 ri->enable_interface = 1;
776 else
777 ri->enable_interface = 0;
778
hassoa94434b2003-05-25 17:10:12 +0000779 /* any candidate interface MUST have a link-local IPv6 address */
780 if ((! ripng_if_ipv6_lladdress_check (ifp)) &&
781 (ri->enable_network || ri->enable_interface)) {
782 ri->enable_network = 0;
783 ri->enable_interface = 0;
784 zlog_warn("Interface %s does not have any link-local address",
785 ifp->name);
786 }
787
paul718e3742002-12-13 20:15:29 +0000788 /* Update running status of the interface. */
789 if (ri->enable_network || ri->enable_interface)
790 {
paul718e3742002-12-13 20:15:29 +0000791 {
792 if (IS_RIPNG_DEBUG_EVENT)
ajs2e23ab22004-12-08 19:46:50 +0000793 zlog_debug ("RIPng turn on %s", ifp->name);
paul718e3742002-12-13 20:15:29 +0000794
795 /* Add interface wake up thread. */
796 if (! ri->t_wakeup)
797 ri->t_wakeup = thread_add_timer (master, ripng_interface_wakeup,
798 ifp, 1);
paul718e3742002-12-13 20:15:29 +0000799
hassoa94434b2003-05-25 17:10:12 +0000800 ripng_connect_set (ifp, 1);
paul718e3742002-12-13 20:15:29 +0000801 }
802 }
803 else
804 {
805 if (ri->running)
806 {
hassoa94434b2003-05-25 17:10:12 +0000807 /* Might as well clean up the route table as well
808 * ripng_if_down sets to 0 ri->running, and displays "turn off %s"
809 **/
810 ripng_if_down(ifp);
paul718e3742002-12-13 20:15:29 +0000811
hassoa94434b2003-05-25 17:10:12 +0000812 ripng_connect_set (ifp, 0);
paul718e3742002-12-13 20:15:29 +0000813 }
814 }
815}
816
817/* Set distribute list to all interfaces. */
Paul Jakma6ac29a52008-08-15 13:45:30 +0100818static void
819ripng_enable_apply_all (void)
paul718e3742002-12-13 20:15:29 +0000820{
821 struct interface *ifp;
hasso52dc7ee2004-09-23 19:18:23 +0000822 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000823
paul1eb8ef22005-04-07 07:30:20 +0000824 for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp))
825 ripng_enable_apply (ifp);
paul718e3742002-12-13 20:15:29 +0000826}
827
hassoa94434b2003-05-25 17:10:12 +0000828/* Clear all network and neighbor configuration */
829void
830ripng_clean_network ()
831{
hasso7a1d5832004-10-08 06:32:23 +0000832 unsigned int i;
hassoa94434b2003-05-25 17:10:12 +0000833 char *str;
834 struct route_node *rn;
835
836 /* ripng_enable_network */
837 for (rn = route_top (ripng_enable_network); rn; rn = route_next (rn))
838 if (rn->info) {
839 rn->info = NULL;
840 route_unlock_node(rn);
841 }
842
843 /* ripng_enable_if */
paul55468c82005-03-14 20:19:01 +0000844 for (i = 0; i < vector_active (ripng_enable_if); i++)
hassoa94434b2003-05-25 17:10:12 +0000845 if ((str = vector_slot (ripng_enable_if, i)) != NULL) {
846 free (str);
847 vector_slot (ripng_enable_if, i) = NULL;
848 }
849}
850
paul718e3742002-12-13 20:15:29 +0000851/* Vector to store passive-interface name. */
852vector Vripng_passive_interface;
853
854/* Utility function for looking up passive interface settings. */
Paul Jakma6ac29a52008-08-15 13:45:30 +0100855static int
hasso98b718a2004-10-11 12:57:57 +0000856ripng_passive_interface_lookup (const char *ifname)
paul718e3742002-12-13 20:15:29 +0000857{
hasso7a1d5832004-10-08 06:32:23 +0000858 unsigned int i;
paul718e3742002-12-13 20:15:29 +0000859 char *str;
860
paul55468c82005-03-14 20:19:01 +0000861 for (i = 0; i < vector_active (Vripng_passive_interface); i++)
paul718e3742002-12-13 20:15:29 +0000862 if ((str = vector_slot (Vripng_passive_interface, i)) != NULL)
863 if (strcmp (str, ifname) == 0)
864 return i;
865 return -1;
866}
867
868void
869ripng_passive_interface_apply (struct interface *ifp)
870{
871 int ret;
872 struct ripng_interface *ri;
873
874 ri = ifp->info;
875
876 ret = ripng_passive_interface_lookup (ifp->name);
877 if (ret < 0)
878 ri->passive = 0;
879 else
880 ri->passive = 1;
881}
882
Paul Jakma6ac29a52008-08-15 13:45:30 +0100883static void
paul718e3742002-12-13 20:15:29 +0000884ripng_passive_interface_apply_all (void)
885{
886 struct interface *ifp;
hasso52dc7ee2004-09-23 19:18:23 +0000887 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000888
paul1eb8ef22005-04-07 07:30:20 +0000889 for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp))
890 ripng_passive_interface_apply (ifp);
paul718e3742002-12-13 20:15:29 +0000891}
892
893/* Passive interface. */
Paul Jakma6ac29a52008-08-15 13:45:30 +0100894static int
hasso98b718a2004-10-11 12:57:57 +0000895ripng_passive_interface_set (struct vty *vty, const char *ifname)
paul718e3742002-12-13 20:15:29 +0000896{
897 if (ripng_passive_interface_lookup (ifname) >= 0)
898 return CMD_WARNING;
899
900 vector_set (Vripng_passive_interface, strdup (ifname));
901
902 ripng_passive_interface_apply_all ();
903
904 return CMD_SUCCESS;
905}
906
Paul Jakma6ac29a52008-08-15 13:45:30 +0100907static int
hasso98b718a2004-10-11 12:57:57 +0000908ripng_passive_interface_unset (struct vty *vty, const char *ifname)
paul718e3742002-12-13 20:15:29 +0000909{
910 int i;
911 char *str;
912
913 i = ripng_passive_interface_lookup (ifname);
914 if (i < 0)
915 return CMD_WARNING;
916
917 str = vector_slot (Vripng_passive_interface, i);
918 free (str);
919 vector_unset (Vripng_passive_interface, i);
920
921 ripng_passive_interface_apply_all ();
922
923 return CMD_SUCCESS;
924}
925
926/* Free all configured RIP passive-interface settings. */
927void
928ripng_passive_interface_clean (void)
929{
hasso7a1d5832004-10-08 06:32:23 +0000930 unsigned int i;
paul718e3742002-12-13 20:15:29 +0000931 char *str;
932
paul55468c82005-03-14 20:19:01 +0000933 for (i = 0; i < vector_active (Vripng_passive_interface); i++)
paul718e3742002-12-13 20:15:29 +0000934 if ((str = vector_slot (Vripng_passive_interface, i)) != NULL)
935 {
936 free (str);
937 vector_slot (Vripng_passive_interface, i) = NULL;
938 }
939 ripng_passive_interface_apply_all ();
940}
941
942/* Write RIPng enable network and interface to the vty. */
943int
hassoa94434b2003-05-25 17:10:12 +0000944ripng_network_write (struct vty *vty, int config_mode)
paul718e3742002-12-13 20:15:29 +0000945{
hasso7a1d5832004-10-08 06:32:23 +0000946 unsigned int i;
hasso98b718a2004-10-11 12:57:57 +0000947 const char *ifname;
paul718e3742002-12-13 20:15:29 +0000948 struct route_node *node;
949 char buf[BUFSIZ];
950
951 /* Write enable network. */
952 for (node = route_top (ripng_enable_network); node; node = route_next (node))
953 if (node->info)
954 {
955 struct prefix *p = &node->p;
hassoa94434b2003-05-25 17:10:12 +0000956 vty_out (vty, "%s%s/%d%s",
957 config_mode ? " network " : " ",
paul718e3742002-12-13 20:15:29 +0000958 inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
959 p->prefixlen,
960 VTY_NEWLINE);
961
962 }
963
964 /* Write enable interface. */
paul55468c82005-03-14 20:19:01 +0000965 for (i = 0; i < vector_active (ripng_enable_if); i++)
hassoa94434b2003-05-25 17:10:12 +0000966 if ((ifname = vector_slot (ripng_enable_if, i)) != NULL)
967 vty_out (vty, "%s%s%s",
968 config_mode ? " network " : " ",
969 ifname,
paul718e3742002-12-13 20:15:29 +0000970 VTY_NEWLINE);
971
972 /* Write passive interface. */
hassoa94434b2003-05-25 17:10:12 +0000973 if (config_mode)
paul55468c82005-03-14 20:19:01 +0000974 for (i = 0; i < vector_active (Vripng_passive_interface); i++)
hassoa94434b2003-05-25 17:10:12 +0000975 if ((ifname = vector_slot (Vripng_passive_interface, i)) != NULL)
976 vty_out (vty, " passive-interface %s%s", ifname, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +0000977
978 return 0;
979}
980
981/* RIPng enable on specified interface or matched network. */
982DEFUN (ripng_network,
983 ripng_network_cmd,
984 "network IF_OR_ADDR",
985 "RIPng enable on specified interface or network.\n"
986 "Interface or address")
987{
988 int ret;
989 struct prefix p;
990
991 ret = str2prefix (argv[0], &p);
992
993 /* Given string is IPv6 network or interface name. */
994 if (ret)
995 ret = ripng_enable_network_add (&p);
996 else
997 ret = ripng_enable_if_add (argv[0]);
998
999 if (ret < 0)
1000 {
1001 vty_out (vty, "There is same network configuration %s%s", argv[0],
1002 VTY_NEWLINE);
1003 return CMD_WARNING;
1004 }
1005
paul718e3742002-12-13 20:15:29 +00001006 return CMD_SUCCESS;
1007}
1008
1009/* RIPng enable on specified interface or matched network. */
1010DEFUN (no_ripng_network,
1011 no_ripng_network_cmd,
1012 "no network IF_OR_ADDR",
1013 NO_STR
1014 "RIPng enable on specified interface or network.\n"
1015 "Interface or address")
1016{
1017 int ret;
1018 struct prefix p;
1019
1020 ret = str2prefix (argv[0], &p);
1021
1022 /* Given string is interface name. */
1023 if (ret)
1024 ret = ripng_enable_network_delete (&p);
1025 else
1026 ret = ripng_enable_if_delete (argv[0]);
1027
1028 if (ret < 0)
1029 {
1030 vty_out (vty, "can't find network %s%s", argv[0],
1031 VTY_NEWLINE);
1032 return CMD_WARNING;
1033 }
1034
paul718e3742002-12-13 20:15:29 +00001035 return CMD_SUCCESS;
1036}
1037
hassoa94434b2003-05-25 17:10:12 +00001038DEFUN (ipv6_ripng_split_horizon,
1039 ipv6_ripng_split_horizon_cmd,
1040 "ipv6 ripng split-horizon",
1041 IPV6_STR
1042 "Routing Information Protocol\n"
1043 "Perform split horizon\n")
1044{
1045 struct interface *ifp;
1046 struct ripng_interface *ri;
1047
1048 ifp = vty->index;
1049 ri = ifp->info;
1050
1051 ri->split_horizon = RIPNG_SPLIT_HORIZON;
1052 return CMD_SUCCESS;
1053}
1054
1055DEFUN (ipv6_ripng_split_horizon_poisoned_reverse,
1056 ipv6_ripng_split_horizon_poisoned_reverse_cmd,
1057 "ipv6 ripng split-horizon poisoned-reverse",
1058 IPV6_STR
1059 "Routing Information Protocol\n"
1060 "Perform split horizon\n"
1061 "With poisoned-reverse\n")
1062{
1063 struct interface *ifp;
1064 struct ripng_interface *ri;
1065
1066 ifp = vty->index;
1067 ri = ifp->info;
1068
1069 ri->split_horizon = RIPNG_SPLIT_HORIZON_POISONED_REVERSE;
1070 return CMD_SUCCESS;
1071}
1072
1073DEFUN (no_ipv6_ripng_split_horizon,
1074 no_ipv6_ripng_split_horizon_cmd,
1075 "no ipv6 ripng split-horizon",
1076 NO_STR
1077 IPV6_STR
1078 "Routing Information Protocol\n"
1079 "Perform split horizon\n")
1080{
1081 struct interface *ifp;
1082 struct ripng_interface *ri;
1083
1084 ifp = vty->index;
1085 ri = ifp->info;
1086
1087 ri->split_horizon = RIPNG_NO_SPLIT_HORIZON;
1088 return CMD_SUCCESS;
1089}
1090
1091ALIAS (no_ipv6_ripng_split_horizon,
1092 no_ipv6_ripng_split_horizon_poisoned_reverse_cmd,
1093 "no ipv6 ripng split-horizon poisoned-reverse",
1094 NO_STR
1095 IPV6_STR
1096 "Routing Information Protocol\n"
1097 "Perform split horizon\n"
1098 "With poisoned-reverse\n")
1099
paul718e3742002-12-13 20:15:29 +00001100DEFUN (ripng_passive_interface,
1101 ripng_passive_interface_cmd,
1102 "passive-interface IFNAME",
1103 "Suppress routing updates on an interface\n"
1104 "Interface name\n")
1105{
1106 return ripng_passive_interface_set (vty, argv[0]);
1107}
1108
1109DEFUN (no_ripng_passive_interface,
1110 no_ripng_passive_interface_cmd,
1111 "no passive-interface IFNAME",
1112 NO_STR
1113 "Suppress routing updates on an interface\n"
1114 "Interface name\n")
1115{
1116 return ripng_passive_interface_unset (vty, argv[0]);
1117}
1118
Paul Jakma6ac29a52008-08-15 13:45:30 +01001119static struct ripng_interface *
1120ri_new (void)
paul718e3742002-12-13 20:15:29 +00001121{
1122 struct ripng_interface *ri;
1123 ri = XCALLOC (MTYPE_IF, sizeof (struct ripng_interface));
hassoa94434b2003-05-25 17:10:12 +00001124
1125 /* Set default split-horizon behavior. If the interface is Frame
1126 Relay or SMDS is enabled, the default value for split-horizon is
1127 off. But currently Zebra does detect Frame Relay or SMDS
1128 interface. So all interface is set to split horizon. */
1129 ri->split_horizon_default = RIPNG_SPLIT_HORIZON;
1130 ri->split_horizon = ri->split_horizon_default;
1131
paul718e3742002-12-13 20:15:29 +00001132 return ri;
1133}
1134
Paul Jakma6ac29a52008-08-15 13:45:30 +01001135static int
paul718e3742002-12-13 20:15:29 +00001136ripng_if_new_hook (struct interface *ifp)
1137{
1138 ifp->info = ri_new ();
1139 return 0;
1140}
1141
hassoa94434b2003-05-25 17:10:12 +00001142/* Called when interface structure deleted. */
Paul Jakma6ac29a52008-08-15 13:45:30 +01001143static int
hassoa94434b2003-05-25 17:10:12 +00001144ripng_if_delete_hook (struct interface *ifp)
1145{
1146 XFREE (MTYPE_IF, ifp->info);
1147 ifp->info = NULL;
1148 return 0;
1149}
1150
paul718e3742002-12-13 20:15:29 +00001151/* Configuration write function for ripngd. */
Paul Jakma6ac29a52008-08-15 13:45:30 +01001152static int
paul718e3742002-12-13 20:15:29 +00001153interface_config_write (struct vty *vty)
1154{
hasso52dc7ee2004-09-23 19:18:23 +00001155 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001156 struct interface *ifp;
1157 struct ripng_interface *ri;
1158 int write = 0;
1159
paul1eb8ef22005-04-07 07:30:20 +00001160 for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp))
paul718e3742002-12-13 20:15:29 +00001161 {
paul718e3742002-12-13 20:15:29 +00001162 ri = ifp->info;
1163
hassoa94434b2003-05-25 17:10:12 +00001164 /* Do not display the interface if there is no
1165 * configuration about it.
1166 **/
1167 if ((!ifp->desc) &&
1168 (ri->split_horizon == ri->split_horizon_default))
1169 continue;
1170
paul718e3742002-12-13 20:15:29 +00001171 vty_out (vty, "interface %s%s", ifp->name,
1172 VTY_NEWLINE);
1173 if (ifp->desc)
1174 vty_out (vty, " description %s%s", ifp->desc,
1175 VTY_NEWLINE);
1176
hassoa94434b2003-05-25 17:10:12 +00001177 /* Split horizon. */
1178 if (ri->split_horizon != ri->split_horizon_default)
1179 {
1180 switch (ri->split_horizon) {
1181 case RIPNG_SPLIT_HORIZON:
1182 vty_out (vty, " ipv6 ripng split-horizon%s", VTY_NEWLINE);
1183 break;
1184 case RIPNG_SPLIT_HORIZON_POISONED_REVERSE:
1185 vty_out (vty, " ipv6 ripng split-horizon poisoned-reverse%s",
1186 VTY_NEWLINE);
1187 break;
1188 case RIPNG_NO_SPLIT_HORIZON:
1189 default:
1190 vty_out (vty, " no ipv6 ripng split-horizon%s", VTY_NEWLINE);
1191 break;
1192 }
1193 }
1194
paul718e3742002-12-13 20:15:29 +00001195 vty_out (vty, "!%s", VTY_NEWLINE);
1196
1197 write++;
1198 }
1199 return write;
1200}
1201
1202/* ripngd's interface node. */
Stephen Hemminger7fc626d2008-12-01 11:10:34 -08001203static struct cmd_node interface_node =
paul718e3742002-12-13 20:15:29 +00001204{
1205 INTERFACE_NODE,
1206 "%s(config-if)# ",
hassoa94434b2003-05-25 17:10:12 +00001207 1 /* VTYSH */
paul718e3742002-12-13 20:15:29 +00001208};
1209
1210/* Initialization of interface. */
1211void
1212ripng_if_init ()
1213{
1214 /* Interface initialize. */
1215 iflist = list_new ();
1216 if_add_hook (IF_NEW_HOOK, ripng_if_new_hook);
hassoa94434b2003-05-25 17:10:12 +00001217 if_add_hook (IF_DELETE_HOOK, ripng_if_delete_hook);
paul718e3742002-12-13 20:15:29 +00001218
1219 /* RIPng enable network init. */
1220 ripng_enable_network = route_table_init ();
1221
1222 /* RIPng enable interface init. */
1223 ripng_enable_if = vector_init (1);
1224
1225 /* RIPng passive interface. */
1226 Vripng_passive_interface = vector_init (1);
1227
1228 /* Install interface node. */
1229 install_node (&interface_node, interface_config_write);
hassoa94434b2003-05-25 17:10:12 +00001230
1231 /* Install commands. */
paul718e3742002-12-13 20:15:29 +00001232 install_element (CONFIG_NODE, &interface_cmd);
paul32d24632003-05-23 09:25:20 +00001233 install_element (CONFIG_NODE, &no_interface_cmd);
hassoa94434b2003-05-25 17:10:12 +00001234 install_default (INTERFACE_NODE);
paul718e3742002-12-13 20:15:29 +00001235 install_element (INTERFACE_NODE, &interface_desc_cmd);
1236 install_element (INTERFACE_NODE, &no_interface_desc_cmd);
1237
1238 install_element (RIPNG_NODE, &ripng_network_cmd);
1239 install_element (RIPNG_NODE, &no_ripng_network_cmd);
1240 install_element (RIPNG_NODE, &ripng_passive_interface_cmd);
1241 install_element (RIPNG_NODE, &no_ripng_passive_interface_cmd);
hassoa94434b2003-05-25 17:10:12 +00001242
1243 install_element (INTERFACE_NODE, &ipv6_ripng_split_horizon_cmd);
1244 install_element (INTERFACE_NODE, &ipv6_ripng_split_horizon_poisoned_reverse_cmd);
1245 install_element (INTERFACE_NODE, &no_ipv6_ripng_split_horizon_cmd);
1246 install_element (INTERFACE_NODE, &no_ipv6_ripng_split_horizon_poisoned_reverse_cmd);
paul718e3742002-12-13 20:15:29 +00001247}