diff options
author | Jun-ichiro itojun Hagino <itojun@cvs.openbsd.org> | 1999-12-08 07:55:55 +0000 |
---|---|---|
committer | Jun-ichiro itojun Hagino <itojun@cvs.openbsd.org> | 1999-12-08 07:55:55 +0000 |
commit | 3f3fff9f5d68aa1319f0503da06f65782885c777 (patch) | |
tree | 625b58ff7997b30ca99f4b8299f31be78a051d0c /sbin/route | |
parent | 10263d773d79045708f7f3f2d633e99293387ff2 (diff) |
ipv6 support from KAME (needs no libc upgrade). regen keywords.[ch].
Diffstat (limited to 'sbin/route')
-rw-r--r-- | sbin/route/Makefile | 4 | ||||
-rw-r--r-- | sbin/route/keywords.c | 4 | ||||
-rw-r--r-- | sbin/route/keywords.h | 58 | ||||
-rw-r--r-- | sbin/route/keywords.sh | 4 | ||||
-rw-r--r-- | sbin/route/route.8 | 21 | ||||
-rw-r--r-- | sbin/route/route.c | 128 | ||||
-rw-r--r-- | sbin/route/show.c | 24 |
7 files changed, 201 insertions, 42 deletions
diff --git a/sbin/route/Makefile b/sbin/route/Makefile index dc3d47d2ba6..ed8c3caa26e 100644 --- a/sbin/route/Makefile +++ b/sbin/route/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.5 1997/12/12 09:04:32 deraadt Exp $ +# $OpenBSD: Makefile,v 1.6 1999/12/08 07:55:54 itojun Exp $ PROG= route MAN= route.8 @@ -6,6 +6,8 @@ SRCS= route.c show.c keywords.c ccitt_addr.c BINOWN= root BINMODE=555 +CPPFLAGS+= -DINET6 + route.o .depend lint tags: keywords.h .include <bsd.prog.mk> diff --git a/sbin/route/keywords.c b/sbin/route/keywords.c index 598b63b0677..d132e5295ba 100644 --- a/sbin/route/keywords.c +++ b/sbin/route/keywords.c @@ -1,4 +1,4 @@ -/* $OpenBSD: keywords.c,v 1.4 1997/08/26 13:49:36 niklas Exp $ */ +/* $OpenBSD: keywords.c,v 1.5 1999/12/08 07:55:54 itojun Exp $ */ /* WARNING! This file was generated by keywords.sh */ @@ -25,6 +25,7 @@ struct keytab keywords[] = { {"ifa", K_IFA}, {"ifp", K_IFP}, {"inet", K_INET}, + {"inet6", K_INET6}, {"ipx", K_IPX}, {"iso", K_ISO}, {"link", K_LINK}, @@ -38,6 +39,7 @@ struct keytab keywords[] = { {"netmask", K_NETMASK}, {"nostatic", K_NOSTATIC}, {"osi", K_OSI}, + {"prefixlen", K_PREFIXLEN}, {"proto1", K_PROTO1}, {"proto2", K_PROTO2}, {"recvpipe", K_RECVPIPE}, diff --git a/sbin/route/keywords.h b/sbin/route/keywords.h index 83775decc15..95263dd00c5 100644 --- a/sbin/route/keywords.h +++ b/sbin/route/keywords.h @@ -1,4 +1,4 @@ -/* $OpenBSD: keywords.h,v 1.4 1997/08/26 13:49:36 niklas Exp $ */ +/* $OpenBSD: keywords.h,v 1.5 1999/12/08 07:55:54 itojun Exp $ */ /* WARNING! This file was generated by keywords.sh */ @@ -27,30 +27,32 @@ extern struct keytab { #define K_IFA 17 #define K_IFP 18 #define K_INET 19 -#define K_IPX 20 -#define K_ISO 21 -#define K_LINK 22 -#define K_LLINFO 23 -#define K_LOCK 24 -#define K_LOCKREST 25 -#define K_MASK 26 -#define K_MONITOR 27 -#define K_MTU 28 -#define K_NET 29 -#define K_NETMASK 30 -#define K_NOSTATIC 31 -#define K_OSI 32 -#define K_PROTO1 33 -#define K_PROTO2 34 -#define K_RECVPIPE 35 -#define K_REJECT 36 -#define K_RTT 37 -#define K_RTTVAR 38 -#define K_SA 39 -#define K_SENDPIPE 40 -#define K_SHOW 41 -#define K_SSTHRESH 42 -#define K_STATIC 43 -#define K_X25 44 -#define K_XNS 45 -#define K_XRESOLVE 46 +#define K_INET6 20 +#define K_IPX 21 +#define K_ISO 22 +#define K_LINK 23 +#define K_LLINFO 24 +#define K_LOCK 25 +#define K_LOCKREST 26 +#define K_MASK 27 +#define K_MONITOR 28 +#define K_MTU 29 +#define K_NET 30 +#define K_NETMASK 31 +#define K_NOSTATIC 32 +#define K_OSI 33 +#define K_PREFIXLEN 34 +#define K_PROTO1 35 +#define K_PROTO2 36 +#define K_RECVPIPE 37 +#define K_REJECT 38 +#define K_RTT 39 +#define K_RTTVAR 40 +#define K_SA 41 +#define K_SENDPIPE 42 +#define K_SHOW 43 +#define K_SSTHRESH 44 +#define K_STATIC 45 +#define K_X25 46 +#define K_XNS 47 +#define K_XRESOLVE 48 diff --git a/sbin/route/keywords.sh b/sbin/route/keywords.sh index 5f53fdb93b4..c77269d3721 100644 --- a/sbin/route/keywords.sh +++ b/sbin/route/keywords.sh @@ -1,5 +1,5 @@ #!/bin/sh -# $OpenBSD: keywords.sh,v 1.3 1997/08/26 13:49:37 niklas Exp $ +# $OpenBSD: keywords.sh,v 1.4 1999/12/08 07:55:54 itojun Exp $ # $NetBSD: keywords.sh,v 1.2 1996/11/15 18:57:21 gwr Exp $ # @(#)keywords 8.2 (Berkeley) 3/19/94 # @@ -28,6 +28,7 @@ interface ifa ifp inet +inet6 ipx iso link @@ -41,6 +42,7 @@ net netmask nostatic osi +prefixlen proto1 proto2 recvpipe diff --git a/sbin/route/route.8 b/sbin/route/route.8 index 360f2de398c..ff8afcc1e6b 100644 --- a/sbin/route/route.8 +++ b/sbin/route/route.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: route.8,v 1.18 1999/07/29 22:14:33 ho Exp $ +.\" $OpenBSD: route.8,v 1.19 1999/12/08 07:55:54 itojun Exp $ .\" $NetBSD: route.8,v 1.6 1995/03/18 15:00:13 cgd Exp $ .\" .\" Copyright (c) 1983, 1991, 1993 @@ -133,8 +133,9 @@ When the address family is specified by any of the .Fl link, .Fl encap , .Fl x25 , +.Fl inet , or -.Fl inet +.Fl inet6 modifiers, only routes having destinations with addresses in the delineated family will be deleted. .Pp @@ -229,6 +230,8 @@ The implicit network mask generated in the .Dv AF_INET case can be overridden by making sure this option follows the destination parameter. +.Fl prefixlen +is also available for similar purpose, in IPv6 case. .Pp Routes have associated flags which influence operation of the protocols when sending to destinations matched by the routes. @@ -347,7 +350,21 @@ The .Nm command appeared in .Bx 4.2 . +IPv6 support was added by WIDE/KAME project. .Sh BUGS The first paragraph may have slightly exaggerated .Xr routed Ns 's abilities. +.Pp +Some uses of the +.Fl ifa +or +.Fl ifp +modifiers with the add command will incorrectly fail with a +.Dq Network is unreachable +message if there is no default route. +See case +.Dv RTM_ADD +in +.Pa sys/net/rtsock.c:route_output +for details. diff --git a/sbin/route/route.c b/sbin/route/route.c index be75771aaa5..79e6decb455 100644 --- a/sbin/route/route.c +++ b/sbin/route/route.c @@ -1,4 +1,4 @@ -/* $OpenBSD: route.c,v 1.34 1999/09/22 05:10:04 deraadt Exp $ */ +/* $OpenBSD: route.c,v 1.35 1999/12/08 07:55:54 itojun Exp $ */ /* $NetBSD: route.c,v 1.16 1996/04/15 18:27:05 cgd Exp $ */ /* @@ -44,7 +44,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)route.c 8.3 (Berkeley) 3/19/94"; #else -static char rcsid[] = "$OpenBSD: route.c,v 1.34 1999/09/22 05:10:04 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: route.c,v 1.35 1999/12/08 07:55:54 itojun Exp $"; #endif #endif /* not lint */ @@ -79,6 +79,9 @@ static char rcsid[] = "$OpenBSD: route.c,v 1.34 1999/09/22 05:10:04 deraadt Exp union sockunion { struct sockaddr sa; struct sockaddr_in sin; +#ifdef INET6 + struct sockaddr_in6 sin6; +#endif struct sockaddr_ns sns; struct sockaddr_ipx sipx; struct sockaddr_iso siso; @@ -101,6 +104,9 @@ char *netname __P((struct sockaddr *)); void flushroutes __P((int, char **)); void newroute __P((int, char **)); void monitor __P((void)); +#ifdef INET6 +static int prefixlen __P((char *)); +#endif void sockaddr __P((char *, struct sockaddr *)); void sodump __P((sup, char *)); void print_getmsg __P((struct rt_msghdr *, int)); @@ -245,6 +251,11 @@ flushroutes(argc, argv) case K_INET: af = AF_INET; break; +#ifdef INET6 + case K_INET6: + af = AF_INET6; + break; +#endif case K_XNS: af = AF_NS; break; @@ -373,6 +384,9 @@ routename(sa) struct in_addr ina; char *ns_print(); char *ipx_print(); +#ifdef INET6 + static char ntop_buf[NI_MAXHOST]; /*for inet_ntop()*/ +#endif if (first) { first = 0; @@ -408,6 +422,19 @@ routename(sa) break; } +#ifdef INET6 + case AF_INET6: + { struct in6_addr in6; + int gap; + + in6 = ((struct sockaddr_in6 *)sa)->sin6_addr; + gap = 24 - sa->sa_len; + if (gap > 0) + bzero((char *)(&in6 + 1) - gap, gap); + return ((char *)inet_ntop(AF_INET6, &in6, ntop_buf, sizeof(ntop_buf))); + } +#endif + case AF_NS: return (ns_print((struct sockaddr_ns *)sa)); @@ -444,6 +471,9 @@ netname(sa) in_addr_t net, mask, subnetshift; char *ns_print(); char *ipx_print(); +#ifdef INET6 + static char ntop_buf[NI_MAXHOST]; /*for inet_ntop()*/ +#endif switch (sa->sa_family) { @@ -486,6 +516,19 @@ netname(sa) break; } +#ifdef INET6 + case AF_INET6: + { struct in6_addr in6; + int gap; + + in6 = ((struct sockaddr_in6 *)sa)->sin6_addr; + gap = 24 - sa->sa_len; + if (gap > 0) + bzero((char *)(&in6 + 1) - gap, gap); + return ((char *)inet_ntop(AF_INET6, &in6, ntop_buf, sizeof(ntop_buf))); + } +#endif + case AF_NS: return (ns_print((struct sockaddr_ns *)sa)); @@ -568,6 +611,12 @@ newroute(argc, argv) af = AF_INET; aflen = sizeof(struct sockaddr_in); break; +#ifdef INET6 + case K_INET6: + af = AF_INET6; + aflen = sizeof(struct sockaddr_in6); + break; +#endif case K_X25: af = AF_CCITT; aflen = sizeof(struct sockaddr_x25); @@ -658,6 +707,18 @@ newroute(argc, argv) case K_NET: forcenet++; break; +#ifdef INET6 + case K_PREFIXLEN: + argc--; + if (prefixlen(*++argv) == 128) { + forcenet = 0; + ishost = 1; + } else { + forcenet = 1; + ishost = 0; + } + break; +#endif case K_MTU: case K_HOPCOUNT: case K_EXPIRE: @@ -823,20 +884,20 @@ getaddr(which, s, hpp) struct netent *np; u_long val; char *q, qs; + int afamily; if (af == 0) { af = AF_INET; aflen = sizeof(struct sockaddr_in); } + afamily = af; /* local copy of af so we can change it */ rtm_addrs |= which; switch (which) { case RTA_DST: su = &so_dst; - su->sa.sa_family = af; break; case RTA_GATEWAY: su = &so_gate; - su->sa.sa_family = af; break; case RTA_NETMASK: su = &so_mask; @@ -846,7 +907,7 @@ getaddr(which, s, hpp) break; case RTA_IFP: su = &so_ifp; - su->sa.sa_family = af; + afamily = AF_LINK; break; case RTA_IFA: su = &so_ifa; @@ -857,6 +918,7 @@ getaddr(which, s, hpp) /*NOTREACHED*/ } su->sa.sa_len = aflen; + su->sa.sa_family = afamily; /* cases that don't want it have left already */ if (strcmp(s, "default") == 0) { switch (which) { case RTA_DST: @@ -869,7 +931,16 @@ getaddr(which, s, hpp) } return (0); } - switch (af) { + switch (afamily) { +#ifdef INET6 + case AF_INET6: + if (inet_pton(AF_INET6, s, (void *)&su->sin6.sin6_addr) != 1) { + (void) fprintf(stderr, "%s: bad value\n", s); + exit(1); + } + return 0; +#endif + case AF_NS: if (which == RTA_DST) { extern short ns_bh[3]; @@ -971,6 +1042,33 @@ netdone: exit(1); } +#ifdef INET6 +int +prefixlen(s) + char *s; +{ + int len = atoi(s), q, r; + + rtm_addrs |= RTA_NETMASK; + if (len < -1 || len > 129) { + (void) fprintf(stderr, "%s: bad value\n", s); + exit(1); + } + + q = len >> 3; + r = len & 7; + so_mask.sin6.sin6_family = AF_INET6; + so_mask.sin6.sin6_len = sizeof(struct sockaddr_in6); + memset((void *)&so_mask.sin6.sin6_addr, 0, + sizeof(so_mask.sin6.sin6_addr)); + if (q > 0) + memset((void *)&so_mask.sin6.sin6_addr, 0xff, q); + if (r > 0) + *((u_char *)&so_mask.sin6.sin6_addr + q) = (0xff00 >> r) & 0xff; + return(len); +} +#endif + int x25_makemask() { @@ -1122,8 +1220,10 @@ monitor() exit(0); } for(;;) { + time_t now; n = read(s, msg, 2048); - (void) printf("got message of size %d\n", n); + now = time(NULL); + (void) printf("got message of size %d on %s", n, ctime(&now)); print_rtmsg((struct rt_msghdr *)msg, n); } } @@ -1221,6 +1321,9 @@ mask_addr() case AF_NS: case AF_IPX: case AF_INET: +#ifdef INET6 + case AF_INET6: +#endif case AF_CCITT: case 0: return; @@ -1486,6 +1589,10 @@ sodump(su, which) register sup su; char *which; { +#ifdef INET6 + char ntop_buf[NI_MAXHOST]; /*for inet_ntop()*/ +#endif + switch (su->sa.sa_family) { case AF_LINK: (void) printf("%s: link %s; ", @@ -1499,6 +1606,13 @@ sodump(su, which) (void) printf("%s: inet %s; ", which, inet_ntoa(su->sin.sin_addr)); break; +#ifdef INET6 + case AF_INET6: + (void) printf("%s: inet6 %s; ", + which, inet_ntop(AF_INET6, &su->sin6.sin6_addr, + ntop_buf, sizeof(ntop_buf))); + break; +#endif case AF_NS: (void) printf("%s: xns %s; ", which, ns_ntoa(su->sns.sns_addr)); diff --git a/sbin/route/show.c b/sbin/route/show.c index 237a10ecd36..5dbd9e83703 100644 --- a/sbin/route/show.c +++ b/sbin/route/show.c @@ -1,4 +1,4 @@ -/* $OpenBSD: show.c,v 1.9 1999/09/22 05:10:04 deraadt Exp $ */ +/* $OpenBSD: show.c,v 1.10 1999/12/08 07:55:54 itojun Exp $ */ /* $NetBSD: show.c,v 1.1 1996/11/15 18:01:41 gwr Exp $ */ /* @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "from: @(#)route.c 8.3 (Berkeley) 3/9/94"; #else -static char *rcsid = "$OpenBSD: show.c,v 1.9 1999/09/22 05:10:04 deraadt Exp $"; +static char *rcsid = "$OpenBSD: show.c,v 1.10 1999/12/08 07:55:54 itojun Exp $"; #endif #endif /* not lint */ @@ -244,6 +244,11 @@ pr_family(af) case AF_INET: afname = "Internet"; break; +#ifdef INET6 + case AF_INET6: + afname = "Internet6"; + break; +#endif /* INET6 */ case AF_NS: afname = "XNS"; break; @@ -323,6 +328,21 @@ p_sockaddr(sa, flags, width) break; } +#ifdef INET6 + case AF_INET6: + { + struct sockaddr_in6 *sin = (struct sockaddr_in6 *)sa; + + cp = IN6_IS_ADDR_UNSPECIFIED(&sin->sin6_addr) ? "default" : + ((flags & RTF_HOST) ? + routename(sa) : netname(sa)); + /* make sure numeric address is not truncated */ + if (strchr(cp, ':') != NULL && strlen(cp) > width) + width = strlen(cp); + break; + } +#endif /* INET6 */ + case AF_NS: cp = ns_print((struct sockaddr_ns *)sa); break; |