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.
5 * Copyright (C) 2011 Hiroki Sato <hrs@FreeBSD.org>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the project nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #include <sys/param.h>
34 #include <sys/socket.h>
37 #include <sys/queue.h>
40 #include <net/route.h>
41 #include <net/if_dl.h>
42 #include <netinet/in.h>
43 #include <netinet/ip6.h>
44 #include <netinet6/ip6_var.h>
45 #include <netinet/icmp6.h>
47 #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 */
88 char *conffile
= NULL
;
90 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
;
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 /* timer initialization */
206 /* random value initialization */
207 srandom((u_long
)time(NULL
));
209 /* get iflist block from kernel */
215 if (inet_pton(AF_INET6
, ALLNODES
, &sin6_allnodes
.sin6_addr
) != 1) {
216 fprintf(stderr
, "fatal: inet_pton failed\n");
220 pfh
= pidfile_open(pidfilename
, 0600, &otherpid
);
223 errx(1, "%s already running, pid: %d",
224 getprogname(), otherpid
);
225 errorlog("<%s> failed to open the pid log file, run anyway.",
234 /* record the current PID */
246 fdmasks
= howmany(maxfd
+ 1, NFDBITS
) * sizeof(fd_mask
);
247 if ((fdsetp
= malloc(fdmasks
)) == NULL
) {
251 if ((selectfdp
= malloc(fdmasks
)) == NULL
) {
255 memset(fdsetp
, 0, fdmasks
);
256 FD_SET(sock
, fdsetp
);
258 FD_SET(rtsock
, fdsetp
);
260 signal(SIGTERM
, set_die
);
261 signal(SIGUSR1
, rtadvd_set_dump_file
);
264 memcpy(selectfdp
, fdsetp
, fdmasks
); /* reinitialize */
266 if (do_dump
) { /* SIGUSR1 */
268 rtadvd_dump_file(dumpfilename
);
276 /* timer expiration check and reset the timer */
277 timeout
= rtadvd_check_timer();
279 if (timeout
!= NULL
) {
280 debuglog("<%s> set timer to %ld:%ld. waiting for "
281 "inputs or timeout", __func__
,
282 (long int)timeout
->tv_sec
,
283 (long int)timeout
->tv_usec
);
285 debuglog("<%s> there's no timer. waiting for inputs",
289 if ((i
= select(maxfd
+ 1, selectfdp
, NULL
, NULL
,
291 /* EINTR would occur upon SIGUSR1 for status dump */
293 errorlog( "<%s> select: %s",
294 __func__
, strerror(errno
));
297 if (i
== 0) /* timeout */
299 if (rtsock
!= -1 && FD_ISSET(rtsock
, selectfdp
))
301 if (FD_ISSET(sock
, selectfdp
))
304 exit(0); /* NOTREACHED */
308 rtadvd_set_dump_file(sig
)
326 const int retrans
= MAX_FINAL_RTR_ADVERTISEMENTS
;
329 debuglog("<%s> cease to be an advertising router\n",
333 for (ra
= ralist
; ra
; ra
= ra
->next
) {
337 for (i
= 0; i
< retrans
; i
++) {
338 for (ra
= ralist
; ra
; ra
= ra
->next
)
342 sleep(MIN_DELAY_BETWEEN_RAS
);
352 int n
, type
, ifindex
= 0, plen
;
354 char msg
[2048], *next
, *lim
;
355 char ifname
[IF_NAMESIZE
];
356 struct prefix
*prefix
;
358 struct in6_addr
*addr
;
359 char addrbuf
[INET6_ADDRSTRLEN
];
360 int prefixchange
= 0;
362 n
= read(rtsock
, msg
, sizeof(msg
));
364 debuglog( "<%s> received a routing message "
365 "(type = %d, len = %d)", __func__
, rtmsg_type(msg
), n
);
367 if (n
> rtmsg_len(msg
)) {
369 * This usually won't happen for messages received on
373 debuglog("<%s> received data length is larger than "
374 "1st routing message len. multiple messages? "
375 "read %d bytes, but 1st msg len = %d",
376 __func__
, n
, rtmsg_len(msg
));
384 for (next
= msg
; next
< lim
; next
+= len
) {
385 struct if_msghdr
* ifm
= NULL
;
388 next
= get_next_msg(next
, lim
, 0, &len
,
389 RTADV_TYPE2BITMASK(RTM_ADD
) |
390 RTADV_TYPE2BITMASK(RTM_DELETE
) |
391 RTADV_TYPE2BITMASK(RTM_NEWADDR
) |
392 RTADV_TYPE2BITMASK(RTM_DELADDR
) |
393 RTADV_TYPE2BITMASK(RTM_IFINFO
));
396 type
= rtmsg_type(next
);
400 ifindex
= get_rtm_ifindex(next
);
404 ifindex
= get_ifam_ifindex(next
);
407 ifindex
= get_ifm_ifindex(next
);
410 /* should not reach here */
412 debuglog("<%s:%d> unknown rtmsg %d on %s",
413 __func__
, __LINE__
, type
,
414 if_indextoname(ifindex
, ifname
));
419 if ((rai
= if_indextorainfo(ifindex
)) == NULL
) {
421 debuglog("<%s> route changed on "
422 "non advertising interface(%s)",
424 if_indextoname(ifindex
, ifname
));
428 ifm
= get_interface_entry(ifindex
);
430 debuglog("Couldn't find interface entry for %d. Skipping.", ifindex
);
433 oldifflags
= ifm
->ifm_flags
;
437 /* init ifflags because it may have changed */
439 if_getflags(ifindex
, ifm
->ifm_flags
);
442 break; /* we aren't interested in prefixes */
444 addr
= get_addr(msg
);
445 plen
= get_prefixlen(msg
);
446 /* sanity check for plen */
447 /* as RFC2373, prefixlen is at least 4 */
448 if (plen
< 4 || plen
> 127) {
449 infolog("<%s> new interface route's"
450 "plen %d is invalid for a prefix",
454 prefix
= find_prefix(rai
, addr
, plen
);
458 * If the prefix has been invalidated,
459 * make it available again.
461 update_prefix(prefix
);
463 } else if (dflag
> 1) {
464 debuglog("<%s> new prefix(%s/%d) "
466 "but it was already in list",
468 inet_ntop(AF_INET6
, addr
,
469 (char *)addrbuf
, INET6_ADDRSTRLEN
),
474 make_prefix(rai
, ifindex
, addr
, plen
);
478 /* init ifflags because it may have changed */
479 ifm
->ifm_flags
= if_getflags(ifindex
, ifm
->ifm_flags
);
484 addr
= get_addr(msg
);
485 plen
= get_prefixlen(msg
);
486 /* sanity check for plen */
487 /* as RFC2373, prefixlen is at least 4 */
488 if (plen
< 4 || plen
> 127) {
489 infolog("<%s> deleted interface route's "
490 "plen %d is invalid for a prefix",
494 prefix
= find_prefix(rai
, addr
, plen
);
495 if (prefix
== NULL
) {
497 debuglog("<%s> prefix(%s/%d) was "
499 "but it was not in list",
501 inet_ntop(AF_INET6
, addr
,
502 (char *)addrbuf
, INET6_ADDRSTRLEN
),
507 invalidate_prefix(prefix
);
512 /* init ifflags because it may have changed */
513 ifm
->ifm_flags
= if_getflags(ifindex
, ifm
->ifm_flags
);
516 ifm
->ifm_flags
= get_ifm_flags(next
);
519 /* should not reach here */
521 debuglog("<%s:%d> unknown rtmsg %d on %s",
522 __func__
, __LINE__
, type
,
523 if_indextoname(ifindex
, ifname
));
528 /* check if an interface flag is changed */
529 if ((oldifflags
& IFF_UP
) && /* UP to DOWN */
530 !(ifm
->ifm_flags
& IFF_UP
)) {
531 infolog("<%s> interface %s becomes down. stop timer.",
532 __func__
, rai
->ifname
);
533 rtadvd_remove_timer(&rai
->timer
);
534 } else if (!(oldifflags
& IFF_UP
) && /* DOWN to UP */
535 (ifm
->ifm_flags
& IFF_UP
)) {
536 infolog("<%s> interface %s becomes up. restart timer.",
537 __func__
, rai
->ifname
);
539 rai
->initcounter
= 0; /* reset the counter */
540 rai
->waiting
= 0; /* XXX */
541 rai
->timer
= rtadvd_add_timer(ra_timeout
,
542 ra_timer_update
, rai
, rai
);
543 ra_timer_update((void *)rai
, &rai
->timer
->tm
);
544 rtadvd_set_timer(&rai
->timer
->tm
, rai
->timer
);
545 } else if (prefixchange
&&
546 (ifm
->ifm_flags
& IFF_UP
)) {
548 * An advertised prefix has been added or invalidated.
549 * Will notice the change in a short delay.
551 rai
->initcounter
= 0;
552 set_short_delay(rai
);
567 struct icmp6_hdr
*icp
;
570 struct in6_pktinfo
*pi
= NULL
;
571 char ntopbuf
[INET6_ADDRSTRLEN
], ifnamebuf
[IFNAMSIZ
];
572 struct in6_addr dst
= in6addr_any
;
573 struct if_msghdr
*ifm
= NULL
;
576 * Get message. We reset msg_controllen since the field could
577 * be modified if we had received a message before setting
580 rcvmhdr
.msg_controllen
= rcvcmsgbuflen
;
581 if ((i
= recvmsg(sock
, &rcvmhdr
, 0)) < 0)
584 /* extract optional information via Advanced API */
585 for (cm
= (struct cmsghdr
*)CMSG_FIRSTHDR(&rcvmhdr
);
587 cm
= (struct cmsghdr
*)CMSG_NXTHDR(&rcvmhdr
, cm
)) {
588 if (cm
->cmsg_level
== IPPROTO_IPV6
&&
589 cm
->cmsg_type
== IPV6_PKTINFO
&&
590 cm
->cmsg_len
== CMSG_LEN(sizeof(struct in6_pktinfo
))) {
591 pi
= (struct in6_pktinfo
*)(CMSG_DATA(cm
));
592 ifindex
= pi
->ipi6_ifindex
;
595 if (cm
->cmsg_level
== IPPROTO_IPV6
&&
596 cm
->cmsg_type
== IPV6_HOPLIMIT
&&
597 cm
->cmsg_len
== CMSG_LEN(sizeof(int)))
598 hlimp
= (int *)CMSG_DATA(cm
);
601 errorlog("<%s> failed to get receiving interface",
606 errorlog("<%s> failed to get receiving hop limit",
611 ifm
= get_interface_entry(pi
->ipi6_ifindex
);
613 * If we happen to receive data on an interface which is now gone
614 * or down, just discard the data.
617 (ifm
->ifm_flags
& IFF_UP
) == 0) {
618 infolog("<%s> received data on a disabled interface (%s)",
620 (ifm
== NULL
) ? "[gone]" :
621 if_indextoname(pi
->ipi6_ifindex
, ifnamebuf
));
626 if (i
< sizeof(struct ip6_hdr
) + sizeof(struct icmp6_hdr
)) {
627 errorlog("<%s> packet size(%d) is too short",
632 ip
= (struct ip6_hdr
*)rcvmhdr
.msg_iov
[0].iov_base
;
633 icp
= (struct icmp6_hdr
*)(ip
+ 1); /* XXX: ext. hdr? */
635 if (i
< sizeof(struct icmp6_hdr
)) {
636 errorlog("<%s> packet size(%d) is too short",
641 icp
= (struct icmp6_hdr
*)rcvmhdr
.msg_iov
[0].iov_base
;
644 switch (icp
->icmp6_type
) {
645 case ND_ROUTER_SOLICIT
:
647 * Message verification - RFC-2461 6.1.1
648 * XXX: these checks must be done in the kernel as well,
649 * but we can't completely rely on them.
652 noticelog("<%s> RS with invalid hop limit(%d) "
653 "received from %s on %s",
655 inet_ntop(AF_INET6
, &rcvfrom
.sin6_addr
, ntopbuf
,
657 if_indextoname(pi
->ipi6_ifindex
, ifnamebuf
));
660 if (icp
->icmp6_code
) {
661 noticelog("<%s> RS with invalid ICMP6 code(%d) "
662 "received from %s on %s",
663 __func__
, icp
->icmp6_code
,
664 inet_ntop(AF_INET6
, &rcvfrom
.sin6_addr
, ntopbuf
,
666 if_indextoname(pi
->ipi6_ifindex
, ifnamebuf
));
669 if (i
< sizeof(struct nd_router_solicit
)) {
670 noticelog("<%s> RS from %s on %s does not have enough "
673 inet_ntop(AF_INET6
, &rcvfrom
.sin6_addr
, ntopbuf
,
675 if_indextoname(pi
->ipi6_ifindex
, ifnamebuf
), i
);
678 rs_input(i
, (struct nd_router_solicit
*)icp
, pi
, &rcvfrom
);
680 case ND_ROUTER_ADVERT
:
682 * Message verification - RFC-2461 6.1.2
683 * XXX: there's a same dilemma as above...
686 noticelog("<%s> RA with invalid hop limit(%d) "
687 "received from %s on %s",
689 inet_ntop(AF_INET6
, &rcvfrom
.sin6_addr
, ntopbuf
,
691 if_indextoname(pi
->ipi6_ifindex
, ifnamebuf
));
694 if (icp
->icmp6_code
) {
695 noticelog("<%s> RA with invalid ICMP6 code(%d) "
696 "received from %s on %s",
697 __func__
, icp
->icmp6_code
,
698 inet_ntop(AF_INET6
, &rcvfrom
.sin6_addr
, ntopbuf
,
700 if_indextoname(pi
->ipi6_ifindex
, ifnamebuf
));
703 if (i
< sizeof(struct nd_router_advert
)) {
704 noticelog("<%s> RA from %s on %s does not have enough "
707 inet_ntop(AF_INET6
, &rcvfrom
.sin6_addr
, ntopbuf
,
709 if_indextoname(pi
->ipi6_ifindex
, ifnamebuf
), i
);
712 ra_input(i
, (struct nd_router_advert
*)icp
, pi
, &rcvfrom
);
714 case ICMP6_ROUTER_RENUMBERING
:
715 if (accept_rr
== 0) {
716 errorlog("<%s> received a router renumbering "
717 "message, but not allowed to be accepted",
721 rr_input(i
, (struct icmp6_router_renum
*)icp
, pi
, &rcvfrom
,
726 * Note that this case is POSSIBLE, especially just
727 * after invocation of the daemon. This is because we
728 * could receive message after opening the socket and
729 * before setting ICMP6 type filter(see sock_open()).
731 errorlog("<%s> invalid icmp type(%d)",
732 __func__
, icp
->icmp6_type
);
740 rs_input(int len
, struct nd_router_solicit
*rs
,
741 struct in6_pktinfo
*pi
, struct sockaddr_in6
*from
)
743 char ntopbuf
[INET6_ADDRSTRLEN
], ifnamebuf
[IFNAMSIZ
];
744 union nd_opts ndopts
;
746 struct soliciter
*sol
;
749 "<%s> RS received from %s on %s",
751 inet_ntop(AF_INET6
, &from
->sin6_addr
,
752 ntopbuf
, INET6_ADDRSTRLEN
),
753 if_indextoname(pi
->ipi6_ifindex
, ifnamebuf
));
755 /* ND option check */
756 memset(&ndopts
, 0, sizeof(ndopts
));
757 if (nd6_options((struct nd_opt_hdr
*)(rs
+ 1),
758 len
- sizeof(struct nd_router_solicit
),
759 &ndopts
, NDOPT_FLAG_SRCLINKADDR
)) {
760 infolog("<%s> ND option check failed for an RS from %s on %s",
762 inet_ntop(AF_INET6
, &from
->sin6_addr
,
763 ntopbuf
, INET6_ADDRSTRLEN
),
764 if_indextoname(pi
->ipi6_ifindex
, ifnamebuf
));
769 * If the IP source address is the unspecified address, there
770 * must be no source link-layer address option in the message.
773 if (IN6_IS_ADDR_UNSPECIFIED(&from
->sin6_addr
) &&
774 ndopts
.nd_opts_src_lladdr
) {
775 infolog("<%s> RS from unspecified src on %s has a link-layer"
778 if_indextoname(pi
->ipi6_ifindex
, ifnamebuf
));
784 if (pi
->ipi6_ifindex
== ra
->ifindex
)
789 infolog("<%s> RS received on non advertising interface(%s)",
791 if_indextoname(pi
->ipi6_ifindex
, ifnamebuf
));
795 ra
->rsinput
++; /* increment statistics */
798 * Decide whether to send RA according to the rate-limit
802 /* record sockaddr waiting for RA, if possible */
803 sol
= (struct soliciter
*)malloc(sizeof(*sol
));
806 /* XXX RFC2553 need clarification on flowinfo */
807 sol
->addr
.sin6_flowinfo
= 0;
808 sol
->next
= ra
->soliciter
;
813 * If there is already a waiting RS packet, don't
822 free_ndopts(&ndopts
);
830 long delay
; /* must not be greater than 1000000 */
831 struct timeval interval
, now
, min_delay
, tm_tmp
, *rest
;
833 if (rai
->timer
== NULL
)
836 * Compute a random delay. If the computed value
837 * corresponds to a time later than the time the next
838 * multicast RA is scheduled to be sent, ignore the random
839 * delay and send the advertisement at the
840 * already-scheduled time. RFC-2461 6.2.6
842 #ifdef HAVE_ARC4RANDOM
843 delay
= arc4random_uniform(MAX_RA_DELAY_TIME
);
845 delay
= random() % MAX_RA_DELAY_TIME
;
848 interval
.tv_usec
= delay
;
849 rest
= rtadvd_timer_rest(rai
->timer
);
850 if (TIMEVAL_LT(*rest
, interval
)) {
851 debuglog("<%s> random delay is larger than "
852 "the rest of the current timer", __func__
);
857 * If we sent a multicast Router Advertisement within
858 * the last MIN_DELAY_BETWEEN_RAS seconds, schedule
859 * the advertisement to be sent at a time corresponding to
860 * MIN_DELAY_BETWEEN_RAS plus the random value after the
861 * previous advertisement was sent.
863 gettimeofday(&now
, NULL
);
864 TIMEVAL_SUB(&now
, &rai
->lastsent
, &tm_tmp
);
865 min_delay
.tv_sec
= MIN_DELAY_BETWEEN_RAS
;
866 min_delay
.tv_usec
= 0;
867 if (TIMEVAL_LT(tm_tmp
, min_delay
)) {
868 TIMEVAL_SUB(&min_delay
, &tm_tmp
, &min_delay
);
869 TIMEVAL_ADD(&min_delay
, &interval
, &interval
);
871 rtadvd_set_timer(&interval
, rai
->timer
);
875 ra_input(int len
, struct nd_router_advert
*ra
,
876 struct in6_pktinfo
*pi
, struct sockaddr_in6
*from
)
879 char ntopbuf
[INET6_ADDRSTRLEN
], ifnamebuf
[IFNAMSIZ
];
880 union nd_opts ndopts
;
881 char *on_off
[] = {"OFF", "ON"};
882 u_int32_t reachabletime
, retranstimer
, mtu
;
883 int inconsistent
= 0;
885 debuglog("<%s> RA received from %s on %s",
887 inet_ntop(AF_INET6
, &from
->sin6_addr
,
888 ntopbuf
, INET6_ADDRSTRLEN
),
889 if_indextoname(pi
->ipi6_ifindex
, ifnamebuf
));
891 /* ND option check */
892 memset(&ndopts
, 0, sizeof(ndopts
));
893 if (nd6_options((struct nd_opt_hdr
*)(ra
+ 1),
894 len
- sizeof(struct nd_router_advert
),
895 &ndopts
, NDOPT_FLAG_SRCLINKADDR
|
896 NDOPT_FLAG_PREFIXINFO
| NDOPT_FLAG_MTU
)) {
897 infolog("<%s> ND option check failed for an RA from %s on %s",
899 inet_ntop(AF_INET6
, &from
->sin6_addr
,
900 ntopbuf
, INET6_ADDRSTRLEN
),
901 if_indextoname(pi
->ipi6_ifindex
, ifnamebuf
));
906 * RA consistency check according to RFC-2461 6.2.7
908 if ((rai
= if_indextorainfo(pi
->ipi6_ifindex
)) == 0) {
909 infolog("<%s> received RA from %s on non-advertising"
912 inet_ntop(AF_INET6
, &from
->sin6_addr
,
913 ntopbuf
, INET6_ADDRSTRLEN
),
914 if_indextoname(pi
->ipi6_ifindex
, ifnamebuf
));
917 rai
->rainput
++; /* increment statistics */
919 /* Cur Hop Limit value */
920 if (ra
->nd_ra_curhoplimit
&& rai
->hoplimit
&&
921 ra
->nd_ra_curhoplimit
!= rai
->hoplimit
) {
922 infolog("<%s> CurHopLimit inconsistent on %s:"
923 " %d from %s, %d from us",
926 ra
->nd_ra_curhoplimit
,
927 inet_ntop(AF_INET6
, &from
->sin6_addr
,
928 ntopbuf
, INET6_ADDRSTRLEN
),
933 if ((ra
->nd_ra_flags_reserved
& ND_RA_FLAG_MANAGED
) !=
935 infolog("<%s> M flag inconsistent on %s:"
936 " %s from %s, %s from us",
939 on_off
[!rai
->managedflg
],
940 inet_ntop(AF_INET6
, &from
->sin6_addr
,
941 ntopbuf
, INET6_ADDRSTRLEN
),
942 on_off
[rai
->managedflg
]);
946 if ((ra
->nd_ra_flags_reserved
& ND_RA_FLAG_OTHER
) !=
948 infolog("<%s> O flag inconsistent on %s:"
949 " %s from %s, %s from us",
952 on_off
[!rai
->otherflg
],
953 inet_ntop(AF_INET6
, &from
->sin6_addr
,
954 ntopbuf
, INET6_ADDRSTRLEN
),
955 on_off
[rai
->otherflg
]);
959 reachabletime
= ntohl(ra
->nd_ra_reachable
);
960 if (reachabletime
&& rai
->reachabletime
&&
961 reachabletime
!= rai
->reachabletime
) {
962 infolog("<%s> ReachableTime inconsistent on %s:"
963 " %d from %s, %d from us",
967 inet_ntop(AF_INET6
, &from
->sin6_addr
,
968 ntopbuf
, INET6_ADDRSTRLEN
),
973 retranstimer
= ntohl(ra
->nd_ra_retransmit
);
974 if (retranstimer
&& rai
->retranstimer
&&
975 retranstimer
!= rai
->retranstimer
) {
976 infolog("<%s> RetranceTimer inconsistent on %s:"
977 " %d from %s, %d from us",
981 inet_ntop(AF_INET6
, &from
->sin6_addr
,
982 ntopbuf
, INET6_ADDRSTRLEN
),
986 /* Values in the MTU options */
987 if (ndopts
.nd_opts_mtu
) {
988 mtu
= ntohl(ndopts
.nd_opts_mtu
->nd_opt_mtu_mtu
);
989 if (mtu
&& rai
->linkmtu
&& mtu
!= rai
->linkmtu
) {
990 infolog("<%s> MTU option value inconsistent on %s:"
991 " %d from %s, %d from us",
994 inet_ntop(AF_INET6
, &from
->sin6_addr
,
995 ntopbuf
, INET6_ADDRSTRLEN
),
1000 /* Preferred and Valid Lifetimes for prefixes */
1002 struct nd_optlist
*optp
= ndopts
.nd_opts_list
;
1004 if (ndopts
.nd_opts_pi
) {
1005 if (prefix_check(ndopts
.nd_opts_pi
, rai
, from
))
1009 if (prefix_check((struct nd_opt_prefix_info
*)optp
->opt
,
1017 rai
->rainconsistent
++;
1020 free_ndopts(&ndopts
);
1024 /* return a non-zero value if the received prefix is inconsitent with ours */
1026 prefix_check(struct nd_opt_prefix_info
*pinfo
,
1027 struct rainfo
*rai
, struct sockaddr_in6
*from
)
1029 u_int32_t preferred_time
, valid_time
;
1031 int inconsistent
= 0;
1032 char ntopbuf
[INET6_ADDRSTRLEN
], prefixbuf
[INET6_ADDRSTRLEN
];
1035 #if 0 /* impossible */
1036 if (pinfo
->nd_opt_pi_type
!= ND_OPT_PREFIX_INFORMATION
)
1041 * log if the adveritsed prefix has link-local scope(sanity check?)
1043 if (IN6_IS_ADDR_LINKLOCAL(&pinfo
->nd_opt_pi_prefix
)) {
1044 infolog("<%s> link-local prefix %s/%d is advertised "
1047 inet_ntop(AF_INET6
, &pinfo
->nd_opt_pi_prefix
,
1048 prefixbuf
, INET6_ADDRSTRLEN
),
1049 pinfo
->nd_opt_pi_prefix_len
,
1050 inet_ntop(AF_INET6
, &from
->sin6_addr
,
1051 ntopbuf
, INET6_ADDRSTRLEN
),
1055 if ((pp
= find_prefix(rai
, &pinfo
->nd_opt_pi_prefix
,
1056 pinfo
->nd_opt_pi_prefix_len
)) == NULL
) {
1057 infolog("<%s> prefix %s/%d from %s on %s is not in our list",
1059 inet_ntop(AF_INET6
, &pinfo
->nd_opt_pi_prefix
,
1060 prefixbuf
, INET6_ADDRSTRLEN
),
1061 pinfo
->nd_opt_pi_prefix_len
,
1062 inet_ntop(AF_INET6
, &from
->sin6_addr
,
1063 ntopbuf
, INET6_ADDRSTRLEN
),
1068 preferred_time
= ntohl(pinfo
->nd_opt_pi_preferred_time
);
1069 if (pp
->pltimeexpire
) {
1071 * The lifetime is decremented in real time, so we should
1072 * compare the expiration time.
1073 * (RFC 2461 Section 6.2.7.)
1074 * XXX: can we really expect that all routers on the link
1075 * have synchronized clocks?
1077 gettimeofday(&now
, NULL
);
1078 preferred_time
+= now
.tv_sec
;
1080 if (!pp
->timer
&& rai
->clockskew
&&
1081 preferred_time
- pp
->pltimeexpire
> rai
->clockskew
) {
1082 infolog("<%s> preferred lifetime for %s/%d"
1083 " (decr. in real time) inconsistent on %s:"
1084 " %d from %s, %ld from us",
1086 inet_ntop(AF_INET6
, &pinfo
->nd_opt_pi_prefix
,
1087 prefixbuf
, INET6_ADDRSTRLEN
),
1088 pinfo
->nd_opt_pi_prefix_len
,
1089 rai
->ifname
, preferred_time
,
1090 inet_ntop(AF_INET6
, &from
->sin6_addr
,
1091 ntopbuf
, INET6_ADDRSTRLEN
),
1095 } else if (!pp
->timer
&& preferred_time
!= pp
->preflifetime
) {
1096 infolog("<%s> preferred lifetime for %s/%d"
1097 " inconsistent on %s:"
1098 " %d from %s, %d from us",
1100 inet_ntop(AF_INET6
, &pinfo
->nd_opt_pi_prefix
,
1101 prefixbuf
, INET6_ADDRSTRLEN
),
1102 pinfo
->nd_opt_pi_prefix_len
,
1103 rai
->ifname
, preferred_time
,
1104 inet_ntop(AF_INET6
, &from
->sin6_addr
,
1105 ntopbuf
, INET6_ADDRSTRLEN
),
1109 valid_time
= ntohl(pinfo
->nd_opt_pi_valid_time
);
1110 if (pp
->vltimeexpire
) {
1111 gettimeofday(&now
, NULL
);
1112 valid_time
+= now
.tv_sec
;
1114 if (!pp
->timer
&& rai
->clockskew
&&
1115 valid_time
- pp
->vltimeexpire
> rai
->clockskew
) {
1116 infolog("<%s> valid lifetime for %s/%d"
1117 " (decr. in real time) inconsistent on %s:"
1118 " %d from %s, %ld from us",
1120 inet_ntop(AF_INET6
, &pinfo
->nd_opt_pi_prefix
,
1121 prefixbuf
, INET6_ADDRSTRLEN
),
1122 pinfo
->nd_opt_pi_prefix_len
,
1123 rai
->ifname
, preferred_time
,
1124 inet_ntop(AF_INET6
, &from
->sin6_addr
,
1125 ntopbuf
, INET6_ADDRSTRLEN
),
1129 } else if (!pp
->timer
&& valid_time
!= pp
->validlifetime
) {
1130 infolog("<%s> valid lifetime for %s/%d"
1131 " inconsistent on %s:"
1132 " %d from %s, %d from us",
1134 inet_ntop(AF_INET6
, &pinfo
->nd_opt_pi_prefix
,
1135 prefixbuf
, INET6_ADDRSTRLEN
),
1136 pinfo
->nd_opt_pi_prefix_len
,
1137 rai
->ifname
, valid_time
,
1138 inet_ntop(AF_INET6
, &from
->sin6_addr
,
1139 ntopbuf
, INET6_ADDRSTRLEN
),
1144 return(inconsistent
);
1148 find_prefix(struct rainfo
*rai
, struct in6_addr
*prefix
, int plen
)
1151 int bytelen
, bitlen
;
1154 for (pp
= rai
->prefix
.next
; pp
!= &rai
->prefix
; pp
= pp
->next
) {
1155 if (plen
!= pp
->prefixlen
)
1159 bitmask
= 0xff << (8 - bitlen
);
1160 if (memcmp((void *)prefix
, (void *)&pp
->prefix
, bytelen
))
1163 ((prefix
->s6_addr
[bytelen
] & bitmask
) ==
1164 (pp
->prefix
.s6_addr
[bytelen
] & bitmask
))) {
1172 /* check if p0/plen0 matches p1/plen1; return 1 if matches, otherwise 0. */
1174 prefix_match(struct in6_addr
*p0
, int plen0
,
1175 struct in6_addr
*p1
, int plen1
)
1177 int bytelen
, bitlen
;
1182 bytelen
= plen1
/ 8;
1184 bitmask
= 0xff << (8 - bitlen
);
1185 if (memcmp((void *)p0
, (void *)p1
, bytelen
))
1188 ((p0
->s6_addr
[bytelen
] & bitmask
) ==
1189 (p1
->s6_addr
[bytelen
] & bitmask
))) {
1197 nd6_options(struct nd_opt_hdr
*hdr
, int limit
,
1198 union nd_opts
*ndopts
, u_int32_t optflags
)
1202 for (; limit
> 0; limit
-= optlen
) {
1203 if (limit
< sizeof(struct nd_opt_hdr
)) {
1204 infolog("<%s> short option header", __func__
);
1208 hdr
= (struct nd_opt_hdr
*)((caddr_t
)hdr
+ optlen
);
1209 if (hdr
->nd_opt_len
== 0) {
1210 infolog("<%s> bad ND option length(0) (type = %d)",
1211 __func__
, hdr
->nd_opt_type
);
1214 optlen
= hdr
->nd_opt_len
<< 3;
1215 if (optlen
> limit
) {
1216 infolog("<%s> short option", __func__
);
1220 if (hdr
->nd_opt_type
> ND_OPT_MTU
) {
1221 infolog("<%s> unknown ND option(type %d)",
1222 __func__
, hdr
->nd_opt_type
);
1226 if ((ndopt_flags
[hdr
->nd_opt_type
] & optflags
) == 0) {
1227 infolog("<%s> unexpected ND option(type %d)",
1228 __func__
, hdr
->nd_opt_type
);
1233 * Option length check. Do it here for all fixed-length
1236 if ((hdr
->nd_opt_type
== ND_OPT_MTU
&&
1237 (optlen
!= sizeof(struct nd_opt_mtu
))) ||
1238 ((hdr
->nd_opt_type
== ND_OPT_PREFIX_INFORMATION
&&
1239 optlen
!= sizeof(struct nd_opt_prefix_info
)))) {
1240 infolog("<%s> invalid option length",
1245 switch (hdr
->nd_opt_type
) {
1246 case ND_OPT_TARGET_LINKADDR
:
1247 case ND_OPT_REDIRECTED_HEADER
:
1248 break; /* we don't care about these options */
1249 case ND_OPT_SOURCE_LINKADDR
:
1251 if (ndopts
->nd_opt_array
[hdr
->nd_opt_type
]) {
1252 infolog("<%s> duplicated ND option (type = %d)",
1253 __func__
, hdr
->nd_opt_type
);
1255 ndopts
->nd_opt_array
[hdr
->nd_opt_type
] = hdr
;
1257 case ND_OPT_PREFIX_INFORMATION
:
1259 struct nd_optlist
*pfxlist
;
1261 if (ndopts
->nd_opts_pi
== 0) {
1262 ndopts
->nd_opts_pi
=
1263 (struct nd_opt_prefix_info
*)hdr
;
1266 if ((pfxlist
= malloc(sizeof(*pfxlist
))) == NULL
) {
1267 errorlog("<%s> can't allocate memory",
1271 pfxlist
->next
= ndopts
->nd_opts_list
;
1273 ndopts
->nd_opts_list
= pfxlist
;
1277 default: /* impossible */
1285 free_ndopts(ndopts
);
1291 free_ndopts(union nd_opts
*ndopts
)
1293 struct nd_optlist
*opt
= ndopts
->nd_opts_list
, *next
;
1305 struct icmp6_filter filt
;
1306 struct ipv6_mreq mreq
;
1307 struct rainfo
*ra
= ralist
;
1309 /* XXX: should be max MTU attached to the node */
1310 static u_char answer
[1500];
1312 rcvcmsgbuflen
= CMSG_SPACE(sizeof(struct in6_pktinfo
)) +
1313 CMSG_SPACE(sizeof(int));
1314 rcvcmsgbuf
= (u_char
*)malloc(rcvcmsgbuflen
);
1315 if (rcvcmsgbuf
== NULL
) {
1316 errorlog("<%s> not enough core", __func__
);
1320 sndcmsgbuflen
= CMSG_SPACE(sizeof(struct in6_pktinfo
)) +
1321 CMSG_SPACE(sizeof(int));
1322 sndcmsgbuf
= (u_char
*)malloc(sndcmsgbuflen
);
1323 if (sndcmsgbuf
== NULL
) {
1324 errorlog("<%s> not enough core", __func__
);
1328 if ((sock
= socket(AF_INET6
, SOCK_RAW
, IPPROTO_ICMPV6
)) < 0) {
1329 errorlog("<%s> socket: %s", __func__
,
1334 (void) setsockopt(sock
, SOL_SOCKET
, SO_TRAFFIC_CLASS
,
1335 (void *)&so_traffic_class
, sizeof (so_traffic_class
));
1337 /* specify to tell receiving interface */
1339 #ifdef IPV6_RECVPKTINFO
1340 if (setsockopt(sock
, IPPROTO_IPV6
, IPV6_RECVPKTINFO
, &on
,
1342 errorlog("<%s> IPV6_RECVPKTINFO: %s",
1343 __func__
, strerror(errno
));
1346 #else /* old adv. API */
1347 if (setsockopt(sock
, IPPROTO_IPV6
, IPV6_PKTINFO
, &on
,
1349 errorlog("<%s> IPV6_PKTINFO: %s",
1350 __func__
, strerror(errno
));
1356 /* specify to tell value of hoplimit field of received IP6 hdr */
1357 #ifdef IPV6_RECVHOPLIMIT
1358 if (setsockopt(sock
, IPPROTO_IPV6
, IPV6_RECVHOPLIMIT
, &on
,
1360 errorlog( "<%s> IPV6_RECVHOPLIMIT: %s",
1361 __func__
, strerror(errno
));
1364 #else /* old adv. API */
1365 if (setsockopt(sock
, IPPROTO_IPV6
, IPV6_HOPLIMIT
, &on
,
1367 errorlog("<%s> IPV6_HOPLIMIT: %s",
1368 __func__
, strerror(errno
));
1373 ICMP6_FILTER_SETBLOCKALL(&filt
);
1374 ICMP6_FILTER_SETPASS(ND_ROUTER_SOLICIT
, &filt
);
1375 ICMP6_FILTER_SETPASS(ND_ROUTER_ADVERT
, &filt
);
1377 ICMP6_FILTER_SETPASS(ICMP6_ROUTER_RENUMBERING
, &filt
);
1378 if (setsockopt(sock
, IPPROTO_ICMPV6
, ICMP6_FILTER
, &filt
,
1379 sizeof(filt
)) < 0) {
1380 errorlog("<%s> IICMP6_FILTER: %s",
1381 __func__
, strerror(errno
));
1386 * join all routers multicast address on each advertising interface.
1388 if (inet_pton(AF_INET6
, ALLROUTERS_LINK
,
1389 &mreq
.ipv6mr_multiaddr
.s6_addr
)
1391 errorlog("<%s> inet_pton failed(library bug?)",
1396 mreq
.ipv6mr_interface
= ra
->ifindex
;
1397 if (setsockopt(sock
, IPPROTO_IPV6
, IPV6_JOIN_GROUP
, &mreq
,
1398 sizeof(mreq
)) < 0) {
1399 errorlog("<%s> IPV6_JOIN_GROUP(link) on %s: %s",
1400 __func__
, ra
->ifname
, strerror(errno
));
1407 * When attending router renumbering, join all-routers site-local
1411 if (inet_pton(AF_INET6
, ALLROUTERS_SITE
,
1412 &in6a_site_allrouters
) != 1) {
1413 errorlog("<%s> inet_pton failed(library bug?)",
1417 mreq
.ipv6mr_multiaddr
= in6a_site_allrouters
;
1419 if ((mreq
.ipv6mr_interface
= if_nametoindex(mcastif
))
1421 errorlog("<%s> invalid interface: %s",
1426 mreq
.ipv6mr_interface
= ralist
->ifindex
;
1427 if (setsockopt(sock
, IPPROTO_IPV6
, IPV6_JOIN_GROUP
,
1428 &mreq
, sizeof(mreq
)) < 0) {
1429 errorlog("<%s> IPV6_JOIN_GROUP(site) on %s: %s",
1431 mcastif
? mcastif
: ralist
->ifname
,
1437 /* initialize msghdr for receiving packets */
1438 rcviov
[0].iov_base
= (caddr_t
)answer
;
1439 rcviov
[0].iov_len
= sizeof(answer
);
1440 rcvmhdr
.msg_name
= (caddr_t
)&rcvfrom
;
1441 rcvmhdr
.msg_namelen
= sizeof(rcvfrom
);
1442 rcvmhdr
.msg_iov
= rcviov
;
1443 rcvmhdr
.msg_iovlen
= 1;
1444 rcvmhdr
.msg_control
= (caddr_t
) rcvcmsgbuf
;
1445 rcvmhdr
.msg_controllen
= rcvcmsgbuflen
;
1447 /* initialize msghdr for sending packets */
1448 sndmhdr
.msg_namelen
= sizeof(struct sockaddr_in6
);
1449 sndmhdr
.msg_iov
= sndiov
;
1450 sndmhdr
.msg_iovlen
= 1;
1451 sndmhdr
.msg_control
= (caddr_t
)sndcmsgbuf
;
1452 sndmhdr
.msg_controllen
= sndcmsgbuflen
;
1457 /* open a routing socket to watch the routing table */
1461 if ((rtsock
= socket(PF_ROUTE
, SOCK_RAW
, 0)) < 0) {
1462 errorlog("<%s> socket: %s", __func__
, strerror(errno
));
1468 if_indextorainfo(int idx
)
1470 struct rainfo
*rai
= ralist
;
1472 for (rai
= ralist
; rai
; rai
= rai
->next
) {
1473 if (rai
->ifindex
== idx
)
1477 return(NULL
); /* search failed */
1482 struct rainfo
*rainfo
;
1486 struct in6_pktinfo
*pi
;
1487 struct soliciter
*sol
, *nextsol
;
1488 struct if_msghdr
*ifm
= get_interface_entry(rainfo
->ifindex
);
1491 (ifm
->ifm_flags
& IFF_UP
) == 0) {
1492 debuglog("<%s> %s is not up, skip sending RA",
1493 __func__
, rainfo
->ifname
);
1497 make_packet(rainfo
); /* XXX: inefficient */
1499 sndmhdr
.msg_name
= (caddr_t
)&sin6_allnodes
;
1500 sndmhdr
.msg_iov
[0].iov_base
= (caddr_t
)rainfo
->ra_data
;
1501 sndmhdr
.msg_iov
[0].iov_len
= rainfo
->ra_datalen
;
1503 cm
= CMSG_FIRSTHDR(&sndmhdr
);
1504 /* specify the outgoing interface */
1505 cm
->cmsg_level
= IPPROTO_IPV6
;
1506 cm
->cmsg_type
= IPV6_PKTINFO
;
1507 cm
->cmsg_len
= CMSG_LEN(sizeof(struct in6_pktinfo
));
1508 pi
= (struct in6_pktinfo
*)CMSG_DATA(cm
);
1509 memset(&pi
->ipi6_addr
, 0, sizeof(pi
->ipi6_addr
)); /*XXX*/
1510 pi
->ipi6_ifindex
= rainfo
->ifindex
;
1512 /* specify the hop limit of the packet */
1516 cm
= CMSG_NXTHDR(&sndmhdr
, cm
);
1517 cm
->cmsg_level
= IPPROTO_IPV6
;
1518 cm
->cmsg_type
= IPV6_HOPLIMIT
;
1519 cm
->cmsg_len
= CMSG_LEN(sizeof(int));
1520 memcpy(CMSG_DATA(cm
), &hoplimit
, sizeof(int));
1523 debuglog("<%s> send RA on %s, # of waitings = %d",
1524 __func__
, rainfo
->ifname
, rainfo
->waiting
);
1526 i
= sendmsg(sock
, &sndmhdr
, 0);
1528 if (i
< 0 || i
!= rainfo
->ra_datalen
) {
1530 errorlog("<%s> sendmsg on %s: %s",
1531 __func__
, rainfo
->ifname
,
1535 /* update counter */
1536 if (rainfo
->initcounter
< MAX_INITIAL_RTR_ADVERTISEMENTS
)
1537 rainfo
->initcounter
++;
1541 * unicast advertisements
1542 * XXX commented out. reason: though spec does not forbit it, unicast
1543 * advert does not really help
1545 for (sol
= rainfo
->soliciter
; sol
; sol
= nextsol
) {
1546 nextsol
= sol
->next
;
1551 rainfo
->soliciter
= NULL
;
1553 /* update timestamp */
1554 gettimeofday(&rainfo
->lastsent
, NULL
);
1556 /* reset waiting conter */
1557 rainfo
->waiting
= 0;
1560 /* process RA timer */
1561 struct rtadvd_timer
*
1562 ra_timeout(void *data
)
1564 struct rainfo
*rai
= (struct rainfo
*)data
;
1567 /* if necessary, reconstruct the packet. */
1570 debuglog("<%s> RA timer on %s is expired",
1571 __func__
, rai
->ifname
);
1578 /* update RA timer */
1580 ra_timer_update(void *data
, struct timeval
*tm
)
1582 struct rainfo
*rai
= (struct rainfo
*)data
;
1586 * Whenever a multicast advertisement is sent from an interface,
1587 * the timer is reset to a uniformly-distributed random value
1588 * between the interface's configured MinRtrAdvInterval and
1589 * MaxRtrAdvInterval (RFC2461 6.2.4).
1591 interval
= rai
->mininterval
;
1592 interval
+= random() % (rai
->maxinterval
- rai
->mininterval
);
1595 * The first advertisement is sent as soon as rtadvd starts up
1596 * and for the next few advertisements (up to
1597 * MAX_INITIAL_RTR_ADVERTISEMENTS), if the randomly chosen interval
1598 * is greater than MAX_INITIAL_RTR_ADVERT_INTERVAL, the timer
1599 * SHOULD be set to MAX_INITIAL_RTR_ADVERT_INTERVAL instead.
1602 if (rai
->initcounter
< MAX_INITIAL_RTR_ADVERTISEMENTS
&&
1603 interval
> MAX_INITIAL_RTR_ADVERT_INTERVAL
)
1604 interval
= MAX_INITIAL_RTR_ADVERT_INTERVAL
;
1606 tm
->tv_sec
= rai
->initcounter
== 0 ? 0 : interval
;
1609 debuglog("<%s> RA timer on %s is set to %ld:%ld",
1610 __func__
, rai
->ifname
,
1611 (long int)tm
->tv_sec
, (long int)tm
->tv_usec
);