CVS commit: src/sys/netinet6

2021-08-17 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Tue Aug 17 09:43:21 UTC 2021

Modified Files:
src/sys/netinet6: nd6.c

Log Message:
nd6: prevent ln from being freed while releasing held packets


To generate a diff of this commit:
cvs rdiff -u -r1.276 -r1.277 src/sys/netinet6/nd6.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/nd6.c
diff -u src/sys/netinet6/nd6.c:1.276 src/sys/netinet6/nd6.c:1.277
--- src/sys/netinet6/nd6.c:1.276	Mon Dec 28 20:19:50 2020
+++ src/sys/netinet6/nd6.c	Tue Aug 17 09:43:21 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: nd6.c,v 1.276 2020/12/28 20:19:50 nia Exp $	*/
+/*	$NetBSD: nd6.c,v 1.277 2021/08/17 09:43:21 ozaki-r Exp $	*/
 /*	$KAME: nd6.c,v 1.279 2002/06/08 11:16:51 itojun Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nd6.c,v 1.276 2020/12/28 20:19:50 nia Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nd6.c,v 1.277 2021/08/17 09:43:21 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -1305,6 +1305,7 @@ nd6_llinfo_release_pkts(struct llentry *
 
 	m_hold = ln->la_hold, ln->la_hold = NULL, ln->la_numheld = 0;
 
+	LLE_ADDREF(ln);
 	LLE_WUNLOCK(ln);
 	for (; m_hold != NULL; m_hold = m_hold_next) {
 		m_hold_next = m_hold->m_nextpkt;
@@ -1318,6 +1319,7 @@ nd6_llinfo_release_pkts(struct llentry *
 		ip6_if_output(ifp, ifp, m_hold, , NULL);
 	}
 	LLE_WLOCK(ln);
+	LLE_REMREF(ln);
 }
 
 /*



CVS commit: src/sys/netinet6

2021-08-10 Thread Frank Kardel
Module Name:src
Committed By:   kardel
Date:   Tue Aug 10 06:29:56 UTC 2021

Modified Files:
src/sys/netinet6: in6_src.c

Log Message:
PR kern/56348
MTU discovery fails with IPv6 sockets bound to IPv4 mapped address

pick up the IPv4 route for IPv4 mapped IPv6 address to get the correct
MTU and not any unrelated/inappropriate MTU from IPv6 routes. IPv4 mapped
IPv6 addresses are always handled by the IPv4 stack and MTU discovery
is solely handled with the IPv4 routing table.


To generate a diff of this commit:
cvs rdiff -u -r1.87 -r1.88 src/sys/netinet6/in6_src.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_src.c
diff -u src/sys/netinet6/in6_src.c:1.87 src/sys/netinet6/in6_src.c:1.88
--- src/sys/netinet6/in6_src.c:1.87	Fri Aug 28 06:32:24 2020
+++ src/sys/netinet6/in6_src.c	Tue Aug 10 06:29:56 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: in6_src.c,v 1.87 2020/08/28 06:32:24 ozaki-r Exp $	*/
+/*	$NetBSD: in6_src.c,v 1.88 2021/08/10 06:29:56 kardel Exp $	*/
 /*	$KAME: in6_src.c,v 1.159 2005/10/19 01:40:32 t-momose Exp $	*/
 
 /*
@@ -66,7 +66,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in6_src.c,v 1.87 2020/08/28 06:32:24 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6_src.c,v 1.88 2021/08/10 06:29:56 kardel Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -612,6 +612,7 @@ in6_selectroute(struct sockaddr_in6 *dst
 	struct rtentry *rt = NULL;
 	union {
 		struct sockaddr		dst;
+		struct sockaddr_in	dst4;
 		struct sockaddr_in6	dst6;
 	} u;
 
@@ -679,9 +680,17 @@ in6_selectroute(struct sockaddr_in6 *dst
 	 * Use a cached route if it exists and is valid, else try to allocate
 	 * a new one.  Note that we should check the address family of the
 	 * cached destination, in case of sharing the cache with IPv4.
+	 *
+	 * for V4 mapped addresses we want to pick up the v4 route
+	 * see PR kern/56348
 	 */
-	u.dst6 = *dstsock;
-	u.dst6.sin6_scope_id = 0;
+	if (IN6_IS_ADDR_V4MAPPED(>sin6_addr)) {
+		in6_sin6_2_sin(, dstsock);
+	} else {
+		u.dst6 = *dstsock;
+		u.dst6.sin6_scope_id = 0;
+	}
+
 	rt = rtcache_lookup1(*ro, , 1);
 
 	if (rt == NULL)



CVS commit: src/sys/netinet6

2021-07-31 Thread Andrius Varanavicius
Module Name:src
Committed By:   andvar
Date:   Sat Jul 31 10:12:04 UTC 2021

Modified Files:
src/sys/netinet6: in6.h

Log Message:
fix typos in comments


To generate a diff of this commit:
cvs rdiff -u -r1.100 -r1.101 src/sys/netinet6/in6.h

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.100 src/sys/netinet6/in6.h:1.101
--- src/sys/netinet6/in6.h:1.100	Tue Sep  8 14:12:57 2020
+++ src/sys/netinet6/in6.h	Sat Jul 31 10:12:04 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: in6.h,v 1.100 2020/09/08 14:12:57 christos Exp $	*/
+/*	$NetBSD: in6.h,v 1.101 2021/07/31 10:12:04 andvar Exp $	*/
 /*	$KAME: in6.h,v 1.83 2001/03/29 02:55:07 jinmei Exp $	*/
 
 /*
@@ -429,7 +429,7 @@ extern const struct in6_addr in6addr_lin
 #define IPV6_HOPLIMIT		47 /* int; send hop limit */
 #define IPV6_NEXTHOP		48 /* sockaddr; next hop addr */
 #define IPV6_HOPOPTS		49 /* ip6_hbh; send hop-by-hop option */
-#define IPV6_DSTOPTS		50 /* ip6_dest; send dst option befor rthdr */
+#define IPV6_DSTOPTS		50 /* ip6_dest; send dst option before rthdr */
 #define IPV6_RTHDR		51 /* ip6_rthdr; send routing header */
 
 #define IPV6_RECVTCLASS		57 /* bool; recv traffic class values */
@@ -440,7 +440,7 @@ 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 */
+* the source address */
 #define IPV6_BINDANY		64 /* bool: allow bind to any address */
 /* to define items, should talk with KAME guys first, for *BSD compatibility */
 



CVS commit: src/sys/netinet6

2021-03-11 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Thu Mar 11 11:10:22 UTC 2021

Modified Files:
src/sys/netinet6: ip6_var.h

Log Message:
flowlabel will never return anything other than 1 or 0.
s/&&/&/


To generate a diff of this commit:
cvs rdiff -u -r1.89 -r1.90 src/sys/netinet6/ip6_var.h

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/ip6_var.h
diff -u src/sys/netinet6/ip6_var.h:1.89 src/sys/netinet6/ip6_var.h:1.90
--- src/sys/netinet6/ip6_var.h:1.89	Mon Mar  8 18:22:16 2021
+++ src/sys/netinet6/ip6_var.h	Thu Mar 11 11:10:22 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6_var.h,v 1.89 2021/03/08 18:22:16 christos Exp $	*/
+/*	$NetBSD: ip6_var.h,v 1.90 2021/03/11 11:10:22 ryo Exp $	*/
 /*	$KAME: ip6_var.h,v 1.33 2000/06/11 14:59:20 jinmei Exp $	*/
 
 /*
@@ -382,7 +382,7 @@ static __inline uint32_t
 ip6_randomflowlabel(void)
 {
 
-	return cprng_fast32() && 0xf;
+	return cprng_fast32() & 0xf;
 }
 
 static __inline bool



CVS commit: src/sys/netinet6

2021-03-10 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Mar 10 22:28:27 UTC 2021

Modified Files:
src/sys/netinet6: ip6_output.c

Log Message:
byte-flipping a random number is not very useful.


To generate a diff of this commit:
cvs rdiff -u -r1.226 -r1.227 src/sys/netinet6/ip6_output.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/ip6_output.c
diff -u src/sys/netinet6/ip6_output.c:1.226 src/sys/netinet6/ip6_output.c:1.227
--- src/sys/netinet6/ip6_output.c:1.226	Tue Sep  8 10:12:57 2020
+++ src/sys/netinet6/ip6_output.c	Wed Mar 10 17:28:26 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6_output.c,v 1.226 2020/09/08 14:12:57 christos Exp $	*/
+/*	$NetBSD: ip6_output.c,v 1.227 2021/03/10 22:28:26 christos Exp $	*/
 /*	$KAME: ip6_output.c,v 1.172 2001/03/25 09:55:56 itojun Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip6_output.c,v 1.226 2020/09/08 14:12:57 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_output.c,v 1.227 2021/03/10 22:28:26 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -889,7 +889,7 @@ ip6_output(
 		in6_ifstat_inc(ifp, ifs6_out_fragfail);
 		goto bad;
 	} else {
-		const u_int32_t id = htonl(ip6_randomid());
+		const uint32_t id = ip6_randomid();
 		struct mbuf **mnext, *m_frgpart;
 		const int hlen = unfragpartlen;
 		struct ip6_frag *ip6f;



CVS commit: src/sys/netinet6

2021-03-08 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Mar  8 18:22:16 UTC 2021

Modified Files:
src/sys/netinet6: files.netinet6 ip6_var.h
Removed Files:
src/sys/netinet6: ip6_id.c

Log Message:
no need for ip6_id.c...


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/netinet6/files.netinet6
cvs rdiff -u -r1.21 -r0 src/sys/netinet6/ip6_id.c
cvs rdiff -u -r1.88 -r1.89 src/sys/netinet6/ip6_var.h

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/files.netinet6
diff -u src/sys/netinet6/files.netinet6:1.13 src/sys/netinet6/files.netinet6:1.14
--- src/sys/netinet6/files.netinet6:1.13	Thu Feb  8 06:34:35 2018
+++ src/sys/netinet6/files.netinet6	Mon Mar  8 13:22:16 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: files.netinet6,v 1.13 2018/02/08 11:34:35 maxv Exp $
+#	$NetBSD: files.netinet6,v 1.14 2021/03/08 18:22:16 christos Exp $
 
 defflag	opt_inet6.h	RFC2292	
 
@@ -17,7 +17,6 @@ file	netinet6/in6_proto.c		inet6
 file	netinet6/in6_src.c		inet6
 file	netinet6/ip6_flow.c		inet6 & gateway
 file	netinet6/ip6_forward.c		inet6
-file	netinet6/ip6_id.c		inet6
 file	netinet6/ip6_input.c		inet6
 file	netinet6/ip6_mroute.c		inet6
 file	netinet6/ip6_output.c		inet6

Index: src/sys/netinet6/ip6_var.h
diff -u src/sys/netinet6/ip6_var.h:1.88 src/sys/netinet6/ip6_var.h:1.89
--- src/sys/netinet6/ip6_var.h:1.88	Sun Mar  7 10:01:35 2021
+++ src/sys/netinet6/ip6_var.h	Mon Mar  8 13:22:16 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6_var.h,v 1.88 2021/03/07 15:01:35 christos Exp $	*/
+/*	$NetBSD: ip6_var.h,v 1.89 2021/03/08 18:22:16 christos Exp $	*/
 /*	$KAME: ip6_var.h,v 1.33 2000/06/11 14:59:20 jinmei Exp $	*/
 
 /*
@@ -228,6 +228,7 @@ struct ip6flow {
 #ifdef _KERNEL
 
 #include 
+#include 
 
 /*
  * Auxiliary attributes of incoming IPv6 packets, which is initialized when we
@@ -370,10 +371,21 @@ int in6_selectroute(struct sockaddr_in6 
 int	ip6_get_membership(const struct sockopt *, struct ifnet **,
 	struct psref *, void *, size_t);
 
-u_int32_t ip6_randomid(void);
-u_int32_t ip6_randomflowlabel(void);
+static __inline uint32_t
+ip6_randomid(void)
+{
+
+	return cprng_fast32();
+}
+
+static __inline uint32_t
+ip6_randomflowlabel(void)
+{
+
+	return cprng_fast32() && 0xf;
+}
 
-static inline bool
+static __inline bool
 ip6_dad_enabled(void)
 {
 



CVS commit: src/sys/netinet6

2021-03-07 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Mar  7 15:03:32 UTC 2021

Modified Files:
src/sys/netinet6: ip6_id.c

Log Message:
Amend missed messages:

netinet6: Pick IPv6 fragment ids uniformly at random.

Expected number of packets before collision is ~2^16, about the same
as we get for IPv4 with alternating disjoint random cycles.  Keep it
simple unless we determine we really need something much better for
IPv6 than what IPv4 can achieve anyway.

netinet6: Rip out now-unused IPv6 fragment id logic.

(from riastradh)


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/netinet6/ip6_id.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/ip6_id.c
diff -u src/sys/netinet6/ip6_id.c:1.20 src/sys/netinet6/ip6_id.c:1.21
--- src/sys/netinet6/ip6_id.c:1.20	Sun Mar  7 09:59:36 2021
+++ src/sys/netinet6/ip6_id.c	Sun Mar  7 10:03:32 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6_id.c,v 1.20 2021/03/07 14:59:36 christos Exp $	*/
+/*	$NetBSD: ip6_id.c,v 1.21 2021/03/07 15:03:32 christos Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip6_id.c,v 1.20 2021/03/07 14:59:36 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_id.c,v 1.21 2021/03/07 15:03:32 christos Exp $");
 
 #include 
 #include 



CVS commit: src/sys/netinet6

2021-03-07 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Mar  7 15:01:35 UTC 2021

Modified Files:
src/sys/netinet6: ip6_var.h

Log Message:
netinet/netinet6: Add necessary includes to make these standalone.
(from riastradh)


To generate a diff of this commit:
cvs rdiff -u -r1.87 -r1.88 src/sys/netinet6/ip6_var.h

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/ip6_var.h
diff -u src/sys/netinet6/ip6_var.h:1.87 src/sys/netinet6/ip6_var.h:1.88
--- src/sys/netinet6/ip6_var.h:1.87	Fri Aug 28 02:32:24 2020
+++ src/sys/netinet6/ip6_var.h	Sun Mar  7 10:01:35 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6_var.h,v 1.87 2020/08/28 06:32:24 ozaki-r Exp $	*/
+/*	$NetBSD: ip6_var.h,v 1.88 2021/03/07 15:01:35 christos Exp $	*/
 /*	$KAME: ip6_var.h,v 1.33 2000/06/11 14:59:20 jinmei Exp $	*/
 
 /*
@@ -64,9 +64,16 @@
 #ifndef _NETINET6_IP6_VAR_H_
 #define _NETINET6_IP6_VAR_H_
 
+#include 
+#include 
 #include 
+
+#include 
 #include 
 
+#include 
+#include 
+
 struct	ip6_moptions {
 	if_index_t im6o_multicast_if_index; /* I/F for outgoing multicasts */
 	u_char	im6o_multicast_hlim;	/* hoplimit for outgoing multicasts */
@@ -219,6 +226,9 @@ struct ip6flow {
 };
 
 #ifdef _KERNEL
+
+#include 
+
 /*
  * Auxiliary attributes of incoming IPv6 packets, which is initialized when we
  * come into ip6_input().



CVS commit: src/sys/netinet6

2021-03-07 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Mar  7 14:59:36 UTC 2021

Modified Files:
src/sys/netinet6: ip6_id.c

Log Message:
netinet6: Mark randomid unused.

Will make merging and bisection easier if anything goes wrong with
flow label or fragment id randomization changes.

(from riastradh)


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/netinet6/ip6_id.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/ip6_id.c
diff -u src/sys/netinet6/ip6_id.c:1.19 src/sys/netinet6/ip6_id.c:1.20
--- src/sys/netinet6/ip6_id.c:1.19	Fri Oct 18 00:09:02 2019
+++ src/sys/netinet6/ip6_id.c	Sun Mar  7 09:59:36 2021
@@ -1,9 +1,7 @@
-/*	$NetBSD: ip6_id.c,v 1.19 2019/10/18 04:09:02 msaitoh Exp $	*/
-/*	$KAME: ip6_id.c,v 1.8 2003/09/06 13:41:06 itojun Exp $	*/
-/*	$OpenBSD: ip_id.c,v 1.6 2002/03/15 18:19:52 millert Exp $	*/
+/*	$NetBSD: ip6_id.c,v 1.20 2021/03/07 14:59:36 christos Exp $	*/
 
-/*
- * Copyright (C) 2003 WIDE Project.
+/*-
+ * Copyright (c) 2020 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -14,241 +12,38 @@
  * 2. Redistributions in binary form must reproduce the above copyright
  *notice, this list of conditions and the following disclaimer in the
  *documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the project nor the names of its contributors
- *may be used to endorse or promote products derived from this software
- *without specific prior written permission.
  *
- * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- * Copyright 1998 Niels Provos 
- * All rights reserved.
- *
- * Theo de Raadt  came up with the idea of using
- * such a mathematical system to generate more random (yet non-repeating)
- * ids to solve the resolver/named problem.  But Niels designed the
- * actual system based on the constraints.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *notice, this list of conditions and the following disclaimer in the
- *documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * seed = random (bits - 1) bit
- * n = prime, g0 = generator to n,
- * j = random so that gcd(j,n-1) == 1
- * g = g0^j mod n will be a generator again.
- *
- * X[0] = random seed.
- * X[n] = a*X[n-1]+b mod m is a Linear Congruential Generator
- * with a = 7^(even random) mod m,
- *  b = random with gcd(b,m) == 1
- *  m = constant and a maximal period of m-1.
- *
- * The transaction id is determined by:
- * id[n] = seed xor (g^X[n] mod n)
- *
- * Effectively the id is restricted to the lower (bits - 1) bits, thus
- * yielding two different cycles by toggling the msb on and off.
- * This avoids reuse issues caused by reseeding.
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE 

CVS commit: src/sys/netinet6

2021-02-15 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Feb 15 10:13:45 UTC 2021

Modified Files:
src/sys/netinet6: icmp6.c

Log Message:
Fix the build.
Maybe there should be a ICMP6_HDR_ALIGNMENT, but for now there is
only IP6_HDR_ALIGNMENT.


To generate a diff of this commit:
cvs rdiff -u -r1.248 -r1.249 src/sys/netinet6/icmp6.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/icmp6.c
diff -u src/sys/netinet6/icmp6.c:1.248 src/sys/netinet6/icmp6.c:1.249
--- src/sys/netinet6/icmp6.c:1.248	Sun Feb 14 20:58:35 2021
+++ src/sys/netinet6/icmp6.c	Mon Feb 15 10:13:45 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: icmp6.c,v 1.248 2021/02/14 20:58:35 christos Exp $	*/
+/*	$NetBSD: icmp6.c,v 1.249 2021/02/15 10:13:45 martin Exp $	*/
 /*	$KAME: icmp6.c,v 1.217 2001/06/20 15:03:29 jinmei Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: icmp6.c,v 1.248 2021/02/14 20:58:35 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: icmp6.c,v 1.249 2021/02/15 10:13:45 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -538,7 +538,7 @@ _icmp6_input(struct mbuf *m, int off, in
 	 * Enforce alignment requirements that are violated in
 	 * some cases, see kern/50766 for details.
 	 */
-	if (POINTER_ALIGNED_P(icmp6, ICMP6_HDR_ALIGNMENT) == 0) {
+	if (POINTER_ALIGNED_P(icmp6, IP6_HDR_ALIGNMENT) == 0) {
 		m = m_copyup(m, off + sizeof(struct icmp6_hdr), 0);
 		if (m == NULL) {
 			ICMP6_STATINC(ICMP6_STAT_TOOSHORT);
@@ -548,7 +548,7 @@ _icmp6_input(struct mbuf *m, int off, in
 		ip6 = mtod(m, struct ip6_hdr *);
 		icmp6 = (struct icmp6_hdr *)(mtod(m, char *) + off);
 	}
-	KASSERT(POINTER_ALIGNED_P(icmp6, ICMP6_HDR_ALIGNMENT));
+	KASSERT(POINTER_ALIGNED_P(icmp6, IP6_HDR_ALIGNMENT));
 
 	/*
 	 * calculate the checksum



CVS commit: src/sys/netinet6

2020-12-28 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Mon Dec 28 20:19:50 UTC 2020

Modified Files:
src/sys/netinet6: nd6.c

Log Message:
Add more guards against NULL deref, since KUBSAN still complains.


To generate a diff of this commit:
cvs rdiff -u -r1.275 -r1.276 src/sys/netinet6/nd6.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/nd6.c
diff -u src/sys/netinet6/nd6.c:1.275 src/sys/netinet6/nd6.c:1.276
--- src/sys/netinet6/nd6.c:1.275	Sat Dec 26 10:43:39 2020
+++ src/sys/netinet6/nd6.c	Mon Dec 28 20:19:50 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: nd6.c,v 1.275 2020/12/26 10:43:39 nia Exp $	*/
+/*	$NetBSD: nd6.c,v 1.276 2020/12/28 20:19:50 nia Exp $	*/
 /*	$KAME: nd6.c,v 1.279 2002/06/08 11:16:51 itojun Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nd6.c,v 1.275 2020/12/26 10:43:39 nia Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nd6.c,v 1.276 2020/12/28 20:19:50 nia Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -384,8 +384,10 @@ nd6_llinfo_output(struct ifnet *ifp, con
 const union l3addr *hsrc)
 {
 
-	nd6_ns_output(ifp, daddr != NULL ? >addr6 : NULL,
-	>addr6, >addr6, NULL);
+	nd6_ns_output(ifp,
+	daddr != NULL ? >addr6 : NULL,
+	taddr != NULL ? >addr6 : NULL,
+	hsrc != NULL ? >addr6 : NULL, NULL);
 }
 
 static bool



CVS commit: src/sys/netinet6

2020-12-26 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Sat Dec 26 10:43:39 UTC 2020

Modified Files:
src/sys/netinet6: nd6.c

Log Message:
Avoid NULL pointer dereference, noticed by KUBSAN.

"Looks fine" roy@


To generate a diff of this commit:
cvs rdiff -u -r1.274 -r1.275 src/sys/netinet6/nd6.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/nd6.c
diff -u src/sys/netinet6/nd6.c:1.274 src/sys/netinet6/nd6.c:1.275
--- src/sys/netinet6/nd6.c:1.274	Tue Sep 15 10:05:36 2020
+++ src/sys/netinet6/nd6.c	Sat Dec 26 10:43:39 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: nd6.c,v 1.274 2020/09/15 10:05:36 roy Exp $	*/
+/*	$NetBSD: nd6.c,v 1.275 2020/12/26 10:43:39 nia Exp $	*/
 /*	$KAME: nd6.c,v 1.279 2002/06/08 11:16:51 itojun Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nd6.c,v 1.274 2020/09/15 10:05:36 roy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nd6.c,v 1.275 2020/12/26 10:43:39 nia Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -384,8 +384,8 @@ nd6_llinfo_output(struct ifnet *ifp, con
 const union l3addr *hsrc)
 {
 
-	nd6_ns_output(ifp, >addr6, >addr6,
-	>addr6, NULL);
+	nd6_ns_output(ifp, daddr != NULL ? >addr6 : NULL,
+	>addr6, >addr6, NULL);
 }
 
 static bool



CVS commit: src/sys/netinet6

2020-09-11 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Fri Sep 11 15:03:33 UTC 2020

Modified Files:
src/sys/netinet6: icmp6.c nd6.c nd6.h nd6_nbr.c

Log Message:
inet6: Use generic Neighor Detection rather than IPv6 specific

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.246 -r1.247 src/sys/netinet6/icmp6.c
cvs rdiff -u -r1.271 -r1.272 src/sys/netinet6/nd6.c
cvs rdiff -u -r1.90 -r1.91 src/sys/netinet6/nd6.h
cvs rdiff -u -r1.180 -r1.181 src/sys/netinet6/nd6_nbr.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/icmp6.c
diff -u src/sys/netinet6/icmp6.c:1.246 src/sys/netinet6/icmp6.c:1.247
--- src/sys/netinet6/icmp6.c:1.246	Mon Jul 27 14:52:55 2020
+++ src/sys/netinet6/icmp6.c	Fri Sep 11 15:03:33 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: icmp6.c,v 1.246 2020/07/27 14:52:55 roy Exp $	*/
+/*	$NetBSD: icmp6.c,v 1.247 2020/09/11 15:03:33 roy Exp $	*/
 /*	$KAME: icmp6.c,v 1.217 2001/06/20 15:03:29 jinmei Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: icmp6.c,v 1.246 2020/07/27 14:52:55 roy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: icmp6.c,v 1.247 2020/09/11 15:03:33 roy Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -87,6 +87,7 @@ __KERNEL_RCSID(0, "$NetBSD: icmp6.c,v 1.
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -98,9 +99,9 @@ __KERNEL_RCSID(0, "$NetBSD: icmp6.c,v 1.
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
+#include 
 #include 
 
 #ifdef IPSEC
@@ -2953,7 +2954,6 @@ out:
 static void
 sysctl_net_inet6_icmp6_setup(struct sysctllog **clog)
 {
-	extern int nd6_maxqueuelen; /* defined in nd6.c */
 
 	sysctl_createv(clog, 0, NULL, NULL,
 		   CTLFLAG_PERMANENT,
@@ -3008,23 +3008,37 @@ sysctl_net_inet6_icmp6_setup(struct sysc
 		   CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
 		   CTLTYPE_INT, "nd6_delay",
 		   SYSCTL_DESCR("First probe delay time"),
-		   NULL, 0, _delay, 0,
+		   NULL, 0, _nd_domain.nd_delay, 0,
 		   CTL_NET, PF_INET6, IPPROTO_ICMPV6,
 		   ICMPV6CTL_ND6_DELAY, CTL_EOL);
 	sysctl_createv(clog, 0, NULL, NULL,
 		   CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
+		   CTLTYPE_INT, "nd6_mmaxtries",
+		   SYSCTL_DESCR("Number of multicast discovery attempts"),
+		   NULL, 0, _nd_domain.nd_mmaxtries, 0,
+		   CTL_NET, PF_INET6, IPPROTO_ICMPV6,
+		   ICMPV6CTL_ND6_MMAXTRIES, CTL_EOL);
+	sysctl_createv(clog, 0, NULL, NULL,
+		   CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
 		   CTLTYPE_INT, "nd6_umaxtries",
 		   SYSCTL_DESCR("Number of unicast discovery attempts"),
-		   NULL, 0, _umaxtries, 0,
+		   NULL, 0, _nd_domain.nd_umaxtries, 0,
 		   CTL_NET, PF_INET6, IPPROTO_ICMPV6,
 		   ICMPV6CTL_ND6_UMAXTRIES, CTL_EOL);
 	sysctl_createv(clog, 0, NULL, NULL,
 		   CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
-		   CTLTYPE_INT, "nd6_mmaxtries",
-		   SYSCTL_DESCR("Number of multicast discovery attempts"),
-		   NULL, 0, _mmaxtries, 0,
+		   CTLTYPE_INT, "nd6_maxnudhint",
+		   SYSCTL_DESCR("Maximum neighbor unreachable hint count"),
+		   NULL, 0, _nd_domain.nd_maxnudhint, 0,
 		   CTL_NET, PF_INET6, IPPROTO_ICMPV6,
-		   ICMPV6CTL_ND6_MMAXTRIES, CTL_EOL);
+		   ICMPV6CTL_ND6_MAXNUDHINT, CTL_EOL);
+	sysctl_createv(clog, 0, NULL, NULL,
+		   CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
+		   CTLTYPE_INT, "maxqueuelen",
+		   SYSCTL_DESCR("max packet queue len for a unresolved ND"),
+		   NULL, 1, _nd_domain.nd_maxqueuelen, 0,
+		   CTL_NET, PF_INET6, IPPROTO_ICMPV6,
+		   ICMPV6CTL_ND6_MAXQLEN, CTL_EOL);
 	sysctl_createv(clog, 0, NULL, NULL,
 		   CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
 		   CTLTYPE_INT, "nd6_useloopback",
@@ -3056,13 +3070,6 @@ sysctl_net_inet6_icmp6_setup(struct sysc
 		   ICMPV6CTL_ERRPPSLIMIT, CTL_EOL);
 	sysctl_createv(clog, 0, NULL, NULL,
 		   CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
-		   CTLTYPE_INT, "nd6_maxnudhint",
-		   SYSCTL_DESCR("Maximum neighbor unreachable hint count"),
-		   NULL, 0, _maxnudhint, 0,
-		   CTL_NET, PF_INET6, IPPROTO_ICMPV6,
-		   ICMPV6CTL_ND6_MAXNUDHINT, CTL_EOL);
-	sysctl_createv(clog, 0, NULL, NULL,
-		   CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
 		   CTLTYPE_INT, "mtudisc_hiwat",
 		   SYSCTL_DESCR("Low mark on MTU Discovery route timers"),
 		   NULL, 0, _mtudisc_hiwat, 0,
@@ -3098,13 +3105,6 @@ sysctl_net_inet6_icmp6_setup(struct sysc
 		   CTL_NET, PF_INET6, IPPROTO_ICMPV6,
 		   OICMPV6CTL_ND6_PRLIST, CTL_EOL);
 #endif
-	sysctl_createv(clog, 0, NULL, NULL,
-		   CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
-		   CTLTYPE_INT, "maxqueuelen",
-		   SYSCTL_DESCR("max packet queue len for a unresolved ND"),
-		   NULL, 1, _maxqueuelen, 0,
-		   CTL_NET, PF_INET6, IPPROTO_ICMPV6,
-		   ICMPV6CTL_ND6_MAXQLEN, CTL_EOL);
 }
 
 void

Index: 

CVS commit: src/sys/netinet6

2020-08-28 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Fri Aug 28 06:32:24 UTC 2020

Modified Files:
src/sys/netinet6: in6_src.c ip6_forward.c ip6_input.c ip6_output.c
ip6_var.h

Log Message:
inet6: reduce silent packet discards


To generate a diff of this commit:
cvs rdiff -u -r1.86 -r1.87 src/sys/netinet6/in6_src.c \
src/sys/netinet6/ip6_var.h
cvs rdiff -u -r1.101 -r1.102 src/sys/netinet6/ip6_forward.c
cvs rdiff -u -r1.221 -r1.222 src/sys/netinet6/ip6_input.c
cvs rdiff -u -r1.224 -r1.225 src/sys/netinet6/ip6_output.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_src.c
diff -u src/sys/netinet6/in6_src.c:1.86 src/sys/netinet6/in6_src.c:1.87
--- src/sys/netinet6/in6_src.c:1.86	Wed Nov 13 02:51:22 2019
+++ src/sys/netinet6/in6_src.c	Fri Aug 28 06:32:24 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: in6_src.c,v 1.86 2019/11/13 02:51:22 ozaki-r Exp $	*/
+/*	$NetBSD: in6_src.c,v 1.87 2020/08/28 06:32:24 ozaki-r Exp $	*/
 /*	$KAME: in6_src.c,v 1.159 2005/10/19 01:40:32 t-momose Exp $	*/
 
 /*
@@ -66,7 +66,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in6_src.c,v 1.86 2019/11/13 02:51:22 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6_src.c,v 1.87 2020/08/28 06:32:24 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -646,6 +646,7 @@ in6_selectroute(struct sockaddr_in6 *dst
 
 		/* at this moment, we only support AF_INET6 next hops */
 		if (sin6_next->sin6_family != AF_INET6) {
+			IP6_STATINC(IP6_STAT_ODROPPED);
 			error = EAFNOSUPPORT; /* or should we proceed? */
 			goto done;
 		}
Index: src/sys/netinet6/ip6_var.h
diff -u src/sys/netinet6/ip6_var.h:1.86 src/sys/netinet6/ip6_var.h:1.87
--- src/sys/netinet6/ip6_var.h:1.86	Fri Aug 28 06:28:58 2020
+++ src/sys/netinet6/ip6_var.h	Fri Aug 28 06:32:24 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6_var.h,v 1.86 2020/08/28 06:28:58 ozaki-r Exp $	*/
+/*	$NetBSD: ip6_var.h,v 1.87 2020/08/28 06:32:24 ozaki-r Exp $	*/
 /*	$KAME: ip6_var.h,v 1.33 2000/06/11 14:59:20 jinmei Exp $	*/
 
 /*
@@ -190,8 +190,13 @@ struct	ip6_pktopts {
 #define	IP6_STAT_PFILDROP_OUT	404	/* dropped by pfil (PFIL_OUT) */
 #define	IP6_STAT_IPSECDROP_IN	405	/* dropped by IPsec SP check */
 #define	IP6_STAT_IPSECDROP_OUT	406	/* dropped by IPsec SP check */
+#define	IP6_STAT_IFDROP		407	/* dropped due to inteface state */
+#define	IP6_STAT_IDROPPED	408	/* lost packets due to nobufs, etc. */
+#define	IP6_STAT_TIMXCEED	409	/* hop limit exceeded */
+#define	IP6_STAT_TOOBIG		410	/* packet bigger than MTU */
+#define	IP6_STAT_RTREJECT	411	/* rejected by route */
 
-#define	IP6_NSTATS		407
+#define	IP6_NSTATS		412
 
 #define IP6FLOW_HASHBITS 6 /* should not be a multiple of 8 */
 

Index: src/sys/netinet6/ip6_forward.c
diff -u src/sys/netinet6/ip6_forward.c:1.101 src/sys/netinet6/ip6_forward.c:1.102
--- src/sys/netinet6/ip6_forward.c:1.101	Fri Aug 28 06:28:58 2020
+++ src/sys/netinet6/ip6_forward.c	Fri Aug 28 06:32:24 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6_forward.c,v 1.101 2020/08/28 06:28:58 ozaki-r Exp $	*/
+/*	$NetBSD: ip6_forward.c,v 1.102 2020/08/28 06:32:24 ozaki-r Exp $	*/
 /*	$KAME: ip6_forward.c,v 1.109 2002/09/11 08:10:17 sakane Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip6_forward.c,v 1.101 2020/08/28 06:28:58 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_forward.c,v 1.102 2020/08/28 06:32:24 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_gateway.h"
@@ -287,6 +287,7 @@ ip6_forward(struct mbuf *m, int srcrt, s
 	}
 
 	if (m->m_pkthdr.len > rt->rt_ifp->if_mtu) {
+		IP6_STATINC(IP6_STAT_TOOBIG);
 		in6_ifstat_inc(rt->rt_ifp, ifs6_in_toobig);
 		if (mcopy)
 			icmp6_error(mcopy, ICMP6_PACKET_TOO_BIG, 0,

Index: src/sys/netinet6/ip6_input.c
diff -u src/sys/netinet6/ip6_input.c:1.221 src/sys/netinet6/ip6_input.c:1.222
--- src/sys/netinet6/ip6_input.c:1.221	Fri Aug 28 06:28:58 2020
+++ src/sys/netinet6/ip6_input.c	Fri Aug 28 06:32:24 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6_input.c,v 1.221 2020/08/28 06:28:58 ozaki-r Exp $	*/
+/*	$NetBSD: ip6_input.c,v 1.222 2020/08/28 06:32:24 ozaki-r Exp $	*/
 /*	$KAME: ip6_input.c,v 1.188 2001/03/29 05:34:31 itojun Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.221 2020/08/28 06:28:58 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.222 2020/08/28 06:32:24 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_gateway.h"
@@ -227,6 +227,7 @@ ip6intr(void *arg __unused)
 		struct ifnet *rcvif = m_get_rcvif_psref(m, );
 
 		if (rcvif == NULL) {
+			IP6_STATINC(IP6_STAT_IFDROP);
 			m_freem(m);
 			continue;
 		}
@@ -235,6 +236,7 @@ ip6intr(void *arg __unused)
 		 */
 		if ((ND_IFINFO(rcvif)->flags & ND6_IFF_IFDISABLED)) {
 			m_put_rcvif_psref(rcvif, );
+			IP6_STATINC(IP6_STAT_IFDROP);
 			m_freem(m);
 			continue;
 		}
@@ -396,8 +398,10 @@ ip6_input(struct mbuf *m, struct ifnet *
 	 * is not loopback.
 	 */
 	if 

CVS commit: src/sys/netinet6

2020-08-28 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Fri Aug 28 06:28:58 UTC 2020

Modified Files:
src/sys/netinet6: ip6_forward.c ip6_input.c ip6_var.h

Log Message:
inet6: pass rcvif to ip6_forward to avoid extra psref_acquire


To generate a diff of this commit:
cvs rdiff -u -r1.100 -r1.101 src/sys/netinet6/ip6_forward.c
cvs rdiff -u -r1.220 -r1.221 src/sys/netinet6/ip6_input.c
cvs rdiff -u -r1.85 -r1.86 src/sys/netinet6/ip6_var.h

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/ip6_forward.c
diff -u src/sys/netinet6/ip6_forward.c:1.100 src/sys/netinet6/ip6_forward.c:1.101
--- src/sys/netinet6/ip6_forward.c:1.100	Fri Aug 28 06:19:13 2020
+++ src/sys/netinet6/ip6_forward.c	Fri Aug 28 06:28:58 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6_forward.c,v 1.100 2020/08/28 06:19:13 ozaki-r Exp $	*/
+/*	$NetBSD: ip6_forward.c,v 1.101 2020/08/28 06:28:58 ozaki-r Exp $	*/
 /*	$KAME: ip6_forward.c,v 1.109 2002/09/11 08:10:17 sakane Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip6_forward.c,v 1.100 2020/08/28 06:19:13 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_forward.c,v 1.101 2020/08/28 06:28:58 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_gateway.h"
@@ -116,7 +116,7 @@ ip6_cantforward(const struct ip6_hdr *ip
  * protocol deal with that.
  */
 void
-ip6_forward(struct mbuf *m, int srcrt)
+ip6_forward(struct mbuf *m, int srcrt, struct ifnet *rcvif)
 {
 	struct ip6_hdr *ip6 = mtod(m, struct ip6_hdr *);
 	const struct sockaddr_in6 *dst;
@@ -126,8 +126,6 @@ ip6_forward(struct mbuf *m, int srcrt)
 	struct ifnet *origifp;	/* maybe unnecessary */
 	uint32_t inzone, outzone;
 	struct in6_addr src_in6, dst_in6;
-	struct ifnet *rcvif = NULL;
-	struct psref psref;
 	struct route *ro = NULL;
 #ifdef IPSEC
 	int needipsec = 0;
@@ -139,10 +137,6 @@ ip6_forward(struct mbuf *m, int srcrt)
 	 */
 	m->m_pkthdr.csum_flags = 0;
 
-	rcvif = m_get_rcvif_psref(m, );
-	if (__predict_false(rcvif == NULL))
-		goto drop;
-
 	/*
 	 * Do not forward packets to multicast destination (should be handled
 	 * by ip6_mforward()). Do not forward packets with unspecified source.
@@ -469,7 +463,5 @@ out:
 	rtcache_unref(rt, ro);
 	if (ro != NULL)
 		rtcache_percpu_putref(ip6_forward_rt_percpu);
-	if (rcvif != NULL)
-		m_put_rcvif_psref(rcvif, );
 	return;
 }

Index: src/sys/netinet6/ip6_input.c
diff -u src/sys/netinet6/ip6_input.c:1.220 src/sys/netinet6/ip6_input.c:1.221
--- src/sys/netinet6/ip6_input.c:1.220	Fri Aug 28 06:20:44 2020
+++ src/sys/netinet6/ip6_input.c	Fri Aug 28 06:28:58 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6_input.c,v 1.220 2020/08/28 06:20:44 ozaki-r Exp $	*/
+/*	$NetBSD: ip6_input.c,v 1.221 2020/08/28 06:28:58 ozaki-r Exp $	*/
 /*	$KAME: ip6_input.c,v 1.188 2001/03/29 05:34:31 itojun Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.220 2020/08/28 06:20:44 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.221 2020/08/28 06:28:58 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_gateway.h"
@@ -667,7 +667,7 @@ hbhcheck:
 	} else if (!ours) {
 		rtcache_unref(rt, ro);
 		rtcache_percpu_putref(ip6_forward_rt_percpu);
-		ip6_forward(m, srcrt);
+		ip6_forward(m, srcrt, rcvif);
 		return;
 	}
 

Index: src/sys/netinet6/ip6_var.h
diff -u src/sys/netinet6/ip6_var.h:1.85 src/sys/netinet6/ip6_var.h:1.86
--- src/sys/netinet6/ip6_var.h:1.85	Fri Aug 28 06:19:13 2020
+++ src/sys/netinet6/ip6_var.h	Fri Aug 28 06:28:58 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6_var.h,v 1.85 2020/08/28 06:19:13 ozaki-r Exp $	*/
+/*	$NetBSD: ip6_var.h,v 1.86 2020/08/28 06:28:58 ozaki-r Exp $	*/
 /*	$KAME: ip6_var.h,v 1.33 2000/06/11 14:59:20 jinmei Exp $	*/
 
 /*
@@ -295,7 +295,7 @@ void	ip6_notify_pmtu(struct in6pcb *, co
 		u_int32_t *);
 int	ip6_sysctl(int *, u_int, void *, size_t *, void *, size_t);
 
-void	ip6_forward(struct mbuf *, int);
+void	ip6_forward(struct mbuf *, int, struct ifnet *);
 
 void	ip6_mloopback(struct ifnet *, struct mbuf *,
 	  const struct sockaddr_in6 *);



CVS commit: src/sys/netinet6

2020-08-20 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Thu Aug 20 11:01:02 UTC 2020

Modified Files:
src/sys/netinet6: nd6.h nd6_nbr.c

Log Message:
Sprinkle some const


To generate a diff of this commit:
cvs rdiff -u -r1.89 -r1.90 src/sys/netinet6/nd6.h
cvs rdiff -u -r1.179 -r1.180 src/sys/netinet6/nd6_nbr.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/nd6.h
diff -u src/sys/netinet6/nd6.h:1.89 src/sys/netinet6/nd6.h:1.90
--- src/sys/netinet6/nd6.h:1.89	Fri Jun 12 11:04:45 2020
+++ src/sys/netinet6/nd6.h	Thu Aug 20 11:01:02 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: nd6.h,v 1.89 2020/06/12 11:04:45 roy Exp $	*/
+/*	$NetBSD: nd6.h,v 1.90 2020/08/20 11:01:02 roy Exp $	*/
 /*	$KAME: nd6.h,v 1.95 2002/06/08 11:31:06 itojun Exp $	*/
 
 /*
@@ -200,7 +200,7 @@ void nd6_na_output(struct ifnet *, const
 	const struct in6_addr *, u_long, int, const struct sockaddr *);
 void nd6_ns_input(struct mbuf *, int, int);
 void nd6_ns_output(struct ifnet *, const struct in6_addr *,
-	const struct in6_addr *, struct in6_addr *, uint8_t *);
+	const struct in6_addr *, const struct in6_addr *, const uint8_t *);
 const void *nd6_ifptomac(const struct ifnet *);
 void nd6_dad_start(struct ifaddr *, int);
 void nd6_dad_stop(struct ifaddr *);

Index: src/sys/netinet6/nd6_nbr.c
diff -u src/sys/netinet6/nd6_nbr.c:1.179 src/sys/netinet6/nd6_nbr.c:1.180
--- src/sys/netinet6/nd6_nbr.c:1.179	Fri Jun 12 11:04:45 2020
+++ src/sys/netinet6/nd6_nbr.c	Thu Aug 20 11:01:02 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: nd6_nbr.c,v 1.179 2020/06/12 11:04:45 roy Exp $	*/
+/*	$NetBSD: nd6_nbr.c,v 1.180 2020/08/20 11:01:02 roy Exp $	*/
 /*	$KAME: nd6_nbr.c,v 1.61 2001/02/10 16:06:14 jinmei Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nd6_nbr.c,v 1.179 2020/06/12 11:04:45 roy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nd6_nbr.c,v 1.180 2020/08/20 11:01:02 roy Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -389,13 +389,14 @@ nd6_ns_input(struct mbuf *m, int off, in
 void
 nd6_ns_output(struct ifnet *ifp, const struct in6_addr *daddr6,
 const struct in6_addr *taddr6,
-struct in6_addr *hsrc,
-uint8_t *nonce		/* duplicate address detection */)
+const struct in6_addr *hsrc,
+const uint8_t *nonce	/* duplicate address detection */)
 {
 	struct mbuf *m;
 	struct ip6_hdr *ip6;
 	struct nd_neighbor_solicit *nd_ns;
-	struct in6_addr *src, src_in;
+	const struct in6_addr *src;
+	struct in6_addr src_in;
 	struct ip6_moptions im6o;
 	int icmp6len;
 	int maxlen;



CVS commit: src/sys/netinet6

2020-06-19 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Jun 19 16:08:06 UTC 2020

Modified Files:
src/sys/netinet6: ip6_input.c ip6_var.h

Log Message:
localify


To generate a diff of this commit:
cvs rdiff -u -r1.216 -r1.217 src/sys/netinet6/ip6_input.c
cvs rdiff -u -r1.83 -r1.84 src/sys/netinet6/ip6_var.h

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/ip6_input.c
diff -u src/sys/netinet6/ip6_input.c:1.216 src/sys/netinet6/ip6_input.c:1.217
--- src/sys/netinet6/ip6_input.c:1.216	Fri Jun 12 11:04:45 2020
+++ src/sys/netinet6/ip6_input.c	Fri Jun 19 16:08:06 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6_input.c,v 1.216 2020/06/12 11:04:45 roy Exp $	*/
+/*	$NetBSD: ip6_input.c,v 1.217 2020/06/19 16:08:06 maxv Exp $	*/
 /*	$KAME: ip6_input.c,v 1.188 2001/03/29 05:34:31 itojun Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.216 2020/06/12 11:04:45 roy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.217 2020/06/19 16:08:06 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_gateway.h"
@@ -135,9 +135,14 @@ percpu_t *ip6stat_percpu;
 percpu_t *ip6_forward_rt_percpu __cacheline_aligned;
 
 static void ip6intr(void *);
+static void ip6_input(struct mbuf *, struct ifnet *);
 static bool ip6_badaddr(struct ip6_hdr *);
 static struct m_tag *ip6_setdstifaddr(struct mbuf *, const struct in6_ifaddr *);
 
+static struct m_tag *ip6_addaux(struct mbuf *);
+static struct m_tag *ip6_findaux(struct mbuf *);
+static void ip6_delaux(struct mbuf *);
+
 static int ip6_process_hopopts(struct mbuf *, u_int8_t *, int, u_int32_t *,
 u_int32_t *);
 static struct mbuf *ip6_pullexthdr(struct mbuf *, size_t, int);
@@ -225,7 +230,7 @@ ip6intr(void *arg __unused)
 	SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE();
 }
 
-void
+static void
 ip6_input(struct mbuf *m, struct ifnet *rcvif)
 {
 	struct ip6_hdr *ip6;
@@ -1479,7 +1484,7 @@ ip6_lasthdr(struct mbuf *m, int off, int
 	}
 }
 
-struct m_tag *
+static struct m_tag *
 ip6_addaux(struct mbuf *m)
 {
 	struct m_tag *mtag;
@@ -1496,7 +1501,7 @@ ip6_addaux(struct mbuf *m)
 	return mtag;
 }
 
-struct m_tag *
+static struct m_tag *
 ip6_findaux(struct mbuf *m)
 {
 	struct m_tag *mtag;
@@ -1505,7 +1510,7 @@ ip6_findaux(struct mbuf *m)
 	return mtag;
 }
 
-void
+static void
 ip6_delaux(struct mbuf *m)
 {
 	struct m_tag *mtag;

Index: src/sys/netinet6/ip6_var.h
diff -u src/sys/netinet6/ip6_var.h:1.83 src/sys/netinet6/ip6_var.h:1.84
--- src/sys/netinet6/ip6_var.h:1.83	Fri Jun 12 11:04:45 2020
+++ src/sys/netinet6/ip6_var.h	Fri Jun 19 16:08:06 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6_var.h,v 1.83 2020/06/12 11:04:45 roy Exp $	*/
+/*	$NetBSD: ip6_var.h,v 1.84 2020/06/19 16:08:06 maxv Exp $	*/
 /*	$KAME: ip6_var.h,v 1.33 2000/06/11 14:59:20 jinmei Exp $	*/
 
 /*
@@ -276,7 +276,6 @@ int	icmp6_ctloutput(int, struct socket *
 
 struct mbuf;
 void	ip6_init(void);
-void	ip6_input(struct mbuf *, struct ifnet *);
 const struct ip6aux *ip6_getdstifaddr(struct mbuf *);
 void	ip6_freepcbopts(struct ip6_pktopts *);
 void	ip6_freemoptions(struct ip6_moptions *);
@@ -285,9 +284,6 @@ int	ip6_get_prevhdr(struct mbuf *, int);
 int	ip6_nexthdr(struct mbuf *, int, int, int *);
 int	ip6_lasthdr(struct mbuf *, int, int, int *);
 
-struct m_tag *ip6_addaux(struct mbuf *);
-struct m_tag *ip6_findaux(struct mbuf *);
-void	ip6_delaux(struct mbuf *);
 struct ip6_hdr;
 int	ip6_mforward(struct ip6_hdr *, struct ifnet *, struct mbuf *);
 int	ip6_hopopts_input(u_int32_t *, u_int32_t *, struct mbuf **, int *);



CVS commit: src/sys/netinet6

2020-06-16 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Tue Jun 16 17:12:18 UTC 2020

Modified Files:
src/sys/netinet6: in6.c in6_var.h scope6.c scope6_var.h

Log Message:
remove unused


To generate a diff of this commit:
cvs rdiff -u -r1.280 -r1.281 src/sys/netinet6/in6.c
cvs rdiff -u -r1.103 -r1.104 src/sys/netinet6/in6_var.h
cvs rdiff -u -r1.22 -r1.23 src/sys/netinet6/scope6.c
cvs rdiff -u -r1.4 -r1.5 src/sys/netinet6/scope6_var.h

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.c
diff -u src/sys/netinet6/in6.c:1.280 src/sys/netinet6/in6.c:1.281
--- src/sys/netinet6/in6.c:1.280	Sun Jun 14 14:26:17 2020
+++ src/sys/netinet6/in6.c	Tue Jun 16 17:12:18 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: in6.c,v 1.280 2020/06/14 14:26:17 roy Exp $	*/
+/*	$NetBSD: in6.c,v 1.281 2020/06/16 17:12:18 maxv Exp $	*/
 /*	$KAME: in6.c,v 1.198 2001/07/18 09:12:38 itojun Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.280 2020/06/14 14:26:17 roy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.281 2020/06/16 17:12:18 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -2000,32 +2000,6 @@ in6_matchlen(struct in6_addr *src, struc
 	return match;
 }
 
-/* XXX: to be scope conscious */
-int
-in6_are_prefix_equal(struct in6_addr *p1, struct in6_addr *p2, int len)
-{
-	int bytelen, bitlen;
-
-	/* sanity check */
-	if (len < 0 || len > 128) {
-		log(LOG_ERR, "in6_are_prefix_equal: invalid prefix length(%d)\n",
-		len);
-		return 0;
-	}
-
-	bytelen = len / NBBY;
-	bitlen = len % NBBY;
-
-	if (memcmp(>s6_addr, >s6_addr, bytelen))
-		return 0;
-	if (bitlen != 0 &&
-	p1->s6_addr[bytelen] >> (NBBY - bitlen) !=
-	p2->s6_addr[bytelen] >> (NBBY - bitlen))
-		return 0;
-
-	return 1;
-}
-
 void
 in6_prefixlen2mask(struct in6_addr *maskp, int len)
 {

Index: src/sys/netinet6/in6_var.h
diff -u src/sys/netinet6/in6_var.h:1.103 src/sys/netinet6/in6_var.h:1.104
--- src/sys/netinet6/in6_var.h:1.103	Fri Jun 12 11:04:45 2020
+++ src/sys/netinet6/in6_var.h	Tue Jun 16 17:12:18 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: in6_var.h,v 1.103 2020/06/12 11:04:45 roy Exp $	*/
+/*	$NetBSD: in6_var.h,v 1.104 2020/06/16 17:12:18 maxv Exp $	*/
 /*	$KAME: in6_var.h,v 1.81 2002/06/08 11:16:51 itojun Exp $	*/
 
 /*
@@ -624,7 +624,6 @@ struct in6_ifaddr *
 	struct psref *);
 struct in6_ifaddr *in6ifa_ifwithaddr(const struct in6_addr *, uint32_t);
 int	in6_matchlen(struct in6_addr *, struct in6_addr *);
-int	in6_are_prefix_equal(struct in6_addr *, struct in6_addr *, int);
 void	in6_prefixlen2mask(struct in6_addr *, int);
 void	in6_purge_mcast_references(struct in6_multi *);
 

Index: src/sys/netinet6/scope6.c
diff -u src/sys/netinet6/scope6.c:1.22 src/sys/netinet6/scope6.c:1.23
--- src/sys/netinet6/scope6.c:1.22	Mon Sep 23 23:12:47 2019
+++ src/sys/netinet6/scope6.c	Tue Jun 16 17:12:18 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: scope6.c,v 1.22 2019/09/23 23:12:47 kamil Exp $	*/
+/*	$NetBSD: scope6.c,v 1.23 2020/06/16 17:12:18 maxv Exp $	*/
 /*	$KAME$	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: scope6.c,v 1.22 2019/09/23 23:12:47 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: scope6.c,v 1.23 2020/06/16 17:12:18 maxv Exp $");
 
 #include 
 #include 
@@ -95,78 +95,6 @@ scope6_ifdetach(struct scope6_id *sid)
 	free(sid, M_IFADDR);
 }
 
-int
-scope6_set(struct ifnet *ifp, const struct scope6_id *idlist)
-{
-	int i;
-	int error = 0;
-	struct scope6_id *sid = SID(ifp);
-
-	if (!sid)	/* paranoid? */
-		return EINVAL;
-
-	/*
-	 * XXX: We need more consistency checks of the relationship among
-	 * scopes (e.g. an organization should be larger than a site).
-	 */
-
-	/*
-	 * TODO(XXX): after setting, we should reflect the changes to
-	 * interface addresses, routing table entries, PCB entries...
-	 */
-
-	for (i = 0; i < 16; i++) {
-		if (idlist->s6id_list[i] &&
-		idlist->s6id_list[i] != sid->s6id_list[i]) {
-			int s;
-			/*
-			 * An interface zone ID must be the corresponding
-			 * interface index by definition.
-			 */
-			if (i == IPV6_ADDR_SCOPE_INTFACELOCAL &&
-			idlist->s6id_list[i] != ifp->if_index)
-return EINVAL;
-
-			s = pserialize_read_enter();
-			if (i == IPV6_ADDR_SCOPE_LINKLOCAL &&
-			!if_byindex(idlist->s6id_list[i])) {
-/*
- * XXX: theoretically, there should be no
- * relationship between link IDs and interface
- * IDs, but we check the consistency for
- * safety in later use.
- */
-pserialize_read_exit(s);
-return EINVAL;
-			}
-			pserialize_read_exit(s);
-
-			/*
-			 * XXX: we must need lots of work in this case,
-			 * but we simply set the new value in this initial
-			 * implementation.
-			 */
-			sid->s6id_list[i] = idlist->s6id_list[i];
-		}
-	}
-
-	return error;
-}
-
-int
-scope6_get(const struct ifnet *ifp, struct scope6_id *idlist)
-{
-	/* We only need to lock the interface's afdata for SID() to work. */
-	const 

CVS commit: src/sys/netinet6

2020-06-14 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Sun Jun 14 14:26:18 UTC 2020

Modified Files:
src/sys/netinet6: in6.c

Log Message:
inet6: Allow addresses to be marked AUTOCONF from userland


To generate a diff of this commit:
cvs rdiff -u -r1.279 -r1.280 src/sys/netinet6/in6.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.c
diff -u src/sys/netinet6/in6.c:1.279 src/sys/netinet6/in6.c:1.280
--- src/sys/netinet6/in6.c:1.279	Sat Jun 13 06:05:08 2020
+++ src/sys/netinet6/in6.c	Sun Jun 14 14:26:17 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: in6.c,v 1.279 2020/06/13 06:05:08 mlelstv Exp $	*/
+/*	$NetBSD: in6.c,v 1.280 2020/06/14 14:26:17 roy Exp $	*/
 /*	$KAME: in6.c,v 1.198 2001/07/18 09:12:38 itojun Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.279 2020/06/13 06:05:08 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.280 2020/06/14 14:26:17 roy Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -682,8 +682,7 @@ in6_control1(struct socket *so, u_long c
 		if ((ifra->ifra_flags & IN6_IFF_DUPLICATED) != 0 ||
 		(ifra->ifra_flags & IN6_IFF_DETACHED) != 0 ||
 		(ifra->ifra_flags & IN6_IFF_TENTATIVE) != 0 ||
-		(ifra->ifra_flags & IN6_IFF_NODAD) != 0 ||
-		(ifra->ifra_flags & IN6_IFF_AUTOCONF) != 0) {
+		(ifra->ifra_flags & IN6_IFF_NODAD) != 0) {
 			error = EINVAL;
 			break;
 		}



CVS commit: src/sys/netinet6

2020-06-13 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Jun 13 06:05:08 UTC 2020

Modified Files:
src/sys/netinet6: in6.c

Log Message:
COMPAT_90 doesn't necessarily imply COMPAT_50. So include compat in6_var.h in
either case.

Fixes evbarm build that starts with COMPAT_60.


To generate a diff of this commit:
cvs rdiff -u -r1.278 -r1.279 src/sys/netinet6/in6.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.c
diff -u src/sys/netinet6/in6.c:1.278 src/sys/netinet6/in6.c:1.279
--- src/sys/netinet6/in6.c:1.278	Fri Jun 12 11:04:45 2020
+++ src/sys/netinet6/in6.c	Sat Jun 13 06:05:08 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: in6.c,v 1.278 2020/06/12 11:04:45 roy Exp $	*/
+/*	$NetBSD: in6.c,v 1.279 2020/06/13 06:05:08 mlelstv Exp $	*/
 /*	$KAME: in6.c,v 1.198 2001/07/18 09:12:38 itojun Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.278 2020/06/12 11:04:45 roy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.279 2020/06/13 06:05:08 mlelstv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -109,6 +109,7 @@ __KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.27
 #include 
 #endif
 #ifdef COMPAT_90
+#include 
 #include 
 #endif
 



CVS commit: src/sys/netinet6

2020-04-28 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Tue Apr 28 15:12:28 UTC 2020

Modified Files:
src/sys/netinet6: nd6.c

Log Message:
inet6: Ensure that route MTU is guarded by ARC_PHDS_MAXMTU

This mirrors the ARP behavior for ARCnet interfaces based on current
kernel RA handling.


To generate a diff of this commit:
cvs rdiff -u -r1.269 -r1.270 src/sys/netinet6/nd6.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/nd6.c
diff -u src/sys/netinet6/nd6.c:1.269 src/sys/netinet6/nd6.c:1.270
--- src/sys/netinet6/nd6.c:1.269	Sun Apr 12 12:13:52 2020
+++ src/sys/netinet6/nd6.c	Tue Apr 28 15:12:28 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: nd6.c,v 1.269 2020/04/12 12:13:52 roy Exp $	*/
+/*	$NetBSD: nd6.c,v 1.270 2020/04/28 15:12:28 roy Exp $	*/
 /*	$KAME: nd6.c,v 1.279 2002/06/08 11:16:51 itojun Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nd6.c,v 1.269 2020/04/12 12:13:52 roy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nd6.c,v 1.270 2020/04/28 15:12:28 roy Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -1462,8 +1462,22 @@ nd6_rtrequest(int req, struct rtentry *r
 		return;
 	}
 
-	if ((rt->rt_flags & RTF_GATEWAY) != 0)
+	if ((rt->rt_flags & RTF_GATEWAY) != 0) {
+		if (req != RTM_ADD)
+			return;
+		/*
+		 * linklayers with particular MTU limitation.
+		 */
+		switch(ifp->if_type) {
+#if NARCNET > 0
+		case IFT_ARCNET:
+			if (rt->rt_rmx.rmx_mtu > ARC_PHDS_MAXMTU) /* RFC2497 */
+rt->rt_rmx.rmx_mtu = ARC_PHDS_MAXMTU;
+			break;
+#endif
+		}
 		return;
+	}
 
 	if (nd6_need_cache(ifp) == 0 && (rt->rt_flags & RTF_HOST) == 0) {
 		RT_DPRINTF("rt_getkey(rt) = %p\n", rt_getkey(rt));



CVS commit: src/sys/netinet6

2020-04-27 Thread Robert Swindells
Module Name:src
Committed By:   rjs
Date:   Mon Apr 27 19:33:48 UTC 2020

Modified Files:
src/sys/netinet6: sctp6_usrreq.c

Log Message:
Call IPv4 handler for accept().


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/netinet6/sctp6_usrreq.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/sctp6_usrreq.c
diff -u src/sys/netinet6/sctp6_usrreq.c:1.21 src/sys/netinet6/sctp6_usrreq.c:1.22
--- src/sys/netinet6/sctp6_usrreq.c:1.21	Mon Apr 27 19:21:43 2020
+++ src/sys/netinet6/sctp6_usrreq.c	Mon Apr 27 19:33:48 2020
@@ -1,5 +1,5 @@
 /* $KAME: sctp6_usrreq.c,v 1.38 2005/08/24 08:08:56 suz Exp $ */
-/* $NetBSD: sctp6_usrreq.c,v 1.21 2020/04/27 19:21:43 rjs Exp $ */
+/* $NetBSD: sctp6_usrreq.c,v 1.22 2020/04/27 19:33:48 rjs Exp $ */
 
 /*
  * Copyright (c) 2001, 2002, 2003, 2004 Cisco Systems, Inc.
@@ -33,7 +33,7 @@
  * SUCH DAMAGE.
  */
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sctp6_usrreq.c,v 1.21 2020/04/27 19:21:43 rjs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sctp6_usrreq.c,v 1.22 2020/04/27 19:33:48 rjs Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1275,9 +1275,7 @@ sctp6_ioctl(struct socket *so, u_long cm
 static int
 sctp6_accept(struct socket *so, struct sockaddr *nam)
 {
-	KASSERT(solocked(so));
-
-	return EOPNOTSUPP;
+	return sctp_accept(so, nam);
 }
 
 static int



CVS commit: src/sys/netinet6

2020-04-24 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Fri Apr 24 17:36:55 UTC 2020

Modified Files:
src/sys/netinet6: in6_proto.c

Log Message:
Fill in .pr_usrreqs for SOCK_SEQPACKET and SOCK_STREAM variants of SCTP too.

This should allow these socket types of SCTP to operate on IPv6 family
sockets, as .pr_usrreqs must not be NULL for socreate() to succeed.


To generate a diff of this commit:
cvs rdiff -u -r1.126 -r1.127 src/sys/netinet6/in6_proto.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_proto.c
diff -u src/sys/netinet6/in6_proto.c:1.126 src/sys/netinet6/in6_proto.c:1.127
--- src/sys/netinet6/in6_proto.c:1.126	Tue Aug 14 14:49:14 2018
+++ src/sys/netinet6/in6_proto.c	Fri Apr 24 17:36:55 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: in6_proto.c,v 1.126 2018/08/14 14:49:14 maxv Exp $	*/
+/*	$NetBSD: in6_proto.c,v 1.127 2020/04/24 17:36:55 jakllsch Exp $	*/
 /*	$KAME: in6_proto.c,v 1.66 2000/10/10 15:35:47 itojun Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in6_proto.c,v 1.126 2018/08/14 14:49:14 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6_proto.c,v 1.127 2020/04/24 17:36:55 jakllsch Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_gateway.h"
@@ -335,6 +335,7 @@ const struct ip6protosw inet6sw[] = {
 	.pr_input = sctp6_input,
 	.pr_ctlinput = sctp6_ctlinput,
 	.pr_ctloutput = sctp_ctloutput,
+	.pr_usrreqs = _usrreqs,
 	.pr_drain = sctp_drain,
 },
 {	.pr_type = SOCK_STREAM,
@@ -344,6 +345,7 @@ const struct ip6protosw inet6sw[] = {
 	.pr_input = sctp6_input,
 	.pr_ctlinput = sctp6_ctlinput,
 	.pr_ctloutput = sctp_ctloutput,
+	.pr_usrreqs = _usrreqs,
 	.pr_drain = sctp_drain,
 },
 #endif /* SCTP */



CVS commit: src/sys/netinet6

2020-04-22 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Wed Apr 22 19:32:11 UTC 2020

Modified Files:
src/sys/netinet6: nd6_nbr.c

Log Message:
inet6: nd6_na_input() now considers ln_state <= ND6_LLINFO_INCOMPLETE

Otherwise if ln_state != ND6_LLINFO_INCOMPLETE and the is no lladdr
and this message was solicited then ln_state is set to ND6_LLINFO_REACHABLE
which could then cause a panic in nd6_resolve().
If ln_state > ND6_LLINFO_INCOMPLETE then it's assumed we have a lladdr.

Potentially this could have been triggered by the introduction of
ND6_LLINFO_PURGE in nd6.c r1.143 but also by the re-introduction of
ND6_LLINFO_INCOMPLETE in nd6.c r1.263.
Depending on the timing, it's technically possible to receive such
a message after the llentry is created with ND6_LLINFO_NOSTATE.


To generate a diff of this commit:
cvs rdiff -u -r1.177 -r1.178 src/sys/netinet6/nd6_nbr.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/nd6_nbr.c
diff -u src/sys/netinet6/nd6_nbr.c:1.177 src/sys/netinet6/nd6_nbr.c:1.178
--- src/sys/netinet6/nd6_nbr.c:1.177	Mon Mar  9 21:20:56 2020
+++ src/sys/netinet6/nd6_nbr.c	Wed Apr 22 19:32:11 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: nd6_nbr.c,v 1.177 2020/03/09 21:20:56 roy Exp $	*/
+/*	$NetBSD: nd6_nbr.c,v 1.178 2020/04/22 19:32:11 roy Exp $	*/
 /*	$KAME: nd6_nbr.c,v 1.61 2001/02/10 16:06:14 jinmei Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nd6_nbr.c,v 1.177 2020/03/09 21:20:56 roy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nd6_nbr.c,v 1.178 2020/04/22 19:32:11 roy Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -735,7 +735,7 @@ nd6_na_input(struct mbuf *m, int off, in
 		goto freeit;
 
 	rt_cmd = 0;
-	if (ln->ln_state == ND6_LLINFO_INCOMPLETE) {
+	if (ln->ln_state <= ND6_LLINFO_INCOMPLETE) {
 		/*
 		 * If the link-layer has address, and no lladdr option came,
 		 * discard the packet.



CVS commit: src/sys/netinet6

2020-04-13 Thread Kimmo Suominen
Module Name:src
Committed By:   kim
Date:   Mon Apr 13 14:04:27 UTC 2020

Modified Files:
src/sys/netinet6: nd6_rtr.c

Log Message:
Fix default route selection

The primary issue was that in revision 1.79 a check was added in the
nd6_defrouter_select() search loop to ignore the entry if RA processing
is enabled on its interface.  In practice this results in all entries
being ignored.

This fix reverses the condition, so that an entry is ignored when RA
processing is NOT enabled on its interface.  Further, the entry is
only ignored for being selected as the default router.  The currently
installed router must be identified regardless of the (current) status
of its interface, so that we can delete the route before installing a
new one.

I also added error logging when adding or deleting a route fails. This
should help the administrator (or kernel developer) in noticing possible
problems.

Finally, if deleting a route fails, the corresponding default route
entry no longer has its "installed" flag cleared, so that deletion will
be retried.  At a minimum, this will cause repeated messages about the
failed deletion as opposed to only getting repeated messages about the
installation of a new default route failing.

Fixes PR kern/55091 and also PR bin/54997 as far as the behaviour
observed with ndp(8).


To generate a diff of this commit:
cvs rdiff -u -r1.147 -r1.148 src/sys/netinet6/nd6_rtr.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/nd6_rtr.c
diff -u src/sys/netinet6/nd6_rtr.c:1.147 src/sys/netinet6/nd6_rtr.c:1.148
--- src/sys/netinet6/nd6_rtr.c:1.147	Fri Dec 27 10:17:56 2019
+++ src/sys/netinet6/nd6_rtr.c	Mon Apr 13 14:04:27 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: nd6_rtr.c,v 1.147 2019/12/27 10:17:56 msaitoh Exp $	*/
+/*	$NetBSD: nd6_rtr.c,v 1.148 2020/04/13 14:04:27 kim Exp $	*/
 /*	$KAME: nd6_rtr.c,v 1.95 2001/02/07 08:09:47 itojun Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nd6_rtr.c,v 1.147 2019/12/27 10:17:56 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nd6_rtr.c,v 1.148 2020/04/13 14:04:27 kim Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -487,6 +487,11 @@ defrouter_addreq(struct nd_defrouter *ne
 	if (error == 0) {
 		nd6_numroutes++;
 		newdr->installed = 1;
+	} else {
+		char ip6buf[INET6_ADDRSTRLEN];
+		log(LOG_ERR, "defrouter_addreq: "
+		"error %d adding default router %s on %s\n",
+		error, IN6_PRINT(ip6buf, >rtaddr), newdr->ifp->if_xname);
 	}
 #ifndef NET_MPSAFE
 	splx(s);
@@ -596,10 +601,15 @@ defrouter_delreq(struct nd_defrouter *dr
 
 	error = rtrequest_newmsg(RTM_DELETE, , , ,
 	RTF_GATEWAY);
-	if (error == 0)
+	if (error == 0) {
 		nd6_numroutes--;
-
-	dr->installed = 0;
+		dr->installed = 0;
+	} else {
+		char ip6buf[INET6_ADDRSTRLEN];
+		log(LOG_ERR, "defrouter_delreq: "
+		"error %d deleting default router %s on %s\n",
+		error, IN6_PRINT(ip6buf, >rtaddr), dr->ifp->if_xname);
+	}
 }
 
 /*
@@ -675,14 +685,6 @@ nd6_defrouter_select(void)
 	 * the ordering rule of the list described in defrtrlist_update().
 	 */
 	ND_DEFROUTER_LIST_FOREACH(dr) {
-		ndi = ND_IFINFO(dr->ifp);
-		if (nd6_accepts_rtadv(ndi))
-			continue;
-
-		if (selected_dr == NULL &&
-		nd6_is_llinfo_probreach(dr))
-			selected_dr = dr;
-
 		if (dr->installed && !installed_dr)
 			installed_dr = dr;
 		else if (dr->installed && installed_dr) {
@@ -690,6 +692,14 @@ nd6_defrouter_select(void)
 			log(LOG_ERR, "nd6_defrouter_select: more than one router"
 			" is installed\n");
 		}
+
+		ndi = ND_IFINFO(dr->ifp);
+		if (!nd6_accepts_rtadv(ndi))
+			continue;
+
+		if (selected_dr == NULL &&
+		nd6_is_llinfo_probreach(dr))
+			selected_dr = dr;
 	}
 	/*
 	 * If none of the default routers was found to be reachable,



CVS commit: src/sys/netinet6

2020-04-12 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Sun Apr 12 12:13:52 UTC 2020

Modified Files:
src/sys/netinet6: nd6.c

Log Message:
nd6: RTM_MISS reports RTA_AUTHOR once more

Just moves the logic to send RTM_MISS after the ICMP6 report as we
rely on that function to extract the requesting address.

Fixes PR kern/55164.


To generate a diff of this commit:
cvs rdiff -u -r1.268 -r1.269 src/sys/netinet6/nd6.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/nd6.c
diff -u src/sys/netinet6/nd6.c:1.268 src/sys/netinet6/nd6.c:1.269
--- src/sys/netinet6/nd6.c:1.268	Fri Apr  3 14:04:27 2020
+++ src/sys/netinet6/nd6.c	Sun Apr 12 12:13:52 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: nd6.c,v 1.268 2020/04/03 14:04:27 christos Exp $	*/
+/*	$NetBSD: nd6.c,v 1.269 2020/04/12 12:13:52 roy Exp $	*/
 /*	$KAME: nd6.c,v 1.279 2002/06/08 11:16:51 itojun Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nd6.c,v 1.268 2020/04/03 14:04:27 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nd6.c,v 1.269 2020/04/12 12:13:52 roy Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -458,12 +458,11 @@ nd6_llinfo_timer(void *arg)
 	struct ifnet *ifp;
 	struct nd_ifinfo *ndi = NULL;
 	bool send_ns = false;
-	struct in6_addr mdaddr6 = zeroin6_addr;
 	const struct in6_addr *daddr6 = NULL;
 	const struct in6_addr *taddr6 = >r_l3addr.addr6;
 	struct sockaddr_in6 dsin6, tsin6;
-	struct sockaddr *sa;
 	struct mbuf *m = NULL;
+	bool missed = false;
 
 	SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE();
 
@@ -493,6 +492,9 @@ nd6_llinfo_timer(void *arg)
 			break;
 		}
 
+		missed = true;
+		sockaddr_in6_init(, taddr6, 0, 0, 0);
+
 		if (ln->ln_hold) {
 			struct mbuf *m0;
 
@@ -508,15 +510,6 @@ nd6_llinfo_timer(void *arg)
 			clear_llinfo_pqueue(ln);
 		}
 
-		sockaddr_in6_init(, taddr6, 0, 0, 0);
-		if (!IN6_IS_ADDR_UNSPECIFIED()) {
-			sockaddr_in6_init(, , 0, 0, 0);
-			sa = sin6tosa();
-		} else
-			sa = NULL;
-
-		rt_clonedmsg(RTM_MISS, sa, sin6tosa(), NULL, ifp);
-
 		/*
 		 * Move to the ND6_LLINFO_WAITDELETE state for another
 		 * interval at which point the llentry will be freed
@@ -586,9 +579,19 @@ out:
 	if (ln != NULL)
 		LLE_FREE_LOCKED(ln);
 	SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE();
-	if (m) {
-		icmp6_error2(m, ICMP6_DST_UNREACH,
-		ICMP6_DST_UNREACH_ADDR, 0, ifp, );
+	if (missed) {
+		struct in6_addr mdaddr6 = zeroin6_addr;
+		struct sockaddr *sa;
+
+		if (m != NULL)
+			icmp6_error2(m, ICMP6_DST_UNREACH,
+			ICMP6_DST_UNREACH_ADDR, 0, ifp, );
+		if (!IN6_IS_ADDR_UNSPECIFIED()) {
+			sockaddr_in6_init(, , 0, 0, 0);
+			sa = sin6tosa();
+		} else
+			sa = NULL;
+		rt_clonedmsg(RTM_MISS, sa, sin6tosa(), NULL, ifp);
 	}
 }
 



CVS commit: src/sys/netinet6

2020-04-03 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Apr  3 14:04:27 UTC 2020

Modified Files:
src/sys/netinet6: nd6.c

Log Message:
PR/55030: Avoid locking against myself panic by moving the icmp error outside
the lock. Thanks ozaki-r!


To generate a diff of this commit:
cvs rdiff -u -r1.267 -r1.268 src/sys/netinet6/nd6.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/nd6.c
diff -u src/sys/netinet6/nd6.c:1.267 src/sys/netinet6/nd6.c:1.268
--- src/sys/netinet6/nd6.c:1.267	Mon Mar  9 17:20:56 2020
+++ src/sys/netinet6/nd6.c	Fri Apr  3 10:04:27 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: nd6.c,v 1.267 2020/03/09 21:20:56 roy Exp $	*/
+/*	$NetBSD: nd6.c,v 1.268 2020/04/03 14:04:27 christos Exp $	*/
 /*	$KAME: nd6.c,v 1.279 2002/06/08 11:16:51 itojun Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nd6.c,v 1.267 2020/03/09 21:20:56 roy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nd6.c,v 1.268 2020/04/03 14:04:27 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -463,6 +463,7 @@ nd6_llinfo_timer(void *arg)
 	const struct in6_addr *taddr6 = >r_l3addr.addr6;
 	struct sockaddr_in6 dsin6, tsin6;
 	struct sockaddr *sa;
+	struct mbuf *m = NULL;
 
 	SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE();
 
@@ -493,7 +494,9 @@ nd6_llinfo_timer(void *arg)
 		}
 
 		if (ln->ln_hold) {
-			struct mbuf *m = ln->ln_hold, *m0;
+			struct mbuf *m0;
+
+			m = ln->ln_hold;
 
 			/*
 			 * assuming every packet in ln_hold has
@@ -503,9 +506,6 @@ nd6_llinfo_timer(void *arg)
 			m->m_nextpkt = NULL;
 			ln->ln_hold = m0;
 			clear_llinfo_pqueue(ln);
-
-			icmp6_error2(m, ICMP6_DST_UNREACH,
-			ICMP6_DST_UNREACH_ADDR, 0, ifp, );
 		}
 
 		sockaddr_in6_init(, taddr6, 0, 0, 0);
@@ -586,6 +586,10 @@ out:
 	if (ln != NULL)
 		LLE_FREE_LOCKED(ln);
 	SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE();
+	if (m) {
+		icmp6_error2(m, ICMP6_DST_UNREACH,
+		ICMP6_DST_UNREACH_ADDR, 0, ifp, );
+	}
 }
 
 /*



CVS commit: src/sys/netinet6

2020-01-28 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed Jan 29 04:38:06 UTC 2020

Modified Files:
src/sys/netinet6: in6_l2tp.c

Log Message:
Adopt .


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/netinet6/in6_l2tp.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_l2tp.c
diff -u src/sys/netinet6/in6_l2tp.c:1.18 src/sys/netinet6/in6_l2tp.c:1.19
--- src/sys/netinet6/in6_l2tp.c:1.18	Thu Sep 19 06:07:25 2019
+++ src/sys/netinet6/in6_l2tp.c	Wed Jan 29 04:38:06 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: in6_l2tp.c,v 1.18 2019/09/19 06:07:25 knakahara Exp $	*/
+/*	$NetBSD: in6_l2tp.c,v 1.19 2020/01/29 04:38:06 thorpej Exp $	*/
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in6_l2tp.c,v 1.18 2019/09/19 06:07:25 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6_l2tp.c,v 1.19 2020/01/29 04:38:06 thorpej Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_l2tp.h"
@@ -231,7 +231,7 @@ in6_l2tp_output(struct l2tp_variant *var
 
 looped:
 	if (error)
-		ifp->if_oerrors++;
+		if_statinc(ifp, if_oerrors);
 
 	return error;
 }



CVS commit: src/sys/netinet6

2020-01-03 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Jan  3 08:53:14 UTC 2020

Modified Files:
src/sys/netinet6: ip6_mroute.c

Log Message:
Don't forget to initialize 'sin6_len'. With kASan, from time to time the
value will be bigger than the size of the source, and we get a read
overflow. With kMSan the uninitialized access is detected immediately.

Reported-by: syzbot+841ca14baccec37b4...@syzkaller.appspotmail.com


To generate a diff of this commit:
cvs rdiff -u -r1.130 -r1.131 src/sys/netinet6/ip6_mroute.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/ip6_mroute.c
diff -u src/sys/netinet6/ip6_mroute.c:1.130 src/sys/netinet6/ip6_mroute.c:1.131
--- src/sys/netinet6/ip6_mroute.c:1.130	Wed Jul 24 02:38:29 2019
+++ src/sys/netinet6/ip6_mroute.c	Fri Jan  3 08:53:14 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6_mroute.c,v 1.130 2019/07/24 02:38:29 msaitoh Exp $	*/
+/*	$NetBSD: ip6_mroute.c,v 1.131 2020/01/03 08:53:14 maxv Exp $	*/
 /*	$KAME: ip6_mroute.c,v 1.49 2001/07/25 09:21:18 jinmei Exp $	*/
 
 /*
@@ -117,7 +117,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip6_mroute.c,v 1.130 2019/07/24 02:38:29 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_mroute.c,v 1.131 2020/01/03 08:53:14 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -540,9 +540,8 @@ ip6_mrouter_done(void)
 		for (mifi = 0; mifi < nummifs; mifi++) {
 			if (mif6table[mifi].m6_ifp &&
 			!(mif6table[mifi].m6_flags & MIFF_REGISTER)) {
-sin6.sin6_family = AF_INET6;
-sin6.sin6_addr = in6addr_any;
 ifp = mif6table[mifi].m6_ifp;
+sockaddr_in6_init(, _any, 0, 0, 0);
 if_mcast_op(ifp, SIOCDELMULTI,
 sin6tocsa());
 			}
@@ -674,8 +673,7 @@ add_m6if(struct mif6ctl *mifcp)
 		 * Enable promiscuous reception of all IPv6 multicasts
 		 * from the interface.
 		 */
-		sin6.sin6_family = AF_INET6;
-		sin6.sin6_addr = in6addr_any;
+		sockaddr_in6_init(, _any, 0, 0, 0);
 		error = if_mcast_op(ifp, SIOCADDMULTI, sin6tosa());
 		splx(s);
 		if (error)
@@ -732,8 +730,7 @@ del_m6if(mifi_t *mifip)
 		 */
 		ifp = mifp->m6_ifp;
 
-		sin6.sin6_family = AF_INET6;
-		sin6.sin6_addr = in6addr_any;
+		sockaddr_in6_init(, _any, 0, 0, 0);
 		if_mcast_op(ifp, SIOCDELMULTI, sin6tosa());
 	} else {
 		if (reg_mif_num != (mifi_t)-1) {



CVS commit: src/sys/netinet6

2019-04-03 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Wed Apr  3 19:23:38 UTC 2019

Modified Files:
src/sys/netinet6: ip6_output.c

Log Message:
Fix small read overflow; harmless, because since I removed RH0, the memory
access on IPV6_RTHDR that would normally be illegal is not needed, and GCC
automatically removes it.


To generate a diff of this commit:
cvs rdiff -u -r1.217 -r1.218 src/sys/netinet6/ip6_output.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/ip6_output.c
diff -u src/sys/netinet6/ip6_output.c:1.217 src/sys/netinet6/ip6_output.c:1.218
--- src/sys/netinet6/ip6_output.c:1.217	Mon Feb  4 10:48:46 2019
+++ src/sys/netinet6/ip6_output.c	Wed Apr  3 19:23:38 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6_output.c,v 1.217 2019/02/04 10:48:46 mrg Exp $	*/
+/*	$NetBSD: ip6_output.c,v 1.218 2019/04/03 19:23:38 maxv Exp $	*/
 /*	$KAME: ip6_output.c,v 1.172 2001/03/25 09:55:56 itojun Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip6_output.c,v 1.217 2019/02/04 10:48:46 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_output.c,v 1.218 2019/04/03 19:23:38 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -2772,7 +2772,7 @@ ip6_setpktopts(struct mbuf *control, str
 			return (EINVAL);
 
 		cm = mtod(control, struct cmsghdr *);
-		if (cm->cmsg_len == 0 || cm->cmsg_len > control->m_len)
+		if (cm->cmsg_len < CMSG_LEN(0) || cm->cmsg_len > control->m_len)
 			return (EINVAL);
 		if (cm->cmsg_level != IPPROTO_IPV6)
 			continue;



CVS commit: src/sys/netinet6

2019-03-19 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Tue Mar 19 13:38:54 UTC 2019

Modified Files:
src/sys/netinet6: ip6protosw.h

Log Message:
Fix typos in comment:
- s/paylaod/payload/
- s/dstination/destination/


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/sys/netinet6/ip6protosw.h

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/ip6protosw.h
diff -u src/sys/netinet6/ip6protosw.h:1.26 src/sys/netinet6/ip6protosw.h:1.27
--- src/sys/netinet6/ip6protosw.h:1.26	Wed Sep 27 10:05:05 2017
+++ src/sys/netinet6/ip6protosw.h	Tue Mar 19 13:38:53 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6protosw.h,v 1.26 2017/09/27 10:05:05 ozaki-r Exp $	*/
+/*	$NetBSD: ip6protosw.h,v 1.27 2019/03/19 13:38:53 msaitoh Exp $	*/
 /*	$KAME: ip6protosw.h,v 1.22 2001/02/08 18:02:08 itojun Exp $	*/
 
 /*
@@ -85,7 +85,7 @@ struct in6_addr;
  * argument type for the last arg of pr_ctlinput().
  * should be consulted only with AF_INET6 family.
  *
- * IPv6 ICMP IPv6 [exthdrs] finalhdr paylaod
+ * IPv6 ICMP IPv6 [exthdrs] finalhdr payload
  * ^^^  ^
  * ||ip6c_ip6   ip6c_off
  * |ip6c_icmp6
@@ -93,7 +93,7 @@ struct in6_addr;
  *
  * ip6c_finaldst usually points to ip6c_ip6->ip6_dst.  if the original
  * (internal) packet carries a routing header, it may point the final
- * dstination address in the routing header.
+ * destination address in the routing header.
  *
  * ip6c_src: ip6c_ip6->ip6_src + scope info + flowlabel in ip6c_ip6
  *	(beware of flowlabel, if you try to compare it against others)



CVS commit: src/sys/netinet6

2019-02-24 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Mon Feb 25 07:31:32 UTC 2019

Modified Files:
src/sys/netinet6: udp6_usrreq.c

Log Message:
Fix the order in udp6_attach: soreserve should be called before
in6_pcballoc, otherwise if it fails there is still a PCB attached, and
we hit a KASSERT in socreate. In !DIAGNOSTIC this would have caused a
memory leak.

By the way I find the splsoftnet highly suspicious, in6_pcballoc already
does that.

Triggered by SyzKaller.

Reported-by: syzbot+7bace612ca3cc3e12...@syzkaller.appspotmail.com


To generate a diff of this commit:
cvs rdiff -u -r1.146 -r1.147 src/sys/netinet6/udp6_usrreq.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/udp6_usrreq.c
diff -u src/sys/netinet6/udp6_usrreq.c:1.146 src/sys/netinet6/udp6_usrreq.c:1.147
--- src/sys/netinet6/udp6_usrreq.c:1.146	Mon Jan 28 12:53:01 2019
+++ src/sys/netinet6/udp6_usrreq.c	Mon Feb 25 07:31:32 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: udp6_usrreq.c,v 1.146 2019/01/28 12:53:01 martin Exp $ */
+/* $NetBSD: udp6_usrreq.c,v 1.147 2019/02/25 07:31:32 maxv Exp $ */
 /* $KAME: udp6_usrreq.c,v 1.86 2001/05/27 17:33:00 itojun Exp $ */
 /* $KAME: udp6_output.c,v 1.43 2001/10/15 09:19:52 itojun Exp $ */
 
@@ -63,7 +63,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: udp6_usrreq.c,v 1.146 2019/01/28 12:53:01 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: udp6_usrreq.c,v 1.147 2019/02/25 07:31:32 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1045,6 +1045,11 @@ udp6_attach(struct socket *so, int proto
 	KASSERT(sotoin6pcb(so) == NULL);
 	sosetlock(so);
 
+	error = soreserve(so, udp6_sendspace, udp6_recvspace);
+	if (error) {
+		return error;
+	}
+
 	/*
 	 * MAPPED_ADDR implementation spec:
 	 *  Always attach for IPv6, and only when necessary for IPv4.
@@ -1055,10 +1060,7 @@ udp6_attach(struct socket *so, int proto
 	if (error) {
 		return error;
 	}
-	error = soreserve(so, udp6_sendspace, udp6_recvspace);
-	if (error) {
-		return error;
-	}
+
 	in6p = sotoin6pcb(so);
 	in6p->in6p_cksum = -1;	/* just to be sure */
 



CVS commit: src/sys/netinet6

2019-01-14 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Mon Jan 14 18:51:15 UTC 2019

Modified Files:
src/sys/netinet6: ip6_input.c

Log Message:
Fix bug, should be ip6_protox[].


To generate a diff of this commit:
cvs rdiff -u -r1.205 -r1.206 src/sys/netinet6/ip6_input.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/ip6_input.c
diff -u src/sys/netinet6/ip6_input.c:1.205 src/sys/netinet6/ip6_input.c:1.206
--- src/sys/netinet6/ip6_input.c:1.205	Thu Nov 15 10:23:56 2018
+++ src/sys/netinet6/ip6_input.c	Mon Jan 14 18:51:15 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6_input.c,v 1.205 2018/11/15 10:23:56 maxv Exp $	*/
+/*	$NetBSD: ip6_input.c,v 1.206 2019/01/14 18:51:15 maxv Exp $	*/
 /*	$KAME: ip6_input.c,v 1.188 2001/03/29 05:34:31 itojun Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.205 2018/11/15 10:23:56 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.206 2019/01/14 18:51:15 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_gateway.h"
@@ -739,7 +739,7 @@ hbhcheck:
 			 * header. Note that we do not visit this with
 			 * protocols with pcb layer code - like udp/tcp/raw ip.
 			 */
-			if ((inet6sw[ip_protox[nxt]].pr_flags
+			if ((inet6sw[ip6_protox[nxt]].pr_flags
 			& PR_LASTHDR) != 0) {
 int error;
 



CVS commit: src/sys/netinet6

2018-12-16 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Sun Dec 16 08:54:58 UTC 2018

Modified Files:
src/sys/netinet6: nd6.c

Log Message:
netinet6: only flush prefixes and routers for the given interface.

Unless it's lo0, where we then flush the lot.
The maintains the status-quo with ndp(8) and allows dhcpcd(8) to at least
try and work with kernel RA on one interface and dhcpcd on another.


To generate a diff of this commit:
cvs rdiff -u -r1.251 -r1.252 src/sys/netinet6/nd6.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/nd6.c
diff -u src/sys/netinet6/nd6.c:1.251 src/sys/netinet6/nd6.c:1.252
--- src/sys/netinet6/nd6.c:1.251	Tue Oct 30 05:54:41 2018
+++ src/sys/netinet6/nd6.c	Sun Dec 16 08:54:58 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: nd6.c,v 1.251 2018/10/30 05:54:41 ozaki-r Exp $	*/
+/*	$NetBSD: nd6.c,v 1.252 2018/12/16 08:54:58 roy Exp $	*/
 /*	$KAME: nd6.c,v 1.279 2002/06/08 11:16:51 itojun Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nd6.c,v 1.251 2018/10/30 05:54:41 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nd6.c,v 1.252 2018/12/16 08:54:58 roy Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -1884,6 +1884,10 @@ nd6_ioctl(u_long cmd, void *data, struct
 			struct in6_ifaddr *ia, *ia_next;
 			int _s;
 
+			/* Only flush prefixes for the given interface. */
+			if (ifp != lo0ifp && ifp != pfx->ndpr_ifp)
+continue;
+
 			if (IN6_IS_ADDR_LINKLOCAL(>ndpr_prefix.sin6_addr))
 continue; /* XXX */
 
@@ -1953,8 +1957,15 @@ nd6_ioctl(u_long cmd, void *data, struct
 		struct nd_defrouter *drtr, *next;
 
 		ND6_WLOCK();
+#if 0
+		/* XXX Is this really needed? */
 		nd6_defrouter_reset();
+#endif
 		ND_DEFROUTER_LIST_FOREACH_SAFE(drtr, next) {
+			/* Only flush routers for the given interface. */
+			if (ifp != lo0ifp && ifp != drtr->ifp)
+continue;
+
 			nd6_defrtrlist_del(drtr, NULL);
 		}
 		nd6_defrouter_select();



CVS commit: src/sys/netinet6

2018-12-13 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Thu Dec 13 10:27:51 UTC 2018

Modified Files:
src/sys/netinet6: nd6_nbr.c

Log Message:
inet6: discard any received NA with a LL address we own

This matches ARP behaviour.


To generate a diff of this commit:
cvs rdiff -u -r1.162 -r1.163 src/sys/netinet6/nd6_nbr.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/nd6_nbr.c
diff -u src/sys/netinet6/nd6_nbr.c:1.162 src/sys/netinet6/nd6_nbr.c:1.163
--- src/sys/netinet6/nd6_nbr.c:1.162	Fri Dec  7 14:47:24 2018
+++ src/sys/netinet6/nd6_nbr.c	Thu Dec 13 10:27:51 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: nd6_nbr.c,v 1.162 2018/12/07 14:47:24 roy Exp $	*/
+/*	$NetBSD: nd6_nbr.c,v 1.163 2018/12/13 10:27:51 roy Exp $	*/
 /*	$KAME: nd6_nbr.c,v 1.61 2001/02/10 16:06:14 jinmei Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nd6_nbr.c,v 1.162 2018/12/07 14:47:24 roy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nd6_nbr.c,v 1.163 2018/12/13 10:27:51 roy Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -653,9 +653,26 @@ nd6_na_input(struct mbuf *m, int off, in
 		goto freeit;
 	}
 
-	if (ndopts.nd_opts_tgt_lladdr) {
+	if (ndopts.nd_opts_tgt_lladdr != NULL) {
+		struct ifnet *ifp_ll;
+		struct psref psref_ll;
+
 		lladdr = (char *)(ndopts.nd_opts_tgt_lladdr + 1);
 		lladdrlen = ndopts.nd_opts_tgt_lladdr->nd_opt_len << 3;
+
+		if (lladdr && ((ifp->if_addrlen + 2 + 7) & ~7) != lladdrlen) {
+			nd6log(LOG_INFO, "lladdrlen mismatch for %s "
+			"(if %d, NA packet %d)\n", IN6_PRINT(ip6buf, ),
+			ifp->if_addrlen, lladdrlen - 2);
+			goto bad;
+		}
+
+		ifp_ll = if_get_bylla(lladdr, ifp->if_addrlen, _ll);
+		if (ifp_ll != NULL) {
+			/* it's from me, ignore it. */
+			if_put(ifp_ll, _ll);
+			goto freeit;
+		}
 	}
 
 	ifa = (struct ifaddr *)in6ifa_ifpwithaddr_psref(ifp, , _ia);
@@ -691,13 +708,6 @@ nd6_na_input(struct mbuf *m, int off, in
 		goto bad;
 	}
 
-	if (lladdr && ((ifp->if_addrlen + 2 + 7) & ~7) != lladdrlen) {
-		nd6log(LOG_INFO, "lladdrlen mismatch for %s "
-		"(if %d, NA packet %d)\n", IN6_PRINT(ip6buf, ),
-		ifp->if_addrlen, lladdrlen - 2);
-		goto bad;
-	}
-
 	/*
 	 * If no neighbor cache entry is found, NA SHOULD silently be
 	 * discarded.



CVS commit: src/sys/netinet6

2018-12-10 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Dec 10 16:28:52 UTC 2018

Modified Files:
src/sys/netinet6: in6.h

Log Message:
need  (or arpa/inet.h) for ntohl() used in macros.


To generate a diff of this commit:
cvs rdiff -u -r1.93 -r1.94 src/sys/netinet6/in6.h

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.93 src/sys/netinet6/in6.h:1.94
--- src/sys/netinet6/in6.h:1.93	Tue Aug 21 21:05:24 2018
+++ src/sys/netinet6/in6.h	Mon Dec 10 11:28:52 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: in6.h,v 1.93 2018/08/22 01:05:24 msaitoh Exp $	*/
+/*	$NetBSD: in6.h,v 1.94 2018/12/10 16:28:52 christos Exp $	*/
 /*	$KAME: in6.h,v 1.83 2001/03/29 02:55:07 jinmei Exp $	*/
 
 /*
@@ -71,6 +71,7 @@
 #endif
 
 #include 
+#include 		/* ntohl */
 
 /*
  * Identification of the network protocol stack



CVS commit: src/sys/netinet6

2018-12-07 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Fri Dec  7 14:47:24 UTC 2018

Modified Files:
src/sys/netinet6: nd6_nbr.c

Log Message:
inet6: match NS nonce to any interface

This allows the same address to exist on many interfaces on the same
prefix, matching the inet behaviour.


To generate a diff of this commit:
cvs rdiff -u -r1.161 -r1.162 src/sys/netinet6/nd6_nbr.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/nd6_nbr.c
diff -u src/sys/netinet6/nd6_nbr.c:1.161 src/sys/netinet6/nd6_nbr.c:1.162
--- src/sys/netinet6/nd6_nbr.c:1.161	Tue Dec  4 21:16:54 2018
+++ src/sys/netinet6/nd6_nbr.c	Fri Dec  7 14:47:24 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: nd6_nbr.c,v 1.161 2018/12/04 21:16:54 roy Exp $	*/
+/*	$NetBSD: nd6_nbr.c,v 1.162 2018/12/07 14:47:24 roy Exp $	*/
 /*	$KAME: nd6_nbr.c,v 1.61 2001/02/10 16:06:14 jinmei Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nd6_nbr.c,v 1.161 2018/12/04 21:16:54 roy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nd6_nbr.c,v 1.162 2018/12/07 14:47:24 roy Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -77,6 +77,7 @@ __KERNEL_RCSID(0, "$NetBSD: nd6_nbr.c,v 
 
 struct dadq;
 static struct dadq *nd6_dad_find(struct ifaddr *, struct nd_opt_nonce *, bool *);
+static bool nd6_dad_ownnonce(struct ifaddr *, struct nd_opt_nonce *nonce);
 static void nd6_dad_starttimer(struct dadq *, int);
 static void nd6_dad_destroytimer(struct dadq *);
 static void nd6_dad_timer(struct dadq *);
@@ -309,6 +310,16 @@ nd6_ns_input(struct mbuf *m, int off, in
 		goto freeit;
 	}
 
+	/*
+	 * It looks that sender is performing DAD.
+	 * Check that the nonce is not being used by the same address
+	 * on another interface.
+	 */
+	if (IN6_IS_ADDR_UNSPECIFIED() && ndopts.nd_opts_nonce != NULL) {
+		if (nd6_dad_ownnonce(ifa, ndopts.nd_opts_nonce))
+			goto freeit;
+	}
+
 	ifa_release(ifa, _ia);
 	ifa = NULL;
 
@@ -1088,17 +1099,33 @@ static kmutex_t nd6_dad_lock;
 static struct dadq *
 nd6_dad_find(struct ifaddr *ifa, struct nd_opt_nonce *nonce, bool *found_nonce)
 {
+	struct in6_addr *myaddr6, *dadaddr6;
+	bool match_ifa;
 	struct dadq *dp;
 	int i, nonce_max;
 
 	KASSERT(mutex_owned(_dad_lock));
+	KASSERT(ifa != NULL);
+
+	myaddr6 = IFA_IN6(ifa);
+	if (nonce != NULL &&
+	nonce->nd_opt_nonce_len != (ND_OPT_NONCE_LEN + 2) / 8)
+		nonce = NULL;
+	match_ifa = nonce == NULL || found_nonce == NULL || *found_nonce == false;
+	if (found_nonce != NULL)
+		*found_nonce = false;
 
 	TAILQ_FOREACH(dp, , dad_list) {
-		if (dp->dad_ifa != ifa)
-			continue;
+		if (match_ifa) {
+			if (dp->dad_ifa != ifa)
+continue;
+		} else {
+			dadaddr6 = IFA_IN6(dp->dad_ifa);
+			if (!IN6_ARE_ADDR_EQUAL(myaddr6, dadaddr6))
+continue;
+		}
 
-		if (nonce == NULL ||
-		nonce->nd_opt_nonce_len != (ND_OPT_NONCE_LEN + 2) / 8)
+		if (nonce == NULL)
 			break;
 
 		nonce_max = MIN(dp->dad_ns_ocount, ND_OPT_NONCE_STORE);
@@ -1115,7 +1142,7 @@ nd6_dad_find(struct ifaddr *ifa, struct 
 			log(LOG_DEBUG,
 			"%s: detected a looped back NS message for %s\n",
 			ifa->ifa_ifp ? if_name(ifa->ifa_ifp) : "???",
-			IN6_PRINT(ip6buf, IFA_IN6(ifa)));
+			IN6_PRINT(ip6buf, myaddr6));
 			dp->dad_ns_lcount++;
 			continue;
 		}
@@ -1125,6 +1152,18 @@ nd6_dad_find(struct ifaddr *ifa, struct 
 	return dp;
 }
 
+static bool
+nd6_dad_ownnonce(struct ifaddr *ifa, struct nd_opt_nonce *nonce)
+{
+	bool found_nonce = true;
+
+	mutex_enter(_dad_lock);
+	nd6_dad_find(ifa, nonce, _nonce);
+	mutex_exit(_dad_lock);
+
+	return found_nonce;
+}
+
 static void
 nd6_dad_starttimer(struct dadq *dp, int ticks)
 {



CVS commit: src/sys/netinet6

2018-12-04 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Tue Dec  4 21:16:54 UTC 2018

Modified Files:
src/sys/netinet6: nd6_nbr.c

Log Message:
inet6: remove needless ifa_release.


To generate a diff of this commit:
cvs rdiff -u -r1.160 -r1.161 src/sys/netinet6/nd6_nbr.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/nd6_nbr.c
diff -u src/sys/netinet6/nd6_nbr.c:1.160 src/sys/netinet6/nd6_nbr.c:1.161
--- src/sys/netinet6/nd6_nbr.c:1.160	Tue Dec  4 21:01:48 2018
+++ src/sys/netinet6/nd6_nbr.c	Tue Dec  4 21:16:54 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: nd6_nbr.c,v 1.160 2018/12/04 21:01:48 roy Exp $	*/
+/*	$NetBSD: nd6_nbr.c,v 1.161 2018/12/04 21:16:54 roy Exp $	*/
 /*	$KAME: nd6_nbr.c,v 1.61 2001/02/10 16:06:14 jinmei Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nd6_nbr.c,v 1.160 2018/12/04 21:01:48 roy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nd6_nbr.c,v 1.161 2018/12/04 21:16:54 roy Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -306,11 +306,9 @@ nd6_ns_input(struct mbuf *m, int off, in
 		 */
 		if (IN6_IS_ADDR_UNSPECIFIED())
 			nd6_dad_input(ifa, ndopts.nd_opts_nonce);
-		ifa_release(ifa, _ia);
-		ifa = NULL;
-
 		goto freeit;
 	}
+
 	ifa_release(ifa, _ia);
 	ifa = NULL;
 



CVS commit: src/sys/netinet6

2018-12-04 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Tue Dec  4 21:01:48 UTC 2018

Modified Files:
src/sys/netinet6: nd6_nbr.c

Log Message:
inet6: use one function for nd6_dad_input

Having different ones for NA and NS is a bit wasteful.


To generate a diff of this commit:
cvs rdiff -u -r1.159 -r1.160 src/sys/netinet6/nd6_nbr.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/nd6_nbr.c
diff -u src/sys/netinet6/nd6_nbr.c:1.159 src/sys/netinet6/nd6_nbr.c:1.160
--- src/sys/netinet6/nd6_nbr.c:1.159	Tue Dec  4 20:46:56 2018
+++ src/sys/netinet6/nd6_nbr.c	Tue Dec  4 21:01:48 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: nd6_nbr.c,v 1.159 2018/12/04 20:46:56 roy Exp $	*/
+/*	$NetBSD: nd6_nbr.c,v 1.160 2018/12/04 21:01:48 roy Exp $	*/
 /*	$KAME: nd6_nbr.c,v 1.61 2001/02/10 16:06:14 jinmei Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nd6_nbr.c,v 1.159 2018/12/04 20:46:56 roy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nd6_nbr.c,v 1.160 2018/12/04 21:01:48 roy Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -81,8 +81,7 @@ static void nd6_dad_starttimer(struct da
 static void nd6_dad_destroytimer(struct dadq *);
 static void nd6_dad_timer(struct dadq *);
 static void nd6_dad_ns_output(struct dadq *, struct ifaddr *);
-static void nd6_dad_ns_input(struct ifaddr *, struct nd_opt_nonce *);
-static void nd6_dad_na_input(struct ifaddr *);
+static void nd6_dad_input(struct ifaddr *, struct nd_opt_nonce *);
 static void nd6_dad_duplicated(struct ifaddr *, struct dadq *);
 
 static int dad_maxtry = 15;	/* max # of *tries* to transmit DAD packet */
@@ -306,7 +305,7 @@ nd6_ns_input(struct mbuf *m, int off, in
 		 * silently ignore it.
 		 */
 		if (IN6_IS_ADDR_UNSPECIFIED())
-			nd6_dad_ns_input(ifa, ndopts.nd_opts_nonce);
+			nd6_dad_input(ifa, ndopts.nd_opts_nonce);
 		ifa_release(ifa, _ia);
 		ifa = NULL;
 
@@ -663,7 +662,7 @@ nd6_na_input(struct mbuf *m, int off, in
 	 */
 	if (ifa) {
 		if (((struct in6_ifaddr *)ifa)->ia6_flags & IN6_IFF_TENTATIVE)
-			nd6_dad_na_input(ifa);
+			nd6_dad_input(ifa, NULL);
 		else
 			log(LOG_ERR,
 			"nd6_na_input: duplicate IP6 address %s\n",
@@ -1446,7 +1445,7 @@ nd6_dad_ns_output(struct dadq *dp, struc
 }
 
 static void
-nd6_dad_ns_input(struct ifaddr *ifa, struct nd_opt_nonce *nonce)
+nd6_dad_input(struct ifaddr *ifa, struct nd_opt_nonce *nonce)
 {
 	struct dadq *dp;
 	bool found_nonce = false;
@@ -1466,24 +1465,3 @@ nd6_dad_ns_input(struct ifaddr *ifa, str
 		ifafree(ifa);
 	}
 }
-
-static void
-nd6_dad_na_input(struct ifaddr *ifa)
-{
-	struct dadq *dp;
-
-	KASSERT(ifa != NULL);
-
-	mutex_enter(_dad_lock);
-	dp = nd6_dad_find(ifa, NULL, NULL);
-	if (dp == NULL) {
-		mutex_exit(_dad_lock);
-		return;
-	}
-
-	nd6_dad_duplicated(ifa, dp);
-	nd6_dad_stoptimer(dp);
-	mutex_exit(_dad_lock);
-	nd6_dad_destroytimer(dp);
-	ifafree(ifa);
-}



CVS commit: src/sys/netinet6

2018-12-04 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Tue Dec  4 20:46:56 UTC 2018

Modified Files:
src/sys/netinet6: nd6_nbr.c

Log Message:
inet6: simplify NA DaD checking


To generate a diff of this commit:
cvs rdiff -u -r1.158 -r1.159 src/sys/netinet6/nd6_nbr.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/nd6_nbr.c
diff -u src/sys/netinet6/nd6_nbr.c:1.158 src/sys/netinet6/nd6_nbr.c:1.159
--- src/sys/netinet6/nd6_nbr.c:1.158	Tue Dec  4 12:23:43 2018
+++ src/sys/netinet6/nd6_nbr.c	Tue Dec  4 20:46:56 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: nd6_nbr.c,v 1.158 2018/12/04 12:23:43 roy Exp $	*/
+/*	$NetBSD: nd6_nbr.c,v 1.159 2018/12/04 20:46:56 roy Exp $	*/
 /*	$KAME: nd6_nbr.c,v 1.61 2001/02/10 16:06:14 jinmei Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nd6_nbr.c,v 1.158 2018/12/04 12:23:43 roy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nd6_nbr.c,v 1.159 2018/12/04 20:46:56 roy Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -661,20 +661,13 @@ nd6_na_input(struct mbuf *m, int off, in
 	 *
 	 * Otherwise, process as defined in RFC 2461.
 	 */
-	if (ifa &&
-	(((struct in6_ifaddr *)ifa)->ia6_flags & IN6_IFF_TENTATIVE))
-	{
-		nd6_dad_na_input(ifa);
-		ifa_release(ifa, _ia);
-		ifa = NULL;
-		goto freeit;
-	}
-
-	/* Just for safety, maybe unnecessary. */
 	if (ifa) {
-		log(LOG_ERR,
-		"nd6_na_input: duplicate IP6 address %s\n",
-		IN6_PRINT(ip6buf, ));
+		if (((struct in6_ifaddr *)ifa)->ia6_flags & IN6_IFF_TENTATIVE)
+			nd6_dad_na_input(ifa);
+		else
+			log(LOG_ERR,
+			"nd6_na_input: duplicate IP6 address %s\n",
+			IN6_PRINT(ip6buf, ));
 		ifa_release(ifa, _ia);
 		ifa = NULL;
 		goto freeit;



CVS commit: src/sys/netinet6

2018-12-04 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Tue Dec  4 12:23:43 UTC 2018

Modified Files:
src/sys/netinet6: nd6_nbr.c

Log Message:
inet6: remove unused dad ns/na counters

The current DaD code triggers when either an NS or NA is directly
received, so the counters themselves do nothing of use.


To generate a diff of this commit:
cvs rdiff -u -r1.157 -r1.158 src/sys/netinet6/nd6_nbr.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/nd6_nbr.c
diff -u src/sys/netinet6/nd6_nbr.c:1.157 src/sys/netinet6/nd6_nbr.c:1.158
--- src/sys/netinet6/nd6_nbr.c:1.157	Thu Nov 29 09:51:21 2018
+++ src/sys/netinet6/nd6_nbr.c	Tue Dec  4 12:23:43 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: nd6_nbr.c,v 1.157 2018/11/29 09:51:21 ozaki-r Exp $	*/
+/*	$NetBSD: nd6_nbr.c,v 1.158 2018/12/04 12:23:43 roy Exp $	*/
 /*	$KAME: nd6_nbr.c,v 1.61 2001/02/10 16:06:14 jinmei Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nd6_nbr.c,v 1.157 2018/11/29 09:51:21 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nd6_nbr.c,v 1.158 2018/12/04 12:23:43 roy Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -76,14 +76,14 @@ __KERNEL_RCSID(0, "$NetBSD: nd6_nbr.c,v 
 #endif
 
 struct dadq;
-static struct dadq *nd6_dad_find(struct ifaddr *, struct nd_opt_nonce *);
+static struct dadq *nd6_dad_find(struct ifaddr *, struct nd_opt_nonce *, bool *);
 static void nd6_dad_starttimer(struct dadq *, int);
 static void nd6_dad_destroytimer(struct dadq *);
 static void nd6_dad_timer(struct dadq *);
 static void nd6_dad_ns_output(struct dadq *, struct ifaddr *);
 static void nd6_dad_ns_input(struct ifaddr *, struct nd_opt_nonce *);
 static void nd6_dad_na_input(struct ifaddr *);
-static void nd6_dad_duplicated(struct dadq *);
+static void nd6_dad_duplicated(struct ifaddr *, struct dadq *);
 
 static int dad_maxtry = 15;	/* max # of *tries* to transmit DAD packet */
 
@@ -661,8 +661,9 @@ nd6_na_input(struct mbuf *m, int off, in
 	 *
 	 * Otherwise, process as defined in RFC 2461.
 	 */
-	if (ifa
-	 && (((struct in6_ifaddr *)ifa)->ia6_flags & IN6_IFF_TENTATIVE)) {
+	if (ifa &&
+	(((struct in6_ifaddr *)ifa)->ia6_flags & IN6_IFF_TENTATIVE))
+	{
 		nd6_dad_na_input(ifa);
 		ifa_release(ifa, _ia);
 		ifa = NULL;
@@ -1075,8 +1076,6 @@ struct dadq {
 	int dad_count;			/* max NS to send */
 	int dad_ns_tcount;		/* # of trials to send NS */
 	int dad_ns_ocount;		/* NS sent so far */
-	int dad_ns_icount;
-	int dad_na_icount;
 	int dad_ns_lcount;		/* looped back NS */
 	struct callout dad_timer_ch;
 #define	ND_OPT_NONCE_STORE	3	/* dad_count should not exceed this */
@@ -1097,7 +1096,7 @@ static int dad_init = 0;
 static kmutex_t nd6_dad_lock;
 
 static struct dadq *
-nd6_dad_find(struct ifaddr *ifa, struct nd_opt_nonce *nonce)
+nd6_dad_find(struct ifaddr *ifa, struct nd_opt_nonce *nonce, bool *found_nonce)
 {
 	struct dadq *dp;
 	int i, nonce_max;
@@ -1122,6 +1121,7 @@ nd6_dad_find(struct ifaddr *ifa, struct 
 		if (i < nonce_max) {
 			char ip6buf[INET6_ADDRSTRLEN];
 
+			*found_nonce = true;
 			log(LOG_DEBUG,
 			"%s: detected a looped back NS message for %s\n",
 			ifa->ifa_ifp ? if_name(ifa->ifa_ifp) : "???",
@@ -1210,7 +1210,7 @@ nd6_dad_start(struct ifaddr *ifa, int xt
 	dp = kmem_intr_alloc(sizeof(*dp), KM_NOSLEEP);
 
 	mutex_enter(_dad_lock);
-	if (nd6_dad_find(ifa, NULL) != NULL) {
+	if (nd6_dad_find(ifa, NULL, NULL) != NULL) {
 		mutex_exit(_dad_lock);
 		/* DAD already in progress */
 		if (dp != NULL)
@@ -1237,7 +1237,6 @@ nd6_dad_start(struct ifaddr *ifa, int xt
 	dp->dad_ifa = ifa;
 	ifaref(ifa);	/* just for safety */
 	dp->dad_count = ip6_dad_count;
-	dp->dad_ns_icount = dp->dad_na_icount = 0;
 	dp->dad_ns_ocount = dp->dad_ns_tcount = 0;
 	dp->dad_ns_lcount = 0;
 	TAILQ_INSERT_TAIL(, (struct dadq *)dp, dad_list);
@@ -1266,7 +1265,7 @@ nd6_dad_stop(struct ifaddr *ifa)
 		return;
 
 	mutex_enter(_dad_lock);
-	dp = nd6_dad_find(ifa, NULL);
+	dp = nd6_dad_find(ifa, NULL, NULL);
 	if (dp == NULL) {
 		mutex_exit(_dad_lock);
 		/* DAD wasn't started yet */
@@ -1287,7 +1286,6 @@ nd6_dad_timer(struct dadq *dp)
 {
 	struct ifaddr *ifa;
 	struct in6_ifaddr *ia;
-	int duplicate = 0;
 	char ip6buf[INET6_ADDRSTRLEN];
 	bool need_free = false;
 
@@ -1336,42 +1334,19 @@ nd6_dad_timer(struct dadq *dp)
 		(long)ND_IFINFO(ifa->ifa_ifp)->retrans * hz / 1000);
 	} else {
 		/*
-		 * We have transmitted sufficient number of DAD packets.
-		 * See what we've got.
+		 * We are done with DAD.  No NA came, no NS came.
+		 * No duplicate address found.
 		 */
-		if (dp->dad_na_icount) {
-			/*
-			 * the check is in nd6_dad_na_input(),
-			 * but just in case
-			 */
-			duplicate++;
-		}
-
-		if (dp->dad_ns_icount) {
-			/* We've seen NS, means DAD has failed. */
-			duplicate++;
-		}
-
-		if (duplicate) {
-			nd6_dad_duplicated(dp);
-			nd6_dad_stoptimer(dp);
-			need_free = true;
-		} else {
-			/*
-			 * We are done 

CVS commit: src/sys/netinet6

2018-11-29 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Thu Nov 29 10:02:52 UTC 2018

Modified Files:
src/sys/netinet6: ip6_output.c

Log Message:
Don't validate the source address of forwarding IPv6 packets (same as IPv4)


To generate a diff of this commit:
cvs rdiff -u -r1.212 -r1.213 src/sys/netinet6/ip6_output.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/ip6_output.c
diff -u src/sys/netinet6/ip6_output.c:1.212 src/sys/netinet6/ip6_output.c:1.213
--- src/sys/netinet6/ip6_output.c:1.212	Fri Aug 10 06:46:09 2018
+++ src/sys/netinet6/ip6_output.c	Thu Nov 29 10:02:52 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6_output.c,v 1.212 2018/08/10 06:46:09 maxv Exp $	*/
+/*	$NetBSD: ip6_output.c,v 1.213 2018/11/29 10:02:52 ozaki-r Exp $	*/
 /*	$KAME: ip6_output.c,v 1.172 2001/03/25 09:55:56 itojun Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip6_output.c,v 1.212 2018/08/10 06:46:09 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_output.c,v 1.213 2018/11/29 10:02:52 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -578,6 +578,7 @@ ip6_output(
 
 	/* Ensure we only send from a valid address. */
 	if ((ifp->if_flags & IFF_LOOPBACK) == 0 &&
+	(flags & IPV6_FORWARDING) == 0 &&
 	(error = ip6_ifaddrvalid(, )) != 0)
 	{
 		char ip6buf[INET6_ADDRSTRLEN];



CVS commit: src/sys/netinet6

2018-11-05 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Tue Nov  6 04:27:41 UTC 2018

Modified Files:
src/sys/netinet6: udp6_usrreq.c

Log Message:
Restore the length check of a sockaddr passed from userland at udp6_output

A sockaddr with invalid length could be passed to the network stack resulting in
a kernel panic like this:

panic: sockaddr_copy: source too long, 28 < 128 bytes
fatal breakpoint trap in supervisor mode
trap type 1 code 0 rip 0x80216c35 cs 0x8 rflags 0x246 cr2 
0x7f7ff7ef3000 ilevel 0x4 rsp 0x80003308b690
curlwp 0xfe803e11ca40 pid 48.1 lowest kstack 0x8000330852c0
Stopped in pid 48.1 (a.out) at  netbsd:breakpoint+0x5:  leave
db{1}> bt
breakpoint() at netbsd:breakpoint+0x5
vpanic() at netbsd:vpanic+0x140
panic() at netbsd:panic+0x3c
sockaddr_copy() at netbsd:sockaddr_copy+0x95
rtcache_setdst() at netbsd:rtcache_setdst+0x73
rtcache_lookup2() at netbsd:rtcache_lookup2+0x56
in6_selectroute() at netbsd:in6_selectroute+0x184
in6_selectsrc() at netbsd:in6_selectsrc+0x119
udp6_output() at netbsd:udp6_output+0x25e
udp6_send_wrapper() at netbsd:udp6_send_wrapper+0x8a
sosend() at netbsd:sosend+0x7bf
do_sys_sendmsg_so() at netbsd:do_sys_sendmsg_so+0x28e
do_sys_sendmsg() at netbsd:do_sys_sendmsg+0x89
sys_sendto() at netbsd:sys_sendto+0x5c
syscall() at netbsd:syscall+0x1ed
--- syscall (number 133) ---
7f7ff790173a:

Reported by Paul Ripke


To generate a diff of this commit:
cvs rdiff -u -r1.142 -r1.143 src/sys/netinet6/udp6_usrreq.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/udp6_usrreq.c
diff -u src/sys/netinet6/udp6_usrreq.c:1.142 src/sys/netinet6/udp6_usrreq.c:1.143
--- src/sys/netinet6/udp6_usrreq.c:1.142	Sun Nov  4 08:48:01 2018
+++ src/sys/netinet6/udp6_usrreq.c	Tue Nov  6 04:27:41 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: udp6_usrreq.c,v 1.142 2018/11/04 08:48:01 mlelstv Exp $ */
+/* $NetBSD: udp6_usrreq.c,v 1.143 2018/11/06 04:27:41 ozaki-r Exp $ */
 /* $KAME: udp6_usrreq.c,v 1.86 2001/05/27 17:33:00 itojun Exp $ */
 /* $KAME: udp6_output.c,v 1.43 2001/10/15 09:19:52 itojun Exp $ */
 
@@ -63,7 +63,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: udp6_usrreq.c,v 1.142 2018/11/04 08:48:01 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: udp6_usrreq.c,v 1.143 2018/11/06 04:27:41 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -668,6 +668,10 @@ udp6_output(struct in6pcb * const in6p, 
 
 	if (addr6) {
 		sin6 = addr6;
+		if (sin6->sin6_len != sizeof(*sin6)) {
+			error = EINVAL;
+			goto release;
+		}
 		if (sin6->sin6_family != AF_INET6) {
 			error = EAFNOSUPPORT;
 			goto release;



CVS commit: src/sys/netinet6

2018-11-04 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun Nov  4 08:48:01 UTC 2018

Modified Files:
src/sys/netinet6: udp6_usrreq.c

Log Message:
Fix error path in ip6 source address selection.

in6_selectsrc previously returned a pointer to an ipv6 address,
the pointer was NULL in case of an error and is checked later
instead of the also returned error code. When in6_selectsrc was
changed to store the address into a buffer, the error code
was still ignored, but the buffer pointer was never set to NULL.

As a result send() to an ipv6 address on a system that isn't
configured for ipv6 no longer returns the expected EADDRAVAIL
but fails later in ip6_output with EOPNOTSUPP when trying to
send from an unspecified address. The wrong error code caused
BIND to log the unexpected errors.


To generate a diff of this commit:
cvs rdiff -u -r1.141 -r1.142 src/sys/netinet6/udp6_usrreq.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/udp6_usrreq.c
diff -u src/sys/netinet6/udp6_usrreq.c:1.141 src/sys/netinet6/udp6_usrreq.c:1.142
--- src/sys/netinet6/udp6_usrreq.c:1.141	Sat Apr 28 13:26:57 2018
+++ src/sys/netinet6/udp6_usrreq.c	Sun Nov  4 08:48:01 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: udp6_usrreq.c,v 1.141 2018/04/28 13:26:57 maxv Exp $ */
+/* $NetBSD: udp6_usrreq.c,v 1.142 2018/11/04 08:48:01 mlelstv Exp $ */
 /* $KAME: udp6_usrreq.c,v 1.86 2001/05/27 17:33:00 itojun Exp $ */
 /* $KAME: udp6_output.c,v 1.43 2001/10/15 09:19:52 itojun Exp $ */
 
@@ -63,7 +63,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: udp6_usrreq.c,v 1.141 2018/04/28 13:26:57 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: udp6_usrreq.c,v 1.142 2018/11/04 08:48:01 mlelstv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -763,7 +763,10 @@ udp6_output(struct in6pcb * const in6p, 
 			in6p->in6p_moptions,
 			>in6p_route,
 			>in6p_laddr, , , &_laddr);
-			/* XXX need error check? */
+			if (error)
+laddr = NULL;
+			else
+laddr = &_laddr;
 			if (oifp && scope_ambiguous &&
 			(error = in6_setscope(>sin6_addr,
 			oifp, NULL))) {
@@ -773,7 +776,6 @@ udp6_output(struct in6pcb * const in6p, 
 			}
 			if_put(oifp, );
 			curlwp_bindx(bound);
-			laddr = &_laddr;
 		} else {
 			/*
 			 * XXX: freebsd[34] does not have in_selectsrc, but



CVS commit: src/sys/netinet6

2018-10-24 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Thu Oct 25 02:40:45 UTC 2018

Modified Files:
src/sys/netinet6: icmp6.c

Log Message:
Remove a leftover debug printf

Pointed out by hannken@


To generate a diff of this commit:
cvs rdiff -u -r1.239 -r1.240 src/sys/netinet6/icmp6.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/icmp6.c
diff -u src/sys/netinet6/icmp6.c:1.239 src/sys/netinet6/icmp6.c:1.240
--- src/sys/netinet6/icmp6.c:1.239	Mon Sep  3 16:29:36 2018
+++ src/sys/netinet6/icmp6.c	Thu Oct 25 02:40:45 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: icmp6.c,v 1.239 2018/09/03 16:29:36 riastradh Exp $	*/
+/*	$NetBSD: icmp6.c,v 1.240 2018/10/25 02:40:45 ozaki-r Exp $	*/
 /*	$KAME: icmp6.c,v 1.217 2001/06/20 15:03:29 jinmei Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: icmp6.c,v 1.239 2018/09/03 16:29:36 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: icmp6.c,v 1.240 2018/10/25 02:40:45 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -2861,7 +2861,6 @@ icmp6_redirect_timeout(struct rtentry *r
 
 	if ((rt->rt_flags & (RTF_GATEWAY | RTF_DYNAMIC | RTF_HOST)) ==
 	(RTF_GATEWAY | RTF_DYNAMIC | RTF_HOST)) {
-		printf("%s: RTM_DELETE\n", __func__);
 		rtrequest(RTM_DELETE, rt_getkey(rt),
 		rt->rt_gateway, rt_mask(rt), rt->rt_flags, );
 		rt_unref(rt);



CVS commit: src/sys/netinet6

2018-09-15 Thread Robert Swindells
Module Name:src
Committed By:   rjs
Date:   Sat Sep 15 13:33:15 UTC 2018

Modified Files:
src/sys/netinet6: dccp6_usrreq.c

Log Message:
Make it compile after change to non-variadic pr_input.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/netinet6/dccp6_usrreq.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/dccp6_usrreq.c
diff -u src/sys/netinet6/dccp6_usrreq.c:1.11 src/sys/netinet6/dccp6_usrreq.c:1.12
--- src/sys/netinet6/dccp6_usrreq.c:1.11	Tue Jan 24 07:09:25 2017
+++ src/sys/netinet6/dccp6_usrreq.c	Sat Sep 15 13:33:15 2018
@@ -1,5 +1,5 @@
 /*	$KAME: dccp6_usrreq.c,v 1.13 2005/07/27 08:42:56 nishida Exp $	*/
-/*	$NetBSD: dccp6_usrreq.c,v 1.11 2017/01/24 07:09:25 ozaki-r Exp $ */
+/*	$NetBSD: dccp6_usrreq.c,v 1.12 2018/09/15 13:33:15 rjs Exp $ */
 
 /*
  * Copyright (C) 2003 WIDE Project.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: dccp6_usrreq.c,v 1.11 2017/01/24 07:09:25 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dccp6_usrreq.c,v 1.12 2018/09/15 13:33:15 rjs Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -96,7 +96,7 @@ dccp6_input(struct mbuf **mp, int *offp,
 	IP6_EXTHDR_CHECK(m, *offp, sizeof(struct dccphdr), IPPROTO_DONE);
 #endif
 
-	dccp_input(m, *offp);
+	dccp_input(m, *offp, proto);
 	return IPPROTO_DONE;
 }
 



CVS commit: src/sys/netinet6

2018-08-13 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Tue Aug 14 01:10:58 UTC 2018

Modified Files:
src/sys/netinet6: nd6_rtr.c

Log Message:
Don't call find_pfxlist_reachable_router, which may sleep, in a pserialize read 
section

Found by knakahara@


To generate a diff of this commit:
cvs rdiff -u -r1.143 -r1.144 src/sys/netinet6/nd6_rtr.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/nd6_rtr.c
diff -u src/sys/netinet6/nd6_rtr.c:1.143 src/sys/netinet6/nd6_rtr.c:1.144
--- src/sys/netinet6/nd6_rtr.c:1.143	Sat May 19 08:22:58 2018
+++ src/sys/netinet6/nd6_rtr.c	Tue Aug 14 01:10:58 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: nd6_rtr.c,v 1.143 2018/05/19 08:22:58 maxv Exp $	*/
+/*	$NetBSD: nd6_rtr.c,v 1.144 2018/08/14 01:10:58 ozaki-r Exp $	*/
 /*	$KAME: nd6_rtr.c,v 1.95 2001/02/07 08:09:47 itojun Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nd6_rtr.c,v 1.143 2018/05/19 08:22:58 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nd6_rtr.c,v 1.144 2018/08/14 01:10:58 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -1586,6 +1586,7 @@ nd6_pfxlist_onlink_check(void)
 		}
 	}
 
+	int bound = curlwp_bind();
 	/*
 	 * Changes on the prefix status might affect address status as well.
 	 * Make sure that all addresses derived from an attached prefix are
@@ -1596,6 +1597,9 @@ nd6_pfxlist_onlink_check(void)
 	 */
 	s = pserialize_read_enter();
 	IN6_ADDRLIST_READER_FOREACH(ia) {
+		struct psref psref;
+		bool found;
+
 		if (!(ia->ia6_flags & IN6_IFF_AUTOCONF))
 			continue;
 
@@ -1608,14 +1612,19 @@ nd6_pfxlist_onlink_check(void)
 			continue;
 		}
 
-		if (find_pfxlist_reachable_router(ia->ia6_ndpr))
+		ia6_acquire(ia, );
+		pserialize_read_exit(s);
+
+		found = find_pfxlist_reachable_router(ia->ia6_ndpr) != NULL;
+
+		s = pserialize_read_enter();
+		ia6_release(ia, );
+		if (found)
 			break;
 	}
 	pserialize_read_exit(s);
 
 	if (ia) {
-		int bound = curlwp_bind();
-
 		s = pserialize_read_enter();
 		IN6_ADDRLIST_READER_FOREACH(ia) {
 			struct ifaddr *ifa = (struct ifaddr *)ia;
@@ -1652,11 +1661,8 @@ nd6_pfxlist_onlink_check(void)
 			ia6_release(ia, );
 		}
 		pserialize_read_exit(s);
-		curlwp_bindx(bound);
 	}
 	else {
-		int bound = curlwp_bind();
-
 		s = pserialize_read_enter();
 		IN6_ADDRLIST_READER_FOREACH(ia) {
 			if ((ia->ia6_flags & IN6_IFF_AUTOCONF) == 0)
@@ -1680,8 +1686,9 @@ nd6_pfxlist_onlink_check(void)
 			}
 		}
 		pserialize_read_exit(s);
-		curlwp_bindx(bound);
 	}
+
+	curlwp_bindx(bound);
 }
 
 static int



CVS commit: src/sys/netinet6

2018-08-10 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Aug 10 06:55:04 UTC 2018

Modified Files:
src/sys/netinet6: in6_offload.c in6_offload.h

Log Message:
Remove the callback and localify. Same as IPv4.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/netinet6/in6_offload.c
cvs rdiff -u -r1.8 -r1.9 src/sys/netinet6/in6_offload.h

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_offload.c
diff -u src/sys/netinet6/in6_offload.c:1.9 src/sys/netinet6/in6_offload.c:1.10
--- src/sys/netinet6/in6_offload.c:1.9	Fri Aug 10 06:46:09 2018
+++ src/sys/netinet6/in6_offload.c	Fri Aug 10 06:55:04 2018
@@ -1,6 +1,6 @@
-/*	$NetBSD: in6_offload.c,v 1.9 2018/08/10 06:46:09 maxv Exp $	*/
+/*	$NetBSD: in6_offload.c,v 1.10 2018/08/10 06:55:04 maxv Exp $	*/
 
-/*-
+/*
  * Copyright (c)2006 YAMAMOTO Takashi,
  * All rights reserved.
  *
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in6_offload.c,v 1.9 2018/08/10 06:46:09 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6_offload.c,v 1.10 2018/08/10 06:55:04 maxv Exp $");
 
 #include 
 #include 
@@ -43,47 +43,13 @@ __KERNEL_RCSID(0, "$NetBSD: in6_offload.
 #include 
 #include 
 
-struct ip6_tso_output_args {
-	struct ifnet *ifp;
-	struct ifnet *origifp;
-	const struct sockaddr_in6 *dst;
-	struct rtentry *rt;
-};
-
-static int ip6_tso_output_callback(void *, struct mbuf *);
-
-static int
-ip6_tso_output_callback(void *vp, struct mbuf *m)
-{
-	struct ip6_tso_output_args *args = vp;
-
-	return ip6_if_output(args->ifp, args->origifp, m, args->dst, args->rt);
-}
-
-int
-ip6_tso_output(struct ifnet *ifp, struct ifnet *origifp, struct mbuf *m,
-const struct sockaddr_in6 *dst, struct rtentry *rt)
-{
-	struct ip6_tso_output_args args;
-
-	args.ifp = ifp;
-	args.origifp = origifp;
-	args.dst = dst;
-	args.rt = rt;
-
-	return tcp6_segment(m, ip6_tso_output_callback, );
-}
-
 /*
- * tcp6_segment: handle M_CSUM_TSOv6 by software.
- *
- * => always consume m.
- * => call output_func with output_arg for each segments.
+ * Handle M_CSUM_TSOv6 in software. Split the TCP payload in chunks of
+ * size MSS, and send them.
  */
-
-int
-tcp6_segment(struct mbuf *m, int (*output_func)(void *, struct mbuf *),
-void *output_arg)
+static int
+tcp6_segment(struct ifnet *ifp, struct ifnet *origifp, struct mbuf *m,
+const struct sockaddr_in6 *dst, struct rtentry *rt)
 {
 	int mss;
 	int iphlen;
@@ -173,7 +139,7 @@ tcp6_segment(struct mbuf *m, int (*outpu
 		th->th_sum = 0;
 		th->th_sum = in6_cksum(n, IPPROTO_TCP, iphlen, thlen + mss);
 
-		error = (*output_func)(output_arg, n);
+		error = ip6_if_output(ifp, origifp, n, dst, rt);
 		if (error) {
 			goto quit;
 		}
@@ -193,6 +159,13 @@ quit:
 	return error;
 }
 
+int
+ip6_tso_output(struct ifnet *ifp, struct ifnet *origifp, struct mbuf *m,
+const struct sockaddr_in6 *dst, struct rtentry *rt)
+{
+	return tcp6_segment(ifp, origifp, m, dst, rt);
+}
+
 /*
  * Compute now in software the IP and TCP/UDP checksums. Cancel the
  * hardware offloading.

Index: src/sys/netinet6/in6_offload.h
diff -u src/sys/netinet6/in6_offload.h:1.8 src/sys/netinet6/in6_offload.h:1.9
--- src/sys/netinet6/in6_offload.h:1.8	Fri Aug 10 06:46:09 2018
+++ src/sys/netinet6/in6_offload.h	Fri Aug 10 06:55:04 2018
@@ -1,6 +1,6 @@
-/*	$NetBSD: in6_offload.h,v 1.8 2018/08/10 06:46:09 maxv Exp $	*/
+/*	$NetBSD: in6_offload.h,v 1.9 2018/08/10 06:55:04 maxv Exp $	*/
 
-/*-
+/*
  * Copyright (c)2005, 2006 YAMAMOTO Takashi,
  * All rights reserved.
  *
@@ -26,14 +26,12 @@
  * SUCH DAMAGE.
  */
 
-/*
- * subroutines to do software-only equivalent of h/w offloading.
- */
-
 #if !defined(_NETINET6_IN6_OFFLOAD_H_)
 #define	_NETINET6_IN6_OFFLOAD_H_
 
-int tcp6_segment(struct mbuf *, int (*)(void *, struct mbuf *), void *);
+/*
+ * Subroutines to do software-only equivalent of h/w offloading.
+ */
 int ip6_tso_output(struct ifnet *, struct ifnet *, struct mbuf *,
 const struct sockaddr_in6 *, struct rtentry *);
 void in6_undefer_cksum(struct mbuf *, size_t, int);



CVS commit: src/sys/netinet6

2018-07-03 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed Jul  4 00:35:34 UTC 2018

Modified Files:
src/sys/netinet6: in6.c

Log Message:
Paper over Undefined Behavior in in6_control1()

Replace calculation of maxexpire (TIME_MAX) with a construct that triggers
UB with a one that uses implementation defined semantics.

No functional change intended.

An attempt to appease KUBSAn.

Detected with Kernel Undefined Behavior Sanitizer.

Reported by 


To generate a diff of this commit:
cvs rdiff -u -r1.268 -r1.269 src/sys/netinet6/in6.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.c
diff -u src/sys/netinet6/in6.c:1.268 src/sys/netinet6/in6.c:1.269
--- src/sys/netinet6/in6.c:1.268	Tue May 29 09:10:39 2018
+++ src/sys/netinet6/in6.c	Wed Jul  4 00:35:33 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: in6.c,v 1.268 2018/05/29 09:10:39 prlw1 Exp $	*/
+/*	$NetBSD: in6.c,v 1.269 2018/07/04 00:35:33 kamil Exp $	*/
 /*	$KAME: in6.c,v 1.198 2001/07/18 09:12:38 itojun Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.268 2018/05/29 09:10:39 prlw1 Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.269 2018/07/04 00:35:33 kamil Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -632,7 +632,7 @@ in6_control1(struct socket *so, u_long c
 			 * signed.
 			 */
 			maxexpire = ((time_t)~0) &
-			~((time_t)1 << ((sizeof(maxexpire) * NBBY) - 1));
+			(time_t)~(1ULL << ((sizeof(maxexpire) * NBBY) - 1));
 			if (ia->ia6_lifetime.ia6t_vltime <
 			maxexpire - ia->ia6_updatetime) {
 retlt->ia6t_expire = ia->ia6_updatetime +
@@ -653,7 +653,7 @@ in6_control1(struct socket *so, u_long c
 			 * signed.
 			 */
 			maxexpire = ((time_t)~0) &
-			~((time_t)1 << ((sizeof(maxexpire) * NBBY) - 1));
+			(time_t)~(1ULL << ((sizeof(maxexpire) * NBBY) - 1));
 			if (ia->ia6_lifetime.ia6t_pltime <
 			maxexpire - ia->ia6_updatetime) {
 retlt->ia6t_preferred = ia->ia6_updatetime +



CVS commit: src/sys/netinet6

2018-05-29 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Tue May 29 16:21:30 UTC 2018

Modified Files:
src/sys/netinet6: ip6_output.c

Log Message:
Remove dead code, we don't care.


To generate a diff of this commit:
cvs rdiff -u -r1.209 -r1.210 src/sys/netinet6/ip6_output.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/ip6_output.c
diff -u src/sys/netinet6/ip6_output.c:1.209 src/sys/netinet6/ip6_output.c:1.210
--- src/sys/netinet6/ip6_output.c:1.209	Wed May  9 06:35:10 2018
+++ src/sys/netinet6/ip6_output.c	Tue May 29 16:21:30 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6_output.c,v 1.209 2018/05/09 06:35:10 maxv Exp $	*/
+/*	$NetBSD: ip6_output.c,v 1.210 2018/05/29 16:21:30 maxv Exp $	*/
 /*	$KAME: ip6_output.c,v 1.172 2001/03/25 09:55:56 itojun Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip6_output.c,v 1.209 2018/05/09 06:35:10 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_output.c,v 1.210 2018/05/29 16:21:30 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -875,33 +875,10 @@ ip6_output(
 		const int hlen = unfragpartlen;
 		struct ip6_frag *ip6f;
 		u_char nextproto;
-#if 0		/* see below */
-		struct ip6ctlparam ip6cp;
-		u_int32_t mtu32;
-#endif
 
 		if (mtu > IPV6_MAXPACKET)
 			mtu = IPV6_MAXPACKET;
 
-#if 0
-		/*
-		 * It is believed this code is a leftover from the
-		 * development of the IPV6_RECVPATHMTU sockopt and
-		 * associated work to implement RFC3542.
-		 * It's not entirely clear what the intent of the API
-		 * is at this point, so disable this code for now.
-		 * The IPV6_RECVPATHMTU sockopt and/or IPV6_DONTFRAG
-		 * will send notifications if the application requests.
-		 */
-
-		/* Notify a proper path MTU to applications. */
-		mtu32 = (u_int32_t)mtu;
-		memset(, 0, sizeof(ip6cp));
-		ip6cp.ip6c_cmdarg = (void *)
-		pfctlinput2(PRC_MSGSIZE,
-		rtcache_getdst(ro_pmtu), );
-#endif
-
 		/*
 		 * Must be able to put at least 8 bytes per fragment.
 		 */



CVS commit: src/sys/netinet6

2018-05-29 Thread Patrick Welche
Module Name:src
Committed By:   prlw1
Date:   Tue May 29 09:10:39 UTC 2018

Modified Files:
src/sys/netinet6: in6.c

Log Message:
Mark in6m as used for non-DIAGNOSTIC builds.


To generate a diff of this commit:
cvs rdiff -u -r1.267 -r1.268 src/sys/netinet6/in6.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.c
diff -u src/sys/netinet6/in6.c:1.267 src/sys/netinet6/in6.c:1.268
--- src/sys/netinet6/in6.c:1.267	Tue May 29 04:37:16 2018
+++ src/sys/netinet6/in6.c	Tue May 29 09:10:39 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: in6.c,v 1.267 2018/05/29 04:37:16 ozaki-r Exp $	*/
+/*	$NetBSD: in6.c,v 1.268 2018/05/29 09:10:39 prlw1 Exp $	*/
 /*	$KAME: in6.c,v 1.198 2001/07/18 09:12:38 itojun Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.267 2018/05/29 04:37:16 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.268 2018/05/29 09:10:39 prlw1 Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1405,7 +1405,7 @@ in6_purgeaddr(struct ifaddr *ifa)
 again:
 	mutex_enter(_ifaddr_lock);
 	while ((imm = LIST_FIRST(>ia6_memberships)) != NULL) {
-		struct in6_multi *in6m = imm->i6mm_maddr;
+		struct in6_multi *in6m __diagused = imm->i6mm_maddr;
 		KASSERT(in6m == NULL || in6m->in6m_ifp == ifp);
 		LIST_REMOVE(imm, i6mm_chain);
 		mutex_exit(_ifaddr_lock);



CVS commit: src/sys/netinet6

2018-05-28 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Tue May 29 04:39:26 UTC 2018

Modified Files:
src/sys/netinet6: mld6.c

Log Message:
Avoid double LIST_REMOVE which corrupts lists


To generate a diff of this commit:
cvs rdiff -u -r1.98 -r1.99 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/mld6.c
diff -u src/sys/netinet6/mld6.c:1.98 src/sys/netinet6/mld6.c:1.99
--- src/sys/netinet6/mld6.c:1.98	Tue May 29 04:38:59 2018
+++ src/sys/netinet6/mld6.c	Tue May 29 04:39:26 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: mld6.c,v 1.98 2018/05/29 04:38:59 ozaki-r Exp $	*/
+/*	$NetBSD: mld6.c,v 1.99 2018/05/29 04:39:26 ozaki-r Exp $	*/
 /*	$KAME: mld6.c,v 1.25 2001/01/16 14:14:18 itojun Exp $	*/
 
 /*
@@ -102,7 +102,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mld6.c,v 1.98 2018/05/29 04:38:59 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mld6.c,v 1.99 2018/05/29 04:39:26 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -777,12 +777,13 @@ in6m_destroy(struct in6_multi *in6m)
 	KASSERT(in6m->in6m_refcount == 0);
 
 	/*
-	 * Unlink from list.  This must be done before mld_stop_listening
-	 * because it releases in6_multilock and that allows someone to
-	 * look up the removing in6m from the list and add a reference to the
-	 * entry unexpectedly.
+	 * Unlink from list if it's listed.  This must be done before
+	 * mld_stop_listening because it releases in6_multilock and that allows
+	 * someone to look up the removing in6m from the list and add a
+	 * reference to the entry unexpectedly.
 	 */
-	LIST_REMOVE(in6m, in6m_entry);
+	if (in6_lookup_multi(>in6m_addr, in6m->in6m_ifp) != NULL)
+		LIST_REMOVE(in6m, in6m_entry);
 
 	/*
 	 * No remaining claims to this record; let MLD6 know



CVS commit: src/sys/netinet6

2018-05-28 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Tue May 29 04:38:59 UTC 2018

Modified Files:
src/sys/netinet6: mld6.c

Log Message:
Move LIST_REMOVE

mld_stoptimer releases in6_multilock temporarily, so we must LIST_REMOVE first.


To generate a diff of this commit:
cvs rdiff -u -r1.97 -r1.98 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/mld6.c
diff -u src/sys/netinet6/mld6.c:1.97 src/sys/netinet6/mld6.c:1.98
--- src/sys/netinet6/mld6.c:1.97	Tue May 29 04:38:29 2018
+++ src/sys/netinet6/mld6.c	Tue May 29 04:38:59 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: mld6.c,v 1.97 2018/05/29 04:38:29 ozaki-r Exp $	*/
+/*	$NetBSD: mld6.c,v 1.98 2018/05/29 04:38:59 ozaki-r Exp $	*/
 /*	$KAME: mld6.c,v 1.25 2001/01/16 14:14:18 itojun Exp $	*/
 
 /*
@@ -102,7 +102,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mld6.c,v 1.97 2018/05/29 04:38:29 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mld6.c,v 1.98 2018/05/29 04:38:59 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -896,6 +896,7 @@ in6_purge_multi(struct ifnet *ifp)
 
 	rw_enter(_multilock, RW_WRITER);
 	LIST_FOREACH_SAFE(in6m, >if_multiaddrs, in6m_entry, next) {
+		LIST_REMOVE(in6m, in6m_entry);
 		/*
 		 * Normally multicast addresses are already purged at this
 		 * point. Remaining references aren't accessible via ifp,
@@ -903,7 +904,6 @@ in6_purge_multi(struct ifnet *ifp)
 		 * accessed via in6m by removing it from the list of ifp.
 		 */
 		mld_stoptimer(in6m);
-		LIST_REMOVE(in6m, in6m_entry);
 	}
 	rw_exit(_multilock);
 }



CVS commit: src/sys/netinet6

2018-05-28 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Tue May 29 04:38:29 UTC 2018

Modified Files:
src/sys/netinet6: in6_var.h mld6.c nd6.c

Log Message:
Make a deletion of in6m in nd6_rtrequest atomic


To generate a diff of this commit:
cvs rdiff -u -r1.99 -r1.100 src/sys/netinet6/in6_var.h
cvs rdiff -u -r1.96 -r1.97 src/sys/netinet6/mld6.c
cvs rdiff -u -r1.248 -r1.249 src/sys/netinet6/nd6.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_var.h
diff -u src/sys/netinet6/in6_var.h:1.99 src/sys/netinet6/in6_var.h:1.100
--- src/sys/netinet6/in6_var.h:1.99	Tue May 29 04:36:47 2018
+++ src/sys/netinet6/in6_var.h	Tue May 29 04:38:29 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: in6_var.h,v 1.99 2018/05/29 04:36:47 ozaki-r Exp $	*/
+/*	$NetBSD: in6_var.h,v 1.100 2018/05/29 04:38:29 ozaki-r Exp $	*/
 /*	$KAME: in6_var.h,v 1.81 2002/06/08 11:16:51 itojun Exp $	*/
 
 /*
@@ -692,6 +692,8 @@ struct	in6_multi *in6_addmulti(struct in
 	int *, int);
 void	in6_delmulti(struct in6_multi *);
 void	in6_delmulti_locked(struct in6_multi *);
+void	in6_lookup_and_delete_multi(const struct in6_addr *,
+	const struct ifnet *);
 struct in6_multi_mship *in6_joingroup(struct ifnet *, struct in6_addr *,
 	int *, int);
 int	in6_leavegroup(struct in6_multi_mship *);

Index: src/sys/netinet6/mld6.c
diff -u src/sys/netinet6/mld6.c:1.96 src/sys/netinet6/mld6.c:1.97
--- src/sys/netinet6/mld6.c:1.96	Tue May 29 04:37:58 2018
+++ src/sys/netinet6/mld6.c	Tue May 29 04:38:29 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: mld6.c,v 1.96 2018/05/29 04:37:58 ozaki-r Exp $	*/
+/*	$NetBSD: mld6.c,v 1.97 2018/05/29 04:38:29 ozaki-r Exp $	*/
 /*	$KAME: mld6.c,v 1.25 2001/01/16 14:14:18 itojun Exp $	*/
 
 /*
@@ -102,7 +102,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mld6.c,v 1.96 2018/05/29 04:37:58 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mld6.c,v 1.97 2018/05/29 04:38:29 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -861,6 +861,19 @@ in6_lookup_multi(const struct in6_addr *
 	return in6m;
 }
 
+void
+in6_lookup_and_delete_multi(const struct in6_addr *addr,
+const struct ifnet *ifp)
+{
+	struct in6_multi *in6m;
+
+	rw_enter(_multilock, RW_WRITER);
+	in6m = in6_lookup_multi(addr, ifp);
+	if (in6m != NULL)
+		in6_delmulti_locked(in6m);
+	rw_exit(_multilock);
+}
+
 bool
 in6_multi_group(const struct in6_addr *addr, const struct ifnet *ifp)
 {

Index: src/sys/netinet6/nd6.c
diff -u src/sys/netinet6/nd6.c:1.248 src/sys/netinet6/nd6.c:1.249
--- src/sys/netinet6/nd6.c:1.248	Tue May  1 07:21:39 2018
+++ src/sys/netinet6/nd6.c	Tue May 29 04:38:29 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: nd6.c,v 1.248 2018/05/01 07:21:39 maxv Exp $	*/
+/*	$NetBSD: nd6.c,v 1.249 2018/05/29 04:38:29 ozaki-r Exp $	*/
 /*	$KAME: nd6.c,v 1.279 2002/06/08 11:16:51 itojun Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nd6.c,v 1.248 2018/05/01 07:21:39 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nd6.c,v 1.249 2018/05/29 04:38:29 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -1606,18 +1606,14 @@ nd6_rtrequest(int req, struct rtentry *r
 		if ((rt->rt_flags & RTF_ANNOUNCE) != 0 &&
 		(ifp->if_flags & IFF_MULTICAST) != 0) {
 			struct in6_addr llsol;
-			struct in6_multi *in6m;
 
 			llsol = satocsin6(rt_getkey(rt))->sin6_addr;
 			llsol.s6_addr32[0] = htonl(0xff02);
 			llsol.s6_addr32[1] = 0;
 			llsol.s6_addr32[2] = htonl(1);
 			llsol.s6_addr8[12] = 0xff;
-			if (in6_setscope(, ifp, NULL) == 0) {
-in6m = in6_lookup_multi(, ifp);
-if (in6m)
-	in6_delmulti(in6m);
-			}
+			if (in6_setscope(, ifp, NULL) == 0)
+in6_lookup_and_delete_multi(, ifp);
 		}
 		break;
 	}



CVS commit: src/sys/netinet6

2018-05-28 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Tue May 29 04:37:58 UTC 2018

Modified Files:
src/sys/netinet6: mld6.c

Log Message:
Make a refcount decrement and a removal from a list of an item atomic

in6m_refcount of an in6m can be incremented if the in6m is on the list
(if_multiaddrs) in in6_addmulti or mld_input.  So we must avoid such an
increment when we try to destroy an in6m.  To this end we must make
an in6m_refcount decrement and a removal of an in6m from if_multiaddrs
atomic.


To generate a diff of this commit:
cvs rdiff -u -r1.95 -r1.96 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/mld6.c
diff -u src/sys/netinet6/mld6.c:1.95 src/sys/netinet6/mld6.c:1.96
--- src/sys/netinet6/mld6.c:1.95	Tue May 29 04:36:47 2018
+++ src/sys/netinet6/mld6.c	Tue May 29 04:37:58 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: mld6.c,v 1.95 2018/05/29 04:36:47 ozaki-r Exp $	*/
+/*	$NetBSD: mld6.c,v 1.96 2018/05/29 04:37:58 ozaki-r Exp $	*/
 /*	$KAME: mld6.c,v 1.25 2001/01/16 14:14:18 itojun Exp $	*/
 
 /*
@@ -102,7 +102,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mld6.c,v 1.95 2018/05/29 04:36:47 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mld6.c,v 1.96 2018/05/29 04:37:58 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -777,15 +777,18 @@ in6m_destroy(struct in6_multi *in6m)
 	KASSERT(in6m->in6m_refcount == 0);
 
 	/*
-	 * No remaining claims to this record; let MLD6 know
-	 * that we are leaving the multicast group.
+	 * Unlink from list.  This must be done before mld_stop_listening
+	 * because it releases in6_multilock and that allows someone to
+	 * look up the removing in6m from the list and add a reference to the
+	 * entry unexpectedly.
 	 */
-	mld_stop_listening(in6m);
+	LIST_REMOVE(in6m, in6m_entry);
 
 	/*
-	 * Unlink from list.
+	 * No remaining claims to this record; let MLD6 know
+	 * that we are leaving the multicast group.
 	 */
-	LIST_REMOVE(in6m, in6m_entry);
+	mld_stop_listening(in6m);
 
 	/*
 	 * Delete all references of this multicasting group from



CVS commit: src/sys/netinet6

2018-05-28 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Tue May 29 04:36:48 UTC 2018

Modified Files:
src/sys/netinet6: in6_var.h mld6.c

Log Message:
Improve atomicity of in6_leavegroup and in6_delmulti


To generate a diff of this commit:
cvs rdiff -u -r1.98 -r1.99 src/sys/netinet6/in6_var.h
cvs rdiff -u -r1.94 -r1.95 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_var.h
diff -u src/sys/netinet6/in6_var.h:1.98 src/sys/netinet6/in6_var.h:1.99
--- src/sys/netinet6/in6_var.h:1.98	Thu Apr 19 21:22:02 2018
+++ src/sys/netinet6/in6_var.h	Tue May 29 04:36:47 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: in6_var.h,v 1.98 2018/04/19 21:22:02 christos Exp $	*/
+/*	$NetBSD: in6_var.h,v 1.99 2018/05/29 04:36:47 ozaki-r Exp $	*/
 /*	$KAME: in6_var.h,v 1.81 2002/06/08 11:16:51 itojun Exp $	*/
 
 /*
@@ -691,6 +691,7 @@ void	in6_purge_multi(struct ifnet *);
 struct	in6_multi *in6_addmulti(struct in6_addr *, struct ifnet *,
 	int *, int);
 void	in6_delmulti(struct in6_multi *);
+void	in6_delmulti_locked(struct in6_multi *);
 struct in6_multi_mship *in6_joingroup(struct ifnet *, struct in6_addr *,
 	int *, int);
 int	in6_leavegroup(struct in6_multi_mship *);

Index: src/sys/netinet6/mld6.c
diff -u src/sys/netinet6/mld6.c:1.94 src/sys/netinet6/mld6.c:1.95
--- src/sys/netinet6/mld6.c:1.94	Tue May 29 04:36:15 2018
+++ src/sys/netinet6/mld6.c	Tue May 29 04:36:47 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: mld6.c,v 1.94 2018/05/29 04:36:15 ozaki-r Exp $	*/
+/*	$NetBSD: mld6.c,v 1.95 2018/05/29 04:36:47 ozaki-r Exp $	*/
 /*	$KAME: mld6.c,v 1.25 2001/01/16 14:14:18 itojun Exp $	*/
 
 /*
@@ -102,7 +102,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mld6.c,v 1.94 2018/05/29 04:36:15 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mld6.c,v 1.95 2018/05/29 04:36:47 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -815,12 +815,12 @@ in6m_destroy(struct in6_multi *in6m)
  * Delete a multicast address record.
  */
 void
-in6_delmulti(struct in6_multi *in6m)
+in6_delmulti_locked(struct in6_multi *in6m)
 {
 
+	KASSERT(rw_write_held(_multilock));
 	KASSERT(in6m->in6m_refcount > 0);
 
-	rw_enter(_multilock, RW_WRITER);
 	/*
 	 * The caller should have a reference to in6m. So we don't need to care
 	 * of releasing the lock in mld_stoptimer.
@@ -828,6 +828,14 @@ in6_delmulti(struct in6_multi *in6m)
 	mld_stoptimer(in6m);
 	if (--in6m->in6m_refcount == 0)
 		in6m_destroy(in6m);
+}
+
+void
+in6_delmulti(struct in6_multi *in6m)
+{
+
+	rw_enter(_multilock, RW_WRITER);
+	in6_delmulti_locked(in6m);
 	rw_exit(_multilock);
 }
 
@@ -937,12 +945,13 @@ in6_leavegroup(struct in6_multi_mship *i
 {
 	struct in6_multi *in6m;
 
-	rw_enter(_multilock, RW_READER);
+	rw_enter(_multilock, RW_WRITER);
 	in6m = imm->i6mm_maddr;
-	rw_exit(_multilock);
+	imm->i6mm_maddr = NULL;
 	if (in6m != NULL) {
-		in6_delmulti(in6m);
+		in6_delmulti_locked(in6m);
 	}
+	rw_exit(_multilock);
 	free(imm, M_IPMADDR);
 	return 0;
 }



CVS commit: src/sys/netinet6

2018-05-28 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Tue May 29 04:37:16 UTC 2018

Modified Files:
src/sys/netinet6: in6.c

Log Message:
Avoid NULL pointer dereference on imm->i6mm_maddr


To generate a diff of this commit:
cvs rdiff -u -r1.266 -r1.267 src/sys/netinet6/in6.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.c
diff -u src/sys/netinet6/in6.c:1.266 src/sys/netinet6/in6.c:1.267
--- src/sys/netinet6/in6.c:1.266	Tue May  1 07:21:39 2018
+++ src/sys/netinet6/in6.c	Tue May 29 04:37:16 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: in6.c,v 1.266 2018/05/01 07:21:39 maxv Exp $	*/
+/*	$NetBSD: in6.c,v 1.267 2018/05/29 04:37:16 ozaki-r Exp $	*/
 /*	$KAME: in6.c,v 1.198 2001/07/18 09:12:38 itojun Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.266 2018/05/01 07:21:39 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.267 2018/05/29 04:37:16 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1405,9 +1405,11 @@ in6_purgeaddr(struct ifaddr *ifa)
 again:
 	mutex_enter(_ifaddr_lock);
 	while ((imm = LIST_FIRST(>ia6_memberships)) != NULL) {
+		struct in6_multi *in6m = imm->i6mm_maddr;
+		KASSERT(in6m == NULL || in6m->in6m_ifp == ifp);
 		LIST_REMOVE(imm, i6mm_chain);
 		mutex_exit(_ifaddr_lock);
-		KASSERT(imm->i6mm_maddr->in6m_ifp == ifp);
+
 		in6_leavegroup(imm);
 		goto again;
 	}



CVS commit: src/sys/netinet6

2018-05-28 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Tue May 29 04:36:15 UTC 2018

Modified Files:
src/sys/netinet6: mld6.c

Log Message:
Release in6_multilock on callout_halt of mld_timeo to avoid a deadlock


To generate a diff of this commit:
cvs rdiff -u -r1.93 -r1.94 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/mld6.c
diff -u src/sys/netinet6/mld6.c:1.93 src/sys/netinet6/mld6.c:1.94
--- src/sys/netinet6/mld6.c:1.93	Tue May 29 04:35:28 2018
+++ src/sys/netinet6/mld6.c	Tue May 29 04:36:15 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: mld6.c,v 1.93 2018/05/29 04:35:28 ozaki-r Exp $	*/
+/*	$NetBSD: mld6.c,v 1.94 2018/05/29 04:36:15 ozaki-r Exp $	*/
 /*	$KAME: mld6.c,v 1.25 2001/01/16 14:14:18 itojun Exp $	*/
 
 /*
@@ -102,7 +102,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mld6.c,v 1.93 2018/05/29 04:35:28 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mld6.c,v 1.94 2018/05/29 04:36:15 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -803,10 +803,12 @@ in6m_destroy(struct in6_multi *in6m)
 	/* Tell mld_timeo we're halting the timer */
 	in6m->in6m_timer = IN6M_TIMER_UNDEF;
 
+	rw_exit(_multilock);
 	callout_halt(>in6m_timer_ch, NULL);
 	callout_destroy(>in6m_timer_ch);
 
 	free(in6m, M_IPMADDR);
+	rw_enter(_multilock, RW_WRITER);
 }
 
 /*



CVS commit: src/sys/netinet6

2018-05-28 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Tue May 29 04:35:28 UTC 2018

Modified Files:
src/sys/netinet6: mld6.c

Log Message:
Don't hold softnet_lock in mld_timeo

Then we can get rid of remaining abuses of mutex_owned(softnet_lock).


To generate a diff of this commit:
cvs rdiff -u -r1.92 -r1.93 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/mld6.c
diff -u src/sys/netinet6/mld6.c:1.92 src/sys/netinet6/mld6.c:1.93
--- src/sys/netinet6/mld6.c:1.92	Tue May  1 07:21:39 2018
+++ src/sys/netinet6/mld6.c	Tue May 29 04:35:28 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: mld6.c,v 1.92 2018/05/01 07:21:39 maxv Exp $	*/
+/*	$NetBSD: mld6.c,v 1.93 2018/05/29 04:35:28 ozaki-r Exp $	*/
 /*	$KAME: mld6.c,v 1.25 2001/01/16 14:14:18 itojun Exp $	*/
 
 /*
@@ -102,7 +102,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mld6.c,v 1.92 2018/05/01 07:21:39 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mld6.c,v 1.93 2018/05/29 04:35:28 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -221,10 +221,7 @@ mld_stoptimer(struct in6_multi *in6m)
 
 	rw_exit(_multilock);
 
-	if (mutex_owned(softnet_lock))
-		callout_halt(>in6m_timer_ch, softnet_lock);
-	else
-		callout_halt(>in6m_timer_ch, NULL);
+	callout_halt(>in6m_timer_ch, NULL);
 
 	rw_enter(_multilock, RW_WRITER);
 
@@ -238,7 +235,7 @@ mld_timeo(void *arg)
 
 	KASSERT(in6m->in6m_refcount > 0);
 
-	SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE();
+	KERNEL_LOCK_UNLESS_NET_MPSAFE();
 	rw_enter(_multilock, RW_WRITER);
 	if (in6m->in6m_timer == IN6M_TIMER_UNDEF)
 		goto out;
@@ -256,7 +253,7 @@ mld_timeo(void *arg)
 
 out:
 	rw_exit(_multilock);
-	SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE();
+	KERNEL_UNLOCK_UNLESS_NET_MPSAFE();
 }
 
 static u_long
@@ -805,10 +802,8 @@ in6m_destroy(struct in6_multi *in6m)
 
 	/* Tell mld_timeo we're halting the timer */
 	in6m->in6m_timer = IN6M_TIMER_UNDEF;
-	if (mutex_owned(softnet_lock))
-		callout_halt(>in6m_timer_ch, softnet_lock);
-	else
-		callout_halt(>in6m_timer_ch, NULL);
+
+	callout_halt(>in6m_timer_ch, NULL);
 	callout_destroy(>in6m_timer_ch);
 
 	free(in6m, M_IPMADDR);



CVS commit: src/sys/netinet6

2018-05-20 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sun May 20 06:29:43 UTC 2018

Modified Files:
src/sys/netinet6: ip6_mroute.c ip6_mroute.h

Log Message:
Remove notyet, we've never had this.


To generate a diff of this commit:
cvs rdiff -u -r1.127 -r1.128 src/sys/netinet6/ip6_mroute.c
cvs rdiff -u -r1.18 -r1.19 src/sys/netinet6/ip6_mroute.h

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/ip6_mroute.c
diff -u src/sys/netinet6/ip6_mroute.c:1.127 src/sys/netinet6/ip6_mroute.c:1.128
--- src/sys/netinet6/ip6_mroute.c:1.127	Tue May  1 07:21:39 2018
+++ src/sys/netinet6/ip6_mroute.c	Sun May 20 06:29:43 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6_mroute.c,v 1.127 2018/05/01 07:21:39 maxv Exp $	*/
+/*	$NetBSD: ip6_mroute.c,v 1.128 2018/05/20 06:29:43 maxv Exp $	*/
 /*	$KAME: ip6_mroute.c,v 1.49 2001/07/25 09:21:18 jinmei Exp $	*/
 
 /*
@@ -117,7 +117,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip6_mroute.c,v 1.127 2018/05/01 07:21:39 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_mroute.c,v 1.128 2018/05/20 06:29:43 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -685,10 +685,6 @@ add_m6if(struct mif6ctl *mifcp)
 	s = splsoftnet();
 	mifp->m6_flags = mifcp->mif6c_flags;
 	mifp->m6_ifp   = ifp;
-#ifdef notyet
-	/* scaling up here allows division by 1024 in critical code */
-	mifp->m6_rate_limit = mifcp->mif6c_rate_limit * 1024 / 1000;
-#endif
 	/* initialize per mif pkt counters */
 	mifp->m6_pkt_in= 0;
 	mifp->m6_pkt_out   = 0;

Index: src/sys/netinet6/ip6_mroute.h
diff -u src/sys/netinet6/ip6_mroute.h:1.18 src/sys/netinet6/ip6_mroute.h:1.19
--- src/sys/netinet6/ip6_mroute.h:1.18	Tue Feb  6 06:32:25 2018
+++ src/sys/netinet6/ip6_mroute.h	Sun May 20 06:29:43 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6_mroute.h,v 1.18 2018/02/06 06:32:25 maxv Exp $	*/
+/*	$NetBSD: ip6_mroute.h,v 1.19 2018/05/20 06:29:43 maxv Exp $	*/
 /*	$KAME: ip6_mroute.h,v 1.17 2001/02/10 02:05:52 itojun Exp $	*/
 
 /*
@@ -103,9 +103,6 @@ struct mif6ctl {
 	mifi_t	mif6c_mifi;		/* the index of the mif to be added  */
 	u_char	mif6c_flags; 	/* MIFF_ flags defined below */
 	u_short	mif6c_pifi;		/* the index of the physical IF */
-#ifdef notyet
-	u_int	mif6c_rate_limit;/* max rate   		 */
-#endif
 };
 
 #define	MIFF_REGISTER	0x1	/* mif represents a register end-point */



CVS commit: src/sys/netinet6

2018-05-19 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat May 19 08:22:58 UTC 2018

Modified Files:
src/sys/netinet6: nd6_nbr.c nd6_rtr.c

Log Message:
Style.


To generate a diff of this commit:
cvs rdiff -u -r1.155 -r1.156 src/sys/netinet6/nd6_nbr.c
cvs rdiff -u -r1.142 -r1.143 src/sys/netinet6/nd6_rtr.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/nd6_nbr.c
diff -u src/sys/netinet6/nd6_nbr.c:1.155 src/sys/netinet6/nd6_nbr.c:1.156
--- src/sys/netinet6/nd6_nbr.c:1.155	Thu May 17 12:07:48 2018
+++ src/sys/netinet6/nd6_nbr.c	Sat May 19 08:22:58 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: nd6_nbr.c,v 1.155 2018/05/17 12:07:48 maxv Exp $	*/
+/*	$NetBSD: nd6_nbr.c,v 1.156 2018/05/19 08:22:58 maxv Exp $	*/
 /*	$KAME: nd6_nbr.c,v 1.61 2001/02/10 16:06:14 jinmei Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nd6_nbr.c,v 1.155 2018/05/17 12:07:48 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nd6_nbr.c,v 1.156 2018/05/19 08:22:58 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -164,7 +164,6 @@ nd6_ns_input(struct mbuf *m, int off, in
 		}
 	}
 
-
 	if (IN6_IS_ADDR_MULTICAST()) {
 		nd6log(LOG_INFO, "bad NS target (multicast)\n");
 		goto bad;
@@ -197,7 +196,7 @@ nd6_ns_input(struct mbuf *m, int off, in
 	 * Otherwise	MAY be omitted
 	 *
 	 * In this implementation, we omit the target link-layer address
-	 * in the "MAY" case. 
+	 * in the "MAY" case.
 	 */
 #if 0 /* too much! */
 	ifa = (struct ifaddr *)in6ifa_ifpwithaddr(ifp, );

Index: src/sys/netinet6/nd6_rtr.c
diff -u src/sys/netinet6/nd6_rtr.c:1.142 src/sys/netinet6/nd6_rtr.c:1.143
--- src/sys/netinet6/nd6_rtr.c:1.142	Fri May 18 21:03:33 2018
+++ src/sys/netinet6/nd6_rtr.c	Sat May 19 08:22:58 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: nd6_rtr.c,v 1.142 2018/05/18 21:03:33 maxv Exp $	*/
+/*	$NetBSD: nd6_rtr.c,v 1.143 2018/05/19 08:22:58 maxv Exp $	*/
 /*	$KAME: nd6_rtr.c,v 1.95 2001/02/07 08:09:47 itojun Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nd6_rtr.c,v 1.142 2018/05/18 21:03:33 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nd6_rtr.c,v 1.143 2018/05/19 08:22:58 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -230,12 +230,6 @@ nd6_ra_input(struct mbuf *m, int off, in
 	struct ip6_hdr *ip6 = mtod(m, struct ip6_hdr *);
 	struct nd_router_advert *nd_ra;
 	struct in6_addr saddr6 = ip6->ip6_src;
-#if 0
-	struct in6_addr daddr6 = ip6->ip6_dst;
-	int flags; /* = nd_ra->nd_ra_flags_reserved; */
-	int is_managed = ((flags & ND_RA_FLAG_MANAGED) != 0);
-	int is_other = ((flags & ND_RA_FLAG_OTHER) != 0);
-#endif
 	int mcast = 0;
 	union nd_opts ndopts;
 	struct nd_defrouter *dr;
@@ -248,9 +242,9 @@ nd6_ra_input(struct mbuf *m, int off, in
 
 	ndi = ND_IFINFO(ifp);
 	/*
-	 * We only accept RAs when
-	 * the system-wide variable allows the acceptance, and the
-	 * per-interface variable allows RAs on the receiving interface.
+	 * We only accept RAs when the system-wide variable allows the
+	 * acceptance, and the per-interface variable allows RAs on the
+	 * receiving interface.
 	 */
 	if (!nd6_accepts_rtadv(ndi))
 		goto freeit;
@@ -958,7 +952,7 @@ restart:
 }
 
 static int
-nd6_prelist_add(struct nd_prefixctl *prc, struct nd_defrouter *dr, 
+nd6_prelist_add(struct nd_prefixctl *prc, struct nd_defrouter *dr,
 	struct nd_prefix **newp)
 {
 	struct nd_prefix *newpr = NULL;
@@ -968,8 +962,8 @@ nd6_prelist_add(struct nd_prefixctl *prc
 
 	ND6_ASSERT_WLOCK();
 
-	if (ip6_maxifprefixes >= 0) { 
-		if (ext->nprefixes >= ip6_maxifprefixes / 2) 
+	if (ip6_maxifprefixes >= 0) {
+		if (ext->nprefixes >= ip6_maxifprefixes / 2)
 			purge_detached(prc->ndprc_ifp);
 		if (ext->nprefixes >= ip6_maxifprefixes)
 			return ENOMEM;
@@ -1104,7 +1098,7 @@ nd6_prelist_remove(struct nd_prefix *pr)
 static int
 prelist_update(struct nd_prefixctl *newprc,
 	struct nd_defrouter *dr, /* may be NULL */
-	struct mbuf *m, 
+	struct mbuf *m,
 	int mcast)
 {
 	struct in6_ifaddr *ia6_match = NULL;
@@ -2024,7 +2018,7 @@ in6_ifadd(struct nd_prefixctl *prc, int 
 int
 in6_tmpifadd(
 	const struct in6_ifaddr *ia0, /* corresponding public address */
-	int forcegen, 
+	int forcegen,
 	int dad_delay)
 {
 	struct ifnet *ifp = ia0->ia_ifa.ifa_ifp;



CVS commit: src/sys/netinet6

2018-05-19 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat May 19 06:44:08 UTC 2018

Modified Files:
src/sys/netinet6: ip6_input.c

Log Message:
Remove misleading comment.


To generate a diff of this commit:
cvs rdiff -u -r1.203 -r1.204 src/sys/netinet6/ip6_input.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/ip6_input.c
diff -u src/sys/netinet6/ip6_input.c:1.203 src/sys/netinet6/ip6_input.c:1.204
--- src/sys/netinet6/ip6_input.c:1.203	Thu May 17 11:59:36 2018
+++ src/sys/netinet6/ip6_input.c	Sat May 19 06:44:08 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6_input.c,v 1.203 2018/05/17 11:59:36 maxv Exp $	*/
+/*	$NetBSD: ip6_input.c,v 1.204 2018/05/19 06:44:08 maxv Exp $	*/
 /*	$KAME: ip6_input.c,v 1.188 2001/03/29 05:34:31 itojun Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.203 2018/05/17 11:59:36 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.204 2018/05/19 06:44:08 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_gateway.h"
@@ -1050,17 +1050,6 @@ ip6_unknown_opt(u_int8_t *optp, struct m
 	return (-1);
 }
 
-/*
- * Create the "control" list for this pcb.
- *
- * The routine will be called from upper layer handlers like tcp6_input().
- * Thus the routine assumes that the caller (tcp6_input) have already
- * called IP6_EXTHDR_CHECK() and all the extension headers are located in the
- * very first mbuf on the mbuf chain.
- * We may want to add some infinite loop prevention or sanity checks for safety.
- * (This applies only when you are using KAME mbuf chain restriction, i.e.
- * you are using IP6_EXTHDR_CHECK() not m_pulldown())
- */
 void
 ip6_savecontrol(struct in6pcb *in6p, struct mbuf **mp, 
 	struct ip6_hdr *ip6, struct mbuf *m)



CVS commit: src/sys/netinet6

2018-05-18 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri May 18 21:03:33 UTC 2018

Modified Files:
src/sys/netinet6: nd6_rtr.c

Log Message:
Add missing m_put_rcvif_psref.


To generate a diff of this commit:
cvs rdiff -u -r1.141 -r1.142 src/sys/netinet6/nd6_rtr.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/nd6_rtr.c
diff -u src/sys/netinet6/nd6_rtr.c:1.141 src/sys/netinet6/nd6_rtr.c:1.142
--- src/sys/netinet6/nd6_rtr.c:1.141	Tue May  1 07:21:39 2018
+++ src/sys/netinet6/nd6_rtr.c	Fri May 18 21:03:33 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: nd6_rtr.c,v 1.141 2018/05/01 07:21:39 maxv Exp $	*/
+/*	$NetBSD: nd6_rtr.c,v 1.142 2018/05/18 21:03:33 maxv Exp $	*/
 /*	$KAME: nd6_rtr.c,v 1.95 2001/02/07 08:09:47 itojun Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nd6_rtr.c,v 1.141 2018/05/01 07:21:39 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nd6_rtr.c,v 1.142 2018/05/18 21:03:33 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -177,6 +177,7 @@ nd6_rs_input(struct mbuf *m, int off, in
 	IP6_EXTHDR_GET(nd_rs, struct nd_router_solicit *, m, off, icmp6len);
 	if (nd_rs == NULL) {
 		ICMP6_STATINC(ICMP6_STAT_TOOSHORT);
+		m_put_rcvif_psref(ifp, );
 		return;
 	}
 



CVS commit: src/sys/netinet6

2018-05-17 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu May 17 12:07:48 UTC 2018

Modified Files:
src/sys/netinet6: nd6_nbr.c

Log Message:
Fix the KASSERTs. It doesn't matter at all since the packet can't be this
big anyway, and there are many other places that have this kind of typo;
but still fix it, for the sake of closing PR/49834.


To generate a diff of this commit:
cvs rdiff -u -r1.154 -r1.155 src/sys/netinet6/nd6_nbr.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/nd6_nbr.c
diff -u src/sys/netinet6/nd6_nbr.c:1.154 src/sys/netinet6/nd6_nbr.c:1.155
--- src/sys/netinet6/nd6_nbr.c:1.154	Tue May  1 07:21:39 2018
+++ src/sys/netinet6/nd6_nbr.c	Thu May 17 12:07:48 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: nd6_nbr.c,v 1.154 2018/05/01 07:21:39 maxv Exp $	*/
+/*	$NetBSD: nd6_nbr.c,v 1.155 2018/05/17 12:07:48 maxv Exp $	*/
 /*	$KAME: nd6_nbr.c,v 1.61 2001/02/10 16:06:14 jinmei Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nd6_nbr.c,v 1.154 2018/05/01 07:21:39 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nd6_nbr.c,v 1.155 2018/05/17 12:07:48 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -392,8 +392,8 @@ nd6_ns_output(struct ifnet *ifp, const s
 	/* estimate the size of message */
 	maxlen = sizeof(*ip6) + sizeof(*nd_ns);
 	maxlen += (sizeof(struct nd_opt_hdr) + ifp->if_addrlen + 7) & ~7;
-	KASSERTMSG(max_linkhdr + maxlen < MCLBYTES,
-	"max_linkhdr + maxlen >= MCLBYTES (%d + %d >= %d)",
+	KASSERTMSG(max_linkhdr + maxlen <= MCLBYTES,
+	"max_linkhdr + maxlen > MCLBYTES (%d + %d > %d)",
 	max_linkhdr, maxlen, MCLBYTES);
 
 	MGETHDR(m, M_DONTWAIT, MT_DATA);
@@ -922,8 +922,8 @@ nd6_na_output(
 	/* estimate the size of message */
 	maxlen = sizeof(*ip6) + sizeof(*nd_na);
 	maxlen += (sizeof(struct nd_opt_hdr) + ifp->if_addrlen + 7) & ~7;
-	KASSERTMSG(max_linkhdr + maxlen < MCLBYTES,
-	"max_linkhdr + maxlen >= MCLBYTES (%d + %d >= %d)",
+	KASSERTMSG(max_linkhdr + maxlen <= MCLBYTES,
+	"max_linkhdr + maxlen > MCLBYTES (%d + %d > %d)",
 	max_linkhdr, maxlen, MCLBYTES);
 
 	MGETHDR(m, M_DONTWAIT, MT_DATA);



CVS commit: src/sys/netinet6

2018-05-11 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri May 11 14:25:50 UTC 2018

Modified Files:
src/sys/netinet6: raw_ip6.c

Log Message:
Dedup: introduce rip6_sbappendaddr. Same as IPv4.


To generate a diff of this commit:
cvs rdiff -u -r1.171 -r1.172 src/sys/netinet6/raw_ip6.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/raw_ip6.c
diff -u src/sys/netinet6/raw_ip6.c:1.171 src/sys/netinet6/raw_ip6.c:1.172
--- src/sys/netinet6/raw_ip6.c:1.171	Sun Apr 29 07:05:13 2018
+++ src/sys/netinet6/raw_ip6.c	Fri May 11 14:25:50 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: raw_ip6.c,v 1.171 2018/04/29 07:05:13 maxv Exp $	*/
+/*	$NetBSD: raw_ip6.c,v 1.172 2018/05/11 14:25:50 maxv Exp $	*/
 /*	$KAME: raw_ip6.c,v 1.82 2001/07/23 18:57:56 jinmei Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: raw_ip6.c,v 1.171 2018/04/29 07:05:13 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: raw_ip6.c,v 1.172 2018/05/11 14:25:50 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ipsec.h"
@@ -134,6 +134,28 @@ rip6_init(void)
 	rip6stat_percpu = percpu_alloc(sizeof(uint64_t) * RIP6_NSTATS);
 }
 
+static void
+rip6_sbappendaddr(struct in6pcb *last, struct ip6_hdr *ip6,
+const struct sockaddr *sa, int hlen, struct mbuf *n)
+{
+	struct mbuf *opts = NULL;
+
+	if (last->in6p_flags & IN6P_CONTROLOPTS)
+		ip6_savecontrol(last, , ip6, n);
+
+	m_adj(n, hlen);
+
+	if (sbappendaddr(>in6p_socket->so_rcv, sa, n, opts) == 0) {
+		soroverflow(last->in6p_socket);
+		m_freem(n);
+		if (opts)
+			m_freem(opts);
+		RIP6_STATINC(RIP6_STAT_FULLSOCK);
+	} else {
+		sorwakeup(last->in6p_socket);
+	}
+}
+
 /*
  * Setup generic address and protocol structures
  * for raw_input routine, then pass them along with
@@ -148,7 +170,7 @@ rip6_input(struct mbuf **mp, int *offp, 
 	struct in6pcb *in6p;
 	struct in6pcb *last = NULL;
 	struct sockaddr_in6 rip6src;
-	struct mbuf *n, *opts = NULL;
+	struct mbuf *n;
 
 	RIP6_STATINC(RIP6_STAT_IPACKETS);
 
@@ -198,21 +220,8 @@ rip6_input(struct mbuf **mp, int *offp, 
 		}
 #endif
 		else if ((n = m_copypacket(m, M_DONTWAIT)) != NULL) {
-			if (last->in6p_flags & IN6P_CONTROLOPTS)
-ip6_savecontrol(last, , ip6, n);
-			/* strip intermediate headers */
-			m_adj(n, *offp);
-			if (sbappendaddr(>in6p_socket->so_rcv,
-			sin6tosa(), n, opts) == 0) {
-soroverflow(last->in6p_socket);
-m_freem(n);
-if (opts)
-	m_freem(opts);
-RIP6_STATINC(RIP6_STAT_FULLSOCK);
-			} else {
-sorwakeup(last->in6p_socket);
-			}
-			opts = NULL;
+			rip6_sbappendaddr(last, ip6, sin6tosa(),
+			*offp, n);
 		}
 
 		last = in6p;
@@ -225,20 +234,8 @@ rip6_input(struct mbuf **mp, int *offp, 
 		/* do not inject data into pcb */
 	} else
 #endif
-	if (last) {
-		if (last->in6p_flags & IN6P_CONTROLOPTS)
-			ip6_savecontrol(last, , ip6, m);
-		/* strip intermediate headers */
-		m_adj(m, *offp);
-		if (sbappendaddr(>in6p_socket->so_rcv,
-		sin6tosa(), m, opts) == 0) {
-			soroverflow(last->in6p_socket);
-			m_freem(m);
-			if (opts)
-m_freem(opts);
-			RIP6_STATINC(RIP6_STAT_FULLSOCK);
-		} else
-			sorwakeup(last->in6p_socket);
+	if (last != NULL) {
+		rip6_sbappendaddr(last, ip6, sin6tosa(), *offp, m);
 	} else {
 		RIP6_STATINC(RIP6_STAT_NOSOCK);
 		if (m->m_flags & M_MCAST)



CVS commit: src/sys/netinet6

2018-05-07 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Mon May  7 10:21:08 UTC 2018

Modified Files:
src/sys/netinet6: icmp6.c

Log Message:
Remove misleading comments.


To generate a diff of this commit:
cvs rdiff -u -r1.236 -r1.237 src/sys/netinet6/icmp6.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/icmp6.c
diff -u src/sys/netinet6/icmp6.c:1.236 src/sys/netinet6/icmp6.c:1.237
--- src/sys/netinet6/icmp6.c:1.236	Tue May  1 07:21:39 2018
+++ src/sys/netinet6/icmp6.c	Mon May  7 10:21:08 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: icmp6.c,v 1.236 2018/05/01 07:21:39 maxv Exp $	*/
+/*	$NetBSD: icmp6.c,v 1.237 2018/05/07 10:21:08 maxv Exp $	*/
 /*	$KAME: icmp6.c,v 1.217 2001/06/20 15:03:29 jinmei Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: icmp6.c,v 1.236 2018/05/01 07:21:39 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: icmp6.c,v 1.237 2018/05/07 10:21:08 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -766,7 +766,7 @@ _icmp6_input(struct mbuf *m, int off, in
 			memset(p, 0, 4);
 			memcpy(p + 4, hostname, maxhlen); /* meaningless TTL */
 
-			M_COPY_PKTHDR(n, m); /* just for rcvif */
+			M_COPY_PKTHDR(n, m);
 			n->m_pkthdr.len = n->m_len = sizeof(struct ip6_hdr) +
 sizeof(struct icmp6_hdr) + 4 + maxhlen;
 			nicmp6->icmp6_type = ICMP6_WRUREPLY;
@@ -1407,7 +1407,7 @@ ni6_input(struct mbuf *m, int off)
 	if (n == NULL) {
 		goto bad;
 	}
-	M_MOVE_PKTHDR(n, m); /* just for rcvif */
+	M_MOVE_PKTHDR(n, m);
 	if (replylen > MHLEN) {
 		if (replylen > MCLBYTES) {
 			/*



CVS commit: src/sys/netinet6

2018-04-29 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sun Apr 29 07:05:13 UTC 2018

Modified Files:
src/sys/netinet6: icmp6.c ip6_mroute.c raw_ip6.c

Log Message:
Replace
m_copym(m, 0, M_COPYALL, M_DONTWAIT)
by
m_copypacket(m, M_DONTWAIT)
when it is obvious that 'm' has M_PKTHDR set.


To generate a diff of this commit:
cvs rdiff -u -r1.234 -r1.235 src/sys/netinet6/icmp6.c
cvs rdiff -u -r1.125 -r1.126 src/sys/netinet6/ip6_mroute.c
cvs rdiff -u -r1.170 -r1.171 src/sys/netinet6/raw_ip6.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/icmp6.c
diff -u src/sys/netinet6/icmp6.c:1.234 src/sys/netinet6/icmp6.c:1.235
--- src/sys/netinet6/icmp6.c:1.234	Sat Apr 28 13:26:57 2018
+++ src/sys/netinet6/icmp6.c	Sun Apr 29 07:05:13 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: icmp6.c,v 1.234 2018/04/28 13:26:57 maxv Exp $	*/
+/*	$NetBSD: icmp6.c,v 1.235 2018/04/29 07:05:13 maxv Exp $	*/
 /*	$KAME: icmp6.c,v 1.217 2001/06/20 15:03:29 jinmei Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: icmp6.c,v 1.234 2018/04/28 13:26:57 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: icmp6.c,v 1.235 2018/04/29 07:05:13 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -637,7 +637,7 @@ _icmp6_input(struct mbuf *m, int off, in
 		 * copy the first part of the data into a fresh mbuf.
 		 * Otherwise, we will wrongly overwrite both copies.
 		 */
-		if ((n = m_copym(m, 0, M_COPYALL, M_DONTWAIT)) == NULL) {
+		if ((n = m_copypacket(m, M_DONTWAIT)) == NULL) {
 			/* Give up local */
 			n = m;
 			m = NULL;
@@ -686,7 +686,7 @@ _icmp6_input(struct mbuf *m, int off, in
 			icmp6_ifstat_inc(rcvif, ifs6_in_mldquery);
 		else
 			icmp6_ifstat_inc(rcvif, ifs6_in_mldreport);
-		if ((n = m_copym(m, 0, M_COPYALL, M_DONTWAIT)) == NULL) {
+		if ((n = m_copypacket(m, M_DONTWAIT)) == NULL) {
 			/* give up local */
 			mld_input(m, off);
 			m = NULL;
@@ -723,7 +723,7 @@ _icmp6_input(struct mbuf *m, int off, in
 			goto badlen;
 
 		if (mode == FQDN) {
-			n = m_copym(m, 0, M_COPYALL, M_DONTWAIT);
+			n = m_copypacket(m, M_DONTWAIT);
 			if (n)
 n = ni6_input(n, off);
 		} else {
@@ -795,7 +795,7 @@ _icmp6_input(struct mbuf *m, int off, in
 			goto badcode;
 		if (icmp6len < sizeof(struct nd_router_solicit))
 			goto badlen;
-		if ((n = m_copym(m, 0, M_COPYALL, M_DONTWAIT)) == NULL) {
+		if ((n = m_copypacket(m, M_DONTWAIT)) == NULL) {
 			/* give up local */
 			nd6_rs_input(m, off, icmp6len);
 			m = NULL;
@@ -811,7 +811,7 @@ _icmp6_input(struct mbuf *m, int off, in
 			goto badcode;
 		if (icmp6len < sizeof(struct nd_router_advert))
 			goto badlen;
-		if ((n = m_copym(m, 0, M_COPYALL, M_DONTWAIT)) == NULL) {
+		if ((n = m_copypacket(m, M_DONTWAIT)) == NULL) {
 			/* give up local */
 			nd6_ra_input(m, off, icmp6len);
 			m = NULL;
@@ -827,7 +827,7 @@ _icmp6_input(struct mbuf *m, int off, in
 			goto badcode;
 		if (icmp6len < sizeof(struct nd_neighbor_solicit))
 			goto badlen;
-		if ((n = m_copym(m, 0, M_COPYALL, M_DONTWAIT)) == NULL) {
+		if ((n = m_copypacket(m, M_DONTWAIT)) == NULL) {
 			/* give up local */
 			nd6_ns_input(m, off, icmp6len);
 			m = NULL;
@@ -843,7 +843,7 @@ _icmp6_input(struct mbuf *m, int off, in
 			goto badcode;
 		if (icmp6len < sizeof(struct nd_neighbor_advert))
 			goto badlen;
-		if ((n = m_copym(m, 0, M_COPYALL, M_DONTWAIT)) == NULL) {
+		if ((n = m_copypacket(m, M_DONTWAIT)) == NULL) {
 			/* give up local */
 			nd6_na_input(m, off, icmp6len);
 			m = NULL;
@@ -859,7 +859,7 @@ _icmp6_input(struct mbuf *m, int off, in
 			goto badcode;
 		if (icmp6len < sizeof(struct nd_redirect))
 			goto badlen;
-		if ((n = m_copym(m, 0, M_COPYALL, M_DONTWAIT)) == NULL) {
+		if ((n = m_copypacket(m, M_DONTWAIT)) == NULL) {
 			/* give up local */
 			icmp6_redirect_input(m, off);
 			m = NULL;
@@ -1966,7 +1966,7 @@ icmp6_rip6_input(struct mbuf **mp, int o
 			/* do not inject data into pcb */
 		}
 #endif
-		else if ((n = m_copym(m, 0, (int)M_COPYALL, M_DONTWAIT)) != NULL) {
+		else if ((n = m_copypacket(m, M_DONTWAIT)) != NULL) {
 			if (last->in6p_flags & IN6P_CONTROLOPTS)
 ip6_savecontrol(last, , ip6, n);
 			/* strip intermediate headers */

Index: src/sys/netinet6/ip6_mroute.c
diff -u src/sys/netinet6/ip6_mroute.c:1.125 src/sys/netinet6/ip6_mroute.c:1.126
--- src/sys/netinet6/ip6_mroute.c:1.125	Thu Apr 26 19:50:09 2018
+++ src/sys/netinet6/ip6_mroute.c	Sun Apr 29 07:05:13 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6_mroute.c,v 1.125 2018/04/26 19:50:09 maxv Exp $	*/
+/*	$NetBSD: ip6_mroute.c,v 1.126 2018/04/29 07:05:13 maxv Exp $	*/
 /*	$KAME: ip6_mroute.c,v 1.49 2001/07/25 09:21:18 jinmei Exp $	*/
 
 /*
@@ -117,7 +117,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip6_mroute.c,v 1.125 2018/04/26 19:50:09 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_mroute.c,v 1.126 2018/04/29 07:05:13 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1125,7 

CVS commit: src/sys/netinet6

2018-04-27 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Apr 27 09:02:16 UTC 2018

Modified Files:
src/sys/netinet6: icmp6.c

Log Message:
Fix a bug introduced in rev1.154 (2009). mcl_cache still has a size of
MCLBYTES, so the area allocated is still too small.

I think it should have been MEXTMALLOC, and of course I can't test my
change.


To generate a diff of this commit:
cvs rdiff -u -r1.232 -r1.233 src/sys/netinet6/icmp6.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/icmp6.c
diff -u src/sys/netinet6/icmp6.c:1.232 src/sys/netinet6/icmp6.c:1.233
--- src/sys/netinet6/icmp6.c:1.232	Thu Apr 26 19:50:09 2018
+++ src/sys/netinet6/icmp6.c	Fri Apr 27 09:02:16 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: icmp6.c,v 1.232 2018/04/26 19:50:09 maxv Exp $	*/
+/*	$NetBSD: icmp6.c,v 1.233 2018/04/27 09:02:16 maxv Exp $	*/
 /*	$KAME: icmp6.c,v 1.217 2001/06/20 15:03:29 jinmei Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: icmp6.c,v 1.232 2018/04/26 19:50:09 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: icmp6.c,v 1.233 2018/04/27 09:02:16 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -2495,7 +2495,7 @@ icmp6_redirect_output(struct mbuf *m0, s
 	MGETHDR(m, M_DONTWAIT, MT_HEADER);
 	if (m && IPV6_MMTU >= MHLEN) {
 #if IPV6_MMTU >= MCLBYTES
-		_MCLGET(m, mcl_cache, IPV6_MMTU, M_DONTWAIT);
+		MEXTMALLOC(m, IPV6_MMTU, M_NOWAIT);
 #else
 		MCLGET(m, M_DONTWAIT);
 #endif



CVS commit: src/sys/netinet6

2018-04-26 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu Apr 26 07:01:38 UTC 2018

Modified Files:
src/sys/netinet6: ip6_input.c

Log Message:
Move the address checks into one function, ip6_badaddr(). In this function,
reinstate the "IPv4-compatible IPv6 addresses" check; these addresses are
deprecated by RFC4291 (2006).


To generate a diff of this commit:
cvs rdiff -u -r1.198 -r1.199 src/sys/netinet6/ip6_input.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/ip6_input.c
diff -u src/sys/netinet6/ip6_input.c:1.198 src/sys/netinet6/ip6_input.c:1.199
--- src/sys/netinet6/ip6_input.c:1.198	Sun Apr 15 08:31:18 2018
+++ src/sys/netinet6/ip6_input.c	Thu Apr 26 07:01:38 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6_input.c,v 1.198 2018/04/15 08:31:18 maxv Exp $	*/
+/*	$NetBSD: ip6_input.c,v 1.199 2018/04/26 07:01:38 maxv Exp $	*/
 /*	$KAME: ip6_input.c,v 1.188 2001/03/29 05:34:31 itojun Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.198 2018/04/15 08:31:18 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.199 2018/04/26 07:01:38 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_gateway.h"
@@ -138,6 +138,7 @@ percpu_t *ip6_forward_rt_percpu __cachel
 
 static void ip6_init2(void);
 static void ip6intr(void *);
+static bool ip6_badaddr(struct ip6_hdr *);
 static struct m_tag *ip6_setdstifaddr(struct mbuf *, const struct in6_ifaddr *);
 
 static int ip6_process_hopopts(struct mbuf *, u_int8_t *, int, u_int32_t *,
@@ -320,55 +321,13 @@ ip6_input(struct mbuf *m, struct ifnet *
 		goto bad;
 	}
 
-	/*
-	 * Check against address spoofing/corruption.
-	 */
-	if (IN6_IS_ADDR_MULTICAST(>ip6_src) ||
-	IN6_IS_ADDR_UNSPECIFIED(>ip6_dst)) {
-		/*
-		 * XXX: "badscope" is not very suitable for a multicast source.
-		 */
+	if (ip6_badaddr(ip6)) {
 		IP6_STATINC(IP6_STAT_BADSCOPE);
 		in6_ifstat_inc(rcvif, ifs6_in_addrerr);
 		goto bad;
 	}
 
 	/*
-	 * The following check is not documented in specs.  A malicious
-	 * party may be able to use IPv4 mapped addr to confuse tcp/udp stack
-	 * and bypass security checks (act as if it was from 127.0.0.1 by using
-	 * IPv6 src :::127.0.0.1).  Be cautious.
-	 *
-	 * This check chokes if we are in an SIIT cloud.  As none of BSDs
-	 * support IPv4-less kernel compilation, we cannot support SIIT
-	 * environment at all.  So, it makes more sense for us to reject any
-	 * malicious packets for non-SIIT environment, than try to do a
-	 * partial support for SIIT environment.
-	 */
-	if (IN6_IS_ADDR_V4MAPPED(>ip6_src) ||
-	IN6_IS_ADDR_V4MAPPED(>ip6_dst)) {
-		IP6_STATINC(IP6_STAT_BADSCOPE);
-		in6_ifstat_inc(rcvif, ifs6_in_addrerr);
-		goto bad;
-	}
-
-#if 0
-	/*
-	 * Reject packets with IPv4 compatible addresses (auto tunnel).
-	 *
-	 * The code forbids auto tunnel relay case in RFC1933 (the check is
-	 * stronger than RFC1933).  We may want to re-enable it if mech-xx
-	 * is revised to forbid relaying case.
-	 */
-	if (IN6_IS_ADDR_V4COMPAT(>ip6_src) ||
-	IN6_IS_ADDR_V4COMPAT(>ip6_dst)) {
-		IP6_STATINC(IP6_STAT_BADSCOPE);
-		in6_ifstat_inc(rcvif, ifs6_in_addrerr);
-		goto bad;
-	}
-#endif
-
-	/*
 	 * Assume that we can create a fast-forward IP flow entry
 	 * based on this packet.
 	 */
@@ -804,6 +763,43 @@ bad:
 	return;
 }
 
+static bool
+ip6_badaddr(struct ip6_hdr *ip6)
+{
+	/* Check against address spoofing/corruption. */
+	if (IN6_IS_ADDR_MULTICAST(>ip6_src) ||
+	IN6_IS_ADDR_UNSPECIFIED(>ip6_dst)) {
+		return true;
+	}
+
+	/*
+	 * The following check is not documented in specs.  A malicious
+	 * party may be able to use IPv4 mapped addr to confuse tcp/udp stack
+	 * and bypass security checks (act as if it was from 127.0.0.1 by using
+	 * IPv6 src :::127.0.0.1).  Be cautious.
+	 *
+	 * This check chokes if we are in an SIIT cloud.  As none of BSDs
+	 * support IPv4-less kernel compilation, we cannot support SIIT
+	 * environment at all.  So, it makes more sense for us to reject any
+	 * malicious packets for non-SIIT environment, than try to do a
+	 * partial support for SIIT environment.
+	 */
+	if (IN6_IS_ADDR_V4MAPPED(>ip6_src) ||
+	IN6_IS_ADDR_V4MAPPED(>ip6_dst)) {
+		return true;
+	}
+
+	/*
+	 * Reject packets with IPv4-compatible IPv6 addresses (RFC4291).
+	 */
+	if (IN6_IS_ADDR_V4COMPAT(>ip6_src) ||
+	IN6_IS_ADDR_V4COMPAT(>ip6_dst)) {
+		return true;
+	}
+
+	return false;
+}
+
 /*
  * set/grab in6_ifaddr correspond to IPv6 destination address.
  */



CVS commit: src/sys/netinet6

2018-04-24 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Tue Apr 24 08:22:17 UTC 2018

Modified Files:
src/sys/netinet6: nd6_rtr.c

Log Message:
Remove nullcheck, m is not allowed to be null.


To generate a diff of this commit:
cvs rdiff -u -r1.139 -r1.140 src/sys/netinet6/nd6_rtr.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/nd6_rtr.c
diff -u src/sys/netinet6/nd6_rtr.c:1.139 src/sys/netinet6/nd6_rtr.c:1.140
--- src/sys/netinet6/nd6_rtr.c:1.139	Tue Apr 24 08:07:05 2018
+++ src/sys/netinet6/nd6_rtr.c	Tue Apr 24 08:22:16 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: nd6_rtr.c,v 1.139 2018/04/24 08:07:05 maxv Exp $	*/
+/*	$NetBSD: nd6_rtr.c,v 1.140 2018/04/24 08:22:16 maxv Exp $	*/
 /*	$KAME: nd6_rtr.c,v 1.95 2001/02/07 08:09:47 itojun Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nd6_rtr.c,v 1.139 2018/04/24 08:07:05 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nd6_rtr.c,v 1.140 2018/04/24 08:22:16 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -1118,12 +1118,10 @@ prelist_update(struct nd_prefixctl *newp
 	int ss;
 	char ip6buf[INET6_ADDRSTRLEN];
 
+	KASSERT(m != NULL);
 	ND6_ASSERT_WLOCK();
 
-	auth = 0;
-	if (m) {
-		auth = (m->m_flags & M_AUTHIPHDR) ? 1 : 0;
-	}
+	auth = (m->m_flags & M_AUTHIPHDR) ? 1 : 0;
 
 	if ((pr = nd6_prefix_lookup(newprc)) != NULL) {
 		/*



CVS commit: src/sys/netinet6

2018-04-19 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Apr 19 21:22:02 UTC 2018

Modified Files:
src/sys/netinet6: in6.h in6_var.h

Log Message:
s/static inline/static __inline/g for consistency.


To generate a diff of this commit:
cvs rdiff -u -r1.90 -r1.91 src/sys/netinet6/in6.h
cvs rdiff -u -r1.97 -r1.98 src/sys/netinet6/in6_var.h

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.90 src/sys/netinet6/in6.h:1.91
--- src/sys/netinet6/in6.h:1.90	Fri Feb  9 13:31:52 2018
+++ src/sys/netinet6/in6.h	Thu Apr 19 17:22:02 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: in6.h,v 1.90 2018/02/09 18:31:52 maxv Exp $	*/
+/*	$NetBSD: in6.h,v 1.91 2018/04/19 21:22:02 christos Exp $	*/
 /*	$KAME: in6.h,v 1.83 2001/03/29 02:55:07 jinmei Exp $	*/
 
 /*
@@ -720,7 +720,7 @@ int in6_tunnel_validate(const struct ip6
 #define	sin6tocsa(sin6)	((const struct sockaddr *)(sin6))
 #define	ifatoia6(ifa)	((struct in6_ifaddr *)(ifa))
 
-static inline void
+static __inline void
 sockaddr_in6_init1(struct sockaddr_in6 *sin6, const struct in6_addr *addr,
 in_port_t port, uint32_t flowinfo, uint32_t scope_id)
 {
@@ -730,7 +730,7 @@ sockaddr_in6_init1(struct sockaddr_in6 *
 	sin6->sin6_scope_id = scope_id;
 }
 
-static inline void
+static __inline void
 sockaddr_in6_init(struct sockaddr_in6 *sin6, const struct in6_addr *addr,
 in_port_t port, uint32_t flowinfo, uint32_t scope_id)
 {
@@ -739,7 +739,7 @@ sockaddr_in6_init(struct sockaddr_in6 *s
 	sockaddr_in6_init1(sin6, addr, port, flowinfo, scope_id);
 }
 
-static inline struct sockaddr *
+static __inline struct sockaddr *
 sockaddr_in6_alloc(const struct in6_addr *addr, in_port_t port,
 uint32_t flowinfo, uint32_t scope_id, int flags)
 {

Index: src/sys/netinet6/in6_var.h
diff -u src/sys/netinet6/in6_var.h:1.97 src/sys/netinet6/in6_var.h:1.98
--- src/sys/netinet6/in6_var.h:1.97	Thu Mar  2 04:48:20 2017
+++ src/sys/netinet6/in6_var.h	Thu Apr 19 17:22:02 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: in6_var.h,v 1.97 2017/03/02 09:48:20 ozaki-r Exp $	*/
+/*	$NetBSD: in6_var.h,v 1.98 2018/04/19 21:22:02 christos Exp $	*/
 /*	$KAME: in6_var.h,v 1.81 2002/06/08 11:16:51 itojun Exp $	*/
 
 /*
@@ -136,7 +136,7 @@ struct	in6_ifaddr {
 };
 
 #ifdef _KERNEL
-static inline void
+static __inline void
 ia6_acquire(struct in6_ifaddr *ia, struct psref *psref)
 {
 
@@ -144,7 +144,7 @@ ia6_acquire(struct in6_ifaddr *ia, struc
 	ifa_acquire(>ia_ifa, psref);
 }
 
-static inline void
+static __inline void
 ia6_release(struct in6_ifaddr *ia, struct psref *psref)
 {
 
@@ -590,7 +590,7 @@ extern callout_t in6_tmpaddrtimer_ch;
  * Macro for finding the internet address structure (in6_ifaddr) corresponding
  * to a given interface (ifnet structure).
  */
-static inline struct in6_ifaddr *
+static __inline struct in6_ifaddr *
 in6_get_ia_from_ifp(struct ifnet *ifp)
 {
 	struct ifaddr *ifa;
@@ -602,7 +602,7 @@ in6_get_ia_from_ifp(struct ifnet *ifp)
 	return (struct in6_ifaddr *)ifa;
 }
 
-static inline struct in6_ifaddr *
+static __inline struct in6_ifaddr *
 in6_get_ia_from_ifp_psref(struct ifnet *ifp, struct psref *psref)
 {
 	struct in6_ifaddr *ia;
@@ -653,7 +653,7 @@ struct	in6_multi {
  * address on a given interface. If no matching record is found, "imm"
  * returns NULL.
  */
-static inline struct in6_multi_mship *
+static __inline struct in6_multi_mship *
 in6_lookup_mship(struct in6_addr *addr, struct ifnet *ifp,
 struct ip6_moptions *imop)
 {



CVS commit: src/sys/netinet6

2018-04-15 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sun Apr 15 08:31:18 UTC 2018

Modified Files:
src/sys/netinet6: ip6_input.c

Log Message:
Remove useless DIAGNOSTIC block, the caller already ensures the
assumptions, and here we're not doing anything (it should be a panic
rather than a printf).


To generate a diff of this commit:
cvs rdiff -u -r1.197 -r1.198 src/sys/netinet6/ip6_input.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/ip6_input.c
diff -u src/sys/netinet6/ip6_input.c:1.197 src/sys/netinet6/ip6_input.c:1.198
--- src/sys/netinet6/ip6_input.c:1.197	Sun Apr 15 07:35:49 2018
+++ src/sys/netinet6/ip6_input.c	Sun Apr 15 08:31:18 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6_input.c,v 1.197 2018/04/15 07:35:49 maxv Exp $	*/
+/*	$NetBSD: ip6_input.c,v 1.198 2018/04/15 08:31:18 maxv Exp $	*/
 /*	$KAME: ip6_input.c,v 1.188 2001/03/29 05:34:31 itojun Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.197 2018/04/15 07:35:49 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.198 2018/04/15 08:31:18 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_gateway.h"
@@ -1318,18 +1318,6 @@ ip6_pullexthdr(struct mbuf *m, size_t of
 	size_t elen;
 	struct mbuf *n;
 
-#ifdef DIAGNOSTIC
-	switch (nxt) {
-	case IPPROTO_DSTOPTS:
-	case IPPROTO_ROUTING:
-	case IPPROTO_HOPOPTS:
-	case IPPROTO_AH: /* is it possible? */
-		break;
-	default:
-		printf("ip6_pullexthdr: invalid nxt=%d\n", nxt);
-	}
-#endif
-
 	m_copydata(m, off, sizeof(ip6e), (void *));
 	if (nxt == IPPROTO_AH)
 		elen = (ip6e.ip6e_len + 2) << 2;



CVS commit: src/sys/netinet6

2018-04-14 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat Apr 14 17:55:47 UTC 2018

Modified Files:
src/sys/netinet6: icmp6.c

Log Message:
Fix 'icmp6len', it shouldn't be ip6_plen, because we may not be at the
beginning of the packet (off+ip6_plen is beyond the end of the mbuf). By
luck, the IP6_EXTHDR_GET that follows will fail and prevent buffer
overflows in non-jumbogram packets.

For jumbograms we will probably be in trouble here; but it doesn't seem
possible to craft reliably a jumbogram for a non-jumbogram-enabled device.

So I don't think it's a huge problem.


To generate a diff of this commit:
cvs rdiff -u -r1.229 -r1.230 src/sys/netinet6/icmp6.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/icmp6.c
diff -u src/sys/netinet6/icmp6.c:1.229 src/sys/netinet6/icmp6.c:1.230
--- src/sys/netinet6/icmp6.c:1.229	Sat Apr 14 14:59:58 2018
+++ src/sys/netinet6/icmp6.c	Sat Apr 14 17:55:47 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: icmp6.c,v 1.229 2018/04/14 14:59:58 maxv Exp $	*/
+/*	$NetBSD: icmp6.c,v 1.230 2018/04/14 17:55:47 maxv Exp $	*/
 /*	$KAME: icmp6.c,v 1.217 2001/06/20 15:03:29 jinmei Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: icmp6.c,v 1.229 2018/04/14 14:59:58 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: icmp6.c,v 1.230 2018/04/14 17:55:47 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -2224,7 +2224,7 @@ icmp6_redirect_input(struct mbuf *m, int
 	struct ifnet *ifp;
 	struct ip6_hdr *ip6 = mtod(m, struct ip6_hdr *);
 	struct nd_redirect *nd_rd;
-	int icmp6len = ntohs(ip6->ip6_plen);
+	int icmp6len = m->m_pkthdr.len - off;
 	char *lladdr = NULL;
 	int lladdrlen = 0;
 	struct rtentry *rt = NULL;



CVS commit: src/sys/netinet6

2018-04-14 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat Apr 14 14:59:59 UTC 2018

Modified Files:
src/sys/netinet6: icmp6.c

Log Message:
Cosmetic, and remove one XXX (no problem).


To generate a diff of this commit:
cvs rdiff -u -r1.228 -r1.229 src/sys/netinet6/icmp6.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/icmp6.c
diff -u src/sys/netinet6/icmp6.c:1.228 src/sys/netinet6/icmp6.c:1.229
--- src/sys/netinet6/icmp6.c:1.228	Sat Apr 14 08:03:33 2018
+++ src/sys/netinet6/icmp6.c	Sat Apr 14 14:59:58 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: icmp6.c,v 1.228 2018/04/14 08:03:33 maxv Exp $	*/
+/*	$NetBSD: icmp6.c,v 1.229 2018/04/14 14:59:58 maxv Exp $	*/
 /*	$KAME: icmp6.c,v 1.217 2001/06/20 15:03:29 jinmei Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: icmp6.c,v 1.228 2018/04/14 08:03:33 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: icmp6.c,v 1.229 2018/04/14 14:59:58 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -974,7 +974,7 @@ icmp6_notify_error(struct mbuf *m, int o
 			case IPPROTO_DSTOPTS:
 			case IPPROTO_AH:
 IP6_EXTHDR_GET(eh, struct ip6_ext *, m,
-	   eoff, sizeof(*eh));
+eoff, sizeof(*eh));
 if (eh == NULL) {
 	ICMP6_STATINC(ICMP6_STAT_TOOSHORT);
 	return (-1);
@@ -989,7 +989,7 @@ icmp6_notify_error(struct mbuf *m, int o
 			case IPPROTO_ROUTING:
 /* Ignore the option. */
 IP6_EXTHDR_GET(rth, struct ip6_rthdr *, m,
-	   eoff, sizeof(*rth));
+eoff, sizeof(*rth));
 if (rth == NULL) {
 	ICMP6_STATINC(ICMP6_STAT_TOOSHORT);
 	return (-1);
@@ -1000,7 +1000,7 @@ icmp6_notify_error(struct mbuf *m, int o
 break;
 			case IPPROTO_FRAGMENT:
 IP6_EXTHDR_GET(fh, struct ip6_frag *, m,
-	   eoff, sizeof(*fh));
+eoff, sizeof(*fh));
 if (fh == NULL) {
 	ICMP6_STATINC(ICMP6_STAT_TOOSHORT);
 	return (-1);
@@ -1031,7 +1031,7 @@ icmp6_notify_error(struct mbuf *m, int o
 		}
 	  notify:
 		IP6_EXTHDR_GET(icmp6, struct icmp6_hdr *, m, off,
-			   sizeof(*icmp6) + sizeof(struct ip6_hdr));
+		sizeof(*icmp6) + sizeof(struct ip6_hdr));
 		if (icmp6 == NULL) {
 			ICMP6_STATINC(ICMP6_STAT_TOOSHORT);
 			return (-1);
@@ -1082,7 +1082,7 @@ icmp6_notify_error(struct mbuf *m, int o
 		}
 
 		ctlfunc = (void (*)(int, struct sockaddr *, void *))
-			(inet6sw[ip6_protox[nxt]].pr_ctlinput);
+		(inet6sw[ip6_protox[nxt]].pr_ctlinput);
 		if (ctlfunc) {
 			(void)(*ctlfunc)(code, sin6tosa(), );
 		}
@@ -1236,11 +1236,11 @@ ni6_input(struct mbuf *m, int off)
 	/* XXX scopeid */
 	ss = pserialize_read_enter();
 	ifa = ifa_ifwithaddr(sin6tosa());
-	if (ifa != NULL)
+	if (ifa != NULL) {
 		; /* unicast/anycast, fine */
-	else if (IN6_IS_ADDR_MC_LINKLOCAL(_addr))
+	} else if (IN6_IS_ADDR_MC_LINKLOCAL(_addr)) {
 		; /* link-local multicast, fine */
-	else {
+	} else {
 		pserialize_read_exit(ss);
 		goto bad;
 	}
@@ -1341,7 +1341,7 @@ ni6_input(struct mbuf *m, int off)
 			if (subj == NULL)
 goto bad;
 			if (!ni6_dnsmatch(subj, subjlen, mtod(n, const char *),
-	n->m_len)) {
+			n->m_len)) {
 goto bad;
 			}
 			m_freem(n);
@@ -1451,8 +1451,7 @@ ni6_input(struct mbuf *m, int off)
 	case NI_QTYPE_FQDN:
 		nni6->ni_code = ICMP6_NI_SUCCESS;
 		fqdn = (struct ni_reply_fqdn *)(mtod(n, char *) +
-		sizeof(struct ip6_hdr) +
-		sizeof(struct icmp6_nodeinfo));
+		sizeof(struct ip6_hdr) + sizeof(struct icmp6_nodeinfo));
 		nni6->ni_flags = 0; /* XXX: meaningless TTL */
 		fqdn->ni_fqdn_ttl = 0;	/* ditto. */
 		/*
@@ -1471,15 +1470,15 @@ ni6_input(struct mbuf *m, int off)
 		int lenlim, copied;
 
 		nni6->ni_code = ICMP6_NI_SUCCESS;
-		n->m_pkthdr.len = n->m_len =
-		sizeof(struct ip6_hdr) + sizeof(struct icmp6_nodeinfo);
+		n->m_pkthdr.len = n->m_len = sizeof(struct ip6_hdr) +
+		sizeof(struct icmp6_nodeinfo);
 		lenlim = M_TRAILINGSPACE(n);
 		copied = ni6_store_addrs(ni6, nni6, ifp, lenlim);
 		if_put(ifp, );
 		ifp = NULL;
-		/* XXX: reset mbuf length */
+		/* update mbuf length */
 		n->m_pkthdr.len = n->m_len = sizeof(struct ip6_hdr) +
-			sizeof(struct icmp6_nodeinfo) + copied;
+		sizeof(struct icmp6_nodeinfo) + copied;
 		break;
 	}
 	default:
@@ -1695,7 +1694,7 @@ ni6_addrs(struct icmp6_nodeinfo *ni6, st
 		switch (ni6->ni_code) {
 		case ICMP6_NI_SUBJ_IPV6:
 			if (subj == NULL) /* must be impossible... */
-return (0);
+return 0;
 			subj_ip6 = (struct sockaddr_in6 *)subj;
 			break;
 		default:
@@ -1703,7 +1702,7 @@ ni6_addrs(struct icmp6_nodeinfo *ni6, st
 			 * XXX: we only support IPv6 subject address for
 			 * this Qtype.
 			 */
-			return (0);
+			return 0;
 		}
 	}
 
@@ -1717,7 +1716,7 @@ ni6_addrs(struct icmp6_nodeinfo *ni6, st
 
 			if ((niflags & NI_NODEADDR_FLAG_ALL) == 0 &&
 			IN6_ARE_ADDR_EQUAL(_ip6->sin6_addr,
-	   >ia_addr.sin6_addr))
+			 >ia_addr.sin6_addr))
 iffound = 1;
 
 			/*
@@ 

CVS commit: src/sys/netinet6

2018-04-14 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat Apr 14 08:03:33 UTC 2018

Modified Files:
src/sys/netinet6: icmp6.c

Log Message:
Remove the RH0 code from ICMPv6. RH0 is deprecated by RFC5095 (2007) for
security reasons. We already removed it in Route6.

In addition there was an mbuf bug here: calling IP6_EXTHDR_GET twice with
the same offset, but still using the pointer from the first call, which
could have been made invalid. By luck, m_pulldown leaves zero-sized mbufs
in place, instead of freeing them.

And in general, using a 'finaldst' pointer on the mbuf, and then modifying
that mbuf with IP6_EXTHDR_GET with a smaller offset, was really error-
prone.


To generate a diff of this commit:
cvs rdiff -u -r1.227 -r1.228 src/sys/netinet6/icmp6.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/icmp6.c
diff -u src/sys/netinet6/icmp6.c:1.227 src/sys/netinet6/icmp6.c:1.228
--- src/sys/netinet6/icmp6.c:1.227	Sat Apr 14 06:45:17 2018
+++ src/sys/netinet6/icmp6.c	Sat Apr 14 08:03:33 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: icmp6.c,v 1.227 2018/04/14 06:45:17 maxv Exp $	*/
+/*	$NetBSD: icmp6.c,v 1.228 2018/04/14 08:03:33 maxv Exp $	*/
 /*	$KAME: icmp6.c,v 1.217 2001/06/20 15:03:29 jinmei Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: icmp6.c,v 1.227 2018/04/14 06:45:17 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: icmp6.c,v 1.228 2018/04/14 08:03:33 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -963,8 +963,6 @@ icmp6_notify_error(struct mbuf *m, int o
 		int icmp6type = icmp6->icmp6_type;
 		struct ip6_frag *fh;
 		struct ip6_rthdr *rth;
-		struct ip6_rthdr0 *rth0;
-		int rthlen;
 		struct ifnet *rcvif;
 		int s;
 
@@ -989,46 +987,15 @@ icmp6_notify_error(struct mbuf *m, int o
 nxt = eh->ip6e_nxt;
 break;
 			case IPPROTO_ROUTING:
-/*
- * When the erroneous packet contains a
- * routing header, we should examine the
- * header to determine the final destination.
- * Otherwise, we can't properly update
- * information that depends on the final
- * destination (e.g. path MTU).
- */
+/* Ignore the option. */
 IP6_EXTHDR_GET(rth, struct ip6_rthdr *, m,
 	   eoff, sizeof(*rth));
 if (rth == NULL) {
 	ICMP6_STATINC(ICMP6_STAT_TOOSHORT);
 	return (-1);
 }
-rthlen = (rth->ip6r_len + 1) << 3;
-/*
- * XXX: currently there is no
- * officially defined type other
- * than type-0.
- * Note that if the segment left field
- * is 0, all intermediate hops must
- * have been passed.
- */
-if (rth->ip6r_segleft &&
-rth->ip6r_type == IPV6_RTHDR_TYPE_0) {
-	int hops;
-
-	IP6_EXTHDR_GET(rth0,
-		   struct ip6_rthdr0 *, m,
-		   eoff, rthlen);
-	if (rth0 == NULL) {
-		ICMP6_STATINC(ICMP6_STAT_TOOSHORT);
-		return (-1);
-	}
-	/* just ignore a bogus header */
-	if ((rth0->ip6r0_len % 2) == 0 &&
-	(hops = rth0->ip6r0_len/2))
-		finaldst = (struct in6_addr *)(rth0 + 1) + (hops - 1);
-}
-eoff += rthlen;
+
+eoff += (rth->ip6r_len + 1) << 3;
 nxt = rth->ip6r_nxt;
 break;
 			case IPPROTO_FRAGMENT:



CVS commit: src/sys/netinet6

2018-04-14 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat Apr 14 06:45:18 UTC 2018

Modified Files:
src/sys/netinet6: icmp6.c

Log Message:
Remove dead code. It is the same as the non-obsolete one, since
ICMP6_DST_UNREACH_NOTNEIGHBOR == ICMP6_DST_UNREACH_BEYONDSCOPE,
and the code leads to the same errno value (EHOSTUNREACH).


To generate a diff of this commit:
cvs rdiff -u -r1.226 -r1.227 src/sys/netinet6/icmp6.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/icmp6.c
diff -u src/sys/netinet6/icmp6.c:1.226 src/sys/netinet6/icmp6.c:1.227
--- src/sys/netinet6/icmp6.c:1.226	Thu Apr 12 07:28:10 2018
+++ src/sys/netinet6/icmp6.c	Sat Apr 14 06:45:17 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: icmp6.c,v 1.226 2018/04/12 07:28:10 maxv Exp $	*/
+/*	$NetBSD: icmp6.c,v 1.227 2018/04/14 06:45:17 maxv Exp $	*/
 /*	$KAME: icmp6.c,v 1.217 2001/06/20 15:03:29 jinmei Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: icmp6.c,v 1.226 2018/04/12 07:28:10 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: icmp6.c,v 1.227 2018/04/14 06:45:17 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -570,16 +570,10 @@ _icmp6_input(struct mbuf *m, int off, in
 		case ICMP6_DST_UNREACH_ADDR:
 			code = PRC_HOSTDEAD;
 			break;
-#ifdef COMPAT_RFC1885
-		case ICMP6_DST_UNREACH_NOTNEIGHBOR:
-			code = PRC_UNREACH_SRCFAIL;
-			break;
-#else
 		case ICMP6_DST_UNREACH_BEYONDSCOPE:
 			/* I mean "source address was incorrect." */
 			code = PRC_UNREACH_NET;
 			break;
-#endif
 		case ICMP6_DST_UNREACH_NOPORT:
 			code = PRC_UNREACH_PORT;
 			break;



CVS commit: src/sys/netinet6

2018-04-13 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Apr 13 11:32:44 UTC 2018

Modified Files:
src/sys/netinet6: frag6.c

Log Message:
Localify global variables, style, and add two XXXs.


To generate a diff of this commit:
cvs rdiff -u -r1.70 -r1.71 src/sys/netinet6/frag6.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/frag6.c
diff -u src/sys/netinet6/frag6.c:1.70 src/sys/netinet6/frag6.c:1.71
--- src/sys/netinet6/frag6.c:1.70	Fri Apr 13 11:19:09 2018
+++ src/sys/netinet6/frag6.c	Fri Apr 13 11:32:44 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: frag6.c,v 1.70 2018/04/13 11:19:09 maxv Exp $	*/
+/*	$NetBSD: frag6.c,v 1.71 2018/04/13 11:32:44 maxv Exp $	*/
 /*	$KAME: frag6.c,v 1.40 2002/05/27 21:40:31 itojun Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: frag6.c,v 1.70 2018/04/13 11:19:09 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: frag6.c,v 1.71 2018/04/13 11:32:44 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -59,8 +59,10 @@ __KERNEL_RCSID(0, "$NetBSD: frag6.c,v 1.
 #include 
 
 /*
- * IP6 reassembly queue structure.  Each fragment
- * being reassembled is attached to one of these structures.
+ * IPv6 reassembly queue structure. Each fragment being reassembled is
+ * attached to one of these structures.
+ *
+ * XXX: Would be better to use TAILQ.
  */
 struct	ip6q {
 	u_int32_t	ip6q_head;
@@ -93,7 +95,6 @@ struct	ip6asfrag {
 	bool		ip6af_mff;	/* more fragment bit in frag off */
 };
 
-
 static void frag6_enq(struct ip6asfrag *, struct ip6asfrag *);
 static void frag6_deq(struct ip6asfrag *);
 static void frag6_insque(struct ip6q *, struct ip6q *);
@@ -102,9 +103,9 @@ static void frag6_freef(struct ip6q *);
 
 static int frag6_drainwanted;
 
-u_int frag6_nfragpackets;
-u_int frag6_nfrags;
-struct ip6q ip6q;	/* ip6 reassembly queue */
+static u_int frag6_nfragpackets;
+static u_int frag6_nfrags;
+static struct ip6q ip6q;	/* ip6 reassembly queue */
 
 /* Protects ip6q */
 static kmutex_t	frag6_lock __cacheline_aligned;
@@ -216,6 +217,10 @@ frag6_input(struct mbuf **mp, int *offp,
 	 * a Fragment Header with the "Fragment Offset" equal to 0 and
 	 * the "M" bit equal to 0 MUST process such packet in isolation
 	 * from any other packets/fragments.
+	 *
+	 * XXX: Would be better to remove this fragment header entirely,
+	 * for us not to get confused later when looking back at the
+	 * previous headers in the chain.
 	 */
 	fragoff = ntohs(ip6f->ip6f_offlg & IP6F_OFF_MASK);
 	if (fragoff == 0 && !(ip6f->ip6f_offlg & IP6F_MORE_FRAG)) {
@@ -664,7 +669,7 @@ frag6_slowtimo(void)
 
 	mutex_enter(_lock);
 	q6 = ip6q.ip6q_next;
-	if (q6)
+	if (q6) {
 		while (q6 != ) {
 			--q6->ip6q_ttl;
 			q6 = q6->ip6q_next;
@@ -674,6 +679,8 @@ frag6_slowtimo(void)
 frag6_freef(q6->ip6q_prev);
 			}
 		}
+	}
+
 	/*
 	 * If we are over the maximum number of fragments
 	 * (due to the limit being lowered), drain off
@@ -698,7 +705,6 @@ frag6_slowtimo(void)
 	rtcache_free(_forward_rt);
 	rtcache_free(_rt);
 #endif
-
 }
 
 void



CVS commit: src/sys/netinet6

2018-04-13 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Apr 13 11:19:10 UTC 2018

Modified Files:
src/sys/netinet6: frag6.c

Log Message:
Add XXX, using a pool would be better than kmem.


To generate a diff of this commit:
cvs rdiff -u -r1.69 -r1.70 src/sys/netinet6/frag6.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/frag6.c
diff -u src/sys/netinet6/frag6.c:1.69 src/sys/netinet6/frag6.c:1.70
--- src/sys/netinet6/frag6.c:1.69	Fri Apr 13 11:18:08 2018
+++ src/sys/netinet6/frag6.c	Fri Apr 13 11:19:09 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: frag6.c,v 1.69 2018/04/13 11:18:08 maxv Exp $	*/
+/*	$NetBSD: frag6.c,v 1.70 2018/04/13 11:19:09 maxv Exp $	*/
 /*	$KAME: frag6.c,v 1.40 2002/05/27 21:40:31 itojun Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: frag6.c,v 1.69 2018/04/13 11:18:08 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: frag6.c,v 1.70 2018/04/13 11:19:09 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -150,6 +150,8 @@ frag6_init(void)
  *		-> should grab it from the first fragment only
  *
  * There is no explicit reason given in the RFC.  Historical reason maybe?
+ *
+ * XXX: It would be better to use a pool, rather than kmem.
  */
 int
 frag6_input(struct mbuf **mp, int *offp, int proto)



CVS commit: src/sys/netinet6

2018-04-13 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Apr 13 11:18:08 UTC 2018

Modified Files:
src/sys/netinet6: frag6.c

Log Message:
Release the lock a little earlier.


To generate a diff of this commit:
cvs rdiff -u -r1.68 -r1.69 src/sys/netinet6/frag6.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/frag6.c
diff -u src/sys/netinet6/frag6.c:1.68 src/sys/netinet6/frag6.c:1.69
--- src/sys/netinet6/frag6.c:1.68	Fri Apr 13 08:55:50 2018
+++ src/sys/netinet6/frag6.c	Fri Apr 13 11:18:08 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: frag6.c,v 1.68 2018/04/13 08:55:50 maxv Exp $	*/
+/*	$NetBSD: frag6.c,v 1.69 2018/04/13 11:18:08 maxv Exp $	*/
 /*	$KAME: frag6.c,v 1.40 2002/05/27 21:40:31 itojun Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: frag6.c,v 1.68 2018/04/13 08:55:50 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: frag6.c,v 1.69 2018/04/13 11:18:08 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -501,15 +501,13 @@ insert:
 	IP6_STATINC(IP6_STAT_REASSEMBLED);
 	in6_ifstat_inc(dstifp, ifs6_reass_ok);
 	rtcache_unref(rt, );
+	mutex_exit(_lock);
 
 	/*
-	 * Tell launch routine the next header
+	 * Tell launch routine the next header.
 	 */
-
 	*mp = m;
 	*offp = offset;
-
-	mutex_exit(_lock);
 	return nxt;
 
  dropfrag:



CVS commit: src/sys/netinet6

2018-04-13 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Apr 13 11:01:14 UTC 2018

Modified Files:
src/sys/netinet6: dest6.c

Log Message:
style


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/netinet6/dest6.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/dest6.c
diff -u src/sys/netinet6/dest6.c:1.21 src/sys/netinet6/dest6.c:1.22
--- src/sys/netinet6/dest6.c:1.21	Tue Jan 23 15:13:56 2018
+++ src/sys/netinet6/dest6.c	Fri Apr 13 11:01:14 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: dest6.c,v 1.21 2018/01/23 15:13:56 maxv Exp $	*/
+/*	$NetBSD: dest6.c,v 1.22 2018/04/13 11:01:14 maxv Exp $	*/
 /*	$KAME: dest6.c,v 1.25 2001/02/22 01:39:16 itojun Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: dest6.c,v 1.21 2018/01/23 15:13:56 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dest6.c,v 1.22 2018/04/13 11:01:14 maxv Exp $");
 
 #include 
 #include 
@@ -92,7 +92,7 @@ dest6_input(struct mbuf **mp, int *offp,
 			erroff = *offp + (opt - (u_int8_t *)dstopts);
 			optlen = ip6_unknown_opt(opt, m, erroff);
 			if (optlen == -1)
-return (IPPROTO_DONE);
+return IPPROTO_DONE;
 			optlen += 2;
 			break;
 		}



CVS commit: src/sys/netinet6

2018-04-13 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Apr 13 08:55:50 UTC 2018

Modified Files:
src/sys/netinet6: frag6.c

Log Message:
Add XXX. In fact, it would be better, if all the fragments were offloaded,
to quickly recompute the checksum on the fly, and keep it in the mbuf
header.


To generate a diff of this commit:
cvs rdiff -u -r1.67 -r1.68 src/sys/netinet6/frag6.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/frag6.c
diff -u src/sys/netinet6/frag6.c:1.67 src/sys/netinet6/frag6.c:1.68
--- src/sys/netinet6/frag6.c:1.67	Fri Mar  9 11:57:38 2018
+++ src/sys/netinet6/frag6.c	Fri Apr 13 08:55:50 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: frag6.c,v 1.67 2018/03/09 11:57:38 maxv Exp $	*/
+/*	$NetBSD: frag6.c,v 1.68 2018/04/13 08:55:50 maxv Exp $	*/
 /*	$KAME: frag6.c,v 1.40 2002/05/27 21:40:31 itojun Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: frag6.c,v 1.67 2018/03/09 11:57:38 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: frag6.c,v 1.68 2018/04/13 08:55:50 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -480,6 +480,7 @@ insert:
 			plen += t->m_len;
 		}
 		m->m_pkthdr.len = plen;
+		/* XXX XXX: clear csum_flags? */
 	}
 
 	/*



CVS commit: src/sys/netinet6

2018-03-18 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Mon Mar 19 03:14:08 UTC 2018

Modified Files:
src/sys/netinet6: nd6_nbr.c

Log Message:
Pull out a sleepable function (in6_selectsrc) from a pserialize read section


To generate a diff of this commit:
cvs rdiff -u -r1.152 -r1.153 src/sys/netinet6/nd6_nbr.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/nd6_nbr.c
diff -u src/sys/netinet6/nd6_nbr.c:1.152 src/sys/netinet6/nd6_nbr.c:1.153
--- src/sys/netinet6/nd6_nbr.c:1.152	Thu Mar  8 06:48:23 2018
+++ src/sys/netinet6/nd6_nbr.c	Mon Mar 19 03:14:08 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: nd6_nbr.c,v 1.152 2018/03/08 06:48:23 ozaki-r Exp $	*/
+/*	$NetBSD: nd6_nbr.c,v 1.153 2018/03/19 03:14:08 ozaki-r Exp $	*/
 /*	$KAME: nd6_nbr.c,v 1.61 2001/02/10 16:06:14 jinmei Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nd6_nbr.c,v 1.152 2018/03/08 06:48:23 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nd6_nbr.c,v 1.153 2018/03/19 03:14:08 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -459,12 +459,15 @@ nd6_ns_output(struct ifnet *ifp, const s
 		 * Otherwise, we perform the source address selection as usual.
 		 */
 		s = pserialize_read_enter();
-		if (hsrc && in6ifa_ifpwithaddr(ifp, hsrc))
+		if (hsrc && in6ifa_ifpwithaddr(ifp, hsrc)) {
+			pserialize_read_exit(s);
 			src = hsrc;
-		else {
+		} else {
 			int error;
 			struct sockaddr_in6 dst_sa;
 
+			pserialize_read_exit(s);
+
 			sockaddr_in6_init(_sa, >ip6_dst, 0, 0, 0);
 
 			error = in6_selectsrc(_sa, NULL,
@@ -480,7 +483,6 @@ nd6_ns_output(struct ifnet *ifp, const s
 			}
 			src = _in;
 		}
-		pserialize_read_exit(s);
 	} else {
 		/*
 		 * Source address for DAD packet must always be IPv6



CVS commit: src/sys/netinet6

2018-03-14 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Mar 14 07:56:32 UTC 2018

Modified Files:
src/sys/netinet6: in6_gif.c

Log Message:
Fix error checking in in6_gif_ctlinput().

if_gif.c:r1.133 introduces gif_update_variant() which ensure ifp->if_flags
is set IFF_RUNNING when gif_softc->gif_var->gv_{psrc,pdst} are not null.
So, in6_gif_ctlinput() is not required IFF_RUNNING checking. In contrast,
it is required gv_{psrc,pdst} NULL checking.


To generate a diff of this commit:
cvs rdiff -u -r1.90 -r1.91 src/sys/netinet6/in6_gif.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_gif.c
diff -u src/sys/netinet6/in6_gif.c:1.90 src/sys/netinet6/in6_gif.c:1.91
--- src/sys/netinet6/in6_gif.c:1.90	Wed Jan 10 11:13:26 2018
+++ src/sys/netinet6/in6_gif.c	Wed Mar 14 07:56:32 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: in6_gif.c,v 1.90 2018/01/10 11:13:26 knakahara Exp $	*/
+/*	$NetBSD: in6_gif.c,v 1.91 2018/03/14 07:56:32 knakahara Exp $	*/
 /*	$KAME: in6_gif.c,v 1.62 2001/07/29 04:27:25 itojun Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in6_gif.c,v 1.90 2018/01/10 11:13:26 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6_gif.c,v 1.91 2018/03/14 07:56:32 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -459,9 +459,11 @@ in6_gif_ctlinput(int cmd, const struct s
 	if (!ip6)
 		return NULL;
 
-	if ((sc->gif_if.if_flags & IFF_RUNNING) == 0)
-		return NULL;
 	var = gif_getref_variant(sc, );
+	if (var->gv_psrc == NULL || var->gv_pdst == NULL) {
+		gif_putref_variant(var, );
+		return NULL;
+	}
 	if (var->gv_psrc->sa_family != AF_INET6) {
 		gif_putref_variant(var, );
 		return NULL;



CVS commit: src/sys/netinet6

2018-03-06 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Wed Mar  7 01:37:24 UTC 2018

Modified Files:
src/sys/netinet6: nd6_nbr.c

Log Message:
Avoid passing NULL to nd6_dad_duplicated

Fix PR kern/53075


To generate a diff of this commit:
cvs rdiff -u -r1.150 -r1.151 src/sys/netinet6/nd6_nbr.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/nd6_nbr.c
diff -u src/sys/netinet6/nd6_nbr.c:1.150 src/sys/netinet6/nd6_nbr.c:1.151
--- src/sys/netinet6/nd6_nbr.c:1.150	Tue Mar  6 11:21:31 2018
+++ src/sys/netinet6/nd6_nbr.c	Wed Mar  7 01:37:24 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: nd6_nbr.c,v 1.150 2018/03/06 11:21:31 martin Exp $	*/
+/*	$NetBSD: nd6_nbr.c,v 1.151 2018/03/07 01:37:24 ozaki-r Exp $	*/
 /*	$KAME: nd6_nbr.c,v 1.61 2001/02/10 16:06:14 jinmei Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nd6_nbr.c,v 1.150 2018/03/06 11:21:31 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nd6_nbr.c,v 1.151 2018/03/07 01:37:24 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1347,7 +1347,8 @@ nd6_dad_timer(struct dadq *dp)
 		}
 
 		if (duplicate) {
-			/* (*dp) will be freed in nd6_dad_duplicated() */
+			nd6_dad_duplicated(dp);
+			/* (*dp) has been freed in nd6_dad_duplicated() */
 			dp = NULL;
 		} else {
 			/*
@@ -1367,9 +1368,6 @@ nd6_dad_timer(struct dadq *dp)
 		}
 	}
 done:
-	if (duplicate)
-		nd6_dad_duplicated(dp);
-
 	mutex_exit(_dad_lock);
 
 	if (need_free) {
@@ -1501,7 +1499,8 @@ nd6_dad_ns_input(struct ifaddr *ifa, str
 	/* XXX more checks for loopback situation - see nd6_dad_timer too */
 
 	if (duplicate) {
-		nd6_dad_duplicated(dp);
+		if (dp)
+			nd6_dad_duplicated(dp);
 	} else {
 		/*
 		 * not sure if I got a duplicate.
@@ -1522,11 +1521,12 @@ nd6_dad_na_input(struct ifaddr *ifa)
 
 	mutex_enter(_dad_lock);
 	dp = nd6_dad_find(ifa, NULL);
-	if (dp)
+	if (dp) {
 		dp->dad_na_icount++;
 
-	/* remove the address. */
-	nd6_dad_duplicated(dp);
+		/* remove the address. */
+		nd6_dad_duplicated(dp);
+	}
 
 	mutex_exit(_dad_lock);
 }



CVS commit: src/sys/netinet6

2018-03-06 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Tue Mar  6 17:39:36 UTC 2018

Modified Files:
src/sys/netinet6: ip6_input.c

Log Message:
Perform the IP (src/dst) checks _before_ calling the packet filter, because
if the filter has a "return-icmp" rule it may call icmp6_error with an src
field that was not entirely validated.


To generate a diff of this commit:
cvs rdiff -u -r1.193 -r1.194 src/sys/netinet6/ip6_input.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/ip6_input.c
diff -u src/sys/netinet6/ip6_input.c:1.193 src/sys/netinet6/ip6_input.c:1.194
--- src/sys/netinet6/ip6_input.c:1.193	Sat Feb 24 07:37:09 2018
+++ src/sys/netinet6/ip6_input.c	Tue Mar  6 17:39:36 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6_input.c,v 1.193 2018/02/24 07:37:09 ozaki-r Exp $	*/
+/*	$NetBSD: ip6_input.c,v 1.194 2018/03/06 17:39:36 maxv Exp $	*/
 /*	$KAME: ip6_input.c,v 1.188 2001/03/29 05:34:31 itojun Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.193 2018/02/24 07:37:09 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.194 2018/03/06 17:39:36 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_gateway.h"
@@ -321,54 +321,6 @@ ip6_input(struct mbuf *m, struct ifnet *
 	}
 
 	/*
-	 * Assume that we can create a fast-forward IP flow entry
-	 * based on this packet.
-	 */
-	m->m_flags |= M_CANFASTFWD;
-
-	/*
-	 * Run through list of hooks for input packets.  If there are any
-	 * filters which require that additional packets in the flow are
-	 * not fast-forwarded, they must clear the M_CANFASTFWD flag.
-	 * Note that filters must _never_ set this flag, as another filter
-	 * in the list may have previously cleared it.
-	 */
-	/*
-	 * let ipfilter look at packet on the wire,
-	 * not the decapsulated packet.
-	 */
-#if defined(IPSEC)
-	if (!ipsec_used || !ipsec_indone(m))
-#else
-	if (1)
-#endif
-	{
-		struct in6_addr odst;
-
-		odst = ip6->ip6_dst;
-		if (pfil_run_hooks(inet6_pfil_hook, , rcvif, PFIL_IN) != 0)
-			return;
-		if (m == NULL)
-			return;
-		ip6 = mtod(m, struct ip6_hdr *);
-		srcrt = !IN6_ARE_ADDR_EQUAL(, >ip6_dst);
-	}
-
-	IP6_STATINC(IP6_STAT_NXTHIST + ip6->ip6_nxt);
-
-#ifdef ALTQ
-	if (altq_input != NULL) {
-		SOFTNET_LOCK();
-		if ((*altq_input)(m, AF_INET6) == 0) {
-			SOFTNET_UNLOCK();
-			/* packet is dropped by traffic conditioner */
-			return;
-		}
-		SOFTNET_UNLOCK();
-	}
-#endif
-
-	/*
 	 * Check against address spoofing/corruption.
 	 */
 	if (IN6_IS_ADDR_MULTICAST(>ip6_src) ||
@@ -417,6 +369,54 @@ ip6_input(struct mbuf *m, struct ifnet *
 #endif
 
 	/*
+	 * Assume that we can create a fast-forward IP flow entry
+	 * based on this packet.
+	 */
+	m->m_flags |= M_CANFASTFWD;
+
+	/*
+	 * Run through list of hooks for input packets.  If there are any
+	 * filters which require that additional packets in the flow are
+	 * not fast-forwarded, they must clear the M_CANFASTFWD flag.
+	 * Note that filters must _never_ set this flag, as another filter
+	 * in the list may have previously cleared it.
+	 */
+	/*
+	 * let ipfilter look at packet on the wire,
+	 * not the decapsulated packet.
+	 */
+#if defined(IPSEC)
+	if (!ipsec_used || !ipsec_indone(m))
+#else
+	if (1)
+#endif
+	{
+		struct in6_addr odst;
+
+		odst = ip6->ip6_dst;
+		if (pfil_run_hooks(inet6_pfil_hook, , rcvif, PFIL_IN) != 0)
+			return;
+		if (m == NULL)
+			return;
+		ip6 = mtod(m, struct ip6_hdr *);
+		srcrt = !IN6_ARE_ADDR_EQUAL(, >ip6_dst);
+	}
+
+	IP6_STATINC(IP6_STAT_NXTHIST + ip6->ip6_nxt);
+
+#ifdef ALTQ
+	if (altq_input != NULL) {
+		SOFTNET_LOCK();
+		if ((*altq_input)(m, AF_INET6) == 0) {
+			SOFTNET_UNLOCK();
+			/* packet is dropped by traffic conditioner */
+			return;
+		}
+		SOFTNET_UNLOCK();
+	}
+#endif
+
+	/*
 	 * Disambiguate address scope zones (if there is ambiguity).
 	 * We first make sure that the original source or destination address
 	 * is not in our internal form for scoped addresses.  Such addresses



CVS commit: src/sys/netinet6

2018-03-06 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Mar  6 11:21:32 UTC 2018

Modified Files:
src/sys/netinet6: nd6_nbr.c

Log Message:
Remove unused variables


To generate a diff of this commit:
cvs rdiff -u -r1.149 -r1.150 src/sys/netinet6/nd6_nbr.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/nd6_nbr.c
diff -u src/sys/netinet6/nd6_nbr.c:1.149 src/sys/netinet6/nd6_nbr.c:1.150
--- src/sys/netinet6/nd6_nbr.c:1.149	Tue Mar  6 10:57:00 2018
+++ src/sys/netinet6/nd6_nbr.c	Tue Mar  6 11:21:31 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: nd6_nbr.c,v 1.149 2018/03/06 10:57:00 roy Exp $	*/
+/*	$NetBSD: nd6_nbr.c,v 1.150 2018/03/06 11:21:31 martin Exp $	*/
 /*	$KAME: nd6_nbr.c,v 1.61 2001/02/10 16:06:14 jinmei Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nd6_nbr.c,v 1.149 2018/03/06 10:57:00 roy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nd6_nbr.c,v 1.150 2018/03/06 11:21:31 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1480,16 +1480,12 @@ nd6_dad_ns_output(struct dadq *dp, struc
 static void
 nd6_dad_ns_input(struct ifaddr *ifa, struct nd_opt_nonce *nonce)
 {
-	struct in6_ifaddr *ia;
-	const struct in6_addr *taddr6;
 	struct dadq *dp;
 	int duplicate;
 
 	if (ifa == NULL)
 		panic("ifa == NULL in nd6_dad_ns_input");
 
-	ia = (struct in6_ifaddr *)ifa;
-	taddr6 = >ia_addr.sin6_addr;
 	duplicate = 0;
 
 	mutex_enter(_dad_lock);



CVS commit: src/sys/netinet6

2018-02-26 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Mon Feb 26 09:13:00 UTC 2018

Modified Files:
src/sys/netinet6: icmp6.c raw_ip6.c

Log Message:
Remove redundant condition (harmless). PR/53030.


To generate a diff of this commit:
cvs rdiff -u -r1.221 -r1.222 src/sys/netinet6/icmp6.c
cvs rdiff -u -r1.163 -r1.164 src/sys/netinet6/raw_ip6.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/icmp6.c
diff -u src/sys/netinet6/icmp6.c:1.221 src/sys/netinet6/icmp6.c:1.222
--- src/sys/netinet6/icmp6.c:1.221	Mon Feb 26 09:04:29 2018
+++ src/sys/netinet6/icmp6.c	Mon Feb 26 09:13:00 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: icmp6.c,v 1.221 2018/02/26 09:04:29 maxv Exp $	*/
+/*	$NetBSD: icmp6.c,v 1.222 2018/02/26 09:13:00 maxv Exp $	*/
 /*	$KAME: icmp6.c,v 1.217 2001/06/20 15:03:29 jinmei Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: icmp6.c,v 1.221 2018/02/26 09:04:29 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: icmp6.c,v 1.222 2018/02/26 09:13:00 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -2007,8 +2007,7 @@ icmp6_rip6_input(struct mbuf **mp, int o
 			/*
 			 * Check AH/ESP integrity
 			 */
-			if (!ipsec_used ||
-			(ipsec_used && !ipsec_in_reject(m, last)))
+			if (!ipsec_used || !ipsec_in_reject(m, last))
 #endif
 			if ((n = m_copy(m, 0, (int)M_COPYALL)) != NULL) {
 if (last->in6p_flags & IN6P_CONTROLOPTS)

Index: src/sys/netinet6/raw_ip6.c
diff -u src/sys/netinet6/raw_ip6.c:1.163 src/sys/netinet6/raw_ip6.c:1.164
--- src/sys/netinet6/raw_ip6.c:1.163	Mon Feb 26 09:04:29 2018
+++ src/sys/netinet6/raw_ip6.c	Mon Feb 26 09:13:00 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: raw_ip6.c,v 1.163 2018/02/26 09:04:29 maxv Exp $	*/
+/*	$NetBSD: raw_ip6.c,v 1.164 2018/02/26 09:13:00 maxv Exp $	*/
 /*	$KAME: raw_ip6.c,v 1.82 2001/07/23 18:57:56 jinmei Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: raw_ip6.c,v 1.163 2018/02/26 09:04:29 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: raw_ip6.c,v 1.164 2018/02/26 09:13:00 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ipsec.h"
@@ -197,8 +197,7 @@ rip6_input(struct mbuf **mp, int *offp, 
 			/*
 			 * Check AH/ESP integrity
 			 */
-			if (!ipsec_used ||
-			(ipsec_used && !ipsec_in_reject(m, last)))
+			if (!ipsec_used || !ipsec_in_reject(m, last))
 #endif
 			if ((n = m_copy(m, 0, (int)M_COPYALL)) != NULL) {
 if (last->in6p_flags & IN6P_CONTROLOPTS)



CVS commit: src/sys/netinet6

2018-02-23 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Sat Feb 24 07:40:40 UTC 2018

Modified Files:
src/sys/netinet6: nd6_nbr.c

Log Message:
Simplify; pass dp to nd6_dad_duplicated instead of looking it up again in it


To generate a diff of this commit:
cvs rdiff -u -r1.146 -r1.147 src/sys/netinet6/nd6_nbr.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/nd6_nbr.c
diff -u src/sys/netinet6/nd6_nbr.c:1.146 src/sys/netinet6/nd6_nbr.c:1.147
--- src/sys/netinet6/nd6_nbr.c:1.146	Sat Feb 24 07:38:05 2018
+++ src/sys/netinet6/nd6_nbr.c	Sat Feb 24 07:40:40 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: nd6_nbr.c,v 1.146 2018/02/24 07:38:05 ozaki-r Exp $	*/
+/*	$NetBSD: nd6_nbr.c,v 1.147 2018/02/24 07:40:40 ozaki-r Exp $	*/
 /*	$KAME: nd6_nbr.c,v 1.61 2001/02/10 16:06:14 jinmei Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nd6_nbr.c,v 1.146 2018/02/24 07:38:05 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nd6_nbr.c,v 1.147 2018/02/24 07:40:40 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -84,7 +84,7 @@ static void nd6_dad_timer(struct dadq *)
 static void nd6_dad_ns_output(struct dadq *, struct ifaddr *);
 static void nd6_dad_ns_input(struct ifaddr *);
 static void nd6_dad_na_input(struct ifaddr *);
-static void nd6_dad_duplicated(struct ifaddr *);
+static void nd6_dad_duplicated(struct dadq *);
 
 static int dad_ignore_ns = 0;	/* ignore NS in DAD - specwise incorrect*/
 static int dad_maxtry = 15;	/* max # of *tries* to transmit DAD packet */
@@ -1092,10 +1092,13 @@ nd6_dad_starttimer(struct dadq *dp, int 
 static void
 nd6_dad_destroytimer(struct dadq *dp)
 {
+	struct ifaddr *ifa;
 
 	TAILQ_REMOVE(, dp, dad_list);
 	/* Request the timer to destroy dp. */
+	ifa = dp->dad_ifa;
 	dp->dad_ifa = NULL;
+	ifafree(ifa);
 	callout_reset(>dad_timer_ch, 0,
 	(void (*)(void *))nd6_dad_timer, dp);
 }
@@ -1212,8 +1215,6 @@ nd6_dad_stop(struct ifaddr *ifa)
 	nd6_dad_destroytimer(dp);
 
 	mutex_exit(_dad_lock);
-
-	ifafree(ifa);
 }
 
 static void
@@ -1315,6 +1316,9 @@ nd6_dad_timer(struct dadq *dp)
 		}
 	}
 done:
+	if (duplicate)
+		nd6_dad_duplicated(dp);
+
 	mutex_exit(_dad_lock);
 
 	if (need_free) {
@@ -1324,29 +1328,22 @@ done:
 			ifafree(ifa);
 	}
 
-	if (duplicate)
-		nd6_dad_duplicated(ifa);
-
 	SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE();
 }
 
 static void
-nd6_dad_duplicated(struct ifaddr *ifa)
+nd6_dad_duplicated(struct dadq *dp)
 {
-	struct in6_ifaddr *ia = (struct in6_ifaddr *)ifa;
+	struct ifaddr *ifa = dp->dad_ifa;
+	struct in6_ifaddr *ia;
 	struct ifnet *ifp;
-	struct dadq *dp;
 	char ip6buf[INET6_ADDRSTRLEN];
 
-	mutex_enter(_dad_lock);
-	dp = nd6_dad_find(ifa);
-	if (dp == NULL) {
-		mutex_exit(_dad_lock);
-		/* DAD seems to be stopping, so do nothing. */
-		return;
-	}
+	KASSERT(mutex_owned(_dad_lock));
+	KASSERT(ifa != NULL);
 
 	ifp = ifa->ifa_ifp;
+	ia = (struct in6_ifaddr *)ifa;
 	log(LOG_ERR, "%s: DAD detected duplicate IPv6 address %s: "
 	"NS in/out=%d/%d, NA in=%d\n",
 	if_name(ifp), IN6_PRINT(ip6buf, >ia_addr.sin6_addr),
@@ -1397,10 +1394,6 @@ nd6_dad_duplicated(struct ifaddr *ifa)
 
 	/* We are done with DAD, with duplicated address found. (failure) */
 	nd6_dad_destroytimer(dp);
-
-	mutex_exit(_dad_lock);
-
-	ifafree(ifa);
 }
 
 static void
@@ -1465,9 +1458,7 @@ nd6_dad_ns_input(struct ifaddr *ifa)
 	/* XXX more checks for loopback situation - see nd6_dad_timer too */
 
 	if (duplicate) {
-		dp = NULL;	/* will be freed in nd6_dad_duplicated() */
-		mutex_exit(_dad_lock);
-		nd6_dad_duplicated(ifa);
+		nd6_dad_duplicated(dp);
 	} else {
 		/*
 		 * not sure if I got a duplicate.
@@ -1475,8 +1466,8 @@ nd6_dad_ns_input(struct ifaddr *ifa)
 		 */
 		if (dp)
 			dp->dad_ns_icount++;
-		mutex_exit(_dad_lock);
 	}
+	mutex_exit(_dad_lock);
 }
 
 static void
@@ -1490,8 +1481,9 @@ nd6_dad_na_input(struct ifaddr *ifa)
 	dp = nd6_dad_find(ifa);
 	if (dp)
 		dp->dad_na_icount++;
-	mutex_exit(_dad_lock);
 
 	/* remove the address. */
-	nd6_dad_duplicated(ifa);
+	nd6_dad_duplicated(dp);
+
+	mutex_exit(_dad_lock);
 }



CVS commit: src/sys/netinet6

2018-02-23 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Sat Feb 24 07:38:05 UTC 2018

Modified Files:
src/sys/netinet6: nd6_nbr.c

Log Message:
Use KASSERT for checking a programming error


To generate a diff of this commit:
cvs rdiff -u -r1.145 -r1.146 src/sys/netinet6/nd6_nbr.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/nd6_nbr.c
diff -u src/sys/netinet6/nd6_nbr.c:1.145 src/sys/netinet6/nd6_nbr.c:1.146
--- src/sys/netinet6/nd6_nbr.c:1.145	Fri Feb  2 10:49:01 2018
+++ src/sys/netinet6/nd6_nbr.c	Sat Feb 24 07:38:05 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: nd6_nbr.c,v 1.145 2018/02/02 10:49:01 maxv Exp $	*/
+/*	$NetBSD: nd6_nbr.c,v 1.146 2018/02/24 07:38:05 ozaki-r Exp $	*/
 /*	$KAME: nd6_nbr.c,v 1.61 2001/02/10 16:06:14 jinmei Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nd6_nbr.c,v 1.145 2018/02/02 10:49:01 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nd6_nbr.c,v 1.146 2018/02/24 07:38:05 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1484,8 +1484,7 @@ nd6_dad_na_input(struct ifaddr *ifa)
 {
 	struct dadq *dp;
 
-	if (ifa == NULL)
-		panic("ifa == NULL in nd6_dad_na_input");
+	KASSERT(ifa != NULL);
 
 	mutex_enter(_dad_lock);
 	dp = nd6_dad_find(ifa);



CVS commit: src/sys/netinet6

2018-02-13 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Wed Feb 14 05:29:39 UTC 2018

Modified Files:
src/sys/netinet6: ip6_input.c ip6_var.h

Log Message:
Re-make ip6_nexthdr global, it will be used in soon-to-be-added code...


To generate a diff of this commit:
cvs rdiff -u -r1.191 -r1.192 src/sys/netinet6/ip6_input.c
cvs rdiff -u -r1.79 -r1.80 src/sys/netinet6/ip6_var.h

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/ip6_input.c
diff -u src/sys/netinet6/ip6_input.c:1.191 src/sys/netinet6/ip6_input.c:1.192
--- src/sys/netinet6/ip6_input.c:1.191	Mon Feb 12 12:52:12 2018
+++ src/sys/netinet6/ip6_input.c	Wed Feb 14 05:29:39 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6_input.c,v 1.191 2018/02/12 12:52:12 maxv Exp $	*/
+/*	$NetBSD: ip6_input.c,v 1.192 2018/02/14 05:29:39 maxv Exp $	*/
 /*	$KAME: ip6_input.c,v 1.188 2001/03/29 05:34:31 itojun Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.191 2018/02/12 12:52:12 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.192 2018/02/14 05:29:39 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_gateway.h"
@@ -1402,7 +1402,7 @@ ip6_get_prevhdr(struct mbuf *m, int off)
 /*
  * get next header offset.  m will be retained.
  */
-static int
+int
 ip6_nexthdr(struct mbuf *m, int off, int proto, int *nxtp)
 {
 	struct ip6_hdr ip6;

Index: src/sys/netinet6/ip6_var.h
diff -u src/sys/netinet6/ip6_var.h:1.79 src/sys/netinet6/ip6_var.h:1.80
--- src/sys/netinet6/ip6_var.h:1.79	Tue Jan 30 15:54:02 2018
+++ src/sys/netinet6/ip6_var.h	Wed Feb 14 05:29:39 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6_var.h,v 1.79 2018/01/30 15:54:02 maxv Exp $	*/
+/*	$NetBSD: ip6_var.h,v 1.80 2018/02/14 05:29:39 maxv Exp $	*/
 /*	$KAME: ip6_var.h,v 1.33 2000/06/11 14:59:20 jinmei Exp $	*/
 
 /*
@@ -287,6 +287,7 @@ void	ip6_freepcbopts(struct ip6_pktopts 
 void	ip6_freemoptions(struct ip6_moptions *);
 int	ip6_unknown_opt(u_int8_t *, struct mbuf *, int);
 int	ip6_get_prevhdr(struct mbuf *, int);
+int	ip6_nexthdr(struct mbuf *, int, int, int *);
 int	ip6_lasthdr(struct mbuf *, int, int, int *);
 
 struct m_tag *ip6_addaux(struct mbuf *);



CVS commit: src/sys/netinet6

2018-02-12 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Mon Feb 12 12:52:13 UTC 2018

Modified Files:
src/sys/netinet6: icmp6.c ip6_input.c ip6_output.c

Log Message:
Replace bcopy -> memcpy when it is obvious that the areas don't overlap.
Rearrange ip6_splithdr() for clarity.


To generate a diff of this commit:
cvs rdiff -u -r1.219 -r1.220 src/sys/netinet6/icmp6.c
cvs rdiff -u -r1.190 -r1.191 src/sys/netinet6/ip6_input.c
cvs rdiff -u -r1.200 -r1.201 src/sys/netinet6/ip6_output.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/icmp6.c
diff -u src/sys/netinet6/icmp6.c:1.219 src/sys/netinet6/icmp6.c:1.220
--- src/sys/netinet6/icmp6.c:1.219	Tue Jan 23 10:55:38 2018
+++ src/sys/netinet6/icmp6.c	Mon Feb 12 12:52:12 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: icmp6.c,v 1.219 2018/01/23 10:55:38 maxv Exp $	*/
+/*	$NetBSD: icmp6.c,v 1.220 2018/02/12 12:52:12 maxv Exp $	*/
 /*	$KAME: icmp6.c,v 1.217 2001/06/20 15:03:29 jinmei Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: icmp6.c,v 1.219 2018/01/23 10:55:38 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: icmp6.c,v 1.220 2018/02/12 12:52:12 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1486,7 +1486,7 @@ ni6_input(struct mbuf *m, int off)
 		nni6->ni_flags = htons(0x);	/* raw bitmap */
 		/* supports NOOP, SUPTYPES, FQDN, and NODEADDR */
 		v = (u_int32_t)htonl(0x000f);
-		bcopy(, nni6 + 1, sizeof(u_int32_t));
+		memcpy(nni6 + 1, , sizeof(u_int32_t));
 		break;
 	}
 	case NI_QTYPE_FQDN:
@@ -1580,7 +1580,7 @@ ni6_nametodns(const char *name, int name
 	if (old) {
 		m->m_len = len;
 		*mtod(m, char *) = namelen;
-		bcopy(name, mtod(m, char *) + 1, namelen);
+		memcpy(mtod(m, char *) + 1, name, namelen);
 		return m;
 	} else {
 		m->m_len = 0;
@@ -1927,7 +1927,7 @@ again:
 ltime = 0x7fff;
 			ltime = htonl(ltime);
 
-			bcopy(, cp, sizeof(u_int32_t));
+			memcpy(cp, , sizeof(u_int32_t));
 			cp += sizeof(u_int32_t);
 
 			/* copy the address itself */
@@ -2109,7 +2109,7 @@ icmp6_reflect(struct mbuf *m, size_t off
 			if ((m = m_pullup(m, l)) == NULL)
 return;
 		}
-		bcopy((void *), mtod(m, void *), sizeof(nip6));
+		memcpy(mtod(m, void *), (void *), sizeof(nip6));
 	} else {
 		size_t l = sizeof(struct ip6_hdr) + sizeof(struct icmp6_hdr);
 		if (m->m_len < l) {

Index: src/sys/netinet6/ip6_input.c
diff -u src/sys/netinet6/ip6_input.c:1.190 src/sys/netinet6/ip6_input.c:1.191
--- src/sys/netinet6/ip6_input.c:1.190	Fri Feb  9 18:31:52 2018
+++ src/sys/netinet6/ip6_input.c	Mon Feb 12 12:52:12 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6_input.c,v 1.190 2018/02/09 18:31:52 maxv Exp $	*/
+/*	$NetBSD: ip6_input.c,v 1.191 2018/02/12 12:52:12 maxv Exp $	*/
 /*	$KAME: ip6_input.c,v 1.188 2001/03/29 05:34:31 itojun Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.190 2018/02/09 18:31:52 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.191 2018/02/12 12:52:12 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_gateway.h"
@@ -960,7 +960,7 @@ ip6_process_hopopts(struct mbuf *m, u_in
 
 			/*
 			 * We may see jumbolen in unaligned location, so
-			 * we'd need to perform bcopy().
+			 * we'd need to perform memcpy().
 			 */
 			memcpy(, opt + 2, sizeof(jumboplen));
 			jumboplen = (u_int32_t)htonl(jumboplen);

Index: src/sys/netinet6/ip6_output.c
diff -u src/sys/netinet6/ip6_output.c:1.200 src/sys/netinet6/ip6_output.c:1.201
--- src/sys/netinet6/ip6_output.c:1.200	Wed Jan 31 15:23:08 2018
+++ src/sys/netinet6/ip6_output.c	Mon Feb 12 12:52:12 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6_output.c,v 1.200 2018/01/31 15:23:08 maxv Exp $	*/
+/*	$NetBSD: ip6_output.c,v 1.201 2018/02/12 12:52:12 maxv Exp $	*/
 /*	$KAME: ip6_output.c,v 1.172 2001/03/25 09:55:56 itojun Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip6_output.c,v 1.200 2018/01/31 15:23:08 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_output.c,v 1.201 2018/02/12 12:52:12 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1115,7 +1115,7 @@ ip6_copyexthdr(struct mbuf **mp, void *h
 	}
 	m->m_len = hlen;
 	if (hdr)
-		bcopy(hdr, mtod(m, void *), hlen);
+		memcpy(mtod(m, void *), hdr, hlen);
 
 	*mp = m;
 	return 0;
@@ -1236,7 +1236,7 @@ ip6_insert_jumboopt(struct ip6_exthdrs *
 	optbuf[2] = IP6OPT_JUMBO;
 	optbuf[3] = 4;
 	v = (u_int32_t)htonl(plen + JUMBOOPTLEN);
-	bcopy(, [4], sizeof(u_int32_t));
+	memcpy([4], , sizeof(u_int32_t));
 
 	/* finally, adjust the packet header length */
 	exthdrs->ip6e_ip6->m_pkthdr.len += JUMBOOPTLEN;
@@ -3328,7 +3328,7 @@ ip6_mloopback(struct ifnet *ifp, struct 
  * Chop IPv6 header off from the payload.
  */
 static int
-ip6_splithdr(struct mbuf *m,  struct ip6_exthdrs *exthdrs)
+ip6_splithdr(struct mbuf *m, struct ip6_exthdrs *exthdrs)
 {
 	struct mbuf *mh;
 	struct ip6_hdr *ip6;
@@ -3336,7 +3336,7 @@ ip6_splithdr(struct mbuf *m,  struct 

CVS commit: src/sys/netinet6

2018-02-08 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu Feb  8 11:49:37 UTC 2018

Modified Files:
src/sys/netinet6: udp6_usrreq.c

Log Message:
pr_send can be given a NULL lwp. It looks like the

control != NULL && lwp == NULL

condition is never supposed to happen, but add a panic for safety.


To generate a diff of this commit:
cvs rdiff -u -r1.132 -r1.133 src/sys/netinet6/udp6_usrreq.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/udp6_usrreq.c
diff -u src/sys/netinet6/udp6_usrreq.c:1.132 src/sys/netinet6/udp6_usrreq.c:1.133
--- src/sys/netinet6/udp6_usrreq.c:1.132	Thu Feb  8 11:34:35 2018
+++ src/sys/netinet6/udp6_usrreq.c	Thu Feb  8 11:49:37 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: udp6_usrreq.c,v 1.132 2018/02/08 11:34:35 maxv Exp $ */
+/* $NetBSD: udp6_usrreq.c,v 1.133 2018/02/08 11:49:37 maxv Exp $ */
 /* $KAME: udp6_usrreq.c,v 1.86 2001/05/27 17:33:00 itojun Exp $ */
 /* $KAME: udp6_output.c,v 1.43 2001/10/15 09:19:52 itojun Exp $ */
 
@@ -63,7 +63,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: udp6_usrreq.c,v 1.132 2018/02/08 11:34:35 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: udp6_usrreq.c,v 1.133 2018/02/08 11:49:37 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -708,6 +708,9 @@ udp6_output(struct in6pcb * const in6p, 
 	}
 
 	if (control) {
+		if (__predict_false(l == NULL)) {
+			panic("%s: control but no lwp", __func__);
+		}
 		if ((error = ip6_setpktopts(control, ,
 		in6p->in6p_outputopts, l->l_cred, IPPROTO_UDP)) != 0)
 			goto release;



CVS commit: src/sys/netinet6

2018-02-08 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu Feb  8 11:13:20 UTC 2018

Modified Files:
src/sys/netinet6: udp6_output.c udp6_usrreq.c

Log Message:
Style, no functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 src/sys/netinet6/udp6_output.c
cvs rdiff -u -r1.130 -r1.131 src/sys/netinet6/udp6_usrreq.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/udp6_output.c
diff -u src/sys/netinet6/udp6_output.c:1.55 src/sys/netinet6/udp6_output.c:1.56
--- src/sys/netinet6/udp6_output.c:1.55	Fri Mar  3 07:13:06 2017
+++ src/sys/netinet6/udp6_output.c	Thu Feb  8 11:13:20 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: udp6_output.c,v 1.55 2017/03/03 07:13:06 ozaki-r Exp $	*/
+/*	$NetBSD: udp6_output.c,v 1.56 2018/02/08 11:13:20 maxv Exp $	*/
 /*	$KAME: udp6_output.c,v 1.43 2001/10/15 09:19:52 itojun Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: udp6_output.c,v 1.55 2017/03/03 07:13:06 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: udp6_output.c,v 1.56 2018/02/08 11:13:20 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -190,13 +190,11 @@ udp6_output(struct in6pcb * const in6p, 
 			goto release;
 		}
 
-
 		faddr = >sin6_addr;
 		fport = sin6->sin6_port; /* allow 0 port */
 
 		if (IN6_IS_ADDR_V4MAPPED(faddr)) {
-			if ((in6p->in6p_flags & IN6P_IPV6_V6ONLY))
-			{
+			if ((in6p->in6p_flags & IN6P_IPV6_V6ONLY)) {
 /*
  * I believe we should explicitly discard the
  * packet when mapped addresses are disabled,
@@ -210,8 +208,8 @@ udp6_output(struct in6pcb * const in6p, 
 error = EINVAL;
 goto release;
 			}
-			if (!IN6_IS_ADDR_UNSPECIFIED(>in6p_laddr)
-			&& !IN6_IS_ADDR_V4MAPPED(>in6p_laddr)) {
+			if (!IN6_IS_ADDR_UNSPECIFIED(>in6p_laddr) &&
+			!IN6_IS_ADDR_V4MAPPED(>in6p_laddr)) {
 /*
  * when remote addr is an IPv4-mapped address,
  * local addr should not be an IPv6 address,
@@ -343,7 +341,7 @@ udp6_output(struct in6pcb * const in6p, 
 	 * for UDP and IP6 headers.
 	 */
 	M_PREPEND(m, hlen + sizeof(struct udphdr), M_DONTWAIT);
-	if (m == 0) {
+	if (m == NULL) {
 		error = ENOBUFS;
 		goto release;
 	}
@@ -366,7 +364,7 @@ udp6_output(struct in6pcb * const in6p, 
 		ip6->ip6_flow	= in6p->in6p_flowinfo & IPV6_FLOWINFO_MASK;
 		ip6->ip6_vfc 	&= ~IPV6_VERSION_MASK;
 		ip6->ip6_vfc 	|= IPV6_VERSION;
-#if 0/* ip6_plen will be filled in ip6_output. */
+#if 0		/* ip6_plen will be filled in ip6_output. */
 		ip6->ip6_plen	= htons((u_int16_t)plen);
 #endif
 		ip6->ip6_nxt	= IPPROTO_UDP;

Index: src/sys/netinet6/udp6_usrreq.c
diff -u src/sys/netinet6/udp6_usrreq.c:1.130 src/sys/netinet6/udp6_usrreq.c:1.131
--- src/sys/netinet6/udp6_usrreq.c:1.130	Thu Jul  6 17:08:57 2017
+++ src/sys/netinet6/udp6_usrreq.c	Thu Feb  8 11:13:20 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: udp6_usrreq.c,v 1.130 2017/07/06 17:08:57 christos Exp $	*/
+/*	$NetBSD: udp6_usrreq.c,v 1.131 2018/02/08 11:13:20 maxv Exp $	*/
 /*	$KAME: udp6_usrreq.c,v 1.86 2001/05/27 17:33:00 itojun Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: udp6_usrreq.c,v 1.130 2017/07/06 17:08:57 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: udp6_usrreq.c,v 1.131 2018/02/08 11:13:20 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -113,7 +113,7 @@ __KERNEL_RCSID(0, "$NetBSD: udp6_usrreq.
 #ifdef INET6
 #include 
 #endif
-#endif	/* IPSEC */
+#endif
 
 #include "faith.h"
 #if defined(NFAITH) && NFAITH > 0
@@ -130,12 +130,12 @@ extern struct inpcbtable udbtable;
 percpu_t *udp6stat_percpu;
 
 /* UDP on IP6 parameters */
-static int	udp6_sendspace = 9216;	/* really max datagram size */
-static int	udp6_recvspace = 40 * (1024 + sizeof(struct sockaddr_in6));
+static int udp6_sendspace = 9216;	/* really max datagram size */
+static int udp6_recvspace = 40 * (1024 + sizeof(struct sockaddr_in6));
 	/* 40 1K datagrams */
 
-static	void udp6_notify(struct in6pcb *, int);
-static	void sysctl_net_inet6_udp6_setup(struct sysctllog **);
+static void udp6_notify(struct in6pcb *, int);
+static void sysctl_net_inet6_udp6_setup(struct sysctllog **);
 
 #ifdef UDP_CSUM_COUNTERS
 #include 
@@ -255,7 +255,7 @@ udp6_ctlinput(int cmd, const struct sock
 			 */
 			if (in6_pcblookup_connect(, >sin6_addr,
 			uh.uh_dport, (const struct in6_addr *)_src->sin6_addr,
-		  uh.uh_sport, 0, 0))
+			uh.uh_sport, 0, 0))
 valid++;
 #if 0
 			/*
@@ -289,11 +289,11 @@ udp6_ctlinput(int cmd, const struct sock
 			 */
 		}
 
-		(void) in6_pcbnotify(, sa, uh.uh_dport,
+		(void)in6_pcbnotify(, sa, uh.uh_dport,
 		sin6tocsa(sa6_src), uh.uh_sport, cmd, cmdarg,
 		notify);
 	} else {
-		(void) in6_pcbnotify(, sa, 0,
+		(void)in6_pcbnotify(, sa, 0,
 		sin6tocsa(sa6_src), 0, cmd, cmdarg, notify);
 	}
 	return NULL;
@@ -339,7 +339,7 @@ end:
 
 static void
 udp6_sendup(struct mbuf *m, int off /* offset of data portion */,
-	struct 

CVS commit: src/sys/netinet6

2018-02-07 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Wed Feb  7 10:52:20 UTC 2018

Modified Files:
src/sys/netinet6: in6_proto.c

Log Message:
Style, and localify IPV6FORWARDING. No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.120 -r1.121 src/sys/netinet6/in6_proto.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_proto.c
diff -u src/sys/netinet6/in6_proto.c:1.120 src/sys/netinet6/in6_proto.c:1.121
--- src/sys/netinet6/in6_proto.c:1.120	Wed Feb  7 10:21:59 2018
+++ src/sys/netinet6/in6_proto.c	Wed Feb  7 10:52:20 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: in6_proto.c,v 1.120 2018/02/07 10:21:59 maxv Exp $	*/
+/*	$NetBSD: in6_proto.c,v 1.121 2018/02/07 10:52:20 maxv Exp $	*/
 /*	$KAME: in6_proto.c,v 1.66 2000/10/10 15:35:47 itojun Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in6_proto.c,v 1.120 2018/02/07 10:21:59 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6_proto.c,v 1.121 2018/02/07 10:52:20 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_gateway.h"
@@ -124,8 +124,7 @@ __KERNEL_RCSID(0, "$NetBSD: in6_proto.c,
 #include 
 #include 
 #include 
-#endif /* IPSEC */
-
+#endif
 
 #include "carp.h"
 #if NCARP > 0
@@ -553,51 +552,44 @@ sockaddr_in6_cmp(const struct sockaddr *
 /*
  * Internet configuration info
  */
-#ifndef	IPV6FORWARDING
 #ifdef GATEWAY6
-#define	IPV6FORWARDING	1	/* forward IP6 packets not for us */
+#define IPV6FORWARDING	1	/* forward IP6 packets not for us */
 #else
-#define	IPV6FORWARDING	0	/* don't forward IP6 packets not for us */
-#endif /* GATEWAY6 */
-#endif /* !IPV6FORWARDING */
-
-int	ip6_forwarding = IPV6FORWARDING;	/* act as router? */
-int	ip6_sendredirects = 1;
-int	ip6_defhlim = IPV6_DEFHLIM;
-int	ip6_defmcasthlim = IPV6_DEFAULT_MULTICAST_HOPS;
-int	ip6_accept_rtadv = 0;	/* "IPV6FORWARDING ? 0 : 1" is dangerous */
-int	ip6_maxfragpackets = 200;
-int	ip6_maxfrags = 200;
-int	ip6_log_interval = 5;
-int	ip6_hdrnestlimit = 15;	/* appropriate? */
-int	ip6_dad_count = 1;	/* DupAddrDetectionTransmits */
-int	ip6_auto_flowlabel = 1;
-int	ip6_use_deprecated = 1;	/* allow deprecated addr (RFC2462 5.5.4) */
-int	ip6_rr_prune = 5;	/* router renumbering prefix
- * walk list every 5 sec. */
-int	ip6_mcast_pmtu = 0;	/* enable pMTU discovery for multicast? */
-int	ip6_v6only = 1;
-int ip6_neighborgcthresh = 2048; /* Threshold # of NDP entries for GC */
-int ip6_maxifprefixes = 16; /* Max acceptable prefixes via RA per IF */
-int ip6_maxifdefrouters = 16; /* Max acceptable def routers via RA */
-int ip6_maxdynroutes = 4096; /* Max # of routes created via redirect */
-
-int	ip6_keepfaith = 0;
-time_t	ip6_log_time = 0;
-int	ip6_rtadv_maxroutes = 100; /* (arbitrary) initial maximum number of
-* routes via rtadv expected to be
-* significantly larger than common use.
-* if you need to count: 3 extra initial
-* routes, plus 1 per interface after the
-* first one, then one per non-linklocal
-* prefix */
+#define IPV6FORWARDING	0	/* don't forward IP6 packets not for us */
+#endif
+
+int ip6_forwarding = IPV6FORWARDING;	/* act as router? */
+int ip6_sendredirects = 1;
+int ip6_defhlim = IPV6_DEFHLIM;
+int ip6_defmcasthlim = IPV6_DEFAULT_MULTICAST_HOPS;
+int ip6_accept_rtadv = 0;
+int ip6_maxfragpackets = 200;
+int ip6_maxfrags = 200;
+int ip6_log_interval = 5;
+int ip6_hdrnestlimit = 15;
+int ip6_dad_count = 1;	/* DupAddrDetectionTransmits */
+int ip6_auto_flowlabel = 1;
+int ip6_use_deprecated = 1;	/* allow deprecated addr (RFC2462 5.5.4) */
+int ip6_rr_prune = 5;	/* router renumbering prefix
+ * walk list every 5 sec. */
+int ip6_mcast_pmtu = 0;	/* enable pMTU discovery for multicast? */
+int ip6_v6only = 1;
+int ip6_neighborgcthresh = 2048; /* Threshold # of NDP entries for GC */
+int ip6_maxifprefixes = 16; /* Max acceptable prefixes via RA per IF */
+int ip6_maxifdefrouters = 16; /* Max acceptable def routers via RA */
+int ip6_maxdynroutes = 4096; /* Max # of routes created via redirect */
+
+int ip6_keepfaith = 0;
+time_t ip6_log_time = 0;
+int ip6_rtadv_maxroutes = 100; /* (arbitrary) initial maximum number of
+* routes via rtadv expected to be
+* significantly larger than common use.
+* if you need to count: 3 extra initial
+* routes, plus 1 per interface after the
+* first one, then one per non-linklocal
+* prefix */
 
 /* icmp6 */
-/*
- * BSDI4 defines these variables in in_proto.c...
- * XXX: what if we don't define INET? Should we define pmtu6_expire
- * or so? 

CVS commit: src/sys/netinet6

2018-02-07 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Wed Feb  7 10:22:00 UTC 2018

Modified Files:
src/sys/netinet6: in6_proto.c

Log Message:
Change ip6_hdrnestlimit to be 15 instead of 50. I couldn't find any
reference in RFCs about what a correct limit should be, but FreeBSD already
uses 15.

If an IPv6 packet has 50 options, there is clearly something wrong with it.


To generate a diff of this commit:
cvs rdiff -u -r1.119 -r1.120 src/sys/netinet6/in6_proto.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_proto.c
diff -u src/sys/netinet6/in6_proto.c:1.119 src/sys/netinet6/in6_proto.c:1.120
--- src/sys/netinet6/in6_proto.c:1.119	Wed Sep 27 10:05:05 2017
+++ src/sys/netinet6/in6_proto.c	Wed Feb  7 10:21:59 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: in6_proto.c,v 1.119 2017/09/27 10:05:05 ozaki-r Exp $	*/
+/*	$NetBSD: in6_proto.c,v 1.120 2018/02/07 10:21:59 maxv Exp $	*/
 /*	$KAME: in6_proto.c,v 1.66 2000/10/10 15:35:47 itojun Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in6_proto.c,v 1.119 2017/09/27 10:05:05 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6_proto.c,v 1.120 2018/02/07 10:21:59 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_gateway.h"
@@ -569,7 +569,7 @@ int	ip6_accept_rtadv = 0;	/* "IPV6FORWAR
 int	ip6_maxfragpackets = 200;
 int	ip6_maxfrags = 200;
 int	ip6_log_interval = 5;
-int	ip6_hdrnestlimit = 50;	/* appropriate? */
+int	ip6_hdrnestlimit = 15;	/* appropriate? */
 int	ip6_dad_count = 1;	/* DupAddrDetectionTransmits */
 int	ip6_auto_flowlabel = 1;
 int	ip6_use_deprecated = 1;	/* allow deprecated addr (RFC2462 5.5.4) */



CVS commit: src/sys/netinet6

2018-02-07 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Wed Feb  7 09:53:09 UTC 2018

Modified Files:
src/sys/netinet6: frag6.c

Log Message:
Rename back to ip6af_mff. It was actually clearer than ip6af_more.


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 src/sys/netinet6/frag6.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/frag6.c
diff -u src/sys/netinet6/frag6.c:1.65 src/sys/netinet6/frag6.c:1.66
--- src/sys/netinet6/frag6.c:1.65	Tue Jan 30 14:49:25 2018
+++ src/sys/netinet6/frag6.c	Wed Feb  7 09:53:08 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: frag6.c,v 1.65 2018/01/30 14:49:25 maxv Exp $	*/
+/*	$NetBSD: frag6.c,v 1.66 2018/02/07 09:53:08 maxv Exp $	*/
 /*	$KAME: frag6.c,v 1.40 2002/05/27 21:40:31 itojun Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: frag6.c,v 1.65 2018/01/30 14:49:25 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: frag6.c,v 1.66 2018/02/07 09:53:08 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -90,7 +90,7 @@ struct	ip6asfrag {
 	int		ip6af_offset;	/* offset in ip6af_m to next header */
 	int		ip6af_frglen;	/* fragmentable part length */
 	int		ip6af_off;	/* fragment offset */
-	bool		ip6af_more;	/* more fragment bit in frag off */
+	bool		ip6af_mff;	/* more fragment bit in frag off */
 };
 
 
@@ -356,7 +356,7 @@ frag6_input(struct mbuf **mp, int *offp,
 	ip6af->ip6af_len = ip6->ip6_plen;
 	ip6af->ip6af_nxt = ip6->ip6_nxt;
 	ip6af->ip6af_hlim = ip6->ip6_hlim;
-	ip6af->ip6af_more = (ip6f->ip6f_offlg & IP6F_MORE_FRAG) != 0;
+	ip6af->ip6af_mff = (ip6f->ip6f_offlg & IP6F_MORE_FRAG) != 0;
 	ip6af->ip6af_off = fragoff;
 	ip6af->ip6af_frglen = frgpartlen;
 	ip6af->ip6af_offset = offset;
@@ -415,7 +415,7 @@ insert:
 		}
 		next += af6->ip6af_frglen;
 	}
-	if (af6->ip6af_up->ip6af_more) {
+	if (af6->ip6af_up->ip6af_mff) {
 		mutex_exit(_lock);
 		goto done;
 	}



CVS commit: src/sys/netinet6

2018-02-05 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Tue Feb  6 06:32:26 UTC 2018

Modified Files:
src/sys/netinet6: ip6_mroute.c ip6_mroute.h

Log Message:
Remove dead code.


To generate a diff of this commit:
cvs rdiff -u -r1.121 -r1.122 src/sys/netinet6/ip6_mroute.c
cvs rdiff -u -r1.17 -r1.18 src/sys/netinet6/ip6_mroute.h

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/ip6_mroute.c
diff -u src/sys/netinet6/ip6_mroute.c:1.121 src/sys/netinet6/ip6_mroute.c:1.122
--- src/sys/netinet6/ip6_mroute.c:1.121	Fri Feb  2 09:01:17 2018
+++ src/sys/netinet6/ip6_mroute.c	Tue Feb  6 06:32:25 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6_mroute.c,v 1.121 2018/02/02 09:01:17 maxv Exp $	*/
+/*	$NetBSD: ip6_mroute.c,v 1.122 2018/02/06 06:32:25 maxv Exp $	*/
 /*	$KAME: ip6_mroute.c,v 1.49 2001/07/25 09:21:18 jinmei Exp $	*/
 
 /*
@@ -117,7 +117,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip6_mroute.c,v 1.121 2018/02/02 09:01:17 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_mroute.c,v 1.122 2018/02/06 06:32:25 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -550,10 +550,7 @@ ip6_mrouter_done(void)
 			}
 		}
 	}
-#ifdef notyet
-	memset((void *)qtable, 0, sizeof(qtable));
-	memset((void *)tbftable, 0, sizeof(tbftable));
-#endif
+
 	memset((void *)mif6table, 0, sizeof(mif6table));
 	nummifs = 0;
 
@@ -649,9 +646,6 @@ add_m6if(struct mif6ctl *mifcp)
 	struct ifnet *ifp;
 	struct sockaddr_in6 sin6;
 	int error, s;
-#ifdef notyet
-	struct tbf *m_tbf = tbftable + mifcp->mif6c_mifi;
-#endif
 
 	if (mifcp->mif6c_mifi >= MAXMIFS)
 		return EINVAL;
@@ -754,10 +748,6 @@ del_m6if(mifi_t *mifip)
 		}
 	}
 
-#ifdef notyet
-	memset((void *)qtable[*mifip], 0, sizeof(qtable[*mifip]));
-	memset((void *)mifp->m6_tbf, 0, sizeof(*(mifp->m6_tbf)));
-#endif
 	memset((void *)mifp, 0, sizeof (*mifp));
 
 	/* Adjust nummifs down */

Index: src/sys/netinet6/ip6_mroute.h
diff -u src/sys/netinet6/ip6_mroute.h:1.17 src/sys/netinet6/ip6_mroute.h:1.18
--- src/sys/netinet6/ip6_mroute.h:1.17	Wed Mar 18 17:06:52 2009
+++ src/sys/netinet6/ip6_mroute.h	Tue Feb  6 06:32:25 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6_mroute.h,v 1.17 2009/03/18 17:06:52 cegger Exp $	*/
+/*	$NetBSD: ip6_mroute.h,v 1.18 2018/02/06 06:32:25 maxv Exp $	*/
 /*	$KAME: ip6_mroute.h,v 1.17 2001/02/10 02:05:52 itojun Exp $	*/
 
 /*
@@ -209,19 +209,12 @@ struct sioc_mif_req6 {
 struct mif6 {
 u_char   	m6_flags; 	/* MIFF_ flags defined above */
 	u_int  	m6_rate_limit; 	/* max rate			 */
-#ifdef notyet
-	struct tbf  *m6_tbf;  	/* token bucket structure at intf.   */
-#endif
 	struct in6_addr	m6_lcl_addr;   	/* local interface address   */
 	struct ifnet*m6_ifp; 	/* pointer to interface  */
 	u_quad_t	m6_pkt_in;	/* # pkts in on interface*/
 	u_quad_t	m6_pkt_out;	/* # pkts out on interface   */
 	u_quad_t	m6_bytes_in;	/* # bytes in on interface	 */
 	u_quad_t	m6_bytes_out;	/* # bytes out on interface	 */
-#ifdef notyet
-	u_int		m6_rsvp_on;	/* RSVP listening on this vif */
-	struct socket   *m6_rsvpd;	/* RSVP daemon socket */
-#endif
 };
 
 /*



CVS commit: src/sys/netinet6

2018-02-05 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Tue Feb  6 03:37:00 UTC 2018

Modified Files:
src/sys/netinet6: ip6_flow.c

Log Message:
Shorten the name of a workqueue instance to fit to the limit (15)


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/sys/netinet6/ip6_flow.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/ip6_flow.c
diff -u src/sys/netinet6/ip6_flow.c:1.39 src/sys/netinet6/ip6_flow.c:1.40
--- src/sys/netinet6/ip6_flow.c:1.39	Mon Jan 29 08:27:10 2018
+++ src/sys/netinet6/ip6_flow.c	Tue Feb  6 03:37:00 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6_flow.c,v 1.39 2018/01/29 08:27:10 maxv Exp $	*/
+/*	$NetBSD: ip6_flow.c,v 1.40 2018/02/06 03:37:00 ozaki-r Exp $	*/
 
 /*
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip6_flow.c,v 1.39 2018/01/29 08:27:10 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_flow.c,v 1.40 2018/02/06 03:37:00 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -231,7 +231,7 @@ ip6flow_init(int table_size)
 {
 	int ret, error;
 
-	error = workqueue_create(_slowtimo_wq, "ip6flow_slowtimo",
+	error = workqueue_create(_slowtimo_wq, "ip6flow",
 	ip6flow_slowtimo_work, NULL, PRI_SOFTNET, IPL_SOFTNET, WQ_MPSAFE);
 	if (error != 0)
 		panic("%s: workqueue_create failed (%d)\n", __func__, error);



CVS commit: src/sys/netinet6

2018-02-02 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Feb  2 10:49:01 UTC 2018

Modified Files:
src/sys/netinet6: nd6_nbr.c

Log Message:
Fix memory leak. Contrary to what the XXX indicates, this place is 100%
reachable remotely.


To generate a diff of this commit:
cvs rdiff -u -r1.144 -r1.145 src/sys/netinet6/nd6_nbr.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/nd6_nbr.c
diff -u src/sys/netinet6/nd6_nbr.c:1.144 src/sys/netinet6/nd6_nbr.c:1.145
--- src/sys/netinet6/nd6_nbr.c:1.144	Tue Jan 16 08:13:47 2018
+++ src/sys/netinet6/nd6_nbr.c	Fri Feb  2 10:49:01 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: nd6_nbr.c,v 1.144 2018/01/16 08:13:47 ozaki-r Exp $	*/
+/*	$NetBSD: nd6_nbr.c,v 1.145 2018/02/02 10:49:01 maxv Exp $	*/
 /*	$KAME: nd6_nbr.c,v 1.61 2001/02/10 16:06:14 jinmei Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nd6_nbr.c,v 1.144 2018/01/16 08:13:47 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nd6_nbr.c,v 1.145 2018/02/02 10:49:01 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -607,8 +607,7 @@ nd6_na_input(struct mbuf *m, int off, in
 
 	taddr6 = nd_na->nd_na_target;
 	if (in6_setscope(, ifp, NULL)) {
-		m_put_rcvif_psref(ifp, );
-		return;		/* XXX: impossible */
+		goto bad;
 	}
 
 	if (IN6_IS_ADDR_MULTICAST()) {



CVS commit: src/sys/netinet6

2018-02-02 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Feb  2 09:01:17 UTC 2018

Modified Files:
src/sys/netinet6: ip6_mroute.c

Log Message:
Style, no functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.120 -r1.121 src/sys/netinet6/ip6_mroute.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/ip6_mroute.c
diff -u src/sys/netinet6/ip6_mroute.c:1.120 src/sys/netinet6/ip6_mroute.c:1.121
--- src/sys/netinet6/ip6_mroute.c:1.120	Fri Feb  2 06:23:45 2018
+++ src/sys/netinet6/ip6_mroute.c	Fri Feb  2 09:01:17 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6_mroute.c,v 1.120 2018/02/02 06:23:45 maxv Exp $	*/
+/*	$NetBSD: ip6_mroute.c,v 1.121 2018/02/02 09:01:17 maxv Exp $	*/
 /*	$KAME: ip6_mroute.c,v 1.49 2001/07/25 09:21:18 jinmei Exp $	*/
 
 /*
@@ -117,7 +117,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip6_mroute.c,v 1.120 2018/02/02 06:23:45 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_mroute.c,v 1.121 2018/02/02 09:01:17 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -162,8 +162,7 @@ static int ip6_mdq(struct mbuf *, struct
 static void phyint_send(struct ip6_hdr *, struct mif6 *, struct mbuf *);
 
 static int set_pim6(int *);
-static int socket_send(struct socket *, struct mbuf *,
-	struct sockaddr_in6 *);
+static int socket_send(struct socket *, struct mbuf *, struct sockaddr_in6 *);
 static int register_send(struct ip6_hdr *, struct mif6 *, struct mbuf *);
 
 /*
@@ -376,7 +375,8 @@ ip6_mrouter_get(struct socket *so, struc
 {
 	int error;
 
-	if (so != ip6_mrouter) return EACCES;
+	if (so != ip6_mrouter)
+		return EACCES;
 
 	error = 0;
 
@@ -479,13 +479,13 @@ ip6_mrouter_init(struct socket *so, int 
 
 	if (so->so_type != SOCK_RAW ||
 	so->so_proto->pr_protocol != IPPROTO_ICMPV6)
-		return (EOPNOTSUPP);
+		return EOPNOTSUPP;
 
 	if (v != 1)
-		return (ENOPROTOOPT);
+		return ENOPROTOOPT;
 
 	if (ip6_mrouter != NULL)
-		return (EADDRINUSE);
+		return EADDRINUSE;
 
 	ip6_mrouter = so;
 	ip6_mrouter_ver = cmd;
@@ -591,7 +591,7 @@ ip6_mrouter_done(void)
 		if_detach(_register_if6);
 		reg_mif_num = (mifi_t)-1;
 	}
- 
+
 	ip6_mrouter = NULL;
 	ip6_mrouter_ver = 0;
 
@@ -639,7 +639,6 @@ ip6_mrouter_detach(struct ifnet *ifp)
 	}
 }
 
-
 /*
  * Add a mif to the mif table
  */
@@ -666,16 +665,14 @@ add_m6if(struct mif6ctl *mifcp)
 		ifp = _register_if6;
 
 		if (reg_mif_num == (mifi_t)-1) {
-			strlcpy(ifp->if_xname, "register_mif", 
+			strlcpy(ifp->if_xname, "register_mif",
 			sizeof(ifp->if_xname));
 			ifp->if_flags |= IFF_LOOPBACK;
 			ifp->if_index = mifcp->mif6c_mifi;
 			reg_mif_num = mifcp->mif6c_mifi;
 			if_attach(ifp);
 		}
-
-	} /* if REGISTER */
-	else {
+	} else {
 		/* Make sure the interface supports multicast */
 		if ((ifp->if_flags & IFF_MULTICAST) == 0)
 			return EOPNOTSUPP;
@@ -869,7 +866,7 @@ add_m6fc(struct mf6cctl *mfccp)
 m_freem(rte->m);
 #ifdef UPCALL_TIMING
 collate(&(rte->t));
-#endif /* UPCALL_TIMING */
+#endif
 free(rte, M_MRTABLE);
 rte = n;
 			}
@@ -916,8 +913,7 @@ add_m6fc(struct mf6cctl *mfccp)
 		}
 		if (rt == NULL) {
 			/* no upcall, so make a new entry */
-			rt = (struct mf6c *)malloc(sizeof(*rt), M_MRTABLE,
-		  M_NOWAIT);
+			rt = malloc(sizeof(*rt), M_MRTABLE, M_NOWAIT);
 			if (rt == NULL) {
 splx(s);
 return ENOBUFS;
@@ -1045,7 +1041,6 @@ socket_send(struct socket *s, struct mbu
  * erroneous, in which case a non-zero return value tells the caller to
  * discard it.
  */
-
 int
 ip6_mforward(struct ip6_hdr *ip6, struct ifnet *ifp, struct mbuf *m)
 {
@@ -1106,23 +1101,21 @@ ip6_mforward(struct ip6_hdr *ip6, struct
 	/* Entry exists, so forward if necessary */
 	if (rt) {
 		splx(s);
-		return (ip6_mdq(m, ifp, rt));
+		return ip6_mdq(m, ifp, rt);
 	} else {
 		/*
-		 * If we don't have a route for packet's origin,
-		 * Make a copy of the packet &
-		 * send message to routing daemon
+		 * If we don't have a route for packet's origin, make a copy
+		 * of the packet and send message to routing daemon.
 		 */
 
 		struct mbuf *mb0;
 		struct rtdetq *rte;
 		u_long hash;
-/*		int i, npkts;*/
+
 #ifdef UPCALL_TIMING
 		struct timeval tp;
-
 		GET_TIME(tp);
-#endif /* UPCALL_TIMING */
+#endif
 
 		mrt6stat.mrt6s_no_route++;
 #ifdef MRT6DEBUG
@@ -1136,13 +1129,13 @@ ip6_mforward(struct ip6_hdr *ip6, struct
 		 * Allocate mbufs early so that we don't do extra work if we
 		 * are just going to fail anyway.
 		 */
-		rte = (struct rtdetq *)malloc(sizeof(*rte), M_MRTABLE,
-	  M_NOWAIT);
+		rte = malloc(sizeof(*rte), M_MRTABLE, M_NOWAIT);
 		if (rte == NULL) {
 			splx(s);
 			return ENOBUFS;
 		}
 		mb0 = m_copy(m, 0, M_COPYALL);
+
 		/*
 		 * Pullup packet header if needed before storing it,
 		 * as other references may modify it in the meantime.
@@ -1172,14 +1165,14 @@ ip6_mforward(struct ip6_hdr *ip6, struct
 			struct omrt6msg *oim;
 
 			/* no upcall, so make a new entry 

  1   2   3   4   5   >