Tue Jan 20 21:27:37 2015 UTC ()
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.


(roy)
diff -r1.81 -r1.82 src/sys/netinet6/in6.h
diff -r1.55 -r1.56 src/sys/netinet6/in6_src.c
diff -r1.149 -r1.150 src/sys/netinet6/ip6_input.c
diff -r1.160 -r1.161 src/sys/netinet6/ip6_output.c
diff -r1.63 -r1.64 src/sys/netinet6/ip6_var.h
diff -r1.61 -r1.62 src/sys/netinet6/mld6.c

cvs diff -r1.81 -r1.82 src/sys/netinet6/in6.h (expand / switch to unified diff)

--- src/sys/netinet6/in6.h 2014/12/02 20:25:48 1.81
+++ src/sys/netinet6/in6.h 2015/01/20 21:27:36 1.82
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: in6.h,v 1.81 2014/12/02 20:25:48 christos Exp $ */ 1/* $NetBSD: in6.h,v 1.82 2015/01/20 21:27:36 roy Exp $ */
2/* $KAME: in6.h,v 1.83 2001/03/29 02:55:07 jinmei Exp $ */ 2/* $KAME: in6.h,v 1.83 2001/03/29 02:55:07 jinmei Exp $ */
3 3
4/* 4/*
5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -428,26 +428,28 @@ extern const struct in6_addr in6addr_lin @@ -428,26 +428,28 @@ extern const struct in6_addr in6addr_lin
428#define IPV6_HOPLIMIT 47 /* int; send hop limit */ 428#define IPV6_HOPLIMIT 47 /* int; send hop limit */
429#define IPV6_NEXTHOP 48 /* sockaddr; next hop addr */ 429#define IPV6_NEXTHOP 48 /* sockaddr; next hop addr */
430#define IPV6_HOPOPTS 49 /* ip6_hbh; send hop-by-hop option */ 430#define IPV6_HOPOPTS 49 /* ip6_hbh; send hop-by-hop option */
431#define IPV6_DSTOPTS 50 /* ip6_dest; send dst option befor rthdr */ 431#define IPV6_DSTOPTS 50 /* ip6_dest; send dst option befor rthdr */
432#define IPV6_RTHDR 51 /* ip6_rthdr; send routing header */ 432#define IPV6_RTHDR 51 /* ip6_rthdr; send routing header */
433 433
434#define IPV6_RECVTCLASS 57 /* bool; recv traffic class values */ 434#define IPV6_RECVTCLASS 57 /* bool; recv traffic class values */
435#ifdef _KERNEL 435#ifdef _KERNEL
436#define IPV6_OTCLASS 58 /* u_int8_t; send traffic class value */ 436#define IPV6_OTCLASS 58 /* u_int8_t; send traffic class value */
437#endif 437#endif
438 438
439#define IPV6_TCLASS 61 /* int; send traffic class value */ 439#define IPV6_TCLASS 61 /* int; send traffic class value */
440#define IPV6_DONTFRAG 62 /* bool; disable IPv6 fragmentation */ 440#define IPV6_DONTFRAG 62 /* bool; disable IPv6 fragmentation */
 441#define IPV6_PREFER_TEMPADDR 63 /* int; prefer temporary address as
 442 * the sorce address */
441/* to define items, should talk with KAME guys first, for *BSD compatibility */ 443/* to define items, should talk with KAME guys first, for *BSD compatibility */
442 444
443#define IPV6_RTHDR_LOOSE 0 /* this hop need not be a neighbor. XXX old spec */ 445#define IPV6_RTHDR_LOOSE 0 /* this hop need not be a neighbor. XXX old spec */
444#define IPV6_RTHDR_STRICT 1 /* this hop must be a neighbor. XXX old spec */ 446#define IPV6_RTHDR_STRICT 1 /* this hop must be a neighbor. XXX old spec */
445#define IPV6_RTHDR_TYPE_0 0 /* IPv6 routing header type 0 */ 447#define IPV6_RTHDR_TYPE_0 0 /* IPv6 routing header type 0 */
446 448
447/* 449/*
448 * Defaults and limits for options 450 * Defaults and limits for options
449 */ 451 */
450#define IPV6_DEFAULT_MULTICAST_HOPS 1 /* normally limit m'casts to 1 hop */ 452#define IPV6_DEFAULT_MULTICAST_HOPS 1 /* normally limit m'casts to 1 hop */
451#define IPV6_DEFAULT_MULTICAST_LOOP 1 /* normally hear sends if a member */ 453#define IPV6_DEFAULT_MULTICAST_LOOP 1 /* normally hear sends if a member */
452 454
453/* 455/*

cvs diff -r1.55 -r1.56 src/sys/netinet6/in6_src.c (expand / switch to unified diff)

--- src/sys/netinet6/in6_src.c 2014/09/05 06:08:15 1.55
+++ src/sys/netinet6/in6_src.c 2015/01/20 21:27:36 1.56
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: in6_src.c,v 1.55 2014/09/05 06:08:15 matt Exp $ */ 1/* $NetBSD: in6_src.c,v 1.56 2015/01/20 21:27:36 roy Exp $ */
2/* $KAME: in6_src.c,v 1.159 2005/10/19 01:40:32 t-momose Exp $ */ 2/* $KAME: in6_src.c,v 1.159 2005/10/19 01:40:32 t-momose Exp $ */
3 3
4/* 4/*
5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -56,27 +56,27 @@ @@ -56,27 +56,27 @@
56 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 56 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
57 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 57 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
58 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 58 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
59 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 59 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
60 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 60 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
61 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 61 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
62 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 62 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63 * SUCH DAMAGE. 63 * SUCH DAMAGE.
64 * 64 *
65 * @(#)in_pcb.c 8.2 (Berkeley) 1/4/94 65 * @(#)in_pcb.c 8.2 (Berkeley) 1/4/94
66 */ 66 */
67 67
68#include <sys/cdefs.h> 68#include <sys/cdefs.h>
69__KERNEL_RCSID(0, "$NetBSD: in6_src.c,v 1.55 2014/09/05 06:08:15 matt Exp $"); 69__KERNEL_RCSID(0, "$NetBSD: in6_src.c,v 1.56 2015/01/20 21:27:36 roy Exp $");
70 70
71#include "opt_inet.h" 71#include "opt_inet.h"
72 72
73#include <sys/param.h> 73#include <sys/param.h>
74#include <sys/systm.h> 74#include <sys/systm.h>
75#include <sys/malloc.h> 75#include <sys/malloc.h>
76#include <sys/mbuf.h> 76#include <sys/mbuf.h>
77#include <sys/protosw.h> 77#include <sys/protosw.h>
78#include <sys/socket.h> 78#include <sys/socket.h>
79#include <sys/socketvar.h> 79#include <sys/socketvar.h>
80#include <sys/ioctl.h> 80#include <sys/ioctl.h>
81#include <sys/errno.h> 81#include <sys/errno.h>
82#include <sys/time.h> 82#include <sys/time.h>
@@ -108,29 +108,27 @@ __KERNEL_RCSID(0, "$NetBSD: in6_src.c,v  @@ -108,29 +108,27 @@ __KERNEL_RCSID(0, "$NetBSD: in6_src.c,v
108#include <netinet6/mip6.h> 108#include <netinet6/mip6.h>
109#include <netinet6/mip6_var.h> 109#include <netinet6/mip6_var.h>
110#include "mip.h" 110#include "mip.h"
111#if NMIP > 0 111#if NMIP > 0
112#include <net/if_mip.h> 112#include <net/if_mip.h>
113#endif /* NMIP > 0 */ 113#endif /* NMIP > 0 */
114#endif /* MIP6 */ 114#endif /* MIP6 */
115 115
116#include <netinet/tcp_vtw.h> 116#include <netinet/tcp_vtw.h>
117 117
118#define ADDR_LABEL_NOTAPP (-1) 118#define ADDR_LABEL_NOTAPP (-1)
119struct in6_addrpolicy defaultaddrpolicy; 119struct in6_addrpolicy defaultaddrpolicy;
120 120
121#ifdef notyet /* until introducing ND extensions and address selection */ 
122int ip6_prefer_tempaddr = 0; 121int ip6_prefer_tempaddr = 0;
123#endif 
124 122
125static int selectroute(struct sockaddr_in6 *, struct ip6_pktopts *, 123static int selectroute(struct sockaddr_in6 *, struct ip6_pktopts *,
126 struct ip6_moptions *, struct route *, struct ifnet **, 124 struct ip6_moptions *, struct route *, struct ifnet **,
127 struct rtentry **, int, int); 125 struct rtentry **, int, int);
128static int in6_selectif(struct sockaddr_in6 *, struct ip6_pktopts *, 126static int in6_selectif(struct sockaddr_in6 *, struct ip6_pktopts *,
129 struct ip6_moptions *, struct route *, struct ifnet **); 127 struct ip6_moptions *, struct route *, struct ifnet **);
130 128
131static struct in6_addrpolicy *lookup_addrsel_policy(struct sockaddr_in6 *); 129static struct in6_addrpolicy *lookup_addrsel_policy(struct sockaddr_in6 *);
132 130
133static void init_policy_queue(void); 131static void init_policy_queue(void);
134static int add_addrsel_policyent(struct in6_addrpolicy *); 132static int add_addrsel_policyent(struct in6_addrpolicy *);
135static int delete_addrsel_policyent(struct in6_addrpolicy *); 133static int delete_addrsel_policyent(struct in6_addrpolicy *);
136static int walk_addrsel_policy(int (*)(struct in6_addrpolicy *, void *), 134static int walk_addrsel_policy(int (*)(struct in6_addrpolicy *, void *),
@@ -174,29 +172,27 @@ static struct in6_addrpolicy *match_addr @@ -174,29 +172,27 @@ static struct in6_addrpolicy *match_addr
174struct in6_addr * 172struct in6_addr *
175in6_selectsrc(struct sockaddr_in6 *dstsock, struct ip6_pktopts *opts,  173in6_selectsrc(struct sockaddr_in6 *dstsock, struct ip6_pktopts *opts,
176 struct ip6_moptions *mopts, struct route *ro, struct in6_addr *laddr,  174 struct ip6_moptions *mopts, struct route *ro, struct in6_addr *laddr,
177 struct ifnet **ifpp, int *errorp) 175 struct ifnet **ifpp, int *errorp)
178{ 176{
179 struct in6_addr dst; 177 struct in6_addr dst;
180 struct ifnet *ifp = NULL; 178 struct ifnet *ifp = NULL;
181 struct in6_ifaddr *ia = NULL, *ia_best = NULL; 179 struct in6_ifaddr *ia = NULL, *ia_best = NULL;
182 struct in6_pktinfo *pi = NULL; 180 struct in6_pktinfo *pi = NULL;
183 int dst_scope = -1, best_scope = -1, best_matchlen = -1; 181 int dst_scope = -1, best_scope = -1, best_matchlen = -1;
184 struct in6_addrpolicy *dst_policy = NULL, *best_policy = NULL; 182 struct in6_addrpolicy *dst_policy = NULL, *best_policy = NULL;
185 u_int32_t odstzone; 183 u_int32_t odstzone;
186 int error; 184 int error;
187#ifdef notyet /* until introducing ND extensions and address selection */ 
188 int prefer_tempaddr; 185 int prefer_tempaddr;
189#endif 
190#if defined(MIP6) && NMIP > 0 186#if defined(MIP6) && NMIP > 0
191 u_int8_t ip6po_usecoa = 0; 187 u_int8_t ip6po_usecoa = 0;
192#endif /* MIP6 && NMIP > 0 */ 188#endif /* MIP6 && NMIP > 0 */
193 189
194 dst = dstsock->sin6_addr; /* make a copy for local operation */ 190 dst = dstsock->sin6_addr; /* make a copy for local operation */
195 *errorp = 0; 191 *errorp = 0;
196 if (ifpp) 192 if (ifpp)
197 *ifpp = NULL; 193 *ifpp = NULL;
198 194
199 /* 195 /*
200 * Try to determine the outgoing interface for the given destination. 196 * Try to determine the outgoing interface for the given destination.
201 * We do this regardless of whether the socket is bound, since the 197 * We do this regardless of whether the socket is bound, since the
202 * caller may need this information as a side effect of the call 198 * caller may need this information as a side effect of the call
@@ -448,50 +444,48 @@ in6_selectsrc(struct sockaddr_in6 *dstso @@ -448,50 +444,48 @@ in6_selectsrc(struct sockaddr_in6 *dstso
448 dst_policy->label != new_policy->label) 444 dst_policy->label != new_policy->label)
449 NEXT(6); 445 NEXT(6);
450 if (dst_policy->label != best_policy->label && 446 if (dst_policy->label != best_policy->label &&
451 dst_policy->label == new_policy->label) 447 dst_policy->label == new_policy->label)
452 REPLACE(6); 448 REPLACE(6);
453 } 449 }
454 450
455 /* 451 /*
456 * Rule 7: Prefer public addresses. 452 * Rule 7: Prefer public addresses.
457 * We allow users to reverse the logic by configuring 453 * We allow users to reverse the logic by configuring
458 * a sysctl variable, so that privacy conscious users can 454 * a sysctl variable, so that privacy conscious users can
459 * always prefer temporary addresses. 455 * always prefer temporary addresses.
460 */ 456 */
461#ifdef notyet /* until introducing ND extensions and address selection */ 
462 if (opts == NULL || 457 if (opts == NULL ||
463 opts->ip6po_prefer_tempaddr == IP6PO_TEMPADDR_SYSTEM) { 458 opts->ip6po_prefer_tempaddr == IP6PO_TEMPADDR_SYSTEM) {
464 prefer_tempaddr = ip6_prefer_tempaddr; 459 prefer_tempaddr = ip6_prefer_tempaddr;
465 } else if (opts->ip6po_prefer_tempaddr == 460 } else if (opts->ip6po_prefer_tempaddr ==
466 IP6PO_TEMPADDR_NOTPREFER) { 461 IP6PO_TEMPADDR_NOTPREFER) {
467 prefer_tempaddr = 0; 462 prefer_tempaddr = 0;
468 } else 463 } else
469 prefer_tempaddr = 1; 464 prefer_tempaddr = 1;
470 if (!(ia_best->ia6_flags & IN6_IFF_TEMPORARY) && 465 if (!(ia_best->ia6_flags & IN6_IFF_TEMPORARY) &&
471 (ia->ia6_flags & IN6_IFF_TEMPORARY)) { 466 (ia->ia6_flags & IN6_IFF_TEMPORARY)) {
472 if (prefer_tempaddr) 467 if (prefer_tempaddr)
473 REPLACE(7); 468 REPLACE(7);
474 else 469 else
475 NEXT(7); 470 NEXT(7);
476 } 471 }
477 if ((ia_best->ia6_flags & IN6_IFF_TEMPORARY) && 472 if ((ia_best->ia6_flags & IN6_IFF_TEMPORARY) &&
478 !(ia->ia6_flags & IN6_IFF_TEMPORARY)) { 473 !(ia->ia6_flags & IN6_IFF_TEMPORARY)) {
479 if (prefer_tempaddr) 474 if (prefer_tempaddr)
480 NEXT(7); 475 NEXT(7);
481 else 476 else
482 REPLACE(7); 477 REPLACE(7);
483 } 478 }
484#endif 
485 479
486 /* 480 /*
487 * Rule 8: prefer addresses on alive interfaces. 481 * Rule 8: prefer addresses on alive interfaces.
488 * This is a KAME specific rule. 482 * This is a KAME specific rule.
489 */ 483 */
490 if ((ia_best->ia_ifp->if_flags & IFF_UP) && 484 if ((ia_best->ia_ifp->if_flags & IFF_UP) &&
491 !(ia->ia_ifp->if_flags & IFF_UP)) 485 !(ia->ia_ifp->if_flags & IFF_UP))
492 NEXT(8); 486 NEXT(8);
493 if (!(ia_best->ia_ifp->if_flags & IFF_UP) && 487 if (!(ia_best->ia_ifp->if_flags & IFF_UP) &&
494 (ia->ia_ifp->if_flags & IFF_UP)) 488 (ia->ia_ifp->if_flags & IFF_UP))
495 REPLACE(8); 489 REPLACE(8);
496 490
497 /* 491 /*

cvs diff -r1.149 -r1.150 src/sys/netinet6/ip6_input.c (expand / switch to unified diff)

--- src/sys/netinet6/ip6_input.c 2014/06/16 00:33:39 1.149
+++ src/sys/netinet6/ip6_input.c 2015/01/20 21:27:36 1.150
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ip6_input.c,v 1.149 2014/06/16 00:33:39 ozaki-r Exp $ */ 1/* $NetBSD: ip6_input.c,v 1.150 2015/01/20 21:27:36 roy Exp $ */
2/* $KAME: ip6_input.c,v 1.188 2001/03/29 05:34:31 itojun Exp $ */ 2/* $KAME: ip6_input.c,v 1.188 2001/03/29 05:34:31 itojun Exp $ */
3 3
4/* 4/*
5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -52,27 +52,27 @@ @@ -52,27 +52,27 @@
52 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 52 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
53 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 53 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59 * SUCH DAMAGE. 59 * SUCH DAMAGE.
60 * 60 *
61 * @(#)ip_input.c 8.2 (Berkeley) 1/4/94 61 * @(#)ip_input.c 8.2 (Berkeley) 1/4/94
62 */ 62 */
63 63
64#include <sys/cdefs.h> 64#include <sys/cdefs.h>
65__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.149 2014/06/16 00:33:39 ozaki-r Exp $"); 65__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.150 2015/01/20 21:27:36 roy Exp $");
66 66
67#include "opt_gateway.h" 67#include "opt_gateway.h"
68#include "opt_inet.h" 68#include "opt_inet.h"
69#include "opt_inet6.h" 69#include "opt_inet6.h"
70#include "opt_ipsec.h" 70#include "opt_ipsec.h"
71#include "opt_compat_netbsd.h" 71#include "opt_compat_netbsd.h"
72 72
73#include <sys/param.h> 73#include <sys/param.h>
74#include <sys/systm.h> 74#include <sys/systm.h>
75#include <sys/malloc.h> 75#include <sys/malloc.h>
76#include <sys/mbuf.h> 76#include <sys/mbuf.h>
77#include <sys/domain.h> 77#include <sys/domain.h>
78#include <sys/protosw.h> 78#include <sys/protosw.h>
@@ -1892,26 +1892,34 @@ sysctl_net_inet6_ip6_setup(struct sysctl @@ -1892,26 +1892,34 @@ sysctl_net_inet6_ip6_setup(struct sysctl
1892 sysctl_net_inet_ip_ports, 0, &ip6_lowportmax, 0, 1892 sysctl_net_inet_ip_ports, 0, &ip6_lowportmax, 0,
1893 CTL_NET, PF_INET6, IPPROTO_IPV6, 1893 CTL_NET, PF_INET6, IPPROTO_IPV6,
1894 IPV6CTL_LOWPORTMAX, CTL_EOL); 1894 IPV6CTL_LOWPORTMAX, CTL_EOL);
1895#endif /* IPNOPRIVPORTS */ 1895#endif /* IPNOPRIVPORTS */
1896 sysctl_createv(clog, 0, NULL, NULL, 1896 sysctl_createv(clog, 0, NULL, NULL,
1897 CTLFLAG_PERMANENT|CTLFLAG_READWRITE, 1897 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1898 CTLTYPE_INT, "use_tempaddr", 1898 CTLTYPE_INT, "use_tempaddr",
1899 SYSCTL_DESCR("Use temporary address"), 1899 SYSCTL_DESCR("Use temporary address"),
1900 NULL, 0, &ip6_use_tempaddr, 0, 1900 NULL, 0, &ip6_use_tempaddr, 0,
1901 CTL_NET, PF_INET6, IPPROTO_IPV6, 1901 CTL_NET, PF_INET6, IPPROTO_IPV6,
1902 CTL_CREATE, CTL_EOL); 1902 CTL_CREATE, CTL_EOL);
1903 sysctl_createv(clog, 0, NULL, NULL, 1903 sysctl_createv(clog, 0, NULL, NULL,
1904 CTLFLAG_PERMANENT|CTLFLAG_READWRITE, 1904 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
 1905 CTLTYPE_INT, "prefer_tempaddr",
 1906 SYSCTL_DESCR("Prefer temporary address as source "
 1907 "address"),
 1908 NULL, 0, &ip6_prefer_tempaddr, 0,
 1909 CTL_NET, PF_INET6, IPPROTO_IPV6,
 1910 CTL_CREATE, CTL_EOL);
 1911 sysctl_createv(clog, 0, NULL, NULL,
 1912 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1905 CTLTYPE_INT, "temppltime", 1913 CTLTYPE_INT, "temppltime",
1906 SYSCTL_DESCR("preferred lifetime of a temporary address"), 1914 SYSCTL_DESCR("preferred lifetime of a temporary address"),
1907 NULL, 0, &ip6_temp_preferred_lifetime, 0, 1915 NULL, 0, &ip6_temp_preferred_lifetime, 0,
1908 CTL_NET, PF_INET6, IPPROTO_IPV6, 1916 CTL_NET, PF_INET6, IPPROTO_IPV6,
1909 CTL_CREATE, CTL_EOL); 1917 CTL_CREATE, CTL_EOL);
1910 sysctl_createv(clog, 0, NULL, NULL, 1918 sysctl_createv(clog, 0, NULL, NULL,
1911 CTLFLAG_PERMANENT|CTLFLAG_READWRITE, 1919 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1912 CTLTYPE_INT, "tempvltime", 1920 CTLTYPE_INT, "tempvltime",
1913 SYSCTL_DESCR("valid lifetime of a temporary address"), 1921 SYSCTL_DESCR("valid lifetime of a temporary address"),
1914 NULL, 0, &ip6_temp_valid_lifetime, 0, 1922 NULL, 0, &ip6_temp_valid_lifetime, 0,
1915 CTL_NET, PF_INET6, IPPROTO_IPV6, 1923 CTL_NET, PF_INET6, IPPROTO_IPV6,
1916 CTL_CREATE, CTL_EOL); 1924 CTL_CREATE, CTL_EOL);
1917 sysctl_createv(clog, 0, NULL, NULL, 1925 sysctl_createv(clog, 0, NULL, NULL,

cvs diff -r1.160 -r1.161 src/sys/netinet6/ip6_output.c (expand / switch to unified diff)

--- src/sys/netinet6/ip6_output.c 2014/10/12 19:00:21 1.160
+++ src/sys/netinet6/ip6_output.c 2015/01/20 21:27:36 1.161
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ip6_output.c,v 1.160 2014/10/12 19:00:21 christos Exp $ */ 1/* $NetBSD: ip6_output.c,v 1.161 2015/01/20 21:27:36 roy Exp $ */
2/* $KAME: ip6_output.c,v 1.172 2001/03/25 09:55:56 itojun Exp $ */ 2/* $KAME: ip6_output.c,v 1.172 2001/03/25 09:55:56 itojun Exp $ */
3 3
4/* 4/*
5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -52,27 +52,27 @@ @@ -52,27 +52,27 @@
52 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 52 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
53 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 53 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59 * SUCH DAMAGE. 59 * SUCH DAMAGE.
60 * 60 *
61 * @(#)ip_output.c 8.3 (Berkeley) 1/21/94 61 * @(#)ip_output.c 8.3 (Berkeley) 1/21/94
62 */ 62 */
63 63
64#include <sys/cdefs.h> 64#include <sys/cdefs.h>
65__KERNEL_RCSID(0, "$NetBSD: ip6_output.c,v 1.160 2014/10/12 19:00:21 christos Exp $"); 65__KERNEL_RCSID(0, "$NetBSD: ip6_output.c,v 1.161 2015/01/20 21:27:36 roy Exp $");
66 66
67#include "opt_inet.h" 67#include "opt_inet.h"
68#include "opt_inet6.h" 68#include "opt_inet6.h"
69#include "opt_ipsec.h" 69#include "opt_ipsec.h"
70 70
71#include <sys/param.h> 71#include <sys/param.h>
72#include <sys/malloc.h> 72#include <sys/malloc.h>
73#include <sys/mbuf.h> 73#include <sys/mbuf.h>
74#include <sys/errno.h> 74#include <sys/errno.h>
75#include <sys/protosw.h> 75#include <sys/protosw.h>
76#include <sys/socket.h> 76#include <sys/socket.h>
77#include <sys/socketvar.h> 77#include <sys/socketvar.h>
78#include <sys/systm.h> 78#include <sys/systm.h>
@@ -1519,26 +1519,27 @@ else \ @@ -1519,26 +1519,27 @@ else \
1519 break; 1519 break;
1520 optp = &in6p->in6p_outputopts; 1520 optp = &in6p->in6p_outputopts;
1521 error = ip6_pcbopt(optname, 1521 error = ip6_pcbopt(optname,
1522 (u_char *)&tclass, 1522 (u_char *)&tclass,
1523 sizeof(tclass), 1523 sizeof(tclass),
1524 optp, 1524 optp,
1525 kauth_cred_get(), uproto); 1525 kauth_cred_get(), uproto);
1526 break; 1526 break;
1527 } 1527 }
1528 1528
1529 case IPV6_TCLASS: 1529 case IPV6_TCLASS:
1530 case IPV6_DONTFRAG: 1530 case IPV6_DONTFRAG:
1531 case IPV6_USE_MIN_MTU: 1531 case IPV6_USE_MIN_MTU:
 1532 case IPV6_PREFER_TEMPADDR:
1532 error = sockopt_getint(sopt, &optval); 1533 error = sockopt_getint(sopt, &optval);
1533 if (error) 1534 if (error)
1534 break; 1535 break;
1535 { 1536 {
1536 struct ip6_pktopts **optp; 1537 struct ip6_pktopts **optp;
1537 optp = &in6p->in6p_outputopts; 1538 optp = &in6p->in6p_outputopts;
1538 error = ip6_pcbopt(optname, 1539 error = ip6_pcbopt(optname,
1539 (u_char *)&optval, 1540 (u_char *)&optval,
1540 sizeof(optval), 1541 sizeof(optval),
1541 optp, 1542 optp,
1542 kauth_cred_get(), uproto); 1543 kauth_cred_get(), uproto);
1543 break; 1544 break;
1544 } 1545 }
@@ -1841,26 +1842,27 @@ else \ @@ -1841,26 +1842,27 @@ else \
1841 error = sockopt_setint(sopt, optval); 1842 error = sockopt_setint(sopt, optval);
1842 break; 1843 break;
1843#endif 1844#endif
1844 case IPV6_PKTINFO: 1845 case IPV6_PKTINFO:
1845 case IPV6_HOPOPTS: 1846 case IPV6_HOPOPTS:
1846 case IPV6_RTHDR: 1847 case IPV6_RTHDR:
1847 case IPV6_DSTOPTS: 1848 case IPV6_DSTOPTS:
1848 case IPV6_RTHDRDSTOPTS: 1849 case IPV6_RTHDRDSTOPTS:
1849 case IPV6_NEXTHOP: 1850 case IPV6_NEXTHOP:
1850 case IPV6_OTCLASS: 1851 case IPV6_OTCLASS:
1851 case IPV6_TCLASS: 1852 case IPV6_TCLASS:
1852 case IPV6_DONTFRAG: 1853 case IPV6_DONTFRAG:
1853 case IPV6_USE_MIN_MTU: 1854 case IPV6_USE_MIN_MTU:
 1855 case IPV6_PREFER_TEMPADDR:
1854 error = ip6_getpcbopt(in6p->in6p_outputopts, 1856 error = ip6_getpcbopt(in6p->in6p_outputopts,
1855 optname, sopt); 1857 optname, sopt);
1856 break; 1858 break;
1857 1859
1858 case IPV6_MULTICAST_IF: 1860 case IPV6_MULTICAST_IF:
1859 case IPV6_MULTICAST_HOPS: 1861 case IPV6_MULTICAST_HOPS:
1860 case IPV6_MULTICAST_LOOP: 1862 case IPV6_MULTICAST_LOOP:
1861 case IPV6_JOIN_GROUP: 1863 case IPV6_JOIN_GROUP:
1862 case IPV6_LEAVE_GROUP: 1864 case IPV6_LEAVE_GROUP:
1863 error = ip6_getmoptions(sopt, in6p); 1865 error = ip6_getmoptions(sopt, in6p);
1864 break; 1866 break;
1865 1867
1866 case IPV6_PORTALGO: 1868 case IPV6_PORTALGO:
@@ -2021,26 +2023,27 @@ ip6_pcbopts(struct ip6_pktopts **pktopt, @@ -2021,26 +2023,27 @@ ip6_pcbopts(struct ip6_pktopts **pktopt,
2021 2023
2022/* 2024/*
2023 * initialize ip6_pktopts. beware that there are non-zero default values in 2025 * initialize ip6_pktopts. beware that there are non-zero default values in
2024 * the struct. 2026 * the struct.
2025 */ 2027 */
2026void 2028void
2027ip6_initpktopts(struct ip6_pktopts *opt) 2029ip6_initpktopts(struct ip6_pktopts *opt)
2028{ 2030{
2029 2031
2030 memset(opt, 0, sizeof(*opt)); 2032 memset(opt, 0, sizeof(*opt));
2031 opt->ip6po_hlim = -1; /* -1 means default hop limit */ 2033 opt->ip6po_hlim = -1; /* -1 means default hop limit */
2032 opt->ip6po_tclass = -1; /* -1 means default traffic class */ 2034 opt->ip6po_tclass = -1; /* -1 means default traffic class */
2033 opt->ip6po_minmtu = IP6PO_MINMTU_MCASTONLY; 2035 opt->ip6po_minmtu = IP6PO_MINMTU_MCASTONLY;
 2036 opt->ip6po_prefer_tempaddr = IP6PO_TEMPADDR_SYSTEM;
2034} 2037}
2035 2038
2036#define sin6tosa(sin6) ((struct sockaddr *)(sin6)) /* XXX */ 2039#define sin6tosa(sin6) ((struct sockaddr *)(sin6)) /* XXX */
2037static int 2040static int
2038ip6_pcbopt(int optname, u_char *buf, int len, struct ip6_pktopts **pktopt, 2041ip6_pcbopt(int optname, u_char *buf, int len, struct ip6_pktopts **pktopt,
2039 kauth_cred_t cred, int uproto) 2042 kauth_cred_t cred, int uproto)
2040{ 2043{
2041 struct ip6_pktopts *opt; 2044 struct ip6_pktopts *opt;
2042 2045
2043 if (*pktopt == NULL) { 2046 if (*pktopt == NULL) {
2044 *pktopt = malloc(sizeof(struct ip6_pktopts), M_IP6OPT, 2047 *pktopt = malloc(sizeof(struct ip6_pktopts), M_IP6OPT,
2045 M_NOWAIT); 2048 M_NOWAIT);
2046 if (*pktopt == NULL) 2049 if (*pktopt == NULL)
@@ -2053,26 +2056,27 @@ ip6_pcbopt(int optname, u_char *buf, int @@ -2053,26 +2056,27 @@ ip6_pcbopt(int optname, u_char *buf, int
2053 return (ip6_setpktopt(optname, buf, len, opt, cred, 1, 0, uproto)); 2056 return (ip6_setpktopt(optname, buf, len, opt, cred, 1, 0, uproto));
2054} 2057}
2055 2058
2056static int 2059static int
2057ip6_getpcbopt(struct ip6_pktopts *pktopt, int optname, struct sockopt *sopt) 2060ip6_getpcbopt(struct ip6_pktopts *pktopt, int optname, struct sockopt *sopt)
2058{ 2061{
2059 void *optdata = NULL; 2062 void *optdata = NULL;
2060 int optdatalen = 0; 2063 int optdatalen = 0;
2061 struct ip6_ext *ip6e; 2064 struct ip6_ext *ip6e;
2062 int error = 0; 2065 int error = 0;
2063 struct in6_pktinfo null_pktinfo; 2066 struct in6_pktinfo null_pktinfo;
2064 int deftclass = 0, on; 2067 int deftclass = 0, on;
2065 int defminmtu = IP6PO_MINMTU_MCASTONLY; 2068 int defminmtu = IP6PO_MINMTU_MCASTONLY;
 2069 int defpreftemp = IP6PO_TEMPADDR_SYSTEM;
2066 2070
2067 switch (optname) { 2071 switch (optname) {
2068 case IPV6_PKTINFO: 2072 case IPV6_PKTINFO:
2069 if (pktopt && pktopt->ip6po_pktinfo) 2073 if (pktopt && pktopt->ip6po_pktinfo)
2070 optdata = (void *)pktopt->ip6po_pktinfo; 2074 optdata = (void *)pktopt->ip6po_pktinfo;
2071 else { 2075 else {
2072 /* XXX: we don't have to do this every time... */ 2076 /* XXX: we don't have to do this every time... */
2073 memset(&null_pktinfo, 0, sizeof(null_pktinfo)); 2077 memset(&null_pktinfo, 0, sizeof(null_pktinfo));
2074 optdata = (void *)&null_pktinfo; 2078 optdata = (void *)&null_pktinfo;
2075 } 2079 }
2076 optdatalen = sizeof(struct in6_pktinfo); 2080 optdatalen = sizeof(struct in6_pktinfo);
2077 break; 2081 break;
2078 case IPV6_OTCLASS: 2082 case IPV6_OTCLASS:
@@ -2124,26 +2128,32 @@ ip6_getpcbopt(struct ip6_pktopts *pktopt @@ -2124,26 +2128,32 @@ ip6_getpcbopt(struct ip6_pktopts *pktopt
2124 optdata = (void *)&pktopt->ip6po_minmtu; 2128 optdata = (void *)&pktopt->ip6po_minmtu;
2125 else 2129 else
2126 optdata = (void *)&defminmtu; 2130 optdata = (void *)&defminmtu;
2127 optdatalen = sizeof(int); 2131 optdatalen = sizeof(int);
2128 break; 2132 break;
2129 case IPV6_DONTFRAG: 2133 case IPV6_DONTFRAG:
2130 if (pktopt && ((pktopt->ip6po_flags) & IP6PO_DONTFRAG)) 2134 if (pktopt && ((pktopt->ip6po_flags) & IP6PO_DONTFRAG))
2131 on = 1; 2135 on = 1;
2132 else 2136 else
2133 on = 0; 2137 on = 0;
2134 optdata = (void *)&on; 2138 optdata = (void *)&on;
2135 optdatalen = sizeof(on); 2139 optdatalen = sizeof(on);
2136 break; 2140 break;
 2141 case IPV6_PREFER_TEMPADDR:
 2142 if (pktopt)
 2143 optdata = (void *)&pktopt->ip6po_prefer_tempaddr;
 2144 else
 2145 optdata = (void *)&defpreftemp;
 2146 optdatalen = sizeof(int);
2137 default: /* should not happen */ 2147 default: /* should not happen */
2138#ifdef DIAGNOSTIC 2148#ifdef DIAGNOSTIC
2139 panic("ip6_getpcbopt: unexpected option\n"); 2149 panic("ip6_getpcbopt: unexpected option\n");
2140#endif 2150#endif
2141 return (ENOPROTOOPT); 2151 return (ENOPROTOOPT);
2142 } 2152 }
2143 2153
2144 error = sockopt_set(sopt, optdata, optdatalen); 2154 error = sockopt_set(sopt, optdata, optdatalen);
2145 2155
2146 return (error); 2156 return (error);
2147} 2157}
2148 2158
2149void 2159void
@@ -2194,26 +2204,27 @@ do { \ @@ -2194,26 +2204,27 @@ do { \
2194 dst->type = malloc(hlen, M_IP6OPT, canwait); \ 2204 dst->type = malloc(hlen, M_IP6OPT, canwait); \
2195 if (dst->type == NULL) \ 2205 if (dst->type == NULL) \
2196 goto bad; \ 2206 goto bad; \
2197 memcpy(dst->type, src->type, hlen); \ 2207 memcpy(dst->type, src->type, hlen); \
2198 } \ 2208 } \
2199} while (/*CONSTCOND*/ 0) 2209} while (/*CONSTCOND*/ 0)
2200 2210
2201static int 2211static int
2202copypktopts(struct ip6_pktopts *dst, struct ip6_pktopts *src, int canwait) 2212copypktopts(struct ip6_pktopts *dst, struct ip6_pktopts *src, int canwait)
2203{ 2213{
2204 dst->ip6po_hlim = src->ip6po_hlim; 2214 dst->ip6po_hlim = src->ip6po_hlim;
2205 dst->ip6po_tclass = src->ip6po_tclass; 2215 dst->ip6po_tclass = src->ip6po_tclass;
2206 dst->ip6po_flags = src->ip6po_flags; 2216 dst->ip6po_flags = src->ip6po_flags;
 2217 dst->ip6po_prefer_tempaddr = src->ip6po_prefer_tempaddr;
2207 if (src->ip6po_pktinfo) { 2218 if (src->ip6po_pktinfo) {
2208 dst->ip6po_pktinfo = malloc(sizeof(*dst->ip6po_pktinfo), 2219 dst->ip6po_pktinfo = malloc(sizeof(*dst->ip6po_pktinfo),
2209 M_IP6OPT, canwait); 2220 M_IP6OPT, canwait);
2210 if (dst->ip6po_pktinfo == NULL) 2221 if (dst->ip6po_pktinfo == NULL)
2211 goto bad; 2222 goto bad;
2212 *dst->ip6po_pktinfo = *src->ip6po_pktinfo; 2223 *dst->ip6po_pktinfo = *src->ip6po_pktinfo;
2213 } 2224 }
2214 if (src->ip6po_nexthop) { 2225 if (src->ip6po_nexthop) {
2215 dst->ip6po_nexthop = malloc(src->ip6po_nexthop->sa_len, 2226 dst->ip6po_nexthop = malloc(src->ip6po_nexthop->sa_len,
2216 M_IP6OPT, canwait); 2227 M_IP6OPT, canwait);
2217 if (dst->ip6po_nexthop == NULL) 2228 if (dst->ip6po_nexthop == NULL)
2218 goto bad; 2229 goto bad;
2219 memcpy(dst->ip6po_nexthop, src->ip6po_nexthop, 2230 memcpy(dst->ip6po_nexthop, src->ip6po_nexthop,
@@ -2745,26 +2756,27 @@ ip6_setpktopt(int optname, u_char *buf,  @@ -2745,26 +2756,27 @@ ip6_setpktopt(int optname, u_char *buf,
2745 if (sticky && cmsg) { 2756 if (sticky && cmsg) {
2746 switch (optname) { 2757 switch (optname) {
2747 case IPV6_PKTINFO: 2758 case IPV6_PKTINFO:
2748 case IPV6_HOPLIMIT: 2759 case IPV6_HOPLIMIT:
2749 case IPV6_NEXTHOP: 2760 case IPV6_NEXTHOP:
2750 case IPV6_HOPOPTS: 2761 case IPV6_HOPOPTS:
2751 case IPV6_DSTOPTS: 2762 case IPV6_DSTOPTS:
2752 case IPV6_RTHDRDSTOPTS: 2763 case IPV6_RTHDRDSTOPTS:
2753 case IPV6_RTHDR: 2764 case IPV6_RTHDR:
2754 case IPV6_USE_MIN_MTU: 2765 case IPV6_USE_MIN_MTU:
2755 case IPV6_DONTFRAG: 2766 case IPV6_DONTFRAG:
2756 case IPV6_OTCLASS: 2767 case IPV6_OTCLASS:
2757 case IPV6_TCLASS: 2768 case IPV6_TCLASS:
 2769 case IPV6_PREFER_TEMPADDR: /* XXX not an RFC3542 option */
2758 return (ENOPROTOOPT); 2770 return (ENOPROTOOPT);
2759 } 2771 }
2760 } 2772 }
2761 2773
2762 switch (optname) { 2774 switch (optname) {
2763#ifdef RFC2292 2775#ifdef RFC2292
2764 case IPV6_2292PKTINFO: 2776 case IPV6_2292PKTINFO:
2765#endif 2777#endif
2766 case IPV6_PKTINFO: 2778 case IPV6_PKTINFO:
2767 { 2779 {
2768 struct ifnet *ifp = NULL; 2780 struct ifnet *ifp = NULL;
2769 struct in6_pktinfo *pktinfo; 2781 struct in6_pktinfo *pktinfo;
2770 2782
@@ -3078,26 +3090,45 @@ ip6_setpktopt(int optname, u_char *buf,  @@ -3078,26 +3090,45 @@ ip6_setpktopt(int optname, u_char *buf,
3078 if (len != sizeof(int)) 3090 if (len != sizeof(int))
3079 return (EINVAL); 3091 return (EINVAL);
3080 3092
3081 if (uproto == IPPROTO_TCP || *(int *)buf == 0) { 3093 if (uproto == IPPROTO_TCP || *(int *)buf == 0) {
3082 /* 3094 /*
3083 * we ignore this option for TCP sockets. 3095 * we ignore this option for TCP sockets.
3084 * (RFC3542 leaves this case unspecified.) 3096 * (RFC3542 leaves this case unspecified.)
3085 */ 3097 */
3086 opt->ip6po_flags &= ~IP6PO_DONTFRAG; 3098 opt->ip6po_flags &= ~IP6PO_DONTFRAG;
3087 } else 3099 } else
3088 opt->ip6po_flags |= IP6PO_DONTFRAG; 3100 opt->ip6po_flags |= IP6PO_DONTFRAG;
3089 break; 3101 break;
3090 3102
 3103 case IPV6_PREFER_TEMPADDR:
 3104 {
 3105 int preftemp;
 3106
 3107 if (len != sizeof(int))
 3108 return (EINVAL);
 3109 preftemp = *(int *)buf;
 3110 switch (preftemp) {
 3111 case IP6PO_TEMPADDR_SYSTEM:
 3112 case IP6PO_TEMPADDR_NOTPREFER:
 3113 case IP6PO_TEMPADDR_PREFER:
 3114 break;
 3115 default:
 3116 return (EINVAL);
 3117 }
 3118 opt->ip6po_prefer_tempaddr = preftemp;
 3119 break;
 3120 }
 3121
3091 default: 3122 default:
3092 return (ENOPROTOOPT); 3123 return (ENOPROTOOPT);
3093 } /* end of switch */ 3124 } /* end of switch */
3094 3125
3095 return (0); 3126 return (0);
3096} 3127}
3097 3128
3098/* 3129/*
3099 * Routine called from ip6_output() to loop back a copy of an IP6 multicast 3130 * Routine called from ip6_output() to loop back a copy of an IP6 multicast
3100 * packet to the input queue of a specified interface. Note that this 3131 * packet to the input queue of a specified interface. Note that this
3101 * calls the output routine of the loopback "driver", but with an interface 3132 * calls the output routine of the loopback "driver", but with an interface
3102 * pointer that might NOT be lo0ifp -- easier than replicating that code here. 3133 * pointer that might NOT be lo0ifp -- easier than replicating that code here.
3103 */ 3134 */

cvs diff -r1.63 -r1.64 src/sys/netinet6/ip6_var.h (expand / switch to unified diff)

--- src/sys/netinet6/ip6_var.h 2014/10/12 19:00:21 1.63
+++ src/sys/netinet6/ip6_var.h 2015/01/20 21:27:36 1.64
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ip6_var.h,v 1.63 2014/10/12 19:00:21 christos Exp $ */ 1/* $NetBSD: ip6_var.h,v 1.64 2015/01/20 21:27:36 roy Exp $ */
2/* $KAME: ip6_var.h,v 1.33 2000/06/11 14:59:20 jinmei Exp $ */ 2/* $KAME: ip6_var.h,v 1.33 2000/06/11 14:59:20 jinmei Exp $ */
3 3
4/* 4/*
5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -138,26 +138,31 @@ struct ip6po_nhinfo { @@ -138,26 +138,31 @@ struct ip6po_nhinfo {
138struct ip6_pktopts { 138struct ip6_pktopts {
139 int ip6po_hlim; /* Hoplimit for outgoing packets */ 139 int ip6po_hlim; /* Hoplimit for outgoing packets */
140 struct in6_pktinfo *ip6po_pktinfo; /* Outgoing IF/address information */ 140 struct in6_pktinfo *ip6po_pktinfo; /* Outgoing IF/address information */
141 struct ip6po_nhinfo ip6po_nhinfo; /* Next-hop address information */ 141 struct ip6po_nhinfo ip6po_nhinfo; /* Next-hop address information */
142 struct ip6_hbh *ip6po_hbh; /* Hop-by-Hop options header */ 142 struct ip6_hbh *ip6po_hbh; /* Hop-by-Hop options header */
143 struct ip6_dest *ip6po_dest1; /* Destination options header(1st part) */ 143 struct ip6_dest *ip6po_dest1; /* Destination options header(1st part) */
144 struct ip6po_rhinfo ip6po_rhinfo; /* Routing header related info. */ 144 struct ip6po_rhinfo ip6po_rhinfo; /* Routing header related info. */
145 struct ip6_dest *ip6po_dest2; /* Destination options header(2nd part) */ 145 struct ip6_dest *ip6po_dest2; /* Destination options header(2nd part) */
146 int ip6po_tclass; /* traffic class */ 146 int ip6po_tclass; /* traffic class */
147 int ip6po_minmtu; /* fragment vs PMTU discovery policy */ 147 int ip6po_minmtu; /* fragment vs PMTU discovery policy */
148#define IP6PO_MINMTU_MCASTONLY -1 /* default; send at min MTU for multicast*/ 148#define IP6PO_MINMTU_MCASTONLY -1 /* default; send at min MTU for multicast*/
149#define IP6PO_MINMTU_DISABLE 0 /* always perform pmtu disc */ 149#define IP6PO_MINMTU_DISABLE 0 /* always perform pmtu disc */
150#define IP6PO_MINMTU_ALL 1 /* always send at min MTU */ 150#define IP6PO_MINMTU_ALL 1 /* always send at min MTU */
 151 int ip6po_prefer_tempaddr; /* whether temporary addresses are
 152 * preferred as source address */
 153#define IP6PO_TEMPADDR_SYSTEM -1 /* follow the system default */
 154#define IP6PO_TEMPADDR_NOTPREFER 0 /* not prefer temporary address */
 155#define IP6PO_TEMPADDR_PREFER 1 /* prefer temporary address */
151 int ip6po_flags; 156 int ip6po_flags;
152#if 0 /* parameters in this block is obsolete. do not reuse the values. */ 157#if 0 /* parameters in this block is obsolete. do not reuse the values. */
153#define IP6PO_REACHCONF 0x01 /* upper-layer reachability confirmation. */ 158#define IP6PO_REACHCONF 0x01 /* upper-layer reachability confirmation. */
154#define IP6PO_MINMTU 0x02 /* use minimum MTU (IPV6_USE_MIN_MTU) */ 159#define IP6PO_MINMTU 0x02 /* use minimum MTU (IPV6_USE_MIN_MTU) */
155#endif 160#endif
156#define IP6PO_DONTFRAG 0x04 /* disable fragmentation (IPV6_DONTFRAG) */ 161#define IP6PO_DONTFRAG 0x04 /* disable fragmentation (IPV6_DONTFRAG) */
157}; 162};
158 163
159/* 164/*
160 * IPv6 statistics. 165 * IPv6 statistics.
161 * Each counter is an unsigned 64-bit value. 166 * Each counter is an unsigned 64-bit value.
162 */ 167 */
163#define IP6_STAT_TOTAL 0 /* total packets received */ 168#define IP6_STAT_TOTAL 0 /* total packets received */

cvs diff -r1.61 -r1.62 src/sys/netinet6/mld6.c (expand / switch to unified diff)

--- src/sys/netinet6/mld6.c 2014/11/12 03:24:25 1.61
+++ src/sys/netinet6/mld6.c 2015/01/20 21:27:36 1.62
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: mld6.c,v 1.61 2014/11/12 03:24:25 ozaki-r Exp $ */ 1/* $NetBSD: mld6.c,v 1.62 2015/01/20 21:27:36 roy Exp $ */
2/* $KAME: mld6.c,v 1.25 2001/01/16 14:14:18 itojun Exp $ */ 2/* $KAME: mld6.c,v 1.25 2001/01/16 14:14:18 itojun Exp $ */
3 3
4/* 4/*
5 * Copyright (C) 1998 WIDE Project. 5 * Copyright (C) 1998 WIDE Project.
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -92,27 +92,27 @@ @@ -92,27 +92,27 @@
92 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 92 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
93 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 93 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
94 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 94 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
95 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 95 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
96 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 96 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
97 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 97 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
98 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 98 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
99 * SUCH DAMAGE. 99 * SUCH DAMAGE.
100 * 100 *
101 * @(#)igmp.c 8.1 (Berkeley) 7/19/93 101 * @(#)igmp.c 8.1 (Berkeley) 7/19/93
102 */ 102 */
103 103
104#include <sys/cdefs.h> 104#include <sys/cdefs.h>
105__KERNEL_RCSID(0, "$NetBSD: mld6.c,v 1.61 2014/11/12 03:24:25 ozaki-r Exp $"); 105__KERNEL_RCSID(0, "$NetBSD: mld6.c,v 1.62 2015/01/20 21:27:36 roy Exp $");
106 106
107#include "opt_inet.h" 107#include "opt_inet.h"
108 108
109#include <sys/param.h> 109#include <sys/param.h>
110#include <sys/systm.h> 110#include <sys/systm.h>
111#include <sys/mbuf.h> 111#include <sys/mbuf.h>
112#include <sys/socket.h> 112#include <sys/socket.h>
113#include <sys/socketvar.h> 113#include <sys/socketvar.h>
114#include <sys/protosw.h> 114#include <sys/protosw.h>
115#include <sys/syslog.h> 115#include <sys/syslog.h>
116#include <sys/sysctl.h> 116#include <sys/sysctl.h>
117#include <sys/kernel.h> 117#include <sys/kernel.h>
118#include <sys/callout.h> 118#include <sys/callout.h>
@@ -178,26 +178,27 @@ mld_init(void) @@ -178,26 +178,27 @@ mld_init(void)
178 /* ip6h_nxt will be fill in later */ 178 /* ip6h_nxt will be fill in later */
179 hbh->ip6h_len = 0; /* (8 >> 3) - 1 */ 179 hbh->ip6h_len = 0; /* (8 >> 3) - 1 */
180 180
181 /* XXX: grotty hard coding... */ 181 /* XXX: grotty hard coding... */
182 hbh_buf[2] = IP6OPT_PADN; /* 2 byte padding */ 182 hbh_buf[2] = IP6OPT_PADN; /* 2 byte padding */
183 hbh_buf[3] = 0; 183 hbh_buf[3] = 0;
184 hbh_buf[4] = IP6OPT_RTALERT; 184 hbh_buf[4] = IP6OPT_RTALERT;
185 hbh_buf[5] = IP6OPT_RTALERT_LEN - 2; 185 hbh_buf[5] = IP6OPT_RTALERT_LEN - 2;
186 memcpy(&hbh_buf[6], (void *)&rtalert_code, sizeof(u_int16_t)); 186 memcpy(&hbh_buf[6], (void *)&rtalert_code, sizeof(u_int16_t));
187 187
188 ip6_opts.ip6po_hbh = hbh; 188 ip6_opts.ip6po_hbh = hbh;
189 /* We will specify the hoplimit by a multicast option. */ 189 /* We will specify the hoplimit by a multicast option. */
190 ip6_opts.ip6po_hlim = -1; 190 ip6_opts.ip6po_hlim = -1;
 191 ip6_opts.ip6po_prefer_tempaddr = IP6PO_TEMPADDR_NOTPREFER;
191} 192}
192 193
193static void 194static void
194mld_starttimer(struct in6_multi *in6m) 195mld_starttimer(struct in6_multi *in6m)
195{ 196{
196 struct timeval now; 197 struct timeval now;
197 198
198 KASSERT(in6m->in6m_timer != IN6M_TIMER_UNDEF); 199 KASSERT(in6m->in6m_timer != IN6M_TIMER_UNDEF);
199 200
200 microtime(&now); 201 microtime(&now);
201 in6m->in6m_timer_expire.tv_sec = now.tv_sec + in6m->in6m_timer / hz; 202 in6m->in6m_timer_expire.tv_sec = now.tv_sec + in6m->in6m_timer / hz;
202 in6m->in6m_timer_expire.tv_usec = now.tv_usec + 203 in6m->in6m_timer_expire.tv_usec = now.tv_usec +
203 (in6m->in6m_timer % hz) * (1000000 / hz); 204 (in6m->in6m_timer % hz) * (1000000 / hz);