Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/netinet6 Add net.inet6.ip6.prefer_tempaddr sysctl knob s...



details:   https://anonhg.NetBSD.org/src/rev/0f494fc54c94
branches:  trunk
changeset: 805820:0f494fc54c94
user:      roy <roy%NetBSD.org@localhost>
date:      Tue Jan 20 21:27:36 2015 +0000

description:
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.

diffstat:

 sys/netinet6/in6.h        |   4 +++-
 sys/netinet6/in6_src.c    |  10 ++--------
 sys/netinet6/ip6_input.c  |  12 ++++++++++--
 sys/netinet6/ip6_output.c |  35 +++++++++++++++++++++++++++++++++--
 sys/netinet6/ip6_var.h    |   7 ++++++-
 sys/netinet6/mld6.c       |   5 +++--
 6 files changed, 57 insertions(+), 16 deletions(-)

diffs (257 lines):

diff -r e0d7a82f98d7 -r 0f494fc54c94 sys/netinet6/in6.h
--- a/sys/netinet6/in6.h        Tue Jan 20 20:43:10 2015 +0000
+++ b/sys/netinet6/in6.h        Tue Jan 20 21:27:36 2015 +0000
@@ -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 @@
 
 #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 */
diff -r e0d7a82f98d7 -r 0f494fc54c94 sys/netinet6/in6_src.c
--- a/sys/netinet6/in6_src.c    Tue Jan 20 20:43:10 2015 +0000
+++ b/sys/netinet6/in6_src.c    Tue Jan 20 21:27:36 2015 +0000
@@ -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 @@
 #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 @@
        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 @@
                 * 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 @@
                        else
                                REPLACE(7);
                }
-#endif
 
                /*
                 * Rule 8: prefer addresses on alive interfaces.
diff -r e0d7a82f98d7 -r 0f494fc54c94 sys/netinet6/ip6_input.c
--- a/sys/netinet6/ip6_input.c  Tue Jan 20 20:43:10 2015 +0000
+++ b/sys/netinet6/ip6_input.c  Tue Jan 20 21:27:36 2015 +0000
@@ -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 @@
                       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,
diff -r e0d7a82f98d7 -r 0f494fc54c94 sys/netinet6/ip6_output.c
--- a/sys/netinet6/ip6_output.c Tue Jan 20 20:43:10 2015 +0000
+++ b/sys/netinet6/ip6_output.c Tue Jan 20 21:27:36 2015 +0000
@@ -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 @@
                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 @@
                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 @@
        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 @@
        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 @@
                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 @@
        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 @@
                case IPV6_DONTFRAG:
                case IPV6_OTCLASS:
                case IPV6_TCLASS:
+               case IPV6_PREFER_TEMPADDR: /* XXX not an RFC3542 option */
                        return (ENOPROTOOPT);
                }
        }
@@ -3088,6 +3100,25 @@
                        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 */
diff -r e0d7a82f98d7 -r 0f494fc54c94 sys/netinet6/ip6_var.h
--- a/sys/netinet6/ip6_var.h    Tue Jan 20 20:43:10 2015 +0000
+++ b/sys/netinet6/ip6_var.h    Tue Jan 20 21:27:36 2015 +0000
@@ -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 @@
 #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. */
diff -r e0d7a82f98d7 -r 0f494fc54c94 sys/netinet6/mld6.c
--- a/sys/netinet6/mld6.c       Tue Jan 20 20:43:10 2015 +0000
+++ b/sys/netinet6/mld6.c       Tue Jan 20 21:27:36 2015 +0000
@@ -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 @@
        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



Home | Main Index | Thread Index | Old Index