1 /* $KAME: rtadvd.c,v 1.82 2003/08/05 12:34:23 itojun Exp $ */
4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the project nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/param.h>
33 #include <sys/socket.h>
36 #include <sys/queue.h>
39 #include <net/route.h>
40 #include <net/if_dl.h>
41 #include <netinet/in.h>
42 #include <netinet/ip6.h>
43 #include <netinet6/ip6_var.h>
44 #include <netinet/icmp6.h>
46 #include <arpa/inet.h>
66 struct msghdr rcvmhdr
;
67 static u_char
*rcvcmsgbuf
;
68 static size_t rcvcmsgbuflen
;
69 static u_char
*sndcmsgbuf
= NULL
;
70 static size_t sndcmsgbuflen
;
71 volatile sig_atomic_t do_dump
;
72 volatile sig_atomic_t do_die
;
73 struct msghdr sndmhdr
;
74 struct iovec rcviov
[2];
75 struct iovec sndiov
[2];
76 struct sockaddr_in6 rcvfrom
;
77 struct sockaddr_in6 sin6_allnodes
= {sizeof(sin6_allnodes
), AF_INET6
};
78 struct in6_addr in6a_site_allrouters
;
79 static char *dumpfilename
= "/var/run/rtadvd.dump";
80 static char *pidfilename
= "/var/run/rtadvd.pid";
81 static struct pidfh
*pfh
;
86 int dflag
= 0, sflag
= 0;
87 int so_traffic_class
= SO_TC_CTL
; /* use control class, by default */
89 char *conffile
= NULL
;
91 struct rainfo
*ralist
= NULL
;
93 struct nd_optlist
*next
;
94 struct nd_opt_hdr
*opt
;
97 struct nd_opt_hdr
*nd_opt_array
[9];
99 struct nd_opt_hdr
*zero
;
100 struct nd_opt_hdr
*src_lladdr
;
101 struct nd_opt_hdr
*tgt_lladdr
;
102 struct nd_opt_prefix_info
*pi
;
103 struct nd_opt_rd_hdr
*rh
;
104 struct nd_opt_mtu
*mtu
;
105 struct nd_optlist
*list
;
108 #define nd_opts_src_lladdr nd_opt_each.src_lladdr
109 #define nd_opts_tgt_lladdr nd_opt_each.tgt_lladdr
110 #define nd_opts_pi nd_opt_each.pi
111 #define nd_opts_rh nd_opt_each.rh
112 #define nd_opts_mtu nd_opt_each.mtu
113 #define nd_opts_list nd_opt_each.list
115 #define NDOPT_FLAG_SRCLINKADDR 0x1
116 #define NDOPT_FLAG_TGTLINKADDR 0x2
117 #define NDOPT_FLAG_PREFIXINFO 0x4
118 #define NDOPT_FLAG_RDHDR 0x8
119 #define NDOPT_FLAG_MTU 0x10
121 u_int32_t ndopt_flags
[] = {
122 0, NDOPT_FLAG_SRCLINKADDR
, NDOPT_FLAG_TGTLINKADDR
,
123 NDOPT_FLAG_PREFIXINFO
, NDOPT_FLAG_RDHDR
, NDOPT_FLAG_MTU
,
126 int main(int, char *[]);
127 static void set_die(int);
128 static void die(void);
129 static void sock_open(void);
130 static void rtsock_open(void);
131 static void rtadvd_input(void);
132 static void rs_input(int, struct nd_router_solicit
*,
133 struct in6_pktinfo
*, struct sockaddr_in6
*);
134 static void ra_input(int, struct nd_router_advert
*,
135 struct in6_pktinfo
*, struct sockaddr_in6
*);
136 static int prefix_check(struct nd_opt_prefix_info
*, struct rainfo
*,
137 struct sockaddr_in6
*);
138 static int nd6_options(struct nd_opt_hdr
*, int,
139 union nd_opts
*, u_int32_t
);
140 static void free_ndopts(union nd_opts
*);
141 static void ra_output(struct rainfo
*);
142 static void rtmsg_input(void);
143 static void rtadvd_set_dump_file(int);
144 static void set_short_delay(struct rainfo
*);
151 fd_set
*fdsetp
, *selectfdp
;
154 struct timeval
*timeout
;
156 int fflag
= 0, logopt
;
159 /* get command line options and arguments */
160 while ((ch
= getopt(argc
, argv
, "c:dDF:fMp:Rs")) != -1) {
178 fprintf(stderr
, "rtadvd: "
179 "the -R option is currently ignored.\n");
187 pidfilename
= optarg
;
190 dumpfilename
= optarg
;
198 "usage: rtadvd [-dDfMRs] [-c conffile] "
199 "[-F dumpfile] [-p pidfile] interfaces...\n");
203 logopt
= LOG_NDELAY
| LOG_PID
;
205 logopt
|= LOG_PERROR
;
206 openlog("rtadvd", logopt
, LOG_DAEMON
);
210 (void)setlogmask(LOG_UPTO(LOG_ERR
));
212 (void)setlogmask(LOG_UPTO(LOG_INFO
));
214 /* timer initialization */
217 /* random value initialization */
218 srandom((u_long
)time(NULL
));
220 /* get iflist block from kernel */
226 if (inet_pton(AF_INET6
, ALLNODES
, &sin6_allnodes
.sin6_addr
) != 1) {
227 fprintf(stderr
, "fatal: inet_pton failed\n");
231 pfh
= pidfile_open(pidfilename
, 0600, &otherpid
);
234 errx(1, "%s already running, pid: %d",
235 getprogname(), otherpid
);
237 "<%s> failed to open the pid log file, run anyway.",
246 /* record the current PID */
258 fdmasks
= howmany(maxfd
+ 1, NFDBITS
) * sizeof(fd_mask
);
259 if ((fdsetp
= malloc(fdmasks
)) == NULL
) {
263 if ((selectfdp
= malloc(fdmasks
)) == NULL
) {
267 memset(fdsetp
, 0, fdmasks
);
268 FD_SET(sock
, fdsetp
);
270 FD_SET(rtsock
, fdsetp
);
272 signal(SIGTERM
, set_die
);
273 signal(SIGUSR1
, rtadvd_set_dump_file
);
276 memcpy(selectfdp
, fdsetp
, fdmasks
); /* reinitialize */
278 if (do_dump
) { /* SIGUSR1 */
280 rtadvd_dump_file(dumpfilename
);
288 /* timer expiration check and reset the timer */
289 timeout
= rtadvd_check_timer();
291 if (timeout
!= NULL
) {
293 "<%s> set timer to %ld:%ld. waiting for "
294 "inputs or timeout", __func__
,
295 (long int)timeout
->tv_sec
,
296 (long int)timeout
->tv_usec
);
299 "<%s> there's no timer. waiting for inputs",
303 if ((i
= select(maxfd
+ 1, selectfdp
, NULL
, NULL
,
305 /* EINTR would occur upon SIGUSR1 for status dump */
307 syslog(LOG_ERR
, "<%s> select: %s",
308 __func__
, strerror(errno
));
311 if (i
== 0) /* timeout */
313 if (rtsock
!= -1 && FD_ISSET(rtsock
, selectfdp
))
315 if (FD_ISSET(sock
, selectfdp
))
318 exit(0); /* NOTREACHED */
322 rtadvd_set_dump_file(sig
)
340 const int retrans
= MAX_FINAL_RTR_ADVERTISEMENTS
;
343 syslog(LOG_DEBUG
, "<%s> cease to be an advertising router\n",
347 for (ra
= ralist
; ra
; ra
= ra
->next
) {
351 for (i
= 0; i
< retrans
; i
++) {
352 for (ra
= ralist
; ra
; ra
= ra
->next
)
356 sleep(MIN_DELAY_BETWEEN_RAS
);
366 int n
, type
, ifindex
= 0, plen
;
368 char msg
[2048], *next
, *lim
;
369 char ifname
[IF_NAMESIZE
];
370 struct prefix
*prefix
;
372 struct in6_addr
*addr
;
373 char addrbuf
[INET6_ADDRSTRLEN
];
374 int prefixchange
= 0;
376 n
= read(rtsock
, msg
, sizeof(msg
));
378 syslog(LOG_DEBUG
, "<%s> received a routing message "
379 "(type = %d, len = %d)", __func__
, rtmsg_type(msg
), n
);
381 if (n
> rtmsg_len(msg
)) {
383 * This usually won't happen for messages received on
388 "<%s> received data length is larger than "
389 "1st routing message len. multiple messages? "
390 "read %d bytes, but 1st msg len = %d",
391 __func__
, n
, rtmsg_len(msg
));
399 for (next
= msg
; next
< lim
; next
+= len
) {
402 next
= get_next_msg(next
, lim
, 0, &len
,
403 RTADV_TYPE2BITMASK(RTM_ADD
) |
404 RTADV_TYPE2BITMASK(RTM_DELETE
) |
405 RTADV_TYPE2BITMASK(RTM_NEWADDR
) |
406 RTADV_TYPE2BITMASK(RTM_DELADDR
) |
407 RTADV_TYPE2BITMASK(RTM_IFINFO
));
410 type
= rtmsg_type(next
);
414 ifindex
= get_rtm_ifindex(next
);
418 ifindex
= get_ifam_ifindex(next
);
421 ifindex
= get_ifm_ifindex(next
);
424 /* should not reach here */
427 "<%s:%d> unknown rtmsg %d on %s",
428 __func__
, __LINE__
, type
,
429 if_indextoname(ifindex
, ifname
));
434 if ((rai
= if_indextorainfo(ifindex
)) == NULL
) {
437 "<%s> route changed on "
438 "non advertising interface(%s)",
440 if_indextoname(ifindex
, ifname
));
444 oldifflags
= iflist
[ifindex
]->ifm_flags
;
448 /* init ifflags because it may have changed */
449 iflist
[ifindex
]->ifm_flags
=
450 if_getflags(ifindex
, iflist
[ifindex
]->ifm_flags
);
453 break; /* we aren't interested in prefixes */
455 addr
= get_addr(msg
);
456 plen
= get_prefixlen(msg
);
457 /* sanity check for plen */
458 /* as RFC2373, prefixlen is at least 4 */
459 if (plen
< 4 || plen
> 127) {
460 syslog(LOG_INFO
, "<%s> new interface route's"
461 "plen %d is invalid for a prefix",
465 prefix
= find_prefix(rai
, addr
, plen
);
469 * If the prefix has been invalidated,
470 * make it available again.
472 update_prefix(prefix
);
474 } else if (dflag
> 1) {
476 "<%s> new prefix(%s/%d) "
478 "but it was already in list",
480 inet_ntop(AF_INET6
, addr
,
481 (char *)addrbuf
, INET6_ADDRSTRLEN
),
486 make_prefix(rai
, ifindex
, addr
, plen
);
490 /* init ifflags because it may have changed */
491 iflist
[ifindex
]->ifm_flags
=
492 if_getflags(ifindex
, iflist
[ifindex
]->ifm_flags
);
497 addr
= get_addr(msg
);
498 plen
= get_prefixlen(msg
);
499 /* sanity check for plen */
500 /* as RFC2373, prefixlen is at least 4 */
501 if (plen
< 4 || plen
> 127) {
503 "<%s> deleted interface route's "
504 "plen %d is invalid for a prefix",
508 prefix
= find_prefix(rai
, addr
, plen
);
509 if (prefix
== NULL
) {
512 "<%s> prefix(%s/%d) was "
514 "but it was not in list",
516 inet_ntop(AF_INET6
, addr
,
517 (char *)addrbuf
, INET6_ADDRSTRLEN
),
522 invalidate_prefix(prefix
);
527 /* init ifflags because it may have changed */
528 iflist
[ifindex
]->ifm_flags
=
529 if_getflags(ifindex
, iflist
[ifindex
]->ifm_flags
);
532 iflist
[ifindex
]->ifm_flags
= get_ifm_flags(next
);
535 /* should not reach here */
538 "<%s:%d> unknown rtmsg %d on %s",
539 __func__
, __LINE__
, type
,
540 if_indextoname(ifindex
, ifname
));
545 /* check if an interface flag is changed */
546 if ((oldifflags
& IFF_UP
) && /* UP to DOWN */
547 !(iflist
[ifindex
]->ifm_flags
& IFF_UP
)) {
549 "<%s> interface %s becomes down. stop timer.",
550 __func__
, rai
->ifname
);
551 rtadvd_remove_timer(&rai
->timer
);
552 } else if (!(oldifflags
& IFF_UP
) && /* DOWN to UP */
553 (iflist
[ifindex
]->ifm_flags
& IFF_UP
)) {
555 "<%s> interface %s becomes up. restart timer.",
556 __func__
, rai
->ifname
);
558 rai
->initcounter
= 0; /* reset the counter */
559 rai
->waiting
= 0; /* XXX */
560 rai
->timer
= rtadvd_add_timer(ra_timeout
,
561 ra_timer_update
, rai
, rai
);
562 ra_timer_update((void *)rai
, &rai
->timer
->tm
);
563 rtadvd_set_timer(&rai
->timer
->tm
, rai
->timer
);
564 } else if (prefixchange
&&
565 (iflist
[ifindex
]->ifm_flags
& IFF_UP
)) {
567 * An advertised prefix has been added or invalidated.
568 * Will notice the change in a short delay.
570 rai
->initcounter
= 0;
571 set_short_delay(rai
);
586 struct icmp6_hdr
*icp
;
589 struct in6_pktinfo
*pi
= NULL
;
590 char ntopbuf
[INET6_ADDRSTRLEN
], ifnamebuf
[IFNAMSIZ
];
591 struct in6_addr dst
= in6addr_any
;
594 * Get message. We reset msg_controllen since the field could
595 * be modified if we had received a message before setting
598 rcvmhdr
.msg_controllen
= rcvcmsgbuflen
;
599 if ((i
= recvmsg(sock
, &rcvmhdr
, 0)) < 0)
602 /* extract optional information via Advanced API */
603 for (cm
= (struct cmsghdr
*)CMSG_FIRSTHDR(&rcvmhdr
);
605 cm
= (struct cmsghdr
*)CMSG_NXTHDR(&rcvmhdr
, cm
)) {
606 if (cm
->cmsg_level
== IPPROTO_IPV6
&&
607 cm
->cmsg_type
== IPV6_PKTINFO
&&
608 cm
->cmsg_len
== CMSG_LEN(sizeof(struct in6_pktinfo
))) {
609 pi
= (struct in6_pktinfo
*)(CMSG_DATA(cm
));
610 ifindex
= pi
->ipi6_ifindex
;
613 if (cm
->cmsg_level
== IPPROTO_IPV6
&&
614 cm
->cmsg_type
== IPV6_HOPLIMIT
&&
615 cm
->cmsg_len
== CMSG_LEN(sizeof(int)))
616 hlimp
= (int *)CMSG_DATA(cm
);
620 "<%s> failed to get receiving interface",
626 "<%s> failed to get receiving hop limit",
632 * If we happen to receive data on an interface which is now gone
633 * or down, just discard the data.
635 if (iflist
[pi
->ipi6_ifindex
] == NULL
||
636 (iflist
[pi
->ipi6_ifindex
]->ifm_flags
& IFF_UP
) == 0) {
638 "<%s> received data on a disabled interface (%s)",
640 (iflist
[pi
->ipi6_ifindex
] == NULL
) ? "[gone]" :
641 if_indextoname(pi
->ipi6_ifindex
, ifnamebuf
));
646 if (i
< sizeof(struct ip6_hdr
) + sizeof(struct icmp6_hdr
)) {
648 "<%s> packet size(%d) is too short",
653 ip
= (struct ip6_hdr
*)rcvmhdr
.msg_iov
[0].iov_base
;
654 icp
= (struct icmp6_hdr
*)(ip
+ 1); /* XXX: ext. hdr? */
656 if (i
< sizeof(struct icmp6_hdr
)) {
658 "<%s> packet size(%d) is too short",
663 icp
= (struct icmp6_hdr
*)rcvmhdr
.msg_iov
[0].iov_base
;
666 switch (icp
->icmp6_type
) {
667 case ND_ROUTER_SOLICIT
:
669 * Message verification - RFC-2461 6.1.1
670 * XXX: these checks must be done in the kernel as well,
671 * but we can't completely rely on them.
675 "<%s> RS with invalid hop limit(%d) "
676 "received from %s on %s",
678 inet_ntop(AF_INET6
, &rcvfrom
.sin6_addr
, ntopbuf
,
680 if_indextoname(pi
->ipi6_ifindex
, ifnamebuf
));
683 if (icp
->icmp6_code
) {
685 "<%s> RS with invalid ICMP6 code(%d) "
686 "received from %s on %s",
687 __func__
, icp
->icmp6_code
,
688 inet_ntop(AF_INET6
, &rcvfrom
.sin6_addr
, ntopbuf
,
690 if_indextoname(pi
->ipi6_ifindex
, ifnamebuf
));
693 if (i
< sizeof(struct nd_router_solicit
)) {
695 "<%s> RS from %s on %s does not have enough "
698 inet_ntop(AF_INET6
, &rcvfrom
.sin6_addr
, ntopbuf
,
700 if_indextoname(pi
->ipi6_ifindex
, ifnamebuf
), i
);
703 rs_input(i
, (struct nd_router_solicit
*)icp
, pi
, &rcvfrom
);
705 case ND_ROUTER_ADVERT
:
707 * Message verification - RFC-2461 6.1.2
708 * XXX: there's a same dilemma as above...
712 "<%s> RA with invalid hop limit(%d) "
713 "received from %s on %s",
715 inet_ntop(AF_INET6
, &rcvfrom
.sin6_addr
, ntopbuf
,
717 if_indextoname(pi
->ipi6_ifindex
, ifnamebuf
));
720 if (icp
->icmp6_code
) {
722 "<%s> RA with invalid ICMP6 code(%d) "
723 "received from %s on %s",
724 __func__
, icp
->icmp6_code
,
725 inet_ntop(AF_INET6
, &rcvfrom
.sin6_addr
, ntopbuf
,
727 if_indextoname(pi
->ipi6_ifindex
, ifnamebuf
));
730 if (i
< sizeof(struct nd_router_advert
)) {
732 "<%s> RA from %s on %s does not have enough "
735 inet_ntop(AF_INET6
, &rcvfrom
.sin6_addr
, ntopbuf
,
737 if_indextoname(pi
->ipi6_ifindex
, ifnamebuf
), i
);
740 ra_input(i
, (struct nd_router_advert
*)icp
, pi
, &rcvfrom
);
742 case ICMP6_ROUTER_RENUMBERING
:
743 if (accept_rr
== 0) {
744 syslog(LOG_ERR
, "<%s> received a router renumbering "
745 "message, but not allowed to be accepted",
749 rr_input(i
, (struct icmp6_router_renum
*)icp
, pi
, &rcvfrom
,
754 * Note that this case is POSSIBLE, especially just
755 * after invocation of the daemon. This is because we
756 * could receive message after opening the socket and
757 * before setting ICMP6 type filter(see sock_open()).
759 syslog(LOG_ERR
, "<%s> invalid icmp type(%d)",
760 __func__
, icp
->icmp6_type
);
768 rs_input(int len
, struct nd_router_solicit
*rs
,
769 struct in6_pktinfo
*pi
, struct sockaddr_in6
*from
)
771 char ntopbuf
[INET6_ADDRSTRLEN
], ifnamebuf
[IFNAMSIZ
];
772 union nd_opts ndopts
;
774 struct soliciter
*sol
;
777 "<%s> RS received from %s on %s",
779 inet_ntop(AF_INET6
, &from
->sin6_addr
,
780 ntopbuf
, INET6_ADDRSTRLEN
),
781 if_indextoname(pi
->ipi6_ifindex
, ifnamebuf
));
783 /* ND option check */
784 memset(&ndopts
, 0, sizeof(ndopts
));
785 if (nd6_options((struct nd_opt_hdr
*)(rs
+ 1),
786 len
- sizeof(struct nd_router_solicit
),
787 &ndopts
, NDOPT_FLAG_SRCLINKADDR
)) {
789 "<%s> ND option check failed for an RS from %s on %s",
791 inet_ntop(AF_INET6
, &from
->sin6_addr
,
792 ntopbuf
, INET6_ADDRSTRLEN
),
793 if_indextoname(pi
->ipi6_ifindex
, ifnamebuf
));
798 * If the IP source address is the unspecified address, there
799 * must be no source link-layer address option in the message.
802 if (IN6_IS_ADDR_UNSPECIFIED(&from
->sin6_addr
) &&
803 ndopts
.nd_opts_src_lladdr
) {
805 "<%s> RS from unspecified src on %s has a link-layer"
808 if_indextoname(pi
->ipi6_ifindex
, ifnamebuf
));
814 if (pi
->ipi6_ifindex
== ra
->ifindex
)
820 "<%s> RS received on non advertising interface(%s)",
822 if_indextoname(pi
->ipi6_ifindex
, ifnamebuf
));
826 ra
->rsinput
++; /* increment statistics */
829 * Decide whether to send RA according to the rate-limit
833 /* record sockaddr waiting for RA, if possible */
834 sol
= (struct soliciter
*)malloc(sizeof(*sol
));
837 /* XXX RFC2553 need clarification on flowinfo */
838 sol
->addr
.sin6_flowinfo
= 0;
839 sol
->next
= ra
->soliciter
;
844 * If there is already a waiting RS packet, don't
853 free_ndopts(&ndopts
);
861 long delay
; /* must not be greater than 1000000 */
862 struct timeval interval
, now
, min_delay
, tm_tmp
, *rest
;
865 * Compute a random delay. If the computed value
866 * corresponds to a time later than the time the next
867 * multicast RA is scheduled to be sent, ignore the random
868 * delay and send the advertisement at the
869 * already-scheduled time. RFC-2461 6.2.6
871 #ifdef HAVE_ARC4RANDOM
872 delay
= arc4random_uniform(MAX_RA_DELAY_TIME
);
874 delay
= random() % MAX_RA_DELAY_TIME
;
877 interval
.tv_usec
= delay
;
878 rest
= rtadvd_timer_rest(rai
->timer
);
879 if (TIMEVAL_LT(*rest
, interval
)) {
880 syslog(LOG_DEBUG
, "<%s> random delay is larger than "
881 "the rest of the current timer", __func__
);
886 * If we sent a multicast Router Advertisement within
887 * the last MIN_DELAY_BETWEEN_RAS seconds, schedule
888 * the advertisement to be sent at a time corresponding to
889 * MIN_DELAY_BETWEEN_RAS plus the random value after the
890 * previous advertisement was sent.
892 gettimeofday(&now
, NULL
);
893 TIMEVAL_SUB(&now
, &rai
->lastsent
, &tm_tmp
);
894 min_delay
.tv_sec
= MIN_DELAY_BETWEEN_RAS
;
895 min_delay
.tv_usec
= 0;
896 if (TIMEVAL_LT(tm_tmp
, min_delay
)) {
897 TIMEVAL_SUB(&min_delay
, &tm_tmp
, &min_delay
);
898 TIMEVAL_ADD(&min_delay
, &interval
, &interval
);
900 rtadvd_set_timer(&interval
, rai
->timer
);
904 ra_input(int len
, struct nd_router_advert
*ra
,
905 struct in6_pktinfo
*pi
, struct sockaddr_in6
*from
)
908 char ntopbuf
[INET6_ADDRSTRLEN
], ifnamebuf
[IFNAMSIZ
];
909 union nd_opts ndopts
;
910 char *on_off
[] = {"OFF", "ON"};
911 u_int32_t reachabletime
, retranstimer
, mtu
;
912 int inconsistent
= 0;
915 "<%s> RA received from %s on %s",
917 inet_ntop(AF_INET6
, &from
->sin6_addr
,
918 ntopbuf
, INET6_ADDRSTRLEN
),
919 if_indextoname(pi
->ipi6_ifindex
, ifnamebuf
));
921 /* ND option check */
922 memset(&ndopts
, 0, sizeof(ndopts
));
923 if (nd6_options((struct nd_opt_hdr
*)(ra
+ 1),
924 len
- sizeof(struct nd_router_advert
),
925 &ndopts
, NDOPT_FLAG_SRCLINKADDR
|
926 NDOPT_FLAG_PREFIXINFO
| NDOPT_FLAG_MTU
)) {
928 "<%s> ND option check failed for an RA from %s on %s",
930 inet_ntop(AF_INET6
, &from
->sin6_addr
,
931 ntopbuf
, INET6_ADDRSTRLEN
),
932 if_indextoname(pi
->ipi6_ifindex
, ifnamebuf
));
937 * RA consistency check according to RFC-2461 6.2.7
939 if ((rai
= if_indextorainfo(pi
->ipi6_ifindex
)) == 0) {
941 "<%s> received RA from %s on non-advertising"
944 inet_ntop(AF_INET6
, &from
->sin6_addr
,
945 ntopbuf
, INET6_ADDRSTRLEN
),
946 if_indextoname(pi
->ipi6_ifindex
, ifnamebuf
));
949 rai
->rainput
++; /* increment statistics */
951 /* Cur Hop Limit value */
952 if (ra
->nd_ra_curhoplimit
&& rai
->hoplimit
&&
953 ra
->nd_ra_curhoplimit
!= rai
->hoplimit
) {
955 "<%s> CurHopLimit inconsistent on %s:"
956 " %d from %s, %d from us",
959 ra
->nd_ra_curhoplimit
,
960 inet_ntop(AF_INET6
, &from
->sin6_addr
,
961 ntopbuf
, INET6_ADDRSTRLEN
),
966 if ((ra
->nd_ra_flags_reserved
& ND_RA_FLAG_MANAGED
) !=
969 "<%s> M flag inconsistent on %s:"
970 " %s from %s, %s from us",
973 on_off
[!rai
->managedflg
],
974 inet_ntop(AF_INET6
, &from
->sin6_addr
,
975 ntopbuf
, INET6_ADDRSTRLEN
),
976 on_off
[rai
->managedflg
]);
980 if ((ra
->nd_ra_flags_reserved
& ND_RA_FLAG_OTHER
) !=
983 "<%s> O flag inconsistent on %s:"
984 " %s from %s, %s from us",
987 on_off
[!rai
->otherflg
],
988 inet_ntop(AF_INET6
, &from
->sin6_addr
,
989 ntopbuf
, INET6_ADDRSTRLEN
),
990 on_off
[rai
->otherflg
]);
994 reachabletime
= ntohl(ra
->nd_ra_reachable
);
995 if (reachabletime
&& rai
->reachabletime
&&
996 reachabletime
!= rai
->reachabletime
) {
998 "<%s> ReachableTime inconsistent on %s:"
999 " %d from %s, %d from us",
1003 inet_ntop(AF_INET6
, &from
->sin6_addr
,
1004 ntopbuf
, INET6_ADDRSTRLEN
),
1005 rai
->reachabletime
);
1009 retranstimer
= ntohl(ra
->nd_ra_retransmit
);
1010 if (retranstimer
&& rai
->retranstimer
&&
1011 retranstimer
!= rai
->retranstimer
) {
1013 "<%s> RetranceTimer inconsistent on %s:"
1014 " %d from %s, %d from us",
1018 inet_ntop(AF_INET6
, &from
->sin6_addr
,
1019 ntopbuf
, INET6_ADDRSTRLEN
),
1023 /* Values in the MTU options */
1024 if (ndopts
.nd_opts_mtu
) {
1025 mtu
= ntohl(ndopts
.nd_opts_mtu
->nd_opt_mtu_mtu
);
1026 if (mtu
&& rai
->linkmtu
&& mtu
!= rai
->linkmtu
) {
1028 "<%s> MTU option value inconsistent on %s:"
1029 " %d from %s, %d from us",
1032 inet_ntop(AF_INET6
, &from
->sin6_addr
,
1033 ntopbuf
, INET6_ADDRSTRLEN
),
1038 /* Preferred and Valid Lifetimes for prefixes */
1040 struct nd_optlist
*optp
= ndopts
.nd_opts_list
;
1042 if (ndopts
.nd_opts_pi
) {
1043 if (prefix_check(ndopts
.nd_opts_pi
, rai
, from
))
1047 if (prefix_check((struct nd_opt_prefix_info
*)optp
->opt
,
1055 rai
->rainconsistent
++;
1058 free_ndopts(&ndopts
);
1062 /* return a non-zero value if the received prefix is inconsitent with ours */
1064 prefix_check(struct nd_opt_prefix_info
*pinfo
,
1065 struct rainfo
*rai
, struct sockaddr_in6
*from
)
1067 u_int32_t preferred_time
, valid_time
;
1069 int inconsistent
= 0;
1070 char ntopbuf
[INET6_ADDRSTRLEN
], prefixbuf
[INET6_ADDRSTRLEN
];
1073 #if 0 /* impossible */
1074 if (pinfo
->nd_opt_pi_type
!= ND_OPT_PREFIX_INFORMATION
)
1079 * log if the adveritsed prefix has link-local scope(sanity check?)
1081 if (IN6_IS_ADDR_LINKLOCAL(&pinfo
->nd_opt_pi_prefix
)) {
1083 "<%s> link-local prefix %s/%d is advertised "
1086 inet_ntop(AF_INET6
, &pinfo
->nd_opt_pi_prefix
,
1087 prefixbuf
, INET6_ADDRSTRLEN
),
1088 pinfo
->nd_opt_pi_prefix_len
,
1089 inet_ntop(AF_INET6
, &from
->sin6_addr
,
1090 ntopbuf
, INET6_ADDRSTRLEN
),
1094 if ((pp
= find_prefix(rai
, &pinfo
->nd_opt_pi_prefix
,
1095 pinfo
->nd_opt_pi_prefix_len
)) == NULL
) {
1097 "<%s> prefix %s/%d from %s on %s is not in our list",
1099 inet_ntop(AF_INET6
, &pinfo
->nd_opt_pi_prefix
,
1100 prefixbuf
, INET6_ADDRSTRLEN
),
1101 pinfo
->nd_opt_pi_prefix_len
,
1102 inet_ntop(AF_INET6
, &from
->sin6_addr
,
1103 ntopbuf
, INET6_ADDRSTRLEN
),
1108 preferred_time
= ntohl(pinfo
->nd_opt_pi_preferred_time
);
1109 if (pp
->pltimeexpire
) {
1111 * The lifetime is decremented in real time, so we should
1112 * compare the expiration time.
1113 * (RFC 2461 Section 6.2.7.)
1114 * XXX: can we really expect that all routers on the link
1115 * have synchronized clocks?
1117 gettimeofday(&now
, NULL
);
1118 preferred_time
+= now
.tv_sec
;
1120 if (!pp
->timer
&& rai
->clockskew
&&
1121 preferred_time
- pp
->pltimeexpire
> rai
->clockskew
) {
1123 "<%s> preferred lifetime for %s/%d"
1124 " (decr. in real time) inconsistent on %s:"
1125 " %d from %s, %ld from us",
1127 inet_ntop(AF_INET6
, &pinfo
->nd_opt_pi_prefix
,
1128 prefixbuf
, INET6_ADDRSTRLEN
),
1129 pinfo
->nd_opt_pi_prefix_len
,
1130 rai
->ifname
, preferred_time
,
1131 inet_ntop(AF_INET6
, &from
->sin6_addr
,
1132 ntopbuf
, INET6_ADDRSTRLEN
),
1136 } else if (!pp
->timer
&& preferred_time
!= pp
->preflifetime
) {
1138 "<%s> preferred lifetime for %s/%d"
1139 " inconsistent on %s:"
1140 " %d from %s, %d from us",
1142 inet_ntop(AF_INET6
, &pinfo
->nd_opt_pi_prefix
,
1143 prefixbuf
, INET6_ADDRSTRLEN
),
1144 pinfo
->nd_opt_pi_prefix_len
,
1145 rai
->ifname
, preferred_time
,
1146 inet_ntop(AF_INET6
, &from
->sin6_addr
,
1147 ntopbuf
, INET6_ADDRSTRLEN
),
1151 valid_time
= ntohl(pinfo
->nd_opt_pi_valid_time
);
1152 if (pp
->vltimeexpire
) {
1153 gettimeofday(&now
, NULL
);
1154 valid_time
+= now
.tv_sec
;
1156 if (!pp
->timer
&& rai
->clockskew
&&
1157 valid_time
- pp
->vltimeexpire
> rai
->clockskew
) {
1159 "<%s> valid lifetime for %s/%d"
1160 " (decr. in real time) inconsistent on %s:"
1161 " %d from %s, %ld from us",
1163 inet_ntop(AF_INET6
, &pinfo
->nd_opt_pi_prefix
,
1164 prefixbuf
, INET6_ADDRSTRLEN
),
1165 pinfo
->nd_opt_pi_prefix_len
,
1166 rai
->ifname
, preferred_time
,
1167 inet_ntop(AF_INET6
, &from
->sin6_addr
,
1168 ntopbuf
, INET6_ADDRSTRLEN
),
1172 } else if (!pp
->timer
&& valid_time
!= pp
->validlifetime
) {
1174 "<%s> valid lifetime for %s/%d"
1175 " inconsistent on %s:"
1176 " %d from %s, %d from us",
1178 inet_ntop(AF_INET6
, &pinfo
->nd_opt_pi_prefix
,
1179 prefixbuf
, INET6_ADDRSTRLEN
),
1180 pinfo
->nd_opt_pi_prefix_len
,
1181 rai
->ifname
, valid_time
,
1182 inet_ntop(AF_INET6
, &from
->sin6_addr
,
1183 ntopbuf
, INET6_ADDRSTRLEN
),
1188 return(inconsistent
);
1192 find_prefix(struct rainfo
*rai
, struct in6_addr
*prefix
, int plen
)
1195 int bytelen
, bitlen
;
1198 for (pp
= rai
->prefix
.next
; pp
!= &rai
->prefix
; pp
= pp
->next
) {
1199 if (plen
!= pp
->prefixlen
)
1203 bitmask
= 0xff << (8 - bitlen
);
1204 if (memcmp((void *)prefix
, (void *)&pp
->prefix
, bytelen
))
1207 ((prefix
->s6_addr
[bytelen
] & bitmask
) ==
1208 (pp
->prefix
.s6_addr
[bytelen
] & bitmask
))) {
1216 /* check if p0/plen0 matches p1/plen1; return 1 if matches, otherwise 0. */
1218 prefix_match(struct in6_addr
*p0
, int plen0
,
1219 struct in6_addr
*p1
, int plen1
)
1221 int bytelen
, bitlen
;
1226 bytelen
= plen1
/ 8;
1228 bitmask
= 0xff << (8 - bitlen
);
1229 if (memcmp((void *)p0
, (void *)p1
, bytelen
))
1232 ((p0
->s6_addr
[bytelen
] & bitmask
) ==
1233 (p1
->s6_addr
[bytelen
] & bitmask
))) {
1241 nd6_options(struct nd_opt_hdr
*hdr
, int limit
,
1242 union nd_opts
*ndopts
, u_int32_t optflags
)
1246 for (; limit
> 0; limit
-= optlen
) {
1247 if (limit
< sizeof(struct nd_opt_hdr
)) {
1248 syslog(LOG_INFO
, "<%s> short option header", __func__
);
1252 hdr
= (struct nd_opt_hdr
*)((caddr_t
)hdr
+ optlen
);
1253 if (hdr
->nd_opt_len
== 0) {
1255 "<%s> bad ND option length(0) (type = %d)",
1256 __func__
, hdr
->nd_opt_type
);
1259 optlen
= hdr
->nd_opt_len
<< 3;
1260 if (optlen
> limit
) {
1261 syslog(LOG_INFO
, "<%s> short option", __func__
);
1265 if (hdr
->nd_opt_type
> ND_OPT_MTU
) {
1266 syslog(LOG_INFO
, "<%s> unknown ND option(type %d)",
1267 __func__
, hdr
->nd_opt_type
);
1271 if ((ndopt_flags
[hdr
->nd_opt_type
] & optflags
) == 0) {
1272 syslog(LOG_INFO
, "<%s> unexpected ND option(type %d)",
1273 __func__
, hdr
->nd_opt_type
);
1278 * Option length check. Do it here for all fixed-length
1281 if ((hdr
->nd_opt_type
== ND_OPT_MTU
&&
1282 (optlen
!= sizeof(struct nd_opt_mtu
))) ||
1283 ((hdr
->nd_opt_type
== ND_OPT_PREFIX_INFORMATION
&&
1284 optlen
!= sizeof(struct nd_opt_prefix_info
)))) {
1285 syslog(LOG_INFO
, "<%s> invalid option length",
1290 switch (hdr
->nd_opt_type
) {
1291 case ND_OPT_TARGET_LINKADDR
:
1292 case ND_OPT_REDIRECTED_HEADER
:
1293 break; /* we don't care about these options */
1294 case ND_OPT_SOURCE_LINKADDR
:
1296 if (ndopts
->nd_opt_array
[hdr
->nd_opt_type
]) {
1298 "<%s> duplicated ND option (type = %d)",
1299 __func__
, hdr
->nd_opt_type
);
1301 ndopts
->nd_opt_array
[hdr
->nd_opt_type
] = hdr
;
1303 case ND_OPT_PREFIX_INFORMATION
:
1305 struct nd_optlist
*pfxlist
;
1307 if (ndopts
->nd_opts_pi
== 0) {
1308 ndopts
->nd_opts_pi
=
1309 (struct nd_opt_prefix_info
*)hdr
;
1312 if ((pfxlist
= malloc(sizeof(*pfxlist
))) == NULL
) {
1313 syslog(LOG_ERR
, "<%s> can't allocate memory",
1317 pfxlist
->next
= ndopts
->nd_opts_list
;
1319 ndopts
->nd_opts_list
= pfxlist
;
1323 default: /* impossible */
1331 free_ndopts(ndopts
);
1337 free_ndopts(union nd_opts
*ndopts
)
1339 struct nd_optlist
*opt
= ndopts
->nd_opts_list
, *next
;
1351 struct icmp6_filter filt
;
1352 struct ipv6_mreq mreq
;
1353 struct rainfo
*ra
= ralist
;
1355 /* XXX: should be max MTU attached to the node */
1356 static u_char answer
[1500];
1358 rcvcmsgbuflen
= CMSG_SPACE(sizeof(struct in6_pktinfo
)) +
1359 CMSG_SPACE(sizeof(int));
1360 rcvcmsgbuf
= (u_char
*)malloc(rcvcmsgbuflen
);
1361 if (rcvcmsgbuf
== NULL
) {
1362 syslog(LOG_ERR
, "<%s> not enough core", __func__
);
1366 sndcmsgbuflen
= CMSG_SPACE(sizeof(struct in6_pktinfo
)) +
1367 CMSG_SPACE(sizeof(int));
1368 sndcmsgbuf
= (u_char
*)malloc(sndcmsgbuflen
);
1369 if (sndcmsgbuf
== NULL
) {
1370 syslog(LOG_ERR
, "<%s> not enough core", __func__
);
1374 if ((sock
= socket(AF_INET6
, SOCK_RAW
, IPPROTO_ICMPV6
)) < 0) {
1375 syslog(LOG_ERR
, "<%s> socket: %s", __func__
,
1380 (void) setsockopt(sock
, SOL_SOCKET
, SO_TRAFFIC_CLASS
,
1381 (void *)&so_traffic_class
, sizeof (so_traffic_class
));
1383 /* specify to tell receiving interface */
1385 #ifdef IPV6_RECVPKTINFO
1386 if (setsockopt(sock
, IPPROTO_IPV6
, IPV6_RECVPKTINFO
, &on
,
1388 syslog(LOG_ERR
, "<%s> IPV6_RECVPKTINFO: %s",
1389 __func__
, strerror(errno
));
1392 #else /* old adv. API */
1393 if (setsockopt(sock
, IPPROTO_IPV6
, IPV6_PKTINFO
, &on
,
1395 syslog(LOG_ERR
, "<%s> IPV6_PKTINFO: %s",
1396 __func__
, strerror(errno
));
1402 /* specify to tell value of hoplimit field of received IP6 hdr */
1403 #ifdef IPV6_RECVHOPLIMIT
1404 if (setsockopt(sock
, IPPROTO_IPV6
, IPV6_RECVHOPLIMIT
, &on
,
1406 syslog(LOG_ERR
, "<%s> IPV6_RECVHOPLIMIT: %s",
1407 __func__
, strerror(errno
));
1410 #else /* old adv. API */
1411 if (setsockopt(sock
, IPPROTO_IPV6
, IPV6_HOPLIMIT
, &on
,
1413 syslog(LOG_ERR
, "<%s> IPV6_HOPLIMIT: %s",
1414 __func__
, strerror(errno
));
1419 ICMP6_FILTER_SETBLOCKALL(&filt
);
1420 ICMP6_FILTER_SETPASS(ND_ROUTER_SOLICIT
, &filt
);
1421 ICMP6_FILTER_SETPASS(ND_ROUTER_ADVERT
, &filt
);
1423 ICMP6_FILTER_SETPASS(ICMP6_ROUTER_RENUMBERING
, &filt
);
1424 if (setsockopt(sock
, IPPROTO_ICMPV6
, ICMP6_FILTER
, &filt
,
1425 sizeof(filt
)) < 0) {
1426 syslog(LOG_ERR
, "<%s> IICMP6_FILTER: %s",
1427 __func__
, strerror(errno
));
1432 * join all routers multicast address on each advertising interface.
1434 if (inet_pton(AF_INET6
, ALLROUTERS_LINK
,
1435 &mreq
.ipv6mr_multiaddr
.s6_addr
)
1437 syslog(LOG_ERR
, "<%s> inet_pton failed(library bug?)",
1442 mreq
.ipv6mr_interface
= ra
->ifindex
;
1443 if (setsockopt(sock
, IPPROTO_IPV6
, IPV6_JOIN_GROUP
, &mreq
,
1444 sizeof(mreq
)) < 0) {
1445 syslog(LOG_ERR
, "<%s> IPV6_JOIN_GROUP(link) on %s: %s",
1446 __func__
, ra
->ifname
, strerror(errno
));
1453 * When attending router renumbering, join all-routers site-local
1457 if (inet_pton(AF_INET6
, ALLROUTERS_SITE
,
1458 &in6a_site_allrouters
) != 1) {
1459 syslog(LOG_ERR
, "<%s> inet_pton failed(library bug?)",
1463 mreq
.ipv6mr_multiaddr
= in6a_site_allrouters
;
1465 if ((mreq
.ipv6mr_interface
= if_nametoindex(mcastif
))
1468 "<%s> invalid interface: %s",
1473 mreq
.ipv6mr_interface
= ralist
->ifindex
;
1474 if (setsockopt(sock
, IPPROTO_IPV6
, IPV6_JOIN_GROUP
,
1475 &mreq
, sizeof(mreq
)) < 0) {
1477 "<%s> IPV6_JOIN_GROUP(site) on %s: %s",
1479 mcastif
? mcastif
: ralist
->ifname
,
1485 /* initialize msghdr for receiving packets */
1486 rcviov
[0].iov_base
= (caddr_t
)answer
;
1487 rcviov
[0].iov_len
= sizeof(answer
);
1488 rcvmhdr
.msg_name
= (caddr_t
)&rcvfrom
;
1489 rcvmhdr
.msg_namelen
= sizeof(rcvfrom
);
1490 rcvmhdr
.msg_iov
= rcviov
;
1491 rcvmhdr
.msg_iovlen
= 1;
1492 rcvmhdr
.msg_control
= (caddr_t
) rcvcmsgbuf
;
1493 rcvmhdr
.msg_controllen
= rcvcmsgbuflen
;
1495 /* initialize msghdr for sending packets */
1496 sndmhdr
.msg_namelen
= sizeof(struct sockaddr_in6
);
1497 sndmhdr
.msg_iov
= sndiov
;
1498 sndmhdr
.msg_iovlen
= 1;
1499 sndmhdr
.msg_control
= (caddr_t
)sndcmsgbuf
;
1500 sndmhdr
.msg_controllen
= sndcmsgbuflen
;
1505 /* open a routing socket to watch the routing table */
1509 if ((rtsock
= socket(PF_ROUTE
, SOCK_RAW
, 0)) < 0) {
1511 "<%s> socket: %s", __func__
, strerror(errno
));
1517 if_indextorainfo(int idx
)
1519 struct rainfo
*rai
= ralist
;
1521 for (rai
= ralist
; rai
; rai
= rai
->next
) {
1522 if (rai
->ifindex
== idx
)
1526 return(NULL
); /* search failed */
1531 struct rainfo
*rainfo
;
1535 struct in6_pktinfo
*pi
;
1536 struct soliciter
*sol
, *nextsol
;
1538 if ((iflist
[rainfo
->ifindex
]->ifm_flags
& IFF_UP
) == 0) {
1539 syslog(LOG_DEBUG
, "<%s> %s is not up, skip sending RA",
1540 __func__
, rainfo
->ifname
);
1544 make_packet(rainfo
); /* XXX: inefficient */
1546 sndmhdr
.msg_name
= (caddr_t
)&sin6_allnodes
;
1547 sndmhdr
.msg_iov
[0].iov_base
= (caddr_t
)rainfo
->ra_data
;
1548 sndmhdr
.msg_iov
[0].iov_len
= rainfo
->ra_datalen
;
1550 cm
= CMSG_FIRSTHDR(&sndmhdr
);
1551 /* specify the outgoing interface */
1552 cm
->cmsg_level
= IPPROTO_IPV6
;
1553 cm
->cmsg_type
= IPV6_PKTINFO
;
1554 cm
->cmsg_len
= CMSG_LEN(sizeof(struct in6_pktinfo
));
1555 pi
= (struct in6_pktinfo
*)CMSG_DATA(cm
);
1556 memset(&pi
->ipi6_addr
, 0, sizeof(pi
->ipi6_addr
)); /*XXX*/
1557 pi
->ipi6_ifindex
= rainfo
->ifindex
;
1559 /* specify the hop limit of the packet */
1563 cm
= CMSG_NXTHDR(&sndmhdr
, cm
);
1564 cm
->cmsg_level
= IPPROTO_IPV6
;
1565 cm
->cmsg_type
= IPV6_HOPLIMIT
;
1566 cm
->cmsg_len
= CMSG_LEN(sizeof(int));
1567 memcpy(CMSG_DATA(cm
), &hoplimit
, sizeof(int));
1571 "<%s> send RA on %s, # of waitings = %d",
1572 __func__
, rainfo
->ifname
, rainfo
->waiting
);
1574 i
= sendmsg(sock
, &sndmhdr
, 0);
1576 if (i
< 0 || i
!= rainfo
->ra_datalen
) {
1578 syslog(LOG_ERR
, "<%s> sendmsg on %s: %s",
1579 __func__
, rainfo
->ifname
,
1583 /* update counter */
1584 if (rainfo
->initcounter
< MAX_INITIAL_RTR_ADVERTISEMENTS
)
1585 rainfo
->initcounter
++;
1589 * unicast advertisements
1590 * XXX commented out. reason: though spec does not forbit it, unicast
1591 * advert does not really help
1593 for (sol
= rainfo
->soliciter
; sol
; sol
= nextsol
) {
1594 nextsol
= sol
->next
;
1599 rainfo
->soliciter
= NULL
;
1601 /* update timestamp */
1602 gettimeofday(&rainfo
->lastsent
, NULL
);
1604 /* reset waiting conter */
1605 rainfo
->waiting
= 0;
1608 /* process RA timer */
1609 struct rtadvd_timer
*
1610 ra_timeout(void *data
)
1612 struct rainfo
*rai
= (struct rainfo
*)data
;
1615 /* if necessary, reconstruct the packet. */
1619 "<%s> RA timer on %s is expired",
1620 __func__
, rai
->ifname
);
1627 /* update RA timer */
1629 ra_timer_update(void *data
, struct timeval
*tm
)
1631 struct rainfo
*rai
= (struct rainfo
*)data
;
1635 * Whenever a multicast advertisement is sent from an interface,
1636 * the timer is reset to a uniformly-distributed random value
1637 * between the interface's configured MinRtrAdvInterval and
1638 * MaxRtrAdvInterval (RFC2461 6.2.4).
1640 interval
= rai
->mininterval
;
1641 interval
+= random() % (rai
->maxinterval
- rai
->mininterval
);
1644 * The first advertisement is sent as soon as rtadvd starts up
1645 * and for the next few advertisements (up to
1646 * MAX_INITIAL_RTR_ADVERTISEMENTS), if the randomly chosen interval
1647 * is greater than MAX_INITIAL_RTR_ADVERT_INTERVAL, the timer
1648 * SHOULD be set to MAX_INITIAL_RTR_ADVERT_INTERVAL instead.
1651 if (rai
->initcounter
< MAX_INITIAL_RTR_ADVERTISEMENTS
&&
1652 interval
> MAX_INITIAL_RTR_ADVERT_INTERVAL
)
1653 interval
= MAX_INITIAL_RTR_ADVERT_INTERVAL
;
1655 tm
->tv_sec
= rai
->initcounter
== 0 ? 0 : interval
;
1659 "<%s> RA timer on %s is set to %ld:%ld",
1660 __func__
, rai
->ifname
,
1661 (long int)tm
->tv_sec
, (long int)tm
->tv_usec
);