2004-01-14 17:16:19 +00:00
|
|
|
/* $KAME: rtsol.c,v 1.27 2003/10/05 00:09:36 itojun Exp $ */
|
2000-10-06 23:46:52 +00:00
|
|
|
|
1999-12-28 02:37:14 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
|
|
|
|
* All rights reserved.
|
2000-07-05 10:14:11 +00:00
|
|
|
*
|
1999-12-28 02:37:14 +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.
|
2000-07-05 10:14:11 +00:00
|
|
|
*
|
1999-12-28 02:37:14 +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.
|
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/uio.h>
|
|
|
|
#include <sys/time.h>
|
2000-10-06 23:46:52 +00:00
|
|
|
#include <sys/queue.h>
|
2003-08-08 16:42:37 +00:00
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <sys/stat.h>
|
1999-12-28 02:37:14 +00:00
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/route.h>
|
|
|
|
#include <net/if_dl.h>
|
|
|
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/ip6.h>
|
|
|
|
#include <netinet6/ip6_var.h>
|
|
|
|
#include <netinet/icmp6.h>
|
|
|
|
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
|
|
|
#include <time.h>
|
2003-08-17 11:11:32 +00:00
|
|
|
#include <fcntl.h>
|
1999-12-28 02:37:14 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <syslog.h>
|
|
|
|
#include "rtsold.h"
|
|
|
|
|
2000-07-05 10:14:11 +00:00
|
|
|
#define ALLROUTER "ff02::2"
|
1999-12-28 02:37:14 +00:00
|
|
|
|
|
|
|
static struct msghdr rcvmhdr;
|
|
|
|
static struct msghdr sndmhdr;
|
|
|
|
static struct iovec rcviov[2];
|
|
|
|
static struct iovec sndiov[2];
|
|
|
|
static struct sockaddr_in6 from;
|
2003-08-17 11:11:32 +00:00
|
|
|
static int rcvcmsglen;
|
1999-12-28 02:37:14 +00:00
|
|
|
|
2000-07-05 10:14:11 +00:00
|
|
|
int rssock;
|
1999-12-28 02:37:14 +00:00
|
|
|
|
2003-08-08 16:56:01 +00:00
|
|
|
static struct sockaddr_in6 sin6_allrouters =
|
|
|
|
{sizeof(sin6_allrouters), AF_INET6};
|
1999-12-28 02:37:14 +00:00
|
|
|
|
2003-08-08 16:42:37 +00:00
|
|
|
static void call_script __P((char *, char *));
|
|
|
|
static int safefile __P((const char *));
|
|
|
|
|
1999-12-28 02:37:14 +00:00
|
|
|
int
|
2004-01-14 17:16:19 +00:00
|
|
|
sockopen(void)
|
1999-12-28 02:37:14 +00:00
|
|
|
{
|
2000-07-05 10:14:11 +00:00
|
|
|
static u_char *rcvcmsgbuf = NULL, *sndcmsgbuf = NULL;
|
2003-08-17 11:11:32 +00:00
|
|
|
int sndcmsglen, on;
|
|
|
|
static u_char answer[1500];
|
|
|
|
struct icmp6_filter filt;
|
2000-07-05 10:14:11 +00:00
|
|
|
|
|
|
|
sndcmsglen = rcvcmsglen = CMSG_SPACE(sizeof(struct in6_pktinfo)) +
|
2003-08-08 16:56:01 +00:00
|
|
|
CMSG_SPACE(sizeof(int));
|
2000-07-05 10:14:11 +00:00
|
|
|
if (rcvcmsgbuf == NULL && (rcvcmsgbuf = malloc(rcvcmsglen)) == NULL) {
|
2003-08-08 16:38:23 +00:00
|
|
|
warnmsg(LOG_ERR, __func__,
|
2003-08-08 16:56:01 +00:00
|
|
|
"malloc for receive msghdr failed");
|
2000-07-05 10:14:11 +00:00
|
|
|
return(-1);
|
|
|
|
}
|
2003-08-08 16:56:01 +00:00
|
|
|
if (sndcmsgbuf == NULL && (sndcmsgbuf = malloc(sndcmsglen)) == NULL) {
|
2003-08-08 16:38:23 +00:00
|
|
|
warnmsg(LOG_ERR, __func__,
|
2003-08-08 16:56:01 +00:00
|
|
|
"malloc for send msghdr failed");
|
2000-07-05 10:14:11 +00:00
|
|
|
return(-1);
|
|
|
|
}
|
1999-12-28 02:37:14 +00:00
|
|
|
memset(&sin6_allrouters, 0, sizeof(struct sockaddr_in6));
|
2002-04-19 11:39:54 +00:00
|
|
|
sin6_allrouters.sin6_family = AF_INET6;
|
|
|
|
sin6_allrouters.sin6_len = sizeof(sin6_allrouters);
|
1999-12-28 02:37:14 +00:00
|
|
|
if (inet_pton(AF_INET6, ALLROUTER,
|
2003-08-08 16:56:01 +00:00
|
|
|
&sin6_allrouters.sin6_addr.s6_addr) != 1) {
|
2003-08-08 16:38:23 +00:00
|
|
|
warnmsg(LOG_ERR, __func__, "inet_pton failed for %s",
|
2003-08-08 16:56:01 +00:00
|
|
|
ALLROUTER);
|
1999-12-28 02:37:14 +00:00
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((rssock = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6)) < 0) {
|
2003-08-08 16:38:23 +00:00
|
|
|
warnmsg(LOG_ERR, __func__, "socket: %s", strerror(errno));
|
1999-12-28 02:37:14 +00:00
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* specify to tell receiving interface */
|
|
|
|
on = 1;
|
2000-07-05 10:14:11 +00:00
|
|
|
#ifdef IPV6_RECVPKTINFO
|
|
|
|
if (setsockopt(rssock, IPPROTO_IPV6, IPV6_RECVPKTINFO, &on,
|
2003-08-08 16:56:01 +00:00
|
|
|
sizeof(on)) < 0) {
|
2003-08-08 16:38:23 +00:00
|
|
|
warnmsg(LOG_ERR, __func__, "IPV6_RECVPKTINFO: %s",
|
2003-08-08 16:56:01 +00:00
|
|
|
strerror(errno));
|
2000-07-05 10:14:11 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
#else /* old adv. API */
|
1999-12-28 02:37:14 +00:00
|
|
|
if (setsockopt(rssock, IPPROTO_IPV6, IPV6_PKTINFO, &on,
|
2003-08-08 16:56:01 +00:00
|
|
|
sizeof(on)) < 0) {
|
2003-08-08 16:38:23 +00:00
|
|
|
warnmsg(LOG_ERR, __func__, "IPV6_PKTINFO: %s",
|
2003-08-08 16:56:01 +00:00
|
|
|
strerror(errno));
|
1999-12-28 02:37:14 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2003-08-08 16:56:01 +00:00
|
|
|
#endif
|
1999-12-28 02:37:14 +00:00
|
|
|
|
|
|
|
on = 1;
|
|
|
|
/* specify to tell value of hoplimit field of received IP6 hdr */
|
2000-07-05 10:14:11 +00:00
|
|
|
#ifdef IPV6_RECVHOPLIMIT
|
|
|
|
if (setsockopt(rssock, IPPROTO_IPV6, IPV6_RECVHOPLIMIT, &on,
|
2003-08-08 16:56:01 +00:00
|
|
|
sizeof(on)) < 0) {
|
2003-08-08 16:38:23 +00:00
|
|
|
warnmsg(LOG_ERR, __func__, "IPV6_RECVHOPLIMIT: %s",
|
2003-08-08 16:56:01 +00:00
|
|
|
strerror(errno));
|
2000-07-05 10:14:11 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
#else /* old adv. API */
|
1999-12-28 02:37:14 +00:00
|
|
|
if (setsockopt(rssock, IPPROTO_IPV6, IPV6_HOPLIMIT, &on,
|
2003-08-08 16:56:01 +00:00
|
|
|
sizeof(on)) < 0) {
|
2003-08-08 16:38:23 +00:00
|
|
|
warnmsg(LOG_ERR, __func__, "IPV6_HOPLIMIT: %s",
|
2003-08-08 16:56:01 +00:00
|
|
|
strerror(errno));
|
1999-12-28 02:37:14 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2003-08-08 16:56:01 +00:00
|
|
|
#endif
|
1999-12-28 02:37:14 +00:00
|
|
|
|
|
|
|
/* specfiy to accept only router advertisements on the socket */
|
|
|
|
ICMP6_FILTER_SETBLOCKALL(&filt);
|
|
|
|
ICMP6_FILTER_SETPASS(ND_ROUTER_ADVERT, &filt);
|
|
|
|
if (setsockopt(rssock, IPPROTO_ICMPV6, ICMP6_FILTER, &filt,
|
2003-08-08 16:56:01 +00:00
|
|
|
sizeof(filt)) == -1) {
|
2003-08-08 16:38:23 +00:00
|
|
|
warnmsg(LOG_ERR, __func__, "setsockopt(ICMP6_FILTER): %s",
|
2003-08-08 16:56:01 +00:00
|
|
|
strerror(errno));
|
1999-12-28 02:37:14 +00:00
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* initialize msghdr for receiving packets */
|
|
|
|
rcviov[0].iov_base = (caddr_t)answer;
|
|
|
|
rcviov[0].iov_len = sizeof(answer);
|
|
|
|
rcvmhdr.msg_name = (caddr_t)&from;
|
|
|
|
rcvmhdr.msg_iov = rcviov;
|
|
|
|
rcvmhdr.msg_iovlen = 1;
|
|
|
|
rcvmhdr.msg_control = (caddr_t) rcvcmsgbuf;
|
|
|
|
|
|
|
|
/* 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 10:14:11 +00:00
|
|
|
sndmhdr.msg_controllen = sndcmsglen;
|
1999-12-28 02:37:14 +00:00
|
|
|
|
|
|
|
return(rssock);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sendpacket(struct ifinfo *ifinfo)
|
|
|
|
{
|
|
|
|
struct in6_pktinfo *pi;
|
2003-08-08 16:56:01 +00:00
|
|
|
struct cmsghdr *cm;
|
|
|
|
int hoplimit = 255;
|
|
|
|
int i;
|
2003-08-17 11:11:32 +00:00
|
|
|
struct sockaddr_in6 dst;
|
|
|
|
|
|
|
|
dst = sin6_allrouters;
|
|
|
|
dst.sin6_scope_id = ifinfo->linkid;
|
1999-12-28 02:37:14 +00:00
|
|
|
|
2003-08-17 11:11:32 +00:00
|
|
|
sndmhdr.msg_name = (caddr_t)&dst;
|
1999-12-28 02:37:14 +00:00
|
|
|
sndmhdr.msg_iov[0].iov_base = (caddr_t)ifinfo->rs_data;
|
|
|
|
sndmhdr.msg_iov[0].iov_len = ifinfo->rs_datalen;
|
|
|
|
|
|
|
|
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*/
|
|
|
|
pi->ipi6_ifindex = ifinfo->sdl->sdl_index;
|
|
|
|
|
|
|
|
/* specify the hop limit of the packet */
|
2003-08-08 16:56:01 +00:00
|
|
|
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));
|
1999-12-28 02:37:14 +00:00
|
|
|
|
2003-08-08 16:56:01 +00:00
|
|
|
warnmsg(LOG_DEBUG, __func__,
|
|
|
|
"send RS on %s, whose state is %d",
|
|
|
|
ifinfo->ifname, ifinfo->state);
|
1999-12-28 02:37:14 +00:00
|
|
|
i = sendmsg(rssock, &sndmhdr, 0);
|
|
|
|
if (i < 0 || i != ifinfo->rs_datalen) {
|
|
|
|
/*
|
|
|
|
* ENETDOWN is not so serious, especially when using several
|
|
|
|
* network cards on a mobile node. We ignore it.
|
|
|
|
*/
|
|
|
|
if (errno != ENETDOWN || dflag > 0)
|
2003-08-08 16:38:23 +00:00
|
|
|
warnmsg(LOG_ERR, __func__, "sendmsg on %s: %s",
|
2003-08-08 16:56:01 +00:00
|
|
|
ifinfo->ifname, strerror(errno));
|
1999-12-28 02:37:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* update counter */
|
|
|
|
ifinfo->probes++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rtsol_input(int s)
|
|
|
|
{
|
2003-08-17 11:11:32 +00:00
|
|
|
u_char ntopbuf[INET6_ADDRSTRLEN], ifnamebuf[IFNAMSIZ];
|
|
|
|
int ifindex = 0, i, *hlimp = NULL;
|
1999-12-28 02:37:14 +00:00
|
|
|
struct in6_pktinfo *pi = NULL;
|
|
|
|
struct ifinfo *ifi = NULL;
|
2003-08-17 11:11:32 +00:00
|
|
|
struct icmp6_hdr *icp;
|
2003-08-08 16:42:37 +00:00
|
|
|
struct nd_router_advert *nd_ra;
|
2003-08-17 11:11:32 +00:00
|
|
|
struct cmsghdr *cm;
|
1999-12-28 02:37:14 +00:00
|
|
|
|
2003-08-17 11:11:32 +00:00
|
|
|
/* get message. namelen and controllen must always be initialized. */
|
|
|
|
rcvmhdr.msg_namelen = sizeof(from);
|
|
|
|
rcvmhdr.msg_controllen = rcvcmsglen;
|
1999-12-28 02:37:14 +00:00
|
|
|
if ((i = recvmsg(s, &rcvmhdr, 0)) < 0) {
|
2003-08-08 16:38:23 +00:00
|
|
|
warnmsg(LOG_ERR, __func__, "recvmsg: %s", strerror(errno));
|
1999-12-28 02:37:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* extract optional information via Advanced API */
|
2003-08-08 16:56:01 +00:00
|
|
|
for (cm = (struct cmsghdr *)CMSG_FIRSTHDR(&rcvmhdr); cm;
|
|
|
|
cm = (struct cmsghdr *)CMSG_NXTHDR(&rcvmhdr, cm)) {
|
1999-12-28 02:37:14 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
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) {
|
2003-08-08 16:56:01 +00:00
|
|
|
warnmsg(LOG_ERR, __func__,
|
|
|
|
"failed to get receiving interface");
|
1999-12-28 02:37:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (hlimp == NULL) {
|
2003-08-08 16:56:01 +00:00
|
|
|
warnmsg(LOG_ERR, __func__,
|
|
|
|
"failed to get receiving hop limit");
|
1999-12-28 02:37:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i < sizeof(struct nd_router_advert)) {
|
2003-08-14 15:21:55 +00:00
|
|
|
warnmsg(LOG_INFO, __func__,
|
2003-08-08 16:56:01 +00:00
|
|
|
"packet size(%d) is too short", i);
|
1999-12-28 02:37:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
icp = (struct icmp6_hdr *)rcvmhdr.msg_iov[0].iov_base;
|
|
|
|
|
|
|
|
if (icp->icmp6_type != ND_ROUTER_ADVERT) {
|
2003-08-14 15:21:55 +00:00
|
|
|
/*
|
|
|
|
* this should not happen because we configured a filter
|
|
|
|
* that only passes RAs on the receiving socket.
|
|
|
|
*/
|
2003-08-08 16:38:23 +00:00
|
|
|
warnmsg(LOG_ERR, __func__,
|
2003-08-08 16:56:01 +00:00
|
|
|
"invalid icmp type(%d) from %s on %s", icp->icmp6_type,
|
|
|
|
inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf,
|
|
|
|
INET6_ADDRSTRLEN),
|
|
|
|
if_indextoname(pi->ipi6_ifindex, ifnamebuf));
|
1999-12-28 02:37:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (icp->icmp6_code != 0) {
|
2003-08-14 15:21:55 +00:00
|
|
|
warnmsg(LOG_INFO, __func__,
|
2003-08-08 16:56:01 +00:00
|
|
|
"invalid icmp code(%d) from %s on %s", icp->icmp6_code,
|
|
|
|
inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf,
|
|
|
|
INET6_ADDRSTRLEN),
|
|
|
|
if_indextoname(pi->ipi6_ifindex, ifnamebuf));
|
1999-12-28 02:37:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*hlimp != 255) {
|
2003-08-14 15:21:55 +00:00
|
|
|
warnmsg(LOG_INFO, __func__,
|
2003-08-08 16:56:01 +00:00
|
|
|
"invalid RA with hop limit(%d) from %s on %s",
|
|
|
|
*hlimp,
|
|
|
|
inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf,
|
|
|
|
INET6_ADDRSTRLEN),
|
|
|
|
if_indextoname(pi->ipi6_ifindex, ifnamebuf));
|
1999-12-28 02:37:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pi && !IN6_IS_ADDR_LINKLOCAL(&from.sin6_addr)) {
|
2003-08-14 15:21:55 +00:00
|
|
|
warnmsg(LOG_INFO, __func__,
|
2003-08-08 16:56:01 +00:00
|
|
|
"invalid RA with non link-local source from %s on %s",
|
|
|
|
inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf,
|
|
|
|
INET6_ADDRSTRLEN),
|
|
|
|
if_indextoname(pi->ipi6_ifindex, ifnamebuf));
|
1999-12-28 02:37:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* xxx: more validation? */
|
|
|
|
|
|
|
|
if ((ifi = find_ifinfo(pi->ipi6_ifindex)) == NULL) {
|
2003-08-14 15:21:55 +00:00
|
|
|
warnmsg(LOG_INFO, __func__,
|
2003-08-08 16:56:01 +00:00
|
|
|
"received RA from %s on an unexpected IF(%s)",
|
|
|
|
inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf,
|
|
|
|
INET6_ADDRSTRLEN),
|
|
|
|
if_indextoname(pi->ipi6_ifindex, ifnamebuf));
|
1999-12-28 02:37:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-08-08 16:38:23 +00:00
|
|
|
warnmsg(LOG_DEBUG, __func__,
|
2003-08-08 16:56:01 +00:00
|
|
|
"received RA from %s on %s, state is %d",
|
|
|
|
inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf, INET6_ADDRSTRLEN),
|
|
|
|
ifi->ifname, ifi->state);
|
1999-12-28 02:37:14 +00:00
|
|
|
|
2003-08-08 16:42:37 +00:00
|
|
|
nd_ra = (struct nd_router_advert *)icp;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process the "O bit."
|
|
|
|
* If the value of OtherConfigFlag changes from FALSE to TRUE, the
|
|
|
|
* host should invoke the stateful autoconfiguration protocol,
|
|
|
|
* requesting information.
|
|
|
|
* [RFC 2462 Section 5.5.3]
|
|
|
|
*/
|
|
|
|
if (((nd_ra->nd_ra_flags_reserved) & ND_RA_FLAG_OTHER) &&
|
|
|
|
!ifi->otherconfig) {
|
|
|
|
warnmsg(LOG_DEBUG, __func__,
|
|
|
|
"OtherConfigFlag on %s is turned on", ifi->ifname);
|
|
|
|
ifi->otherconfig = 1;
|
|
|
|
call_script(otherconf_script, ifi->ifname);
|
|
|
|
}
|
|
|
|
|
1999-12-28 02:37:14 +00:00
|
|
|
ifi->racnt++;
|
|
|
|
|
2003-08-08 16:56:01 +00:00
|
|
|
switch (ifi->state) {
|
|
|
|
case IFS_IDLE: /* should be ignored */
|
|
|
|
case IFS_DELAY: /* right? */
|
|
|
|
break;
|
|
|
|
case IFS_PROBE:
|
|
|
|
ifi->state = IFS_IDLE;
|
|
|
|
ifi->probes = 0;
|
|
|
|
rtsol_timer_update(ifi);
|
|
|
|
break;
|
1999-12-28 02:37:14 +00:00
|
|
|
}
|
|
|
|
}
|
2003-08-08 16:42:37 +00:00
|
|
|
|
|
|
|
static void
|
2004-01-14 17:16:19 +00:00
|
|
|
call_script(char *scriptpath, char *ifname)
|
2003-08-08 16:42:37 +00:00
|
|
|
{
|
|
|
|
pid_t pid, wpid;
|
|
|
|
|
|
|
|
if (scriptpath == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* launch the script */
|
|
|
|
pid = fork();
|
|
|
|
if (pid < 0) {
|
|
|
|
warnmsg(LOG_ERR, __func__,
|
|
|
|
"failed to fork: %s", strerror(errno));
|
|
|
|
return;
|
|
|
|
} else if (pid) {
|
|
|
|
int wstatus;
|
|
|
|
|
|
|
|
do {
|
|
|
|
wpid = wait(&wstatus);
|
|
|
|
} while (wpid != pid && wpid > 0);
|
|
|
|
|
|
|
|
if (wpid < 0)
|
|
|
|
warnmsg(LOG_ERR, __func__,
|
|
|
|
"wait: %s", strerror(errno));
|
|
|
|
else {
|
|
|
|
warnmsg(LOG_DEBUG, __func__,
|
|
|
|
"script \"%s\" terminated", scriptpath);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
char *argv[3];
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
argv[0] = scriptpath;
|
|
|
|
argv[1] = ifname;
|
|
|
|
argv[2] = NULL;
|
|
|
|
|
|
|
|
if (safefile(scriptpath)) {
|
|
|
|
warnmsg(LOG_ERR, __func__,
|
|
|
|
"script \"%s\" cannot be executed safely",
|
|
|
|
scriptpath);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((fd = open("/dev/null", O_RDWR)) != -1) {
|
|
|
|
dup2(fd, STDIN_FILENO);
|
|
|
|
dup2(fd, STDOUT_FILENO);
|
|
|
|
dup2(fd, STDERR_FILENO);
|
|
|
|
if (fd > STDERR_FILENO)
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
execv(scriptpath, argv);
|
|
|
|
|
|
|
|
warnmsg(LOG_ERR, __func__, "child: exec failed: %s",
|
|
|
|
strerror(errno));
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2004-01-14 17:16:19 +00:00
|
|
|
safefile(const char *path)
|
2003-08-08 16:42:37 +00:00
|
|
|
{
|
|
|
|
struct stat s;
|
|
|
|
uid_t myuid;
|
|
|
|
|
|
|
|
/* no setuid */
|
|
|
|
if (getuid() != geteuid()) {
|
|
|
|
warnmsg(LOG_NOTICE, __func__,
|
|
|
|
"setuid'ed execution not allowed\n");
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lstat(path, &s) != 0) {
|
|
|
|
warnmsg(LOG_NOTICE, __func__, "lstat failed: %s",
|
|
|
|
strerror(errno));
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* the file must be owned by the running uid */
|
|
|
|
myuid = getuid();
|
|
|
|
if (s.st_uid != myuid) {
|
|
|
|
warnmsg(LOG_NOTICE, __func__,
|
|
|
|
"%s has invalid owner uid\n", path);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (s.st_mode & S_IFMT) {
|
|
|
|
case S_IFREG:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
warnmsg(LOG_NOTICE, __func__,
|
|
|
|
"%s is an invalid file type 0x%o\n",
|
|
|
|
path, (s.st_mode & S_IFMT));
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|