Module Name: src
Committed By: roy
Date: Tue Jan 20 21:27:37 UTC 2015
Modified Files:
src/sys/netinet6: in6.h in6_src.c ip6_input.c ip6_output.c ip6_var.h
mld6.c
Log Message:
Add net.inet6.ip6.prefer_tempaddr sysctl knob so that we can prefer
IPv6 temporary addresses as the source address.
Fixes PR kern/47100 based on a patch by Dieter Roelants.
To generate a diff of this commit:
cvs rdiff -u -r1.81 -r1.82 src/sys/netinet6/in6.h
cvs rdiff -u -r1.55 -r1.56 src/sys/netinet6/in6_src.c
cvs rdiff -u -r1.149 -r1.150 src/sys/netinet6/ip6_input.c
cvs rdiff -u -r1.160 -r1.161 src/sys/netinet6/ip6_output.c
cvs rdiff -u -r1.63 -r1.64 src/sys/netinet6/ip6_var.h
cvs rdiff -u -r1.61 -r1.62 src/sys/netinet6/mld6.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/netinet6/in6.h
diff -u src/sys/netinet6/in6.h:1.81 src/sys/netinet6/in6.h:1.82
--- src/sys/netinet6/in6.h:1.81 Tue Dec 2 20:25:48 2014
+++ src/sys/netinet6/in6.h Tue Jan 20 21:27:36 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: in6.h,v 1.81 2014/12/02 20:25:48 christos Exp $ */
+/* $NetBSD: in6.h,v 1.82 2015/01/20 21:27:36 roy Exp $ */
/* $KAME: in6.h,v 1.83 2001/03/29 02:55:07 jinmei Exp $ */
/*
@@ -438,6 +438,8 @@ extern const struct in6_addr in6addr_lin
#define IPV6_TCLASS 61 /* int; send traffic class value */
#define IPV6_DONTFRAG 62 /* bool; disable IPv6 fragmentation */
+#define IPV6_PREFER_TEMPADDR 63 /* int; prefer temporary address as
+ * the sorce address */
/* to define items, should talk with KAME guys first, for *BSD compatibility */
#define IPV6_RTHDR_LOOSE 0 /* this hop need not be a neighbor. XXX old spec */
Index: src/sys/netinet6/in6_src.c
diff -u src/sys/netinet6/in6_src.c:1.55 src/sys/netinet6/in6_src.c:1.56
--- src/sys/netinet6/in6_src.c:1.55 Fri Sep 5 06:08:15 2014
+++ src/sys/netinet6/in6_src.c Tue Jan 20 21:27:36 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: in6_src.c,v 1.55 2014/09/05 06:08:15 matt Exp $ */
+/* $NetBSD: in6_src.c,v 1.56 2015/01/20 21:27:36 roy Exp $ */
/* $KAME: in6_src.c,v 1.159 2005/10/19 01:40:32 t-momose Exp $ */
/*
@@ -66,7 +66,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in6_src.c,v 1.55 2014/09/05 06:08:15 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6_src.c,v 1.56 2015/01/20 21:27:36 roy Exp $");
#include "opt_inet.h"
@@ -118,9 +118,7 @@ __KERNEL_RCSID(0, "$NetBSD: in6_src.c,v
#define ADDR_LABEL_NOTAPP (-1)
struct in6_addrpolicy defaultaddrpolicy;
-#ifdef notyet /* until introducing ND extensions and address selection */
int ip6_prefer_tempaddr = 0;
-#endif
static int selectroute(struct sockaddr_in6 *, struct ip6_pktopts *,
struct ip6_moptions *, struct route *, struct ifnet **,
@@ -184,9 +182,7 @@ in6_selectsrc(struct sockaddr_in6 *dstso
struct in6_addrpolicy *dst_policy = NULL, *best_policy = NULL;
u_int32_t odstzone;
int error;
-#ifdef notyet /* until introducing ND extensions and address selection */
int prefer_tempaddr;
-#endif
#if defined(MIP6) && NMIP > 0
u_int8_t ip6po_usecoa = 0;
#endif /* MIP6 && NMIP > 0 */
@@ -458,7 +454,6 @@ in6_selectsrc(struct sockaddr_in6 *dstso
* a sysctl variable, so that privacy conscious users can
* always prefer temporary addresses.
*/
-#ifdef notyet /* until introducing ND extensions and address selection */
if (opts == NULL ||
opts->ip6po_prefer_tempaddr == IP6PO_TEMPADDR_SYSTEM) {
prefer_tempaddr = ip6_prefer_tempaddr;
@@ -481,7 +476,6 @@ in6_selectsrc(struct sockaddr_in6 *dstso
else
REPLACE(7);
}
-#endif
/*
* Rule 8: prefer addresses on alive interfaces.
Index: src/sys/netinet6/ip6_input.c
diff -u src/sys/netinet6/ip6_input.c:1.149 src/sys/netinet6/ip6_input.c:1.150
--- src/sys/netinet6/ip6_input.c:1.149 Mon Jun 16 00:33:39 2014
+++ src/sys/netinet6/ip6_input.c Tue Jan 20 21:27:36 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: ip6_input.c,v 1.149 2014/06/16 00:33:39 ozaki-r Exp $ */
+/* $NetBSD: ip6_input.c,v 1.150 2015/01/20 21:27:36 roy Exp $ */
/* $KAME: ip6_input.c,v 1.188 2001/03/29 05:34:31 itojun Exp $ */
/*
@@ -62,7 +62,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.149 2014/06/16 00:33:39 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.150 2015/01/20 21:27:36 roy Exp $");
#include "opt_gateway.h"
#include "opt_inet.h"
@@ -1902,6 +1902,14 @@ sysctl_net_inet6_ip6_setup(struct sysctl
CTL_CREATE, CTL_EOL);
sysctl_createv(clog, 0, NULL, NULL,
CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
+ CTLTYPE_INT, "prefer_tempaddr",
+ SYSCTL_DESCR("Prefer temporary address as source "
+ "address"),
+ NULL, 0, &ip6_prefer_tempaddr, 0,
+ CTL_NET, PF_INET6, IPPROTO_IPV6,
+ CTL_CREATE, CTL_EOL);
+ sysctl_createv(clog, 0, NULL, NULL,
+ CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
CTLTYPE_INT, "temppltime",
SYSCTL_DESCR("preferred lifetime of a temporary address"),
NULL, 0, &ip6_temp_preferred_lifetime, 0,
Index: src/sys/netinet6/ip6_output.c
diff -u src/sys/netinet6/ip6_output.c:1.160 src/sys/netinet6/ip6_output.c:1.161
--- src/sys/netinet6/ip6_output.c:1.160 Sun Oct 12 19:00:21 2014
+++ src/sys/netinet6/ip6_output.c Tue Jan 20 21:27:36 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: ip6_output.c,v 1.160 2014/10/12 19:00:21 christos Exp $ */
+/* $NetBSD: ip6_output.c,v 1.161 2015/01/20 21:27:36 roy Exp $ */
/* $KAME: ip6_output.c,v 1.172 2001/03/25 09:55:56 itojun Exp $ */
/*
@@ -62,7 +62,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip6_output.c,v 1.160 2014/10/12 19:00:21 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_output.c,v 1.161 2015/01/20 21:27:36 roy Exp $");
#include "opt_inet.h"
#include "opt_inet6.h"
@@ -1529,6 +1529,7 @@ else \
case IPV6_TCLASS:
case IPV6_DONTFRAG:
case IPV6_USE_MIN_MTU:
+ case IPV6_PREFER_TEMPADDR:
error = sockopt_getint(sopt, &optval);
if (error)
break;
@@ -1851,6 +1852,7 @@ else \
case IPV6_TCLASS:
case IPV6_DONTFRAG:
case IPV6_USE_MIN_MTU:
+ case IPV6_PREFER_TEMPADDR:
error = ip6_getpcbopt(in6p->in6p_outputopts,
optname, sopt);
break;
@@ -2031,6 +2033,7 @@ ip6_initpktopts(struct ip6_pktopts *opt)
opt->ip6po_hlim = -1; /* -1 means default hop limit */
opt->ip6po_tclass = -1; /* -1 means default traffic class */
opt->ip6po_minmtu = IP6PO_MINMTU_MCASTONLY;
+ opt->ip6po_prefer_tempaddr = IP6PO_TEMPADDR_SYSTEM;
}
#define sin6tosa(sin6) ((struct sockaddr *)(sin6)) /* XXX */
@@ -2063,6 +2066,7 @@ ip6_getpcbopt(struct ip6_pktopts *pktopt
struct in6_pktinfo null_pktinfo;
int deftclass = 0, on;
int defminmtu = IP6PO_MINMTU_MCASTONLY;
+ int defpreftemp = IP6PO_TEMPADDR_SYSTEM;
switch (optname) {
case IPV6_PKTINFO:
@@ -2134,6 +2138,12 @@ ip6_getpcbopt(struct ip6_pktopts *pktopt
optdata = (void *)&on;
optdatalen = sizeof(on);
break;
+ case IPV6_PREFER_TEMPADDR:
+ if (pktopt)
+ optdata = (void *)&pktopt->ip6po_prefer_tempaddr;
+ else
+ optdata = (void *)&defpreftemp;
+ optdatalen = sizeof(int);
default: /* should not happen */
#ifdef DIAGNOSTIC
panic("ip6_getpcbopt: unexpected option\n");
@@ -2204,6 +2214,7 @@ copypktopts(struct ip6_pktopts *dst, str
dst->ip6po_hlim = src->ip6po_hlim;
dst->ip6po_tclass = src->ip6po_tclass;
dst->ip6po_flags = src->ip6po_flags;
+ dst->ip6po_prefer_tempaddr = src->ip6po_prefer_tempaddr;
if (src->ip6po_pktinfo) {
dst->ip6po_pktinfo = malloc(sizeof(*dst->ip6po_pktinfo),
M_IP6OPT, canwait);
@@ -2755,6 +2766,7 @@ ip6_setpktopt(int optname, u_char *buf,
case IPV6_DONTFRAG:
case IPV6_OTCLASS:
case IPV6_TCLASS:
+ case IPV6_PREFER_TEMPADDR: /* XXX not an RFC3542 option */
return (ENOPROTOOPT);
}
}
@@ -3088,6 +3100,25 @@ ip6_setpktopt(int optname, u_char *buf,
opt->ip6po_flags |= IP6PO_DONTFRAG;
break;
+ case IPV6_PREFER_TEMPADDR:
+ {
+ int preftemp;
+
+ if (len != sizeof(int))
+ return (EINVAL);
+ preftemp = *(int *)buf;
+ switch (preftemp) {
+ case IP6PO_TEMPADDR_SYSTEM:
+ case IP6PO_TEMPADDR_NOTPREFER:
+ case IP6PO_TEMPADDR_PREFER:
+ break;
+ default:
+ return (EINVAL);
+ }
+ opt->ip6po_prefer_tempaddr = preftemp;
+ break;
+ }
+
default:
return (ENOPROTOOPT);
} /* end of switch */
Index: src/sys/netinet6/ip6_var.h
diff -u src/sys/netinet6/ip6_var.h:1.63 src/sys/netinet6/ip6_var.h:1.64
--- src/sys/netinet6/ip6_var.h:1.63 Sun Oct 12 19:00:21 2014
+++ src/sys/netinet6/ip6_var.h Tue Jan 20 21:27:36 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: ip6_var.h,v 1.63 2014/10/12 19:00:21 christos Exp $ */
+/* $NetBSD: ip6_var.h,v 1.64 2015/01/20 21:27:36 roy Exp $ */
/* $KAME: ip6_var.h,v 1.33 2000/06/11 14:59:20 jinmei Exp $ */
/*
@@ -148,6 +148,11 @@ struct ip6_pktopts {
#define IP6PO_MINMTU_MCASTONLY -1 /* default; send at min MTU for multicast*/
#define IP6PO_MINMTU_DISABLE 0 /* always perform pmtu disc */
#define IP6PO_MINMTU_ALL 1 /* always send at min MTU */
+ int ip6po_prefer_tempaddr; /* whether temporary addresses are
+ * preferred as source address */
+#define IP6PO_TEMPADDR_SYSTEM -1 /* follow the system default */
+#define IP6PO_TEMPADDR_NOTPREFER 0 /* not prefer temporary address */
+#define IP6PO_TEMPADDR_PREFER 1 /* prefer temporary address */
int ip6po_flags;
#if 0 /* parameters in this block is obsolete. do not reuse the values. */
#define IP6PO_REACHCONF 0x01 /* upper-layer reachability confirmation. */
Index: src/sys/netinet6/mld6.c
diff -u src/sys/netinet6/mld6.c:1.61 src/sys/netinet6/mld6.c:1.62
--- src/sys/netinet6/mld6.c:1.61 Wed Nov 12 03:24:25 2014
+++ src/sys/netinet6/mld6.c Tue Jan 20 21:27:36 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: mld6.c,v 1.61 2014/11/12 03:24:25 ozaki-r Exp $ */
+/* $NetBSD: mld6.c,v 1.62 2015/01/20 21:27:36 roy Exp $ */
/* $KAME: mld6.c,v 1.25 2001/01/16 14:14:18 itojun Exp $ */
/*
@@ -102,7 +102,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mld6.c,v 1.61 2014/11/12 03:24:25 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mld6.c,v 1.62 2015/01/20 21:27:36 roy Exp $");
#include "opt_inet.h"
@@ -188,6 +188,7 @@ mld_init(void)
ip6_opts.ip6po_hbh = hbh;
/* We will specify the hoplimit by a multicast option. */
ip6_opts.ip6po_hlim = -1;
+ ip6_opts.ip6po_prefer_tempaddr = IP6PO_TEMPADDR_NOTPREFER;
}
static void