diff options
author | Jun-ichiro itojun Hagino <itojun@cvs.openbsd.org> | 2002-05-31 21:24:29 +0000 |
---|---|---|
committer | Jun-ichiro itojun Hagino <itojun@cvs.openbsd.org> | 2002-05-31 21:24:29 +0000 |
commit | 016a2eeb3a47fcdf174c977d8026a2a3ed13ebb1 (patch) | |
tree | 2380e5d39646272f60cfbed3b223aba90bd183b8 /usr.sbin | |
parent | ed41dbb449d7a54f1617d4a36dc7d4262d17b07c (diff) |
sync w/ latest kame. link id handling.
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/rtsold/dump.c | 4 | ||||
-rw-r--r-- | usr.sbin/rtsold/if.c | 19 | ||||
-rw-r--r-- | usr.sbin/rtsold/probe.c | 28 | ||||
-rw-r--r-- | usr.sbin/rtsold/rtsol.c | 10 | ||||
-rw-r--r-- | usr.sbin/rtsold/rtsold.c | 135 | ||||
-rw-r--r-- | usr.sbin/rtsold/rtsold.h | 8 |
6 files changed, 117 insertions, 87 deletions
diff --git a/usr.sbin/rtsold/dump.c b/usr.sbin/rtsold/dump.c index deaa6b356f8..da69e608b95 100644 --- a/usr.sbin/rtsold/dump.c +++ b/usr.sbin/rtsold/dump.c @@ -1,5 +1,5 @@ -/* $OpenBSD: dump.c,v 1.8 2002/05/31 09:53:26 deraadt Exp $ */ -/* $KAME: dump.c,v 1.9 2001/08/20 06:55:54 itojun Exp $ */ +/* $OpenBSD: dump.c,v 1.9 2002/05/31 21:24:27 itojun Exp $ */ +/* $KAME: dump.c,v 1.10 2002/05/31 10:10:03 itojun Exp $ */ /* * Copyright (C) 1999 WIDE Project. diff --git a/usr.sbin/rtsold/if.c b/usr.sbin/rtsold/if.c index edd74486b1d..f4dfa1e9213 100644 --- a/usr.sbin/rtsold/if.c +++ b/usr.sbin/rtsold/if.c @@ -1,5 +1,5 @@ -/* $OpenBSD: if.c,v 1.11 2002/05/31 09:53:26 deraadt Exp $ */ -/* $KAME: if.c,v 1.15 2001/05/22 06:04:17 jinmei Exp $ */ +/* $OpenBSD: if.c,v 1.12 2002/05/31 21:24:28 itojun Exp $ */ +/* $KAME: if.c,v 1.18 2002/05/31 10:10:03 itojun Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -37,23 +37,12 @@ #include <sys/queue.h> #include <net/if.h> -#if defined(__FreeBSD__) && __FreeBSD__ >= 3 -#include <net/if_var.h> -#endif /* __FreeBSD__ >= 3 */ #include <net/if_types.h> #include <net/route.h> #include <net/if_dl.h> #include <net/if_media.h> -#ifdef __FreeBSD__ -# include <net/ethernet.h> -#endif -#ifdef __NetBSD__ -#include <net/if_ether.h> -#endif -#if defined(__bsdi__) || defined(__OpenBSD__) -# include <netinet/in.h> -# include <netinet/if_ether.h> -#endif +#include <netinet/in.h> +#include <netinet/if_ether.h> #include <netinet/in.h> #include <netinet/icmp6.h> diff --git a/usr.sbin/rtsold/probe.c b/usr.sbin/rtsold/probe.c index 5fa148c71f7..91ed3dace4e 100644 --- a/usr.sbin/rtsold/probe.c +++ b/usr.sbin/rtsold/probe.c @@ -1,5 +1,5 @@ -/* $OpenBSD: probe.c,v 1.6 2002/05/31 09:53:26 deraadt Exp $ */ -/* $KAME: probe.c,v 1.10 2000/08/13 06:14:59 itojun Exp $ */ +/* $OpenBSD: probe.c,v 1.7 2002/05/31 21:24:28 itojun Exp $ */ +/* $KAME: probe.c,v 1.14 2002/05/31 10:10:03 itojun Exp $ */ /* * Copyright (C) 1998 WIDE Project. @@ -38,9 +38,7 @@ #include <sys/queue.h> #include <net/if.h> -#if defined(__FreeBSD__) && __FreeBSD__ >= 3 -#include <net/if_var.h> -#endif /* __FreeBSD__ >= 3 */ +#include <net/if_dl.h> #include <netinet/in.h> #include <netinet6/in6_var.h> @@ -60,7 +58,7 @@ static struct msghdr sndmhdr; static struct iovec sndiov[2]; static int probesock; -static void sendprobe(struct in6_addr *addr, int ifindex); +static void sendprobe(struct in6_addr *, struct ifinfo *); int probe_init() @@ -99,18 +97,19 @@ probe_init() * Probe if each router in the default router list is still alive. */ void -defrouter_probe(int ifindex) +defrouter_probe(struct ifinfo *ifinfo) { u_char ntopbuf[INET6_ADDRSTRLEN]; struct in6_drlist dr; int s, i; + int ifindex = ifinfo->sdl->sdl_index; if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) { warnmsg(LOG_ERR, __FUNCTION__, "socket: %s", strerror(errno)); return; } - bzero(&dr, sizeof(dr)); - strlcpy(dr.ifname, "lo0", sizeof dr.ifname); /* dummy interface */ + memset(&dr, 0, sizeof(dr)); + strcpy(dr.ifname, "lo0"); /* dummy interface */ if (ioctl(s, SIOCGDRLST_IN6, (caddr_t)&dr) < 0) { warnmsg(LOG_ERR, __FUNCTION__, "ioctl(SIOCGDRLST_IN6): %s", strerror(errno)); @@ -123,14 +122,13 @@ defrouter_probe(int ifindex) if (!IN6_IS_ADDR_LINKLOCAL(&dr.defrouter[i].rtaddr)) { warnmsg(LOG_ERR, __FUNCTION__, "default router list contains a " - "non-linklocal address(%s)", + "non-link-local address(%s)", inet_ntop(AF_INET6, &dr.defrouter[i].rtaddr, ntopbuf, INET6_ADDRSTRLEN)); continue; /* ignore the address */ } - sendprobe(&dr.defrouter[i].rtaddr, - dr.defrouter[i].if_index); + sendprobe(&dr.defrouter[i].rtaddr, ifinfo); } } @@ -139,18 +137,20 @@ closeandend: } static void -sendprobe(struct in6_addr *addr, int ifindex) +sendprobe(struct in6_addr *addr, struct ifinfo *ifinfo) { u_char ntopbuf[INET6_ADDRSTRLEN], ifnamebuf[IFNAMSIZ]; struct sockaddr_in6 sa6_probe; struct in6_pktinfo *pi; struct cmsghdr *cm; + u_int32_t ifindex = ifinfo->sdl->sdl_index; int hoplimit = 1; - bzero(&sa6_probe, sizeof(sa6_probe)); + memset(&sa6_probe, 0, sizeof(sa6_probe)); sa6_probe.sin6_family = AF_INET6; sa6_probe.sin6_len = sizeof(sa6_probe); sa6_probe.sin6_addr = *addr; + sa6_probe.sin6_scope_id = ifinfo->linkid; sndmhdr.msg_name = (caddr_t)&sa6_probe; sndmhdr.msg_iov[0].iov_base = NULL; diff --git a/usr.sbin/rtsold/rtsol.c b/usr.sbin/rtsold/rtsol.c index 6c419b5b618..a4052ac67ca 100644 --- a/usr.sbin/rtsold/rtsol.c +++ b/usr.sbin/rtsold/rtsol.c @@ -1,5 +1,5 @@ -/* $OpenBSD: rtsol.c,v 1.7 2002/05/31 09:53:26 deraadt Exp $ */ -/* $KAME: rtsol.c,v 1.14 2001/11/13 10:31:23 jinmei Exp $ */ +/* $OpenBSD: rtsol.c,v 1.8 2002/05/31 21:24:28 itojun Exp $ */ +/* $KAME: rtsol.c,v 1.15 2002/05/31 10:10:03 itojun Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -177,8 +177,12 @@ sendpacket(struct ifinfo *ifinfo) struct cmsghdr *cm; int hoplimit = 255; int i; + struct sockaddr_in6 dst; - sndmhdr.msg_name = (caddr_t)&sin6_allrouters; + dst = sin6_allrouters; + dst.sin6_scope_id = ifinfo->linkid; + + sndmhdr.msg_name = (caddr_t)&dst; sndmhdr.msg_iov[0].iov_base = (caddr_t)ifinfo->rs_data; sndmhdr.msg_iov[0].iov_len = ifinfo->rs_datalen; diff --git a/usr.sbin/rtsold/rtsold.c b/usr.sbin/rtsold/rtsold.c index 26ee569b51c..6eb21ef9817 100644 --- a/usr.sbin/rtsold/rtsold.c +++ b/usr.sbin/rtsold/rtsold.c @@ -1,5 +1,5 @@ -/* $OpenBSD: rtsold.c,v 1.20 2002/05/31 10:11:14 itojun Exp $ */ -/* $KAME: rtsold.c,v 1.32 2001/07/09 22:34:07 itojun Exp $ */ +/* $OpenBSD: rtsold.c,v 1.21 2002/05/31 21:24:28 itojun Exp $ */ +/* $KAME: rtsold.c,v 1.49 2002/05/31 10:19:46 itojun Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -33,6 +33,7 @@ #include <sys/types.h> #include <sys/time.h> #include <sys/socket.h> +#include <sys/param.h> #include <net/if.h> #include <net/if_dl.h> @@ -88,7 +89,6 @@ static int mobile_node = 0; volatile sig_atomic_t do_dump; static char *dumpfilename = "/var/run/rtsold.dump"; /* XXX: should be configurable */ -static int ifconfig(char *); #if 0 static int ifreconfig(char *); #endif @@ -99,14 +99,13 @@ static void TIMEVAL_SUB(struct timeval *, struct timeval *, struct timeval *); static void rtsold_set_dump_file(void); static void usage(char *); -static char **autoifprobe(void); int main(argc, argv) int argc; - char *argv[]; + char **argv; { - int s, maxfd, ch, once = 0, i; + int s, maxfd, ch, once = 0; struct timeval *timeout; char *argv0, *opts; fd_set fdset; @@ -155,23 +154,7 @@ main(argc, argv) argc -= optind; argv += optind; - if (aflag) { - if (argc != 0) { - usage(argv0); - /*NOTREACHED*/ - } - - argv = autoifprobe(); - if (!argv) { - errx(1, "could not autoprobe interface"); - /*NOTREACHED*/ - } - - for (i = 0; argv[i]; i++) - ; - argc = i; - } - if (argc == 0) { + if ((!aflag && argc == 0) || (aflag && argc != 0)) { usage(argv0); /*NOTREACHED*/ } @@ -241,7 +224,9 @@ main(argc, argv) exit(1); /*NOTREACHED*/ } - while (argc--) { + if (aflag) + argv = autoifprobe(); + while (argv && *argv) { if (ifconfig(*argv)) { warnmsg(LOG_ERR, __FUNCTION__, "failed to initialize %s", *argv); @@ -321,7 +306,7 @@ main(argc, argv) return 0; } -static int +int ifconfig(char *ifname) { struct ifinfo *ifinfo; @@ -354,6 +339,15 @@ ifconfig(char *ifname) if (make_packet(ifinfo)) goto bad; + /* set link ID of this interface. */ +#ifdef HAVE_SCOPELIB + if (inet_zoneid(AF_INET6, 2, ifname, &ifinfo->linkid)) + goto bad; +#else + /* XXX: assume interface IDs as link IDs */ + ifinfo->linkid = ifinfo->sdl->sdl_index; +#endif + /* * check if the interface is available. * also check if SIOCGIFMEDIA ioctl is OK on the interface. @@ -392,6 +386,22 @@ bad: return(-1); } +void +iflist_init() +{ + struct ifinfo *ifi, *next; + + for (ifi = iflist; ifi; ifi = next) { + next = ifi->next; + if (ifi->sdl) + free(ifi->sdl); + if (ifi->rs_data) + free(ifi->rs_data); + free(ifi); + iflist = NULL; + } +} + #if 0 static int ifreconfig(char *ifname) @@ -525,7 +535,7 @@ rtsol_check_timer() } if (probe && mobile_node) - defrouter_probe(ifinfo->sdl->sdl_index); + defrouter_probe(ifinfo); break; } case IFS_DELAY: @@ -717,16 +727,30 @@ warnmsg(int priority, const char *func, const char *msg, ...) va_end(ap); } -static char ** +/* + * return a list of interfaces which is suitable to sending an RS. + */ +char ** autoifprobe() { #ifndef HAVE_GETIFADDRS errx(1, "-a is not available with the configuration"); #else - static char ifname[IFNAMSIZ + 1]; - static char *argv[2]; + static char **argv = NULL; + static int n = 0; + char **a; + int i, found; struct ifaddrs *ifap, *ifa, *target; + /* initialize */ + while (n--) + free(argv[n]); + if (argv) { + free(argv); + argv = NULL; + } + n = 0; + if (getifaddrs(&ifap) != 0) return NULL; @@ -745,33 +769,44 @@ autoifprobe() if (ifa->ifa_addr->sa_family != AF_INET6) continue; - if (target && strcmp(target->ifa_name, ifa->ifa_name) == 0) + found = 0; + for (i = 0; i < n; i++) { + if (strcmp(argv[i], ifa->ifa_name) == 0) { + found++; + break; + } + } + if (found) continue; - if (!target) - target = ifa; - else { - /* if we find multiple candidates, failure. */ - if (dflag > 1) - warnx("multiple interfaces found"); - target = NULL; - break; - } + /* if we find multiple candidates, just warn. */ + if (n != 0 && dflag > 1) + warnx("multiple interfaces found"); + + a = (char **)realloc(argv, (n + 1) * sizeof(char **)); + if (a == NULL) + err(1, "realloc"); + argv = a; + argv[n] = (char *)malloc(1 + strlen(ifa->ifa_name)); + if (!argv[n]) + err(1, "malloc"); + strcpy(argv[n], ifa->ifa_name); + n++; } - if (target) { - strncpy(ifname, target->ifa_name, sizeof(ifname) - 1); - ifname[sizeof(ifname) - 1] = '\0'; - argv[0] = ifname; - argv[1] = NULL; + if (n) { + a = (char **)realloc(argv, (n + 1) * sizeof(char **)); + if (a == NULL) + err(1, "realloc"); + argv = a; + argv[n] = NULL; - if (dflag > 0) - warnx("probing %s", argv[0]); + if (dflag > 0) { + for (i = 0; i < n; i++) + warnx("probing %s", argv[i]); + } } freeifaddrs(ifap); - if (target) - return argv; - else - return (char **)NULL; + return argv; #endif } diff --git a/usr.sbin/rtsold/rtsold.h b/usr.sbin/rtsold/rtsold.h index 3e4c22cf484..af03c4236a0 100644 --- a/usr.sbin/rtsold/rtsold.h +++ b/usr.sbin/rtsold/rtsold.h @@ -1,5 +1,5 @@ -/* $OpenBSD: rtsold.h,v 1.9 2002/05/31 10:11:14 itojun Exp $ */ -/* $KAME: rtsold.h,v 1.11 2000/10/10 06:18:04 itojun Exp $ */ +/* $OpenBSD: rtsold.h,v 1.10 2002/05/31 21:24:28 itojun Exp $ */ +/* $KAME: rtsold.h,v 1.14 2002/05/31 10:10:03 itojun Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -35,6 +35,7 @@ struct ifinfo { struct sockaddr_dl *sdl; /* link-layer address */ char ifname[IF_NAMESIZE]; /* interface name */ + u_int32_t linkid; /* link ID of this interface */ int active; /* interface status */ int probeinterval; /* interval of probe timer(if necessary) */ int probetimer; /* rest of probe timer */ @@ -66,6 +67,7 @@ struct ifinfo *find_ifinfo(int ifindex); void rtsol_timer_update(struct ifinfo *); extern void warnmsg(int, const char *, const char *, ...) __attribute__((__format__(__printf__, 3, 4))); +extern char **autoifprobe(void); /* if.c */ extern int ifinit(void); @@ -83,7 +85,7 @@ extern void rtsol_input(int); /* probe.c */ extern int probe_init(void); -extern void defrouter_probe(int); +extern void defrouter_probe(struct ifinfo *); /* dump.c */ extern void rtsold_dump_file(char *); |