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
;
76 /* Utility function for making IPv6 address string. */
78 inet6_ntop (struct in6_addr
*p
)
80 static char buf
[INET6_ADDRSTRLEN
];
82 inet_ntop (AF_INET6
, p
, buf
, INET6_ADDRSTRLEN
);
88 ripng_route_rte (struct ripng_info
*rinfo
)
90 return (rinfo
->type
== ZEBRA_ROUTE_RIPNG
&& rinfo
->sub_type
== RIPNG_ROUTE_RTE
);
93 /* Allocate new ripng information. */
97 struct ripng_info
*new;
99 new = XCALLOC (MTYPE_RIPNG_ROUTE
, sizeof (struct ripng_info
));
103 /* Free ripng information. */
105 ripng_info_free (struct ripng_info
*rinfo
)
107 XFREE (MTYPE_RIPNG_ROUTE
, rinfo
);
111 setsockopt_so_recvbuf (int sock
, int size
)
115 ret
= setsockopt (sock
, SOL_SOCKET
, SO_RCVBUF
, (char *) &size
, sizeof (int));
117 zlog (NULL
, LOG_ERR
, "can't setsockopt SO_RCVBUF");
121 /* Create ripng socket. */
123 ripng_make_socket (void)
127 struct sockaddr_in6 ripaddr
;
129 sock
= socket (AF_INET6
, SOCK_DGRAM
, 0);
132 zlog (NULL
, LOG_ERR
, "Can't make ripng socket");
136 ret
= setsockopt_so_recvbuf (sock
, 8096);
139 ret
= setsockopt_ipv6_pktinfo (sock
, 1);
142 ret
= setsockopt_ipv6_multicast_hops (sock
, 255);
145 ret
= setsockopt_ipv6_multicast_loop (sock
, 0);
148 ret
= setsockopt_ipv6_hoplimit (sock
, 1);
152 memset (&ripaddr
, 0, sizeof (ripaddr
));
153 ripaddr
.sin6_family
= AF_INET6
;
155 ripaddr
.sin6_len
= sizeof (struct sockaddr_in6
);
156 #endif /* SIN6_LEN */
157 ripaddr
.sin6_port
= htons (RIPNG_PORT_DEFAULT
);
159 if (ripngd_privs
.change (ZPRIVS_RAISE
))
160 zlog_err ("ripng_make_socket: could not raise privs");
162 ret
= bind (sock
, (struct sockaddr
*) &ripaddr
, sizeof (ripaddr
));
165 zlog (NULL
, LOG_ERR
, "Can't bind ripng socket: %s.", strerror (errno
));
166 if (ripngd_privs
.change (ZPRIVS_LOWER
))
167 zlog_err ("ripng_make_socket: could not lower privs");
170 if (ripngd_privs
.change (ZPRIVS_LOWER
))
171 zlog_err ("ripng_make_socket: could not lower privs");
175 /* Send RIPng packet. */
177 ripng_send_packet (caddr_t buf
, int bufsize
, struct sockaddr_in6
*to
,
178 struct interface
*ifp
)
183 struct cmsghdr
*cmsgptr
;
185 struct in6_pktinfo
*pkt
;
186 struct sockaddr_in6 addr
;
188 if (IS_RIPNG_DEBUG_SEND
) {
190 zlog_info ("send to %s", inet6_ntop (&to
->sin6_addr
));
191 zlog_info (" send interface %s", ifp
->name
);
192 zlog_info (" send packet size %d", bufsize
);
195 memset (&addr
, 0, sizeof (struct sockaddr_in6
));
196 addr
.sin6_family
= AF_INET6
;
198 addr
.sin6_len
= sizeof (struct sockaddr_in6
);
199 #endif /* SIN6_LEN */
200 addr
.sin6_flowinfo
= htonl (RIPNG_PRIORITY_DEFAULT
);
202 /* When destination is specified. */
205 addr
.sin6_addr
= to
->sin6_addr
;
206 addr
.sin6_port
= to
->sin6_port
;
210 inet_pton(AF_INET6
, RIPNG_GROUP
, &addr
.sin6_addr
);
211 addr
.sin6_port
= htons (RIPNG_PORT_DEFAULT
);
214 msg
.msg_name
= (void *) &addr
;
215 msg
.msg_namelen
= sizeof (struct sockaddr_in6
);
218 msg
.msg_control
= (void *) adata
;
219 msg
.msg_controllen
= CMSG_SPACE(sizeof(struct in6_pktinfo
));
222 iov
.iov_len
= bufsize
;
224 cmsgptr
= (struct cmsghdr
*)adata
;
225 cmsgptr
->cmsg_len
= CMSG_LEN(sizeof (struct in6_pktinfo
));
226 cmsgptr
->cmsg_level
= IPPROTO_IPV6
;
227 cmsgptr
->cmsg_type
= IPV6_PKTINFO
;
229 pkt
= (struct in6_pktinfo
*) CMSG_DATA (cmsgptr
);
230 memset (&pkt
->ipi6_addr
, 0, sizeof (struct in6_addr
));
231 pkt
->ipi6_ifindex
= ifp
->ifindex
;
233 ret
= sendmsg (ripng
->sock
, &msg
, 0);
237 zlog_err ("RIPng send fail on %s to %s: %s", ifp
->name
,
238 inet6_ntop (&to
->sin6_addr
), strerror (errno
));
240 zlog_err ("RIPng send fail on %s: %s", ifp
->name
, strerror (errno
));
246 /* Receive UDP RIPng packet from socket. */
248 ripng_recv_packet (int sock
, u_char
*buf
, int bufsize
,
249 struct sockaddr_in6
*from
, unsigned int *ifindex
,
255 struct cmsghdr
*cmsgptr
;
258 /* Ancillary data. This store cmsghdr and in6_pktinfo. But at this
259 point I can't determine size of cmsghdr */
262 /* Fill in message and iovec. */
263 msg
.msg_name
= (void *) from
;
264 msg
.msg_namelen
= sizeof (struct sockaddr_in6
);
267 msg
.msg_control
= (void *) adata
;
268 msg
.msg_controllen
= sizeof adata
;
270 iov
.iov_len
= bufsize
;
272 /* If recvmsg fail return minus value. */
273 ret
= recvmsg (sock
, &msg
, 0);
277 for (cmsgptr
= CMSG_FIRSTHDR(&msg
); cmsgptr
!= NULL
;
278 cmsgptr
= CMSG_NXTHDR(&msg
, cmsgptr
))
280 /* I want interface index which this packet comes from. */
281 if (cmsgptr
->cmsg_level
== IPPROTO_IPV6
&&
282 cmsgptr
->cmsg_type
== IPV6_PKTINFO
)
284 struct in6_pktinfo
*ptr
;
286 ptr
= (struct in6_pktinfo
*) CMSG_DATA (cmsgptr
);
287 *ifindex
= ptr
->ipi6_ifindex
;
288 dst
= ptr
->ipi6_addr
;
291 zlog_warn ("Interface index returned by IPV6_PKTINFO is zero");
294 /* Incoming packet's multicast hop limit. */
295 if (cmsgptr
->cmsg_level
== IPPROTO_IPV6
&&
296 cmsgptr
->cmsg_type
== IPV6_HOPLIMIT
)
297 *hoplimit
= *((int *) CMSG_DATA (cmsgptr
));
300 /* Hoplimit check shold be done when destination address is
301 multicast address. */
302 if (! IN6_IS_ADDR_MULTICAST (&dst
))
308 /* Dump rip packet */
310 ripng_packet_dump (struct ripng_packet
*packet
, int size
, char *sndrcv
)
316 /* Set command string. */
317 if (packet
->command
== RIPNG_REQUEST
)
318 command_str
= "request";
319 else if (packet
->command
== RIPNG_RESPONSE
)
320 command_str
= "response";
322 command_str
= "unknown";
324 /* Dump packet header. */
325 zlog_info ("%s %s version %d packet size %d",
326 sndrcv
, command_str
, packet
->version
, size
);
328 /* Dump each routing table entry. */
331 for (lim
= (caddr_t
) packet
+ size
; (caddr_t
) rte
< lim
; rte
++)
333 if (rte
->metric
== RIPNG_METRIC_NEXTHOP
)
334 zlog_info (" nexthop %s/%d", inet6_ntop (&rte
->addr
), rte
->prefixlen
);
336 zlog_info (" %s/%d metric %d tag %d",
337 inet6_ntop (&rte
->addr
), rte
->prefixlen
,
338 rte
->metric
, ntohs (rte
->tag
));
342 /* RIPng next hop address RTE (Route Table Entry). */
344 ripng_nexthop_rte (struct rte
*rte
,
345 struct sockaddr_in6
*from
,
346 struct ripng_nexthop
*nexthop
)
348 char buf
[INET6_BUFSIZ
];
350 /* Logging before checking RTE. */
351 if (IS_RIPNG_DEBUG_RECV
)
352 zlog_info ("RIPng nexthop RTE address %s tag %d prefixlen %d",
353 inet6_ntop (&rte
->addr
), ntohs (rte
->tag
), rte
->prefixlen
);
355 /* RFC2080 2.1.1 Next Hop:
356 The route tag and prefix length in the next hop RTE must be
357 set to zero on sending and ignored on receiption. */
358 if (ntohs (rte
->tag
) != 0)
359 zlog_warn ("RIPng nexthop RTE with non zero tag value %d from %s",
360 ntohs (rte
->tag
), inet6_ntop (&from
->sin6_addr
));
362 if (rte
->prefixlen
!= 0)
363 zlog_warn ("RIPng nexthop RTE with non zero prefixlen value %d from %s",
364 rte
->prefixlen
, inet6_ntop (&from
->sin6_addr
));
366 /* Specifying a value of 0:0:0:0:0:0:0:0 in the prefix field of a
367 next hop RTE indicates that the next hop address should be the
368 originator of the RIPng advertisement. An address specified as a
369 next hop must be a link-local address. */
370 if (IN6_IS_ADDR_UNSPECIFIED (&rte
->addr
))
372 nexthop
->flag
= RIPNG_NEXTHOP_UNSPEC
;
373 memset (&nexthop
->address
, 0, sizeof (struct in6_addr
));
377 if (IN6_IS_ADDR_LINKLOCAL (&rte
->addr
))
379 nexthop
->flag
= RIPNG_NEXTHOP_ADDRESS
;
380 IPV6_ADDR_COPY (&nexthop
->address
, &rte
->addr
);
384 /* The purpose of the next hop RTE is to eliminate packets being
385 routed through extra hops in the system. It is particularly useful
386 when RIPng is not being run on all of the routers on a network.
387 Note that next hop RTE is "advisory". That is, if the provided
388 information is ignored, a possibly sub-optimal, but absolutely
389 valid, route may be taken. If the received next hop address is not
390 a link-local address, it should be treated as 0:0:0:0:0:0:0:0. */
391 zlog_warn ("RIPng nexthop RTE with non link-local address %s from %s",
392 inet6_ntop (&rte
->addr
),
393 inet_ntop (AF_INET6
, &from
->sin6_addr
, buf
, INET6_BUFSIZ
));
395 nexthop
->flag
= RIPNG_NEXTHOP_UNSPEC
;
396 memset (&nexthop
->address
, 0, sizeof (struct in6_addr
));
401 /* If ifp has same link-local address then return 1. */
403 ripng_lladdr_check (struct interface
*ifp
, struct in6_addr
*addr
)
406 struct connected
*connected
;
409 for (listnode
= listhead (ifp
->connected
); listnode
; nextnode (listnode
))
410 if ((connected
= getdata (listnode
)) != NULL
)
412 p
= connected
->address
;
414 if (p
->family
== AF_INET6
&&
415 IN6_IS_ADDR_LINKLOCAL (&p
->u
.prefix6
) &&
416 IN6_ARE_ADDR_EQUAL (&p
->u
.prefix6
, addr
))
422 /* RIPng route garbage collect timer. */
424 ripng_garbage_collect (struct thread
*t
)
426 struct ripng_info
*rinfo
;
427 struct route_node
*rp
;
429 rinfo
= THREAD_ARG (t
);
430 rinfo
->t_garbage_collect
= NULL
;
432 /* Off timeout timer. */
433 RIPNG_TIMER_OFF (rinfo
->t_timeout
);
435 /* Get route_node pointer. */
438 /* Unlock route_node. */
440 route_unlock_node (rp
);
442 /* Free RIPng routing information. */
443 ripng_info_free (rinfo
);
448 /* Timeout RIPng routes. */
450 ripng_timeout (struct thread
*t
)
452 struct ripng_info
*rinfo
;
453 struct route_node
*rp
;
455 rinfo
= THREAD_ARG (t
);
456 rinfo
->t_timeout
= NULL
;
458 /* Get route_node pointer. */
461 /* - The garbage-collection timer is set for 120 seconds. */
462 RIPNG_TIMER_ON (rinfo
->t_garbage_collect
, ripng_garbage_collect
,
463 ripng
->garbage_time
);
465 /* Delete this route from the kernel. */
466 ripng_zebra_ipv6_delete ((struct prefix_ipv6
*)&rp
->p
, &rinfo
->nexthop
,
468 /* - The metric for the route is set to 16 (infinity). This causes
469 the route to be removed from service. */
470 rinfo
->metric
= RIPNG_METRIC_INFINITY
;
471 rinfo
->flags
&= ~RIPNG_RTF_FIB
;
473 /* Aggregate count decrement. */
474 ripng_aggregate_decrement (rp
, rinfo
);
476 /* - The route change flag is to indicate that this entry has been
478 rinfo
->flags
|= RIPNG_RTF_CHANGED
;
480 /* - The output process is signalled to trigger a response. */
481 ripng_event (RIPNG_TRIGGERED_UPDATE
, 0);
487 ripng_timeout_update (struct ripng_info
*rinfo
)
489 if (rinfo
->metric
!= RIPNG_METRIC_INFINITY
)
491 RIPNG_TIMER_OFF (rinfo
->t_timeout
);
492 RIPNG_TIMER_ON (rinfo
->t_timeout
, ripng_timeout
, ripng
->timeout_time
);
497 ripng_incoming_filter (struct prefix_ipv6
*p
, struct ripng_interface
*ri
)
499 struct distribute
*dist
;
500 struct access_list
*alist
;
501 struct prefix_list
*plist
;
503 /* Input distribute-list filtering. */
504 if (ri
->list
[RIPNG_FILTER_IN
])
506 if (access_list_apply (ri
->list
[RIPNG_FILTER_IN
],
507 (struct prefix
*) p
) == FILTER_DENY
)
509 if (IS_RIPNG_DEBUG_PACKET
)
510 zlog_info ("%s/%d filtered by distribute in",
511 inet6_ntop (&p
->prefix
), p
->prefixlen
);
515 if (ri
->prefix
[RIPNG_FILTER_IN
])
517 if (prefix_list_apply (ri
->prefix
[RIPNG_FILTER_IN
],
518 (struct prefix
*) p
) == PREFIX_DENY
)
520 if (IS_RIPNG_DEBUG_PACKET
)
521 zlog_info ("%s/%d filtered by prefix-list in",
522 inet6_ntop (&p
->prefix
), p
->prefixlen
);
527 /* All interface filter check. */
528 dist
= distribute_lookup (NULL
);
531 if (dist
->list
[DISTRIBUTE_IN
])
533 alist
= access_list_lookup (AFI_IP6
, dist
->list
[DISTRIBUTE_IN
]);
537 if (access_list_apply (alist
,
538 (struct prefix
*) p
) == FILTER_DENY
)
540 if (IS_RIPNG_DEBUG_PACKET
)
541 zlog_info ("%s/%d filtered by distribute in",
542 inet6_ntop (&p
->prefix
), p
->prefixlen
);
547 if (dist
->prefix
[DISTRIBUTE_IN
])
549 plist
= prefix_list_lookup (AFI_IP6
, dist
->prefix
[DISTRIBUTE_IN
]);
553 if (prefix_list_apply (plist
,
554 (struct prefix
*) p
) == PREFIX_DENY
)
556 if (IS_RIPNG_DEBUG_PACKET
)
557 zlog_info ("%s/%d filtered by prefix-list in",
558 inet6_ntop (&p
->prefix
), p
->prefixlen
);
568 ripng_outgoing_filter (struct prefix_ipv6
*p
, struct ripng_interface
*ri
)
570 struct distribute
*dist
;
571 struct access_list
*alist
;
572 struct prefix_list
*plist
;
574 if (ri
->list
[RIPNG_FILTER_OUT
])
576 if (access_list_apply (ri
->list
[RIPNG_FILTER_OUT
],
577 (struct prefix
*) p
) == FILTER_DENY
)
579 if (IS_RIPNG_DEBUG_PACKET
)
580 zlog_info ("%s/%d is filtered by distribute out",
581 inet6_ntop (&p
->prefix
), p
->prefixlen
);
585 if (ri
->prefix
[RIPNG_FILTER_OUT
])
587 if (prefix_list_apply (ri
->prefix
[RIPNG_FILTER_OUT
],
588 (struct prefix
*) p
) == PREFIX_DENY
)
590 if (IS_RIPNG_DEBUG_PACKET
)
591 zlog_info ("%s/%d is filtered by prefix-list out",
592 inet6_ntop (&p
->prefix
), p
->prefixlen
);
597 /* All interface filter check. */
598 dist
= distribute_lookup (NULL
);
601 if (dist
->list
[DISTRIBUTE_OUT
])
603 alist
= access_list_lookup (AFI_IP6
, dist
->list
[DISTRIBUTE_OUT
]);
607 if (access_list_apply (alist
,
608 (struct prefix
*) p
) == FILTER_DENY
)
610 if (IS_RIPNG_DEBUG_PACKET
)
611 zlog_info ("%s/%d filtered by distribute out",
612 inet6_ntop (&p
->prefix
), p
->prefixlen
);
617 if (dist
->prefix
[DISTRIBUTE_OUT
])
619 plist
= prefix_list_lookup (AFI_IP6
, dist
->prefix
[DISTRIBUTE_OUT
]);
623 if (prefix_list_apply (plist
,
624 (struct prefix
*) p
) == PREFIX_DENY
)
626 if (IS_RIPNG_DEBUG_PACKET
)
627 zlog_info ("%s/%d filtered by prefix-list out",
628 inet6_ntop (&p
->prefix
), p
->prefixlen
);
637 /* Process RIPng route according to RFC2080. */
639 ripng_route_process (struct rte
*rte
, struct sockaddr_in6
*from
,
640 struct ripng_nexthop
*ripng_nexthop
,
641 struct interface
*ifp
)
644 struct prefix_ipv6 p
;
645 struct route_node
*rp
;
646 struct ripng_info
*rinfo
;
647 struct ripng_interface
*ri
;
648 struct in6_addr
*nexthop
;
652 /* Make prefix structure. */
653 memset (&p
, 0, sizeof (struct prefix_ipv6
));
655 /* p.prefix = rte->addr; */
656 IPV6_ADDR_COPY (&p
.prefix
, &rte
->addr
);
657 p
.prefixlen
= rte
->prefixlen
;
659 /* Make sure mask is applied. */
660 /* XXX We have to check the prefix is valid or not before call
662 apply_mask_ipv6 (&p
);
664 /* Apply input filters. */
667 ret
= ripng_incoming_filter (&p
, ri
);
672 if (ri
->routemap
[RIPNG_FILTER_IN
])
675 struct ripng_info newinfo
;
677 memset (&newinfo
, 0, sizeof (struct ripng_info
));
678 newinfo
.type
= ZEBRA_ROUTE_RIPNG
;
679 newinfo
.sub_type
= RIPNG_ROUTE_RTE
;
680 if (ripng_nexthop
->flag
== RIPNG_NEXTHOP_ADDRESS
)
681 newinfo
.nexthop
= ripng_nexthop
->address
;
683 newinfo
.nexthop
= from
->sin6_addr
;
684 newinfo
.from
= from
->sin6_addr
;
685 newinfo
.ifindex
= ifp
->ifindex
;
686 newinfo
.metric
= rte
->metric
;
687 newinfo
.metric_out
= rte
->metric
; /* XXX */
688 newinfo
.tag
= ntohs(rte
->tag
); /* XXX */
690 ret
= route_map_apply (ri
->routemap
[RIPNG_FILTER_IN
],
691 (struct prefix
*)&p
, RMAP_RIPNG
, &newinfo
);
693 if (ret
== RMAP_DENYMATCH
)
695 if (IS_RIPNG_DEBUG_PACKET
)
696 zlog_info ("RIPng %s/%d is filtered by route-map in",
697 inet6_ntop (&p
.prefix
), p
.prefixlen
);
701 /* Get back the object */
702 if (ripng_nexthop
->flag
== RIPNG_NEXTHOP_ADDRESS
) {
703 if (! IPV6_ADDR_SAME(&newinfo
.nexthop
, &ripng_nexthop
->address
) ) {
704 /* the nexthop get changed by the routemap */
705 if (IN6_IS_ADDR_LINKLOCAL(&newinfo
.nexthop
))
706 ripng_nexthop
->address
= newinfo
.nexthop
;
708 ripng_nexthop
->address
= in6addr_any
;
711 if (! IPV6_ADDR_SAME(&newinfo
.nexthop
, &from
->sin6_addr
) ) {
712 /* the nexthop get changed by the routemap */
713 if (IN6_IS_ADDR_LINKLOCAL(&newinfo
.nexthop
)) {
714 ripng_nexthop
->flag
= RIPNG_NEXTHOP_ADDRESS
;
715 ripng_nexthop
->address
= newinfo
.nexthop
;
719 rte
->tag
= htons(newinfo
.tag_out
); /* XXX */
720 rte
->metric
= newinfo
.metric_out
; /* XXX: the routemap uses the metric_out field */
723 /* Once the entry has been validated, update the metric by
724 * adding the cost of the network on wich the message
725 * arrived. If the result is greater than infinity, use infinity
726 * (RFC2453 Sec. 3.9.2)
729 /* Zebra ripngd can handle offset-list in. */
730 ret
= ripng_offset_list_apply_in (&p
, ifp
, &rte
->metric
);
732 /* If offset-list does not modify the metric use interface's
735 rte
->metric
+= ifp
->metric
;
737 if (rte
->metric
> RIPNG_METRIC_INFINITY
)
738 rte
->metric
= RIPNG_METRIC_INFINITY
;
740 /* Set nexthop pointer. */
741 if (ripng_nexthop
->flag
== RIPNG_NEXTHOP_ADDRESS
)
742 nexthop
= &ripng_nexthop
->address
;
744 nexthop
= &from
->sin6_addr
;
746 /* Lookup RIPng routing table. */
747 rp
= route_node_get (ripng
->table
, (struct prefix
*) &p
);
753 /* Redistributed route check. */
754 if (rinfo
->type
!= ZEBRA_ROUTE_RIPNG
755 && rinfo
->metric
!= RIPNG_METRIC_INFINITY
)
758 /* Local static route. */
759 if (rinfo
->type
== ZEBRA_ROUTE_RIPNG
760 && ((rinfo
->sub_type
== RIPNG_ROUTE_STATIC
) ||
761 (rinfo
->sub_type
== RIPNG_ROUTE_DEFAULT
))
762 && rinfo
->metric
!= RIPNG_METRIC_INFINITY
)
766 if (rp
->info
== NULL
)
768 /* Now, check to see whether there is already an explicit route
769 for the destination prefix. If there is no such route, add
770 this route to the routing table, unless the metric is
771 infinity (there is no point in adding a route which
773 if (rte
->metric
!= RIPNG_METRIC_INFINITY
)
775 rinfo
= ripng_info_new ();
777 /* - Setting the destination prefix and length to those in
782 /* - Setting the metric to the newly calculated metric (as
784 rinfo
->metric
= rte
->metric
;
785 rinfo
->tag
= ntohs (rte
->tag
);
787 /* - Set the next hop address to be the address of the router
788 from which the datagram came or the next hop address
789 specified by a next hop RTE. */
790 IPV6_ADDR_COPY (&rinfo
->nexthop
, nexthop
);
791 IPV6_ADDR_COPY (&rinfo
->from
, &from
->sin6_addr
);
792 rinfo
->ifindex
= ifp
->ifindex
;
794 /* - Initialize the timeout for the route. If the
795 garbage-collection timer is running for this route, stop it. */
796 ripng_timeout_update (rinfo
);
798 /* - Set the route change flag. */
799 rinfo
->flags
|= RIPNG_RTF_CHANGED
;
801 /* - Signal the output process to trigger an update (see section
803 ripng_event (RIPNG_TRIGGERED_UPDATE
, 0);
805 /* Finally, route goes into the kernel. */
806 rinfo
->type
= ZEBRA_ROUTE_RIPNG
;
807 rinfo
->sub_type
= RIPNG_ROUTE_RTE
;
809 ripng_zebra_ipv6_add (&p
, &rinfo
->nexthop
, rinfo
->ifindex
);
810 rinfo
->flags
|= RIPNG_RTF_FIB
;
812 /* Aggregate check. */
813 ripng_aggregate_increment (rp
, rinfo
);
820 /* If there is an existing route, compare the next hop address
821 to the address of the router from which the datagram came.
822 If this datagram is from the same router as the existing
823 route, reinitialize the timeout. */
824 same
= (IN6_ARE_ADDR_EQUAL (&rinfo
->from
, &from
->sin6_addr
)
825 && (rinfo
->ifindex
== ifp
->ifindex
));
828 ripng_timeout_update (rinfo
);
830 /* Next, compare the metrics. If the datagram is from the same
831 router as the existing route, and the new metric is different
832 than the old one; or, if the new metric is lower than the old
833 one; do the following actions: */
834 if ((same
&& rinfo
->metric
!= rte
->metric
) ||
835 rte
->metric
< rinfo
->metric
)
837 /* - Adopt the route from the datagram. That is, put the
838 new metric in, and adjust the next hop address (if
840 oldmetric
= rinfo
->metric
;
841 rinfo
->metric
= rte
->metric
;
842 rinfo
->tag
= ntohs (rte
->tag
);
843 IPV6_ADDR_COPY (&rinfo
->from
, &from
->sin6_addr
);
844 rinfo
->ifindex
= ifp
->ifindex
;
846 /* Should a new route to this network be established
847 while the garbage-collection timer is running, the
848 new route will replace the one that is about to be
849 deleted. In this case the garbage-collection timer
852 if (oldmetric
== RIPNG_METRIC_INFINITY
&&
853 rinfo
->metric
< RIPNG_METRIC_INFINITY
)
855 rinfo
->type
= ZEBRA_ROUTE_RIPNG
;
856 rinfo
->sub_type
= RIPNG_ROUTE_RTE
;
858 RIPNG_TIMER_OFF (rinfo
->t_garbage_collect
);
860 if (! IPV6_ADDR_SAME (&rinfo
->nexthop
, nexthop
))
861 IPV6_ADDR_COPY (&rinfo
->nexthop
, nexthop
);
863 ripng_zebra_ipv6_add (&p
, nexthop
, ifp
->ifindex
);
864 rinfo
->flags
|= RIPNG_RTF_FIB
;
866 /* The aggregation counter needs to be updated because
867 the prefixes, which are into the gc, have been
868 removed from the aggregator (see ripng_timout). */
869 ripng_aggregate_increment (rp
, rinfo
);
872 /* Update nexthop and/or metric value. */
873 if (oldmetric
!= RIPNG_METRIC_INFINITY
)
875 ripng_zebra_ipv6_delete (&p
, &rinfo
->nexthop
, rinfo
->ifindex
);
876 ripng_zebra_ipv6_add (&p
, nexthop
, ifp
->ifindex
);
877 rinfo
->flags
|= RIPNG_RTF_FIB
;
879 if (! IPV6_ADDR_SAME (&rinfo
->nexthop
, nexthop
))
880 IPV6_ADDR_COPY (&rinfo
->nexthop
, nexthop
);
883 /* - Set the route change flag and signal the output process
884 to trigger an update. */
885 rinfo
->flags
|= RIPNG_RTF_CHANGED
;
886 ripng_event (RIPNG_TRIGGERED_UPDATE
, 0);
888 /* - If the new metric is infinity, start the deletion
889 process (described above); */
890 if (rinfo
->metric
== RIPNG_METRIC_INFINITY
)
892 /* If the new metric is infinity, the deletion process
893 begins for the route, which is no longer used for
894 routing packets. Note that the deletion process is
895 started only when the metric is first set to
896 infinity. If the metric was already infinity, then a
897 new deletion process is not started. */
898 if (oldmetric
!= RIPNG_METRIC_INFINITY
)
900 /* - The garbage-collection timer is set for 120 seconds. */
901 RIPNG_TIMER_ON (rinfo
->t_garbage_collect
,
902 ripng_garbage_collect
, ripng
->garbage_time
);
903 RIPNG_TIMER_OFF (rinfo
->t_timeout
);
905 /* - The metric for the route is set to 16
906 (infinity). This causes the route to be removed
908 ripng_zebra_ipv6_delete (&p
, &rinfo
->nexthop
, rinfo
->ifindex
);
909 rinfo
->flags
&= ~RIPNG_RTF_FIB
;
911 /* Aggregate count decrement. */
912 ripng_aggregate_decrement (rp
, rinfo
);
914 /* - The route change flag is to indicate that this
915 entry has been changed. */
916 /* - The output process is signalled to trigger a
918 ; /* Above processes are already done previously. */
923 /* otherwise, re-initialize the timeout. */
924 ripng_timeout_update (rinfo
);
927 /* Unlock tempolary lock of the route. */
928 route_unlock_node (rp
);
932 /* Add redistributed route to RIPng table. */
934 ripng_redistribute_add (int type
, int sub_type
, struct prefix_ipv6
*p
,
935 unsigned int ifindex
, struct in6_addr
*nexthop
)
937 struct route_node
*rp
;
938 struct ripng_info
*rinfo
;
940 /* Redistribute route */
941 if (IN6_IS_ADDR_LINKLOCAL (&p
->prefix
))
943 if (IN6_IS_ADDR_LOOPBACK (&p
->prefix
))
945 #if defined (MUSICA) || defined (LINUX)
946 /* XXX As long as the RIPng redistribution is applied to all the connected
947 * routes, one needs to filter the ::/96 prefixes.
948 * However it could be a wanted case, it will be removed soon.
950 if ((IN6_IS_ADDR_V4COMPAT(&p
->prefix
)) ||
951 (IN6_IS_ADDR_UNSPECIFIED (&p
->prefix
) && (p
->prefixlen
== 96)))
953 #endif /* MUSICA or LINUX */
955 rp
= route_node_get (ripng
->table
, (struct prefix
*) p
);
960 if (rinfo
->type
== ZEBRA_ROUTE_CONNECT
961 && rinfo
->sub_type
== RIPNG_ROUTE_INTERFACE
962 && rinfo
->metric
!= RIPNG_METRIC_INFINITY
) {
963 route_unlock_node (rp
);
967 /* Manually configured RIPng route check.
968 * They have the precedence on all the other entries.
970 if (rinfo
->type
== ZEBRA_ROUTE_RIPNG
971 && ((rinfo
->sub_type
== RIPNG_ROUTE_STATIC
) ||
972 (rinfo
->sub_type
== RIPNG_ROUTE_DEFAULT
)) ) {
973 if (type
!= ZEBRA_ROUTE_RIPNG
|| ((sub_type
!= RIPNG_ROUTE_STATIC
) &&
974 (sub_type
!= RIPNG_ROUTE_DEFAULT
))) {
975 route_unlock_node (rp
);
980 RIPNG_TIMER_OFF (rinfo
->t_timeout
);
981 RIPNG_TIMER_OFF (rinfo
->t_garbage_collect
);
983 /* Tells the other daemons about the deletion of
986 if (ripng_route_rte (rinfo
))
987 ripng_zebra_ipv6_delete ((struct prefix_ipv6
*)&rp
->p
, &rinfo
->nexthop
,
991 ripng_info_free (rinfo
);
993 route_unlock_node (rp
);
997 rinfo
= ripng_info_new ();
1000 rinfo
->sub_type
= sub_type
;
1001 rinfo
->ifindex
= ifindex
;
1005 if (nexthop
&& IN6_IS_ADDR_LINKLOCAL(nexthop
))
1006 rinfo
->nexthop
= *nexthop
;
1008 rinfo
->flags
|= RIPNG_RTF_FIB
;
1011 /* Aggregate check. */
1012 ripng_aggregate_increment (rp
, rinfo
);
1014 rinfo
->flags
|= RIPNG_RTF_CHANGED
;
1016 if (IS_RIPNG_DEBUG_EVENT
) {
1018 zlog_info ("Redistribute new prefix %s/%d on the interface %s",
1019 inet6_ntop(&p
->prefix
), p
->prefixlen
,
1020 ifindex2ifname(ifindex
));
1022 zlog_info ("Redistribute new prefix %s/%d with nexthop %s on the interface %s",
1023 inet6_ntop(&p
->prefix
), p
->prefixlen
, inet6_ntop(nexthop
),
1024 ifindex2ifname(ifindex
));
1027 ripng_event (RIPNG_TRIGGERED_UPDATE
, 0);
1030 /* Delete redistributed route to RIPng table. */
1032 ripng_redistribute_delete (int type
, int sub_type
, struct prefix_ipv6
*p
,
1033 unsigned int ifindex
)
1035 struct route_node
*rp
;
1036 struct ripng_info
*rinfo
;
1038 if (IN6_IS_ADDR_LINKLOCAL (&p
->prefix
))
1040 if (IN6_IS_ADDR_LOOPBACK (&p
->prefix
))
1042 #if defined (MUSICA) || defined (LINUX)
1043 /* XXX As long as the RIPng redistribution is applied to all the connected
1044 * routes, one needs to filter the ::/96 prefixes.
1045 * However it could be a wanted case, it will be removed soon.
1047 if ((IN6_IS_ADDR_V4COMPAT(&p
->prefix
)) ||
1048 (IN6_IS_ADDR_UNSPECIFIED (&p
->prefix
) && (p
->prefixlen
== 96)))
1050 #endif /* MUSICA or LINUX */
1052 rp
= route_node_lookup (ripng
->table
, (struct prefix
*) p
);
1059 && rinfo
->type
== type
1060 && rinfo
->sub_type
== sub_type
1061 && rinfo
->ifindex
== ifindex
)
1063 /* Perform poisoned reverse. */
1064 rinfo
->metric
= RIPNG_METRIC_INFINITY
;
1065 RIPNG_TIMER_ON (rinfo
->t_garbage_collect
,
1066 ripng_garbage_collect
, ripng
->garbage_time
);
1067 RIPNG_TIMER_OFF (rinfo
->t_timeout
);
1069 /* Aggregate count decrement. */
1070 ripng_aggregate_decrement (rp
, rinfo
);
1072 rinfo
->flags
|= RIPNG_RTF_CHANGED
;
1074 if (IS_RIPNG_DEBUG_EVENT
)
1075 zlog_info ("Poisone %s/%d on the interface %s with an infinity metric [delete]",
1076 inet6_ntop(&p
->prefix
), p
->prefixlen
,
1077 ifindex2ifname(ifindex
));
1079 ripng_event (RIPNG_TRIGGERED_UPDATE
, 0);
1084 /* Withdraw redistributed route. */
1086 ripng_redistribute_withdraw (int type
)
1088 struct route_node
*rp
;
1089 struct ripng_info
*rinfo
;
1094 for (rp
= route_top (ripng
->table
); rp
; rp
= route_next (rp
))
1095 if ((rinfo
= rp
->info
) != NULL
)
1097 if ((rinfo
->type
== type
)
1098 && (rinfo
->sub_type
!= RIPNG_ROUTE_INTERFACE
))
1100 /* Perform poisoned reverse. */
1101 rinfo
->metric
= RIPNG_METRIC_INFINITY
;
1102 RIPNG_TIMER_ON (rinfo
->t_garbage_collect
,
1103 ripng_garbage_collect
, ripng
->garbage_time
);
1104 RIPNG_TIMER_OFF (rinfo
->t_timeout
);
1106 /* Aggregate count decrement. */
1107 ripng_aggregate_decrement (rp
, rinfo
);
1109 rinfo
->flags
|= RIPNG_RTF_CHANGED
;
1111 if (IS_RIPNG_DEBUG_EVENT
) {
1112 struct prefix_ipv6
*p
= (struct prefix_ipv6
*) &rp
->p
;
1114 zlog_info ("Poisone %s/%d on the interface %s [withdraw]",
1115 inet6_ntop(&p
->prefix
), p
->prefixlen
,
1116 ifindex2ifname(rinfo
->ifindex
));
1119 ripng_event (RIPNG_TRIGGERED_UPDATE
, 0);
1124 /* RIP routing information. */
1126 ripng_response_process (struct ripng_packet
*packet
, int size
,
1127 struct sockaddr_in6
*from
, struct interface
*ifp
,
1132 struct ripng_nexthop nexthop
;
1134 /* RFC2080 2.4.2 Response Messages:
1135 The Response must be ignored if it is not from the RIPng port. */
1136 if (ntohs (from
->sin6_port
) != RIPNG_PORT_DEFAULT
)
1138 zlog_warn ("RIPng packet comes from non RIPng port %d from %s",
1139 ntohs (from
->sin6_port
), inet6_ntop (&from
->sin6_addr
));
1140 ripng_peer_bad_packet (from
);
1144 /* The datagram's IPv6 source address should be checked to see
1145 whether the datagram is from a valid neighbor; the source of the
1146 datagram must be a link-local address. */
1147 if (! IN6_IS_ADDR_LINKLOCAL(&from
->sin6_addr
))
1149 zlog_warn ("RIPng packet comes from non link local address %s",
1150 inet6_ntop (&from
->sin6_addr
));
1151 ripng_peer_bad_packet (from
);
1155 /* It is also worth checking to see whether the response is from one
1156 of the router's own addresses. Interfaces on broadcast networks
1157 may receive copies of their own multicasts immediately. If a
1158 router processes its own output as new input, confusion is likely,
1159 and such datagrams must be ignored. */
1160 if (ripng_lladdr_check (ifp
, &from
->sin6_addr
))
1162 zlog_warn ("RIPng packet comes from my own link local address %s",
1163 inet6_ntop (&from
->sin6_addr
));
1164 ripng_peer_bad_packet (from
);
1168 /* As an additional check, periodic advertisements must have their
1169 hop counts set to 255, and inbound, multicast packets sent from the
1170 RIPng port (i.e. periodic advertisement or triggered update
1171 packets) must be examined to ensure that the hop count is 255. */
1172 if (hoplimit
>= 0 && hoplimit
!= 255)
1174 zlog_warn ("RIPng packet comes with non 255 hop count %d from %s",
1175 hoplimit
, inet6_ntop (&from
->sin6_addr
));
1176 ripng_peer_bad_packet (from
);
1180 /* Update RIPng peer. */
1181 ripng_peer_update (from
, packet
->version
);
1183 /* Reset nexthop. */
1184 memset (&nexthop
, 0, sizeof (struct ripng_nexthop
));
1185 nexthop
.flag
= RIPNG_NEXTHOP_UNSPEC
;
1187 /* Set RTE pointer. */
1190 for (lim
= ((caddr_t
) packet
) + size
; (caddr_t
) rte
< lim
; rte
++)
1192 /* First of all, we have to check this RTE is next hop RTE or
1193 not. Next hop RTE is completely different with normal RTE so
1194 we need special treatment. */
1195 if (rte
->metric
== RIPNG_METRIC_NEXTHOP
)
1197 ripng_nexthop_rte (rte
, from
, &nexthop
);
1201 /* RTE information validation. */
1203 /* - is the destination prefix valid (e.g., not a multicast
1204 prefix and not a link-local address) A link-local address
1205 should never be present in an RTE. */
1206 if (IN6_IS_ADDR_MULTICAST (&rte
->addr
))
1208 zlog_warn ("Destination prefix is a multicast address %s/%d [%d]",
1209 inet6_ntop (&rte
->addr
), rte
->prefixlen
, rte
->metric
);
1210 ripng_peer_bad_route (from
);
1213 if (IN6_IS_ADDR_LINKLOCAL (&rte
->addr
))
1215 zlog_warn ("Destination prefix is a link-local address %s/%d [%d]",
1216 inet6_ntop (&rte
->addr
), rte
->prefixlen
, rte
->metric
);
1217 ripng_peer_bad_route (from
);
1220 if (IN6_IS_ADDR_LOOPBACK (&rte
->addr
))
1222 zlog_warn ("Destination prefix is a loopback address %s/%d [%d]",
1223 inet6_ntop (&rte
->addr
), rte
->prefixlen
, rte
->metric
);
1224 ripng_peer_bad_route (from
);
1228 /* - is the prefix length valid (i.e., between 0 and 128,
1230 if (rte
->prefixlen
> 128)
1232 zlog_warn ("Invalid prefix length %s/%d from %s%%%s",
1233 inet6_ntop (&rte
->addr
), rte
->prefixlen
,
1234 inet6_ntop (&from
->sin6_addr
), ifp
->name
);
1235 ripng_peer_bad_route (from
);
1239 /* - is the metric valid (i.e., between 1 and 16, inclusive) */
1240 if (! (rte
->metric
>= 1 && rte
->metric
<= 16))
1242 zlog_warn ("Invalid metric %d from %s%%%s", rte
->metric
,
1243 inet6_ntop (&from
->sin6_addr
), ifp
->name
);
1244 ripng_peer_bad_route (from
);
1248 /* Vincent: XXX Should we compute the direclty reachable nexthop
1249 * for our RIPng network ?
1252 /* Routing table updates. */
1253 ripng_route_process (rte
, from
, &nexthop
, ifp
);
1257 /* Response to request message. */
1259 ripng_request_process (struct ripng_packet
*packet
,int size
,
1260 struct sockaddr_in6
*from
, struct interface
*ifp
)
1264 struct prefix_ipv6 p
;
1265 struct route_node
*rp
;
1266 struct ripng_info
*rinfo
;
1267 struct ripng_interface
*ri
;
1269 /* Does not reponse to the requests on the loopback interfaces */
1270 if (if_is_loopback (ifp
))
1273 /* Check RIPng process is enabled on this interface. */
1278 /* When passive interface is specified, suppress responses */
1282 /* RIPng peer update. */
1283 ripng_peer_update (from
, packet
->version
);
1285 lim
= ((caddr_t
) packet
) + size
;
1288 /* The Request is processed entry by entry. If there are no
1289 entries, no response is given. */
1290 if (lim
== (caddr_t
) rte
)
1293 /* There is one special case. If there is exactly one entry in the
1294 request, and it has a destination prefix of zero, a prefix length
1295 of zero, and a metric of infinity (i.e., 16), then this is a
1296 request to send the entire routing table. In that case, a call
1297 is made to the output process to send the routing table to the
1298 requesting address/port. */
1299 if (lim
== ((caddr_t
) (rte
+ 1)) &&
1300 IN6_IS_ADDR_UNSPECIFIED (&rte
->addr
) &&
1301 rte
->prefixlen
== 0 &&
1302 rte
->metric
== RIPNG_METRIC_INFINITY
)
1304 /* All route with split horizon */
1305 ripng_output_process (ifp
, from
, ripng_all_route
);
1309 /* Except for this special case, processing is quite simple.
1310 Examine the list of RTEs in the Request one by one. For each
1311 entry, look up the destination in the router's routing
1312 database and, if there is a route, put that route's metric in
1313 the metric field of the RTE. If there is no explicit route
1314 to the specified destination, put infinity in the metric
1315 field. Once all the entries have been filled in, change the
1316 command from Request to Response and send the datagram back
1317 to the requestor. */
1318 memset (&p
, 0, sizeof (struct prefix_ipv6
));
1319 p
.family
= AF_INET6
;
1321 for (; ((caddr_t
) rte
) < lim
; rte
++)
1323 p
.prefix
= rte
->addr
;
1324 p
.prefixlen
= rte
->prefixlen
;
1325 apply_mask_ipv6 (&p
);
1327 rp
= route_node_lookup (ripng
->table
, (struct prefix
*) &p
);
1332 rte
->metric
= rinfo
->metric
;
1333 route_unlock_node (rp
);
1336 rte
->metric
= RIPNG_METRIC_INFINITY
;
1338 packet
->command
= RIPNG_RESPONSE
;
1340 ripng_send_packet ((caddr_t
) packet
, size
, from
, ifp
);
1344 /* First entry point of reading RIPng packet. */
1346 ripng_read (struct thread
*thread
)
1350 struct sockaddr_in6 from
;
1351 struct ripng_packet
*packet
;
1352 unsigned int ifindex
;
1353 struct interface
*ifp
;
1356 /* Check ripng is active and alive. */
1357 assert (ripng
!= NULL
);
1358 assert (ripng
->sock
>= 0);
1360 /* Fetch thread data and set read pointer to empty for event
1361 managing. `sock' sould be same as ripng->sock. */
1362 sock
= THREAD_FD (thread
);
1363 ripng
->t_read
= NULL
;
1365 /* Add myself to the next event. */
1366 ripng_event (RIPNG_READ
, sock
);
1368 /* Read RIPng packet. */
1369 len
= ripng_recv_packet (sock
, STREAM_DATA (ripng
->ibuf
),
1370 STREAM_SIZE (ripng
->ibuf
), &from
, &ifindex
,
1374 zlog_warn ("RIPng recvfrom failed: %s.", strerror (errno
));
1378 /* Check RTE boundary. RTE size (Packet length - RIPng header size
1379 (4)) must be multiple size of one RTE size (20). */
1380 if (((len
- 4) % 20) != 0)
1382 zlog_warn ("RIPng invalid packet size %d from %s", len
,
1383 inet6_ntop (&from
.sin6_addr
));
1384 ripng_peer_bad_packet (&from
);
1388 packet
= (struct ripng_packet
*) STREAM_DATA (ripng
->ibuf
);
1389 ifp
= if_lookup_by_index (ifindex
);
1391 /* RIPng packet received. */
1392 if (IS_RIPNG_DEBUG_EVENT
)
1393 zlog_info ("RIPng packet received from %s port %d on %s",
1394 inet6_ntop (&from
.sin6_addr
), ntohs (from
.sin6_port
),
1395 ifp
? ifp
->name
: "unknown");
1397 /* Logging before packet checking. */
1398 if (IS_RIPNG_DEBUG_RECV
)
1399 ripng_packet_dump (packet
, len
, "RECV");
1401 /* Packet comes from unknown interface. */
1404 zlog_warn ("RIPng packet comes from unknown interface %d", ifindex
);
1408 /* Packet version mismatch checking. */
1409 if (packet
->version
!= ripng
->version
)
1411 zlog_warn ("RIPng packet version %d doesn't fit to my version %d",
1412 packet
->version
, ripng
->version
);
1413 ripng_peer_bad_packet (&from
);
1417 /* Process RIPng packet. */
1418 switch (packet
->command
)
1421 ripng_request_process (packet
, len
, &from
, ifp
);
1423 case RIPNG_RESPONSE
:
1424 ripng_response_process (packet
, len
, &from
, ifp
, hoplimit
);
1427 zlog_warn ("Invalid RIPng command %d", packet
->command
);
1428 ripng_peer_bad_packet (&from
);
1434 /* Walk down the RIPng routing table then clear changed flag. */
1436 ripng_clear_changed_flag ()
1438 struct route_node
*rp
;
1439 struct ripng_info
*rinfo
;
1441 for (rp
= route_top (ripng
->table
); rp
; rp
= route_next (rp
))
1442 if ((rinfo
= rp
->info
) != NULL
)
1443 if (rinfo
->flags
& RIPNG_RTF_CHANGED
)
1444 rinfo
->flags
&= ~RIPNG_RTF_CHANGED
;
1447 /* Regular update of RIPng route. Send all routing formation to RIPng
1448 enabled interface. */
1450 ripng_update (struct thread
*t
)
1453 struct interface
*ifp
;
1454 struct ripng_interface
*ri
;
1456 /* Clear update timer thread. */
1457 ripng
->t_update
= NULL
;
1459 /* Logging update event. */
1460 if (IS_RIPNG_DEBUG_EVENT
)
1461 zlog_info ("RIPng update timer expired!");
1463 /* Supply routes to each interface. */
1464 for (node
= listhead (iflist
); node
; nextnode (node
))
1466 ifp
= getdata (node
);
1469 if (if_is_loopback (ifp
) || ! if_is_up (ifp
))
1475 /* When passive interface is specified, suppress announce to the
1481 if (ri
->ri_send
== RIPNG_SEND_OFF
)
1483 if (IS_RIPNG_DEBUG_EVENT
)
1484 zlog (NULL
, LOG_INFO
,
1485 "[Event] RIPng send to if %d is suppressed by config",
1489 #endif /* RIPNG_ADVANCED */
1491 ripng_output_process (ifp
, NULL
, ripng_all_route
);
1494 /* Triggered updates may be suppressed if a regular update is due by
1495 the time the triggered update would be sent. */
1496 if (ripng
->t_triggered_interval
)
1498 thread_cancel (ripng
->t_triggered_interval
);
1499 ripng
->t_triggered_interval
= NULL
;
1503 /* Reset flush event. */
1504 ripng_event (RIPNG_UPDATE_EVENT
, 0);
1509 /* Triggered update interval timer. */
1511 ripng_triggered_interval (struct thread
*t
)
1513 ripng
->t_triggered_interval
= NULL
;
1518 ripng_triggered_update (t
);
1523 /* Execute triggered update. */
1525 ripng_triggered_update (struct thread
*t
)
1528 struct interface
*ifp
;
1529 struct ripng_interface
*ri
;
1532 ripng
->t_triggered_update
= NULL
;
1534 /* Cancel interval timer. */
1535 if (ripng
->t_triggered_interval
)
1537 thread_cancel (ripng
->t_triggered_interval
);
1538 ripng
->t_triggered_interval
= NULL
;
1542 /* Logging triggered update. */
1543 if (IS_RIPNG_DEBUG_EVENT
)
1544 zlog_info ("RIPng triggered update!");
1546 /* Split Horizon processing is done when generating triggered
1547 updates as well as normal updates (see section 2.6). */
1548 for (node
= listhead (iflist
); node
; nextnode (node
))
1550 ifp
= getdata (node
);
1553 if (if_is_loopback (ifp
) || ! if_is_up (ifp
))
1559 /* When passive interface is specified, suppress announce to the
1564 ripng_output_process (ifp
, NULL
, ripng_changed_route
);
1567 /* Once all of the triggered updates have been generated, the route
1568 change flags should be cleared. */
1569 ripng_clear_changed_flag ();
1571 /* After a triggered update is sent, a timer should be set for a
1572 random interval between 1 and 5 seconds. If other changes that
1573 would trigger updates occur before the timer expires, a single
1574 update is triggered when the timer expires. */
1575 interval
= (random () % 5) + 1;
1577 ripng
->t_triggered_interval
=
1578 thread_add_timer (master
, ripng_triggered_interval
, NULL
, interval
);
1583 /* Write routing table entry to the stream and return next index of
1584 the routing table entry in the stream. */
1586 ripng_write_rte (int num
, struct stream
*s
, struct prefix_ipv6
*p
,
1587 struct in6_addr
*nexthop
, u_int16_t tag
, u_char metric
)
1589 /* RIPng packet header. */
1592 stream_putc (s
, RIPNG_RESPONSE
);
1593 stream_putc (s
, RIPNG_V1
);
1597 /* Write routing table entry. */
1599 stream_write (s
, (caddr_t
) &p
->prefix
, sizeof (struct in6_addr
));
1601 stream_write (s
, (caddr_t
) nexthop
, sizeof (struct in6_addr
));
1602 stream_putw (s
, tag
);
1604 stream_putc (s
, p
->prefixlen
);
1607 stream_putc (s
, metric
);
1612 /* Send RESPONSE message to specified destination. */
1614 ripng_output_process (struct interface
*ifp
, struct sockaddr_in6
*to
,
1618 struct route_node
*rp
;
1619 struct ripng_info
*rinfo
;
1620 struct ripng_interface
*ri
;
1621 struct ripng_aggregate
*aggregate
;
1622 struct prefix_ipv6
*p
;
1623 struct list
* ripng_rte_list
;
1625 if (IS_RIPNG_DEBUG_EVENT
) {
1627 zlog_info ("RIPng update routes to neighbor %s",
1628 inet6_ntop(&to
->sin6_addr
));
1630 zlog_info ("RIPng update routes on interface %s", ifp
->name
);
1633 /* Get RIPng interface. */
1636 ripng_rte_list
= ripng_rte_new();
1638 for (rp
= route_top (ripng
->table
); rp
; rp
= route_next (rp
))
1640 if ((rinfo
= rp
->info
) != NULL
&& rinfo
->suppress
== 0)
1642 /* If no route-map are applied, the RTE will be these following
1645 p
= (struct prefix_ipv6
*) &rp
->p
;
1646 rinfo
->metric_out
= rinfo
->metric
;
1647 rinfo
->tag_out
= rinfo
->tag
;
1648 memset(&rinfo
->nexthop_out
, 0, sizeof(rinfo
->nexthop_out
));
1649 /* In order to avoid some local loops,
1650 * if the RIPng route has a nexthop via this interface, keep the nexthop,
1651 * otherwise set it to 0. The nexthop should not be propagated
1652 * beyond the local broadcast/multicast area in order
1653 * to avoid an IGP multi-level recursive look-up.
1655 if (rinfo
->ifindex
== ifp
->ifindex
)
1656 rinfo
->nexthop_out
= rinfo
->nexthop
;
1658 /* Apply output filters. */
1659 ret
= ripng_outgoing_filter (p
, ri
);
1663 /* Changed route only output. */
1664 if (route_type
== ripng_changed_route
&&
1665 (! (rinfo
->flags
& RIPNG_RTF_CHANGED
)))
1668 /* Split horizon. */
1669 if (ri
->split_horizon
== RIPNG_SPLIT_HORIZON
)
1671 /* We perform split horizon for RIPng routes. */
1672 if ((rinfo
->type
== ZEBRA_ROUTE_RIPNG
) &&
1673 rinfo
->ifindex
== ifp
->ifindex
)
1677 /* Preparation for route-map. */
1678 rinfo
->metric_set
= 0;
1681 * and tag_out are already initialized.
1684 /* Interface route-map */
1685 if (ri
->routemap
[RIPNG_FILTER_OUT
])
1689 ret
= route_map_apply (ri
->routemap
[RIPNG_FILTER_OUT
],
1690 (struct prefix
*) p
, RMAP_RIPNG
,
1693 if (ret
== RMAP_DENYMATCH
)
1695 if (IS_RIPNG_DEBUG_PACKET
)
1696 zlog_info ("RIPng %s/%d is filtered by route-map out",
1697 inet6_ntop (&p
->prefix
), p
->prefixlen
);
1703 /* Redistribute route-map. */
1704 if (ripng
->route_map
[rinfo
->type
].name
)
1708 ret
= route_map_apply (ripng
->route_map
[rinfo
->type
].map
,
1709 (struct prefix
*) p
, RMAP_RIPNG
,
1712 if (ret
== RMAP_DENYMATCH
)
1714 if (IS_RIPNG_DEBUG_PACKET
)
1715 zlog_info ("RIPng %s/%d is filtered by route-map",
1716 inet6_ntop (&p
->prefix
), p
->prefixlen
);
1721 /* When the route-map does not set metric. */
1722 if (! rinfo
->metric_set
)
1724 /* If the redistribute metric is set. */
1725 if (ripng
->route_map
[rinfo
->type
].metric_config
1726 && rinfo
->metric
!= RIPNG_METRIC_INFINITY
)
1728 rinfo
->metric_out
= ripng
->route_map
[rinfo
->type
].metric
;
1732 /* If the route is not connected or localy generated
1733 one, use default-metric value */
1734 if (rinfo
->type
!= ZEBRA_ROUTE_RIPNG
1735 && rinfo
->type
!= ZEBRA_ROUTE_CONNECT
1736 && rinfo
->metric
!= RIPNG_METRIC_INFINITY
)
1737 rinfo
->metric_out
= ripng
->default_metric
;
1741 /* Apply offset-list */
1742 if (rinfo
->metric_out
!= RIPNG_METRIC_INFINITY
)
1743 ripng_offset_list_apply_out (p
, ifp
, &rinfo
->metric_out
);
1745 if (rinfo
->metric_out
> RIPNG_METRIC_INFINITY
)
1746 rinfo
->metric_out
= RIPNG_METRIC_INFINITY
;
1748 /* Perform split-horizon with poisoned reverse
1751 if (ri
->split_horizon
== RIPNG_SPLIT_HORIZON_POISONED_REVERSE
) {
1752 if ((rinfo
->type
== ZEBRA_ROUTE_RIPNG
) &&
1753 rinfo
->ifindex
== ifp
->ifindex
)
1754 rinfo
->metric_out
= RIPNG_METRIC_INFINITY
;
1757 /* Add RTE to the list */
1758 ripng_rte_add(ripng_rte_list
, p
, rinfo
, NULL
);
1761 /* Process the aggregated RTE entry */
1762 if ((aggregate
= rp
->aggregate
) != NULL
&&
1763 aggregate
->count
> 0 &&
1764 aggregate
->suppress
== 0)
1766 /* If no route-map are applied, the RTE will be these following
1769 p
= (struct prefix_ipv6
*) &rp
->p
;
1770 aggregate
->metric_set
= 0;
1771 aggregate
->metric_out
= aggregate
->metric
;
1772 aggregate
->tag_out
= aggregate
->tag
;
1773 memset(&aggregate
->nexthop_out
, 0, sizeof(aggregate
->nexthop_out
));
1775 /* Apply output filters.*/
1776 ret
= ripng_outgoing_filter (p
, ri
);
1780 /* Interface route-map */
1781 if (ri
->routemap
[RIPNG_FILTER_OUT
])
1784 struct ripng_info newinfo
;
1786 /* let's cast the aggregate structure to ripng_info */
1787 memset (&newinfo
, 0, sizeof (struct ripng_info
));
1788 /* the nexthop is :: */
1789 newinfo
.metric
= aggregate
->metric
;
1790 newinfo
.metric_out
= aggregate
->metric_out
;
1791 newinfo
.tag
= aggregate
->tag
;
1792 newinfo
.tag_out
= aggregate
->tag_out
;
1794 ret
= route_map_apply (ri
->routemap
[RIPNG_FILTER_OUT
],
1795 (struct prefix
*) p
, RMAP_RIPNG
,
1798 if (ret
== RMAP_DENYMATCH
)
1800 if (IS_RIPNG_DEBUG_PACKET
)
1801 zlog_info ("RIPng %s/%d is filtered by route-map out",
1802 inet6_ntop (&p
->prefix
), p
->prefixlen
);
1806 aggregate
->metric_out
= newinfo
.metric_out
;
1807 aggregate
->tag_out
= newinfo
.tag_out
;
1808 if (IN6_IS_ADDR_LINKLOCAL(&newinfo
.nexthop_out
))
1809 aggregate
->nexthop_out
= newinfo
.nexthop_out
;
1812 /* There is no redistribute routemap for the aggregated RTE */
1814 /* Changed route only output. */
1815 /* XXX, vincent, in order to increase time convergence,
1816 * it should be announced if a child has changed.
1818 if (route_type
== ripng_changed_route
)
1821 /* Apply offset-list */
1822 if (aggregate
->metric_out
!= RIPNG_METRIC_INFINITY
)
1823 ripng_offset_list_apply_out (p
, ifp
, &aggregate
->metric_out
);
1825 if (aggregate
->metric_out
> RIPNG_METRIC_INFINITY
)
1826 aggregate
->metric_out
= RIPNG_METRIC_INFINITY
;
1828 /* Add RTE to the list */
1829 ripng_rte_add(ripng_rte_list
, p
, NULL
, aggregate
);
1834 /* Flush the list */
1835 ripng_rte_send(ripng_rte_list
, ifp
, to
);
1836 ripng_rte_free(ripng_rte_list
);
1839 /* Create new RIPng instance and set it to global variable. */
1843 /* ripng should be NULL. */
1844 assert (ripng
== NULL
);
1846 /* Allocaste RIPng instance. */
1847 ripng
= XMALLOC (MTYPE_RIPNG
, sizeof (struct ripng
));
1848 memset (ripng
, 0, sizeof (struct ripng
));
1850 /* Default version and timer values. */
1851 ripng
->version
= RIPNG_V1
;
1852 ripng
->update_time
= RIPNG_UPDATE_TIMER_DEFAULT
;
1853 ripng
->timeout_time
= RIPNG_TIMEOUT_TIMER_DEFAULT
;
1854 ripng
->garbage_time
= RIPNG_GARBAGE_TIMER_DEFAULT
;
1855 ripng
->default_metric
= RIPNG_DEFAULT_METRIC_DEFAULT
;
1858 ripng
->ibuf
= stream_new (RIPNG_MAX_PACKET_SIZE
* 5);
1859 ripng
->obuf
= stream_new (RIPNG_MAX_PACKET_SIZE
);
1861 /* Initialize RIPng routig table. */
1862 ripng
->table
= route_table_init ();
1863 ripng
->route
= route_table_init ();
1864 ripng
->aggregate
= route_table_init ();
1867 ripng
->sock
= ripng_make_socket ();
1868 if (ripng
->sock
< 0)
1872 ripng_event (RIPNG_READ
, ripng
->sock
);
1873 ripng_event (RIPNG_UPDATE_EVENT
, 1);
1878 /* Send RIPng request to the interface. */
1880 ripng_request (struct interface
*ifp
)
1883 struct ripng_packet ripng_packet
;
1885 /* In default ripd doesn't send RIP_REQUEST to the loopback interface. */
1886 if (if_is_loopback(ifp
))
1889 /* If interface is down, don't send RIP packet. */
1890 if (! if_is_up (ifp
))
1893 if (IS_RIPNG_DEBUG_EVENT
)
1894 zlog_info ("RIPng send request to %s", ifp
->name
);
1896 memset (&ripng_packet
, 0, sizeof (ripng_packet
));
1897 ripng_packet
.command
= RIPNG_REQUEST
;
1898 ripng_packet
.version
= RIPNG_V1
;
1899 rte
= ripng_packet
.rte
;
1900 rte
->metric
= RIPNG_METRIC_INFINITY
;
1902 return ripng_send_packet ((caddr_t
) &ripng_packet
, sizeof (ripng_packet
),
1908 ripng_update_jitter (int time
)
1910 return ((rand () % (time
+ 1)) - (time
/ 2));
1914 ripng_event (enum ripng_event event
, int sock
)
1922 ripng
->t_read
= thread_add_read (master
, ripng_read
, NULL
, sock
);
1924 case RIPNG_UPDATE_EVENT
:
1925 if (ripng
->t_update
)
1927 thread_cancel (ripng
->t_update
);
1928 ripng
->t_update
= NULL
;
1930 /* Update timer jitter. */
1931 jitter
= ripng_update_jitter (ripng
->update_time
);
1934 thread_add_timer (master
, ripng_update
, NULL
,
1935 sock
? 2 : ripng
->update_time
+ jitter
);
1937 case RIPNG_TRIGGERED_UPDATE
:
1938 if (ripng
->t_triggered_interval
)
1940 else if (! ripng
->t_triggered_update
)
1941 ripng
->t_triggered_update
=
1942 thread_add_event (master
, ripng_triggered_update
, NULL
, 0);
1949 /* Each route type's strings and default preference. */
1958 { ZEBRA_ROUTE_SYSTEM
, "X", "system", 10},
1959 { ZEBRA_ROUTE_KERNEL
, "K", "kernel", 20},
1960 { ZEBRA_ROUTE_CONNECT
, "C", "connected", 30},
1961 { ZEBRA_ROUTE_STATIC
, "S", "static", 40},
1962 { ZEBRA_ROUTE_RIP
, "R", "rip", 50},
1963 { ZEBRA_ROUTE_RIPNG
, "R", "ripng", 50},
1964 { ZEBRA_ROUTE_OSPF
, "O", "ospf", 60},
1965 { ZEBRA_ROUTE_OSPF6
, "O", "ospf6", 60},
1966 { ZEBRA_ROUTE_BGP
, "B", "bgp", 70},
1969 /* Print out routes update time. */
1971 ripng_vty_out_uptime (struct vty
*vty
, struct ripng_info
*rinfo
)
1973 struct timeval timer_now
;
1977 char timebuf
[TIME_BUF
];
1978 struct thread
*thread
;
1980 gettimeofday (&timer_now
, NULL
);
1982 if ((thread
= rinfo
->t_timeout
) != NULL
)
1984 clock
= thread
->u
.sands
.tv_sec
- timer_now
.tv_sec
;
1985 tm
= gmtime (&clock
);
1986 strftime (timebuf
, TIME_BUF
, "%M:%S", tm
);
1987 vty_out (vty
, "%5s", timebuf
);
1989 else if ((thread
= rinfo
->t_garbage_collect
) != NULL
)
1991 clock
= thread
->u
.sands
.tv_sec
- timer_now
.tv_sec
;
1992 tm
= gmtime (&clock
);
1993 strftime (timebuf
, TIME_BUF
, "%M:%S", tm
);
1994 vty_out (vty
, "%5s", timebuf
);
1999 ripng_route_subtype_print (struct ripng_info
*rinfo
)
2004 if (rinfo
->suppress
)
2007 switch (rinfo
->sub_type
)
2009 case RIPNG_ROUTE_RTE
:
2012 case RIPNG_ROUTE_STATIC
:
2015 case RIPNG_ROUTE_DEFAULT
:
2018 case RIPNG_ROUTE_REDISTRIBUTE
:
2021 case RIPNG_ROUTE_INTERFACE
:
2032 DEFUN (show_ipv6_ripng
,
2033 show_ipv6_ripng_cmd
,
2037 "Show RIPng routes\n")
2039 struct route_node
*rp
;
2040 struct ripng_info
*rinfo
;
2041 struct ripng_aggregate
*aggregate
;
2042 struct prefix_ipv6
*p
;
2048 /* Header of display. */
2049 vty_out (vty
, "Codes: R - RIPng, C - connected, S - Static, O - OSPF, B - BGP%s"
2051 " (n) - normal, (s) - static, (d) - default, (r) - redistribute,%s"
2052 " (i) - interface, (a/S) - aggregated/Suppressed%s%s"
2053 " Network Next Hop Via Metric Tag Time%s",
2054 VTY_NEWLINE
, VTY_NEWLINE
, VTY_NEWLINE
,
2055 VTY_NEWLINE
, VTY_NEWLINE
, VTY_NEWLINE
);
2057 for (rp
= route_top (ripng
->table
); rp
; rp
= route_next (rp
))
2059 if ((aggregate
= rp
->aggregate
) != NULL
)
2061 p
= (struct prefix_ipv6
*) &rp
->p
;
2064 len
= vty_out (vty
, "R(a) %d/%d %s/%d ",
2065 aggregate
->count
, aggregate
->suppress
,
2066 inet6_ntop (&p
->prefix
), p
->prefixlen
);
2068 len
= vty_out (vty
, "R(a) %s/%d ",
2069 inet6_ntop (&p
->prefix
), p
->prefixlen
);
2071 vty_out (vty
, "%s", VTY_NEWLINE
);
2072 vty_out (vty
, "%*s", 18, " ");
2074 vty_out (vty
, "%*s", 28, " ");
2075 vty_out (vty
, "self %2d %3d%s", aggregate
->metric
,
2080 if ((rinfo
= rp
->info
) != NULL
)
2082 p
= (struct prefix_ipv6
*) &rp
->p
;
2085 len
= vty_out (vty
, "%s(%s) 0/%d %s/%d ",
2086 route_info
[rinfo
->type
].str
,
2087 ripng_route_subtype_print(rinfo
),
2089 inet6_ntop (&p
->prefix
), p
->prefixlen
);
2091 len
= vty_out (vty
, "%s(%s) %s/%d ",
2092 route_info
[rinfo
->type
].str
,
2093 ripng_route_subtype_print(rinfo
),
2094 inet6_ntop (&p
->prefix
), p
->prefixlen
);
2096 vty_out (vty
, "%s", VTY_NEWLINE
);
2097 vty_out (vty
, "%*s", 18, " ");
2098 len
= vty_out (vty
, "%s", inet6_ntop (&rinfo
->nexthop
));
2102 len
= vty_out (vty
, "%*s", len
, " ");
2105 if ((rinfo
->type
== ZEBRA_ROUTE_RIPNG
) &&
2106 (rinfo
->sub_type
== RIPNG_ROUTE_RTE
))
2108 len
= vty_out (vty
, "%s", ifindex2ifname(rinfo
->ifindex
));
2109 } else if (rinfo
->metric
== RIPNG_METRIC_INFINITY
)
2111 len
= vty_out (vty
, "kill");
2113 len
= vty_out (vty
, "self");
2117 vty_out (vty
, "%*s", len
, " ");
2119 vty_out (vty
, " %2d %3d ",
2120 rinfo
->metric
, rinfo
->tag
);
2123 if ((rinfo
->type
== ZEBRA_ROUTE_RIPNG
) &&
2124 (rinfo
->sub_type
== RIPNG_ROUTE_RTE
))
2126 /* RTE from remote RIP routers */
2127 ripng_vty_out_uptime (vty
, rinfo
);
2128 } else if (rinfo
->metric
== RIPNG_METRIC_INFINITY
)
2130 /* poisonous reversed routes (gc) */
2131 ripng_vty_out_uptime (vty
, rinfo
);
2134 vty_out (vty
, "%s", VTY_NEWLINE
);
2141 /* Return next event time. */
2143 ripng_next_thread_timer (struct thread
*thread
)
2145 struct timeval timer_now
;
2147 gettimeofday (&timer_now
, NULL
);
2149 return thread
->u
.sands
.tv_sec
- timer_now
.tv_sec
;
2152 DEFUN (show_ipv6_ripng_status
,
2153 show_ipv6_ripng_status_cmd
,
2154 "show ipv6 ripng status",
2157 "Show RIPng routes\n"
2158 "IPv6 routing protocol process parameters and statistics\n")
2161 int ripng_network_write (struct vty
*, int);
2162 void ripng_redistribute_write (struct vty
*, int);
2167 vty_out (vty
, "Routing Protocol is \"RIPng\"%s", VTY_NEWLINE
);
2168 vty_out (vty
, " Sending updates every %ld seconds with +/-50%%,",
2169 ripng
->update_time
);
2170 vty_out (vty
, " next due in %d seconds%s",
2171 ripng_next_thread_timer (ripng
->t_update
),
2173 vty_out (vty
, " Timeout after %ld seconds,", ripng
->timeout_time
);
2174 vty_out (vty
, " garbage collect after %ld seconds%s", ripng
->garbage_time
,
2177 /* Filtering status show. */
2178 config_show_distribute (vty
);
2180 /* Default metric information. */
2181 vty_out (vty
, " Default redistribution metric is %d%s",
2182 ripng
->default_metric
, VTY_NEWLINE
);
2184 /* Redistribute information. */
2185 vty_out (vty
, " Redistributing:");
2186 ripng_redistribute_write (vty
, 0);
2187 vty_out (vty
, "%s", VTY_NEWLINE
);
2189 vty_out (vty
, " Default version control: send version %d,", ripng
->version
);
2190 vty_out (vty
, " receive version %d %s", ripng
->version
,
2193 vty_out (vty
, " Interface Send Recv%s", VTY_NEWLINE
);
2195 for (node
= listhead (iflist
); node
; node
= nextnode (node
))
2197 struct ripng_interface
*ri
;
2198 struct interface
*ifp
;
2200 ifp
= getdata (node
);
2203 if (ri
->enable_network
|| ri
->enable_interface
)
2206 vty_out (vty
, " %-17s%-3d %-3d%s", ifp
->name
,
2213 vty_out (vty
, " Routing for Networks:%s", VTY_NEWLINE
);
2214 ripng_network_write (vty
, 0);
2216 vty_out (vty
, " Routing Information Sources:%s", VTY_NEWLINE
);
2217 vty_out (vty
, " Gateway BadPackets BadRoutes Distance Last Update%s", VTY_NEWLINE
);
2218 ripng_peer_display (vty
);
2223 DEFUN (router_ripng
,
2226 "Enable a routing process\n"
2227 "Make RIPng instance command\n")
2231 vty
->node
= RIPNG_NODE
;
2235 ret
= ripng_create ();
2237 /* Notice to user we couldn't create RIPng. */
2240 zlog_warn ("can't create RIPng");
2248 DEFUN (no_router_ripng
,
2249 no_router_ripng_cmd
,
2252 "Enable a routing process\n"
2253 "Make RIPng instance command\n")
2263 "Static route setup\n"
2264 "Set static RIPng route announcement\n")
2267 struct prefix_ipv6 p
;
2268 struct route_node
*rp
;
2270 ret
= str2prefix_ipv6 (argv
[0], (struct prefix_ipv6
*)&p
);
2273 vty_out (vty
, "Malformed address%s", VTY_NEWLINE
);
2276 apply_mask_ipv6 (&p
);
2278 rp
= route_node_get (ripng
->route
, (struct prefix
*) &p
);
2281 vty_out (vty
, "There is already same static route.%s", VTY_NEWLINE
);
2282 route_unlock_node (rp
);
2285 rp
->info
= (void *)1;
2287 ripng_redistribute_add (ZEBRA_ROUTE_RIPNG
, RIPNG_ROUTE_STATIC
, &p
, 0, NULL
);
2292 DEFUN (no_ripng_route
,
2294 "no route IPV6ADDR",
2296 "Static route setup\n"
2297 "Delete static RIPng route announcement\n")
2300 struct prefix_ipv6 p
;
2301 struct route_node
*rp
;
2303 ret
= str2prefix_ipv6 (argv
[0], (struct prefix_ipv6
*)&p
);
2306 vty_out (vty
, "Malformed address%s", VTY_NEWLINE
);
2309 apply_mask_ipv6 (&p
);
2311 rp
= route_node_lookup (ripng
->route
, (struct prefix
*) &p
);
2314 vty_out (vty
, "Can't find static route.%s", VTY_NEWLINE
);
2318 ripng_redistribute_delete (ZEBRA_ROUTE_RIPNG
, RIPNG_ROUTE_STATIC
, &p
, 0);
2319 route_unlock_node (rp
);
2322 route_unlock_node (rp
);
2327 DEFUN (ripng_aggregate_address
,
2328 ripng_aggregate_address_cmd
,
2329 "aggregate-address X:X::X:X/M",
2330 "Set aggregate RIPng route announcement\n"
2331 "Aggregate network\n")
2335 struct route_node
*node
;
2337 ret
= str2prefix_ipv6 (argv
[0], (struct prefix_ipv6
*)&p
);
2340 vty_out (vty
, "Malformed address%s", VTY_NEWLINE
);
2344 /* Check aggregate alredy exist or not. */
2345 node
= route_node_get (ripng
->aggregate
, &p
);
2348 vty_out (vty
, "There is already same aggregate route.%s", VTY_NEWLINE
);
2349 route_unlock_node (node
);
2352 node
->info
= (void *)1;
2354 ripng_aggregate_add (&p
);
2359 DEFUN (no_ripng_aggregate_address
,
2360 no_ripng_aggregate_address_cmd
,
2361 "no aggregate-address X:X::X:X/M",
2363 "Delete aggregate RIPng route announcement\n"
2364 "Aggregate network")
2368 struct route_node
*rn
;
2370 ret
= str2prefix_ipv6 (argv
[0], (struct prefix_ipv6
*) &p
);
2373 vty_out (vty
, "Malformed address%s", VTY_NEWLINE
);
2377 rn
= route_node_lookup (ripng
->aggregate
, &p
);
2380 vty_out (vty
, "Can't find aggregate route.%s", VTY_NEWLINE
);
2383 route_unlock_node (rn
);
2385 route_unlock_node (rn
);
2387 ripng_aggregate_delete (&p
);
2392 DEFUN (ripng_default_metric
,
2393 ripng_default_metric_cmd
,
2394 "default-metric <1-16>",
2395 "Set a metric of redistribute routes\n"
2400 ripng
->default_metric
= atoi (argv
[0]);
2405 DEFUN (no_ripng_default_metric
,
2406 no_ripng_default_metric_cmd
,
2407 "no default-metric",
2409 "Set a metric of redistribute routes\n"
2414 ripng
->default_metric
= RIPNG_DEFAULT_METRIC_DEFAULT
;
2419 ALIAS (no_ripng_default_metric
,
2420 no_ripng_default_metric_val_cmd
,
2421 "no default-metric <1-16>",
2423 "Set a metric of redistribute routes\n"
2427 /* RIPng update timer setup. */
2428 DEFUN (ripng_update_timer
,
2429 ripng_update_timer_cmd
,
2430 "update-timer SECOND",
2431 "Set RIPng update timer in seconds\n"
2434 unsigned long update
;
2435 char *endptr
= NULL
;
2437 update
= strtoul (argv
[0], &endptr
, 10);
2438 if (update
== ULONG_MAX
|| *endptr
!= '\0')
2440 vty_out (vty
, "update timer value error%s", VTY_NEWLINE
);
2444 ripng
->update_time
= update
;
2446 ripng_event (RIPNG_UPDATE_EVENT
, 0);
2450 DEFUN (no_ripng_update_timer
,
2451 no_ripng_update_timer_cmd
,
2452 "no update-timer SECOND",
2454 "Unset RIPng update timer in seconds\n"
2457 ripng
->update_time
= RIPNG_UPDATE_TIMER_DEFAULT
;
2458 ripng_event (RIPNG_UPDATE_EVENT
, 0);
2462 /* RIPng timeout timer setup. */
2463 DEFUN (ripng_timeout_timer
,
2464 ripng_timeout_timer_cmd
,
2465 "timeout-timer SECOND",
2466 "Set RIPng timeout timer in seconds\n"
2469 unsigned long timeout
;
2470 char *endptr
= NULL
;
2472 timeout
= strtoul (argv
[0], &endptr
, 10);
2473 if (timeout
== ULONG_MAX
|| *endptr
!= '\0')
2475 vty_out (vty
, "timeout timer value error%s", VTY_NEWLINE
);
2479 ripng
->timeout_time
= timeout
;
2484 DEFUN (no_ripng_timeout_timer
,
2485 no_ripng_timeout_timer_cmd
,
2486 "no timeout-timer SECOND",
2488 "Unset RIPng timeout timer in seconds\n"
2491 ripng
->timeout_time
= RIPNG_TIMEOUT_TIMER_DEFAULT
;
2495 /* RIPng garbage timer setup. */
2496 DEFUN (ripng_garbage_timer
,
2497 ripng_garbage_timer_cmd
,
2498 "garbage-timer SECOND",
2499 "Set RIPng garbage timer in seconds\n"
2502 unsigned long garbage
;
2503 char *endptr
= NULL
;
2505 garbage
= strtoul (argv
[0], &endptr
, 10);
2506 if (garbage
== ULONG_MAX
|| *endptr
!= '\0')
2508 vty_out (vty
, "garbage timer value error%s", VTY_NEWLINE
);
2512 ripng
->garbage_time
= garbage
;
2517 DEFUN (no_ripng_garbage_timer
,
2518 no_ripng_garbage_timer_cmd
,
2519 "no garbage-timer SECOND",
2521 "Unset RIPng garbage timer in seconds\n"
2524 ripng
->garbage_time
= RIPNG_GARBAGE_TIMER_DEFAULT
;
2529 DEFUN (ripng_timers
,
2531 "timers basic <0-65535> <0-65535> <0-65535>",
2532 "RIPng timers setup\n"
2534 "Routing table update timer value in second. Default is 30.\n"
2535 "Routing information timeout timer. Default is 180.\n"
2536 "Garbage collection timer. Default is 120.\n")
2538 unsigned long update
;
2539 unsigned long timeout
;
2540 unsigned long garbage
;
2541 char *endptr
= NULL
;
2543 update
= strtoul (argv
[0], &endptr
, 10);
2544 if (update
== ULONG_MAX
|| *endptr
!= '\0')
2546 vty_out (vty
, "update timer value error%s", VTY_NEWLINE
);
2550 timeout
= strtoul (argv
[1], &endptr
, 10);
2551 if (timeout
== ULONG_MAX
|| *endptr
!= '\0')
2553 vty_out (vty
, "timeout timer value error%s", VTY_NEWLINE
);
2557 garbage
= strtoul (argv
[2], &endptr
, 10);
2558 if (garbage
== ULONG_MAX
|| *endptr
!= '\0')
2560 vty_out (vty
, "garbage timer value error%s", VTY_NEWLINE
);
2564 /* Set each timer value. */
2565 ripng
->update_time
= update
;
2566 ripng
->timeout_time
= timeout
;
2567 ripng
->garbage_time
= garbage
;
2569 /* Reset update timer thread. */
2570 ripng_event (RIPNG_UPDATE_EVENT
, 0);
2575 DEFUN (no_ripng_timers
,
2576 no_ripng_timers_cmd
,
2579 "RIPng timers setup\n"
2582 /* Set each timer value to the default. */
2583 ripng
->update_time
= RIPNG_UPDATE_TIMER_DEFAULT
;
2584 ripng
->timeout_time
= RIPNG_TIMEOUT_TIMER_DEFAULT
;
2585 ripng
->garbage_time
= RIPNG_GARBAGE_TIMER_DEFAULT
;
2587 /* Reset update timer thread. */
2588 ripng_event (RIPNG_UPDATE_EVENT
, 0);
2593 ALIAS (no_ripng_timers
,
2594 no_ripng_timers_val_cmd
,
2595 "no timers basic <0-65535> <0-65535> <0-65535>",
2597 "RIPng timers setup\n"
2599 "Routing table update timer value in second. Default is 30.\n"
2600 "Routing information timeout timer. Default is 180.\n"
2601 "Garbage collection timer. Default is 120.\n")
2603 DEFUN (show_ipv6_protocols
, show_ipv6_protocols_cmd
,
2604 "show ipv6 protocols",
2607 "Routing protocol information")
2612 vty_out (vty
, "Routing Protocol is \"ripng\"%s", VTY_NEWLINE
);
2614 vty_out (vty
, "Sending updates every %ld seconds, next due in %d seconds%s",
2615 ripng
->update_time
, 0,
2618 vty_out (vty
, "Timerout after %ld seconds, garbage correct %ld%s",
2619 ripng
->timeout_time
,
2620 ripng
->garbage_time
,
2623 vty_out (vty
, "Outgoing update filter list for all interfaces is not set");
2624 vty_out (vty
, "Incoming update filter list for all interfaces is not set");
2629 /* Please be carefull to use this command. */
2630 DEFUN (ripng_default_information_originate
,
2631 ripng_default_information_originate_cmd
,
2632 "default-information originate",
2633 "Default route information\n"
2634 "Distribute default route\n")
2636 struct prefix_ipv6 p
;
2638 if (! ripng
->default_information
) {
2639 ripng
->default_information
= 1;
2641 str2prefix_ipv6 ("::/0", &p
);
2642 ripng_redistribute_add (ZEBRA_ROUTE_RIPNG
, RIPNG_ROUTE_DEFAULT
, &p
, 0, NULL
);
2648 DEFUN (no_ripng_default_information_originate
,
2649 no_ripng_default_information_originate_cmd
,
2650 "no default-information originate",
2652 "Default route information\n"
2653 "Distribute default route\n")
2655 struct prefix_ipv6 p
;
2657 if (ripng
->default_information
) {
2658 ripng
->default_information
= 0;
2660 str2prefix_ipv6 ("::/0", &p
);
2661 ripng_redistribute_delete (ZEBRA_ROUTE_RIPNG
, RIPNG_ROUTE_DEFAULT
, &p
, 0);
2667 /* RIPng configuration write function. */
2669 ripng_config_write (struct vty
*vty
)
2671 int ripng_network_write (struct vty
*, int);
2672 void ripng_redistribute_write (struct vty
*, int);
2674 struct route_node
*rp
;
2680 vty_out (vty
, "router ripng%s", VTY_NEWLINE
);
2682 if (ripng
->default_information
)
2683 vty_out (vty
, " default-information originate%s", VTY_NEWLINE
);
2685 ripng_network_write (vty
, 1);
2687 /* RIPng default metric configuration */
2688 if (ripng
->default_metric
!= RIPNG_DEFAULT_METRIC_DEFAULT
)
2689 vty_out (vty
, " default-metric %d%s",
2690 ripng
->default_metric
, VTY_NEWLINE
);
2692 ripng_redistribute_write (vty
, 1);
2694 /* RIP offset-list configuration. */
2695 config_write_ripng_offset_list (vty
);
2697 /* RIPng aggregate routes. */
2698 for (rp
= route_top (ripng
->aggregate
); rp
; rp
= route_next (rp
))
2699 if (rp
->info
!= NULL
)
2700 vty_out (vty
, " aggregate-address %s/%d%s",
2701 inet6_ntop (&rp
->p
.u
.prefix6
),
2706 /* RIPng static routes. */
2707 for (rp
= route_top (ripng
->route
); rp
; rp
= route_next (rp
))
2708 if (rp
->info
!= NULL
)
2709 vty_out (vty
, " route %s/%d%s", inet6_ntop (&rp
->p
.u
.prefix6
),
2713 /* RIPng timers configuration. */
2714 if (ripng
->update_time
!= RIPNG_UPDATE_TIMER_DEFAULT
||
2715 ripng
->timeout_time
!= RIPNG_TIMEOUT_TIMER_DEFAULT
||
2716 ripng
->garbage_time
!= RIPNG_GARBAGE_TIMER_DEFAULT
)
2718 vty_out (vty
, " timers basic %ld %ld %ld%s",
2720 ripng
->timeout_time
,
2721 ripng
->garbage_time
,
2725 if (ripng
->update_time
!= RIPNG_UPDATE_TIMER_DEFAULT
)
2726 vty_out (vty
, " update-timer %d%s", ripng
->update_time
,
2728 if (ripng
->timeout_time
!= RIPNG_TIMEOUT_TIMER_DEFAULT
)
2729 vty_out (vty
, " timeout-timer %d%s", ripng
->timeout_time
,
2731 if (ripng
->garbage_time
!= RIPNG_GARBAGE_TIMER_DEFAULT
)
2732 vty_out (vty
, " garbage-timer %d%s", ripng
->garbage_time
,
2736 write
+= config_write_distribute (vty
);
2738 write
+= config_write_if_rmap (vty
);
2745 /* RIPng node structure. */
2746 struct cmd_node cmd_ripng_node
=
2749 "%s(config-router)# ",
2754 ripng_distribute_update (struct distribute
*dist
)
2756 struct interface
*ifp
;
2757 struct ripng_interface
*ri
;
2758 struct access_list
*alist
;
2759 struct prefix_list
*plist
;
2764 ifp
= if_lookup_by_name (dist
->ifname
);
2770 if (dist
->list
[DISTRIBUTE_IN
])
2772 alist
= access_list_lookup (AFI_IP6
, dist
->list
[DISTRIBUTE_IN
]);
2774 ri
->list
[RIPNG_FILTER_IN
] = alist
;
2776 ri
->list
[RIPNG_FILTER_IN
] = NULL
;
2779 ri
->list
[RIPNG_FILTER_IN
] = NULL
;
2781 if (dist
->list
[DISTRIBUTE_OUT
])
2783 alist
= access_list_lookup (AFI_IP6
, dist
->list
[DISTRIBUTE_OUT
]);
2785 ri
->list
[RIPNG_FILTER_OUT
] = alist
;
2787 ri
->list
[RIPNG_FILTER_OUT
] = NULL
;
2790 ri
->list
[RIPNG_FILTER_OUT
] = NULL
;
2792 if (dist
->prefix
[DISTRIBUTE_IN
])
2794 plist
= prefix_list_lookup (AFI_IP6
, dist
->prefix
[DISTRIBUTE_IN
]);
2796 ri
->prefix
[RIPNG_FILTER_IN
] = plist
;
2798 ri
->prefix
[RIPNG_FILTER_IN
] = NULL
;
2801 ri
->prefix
[RIPNG_FILTER_IN
] = NULL
;
2803 if (dist
->prefix
[DISTRIBUTE_OUT
])
2805 plist
= prefix_list_lookup (AFI_IP6
, dist
->prefix
[DISTRIBUTE_OUT
]);
2807 ri
->prefix
[RIPNG_FILTER_OUT
] = plist
;
2809 ri
->prefix
[RIPNG_FILTER_OUT
] = NULL
;
2812 ri
->prefix
[RIPNG_FILTER_OUT
] = NULL
;
2816 ripng_distribute_update_interface (struct interface
*ifp
)
2818 struct distribute
*dist
;
2820 dist
= distribute_lookup (ifp
->name
);
2822 ripng_distribute_update (dist
);
2825 /* Update all interface's distribute list. */
2827 ripng_distribute_update_all ()
2829 struct interface
*ifp
;
2832 for (node
= listhead (iflist
); node
; nextnode (node
))
2834 ifp
= getdata (node
);
2835 ripng_distribute_update_interface (ifp
);
2839 /* delete all the added ripng routes. */
2844 struct route_node
*rp
;
2845 struct ripng_info
*rinfo
;
2848 /* Clear RIPng routes */
2849 for (rp
= route_top (ripng
->table
); rp
; rp
= route_next (rp
)) {
2850 if ((rinfo
= rp
->info
) != NULL
) {
2851 if ((rinfo
->type
== ZEBRA_ROUTE_RIPNG
) &&
2852 (rinfo
->sub_type
== RIPNG_ROUTE_RTE
))
2853 ripng_zebra_ipv6_delete ((struct prefix_ipv6
*)&rp
->p
,
2854 &rinfo
->nexthop
, rinfo
->metric
);
2856 RIPNG_TIMER_OFF (rinfo
->t_timeout
);
2857 RIPNG_TIMER_OFF (rinfo
->t_garbage_collect
);
2860 route_unlock_node (rp
);
2862 ripng_info_free(rinfo
);
2866 /* Cancel the RIPng timers */
2867 RIPNG_TIMER_OFF (ripng
->t_update
);
2868 RIPNG_TIMER_OFF (ripng
->t_triggered_update
);
2869 RIPNG_TIMER_OFF (ripng
->t_triggered_interval
);
2871 /* Cancel the read thread */
2872 if (ripng
->t_read
) {
2873 thread_cancel (ripng
->t_read
);
2874 ripng
->t_read
= NULL
;
2877 /* Close the RIPng socket */
2878 if (ripng
->sock
>= 0) {
2883 /* Static RIPng route configuration. */
2884 for (rp
= route_top (ripng
->route
); rp
; rp
= route_next (rp
))
2887 route_unlock_node (rp
);
2890 /* RIPng aggregated prefixes */
2891 for (rp
= route_top (ripng
->aggregate
); rp
; rp
= route_next (rp
))
2894 route_unlock_node (rp
);
2897 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++)
2898 if (ripng
->route_map
[i
].name
)
2899 free (ripng
->route_map
[i
].name
);
2901 XFREE (MTYPE_ROUTE_TABLE
, ripng
->table
);
2902 XFREE (MTYPE_ROUTE_TABLE
, ripng
->route
);
2903 XFREE (MTYPE_ROUTE_TABLE
, ripng
->aggregate
);
2905 XFREE (MTYPE_RIPNG
, ripng
);
2909 ripng_clean_network();
2910 ripng_passive_interface_clean ();
2911 ripng_offset_clean ();
2912 ripng_interface_clean ();
2913 ripng_redistribute_clean ();
2916 /* Reset all values to the default settings. */
2920 /* Call ripd related reset functions. */
2921 ripng_debug_reset ();
2922 ripng_route_map_reset ();
2924 /* Call library reset functions. */
2926 access_list_reset ();
2927 prefix_list_reset ();
2929 distribute_list_reset ();
2931 ripng_interface_reset ();
2933 ripng_zclient_reset ();
2937 ripng_if_rmap_update (struct if_rmap
*if_rmap
)
2939 struct interface
*ifp
;
2940 struct ripng_interface
*ri
;
2941 struct route_map
*rmap
;
2943 ifp
= if_lookup_by_name (if_rmap
->ifname
);
2949 if (if_rmap
->routemap
[IF_RMAP_IN
])
2951 rmap
= route_map_lookup_by_name (if_rmap
->routemap
[IF_RMAP_IN
]);
2953 ri
->routemap
[IF_RMAP_IN
] = rmap
;
2955 ri
->routemap
[IF_RMAP_IN
] = NULL
;
2958 ri
->routemap
[RIPNG_FILTER_IN
] = NULL
;
2960 if (if_rmap
->routemap
[IF_RMAP_OUT
])
2962 rmap
= route_map_lookup_by_name (if_rmap
->routemap
[IF_RMAP_OUT
]);
2964 ri
->routemap
[IF_RMAP_OUT
] = rmap
;
2966 ri
->routemap
[IF_RMAP_OUT
] = NULL
;
2969 ri
->routemap
[RIPNG_FILTER_OUT
] = NULL
;
2973 ripng_if_rmap_update_interface (struct interface
*ifp
)
2975 struct if_rmap
*if_rmap
;
2977 if_rmap
= if_rmap_lookup (ifp
->name
);
2979 ripng_if_rmap_update (if_rmap
);
2983 ripng_routemap_update_redistribute (void)
2989 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++)
2991 if (ripng
->route_map
[i
].name
)
2992 ripng
->route_map
[i
].map
=
2993 route_map_lookup_by_name (ripng
->route_map
[i
].name
);
2999 ripng_routemap_update ()
3001 struct interface
*ifp
;
3004 for (node
= listhead (iflist
); node
; nextnode (node
))
3006 ifp
= getdata (node
);
3007 ripng_if_rmap_update_interface (ifp
);
3010 ripng_routemap_update_redistribute ();
3013 /* Initialize ripng structure and set commands. */
3018 srand (time (NULL
));
3020 /* Install RIPNG_NODE. */
3021 install_node (&cmd_ripng_node
, ripng_config_write
);
3023 /* Install ripng commands. */
3024 install_element (VIEW_NODE
, &show_ipv6_ripng_cmd
);
3025 install_element (VIEW_NODE
, &show_ipv6_ripng_status_cmd
);
3027 install_element (ENABLE_NODE
, &show_ipv6_ripng_cmd
);
3028 install_element (ENABLE_NODE
, &show_ipv6_ripng_status_cmd
);
3030 install_element (CONFIG_NODE
, &router_ripng_cmd
);
3031 install_element (CONFIG_NODE
, &no_router_ripng_cmd
);
3033 install_default (RIPNG_NODE
);
3034 install_element (RIPNG_NODE
, &ripng_route_cmd
);
3035 install_element (RIPNG_NODE
, &no_ripng_route_cmd
);
3036 install_element (RIPNG_NODE
, &ripng_aggregate_address_cmd
);
3037 install_element (RIPNG_NODE
, &no_ripng_aggregate_address_cmd
);
3039 install_element (RIPNG_NODE
, &ripng_default_metric_cmd
);
3040 install_element (RIPNG_NODE
, &no_ripng_default_metric_cmd
);
3041 install_element (RIPNG_NODE
, &no_ripng_default_metric_val_cmd
);
3043 install_element (RIPNG_NODE
, &ripng_timers_cmd
);
3044 install_element (RIPNG_NODE
, &no_ripng_timers_cmd
);
3045 install_element (RIPNG_NODE
, &no_ripng_timers_val_cmd
);
3047 install_element (RIPNG_NODE
, &ripng_update_timer_cmd
);
3048 install_element (RIPNG_NODE
, &no_ripng_update_timer_cmd
);
3049 install_element (RIPNG_NODE
, &ripng_timeout_timer_cmd
);
3050 install_element (RIPNG_NODE
, &no_ripng_timeout_timer_cmd
);
3051 install_element (RIPNG_NODE
, &ripng_garbage_timer_cmd
);
3052 install_element (RIPNG_NODE
, &no_ripng_garbage_timer_cmd
);
3055 install_element (RIPNG_NODE
, &ripng_default_information_originate_cmd
);
3056 install_element (RIPNG_NODE
, &no_ripng_default_information_originate_cmd
);
3059 ripng_debug_init ();
3061 /* Access list install. */
3062 access_list_init ();
3063 access_list_add_hook (ripng_distribute_update_all
);
3064 access_list_delete_hook (ripng_distribute_update_all
);
3066 /* Prefix list initialize.*/
3067 prefix_list_init ();
3068 prefix_list_add_hook (ripng_distribute_update_all
);
3069 prefix_list_delete_hook (ripng_distribute_update_all
);
3071 /* Distribute list install. */
3072 distribute_list_init (RIPNG_NODE
);
3073 distribute_list_add_hook (ripng_distribute_update
);
3074 distribute_list_delete_hook (ripng_distribute_update
);
3076 /* Route-map for interface. */
3077 ripng_route_map_init ();
3078 ripng_offset_init ();
3080 route_map_add_hook (ripng_routemap_update
);
3081 route_map_delete_hook (ripng_routemap_update
);
3083 if_rmap_init (RIPNG_NODE
);
3084 if_rmap_hook_add (ripng_if_rmap_update
);
3085 if_rmap_hook_delete (ripng_if_rmap_update
);