]> git.proxmox.com Git - mirror_frr.git/blame - ripngd/ripngd.c
vtysh: return non-zero for configuration failures
[mirror_frr.git] / ripngd / ripngd.c
CommitLineData
718e3744 1/* RIPng daemon
2 * Copyright (C) 1998, 1999 Kunihiro Ishiguro
3 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
896014f4
DL
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
718e3744 19 */
20
21#include <zebra.h>
22
718e3744 23#include "prefix.h"
24#include "filter.h"
25#include "log.h"
26#include "thread.h"
27#include "memory.h"
28#include "if.h"
29#include "stream.h"
30#include "table.h"
31#include "command.h"
32#include "sockopt.h"
33#include "distribute.h"
34#include "plist.h"
35#include "routemap.h"
0750d21f 36#include "if_rmap.h"
27d47aa7 37#include "privs.h"
718e3744 38
39#include "ripngd/ripngd.h"
40#include "ripngd/ripng_route.h"
41#include "ripngd/ripng_debug.h"
a94434b6 42#include "ripngd/ripng_nexthop.h"
718e3744 43
44/* RIPng structure which includes many parameters related to RIPng
45 protocol. If ripng couldn't active or ripng doesn't configured,
46 ripng->fd must be negative value. */
47struct ripng *ripng = NULL;
48
49enum
50{
51 ripng_all_route,
52 ripng_changed_route,
718e3744 53};
54
27d47aa7 55extern struct zebra_privs_t ripngd_privs;
56
718e3744 57/* Prototypes. */
58void
a94434b6 59ripng_output_process (struct interface *, struct sockaddr_in6 *, int);
718e3744 60
61int
62ripng_triggered_update (struct thread *);
63
64/* RIPng next hop specification. */
65struct ripng_nexthop
66{
67 enum ripng_nexthop_type
68 {
69 RIPNG_NEXTHOP_UNSPEC,
70 RIPNG_NEXTHOP_ADDRESS
71 } flag;
72 struct in6_addr address;
73};
718e3744 74
6ac29a51 75static int
a94434b6 76ripng_route_rte (struct ripng_info *rinfo)
77{
78 return (rinfo->type == ZEBRA_ROUTE_RIPNG && rinfo->sub_type == RIPNG_ROUTE_RTE);
79}
80
718e3744 81/* Allocate new ripng information. */
82struct ripng_info *
83ripng_info_new ()
84{
85 struct ripng_info *new;
86
87 new = XCALLOC (MTYPE_RIPNG_ROUTE, sizeof (struct ripng_info));
88 return new;
89}
90
91/* Free ripng information. */
92void
93ripng_info_free (struct ripng_info *rinfo)
94{
95 XFREE (MTYPE_RIPNG_ROUTE, rinfo);
96}
6b0655a2 97
718e3744 98/* Create ripng socket. */
6ac29a51 99static int
718e3744 100ripng_make_socket (void)
101{
102 int ret;
103 int sock;
104 struct sockaddr_in6 ripaddr;
105
106 sock = socket (AF_INET6, SOCK_DGRAM, 0);
107 if (sock < 0)
108 {
4525281a 109 zlog_err("Can't make ripng socket");
718e3744 110 return sock;
111 }
112
6228a3b8 113 setsockopt_so_recvbuf (sock, 8096);
718e3744 114 ret = setsockopt_ipv6_pktinfo (sock, 1);
115 if (ret < 0)
116 return ret;
6d0732c8
SH
117#ifdef IPTOS_PREC_INTERNETCONTROL
118 ret = setsockopt_ipv6_tclass (sock, IPTOS_PREC_INTERNETCONTROL);
119 if (ret < 0)
120 return ret;
121#endif
718e3744 122 ret = setsockopt_ipv6_multicast_hops (sock, 255);
123 if (ret < 0)
124 return ret;
125 ret = setsockopt_ipv6_multicast_loop (sock, 0);
126 if (ret < 0)
127 return ret;
128 ret = setsockopt_ipv6_hoplimit (sock, 1);
129 if (ret < 0)
130 return ret;
131
132 memset (&ripaddr, 0, sizeof (ripaddr));
133 ripaddr.sin6_family = AF_INET6;
134#ifdef SIN6_LEN
135 ripaddr.sin6_len = sizeof (struct sockaddr_in6);
136#endif /* SIN6_LEN */
137 ripaddr.sin6_port = htons (RIPNG_PORT_DEFAULT);
138
27d47aa7 139 if (ripngd_privs.change (ZPRIVS_RAISE))
140 zlog_err ("ripng_make_socket: could not raise privs");
141
718e3744 142 ret = bind (sock, (struct sockaddr *) &ripaddr, sizeof (ripaddr));
143 if (ret < 0)
27d47aa7 144 {
4525281a 145 zlog_err("Can't bind ripng socket: %s.", safe_strerror(errno));
27d47aa7 146 if (ripngd_privs.change (ZPRIVS_LOWER))
147 zlog_err ("ripng_make_socket: could not lower privs");
148 return ret;
149 }
150 if (ripngd_privs.change (ZPRIVS_LOWER))
151 zlog_err ("ripng_make_socket: could not lower privs");
718e3744 152 return sock;
153}
154
155/* Send RIPng packet. */
156int
157ripng_send_packet (caddr_t buf, int bufsize, struct sockaddr_in6 *to,
158 struct interface *ifp)
159{
160 int ret;
161 struct msghdr msg;
162 struct iovec iov;
163 struct cmsghdr *cmsgptr;
164 char adata [256];
165 struct in6_pktinfo *pkt;
166 struct sockaddr_in6 addr;
167
a94434b6 168 if (IS_RIPNG_DEBUG_SEND) {
169 if (to)
3a2ce6a1 170 zlog_debug ("send to %s", inet6_ntoa (to->sin6_addr));
c6106812 171 zlog_debug (" send interface %s", ifp->name);
172 zlog_debug (" send packet size %d", bufsize);
a94434b6 173 }
718e3744 174
175 memset (&addr, 0, sizeof (struct sockaddr_in6));
176 addr.sin6_family = AF_INET6;
177#ifdef SIN6_LEN
178 addr.sin6_len = sizeof (struct sockaddr_in6);
179#endif /* SIN6_LEN */
180 addr.sin6_flowinfo = htonl (RIPNG_PRIORITY_DEFAULT);
181
182 /* When destination is specified. */
183 if (to != NULL)
184 {
185 addr.sin6_addr = to->sin6_addr;
186 addr.sin6_port = to->sin6_port;
187 }
188 else
189 {
190 inet_pton(AF_INET6, RIPNG_GROUP, &addr.sin6_addr);
191 addr.sin6_port = htons (RIPNG_PORT_DEFAULT);
192 }
193
194 msg.msg_name = (void *) &addr;
195 msg.msg_namelen = sizeof (struct sockaddr_in6);
196 msg.msg_iov = &iov;
197 msg.msg_iovlen = 1;
198 msg.msg_control = (void *) adata;
199 msg.msg_controllen = CMSG_SPACE(sizeof(struct in6_pktinfo));
200
201 iov.iov_base = buf;
202 iov.iov_len = bufsize;
203
204 cmsgptr = (struct cmsghdr *)adata;
205 cmsgptr->cmsg_len = CMSG_LEN(sizeof (struct in6_pktinfo));
206 cmsgptr->cmsg_level = IPPROTO_IPV6;
207 cmsgptr->cmsg_type = IPV6_PKTINFO;
208
209 pkt = (struct in6_pktinfo *) CMSG_DATA (cmsgptr);
210 memset (&pkt->ipi6_addr, 0, sizeof (struct in6_addr));
211 pkt->ipi6_ifindex = ifp->ifindex;
212
213 ret = sendmsg (ripng->sock, &msg, 0);
214
a94434b6 215 if (ret < 0) {
216 if (to)
217 zlog_err ("RIPng send fail on %s to %s: %s", ifp->name,
3a2ce6a1 218 inet6_ntoa (to->sin6_addr), safe_strerror (errno));
a94434b6 219 else
6099b3b5 220 zlog_err ("RIPng send fail on %s: %s", ifp->name, safe_strerror (errno));
a94434b6 221 }
718e3744 222
223 return ret;
224}
225
226/* Receive UDP RIPng packet from socket. */
6ac29a51 227static int
718e3744 228ripng_recv_packet (int sock, u_char *buf, int bufsize,
b892f1dd 229 struct sockaddr_in6 *from, ifindex_t *ifindex,
718e3744 230 int *hoplimit)
231{
232 int ret;
233 struct msghdr msg;
234 struct iovec iov;
235 struct cmsghdr *cmsgptr;
c5e0075f 236 struct in6_addr dst = { .s6_addr = { 0 } };
718e3744 237
37477535
DS
238 memset(&dst, 0, sizeof(struct in6_addr));
239
718e3744 240 /* Ancillary data. This store cmsghdr and in6_pktinfo. But at this
241 point I can't determine size of cmsghdr */
242 char adata[1024];
243
244 /* Fill in message and iovec. */
245 msg.msg_name = (void *) from;
246 msg.msg_namelen = sizeof (struct sockaddr_in6);
247 msg.msg_iov = &iov;
248 msg.msg_iovlen = 1;
249 msg.msg_control = (void *) adata;
250 msg.msg_controllen = sizeof adata;
251 iov.iov_base = buf;
252 iov.iov_len = bufsize;
253
254 /* If recvmsg fail return minus value. */
255 ret = recvmsg (sock, &msg, 0);
256 if (ret < 0)
257 return ret;
258
b99760ab 259 for (cmsgptr = ZCMSG_FIRSTHDR(&msg); cmsgptr != NULL;
718e3744 260 cmsgptr = CMSG_NXTHDR(&msg, cmsgptr))
261 {
262 /* I want interface index which this packet comes from. */
263 if (cmsgptr->cmsg_level == IPPROTO_IPV6 &&
264 cmsgptr->cmsg_type == IPV6_PKTINFO)
265 {
266 struct in6_pktinfo *ptr;
267
268 ptr = (struct in6_pktinfo *) CMSG_DATA (cmsgptr);
269 *ifindex = ptr->ipi6_ifindex;
270 dst = ptr->ipi6_addr;
271
272 if (*ifindex == 0)
273 zlog_warn ("Interface index returned by IPV6_PKTINFO is zero");
274 }
275
276 /* Incoming packet's multicast hop limit. */
277 if (cmsgptr->cmsg_level == IPPROTO_IPV6 &&
278 cmsgptr->cmsg_type == IPV6_HOPLIMIT)
5eb9d11b
SH
279 {
280 int *phoplimit = (int *) CMSG_DATA (cmsgptr);
281 *hoplimit = *phoplimit;
282 }
718e3744 283 }
284
285 /* Hoplimit check shold be done when destination address is
286 multicast address. */
287 if (! IN6_IS_ADDR_MULTICAST (&dst))
288 *hoplimit = -1;
289
290 return ret;
291}
292
293/* Dump rip packet */
294void
7a1d583c 295ripng_packet_dump (struct ripng_packet *packet, int size, const char *sndrcv)
718e3744 296{
297 caddr_t lim;
298 struct rte *rte;
7a1d583c 299 const char *command_str;
718e3744 300
301 /* Set command string. */
302 if (packet->command == RIPNG_REQUEST)
303 command_str = "request";
304 else if (packet->command == RIPNG_RESPONSE)
305 command_str = "response";
306 else
307 command_str = "unknown";
308
309 /* Dump packet header. */
c6106812 310 zlog_debug ("%s %s version %d packet size %d",
718e3744 311 sndrcv, command_str, packet->version, size);
312
313 /* Dump each routing table entry. */
314 rte = packet->rte;
315
316 for (lim = (caddr_t) packet + size; (caddr_t) rte < lim; rte++)
317 {
318 if (rte->metric == RIPNG_METRIC_NEXTHOP)
3a2ce6a1 319 zlog_debug (" nexthop %s/%d", inet6_ntoa (rte->addr), rte->prefixlen);
718e3744 320 else
dc9ffce8 321 zlog_debug (" %s/%d metric %d tag %"ROUTE_TAG_PRI,
3a2ce6a1 322 inet6_ntoa (rte->addr), rte->prefixlen,
dc9ffce8 323 rte->metric, (route_tag_t)ntohs (rte->tag));
718e3744 324 }
325}
326
327/* RIPng next hop address RTE (Route Table Entry). */
6ac29a51 328static void
718e3744 329ripng_nexthop_rte (struct rte *rte,
330 struct sockaddr_in6 *from,
331 struct ripng_nexthop *nexthop)
332{
333 char buf[INET6_BUFSIZ];
334
335 /* Logging before checking RTE. */
336 if (IS_RIPNG_DEBUG_RECV)
dc9ffce8
CF
337 zlog_debug ("RIPng nexthop RTE address %s tag %"ROUTE_TAG_PRI" prefixlen %d",
338 inet6_ntoa (rte->addr), (route_tag_t)ntohs (rte->tag), rte->prefixlen);
718e3744 339
340 /* RFC2080 2.1.1 Next Hop:
341 The route tag and prefix length in the next hop RTE must be
342 set to zero on sending and ignored on receiption. */
343 if (ntohs (rte->tag) != 0)
dc9ffce8
CF
344 zlog_warn ("RIPng nexthop RTE with non zero tag value %"ROUTE_TAG_PRI" from %s",
345 (route_tag_t)ntohs (rte->tag), inet6_ntoa (from->sin6_addr));
718e3744 346
347 if (rte->prefixlen != 0)
348 zlog_warn ("RIPng nexthop RTE with non zero prefixlen value %d from %s",
3a2ce6a1 349 rte->prefixlen, inet6_ntoa (from->sin6_addr));
718e3744 350
351 /* Specifying a value of 0:0:0:0:0:0:0:0 in the prefix field of a
352 next hop RTE indicates that the next hop address should be the
353 originator of the RIPng advertisement. An address specified as a
354 next hop must be a link-local address. */
355 if (IN6_IS_ADDR_UNSPECIFIED (&rte->addr))
356 {
357 nexthop->flag = RIPNG_NEXTHOP_UNSPEC;
358 memset (&nexthop->address, 0, sizeof (struct in6_addr));
359 return;
360 }
361
362 if (IN6_IS_ADDR_LINKLOCAL (&rte->addr))
363 {
364 nexthop->flag = RIPNG_NEXTHOP_ADDRESS;
365 IPV6_ADDR_COPY (&nexthop->address, &rte->addr);
366 return;
367 }
368
369 /* The purpose of the next hop RTE is to eliminate packets being
370 routed through extra hops in the system. It is particularly useful
371 when RIPng is not being run on all of the routers on a network.
372 Note that next hop RTE is "advisory". That is, if the provided
373 information is ignored, a possibly sub-optimal, but absolutely
374 valid, route may be taken. If the received next hop address is not
375 a link-local address, it should be treated as 0:0:0:0:0:0:0:0. */
376 zlog_warn ("RIPng nexthop RTE with non link-local address %s from %s",
3a2ce6a1 377 inet6_ntoa (rte->addr),
718e3744 378 inet_ntop (AF_INET6, &from->sin6_addr, buf, INET6_BUFSIZ));
379
380 nexthop->flag = RIPNG_NEXTHOP_UNSPEC;
381 memset (&nexthop->address, 0, sizeof (struct in6_addr));
382
383 return;
384}
385
386/* If ifp has same link-local address then return 1. */
6ac29a51 387static int
718e3744 388ripng_lladdr_check (struct interface *ifp, struct in6_addr *addr)
389{
1eb8ef25 390 struct listnode *node;
718e3744 391 struct connected *connected;
392 struct prefix *p;
393
1eb8ef25 394 for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, connected))
395 {
396 p = connected->address;
718e3744 397
1eb8ef25 398 if (p->family == AF_INET6 &&
399 IN6_IS_ADDR_LINKLOCAL (&p->u.prefix6) &&
400 IN6_ARE_ADDR_EQUAL (&p->u.prefix6, addr))
401 return 1;
402 }
718e3744 403 return 0;
404}
405
406/* RIPng route garbage collect timer. */
6ac29a51 407static int
718e3744 408ripng_garbage_collect (struct thread *t)
409{
410 struct ripng_info *rinfo;
411 struct route_node *rp;
412
413 rinfo = THREAD_ARG (t);
414 rinfo->t_garbage_collect = NULL;
415
416 /* Off timeout timer. */
417 RIPNG_TIMER_OFF (rinfo->t_timeout);
418
419 /* Get route_node pointer. */
420 rp = rinfo->rp;
421
718e3744 422 /* Unlock route_node. */
c880b636
FL
423 listnode_delete (rp->info, rinfo);
424 if (list_isempty ((struct list *)rp->info))
425 {
426 list_free (rp->info);
427 rp->info = NULL;
428 route_unlock_node (rp);
429 }
718e3744 430
431 /* Free RIPng routing information. */
432 ripng_info_free (rinfo);
433
434 return 0;
435}
436
c880b636
FL
437static void ripng_timeout_update (struct ripng_info *rinfo);
438
439/* Add new route to the ECMP list.
fac76f9c
FL
440 * RETURN: the new entry added in the list, or NULL if it is not the first
441 * entry and ECMP is not allowed.
c880b636
FL
442 */
443struct ripng_info *
444ripng_ecmp_add (struct ripng_info *rinfo_new)
718e3744 445{
c880b636
FL
446 struct route_node *rp = rinfo_new->rp;
447 struct ripng_info *rinfo = NULL;
448 struct list *list = NULL;
718e3744 449
c880b636
FL
450 if (rp->info == NULL)
451 rp->info = list_new ();
452 list = (struct list *)rp->info;
718e3744 453
fac76f9c
FL
454 /* If ECMP is not allowed and some entry already exists in the list,
455 * do nothing. */
456 if (listcount (list) && !ripng->ecmp)
457 return NULL;
458
c880b636
FL
459 rinfo = ripng_info_new ();
460 memcpy (rinfo, rinfo_new, sizeof (struct ripng_info));
461 listnode_add (list, rinfo);
462
463 if (ripng_route_rte (rinfo))
464 {
465 ripng_timeout_update (rinfo);
466 ripng_zebra_ipv6_add (rp);
467 }
468
469 ripng_aggregate_increment (rp, rinfo);
470
471 /* Set the route change flag on the first entry. */
472 rinfo = listgetdata (listhead (list));
473 SET_FLAG (rinfo->flags, RIPNG_RTF_CHANGED);
474
475 /* Signal the output process to trigger an update. */
476 ripng_event (RIPNG_TRIGGERED_UPDATE, 0);
477
478 return rinfo;
479}
480
481/* Replace the ECMP list with the new route.
482 * RETURN: the new entry added in the list
483 */
484struct ripng_info *
485ripng_ecmp_replace (struct ripng_info *rinfo_new)
486{
487 struct route_node *rp = rinfo_new->rp;
488 struct list *list = (struct list *)rp->info;
489 struct ripng_info *rinfo = NULL, *tmp_rinfo = NULL;
490 struct listnode *node = NULL, *nextnode = NULL;
491
492 if (list == NULL || listcount (list) == 0)
493 return ripng_ecmp_add (rinfo_new);
494
495 /* Get the first entry */
496 rinfo = listgetdata (listhead (list));
718e3744 497
c880b636
FL
498 /* Learnt route replaced by a local one. Delete it from zebra. */
499 if (ripng_route_rte (rinfo) && !ripng_route_rte (rinfo_new))
500 if (CHECK_FLAG (rinfo->flags, RIPNG_RTF_FIB))
501 ripng_zebra_ipv6_delete (rp);
718e3744 502
c880b636
FL
503 if (rinfo->metric != RIPNG_METRIC_INFINITY)
504 ripng_aggregate_decrement_list (rp, list);
a94434b6 505
c880b636
FL
506 /* Re-use the first entry, and delete the others. */
507 for (ALL_LIST_ELEMENTS (list, node, nextnode, tmp_rinfo))
508 if (tmp_rinfo != rinfo)
509 {
510 RIPNG_TIMER_OFF (tmp_rinfo->t_timeout);
511 RIPNG_TIMER_OFF (tmp_rinfo->t_garbage_collect);
512 list_delete_node (list, node);
513 ripng_info_free (tmp_rinfo);
514 }
718e3744 515
c880b636
FL
516 RIPNG_TIMER_OFF (rinfo->t_timeout);
517 RIPNG_TIMER_OFF (rinfo->t_garbage_collect);
518 memcpy (rinfo, rinfo_new, sizeof (struct ripng_info));
718e3744 519
c880b636
FL
520 if (ripng_route_rte (rinfo))
521 {
522 ripng_timeout_update (rinfo);
523 /* The ADD message implies an update. */
524 ripng_zebra_ipv6_add (rp);
525 }
526
527 ripng_aggregate_increment (rp, rinfo);
528
529 /* Set the route change flag. */
530 SET_FLAG (rinfo->flags, RIPNG_RTF_CHANGED);
531
532 /* Signal the output process to trigger an update. */
718e3744 533 ripng_event (RIPNG_TRIGGERED_UPDATE, 0);
534
c880b636
FL
535 return rinfo;
536}
537
538/* Delete one route from the ECMP list.
539 * RETURN:
540 * null - the entry is freed, and other entries exist in the list
541 * the entry - the entry is the last one in the list; its metric is set
542 * to INFINITY, and the garbage collector is started for it
543 */
544struct ripng_info *
545ripng_ecmp_delete (struct ripng_info *rinfo)
546{
547 struct route_node *rp = rinfo->rp;
548 struct list *list = (struct list *)rp->info;
549
550 RIPNG_TIMER_OFF (rinfo->t_timeout);
551
552 if (rinfo->metric != RIPNG_METRIC_INFINITY)
553 ripng_aggregate_decrement (rp, rinfo);
554
555 if (listcount (list) > 1)
556 {
557 /* Some other ECMP entries still exist. Just delete this entry. */
558 RIPNG_TIMER_OFF (rinfo->t_garbage_collect);
559 listnode_delete (list, rinfo);
560 if (ripng_route_rte (rinfo) && CHECK_FLAG (rinfo->flags, RIPNG_RTF_FIB))
561 /* The ADD message implies the update. */
562 ripng_zebra_ipv6_add (rp);
563 ripng_info_free (rinfo);
564 rinfo = NULL;
565 }
566 else
567 {
568 assert (rinfo == listgetdata (listhead (list)));
569
570 /* This is the only entry left in the list. We must keep it in
571 * the list for garbage collection time, with INFINITY metric. */
572
573 rinfo->metric = RIPNG_METRIC_INFINITY;
574 RIPNG_TIMER_ON (rinfo->t_garbage_collect,
575 ripng_garbage_collect, ripng->garbage_time);
576
577 if (ripng_route_rte (rinfo) && CHECK_FLAG (rinfo->flags, RIPNG_RTF_FIB))
578 ripng_zebra_ipv6_delete (rp);
579 }
580
581 /* Set the route change flag on the first entry. */
582 rinfo = listgetdata (listhead (list));
583 SET_FLAG (rinfo->flags, RIPNG_RTF_CHANGED);
584
585 /* Signal the output process to trigger an update. */
586 ripng_event (RIPNG_TRIGGERED_UPDATE, 0);
587
588 return rinfo;
589}
590
591/* Timeout RIPng routes. */
592static int
593ripng_timeout (struct thread *t)
594{
595 ripng_ecmp_delete ((struct ripng_info *)THREAD_ARG (t));
718e3744 596 return 0;
597}
598
6ac29a51 599static void
718e3744 600ripng_timeout_update (struct ripng_info *rinfo)
601{
602 if (rinfo->metric != RIPNG_METRIC_INFINITY)
603 {
604 RIPNG_TIMER_OFF (rinfo->t_timeout);
605 RIPNG_TIMER_ON (rinfo->t_timeout, ripng_timeout, ripng->timeout_time);
606 }
607}
608
6ac29a51 609static int
644ed6c5
MB
610ripng_filter (int ripng_distribute, struct prefix_ipv6 *p,
611 struct ripng_interface *ri)
a94434b6 612{
613 struct distribute *dist;
614 struct access_list *alist;
615 struct prefix_list *plist;
644ed6c5 616 int distribute = ripng_distribute == RIPNG_FILTER_OUT ?
fb23cf4a 617 DISTRIBUTE_V6_OUT : DISTRIBUTE_V6_IN;
644ed6c5 618 const char *inout = ripng_distribute == RIPNG_FILTER_OUT ? "out" : "in";
a94434b6 619
620 /* Input distribute-list filtering. */
644ed6c5 621 if (ri->list[ripng_distribute])
a94434b6 622 {
644ed6c5 623 if (access_list_apply (ri->list[ripng_distribute],
a94434b6 624 (struct prefix *) p) == FILTER_DENY)
625 {
626 if (IS_RIPNG_DEBUG_PACKET)
644ed6c5
MB
627 zlog_debug ("%s/%d filtered by distribute %s",
628 inet6_ntoa (p->prefix), p->prefixlen, inout);
a94434b6 629 return -1;
630 }
631 }
644ed6c5 632 if (ri->prefix[ripng_distribute])
a94434b6 633{
644ed6c5 634 if (prefix_list_apply (ri->prefix[ripng_distribute],
a94434b6 635 (struct prefix *) p) == PREFIX_DENY)
636 {
637 if (IS_RIPNG_DEBUG_PACKET)
644ed6c5
MB
638 zlog_debug ("%s/%d filtered by prefix-list %s",
639 inet6_ntoa (p->prefix), p->prefixlen, inout);
a94434b6 640 return -1;
641 }
642 }
643
644 /* All interface filter check. */
645 dist = distribute_lookup (NULL);
646 if (dist)
647 {
644ed6c5 648 if (dist->list[distribute])
a94434b6 649 {
644ed6c5 650 alist = access_list_lookup (AFI_IP6, dist->list[distribute]);
a94434b6 651
652 if (alist)
653 {
654 if (access_list_apply (alist,
655 (struct prefix *) p) == FILTER_DENY)
656 {
657 if (IS_RIPNG_DEBUG_PACKET)
644ed6c5
MB
658 zlog_debug ("%s/%d filtered by distribute %s",
659 inet6_ntoa (p->prefix), p->prefixlen, inout);
a94434b6 660 return -1;
661 }
662 }
663 }
644ed6c5 664 if (dist->prefix[distribute])
a94434b6 665 {
644ed6c5 666 plist = prefix_list_lookup (AFI_IP6, dist->prefix[distribute]);
a94434b6 667
668 if (plist)
669 {
670 if (prefix_list_apply (plist,
671 (struct prefix *) p) == PREFIX_DENY)
672 {
673 if (IS_RIPNG_DEBUG_PACKET)
644ed6c5
MB
674 zlog_debug ("%s/%d filtered by prefix-list %s",
675 inet6_ntoa (p->prefix), p->prefixlen, inout);
a94434b6 676 return -1;
677 }
678 }
679 }
680 }
681 return 0;
682}
683
718e3744 684/* Process RIPng route according to RFC2080. */
6ac29a51 685static void
718e3744 686ripng_route_process (struct rte *rte, struct sockaddr_in6 *from,
687 struct ripng_nexthop *ripng_nexthop,
688 struct interface *ifp)
689{
a94434b6 690 int ret;
718e3744 691 struct prefix_ipv6 p;
692 struct route_node *rp;
c880b636 693 struct ripng_info *rinfo = NULL, newinfo;
718e3744 694 struct ripng_interface *ri;
695 struct in6_addr *nexthop;
718e3744 696 int same = 0;
c880b636
FL
697 struct list *list = NULL;
698 struct listnode *node = NULL;
718e3744 699
700 /* Make prefix structure. */
701 memset (&p, 0, sizeof (struct prefix_ipv6));
702 p.family = AF_INET6;
703 /* p.prefix = rte->addr; */
704 IPV6_ADDR_COPY (&p.prefix, &rte->addr);
705 p.prefixlen = rte->prefixlen;
706
707 /* Make sure mask is applied. */
708 /* XXX We have to check the prefix is valid or not before call
709 apply_mask_ipv6. */
710 apply_mask_ipv6 (&p);
711
712 /* Apply input filters. */
713 ri = ifp->info;
714
644ed6c5 715 ret = ripng_filter (RIPNG_FILTER_IN, &p, ri);
a94434b6 716 if (ret < 0)
717 return;
718e3744 718
c880b636
FL
719 memset (&newinfo, 0, sizeof (newinfo));
720 newinfo.type = ZEBRA_ROUTE_RIPNG;
721 newinfo.sub_type = RIPNG_ROUTE_RTE;
722 if (ripng_nexthop->flag == RIPNG_NEXTHOP_ADDRESS)
723 newinfo.nexthop = ripng_nexthop->address;
724 else
725 newinfo.nexthop = from->sin6_addr;
726 newinfo.from = from->sin6_addr;
727 newinfo.ifindex = ifp->ifindex;
728 newinfo.metric = rte->metric;
729 newinfo.metric_out = rte->metric; /* XXX */
730 newinfo.tag = ntohs (rte->tag); /* XXX */
731
718e3744 732 /* Modify entry. */
733 if (ri->routemap[RIPNG_FILTER_IN])
734 {
735 int ret;
718e3744 736
737 ret = route_map_apply (ri->routemap[RIPNG_FILTER_IN],
738 (struct prefix *)&p, RMAP_RIPNG, &newinfo);
739
740 if (ret == RMAP_DENYMATCH)
741 {
742 if (IS_RIPNG_DEBUG_PACKET)
c6106812 743 zlog_debug ("RIPng %s/%d is filtered by route-map in",
3a2ce6a1 744 inet6_ntoa (p.prefix), p.prefixlen);
718e3744 745 return;
746 }
747
a94434b6 748 /* Get back the object */
749 if (ripng_nexthop->flag == RIPNG_NEXTHOP_ADDRESS) {
750 if (! IPV6_ADDR_SAME(&newinfo.nexthop, &ripng_nexthop->address) ) {
751 /* the nexthop get changed by the routemap */
752 if (IN6_IS_ADDR_LINKLOCAL(&newinfo.nexthop))
753 ripng_nexthop->address = newinfo.nexthop;
754 else
755 ripng_nexthop->address = in6addr_any;
756 }
757 } else {
758 if (! IPV6_ADDR_SAME(&newinfo.nexthop, &from->sin6_addr) ) {
759 /* the nexthop get changed by the routemap */
760 if (IN6_IS_ADDR_LINKLOCAL(&newinfo.nexthop)) {
761 ripng_nexthop->flag = RIPNG_NEXTHOP_ADDRESS;
762 ripng_nexthop->address = newinfo.nexthop;
763 }
764 }
765 }
766 rte->tag = htons(newinfo.tag_out); /* XXX */
767 rte->metric = newinfo.metric_out; /* XXX: the routemap uses the metric_out field */
718e3744 768 }
769
a94434b6 770 /* Once the entry has been validated, update the metric by
771 * adding the cost of the network on wich the message
772 * arrived. If the result is greater than infinity, use infinity
773 * (RFC2453 Sec. 3.9.2)
774 **/
775
776 /* Zebra ripngd can handle offset-list in. */
777 ret = ripng_offset_list_apply_in (&p, ifp, &rte->metric);
778
779 /* If offset-list does not modify the metric use interface's
780 * one. */
781 if (! ret)
7b3b98ae 782 rte->metric += ifp->metric ? ifp->metric : 1;
a94434b6 783
784 if (rte->metric > RIPNG_METRIC_INFINITY)
785 rte->metric = RIPNG_METRIC_INFINITY;
786
718e3744 787 /* Set nexthop pointer. */
788 if (ripng_nexthop->flag == RIPNG_NEXTHOP_ADDRESS)
789 nexthop = &ripng_nexthop->address;
790 else
791 nexthop = &from->sin6_addr;
792
793 /* Lookup RIPng routing table. */
794 rp = route_node_get (ripng->table, (struct prefix *) &p);
795
c880b636
FL
796 newinfo.rp = rp;
797 newinfo.nexthop = *nexthop;
798 newinfo.metric = rte->metric;
799 newinfo.tag = ntohs (rte->tag);
800
801 /* Check to see whether there is already RIPng route on the table. */
802 if ((list = rp->info) != NULL)
803 for (ALL_LIST_ELEMENTS_RO (list, node, rinfo))
804 {
805 /* Need to compare with redistributed entry or local entry */
806 if (!ripng_route_rte (rinfo))
807 break;
808
809 if (IPV6_ADDR_SAME (&rinfo->from, &from->sin6_addr) &&
810 IPV6_ADDR_SAME (&rinfo->nexthop, nexthop))
811 break;
812
813 if (!listnextnode (node))
814 {
815 /* Not found in the list */
816
817 if (rte->metric > rinfo->metric)
818 {
819 /* New route has a greater metric. Discard it. */
820 route_unlock_node (rp);
821 return;
822 }
823
824 if (rte->metric < rinfo->metric)
825 /* New route has a smaller metric. Replace the ECMP list
826 * with the new one in below. */
827 break;
828
705e86f0
RW
829 /* Metrics are same. Unless ECMP is disabled, keep "rinfo" null and
830 * the new route is added in the ECMP list in below. */
831 if (! ripng->ecmp)
832 break;
c880b636
FL
833 }
834 }
835
a94434b6 836 if (rinfo)
837 {
838 /* Redistributed route check. */
839 if (rinfo->type != ZEBRA_ROUTE_RIPNG
840 && rinfo->metric != RIPNG_METRIC_INFINITY)
c880b636
FL
841 {
842 route_unlock_node (rp);
843 return;
844 }
a94434b6 845
846 /* Local static route. */
847 if (rinfo->type == ZEBRA_ROUTE_RIPNG
848 && ((rinfo->sub_type == RIPNG_ROUTE_STATIC) ||
849 (rinfo->sub_type == RIPNG_ROUTE_DEFAULT))
850 && rinfo->metric != RIPNG_METRIC_INFINITY)
c880b636
FL
851 {
852 route_unlock_node (rp);
853 return;
854 }
a94434b6 855 }
856
c880b636 857 if (!rinfo)
718e3744 858 {
859 /* Now, check to see whether there is already an explicit route
860 for the destination prefix. If there is no such route, add
861 this route to the routing table, unless the metric is
862 infinity (there is no point in adding a route which
863 unusable). */
864 if (rte->metric != RIPNG_METRIC_INFINITY)
c880b636 865 ripng_ecmp_add (&newinfo);
718e3744 866 }
867 else
868 {
718e3744 869 /* If there is an existing route, compare the next hop address
870 to the address of the router from which the datagram came.
871 If this datagram is from the same router as the existing
872 route, reinitialize the timeout. */
873 same = (IN6_ARE_ADDR_EQUAL (&rinfo->from, &from->sin6_addr)
874 && (rinfo->ifindex == ifp->ifindex));
875
705e86f0
RW
876 /*
877 * RFC 2080 - Section 2.4.2:
878 * "If the new metric is the same as the old one, examine the timeout
879 * for the existing route. If it is at least halfway to the expiration
880 * point, switch to the new route. This heuristic is optional, but
881 * highly recommended".
882 */
883 if (!ripng->ecmp && !same &&
884 rinfo->metric == rte->metric && rinfo->t_timeout &&
885 (thread_timer_remain_second (rinfo->t_timeout) < (ripng->timeout_time / 2)))
886 {
887 ripng_ecmp_replace (&newinfo);
888 }
718e3744 889 /* Next, compare the metrics. If the datagram is from the same
890 router as the existing route, and the new metric is different
891 than the old one; or, if the new metric is lower than the old
892 one; do the following actions: */
705e86f0 893 else if ((same && rinfo->metric != rte->metric) ||
718e3744 894 rte->metric < rinfo->metric)
895 {
c880b636
FL
896 if (listcount (list) == 1)
897 {
898 if (newinfo.metric != RIPNG_METRIC_INFINITY)
899 ripng_ecmp_replace (&newinfo);
900 else
901 ripng_ecmp_delete (rinfo);
902 }
903 else
904 {
905 if (newinfo.metric < rinfo->metric)
906 ripng_ecmp_replace (&newinfo);
907 else /* newinfo.metric > rinfo->metric */
908 ripng_ecmp_delete (rinfo);
909 }
718e3744 910 }
c880b636
FL
911 else /* same & no change */
912 ripng_timeout_update (rinfo);
913
718e3744 914 /* Unlock tempolary lock of the route. */
915 route_unlock_node (rp);
916 }
917}
918
919/* Add redistributed route to RIPng table. */
920void
921ripng_redistribute_add (int type, int sub_type, struct prefix_ipv6 *p,
1796a585
CF
922 ifindex_t ifindex, struct in6_addr *nexthop,
923 route_tag_t tag)
718e3744 924{
925 struct route_node *rp;
c880b636
FL
926 struct ripng_info *rinfo = NULL, newinfo;
927 struct list *list = NULL;
718e3744 928
929 /* Redistribute route */
930 if (IN6_IS_ADDR_LINKLOCAL (&p->prefix))
931 return;
932 if (IN6_IS_ADDR_LOOPBACK (&p->prefix))
933 return;
934
935 rp = route_node_get (ripng->table, (struct prefix *) p);
718e3744 936
c880b636
FL
937 memset (&newinfo, 0, sizeof (struct ripng_info));
938 newinfo.type = type;
939 newinfo.sub_type = sub_type;
940 newinfo.ifindex = ifindex;
941 newinfo.metric = 1;
1796a585
CF
942 if (tag <= UINT16_MAX) /* RIPng only supports 16 bit tags */
943 newinfo.tag = tag;
c880b636
FL
944 newinfo.rp = rp;
945 if (nexthop && IN6_IS_ADDR_LINKLOCAL(nexthop))
946 newinfo.nexthop = *nexthop;
947
948 if ((list = rp->info) != NULL && listcount (list) != 0)
718e3744 949 {
c880b636
FL
950 rinfo = listgetdata (listhead (list));
951
a94434b6 952 if (rinfo->type == ZEBRA_ROUTE_CONNECT
953 && rinfo->sub_type == RIPNG_ROUTE_INTERFACE
954 && rinfo->metric != RIPNG_METRIC_INFINITY) {
955 route_unlock_node (rp);
956 return;
957 }
958
959 /* Manually configured RIPng route check.
960 * They have the precedence on all the other entries.
961 **/
962 if (rinfo->type == ZEBRA_ROUTE_RIPNG
963 && ((rinfo->sub_type == RIPNG_ROUTE_STATIC) ||
964 (rinfo->sub_type == RIPNG_ROUTE_DEFAULT)) ) {
965 if (type != ZEBRA_ROUTE_RIPNG || ((sub_type != RIPNG_ROUTE_STATIC) &&
966 (sub_type != RIPNG_ROUTE_DEFAULT))) {
967 route_unlock_node (rp);
968 return;
969 }
970 }
a94434b6 971
c16b6d31 972 ripng_ecmp_replace (&newinfo);
718e3744 973 route_unlock_node (rp);
974 }
c880b636 975 else
c16b6d31 976 ripng_ecmp_add (&newinfo);
a94434b6 977
978 if (IS_RIPNG_DEBUG_EVENT) {
979 if (!nexthop)
c6106812 980 zlog_debug ("Redistribute new prefix %s/%d on the interface %s",
baaea325
DS
981 inet6_ntoa(p->prefix), p->prefixlen,
982 ifindex2ifname(ifindex, VRF_DEFAULT));
a94434b6 983 else
c6106812 984 zlog_debug ("Redistribute new prefix %s/%d with nexthop %s on the interface %s",
baaea325
DS
985 inet6_ntoa(p->prefix), p->prefixlen, inet6_ntoa(*nexthop),
986 ifindex2ifname(ifindex, VRF_DEFAULT));
a94434b6 987 }
988
989 ripng_event (RIPNG_TRIGGERED_UPDATE, 0);
718e3744 990}
991
992/* Delete redistributed route to RIPng table. */
993void
994ripng_redistribute_delete (int type, int sub_type, struct prefix_ipv6 *p,
b892f1dd 995 ifindex_t ifindex)
718e3744 996{
997 struct route_node *rp;
998 struct ripng_info *rinfo;
999
1000 if (IN6_IS_ADDR_LINKLOCAL (&p->prefix))
1001 return;
1002 if (IN6_IS_ADDR_LOOPBACK (&p->prefix))
1003 return;
1004
1005 rp = route_node_lookup (ripng->table, (struct prefix *) p);
1006
1007 if (rp)
1008 {
c880b636
FL
1009 struct list *list = rp->info;
1010
1011 if (list != NULL && listcount (list) != 0)
1012 {
1013 rinfo = listgetdata (listhead (list));
1014 if (rinfo != NULL
1015 && rinfo->type == type
1016 && rinfo->sub_type == sub_type
1017 && rinfo->ifindex == ifindex)
1018 {
1019 /* Perform poisoned reverse. */
1020 rinfo->metric = RIPNG_METRIC_INFINITY;
1021 RIPNG_TIMER_ON (rinfo->t_garbage_collect,
1022 ripng_garbage_collect, ripng->garbage_time);
1023 RIPNG_TIMER_OFF (rinfo->t_timeout);
1024
1025 /* Aggregate count decrement. */
1026 ripng_aggregate_decrement (rp, rinfo);
1027
1028 rinfo->flags |= RIPNG_RTF_CHANGED;
1029
1030 if (IS_RIPNG_DEBUG_EVENT)
1031 zlog_debug ("Poisone %s/%d on the interface %s with an "
1032 "infinity metric [delete]",
1033 inet6_ntoa (p->prefix), p->prefixlen,
baaea325 1034 ifindex2ifname (ifindex, VRF_DEFAULT));
c880b636
FL
1035
1036 ripng_event (RIPNG_TRIGGERED_UPDATE, 0);
1037 }
1038 }
1039 route_unlock_node (rp);
718e3744 1040 }
1041}
1042
1043/* Withdraw redistributed route. */
1044void
1045ripng_redistribute_withdraw (int type)
1046{
1047 struct route_node *rp;
c880b636
FL
1048 struct ripng_info *rinfo = NULL;
1049 struct list *list = NULL;
718e3744 1050
a94434b6 1051 if (!ripng)
1052 return;
1053
718e3744 1054 for (rp = route_top (ripng->table); rp; rp = route_next (rp))
c880b636 1055 if ((list = rp->info) != NULL)
718e3744 1056 {
c880b636 1057 rinfo = listgetdata (listhead (list));
a94434b6 1058 if ((rinfo->type == type)
1059 && (rinfo->sub_type != RIPNG_ROUTE_INTERFACE))
718e3744 1060 {
a94434b6 1061 /* Perform poisoned reverse. */
1062 rinfo->metric = RIPNG_METRIC_INFINITY;
1063 RIPNG_TIMER_ON (rinfo->t_garbage_collect,
1064 ripng_garbage_collect, ripng->garbage_time);
718e3744 1065 RIPNG_TIMER_OFF (rinfo->t_timeout);
718e3744 1066
a94434b6 1067 /* Aggregate count decrement. */
1068 ripng_aggregate_decrement (rp, rinfo);
1069
1070 rinfo->flags |= RIPNG_RTF_CHANGED;
1071
1072 if (IS_RIPNG_DEBUG_EVENT) {
1073 struct prefix_ipv6 *p = (struct prefix_ipv6 *) &rp->p;
718e3744 1074
c6106812 1075 zlog_debug ("Poisone %s/%d on the interface %s [withdraw]",
baaea325
DS
1076 inet6_ntoa(p->prefix), p->prefixlen,
1077 ifindex2ifname(rinfo->ifindex, VRF_DEFAULT));
a94434b6 1078 }
1079
1080 ripng_event (RIPNG_TRIGGERED_UPDATE, 0);
718e3744 1081 }
1082 }
1083}
1084
1085/* RIP routing information. */
6ac29a51 1086static void
718e3744 1087ripng_response_process (struct ripng_packet *packet, int size,
1088 struct sockaddr_in6 *from, struct interface *ifp,
1089 int hoplimit)
1090{
1091 caddr_t lim;
1092 struct rte *rte;
1093 struct ripng_nexthop nexthop;
1094
1095 /* RFC2080 2.4.2 Response Messages:
1096 The Response must be ignored if it is not from the RIPng port. */
1097 if (ntohs (from->sin6_port) != RIPNG_PORT_DEFAULT)
1098 {
1099 zlog_warn ("RIPng packet comes from non RIPng port %d from %s",
3a2ce6a1 1100 ntohs (from->sin6_port), inet6_ntoa (from->sin6_addr));
a94434b6 1101 ripng_peer_bad_packet (from);
718e3744 1102 return;
1103 }
1104
1105 /* The datagram's IPv6 source address should be checked to see
1106 whether the datagram is from a valid neighbor; the source of the
1107 datagram must be a link-local address. */
1108 if (! IN6_IS_ADDR_LINKLOCAL(&from->sin6_addr))
1109 {
1110 zlog_warn ("RIPng packet comes from non link local address %s",
3a2ce6a1 1111 inet6_ntoa (from->sin6_addr));
a94434b6 1112 ripng_peer_bad_packet (from);
718e3744 1113 return;
1114 }
1115
1116 /* It is also worth checking to see whether the response is from one
1117 of the router's own addresses. Interfaces on broadcast networks
1118 may receive copies of their own multicasts immediately. If a
1119 router processes its own output as new input, confusion is likely,
1120 and such datagrams must be ignored. */
1121 if (ripng_lladdr_check (ifp, &from->sin6_addr))
1122 {
1123 zlog_warn ("RIPng packet comes from my own link local address %s",
3a2ce6a1 1124 inet6_ntoa (from->sin6_addr));
a94434b6 1125 ripng_peer_bad_packet (from);
718e3744 1126 return;
1127 }
1128
1129 /* As an additional check, periodic advertisements must have their
1130 hop counts set to 255, and inbound, multicast packets sent from the
1131 RIPng port (i.e. periodic advertisement or triggered update
1132 packets) must be examined to ensure that the hop count is 255. */
1133 if (hoplimit >= 0 && hoplimit != 255)
1134 {
1135 zlog_warn ("RIPng packet comes with non 255 hop count %d from %s",
3a2ce6a1 1136 hoplimit, inet6_ntoa (from->sin6_addr));
a94434b6 1137 ripng_peer_bad_packet (from);
718e3744 1138 return;
1139 }
1140
a94434b6 1141 /* Update RIPng peer. */
1142 ripng_peer_update (from, packet->version);
1143
718e3744 1144 /* Reset nexthop. */
1145 memset (&nexthop, 0, sizeof (struct ripng_nexthop));
1146 nexthop.flag = RIPNG_NEXTHOP_UNSPEC;
1147
1148 /* Set RTE pointer. */
1149 rte = packet->rte;
1150
1151 for (lim = ((caddr_t) packet) + size; (caddr_t) rte < lim; rte++)
1152 {
1153 /* First of all, we have to check this RTE is next hop RTE or
1154 not. Next hop RTE is completely different with normal RTE so
1155 we need special treatment. */
1156 if (rte->metric == RIPNG_METRIC_NEXTHOP)
1157 {
1158 ripng_nexthop_rte (rte, from, &nexthop);
1159 continue;
1160 }
1161
1162 /* RTE information validation. */
1163
1164 /* - is the destination prefix valid (e.g., not a multicast
1165 prefix and not a link-local address) A link-local address
1166 should never be present in an RTE. */
1167 if (IN6_IS_ADDR_MULTICAST (&rte->addr))
1168 {
1169 zlog_warn ("Destination prefix is a multicast address %s/%d [%d]",
3a2ce6a1 1170 inet6_ntoa (rte->addr), rte->prefixlen, rte->metric);
a94434b6 1171 ripng_peer_bad_route (from);
718e3744 1172 continue;
1173 }
1174 if (IN6_IS_ADDR_LINKLOCAL (&rte->addr))
1175 {
1176 zlog_warn ("Destination prefix is a link-local address %s/%d [%d]",
3a2ce6a1 1177 inet6_ntoa (rte->addr), rte->prefixlen, rte->metric);
a94434b6 1178 ripng_peer_bad_route (from);
718e3744 1179 continue;
1180 }
1181 if (IN6_IS_ADDR_LOOPBACK (&rte->addr))
1182 {
1183 zlog_warn ("Destination prefix is a loopback address %s/%d [%d]",
3a2ce6a1 1184 inet6_ntoa (rte->addr), rte->prefixlen, rte->metric);
a94434b6 1185 ripng_peer_bad_route (from);
718e3744 1186 continue;
1187 }
1188
1189 /* - is the prefix length valid (i.e., between 0 and 128,
1190 inclusive) */
1191 if (rte->prefixlen > 128)
1192 {
1193 zlog_warn ("Invalid prefix length %s/%d from %s%%%s",
3a2ce6a1 1194 inet6_ntoa (rte->addr), rte->prefixlen,
1195 inet6_ntoa (from->sin6_addr), ifp->name);
a94434b6 1196 ripng_peer_bad_route (from);
718e3744 1197 continue;
1198 }
1199
1200 /* - is the metric valid (i.e., between 1 and 16, inclusive) */
1201 if (! (rte->metric >= 1 && rte->metric <= 16))
1202 {
1203 zlog_warn ("Invalid metric %d from %s%%%s", rte->metric,
3a2ce6a1 1204 inet6_ntoa (from->sin6_addr), ifp->name);
a94434b6 1205 ripng_peer_bad_route (from);
718e3744 1206 continue;
1207 }
1208
a94434b6 1209 /* Vincent: XXX Should we compute the direclty reachable nexthop
1210 * for our RIPng network ?
1211 **/
718e3744 1212
1213 /* Routing table updates. */
1214 ripng_route_process (rte, from, &nexthop, ifp);
1215 }
1216}
1217
1218/* Response to request message. */
6ac29a51 1219static void
718e3744 1220ripng_request_process (struct ripng_packet *packet,int size,
1221 struct sockaddr_in6 *from, struct interface *ifp)
1222{
1223 caddr_t lim;
1224 struct rte *rte;
1225 struct prefix_ipv6 p;
1226 struct route_node *rp;
1227 struct ripng_info *rinfo;
1228 struct ripng_interface *ri;
1229
a94434b6 1230 /* Does not reponse to the requests on the loopback interfaces */
1231 if (if_is_loopback (ifp))
1232 return;
1233
718e3744 1234 /* Check RIPng process is enabled on this interface. */
1235 ri = ifp->info;
1236 if (! ri->running)
1237 return;
1238
1239 /* When passive interface is specified, suppress responses */
1240 if (ri->passive)
1241 return;
1242
a94434b6 1243 /* RIPng peer update. */
1244 ripng_peer_update (from, packet->version);
1245
718e3744 1246 lim = ((caddr_t) packet) + size;
1247 rte = packet->rte;
1248
1249 /* The Request is processed entry by entry. If there are no
1250 entries, no response is given. */
1251 if (lim == (caddr_t) rte)
1252 return;
1253
1254 /* There is one special case. If there is exactly one entry in the
1255 request, and it has a destination prefix of zero, a prefix length
1256 of zero, and a metric of infinity (i.e., 16), then this is a
1257 request to send the entire routing table. In that case, a call
1258 is made to the output process to send the routing table to the
1259 requesting address/port. */
1260 if (lim == ((caddr_t) (rte + 1)) &&
1261 IN6_IS_ADDR_UNSPECIFIED (&rte->addr) &&
1262 rte->prefixlen == 0 &&
1263 rte->metric == RIPNG_METRIC_INFINITY)
1264 {
1265 /* All route with split horizon */
a94434b6 1266 ripng_output_process (ifp, from, ripng_all_route);
718e3744 1267 }
1268 else
1269 {
1270 /* Except for this special case, processing is quite simple.
1271 Examine the list of RTEs in the Request one by one. For each
1272 entry, look up the destination in the router's routing
1273 database and, if there is a route, put that route's metric in
1274 the metric field of the RTE. If there is no explicit route
1275 to the specified destination, put infinity in the metric
1276 field. Once all the entries have been filled in, change the
1277 command from Request to Response and send the datagram back
1278 to the requestor. */
1279 memset (&p, 0, sizeof (struct prefix_ipv6));
1280 p.family = AF_INET6;
1281
1282 for (; ((caddr_t) rte) < lim; rte++)
1283 {
1284 p.prefix = rte->addr;
1285 p.prefixlen = rte->prefixlen;
1286 apply_mask_ipv6 (&p);
1287
1288 rp = route_node_lookup (ripng->table, (struct prefix *) &p);
1289
1290 if (rp)
1291 {
c880b636 1292 rinfo = listgetdata (listhead ((struct list *)rp->info));
718e3744 1293 rte->metric = rinfo->metric;
1294 route_unlock_node (rp);
1295 }
1296 else
1297 rte->metric = RIPNG_METRIC_INFINITY;
1298 }
1299 packet->command = RIPNG_RESPONSE;
1300
1301 ripng_send_packet ((caddr_t) packet, size, from, ifp);
1302 }
1303}
1304
1305/* First entry point of reading RIPng packet. */
6ac29a51 1306static int
718e3744 1307ripng_read (struct thread *thread)
1308{
1309 int len;
1310 int sock;
1311 struct sockaddr_in6 from;
1312 struct ripng_packet *packet;
b892f1dd 1313 ifindex_t ifindex = 0;
718e3744 1314 struct interface *ifp;
1315 int hoplimit = -1;
1316
1317 /* Check ripng is active and alive. */
1318 assert (ripng != NULL);
1319 assert (ripng->sock >= 0);
1320
1321 /* Fetch thread data and set read pointer to empty for event
1322 managing. `sock' sould be same as ripng->sock. */
1323 sock = THREAD_FD (thread);
1324 ripng->t_read = NULL;
1325
1326 /* Add myself to the next event. */
1327 ripng_event (RIPNG_READ, sock);
1328
1329 /* Read RIPng packet. */
1330 len = ripng_recv_packet (sock, STREAM_DATA (ripng->ibuf),
1331 STREAM_SIZE (ripng->ibuf), &from, &ifindex,
1332 &hoplimit);
1333 if (len < 0)
1334 {
6099b3b5 1335 zlog_warn ("RIPng recvfrom failed: %s.", safe_strerror (errno));
718e3744 1336 return len;
1337 }
1338
1339 /* Check RTE boundary. RTE size (Packet length - RIPng header size
1340 (4)) must be multiple size of one RTE size (20). */
1341 if (((len - 4) % 20) != 0)
1342 {
1343 zlog_warn ("RIPng invalid packet size %d from %s", len,
3a2ce6a1 1344 inet6_ntoa (from.sin6_addr));
a94434b6 1345 ripng_peer_bad_packet (&from);
718e3744 1346 return 0;
1347 }
1348
1349 packet = (struct ripng_packet *) STREAM_DATA (ripng->ibuf);
7e2b7603 1350 ifp = if_lookup_by_index (ifindex, VRF_DEFAULT);
718e3744 1351
1352 /* RIPng packet received. */
1353 if (IS_RIPNG_DEBUG_EVENT)
c6106812 1354 zlog_debug ("RIPng packet received from %s port %d on %s",
3a2ce6a1 1355 inet6_ntoa (from.sin6_addr), ntohs (from.sin6_port),
718e3744 1356 ifp ? ifp->name : "unknown");
1357
1358 /* Logging before packet checking. */
1359 if (IS_RIPNG_DEBUG_RECV)
1360 ripng_packet_dump (packet, len, "RECV");
1361
1362 /* Packet comes from unknown interface. */
1363 if (ifp == NULL)
1364 {
1365 zlog_warn ("RIPng packet comes from unknown interface %d", ifindex);
1366 return 0;
1367 }
1368
1369 /* Packet version mismatch checking. */
1370 if (packet->version != ripng->version)
1371 {
1372 zlog_warn ("RIPng packet version %d doesn't fit to my version %d",
1373 packet->version, ripng->version);
a94434b6 1374 ripng_peer_bad_packet (&from);
718e3744 1375 return 0;
1376 }
1377
1378 /* Process RIPng packet. */
1379 switch (packet->command)
1380 {
1381 case RIPNG_REQUEST:
1382 ripng_request_process (packet, len, &from, ifp);
1383 break;
1384 case RIPNG_RESPONSE:
1385 ripng_response_process (packet, len, &from, ifp, hoplimit);
1386 break;
1387 default:
1388 zlog_warn ("Invalid RIPng command %d", packet->command);
a94434b6 1389 ripng_peer_bad_packet (&from);
718e3744 1390 break;
1391 }
1392 return 0;
1393}
1394
1395/* Walk down the RIPng routing table then clear changed flag. */
6ac29a51
PJ
1396static void
1397ripng_clear_changed_flag (void)
718e3744 1398{
1399 struct route_node *rp;
c880b636
FL
1400 struct ripng_info *rinfo = NULL;
1401 struct list *list = NULL;
1402 struct listnode *listnode = NULL;
718e3744 1403
1404 for (rp = route_top (ripng->table); rp; rp = route_next (rp))
c880b636
FL
1405 if ((list = rp->info) != NULL)
1406 for (ALL_LIST_ELEMENTS_RO (list, listnode, rinfo))
1407 {
1408 UNSET_FLAG (rinfo->flags, RIPNG_RTF_CHANGED);
1409 /* This flag can be set only on the first entry. */
1410 break;
1411 }
718e3744 1412}
1413
1414/* Regular update of RIPng route. Send all routing formation to RIPng
1415 enabled interface. */
6ac29a51 1416static int
718e3744 1417ripng_update (struct thread *t)
1418{
52dc7ee6 1419 struct listnode *node;
718e3744 1420 struct interface *ifp;
1421 struct ripng_interface *ri;
1422
1423 /* Clear update timer thread. */
1424 ripng->t_update = NULL;
1425
1426 /* Logging update event. */
1427 if (IS_RIPNG_DEBUG_EVENT)
c6106812 1428 zlog_debug ("RIPng update timer expired!");
718e3744 1429
1430 /* Supply routes to each interface. */
b2d7c082 1431 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp))
718e3744 1432 {
718e3744 1433 ri = ifp->info;
1434
1435 if (if_is_loopback (ifp) || ! if_is_up (ifp))
1436 continue;
1437
1438 if (! ri->running)
1439 continue;
1440
1441 /* When passive interface is specified, suppress announce to the
1442 interface. */
1443 if (ri->passive)
1444 continue;
1445
1446#if RIPNG_ADVANCED
1447 if (ri->ri_send == RIPNG_SEND_OFF)
1448 {
1449 if (IS_RIPNG_DEBUG_EVENT)
4525281a 1450 zlog_debug ("[Event] RIPng send to if %d is suppressed by config",
718e3744 1451 ifp->ifindex);
1452 continue;
1453 }
1454#endif /* RIPNG_ADVANCED */
1455
a94434b6 1456 ripng_output_process (ifp, NULL, ripng_all_route);
718e3744 1457 }
1458
1459 /* Triggered updates may be suppressed if a regular update is due by
1460 the time the triggered update would be sent. */
1461 if (ripng->t_triggered_interval)
1462 {
1463 thread_cancel (ripng->t_triggered_interval);
1464 ripng->t_triggered_interval = NULL;
1465 }
1466 ripng->trigger = 0;
1467
1468 /* Reset flush event. */
1469 ripng_event (RIPNG_UPDATE_EVENT, 0);
1470
1471 return 0;
1472}
1473
1474/* Triggered update interval timer. */
6ac29a51 1475static int
718e3744 1476ripng_triggered_interval (struct thread *t)
1477{
1478 ripng->t_triggered_interval = NULL;
1479
1480 if (ripng->trigger)
1481 {
1482 ripng->trigger = 0;
1483 ripng_triggered_update (t);
1484 }
1485 return 0;
1486}
1487
1488/* Execute triggered update. */
1489int
1490ripng_triggered_update (struct thread *t)
1491{
52dc7ee6 1492 struct listnode *node;
718e3744 1493 struct interface *ifp;
1494 struct ripng_interface *ri;
1495 int interval;
1496
1497 ripng->t_triggered_update = NULL;
1498
1499 /* Cancel interval timer. */
1500 if (ripng->t_triggered_interval)
1501 {
1502 thread_cancel (ripng->t_triggered_interval);
1503 ripng->t_triggered_interval = NULL;
1504 }
1505 ripng->trigger = 0;
1506
1507 /* Logging triggered update. */
1508 if (IS_RIPNG_DEBUG_EVENT)
c6106812 1509 zlog_debug ("RIPng triggered update!");
718e3744 1510
1511 /* Split Horizon processing is done when generating triggered
1512 updates as well as normal updates (see section 2.6). */
b2d7c082 1513 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp))
718e3744 1514 {
718e3744 1515 ri = ifp->info;
1516
1517 if (if_is_loopback (ifp) || ! if_is_up (ifp))
1518 continue;
1519
1520 if (! ri->running)
1521 continue;
1522
1523 /* When passive interface is specified, suppress announce to the
1524 interface. */
1525 if (ri->passive)
1526 continue;
1527
a94434b6 1528 ripng_output_process (ifp, NULL, ripng_changed_route);
718e3744 1529 }
1530
1531 /* Once all of the triggered updates have been generated, the route
1532 change flags should be cleared. */
1533 ripng_clear_changed_flag ();
1534
1535 /* After a triggered update is sent, a timer should be set for a
1536 random interval between 1 and 5 seconds. If other changes that
1537 would trigger updates occur before the timer expires, a single
1538 update is triggered when the timer expires. */
1539 interval = (random () % 5) + 1;
1540
66e78ae6
QY
1541 ripng->t_triggered_interval = NULL;
1542 thread_add_timer(master, ripng_triggered_interval, NULL, interval,
1543 &ripng->t_triggered_interval);
718e3744 1544
1545 return 0;
1546}
1547
1548/* Write routing table entry to the stream and return next index of
1549 the routing table entry in the stream. */
1550int
1551ripng_write_rte (int num, struct stream *s, struct prefix_ipv6 *p,
a94434b6 1552 struct in6_addr *nexthop, u_int16_t tag, u_char metric)
718e3744 1553{
1554 /* RIPng packet header. */
1555 if (num == 0)
1556 {
1557 stream_putc (s, RIPNG_RESPONSE);
1558 stream_putc (s, RIPNG_V1);
1559 stream_putw (s, 0);
1560 }
1561
1562 /* Write routing table entry. */
a94434b6 1563 if (!nexthop)
c9e52be3 1564 stream_write (s, (u_char *) &p->prefix, sizeof (struct in6_addr));
a94434b6 1565 else
c9e52be3 1566 stream_write (s, (u_char *) nexthop, sizeof (struct in6_addr));
718e3744 1567 stream_putw (s, tag);
a94434b6 1568 if (p)
1569 stream_putc (s, p->prefixlen);
1570 else
1571 stream_putc (s, 0);
718e3744 1572 stream_putc (s, metric);
1573
1574 return ++num;
1575}
1576
1577/* Send RESPONSE message to specified destination. */
1578void
1579ripng_output_process (struct interface *ifp, struct sockaddr_in6 *to,
a94434b6 1580 int route_type)
718e3744 1581{
1582 int ret;
718e3744 1583 struct route_node *rp;
1584 struct ripng_info *rinfo;
1585 struct ripng_interface *ri;
1586 struct ripng_aggregate *aggregate;
1587 struct prefix_ipv6 *p;
a94434b6 1588 struct list * ripng_rte_list;
c880b636
FL
1589 struct list *list = NULL;
1590 struct listnode *listnode = NULL;
718e3744 1591
a94434b6 1592 if (IS_RIPNG_DEBUG_EVENT) {
1593 if (to)
c6106812 1594 zlog_debug ("RIPng update routes to neighbor %s",
3a2ce6a1 1595 inet6_ntoa(to->sin6_addr));
a94434b6 1596 else
c6106812 1597 zlog_debug ("RIPng update routes on interface %s", ifp->name);
a94434b6 1598 }
718e3744 1599
718e3744 1600 /* Get RIPng interface. */
1601 ri = ifp->info;
a94434b6 1602
1603 ripng_rte_list = ripng_rte_new();
1604
718e3744 1605 for (rp = route_top (ripng->table); rp; rp = route_next (rp))
1606 {
c880b636
FL
1607 if ((list = rp->info) != NULL &&
1608 (rinfo = listgetdata (listhead (list))) != NULL &&
1609 rinfo->suppress == 0)
718e3744 1610 {
a94434b6 1611 /* If no route-map are applied, the RTE will be these following
1612 * informations.
1613 */
718e3744 1614 p = (struct prefix_ipv6 *) &rp->p;
a94434b6 1615 rinfo->metric_out = rinfo->metric;
1616 rinfo->tag_out = rinfo->tag;
1617 memset(&rinfo->nexthop_out, 0, sizeof(rinfo->nexthop_out));
1618 /* In order to avoid some local loops,
1619 * if the RIPng route has a nexthop via this interface, keep the nexthop,
1620 * otherwise set it to 0. The nexthop should not be propagated
1621 * beyond the local broadcast/multicast area in order
1622 * to avoid an IGP multi-level recursive look-up.
1623 */
1624 if (rinfo->ifindex == ifp->ifindex)
1625 rinfo->nexthop_out = rinfo->nexthop;
1626
1627 /* Apply output filters. */
644ed6c5 1628 ret = ripng_filter (RIPNG_FILTER_OUT, p, ri);
a94434b6 1629 if (ret < 0)
1630 continue;
718e3744 1631
1632 /* Changed route only output. */
1633 if (route_type == ripng_changed_route &&
1634 (! (rinfo->flags & RIPNG_RTF_CHANGED)))
1635 continue;
1636
1637 /* Split horizon. */
a94434b6 1638 if (ri->split_horizon == RIPNG_SPLIT_HORIZON)
1639 {
1640 /* We perform split horizon for RIPng routes. */
c880b636
FL
1641 int suppress = 0;
1642 struct ripng_info *tmp_rinfo = NULL;
1643
1644 for (ALL_LIST_ELEMENTS_RO (list, listnode, tmp_rinfo))
1645 if (tmp_rinfo->type == ZEBRA_ROUTE_RIPNG &&
1646 tmp_rinfo->ifindex == ifp->ifindex)
1647 {
1648 suppress = 1;
1649 break;
1650 }
1651 if (suppress)
a94434b6 1652 continue;
1653 }
718e3744 1654
1655 /* Preparation for route-map. */
a94434b6 1656 rinfo->metric_set = 0;
1657 /* nexthop_out,
1658 * metric_out
1659 * and tag_out are already initialized.
1660 */
718e3744 1661
a94434b6 1662 /* Interface route-map */
718e3744 1663 if (ri->routemap[RIPNG_FILTER_OUT])
1664 {
1665 int ret;
718e3744 1666
1667 ret = route_map_apply (ri->routemap[RIPNG_FILTER_OUT],
1668 (struct prefix *) p, RMAP_RIPNG,
a94434b6 1669 rinfo);
718e3744 1670
1671 if (ret == RMAP_DENYMATCH)
1672 {
1673 if (IS_RIPNG_DEBUG_PACKET)
c6106812 1674 zlog_debug ("RIPng %s/%d is filtered by route-map out",
3a2ce6a1 1675 inet6_ntoa (p->prefix), p->prefixlen);
a94434b6 1676 continue;
718e3744 1677 }
1678
718e3744 1679 }
1680
a94434b6 1681 /* Redistribute route-map. */
1682 if (ripng->route_map[rinfo->type].name)
718e3744 1683 {
a94434b6 1684 int ret;
1685
1686 ret = route_map_apply (ripng->route_map[rinfo->type].map,
1687 (struct prefix *) p, RMAP_RIPNG,
bb3a023e 1688 rinfo);
a94434b6 1689
1690 if (ret == RMAP_DENYMATCH)
718e3744 1691 {
a94434b6 1692 if (IS_RIPNG_DEBUG_PACKET)
c6106812 1693 zlog_debug ("RIPng %s/%d is filtered by route-map",
3a2ce6a1 1694 inet6_ntoa (p->prefix), p->prefixlen);
a94434b6 1695 continue;
718e3744 1696 }
a94434b6 1697 }
718e3744 1698
a94434b6 1699 /* When the route-map does not set metric. */
1700 if (! rinfo->metric_set)
1701 {
1702 /* If the redistribute metric is set. */
1703 if (ripng->route_map[rinfo->type].metric_config
1704 && rinfo->metric != RIPNG_METRIC_INFINITY)
1705 {
1706 rinfo->metric_out = ripng->route_map[rinfo->type].metric;
1707 }
1708 else
718e3744 1709 {
a94434b6 1710 /* If the route is not connected or localy generated
1711 one, use default-metric value */
1712 if (rinfo->type != ZEBRA_ROUTE_RIPNG
1713 && rinfo->type != ZEBRA_ROUTE_CONNECT
718e3744 1714 && rinfo->metric != RIPNG_METRIC_INFINITY)
a94434b6 1715 rinfo->metric_out = ripng->default_metric;
718e3744 1716 }
1717 }
1718
a94434b6 1719 /* Apply offset-list */
1720 if (rinfo->metric_out != RIPNG_METRIC_INFINITY)
1721 ripng_offset_list_apply_out (p, ifp, &rinfo->metric_out);
1722
1723 if (rinfo->metric_out > RIPNG_METRIC_INFINITY)
1724 rinfo->metric_out = RIPNG_METRIC_INFINITY;
1725
1726 /* Perform split-horizon with poisoned reverse
1727 * for RIPng routes.
1728 **/
1729 if (ri->split_horizon == RIPNG_SPLIT_HORIZON_POISONED_REVERSE) {
c880b636
FL
1730 struct ripng_info *tmp_rinfo = NULL;
1731
1732 for (ALL_LIST_ELEMENTS_RO (list, listnode, tmp_rinfo))
1733 if ((tmp_rinfo->type == ZEBRA_ROUTE_RIPNG) &&
1734 tmp_rinfo->ifindex == ifp->ifindex)
1735 rinfo->metric_out = RIPNG_METRIC_INFINITY;
a94434b6 1736 }
1737
1738 /* Add RTE to the list */
1739 ripng_rte_add(ripng_rte_list, p, rinfo, NULL);
718e3744 1740 }
a94434b6 1741
1742 /* Process the aggregated RTE entry */
718e3744 1743 if ((aggregate = rp->aggregate) != NULL &&
1744 aggregate->count > 0 &&
1745 aggregate->suppress == 0)
1746 {
a94434b6 1747 /* If no route-map are applied, the RTE will be these following
1748 * informations.
1749 */
718e3744 1750 p = (struct prefix_ipv6 *) &rp->p;
a94434b6 1751 aggregate->metric_set = 0;
1752 aggregate->metric_out = aggregate->metric;
1753 aggregate->tag_out = aggregate->tag;
1754 memset(&aggregate->nexthop_out, 0, sizeof(aggregate->nexthop_out));
718e3744 1755
1756 /* Apply output filters.*/
644ed6c5 1757 ret = ripng_filter (RIPNG_FILTER_OUT, p, ri);
a94434b6 1758 if (ret < 0)
1759 continue;
718e3744 1760
a94434b6 1761 /* Interface route-map */
718e3744 1762 if (ri->routemap[RIPNG_FILTER_OUT])
1763 {
1764 int ret;
1765 struct ripng_info newinfo;
1766
a94434b6 1767 /* let's cast the aggregate structure to ripng_info */
718e3744 1768 memset (&newinfo, 0, sizeof (struct ripng_info));
a94434b6 1769 /* the nexthop is :: */
1770 newinfo.metric = aggregate->metric;
1771 newinfo.metric_out = aggregate->metric_out;
1772 newinfo.tag = aggregate->tag;
1773 newinfo.tag_out = aggregate->tag_out;
718e3744 1774
1775 ret = route_map_apply (ri->routemap[RIPNG_FILTER_OUT],
1776 (struct prefix *) p, RMAP_RIPNG,
1777 &newinfo);
1778
1779 if (ret == RMAP_DENYMATCH)
1780 {
1781 if (IS_RIPNG_DEBUG_PACKET)
c6106812 1782 zlog_debug ("RIPng %s/%d is filtered by route-map out",
3a2ce6a1 1783 inet6_ntoa (p->prefix), p->prefixlen);
a94434b6 1784 continue;
718e3744 1785 }
1786
a94434b6 1787 aggregate->metric_out = newinfo.metric_out;
1788 aggregate->tag_out = newinfo.tag_out;
1789 if (IN6_IS_ADDR_LINKLOCAL(&newinfo.nexthop_out))
1790 aggregate->nexthop_out = newinfo.nexthop_out;
718e3744 1791 }
1792
a94434b6 1793 /* There is no redistribute routemap for the aggregated RTE */
1794
718e3744 1795 /* Changed route only output. */
a94434b6 1796 /* XXX, vincent, in order to increase time convergence,
1797 * it should be announced if a child has changed.
1798 */
718e3744 1799 if (route_type == ripng_changed_route)
1800 continue;
1801
a94434b6 1802 /* Apply offset-list */
1803 if (aggregate->metric_out != RIPNG_METRIC_INFINITY)
1804 ripng_offset_list_apply_out (p, ifp, &aggregate->metric_out);
1805
1806 if (aggregate->metric_out > RIPNG_METRIC_INFINITY)
1807 aggregate->metric_out = RIPNG_METRIC_INFINITY;
1808
1809 /* Add RTE to the list */
1810 ripng_rte_add(ripng_rte_list, p, NULL, aggregate);
718e3744 1811 }
1812
1813 }
718e3744 1814
a94434b6 1815 /* Flush the list */
1816 ripng_rte_send(ripng_rte_list, ifp, to);
1817 ripng_rte_free(ripng_rte_list);
718e3744 1818}
1819
1820/* Create new RIPng instance and set it to global variable. */
6ac29a51
PJ
1821static int
1822ripng_create (void)
718e3744 1823{
1824 /* ripng should be NULL. */
1825 assert (ripng == NULL);
1826
1827 /* Allocaste RIPng instance. */
393deb9b 1828 ripng = XCALLOC (MTYPE_RIPNG, sizeof (struct ripng));
718e3744 1829
1830 /* Default version and timer values. */
1831 ripng->version = RIPNG_V1;
1832 ripng->update_time = RIPNG_UPDATE_TIMER_DEFAULT;
1833 ripng->timeout_time = RIPNG_TIMEOUT_TIMER_DEFAULT;
1834 ripng->garbage_time = RIPNG_GARBAGE_TIMER_DEFAULT;
1835 ripng->default_metric = RIPNG_DEFAULT_METRIC_DEFAULT;
1836
1837 /* Make buffer. */
1838 ripng->ibuf = stream_new (RIPNG_MAX_PACKET_SIZE * 5);
1839 ripng->obuf = stream_new (RIPNG_MAX_PACKET_SIZE);
1840
1841 /* Initialize RIPng routig table. */
1842 ripng->table = route_table_init ();
1843 ripng->route = route_table_init ();
1844 ripng->aggregate = route_table_init ();
1845
1846 /* Make socket. */
1847 ripng->sock = ripng_make_socket ();
1848 if (ripng->sock < 0)
1849 return ripng->sock;
1850
1851 /* Threads. */
1852 ripng_event (RIPNG_READ, ripng->sock);
1853 ripng_event (RIPNG_UPDATE_EVENT, 1);
1854
1855 return 0;
1856}
1857
a94434b6 1858/* Send RIPng request to the interface. */
718e3744 1859int
1860ripng_request (struct interface *ifp)
1861{
1862 struct rte *rte;
1863 struct ripng_packet ripng_packet;
1864
a94434b6 1865 /* In default ripd doesn't send RIP_REQUEST to the loopback interface. */
1866 if (if_is_loopback(ifp))
1867 return 0;
1868
1869 /* If interface is down, don't send RIP packet. */
1870 if (! if_is_up (ifp))
1871 return 0;
1872
718e3744 1873 if (IS_RIPNG_DEBUG_EVENT)
c6106812 1874 zlog_debug ("RIPng send request to %s", ifp->name);
718e3744 1875
1876 memset (&ripng_packet, 0, sizeof (ripng_packet));
1877 ripng_packet.command = RIPNG_REQUEST;
1878 ripng_packet.version = RIPNG_V1;
1879 rte = ripng_packet.rte;
1880 rte->metric = RIPNG_METRIC_INFINITY;
1881
1882 return ripng_send_packet ((caddr_t) &ripng_packet, sizeof (ripng_packet),
1883 NULL, ifp);
1884}
1885
6b0655a2 1886
6ac29a51 1887static int
718e3744 1888ripng_update_jitter (int time)
1889{
b06fd125 1890 return ((random () % (time + 1)) - (time / 2));
718e3744 1891}
1892
1893void
1894ripng_event (enum ripng_event event, int sock)
1895{
718e3744 1896 int jitter = 0;
1897
1898 switch (event)
1899 {
1900 case RIPNG_READ:
ffa2c898 1901 thread_add_read(master, ripng_read, NULL, sock, &ripng->t_read);
718e3744 1902 break;
1903 case RIPNG_UPDATE_EVENT:
1904 if (ripng->t_update)
1905 {
1906 thread_cancel (ripng->t_update);
1907 ripng->t_update = NULL;
1908 }
1909 /* Update timer jitter. */
1910 jitter = ripng_update_jitter (ripng->update_time);
1911
66e78ae6
QY
1912 ripng->t_update = NULL;
1913 thread_add_timer(master, ripng_update, NULL, sock ? 2 : ripng->update_time + jitter,
1914 &ripng->t_update);
718e3744 1915 break;
1916 case RIPNG_TRIGGERED_UPDATE:
1917 if (ripng->t_triggered_interval)
1918 ripng->trigger = 1;
ffa2c898
QY
1919 else thread_add_event(master, ripng_triggered_update, NULL, 0,
1920 &ripng->t_triggered_update);
718e3744 1921 break;
1922 default:
1923 break;
1924 }
1925}
6b0655a2 1926
718e3744 1927
718e3744 1928/* Print out routes update time. */
1929static void
1930ripng_vty_out_uptime (struct vty *vty, struct ripng_info *rinfo)
1931{
718e3744 1932 time_t clock;
1933 struct tm *tm;
1934#define TIME_BUF 25
1935 char timebuf [TIME_BUF];
1936 struct thread *thread;
1937
718e3744 1938 if ((thread = rinfo->t_timeout) != NULL)
1939 {
6dfa827b 1940 clock = thread_timer_remain_second (thread);
718e3744 1941 tm = gmtime (&clock);
1942 strftime (timebuf, TIME_BUF, "%M:%S", tm);
1943 vty_out (vty, "%5s", timebuf);
1944 }
1945 else if ((thread = rinfo->t_garbage_collect) != NULL)
1946 {
6dfa827b 1947 clock = thread_timer_remain_second (thread);
718e3744 1948 tm = gmtime (&clock);
1949 strftime (timebuf, TIME_BUF, "%M:%S", tm);
1950 vty_out (vty, "%5s", timebuf);
1951 }
1952}
1953
6ac29a51 1954static char *
a94434b6 1955ripng_route_subtype_print (struct ripng_info *rinfo)
1956{
1957 static char str[3];
1958 memset(str, 0, 3);
1959
1960 if (rinfo->suppress)
1961 strcat(str, "S");
1962
1963 switch (rinfo->sub_type)
1964 {
1965 case RIPNG_ROUTE_RTE:
1966 strcat(str, "n");
1967 break;
1968 case RIPNG_ROUTE_STATIC:
1969 strcat(str, "s");
1970 break;
1971 case RIPNG_ROUTE_DEFAULT:
1972 strcat(str, "d");
1973 break;
1974 case RIPNG_ROUTE_REDISTRIBUTE:
1975 strcat(str, "r");
1976 break;
1977 case RIPNG_ROUTE_INTERFACE:
1978 strcat(str, "i");
1979 break;
1980 default:
1981 strcat(str, "?");
1982 break;
1983 }
1984
1985 return str;
1986}
1987
718e3744 1988DEFUN (show_ipv6_ripng,
1989 show_ipv6_ripng_cmd,
1990 "show ipv6 ripng",
1991 SHOW_STR
8d0f15fd 1992 IPV6_STR
718e3744 1993 "Show RIPng routes\n")
1994{
1995 struct route_node *rp;
1996 struct ripng_info *rinfo;
1997 struct ripng_aggregate *aggregate;
1998 struct prefix_ipv6 *p;
c880b636
FL
1999 struct list *list = NULL;
2000 struct listnode *listnode = NULL;
718e3744 2001 int len;
2002
a94434b6 2003 if (! ripng)
2004 return CMD_SUCCESS;
2005
718e3744 2006 /* Header of display. */
96ade3ed 2007 vty_outln (vty, "Codes: R - RIPng, C - connected, S - Static, O - OSPF, B - BGP%s"
a94434b6 2008 "Sub-codes:%s"
2009 " (n) - normal, (s) - static, (d) - default, (r) - redistribute,%s"
2010 " (i) - interface, (a/S) - aggregated/Suppressed%s%s"
96ade3ed 2011 " Network Next Hop Via Metric Tag Time",
1318e7c8
QY
2012 VTYNL, VTYNL, VTYNL,
2013 VTYNL, VTYNL);
718e3744 2014
2015 for (rp = route_top (ripng->table); rp; rp = route_next (rp))
2016 {
2017 if ((aggregate = rp->aggregate) != NULL)
2018 {
2019 p = (struct prefix_ipv6 *) &rp->p;
2020
2021#ifdef DEBUG
c16b6d31 2022 vty_out (vty, "R(a) %d/%d %s/%d ",
718e3744 2023 aggregate->count, aggregate->suppress,
3a2ce6a1 2024 inet6_ntoa (p->prefix), p->prefixlen);
718e3744 2025#else
c16b6d31 2026 vty_out (vty, "R(a) %s/%d ",
3a2ce6a1 2027 inet6_ntoa (p->prefix), p->prefixlen);
718e3744 2028#endif /* DEBUG */
e31b6333 2029 vty_out (vty, VTYNL);
a94434b6 2030 vty_out (vty, "%*s", 18, " ");
718e3744 2031
a94434b6 2032 vty_out (vty, "%*s", 28, " ");
96ade3ed
QY
2033 vty_outln (vty, "self %2d %3"ROUTE_TAG_PRI"", aggregate->metric,
2034 (route_tag_t)aggregate->tag);
718e3744 2035 }
2036
c880b636
FL
2037 if ((list = rp->info) != NULL)
2038 for (ALL_LIST_ELEMENTS_RO (list, listnode, rinfo))
718e3744 2039 {
2040 p = (struct prefix_ipv6 *) &rp->p;
2041
2042#ifdef DEBUG
c16b6d31 2043 vty_out (vty, "%c(%s) 0/%d %s/%d ",
f52d13cb 2044 zebra_route_char(rinfo->type),
a94434b6 2045 ripng_route_subtype_print(rinfo),
718e3744 2046 rinfo->suppress,
3a2ce6a1 2047 inet6_ntoa (p->prefix), p->prefixlen);
718e3744 2048#else
c16b6d31 2049 vty_out (vty, "%c(%s) %s/%d ",
f52d13cb 2050 zebra_route_char(rinfo->type),
a94434b6 2051 ripng_route_subtype_print(rinfo),
3a2ce6a1 2052 inet6_ntoa (p->prefix), p->prefixlen);
718e3744 2053#endif /* DEBUG */
e31b6333 2054 vty_out (vty, VTYNL);
a94434b6 2055 vty_out (vty, "%*s", 18, " ");
3a2ce6a1 2056 len = vty_out (vty, "%s", inet6_ntoa (rinfo->nexthop));
a94434b6 2057
2058 len = 28 - len;
718e3744 2059 if (len > 0)
a94434b6 2060 len = vty_out (vty, "%*s", len, " ");
718e3744 2061
a94434b6 2062 /* from */
2063 if ((rinfo->type == ZEBRA_ROUTE_RIPNG) &&
2064 (rinfo->sub_type == RIPNG_ROUTE_RTE))
2065 {
baaea325 2066 len = vty_out (vty, "%s", ifindex2ifname(rinfo->ifindex, VRF_DEFAULT));
a94434b6 2067 } else if (rinfo->metric == RIPNG_METRIC_INFINITY)
2068 {
2069 len = vty_out (vty, "kill");
2070 } else
2071 len = vty_out (vty, "self");
718e3744 2072
a94434b6 2073 len = 9 - len;
718e3744 2074 if (len > 0)
2075 vty_out (vty, "%*s", len, " ");
2076
dc9ffce8
CF
2077 vty_out (vty, " %2d %3"ROUTE_TAG_PRI" ",
2078 rinfo->metric, (route_tag_t)rinfo->tag);
718e3744 2079
a94434b6 2080 /* time */
2081 if ((rinfo->type == ZEBRA_ROUTE_RIPNG) &&
2082 (rinfo->sub_type == RIPNG_ROUTE_RTE))
2083 {
2084 /* RTE from remote RIP routers */
718e3744 2085 ripng_vty_out_uptime (vty, rinfo);
a94434b6 2086 } else if (rinfo->metric == RIPNG_METRIC_INFINITY)
2087 {
2088 /* poisonous reversed routes (gc) */
2089 ripng_vty_out_uptime (vty, rinfo);
2090 }
718e3744 2091
e31b6333 2092 vty_out (vty, VTYNL);
718e3744 2093 }
2094 }
2095
2096 return CMD_SUCCESS;
2097}
2098
a94434b6 2099DEFUN (show_ipv6_ripng_status,
2100 show_ipv6_ripng_status_cmd,
2101 "show ipv6 ripng status",
2102 SHOW_STR
8d0f15fd 2103 IPV6_STR
a94434b6 2104 "Show RIPng routes\n"
2105 "IPv6 routing protocol process parameters and statistics\n")
2106{
52dc7ee6 2107 struct listnode *node;
1eb8ef25 2108 struct interface *ifp;
a94434b6 2109
2110 if (! ripng)
2111 return CMD_SUCCESS;
2112
96ade3ed 2113 vty_outln (vty, "Routing Protocol is \"RIPng\"");
a94434b6 2114 vty_out (vty, " Sending updates every %ld seconds with +/-50%%,",
2115 ripng->update_time);
96ade3ed
QY
2116 vty_outln (vty, " next due in %lu seconds",
2117 thread_timer_remain_second(ripng->t_update));
a94434b6 2118 vty_out (vty, " Timeout after %ld seconds,", ripng->timeout_time);
96ade3ed 2119 vty_outln (vty, " garbage collect after %ld seconds",ripng->garbage_time);
a94434b6 2120
2121 /* Filtering status show. */
2122 config_show_distribute (vty);
2123
2124 /* Default metric information. */
96ade3ed
QY
2125 vty_outln (vty, " Default redistribution metric is %d",
2126 ripng->default_metric);
a94434b6 2127
2128 /* Redistribute information. */
2129 vty_out (vty, " Redistributing:");
2130 ripng_redistribute_write (vty, 0);
e31b6333 2131 vty_out (vty, VTYNL);
a94434b6 2132
2133 vty_out (vty, " Default version control: send version %d,", ripng->version);
96ade3ed 2134 vty_outln (vty, " receive version %d ",ripng->version);
a94434b6 2135
96ade3ed 2136 vty_outln (vty, " Interface Send Recv");
a94434b6 2137
b2d7c082 2138 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp))
a94434b6 2139 {
2140 struct ripng_interface *ri;
1eb8ef25 2141
a94434b6 2142 ri = ifp->info;
2143
2144 if (ri->enable_network || ri->enable_interface)
2145 {
2146
96ade3ed 2147 vty_outln (vty, " %-17s%-3d %-3d", ifp->name,
a94434b6 2148 ripng->version,
96ade3ed 2149 ripng->version);
a94434b6 2150 }
2151 }
2152
96ade3ed 2153 vty_outln (vty, " Routing for Networks:");
a94434b6 2154 ripng_network_write (vty, 0);
2155
96ade3ed
QY
2156 vty_outln (vty, " Routing Information Sources:");
2157 vty_outln (vty,
2158 " Gateway BadPackets BadRoutes Distance Last Update");
a94434b6 2159 ripng_peer_display (vty);
2160
2161 return CMD_SUCCESS;
2162}
2163
d7f966ab
RW
2164DEFUN (clear_ipv6_rip,
2165 clear_ipv6_rip_cmd,
2166 "clear ipv6 ripng",
2167 CLEAR_STR
2168 IPV6_STR
d911a12a 2169 "Clear IPv6 RIP database\n")
d7f966ab
RW
2170{
2171 struct route_node *rp;
2172 struct ripng_info *rinfo;
2173 struct list *list;
2174 struct listnode *listnode;
2175
2176 /* Clear received RIPng routes */
2177 for (rp = route_top (ripng->table); rp; rp = route_next (rp))
2178 {
2179 list = rp->info;
2180 if (list == NULL)
2181 continue;
2182
2183 for (ALL_LIST_ELEMENTS_RO (list, listnode, rinfo))
2184 {
2185 if (! ripng_route_rte (rinfo))
2186 continue;
2187
2188 if (CHECK_FLAG (rinfo->flags, RIPNG_RTF_FIB))
2189 ripng_zebra_ipv6_delete (rp);
2190 break;
2191 }
2192
2193 if (rinfo)
2194 {
2195 RIPNG_TIMER_OFF (rinfo->t_timeout);
2196 RIPNG_TIMER_OFF (rinfo->t_garbage_collect);
2197 listnode_delete (list, rinfo);
2198 ripng_info_free (rinfo);
2199 }
2200
2201 if (list_isempty (list))
2202 {
2203 list_free (list);
2204 rp->info = NULL;
2205 route_unlock_node (rp);
2206 }
2207 }
2208
2209 return CMD_SUCCESS;
2210}
2211
505e5056 2212DEFUN_NOSH (router_ripng,
718e3744 2213 router_ripng_cmd,
2214 "router ripng",
2215 "Enable a routing process\n"
2216 "Make RIPng instance command\n")
2217{
2218 int ret;
2219
2220 vty->node = RIPNG_NODE;
2221
2222 if (!ripng)
2223 {
2224 ret = ripng_create ();
2225
2226 /* Notice to user we couldn't create RIPng. */
2227 if (ret < 0)
2228 {
2229 zlog_warn ("can't create RIPng");
f1a05de9 2230 return CMD_WARNING_CONFIG_FAILED;
718e3744 2231 }
2232 }
2233
2234 return CMD_SUCCESS;
2235}
2236
a94434b6 2237DEFUN (no_router_ripng,
2238 no_router_ripng_cmd,
2239 "no router ripng",
2240 NO_STR
2241 "Enable a routing process\n"
2242 "Make RIPng instance command\n")
2243{
2244 if(ripng)
2245 ripng_clean();
2246 return CMD_SUCCESS;
2247}
2248
718e3744 2249DEFUN (ripng_route,
2250 ripng_route_cmd,
2251 "route IPV6ADDR",
2252 "Static route setup\n"
2253 "Set static RIPng route announcement\n")
2254{
ab34a28a 2255 int idx_ipv6addr = 1;
718e3744 2256 int ret;
2257 struct prefix_ipv6 p;
2258 struct route_node *rp;
2259
ab34a28a 2260 ret = str2prefix_ipv6 (argv[idx_ipv6addr]->arg, (struct prefix_ipv6 *)&p);
718e3744 2261 if (ret <= 0)
2262 {
96ade3ed 2263 vty_outln (vty, "Malformed address");
f1a05de9 2264 return CMD_WARNING_CONFIG_FAILED;
718e3744 2265 }
2266 apply_mask_ipv6 (&p);
2267
2268 rp = route_node_get (ripng->route, (struct prefix *) &p);
2269 if (rp->info)
2270 {
96ade3ed 2271 vty_outln (vty, "There is already same static route.");
718e3744 2272 route_unlock_node (rp);
f1a05de9 2273 return CMD_WARNING_CONFIG_FAILED;
718e3744 2274 }
2275 rp->info = (void *)1;
2276
1796a585 2277 ripng_redistribute_add (ZEBRA_ROUTE_RIPNG, RIPNG_ROUTE_STATIC, &p, 0, NULL, 0);
718e3744 2278
2279 return CMD_SUCCESS;
2280}
2281
2282DEFUN (no_ripng_route,
2283 no_ripng_route_cmd,
2284 "no route IPV6ADDR",
2285 NO_STR
2286 "Static route setup\n"
2287 "Delete static RIPng route announcement\n")
2288{
ab34a28a 2289 int idx_ipv6addr = 2;
718e3744 2290 int ret;
2291 struct prefix_ipv6 p;
2292 struct route_node *rp;
2293
ab34a28a 2294 ret = str2prefix_ipv6 (argv[idx_ipv6addr]->arg, (struct prefix_ipv6 *)&p);
718e3744 2295 if (ret <= 0)
2296 {
96ade3ed 2297 vty_outln (vty, "Malformed address");
f1a05de9 2298 return CMD_WARNING_CONFIG_FAILED;
718e3744 2299 }
2300 apply_mask_ipv6 (&p);
2301
2302 rp = route_node_lookup (ripng->route, (struct prefix *) &p);
2303 if (! rp)
2304 {
96ade3ed 2305 vty_outln (vty, "Can't find static route.");
f1a05de9 2306 return CMD_WARNING_CONFIG_FAILED;
718e3744 2307 }
2308
2309 ripng_redistribute_delete (ZEBRA_ROUTE_RIPNG, RIPNG_ROUTE_STATIC, &p, 0);
2310 route_unlock_node (rp);
2311
2312 rp->info = NULL;
2313 route_unlock_node (rp);
2314
2315 return CMD_SUCCESS;
2316}
2317
2318DEFUN (ripng_aggregate_address,
2319 ripng_aggregate_address_cmd,
2320 "aggregate-address X:X::X:X/M",
2321 "Set aggregate RIPng route announcement\n"
2322 "Aggregate network\n")
2323{
ab34a28a 2324 int idx_ipv6_prefixlen = 1;
718e3744 2325 int ret;
2326 struct prefix p;
2327 struct route_node *node;
2328
ab34a28a 2329 ret = str2prefix_ipv6 (argv[idx_ipv6_prefixlen]->arg, (struct prefix_ipv6 *)&p);
718e3744 2330 if (ret <= 0)
2331 {
96ade3ed 2332 vty_outln (vty, "Malformed address");
f1a05de9 2333 return CMD_WARNING_CONFIG_FAILED;
718e3744 2334 }
2335
2336 /* Check aggregate alredy exist or not. */
2337 node = route_node_get (ripng->aggregate, &p);
2338 if (node->info)
2339 {
96ade3ed 2340 vty_outln (vty, "There is already same aggregate route.");
718e3744 2341 route_unlock_node (node);
f1a05de9 2342 return CMD_WARNING_CONFIG_FAILED;
718e3744 2343 }
2344 node->info = (void *)1;
2345
2346 ripng_aggregate_add (&p);
2347
2348 return CMD_SUCCESS;
2349}
2350
2351DEFUN (no_ripng_aggregate_address,
2352 no_ripng_aggregate_address_cmd,
2353 "no aggregate-address X:X::X:X/M",
2354 NO_STR
2355 "Delete aggregate RIPng route announcement\n"
d911a12a 2356 "Aggregate network\n")
718e3744 2357{
ab34a28a 2358 int idx_ipv6_prefixlen = 2;
718e3744 2359 int ret;
2360 struct prefix p;
2361 struct route_node *rn;
2362
ab34a28a 2363 ret = str2prefix_ipv6 (argv[idx_ipv6_prefixlen]->arg, (struct prefix_ipv6 *) &p);
718e3744 2364 if (ret <= 0)
2365 {
96ade3ed 2366 vty_outln (vty, "Malformed address");
f1a05de9 2367 return CMD_WARNING_CONFIG_FAILED;
718e3744 2368 }
2369
2370 rn = route_node_lookup (ripng->aggregate, &p);
2371 if (! rn)
2372 {
96ade3ed 2373 vty_outln (vty, "Can't find aggregate route.");
f1a05de9 2374 return CMD_WARNING_CONFIG_FAILED;
718e3744 2375 }
2376 route_unlock_node (rn);
2377 rn->info = NULL;
2378 route_unlock_node (rn);
2379
2380 ripng_aggregate_delete (&p);
2381
2382 return CMD_SUCCESS;
2383}
2384
2385DEFUN (ripng_default_metric,
2386 ripng_default_metric_cmd,
6147e2c6 2387 "default-metric (1-16)",
718e3744 2388 "Set a metric of redistribute routes\n"
2389 "Default metric\n")
2390{
ab34a28a 2391 int idx_number = 1;
718e3744 2392 if (ripng)
2393 {
ab34a28a 2394 ripng->default_metric = atoi (argv[idx_number]->arg);
718e3744 2395 }
2396 return CMD_SUCCESS;
2397}
2398
2399DEFUN (no_ripng_default_metric,
2400 no_ripng_default_metric_cmd,
55c727dd 2401 "no default-metric [(1-16)]",
718e3744 2402 NO_STR
2403 "Set a metric of redistribute routes\n"
2404 "Default metric\n")
2405{
2406 if (ripng)
2407 {
2408 ripng->default_metric = RIPNG_DEFAULT_METRIC_DEFAULT;
2409 }
2410 return CMD_SUCCESS;
2411}
2412
718e3744 2413
2414#if 0
2415/* RIPng update timer setup. */
2416DEFUN (ripng_update_timer,
2417 ripng_update_timer_cmd,
2418 "update-timer SECOND",
2419 "Set RIPng update timer in seconds\n"
2420 "Seconds\n")
2421{
2422 unsigned long update;
2423 char *endptr = NULL;
2424
2425 update = strtoul (argv[0], &endptr, 10);
2426 if (update == ULONG_MAX || *endptr != '\0')
2427 {
1318e7c8 2428 vty_out (vty, "update timer value error%s", VTYNL);
f1a05de9 2429 return CMD_WARNING_CONFIG_FAILED;
718e3744 2430 }
2431
2432 ripng->update_time = update;
2433
2434 ripng_event (RIPNG_UPDATE_EVENT, 0);
2435 return CMD_SUCCESS;
2436}
2437
2438DEFUN (no_ripng_update_timer,
2439 no_ripng_update_timer_cmd,
2440 "no update-timer SECOND",
2441 NO_STR
2442 "Unset RIPng update timer in seconds\n"
2443 "Seconds\n")
2444{
2445 ripng->update_time = RIPNG_UPDATE_TIMER_DEFAULT;
2446 ripng_event (RIPNG_UPDATE_EVENT, 0);
2447 return CMD_SUCCESS;
2448}
2449
2450/* RIPng timeout timer setup. */
2451DEFUN (ripng_timeout_timer,
2452 ripng_timeout_timer_cmd,
2453 "timeout-timer SECOND",
2454 "Set RIPng timeout timer in seconds\n"
2455 "Seconds\n")
2456{
2457 unsigned long timeout;
2458 char *endptr = NULL;
2459
2460 timeout = strtoul (argv[0], &endptr, 10);
2461 if (timeout == ULONG_MAX || *endptr != '\0')
2462 {
1318e7c8 2463 vty_out (vty, "timeout timer value error%s", VTYNL);
f1a05de9 2464 return CMD_WARNING_CONFIG_FAILED;
718e3744 2465 }
2466
2467 ripng->timeout_time = timeout;
2468
2469 return CMD_SUCCESS;
2470}
2471
2472DEFUN (no_ripng_timeout_timer,
2473 no_ripng_timeout_timer_cmd,
2474 "no timeout-timer SECOND",
2475 NO_STR
2476 "Unset RIPng timeout timer in seconds\n"
2477 "Seconds\n")
2478{
2479 ripng->timeout_time = RIPNG_TIMEOUT_TIMER_DEFAULT;
2480 return CMD_SUCCESS;
2481}
2482
2483/* RIPng garbage timer setup. */
2484DEFUN (ripng_garbage_timer,
2485 ripng_garbage_timer_cmd,
2486 "garbage-timer SECOND",
2487 "Set RIPng garbage timer in seconds\n"
2488 "Seconds\n")
2489{
2490 unsigned long garbage;
2491 char *endptr = NULL;
2492
2493 garbage = strtoul (argv[0], &endptr, 10);
2494 if (garbage == ULONG_MAX || *endptr != '\0')
2495 {
1318e7c8 2496 vty_out (vty, "garbage timer value error%s", VTYNL);
f1a05de9 2497 return CMD_WARNING_CONFIG_FAILED;
718e3744 2498 }
2499
2500 ripng->garbage_time = garbage;
2501
2502 return CMD_SUCCESS;
2503}
2504
2505DEFUN (no_ripng_garbage_timer,
2506 no_ripng_garbage_timer_cmd,
2507 "no garbage-timer SECOND",
2508 NO_STR
2509 "Unset RIPng garbage timer in seconds\n"
2510 "Seconds\n")
2511{
2512 ripng->garbage_time = RIPNG_GARBAGE_TIMER_DEFAULT;
2513 return CMD_SUCCESS;
2514}
2515#endif /* 0 */
2516
2517DEFUN (ripng_timers,
2518 ripng_timers_cmd,
6147e2c6 2519 "timers basic (0-65535) (0-65535) (0-65535)",
718e3744 2520 "RIPng timers setup\n"
2521 "Basic timer\n"
2522 "Routing table update timer value in second. Default is 30.\n"
2523 "Routing information timeout timer. Default is 180.\n"
2524 "Garbage collection timer. Default is 120.\n")
2525{
ab34a28a
DW
2526 int idx_number = 2;
2527 int idx_number_2 = 3;
2528 int idx_number_3 = 4;
718e3744 2529 unsigned long update;
2530 unsigned long timeout;
2531 unsigned long garbage;
718e3744 2532
facfee22
QY
2533 update = strtoul(argv[idx_number]->arg, NULL, 10);
2534 timeout = strtoul(argv[idx_number_2]->arg, NULL, 10);
2535 garbage = strtoul(argv[idx_number_3]->arg, NULL, 10);
718e3744 2536
2537 /* Set each timer value. */
2538 ripng->update_time = update;
2539 ripng->timeout_time = timeout;
2540 ripng->garbage_time = garbage;
2541
2542 /* Reset update timer thread. */
2543 ripng_event (RIPNG_UPDATE_EVENT, 0);
2544
2545 return CMD_SUCCESS;
2546}
2547
2548DEFUN (no_ripng_timers,
2549 no_ripng_timers_cmd,
d04c479d 2550 "no timers basic [(0-65535) (0-65535) (0-65535)]",
718e3744 2551 NO_STR
2552 "RIPng timers setup\n"
c8952fc1
QY
2553 "Basic timer\n"
2554 "Routing table update timer value in second. Default is 30.\n"
2555 "Routing information timeout timer. Default is 180.\n"
2556 "Garbage collection timer. Default is 120.\n")
718e3744 2557{
2558 /* Set each timer value to the default. */
2559 ripng->update_time = RIPNG_UPDATE_TIMER_DEFAULT;
2560 ripng->timeout_time = RIPNG_TIMEOUT_TIMER_DEFAULT;
2561 ripng->garbage_time = RIPNG_GARBAGE_TIMER_DEFAULT;
2562
2563 /* Reset update timer thread. */
2564 ripng_event (RIPNG_UPDATE_EVENT, 0);
2565
2566 return CMD_SUCCESS;
2567}
2568
d7d73ffc 2569#if 0
dd4f9f99
DW
2570DEFUN (show_ipv6_protocols,
2571 show_ipv6_protocols_cmd,
718e3744 2572 "show ipv6 protocols",
2573 SHOW_STR
8d0f15fd 2574 IPV6_STR
d911a12a 2575 "Routing protocol information\n")
718e3744 2576{
2577 if (! ripng)
2578 return CMD_SUCCESS;
2579
1318e7c8 2580 vty_out (vty, "Routing Protocol is \"ripng\"%s", VTYNL);
718e3744 2581
2582 vty_out (vty, "Sending updates every %ld seconds, next due in %d seconds%s",
2583 ripng->update_time, 0,
1318e7c8 2584 VTYNL);
718e3744 2585
2586 vty_out (vty, "Timerout after %ld seconds, garbage correct %ld%s",
2587 ripng->timeout_time,
2588 ripng->garbage_time,
1318e7c8 2589 VTYNL);
718e3744 2590
2591 vty_out (vty, "Outgoing update filter list for all interfaces is not set");
2592 vty_out (vty, "Incoming update filter list for all interfaces is not set");
2593
2594 return CMD_SUCCESS;
2595}
d7d73ffc 2596#endif
718e3744 2597
2598/* Please be carefull to use this command. */
a2c62831 2599DEFUN (ripng_default_information_originate,
2600 ripng_default_information_originate_cmd,
718e3744 2601 "default-information originate",
2602 "Default route information\n"
2603 "Distribute default route\n")
2604{
2605 struct prefix_ipv6 p;
2606
a94434b6 2607 if (! ripng ->default_information) {
2608 ripng->default_information = 1;
718e3744 2609
a94434b6 2610 str2prefix_ipv6 ("::/0", &p);
1796a585 2611 ripng_redistribute_add (ZEBRA_ROUTE_RIPNG, RIPNG_ROUTE_DEFAULT, &p, 0, NULL, 0);
a94434b6 2612 }
718e3744 2613
2614 return CMD_SUCCESS;
2615}
2616
a2c62831 2617DEFUN (no_ripng_default_information_originate,
2618 no_ripng_default_information_originate_cmd,
718e3744 2619 "no default-information originate",
2620 NO_STR
2621 "Default route information\n"
2622 "Distribute default route\n")
2623{
2624 struct prefix_ipv6 p;
2625
a94434b6 2626 if (ripng->default_information) {
2627 ripng->default_information = 0;
718e3744 2628
a94434b6 2629 str2prefix_ipv6 ("::/0", &p);
2630 ripng_redistribute_delete (ZEBRA_ROUTE_RIPNG, RIPNG_ROUTE_DEFAULT, &p, 0);
2631 }
718e3744 2632
2633 return CMD_SUCCESS;
2634}
2635
fac76f9c
FL
2636/* Update ECMP routes to zebra when ECMP is disabled. */
2637static void
2638ripng_ecmp_disable (void)
2639{
2640 struct route_node *rp;
2641 struct ripng_info *rinfo, *tmp_rinfo;
2642 struct list *list;
2643 struct listnode *node, *nextnode;
2644
2645 if (!ripng)
2646 return;
2647
2648 for (rp = route_top (ripng->table); rp; rp = route_next (rp))
2649 if ((list = rp->info) != NULL && listcount (list) > 1)
2650 {
2651 rinfo = listgetdata (listhead (list));
2652 if (!ripng_route_rte (rinfo))
2653 continue;
2654
2655 /* Drop all other entries, except the first one. */
2656 for (ALL_LIST_ELEMENTS (list, node, nextnode, tmp_rinfo))
2657 if (tmp_rinfo != rinfo)
2658 {
2659 RIPNG_TIMER_OFF (tmp_rinfo->t_timeout);
2660 RIPNG_TIMER_OFF (tmp_rinfo->t_garbage_collect);
2661 list_delete_node (list, node);
2662 ripng_info_free (tmp_rinfo);
2663 }
2664
2665 /* Update zebra. */
2666 ripng_zebra_ipv6_add (rp);
2667
2668 /* Set the route change flag. */
2669 SET_FLAG (rinfo->flags, RIPNG_RTF_CHANGED);
2670
2671 /* Signal the output process to trigger an update. */
2672 ripng_event (RIPNG_TRIGGERED_UPDATE, 0);
2673 }
2674}
2675
2676DEFUN (ripng_allow_ecmp,
2677 ripng_allow_ecmp_cmd,
2678 "allow-ecmp",
2679 "Allow Equal Cost MultiPath\n")
2680{
2681 if (ripng->ecmp)
2682 {
96ade3ed 2683 vty_outln (vty, "ECMP is already enabled.");
f1a05de9 2684 return CMD_WARNING_CONFIG_FAILED;
fac76f9c
FL
2685 }
2686
2687 ripng->ecmp = 1;
2688 zlog_info ("ECMP is enabled.");
2689 return CMD_SUCCESS;
2690}
2691
2692DEFUN (no_ripng_allow_ecmp,
2693 no_ripng_allow_ecmp_cmd,
2694 "no allow-ecmp",
2695 NO_STR
2696 "Allow Equal Cost MultiPath\n")
2697{
2698 if (!ripng->ecmp)
2699 {
96ade3ed 2700 vty_outln (vty, "ECMP is already disabled.");
f1a05de9 2701 return CMD_WARNING_CONFIG_FAILED;
fac76f9c
FL
2702 }
2703
2704 ripng->ecmp = 0;
2705 zlog_info ("ECMP is disabled.");
2706 ripng_ecmp_disable ();
2707 return CMD_SUCCESS;
2708}
2709
718e3744 2710/* RIPng configuration write function. */
6ac29a51 2711static int
718e3744 2712ripng_config_write (struct vty *vty)
2713{
a94434b6 2714 int ripng_network_write (struct vty *, int);
2715 void ripng_redistribute_write (struct vty *, int);
718e3744 2716 int write = 0;
2717 struct route_node *rp;
2718
2719 if (ripng)
2720 {
2721
2722 /* RIPng router. */
96ade3ed 2723 vty_outln (vty, "router ripng");
718e3744 2724
2725 if (ripng->default_information)
96ade3ed 2726 vty_outln (vty, " default-information originate");
718e3744 2727
a94434b6 2728 ripng_network_write (vty, 1);
718e3744 2729
2730 /* RIPng default metric configuration */
2731 if (ripng->default_metric != RIPNG_DEFAULT_METRIC_DEFAULT)
96ade3ed
QY
2732 vty_outln (vty, " default-metric %d",
2733 ripng->default_metric);
718e3744 2734
a94434b6 2735 ripng_redistribute_write (vty, 1);
2736
2737 /* RIP offset-list configuration. */
2738 config_write_ripng_offset_list (vty);
718e3744 2739
2740 /* RIPng aggregate routes. */
2741 for (rp = route_top (ripng->aggregate); rp; rp = route_next (rp))
2742 if (rp->info != NULL)
96ade3ed 2743 vty_outln (vty, " aggregate-address %s/%d",
3a2ce6a1 2744 inet6_ntoa (rp->p.u.prefix6),
96ade3ed 2745 rp->p.prefixlen);
718e3744 2746
fac76f9c
FL
2747 /* ECMP configuration. */
2748 if (ripng->ecmp)
96ade3ed 2749 vty_outln (vty, " allow-ecmp");
fac76f9c 2750
718e3744 2751 /* RIPng static routes. */
2752 for (rp = route_top (ripng->route); rp; rp = route_next (rp))
2753 if (rp->info != NULL)
96ade3ed
QY
2754 vty_outln (vty, " route %s/%d", inet6_ntoa (rp->p.u.prefix6),
2755 rp->p.prefixlen);
718e3744 2756
2757 /* RIPng timers configuration. */
2758 if (ripng->update_time != RIPNG_UPDATE_TIMER_DEFAULT ||
2759 ripng->timeout_time != RIPNG_TIMEOUT_TIMER_DEFAULT ||
2760 ripng->garbage_time != RIPNG_GARBAGE_TIMER_DEFAULT)
2761 {
96ade3ed 2762 vty_outln (vty, " timers basic %ld %ld %ld",
718e3744 2763 ripng->update_time,
2764 ripng->timeout_time,
96ade3ed 2765 ripng->garbage_time);
718e3744 2766 }
2767#if 0
2768 if (ripng->update_time != RIPNG_UPDATE_TIMER_DEFAULT)
2769 vty_out (vty, " update-timer %d%s", ripng->update_time,
1318e7c8 2770 VTYNL);
718e3744 2771 if (ripng->timeout_time != RIPNG_TIMEOUT_TIMER_DEFAULT)
2772 vty_out (vty, " timeout-timer %d%s", ripng->timeout_time,
1318e7c8 2773 VTYNL);
718e3744 2774 if (ripng->garbage_time != RIPNG_GARBAGE_TIMER_DEFAULT)
2775 vty_out (vty, " garbage-timer %d%s", ripng->garbage_time,
1318e7c8 2776 VTYNL);
718e3744 2777#endif /* 0 */
2778
2779 write += config_write_distribute (vty);
2780
2781 write += config_write_if_rmap (vty);
2782
2783 write++;
2784 }
2785 return write;
2786}
2787
2788/* RIPng node structure. */
7fc626de 2789static struct cmd_node cmd_ripng_node =
718e3744 2790{
2791 RIPNG_NODE,
2792 "%s(config-router)# ",
2793 1,
2794};
2795
6ac29a51 2796static void
718e3744 2797ripng_distribute_update (struct distribute *dist)
2798{
2799 struct interface *ifp;
2800 struct ripng_interface *ri;
2801 struct access_list *alist;
2802 struct prefix_list *plist;
2803
2804 if (! dist->ifname)
2805 return;
2806
1306c09a 2807 ifp = if_lookup_by_name (dist->ifname, VRF_DEFAULT);
718e3744 2808 if (ifp == NULL)
2809 return;
2810
2811 ri = ifp->info;
2812
fb23cf4a 2813 if (dist->list[DISTRIBUTE_V6_IN])
718e3744 2814 {
fb23cf4a 2815 alist = access_list_lookup (AFI_IP6, dist->list[DISTRIBUTE_V6_IN]);
718e3744 2816 if (alist)
2817 ri->list[RIPNG_FILTER_IN] = alist;
2818 else
2819 ri->list[RIPNG_FILTER_IN] = NULL;
2820 }
2821 else
2822 ri->list[RIPNG_FILTER_IN] = NULL;
2823
fb23cf4a 2824 if (dist->list[DISTRIBUTE_V6_OUT])
718e3744 2825 {
fb23cf4a 2826 alist = access_list_lookup (AFI_IP6, dist->list[DISTRIBUTE_V6_OUT]);
718e3744 2827 if (alist)
2828 ri->list[RIPNG_FILTER_OUT] = alist;
2829 else
2830 ri->list[RIPNG_FILTER_OUT] = NULL;
2831 }
2832 else
2833 ri->list[RIPNG_FILTER_OUT] = NULL;
2834
fb23cf4a 2835 if (dist->prefix[DISTRIBUTE_V6_IN])
718e3744 2836 {
fb23cf4a 2837 plist = prefix_list_lookup (AFI_IP6, dist->prefix[DISTRIBUTE_V6_IN]);
718e3744 2838 if (plist)
2839 ri->prefix[RIPNG_FILTER_IN] = plist;
2840 else
2841 ri->prefix[RIPNG_FILTER_IN] = NULL;
2842 }
2843 else
2844 ri->prefix[RIPNG_FILTER_IN] = NULL;
2845
fb23cf4a 2846 if (dist->prefix[DISTRIBUTE_V6_OUT])
718e3744 2847 {
fb23cf4a 2848 plist = prefix_list_lookup (AFI_IP6, dist->prefix[DISTRIBUTE_V6_OUT]);
718e3744 2849 if (plist)
2850 ri->prefix[RIPNG_FILTER_OUT] = plist;
2851 else
2852 ri->prefix[RIPNG_FILTER_OUT] = NULL;
2853 }
2854 else
2855 ri->prefix[RIPNG_FILTER_OUT] = NULL;
2856}
a94434b6 2857
718e3744 2858void
2859ripng_distribute_update_interface (struct interface *ifp)
2860{
2861 struct distribute *dist;
2862
2863 dist = distribute_lookup (ifp->name);
2864 if (dist)
2865 ripng_distribute_update (dist);
2866}
2867
2868/* Update all interface's distribute list. */
6ac29a51 2869static void
c9e52be3 2870ripng_distribute_update_all (struct prefix_list *notused)
718e3744 2871{
2872 struct interface *ifp;
52dc7ee6 2873 struct listnode *node;
718e3744 2874
b2d7c082 2875 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp))
1eb8ef25 2876 ripng_distribute_update_interface (ifp);
718e3744 2877}
c9e52be3 2878
6ac29a51 2879static void
c9e52be3 2880ripng_distribute_update_all_wrapper (struct access_list *notused)
2881{
2882 ripng_distribute_update_all(NULL);
2883}
6b0655a2 2884
a94434b6 2885/* delete all the added ripng routes. */
2886void
2887ripng_clean()
2888{
2889 int i;
2890 struct route_node *rp;
2891 struct ripng_info *rinfo;
c880b636
FL
2892 struct ripng_aggregate *aggregate;
2893 struct list *list = NULL;
2894 struct listnode *listnode = NULL;
a94434b6 2895
2896 if (ripng) {
2897 /* Clear RIPng routes */
c880b636
FL
2898 for (rp = route_top (ripng->table); rp; rp = route_next (rp))
2899 {
2900 if ((list = rp->info) != NULL)
2901 {
2902 rinfo = listgetdata (listhead (list));
2903 if (ripng_route_rte (rinfo))
2904 ripng_zebra_ipv6_delete (rp);
2905
2906 for (ALL_LIST_ELEMENTS_RO (list, listnode, rinfo))
2907 {
2908 RIPNG_TIMER_OFF (rinfo->t_timeout);
2909 RIPNG_TIMER_OFF (rinfo->t_garbage_collect);
2910 ripng_info_free (rinfo);
2911 }
2912 list_delete (list);
2913 rp->info = NULL;
2914 route_unlock_node (rp);
2915 }
2916
2917 if ((aggregate = rp->aggregate) != NULL)
2918 {
2919 ripng_aggregate_free (aggregate);
2920 rp->aggregate = NULL;
2921 route_unlock_node (rp);
2922 }
a94434b6 2923 }
2924
2925 /* Cancel the RIPng timers */
2926 RIPNG_TIMER_OFF (ripng->t_update);
2927 RIPNG_TIMER_OFF (ripng->t_triggered_update);
2928 RIPNG_TIMER_OFF (ripng->t_triggered_interval);
2929
2930 /* Cancel the read thread */
2931 if (ripng->t_read) {
2932 thread_cancel (ripng->t_read);
2933 ripng->t_read = NULL;
2934 }
2935
2936 /* Close the RIPng socket */
2937 if (ripng->sock >= 0) {
2938 close(ripng->sock);
2939 ripng->sock = -1;
2940 }
2941
2942 /* Static RIPng route configuration. */
2943 for (rp = route_top (ripng->route); rp; rp = route_next (rp))
2944 if (rp->info) {
2945 rp->info = NULL;
2946 route_unlock_node (rp);
2947 }
2948
2949 /* RIPng aggregated prefixes */
2950 for (rp = route_top (ripng->aggregate); rp; rp = route_next (rp))
2951 if (rp->info) {
2952 rp->info = NULL;
2953 route_unlock_node (rp);
2954 }
2955
2956 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
2957 if (ripng->route_map[i].name)
2958 free (ripng->route_map[i].name);
2959
2960 XFREE (MTYPE_ROUTE_TABLE, ripng->table);
2961 XFREE (MTYPE_ROUTE_TABLE, ripng->route);
2962 XFREE (MTYPE_ROUTE_TABLE, ripng->aggregate);
2963
0581e54d
QY
2964 stream_free (ripng->ibuf);
2965 stream_free (ripng->obuf);
2966
a94434b6 2967 XFREE (MTYPE_RIPNG, ripng);
2968 ripng = NULL;
2969 } /* if (ripng) */
2970
2971 ripng_clean_network();
2972 ripng_passive_interface_clean ();
2973 ripng_offset_clean ();
2974 ripng_interface_clean ();
2975 ripng_redistribute_clean ();
2976}
2977
2978/* Reset all values to the default settings. */
2979void
2980ripng_reset ()
2981{
2982 /* Call ripd related reset functions. */
2983 ripng_debug_reset ();
2984 ripng_route_map_reset ();
2985
2986 /* Call library reset functions. */
2987 vty_reset ();
2988 access_list_reset ();
2989 prefix_list_reset ();
2990
2991 distribute_list_reset ();
2992
2993 ripng_interface_reset ();
2994
2995 ripng_zclient_reset ();
2996}
718e3744 2997
6ac29a51 2998static void
718e3744 2999ripng_if_rmap_update (struct if_rmap *if_rmap)
3000{
3001 struct interface *ifp;
3002 struct ripng_interface *ri;
3003 struct route_map *rmap;
3004
1306c09a 3005 ifp = if_lookup_by_name (if_rmap->ifname, VRF_DEFAULT);
718e3744 3006 if (ifp == NULL)
3007 return;
3008
3009 ri = ifp->info;
3010
3011 if (if_rmap->routemap[IF_RMAP_IN])
3012 {
3013 rmap = route_map_lookup_by_name (if_rmap->routemap[IF_RMAP_IN]);
3014 if (rmap)
3015 ri->routemap[IF_RMAP_IN] = rmap;
3016 else
3017 ri->routemap[IF_RMAP_IN] = NULL;
3018 }
3019 else
3020 ri->routemap[RIPNG_FILTER_IN] = NULL;
3021
3022 if (if_rmap->routemap[IF_RMAP_OUT])
3023 {
3024 rmap = route_map_lookup_by_name (if_rmap->routemap[IF_RMAP_OUT]);
3025 if (rmap)
3026 ri->routemap[IF_RMAP_OUT] = rmap;
3027 else
3028 ri->routemap[IF_RMAP_OUT] = NULL;
3029 }
3030 else
3031 ri->routemap[RIPNG_FILTER_OUT] = NULL;
3032}
3033
3034void
3035ripng_if_rmap_update_interface (struct interface *ifp)
3036{
3037 struct if_rmap *if_rmap;
3038
3039 if_rmap = if_rmap_lookup (ifp->name);
3040 if (if_rmap)
3041 ripng_if_rmap_update (if_rmap);
3042}
3043
6ac29a51 3044static void
718e3744 3045ripng_routemap_update_redistribute (void)
3046{
3047 int i;
3048
3049 if (ripng)
3050 {
3051 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
3052 {
3053 if (ripng->route_map[i].name)
3054 ripng->route_map[i].map =
3055 route_map_lookup_by_name (ripng->route_map[i].name);
3056 }
3057 }
3058}
3059
6ac29a51 3060static void
98b718a9 3061ripng_routemap_update (const char *unused)
718e3744 3062{
3063 struct interface *ifp;
52dc7ee6 3064 struct listnode *node;
718e3744 3065
b2d7c082 3066 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp))
1eb8ef25 3067 ripng_if_rmap_update_interface (ifp);
718e3744 3068
3069 ripng_routemap_update_redistribute ();
3070}
3071
3072/* Initialize ripng structure and set commands. */
3073void
3074ripng_init ()
3075{
718e3744 3076 /* Install RIPNG_NODE. */
3077 install_node (&cmd_ripng_node, ripng_config_write);
3078
3079 /* Install ripng commands. */
3080 install_element (VIEW_NODE, &show_ipv6_ripng_cmd);
a94434b6 3081 install_element (VIEW_NODE, &show_ipv6_ripng_status_cmd);
718e3744 3082
d7f966ab
RW
3083 install_element (ENABLE_NODE, &clear_ipv6_rip_cmd);
3084
718e3744 3085 install_element (CONFIG_NODE, &router_ripng_cmd);
a94434b6 3086 install_element (CONFIG_NODE, &no_router_ripng_cmd);
718e3744 3087
3088 install_default (RIPNG_NODE);
3089 install_element (RIPNG_NODE, &ripng_route_cmd);
3090 install_element (RIPNG_NODE, &no_ripng_route_cmd);
3091 install_element (RIPNG_NODE, &ripng_aggregate_address_cmd);
3092 install_element (RIPNG_NODE, &no_ripng_aggregate_address_cmd);
3093
3094 install_element (RIPNG_NODE, &ripng_default_metric_cmd);
3095 install_element (RIPNG_NODE, &no_ripng_default_metric_cmd);
718e3744 3096
3097 install_element (RIPNG_NODE, &ripng_timers_cmd);
3098 install_element (RIPNG_NODE, &no_ripng_timers_cmd);
3099#if 0
ee9216cf 3100 install_element (VIEW_NODE, &show_ipv6_protocols_cmd);
718e3744 3101 install_element (RIPNG_NODE, &ripng_update_timer_cmd);
3102 install_element (RIPNG_NODE, &no_ripng_update_timer_cmd);
3103 install_element (RIPNG_NODE, &ripng_timeout_timer_cmd);
3104 install_element (RIPNG_NODE, &no_ripng_timeout_timer_cmd);
3105 install_element (RIPNG_NODE, &ripng_garbage_timer_cmd);
3106 install_element (RIPNG_NODE, &no_ripng_garbage_timer_cmd);
3107#endif /* 0 */
3108
a2c62831 3109 install_element (RIPNG_NODE, &ripng_default_information_originate_cmd);
3110 install_element (RIPNG_NODE, &no_ripng_default_information_originate_cmd);
718e3744 3111
fac76f9c
FL
3112 install_element (RIPNG_NODE, &ripng_allow_ecmp_cmd);
3113 install_element (RIPNG_NODE, &no_ripng_allow_ecmp_cmd);
3114
718e3744 3115 ripng_if_init ();
3116 ripng_debug_init ();
3117
3118 /* Access list install. */
3119 access_list_init ();
c9e52be3 3120 access_list_add_hook (ripng_distribute_update_all_wrapper);
3121 access_list_delete_hook (ripng_distribute_update_all_wrapper);
718e3744 3122
3123 /* Prefix list initialize.*/
3124 prefix_list_init ();
3125 prefix_list_add_hook (ripng_distribute_update_all);
3126 prefix_list_delete_hook (ripng_distribute_update_all);
3127
3128 /* Distribute list install. */
3129 distribute_list_init (RIPNG_NODE);
3130 distribute_list_add_hook (ripng_distribute_update);
3131 distribute_list_delete_hook (ripng_distribute_update);
3132
3133 /* Route-map for interface. */
3134 ripng_route_map_init ();
a94434b6 3135 ripng_offset_init ();
3136
718e3744 3137 route_map_add_hook (ripng_routemap_update);
3138 route_map_delete_hook (ripng_routemap_update);
3139
0750d21f 3140 if_rmap_init (RIPNG_NODE);
718e3744 3141 if_rmap_hook_add (ripng_if_rmap_update);
3142 if_rmap_hook_delete (ripng_if_rmap_update);
3143}