2001-01-21 15:25:46 +00:00
|
|
|
/* $FreeBSD$ */
|
- supported a string notation for xxflags.
- deprecate routes#N, as it is hard to keep consistency with
rtprefixN. accept any number of "rtprefix", "rtrefix0",
..., "rtprefix99".
- deprecate "addrs#N", as it is difficult for users to keep
consistency with "addrN".
accept 100 prefix info in maximum - like "addr", "addr0"
... "addr99". WARNS=2 clean on netbsd.
old configuration file should work just fine.
behavior change:
previously, we rejected "addrN" if there's "addr", and we rejected
"addr" if there is "addrN". now we accept both without problem.
- when an advertised prefix configured from the kernel has been added
or invalidated, notice the change in a short delay.
- when invalidating a prefix, do not bark even if there is
inconsistency about prefix lifetimes.
- wrap more specific route info code into ROUTEINFO.
Obtained from: KAME
MFC after: 1 week
2003-08-15 19:13:53 +00:00
|
|
|
/* $KAME: rtadvd.c,v 1.82 2003/08/05 12:34:23 itojun Exp $ */
|
2000-07-05 22:09:50 +00:00
|
|
|
|
2000-01-06 12:40:54 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
|
2011-07-17 19:24:54 +00:00
|
|
|
* Copyright (C) 2011 Hiroki Sato <hrs@FreeBSD.org>
|
2000-01-06 12:40:54 +00:00
|
|
|
* All rights reserved.
|
2011-06-06 03:06:43 +00:00
|
|
|
*
|
2000-01-06 12:40:54 +00:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the name of the project nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
2011-06-06 03:06:43 +00:00
|
|
|
*
|
2000-01-06 12:40:54 +00:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
2011-06-06 03:06:43 +00:00
|
|
|
#include <sys/ioctl.h>
|
2000-01-06 12:40:54 +00:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/uio.h>
|
2001-06-11 12:39:29 +00:00
|
|
|
#include <sys/queue.h>
|
2011-07-17 19:24:54 +00:00
|
|
|
#include <sys/stat.h>
|
2011-06-06 03:06:43 +00:00
|
|
|
#include <sys/sysctl.h>
|
2000-01-06 12:40:54 +00:00
|
|
|
|
|
|
|
#include <net/if.h>
|
2011-07-17 19:24:54 +00:00
|
|
|
#include <net/if_types.h>
|
2011-06-06 03:06:43 +00:00
|
|
|
#include <net/if_media.h>
|
2000-01-06 12:40:54 +00:00
|
|
|
#include <net/if_dl.h>
|
2011-07-17 19:24:54 +00:00
|
|
|
#include <net/route.h>
|
2000-01-06 12:40:54 +00:00
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/ip6.h>
|
|
|
|
#include <netinet6/ip6_var.h>
|
|
|
|
#include <netinet/icmp6.h>
|
|
|
|
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
2011-06-06 03:06:43 +00:00
|
|
|
#include <netinet/in_var.h>
|
|
|
|
#include <netinet6/nd6.h>
|
|
|
|
|
2000-01-06 12:40:54 +00:00
|
|
|
#include <time.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
2011-07-17 19:24:54 +00:00
|
|
|
#include <inttypes.h>
|
2010-12-22 23:58:21 +00:00
|
|
|
#include <libutil.h>
|
2011-06-06 03:06:43 +00:00
|
|
|
#include <netdb.h>
|
2011-07-17 19:24:54 +00:00
|
|
|
#include <signal.h>
|
2000-01-06 12:40:54 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <syslog.h>
|
2003-08-14 18:43:57 +00:00
|
|
|
#include <poll.h>
|
|
|
|
|
2011-07-17 19:24:54 +00:00
|
|
|
#include "pathnames.h"
|
2000-01-06 12:40:54 +00:00
|
|
|
#include "rtadvd.h"
|
2011-07-17 19:24:54 +00:00
|
|
|
#include "if.h"
|
2000-01-06 12:40:54 +00:00
|
|
|
#include "rrenum.h"
|
|
|
|
#include "advcap.h"
|
2011-07-17 19:24:54 +00:00
|
|
|
#include "timer_subr.h"
|
2000-01-06 12:40:54 +00:00
|
|
|
#include "timer.h"
|
|
|
|
#include "config.h"
|
2011-07-17 19:24:54 +00:00
|
|
|
#include "control.h"
|
|
|
|
#include "control_server.h"
|
|
|
|
|
|
|
|
#define RTADV_TYPE2BITMASK(type) (0x1 << type)
|
2000-07-05 22:09:50 +00:00
|
|
|
|
|
|
|
struct msghdr rcvmhdr;
|
2011-07-17 19:24:54 +00:00
|
|
|
static char *rcvcmsgbuf;
|
2000-07-05 22:09:50 +00:00
|
|
|
static size_t rcvcmsgbuflen;
|
2011-07-17 19:24:54 +00:00
|
|
|
static char *sndcmsgbuf = NULL;
|
2000-07-05 22:09:50 +00:00
|
|
|
static size_t sndcmsgbuflen;
|
|
|
|
struct msghdr sndmhdr;
|
|
|
|
struct iovec rcviov[2];
|
|
|
|
struct iovec sndiov[2];
|
2003-08-14 16:51:13 +00:00
|
|
|
struct sockaddr_in6 rcvfrom;
|
2011-06-06 03:06:43 +00:00
|
|
|
static const char *pidfilename = _PATH_RTADVDPID;
|
|
|
|
const char *conffile = _PATH_RTADVDCONF;
|
2010-12-22 23:58:21 +00:00
|
|
|
static struct pidfh *pfh;
|
2013-07-09 07:08:36 +00:00
|
|
|
static int dflag, sflag;
|
2011-07-17 19:24:54 +00:00
|
|
|
static int wait_shutdown;
|
|
|
|
|
|
|
|
#define PFD_RAWSOCK 0
|
|
|
|
#define PFD_RTSOCK 1
|
|
|
|
#define PFD_CSOCK 2
|
|
|
|
#define PFD_MAX 3
|
2000-01-06 12:40:54 +00:00
|
|
|
|
2011-06-06 03:06:43 +00:00
|
|
|
struct railist_head_t railist =
|
|
|
|
TAILQ_HEAD_INITIALIZER(railist);
|
2011-07-17 19:24:54 +00:00
|
|
|
struct ifilist_head_t ifilist =
|
|
|
|
TAILQ_HEAD_INITIALIZER(ifilist);
|
2000-07-05 22:09:50 +00:00
|
|
|
|
|
|
|
struct nd_optlist {
|
2011-06-06 03:06:43 +00:00
|
|
|
TAILQ_ENTRY(nd_optlist) nol_next;
|
|
|
|
struct nd_opt_hdr *nol_opt;
|
2000-01-06 12:40:54 +00:00
|
|
|
};
|
2011-06-06 03:06:43 +00:00
|
|
|
union nd_opt {
|
|
|
|
struct nd_opt_hdr *opt_array[9];
|
2000-01-06 12:40:54 +00:00
|
|
|
struct {
|
2000-07-05 22:09:50 +00:00
|
|
|
struct nd_opt_hdr *zero;
|
|
|
|
struct nd_opt_hdr *src_lladdr;
|
|
|
|
struct nd_opt_hdr *tgt_lladdr;
|
|
|
|
struct nd_opt_prefix_info *pi;
|
|
|
|
struct nd_opt_rd_hdr *rh;
|
|
|
|
struct nd_opt_mtu *mtu;
|
2011-06-06 03:06:43 +00:00
|
|
|
TAILQ_HEAD(, nd_optlist) opt_list;
|
2000-01-06 12:40:54 +00:00
|
|
|
} nd_opt_each;
|
|
|
|
};
|
2011-06-06 03:06:43 +00:00
|
|
|
#define opt_src_lladdr nd_opt_each.src_lladdr
|
|
|
|
#define opt_tgt_lladdr nd_opt_each.tgt_lladdr
|
|
|
|
#define opt_pi nd_opt_each.pi
|
|
|
|
#define opt_rh nd_opt_each.rh
|
|
|
|
#define opt_mtu nd_opt_each.mtu
|
|
|
|
#define opt_list nd_opt_each.opt_list
|
|
|
|
|
|
|
|
#define NDOPT_FLAG_SRCLINKADDR (1 << 0)
|
|
|
|
#define NDOPT_FLAG_TGTLINKADDR (1 << 1)
|
|
|
|
#define NDOPT_FLAG_PREFIXINFO (1 << 2)
|
|
|
|
#define NDOPT_FLAG_RDHDR (1 << 3)
|
|
|
|
#define NDOPT_FLAG_MTU (1 << 4)
|
|
|
|
#define NDOPT_FLAG_RDNSS (1 << 5)
|
|
|
|
#define NDOPT_FLAG_DNSSL (1 << 6)
|
2000-01-06 12:40:54 +00:00
|
|
|
|
2013-07-09 07:08:36 +00:00
|
|
|
static uint32_t ndopt_flags[] = {
|
2011-06-06 03:06:43 +00:00
|
|
|
[ND_OPT_SOURCE_LINKADDR] = NDOPT_FLAG_SRCLINKADDR,
|
|
|
|
[ND_OPT_TARGET_LINKADDR] = NDOPT_FLAG_TGTLINKADDR,
|
|
|
|
[ND_OPT_PREFIX_INFORMATION] = NDOPT_FLAG_PREFIXINFO,
|
|
|
|
[ND_OPT_REDIRECTED_HEADER] = NDOPT_FLAG_RDHDR,
|
|
|
|
[ND_OPT_MTU] = NDOPT_FLAG_MTU,
|
|
|
|
[ND_OPT_RDNSS] = NDOPT_FLAG_RDNSS,
|
|
|
|
[ND_OPT_DNSSL] = NDOPT_FLAG_DNSSL,
|
|
|
|
};
|
|
|
|
|
2011-07-17 19:24:54 +00:00
|
|
|
static void rtadvd_shutdown(void);
|
|
|
|
static void sock_open(struct sockinfo *);
|
|
|
|
static void rtsock_open(struct sockinfo *);
|
|
|
|
static void rtadvd_input(struct sockinfo *);
|
2011-06-06 03:06:43 +00:00
|
|
|
static void rs_input(int, struct nd_router_solicit *,
|
|
|
|
struct in6_pktinfo *, struct sockaddr_in6 *);
|
|
|
|
static void ra_input(int, struct nd_router_advert *,
|
|
|
|
struct in6_pktinfo *, struct sockaddr_in6 *);
|
|
|
|
static int prefix_check(struct nd_opt_prefix_info *, struct rainfo *,
|
|
|
|
struct sockaddr_in6 *);
|
|
|
|
static int nd6_options(struct nd_opt_hdr *, int,
|
2011-07-17 19:24:54 +00:00
|
|
|
union nd_opt *, uint32_t);
|
2011-06-06 03:06:43 +00:00
|
|
|
static void free_ndopts(union nd_opt *);
|
2011-07-17 19:24:54 +00:00
|
|
|
static void rtmsg_input(struct sockinfo *);
|
|
|
|
static void set_short_delay(struct ifinfo *);
|
2011-06-06 03:06:43 +00:00
|
|
|
static int check_accept_rtadv(int);
|
2000-01-06 12:40:54 +00:00
|
|
|
|
2013-02-25 16:47:09 +00:00
|
|
|
static void
|
|
|
|
usage(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
fprintf(stderr, "usage: rtadvd [-dDfRs] "
|
|
|
|
"[-c configfile] [-C ctlsock] [-M ifname] [-p pidfile]\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2000-01-06 12:40:54 +00:00
|
|
|
int
|
2011-06-06 03:06:43 +00:00
|
|
|
main(int argc, char *argv[])
|
2000-01-06 12:40:54 +00:00
|
|
|
{
|
2011-07-17 19:24:54 +00:00
|
|
|
struct pollfd set[PFD_MAX];
|
2013-08-05 20:13:02 +00:00
|
|
|
struct timespec *timeout;
|
2000-01-06 12:40:54 +00:00
|
|
|
int i, ch;
|
2003-08-15 17:15:10 +00:00
|
|
|
int fflag = 0, logopt;
|
2011-07-17 19:24:54 +00:00
|
|
|
int error;
|
2010-12-22 23:58:21 +00:00
|
|
|
pid_t pid, otherpid;
|
2000-01-06 12:40:54 +00:00
|
|
|
|
|
|
|
/* get command line options and arguments */
|
2013-02-25 16:47:09 +00:00
|
|
|
while ((ch = getopt(argc, argv, "c:C:dDfhM:p:Rs")) != -1) {
|
2002-06-01 17:28:12 +00:00
|
|
|
switch (ch) {
|
|
|
|
case 'c':
|
|
|
|
conffile = optarg;
|
|
|
|
break;
|
2011-07-17 19:24:54 +00:00
|
|
|
case 'C':
|
|
|
|
ctrlsock.si_name = optarg;
|
|
|
|
break;
|
2002-06-01 17:28:12 +00:00
|
|
|
case 'd':
|
2011-06-06 03:06:43 +00:00
|
|
|
dflag++;
|
2002-06-01 17:28:12 +00:00
|
|
|
break;
|
|
|
|
case 'D':
|
2011-09-12 23:52:55 +00:00
|
|
|
dflag += 3;
|
2002-06-01 17:28:12 +00:00
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
fflag = 1;
|
|
|
|
break;
|
2001-06-11 12:39:29 +00:00
|
|
|
case 'M':
|
|
|
|
mcastif = optarg;
|
|
|
|
break;
|
2002-06-01 17:28:12 +00:00
|
|
|
case 'R':
|
|
|
|
fprintf(stderr, "rtadvd: "
|
|
|
|
"the -R option is currently ignored.\n");
|
|
|
|
/* accept_rr = 1; */
|
|
|
|
/* run anyway... */
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
sflag = 1;
|
|
|
|
break;
|
2010-12-22 23:58:21 +00:00
|
|
|
case 'p':
|
|
|
|
pidfilename = optarg;
|
|
|
|
break;
|
2013-02-25 16:47:09 +00:00
|
|
|
default:
|
|
|
|
usage();
|
2000-01-06 12:40:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
2003-08-15 17:15:10 +00:00
|
|
|
logopt = LOG_NDELAY | LOG_PID;
|
|
|
|
if (fflag)
|
|
|
|
logopt |= LOG_PERROR;
|
|
|
|
openlog("rtadvd", logopt, LOG_DAEMON);
|
|
|
|
|
2000-01-06 12:40:54 +00:00
|
|
|
/* set log level */
|
2011-09-12 23:52:55 +00:00
|
|
|
if (dflag > 2)
|
2011-06-06 03:06:43 +00:00
|
|
|
(void)setlogmask(LOG_UPTO(LOG_DEBUG));
|
2011-09-12 23:52:55 +00:00
|
|
|
else if (dflag > 1)
|
2000-01-06 12:40:54 +00:00
|
|
|
(void)setlogmask(LOG_UPTO(LOG_INFO));
|
2011-09-12 23:52:55 +00:00
|
|
|
else if (dflag > 0)
|
|
|
|
(void)setlogmask(LOG_UPTO(LOG_NOTICE));
|
2011-06-06 03:06:43 +00:00
|
|
|
else
|
|
|
|
(void)setlogmask(LOG_UPTO(LOG_ERR));
|
2000-01-06 12:40:54 +00:00
|
|
|
|
|
|
|
/* timer initialization */
|
|
|
|
rtadvd_timer_init();
|
|
|
|
|
2010-12-22 23:58:21 +00:00
|
|
|
pfh = pidfile_open(pidfilename, 0600, &otherpid);
|
|
|
|
if (pfh == NULL) {
|
|
|
|
if (errno == EEXIST)
|
|
|
|
errx(1, "%s already running, pid: %d",
|
|
|
|
getprogname(), otherpid);
|
|
|
|
syslog(LOG_ERR,
|
2011-09-12 23:52:55 +00:00
|
|
|
"failed to open the pid file %s, run anyway.",
|
|
|
|
pidfilename);
|
2010-12-22 23:58:21 +00:00
|
|
|
}
|
2000-01-06 12:40:54 +00:00
|
|
|
if (!fflag)
|
|
|
|
daemon(1, 0);
|
|
|
|
|
2011-07-17 19:24:54 +00:00
|
|
|
sock_open(&sock);
|
|
|
|
|
|
|
|
update_ifinfo(&ifilist, UPDATE_IFINFO_ALL);
|
|
|
|
for (i = 0; i < argc; i++)
|
|
|
|
update_persist_ifinfo(&ifilist, argv[i]);
|
|
|
|
|
|
|
|
csock_open(&ctrlsock, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
|
|
|
|
if (ctrlsock.si_fd == -1) {
|
2011-09-12 23:52:55 +00:00
|
|
|
syslog(LOG_ERR, "cannot open control socket: %s",
|
|
|
|
strerror(errno));
|
2011-07-17 19:24:54 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2003-08-14 19:05:24 +00:00
|
|
|
|
2000-07-05 22:09:50 +00:00
|
|
|
/* record the current PID */
|
|
|
|
pid = getpid();
|
2010-12-22 23:58:21 +00:00
|
|
|
pidfile_write(pfh);
|
2000-07-05 22:09:50 +00:00
|
|
|
|
2011-07-17 19:24:54 +00:00
|
|
|
set[PFD_RAWSOCK].fd = sock.si_fd;
|
|
|
|
set[PFD_RAWSOCK].events = POLLIN;
|
2003-08-14 18:43:57 +00:00
|
|
|
if (sflag == 0) {
|
2011-07-17 19:24:54 +00:00
|
|
|
rtsock_open(&rtsock);
|
|
|
|
set[PFD_RTSOCK].fd = rtsock.si_fd;
|
|
|
|
set[PFD_RTSOCK].events = POLLIN;
|
2003-08-14 18:43:57 +00:00
|
|
|
} else
|
2011-07-17 19:24:54 +00:00
|
|
|
set[PFD_RTSOCK].fd = -1;
|
|
|
|
set[PFD_CSOCK].fd = ctrlsock.si_fd;
|
|
|
|
set[PFD_CSOCK].events = POLLIN;
|
|
|
|
signal(SIGTERM, set_do_shutdown);
|
|
|
|
signal(SIGINT, set_do_shutdown);
|
|
|
|
signal(SIGHUP, set_do_reload);
|
|
|
|
|
|
|
|
error = csock_listen(&ctrlsock);
|
|
|
|
if (error) {
|
2011-09-12 23:52:55 +00:00
|
|
|
syslog(LOG_ERR, "cannot listen control socket: %s",
|
|
|
|
strerror(errno));
|
2011-07-17 19:24:54 +00:00
|
|
|
exit(1);
|
2003-08-14 16:19:59 +00:00
|
|
|
}
|
2011-07-17 19:24:54 +00:00
|
|
|
|
|
|
|
/* load configuration file */
|
|
|
|
set_do_reload(0);
|
2000-01-06 12:40:54 +00:00
|
|
|
|
|
|
|
while (1) {
|
2011-07-17 19:24:54 +00:00
|
|
|
if (is_do_shutdown())
|
|
|
|
rtadvd_shutdown();
|
2000-07-05 22:09:50 +00:00
|
|
|
|
2011-07-17 19:24:54 +00:00
|
|
|
if (is_do_reload()) {
|
|
|
|
loadconfig_ifname(reload_ifname());
|
|
|
|
if (reload_ifname() == NULL)
|
|
|
|
syslog(LOG_INFO,
|
|
|
|
"configuration file reloaded.");
|
|
|
|
else
|
|
|
|
syslog(LOG_INFO,
|
|
|
|
"configuration file for %s reloaded.",
|
|
|
|
reload_ifname());
|
|
|
|
reset_do_reload();
|
2001-06-11 12:39:29 +00:00
|
|
|
}
|
|
|
|
|
2011-07-17 19:24:54 +00:00
|
|
|
/* timeout handler update for active interfaces */
|
|
|
|
rtadvd_update_timeout_handler();
|
2011-06-11 03:25:10 +00:00
|
|
|
|
2000-01-06 12:40:54 +00:00
|
|
|
/* timer expiration check and reset the timer */
|
|
|
|
timeout = rtadvd_check_timer();
|
|
|
|
|
2000-07-05 22:09:50 +00:00
|
|
|
if (timeout != NULL) {
|
|
|
|
syslog(LOG_DEBUG,
|
2002-06-01 17:28:12 +00:00
|
|
|
"<%s> set timer to %ld:%ld. waiting for "
|
2003-08-08 16:38:23 +00:00
|
|
|
"inputs or timeout", __func__,
|
2002-06-01 17:28:12 +00:00
|
|
|
(long int)timeout->tv_sec,
|
2013-08-05 20:13:02 +00:00
|
|
|
(long int)timeout->tv_nsec / 1000);
|
2000-07-05 22:09:50 +00:00
|
|
|
} else {
|
|
|
|
syslog(LOG_DEBUG,
|
2002-06-01 17:28:12 +00:00
|
|
|
"<%s> there's no timer. waiting for inputs",
|
2003-08-08 16:38:23 +00:00
|
|
|
__func__);
|
2000-07-05 22:09:50 +00:00
|
|
|
}
|
2011-07-17 19:24:54 +00:00
|
|
|
if ((i = poll(set, sizeof(set)/sizeof(set[0]),
|
|
|
|
timeout ? (timeout->tv_sec * 1000 +
|
2013-08-05 20:13:02 +00:00
|
|
|
timeout->tv_nsec / 1000 / 1000) : INFTIM)) < 0) {
|
2011-09-12 23:52:55 +00:00
|
|
|
|
|
|
|
/* EINTR would occur if a signal was delivered */
|
2000-07-05 22:09:50 +00:00
|
|
|
if (errno != EINTR)
|
2011-09-12 23:52:55 +00:00
|
|
|
syslog(LOG_ERR, "poll() failed: %s",
|
|
|
|
strerror(errno));
|
2000-01-06 12:40:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (i == 0) /* timeout */
|
|
|
|
continue;
|
2011-07-17 19:24:54 +00:00
|
|
|
if (rtsock.si_fd != -1 && set[PFD_RTSOCK].revents & POLLIN)
|
|
|
|
rtmsg_input(&rtsock);
|
2000-01-06 12:40:54 +00:00
|
|
|
|
2011-07-17 19:24:54 +00:00
|
|
|
if (set[PFD_RAWSOCK].revents & POLLIN)
|
|
|
|
rtadvd_input(&sock);
|
2011-06-06 03:06:43 +00:00
|
|
|
|
2011-07-17 19:24:54 +00:00
|
|
|
if (set[PFD_CSOCK].revents & POLLIN) {
|
|
|
|
int fd;
|
2011-06-11 03:25:10 +00:00
|
|
|
|
2011-07-17 19:24:54 +00:00
|
|
|
fd = csock_accept(&ctrlsock);
|
|
|
|
if (fd == -1)
|
2011-09-12 23:52:55 +00:00
|
|
|
syslog(LOG_ERR,
|
|
|
|
"cannot accept() control socket: %s",
|
|
|
|
strerror(errno));
|
2011-07-17 19:24:54 +00:00
|
|
|
else {
|
2011-09-12 23:52:55 +00:00
|
|
|
cm_handler_server(fd);
|
2011-07-17 19:24:54 +00:00
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
exit(0); /* NOTREACHED */
|
2001-06-11 12:39:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-07-17 19:24:54 +00:00
|
|
|
rtadvd_shutdown(void)
|
2000-07-05 22:09:50 +00:00
|
|
|
{
|
2011-07-17 19:24:54 +00:00
|
|
|
struct ifinfo *ifi;
|
2011-06-06 03:06:43 +00:00
|
|
|
struct rainfo *rai;
|
|
|
|
struct rdnss *rdn;
|
|
|
|
struct dnssl *dns;
|
2011-07-17 19:24:54 +00:00
|
|
|
|
|
|
|
if (wait_shutdown) {
|
|
|
|
syslog(LOG_INFO,
|
2011-09-12 23:52:55 +00:00
|
|
|
"waiting expiration of the all RA timers.");
|
2011-07-17 19:24:54 +00:00
|
|
|
|
2011-09-20 00:32:30 +00:00
|
|
|
TAILQ_FOREACH(ifi, &ifilist, ifi_next) {
|
|
|
|
/*
|
|
|
|
* Ignore !IFF_UP interfaces in waiting for shutdown.
|
|
|
|
*/
|
|
|
|
if (!(ifi->ifi_flags & IFF_UP) &&
|
|
|
|
ifi->ifi_ra_timer != NULL) {
|
|
|
|
ifi->ifi_state = IFI_STATE_UNCONFIGURED;
|
|
|
|
rtadvd_remove_timer(ifi->ifi_ra_timer);
|
|
|
|
ifi->ifi_ra_timer = NULL;
|
|
|
|
syslog(LOG_DEBUG, "<%s> %s(idx=%d) is down. "
|
|
|
|
"Timer removed and marked as UNCONFIGURED.",
|
|
|
|
__func__, ifi->ifi_ifname,
|
|
|
|
ifi->ifi_ifindex);
|
|
|
|
}
|
|
|
|
}
|
2011-07-17 19:24:54 +00:00
|
|
|
TAILQ_FOREACH(ifi, &ifilist, ifi_next) {
|
|
|
|
if (ifi->ifi_ra_timer != NULL)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (ifi == NULL) {
|
2011-09-12 23:52:55 +00:00
|
|
|
syslog(LOG_NOTICE, "gracefully terminated.");
|
2011-07-17 19:24:54 +00:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
sleep(1);
|
|
|
|
return;
|
|
|
|
}
|
2000-07-05 22:09:50 +00:00
|
|
|
|
2011-09-12 23:52:55 +00:00
|
|
|
syslog(LOG_DEBUG, "<%s> cease to be an advertising router",
|
2011-06-06 03:06:43 +00:00
|
|
|
__func__);
|
2000-07-05 22:09:50 +00:00
|
|
|
|
2011-07-17 19:24:54 +00:00
|
|
|
wait_shutdown = 1;
|
|
|
|
|
2011-06-06 03:06:43 +00:00
|
|
|
TAILQ_FOREACH(rai, &railist, rai_next) {
|
|
|
|
rai->rai_lifetime = 0;
|
|
|
|
TAILQ_FOREACH(rdn, &rai->rai_rdnss, rd_next)
|
|
|
|
rdn->rd_ltime = 0;
|
|
|
|
TAILQ_FOREACH(dns, &rai->rai_dnssl, dn_next)
|
|
|
|
dns->dn_ltime = 0;
|
2000-07-05 22:09:50 +00:00
|
|
|
}
|
2011-07-17 19:24:54 +00:00
|
|
|
TAILQ_FOREACH(ifi, &ifilist, ifi_next) {
|
|
|
|
if (!ifi->ifi_persist)
|
|
|
|
continue;
|
|
|
|
if (ifi->ifi_state == IFI_STATE_UNCONFIGURED)
|
|
|
|
continue;
|
|
|
|
if (ifi->ifi_ra_timer == NULL)
|
|
|
|
continue;
|
2011-09-12 23:52:55 +00:00
|
|
|
if (ifi->ifi_ra_lastsent.tv_sec == 0 &&
|
2013-08-05 20:13:02 +00:00
|
|
|
ifi->ifi_ra_lastsent.tv_nsec == 0 &&
|
2011-09-12 23:52:55 +00:00
|
|
|
ifi->ifi_ra_timer != NULL) {
|
|
|
|
/*
|
|
|
|
* When RA configured but never sent,
|
|
|
|
* ignore the IF immediately.
|
|
|
|
*/
|
|
|
|
rtadvd_remove_timer(ifi->ifi_ra_timer);
|
|
|
|
ifi->ifi_ra_timer = NULL;
|
|
|
|
ifi->ifi_state = IFI_STATE_UNCONFIGURED;
|
|
|
|
continue;
|
|
|
|
}
|
2011-07-17 19:24:54 +00:00
|
|
|
|
|
|
|
ifi->ifi_state = IFI_STATE_TRANSITIVE;
|
|
|
|
|
|
|
|
/* Mark as the shut-down state. */
|
|
|
|
ifi->ifi_rainfo_trans = ifi->ifi_rainfo;
|
|
|
|
ifi->ifi_rainfo = NULL;
|
|
|
|
|
|
|
|
ifi->ifi_burstcount = MAX_FINAL_RTR_ADVERTISEMENTS;
|
|
|
|
ifi->ifi_burstinterval = MIN_DELAY_BETWEEN_RAS;
|
|
|
|
|
|
|
|
ra_timer_update(ifi, &ifi->ifi_ra_timer->rat_tm);
|
|
|
|
rtadvd_set_timer(&ifi->ifi_ra_timer->rat_tm,
|
|
|
|
ifi->ifi_ra_timer);
|
2000-07-05 22:09:50 +00:00
|
|
|
}
|
2011-09-12 23:52:55 +00:00
|
|
|
syslog(LOG_NOTICE, "final RA transmission started.");
|
2011-06-06 03:06:43 +00:00
|
|
|
|
2011-07-17 19:24:54 +00:00
|
|
|
pidfile_remove(pfh);
|
|
|
|
csock_close(&ctrlsock);
|
2000-07-05 22:09:50 +00:00
|
|
|
}
|
|
|
|
|
2000-01-06 12:40:54 +00:00
|
|
|
static void
|
2011-07-17 19:24:54 +00:00
|
|
|
rtmsg_input(struct sockinfo *s)
|
2000-01-06 12:40:54 +00:00
|
|
|
{
|
2000-07-05 22:09:50 +00:00
|
|
|
int n, type, ifindex = 0, plen;
|
2000-01-06 12:40:54 +00:00
|
|
|
size_t len;
|
|
|
|
char msg[2048], *next, *lim;
|
2011-07-17 19:24:54 +00:00
|
|
|
char ifname[IFNAMSIZ];
|
2011-06-06 03:06:43 +00:00
|
|
|
struct if_announcemsghdr *ifan;
|
2011-07-17 19:24:54 +00:00
|
|
|
struct rt_msghdr *rtm;
|
2011-06-06 03:06:43 +00:00
|
|
|
struct prefix *pfx;
|
2000-01-06 12:40:54 +00:00
|
|
|
struct rainfo *rai;
|
|
|
|
struct in6_addr *addr;
|
2011-07-17 19:24:54 +00:00
|
|
|
struct ifinfo *ifi;
|
2000-01-06 12:40:54 +00:00
|
|
|
char addrbuf[INET6_ADDRSTRLEN];
|
- supported a string notation for xxflags.
- deprecate routes#N, as it is hard to keep consistency with
rtprefixN. accept any number of "rtprefix", "rtrefix0",
..., "rtprefix99".
- deprecate "addrs#N", as it is difficult for users to keep
consistency with "addrN".
accept 100 prefix info in maximum - like "addr", "addr0"
... "addr99". WARNS=2 clean on netbsd.
old configuration file should work just fine.
behavior change:
previously, we rejected "addrN" if there's "addr", and we rejected
"addr" if there is "addrN". now we accept both without problem.
- when an advertised prefix configured from the kernel has been added
or invalidated, notice the change in a short delay.
- when invalidating a prefix, do not bark even if there is
inconsistency about prefix lifetimes.
- wrap more specific route info code into ROUTEINFO.
Obtained from: KAME
MFC after: 1 week
2003-08-15 19:13:53 +00:00
|
|
|
int prefixchange = 0;
|
2000-01-06 12:40:54 +00:00
|
|
|
|
2011-07-17 19:24:54 +00:00
|
|
|
if (s == NULL) {
|
|
|
|
syslog(LOG_ERR, "<%s> internal error", __func__);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
n = read(s->si_fd, msg, sizeof(msg));
|
|
|
|
rtm = (struct rt_msghdr *)msg;
|
2011-06-06 03:06:43 +00:00
|
|
|
syslog(LOG_DEBUG, "<%s> received a routing message "
|
2011-07-17 19:24:54 +00:00
|
|
|
"(type = %d, len = %d)", __func__, rtm->rtm_type, n);
|
2011-06-06 03:06:43 +00:00
|
|
|
|
2011-07-17 19:24:54 +00:00
|
|
|
if (n > rtm->rtm_msglen) {
|
2000-01-06 12:40:54 +00:00
|
|
|
/*
|
2011-06-06 03:06:43 +00:00
|
|
|
* This usually won't happen for messages received on
|
2000-07-05 22:09:50 +00:00
|
|
|
* a routing socket.
|
2000-01-06 12:40:54 +00:00
|
|
|
*/
|
2011-06-06 03:06:43 +00:00
|
|
|
syslog(LOG_DEBUG,
|
|
|
|
"<%s> received data length is larger than "
|
|
|
|
"1st routing message len. multiple messages? "
|
|
|
|
"read %d bytes, but 1st msg len = %d",
|
2011-07-17 19:24:54 +00:00
|
|
|
__func__, n, rtm->rtm_msglen);
|
2000-07-05 22:09:50 +00:00
|
|
|
#if 0
|
|
|
|
/* adjust length */
|
2011-07-17 19:24:54 +00:00
|
|
|
n = rtm->rtm_msglen;
|
2000-07-05 22:09:50 +00:00
|
|
|
#endif
|
2000-01-06 12:40:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
lim = msg + n;
|
|
|
|
for (next = msg; next < lim; next += len) {
|
2000-07-05 22:09:50 +00:00
|
|
|
int oldifflags;
|
|
|
|
|
2000-01-06 12:40:54 +00:00
|
|
|
next = get_next_msg(next, lim, 0, &len,
|
2011-06-06 03:06:43 +00:00
|
|
|
RTADV_TYPE2BITMASK(RTM_ADD) |
|
|
|
|
RTADV_TYPE2BITMASK(RTM_DELETE) |
|
|
|
|
RTADV_TYPE2BITMASK(RTM_NEWADDR) |
|
|
|
|
RTADV_TYPE2BITMASK(RTM_DELADDR) |
|
|
|
|
RTADV_TYPE2BITMASK(RTM_IFINFO) |
|
|
|
|
RTADV_TYPE2BITMASK(RTM_IFANNOUNCE));
|
2000-01-06 12:40:54 +00:00
|
|
|
if (len == 0)
|
|
|
|
break;
|
2011-07-17 19:24:54 +00:00
|
|
|
type = ((struct rt_msghdr *)next)->rtm_type;
|
2000-01-06 12:40:54 +00:00
|
|
|
switch (type) {
|
|
|
|
case RTM_ADD:
|
|
|
|
case RTM_DELETE:
|
|
|
|
ifindex = get_rtm_ifindex(next);
|
|
|
|
break;
|
|
|
|
case RTM_NEWADDR:
|
|
|
|
case RTM_DELADDR:
|
2011-07-17 19:24:54 +00:00
|
|
|
ifindex = (int)((struct ifa_msghdr *)next)->ifam_index;
|
2000-01-06 12:40:54 +00:00
|
|
|
break;
|
|
|
|
case RTM_IFINFO:
|
2011-07-17 19:24:54 +00:00
|
|
|
ifindex = (int)((struct if_msghdr *)next)->ifm_index;
|
2000-01-06 12:40:54 +00:00
|
|
|
break;
|
2011-06-06 03:06:43 +00:00
|
|
|
case RTM_IFANNOUNCE:
|
|
|
|
ifan = (struct if_announcemsghdr *)next;
|
|
|
|
switch (ifan->ifan_what) {
|
|
|
|
case IFAN_ARRIVAL:
|
|
|
|
case IFAN_DEPARTURE:
|
|
|
|
break;
|
|
|
|
default:
|
2000-01-06 12:40:54 +00:00
|
|
|
syslog(LOG_DEBUG,
|
2011-06-06 03:06:43 +00:00
|
|
|
"<%s:%d> unknown ifan msg (ifan_what=%d)",
|
|
|
|
__func__, __LINE__, ifan->ifan_what);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-09-12 23:52:55 +00:00
|
|
|
syslog(LOG_DEBUG, "<%s>: if_announcemsg (idx=%d:%d)",
|
2011-06-06 03:06:43 +00:00
|
|
|
__func__, ifan->ifan_index, ifan->ifan_what);
|
|
|
|
switch (ifan->ifan_what) {
|
|
|
|
case IFAN_ARRIVAL:
|
2011-09-12 23:52:55 +00:00
|
|
|
syslog(LOG_NOTICE,
|
|
|
|
"interface added (idx=%d)",
|
|
|
|
ifan->ifan_index);
|
2011-07-17 19:24:54 +00:00
|
|
|
update_ifinfo(&ifilist, ifan->ifan_index);
|
|
|
|
loadconfig_index(ifan->ifan_index);
|
2011-06-06 03:06:43 +00:00
|
|
|
break;
|
|
|
|
case IFAN_DEPARTURE:
|
2011-09-12 23:52:55 +00:00
|
|
|
syslog(LOG_NOTICE,
|
|
|
|
"interface removed (idx=%d)",
|
|
|
|
ifan->ifan_index);
|
2011-07-17 19:24:54 +00:00
|
|
|
rm_ifinfo_index(ifan->ifan_index);
|
|
|
|
|
|
|
|
/* Clear ifi_ifindex */
|
|
|
|
TAILQ_FOREACH(ifi, &ifilist, ifi_next) {
|
|
|
|
if (ifi->ifi_ifindex
|
|
|
|
== ifan->ifan_index) {
|
|
|
|
ifi->ifi_ifindex = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
update_ifinfo(&ifilist, ifan->ifan_index);
|
2011-06-06 03:06:43 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
default:
|
|
|
|
/* should not reach here */
|
|
|
|
syslog(LOG_DEBUG,
|
|
|
|
"<%s:%d> unknown rtmsg %d on %s",
|
|
|
|
__func__, __LINE__, type,
|
|
|
|
if_indextoname(ifindex, ifname));
|
2000-07-05 22:09:50 +00:00
|
|
|
continue;
|
2000-01-06 12:40:54 +00:00
|
|
|
}
|
2011-07-17 19:24:54 +00:00
|
|
|
ifi = if_indextoifinfo(ifindex);
|
|
|
|
if (ifi == NULL) {
|
2011-06-06 03:06:43 +00:00
|
|
|
syslog(LOG_DEBUG,
|
2011-07-17 19:24:54 +00:00
|
|
|
"<%s> ifinfo not found for idx=%d. Why?",
|
|
|
|
__func__, ifindex);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
rai = ifi->ifi_rainfo;
|
|
|
|
if (rai == NULL) {
|
|
|
|
syslog(LOG_DEBUG,
|
|
|
|
"<%s> route changed on "
|
|
|
|
"non advertising interface(%s)",
|
|
|
|
__func__, ifi->ifi_ifname);
|
2000-07-05 22:09:50 +00:00
|
|
|
continue;
|
2000-01-06 12:40:54 +00:00
|
|
|
}
|
2011-07-17 19:24:54 +00:00
|
|
|
|
|
|
|
oldifflags = ifi->ifi_flags;
|
|
|
|
/* init ifflags because it may have changed */
|
|
|
|
update_ifinfo(&ifilist, ifindex);
|
2000-01-06 12:40:54 +00:00
|
|
|
|
2002-06-01 17:28:12 +00:00
|
|
|
switch (type) {
|
|
|
|
case RTM_ADD:
|
|
|
|
if (sflag)
|
|
|
|
break; /* we aren't interested in prefixes */
|
|
|
|
|
|
|
|
addr = get_addr(msg);
|
|
|
|
plen = get_prefixlen(msg);
|
|
|
|
/* sanity check for plen */
|
|
|
|
/* as RFC2373, prefixlen is at least 4 */
|
|
|
|
if (plen < 4 || plen > 127) {
|
2000-01-06 12:40:54 +00:00
|
|
|
syslog(LOG_INFO, "<%s> new interface route's"
|
2002-06-01 17:28:12 +00:00
|
|
|
"plen %d is invalid for a prefix",
|
2003-08-08 16:38:23 +00:00
|
|
|
__func__, plen);
|
2000-07-05 22:09:50 +00:00
|
|
|
break;
|
2002-06-01 17:28:12 +00:00
|
|
|
}
|
2011-06-06 03:06:43 +00:00
|
|
|
pfx = find_prefix(rai, addr, plen);
|
|
|
|
if (pfx) {
|
|
|
|
if (pfx->pfx_timer) {
|
2002-06-13 16:59:31 +00:00
|
|
|
/*
|
|
|
|
* If the prefix has been invalidated,
|
|
|
|
* make it available again.
|
|
|
|
*/
|
2011-06-06 03:06:43 +00:00
|
|
|
update_prefix(pfx);
|
- supported a string notation for xxflags.
- deprecate routes#N, as it is hard to keep consistency with
rtprefixN. accept any number of "rtprefix", "rtrefix0",
..., "rtprefix99".
- deprecate "addrs#N", as it is difficult for users to keep
consistency with "addrN".
accept 100 prefix info in maximum - like "addr", "addr0"
... "addr99". WARNS=2 clean on netbsd.
old configuration file should work just fine.
behavior change:
previously, we rejected "addrN" if there's "addr", and we rejected
"addr" if there is "addrN". now we accept both without problem.
- when an advertised prefix configured from the kernel has been added
or invalidated, notice the change in a short delay.
- when invalidating a prefix, do not bark even if there is
inconsistency about prefix lifetimes.
- wrap more specific route info code into ROUTEINFO.
Obtained from: KAME
MFC after: 1 week
2003-08-15 19:13:53 +00:00
|
|
|
prefixchange = 1;
|
2011-06-06 03:06:43 +00:00
|
|
|
} else
|
2002-06-01 17:28:12 +00:00
|
|
|
syslog(LOG_DEBUG,
|
|
|
|
"<%s> new prefix(%s/%d) "
|
|
|
|
"added on %s, "
|
|
|
|
"but it was already in list",
|
2003-08-08 16:38:23 +00:00
|
|
|
__func__,
|
2002-06-01 17:28:12 +00:00
|
|
|
inet_ntop(AF_INET6, addr,
|
2011-06-06 03:06:43 +00:00
|
|
|
(char *)addrbuf,
|
|
|
|
sizeof(addrbuf)),
|
2011-07-17 19:24:54 +00:00
|
|
|
plen, ifi->ifi_ifname);
|
2000-07-05 22:09:50 +00:00
|
|
|
break;
|
2002-06-01 17:28:12 +00:00
|
|
|
}
|
|
|
|
make_prefix(rai, ifindex, addr, plen);
|
- supported a string notation for xxflags.
- deprecate routes#N, as it is hard to keep consistency with
rtprefixN. accept any number of "rtprefix", "rtrefix0",
..., "rtprefix99".
- deprecate "addrs#N", as it is difficult for users to keep
consistency with "addrN".
accept 100 prefix info in maximum - like "addr", "addr0"
... "addr99". WARNS=2 clean on netbsd.
old configuration file should work just fine.
behavior change:
previously, we rejected "addrN" if there's "addr", and we rejected
"addr" if there is "addrN". now we accept both without problem.
- when an advertised prefix configured from the kernel has been added
or invalidated, notice the change in a short delay.
- when invalidating a prefix, do not bark even if there is
inconsistency about prefix lifetimes.
- wrap more specific route info code into ROUTEINFO.
Obtained from: KAME
MFC after: 1 week
2003-08-15 19:13:53 +00:00
|
|
|
prefixchange = 1;
|
2002-06-01 17:28:12 +00:00
|
|
|
break;
|
|
|
|
case RTM_DELETE:
|
|
|
|
if (sflag)
|
|
|
|
break;
|
|
|
|
|
|
|
|
addr = get_addr(msg);
|
|
|
|
plen = get_prefixlen(msg);
|
|
|
|
/* sanity check for plen */
|
|
|
|
/* as RFC2373, prefixlen is at least 4 */
|
|
|
|
if (plen < 4 || plen > 127) {
|
|
|
|
syslog(LOG_INFO,
|
|
|
|
"<%s> deleted interface route's "
|
|
|
|
"plen %d is invalid for a prefix",
|
2003-08-08 16:38:23 +00:00
|
|
|
__func__, plen);
|
2002-06-01 17:28:12 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-06-06 03:06:43 +00:00
|
|
|
pfx = find_prefix(rai, addr, plen);
|
|
|
|
if (pfx == NULL) {
|
|
|
|
syslog(LOG_DEBUG,
|
|
|
|
"<%s> prefix(%s/%d) was deleted on %s, "
|
|
|
|
"but it was not in list",
|
|
|
|
__func__, inet_ntop(AF_INET6, addr,
|
|
|
|
(char *)addrbuf, sizeof(addrbuf)),
|
2011-07-17 19:24:54 +00:00
|
|
|
plen, ifi->ifi_ifname);
|
2002-06-01 17:28:12 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-06-06 03:06:43 +00:00
|
|
|
invalidate_prefix(pfx);
|
- supported a string notation for xxflags.
- deprecate routes#N, as it is hard to keep consistency with
rtprefixN. accept any number of "rtprefix", "rtrefix0",
..., "rtprefix99".
- deprecate "addrs#N", as it is difficult for users to keep
consistency with "addrN".
accept 100 prefix info in maximum - like "addr", "addr0"
... "addr99". WARNS=2 clean on netbsd.
old configuration file should work just fine.
behavior change:
previously, we rejected "addrN" if there's "addr", and we rejected
"addr" if there is "addrN". now we accept both without problem.
- when an advertised prefix configured from the kernel has been added
or invalidated, notice the change in a short delay.
- when invalidating a prefix, do not bark even if there is
inconsistency about prefix lifetimes.
- wrap more specific route info code into ROUTEINFO.
Obtained from: KAME
MFC after: 1 week
2003-08-15 19:13:53 +00:00
|
|
|
prefixchange = 1;
|
2002-06-01 17:28:12 +00:00
|
|
|
break;
|
2000-01-06 12:40:54 +00:00
|
|
|
case RTM_NEWADDR:
|
|
|
|
case RTM_DELADDR:
|
|
|
|
case RTM_IFINFO:
|
2002-06-01 17:28:12 +00:00
|
|
|
break;
|
2000-01-06 12:40:54 +00:00
|
|
|
default:
|
|
|
|
/* should not reach here */
|
2011-06-06 03:06:43 +00:00
|
|
|
syslog(LOG_DEBUG,
|
|
|
|
"<%s:%d> unknown rtmsg %d on %s",
|
|
|
|
__func__, __LINE__, type,
|
|
|
|
if_indextoname(ifindex, ifname));
|
2000-01-06 12:40:54 +00:00
|
|
|
return;
|
|
|
|
}
|
2000-07-05 22:09:50 +00:00
|
|
|
|
|
|
|
/* check if an interface flag is changed */
|
2003-08-08 16:56:01 +00:00
|
|
|
if ((oldifflags & IFF_UP) && /* UP to DOWN */
|
2011-07-17 19:24:54 +00:00
|
|
|
!(ifi->ifi_flags & IFF_UP)) {
|
2011-09-12 23:52:55 +00:00
|
|
|
syslog(LOG_NOTICE,
|
|
|
|
"<interface %s becomes down. stop timer.",
|
|
|
|
ifi->ifi_ifname);
|
2011-07-17 19:24:54 +00:00
|
|
|
rtadvd_remove_timer(ifi->ifi_ra_timer);
|
|
|
|
ifi->ifi_ra_timer = NULL;
|
2003-08-08 16:56:01 +00:00
|
|
|
} else if (!(oldifflags & IFF_UP) && /* DOWN to UP */
|
2011-07-17 19:24:54 +00:00
|
|
|
(ifi->ifi_flags & IFF_UP)) {
|
2011-09-12 23:52:55 +00:00
|
|
|
syslog(LOG_NOTICE,
|
|
|
|
"interface %s becomes up. restart timer.",
|
|
|
|
ifi->ifi_ifname);
|
2011-07-17 19:24:54 +00:00
|
|
|
|
|
|
|
ifi->ifi_state = IFI_STATE_TRANSITIVE;
|
|
|
|
ifi->ifi_burstcount =
|
|
|
|
MAX_INITIAL_RTR_ADVERTISEMENTS;
|
|
|
|
ifi->ifi_burstinterval =
|
|
|
|
MAX_INITIAL_RTR_ADVERT_INTERVAL;
|
|
|
|
|
|
|
|
ifi->ifi_ra_timer = rtadvd_add_timer(ra_timeout,
|
|
|
|
ra_timer_update, ifi, ifi);
|
|
|
|
ra_timer_update(ifi, &ifi->ifi_ra_timer->rat_tm);
|
|
|
|
rtadvd_set_timer(&ifi->ifi_ra_timer->rat_tm,
|
|
|
|
ifi->ifi_ra_timer);
|
- supported a string notation for xxflags.
- deprecate routes#N, as it is hard to keep consistency with
rtprefixN. accept any number of "rtprefix", "rtrefix0",
..., "rtprefix99".
- deprecate "addrs#N", as it is difficult for users to keep
consistency with "addrN".
accept 100 prefix info in maximum - like "addr", "addr0"
... "addr99". WARNS=2 clean on netbsd.
old configuration file should work just fine.
behavior change:
previously, we rejected "addrN" if there's "addr", and we rejected
"addr" if there is "addrN". now we accept both without problem.
- when an advertised prefix configured from the kernel has been added
or invalidated, notice the change in a short delay.
- when invalidating a prefix, do not bark even if there is
inconsistency about prefix lifetimes.
- wrap more specific route info code into ROUTEINFO.
Obtained from: KAME
MFC after: 1 week
2003-08-15 19:13:53 +00:00
|
|
|
} else if (prefixchange &&
|
2011-07-17 19:24:54 +00:00
|
|
|
(ifi->ifi_flags & IFF_UP)) {
|
- supported a string notation for xxflags.
- deprecate routes#N, as it is hard to keep consistency with
rtprefixN. accept any number of "rtprefix", "rtrefix0",
..., "rtprefix99".
- deprecate "addrs#N", as it is difficult for users to keep
consistency with "addrN".
accept 100 prefix info in maximum - like "addr", "addr0"
... "addr99". WARNS=2 clean on netbsd.
old configuration file should work just fine.
behavior change:
previously, we rejected "addrN" if there's "addr", and we rejected
"addr" if there is "addrN". now we accept both without problem.
- when an advertised prefix configured from the kernel has been added
or invalidated, notice the change in a short delay.
- when invalidating a prefix, do not bark even if there is
inconsistency about prefix lifetimes.
- wrap more specific route info code into ROUTEINFO.
Obtained from: KAME
MFC after: 1 week
2003-08-15 19:13:53 +00:00
|
|
|
/*
|
|
|
|
* An advertised prefix has been added or invalidated.
|
|
|
|
* Will notice the change in a short delay.
|
|
|
|
*/
|
2011-07-17 19:24:54 +00:00
|
|
|
set_short_delay(ifi);
|
2000-07-05 22:09:50 +00:00
|
|
|
}
|
2000-01-06 12:40:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-07-17 19:24:54 +00:00
|
|
|
rtadvd_input(struct sockinfo *s)
|
2000-01-06 12:40:54 +00:00
|
|
|
{
|
2011-06-06 03:06:43 +00:00
|
|
|
ssize_t i;
|
2000-01-06 12:40:54 +00:00
|
|
|
int *hlimp = NULL;
|
2000-07-05 22:09:50 +00:00
|
|
|
#ifdef OLDRAWSOCKET
|
|
|
|
struct ip6_hdr *ip;
|
2011-06-06 03:06:43 +00:00
|
|
|
#endif
|
2000-01-06 12:40:54 +00:00
|
|
|
struct icmp6_hdr *icp;
|
|
|
|
int ifindex = 0;
|
|
|
|
struct cmsghdr *cm;
|
|
|
|
struct in6_pktinfo *pi = NULL;
|
2011-07-17 19:24:54 +00:00
|
|
|
char ntopbuf[INET6_ADDRSTRLEN], ifnamebuf[IFNAMSIZ];
|
2000-01-06 12:40:54 +00:00
|
|
|
struct in6_addr dst = in6addr_any;
|
2011-07-17 19:24:54 +00:00
|
|
|
struct ifinfo *ifi;
|
|
|
|
|
|
|
|
syslog(LOG_DEBUG, "<%s> enter", __func__);
|
2000-01-06 12:40:54 +00:00
|
|
|
|
2011-07-17 19:24:54 +00:00
|
|
|
if (s == NULL) {
|
|
|
|
syslog(LOG_ERR, "<%s> internal error", __func__);
|
|
|
|
exit(1);
|
|
|
|
}
|
2000-01-06 12:40:54 +00:00
|
|
|
/*
|
|
|
|
* Get message. We reset msg_controllen since the field could
|
|
|
|
* be modified if we had received a message before setting
|
|
|
|
* receive options.
|
|
|
|
*/
|
2000-07-05 22:09:50 +00:00
|
|
|
rcvmhdr.msg_controllen = rcvcmsgbuflen;
|
2011-07-17 19:24:54 +00:00
|
|
|
if ((i = recvmsg(s->si_fd, &rcvmhdr, 0)) < 0)
|
2000-01-06 12:40:54 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* extract optional information via Advanced API */
|
|
|
|
for (cm = (struct cmsghdr *)CMSG_FIRSTHDR(&rcvmhdr);
|
|
|
|
cm;
|
|
|
|
cm = (struct cmsghdr *)CMSG_NXTHDR(&rcvmhdr, cm)) {
|
|
|
|
if (cm->cmsg_level == IPPROTO_IPV6 &&
|
|
|
|
cm->cmsg_type == IPV6_PKTINFO &&
|
|
|
|
cm->cmsg_len == CMSG_LEN(sizeof(struct in6_pktinfo))) {
|
|
|
|
pi = (struct in6_pktinfo *)(CMSG_DATA(cm));
|
|
|
|
ifindex = pi->ipi6_ifindex;
|
|
|
|
dst = pi->ipi6_addr;
|
|
|
|
}
|
|
|
|
if (cm->cmsg_level == IPPROTO_IPV6 &&
|
|
|
|
cm->cmsg_type == IPV6_HOPLIMIT &&
|
|
|
|
cm->cmsg_len == CMSG_LEN(sizeof(int)))
|
|
|
|
hlimp = (int *)CMSG_DATA(cm);
|
|
|
|
}
|
|
|
|
if (ifindex == 0) {
|
2011-09-12 23:52:55 +00:00
|
|
|
syslog(LOG_ERR, "failed to get receiving interface");
|
2000-01-06 12:40:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (hlimp == NULL) {
|
2011-09-12 23:52:55 +00:00
|
|
|
syslog(LOG_ERR, "failed to get receiving hop limit");
|
2000-01-06 12:40:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-07-05 22:09:50 +00:00
|
|
|
/*
|
2011-03-02 17:13:07 +00:00
|
|
|
* If we happen to receive data on an interface which is now gone
|
|
|
|
* or down, just discard the data.
|
2000-07-05 22:09:50 +00:00
|
|
|
*/
|
2011-07-17 19:24:54 +00:00
|
|
|
ifi = if_indextoifinfo(pi->ipi6_ifindex);
|
|
|
|
if (ifi == NULL || !(ifi->ifi_flags & IFF_UP)) {
|
2000-07-05 22:09:50 +00:00
|
|
|
syslog(LOG_INFO,
|
2011-06-06 03:06:43 +00:00
|
|
|
"<%s> received data on a disabled interface (%s)",
|
|
|
|
__func__,
|
2011-07-17 19:24:54 +00:00
|
|
|
(ifi == NULL) ? "[gone]" : ifi->ifi_ifname);
|
2000-07-05 22:09:50 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef OLDRAWSOCKET
|
2011-06-06 03:06:43 +00:00
|
|
|
if ((size_t)i < sizeof(struct ip6_hdr) + sizeof(struct icmp6_hdr)) {
|
2000-07-05 22:09:50 +00:00
|
|
|
syslog(LOG_ERR,
|
2011-09-12 23:52:55 +00:00
|
|
|
"packet size(%d) is too short", i);
|
2000-07-05 22:09:50 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ip = (struct ip6_hdr *)rcvmhdr.msg_iov[0].iov_base;
|
|
|
|
icp = (struct icmp6_hdr *)(ip + 1); /* XXX: ext. hdr? */
|
|
|
|
#else
|
2011-06-06 03:06:43 +00:00
|
|
|
if ((size_t)i < sizeof(struct icmp6_hdr)) {
|
2011-09-12 23:52:55 +00:00
|
|
|
syslog(LOG_ERR, "packet size(%zd) is too short", i);
|
2000-01-06 12:40:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
icp = (struct icmp6_hdr *)rcvmhdr.msg_iov[0].iov_base;
|
2000-07-05 22:09:50 +00:00
|
|
|
#endif
|
2000-01-06 12:40:54 +00:00
|
|
|
|
2002-06-01 17:28:12 +00:00
|
|
|
switch (icp->icmp6_type) {
|
|
|
|
case ND_ROUTER_SOLICIT:
|
|
|
|
/*
|
2011-06-06 03:06:43 +00:00
|
|
|
* Message verification - RFC 4861 6.1.1
|
2002-06-01 17:28:12 +00:00
|
|
|
* XXX: these checks must be done in the kernel as well,
|
|
|
|
* but we can't completely rely on them.
|
|
|
|
*/
|
|
|
|
if (*hlimp != 255) {
|
|
|
|
syslog(LOG_NOTICE,
|
2011-09-12 23:52:55 +00:00
|
|
|
"RS with invalid hop limit(%d) "
|
2002-06-01 17:28:12 +00:00
|
|
|
"received from %s on %s",
|
2011-09-12 23:52:55 +00:00
|
|
|
*hlimp,
|
2003-08-14 16:51:13 +00:00
|
|
|
inet_ntop(AF_INET6, &rcvfrom.sin6_addr, ntopbuf,
|
2011-06-06 03:06:43 +00:00
|
|
|
sizeof(ntopbuf)),
|
2002-06-01 17:28:12 +00:00
|
|
|
if_indextoname(pi->ipi6_ifindex, ifnamebuf));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (icp->icmp6_code) {
|
|
|
|
syslog(LOG_NOTICE,
|
2011-09-12 23:52:55 +00:00
|
|
|
"RS with invalid ICMP6 code(%d) "
|
2002-06-01 17:28:12 +00:00
|
|
|
"received from %s on %s",
|
2011-09-12 23:52:55 +00:00
|
|
|
icp->icmp6_code,
|
2003-08-14 16:51:13 +00:00
|
|
|
inet_ntop(AF_INET6, &rcvfrom.sin6_addr, ntopbuf,
|
2011-06-06 03:06:43 +00:00
|
|
|
sizeof(ntopbuf)),
|
2002-06-01 17:28:12 +00:00
|
|
|
if_indextoname(pi->ipi6_ifindex, ifnamebuf));
|
|
|
|
return;
|
|
|
|
}
|
2011-06-06 03:06:43 +00:00
|
|
|
if ((size_t)i < sizeof(struct nd_router_solicit)) {
|
2002-06-01 17:28:12 +00:00
|
|
|
syslog(LOG_NOTICE,
|
2011-09-12 23:52:55 +00:00
|
|
|
"RS from %s on %s does not have enough "
|
2011-06-06 10:51:00 +00:00
|
|
|
"length (len = %zd)",
|
2003-08-14 16:51:13 +00:00
|
|
|
inet_ntop(AF_INET6, &rcvfrom.sin6_addr, ntopbuf,
|
2011-06-06 03:06:43 +00:00
|
|
|
sizeof(ntopbuf)),
|
2002-06-01 17:28:12 +00:00
|
|
|
if_indextoname(pi->ipi6_ifindex, ifnamebuf), i);
|
|
|
|
return;
|
|
|
|
}
|
2003-08-14 16:51:13 +00:00
|
|
|
rs_input(i, (struct nd_router_solicit *)icp, pi, &rcvfrom);
|
2002-06-01 17:28:12 +00:00
|
|
|
break;
|
|
|
|
case ND_ROUTER_ADVERT:
|
|
|
|
/*
|
2011-06-06 03:06:43 +00:00
|
|
|
* Message verification - RFC 4861 6.1.2
|
|
|
|
* XXX: there's the same dilemma as above...
|
2002-06-01 17:28:12 +00:00
|
|
|
*/
|
2011-06-06 03:06:43 +00:00
|
|
|
if (!IN6_IS_ADDR_LINKLOCAL(&rcvfrom.sin6_addr)) {
|
|
|
|
syslog(LOG_NOTICE,
|
2011-12-30 10:58:14 +00:00
|
|
|
"RA with non-linklocal source address "
|
2011-06-06 03:06:43 +00:00
|
|
|
"received from %s on %s",
|
2011-09-12 23:52:55 +00:00
|
|
|
inet_ntop(AF_INET6, &rcvfrom.sin6_addr,
|
2011-06-06 03:06:43 +00:00
|
|
|
ntopbuf, sizeof(ntopbuf)),
|
|
|
|
if_indextoname(pi->ipi6_ifindex, ifnamebuf));
|
|
|
|
return;
|
|
|
|
}
|
2002-06-01 17:28:12 +00:00
|
|
|
if (*hlimp != 255) {
|
|
|
|
syslog(LOG_NOTICE,
|
2011-09-12 23:52:55 +00:00
|
|
|
"RA with invalid hop limit(%d) "
|
2002-06-01 17:28:12 +00:00
|
|
|
"received from %s on %s",
|
2011-09-12 23:52:55 +00:00
|
|
|
*hlimp,
|
2003-08-14 16:51:13 +00:00
|
|
|
inet_ntop(AF_INET6, &rcvfrom.sin6_addr, ntopbuf,
|
2011-06-06 03:06:43 +00:00
|
|
|
sizeof(ntopbuf)),
|
2002-06-01 17:28:12 +00:00
|
|
|
if_indextoname(pi->ipi6_ifindex, ifnamebuf));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (icp->icmp6_code) {
|
|
|
|
syslog(LOG_NOTICE,
|
2011-09-12 23:52:55 +00:00
|
|
|
"RA with invalid ICMP6 code(%d) "
|
2002-06-01 17:28:12 +00:00
|
|
|
"received from %s on %s",
|
2011-09-12 23:52:55 +00:00
|
|
|
icp->icmp6_code,
|
2003-08-14 16:51:13 +00:00
|
|
|
inet_ntop(AF_INET6, &rcvfrom.sin6_addr, ntopbuf,
|
2011-06-06 03:06:43 +00:00
|
|
|
sizeof(ntopbuf)),
|
2002-06-01 17:28:12 +00:00
|
|
|
if_indextoname(pi->ipi6_ifindex, ifnamebuf));
|
|
|
|
return;
|
|
|
|
}
|
2011-06-06 03:06:43 +00:00
|
|
|
if ((size_t)i < sizeof(struct nd_router_advert)) {
|
2002-06-01 17:28:12 +00:00
|
|
|
syslog(LOG_NOTICE,
|
2011-09-12 23:52:55 +00:00
|
|
|
"RA from %s on %s does not have enough "
|
2011-06-06 10:51:00 +00:00
|
|
|
"length (len = %zd)",
|
2003-08-14 16:51:13 +00:00
|
|
|
inet_ntop(AF_INET6, &rcvfrom.sin6_addr, ntopbuf,
|
2011-06-06 03:06:43 +00:00
|
|
|
sizeof(ntopbuf)),
|
2002-06-01 17:28:12 +00:00
|
|
|
if_indextoname(pi->ipi6_ifindex, ifnamebuf), i);
|
|
|
|
return;
|
|
|
|
}
|
2003-08-14 16:51:13 +00:00
|
|
|
ra_input(i, (struct nd_router_advert *)icp, pi, &rcvfrom);
|
2002-06-01 17:28:12 +00:00
|
|
|
break;
|
|
|
|
case ICMP6_ROUTER_RENUMBERING:
|
2011-07-17 19:24:54 +00:00
|
|
|
if (mcastif == NULL) {
|
2011-09-12 23:52:55 +00:00
|
|
|
syslog(LOG_ERR, "received a router renumbering "
|
|
|
|
"message, but not allowed to be accepted");
|
2002-06-01 17:28:12 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-08-14 16:51:13 +00:00
|
|
|
rr_input(i, (struct icmp6_router_renum *)icp, pi, &rcvfrom,
|
2011-06-06 03:06:43 +00:00
|
|
|
&dst);
|
2002-06-01 17:28:12 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/*
|
|
|
|
* Note that this case is POSSIBLE, especially just
|
|
|
|
* after invocation of the daemon. This is because we
|
|
|
|
* could receive message after opening the socket and
|
|
|
|
* before setting ICMP6 type filter(see sock_open()).
|
|
|
|
*/
|
2011-09-12 23:52:55 +00:00
|
|
|
syslog(LOG_ERR, "invalid icmp type(%d)", icp->icmp6_type);
|
2002-06-01 17:28:12 +00:00
|
|
|
return;
|
2000-01-06 12:40:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rs_input(int len, struct nd_router_solicit *rs,
|
|
|
|
struct in6_pktinfo *pi, struct sockaddr_in6 *from)
|
|
|
|
{
|
2011-07-17 19:24:54 +00:00
|
|
|
char ntopbuf[INET6_ADDRSTRLEN];
|
|
|
|
char ifnamebuf[IFNAMSIZ];
|
2011-06-06 03:06:43 +00:00
|
|
|
union nd_opt ndopts;
|
|
|
|
struct rainfo *rai;
|
2011-07-17 19:24:54 +00:00
|
|
|
struct ifinfo *ifi;
|
- supported a string notation for xxflags.
- deprecate routes#N, as it is hard to keep consistency with
rtprefixN. accept any number of "rtprefix", "rtrefix0",
..., "rtprefix99".
- deprecate "addrs#N", as it is difficult for users to keep
consistency with "addrN".
accept 100 prefix info in maximum - like "addr", "addr0"
... "addr99". WARNS=2 clean on netbsd.
old configuration file should work just fine.
behavior change:
previously, we rejected "addrN" if there's "addr", and we rejected
"addr" if there is "addrN". now we accept both without problem.
- when an advertised prefix configured from the kernel has been added
or invalidated, notice the change in a short delay.
- when invalidating a prefix, do not bark even if there is
inconsistency about prefix lifetimes.
- wrap more specific route info code into ROUTEINFO.
Obtained from: KAME
MFC after: 1 week
2003-08-15 19:13:53 +00:00
|
|
|
struct soliciter *sol;
|
2000-01-06 12:40:54 +00:00
|
|
|
|
|
|
|
syslog(LOG_DEBUG,
|
2011-06-06 03:06:43 +00:00
|
|
|
"<%s> RS received from %s on %s",
|
|
|
|
__func__,
|
|
|
|
inet_ntop(AF_INET6, &from->sin6_addr, ntopbuf, sizeof(ntopbuf)),
|
|
|
|
if_indextoname(pi->ipi6_ifindex, ifnamebuf));
|
2000-01-06 12:40:54 +00:00
|
|
|
|
|
|
|
/* ND option check */
|
|
|
|
memset(&ndopts, 0, sizeof(ndopts));
|
2011-09-12 23:52:55 +00:00
|
|
|
TAILQ_INIT(&ndopts.opt_list);
|
2000-01-06 12:40:54 +00:00
|
|
|
if (nd6_options((struct nd_opt_hdr *)(rs + 1),
|
|
|
|
len - sizeof(struct nd_router_solicit),
|
2003-08-08 16:56:01 +00:00
|
|
|
&ndopts, NDOPT_FLAG_SRCLINKADDR)) {
|
2005-10-19 15:19:06 +00:00
|
|
|
syslog(LOG_INFO,
|
2011-06-06 03:06:43 +00:00
|
|
|
"<%s> ND option check failed for an RS from %s on %s",
|
|
|
|
__func__,
|
|
|
|
inet_ntop(AF_INET6, &from->sin6_addr, ntopbuf,
|
|
|
|
sizeof(ntopbuf)),
|
|
|
|
if_indextoname(pi->ipi6_ifindex, ifnamebuf));
|
2000-01-06 12:40:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the IP source address is the unspecified address, there
|
|
|
|
* must be no source link-layer address option in the message.
|
2011-06-06 03:06:43 +00:00
|
|
|
* (RFC 4861 6.1.1)
|
2000-01-06 12:40:54 +00:00
|
|
|
*/
|
|
|
|
if (IN6_IS_ADDR_UNSPECIFIED(&from->sin6_addr) &&
|
2011-06-06 03:06:43 +00:00
|
|
|
ndopts.opt_src_lladdr) {
|
2005-10-19 15:19:06 +00:00
|
|
|
syslog(LOG_INFO,
|
2011-06-06 03:06:43 +00:00
|
|
|
"<%s> RS from unspecified src on %s has a link-layer"
|
|
|
|
" address option",
|
|
|
|
__func__, if_indextoname(pi->ipi6_ifindex, ifnamebuf));
|
2000-01-06 12:40:54 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2011-07-17 19:24:54 +00:00
|
|
|
ifi = if_indextoifinfo(pi->ipi6_ifindex);
|
|
|
|
if (ifi == NULL) {
|
|
|
|
syslog(LOG_INFO,
|
|
|
|
"<%s> if (idx=%d) not found. Why?",
|
|
|
|
__func__, pi->ipi6_ifindex);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
rai = ifi->ifi_rainfo;
|
2011-06-06 03:06:43 +00:00
|
|
|
if (rai == NULL) {
|
2000-01-06 12:40:54 +00:00
|
|
|
syslog(LOG_INFO,
|
|
|
|
"<%s> RS received on non advertising interface(%s)",
|
2003-08-08 16:38:23 +00:00
|
|
|
__func__,
|
2000-01-06 12:40:54 +00:00
|
|
|
if_indextoname(pi->ipi6_ifindex, ifnamebuf));
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2011-07-17 19:24:54 +00:00
|
|
|
rai->rai_ifinfo->ifi_rsinput++;
|
2000-07-05 22:09:50 +00:00
|
|
|
|
2000-01-06 12:40:54 +00:00
|
|
|
/*
|
|
|
|
* Decide whether to send RA according to the rate-limit
|
|
|
|
* consideration.
|
|
|
|
*/
|
2000-07-05 22:09:50 +00:00
|
|
|
|
- supported a string notation for xxflags.
- deprecate routes#N, as it is hard to keep consistency with
rtprefixN. accept any number of "rtprefix", "rtrefix0",
..., "rtprefix99".
- deprecate "addrs#N", as it is difficult for users to keep
consistency with "addrN".
accept 100 prefix info in maximum - like "addr", "addr0"
... "addr99". WARNS=2 clean on netbsd.
old configuration file should work just fine.
behavior change:
previously, we rejected "addrN" if there's "addr", and we rejected
"addr" if there is "addrN". now we accept both without problem.
- when an advertised prefix configured from the kernel has been added
or invalidated, notice the change in a short delay.
- when invalidating a prefix, do not bark even if there is
inconsistency about prefix lifetimes.
- wrap more specific route info code into ROUTEINFO.
Obtained from: KAME
MFC after: 1 week
2003-08-15 19:13:53 +00:00
|
|
|
/* record sockaddr waiting for RA, if possible */
|
|
|
|
sol = (struct soliciter *)malloc(sizeof(*sol));
|
|
|
|
if (sol) {
|
2011-06-06 03:06:43 +00:00
|
|
|
sol->sol_addr = *from;
|
|
|
|
/* XXX RFC 2553 need clarification on flowinfo */
|
|
|
|
sol->sol_addr.sin6_flowinfo = 0;
|
|
|
|
TAILQ_INSERT_TAIL(&rai->rai_soliciter, sol, sol_next);
|
- supported a string notation for xxflags.
- deprecate routes#N, as it is hard to keep consistency with
rtprefixN. accept any number of "rtprefix", "rtrefix0",
..., "rtprefix99".
- deprecate "addrs#N", as it is difficult for users to keep
consistency with "addrN".
accept 100 prefix info in maximum - like "addr", "addr0"
... "addr99". WARNS=2 clean on netbsd.
old configuration file should work just fine.
behavior change:
previously, we rejected "addrN" if there's "addr", and we rejected
"addr" if there is "addrN". now we accept both without problem.
- when an advertised prefix configured from the kernel has been added
or invalidated, notice the change in a short delay.
- when invalidating a prefix, do not bark even if there is
inconsistency about prefix lifetimes.
- wrap more specific route info code into ROUTEINFO.
Obtained from: KAME
MFC after: 1 week
2003-08-15 19:13:53 +00:00
|
|
|
}
|
2000-01-06 12:40:54 +00:00
|
|
|
|
- supported a string notation for xxflags.
- deprecate routes#N, as it is hard to keep consistency with
rtprefixN. accept any number of "rtprefix", "rtrefix0",
..., "rtprefix99".
- deprecate "addrs#N", as it is difficult for users to keep
consistency with "addrN".
accept 100 prefix info in maximum - like "addr", "addr0"
... "addr99". WARNS=2 clean on netbsd.
old configuration file should work just fine.
behavior change:
previously, we rejected "addrN" if there's "addr", and we rejected
"addr" if there is "addrN". now we accept both without problem.
- when an advertised prefix configured from the kernel has been added
or invalidated, notice the change in a short delay.
- when invalidating a prefix, do not bark even if there is
inconsistency about prefix lifetimes.
- wrap more specific route info code into ROUTEINFO.
Obtained from: KAME
MFC after: 1 week
2003-08-15 19:13:53 +00:00
|
|
|
/*
|
|
|
|
* If there is already a waiting RS packet, don't
|
|
|
|
* update the timer.
|
|
|
|
*/
|
2011-07-17 19:24:54 +00:00
|
|
|
if (ifi->ifi_rs_waitcount++)
|
2000-07-05 22:09:50 +00:00
|
|
|
goto done;
|
- supported a string notation for xxflags.
- deprecate routes#N, as it is hard to keep consistency with
rtprefixN. accept any number of "rtprefix", "rtrefix0",
..., "rtprefix99".
- deprecate "addrs#N", as it is difficult for users to keep
consistency with "addrN".
accept 100 prefix info in maximum - like "addr", "addr0"
... "addr99". WARNS=2 clean on netbsd.
old configuration file should work just fine.
behavior change:
previously, we rejected "addrN" if there's "addr", and we rejected
"addr" if there is "addrN". now we accept both without problem.
- when an advertised prefix configured from the kernel has been added
or invalidated, notice the change in a short delay.
- when invalidating a prefix, do not bark even if there is
inconsistency about prefix lifetimes.
- wrap more specific route info code into ROUTEINFO.
Obtained from: KAME
MFC after: 1 week
2003-08-15 19:13:53 +00:00
|
|
|
|
2011-07-17 19:24:54 +00:00
|
|
|
set_short_delay(ifi);
|
2000-01-06 12:40:54 +00:00
|
|
|
|
|
|
|
done:
|
|
|
|
free_ndopts(&ndopts);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
- supported a string notation for xxflags.
- deprecate routes#N, as it is hard to keep consistency with
rtprefixN. accept any number of "rtprefix", "rtrefix0",
..., "rtprefix99".
- deprecate "addrs#N", as it is difficult for users to keep
consistency with "addrN".
accept 100 prefix info in maximum - like "addr", "addr0"
... "addr99". WARNS=2 clean on netbsd.
old configuration file should work just fine.
behavior change:
previously, we rejected "addrN" if there's "addr", and we rejected
"addr" if there is "addrN". now we accept both without problem.
- when an advertised prefix configured from the kernel has been added
or invalidated, notice the change in a short delay.
- when invalidating a prefix, do not bark even if there is
inconsistency about prefix lifetimes.
- wrap more specific route info code into ROUTEINFO.
Obtained from: KAME
MFC after: 1 week
2003-08-15 19:13:53 +00:00
|
|
|
static void
|
2011-07-17 19:24:54 +00:00
|
|
|
set_short_delay(struct ifinfo *ifi)
|
- supported a string notation for xxflags.
- deprecate routes#N, as it is hard to keep consistency with
rtprefixN. accept any number of "rtprefix", "rtrefix0",
..., "rtprefix99".
- deprecate "addrs#N", as it is difficult for users to keep
consistency with "addrN".
accept 100 prefix info in maximum - like "addr", "addr0"
... "addr99". WARNS=2 clean on netbsd.
old configuration file should work just fine.
behavior change:
previously, we rejected "addrN" if there's "addr", and we rejected
"addr" if there is "addrN". now we accept both without problem.
- when an advertised prefix configured from the kernel has been added
or invalidated, notice the change in a short delay.
- when invalidating a prefix, do not bark even if there is
inconsistency about prefix lifetimes.
- wrap more specific route info code into ROUTEINFO.
Obtained from: KAME
MFC after: 1 week
2003-08-15 19:13:53 +00:00
|
|
|
{
|
|
|
|
long delay; /* must not be greater than 1000000 */
|
2013-08-05 20:13:02 +00:00
|
|
|
struct timespec interval, now, min_delay, tm_tmp, *rest;
|
- supported a string notation for xxflags.
- deprecate routes#N, as it is hard to keep consistency with
rtprefixN. accept any number of "rtprefix", "rtrefix0",
..., "rtprefix99".
- deprecate "addrs#N", as it is difficult for users to keep
consistency with "addrN".
accept 100 prefix info in maximum - like "addr", "addr0"
... "addr99". WARNS=2 clean on netbsd.
old configuration file should work just fine.
behavior change:
previously, we rejected "addrN" if there's "addr", and we rejected
"addr" if there is "addrN". now we accept both without problem.
- when an advertised prefix configured from the kernel has been added
or invalidated, notice the change in a short delay.
- when invalidating a prefix, do not bark even if there is
inconsistency about prefix lifetimes.
- wrap more specific route info code into ROUTEINFO.
Obtained from: KAME
MFC after: 1 week
2003-08-15 19:13:53 +00:00
|
|
|
|
2013-03-06 04:58:48 +00:00
|
|
|
if (ifi->ifi_ra_timer == NULL)
|
|
|
|
return;
|
- supported a string notation for xxflags.
- deprecate routes#N, as it is hard to keep consistency with
rtprefixN. accept any number of "rtprefix", "rtrefix0",
..., "rtprefix99".
- deprecate "addrs#N", as it is difficult for users to keep
consistency with "addrN".
accept 100 prefix info in maximum - like "addr", "addr0"
... "addr99". WARNS=2 clean on netbsd.
old configuration file should work just fine.
behavior change:
previously, we rejected "addrN" if there's "addr", and we rejected
"addr" if there is "addrN". now we accept both without problem.
- when an advertised prefix configured from the kernel has been added
or invalidated, notice the change in a short delay.
- when invalidating a prefix, do not bark even if there is
inconsistency about prefix lifetimes.
- wrap more specific route info code into ROUTEINFO.
Obtained from: KAME
MFC after: 1 week
2003-08-15 19:13:53 +00:00
|
|
|
/*
|
|
|
|
* Compute a random delay. If the computed value
|
|
|
|
* corresponds to a time later than the time the next
|
|
|
|
* multicast RA is scheduled to be sent, ignore the random
|
|
|
|
* delay and send the advertisement at the
|
2011-06-06 03:06:43 +00:00
|
|
|
* already-scheduled time. RFC 4861 6.2.6
|
- supported a string notation for xxflags.
- deprecate routes#N, as it is hard to keep consistency with
rtprefixN. accept any number of "rtprefix", "rtrefix0",
..., "rtprefix99".
- deprecate "addrs#N", as it is difficult for users to keep
consistency with "addrN".
accept 100 prefix info in maximum - like "addr", "addr0"
... "addr99". WARNS=2 clean on netbsd.
old configuration file should work just fine.
behavior change:
previously, we rejected "addrN" if there's "addr", and we rejected
"addr" if there is "addrN". now we accept both without problem.
- when an advertised prefix configured from the kernel has been added
or invalidated, notice the change in a short delay.
- when invalidating a prefix, do not bark even if there is
inconsistency about prefix lifetimes.
- wrap more specific route info code into ROUTEINFO.
Obtained from: KAME
MFC after: 1 week
2003-08-15 19:13:53 +00:00
|
|
|
*/
|
2008-07-26 15:39:32 +00:00
|
|
|
delay = arc4random_uniform(MAX_RA_DELAY_TIME);
|
- supported a string notation for xxflags.
- deprecate routes#N, as it is hard to keep consistency with
rtprefixN. accept any number of "rtprefix", "rtrefix0",
..., "rtprefix99".
- deprecate "addrs#N", as it is difficult for users to keep
consistency with "addrN".
accept 100 prefix info in maximum - like "addr", "addr0"
... "addr99". WARNS=2 clean on netbsd.
old configuration file should work just fine.
behavior change:
previously, we rejected "addrN" if there's "addr", and we rejected
"addr" if there is "addrN". now we accept both without problem.
- when an advertised prefix configured from the kernel has been added
or invalidated, notice the change in a short delay.
- when invalidating a prefix, do not bark even if there is
inconsistency about prefix lifetimes.
- wrap more specific route info code into ROUTEINFO.
Obtained from: KAME
MFC after: 1 week
2003-08-15 19:13:53 +00:00
|
|
|
interval.tv_sec = 0;
|
2013-08-05 20:13:02 +00:00
|
|
|
interval.tv_nsec = delay * 1000;
|
2011-07-17 19:24:54 +00:00
|
|
|
rest = rtadvd_timer_rest(ifi->ifi_ra_timer);
|
2013-08-05 20:13:02 +00:00
|
|
|
if (TS_CMP(rest, &interval, <)) {
|
- supported a string notation for xxflags.
- deprecate routes#N, as it is hard to keep consistency with
rtprefixN. accept any number of "rtprefix", "rtrefix0",
..., "rtprefix99".
- deprecate "addrs#N", as it is difficult for users to keep
consistency with "addrN".
accept 100 prefix info in maximum - like "addr", "addr0"
... "addr99". WARNS=2 clean on netbsd.
old configuration file should work just fine.
behavior change:
previously, we rejected "addrN" if there's "addr", and we rejected
"addr" if there is "addrN". now we accept both without problem.
- when an advertised prefix configured from the kernel has been added
or invalidated, notice the change in a short delay.
- when invalidating a prefix, do not bark even if there is
inconsistency about prefix lifetimes.
- wrap more specific route info code into ROUTEINFO.
Obtained from: KAME
MFC after: 1 week
2003-08-15 19:13:53 +00:00
|
|
|
syslog(LOG_DEBUG, "<%s> random delay is larger than "
|
|
|
|
"the rest of the current timer", __func__);
|
|
|
|
interval = *rest;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we sent a multicast Router Advertisement within
|
|
|
|
* the last MIN_DELAY_BETWEEN_RAS seconds, schedule
|
|
|
|
* the advertisement to be sent at a time corresponding to
|
|
|
|
* MIN_DELAY_BETWEEN_RAS plus the random value after the
|
|
|
|
* previous advertisement was sent.
|
|
|
|
*/
|
2013-08-05 20:13:02 +00:00
|
|
|
clock_gettime(CLOCK_MONOTONIC_FAST, &now);
|
|
|
|
TS_SUB(&now, &ifi->ifi_ra_lastsent, &tm_tmp);
|
- supported a string notation for xxflags.
- deprecate routes#N, as it is hard to keep consistency with
rtprefixN. accept any number of "rtprefix", "rtrefix0",
..., "rtprefix99".
- deprecate "addrs#N", as it is difficult for users to keep
consistency with "addrN".
accept 100 prefix info in maximum - like "addr", "addr0"
... "addr99". WARNS=2 clean on netbsd.
old configuration file should work just fine.
behavior change:
previously, we rejected "addrN" if there's "addr", and we rejected
"addr" if there is "addrN". now we accept both without problem.
- when an advertised prefix configured from the kernel has been added
or invalidated, notice the change in a short delay.
- when invalidating a prefix, do not bark even if there is
inconsistency about prefix lifetimes.
- wrap more specific route info code into ROUTEINFO.
Obtained from: KAME
MFC after: 1 week
2003-08-15 19:13:53 +00:00
|
|
|
min_delay.tv_sec = MIN_DELAY_BETWEEN_RAS;
|
2013-08-05 20:13:02 +00:00
|
|
|
min_delay.tv_nsec = 0;
|
|
|
|
if (TS_CMP(&tm_tmp, &min_delay, <)) {
|
|
|
|
TS_SUB(&min_delay, &tm_tmp, &min_delay);
|
|
|
|
TS_ADD(&min_delay, &interval, &interval);
|
- supported a string notation for xxflags.
- deprecate routes#N, as it is hard to keep consistency with
rtprefixN. accept any number of "rtprefix", "rtrefix0",
..., "rtprefix99".
- deprecate "addrs#N", as it is difficult for users to keep
consistency with "addrN".
accept 100 prefix info in maximum - like "addr", "addr0"
... "addr99". WARNS=2 clean on netbsd.
old configuration file should work just fine.
behavior change:
previously, we rejected "addrN" if there's "addr", and we rejected
"addr" if there is "addrN". now we accept both without problem.
- when an advertised prefix configured from the kernel has been added
or invalidated, notice the change in a short delay.
- when invalidating a prefix, do not bark even if there is
inconsistency about prefix lifetimes.
- wrap more specific route info code into ROUTEINFO.
Obtained from: KAME
MFC after: 1 week
2003-08-15 19:13:53 +00:00
|
|
|
}
|
2011-07-17 19:24:54 +00:00
|
|
|
rtadvd_set_timer(&interval, ifi->ifi_ra_timer);
|
2011-06-06 03:06:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
check_accept_rtadv(int idx)
|
|
|
|
{
|
2011-07-17 19:24:54 +00:00
|
|
|
struct ifinfo *ifi;
|
2011-06-06 03:06:43 +00:00
|
|
|
|
2011-07-17 19:24:54 +00:00
|
|
|
TAILQ_FOREACH(ifi, &ifilist, ifi_next) {
|
|
|
|
if (ifi->ifi_ifindex == idx)
|
|
|
|
break;
|
2011-06-06 03:06:43 +00:00
|
|
|
}
|
2011-07-17 19:24:54 +00:00
|
|
|
if (ifi == NULL) {
|
2011-09-12 23:52:55 +00:00
|
|
|
syslog(LOG_DEBUG,
|
2011-07-17 19:24:54 +00:00
|
|
|
"<%s> if (idx=%d) not found. Why?",
|
2011-06-06 03:06:43 +00:00
|
|
|
__func__, idx);
|
|
|
|
return (0);
|
|
|
|
}
|
2011-07-17 19:24:54 +00:00
|
|
|
#if (__FreeBSD_version < 900000)
|
|
|
|
/*
|
|
|
|
* RA_RECV: !ip6.forwarding && ip6.accept_rtadv
|
|
|
|
* RA_SEND: ip6.forwarding
|
|
|
|
*/
|
|
|
|
return ((getinet6sysctl(IPV6CTL_FORWARDING) == 0) &&
|
|
|
|
(getinet6sysctl(IPV6CTL_ACCEPT_RTADV) == 1));
|
|
|
|
#else
|
|
|
|
/*
|
|
|
|
* RA_RECV: ND6_IFF_ACCEPT_RTADV
|
|
|
|
* RA_SEND: ip6.forwarding
|
|
|
|
*/
|
|
|
|
if (update_ifinfo_nd_flags(ifi) != 0) {
|
2011-09-12 23:52:55 +00:00
|
|
|
syslog(LOG_ERR, "cannot get nd6 flags (idx=%d)", idx);
|
2011-07-17 19:24:54 +00:00
|
|
|
return (0);
|
2011-06-06 03:06:43 +00:00
|
|
|
}
|
|
|
|
|
2011-07-17 19:24:54 +00:00
|
|
|
return (ifi->ifi_nd_flags & ND6_IFF_ACCEPT_RTADV);
|
|
|
|
#endif
|
- supported a string notation for xxflags.
- deprecate routes#N, as it is hard to keep consistency with
rtprefixN. accept any number of "rtprefix", "rtrefix0",
..., "rtprefix99".
- deprecate "addrs#N", as it is difficult for users to keep
consistency with "addrN".
accept 100 prefix info in maximum - like "addr", "addr0"
... "addr99". WARNS=2 clean on netbsd.
old configuration file should work just fine.
behavior change:
previously, we rejected "addrN" if there's "addr", and we rejected
"addr" if there is "addrN". now we accept both without problem.
- when an advertised prefix configured from the kernel has been added
or invalidated, notice the change in a short delay.
- when invalidating a prefix, do not bark even if there is
inconsistency about prefix lifetimes.
- wrap more specific route info code into ROUTEINFO.
Obtained from: KAME
MFC after: 1 week
2003-08-15 19:13:53 +00:00
|
|
|
}
|
|
|
|
|
2000-01-06 12:40:54 +00:00
|
|
|
static void
|
2011-06-06 03:06:43 +00:00
|
|
|
ra_input(int len, struct nd_router_advert *nra,
|
2000-01-06 12:40:54 +00:00
|
|
|
struct in6_pktinfo *pi, struct sockaddr_in6 *from)
|
|
|
|
{
|
|
|
|
struct rainfo *rai;
|
2011-07-17 19:24:54 +00:00
|
|
|
struct ifinfo *ifi;
|
|
|
|
char ntopbuf[INET6_ADDRSTRLEN];
|
|
|
|
char ifnamebuf[IFNAMSIZ];
|
2011-06-06 03:06:43 +00:00
|
|
|
union nd_opt ndopts;
|
|
|
|
const char *on_off[] = {"OFF", "ON"};
|
2011-07-17 19:24:54 +00:00
|
|
|
uint32_t reachabletime, retranstimer, mtu;
|
2000-07-05 22:09:50 +00:00
|
|
|
int inconsistent = 0;
|
2011-06-06 03:06:43 +00:00
|
|
|
int error;
|
|
|
|
|
|
|
|
syslog(LOG_DEBUG, "<%s> RA received from %s on %s", __func__,
|
|
|
|
inet_ntop(AF_INET6, &from->sin6_addr, ntopbuf, sizeof(ntopbuf)),
|
|
|
|
if_indextoname(pi->ipi6_ifindex, ifnamebuf));
|
|
|
|
|
2000-01-06 12:40:54 +00:00
|
|
|
/* ND option check */
|
|
|
|
memset(&ndopts, 0, sizeof(ndopts));
|
2011-09-12 23:52:55 +00:00
|
|
|
TAILQ_INIT(&ndopts.opt_list);
|
2011-06-06 03:06:43 +00:00
|
|
|
error = nd6_options((struct nd_opt_hdr *)(nra + 1),
|
|
|
|
len - sizeof(struct nd_router_advert), &ndopts,
|
|
|
|
NDOPT_FLAG_SRCLINKADDR | NDOPT_FLAG_PREFIXINFO | NDOPT_FLAG_MTU |
|
|
|
|
NDOPT_FLAG_RDNSS | NDOPT_FLAG_DNSSL);
|
|
|
|
if (error) {
|
2005-10-19 15:19:06 +00:00
|
|
|
syslog(LOG_INFO,
|
2011-06-06 03:06:43 +00:00
|
|
|
"<%s> ND option check failed for an RA from %s on %s",
|
|
|
|
__func__,
|
|
|
|
inet_ntop(AF_INET6, &from->sin6_addr, ntopbuf,
|
|
|
|
sizeof(ntopbuf)), if_indextoname(pi->ipi6_ifindex,
|
|
|
|
ifnamebuf));
|
2000-01-06 12:40:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2011-06-06 03:06:43 +00:00
|
|
|
* RA consistency check according to RFC 4861 6.2.7
|
2000-01-06 12:40:54 +00:00
|
|
|
*/
|
2011-07-17 19:24:54 +00:00
|
|
|
ifi = if_indextoifinfo(pi->ipi6_ifindex);
|
|
|
|
if (ifi->ifi_rainfo == NULL) {
|
2000-01-06 12:40:54 +00:00
|
|
|
syslog(LOG_INFO,
|
2011-06-06 03:06:43 +00:00
|
|
|
"<%s> received RA from %s on non-advertising"
|
|
|
|
" interface(%s)",
|
|
|
|
__func__,
|
|
|
|
inet_ntop(AF_INET6, &from->sin6_addr, ntopbuf,
|
|
|
|
sizeof(ntopbuf)), if_indextoname(pi->ipi6_ifindex,
|
|
|
|
ifnamebuf));
|
2000-01-06 12:40:54 +00:00
|
|
|
goto done;
|
|
|
|
}
|
2011-07-17 19:24:54 +00:00
|
|
|
rai = ifi->ifi_rainfo;
|
|
|
|
ifi->ifi_rainput++;
|
2011-09-12 23:52:55 +00:00
|
|
|
syslog(LOG_DEBUG, "<%s> ifi->ifi_rainput = %" PRIu64, __func__,
|
2011-07-17 19:24:54 +00:00
|
|
|
ifi->ifi_rainput);
|
2011-06-06 03:06:43 +00:00
|
|
|
|
2000-01-06 12:40:54 +00:00
|
|
|
/* Cur Hop Limit value */
|
2011-06-06 03:06:43 +00:00
|
|
|
if (nra->nd_ra_curhoplimit && rai->rai_hoplimit &&
|
|
|
|
nra->nd_ra_curhoplimit != rai->rai_hoplimit) {
|
2011-09-12 23:52:55 +00:00
|
|
|
syslog(LOG_NOTICE,
|
|
|
|
"CurHopLimit inconsistent on %s:"
|
2011-06-06 03:06:43 +00:00
|
|
|
" %d from %s, %d from us",
|
2011-09-12 23:52:55 +00:00
|
|
|
ifi->ifi_ifname, nra->nd_ra_curhoplimit,
|
2011-06-06 03:06:43 +00:00
|
|
|
inet_ntop(AF_INET6, &from->sin6_addr, ntopbuf,
|
|
|
|
sizeof(ntopbuf)), rai->rai_hoplimit);
|
2000-07-05 22:09:50 +00:00
|
|
|
inconsistent++;
|
2000-01-06 12:40:54 +00:00
|
|
|
}
|
|
|
|
/* M flag */
|
2011-06-06 03:06:43 +00:00
|
|
|
if ((nra->nd_ra_flags_reserved & ND_RA_FLAG_MANAGED) !=
|
|
|
|
rai->rai_managedflg) {
|
2011-09-12 23:52:55 +00:00
|
|
|
syslog(LOG_NOTICE,
|
|
|
|
"M flag inconsistent on %s:"
|
2011-06-06 03:06:43 +00:00
|
|
|
" %s from %s, %s from us",
|
2011-09-12 23:52:55 +00:00
|
|
|
ifi->ifi_ifname, on_off[!rai->rai_managedflg],
|
2011-06-06 03:06:43 +00:00
|
|
|
inet_ntop(AF_INET6, &from->sin6_addr, ntopbuf,
|
|
|
|
sizeof(ntopbuf)), on_off[rai->rai_managedflg]);
|
2000-07-05 22:09:50 +00:00
|
|
|
inconsistent++;
|
2000-01-06 12:40:54 +00:00
|
|
|
}
|
|
|
|
/* O flag */
|
2011-06-06 03:06:43 +00:00
|
|
|
if ((nra->nd_ra_flags_reserved & ND_RA_FLAG_OTHER) !=
|
|
|
|
rai->rai_otherflg) {
|
2011-09-12 23:52:55 +00:00
|
|
|
syslog(LOG_NOTICE,
|
|
|
|
"O flag inconsistent on %s:"
|
2011-06-06 03:06:43 +00:00
|
|
|
" %s from %s, %s from us",
|
2011-09-12 23:52:55 +00:00
|
|
|
ifi->ifi_ifname, on_off[!rai->rai_otherflg],
|
2011-06-06 03:06:43 +00:00
|
|
|
inet_ntop(AF_INET6, &from->sin6_addr, ntopbuf,
|
|
|
|
sizeof(ntopbuf)), on_off[rai->rai_otherflg]);
|
2000-07-05 22:09:50 +00:00
|
|
|
inconsistent++;
|
2000-01-06 12:40:54 +00:00
|
|
|
}
|
|
|
|
/* Reachable Time */
|
2011-06-06 03:06:43 +00:00
|
|
|
reachabletime = ntohl(nra->nd_ra_reachable);
|
|
|
|
if (reachabletime && rai->rai_reachabletime &&
|
|
|
|
reachabletime != rai->rai_reachabletime) {
|
2011-09-12 23:52:55 +00:00
|
|
|
syslog(LOG_NOTICE,
|
|
|
|
"ReachableTime inconsistent on %s:"
|
2011-06-06 03:06:43 +00:00
|
|
|
" %d from %s, %d from us",
|
2011-09-12 23:52:55 +00:00
|
|
|
ifi->ifi_ifname, reachabletime,
|
2011-06-06 03:06:43 +00:00
|
|
|
inet_ntop(AF_INET6, &from->sin6_addr, ntopbuf,
|
|
|
|
sizeof(ntopbuf)), rai->rai_reachabletime);
|
2000-07-05 22:09:50 +00:00
|
|
|
inconsistent++;
|
2000-01-06 12:40:54 +00:00
|
|
|
}
|
|
|
|
/* Retrans Timer */
|
2011-06-06 03:06:43 +00:00
|
|
|
retranstimer = ntohl(nra->nd_ra_retransmit);
|
|
|
|
if (retranstimer && rai->rai_retranstimer &&
|
|
|
|
retranstimer != rai->rai_retranstimer) {
|
2011-09-12 23:52:55 +00:00
|
|
|
syslog(LOG_NOTICE,
|
|
|
|
"RetranceTimer inconsistent on %s:"
|
2011-06-06 03:06:43 +00:00
|
|
|
" %d from %s, %d from us",
|
2011-09-12 23:52:55 +00:00
|
|
|
ifi->ifi_ifname, retranstimer,
|
2011-06-06 03:06:43 +00:00
|
|
|
inet_ntop(AF_INET6, &from->sin6_addr, ntopbuf,
|
|
|
|
sizeof(ntopbuf)), rai->rai_retranstimer);
|
2000-07-05 22:09:50 +00:00
|
|
|
inconsistent++;
|
2000-01-06 12:40:54 +00:00
|
|
|
}
|
|
|
|
/* Values in the MTU options */
|
2011-06-06 03:06:43 +00:00
|
|
|
if (ndopts.opt_mtu) {
|
|
|
|
mtu = ntohl(ndopts.opt_mtu->nd_opt_mtu_mtu);
|
|
|
|
if (mtu && rai->rai_linkmtu && mtu != rai->rai_linkmtu) {
|
2011-09-12 23:52:55 +00:00
|
|
|
syslog(LOG_NOTICE,
|
|
|
|
"MTU option value inconsistent on %s:"
|
2011-06-06 03:06:43 +00:00
|
|
|
" %d from %s, %d from us",
|
2011-09-12 23:52:55 +00:00
|
|
|
ifi->ifi_ifname, mtu,
|
2011-06-06 03:06:43 +00:00
|
|
|
inet_ntop(AF_INET6, &from->sin6_addr, ntopbuf,
|
|
|
|
sizeof(ntopbuf)), rai->rai_linkmtu);
|
2000-07-05 22:09:50 +00:00
|
|
|
inconsistent++;
|
2000-01-06 12:40:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Preferred and Valid Lifetimes for prefixes */
|
|
|
|
{
|
2011-06-06 03:06:43 +00:00
|
|
|
struct nd_optlist *nol;
|
2001-06-11 12:39:29 +00:00
|
|
|
|
2011-06-06 03:06:43 +00:00
|
|
|
if (ndopts.opt_pi)
|
|
|
|
if (prefix_check(ndopts.opt_pi, rai, from))
|
2000-07-05 22:09:50 +00:00
|
|
|
inconsistent++;
|
2011-06-06 03:06:43 +00:00
|
|
|
|
|
|
|
TAILQ_FOREACH(nol, &ndopts.opt_list, nol_next)
|
|
|
|
if (prefix_check((struct nd_opt_prefix_info *)nol->nol_opt,
|
|
|
|
rai, from))
|
2000-07-05 22:09:50 +00:00
|
|
|
inconsistent++;
|
2000-01-06 12:40:54 +00:00
|
|
|
}
|
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
if (inconsistent)
|
2011-07-17 19:24:54 +00:00
|
|
|
ifi->ifi_rainconsistent++;
|
2011-06-06 03:06:43 +00:00
|
|
|
|
2000-01-06 12:40:54 +00:00
|
|
|
done:
|
|
|
|
free_ndopts(&ndopts);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-11-22 23:04:33 +00:00
|
|
|
static uint32_t
|
|
|
|
udiff(uint32_t u, uint32_t v)
|
|
|
|
{
|
|
|
|
return (u >= v ? u - v : v - u);
|
|
|
|
}
|
|
|
|
|
2000-07-05 22:09:50 +00:00
|
|
|
/* return a non-zero value if the received prefix is inconsitent with ours */
|
|
|
|
static int
|
2000-01-06 12:40:54 +00:00
|
|
|
prefix_check(struct nd_opt_prefix_info *pinfo,
|
2011-06-06 03:06:43 +00:00
|
|
|
struct rainfo *rai, struct sockaddr_in6 *from)
|
2000-01-06 12:40:54 +00:00
|
|
|
{
|
2011-07-17 19:24:54 +00:00
|
|
|
struct ifinfo *ifi;
|
|
|
|
uint32_t preferred_time, valid_time;
|
2011-06-06 03:06:43 +00:00
|
|
|
struct prefix *pfx;
|
2000-07-05 22:09:50 +00:00
|
|
|
int inconsistent = 0;
|
2011-07-17 19:24:54 +00:00
|
|
|
char ntopbuf[INET6_ADDRSTRLEN];
|
|
|
|
char prefixbuf[INET6_ADDRSTRLEN];
|
2013-08-05 20:13:02 +00:00
|
|
|
struct timespec now;
|
2000-01-06 12:40:54 +00:00
|
|
|
|
2000-07-05 22:09:50 +00:00
|
|
|
#if 0 /* impossible */
|
|
|
|
if (pinfo->nd_opt_pi_type != ND_OPT_PREFIX_INFORMATION)
|
2011-06-06 03:06:43 +00:00
|
|
|
return (0);
|
2000-07-05 22:09:50 +00:00
|
|
|
#endif
|
2011-07-17 19:24:54 +00:00
|
|
|
ifi = rai->rai_ifinfo;
|
2000-01-06 12:40:54 +00:00
|
|
|
/*
|
|
|
|
* log if the adveritsed prefix has link-local scope(sanity check?)
|
|
|
|
*/
|
2011-06-06 03:06:43 +00:00
|
|
|
if (IN6_IS_ADDR_LINKLOCAL(&pinfo->nd_opt_pi_prefix))
|
2000-01-06 12:40:54 +00:00
|
|
|
syslog(LOG_INFO,
|
2011-06-06 03:06:43 +00:00
|
|
|
"<%s> link-local prefix %s/%d is advertised "
|
|
|
|
"from %s on %s",
|
|
|
|
__func__,
|
|
|
|
inet_ntop(AF_INET6, &pinfo->nd_opt_pi_prefix, prefixbuf,
|
|
|
|
sizeof(prefixbuf)),
|
|
|
|
pinfo->nd_opt_pi_prefix_len,
|
|
|
|
inet_ntop(AF_INET6, &from->sin6_addr, ntopbuf,
|
2011-07-17 19:24:54 +00:00
|
|
|
sizeof(ntopbuf)), ifi->ifi_ifname);
|
2011-06-06 03:06:43 +00:00
|
|
|
|
|
|
|
if ((pfx = find_prefix(rai, &pinfo->nd_opt_pi_prefix,
|
|
|
|
pinfo->nd_opt_pi_prefix_len)) == NULL) {
|
2000-01-06 12:40:54 +00:00
|
|
|
syslog(LOG_INFO,
|
2011-06-06 03:06:43 +00:00
|
|
|
"<%s> prefix %s/%d from %s on %s is not in our list",
|
|
|
|
__func__,
|
|
|
|
inet_ntop(AF_INET6, &pinfo->nd_opt_pi_prefix, prefixbuf,
|
|
|
|
sizeof(prefixbuf)),
|
|
|
|
pinfo->nd_opt_pi_prefix_len,
|
|
|
|
inet_ntop(AF_INET6, &from->sin6_addr, ntopbuf,
|
2011-07-17 19:24:54 +00:00
|
|
|
sizeof(ntopbuf)), ifi->ifi_ifname);
|
2011-06-06 03:06:43 +00:00
|
|
|
return (0);
|
2000-01-06 12:40:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
preferred_time = ntohl(pinfo->nd_opt_pi_preferred_time);
|
2011-06-06 03:06:43 +00:00
|
|
|
if (pfx->pfx_pltimeexpire) {
|
2001-06-11 12:39:29 +00:00
|
|
|
/*
|
|
|
|
* The lifetime is decremented in real time, so we should
|
|
|
|
* compare the expiration time.
|
|
|
|
* (RFC 2461 Section 6.2.7.)
|
|
|
|
* XXX: can we really expect that all routers on the link
|
|
|
|
* have synchronized clocks?
|
|
|
|
*/
|
2013-08-05 20:13:02 +00:00
|
|
|
clock_gettime(CLOCK_MONOTONIC_FAST, &now);
|
2001-06-11 12:39:29 +00:00
|
|
|
preferred_time += now.tv_sec;
|
|
|
|
|
2011-06-06 03:06:43 +00:00
|
|
|
if (!pfx->pfx_timer && rai->rai_clockskew &&
|
2014-11-22 23:04:33 +00:00
|
|
|
udiff(preferred_time, pfx->pfx_pltimeexpire) > rai->rai_clockskew) {
|
2001-06-11 12:39:29 +00:00
|
|
|
syslog(LOG_INFO,
|
2011-06-06 03:06:43 +00:00
|
|
|
"<%s> preferred lifetime for %s/%d"
|
|
|
|
" (decr. in real time) inconsistent on %s:"
|
2011-07-17 19:24:54 +00:00
|
|
|
" %" PRIu32 " from %s, %" PRIu32 " from us",
|
2011-06-06 03:06:43 +00:00
|
|
|
__func__,
|
|
|
|
inet_ntop(AF_INET6, &pinfo->nd_opt_pi_prefix, prefixbuf,
|
|
|
|
sizeof(prefixbuf)),
|
|
|
|
pinfo->nd_opt_pi_prefix_len,
|
2011-07-17 19:24:54 +00:00
|
|
|
ifi->ifi_ifname, preferred_time,
|
2011-06-06 03:06:43 +00:00
|
|
|
inet_ntop(AF_INET6, &from->sin6_addr, ntopbuf,
|
|
|
|
sizeof(ntopbuf)), pfx->pfx_pltimeexpire);
|
2001-06-11 12:39:29 +00:00
|
|
|
inconsistent++;
|
|
|
|
}
|
2011-06-06 03:06:43 +00:00
|
|
|
} else if (!pfx->pfx_timer && preferred_time != pfx->pfx_preflifetime)
|
2001-06-11 12:39:29 +00:00
|
|
|
syslog(LOG_INFO,
|
2011-06-06 03:06:43 +00:00
|
|
|
"<%s> preferred lifetime for %s/%d"
|
|
|
|
" inconsistent on %s:"
|
|
|
|
" %d from %s, %d from us",
|
|
|
|
__func__,
|
|
|
|
inet_ntop(AF_INET6, &pinfo->nd_opt_pi_prefix, prefixbuf,
|
|
|
|
sizeof(prefixbuf)),
|
|
|
|
pinfo->nd_opt_pi_prefix_len,
|
2011-07-17 19:24:54 +00:00
|
|
|
ifi->ifi_ifname, preferred_time,
|
2011-06-06 03:06:43 +00:00
|
|
|
inet_ntop(AF_INET6, &from->sin6_addr, ntopbuf,
|
|
|
|
sizeof(ntopbuf)), pfx->pfx_preflifetime);
|
2000-01-06 12:40:54 +00:00
|
|
|
|
|
|
|
valid_time = ntohl(pinfo->nd_opt_pi_valid_time);
|
2011-06-06 03:06:43 +00:00
|
|
|
if (pfx->pfx_vltimeexpire) {
|
2013-08-05 20:13:02 +00:00
|
|
|
clock_gettime(CLOCK_MONOTONIC_FAST, &now);
|
2001-06-11 12:39:29 +00:00
|
|
|
valid_time += now.tv_sec;
|
|
|
|
|
2011-06-06 03:06:43 +00:00
|
|
|
if (!pfx->pfx_timer && rai->rai_clockskew &&
|
2014-11-22 23:04:33 +00:00
|
|
|
udiff(valid_time, pfx->pfx_vltimeexpire) > rai->rai_clockskew) {
|
2001-06-11 12:39:29 +00:00
|
|
|
syslog(LOG_INFO,
|
2011-06-06 03:06:43 +00:00
|
|
|
"<%s> valid lifetime for %s/%d"
|
|
|
|
" (decr. in real time) inconsistent on %s:"
|
2011-07-17 19:24:54 +00:00
|
|
|
" %d from %s, %" PRIu32 " from us",
|
2011-06-06 03:06:43 +00:00
|
|
|
__func__,
|
|
|
|
inet_ntop(AF_INET6, &pinfo->nd_opt_pi_prefix, prefixbuf,
|
|
|
|
sizeof(prefixbuf)),
|
|
|
|
pinfo->nd_opt_pi_prefix_len,
|
2011-07-17 19:24:54 +00:00
|
|
|
ifi->ifi_ifname, preferred_time,
|
2011-06-06 03:06:43 +00:00
|
|
|
inet_ntop(AF_INET6, &from->sin6_addr, ntopbuf,
|
|
|
|
sizeof(ntopbuf)), pfx->pfx_vltimeexpire);
|
2001-06-11 12:39:29 +00:00
|
|
|
inconsistent++;
|
|
|
|
}
|
2011-06-06 03:06:43 +00:00
|
|
|
} else if (!pfx->pfx_timer && valid_time != pfx->pfx_validlifetime) {
|
2001-06-11 12:39:29 +00:00
|
|
|
syslog(LOG_INFO,
|
2011-06-06 03:06:43 +00:00
|
|
|
"<%s> valid lifetime for %s/%d"
|
|
|
|
" inconsistent on %s:"
|
|
|
|
" %d from %s, %d from us",
|
|
|
|
__func__,
|
|
|
|
inet_ntop(AF_INET6, &pinfo->nd_opt_pi_prefix, prefixbuf,
|
|
|
|
sizeof(prefixbuf)),
|
|
|
|
pinfo->nd_opt_pi_prefix_len,
|
2011-07-17 19:24:54 +00:00
|
|
|
ifi->ifi_ifname, valid_time,
|
2011-06-06 03:06:43 +00:00
|
|
|
inet_ntop(AF_INET6, &from->sin6_addr, ntopbuf,
|
|
|
|
sizeof(ntopbuf)), pfx->pfx_validlifetime);
|
2000-07-05 22:09:50 +00:00
|
|
|
inconsistent++;
|
|
|
|
}
|
|
|
|
|
2011-06-06 03:06:43 +00:00
|
|
|
return (inconsistent);
|
2000-01-06 12:40:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct prefix *
|
|
|
|
find_prefix(struct rainfo *rai, struct in6_addr *prefix, int plen)
|
|
|
|
{
|
2011-06-06 03:06:43 +00:00
|
|
|
struct prefix *pfx;
|
2000-01-06 12:40:54 +00:00
|
|
|
int bytelen, bitlen;
|
2011-07-17 19:24:54 +00:00
|
|
|
char bitmask;
|
2000-01-06 12:40:54 +00:00
|
|
|
|
2011-06-06 03:06:43 +00:00
|
|
|
TAILQ_FOREACH(pfx, &rai->rai_prefix, pfx_next) {
|
|
|
|
if (plen != pfx->pfx_prefixlen)
|
2000-01-06 12:40:54 +00:00
|
|
|
continue;
|
2011-06-06 03:06:43 +00:00
|
|
|
|
2000-01-06 12:40:54 +00:00
|
|
|
bytelen = plen / 8;
|
|
|
|
bitlen = plen % 8;
|
- supported a string notation for xxflags.
- deprecate routes#N, as it is hard to keep consistency with
rtprefixN. accept any number of "rtprefix", "rtrefix0",
..., "rtprefix99".
- deprecate "addrs#N", as it is difficult for users to keep
consistency with "addrN".
accept 100 prefix info in maximum - like "addr", "addr0"
... "addr99". WARNS=2 clean on netbsd.
old configuration file should work just fine.
behavior change:
previously, we rejected "addrN" if there's "addr", and we rejected
"addr" if there is "addrN". now we accept both without problem.
- when an advertised prefix configured from the kernel has been added
or invalidated, notice the change in a short delay.
- when invalidating a prefix, do not bark even if there is
inconsistency about prefix lifetimes.
- wrap more specific route info code into ROUTEINFO.
Obtained from: KAME
MFC after: 1 week
2003-08-15 19:13:53 +00:00
|
|
|
bitmask = 0xff << (8 - bitlen);
|
2011-06-06 03:06:43 +00:00
|
|
|
|
|
|
|
if (memcmp((void *)prefix, (void *)&pfx->pfx_prefix, bytelen))
|
2000-01-06 12:40:54 +00:00
|
|
|
continue;
|
2011-06-06 03:06:43 +00:00
|
|
|
|
- supported a string notation for xxflags.
- deprecate routes#N, as it is hard to keep consistency with
rtprefixN. accept any number of "rtprefix", "rtrefix0",
..., "rtprefix99".
- deprecate "addrs#N", as it is difficult for users to keep
consistency with "addrN".
accept 100 prefix info in maximum - like "addr", "addr0"
... "addr99". WARNS=2 clean on netbsd.
old configuration file should work just fine.
behavior change:
previously, we rejected "addrN" if there's "addr", and we rejected
"addr" if there is "addrN". now we accept both without problem.
- when an advertised prefix configured from the kernel has been added
or invalidated, notice the change in a short delay.
- when invalidating a prefix, do not bark even if there is
inconsistency about prefix lifetimes.
- wrap more specific route info code into ROUTEINFO.
Obtained from: KAME
MFC after: 1 week
2003-08-15 19:13:53 +00:00
|
|
|
if (bitlen == 0 ||
|
2011-06-06 03:06:43 +00:00
|
|
|
((prefix->s6_addr[bytelen] & bitmask) ==
|
|
|
|
(pfx->pfx_prefix.s6_addr[bytelen] & bitmask))) {
|
|
|
|
return (pfx);
|
- supported a string notation for xxflags.
- deprecate routes#N, as it is hard to keep consistency with
rtprefixN. accept any number of "rtprefix", "rtrefix0",
..., "rtprefix99".
- deprecate "addrs#N", as it is difficult for users to keep
consistency with "addrN".
accept 100 prefix info in maximum - like "addr", "addr0"
... "addr99". WARNS=2 clean on netbsd.
old configuration file should work just fine.
behavior change:
previously, we rejected "addrN" if there's "addr", and we rejected
"addr" if there is "addrN". now we accept both without problem.
- when an advertised prefix configured from the kernel has been added
or invalidated, notice the change in a short delay.
- when invalidating a prefix, do not bark even if there is
inconsistency about prefix lifetimes.
- wrap more specific route info code into ROUTEINFO.
Obtained from: KAME
MFC after: 1 week
2003-08-15 19:13:53 +00:00
|
|
|
}
|
2000-01-06 12:40:54 +00:00
|
|
|
}
|
|
|
|
|
2011-06-06 03:06:43 +00:00
|
|
|
return (NULL);
|
2000-01-06 12:40:54 +00:00
|
|
|
}
|
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
/* check if p0/plen0 matches p1/plen1; return 1 if matches, otherwise 0. */
|
|
|
|
int
|
|
|
|
prefix_match(struct in6_addr *p0, int plen0,
|
2011-06-06 03:06:43 +00:00
|
|
|
struct in6_addr *p1, int plen1)
|
2001-06-11 12:39:29 +00:00
|
|
|
{
|
|
|
|
int bytelen, bitlen;
|
2011-07-17 19:24:54 +00:00
|
|
|
char bitmask;
|
2001-06-11 12:39:29 +00:00
|
|
|
|
|
|
|
if (plen0 < plen1)
|
2011-06-06 03:06:43 +00:00
|
|
|
return (0);
|
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
bytelen = plen1 / 8;
|
|
|
|
bitlen = plen1 % 8;
|
- supported a string notation for xxflags.
- deprecate routes#N, as it is hard to keep consistency with
rtprefixN. accept any number of "rtprefix", "rtrefix0",
..., "rtprefix99".
- deprecate "addrs#N", as it is difficult for users to keep
consistency with "addrN".
accept 100 prefix info in maximum - like "addr", "addr0"
... "addr99". WARNS=2 clean on netbsd.
old configuration file should work just fine.
behavior change:
previously, we rejected "addrN" if there's "addr", and we rejected
"addr" if there is "addrN". now we accept both without problem.
- when an advertised prefix configured from the kernel has been added
or invalidated, notice the change in a short delay.
- when invalidating a prefix, do not bark even if there is
inconsistency about prefix lifetimes.
- wrap more specific route info code into ROUTEINFO.
Obtained from: KAME
MFC after: 1 week
2003-08-15 19:13:53 +00:00
|
|
|
bitmask = 0xff << (8 - bitlen);
|
2011-06-06 03:06:43 +00:00
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
if (memcmp((void *)p0, (void *)p1, bytelen))
|
2011-06-06 03:06:43 +00:00
|
|
|
return (0);
|
|
|
|
|
- supported a string notation for xxflags.
- deprecate routes#N, as it is hard to keep consistency with
rtprefixN. accept any number of "rtprefix", "rtrefix0",
..., "rtprefix99".
- deprecate "addrs#N", as it is difficult for users to keep
consistency with "addrN".
accept 100 prefix info in maximum - like "addr", "addr0"
... "addr99". WARNS=2 clean on netbsd.
old configuration file should work just fine.
behavior change:
previously, we rejected "addrN" if there's "addr", and we rejected
"addr" if there is "addrN". now we accept both without problem.
- when an advertised prefix configured from the kernel has been added
or invalidated, notice the change in a short delay.
- when invalidating a prefix, do not bark even if there is
inconsistency about prefix lifetimes.
- wrap more specific route info code into ROUTEINFO.
Obtained from: KAME
MFC after: 1 week
2003-08-15 19:13:53 +00:00
|
|
|
if (bitlen == 0 ||
|
|
|
|
((p0->s6_addr[bytelen] & bitmask) ==
|
|
|
|
(p1->s6_addr[bytelen] & bitmask))) {
|
2011-06-06 03:06:43 +00:00
|
|
|
return (1);
|
- supported a string notation for xxflags.
- deprecate routes#N, as it is hard to keep consistency with
rtprefixN. accept any number of "rtprefix", "rtrefix0",
..., "rtprefix99".
- deprecate "addrs#N", as it is difficult for users to keep
consistency with "addrN".
accept 100 prefix info in maximum - like "addr", "addr0"
... "addr99". WARNS=2 clean on netbsd.
old configuration file should work just fine.
behavior change:
previously, we rejected "addrN" if there's "addr", and we rejected
"addr" if there is "addrN". now we accept both without problem.
- when an advertised prefix configured from the kernel has been added
or invalidated, notice the change in a short delay.
- when invalidating a prefix, do not bark even if there is
inconsistency about prefix lifetimes.
- wrap more specific route info code into ROUTEINFO.
Obtained from: KAME
MFC after: 1 week
2003-08-15 19:13:53 +00:00
|
|
|
}
|
2001-06-11 12:39:29 +00:00
|
|
|
|
2011-06-06 03:06:43 +00:00
|
|
|
return (0);
|
2001-06-11 12:39:29 +00:00
|
|
|
}
|
|
|
|
|
2000-01-06 12:40:54 +00:00
|
|
|
static int
|
|
|
|
nd6_options(struct nd_opt_hdr *hdr, int limit,
|
2011-07-17 19:24:54 +00:00
|
|
|
union nd_opt *ndopts, uint32_t optflags)
|
2000-01-06 12:40:54 +00:00
|
|
|
{
|
|
|
|
int optlen = 0;
|
|
|
|
|
|
|
|
for (; limit > 0; limit -= optlen) {
|
2011-06-06 03:06:43 +00:00
|
|
|
if ((size_t)limit < sizeof(struct nd_opt_hdr)) {
|
2003-08-08 16:38:23 +00:00
|
|
|
syslog(LOG_INFO, "<%s> short option header", __func__);
|
2003-03-26 17:28:47 +00:00
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
2000-01-06 12:40:54 +00:00
|
|
|
hdr = (struct nd_opt_hdr *)((caddr_t)hdr + optlen);
|
|
|
|
if (hdr->nd_opt_len == 0) {
|
2003-03-26 17:28:47 +00:00
|
|
|
syslog(LOG_INFO,
|
2002-06-01 17:28:12 +00:00
|
|
|
"<%s> bad ND option length(0) (type = %d)",
|
2003-08-08 16:38:23 +00:00
|
|
|
__func__, hdr->nd_opt_type);
|
2000-01-06 12:40:54 +00:00
|
|
|
goto bad;
|
|
|
|
}
|
2003-03-26 17:28:47 +00:00
|
|
|
optlen = hdr->nd_opt_len << 3;
|
|
|
|
if (optlen > limit) {
|
2003-08-08 16:38:23 +00:00
|
|
|
syslog(LOG_INFO, "<%s> short option", __func__);
|
2003-03-26 17:28:47 +00:00
|
|
|
goto bad;
|
|
|
|
}
|
2000-01-06 12:40:54 +00:00
|
|
|
|
2011-06-06 03:06:43 +00:00
|
|
|
if (hdr->nd_opt_type > ND_OPT_MTU &&
|
|
|
|
hdr->nd_opt_type != ND_OPT_RDNSS &&
|
|
|
|
hdr->nd_opt_type != ND_OPT_DNSSL) {
|
2003-08-08 16:56:01 +00:00
|
|
|
syslog(LOG_INFO, "<%s> unknown ND option(type %d)",
|
2003-08-08 16:38:23 +00:00
|
|
|
__func__, hdr->nd_opt_type);
|
2000-01-06 12:40:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((ndopt_flags[hdr->nd_opt_type] & optflags) == 0) {
|
2003-08-08 16:56:01 +00:00
|
|
|
syslog(LOG_INFO, "<%s> unexpected ND option(type %d)",
|
|
|
|
__func__, hdr->nd_opt_type);
|
2000-01-06 12:40:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2003-03-26 17:28:47 +00:00
|
|
|
/*
|
|
|
|
* Option length check. Do it here for all fixed-length
|
|
|
|
* options.
|
|
|
|
*/
|
2011-06-06 03:06:43 +00:00
|
|
|
switch (hdr->nd_opt_type) {
|
|
|
|
case ND_OPT_MTU:
|
|
|
|
if (optlen == sizeof(struct nd_opt_mtu))
|
|
|
|
break;
|
|
|
|
goto skip;
|
|
|
|
case ND_OPT_RDNSS:
|
|
|
|
if (optlen >= 24 &&
|
|
|
|
(optlen - sizeof(struct nd_opt_rdnss)) % 16 == 0)
|
|
|
|
break;
|
|
|
|
goto skip;
|
|
|
|
case ND_OPT_DNSSL:
|
|
|
|
if (optlen >= 16 &&
|
|
|
|
(optlen - sizeof(struct nd_opt_dnssl)) % 8 == 0)
|
|
|
|
break;
|
|
|
|
goto skip;
|
|
|
|
case ND_OPT_PREFIX_INFORMATION:
|
|
|
|
if (optlen == sizeof(struct nd_opt_prefix_info))
|
|
|
|
break;
|
|
|
|
skip:
|
2003-03-26 17:28:47 +00:00
|
|
|
syslog(LOG_INFO, "<%s> invalid option length",
|
2003-08-08 16:38:23 +00:00
|
|
|
__func__);
|
2003-03-26 17:28:47 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2002-06-01 17:28:12 +00:00
|
|
|
switch (hdr->nd_opt_type) {
|
|
|
|
case ND_OPT_TARGET_LINKADDR:
|
|
|
|
case ND_OPT_REDIRECTED_HEADER:
|
2011-06-06 03:06:43 +00:00
|
|
|
case ND_OPT_RDNSS:
|
|
|
|
case ND_OPT_DNSSL:
|
2003-03-26 17:28:47 +00:00
|
|
|
break; /* we don't care about these options */
|
2005-10-19 15:14:28 +00:00
|
|
|
case ND_OPT_SOURCE_LINKADDR:
|
2002-06-01 17:28:12 +00:00
|
|
|
case ND_OPT_MTU:
|
2011-06-06 03:06:43 +00:00
|
|
|
if (ndopts->opt_array[hdr->nd_opt_type]) {
|
2002-06-01 17:28:12 +00:00
|
|
|
syslog(LOG_INFO,
|
|
|
|
"<%s> duplicated ND option (type = %d)",
|
2003-08-08 16:38:23 +00:00
|
|
|
__func__, hdr->nd_opt_type);
|
2002-06-01 17:28:12 +00:00
|
|
|
}
|
2011-06-06 03:06:43 +00:00
|
|
|
ndopts->opt_array[hdr->nd_opt_type] = hdr;
|
2002-06-01 17:28:12 +00:00
|
|
|
break;
|
|
|
|
case ND_OPT_PREFIX_INFORMATION:
|
|
|
|
{
|
2011-06-06 03:06:43 +00:00
|
|
|
struct nd_optlist *nol;
|
2002-06-01 17:28:12 +00:00
|
|
|
|
2011-06-06 03:06:43 +00:00
|
|
|
if (ndopts->opt_pi == 0) {
|
|
|
|
ndopts->opt_pi =
|
2002-06-01 17:28:12 +00:00
|
|
|
(struct nd_opt_prefix_info *)hdr;
|
|
|
|
continue;
|
|
|
|
}
|
2011-06-06 03:06:43 +00:00
|
|
|
nol = malloc(sizeof(*nol));
|
|
|
|
if (nol == NULL) {
|
2002-06-01 17:28:12 +00:00
|
|
|
syslog(LOG_ERR, "<%s> can't allocate memory",
|
2003-08-08 16:38:23 +00:00
|
|
|
__func__);
|
2002-06-01 17:28:12 +00:00
|
|
|
goto bad;
|
|
|
|
}
|
2011-06-06 03:06:43 +00:00
|
|
|
nol->nol_opt = hdr;
|
|
|
|
TAILQ_INSERT_TAIL(&(ndopts->opt_list), nol, nol_next);
|
2002-06-01 17:28:12 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: /* impossible */
|
|
|
|
break;
|
2000-01-06 12:40:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-06 03:06:43 +00:00
|
|
|
return (0);
|
2000-01-06 12:40:54 +00:00
|
|
|
|
|
|
|
bad:
|
|
|
|
free_ndopts(ndopts);
|
|
|
|
|
2011-06-06 03:06:43 +00:00
|
|
|
return (-1);
|
2000-01-06 12:40:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-06-06 03:06:43 +00:00
|
|
|
free_ndopts(union nd_opt *ndopts)
|
2000-01-06 12:40:54 +00:00
|
|
|
{
|
2011-06-06 03:06:43 +00:00
|
|
|
struct nd_optlist *nol;
|
2000-01-06 12:40:54 +00:00
|
|
|
|
2011-06-06 03:06:43 +00:00
|
|
|
while ((nol = TAILQ_FIRST(&ndopts->opt_list)) != NULL) {
|
|
|
|
TAILQ_REMOVE(&ndopts->opt_list, nol, nol_next);
|
|
|
|
free(nol);
|
2000-01-06 12:40:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-07-17 19:24:54 +00:00
|
|
|
sock_open(struct sockinfo *s)
|
2000-01-06 12:40:54 +00:00
|
|
|
{
|
|
|
|
struct icmp6_filter filt;
|
|
|
|
int on;
|
|
|
|
/* XXX: should be max MTU attached to the node */
|
2011-07-17 19:24:54 +00:00
|
|
|
static char answer[1500];
|
2000-01-06 12:40:54 +00:00
|
|
|
|
2011-07-17 19:24:54 +00:00
|
|
|
syslog(LOG_DEBUG, "<%s> enter", __func__);
|
|
|
|
|
|
|
|
if (s == NULL) {
|
|
|
|
syslog(LOG_ERR, "<%s> internal error", __func__);
|
|
|
|
exit(1);
|
|
|
|
}
|
2000-07-05 22:09:50 +00:00
|
|
|
rcvcmsgbuflen = CMSG_SPACE(sizeof(struct in6_pktinfo)) +
|
2011-06-06 03:06:43 +00:00
|
|
|
CMSG_SPACE(sizeof(int));
|
2011-07-17 19:24:54 +00:00
|
|
|
rcvcmsgbuf = (char *)malloc(rcvcmsgbuflen);
|
2000-07-05 22:09:50 +00:00
|
|
|
if (rcvcmsgbuf == NULL) {
|
2003-08-08 16:38:23 +00:00
|
|
|
syslog(LOG_ERR, "<%s> not enough core", __func__);
|
2000-07-05 22:09:50 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2011-06-06 03:06:43 +00:00
|
|
|
sndcmsgbuflen = CMSG_SPACE(sizeof(struct in6_pktinfo)) +
|
|
|
|
CMSG_SPACE(sizeof(int));
|
2011-07-17 19:24:54 +00:00
|
|
|
sndcmsgbuf = (char *)malloc(sndcmsgbuflen);
|
2000-07-05 22:09:50 +00:00
|
|
|
if (sndcmsgbuf == NULL) {
|
2003-08-08 16:38:23 +00:00
|
|
|
syslog(LOG_ERR, "<%s> not enough core", __func__);
|
2000-07-05 22:09:50 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2011-07-17 19:24:54 +00:00
|
|
|
if ((s->si_fd = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6)) < 0) {
|
2011-06-06 03:06:43 +00:00
|
|
|
syslog(LOG_ERR, "<%s> socket: %s", __func__, strerror(errno));
|
2000-01-06 12:40:54 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
/* specify to tell receiving interface */
|
|
|
|
on = 1;
|
2011-07-17 19:24:54 +00:00
|
|
|
if (setsockopt(s->si_fd, IPPROTO_IPV6, IPV6_RECVPKTINFO, &on,
|
2011-06-06 03:06:43 +00:00
|
|
|
sizeof(on)) < 0) {
|
|
|
|
syslog(LOG_ERR, "<%s> IPV6_RECVPKTINFO: %s", __func__,
|
|
|
|
strerror(errno));
|
2000-07-05 22:09:50 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2000-01-06 12:40:54 +00:00
|
|
|
on = 1;
|
|
|
|
/* specify to tell value of hoplimit field of received IP6 hdr */
|
2011-07-17 19:24:54 +00:00
|
|
|
if (setsockopt(s->si_fd, IPPROTO_IPV6, IPV6_RECVHOPLIMIT, &on,
|
2011-06-06 03:06:43 +00:00
|
|
|
sizeof(on)) < 0) {
|
|
|
|
syslog(LOG_ERR, "<%s> IPV6_RECVHOPLIMIT: %s", __func__,
|
|
|
|
strerror(errno));
|
2000-07-05 22:09:50 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2000-01-06 12:40:54 +00:00
|
|
|
ICMP6_FILTER_SETBLOCKALL(&filt);
|
2000-07-05 22:09:50 +00:00
|
|
|
ICMP6_FILTER_SETPASS(ND_ROUTER_SOLICIT, &filt);
|
|
|
|
ICMP6_FILTER_SETPASS(ND_ROUTER_ADVERT, &filt);
|
2011-07-17 19:24:54 +00:00
|
|
|
if (mcastif != NULL)
|
2000-01-06 12:40:54 +00:00
|
|
|
ICMP6_FILTER_SETPASS(ICMP6_ROUTER_RENUMBERING, &filt);
|
2011-06-06 03:06:43 +00:00
|
|
|
|
2011-07-17 19:24:54 +00:00
|
|
|
if (setsockopt(s->si_fd, IPPROTO_ICMPV6, ICMP6_FILTER, &filt,
|
2011-06-06 03:06:43 +00:00
|
|
|
sizeof(filt)) < 0) {
|
2000-01-06 12:40:54 +00:00
|
|
|
syslog(LOG_ERR, "<%s> IICMP6_FILTER: %s",
|
2011-06-06 03:06:43 +00:00
|
|
|
__func__, strerror(errno));
|
2000-01-06 12:40:54 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* initialize msghdr for receiving packets */
|
|
|
|
rcviov[0].iov_base = (caddr_t)answer;
|
|
|
|
rcviov[0].iov_len = sizeof(answer);
|
2003-08-14 16:51:13 +00:00
|
|
|
rcvmhdr.msg_name = (caddr_t)&rcvfrom;
|
|
|
|
rcvmhdr.msg_namelen = sizeof(rcvfrom);
|
2000-01-06 12:40:54 +00:00
|
|
|
rcvmhdr.msg_iov = rcviov;
|
|
|
|
rcvmhdr.msg_iovlen = 1;
|
|
|
|
rcvmhdr.msg_control = (caddr_t) rcvcmsgbuf;
|
2000-07-05 22:09:50 +00:00
|
|
|
rcvmhdr.msg_controllen = rcvcmsgbuflen;
|
2000-01-06 12:40:54 +00:00
|
|
|
|
|
|
|
/* initialize msghdr for sending packets */
|
|
|
|
sndmhdr.msg_namelen = sizeof(struct sockaddr_in6);
|
|
|
|
sndmhdr.msg_iov = sndiov;
|
|
|
|
sndmhdr.msg_iovlen = 1;
|
|
|
|
sndmhdr.msg_control = (caddr_t)sndcmsgbuf;
|
2000-07-05 22:09:50 +00:00
|
|
|
sndmhdr.msg_controllen = sndcmsgbuflen;
|
2011-06-06 03:06:43 +00:00
|
|
|
|
2000-01-06 12:40:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* open a routing socket to watch the routing table */
|
|
|
|
static void
|
2011-07-17 19:24:54 +00:00
|
|
|
rtsock_open(struct sockinfo *s)
|
2000-01-06 12:40:54 +00:00
|
|
|
{
|
2011-07-17 19:24:54 +00:00
|
|
|
if (s == NULL) {
|
|
|
|
syslog(LOG_ERR, "<%s> internal error", __func__);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if ((s->si_fd = socket(PF_ROUTE, SOCK_RAW, 0)) < 0) {
|
2000-01-06 12:40:54 +00:00
|
|
|
syslog(LOG_ERR,
|
2011-06-06 03:06:43 +00:00
|
|
|
"<%s> socket: %s", __func__, strerror(errno));
|
2000-01-06 12:40:54 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-17 19:24:54 +00:00
|
|
|
struct ifinfo *
|
|
|
|
if_indextoifinfo(int idx)
|
2000-01-06 12:40:54 +00:00
|
|
|
{
|
2011-07-17 19:24:54 +00:00
|
|
|
struct ifinfo *ifi;
|
2013-07-09 07:08:36 +00:00
|
|
|
char *name, name0[IFNAMSIZ];
|
|
|
|
|
|
|
|
/* Check if the interface has a valid name or not. */
|
|
|
|
if (if_indextoname(idx, name0) == NULL)
|
|
|
|
return (NULL);
|
2000-01-06 12:40:54 +00:00
|
|
|
|
2011-07-17 19:24:54 +00:00
|
|
|
TAILQ_FOREACH(ifi, &ifilist, ifi_next) {
|
|
|
|
if (ifi->ifi_ifindex == idx)
|
|
|
|
return (ifi);
|
2000-01-06 12:40:54 +00:00
|
|
|
}
|
|
|
|
|
2011-07-17 19:24:54 +00:00
|
|
|
if (ifi != NULL)
|
|
|
|
syslog(LOG_DEBUG, "<%s> ifi found (idx=%d)",
|
|
|
|
__func__, idx);
|
|
|
|
else
|
|
|
|
syslog(LOG_DEBUG, "<%s> ifi not found (idx=%d)",
|
|
|
|
__func__, idx);
|
|
|
|
|
2011-06-06 03:06:43 +00:00
|
|
|
return (NULL); /* search failed */
|
2000-01-06 12:40:54 +00:00
|
|
|
}
|
|
|
|
|
2011-06-11 03:25:10 +00:00
|
|
|
void
|
2011-07-17 19:24:54 +00:00
|
|
|
ra_output(struct ifinfo *ifi)
|
2000-01-06 12:40:54 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct cmsghdr *cm;
|
|
|
|
struct in6_pktinfo *pi;
|
2011-06-06 03:06:43 +00:00
|
|
|
struct soliciter *sol;
|
2011-07-17 19:24:54 +00:00
|
|
|
struct rainfo *rai;
|
2000-07-05 22:09:50 +00:00
|
|
|
|
2011-07-17 19:24:54 +00:00
|
|
|
switch (ifi->ifi_state) {
|
|
|
|
case IFI_STATE_CONFIGURED:
|
|
|
|
rai = ifi->ifi_rainfo;
|
|
|
|
break;
|
|
|
|
case IFI_STATE_TRANSITIVE:
|
|
|
|
rai = ifi->ifi_rainfo_trans;
|
|
|
|
break;
|
|
|
|
case IFI_STATE_UNCONFIGURED:
|
|
|
|
syslog(LOG_DEBUG, "<%s> %s is unconfigured. "
|
|
|
|
"Skip sending RAs.",
|
|
|
|
__func__, ifi->ifi_ifname);
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
rai = NULL;
|
|
|
|
}
|
|
|
|
if (rai == NULL) {
|
|
|
|
syslog(LOG_DEBUG, "<%s> rainfo is NULL on %s."
|
|
|
|
"Skip sending RAs.",
|
|
|
|
__func__, ifi->ifi_ifname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!(ifi->ifi_flags & IFF_UP)) {
|
|
|
|
syslog(LOG_DEBUG, "<%s> %s is not up. "
|
|
|
|
"Skip sending RAs.",
|
|
|
|
__func__, ifi->ifi_ifname);
|
2000-07-05 22:09:50 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-06-06 03:06:43 +00:00
|
|
|
/*
|
|
|
|
* Check lifetime, ACCEPT_RTADV flag, and ip6.forwarding.
|
|
|
|
*
|
|
|
|
* (lifetime == 0) = output
|
2011-07-17 19:24:54 +00:00
|
|
|
* (lifetime != 0 && (check_accept_rtadv()) = no output
|
2011-06-06 03:06:43 +00:00
|
|
|
*
|
|
|
|
* Basically, hosts MUST NOT send Router Advertisement
|
|
|
|
* messages at any time (RFC 4861, Section 6.2.3). However, it
|
|
|
|
* would sometimes be useful to allow hosts to advertise some
|
|
|
|
* parameters such as prefix information and link MTU. Thus,
|
|
|
|
* we allow hosts to invoke rtadvd only when router lifetime
|
|
|
|
* (on every advertising interface) is explicitly set
|
|
|
|
* zero. (see also the above section)
|
|
|
|
*/
|
|
|
|
syslog(LOG_DEBUG,
|
2011-07-17 19:24:54 +00:00
|
|
|
"<%s> check lifetime=%d, ACCEPT_RTADV=%d, ip6.forwarding=%d "
|
|
|
|
"on %s", __func__,
|
|
|
|
rai->rai_lifetime,
|
|
|
|
check_accept_rtadv(ifi->ifi_ifindex),
|
|
|
|
getinet6sysctl(IPV6CTL_FORWARDING),
|
|
|
|
ifi->ifi_ifname);
|
|
|
|
|
2011-06-06 03:06:43 +00:00
|
|
|
if (rai->rai_lifetime != 0) {
|
|
|
|
if (getinet6sysctl(IPV6CTL_FORWARDING) == 0) {
|
2011-09-12 23:52:55 +00:00
|
|
|
syslog(LOG_ERR,
|
|
|
|
"non-zero lifetime RA "
|
2011-06-06 03:06:43 +00:00
|
|
|
"but net.inet6.ip6.forwarding=0. "
|
2011-09-12 23:52:55 +00:00
|
|
|
"Ignored.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (check_accept_rtadv(ifi->ifi_ifindex)) {
|
|
|
|
syslog(LOG_ERR,
|
|
|
|
"non-zero lifetime RA "
|
|
|
|
"on RA receiving interface %s."
|
|
|
|
" Ignored.", ifi->ifi_ifname);
|
2011-06-06 03:06:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
make_packet(rai); /* XXX: inefficient */
|
2001-06-11 12:39:29 +00:00
|
|
|
|
2011-06-06 03:06:43 +00:00
|
|
|
sndmhdr.msg_name = (caddr_t)&sin6_linklocal_allnodes;
|
|
|
|
sndmhdr.msg_iov[0].iov_base = (caddr_t)rai->rai_ra_data;
|
|
|
|
sndmhdr.msg_iov[0].iov_len = rai->rai_ra_datalen;
|
2000-01-06 12:40:54 +00:00
|
|
|
|
|
|
|
cm = CMSG_FIRSTHDR(&sndmhdr);
|
|
|
|
/* specify the outgoing interface */
|
|
|
|
cm->cmsg_level = IPPROTO_IPV6;
|
|
|
|
cm->cmsg_type = IPV6_PKTINFO;
|
|
|
|
cm->cmsg_len = CMSG_LEN(sizeof(struct in6_pktinfo));
|
|
|
|
pi = (struct in6_pktinfo *)CMSG_DATA(cm);
|
|
|
|
memset(&pi->ipi6_addr, 0, sizeof(pi->ipi6_addr)); /*XXX*/
|
2011-07-17 19:24:54 +00:00
|
|
|
pi->ipi6_ifindex = ifi->ifi_ifindex;
|
2000-01-06 12:40:54 +00:00
|
|
|
|
|
|
|
/* specify the hop limit of the packet */
|
|
|
|
{
|
|
|
|
int hoplimit = 255;
|
|
|
|
|
|
|
|
cm = CMSG_NXTHDR(&sndmhdr, cm);
|
|
|
|
cm->cmsg_level = IPPROTO_IPV6;
|
|
|
|
cm->cmsg_type = IPV6_HOPLIMIT;
|
|
|
|
cm->cmsg_len = CMSG_LEN(sizeof(int));
|
|
|
|
memcpy(CMSG_DATA(cm), &hoplimit, sizeof(int));
|
|
|
|
}
|
|
|
|
|
|
|
|
syslog(LOG_DEBUG,
|
2011-07-17 19:24:54 +00:00
|
|
|
"<%s> send RA on %s, # of RS waitings = %d",
|
|
|
|
__func__, ifi->ifi_ifname, ifi->ifi_rs_waitcount);
|
2000-01-06 12:40:54 +00:00
|
|
|
|
2011-07-17 19:24:54 +00:00
|
|
|
i = sendmsg(sock.si_fd, &sndmhdr, 0);
|
2000-01-06 12:40:54 +00:00
|
|
|
|
2011-06-06 03:06:43 +00:00
|
|
|
if (i < 0 || (size_t)i != rai->rai_ra_datalen) {
|
2000-01-06 12:40:54 +00:00
|
|
|
if (i < 0) {
|
2000-07-05 22:09:50 +00:00
|
|
|
syslog(LOG_ERR, "<%s> sendmsg on %s: %s",
|
2011-07-17 19:24:54 +00:00
|
|
|
__func__, ifi->ifi_ifname,
|
2011-06-06 03:06:43 +00:00
|
|
|
strerror(errno));
|
2000-07-05 22:09:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* unicast advertisements
|
|
|
|
* XXX commented out. reason: though spec does not forbit it, unicast
|
|
|
|
* advert does not really help
|
|
|
|
*/
|
2011-06-06 03:06:43 +00:00
|
|
|
while ((sol = TAILQ_FIRST(&rai->rai_soliciter)) != NULL) {
|
|
|
|
TAILQ_REMOVE(&rai->rai_soliciter, sol, sol_next);
|
2000-07-05 22:09:50 +00:00
|
|
|
free(sol);
|
2000-01-06 12:40:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* update timestamp */
|
2013-08-05 20:13:02 +00:00
|
|
|
clock_gettime(CLOCK_MONOTONIC_FAST, &ifi->ifi_ra_lastsent);
|
2011-07-17 19:24:54 +00:00
|
|
|
|
|
|
|
/* update counter */
|
|
|
|
ifi->ifi_rs_waitcount = 0;
|
|
|
|
ifi->ifi_raoutput++;
|
|
|
|
|
|
|
|
switch (ifi->ifi_state) {
|
|
|
|
case IFI_STATE_CONFIGURED:
|
|
|
|
if (ifi->ifi_burstcount > 0)
|
|
|
|
ifi->ifi_burstcount--;
|
|
|
|
break;
|
|
|
|
case IFI_STATE_TRANSITIVE:
|
|
|
|
ifi->ifi_burstcount--;
|
|
|
|
if (ifi->ifi_burstcount == 0) {
|
|
|
|
if (ifi->ifi_rainfo == ifi->ifi_rainfo_trans) {
|
2011-12-30 10:58:14 +00:00
|
|
|
/* Initial burst finished. */
|
2011-07-17 19:24:54 +00:00
|
|
|
if (ifi->ifi_rainfo_trans != NULL)
|
|
|
|
ifi->ifi_rainfo_trans = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove burst RA information */
|
|
|
|
if (ifi->ifi_rainfo_trans != NULL) {
|
|
|
|
rm_rainfo(ifi->ifi_rainfo_trans);
|
|
|
|
ifi->ifi_rainfo_trans = NULL;
|
|
|
|
}
|
2000-01-06 12:40:54 +00:00
|
|
|
|
2011-07-17 19:24:54 +00:00
|
|
|
if (ifi->ifi_rainfo != NULL) {
|
|
|
|
/*
|
|
|
|
* TRANSITIVE -> CONFIGURED
|
|
|
|
*
|
|
|
|
* After initial burst or transition from
|
|
|
|
* one configuration to another,
|
|
|
|
* ifi_rainfo always points to the next RA
|
|
|
|
* information.
|
|
|
|
*/
|
|
|
|
ifi->ifi_state = IFI_STATE_CONFIGURED;
|
|
|
|
syslog(LOG_DEBUG,
|
|
|
|
"<%s> ifname=%s marked as "
|
|
|
|
"CONFIGURED.", __func__,
|
|
|
|
ifi->ifi_ifname);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* TRANSITIVE -> UNCONFIGURED
|
|
|
|
*
|
|
|
|
* If ifi_rainfo points to NULL, this
|
|
|
|
* interface is shutting down.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
int error;
|
|
|
|
|
|
|
|
ifi->ifi_state = IFI_STATE_UNCONFIGURED;
|
|
|
|
syslog(LOG_DEBUG,
|
|
|
|
"<%s> ifname=%s marked as "
|
|
|
|
"UNCONFIGURED.", __func__,
|
|
|
|
ifi->ifi_ifname);
|
|
|
|
error = sock_mc_leave(&sock,
|
|
|
|
ifi->ifi_ifindex);
|
|
|
|
if (error)
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2000-01-06 12:40:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* process RA timer */
|
2002-06-13 16:59:31 +00:00
|
|
|
struct rtadvd_timer *
|
2011-06-06 03:06:43 +00:00
|
|
|
ra_timeout(void *arg)
|
2000-01-06 12:40:54 +00:00
|
|
|
{
|
2011-07-17 19:24:54 +00:00
|
|
|
struct ifinfo *ifi;
|
2000-01-06 12:40:54 +00:00
|
|
|
|
2011-07-17 19:24:54 +00:00
|
|
|
ifi = (struct ifinfo *)arg;
|
2011-06-06 03:06:43 +00:00
|
|
|
syslog(LOG_DEBUG, "<%s> RA timer on %s is expired",
|
2011-07-17 19:24:54 +00:00
|
|
|
__func__, ifi->ifi_ifname);
|
2000-01-06 12:40:54 +00:00
|
|
|
|
2011-07-17 19:24:54 +00:00
|
|
|
ra_output(ifi);
|
2002-06-13 16:59:31 +00:00
|
|
|
|
2011-07-17 19:24:54 +00:00
|
|
|
return (ifi->ifi_ra_timer);
|
2000-01-06 12:40:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* update RA timer */
|
|
|
|
void
|
2013-08-05 20:13:02 +00:00
|
|
|
ra_timer_update(void *arg, struct timespec *tm)
|
2000-01-06 12:40:54 +00:00
|
|
|
{
|
2011-07-17 19:24:54 +00:00
|
|
|
uint16_t interval;
|
2011-06-06 03:06:43 +00:00
|
|
|
struct rainfo *rai;
|
2011-07-17 19:24:54 +00:00
|
|
|
struct ifinfo *ifi;
|
2000-01-06 12:40:54 +00:00
|
|
|
|
2011-07-17 19:24:54 +00:00
|
|
|
ifi = (struct ifinfo *)arg;
|
|
|
|
rai = ifi->ifi_rainfo;
|
|
|
|
interval = 0;
|
|
|
|
|
|
|
|
switch (ifi->ifi_state) {
|
|
|
|
case IFI_STATE_UNCONFIGURED:
|
|
|
|
return;
|
|
|
|
break;
|
|
|
|
case IFI_STATE_CONFIGURED:
|
|
|
|
/*
|
|
|
|
* Whenever a multicast advertisement is sent from
|
|
|
|
* an interface, the timer is reset to a
|
|
|
|
* uniformly-distributed random value between the
|
|
|
|
* interface's configured MinRtrAdvInterval and
|
|
|
|
* MaxRtrAdvInterval (RFC4861 6.2.4).
|
|
|
|
*/
|
|
|
|
interval = rai->rai_mininterval;
|
|
|
|
interval += arc4random_uniform(rai->rai_maxinterval -
|
|
|
|
rai->rai_mininterval);
|
|
|
|
break;
|
|
|
|
case IFI_STATE_TRANSITIVE:
|
|
|
|
/*
|
|
|
|
* For the first few advertisements (up to
|
|
|
|
* MAX_INITIAL_RTR_ADVERTISEMENTS), if the randomly chosen
|
|
|
|
* interval is greater than
|
|
|
|
* MAX_INITIAL_RTR_ADVERT_INTERVAL, the timer SHOULD be
|
|
|
|
* set to MAX_INITIAL_RTR_ADVERT_INTERVAL instead. (RFC
|
|
|
|
* 4861 6.2.4)
|
|
|
|
*
|
|
|
|
* In such cases, the router SHOULD transmit one or more
|
|
|
|
* (but not more than MAX_FINAL_RTR_ADVERTISEMENTS) final
|
|
|
|
* multicast Router Advertisements on the interface with a
|
|
|
|
* Router Lifetime field of zero. (RFC 4861 6.2.5)
|
|
|
|
*/
|
|
|
|
interval = ifi->ifi_burstinterval;
|
|
|
|
break;
|
|
|
|
}
|
2000-01-06 12:40:54 +00:00
|
|
|
|
|
|
|
tm->tv_sec = interval;
|
2013-08-05 20:13:02 +00:00
|
|
|
tm->tv_nsec = 0;
|
2000-01-06 12:40:54 +00:00
|
|
|
|
|
|
|
syslog(LOG_DEBUG,
|
2011-06-06 03:06:43 +00:00
|
|
|
"<%s> RA timer on %s is set to %ld:%ld",
|
2011-07-17 19:24:54 +00:00
|
|
|
__func__, ifi->ifi_ifname,
|
2013-08-05 20:13:02 +00:00
|
|
|
(long int)tm->tv_sec, (long int)tm->tv_nsec / 1000);
|
2000-01-06 12:40:54 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|