CVS commit: src/sys/net

2018-04-09 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Apr  9 10:32:32 UTC 2018

Modified Files:
src/sys/net: if_l2tp.c

Log Message:
Improve comment. Pointed out by maxv@n.o, thanks.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/net/if_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/net/if_l2tp.c
diff -u src/sys/net/if_l2tp.c:1.21 src/sys/net/if_l2tp.c:1.22
--- src/sys/net/if_l2tp.c:1.21	Mon Apr  9 10:06:59 2018
+++ src/sys/net/if_l2tp.c	Mon Apr  9 10:32:32 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_l2tp.c,v 1.21 2018/04/09 10:06:59 knakahara Exp $	*/
+/*	$NetBSD: if_l2tp.c,v 1.22 2018/04/09 10:32:32 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_l2tp.c,v 1.21 2018/04/09 10:06:59 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_l2tp.c,v 1.22 2018/04/09 10:32:32 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -477,6 +477,9 @@ l2tp_input(struct mbuf *m, struct ifnet 
 		return;
 	}
 
+	/*
+	 * If the head of the payload is not aligned, align it.
+	 */
 	addr = mtod(m, vaddr_t);
 	if ((addr & 0x03) == 0) {
 		/* copy and align head of payload */



CVS commit: src/sys/net

2018-04-09 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Apr  9 10:06:59 UTC 2018

Modified Files:
src/sys/net: if_l2tp.c

Log Message:
Fix l2tp(4) alignment check. Pointed out and reviewed by k-goda@IIJ.

The alignment check should be done for the address of m_data instead of
the value of m_data.

XXX pullup-8


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/net/if_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/net/if_l2tp.c
diff -u src/sys/net/if_l2tp.c:1.20 src/sys/net/if_l2tp.c:1.21
--- src/sys/net/if_l2tp.c:1.20	Fri Jan 26 14:10:15 2018
+++ src/sys/net/if_l2tp.c	Mon Apr  9 10:06:59 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_l2tp.c,v 1.20 2018/01/26 14:10:15 maxv Exp $	*/
+/*	$NetBSD: if_l2tp.c,v 1.21 2018/04/09 10:06:59 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_l2tp.c,v 1.20 2018/01/26 14:10:15 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_l2tp.c,v 1.21 2018/04/09 10:06:59 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -465,18 +465,20 @@ l2tpintr(struct l2tp_variant *var)
 void
 l2tp_input(struct mbuf *m, struct ifnet *ifp)
 {
-	u_long val;
+	vaddr_t addr;
 
 	KASSERT(ifp != NULL);
 
-	if (m->m_pkthdr.len < sizeof(val)) {
+	/*
+	 * Currently, l2tp(4) supports only ethernet as inner protocol.
+	 */
+	if (m->m_pkthdr.len < sizeof(struct ether_header)) {
 		m_freem(m);
 		return;
 	}
 
-	m_copydata(m, 0, sizeof(val), &val);
-
-	if ((val & 0x03) == 0) {
+	addr = mtod(m, vaddr_t);
+	if ((addr & 0x03) == 0) {
 		/* copy and align head of payload */
 		struct mbuf *m_head;
 		int copy_length;



CVS commit: src/sys

2018-04-06 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Apr  6 10:38:53 UTC 2018

Modified Files:
src/sys/net: if_ipsec.c
src/sys/netipsec: ipsecif.c ipsecif.h

Log Message:
Fix unexpected failure when ipsecif(4) over IPv6 is changed port number only.

Here is an example of the operation which causes this problem.
# ifconfig ipsec0 create link0
# ifconfig ipsec0 tunnel fc00:1001::2,4500 fc00:1001::1,4501
# ifconfig ipsec0 tunnel fc00:1001::2,4500 fc00:1001::1,4502


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/net/if_ipsec.c
cvs rdiff -u -r1.6 -r1.7 src/sys/netipsec/ipsecif.c
cvs rdiff -u -r1.1 -r1.2 src/sys/netipsec/ipsecif.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/net/if_ipsec.c
diff -u src/sys/net/if_ipsec.c:1.10 src/sys/net/if_ipsec.c:1.11
--- src/sys/net/if_ipsec.c:1.10	Fri Apr  6 09:30:09 2018
+++ src/sys/net/if_ipsec.c	Fri Apr  6 10:38:53 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ipsec.c,v 1.10 2018/04/06 09:30:09 knakahara Exp $  */
+/*	$NetBSD: if_ipsec.c,v 1.11 2018/04/06 10:38:53 knakahara Exp $  */
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_ipsec.c,v 1.10 2018/04/06 09:30:09 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ipsec.c,v 1.11 2018/04/06 10:38:53 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -280,7 +280,7 @@ if_ipsec_fwd_ipv6(struct ipsec_softc *sc
 int
 if_ipsec_encap_func(struct mbuf *m, int off, int proto, void *arg)
 {
-	struct ip ip;
+	uint8_t v;
 	struct ipsec_softc *sc;
 	struct ipsec_variant *var = NULL;
 	struct psref psref;
@@ -304,18 +304,39 @@ if_ipsec_encap_func(struct mbuf *m, int 
 		goto out;
 	}
 
-	if (m->m_pkthdr.len < sizeof(ip))
-		goto out;
+	m_copydata(m, 0, sizeof(v), &v);
+	v = (v >> 4) & 0xff;  /* Get the IP version number. */
 
-	m_copydata(m, 0, sizeof(ip), &ip);
-	switch (ip.ip_v) {
+	switch (v) {
 #ifdef INET
-	case IPVERSION:
+	case IPVERSION: {
+		struct ip ip;
+
+		if (m->m_pkthdr.len < sizeof(ip))
+			goto out;
+
+		m_copydata(m, 0, sizeof(ip), &ip);
 		if (var->iv_psrc->sa_family != AF_INET ||
 		var->iv_pdst->sa_family != AF_INET)
 			goto out;
 		ret = ipsecif4_encap_func(m, &ip, var);
 		break;
+	}
+#endif
+#ifdef INET6
+	case (IPV6_VERSION >> 4): {
+		struct ip6_hdr ip6;
+
+		if (m->m_pkthdr.len < sizeof(ip6))
+			goto out;
+
+		m_copydata(m, 0, sizeof(ip6), &ip6);
+		if (var->iv_psrc->sa_family != AF_INET6 ||
+		var->iv_pdst->sa_family != AF_INET6)
+			goto out;
+		ret = ipsecif6_encap_func(m, &ip6, var);
+		break;
+	}
 #endif
 	default:
 		goto out;

Index: src/sys/netipsec/ipsecif.c
diff -u src/sys/netipsec/ipsecif.c:1.6 src/sys/netipsec/ipsecif.c:1.7
--- src/sys/netipsec/ipsecif.c:1.6	Fri Apr  6 10:31:35 2018
+++ src/sys/netipsec/ipsecif.c	Fri Apr  6 10:38:53 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ipsecif.c,v 1.6 2018/04/06 10:31:35 knakahara Exp $  */
+/*	$NetBSD: ipsecif.c,v 1.7 2018/04/06 10:38:53 knakahara Exp $  */
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ipsecif.c,v 1.6 2018/04/06 10:31:35 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ipsecif.c,v 1.7 2018/04/06 10:38:53 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -412,6 +412,57 @@ done:
 }
 
 #ifdef INET6
+int
+ipsecif6_encap_func(struct mbuf *m, struct ip6_hdr *ip6, struct ipsec_variant *var)
+{
+	struct m_tag *mtag;
+	struct sockaddr_in6 *src, *dst;
+	u_int16_t src_port = 0;
+	u_int16_t dst_port = 0;
+
+	KASSERT(var != NULL);
+
+	src = satosin6(var->iv_psrc);
+	dst = satosin6(var->iv_pdst);
+	mtag = m_tag_find(m, PACKET_TAG_IPSEC_NAT_T_PORTS, NULL);
+	if (mtag) {
+		u_int16_t *ports;
+
+		ports = (u_int16_t *)(mtag + 1);
+		src_port = ports[0];
+		dst_port = ports[1];
+	}
+
+	/* address match */
+	if (!IN6_ARE_ADDR_EQUAL(&src->sin6_addr, &ip6->ip6_dst) ||
+	!IN6_ARE_ADDR_EQUAL(&dst->sin6_addr, &ip6->ip6_src))
+		return 0;
+
+	/* UDP encap? */
+	if (mtag == NULL && var->iv_sport == 0 && var->iv_dport == 0)
+		goto match;
+
+	/* port match */
+	if (src_port != var->iv_dport ||
+	dst_port != var->iv_sport) {
+#ifdef DEBUG
+		printf("%s: port mismatch: pkt(%u, %u), if(%u, %u)\n",
+		__func__, ntohs(src_port), ntohs(dst_port),
+		ntohs(var->iv_sport), ntohs(var->iv_dport));
+#endif
+		return 0;
+	}
+
+match:
+	/*
+	 * hide NAT-T information from encapsulated traffics.
+	 * they don't know about IPsec.
+	 */
+	if (mtag)
+		m_tag_delete(m, mtag);
+	return sizeof(src->sin6_addr) + sizeof(dst->sin6_addr);
+}
+
 static int
 ipsecif6_output(struct ipsec_variant *var, int family, struct mbuf *m)
 {
@@ -841,9 +892,7 @@ ipsecif6_attach(struct ipsec_variant *va
 	mask6.sin6_addr.s6_addr32[0] = mask6.sin6_addr.s6_addr32[1] =
 	mask6.sin6_addr.s6_addr32[2] = mask6.sin6_addr.s6_addr32[3] = ~0;
 
-	var->iv_enca

CVS commit: src/sys/netipsec

2018-04-06 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Apr  6 10:31:35 UTC 2018

Modified Files:
src/sys/netipsec: ipsecif.c

Log Message:
Add IPv4 ID when the ipsecif(4) packet can be fragmented. Implemented by 
hsuenaga@IIJ and ohishi@IIJ, thanks.

This modification reduces packet loss of fragmented packets on a
network where reordering occurs.

Alghough this modification has been applied, IPv4 ID is not set for
the packet smaller then IP_MINFRAGSIZE. According to RFC 6864, that
must not cause problems.

XXX pullup-8


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/netipsec/ipsecif.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/netipsec/ipsecif.c
diff -u src/sys/netipsec/ipsecif.c:1.5 src/sys/netipsec/ipsecif.c:1.6
--- src/sys/netipsec/ipsecif.c:1.5	Tue Mar 13 03:05:12 2018
+++ src/sys/netipsec/ipsecif.c	Fri Apr  6 10:31:35 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ipsecif.c,v 1.5 2018/03/13 03:05:12 knakahara Exp $  */
+/*	$NetBSD: ipsecif.c,v 1.6 2018/04/06 10:31:35 knakahara Exp $  */
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ipsecif.c,v 1.5 2018/03/13 03:05:12 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ipsecif.c,v 1.6 2018/04/06 10:31:35 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -135,7 +135,10 @@ ipsecif4_prepend_hdr(struct ipsec_varian
 	ip = mtod(m, struct ip *);
 	ip->ip_v = IPVERSION;
 	ip->ip_off = htons(0);
-	ip->ip_id = 0;
+	if (m->m_pkthdr.len < IP_MINFRAGSIZE)
+		ip->ip_id = 0;
+	else
+		ip->ip_id = ip_newid(NULL);
 	ip->ip_hl = sizeof(*ip) >> 2;
 	if (ip_ipsec_copy_tos)
 		ip->ip_tos = tos;



CVS commit: src/sys/net

2018-04-06 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Apr  6 09:30:09 UTC 2018

Modified Files:
src/sys/net: if_ipsec.c

Log Message:
fix ipsecif(4) stack overflow.

XXX pullup-8


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/net/if_ipsec.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/net/if_ipsec.c
diff -u src/sys/net/if_ipsec.c:1.9 src/sys/net/if_ipsec.c:1.10
--- src/sys/net/if_ipsec.c:1.9	Fri Apr  6 09:28:26 2018
+++ src/sys/net/if_ipsec.c	Fri Apr  6 09:30:09 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ipsec.c,v 1.9 2018/04/06 09:28:26 knakahara Exp $  */
+/*	$NetBSD: if_ipsec.c,v 1.10 2018/04/06 09:30:09 knakahara Exp $  */
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_ipsec.c,v 1.9 2018/04/06 09:28:26 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ipsec.c,v 1.10 2018/04/06 09:30:09 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -76,6 +76,7 @@ __KERNEL_RCSID(0, "$NetBSD: if_ipsec.c,v
 #include 
 
 #include 
+#include  /* for union sockaddr_union */
 #include 
 #include 
 
@@ -1340,10 +1341,11 @@ if_ipsec_add_mbuf_addr_port(struct mbuf 
 	if (port == 0) {
 		if_ipsec_add_mbuf_optalign(m0, addr, addr->sa_len, align);
 	} else {
-		struct sockaddr addrport;
+		union sockaddr_union addrport_u;
+		struct sockaddr *addrport = &addrport_u.sa;
 
-		if_ipsec_set_addr_port(&addrport, addr, port);
-		if_ipsec_add_mbuf_optalign(m0, &addrport, addrport.sa_len, align);
+		if_ipsec_set_addr_port(addrport, addr, port);
+		if_ipsec_add_mbuf_optalign(m0, addrport, addrport->sa_len, align);
 	}
 }
 



CVS commit: src/sys/net

2018-04-06 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Apr  6 09:28:26 UTC 2018

Modified Files:
src/sys/net: if_ipsec.c

Log Message:
fix ipsecif(4) unmatch curlwp_bind.

XXX pullup-8


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/net/if_ipsec.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/net/if_ipsec.c
diff -u src/sys/net/if_ipsec.c:1.8 src/sys/net/if_ipsec.c:1.9
--- src/sys/net/if_ipsec.c:1.8	Fri Apr  6 09:24:13 2018
+++ src/sys/net/if_ipsec.c	Fri Apr  6 09:28:26 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ipsec.c,v 1.8 2018/04/06 09:24:13 knakahara Exp $  */
+/*	$NetBSD: if_ipsec.c,v 1.9 2018/04/06 09:28:26 knakahara Exp $  */
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_ipsec.c,v 1.8 2018/04/06 09:24:13 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ipsec.c,v 1.9 2018/04/06 09:28:26 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -637,6 +637,7 @@ if_ipsec_ioctl(struct ifnet *ifp, u_long
 		error = if_ipsec_set_tunnel(&sc->ipsec_if, src, dst);
 		if (error)
 			goto bad;
+		curlwp_bindx(bound);
 		break;
 
 	case SIOCDIFPHYADDR:
@@ -769,6 +770,7 @@ if_ipsec_ioctl(struct ifnet *ifp, u_long
 			error = if_ipsec_ensure_flags(&sc->ipsec_if, oflags);
 			if (error)
 goto bad;
+			curlwp_bindx(bound);
 		}
 		break;
 	}



CVS commit: src/sys/net

2018-04-06 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Apr  6 09:24:13 UTC 2018

Modified Files:
src/sys/net: if_ipsec.c

Log Message:
fix ipsec(4) encap_lock leak.

XXX pullup-8


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/net/if_ipsec.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/net/if_ipsec.c
diff -u src/sys/net/if_ipsec.c:1.7 src/sys/net/if_ipsec.c:1.8
--- src/sys/net/if_ipsec.c:1.7	Tue Mar 13 02:12:05 2018
+++ src/sys/net/if_ipsec.c	Fri Apr  6 09:24:13 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ipsec.c,v 1.7 2018/03/13 02:12:05 knakahara Exp $  */
+/*	$NetBSD: if_ipsec.c,v 1.8 2018/04/06 09:24:13 knakahara Exp $  */
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_ipsec.c,v 1.7 2018/03/13 02:12:05 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ipsec.c,v 1.8 2018/04/06 09:24:13 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1166,6 +1166,7 @@ if_ipsec_ensure_flags(struct ifnet *ifp,
 	if (if_ipsec_variant_is_unconfigured(ovar)) {
 		/* nothing to do */
 		mutex_exit(&sc->ipsec_lock);
+		encap_lock_exit();
 		return 0;
 	}
 



CVS commit: src/sys/dev/pci/ixgbe

2018-04-01 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Apr  2 05:02:55 UTC 2018

Modified Files:
src/sys/dev/pci/ixgbe: ix_txrx.c ixgbe.c ixgbe.h

Log Message:
Avoid issues caused by sending old packets at next link-up time.

This modification consists by the following two parts.
- drain packets in if_snd queue or corresponding txr->txr_interq
  when link_active == false in ifp->if_start(), ifp->if_transmit(),
  and deferred Tx processing
- drain packets in if_snd queue and all of txr->txr_interq's
  at link-down time

ok by msaitoh@n.o.


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/sys/dev/pci/ixgbe/ix_txrx.c
cvs rdiff -u -r1.140 -r1.141 src/sys/dev/pci/ixgbe/ixgbe.c
cvs rdiff -u -r1.39 -r1.40 src/sys/dev/pci/ixgbe/ixgbe.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/dev/pci/ixgbe/ix_txrx.c
diff -u src/sys/dev/pci/ixgbe/ix_txrx.c:1.37 src/sys/dev/pci/ixgbe/ix_txrx.c:1.38
--- src/sys/dev/pci/ixgbe/ix_txrx.c:1.37	Fri Mar 30 03:58:20 2018
+++ src/sys/dev/pci/ixgbe/ix_txrx.c	Mon Apr  2 05:02:55 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: ix_txrx.c,v 1.37 2018/03/30 03:58:20 knakahara Exp $ */
+/* $NetBSD: ix_txrx.c,v 1.38 2018/04/02 05:02:55 knakahara Exp $ */
 
 /**
 
@@ -103,6 +103,7 @@ static void  ixgbe_free_receive_
 static void  ixgbe_rx_checksum(u32, struct mbuf *, u32,
struct ixgbe_hw_stats *);
 static void  ixgbe_refresh_mbufs(struct rx_ring *, int);
+static void  ixgbe_drain(struct ifnet *, struct tx_ring *);
 static int   ixgbe_xmit(struct tx_ring *, struct mbuf *);
 static int   ixgbe_tx_ctx_setup(struct tx_ring *,
 struct mbuf *, u32 *, u32 *);
@@ -135,9 +136,15 @@ ixgbe_legacy_start_locked(struct ifnet *
 
 	IXGBE_TX_LOCK_ASSERT(txr);
 
-	if ((ifp->if_flags & IFF_RUNNING) == 0)
+	if (!adapter->link_active) {
+		/*
+		 * discard all packets buffered in IFQ to avoid
+		 * sending old packets at next link up timing.
+		 */
+		ixgbe_drain(ifp, txr);
 		return (ENETDOWN);
-	if (!adapter->link_active)
+	}
+	if ((ifp->if_flags & IFF_RUNNING) == 0)
 		return (ENETDOWN);
 
 	while (!IFQ_IS_EMPTY(&ifp->if_snd)) {
@@ -271,9 +278,15 @@ ixgbe_mq_start_locked(struct ifnet *ifp,
 	struct mbuf*next;
 	intenqueued = 0, err = 0;
 
-	if ((ifp->if_flags & IFF_RUNNING) == 0)
+	if (!txr->adapter->link_active) {
+		/*
+		 * discard all packets buffered in txr_interq to avoid
+		 * sending old packets at next link up timing.
+		 */
+		ixgbe_drain(ifp, txr);
 		return (ENETDOWN);
-	if (txr->adapter->link_active == 0)
+	}
+	if ((ifp->if_flags & IFF_RUNNING) == 0)
 		return (ENETDOWN);
 
 	/* Process the queue */
@@ -342,6 +355,23 @@ ixgbe_deferred_mq_start_work(struct work
 	ixgbe_deferred_mq_start(txr);
 } /* ixgbe_deferred_mq_start */
 
+/
+ * ixgbe_drain_all
+ /
+void
+ixgbe_drain_all(struct adapter *adapter)
+{
+	struct ifnet *ifp = adapter->ifp;
+	struct ix_queue *que = adapter->queues;
+
+	for (int i = 0; i < adapter->num_queues; i++, que++) {
+		struct tx_ring  *txr = que->txr;
+
+		IXGBE_TX_LOCK(txr);
+		ixgbe_drain(ifp, txr);
+		IXGBE_TX_UNLOCK(txr);
+	}
+}
 
 /
  * ixgbe_xmit
@@ -515,6 +545,29 @@ retry:
 	return (0);
 } /* ixgbe_xmit */
 
+/
+ * ixgbe_drain
+ /
+static void
+ixgbe_drain(struct ifnet *ifp, struct tx_ring *txr)
+{
+	struct mbuf *m;
+
+	IXGBE_TX_LOCK_ASSERT(txr);
+
+	if (txr->me == 0) {
+		while (!IFQ_IS_EMPTY(&ifp->if_snd)) {
+			IFQ_DEQUEUE(&ifp->if_snd, m);
+			m_freem(m);
+			IF_DROP(&ifp->if_snd);
+		}
+	}
+
+	while ((m = pcq_get(txr->txr_interq)) != NULL) {
+		m_freem(m);
+		txr->pcq_drops.ev_count++;
+	}
+}
 
 /
  * ixgbe_allocate_transmit_buffers

Index: src/sys/dev/pci/ixgbe/ixgbe.c
diff -u src/sys/dev/pci/ixgbe/ixgbe.c:1.140 src/sys/dev/pci/ixgbe/ixgbe.c:1.141
--- src/sys/dev/pci/ixgbe/ixgbe.c:1.140	Fri Mar 30 06:44:30 2018
+++ src/sys/dev/pci/ixgbe/ixgbe.c	Mon Apr  2 05:02:55 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe.c,v 1.140 2018/03/30 06:44:30 msaitoh Exp $ */
+/* $NetBSD: ixgbe.c,v 1.141 2018/04/02 05:02:55 knakahara Exp $ */
 
 /**
 
@@ -4600,6 +4600,7 @@ ixgbe_update_link_status(struct adapter 
 			adapter->link_active = FALSE;
 			if (adapter->feat_en & IXGBE_FEATURE_SRIOV)
 ixgbe_ping_all_vfs(adapter);
+			ixgbe_dr

CVS commit: src/sys/dev/pci/ixgbe

2018-03-29 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Mar 30 03:58:20 UTC 2018

Modified Files:
src/sys/dev/pci/ixgbe: ix_txrx.c ixgbe.c ixgbe.h ixgbe_api.h
ixgbe_common.c ixv.c

Log Message:
Don't write EIMC directly. It is required to manage with struct ix_queue status.

XXX pullup-8


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/sys/dev/pci/ixgbe/ix_txrx.c
cvs rdiff -u -r1.138 -r1.139 src/sys/dev/pci/ixgbe/ixgbe.c
cvs rdiff -u -r1.38 -r1.39 src/sys/dev/pci/ixgbe/ixgbe.h
cvs rdiff -u -r1.11 -r1.12 src/sys/dev/pci/ixgbe/ixgbe_api.h
cvs rdiff -u -r1.18 -r1.19 src/sys/dev/pci/ixgbe/ixgbe_common.c
cvs rdiff -u -r1.89 -r1.90 src/sys/dev/pci/ixgbe/ixv.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/dev/pci/ixgbe/ix_txrx.c
diff -u src/sys/dev/pci/ixgbe/ix_txrx.c:1.36 src/sys/dev/pci/ixgbe/ix_txrx.c:1.37
--- src/sys/dev/pci/ixgbe/ix_txrx.c:1.36	Thu Mar 15 06:48:51 2018
+++ src/sys/dev/pci/ixgbe/ix_txrx.c	Fri Mar 30 03:58:20 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: ix_txrx.c,v 1.36 2018/03/15 06:48:51 msaitoh Exp $ */
+/* $NetBSD: ix_txrx.c,v 1.37 2018/03/30 03:58:20 knakahara Exp $ */
 
 /**
 
@@ -2298,8 +2298,8 @@ ixgbe_allocate_queues(struct adapter *ad
 		que->txr = &adapter->tx_rings[i];
 		que->rxr = &adapter->rx_rings[i];
 
-		mutex_init(&que->im_mtx, MUTEX_DEFAULT, IPL_NET);
-		que->im_nest = 0;
+		mutex_init(&que->dc_mtx, MUTEX_DEFAULT, IPL_NET);
+		que->disabled_count = 0;
 	}
 
 	return (0);

Index: src/sys/dev/pci/ixgbe/ixgbe.c
diff -u src/sys/dev/pci/ixgbe/ixgbe.c:1.138 src/sys/dev/pci/ixgbe/ixgbe.c:1.139
--- src/sys/dev/pci/ixgbe/ixgbe.c:1.138	Fri Mar 30 03:56:38 2018
+++ src/sys/dev/pci/ixgbe/ixgbe.c	Fri Mar 30 03:58:20 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe.c,v 1.138 2018/03/30 03:56:38 knakahara Exp $ */
+/* $NetBSD: ixgbe.c,v 1.139 2018/03/30 03:58:20 knakahara Exp $ */
 
 /**
 
@@ -2410,8 +2410,8 @@ ixgbe_enable_queue(struct adapter *adapt
 	u64 queue = (u64)(1ULL << vector);
 	u32 mask;
 
-	mutex_enter(&que->im_mtx);
-	if (que->im_nest > 0 && --que->im_nest > 0)
+	mutex_enter(&que->dc_mtx);
+	if (que->disabled_count > 0 && --que->disabled_count > 0)
 		goto out;
 
 	if (hw->mac.type == ixgbe_mac_82598EB) {
@@ -2426,23 +2426,28 @@ ixgbe_enable_queue(struct adapter *adapt
 			IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
 	}
 out:
-	mutex_exit(&que->im_mtx);
+	mutex_exit(&que->dc_mtx);
 } /* ixgbe_enable_queue */
 
 /
- * ixgbe_disable_queue
+ * ixgbe_disable_queue_internal
  /
 static inline void
-ixgbe_disable_queue(struct adapter *adapter, u32 vector)
+ixgbe_disable_queue_internal(struct adapter *adapter, u32 vector, bool nestok)
 {
 	struct ixgbe_hw *hw = &adapter->hw;
 	struct ix_queue *que = &adapter->queues[vector];
 	u64 queue = (u64)(1ULL << vector);
 	u32 mask;
 
-	mutex_enter(&que->im_mtx);
-	if (que->im_nest++ > 0)
-		goto  out;
+	mutex_enter(&que->dc_mtx);
+
+	if (que->disabled_count > 0) {
+		if (nestok)
+			que->disabled_count++;
+		goto out;
+	}
+	que->disabled_count++;
 
 	if (hw->mac.type == ixgbe_mac_82598EB) {
 		mask = (IXGBE_EIMS_RTX_QUEUE & queue);
@@ -2456,7 +2461,17 @@ ixgbe_disable_queue(struct adapter *adap
 			IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
 	}
 out:
-	mutex_exit(&que->im_mtx);
+	mutex_exit(&que->dc_mtx);
+} /* ixgbe_disable_queue_internal */
+
+/
+ * ixgbe_disable_queue
+ /
+static inline void
+ixgbe_disable_queue(struct adapter *adapter, u32 vector)
+{
+
+	ixgbe_disable_queue_internal(adapter, vector, true);
 } /* ixgbe_disable_queue */
 
 /
@@ -3511,7 +3526,7 @@ ixgbe_detach(device_t dev, int flags)
 	ixgbe_free_receive_structures(adapter);
 	for (int i = 0; i < adapter->num_queues; i++) {
 		struct ix_queue * que = &adapter->queues[i];
-		mutex_destroy(&que->im_mtx);
+		mutex_destroy(&que->dc_mtx);
 	}
 	free(adapter->queues, M_DEVBUF);
 	free(adapter->mta, M_DEVBUF);
@@ -4295,11 +4310,11 @@ ixgbe_local_timer1(void *arg)
 	else if (queues != 0) { /* Force an IRQ on queues with work */
 		que = adapter->queues;
 		for (i = 0; i < adapter->num_queues; i++, que++) {
-			mutex_enter(&que->im_mtx);
-			if (que->im_nest == 0)
+			mutex_enter(&que->dc_mtx);
+			if (que->disabled_count == 0)
 ixgbe_rearm_queues(adapter,
 queues & ((u64)1 << i));
-			mutex_exit(&que->im_mtx);
+			mutex_exit(&que->dc_mtx);
 		}
 	}
 
@@ -4697,10 +4712,10 @@ ixgbe_enable_int

CVS commit: src/sys/dev/pci/ixgbe

2018-03-29 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Mar 30 03:56:38 UTC 2018

Modified Files:
src/sys/dev/pci/ixgbe: ixgbe.c ixgbe.h

Log Message:
Fix the problem between eitr and link_speed.

In ixgbe_msix_que(), que->eitr_setting is limited to IXGBE_MIN_RSC_EITR_10G1G
when link_speed is 1Gbps or 10Gbps. However, que->eitr_setting is set to EITR
register in the *next* Tx/Rx interrupt. If link_speed changes from 100Mbps to
1Gbps ro 10Gbps, que->eitr_setting which is not limited can be set to EITR
register, that is, the problem fixed by ixgbe.c:r1.124 can occur in this case.

To fix this case, que->eitr_setting should be clear when link_speed is changed
or link state is changed.

Furthermore, expand the variants used for AIM (txr->bytes, txr->packets,
rxr->bytes and rxr->packets) from u32 to u64 to avoid wraparound which causes
que->eitr_setting calculation mistake.

XXX pullup-8


To generate a diff of this commit:
cvs rdiff -u -r1.137 -r1.138 src/sys/dev/pci/ixgbe/ixgbe.c
cvs rdiff -u -r1.37 -r1.38 src/sys/dev/pci/ixgbe/ixgbe.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/dev/pci/ixgbe/ixgbe.c
diff -u src/sys/dev/pci/ixgbe/ixgbe.c:1.137 src/sys/dev/pci/ixgbe/ixgbe.c:1.138
--- src/sys/dev/pci/ixgbe/ixgbe.c:1.137	Mon Mar 26 06:40:28 2018
+++ src/sys/dev/pci/ixgbe/ixgbe.c	Fri Mar 30 03:56:38 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe.c,v 1.137 2018/03/26 06:40:28 msaitoh Exp $ */
+/* $NetBSD: ixgbe.c,v 1.138 2018/03/30 03:56:38 knakahara Exp $ */
 
 /**
 
@@ -4012,6 +4012,13 @@ ixgbe_configure_ivars(struct adapter *ad
 		ixgbe_set_ivar(adapter, txr->me, que->msix, 1);
 		/* Set an Initial EITR value */
 		ixgbe_eitr_write(que, newitr);
+		/*
+		 * To eliminate influence of the previous state.
+		 * At this point, Tx/Rx interrupt handler
+		 * (ixgbe_msix_que()) cannot be called, so  both
+		 * IXGBE_TX_LOCK and IXGBE_RX_LOCK are not required.
+		 */
+		que->eitr_setting = 0;
 	}
 
 	/* For the Link interrupt */
@@ -4509,6 +4516,14 @@ ixgbe_update_link_status(struct adapter 
 
 	if (adapter->link_up) {
 		if (adapter->link_active == FALSE) {
+			/*
+			 * To eliminate influence of the previous state
+			 * in the same way as ixgbe_init_locked().
+			 */
+			struct ix_queue	*que = adapter->queues;
+			for (int i = 0; i < adapter->num_queues; i++, que++)
+que->eitr_setting = 0;
+
 			if (adapter->link_speed == IXGBE_LINK_SPEED_10GB_FULL){
 /*
  *  Discard count for both MAC Local Fault and

Index: src/sys/dev/pci/ixgbe/ixgbe.h
diff -u src/sys/dev/pci/ixgbe/ixgbe.h:1.37 src/sys/dev/pci/ixgbe/ixgbe.h:1.38
--- src/sys/dev/pci/ixgbe/ixgbe.h:1.37	Mon Mar 26 06:40:28 2018
+++ src/sys/dev/pci/ixgbe/ixgbe.h	Fri Mar 30 03:56:38 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe.h,v 1.37 2018/03/26 06:40:28 msaitoh Exp $ */
+/* $NetBSD: ixgbe.h,v 1.38 2018/03/30 03:56:38 knakahara Exp $ */
 
 /**
   SPDX-License-Identifier: BSD-3-Clause
@@ -370,8 +370,8 @@ struct tx_ring {
 	u16			atr_sample;
 	u16			atr_count;
 
-	u32			bytes;  /* used for AIM */
-	u32			packets;
+	u64			bytes;  /* used for AIM */
+	u64			packets;
 	/* Soft Stats */
 	struct evcnt	   	tso_tx;
 	struct evcnt		no_desc_avail;
@@ -413,8 +413,8 @@ struct rx_ring {
 	struct ixgbe_rx_buf	*rx_buffers;
 	ixgbe_dma_tag_t		*ptag;
 
-	u32			bytes; /* Used for AIM calc */
-	u32			packets;
+	u64			bytes; /* Used for AIM calc */
+	u64			packets;
 
 	/* Soft stats */
 	struct evcnt		rx_copies;



CVS commit: src/sys/arch/x86/x86

2018-03-25 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Mar 26 02:30:08 UTC 2018

Modified Files:
src/sys/arch/x86/x86: intr.c

Log Message:
Fix "intrctl list" causes panic while attaching MSI/MSI-X devices.

When there are devices which is already pci_intr_alloc'ed, however is not
established yet, "intrctl list" causes panic. E.g.
# while true; do intrctl list > /dev/null ; done&
# drvctl -d ixg0 && drvctl -r pci0

And add some KASSERTMSG to similar but not the same code.

Pointed out by msaitoh@n.o.

XXX pullup-8


To generate a diff of this commit:
cvs rdiff -u -r1.123 -r1.124 src/sys/arch/x86/x86/intr.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/arch/x86/x86/intr.c
diff -u src/sys/arch/x86/x86/intr.c:1.123 src/sys/arch/x86/x86/intr.c:1.124
--- src/sys/arch/x86/x86/intr.c:1.123	Sat Feb 17 18:51:53 2018
+++ src/sys/arch/x86/x86/intr.c	Mon Mar 26 02:30:08 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.c,v 1.123 2018/02/17 18:51:53 maxv Exp $	*/
+/*	$NetBSD: intr.c,v 1.124 2018/03/26 02:30:08 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -133,7 +133,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.123 2018/02/17 18:51:53 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.124 2018/03/26 02:30:08 knakahara Exp $");
 
 #include "opt_intrdebug.h"
 #include "opt_multiprocessor.h"
@@ -2012,6 +2012,9 @@ intr_get_affinity(struct intrsource *isp
 		return;
 	}
 
+	KASSERTMSG(isp->is_handlers != NULL,
+	"Don't get affinity for the device which is not established.");
+
 	ci = isp->is_handlers->ih_cpu;
 	if (ci == NULL) {
 		kcpuset_zero(cpuset);
@@ -2064,6 +2067,9 @@ intr_set_affinity(struct intrsource *isp
 	}
 
 	ih = isp->is_handlers;
+	KASSERTMSG(ih != NULL,
+	"Don't set affinity for the device which is not established.");
+
 	oldci = ih->ih_cpu;
 	if (newci == oldci) /* nothing to do */
 		return 0;
@@ -2130,6 +2136,13 @@ intr_is_affinity_intrsource(struct intrs
 
 	KASSERT(mutex_owned(&cpu_lock));
 
+	/*
+	 * The device is already pci_intr_alloc'ed, however it is not
+	 * established yet.
+	 */
+	if (isp->is_handlers == NULL)
+		return false;
+
 	ci = isp->is_handlers->ih_cpu;
 	KASSERT(ci != NULL);
 



CVS commit: src/sys/dev/pci/ixgbe

2018-03-20 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Tue Mar 20 09:50:33 UTC 2018

Modified Files:
src/sys/dev/pci/ixgbe: ixv.c

Log Message:
Fix race about writing adapter->link_active for ixv(4).

adapter->link_active is updated by ixv_update_link_status() only.
The function is called from the following two functions.
- ixv_media_status()
- ixv_handle_link()

ixv_media_status() calls ixv_update_link_status() with holding
IXGBE_CORE_LOCK, however ixv_handle_link() calls it without
holding IXGBE_CORE_LOCK, the same as ixg(4).

ok by msaitoh@n.o.


To generate a diff of this commit:
cvs rdiff -u -r1.88 -r1.89 src/sys/dev/pci/ixgbe/ixv.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/dev/pci/ixgbe/ixv.c
diff -u src/sys/dev/pci/ixgbe/ixv.c:1.88 src/sys/dev/pci/ixgbe/ixv.c:1.89
--- src/sys/dev/pci/ixgbe/ixv.c:1.88	Thu Mar 15 06:48:51 2018
+++ src/sys/dev/pci/ixgbe/ixv.c	Tue Mar 20 09:50:33 2018
@@ -1,4 +1,4 @@
-/*$NetBSD: ixv.c,v 1.88 2018/03/15 06:48:51 msaitoh Exp $*/
+/*$NetBSD: ixv.c,v 1.89 2018/03/20 09:50:33 knakahara Exp $*/
 
 /**
 
@@ -1293,6 +1293,8 @@ ixv_update_link_status(struct adapter *a
 	struct ifnet *ifp = adapter->ifp;
 	device_t dev = adapter->dev;
 
+	KASSERT(mutex_owned(&adapter->core_mtx));
+
 	if (adapter->link_up) {
 		if (adapter->link_active == FALSE) {
 			if (bootverbose) {
@@ -3080,9 +3082,13 @@ ixv_handle_link(void *context)
 {
 	struct adapter *adapter = context;
 
+	IXGBE_CORE_LOCK(adapter);
+
 	adapter->hw.mac.ops.check_link(&adapter->hw, &adapter->link_speed,
 	&adapter->link_up, FALSE);
 	ixv_update_link_status(adapter);
+
+	IXGBE_CORE_UNLOCK(adapter);
 } /* ixv_handle_link */
 
 /
@@ -3091,6 +3097,9 @@ ixv_handle_link(void *context)
 static void
 ixv_check_link(struct adapter *adapter)
 {
+
+	KASSERT(mutex_owned(&adapter->core_mtx));
+
 	adapter->hw.mac.get_link_status = TRUE;
 
 	adapter->hw.mac.ops.check_link(&adapter->hw, &adapter->link_speed,



CVS commit: src/sys/dev/pci/ixgbe

2018-03-20 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Tue Mar 20 09:46:25 UTC 2018

Modified Files:
src/sys/dev/pci/ixgbe: ixgbe.c

Log Message:
Fix race about writing adapter->link_active for ixg(4).

adapter->link_active is updated by ixgbe_update_link_status() only.
The function is called from the following four functions.
- ixgbe_media_status()
- ixgbe_local_timer1()
- ixgbe_stop()
- ixgbe_handle_link()

The functions other than ixgbe_handle_link() call ixgbe_update_link_status()
with holding IXGBE_CORE_LOCK, however ixgbe_handle_link() calls it without
holding IXGBE_CORE_LOCK. That can cause race. So, add IXGBE_CORE_LOCK to
ixgbe_handle_link().

Tested by msaitoh@n.o and me.


To generate a diff of this commit:
cvs rdiff -u -r1.135 -r1.136 src/sys/dev/pci/ixgbe/ixgbe.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/dev/pci/ixgbe/ixgbe.c
diff -u src/sys/dev/pci/ixgbe/ixgbe.c:1.135 src/sys/dev/pci/ixgbe/ixgbe.c:1.136
--- src/sys/dev/pci/ixgbe/ixgbe.c:1.135	Thu Mar 15 06:48:51 2018
+++ src/sys/dev/pci/ixgbe/ixgbe.c	Tue Mar 20 09:46:25 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe.c,v 1.135 2018/03/15 06:48:51 msaitoh Exp $ */
+/* $NetBSD: ixgbe.c,v 1.136 2018/03/20 09:46:25 knakahara Exp $ */
 
 /**
 
@@ -4486,6 +4486,8 @@ ixgbe_update_link_status(struct adapter 
 	device_tdev = adapter->dev;
 	struct ixgbe_hw *hw = &adapter->hw;
 
+	KASSERT(mutex_owned(&adapter->core_mtx));
+
 	if (adapter->link_up) {
 		if (adapter->link_active == FALSE) {
 			if (adapter->link_speed == IXGBE_LINK_SPEED_10GB_FULL){
@@ -6338,11 +6340,15 @@ ixgbe_handle_link(void *context)
 	struct adapter  *adapter = context;
 	struct ixgbe_hw *hw = &adapter->hw;
 
+	IXGBE_CORE_LOCK(adapter);
+
 	ixgbe_check_link(hw, &adapter->link_speed, &adapter->link_up, 0);
 	ixgbe_update_link_status(adapter);
 
 	/* Re-enable link interrupts */
 	IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_LSC);
+
+	IXGBE_CORE_UNLOCK(adapter);
 } /* ixgbe_handle_link */
 
 /



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, &psref);
+	if (var->gv_psrc == NULL || var->gv_pdst == NULL) {
+		gif_putref_variant(var, &psref);
+		return NULL;
+	}
 	if (var->gv_psrc->sa_family != AF_INET6) {
 		gif_putref_variant(var, &psref);
 		return NULL;



CVS commit: src/tests/net/if_ipsec

2018-03-12 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Tue Mar 13 03:50:26 UTC 2018

Modified Files:
src/tests/net/if_ipsec: t_ipsec.sh

Log Message:
Enhance assertion ipsecif(4) ATF to avoid confusing setkey(8) error message.

When setkey(8) says "syntax error at [-E]", it must mean get_if_ipsec_unique()
failed.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/net/if_ipsec/t_ipsec.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/net/if_ipsec/t_ipsec.sh
diff -u src/tests/net/if_ipsec/t_ipsec.sh:1.3 src/tests/net/if_ipsec/t_ipsec.sh:1.4
--- src/tests/net/if_ipsec/t_ipsec.sh:1.3	Thu Feb  1 05:22:01 2018
+++ src/tests/net/if_ipsec/t_ipsec.sh	Tue Mar 13 03:50:26 2018
@@ -1,4 +1,4 @@
-#	$NetBSD: t_ipsec.sh,v 1.3 2018/02/01 05:22:01 ozaki-r Exp $
+#	$NetBSD: t_ipsec.sh,v 1.4 2018/03/13 03:50:26 knakahara Exp $
 #
 # Copyright (c) 2017 Internet Initiative Japan Inc.
 # All rights reserved.
@@ -269,7 +269,9 @@ setup_if_ipsec_sa()
 	local algo_args="$(generate_algo_args $proto $algo)"
 
 	inunique=`get_if_ipsec_unique ${sock} ${dst} ${mode}`
+	atf_check -s exit:0 test "X$inunique" != "X"
 	outunique=`get_if_ipsec_unique ${sock} ${src} ${mode}`
+	atf_check -s exit:0 test "X$outunique" != "X"
 
 	if [ ${dir} = "1to2" ] ; then
 	if [ ${mode} = "ipv6" ] ; then
@@ -446,7 +448,9 @@ setup_dummy_if_ipsec_sa()
 	local algo_args="$(generate_algo_args $proto $algo)"
 
 	inunique=`get_if_ipsec_unique ${sock} ${dst} ${mode}`
+	atf_check -s exit:0 test "X$inunique" != "X"
 	outunique=`get_if_ipsec_unique ${sock} ${src} ${mode}`
+	atf_check -s exit:0 test "X$outunique" != "X"
 
 	if [ ${dir} = "1to2" ] ; then
 	inid="2"



CVS commit: src/sys/netipsec

2018-03-12 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Tue Mar 13 03:05:13 UTC 2018

Modified Files:
src/sys/netipsec: ipsecif.c

Log Message:
comment out confusing (and incorrect) code and add comment. Pointed out by 
maxv@n.o, thanks.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/netipsec/ipsecif.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/netipsec/ipsecif.c
diff -u src/sys/netipsec/ipsecif.c:1.4 src/sys/netipsec/ipsecif.c:1.5
--- src/sys/netipsec/ipsecif.c:1.4	Fri Mar  9 11:05:21 2018
+++ src/sys/netipsec/ipsecif.c	Tue Mar 13 03:05:12 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ipsecif.c,v 1.4 2018/03/09 11:05:21 knakahara Exp $  */
+/*	$NetBSD: ipsecif.c,v 1.5 2018/03/13 03:05:12 knakahara Exp $  */
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ipsecif.c,v 1.4 2018/03/09 11:05:21 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ipsecif.c,v 1.5 2018/03/13 03:05:12 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -483,7 +483,9 @@ ipsecif6_output(struct ipsec_variant *va
 	ip6->ip6_flow	= 0;
 	ip6->ip6_vfc	&= ~IPV6_VERSION_MASK;
 	ip6->ip6_vfc	|= IPV6_VERSION;
-	ip6->ip6_plen	= htons((u_short)m->m_pkthdr.len);
+#if 0	/* ip6->ip6_plen will be filled by ip6_output */
+	ip6->ip6_plen	= htons((u_short)m->m_pkthdr.len - sizeof(*ip6));
+#endif
 	ip6->ip6_nxt	= proto;
 	ip6->ip6_hlim	= ip6_ipsec_hlim;
 	ip6->ip6_src	= sin6_src->sin6_addr;



CVS commit: src/sys/net

2018-03-12 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Tue Mar 13 02:12:05 UTC 2018

Modified Files:
src/sys/net: if_ipsec.c

Log Message:
Fix IPv6 ipsecif(4) ATF regression, sorry.

There must *not* be padding between the src sockaddr and the dst sockaddr
after struct sadb_x_policy.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/net/if_ipsec.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/net/if_ipsec.c
diff -u src/sys/net/if_ipsec.c:1.6 src/sys/net/if_ipsec.c:1.7
--- src/sys/net/if_ipsec.c:1.6	Fri Mar  9 11:03:26 2018
+++ src/sys/net/if_ipsec.c	Tue Mar 13 02:12:05 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ipsec.c,v 1.6 2018/03/09 11:03:26 knakahara Exp $  */
+/*	$NetBSD: if_ipsec.c,v 1.7 2018/03/13 02:12:05 knakahara Exp $  */
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_ipsec.c,v 1.6 2018/03/09 11:03:26 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ipsec.c,v 1.7 2018/03/13 02:12:05 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1310,27 +1310,37 @@ if_ipsec_unshare_sp(struct ipsec_variant
 }
 
 static inline void
-if_ipsec_add_mbuf(struct mbuf *m0, void *data, size_t len)
+if_ipsec_add_mbuf_optalign(struct mbuf *m0, void *data, size_t len, bool align)
 {
 	struct mbuf *m;
 
 	MGET(m, M_WAITOK | M_ZERO, MT_DATA);
-	m->m_len = PFKEY_ALIGN8(len);
+	if (align)
+		m->m_len = PFKEY_ALIGN8(len);
+	else
+		m->m_len = len;
 	m_copyback(m, 0, len, data);
 	m_cat(m0, m);
 }
 
 static inline void
-if_ipsec_add_mbuf_addr_port(struct mbuf *m0, struct sockaddr *addr, in_port_t port)
+if_ipsec_add_mbuf(struct mbuf *m0, void *data, size_t len)
+{
+
+	if_ipsec_add_mbuf_optalign(m0, data, len, true);
+}
+
+static inline void
+if_ipsec_add_mbuf_addr_port(struct mbuf *m0, struct sockaddr *addr, in_port_t port, bool align)
 {
 
 	if (port == 0) {
-		if_ipsec_add_mbuf(m0, addr, addr->sa_len);
+		if_ipsec_add_mbuf_optalign(m0, addr, addr->sa_len, align);
 	} else {
 		struct sockaddr addrport;
 
 		if_ipsec_set_addr_port(&addrport, addr, port);
-		if_ipsec_add_mbuf(m0, &addrport, addrport.sa_len);
+		if_ipsec_add_mbuf_optalign(m0, &addrport, addrport.sa_len, align);
 	}
 }
 
@@ -1412,10 +1422,8 @@ if_ipsec_set_sadb_x_policy(struct sadb_x
 	size = sizeof(*xpl);
 	if (policy == IPSEC_POLICY_IPSEC) {
 		size += PFKEY_ALIGN8(sizeof(*xisr));
-		if (src != NULL)
-			size += PFKEY_ALIGN8(src->sa_len);
-		if (dst != NULL)
-			size += PFKEY_ALIGN8(dst->sa_len);
+		if (src != NULL && dst != NULL)
+			size += PFKEY_ALIGN8(src->sa_len + dst->sa_len);
 	}
 	xpl->sadb_x_policy_len = PFKEY_UNIT64(size);
 	xpl->sadb_x_policy_exttype = SADB_X_EXT_POLICY;
@@ -1427,10 +1435,9 @@ if_ipsec_set_sadb_x_policy(struct sadb_x
 
 	if (policy == IPSEC_POLICY_IPSEC) {
 		xisr->sadb_x_ipsecrequest_len = PFKEY_ALIGN8(sizeof(*xisr));
-		if (src != NULL)
-			xisr->sadb_x_ipsecrequest_len += PFKEY_ALIGN8(src->sa_len);
-		if (dst != NULL)
-			xisr->sadb_x_ipsecrequest_len += PFKEY_ALIGN8(dst->sa_len);
+		if (src != NULL && dst != NULL)
+			xisr->sadb_x_ipsecrequest_len +=
+PFKEY_ALIGN8(src->sa_len + dst->sa_len);
 		xisr->sadb_x_ipsecrequest_proto = IPPROTO_ESP;
 		xisr->sadb_x_ipsecrequest_mode = IPSEC_MODE_TRANSPORT;
 		xisr->sadb_x_ipsecrequest_level = level;
@@ -1539,13 +1546,13 @@ if_ipsec_add_sp0(struct sockaddr *src, i
 	m_copyback(m, 0, sizeof(msg), &msg);
 
 	if_ipsec_add_mbuf(m, &xsrc, sizeof(xsrc));
-	if_ipsec_add_mbuf_addr_port(m, src, sport);
+	if_ipsec_add_mbuf_addr_port(m, src, sport, true);
 	padlen = PFKEY_UNUNIT64(xsrc.sadb_address_len)
 		- (sizeof(xsrc) + PFKEY_ALIGN8(src->sa_len));
 	if_ipsec_add_pad(m, padlen);
 
 	if_ipsec_add_mbuf(m, &xdst, sizeof(xdst));
-	if_ipsec_add_mbuf_addr_port(m, dst, dport);
+	if_ipsec_add_mbuf_addr_port(m, dst, dport, true);
 	padlen = PFKEY_UNUNIT64(xdst.sadb_address_len)
 		- (sizeof(xdst) + PFKEY_ALIGN8(dst->sa_len));
 	if_ipsec_add_pad(m, padlen);
@@ -1553,14 +1560,12 @@ if_ipsec_add_sp0(struct sockaddr *src, i
 	if_ipsec_add_mbuf(m, &xpl, sizeof(xpl));
 	if (policy == IPSEC_POLICY_IPSEC) {
 		if_ipsec_add_mbuf(m, &xisr, sizeof(xisr));
-		if_ipsec_add_mbuf_addr_port(m, src, sport);
-		if_ipsec_add_mbuf_addr_port(m, dst, dport);
+		if_ipsec_add_mbuf_addr_port(m, src, sport, false);
+		if_ipsec_add_mbuf_addr_port(m, dst, dport, false);
 	}
 	padlen = PFKEY_UNUNIT64(xpl.sadb_x_policy_len) - sizeof(xpl);
-	if (src != NULL)
-		padlen -= PFKEY_ALIGN8(src->sa_len);
-	if (dst != NULL)
-		padlen -= PFKEY_ALIGN8(dst->sa_len);
+	if (src != NULL && dst != NULL)
+		padlen -= PFKEY_ALIGN8(src->sa_len + dst->sa_len);
 	if_ipsec_add_pad(m, padlen);
 
 	/* key_kpi_spdadd() has already done KEY_SP_REF(). */



CVS commit: src/sys/netipsec

2018-03-09 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Mar  9 11:05:21 UTC 2018

Modified Files:
src/sys/netipsec: ipsecif.c

Log Message:
Fix ipsec(4) I/F esp_frag support.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/netipsec/ipsecif.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/netipsec/ipsecif.c
diff -u src/sys/netipsec/ipsecif.c:1.3 src/sys/netipsec/ipsecif.c:1.4
--- src/sys/netipsec/ipsecif.c:1.3	Tue Mar  6 10:07:06 2018
+++ src/sys/netipsec/ipsecif.c	Fri Mar  9 11:05:21 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ipsecif.c,v 1.3 2018/03/06 10:07:06 knakahara Exp $  */
+/*	$NetBSD: ipsecif.c,v 1.4 2018/03/09 11:05:21 knakahara Exp $  */
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ipsecif.c,v 1.3 2018/03/06 10:07:06 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ipsecif.c,v 1.4 2018/03/09 11:05:21 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -259,7 +259,13 @@ ipsecif4_fragout(struct ipsec_variant *v
 	if (mtag)
 		m_tag_delete(m, mtag);
 
-	error = ip_fragment(m, ifp, mtu);
+	/* consider new IP header prepended in ipsecif4_output() */
+	if (mtu <= sizeof(struct ip)) {
+		m_freem(m);
+		return ENETUNREACH;
+	}
+	m->m_pkthdr.csum_flags |= M_CSUM_IPv4;
+	error = ip_fragment(m, ifp, mtu - sizeof(struct ip));
 	if (error)
 		return error;
 
@@ -396,7 +402,7 @@ ipsecif4_output(struct ipsec_variant *va
 	 * frangmentation is already done in ipsecif4_fragout(),
 	 * so ipsec4_process_packet() must not do fragmentation here.
 	 */
-	KASSERT(error != 0 || sa_mtu == 0);
+	KASSERT(sa_mtu == 0);
 
 done:
 	return error;



CVS commit: src/sys/net

2018-03-09 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Mar  9 11:03:26 UTC 2018

Modified Files:
src/sys/net: if_ipsec.c

Log Message:
Functionalize duplicated code. No functional changes.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/net/if_ipsec.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/net/if_ipsec.c
diff -u src/sys/net/if_ipsec.c:1.5 src/sys/net/if_ipsec.c:1.6
--- src/sys/net/if_ipsec.c:1.5	Fri Mar  9 11:01:41 2018
+++ src/sys/net/if_ipsec.c	Fri Mar  9 11:03:26 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ipsec.c,v 1.5 2018/03/09 11:01:41 knakahara Exp $  */
+/*	$NetBSD: if_ipsec.c,v 1.6 2018/03/09 11:03:26 knakahara Exp $  */
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_ipsec.c,v 1.5 2018/03/09 11:01:41 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ipsec.c,v 1.6 2018/03/09 11:03:26 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1321,6 +1321,20 @@ if_ipsec_add_mbuf(struct mbuf *m0, void 
 }
 
 static inline void
+if_ipsec_add_mbuf_addr_port(struct mbuf *m0, struct sockaddr *addr, in_port_t port)
+{
+
+	if (port == 0) {
+		if_ipsec_add_mbuf(m0, addr, addr->sa_len);
+	} else {
+		struct sockaddr addrport;
+
+		if_ipsec_set_addr_port(&addrport, addr, port);
+		if_ipsec_add_mbuf(m0, &addrport, addrport.sa_len);
+	}
+}
+
+static inline void
 if_ipsec_add_pad(struct mbuf *m0, size_t len)
 {
 	struct mbuf *m;
@@ -1525,27 +1539,13 @@ if_ipsec_add_sp0(struct sockaddr *src, i
 	m_copyback(m, 0, sizeof(msg), &msg);
 
 	if_ipsec_add_mbuf(m, &xsrc, sizeof(xsrc));
-	if (sport == 0) {
-		if_ipsec_add_mbuf(m, src, src->sa_len);
-	} else {
-		struct sockaddr addrport;
-
-		if_ipsec_set_addr_port(&addrport, src, sport);
-		if_ipsec_add_mbuf(m, &addrport, addrport.sa_len);
-	}
+	if_ipsec_add_mbuf_addr_port(m, src, sport);
 	padlen = PFKEY_UNUNIT64(xsrc.sadb_address_len)
 		- (sizeof(xsrc) + PFKEY_ALIGN8(src->sa_len));
 	if_ipsec_add_pad(m, padlen);
 
 	if_ipsec_add_mbuf(m, &xdst, sizeof(xdst));
-	if (dport == 0) {
-		if_ipsec_add_mbuf(m, dst, dst->sa_len);
-	} else {
-		struct sockaddr addrport;
-
-		if_ipsec_set_addr_port(&addrport, dst, dport);
-		if_ipsec_add_mbuf(m, &addrport, addrport.sa_len);
-	}
+	if_ipsec_add_mbuf_addr_port(m, dst, dport);
 	padlen = PFKEY_UNUNIT64(xdst.sadb_address_len)
 		- (sizeof(xdst) + PFKEY_ALIGN8(dst->sa_len));
 	if_ipsec_add_pad(m, padlen);
@@ -1553,21 +1553,8 @@ if_ipsec_add_sp0(struct sockaddr *src, i
 	if_ipsec_add_mbuf(m, &xpl, sizeof(xpl));
 	if (policy == IPSEC_POLICY_IPSEC) {
 		if_ipsec_add_mbuf(m, &xisr, sizeof(xisr));
-		if (sport == 0) {
-			if_ipsec_add_mbuf(m, src, src->sa_len);
-		} else {
-			struct sockaddr addrport;
-
-			if_ipsec_set_addr_port(&addrport, src, sport);
-			if_ipsec_add_mbuf(m, &addrport, addrport.sa_len);
-		}
-		if (dport == 0) {
-			if_ipsec_add_mbuf(m, dst, dst->sa_len);
-		} else {
-			struct sockaddr addrport;
-			if_ipsec_set_addr_port(&addrport, dst, dport);
-			if_ipsec_add_mbuf(m, &addrport, addrport.sa_len);
-		}
+		if_ipsec_add_mbuf_addr_port(m, src, sport);
+		if_ipsec_add_mbuf_addr_port(m, dst, dport);
 	}
 	padlen = PFKEY_UNUNIT64(xpl.sadb_x_policy_len) - sizeof(xpl);
 	if (src != NULL)



CVS commit: src/sys/net

2018-03-09 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Mar  9 11:01:41 UTC 2018

Modified Files:
src/sys/net: if_ipsec.c

Log Message:
Fix missing sadb_x_ipsecrequest informations for PF_KEY message.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/net/if_ipsec.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/net/if_ipsec.c
diff -u src/sys/net/if_ipsec.c:1.4 src/sys/net/if_ipsec.c:1.5
--- src/sys/net/if_ipsec.c:1.4	Fri Mar  9 10:59:36 2018
+++ src/sys/net/if_ipsec.c	Fri Mar  9 11:01:41 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ipsec.c,v 1.4 2018/03/09 10:59:36 knakahara Exp $  */
+/*	$NetBSD: if_ipsec.c,v 1.5 2018/03/09 11:01:41 knakahara Exp $  */
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_ipsec.c,v 1.4 2018/03/09 10:59:36 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ipsec.c,v 1.5 2018/03/09 11:01:41 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -109,7 +109,8 @@ static inline size_t if_ipsec_set_sadb_s
 static inline size_t if_ipsec_set_sadb_dst(struct sadb_address *,
 struct sockaddr *, int);
 static inline size_t if_ipsec_set_sadb_x_policy(struct sadb_x_policy *,
-struct sadb_x_ipsecrequest *, uint16_t, uint8_t, uint32_t, uint8_t);
+struct sadb_x_ipsecrequest *, uint16_t, uint8_t, uint32_t, uint8_t,
+struct sockaddr *, struct sockaddr *);
 static inline void if_ipsec_set_sadb_msg(struct sadb_msg *, uint16_t, uint8_t);
 static inline void if_ipsec_set_sadb_msg_add(struct sadb_msg *, uint16_t);
 static inline void if_ipsec_set_sadb_msg_del(struct sadb_msg *, uint16_t);
@@ -1388,7 +1389,7 @@ if_ipsec_set_sadb_dst(struct sadb_addres
 static inline size_t
 if_ipsec_set_sadb_x_policy(struct sadb_x_policy *xpl,
 struct sadb_x_ipsecrequest *xisr, uint16_t policy, uint8_t dir, uint32_t id,
-uint8_t level)
+uint8_t level, struct sockaddr *src, struct sockaddr *dst)
 {
 	size_t size;
 
@@ -1397,6 +1398,10 @@ if_ipsec_set_sadb_x_policy(struct sadb_x
 	size = sizeof(*xpl);
 	if (policy == IPSEC_POLICY_IPSEC) {
 		size += PFKEY_ALIGN8(sizeof(*xisr));
+		if (src != NULL)
+			size += PFKEY_ALIGN8(src->sa_len);
+		if (dst != NULL)
+			size += PFKEY_ALIGN8(dst->sa_len);
 	}
 	xpl->sadb_x_policy_len = PFKEY_UNIT64(size);
 	xpl->sadb_x_policy_exttype = SADB_X_EXT_POLICY;
@@ -1408,6 +1413,10 @@ if_ipsec_set_sadb_x_policy(struct sadb_x
 
 	if (policy == IPSEC_POLICY_IPSEC) {
 		xisr->sadb_x_ipsecrequest_len = PFKEY_ALIGN8(sizeof(*xisr));
+		if (src != NULL)
+			xisr->sadb_x_ipsecrequest_len += PFKEY_ALIGN8(src->sa_len);
+		if (dst != NULL)
+			xisr->sadb_x_ipsecrequest_len += PFKEY_ALIGN8(dst->sa_len);
 		xisr->sadb_x_ipsecrequest_proto = IPPROTO_ESP;
 		xisr->sadb_x_ipsecrequest_mode = IPSEC_MODE_TRANSPORT;
 		xisr->sadb_x_ipsecrequest_level = level;
@@ -1506,7 +1515,7 @@ if_ipsec_add_sp0(struct sockaddr *src, i
 	ext_msg_len += PFKEY_UNIT64(size);
 	size = if_ipsec_set_sadb_dst(&xdst, dst, proto);
 	ext_msg_len += PFKEY_UNIT64(size);
-	size = if_ipsec_set_sadb_x_policy(&xpl, &xisr, policy, dir, 0, level);
+	size = if_ipsec_set_sadb_x_policy(&xpl, &xisr, policy, dir, 0, level, src, dst);
 	ext_msg_len += PFKEY_UNIT64(size);
 	if_ipsec_set_sadb_msg_add(&msg, ext_msg_len);
 
@@ -1542,8 +1551,30 @@ if_ipsec_add_sp0(struct sockaddr *src, i
 	if_ipsec_add_pad(m, padlen);
 
 	if_ipsec_add_mbuf(m, &xpl, sizeof(xpl));
-	if (policy == IPSEC_POLICY_IPSEC)
+	if (policy == IPSEC_POLICY_IPSEC) {
 		if_ipsec_add_mbuf(m, &xisr, sizeof(xisr));
+		if (sport == 0) {
+			if_ipsec_add_mbuf(m, src, src->sa_len);
+		} else {
+			struct sockaddr addrport;
+
+			if_ipsec_set_addr_port(&addrport, src, sport);
+			if_ipsec_add_mbuf(m, &addrport, addrport.sa_len);
+		}
+		if (dport == 0) {
+			if_ipsec_add_mbuf(m, dst, dst->sa_len);
+		} else {
+			struct sockaddr addrport;
+			if_ipsec_set_addr_port(&addrport, dst, dport);
+			if_ipsec_add_mbuf(m, &addrport, addrport.sa_len);
+		}
+	}
+	padlen = PFKEY_UNUNIT64(xpl.sadb_x_policy_len) - sizeof(xpl);
+	if (src != NULL)
+		padlen -= PFKEY_ALIGN8(src->sa_len);
+	if (dst != NULL)
+		padlen -= PFKEY_ALIGN8(dst->sa_len);
+	if_ipsec_add_pad(m, padlen);
 
 	/* key_kpi_spdadd() has already done KEY_SP_REF(). */
 	return key_kpi_spdadd(m);
@@ -1636,7 +1667,7 @@ if_ipsec_del_sp0(struct secpolicy *sp)
 
 	MGETHDR(m, M_WAITOK, MT_DATA);
 
-	size = if_ipsec_set_sadb_x_policy(&xpl, NULL, 0, 0, sp->id, 0);
+	size = if_ipsec_set_sadb_x_policy(&xpl, NULL, 0, 0, sp->id, 0, NULL, NULL);
 	ext_msg_len += PFKEY_UNIT64(size);
 
 	if_ipsec_set_sadb_msg_del(&msg, ext_msg_len);



CVS commit: src/sys/net

2018-03-09 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Mar  9 10:59:36 UTC 2018

Modified Files:
src/sys/net: if_ipsec.c

Log Message:
NAT-T src and dst port in ipsec_variant should be network byte order.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/net/if_ipsec.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/net/if_ipsec.c
diff -u src/sys/net/if_ipsec.c:1.3 src/sys/net/if_ipsec.c:1.4
--- src/sys/net/if_ipsec.c:1.3	Wed Jan 31 07:33:18 2018
+++ src/sys/net/if_ipsec.c	Fri Mar  9 10:59:36 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ipsec.c,v 1.3 2018/01/31 07:33:18 mrg Exp $  */
+/*	$NetBSD: if_ipsec.c,v 1.4 2018/03/09 10:59:36 knakahara Exp $  */
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_ipsec.c,v 1.3 2018/01/31 07:33:18 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ipsec.c,v 1.4 2018/03/09 10:59:36 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -892,7 +892,7 @@ if_ipsec_set_tunnel(struct ifnet *ifp,
 	switch(nsrc->sa_family) {
 #ifdef INET
 	case AF_INET:
-		nsport = ntohs(satosin(src)->sin_port);
+		nsport = satosin(src)->sin_port;
 		/*
 		 * avoid confuse SP when NAT-T disabled,
 		 * e.g.
@@ -900,15 +900,15 @@ if_ipsec_set_tunnel(struct ifnet *ifp,
 		 * confuse : 10.0.1.2[600] 10.0.1.1[600] 4(ipv4)
 		 */
 		satosin(nsrc)->sin_port = 0;
-		ndport = ntohs(satosin(dst)->sin_port);
+		ndport = satosin(dst)->sin_port;
 		satosin(ndst)->sin_port = 0;
 		break;
 #endif /* INET */
 #ifdef INET6
 	case AF_INET6:
-		nsport = ntohs(satosin6(src)->sin6_port);
+		nsport = satosin6(src)->sin6_port;
 		satosin6(nsrc)->sin6_port = 0;
-		ndport = ntohs(satosin6(dst)->sin6_port);
+		ndport = satosin6(dst)->sin6_port;
 		satosin6(ndst)->sin6_port = 0;
 		break;
 #endif /* INET6 */
@@ -1459,14 +1459,14 @@ if_ipsec_set_addr_port(struct sockaddr *
 #ifdef INET
 	case AF_INET: {
 		struct sockaddr_in *sin = satosin(addrport);
-		sin->sin_port = htons(port);
+		sin->sin_port = port;
 		break;
 	}
 #endif /* INET */
 #ifdef INET6
 	case AF_INET6: {
 		struct sockaddr_in6 *sin6 = satosin6(addrport);
-		sin6->sin6_port = htons(port);
+		sin6->sin6_port = port;
 		break;
 	}
 #endif /* INET6 */



CVS commit: src/sys/dev/pci/ixgbe

2018-03-07 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Mar  8 02:41:27 UTC 2018

Modified Files:
src/sys/dev/pci/ixgbe: ixgbe.c

Log Message:
Reduce duplicated code which schedule deferred packet processing. No functional 
change.


To generate a diff of this commit:
cvs rdiff -u -r1.132 -r1.133 src/sys/dev/pci/ixgbe/ixgbe.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/dev/pci/ixgbe/ixgbe.c
diff -u src/sys/dev/pci/ixgbe/ixgbe.c:1.132 src/sys/dev/pci/ixgbe/ixgbe.c:1.133
--- src/sys/dev/pci/ixgbe/ixgbe.c:1.132	Thu Mar  8 02:39:42 2018
+++ src/sys/dev/pci/ixgbe/ixgbe.c	Thu Mar  8 02:41:27 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe.c,v 1.132 2018/03/08 02:39:42 knakahara Exp $ */
+/* $NetBSD: ixgbe.c,v 1.133 2018/03/08 02:41:27 knakahara Exp $ */
 
 /**
 
@@ -2439,6 +2439,36 @@ out:
 } /* ixgbe_disable_queue */
 
 /
+ * ixgbe_sched_handle_que - schedule deferred packet processing
+ /
+static inline void
+ixgbe_sched_handle_que(struct adapter *adapter, struct ix_queue *que)
+{
+
+	if (adapter->txrx_use_workqueue) {
+		/*
+		 * adapter->que_wq is bound to each CPU instead of
+		 * each NIC queue to reduce workqueue kthread. As we
+		 * should consider about interrupt affinity in this
+		 * function, the workqueue kthread must be WQ_PERCPU.
+		 * If create WQ_PERCPU workqueue kthread for each NIC
+		 * queue, that number of created workqueue kthread is
+		 * (number of used NIC queue) * (number of CPUs) =
+		 * (number of CPUs) ^ 2 most often.
+		 *
+		 * The same NIC queue's interrupts are avoided by
+		 * masking the queue's interrupt. And different
+		 * NIC queue's interrupts use different struct work
+		 * (que->wq_cookie). So, "enqueued flag" to avoid
+		 * twice workqueue_enqueue() is not required .
+		 */
+		workqueue_enqueue(adapter->que_wq, &que->wq_cookie, curcpu());
+	} else {
+		softint_schedule(que->que_si);
+	}
+}
+
+/
  * ixgbe_msix_que - MSI-X Queue Interrupt Service routine
  /
 static int
@@ -2526,30 +2556,9 @@ ixgbe_msix_que(void *arg)
 	rxr->packets = 0;
 
 no_calc:
-	if (more) {
-		if (adapter->txrx_use_workqueue) {
-			/*
-			 * adapter->que_wq is bound to each CPU instead of
-			 * each NIC queue to reduce workqueue kthread. As we
-			 * should consider about interrupt affinity in this
-			 * function, the workqueue kthread must be WQ_PERCPU.
-			 * If create WQ_PERCPU workqueue kthread for each NIC
-			 * queue, that number of created workqueue kthread is
-			 * (number of used NIC queue) * (number of CPUs) =
-			 * (number of CPUs) ^ 2 most often.
-			 *
-			 * The same NIC queue's interrupts are avoided by
-			 * masking the queue's interrupt. And different
-			 * NIC queue's interrupts use different struct work
-			 * (que->wq_cookie). So, "enqueued flag" to avoid
-			 * twice workqueue_enqueue() is not required .
-			 */
-			workqueue_enqueue(adapter->que_wq, &que->wq_cookie,
-			curcpu());
-		} else {
-			softint_schedule(que->que_si);
-		}
-	} else
+	if (more)
+		ixgbe_sched_handle_que(adapter, que);
+	else
 		ixgbe_enable_queue(adapter, que->msix);
 
 	return 1;
@@ -4725,16 +4734,7 @@ ixgbe_legacy_irq(void *arg)
 
 	if (more) {
 		que->req.ev_count++;
-		if (adapter->txrx_use_workqueue) {
-			/*
-			 * "enqueued flag" is not required here.
-			 * See ixgbe_msix_que().
-			 */
-			workqueue_enqueue(adapter->que_wq, &que->wq_cookie,
-			curcpu());
-		} else {
-			softint_schedule(que->que_si);
-		}
+		ixgbe_sched_handle_que(adapter, que);
 	} else
 		ixgbe_enable_intr(adapter);
 
@@ -5853,16 +5853,7 @@ ixgbe_handle_que(void *context)
 
 	if (more) {
 		que->req.ev_count++;
-		if (adapter->txrx_use_workqueue) {
-			/*
-			 * "enqueued flag" is not required here.
-			 * See ixgbe_msix_que().
-			 */
-			workqueue_enqueue(adapter->que_wq, &que->wq_cookie,
-			curcpu());
-		} else {
-			softint_schedule(que->que_si);
-		}
+		ixgbe_sched_handle_que(adapter, que);
 	} else if (que->res != NULL) {
 		/* Re-enable this interrupt */
 		ixgbe_enable_queue(adapter, que->msix);



CVS commit: src/sys/dev/pci/ixgbe

2018-03-07 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Mar  8 02:39:42 UTC 2018

Modified Files:
src/sys/dev/pci/ixgbe: ixgbe.c

Log Message:
Fix INTx/MSI handler did not schedule workqueue. Pointed out by msaitoh@n.o.


To generate a diff of this commit:
cvs rdiff -u -r1.131 -r1.132 src/sys/dev/pci/ixgbe/ixgbe.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/dev/pci/ixgbe/ixgbe.c
diff -u src/sys/dev/pci/ixgbe/ixgbe.c:1.131 src/sys/dev/pci/ixgbe/ixgbe.c:1.132
--- src/sys/dev/pci/ixgbe/ixgbe.c:1.131	Wed Mar  7 11:18:29 2018
+++ src/sys/dev/pci/ixgbe/ixgbe.c	Thu Mar  8 02:39:42 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe.c,v 1.131 2018/03/07 11:18:29 knakahara Exp $ */
+/* $NetBSD: ixgbe.c,v 1.132 2018/03/08 02:39:42 knakahara Exp $ */
 
 /**
 
@@ -4725,7 +4725,16 @@ ixgbe_legacy_irq(void *arg)
 
 	if (more) {
 		que->req.ev_count++;
-		softint_schedule(que->que_si);
+		if (adapter->txrx_use_workqueue) {
+			/*
+			 * "enqueued flag" is not required here.
+			 * See ixgbe_msix_que().
+			 */
+			workqueue_enqueue(adapter->que_wq, &que->wq_cookie,
+			curcpu());
+		} else {
+			softint_schedule(que->que_si);
+		}
 	} else
 		ixgbe_enable_intr(adapter);
 



CVS commit: src/sys/dev/pci/ixgbe

2018-03-07 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Mar  7 11:18:29 UTC 2018

Modified Files:
src/sys/dev/pci/ixgbe: ixgbe.c

Log Message:
Fix another poll mode assumption breaking. Implemented by msaitoh@n.o, I just 
commit by proxy.

ixgbe_rearm_queues() writes EICS register(s). 82599, X540 and X550
specifications say "Following a write of 1b to any bit in the EICS register
(interrupt cause set), its corresponding bit in the EIMS register is auto
set as well enabling its interrupt." in "Extended Interrupt Auto Mask Enable
(EIAM) Register" section. That is, ixgbe_rearm_queues() causes interrupts
regardless of the status managed by ixgbe_enable_queue()/ixgbe_disable_queue().
That can break poll mode assumption.

In fact, the problem occurs in the following situation
- CPU#A has high load traffic, in contrast, CPU#B has not so high load 
traffic
- CPU#A is occurred interrupt by its NIC queue
  - CPU#A calls ixgbe_disable_queue() in interrupt handler(ixgbe_msix_que())
  - CPU#A kick softint handler(ixgbe_handle_que())
- CPU#A begins softint
- CPU#A's NIC queue is set que->txr->busy flag
- With some reason, CPU#A can do ixg interrupt handler
  E.g. when one of CPU#A's softnet handlers sleeps, ipl is lowered
- CPU#B starts callout
  - CPU#B calls ixgbe_local_timer1()
- CPU#B writes EICS bit corresponding CPU#A's NIC queue bit
- CPU#A's NIC queue causes interrupt whie CPU#A is running in poll mode
  - CPU#A calls ixgbe_disable_queue() in interrupt handler *again*
- CPU#A has done polling, and then CPU#A calls ixgbe_enable_queue() *once*
- CPU#A's NIC queue interrupt is disabled until ixg is detached as
  ixgbe_disable_queue() is called twice though ixgbe_disable_queue() is
  called once only

NOTE:
82598 does not say so, but it is treated in the same way because of no harm.

By the way, we will refactor ixgbe_local_timer(watchdog processing) later.

XXX pullup-8


To generate a diff of this commit:
cvs rdiff -u -r1.130 -r1.131 src/sys/dev/pci/ixgbe/ixgbe.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/dev/pci/ixgbe/ixgbe.c
diff -u src/sys/dev/pci/ixgbe/ixgbe.c:1.130 src/sys/dev/pci/ixgbe/ixgbe.c:1.131
--- src/sys/dev/pci/ixgbe/ixgbe.c:1.130	Wed Mar  7 08:01:32 2018
+++ src/sys/dev/pci/ixgbe/ixgbe.c	Wed Mar  7 11:18:29 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe.c,v 1.130 2018/03/07 08:01:32 msaitoh Exp $ */
+/* $NetBSD: ixgbe.c,v 1.131 2018/03/07 11:18:29 knakahara Exp $ */
 
 /**
 
@@ -4229,7 +4229,14 @@ ixgbe_local_timer1(void *arg)
 	if (hung == adapter->num_queues)
 		goto watchdog;
 	else if (queues != 0) { /* Force an IRQ on queues with work */
-		ixgbe_rearm_queues(adapter, queues);
+		que = adapter->queues;
+		for (int i = 0; i < adapter->num_queues; i++, que++) {
+			mutex_enter(&que->im_mtx);
+			if (que->im_nest == 0)
+ixgbe_rearm_queues(adapter,
+queues & ((u64)1 << i));
+			mutex_exit(&que->im_mtx);
+		}
 	}
 
 out:



CVS commit: src/sys/netipsec

2018-03-06 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Tue Mar  6 10:07:06 UTC 2018

Modified Files:
src/sys/netipsec: ipsecif.c

Log Message:
Fix fragment processing in ipsec4_fragout(). Pointed out by maxv@n.o, thanks.

XXX need pullup-8


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/netipsec/ipsecif.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/netipsec/ipsecif.c
diff -u src/sys/netipsec/ipsecif.c:1.2 src/sys/netipsec/ipsecif.c:1.3
--- src/sys/netipsec/ipsecif.c:1.2	Mon Feb 26 06:17:01 2018
+++ src/sys/netipsec/ipsecif.c	Tue Mar  6 10:07:06 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ipsecif.c,v 1.2 2018/02/26 06:17:01 maxv Exp $  */
+/*	$NetBSD: ipsecif.c,v 1.3 2018/03/06 10:07:06 knakahara Exp $  */
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ipsecif.c,v 1.2 2018/02/26 06:17:01 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ipsecif.c,v 1.3 2018/03/06 10:07:06 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -265,7 +265,7 @@ ipsecif4_fragout(struct ipsec_variant *v
 
 	for (error = 0; m; m = next) {
 		next = m->m_nextpkt;
-		m->m_next = NULL;
+		m->m_nextpkt = NULL;
 		if (error) {
 			m_freem(m);
 			continue;



CVS commit: src/sys/dev/pci/ixgbe

2018-03-02 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Mar  2 10:21:01 UTC 2018

Modified Files:
src/sys/dev/pci/ixgbe: ixv.c

Log Message:
ixv(4) also supports workqueue poll mode, but not enabled by default yet, 
either.

ok by msaitoh@n.o.


To generate a diff of this commit:
cvs rdiff -u -r1.83 -r1.84 src/sys/dev/pci/ixgbe/ixv.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/dev/pci/ixgbe/ixv.c
diff -u src/sys/dev/pci/ixgbe/ixv.c:1.83 src/sys/dev/pci/ixgbe/ixv.c:1.84
--- src/sys/dev/pci/ixgbe/ixv.c:1.83	Tue Feb 27 04:58:27 2018
+++ src/sys/dev/pci/ixgbe/ixv.c	Fri Mar  2 10:21:01 2018
@@ -1,4 +1,4 @@
-/*$NetBSD: ixv.c,v 1.83 2018/02/27 04:58:27 msaitoh Exp $*/
+/*$NetBSD: ixv.c,v 1.84 2018/03/02 10:21:01 knakahara Exp $*/
 
 /**
 
@@ -150,6 +150,9 @@ static int	ixv_msix_mbx(void *);
 static void	ixv_handle_que(void *);
 static void ixv_handle_link(void *);
 
+/* Workqueue handler for deferred work */
+static void	ixv_handle_que_work(struct work *, void *);
+
 const struct sysctlnode *ixv_sysctl_instance(struct adapter *);
 static ixgbe_vendor_info_t *ixv_lookup(const struct pci_attach_args *);
 
@@ -200,6 +203,9 @@ TUNABLE_INT("hw.ixv.rx_process_limit", &
 static int ixv_tx_process_limit = 256;
 TUNABLE_INT("hw.ixv.tx_process_limit", &ixv_tx_process_limit);
 
+/* Which pakcet processing uses workqueue or softint */
+static bool ixv_txrx_workqueue = false;
+
 /*
  * Number of TX descriptors per ring,
  * setting higher than RX as this seems
@@ -220,10 +226,13 @@ TUNABLE_INT("hw.ixv.enable_legacy_tx", &
 #define IXGBE_MPSAFE		1
 #define IXGBE_CALLOUT_FLAGS	CALLOUT_MPSAFE
 #define IXGBE_SOFTINFT_FLAGS	SOFTINT_MPSAFE
+#define IXGBE_WORKQUEUE_FLAGS	WQ_PERCPU | WQ_MPSAFE
 #else
 #define IXGBE_CALLOUT_FLAGS	0
 #define IXGBE_SOFTINFT_FLAGS	0
+#define IXGBE_WORKQUEUE_FLAGS	WQ_PERCPU
 #endif
+#define IXGBE_WORKQUEUE_PRI PRI_SOFTNET
 
 #if 0
 static int (*ixv_start_locked)(struct ifnet *, struct tx_ring *);
@@ -508,6 +517,8 @@ ixv_attach(device_t parent, device_t dev
 	/* hw.ix defaults init */
 	adapter->enable_aim = ixv_enable_aim;
 
+	adapter->txrx_use_workqueue = ixv_txrx_workqueue;
+
 	error = ixv_allocate_msix(adapter, pa);
 	if (error) {
 		device_printf(dev, "ixv_allocate_msix() failed!\n");
@@ -597,6 +608,12 @@ ixv_detach(device_t dev, int flags)
 			softint_disestablish(txr->txr_si);
 		softint_disestablish(que->que_si);
 	}
+	if (adapter->txr_wq != NULL)
+		workqueue_destroy(adapter->txr_wq);
+	if (adapter->txr_wq_enqueued != NULL)
+		percpu_free(adapter->txr_wq_enqueued, sizeof(u_int));
+	if (adapter->que_wq != NULL)
+		workqueue_destroy(adapter->que_wq);
 
 	/* Drain the Mailbox(link) queue */
 	softint_disestablish(adapter->link_si);
@@ -2300,6 +2317,12 @@ ixv_add_device_sysctls(struct adapter *a
 	"enable_aim", SYSCTL_DESCR("Interrupt Moderation"),
 	NULL, 0, &adapter->enable_aim, 0, CTL_CREATE, CTL_EOL) != 0)
 		aprint_error_dev(dev, "could not create sysctl\n");
+
+	if (sysctl_createv(log, 0, &rnode, &cnode,
+	CTLFLAG_READWRITE, CTLTYPE_BOOL,
+	"txrx_workqueue", SYSCTL_DESCR("Use workqueue for packet processing"),
+		NULL, 0, &adapter->txrx_use_workqueue, 0, CTL_CREATE, CTL_EOL) != 0)
+		aprint_error_dev(dev, "could not create sysctl\n");
 }
 
 /
@@ -2769,7 +2792,6 @@ ixv_init(struct ifnet *ifp)
 	return 0;
 } /* ixv_init */
 
-
 /
  * ixv_handle_que
  /
@@ -2799,7 +2821,15 @@ ixv_handle_que(void *context)
 		IXGBE_TX_UNLOCK(txr);
 		if (more) {
 			adapter->req.ev_count++;
-			softint_schedule(que->que_si);
+			if (adapter->txrx_use_workqueue) {
+/*
+ * "enqueued flag" is not required here
+ * the same as ixg(4). See ixgbe_msix_que().
+ */
+workqueue_enqueue(adapter->que_wq,
+&que->wq_cookie, curcpu());
+			} else
+  softint_schedule(que->que_si);
 			return;
 		}
 	}
@@ -2811,6 +2841,21 @@ ixv_handle_que(void *context)
 } /* ixv_handle_que */
 
 /
+ * ixv_handle_que_work
+ /
+static void
+ixv_handle_que_work(struct work *wk, void *context)
+{
+	struct ix_queue *que = container_of(wk, struct ix_queue, wq_cookie);
+
+	/*
+	 * "enqueued flag" is not required here the same as ixg(4).
+	 * See ixgbe_msix_que().
+	 */
+	ixv_handle_que(que);
+}
+
+/
  * ixv_allocate_msix - Setup MSI-X Interrupt resources and handlers
  /
 static int
@@ -2823,6 +2868,7 @@ ixv_allocate_

CVS commit: src/sys/dev/pci/ixgbe

2018-03-02 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Mar  2 10:19:20 UTC 2018

Modified Files:
src/sys/dev/pci/ixgbe: ix_txrx.c ixgbe.c ixgbe.h

Log Message:
ixg(4) supports workqueue poll mode, but not enabled by default yet. (that is, 
the default behavior is *not* changed)

At the time of high load near the wire rate, the turnaround time
of update/delete processing such as "ifconfig ixg0 inet XXX" or
"ifconfig ixg0 delete" is very long. The main reason is CPU
starvation caused by ixg(4)'s softint poll mode. ixg(4) uses
workqueue poll mode instead of softint poll mode, so that this
problem will be fix.

This change may cause performance issues, so it is not enabled
by default yet. Although there are that issues, if you want to use
workqueue poll mode, do "sysctl -w hw.ixgXX.txrx_workqueue=1" while
there is no traffic on the ixgXX.

ok by msaitoh@n.o.


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/sys/dev/pci/ixgbe/ix_txrx.c
cvs rdiff -u -r1.127 -r1.128 src/sys/dev/pci/ixgbe/ixgbe.c
cvs rdiff -u -r1.31 -r1.32 src/sys/dev/pci/ixgbe/ixgbe.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/dev/pci/ixgbe/ix_txrx.c
diff -u src/sys/dev/pci/ixgbe/ix_txrx.c:1.33 src/sys/dev/pci/ixgbe/ix_txrx.c:1.34
--- src/sys/dev/pci/ixgbe/ix_txrx.c:1.33	Mon Feb 26 04:19:00 2018
+++ src/sys/dev/pci/ixgbe/ix_txrx.c	Fri Mar  2 10:19:20 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: ix_txrx.c,v 1.33 2018/02/26 04:19:00 knakahara Exp $ */
+/* $NetBSD: ix_txrx.c,v 1.34 2018/03/02 10:19:20 knakahara Exp $ */
 
 /**
 
@@ -238,8 +238,26 @@ ixgbe_mq_start(struct ifnet *ifp, struct
 	if (IXGBE_TX_TRYLOCK(txr)) {
 		ixgbe_mq_start_locked(ifp, txr);
 		IXGBE_TX_UNLOCK(txr);
-	} else
-		softint_schedule(txr->txr_si);
+	} else {
+		if (adapter->txrx_use_workqueue) {
+			/*
+			 * This function itself is not called in interrupt
+			 * context, however it can be called in fast softint
+			 * context right after receiving forwarding packets.
+			 * So, it is required to protect workqueue from twice
+			 * enqueuing when the machine uses both spontaneous
+			 * packets and forwarding packets.
+			 */
+			u_int *enqueued = percpu_getref(adapter->txr_wq_enqueued);
+			if (*enqueued == 0) {
+*enqueued = 1;
+percpu_putref(adapter->txr_wq_enqueued);
+workqueue_enqueue(adapter->txr_wq, &txr->wq_cookie, curcpu());
+			} else
+percpu_putref(adapter->txr_wq_enqueued);
+		} else
+			softint_schedule(txr->txr_si);
+	}
 
 	return (0);
 } /* ixgbe_mq_start */
@@ -291,7 +309,8 @@ ixgbe_mq_start_locked(struct ifnet *ifp,
 /
  * ixgbe_deferred_mq_start
  *
- *   Called from a taskqueue to drain queued transmit packets.
+ *   Called from a softint and workqueue (indirectly) to drain queued
+ *   transmit packets.
  /
 void
 ixgbe_deferred_mq_start(void *arg)
@@ -307,6 +326,24 @@ ixgbe_deferred_mq_start(void *arg)
 } /* ixgbe_deferred_mq_start */
 
 /
+ * ixgbe_deferred_mq_start_work
+ *
+ *   Called from a workqueue to drain queued transmit packets.
+ /
+void
+ixgbe_deferred_mq_start_work(struct work *wk, void *arg)
+{
+	struct tx_ring *txr = container_of(wk, struct tx_ring, wq_cookie);
+	struct adapter *adapter = txr->adapter;
+	u_int *enqueued = percpu_getref(adapter->txr_wq_enqueued);
+	*enqueued = 0;
+	percpu_putref(adapter->txr_wq_enqueued);
+
+	ixgbe_deferred_mq_start(txr);
+} /* ixgbe_deferred_mq_start */
+
+
+/
  * ixgbe_xmit
  *
  *   Maps the mbufs to tx descriptors, allowing the

Index: src/sys/dev/pci/ixgbe/ixgbe.c
diff -u src/sys/dev/pci/ixgbe/ixgbe.c:1.127 src/sys/dev/pci/ixgbe/ixgbe.c:1.128
--- src/sys/dev/pci/ixgbe/ixgbe.c:1.127	Mon Feb 26 04:19:00 2018
+++ src/sys/dev/pci/ixgbe/ixgbe.c	Fri Mar  2 10:19:20 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe.c,v 1.127 2018/02/26 04:19:00 knakahara Exp $ */
+/* $NetBSD: ixgbe.c,v 1.128 2018/03/02 10:19:20 knakahara Exp $ */
 
 /**
 
@@ -260,6 +260,9 @@ static void	ixgbe_handle_msf(void *);
 static void	ixgbe_handle_mod(void *);
 static void	ixgbe_handle_phy(void *);
 
+/* Workqueue handler for deferred work */
+static void	ixgbe_handle_que_work(struct work *, void *);
+
 static ixgbe_vendor_info_t *ixgbe_lookup(const struct pci_attach_args *);
 
 /
@@ -315,6 +318,9 @@ static int ixgbe_flow_control = ixgbe_fc
 SYSCTL_INT(_hw_ix, OID_AUTO, flow_control, CTLFLAG_RDTUN,
 &ixgbe_flow_control, 0, "Defa

CVS commit: src/sys/dev/pci/ixgbe

2018-02-26 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Feb 26 08:14:01 UTC 2018

Modified Files:
src/sys/dev/pci/ixgbe: ixv.c

Log Message:
Apply ixgbe.c:r1.127 to ixv.c. Pointed out by msaitoh@n.o.


To generate a diff of this commit:
cvs rdiff -u -r1.81 -r1.82 src/sys/dev/pci/ixgbe/ixv.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/dev/pci/ixgbe/ixv.c
diff -u src/sys/dev/pci/ixgbe/ixv.c:1.81 src/sys/dev/pci/ixgbe/ixv.c:1.82
--- src/sys/dev/pci/ixgbe/ixv.c:1.81	Thu Feb 22 10:02:08 2018
+++ src/sys/dev/pci/ixgbe/ixv.c	Mon Feb 26 08:14:01 2018
@@ -1,4 +1,4 @@
-/*$NetBSD: ixv.c,v 1.81 2018/02/22 10:02:08 msaitoh Exp $*/
+/*$NetBSD: ixv.c,v 1.82 2018/02/26 08:14:01 knakahara Exp $*/
 
 /**
 
@@ -664,6 +664,10 @@ ixv_detach(device_t dev, int flags)
 
 	ixgbe_free_transmit_structures(adapter);
 	ixgbe_free_receive_structures(adapter);
+	for (int i = 0; i < adapter->num_queues; i++) {
+		struct ix_queue *lque = &adapter->queues[i];
+		mutex_destroy(&lque->im_mtx);
+	}
 	free(adapter->queues, M_DEVBUF);
 
 	IXGBE_CORE_LOCK_DESTROY(adapter);
@@ -804,22 +808,36 @@ static inline void
 ixv_enable_queue(struct adapter *adapter, u32 vector)
 {
 	struct ixgbe_hw *hw = &adapter->hw;
+	struct ix_queue *que = &adapter->queues[vector];
 	u32 queue = 1 << vector;
 	u32 mask;
 
+	mutex_enter(&que->im_mtx);
+	if (que->im_nest > 0 && --que->im_nest > 0)
+		goto out;
+
 	mask = (IXGBE_EIMS_RTX_QUEUE & queue);
 	IXGBE_WRITE_REG(hw, IXGBE_VTEIMS, mask);
+out:
+	mutex_exit(&que->im_mtx);
 } /* ixv_enable_queue */
 
 static inline void
 ixv_disable_queue(struct adapter *adapter, u32 vector)
 {
 	struct ixgbe_hw *hw = &adapter->hw;
+	struct ix_queue *que = &adapter->queues[vector];
 	u64 queue = (u64)(1 << vector);
 	u32 mask;
 
+	mutex_enter(&que->im_mtx);
+	if (que->im_nest++ > 0)
+		goto  out;
+
 	mask = (IXGBE_EIMS_RTX_QUEUE & queue);
 	IXGBE_WRITE_REG(hw, IXGBE_VTEIMC, mask);
+out:
+	mutex_exit(&que->im_mtx);
 } /* ixv_disable_queue */
 
 static inline void
@@ -1923,8 +1941,16 @@ ixv_enable_intr(struct adapter *adapter)
 static void
 ixv_disable_intr(struct adapter *adapter)
 {
+	struct ix_queue	*que = adapter->queues;
+
 	IXGBE_WRITE_REG(&adapter->hw, IXGBE_VTEIAC, 0);
-	IXGBE_WRITE_REG(&adapter->hw, IXGBE_VTEIMC, ~0);
+
+	/* disable interrupts other than queues */
+	IXGBE_WRITE_REG(&adapter->hw, IXGBE_VTEIMC, adapter->vector);
+
+	for (int i = 0; i < adapter->num_queues; i++, que++)
+		ixv_disable_queue(adapter, que->msix);
+
 	IXGBE_WRITE_FLUSH(&adapter->hw);
 
 	return;



CVS commit: src/sys/dev/pci/ixgbe

2018-02-25 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Feb 26 04:19:00 UTC 2018

Modified Files:
src/sys/dev/pci/ixgbe: ix_txrx.c ixgbe.c ixgbe.h

Log Message:
Fix poll mode assumption breaking.

ixgbe_{enable,disable}_intr() forcibly enable/disable all interrupts
regardless of current state. That can break poll mode assumption,
that is, queue interrupts must not occur while polling Tx/Rx rings.

E.g. "ifconfig ixg0 delete && ifconfig ixg0 192.168.0.1" on heavy
load traffic can causes this issue.

This fix may have 1% or 2% performance impact at short packets.

XXX
ixgbe_rearm_queues() which is called only via watchdog can also break
this poll mode assumption because writing EICS casues interrupts
immediately when interrupt auto mask enabled.
We will fix it with other issues about watchdog later.

ok by msaitoh@n.o.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/sys/dev/pci/ixgbe/ix_txrx.c
cvs rdiff -u -r1.126 -r1.127 src/sys/dev/pci/ixgbe/ixgbe.c
cvs rdiff -u -r1.30 -r1.31 src/sys/dev/pci/ixgbe/ixgbe.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/dev/pci/ixgbe/ix_txrx.c
diff -u src/sys/dev/pci/ixgbe/ix_txrx.c:1.32 src/sys/dev/pci/ixgbe/ix_txrx.c:1.33
--- src/sys/dev/pci/ixgbe/ix_txrx.c:1.32	Thu Feb 22 10:02:08 2018
+++ src/sys/dev/pci/ixgbe/ix_txrx.c	Mon Feb 26 04:19:00 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: ix_txrx.c,v 1.32 2018/02/22 10:02:08 msaitoh Exp $ */
+/* $NetBSD: ix_txrx.c,v 1.33 2018/02/26 04:19:00 knakahara Exp $ */
 
 /**
 
@@ -2260,6 +2260,9 @@ ixgbe_allocate_queues(struct adapter *ad
 		que->me = i;
 		que->txr = &adapter->tx_rings[i];
 		que->rxr = &adapter->rx_rings[i];
+
+		mutex_init(&que->im_mtx, MUTEX_DEFAULT, IPL_NET);
+		que->im_nest = 0;
 	}
 
 	return (0);

Index: src/sys/dev/pci/ixgbe/ixgbe.c
diff -u src/sys/dev/pci/ixgbe/ixgbe.c:1.126 src/sys/dev/pci/ixgbe/ixgbe.c:1.127
--- src/sys/dev/pci/ixgbe/ixgbe.c:1.126	Thu Feb 22 10:02:08 2018
+++ src/sys/dev/pci/ixgbe/ixgbe.c	Mon Feb 26 04:19:00 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe.c,v 1.126 2018/02/22 10:02:08 msaitoh Exp $ */
+/* $NetBSD: ixgbe.c,v 1.127 2018/02/26 04:19:00 knakahara Exp $ */
 
 /**
 
@@ -2384,9 +2384,14 @@ static inline void
 ixgbe_enable_queue(struct adapter *adapter, u32 vector)
 {
 	struct ixgbe_hw *hw = &adapter->hw;
+	struct ix_queue *que = &adapter->queues[vector];
 	u64 queue = (u64)(1ULL << vector);
 	u32 mask;
 
+	mutex_enter(&que->im_mtx);
+	if (que->im_nest > 0 && --que->im_nest > 0)
+		goto out;
+
 	if (hw->mac.type == ixgbe_mac_82598EB) {
 		mask = (IXGBE_EIMS_RTX_QUEUE & queue);
 		IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
@@ -2398,6 +2403,8 @@ ixgbe_enable_queue(struct adapter *adapt
 		if (mask)
 			IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
 	}
+out:
+	mutex_exit(&que->im_mtx);
 } /* ixgbe_enable_queue */
 
 /
@@ -2407,9 +2414,14 @@ static inline void
 ixgbe_disable_queue(struct adapter *adapter, u32 vector)
 {
 	struct ixgbe_hw *hw = &adapter->hw;
+	struct ix_queue *que = &adapter->queues[vector];
 	u64 queue = (u64)(1ULL << vector);
 	u32 mask;
 
+	mutex_enter(&que->im_mtx);
+	if (que->im_nest++ > 0)
+		goto  out;
+
 	if (hw->mac.type == ixgbe_mac_82598EB) {
 		mask = (IXGBE_EIMS_RTX_QUEUE & queue);
 		IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
@@ -2421,6 +2433,8 @@ ixgbe_disable_queue(struct adapter *adap
 		if (mask)
 			IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
 	}
+out:
+	mutex_exit(&que->im_mtx);
 } /* ixgbe_disable_queue */
 
 /
@@ -3427,6 +3441,10 @@ ixgbe_detach(device_t dev, int flags)
 
 	ixgbe_free_transmit_structures(adapter);
 	ixgbe_free_receive_structures(adapter);
+	for (int i = 0; i < adapter->num_queues; i++) {
+		struct ix_queue * que = &adapter->queues[i];
+		mutex_destroy(&que->im_mtx);
+	}
 	free(adapter->queues, M_DEVBUF);
 	free(adapter->mta, M_DEVBUF);
 
@@ -4568,15 +4586,17 @@ ixgbe_enable_intr(struct adapter *adapte
 static void
 ixgbe_disable_intr(struct adapter *adapter)
 {
+	struct ix_queue	*que = adapter->queues;
+
+	/* disable interrupts other than queues */
+	IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~IXGBE_EIMC_RTX_QUEUE);
+
 	if (adapter->msix_mem)
 		IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, 0);
-	if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
-		IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
-	} else {
-		IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0x);
-		IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
-		IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
-	}
+
+	for (int i = 0; i < adapter->num_queues; i++, que++)
+		ixgbe_disable_queue(adapter, que->msix);
+
 	IXGBE_WRITE_F

CVS commit: src/sys/dev/pci/ixgbe

2018-02-20 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Tue Feb 20 08:49:23 UTC 2018

Modified Files:
src/sys/dev/pci/ixgbe: ixgbe.c

Log Message:
Improve a comment about reading EICS register defined write-only by spec.

It seems that is workaround for silicon errata.

ok by msaitoh@n.o.


To generate a diff of this commit:
cvs rdiff -u -r1.124 -r1.125 src/sys/dev/pci/ixgbe/ixgbe.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/dev/pci/ixgbe/ixgbe.c
diff -u src/sys/dev/pci/ixgbe/ixgbe.c:1.124 src/sys/dev/pci/ixgbe/ixgbe.c:1.125
--- src/sys/dev/pci/ixgbe/ixgbe.c:1.124	Tue Feb 20 07:24:37 2018
+++ src/sys/dev/pci/ixgbe/ixgbe.c	Tue Feb 20 08:49:23 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe.c,v 1.124 2018/02/20 07:24:37 msaitoh Exp $ */
+/* $NetBSD: ixgbe.c,v 1.125 2018/02/20 08:49:23 knakahara Exp $ */
 
 /**
 
@@ -2838,6 +2838,12 @@ ixgbe_msix_link(void *arg)
 	IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_OTHER);
 
 	/* First get the cause */
+	/*
+	 * The specifications of 82598, 82599, X540 and X550 say EICS register
+	 * is write only. However, Linux says it is a workaround for silicon
+	 * errata to read EICS instead of EICR to get interrupt cause. It seems
+	 * there is a problem about read clear mechanism for EICR register.
+	 */
 	eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
 	/* Be sure the queue bits are not cleared */
 	eicr &= ~IXGBE_EICR_RTX_QUEUE;



CVS commit: src

2018-02-16 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Feb 16 10:19:04 UTC 2018

Modified Files:
src/distrib/sets/lists/comp: mi
src/sys/net: Makefile

Log Message:
Currently, it is not necessary to install rss_config.h. Pointed out by 
msaitoh@n.o.


To generate a diff of this commit:
cvs rdiff -u -r1.2182 -r1.2183 src/distrib/sets/lists/comp/mi
cvs rdiff -u -r1.35 -r1.36 src/sys/net/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/sets/lists/comp/mi
diff -u src/distrib/sets/lists/comp/mi:1.2182 src/distrib/sets/lists/comp/mi:1.2183
--- src/distrib/sets/lists/comp/mi:1.2182	Fri Feb 16 07:05:21 2018
+++ src/distrib/sets/lists/comp/mi	Fri Feb 16 10:19:03 2018
@@ -1,4 +1,4 @@
-#	$NetBSD: mi,v 1.2182 2018/02/16 07:05:21 knakahara Exp $
+#	$NetBSD: mi,v 1.2183 2018/02/16 10:19:03 knakahara Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 ./etc/mtree/set.compcomp-sys-root
@@ -2333,7 +2333,6 @@
 ./usr/include/net/radix.h			comp-c-include
 ./usr/include/net/raw_cb.h			comp-c-include
 ./usr/include/net/route.h			comp-c-include
-./usr/include/net/rss_config.h			comp-c-include
 ./usr/include/net/slcompress.h			comp-c-include
 ./usr/include/net/slip.h			comp-c-include
 ./usr/include/net/zlib.h			comp-c-include

Index: src/sys/net/Makefile
diff -u src/sys/net/Makefile:1.35 src/sys/net/Makefile:1.36
--- src/sys/net/Makefile:1.35	Fri Feb 16 04:48:32 2018
+++ src/sys/net/Makefile	Fri Feb 16 10:19:04 2018
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.35 2018/02/16 04:48:32 knakahara Exp $
+#	$NetBSD: Makefile,v 1.36 2018/02/16 10:19:04 knakahara Exp $
 
 INCSDIR= /usr/include/net
 
@@ -8,7 +8,7 @@ INCS=	bpf.h bpfjit.h bpfdesc.h dlt.h eth
 	if_pflog.h if_ppp.h if_pppoe.h if_l2tp.h if_sppp.h if_srt.h if_stf.h \
 	if_tap.h if_token.h if_tun.h if_types.h if_vlanvar.h net_stats.h \
 	netisr.h pfil.h pfkeyv2.h pfvar.h ppp-comp.h ppp_defs.h radix.h \
-	raw_cb.h route.h rss_config.h slcompress.h slip.h zlib.h
+	raw_cb.h route.h slcompress.h slip.h zlib.h
 
 SUBDIR=	agr npf
 



CVS commit: src/distrib/sets/lists/comp

2018-02-15 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Feb 16 07:05:21 UTC 2018

Modified Files:
src/distrib/sets/lists/comp: mi

Log Message:
Fix build failure, sorry.


To generate a diff of this commit:
cvs rdiff -u -r1.2181 -r1.2182 src/distrib/sets/lists/comp/mi

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/sets/lists/comp/mi
diff -u src/distrib/sets/lists/comp/mi:1.2181 src/distrib/sets/lists/comp/mi:1.2182
--- src/distrib/sets/lists/comp/mi:1.2181	Tue Feb 13 10:02:12 2018
+++ src/distrib/sets/lists/comp/mi	Fri Feb 16 07:05:21 2018
@@ -1,4 +1,4 @@
-#	$NetBSD: mi,v 1.2181 2018/02/13 10:02:12 mrg Exp $
+#	$NetBSD: mi,v 1.2182 2018/02/16 07:05:21 knakahara Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 ./etc/mtree/set.compcomp-sys-root
@@ -2333,6 +2333,7 @@
 ./usr/include/net/radix.h			comp-c-include
 ./usr/include/net/raw_cb.h			comp-c-include
 ./usr/include/net/route.h			comp-c-include
+./usr/include/net/rss_config.h			comp-c-include
 ./usr/include/net/slcompress.h			comp-c-include
 ./usr/include/net/slip.h			comp-c-include
 ./usr/include/net/zlib.h			comp-c-include



CVS commit: src/sys/dev/pci/ixgbe

2018-02-15 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Feb 16 04:50:19 UTC 2018

Modified Files:
src/sys/dev/pci/ixgbe: ixgbe.c ixgbe_rss.h ixv.c

Log Message:
Apply RSS utility to ixg(4) and ixv(4).

ok by msaitoh@n.o.


To generate a diff of this commit:
cvs rdiff -u -r1.121 -r1.122 src/sys/dev/pci/ixgbe/ixgbe.c
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/pci/ixgbe/ixgbe_rss.h
cvs rdiff -u -r1.77 -r1.78 src/sys/dev/pci/ixgbe/ixv.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/dev/pci/ixgbe/ixgbe.c
diff -u src/sys/dev/pci/ixgbe/ixgbe.c:1.121 src/sys/dev/pci/ixgbe/ixgbe.c:1.122
--- src/sys/dev/pci/ixgbe/ixgbe.c:1.121	Wed Feb 14 10:38:28 2018
+++ src/sys/dev/pci/ixgbe/ixgbe.c	Fri Feb 16 04:50:19 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe.c,v 1.121 2018/02/14 10:38:28 msaitoh Exp $ */
+/* $NetBSD: ixgbe.c,v 1.122 2018/02/16 04:50:19 knakahara Exp $ */
 
 /**
 
@@ -411,6 +411,10 @@ ixgbe_initialize_rss_mapping(struct adap
 	int i, j;
 	u32 rss_hash_config;
 
+	/* force use default RSS key. */
+#ifdef __NetBSD__
+	rss_getkey((uint8_t *) &rss_key);
+#else
 	if (adapter->feat_en & IXGBE_FEATURE_RSS) {
 		/* Fetch the configured RSS key */
 		rss_getkey((uint8_t *) &rss_key);
@@ -418,6 +422,7 @@ ixgbe_initialize_rss_mapping(struct adap
 		/* set up random bits */
 		cprng_fast(&rss_key, sizeof(rss_key));
 	}
+#endif
 
 	/* Set multiplier for RETA setup and table size based on MAC */
 	index_mult = 0x1;

Index: src/sys/dev/pci/ixgbe/ixgbe_rss.h
diff -u src/sys/dev/pci/ixgbe/ixgbe_rss.h:1.2 src/sys/dev/pci/ixgbe/ixgbe_rss.h:1.3
--- src/sys/dev/pci/ixgbe/ixgbe_rss.h:1.2	Wed Dec  6 04:08:50 2017
+++ src/sys/dev/pci/ixgbe/ixgbe_rss.h	Fri Feb 16 04:50:19 2018
@@ -35,6 +35,26 @@
 #ifndef _IXGBE_RSS_H_
 #define _IXGBE_RSS_H_
 
+#ifdef __NetBSD__
+#include 
+
+#define RSS_HASHTYPE_RSS_IPV4  (1 << 1)
+#define RSS_HASHTYPE_RSS_TCP_IPV4  (1 << 2)
+#define RSS_HASHTYPE_RSS_IPV6  (1 << 3)
+#define RSS_HASHTYPE_RSS_TCP_IPV6  (1 << 4)
+#define RSS_HASHTYPE_RSS_IPV6_EX   (1 << 5)
+#define RSS_HASHTYPE_RSS_TCP_IPV6_EX   (1 << 6)
+#define RSS_HASHTYPE_RSS_UDP_IPV4  (1 << 7)
+#define RSS_HASHTYPE_RSS_UDP_IPV6  (1 << 9)
+#define RSS_HASHTYPE_RSS_UDP_IPV6_EX   (1 << 10)
+
+#define rss_getcpu(_a) 0
+#define rss_getnumbuckets() 1
+#define rss_get_indirection_to_bucket(_a) 0
+#define rss_gethashconfig() 0x7E
+#define rss_hash2bucket(_a,_b,_c) -1
+
+#else
 #ifdef RSS
 
 #include 
@@ -60,4 +80,5 @@
 #define rss_hash2bucket(_a,_b,_c) -1
 
 #endif
+#endif /* __NetBSD__ */
 #endif /* _IXGBE_RSS_H_ */

Index: src/sys/dev/pci/ixgbe/ixv.c
diff -u src/sys/dev/pci/ixgbe/ixv.c:1.77 src/sys/dev/pci/ixgbe/ixv.c:1.78
--- src/sys/dev/pci/ixgbe/ixv.c:1.77	Thu Dec 21 06:49:26 2017
+++ src/sys/dev/pci/ixgbe/ixv.c	Fri Feb 16 04:50:19 2018
@@ -1,4 +1,4 @@
-/*$NetBSD: ixv.c,v 1.77 2017/12/21 06:49:26 msaitoh Exp $*/
+/*$NetBSD: ixv.c,v 1.78 2018/02/16 04:50:19 knakahara Exp $*/
 
 /**
 
@@ -1520,6 +1520,10 @@ ixv_initialize_rss_mapping(struct adapte
 	int i, j;
 	u32 rss_hash_config;
 
+	/* force use default RSS key. */
+#ifdef __NetBSD__
+	rss_getkey((uint8_t *) &rss_key);
+#else
 	if (adapter->feat_en & IXGBE_FEATURE_RSS) {
 		/* Fetch the configured RSS key */
 		rss_getkey((uint8_t *)&rss_key);
@@ -1527,6 +1531,7 @@ ixv_initialize_rss_mapping(struct adapte
 		/* set up random bits */
 		cprng_fast(&rss_key, sizeof(rss_key));
 	}
+#endif
 
 	/* Now fill out hash function seeds */
 	for (i = 0; i < 10; i++)



CVS commit: src/sys/dev/pci

2018-02-15 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Feb 16 04:49:27 UTC 2018

Modified Files:
src/sys/dev/pci: if_wm.c

Log Message:
Apply RSS utility to wm(4).

ok by msaitoh@n.o.


To generate a diff of this commit:
cvs rdiff -u -r1.563 -r1.564 src/sys/dev/pci/if_wm.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/dev/pci/if_wm.c
diff -u src/sys/dev/pci/if_wm.c:1.563 src/sys/dev/pci/if_wm.c:1.564
--- src/sys/dev/pci/if_wm.c:1.563	Wed Feb 14 12:56:00 2018
+++ src/sys/dev/pci/if_wm.c	Fri Feb 16 04:49:27 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_wm.c,v 1.563 2018/02/14 12:56:00 knakahara Exp $	*/
+/*	$NetBSD: if_wm.c,v 1.564 2018/02/16 04:49:27 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2001, 2002, 2003, 2004 Wasabi Systems, Inc.
@@ -83,7 +83,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.563 2018/02/14 12:56:00 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.564 2018/02/16 04:49:27 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -116,6 +116,8 @@ __KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.
 
 #include 
 
+#include 
+
 #include 			/* XXX for struct ip */
 #include 		/* XXX for struct ip */
 #include 			/* XXX for struct ip */
@@ -715,7 +717,6 @@ static void	wm_flush_desc_rings(struct w
 static void	wm_reset(struct wm_softc *);
 static int	wm_add_rxbuf(struct wm_rxqueue *, int);
 static void	wm_rxdrain(struct wm_rxqueue *);
-static void	wm_rss_getkey(uint8_t *);
 static void	wm_init_rss(struct wm_softc *);
 static void	wm_adjust_qnum(struct wm_softc *, int);
 static inline bool	wm_is_using_msix(struct wm_softc *);
@@ -4838,43 +4839,6 @@ wm_rxdrain(struct wm_rxqueue *rxq)
 	}
 }
 
-
-/*
- * XXX copy from FreeBSD's sys/net/rss_config.c
- */
-/*
- * RSS secret key, intended to prevent attacks on load-balancing.  Its
- * effectiveness may be limited by algorithm choice and available entropy
- * during the boot.
- *
- * XXXRW: And that we don't randomize it yet!
- *
- * This is the default Microsoft RSS specification key which is also
- * the Chelsio T5 firmware default key.
- */
-#define RSS_KEYSIZE 40
-static uint8_t wm_rss_key[RSS_KEYSIZE] = {
-	0x6d, 0x5a, 0x56, 0xda, 0x25, 0x5b, 0x0e, 0xc2,
-	0x41, 0x67, 0x25, 0x3d, 0x43, 0xa3, 0x8f, 0xb0,
-	0xd0, 0xca, 0x2b, 0xcb, 0xae, 0x7b, 0x30, 0xb4,
-	0x77, 0xcb, 0x2d, 0xa3, 0x80, 0x30, 0xf2, 0x0c,
-	0x6a, 0x42, 0xb7, 0x3b, 0xbe, 0xac, 0x01, 0xfa,
-};
-
-/*
- * Caller must pass an array of size sizeof(rss_key).
- *
- * XXX
- * As if_ixgbe may use this function, this function should not be
- * if_wm specific function.
- */
-static void
-wm_rss_getkey(uint8_t *key)
-{
-
-	memcpy(key, wm_rss_key, sizeof(wm_rss_key));
-}
-
 /*
  * Setup registers for RSS.
  *
@@ -4886,7 +4850,7 @@ wm_init_rss(struct wm_softc *sc)
 	uint32_t mrqc, reta_reg, rss_key[RSSRK_NUM_REGS];
 	int i;
 
-	CTASSERT(sizeof(rss_key) == sizeof(wm_rss_key));
+	CTASSERT(sizeof(rss_key) == RSS_KEYSIZE);
 
 	for (i = 0; i < RETA_NUM_ENTRIES; i++) {
 		int qid, reta_ent;
@@ -4912,7 +4876,7 @@ wm_init_rss(struct wm_softc *sc)
 		CSR_WRITE(sc, WMREG_RETA_Q(i), reta_reg);
 	}
 
-	wm_rss_getkey((uint8_t *)rss_key);
+	rss_getkey((uint8_t *)rss_key);
 	for (i = 0; i < RSSRK_NUM_REGS; i++)
 		CSR_WRITE(sc, WMREG_RSSRK(i), rss_key[i]);
 



CVS commit: src/sys/net

2018-02-15 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Feb 16 04:48:33 UTC 2018

Modified Files:
src/sys/net: Makefile files.net
Added Files:
src/sys/net: rss_config.c rss_config.h

Log Message:
Introduce very simple Receive Side Scaling (RSS) utility.

ok by msaitoh@n.o.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sys/net/Makefile
cvs rdiff -u -r1.14 -r1.15 src/sys/net/files.net
cvs rdiff -u -r0 -r1.1 src/sys/net/rss_config.c src/sys/net/rss_config.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/net/Makefile
diff -u src/sys/net/Makefile:1.34 src/sys/net/Makefile:1.35
--- src/sys/net/Makefile:1.34	Wed Jan 10 10:56:30 2018
+++ src/sys/net/Makefile	Fri Feb 16 04:48:32 2018
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.34 2018/01/10 10:56:30 knakahara Exp $
+#	$NetBSD: Makefile,v 1.35 2018/02/16 04:48:32 knakahara Exp $
 
 INCSDIR= /usr/include/net
 
@@ -8,7 +8,7 @@ INCS=	bpf.h bpfjit.h bpfdesc.h dlt.h eth
 	if_pflog.h if_ppp.h if_pppoe.h if_l2tp.h if_sppp.h if_srt.h if_stf.h \
 	if_tap.h if_token.h if_tun.h if_types.h if_vlanvar.h net_stats.h \
 	netisr.h pfil.h pfkeyv2.h pfvar.h ppp-comp.h ppp_defs.h radix.h \
-	raw_cb.h route.h slcompress.h slip.h zlib.h
+	raw_cb.h route.h rss_config.h slcompress.h slip.h zlib.h
 
 SUBDIR=	agr npf
 

Index: src/sys/net/files.net
diff -u src/sys/net/files.net:1.14 src/sys/net/files.net:1.15
--- src/sys/net/files.net:1.14	Wed Jan 10 10:56:30 2018
+++ src/sys/net/files.net	Fri Feb 16 04:48:32 2018
@@ -1,4 +1,4 @@
-#	$NetBSD: files.net,v 1.14 2018/01/10 10:56:30 knakahara Exp $
+#	$NetBSD: files.net,v 1.15 2018/02/16 04:48:32 knakahara Exp $
 
 # XXX CLEANUP
 define	net
@@ -48,6 +48,7 @@ file	net/radix.c			net
 file	net/raw_cb.c			net
 file	net/raw_usrreq.c		net
 file	net/route.c			net
+file	net/rss_config.c		net
 file	net/rtbl.c			net
 file	net/rtsock.c			net
 file	net/slcompress.c		sl | ppp | strip | (irip & irip_vj)

Added files:

Index: src/sys/net/rss_config.c
diff -u /dev/null src/sys/net/rss_config.c:1.1
--- /dev/null	Fri Feb 16 04:48:33 2018
+++ src/sys/net/rss_config.c	Fri Feb 16 04:48:32 2018
@@ -0,0 +1,76 @@
+/*	$NetBSD: rss_config.c,v 1.1 2018/02/16 04:48:32 knakahara Exp $  */
+
+/*
+ * Copyright (c) 2018 Internet Initiative Japan Inc.
+ * All rights reserved.
+ *
+ * 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 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 FOUNDATION 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.
+ */
+
+#include 
+__KERNEL_RCSID(0, "$NetBSD: rss_config.c,v 1.1 2018/02/16 04:48:32 knakahara Exp $");
+
+#include 
+#include 
+#include 
+
+#include 
+
+/*
+ * Same as FreeBSD.
+ *
+ * This rss key is assumed for verification suite in many intel Gigabit and
+ * 10 Gigabit Controller specifications.
+ */
+static uint8_t rss_default_key[RSS_KEYSIZE] = {
+	0x6d, 0x5a, 0x56, 0xda, 0x25, 0x5b, 0x0e, 0xc2,
+	0x41, 0x67, 0x25, 0x3d, 0x43, 0xa3, 0x8f, 0xb0,
+	0xd0, 0xca, 0x2b, 0xcb, 0xae, 0x7b, 0x30, 0xb4,
+	0x77, 0xcb, 0x2d, 0xa3, 0x80, 0x30, 0xf2, 0x0c,
+	0x6a, 0x42, 0xb7, 0x3b, 0xbe, 0xac, 0x01, 0xfa,
+};
+
+#ifdef NOTYET
+/*
+ * Same as DragonFlyBSD.
+ *
+ * This rss key make rss hash value symmetric, that is, the hash value
+ * calculated by func("source address", "destination address") equals to
+ * the hash value calculated by func("destination address", "source address").
+ */
+static uint8_t rss_symmetric_key[RSS_KEYSIZE] = {
+	0x6d, 0x5a, 0x6d, 0x5a, 0x6d, 0x5a, 0x6d, 0x5a,
+	0x6d, 0x5a, 0x6d, 0x5a, 0x6d, 0x5a, 0x6d, 0x5a,
+	0x6d, 0x5a, 0x6d, 0x5a, 0x6d, 0x5a, 0x6d, 0x5a,
+	0x6d, 0x5a, 0x6d, 0x5a, 0x6d, 0x5a, 0x6d, 0x5a,
+};
+#endif
+
+/*
+ * sizeof(key) must be more than or equal to RSS_KEYSIZE.
+ */
+void
+rss_getkey(uint8_t *key)
+{
+
+	memcpy(key, rss_de

CVS commit: src/sys/dev/pci

2018-02-14 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Feb 14 12:56:00 UTC 2018

Modified Files:
src/sys/dev/pci: if_wm.c

Log Message:
Fix a bug that RX and TX may stall on heavy load on wm(4) like ixgbe.c:r1.121.

wm_rxeof() and wm_txeof() have loop limit and the function returns true
if a packet still exists.

XXX need pullup-8


To generate a diff of this commit:
cvs rdiff -u -r1.562 -r1.563 src/sys/dev/pci/if_wm.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/dev/pci/if_wm.c
diff -u src/sys/dev/pci/if_wm.c:1.562 src/sys/dev/pci/if_wm.c:1.563
--- src/sys/dev/pci/if_wm.c:1.562	Tue Jan 30 08:15:47 2018
+++ src/sys/dev/pci/if_wm.c	Wed Feb 14 12:56:00 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_wm.c,v 1.562 2018/01/30 08:15:47 knakahara Exp $	*/
+/*	$NetBSD: if_wm.c,v 1.563 2018/02/14 12:56:00 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2001, 2002, 2003, 2004 Wasabi Systems, Inc.
@@ -83,7 +83,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.562 2018/01/30 08:15:47 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.563 2018/02/14 12:56:00 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -775,8 +775,8 @@ static void	wm_nq_send_common_locked(str
 static void	wm_deferred_start_locked(struct wm_txqueue *);
 static void	wm_handle_queue(void *);
 /* Interrupt */
-static int	wm_txeof(struct wm_txqueue *, u_int);
-static void	wm_rxeof(struct wm_rxqueue *, u_int);
+static bool	wm_txeof(struct wm_txqueue *, u_int);
+static bool	wm_rxeof(struct wm_rxqueue *, u_int);
 static void	wm_linkintr_gmii(struct wm_softc *, uint32_t);
 static void	wm_linkintr_tbi(struct wm_softc *, uint32_t);
 static void	wm_linkintr_serdes(struct wm_softc *, uint32_t);
@@ -8066,7 +8066,7 @@ wm_deferred_start_locked(struct wm_txque
  *
  *	Helper; handle transmit interrupts.
  */
-static int
+static bool
 wm_txeof(struct wm_txqueue *txq, u_int limit)
 {
 	struct wm_softc *sc = txq->txq_sc;
@@ -8076,11 +8076,12 @@ wm_txeof(struct wm_txqueue *txq, u_int l
 	int i;
 	uint8_t status;
 	struct wm_queue *wmq = container_of(txq, struct wm_queue, wmq_txq);
+	bool more = false;
 
 	KASSERT(mutex_owned(txq->txq_lock));
 
 	if (txq->txq_stopping)
-		return 0;
+		return false;
 
 	txq->txq_flags &= ~WM_TXQ_NO_SPACE;
 	/* for ALTQ and legacy(not use multiqueue) ethernet controller */
@@ -8093,8 +8094,13 @@ wm_txeof(struct wm_txqueue *txq, u_int l
 	 */
 	for (i = txq->txq_sdirty; txq->txq_sfree != WM_TXQUEUELEN(txq);
 	 i = WM_NEXTTXS(txq, i), txq->txq_sfree++) {
-		if (limit-- == 0)
+		if (limit-- == 0) {
+			more = true;
+			DPRINTF(WM_DEBUG_TX,
+			("%s: TX: loop limited, job %d is not processed\n",
+device_xname(sc->sc_dev), i));
 			break;
+		}
 
 		txs = &txq->txq_soft[i];
 
@@ -8168,7 +8174,7 @@ wm_txeof(struct wm_txqueue *txq, u_int l
 	if (txq->txq_sfree == WM_TXQUEUELEN(txq))
 		txq->txq_watchdog = false;
 
-	return count;
+	return more;
 }
 
 static inline uint32_t
@@ -8381,7 +8387,7 @@ wm_rxdesc_ensure_checksum(struct wm_rxqu
  *
  *	Helper; handle receive interrupts.
  */
-static void
+static bool
 wm_rxeof(struct wm_rxqueue *rxq, u_int limit)
 {
 	struct wm_softc *sc = rxq->rxq_sc;
@@ -8392,12 +8398,17 @@ wm_rxeof(struct wm_rxqueue *rxq, u_int l
 	int count = 0;
 	uint32_t status, errors;
 	uint16_t vlantag;
+	bool more = false;
 
 	KASSERT(mutex_owned(rxq->rxq_lock));
 
 	for (i = rxq->rxq_ptr;; i = WM_NEXTRX(i)) {
 		if (limit-- == 0) {
 			rxq->rxq_ptr = i;
+			more = true;
+			DPRINTF(WM_DEBUG_RX,
+			("%s: RX: loop limited, descriptor %d is not processed\n",
+device_xname(sc->sc_dev), i));
 			break;
 		}
 
@@ -8571,6 +8582,8 @@ wm_rxeof(struct wm_rxqueue *rxq, u_int l
 
 	DPRINTF(WM_DEBUG_RX,
 	("%s: RX: rxptr -> %d\n", device_xname(sc->sc_dev), i));
+
+	return more;
 }
 
 /*
@@ -9009,6 +9022,8 @@ wm_txrxintr_msix(void *arg)
 	struct wm_softc *sc = txq->txq_sc;
 	u_int txlimit = sc->sc_tx_intr_process_limit;
 	u_int rxlimit = sc->sc_rx_intr_process_limit;
+	bool txmore;
+	bool rxmore;
 
 	KASSERT(wmq->wmq_intr_idx == wmq->wmq_id);
 
@@ -9025,7 +9040,7 @@ wm_txrxintr_msix(void *arg)
 	}
 
 	WM_Q_EVCNT_INCR(txq, txdw);
-	wm_txeof(txq, txlimit);
+	txmore = wm_txeof(txq, txlimit);
 	/* wm_deferred start() is done in wm_handle_queue(). */
 	mutex_exit(txq->txq_lock);
 
@@ -9039,12 +9054,15 @@ wm_txrxintr_msix(void *arg)
 	}
 
 	WM_Q_EVCNT_INCR(rxq, rxintr);
-	wm_rxeof(rxq, rxlimit);
+	rxmore = wm_rxeof(rxq, rxlimit);
 	mutex_exit(rxq->rxq_lock);
 
 	wm_itrs_writereg(sc, wmq);
 
-	softint_schedule(wmq->wmq_si);
+	if (txmore || rxmore)
+		softint_schedule(wmq->wmq_si);
+	else
+		wm_txrxintr_enable(wmq);
 
 	return 1;
 }
@@ -9058,13 +9076,15 @@ wm_handle_queue(void *arg)
 	struct wm_softc *sc = txq->txq_sc;
 	u_int txlimit = sc->sc_tx_process_limit;
 	u_int rxlimit = sc->sc_rx_process_limit;
+	bool txmore;
+	bool rxmore;
 
 	mutex_enter(txq->txq_lock);
 	if (txq->txq

CVS commit: src/share/man/man4

2018-02-06 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Feb  7 03:26:37 UTC 2018

Modified Files:
src/share/man/man4: wm.4

Log Message:
Fix PR misc/52890


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/share/man/man4/wm.4

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/share/man/man4/wm.4
diff -u src/share/man/man4/wm.4:1.38 src/share/man/man4/wm.4:1.39
--- src/share/man/man4/wm.4:1.38	Thu Jan 18 09:54:52 2018
+++ src/share/man/man4/wm.4	Wed Feb  7 03:26:36 2018
@@ -1,4 +1,4 @@
-.\"	$NetBSD: wm.4,v 1.38 2018/01/18 09:54:52 wiz Exp $
+.\"	$NetBSD: wm.4,v 1.39 2018/02/07 03:26:36 knakahara Exp $
 .\"
 .\" Copyright 2002, 2003 Wasabi Systems, Inc.
 .\" All rights reserved.
@@ -168,6 +168,15 @@ driver supports these features of the ch
 See
 .Xr ifconfig 8
 for information on how to enable this feature.
+.Pp
+Many chips supported by the
+.Nm
+driver support jumbo frames, however several chips do not support
+jumbo frames, e.g. i82542, i82081H and 82567V.
+Jumbo frames can be configured via the interface MTU setting.
+Selecting an MTU larger than 1500 bytes with the
+.Xr ifconfig 8
+utility configures the adapter to receive and transmit jumbo frames.
 .\" .Sh DIAGNOSTICS
 .\" XXX to be done.
 .Sh OPTIONS



CVS commit: src/sys/net

2018-02-05 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Tue Feb  6 03:15:15 UTC 2018

Modified Files:
src/sys/net: if_spppsubr.c

Log Message:
Fix breaking character limit. Pointed out by ozaki-r@n.o, thanks.


To generate a diff of this commit:
cvs rdiff -u -r1.178 -r1.179 src/sys/net/if_spppsubr.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/net/if_spppsubr.c
diff -u src/sys/net/if_spppsubr.c:1.178 src/sys/net/if_spppsubr.c:1.179
--- src/sys/net/if_spppsubr.c:1.178	Thu Dec 28 07:06:36 2017
+++ src/sys/net/if_spppsubr.c	Tue Feb  6 03:15:15 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppsubr.c,v 1.178 2017/12/28 07:06:36 ozaki-r Exp $	 */
+/*	$NetBSD: if_spppsubr.c,v 1.179 2018/02/06 03:15:15 knakahara Exp $	 */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.178 2017/12/28 07:06:36 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.179 2018/02/06 03:15:15 knakahara Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -2969,7 +2969,7 @@ sppp_ipcp_init(struct sppp *sp)
 	sp->pp_rseq[IDX_IPCP] = 0;
 	callout_init(&sp->ch[IDX_IPCP], CALLOUT_MPSAFE);
 
-	error = workqueue_create(&sp->ipcp.update_addrs_wq, "ipcp_update_addrs",
+	error = workqueue_create(&sp->ipcp.update_addrs_wq, "ipcp_addr",
 	sppp_update_ip_addrs_work, sp, PRI_SOFTNET, IPL_NET, 0);
 	if (error)
 		panic("%s: update_addrs workqueue_create failed (%d)\n",



CVS commit: src/sys/dev/pci

2018-01-30 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Tue Jan 30 08:15:47 UTC 2018

Modified Files:
src/sys/dev/pci: if_wm.c

Log Message:
Make wm(4) watchdog MP-safe. There is almost no influence on performance.

wm(4) does not use ifp->if_watchdog now, that is, it does not touch
ifp->if_timer.
It also uses own callout(wm_tick) as watchdog now. The watchdog uses
per-queue counter to check timeout. So, global lock is not required.


To generate a diff of this commit:
cvs rdiff -u -r1.561 -r1.562 src/sys/dev/pci/if_wm.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/dev/pci/if_wm.c
diff -u src/sys/dev/pci/if_wm.c:1.561 src/sys/dev/pci/if_wm.c:1.562
--- src/sys/dev/pci/if_wm.c:1.561	Mon Jan 29 04:17:32 2018
+++ src/sys/dev/pci/if_wm.c	Tue Jan 30 08:15:47 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_wm.c,v 1.561 2018/01/29 04:17:32 knakahara Exp $	*/
+/*	$NetBSD: if_wm.c,v 1.562 2018/01/30 08:15:47 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2001, 2002, 2003, 2004 Wasabi Systems, Inc.
@@ -83,7 +83,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.561 2018/01/29 04:17:32 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.562 2018/01/30 08:15:47 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -183,6 +183,11 @@ int	wm_debug = WM_DEBUG_TX | WM_DEBUG_RX
 int wm_disable_msi = WM_DISABLE_MSI;
 int wm_disable_msix = WM_DISABLE_MSIX;
 
+#ifndef WM_WATCHDOG_TIMEOUT
+#define WM_WATCHDOG_TIMEOUT 5
+#endif
+static int wm_watchdog_timeout = WM_WATCHDOG_TIMEOUT;
+
 /*
  * Transmit descriptor list size.  Due to errata, we can only have
  * 256 hardware descriptors in the ring on < 82544, but we use 4096
@@ -363,6 +368,9 @@ struct wm_txqueue {
 
 	bool txq_stopping;
 
+	bool txq_watchdog;
+	time_t txq_lastsent;
+
 	uint32_t txq_packets;		/* for AIM */
 	uint32_t txq_bytes;		/* for AIM */
 #ifdef WM_EVENT_COUNTERS
@@ -680,8 +688,8 @@ static int	wm_detach(device_t, int);
 static bool	wm_suspend(device_t, const pmf_qual_t *);
 static bool	wm_resume(device_t, const pmf_qual_t *);
 static void	wm_watchdog(struct ifnet *);
-static void	wm_watchdog_txq(struct ifnet *, struct wm_txqueue *);
-static void	wm_watchdog_txq_locked(struct ifnet *, struct wm_txqueue *);
+static void	wm_watchdog_txq(struct ifnet *, struct wm_txqueue *, uint16_t *);
+static void	wm_watchdog_txq_locked(struct ifnet *, struct wm_txqueue *, uint16_t *);
 static void	wm_tick(void *);
 static int	wm_ifflags_cb(struct ethercom *);
 static int	wm_ioctl(struct ifnet *, u_long, void *);
@@ -2683,7 +2691,7 @@ alloc_retry:
 		if (wm_is_using_multiqueue(sc))
 			ifp->if_transmit = wm_transmit;
 	}
-	ifp->if_watchdog = wm_watchdog;
+	/* wm(4) doest not use ifp->if_watchdog, use wm_tick as watchdog. */
 	ifp->if_init = wm_init;
 	ifp->if_stop = wm_stop;
 	IFQ_SET_MAXLEN(&ifp->if_snd, max(WM_IFQUEUELEN, IFQ_MAXLEN));
@@ -2945,37 +2953,47 @@ wm_watchdog(struct ifnet *ifp)
 {
 	int qid;
 	struct wm_softc *sc = ifp->if_softc;
+	uint16_t hang_queue = 0; /* Max queue number of wm(4) is 82576's 16. */
 
 	for (qid = 0; qid < sc->sc_nqueues; qid++) {
 		struct wm_txqueue *txq = &sc->sc_queue[qid].wmq_txq;
 
-		wm_watchdog_txq(ifp, txq);
+		wm_watchdog_txq(ifp, txq, &hang_queue);
 	}
 
-	/* Reset the interface. */
-	(void) wm_init(ifp);
-
 	/*
-	 * There are still some upper layer processing which call
-	 * ifp->if_start(). e.g. ALTQ or one CPU system
+	 * IF any of queues hanged up, reset the interface.
 	 */
-	/* Try to get more packets going. */
-	ifp->if_start(ifp);
+	if (hang_queue != 0) {
+		(void) wm_init(ifp);
+
+		/*
+		 * There are still some upper layer processing which call
+		 * ifp->if_start(). e.g. ALTQ or one CPU system
+		 */
+		/* Try to get more packets going. */
+		ifp->if_start(ifp);
+	}
 }
 
+
 static void
-wm_watchdog_txq(struct ifnet *ifp, struct wm_txqueue *txq)
+wm_watchdog_txq(struct ifnet *ifp, struct wm_txqueue *txq, uint16_t *hang)
 {
 
 	mutex_enter(txq->txq_lock);
-	wm_watchdog_txq_locked(ifp, txq);
+	if (txq->txq_watchdog &&
+	time_uptime - txq->txq_lastsent > wm_watchdog_timeout) {
+		wm_watchdog_txq_locked(ifp, txq, hang);
+	}
 	mutex_exit(txq->txq_lock);
 }
 
 static void
-wm_watchdog_txq_locked(struct ifnet *ifp, struct wm_txqueue *txq)
+wm_watchdog_txq_locked(struct ifnet *ifp, struct wm_txqueue *txq, uint16_t *hang)
 {
 	struct wm_softc *sc = ifp->if_softc;
+	struct wm_queue *wmq = container_of(txq, struct wm_queue, wmq_txq);
 
 	KASSERT(mutex_owned(txq->txq_lock));
 
@@ -2984,6 +3002,8 @@ wm_watchdog_txq_locked(struct ifnet *ifp
 	 * before we report an error.
 	 */
 	wm_txeof(txq, UINT_MAX);
+	if (txq->txq_watchdog)
+		*hang |= __BIT(wmq->wmq_id);
 
 	if (txq->txq_free != WM_NTXDESC(txq)) {
 #ifdef WM_DEBUG
@@ -3044,8 +3064,13 @@ wm_tick(void *arg)
 
 	WM_CORE_LOCK(sc);
 
-	if (sc->sc_core_stopping)
-		goto out;
+	if (sc->sc_core_stopping) {
+		WM_CORE_UNLOCK(sc);
+#ifndef WM_MPSAFE
+		s

CVS commit: src/sys/dev/pci

2018-01-28 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Jan 29 04:17:32 UTC 2018

Modified Files:
src/sys/dev/pci: if_wm.c

Log Message:
Fix unmatched return type. The return value of wm_txeof() is not useded yet.


To generate a diff of this commit:
cvs rdiff -u -r1.560 -r1.561 src/sys/dev/pci/if_wm.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/dev/pci/if_wm.c
diff -u src/sys/dev/pci/if_wm.c:1.560 src/sys/dev/pci/if_wm.c:1.561
--- src/sys/dev/pci/if_wm.c:1.560	Mon Jan 29 03:42:30 2018
+++ src/sys/dev/pci/if_wm.c	Mon Jan 29 04:17:32 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_wm.c,v 1.560 2018/01/29 03:42:30 knakahara Exp $	*/
+/*	$NetBSD: if_wm.c,v 1.561 2018/01/29 04:17:32 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2001, 2002, 2003, 2004 Wasabi Systems, Inc.
@@ -83,7 +83,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.560 2018/01/29 03:42:30 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.561 2018/01/29 04:17:32 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -8044,7 +8044,6 @@ wm_txeof(struct wm_txqueue *txq, u_int l
 	struct wm_softc *sc = txq->txq_sc;
 	struct ifnet *ifp = &sc->sc_ethercom.ec_if;
 	struct wm_txsoft *txs;
-	bool processed = false;
 	int count = 0;
 	int i;
 	uint8_t status;
@@ -8085,7 +8084,6 @@ wm_txeof(struct wm_txqueue *txq, u_int l
 			break;
 		}
 
-		processed = true;
 		count++;
 		DPRINTF(WM_DEBUG_TX,
 		("%s: TX: job %d done: descs %d..%d\n",
@@ -8142,7 +8140,7 @@ wm_txeof(struct wm_txqueue *txq, u_int l
 	if (txq->txq_sfree == WM_TXQUEUELEN(txq))
 		ifp->if_timer = 0;
 
-	return processed;
+	return count;
 }
 
 static inline uint32_t



CVS commit: src/sys/dev/pci

2018-01-28 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Jan 29 03:42:30 UTC 2018

Modified Files:
src/sys/dev/pci: if_wm.c

Log Message:
Fix if_wm.c:r1.557 merge miss, sorry.


To generate a diff of this commit:
cvs rdiff -u -r1.559 -r1.560 src/sys/dev/pci/if_wm.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/dev/pci/if_wm.c
diff -u src/sys/dev/pci/if_wm.c:1.559 src/sys/dev/pci/if_wm.c:1.560
--- src/sys/dev/pci/if_wm.c:1.559	Fri Jan 26 16:25:28 2018
+++ src/sys/dev/pci/if_wm.c	Mon Jan 29 03:42:30 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_wm.c,v 1.559 2018/01/26 16:25:28 knakahara Exp $	*/
+/*	$NetBSD: if_wm.c,v 1.560 2018/01/29 03:42:30 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2001, 2002, 2003, 2004 Wasabi Systems, Inc.
@@ -83,7 +83,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.559 2018/01/26 16:25:28 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.560 2018/01/29 03:42:30 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -2983,9 +2983,7 @@ wm_watchdog_txq_locked(struct ifnet *ifp
 	 * Since we're using delayed interrupts, sweep up
 	 * before we report an error.
 	 */
-	mutex_enter(txq->txq_lock);
 	wm_txeof(txq, UINT_MAX);
-	mutex_exit(txq->txq_lock);
 
 	if (txq->txq_free != WM_NTXDESC(txq)) {
 #ifdef WM_DEBUG



CVS commit: src/sys/dev/pci

2018-01-26 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Jan 26 16:25:28 UTC 2018

Modified Files:
src/sys/dev/pci: if_wm.c

Log Message:
Fix 82574 MSI-X mode cannot receive packets after 82574 receives high rate 
traffic.

In short, 82574 MSI-X mode does not cause RXQ MSI-X vector when 82574's
phys FIFO overflows. I don't know why but 82574 causes not RXQ MSI-X vector
but OTHER MSI-X vector at the situation.
see:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?h=v4.15-rc9&id=4aea7a5c5e940c1723add439f4088844cd26196d

advised by msaitoh@n.o, thanks.


To generate a diff of this commit:
cvs rdiff -u -r1.558 -r1.559 src/sys/dev/pci/if_wm.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/dev/pci/if_wm.c
diff -u src/sys/dev/pci/if_wm.c:1.558 src/sys/dev/pci/if_wm.c:1.559
--- src/sys/dev/pci/if_wm.c:1.558	Sun Jan 21 04:07:49 2018
+++ src/sys/dev/pci/if_wm.c	Fri Jan 26 16:25:28 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_wm.c,v 1.558 2018/01/21 04:07:49 christos Exp $	*/
+/*	$NetBSD: if_wm.c,v 1.559 2018/01/26 16:25:28 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2001, 2002, 2003, 2004 Wasabi Systems, Inc.
@@ -83,7 +83,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.558 2018/01/21 04:07:49 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.559 2018/01/26 16:25:28 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -8962,8 +8962,14 @@ wm_txrxintr_enable(struct wm_queue *wmq)
 
 	wm_itrs_calculate(sc, wmq);
 
+	/*
+	 * ICR_OTHER which is disabled in wm_linkintr_msix() is enabled here.
+	 * There is no need to care about which of RXQ(0) and RXQ(1) enable
+	 * ICR_OTHER in first, because each RXQ/TXQ interrupt is disabled
+	 * while each wm_handle_queue(wmq) is runnig.
+	 */
 	if (sc->sc_type == WM_T_82574)
-		CSR_WRITE(sc, WMREG_IMS, ICR_TXQ(wmq->wmq_id) | ICR_RXQ(wmq->wmq_id));
+		CSR_WRITE(sc, WMREG_IMS, ICR_TXQ(wmq->wmq_id) | ICR_RXQ(wmq->wmq_id) | ICR_OTHER);
 	else if (sc->sc_type == WM_T_82575)
 		CSR_WRITE(sc, WMREG_EIMS, EITR_TX_QUEUE(wmq->wmq_id) | EITR_RX_QUEUE(wmq->wmq_id));
 	else
@@ -9060,24 +9066,59 @@ wm_linkintr_msix(void *arg)
 {
 	struct wm_softc *sc = arg;
 	uint32_t reg;
+	bool has_rxo;
 
 	DPRINTF(WM_DEBUG_LINK,
 	("%s: LINK: got link intr\n", device_xname(sc->sc_dev)));
 
 	reg = CSR_READ(sc, WMREG_ICR);
 	WM_CORE_LOCK(sc);
-	if ((sc->sc_core_stopping) || ((reg & ICR_LSC) == 0))
+	if (sc->sc_core_stopping)
 		goto out;
 
-	WM_EVCNT_INCR(&sc->sc_ev_linkintr);
-	wm_linkintr(sc, ICR_LSC);
+	if((reg & ICR_LSC) != 0) {
+		WM_EVCNT_INCR(&sc->sc_ev_linkintr);
+		wm_linkintr(sc, ICR_LSC);
+	}
+
+	/*
+	 * XXX 82574 MSI-X mode workaround
+	 *
+	 * 82574 MSI-X mode causes receive overrun(RXO) interrupt as ICR_OTHER
+	 * MSI-X vector, furthermore it does not cause neigher ICR_RXQ(0) nor
+	 * ICR_RXQ(1) vector. So, we generate ICR_RXQ(0) and ICR_RXQ(1)
+	 * interrupts by writing WMREG_ICS to process receive packets.
+	 */
+	if (sc->sc_type == WM_T_82574 && ((reg & ICR_RXO) != 0)) {
+#if defined(WM_DEBUG)
+		log(LOG_WARNING, "%s: Receive overrun\n",
+		device_xname(sc->sc_dev));
+#endif /* defined(WM_DEBUG) */
+
+		has_rxo = true;
+		/*
+		 * The RXO interrupt is very high rate when receive traffic is
+		 * high rate. We use polling mode for ICR_OTHER like Tx/Rx
+		 * interrupts. ICR_OTHER will be enabled at the end of
+		 * wm_txrxintr_msix() which is kicked by both ICR_RXQ(0) and
+		 * ICR_RXQ(1) interrupts.
+		 */
+		CSR_WRITE(sc, WMREG_IMC, ICR_OTHER);
+
+		CSR_WRITE(sc, WMREG_ICS, ICR_RXQ(0) | ICR_RXQ(1));
+	}
+
+
 
 out:
 	WM_CORE_UNLOCK(sc);
 	
-	if (sc->sc_type == WM_T_82574)
-		CSR_WRITE(sc, WMREG_IMS, ICR_OTHER | ICR_LSC);
-	else if (sc->sc_type == WM_T_82575)
+	if (sc->sc_type == WM_T_82574) {
+		if (!has_rxo)
+			CSR_WRITE(sc, WMREG_IMS, ICR_OTHER | ICR_LSC);
+		else
+			CSR_WRITE(sc, WMREG_IMS, ICR_LSC);
+	} else if (sc->sc_type == WM_T_82575)
 		CSR_WRITE(sc, WMREG_EIMS, EITR_OTHER);
 	else
 		CSR_WRITE(sc, WMREG_EIMS, 1 << sc->sc_link_intr_idx);



CVS commit: src/share/man/man4

2018-01-18 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Jan 18 09:38:15 UTC 2018

Modified Files:
src/share/man/man4: wm.4

Log Message:
add WM_TX_PROCESS_LIMIT_DEFAULT and WM_TX_INTR_PROCESS_LIMIT_DEFAULT man.


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/share/man/man4/wm.4

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/share/man/man4/wm.4
diff -u src/share/man/man4/wm.4:1.36 src/share/man/man4/wm.4:1.37
--- src/share/man/man4/wm.4:1.36	Thu Apr 13 10:37:36 2017
+++ src/share/man/man4/wm.4	Thu Jan 18 09:38:15 2018
@@ -1,4 +1,4 @@
-.\"	$NetBSD: wm.4,v 1.36 2017/04/13 10:37:36 knakahara Exp $
+.\"	$NetBSD: wm.4,v 1.37 2018/01/18 09:38:15 knakahara Exp $
 .\"
 .\" Copyright 2002, 2003 Wasabi Systems, Inc.
 .\" All rights reserved.
@@ -33,7 +33,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd March 22, 2017
+.Dd January 18, 2018
 .Dt WM 4
 .Os
 .Sh NAME
@@ -182,6 +182,8 @@ The value range is from zero to
 The default value is 100.
 When you increase this value, both the receive latency and
 the receive throughput will increase.
+.It Dv WM_TX_PROCESS_LIMIT_DEFAULT
+Transmit side of WM_RX_PROCESS_LIMIT_DEFAULT.
 .It Dv WM_RX_INTR_PROCESS_LIMIT_DEFAULT
 The maximum number of received packets processed in each
 hardware interrupt context.
@@ -191,6 +193,8 @@ The value range is from zero to
 The default value is 0.
 When you increase this value, both the receive latency and
 the receive throughput will decrease.
+.It Dv WM_TX_INTR_PROCESS_LIMIT_DEFAULT
+Transmit side of WM_RX_INTR_PROCESS_LIMIT_DEFAULT.
 .It Dv WM_EVENT_COUNTERS
 Enable many event counters such as each Tx drop counter and Rx interrupt
 counter.



CVS commit: src/sys/dev/pci

2018-01-18 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Jan 18 09:36:26 UTC 2018

Modified Files:
src/sys/dev/pci: if_wm.c

Log Message:
wm_txeof() can limit the loop count the same as wm_rxeof() now.


To generate a diff of this commit:
cvs rdiff -u -r1.556 -r1.557 src/sys/dev/pci/if_wm.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/dev/pci/if_wm.c
diff -u src/sys/dev/pci/if_wm.c:1.556 src/sys/dev/pci/if_wm.c:1.557
--- src/sys/dev/pci/if_wm.c:1.556	Wed Jan 17 02:16:07 2018
+++ src/sys/dev/pci/if_wm.c	Thu Jan 18 09:36:26 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_wm.c,v 1.556 2018/01/17 02:16:07 knakahara Exp $	*/
+/*	$NetBSD: if_wm.c,v 1.557 2018/01/18 09:36:26 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2001, 2002, 2003, 2004 Wasabi Systems, Inc.
@@ -83,7 +83,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.556 2018/01/17 02:16:07 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.557 2018/01/18 09:36:26 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -213,6 +213,13 @@ int wm_disable_msix = WM_DISABLE_MSIX;
 
 #define	WM_TXINTERQSIZE		256
 
+#ifndef WM_TX_PROCESS_LIMIT_DEFAULT
+#define	WM_TX_PROCESS_LIMIT_DEFAULT		100U
+#endif
+#ifndef WM_TX_INTR_PROCESS_LIMIT_DEFAULT
+#define	WM_TX_INTR_PROCESS_LIMIT_DEFAULT	0U
+#endif
+
 /*
  * Receive descriptor list size.  We have one Rx buffer for normal
  * sized packets.  Jumbo packets consume 5 Rx buffers for a full-sized
@@ -519,6 +526,8 @@ struct wm_softc {
 
 	int sc_nqueues;
 	struct wm_queue *sc_queue;
+	u_int sc_tx_process_limit;	/* Tx processing repeat limit in softint */
+	u_int sc_tx_intr_process_limit;	/* Tx processing repeat limit in H/W intr */
 	u_int sc_rx_process_limit;	/* Rx processing repeat limit in softint */
 	u_int sc_rx_intr_process_limit;	/* Rx processing repeat limit in H/W intr */
 
@@ -758,7 +767,7 @@ static void	wm_nq_send_common_locked(str
 static void	wm_deferred_start_locked(struct wm_txqueue *);
 static void	wm_handle_queue(void *);
 /* Interrupt */
-static int	wm_txeof(struct wm_softc *, struct wm_txqueue *);
+static int	wm_txeof(struct wm_txqueue *, u_int);
 static void	wm_rxeof(struct wm_rxqueue *, u_int);
 static void	wm_linkintr_gmii(struct wm_softc *, uint32_t);
 static void	wm_linkintr_tbi(struct wm_softc *, uint32_t);
@@ -2764,6 +2773,8 @@ alloc_retry:
 		ifp->if_capabilities |= IFCAP_TSOv6;
 	}
 
+	sc->sc_tx_process_limit = WM_TX_PROCESS_LIMIT_DEFAULT;
+	sc->sc_tx_intr_process_limit = WM_TX_INTR_PROCESS_LIMIT_DEFAULT;
 	sc->sc_rx_process_limit = WM_RX_PROCESS_LIMIT_DEFAULT;
 	sc->sc_rx_intr_process_limit = WM_RX_INTR_PROCESS_LIMIT_DEFAULT;
 
@@ -2972,7 +2983,9 @@ wm_watchdog_txq_locked(struct ifnet *ifp
 	 * Since we're using delayed interrupts, sweep up
 	 * before we report an error.
 	 */
-	wm_txeof(sc, txq);
+	mutex_enter(txq->txq_lock);
+	wm_txeof(txq, UINT_MAX);
+	mutex_exit(txq->txq_lock);
 
 	if (txq->txq_free != WM_NTXDESC(txq)) {
 #ifdef WM_DEBUG
@@ -7140,7 +7153,7 @@ wm_send_common_locked(struct ifnet *ifp,
 
 		/* Get a work queue entry. */
 		if (txq->txq_sfree < WM_TXQUEUE_GC(txq)) {
-			wm_txeof(sc, txq);
+			wm_txeof(txq, UINT_MAX);
 			if (txq->txq_sfree == 0) {
 DPRINTF(WM_DEBUG_TX,
 ("%s: TX: no free job descriptors\n",
@@ -7739,7 +7752,7 @@ wm_nq_send_common_locked(struct ifnet *i
 
 		/* Get a work queue entry. */
 		if (txq->txq_sfree < WM_TXQUEUE_GC(txq)) {
-			wm_txeof(sc, txq);
+			wm_txeof(txq, UINT_MAX);
 			if (txq->txq_sfree == 0) {
 DPRINTF(WM_DEBUG_TX,
 ("%s: TX: no free job descriptors\n",
@@ -8028,8 +8041,9 @@ wm_deferred_start_locked(struct wm_txque
  *	Helper; handle transmit interrupts.
  */
 static int
-wm_txeof(struct wm_softc *sc, struct wm_txqueue *txq)
+wm_txeof(struct wm_txqueue *txq, u_int limit)
 {
+	struct wm_softc *sc = txq->txq_sc;
 	struct ifnet *ifp = &sc->sc_ethercom.ec_if;
 	struct wm_txsoft *txs;
 	bool processed = false;
@@ -8054,6 +8068,9 @@ wm_txeof(struct wm_softc *sc, struct wm_
 	 */
 	for (i = txq->txq_sdirty; txq->txq_sfree != WM_TXQUEUELEN(txq);
 	 i = WM_NEXTTXS(txq, i), txq->txq_sfree++) {
+		if (limit-- == 0)
+			break;
+
 		txs = &txq->txq_soft[i];
 
 		DPRINTF(WM_DEBUG_TX, ("%s: TX: checking job %d\n",
@@ -8890,7 +8907,7 @@ wm_intr_legacy(void *arg)
 			WM_Q_EVCNT_INCR(txq, txdw);
 		}
 #endif
-		wm_txeof(sc, txq);
+		wm_txeof(txq, UINT_MAX);
 
 		mutex_exit(txq->txq_lock);
 		WM_CORE_LOCK(sc);
@@ -8960,7 +8977,8 @@ wm_txrxintr_msix(void *arg)
 	struct wm_txqueue *txq = &wmq->wmq_txq;
 	struct wm_rxqueue *rxq = &wmq->wmq_rxq;
 	struct wm_softc *sc = txq->txq_sc;
-	u_int limit = sc->sc_rx_intr_process_limit;
+	u_int txlimit = sc->sc_tx_intr_process_limit;
+	u_int rxlimit = sc->sc_rx_intr_process_limit;
 
 	KASSERT(wmq->wmq_intr_idx == wmq->wmq_id);
 
@@ -8977,7 +8995,7 @@ wm_txrxintr_msix(void *arg)
 	}
 
 	WM_Q_EVCNT_INCR(txq, txdw);
-	wm_txeof(sc, txq);
+	wm_txeof(txq, txli

CVS commit: src/sys/dev/pci

2018-01-16 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Jan 17 02:16:07 UTC 2018

Modified Files:
src/sys/dev/pci: if_wm.c

Log Message:
Fix duplicated "rxintr" evcnt counting. Pointed out by ozaki-r@n.o, thanks.


To generate a diff of this commit:
cvs rdiff -u -r1.555 -r1.556 src/sys/dev/pci/if_wm.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/dev/pci/if_wm.c
diff -u src/sys/dev/pci/if_wm.c:1.555 src/sys/dev/pci/if_wm.c:1.556
--- src/sys/dev/pci/if_wm.c:1.555	Tue Jan 16 07:23:13 2018
+++ src/sys/dev/pci/if_wm.c	Wed Jan 17 02:16:07 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_wm.c,v 1.555 2018/01/16 07:23:13 knakahara Exp $	*/
+/*	$NetBSD: if_wm.c,v 1.556 2018/01/17 02:16:07 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2001, 2002, 2003, 2004 Wasabi Systems, Inc.
@@ -83,7 +83,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.555 2018/01/16 07:23:13 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.556 2018/01/17 02:16:07 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -417,6 +417,7 @@ struct wm_rxqueue {
 	uint32_t rxq_bytes;		/* for AIM */
 #ifdef WM_EVENT_COUNTERS
 	WM_Q_EVCNT_DEFINE(rxq, rxintr);		/* Rx interrupts */
+	WM_Q_EVCNT_DEFINE(rxq, rxdefer);	/* Rx deferred processing */
 
 	WM_Q_EVCNT_DEFINE(rxq, rxipsum);	/* IP checksums checked in-bound */
 	WM_Q_EVCNT_DEFINE(rxq, rxtusum);	/* TCP/UDP cksums checked in-bound */
@@ -6456,6 +6457,7 @@ wm_alloc_txrx_queues(struct wm_softc *sc
 		xname = device_xname(sc->sc_dev);
 
 		WM_Q_INTR_EVCNT_ATTACH(rxq, rxintr, rxq, i, xname);
+		WM_Q_INTR_EVCNT_ATTACH(rxq, rxdefer, rxq, i, xname);
 
 		WM_Q_INTR_EVCNT_ATTACH(rxq, rxipsum, rxq, i, xname);
 		WM_Q_INTR_EVCNT_ATTACH(rxq, rxtusum, rxq, i, xname);
@@ -6506,6 +6508,7 @@ wm_free_txrx_queues(struct wm_softc *sc)
 
 #ifdef WM_EVENT_COUNTERS
 		WM_Q_EVCNT_DETACH(rxq, rxintr, rxq, i);
+		WM_Q_EVCNT_DETACH(rxq, rxdefer, rxq, i);
 		WM_Q_EVCNT_DETACH(rxq, rxipsum, rxq, i);
 		WM_Q_EVCNT_DETACH(rxq, rxtusum, rxq, i);
 #endif /* WM_EVENT_COUNTERS */
@@ -9021,7 +9024,7 @@ wm_handle_queue(void *arg)
 		mutex_exit(rxq->rxq_lock);
 		return;
 	}
-	WM_Q_EVCNT_INCR(rxq, rxintr);
+	WM_Q_EVCNT_INCR(rxq, rxdefer);
 	wm_rxeof(rxq, limit);
 	mutex_exit(rxq->rxq_lock);
 



CVS commit: src/sys

2018-01-15 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Tue Jan 16 07:34:12 UTC 2018

Modified Files:
src/sys/modules/if_agr: Makefile
src/sys/net/agr: if_agr.c

Log Message:
Fix agr(4) module build. Reviewed by pgoyette@n.o, thanks.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/modules/if_agr/Makefile
cvs rdiff -u -r1.44 -r1.45 src/sys/net/agr/if_agr.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/modules/if_agr/Makefile
diff -u src/sys/modules/if_agr/Makefile:1.1 src/sys/modules/if_agr/Makefile:1.2
--- src/sys/modules/if_agr/Makefile:1.1	Sun Aug  7 14:27:38 2016
+++ src/sys/modules/if_agr/Makefile	Tue Jan 16 07:34:12 2018
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.1 2016/08/07 14:27:38 christos Exp $
+# $NetBSD: Makefile,v 1.2 2018/01/16 07:34:12 knakahara Exp $
 
 .include "../Makefile.inc"
 
@@ -25,6 +25,6 @@ if_agrsoftc.c \
 if_agrsubr.c \
 if_agrtimer.c 
 
-CPPFLAGS+=	-DINET
+CPPFLAGS+=	-DINET -DNVLAN=1
 
 .include 

Index: src/sys/net/agr/if_agr.c
diff -u src/sys/net/agr/if_agr.c:1.44 src/sys/net/agr/if_agr.c:1.45
--- src/sys/net/agr/if_agr.c:1.44	Mon Jan 15 11:16:04 2018
+++ src/sys/net/agr/if_agr.c	Tue Jan 16 07:34:12 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_agr.c,v 1.44 2018/01/15 11:16:04 maxv Exp $	*/
+/*	$NetBSD: if_agr.c,v 1.45 2018/01/16 07:34:12 knakahara Exp $	*/
 
 /*-
  * Copyright (c)2005 YAMAMOTO Takashi,
@@ -27,13 +27,12 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_agr.c,v 1.44 2018/01/15 11:16:04 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_agr.c,v 1.45 2018/01/16 07:34:12 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
-#endif
-
 #include "vlan.h"
+#endif
 
 #include 
 #include 
@@ -1168,4 +1167,4 @@ agrport_config_promisc(struct agr_port *
  */
 #include 
 
-IF_MODULE(MODULE_CLASS_DRIVER, agr, "")
+IF_MODULE(MODULE_CLASS_DRIVER, agr, "if_vlan")



CVS commit: src/sys/dev/pci

2018-01-15 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Tue Jan 16 07:23:13 UTC 2018

Modified Files:
src/sys/dev/pci: if_wm.c

Log Message:
Fix wm_watchdog_txq() lock region.

Not only wm_txeof() but also wm_watchdog_txq() itself requires txq_lock
as it reads Tx descriptor management variables such as "txq_free".

There is almost no influence on performance.


To generate a diff of this commit:
cvs rdiff -u -r1.554 -r1.555 src/sys/dev/pci/if_wm.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/dev/pci/if_wm.c
diff -u src/sys/dev/pci/if_wm.c:1.554 src/sys/dev/pci/if_wm.c:1.555
--- src/sys/dev/pci/if_wm.c:1.554	Mon Jan 15 04:25:48 2018
+++ src/sys/dev/pci/if_wm.c	Tue Jan 16 07:23:13 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_wm.c,v 1.554 2018/01/15 04:25:48 knakahara Exp $	*/
+/*	$NetBSD: if_wm.c,v 1.555 2018/01/16 07:23:13 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2001, 2002, 2003, 2004 Wasabi Systems, Inc.
@@ -83,7 +83,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.554 2018/01/15 04:25:48 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.555 2018/01/16 07:23:13 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -671,6 +671,7 @@ static bool	wm_suspend(device_t, const p
 static bool	wm_resume(device_t, const pmf_qual_t *);
 static void	wm_watchdog(struct ifnet *);
 static void	wm_watchdog_txq(struct ifnet *, struct wm_txqueue *);
+static void	wm_watchdog_txq_locked(struct ifnet *, struct wm_txqueue *);
 static void	wm_tick(void *);
 static int	wm_ifflags_cb(struct ethercom *);
 static int	wm_ioctl(struct ifnet *, u_long, void *);
@@ -2953,15 +2954,24 @@ wm_watchdog(struct ifnet *ifp)
 static void
 wm_watchdog_txq(struct ifnet *ifp, struct wm_txqueue *txq)
 {
+
+	mutex_enter(txq->txq_lock);
+	wm_watchdog_txq_locked(ifp, txq);
+	mutex_exit(txq->txq_lock);
+}
+
+static void
+wm_watchdog_txq_locked(struct ifnet *ifp, struct wm_txqueue *txq)
+{
 	struct wm_softc *sc = ifp->if_softc;
 
+	KASSERT(mutex_owned(txq->txq_lock));
+
 	/*
 	 * Since we're using delayed interrupts, sweep up
 	 * before we report an error.
 	 */
-	mutex_enter(txq->txq_lock);
 	wm_txeof(sc, txq);
-	mutex_exit(txq->txq_lock);
 
 	if (txq->txq_free != WM_NTXDESC(txq)) {
 #ifdef WM_DEBUG



CVS commit: src/sys/dev/pci

2018-01-14 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Jan 15 04:25:48 UTC 2018

Modified Files:
src/sys/dev/pci: if_wm.c

Log Message:
improve comments


To generate a diff of this commit:
cvs rdiff -u -r1.553 -r1.554 src/sys/dev/pci/if_wm.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/dev/pci/if_wm.c
diff -u src/sys/dev/pci/if_wm.c:1.553 src/sys/dev/pci/if_wm.c:1.554
--- src/sys/dev/pci/if_wm.c:1.553	Mon Jan 15 04:09:58 2018
+++ src/sys/dev/pci/if_wm.c	Mon Jan 15 04:25:48 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_wm.c,v 1.553 2018/01/15 04:09:58 knakahara Exp $	*/
+/*	$NetBSD: if_wm.c,v 1.554 2018/01/15 04:25:48 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2001, 2002, 2003, 2004 Wasabi Systems, Inc.
@@ -83,7 +83,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.553 2018/01/15 04:09:58 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.554 2018/01/15 04:25:48 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -4210,6 +4210,10 @@ wm_reset_phy(struct wm_softc *sc)
 	wm_phy_post_reset(sc);
 }
 
+/*
+ * Only used by WM_T_PCH_SPT which does not use multiqueue,
+ * so it is enough to check sc->sc_queue[0] only.
+ */
 static void
 wm_flush_desc_rings(struct wm_softc *sc)
 {



CVS commit: src/sys/dev/pci

2018-01-14 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Jan 15 04:09:58 UTC 2018

Modified Files:
src/sys/dev/pci: if_wm.c

Log Message:
Fix legacy Tx descriptors printing when WM_DEBUG is enabled.


To generate a diff of this commit:
cvs rdiff -u -r1.552 -r1.553 src/sys/dev/pci/if_wm.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/dev/pci/if_wm.c
diff -u src/sys/dev/pci/if_wm.c:1.552 src/sys/dev/pci/if_wm.c:1.553
--- src/sys/dev/pci/if_wm.c:1.552	Thu Jan  4 09:43:27 2018
+++ src/sys/dev/pci/if_wm.c	Mon Jan 15 04:09:58 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_wm.c,v 1.552 2018/01/04 09:43:27 msaitoh Exp $	*/
+/*	$NetBSD: if_wm.c,v 1.553 2018/01/15 04:09:58 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2001, 2002, 2003, 2004 Wasabi Systems, Inc.
@@ -83,7 +83,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.552 2018/01/04 09:43:27 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.553 2018/01/15 04:09:58 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -2981,11 +2981,22 @@ wm_watchdog_txq(struct ifnet *ifp, struc
 			i, txs->txs_firstdesc, txs->txs_lastdesc);
 		for (j = txs->txs_firstdesc; ;
 			j = WM_NEXTTX(txq, j)) {
-			printf("\tdesc %d: 0x%" PRIx64 "\n", j,
-			txq->txq_nq_descs[j].nqtx_data.nqtxd_addr);
-			printf("\t %#08x%08x\n",
-			txq->txq_nq_descs[j].nqtx_data.nqtxd_fields,
-			txq->txq_nq_descs[j].nqtx_data.nqtxd_cmdlen);
+			if ((sc->sc_flags & WM_F_NEWQUEUE) != 0) {
+printf("\tdesc %d: 0x%" PRIx64 "\n", j,
+	txq->txq_nq_descs[j].nqtx_data.nqtxd_addr);
+printf("\t %#08x%08x\n",
+	txq->txq_nq_descs[j].nqtx_data.nqtxd_fields,
+	txq->txq_nq_descs[j].nqtx_data.nqtxd_cmdlen);
+			} else {
+printf("\tdesc %d: 0x%" PRIx64 "\n", j,
+	(uint64_t)txq->txq_descs[j].wtx_addr.wa_high << 32 |
+	txq->txq_descs[j].wtx_addr.wa_low);
+printf("\t %#04x%02x%02x%08x\n",
+	txq->txq_descs[j].wtx_fields.wtxu_vlan,
+	txq->txq_descs[j].wtx_fields.wtxu_options,
+	txq->txq_descs[j].wtx_fields.wtxu_status,
+	txq->txq_descs[j].wtx_cmdlen);
+			}
 			if (j == txs->txs_lastdesc)
 break;
 			}



CVS commit: src/sys/net

2018-01-14 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Jan 15 02:39:53 UTC 2018

Modified Files:
src/sys/net: if_ipsec.c

Log Message:
Fix PR kern/52920. Pointed out by David Binderman, thanks.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/net/if_ipsec.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/net/if_ipsec.c
diff -u src/sys/net/if_ipsec.c:1.1 src/sys/net/if_ipsec.c:1.2
--- src/sys/net/if_ipsec.c:1.1	Wed Jan 10 10:56:30 2018
+++ src/sys/net/if_ipsec.c	Mon Jan 15 02:39:53 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ipsec.c,v 1.1 2018/01/10 10:56:30 knakahara Exp $  */
+/*	$NetBSD: if_ipsec.c,v 1.2 2018/01/15 02:39:53 knakahara Exp $  */
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_ipsec.c,v 1.1 2018/01/10 10:56:30 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ipsec.c,v 1.2 2018/01/15 02:39:53 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1214,7 +1214,7 @@ if_ipsec_share_sp(struct ipsec_variant *
 	struct psref psref;
 
 	KASSERT(encap_lock_held());
-	KASSERT(var->iv_pdst != NULL && var->iv_pdst != NULL);
+	KASSERT(var->iv_psrc != NULL && var->iv_pdst != NULL);
 
 	mutex_enter(&ipsec_softcs.lock);
 	LIST_FOREACH(sc2, &ipsec_softcs.list, ipsec_list) {



CVS commit: src/share/man/man4

2018-01-10 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Jan 11 06:38:05 UTC 2018

Modified Files:
src/share/man/man4: ipsecif.4

Log Message:
Improve ipsecif.4. Default port ipsec(4) NAT-T is tested now.

pointed out by wiz@n.o and suggested by ozaki-r@n.o, thanks.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/share/man/man4/ipsecif.4

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/share/man/man4/ipsecif.4
diff -u src/share/man/man4/ipsecif.4:1.2 src/share/man/man4/ipsecif.4:1.3
--- src/share/man/man4/ipsecif.4:1.2	Wed Jan 10 12:18:22 2018
+++ src/share/man/man4/ipsecif.4	Thu Jan 11 06:38:05 2018
@@ -1,4 +1,4 @@
-.\"	$NetBSD: ipsecif.4,v 1.2 2018/01/10 12:18:22 wiz Exp $
+.\"	$NetBSD: ipsecif.4,v 1.3 2018/01/11 06:38:05 knakahara Exp $
 .\"
 .\" Copyright (C) 2017 Internet Initiative Japan Inc.
 .\" All rights reserved.
@@ -27,7 +27,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd December 22, 2017
+.Dd January 11, 2018
 .Dt IPSECIF 4
 .Os
 .Sh NAME
@@ -38,24 +38,51 @@
 .Sh DESCRIPTION
 The
 .Nm
-interface is similar to
+interface is targeted for route-based VPNs. It can tunnel IPv4 and
+IPv6 traffic over either IPv4 or IPv6 and secure it with ESP.
+.Pp
+.Nm
+interfaces are dynamically created and destroyed with the
+.Xr ifconfig 8
+.Cm create
+and
+.Cm destroy
+subcommands. The administrator must configure
+.Nm
+.Cm
+tunnel
+endpoint addresses. These addresses will be used for the outer IP
+header of ESP packets. The administrator also configures the protocol
+and addresses for the inner IP header with
+.Xr ifconfig 8
+.Cm inet
+or
+.Cm inet6
+subcommands, and modify the routing table to route the packets through
+the
+.Nm
+interface.
+.Pp
+The packet processing is similar to
 .Xr gif 4
 over
 .Xr ipsec 4
-transport mode.
+transport mode, however their security policy managements are different.
 .Xr gif 4
 over
 .Xr ipsec 4
-transport mode is managed by userland programs.
-In contrast,
+transport mode expects for userland programs to managed its
+security policies. In contrast,
 .Nm
-manages its security policies by itself, that is, when user sets up a
+manages its security policies by itself, that is, when the administrator
+sets up a
 .Nm
 tunnel source and destination address pair, the related security policies
 are created automatically in the kernel.
 Therefore, the security policies of
 .Nm
 are added/deleted atomically.
+.Pp
 It also means that
 .Nm
 ensures that both the in and out security policy pairs exist, that is,
@@ -66,10 +93,10 @@ policy pair exists.
 There are four security policies generated by
 .Nm ,
 that is, one in and out pair for IPv4 and IPv6 each.
-This
+These security policies equal to the following
 .Xr ipsec.conf 5
-has the same meaning as these security policies:
-.Bd -literal
+configuration where src and dst are IP addresses specified to the tunnel:
+.Bd -literal -offset indent
 spdadd "src" "dst" ipv4 -P out ipsec esp/transport//unique;
 spdadd "dst" "src" ipv4 -P in ipsec esp/transport//unique;
 spdadd "src" "dst" ipv6 -P out ipsec esp/transport//unique;
@@ -89,16 +116,23 @@ with the
 .Fl u
 option which sets a security policy's unique id.
 .Pp
-Some if_flags change
+Some
+.Xr ifconfig 8
+parameters change
 .Nm Ap s
 behaviour.
-IFF_LINK0 can enable Network Address Translator traversal,
-IFF_LINK1 can enable ECN friendly mode like
+link0 can enable NAT-Traversal,
+link1 can enable ECN friendly mode like
 .Xr gif 4 ,
-and IFF_LINK2 can enable forwarding inner IPv6 packets.
-Only IFF_LINK2 is set by default.
+and link2 can enable forwarding inner IPv6 packets.
+Only link2 is set by default.
 If you use only IPv4 packets as inner packets, you would want to
-unset IFF_LINK2 to reduce security associates for IPv6 packets.
+do
+.Bd -literal -offset indent
+ifconfig ipsec0 -link2
+.Ed
+.Pp
+to reduce security associates for IPv6 packets.
 .Sh EXAMPLES
 Configuration example:
 .Bd -literal
@@ -139,6 +173,7 @@ start IKE daemon or set security associa
 .Xr inet6 4 ,
 .Xr ipsec 4 ,
 .Xr ifconfig 8 ,
+.Xr racoon 8 ,
 .Xr setkey 8
 .Sh HISTORY
 The
@@ -150,4 +185,4 @@ Currently, the
 .Nm
 interface supports the ESP protocol only.
 .Nm
-does not support Network Address Translator traversal (NAT-T).
+supports default port number (4500) only for NAT-Traversal.



CVS commit: src/sys

2018-01-10 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Jan 10 11:13:26 UTC 2018

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

Log Message:
apply in{,6}_tunnel_validate() to gif(4).


To generate a diff of this commit:
cvs rdiff -u -r1.91 -r1.92 src/sys/netinet/in_gif.c
cvs rdiff -u -r1.89 -r1.90 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/netinet/in_gif.c
diff -u src/sys/netinet/in_gif.c:1.91 src/sys/netinet/in_gif.c:1.92
--- src/sys/netinet/in_gif.c:1.91	Mon Nov 27 05:05:51 2017
+++ src/sys/netinet/in_gif.c	Wed Jan 10 11:13:26 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: in_gif.c,v 1.91 2017/11/27 05:05:51 knakahara Exp $	*/
+/*	$NetBSD: in_gif.c,v 1.92 2018/01/10 11:13:26 knakahara Exp $	*/
 /*	$KAME: in_gif.c,v 1.66 2001/07/29 04:46:09 itojun Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in_gif.c,v 1.91 2017/11/27 05:05:51 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in_gif.c,v 1.92 2018/01/10 11:13:26 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -303,36 +303,15 @@ static int
 gif_validate4(const struct ip *ip, struct gif_variant *var, struct ifnet *ifp)
 {
 	struct sockaddr_in *src, *dst;
-	struct in_ifaddr *ia4;
-	int s;
+	int ret;
 
 	src = satosin(var->gv_psrc);
 	dst = satosin(var->gv_pdst);
 
-	/* check for address match */
-	if (src->sin_addr.s_addr != ip->ip_dst.s_addr ||
-	dst->sin_addr.s_addr != ip->ip_src.s_addr)
+	ret = in_tunnel_validate(ip, src->sin_addr, dst->sin_addr);
+	if (ret == 0)
 		return 0;
 
-	/* martian filters on outer source - NOT done in ip_input! */
-	if (IN_MULTICAST(ip->ip_src.s_addr))
-		return 0;
-	switch ((ntohl(ip->ip_src.s_addr) & 0xff00) >> 24) {
-	case 0: case 127: case 255:
-		return 0;
-	}
-	/* reject packets with broadcast on source */
-	s = pserialize_read_enter();
-	IN_ADDRLIST_READER_FOREACH(ia4) {
-		if ((ia4->ia_ifa.ifa_ifp->if_flags & IFF_BROADCAST) == 0)
-			continue;
-		if (ip->ip_src.s_addr == ia4->ia_broadaddr.sin_addr.s_addr) {
-			pserialize_read_exit(s);
-			return 0;
-		}
-	}
-	pserialize_read_exit(s);
-
 	/* ingress filters on outer source */
 	if ((var->gv_softc->gif_if.if_flags & IFF_LINK2) == 0 && ifp) {
 		union {
@@ -357,7 +336,7 @@ gif_validate4(const struct ip *ip, struc
 		rt_unref(rt);
 	}
 
-	return 32 * 2;
+	return ret;
 }
 
 #ifdef GIF_ENCAPCHECK

Index: src/sys/netinet6/in6_gif.c
diff -u src/sys/netinet6/in6_gif.c:1.89 src/sys/netinet6/in6_gif.c:1.90
--- src/sys/netinet6/in6_gif.c:1.89	Mon Nov 27 05:05:51 2017
+++ src/sys/netinet6/in6_gif.c	Wed Jan 10 11:13:26 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: in6_gif.c,v 1.89 2017/11/27 05:05:51 knakahara Exp $	*/
+/*	$NetBSD: in6_gif.c,v 1.90 2018/01/10 11:13:26 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.89 2017/11/27 05:05:51 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6_gif.c,v 1.90 2018/01/10 11:13:26 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -322,17 +322,15 @@ gif_validate6(const struct ip6_hdr *ip6,
 	struct ifnet *ifp)
 {
 	const struct sockaddr_in6 *src, *dst;
+	int ret;
 
 	src = satosin6(var->gv_psrc);
 	dst = satosin6(var->gv_pdst);
 
-	/* check for address match */
-	if (!IN6_ARE_ADDR_EQUAL(&src->sin6_addr, &ip6->ip6_dst) ||
-	!IN6_ARE_ADDR_EQUAL(&dst->sin6_addr, &ip6->ip6_src))
+	ret = in6_tunnel_validate(ip6, &src->sin6_addr, &dst->sin6_addr);
+	if (ret == 0)
 		return 0;
 
-	/* martian filters on outer source - done in ip6_input */
-
 	/* ingress filters on outer source */
 	if ((var->gv_softc->gif_if.if_flags & IFF_LINK2) == 0 && ifp) {
 		union {
@@ -359,7 +357,7 @@ gif_validate6(const struct ip6_hdr *ip6,
 		rt_unref(rt);
 	}
 
-	return 128 * 2;
+	return ret;
 }
 
 #ifdef GIF_ENCAPCHECK



CVS commit: src/sys/arch/amd64/conf

2018-01-10 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Jan 10 11:11:20 UTC 2018

Modified Files:
src/sys/arch/amd64/conf: ALL GENERIC

Log Message:
add ipsec(4) interface to amd64/GENERIC and amd64/ALL configs.


To generate a diff of this commit:
cvs rdiff -u -r1.76 -r1.77 src/sys/arch/amd64/conf/ALL
cvs rdiff -u -r1.479 -r1.480 src/sys/arch/amd64/conf/GENERIC

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/amd64/conf/ALL
diff -u src/sys/arch/amd64/conf/ALL:1.76 src/sys/arch/amd64/conf/ALL:1.77
--- src/sys/arch/amd64/conf/ALL:1.76	Tue Jan  9 03:31:12 2018
+++ src/sys/arch/amd64/conf/ALL	Wed Jan 10 11:11:20 2018
@@ -1,4 +1,4 @@
-# $NetBSD: ALL,v 1.76 2018/01/09 03:31:12 christos Exp $
+# $NetBSD: ALL,v 1.77 2018/01/10 11:11:20 knakahara Exp $
 # From NetBSD: GENERIC,v 1.787 2006/10/01 18:37:54 bouyer Exp
 #
 # ALL machine description file
@@ -17,7 +17,7 @@ include 	"arch/amd64/conf/std.amd64"
 
 options 	INCLUDE_CONFIG_FILE	# embed config file in kernel binary
 
-#ident		"ALL-$Revision: 1.76 $"
+#ident		"ALL-$Revision: 1.77 $"
 
 maxusers	64		# estimated number of users
 
@@ -1610,6 +1610,7 @@ pseudo-device	tap			# virtual Ethernet
 pseudo-device	tun			# network tunneling over tty
 pseudo-device	gre			# generic L3 over IP tunnel
 pseudo-device	gif			# IPv[46] over IPv[46] tunnel (RFC 1933)
+pseudo-device	ipsecif			# tunnel interface for routing based ipsec
 pseudo-device	faith			# IPv[46] tcp relay translation i/f
 pseudo-device	stf			# 6to4 IPv6 over IPv4 encapsulation
 pseudo-device	vlan			# IEEE 802.1q encapsulation

Index: src/sys/arch/amd64/conf/GENERIC
diff -u src/sys/arch/amd64/conf/GENERIC:1.479 src/sys/arch/amd64/conf/GENERIC:1.480
--- src/sys/arch/amd64/conf/GENERIC:1.479	Tue Jan  9 03:31:12 2018
+++ src/sys/arch/amd64/conf/GENERIC	Wed Jan 10 11:11:20 2018
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC,v 1.479 2018/01/09 03:31:12 christos Exp $
+# $NetBSD: GENERIC,v 1.480 2018/01/10 11:11:20 knakahara Exp $
 #
 # GENERIC machine description file
 #
@@ -22,7 +22,7 @@ include 	"arch/amd64/conf/std.amd64"
 
 options 	INCLUDE_CONFIG_FILE	# embed config file in kernel binary
 
-#ident		"GENERIC-$Revision: 1.479 $"
+#ident		"GENERIC-$Revision: 1.480 $"
 
 maxusers	64		# estimated number of users
 
@@ -1288,6 +1288,7 @@ pseudo-device	tun			# network tunneling 
 pseudo-device	tap			# virtual Ethernet
 pseudo-device	gre			# generic L3 over IP tunnel
 pseudo-device	gif			# IPv[46] over IPv[46] tunnel (RFC1933)
+pseudo-device	ipsecif			# tunnel interface for routing based ipsec
 #pseudo-device	faith			# IPv[46] tcp relay translation i/f
 pseudo-device	stf			# 6to4 IPv6 over IPv4 encapsulation
 pseudo-device	vlan			# IEEE 802.1q encapsulation



CVS commit: src

2018-01-10 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Jan 10 11:08:56 UTC 2018

Modified Files:
src/distrib/sets/lists/man: mi
src/share/man/man4: Makefile ipsec.4
Added Files:
src/share/man/man4: ipsecif.4

Log Message:
add ipsec(4) interface man as ipsecif.4.


To generate a diff of this commit:
cvs rdiff -u -r1.1569 -r1.1570 src/distrib/sets/lists/man/mi
cvs rdiff -u -r1.649 -r1.650 src/share/man/man4/Makefile
cvs rdiff -u -r1.41 -r1.42 src/share/man/man4/ipsec.4
cvs rdiff -u -r0 -r1.1 src/share/man/man4/ipsecif.4

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/sets/lists/man/mi
diff -u src/distrib/sets/lists/man/mi:1.1569 src/distrib/sets/lists/man/mi:1.1570
--- src/distrib/sets/lists/man/mi:1.1569	Tue Jan  9 03:31:14 2018
+++ src/distrib/sets/lists/man/mi	Wed Jan 10 11:08:55 2018
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1569 2018/01/09 03:31:14 christos Exp $
+# $NetBSD: mi,v 1.1570 2018/01/10 11:08:55 knakahara Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -1329,6 +1329,7 @@
 ./usr/share/man/cat4/ipnat.0			man-ipf-catman		ipfilter,.cat
 ./usr/share/man/cat4/ippp.0			man-sys-catman		.cat
 ./usr/share/man/cat4/ipsec.0			man-sys-catman		.cat
+./usr/share/man/cat4/ipsecif.0			man-sys-catman		.cat
 ./usr/share/man/cat4/ipw.0			man-sys-catman		.cat
 ./usr/share/man/cat4/irda.0			man-sys-catman		.cat
 ./usr/share/man/cat4/irframe.0			man-sys-catman		.cat
@@ -4428,6 +4429,7 @@
 ./usr/share/man/html4/ipnat.html		man-ipf-htmlman		ipfilter,html
 ./usr/share/man/html4/ippp.html			man-sys-htmlman		html
 ./usr/share/man/html4/ipsec.html		man-sys-htmlman		html
+./usr/share/man/html4/ipsecif.html		man-sys-htmlman		html
 ./usr/share/man/html4/ipw.html			man-sys-htmlman		html
 ./usr/share/man/html4/irda.html			man-sys-htmlman		html
 ./usr/share/man/html4/irframe.html		man-sys-htmlman		html
@@ -7365,6 +7367,7 @@
 ./usr/share/man/man4/ipnat.4			man-sys-man		ipfilter,.man
 ./usr/share/man/man4/ippp.4			man-sys-man		.man
 ./usr/share/man/man4/ipsec.4			man-sys-man		.man
+./usr/share/man/man4/ipsecif.4			man-sys-man		.man
 ./usr/share/man/man4/ipw.4			man-sys-man		.man
 ./usr/share/man/man4/irda.4			man-sys-man		.man
 ./usr/share/man/man4/irframe.4			man-sys-man		.man

Index: src/share/man/man4/Makefile
diff -u src/share/man/man4/Makefile:1.649 src/share/man/man4/Makefile:1.650
--- src/share/man/man4/Makefile:1.649	Fri Dec 29 08:15:21 2017
+++ src/share/man/man4/Makefile	Wed Jan 10 11:08:55 2018
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.649 2017/12/29 08:15:21 kre Exp $
+#	$NetBSD: Makefile,v 1.650 2018/01/10 11:08:55 knakahara Exp $
 #	@(#)Makefile	8.1 (Berkeley) 6/18/93
 
 MAN=	aac.4 ac97.4 acardide.4 aceride.4 acphy.4 \
@@ -141,7 +141,7 @@ MAN +=	sbt.4 sdhc.4 sdmmc.4
 MAN +=	hil.4 hilkbd.4 hilid.4 hilms.4
 
 # IPv6/IPsec
-MAN+=	faith.4 gif.4 inet6.4 icmp6.4 ip6.4 ipsec.4 stf.4
+MAN+=	faith.4 gif.4 inet6.4 icmp6.4 ip6.4 ipsec.4 ipsecif.4 stf.4
 
 # ISDN devices
 MAN+=	daic.4 isdntrc.4 isdntel.4 isdnbchan.4 ippp.4 irip.4 isdnctl.4 isdn.4 \

Index: src/share/man/man4/ipsec.4
diff -u src/share/man/man4/ipsec.4:1.41 src/share/man/man4/ipsec.4:1.42
--- src/share/man/man4/ipsec.4:1.41	Sun May 21 09:13:46 2017
+++ src/share/man/man4/ipsec.4	Wed Jan 10 11:08:55 2018
@@ -1,4 +1,4 @@
-.\"	$NetBSD: ipsec.4,v 1.41 2017/05/21 09:13:46 wiz Exp $
+.\"	$NetBSD: ipsec.4,v 1.42 2018/01/10 11:08:55 knakahara Exp $
 .\"	$KAME: ipsec.4,v 1.17 2001/06/27 15:25:10 itojun Exp $
 .\"
 .\" Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -35,6 +35,10 @@
 .Nm ipsec
 .Nd IP security protocol
 .Sh DESCRIPTION
+This manual pages describes the IPSEC.
+For the network device driver please see
+.Xr ipsecif 4 .
+.Pp
 .Nm
 is a security protocol in the Internet Protocol (IP) layer.
 .Nm
@@ -281,6 +285,7 @@ routines from looking into IP payload.
 .Xr ipsec_set_policy 3 ,
 .Xr fast_ipsec 4 ,
 .Xr icmp6 4 ,
+.Xr ipsecif 4 ,
 .Xr intro 4 ,
 .Xr ip6 4 ,
 .Xr racoon 8 ,

Added files:

Index: src/share/man/man4/ipsecif.4
diff -u /dev/null src/share/man/man4/ipsecif.4:1.1
--- /dev/null	Wed Jan 10 11:08:56 2018
+++ src/share/man/man4/ipsecif.4	Wed Jan 10 11:08:55 2018
@@ -0,0 +1,148 @@
+.\"	$NetBSD: ipsecif.4,v 1.1 2018/01/10 11:08:55 knakahara Exp $
+.\"
+.\" Copyright (C) 2017 Internet Initiative Japan Inc.
+.\" All rights reserved.
+.\"
+.\" 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.
+.\" 3. Neither the name of t

CVS commit: src

2018-01-10 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Jan 10 11:06:06 UTC 2018

Modified Files:
src/distrib/sets/lists/tests: mi
src/etc/mtree: NetBSD.dist.tests
src/tests/net: Makefile
Added Files:
src/tests/net/if_ipsec: Makefile t_ipsec.sh

Log Message:
add ipsec(4) interface ATF.


To generate a diff of this commit:
cvs rdiff -u -r1.771 -r1.772 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.149 -r1.150 src/etc/mtree/NetBSD.dist.tests
cvs rdiff -u -r1.33 -r1.34 src/tests/net/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/net/if_ipsec/Makefile \
src/tests/net/if_ipsec/t_ipsec.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.771 src/distrib/sets/lists/tests/mi:1.772
--- src/distrib/sets/lists/tests/mi:1.771	Sun Dec 10 15:39:37 2017
+++ src/distrib/sets/lists/tests/mi	Wed Jan 10 11:06:06 2018
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.771 2017/12/10 15:39:37 christos Exp $
+# $NetBSD: mi,v 1.772 2018/01/10 11:06:06 knakahara Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -3295,6 +3295,10 @@
 ./usr/tests/net/if_gif/Atffile			tests-net-tests		atf,rump
 ./usr/tests/net/if_gif/Kyuafile			tests-net-tests		atf,rump,kyua
 ./usr/tests/net/if_gif/t_gif			tests-net-tests		atf,rump
+./usr/tests/net/if_ipsec			tests-net-tests		compattestfile,atf
+./usr/tests/net/if_ipsec/Atffile		tests-net-tests		atf,rump
+./usr/tests/net/if_ipsec/Kyuafile		tests-net-tests		atf,rump,kyua
+./usr/tests/net/if_ipsec/t_ipsec		tests-net-tests		atf,rump
 ./usr/tests/net/if_l2tptests-net-tests		compattestfile,atf
 ./usr/tests/net/if_l2tp/Atffile			tests-net-tests		atf,rump
 ./usr/tests/net/if_l2tp/Kyuafile		tests-net-tests		atf,rump,kyua

Index: src/etc/mtree/NetBSD.dist.tests
diff -u src/etc/mtree/NetBSD.dist.tests:1.149 src/etc/mtree/NetBSD.dist.tests:1.150
--- src/etc/mtree/NetBSD.dist.tests:1.149	Wed Nov  1 08:32:07 2017
+++ src/etc/mtree/NetBSD.dist.tests	Wed Jan 10 11:06:06 2018
@@ -1,4 +1,4 @@
-#	$NetBSD: NetBSD.dist.tests,v 1.149 2017/11/01 08:32:07 martin Exp $
+#	$NetBSD: NetBSD.dist.tests,v 1.150 2018/01/10 11:06:06 knakahara Exp $
 
 ./usr/libdata/debug/usr/tests
 ./usr/libdata/debug/usr/tests/atf
@@ -332,6 +332,7 @@
 ./usr/tests/net/if
 ./usr/tests/net/if_bridge
 ./usr/tests/net/if_gif
+./usr/tests/net/if_ipsec
 ./usr/tests/net/if_l2tp
 ./usr/tests/net/if_loop
 ./usr/tests/net/if_pppoe

Index: src/tests/net/Makefile
diff -u src/tests/net/Makefile:1.33 src/tests/net/Makefile:1.34
--- src/tests/net/Makefile:1.33	Sat May 27 21:02:56 2017
+++ src/tests/net/Makefile	Wed Jan 10 11:06:06 2018
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.33 2017/05/27 21:02:56 bouyer Exp $
+# $NetBSD: Makefile,v 1.34 2018/01/10 11:06:06 knakahara Exp $
 
 .include 
 
@@ -7,7 +7,7 @@ TESTSDIR=	${TESTSBASE}/net
 TESTS_SUBDIRS=		fdpass in_cksum net sys
 .if (${MKRUMP} != "no") && !defined(BSD_MK_COMPAT_FILE)
 TESTS_SUBDIRS+=		arp bpf bpfilter can carp icmp if if_bridge if_gif
-TESTS_SUBDIRS+=		if_l2tp if_loop if_pppoe if_tap if_tun ipsec
+TESTS_SUBDIRS+=		if_ipsec if_l2tp if_loop if_pppoe if_tap if_tun ipsec
 TESTS_SUBDIRS+=		mcast mpls ndp npf route if_vlan
 .if (${MKSLJIT} != "no")
 TESTS_SUBDIRS+=		bpfjit

Added files:

Index: src/tests/net/if_ipsec/Makefile
diff -u /dev/null src/tests/net/if_ipsec/Makefile:1.1
--- /dev/null	Wed Jan 10 11:06:06 2018
+++ src/tests/net/if_ipsec/Makefile	Wed Jan 10 11:06:06 2018
@@ -0,0 +1,14 @@
+# $NetBSD: Makefile,v 1.1 2018/01/10 11:06:06 knakahara Exp $
+#
+
+.include 
+
+TESTSDIR=	${TESTSBASE}/net/if_ipsec
+
+.for name in ipsec
+TESTS_SH+=		t_${name}
+TESTS_SH_SRC_t_${name}=	../net_common.sh t_${name}.sh \
+	../ipsec/common.sh ../ipsec/algorithms.sh
+.endfor
+
+.include 
Index: src/tests/net/if_ipsec/t_ipsec.sh
diff -u /dev/null src/tests/net/if_ipsec/t_ipsec.sh:1.1
--- /dev/null	Wed Jan 10 11:06:06 2018
+++ src/tests/net/if_ipsec/t_ipsec.sh	Wed Jan 10 11:06:06 2018
@@ -0,0 +1,925 @@
+#	$NetBSD: t_ipsec.sh,v 1.1 2018/01/10 11:06:06 knakahara Exp $
+#
+# Copyright (c) 2017 Internet Initiative Japan Inc.
+# All rights reserved.
+#
+# 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 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 D

CVS commit: src

2018-01-10 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Jan 10 11:02:42 UTC 2018

Modified Files:
src/distrib/sets/lists/base: shl.mi
src/distrib/sets/lists/comp: mi shl.mi
src/distrib/sets/lists/debug: mi shl.mi
src/sys/rump/net: Makefile.rumpnetcomp
Added Files:
src/sys/rump/net/lib/libipsec: IPSEC.ioconf Makefile ipsec_component.c

Log Message:
ipsec(4) interface supports rump now.


To generate a diff of this commit:
cvs rdiff -u -r1.824 -r1.825 src/distrib/sets/lists/base/shl.mi
cvs rdiff -u -r1.2168 -r1.2169 src/distrib/sets/lists/comp/mi
cvs rdiff -u -r1.309 -r1.310 src/distrib/sets/lists/comp/shl.mi
cvs rdiff -u -r1.233 -r1.234 src/distrib/sets/lists/debug/mi
cvs rdiff -u -r1.187 -r1.188 src/distrib/sets/lists/debug/shl.mi
cvs rdiff -u -r1.19 -r1.20 src/sys/rump/net/Makefile.rumpnetcomp
cvs rdiff -u -r0 -r1.1 src/sys/rump/net/lib/libipsec/IPSEC.ioconf \
src/sys/rump/net/lib/libipsec/Makefile \
src/sys/rump/net/lib/libipsec/ipsec_component.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/sets/lists/base/shl.mi
diff -u src/distrib/sets/lists/base/shl.mi:1.824 src/distrib/sets/lists/base/shl.mi:1.825
--- src/distrib/sets/lists/base/shl.mi:1.824	Wed Oct 25 06:32:59 2017
+++ src/distrib/sets/lists/base/shl.mi	Wed Jan 10 11:02:41 2018
@@ -1,4 +1,4 @@
-# $NetBSD: shl.mi,v 1.824 2017/10/25 06:32:59 kre Exp $
+# $NetBSD: shl.mi,v 1.825 2018/01/10 11:02:41 knakahara Exp $
 #
 # Note:	Don't delete entries from here - mark them as "obsolete" instead,
 #	unless otherwise stated below.
@@ -706,6 +706,9 @@
 ./usr/lib/librumpnet_gif.so			base-rump-shlib		rump
 ./usr/lib/librumpnet_gif.so.0			base-rump-shlib		rump
 ./usr/lib/librumpnet_gif.so.0.0			base-rump-shlib		rump
+./usr/lib/librumpnet_ipsec.so			base-rump-shlib		rump
+./usr/lib/librumpnet_ipsec.so.0			base-rump-shlib		rump
+./usr/lib/librumpnet_ipsec.so.0.0		base-rump-shlib		rump
 ./usr/lib/librumpnet_l2tp.so			base-rump-shlib		rump
 ./usr/lib/librumpnet_l2tp.so.0			base-rump-shlib		rump
 ./usr/lib/librumpnet_l2tp.so.0.0		base-rump-shlib		rump

Index: src/distrib/sets/lists/comp/mi
diff -u src/distrib/sets/lists/comp/mi:1.2168 src/distrib/sets/lists/comp/mi:1.2169
--- src/distrib/sets/lists/comp/mi:1.2168	Wed Jan 10 10:56:30 2018
+++ src/distrib/sets/lists/comp/mi	Wed Jan 10 11:02:41 2018
@@ -1,4 +1,4 @@
-#	$NetBSD: mi,v 1.2168 2018/01/10 10:56:30 knakahara Exp $
+#	$NetBSD: mi,v 1.2169 2018/01/10 11:02:41 knakahara Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 ./etc/mtree/set.compcomp-sys-root
@@ -3569,6 +3569,8 @@
 ./usr/lib/librumpnet_bridge_p.a			comp-c-proflib		rump,profile
 ./usr/lib/librumpnet_gif.a			comp-c-lib		rump
 ./usr/lib/librumpnet_gif_p.a			comp-c-proflib		rump,profile
+./usr/lib/librumpnet_ipsec.a			comp-c-lib		rump
+./usr/lib/librumpnet_ipsec_p.a			comp-c-proflib		rump,profile
 ./usr/lib/librumpnet_l2tp.a			comp-c-lib		rump
 ./usr/lib/librumpnet_l2tp_p.a			comp-c-proflib		rump,profile
 ./usr/lib/librumpnet_local.a			comp-c-lib		rump

Index: src/distrib/sets/lists/comp/shl.mi
diff -u src/distrib/sets/lists/comp/shl.mi:1.309 src/distrib/sets/lists/comp/shl.mi:1.310
--- src/distrib/sets/lists/comp/shl.mi:1.309	Sat Nov  4 16:21:49 2017
+++ src/distrib/sets/lists/comp/shl.mi	Wed Jan 10 11:02:41 2018
@@ -1,4 +1,4 @@
-# $NetBSD: shl.mi,v 1.309 2017/11/04 16:21:49 kamil Exp $
+# $NetBSD: shl.mi,v 1.310 2018/01/10 11:02:41 knakahara Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -219,6 +219,7 @@
 ./usr/lib/librumpnet_bpfjit_pic.a		comp-c-piclib		picinstall,rump,sljit
 ./usr/lib/librumpnet_bridge_pic.a		comp-c-piclib		picinstall,rump
 ./usr/lib/librumpnet_gif_pic.a			comp-c-piclib		picinstall,rump
+./usr/lib/librumpnet_ipsec_pic.a		comp-c-piclib		picinstall,rump
 ./usr/lib/librumpnet_l2tp_pic.a			comp-c-piclib		picinstall,rump
 ./usr/lib/librumpnet_local_pic.a		comp-c-piclib		picinstall,rump
 ./usr/lib/librumpnet_net80211_pic.a		comp-c-piclib		picinstall,rump

Index: src/distrib/sets/lists/debug/mi
diff -u src/distrib/sets/lists/debug/mi:1.233 src/distrib/sets/lists/debug/mi:1.234
--- src/distrib/sets/lists/debug/mi:1.233	Tue Jan  9 03:31:13 2018
+++ src/distrib/sets/lists/debug/mi	Wed Jan 10 11:02:41 2018
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.233 2018/01/09 03:31:13 christos Exp $
+# $NetBSD: mi,v 1.234 2018/01/10 11:02:41 knakahara Exp $
 ./etc/mtree/set.debug   comp-sys-root
 ./usr/lib	comp-sys-usr		compatdir
 ./usr/lib/i18n/libBIG5_g.a			comp-c-debuglib		debuglib,compatfile
@@ -211,6 +211,7 @@
 ./usr/lib/librumpnet_bridge_g.a			comp-c-debuglib		debuglib,rump
 ./usr/lib/librumpnet_g.a			comp-c-debuglib		debuglib,compatfile,rump
 ./usr/lib/librumpnet_gif_g.a			comp-c-debuglib		debuglib,rump
+./usr/lib/librumpnet_ipsec_g.a			comp-c-debuglib		debuglib,rump
 ./usr/lib/librumpnet_l2tp_g

CVS commit: src

2018-01-10 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Jan 10 10:56:31 UTC 2018

Modified Files:
src/distrib/sets/lists/comp: mi
src/sys/conf: files
src/sys/net: Makefile files.net if_types.h
src/sys/netinet: in.c in.h ip_var.h
src/sys/netinet6: in6.c in6.h ip6_var.h
src/sys/netipsec: Makefile files.netipsec ipsec.h key.c key.h
Added Files:
src/sys/net: if_ipsec.c if_ipsec.h
src/sys/netipsec: ipsecif.c ipsecif.h

Log Message:
add ipsec(4) interface, which is used for route-based VPN.

man and ATF are added later, please see man for details.

reviewed by christos@n.o, joerg@n.o and ozaki-r@n.o, thanks.
https://mail-index.netbsd.org/tech-net/2017/12/18/msg006557.html


To generate a diff of this commit:
cvs rdiff -u -r1.2167 -r1.2168 src/distrib/sets/lists/comp/mi
cvs rdiff -u -r1.1190 -r1.1191 src/sys/conf/files
cvs rdiff -u -r1.33 -r1.34 src/sys/net/Makefile
cvs rdiff -u -r1.13 -r1.14 src/sys/net/files.net
cvs rdiff -u -r0 -r1.1 src/sys/net/if_ipsec.c src/sys/net/if_ipsec.h
cvs rdiff -u -r1.27 -r1.28 src/sys/net/if_types.h
cvs rdiff -u -r1.213 -r1.214 src/sys/netinet/in.c
cvs rdiff -u -r1.102 -r1.103 src/sys/netinet/in.h
cvs rdiff -u -r1.121 -r1.122 src/sys/netinet/ip_var.h
cvs rdiff -u -r1.256 -r1.257 src/sys/netinet6/in6.c
cvs rdiff -u -r1.87 -r1.88 src/sys/netinet6/in6.h
cvs rdiff -u -r1.74 -r1.75 src/sys/netinet6/ip6_var.h
cvs rdiff -u -r1.5 -r1.6 src/sys/netipsec/Makefile
cvs rdiff -u -r1.12 -r1.13 src/sys/netipsec/files.netipsec
cvs rdiff -u -r1.61 -r1.62 src/sys/netipsec/ipsec.h
cvs rdiff -u -r0 -r1.1 src/sys/netipsec/ipsecif.c src/sys/netipsec/ipsecif.h
cvs rdiff -u -r1.246 -r1.247 src/sys/netipsec/key.c
cvs rdiff -u -r1.33 -r1.34 src/sys/netipsec/key.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/sets/lists/comp/mi
diff -u src/distrib/sets/lists/comp/mi:1.2167 src/distrib/sets/lists/comp/mi:1.2168
--- src/distrib/sets/lists/comp/mi:1.2167	Tue Jan  9 03:31:13 2018
+++ src/distrib/sets/lists/comp/mi	Wed Jan 10 10:56:30 2018
@@ -1,4 +1,4 @@
-#	$NetBSD: mi,v 1.2167 2018/01/09 03:31:13 christos Exp $
+#	$NetBSD: mi,v 1.2168 2018/01/10 10:56:30 knakahara Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 ./etc/mtree/set.compcomp-sys-root
@@ -2224,6 +2224,7 @@
 ./usr/include/net/if_hippi.h			comp-c-include
 ./usr/include/net/if_ieee1394.h			comp-c-include
 ./usr/include/net/if_ieee80211.h		comp-obsolete		obsolete
+./usr/include/net/if_ipsec.h			comp-c-include
 ./usr/include/net/if_l2tp.h			comp-c-include
 ./usr/include/net/if_llc.h			comp-c-include
 ./usr/include/net/if_media.h			comp-c-include
@@ -2382,6 +2383,7 @@
 ./usr/include/netipsec/ipcomp_var.h		comp-c-include
 ./usr/include/netipsec/ipip_var.h		comp-c-include
 ./usr/include/netipsec/ipsec.h			comp-c-include
+./usr/include/netipsec/ipsecif.h		comp-c-include
 ./usr/include/netipsec/ipsec_var.h		comp-c-include
 ./usr/include/netipsec/keydb.h			comp-obsolete		obsolete
 ./usr/include/netipsec/keysock.h		comp-c-include

Index: src/sys/conf/files
diff -u src/sys/conf/files:1.1190 src/sys/conf/files:1.1191
--- src/sys/conf/files:1.1190	Tue Jan  9 03:31:12 2018
+++ src/sys/conf/files	Wed Jan 10 10:56:30 2018
@@ -1,4 +1,4 @@
-#	$NetBSD: files,v 1.1190 2018/01/09 03:31:12 christos Exp $
+#	$NetBSD: files,v 1.1191 2018/01/10 10:56:30 knakahara Exp $
 #	@(#)files.newconf	7.5 (Berkeley) 5/10/93
 
 version 	20171118
@@ -1463,6 +1463,7 @@ defpseudo carp:		ifnet, ether, arp
 defpseudodev etherip:	ifnet, ether, arp
 defpseudodev l2tp:	ifnet, ether, arp
 defpseudo canloop:	ifnet
+defpseudo ipsecif:	ifnet		# avoid to confuse ipsec itself option
 
 defpseudo sequencer
 defpseudo clockctl

Index: src/sys/net/Makefile
diff -u src/sys/net/Makefile:1.33 src/sys/net/Makefile:1.34
--- src/sys/net/Makefile:1.33	Thu Feb 16 08:12:44 2017
+++ src/sys/net/Makefile	Wed Jan 10 10:56:30 2018
@@ -1,10 +1,10 @@
-#	$NetBSD: Makefile,v 1.33 2017/02/16 08:12:44 knakahara Exp $
+#	$NetBSD: Makefile,v 1.34 2018/01/10 10:56:30 knakahara Exp $
 
 INCSDIR= /usr/include/net
 
 INCS=	bpf.h bpfjit.h bpfdesc.h dlt.h ethertypes.h if.h if_arc.h if_arp.h \
 	if_atm.h if_bridgevar.h if_dl.h if_ether.h if_etherip.h if_fddi.h if_gif.h \
-	if_gre.h if_hippi.h if_ieee1394.h if_llc.h if_media.h if_mpls.h \
+	if_gre.h if_hippi.h if_ieee1394.h if_ipsec.h if_llc.h if_media.h if_mpls.h \
 	if_pflog.h if_ppp.h if_pppoe.h if_l2tp.h if_sppp.h if_srt.h if_stf.h \
 	if_tap.h if_token.h if_tun.h if_types.h if_vlanvar.h net_stats.h \
 	netisr.h pfil.h pfkeyv2.h pfvar.h ppp-comp.h ppp_defs.h radix.h \

Index: src/sys/net/files.net
diff -u src/sys/net/files.net:1.13 src/sys/net/files.net:1.14
--- src/sys/net/files.net:1.13	Thu Feb 16 08:12:44 2017
+++ src/sys/net/files.net	Wed Jan 10 10:56:30 2018
@@ -1,4 +1,4 @@
-#	$NetBSD: files.net,v 1.13 2017/02/16 08:12:44 knakahara Exp $
+#	$NetBSD: files.net,v 1

CVS commit: src/sys/opencrypto

2018-01-08 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Jan  8 23:34:56 UTC 2018

Modified Files:
src/sys/opencrypto: crypto.c

Log Message:
Fix PR kern/52910. Reported and implemented a patch by Sevan Janiyan, thanks.


To generate a diff of this commit:
cvs rdiff -u -r1.104 -r1.105 src/sys/opencrypto/crypto.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/opencrypto/crypto.c
diff -u src/sys/opencrypto/crypto.c:1.104 src/sys/opencrypto/crypto.c:1.105
--- src/sys/opencrypto/crypto.c:1.104	Mon Jan  8 23:33:40 2018
+++ src/sys/opencrypto/crypto.c	Mon Jan  8 23:34:56 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: crypto.c,v 1.104 2018/01/08 23:33:40 knakahara Exp $ */
+/*	$NetBSD: crypto.c,v 1.105 2018/01/08 23:34:56 knakahara Exp $ */
 /*	$FreeBSD: src/sys/opencrypto/crypto.c,v 1.4.2.5 2003/02/26 00:14:05 sam Exp $	*/
 /*	$OpenBSD: crypto.c,v 1.41 2002/07/17 23:52:38 art Exp $	*/
 
@@ -53,7 +53,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.104 2018/01/08 23:33:40 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.105 2018/01/08 23:34:56 knakahara Exp $");
 
 #include 
 #include 
@@ -360,7 +360,7 @@ sysctl_opencrypto_kq_maxlen(SYSCTLFN_ARG
 }
 
 /*
- * Crypto op and desciptor data structures are allocated
+ * Crypto op and descriptor data structures are allocated
  * from separate private zones(FreeBSD)/pools(netBSD/OpenBSD) .
  */
 static pool_cache_t cryptop_cache;



CVS commit: src/sys

2018-01-08 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Jan  8 23:33:40 UTC 2018

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

Log Message:
Committed debugging logs by mistake, sorry. Revert cryoto.c:r.1.103 and 
ip6_flow.c:r.1.37.


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/sys/netinet6/ip6_flow.c
cvs rdiff -u -r1.103 -r1.104 src/sys/opencrypto/crypto.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.37 src/sys/netinet6/ip6_flow.c:1.38
--- src/sys/netinet6/ip6_flow.c:1.37	Mon Jan  8 23:23:25 2018
+++ src/sys/netinet6/ip6_flow.c	Mon Jan  8 23:33:40 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6_flow.c,v 1.37 2018/01/08 23:23:25 knakahara Exp $	*/
+/*	$NetBSD: ip6_flow.c,v 1.38 2018/01/08 23:33:40 knakahara Exp $	*/
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip6_flow.c,v 1.37 2018/01/08 23:23:25 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_flow.c,v 1.38 2018/01/08 23:33:40 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -560,8 +560,6 @@ ip6flow_create(struct route *ro, struct 
 	struct ip6flow *ip6f;
 	size_t hash;
 
-	printf(" %s: enter\n", __func__);
-
 	ip6 = mtod(m, const struct ip6_hdr *);
 
 	KERNEL_LOCK_UNLESS_NET_MPSAFE();
@@ -573,12 +571,8 @@ ip6flow_create(struct route *ro, struct 
 	 *
 	 * Don't create a flow for ICMPv6 messages.
 	 */
-	if (ip6_maxflows == 0 || ip6->ip6_nxt == IPPROTO_IPV6_ICMP) {
-		printf(" %s: icmp skip\n", __func__);
+	if (ip6_maxflows == 0 || ip6->ip6_nxt == IPPROTO_IPV6_ICMP)
 		goto out;
-	}
-
-	printf(" %s: ip6->ip6_nxt=%d\n", __func__, ip6->ip6_nxt);
 
 	/*
 	 * See if an existing flow exists.  If so:

Index: src/sys/opencrypto/crypto.c
diff -u src/sys/opencrypto/crypto.c:1.103 src/sys/opencrypto/crypto.c:1.104
--- src/sys/opencrypto/crypto.c:1.103	Mon Jan  8 23:23:25 2018
+++ src/sys/opencrypto/crypto.c	Mon Jan  8 23:33:40 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: crypto.c,v 1.103 2018/01/08 23:23:25 knakahara Exp $ */
+/*	$NetBSD: crypto.c,v 1.104 2018/01/08 23:33:40 knakahara Exp $ */
 /*	$FreeBSD: src/sys/opencrypto/crypto.c,v 1.4.2.5 2003/02/26 00:14:05 sam Exp $	*/
 /*	$OpenBSD: crypto.c,v 1.41 2002/07/17 23:52:38 art Exp $	*/
 
@@ -53,7 +53,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.103 2018/01/08 23:23:25 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.104 2018/01/08 23:33:40 knakahara Exp $");
 
 #include 
 #include 
@@ -360,7 +360,7 @@ sysctl_opencrypto_kq_maxlen(SYSCTLFN_ARG
 }
 
 /*
- * Crypto op and descriptor data structures are allocated
+ * Crypto op and desciptor data structures are allocated
  * from separate private zones(FreeBSD)/pools(netBSD/OpenBSD) .
  */
 static pool_cache_t cryptop_cache;



CVS commit: src/sys

2018-01-08 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Jan  8 23:23:25 UTC 2018

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

Log Message:
Fix PR kern/52910. Reported and implemented a patch by Sevan Janiyan, thanks.


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/sys/netinet6/ip6_flow.c
cvs rdiff -u -r1.102 -r1.103 src/sys/opencrypto/crypto.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.36 src/sys/netinet6/ip6_flow.c:1.37
--- src/sys/netinet6/ip6_flow.c:1.36	Sun Dec 10 09:06:46 2017
+++ src/sys/netinet6/ip6_flow.c	Mon Jan  8 23:23:25 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6_flow.c,v 1.36 2017/12/10 09:06:46 maxv Exp $	*/
+/*	$NetBSD: ip6_flow.c,v 1.37 2018/01/08 23:23:25 knakahara Exp $	*/
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip6_flow.c,v 1.36 2017/12/10 09:06:46 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_flow.c,v 1.37 2018/01/08 23:23:25 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -560,6 +560,8 @@ ip6flow_create(struct route *ro, struct 
 	struct ip6flow *ip6f;
 	size_t hash;
 
+	printf(" %s: enter\n", __func__);
+
 	ip6 = mtod(m, const struct ip6_hdr *);
 
 	KERNEL_LOCK_UNLESS_NET_MPSAFE();
@@ -571,8 +573,12 @@ ip6flow_create(struct route *ro, struct 
 	 *
 	 * Don't create a flow for ICMPv6 messages.
 	 */
-	if (ip6_maxflows == 0 || ip6->ip6_nxt == IPPROTO_IPV6_ICMP)
+	if (ip6_maxflows == 0 || ip6->ip6_nxt == IPPROTO_IPV6_ICMP) {
+		printf(" %s: icmp skip\n", __func__);
 		goto out;
+	}
+
+	printf(" %s: ip6->ip6_nxt=%d\n", __func__, ip6->ip6_nxt);
 
 	/*
 	 * See if an existing flow exists.  If so:

Index: src/sys/opencrypto/crypto.c
diff -u src/sys/opencrypto/crypto.c:1.102 src/sys/opencrypto/crypto.c:1.103
--- src/sys/opencrypto/crypto.c:1.102	Thu Nov  9 22:20:25 2017
+++ src/sys/opencrypto/crypto.c	Mon Jan  8 23:23:25 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: crypto.c,v 1.102 2017/11/09 22:20:25 christos Exp $ */
+/*	$NetBSD: crypto.c,v 1.103 2018/01/08 23:23:25 knakahara Exp $ */
 /*	$FreeBSD: src/sys/opencrypto/crypto.c,v 1.4.2.5 2003/02/26 00:14:05 sam Exp $	*/
 /*	$OpenBSD: crypto.c,v 1.41 2002/07/17 23:52:38 art Exp $	*/
 
@@ -53,7 +53,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.102 2017/11/09 22:20:25 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.103 2018/01/08 23:23:25 knakahara Exp $");
 
 #include 
 #include 
@@ -360,7 +360,7 @@ sysctl_opencrypto_kq_maxlen(SYSCTLFN_ARG
 }
 
 /*
- * Crypto op and desciptor data structures are allocated
+ * Crypto op and descriptor data structures are allocated
  * from separate private zones(FreeBSD)/pools(netBSD/OpenBSD) .
  */
 static pool_cache_t cryptop_cache;



CVS commit: src/sys/arch/x86

2018-01-03 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Jan  4 01:01:59 UTC 2018

Modified Files:
src/sys/arch/x86/include: intr.h
src/sys/arch/x86/pci: pci_intr_machdep.c
src/sys/arch/x86/x86: intr.c

Log Message:
fix "intrctl list" panic when ACPI is disabled.

reviewed by cherry@n.o and tested by msaitoh@n.o, thanks.


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.53 src/sys/arch/x86/include/intr.h
cvs rdiff -u -r1.41 -r1.42 src/sys/arch/x86/pci/pci_intr_machdep.c
cvs rdiff -u -r1.113 -r1.114 src/sys/arch/x86/x86/intr.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/arch/x86/include/intr.h
diff -u src/sys/arch/x86/include/intr.h:1.52 src/sys/arch/x86/include/intr.h:1.53
--- src/sys/arch/x86/include/intr.h:1.52	Sat Nov  4 14:56:48 2017
+++ src/sys/arch/x86/include/intr.h	Thu Jan  4 01:01:59 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.h,v 1.52 2017/11/04 14:56:48 cherry Exp $	*/
+/*	$NetBSD: intr.h,v 1.53 2018/01/04 01:01:59 knakahara Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -222,6 +222,9 @@ int intr_find_mpmapping(int, int, intr_h
 struct pic *intr_findpic(int);
 void intr_printconfig(void);
 
+#if !defined(XEN)
+const char *intr_create_intrid(int, struct pic *, int, char *, size_t);
+#endif /* XEN */
 struct intrsource *intr_allocate_io_intrsource(const char *);
 void intr_free_io_intrsource(const char *);
 

Index: src/sys/arch/x86/pci/pci_intr_machdep.c
diff -u src/sys/arch/x86/pci/pci_intr_machdep.c:1.41 src/sys/arch/x86/pci/pci_intr_machdep.c:1.42
--- src/sys/arch/x86/pci/pci_intr_machdep.c:1.41	Fri Jul 28 14:26:50 2017
+++ src/sys/arch/x86/pci/pci_intr_machdep.c	Thu Jan  4 01:01:59 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: pci_intr_machdep.c,v 1.41 2017/07/28 14:26:50 maxv Exp $	*/
+/*	$NetBSD: pci_intr_machdep.c,v 1.42 2018/01/04 01:01:59 knakahara Exp $	*/
 
 /*-
  * Copyright (c) 1997, 1998, 2009 The NetBSD Foundation, Inc.
@@ -73,7 +73,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pci_intr_machdep.c,v 1.41 2017/07/28 14:26:50 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pci_intr_machdep.c,v 1.42 2018/01/04 01:01:59 knakahara Exp $");
 
 #include 
 #include 
@@ -273,15 +273,42 @@ pci_intr_setattr(pci_chipset_tag_t pc, p
 	}
 }
 
+static int
+pci_intr_find_intx_irq(pci_intr_handle_t ih, int *irq, struct pic **pic,
+int *pin)
+{
+
+	KASSERT(irq != NULL);
+	KASSERT(pic != NULL);
+	KASSERT(pin != NULL);
+
+	*pic = &i8259_pic;
+	*pin = *irq = APIC_IRQ_LEGACY_IRQ(ih);
+
+#if NIOAPIC > 0
+	if (ih & APIC_INT_VIA_APIC) {
+		struct ioapic_softc *ioapic;
+
+		ioapic = ioapic_find(APIC_IRQ_APIC(ih));
+		if (ioapic == NULL)
+			return ENOENT;
+		*pic = &ioapic->sc_pic;
+		*pin = APIC_IRQ_PIN(ih);
+		*irq = APIC_IRQ_LEGACY_IRQ(ih);
+		if (*irq < 0 || *irq >= NUM_LEGACY_IRQS)
+			*irq = -1;
+	}
+#endif
+
+	return 0;
+}
+
 static void *
 pci_intr_establish_xname_internal(pci_chipset_tag_t pc, pci_intr_handle_t ih,
 int level, int (*func)(void *), void *arg, const char *xname)
 {
 	int pin, irq;
 	struct pic *pic;
-#if NIOAPIC > 0
-	struct ioapic_softc *ioapic;
-#endif
 	bool mpsafe;
 	pci_chipset_tag_t ipc;
 
@@ -301,25 +328,13 @@ pci_intr_establish_xname_internal(pci_ch
 			xname);
 	}
 
-	pic = &i8259_pic;
-	pin = irq = APIC_IRQ_LEGACY_IRQ(ih);
-	mpsafe = ((ih & MPSAFE_MASK) != 0);
-
-#if NIOAPIC > 0
-	if (ih & APIC_INT_VIA_APIC) {
-		ioapic = ioapic_find(APIC_IRQ_APIC(ih));
-		if (ioapic == NULL) {
-			aprint_normal("pci_intr_establish: bad ioapic %d\n",
-			APIC_IRQ_APIC(ih));
-			return NULL;
-		}
-		pic = &ioapic->sc_pic;
-		pin = APIC_IRQ_PIN(ih);
-		irq = APIC_IRQ_LEGACY_IRQ(ih);
-		if (irq < 0 || irq >= NUM_LEGACY_IRQS)
-			irq = -1;
+	if (pci_intr_find_intx_irq(ih, &irq, &pic, &pin)) {
+		aprint_normal("%s: bad pic %d\n", __func__,
+		APIC_IRQ_APIC(ih));
+		return NULL;
 	}
-#endif
+
+	mpsafe = ((ih & MPSAFE_MASK) != 0);
 
 	return intr_establish_xname(irq, pic, pin, IST_LEVEL, level, func, arg,
 	mpsafe, xname);
@@ -376,6 +391,31 @@ pci_intr_type(pci_chipset_tag_t pc, pci_
 	}
 }
 
+static const char *
+x86_pci_intx_create_intrid(pci_chipset_tag_t pc, pci_intr_handle_t ih, char *buf,
+size_t len)
+{
+#if !defined(XEN)
+	int pin, irq;
+	struct pic *pic;
+
+	KASSERT(!INT_VIA_MSI(ih));
+
+	pic = &i8259_pic;
+	pin = irq = APIC_IRQ_LEGACY_IRQ(ih);
+
+	if (pci_intr_find_intx_irq(ih, &irq, &pic, &pin)) {
+		aprint_normal("%s: bad pic %d\n", __func__,
+		APIC_IRQ_APIC(ih));
+		return NULL;
+	}
+
+	return intr_create_intrid(irq, pic, pin, buf, len);
+#else
+	return pci_intr_string(pc, ih, buf, len);
+#endif /* !XEN */
+}
+
 static void
 x86_pci_intx_release(pci_chipset_tag_t pc, pci_intr_handle_t *pih)
 {
@@ -406,8 +446,11 @@ pci_intx_alloc(const struct pci_attach_a
 		goto error;
 	}
 
-	intrstr = pci_intr_string(pa->pa_pc, *handle,
-	intrstr_buf, sizeof(intrstr_buf));
+	/*
+	 * must be 

CVS commit: src/sys/net

2017-12-21 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Dec 21 09:35:38 UTC 2017

Modified Files:
src/sys/net: if_gif.c

Log Message:
remove duplicated null ckeck


To generate a diff of this commit:
cvs rdiff -u -r1.136 -r1.137 src/sys/net/if_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/net/if_gif.c
diff -u src/sys/net/if_gif.c:1.136 src/sys/net/if_gif.c:1.137
--- src/sys/net/if_gif.c:1.136	Sat Dec  9 08:03:06 2017
+++ src/sys/net/if_gif.c	Thu Dec 21 09:35:38 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_gif.c,v 1.136 2017/12/09 08:03:06 pgoyette Exp $	*/
+/*	$NetBSD: if_gif.c,v 1.137 2017/12/21 09:35:38 knakahara Exp $	*/
 /*	$KAME: if_gif.c,v 1.76 2001/08/20 02:01:02 kjc Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.136 2017/12/09 08:03:06 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.137 2017/12/21 09:35:38 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -382,11 +382,8 @@ gif_encapcheck(struct mbuf *m, int off, 
 		return 0;
 
 	var = gif_getref_variant(sc, &psref);
-	if (var->gv_psrc == NULL || var->gv_pdst == NULL)
-		goto out;
-
 	/* no physical address */
-	if (!var->gv_psrc || !var->gv_pdst)
+	if (var->gv_psrc == NULL || var->gv_pdst == NULL)
 		goto out;
 
 	switch (proto) {



CVS commit: src/sys

2017-12-17 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Dec 18 03:21:44 UTC 2017

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

Log Message:
fix mbuf leaks. pointed out and suggested by kre@n.o, thanks.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/netinet/in_l2tp.c
cvs rdiff -u -r1.11 -r1.12 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/netinet/in_l2tp.c
diff -u src/sys/netinet/in_l2tp.c:1.8 src/sys/netinet/in_l2tp.c:1.9
--- src/sys/netinet/in_l2tp.c:1.8	Mon Dec 18 03:20:12 2017
+++ src/sys/netinet/in_l2tp.c	Mon Dec 18 03:21:44 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: in_l2tp.c,v 1.8 2017/12/18 03:20:12 knakahara Exp $	*/
+/*	$NetBSD: in_l2tp.c,v 1.9 2017/12/18 03:21:44 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in_l2tp.c,v 1.8 2017/12/18 03:20:12 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in_l2tp.c,v 1.9 2017/12/18 03:21:44 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_l2tp.h"
@@ -368,13 +368,11 @@ in_l2tp_match(struct mbuf *m, int off, i
 
 	KASSERT(proto == IPPROTO_L2TP);
 
-	if (m->m_len < off + sizeof(uint32_t)) {
-		m = m_pullup(m, off + sizeof(uint32_t));
-		if (!m) {
-			/* if payload length < 4 octets */
-			return 0;
-		}
-}
+	/*
+	 * If the packet contains no session ID it cannot match
+	 */
+	if (m_length(m) < off + sizeof(uint32_t))
+		return 0;
 
 	/* get L2TP session ID */
 	m_copydata(m, off, sizeof(uint32_t), (void *)&sess_id);

Index: src/sys/netinet6/in6_l2tp.c
diff -u src/sys/netinet6/in6_l2tp.c:1.11 src/sys/netinet6/in6_l2tp.c:1.12
--- src/sys/netinet6/in6_l2tp.c:1.11	Mon Dec 18 03:20:13 2017
+++ src/sys/netinet6/in6_l2tp.c	Mon Dec 18 03:21:44 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: in6_l2tp.c,v 1.11 2017/12/18 03:20:13 knakahara Exp $	*/
+/*	$NetBSD: in6_l2tp.c,v 1.12 2017/12/18 03:21:44 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in6_l2tp.c,v 1.11 2017/12/18 03:20:13 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6_l2tp.c,v 1.12 2017/12/18 03:21:44 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_l2tp.h"
@@ -360,13 +360,11 @@ in6_l2tp_match(struct mbuf *m, int off, 
 
 	KASSERT(proto == IPPROTO_L2TP);
 
-	if (m->m_len < off + sizeof(uint32_t)) {
-		m = m_pullup(m, off + sizeof(uint32_t));
-		if (!m) {
-			/* if payload length < 4 octets */
-			return 0;
-		}
-}
+	/*
+	 * If the packet contains no session ID it cannot match
+	 */
+	if (m_length(m) < off + sizeof(uint32_t))
+		return 0;
 
 	/* get L2TP session ID */
 	m_copydata(m, off, sizeof(uint32_t), (void *)&sess_id);



CVS commit: src/sys

2017-12-17 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Dec 18 03:20:13 UTC 2017

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

Log Message:
backout wrong fix again, sorry.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/netinet/in_l2tp.c
cvs rdiff -u -r1.10 -r1.11 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/netinet/in_l2tp.c
diff -u src/sys/netinet/in_l2tp.c:1.7 src/sys/netinet/in_l2tp.c:1.8
--- src/sys/netinet/in_l2tp.c:1.7	Fri Dec 15 05:01:16 2017
+++ src/sys/netinet/in_l2tp.c	Mon Dec 18 03:20:12 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: in_l2tp.c,v 1.7 2017/12/15 05:01:16 knakahara Exp $	*/
+/*	$NetBSD: in_l2tp.c,v 1.8 2017/12/18 03:20:12 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in_l2tp.c,v 1.7 2017/12/15 05:01:16 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in_l2tp.c,v 1.8 2017/12/18 03:20:12 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_l2tp.h"
@@ -369,10 +369,12 @@ in_l2tp_match(struct mbuf *m, int off, i
 	KASSERT(proto == IPPROTO_L2TP);
 
 	if (m->m_len < off + sizeof(uint32_t)) {
-		/* if payload length < 4 octets */
-		if(!m_ensure_contig(&m, off + sizeof(uint32_t)))
+		m = m_pullup(m, off + sizeof(uint32_t));
+		if (!m) {
+			/* if payload length < 4 octets */
 			return 0;
-	}
+		}
+}
 
 	/* get L2TP session ID */
 	m_copydata(m, off, sizeof(uint32_t), (void *)&sess_id);

Index: src/sys/netinet6/in6_l2tp.c
diff -u src/sys/netinet6/in6_l2tp.c:1.10 src/sys/netinet6/in6_l2tp.c:1.11
--- src/sys/netinet6/in6_l2tp.c:1.10	Fri Dec 15 05:01:16 2017
+++ src/sys/netinet6/in6_l2tp.c	Mon Dec 18 03:20:13 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: in6_l2tp.c,v 1.10 2017/12/15 05:01:16 knakahara Exp $	*/
+/*	$NetBSD: in6_l2tp.c,v 1.11 2017/12/18 03:20:13 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in6_l2tp.c,v 1.10 2017/12/15 05:01:16 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6_l2tp.c,v 1.11 2017/12/18 03:20:13 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_l2tp.h"
@@ -361,10 +361,12 @@ in6_l2tp_match(struct mbuf *m, int off, 
 	KASSERT(proto == IPPROTO_L2TP);
 
 	if (m->m_len < off + sizeof(uint32_t)) {
-		/* if payload length < 4 octets */
-		if(!m_ensure_contig(&m, off + sizeof(uint32_t)))
+		m = m_pullup(m, off + sizeof(uint32_t));
+		if (!m) {
+			/* if payload length < 4 octets */
 			return 0;
-	}
+		}
+}
 
 	/* get L2TP session ID */
 	m_copydata(m, off, sizeof(uint32_t), (void *)&sess_id);



CVS commit: src/sys

2017-12-14 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Dec 15 05:01:17 UTC 2017

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

Log Message:
Fix pullup'ed mbuf leaks. The match function just requires enough mbuf length.

XXX need pullup-8


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/netinet/in_l2tp.c
cvs rdiff -u -r1.9 -r1.10 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/netinet/in_l2tp.c
diff -u src/sys/netinet/in_l2tp.c:1.6 src/sys/netinet/in_l2tp.c:1.7
--- src/sys/netinet/in_l2tp.c:1.6	Fri Dec 15 04:58:31 2017
+++ src/sys/netinet/in_l2tp.c	Fri Dec 15 05:01:16 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: in_l2tp.c,v 1.6 2017/12/15 04:58:31 knakahara Exp $	*/
+/*	$NetBSD: in_l2tp.c,v 1.7 2017/12/15 05:01:16 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in_l2tp.c,v 1.6 2017/12/15 04:58:31 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in_l2tp.c,v 1.7 2017/12/15 05:01:16 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_l2tp.h"
@@ -369,12 +369,10 @@ in_l2tp_match(struct mbuf *m, int off, i
 	KASSERT(proto == IPPROTO_L2TP);
 
 	if (m->m_len < off + sizeof(uint32_t)) {
-		m = m_pullup(m, off + sizeof(uint32_t));
-		if (!m) {
-			/* if payload length < 4 octets */
+		/* if payload length < 4 octets */
+		if(!m_ensure_contig(&m, off + sizeof(uint32_t)))
 			return 0;
-		}
-}
+	}
 
 	/* get L2TP session ID */
 	m_copydata(m, off, sizeof(uint32_t), (void *)&sess_id);

Index: src/sys/netinet6/in6_l2tp.c
diff -u src/sys/netinet6/in6_l2tp.c:1.9 src/sys/netinet6/in6_l2tp.c:1.10
--- src/sys/netinet6/in6_l2tp.c:1.9	Fri Dec 15 04:58:31 2017
+++ src/sys/netinet6/in6_l2tp.c	Fri Dec 15 05:01:16 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: in6_l2tp.c,v 1.9 2017/12/15 04:58:31 knakahara Exp $	*/
+/*	$NetBSD: in6_l2tp.c,v 1.10 2017/12/15 05:01:16 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in6_l2tp.c,v 1.9 2017/12/15 04:58:31 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6_l2tp.c,v 1.10 2017/12/15 05:01:16 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_l2tp.h"
@@ -361,12 +361,10 @@ in6_l2tp_match(struct mbuf *m, int off, 
 	KASSERT(proto == IPPROTO_L2TP);
 
 	if (m->m_len < off + sizeof(uint32_t)) {
-		m = m_pullup(m, off + sizeof(uint32_t));
-		if (!m) {
-			/* if payload length < 4 octets */
+		/* if payload length < 4 octets */
+		if(!m_ensure_contig(&m, off + sizeof(uint32_t)))
 			return 0;
-		}
-}
+	}
 
 	/* get L2TP session ID */
 	m_copydata(m, off, sizeof(uint32_t), (void *)&sess_id);



CVS commit: src/sys

2017-12-14 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Dec 15 04:58:32 UTC 2017

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

Log Message:
backout wrong fix as it causes atf net/ipsec/t_ipsec_l2tp failures.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/netinet/in_l2tp.c
cvs rdiff -u -r1.8 -r1.9 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/netinet/in_l2tp.c
diff -u src/sys/netinet/in_l2tp.c:1.5 src/sys/netinet/in_l2tp.c:1.6
--- src/sys/netinet/in_l2tp.c:1.5	Mon Dec 11 02:17:35 2017
+++ src/sys/netinet/in_l2tp.c	Fri Dec 15 04:58:31 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: in_l2tp.c,v 1.5 2017/12/11 02:17:35 knakahara Exp $	*/
+/*	$NetBSD: in_l2tp.c,v 1.6 2017/12/15 04:58:31 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in_l2tp.c,v 1.5 2017/12/11 02:17:35 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in_l2tp.c,v 1.6 2017/12/15 04:58:31 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_l2tp.h"
@@ -368,9 +368,13 @@ in_l2tp_match(struct mbuf *m, int off, i
 
 	KASSERT(proto == IPPROTO_L2TP);
 
-	/* if payload length < 4 octets */
-	if (m->m_len < off + sizeof(uint32_t))
-		return 0;
+	if (m->m_len < off + sizeof(uint32_t)) {
+		m = m_pullup(m, off + sizeof(uint32_t));
+		if (!m) {
+			/* if payload length < 4 octets */
+			return 0;
+		}
+}
 
 	/* get L2TP session ID */
 	m_copydata(m, off, sizeof(uint32_t), (void *)&sess_id);

Index: src/sys/netinet6/in6_l2tp.c
diff -u src/sys/netinet6/in6_l2tp.c:1.8 src/sys/netinet6/in6_l2tp.c:1.9
--- src/sys/netinet6/in6_l2tp.c:1.8	Mon Dec 11 02:17:35 2017
+++ src/sys/netinet6/in6_l2tp.c	Fri Dec 15 04:58:31 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: in6_l2tp.c,v 1.8 2017/12/11 02:17:35 knakahara Exp $	*/
+/*	$NetBSD: in6_l2tp.c,v 1.9 2017/12/15 04:58:31 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in6_l2tp.c,v 1.8 2017/12/11 02:17:35 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6_l2tp.c,v 1.9 2017/12/15 04:58:31 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_l2tp.h"
@@ -360,9 +360,13 @@ in6_l2tp_match(struct mbuf *m, int off, 
 
 	KASSERT(proto == IPPROTO_L2TP);
 
-	/* if payload length < 4 octets */
-	if (m->m_len < off + sizeof(uint32_t))
-		return 0;
+	if (m->m_len < off + sizeof(uint32_t)) {
+		m = m_pullup(m, off + sizeof(uint32_t));
+		if (!m) {
+			/* if payload length < 4 octets */
+			return 0;
+		}
+}
 
 	/* get L2TP session ID */
 	m_copydata(m, off, sizeof(uint32_t), (void *)&sess_id);



CVS commit: src/share/man/man4

2017-12-12 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Dec 13 00:32:32 UTC 2017

Modified Files:
src/share/man/man4: wbsio.4

Log Message:
Update the manual of wbsio(4). Implemeted by s-yamaguchi@IIJ, reviewed by 
msaitoh@n.o.

I just commit by proxy.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/share/man/man4/wbsio.4

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/share/man/man4/wbsio.4
diff -u src/share/man/man4/wbsio.4:1.6 src/share/man/man4/wbsio.4:1.7
--- src/share/man/man4/wbsio.4:1.6	Wed Jul 12 11:23:58 2017
+++ src/share/man/man4/wbsio.4	Wed Dec 13 00:32:32 2017
@@ -1,4 +1,4 @@
-.\"	$NetBSD: wbsio.4,v 1.6 2017/07/12 11:23:58 wiz Exp $
+.\"	$NetBSD: wbsio.4,v 1.7 2017/12/13 00:32:32 knakahara Exp $
 .\"	$OpenBSD: wbsio.4,v 1.2 2008/02/17 16:48:47 jmc Exp $
 .\"
 .\" Copyright (c) 2008 Mark Kettenis 
@@ -15,7 +15,7 @@
 .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 .\"
-.Dd July 12, 2017
+.Dd December 12, 2017
 .Dt WBSIO 4
 .Os
 .Sh NAME
@@ -25,20 +25,25 @@
 .Cd "wbsio* at isa? port 0x2e"
 .Cd "wbsio* at isa? port 0x4e"
 .Cd "lm* at wbsio?"
+.Cd "gpio* at gpiobus?"
+.Pp
+.Cd "options WBSIO_GPIO"
 .Sh DESCRIPTION
 The
 .Nm
 driver provides support for the Winbond (was spun off as Nuvoton) LPC Super I/O
 ICs.
-Only the hardware monitoring function is currently supported.
+The hardware monitoring function and GPIO are currently supported.
 .Pp
 Support for the hardware monitor function is provided through the
 .Xr lm 4
-driver.
+driver. The GPIO function supports 64 pins for NCT6795D. Access to the pins
+provided by the gpio(4) interface.
 .Sh SEE ALSO
 .Xr intro 4 ,
 .Xr isa 4 ,
-.Xr lm 4
+.Xr lm 4 ,
+.Xr gpio 4
 .Sh HISTORY
 The
 .Nm



CVS commit: src/sys/dev/isa

2017-12-12 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Dec 13 00:31:46 UTC 2017

Modified Files:
src/sys/dev/isa: wbsio.c

Log Message:
Improve the error log message to use product name. Implemeted by 
s-yamaguchi@IIJ, reviewed by msaitoh@n.o.

I just commit by proxy.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/dev/isa/wbsio.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/dev/isa/wbsio.c
diff -u src/sys/dev/isa/wbsio.c:1.19 src/sys/dev/isa/wbsio.c:1.20
--- src/sys/dev/isa/wbsio.c:1.19	Wed Dec 13 00:29:02 2017
+++ src/sys/dev/isa/wbsio.c	Wed Dec 13 00:31:46 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: wbsio.c,v 1.19 2017/12/13 00:29:02 knakahara Exp $	*/
+/*	$NetBSD: wbsio.c,v 1.20 2017/12/13 00:31:46 knakahara Exp $	*/
 /*	$OpenBSD: wbsio.c,v 1.10 2015/03/14 03:38:47 jsg Exp $	*/
 /*
  * Copyright (c) 2008 Mark Kettenis 
@@ -470,7 +470,8 @@ wbsio_gpio_search(device_t parent, cfdat
 		sc->sc_gpio_rt = true;
 		break;
 	default:
-		aprint_error_dev(parent, "GPIO is not supported\n");
+		aprint_error_dev(parent, "%s's GPIO is not supported yet\n",
+		product->str);
 		return -1;
 	}
 



CVS commit: src/sys/dev/isa

2017-12-12 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Dec 13 00:29:02 UTC 2017

Modified Files:
src/sys/dev/isa: wbsio.c

Log Message:
Add an option to enable GPIO function of wbsio. Implemeted by s-yamaguchi@IIJ, 
reviewed by msaitoh@n.o.

I just commit by proxy.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/dev/isa/wbsio.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/dev/isa/wbsio.c
diff -u src/sys/dev/isa/wbsio.c:1.18 src/sys/dev/isa/wbsio.c:1.19
--- src/sys/dev/isa/wbsio.c:1.18	Wed Dec 13 00:27:53 2017
+++ src/sys/dev/isa/wbsio.c	Wed Dec 13 00:29:02 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: wbsio.c,v 1.18 2017/12/13 00:27:53 knakahara Exp $	*/
+/*	$NetBSD: wbsio.c,v 1.19 2017/12/13 00:29:02 knakahara Exp $	*/
 /*	$OpenBSD: wbsio.c,v 1.10 2015/03/14 03:38:47 jsg Exp $	*/
 /*
  * Copyright (c) 2008 Mark Kettenis 
@@ -37,9 +37,10 @@
 #include 
 
 /* Don't use gpio for now in the module */
-#ifndef _MODULE
+#if !defined(_MODULE) && defined(WBSIO_GPIO)
 #include "gpio.h"
 #endif
+
 #if NGPIO > 0
 #include 
 #endif



CVS commit: src/sys/dev/isa

2017-12-12 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Dec 13 00:27:53 UTC 2017

Modified Files:
src/sys/dev/isa: wbsio.c wbsioreg.h

Log Message:
Add Watchdog timer implementation to wbsio(4). Implemeted by s-yamaguchi@IIJ, 
reviewed by msaitoh@n.o.

I just commit by proxy.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/dev/isa/wbsio.c
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/isa/wbsioreg.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/dev/isa/wbsio.c
diff -u src/sys/dev/isa/wbsio.c:1.17 src/sys/dev/isa/wbsio.c:1.18
--- src/sys/dev/isa/wbsio.c:1.17	Wed Dec 13 00:27:01 2017
+++ src/sys/dev/isa/wbsio.c	Wed Dec 13 00:27:53 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: wbsio.c,v 1.17 2017/12/13 00:27:01 knakahara Exp $	*/
+/*	$NetBSD: wbsio.c,v 1.18 2017/12/13 00:27:53 knakahara Exp $	*/
 /*	$OpenBSD: wbsio.c,v 1.10 2015/03/14 03:38:47 jsg Exp $	*/
 /*
  * Copyright (c) 2008 Mark Kettenis 
@@ -34,6 +34,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /* Don't use gpio for now in the module */
 #ifndef _MODULE
@@ -52,6 +53,7 @@ struct wbsio_softc {
 
 	bus_space_tag_t		sc_iot;
 	bus_space_handle_t	sc_ioh;
+	kmutex_t		sc_conf_lock;
 
 	struct isa_attach_args	sc_ia;
 	struct isa_io		sc_io;
@@ -63,6 +65,9 @@ struct wbsio_softc {
 	struct gpio_pin		sc_gpio_pins[WBSIO_GPIO_NPINS];
 	bool			sc_gpio_rt;
 #endif
+
+	struct sysmon_wdog	sc_smw;
+	bool			sc_smw_valid;
 };
 
 static const struct wbsio_product {
@@ -101,6 +106,7 @@ static int	wbsio_rescan(device_t, const 
 static void	wbsio_childdet(device_t, device_t);
 static int	wbsio_print(void *, const char *);
 static int	wbsio_search(device_t, cfdata_t, const int *, void *);
+static bool	wbsio_suspend(device_t, const pmf_qual_t *);
 #if NGPIO > 0
 static int	wbsio_gpio_search(device_t, cfdata_t, const int *, void *);
 static int	wbsio_gpio_rt_init(struct wbsio_softc *);
@@ -112,22 +118,35 @@ static void	wbsio_gpio_rt_pin_ctl(void *
 static void	wbsio_gpio_enable_nct6779d(device_t);
 static void	wbsio_gpio_pinconfig_nct6779d(device_t);
 #endif
+static void	wbsio_wdog_attach(device_t);
+static int	wbsio_wdog_detach(device_t);
+static int	wbsio_wdog_setmode(struct sysmon_wdog *);
+static int	wbsio_wdog_tickle(struct sysmon_wdog *);
+static void	wbsio_wdog_setcounter(struct wbsio_softc *, uint8_t);
+static void	wbsio_wdog_clear_timeout(struct wbsio_softc *);
 
 CFATTACH_DECL2_NEW(wbsio, sizeof(struct wbsio_softc),
 wbsio_match, wbsio_attach, wbsio_detach, NULL,
 wbsio_rescan, wbsio_childdet);
 
 static __inline void
-wbsio_conf_enable(bus_space_tag_t iot, bus_space_handle_t ioh)
+wbsio_conf_enable(kmutex_t *lock, bus_space_tag_t iot, bus_space_handle_t ioh)
 {
+	if (lock)
+		mutex_enter(lock);
+
 	bus_space_write_1(iot, ioh, WBSIO_INDEX, WBSIO_CONF_EN_MAGIC);
 	bus_space_write_1(iot, ioh, WBSIO_INDEX, WBSIO_CONF_EN_MAGIC);
 }
 
 static __inline void
-wbsio_conf_disable(bus_space_tag_t iot, bus_space_handle_t ioh)
+wbsio_conf_disable(kmutex_t *lock, bus_space_tag_t iot, bus_space_handle_t ioh)
 {
+
 	bus_space_write_1(iot, ioh, WBSIO_INDEX, WBSIO_CONF_DS_MAGIC);
+
+	if (lock)
+		mutex_exit(lock);
 }
 
 static __inline uint8_t
@@ -188,11 +207,11 @@ wbsio_match(device_t parent, cfdata_t ma
 	iot = ia->ia_iot;
 	if (bus_space_map(iot, ia->ia_io[0].ir_addr, WBSIO_IOSIZE, 0, &ioh))
 		return 0;
-	wbsio_conf_enable(iot, ioh);
+	wbsio_conf_enable(NULL, iot, ioh);
 	id = wbsio_conf_read(iot, ioh, WBSIO_ID);
 	rev = wbsio_conf_read(iot, ioh, WBSIO_REV);
 	aprint_debug("wbsio_probe: id 0x%02x, rev 0x%02x\n", id, rev);
-	wbsio_conf_disable(iot, ioh);
+	wbsio_conf_disable(NULL, iot, ioh);
 	bus_space_unmap(iot, ioh, WBSIO_IOSIZE);
 
 	if ((product = wbsio_lookup(id, rev)) == NULL)
@@ -228,8 +247,10 @@ wbsio_attach(device_t parent, device_t s
 		return;
 	}
 
+	mutex_init(&sc->sc_conf_lock, MUTEX_DEFAULT, IPL_NONE);
+
 	/* Enter configuration mode */
-	wbsio_conf_enable(sc->sc_iot, sc->sc_ioh);
+	wbsio_conf_enable(&sc->sc_conf_lock, sc->sc_iot, sc->sc_ioh);
 
 	/* Read device ID */
 	id = wbsio_conf_read(sc->sc_iot, sc->sc_ioh, WBSIO_ID);
@@ -237,7 +258,7 @@ wbsio_attach(device_t parent, device_t s
 	rev = wbsio_conf_read(sc->sc_iot, sc->sc_ioh, WBSIO_REV);
 
 	/* Escape from configuration mode */
-	wbsio_conf_disable(sc->sc_iot, sc->sc_ioh);
+	wbsio_conf_disable(&sc->sc_conf_lock, sc->sc_iot, sc->sc_ioh);
 
 	if ((product = wbsio_lookup(id, rev)) == NULL) {
 		aprint_error_dev(self, "Unknown device. Failed to attach\n");
@@ -259,8 +280,11 @@ wbsio_attach(device_t parent, device_t s
 	} else
 		aprint_normal("0x%02x\n", rev);
 
-	if (!pmf_device_register(self, NULL, NULL))
+	if (!pmf_device_register(self, wbsio_suspend, NULL))
 		aprint_error_dev(self, "couldn't establish power handler\n");
+
+	wbsio_wdog_attach(self);
+
 	wbsio_rescan(self, "wbsio", NULL);
 
 #if NGPIO > 0
@@ -275,6 +299,9 @@ wbsio_detach(device_t self, int flags)
 	struct wbsio_s

CVS commit: src/sys/dev/isa

2017-12-12 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Dec 13 00:27:01 UTC 2017

Modified Files:
src/sys/dev/isa: wbsio.c

Log Message:
Fix NCT6779 gpio pin configuration. Implemeted by s-yamaguchi@IIJ, reviewed by 
msaitoh@n.o.

I just commit by proxy.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/dev/isa/wbsio.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/dev/isa/wbsio.c
diff -u src/sys/dev/isa/wbsio.c:1.16 src/sys/dev/isa/wbsio.c:1.17
--- src/sys/dev/isa/wbsio.c:1.16	Wed Dec 13 00:26:06 2017
+++ src/sys/dev/isa/wbsio.c	Wed Dec 13 00:27:01 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: wbsio.c,v 1.16 2017/12/13 00:26:06 knakahara Exp $	*/
+/*	$NetBSD: wbsio.c,v 1.17 2017/12/13 00:27:01 knakahara Exp $	*/
 /*	$OpenBSD: wbsio.c,v 1.10 2015/03/14 03:38:47 jsg Exp $	*/
 /*
  * Copyright (c) 2008 Mark Kettenis 
@@ -668,7 +668,7 @@ wbsio_gpio_pinconfig_nct6779d(device_t p
 	mfs2 |= WBSIO_NCT6779D_MFS2_GP04;
 	mfs2 |= WBSIO_NCT6779D_MFS2_GP05;
 	mfs2 |= WBSIO_NCT6779D_MFS2_GP06;
-	mfs3 |= WBSIO_NCT6779D_MFS3_GP07_MASK;
+	mfs3 &= ~WBSIO_NCT6779D_MFS3_GP07_MASK;
 
 	/* GPIO1 pin configs */
 	mfs4 |= WBSIO_NCT6779D_MFS4_GP10_GP17;
@@ -703,7 +703,7 @@ wbsio_gpio_pinconfig_nct6779d(device_t p
 	mfs1 |= WBSIO_NCT6779D_MFS1_GP42;
 	mfs1 |= WBSIO_NCT6779D_MFS1_GP42;
 	gopt2 |= WBSIO_NCT6779D_GOPT2_GP43;
-	mfs1 |= WBSIO_NCT6779D_MFS1_GP44_GP45_MASK;
+	mfs1 &= ~WBSIO_NCT6779D_MFS1_GP44_GP45_MASK;
 	gopt2 &= ~WBSIO_NCT6779D_GOPT2_GP46_MASK;
 	mfs1 |= WBSIO_NCT6779D_MFS1_GP47;
 



CVS commit: src/sys/dev/isa

2017-12-12 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Dec 13 00:26:06 UTC 2017

Modified Files:
src/sys/dev/isa: files.isa wbsio.c wbsioreg.h

Log Message:
Add wbsio(4) GPIO driver. Implemeted by s-yamaguchi@IIJ, reviewed by 
msaitoh@n.o.

I just commit by proxy.


To generate a diff of this commit:
cvs rdiff -u -r1.167 -r1.168 src/sys/dev/isa/files.isa
cvs rdiff -u -r1.15 -r1.16 src/sys/dev/isa/wbsio.c
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/isa/wbsioreg.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/dev/isa/files.isa
diff -u src/sys/dev/isa/files.isa:1.167 src/sys/dev/isa/files.isa:1.168
--- src/sys/dev/isa/files.isa:1.167	Fri Dec  9 04:32:39 2016
+++ src/sys/dev/isa/files.isa	Wed Dec 13 00:26:06 2017
@@ -1,4 +1,4 @@
-#	$NetBSD: files.isa,v 1.167 2016/12/09 04:32:39 christos Exp $
+#	$NetBSD: files.isa,v 1.168 2017/12/13 00:26:06 knakahara Exp $
 #
 # Config file and device description for machine-independent ISA code.
 # Included by ports that need it.  Requires that the SCSI files be
@@ -454,7 +454,7 @@ attach	smsc at isa with smsc
 file	dev/isa/smsc.c			smsc			needs-flag
 
 # Winbond LPC Super I/O
-device	wbsio {}
+device	wbsio { }: gpiobus
 attach	wbsio at isa
 file	dev/isa/wbsio.c			wbsio
 

Index: src/sys/dev/isa/wbsio.c
diff -u src/sys/dev/isa/wbsio.c:1.15 src/sys/dev/isa/wbsio.c:1.16
--- src/sys/dev/isa/wbsio.c:1.15	Fri Aug 18 04:07:51 2017
+++ src/sys/dev/isa/wbsio.c	Wed Dec 13 00:26:06 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: wbsio.c,v 1.15 2017/08/18 04:07:51 msaitoh Exp $	*/
+/*	$NetBSD: wbsio.c,v 1.16 2017/12/13 00:26:06 knakahara Exp $	*/
 /*	$OpenBSD: wbsio.c,v 1.10 2015/03/14 03:38:47 jsg Exp $	*/
 /*
  * Copyright (c) 2008 Mark Kettenis 
@@ -20,11 +20,14 @@
  * Winbond LPC Super I/O driver.
  */
 
+#include 
 #include 
 #include 
 #include 
 #include 
 #include 
+#include 
+#include 
 
 #include 
 
@@ -32,15 +35,34 @@
 #include 
 #include 
 
+/* Don't use gpio for now in the module */
+#ifndef _MODULE
+#include "gpio.h"
+#endif
+#if NGPIO > 0
+#include 
+#endif
+
 struct wbsio_softc {
 	device_t	sc_dev;
 	device_t	sc_lm_dev;
+#if NGPIO > 0
+	device_t	sc_gpio_dev;
+#endif
 
 	bus_space_tag_t		sc_iot;
 	bus_space_handle_t	sc_ioh;
 
 	struct isa_attach_args	sc_ia;
 	struct isa_io		sc_io;
+
+#if NGPIO > 0
+	bus_space_handle_t	sc_gpio_ioh;
+	kmutex_t		sc_gpio_lock;
+	struct gpio_chipset_tag	sc_gpio_gc;
+	struct gpio_pin		sc_gpio_pins[WBSIO_GPIO_NPINS];
+	bool			sc_gpio_rt;
+#endif
 };
 
 static const struct wbsio_product {
@@ -79,6 +101,17 @@ static int	wbsio_rescan(device_t, const 
 static void	wbsio_childdet(device_t, device_t);
 static int	wbsio_print(void *, const char *);
 static int	wbsio_search(device_t, cfdata_t, const int *, void *);
+#if NGPIO > 0
+static int	wbsio_gpio_search(device_t, cfdata_t, const int *, void *);
+static int	wbsio_gpio_rt_init(struct wbsio_softc *);
+static int	wbsio_gpio_rt_read(struct wbsio_softc *, int, int);
+static void	wbsio_gpio_rt_write(struct wbsio_softc *, int, int, int);
+static int	wbsio_gpio_rt_pin_read(void *, int);
+static void	wbsio_gpio_rt_pin_write(void *, int, int);
+static void	wbsio_gpio_rt_pin_ctl(void *, int, int);
+static void	wbsio_gpio_enable_nct6779d(device_t);
+static void	wbsio_gpio_pinconfig_nct6779d(device_t);
+#endif
 
 CFATTACH_DECL2_NEW(wbsio, sizeof(struct wbsio_softc),
 wbsio_match, wbsio_attach, wbsio_detach, NULL,
@@ -229,6 +262,11 @@ wbsio_attach(device_t parent, device_t s
 	if (!pmf_device_register(self, NULL, NULL))
 		aprint_error_dev(self, "couldn't establish power handler\n");
 	wbsio_rescan(self, "wbsio", NULL);
+
+#if NGPIO > 0
+
+	wbsio_rescan(self, "gpiobus", NULL);
+#endif
 }
 
 int
@@ -241,6 +279,17 @@ wbsio_detach(device_t self, int flags)
 		return rc;
 	bus_space_unmap(sc->sc_iot, sc->sc_ioh, WBSIO_IOSIZE);
 	pmf_device_deregister(self);
+
+#if NGPIO > 0
+	if (sc->sc_gpio_dev) {
+		bus_space_unmap(sc->sc_iot, sc->sc_gpio_ioh,
+		WBSIO_GPIO_IOSIZE);
+	}
+
+	if (sc->sc_gpio_rt) {
+		mutex_destroy(&sc->sc_gpio_lock);
+	}
+#endif
 	return 0;
 }
 
@@ -248,6 +297,13 @@ int
 wbsio_rescan(device_t self, const char *ifattr, const int *locators)
 {
 
+#if NGPIO > 0
+	if (ifattr_match(ifattr, "gpiobus")) {
+		config_search_loc(wbsio_gpio_search, self,
+		ifattr, locators, NULL);
+		return 0;
+	}
+#endif
 	config_search_loc(wbsio_search, self, ifattr, locators, NULL);
 
 	return 0;
@@ -338,6 +394,357 @@ wbsio_print(void *aux, const char *pnp)
 	return (UNCONF);
 }
 
+#if NGPIO > 0
+static int
+wbsio_gpio_search(device_t parent, cfdata_t cf, const int *slocs, void *aux)
+{
+	struct wbsio_softc *sc = device_private(parent);
+	const struct wbsio_product *product;
+	struct gpiobus_attach_args gba;
+	uint16_t devid;
+	uint8_t rev;
+	int i;
+
+	/* Enter configuration mode */
+	wbsio_conf_enable(sc->sc_iot, sc->sc_ioh);
+	/* Read device ID and revision */
+	devid = wbsio_conf_read(sc->sc_iot, sc->sc_ioh, WB

CVS commit: src/sys

2017-12-10 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Dec 11 02:33:17 UTC 2017

Modified Files:
src/sys/kern: subr_psref.c
src/sys/sys: psref.h

Log Message:
Fix psref(9) part of PR kern/52515. It is complete to fix the PR now.

implementated by ozaki-r@n.o, reviewed by riastradh@n.o, thanks.

XXX need pullup-8


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/kern/subr_psref.c
cvs rdiff -u -r1.2 -r1.3 src/sys/sys/psref.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/kern/subr_psref.c
diff -u src/sys/kern/subr_psref.c:1.7 src/sys/kern/subr_psref.c:1.8
--- src/sys/kern/subr_psref.c:1.7	Thu Jun  1 02:45:13 2017
+++ src/sys/kern/subr_psref.c	Mon Dec 11 02:33:17 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_psref.c,v 1.7 2017/06/01 02:45:13 chs Exp $	*/
+/*	$NetBSD: subr_psref.c,v 1.8 2017/12/11 02:33:17 knakahara Exp $	*/
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: subr_psref.c,v 1.7 2017/06/01 02:45:13 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_psref.c,v 1.8 2017/12/11 02:33:17 knakahara Exp $");
 
 #include 
 #include 
@@ -78,7 +78,7 @@ __KERNEL_RCSID(0, "$NetBSD: subr_psref.c
 #include 
 #include 
 
-LIST_HEAD(psref_head, psref);
+SLIST_HEAD(psref_head, psref);
 
 static bool	_psref_held(const struct psref_target *, struct psref_class *,
 		bool);
@@ -135,7 +135,7 @@ psref_cpu_drained_p(void *p, void *cooki
 	const struct psref_cpu *pcpu = p;
 	bool *retp = cookie;
 
-	if (!LIST_EMPTY(&pcpu->pcpu_head))
+	if (!SLIST_EMPTY(&pcpu->pcpu_head))
 		*retp = false;
 }
 
@@ -194,7 +194,7 @@ psref_check_duplication(struct psref_cpu
 	bool found = false;
 	struct psref *_psref;
 
-	LIST_FOREACH(_psref, &pcpu->pcpu_head, psref_entry) {
+	SLIST_FOREACH(_psref, &pcpu->pcpu_head, psref_entry) {
 		if (_psref == psref &&
 		_psref->psref_target == target) {
 			found = true;
@@ -250,7 +250,7 @@ psref_acquire(struct psref *psref, const
 #endif
 
 	/* Record our reference.  */
-	LIST_INSERT_HEAD(&pcpu->pcpu_head, psref, psref_entry);
+	SLIST_INSERT_HEAD(&pcpu->pcpu_head, psref, psref_entry);
 	psref->psref_target = target;
 	psref->psref_lwp = curlwp;
 	psref->psref_cpu = curcpu();
@@ -273,6 +273,7 @@ void
 psref_release(struct psref *psref, const struct psref_target *target,
 struct psref_class *class)
 {
+	struct psref_cpu *pcpu;
 	int s;
 
 	KASSERTMSG((kpreempt_disabled() || cpu_softintr_p() ||
@@ -302,7 +303,9 @@ psref_release(struct psref *psref, const
 	 * (as does blocking interrupts).
 	 */
 	s = splraiseipl(class->prc_iplcookie);
-	LIST_REMOVE(psref, psref_entry);
+	pcpu = percpu_getref(class->prc_percpu);
+	SLIST_REMOVE(&pcpu->pcpu_head, psref, psref, psref_entry);
+	percpu_putref(class->prc_percpu);
 	splx(s);
 
 	/* If someone is waiting for users to drain, notify 'em.  */
@@ -353,7 +356,7 @@ psref_copy(struct psref *pto, const stru
 	pcpu = percpu_getref(class->prc_percpu);
 
 	/* Record the new reference.  */
-	LIST_INSERT_HEAD(&pcpu->pcpu_head, pto, psref_entry);
+	SLIST_INSERT_HEAD(&pcpu->pcpu_head, pto, psref_entry);
 	pto->psref_target = pfrom->psref_target;
 	pto->psref_lwp = curlwp;
 	pto->psref_cpu = curcpu();
@@ -474,7 +477,7 @@ _psref_held(const struct psref_target *t
 	pcpu = percpu_getref(class->prc_percpu);
 
 	/* Search through all the references on this CPU.  */
-	LIST_FOREACH(psref, &pcpu->pcpu_head, psref_entry) {
+	SLIST_FOREACH(psref, &pcpu->pcpu_head, psref_entry) {
 		/* Sanity-check the reference's CPU.  */
 		KASSERTMSG((psref->psref_cpu == curcpu()),
 		"passive reference transferred from CPU %u to CPU %u",

Index: src/sys/sys/psref.h
diff -u src/sys/sys/psref.h:1.2 src/sys/sys/psref.h:1.3
--- src/sys/sys/psref.h:1.2	Fri Dec 16 20:12:11 2016
+++ src/sys/sys/psref.h	Mon Dec 11 02:33:17 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: psref.h,v 1.2 2016/12/16 20:12:11 christos Exp $	*/
+/*	$NetBSD: psref.h,v 1.3 2017/12/11 02:33:17 knakahara Exp $	*/
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -69,7 +69,9 @@ struct psref_target {
  *	written only on the local CPU.
  */
 struct psref {
-	LIST_ENTRY(psref)		psref_entry;
+	SLIST_ENTRY(psref)		psref_entry;
+	/* To keep ABI with LIST_ENTRY(psref) version. */
+	void*psref_unused0;
 	const struct psref_target	*psref_target;
 	struct lwp			*psref_lwp;
 	struct cpu_info			*psref_cpu;



CVS commit: src/sys

2017-12-10 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Dec 11 02:17:35 UTC 2017

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

Log Message:
fix pullup'ed mbuf leaks. pointed out by maxv@n.o, thanks.

XXX need pullup-8


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/netinet/in_l2tp.c
cvs rdiff -u -r1.7 -r1.8 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/netinet/in_l2tp.c
diff -u src/sys/netinet/in_l2tp.c:1.4 src/sys/netinet/in_l2tp.c:1.5
--- src/sys/netinet/in_l2tp.c:1.4	Wed Nov 15 10:42:41 2017
+++ src/sys/netinet/in_l2tp.c	Mon Dec 11 02:17:35 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: in_l2tp.c,v 1.4 2017/11/15 10:42:41 knakahara Exp $	*/
+/*	$NetBSD: in_l2tp.c,v 1.5 2017/12/11 02:17:35 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in_l2tp.c,v 1.4 2017/11/15 10:42:41 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in_l2tp.c,v 1.5 2017/12/11 02:17:35 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_l2tp.h"
@@ -368,13 +368,9 @@ in_l2tp_match(struct mbuf *m, int off, i
 
 	KASSERT(proto == IPPROTO_L2TP);
 
-	if (m->m_len < off + sizeof(uint32_t)) {
-		m = m_pullup(m, off + sizeof(uint32_t));
-		if (!m) {
-			/* if payload length < 4 octets */
-			return 0;
-		}
-}
+	/* if payload length < 4 octets */
+	if (m->m_len < off + sizeof(uint32_t))
+		return 0;
 
 	/* get L2TP session ID */
 	m_copydata(m, off, sizeof(uint32_t), (void *)&sess_id);

Index: src/sys/netinet6/in6_l2tp.c
diff -u src/sys/netinet6/in6_l2tp.c:1.7 src/sys/netinet6/in6_l2tp.c:1.8
--- src/sys/netinet6/in6_l2tp.c:1.7	Wed Nov 15 10:42:41 2017
+++ src/sys/netinet6/in6_l2tp.c	Mon Dec 11 02:17:35 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: in6_l2tp.c,v 1.7 2017/11/15 10:42:41 knakahara Exp $	*/
+/*	$NetBSD: in6_l2tp.c,v 1.8 2017/12/11 02:17:35 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in6_l2tp.c,v 1.7 2017/11/15 10:42:41 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6_l2tp.c,v 1.8 2017/12/11 02:17:35 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_l2tp.h"
@@ -360,13 +360,9 @@ in6_l2tp_match(struct mbuf *m, int off, 
 
 	KASSERT(proto == IPPROTO_L2TP);
 
-	if (m->m_len < off + sizeof(uint32_t)) {
-		m = m_pullup(m, off + sizeof(uint32_t));
-		if (!m) {
-			/* if payload length < 4 octets */
-			return 0;
-		}
-}
+	/* if payload length < 4 octets */
+	if (m->m_len < off + sizeof(uint32_t))
+		return 0;
 
 	/* get L2TP session ID */
 	m_copydata(m, off, sizeof(uint32_t), (void *)&sess_id);



CVS commit: src/sys/sys

2017-12-06 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Dec  6 08:25:47 UTC 2017

Modified Files:
src/sys/sys: param.h

Log Message:
Bump kernel version for if_tunnel_check_nesting() used by gif(4) and l2tp(4) 
modules.

Welcome to 8.99.9


To generate a diff of this commit:
cvs rdiff -u -r1.553 -r1.554 src/sys/sys/param.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/sys/param.h
diff -u src/sys/sys/param.h:1.553 src/sys/sys/param.h:1.554
--- src/sys/sys/param.h:1.553	Fri Dec  1 19:04:19 2017
+++ src/sys/sys/param.h	Wed Dec  6 08:25:47 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: param.h,v 1.553 2017/12/01 19:04:19 christos Exp $	*/
+/*	$NetBSD: param.h,v 1.554 2017/12/06 08:25:47 knakahara Exp $	*/
 
 /*-
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -67,7 +67,7 @@
  *	2.99.9		(299000900)
  */
 
-#define	__NetBSD_Version__	899000800	/* NetBSD 8.99.8 */
+#define	__NetBSD_Version__	899000900	/* NetBSD 8.99.9 */
 
 #define __NetBSD_Prereq__(M,m,p) (M) * 1) + \
 (m) * 100) + (p) * 100) <= __NetBSD_Version__)



CVS commit: src/sys/net

2017-12-06 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Dec  6 08:23:17 UTC 2017

Modified Files:
src/sys/net: if.c if.h if_gif.c if_l2tp.c

Log Message:
unify processing to check nesting count for some tunnel protocols.


To generate a diff of this commit:
cvs rdiff -u -r1.403 -r1.404 src/sys/net/if.c
cvs rdiff -u -r1.247 -r1.248 src/sys/net/if.h
cvs rdiff -u -r1.134 -r1.135 src/sys/net/if_gif.c
cvs rdiff -u -r1.15 -r1.16 src/sys/net/if_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/net/if.c
diff -u src/sys/net/if.c:1.403 src/sys/net/if.c:1.404
--- src/sys/net/if.c:1.403	Wed Dec  6 08:12:54 2017
+++ src/sys/net/if.c	Wed Dec  6 08:23:17 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.403 2017/12/06 08:12:54 ozaki-r Exp $	*/
+/*	$NetBSD: if.c,v 1.404 2017/12/06 08:23:17 knakahara Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc.
@@ -90,7 +90,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.403 2017/12/06 08:12:54 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.404 2017/12/06 08:23:17 knakahara Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -2762,6 +2762,43 @@ if_held(struct ifnet *ifp)
 	return psref_held(&ifp->if_psref, ifnet_psref_class);
 }
 
+/*
+ * Some tunnel interfaces can nest, e.g. IPv4 over IPv4 gif(4) tunnel over IPv4.
+ * Check the tunnel nesting count.
+ * Return > 0, if tunnel nesting count is more than limit.
+ * Return 0, if tunnel nesting count is equal or less than limit.
+ */
+int
+if_tunnel_check_nesting(struct ifnet *ifp, struct mbuf *m, int limit)
+{
+	struct m_tag *mtag;
+	int *count;
+
+	mtag = m_tag_find(m, PACKET_TAG_TUNNEL_INFO, NULL);
+	if (mtag != NULL) {
+		count = (int *)(mtag + 1);
+		if (++(*count) > limit) {
+			log(LOG_NOTICE,
+			"%s: recursively called too many times(%d)\n",
+			ifp->if_xname, *count);
+			return EIO;
+		}
+	} else {
+		mtag = m_tag_get(PACKET_TAG_TUNNEL_INFO, sizeof(*count),
+		M_NOWAIT);
+		if (mtag != NULL) {
+			m_tag_prepend(m, mtag);
+			count = (int *)(mtag + 1);
+			*count = 0;
+		} else {
+			log(LOG_DEBUG,
+			"%s: m_tag_get() failed, recursion calls are not prevented.\n",
+			ifp->if_xname);
+		}
+	}
+
+	return 0;
+}
 
 /* common */
 int

Index: src/sys/net/if.h
diff -u src/sys/net/if.h:1.247 src/sys/net/if.h:1.248
--- src/sys/net/if.h:1.247	Wed Dec  6 08:12:54 2017
+++ src/sys/net/if.h	Wed Dec  6 08:23:17 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.h,v 1.247 2017/12/06 08:12:54 ozaki-r Exp $	*/
+/*	$NetBSD: if.h,v 1.248 2017/12/06 08:23:17 knakahara Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc.
@@ -1034,6 +1034,8 @@ void	if_put(const struct ifnet *, struct
 void	if_acquire(struct ifnet *, struct psref *);
 #define	if_release	if_put
 
+int if_tunnel_check_nesting(struct ifnet *, struct mbuf *, int);
+
 static inline if_index_t
 if_get_index(const struct ifnet *ifp)
 {

Index: src/sys/net/if_gif.c
diff -u src/sys/net/if_gif.c:1.134 src/sys/net/if_gif.c:1.135
--- src/sys/net/if_gif.c:1.134	Mon Nov 27 05:05:50 2017
+++ src/sys/net/if_gif.c	Wed Dec  6 08:23:17 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_gif.c,v 1.134 2017/11/27 05:05:50 knakahara Exp $	*/
+/*	$NetBSD: if_gif.c,v 1.135 2017/12/06 08:23:17 knakahara Exp $	*/
 /*	$KAME: if_gif.c,v 1.76 2001/08/20 02:01:02 kjc Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.134 2017/11/27 05:05:50 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.135 2017/12/06 08:23:17 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -445,34 +445,8 @@ out:
 static int
 gif_check_nesting(struct ifnet *ifp, struct mbuf *m)
 {
-	struct m_tag *mtag;
-	int *count;
 
-	mtag = m_tag_find(m, PACKET_TAG_TUNNEL_INFO, NULL);
-	if (mtag != NULL) {
-		count = (int *)(mtag + 1);
-		if (++(*count) > max_gif_nesting) {
-			log(LOG_NOTICE,
-			"%s: recursively called too many times(%d)\n",
-			if_name(ifp),
-			*count);
-			return EIO;
-		}
-	} else {
-		mtag = m_tag_get(PACKET_TAG_TUNNEL_INFO, sizeof(*count),
-		M_NOWAIT);
-		if (mtag != NULL) {
-			m_tag_prepend(m, mtag);
-			count = (int *)(mtag + 1);
-			*count = 0;
-		} else {
-			log(LOG_DEBUG,
-			"%s: m_tag_get() failed, recursion calls are not prevented.\n",
-			if_name(ifp));
-		}
-	}
-
-	return 0;
+	return if_tunnel_check_nesting(ifp, m, max_gif_nesting);
 }
 
 static int

Index: src/sys/net/if_l2tp.c
diff -u src/sys/net/if_l2tp.c:1.15 src/sys/net/if_l2tp.c:1.16
--- src/sys/net/if_l2tp.c:1.15	Thu Nov 16 03:07:18 2017
+++ src/sys/net/if_l2tp.c	Wed Dec  6 08:23:17 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_l2tp.c,v 1.15 2017/11/16 03:07:18 ozaki-r Exp $	*/
+/*	$NetBSD: if_l2tp.c,v 1.16 2017/12/06 08:23:17 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_l2tp.c,v 1.1

CVS commit: src/sys

2017-11-26 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Nov 27 05:05:51 UTC 2017

Modified Files:
src/sys/net: if_gif.c
src/sys/netinet: in_gif.c
src/sys/netinet6: in6_gif.c

Log Message:
IFF_RUNNING checking in Rx and Tx processing is unnecessary now.

Because the configs of gif (members of gif_var) are protected by psref(9).


To generate a diff of this commit:
cvs rdiff -u -r1.133 -r1.134 src/sys/net/if_gif.c
cvs rdiff -u -r1.90 -r1.91 src/sys/netinet/in_gif.c
cvs rdiff -u -r1.88 -r1.89 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/net/if_gif.c
diff -u src/sys/net/if_gif.c:1.133 src/sys/net/if_gif.c:1.134
--- src/sys/net/if_gif.c:1.133	Mon Nov 27 05:02:22 2017
+++ src/sys/net/if_gif.c	Mon Nov 27 05:05:50 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_gif.c,v 1.133 2017/11/27 05:02:22 knakahara Exp $	*/
+/*	$NetBSD: if_gif.c,v 1.134 2017/11/27 05:05:50 knakahara Exp $	*/
 /*	$KAME: if_gif.c,v 1.76 2001/08/20 02:01:02 kjc Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.133 2017/11/27 05:02:22 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.134 2017/11/27 05:05:50 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -378,8 +378,7 @@ gif_encapcheck(struct mbuf *m, int off, 
 	if (sc == NULL)
 		return 0;
 
-	if ((sc->gif_if.if_flags & (IFF_UP|IFF_RUNNING))
-	!= (IFF_UP|IFF_RUNNING))
+	if ((sc->gif_if.if_flags & IFF_UP) == 0)
 		return 0;
 
 	var = gif_getref_variant(sc, &psref);
@@ -492,7 +491,7 @@ gif_output(struct ifnet *ifp, struct mbu
 		goto end;
 	}
 
-	if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING)) {
+	if ((ifp->if_flags & IFF_UP) == 0) {
 		m_freem(m);
 		error = ENETDOWN;
 		goto end;

Index: src/sys/netinet/in_gif.c
diff -u src/sys/netinet/in_gif.c:1.90 src/sys/netinet/in_gif.c:1.91
--- src/sys/netinet/in_gif.c:1.90	Mon Nov 27 05:02:22 2017
+++ src/sys/netinet/in_gif.c	Mon Nov 27 05:05:51 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: in_gif.c,v 1.90 2017/11/27 05:02:22 knakahara Exp $	*/
+/*	$NetBSD: in_gif.c,v 1.91 2017/11/27 05:05:51 knakahara Exp $	*/
 /*	$KAME: in_gif.c,v 1.66 2001/07/29 04:46:09 itojun Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in_gif.c,v 1.90 2017/11/27 05:02:22 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in_gif.c,v 1.91 2017/11/27 05:05:51 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -216,7 +216,7 @@ in_gif_input(struct mbuf *m, int off, in
 	ip = mtod(m, const struct ip *);
 
 	gifp = &sc->gif_if;
-	if ((gifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING)) {
+	if ((gifp->if_flags & IFF_UP) == 0) {
 		m_freem(m);
 		ip_statinc(IP_STAT_NOGIF);
 		return;

Index: src/sys/netinet6/in6_gif.c
diff -u src/sys/netinet6/in6_gif.c:1.88 src/sys/netinet6/in6_gif.c:1.89
--- src/sys/netinet6/in6_gif.c:1.88	Mon Nov 27 05:02:22 2017
+++ src/sys/netinet6/in6_gif.c	Mon Nov 27 05:05:51 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: in6_gif.c,v 1.88 2017/11/27 05:02:22 knakahara Exp $	*/
+/*	$NetBSD: in6_gif.c,v 1.89 2017/11/27 05:05:51 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.88 2017/11/27 05:02:22 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6_gif.c,v 1.89 2017/11/27 05:05:51 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -233,7 +233,7 @@ in6_gif_input(struct mbuf **mp, int *off
 	ip6 = mtod(m, struct ip6_hdr *);
 
 	gifp = &sc->gif_if;
-	if ((gifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING)) {
+	if ((gifp->if_flags & IFF_UP) == 0) {
 		m_freem(m);
 		IP6_STATINC(IP6_STAT_NOGIF);
 		return IPPROTO_DONE;



CVS commit: src/sys/net

2017-11-26 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Nov 27 05:03:11 UTC 2017

Modified Files:
src/sys/net: if_gif.h

Log Message:
update gif(4) locking notes.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sys/net/if_gif.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/net/if_gif.h
diff -u src/sys/net/if_gif.h:1.28 src/sys/net/if_gif.h:1.29
--- src/sys/net/if_gif.h:1.28	Mon Nov 27 05:02:22 2017
+++ src/sys/net/if_gif.h	Mon Nov 27 05:03:11 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_gif.h,v 1.28 2017/11/27 05:02:22 knakahara Exp $	*/
+/*	$NetBSD: if_gif.h,v 1.29 2017/11/27 05:03:11 knakahara Exp $	*/
 /*	$KAME: if_gif.h,v 1.23 2001/07/27 09:21:42 itojun Exp $	*/
 
 /*
@@ -140,14 +140,15 @@ int	gif_encapcheck(struct mbuf *, int, i
  * + gif_softc_list is protected by gif_softcs.lock (an adaptive mutex)
  *   gif_softc_list is list of all gif_softcs. It is used by ioctl
  *   context only.
- * + Members of struct gif_softc except for gif_ro_percpu are protected by
- *   - encap_lock for writer
- *   - stopping processing when writer begin to run
- * for reader(Tx and Rx processing)
+ * + gif_softc->gif_var is protected by
+ *   - gif_softc->gif_lock (an adaptive mutex) for writer
+ *   - gif_var->gv_psref for reader
+ *   gif_softc->gif_var is used for variant values while the gif tunnel
+ *   exists.
  * + Each CPU's gif_ro.gr_ro of gif_ro_percpu are protected by
  *   percpu'ed gif_ro.gr_lock.
  *
  * Locking order:
- * - encap_lock => gif_softcs.lock
+ * - encap_lock => gif_softc->gif_lock => gif_softcs.lock
  */
 #endif /* !_NET_IF_GIF_H_ */



CVS commit: src/sys

2017-11-26 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Nov 27 05:02:22 UTC 2017

Modified Files:
src/sys/net: if_gif.c if_gif.h
src/sys/netinet: in_gif.c in_gif.h
src/sys/netinet6: in6_gif.c in6_gif.h

Log Message:
preserve gif(4) configs by psref(9) like vlan(4) and l2tp(4).

After Tx side does not use softint, gif(4) can use psref(9) for config
preservation like vlan(4) and l2tp(4).

update locking notes later.


To generate a diff of this commit:
cvs rdiff -u -r1.132 -r1.133 src/sys/net/if_gif.c
cvs rdiff -u -r1.27 -r1.28 src/sys/net/if_gif.h
cvs rdiff -u -r1.89 -r1.90 src/sys/netinet/in_gif.c
cvs rdiff -u -r1.17 -r1.18 src/sys/netinet/in_gif.h
cvs rdiff -u -r1.87 -r1.88 src/sys/netinet6/in6_gif.c
cvs rdiff -u -r1.16 -r1.17 src/sys/netinet6/in6_gif.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/net/if_gif.c
diff -u src/sys/net/if_gif.c:1.132 src/sys/net/if_gif.c:1.133
--- src/sys/net/if_gif.c:1.132	Thu Nov 16 03:07:18 2017
+++ src/sys/net/if_gif.c	Mon Nov 27 05:02:22 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_gif.c,v 1.132 2017/11/16 03:07:18 ozaki-r Exp $	*/
+/*	$NetBSD: if_gif.c,v 1.133 2017/11/27 05:02:22 knakahara Exp $	*/
 /*	$KAME: if_gif.c,v 1.76 2001/08/20 02:01:02 kjc Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.132 2017/11/16 03:07:18 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.133 2017/11/27 05:02:22 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -57,6 +57,9 @@ __KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1
 #include 
 #include 
 #include 
+#include 
+#include 
+#include 
 
 #include 
 #include 
@@ -102,6 +105,9 @@ static struct {
 	kmutex_t lock;
 } gif_softcs __cacheline_aligned;
 
+pserialize_t gif_psz __read_mostly;
+struct psref_class *gv_psref_class __read_mostly;
+
 static void	gif_ro_init_pc(void *, void *, struct cpu_info *);
 static void	gif_ro_fini_pc(void *, void *, struct cpu_info *);
 
@@ -110,6 +116,7 @@ static int	gif_output(struct ifnet *, st
 			   const struct sockaddr *, const struct rtentry *);
 static void	gif_start(struct ifnet *);
 static int	gif_transmit(struct ifnet *, struct mbuf *);
+static int	gif_transmit_direct(struct gif_variant *, struct mbuf *);
 static int	gif_ioctl(struct ifnet *, u_long, void *);
 static int	gif_set_tunnel(struct ifnet *, struct sockaddr *,
 			   struct sockaddr *);
@@ -119,9 +126,10 @@ static int	gif_clone_create(struct if_cl
 static int	gif_clone_destroy(struct ifnet *);
 static int	gif_check_nesting(struct ifnet *, struct mbuf *);
 
-static int	gif_encap_attach(struct gif_softc *);
-static int	gif_encap_detach(struct gif_softc *);
-static void	gif_encap_pause(struct gif_softc *);
+static int	gif_encap_attach(struct gif_variant *);
+static int	gif_encap_detach(struct gif_variant *);
+
+static void	gif_update_variant(struct gif_softc *, struct gif_variant *);
 
 static struct if_clone gif_cloner =
 IF_CLONE_INITIALIZER("gif", gif_clone_create, gif_clone_destroy);
@@ -216,6 +224,9 @@ gifinit(void)
 	LIST_INIT(&gif_softcs.list);
 	if_clone_attach(&gif_cloner);
 
+	gif_psz = pserialize_create();
+	gv_psref_class = psref_class_create("gifvar", IPL_SOFTNET);
+
 	gif_sysctl_setup();
 }
 
@@ -231,6 +242,9 @@ gifdetach(void)
 	}
 
 	if (error == 0) {
+		psref_class_destroy(gv_psref_class);
+		pserialize_destroy(gif_psz);
+
 		if_clone_detach(&gif_cloner);
 		sysctl_teardown(&gif_sysctl);
 	}
@@ -242,6 +256,7 @@ static int
 gif_clone_create(struct if_clone *ifc, int unit)
 {
 	struct gif_softc *sc;
+	struct gif_variant *var;
 	int rv;
 
 	sc = kmem_zalloc(sizeof(struct gif_softc), KM_SLEEP);
@@ -254,6 +269,12 @@ gif_clone_create(struct if_clone *ifc, i
 		return rv;
 	}
 
+	var = kmem_zalloc(sizeof(*var), KM_SLEEP);
+	var->gv_softc = sc;
+	psref_target_init(&var->gv_psref, gv_psref_class);
+
+	sc->gif_var = var;
+	mutex_init(&sc->gif_lock, MUTEX_DEFAULT, IPL_NONE);
 	sc->gif_ro_percpu = percpu_alloc(sizeof(struct gif_ro));
 	percpu_foreach(sc->gif_ro_percpu, gif_ro_init_pc, NULL);
 
@@ -268,8 +289,6 @@ gifattach0(struct gif_softc *sc)
 {
 	int rv;
 
-	sc->encap_cookie4 = sc->encap_cookie6 = NULL;
-
 	sc->gif_if.if_addrlen = 0;
 	sc->gif_if.if_mtu= GIF_MTU;
 	sc->gif_if.if_flags  = IFF_POINTOPOINT | IFF_MULTICAST;
@@ -325,6 +344,7 @@ static int
 gif_clone_destroy(struct ifnet *ifp)
 {
 	struct gif_softc *sc = (void *) ifp;
+	struct gif_variant *var;
 
 	LIST_REMOVE(sc, gif_list);
 
@@ -335,6 +355,10 @@ gif_clone_destroy(struct ifnet *ifp)
 	percpu_foreach(sc->gif_ro_percpu, gif_ro_fini_pc, NULL);
 	percpu_free(sc->gif_ro_percpu, sizeof(struct gif_ro));
 
+	mutex_destroy(&sc->gif_lock);
+
+	var = sc->gif_var;
+	kmem_free(var, sizeof(*var));
 	kmem_free(sc, sizeof(struct gif_softc));
 
 	return 0;
@@ -346,6 +370,9 @@ gif_encapcheck(struct mbuf *m, int off, 
 {
 	struct ip ip;
 	struct gif_softc *sc;
+	struct gif_variant *var;
+	struct 

CVS commit: src/sys

2017-11-15 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Nov 15 10:42:41 UTC 2017

Modified Files:
src/sys/net: if_stf.c if_stf.h
src/sys/netinet: in_gif.c in_gif.h in_l2tp.c ip_encap.c ip_encap.h
ip_mroute.c
src/sys/netinet6: in6_gif.c in6_gif.h in6_l2tp.c
src/sys/netipsec: xform.h xform_ipip.c

Log Message:
Add argument to encapsw->pr_input() instead of m_tag.


To generate a diff of this commit:
cvs rdiff -u -r1.102 -r1.103 src/sys/net/if_stf.c
cvs rdiff -u -r1.7 -r1.8 src/sys/net/if_stf.h
cvs rdiff -u -r1.88 -r1.89 src/sys/netinet/in_gif.c
cvs rdiff -u -r1.16 -r1.17 src/sys/netinet/in_gif.h
cvs rdiff -u -r1.3 -r1.4 src/sys/netinet/in_l2tp.c
cvs rdiff -u -r1.65 -r1.66 src/sys/netinet/ip_encap.c
cvs rdiff -u -r1.22 -r1.23 src/sys/netinet/ip_encap.h
cvs rdiff -u -r1.147 -r1.148 src/sys/netinet/ip_mroute.c
cvs rdiff -u -r1.86 -r1.87 src/sys/netinet6/in6_gif.c
cvs rdiff -u -r1.15 -r1.16 src/sys/netinet6/in6_gif.h
cvs rdiff -u -r1.6 -r1.7 src/sys/netinet6/in6_l2tp.c
cvs rdiff -u -r1.12 -r1.13 src/sys/netipsec/xform.h
cvs rdiff -u -r1.54 -r1.55 src/sys/netipsec/xform_ipip.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/net/if_stf.c
diff -u src/sys/net/if_stf.c:1.102 src/sys/net/if_stf.c:1.103
--- src/sys/net/if_stf.c:1.102	Mon Oct 23 09:32:55 2017
+++ src/sys/net/if_stf.c	Wed Nov 15 10:42:41 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_stf.c,v 1.102 2017/10/23 09:32:55 msaitoh Exp $	*/
+/*	$NetBSD: if_stf.c,v 1.103 2017/11/15 10:42:41 knakahara Exp $	*/
 /*	$KAME: if_stf.c,v 1.62 2001/06/07 22:32:16 itojun Exp $ */
 
 /*
@@ -75,7 +75,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_stf.c,v 1.102 2017/10/23 09:32:55 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_stf.c,v 1.103 2017/11/15 10:42:41 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -591,16 +591,18 @@ stf_checkaddr6(struct stf_softc *sc, con
 }
 
 void
-in_stf_input(struct mbuf *m, int off, int proto)
+in_stf_input(struct mbuf *m, int off, int proto, void *eparg)
 {
 	int s;
-	struct stf_softc *sc;
+	struct stf_softc *sc = eparg;
 	struct ip *ip;
 	struct ip6_hdr *ip6;
 	uint8_t otos, itos;
 	struct ifnet *ifp;
 	size_t pktlen;
 
+	KASSERT(sc != NULL);
+
 	if (proto != IPPROTO_IPV6) {
 		m_freem(m);
 		return;
@@ -608,9 +610,7 @@ in_stf_input(struct mbuf *m, int off, in
 
 	ip = mtod(m, struct ip *);
 
-	sc = (struct stf_softc *)encap_getarg(m);
-
-	if (sc == NULL || (sc->sc_if.if_flags & IFF_UP) == 0) {
+	if ((sc->sc_if.if_flags & IFF_UP) == 0) {
 		m_freem(m);
 		return;
 	}

Index: src/sys/net/if_stf.h
diff -u src/sys/net/if_stf.h:1.7 src/sys/net/if_stf.h:1.8
--- src/sys/net/if_stf.h:1.7	Thu Aug 18 11:38:58 2016
+++ src/sys/net/if_stf.h	Wed Nov 15 10:42:41 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_stf.h,v 1.7 2016/08/18 11:38:58 knakahara Exp $	*/
+/*	$NetBSD: if_stf.h,v 1.8 2017/11/15 10:42:41 knakahara Exp $	*/
 /*	$KAME: if_stf.h,v 1.3 2000/03/25 07:23:33 sumikawa Exp $	*/
 
 /*
@@ -39,6 +39,6 @@
 #define	STF_MTU_MIN	(1280)	/* Minimum MTU */
 #define	STF_MTU_MAX	(8192)	/* Maximum MTU */
 
-void	in_stf_input(struct mbuf *, int, int);
+void	in_stf_input(struct mbuf *, int, int, void *);
 
 #endif /* !_NET_IF_STF_H_ */

Index: src/sys/netinet/in_gif.c
diff -u src/sys/netinet/in_gif.c:1.88 src/sys/netinet/in_gif.c:1.89
--- src/sys/netinet/in_gif.c:1.88	Thu Sep 21 09:42:03 2017
+++ src/sys/netinet/in_gif.c	Wed Nov 15 10:42:41 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: in_gif.c,v 1.88 2017/09/21 09:42:03 knakahara Exp $	*/
+/*	$NetBSD: in_gif.c,v 1.89 2017/11/15 10:42:41 knakahara Exp $	*/
 /*	$KAME: in_gif.c,v 1.66 2001/07/29 04:46:09 itojun Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in_gif.c,v 1.88 2017/09/21 09:42:03 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in_gif.c,v 1.89 2017/11/15 10:42:41 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -195,19 +195,18 @@ in_gif_output(struct ifnet *ifp, int fam
 }
 
 void
-in_gif_input(struct mbuf *m, int off, int proto)
+in_gif_input(struct mbuf *m, int off, int proto, void *eparg)
 {
-	struct ifnet *gifp = NULL;
+	struct ifnet *gifp = eparg;
 	const struct ip *ip;
 	int af;
 	u_int8_t otos;
 
-	ip = mtod(m, const struct ip *);
+	KASSERT(gifp != NULL);
 
-	gifp = (struct ifnet *)encap_getarg(m);
+	ip = mtod(m, const struct ip *);
 
-	if (gifp == NULL || (gifp->if_flags & (IFF_UP|IFF_RUNNING))
-		!= (IFF_UP|IFF_RUNNING)) {
+	if ((gifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING)) {
 		m_freem(m);
 		ip_statinc(IP_STAT_NOGIF);
 		return;

Index: src/sys/netinet/in_gif.h
diff -u src/sys/netinet/in_gif.h:1.16 src/sys/netinet/in_gif.h:1.17
--- src/sys/netinet/in_gif.h:1.16	Mon Jul  4 04:22:47 2016
+++ src/sys/netinet/in_gif.h	Wed Nov 15 10:42:41 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: in_gif.h,v 1.16 2016/07/04 04:22:47 knakahara Exp $	*/
+/*	$NetBSD: in_gif.h,v 1.17 2017/11/15 10:42:41 knak

CVS commit: src/sys/net

2017-11-14 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Nov 15 07:52:58 UTC 2017

Modified Files:
src/sys/net: if_pppoe.c if_spppsubr.c

Log Message:
Mark callouts of pppoe(4) CALLOUT_MPSAFE. Suggested by ozaki-r@n.o.


To generate a diff of this commit:
cvs rdiff -u -r1.129 -r1.130 src/sys/net/if_pppoe.c
cvs rdiff -u -r1.171 -r1.172 src/sys/net/if_spppsubr.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/net/if_pppoe.c
diff -u src/sys/net/if_pppoe.c:1.129 src/sys/net/if_pppoe.c:1.130
--- src/sys/net/if_pppoe.c:1.129	Mon Oct 23 09:32:33 2017
+++ src/sys/net/if_pppoe.c	Wed Nov 15 07:52:58 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: if_pppoe.c,v 1.129 2017/10/23 09:32:33 msaitoh Exp $ */
+/* $NetBSD: if_pppoe.c,v 1.130 2017/11/15 07:52:58 knakahara Exp $ */
 
 /*-
  * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.129 2017/10/23 09:32:33 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.130 2017/11/15 07:52:58 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "pppoe.h"
@@ -317,7 +317,7 @@ pppoe_clone_create(struct if_clone *ifc,
 	/* changed to real address later */
 	memcpy(&sc->sc_dest, etherbroadcastaddr, sizeof(sc->sc_dest));
 
-	callout_init(&sc->sc_timeout, 0);
+	callout_init(&sc->sc_timeout, CALLOUT_MPSAFE);
 
 	sc->sc_sppp.pp_if.if_start = pppoe_start;
 #ifdef PPPOE_MPSAFE

Index: src/sys/net/if_spppsubr.c
diff -u src/sys/net/if_spppsubr.c:1.171 src/sys/net/if_spppsubr.c:1.172
--- src/sys/net/if_spppsubr.c:1.171	Fri Oct 13 03:11:50 2017
+++ src/sys/net/if_spppsubr.c	Wed Nov 15 07:52:58 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppsubr.c,v 1.171 2017/10/13 03:11:50 knakahara Exp $	 */
+/*	$NetBSD: if_spppsubr.c,v 1.172 2017/11/15 07:52:58 knakahara Exp $	 */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.171 2017/10/13 03:11:50 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.172 2017/11/15 07:52:58 knakahara Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -999,7 +999,7 @@ sppp_attach(struct ifnet *ifp)
 
 	/* Initialize keepalive handler. */
 	if (! spppq) {
-		callout_init(&keepalive_ch, 0);
+		callout_init(&keepalive_ch, CALLOUT_MPSAFE);
 		callout_reset(&keepalive_ch, hz * LCP_KEEPALIVE_INTERVAL, sppp_keepalive, NULL);
 	}
 
@@ -2204,7 +2204,7 @@ sppp_lcp_init(struct sppp *sp)
 	sp->lcp.max_terminate = 2;
 	sp->lcp.max_configure = 10;
 	sp->lcp.max_failure = 10;
-	callout_init(&sp->ch[IDX_LCP], 0);
+	callout_init(&sp->ch[IDX_LCP], CALLOUT_MPSAFE);
 }
 
 static void
@@ -2966,7 +2966,7 @@ sppp_ipcp_init(struct sppp *sp)
 	sp->fail_counter[IDX_IPCP] = 0;
 	sp->pp_seq[IDX_IPCP] = 0;
 	sp->pp_rseq[IDX_IPCP] = 0;
-	callout_init(&sp->ch[IDX_IPCP], 0);
+	callout_init(&sp->ch[IDX_IPCP], CALLOUT_MPSAFE);
 
 	error = workqueue_create(&sp->ipcp.update_addrs_wq, "ipcp_update_addrs",
 	sppp_update_ip_addrs_work, sp, PRI_SOFTNET, IPL_NET, 0);
@@ -3525,7 +3525,7 @@ sppp_ipv6cp_init(struct sppp *sp)
 	sp->fail_counter[IDX_IPV6CP] = 0;
 	sp->pp_seq[IDX_IPV6CP] = 0;
 	sp->pp_rseq[IDX_IPV6CP] = 0;
-	callout_init(&sp->ch[IDX_IPV6CP], 0);
+	callout_init(&sp->ch[IDX_IPV6CP], CALLOUT_MPSAFE);
 }
 
 static void
@@ -4463,7 +4463,7 @@ sppp_chap_init(struct sppp *sp)
 	sp->fail_counter[IDX_CHAP] = 0;
 	sp->pp_seq[IDX_CHAP] = 0;
 	sp->pp_rseq[IDX_CHAP] = 0;
-	callout_init(&sp->ch[IDX_CHAP], 0);
+	callout_init(&sp->ch[IDX_CHAP], CALLOUT_MPSAFE);
 }
 
 static void
@@ -4831,8 +4831,8 @@ sppp_pap_init(struct sppp *sp)
 	sp->fail_counter[IDX_PAP] = 0;
 	sp->pp_seq[IDX_PAP] = 0;
 	sp->pp_rseq[IDX_PAP] = 0;
-	callout_init(&sp->ch[IDX_PAP], 0);
-	callout_init(&sp->pap_my_to_ch, 0);
+	callout_init(&sp->ch[IDX_PAP], CALLOUT_MPSAFE);
+	callout_init(&sp->pap_my_to_ch, CALLOUT_MPSAFE);
 }
 
 static void



CVS commit: src/crypto/dist/ipsec-tools/src/racoon

2017-11-09 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Nov  9 08:34:50 UTC 2017

Modified Files:
src/crypto/dist/ipsec-tools/src/racoon: pfkey.c

Log Message:
fix typo. (does not affect actual operation, but confuses reader...)

The function is called when racoon receives SADB_X_MIGRATE pfkey message,
however the message is not used now. It was compatible code for KAME.


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/crypto/dist/ipsec-tools/src/racoon/pfkey.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/crypto/dist/ipsec-tools/src/racoon/pfkey.c
diff -u src/crypto/dist/ipsec-tools/src/racoon/pfkey.c:1.59 src/crypto/dist/ipsec-tools/src/racoon/pfkey.c:1.60
--- src/crypto/dist/ipsec-tools/src/racoon/pfkey.c:1.59	Thu Nov 29 15:31:25 2012
+++ src/crypto/dist/ipsec-tools/src/racoon/pfkey.c	Thu Nov  9 08:34:50 2017
@@ -1,6 +1,6 @@
-/*	$NetBSD: pfkey.c,v 1.59 2012/11/29 15:31:25 vanhu Exp $	*/
+/*	$NetBSD: pfkey.c,v 1.60 2017/11/09 08:34:50 knakahara Exp $	*/
 
-/* $Id: pfkey.c,v 1.59 2012/11/29 15:31:25 vanhu Exp $ */
+/* $Id: pfkey.c,v 1.60 2017/11/09 08:34:50 knakahara Exp $ */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -3177,8 +3177,8 @@ migrate_ph2_one_isr(spid, isr_cur, xisr_
 
 	/* Then, verify reqid if necessary */
 	if (isr_cur->saidx.reqid &&
-	(xisr_old->sadb_x_ipsecrequest_reqid != IPSEC_LEVEL_UNIQUE ||
-	 xisr_new->sadb_x_ipsecrequest_reqid != IPSEC_LEVEL_UNIQUE ||
+	(xisr_old->sadb_x_ipsecrequest_level != IPSEC_LEVEL_UNIQUE ||
+	 xisr_new->sadb_x_ipsecrequest_level != IPSEC_LEVEL_UNIQUE ||
 	 isr_cur->saidx.reqid != xisr_old->sadb_x_ipsecrequest_reqid ||
 	 isr_cur->saidx.reqid != xisr_new->sadb_x_ipsecrequest_reqid))
 		return -1;



CVS commit: src/sys/net

2017-10-30 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Oct 30 11:24:04 UTC 2017

Modified Files:
src/sys/net: if_l2tp.c if_l2tp.h

Log Message:
If if_attach() failed in the attach function, return. Add comments about 
if_initialize().

suggested by ozaki-r@n.o.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/net/if_l2tp.c
cvs rdiff -u -r1.2 -r1.3 src/sys/net/if_l2tp.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/net/if_l2tp.c
diff -u src/sys/net/if_l2tp.c:1.12 src/sys/net/if_l2tp.c:1.13
--- src/sys/net/if_l2tp.c:1.12	Thu Oct 19 11:28:30 2017
+++ src/sys/net/if_l2tp.c	Mon Oct 30 11:24:04 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_l2tp.c,v 1.12 2017/10/19 11:28:30 knakahara Exp $	*/
+/*	$NetBSD: if_l2tp.c,v 1.13 2017/10/30 11:24:04 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_l2tp.c,v 1.12 2017/10/19 11:28:30 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_l2tp.c,v 1.13 2017/10/30 11:24:04 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -227,10 +227,17 @@ l2tp_clone_create(struct if_clone *ifc, 
 {
 	struct l2tp_softc *sc;
 	struct l2tp_variant *var;
+	int rv;
 
 	sc = kmem_zalloc(sizeof(struct l2tp_softc), KM_SLEEP);
-	var = kmem_zalloc(sizeof(struct l2tp_variant), KM_SLEEP);
+	if_initname(&sc->l2tp_ec.ec_if, ifc->ifc_name, unit);
+	rv = l2tpattach0(sc);
+	if (rv != 0) {
+		kmem_free(sc, sizeof(struct l2tp_softc));
+		return rv;
+	}
 
+	var = kmem_zalloc(sizeof(struct l2tp_variant), KM_SLEEP);
 	var->lv_softc = sc;
 	var->lv_state = L2TP_STATE_DOWN;
 	var->lv_use_cookie = L2TP_COOKIE_OFF;
@@ -240,10 +247,6 @@ l2tp_clone_create(struct if_clone *ifc, 
 	mutex_init(&sc->l2tp_lock, MUTEX_DEFAULT, IPL_NONE);
 	PSLIST_ENTRY_INIT(sc, l2tp_hash);
 
-	if_initname(&sc->l2tp_ec.ec_if, ifc->ifc_name, unit);
-
-	l2tpattach0(sc);
-
 	sc->l2tp_ro_percpu = percpu_alloc(sizeof(struct l2tp_ro));
 	percpu_foreach(sc->l2tp_ro_percpu, l2tp_ro_init_pc, NULL);
 
@@ -254,9 +257,10 @@ l2tp_clone_create(struct if_clone *ifc, 
 	return (0);
 }
 
-void
+int
 l2tpattach0(struct l2tp_softc *sc)
 {
+	int rv;
 
 	sc->l2tp_ec.ec_if.if_addrlen = 0;
 	sc->l2tp_ec.ec_if.if_mtu= L2TP_MTU;
@@ -270,9 +274,19 @@ l2tpattach0(struct l2tp_softc *sc)
 	sc->l2tp_ec.ec_if.if_transmit = l2tp_transmit;
 	sc->l2tp_ec.ec_if._if_input = ether_input;
 	IFQ_SET_READY(&sc->l2tp_ec.ec_if.if_snd);
-	if_attach(&sc->l2tp_ec.ec_if);
+	/* XXX
+	 * It may improve performance to use if_initialize()/if_register()
+	 * so that l2tp_input() calls if_input() instead of
+	 * if_percpuq_enqueue(). However, that causes recursive softnet_lock
+	 * when NET_MPSAFE is not set.
+	 */
+	rv = if_attach(&sc->l2tp_ec.ec_if);
+	if (rv != 0)
+		return rv;
 	if_alloc_sadl(&sc->l2tp_ec.ec_if);
 	bpf_attach(&sc->l2tp_ec.ec_if, DLT_EN10MB, sizeof(struct ether_header));
+
+	return 0;
 }
 
 void

Index: src/sys/net/if_l2tp.h
diff -u src/sys/net/if_l2tp.h:1.2 src/sys/net/if_l2tp.h:1.3
--- src/sys/net/if_l2tp.h:1.2	Wed May 31 08:19:44 2017
+++ src/sys/net/if_l2tp.h	Mon Oct 30 11:24:04 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_l2tp.h,v 1.2 2017/05/31 08:19:44 knakahara Exp $	*/
+/*	$NetBSD: if_l2tp.h,v 1.3 2017/10/30 11:24:04 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -162,7 +162,7 @@ l2tp_heldref_variant(struct l2tp_variant
 
 /* Prototypes */
 void l2tpattach(int);
-void l2tpattach0(struct l2tp_softc *);
+int l2tpattach0(struct l2tp_softc *);
 void l2tp_input(struct mbuf *, struct ifnet *);
 int l2tp_ioctl(struct ifnet *, u_long, void *);
 



CVS commit: src/sys/dev/pci

2017-10-23 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Oct 23 23:29:38 UTC 2017

Modified Files:
src/sys/dev/pci: if_wm.c if_wmreg.h

Log Message:
fix wm(4) vlan panic. Reported and tested by Tom Ivar Helbekkmo, thanks.

wm(4) used PRI bits and CFI bit as vlantag by mistake. It is found out
by if_ether.h:r1.67.

XXX need pullup-8


To generate a diff of this commit:
cvs rdiff -u -r1.541 -r1.542 src/sys/dev/pci/if_wm.c
cvs rdiff -u -r1.103 -r1.104 src/sys/dev/pci/if_wmreg.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/dev/pci/if_wm.c
diff -u src/sys/dev/pci/if_wm.c:1.541 src/sys/dev/pci/if_wm.c:1.542
--- src/sys/dev/pci/if_wm.c:1.541	Mon Oct 23 09:27:21 2017
+++ src/sys/dev/pci/if_wm.c	Mon Oct 23 23:29:38 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_wm.c,v 1.541 2017/10/23 09:27:21 msaitoh Exp $	*/
+/*	$NetBSD: if_wm.c,v 1.542 2017/10/23 23:29:38 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2001, 2002, 2003, 2004 Wasabi Systems, Inc.
@@ -83,7 +83,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.541 2017/10/23 09:27:21 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.542 2017/10/23 23:29:38 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -8108,11 +8108,11 @@ wm_rxdesc_get_vlantag(struct wm_rxqueue 
 	struct wm_softc *sc = rxq->rxq_sc;
 
 	if (sc->sc_type == WM_T_82574)
-		return rxq->rxq_ext_descs[idx].erx_ctx.erxc_vlan;
+		return EXTRXC_VLAN_ID(rxq->rxq_ext_descs[idx].erx_ctx.erxc_vlan);
 	else if ((sc->sc_flags & WM_F_NEWQUEUE) != 0)
-		return rxq->rxq_nq_descs[idx].nqrx_ctx.nrxc_vlan;
+		return NQRXC_VLAN_ID(rxq->rxq_nq_descs[idx].nqrx_ctx.nrxc_vlan);
 	else
-		return rxq->rxq_descs[idx].wrx_special;
+		return WRX_VLAN_ID(rxq->rxq_descs[idx].wrx_special);
 }
 
 static inline int

Index: src/sys/dev/pci/if_wmreg.h
diff -u src/sys/dev/pci/if_wmreg.h:1.103 src/sys/dev/pci/if_wmreg.h:1.104
--- src/sys/dev/pci/if_wmreg.h:1.103	Wed Jul 26 06:48:49 2017
+++ src/sys/dev/pci/if_wmreg.h	Mon Oct 23 23:29:38 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_wmreg.h,v 1.103 2017/07/26 06:48:49 msaitoh Exp $	*/
+/*	$NetBSD: if_wmreg.h,v 1.104 2017/10/23 23:29:38 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -208,6 +208,12 @@ typedef union ext_rxdesc {
 #define EXTRXC_STATUS_PKTTYPE_MASK	__BITS(19,16)
 #define EXTRXC_STATUS_PKTTYPE(status)	__SHIFTOUT(status,EXTRXC_STATUS_PKTTYPE_MASK)
 
+#define	EXTRXC_VLAN_ID_MASK	__BITS(11,0)	/* VLAN identifier mask */
+#define	EXTRXC_VLAN_ID(x)	((x) & EXTRXC_VLAN_ID_MASK) /* VLAN identifier */
+#define	EXTRXC_VLAN_CFI		__BIT(12)	/* Canonical Form Indicator */
+#define	EXTRXC_VLAN_PRI_MASK	__BITS(15,13)	/* VLAN priority mask */
+#define	EXTRXC_VLAN_PRI(x)	__SHIFTOUT((x),EXTRXC_VLAN_PRI_MASK) /* VLAN priority */
+
 /* advanced RX descriptor for 82575 and newer */
 typedef union nq_rxdesc {
 	struct {
@@ -330,6 +336,12 @@ typedef union nq_rxdesc {
 #define NQRXC_STATUS_MC		__BIT(19) /* Packet received from Manageability Controller */
 	  /* "MBC" in i350 spec */
 
+#define	NQRXC_VLAN_ID_MASK	__BITS(11,0)	/* VLAN identifier mask */
+#define	NQRXC_VLAN_ID(x)	((x) & NQRXC_VLAN_ID_MASK) /* VLAN identifier */
+#define	NQRXC_VLAN_CFI		__BIT(12)	/* Canonical Form Indicator */
+#define	NQRXC_VLAN_PRI_MASK	__BITS(15,13)	/* VLAN priority mask */
+#define	NQRXC_VLAN_PRI(x)	__SHIFTOUT((x),NQRXC_VLAN_PRI_MASK) /* VLAN priority */
+
 /*
  * The Wiseman transmit descriptor.
  *



CVS commit: src/sys/net

2017-10-19 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Oct 19 11:28:30 UTC 2017

Modified Files:
src/sys/net: if_l2tp.c

Log Message:
fix l2tp panic when l2tp session id is changed (same as if_vlan.c:r1.104)

E.g. the following operation causes this panic.

# ifconfig l2tp0 create
# ifconfig l2tp0 session 140 140
# ifconfig l2tp1 create
# ifconfig l2tp1 session 200 200
# ifconfig l2tp1 session 300 300
panic: kernel diagnostic assertion "new->ple_next == NULL" failed: file 
"/disk4/home/k-nakahara/repos/netbsd-src/sys/sys/pslist.h", line 118


Pointed out by s-yamaguchi@IIJ, thanks.

XXX need pullup-8


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/net/if_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/net/if_l2tp.c
diff -u src/sys/net/if_l2tp.c:1.11 src/sys/net/if_l2tp.c:1.12
--- src/sys/net/if_l2tp.c:1.11	Thu Jun  1 02:45:14 2017
+++ src/sys/net/if_l2tp.c	Thu Oct 19 11:28:30 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_l2tp.c,v 1.11 2017/06/01 02:45:14 chs Exp $	*/
+/*	$NetBSD: if_l2tp.c,v 1.12 2017/10/19 11:28:30 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_l2tp.c,v 1.11 2017/06/01 02:45:14 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_l2tp.c,v 1.12 2017/10/19 11:28:30 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1069,6 +1069,7 @@ l2tp_set_session(struct l2tp_softc *sc, 
 		pserialize_perform(l2tp_psz);
 	}
 	mutex_exit(&l2tp_hash.lock);
+	PSLIST_ENTRY_DESTROY(sc, l2tp_hash);
 
 	l2tp_variant_update(sc, nvar);
 	mutex_exit(&sc->l2tp_lock);
@@ -1078,6 +1079,7 @@ l2tp_set_session(struct l2tp_softc *sc, 
 		log(LOG_DEBUG, "%s: add hash entry: sess_id=%" PRIu32 ", idx=%" PRIu32 "\n",
 		sc->l2tp_ec.ec_if.if_xname, nvar->lv_my_sess_id, idx);
 
+	PSLIST_ENTRY_INIT(sc, l2tp_hash);
 	mutex_enter(&l2tp_hash.lock);
 	PSLIST_WRITER_INSERT_HEAD(&l2tp_hash.lists[idx], sc, l2tp_hash);
 	mutex_exit(&l2tp_hash.lock);



CVS commit: src/sys/net

2017-10-19 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Oct 19 07:02:00 UTC 2017

Modified Files:
src/sys/net: if_vlan.c

Log Message:
fix vlan panic when vlan is re-configured without destroy.

E.g. the following operation causes this panic.

# ifconfig vlan0 create
# ifconfig vlan0 vlan 1 vlanif ixg3
# ifconfig vlan1 create
# ifconfig vlan1 vlan 1 vlanif ixg2
# ifconfig vlan1 -vlanif
# ifconfig vlan1 vlan 1 vlanif ixg2

panic: kernel diagnostic assertion "new->ple_next == NULL" failed: file 
"/git/netbsd-src/sys/sys/pslist.h", line 118


Pointed out and tested by msaitoh@n.o, fixed by s-yamaguchi@IIJ, thanks.

XXX need pullup-8


To generate a diff of this commit:
cvs rdiff -u -r1.103 -r1.104 src/sys/net/if_vlan.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/net/if_vlan.c
diff -u src/sys/net/if_vlan.c:1.103 src/sys/net/if_vlan.c:1.104
--- src/sys/net/if_vlan.c:1.103	Thu Oct 12 02:40:59 2017
+++ src/sys/net/if_vlan.c	Thu Oct 19 07:02:00 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vlan.c,v 1.103 2017/10/12 02:40:59 ozaki-r Exp $	*/
+/*	$NetBSD: if_vlan.c,v 1.104 2017/10/19 07:02:00 knakahara Exp $	*/
 
 /*-
  * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
@@ -78,7 +78,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.103 2017/10/12 02:40:59 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.104 2017/10/19 07:02:00 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -478,6 +478,7 @@ vlan_config(struct ifvlan *ifv, struct i
 	 */
 	ifv->ifv_if.if_type = p->if_type;
 
+	PSLIST_ENTRY_INIT(ifv, ifv_hash);
 	idx = tag_hash_func(tag, ifv_hash.mask);
 
 	mutex_enter(&ifv_hash.lock);
@@ -582,6 +583,7 @@ vlan_unconfig_locked(struct ifvlan *ifv,
 	PSLIST_WRITER_REMOVE(ifv, ifv_hash);
 	pserialize_perform(vlan_psz);
 	mutex_exit(&ifv_hash.lock);
+	PSLIST_ENTRY_DESTROY(ifv, ifv_hash);
 
 	vlan_linkmib_update(ifv, nmib);
 



CVS commit: src/sys/net

2017-10-12 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Oct 13 03:11:50 UTC 2017

Modified Files:
src/sys/net: if_spppsubr.c

Log Message:
fix no INET6 build.


To generate a diff of this commit:
cvs rdiff -u -r1.170 -r1.171 src/sys/net/if_spppsubr.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/net/if_spppsubr.c
diff -u src/sys/net/if_spppsubr.c:1.170 src/sys/net/if_spppsubr.c:1.171
--- src/sys/net/if_spppsubr.c:1.170	Thu Oct 12 09:49:43 2017
+++ src/sys/net/if_spppsubr.c	Fri Oct 13 03:11:50 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppsubr.c,v 1.170 2017/10/12 09:49:43 knakahara Exp $	 */
+/*	$NetBSD: if_spppsubr.c,v 1.171 2017/10/13 03:11:50 knakahara Exp $	 */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.170 2017/10/12 09:49:43 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.171 2017/10/13 03:11:50 knakahara Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -416,7 +416,9 @@ static void sppp_notify_up(struct sppp *
 static void sppp_notify_down(struct sppp *);
 static void sppp_notify_tls_wlocked(struct sppp *);
 static void sppp_notify_tlf_wlocked(struct sppp *);
+#ifdef INET6
 static void sppp_notify_con_wlocked(struct sppp *);
+#endif
 static void sppp_notify_con(struct sppp *);
 
 static void sppp_notify_chg_wlocked(struct sppp *);
@@ -4038,12 +4040,13 @@ static void
 sppp_ipv6cp_close(struct sppp *sp)
 {
 
-	KASSERT(S_WLOKED(sp));
+	KASSERT(SPPP_WLOCKED(sp));
 }
 
 static void
-sppp_ipv6cp_TO(void *sp)
+sppp_ipv6cp_TO(void *cookie)
 {
+	struct sppp *sp = cookie;
 
 	KASSERT(SPPP_WLOCKED(sp));
 }
@@ -6218,6 +6221,7 @@ sppp_notify_con(struct sppp *sp)
 	sp->pp_con(sp);
 }
 
+#ifdef INET6
 static void
 sppp_notify_con_wlocked(struct sppp *sp)
 {
@@ -6229,6 +6233,7 @@ sppp_notify_con_wlocked(struct sppp *sp)
 	SPPP_LOCK(sp, RW_WRITER);
 
 }
+#endif
 
 static void
 sppp_notify_chg_wlocked(struct sppp *sp)



CVS commit: src/sys/net

2017-10-12 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Oct 12 09:53:55 UTC 2017

Modified Files:
src/sys/net: if_spppvar.h

Log Message:
Add a locking notes for if_spppsubr


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/net/if_spppvar.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/net/if_spppvar.h
diff -u src/sys/net/if_spppvar.h:1.21 src/sys/net/if_spppvar.h:1.22
--- src/sys/net/if_spppvar.h:1.21	Thu Oct 12 09:49:43 2017
+++ src/sys/net/if_spppvar.h	Thu Oct 12 09:53:55 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppvar.h,v 1.21 2017/10/12 09:49:43 knakahara Exp $	*/
+/*	$NetBSD: if_spppvar.h,v 1.22 2017/10/12 09:53:55 knakahara Exp $	*/
 
 #ifndef _NET_IF_SPPPVAR_H_
 #define _NET_IF_SPPPVAR_H_
@@ -182,4 +182,25 @@ struct mbuf *sppp_dequeue (struct ifnet 
 int sppp_isempty (struct ifnet *);
 void sppp_flush (struct ifnet *);
 #endif
+
+/*
+ * Locking notes:
+ * + spppq is protected by spppq_lock (an adaptive mutex)
+ * spppq is a list of all struct sppps, and it is used for
+ * sending keepalive packets.
+ * + struct sppp is protected by sppp->pp_lock (an rwlock)
+ * sppp holds configuration parameters for line,
+ * authentication and addresses. It also has pointers
+ * of functions to notify events to lower layer.
+ * When notify events, sppp->pp_lock must be released.
+ * Because the event handler implemented in a lower
+ * layer often call functions implemented in
+ * if_spppsubr.c.
+ *
+ * Locking order:
+ *- spppq_lock => struct sppp->pp_lock
+ *
+ * NOTICE
+ * - Lower layers must not acquire sppp->pp_lock
+ */
 #endif /* !_NET_IF_SPPPVAR_H_ */



CVS commit: src/sys/net

2017-10-12 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Oct 12 09:50:55 UTC 2017

Modified Files:
src/sys/net: if_pppoe.h

Log Message:
Add a locking notes for if_pppoe


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/net/if_pppoe.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/net/if_pppoe.h
diff -u src/sys/net/if_pppoe.h:1.14 src/sys/net/if_pppoe.h:1.15
--- src/sys/net/if_pppoe.h:1.14	Wed May 31 11:44:44 2017
+++ src/sys/net/if_pppoe.h	Thu Oct 12 09:50:55 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: if_pppoe.h,v 1.14 2017/05/31 11:44:44 knakahara Exp $ */
+/* $NetBSD: if_pppoe.h,v 1.15 2017/10/12 09:50:55 knakahara Exp $ */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -70,10 +70,15 @@ void pppoe_input(struct ifnet *, struct 
 void pppoedisc_input(struct ifnet *, struct mbuf *);
 #endif /* _KERNEL */
 /*
- * TODO: Locking notes
- * Currently, the if_pppoe.c and if_spppsubr.c locking is too complexity.
- * So, we will restructure locks, and then we describe the restructureed
- * locking note.
+ * Locking notes:
+ * + pppoe_softc_list is protected by pppoe_softc_list_lock (an rwlock)
+ * pppoe_softc_list is a list of all pppoe_softc, and it is used to
+ * find pppoe interface by session id or host unique tag.
+ * + pppoe_softc is protected by pppoe_softc->sc_lock (an rwlock)
+ * pppoe_softc holds session id and parameters to establish the id
+ *
+ * Locking order:
+ *- pppoe_softc_list_lock => pppoe_softc->sc_lock
  */
 #endif /* !_NET_IF_PPPOE_H_ */
 



CVS commit: src/sys/net

2017-10-12 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Oct 12 09:49:43 UTC 2017

Modified Files:
src/sys/net: if_pppoe.c if_spppsubr.c if_spppvar.h

Log Message:
sppp_lock is changed from mutex to rwlock now. Contributed by s-yamaguchi@IIJ.

Add locking notes later.


To generate a diff of this commit:
cvs rdiff -u -r1.127 -r1.128 src/sys/net/if_pppoe.c
cvs rdiff -u -r1.169 -r1.170 src/sys/net/if_spppsubr.c
cvs rdiff -u -r1.20 -r1.21 src/sys/net/if_spppvar.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/net/if_pppoe.c
diff -u src/sys/net/if_pppoe.c:1.127 src/sys/net/if_pppoe.c:1.128
--- src/sys/net/if_pppoe.c:1.127	Thu Oct 12 09:47:21 2017
+++ src/sys/net/if_pppoe.c	Thu Oct 12 09:49:43 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: if_pppoe.c,v 1.127 2017/10/12 09:47:21 knakahara Exp $ */
+/* $NetBSD: if_pppoe.c,v 1.128 2017/10/12 09:49:43 knakahara Exp $ */
 
 /*-
  * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.127 2017/10/12 09:47:21 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.128 2017/10/12 09:49:43 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "pppoe.h"
@@ -813,9 +813,7 @@ breakbreak:;
 		sc->sc_state = PPPOE_STATE_SESSION;
 		PPPOE_UNLOCK(sc);
 
-		sppp_lock_enter(&sc->sc_sppp);
 		sc->sc_sppp.pp_up(&sc->sc_sppp);
-		sppp_lock_exit(&sc->sc_sppp);
 		break;
 	}
 #else
@@ -899,9 +897,7 @@ breakbreak:;
 		sc->sc_state = PPPOE_STATE_SESSION;
 		PPPOE_UNLOCK(sc);
 
-		sppp_lock_enter(&sc->sc_sppp);
 		sc->sc_sppp.pp_up(&sc->sc_sppp);	/* notify upper layers */
-		sppp_lock_exit(&sc->sc_sppp);
 		break;
 	case PPPOE_CODE_PADT: {
 		struct ifnet *rcvif;
@@ -1495,9 +1491,7 @@ pppoe_disconnect(struct pppoe_softc *sc)
 	PPPOE_UNLOCK(sc);
 
 	/* notify upper layer */
-	sppp_lock_enter(&sc->sc_sppp);
 	sc->sc_sppp.pp_down(&sc->sc_sppp);
-	sppp_lock_exit(&sc->sc_sppp);
 
 	PPPOE_LOCK(sc, RW_WRITER);
 
@@ -1518,9 +1512,7 @@ pppoe_abort_connect(struct pppoe_softc *
 	PPPOE_UNLOCK(sc);
 
 	/* notify upper layer */
-	sppp_lock_enter(&sc->sc_sppp);
 	sc->sc_sppp.pp_down(&sc->sc_sppp);
-	sppp_lock_exit(&sc->sc_sppp);
 
 	PPPOE_LOCK(sc, RW_WRITER);
 
@@ -1849,13 +1841,11 @@ pppoe_ifattach_hook(void *arg, unsigned 
 			PPPOE_UNLOCK(sc);
 			continue;
 		}
-		sppp_lock_enter(&sc->sc_sppp);
 		if (sc->sc_sppp.pp_if.if_flags & IFF_UP) {
 			sc->sc_sppp.pp_if.if_flags &= ~(IFF_UP|IFF_RUNNING);
 			printf("%s: ethernet interface detached, going down\n",
 			sc->sc_sppp.pp_if.if_xname);
 		}
-		sppp_lock_exit(&sc->sc_sppp);
 		sc->sc_eth_if = NULL;
 		pppoe_clear_softc(sc, "ethernet interface detached");
 		PPPOE_UNLOCK(sc);
@@ -1881,9 +1871,7 @@ pppoe_clear_softc(struct pppoe_softc *sc
 	PPPOE_UNLOCK(sc);
 
 	/* signal upper layer */
-	sppp_lock_enter(&sc->sc_sppp);
 	sc->sc_sppp.pp_down(&sc->sc_sppp);
-	sppp_lock_exit(&sc->sc_sppp);
 
 	PPPOE_LOCK(sc, RW_WRITER);
 

Index: src/sys/net/if_spppsubr.c
diff -u src/sys/net/if_spppsubr.c:1.169 src/sys/net/if_spppsubr.c:1.170
--- src/sys/net/if_spppsubr.c:1.169	Tue Mar 28 08:47:19 2017
+++ src/sys/net/if_spppsubr.c	Thu Oct 12 09:49:43 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppsubr.c,v 1.169 2017/03/28 08:47:19 ozaki-r Exp $	 */
+/*	$NetBSD: if_spppsubr.c,v 1.170 2017/10/12 09:49:43 knakahara Exp $	 */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.169 2017/03/28 08:47:19 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.170 2017/10/12 09:49:43 knakahara Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -254,6 +254,15 @@ static callout_t keepalive_ch;
 #define SPPPQ_UNLOCK()	if (spppq_lock) \
 mutex_exit(spppq_lock);
 
+#define SPPP_LOCK(_sp, _op)	rw_enter(&(_sp)->pp_lock, (_op))
+#define SPPP_UNLOCK(_sp)	rw_exit(&(_sp)->pp_lock)
+#define SPPP_WLOCKED(_sp)	rw_write_held(&(_sp)->pp_lock)
+#define SPPP_UPGRADE(_sp)	do{	\
+	SPPP_UNLOCK(_sp);		\
+	SPPP_LOCK(_sp, RW_WRITER);	\
+}while (0)
+#define SPPP_DOWNGRADE(_sp)	rw_downgrade(&(_sp)->pp_lock)
+
 #ifdef INET
 #ifndef SPPPSUBR_MPSAFE
 /*
@@ -403,6 +412,16 @@ static void sppp_gen_ip6_addr(struct spp
 static void sppp_suggest_ip6_addr(struct sppp *sp, struct in6_addr *src);
 #endif
 
+static void sppp_notify_up(struct sppp *);
+static void sppp_notify_down(struct sppp *);
+static void sppp_notify_tls_wlocked(struct sppp *);
+static void sppp_notify_tlf_wlocked(struct sppp *);
+static void sppp_notify_con_wlocked(struct sppp *);
+static void sppp_notify_con(struct sppp *);
+
+static void sppp_notify_chg_wlocked(struct sppp *);
+
+
 /* our control protocol descriptors */
 static const struct cp lcp = {
 	PPP_LCP, IDX_LCP, CP_LCP, "lcp",
@@ -469,7 +488,7 @@ sppp_change_phase(struct sppp *sp, int p
 {
 	STDDCL;
 
-	KASSERT(sppp_locked(sp));
+	KASSERT(SPPP_WLOCKED(sp));
 
 	if (sp->pp_phase == phase)
 	

CVS commit: src/sys/net

2017-10-12 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Oct 12 09:47:22 UTC 2017

Modified Files:
src/sys/net: if_pppoe.c

Log Message:
Integrate two locks used to protect PPPoE softc. Contributed by s-yamaguchi@IIJ.

PPPOE_SESSION_LOCK protects variables used in PPP packet
processing, on the other hand PPPOE_PARAM_LOCK protects
the other variables used to establish a PPPoE session id.

Those locks isn't acquired in the same time because the
PPP packet processing doesn't work without PPPoE session id.
By the reason, the locks can be integrated into PPPOE_LOCK.

Add locking notes later.


To generate a diff of this commit:
cvs rdiff -u -r1.126 -r1.127 src/sys/net/if_pppoe.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/net/if_pppoe.c
diff -u src/sys/net/if_pppoe.c:1.126 src/sys/net/if_pppoe.c:1.127
--- src/sys/net/if_pppoe.c:1.126	Thu Jul 20 02:34:24 2017
+++ src/sys/net/if_pppoe.c	Thu Oct 12 09:47:21 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: if_pppoe.c,v 1.126 2017/07/20 02:34:24 knakahara Exp $ */
+/* $NetBSD: if_pppoe.c,v 1.127 2017/10/12 09:47:21 knakahara Exp $ */
 
 /*-
  * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.126 2017/07/20 02:34:24 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.127 2017/10/12 09:47:21 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "pppoe.h"
@@ -133,18 +133,12 @@ struct pppoetag {
 #define	IFF_PASSIVE	IFF_LINK0	/* wait passively for connection */
 #endif
 
-#define PPPOE_SESSION_LOCK(_sc, _op)	rw_enter(&(_sc)->sc_session_lock, (_op))
-#define PPPOE_SESSION_UNLOCK(_sc)	rw_exit(&(_sc)->sc_session_lock)
-#define PPPOE_SESSION_LOCKED(_sc)	rw_lock_held(&(_sc)->sc_session_lock)
-#define PPPOE_SESSION_WLOCKED(_sc)	rw_write_held(&(_sc)->sc_session_lock)
-#define PPPOE_SESSION_RLOCKED(_sc)	rw_read_held(&(_sc)->sc_session_lock)
-
-#define PPPOE_PARAM_LOCK(_sc)		if ((_sc)->sc_lock) \
-		mutex_enter((_sc)->sc_lock)
-#define PPPOE_PARAM_UNLOCK(_sc)		if ((_sc)->sc_lock) \
-		mutex_exit((_sc)->sc_lock)
-#define PPPOE_PARAM_LOCKED(_sc)		(!(_sc)->sc_lock || \
-		mutex_owned((_sc)->sc_lock))
+#define PPPOE_LOCK(_sc, _op)	rw_enter(&(_sc)->sc_lock, (_op))
+#define PPPOE_UNLOCK(_sc)	rw_exit(&(_sc)->sc_lock)
+#define PPPOE_LOCKED(_sc)	rw_lock_held(&(_sc)->sc_lock)
+#define PPPOE_WLOCKED(_sc)	rw_write_held(&(_sc)->sc_lock)
+#define PPPOE_RLOCKED(_sc)	rw_read_held(&(_sc)->sc_lock)
+
 #ifdef PPPOE_MPSAFE
 #define DECLARE_SPLNET_VARIABLE
 #define ACQUIRE_SPLNET()	do { } while (0)
@@ -165,7 +159,6 @@ struct pppoe_softc {
 	struct ifnet *sc_eth_if;	/* ethernet interface we are using */
 
 	int sc_state;			/* discovery phase or session connected */
-	bool sc_state_updating;		/* state update in other components */
 	struct ether_addr sc_dest;	/* hardware address of concentrator */
 	uint16_t sc_session;		/* PPPoE session id */
 
@@ -182,8 +175,7 @@ struct pppoe_softc {
 	callout_t sc_timeout;	/* timeout while not in session state */
 	int sc_padi_retried;		/* number of PADI retries already done */
 	int sc_padr_retried;		/* number of PADR retries already done */
-	krwlock_t sc_session_lock;	/* lock of sc_state, sc_session, and sc_eth_if */
-	kmutex_t *sc_lock;		/* lock of other parameters */
+	krwlock_t sc_lock;	/* lock of sc_state, sc_session, and sc_eth_if */
 };
 
 /* incoming traffic will be queued here */
@@ -343,8 +335,7 @@ pppoe_clone_create(struct if_clone *ifc,
 		pfil_add_ihook(pppoe_ifattach_hook, NULL, PFIL_IFNET, if_pfil);
 	}
 
-	sc->sc_lock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_SOFTNET);
-	rw_init(&sc->sc_session_lock);
+	rw_init(&sc->sc_lock);
 
 	rw_enter(&pppoe_softc_list_lock, RW_WRITER);
 	LIST_INSERT_HEAD(&pppoe_softc_list, sc, sc_list);
@@ -359,7 +350,7 @@ pppoe_clone_destroy(struct ifnet *ifp)
 
 	rw_enter(&pppoe_softc_list_lock, RW_WRITER);
 
-	PPPOE_PARAM_LOCK(sc);
+	PPPOE_LOCK(sc, RW_WRITER);
 	callout_halt(&sc->sc_timeout, NULL);
 
 	LIST_REMOVE(sc, sc_list);
@@ -369,7 +360,6 @@ pppoe_clone_destroy(struct ifnet *ifp)
 	}
 	rw_exit(&pppoe_softc_list_lock);
 
-	PPPOE_SESSION_LOCK(sc, RW_WRITER);
 
 	bpf_detach(ifp);
 	sppp_detach(&sc->sc_sppp.pp_if);
@@ -384,11 +374,8 @@ pppoe_clone_destroy(struct ifnet *ifp)
 		free(sc->sc_relay_sid, M_DEVBUF);
 	callout_destroy(&sc->sc_timeout);
 
-	PPPOE_PARAM_UNLOCK(sc);
-	if (sc->sc_lock)
-		mutex_obj_free(sc->sc_lock);
-	PPPOE_SESSION_UNLOCK(sc);
-	rw_destroy(&sc->sc_session_lock);
+	PPPOE_UNLOCK(sc);
+	rw_destroy(&sc->sc_lock);
 
 	free(sc, M_DEVBUF);
 
@@ -410,14 +397,13 @@ pppoe_find_softc_by_session(u_int sessio
 		return NULL;
 	rw_enter(&pppoe_softc_list_lock, RW_READER);
 	LIST_FOREACH(sc, &pppoe_softc_list, sc_list) {
-		PPPOE_SESSION_LOCK(sc, lock);
-		if (!sc->sc_state_updating
-		&& sc->sc_state == PPPOE_STATE_SESSION
+		PPPOE_LOCK(sc, lock);
+		if ( sc->sc_state == PPPOE_STATE_SESSION
 		&& sc->sc_

CVS commit: src/doc

2017-10-11 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Oct 12 03:27:00 UTC 2017

Modified Files:
src/doc: TODO.smpnet

Log Message:
add opencrypto(9)'s scalability comment


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/doc/TODO.smpnet

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/doc/TODO.smpnet
diff -u src/doc/TODO.smpnet:1.13 src/doc/TODO.smpnet:1.14
--- src/doc/TODO.smpnet:1.13	Thu Aug 10 09:26:55 2017
+++ src/doc/TODO.smpnet	Thu Oct 12 03:27:00 2017
@@ -1,4 +1,4 @@
-$NetBSD: TODO.smpnet,v 1.13 2017/08/10 09:26:55 ozaki-r Exp $
+$NetBSD: TODO.smpnet,v 1.14 2017/10/12 03:27:00 knakahara Exp $
 
 MP-safe components
 ==
@@ -153,3 +153,5 @@ Scalability
flows per CPU
  - ipsec(4) isn't scalable on the number of SA/SP; the cost of a look-up
is O(n)
+ - opencrypto(9)'s crypto_newsession()/crypto_freesession() aren't scalable
+   as they are serialized by one mutex



CVS commit: src/sys/arch/powerpc/booke/dev

2017-10-01 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Oct  2 01:55:40 UTC 2017

Modified Files:
src/sys/arch/powerpc/booke/dev: pq3etsec.c

Log Message:
only get vtag when we have vtag like the other drivers.

like if_bge.c:1.312 and if_stge.c:1.64.
fixed by s-yamaguchi@IIJ, thanks.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/sys/arch/powerpc/booke/dev/pq3etsec.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/arch/powerpc/booke/dev/pq3etsec.c
diff -u src/sys/arch/powerpc/booke/dev/pq3etsec.c:1.30 src/sys/arch/powerpc/booke/dev/pq3etsec.c:1.31
--- src/sys/arch/powerpc/booke/dev/pq3etsec.c:1.30	Tue Sep 26 07:42:05 2017
+++ src/sys/arch/powerpc/booke/dev/pq3etsec.c	Mon Oct  2 01:55:40 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: pq3etsec.c,v 1.30 2017/09/26 07:42:05 knakahara Exp $	*/
+/*	$NetBSD: pq3etsec.c,v 1.31 2017/10/02 01:55:40 knakahara Exp $	*/
 /*-
  * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -41,7 +41,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: pq3etsec.c,v 1.30 2017/09/26 07:42:05 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pq3etsec.c,v 1.31 2017/10/02 01:55:40 knakahara Exp $");
 
 #include 
 #include 
@@ -1996,7 +1996,7 @@ pq3etsec_tx_offload(
 	KASSERT(m->m_flags & M_PKTHDR);
 
 	have_vtag = vlan_has_tag(m);
-	vtag = vlan_get_tag(m);
+	vtag = (have_vtag) ? vlan_get_tag(m) : 0;
 
 	/*
 	 * Let see if we are doing any offload first.
@@ -2031,7 +2031,7 @@ pq3etsec_tx_offload(
 		fcb.txfcb_l4os = M_CSUM_DATA_IPv6_HL(m->m_pkthdr.csum_data);
 	fcb.txfcb_l3os = ETHER_HDR_LEN;
 	fcb.txfcb_phcs = 0;
-	fcb.txfcb_vlctl = have_vtag ? vtag : 0;
+	fcb.txfcb_vlctl = vtag;
 
 #if 0
 	printf("%s: csum_flags=%#x: txfcb flags=%#x lsos=%u l4os=%u phcs=%u vlctl=%#x\n",



CVS commit: src/sys

2017-09-26 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Tue Sep 26 07:42:06 UTC 2017

Modified Files:
src/sys/arch/powerpc/booke/dev: pq3etsec.c
src/sys/arch/x86/pci: if_vmx.c
src/sys/dev/ic: i82557.c rtl8169.c
src/sys/dev/pci: if_age.c if_alc.c if_ale.c if_bge.c if_bnx.c if_jme.c
if_nfe.c if_sip.c if_stge.c if_ti.c if_txp.c if_vge.c if_wm.c
src/sys/dev/pci/cxgb: cxgb_sge.c
src/sys/dev/pci/ixgbe: ix_txrx.c
src/sys/net: if_ether.h if_ethersubr.c if_vlan.c
src/sys/net/agr: if_agrether_hash.c
src/sys/net80211: ieee80211_input.c ieee80211_output.c
src/sys/sys: mbuf.h

Log Message:
VLAN ID uses pkthdr instead of mtag now. Contributed by s-yamaguchi@IIJ.

I just commit by proxy. Reviewed by joerg@n.o and christos@n.o, thanks.
See http://mail-index.netbsd.org/tech-net/2017/09/26/msg006459.html

XXX need pullup to -8 branch


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sys/arch/powerpc/booke/dev/pq3etsec.c
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/x86/pci/if_vmx.c
cvs rdiff -u -r1.147 -r1.148 src/sys/dev/ic/i82557.c
cvs rdiff -u -r1.151 -r1.152 src/sys/dev/ic/rtl8169.c
cvs rdiff -u -r1.50 -r1.51 src/sys/dev/pci/if_age.c
cvs rdiff -u -r1.24 -r1.25 src/sys/dev/pci/if_alc.c
cvs rdiff -u -r1.22 -r1.23 src/sys/dev/pci/if_ale.c
cvs rdiff -u -r1.310 -r1.311 src/sys/dev/pci/if_bge.c
cvs rdiff -u -r1.61 -r1.62 src/sys/dev/pci/if_bnx.c
cvs rdiff -u -r1.31 -r1.32 src/sys/dev/pci/if_jme.c
cvs rdiff -u -r1.63 -r1.64 src/sys/dev/pci/if_nfe.c
cvs rdiff -u -r1.166 -r1.167 src/sys/dev/pci/if_sip.c
cvs rdiff -u -r1.62 -r1.63 src/sys/dev/pci/if_stge.c
cvs rdiff -u -r1.101 -r1.102 src/sys/dev/pci/if_ti.c
cvs rdiff -u -r1.47 -r1.48 src/sys/dev/pci/if_txp.c
cvs rdiff -u -r1.60 -r1.61 src/sys/dev/pci/if_vge.c
cvs rdiff -u -r1.537 -r1.538 src/sys/dev/pci/if_wm.c
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/pci/cxgb/cxgb_sge.c
cvs rdiff -u -r1.28 -r1.29 src/sys/dev/pci/ixgbe/ix_txrx.c
cvs rdiff -u -r1.66 -r1.67 src/sys/net/if_ether.h
cvs rdiff -u -r1.243 -r1.244 src/sys/net/if_ethersubr.c
cvs rdiff -u -r1.99 -r1.100 src/sys/net/if_vlan.c
cvs rdiff -u -r1.3 -r1.4 src/sys/net/agr/if_agrether_hash.c
cvs rdiff -u -r1.88 -r1.89 src/sys/net80211/ieee80211_input.c
cvs rdiff -u -r1.58 -r1.59 src/sys/net80211/ieee80211_output.c
cvs rdiff -u -r1.170 -r1.171 src/sys/sys/mbuf.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/arch/powerpc/booke/dev/pq3etsec.c
diff -u src/sys/arch/powerpc/booke/dev/pq3etsec.c:1.29 src/sys/arch/powerpc/booke/dev/pq3etsec.c:1.30
--- src/sys/arch/powerpc/booke/dev/pq3etsec.c:1.29	Thu Dec 15 09:28:04 2016
+++ src/sys/arch/powerpc/booke/dev/pq3etsec.c	Tue Sep 26 07:42:05 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: pq3etsec.c,v 1.29 2016/12/15 09:28:04 ozaki-r Exp $	*/
+/*	$NetBSD: pq3etsec.c,v 1.30 2017/09/26 07:42:05 knakahara Exp $	*/
 /*-
  * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -41,7 +41,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: pq3etsec.c,v 1.29 2016/12/15 09:28:04 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pq3etsec.c,v 1.30 2017/09/26 07:42:05 knakahara Exp $");
 
 #include 
 #include 
@@ -1512,8 +1512,7 @@ pq3etsec_rx_offload(
 	const struct rxfcb *fcb)
 {
 	if (fcb->rxfcb_flags & RXFCB_VLN) {
-		VLAN_INPUT_TAG(&sc->sc_if, m, fcb->rxfcb_vlctl,
-		m_freem(m); return false);
+		vlan_set_tag(m, fcb->rxfcb_vlctl);
 	}
 	if ((fcb->rxfcb_flags & RXFCB_IP) == 0
 	|| (fcb->rxfcb_flags & (RXFCB_CIP|RXFCB_CTU)) == 0)
@@ -1991,14 +1990,18 @@ pq3etsec_tx_offload(
 {
 	struct mbuf *m = *mp;
 	u_int csum_flags = m->m_pkthdr.csum_flags;
-	struct m_tag *vtag = VLAN_OUTPUT_TAG(&sc->sc_ec, m);
+	bool have_vtag;
+	uint16_t vtag;
 
 	KASSERT(m->m_flags & M_PKTHDR);
 
+	have_vtag = vlan_has_tag(m);
+	vtag = vlan_get_tag(m);
+
 	/*
 	 * Let see if we are doing any offload first.
 	 */
-	if (csum_flags == 0 && vtag == 0) {
+	if (csum_flags == 0 && !have_vtag) {
 		m->m_flags &= ~M_HASFCB;
 		return;
 	}
@@ -2012,7 +2015,7 @@ pq3etsec_tx_offload(
 		| ((csum_flags & M_CSUM_CIP) ? TXFCB_CIP : 0)
 		| ((csum_flags & M_CSUM_CTU) ? TXFCB_CTU : 0);
 	}
-	if (vtag) {
+	if (have_vtag) {
 		flags |= TXFCB_VLN;
 	}
 	if (flags == 0) {
@@ -2028,7 +2031,7 @@ pq3etsec_tx_offload(
 		fcb.txfcb_l4os = M_CSUM_DATA_IPv6_HL(m->m_pkthdr.csum_data);
 	fcb.txfcb_l3os = ETHER_HDR_LEN;
 	fcb.txfcb_phcs = 0;
-	fcb.txfcb_vlctl = vtag ? VLAN_TAG_VALUE(vtag) & 0x : 0;
+	fcb.txfcb_vlctl = have_vtag ? vtag : 0;
 
 #if 0
 	printf("%s: csum_flags=%#x: txfcb flags=%#x lsos=%u l4os=%u phcs=%u vlctl=%#x\n",
@@ -2063,7 +2066,6 @@ pq3etsec_tx_offload(
 panic("%s: impossible M_CSUM flags %#x",
 device_xname(sc->sc_dev), csum_flags);
 #endif
-			} else if (vtag) {
 			}
 
 			m->m_flags &= ~M_HASFCB;

Index: src/sys/arch/x86/pci/if_vmx.c
diff -u src/sys/arch/x86/pci/if_vmx.c:1.19 src/sys/arch/x86/pc

CVS commit: src/sys/opencrypto

2017-09-21 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Sep 22 03:04:06 UTC 2017

Modified Files:
src/sys/opencrypto: crypto.c

Log Message:
fix opencrypto(9) part of PR kern/52515

percpu data use pointers to TAILQ instead of TAILQ itself.


To generate a diff of this commit:
cvs rdiff -u -r1.100 -r1.101 src/sys/opencrypto/crypto.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/opencrypto/crypto.c
diff -u src/sys/opencrypto/crypto.c:1.100 src/sys/opencrypto/crypto.c:1.101
--- src/sys/opencrypto/crypto.c:1.100	Mon Jul 31 04:25:45 2017
+++ src/sys/opencrypto/crypto.c	Fri Sep 22 03:04:06 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: crypto.c,v 1.100 2017/07/31 04:25:45 knakahara Exp $ */
+/*	$NetBSD: crypto.c,v 1.101 2017/09/22 03:04:06 knakahara Exp $ */
 /*	$FreeBSD: src/sys/opencrypto/crypto.c,v 1.4.2.5 2003/02/26 00:14:05 sam Exp $	*/
 /*	$OpenBSD: crypto.c,v 1.41 2002/07/17 23:52:38 art Exp $	*/
 
@@ -53,7 +53,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.100 2017/07/31 04:25:45 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: crypto.c,v 1.101 2017/09/22 03:04:06 knakahara Exp $");
 
 #include 
 #include 
@@ -105,8 +105,8 @@ static	void *crypto_ret_si;
 TAILQ_HEAD(crypto_crp_q, cryptop);
 TAILQ_HEAD(crypto_crp_kq, cryptkop);
 struct crypto_crp_qs {
-	struct crypto_crp_q crp_q;
-	struct crypto_crp_kq crp_kq;
+	struct crypto_crp_q *crp_q;
+	struct crypto_crp_kq *crp_kq;
 };
 static percpu_t *crypto_crp_qs_percpu;
 
@@ -136,7 +136,7 @@ crypto_crp_q_is_busy_pc(void *p, void *a
 	struct crypto_crp_qs *qs_pc = p;
 	bool *isempty = arg;
 
-	if (!TAILQ_EMPTY(&qs_pc->crp_q) || !TAILQ_EMPTY(&qs_pc->crp_kq))
+	if (!TAILQ_EMPTY(qs_pc->crp_q) || !TAILQ_EMPTY(qs_pc->crp_kq))
 		*isempty = true;
 }
 
@@ -145,8 +145,11 @@ crypto_crp_qs_init_pc(void *p, void *arg
 {
 	struct crypto_crp_qs *qs = p;
 
-	TAILQ_INIT(&qs->crp_q);
-	TAILQ_INIT(&qs->crp_kq);
+	qs->crp_q = kmem_alloc(sizeof(struct crypto_crp_q), KM_SLEEP);
+	qs->crp_kq = kmem_alloc(sizeof(struct crypto_crp_kq), KM_SLEEP);
+
+	TAILQ_INIT(qs->crp_q);
+	TAILQ_INIT(qs->crp_kq);
 }
 
 /*
@@ -1310,7 +1313,7 @@ crypto_dispatch(struct cryptop *crp)
 		 * don't care list order in batch job.
 		 */
 		crp_qs = crypto_get_crp_qs(&s);
-		crp_q = &crp_qs->crp_q;
+		crp_q = crp_qs->crp_q;
 		wasempty  = TAILQ_EMPTY(crp_q);
 		TAILQ_INSERT_TAIL(crp_q, crp, crp_next);
 		crypto_put_crp_qs(&s);
@@ -1325,7 +1328,7 @@ crypto_dispatch(struct cryptop *crp)
 	}
 
 	crp_qs = crypto_get_crp_qs(&s);
-	crp_q = &crp_qs->crp_q;
+	crp_q = crp_qs->crp_q;
 	cap = crypto_checkdriver_lock(CRYPTO_SESID2HID(crp->crp_sid));
 	/*
 	 * TODO:
@@ -1402,7 +1405,7 @@ crypto_kdispatch(struct cryptkop *krp)
 	cryptostats.cs_kops++;
 
 	crp_qs = crypto_get_crp_qs(&s);
-	crp_kq = &crp_qs->crp_kq;
+	crp_kq = crp_qs->crp_kq;
 	cap = crypto_checkdriver_lock(krp->krp_hid);
 	/*
 	 * TODO:
@@ -1908,8 +1911,8 @@ cryptointr(void *arg __unused)
 
 	cryptostats.cs_intrs++;
 	crp_qs = crypto_get_crp_qs(&s);
-	crp_q = &crp_qs->crp_q;
-	crp_kq = &crp_qs->crp_kq;
+	crp_q = crp_qs->crp_q;
+	crp_kq = crp_qs->crp_kq;
 	do {
 		/*
 		 * Find the first element in the queue that can be



CVS commit: src/sys/net

2017-09-21 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Sep 21 11:42:17 UTC 2017

Modified Files:
src/sys/net: if_loop.c

Log Message:
loop_clone_create() must be called after ncpu is counted up for all CPUs.

loop_clone_create() uses ncpu in the following call-path.
- loop_clone_create()
  - if_attach()
- if_percpuq_create()
  - softint_establish() // use ncpu
  - percpu_foreach() // use ncpu

However, loopinit() of built-in module is called from
module_init_class(MODULE_CLASS_DRIVER) which is called before ncpu is counted
up in some architectures. So, It is too fast.
On the other hand, it is too late for rump netinet component to call
loop_clone_create() in config_finalize().

As the result, loop_clone_create() shuld be called in loopattach() for built-in
module, and in loopinit() for dynamic module.

XXX need pullup -8 branch


To generate a diff of this commit:
cvs rdiff -u -r1.94 -r1.95 src/sys/net/if_loop.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/net/if_loop.c
diff -u src/sys/net/if_loop.c:1.94 src/sys/net/if_loop.c:1.95
--- src/sys/net/if_loop.c:1.94	Tue Mar 28 08:47:19 2017
+++ src/sys/net/if_loop.c	Thu Sep 21 11:42:17 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_loop.c,v 1.94 2017/03/28 08:47:19 ozaki-r Exp $	*/
+/*	$NetBSD: if_loop.c,v 1.95 2017/09/21 11:42:17 knakahara Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -65,7 +65,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_loop.c,v 1.94 2017/03/28 08:47:19 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_loop.c,v 1.95 2017/09/21 11:42:17 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -146,10 +146,9 @@ void
 loopattach(int n)
 {
 
-	/*
-	 * Nothing to do here, initialization is handled by the
-	 * module initialization code in loopnit() below).
-	 */
+#ifndef _MODULE
+	loop_clone_create(&loop_cloner, 0);	/* lo0 always exists */
+#endif
 }
 
 void
@@ -159,7 +158,9 @@ loopinit(void)
 	if (lo0ifp != NULL)	/* can happen in rump kernel */
 		return;
 
-	(void)loop_clone_create(&loop_cloner, 0);	/* lo0 always exists */
+#ifdef _MODULE
+	loop_clone_create(&loop_cloner, 0);	/* lo0 always exists */
+#endif
 	if_clone_attach(&loop_cloner);
 }
 



CVS commit: src/sys/net

2017-09-21 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Sep 21 09:48:15 UTC 2017

Modified Files:
src/sys/net: if_gif.h

Log Message:
update locking notes.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/sys/net/if_gif.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/net/if_gif.h
diff -u src/sys/net/if_gif.h:1.26 src/sys/net/if_gif.h:1.27
--- src/sys/net/if_gif.h:1.26	Thu Sep 21 09:42:03 2017
+++ src/sys/net/if_gif.h	Thu Sep 21 09:48:15 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_gif.h,v 1.26 2017/09/21 09:42:03 knakahara Exp $	*/
+/*	$NetBSD: if_gif.h,v 1.27 2017/09/21 09:48:15 knakahara Exp $	*/
 /*	$KAME: if_gif.h,v 1.23 2001/07/27 09:21:42 itojun Exp $	*/
 
 /*
@@ -81,6 +81,17 @@ int	gif_encapcheck(struct mbuf *, int, i
 
 /*
  * Locking notes:
- * - All members of struct si_sync are protected by si_lock (an adaptive mutex)
+ * + gif_softc_list is protected by gif_softcs.lock (an adaptive mutex)
+ *   gif_softc_list is list of all gif_softcs. It is used by ioctl
+ *   context only.
+ * + Members of struct gif_softc except for gif_ro_percpu are protected by
+ *   - encap_lock for writer
+ *   - stopping processing when writer begin to run
+ * for reader(Tx and Rx processing)
+ * + Each CPU's gif_ro.gr_ro of gif_ro_percpu are protected by
+ *   percpu'ed gif_ro.gr_lock.
+ *
+ * Locking order:
+ * - encap_lock => gif_softcs.lock
  */
 #endif /* !_NET_IF_GIF_H_ */



CVS commit: src/sys/net

2017-09-21 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Sep 21 09:46:14 UTC 2017

Modified Files:
src/sys/net: if_gif.c

Log Message:
add lock for sclist to exclude ifconfig gifX add/delete and ifconfig gifX tunnel


To generate a diff of this commit:
cvs rdiff -u -r1.129 -r1.130 src/sys/net/if_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/net/if_gif.c
diff -u src/sys/net/if_gif.c:1.129 src/sys/net/if_gif.c:1.130
--- src/sys/net/if_gif.c:1.129	Thu Sep 21 09:42:03 2017
+++ src/sys/net/if_gif.c	Thu Sep 21 09:46:14 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_gif.c,v 1.129 2017/09/21 09:42:03 knakahara Exp $	*/
+/*	$NetBSD: if_gif.c,v 1.130 2017/09/21 09:46:14 knakahara Exp $	*/
 /*	$KAME: if_gif.c,v 1.76 2001/08/20 02:01:02 kjc Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.129 2017/09/21 09:42:03 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.130 2017/09/21 09:46:14 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -96,7 +96,11 @@ __KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1
 /*
  * gif global variable definitions
  */
-static LIST_HEAD(, gif_softc) gif_softc_list;
+LIST_HEAD(gif_sclist, gif_softc);
+static struct {
+	struct gif_sclist list;
+	kmutex_t lock;
+} gif_softcs __cacheline_aligned;
 
 static void	gif_ro_init_pc(void *, void *, struct cpu_info *);
 static void	gif_ro_fini_pc(void *, void *, struct cpu_info *);
@@ -208,7 +212,8 @@ static void
 gifinit(void)
 {
 
-	LIST_INIT(&gif_softc_list);
+	mutex_init(&gif_softcs.lock, MUTEX_DEFAULT, IPL_NONE);
+	LIST_INIT(&gif_softcs.list);
 	if_clone_attach(&gif_cloner);
 
 	gif_sysctl_setup();
@@ -219,8 +224,11 @@ gifdetach(void)
 {
 	int error = 0;
 
-	if (!LIST_EMPTY(&gif_softc_list))
+	mutex_enter(&gif_softcs.lock);
+	if (!LIST_EMPTY(&gif_softcs.list)) {
+		mutex_exit(&gif_softcs.lock);
 		error = EBUSY;
+	}
 
 	if (error == 0) {
 		if_clone_detach(&gif_cloner);
@@ -244,7 +252,9 @@ gif_clone_create(struct if_clone *ifc, i
 	sc->gif_ro_percpu = percpu_alloc(sizeof(struct gif_ro));
 	percpu_foreach(sc->gif_ro_percpu, gif_ro_init_pc, NULL);
 
-	LIST_INSERT_HEAD(&gif_softc_list, sc, gif_list);
+	mutex_enter(&gif_softcs.lock);
+	LIST_INSERT_HEAD(&gif_softcs.list, sc, gif_list);
+	mutex_exit(&gif_softcs.lock);
 	return (0);
 }
 
@@ -994,7 +1004,8 @@ gif_set_tunnel(struct ifnet *ifp, struct
 		return error;
 	}
 
-	LIST_FOREACH(sc2, &gif_softc_list, gif_list) {
+	mutex_enter(&gif_softcs.lock);
+	LIST_FOREACH(sc2, &gif_softcs.list, gif_list) {
 		if (sc2 == sc)
 			continue;
 		if (!sc2->gif_pdst || !sc2->gif_psrc)
@@ -1003,12 +1014,14 @@ gif_set_tunnel(struct ifnet *ifp, struct
 		if (sockaddr_cmp(sc2->gif_pdst, dst) == 0 &&
 		sockaddr_cmp(sc2->gif_psrc, src) == 0) {
 			/* continue to use the old configureation. */
+			mutex_exit(&gif_softcs.lock);
 			error =  EADDRNOTAVAIL;
 			goto out;
 		}
 
 		/* XXX both end must be valid? (I mean, not 0.0.0.0) */
 	}
+	mutex_exit(&gif_softcs.lock);
 
 	nsrc = sockaddr_dup(src, M_WAITOK);
 	ndst = sockaddr_dup(dst, M_WAITOK);



CVS commit: src/sys

2017-09-21 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Sep 21 09:42:03 UTC 2017

Modified Files:
src/sys/net: if_gif.c if_gif.h
src/sys/netinet: in_gif.c
src/sys/netinet6: in6_gif.c

Log Message:
add lock for percpu route like l2tp(4).


To generate a diff of this commit:
cvs rdiff -u -r1.128 -r1.129 src/sys/net/if_gif.c
cvs rdiff -u -r1.25 -r1.26 src/sys/net/if_gif.h
cvs rdiff -u -r1.87 -r1.88 src/sys/netinet/in_gif.c
cvs rdiff -u -r1.85 -r1.86 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/net/if_gif.c
diff -u src/sys/net/if_gif.c:1.128 src/sys/net/if_gif.c:1.129
--- src/sys/net/if_gif.c:1.128	Tue Aug  8 03:14:50 2017
+++ src/sys/net/if_gif.c	Thu Sep 21 09:42:03 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_gif.c,v 1.128 2017/08/08 03:14:50 knakahara Exp $	*/
+/*	$NetBSD: if_gif.c,v 1.129 2017/09/21 09:42:03 knakahara Exp $	*/
 /*	$KAME: if_gif.c,v 1.76 2001/08/20 02:01:02 kjc Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.128 2017/08/08 03:14:50 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.129 2017/09/21 09:42:03 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -98,6 +98,9 @@ __KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1
  */
 static LIST_HEAD(, gif_softc) gif_softc_list;
 
+static void	gif_ro_init_pc(void *, void *, struct cpu_info *);
+static void	gif_ro_fini_pc(void *, void *, struct cpu_info *);
+
 static void	gifattach0(struct gif_softc *);
 static int	gif_output(struct ifnet *, struct mbuf *,
 			   const struct sockaddr *, const struct rtentry *);
@@ -238,7 +241,9 @@ gif_clone_create(struct if_clone *ifc, i
 
 	gifattach0(sc);
 
-	sc->gif_ro_percpu = percpu_alloc(sizeof(struct route));
+	sc->gif_ro_percpu = percpu_alloc(sizeof(struct gif_ro));
+	percpu_foreach(sc->gif_ro_percpu, gif_ro_init_pc, NULL);
+
 	LIST_INSERT_HEAD(&gif_softc_list, sc, gif_list);
 	return (0);
 }
@@ -270,12 +275,30 @@ gifattach0(struct gif_softc *sc)
 	bpf_attach(&sc->gif_if, DLT_NULL, sizeof(u_int));
 }
 
+static void
+gif_ro_init_pc(void *p, void *arg __unused, struct cpu_info *ci __unused)
+{
+	struct gif_ro *gro = p;
+
+	mutex_init(&gro->gr_lock, MUTEX_DEFAULT, IPL_NONE);
+}
+
+static void
+gif_ro_fini_pc(void *p, void *arg __unused, struct cpu_info *ci __unused)
+{
+	struct gif_ro *gro = p;
+
+	rtcache_free(&gro->gr_ro);
+
+	mutex_destroy(&gro->gr_lock);
+}
+
 void
 gif_rtcache_free_pc(void *p, void *arg __unused, struct cpu_info *ci __unused)
 {
-	struct route *ro = p;
+	struct gif_ro *gro = p;
 
-	rtcache_free(ro);
+	rtcache_free(&gro->gr_ro);
 }
 
 static int
@@ -288,8 +311,10 @@ gif_clone_destroy(struct ifnet *ifp)
 	gif_delete_tunnel(&sc->gif_if);
 	bpf_detach(ifp);
 	if_detach(ifp);
-	percpu_foreach(sc->gif_ro_percpu, gif_rtcache_free_pc, NULL);
-	percpu_free(sc->gif_ro_percpu, sizeof(struct route));
+
+	percpu_foreach(sc->gif_ro_percpu, gif_ro_fini_pc, NULL);
+	percpu_free(sc->gif_ro_percpu, sizeof(struct gif_ro));
+
 	kmem_free(sc, sizeof(struct gif_softc));
 
 	return (0);

Index: src/sys/net/if_gif.h
diff -u src/sys/net/if_gif.h:1.25 src/sys/net/if_gif.h:1.26
--- src/sys/net/if_gif.h:1.25	Wed Dec 14 11:19:15 2016
+++ src/sys/net/if_gif.h	Thu Sep 21 09:42:03 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_gif.h,v 1.25 2016/12/14 11:19:15 knakahara Exp $	*/
+/*	$NetBSD: if_gif.h,v 1.26 2017/09/21 09:42:03 knakahara Exp $	*/
 /*	$KAME: if_gif.h,v 1.23 2001/07/27 09:21:42 itojun Exp $	*/
 
 /*
@@ -49,11 +49,16 @@
 
 struct encaptab;
 
+struct gif_ro {
+	struct route gr_ro;
+	kmutex_t gr_lock;
+};
+
 struct gif_softc {
 	struct ifnet	gif_if;	   /* common area - must be at the top */
 	struct sockaddr	*gif_psrc; /* Physical src addr */
 	struct sockaddr	*gif_pdst; /* Physical dst addr */
-	percpu_t *gif_ro_percpu;
+	percpu_t *gif_ro_percpu;   /* struct gif_ro */
 	int		gif_flags;
 	const struct encaptab *encap_cookie4;
 	const struct encaptab *encap_cookie6;

Index: src/sys/netinet/in_gif.c
diff -u src/sys/netinet/in_gif.c:1.87 src/sys/netinet/in_gif.c:1.88
--- src/sys/netinet/in_gif.c:1.87	Fri Jan  6 03:25:13 2017
+++ src/sys/netinet/in_gif.c	Thu Sep 21 09:42:03 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: in_gif.c,v 1.87 2017/01/06 03:25:13 knakahara Exp $	*/
+/*	$NetBSD: in_gif.c,v 1.88 2017/09/21 09:42:03 knakahara Exp $	*/
 /*	$KAME: in_gif.c,v 1.66 2001/07/29 04:46:09 itojun Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in_gif.c,v 1.87 2017/01/06 03:25:13 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in_gif.c,v 1.88 2017/09/21 09:42:03 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -84,6 +84,7 @@ in_gif_output(struct ifnet *ifp, int fam
 {
 	struct rtentry *rt;
 	struct route *ro;
+	struct gif_ro *gro;
 	struct gif_softc *sc = ifp->if_softc;
 	struct sockaddr_in *sin_src = satosin(sc->gif_psrc);
 	struct sockaddr_in *sin_dst = satosin(sc->gif_pdst);
@@ 

CVS commit: src/sys/netipsec

2017-08-21 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Aug 21 07:38:42 UTC 2017

Modified Files:
src/sys/netipsec: key.c

Log Message:
remove unnecessary comment.


To generate a diff of this commit:
cvs rdiff -u -r1.224 -r1.225 src/sys/netipsec/key.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/netipsec/key.c
diff -u src/sys/netipsec/key.c:1.224 src/sys/netipsec/key.c:1.225
--- src/sys/netipsec/key.c:1.224	Mon Aug 21 02:35:13 2017
+++ src/sys/netipsec/key.c	Mon Aug 21 07:38:42 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: key.c,v 1.224 2017/08/21 02:35:13 knakahara Exp $	*/
+/*	$NetBSD: key.c,v 1.225 2017/08/21 07:38:42 knakahara Exp $	*/
 /*	$FreeBSD: src/sys/netipsec/key.c,v 1.3.2.3 2004/02/14 22:23:23 bms Exp $	*/
 /*	$KAME: key.c,v 1.191 2001/06/27 10:46:49 sakane Exp $	*/
 
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: key.c,v 1.224 2017/08/21 02:35:13 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: key.c,v 1.225 2017/08/21 07:38:42 knakahara Exp $");
 
 /*
  * This code is referd to RFC 2367
@@ -8291,7 +8291,7 @@ key_sa_chgstate(struct secasvar *sav, u_
 		return;
 
 	key_unlink_sav(sav);
-	localcount_fini(&sav->localcount); /*  fixed by ozaki-r */
+	localcount_fini(&sav->localcount);
 	SAVLIST_ENTRY_DESTROY(sav);
 	key_init_sav(sav);
 



<    1   2   3   4   5   6   >