2 * Copyright (C) 1998, 1999 Kunihiro Ishiguro
4 * This file is part of GNU Zebra.
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
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.
16 * You should have received a copy of the GNU General Public License
17 * along with GNU Zebra; see the file COPYING. If not, write to the Free
18 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
34 #include "distribute.h"
40 #include "ripngd/ripngd.h"
41 #include "ripngd/ripng_route.h"
42 #include "ripngd/ripng_debug.h"
43 #include "ripngd/ripng_nexthop.h"
45 /* RIPng structure which includes many parameters related to RIPng
46 protocol. If ripng couldn't active or ripng doesn't configured,
47 ripng->fd must be negative value. */
48 struct ripng
*ripng
= NULL
;
56 extern struct zebra_privs_t ripngd_privs
;
60 ripng_output_process (struct interface
*, struct sockaddr_in6
*, int);
63 ripng_triggered_update (struct thread
*);
65 /* RIPng next hop specification. */
68 enum ripng_nexthop_type
73 struct in6_addr address
;
77 ripng_route_rte (struct ripng_info
*rinfo
)
79 return (rinfo
->type
== ZEBRA_ROUTE_RIPNG
&& rinfo
->sub_type
== RIPNG_ROUTE_RTE
);
82 /* Allocate new ripng information. */
86 struct ripng_info
*new;
88 new = XCALLOC (MTYPE_RIPNG_ROUTE
, sizeof (struct ripng_info
));
92 /* Free ripng information. */
94 ripng_info_free (struct ripng_info
*rinfo
)
96 XFREE (MTYPE_RIPNG_ROUTE
, rinfo
);
99 /* Create ripng socket. */
101 ripng_make_socket (void)
105 struct sockaddr_in6 ripaddr
;
107 sock
= socket (AF_INET6
, SOCK_DGRAM
, 0);
110 zlog (NULL
, LOG_ERR
, "Can't make ripng socket");
114 ret
= setsockopt_so_recvbuf (sock
, 8096);
117 ret
= setsockopt_ipv6_pktinfo (sock
, 1);
120 ret
= setsockopt_ipv6_multicast_hops (sock
, 255);
123 ret
= setsockopt_ipv6_multicast_loop (sock
, 0);
126 ret
= setsockopt_ipv6_hoplimit (sock
, 1);
130 memset (&ripaddr
, 0, sizeof (ripaddr
));
131 ripaddr
.sin6_family
= AF_INET6
;
133 ripaddr
.sin6_len
= sizeof (struct sockaddr_in6
);
134 #endif /* SIN6_LEN */
135 ripaddr
.sin6_port
= htons (RIPNG_PORT_DEFAULT
);
137 if (ripngd_privs
.change (ZPRIVS_RAISE
))
138 zlog_err ("ripng_make_socket: could not raise privs");
140 ret
= bind (sock
, (struct sockaddr
*) &ripaddr
, sizeof (ripaddr
));
143 zlog (NULL
, LOG_ERR
, "Can't bind ripng socket: %s.", safe_strerror (errno
));
144 if (ripngd_privs
.change (ZPRIVS_LOWER
))
145 zlog_err ("ripng_make_socket: could not lower privs");
148 if (ripngd_privs
.change (ZPRIVS_LOWER
))
149 zlog_err ("ripng_make_socket: could not lower privs");
153 /* Send RIPng packet. */
155 ripng_send_packet (caddr_t buf
, int bufsize
, struct sockaddr_in6
*to
,
156 struct interface
*ifp
)
161 struct cmsghdr
*cmsgptr
;
163 struct in6_pktinfo
*pkt
;
164 struct sockaddr_in6 addr
;
166 if (IS_RIPNG_DEBUG_SEND
) {
168 zlog_debug ("send to %s", inet6_ntoa (to
->sin6_addr
));
169 zlog_debug (" send interface %s", ifp
->name
);
170 zlog_debug (" send packet size %d", bufsize
);
173 memset (&addr
, 0, sizeof (struct sockaddr_in6
));
174 addr
.sin6_family
= AF_INET6
;
176 addr
.sin6_len
= sizeof (struct sockaddr_in6
);
177 #endif /* SIN6_LEN */
178 addr
.sin6_flowinfo
= htonl (RIPNG_PRIORITY_DEFAULT
);
180 /* When destination is specified. */
183 addr
.sin6_addr
= to
->sin6_addr
;
184 addr
.sin6_port
= to
->sin6_port
;
188 inet_pton(AF_INET6
, RIPNG_GROUP
, &addr
.sin6_addr
);
189 addr
.sin6_port
= htons (RIPNG_PORT_DEFAULT
);
192 msg
.msg_name
= (void *) &addr
;
193 msg
.msg_namelen
= sizeof (struct sockaddr_in6
);
196 msg
.msg_control
= (void *) adata
;
197 msg
.msg_controllen
= CMSG_SPACE(sizeof(struct in6_pktinfo
));
200 iov
.iov_len
= bufsize
;
202 cmsgptr
= (struct cmsghdr
*)adata
;
203 cmsgptr
->cmsg_len
= CMSG_LEN(sizeof (struct in6_pktinfo
));
204 cmsgptr
->cmsg_level
= IPPROTO_IPV6
;
205 cmsgptr
->cmsg_type
= IPV6_PKTINFO
;
207 pkt
= (struct in6_pktinfo
*) CMSG_DATA (cmsgptr
);
208 memset (&pkt
->ipi6_addr
, 0, sizeof (struct in6_addr
));
209 pkt
->ipi6_ifindex
= ifp
->ifindex
;
211 ret
= sendmsg (ripng
->sock
, &msg
, 0);
215 zlog_err ("RIPng send fail on %s to %s: %s", ifp
->name
,
216 inet6_ntoa (to
->sin6_addr
), safe_strerror (errno
));
218 zlog_err ("RIPng send fail on %s: %s", ifp
->name
, safe_strerror (errno
));
224 /* Receive UDP RIPng packet from socket. */
226 ripng_recv_packet (int sock
, u_char
*buf
, int bufsize
,
227 struct sockaddr_in6
*from
, unsigned int *ifindex
,
233 struct cmsghdr
*cmsgptr
;
236 /* Ancillary data. This store cmsghdr and in6_pktinfo. But at this
237 point I can't determine size of cmsghdr */
240 /* Fill in message and iovec. */
241 msg
.msg_name
= (void *) from
;
242 msg
.msg_namelen
= sizeof (struct sockaddr_in6
);
245 msg
.msg_control
= (void *) adata
;
246 msg
.msg_controllen
= sizeof adata
;
248 iov
.iov_len
= bufsize
;
250 /* If recvmsg fail return minus value. */
251 ret
= recvmsg (sock
, &msg
, 0);
255 for (cmsgptr
= ZCMSG_FIRSTHDR(&msg
); cmsgptr
!= NULL
;
256 cmsgptr
= CMSG_NXTHDR(&msg
, cmsgptr
))
258 /* I want interface index which this packet comes from. */
259 if (cmsgptr
->cmsg_level
== IPPROTO_IPV6
&&
260 cmsgptr
->cmsg_type
== IPV6_PKTINFO
)
262 struct in6_pktinfo
*ptr
;
264 ptr
= (struct in6_pktinfo
*) CMSG_DATA (cmsgptr
);
265 *ifindex
= ptr
->ipi6_ifindex
;
266 dst
= ptr
->ipi6_addr
;
269 zlog_warn ("Interface index returned by IPV6_PKTINFO is zero");
272 /* Incoming packet's multicast hop limit. */
273 if (cmsgptr
->cmsg_level
== IPPROTO_IPV6
&&
274 cmsgptr
->cmsg_type
== IPV6_HOPLIMIT
)
275 *hoplimit
= *((int *) CMSG_DATA (cmsgptr
));
278 /* Hoplimit check shold be done when destination address is
279 multicast address. */
280 if (! IN6_IS_ADDR_MULTICAST (&dst
))
286 /* Dump rip packet */
288 ripng_packet_dump (struct ripng_packet
*packet
, int size
, const char *sndrcv
)
292 const char *command_str
;
294 /* Set command string. */
295 if (packet
->command
== RIPNG_REQUEST
)
296 command_str
= "request";
297 else if (packet
->command
== RIPNG_RESPONSE
)
298 command_str
= "response";
300 command_str
= "unknown";
302 /* Dump packet header. */
303 zlog_debug ("%s %s version %d packet size %d",
304 sndrcv
, command_str
, packet
->version
, size
);
306 /* Dump each routing table entry. */
309 for (lim
= (caddr_t
) packet
+ size
; (caddr_t
) rte
< lim
; rte
++)
311 if (rte
->metric
== RIPNG_METRIC_NEXTHOP
)
312 zlog_debug (" nexthop %s/%d", inet6_ntoa (rte
->addr
), rte
->prefixlen
);
314 zlog_debug (" %s/%d metric %d tag %d",
315 inet6_ntoa (rte
->addr
), rte
->prefixlen
,
316 rte
->metric
, ntohs (rte
->tag
));
320 /* RIPng next hop address RTE (Route Table Entry). */
322 ripng_nexthop_rte (struct rte
*rte
,
323 struct sockaddr_in6
*from
,
324 struct ripng_nexthop
*nexthop
)
326 char buf
[INET6_BUFSIZ
];
328 /* Logging before checking RTE. */
329 if (IS_RIPNG_DEBUG_RECV
)
330 zlog_debug ("RIPng nexthop RTE address %s tag %d prefixlen %d",
331 inet6_ntoa (rte
->addr
), ntohs (rte
->tag
), rte
->prefixlen
);
333 /* RFC2080 2.1.1 Next Hop:
334 The route tag and prefix length in the next hop RTE must be
335 set to zero on sending and ignored on receiption. */
336 if (ntohs (rte
->tag
) != 0)
337 zlog_warn ("RIPng nexthop RTE with non zero tag value %d from %s",
338 ntohs (rte
->tag
), inet6_ntoa (from
->sin6_addr
));
340 if (rte
->prefixlen
!= 0)
341 zlog_warn ("RIPng nexthop RTE with non zero prefixlen value %d from %s",
342 rte
->prefixlen
, inet6_ntoa (from
->sin6_addr
));
344 /* Specifying a value of 0:0:0:0:0:0:0:0 in the prefix field of a
345 next hop RTE indicates that the next hop address should be the
346 originator of the RIPng advertisement. An address specified as a
347 next hop must be a link-local address. */
348 if (IN6_IS_ADDR_UNSPECIFIED (&rte
->addr
))
350 nexthop
->flag
= RIPNG_NEXTHOP_UNSPEC
;
351 memset (&nexthop
->address
, 0, sizeof (struct in6_addr
));
355 if (IN6_IS_ADDR_LINKLOCAL (&rte
->addr
))
357 nexthop
->flag
= RIPNG_NEXTHOP_ADDRESS
;
358 IPV6_ADDR_COPY (&nexthop
->address
, &rte
->addr
);
362 /* The purpose of the next hop RTE is to eliminate packets being
363 routed through extra hops in the system. It is particularly useful
364 when RIPng is not being run on all of the routers on a network.
365 Note that next hop RTE is "advisory". That is, if the provided
366 information is ignored, a possibly sub-optimal, but absolutely
367 valid, route may be taken. If the received next hop address is not
368 a link-local address, it should be treated as 0:0:0:0:0:0:0:0. */
369 zlog_warn ("RIPng nexthop RTE with non link-local address %s from %s",
370 inet6_ntoa (rte
->addr
),
371 inet_ntop (AF_INET6
, &from
->sin6_addr
, buf
, INET6_BUFSIZ
));
373 nexthop
->flag
= RIPNG_NEXTHOP_UNSPEC
;
374 memset (&nexthop
->address
, 0, sizeof (struct in6_addr
));
379 /* If ifp has same link-local address then return 1. */
381 ripng_lladdr_check (struct interface
*ifp
, struct in6_addr
*addr
)
383 struct listnode
*node
;
384 struct connected
*connected
;
387 for (ALL_LIST_ELEMENTS_RO (ifp
->connected
, node
, connected
))
389 p
= connected
->address
;
391 if (p
->family
== AF_INET6
&&
392 IN6_IS_ADDR_LINKLOCAL (&p
->u
.prefix6
) &&
393 IN6_ARE_ADDR_EQUAL (&p
->u
.prefix6
, addr
))
399 /* RIPng route garbage collect timer. */
401 ripng_garbage_collect (struct thread
*t
)
403 struct ripng_info
*rinfo
;
404 struct route_node
*rp
;
406 rinfo
= THREAD_ARG (t
);
407 rinfo
->t_garbage_collect
= NULL
;
409 /* Off timeout timer. */
410 RIPNG_TIMER_OFF (rinfo
->t_timeout
);
412 /* Get route_node pointer. */
415 /* Unlock route_node. */
417 route_unlock_node (rp
);
419 /* Free RIPng routing information. */
420 ripng_info_free (rinfo
);
425 /* Timeout RIPng routes. */
427 ripng_timeout (struct thread
*t
)
429 struct ripng_info
*rinfo
;
430 struct route_node
*rp
;
432 rinfo
= THREAD_ARG (t
);
433 rinfo
->t_timeout
= NULL
;
435 /* Get route_node pointer. */
438 /* - The garbage-collection timer is set for 120 seconds. */
439 RIPNG_TIMER_ON (rinfo
->t_garbage_collect
, ripng_garbage_collect
,
440 ripng
->garbage_time
);
442 /* Delete this route from the kernel. */
443 ripng_zebra_ipv6_delete ((struct prefix_ipv6
*)&rp
->p
, &rinfo
->nexthop
,
445 /* - The metric for the route is set to 16 (infinity). This causes
446 the route to be removed from service. */
447 rinfo
->metric
= RIPNG_METRIC_INFINITY
;
448 rinfo
->flags
&= ~RIPNG_RTF_FIB
;
450 /* Aggregate count decrement. */
451 ripng_aggregate_decrement (rp
, rinfo
);
453 /* - The route change flag is to indicate that this entry has been
455 rinfo
->flags
|= RIPNG_RTF_CHANGED
;
457 /* - The output process is signalled to trigger a response. */
458 ripng_event (RIPNG_TRIGGERED_UPDATE
, 0);
464 ripng_timeout_update (struct ripng_info
*rinfo
)
466 if (rinfo
->metric
!= RIPNG_METRIC_INFINITY
)
468 RIPNG_TIMER_OFF (rinfo
->t_timeout
);
469 RIPNG_TIMER_ON (rinfo
->t_timeout
, ripng_timeout
, ripng
->timeout_time
);
474 ripng_incoming_filter (struct prefix_ipv6
*p
, struct ripng_interface
*ri
)
476 struct distribute
*dist
;
477 struct access_list
*alist
;
478 struct prefix_list
*plist
;
480 /* Input distribute-list filtering. */
481 if (ri
->list
[RIPNG_FILTER_IN
])
483 if (access_list_apply (ri
->list
[RIPNG_FILTER_IN
],
484 (struct prefix
*) p
) == FILTER_DENY
)
486 if (IS_RIPNG_DEBUG_PACKET
)
487 zlog_debug ("%s/%d filtered by distribute in",
488 inet6_ntoa (p
->prefix
), p
->prefixlen
);
492 if (ri
->prefix
[RIPNG_FILTER_IN
])
494 if (prefix_list_apply (ri
->prefix
[RIPNG_FILTER_IN
],
495 (struct prefix
*) p
) == PREFIX_DENY
)
497 if (IS_RIPNG_DEBUG_PACKET
)
498 zlog_debug ("%s/%d filtered by prefix-list in",
499 inet6_ntoa (p
->prefix
), p
->prefixlen
);
504 /* All interface filter check. */
505 dist
= distribute_lookup (NULL
);
508 if (dist
->list
[DISTRIBUTE_IN
])
510 alist
= access_list_lookup (AFI_IP6
, dist
->list
[DISTRIBUTE_IN
]);
514 if (access_list_apply (alist
,
515 (struct prefix
*) p
) == FILTER_DENY
)
517 if (IS_RIPNG_DEBUG_PACKET
)
518 zlog_debug ("%s/%d filtered by distribute in",
519 inet6_ntoa (p
->prefix
), p
->prefixlen
);
524 if (dist
->prefix
[DISTRIBUTE_IN
])
526 plist
= prefix_list_lookup (AFI_IP6
, dist
->prefix
[DISTRIBUTE_IN
]);
530 if (prefix_list_apply (plist
,
531 (struct prefix
*) p
) == PREFIX_DENY
)
533 if (IS_RIPNG_DEBUG_PACKET
)
534 zlog_debug ("%s/%d filtered by prefix-list in",
535 inet6_ntoa (p
->prefix
), p
->prefixlen
);
545 ripng_outgoing_filter (struct prefix_ipv6
*p
, struct ripng_interface
*ri
)
547 struct distribute
*dist
;
548 struct access_list
*alist
;
549 struct prefix_list
*plist
;
551 if (ri
->list
[RIPNG_FILTER_OUT
])
553 if (access_list_apply (ri
->list
[RIPNG_FILTER_OUT
],
554 (struct prefix
*) p
) == FILTER_DENY
)
556 if (IS_RIPNG_DEBUG_PACKET
)
557 zlog_debug ("%s/%d is filtered by distribute out",
558 inet6_ntoa (p
->prefix
), p
->prefixlen
);
562 if (ri
->prefix
[RIPNG_FILTER_OUT
])
564 if (prefix_list_apply (ri
->prefix
[RIPNG_FILTER_OUT
],
565 (struct prefix
*) p
) == PREFIX_DENY
)
567 if (IS_RIPNG_DEBUG_PACKET
)
568 zlog_debug ("%s/%d is filtered by prefix-list out",
569 inet6_ntoa (p
->prefix
), p
->prefixlen
);
574 /* All interface filter check. */
575 dist
= distribute_lookup (NULL
);
578 if (dist
->list
[DISTRIBUTE_OUT
])
580 alist
= access_list_lookup (AFI_IP6
, dist
->list
[DISTRIBUTE_OUT
]);
584 if (access_list_apply (alist
,
585 (struct prefix
*) p
) == FILTER_DENY
)
587 if (IS_RIPNG_DEBUG_PACKET
)
588 zlog_debug ("%s/%d filtered by distribute out",
589 inet6_ntoa (p
->prefix
), p
->prefixlen
);
594 if (dist
->prefix
[DISTRIBUTE_OUT
])
596 plist
= prefix_list_lookup (AFI_IP6
, dist
->prefix
[DISTRIBUTE_OUT
]);
600 if (prefix_list_apply (plist
,
601 (struct prefix
*) p
) == PREFIX_DENY
)
603 if (IS_RIPNG_DEBUG_PACKET
)
604 zlog_debug ("%s/%d filtered by prefix-list out",
605 inet6_ntoa (p
->prefix
), p
->prefixlen
);
614 /* Process RIPng route according to RFC2080. */
616 ripng_route_process (struct rte
*rte
, struct sockaddr_in6
*from
,
617 struct ripng_nexthop
*ripng_nexthop
,
618 struct interface
*ifp
)
621 struct prefix_ipv6 p
;
622 struct route_node
*rp
;
623 struct ripng_info
*rinfo
;
624 struct ripng_interface
*ri
;
625 struct in6_addr
*nexthop
;
629 /* Make prefix structure. */
630 memset (&p
, 0, sizeof (struct prefix_ipv6
));
632 /* p.prefix = rte->addr; */
633 IPV6_ADDR_COPY (&p
.prefix
, &rte
->addr
);
634 p
.prefixlen
= rte
->prefixlen
;
636 /* Make sure mask is applied. */
637 /* XXX We have to check the prefix is valid or not before call
639 apply_mask_ipv6 (&p
);
641 /* Apply input filters. */
644 ret
= ripng_incoming_filter (&p
, ri
);
649 if (ri
->routemap
[RIPNG_FILTER_IN
])
652 struct ripng_info newinfo
;
654 memset (&newinfo
, 0, sizeof (struct ripng_info
));
655 newinfo
.type
= ZEBRA_ROUTE_RIPNG
;
656 newinfo
.sub_type
= RIPNG_ROUTE_RTE
;
657 if (ripng_nexthop
->flag
== RIPNG_NEXTHOP_ADDRESS
)
658 newinfo
.nexthop
= ripng_nexthop
->address
;
660 newinfo
.nexthop
= from
->sin6_addr
;
661 newinfo
.from
= from
->sin6_addr
;
662 newinfo
.ifindex
= ifp
->ifindex
;
663 newinfo
.metric
= rte
->metric
;
664 newinfo
.metric_out
= rte
->metric
; /* XXX */
665 newinfo
.tag
= ntohs(rte
->tag
); /* XXX */
667 ret
= route_map_apply (ri
->routemap
[RIPNG_FILTER_IN
],
668 (struct prefix
*)&p
, RMAP_RIPNG
, &newinfo
);
670 if (ret
== RMAP_DENYMATCH
)
672 if (IS_RIPNG_DEBUG_PACKET
)
673 zlog_debug ("RIPng %s/%d is filtered by route-map in",
674 inet6_ntoa (p
.prefix
), p
.prefixlen
);
678 /* Get back the object */
679 if (ripng_nexthop
->flag
== RIPNG_NEXTHOP_ADDRESS
) {
680 if (! IPV6_ADDR_SAME(&newinfo
.nexthop
, &ripng_nexthop
->address
) ) {
681 /* the nexthop get changed by the routemap */
682 if (IN6_IS_ADDR_LINKLOCAL(&newinfo
.nexthop
))
683 ripng_nexthop
->address
= newinfo
.nexthop
;
685 ripng_nexthop
->address
= in6addr_any
;
688 if (! IPV6_ADDR_SAME(&newinfo
.nexthop
, &from
->sin6_addr
) ) {
689 /* the nexthop get changed by the routemap */
690 if (IN6_IS_ADDR_LINKLOCAL(&newinfo
.nexthop
)) {
691 ripng_nexthop
->flag
= RIPNG_NEXTHOP_ADDRESS
;
692 ripng_nexthop
->address
= newinfo
.nexthop
;
696 rte
->tag
= htons(newinfo
.tag_out
); /* XXX */
697 rte
->metric
= newinfo
.metric_out
; /* XXX: the routemap uses the metric_out field */
700 /* Once the entry has been validated, update the metric by
701 * adding the cost of the network on wich the message
702 * arrived. If the result is greater than infinity, use infinity
703 * (RFC2453 Sec. 3.9.2)
706 /* Zebra ripngd can handle offset-list in. */
707 ret
= ripng_offset_list_apply_in (&p
, ifp
, &rte
->metric
);
709 /* If offset-list does not modify the metric use interface's
712 rte
->metric
+= ifp
->metric
;
714 if (rte
->metric
> RIPNG_METRIC_INFINITY
)
715 rte
->metric
= RIPNG_METRIC_INFINITY
;
717 /* Set nexthop pointer. */
718 if (ripng_nexthop
->flag
== RIPNG_NEXTHOP_ADDRESS
)
719 nexthop
= &ripng_nexthop
->address
;
721 nexthop
= &from
->sin6_addr
;
723 /* Lookup RIPng routing table. */
724 rp
= route_node_get (ripng
->table
, (struct prefix
*) &p
);
730 /* Redistributed route check. */
731 if (rinfo
->type
!= ZEBRA_ROUTE_RIPNG
732 && rinfo
->metric
!= RIPNG_METRIC_INFINITY
)
735 /* Local static route. */
736 if (rinfo
->type
== ZEBRA_ROUTE_RIPNG
737 && ((rinfo
->sub_type
== RIPNG_ROUTE_STATIC
) ||
738 (rinfo
->sub_type
== RIPNG_ROUTE_DEFAULT
))
739 && rinfo
->metric
!= RIPNG_METRIC_INFINITY
)
743 if (rp
->info
== NULL
)
745 /* Now, check to see whether there is already an explicit route
746 for the destination prefix. If there is no such route, add
747 this route to the routing table, unless the metric is
748 infinity (there is no point in adding a route which
750 if (rte
->metric
!= RIPNG_METRIC_INFINITY
)
752 rinfo
= ripng_info_new ();
754 /* - Setting the destination prefix and length to those in
759 /* - Setting the metric to the newly calculated metric (as
761 rinfo
->metric
= rte
->metric
;
762 rinfo
->tag
= ntohs (rte
->tag
);
764 /* - Set the next hop address to be the address of the router
765 from which the datagram came or the next hop address
766 specified by a next hop RTE. */
767 IPV6_ADDR_COPY (&rinfo
->nexthop
, nexthop
);
768 IPV6_ADDR_COPY (&rinfo
->from
, &from
->sin6_addr
);
769 rinfo
->ifindex
= ifp
->ifindex
;
771 /* - Initialize the timeout for the route. If the
772 garbage-collection timer is running for this route, stop it. */
773 ripng_timeout_update (rinfo
);
775 /* - Set the route change flag. */
776 rinfo
->flags
|= RIPNG_RTF_CHANGED
;
778 /* - Signal the output process to trigger an update (see section
780 ripng_event (RIPNG_TRIGGERED_UPDATE
, 0);
782 /* Finally, route goes into the kernel. */
783 rinfo
->type
= ZEBRA_ROUTE_RIPNG
;
784 rinfo
->sub_type
= RIPNG_ROUTE_RTE
;
786 ripng_zebra_ipv6_add (&p
, &rinfo
->nexthop
, rinfo
->ifindex
,
788 rinfo
->flags
|= RIPNG_RTF_FIB
;
790 /* Aggregate check. */
791 ripng_aggregate_increment (rp
, rinfo
);
798 /* If there is an existing route, compare the next hop address
799 to the address of the router from which the datagram came.
800 If this datagram is from the same router as the existing
801 route, reinitialize the timeout. */
802 same
= (IN6_ARE_ADDR_EQUAL (&rinfo
->from
, &from
->sin6_addr
)
803 && (rinfo
->ifindex
== ifp
->ifindex
));
806 ripng_timeout_update (rinfo
);
808 /* Next, compare the metrics. If the datagram is from the same
809 router as the existing route, and the new metric is different
810 than the old one; or, if the new metric is lower than the old
811 one; do the following actions: */
812 if ((same
&& rinfo
->metric
!= rte
->metric
) ||
813 rte
->metric
< rinfo
->metric
)
815 /* - Adopt the route from the datagram. That is, put the
816 new metric in, and adjust the next hop address (if
818 oldmetric
= rinfo
->metric
;
819 rinfo
->metric
= rte
->metric
;
820 rinfo
->tag
= ntohs (rte
->tag
);
821 IPV6_ADDR_COPY (&rinfo
->from
, &from
->sin6_addr
);
822 rinfo
->ifindex
= ifp
->ifindex
;
824 /* Should a new route to this network be established
825 while the garbage-collection timer is running, the
826 new route will replace the one that is about to be
827 deleted. In this case the garbage-collection timer
830 if (oldmetric
== RIPNG_METRIC_INFINITY
&&
831 rinfo
->metric
< RIPNG_METRIC_INFINITY
)
833 rinfo
->type
= ZEBRA_ROUTE_RIPNG
;
834 rinfo
->sub_type
= RIPNG_ROUTE_RTE
;
836 RIPNG_TIMER_OFF (rinfo
->t_garbage_collect
);
838 if (! IPV6_ADDR_SAME (&rinfo
->nexthop
, nexthop
))
839 IPV6_ADDR_COPY (&rinfo
->nexthop
, nexthop
);
841 ripng_zebra_ipv6_add (&p
, nexthop
, ifp
->ifindex
, rinfo
->metric
);
842 rinfo
->flags
|= RIPNG_RTF_FIB
;
844 /* The aggregation counter needs to be updated because
845 the prefixes, which are into the gc, have been
846 removed from the aggregator (see ripng_timout). */
847 ripng_aggregate_increment (rp
, rinfo
);
850 /* Update nexthop and/or metric value. */
851 if (oldmetric
!= RIPNG_METRIC_INFINITY
)
853 ripng_zebra_ipv6_delete (&p
, &rinfo
->nexthop
, rinfo
->ifindex
);
854 ripng_zebra_ipv6_add (&p
, nexthop
, ifp
->ifindex
, rinfo
->metric
);
855 rinfo
->flags
|= RIPNG_RTF_FIB
;
857 if (! IPV6_ADDR_SAME (&rinfo
->nexthop
, nexthop
))
858 IPV6_ADDR_COPY (&rinfo
->nexthop
, nexthop
);
861 /* - Set the route change flag and signal the output process
862 to trigger an update. */
863 rinfo
->flags
|= RIPNG_RTF_CHANGED
;
864 ripng_event (RIPNG_TRIGGERED_UPDATE
, 0);
866 /* - If the new metric is infinity, start the deletion
867 process (described above); */
868 if (rinfo
->metric
== RIPNG_METRIC_INFINITY
)
870 /* If the new metric is infinity, the deletion process
871 begins for the route, which is no longer used for
872 routing packets. Note that the deletion process is
873 started only when the metric is first set to
874 infinity. If the metric was already infinity, then a
875 new deletion process is not started. */
876 if (oldmetric
!= RIPNG_METRIC_INFINITY
)
878 /* - The garbage-collection timer is set for 120 seconds. */
879 RIPNG_TIMER_ON (rinfo
->t_garbage_collect
,
880 ripng_garbage_collect
, ripng
->garbage_time
);
881 RIPNG_TIMER_OFF (rinfo
->t_timeout
);
883 /* - The metric for the route is set to 16
884 (infinity). This causes the route to be removed
886 ripng_zebra_ipv6_delete (&p
, &rinfo
->nexthop
, rinfo
->ifindex
);
887 rinfo
->flags
&= ~RIPNG_RTF_FIB
;
889 /* Aggregate count decrement. */
890 ripng_aggregate_decrement (rp
, rinfo
);
892 /* - The route change flag is to indicate that this
893 entry has been changed. */
894 /* - The output process is signalled to trigger a
896 ; /* Above processes are already done previously. */
901 /* otherwise, re-initialize the timeout. */
902 ripng_timeout_update (rinfo
);
905 /* Unlock tempolary lock of the route. */
906 route_unlock_node (rp
);
910 /* Add redistributed route to RIPng table. */
912 ripng_redistribute_add (int type
, int sub_type
, struct prefix_ipv6
*p
,
913 unsigned int ifindex
, struct in6_addr
*nexthop
)
915 struct route_node
*rp
;
916 struct ripng_info
*rinfo
;
918 /* Redistribute route */
919 if (IN6_IS_ADDR_LINKLOCAL (&p
->prefix
))
921 if (IN6_IS_ADDR_LOOPBACK (&p
->prefix
))
923 #if defined (MUSICA) || defined (LINUX)
924 /* XXX As long as the RIPng redistribution is applied to all the connected
925 * routes, one needs to filter the ::/96 prefixes.
926 * However it could be a wanted case, it will be removed soon.
928 if ((IN6_IS_ADDR_V4COMPAT(&p
->prefix
)) ||
929 (IN6_IS_ADDR_UNSPECIFIED (&p
->prefix
) && (p
->prefixlen
== 96)))
931 #endif /* MUSICA or LINUX */
933 rp
= route_node_get (ripng
->table
, (struct prefix
*) p
);
938 if (rinfo
->type
== ZEBRA_ROUTE_CONNECT
939 && rinfo
->sub_type
== RIPNG_ROUTE_INTERFACE
940 && rinfo
->metric
!= RIPNG_METRIC_INFINITY
) {
941 route_unlock_node (rp
);
945 /* Manually configured RIPng route check.
946 * They have the precedence on all the other entries.
948 if (rinfo
->type
== ZEBRA_ROUTE_RIPNG
949 && ((rinfo
->sub_type
== RIPNG_ROUTE_STATIC
) ||
950 (rinfo
->sub_type
== RIPNG_ROUTE_DEFAULT
)) ) {
951 if (type
!= ZEBRA_ROUTE_RIPNG
|| ((sub_type
!= RIPNG_ROUTE_STATIC
) &&
952 (sub_type
!= RIPNG_ROUTE_DEFAULT
))) {
953 route_unlock_node (rp
);
958 RIPNG_TIMER_OFF (rinfo
->t_timeout
);
959 RIPNG_TIMER_OFF (rinfo
->t_garbage_collect
);
961 /* Tells the other daemons about the deletion of
964 if (ripng_route_rte (rinfo
))
965 ripng_zebra_ipv6_delete ((struct prefix_ipv6
*)&rp
->p
, &rinfo
->nexthop
,
969 ripng_info_free (rinfo
);
971 route_unlock_node (rp
);
975 rinfo
= ripng_info_new ();
978 rinfo
->sub_type
= sub_type
;
979 rinfo
->ifindex
= ifindex
;
983 if (nexthop
&& IN6_IS_ADDR_LINKLOCAL(nexthop
))
984 rinfo
->nexthop
= *nexthop
;
986 rinfo
->flags
|= RIPNG_RTF_FIB
;
989 /* Aggregate check. */
990 ripng_aggregate_increment (rp
, rinfo
);
992 rinfo
->flags
|= RIPNG_RTF_CHANGED
;
994 if (IS_RIPNG_DEBUG_EVENT
) {
996 zlog_debug ("Redistribute new prefix %s/%d on the interface %s",
997 inet6_ntoa(p
->prefix
), p
->prefixlen
,
998 ifindex2ifname(ifindex
));
1000 zlog_debug ("Redistribute new prefix %s/%d with nexthop %s on the interface %s",
1001 inet6_ntoa(p
->prefix
), p
->prefixlen
, inet6_ntoa(*nexthop
),
1002 ifindex2ifname(ifindex
));
1005 ripng_event (RIPNG_TRIGGERED_UPDATE
, 0);
1008 /* Delete redistributed route to RIPng table. */
1010 ripng_redistribute_delete (int type
, int sub_type
, struct prefix_ipv6
*p
,
1011 unsigned int ifindex
)
1013 struct route_node
*rp
;
1014 struct ripng_info
*rinfo
;
1016 if (IN6_IS_ADDR_LINKLOCAL (&p
->prefix
))
1018 if (IN6_IS_ADDR_LOOPBACK (&p
->prefix
))
1020 #if defined (MUSICA) || defined (LINUX)
1021 /* XXX As long as the RIPng redistribution is applied to all the connected
1022 * routes, one needs to filter the ::/96 prefixes.
1023 * However it could be a wanted case, it will be removed soon.
1025 if ((IN6_IS_ADDR_V4COMPAT(&p
->prefix
)) ||
1026 (IN6_IS_ADDR_UNSPECIFIED (&p
->prefix
) && (p
->prefixlen
== 96)))
1028 #endif /* MUSICA or LINUX */
1030 rp
= route_node_lookup (ripng
->table
, (struct prefix
*) p
);
1037 && rinfo
->type
== type
1038 && rinfo
->sub_type
== sub_type
1039 && rinfo
->ifindex
== ifindex
)
1041 /* Perform poisoned reverse. */
1042 rinfo
->metric
= RIPNG_METRIC_INFINITY
;
1043 RIPNG_TIMER_ON (rinfo
->t_garbage_collect
,
1044 ripng_garbage_collect
, ripng
->garbage_time
);
1045 RIPNG_TIMER_OFF (rinfo
->t_timeout
);
1047 /* Aggregate count decrement. */
1048 ripng_aggregate_decrement (rp
, rinfo
);
1050 rinfo
->flags
|= RIPNG_RTF_CHANGED
;
1052 if (IS_RIPNG_DEBUG_EVENT
)
1053 zlog_debug ("Poisone %s/%d on the interface %s with an infinity metric [delete]",
1054 inet6_ntoa(p
->prefix
), p
->prefixlen
,
1055 ifindex2ifname(ifindex
));
1057 ripng_event (RIPNG_TRIGGERED_UPDATE
, 0);
1062 /* Withdraw redistributed route. */
1064 ripng_redistribute_withdraw (int type
)
1066 struct route_node
*rp
;
1067 struct ripng_info
*rinfo
;
1072 for (rp
= route_top (ripng
->table
); rp
; rp
= route_next (rp
))
1073 if ((rinfo
= rp
->info
) != NULL
)
1075 if ((rinfo
->type
== type
)
1076 && (rinfo
->sub_type
!= RIPNG_ROUTE_INTERFACE
))
1078 /* Perform poisoned reverse. */
1079 rinfo
->metric
= RIPNG_METRIC_INFINITY
;
1080 RIPNG_TIMER_ON (rinfo
->t_garbage_collect
,
1081 ripng_garbage_collect
, ripng
->garbage_time
);
1082 RIPNG_TIMER_OFF (rinfo
->t_timeout
);
1084 /* Aggregate count decrement. */
1085 ripng_aggregate_decrement (rp
, rinfo
);
1087 rinfo
->flags
|= RIPNG_RTF_CHANGED
;
1089 if (IS_RIPNG_DEBUG_EVENT
) {
1090 struct prefix_ipv6
*p
= (struct prefix_ipv6
*) &rp
->p
;
1092 zlog_debug ("Poisone %s/%d on the interface %s [withdraw]",
1093 inet6_ntoa(p
->prefix
), p
->prefixlen
,
1094 ifindex2ifname(rinfo
->ifindex
));
1097 ripng_event (RIPNG_TRIGGERED_UPDATE
, 0);
1102 /* RIP routing information. */
1104 ripng_response_process (struct ripng_packet
*packet
, int size
,
1105 struct sockaddr_in6
*from
, struct interface
*ifp
,
1110 struct ripng_nexthop nexthop
;
1112 /* RFC2080 2.4.2 Response Messages:
1113 The Response must be ignored if it is not from the RIPng port. */
1114 if (ntohs (from
->sin6_port
) != RIPNG_PORT_DEFAULT
)
1116 zlog_warn ("RIPng packet comes from non RIPng port %d from %s",
1117 ntohs (from
->sin6_port
), inet6_ntoa (from
->sin6_addr
));
1118 ripng_peer_bad_packet (from
);
1122 /* The datagram's IPv6 source address should be checked to see
1123 whether the datagram is from a valid neighbor; the source of the
1124 datagram must be a link-local address. */
1125 if (! IN6_IS_ADDR_LINKLOCAL(&from
->sin6_addr
))
1127 zlog_warn ("RIPng packet comes from non link local address %s",
1128 inet6_ntoa (from
->sin6_addr
));
1129 ripng_peer_bad_packet (from
);
1133 /* It is also worth checking to see whether the response is from one
1134 of the router's own addresses. Interfaces on broadcast networks
1135 may receive copies of their own multicasts immediately. If a
1136 router processes its own output as new input, confusion is likely,
1137 and such datagrams must be ignored. */
1138 if (ripng_lladdr_check (ifp
, &from
->sin6_addr
))
1140 zlog_warn ("RIPng packet comes from my own link local address %s",
1141 inet6_ntoa (from
->sin6_addr
));
1142 ripng_peer_bad_packet (from
);
1146 /* As an additional check, periodic advertisements must have their
1147 hop counts set to 255, and inbound, multicast packets sent from the
1148 RIPng port (i.e. periodic advertisement or triggered update
1149 packets) must be examined to ensure that the hop count is 255. */
1150 if (hoplimit
>= 0 && hoplimit
!= 255)
1152 zlog_warn ("RIPng packet comes with non 255 hop count %d from %s",
1153 hoplimit
, inet6_ntoa (from
->sin6_addr
));
1154 ripng_peer_bad_packet (from
);
1158 /* Update RIPng peer. */
1159 ripng_peer_update (from
, packet
->version
);
1161 /* Reset nexthop. */
1162 memset (&nexthop
, 0, sizeof (struct ripng_nexthop
));
1163 nexthop
.flag
= RIPNG_NEXTHOP_UNSPEC
;
1165 /* Set RTE pointer. */
1168 for (lim
= ((caddr_t
) packet
) + size
; (caddr_t
) rte
< lim
; rte
++)
1170 /* First of all, we have to check this RTE is next hop RTE or
1171 not. Next hop RTE is completely different with normal RTE so
1172 we need special treatment. */
1173 if (rte
->metric
== RIPNG_METRIC_NEXTHOP
)
1175 ripng_nexthop_rte (rte
, from
, &nexthop
);
1179 /* RTE information validation. */
1181 /* - is the destination prefix valid (e.g., not a multicast
1182 prefix and not a link-local address) A link-local address
1183 should never be present in an RTE. */
1184 if (IN6_IS_ADDR_MULTICAST (&rte
->addr
))
1186 zlog_warn ("Destination prefix is a multicast address %s/%d [%d]",
1187 inet6_ntoa (rte
->addr
), rte
->prefixlen
, rte
->metric
);
1188 ripng_peer_bad_route (from
);
1191 if (IN6_IS_ADDR_LINKLOCAL (&rte
->addr
))
1193 zlog_warn ("Destination prefix is a link-local address %s/%d [%d]",
1194 inet6_ntoa (rte
->addr
), rte
->prefixlen
, rte
->metric
);
1195 ripng_peer_bad_route (from
);
1198 if (IN6_IS_ADDR_LOOPBACK (&rte
->addr
))
1200 zlog_warn ("Destination prefix is a loopback address %s/%d [%d]",
1201 inet6_ntoa (rte
->addr
), rte
->prefixlen
, rte
->metric
);
1202 ripng_peer_bad_route (from
);
1206 /* - is the prefix length valid (i.e., between 0 and 128,
1208 if (rte
->prefixlen
> 128)
1210 zlog_warn ("Invalid prefix length %s/%d from %s%%%s",
1211 inet6_ntoa (rte
->addr
), rte
->prefixlen
,
1212 inet6_ntoa (from
->sin6_addr
), ifp
->name
);
1213 ripng_peer_bad_route (from
);
1217 /* - is the metric valid (i.e., between 1 and 16, inclusive) */
1218 if (! (rte
->metric
>= 1 && rte
->metric
<= 16))
1220 zlog_warn ("Invalid metric %d from %s%%%s", rte
->metric
,
1221 inet6_ntoa (from
->sin6_addr
), ifp
->name
);
1222 ripng_peer_bad_route (from
);
1226 /* Vincent: XXX Should we compute the direclty reachable nexthop
1227 * for our RIPng network ?
1230 /* Routing table updates. */
1231 ripng_route_process (rte
, from
, &nexthop
, ifp
);
1235 /* Response to request message. */
1237 ripng_request_process (struct ripng_packet
*packet
,int size
,
1238 struct sockaddr_in6
*from
, struct interface
*ifp
)
1242 struct prefix_ipv6 p
;
1243 struct route_node
*rp
;
1244 struct ripng_info
*rinfo
;
1245 struct ripng_interface
*ri
;
1247 /* Does not reponse to the requests on the loopback interfaces */
1248 if (if_is_loopback (ifp
))
1251 /* Check RIPng process is enabled on this interface. */
1256 /* When passive interface is specified, suppress responses */
1260 /* RIPng peer update. */
1261 ripng_peer_update (from
, packet
->version
);
1263 lim
= ((caddr_t
) packet
) + size
;
1266 /* The Request is processed entry by entry. If there are no
1267 entries, no response is given. */
1268 if (lim
== (caddr_t
) rte
)
1271 /* There is one special case. If there is exactly one entry in the
1272 request, and it has a destination prefix of zero, a prefix length
1273 of zero, and a metric of infinity (i.e., 16), then this is a
1274 request to send the entire routing table. In that case, a call
1275 is made to the output process to send the routing table to the
1276 requesting address/port. */
1277 if (lim
== ((caddr_t
) (rte
+ 1)) &&
1278 IN6_IS_ADDR_UNSPECIFIED (&rte
->addr
) &&
1279 rte
->prefixlen
== 0 &&
1280 rte
->metric
== RIPNG_METRIC_INFINITY
)
1282 /* All route with split horizon */
1283 ripng_output_process (ifp
, from
, ripng_all_route
);
1287 /* Except for this special case, processing is quite simple.
1288 Examine the list of RTEs in the Request one by one. For each
1289 entry, look up the destination in the router's routing
1290 database and, if there is a route, put that route's metric in
1291 the metric field of the RTE. If there is no explicit route
1292 to the specified destination, put infinity in the metric
1293 field. Once all the entries have been filled in, change the
1294 command from Request to Response and send the datagram back
1295 to the requestor. */
1296 memset (&p
, 0, sizeof (struct prefix_ipv6
));
1297 p
.family
= AF_INET6
;
1299 for (; ((caddr_t
) rte
) < lim
; rte
++)
1301 p
.prefix
= rte
->addr
;
1302 p
.prefixlen
= rte
->prefixlen
;
1303 apply_mask_ipv6 (&p
);
1305 rp
= route_node_lookup (ripng
->table
, (struct prefix
*) &p
);
1310 rte
->metric
= rinfo
->metric
;
1311 route_unlock_node (rp
);
1314 rte
->metric
= RIPNG_METRIC_INFINITY
;
1316 packet
->command
= RIPNG_RESPONSE
;
1318 ripng_send_packet ((caddr_t
) packet
, size
, from
, ifp
);
1322 /* First entry point of reading RIPng packet. */
1324 ripng_read (struct thread
*thread
)
1328 struct sockaddr_in6 from
;
1329 struct ripng_packet
*packet
;
1330 unsigned int ifindex
;
1331 struct interface
*ifp
;
1334 /* Check ripng is active and alive. */
1335 assert (ripng
!= NULL
);
1336 assert (ripng
->sock
>= 0);
1338 /* Fetch thread data and set read pointer to empty for event
1339 managing. `sock' sould be same as ripng->sock. */
1340 sock
= THREAD_FD (thread
);
1341 ripng
->t_read
= NULL
;
1343 /* Add myself to the next event. */
1344 ripng_event (RIPNG_READ
, sock
);
1346 /* Read RIPng packet. */
1347 len
= ripng_recv_packet (sock
, STREAM_DATA (ripng
->ibuf
),
1348 STREAM_SIZE (ripng
->ibuf
), &from
, &ifindex
,
1352 zlog_warn ("RIPng recvfrom failed: %s.", safe_strerror (errno
));
1356 /* Check RTE boundary. RTE size (Packet length - RIPng header size
1357 (4)) must be multiple size of one RTE size (20). */
1358 if (((len
- 4) % 20) != 0)
1360 zlog_warn ("RIPng invalid packet size %d from %s", len
,
1361 inet6_ntoa (from
.sin6_addr
));
1362 ripng_peer_bad_packet (&from
);
1366 packet
= (struct ripng_packet
*) STREAM_DATA (ripng
->ibuf
);
1367 ifp
= if_lookup_by_index (ifindex
);
1369 /* RIPng packet received. */
1370 if (IS_RIPNG_DEBUG_EVENT
)
1371 zlog_debug ("RIPng packet received from %s port %d on %s",
1372 inet6_ntoa (from
.sin6_addr
), ntohs (from
.sin6_port
),
1373 ifp
? ifp
->name
: "unknown");
1375 /* Logging before packet checking. */
1376 if (IS_RIPNG_DEBUG_RECV
)
1377 ripng_packet_dump (packet
, len
, "RECV");
1379 /* Packet comes from unknown interface. */
1382 zlog_warn ("RIPng packet comes from unknown interface %d", ifindex
);
1386 /* Packet version mismatch checking. */
1387 if (packet
->version
!= ripng
->version
)
1389 zlog_warn ("RIPng packet version %d doesn't fit to my version %d",
1390 packet
->version
, ripng
->version
);
1391 ripng_peer_bad_packet (&from
);
1395 /* Process RIPng packet. */
1396 switch (packet
->command
)
1399 ripng_request_process (packet
, len
, &from
, ifp
);
1401 case RIPNG_RESPONSE
:
1402 ripng_response_process (packet
, len
, &from
, ifp
, hoplimit
);
1405 zlog_warn ("Invalid RIPng command %d", packet
->command
);
1406 ripng_peer_bad_packet (&from
);
1412 /* Walk down the RIPng routing table then clear changed flag. */
1414 ripng_clear_changed_flag ()
1416 struct route_node
*rp
;
1417 struct ripng_info
*rinfo
;
1419 for (rp
= route_top (ripng
->table
); rp
; rp
= route_next (rp
))
1420 if ((rinfo
= rp
->info
) != NULL
)
1421 if (rinfo
->flags
& RIPNG_RTF_CHANGED
)
1422 rinfo
->flags
&= ~RIPNG_RTF_CHANGED
;
1425 /* Regular update of RIPng route. Send all routing formation to RIPng
1426 enabled interface. */
1428 ripng_update (struct thread
*t
)
1430 struct listnode
*node
;
1431 struct interface
*ifp
;
1432 struct ripng_interface
*ri
;
1434 /* Clear update timer thread. */
1435 ripng
->t_update
= NULL
;
1437 /* Logging update event. */
1438 if (IS_RIPNG_DEBUG_EVENT
)
1439 zlog_debug ("RIPng update timer expired!");
1441 /* Supply routes to each interface. */
1442 for (ALL_LIST_ELEMENTS_RO (iflist
, node
, ifp
))
1446 if (if_is_loopback (ifp
) || ! if_is_up (ifp
))
1452 /* When passive interface is specified, suppress announce to the
1458 if (ri
->ri_send
== RIPNG_SEND_OFF
)
1460 if (IS_RIPNG_DEBUG_EVENT
)
1461 zlog (NULL
, LOG_DEBUG
,
1462 "[Event] RIPng send to if %d is suppressed by config",
1466 #endif /* RIPNG_ADVANCED */
1468 ripng_output_process (ifp
, NULL
, ripng_all_route
);
1471 /* Triggered updates may be suppressed if a regular update is due by
1472 the time the triggered update would be sent. */
1473 if (ripng
->t_triggered_interval
)
1475 thread_cancel (ripng
->t_triggered_interval
);
1476 ripng
->t_triggered_interval
= NULL
;
1480 /* Reset flush event. */
1481 ripng_event (RIPNG_UPDATE_EVENT
, 0);
1486 /* Triggered update interval timer. */
1488 ripng_triggered_interval (struct thread
*t
)
1490 ripng
->t_triggered_interval
= NULL
;
1495 ripng_triggered_update (t
);
1500 /* Execute triggered update. */
1502 ripng_triggered_update (struct thread
*t
)
1504 struct listnode
*node
;
1505 struct interface
*ifp
;
1506 struct ripng_interface
*ri
;
1509 ripng
->t_triggered_update
= NULL
;
1511 /* Cancel interval timer. */
1512 if (ripng
->t_triggered_interval
)
1514 thread_cancel (ripng
->t_triggered_interval
);
1515 ripng
->t_triggered_interval
= NULL
;
1519 /* Logging triggered update. */
1520 if (IS_RIPNG_DEBUG_EVENT
)
1521 zlog_debug ("RIPng triggered update!");
1523 /* Split Horizon processing is done when generating triggered
1524 updates as well as normal updates (see section 2.6). */
1525 for (ALL_LIST_ELEMENTS_RO (iflist
, node
, ifp
))
1529 if (if_is_loopback (ifp
) || ! if_is_up (ifp
))
1535 /* When passive interface is specified, suppress announce to the
1540 ripng_output_process (ifp
, NULL
, ripng_changed_route
);
1543 /* Once all of the triggered updates have been generated, the route
1544 change flags should be cleared. */
1545 ripng_clear_changed_flag ();
1547 /* After a triggered update is sent, a timer should be set for a
1548 random interval between 1 and 5 seconds. If other changes that
1549 would trigger updates occur before the timer expires, a single
1550 update is triggered when the timer expires. */
1551 interval
= (random () % 5) + 1;
1553 ripng
->t_triggered_interval
=
1554 thread_add_timer (master
, ripng_triggered_interval
, NULL
, interval
);
1559 /* Write routing table entry to the stream and return next index of
1560 the routing table entry in the stream. */
1562 ripng_write_rte (int num
, struct stream
*s
, struct prefix_ipv6
*p
,
1563 struct in6_addr
*nexthop
, u_int16_t tag
, u_char metric
)
1565 /* RIPng packet header. */
1568 stream_putc (s
, RIPNG_RESPONSE
);
1569 stream_putc (s
, RIPNG_V1
);
1573 /* Write routing table entry. */
1575 stream_write (s
, (u_char
*) &p
->prefix
, sizeof (struct in6_addr
));
1577 stream_write (s
, (u_char
*) nexthop
, sizeof (struct in6_addr
));
1578 stream_putw (s
, tag
);
1580 stream_putc (s
, p
->prefixlen
);
1583 stream_putc (s
, metric
);
1588 /* Send RESPONSE message to specified destination. */
1590 ripng_output_process (struct interface
*ifp
, struct sockaddr_in6
*to
,
1594 struct route_node
*rp
;
1595 struct ripng_info
*rinfo
;
1596 struct ripng_interface
*ri
;
1597 struct ripng_aggregate
*aggregate
;
1598 struct prefix_ipv6
*p
;
1599 struct list
* ripng_rte_list
;
1601 if (IS_RIPNG_DEBUG_EVENT
) {
1603 zlog_debug ("RIPng update routes to neighbor %s",
1604 inet6_ntoa(to
->sin6_addr
));
1606 zlog_debug ("RIPng update routes on interface %s", ifp
->name
);
1609 /* Get RIPng interface. */
1612 ripng_rte_list
= ripng_rte_new();
1614 for (rp
= route_top (ripng
->table
); rp
; rp
= route_next (rp
))
1616 if ((rinfo
= rp
->info
) != NULL
&& rinfo
->suppress
== 0)
1618 /* If no route-map are applied, the RTE will be these following
1621 p
= (struct prefix_ipv6
*) &rp
->p
;
1622 rinfo
->metric_out
= rinfo
->metric
;
1623 rinfo
->tag_out
= rinfo
->tag
;
1624 memset(&rinfo
->nexthop_out
, 0, sizeof(rinfo
->nexthop_out
));
1625 /* In order to avoid some local loops,
1626 * if the RIPng route has a nexthop via this interface, keep the nexthop,
1627 * otherwise set it to 0. The nexthop should not be propagated
1628 * beyond the local broadcast/multicast area in order
1629 * to avoid an IGP multi-level recursive look-up.
1631 if (rinfo
->ifindex
== ifp
->ifindex
)
1632 rinfo
->nexthop_out
= rinfo
->nexthop
;
1634 /* Apply output filters. */
1635 ret
= ripng_outgoing_filter (p
, ri
);
1639 /* Changed route only output. */
1640 if (route_type
== ripng_changed_route
&&
1641 (! (rinfo
->flags
& RIPNG_RTF_CHANGED
)))
1644 /* Split horizon. */
1645 if (ri
->split_horizon
== RIPNG_SPLIT_HORIZON
)
1647 /* We perform split horizon for RIPng routes. */
1648 if ((rinfo
->type
== ZEBRA_ROUTE_RIPNG
) &&
1649 rinfo
->ifindex
== ifp
->ifindex
)
1653 /* Preparation for route-map. */
1654 rinfo
->metric_set
= 0;
1657 * and tag_out are already initialized.
1660 /* Interface route-map */
1661 if (ri
->routemap
[RIPNG_FILTER_OUT
])
1665 ret
= route_map_apply (ri
->routemap
[RIPNG_FILTER_OUT
],
1666 (struct prefix
*) p
, RMAP_RIPNG
,
1669 if (ret
== RMAP_DENYMATCH
)
1671 if (IS_RIPNG_DEBUG_PACKET
)
1672 zlog_debug ("RIPng %s/%d is filtered by route-map out",
1673 inet6_ntoa (p
->prefix
), p
->prefixlen
);
1679 /* Redistribute route-map. */
1680 if (ripng
->route_map
[rinfo
->type
].name
)
1684 ret
= route_map_apply (ripng
->route_map
[rinfo
->type
].map
,
1685 (struct prefix
*) p
, RMAP_RIPNG
,
1688 if (ret
== RMAP_DENYMATCH
)
1690 if (IS_RIPNG_DEBUG_PACKET
)
1691 zlog_debug ("RIPng %s/%d is filtered by route-map",
1692 inet6_ntoa (p
->prefix
), p
->prefixlen
);
1697 /* When the route-map does not set metric. */
1698 if (! rinfo
->metric_set
)
1700 /* If the redistribute metric is set. */
1701 if (ripng
->route_map
[rinfo
->type
].metric_config
1702 && rinfo
->metric
!= RIPNG_METRIC_INFINITY
)
1704 rinfo
->metric_out
= ripng
->route_map
[rinfo
->type
].metric
;
1708 /* If the route is not connected or localy generated
1709 one, use default-metric value */
1710 if (rinfo
->type
!= ZEBRA_ROUTE_RIPNG
1711 && rinfo
->type
!= ZEBRA_ROUTE_CONNECT
1712 && rinfo
->metric
!= RIPNG_METRIC_INFINITY
)
1713 rinfo
->metric_out
= ripng
->default_metric
;
1717 /* Apply offset-list */
1718 if (rinfo
->metric_out
!= RIPNG_METRIC_INFINITY
)
1719 ripng_offset_list_apply_out (p
, ifp
, &rinfo
->metric_out
);
1721 if (rinfo
->metric_out
> RIPNG_METRIC_INFINITY
)
1722 rinfo
->metric_out
= RIPNG_METRIC_INFINITY
;
1724 /* Perform split-horizon with poisoned reverse
1727 if (ri
->split_horizon
== RIPNG_SPLIT_HORIZON_POISONED_REVERSE
) {
1728 if ((rinfo
->type
== ZEBRA_ROUTE_RIPNG
) &&
1729 rinfo
->ifindex
== ifp
->ifindex
)
1730 rinfo
->metric_out
= RIPNG_METRIC_INFINITY
;
1733 /* Add RTE to the list */
1734 ripng_rte_add(ripng_rte_list
, p
, rinfo
, NULL
);
1737 /* Process the aggregated RTE entry */
1738 if ((aggregate
= rp
->aggregate
) != NULL
&&
1739 aggregate
->count
> 0 &&
1740 aggregate
->suppress
== 0)
1742 /* If no route-map are applied, the RTE will be these following
1745 p
= (struct prefix_ipv6
*) &rp
->p
;
1746 aggregate
->metric_set
= 0;
1747 aggregate
->metric_out
= aggregate
->metric
;
1748 aggregate
->tag_out
= aggregate
->tag
;
1749 memset(&aggregate
->nexthop_out
, 0, sizeof(aggregate
->nexthop_out
));
1751 /* Apply output filters.*/
1752 ret
= ripng_outgoing_filter (p
, ri
);
1756 /* Interface route-map */
1757 if (ri
->routemap
[RIPNG_FILTER_OUT
])
1760 struct ripng_info newinfo
;
1762 /* let's cast the aggregate structure to ripng_info */
1763 memset (&newinfo
, 0, sizeof (struct ripng_info
));
1764 /* the nexthop is :: */
1765 newinfo
.metric
= aggregate
->metric
;
1766 newinfo
.metric_out
= aggregate
->metric_out
;
1767 newinfo
.tag
= aggregate
->tag
;
1768 newinfo
.tag_out
= aggregate
->tag_out
;
1770 ret
= route_map_apply (ri
->routemap
[RIPNG_FILTER_OUT
],
1771 (struct prefix
*) p
, RMAP_RIPNG
,
1774 if (ret
== RMAP_DENYMATCH
)
1776 if (IS_RIPNG_DEBUG_PACKET
)
1777 zlog_debug ("RIPng %s/%d is filtered by route-map out",
1778 inet6_ntoa (p
->prefix
), p
->prefixlen
);
1782 aggregate
->metric_out
= newinfo
.metric_out
;
1783 aggregate
->tag_out
= newinfo
.tag_out
;
1784 if (IN6_IS_ADDR_LINKLOCAL(&newinfo
.nexthop_out
))
1785 aggregate
->nexthop_out
= newinfo
.nexthop_out
;
1788 /* There is no redistribute routemap for the aggregated RTE */
1790 /* Changed route only output. */
1791 /* XXX, vincent, in order to increase time convergence,
1792 * it should be announced if a child has changed.
1794 if (route_type
== ripng_changed_route
)
1797 /* Apply offset-list */
1798 if (aggregate
->metric_out
!= RIPNG_METRIC_INFINITY
)
1799 ripng_offset_list_apply_out (p
, ifp
, &aggregate
->metric_out
);
1801 if (aggregate
->metric_out
> RIPNG_METRIC_INFINITY
)
1802 aggregate
->metric_out
= RIPNG_METRIC_INFINITY
;
1804 /* Add RTE to the list */
1805 ripng_rte_add(ripng_rte_list
, p
, NULL
, aggregate
);
1810 /* Flush the list */
1811 ripng_rte_send(ripng_rte_list
, ifp
, to
);
1812 ripng_rte_free(ripng_rte_list
);
1815 /* Create new RIPng instance and set it to global variable. */
1819 /* ripng should be NULL. */
1820 assert (ripng
== NULL
);
1822 /* Allocaste RIPng instance. */
1823 ripng
= XMALLOC (MTYPE_RIPNG
, sizeof (struct ripng
));
1824 memset (ripng
, 0, sizeof (struct ripng
));
1826 /* Default version and timer values. */
1827 ripng
->version
= RIPNG_V1
;
1828 ripng
->update_time
= RIPNG_UPDATE_TIMER_DEFAULT
;
1829 ripng
->timeout_time
= RIPNG_TIMEOUT_TIMER_DEFAULT
;
1830 ripng
->garbage_time
= RIPNG_GARBAGE_TIMER_DEFAULT
;
1831 ripng
->default_metric
= RIPNG_DEFAULT_METRIC_DEFAULT
;
1834 ripng
->ibuf
= stream_new (RIPNG_MAX_PACKET_SIZE
* 5);
1835 ripng
->obuf
= stream_new (RIPNG_MAX_PACKET_SIZE
);
1837 /* Initialize RIPng routig table. */
1838 ripng
->table
= route_table_init ();
1839 ripng
->route
= route_table_init ();
1840 ripng
->aggregate
= route_table_init ();
1843 ripng
->sock
= ripng_make_socket ();
1844 if (ripng
->sock
< 0)
1848 ripng_event (RIPNG_READ
, ripng
->sock
);
1849 ripng_event (RIPNG_UPDATE_EVENT
, 1);
1854 /* Send RIPng request to the interface. */
1856 ripng_request (struct interface
*ifp
)
1859 struct ripng_packet ripng_packet
;
1861 /* In default ripd doesn't send RIP_REQUEST to the loopback interface. */
1862 if (if_is_loopback(ifp
))
1865 /* If interface is down, don't send RIP packet. */
1866 if (! if_is_up (ifp
))
1869 if (IS_RIPNG_DEBUG_EVENT
)
1870 zlog_debug ("RIPng send request to %s", ifp
->name
);
1872 memset (&ripng_packet
, 0, sizeof (ripng_packet
));
1873 ripng_packet
.command
= RIPNG_REQUEST
;
1874 ripng_packet
.version
= RIPNG_V1
;
1875 rte
= ripng_packet
.rte
;
1876 rte
->metric
= RIPNG_METRIC_INFINITY
;
1878 return ripng_send_packet ((caddr_t
) &ripng_packet
, sizeof (ripng_packet
),
1884 ripng_update_jitter (int time
)
1886 return ((rand () % (time
+ 1)) - (time
/ 2));
1890 ripng_event (enum ripng_event event
, int sock
)
1898 ripng
->t_read
= thread_add_read (master
, ripng_read
, NULL
, sock
);
1900 case RIPNG_UPDATE_EVENT
:
1901 if (ripng
->t_update
)
1903 thread_cancel (ripng
->t_update
);
1904 ripng
->t_update
= NULL
;
1906 /* Update timer jitter. */
1907 jitter
= ripng_update_jitter (ripng
->update_time
);
1910 thread_add_timer (master
, ripng_update
, NULL
,
1911 sock
? 2 : ripng
->update_time
+ jitter
);
1913 case RIPNG_TRIGGERED_UPDATE
:
1914 if (ripng
->t_triggered_interval
)
1916 else if (! ripng
->t_triggered_update
)
1917 ripng
->t_triggered_update
=
1918 thread_add_event (master
, ripng_triggered_update
, NULL
, 0);
1926 /* Print out routes update time. */
1928 ripng_vty_out_uptime (struct vty
*vty
, struct ripng_info
*rinfo
)
1933 char timebuf
[TIME_BUF
];
1934 struct thread
*thread
;
1936 if ((thread
= rinfo
->t_timeout
) != NULL
)
1938 clock
= thread_timer_remain_second (thread
);
1939 tm
= gmtime (&clock
);
1940 strftime (timebuf
, TIME_BUF
, "%M:%S", tm
);
1941 vty_out (vty
, "%5s", timebuf
);
1943 else if ((thread
= rinfo
->t_garbage_collect
) != NULL
)
1945 clock
= thread_timer_remain_second (thread
);
1946 tm
= gmtime (&clock
);
1947 strftime (timebuf
, TIME_BUF
, "%M:%S", tm
);
1948 vty_out (vty
, "%5s", timebuf
);
1953 ripng_route_subtype_print (struct ripng_info
*rinfo
)
1958 if (rinfo
->suppress
)
1961 switch (rinfo
->sub_type
)
1963 case RIPNG_ROUTE_RTE
:
1966 case RIPNG_ROUTE_STATIC
:
1969 case RIPNG_ROUTE_DEFAULT
:
1972 case RIPNG_ROUTE_REDISTRIBUTE
:
1975 case RIPNG_ROUTE_INTERFACE
:
1986 DEFUN (show_ipv6_ripng
,
1987 show_ipv6_ripng_cmd
,
1991 "Show RIPng routes\n")
1993 struct route_node
*rp
;
1994 struct ripng_info
*rinfo
;
1995 struct ripng_aggregate
*aggregate
;
1996 struct prefix_ipv6
*p
;
2002 /* Header of display. */
2003 vty_out (vty
, "Codes: R - RIPng, C - connected, S - Static, O - OSPF, B - BGP%s"
2005 " (n) - normal, (s) - static, (d) - default, (r) - redistribute,%s"
2006 " (i) - interface, (a/S) - aggregated/Suppressed%s%s"
2007 " Network Next Hop Via Metric Tag Time%s",
2008 VTY_NEWLINE
, VTY_NEWLINE
, VTY_NEWLINE
,
2009 VTY_NEWLINE
, VTY_NEWLINE
, VTY_NEWLINE
);
2011 for (rp
= route_top (ripng
->table
); rp
; rp
= route_next (rp
))
2013 if ((aggregate
= rp
->aggregate
) != NULL
)
2015 p
= (struct prefix_ipv6
*) &rp
->p
;
2018 len
= vty_out (vty
, "R(a) %d/%d %s/%d ",
2019 aggregate
->count
, aggregate
->suppress
,
2020 inet6_ntoa (p
->prefix
), p
->prefixlen
);
2022 len
= vty_out (vty
, "R(a) %s/%d ",
2023 inet6_ntoa (p
->prefix
), p
->prefixlen
);
2025 vty_out (vty
, "%s", VTY_NEWLINE
);
2026 vty_out (vty
, "%*s", 18, " ");
2028 vty_out (vty
, "%*s", 28, " ");
2029 vty_out (vty
, "self %2d %3d%s", aggregate
->metric
,
2034 if ((rinfo
= rp
->info
) != NULL
)
2036 p
= (struct prefix_ipv6
*) &rp
->p
;
2039 len
= vty_out (vty
, "%c(%s) 0/%d %s/%d ",
2040 zebra_route_char(rinfo
->type
),
2041 ripng_route_subtype_print(rinfo
),
2043 inet6_ntoa (p
->prefix
), p
->prefixlen
);
2045 len
= vty_out (vty
, "%c(%s) %s/%d ",
2046 zebra_route_char(rinfo
->type
),
2047 ripng_route_subtype_print(rinfo
),
2048 inet6_ntoa (p
->prefix
), p
->prefixlen
);
2050 vty_out (vty
, "%s", VTY_NEWLINE
);
2051 vty_out (vty
, "%*s", 18, " ");
2052 len
= vty_out (vty
, "%s", inet6_ntoa (rinfo
->nexthop
));
2056 len
= vty_out (vty
, "%*s", len
, " ");
2059 if ((rinfo
->type
== ZEBRA_ROUTE_RIPNG
) &&
2060 (rinfo
->sub_type
== RIPNG_ROUTE_RTE
))
2062 len
= vty_out (vty
, "%s", ifindex2ifname(rinfo
->ifindex
));
2063 } else if (rinfo
->metric
== RIPNG_METRIC_INFINITY
)
2065 len
= vty_out (vty
, "kill");
2067 len
= vty_out (vty
, "self");
2071 vty_out (vty
, "%*s", len
, " ");
2073 vty_out (vty
, " %2d %3d ",
2074 rinfo
->metric
, rinfo
->tag
);
2077 if ((rinfo
->type
== ZEBRA_ROUTE_RIPNG
) &&
2078 (rinfo
->sub_type
== RIPNG_ROUTE_RTE
))
2080 /* RTE from remote RIP routers */
2081 ripng_vty_out_uptime (vty
, rinfo
);
2082 } else if (rinfo
->metric
== RIPNG_METRIC_INFINITY
)
2084 /* poisonous reversed routes (gc) */
2085 ripng_vty_out_uptime (vty
, rinfo
);
2088 vty_out (vty
, "%s", VTY_NEWLINE
);
2095 DEFUN (show_ipv6_ripng_status
,
2096 show_ipv6_ripng_status_cmd
,
2097 "show ipv6 ripng status",
2100 "Show RIPng routes\n"
2101 "IPv6 routing protocol process parameters and statistics\n")
2103 struct listnode
*node
;
2104 struct interface
*ifp
;
2105 int ripng_network_write (struct vty
*, int);
2106 void ripng_redistribute_write (struct vty
*, int);
2111 vty_out (vty
, "Routing Protocol is \"RIPng\"%s", VTY_NEWLINE
);
2112 vty_out (vty
, " Sending updates every %ld seconds with +/-50%%,",
2113 ripng
->update_time
);
2114 vty_out (vty
, " next due in %lu seconds%s",
2115 thread_timer_remain_second (ripng
->t_update
),
2117 vty_out (vty
, " Timeout after %ld seconds,", ripng
->timeout_time
);
2118 vty_out (vty
, " garbage collect after %ld seconds%s", ripng
->garbage_time
,
2121 /* Filtering status show. */
2122 config_show_distribute (vty
);
2124 /* Default metric information. */
2125 vty_out (vty
, " Default redistribution metric is %d%s",
2126 ripng
->default_metric
, VTY_NEWLINE
);
2128 /* Redistribute information. */
2129 vty_out (vty
, " Redistributing:");
2130 ripng_redistribute_write (vty
, 0);
2131 vty_out (vty
, "%s", VTY_NEWLINE
);
2133 vty_out (vty
, " Default version control: send version %d,", ripng
->version
);
2134 vty_out (vty
, " receive version %d %s", ripng
->version
,
2137 vty_out (vty
, " Interface Send Recv%s", VTY_NEWLINE
);
2139 for (ALL_LIST_ELEMENTS_RO (iflist
, node
, ifp
))
2141 struct ripng_interface
*ri
;
2145 if (ri
->enable_network
|| ri
->enable_interface
)
2148 vty_out (vty
, " %-17s%-3d %-3d%s", ifp
->name
,
2155 vty_out (vty
, " Routing for Networks:%s", VTY_NEWLINE
);
2156 ripng_network_write (vty
, 0);
2158 vty_out (vty
, " Routing Information Sources:%s", VTY_NEWLINE
);
2159 vty_out (vty
, " Gateway BadPackets BadRoutes Distance Last Update%s", VTY_NEWLINE
);
2160 ripng_peer_display (vty
);
2165 DEFUN (router_ripng
,
2168 "Enable a routing process\n"
2169 "Make RIPng instance command\n")
2173 vty
->node
= RIPNG_NODE
;
2177 ret
= ripng_create ();
2179 /* Notice to user we couldn't create RIPng. */
2182 zlog_warn ("can't create RIPng");
2190 DEFUN (no_router_ripng
,
2191 no_router_ripng_cmd
,
2194 "Enable a routing process\n"
2195 "Make RIPng instance command\n")
2205 "Static route setup\n"
2206 "Set static RIPng route announcement\n")
2209 struct prefix_ipv6 p
;
2210 struct route_node
*rp
;
2212 ret
= str2prefix_ipv6 (argv
[0], (struct prefix_ipv6
*)&p
);
2215 vty_out (vty
, "Malformed address%s", VTY_NEWLINE
);
2218 apply_mask_ipv6 (&p
);
2220 rp
= route_node_get (ripng
->route
, (struct prefix
*) &p
);
2223 vty_out (vty
, "There is already same static route.%s", VTY_NEWLINE
);
2224 route_unlock_node (rp
);
2227 rp
->info
= (void *)1;
2229 ripng_redistribute_add (ZEBRA_ROUTE_RIPNG
, RIPNG_ROUTE_STATIC
, &p
, 0, NULL
);
2234 DEFUN (no_ripng_route
,
2236 "no route IPV6ADDR",
2238 "Static route setup\n"
2239 "Delete static RIPng route announcement\n")
2242 struct prefix_ipv6 p
;
2243 struct route_node
*rp
;
2245 ret
= str2prefix_ipv6 (argv
[0], (struct prefix_ipv6
*)&p
);
2248 vty_out (vty
, "Malformed address%s", VTY_NEWLINE
);
2251 apply_mask_ipv6 (&p
);
2253 rp
= route_node_lookup (ripng
->route
, (struct prefix
*) &p
);
2256 vty_out (vty
, "Can't find static route.%s", VTY_NEWLINE
);
2260 ripng_redistribute_delete (ZEBRA_ROUTE_RIPNG
, RIPNG_ROUTE_STATIC
, &p
, 0);
2261 route_unlock_node (rp
);
2264 route_unlock_node (rp
);
2269 DEFUN (ripng_aggregate_address
,
2270 ripng_aggregate_address_cmd
,
2271 "aggregate-address X:X::X:X/M",
2272 "Set aggregate RIPng route announcement\n"
2273 "Aggregate network\n")
2277 struct route_node
*node
;
2279 ret
= str2prefix_ipv6 (argv
[0], (struct prefix_ipv6
*)&p
);
2282 vty_out (vty
, "Malformed address%s", VTY_NEWLINE
);
2286 /* Check aggregate alredy exist or not. */
2287 node
= route_node_get (ripng
->aggregate
, &p
);
2290 vty_out (vty
, "There is already same aggregate route.%s", VTY_NEWLINE
);
2291 route_unlock_node (node
);
2294 node
->info
= (void *)1;
2296 ripng_aggregate_add (&p
);
2301 DEFUN (no_ripng_aggregate_address
,
2302 no_ripng_aggregate_address_cmd
,
2303 "no aggregate-address X:X::X:X/M",
2305 "Delete aggregate RIPng route announcement\n"
2306 "Aggregate network")
2310 struct route_node
*rn
;
2312 ret
= str2prefix_ipv6 (argv
[0], (struct prefix_ipv6
*) &p
);
2315 vty_out (vty
, "Malformed address%s", VTY_NEWLINE
);
2319 rn
= route_node_lookup (ripng
->aggregate
, &p
);
2322 vty_out (vty
, "Can't find aggregate route.%s", VTY_NEWLINE
);
2325 route_unlock_node (rn
);
2327 route_unlock_node (rn
);
2329 ripng_aggregate_delete (&p
);
2334 DEFUN (ripng_default_metric
,
2335 ripng_default_metric_cmd
,
2336 "default-metric <1-16>",
2337 "Set a metric of redistribute routes\n"
2342 ripng
->default_metric
= atoi (argv
[0]);
2347 DEFUN (no_ripng_default_metric
,
2348 no_ripng_default_metric_cmd
,
2349 "no default-metric",
2351 "Set a metric of redistribute routes\n"
2356 ripng
->default_metric
= RIPNG_DEFAULT_METRIC_DEFAULT
;
2361 ALIAS (no_ripng_default_metric
,
2362 no_ripng_default_metric_val_cmd
,
2363 "no default-metric <1-16>",
2365 "Set a metric of redistribute routes\n"
2369 /* RIPng update timer setup. */
2370 DEFUN (ripng_update_timer
,
2371 ripng_update_timer_cmd
,
2372 "update-timer SECOND",
2373 "Set RIPng update timer in seconds\n"
2376 unsigned long update
;
2377 char *endptr
= NULL
;
2379 update
= strtoul (argv
[0], &endptr
, 10);
2380 if (update
== ULONG_MAX
|| *endptr
!= '\0')
2382 vty_out (vty
, "update timer value error%s", VTY_NEWLINE
);
2386 ripng
->update_time
= update
;
2388 ripng_event (RIPNG_UPDATE_EVENT
, 0);
2392 DEFUN (no_ripng_update_timer
,
2393 no_ripng_update_timer_cmd
,
2394 "no update-timer SECOND",
2396 "Unset RIPng update timer in seconds\n"
2399 ripng
->update_time
= RIPNG_UPDATE_TIMER_DEFAULT
;
2400 ripng_event (RIPNG_UPDATE_EVENT
, 0);
2404 /* RIPng timeout timer setup. */
2405 DEFUN (ripng_timeout_timer
,
2406 ripng_timeout_timer_cmd
,
2407 "timeout-timer SECOND",
2408 "Set RIPng timeout timer in seconds\n"
2411 unsigned long timeout
;
2412 char *endptr
= NULL
;
2414 timeout
= strtoul (argv
[0], &endptr
, 10);
2415 if (timeout
== ULONG_MAX
|| *endptr
!= '\0')
2417 vty_out (vty
, "timeout timer value error%s", VTY_NEWLINE
);
2421 ripng
->timeout_time
= timeout
;
2426 DEFUN (no_ripng_timeout_timer
,
2427 no_ripng_timeout_timer_cmd
,
2428 "no timeout-timer SECOND",
2430 "Unset RIPng timeout timer in seconds\n"
2433 ripng
->timeout_time
= RIPNG_TIMEOUT_TIMER_DEFAULT
;
2437 /* RIPng garbage timer setup. */
2438 DEFUN (ripng_garbage_timer
,
2439 ripng_garbage_timer_cmd
,
2440 "garbage-timer SECOND",
2441 "Set RIPng garbage timer in seconds\n"
2444 unsigned long garbage
;
2445 char *endptr
= NULL
;
2447 garbage
= strtoul (argv
[0], &endptr
, 10);
2448 if (garbage
== ULONG_MAX
|| *endptr
!= '\0')
2450 vty_out (vty
, "garbage timer value error%s", VTY_NEWLINE
);
2454 ripng
->garbage_time
= garbage
;
2459 DEFUN (no_ripng_garbage_timer
,
2460 no_ripng_garbage_timer_cmd
,
2461 "no garbage-timer SECOND",
2463 "Unset RIPng garbage timer in seconds\n"
2466 ripng
->garbage_time
= RIPNG_GARBAGE_TIMER_DEFAULT
;
2471 DEFUN (ripng_timers
,
2473 "timers basic <0-65535> <0-65535> <0-65535>",
2474 "RIPng timers setup\n"
2476 "Routing table update timer value in second. Default is 30.\n"
2477 "Routing information timeout timer. Default is 180.\n"
2478 "Garbage collection timer. Default is 120.\n")
2480 unsigned long update
;
2481 unsigned long timeout
;
2482 unsigned long garbage
;
2483 char *endptr
= NULL
;
2485 update
= strtoul (argv
[0], &endptr
, 10);
2486 if (update
== ULONG_MAX
|| *endptr
!= '\0')
2488 vty_out (vty
, "update timer value error%s", VTY_NEWLINE
);
2492 timeout
= strtoul (argv
[1], &endptr
, 10);
2493 if (timeout
== ULONG_MAX
|| *endptr
!= '\0')
2495 vty_out (vty
, "timeout timer value error%s", VTY_NEWLINE
);
2499 garbage
= strtoul (argv
[2], &endptr
, 10);
2500 if (garbage
== ULONG_MAX
|| *endptr
!= '\0')
2502 vty_out (vty
, "garbage timer value error%s", VTY_NEWLINE
);
2506 /* Set each timer value. */
2507 ripng
->update_time
= update
;
2508 ripng
->timeout_time
= timeout
;
2509 ripng
->garbage_time
= garbage
;
2511 /* Reset update timer thread. */
2512 ripng_event (RIPNG_UPDATE_EVENT
, 0);
2517 DEFUN (no_ripng_timers
,
2518 no_ripng_timers_cmd
,
2521 "RIPng timers setup\n"
2524 /* Set each timer value to the default. */
2525 ripng
->update_time
= RIPNG_UPDATE_TIMER_DEFAULT
;
2526 ripng
->timeout_time
= RIPNG_TIMEOUT_TIMER_DEFAULT
;
2527 ripng
->garbage_time
= RIPNG_GARBAGE_TIMER_DEFAULT
;
2529 /* Reset update timer thread. */
2530 ripng_event (RIPNG_UPDATE_EVENT
, 0);
2535 ALIAS (no_ripng_timers
,
2536 no_ripng_timers_val_cmd
,
2537 "no timers basic <0-65535> <0-65535> <0-65535>",
2539 "RIPng timers setup\n"
2541 "Routing table update timer value in second. Default is 30.\n"
2542 "Routing information timeout timer. Default is 180.\n"
2543 "Garbage collection timer. Default is 120.\n")
2545 DEFUN (show_ipv6_protocols
, show_ipv6_protocols_cmd
,
2546 "show ipv6 protocols",
2549 "Routing protocol information")
2554 vty_out (vty
, "Routing Protocol is \"ripng\"%s", VTY_NEWLINE
);
2556 vty_out (vty
, "Sending updates every %ld seconds, next due in %d seconds%s",
2557 ripng
->update_time
, 0,
2560 vty_out (vty
, "Timerout after %ld seconds, garbage correct %ld%s",
2561 ripng
->timeout_time
,
2562 ripng
->garbage_time
,
2565 vty_out (vty
, "Outgoing update filter list for all interfaces is not set");
2566 vty_out (vty
, "Incoming update filter list for all interfaces is not set");
2571 /* Please be carefull to use this command. */
2572 DEFUN (ripng_default_information_originate
,
2573 ripng_default_information_originate_cmd
,
2574 "default-information originate",
2575 "Default route information\n"
2576 "Distribute default route\n")
2578 struct prefix_ipv6 p
;
2580 if (! ripng
->default_information
) {
2581 ripng
->default_information
= 1;
2583 str2prefix_ipv6 ("::/0", &p
);
2584 ripng_redistribute_add (ZEBRA_ROUTE_RIPNG
, RIPNG_ROUTE_DEFAULT
, &p
, 0, NULL
);
2590 DEFUN (no_ripng_default_information_originate
,
2591 no_ripng_default_information_originate_cmd
,
2592 "no default-information originate",
2594 "Default route information\n"
2595 "Distribute default route\n")
2597 struct prefix_ipv6 p
;
2599 if (ripng
->default_information
) {
2600 ripng
->default_information
= 0;
2602 str2prefix_ipv6 ("::/0", &p
);
2603 ripng_redistribute_delete (ZEBRA_ROUTE_RIPNG
, RIPNG_ROUTE_DEFAULT
, &p
, 0);
2609 /* RIPng configuration write function. */
2611 ripng_config_write (struct vty
*vty
)
2613 int ripng_network_write (struct vty
*, int);
2614 void ripng_redistribute_write (struct vty
*, int);
2616 struct route_node
*rp
;
2622 vty_out (vty
, "router ripng%s", VTY_NEWLINE
);
2624 if (ripng
->default_information
)
2625 vty_out (vty
, " default-information originate%s", VTY_NEWLINE
);
2627 ripng_network_write (vty
, 1);
2629 /* RIPng default metric configuration */
2630 if (ripng
->default_metric
!= RIPNG_DEFAULT_METRIC_DEFAULT
)
2631 vty_out (vty
, " default-metric %d%s",
2632 ripng
->default_metric
, VTY_NEWLINE
);
2634 ripng_redistribute_write (vty
, 1);
2636 /* RIP offset-list configuration. */
2637 config_write_ripng_offset_list (vty
);
2639 /* RIPng aggregate routes. */
2640 for (rp
= route_top (ripng
->aggregate
); rp
; rp
= route_next (rp
))
2641 if (rp
->info
!= NULL
)
2642 vty_out (vty
, " aggregate-address %s/%d%s",
2643 inet6_ntoa (rp
->p
.u
.prefix6
),
2648 /* RIPng static routes. */
2649 for (rp
= route_top (ripng
->route
); rp
; rp
= route_next (rp
))
2650 if (rp
->info
!= NULL
)
2651 vty_out (vty
, " route %s/%d%s", inet6_ntoa (rp
->p
.u
.prefix6
),
2655 /* RIPng timers configuration. */
2656 if (ripng
->update_time
!= RIPNG_UPDATE_TIMER_DEFAULT
||
2657 ripng
->timeout_time
!= RIPNG_TIMEOUT_TIMER_DEFAULT
||
2658 ripng
->garbage_time
!= RIPNG_GARBAGE_TIMER_DEFAULT
)
2660 vty_out (vty
, " timers basic %ld %ld %ld%s",
2662 ripng
->timeout_time
,
2663 ripng
->garbage_time
,
2667 if (ripng
->update_time
!= RIPNG_UPDATE_TIMER_DEFAULT
)
2668 vty_out (vty
, " update-timer %d%s", ripng
->update_time
,
2670 if (ripng
->timeout_time
!= RIPNG_TIMEOUT_TIMER_DEFAULT
)
2671 vty_out (vty
, " timeout-timer %d%s", ripng
->timeout_time
,
2673 if (ripng
->garbage_time
!= RIPNG_GARBAGE_TIMER_DEFAULT
)
2674 vty_out (vty
, " garbage-timer %d%s", ripng
->garbage_time
,
2678 write
+= config_write_distribute (vty
);
2680 write
+= config_write_if_rmap (vty
);
2687 /* RIPng node structure. */
2688 struct cmd_node cmd_ripng_node
=
2691 "%s(config-router)# ",
2696 ripng_distribute_update (struct distribute
*dist
)
2698 struct interface
*ifp
;
2699 struct ripng_interface
*ri
;
2700 struct access_list
*alist
;
2701 struct prefix_list
*plist
;
2706 ifp
= if_lookup_by_name (dist
->ifname
);
2712 if (dist
->list
[DISTRIBUTE_IN
])
2714 alist
= access_list_lookup (AFI_IP6
, dist
->list
[DISTRIBUTE_IN
]);
2716 ri
->list
[RIPNG_FILTER_IN
] = alist
;
2718 ri
->list
[RIPNG_FILTER_IN
] = NULL
;
2721 ri
->list
[RIPNG_FILTER_IN
] = NULL
;
2723 if (dist
->list
[DISTRIBUTE_OUT
])
2725 alist
= access_list_lookup (AFI_IP6
, dist
->list
[DISTRIBUTE_OUT
]);
2727 ri
->list
[RIPNG_FILTER_OUT
] = alist
;
2729 ri
->list
[RIPNG_FILTER_OUT
] = NULL
;
2732 ri
->list
[RIPNG_FILTER_OUT
] = NULL
;
2734 if (dist
->prefix
[DISTRIBUTE_IN
])
2736 plist
= prefix_list_lookup (AFI_IP6
, dist
->prefix
[DISTRIBUTE_IN
]);
2738 ri
->prefix
[RIPNG_FILTER_IN
] = plist
;
2740 ri
->prefix
[RIPNG_FILTER_IN
] = NULL
;
2743 ri
->prefix
[RIPNG_FILTER_IN
] = NULL
;
2745 if (dist
->prefix
[DISTRIBUTE_OUT
])
2747 plist
= prefix_list_lookup (AFI_IP6
, dist
->prefix
[DISTRIBUTE_OUT
]);
2749 ri
->prefix
[RIPNG_FILTER_OUT
] = plist
;
2751 ri
->prefix
[RIPNG_FILTER_OUT
] = NULL
;
2754 ri
->prefix
[RIPNG_FILTER_OUT
] = NULL
;
2758 ripng_distribute_update_interface (struct interface
*ifp
)
2760 struct distribute
*dist
;
2762 dist
= distribute_lookup (ifp
->name
);
2764 ripng_distribute_update (dist
);
2767 /* Update all interface's distribute list. */
2769 ripng_distribute_update_all (struct prefix_list
*notused
)
2771 struct interface
*ifp
;
2772 struct listnode
*node
;
2774 for (ALL_LIST_ELEMENTS_RO (iflist
, node
, ifp
))
2775 ripng_distribute_update_interface (ifp
);
2779 ripng_distribute_update_all_wrapper (struct access_list
*notused
)
2781 ripng_distribute_update_all(NULL
);
2784 /* delete all the added ripng routes. */
2789 struct route_node
*rp
;
2790 struct ripng_info
*rinfo
;
2793 /* Clear RIPng routes */
2794 for (rp
= route_top (ripng
->table
); rp
; rp
= route_next (rp
)) {
2795 if ((rinfo
= rp
->info
) != NULL
) {
2796 if ((rinfo
->type
== ZEBRA_ROUTE_RIPNG
) &&
2797 (rinfo
->sub_type
== RIPNG_ROUTE_RTE
))
2798 ripng_zebra_ipv6_delete ((struct prefix_ipv6
*)&rp
->p
,
2799 &rinfo
->nexthop
, rinfo
->metric
);
2801 RIPNG_TIMER_OFF (rinfo
->t_timeout
);
2802 RIPNG_TIMER_OFF (rinfo
->t_garbage_collect
);
2805 route_unlock_node (rp
);
2807 ripng_info_free(rinfo
);
2811 /* Cancel the RIPng timers */
2812 RIPNG_TIMER_OFF (ripng
->t_update
);
2813 RIPNG_TIMER_OFF (ripng
->t_triggered_update
);
2814 RIPNG_TIMER_OFF (ripng
->t_triggered_interval
);
2816 /* Cancel the read thread */
2817 if (ripng
->t_read
) {
2818 thread_cancel (ripng
->t_read
);
2819 ripng
->t_read
= NULL
;
2822 /* Close the RIPng socket */
2823 if (ripng
->sock
>= 0) {
2828 /* Static RIPng route configuration. */
2829 for (rp
= route_top (ripng
->route
); rp
; rp
= route_next (rp
))
2832 route_unlock_node (rp
);
2835 /* RIPng aggregated prefixes */
2836 for (rp
= route_top (ripng
->aggregate
); rp
; rp
= route_next (rp
))
2839 route_unlock_node (rp
);
2842 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++)
2843 if (ripng
->route_map
[i
].name
)
2844 free (ripng
->route_map
[i
].name
);
2846 XFREE (MTYPE_ROUTE_TABLE
, ripng
->table
);
2847 XFREE (MTYPE_ROUTE_TABLE
, ripng
->route
);
2848 XFREE (MTYPE_ROUTE_TABLE
, ripng
->aggregate
);
2850 XFREE (MTYPE_RIPNG
, ripng
);
2854 ripng_clean_network();
2855 ripng_passive_interface_clean ();
2856 ripng_offset_clean ();
2857 ripng_interface_clean ();
2858 ripng_redistribute_clean ();
2861 /* Reset all values to the default settings. */
2865 /* Call ripd related reset functions. */
2866 ripng_debug_reset ();
2867 ripng_route_map_reset ();
2869 /* Call library reset functions. */
2871 access_list_reset ();
2872 prefix_list_reset ();
2874 distribute_list_reset ();
2876 ripng_interface_reset ();
2878 ripng_zclient_reset ();
2882 ripng_if_rmap_update (struct if_rmap
*if_rmap
)
2884 struct interface
*ifp
;
2885 struct ripng_interface
*ri
;
2886 struct route_map
*rmap
;
2888 ifp
= if_lookup_by_name (if_rmap
->ifname
);
2894 if (if_rmap
->routemap
[IF_RMAP_IN
])
2896 rmap
= route_map_lookup_by_name (if_rmap
->routemap
[IF_RMAP_IN
]);
2898 ri
->routemap
[IF_RMAP_IN
] = rmap
;
2900 ri
->routemap
[IF_RMAP_IN
] = NULL
;
2903 ri
->routemap
[RIPNG_FILTER_IN
] = NULL
;
2905 if (if_rmap
->routemap
[IF_RMAP_OUT
])
2907 rmap
= route_map_lookup_by_name (if_rmap
->routemap
[IF_RMAP_OUT
]);
2909 ri
->routemap
[IF_RMAP_OUT
] = rmap
;
2911 ri
->routemap
[IF_RMAP_OUT
] = NULL
;
2914 ri
->routemap
[RIPNG_FILTER_OUT
] = NULL
;
2918 ripng_if_rmap_update_interface (struct interface
*ifp
)
2920 struct if_rmap
*if_rmap
;
2922 if_rmap
= if_rmap_lookup (ifp
->name
);
2924 ripng_if_rmap_update (if_rmap
);
2928 ripng_routemap_update_redistribute (void)
2934 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++)
2936 if (ripng
->route_map
[i
].name
)
2937 ripng
->route_map
[i
].map
=
2938 route_map_lookup_by_name (ripng
->route_map
[i
].name
);
2944 ripng_routemap_update (const char *unused
)
2946 struct interface
*ifp
;
2947 struct listnode
*node
;
2949 for (ALL_LIST_ELEMENTS_RO (iflist
, node
, ifp
))
2950 ripng_if_rmap_update_interface (ifp
);
2952 ripng_routemap_update_redistribute ();
2955 /* Initialize ripng structure and set commands. */
2960 srand (time (NULL
));
2962 /* Install RIPNG_NODE. */
2963 install_node (&cmd_ripng_node
, ripng_config_write
);
2965 /* Install ripng commands. */
2966 install_element (VIEW_NODE
, &show_ipv6_ripng_cmd
);
2967 install_element (VIEW_NODE
, &show_ipv6_ripng_status_cmd
);
2969 install_element (ENABLE_NODE
, &show_ipv6_ripng_cmd
);
2970 install_element (ENABLE_NODE
, &show_ipv6_ripng_status_cmd
);
2972 install_element (CONFIG_NODE
, &router_ripng_cmd
);
2973 install_element (CONFIG_NODE
, &no_router_ripng_cmd
);
2975 install_default (RIPNG_NODE
);
2976 install_element (RIPNG_NODE
, &ripng_route_cmd
);
2977 install_element (RIPNG_NODE
, &no_ripng_route_cmd
);
2978 install_element (RIPNG_NODE
, &ripng_aggregate_address_cmd
);
2979 install_element (RIPNG_NODE
, &no_ripng_aggregate_address_cmd
);
2981 install_element (RIPNG_NODE
, &ripng_default_metric_cmd
);
2982 install_element (RIPNG_NODE
, &no_ripng_default_metric_cmd
);
2983 install_element (RIPNG_NODE
, &no_ripng_default_metric_val_cmd
);
2985 install_element (RIPNG_NODE
, &ripng_timers_cmd
);
2986 install_element (RIPNG_NODE
, &no_ripng_timers_cmd
);
2987 install_element (RIPNG_NODE
, &no_ripng_timers_val_cmd
);
2989 install_element (RIPNG_NODE
, &ripng_update_timer_cmd
);
2990 install_element (RIPNG_NODE
, &no_ripng_update_timer_cmd
);
2991 install_element (RIPNG_NODE
, &ripng_timeout_timer_cmd
);
2992 install_element (RIPNG_NODE
, &no_ripng_timeout_timer_cmd
);
2993 install_element (RIPNG_NODE
, &ripng_garbage_timer_cmd
);
2994 install_element (RIPNG_NODE
, &no_ripng_garbage_timer_cmd
);
2997 install_element (RIPNG_NODE
, &ripng_default_information_originate_cmd
);
2998 install_element (RIPNG_NODE
, &no_ripng_default_information_originate_cmd
);
3001 ripng_debug_init ();
3003 /* Access list install. */
3004 access_list_init ();
3005 access_list_add_hook (ripng_distribute_update_all_wrapper
);
3006 access_list_delete_hook (ripng_distribute_update_all_wrapper
);
3008 /* Prefix list initialize.*/
3009 prefix_list_init ();
3010 prefix_list_add_hook (ripng_distribute_update_all
);
3011 prefix_list_delete_hook (ripng_distribute_update_all
);
3013 /* Distribute list install. */
3014 distribute_list_init (RIPNG_NODE
);
3015 distribute_list_add_hook (ripng_distribute_update
);
3016 distribute_list_delete_hook (ripng_distribute_update
);
3018 /* Route-map for interface. */
3019 ripng_route_map_init ();
3020 ripng_offset_init ();
3022 route_map_add_hook (ripng_routemap_update
);
3023 route_map_delete_hook (ripng_routemap_update
);
3025 if_rmap_init (RIPNG_NODE
);
3026 if_rmap_hook_add (ripng_if_rmap_update
);
3027 if_rmap_hook_delete (ripng_if_rmap_update
);