2001-06-11 12:39:29 +00:00
|
|
|
/* $KAME: rrenumd.c,v 1.20 2000/11/08 02:40:53 itojun Exp $ */
|
2000-07-05 11:12:53 +00:00
|
|
|
|
2000-01-06 12:40:54 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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>
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <net/route.h>
|
|
|
|
|
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/ip.h>
|
|
|
|
#include <netinet/ip6.h>
|
|
|
|
#include <netinet/icmp6.h>
|
|
|
|
|
2000-07-05 11:12:53 +00:00
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
2000-01-06 12:40:54 +00:00
|
|
|
#ifdef IPSEC
|
2007-07-01 12:08:08 +00:00
|
|
|
#include <netipsec/ipsec.h>
|
2000-01-06 12:40:54 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2000-07-05 11:12:53 +00:00
|
|
|
#include <err.h>
|
2000-01-06 12:40:54 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <syslog.h>
|
|
|
|
|
|
|
|
#include "rrenumd.h"
|
|
|
|
|
2000-07-05 11:12:53 +00:00
|
|
|
#define LL_ALLROUTERS "ff02::2"
|
|
|
|
#define SL_ALLROUTERS "ff05::2"
|
2000-01-06 12:40:54 +00:00
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
#define RR_MCHLIM_DEFAULT 64
|
|
|
|
|
2000-01-06 12:40:54 +00:00
|
|
|
#ifndef IN6_IS_SCOPE_LINKLOCAL
|
2000-07-05 11:12:53 +00:00
|
|
|
#define IN6_IS_SCOPE_LINKLOCAL(a) \
|
2000-01-06 12:40:54 +00:00
|
|
|
((IN6_IS_ADDR_LINKLOCAL(a)) || \
|
|
|
|
(IN6_IS_ADDR_MC_LINKLOCAL(a)))
|
|
|
|
#endif /* IN6_IS_SCOPE_LINKLOCAL */
|
|
|
|
|
|
|
|
struct flags {
|
2000-07-05 11:12:53 +00:00
|
|
|
u_long debug : 1;
|
|
|
|
u_long fg : 1;
|
2000-01-06 12:40:54 +00:00
|
|
|
#ifdef IPSEC
|
|
|
|
#ifdef IPSEC_POLICY_IPSEC
|
2000-07-05 11:12:53 +00:00
|
|
|
u_long policy : 1;
|
|
|
|
#else /* IPSEC_POLICY_IPSEC */
|
|
|
|
u_long auth : 1;
|
|
|
|
u_long encrypt : 1;
|
2000-01-06 12:40:54 +00:00
|
|
|
#endif /* IPSEC_POLICY_IPSEC */
|
|
|
|
#endif /*IPSEC*/
|
|
|
|
};
|
|
|
|
|
2000-07-05 11:12:53 +00:00
|
|
|
struct msghdr sndmhdr;
|
|
|
|
struct msghdr rcvmhdr;
|
|
|
|
struct sockaddr_in6 from;
|
|
|
|
struct sockaddr_in6 sin6_ll_allrouters;
|
2000-01-06 12:40:54 +00:00
|
|
|
|
2000-07-05 11:12:53 +00:00
|
|
|
int s4, s6;
|
|
|
|
int with_v4dest, with_v6dest;
|
|
|
|
struct in6_addr prefix; /* ADHOC */
|
|
|
|
int prefixlen = 64; /* ADHOC */
|
2000-01-06 12:40:54 +00:00
|
|
|
|
2007-11-07 10:53:41 +00:00
|
|
|
extern int parse(FILE **);
|
2001-06-11 12:39:29 +00:00
|
|
|
|
2007-11-07 10:53:41 +00:00
|
|
|
static void show_usage(void);
|
|
|
|
static void init_sin6(struct sockaddr_in6 *, const char *);
|
2001-06-11 12:39:29 +00:00
|
|
|
#if 0
|
2007-11-07 10:53:41 +00:00
|
|
|
static void join_multi(const char *);
|
2001-06-11 12:39:29 +00:00
|
|
|
#endif
|
2007-11-07 10:53:41 +00:00
|
|
|
static void init_globals(void);
|
|
|
|
static void config(FILE **);
|
2001-06-11 12:39:29 +00:00
|
|
|
#ifdef IPSEC_POLICY_IPSEC
|
2007-11-07 10:53:41 +00:00
|
|
|
static void sock6_open(struct flags *, char *);
|
|
|
|
static void sock4_open(struct flags *, char *);
|
2001-06-11 12:39:29 +00:00
|
|
|
#else
|
2007-11-07 10:53:41 +00:00
|
|
|
static void sock6_open(struct flags *);
|
|
|
|
static void sock4_open(struct flags *);
|
2001-06-11 12:39:29 +00:00
|
|
|
#endif
|
2007-11-07 10:53:41 +00:00
|
|
|
static void rrenum_output(struct payload_list *, struct dst_list *);
|
|
|
|
static void rrenum_snd_eachdst(struct payload_list *);
|
2001-06-11 12:39:29 +00:00
|
|
|
#if 0
|
2007-11-07 10:53:41 +00:00
|
|
|
static void rrenum_snd_fullsequence(void);
|
2001-06-11 12:39:29 +00:00
|
|
|
#endif
|
2007-11-07 10:53:41 +00:00
|
|
|
static void rrenum_input(int);
|
|
|
|
int main(int, char *[]);
|
2001-06-11 12:39:29 +00:00
|
|
|
|
2000-01-06 12:40:54 +00:00
|
|
|
|
|
|
|
/* Print usage. Don't call this after daemonized. */
|
|
|
|
static void
|
|
|
|
show_usage()
|
|
|
|
{
|
|
|
|
fprintf(stderr, "usage: rrenumd [-c conf_file|-s] [-df"
|
|
|
|
#ifdef IPSEC
|
|
|
|
#ifdef IPSEC_POLICY_IPSEC
|
|
|
|
"] [-P policy"
|
2000-07-05 11:12:53 +00:00
|
|
|
#else /* IPSEC_POLICY_IPSEC */
|
|
|
|
"AE"
|
2000-01-06 12:40:54 +00:00
|
|
|
#endif /* IPSEC_POLICY_IPSEC */
|
|
|
|
#endif /* IPSEC */
|
|
|
|
"]\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
static void
|
2000-01-06 12:40:54 +00:00
|
|
|
init_sin6(struct sockaddr_in6 *sin6, const char *addr_ascii)
|
|
|
|
{
|
|
|
|
memset(sin6, 0, sizeof(*sin6));
|
|
|
|
sin6->sin6_len = sizeof(*sin6);
|
|
|
|
sin6->sin6_family = AF_INET6;
|
|
|
|
if (inet_pton(AF_INET6, addr_ascii, &sin6->sin6_addr) != 1)
|
|
|
|
; /* XXX do something */
|
|
|
|
}
|
|
|
|
|
2000-07-05 11:12:53 +00:00
|
|
|
#if 0 /* XXX: not necessary ?? */
|
2001-06-11 12:39:29 +00:00
|
|
|
static void
|
2000-07-05 11:12:53 +00:00
|
|
|
join_multi(const char *addrname)
|
|
|
|
{
|
|
|
|
struct ipv6_mreq mreq;
|
|
|
|
|
|
|
|
if (inet_pton(AF_INET6, addrname, &mreq.ipv6mr_multiaddr.s6_addr)
|
|
|
|
!= 1) {
|
|
|
|
syslog(LOG_ERR, "<%s> inet_pton failed(library bug?)",
|
2004-10-02 16:42:33 +00:00
|
|
|
__func__);
|
2000-07-05 11:12:53 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
/* ADHOC: currently join only one */
|
|
|
|
{
|
|
|
|
if ((mreq.ipv6mr_interface = if_nametoindex(ifname)) == 0) {
|
|
|
|
syslog(LOG_ERR, "<%s> ifname %s should be invalid: %s",
|
2004-10-02 16:42:33 +00:00
|
|
|
__func__, ifname, strerror(errno));
|
2000-07-05 11:12:53 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (setsockopt(s, IPPROTO_IPV6, IPV6_JOIN_GROUP,
|
|
|
|
&mreq,
|
|
|
|
sizeof(mreq)) < 0) {
|
|
|
|
syslog(LOG_ERR, "<%s> IPV6_JOIN_GROUP on %s: %s",
|
2004-10-02 16:42:33 +00:00
|
|
|
__func__, ifname, strerror(errno));
|
2000-07-05 11:12:53 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
static void
|
2000-01-06 12:40:54 +00:00
|
|
|
init_globals()
|
|
|
|
{
|
|
|
|
static struct iovec rcviov;
|
|
|
|
static u_char rprdata[4500]; /* maximal MTU of connected links */
|
2000-07-05 11:12:53 +00:00
|
|
|
static u_char *rcvcmsgbuf = NULL;
|
|
|
|
static u_char *sndcmsgbuf = NULL;
|
|
|
|
int sndcmsglen, rcvcmsglen;
|
2000-01-06 12:40:54 +00:00
|
|
|
|
|
|
|
/* init ll_allrouters */
|
|
|
|
init_sin6(&sin6_ll_allrouters, LL_ALLROUTERS);
|
|
|
|
|
|
|
|
/* initialize msghdr for receiving packets */
|
|
|
|
rcviov.iov_base = (caddr_t)rprdata;
|
|
|
|
rcviov.iov_len = sizeof(rprdata);
|
|
|
|
rcvmhdr.msg_namelen = sizeof(struct sockaddr_in6);
|
|
|
|
rcvmhdr.msg_iov = &rcviov;
|
|
|
|
rcvmhdr.msg_iovlen = 1;
|
2000-07-05 11:12:53 +00:00
|
|
|
rcvcmsglen = CMSG_SPACE(sizeof(struct in6_pktinfo)) +
|
|
|
|
CMSG_SPACE(sizeof(int));
|
|
|
|
if (rcvcmsgbuf == NULL &&
|
|
|
|
(rcvcmsgbuf = (u_char *)malloc(rcvcmsglen)) == NULL) {
|
2004-10-02 16:42:33 +00:00
|
|
|
syslog(LOG_ERR, "<%s>: malloc failed", __func__);
|
2000-07-05 11:12:53 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2000-01-06 12:40:54 +00:00
|
|
|
rcvmhdr.msg_control = (caddr_t)rcvcmsgbuf;
|
2000-07-05 11:12:53 +00:00
|
|
|
rcvmhdr.msg_controllen = rcvcmsglen;
|
2000-01-06 12:40:54 +00:00
|
|
|
|
|
|
|
/* initialize msghdr for sending packets */
|
|
|
|
sndmhdr.msg_namelen = sizeof(struct sockaddr_in6);
|
|
|
|
sndmhdr.msg_iovlen = 1;
|
2000-07-05 11:12:53 +00:00
|
|
|
sndcmsglen = CMSG_SPACE(sizeof(struct in6_pktinfo)) +
|
|
|
|
CMSG_SPACE(sizeof(int));
|
|
|
|
if (sndcmsgbuf == NULL &&
|
|
|
|
(sndcmsgbuf = (u_char *)malloc(sndcmsglen)) == NULL) {
|
2004-10-02 16:42:33 +00:00
|
|
|
syslog(LOG_ERR, "<%s>: malloc failed", __func__);
|
2000-07-05 11:12:53 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2000-01-06 12:40:54 +00:00
|
|
|
sndmhdr.msg_control = (caddr_t)sndcmsgbuf;
|
2000-07-05 11:12:53 +00:00
|
|
|
sndmhdr.msg_controllen = sndcmsglen;
|
2000-01-06 12:40:54 +00:00
|
|
|
}
|
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
static void
|
2000-01-06 12:40:54 +00:00
|
|
|
config(FILE **fpp)
|
|
|
|
{
|
|
|
|
struct payload_list *pl;
|
|
|
|
struct iovec *iov;
|
|
|
|
struct icmp6_router_renum *irr;
|
|
|
|
struct rr_pco_match *rpm;
|
|
|
|
|
|
|
|
if (parse(fpp) < 0) {
|
2004-10-02 16:42:33 +00:00
|
|
|
syslog(LOG_ERR, "<%s> parse failed", __func__);
|
2000-01-06 12:40:54 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* initialize fields not configured by parser */
|
|
|
|
for (pl = pl_head; pl; pl = pl->pl_next) {
|
|
|
|
iov = (struct iovec *)&pl->pl_sndiov;
|
|
|
|
irr = (struct icmp6_router_renum *)&pl->pl_irr;
|
|
|
|
rpm = (struct rr_pco_match *)&pl->pl_rpm;
|
|
|
|
|
|
|
|
irr->rr_type = ICMP6_ROUTER_RENUMBERING;
|
|
|
|
irr->rr_code = 0;
|
|
|
|
/*
|
|
|
|
* now we don't support multiple PCOs in a rr message.
|
|
|
|
* so segment number is not supported.
|
|
|
|
*/
|
|
|
|
/* TODO: rr flags config in parser */
|
|
|
|
irr->rr_flags |= ICMP6_RR_FLAGS_SPECSITE;
|
|
|
|
/* TODO: max delay config in parser */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* means only 1 use_prefix is contained as router-renum-05.txt.
|
|
|
|
* now we don't support multiple PCOs in a rr message,
|
|
|
|
* nor multiple use_prefix in one PCO.
|
|
|
|
*/
|
|
|
|
rpm->rpm_len = 4*1 +3;
|
|
|
|
rpm->rpm_ordinal = 0;
|
|
|
|
iov->iov_base = (caddr_t)irr;
|
|
|
|
iov->iov_len = sizeof(struct icmp6_router_renum)
|
|
|
|
+ sizeof(struct rr_pco_match)
|
|
|
|
+ sizeof(struct rr_pco_use);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
static void
|
2000-01-06 12:40:54 +00:00
|
|
|
sock6_open(struct flags *flags
|
|
|
|
#ifdef IPSEC_POLICY_IPSEC
|
|
|
|
, char *policy
|
|
|
|
#endif /* IPSEC_POLICY_IPSEC */
|
|
|
|
)
|
|
|
|
{
|
|
|
|
struct icmp6_filter filt;
|
2000-07-05 11:12:53 +00:00
|
|
|
int on;
|
|
|
|
#ifdef IPSEC
|
|
|
|
#ifndef IPSEC_POLICY_IPSEC
|
|
|
|
int optval;
|
|
|
|
#endif
|
|
|
|
#endif
|
2000-01-06 12:40:54 +00:00
|
|
|
|
|
|
|
if (with_v6dest == 0)
|
|
|
|
return;
|
|
|
|
if (with_v6dest &&
|
|
|
|
(s6 = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6)) < 0) {
|
2004-10-02 16:42:33 +00:00
|
|
|
syslog(LOG_ERR, "<%s> socket(v6): %s", __func__,
|
2000-01-06 12:40:54 +00:00
|
|
|
strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2000-07-05 11:12:53 +00:00
|
|
|
/*
|
|
|
|
* join all routers multicast addresses.
|
|
|
|
*/
|
|
|
|
#if 0 /* XXX: not necessary ?? */
|
|
|
|
join_multi(LL_ALLROUTERS);
|
|
|
|
join_multi(SL_ALLROUTERS);
|
|
|
|
#endif
|
2000-01-06 12:40:54 +00:00
|
|
|
|
|
|
|
/* set icmpv6 filter */
|
|
|
|
ICMP6_FILTER_SETBLOCKALL(&filt);
|
|
|
|
ICMP6_FILTER_SETPASS(ICMP6_ROUTER_RENUMBERING, &filt);
|
|
|
|
if (setsockopt(s6, IPPROTO_ICMPV6, ICMP6_FILTER, &filt,
|
|
|
|
sizeof(filt)) < 0) {
|
|
|
|
syslog(LOG_ERR, "<%s> IICMP6_FILTER: %s",
|
2004-10-02 16:42:33 +00:00
|
|
|
__func__, strerror(errno));
|
2000-01-06 12:40:54 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* specify to tell receiving interface */
|
|
|
|
on = 1;
|
2003-10-26 06:21:16 +00:00
|
|
|
if (setsockopt(s6, IPPROTO_IPV6, IPV6_RECVPKTINFO, &on,
|
2000-01-06 12:40:54 +00:00
|
|
|
sizeof(on)) < 0) {
|
2003-10-26 10:30:17 +00:00
|
|
|
syslog(LOG_ERR, "<%s> IPV6_RECVPKTINFO: %s",
|
2004-10-02 16:42:33 +00:00
|
|
|
__func__, strerror(errno));
|
2000-01-06 12:40:54 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef IPSEC
|
|
|
|
#ifdef IPSEC_POLICY_IPSEC
|
|
|
|
if (flags->policy) {
|
|
|
|
char *buf;
|
|
|
|
buf = ipsec_set_policy(policy, strlen(policy));
|
|
|
|
if (buf == NULL)
|
2000-11-19 13:30:36 +00:00
|
|
|
errx(1, "%s", ipsec_strerror());
|
2000-01-06 12:40:54 +00:00
|
|
|
/* XXX should handle in/out bound policy. */
|
|
|
|
if (setsockopt(s6, IPPROTO_IPV6, IPV6_IPSEC_POLICY,
|
|
|
|
buf, ipsec_get_policylen(buf)) < 0)
|
2001-06-11 12:39:29 +00:00
|
|
|
err(1, "setsockopt(IPV6_IPSEC_POLICY)");
|
2000-01-06 12:40:54 +00:00
|
|
|
free(buf);
|
|
|
|
}
|
2000-07-05 11:12:53 +00:00
|
|
|
#else /* IPSEC_POLICY_IPSEC */
|
|
|
|
if (flags->auth) {
|
|
|
|
optval = IPSEC_LEVEL_REQUIRE;
|
|
|
|
if (setsockopt(s6, IPPROTO_IPV6, IPV6_AUTH_TRANS_LEVEL,
|
|
|
|
&optval, sizeof(optval)) == -1) {
|
|
|
|
syslog(LOG_ERR, "<%s> IPV6_AUTH_TRANS_LEVEL: %s",
|
2004-10-02 16:42:33 +00:00
|
|
|
__func__, strerror(errno));
|
2000-07-05 11:12:53 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (flags->encrypt) {
|
|
|
|
optval = IPSEC_LEVEL_REQUIRE;
|
|
|
|
if (setsockopt(s6, IPPROTO_IPV6, IPV6_ESP_TRANS_LEVEL,
|
|
|
|
&optval, sizeof(optval)) == -1) {
|
|
|
|
syslog(LOG_ERR, "<%s> IPV6_ESP_TRANS_LEVEL: %s",
|
2004-10-02 16:42:33 +00:00
|
|
|
__func__, strerror(errno));
|
2000-07-05 11:12:53 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* IPSEC_POLICY_IPSEC */
|
|
|
|
#endif /* IPSEC */
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
static void
|
2000-07-05 11:12:53 +00:00
|
|
|
sock4_open(struct flags *flags
|
|
|
|
#ifdef IPSEC_POLICY_IPSEC
|
|
|
|
, char *policy
|
|
|
|
#endif /* IPSEC_POLICY_IPSEC */
|
|
|
|
)
|
|
|
|
{
|
|
|
|
#ifdef IPSEC
|
|
|
|
#ifndef IPSEC_POLICY_IPSEC
|
|
|
|
int optval;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (with_v4dest == 0)
|
|
|
|
return;
|
|
|
|
if ((s4 = socket(AF_INET, SOCK_RAW, IPPROTO_ICMPV6)) < 0) {
|
2004-10-02 16:42:33 +00:00
|
|
|
syslog(LOG_ERR, "<%s> socket(v4): %s", __func__,
|
2000-07-05 11:12:53 +00:00
|
|
|
strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0 /* XXX: not necessary ?? */
|
|
|
|
/*
|
|
|
|
* join all routers multicast addresses.
|
|
|
|
*/
|
|
|
|
some_join_function();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef IPSEC
|
|
|
|
#ifdef IPSEC_POLICY_IPSEC
|
|
|
|
if (flags->policy) {
|
|
|
|
char *buf;
|
|
|
|
buf = ipsec_set_policy(policy, strlen(policy));
|
|
|
|
if (buf == NULL)
|
2000-11-19 13:30:36 +00:00
|
|
|
errx(1, "%s", ipsec_strerror());
|
2000-07-05 11:12:53 +00:00
|
|
|
/* XXX should handle in/out bound policy. */
|
|
|
|
if (setsockopt(s4, IPPROTO_IP, IP_IPSEC_POLICY,
|
|
|
|
buf, ipsec_get_policylen(buf)) < 0)
|
2001-06-11 12:39:29 +00:00
|
|
|
err(1, "setsockopt(IP_IPSEC_POLICY)");
|
2000-07-05 11:12:53 +00:00
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
#else /* IPSEC_POLICY_IPSEC */
|
|
|
|
if (flags->auth) {
|
|
|
|
optval = IPSEC_LEVEL_REQUIRE;
|
|
|
|
if (setsockopt(s4, IPPROTO_IP, IP_AUTH_TRANS_LEVEL,
|
|
|
|
&optval, sizeof(optval)) == -1) {
|
|
|
|
syslog(LOG_ERR, "<%s> IP_AUTH_TRANS_LEVEL: %s",
|
2004-10-02 16:42:33 +00:00
|
|
|
__func__, strerror(errno));
|
2000-07-05 11:12:53 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (flags->encrypt) {
|
|
|
|
optval = IPSEC_LEVEL_REQUIRE;
|
|
|
|
if (setsockopt(s4, IPPROTO_IP, IP_ESP_TRANS_LEVEL,
|
|
|
|
&optval, sizeof(optval)) == -1) {
|
|
|
|
syslog(LOG_ERR, "<%s> IP_ESP_TRANS_LEVEL: %s",
|
2004-10-02 16:42:33 +00:00
|
|
|
__func__, strerror(errno));
|
2000-07-05 11:12:53 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
2000-01-06 12:40:54 +00:00
|
|
|
#endif /* IPSEC_POLICY_IPSEC */
|
|
|
|
#endif /* IPSEC */
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
static void
|
2000-01-06 12:40:54 +00:00
|
|
|
rrenum_output(struct payload_list *pl, struct dst_list *dl)
|
|
|
|
{
|
|
|
|
int i, msglen = 0;
|
|
|
|
struct cmsghdr *cm;
|
|
|
|
struct in6_pktinfo *pi;
|
|
|
|
struct sockaddr_in6 *sin6 = NULL;
|
|
|
|
|
|
|
|
sndmhdr.msg_name = (caddr_t)dl->dl_dst;
|
|
|
|
if (dl->dl_dst->sa_family == AF_INET6)
|
|
|
|
sin6 = (struct sockaddr_in6 *)dl->dl_dst;
|
|
|
|
|
|
|
|
if (sin6 != NULL &&
|
2001-06-11 12:39:29 +00:00
|
|
|
IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr)) {
|
|
|
|
int hoplimit = RR_MCHLIM_DEFAULT;
|
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*/
|
|
|
|
pi->ipi6_ifindex = sin6->sin6_scope_id;
|
2000-07-05 11:12:53 +00:00
|
|
|
msglen += CMSG_LEN(sizeof(struct in6_pktinfo));
|
2000-01-06 12:40:54 +00:00
|
|
|
|
|
|
|
/* specify the hop limit of the packet if dest is link local */
|
|
|
|
/* not defined by router-renum-05.txt, but maybe its OK */
|
|
|
|
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));
|
2000-07-05 11:12:53 +00:00
|
|
|
msglen += CMSG_LEN(sizeof(int));
|
2000-01-06 12:40:54 +00:00
|
|
|
}
|
|
|
|
sndmhdr.msg_controllen = msglen;
|
|
|
|
if (sndmhdr.msg_controllen == 0)
|
|
|
|
sndmhdr.msg_control = 0;
|
|
|
|
|
|
|
|
sndmhdr.msg_iov = &pl->pl_sndiov;
|
2000-07-05 11:12:53 +00:00
|
|
|
i = sendmsg(dl->dl_dst->sa_family == AF_INET ? s4 : s6, &sndmhdr, 0);
|
2000-01-06 12:40:54 +00:00
|
|
|
|
|
|
|
if (i < 0 || i != sndmhdr.msg_iov->iov_len)
|
2004-10-02 16:42:33 +00:00
|
|
|
syslog(LOG_ERR, "<%s> sendmsg: %s", __func__,
|
2000-01-06 12:40:54 +00:00
|
|
|
strerror(errno));
|
|
|
|
}
|
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
static void
|
2000-01-06 12:40:54 +00:00
|
|
|
rrenum_snd_eachdst(struct payload_list *pl)
|
|
|
|
{
|
|
|
|
struct dst_list *dl;
|
|
|
|
|
|
|
|
for (dl = dl_head; dl; dl = dl->dl_next) {
|
|
|
|
rrenum_output(pl, dl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
#if 0
|
|
|
|
static void
|
2000-01-06 12:40:54 +00:00
|
|
|
rrenum_snd_fullsequence()
|
|
|
|
{
|
|
|
|
struct payload_list *pl;
|
|
|
|
|
|
|
|
for (pl = pl_head; pl; pl = pl->pl_next) {
|
|
|
|
rrenum_snd_eachdst(pl);
|
|
|
|
}
|
|
|
|
}
|
2001-06-11 12:39:29 +00:00
|
|
|
#endif
|
2000-01-06 12:40:54 +00:00
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
static void
|
2000-01-06 12:40:54 +00:00
|
|
|
rrenum_input(int s)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct icmp6_router_renum *rr;
|
|
|
|
|
|
|
|
/* get message */
|
|
|
|
if ((i = recvmsg(s, &rcvmhdr, 0)) < 0) {
|
2004-10-02 16:42:33 +00:00
|
|
|
syslog(LOG_ERR, "<%s> recvmsg: %s", __func__,
|
2000-01-06 12:40:54 +00:00
|
|
|
strerror(errno));
|
|
|
|
return;
|
|
|
|
}
|
2000-07-05 11:12:53 +00:00
|
|
|
if (s == s4)
|
|
|
|
i -= sizeof(struct ip);
|
2000-01-06 12:40:54 +00:00
|
|
|
if (i < sizeof(struct icmp6_router_renum)) {
|
|
|
|
syslog(LOG_ERR, "<%s> packet size(%d) is too short",
|
2004-10-02 16:42:33 +00:00
|
|
|
__func__, i);
|
2000-01-06 12:40:54 +00:00
|
|
|
return;
|
|
|
|
}
|
2000-07-05 11:12:53 +00:00
|
|
|
if (s == s4) {
|
|
|
|
struct ip *ip = (struct ip *)rcvmhdr.msg_iov->iov_base;
|
|
|
|
|
|
|
|
rr = (struct icmp6_router_renum *)(ip + 1);
|
|
|
|
} else /* s == s6 */
|
|
|
|
rr = (struct icmp6_router_renum *)rcvmhdr.msg_iov->iov_base;
|
2000-01-06 12:40:54 +00:00
|
|
|
|
|
|
|
switch(rr->rr_code) {
|
|
|
|
case ICMP6_ROUTER_RENUMBERING_COMMAND:
|
|
|
|
/* COMMAND will be processed by rtadvd */
|
|
|
|
break;
|
|
|
|
case ICMP6_ROUTER_RENUMBERING_RESULT:
|
|
|
|
/* TODO: receiving result message */
|
|
|
|
break;
|
|
|
|
default:
|
2000-07-05 11:12:53 +00:00
|
|
|
syslog(LOG_ERR, "<%s> received unknown code %d",
|
2004-10-02 16:42:33 +00:00
|
|
|
__func__, rr->rr_code);
|
2000-01-06 12:40:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
FILE *fp = stdin;
|
|
|
|
fd_set fdset;
|
|
|
|
struct timeval timeout;
|
|
|
|
int ch, i, maxfd = 0, send_counter = 0;
|
|
|
|
struct flags flags;
|
|
|
|
struct payload_list *pl;
|
|
|
|
#ifdef IPSEC_POLICY_IPSEC
|
|
|
|
char *policy = NULL;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
memset(&flags, 0, sizeof(flags));
|
2000-07-05 11:12:53 +00:00
|
|
|
openlog("rrenumd", LOG_PID, LOG_DAEMON);
|
2000-01-06 12:40:54 +00:00
|
|
|
|
|
|
|
/* get options */
|
|
|
|
while ((ch = getopt(argc, argv, "c:sdf"
|
|
|
|
#ifdef IPSEC
|
|
|
|
#ifdef IPSEC_POLICY_IPSEC
|
2001-07-02 17:50:50 +00:00
|
|
|
"P:"
|
2000-07-05 11:12:53 +00:00
|
|
|
#else /* IPSEC_POLICY_IPSEC */
|
|
|
|
"AE"
|
2000-01-06 12:40:54 +00:00
|
|
|
#endif /* IPSEC_POLICY_IPSEC */
|
|
|
|
#endif /* IPSEC */
|
|
|
|
)) != -1){
|
|
|
|
switch (ch) {
|
|
|
|
case 'c':
|
|
|
|
if((fp = fopen(optarg, "r")) == NULL) {
|
|
|
|
syslog(LOG_ERR,
|
|
|
|
"<%s> config file %s open failed",
|
2004-10-02 16:42:33 +00:00
|
|
|
__func__, optarg);
|
2000-01-06 12:40:54 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
fp = stdin;
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
flags.debug = 1;
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
flags.fg = 1;
|
|
|
|
break;
|
|
|
|
#ifdef IPSEC
|
|
|
|
#ifdef IPSEC_POLICY_IPSEC
|
|
|
|
case 'P':
|
|
|
|
flags.policy = 1;
|
|
|
|
policy = strdup(optarg);
|
|
|
|
break;
|
2000-07-05 11:12:53 +00:00
|
|
|
#else /* IPSEC_POLICY_IPSEC */
|
|
|
|
case 'A':
|
|
|
|
flags.auth = 1;
|
|
|
|
break;
|
|
|
|
case 'E':
|
|
|
|
flags.encrypt = 1;
|
|
|
|
break;
|
2000-01-06 12:40:54 +00:00
|
|
|
#endif /* IPSEC_POLICY_IPSEC */
|
|
|
|
#endif /*IPSEC*/
|
|
|
|
default:
|
|
|
|
show_usage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
/* set log level */
|
|
|
|
if (flags.debug == 0)
|
|
|
|
(void)setlogmask(LOG_UPTO(LOG_ERR));
|
|
|
|
if (flags.debug == 1)
|
|
|
|
(void)setlogmask(LOG_UPTO(LOG_INFO));
|
|
|
|
|
|
|
|
/* init global variables */
|
|
|
|
init_globals();
|
|
|
|
|
|
|
|
config(&fp);
|
|
|
|
|
|
|
|
sock6_open(&flags
|
|
|
|
#ifdef IPSEC_POLICY_IPSEC
|
|
|
|
, policy
|
2000-07-05 11:12:53 +00:00
|
|
|
#endif /* IPSEC_POLICY_IPSEC */
|
|
|
|
);
|
|
|
|
sock4_open(&flags
|
|
|
|
#ifdef IPSEC_POLICY_IPSEC
|
|
|
|
, policy
|
2000-01-06 12:40:54 +00:00
|
|
|
#endif /* IPSEC_POLICY_IPSEC */
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!flags.fg)
|
|
|
|
daemon(0, 0);
|
|
|
|
|
|
|
|
FD_ZERO(&fdset);
|
|
|
|
if (with_v6dest) {
|
|
|
|
FD_SET(s6, &fdset);
|
|
|
|
if (s6 > maxfd)
|
|
|
|
maxfd = s6;
|
|
|
|
}
|
2000-07-05 11:12:53 +00:00
|
|
|
if (with_v4dest) {
|
|
|
|
FD_SET(s4, &fdset);
|
|
|
|
if (s4 > maxfd)
|
|
|
|
maxfd = s4;
|
|
|
|
}
|
2000-01-06 12:40:54 +00:00
|
|
|
|
|
|
|
/* ADHOC: timeout each 30seconds */
|
|
|
|
memset(&timeout, 0, sizeof(timeout));
|
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
/* init temporary payload_list and send_counter*/
|
2000-01-06 12:40:54 +00:00
|
|
|
pl = pl_head;
|
|
|
|
send_counter = retry + 1;
|
|
|
|
while (1) {
|
|
|
|
struct fd_set select_fd = fdset; /* reinitialize */
|
|
|
|
|
|
|
|
if ((i = select(maxfd + 1, &select_fd, NULL, NULL,
|
|
|
|
&timeout)) < 0){
|
|
|
|
syslog(LOG_ERR, "<%s> select: %s",
|
2004-10-02 16:42:33 +00:00
|
|
|
__func__, strerror(errno));
|
2000-01-06 12:40:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (i == 0) { /* timeout */
|
|
|
|
if (pl == NULL)
|
|
|
|
exit(0);
|
|
|
|
rrenum_snd_eachdst(pl);
|
|
|
|
send_counter--;
|
2001-06-11 12:39:29 +00:00
|
|
|
timeout.tv_sec = 30;
|
2000-01-06 12:40:54 +00:00
|
|
|
if (send_counter == 0) {
|
2001-06-11 12:39:29 +00:00
|
|
|
timeout.tv_sec = 0;
|
2000-01-06 12:40:54 +00:00
|
|
|
pl = pl->pl_next;
|
|
|
|
send_counter = retry + 1;
|
|
|
|
}
|
|
|
|
}
|
2000-07-05 11:12:53 +00:00
|
|
|
if (FD_ISSET(s4, &select_fd))
|
|
|
|
rrenum_input(s4);
|
2000-01-06 12:40:54 +00:00
|
|
|
if (FD_ISSET(s6, &select_fd))
|
|
|
|
rrenum_input(s6);
|
|
|
|
}
|
|
|
|
}
|