Module Name: src Committed By: martin Date: Fri Jan 23 09:27:15 UTC 2015
Modified Files: src/sys/netinet6 [netbsd-7]: in6.h in6_src.c ip6_input.c ip6_output.c ip6_var.h mld6.c Log Message: Pull up following revision(s) (requested by pettai in ticket #441): sys/netinet6/ip6_var.h: revision 1.64 sys/netinet6/in6.h: revision 1.82 sys/netinet6/in6_src.c: revision 1.56 sys/netinet6/mld6.c: revision 1.62 sys/netinet6/ip6_input.c: revision 1.150 sys/netinet6/ip6_output.c: revision 1.161 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.78 -r1.78.2.1 src/sys/netinet6/in6.h cvs rdiff -u -r1.54 -r1.54.2.1 src/sys/netinet6/in6_src.c cvs rdiff -u -r1.149 -r1.149.2.1 src/sys/netinet6/ip6_input.c cvs rdiff -u -r1.157.2.1 -r1.157.2.2 src/sys/netinet6/ip6_output.c cvs rdiff -u -r1.62 -r1.62.2.1 src/sys/netinet6/ip6_var.h cvs rdiff -u -r1.59.2.1 -r1.59.2.2 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.78 src/sys/netinet6/in6.h:1.78.2.1 --- src/sys/netinet6/in6.h:1.78 Thu Jun 5 23:48:16 2014 +++ src/sys/netinet6/in6.h Fri Jan 23 09:27:15 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: in6.h,v 1.78 2014/06/05 23:48:16 rmind Exp $ */ +/* $NetBSD: in6.h,v 1.78.2.1 2015/01/23 09:27:15 martin Exp $ */ /* $KAME: in6.h,v 1.83 2001/03/29 02:55:07 jinmei Exp $ */ /* @@ -437,6 +437,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.54 src/sys/netinet6/in6_src.c:1.54.2.1 --- src/sys/netinet6/in6_src.c:1.54 Sat May 17 21:26:20 2014 +++ src/sys/netinet6/in6_src.c Fri Jan 23 09:27:15 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: in6_src.c,v 1.54 2014/05/17 21:26:20 rmind Exp $ */ +/* $NetBSD: in6_src.c,v 1.54.2.1 2015/01/23 09:27:15 martin 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.54 2014/05/17 21:26:20 rmind Exp $"); +__KERNEL_RCSID(0, "$NetBSD: in6_src.c,v 1.54.2.1 2015/01/23 09:27:15 martin 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.149.2.1 --- src/sys/netinet6/ip6_input.c:1.149 Mon Jun 16 00:33:39 2014 +++ src/sys/netinet6/ip6_input.c Fri Jan 23 09:27:15 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.149.2.1 2015/01/23 09:27:15 martin 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.149.2.1 2015/01/23 09:27:15 martin 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.157.2.1 src/sys/netinet6/ip6_output.c:1.157.2.2 --- src/sys/netinet6/ip6_output.c:1.157.2.1 Sun Aug 24 08:34:58 2014 +++ src/sys/netinet6/ip6_output.c Fri Jan 23 09:27:15 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: ip6_output.c,v 1.157.2.1 2014/08/24 08:34:58 martin Exp $ */ +/* $NetBSD: ip6_output.c,v 1.157.2.2 2015/01/23 09:27:15 martin 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.157.2.1 2014/08/24 08:34:58 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ip6_output.c,v 1.157.2.2 2015/01/23 09:27:15 martin Exp $"); #include "opt_inet.h" #include "opt_inet6.h" @@ -1505,6 +1505,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; @@ -1827,6 +1828,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; @@ -2007,6 +2009,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 */ @@ -2039,6 +2042,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: @@ -2110,6 +2114,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"); @@ -2180,6 +2190,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); @@ -2704,6 +2715,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); } } @@ -3037,6 +3049,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.62 src/sys/netinet6/ip6_var.h:1.62.2.1 --- src/sys/netinet6/ip6_var.h:1.62 Thu Jun 5 23:48:16 2014 +++ src/sys/netinet6/ip6_var.h Fri Jan 23 09:27:15 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: ip6_var.h,v 1.62 2014/06/05 23:48:16 rmind Exp $ */ +/* $NetBSD: ip6_var.h,v 1.62.2.1 2015/01/23 09:27:15 martin 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.59.2.1 src/sys/netinet6/mld6.c:1.59.2.2 --- src/sys/netinet6/mld6.c:1.59.2.1 Mon Dec 29 17:33:49 2014 +++ src/sys/netinet6/mld6.c Fri Jan 23 09:27:15 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: mld6.c,v 1.59.2.1 2014/12/29 17:33:49 martin Exp $ */ +/* $NetBSD: mld6.c,v 1.59.2.2 2015/01/23 09:27:15 martin 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.59.2.1 2014/12/29 17:33:49 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: mld6.c,v 1.59.2.2 2015/01/23 09:27:15 martin 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