Re: CVS commit: src/sys/net

2020-01-28 Thread Kamil Rytarowski
On 29.01.2020 07:40, Jason Thorpe wrote:
> 
>> On Jan 28, 2020, at 10:25 PM, Kamil Rytarowski  wrote:
>>
>> The distribution build breaks for me with:
> 
> Should be fixed with:
> 
>  /cvsroot/src/sys/rump/net/lib/libnet/Makefile,v  <--  Makefile
>  new revision: 1.33; previous revision: 1.32
> 
>> /public/netbsd-root/tooldir.NetBSD-9.99.38-amd64/lib/gcc/x86_64--netbsd/8.3.0/../../../../x86_64--netbsd/bin/ld:
>> /public/netbsd-root/destdir.amd64/usr/lib/librumpnet_net.so: undefined
>> reference to `rumpns_if_stats_init'
>> /public/netbsd-root/tooldir.NetBSD-9.99.38-amd64/lib/gcc/x86_64--netbsd/8.3.0/../../../../x86_64--netbsd/bin/ld:
>> /public/netbsd-root/destdir.amd64/usr/lib/librumpnet_net.so: undefined
>> reference to `rumpns_if_stats_fini'
>> /public/netbsd-root/tooldir.NetBSD-9.99.38-amd64/lib/gcc/x86_64--netbsd/8.3.0/../../../../x86_64--netbsd/bin/ld:
>> /public/netbsd-root/destdir.amd64/usr/lib/librumpnet_net.so: undefined
>> reference to `rumpns_if_stats_to_if_data'
>>
> 
> -- thorpej
> 

It works now!



signature.asc
Description: OpenPGP digital signature


Re: CVS commit: src/sys/net

2020-01-28 Thread Jason Thorpe


> On Jan 28, 2020, at 10:25 PM, Kamil Rytarowski  wrote:
> 
> The distribution build breaks for me with:

Should be fixed with:

 /cvsroot/src/sys/rump/net/lib/libnet/Makefile,v  <--  Makefile
 new revision: 1.33; previous revision: 1.32

> /public/netbsd-root/tooldir.NetBSD-9.99.38-amd64/lib/gcc/x86_64--netbsd/8.3.0/../../../../x86_64--netbsd/bin/ld:
> /public/netbsd-root/destdir.amd64/usr/lib/librumpnet_net.so: undefined
> reference to `rumpns_if_stats_init'
> /public/netbsd-root/tooldir.NetBSD-9.99.38-amd64/lib/gcc/x86_64--netbsd/8.3.0/../../../../x86_64--netbsd/bin/ld:
> /public/netbsd-root/destdir.amd64/usr/lib/librumpnet_net.so: undefined
> reference to `rumpns_if_stats_fini'
> /public/netbsd-root/tooldir.NetBSD-9.99.38-amd64/lib/gcc/x86_64--netbsd/8.3.0/../../../../x86_64--netbsd/bin/ld:
> /public/netbsd-root/destdir.amd64/usr/lib/librumpnet_net.so: undefined
> reference to `rumpns_if_stats_to_if_data'
> 

-- thorpej



Re: CVS commit: src/sys/net

2020-01-28 Thread Kamil Rytarowski
On 29.01.2020 04:16, Jason R Thorpe wrote:
> Module Name:  src
> Committed By: thorpej
> Date: Wed Jan 29 03:16:28 UTC 2020
> 
> Modified Files:
>   src/sys/net: Makefile files.net if.c if.h
> Added Files:
>   src/sys/net: if_stats.c if_stats.h
> 
> Log Message:
> Add support for MP-safe network interface statistics by maintaining them
> in per-cpu storage, and collecting them for export in an if_data structure
> when user-space wants them.
> 
> The new if_stat API is structured to make a gradual transition to the
> new way in network drivers possible, and per-cpu stats are currently
> disabled (thus there is no kernel ABI change).  Once all drivers have
> been converted, the old ABI will be removed, and per-cpu stats will be
> enabled universally.
> 

The distribution build breaks for me with:

/public/netbsd-root/tooldir.NetBSD-9.99.38-amd64/lib/gcc/x86_64--netbsd/8.3.0/../../../../x86_64--netbsd/bin/ld:
/public/netbsd-root/destdir.amd64/usr/lib/librumpnet_net.so: undefined
reference to `rumpns_if_stats_init'
/public/netbsd-root/tooldir.NetBSD-9.99.38-amd64/lib/gcc/x86_64--netbsd/8.3.0/../../../../x86_64--netbsd/bin/ld:
/public/netbsd-root/destdir.amd64/usr/lib/librumpnet_net.so: undefined
reference to `rumpns_if_stats_fini'
/public/netbsd-root/tooldir.NetBSD-9.99.38-amd64/lib/gcc/x86_64--netbsd/8.3.0/../../../../x86_64--netbsd/bin/ld:
/public/netbsd-root/destdir.amd64/usr/lib/librumpnet_net.so: undefined
reference to `rumpns_if_stats_to_if_data'



signature.asc
Description: OpenPGP digital signature


Re: CVS commit: src/sys/net

2019-12-04 Thread Masanobu SAITOH
On 2019/12/05 14:29, SAITOH Masanobu wrote:
> Module Name:  src
> Committed By: msaitoh
> Date: Thu Dec  5 05:29:28 UTC 2019
> 
> Modified Files:
>   src/sys/net: if_media.h
> 
> Log Message:
> Fix previous comment change for ifm_media. It was correct.
> 
>  The real problem is that some driver misuse ifm_media as the current active
> media. struct mii_data has the current active media(mii_media_active). If a
> driver use mii(4), it can be use mii->mii_media_active for this purpose.
> struct ifmedia has no entry for this purpose. Some drivers have an entry

s/Some drivers/Some drivers not using mii(4)/

> in their own softc to keep the value, but some other's don't have it and
> they mistakenly use ifm_media.
> 
>  We might add a new entry to struct ifmedia in future to avoid this confusion
> and for simplify.
> 
> 
> To generate a diff of this commit:
> cvs rdiff -u -r1.67 -r1.68 src/sys/net/if_media.h
> 
> Please note that diffs are not public domain; they are subject to the
> copyright notices on the relevant files.
> 


-- 
---
SAITOH Masanobu (msai...@execsw.org
 msai...@netbsd.org)


CVS commit: src/sys/net

2019-11-29 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Fri Nov 29 17:29:32 UTC 2019

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

Log Message:
bpf can send a packet greater than MCLBYTES (JumboFrame) using multiple mbuf.


To generate a diff of this commit:
cvs rdiff -u -r1.231 -r1.232 src/sys/net/bpf.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/bpf.c
diff -u src/sys/net/bpf.c:1.231 src/sys/net/bpf.c:1.232
--- src/sys/net/bpf.c:1.231	Fri Sep 13 06:39:29 2019
+++ src/sys/net/bpf.c	Fri Nov 29 17:29:31 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpf.c,v 1.231 2019/09/13 06:39:29 maxv Exp $	*/
+/*	$NetBSD: bpf.c,v 1.232 2019/11/29 17:29:31 ryo Exp $	*/
 
 /*
  * Copyright (c) 1990, 1991, 1993
@@ -39,7 +39,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.231 2019/09/13 06:39:29 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.232 2019/11/29 17:29:31 ryo Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_bpf.h"
@@ -321,7 +321,7 @@ static int
 bpf_movein(struct uio *uio, int linktype, uint64_t mtu, struct mbuf **mp,
 	   struct sockaddr *sockp)
 {
-	struct mbuf *m;
+	struct mbuf *m, *m0, *n;
 	int error;
 	size_t len;
 	size_t hlen;
@@ -395,15 +395,7 @@ bpf_movein(struct uio *uio, int linktype
 	if (len - hlen > mtu)
 		return (EMSGSIZE);
 
-	/*
-	 * XXX Avoid complicated buffer chaining ---
-	 * bail if it won't fit in a single mbuf.
-	 * (Take into account possible alignment bytes)
-	 */
-	if (len + align > MCLBYTES)
-		return (EIO);
-
-	m = m_gethdr(M_WAIT, MT_DATA);
+	m0 = m = m_gethdr(M_WAIT, MT_DATA);
 	m_reset_rcvif(m);
 	m->m_pkthdr.len = (int)(len - hlen);
 	if (len + align > MHLEN) {
@@ -415,25 +407,39 @@ bpf_movein(struct uio *uio, int linktype
 	}
 
 	/* Insure the data is properly aligned */
-	if (align > 0) {
+	if (align > 0)
 		m->m_data += align;
-		m->m_len -= (int)align;
+
+	for (;;) {
+		len = M_TRAILINGSPACE(m);
+		if (len > uio->uio_resid)
+			len = uio->uio_resid;
+		error = uiomove(mtod(m, void *), len, uio);
+		if (error)
+			goto bad;
+		m->m_len = len;
+
+		if (uio->uio_resid == 0)
+			break;
+
+		n = m_get(M_WAIT, MT_DATA);
+		m_clget(n, M_WAIT);	/* if fails, there is no problem */
+		m->m_next = n;
+		m = n;
 	}
 
-	error = uiomove(mtod(m, void *), len, uio);
-	if (error)
-		goto bad;
 	if (hlen != 0) {
-		memcpy(sockp->sa_data, mtod(m, void *), hlen);
-		m->m_data += hlen; /* XXX */
-		len -= hlen;
+		/* move link level header in the top of mbuf to sa_data */
+		memcpy(sockp->sa_data, mtod(m0, void *), hlen);
+		m0->m_data += hlen;
+		m0->m_len -= hlen;
 	}
-	m->m_len = (int)len;
-	*mp = m;
+
+	*mp = m0;
 	return (0);
 
 bad:
-	m_freem(m);
+	m_freem(m0);
 	return (error);
 }
 



CVS commit: src/sys/net

2019-11-29 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Fri Nov 29 17:29:32 UTC 2019

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

Log Message:
bpf can send a packet greater than MCLBYTES (JumboFrame) using multiple mbuf.


To generate a diff of this commit:
cvs rdiff -u -r1.231 -r1.232 src/sys/net/bpf.c

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



CVS commit: src/sys/net

2019-11-28 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Thu Nov 28 14:08:22 UTC 2019

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

Log Message:
 Fix comment. The ifm_media member of struct ifmedia is NOT user-set media
word but the current "active" media.

 The user-set media word is one of the ifmedia_entry's ifm_media(A) that
ifm_cur points to (e.g. IFM_AUTO). It can be taken as ifmediareq's ifm_current
entry. The current active media word is the ifm_media(B) entry of struct
ifmedia (e.g 1000baseTX-FDX as the result of auto negotiation). It can be
taken as ifmediareq's ifm_active entry.

struct ifmedia_entry {
TAILQ_ENTRY(ifmedia_entry) ifm_list;
u_int   ifm_media;  /* IFMWD: description of this media */ /* A */
u_int   ifm_data;   /* for driver-specific use */
void*ifm_aux;   /* for driver-specific use */
};

struct ifmedia {
u_int   ifm_mask;   /* IFMWD: mask of changes we don't care */
u_int   ifm_media;  /* IFMWD: current active media word */ /* B */
struct ifmedia_entry *ifm_cur;  /* current user-selected media */
TAILQ_HEAD(, ifmedia_entry) ifm_list; /* list of all supported media */
ifm_change_cb_t ifm_change; /* media change driver callback */
ifm_stat_cb_t   ifm_status; /* media status driver callback */
};

So:

in kernel   SIOCGIFMEDIA(ifmediareq)
-
user-setting:   ifm->ifm_cur->ifm_media ifm_current
current active: ifm->ifm_media  ifm_active

It would be good to rename some members to make those meaning clear.


To generate a diff of this commit:
cvs rdiff -u -r1.66 -r1.67 src/sys/net/if_media.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_media.h
diff -u src/sys/net/if_media.h:1.66 src/sys/net/if_media.h:1.67
--- src/sys/net/if_media.h:1.66	Thu Oct  3 14:41:14 2019
+++ src/sys/net/if_media.h	Thu Nov 28 14:08:22 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_media.h,v 1.66 2019/10/03 14:41:14 jmcneill Exp $	*/
+/*	$NetBSD: if_media.h,v 1.67 2019/11/28 14:08:22 msaitoh Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000, 2001 The NetBSD Foundation, Inc.
@@ -872,7 +872,7 @@ typedef	void (*ifm_stat_cb_t)(struct ifn
  */
 struct ifmedia_entry {
 	TAILQ_ENTRY(ifmedia_entry) ifm_list;
-	u_int	ifm_media;	/* description of this media attachment */
+	u_int	ifm_media;	/* IFMWD: description of this media */
 	u_int	ifm_data;	/* for driver-specific use */
 	void	*ifm_aux;	/* for driver-specific use */
 };
@@ -882,9 +882,9 @@ struct ifmedia_entry {
  * It is used to keep general media state.
  */
 struct ifmedia {
-	u_int	ifm_mask;	/* mask of changes we don't care about */
-	u_int	ifm_media;	/* current user-set media word */
-	struct ifmedia_entry *ifm_cur;	/* currently selected media */
+	u_int	ifm_mask;	/* IFMWD: mask of changes we don't care */
+	u_int	ifm_media;	/* IFMWD: current active media word */
+	struct ifmedia_entry *ifm_cur;	/* current user-selected media */
 	TAILQ_HEAD(, ifmedia_entry) ifm_list; /* list of all supported media */
 	ifm_change_cb_t	ifm_change;	/* media change driver callback */
 	ifm_stat_cb_t	ifm_status;	/* media status driver callback */



CVS commit: src/sys/net

2019-11-28 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Thu Nov 28 14:08:22 UTC 2019

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

Log Message:
 Fix comment. The ifm_media member of struct ifmedia is NOT user-set media
word but the current "active" media.

 The user-set media word is one of the ifmedia_entry's ifm_media(A) that
ifm_cur points to (e.g. IFM_AUTO). It can be taken as ifmediareq's ifm_current
entry. The current active media word is the ifm_media(B) entry of struct
ifmedia (e.g 1000baseTX-FDX as the result of auto negotiation). It can be
taken as ifmediareq's ifm_active entry.

struct ifmedia_entry {
TAILQ_ENTRY(ifmedia_entry) ifm_list;
u_int   ifm_media;  /* IFMWD: description of this media */ /* A */
u_int   ifm_data;   /* for driver-specific use */
void*ifm_aux;   /* for driver-specific use */
};

struct ifmedia {
u_int   ifm_mask;   /* IFMWD: mask of changes we don't care */
u_int   ifm_media;  /* IFMWD: current active media word */ /* B */
struct ifmedia_entry *ifm_cur;  /* current user-selected media */
TAILQ_HEAD(, ifmedia_entry) ifm_list; /* list of all supported media */
ifm_change_cb_t ifm_change; /* media change driver callback */
ifm_stat_cb_t   ifm_status; /* media status driver callback */
};

So:

in kernel   SIOCGIFMEDIA(ifmediareq)
-
user-setting:   ifm->ifm_cur->ifm_media ifm_current
current active: ifm->ifm_media  ifm_active

It would be good to rename some members to make those meaning clear.


To generate a diff of this commit:
cvs rdiff -u -r1.66 -r1.67 src/sys/net/if_media.h

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



CVS commit: src/sys/net

2019-11-20 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Nov 20 08:17:02 UTC 2019

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

Log Message:
"rss_symmetric_key" iniitalizer is too short. Pointed out by ryo@n.o, thanks.

It is not used yet.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/net/rss_config.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/rss_config.c
diff -u src/sys/net/rss_config.c:1.1 src/sys/net/rss_config.c:1.2
--- src/sys/net/rss_config.c:1.1	Fri Feb 16 04:48:32 2018
+++ src/sys/net/rss_config.c	Wed Nov 20 08:17:01 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: rss_config.c,v 1.1 2018/02/16 04:48:32 knakahara Exp $  */
+/*	$NetBSD: rss_config.c,v 1.2 2019/11/20 08:17:01 knakahara Exp $  */
 
 /*
  * Copyright (c) 2018 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: rss_config.c,v 1.1 2018/02/16 04:48:32 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rss_config.c,v 1.2 2019/11/20 08:17:01 knakahara Exp $");
 
 #include 
 #include 
@@ -62,6 +62,7 @@ static uint8_t rss_symmetric_key[RSS_KEY
 	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
 



CVS commit: src/sys/net

2019-11-20 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Nov 20 08:17:02 UTC 2019

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

Log Message:
"rss_symmetric_key" iniitalizer is too short. Pointed out by ryo@n.o, thanks.

It is not used yet.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/net/rss_config.c

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



CVS commit: src/sys/net

2019-11-13 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Thu Nov 14 04:14:30 UTC 2019

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

Log Message:
 Fix comment.


To generate a diff of this commit:
cvs rdiff -u -r1.108 -r1.109 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.



CVS commit: src/sys/net

2019-11-13 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Thu Nov 14 04:14:30 UTC 2019

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

Log Message:
 Fix comment.


To generate a diff of this commit:
cvs rdiff -u -r1.108 -r1.109 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.108 src/sys/net/if_loop.c:1.109
--- src/sys/net/if_loop.c:1.108	Mon Nov 11 08:12:35 2019
+++ src/sys/net/if_loop.c	Thu Nov 14 04:14:30 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_loop.c,v 1.108 2019/11/11 08:12:35 msaitoh Exp $	*/
+/*	$NetBSD: if_loop.c,v 1.109 2019/11/14 04:14:30 msaitoh Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -65,7 +65,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_loop.c,v 1.108 2019/11/11 08:12:35 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_loop.c,v 1.109 2019/11/14 04:14:30 msaitoh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -341,7 +341,7 @@ looutput(struct ifnet *ifp, struct mbuf 
 			m->m_pkthdr.csum_flags = 0;
 		} else {
 			/*
-			 * Do nothing. Pass M_CSUM_IPv4 and M_CSUM_UDPv4 as
+			 * Do nothing. Pass M_CSUM_UDPv6 as
 			 * they are to tell those are calculated and good.
 			 */
 		}



CVS commit: src/sys/net

2019-11-11 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Mon Nov 11 08:12:35 UTC 2019

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

Log Message:
 Fix IP broadcast + checksum offload problem.

 When a machine sends a IP broadcast packet to an Ethernet interface that the
checksum offload flags are set, the packet goes through ether_output() ->
looutput() and the offload flags is cleard without calculating the checksum.
And then, ip_input() calculate the packet's checksum because it's csum_flags is
zero. It regard as bad checksum and it's dropped because the packet's ifp
is s not lo0's. Fixes this bug by passing csum_flags as "calculated and good"
when IN_LOOPBACK_NEED_CHECKSUM() is false. Adviced by ryo@.

 This problem was seen when "routed -s" was used and the machine's interface's
offload flags were set. bad checksum field of "netstat -s" was increased every
30 minutes.


To generate a diff of this commit:
cvs rdiff -u -r1.107 -r1.108 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.107 src/sys/net/if_loop.c:1.108
--- src/sys/net/if_loop.c:1.107	Fri Apr 26 08:38:25 2019
+++ src/sys/net/if_loop.c	Mon Nov 11 08:12:35 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_loop.c,v 1.107 2019/04/26 08:38:25 pgoyette Exp $	*/
+/*	$NetBSD: if_loop.c,v 1.108 2019/11/11 08:12:35 msaitoh Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -65,7 +65,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_loop.c,v 1.107 2019/04/26 08:38:25 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_loop.c,v 1.108 2019/11/11 08:12:35 msaitoh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -321,8 +321,13 @@ looutput(struct ifnet *ifp, struct mbuf 
 		KASSERT((csum_flags & ~(M_CSUM_IPv4|M_CSUM_UDPv4)) == 0);
 		if (csum_flags != 0 && IN_LOOPBACK_NEED_CHECKSUM(csum_flags)) {
 			in_undefer_cksum(m, 0, csum_flags);
+			m->m_pkthdr.csum_flags = 0;
+		} else {
+			/*
+			 * Do nothing. Pass M_CSUM_IPv4 and M_CSUM_UDPv4 as
+			 * they are to tell those are calculated and good.
+			 */
 		}
-		m->m_pkthdr.csum_flags = 0;
 		pktq = ip_pktq;
 		break;
 #endif
@@ -333,8 +338,13 @@ looutput(struct ifnet *ifp, struct mbuf 
 		if (csum_flags != 0 &&
 		IN6_LOOPBACK_NEED_CHECKSUM(csum_flags)) {
 			in6_undefer_cksum(m, 0, csum_flags);
+			m->m_pkthdr.csum_flags = 0;
+		} else {
+			/*
+			 * Do nothing. Pass M_CSUM_IPv4 and M_CSUM_UDPv4 as
+			 * they are to tell those are calculated and good.
+			 */
 		}
-		m->m_pkthdr.csum_flags = 0;
 		m->m_flags |= M_LOOP;
 		pktq = ip6_pktq;
 		break;



CVS commit: src/sys/net

2019-11-11 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Mon Nov 11 08:12:35 UTC 2019

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

Log Message:
 Fix IP broadcast + checksum offload problem.

 When a machine sends a IP broadcast packet to an Ethernet interface that the
checksum offload flags are set, the packet goes through ether_output() ->
looutput() and the offload flags is cleard without calculating the checksum.
And then, ip_input() calculate the packet's checksum because it's csum_flags is
zero. It regard as bad checksum and it's dropped because the packet's ifp
is s not lo0's. Fixes this bug by passing csum_flags as "calculated and good"
when IN_LOOPBACK_NEED_CHECKSUM() is false. Adviced by ryo@.

 This problem was seen when "routed -s" was used and the machine's interface's
offload flags were set. bad checksum field of "netstat -s" was increased every
30 minutes.


To generate a diff of this commit:
cvs rdiff -u -r1.107 -r1.108 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.



CVS commit: src/sys/net

2019-11-10 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Mon Nov 11 02:34:46 UTC 2019

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

Log Message:
Fix a bug that vlan(4) fragments IPv6 packets
even the MTU > packet length.

The bug is appeared when the mtu is increased on SIOCSETVLAN.

>From t-kusaba@IIJ


To generate a diff of this commit:
cvs rdiff -u -r1.147 -r1.148 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.147 src/sys/net/if_vlan.c:1.148
--- src/sys/net/if_vlan.c:1.147	Mon Oct 21 06:26:12 2019
+++ src/sys/net/if_vlan.c	Mon Nov 11 02:34:46 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vlan.c,v 1.147 2019/10/21 06:26:12 ozaki-r Exp $	*/
+/*	$NetBSD: if_vlan.c,v 1.148 2019/11/11 02:34:46 yamaguchi Exp $	*/
 
 /*
  * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
@@ -78,7 +78,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.147 2019/10/21 06:26:12 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.148 2019/11/11 02:34:46 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -119,6 +119,7 @@ __KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 
 #ifdef INET6
 #include 
 #include 
+#include 
 #endif
 
 #include "ioconf.h"
@@ -540,6 +541,12 @@ vlan_config(struct ifvlan *ifv, struct i
 	nmib->ifvm_p = p;
 	nmib->ifvm_tag = vid;
 	ifv->ifv_if.if_mtu = p->if_mtu - nmib->ifvm_mtufudge;
+#ifdef INET6
+	KERNEL_LOCK_UNLESS_NET_MPSAFE();
+	if (in6_present)
+		nd6_setmtu(ifp);
+	KERNEL_UNLOCK_UNLESS_NET_MPSAFE();
+#endif
 	ifv->ifv_if.if_flags = p->if_flags &
 	(IFF_UP | IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST);
 



CVS commit: src/sys/net

2019-11-10 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Mon Nov 11 02:34:46 UTC 2019

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

Log Message:
Fix a bug that vlan(4) fragments IPv6 packets
even the MTU > packet length.

The bug is appeared when the mtu is increased on SIOCSETVLAN.

>From t-kusaba@IIJ


To generate a diff of this commit:
cvs rdiff -u -r1.147 -r1.148 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.



CVS commit: src/sys/net

2019-10-21 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Mon Oct 21 06:26:12 UTC 2019

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

Log Message:
vlan: get rid of unnecessary if_ipackets++ in vlan_input

It's done by if_input() below now.

Pointed out by msaitoh@


To generate a diff of this commit:
cvs rdiff -u -r1.146 -r1.147 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.146 src/sys/net/if_vlan.c:1.147
--- src/sys/net/if_vlan.c:1.146	Fri Aug 23 02:33:15 2019
+++ src/sys/net/if_vlan.c	Mon Oct 21 06:26:12 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vlan.c,v 1.146 2019/08/23 02:33:15 msaitoh Exp $	*/
+/*	$NetBSD: if_vlan.c,v 1.147 2019/10/21 06:26:12 ozaki-r Exp $	*/
 
 /*
  * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
@@ -78,7 +78,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.146 2019/08/23 02:33:15 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.147 2019/10/21 06:26:12 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1656,7 +1656,6 @@ vlan_input(struct ifnet *ifp, struct mbu
 	}
 
 	m_set_rcvif(m, >ifv_if);
-	ifv->ifv_if.if_ipackets++;
 
 	if (pfil_run_hooks(ifp->if_pfil, , ifp, PFIL_IN) != 0)
 		goto out;



CVS commit: src/sys/net

2019-10-21 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Mon Oct 21 06:26:12 UTC 2019

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

Log Message:
vlan: get rid of unnecessary if_ipackets++ in vlan_input

It's done by if_input() below now.

Pointed out by msaitoh@


To generate a diff of this commit:
cvs rdiff -u -r1.146 -r1.147 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.



CVS commit: src/sys/net

2019-10-16 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Oct 16 06:53:34 UTC 2019

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

Log Message:
Fix missing kpreempt_disable() before softint_schedule() like if_vmx.c:r1.51.


To generate a diff of this commit:
cvs rdiff -u -r1.175 -r1.176 src/sys/net/if_gre.c
cvs rdiff -u -r1.39 -r1.40 src/sys/net/if_l2tp.c
cvs rdiff -u -r1.113 -r1.114 src/sys/net/if_tap.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_gre.c
diff -u src/sys/net/if_gre.c:1.175 src/sys/net/if_gre.c:1.176
--- src/sys/net/if_gre.c:1.175	Fri Apr 26 11:51:56 2019
+++ src/sys/net/if_gre.c	Wed Oct 16 06:53:34 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_gre.c,v 1.175 2019/04/26 11:51:56 pgoyette Exp $ */
+/*	$NetBSD: if_gre.c,v 1.176 2019/10/16 06:53:34 knakahara Exp $ */
 
 /*
  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -45,7 +45,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_gre.c,v 1.175 2019/04/26 11:51:56 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_gre.c,v 1.176 2019/10/16 06:53:34 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_atalk.h"
@@ -964,8 +964,11 @@ gre_output(struct ifnet *ifp, struct mbu
 	if ((error = gre_bufq_enqueue(>sc_snd, m)) != 0) {
 		sc->sc_oflow_ev.ev_count++;
 		m_freem(m);
-	} else
+	} else {
+		kpreempt_disable();
 		softint_schedule(sc->sc_si);
+		kpreempt_enable();
+	}
 
 end:
 	if (error)

Index: src/sys/net/if_l2tp.c
diff -u src/sys/net/if_l2tp.c:1.39 src/sys/net/if_l2tp.c:1.40
--- src/sys/net/if_l2tp.c:1.39	Thu Sep 19 06:09:52 2019
+++ src/sys/net/if_l2tp.c	Wed Oct 16 06:53:34 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_l2tp.c,v 1.39 2019/09/19 06:09:52 knakahara Exp $	*/
+/*	$NetBSD: if_l2tp.c,v 1.40 2019/10/16 06:53:34 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_l2tp.c,v 1.39 2019/09/19 06:09:52 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_l2tp.c,v 1.40 2019/10/16 06:53:34 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -673,7 +673,9 @@ l2tp_start(struct ifnet *ifp)
 	if (var->lv_psrc == NULL || var->lv_pdst == NULL)
 		return;
 
+	kpreempt_disable();
 	softint_schedule(sc->l2tp_si);
+	kpreempt_enable();
 	l2tp_putref_variant(var, );
 }
 

Index: src/sys/net/if_tap.c
diff -u src/sys/net/if_tap.c:1.113 src/sys/net/if_tap.c:1.114
--- src/sys/net/if_tap.c:1.113	Wed May 29 10:07:30 2019
+++ src/sys/net/if_tap.c	Wed Oct 16 06:53:34 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_tap.c,v 1.113 2019/05/29 10:07:30 msaitoh Exp $	*/
+/*	$NetBSD: if_tap.c,v 1.114 2019/10/16 06:53:34 knakahara Exp $	*/
 
 /*
  *  Copyright (c) 2003, 2004, 2008, 2009 The NetBSD Foundation.
@@ -33,7 +33,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_tap.c,v 1.113 2019/05/29 10:07:30 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_tap.c,v 1.114 2019/10/16 06:53:34 knakahara Exp $");
 
 #if defined(_KERNEL_OPT)
 
@@ -533,8 +533,11 @@ tap_start(struct ifnet *ifp)
 		ifp->if_flags |= IFF_OACTIVE;
 		cv_broadcast(>sc_cv);
 		selnotify(>sc_rsel, 0, 1);
-		if (sc->sc_flags & TAP_ASYNCIO)
+		if (sc->sc_flags & TAP_ASYNCIO) {
+			kpreempt_disable();
 			softint_schedule(sc->sc_sih);
+			kpreempt_enable();
+		}
 	}
 done:
 	mutex_exit(>sc_lock);
@@ -643,8 +646,11 @@ tap_stop(struct ifnet *ifp, int disable)
 	ifp->if_flags &= ~IFF_RUNNING;
 	cv_broadcast(>sc_cv);
 	selnotify(>sc_rsel, 0, 1);
-	if (sc->sc_flags & TAP_ASYNCIO)
+	if (sc->sc_flags & TAP_ASYNCIO) {
+		kpreempt_disable();
 		softint_schedule(sc->sc_sih);
+		kpreempt_enable();
+	}
 	mutex_exit(>sc_lock);
 }
 



CVS commit: src/sys/net

2019-10-14 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Mon Oct 14 16:43:04 UTC 2019

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

Log Message:
Error out if the type is beyond the storage size. No functional change,
since the shift would otherwise 'and' against zero, returning EEXIST.

Reported-by: syzbot+cb68ccdc1ef3aca2d...@syzkaller.appspotmail.com


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/net/rtsock_shared.c

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



CVS commit: src/sys/net

2019-10-14 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Mon Oct 14 16:43:04 UTC 2019

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

Log Message:
Error out if the type is beyond the storage size. No functional change,
since the shift would otherwise 'and' against zero, returning EEXIST.

Reported-by: syzbot+cb68ccdc1ef3aca2d...@syzkaller.appspotmail.com


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/net/rtsock_shared.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/rtsock_shared.c
diff -u src/sys/net/rtsock_shared.c:1.10 src/sys/net/rtsock_shared.c:1.11
--- src/sys/net/rtsock_shared.c:1.10	Mon Aug 19 03:23:30 2019
+++ src/sys/net/rtsock_shared.c	Mon Oct 14 16:43:04 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtsock_shared.c,v 1.10 2019/08/19 03:23:30 ozaki-r Exp $	*/
+/*	$NetBSD: rtsock_shared.c,v 1.11 2019/10/14 16:43:04 maxv Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: rtsock_shared.c,v 1.10 2019/08/19 03:23:30 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rtsock_shared.c,v 1.11 2019/10/14 16:43:04 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -227,6 +227,8 @@ COMPATNAME(route_filter)(struct mbuf *m,
 		return EINVAL;
 
 	rtm = mtod(m, struct rt_xmsghdr *);
+	if (rtm->rtm_type >= sizeof(rop->rocb_msgfilter) * CHAR_BIT)
+		return EINVAL;
 	/* If the rtm type is filtered out, return a positive. */
 	if (!(rop->rocb_msgfilter & RTMSGFILTER(rtm->rtm_type)))
 		return EEXIST;



CVS commit: src/sys/net

2019-10-03 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Thu Oct  3 14:41:14 UTC 2019

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

Log Message:
Add IFM_IEEE80211_VHT subtype, IFM_IEEE80211_11AC operating mode, and missing 
descriptions


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 src/sys/net/if_media.h

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



CVS commit: src/sys/net

2019-10-03 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Thu Oct  3 14:41:14 UTC 2019

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

Log Message:
Add IFM_IEEE80211_VHT subtype, IFM_IEEE80211_11AC operating mode, and missing 
descriptions


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 src/sys/net/if_media.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_media.h
diff -u src/sys/net/if_media.h:1.65 src/sys/net/if_media.h:1.66
--- src/sys/net/if_media.h:1.65	Fri May 17 07:37:12 2019
+++ src/sys/net/if_media.h	Thu Oct  3 14:41:14 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_media.h,v 1.65 2019/05/17 07:37:12 msaitoh Exp $	*/
+/*	$NetBSD: if_media.h,v 1.66 2019/10/03 14:41:14 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000, 2001 The NetBSD Foundation, Inc.
@@ -373,6 +373,7 @@
 #define	IFM_IEEE80211_OFDM27	23	/* OFDM 27Mbps */
 /* NB: not enough bits to express MCS fully */
 #define	IFM_IEEE80211_MCS	24	/* HT MCS rate */
+#define	IFM_IEEE80211_VHT	25	/* VHT MCS rate */
 
 /* IFM_OMASK bits */
 #define	IFM_IEEE80211_ADHOC	0x0100	/* Operate in Adhoc mode */
@@ -390,6 +391,7 @@
 #define	IFM_IEEE80211_FH	0x0004	/* 2 GHz, GFSK mode */
 #define	IFM_IEEE80211_11NA	0x0005	/* 5Ghz, HT mode */
 #define	IFM_IEEE80211_11NG	0x0006	/* 2Ghz, HT mode */
+#define	IFM_IEEE80211_11AC	0x0007	/* 2Ghz/5Ghz, VHT mode */
 
 
 /*
@@ -628,6 +630,8 @@ struct ifmedia_description {
 	{ IFM_IEEE80211 | IFM_IEEE80211_OFDM3,	"OFDM/3Mbps" },		\
 	{ IFM_IEEE80211 | IFM_IEEE80211_OFDM4,	"OFDM/4.5Mbps" },	\
 	{ IFM_IEEE80211 | IFM_IEEE80211_OFDM27, "OFDM/27Mbps" },	\
+	{ IFM_IEEE80211 | IFM_IEEE80211_MCS, "HT" },			\
+	{ IFM_IEEE80211 | IFM_IEEE80211_VHT, "VHT" },			\
 	\
 	{ 0, NULL },			\
 }
@@ -641,6 +645,7 @@ struct ifmedia_description {
 	{ IFM_IEEE80211 | IFM_IEEE80211_FH,	"fh" },			\
 	{ IFM_IEEE80211 | IFM_IEEE80211_11NA,	"11na" },		\
 	{ IFM_IEEE80211 | IFM_IEEE80211_11NG,	"11ng" },		\
+	{ IFM_IEEE80211 | IFM_IEEE80211_11AC,	"11ac" },		\
 	{ 0, NULL },			\
 }
 



CVS commit: src/sys/net

2019-10-02 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Oct  3 03:10:02 UTC 2019

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

Log Message:
Revert route.c:r1.224 to fix net/arp/t_arp and net/ndp/t_ndp failure.

And refactor a little. Discussed with ozaki-r@n.o.


To generate a diff of this commit:
cvs rdiff -u -r1.224 -r1.225 src/sys/net/route.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/route.c
diff -u src/sys/net/route.c:1.224 src/sys/net/route.c:1.225
--- src/sys/net/route.c:1.224	Mon Sep 30 10:22:14 2019
+++ src/sys/net/route.c	Thu Oct  3 03:10:02 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: route.c,v 1.224 2019/09/30 10:22:14 knakahara Exp $	*/
+/*	$NetBSD: route.c,v 1.225 2019/10/03 03:10:02 knakahara Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -97,7 +97,7 @@
 #endif
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.224 2019/09/30 10:22:14 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.225 2019/10/03 03:10:02 knakahara Exp $");
 
 #include 
 #ifdef RTFLUSH_DEBUG
@@ -1400,11 +1400,8 @@ rt_update_get_ifa(const struct rt_addrin
 		*ifp = ifa->ifa_ifp;
 		if_acquire(*ifp, psref_ifp);
 		if (info->rti_info[RTAX_IFA] == NULL &&
-		info->rti_info[RTAX_GATEWAY] == NULL) {
-			ifa_release(ifa, psref);
-			ifa = NULL;
-			goto next;
-		}
+		info->rti_info[RTAX_GATEWAY] == NULL)
+			goto out;
 		ifa_release(ifa, psref);
 		if (info->rti_info[RTAX_IFA] == NULL) {
 			/* route change   -ifp  */



CVS commit: src/sys/net

2019-10-02 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Oct  3 03:10:02 UTC 2019

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

Log Message:
Revert route.c:r1.224 to fix net/arp/t_arp and net/ndp/t_ndp failure.

And refactor a little. Discussed with ozaki-r@n.o.


To generate a diff of this commit:
cvs rdiff -u -r1.224 -r1.225 src/sys/net/route.c

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



CVS commit: src/sys/net

2019-10-01 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Wed Oct  2 04:17:16 UTC 2019

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

Log Message:
 Print oversized frame's message only when DIAGNOSTIC is set. The message
is not so important because we increment if_iqdrops now.


To generate a diff of this commit:
cvs rdiff -u -r1.277 -r1.278 src/sys/net/if_ethersubr.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_ethersubr.c
diff -u src/sys/net/if_ethersubr.c:1.277 src/sys/net/if_ethersubr.c:1.278
--- src/sys/net/if_ethersubr.c:1.277	Tue Oct  1 08:13:16 2019
+++ src/sys/net/if_ethersubr.c	Wed Oct  2 04:17:16 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ethersubr.c,v 1.277 2019/10/01 08:13:16 msaitoh Exp $	*/
+/*	$NetBSD: if_ethersubr.c,v 1.278 2019/10/02 04:17:16 msaitoh Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.277 2019/10/01 08:13:16 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.278 2019/10/02 04:17:16 msaitoh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -164,10 +164,12 @@ extern u_char	aarp_org_code[3];
 #include 
 #endif
 
+#ifdef DIAGNOSTIC
 static struct timeval bigpktppslim_last;
 static int bigpktppslim = 2;	/* XXX */
 static int bigpktpps_count;
 static kmutex_t bigpktpps_lock __cacheline_aligned;
+#endif
 
 const uint8_t etherbroadcastaddr[ETHER_ADDR_LEN] =
 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
@@ -612,6 +614,7 @@ ether_input(struct ifnet *ifp, struct mb
 	 */
 	if (etype != ETHERTYPE_MPLS && m->m_pkthdr.len >
 	ETHER_MAX_FRAME(ifp, etype, m->m_flags & M_HASFCS)) {
+#ifdef DIAGNOSTIC
 		mutex_enter(_lock);
 		if (ppsratecheck(_last, _count,
 		bigpktppslim)) {
@@ -619,6 +622,7 @@ ether_input(struct ifnet *ifp, struct mb
 			ifp->if_xname, m->m_pkthdr.len);
 		}
 		mutex_exit(_lock);
+#endif
 		ifp->if_iqdrops++;
 		m_freem(m);
 		return;
@@ -1718,6 +1722,8 @@ void
 etherinit(void)
 {
 
+#ifdef DIAGNOSTIC
 	mutex_init(_lock, MUTEX_DEFAULT, IPL_NET);
+#endif
 	ether_sysctl_setup(NULL);
 }



CVS commit: src/sys/net

2019-10-01 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Wed Oct  2 04:17:16 UTC 2019

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

Log Message:
 Print oversized frame's message only when DIAGNOSTIC is set. The message
is not so important because we increment if_iqdrops now.


To generate a diff of this commit:
cvs rdiff -u -r1.277 -r1.278 src/sys/net/if_ethersubr.c

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



CVS commit: src/sys/net

2019-10-01 Thread Chuck Silvers
Module Name:src
Committed By:   chs
Date:   Tue Oct  1 17:45:25 UTC 2019

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

Log Message:
in ifmedia_add(), use a wait-style memory allocation rather than
not waiting and panic'ing if the allocation fails.

Reported-by: syzbot+249ca42197f0b066e...@syzkaller.appspotmail.com


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/sys/net/if_media.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_media.c
diff -u src/sys/net/if_media.c:1.47 src/sys/net/if_media.c:1.48
--- src/sys/net/if_media.c:1.47	Sat Aug 10 01:04:05 2019
+++ src/sys/net/if_media.c	Tue Oct  1 17:45:25 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_media.c,v 1.47 2019/08/10 01:04:05 mrg Exp $	*/
+/*	$NetBSD: if_media.c,v 1.48 2019/10/01 17:45:25 chs Exp $	*/
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -76,7 +76,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_media.c,v 1.47 2019/08/10 01:04:05 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_media.c,v 1.48 2019/10/01 17:45:25 chs Exp $");
 
 #include 
 #include 
@@ -162,14 +162,10 @@ ifmedia_add(struct ifmedia *ifm, int mwo
 	}
 #endif
 
-	entry = malloc(sizeof(*entry), M_IFMEDIA, M_NOWAIT);
-	if (entry == NULL)
-		panic("ifmedia_add: can't malloc entry");
-
+	entry = malloc(sizeof(*entry), M_IFMEDIA, M_WAITOK);
 	entry->ifm_media = mword;
 	entry->ifm_data = data;
 	entry->ifm_aux = aux;
-
 	TAILQ_INSERT_TAIL(>ifm_list, entry, ifm_list);
 }
 
@@ -335,8 +331,6 @@ ifmedia_ioctl_locked(struct ifnet *ifp, 
 			int *kptr = malloc(minwords * sizeof(int), M_TEMP,
 			M_WAITOK);
 
-			if (kptr == NULL)
-return ENOMEM;
 			/* Get the media words from the interface's list. */
 			ep = TAILQ_FIRST(>ifm_list);
 			for (count = 0; ep != NULL && count < minwords;



CVS commit: src/sys/net

2019-10-01 Thread Chuck Silvers
Module Name:src
Committed By:   chs
Date:   Tue Oct  1 17:45:25 UTC 2019

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

Log Message:
in ifmedia_add(), use a wait-style memory allocation rather than
not waiting and panic'ing if the allocation fails.

Reported-by: syzbot+249ca42197f0b066e...@syzkaller.appspotmail.com


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/sys/net/if_media.c

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



CVS commit: src/sys/net

2019-10-01 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Oct  1 16:02:55 UTC 2019

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

Log Message:
sync with libcap-1.9.1


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/net/dlt.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/dlt.h
diff -u src/sys/net/dlt.h:1.19 src/sys/net/dlt.h:1.20
--- src/sys/net/dlt.h:1.19	Mon Sep  3 10:58:04 2018
+++ src/sys/net/dlt.h	Tue Oct  1 12:02:55 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: dlt.h,v 1.19 2018/09/03 14:58:04 christos Exp $	*/
+/*	$NetBSD: dlt.h,v 1.20 2019/10/01 16:02:55 christos Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
@@ -252,7 +252,7 @@
  */
 
 /*
- * This is for Linux cooked sockets.
+ * Linux cooked sockets.
  */
 #define DLT_LINUX_SLL	113
 
@@ -775,11 +775,20 @@
 #define DLT_RAIF1		198
 
 /*
- * IPMB packet for IPMI, beginning with the I2C slave address, followed
- * by the netFn and LUN, etc..  Requested by Chanthy Toeung
- * .
+ * IPMB packet for IPMI, beginning with a 2-byte header, followed by
+ * the I2C slave address, followed by the netFn and LUN, etc..
+ * Requested by Chanthy Toeung .
+ *
+ * XXX - this used to be called DLT_IPMB, back when we got the
+ * impression from the email thread requesting it that the packet
+ * had no extra 2-byte header.  We've renamed it; if anybody used
+ * DLT_IPMB and assumed no 2-byte header, this will cause the compile
+ * to fail, at which point we'll have to figure out what to do about
+ * the two header types using the same DLT_/LINKTYPE_ value.  If that
+ * doesn't happen, we'll assume nobody used it and that the redefinition
+ * is safe.
  */
-#define DLT_IPMB		199
+#define DLT_IPMB_KONTRON	199
 
 /*
  * Juniper-private data link type, as per request from
@@ -811,15 +820,34 @@
 #define DLT_LAPD		203
 
 /*
- * Variants of various link-layer headers, with a one-byte direction
- * pseudo-header prepended - zero means "received by this host",
- * non-zero (any non-zero value) means "sent by this host" - as per
- * Will Barker .
- */
-#define DLT_PPP_WITH_DIR	204	/* PPP - don't confuse with DLT_PPP_WITH_DIRECTION */
-#define DLT_C_HDLC_WITH_DIR	205	/* Cisco HDLC */
-#define DLT_FRELAY_WITH_DIR	206	/* Frame Relay */
-#define DLT_LAPB_WITH_DIR	207	/* LAPB */
+ * PPP, with a one-byte direction pseudo-header prepended - zero means
+ * "received by this host", non-zero (any non-zero value) means "sent by
+ * this host" - as per Will Barker .
+ */
+#define DLT_PPP_WITH_DIR	204	/* Don't confuse with DLT_PPP_WITH_DIRECTION */
+
+/*
+ * Cisco HDLC, with a one-byte direction pseudo-header prepended - zero
+ * means "received by this host", non-zero (any non-zero value) means
+ * "sent by this host" - as per Will Barker .
+ */
+#define DLT_C_HDLC_WITH_DIR	205
+
+/*
+ * Frame Relay, with a one-byte direction pseudo-header prepended - zero
+ * means "received by this host" (DCE -> DTE), non-zero (any non-zero
+ * value) means "sent by this host" (DTE -> DCE) - as per Will Barker
+ * .
+ */
+#define DLT_FRELAY_WITH_DIR	206
+
+/*
+ * LAPB, with a one-byte direction pseudo-header prepended - zero means
+ * "received by this host" (DCE -> DTE), non-zero (any non-zero value)
+ * means "sent by this host" (DTE -> DCE)- as per Will Barker
+ * .
+ */
+#define DLT_LAPB_WITH_DIR	207
 
 /*
  * 208 is reserved for an as-yet-unspecified proprietary link-layer
@@ -1374,6 +1402,11 @@
 #define DLT_DISPLAYPORT_AUX	275
 
 /*
+ * Linux cooked sockets v2.
+ */
+#define DLT_LINUX_SLL2	276
+
+/*
  * In case the code that includes this file (directly or indirectly)
  * has also included OS files that happen to define DLT_MATCHING_MAX,
  * with a different value (perhaps because that OS hasn't picked up
@@ -1383,7 +1416,7 @@
 #ifdef DLT_MATCHING_MAX
 #undef DLT_MATCHING_MAX
 #endif
-#define DLT_MATCHING_MAX	275	/* highest value in the "matching" range */
+#define DLT_MATCHING_MAX	276	/* highest value in the "matching" range */
 
 /*
  * DLT and savefile link type values are split into a class and



CVS commit: src/sys/net

2019-10-01 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Oct  1 16:02:55 UTC 2019

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

Log Message:
sync with libcap-1.9.1


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/net/dlt.h

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



CVS commit: src/sys/net

2019-10-01 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Tue Oct  1 08:13:16 UTC 2019

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

Log Message:
 Increment if_iqdrops when dropping an oversized frame.


To generate a diff of this commit:
cvs rdiff -u -r1.276 -r1.277 src/sys/net/if_ethersubr.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_ethersubr.c
diff -u src/sys/net/if_ethersubr.c:1.276 src/sys/net/if_ethersubr.c:1.277
--- src/sys/net/if_ethersubr.c:1.276	Wed Jul 17 03:26:24 2019
+++ src/sys/net/if_ethersubr.c	Tue Oct  1 08:13:16 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ethersubr.c,v 1.276 2019/07/17 03:26:24 msaitoh Exp $	*/
+/*	$NetBSD: if_ethersubr.c,v 1.277 2019/10/01 08:13:16 msaitoh Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.276 2019/07/17 03:26:24 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.277 2019/10/01 08:13:16 msaitoh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -619,6 +619,7 @@ ether_input(struct ifnet *ifp, struct mb
 			ifp->if_xname, m->m_pkthdr.len);
 		}
 		mutex_exit(_lock);
+		ifp->if_iqdrops++;
 		m_freem(m);
 		return;
 	}



CVS commit: src/sys/net

2019-10-01 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Tue Oct  1 08:13:16 UTC 2019

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

Log Message:
 Increment if_iqdrops when dropping an oversized frame.


To generate a diff of this commit:
cvs rdiff -u -r1.276 -r1.277 src/sys/net/if_ethersubr.c

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



CVS commit: src/sys/net/npf

2019-09-30 Thread Mindaugas Rasiukevicius
Module Name:src
Committed By:   rmind
Date:   Mon Sep 30 22:04:33 UTC 2019

Modified Files:
src/sys/net/npf: npf_if.c

Log Message:
npf_ifmap_copylogname: be more defensive.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/net/npf/npf_if.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/npf/npf_if.c
diff -u src/sys/net/npf/npf_if.c:1.11 src/sys/net/npf/npf_if.c:1.12
--- src/sys/net/npf/npf_if.c:1.11	Sun Sep 29 17:00:29 2019
+++ src/sys/net/npf/npf_if.c	Mon Sep 30 22:04:33 2019
@@ -56,7 +56,7 @@
 
 #ifdef _KERNEL
 #include 
-__KERNEL_RCSID(0, "$NetBSD: npf_if.c,v 1.11 2019/09/29 17:00:29 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf_if.c,v 1.12 2019/09/30 22:04:33 rmind Exp $");
 
 #include 
 #include 
@@ -191,20 +191,22 @@ npf_ifmap_getid(npf_t *npf, const ifnet_
 }
 
 /*
- * This function is toxic; it can return garbage since we don't
- * lock, but it is only used temporarily and only for logging.
+ * npf_ifmap_copylogname: this function is toxic; it can return garbage
+ * as we don't lock, but it is only used temporarily and only for logging.
  */
 void
 npf_ifmap_copylogname(npf_t *npf, unsigned id, char *buf, size_t len)
 {
-	if (id != NPF_IFMAP_NOID) {
-		const unsigned i = NPF_IFMAP_ID2SLOT(npf, id);
-		npf_ifmap_t *ifmap = >ifmap[i];
+	const unsigned i = NPF_IFMAP_ID2SLOT(npf, id);
+
+	membar_consumer();
 
+	if (id != NPF_IFMAP_NOID && i < NPF_MAX_IFMAP) {
 		/*
 		 * Lock-free access is safe as there is an extra byte
 		 * with a permanent NUL terminator at the end.
 		 */
+		const npf_ifmap_t *ifmap = >ifmap[i];
 		strlcpy(buf, ifmap->ifname, MIN(len, IFNAMSIZ));
 	} else {
 		strlcpy(buf, "???", len);



CVS commit: src/sys/net/npf

2019-09-30 Thread Mindaugas Rasiukevicius
Module Name:src
Committed By:   rmind
Date:   Mon Sep 30 22:04:33 UTC 2019

Modified Files:
src/sys/net/npf: npf_if.c

Log Message:
npf_ifmap_copylogname: be more defensive.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/net/npf/npf_if.c

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



CVS commit: src/sys/net

2019-09-30 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Sep 30 10:22:14 UTC 2019

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

Log Message:
Fix a ifa_release() leak for a specific struct rt_addrinfo.

ok by ozaki-r@n.o


To generate a diff of this commit:
cvs rdiff -u -r1.223 -r1.224 src/sys/net/route.c

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



CVS commit: src/sys/net

2019-09-30 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Sep 30 10:22:14 UTC 2019

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

Log Message:
Fix a ifa_release() leak for a specific struct rt_addrinfo.

ok by ozaki-r@n.o


To generate a diff of this commit:
cvs rdiff -u -r1.223 -r1.224 src/sys/net/route.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/route.c
diff -u src/sys/net/route.c:1.223 src/sys/net/route.c:1.224
--- src/sys/net/route.c:1.223	Wed Sep 25 09:53:37 2019
+++ src/sys/net/route.c	Mon Sep 30 10:22:14 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: route.c,v 1.223 2019/09/25 09:53:37 ozaki-r Exp $	*/
+/*	$NetBSD: route.c,v 1.224 2019/09/30 10:22:14 knakahara Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -97,7 +97,7 @@
 #endif
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.223 2019/09/25 09:53:37 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.224 2019/09/30 10:22:14 knakahara Exp $");
 
 #include 
 #ifdef RTFLUSH_DEBUG
@@ -1400,8 +1400,11 @@ rt_update_get_ifa(const struct rt_addrin
 		*ifp = ifa->ifa_ifp;
 		if_acquire(*ifp, psref_ifp);
 		if (info->rti_info[RTAX_IFA] == NULL &&
-		info->rti_info[RTAX_GATEWAY] == NULL)
+		info->rti_info[RTAX_GATEWAY] == NULL) {
+			ifa_release(ifa, psref);
+			ifa = NULL;
 			goto next;
+		}
 		ifa_release(ifa, psref);
 		if (info->rti_info[RTAX_IFA] == NULL) {
 			/* route change   -ifp  */



CVS commit: src/sys/net/npf

2019-09-29 Thread Mindaugas Rasiukevicius
Module Name:src
Committed By:   rmind
Date:   Sun Sep 29 17:00:29 UTC 2019

Modified Files:
src/sys/net/npf: npf_conn.c npf_if.c npf_impl.h npf_ruleset.c

Log Message:
NPF ifmap: rework and fix a few small bugs.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sys/net/npf/npf_conn.c
cvs rdiff -u -r1.10 -r1.11 src/sys/net/npf/npf_if.c
cvs rdiff -u -r1.79 -r1.80 src/sys/net/npf/npf_impl.h
cvs rdiff -u -r1.48 -r1.49 src/sys/net/npf/npf_ruleset.c

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



CVS commit: src/sys/net/npf

2019-09-29 Thread Mindaugas Rasiukevicius
Module Name:src
Committed By:   rmind
Date:   Sun Sep 29 17:00:29 UTC 2019

Modified Files:
src/sys/net/npf: npf_conn.c npf_if.c npf_impl.h npf_ruleset.c

Log Message:
NPF ifmap: rework and fix a few small bugs.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sys/net/npf/npf_conn.c
cvs rdiff -u -r1.10 -r1.11 src/sys/net/npf/npf_if.c
cvs rdiff -u -r1.79 -r1.80 src/sys/net/npf/npf_impl.h
cvs rdiff -u -r1.48 -r1.49 src/sys/net/npf/npf_ruleset.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/npf/npf_conn.c
diff -u src/sys/net/npf/npf_conn.c:1.29 src/sys/net/npf/npf_conn.c:1.30
--- src/sys/net/npf/npf_conn.c:1.29	Tue Aug  6 11:40:15 2019
+++ src/sys/net/npf/npf_conn.c	Sun Sep 29 17:00:29 2019
@@ -107,7 +107,7 @@
 
 #ifdef _KERNEL
 #include 
-__KERNEL_RCSID(0, "$NetBSD: npf_conn.c,v 1.29 2019/08/06 11:40:15 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf_conn.c,v 1.30 2019/09/29 17:00:29 rmind Exp $");
 
 #include 
 #include 
@@ -782,7 +782,8 @@ npf_conn_export(npf_t *npf, npf_conn_t *
 	nvlist_add_number(cdict, "flags", con->c_flags);
 	nvlist_add_number(cdict, "proto", con->c_proto);
 	if (con->c_ifid) {
-		const char *ifname = npf_ifmap_getname(npf, con->c_ifid);
+		char ifname[IFNAMSIZ];
+		npf_ifmap_copyname(npf, con->c_ifid, ifname, sizeof(ifname));
 		nvlist_add_string(cdict, "ifname", ifname);
 	}
 	nvlist_add_binary(cdict, "state", >c_state, sizeof(npf_state_t));

Index: src/sys/net/npf/npf_if.c
diff -u src/sys/net/npf/npf_if.c:1.10 src/sys/net/npf/npf_if.c:1.11
--- src/sys/net/npf/npf_if.c:1.10	Sun Aug 11 20:26:33 2019
+++ src/sys/net/npf/npf_if.c	Sun Sep 29 17:00:29 2019
@@ -1,4 +1,5 @@
 /*-
+ * Copyright (c) 2019 Mindaugas Rasiukevicius 
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
@@ -28,23 +29,34 @@
  */
 
 /*
- * NPF network interface handling module.
+ * NPF network interface handling.
  *
- * NPF uses its own interface IDs (npf-if-id).  When NPF configuration is
- * (re)loaded, each required interface name is registered and a matching
- * network interface gets an ID assigned.  If an interface is not present,
- * it gets an ID on attach.
+ * NPF uses its own interface IDs (npf-if-id).  These IDs start from 1.
+ * Zero is reserved to indicate "no interface" case or an interface of
+ * no interest (i.e. not registered).
  *
- * IDs start from 1.  Zero is reserved to indicate "no interface" case or
- * an interface of no interest (i.e. not registered).
+ * This module provides an interface to primarily handle the following:
  *
- * The IDs are mapped synchronously based on interface events which are
- * monitored using pfil(9) hooks.
+ * - Bind a symbolic interface name to NPF interface ID.
+ * - Associate NPF interface ID when the network interface is attached.
+ *
+ * When NPF configuration is (re)loaded, each referenced network interface
+ * name is registered with a unique ID.  If the network interface is already
+ * attached, then the ID is associated with it immediately; otherwise, IDs
+ * are associated/disassociated on interface events which are monitored
+ * using pfil(9) hooks.
+ *
+ * To avoid race conditions when an active NPF configuration is updated or
+ * interfaces are detached/attached, the interface names are never removed
+ * and therefore IDs are never re-assigned.  The only point when interface
+ * names and IDs are cleared is when the configuration is flushed.
+ *
+ * A linear counter is used for IDs.
  */
 
 #ifdef _KERNEL
 #include 
-__KERNEL_RCSID(0, "$NetBSD: npf_if.c,v 1.10 2019/08/11 20:26:33 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf_if.c,v 1.11 2019/09/29 17:00:29 rmind Exp $");
 
 #include 
 #include 
@@ -55,9 +67,13 @@ __KERNEL_RCSID(0, "$NetBSD: npf_if.c,v 1
 #include "npf_impl.h"
 
 typedef struct npf_ifmap {
-	char		n_ifname[IFNAMSIZ];
+	char		ifname[IFNAMSIZ + 1];
 } npf_ifmap_t;
 
+#define	NPF_IFMAP_NOID			(0U)
+#define	NPF_IFMAP_SLOT2ID(npf, slot)	((npf)->ifmap_off + (slot) + 1)
+#define	NPF_IFMAP_ID2SLOT(npf, id)	((id) - (npf)->ifmap_off - 1)
+
 void
 npf_ifmap_init(npf_t *npf, const npf_ifops_t *ifops)
 {
@@ -66,8 +82,10 @@ npf_ifmap_init(npf_t *npf, const npf_ifo
 	KASSERT(ifops != NULL);
 	ifops->flush((void *)(uintptr_t)0);
 
+	mutex_init(>ifmap_lock, MUTEX_DEFAULT, IPL_SOFTNET);
 	npf->ifmap = kmem_zalloc(nbytes, KM_SLEEP);
 	npf->ifmap_cnt = 0;
+	npf->ifmap_off = 0;
 	npf->ifops = ifops;
 }
 
@@ -75,82 +93,101 @@ void
 npf_ifmap_fini(npf_t *npf)
 {
 	const size_t nbytes = sizeof(npf_ifmap_t) * NPF_MAX_IFMAP;
+	mutex_destroy(>ifmap_lock);
 	kmem_free(npf->ifmap, nbytes);
 }
 
-static u_int
-npf_ifmap_new(npf_t *npf)
-{
-	KASSERT(npf_config_locked_p(npf));
-
-	for (u_int i = 0; i < npf->ifmap_cnt; i++)
-		if (npf->ifmap[i].n_ifname[0] == '\0')
-			return i + 1;
-
-	if (npf->ifmap_cnt == NPF_MAX_IFMAP) {
-		printf("npf_ifmap_new: out of slots; bump NPF_MAX_IFMAP\n");
-		

CVS commit: src/sys/net/npf

2019-09-26 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Sep 26 18:44:45 UTC 2019

Modified Files:
src/sys/net/npf: npf_mbuf.c

Log Message:
Cast m_mbuflen() result to "size_t". It could also be "u_int" since it is
assigned to "u_int", but all the other "standalone" equivalent functions return
"size_t".


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/net/npf/npf_mbuf.c

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



CVS commit: src/sys/net/npf

2019-09-26 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Sep 26 18:44:45 UTC 2019

Modified Files:
src/sys/net/npf: npf_mbuf.c

Log Message:
Cast m_mbuflen() result to "size_t". It could also be "u_int" since it is
assigned to "u_int", but all the other "standalone" equivalent functions return
"size_t".


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/net/npf/npf_mbuf.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/npf/npf_mbuf.c
diff -u src/sys/net/npf/npf_mbuf.c:1.22 src/sys/net/npf/npf_mbuf.c:1.23
--- src/sys/net/npf/npf_mbuf.c:1.22	Thu Nov 15 05:23:56 2018
+++ src/sys/net/npf/npf_mbuf.c	Thu Sep 26 14:44:45 2019
@@ -36,7 +36,7 @@
 
 #ifdef _KERNEL
 #include 
-__KERNEL_RCSID(0, "$NetBSD: npf_mbuf.c,v 1.22 2018/11/15 10:23:56 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf_mbuf.c,v 1.23 2019/09/26 18:44:45 christos Exp $");
 
 #include 
 #include 
@@ -62,7 +62,7 @@ __KERNEL_RCSID(0, "$NetBSD: npf_mbuf.c,v
 #define	m_flags_p(m,f)		true
 #else
 #define	m_next_ptr(m)		(m)->m_next
-#define	m_buflen(m)		(m)->m_len
+#define	m_buflen(m)		((size_t)(m)->m_len)
 #define	m_flags_p(m,f)		(((m)->m_flags & (f)) != 0)
 #endif
 



Re: CVS commit: src/sys/net

2019-09-23 Thread Ryota Ozaki
On Mon, Sep 23, 2019 at 4:14 PM Kamil Rytarowski  wrote:
>
> On 23.09.2019 06:53, Rin Okuyama wrote:
> > Hi,
> >
> > On 2019/09/22 18:30, Kamil Rytarowski wrote:
> >> On 12.04.2018 06:38, Ryota Ozaki wrote:
> >>> Module Name:src
> >>> Committed By:ozaki-r
> >>> Date:Thu Apr 12 04:38:13 UTC 2018
> >>>
> >>> Modified Files:
> >>> src/sys/net: if.h route.c route.h rtsock.c
> >>>
> >>> Log Message:
> >>> Resolve tangled lock dependencies in route.c
> >>>
> >>> This change sweeps remaining lock decisions based on if locked or not
> >>> by moving
> >>> utility functions of rtentry updates from rtsock.c and ensuring
> >>> holding the
> >>> rt_lock.  It also improves the atomicity of a update of a rtentry.
> >>>
> >>
> >>> +static struct ifaddr *
> >>> +rt_update_get_ifa(const struct rt_addrinfo info, const struct
> >>> rtentry *rt,
> >>> +struct ifnet **ifp, struct psref *psref_ifp, struct psref *psref)
> >>> +{
> >>
> >>
> >> Do we need to pass info as a value? It is pretty large here (1024 bytes).
> >
> > Yeah, we were just discussing on this alert of LGTM bot.
> >
> > We can use const pointer here. I will commit the fix soon.
> >
> > Thanks,
> > rin

Thank you for the commit!

>
> Thanks for addressing it! I wonder whether there is performance impact
> here (is this hot-path code?).

The function is not used in any packet processing (hot paths)
and used only for route updates that are uncommon for most users.

  ozaki-r


Re: CVS commit: src/sys/net

2019-09-23 Thread Kamil Rytarowski
On 23.09.2019 06:53, Rin Okuyama wrote:
> Hi,
> 
> On 2019/09/22 18:30, Kamil Rytarowski wrote:
>> On 12.04.2018 06:38, Ryota Ozaki wrote:
>>> Module Name:    src
>>> Committed By:    ozaki-r
>>> Date:    Thu Apr 12 04:38:13 UTC 2018
>>>
>>> Modified Files:
>>> src/sys/net: if.h route.c route.h rtsock.c
>>>
>>> Log Message:
>>> Resolve tangled lock dependencies in route.c
>>>
>>> This change sweeps remaining lock decisions based on if locked or not
>>> by moving
>>> utility functions of rtentry updates from rtsock.c and ensuring
>>> holding the
>>> rt_lock.  It also improves the atomicity of a update of a rtentry.
>>>
>>
>>> +static struct ifaddr *
>>> +rt_update_get_ifa(const struct rt_addrinfo info, const struct
>>> rtentry *rt,
>>> +    struct ifnet **ifp, struct psref *psref_ifp, struct psref *psref)
>>> +{
>>
>>
>> Do we need to pass info as a value? It is pretty large here (1024 bytes).
> 
> Yeah, we were just discussing on this alert of LGTM bot.
> 
> We can use const pointer here. I will commit the fix soon.
> 
> Thanks,
> rin

Thanks for addressing it! I wonder whether there is performance impact
here (is this hot-path code?).



signature.asc
Description: OpenPGP digital signature


CVS commit: src/sys/net

2019-09-22 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Mon Sep 23 05:00:20 UTC 2019

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

Log Message:
Stop passing a large const structure by value, in order to avoid
possible kernel stack overflow; const pointer is suffice here.

Pointed out by the lgtm bot and kamil.

OK ozaki-r

XXX
pullup to netbsd-9


To generate a diff of this commit:
cvs rdiff -u -r1.221 -r1.222 src/sys/net/route.c

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



CVS commit: src/sys/net

2019-09-22 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Mon Sep 23 05:00:20 UTC 2019

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

Log Message:
Stop passing a large const structure by value, in order to avoid
possible kernel stack overflow; const pointer is suffice here.

Pointed out by the lgtm bot and kamil.

OK ozaki-r

XXX
pullup to netbsd-9


To generate a diff of this commit:
cvs rdiff -u -r1.221 -r1.222 src/sys/net/route.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/route.c
diff -u src/sys/net/route.c:1.221 src/sys/net/route.c:1.222
--- src/sys/net/route.c:1.221	Thu Sep 19 04:46:29 2019
+++ src/sys/net/route.c	Mon Sep 23 05:00:20 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: route.c,v 1.221 2019/09/19 04:46:29 ozaki-r Exp $	*/
+/*	$NetBSD: route.c,v 1.222 2019/09/23 05:00:20 rin Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -97,7 +97,7 @@
 #endif
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.221 2019/09/19 04:46:29 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.222 2019/09/23 05:00:20 rin Exp $");
 
 #include 
 #ifdef RTFLUSH_DEBUG
@@ -1387,47 +1387,48 @@ rt_setgate(struct rtentry *rt, const str
 }
 
 static struct ifaddr *
-rt_update_get_ifa(const struct rt_addrinfo info, const struct rtentry *rt,
+rt_update_get_ifa(const struct rt_addrinfo *info, const struct rtentry *rt,
 struct ifnet **ifp, struct psref *psref_ifp, struct psref *psref)
 {
 	struct ifaddr *ifa = NULL;
 
 	*ifp = NULL;
-	if (info.rti_info[RTAX_IFP] != NULL) {
-		ifa = ifa_ifwithnet_psref(info.rti_info[RTAX_IFP], psref);
+	if (info->rti_info[RTAX_IFP] != NULL) {
+		ifa = ifa_ifwithnet_psref(info->rti_info[RTAX_IFP], psref);
 		if (ifa == NULL)
 			goto next;
 		*ifp = ifa->ifa_ifp;
 		if_acquire(*ifp, psref_ifp);
-		if (info.rti_info[RTAX_IFA] == NULL &&
-		info.rti_info[RTAX_GATEWAY] == NULL)
+		if (info->rti_info[RTAX_IFA] == NULL &&
+		info->rti_info[RTAX_GATEWAY] == NULL)
 			goto next;
 		ifa_release(ifa, psref);
-		if (info.rti_info[RTAX_IFA] == NULL) {
+		if (info->rti_info[RTAX_IFA] == NULL) {
 			/* route change   -ifp  */
-			ifa = ifaof_ifpforaddr_psref(info.rti_info[RTAX_GATEWAY],
-			*ifp, psref);
+			ifa = ifaof_ifpforaddr_psref(
+			info->rti_info[RTAX_GATEWAY], *ifp, psref);
 		} else {
 			/* route change  -ifp  -ifa  */
-			ifa = ifa_ifwithaddr_psref(info.rti_info[RTAX_IFA], psref);
+			ifa = ifa_ifwithaddr_psref(info->rti_info[RTAX_IFA],
+			psref);
 			if (ifa != NULL)
 goto out;
-			ifa = ifaof_ifpforaddr_psref(info.rti_info[RTAX_IFA],
+			ifa = ifaof_ifpforaddr_psref(info->rti_info[RTAX_IFA],
 			*ifp, psref);
 		}
 		goto out;
 	}
 next:
-	if (info.rti_info[RTAX_IFA] != NULL) {
+	if (info->rti_info[RTAX_IFA] != NULL) {
 		/* route change   -ifa  */
-		ifa = ifa_ifwithaddr_psref(info.rti_info[RTAX_IFA], psref);
+		ifa = ifa_ifwithaddr_psref(info->rti_info[RTAX_IFA], psref);
 		if (ifa != NULL)
 			goto out;
 	}
-	if (info.rti_info[RTAX_GATEWAY] != NULL) {
+	if (info->rti_info[RTAX_GATEWAY] != NULL) {
 		/* route change   */
 		ifa = ifa_ifwithroute_psref(rt->rt_flags, rt_getkey(rt),
-		info.rti_info[RTAX_GATEWAY], psref);
+		info->rti_info[RTAX_GATEWAY], psref);
 	}
 out:
 	if (ifa != NULL && *ifp == NULL) {
@@ -1487,7 +1488,7 @@ rt_update(struct rtentry *rt, struct rt_
 	 * flags may also be different; ifp may be specified
 	 * by ll sockaddr when protocol address is ambiguous
 	 */
-	new_ifa = rt_update_get_ifa(*info, rt, _ifp, _new_ifp,
+	new_ifa = rt_update_get_ifa(info, rt, _ifp, _new_ifp,
 	_new_ifa);
 	if (new_ifa != NULL) {
 		ifa_release(ifa, _ifa);



Re: CVS commit: src/sys/net

2019-09-22 Thread Rin Okuyama

Hi,

On 2019/09/22 18:30, Kamil Rytarowski wrote:

On 12.04.2018 06:38, Ryota Ozaki wrote:

Module Name:src
Committed By:   ozaki-r
Date:   Thu Apr 12 04:38:13 UTC 2018

Modified Files:
src/sys/net: if.h route.c route.h rtsock.c

Log Message:
Resolve tangled lock dependencies in route.c

This change sweeps remaining lock decisions based on if locked or not by moving
utility functions of rtentry updates from rtsock.c and ensuring holding the
rt_lock.  It also improves the atomicity of a update of a rtentry.




+static struct ifaddr *
+rt_update_get_ifa(const struct rt_addrinfo info, const struct rtentry *rt,
+struct ifnet **ifp, struct psref *psref_ifp, struct psref *psref)
+{



Do we need to pass info as a value? It is pretty large here (1024 bytes).


Yeah, we were just discussing on this alert of LGTM bot.

We can use const pointer here. I will commit the fix soon.

Thanks,
rin


Re: CVS commit: src/sys/net

2019-09-22 Thread Kamil Rytarowski
On 12.04.2018 06:38, Ryota Ozaki wrote:
> Module Name:  src
> Committed By: ozaki-r
> Date: Thu Apr 12 04:38:13 UTC 2018
> 
> Modified Files:
>   src/sys/net: if.h route.c route.h rtsock.c
> 
> Log Message:
> Resolve tangled lock dependencies in route.c
> 
> This change sweeps remaining lock decisions based on if locked or not by 
> moving
> utility functions of rtentry updates from rtsock.c and ensuring holding the
> rt_lock.  It also improves the atomicity of a update of a rtentry.
> 

> +static struct ifaddr *
> +rt_update_get_ifa(const struct rt_addrinfo info, const struct rtentry *rt,
> +struct ifnet **ifp, struct psref *psref_ifp, struct psref *psref)
> +{


Do we need to pass info as a value? It is pretty large here (1024 bytes).



signature.asc
Description: OpenPGP digital signature


CVS commit: src/sys/net

2019-09-20 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Sep 20 08:45:30 UTC 2019

Modified Files:
src/sys/net: if_ppp.c ppp_tty.c

Log Message:
dedup


To generate a diff of this commit:
cvs rdiff -u -r1.165 -r1.166 src/sys/net/if_ppp.c
cvs rdiff -u -r1.65 -r1.66 src/sys/net/ppp_tty.c

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



CVS commit: src/sys/net

2019-09-20 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Sep 20 08:45:30 UTC 2019

Modified Files:
src/sys/net: if_ppp.c ppp_tty.c

Log Message:
dedup


To generate a diff of this commit:
cvs rdiff -u -r1.165 -r1.166 src/sys/net/if_ppp.c
cvs rdiff -u -r1.65 -r1.66 src/sys/net/ppp_tty.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_ppp.c
diff -u src/sys/net/if_ppp.c:1.165 src/sys/net/if_ppp.c:1.166
--- src/sys/net/if_ppp.c:1.165	Tue Jun 25 12:30:50 2019
+++ src/sys/net/if_ppp.c	Fri Sep 20 08:45:29 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ppp.c,v 1.165 2019/06/25 12:30:50 msaitoh Exp $	*/
+/*	$NetBSD: if_ppp.c,v 1.166 2019/09/20 08:45:29 maxv Exp $	*/
 /*	Id: if_ppp.c,v 1.6 1997/03/04 03:33:00 paulus Exp 	*/
 
 /*
@@ -102,7 +102,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_ppp.c,v 1.165 2019/06/25 12:30:50 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ppp.c,v 1.166 2019/09/20 08:45:29 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "ppp.h"
@@ -181,19 +181,6 @@ static void	pppintr(void *);
 extern struct linesw ppp_disc;
 
 /*
- * Some useful mbuf macros not in mbuf.h.
- */
-#define M_IS_CLUSTER(m)	((m)->m_flags & M_EXT)
-
-#define M_DATASTART(m)			\
-	(M_IS_CLUSTER(m) ? (m)->m_ext.ext_buf :\
-	(m)->m_flags & M_PKTHDR ? (m)->m_pktdat : (m)->m_dat)
-
-#define M_DATASIZE(m)			\
-	(M_IS_CLUSTER(m) ? (m)->m_ext.ext_size :			\
-	(m)->m_flags & M_PKTHDR ? MHLEN: MLEN)
-
-/*
  * We define two link layer specific mbuf flags, to mark high-priority
  * packets for output, and received packets following lost/corrupted
  * packets.
@@ -1624,7 +1611,7 @@ ppp_inproc(struct ppp_softc *sc, struct 
 	 * If the packet will fit in a header mbuf, don't waste a
 	 * whole cluster on it.
 	 */
-	if (ilen <= MHLEN && M_IS_CLUSTER(m)) {
+	if (ilen <= MHLEN && (m->m_flags & M_EXT)) {
 		MGETHDR(mp, M_DONTWAIT, MT_DATA);
 		if (mp != NULL) {
 			m_copydata(m, 0, ilen, mtod(mp, void *));

Index: src/sys/net/ppp_tty.c
diff -u src/sys/net/ppp_tty.c:1.65 src/sys/net/ppp_tty.c:1.66
--- src/sys/net/ppp_tty.c:1.65	Thu Jan 24 09:31:09 2019
+++ src/sys/net/ppp_tty.c	Fri Sep 20 08:45:29 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ppp_tty.c,v 1.65 2019/01/24 09:31:09 knakahara Exp $	*/
+/*	$NetBSD: ppp_tty.c,v 1.66 2019/09/20 08:45:29 maxv Exp $	*/
 /*	Id: ppp_tty.c,v 1.3 1996/07/01 01:04:11 paulus Exp 	*/
 
 /*
@@ -93,7 +93,7 @@
 /* from NetBSD: if_ppp.c,v 1.15.2.2 1994/07/28 05:17:58 cgd Exp */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ppp_tty.c,v 1.65 2019/01/24 09:31:09 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ppp_tty.c,v 1.66 2019/09/20 08:45:29 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "ppp.h"
@@ -166,19 +166,6 @@ static void	ppplogchar(struct ppp_softc 
 static void	pppdumpframe(struct ppp_softc *sc, struct mbuf* m, int xmit);
 
 /*
- * Some useful mbuf macros not in mbuf.h.
- */
-#define M_IS_CLUSTER(m)	((m)->m_flags & M_EXT)
-
-#define M_DATASTART(m)	\
-	(M_IS_CLUSTER(m) ? (m)->m_ext.ext_buf : \
-	(m)->m_flags & M_PKTHDR ? (m)->m_pktdat : (m)->m_dat)
-
-#define M_DATASIZE(m)	\
-	(M_IS_CLUSTER(m) ? (m)->m_ext.ext_size : \
-	(m)->m_flags & M_PKTHDR ? MHLEN: MLEN)
-
-/*
  * Does c need to be escaped?
  */
 #define ESCAPE_P(c)	(sc->sc_asyncmap[(c) >> 5] & (1 << ((c) & 0x1F)))
@@ -969,7 +956,7 @@ pppgetm(struct ppp_softc *sc)
 	*mp = m;
 	MCLGET(m, M_DONTWAIT);
 	}
-	len -= M_DATASIZE(m);
+	len -= M_BUFSIZE(m);
 	mp = >m_next;
 }
 }
@@ -1137,7 +1124,7 @@ pppinput(int c, struct tty *tp)
 	}
 	m = sc->sc_m;
 	m->m_len = 0;
-	m->m_data = M_DATASTART(sc->sc_m);
+	MRESETDATA(m);
 	sc->sc_mc = m;
 	sc->sc_mp = mtod(m, char *);
 	sc->sc_fcs = PPP_INITFCS;
@@ -1193,7 +1180,7 @@ pppinput(int c, struct tty *tp)
 	}
 	sc->sc_mc = m = m->m_next;
 	m->m_len = 0;
-	m->m_data = M_DATASTART(m);
+	MRESETDATA(m);
 	sc->sc_mp = mtod(m, char *);
 }
 



CVS commit: src/sys/net

2019-09-19 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Sep 19 06:09:52 UTC 2019

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

Log Message:
l2tp(4): avoid having struct ifqueue directly in a percpu storage.

percpu(9) has a certain memory storage for each CPU and provides it by the piece
to users.  If the storages went short, percpu(9) enlarges them by allocating new
larger memory areas, replacing old ones with them and destroying the old ones.
A percpu storage referenced by a pointer gotten via percpu_getref can be
destroyed by the mechanism after a running thread sleeps even if percpu_putref
has not been called.

Tx processing of l2tp(4) uses normally involves sleepable operations so we
must avoid dereferencing a percpu data (struct ifqueue) after executing Tx
processing.  Address this situation by having just a pointer to the data in
a percpu storage instead.

Reviewed by ozaki-r@ and yamaguchi@


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 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.



CVS commit: src/sys/net

2019-09-19 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Sep 19 06:09:52 UTC 2019

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

Log Message:
l2tp(4): avoid having struct ifqueue directly in a percpu storage.

percpu(9) has a certain memory storage for each CPU and provides it by the piece
to users.  If the storages went short, percpu(9) enlarges them by allocating new
larger memory areas, replacing old ones with them and destroying the old ones.
A percpu storage referenced by a pointer gotten via percpu_getref can be
destroyed by the mechanism after a running thread sleeps even if percpu_putref
has not been called.

Tx processing of l2tp(4) uses normally involves sleepable operations so we
must avoid dereferencing a percpu data (struct ifqueue) after executing Tx
processing.  Address this situation by having just a pointer to the data in
a percpu storage instead.

Reviewed by ozaki-r@ and yamaguchi@


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 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.38 src/sys/net/if_l2tp.c:1.39
--- src/sys/net/if_l2tp.c:1.38	Thu Sep 19 06:07:24 2019
+++ src/sys/net/if_l2tp.c	Thu Sep 19 06:09:52 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_l2tp.c,v 1.38 2019/09/19 06:07:24 knakahara Exp $	*/
+/*	$NetBSD: if_l2tp.c,v 1.39 2019/09/19 06:09:52 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_l2tp.c,v 1.38 2019/09/19 06:07:24 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_l2tp.c,v 1.39 2019/09/19 06:09:52 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -116,6 +116,7 @@ pserialize_t l2tp_psz __read_mostly;
 struct psref_class *lv_psref_class __read_mostly;
 
 static void	l2tp_ifq_init_pc(void *, void *, struct cpu_info *);
+static void	l2tp_ifq_fini_pc(void *, void *, struct cpu_info *);
 
 static int	l2tp_clone_create(struct if_clone *, int);
 static int	l2tp_clone_destroy(struct ifnet *);
@@ -151,6 +152,20 @@ static void	l2tp_set_state(struct l2tp_s
 static int	l2tp_encap_attach(struct l2tp_variant *);
 static int	l2tp_encap_detach(struct l2tp_variant *);
 
+static inline struct ifqueue *
+l2tp_ifq_percpu_getref(percpu_t *pc)
+{
+
+	return *(struct ifqueue **)percpu_getref(pc);
+}
+
+static inline void
+l2tp_ifq_percpu_putref(percpu_t *pc)
+{
+
+	percpu_putref(pc);
+}
+
 #ifndef MAX_L2TP_NEST
 /*
  * This macro controls the upper limitation on nesting of l2tp tunnels.
@@ -252,7 +267,7 @@ l2tp_clone_create(struct if_clone *ifc, 
 
 	sc->l2tp_ro_percpu = if_tunnel_alloc_ro_percpu();
 
-	sc->l2tp_ifq_percpu = percpu_alloc(sizeof(struct ifqueue));
+	sc->l2tp_ifq_percpu = percpu_alloc(sizeof(struct ifqueue *));
 	percpu_foreach(sc->l2tp_ifq_percpu, l2tp_ifq_init_pc, NULL);
 	sc->l2tp_si = softint_establish(si_flags, l2tpintr_softint, sc);
 
@@ -319,10 +334,18 @@ l2tpattach0(struct l2tp_softc *sc)
 void
 l2tp_ifq_init_pc(void *p, void *arg __unused, struct cpu_info *ci __unused)
 {
-	struct ifqueue *ifq = p;
+	struct ifqueue **ifqp = p;
 
-	memset(ifq, 0, sizeof(*ifq));
-	ifq->ifq_maxlen = IFQ_MAXLEN;
+	*ifqp = kmem_zalloc(sizeof(**ifqp), KM_SLEEP);
+	(*ifqp)->ifq_maxlen = IFQ_MAXLEN;
+}
+
+void
+l2tp_ifq_fini_pc(void *p, void *arg __unused, struct cpu_info *ci __unused)
+{
+	struct ifqueue **ifqp = p;
+
+	kmem_free(*ifqp, sizeof(**ifqp));
 }
 
 static int
@@ -344,7 +367,8 @@ l2tp_clone_destroy(struct ifnet *ifp)
 	mutex_exit(>l2tp_lock);
 
 	softint_disestablish(sc->l2tp_si);
-	percpu_free(sc->l2tp_ifq_percpu, sizeof(struct ifqueue));
+	percpu_foreach(sc->l2tp_ifq_percpu, l2tp_ifq_fini_pc, NULL);
+	percpu_free(sc->l2tp_ifq_percpu, sizeof(struct ifqueue *));
 
 	mutex_enter(_softcs.lock);
 	LIST_REMOVE(sc, l2tp_list);
@@ -378,10 +402,10 @@ l2tp_tx_enqueue(struct l2tp_variant *var
 	ifp = >l2tp_ec.ec_if;
 
 	s = splsoftnet();
-	ifq = percpu_getref(sc->l2tp_ifq_percpu);
+	ifq = l2tp_ifq_percpu_getref(sc->l2tp_ifq_percpu);
 	if (IF_QFULL(ifq)) {
 		ifp->if_oerrors++;
-		percpu_putref(sc->l2tp_ifq_percpu);
+		l2tp_ifq_percpu_putref(sc->l2tp_ifq_percpu);
 		splx(s);
 		m_freem(m);
 		return ENOBUFS;
@@ -503,16 +527,16 @@ l2tpintr(struct l2tp_variant *var)
 
 	/* output processing */
 	if (var->lv_my_sess_id == 0 || var->lv_peer_sess_id == 0) {
-		ifq = percpu_getref(sc->l2tp_ifq_percpu);
+		ifq = l2tp_ifq_percpu_getref(sc->l2tp_ifq_percpu);
 		IF_PURGE(ifq);
-		percpu_putref(sc->l2tp_ifq_percpu);
+		l2tp_ifq_percpu_putref(sc->l2tp_ifq_percpu);
 		if (cpuid == 0)
 			IFQ_PURGE(>if_snd);
 		return;
 	}
 
 	/* Currently, l2tpintr() is always called in softint context. */
-	ifq = percpu_getref(sc->l2tp_ifq_percpu);
+	ifq = l2tp_ifq_percpu_getref(sc->l2tp_ifq_percpu);
 	for (;;) {
 		IF_DEQUEUE(ifq, m);
 		if (m != NULL)
@@ -520,7 +544,7 @@ l2tpintr(struct l2tp_variant *var)
 		else
 			break;
 	

CVS commit: src/sys/net

2019-09-18 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Sep 19 04:59:42 UTC 2019

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

Log Message:
Divide Tx context of l2tp(4) to improve performance.

It seems l2tp(4) call path is too long for instruction cache. So, dividing
l2tp(4) Tx context improves CPU use efficiency.

After this commit, l2tp(4) throughput gains 10% on my machine(Atom C3000).


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/sys/net/if_l2tp.c
cvs rdiff -u -r1.6 -r1.7 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.



CVS commit: src/sys/net

2019-09-18 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Sep 19 04:59:42 UTC 2019

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

Log Message:
Divide Tx context of l2tp(4) to improve performance.

It seems l2tp(4) call path is too long for instruction cache. So, dividing
l2tp(4) Tx context improves CPU use efficiency.

After this commit, l2tp(4) throughput gains 10% on my machine(Atom C3000).


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/sys/net/if_l2tp.c
cvs rdiff -u -r1.6 -r1.7 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.36 src/sys/net/if_l2tp.c:1.37
--- src/sys/net/if_l2tp.c:1.36	Mon Aug 19 03:24:05 2019
+++ src/sys/net/if_l2tp.c	Thu Sep 19 04:59:42 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_l2tp.c,v 1.36 2019/08/19 03:24:05 ozaki-r Exp $	*/
+/*	$NetBSD: if_l2tp.c,v 1.37 2019/09/19 04:59:42 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_l2tp.c,v 1.36 2019/08/19 03:24:05 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_l2tp.c,v 1.37 2019/09/19 04:59:42 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -118,15 +118,20 @@ struct psref_class *lv_psref_class __rea
 static void	l2tp_ro_init_pc(void *, void *, struct cpu_info *);
 static void	l2tp_ro_fini_pc(void *, void *, struct cpu_info *);
 
+static void	l2tp_ifq_init_pc(void *, void *, struct cpu_info *);
+
 static int	l2tp_clone_create(struct if_clone *, int);
 static int	l2tp_clone_destroy(struct ifnet *);
 
 struct if_clone l2tp_cloner =
 IF_CLONE_INITIALIZER("l2tp", l2tp_clone_create, l2tp_clone_destroy);
 
+static int	l2tp_tx_enqueue(struct l2tp_variant *, struct mbuf *);
 static int	l2tp_output(struct ifnet *, struct mbuf *,
 		const struct sockaddr *, const struct rtentry *);
+static void	l2tp_sendit(struct l2tp_variant *, struct mbuf *);
 static void	l2tpintr(struct l2tp_variant *);
+static void	l2tpintr_softint(void *);
 
 static void	l2tp_hash_init(void);
 static int	l2tp_hash_fini(void);
@@ -225,7 +230,10 @@ l2tp_clone_create(struct if_clone *ifc, 
 	struct l2tp_softc *sc;
 	struct l2tp_variant *var;
 	int rv;
-
+	u_int si_flags = SOFTINT_NET;
+#ifdef NET_MPSAFE
+	si_flags |= SOFTINT_MPSAFE;
+#endif
 	sc = kmem_zalloc(sizeof(struct l2tp_softc), KM_SLEEP);
 	if_initname(>l2tp_ec.ec_if, ifc->ifc_name, unit);
 	rv = l2tpattach0(sc);
@@ -248,6 +256,10 @@ l2tp_clone_create(struct if_clone *ifc, 
 	sc->l2tp_ro_percpu = percpu_alloc(sizeof(struct l2tp_ro));
 	percpu_foreach(sc->l2tp_ro_percpu, l2tp_ro_init_pc, NULL);
 
+	sc->l2tp_ifq_percpu = percpu_alloc(sizeof(struct ifqueue));
+	percpu_foreach(sc->l2tp_ifq_percpu, l2tp_ifq_init_pc, NULL);
+	sc->l2tp_si = softint_establish(si_flags, l2tpintr_softint, sc);
+
 	mutex_enter(_softcs.lock);
 	LIST_INSERT_HEAD(_softcs.list, sc, l2tp_list);
 	mutex_exit(_softcs.lock);
@@ -326,6 +338,15 @@ l2tp_ro_fini_pc(void *p, void *arg __unu
 	mutex_obj_free(lro->lr_lock);
 }
 
+void
+l2tp_ifq_init_pc(void *p, void *arg __unused, struct cpu_info *ci __unused)
+{
+	struct ifqueue *ifq = p;
+
+	memset(ifq, 0, sizeof(*ifq));
+	ifq->ifq_maxlen = IFQ_MAXLEN;
+}
+
 static int
 l2tp_clone_destroy(struct ifnet *ifp)
 {
@@ -336,13 +357,17 @@ l2tp_clone_destroy(struct ifnet *ifp)
 	l2tp_clear_session(sc);
 	l2tp_delete_tunnel(>l2tp_ec.ec_if);
 	/*
-	 * To avoid for l2tp_transmit() to access sc->l2tp_var after free it.
+	 * To avoid for l2tp_transmit() and l2tpintr_softint() to access
+	 * sc->l2tp_var after free it.
 	 */
 	mutex_enter(>l2tp_lock);
 	var = sc->l2tp_var;
 	l2tp_variant_update(sc, NULL);
 	mutex_exit(>l2tp_lock);
 
+	softint_disestablish(sc->l2tp_si);
+	percpu_free(sc->l2tp_ifq_percpu, sizeof(struct ifqueue));
+
 	mutex_enter(_softcs.lock);
 	LIST_REMOVE(sc, l2tp_list);
 	mutex_exit(_softcs.lock);
@@ -363,6 +388,37 @@ l2tp_clone_destroy(struct ifnet *ifp)
 }
 
 static int
+l2tp_tx_enqueue(struct l2tp_variant *var, struct mbuf *m)
+{
+	struct l2tp_softc *sc;
+	struct ifnet *ifp;
+	struct ifqueue *ifq;
+	int s;
+
+	KASSERT(psref_held(>lv_psref, lv_psref_class));
+
+	sc = var->lv_softc;
+	ifp = >l2tp_ec.ec_if;
+
+	s = splsoftnet();
+	ifq = percpu_getref(sc->l2tp_ifq_percpu);
+	if (IF_QFULL(ifq)) {
+		ifp->if_oerrors++;
+		percpu_putref(sc->l2tp_ifq_percpu);
+		splx(s);
+		m_freem(m);
+		return ENOBUFS;
+	}
+
+	IF_ENQUEUE(ifq, m);
+	percpu_putref(sc->l2tp_ifq_percpu);
+	softint_schedule(sc->l2tp_si);
+	/* counter is incremented in l2tpintr() */
+	splx(s);
+	return 0;
+}
+
+static int
 l2tp_output(struct ifnet *ifp, struct mbuf *m, const struct sockaddr *dst,
 const struct rtentry *rt)
 {
@@ -404,17 +460,7 @@ l2tp_output(struct ifnet *ifp, struct mb
 	}
 	*mtod(m, int *) = dst->sa_family;
 
-	IFQ_ENQUEUE(>if_snd, m, error);
-	if (error)
-		goto end;
-
-	/*
-	 * direct call to avoid infinite 

CVS commit: src/sys/net

2019-09-18 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Thu Sep 19 04:46:29 UTC 2019

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

Log Message:
Add missing #include 


To generate a diff of this commit:
cvs rdiff -u -r1.220 -r1.221 src/sys/net/route.c

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



CVS commit: src/sys/net

2019-09-18 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Thu Sep 19 04:46:29 UTC 2019

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

Log Message:
Add missing #include 


To generate a diff of this commit:
cvs rdiff -u -r1.220 -r1.221 src/sys/net/route.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/route.c
diff -u src/sys/net/route.c:1.220 src/sys/net/route.c:1.221
--- src/sys/net/route.c:1.220	Thu Sep 19 04:08:29 2019
+++ src/sys/net/route.c	Thu Sep 19 04:46:29 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: route.c,v 1.220 2019/09/19 04:08:29 ozaki-r Exp $	*/
+/*	$NetBSD: route.c,v 1.221 2019/09/19 04:46:29 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -97,7 +97,7 @@
 #endif
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.220 2019/09/19 04:08:29 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.221 2019/09/19 04:46:29 ozaki-r Exp $");
 
 #include 
 #ifdef RTFLUSH_DEBUG
@@ -119,6 +119,7 @@ __KERNEL_RCSID(0, "$NetBSD: route.c,v 1.
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 



CVS commit: src/sys/net

2019-09-13 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Sep 13 06:39:29 UTC 2019

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

Log Message:
As I suspected, the KASSERT I added yesterday can fire if we try to process
zero-sized packets. Skip them to prevent a type confusion that can trigger
random page faults later.

Reported-by: syzbot+3e447ebdcb2bcfa40...@syzkaller.appspotmail.com


To generate a diff of this commit:
cvs rdiff -u -r1.230 -r1.231 src/sys/net/bpf.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/bpf.c
diff -u src/sys/net/bpf.c:1.230 src/sys/net/bpf.c:1.231
--- src/sys/net/bpf.c:1.230	Thu Sep 12 07:38:19 2019
+++ src/sys/net/bpf.c	Fri Sep 13 06:39:29 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpf.c,v 1.230 2019/09/12 07:38:19 maxv Exp $	*/
+/*	$NetBSD: bpf.c,v 1.231 2019/09/13 06:39:29 maxv Exp $	*/
 
 /*
  * Copyright (c) 1990, 1991, 1993
@@ -39,7 +39,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.230 2019/09/12 07:38:19 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.231 2019/09/13 06:39:29 maxv Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_bpf.h"
@@ -1676,6 +1676,11 @@ _bpf_mtap(struct bpf_if *bp, struct mbuf
 
 	pktlen = m_length(m);
 
+	/* Skip zero-sized packets. */
+	if (__predict_false(pktlen == 0)) {
+		return;
+	}
+
 	if (pktlen == m->m_len) {
 		cpfn = (void *)memcpy;
 		marg = mtod(m, void *);



CVS commit: src/sys/net

2019-09-13 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Sep 13 06:39:29 UTC 2019

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

Log Message:
As I suspected, the KASSERT I added yesterday can fire if we try to process
zero-sized packets. Skip them to prevent a type confusion that can trigger
random page faults later.

Reported-by: syzbot+3e447ebdcb2bcfa40...@syzkaller.appspotmail.com


To generate a diff of this commit:
cvs rdiff -u -r1.230 -r1.231 src/sys/net/bpf.c

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



CVS commit: src/sys/net

2019-09-12 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu Sep 12 07:38:19 UTC 2019

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

Log Message:
Add KASSERT to catch bugs. Something tells me it could easily fire.


To generate a diff of this commit:
cvs rdiff -u -r1.229 -r1.230 src/sys/net/bpf.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/bpf.c
diff -u src/sys/net/bpf.c:1.229 src/sys/net/bpf.c:1.230
--- src/sys/net/bpf.c:1.229	Wed Jul 10 17:55:33 2019
+++ src/sys/net/bpf.c	Thu Sep 12 07:38:19 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpf.c,v 1.229 2019/07/10 17:55:33 maxv Exp $	*/
+/*	$NetBSD: bpf.c,v 1.230 2019/09/12 07:38:19 maxv Exp $	*/
 
 /*
  * Copyright (c) 1990, 1991, 1993
@@ -39,7 +39,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.229 2019/07/10 17:55:33 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.230 2019/09/12 07:38:19 maxv Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_bpf.h"
@@ -1680,6 +1680,7 @@ _bpf_mtap(struct bpf_if *bp, struct mbuf
 		cpfn = (void *)memcpy;
 		marg = mtod(m, void *);
 		buflen = pktlen;
+		KASSERT(buflen != 0);
 	} else {
 		cpfn = bpf_mcpy;
 		marg = m;



CVS commit: src/sys/net

2019-09-12 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu Sep 12 07:38:19 UTC 2019

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

Log Message:
Add KASSERT to catch bugs. Something tells me it could easily fire.


To generate a diff of this commit:
cvs rdiff -u -r1.229 -r1.230 src/sys/net/bpf.c

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



CVS commit: src/sys/net/npf

2019-08-25 Thread Mindaugas Rasiukevicius
Module Name:src
Committed By:   rmind
Date:   Sun Aug 25 17:38:25 UTC 2019

Modified Files:
src/sys/net/npf: npf_ctl.c npf_impl.h npf_os.c

Log Message:
 ake npfctl_switch() and pfil private to OS-specific module.


To generate a diff of this commit:
cvs rdiff -u -r1.57 -r1.58 src/sys/net/npf/npf_ctl.c
cvs rdiff -u -r1.78 -r1.79 src/sys/net/npf/npf_impl.h
cvs rdiff -u -r1.16 -r1.17 src/sys/net/npf/npf_os.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/npf/npf_ctl.c
diff -u src/sys/net/npf/npf_ctl.c:1.57 src/sys/net/npf/npf_ctl.c:1.58
--- src/sys/net/npf/npf_ctl.c:1.57	Sun Aug 25 13:21:03 2019
+++ src/sys/net/npf/npf_ctl.c	Sun Aug 25 17:38:25 2019
@@ -36,7 +36,7 @@
 
 #ifdef _KERNEL
 #include 
-__KERNEL_RCSID(0, "$NetBSD: npf_ctl.c,v 1.57 2019/08/25 13:21:03 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf_ctl.c,v 1.58 2019/08/25 17:38:25 rmind Exp $");
 
 #include 
 #include 
@@ -53,28 +53,6 @@ __KERNEL_RCSID(0, "$NetBSD: npf_ctl.c,v 
 	nvlist_add_string((e), "source-file", __FILE__); \
 	nvlist_add_number((e), "source-line", __LINE__);
 
-#ifdef _KERNEL
-/*
- * npfctl_switch: enable or disable packet inspection.
- */
-int
-npfctl_switch(void *data)
-{
-	const bool onoff = *(int *)data ? true : false;
-	int error;
-
-	if (onoff) {
-		/* Enable: add pfil hooks. */
-		error = npf_pfil_register(false);
-	} else {
-		/* Disable: remove pfil hooks. */
-		npf_pfil_unregister(false);
-		error = 0;
-	}
-	return error;
-}
-#endif
-
 static int
 npf_nvlist_copyin(npf_t *npf, void *data, nvlist_t **nvl)
 {
@@ -731,7 +709,7 @@ npfctl_save(npf_t *npf, u_long cmd, void
 	if (error) {
 		goto out;
 	}
-	nvlist_add_bool(npf_dict, "active", npf_pfil_registered_p());
+	nvlist_add_bool(npf_dict, "active", npf_active_p());
 	error = npf_nvlist_copyout(npf, data, npf_dict);
 	npf_dict = NULL;
 out:

Index: src/sys/net/npf/npf_impl.h
diff -u src/sys/net/npf/npf_impl.h:1.78 src/sys/net/npf/npf_impl.h:1.79
--- src/sys/net/npf/npf_impl.h:1.78	Sun Aug 25 13:21:03 2019
+++ src/sys/net/npf/npf_impl.h	Sun Aug 25 17:38:25 2019
@@ -289,6 +289,7 @@ npf_ruleset_t *	npf_config_ruleset(npf_t
 npf_ruleset_t *	npf_config_natset(npf_t *npf);
 npf_tableset_t *npf_config_tableset(npf_t *npf);
 bool		npf_default_pass(npf_t *);
+bool		npf_active_p(void);
 
 int		npf_worker_sysinit(unsigned);
 void		npf_worker_sysfini(void);
@@ -296,8 +297,6 @@ void		npf_worker_signal(npf_t *);
 void		npf_worker_register(npf_t *, npf_workfunc_t);
 void		npf_worker_unregister(npf_t *, npf_workfunc_t);
 
-int		npfctl_switch(void *);
-int		npfctl_reload(u_long, void *);
 int		npfctl_save(npf_t *, u_long, void *);
 int		npfctl_load(npf_t *, u_long, void *);
 int		npfctl_rule(npf_t *, u_long, void *);
@@ -327,11 +326,6 @@ void		npf_ifaddr_sync(npf_t *, ifnet_t *
 void		npf_ifaddr_flush(npf_t *, ifnet_t *);
 void		npf_ifaddr_syncall(npf_t *);
 
-/* Packet filter hooks. */
-int		npf_pfil_register(bool);
-void		npf_pfil_unregister(bool);
-bool		npf_pfil_registered_p(void);
-
 /* Protocol helpers. */
 int		npf_cache_all(npf_cache_t *);
 void		npf_recache(npf_cache_t *);

Index: src/sys/net/npf/npf_os.c
diff -u src/sys/net/npf/npf_os.c:1.16 src/sys/net/npf/npf_os.c:1.17
--- src/sys/net/npf/npf_os.c:1.16	Sun Aug 25 13:21:03 2019
+++ src/sys/net/npf/npf_os.c	Sun Aug 25 17:38:25 2019
@@ -33,7 +33,7 @@
 
 #ifdef _KERNEL
 #include 
-__KERNEL_RCSID(0, "$NetBSD: npf_os.c,v 1.16 2019/08/25 13:21:03 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf_os.c,v 1.17 2019/08/25 17:38:25 rmind Exp $");
 
 #ifdef _KERNEL_OPT
 #include "pf.h"
@@ -84,6 +84,9 @@ MODULE(MODULE_CLASS_MISC, npf, "bpf");
 MODULE(MODULE_CLASS_DRIVER, npf, "bpf");
 #endif
 
+static int	npf_pfil_register(bool);
+static void	npf_pfil_unregister(bool);
+
 static int	npf_dev_open(dev_t, int, int, lwp_t *);
 static int	npf_dev_close(dev_t, int, int, lwp_t *);
 static int	npf_dev_ioctl(dev_t, u_long, void *, int, lwp_t *);
@@ -226,6 +229,26 @@ npf_stats_export(npf_t *npf, void *data)
 	return error;
 }
 
+/*
+ * npfctl_switch: enable or disable packet inspection.
+ */
+static int
+npfctl_switch(void *data)
+{
+	const bool onoff = *(int *)data ? true : false;
+	int error;
+
+	if (onoff) {
+		/* Enable: add pfil hooks. */
+		error = npf_pfil_register(false);
+	} else {
+		/* Disable: remove pfil hooks. */
+		npf_pfil_unregister(false);
+		error = 0;
+	}
+	return error;
+}
+
 static int
 npf_dev_ioctl(dev_t dev, u_long cmd, void *data, int flag, lwp_t *l)
 {
@@ -290,7 +313,7 @@ bool
 npf_autounload_p(void)
 {
 	npf_t *npf = npf_getkernctx();
-	return !npf_pfil_registered_p() && npf_default_pass(npf);
+	return !npf_active_p() && npf_default_pass(npf);
 }
 
 /*
@@ -394,7 +417,7 @@ npf_ifaddrhook(void *arg, u_long cmd, vo
 /*
  * npf_pfil_register: register pfil(9) hooks.
  */
-int
+static int
 npf_pfil_register(bool init)
 {
 	npf_t *npf = npf_getkernctx();
@@ -463,7 +486,7 @@ out:
 /*
  * npf_pfil_unregister: 

CVS commit: src/sys/net/npf

2019-08-25 Thread Mindaugas Rasiukevicius
Module Name:src
Committed By:   rmind
Date:   Sun Aug 25 17:38:25 UTC 2019

Modified Files:
src/sys/net/npf: npf_ctl.c npf_impl.h npf_os.c

Log Message:
 ake npfctl_switch() and pfil private to OS-specific module.


To generate a diff of this commit:
cvs rdiff -u -r1.57 -r1.58 src/sys/net/npf/npf_ctl.c
cvs rdiff -u -r1.78 -r1.79 src/sys/net/npf/npf_impl.h
cvs rdiff -u -r1.16 -r1.17 src/sys/net/npf/npf_os.c

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



CVS commit: src/sys/net

2019-08-22 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Fri Aug 23 02:33:16 UTC 2019

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

Log Message:
- kmem_alloc(,KM_SLEEP) never return NULL, so remove NULL check.
- VLAN ID is never duplicated, so break the loop when found. Also move
  kmen_free() outside of ETHER_LOCK(ec)/ETHER_UNLOCK(ec) to reduce the hold
  time. suggested by ozaki-r.
- Whitespace fix.


To generate a diff of this commit:
cvs rdiff -u -r1.145 -r1.146 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.



CVS commit: src/sys/net

2019-08-22 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Fri Aug 23 02:33:16 UTC 2019

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

Log Message:
- kmem_alloc(,KM_SLEEP) never return NULL, so remove NULL check.
- VLAN ID is never duplicated, so break the loop when found. Also move
  kmen_free() outside of ETHER_LOCK(ec)/ETHER_UNLOCK(ec) to reduce the hold
  time. suggested by ozaki-r.
- Whitespace fix.


To generate a diff of this commit:
cvs rdiff -u -r1.145 -r1.146 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.145 src/sys/net/if_vlan.c:1.146
--- src/sys/net/if_vlan.c:1.145	Wed Aug 21 06:00:07 2019
+++ src/sys/net/if_vlan.c	Fri Aug 23 02:33:15 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vlan.c,v 1.145 2019/08/21 06:00:07 msaitoh Exp $	*/
+/*	$NetBSD: if_vlan.c,v 1.146 2019/08/23 02:33:15 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
@@ -78,7 +78,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.145 2019/08/21 06:00:07 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.146 2019/08/23 02:33:15 msaitoh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -487,10 +487,6 @@ vlan_config(struct ifvlan *ifv, struct i
 		}
 		/* Add a vid to the list */
 		vidmem = kmem_alloc(sizeof(struct vlanid_list), KM_SLEEP);
-		if (vidmem == NULL) {
-			error = ENOMEM;
-			goto viderr;
-		}
 		vidmem->vid = vid;
 		ETHER_LOCK(ec);
 		SIMPLEQ_INSERT_TAIL(>ec_vids, vidmem, vid_list);
@@ -502,7 +498,6 @@ vlan_config(struct ifvlan *ifv, struct i
 			 * HW tagging function.
 			 */
 			error = (*ec->ec_vlan_cb)(ec, vid, true);
-viderr:
 			if (error) {
 ec->ec_nvlans--;
 if (ec->ec_nvlans == 0) {
@@ -638,18 +633,21 @@ vlan_unconfig_locked(struct ifvlan *ifv,
 	case IFT_ETHER:
 	{
 		struct ethercom *ec = (void *)p;
-		struct vlanid_list *vlanidp, *tmpp;
+		struct vlanid_list *vlanidp;
 		uint16_t vid = EVL_VLANOFTAG(nmib->ifvm_tag);
 
 		ETHER_LOCK(ec);
-		SIMPLEQ_FOREACH_SAFE(vlanidp, >ec_vids, vid_list, tmpp) {
+		SIMPLEQ_FOREACH(vlanidp, >ec_vids, vid_list) {
 			if (vlanidp->vid == vid) {
 SIMPLEQ_REMOVE(>ec_vids, vlanidp,
 vlanid_list, vid_list);
-kmem_free(vlanidp, sizeof(*vlanidp));
+break;
 			}
 		}
 		ETHER_UNLOCK(ec);
+		if (vlanidp != NULL)
+			kmem_free(vlanidp, sizeof(*vlanidp));
+
 		if (ec->ec_vlan_cb != NULL) {
 			/*
 			 * Call ec_vlan_cb(). It will setup VLAN HW filter or
@@ -1038,7 +1036,7 @@ vlan_ioctl(struct ifnet *ifp, u_long cmd
 			error = ENOENT;
 			break;
 		}
-		
+
 		error = vlan_config(ifv, pr, vlr.vlr_tag);
 		if (error != 0)
 			break;



CVS commit: src/sys/net

2019-08-20 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Tue Aug 20 10:59:00 UTC 2019

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

Log Message:
if: announce flag changes other than up or down

For example toggling promiscuous mode or disabling ARP.

XXX Pullup -9


To generate a diff of this commit:
cvs rdiff -u -r1.458 -r1.459 src/sys/net/if.c

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



CVS commit: src/sys/net

2019-08-20 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Tue Aug 20 10:59:00 UTC 2019

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

Log Message:
if: announce flag changes other than up or down

For example toggling promiscuous mode or disabling ARP.

XXX Pullup -9


To generate a diff of this commit:
cvs rdiff -u -r1.458 -r1.459 src/sys/net/if.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.458 src/sys/net/if.c:1.459
--- src/sys/net/if.c:1.458	Thu Aug 15 04:20:59 2019
+++ src/sys/net/if.c	Tue Aug 20 10:59:00 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.458 2019/08/15 04:20:59 ozaki-r Exp $	*/
+/*	$NetBSD: if.c,v 1.459 2019/08/20 10:59:00 roy Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc.
@@ -90,7 +90,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.458 2019/08/15 04:20:59 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.459 2019/08/20 10:59:00 roy Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -2914,6 +2914,7 @@ ifioctl_common(struct ifnet *ifp, u_long
 	struct ifreq *ifr;
 	struct ifcapreq *ifcr;
 	struct ifdatareq *ifdr;
+	unsigned short flags;
 
 	switch (cmd) {
 	case SIOCSIFCAP:
@@ -2985,8 +2986,13 @@ ifioctl_common(struct ifnet *ifp, u_long
 			splx(s);
 		}
 		KERNEL_UNLOCK_IF_IFP_MPSAFE(ifp);
-		ifp->if_flags = (ifp->if_flags & IFF_CANTCHANGE) |
-			(ifr->ifr_flags &~ IFF_CANTCHANGE);
+		flags = (ifp->if_flags & IFF_CANTCHANGE) |
+		(ifr->ifr_flags &~ IFF_CANTCHANGE);
+		if (ifp->if_flags != flags) {
+			ifp->if_flags = flags;
+			/* Notify that the flags have changed. */
+			rt_ifmsg(ifp);
+		}
 		break;
 	case SIOCGIFFLAGS:
 		ifr = data;



CVS commit: src/sys/net

2019-08-19 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Tue Aug 20 03:56:59 UTC 2019

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

Log Message:
 Add missing IFNET_LOCK() and IFNET_UNLOCK() in vlan_config().

XXX pullup-9


To generate a diff of this commit:
cvs rdiff -u -r1.142 -r1.143 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.



CVS commit: src/sys/net

2019-08-19 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Tue Aug 20 03:56:59 UTC 2019

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

Log Message:
 Add missing IFNET_LOCK() and IFNET_UNLOCK() in vlan_config().

XXX pullup-9


To generate a diff of this commit:
cvs rdiff -u -r1.142 -r1.143 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.142 src/sys/net/if_vlan.c:1.143
--- src/sys/net/if_vlan.c:1.142	Tue Aug 20 03:50:55 2019
+++ src/sys/net/if_vlan.c	Tue Aug 20 03:56:59 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vlan.c,v 1.142 2019/08/20 03:50:55 msaitoh Exp $	*/
+/*	$NetBSD: if_vlan.c,v 1.143 2019/08/20 03:56:59 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
@@ -78,7 +78,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.142 2019/08/20 03:50:55 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.143 2019/08/20 03:56:59 msaitoh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -494,8 +494,11 @@ vlan_config(struct ifvlan *ifv, struct i
 			KM_SLEEP);
 			if (vidmem == NULL){
 ec->ec_nvlans--;
-if (ec->ec_nvlans == 0)
+if (ec->ec_nvlans == 0) {
+	IFNET_LOCK(p);
 	(void)ether_disable_vlan_mtu(p);
+	IFNET_UNLOCK(p);
+}
 error = ENOMEM;
 goto done;
 			}
@@ -509,8 +512,11 @@ vlan_config(struct ifvlan *ifv, struct i
 error = (*ec->ec_vlan_cb)(ec, vid, true);
 if (error) {
 	ec->ec_nvlans--;
-	if (ec->ec_nvlans == 0)
+	if (ec->ec_nvlans == 0) {
+		IFNET_LOCK(p);
 		(void)ether_disable_vlan_mtu(p);
+		IFNET_UNLOCK(p);
+	}
 	goto done;
 }
 			}



CVS commit: src/sys/net

2019-08-19 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Tue Aug 20 03:50:55 UTC 2019

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

Log Message:
 Check ec_capenable instead of ec_capabilities to control TX side of VLAN HW
tagging correctly.

XXX pullup-9


To generate a diff of this commit:
cvs rdiff -u -r1.141 -r1.142 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.



CVS commit: src/sys/net

2019-08-19 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Tue Aug 20 03:50:55 UTC 2019

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

Log Message:
 Check ec_capenable instead of ec_capabilities to control TX side of VLAN HW
tagging correctly.

XXX pullup-9


To generate a diff of this commit:
cvs rdiff -u -r1.141 -r1.142 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.141 src/sys/net/if_vlan.c:1.142
--- src/sys/net/if_vlan.c:1.141	Wed Jul 17 03:26:24 2019
+++ src/sys/net/if_vlan.c	Tue Aug 20 03:50:55 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vlan.c,v 1.141 2019/07/17 03:26:24 msaitoh Exp $	*/
+/*	$NetBSD: if_vlan.c,v 1.142 2019/08/20 03:50:55 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
@@ -78,7 +78,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.141 2019/07/17 03:26:24 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.142 2019/08/20 03:50:55 msaitoh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1373,7 +1373,7 @@ vlan_start(struct ifnet *ifp)
 		 * If the parent can insert the tag itself, just mark
 		 * the tag in the mbuf header.
 		 */
-		if (ec->ec_capabilities & ETHERCAP_VLAN_HWTAGGING) {
+		if (ec->ec_capenable & ETHERCAP_VLAN_HWTAGGING) {
 			vlan_set_tag(m, mib->ifvm_tag);
 		} else {
 			/*
@@ -1491,7 +1491,7 @@ vlan_transmit(struct ifnet *ifp, struct 
 	 * If the parent can insert the tag itself, just mark
 	 * the tag in the mbuf header.
 	 */
-	if (ec->ec_capabilities & ETHERCAP_VLAN_HWTAGGING) {
+	if (ec->ec_capenable & ETHERCAP_VLAN_HWTAGGING) {
 		vlan_set_tag(m, mib->ifvm_tag);
 	} else {
 		/*



CVS commit: src/sys/net

2019-08-18 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Mon Aug 19 03:24:05 UTC 2019

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

Log Message:
l2tp: initialize mowner variables for MBUFTRACE


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 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.35 src/sys/net/if_l2tp.c:1.36
--- src/sys/net/if_l2tp.c:1.35	Tue Jun 25 12:30:50 2019
+++ src/sys/net/if_l2tp.c	Mon Aug 19 03:24:05 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_l2tp.c,v 1.35 2019/06/25 12:30:50 msaitoh Exp $	*/
+/*	$NetBSD: if_l2tp.c,v 1.36 2019/08/19 03:24:05 ozaki-r Exp $	*/
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_l2tp.c,v 1.35 2019/06/25 12:30:50 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_l2tp.c,v 1.36 2019/08/19 03:24:05 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -275,6 +275,24 @@ 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(>l2tp_ec.ec_if.if_snd);
+
+#ifdef MBUFTRACE
+	struct ethercom *ec = >l2tp_ec;
+	struct ifnet *ifp = >l2tp_ec.ec_if;
+
+	strlcpy(ec->ec_tx_mowner.mo_name, ifp->if_xname,
+	sizeof(ec->ec_tx_mowner.mo_name));
+	strlcpy(ec->ec_tx_mowner.mo_descr, "tx",
+	sizeof(ec->ec_tx_mowner.mo_descr));
+	strlcpy(ec->ec_rx_mowner.mo_name, ifp->if_xname,
+	sizeof(ec->ec_rx_mowner.mo_name));
+	strlcpy(ec->ec_rx_mowner.mo_descr, "rx",
+	sizeof(ec->ec_rx_mowner.mo_descr));
+	MOWNER_ATTACH(>ec_tx_mowner);
+	MOWNER_ATTACH(>ec_rx_mowner);
+	ifp->if_mowner = >ec_tx_mowner;
+#endif
+
 	/* XXX
 	 * It may improve performance to use if_initialize()/if_register()
 	 * so that l2tp_input() calls if_input() instead of



CVS commit: src/sys/net

2019-08-18 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Mon Aug 19 03:24:05 UTC 2019

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

Log Message:
l2tp: initialize mowner variables for MBUFTRACE


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 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.



CVS commit: src/sys/net

2019-08-14 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Thu Aug 15 04:20:59 UTC 2019

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

Log Message:
Restore if_ioctl on error of ifc_destroy

Otherwise subsequence ioctls won't work.

Patch from Harold Gutch on PR kern/54434 (tweaked a bit by me)


To generate a diff of this commit:
cvs rdiff -u -r1.457 -r1.458 src/sys/net/if.c

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



CVS commit: src/sys/net

2019-08-14 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Thu Aug 15 04:20:59 UTC 2019

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

Log Message:
Restore if_ioctl on error of ifc_destroy

Otherwise subsequence ioctls won't work.

Patch from Harold Gutch on PR kern/54434 (tweaked a bit by me)


To generate a diff of this commit:
cvs rdiff -u -r1.457 -r1.458 src/sys/net/if.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.457 src/sys/net/if.c:1.458
--- src/sys/net/if.c:1.457	Thu Jul 25 07:45:57 2019
+++ src/sys/net/if.c	Thu Aug 15 04:20:59 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.457 2019/07/25 07:45:57 knakahara Exp $	*/
+/*	$NetBSD: if.c,v 1.458 2019/08/15 04:20:59 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc.
@@ -90,7 +90,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.457 2019/07/25 07:45:57 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.458 2019/08/15 04:20:59 ozaki-r Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -1611,6 +1611,8 @@ if_clone_destroy(const char *name)
 	struct if_clone *ifc;
 	struct ifnet *ifp;
 	struct psref psref;
+	int error;
+	int (*if_ioctl)(struct ifnet *, u_long, void *);
 
 	KASSERT(mutex_owned(_clone_mtx));
 
@@ -1627,6 +1629,7 @@ if_clone_destroy(const char *name)
 
 	/* We have to disable ioctls here */
 	IFNET_LOCK(ifp);
+	if_ioctl = ifp->if_ioctl;
 	ifp->if_ioctl = if_nullioctl;
 	IFNET_UNLOCK(ifp);
 
@@ -1636,7 +1639,16 @@ if_clone_destroy(const char *name)
 	 */
 	if_put(ifp, );
 
-	return (*ifc->ifc_destroy)(ifp);
+	error = (*ifc->ifc_destroy)(ifp);
+
+	if (error != 0) {
+		/* We have to restore if_ioctl on error */
+		IFNET_LOCK(ifp);
+		ifp->if_ioctl = if_ioctl;
+		IFNET_UNLOCK(ifp);
+	}
+
+	return error;
 }
 
 static bool



CVS commit: src/sys/net

2019-08-09 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sat Aug 10 01:04:05 UTC 2019

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

Log Message:
rename _ifmedia_ioctl() to ifmedia_ioctl_locked().


To generate a diff of this commit:
cvs rdiff -u -r1.46 -r1.47 src/sys/net/if_media.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_media.c
diff -u src/sys/net/if_media.c:1.46 src/sys/net/if_media.c:1.47
--- src/sys/net/if_media.c:1.46	Tue May 21 09:18:37 2019
+++ src/sys/net/if_media.c	Sat Aug 10 01:04:05 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_media.c,v 1.46 2019/05/21 09:18:37 msaitoh Exp $	*/
+/*	$NetBSD: if_media.c,v 1.47 2019/08/10 01:04:05 mrg Exp $	*/
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -76,7 +76,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_media.c,v 1.46 2019/05/21 09:18:37 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_media.c,v 1.47 2019/08/10 01:04:05 mrg Exp $");
 
 #include 
 #include 
@@ -91,7 +91,7 @@ __KERNEL_RCSID(0, "$NetBSD: if_media.c,v
 
 static void	ifmedia_status(struct ifmedia *, struct ifnet *,
 struct ifmediareq *);
-static int	_ifmedia_ioctl(struct ifnet *, struct ifreq *,
+static int	ifmedia_ioctl_locked(struct ifnet *, struct ifreq *,
 struct ifmedia *, u_long);
 
 /*
@@ -243,7 +243,7 @@ ifmedia_set(struct ifmedia *ifm, int tar
  * Device-independent media ioctl support function.
  */
 static int
-_ifmedia_ioctl(struct ifnet *ifp, struct ifreq *ifr, struct ifmedia *ifm,
+ifmedia_ioctl_locked(struct ifnet *ifp, struct ifreq *ifr, struct ifmedia *ifm,
 u_long cmd)
 {
 	struct ifmedia_entry *match;
@@ -369,10 +369,10 @@ ifmedia_ioctl(struct ifnet *ifp, struct 
 
 	/*
 	 * If if_is_mpsafe(ifp), KERNEL_LOCK isn't held here,
-	 * but _ifmedia_ioctl isn't MP-safe yet, so we must hold the lock.
+	 * but ifmedia_ioctl_locked isn't MP-safe yet, so we must hold the lock.
 	 */
 	KERNEL_LOCK_IF_IFP_MPSAFE(ifp);
-	e = _ifmedia_ioctl(ifp, ifr, ifm, cmd);
+	e = ifmedia_ioctl_locked(ifp, ifr, ifm, cmd);
 	KERNEL_UNLOCK_IF_IFP_MPSAFE(ifp);
 	return e;
 }



CVS commit: src/sys/net

2019-08-09 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sat Aug 10 01:04:05 UTC 2019

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

Log Message:
rename _ifmedia_ioctl() to ifmedia_ioctl_locked().


To generate a diff of this commit:
cvs rdiff -u -r1.46 -r1.47 src/sys/net/if_media.c

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



Re: CVS commit: src/sys/net/npf

2019-08-06 Thread Maxime Villard

Le 06/08/2019 à 12:31, Christos Zoulas a écrit :

I did not see any messages about it, and the fix is fine until rmind comes up 
with something better.


Yes turns out it was an off-list email


It is not nice to have HEAD unusable for 2 weeks now (since July 22nd).


Given your second commit, I should understand that rmind is ok with this
change right?


christos


On Aug 6, 2019, at 1:26 PM, Maxime Villard  wrote:

Le 06/08/2019 à 12:25, Christos Zoulas a écrit :

Module Name:src
Committed By:   christos
Date:   Tue Aug  6 10:25:13 UTC 2019
Modified Files:
src/sys/net/npf: npf_conn.c
Log Message:
Introduce an npf_conn_destroy_idx() that can handle partially constructed
conn structures.
To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/net/npf/npf_conn.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.


Rmind said he had a fix and was testing it. Please revert this.




Re: CVS commit: src/sys/net/npf

2019-08-06 Thread Christos Zoulas
Yes, rmind asked me to commit the change in private email.

christos

> On Aug 6, 2019, at 3:59 PM, Maxime Villard  wrote:
> 
> Le 06/08/2019 à 12:31, Christos Zoulas a écrit :
>> I did not see any messages about it, and the fix is fine until rmind comes 
>> up with something better.
> 
> Yes turns out it was an off-list email
> 
>> It is not nice to have HEAD unusable for 2 weeks now (since July 22nd).
> 
> Given your second commit, I should understand that rmind is ok with this
> change right?
> 
>> christos
>>> On Aug 6, 2019, at 1:26 PM, Maxime Villard  wrote:
>>> 
>>> Le 06/08/2019 à 12:25, Christos Zoulas a écrit :
 Module Name:   src
 Committed By:  christos
 Date:  Tue Aug  6 10:25:13 UTC 2019
 Modified Files:
src/sys/net/npf: npf_conn.c
 Log Message:
 Introduce an npf_conn_destroy_idx() that can handle partially constructed
 conn structures.
 To generate a diff of this commit:
 cvs rdiff -u -r1.27 -r1.28 src/sys/net/npf/npf_conn.c
 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.
>>> 
>>> Rmind said he had a fix and was testing it. Please revert this.



CVS commit: src/sys/net/npf

2019-08-06 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Aug  6 11:40:15 UTC 2019

Modified Files:
src/sys/net/npf: npf.c npf_conn.c npf_conn.h

Log Message:
- npf_conn_init(): fix a race when initialising the G/C thread.
- Fix a bug when partially initialised connection is destroyed on error.
(from rmind@)


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/sys/net/npf/npf.c
cvs rdiff -u -r1.28 -r1.29 src/sys/net/npf/npf_conn.c
cvs rdiff -u -r1.16 -r1.17 src/sys/net/npf/npf_conn.h

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



CVS commit: src/sys/net/npf

2019-08-06 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Aug  6 11:40:15 UTC 2019

Modified Files:
src/sys/net/npf: npf.c npf_conn.c npf_conn.h

Log Message:
- npf_conn_init(): fix a race when initialising the G/C thread.
- Fix a bug when partially initialised connection is destroyed on error.
(from rmind@)


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/sys/net/npf/npf.c
cvs rdiff -u -r1.28 -r1.29 src/sys/net/npf/npf_conn.c
cvs rdiff -u -r1.16 -r1.17 src/sys/net/npf/npf_conn.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/npf/npf.c
diff -u src/sys/net/npf/npf.c:1.38 src/sys/net/npf/npf.c:1.39
--- src/sys/net/npf/npf.c:1.38	Mon Jul 22 20:52:01 2019
+++ src/sys/net/npf/npf.c	Tue Aug  6 07:40:15 2019
@@ -33,7 +33,7 @@
 
 #ifdef _KERNEL
 #include 
-__KERNEL_RCSID(0, "$NetBSD: npf.c,v 1.38 2019/07/23 00:52:01 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf.c,v 1.39 2019/08/06 11:40:15 christos Exp $");
 
 #include 
 #include 
@@ -79,13 +79,17 @@ npf_create(int flags, const npf_mbufops_
 	npf_param_init(npf);
 	npf_state_sysinit(npf);
 	npf_ifmap_init(npf, ifops);
-	npf_conn_init(npf, flags);
+	npf_conn_init(npf);
 	npf_portmap_init(npf);
 	npf_alg_init(npf);
 	npf_ext_init(npf);
 
 	/* Load an empty configuration. */
 	npf_config_init(npf);
+
+	if ((flags & NPF_NO_GC) == 0) {
+		npf_worker_register(npf, npf_conn_worker);
+	}
 	return npf;
 }
 

Index: src/sys/net/npf/npf_conn.c
diff -u src/sys/net/npf/npf_conn.c:1.28 src/sys/net/npf/npf_conn.c:1.29
--- src/sys/net/npf/npf_conn.c:1.28	Tue Aug  6 06:25:13 2019
+++ src/sys/net/npf/npf_conn.c	Tue Aug  6 07:40:15 2019
@@ -107,7 +107,7 @@
 
 #ifdef _KERNEL
 #include 
-__KERNEL_RCSID(0, "$NetBSD: npf_conn.c,v 1.28 2019/08/06 10:25:13 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf_conn.c,v 1.29 2019/08/06 11:40:15 christos Exp $");
 
 #include 
 #include 
@@ -143,14 +143,13 @@ CTASSERT(PFIL_ALL == (0x001 | 0x002));
 enum { CONN_TRACKING_OFF, CONN_TRACKING_ON };
 
 static nvlist_t *npf_conn_export(npf_t *, npf_conn_t *);
-static void npf_conn_destroy_idx(npf_t *, npf_conn_t *, unsigned);
 
 /*
  * npf_conn_sys{init,fini}: initialise/destroy connection tracking.
  */
 
 void
-npf_conn_init(npf_t *npf, int flags)
+npf_conn_init(npf_t *npf)
 {
 	npf->conn_cache[0] = pool_cache_init(
 	offsetof(npf_conn_t, c_keys[NPF_CONNKEY_V4WORDS * 2]),
@@ -162,10 +161,6 @@ npf_conn_init(npf_t *npf, int flags)
 	mutex_init(>conn_lock, MUTEX_DEFAULT, IPL_NONE);
 	npf->conn_tracking = CONN_TRACKING_OFF;
 	npf->conn_db = npf_conndb_create();
-
-	if ((flags & NPF_NO_GC) == 0) {
-		npf_worker_register(npf, npf_conn_worker);
-	}
 	npf_conndb_sysinit(npf);
 }
 
@@ -430,10 +425,11 @@ npf_conn_establish(npf_cache_t *npc, int
 
 	con->c_proto = npc->npc_proto;
 	CTASSERT(sizeof(con->c_proto) >= sizeof(npc->npc_proto));
+	con->c_alen = alen;
 
 	/* Initialize the protocol state. */
 	if (!npf_state_init(npc, >c_state)) {
-		npf_conn_destroy_idx(npf, con, idx);
+		npf_conn_destroy(npf, con);
 		return NULL;
 	}
 	KASSERT(npf_iscached(npc, NPC_IP46));
@@ -447,7 +443,7 @@ npf_conn_establish(npf_cache_t *npc, int
 	 */
 	if (!npf_conn_conkey(npc, fw, true) ||
 	!npf_conn_conkey(npc, bk, false)) {
-		npf_conn_destroy_idx(npf, con, idx);
+		npf_conn_destroy(npf, con);
 		return NULL;
 	}
 	con->c_ifid = global ? nbuf->nb_ifid : 0;
@@ -500,14 +496,8 @@ err:
 void
 npf_conn_destroy(npf_t *npf, npf_conn_t *con)
 {
-	const npf_connkey_t *key = npf_conn_getforwkey(con);
-	const unsigned alen = NPF_CONNKEY_ALEN(key);
-	npf_conn_destroy_idx(npf, con, NPF_CONNCACHE(alen));
-}
+	const unsigned idx __unused = NPF_CONNCACHE(con->c_alen);
 
-static void
-npf_conn_destroy_idx(npf_t *npf, npf_conn_t *con, unsigned idx)
-{
 	KASSERT(con->c_refcnt == 0);
 
 	if (con->c_nat) {
@@ -799,6 +789,7 @@ npf_conn_export(npf_t *npf, npf_conn_t *
 
 	fw = npf_conn_getforwkey(con);
 	alen = NPF_CONNKEY_ALEN(fw);
+	KASSERT(alen == con->c_alen);
 	bk = npf_conn_getbackkey(con, alen);
 
 	kdict = npf_connkey_export(fw);
@@ -899,7 +890,7 @@ npf_conn_import(npf_t *npf, npf_conndb_t
 	npf_conndb_enqueue(cd, con);
 	return 0;
 err:
-	npf_conn_destroy_idx(npf, con, idx);
+	npf_conn_destroy(npf, con);
 	return EINVAL;
 }
 

Index: src/sys/net/npf/npf_conn.h
diff -u src/sys/net/npf/npf_conn.h:1.16 src/sys/net/npf/npf_conn.h:1.17
--- src/sys/net/npf/npf_conn.h:1.16	Mon Jul 22 20:52:01 2019
+++ src/sys/net/npf/npf_conn.h	Tue Aug  6 07:40:15 2019
@@ -50,7 +50,8 @@ struct npf_conn {
 	 * Protocol, address length, the interface ID (if zero,
 	 * then the state is global) and connection flags.
 	 */
-	unsigned		c_proto;
+	uint16_t		c_proto;
+	uint16_t		c_alen;
 	unsigned		c_ifid;
 	unsigned		c_flags;
 
@@ -123,7 +124,7 @@ void		npf_connkey_print(const npf_connke
 /*
  * Connection tracking interface.
  */
-void		npf_conn_init(npf_t *, int);
+void		npf_conn_init(npf_t *);
 void		npf_conn_fini(npf_t 

Re: CVS commit: src/sys/net/npf

2019-08-06 Thread Christos Zoulas
I did not see any messages about it, and the fix is fine until rmind comes up 
with something better.
It is not nice to have HEAD unusable for 2 weeks now (since July 22nd).

christos

> On Aug 6, 2019, at 1:26 PM, Maxime Villard  wrote:
> 
> Le 06/08/2019 à 12:25, Christos Zoulas a écrit :
>> Module Name: src
>> Committed By:christos
>> Date:Tue Aug  6 10:25:13 UTC 2019
>> Modified Files:
>>  src/sys/net/npf: npf_conn.c
>> Log Message:
>> Introduce an npf_conn_destroy_idx() that can handle partially constructed
>> conn structures.
>> To generate a diff of this commit:
>> cvs rdiff -u -r1.27 -r1.28 src/sys/net/npf/npf_conn.c
>> Please note that diffs are not public domain; they are subject to the
>> copyright notices on the relevant files.
> 
> Rmind said he had a fix and was testing it. Please revert this.



Re: CVS commit: src/sys/net/npf

2019-08-06 Thread Maxime Villard

Le 06/08/2019 à 12:25, Christos Zoulas a écrit :

Module Name:src
Committed By:   christos
Date:   Tue Aug  6 10:25:13 UTC 2019

Modified Files:
src/sys/net/npf: npf_conn.c

Log Message:
Introduce an npf_conn_destroy_idx() that can handle partially constructed
conn structures.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/net/npf/npf_conn.c

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


Rmind said he had a fix and was testing it. Please revert this.


CVS commit: src/sys/net/npf

2019-08-06 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Aug  6 10:25:13 UTC 2019

Modified Files:
src/sys/net/npf: npf_conn.c

Log Message:
Introduce an npf_conn_destroy_idx() that can handle partially constructed
conn structures.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/net/npf/npf_conn.c

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



CVS commit: src/sys/net/npf

2019-08-06 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Aug  6 10:25:13 UTC 2019

Modified Files:
src/sys/net/npf: npf_conn.c

Log Message:
Introduce an npf_conn_destroy_idx() that can handle partially constructed
conn structures.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/net/npf/npf_conn.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/npf/npf_conn.c
diff -u src/sys/net/npf/npf_conn.c:1.27 src/sys/net/npf/npf_conn.c:1.28
--- src/sys/net/npf/npf_conn.c:1.27	Mon Jul 22 20:52:01 2019
+++ src/sys/net/npf/npf_conn.c	Tue Aug  6 06:25:13 2019
@@ -107,7 +107,7 @@
 
 #ifdef _KERNEL
 #include 
-__KERNEL_RCSID(0, "$NetBSD: npf_conn.c,v 1.27 2019/07/23 00:52:01 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf_conn.c,v 1.28 2019/08/06 10:25:13 christos Exp $");
 
 #include 
 #include 
@@ -143,6 +143,7 @@ CTASSERT(PFIL_ALL == (0x001 | 0x002));
 enum { CONN_TRACKING_OFF, CONN_TRACKING_ON };
 
 static nvlist_t *npf_conn_export(npf_t *, npf_conn_t *);
+static void npf_conn_destroy_idx(npf_t *, npf_conn_t *, unsigned);
 
 /*
  * npf_conn_sys{init,fini}: initialise/destroy connection tracking.
@@ -432,7 +433,7 @@ npf_conn_establish(npf_cache_t *npc, int
 
 	/* Initialize the protocol state. */
 	if (!npf_state_init(npc, >c_state)) {
-		npf_conn_destroy(npf, con);
+		npf_conn_destroy_idx(npf, con, idx);
 		return NULL;
 	}
 	KASSERT(npf_iscached(npc, NPC_IP46));
@@ -446,7 +447,7 @@ npf_conn_establish(npf_cache_t *npc, int
 	 */
 	if (!npf_conn_conkey(npc, fw, true) ||
 	!npf_conn_conkey(npc, bk, false)) {
-		npf_conn_destroy(npf, con);
+		npf_conn_destroy_idx(npf, con, idx);
 		return NULL;
 	}
 	con->c_ifid = global ? nbuf->nb_ifid : 0;
@@ -501,8 +502,12 @@ npf_conn_destroy(npf_t *npf, npf_conn_t 
 {
 	const npf_connkey_t *key = npf_conn_getforwkey(con);
 	const unsigned alen = NPF_CONNKEY_ALEN(key);
-	const unsigned idx __unused = NPF_CONNCACHE(alen);
+	npf_conn_destroy_idx(npf, con, NPF_CONNCACHE(alen));
+}
 
+static void
+npf_conn_destroy_idx(npf_t *npf, npf_conn_t *con, unsigned idx)
+{
 	KASSERT(con->c_refcnt == 0);
 
 	if (con->c_nat) {
@@ -894,7 +899,7 @@ npf_conn_import(npf_t *npf, npf_conndb_t
 	npf_conndb_enqueue(cd, con);
 	return 0;
 err:
-	npf_conn_destroy(npf, con);
+	npf_conn_destroy_idx(npf, con, idx);
 	return EINVAL;
 }
 



CVS commit: src/sys/net

2019-08-05 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Mon Aug  5 13:30:21 UTC 2019

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

Log Message:
 Cast uint32_t to avoid undefined behavior in bridge_rthash(). Found by kUBSan.


To generate a diff of this commit:
cvs rdiff -u -r1.164 -r1.165 src/sys/net/if_bridge.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_bridge.c
diff -u src/sys/net/if_bridge.c:1.164 src/sys/net/if_bridge.c:1.165
--- src/sys/net/if_bridge.c:1.164	Sat Dec 22 04:28:30 2018
+++ src/sys/net/if_bridge.c	Mon Aug  5 13:30:21 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_bridge.c,v 1.164 2018/12/22 04:28:30 rin Exp $	*/
+/*	$NetBSD: if_bridge.c,v 1.165 2019/08/05 13:30:21 msaitoh Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -80,7 +80,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_bridge.c,v 1.164 2018/12/22 04:28:30 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_bridge.c,v 1.165 2019/08/05 13:30:21 msaitoh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_bridge_ipf.h"
@@ -2517,7 +2517,7 @@ bridge_rthash(struct bridge_softc *sc, c
 
 	b += addr[5] << 8;
 	b += addr[4];
-	a += addr[3] << 24;
+	a += (uint32_t)addr[3] << 24;
 	a += addr[2] << 16;
 	a += addr[1] << 8;
 	a += addr[0];



CVS commit: src/sys/net

2019-08-05 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Mon Aug  5 13:30:21 UTC 2019

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

Log Message:
 Cast uint32_t to avoid undefined behavior in bridge_rthash(). Found by kUBSan.


To generate a diff of this commit:
cvs rdiff -u -r1.164 -r1.165 src/sys/net/if_bridge.c

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



CVS commit: src/sys/net

2019-08-01 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Fri Aug  2 02:17:46 UTC 2019

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

Log Message:
Fix typo (s/m_free/m_freem/) (one more)


To generate a diff of this commit:
cvs rdiff -u -r1.63 -r1.64 src/sys/net/raw_usrreq.c

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

Modified files:

Index: src/sys/net/raw_usrreq.c
diff -u src/sys/net/raw_usrreq.c:1.63 src/sys/net/raw_usrreq.c:1.64
--- src/sys/net/raw_usrreq.c:1.63	Fri Aug  2 01:55:01 2019
+++ src/sys/net/raw_usrreq.c	Fri Aug  2 02:17:46 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: raw_usrreq.c,v 1.63 2019/08/02 01:55:01 ozaki-r Exp $	*/
+/*	$NetBSD: raw_usrreq.c,v 1.64 2019/08/02 02:17:46 ozaki-r Exp $	*/
 
 /*
  * Copyright (c) 1980, 1986, 1993
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: raw_usrreq.c,v 1.63 2019/08/02 01:55:01 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: raw_usrreq.c,v 1.64 2019/08/02 02:17:46 ozaki-r Exp $");
 
 #include 
 #include 
@@ -115,7 +115,7 @@ raw_input(struct mbuf *m0, struct sockpr
 		} else
 			sorwakeup(last);
 	} else {
-		m_free(m);
+		m_freem(m);
 	}
 }
 



CVS commit: src/sys/net

2019-08-01 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Fri Aug  2 02:17:46 UTC 2019

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

Log Message:
Fix typo (s/m_free/m_freem/) (one more)


To generate a diff of this commit:
cvs rdiff -u -r1.63 -r1.64 src/sys/net/raw_usrreq.c

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



CVS commit: src/sys/net

2019-08-01 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Fri Aug  2 01:55:01 UTC 2019

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

Log Message:
Fix typo (s/m_free/m_freem/)

This fixes PR kern/54419 "mbuf leak when deleting route" from sc dying.


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 src/sys/net/raw_usrreq.c

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



CVS commit: src/sys/net

2019-08-01 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Fri Aug  2 01:55:01 UTC 2019

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

Log Message:
Fix typo (s/m_free/m_freem/)

This fixes PR kern/54419 "mbuf leak when deleting route" from sc dying.


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 src/sys/net/raw_usrreq.c

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

Modified files:

Index: src/sys/net/raw_usrreq.c
diff -u src/sys/net/raw_usrreq.c:1.62 src/sys/net/raw_usrreq.c:1.63
--- src/sys/net/raw_usrreq.c:1.62	Fri Sep  7 06:13:14 2018
+++ src/sys/net/raw_usrreq.c	Fri Aug  2 01:55:01 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: raw_usrreq.c,v 1.62 2018/09/07 06:13:14 maxv Exp $	*/
+/*	$NetBSD: raw_usrreq.c,v 1.63 2019/08/02 01:55:01 ozaki-r Exp $	*/
 
 /*
  * Copyright (c) 1980, 1986, 1993
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: raw_usrreq.c,v 1.62 2018/09/07 06:13:14 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: raw_usrreq.c,v 1.63 2019/08/02 01:55:01 ozaki-r Exp $");
 
 #include 
 #include 
@@ -110,7 +110,7 @@ raw_input(struct mbuf *m0, struct sockpr
 	}
 	if (last != NULL) {
 		if (sbappendaddr(>so_rcv, src, m, NULL) == 0) {
-			m_free(m);
+			m_freem(m);
 			soroverflow(last);
 		} else
 			sorwakeup(last);



CVS commit: src/sys/net

2019-07-25 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Jul 25 07:45:57 UTC 2019

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

Log Message:
micro-optimization for if_snd_is_used()


To generate a diff of this commit:
cvs rdiff -u -r1.456 -r1.457 src/sys/net/if.c

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



CVS commit: src/sys/net

2019-07-25 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Jul 25 07:45:57 UTC 2019

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

Log Message:
micro-optimization for if_snd_is_used()


To generate a diff of this commit:
cvs rdiff -u -r1.456 -r1.457 src/sys/net/if.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.456 src/sys/net/if.c:1.457
--- src/sys/net/if.c:1.456	Thu Jul  4 02:44:25 2019
+++ src/sys/net/if.c	Thu Jul 25 07:45:57 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.456 2019/07/04 02:44:25 ozaki-r Exp $	*/
+/*	$NetBSD: if.c,v 1.457 2019/07/25 07:45:57 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.456 2019/07/04 02:44:25 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.457 2019/07/25 07:45:57 knakahara Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -1043,9 +1043,9 @@ static inline bool
 if_snd_is_used(struct ifnet *ifp)
 {
 
-	return ifp->if_transmit == NULL || ifp->if_transmit == if_nulltransmit ||
-	ifp->if_transmit == if_transmit ||
-	ALTQ_IS_ENABLED(>if_snd);
+	return ALTQ_IS_ENABLED(>if_snd) ||
+		ifp->if_transmit == if_transmit ||
+		ifp->if_transmit == NULL || ifp->if_transmit == if_nulltransmit;
 }
 
 /*



CVS commit: src/sys/net/npf

2019-07-24 Thread Mindaugas Rasiukevicius
Module Name:src
Committed By:   rmind
Date:   Thu Jul 25 01:00:28 UTC 2019

Modified Files:
src/sys/net/npf: npf_portmap.c

Log Message:
npf_portmap_flush: remove invalid assert (this routine can be callied via
the npf_destroy() path where the constraint is not applicable).


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/net/npf/npf_portmap.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/npf/npf_portmap.c
diff -u src/sys/net/npf/npf_portmap.c:1.2 src/sys/net/npf/npf_portmap.c:1.3
--- src/sys/net/npf/npf_portmap.c:1.2	Tue Jul 23 08:25:52 2019
+++ src/sys/net/npf/npf_portmap.c	Thu Jul 25 01:00:28 2019
@@ -35,7 +35,7 @@
 
 #ifdef _KERNEL
 #include 
-__KERNEL_RCSID(0, "$NetBSD: npf_portmap.c,v 1.2 2019/07/23 08:25:52 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf_portmap.c,v 1.3 2019/07/25 01:00:28 rmind Exp $");
 
 #include 
 #include 
@@ -461,8 +461,6 @@ npf_portmap_flush(npf_t *npf)
 	npf_portmap_t *pm = npf->portmap;
 	bitmap_t *bm;
 
-	KASSERT(npf_config_locked_p(npf));
-
 	while ((bm = LIST_FIRST(>bitmap_list)) != NULL) {
 		for (unsigned i = 0; i < PORTMAP_L0_WORDS; i++) {
 			uintptr_t bm1 = bm->bits0[i];



CVS commit: src/sys/net/npf

2019-07-24 Thread Mindaugas Rasiukevicius
Module Name:src
Committed By:   rmind
Date:   Thu Jul 25 01:00:28 UTC 2019

Modified Files:
src/sys/net/npf: npf_portmap.c

Log Message:
npf_portmap_flush: remove invalid assert (this routine can be callied via
the npf_destroy() path where the constraint is not applicable).


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/net/npf/npf_portmap.c

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



CVS commit: src/sys/net/npf

2019-07-23 Thread Mindaugas Rasiukevicius
Module Name:src
Committed By:   rmind
Date:   Tue Jul 23 08:25:52 UTC 2019

Modified Files:
src/sys/net/npf: npf_portmap.c

Log Message:
NPF portmap: add a workaround for archs without 64-bit CAS.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/net/npf/npf_portmap.c

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



CVS commit: src/sys/net/npf

2019-07-23 Thread Mindaugas Rasiukevicius
Module Name:src
Committed By:   rmind
Date:   Tue Jul 23 08:25:52 UTC 2019

Modified Files:
src/sys/net/npf: npf_portmap.c

Log Message:
NPF portmap: add a workaround for archs without 64-bit CAS.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/net/npf/npf_portmap.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/npf/npf_portmap.c
diff -u src/sys/net/npf/npf_portmap.c:1.1 src/sys/net/npf/npf_portmap.c:1.2
--- src/sys/net/npf/npf_portmap.c:1.1	Tue Jul 23 00:52:01 2019
+++ src/sys/net/npf/npf_portmap.c	Tue Jul 23 08:25:52 2019
@@ -35,7 +35,7 @@
 
 #ifdef _KERNEL
 #include 
-__KERNEL_RCSID(0, "$NetBSD: npf_portmap.c,v 1.1 2019/07/23 00:52:01 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf_portmap.c,v 1.2 2019/07/23 08:25:52 rmind Exp $");
 
 #include 
 #include 
@@ -106,6 +106,8 @@ typedef struct {
 	int		max_port;
 } npf_portmap_params_t;
 
+static kmutex_t			portmap_lock;
+
 void
 npf_portmap_init(npf_t *npf)
 {
@@ -130,6 +132,8 @@ npf_portmap_init(npf_t *npf)
 	npf->portmap = kmem_zalloc(sizeof(npf_portmap_t), KM_SLEEP);
 	mutex_init(>portmap->list_lock, MUTEX_DEFAULT, IPL_SOFTNET);
 	npf->portmap->addr_map = thmap_create(0, NULL, THMAP_NOCOPY);
+
+	mutex_init(_lock, MUTEX_DEFAULT, IPL_SOFTNET);
 }
 
 void
@@ -146,10 +150,31 @@ npf_portmap_fini(npf_t *npf)
 	thmap_destroy(pm->addr_map);
 	mutex_destroy(>list_lock);
 	kmem_free(pm, sizeof(npf_portmap_t));
+
+	mutex_destroy(_lock);
 }
 
 /
 
+#if defined(_LP64)
+#define	__npf_atomic_cas_64	atomic_cas_64
+#else
+static uint64_t
+__npf_atomic_cas_64(volatile uint64_t *ptr, uint64_t old, uint64_t new)
+{
+	uint64_t prev;
+
+	mutex_enter(_lock);
+	prev = *ptr;
+	if (prev == old) {
+		*ptr = new;
+	}
+	mutex_exit(_lock);
+
+	return prev;
+}
+#endif
+
 /*
  * bitmap_word_isset: test whether the bit value is in the packed array.
  *
@@ -283,7 +308,7 @@ again:
 		 */
 		if ((nval = bitmap_word_cax(bval, -1, chunk_bit)) != 0) {
 			KASSERT((nval & PORTMAP_L1_TAG) == 0);
-			if (atomic_cas_64(>bits0[i], bval, nval) != bval) {
+			if (__npf_atomic_cas_64(>bits0[i], bval, nval) != bval) {
 goto again;
 			}
 			return true;
@@ -315,7 +340,7 @@ again:
 		bm1p = (uintptr_t)bm1;
 		KASSERT((bm1p & PORTMAP_L1_TAG) == 0);
 		bm1p |= PORTMAP_L1_TAG;
-		if (atomic_cas_64(>bits0[i], bval, bm1p) != bval) {
+		if (__npf_atomic_cas_64(>bits0[i], bval, bm1p) != bval) {
 			kmem_intr_free(bm1, sizeof(bitmap_l1_t));
 			goto again;
 		}
@@ -332,7 +357,7 @@ again:
 		return false;
 	}
 	nval = oval | b;
-	if (atomic_cas_64(>bits1[i], oval, nval) != oval) {
+	if (__npf_atomic_cas_64(>bits1[i], oval, nval) != oval) {
 		goto again;
 	}
 	return true;
@@ -356,7 +381,7 @@ again:
 		}
 		nval = bitmap_word_cax(bval, chunk_bit, chunk_bit);
 		KASSERT((nval & PORTMAP_L1_TAG) == 0);
-		if (atomic_cas_64(>bits0[i], bval, nval) != bval) {
+		if (__npf_atomic_cas_64(>bits0[i], bval, nval) != bval) {
 			goto again;
 		}
 		return true;
@@ -372,7 +397,7 @@ again:
 		return false;
 	}
 	nval = oval & ~b;
-	if (atomic_cas_64(>bits1[i], oval, nval) != oval) {
+	if (__npf_atomic_cas_64(>bits1[i], oval, nval) != oval) {
 		goto again;
 	}
 	return true;



CVS commit: src/sys/net

2019-07-18 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Thu Jul 18 06:47:10 UTC 2019

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

Log Message:
Show pointers of llentries on trace logs of LLE_REF_TRACE


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/net/if_llatbl.h

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



CVS commit: src/sys/net

2019-07-18 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Thu Jul 18 06:47:10 UTC 2019

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

Log Message:
Show pointers of llentries on trace logs of LLE_REF_TRACE


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/net/if_llatbl.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_llatbl.h
diff -u src/sys/net/if_llatbl.h:1.16 src/sys/net/if_llatbl.h:1.17
--- src/sys/net/if_llatbl.h:1.16	Thu Jul 12 02:26:04 2018
+++ src/sys/net/if_llatbl.h	Thu Jul 18 06:47:10 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_llatbl.h,v 1.16 2018/07/12 02:26:04 ozaki-r Exp $	*/
+/*	$NetBSD: if_llatbl.h,v 1.17 2019/07/18 06:47:10 ozaki-r Exp $	*/
 /*
  * Copyright (c) 2004 Luigi Rizzo, Alessandro Cerri. All rights reserved.
  * Copyright (c) 2004-2008 Qing Li. All rights reserved.
@@ -143,16 +143,17 @@ struct llentry {
 #define LLE_IS_VALID(lle)	(((lle) != NULL) && ((lle) != (void *)-1))
 
 #if 0
-#define LLE_REF_TRACE(t, n)	log(LOG_DEBUG, "%s:%d: REF(" #t "): refcnt=%d\n", \
-__func__, __LINE__, (n))
+#define LLE_REF_TRACE(t, lle, n) \
+	log(LOG_DEBUG, "%s:%d: %p REF(" #t "): refcnt=%d\n", \
+	__func__, __LINE__, (lle), (n))
 #else
-#define LLE_REF_TRACE(t, n)	do {} while (0)
+#define LLE_REF_TRACE(t, lle, n)	do {} while (0)
 #endif
 
 #define	LLE_ADDREF(lle) do {	\
 	LLE_WLOCK_ASSERT(lle);	\
-	LLE_REF_TRACE(ADD, (lle)->lle_refcnt);			\
-	KASSERTMSG((lle)->lle_refcnt >= 0,\
+	LLE_REF_TRACE(ADD, (lle), (lle)->lle_refcnt);		\
+	KASSERTMSG((lle)->lle_refcnt >= 0,			\
 	"negative refcnt %d on lle %p",			\
 	(lle)->lle_refcnt, (lle));\
 	(lle)->lle_refcnt++;	\
@@ -160,13 +161,13 @@ struct llentry {
 
 #define	LLE_REMREF(lle)	do {	\
 	LLE_WLOCK_ASSERT(lle);	\
-	LLE_REF_TRACE(REM, (lle)->lle_refcnt);			\
-	KASSERTMSG((lle)->lle_refcnt > 0,\
+	LLE_REF_TRACE(REM, (lle), (lle)->lle_refcnt);		\
+	KASSERTMSG((lle)->lle_refcnt > 0,			\
 	"bogus refcnt %d on lle %p",			\
 	(lle)->lle_refcnt, (lle));\
 	(lle)->lle_refcnt--;	\
 	if ((lle)->lle_refcnt == 0)\
-		LLE_REF_TRACE(ZERO, (lle)->lle_refcnt);		\
+		LLE_REF_TRACE(ZERO, (lle), (lle)->lle_refcnt);	\
 } while (0)
 
 #define	LLE_FREE_LOCKED(lle) do {\



CVS commit: src/sys/net

2019-07-10 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Wed Jul 10 17:55:33 UTC 2019

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

Log Message:
Fix info leak: use kmem_zalloc, because we align the buffers, and the
otherwise uninitialized padding bytes get copied to userland in bpf_read().


To generate a diff of this commit:
cvs rdiff -u -r1.228 -r1.229 src/sys/net/bpf.c

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



CVS commit: src/sys/net

2019-07-10 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Wed Jul 10 17:55:33 UTC 2019

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

Log Message:
Fix info leak: use kmem_zalloc, because we align the buffers, and the
otherwise uninitialized padding bytes get copied to userland in bpf_read().


To generate a diff of this commit:
cvs rdiff -u -r1.228 -r1.229 src/sys/net/bpf.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/bpf.c
diff -u src/sys/net/bpf.c:1.228 src/sys/net/bpf.c:1.229
--- src/sys/net/bpf.c:1.228	Mon Sep  3 16:29:35 2018
+++ src/sys/net/bpf.c	Wed Jul 10 17:55:33 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpf.c,v 1.228 2018/09/03 16:29:35 riastradh Exp $	*/
+/*	$NetBSD: bpf.c,v 1.229 2019/07/10 17:55:33 maxv Exp $	*/
 
 /*
  * Copyright (c) 1990, 1991, 1993
@@ -39,7 +39,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.228 2018/09/03 16:29:35 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.229 2019/07/10 17:55:33 maxv Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_bpf.h"
@@ -1987,10 +1987,10 @@ static int
 bpf_allocbufs(struct bpf_d *d)
 {
 
-	d->bd_fbuf = kmem_alloc(d->bd_bufsize, KM_NOSLEEP);
+	d->bd_fbuf = kmem_zalloc(d->bd_bufsize, KM_NOSLEEP);
 	if (!d->bd_fbuf)
 		return (ENOBUFS);
-	d->bd_sbuf = kmem_alloc(d->bd_bufsize, KM_NOSLEEP);
+	d->bd_sbuf = kmem_zalloc(d->bd_bufsize, KM_NOSLEEP);
 	if (!d->bd_sbuf) {
 		kmem_free(d->bd_fbuf, d->bd_bufsize);
 		return (ENOBUFS);



CVS commit: src/sys/net

2019-06-25 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Tue Jun 25 12:30:50 UTC 2019

Modified Files:
src/sys/net: if_gif.c if_ipsec.c if_l2tp.c if_ppp.c if_vlan.c

Log Message:
 Simplify "LIST_HEAD();" to make the code more understandable.
No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.147 -r1.148 src/sys/net/if_gif.c
cvs rdiff -u -r1.21 -r1.22 src/sys/net/if_ipsec.c
cvs rdiff -u -r1.34 -r1.35 src/sys/net/if_l2tp.c
cvs rdiff -u -r1.164 -r1.165 src/sys/net/if_ppp.c
cvs rdiff -u -r1.137 -r1.138 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_gif.c
diff -u src/sys/net/if_gif.c:1.147 src/sys/net/if_gif.c:1.148
--- src/sys/net/if_gif.c:1.147	Tue Jun 18 07:50:43 2019
+++ src/sys/net/if_gif.c	Tue Jun 25 12:30:50 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_gif.c,v 1.147 2019/06/18 07:50:43 msaitoh Exp $	*/
+/*	$NetBSD: if_gif.c,v 1.148 2019/06/25 12:30:50 msaitoh 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.147 2019/06/18 07:50:43 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.148 2019/06/25 12:30:50 msaitoh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -97,9 +97,8 @@ __KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1
 /*
  * gif global variable definitions
  */
-LIST_HEAD(gif_sclist, gif_softc);
 static struct {
-	struct gif_sclist list;
+	LIST_HEAD(gif_sclist, gif_softc) list;
 	kmutex_t lock;
 } gif_softcs __cacheline_aligned;
 

Index: src/sys/net/if_ipsec.c
diff -u src/sys/net/if_ipsec.c:1.21 src/sys/net/if_ipsec.c:1.22
--- src/sys/net/if_ipsec.c:1.21	Thu Mar 14 03:52:40 2019
+++ src/sys/net/if_ipsec.c	Tue Jun 25 12:30:50 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ipsec.c,v 1.21 2019/03/14 03:52:40 knakahara Exp $  */
+/*	$NetBSD: if_ipsec.c,v 1.22 2019/06/25 12:30:50 msaitoh Exp $  */
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_ipsec.c,v 1.21 2019/03/14 03:52:40 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ipsec.c,v 1.22 2019/06/25 12:30:50 msaitoh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -139,9 +139,8 @@ static int if_ipsec_set_addr_port(struct
  */
 
 /* This list is used in ioctl context only. */
-LIST_HEAD(ipsec_sclist, ipsec_softc);
 static struct {
-	struct ipsec_sclist list;
+	LIST_HEAD(ipsec_sclist, ipsec_softc) list;
 	kmutex_t lock;
 } ipsec_softcs __cacheline_aligned;
 

Index: src/sys/net/if_l2tp.c
diff -u src/sys/net/if_l2tp.c:1.34 src/sys/net/if_l2tp.c:1.35
--- src/sys/net/if_l2tp.c:1.34	Fri Apr 26 11:51:56 2019
+++ src/sys/net/if_l2tp.c	Tue Jun 25 12:30:50 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_l2tp.c,v 1.34 2019/04/26 11:51:56 pgoyette Exp $	*/
+/*	$NetBSD: if_l2tp.c,v 1.35 2019/06/25 12:30:50 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_l2tp.c,v 1.34 2019/04/26 11:51:56 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_l2tp.c,v 1.35 2019/06/25 12:30:50 msaitoh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -95,9 +95,8 @@ __KERNEL_RCSID(0, "$NetBSD: if_l2tp.c,v 
 /*
  * l2tp global variable definitions
  */
-LIST_HEAD(l2tp_sclist, l2tp_softc);
 static struct {
-	struct l2tp_sclist list;
+	LIST_HEAD(l2tp_sclist, l2tp_softc) list;
 	kmutex_t lock;
 } l2tp_softcs __cacheline_aligned;
 

Index: src/sys/net/if_ppp.c
diff -u src/sys/net/if_ppp.c:1.164 src/sys/net/if_ppp.c:1.165
--- src/sys/net/if_ppp.c:1.164	Fri Jan 25 08:51:29 2019
+++ src/sys/net/if_ppp.c	Tue Jun 25 12:30:50 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ppp.c,v 1.164 2019/01/25 08:51:29 knakahara Exp $	*/
+/*	$NetBSD: if_ppp.c,v 1.165 2019/06/25 12:30:50 msaitoh Exp $	*/
 /*	Id: if_ppp.c,v 1.6 1997/03/04 03:33:00 paulus Exp 	*/
 
 /*
@@ -102,7 +102,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_ppp.c,v 1.164 2019/01/25 08:51:29 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ppp.c,v 1.165 2019/06/25 12:30:50 msaitoh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "ppp.h"
@@ -206,9 +206,8 @@ static int ppp_clone_destroy(struct ifne
 
 static struct ppp_softc *ppp_create(const char *, int);
 
-LIST_HEAD(ppp_sclist, ppp_softc);
 static struct {
-	struct ppp_sclist list;
+	LIST_HEAD(ppp_sclist, ppp_softc) list;
 	kmutex_t lock;
 } ppp_softcs __cacheline_aligned;
 

Index: src/sys/net/if_vlan.c
diff -u src/sys/net/if_vlan.c:1.137 src/sys/net/if_vlan.c:1.138
--- src/sys/net/if_vlan.c:1.137	Tue Jun 18 08:36:52 2019
+++ src/sys/net/if_vlan.c	Tue Jun 25 12:30:50 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vlan.c,v 1.137 2019/06/18 08:36:52 msaitoh Exp $	*/
+/*	$NetBSD: if_vlan.c,v 1.138 2019/06/25 12:30:50 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
@@ -78,7 +78,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.137 

  1   2   3   >