CVS commit: src/sys/net

2021-08-17 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Aug 17 17:31:13 UTC 2021

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

Log Message:
Some signnes, casts, and constant sizes.
Add module dependencies.


To generate a diff of this commit:
cvs rdiff -u -r1.64 -r1.65 src/sys/net/if_wg.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_wg.c
diff -u src/sys/net/if_wg.c:1.64 src/sys/net/if_wg.c:1.65
--- src/sys/net/if_wg.c:1.64	Tue Jun 15 20:21:19 2021
+++ src/sys/net/if_wg.c	Tue Aug 17 13:31:13 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_wg.c,v 1.64 2021/06/16 00:21:19 riastradh Exp $	*/
+/*	$NetBSD: if_wg.c,v 1.65 2021/08/17 17:31:13 christos Exp $	*/
 
 /*
  * Copyright (C) Ryota Ozaki 
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_wg.c,v 1.64 2021/06/16 00:21:19 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_wg.c,v 1.65 2021/08/17 17:31:13 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_altq_enabled.h"
@@ -442,7 +442,7 @@ sliwin_update(struct sliwin *W, uint64_t
 	bit = S % SLIWIN_BPW;
 	if (W->B[word] & (1UL << bit))
 		return EAUTH;
-	W->B[word] |= 1UL << bit;
+	W->B[word] |= 1U << bit;
 
 	/* Accept!  */
 	return 0;
@@ -1009,7 +1009,7 @@ wg_algo_hmac(uint8_t out[], const size_t
 	uint8_t hmackey[HMAC_BLOCK_LEN] = {0};
 	uint8_t ipad[HMAC_BLOCK_LEN];
 	uint8_t opad[HMAC_BLOCK_LEN];
-	int i;
+	size_t i;
 	struct blake2s state;
 
 	KASSERT(outlen == WG_HASH_LEN);
@@ -1167,11 +1167,11 @@ wg_algo_tai64n(wg_timestamp_t timestamp)
 	/* FIXME strict TAI64N (https://cr.yp.to/libtai/tai64.html) */
 	getnanotime();
 	/* TAI64 label in external TAI64 format */
-	be32enc(timestamp, 0x4000UL + (ts.tv_sec >> 32));
+	be32enc(timestamp, 0x4000U + (uint32_t)(ts.tv_sec >> 32));
 	/* second beginning from 1970 TAI */
-	be32enc(timestamp + 4, ts.tv_sec & 0xU);
+	be32enc(timestamp + 4, (uint32_t)(ts.tv_sec & 0xU));
 	/* nanosecond in big-endian format */
-	be32enc(timestamp + 8, ts.tv_nsec);
+	be32enc(timestamp + 8, (uint32_t)ts.tv_nsec);
 }
 
 /*
@@ -1715,7 +1715,7 @@ wg_send_handshake_msg_init(struct wg_sof
 		if (wgp->wgp_handshake_start_time == 0)
 			wgp->wgp_handshake_start_time = time_uptime;
 		callout_schedule(>wgp_handshake_timeout_timer,
-		MIN(wg_rekey_timeout, INT_MAX/hz) * hz);
+		MIN(wg_rekey_timeout, (unsigned)(INT_MAX / hz)) * hz);
 	} else {
 		wg_put_session_index(wg, wgs);
 		/* Initiation failed; toss packet waiting for it if any.  */
@@ -2271,7 +2271,7 @@ wg_lookup_session_by_index(struct wg_sof
 static void
 wg_schedule_rekey_timer(struct wg_peer *wgp)
 {
-	int timeout = MIN(wg_rekey_after_time, INT_MAX/hz);
+	int timeout = MIN(wg_rekey_after_time, (unsigned)(INT_MAX / hz));
 
 	callout_schedule(>wgp_rekey_timer, timeout * hz);
 }
@@ -2308,7 +2308,7 @@ wg_need_to_send_init_message(struct wg_s
 }
 
 static void
-wg_schedule_peer_task(struct wg_peer *wgp, int task)
+wg_schedule_peer_task(struct wg_peer *wgp, unsigned int task)
 {
 
 	mutex_enter(wgp->wgp_intr_lock);
@@ -3082,7 +3082,7 @@ wg_peer_work(struct work *wk, void *cook
 {
 	struct wg_peer *wgp = container_of(wk, struct wg_peer, wgp_work);
 	struct wg_softc *wg = wgp->wgp_sc;
-	int tasks;
+	unsigned int tasks;
 
 	mutex_enter(wgp->wgp_intr_lock);
 	while ((tasks = wgp->wgp_tasks) != 0) {
@@ -4515,10 +4515,10 @@ wg_ioctl_get(struct wg_softc *wg, struct
 		const struct timespec *t = >wgp_last_handshake_time;
 
 		if (!prop_dictionary_set_uint64(prop_peer,
-			"last_handshake_time_sec", t->tv_sec))
+			"last_handshake_time_sec", (uint64_t)t->tv_sec))
 			goto next;
 		if (!prop_dictionary_set_uint32(prop_peer,
-			"last_handshake_time_nsec", t->tv_nsec))
+			"last_handshake_time_nsec", (uint32_t)t->tv_nsec))
 			goto next;
 
 		if (wgp->wgp_n_allowedips == 0)
@@ -5002,4 +5002,4 @@ rumpkern_wg_recv_peer(struct wg_softc *w
  */
 #include "if_module.h"
 
-IF_MODULE(MODULE_CLASS_DRIVER, wg, "")
+IF_MODULE(MODULE_CLASS_DRIVER, wg, "sodium,blake2s")



CVS commit: src/sys/net

2021-07-17 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sat Jul 17 15:37:04 UTC 2021

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

Log Message:
Mark vlan_safe_ifpromisc_locked() as "__unused" to appease LLVM.

Maybe completely remove this short helper?


To generate a diff of this commit:
cvs rdiff -u -r1.160 -r1.161 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.160 src/sys/net/if_vlan.c:1.161
--- src/sys/net/if_vlan.c:1.160	Thu Jul 15 04:05:47 2021
+++ src/sys/net/if_vlan.c	Sat Jul 17 15:37:04 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vlan.c,v 1.160 2021/07/15 04:05:47 yamaguchi Exp $	*/
+/*	$NetBSD: if_vlan.c,v 1.161 2021/07/17 15:37:04 hannken Exp $	*/
 
 /*
  * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
@@ -78,7 +78,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.160 2021/07/15 04:05:47 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.161 2021/07/17 15:37:04 hannken Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -246,7 +246,7 @@ vlan_safe_ifpromisc(struct ifnet *ifp, i
 	return e;
 }
 
-static inline int
+__unused static inline int
 vlan_safe_ifpromisc_locked(struct ifnet *ifp, int pswitch)
 {
 	int e;



CVS commit: src/sys/net

2021-07-14 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu Jul 15 04:05:47 UTC 2021

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

Log Message:
vlan: drop tagged outgoing packets

vlan(4) doesn't support Q-in-Q yet.


To generate a diff of this commit:
cvs rdiff -u -r1.159 -r1.160 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.159 src/sys/net/if_vlan.c:1.160
--- src/sys/net/if_vlan.c:1.159	Wed Jul 14 06:50:22 2021
+++ src/sys/net/if_vlan.c	Thu Jul 15 04:05:47 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vlan.c,v 1.159 2021/07/14 06:50:22 yamaguchi Exp $	*/
+/*	$NetBSD: if_vlan.c,v 1.160 2021/07/15 04:05:47 yamaguchi Exp $	*/
 
 /*
  * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
@@ -78,7 +78,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.159 2021/07/14 06:50:22 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.160 2021/07/15 04:05:47 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1321,6 +1321,7 @@ vlan_start(struct ifnet *ifp)
 	struct mbuf *m;
 	struct ifvlan_linkmib *mib;
 	struct psref psref;
+	struct ether_header *eh;
 	int error;
 
 	mib = vlan_getref_linkmib(ifv, );
@@ -1342,6 +1343,21 @@ vlan_start(struct ifnet *ifp)
 		if (m == NULL)
 			break;
 
+		if (m->m_len < sizeof(*eh)) {
+			m = m_pullup(m, sizeof(*eh));
+			if (m == NULL) {
+if_statinc(ifp, if_oerrors);
+continue;
+			}
+		}
+
+		eh = mtod(m, struct ether_header *);
+		if (ntohs(eh->ether_type) == ETHERTYPE_VLAN) {
+			m_freem(m);
+			if_statinc(ifp, if_noproto);
+			continue;
+		}
+
 #ifdef ALTQ
 		/*
 		 * KERNEL_LOCK is required for ALTQ even if NET_MPSAFE is
@@ -1465,10 +1481,26 @@ vlan_transmit(struct ifnet *ifp, struct 
 	struct ethercom *ec;
 	struct ifvlan_linkmib *mib;
 	struct psref psref;
+	struct ether_header *eh;
 	int error;
 	size_t pktlen = m->m_pkthdr.len;
 	bool mcast = (m->m_flags & M_MCAST) != 0;
 
+	if (m->m_len < sizeof(*eh)) {
+		m = m_pullup(m, sizeof(*eh));
+		if (m == NULL) {
+			if_statinc(ifp, if_oerrors);
+			return ENOBUFS;
+		}
+	}
+
+	eh = mtod(m, struct ether_header *);
+	if (ntohs(eh->ether_type) == ETHERTYPE_VLAN) {
+		m_freem(m);
+		if_statinc(ifp, if_noproto);
+		return EPROTONOSUPPORT;
+	}
+
 	mib = vlan_getref_linkmib(ifv, );
 	if (mib == NULL) {
 		m_freem(m);



CVS commit: src/sys/net

2021-07-14 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Wed Jul 14 06:50:22 UTC 2021

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

Log Message:
unset IFF_PROMISC at bpf_detach()

Doing "d->bd_promisc = 0" is that bpf_detach() does not call
ifpromisc(ifp, 0). Currently, there is no reason for
this behavior so that it is removed.
In addition to the change, the workaround for it in vlan(4)
is also removed.


To generate a diff of this commit:
cvs rdiff -u -r1.240 -r1.241 src/sys/net/bpf.c
cvs rdiff -u -r1.158 -r1.159 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/bpf.c
diff -u src/sys/net/bpf.c:1.240 src/sys/net/bpf.c:1.241
--- src/sys/net/bpf.c:1.240	Wed Jun  9 15:44:15 2021
+++ src/sys/net/bpf.c	Wed Jul 14 06:50:22 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpf.c,v 1.240 2021/06/09 15:44:15 martin Exp $	*/
+/*	$NetBSD: bpf.c,v 1.241 2021/07/14 06:50:22 yamaguchi Exp $	*/
 
 /*
  * Copyright (c) 1990, 1991, 1993
@@ -39,7 +39,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.240 2021/06/09 15:44:15 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.241 2021/07/14 06:50:22 yamaguchi Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_bpf.h"
@@ -2194,7 +2194,6 @@ _bpfdetach(struct ifnet *ifp)
 			 * Detach the descriptor from an interface now.
 			 * It will be free'ed later by close routine.
 			 */
-			d->bd_promisc = 0;	/* we can't touch device. */
 			bpf_detachd(d);
 			mutex_exit(d->bd_mtx);
 			goto again_d;

Index: src/sys/net/if_vlan.c
diff -u src/sys/net/if_vlan.c:1.158 src/sys/net/if_vlan.c:1.159
--- src/sys/net/if_vlan.c:1.158	Wed Jul 14 06:23:06 2021
+++ src/sys/net/if_vlan.c	Wed Jul 14 06:50:22 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vlan.c,v 1.158 2021/07/14 06:23:06 yamaguchi Exp $	*/
+/*	$NetBSD: if_vlan.c,v 1.159 2021/07/14 06:50:22 yamaguchi Exp $	*/
 
 /*
  * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
@@ -78,7 +78,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.158 2021/07/14 06:23:06 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.159 2021/07/14 06:50:22 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -701,8 +701,6 @@ vlan_unconfig_locked(struct ifvlan *ifv,
 	KERNEL_UNLOCK_UNLESS_NET_MPSAFE();
 #endif
 
-	if ((ifp->if_flags & IFF_PROMISC) != 0)
-		vlan_safe_ifpromisc_locked(ifp, 0);
 	if_down_locked(ifp);
 	ifp->if_capabilities = 0;
 	mutex_enter(>ifv_lock);



CVS commit: src/sys/net

2021-07-14 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Wed Jul 14 06:23:06 UTC 2021

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

Log Message:
Make an mbuf writable before un-tagging


To generate a diff of this commit:
cvs rdiff -u -r1.157 -r1.158 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.157 src/sys/net/if_vlan.c:1.158
--- src/sys/net/if_vlan.c:1.157	Tue Jul  6 02:39:46 2021
+++ src/sys/net/if_vlan.c	Wed Jul 14 06:23:06 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vlan.c,v 1.157 2021/07/06 02:39:46 yamaguchi Exp $	*/
+/*	$NetBSD: if_vlan.c,v 1.158 2021/07/14 06:23:06 yamaguchi Exp $	*/
 
 /*
  * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
@@ -78,7 +78,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.157 2021/07/06 02:39:46 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.158 2021/07/14 06:23:06 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1622,6 +1622,14 @@ vlan_input(struct ifnet *ifp, struct mbu
 			"dropping packet.\n", ifp->if_xname);
 			return;
 		}
+
+		if (m_makewritable(, 0,
+		sizeof(struct ether_vlan_header), M_DONTWAIT)) {
+			m_freem(m);
+			if_statinc(ifp, if_ierrors);
+			return;
+		}
+
 		evl = mtod(m, struct ether_vlan_header *);
 		KASSERT(ntohs(evl->evl_encap_proto) == ETHERTYPE_VLAN);
 



CVS commit: src/sys/net/lagg

2021-07-13 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Tue Jul 13 09:00:27 UTC 2021

Modified Files:
src/sys/net/lagg: if_lagg.c

Log Message:
lagg: fix typo for ALTQ


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/net/lagg/if_lagg.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/lagg/if_lagg.c
diff -u src/sys/net/lagg/if_lagg.c:1.5 src/sys/net/lagg/if_lagg.c:1.6
--- src/sys/net/lagg/if_lagg.c:1.5	Wed Jun 16 00:21:19 2021
+++ src/sys/net/lagg/if_lagg.c	Tue Jul 13 09:00:26 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_lagg.c,v 1.5 2021/06/16 00:21:19 riastradh Exp $	*/
+/*	$NetBSD: if_lagg.c,v 1.6 2021/07/13 09:00:26 ozaki-r Exp $	*/
 
 /*
  * Copyright (c) 2005, 2006 Reyk Floeter 
@@ -20,7 +20,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.5 2021/06/16 00:21:19 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.6 2021/07/13 09:00:26 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -369,7 +369,7 @@ lagg_clone_create(struct if_clone *ifc, 
 	ifp->if_extflags = IFEF_MPSAFE;
 	ifp->if_transmit = lagg_transmit;
 	ifp->if_start = lagg_start;
-	IFQ_SET_READY(>if_send);
+	IFQ_SET_READY(>if_snd);
 
 	error = lagg_setup_sysctls(sc);
 	if (error != 0)



CVS commit: src/sys/net

2021-07-05 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Tue Jul  6 02:39:46 UTC 2021

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

Log Message:
Drop unicast packets that are not for us
when vlan(4) is not in promisc


To generate a diff of this commit:
cvs rdiff -u -r1.156 -r1.157 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.156 src/sys/net/if_vlan.c:1.157
--- src/sys/net/if_vlan.c:1.156	Tue Jul  6 02:34:12 2021
+++ src/sys/net/if_vlan.c	Tue Jul  6 02:39:46 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vlan.c,v 1.156 2021/07/06 02:34:12 yamaguchi Exp $	*/
+/*	$NetBSD: if_vlan.c,v 1.157 2021/07/06 02:39: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.156 2021/07/06 02:34:12 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.157 2021/07/06 02:39:46 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1661,6 +1661,24 @@ vlan_input(struct ifnet *ifp, struct mbu
 		m_adj(m, mib->ifvm_encaplen);
 	}
 
+	/*
+	 * Drop promiscuously received packets if we are not in
+	 * promiscuous mode
+	 */
+	if ((m->m_flags & (M_BCAST | M_MCAST)) == 0 &&
+	(ifp->if_flags & IFF_PROMISC) &&
+	(ifv->ifv_if.if_flags & IFF_PROMISC) == 0) {
+		struct ether_header *eh;
+
+		eh = mtod(m, struct ether_header *);
+		if (memcmp(CLLADDR(ifv->ifv_if.if_sadl),
+		eh->ether_dhost, ETHER_ADDR_LEN) != 0) {
+			m_freem(m);
+			if_statinc(>ifv_if, if_ierrors);
+			goto out;
+		}
+	}
+
 	m_set_rcvif(m, >ifv_if);
 
 	if (pfil_run_hooks(ifp->if_pfil, , ifp, PFIL_IN) != 0)



CVS commit: src/sys/net

2021-07-05 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Tue Jul  6 02:34:12 UTC 2021

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

Log Message:
vlan: added NULL check for the parent interface

The pointer may set to NULL by vlan_unconfig
while packet processing


To generate a diff of this commit:
cvs rdiff -u -r1.155 -r1.156 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.155 src/sys/net/if_vlan.c:1.156
--- src/sys/net/if_vlan.c:1.155	Tue Jul  6 01:16:01 2021
+++ src/sys/net/if_vlan.c	Tue Jul  6 02:34:12 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vlan.c,v 1.155 2021/07/06 01:16:01 yamaguchi Exp $	*/
+/*	$NetBSD: if_vlan.c,v 1.156 2021/07/06 02:34:12 yamaguchi Exp $	*/
 
 /*
  * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
@@ -78,7 +78,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.155 2021/07/06 01:16:01 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.156 2021/07/06 02:34:12 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1328,6 +1328,12 @@ vlan_start(struct ifnet *ifp)
 	mib = vlan_getref_linkmib(ifv, );
 	if (mib == NULL)
 		return;
+
+	if (__predict_false(mib->ifvm_p == NULL)) {
+		vlan_putref_linkmib(mib, );
+		return;
+	}
+
 	p = mib->ifvm_p;
 	ec = (void *)mib->ifvm_p;
 
@@ -1471,6 +1477,12 @@ vlan_transmit(struct ifnet *ifp, struct 
 		return ENETDOWN;
 	}
 
+	if (__predict_false(mib->ifvm_p == NULL)) {
+		vlan_putref_linkmib(mib, );
+		m_freem(m);
+		return ENETDOWN;
+	}
+
 	p = mib->ifvm_p;
 	ec = (void *)mib->ifvm_p;
 



CVS commit: src/sys/net

2021-07-05 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Tue Jul  6 01:16:01 UTC 2021

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

Log Message:
vlan: set the link state to DOWN when its parent detaches


To generate a diff of this commit:
cvs rdiff -u -r1.154 -r1.155 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.154 src/sys/net/if_vlan.c:1.155
--- src/sys/net/if_vlan.c:1.154	Wed Jun 16 00:21:19 2021
+++ src/sys/net/if_vlan.c	Tue Jul  6 01:16:01 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vlan.c,v 1.154 2021/06/16 00:21:19 riastradh Exp $	*/
+/*	$NetBSD: if_vlan.c,v 1.155 2021/07/06 01:16:01 yamaguchi Exp $	*/
 
 /*
  * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
@@ -78,7 +78,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.154 2021/06/16 00:21:19 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.155 2021/07/06 01:16:01 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -366,6 +366,7 @@ vlan_clone_create(struct if_clone *ifc, 
 	 * Set the link state to down.
 	 * When the parent interface attaches we will use that link state.
 	 * When the parent interface link state changes, so will ours.
+	 * When the parent interface detaches, set the link state to down.
 	 */
 	ifp->if_link_state = LINK_STATE_DOWN;
 
@@ -685,6 +686,7 @@ vlan_unconfig_locked(struct ifvlan *ifv,
 	PSLIST_ENTRY_DESTROY(ifv, ifv_hash);
 
 	vlan_linkmib_update(ifv, nmib);
+	if_link_state_change(ifp, LINK_STATE_DOWN);
 
 	mutex_exit(>ifv_lock);
 



CVS commit: src/sys/net

2021-07-01 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Fri Jul  2 03:30:46 UTC 2021

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

Log Message:
Use if_ioctl() for changing MTU, not ether_ioctl to prevent panic

Fix PR kern/56292


To generate a diff of this commit:
cvs rdiff -u -r1.180 -r1.181 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.180 src/sys/net/if_bridge.c:1.181
--- src/sys/net/if_bridge.c:1.180	Wed Jun 16 00:21:19 2021
+++ src/sys/net/if_bridge.c	Fri Jul  2 03:30:46 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_bridge.c,v 1.180 2021/06/16 00:21:19 riastradh Exp $	*/
+/*	$NetBSD: if_bridge.c,v 1.181 2021/07/02 03:30:46 yamaguchi Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -80,7 +80,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_bridge.c,v 1.180 2021/06/16 00:21:19 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_bridge.c,v 1.181 2021/07/02 03:30:46 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -861,7 +861,7 @@ bridge_ioctl_add(struct bridge_softc *sc
 			memset(, 0, sizeof(ifr));
 			ifr.ifr_mtu = sc->sc_if.if_mtu;
 			IFNET_LOCK(ifs);
-			error = ether_ioctl(ifs, SIOCSIFMTU, );
+			error = ifs->if_ioctl(ifs, SIOCSIFMTU, );
 			IFNET_UNLOCK(ifs);
 			if (error != 0)
 goto out;



CVS commit: src/sys/net/lagg

2021-06-30 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Wed Jun 30 06:39:47 UTC 2021

Modified Files:
src/sys/net/lagg: if_lagg_lacp.c

Log Message:
lagg: fix an uninitialize variable

pointed out by tnn@n.o., thanks.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/net/lagg/if_lagg_lacp.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/lagg/if_lagg_lacp.c
diff -u src/sys/net/lagg/if_lagg_lacp.c:1.2 src/sys/net/lagg/if_lagg_lacp.c:1.3
--- src/sys/net/lagg/if_lagg_lacp.c:1.2	Tue May 18 11:02:58 2021
+++ src/sys/net/lagg/if_lagg_lacp.c	Wed Jun 30 06:39:47 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_lagg_lacp.c,v 1.2 2021/05/18 11:02:58 hannken Exp $	*/
+/*	$NetBSD: if_lagg_lacp.c,v 1.3 2021/06/30 06:39:47 yamaguchi Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-NetBSD
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_lagg_lacp.c,v 1.2 2021/05/18 11:02:58 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg_lacp.c,v 1.3 2021/06/30 06:39:47 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_lagg.h"
@@ -2368,13 +2368,17 @@ lacp_unselect(struct lacp_softc *lsc, st
 	lacpp->lp_aggregator = NULL;
 
 	if (LIST_EMPTY(>la_ports)) {
+		remove_actaggr = false;
+
 		if (la == lsc->lsc_aggregator) {
 			LACP_DPRINTF((lsc, NULL, "remove active aggregator\n"));
 			lsc->lsc_aggregator = NULL;
 			remove_actaggr = true;
 		}
+
 		TAILQ_REMOVE(>lsc_aggregators, la, la_q);
 		kmem_free(la, sizeof(*la));
+
 		if (remove_actaggr) {
 			lacp_select_active_aggregator(lsc);
 		}



CVS commit: src/sys/net

2021-06-29 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jun 29 21:19:58 UTC 2021

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

Log Message:
Make if_stats_init, if_attach, if_initialize return void.

percpu_alloc can't fail.

Author: Maya Rashish 
Committer: Taylor R Campbell 


To generate a diff of this commit:
cvs rdiff -u -r1.485 -r1.486 src/sys/net/if.c
cvs rdiff -u -r1.290 -r1.291 src/sys/net/if.h
cvs rdiff -u -r1.3 -r1.4 src/sys/net/if_stats.c
cvs rdiff -u -r1.2 -r1.3 src/sys/net/if_stats.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.c
diff -u src/sys/net/if.c:1.485 src/sys/net/if.c:1.486
--- src/sys/net/if.c:1.485	Mon May 17 04:07:43 2021
+++ src/sys/net/if.c	Tue Jun 29 21:19:58 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.485 2021/05/17 04:07:43 yamaguchi Exp $	*/
+/*	$NetBSD: if.c,v 1.486 2021/06/29 21:19:58 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc.
@@ -90,7 +90,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.485 2021/05/17 04:07:43 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.486 2021/06/29 21:19:58 riastradh Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -702,10 +702,9 @@ skip:
  * ether_ifattach(ifp, enaddr);
  * if_register(ifp);
  */
-int
+void
 if_initialize(ifnet_t *ifp)
 {
-	int rv = 0;
 
 	KASSERT(if_indexlim > 0);
 	TAILQ_INIT(>if_addrlist);
@@ -748,25 +747,11 @@ if_initialize(ifnet_t *ifp)
 	psref_target_init(>if_psref, ifnet_psref_class);
 	ifp->if_ioctl_lock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_NONE);
 	LIST_INIT(>if_multiaddrs);
-	if ((rv = if_stats_init(ifp)) != 0) {
-		goto fail;
-	}
+	if_stats_init(ifp);
 
 	IFNET_GLOBAL_LOCK();
 	if_getindex(ifp);
 	IFNET_GLOBAL_UNLOCK();
-
-	return 0;
-
-fail:
-	IF_AFDATA_LOCK_DESTROY(ifp);
-
-	pfil_run_ifhooks(if_pfil, PFIL_IFNET_DETACH, ifp);
-	(void)pfil_head_destroy(ifp->if_pfil);
-
-	IFQ_LOCK_DESTROY(>if_snd);
-
-	return rv;
 }
 
 /*
@@ -1142,19 +1127,13 @@ if_input(struct ifnet *ifp, struct mbuf 
  * migrate softint-based if_input without much changes. If you don't
  * want to enable it, use if_initialize instead.
  */
-int
+void
 if_attach(ifnet_t *ifp)
 {
-	int rv;
-
-	rv = if_initialize(ifp);
-	if (rv != 0)
-		return rv;
 
+	if_initialize(ifp);
 	ifp->if_percpuq = if_percpuq_create(ifp);
 	if_register(ifp);
-
-	return 0;
 }
 
 void

Index: src/sys/net/if.h
diff -u src/sys/net/if.h:1.290 src/sys/net/if.h:1.291
--- src/sys/net/if.h:1.290	Mon May 17 04:07:43 2021
+++ src/sys/net/if.h	Tue Jun 29 21:19:58 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.h,v 1.290 2021/05/17 04:07:43 yamaguchi Exp $	*/
+/*	$NetBSD: if.h,v 1.291 2021/06/29 21:19:58 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc.
@@ -1115,9 +1115,9 @@ void if_activate_sadl(struct ifnet *, st
 void	if_set_sadl(struct ifnet *, const void *, u_char, bool);
 void	if_alloc_sadl(struct ifnet *);
 void	if_free_sadl(struct ifnet *, int);
-int	if_initialize(struct ifnet *);
+void	if_initialize(struct ifnet *);
 void	if_register(struct ifnet *);
-int	if_attach(struct ifnet *); /* Deprecated. Use if_initialize and if_register */
+void	if_attach(struct ifnet *); /* Deprecated. Use if_initialize and if_register */
 void	if_attachdomain(void);
 void	if_deactivate(struct ifnet *);
 bool	if_is_deactivated(const struct ifnet *);

Index: src/sys/net/if_stats.c
diff -u src/sys/net/if_stats.c:1.3 src/sys/net/if_stats.c:1.4
--- src/sys/net/if_stats.c:1.3	Fri Feb 14 22:04:12 2020
+++ src/sys/net/if_stats.c	Tue Jun 29 21:19:58 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_stats.c,v 1.3 2020/02/14 22:04:12 thorpej Exp $	*/
+/*	$NetBSD: if_stats.c,v 1.4 2021/06/29 21:19:58 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_stats.c,v 1.3 2020/02/14 22:04:12 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_stats.c,v 1.4 2021/06/29 21:19:58 riastradh Exp $");
 
 #include 
 #include 
@@ -45,13 +45,10 @@ __KERNEL_RCSID(0, "$NetBSD: if_stats.c,v
  * if_stats_init --
  *	Initialize statistics storage for a network interface.
  */
-int
+void
 if_stats_init(ifnet_t * const ifp)
 {
 	ifp->if_stats = percpu_alloc(IF_STATS_SIZE);
-	if (ifp->if_stats == NULL)
-		return ENOMEM;
-	return 0;
 }
 
 /*

Index: src/sys/net/if_stats.h
diff -u src/sys/net/if_stats.h:1.2 src/sys/net/if_stats.h:1.3
--- src/sys/net/if_stats.h:1.2	Fri Feb 14 22:04:12 2020
+++ src/sys/net/if_stats.h	Tue Jun 29 21:19:58 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_stats.h,v 1.2 2020/02/14 22:04:12 thorpej Exp $	*/
+/*	$NetBSD: if_stats.h,v 1.3 2021/06/29 21:19:58 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -115,7 +115,7 @@ if_statsub_ref(net_stat_ref_t nsr, if_st
 	_NET_STATSUB_REF(nsr, x, v);
 }
 
-int	if_stats_init(ifnet_t *);
+void	if_stats_init(ifnet_t *);
 void	

CVS commit: src/sys/net

2021-06-09 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Wed Jun  9 15:44:15 UTC 2021

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

Log Message:
Add a bpf_register_track_event() function (and deregister equivalent)
that allows a driver to track listeners attaching/detaching from tap
points.

This is usefull for drivers that would have to do extra work for some
taps and can not easily decide (at the driver level) if the work would
be needed further up the stack.

An example is providing radiotap headers for IEEE 802.11 frames.


To generate a diff of this commit:
cvs rdiff -u -r1.239 -r1.240 src/sys/net/bpf.c
cvs rdiff -u -r1.76 -r1.77 src/sys/net/bpf.h
cvs rdiff -u -r1.47 -r1.48 src/sys/net/bpfdesc.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/bpf.c
diff -u src/sys/net/bpf.c:1.239 src/sys/net/bpf.c:1.240
--- src/sys/net/bpf.c:1.239	Fri Dec 18 01:31:49 2020
+++ src/sys/net/bpf.c	Wed Jun  9 15:44:15 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpf.c,v 1.239 2020/12/18 01:31:49 thorpej Exp $	*/
+/*	$NetBSD: bpf.c,v 1.240 2021/06/09 15:44:15 martin Exp $	*/
 
 /*
  * Copyright (c) 1990, 1991, 1993
@@ -39,7 +39,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.239 2020/12/18 01:31:49 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.240 2021/06/09 15:44:15 martin Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_bpf.h"
@@ -461,6 +461,7 @@ bad:
 static void
 bpf_attachd(struct bpf_d *d, struct bpf_if *bp)
 {
+	struct bpf_event_tracker *t;
 
 	KASSERT(mutex_owned(_mtx));
 	KASSERT(mutex_owned(d->bd_mtx));
@@ -473,6 +474,11 @@ bpf_attachd(struct bpf_d *d, struct bpf_
 	BPFIF_DLIST_WRITER_INSERT_HEAD(bp, d);
 
 	*bp->bif_driverp = bp;
+
+	SLIST_FOREACH(t, >bif_trackers, bet_entries) {
+		t->bet_notify(bp, bp->bif_ifp, bp->bif_dlt,
+		BPF_TRACK_EVENT_ATTACH);
+	}
 }
 
 /*
@@ -482,6 +488,7 @@ static void
 bpf_detachd(struct bpf_d *d)
 {
 	struct bpf_if *bp;
+	struct bpf_event_tracker *t;
 
 	KASSERT(mutex_owned(_mtx));
 	KASSERT(mutex_owned(d->bd_mtx));
@@ -522,7 +529,13 @@ bpf_detachd(struct bpf_d *d)
 		 */
 		*d->bd_bif->bif_driverp = NULL;
 	}
+
 	d->bd_bif = NULL;
+
+	SLIST_FOREACH(t, >bif_trackers, bet_entries) {
+		t->bet_notify(bp, bp->bif_ifp, bp->bif_dlt,
+		BPF_TRACK_EVENT_DETACH);
+	}
 }
 
 static void
@@ -2125,6 +2138,7 @@ _bpfattach(struct ifnet *ifp, u_int dlt,
 	BPF_IFLIST_ENTRY_INIT(bp);
 	PSLIST_INIT(>bif_dlist_head);
 	psref_target_init(>bif_psref, bpf_psref_class);
+	SLIST_INIT(>bif_trackers);
 
 	BPF_IFLIST_WRITER_INSERT_HEAD(bp);
 
@@ -2133,7 +2147,7 @@ _bpfattach(struct ifnet *ifp, u_int dlt,
 	bp->bif_hdrlen = hdrlen;
 	mutex_exit(_mtx);
 #if 0
-	printf("bpf: %s attached\n", ifp->if_xname);
+	printf("bpf: %s attached with dlt %x\n", ifp->if_xname, dlt);
 #endif
 }
 
@@ -2196,6 +2210,14 @@ _bpfdetach(struct ifnet *ifp)
 			pserialize_perform(bpf_psz);
 			psref_target_destroy(>bif_psref, bpf_psref_class);
 
+			while (!SLIST_EMPTY(>bif_trackers)) {
+struct bpf_event_tracker *t =
+SLIST_FIRST(>bif_trackers);
+SLIST_REMOVE_HEAD(>bif_trackers,
+bet_entries);
+kmem_free(t, sizeof(*t));
+			}
+
 			BPF_IFLIST_ENTRY_DESTROY(bp);
 			if (bp->bif_si != NULL) {
 /* XXX NOMPSAFE: assumed running on one CPU */
@@ -2523,10 +2545,69 @@ SYSCTL_SETUP(sysctl_net_bpf_setup, "bpf 
 
 }
 
+static int
+_bpf_register_track_event(struct bpf_if **driverp,
+	void (*_fun)(struct bpf_if *, struct ifnet *, int, int))
+{
+	struct bpf_if *bp;
+	struct bpf_event_tracker *t;
+	int ret = ENOENT;
+
+	t = kmem_zalloc(sizeof(*t), KM_SLEEP);
+	if (!t)
+		return ENOMEM;
+	t->bet_notify = _fun;
+
+	mutex_enter(_mtx);
+	BPF_IFLIST_WRITER_FOREACH(bp) {
+		if (bp->bif_driverp != driverp)
+			continue;
+		SLIST_INSERT_HEAD(>bif_trackers, t, bet_entries);
+		ret = 0;
+		break;
+	}
+	mutex_exit(_mtx);
+
+	return ret;
+}
+
+static int
+_bpf_deregister_track_event(struct bpf_if **driverp,
+	void (*_fun)(struct bpf_if *, struct ifnet *, int, int))
+{
+	struct bpf_if *bp;
+	struct bpf_event_tracker *t = NULL;
+	int ret = ENOENT;
+
+	mutex_enter(_mtx);
+	BPF_IFLIST_WRITER_FOREACH(bp) {
+		if (bp->bif_driverp != driverp)
+			continue;
+		SLIST_FOREACH(t, >bif_trackers, bet_entries) {
+			if (t->bet_notify == _fun) {
+ret = 0;
+break;
+			}
+		}
+		if (ret == 0)
+			break;
+	}
+	if (ret == 0 && t && t->bet_notify == _fun) {
+		SLIST_REMOVE(>bif_trackers, t, bpf_event_tracker,
+		bet_entries);
+	}
+	mutex_exit(_mtx);
+	if (ret == 0)
+		kmem_free(t, sizeof(*t));
+	return ret;
+}
+
 struct bpf_ops bpf_ops_kernel = {
 	.bpf_attach =		_bpfattach,
 	.bpf_detach =		_bpfdetach,
 	.bpf_change_type =	_bpf_change_type,
+	.bpf_register_track_event = _bpf_register_track_event,
+	.bpf_deregister_track_event = _bpf_deregister_track_event,
 
 	.bpf_mtap =		_bpf_mtap,
 	.bpf_mtap2 =		_bpf_mtap2,

Index: src/sys/net/bpf.h
diff -u src/sys/net/bpf.h:1.76 

CVS commit: src/sys/net

2021-06-09 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Wed Jun  9 15:38:40 UTC 2021

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

Log Message:
Add a (FreeBSD compatible) bpf_peers_present() predicate to allow
testing for active listeners on a tap.


To generate a diff of this commit:
cvs rdiff -u -r1.75 -r1.76 src/sys/net/bpf.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/bpf.h
diff -u src/sys/net/bpf.h:1.75 src/sys/net/bpf.h:1.76
--- src/sys/net/bpf.h:1.75	Thu Jun 11 13:36:20 2020
+++ src/sys/net/bpf.h	Wed Jun  9 15:38:39 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpf.h,v 1.75 2020/06/11 13:36:20 roy Exp $	*/
+/*	$NetBSD: bpf.h,v 1.76 2021/06/09 15:38:39 martin Exp $	*/
 
 /*
  * Copyright (c) 1990, 1991, 1993
@@ -501,6 +501,16 @@ bpf_change_type(struct ifnet *_ifp, u_in
 	bpf_ops->bpf_change_type(_ifp, _dlt, _hdrlen);
 }
 
+static __inline bool
+bpf_peers_present(struct bpf_if *dp)
+{
+	/*
+	 * Our code makes sure the driver visible pointer is NULL
+	 * whenever there is no listener on this tap.
+	 */
+	return dp != NULL;
+}
+
 static __inline void
 bpf_detach(struct ifnet *_ifp)
 {



CVS commit: src/sys/net

2021-06-01 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Wed Jun  2 00:47:59 UTC 2021

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

Log Message:
Added missing definition of sppp_ipv6cp_tld

Fixed build without INET6


To generate a diff of this commit:
cvs rdiff -u -r1.257 -r1.258 src/sys/net/if_spppsubr.c

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

Modified files:

Index: src/sys/net/if_spppsubr.c
diff -u src/sys/net/if_spppsubr.c:1.257 src/sys/net/if_spppsubr.c:1.258
--- src/sys/net/if_spppsubr.c:1.257	Tue Jun  1 05:22:57 2021
+++ src/sys/net/if_spppsubr.c	Wed Jun  2 00:47:59 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppsubr.c,v 1.257 2021/06/01 05:22:57 yamaguchi Exp $	 */
+/*	$NetBSD: if_spppsubr.c,v 1.258 2021/06/02 00:47:59 yamaguchi Exp $	 */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.257 2021/06/01 05:22:57 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.258 2021/06/02 00:47:59 yamaguchi Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -4575,6 +4575,13 @@ sppp_ipv6cp_tlu(struct sppp *sp)
 }
 
 static void
+sppp_ipv6cp_tld(struct sppp *sp)
+{
+
+	KASSERT(SPPP_WLOCKED(sp));
+}
+
+static void
 sppp_ipv6cp_scr(struct sppp *sp)
 {
 



CVS commit: src/sys/net

2021-05-31 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Tue Jun  1 05:22:57 UTC 2021

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

Log Message:
Fix the wrong timeout event handler for PAP

sppp_auth_to_event() is a implementation of TO+/TO- event for
authentication protocol and it drops TO+ event in Ack-rcvd state.


To generate a diff of this commit:
cvs rdiff -u -r1.256 -r1.257 src/sys/net/if_spppsubr.c

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

Modified files:

Index: src/sys/net/if_spppsubr.c
diff -u src/sys/net/if_spppsubr.c:1.256 src/sys/net/if_spppsubr.c:1.257
--- src/sys/net/if_spppsubr.c:1.256	Tue Jun  1 05:16:46 2021
+++ src/sys/net/if_spppsubr.c	Tue Jun  1 05:22:57 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppsubr.c,v 1.256 2021/06/01 05:16:46 yamaguchi Exp $	 */
+/*	$NetBSD: if_spppsubr.c,v 1.257 2021/06/01 05:22:57 yamaguchi Exp $	 */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.256 2021/06/01 05:16:46 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.257 2021/06/01 05:22:57 yamaguchi Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -538,7 +538,7 @@ static const struct cp ipv6cp = {
 static const struct cp pap = {
 	PPP_PAP, IDX_PAP, CP_AUTH, "pap",
 	sppp_up_event, sppp_down_event, sppp_open_event,
-	sppp_close_event, sppp_to_event,
+	sppp_close_event, sppp_auth_to_event,
 	sppp_pap_tlu, sppp_null, sppp_tls, sppp_tlf,
 	sppp_pap_scr, sppp_auth_screply,
 	NULL, NULL, NULL



CVS commit: src/sys/net

2021-05-31 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Tue Jun  1 05:16:46 UTC 2021

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

Log Message:
Send Up event in tlu action of LCP

When LCP is stopping, the layer send Down event and Close event
(Down -> Close). To align the sequence, Up event is moved
before Open event.


To generate a diff of this commit:
cvs rdiff -u -r1.255 -r1.256 src/sys/net/if_spppsubr.c

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

Modified files:

Index: src/sys/net/if_spppsubr.c
diff -u src/sys/net/if_spppsubr.c:1.255 src/sys/net/if_spppsubr.c:1.256
--- src/sys/net/if_spppsubr.c:1.255	Tue Jun  1 05:11:22 2021
+++ src/sys/net/if_spppsubr.c	Tue Jun  1 05:16:46 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppsubr.c,v 1.255 2021/06/01 05:11:22 yamaguchi Exp $	 */
+/*	$NetBSD: if_spppsubr.c,v 1.256 2021/06/01 05:16:46 yamaguchi Exp $	 */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.255 2021/06/01 05:11:22 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.256 2021/06/01 05:16:46 yamaguchi Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -1898,6 +1898,7 @@ sppp_open_event(struct sppp *sp, void *x
 		break;
 	case STATE_CLOSED:
 		sp->scp[cp->protoidx].rst_counter = sp->lcp.max_configure;
+		sp->lcp.protos |= (1 << cp->protoidx);
 		(cp->scr)(sp);
 		sppp_cp_change_state(cp, sp, STATE_REQ_SENT);
 		break;
@@ -3114,6 +3115,7 @@ static void
 sppp_lcp_tlu(struct sppp *sp)
 {
 	struct ifnet *ifp;
+	struct sppp_cp *scp;
 	int i;
 	bool going_up;
 
@@ -3160,26 +3162,28 @@ sppp_lcp_tlu(struct sppp *sp)
 	else
 		sppp_change_phase(sp, SPPP_PHASE_NETWORK);
 
-	/*
-	 * Open all authentication protocols.  This is even required
-	 * if we already proceeded to network phase, since it might be
-	 * that remote wants us to authenticate, so we might have to
-	 * send a PAP request.  Undesired authentication protocols
-	 * don't do anything when they get an Open event.
-	 */
-	for (i = 0; i < IDX_COUNT; i++)
-		if ((cps[i])->flags & CP_AUTH) {
-			sppp_wq_add(sp->wq_cp,
-			>scp[(cps[i])->protoidx].work_open);
-		}
 
-	if (sp->pp_phase == SPPP_PHASE_NETWORK) {
-		/* Notify all NCPs. */
-		for (i = 0; i < IDX_COUNT; i++)
-			if ((cps[i])->flags & CP_NCP) {
-			sppp_wq_add(sp->wq_cp,
-			>scp[(cps[i])->protoidx].work_open);
-			}
+	for (i = 0; i < IDX_COUNT; i++) {
+		scp = >scp[(cps[i])->protoidx];
+
+		if (((cps[i])->flags & CP_LCP) == 0)
+			sppp_wq_add(sp->wq_cp, >work_up);
+
+		/*
+		 * Open all authentication protocols.  This is even required
+		 * if we already proceeded to network phase, since it might be
+		 * that remote wants us to authenticate, so we might have to
+		 * send a PAP request.  Undesired authentication protocols
+		 * don't do anything when they get an Open event.
+		 */
+		if ((cps[i])->flags & CP_AUTH)
+			sppp_wq_add(sp->wq_cp, >work_open);
+
+		/* Open all NCPs. */
+		if (sp->pp_phase == SPPP_PHASE_NETWORK &&
+		((cps[i])->flags & CP_NCP) != 0) {
+			sppp_wq_add(sp->wq_cp, >work_open);
+		}
 	}
 
 	/* notify low-level driver of state change */
@@ -3190,7 +3194,8 @@ static void
 sppp_lcp_tld(struct sppp *sp)
 {
 	struct ifnet *ifp;
-	int i, pi, phase;
+	struct sppp_cp *scp;
+	int i, phase;
 
 	KASSERT(SPPP_WLOCKED(sp));
 
@@ -3221,15 +3226,19 @@ sppp_lcp_tld(struct sppp *sp)
 	 * describes it.
 	 */
 	for (i = 0; i < IDX_COUNT; i++) {
-		pi = (cps[i])->protoidx;
-		if (((cps[i])->flags & CP_LCP) == 0) {
-			/* skip if ncp was not started */
-			if (phase != SPPP_PHASE_NETWORK &&
-			((cps[i])->flags & CP_NCP) != 0)
-continue;
+		scp = >scp[(cps[i])->protoidx];
 
-			sppp_wq_add(sp->wq_cp, >scp[pi].work_down);
-			sppp_wq_add(sp->wq_cp, >scp[pi].work_close);
+		if (((cps[i])->flags & CP_LCP) == 0)
+			sppp_wq_add(sp->wq_cp, >work_down);
+
+		if ((cps[i])->flags & CP_AUTH) {
+			sppp_wq_add(sp->wq_cp, >work_close);
+		}
+
+		/* Close all NCPs. */
+		if (phase == SPPP_PHASE_NETWORK &&
+		((cps[i])->flags & CP_NCP) != 0) {
+			sppp_wq_add(sp->wq_cp, >work_close);
 		}
 	}
 }
@@ -6510,11 +6519,10 @@ static void
 sppp_tls(const struct cp *cp, struct sppp *sp)
 {
 
+	SPPP_DLOG(sp, "%s tls\n", cp->name);
+
 	/* notify lcp that is lower layer */
 	sp->lcp.protos |= (1 << cp->protoidx);
-
-	if (sp->scp[IDX_LCP].state == STATE_OPENED)
-		sppp_wq_add(sp->wq_cp, >scp[cp->protoidx].work_up);
 }
 
 static void



CVS commit: src/sys/net

2021-05-31 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Tue Jun  1 05:11:22 UTC 2021

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

Log Message:
Added logs when IPCP and IPv6CP are up or down


To generate a diff of this commit:
cvs rdiff -u -r1.254 -r1.255 src/sys/net/if_spppsubr.c

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

Modified files:

Index: src/sys/net/if_spppsubr.c
diff -u src/sys/net/if_spppsubr.c:1.254 src/sys/net/if_spppsubr.c:1.255
--- src/sys/net/if_spppsubr.c:1.254	Tue Jun  1 05:08:46 2021
+++ src/sys/net/if_spppsubr.c	Tue Jun  1 05:11:22 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppsubr.c,v 1.254 2021/06/01 05:08:46 yamaguchi Exp $	 */
+/*	$NetBSD: if_spppsubr.c,v 1.255 2021/06/01 05:11:22 yamaguchi Exp $	 */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.254 2021/06/01 05:08:46 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.255 2021/06/01 05:11:22 yamaguchi Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -3897,6 +3897,7 @@ sppp_ipcp_tlu(struct sppp *sp)
 
 	KASSERT(SPPP_WLOCKED(sp));
 
+	SPPP_LOG(sp, LOG_INFO, "IPCP layer up\n");
 	ifp = >pp_if;
 	if ((sp->ipcp.flags & IPCP_MYADDR_DYN) &&
 	((sp->ipcp.flags & IPCP_MYADDR_SEEN) == 0)) {
@@ -3920,6 +3921,7 @@ sppp_ipcp_tld(struct sppp *sp)
 
 	KASSERT(SPPP_WLOCKED(sp));
 
+	SPPP_LOG(sp, LOG_INFO, "IPCP layer down\n");
 	ifp = >pp_if;
 	rt_ifmsg(ifp);
 #endif
@@ -4464,6 +4466,7 @@ sppp_ipv6cp_tlu(struct sppp *sp)
 
 	KASSERT(SPPP_WLOCKED(sp));
 
+	SPPP_LOG(sp, LOG_INFO, "IPv6CP layer up\n");
 	ifp = >pp_if;
 	/* we are up - notify isdn daemon */
 	sppp_notify_con_wlocked(sp);
@@ -4477,6 +4480,7 @@ sppp_ipv6cp_tld(struct sppp *sp)
 
 	KASSERT(SPPP_WLOCKED(sp));
 
+	SPPP_LOG(sp, LOG_INFO, "IPv6CP layer down\n");
 	ifp = >pp_if;
 	rt_ifmsg(ifp);
 }



CVS commit: src/sys/net

2021-05-31 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Tue Jun  1 05:08:46 UTC 2021

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

Log Message:
Added SPPP_LOG() for refactoring around log


To generate a diff of this commit:
cvs rdiff -u -r1.253 -r1.254 src/sys/net/if_spppsubr.c

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

Modified files:

Index: src/sys/net/if_spppsubr.c
diff -u src/sys/net/if_spppsubr.c:1.253 src/sys/net/if_spppsubr.c:1.254
--- src/sys/net/if_spppsubr.c:1.253	Tue Jun  1 05:04:06 2021
+++ src/sys/net/if_spppsubr.c	Tue Jun  1 05:08:46 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppsubr.c,v 1.253 2021/06/01 05:04:06 yamaguchi Exp $	 */
+/*	$NetBSD: if_spppsubr.c,v 1.254 2021/06/01 05:08:46 yamaguchi Exp $	 */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.253 2021/06/01 05:04:06 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.254 2021/06/01 05:08:46 yamaguchi Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -319,6 +319,17 @@ static unsigned int sppp_keepalive_cnt =
 #define SPPP_DOWNGRADE(_sp)	rw_downgrade(&(_sp)->pp_lock)
 #define SPPP_WQ_SET(_wk, _func, _arg)	\
 	sppp_wq_set((_wk), (_func), __UNCONST((_arg)))
+#define SPPP_LOG(_sp, _lvl, _fmt, _args...)	do {		\
+	if (__predict_true((_sp) != NULL)) {			\
+		log((_lvl), "%s: ", (_sp)->pp_if.if_xname);	\
+	}			\
+	addlog((_fmt), ##_args);\
+} while (0)
+#define SPPP_DLOG(_sp, _fmt, _args...)	do {	\
+	if (!sppp_debug_enabled(_sp))			\
+		break;	\
+	SPPP_LOG(_sp, LOG_DEBUG, _fmt, ##_args);	\
+} while (0)
 
 #ifdef INET
 #ifndef SPPPSUBR_MPSAFE
@@ -339,10 +350,8 @@ static u_short interactive_ports[8] = {
 #endif
 
 /* almost every function needs these */
-#define STDDCL			\
-	struct ifnet *ifp = >pp_if;\
-	int debug = ifp->if_flags & IFF_DEBUG
 
+static bool sppp_debug_enabled(struct sppp *sp);
 static int sppp_output(struct ifnet *, struct mbuf *,
 		   const struct sockaddr *, const struct rtentry *);
 
@@ -580,13 +589,28 @@ sppp_authproto2proto(u_int authproto)
 	return PPP_NOPROTO;
 }
 
+static inline bool
+sppp_debug_enabled(struct sppp *sp)
+{
+
+	if (__predict_false(sp == NULL))
+		return false;
+
+	if ((sp->pp_if.if_flags & IFF_DEBUG) == 0)
+		return false;
+
+	return true;
+}
+
 static void
 sppp_change_phase(struct sppp *sp, int phase)
 {
-	STDDCL;
+	struct ifnet *ifp;
 
 	KASSERT(SPPP_WLOCKED(sp));
 
+	ifp = >pp_if;
+
 	if (sp->pp_phase == phase)
 		return;
 
@@ -597,11 +621,8 @@ sppp_change_phase(struct sppp *sp, int p
 	else
 		if_link_state_change(ifp, LINK_STATE_DOWN);
 
-	if (debug)
-	{
-		log(LOG_INFO, "%s: phase %s\n", ifp->if_xname,
-			sppp_phase_name(sp->pp_phase));
-	}
+	SPPP_DLOG(sp, "phase %s\n",
+	sppp_phase_name(sp->pp_phase));
 }
 
 /*
@@ -619,7 +640,6 @@ sppp_input(struct ifnet *ifp, struct mbu
 	struct ifqueue *inq = NULL;
 	uint16_t protocol;
 	struct sppp *sp = (struct sppp *)ifp;
-	int debug = ifp->if_flags & IFF_DEBUG;
 	int isr = 0;
 
 	SPPP_LOCK(sp, RW_READER);
@@ -633,10 +653,8 @@ sppp_input(struct ifnet *ifp, struct mbu
 
 	if (m->m_pkthdr.len <= PPP_HEADER_LEN) {
 		/* Too small packet, drop it. */
-		if (debug)
-			log(LOG_DEBUG,
-			"%s: input packet is too small, %d bytes\n",
-			ifp->if_xname, m->m_pkthdr.len);
+		SPPP_DLOG(sp, "input packet is too small, "
+		"%d bytes\n", m->m_pkthdr.len);
 		goto drop;
 	}
 
@@ -658,21 +676,15 @@ sppp_input(struct ifnet *ifp, struct mbu
 		case CISCO_MULTICAST:
 		case CISCO_UNICAST:
 			/* Don't check the control field here (RFC 1547). */
-			if (debug)
-log(LOG_DEBUG,
-"%s: Cisco packet in PPP mode "
-"\n",
-ifp->if_xname,
-h->address, h->control, ntohs(h->protocol));
+			SPPP_DLOG(sp, "Cisco packet in PPP mode "
+			"\n",
+			h->address, h->control, ntohs(h->protocol));
 			goto drop;
 		default:/* Invalid PPP packet. */
 		  invalid:
-			if (debug)
-log(LOG_DEBUG,
-"%s: invalid input packet "
-"\n",
-ifp->if_xname,
-h->address, h->control, ntohs(h->protocol));
+			SPPP_DLOG(sp, "invalid input packet "
+			"\n",
+			h->address, h->control, ntohs(h->protocol));
 			goto drop;
 		}
 		protocol = ntohs(h->protocol);
@@ -692,11 +704,8 @@ sppp_input(struct ifnet *ifp, struct mbu
 		if_statinc(ifp, if_noproto);
 		goto drop;
 	default:
-		if (debug) {
-			log(LOG_DEBUG,
-			"%s: invalid input protocol "
-			"\n", ifp->if_xname, protocol);
-		}
+		SPPP_DLOG(sp, "invalid input protocol "
+		"\n", protocol);
 		goto reject_protocol;
 	case PPP_LCP:
 		SPPP_UNLOCK(sp);
@@ -720,9 +729,8 @@ sppp_input(struct ifnet *ifp, struct mbu
 #ifdef INET
 	case PPP_IPCP:
 		if (!ISSET(sp->pp_ncpflags, SPPP_NCP_IPCP)) {
-			log(LOG_INFO, "%s: reject IPCP packet "
-			"because IPCP is disabled\n",
-			ifp->if_xname);
+			SPPP_LOG(sp, 

CVS commit: src/sys/net

2021-05-31 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Tue Jun  1 05:04:06 UTC 2021

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

Log Message:
Send RTM_IFINFO when a network configuration protocol
is up or down


To generate a diff of this commit:
cvs rdiff -u -r1.252 -r1.253 src/sys/net/if_spppsubr.c

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

Modified files:

Index: src/sys/net/if_spppsubr.c
diff -u src/sys/net/if_spppsubr.c:1.252 src/sys/net/if_spppsubr.c:1.253
--- src/sys/net/if_spppsubr.c:1.252	Tue Jun  1 04:59:50 2021
+++ src/sys/net/if_spppsubr.c	Tue Jun  1 05:04:06 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppsubr.c,v 1.252 2021/06/01 04:59:50 yamaguchi Exp $	 */
+/*	$NetBSD: if_spppsubr.c,v 1.253 2021/06/01 05:04:06 yamaguchi Exp $	 */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.252 2021/06/01 04:59:50 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.253 2021/06/01 05:04:06 yamaguchi Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -417,6 +417,7 @@ static enum cp_rcr_type
 static void sppp_ipcp_confrej(struct sppp *, struct lcp_header *, int);
 static void sppp_ipcp_confnak(struct sppp *, struct lcp_header *, int);
 static void sppp_ipcp_tlu(struct sppp *);
+static void sppp_ipcp_tld(struct sppp *);
 static void sppp_ipcp_scr(struct sppp *);
 
 static void sppp_ipv6cp_init(struct sppp *);
@@ -427,6 +428,7 @@ static enum cp_rcr_type
 static void sppp_ipv6cp_confrej(struct sppp *, struct lcp_header *, int);
 static void sppp_ipv6cp_confnak(struct sppp *, struct lcp_header *, int);
 static void sppp_ipv6cp_tlu(struct sppp *);
+static void sppp_ipv6cp_tld(struct sppp *);
 static void sppp_ipv6cp_scr(struct sppp *);
 
 static void sppp_pap_input(struct sppp *, struct mbuf *);
@@ -504,7 +506,7 @@ static const struct cp ipcp = {
 	"ipcp",
 	sppp_up_event, sppp_down_event, sppp_ipcp_open,
 	sppp_ipcp_close, sppp_to_event,
-	sppp_ipcp_tlu, sppp_null, sppp_tls,
+	sppp_ipcp_tlu, sppp_ipcp_tld, sppp_tls,
 	sppp_tlf, sppp_ipcp_scr, sppp_screply,
 	sppp_ipcp_confreq, sppp_ipcp_confrej, sppp_ipcp_confnak,
 };
@@ -519,7 +521,7 @@ static const struct cp ipv6cp = {
 	"ipv6cp",
 	sppp_up_event, sppp_down_event, sppp_ipv6cp_open,
 	sppp_close_event, sppp_to_event,
-	sppp_ipv6cp_tlu, sppp_null, sppp_tls,
+	sppp_ipv6cp_tlu, sppp_ipv6cp_tld, sppp_tls,
 	sppp_tlf, sppp_ipv6cp_scr, sppp_screply,
 	sppp_ipv6cp_confreq, sppp_ipv6cp_confrej, sppp_ipv6cp_confnak,
 };
@@ -3936,8 +3938,9 @@ sppp_ipcp_tlu(struct sppp *sp)
 #ifdef INET
 	struct ifnet *ifp;
 
-	ifp = >pp_if;
 	KASSERT(SPPP_WLOCKED(sp));
+
+	ifp = >pp_if;
 	if ((sp->ipcp.flags & IPCP_MYADDR_DYN) &&
 	((sp->ipcp.flags & IPCP_MYADDR_SEEN) == 0)) {
 		log(LOG_WARNING, "%s: no IP address, closing IPCP\n",
@@ -3947,11 +3950,25 @@ sppp_ipcp_tlu(struct sppp *sp)
 	} else {
 		/* we are up. Set addresses and notify anyone interested */
 		sppp_set_ip_addrs(sp);
+		rt_ifmsg(ifp);
 	}
 #endif
 }
 
 static void
+sppp_ipcp_tld(struct sppp *sp)
+{
+#ifdef INET
+	struct ifnet *ifp;
+
+	KASSERT(SPPP_WLOCKED(sp));
+
+	ifp = >pp_if;
+	rt_ifmsg(ifp);
+#endif
+}
+
+static void
 sppp_ipcp_scr(struct sppp *sp)
 {
 	uint8_t opt[6 /* compression */ + 6 /* address */ + 12 /* dns addresses */];
@@ -4483,10 +4500,25 @@ end:
 static void
 sppp_ipv6cp_tlu(struct sppp *sp)
 {
+	struct ifnet *ifp;
 
 	KASSERT(SPPP_WLOCKED(sp));
+
+	ifp = >pp_if;
 	/* we are up - notify isdn daemon */
 	sppp_notify_con_wlocked(sp);
+	rt_ifmsg(ifp);
+}
+
+static void
+sppp_ipv6cp_tld(struct sppp *sp)
+{
+	struct ifnet *ifp;
+
+	KASSERT(SPPP_WLOCKED(sp));
+
+	ifp = >pp_if;
+	rt_ifmsg(ifp);
 }
 
 static void



CVS commit: src/sys/net

2021-05-31 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Tue Jun  1 04:59:50 UTC 2021

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

Log Message:
Drop the Open event of LCP to stop the interface
even a reconnection is scheduled

The queue for events in if_spppsubr.c is not possible
to enqueue the same event. So, The close event caused
while a close event and open event are enqueued for
reconnection is not possible to stop interface.
To solve this issue, The open event after
"ifconfig pppoe? down" is dropped.


To generate a diff of this commit:
cvs rdiff -u -r1.251 -r1.252 src/sys/net/if_spppsubr.c
cvs rdiff -u -r1.41 -r1.42 src/sys/net/if_spppvar.h

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

Modified files:

Index: src/sys/net/if_spppsubr.c
diff -u src/sys/net/if_spppsubr.c:1.251 src/sys/net/if_spppsubr.c:1.252
--- src/sys/net/if_spppsubr.c:1.251	Tue Jun  1 04:55:55 2021
+++ src/sys/net/if_spppsubr.c	Tue Jun  1 04:59:50 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppsubr.c,v 1.251 2021/06/01 04:55:55 yamaguchi Exp $	 */
+/*	$NetBSD: if_spppsubr.c,v 1.252 2021/06/01 04:59:50 yamaguchi Exp $	 */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.251 2021/06/01 04:55:55 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.252 2021/06/01 04:59:50 yamaguchi Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -1256,6 +1256,12 @@ sppp_ioctl(struct ifnet *ifp, u_long cmd
 			ifp->if_flags &= ~IFF_AUTO;
 		}
 
+		if (ifp->if_flags & IFF_UP) {
+			sp->pp_flags |= PP_ADMIN_UP;
+		} else {
+			sp->pp_flags &= ~PP_ADMIN_UP;
+		}
+
 		if (going_up || going_down) {
 			sp->lcp.reestablish = false;
 			sppp_wq_add(sp->wq_cp, >scp[IDX_LCP].work_close);
@@ -2571,6 +2577,10 @@ sppp_lcp_open(struct sppp *sp, void *xcp
 	sp->lcp.reestablish = false;
 	sp->scp[IDX_LCP].fail_counter = 0;
 
+	/* the interface was down while waiting for reconnection */
+	if ((sp->pp_flags & PP_ADMIN_UP) == 0)
+		return;
+
 	if (sp->pp_if.if_mtu < PP_MTU) {
 		sp->lcp.mru = sp->pp_if.if_mtu;
 		SET(sp->lcp.opts, SPPP_LCP_OPT_MRU);

Index: src/sys/net/if_spppvar.h
diff -u src/sys/net/if_spppvar.h:1.41 src/sys/net/if_spppvar.h:1.42
--- src/sys/net/if_spppvar.h:1.41	Tue Jun  1 04:55:55 2021
+++ src/sys/net/if_spppvar.h	Tue Jun  1 04:59:50 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppvar.h,v 1.41 2021/06/01 04:55:55 yamaguchi Exp $	*/
+/*	$NetBSD: if_spppvar.h,v 1.42 2021/06/01 04:59:50 yamaguchi Exp $	*/
 
 #ifndef _NET_IF_SPPPVAR_H_
 #define _NET_IF_SPPPVAR_H_
@@ -214,6 +214,7 @@ struct sppp {
 #define PP_LOOPBACK		0x40	/* in line loopback mode */
 #define PP_LOOPBACK_IFDOWN	0x80	/* if_down() when loopback detected */
 #define PP_KEEPALIVE_IFDOWN	0x100	/* if_down() when no ECHO_REPLY received */
+#define PP_ADMIN_UP		0x200	/* the interface is up */
 
 
 #define PP_MTU  1500/* default/minimal MRU */



CVS commit: src/sys/net

2021-05-31 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Tue Jun  1 04:55:56 UTC 2021

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

Log Message:
remove PP_CISCO that was used in obsoleted drivers e.g. lmc(4)


To generate a diff of this commit:
cvs rdiff -u -r1.250 -r1.251 src/sys/net/if_spppsubr.c
cvs rdiff -u -r1.40 -r1.41 src/sys/net/if_spppvar.h

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

Modified files:

Index: src/sys/net/if_spppsubr.c
diff -u src/sys/net/if_spppsubr.c:1.250 src/sys/net/if_spppsubr.c:1.251
--- src/sys/net/if_spppsubr.c:1.250	Tue Jun  1 04:45:22 2021
+++ src/sys/net/if_spppsubr.c	Tue Jun  1 04:55:55 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppsubr.c,v 1.250 2021/06/01 04:45:22 yamaguchi Exp $	 */
+/*	$NetBSD: if_spppsubr.c,v 1.251 2021/06/01 04:55:55 yamaguchi Exp $	 */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.250 2021/06/01 04:45:22 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.251 2021/06/01 04:55:55 yamaguchi Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -346,9 +346,6 @@ static u_short interactive_ports[8] = {
 static int sppp_output(struct ifnet *, struct mbuf *,
 		   const struct sockaddr *, const struct rtentry *);
 
-static void sppp_cisco_send(struct sppp *, int, int32_t, int32_t);
-static void sppp_cisco_input(struct sppp *, struct mbuf *);
-
 static void sppp_cp_init(const struct cp *, struct sppp *);
 static void sppp_cp_fini(const struct cp *, struct sppp *);
 static void sppp_cp_input(const struct cp *, struct sppp *,
@@ -655,49 +652,17 @@ sppp_input(struct ifnet *ifp, struct mbu
 		case PPP_ALLSTATIONS:
 			if (h->control != PPP_UI)
 goto invalid;
-			if (sp->pp_flags & PP_CISCO) {
-if (debug)
-	log(LOG_DEBUG,
-	"%s: PPP packet in Cisco mode "
-	"\n",
-	ifp->if_xname,
-	h->address, h->control, ntohs(h->protocol));
-goto drop;
-			}
 			break;
 		case CISCO_MULTICAST:
 		case CISCO_UNICAST:
 			/* Don't check the control field here (RFC 1547). */
-			if (! (sp->pp_flags & PP_CISCO)) {
-if (debug)
-	log(LOG_DEBUG,
-	"%s: Cisco packet in PPP mode "
-	"\n",
-	ifp->if_xname,
-	h->address, h->control, ntohs(h->protocol));
-goto drop;
-			}
-			switch (ntohs(h->protocol)) {
-			default:
-if_statinc(ifp, if_noproto);
-goto invalid;
-			case CISCO_KEEPALIVE:
-SPPP_UNLOCK(sp);
-sppp_cisco_input((struct sppp *) ifp, m);
-m_freem(m);
-return;
-#ifdef INET
-			case ETHERTYPE_IP:
-pktq = ip_pktq;
-break;
-#endif
-#ifdef INET6
-			case ETHERTYPE_IPV6:
-pktq = ip6_pktq;
-break;
-#endif
-			}
-			goto queue_pkt;
+			if (debug)
+log(LOG_DEBUG,
+"%s: Cisco packet in PPP mode "
+"\n",
+ifp->if_xname,
+h->address, h->control, ntohs(h->protocol));
+			goto drop;
 		default:/* Invalid PPP packet. */
 		  invalid:
 			if (debug)
@@ -799,7 +764,6 @@ sppp_input(struct ifnet *ifp, struct mbu
 #endif
 	}
 
-queue_pkt:
 	if ((ifp->if_flags & IFF_UP) == 0 || (!inq && !pktq)) {
 		goto drop;
 	}
@@ -979,74 +943,61 @@ sppp_output(struct ifnet *ifp, struct mb
 		 * (albeit due to the implementation it's always enough)
 		 */
 		h = mtod(m, struct ppp_header *);
-		if (sp->pp_flags & PP_CISCO) {
-			h->address = CISCO_UNICAST;/* unicast address */
-			h->control = 0;
-		} else {
-			h->address = PPP_ALLSTATIONS;/* broadcast address */
-			h->control = PPP_UI; /* Unnumbered Info */
-		}
+		h->address = PPP_ALLSTATIONS;/* broadcast address */
+		h->control = PPP_UI; /* Unnumbered Info */
 	}
 
 	switch (dst->sa_family) {
 #ifdef INET
 	case AF_INET:   /* Internet Protocol */
-		if (sp->pp_flags & PP_CISCO)
-			protocol = htons(ETHERTYPE_IP);
-		else {
-			/*
-			 * Don't choke with an ENETDOWN early.  It's
-			 * possible that we just started dialing out,
-			 * so don't drop the packet immediately.  If
-			 * we notice that we run out of buffer space
-			 * below, we will however remember that we are
-			 * not ready to carry IP packets, and return
-			 * ENETDOWN, as opposed to ENOBUFS.
-			 */
-			protocol = htons(PPP_IP);
-			if (sp->scp[IDX_IPCP].state != STATE_OPENED) {
-if (ifp->if_flags & IFF_AUTO) {
-	error = ENETDOWN;
-} else {
-	IF_DROP(>if_snd);
-	SPPP_UNLOCK(sp);
-	splx(s);
-
-	m_freem(m);
-	if_statinc(ifp, if_oerrors);
-	return (ENETDOWN);
-}
+		/*
+		 * Don't choke with an ENETDOWN early.  It's
+		 * possible that we just started dialing out,
+		 * so don't drop the packet immediately.  If
+		 * we notice that we run out of buffer space
+		 * below, we will however remember that we are
+		 * not ready to carry IP packets, and return
+		 * ENETDOWN, as opposed to ENOBUFS.
+		 */
+		protocol = 

CVS commit: src/sys/net

2021-05-31 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Tue Jun  1 04:45:22 UTC 2021

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

Log Message:
Remove open event on tlf of PAP/CHAP when retry of them is over
to prevent that LCP stops at Starting state.

And also remove retry counter check on tls of LCP because of
unnecessary.


To generate a diff of this commit:
cvs rdiff -u -r1.249 -r1.250 src/sys/net/if_spppsubr.c

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

Modified files:

Index: src/sys/net/if_spppsubr.c
diff -u src/sys/net/if_spppsubr.c:1.249 src/sys/net/if_spppsubr.c:1.250
--- src/sys/net/if_spppsubr.c:1.249	Tue Jun  1 04:19:57 2021
+++ src/sys/net/if_spppsubr.c	Tue Jun  1 04:45:22 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppsubr.c,v 1.249 2021/06/01 04:19:57 yamaguchi Exp $	 */
+/*	$NetBSD: if_spppsubr.c,v 1.250 2021/06/01 04:45:22 yamaguchi Exp $	 */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.249 2021/06/01 04:19:57 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.250 2021/06/01 04:45:22 yamaguchi Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -3477,16 +3477,6 @@ sppp_lcp_tls(const struct cp *cp __unuse
 
 	KASSERT(SPPP_WLOCKED(sp));
 
-	if (sp->pp_max_auth_fail != 0 && sp->pp_auth_failures >= sp->pp_max_auth_fail) {
-		printf("%s: authentication failed %d times, not retrying again\n",
-		sp->pp_if.if_xname, sp->pp_auth_failures);
-
-		SPPP_UNLOCK(sp);
-		if_down(>pp_if);
-		SPPP_LOCK(sp, RW_WRITER);
-		return;
-	}
-
 	sppp_change_phase(sp, SPPP_PHASE_ESTABLISH);
 
 	/* Notify lower layer if desired. */
@@ -3597,7 +3587,18 @@ sppp_lcp_check_and_close(struct sppp *sp
 		return;
 
 	sppp_wq_add(sp->wq_cp, >scp[IDX_LCP].work_close);
-	sppp_wq_add(sp->wq_cp, >scp[IDX_LCP].work_open);
+
+	if (sp->pp_max_auth_fail != 0 &&
+	sp->pp_auth_failures >= sp->pp_max_auth_fail) {
+		printf("%s: authentication failed %d times, "
+		"not retrying again\n",
+		sp->pp_if.if_xname, sp->pp_auth_failures);
+
+		sppp_wq_add(sp->wq_cp, >work_ifdown);
+		sp->pp_if.if_flags &= ~IFF_RUNNING;
+	} else {
+		sppp_wq_add(sp->wq_cp, >scp[IDX_LCP].work_open);
+	}
 }
 
 /*



CVS commit: src/sys/net

2021-05-31 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Tue Jun  1 04:19:57 UTC 2021

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

Log Message:
Do not if_down() when a down event of the lower layer of LCP is happened
since the layer try to reconnect.


To generate a diff of this commit:
cvs rdiff -u -r1.248 -r1.249 src/sys/net/if_spppsubr.c

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

Modified files:

Index: src/sys/net/if_spppsubr.c
diff -u src/sys/net/if_spppsubr.c:1.248 src/sys/net/if_spppsubr.c:1.249
--- src/sys/net/if_spppsubr.c:1.248	Tue Jun  1 03:51:33 2021
+++ src/sys/net/if_spppsubr.c	Tue Jun  1 04:19:57 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppsubr.c,v 1.248 2021/06/01 03:51:33 yamaguchi Exp $	 */
+/*	$NetBSD: if_spppsubr.c,v 1.249 2021/06/01 04:19:57 yamaguchi Exp $	 */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.248 2021/06/01 03:51:33 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.249 2021/06/01 04:19:57 yamaguchi Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -2746,29 +2746,16 @@ sppp_lcp_down(struct sppp *sp, void *xcp
 		sp->lcp.tlf_sent = false;
 	}
 
-	/*
-	 * If this is neither a dial-on-demand nor a passive
-	 * interface, simulate an ``ifconfig down'' action, so the
-	 * administrator can force a redial by another ``ifconfig
-	 * up''.  XXX For leased line operation, should we immediately
-	 * try to reopen the connection here?
-	 */
-	if ((ifp->if_flags & (IFF_AUTO | IFF_PASSIVE)) == 0) {
-		if (debug)
-			log(LOG_INFO,
-			"%s: Down event (carrier loss), taking interface down.\n",
-			ifp->if_xname);
-		SPPP_UNLOCK(sp);
-		if_down(ifp);
-		SPPP_LOCK(sp, RW_WRITER);
+	if (debug) {
+		log(LOG_DEBUG,
+		"%s: Down event (carrier loss)\n",
+		ifp->if_xname);
+	}
 
+	if ((ifp->if_flags & (IFF_AUTO | IFF_PASSIVE)) == 0) {
 		if (sp->lcp.reestablish)
 			sppp_wq_add(sp->wq_cp, >scp[IDX_LCP].work_open);
 	} else {
-		if (debug)
-			log(LOG_DEBUG,
-			"%s: Down event (carrier loss)\n",
-			ifp->if_xname);
 
 		sp->pp_flags &= ~PP_CALLIN;
 		if (sp->scp[pidx].state != STATE_INITIAL)



CVS commit: src/sys/net

2021-05-31 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Tue Jun  1 03:27:23 UTC 2021

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

Log Message:
restart LCP when loopback packets are detected

In if_spppsubr.c down and up do not mean that LCP is stopping
or running, but mean that the lower layer of LCP is up or down.
And, restarting of LCP is had to use close event and open event.


To generate a diff of this commit:
cvs rdiff -u -r1.246 -r1.247 src/sys/net/if_spppsubr.c
cvs rdiff -u -r1.38 -r1.39 src/sys/net/if_spppvar.h

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

Modified files:

Index: src/sys/net/if_spppsubr.c
diff -u src/sys/net/if_spppsubr.c:1.246 src/sys/net/if_spppsubr.c:1.247
--- src/sys/net/if_spppsubr.c:1.246	Wed May 19 02:14:19 2021
+++ src/sys/net/if_spppsubr.c	Tue Jun  1 03:27:23 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppsubr.c,v 1.246 2021/05/19 02:14:19 yamaguchi Exp $	 */
+/*	$NetBSD: if_spppsubr.c,v 1.247 2021/06/01 03:27:23 yamaguchi Exp $	 */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.246 2021/05/19 02:14:19 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.247 2021/06/01 03:27:23 yamaguchi Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -1480,15 +1480,18 @@ sppp_cisco_input(struct sppp *sp, struct
 printf ("%s: loopback\n",
 	ifp->if_xname);
 sp->pp_loopcnt = 0;
-if (ifp->if_flags & IFF_UP) {
-	SPPP_UNLOCK(sp);
-	if_down(ifp);
-	SPPP_LOCK(sp, RW_WRITER);
 
-	IF_PURGE(>pp_cpq);
-}
+sp->pp_flags |= PP_LOOPBACK;
+sppp_wq_add(sp->wq_cp,
+>work_ifdown);
+
+sppp_wq_add(sp->wq_cp,
+>scp[IDX_LCP].work_close);
+sppp_wq_add(sp->wq_cp,
+>scp[IDX_LCP].work_open);
+			} else {
+++sp->pp_loopcnt;
 			}
-			++sp->pp_loopcnt;
 
 			/* Generate new local sequence number */
 			sp->scp[IDX_LCP].seq = cprng_fast32();
@@ -1500,6 +1503,7 @@ sppp_cisco_input(struct sppp *sp, struct
 			SPPP_UNLOCK(sp);
 			if_up(ifp);
 			SPPP_LOCK(sp, RW_WRITER);
+			sp->pp_flags &= ~PP_LOOPBACK;
 		}
 		break;
 	case CISCO_ADDR_REQ:
@@ -1946,20 +1950,16 @@ sppp_cp_input(const struct cp *cp, struc
 		if (ntohl(u32) == sp->lcp.magic) {
 			/* Line loopback mode detected. */
 			printf("%s: loopback\n", ifp->if_xname);
-			/*
-			 * There is no change for items of sp->scp[cp->protoidx]
-			 * while if_down() even without SPPP_LOCK
-			 */
-			SPPP_UNLOCK(sp);
-			if_down(ifp);
-			SPPP_LOCK(sp, RW_WRITER);
 
-			IF_PURGE(>pp_cpq);
+			sp->pp_flags |= PP_LOOPBACK;
+			sppp_wq_add(sp->wq_cp,
+			>work_ifdown);
 
 			/* Shut down the PPP link. */
-			/* XXX */
-			sppp_wq_add(sp->wq_cp, >scp[IDX_LCP].work_down);
-			sppp_wq_add(sp->wq_cp, >scp[IDX_LCP].work_up);
+			sppp_wq_add(sp->wq_cp,
+			>scp[IDX_LCP].work_close);
+			sppp_wq_add(sp->wq_cp,
+			>scp[IDX_LCP].work_open);
 			break;
 		}
 		u32 = htonl(sp->lcp.magic);
@@ -3000,21 +3000,20 @@ sppp_lcp_confreq(struct sppp *sp, struct
 printf ("%s: loopback\n",
 	ifp->if_xname);
 sp->pp_loopcnt = 0;
-if (ifp->if_flags & IFF_UP) {
-	SPPP_UNLOCK(sp);
-	if_down(ifp);
-	SPPP_LOCK(sp, RW_WRITER);
 
-	IF_PURGE(>pp_cpq);
-	/* XXX ? */
-	sppp_wq_add(sp->wq_cp,
-	>scp[IDX_LCP].work_down);
-	sppp_wq_add(sp->wq_cp,
-	>scp[IDX_LCP].work_up);
-}
-			} else if (debug)
-addlog(" [glitch]");
-			++sp->pp_loopcnt;
+sp->pp_flags |= PP_LOOPBACK;
+sppp_wq_add(sp->wq_cp,
+>work_ifdown);
+
+sppp_wq_add(sp->wq_cp,
+>scp[IDX_LCP].work_close);
+sppp_wq_add(sp->wq_cp,
+>scp[IDX_LCP].work_open);
+			} else {
+if (debug)
+	addlog(" [glitch]");
+++sp->pp_loopcnt;
+			}
 			/*
 			 * We negate our magic here, and NAK it.  If
 			 * we see it later in an NAK packet, we
@@ -3351,22 +3350,34 @@ sppp_lcp_tlu(struct sppp *sp)
 {
 	STDDCL;
 	int i;
+	bool going_up;
 
 	KASSERT(SPPP_WLOCKED(sp));
 
 	/* unlock for IFNET_LOCK and if_up() */
 	SPPP_UNLOCK(sp);
 
-	/* XXX ? */
 	if (! (ifp->if_flags & IFF_UP) &&
 	(ifp->if_flags & IFF_RUNNING)) {
 		/* Coming out of loopback mode. */
+		going_up = true;
 		if_up(ifp);
+	} else {
+		going_up = false;
 	}
 
 	IFNET_LOCK(ifp);
 	SPPP_LOCK(sp, RW_WRITER);
 
+	if (going_up) {
+		if ((sp->pp_flags & PP_LOOPBACK) == 0) {
+			log(LOG_DEBUG, "%s: interface is going up, "
+			"but no loopback packet is deteted\n",
+			ifp->if_xname);
+		}
+		sp->pp_flags &= ~PP_LOOPBACK;
+	}
+
 	if (ifp->if_mtu > sp->lcp.their_mru) {
 		sp->pp_saved_mtu = ifp->if_mtu;
 		ifp->if_mtu = sp->lcp.their_mru;

Index: src/sys/net/if_spppvar.h
diff -u src/sys/net/if_spppvar.h:1.38 src/sys/net/if_spppvar.h:1.39
--- src/sys/net/if_spppvar.h:1.38	Fri May 14 08:41:25 2021
+++ src/sys/net/if_spppvar.h	Tue Jun  1 03:27:23 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppvar.h,v 

CVS commit: src/sys/net

2021-05-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu May 27 13:40:38 UTC 2021

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

Log Message:
Simplify; no need to special case the small buffer zero src_len.
lla_snprintf1 never returns -1.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/net/dl_print.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/dl_print.c
diff -u src/sys/net/dl_print.c:1.7 src/sys/net/dl_print.c:1.8
--- src/sys/net/dl_print.c:1.7	Thu May 27 09:36:33 2021
+++ src/sys/net/dl_print.c	Thu May 27 09:40:38 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: dl_print.c,v 1.7 2021/05/27 13:36:33 christos Exp $	*/
+/*	$NetBSD: dl_print.c,v 1.8 2021/05/27 13:40:38 christos Exp $	*/
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -29,10 +29,10 @@
 #include 
 
 #ifdef _KERNEL
-__KERNEL_RCSID(0, "$NetBSD: dl_print.c,v 1.7 2021/05/27 13:36:33 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dl_print.c,v 1.8 2021/05/27 13:40:38 christos Exp $");
 #include 
 #else
-__RCSID("$NetBSD: dl_print.c,v 1.7 2021/05/27 13:36:33 christos Exp $");
+__RCSID("$NetBSD: dl_print.c,v 1.8 2021/05/27 13:40:38 christos Exp $");
 #include 
 static const char hexdigits[] = "0123456789abcdef";
 #endif
@@ -44,12 +44,6 @@ lla_snprintf1(char *dst, size_t dst_len,
 	char *dp;
 	const uint8_t *sp, *ep;
 
-	if (src_len == 0 || dst_len < 3) {
-		if (dst_len != 0)
-			dst[0] = '\0';
-		return src_len ? (int)(src_len * 3) - 1 : 0;
-	}
-
 	dp = dst;
 	sp = (const uint8_t *)src;
 	ep = sp + src_len;
@@ -64,16 +58,16 @@ lla_snprintf1(char *dst, size_t dst_len,
 			break;
 		*dp++ = ':';
 	}
-	*--dp = '\0';
+	if (dp != dst)
+		*--dp = '\0';
 
-	return (int)(src_len * 3) - 1;
+	return src_len ? (int)(src_len * 3) - 1 : 0;
 }
 
 char *
 lla_snprintf(char *dst, size_t dst_len, const void *src, size_t src_len)
 {
-	if (lla_snprintf1(dst, dst_len, src, src_len) == -1)
-		return NULL;
+	(void)lla_snprintf1(dst, dst_len, src, src_len);
 	return dst;
 }
 



CVS commit: src/sys/net

2021-05-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu May 27 13:36:33 UTC 2021

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

Log Message:
Don't use the stack, print to the buffer directly (this was one of the
biggest stack users).


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/net/dl_print.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/dl_print.c
diff -u src/sys/net/dl_print.c:1.6 src/sys/net/dl_print.c:1.7
--- src/sys/net/dl_print.c:1.6	Tue Apr 30 16:56:32 2019
+++ src/sys/net/dl_print.c	Thu May 27 09:36:33 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: dl_print.c,v 1.6 2019/04/30 20:56:32 kre Exp $	*/
+/*	$NetBSD: dl_print.c,v 1.7 2021/05/27 13:36:33 christos Exp $	*/
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -29,17 +29,17 @@
 #include 
 
 #ifdef _KERNEL
-__KERNEL_RCSID(0, "$NetBSD: dl_print.c,v 1.6 2019/04/30 20:56:32 kre Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dl_print.c,v 1.7 2021/05/27 13:36:33 christos Exp $");
 #include 
 #else
-__RCSID("$NetBSD: dl_print.c,v 1.6 2019/04/30 20:56:32 kre Exp $");
+__RCSID("$NetBSD: dl_print.c,v 1.7 2021/05/27 13:36:33 christos Exp $");
 #include 
 static const char hexdigits[] = "0123456789abcdef";
 #endif
 #include 
 
-char *
-lla_snprintf(char *dst, size_t dst_len, const void *src, size_t src_len)
+static int
+lla_snprintf1(char *dst, size_t dst_len, const void *src, size_t src_len)
 {
 	char *dp;
 	const uint8_t *sp, *ep;
@@ -47,44 +47,72 @@ lla_snprintf(char *dst, size_t dst_len, 
 	if (src_len == 0 || dst_len < 3) {
 		if (dst_len != 0)
 			dst[0] = '\0';
-		return NULL;
+		return src_len ? (int)(src_len * 3) - 1 : 0;
 	}
 
 	dp = dst;
 	sp = (const uint8_t *)src;
 	ep = sp + src_len;
 	while (sp < ep) {
-		if (dst_len < 3)
+		if (dst_len-- == 0)
 			break;
-		dst_len -= 3;
 		*dp++ = hexdigits[(*sp) >> 4];
+		if (dst_len-- == 0)
+			break;
 		*dp++ = hexdigits[(*sp++) & 0xf];
+		if (dst_len-- == 0)
+			break;
 		*dp++ = ':';
 	}
-	*--dp = 0;
+	*--dp = '\0';
+
+	return (int)(src_len * 3) - 1;
+}
 
+char *
+lla_snprintf(char *dst, size_t dst_len, const void *src, size_t src_len)
+{
+	if (lla_snprintf1(dst, dst_len, src, src_len) == -1)
+		return NULL;
 	return dst;
 }
 
+#define clip(a, b) ((a) > (size_t)(b) ? (a) - (size_t)(b) : 0)
+
 int
 dl_print(char *buf, size_t len, const struct dl_addr *dl)
 {
-	char abuf[256 * 3];
+	int l = snprintf(buf, len, "%.*s/%hhu#",
+	(int)dl->dl_nlen, dl->dl_data, dl->dl_type);
+	if (l == -1)
+		return l;
+	int ll = lla_snprintf1(buf + l, clip(len, l),
+	dl->dl_data + dl->dl_nlen, dl->dl_alen);
+	if (ll == -1)
+		return ll;
 
-	lla_snprintf(abuf, sizeof(abuf), dl->dl_data+dl->dl_nlen, dl->dl_alen);
-	return snprintf(buf, len, "%.*s/%hhu#%s",
-	(int)dl->dl_nlen, dl->dl_data, dl->dl_type, abuf);
+	return ll + l;
 }
 
 int
 sdl_print(char *buf, size_t len, const void *v)
 {
 	const struct sockaddr_dl *sdl = v;
-	char abuf[LINK_ADDRSTRLEN];
 
 	if (sdl->sdl_slen == 0 && sdl->sdl_nlen == 0 && sdl->sdl_alen == 0)
 		return snprintf(buf, len, "link#%hu", sdl->sdl_index);
 
-	dl_print(abuf, sizeof(abuf), >sdl_addr);
-	return snprintf(buf, len, "[%s]:%hu", abuf, sdl->sdl_index);
+	if (len > 0) {
+		buf[0] = '[';
+		len--;
+	}
+	int l = dl_print(buf + 1, len, >sdl_addr);
+	if (l == -1)
+		return l;
+	l++;
+	len++;
+	int ll = snprintf(buf + l, clip(len, l), "]:%hu", sdl->sdl_index);
+	if (ll == -1)
+		return ll;
+	return ll + l;
 }



CVS commit: src/sys/net/lagg

2021-05-24 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Mon May 24 13:42:58 UTC 2021

Modified Files:
src/sys/net/lagg: if_lagg.c

Log Message:
Move __KERNEL_RCSID() to the traditional location.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/net/lagg/if_lagg.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/lagg/if_lagg.c
diff -u src/sys/net/lagg/if_lagg.c:1.3 src/sys/net/lagg/if_lagg.c:1.4
--- src/sys/net/lagg/if_lagg.c:1.3	Mon May 24 06:08:28 2021
+++ src/sys/net/lagg/if_lagg.c	Mon May 24 13:42:58 2021
@@ -1,7 +1,4 @@
-/*	$NetBSD: if_lagg.c,v 1.3 2021/05/24 06:08:28 yamaguchi Exp $	*/
-
-#include 
-__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.3 2021/05/24 06:08:28 yamaguchi Exp $");
+/*	$NetBSD: if_lagg.c,v 1.4 2021/05/24 13:42:58 thorpej Exp $	*/
 
 /*
  * Copyright (c) 2005, 2006 Reyk Floeter 
@@ -22,6 +19,9 @@ __KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
+#include 
+__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.4 2021/05/24 13:42:58 thorpej Exp $");
+
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
 #include "opt_lagg.h"



CVS commit: src/sys/net/lagg

2021-05-24 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Mon May 24 13:43:21 UTC 2021

Modified Files:
src/sys/net/lagg: if_laggproto.c

Log Message:
Remove leading blank line.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/net/lagg/if_laggproto.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/lagg/if_laggproto.c
diff -u src/sys/net/lagg/if_laggproto.c:1.1 src/sys/net/lagg/if_laggproto.c:1.2
--- src/sys/net/lagg/if_laggproto.c:1.1	Mon May 17 04:07:43 2021
+++ src/sys/net/lagg/if_laggproto.c	Mon May 24 13:43:21 2021
@@ -1,5 +1,4 @@
-
-/*	$NetBSD: if_laggproto.c,v 1.1 2021/05/17 04:07:43 yamaguchi Exp $	*/
+/*	$NetBSD: if_laggproto.c,v 1.2 2021/05/24 13:43:21 thorpej Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-NetBSD
@@ -30,7 +29,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_laggproto.c,v 1.1 2021/05/17 04:07:43 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_laggproto.c,v 1.2 2021/05/24 13:43:21 thorpej Exp $");
 
 #include 
 #include 



CVS commit: src/sys/net/lagg

2021-05-24 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Mon May 24 06:24:20 UTC 2021

Modified Files:
src/sys/net/lagg: if_laggproto.h

Log Message:
Added missing copyright and license notice

pointed out by thorpej@n.o., Thanks.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/net/lagg/if_laggproto.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/lagg/if_laggproto.h
diff -u src/sys/net/lagg/if_laggproto.h:1.2 src/sys/net/lagg/if_laggproto.h:1.3
--- src/sys/net/lagg/if_laggproto.h:1.2	Wed May 19 06:13:08 2021
+++ src/sys/net/lagg/if_laggproto.h	Mon May 24 06:24:20 2021
@@ -1,4 +1,30 @@
-/*	$NetBSD: if_laggproto.h,v 1.2 2021/05/19 06:13:08 rillig Exp $	*/
+/*	$NetBSD: if_laggproto.h,v 1.3 2021/05/24 06:24:20 yamaguchi Exp $	*/
+
+/*
+ * Copyright (c) 2021 Internet Initiative Japan Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
 
 #ifndef	_NET_LAGG_IF_LAGGPROTO_H_
 #define _NET_LAGG_IF_LAGGPROTO_H_



CVS commit: src/sys/net/lagg

2021-05-24 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Mon May 24 06:08:29 UTC 2021

Modified Files:
src/sys/net/lagg: if_lagg.c if_lagg.h if_lagg_lacp.h if_laggvar.h

Log Message:
Added missing copyright and license notice

pointed out by thorpej@n.o., Thanks.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/net/lagg/if_lagg.c
cvs rdiff -u -r1.1 -r1.2 src/sys/net/lagg/if_lagg.h \
src/sys/net/lagg/if_lagg_lacp.h src/sys/net/lagg/if_laggvar.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/lagg/if_lagg.c
diff -u src/sys/net/lagg/if_lagg.c:1.2 src/sys/net/lagg/if_lagg.c:1.3
--- src/sys/net/lagg/if_lagg.c:1.2	Wed May 19 10:20:50 2021
+++ src/sys/net/lagg/if_lagg.c	Mon May 24 06:08:28 2021
@@ -1,7 +1,26 @@
-/*	$NetBSD: if_lagg.c,v 1.2 2021/05/19 10:20:50 rillig Exp $	*/
+/*	$NetBSD: if_lagg.c,v 1.3 2021/05/24 06:08:28 yamaguchi Exp $	*/
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.2 2021/05/19 10:20:50 rillig Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.3 2021/05/24 06:08:28 yamaguchi Exp $");
+
+/*
+ * Copyright (c) 2005, 2006 Reyk Floeter 
+ * Copyright (c) 2007 Andrew Thompson 
+ * Copyright (c) 2014, 2016 Marcelo Araujo 
+ * Copyright (c) 2021, Internet Initiative Japan Inc.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"

Index: src/sys/net/lagg/if_lagg.h
diff -u src/sys/net/lagg/if_lagg.h:1.1 src/sys/net/lagg/if_lagg.h:1.2
--- src/sys/net/lagg/if_lagg.h:1.1	Mon May 17 04:07:43 2021
+++ src/sys/net/lagg/if_lagg.h	Mon May 24 06:08:28 2021
@@ -1,4 +1,48 @@
-/*	$NetBSD: if_lagg.h,v 1.1 2021/05/17 04:07:43 yamaguchi Exp $	*/
+/*	$NetBSD: if_lagg.h,v 1.2 2021/05/24 06:08:28 yamaguchi Exp $	*/
+
+/*
+ * Copyright (c) 2005, 2006 Reyk Floeter 
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * $FreeBSD$
+ */
+
+/*
+ * Copyright (c) 2021 Internet Initiative Japan Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
 
 #ifndef _NET_LAGG_IF_LAGG_H_
 #define _NET_LAGG_IF_LAGG_H_
Index: src/sys/net/lagg/if_lagg_lacp.h
diff -u src/sys/net/lagg/if_lagg_lacp.h:1.1 src/sys/net/lagg/if_lagg_lacp.h:1.2
--- src/sys/net/lagg/if_lagg_lacp.h:1.1	Mon May 17 04:07:43 2021

CVS commit: src/sys/net/lagg

2021-05-19 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed May 19 10:20:50 UTC 2021

Modified Files:
src/sys/net/lagg: if_lagg.c

Log Message:
if_lagg: fix format string incompatibility

In struct ifnet, the member if_mtu has type uint64_t, which differs from
struct ifreq, where the member ifru_mtu has type int.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/net/lagg/if_lagg.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/lagg/if_lagg.c
diff -u src/sys/net/lagg/if_lagg.c:1.1 src/sys/net/lagg/if_lagg.c:1.2
--- src/sys/net/lagg/if_lagg.c:1.1	Mon May 17 04:07:43 2021
+++ src/sys/net/lagg/if_lagg.c	Wed May 19 10:20:50 2021
@@ -1,7 +1,7 @@
-/*	$NetBSD: if_lagg.c,v 1.1 2021/05/17 04:07:43 yamaguchi Exp $	*/
+/*	$NetBSD: if_lagg.c,v 1.2 2021/05/19 10:20:50 rillig Exp $	*/
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.1 2021/05/17 04:07:43 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.2 2021/05/19 10:20:50 rillig Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -689,7 +689,8 @@ lagg_ioctl(struct ifnet *ifp, u_long cmd
 			if (error != 0) {
 lagg_log(sc, LOG_ERR,
 "failed to change MTU to %d on port %s, "
-"reverting all ports to original MTU(%d)\n",
+"reverting all ports to original "
+"MTU(%" PRIu64 ")\n",
 ifr->ifr_mtu, lp->lp_ifp->if_xname,
 ifp->if_mtu);
 break;



CVS commit: src/sys/net/lagg

2021-05-19 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed May 19 06:13:08 UTC 2021

Modified Files:
src/sys/net/lagg: if_laggproto.h

Log Message:
if_lagg: fix Clang build

Clang is stricter than GCC when it comes to nonliteral format strings.

sys/net/lagg/if_lagg.c:2372:12: error:
format string is not a string literal [-Werror,-Wformat-nonliteral]


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/net/lagg/if_laggproto.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/lagg/if_laggproto.h
diff -u src/sys/net/lagg/if_laggproto.h:1.1 src/sys/net/lagg/if_laggproto.h:1.2
--- src/sys/net/lagg/if_laggproto.h:1.1	Mon May 17 04:07:43 2021
+++ src/sys/net/lagg/if_laggproto.h	Wed May 19 06:13:08 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_laggproto.h,v 1.1 2021/05/17 04:07:43 yamaguchi Exp $	*/
+/*	$NetBSD: if_laggproto.h,v 1.2 2021/05/19 06:13:08 rillig Exp $	*/
 
 #ifndef	_NET_LAGG_IF_LAGGPROTO_H_
 #define _NET_LAGG_IF_LAGGPROTO_H_
@@ -226,7 +226,8 @@ lagg_portactive(struct lagg_port *lp)
 	return false;
 }
 
-void		lagg_log(struct lagg_softc *, int, const char *, ...);
+void		lagg_log(struct lagg_softc *, int, const char *, ...)
+		__printflike(3, 4);
 void		lagg_port_getref(struct lagg_port *, struct psref *);
 void		lagg_port_putref(struct lagg_port *, struct psref *);
 void		lagg_enqueue(struct lagg_softc *,



CVS commit: src/sys/net

2021-05-18 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Wed May 19 03:35:27 UTC 2021

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

Log Message:
Added a limitation of the number of processing packets
because a enqueuing process can not add packets over IFQ_MAXLEN

and removed reschedule at pppoeintr()
because it also scheduled at enqueuing process.


To generate a diff of this commit:
cvs rdiff -u -r1.174 -r1.175 src/sys/net/if_pppoe.c

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

Modified files:

Index: src/sys/net/if_pppoe.c
diff -u src/sys/net/if_pppoe.c:1.174 src/sys/net/if_pppoe.c:1.175
--- src/sys/net/if_pppoe.c:1.174	Tue May 18 01:46:29 2021
+++ src/sys/net/if_pppoe.c	Wed May 19 03:35:27 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: if_pppoe.c,v 1.174 2021/05/18 01:46:29 yamaguchi Exp $ */
+/* $NetBSD: if_pppoe.c,v 1.175 2021/05/19 03:35:27 yamaguchi Exp $ */
 
 /*
  * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.174 2021/05/18 01:46:29 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.175 2021/05/19 03:35:27 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "pppoe.h"
@@ -594,36 +594,27 @@ static void
 pppoeintr(void)
 {
 	struct mbuf *m;
-	int disc_done, data_done;
+	int i;
 
 	SOFTNET_LOCK_UNLESS_NET_MPSAFE();
 
-	do {
-		disc_done = 0;
-		data_done = 0;
-		for (;;) {
-			IFQ_LOCK();
-			IF_DEQUEUE(, m);
-			IFQ_UNLOCK();
-			if (m == NULL)
-break;
-			disc_done = 1;
-			pppoe_disc_input(m);
-		}
-
-		for (;;) {
-			IFQ_LOCK();
-			IF_DEQUEUE(, m);
-			IFQ_UNLOCK();
-			if (m == NULL)
-break;
-			data_done = 1;
-			pppoe_data_input(m);
-		}
-	} while (disc_done || data_done);
+	for (i = 0; i < IFQ_MAXLEN; i++) {
+		IFQ_LOCK();
+		IF_DEQUEUE(, m);
+		IFQ_UNLOCK();
+		if (m == NULL)
+			break;
+		pppoe_disc_input(m);
+	}
 
-	if (!IF_IS_EMPTY() || !IF_IS_EMPTY())
-		softint_schedule(pppoe_softintr);
+	for (i = 0; i < IFQ_MAXLEN; i++) {
+		IFQ_LOCK();
+		IF_DEQUEUE(, m);
+		IFQ_UNLOCK();
+		if (m == NULL)
+			break;
+		pppoe_data_input(m);
+	}
 
 	SOFTNET_UNLOCK_UNLESS_NET_MPSAFE();
 }



CVS commit: src/sys/net

2021-05-18 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Wed May 19 02:14:19 UTC 2021

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

Log Message:
Make functions that use for logging MP-safe

There is no change in behavior.


To generate a diff of this commit:
cvs rdiff -u -r1.245 -r1.246 src/sys/net/if_spppsubr.c

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

Modified files:

Index: src/sys/net/if_spppsubr.c
diff -u src/sys/net/if_spppsubr.c:1.245 src/sys/net/if_spppsubr.c:1.246
--- src/sys/net/if_spppsubr.c:1.245	Wed May 19 02:07:20 2021
+++ src/sys/net/if_spppsubr.c	Wed May 19 02:14:19 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppsubr.c,v 1.245 2021/05/19 02:07:20 yamaguchi Exp $	 */
+/*	$NetBSD: if_spppsubr.c,v 1.246 2021/05/19 02:14:19 yamaguchi Exp $	 */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.245 2021/05/19 02:07:20 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.246 2021/05/19 02:14:19 yamaguchi Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -116,6 +116,14 @@ __KERNEL_RCSID(0, "$NetBSD: if_spppsubr.
 #define SPPP_ALIVE_INTERVAL		DEFAULT_ALIVE_INTERVAL
 #endif
 
+#define SPPP_CPTYPE_NAMELEN	5	/* buf size of cp type name */
+#define SPPP_AUTHTYPE_NAMELEN	32	/* buf size of auth type name */
+#define SPPP_LCPOPT_NAMELEN	5	/* buf size of lcp option name  */
+#define SPPP_IPCPOPT_NAMELEN	5	/* buf size of ipcp option name */
+#define SPPP_IPV6CPOPT_NAMELEN	5	/* buf size of ipv6cp option name */
+#define SPPP_PROTO_NAMELEN	7	/* buf size of protocol name */
+#define SPPP_DOTQUAD_BUFLEN	16	/* length of "aa.bb.cc.dd" */
+
 /*
  * Interface flags that can be set in an ifconfig command.
  *
@@ -437,16 +445,16 @@ static void sppp_chap_tlu(struct sppp *)
 static void sppp_chap_scr(struct sppp *);
 static void sppp_chap_rcv_challenge_event(struct sppp *, void *);
 
-static const char *sppp_auth_type_name(u_short, u_char);
-static const char *sppp_cp_type_name(u_char);
-static const char *sppp_dotted_quad(uint32_t);
-static const char *sppp_ipcp_opt_name(u_char);
+static const char *sppp_auth_type_name(char *, size_t, u_short, u_char);
+static const char *sppp_cp_type_name(char *, size_t, u_char);
+static const char *sppp_dotted_quad(char *, size_t, uint32_t);
+static const char *sppp_ipcp_opt_name(char *, size_t, u_char);
 #ifdef INET6
-static const char *sppp_ipv6cp_opt_name(u_char);
+static const char *sppp_ipv6cp_opt_name(char *, size_t, u_char);
 #endif
-static const char *sppp_lcp_opt_name(u_char);
+static const char *sppp_lcp_opt_name(char *, size_t, u_char);
 static const char *sppp_phase_name(int);
-static const char *sppp_proto_name(u_short);
+static const char *sppp_proto_name(char *, size_t, u_short);
 static const char *sppp_state_name(int);
 static int sppp_params(struct sppp *, u_long, void *);
 #ifdef INET
@@ -1612,10 +1620,15 @@ sppp_cp_send(struct sppp *sp, u_short pr
 		memcpy(lh + 1, data, len);
 
 	if (debug) {
+		char pbuf[SPPP_PROTO_NAMELEN];
+		char tbuf[SPPP_CPTYPE_NAMELEN];
+		const char *pname, *cpname;
+
+		pname = sppp_proto_name(pbuf, sizeof(pbuf), proto);
+		cpname = sppp_cp_type_name(tbuf, sizeof(tbuf), lh->type);
 		log(LOG_DEBUG, "%s: %s output <%s id=0x%x len=%d",
-		ifp->if_xname,
-		sppp_proto_name(proto),
-		sppp_cp_type_name(lh->type), lh->ident, ntohs(lh->len));
+		ifp->if_xname, pname, cpname,
+		lh->ident, ntohs(lh->len));
 		if (len)
 			sppp_print_bytes((u_char *)(lh + 1), len);
 		addlog(">\n");
@@ -1756,6 +1769,8 @@ sppp_cp_input(const struct cp *cp, struc
 	int printlen, len = m->m_pkthdr.len;
 	u_char *p;
 	uint32_t u32;
+	char tbuf[SPPP_CPTYPE_NAMELEN];
+	const char *cpname;
 
 	SPPP_LOCK(sp, RW_WRITER);
 
@@ -1771,11 +1786,12 @@ sppp_cp_input(const struct cp *cp, struc
 	h = mtod(m, struct lcp_header *);
 	if (debug) {
 		printlen = ntohs(h->len);
+		cpname = sppp_cp_type_name(tbuf, sizeof(tbuf), h->type);
 		log(LOG_DEBUG,
 		"%s: %s input(%s): <%s id=0x%x len=%d",
 		ifp->if_xname, cp->name,
 		sppp_state_name(scp->state),
-		sppp_cp_type_name(h->type), h->ident, printlen);
+		cpname, h->ident, printlen);
 		if (len < printlen)
 			printlen = len;
 		if (printlen > 4)
@@ -1855,11 +1871,11 @@ sppp_cp_input(const struct cp *cp, struc
 		break;
 	case CODE_REJ:
 		/* XXX catastrophic rejects (RXJ-) aren't handled yet. */
+		cpname = sppp_cp_type_name(tbuf, sizeof(tbuf), h->type);
 		log(LOG_INFO,
 		"%s: %s: ignoring RXJ (%s) for code ?, "
 		"danger will robinson\n",
-		ifp->if_xname, cp->name,
-		sppp_cp_type_name(h->type));
+		ifp->if_xname, cp->name, cpname);
 		sppp_wq_add(sp->wq_cp, >work_rxj);
 		break;
 	case PROTO_REJ:
@@ -1881,13 +1897,14 @@ sppp_cp_input(const struct cp *cp, struc
 		if (upper == NULL)
 			catastrophic++;
 
-		if (debug)
+		if (debug) {
+			cpname = sppp_cp_type_name(tbuf, 

CVS commit: src/sys/net

2021-05-18 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Wed May 19 02:07:21 UTC 2021

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

Log Message:
Added clear of dns addresses when IPCP is closed


To generate a diff of this commit:
cvs rdiff -u -r1.244 -r1.245 src/sys/net/if_spppsubr.c

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

Modified files:

Index: src/sys/net/if_spppsubr.c
diff -u src/sys/net/if_spppsubr.c:1.244 src/sys/net/if_spppsubr.c:1.245
--- src/sys/net/if_spppsubr.c:1.244	Wed May 19 02:02:46 2021
+++ src/sys/net/if_spppsubr.c	Wed May 19 02:07:20 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppsubr.c,v 1.244 2021/05/19 02:02:46 yamaguchi Exp $	 */
+/*	$NetBSD: if_spppsubr.c,v 1.245 2021/05/19 02:07:20 yamaguchi Exp $	 */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.244 2021/05/19 02:02:46 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.245 2021/05/19 02:07:20 yamaguchi Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -3662,12 +3662,14 @@ sppp_ipcp_close(struct sppp *sp, void *x
 	sppp_close_event(sp, xcp);
 
 #ifdef INET
-	if (sp->ipcp.flags & (IPCP_MYADDR_DYN|IPCP_HISADDR_DYN))
+	if (sp->ipcp.flags & (IPCP_MYADDR_DYN|IPCP_HISADDR_DYN)) {
 		/*
 		 * Some address was dynamic, clear it again.
 		 */
 		sppp_clear_ip_addrs(sp);
+	}
 #endif
+	memset(>dns_addrs, 0, sizeof sp->dns_addrs);
 }
 
 /*



CVS commit: src/sys/net

2021-05-18 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Wed May 19 02:02:46 UTC 2021

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

Log Message:
Added logs on dropping IPCP and IPv6CP packets


To generate a diff of this commit:
cvs rdiff -u -r1.243 -r1.244 src/sys/net/if_spppsubr.c

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

Modified files:

Index: src/sys/net/if_spppsubr.c
diff -u src/sys/net/if_spppsubr.c:1.243 src/sys/net/if_spppsubr.c:1.244
--- src/sys/net/if_spppsubr.c:1.243	Wed May 19 01:54:09 2021
+++ src/sys/net/if_spppsubr.c	Wed May 19 02:02:46 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppsubr.c,v 1.243 2021/05/19 01:54:09 yamaguchi Exp $	 */
+/*	$NetBSD: if_spppsubr.c,v 1.244 2021/05/19 02:02:46 yamaguchi Exp $	 */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.243 2021/05/19 01:54:09 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.244 2021/05/19 02:02:46 yamaguchi Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -714,13 +714,14 @@ sppp_input(struct ifnet *ifp, struct mbu
 			);
 			SPPP_DOWNGRADE(sp);
 		}
-		if (debug)
-			log(LOG_DEBUG,
-			"%s: invalid input protocol "
-			"\n", ifp->if_xname, protocol);
 		if_statinc(ifp, if_noproto);
 		goto drop;
 	default:
+		if (debug) {
+			log(LOG_DEBUG,
+			"%s: invalid input protocol "
+			"\n", ifp->if_xname, protocol);
+		}
 		goto reject_protocol;
 	case PPP_LCP:
 		SPPP_UNLOCK(sp);
@@ -743,8 +744,12 @@ sppp_input(struct ifnet *ifp, struct mbu
 		return;
 #ifdef INET
 	case PPP_IPCP:
-		if (!ISSET(sp->pp_ncpflags, SPPP_NCP_IPCP))
+		if (!ISSET(sp->pp_ncpflags, SPPP_NCP_IPCP)) {
+			log(LOG_INFO, "%s: reject IPCP packet "
+			"because IPCP is disabled\n",
+			ifp->if_xname);
 			goto reject_protocol;
+		}
 		SPPP_UNLOCK(sp);
 		if (sp->pp_phase == SPPP_PHASE_NETWORK) {
 			sppp_cp_input(, sp, m);
@@ -762,8 +767,12 @@ sppp_input(struct ifnet *ifp, struct mbu
 #endif
 #ifdef INET6
 	case PPP_IPV6CP:
-		if (!ISSET(sp->pp_ncpflags, SPPP_NCP_IPV6CP))
+		if (!ISSET(sp->pp_ncpflags, SPPP_NCP_IPV6CP)) {
+			log(LOG_INFO, "%s: reject IPv6CP packet "
+			"because IPv6CP is disabled\n",
+			ifp->if_xname);
 			goto reject_protocol;
+		}
 		SPPP_UNLOCK(sp);
 		if (sp->pp_phase == SPPP_PHASE_NETWORK) {
 			sppp_cp_input(, sp, m);



CVS commit: src/sys/net

2021-05-18 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Wed May 19 01:54:09 UTC 2021

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

Log Message:
remove a wrong ntohs().

The variable is already host-byte-order.


To generate a diff of this commit:
cvs rdiff -u -r1.242 -r1.243 src/sys/net/if_spppsubr.c

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

Modified files:

Index: src/sys/net/if_spppsubr.c
diff -u src/sys/net/if_spppsubr.c:1.242 src/sys/net/if_spppsubr.c:1.243
--- src/sys/net/if_spppsubr.c:1.242	Wed May 19 01:42:35 2021
+++ src/sys/net/if_spppsubr.c	Wed May 19 01:54:09 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppsubr.c,v 1.242 2021/05/19 01:42:35 yamaguchi Exp $	 */
+/*	$NetBSD: if_spppsubr.c,v 1.243 2021/05/19 01:54:09 yamaguchi Exp $	 */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.242 2021/05/19 01:42:35 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.243 2021/05/19 01:54:09 yamaguchi Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -717,7 +717,7 @@ sppp_input(struct ifnet *ifp, struct mbu
 		if (debug)
 			log(LOG_DEBUG,
 			"%s: invalid input protocol "
-			"\n", ifp->if_xname, ntohs(protocol));
+			"\n", ifp->if_xname, protocol);
 		if_statinc(ifp, if_noproto);
 		goto drop;
 	default:



CVS commit: src/sys/net

2021-05-18 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Wed May 19 01:42:35 UTC 2021

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

Log Message:
Added a log about rejection of IPCP address option


To generate a diff of this commit:
cvs rdiff -u -r1.241 -r1.242 src/sys/net/if_spppsubr.c

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

Modified files:

Index: src/sys/net/if_spppsubr.c
diff -u src/sys/net/if_spppsubr.c:1.241 src/sys/net/if_spppsubr.c:1.242
--- src/sys/net/if_spppsubr.c:1.241	Fri May 14 08:41:25 2021
+++ src/sys/net/if_spppsubr.c	Wed May 19 01:42:35 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppsubr.c,v 1.241 2021/05/14 08:41:25 yamaguchi Exp $	 */
+/*	$NetBSD: if_spppsubr.c,v 1.242 2021/05/19 01:42:35 yamaguchi Exp $	 */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.241 2021/05/14 08:41:25 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.242 2021/05/19 01:42:35 yamaguchi Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -3929,6 +3929,11 @@ sppp_ipcp_confrej(struct sppp *sp, struc
 			 * Peer doesn't grok address option.  This is
 			 * bad.  XXX  Should we better give up here?
 			 */
+			if (!debug) {
+log(LOG_ERR, "%s: "
+"IPCP address option rejected\n",
+ifp->if_xname);
+			}
 			CLR(sp->ipcp.opts, SPPP_IPCP_OPT_ADDRESS);
 			break;
 #ifdef notyet



CVS commit: src/sys/net/lagg

2021-05-18 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Tue May 18 11:02:58 UTC 2021

Modified Files:
src/sys/net/lagg: if_lagg_lacp.c

Log Message:
Make this compile without DIAGNOSTIC.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/net/lagg/if_lagg_lacp.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/lagg/if_lagg_lacp.c
diff -u src/sys/net/lagg/if_lagg_lacp.c:1.1 src/sys/net/lagg/if_lagg_lacp.c:1.2
--- src/sys/net/lagg/if_lagg_lacp.c:1.1	Mon May 17 04:07:43 2021
+++ src/sys/net/lagg/if_lagg_lacp.c	Tue May 18 11:02:58 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_lagg_lacp.c,v 1.1 2021/05/17 04:07:43 yamaguchi Exp $	*/
+/*	$NetBSD: if_lagg_lacp.c,v 1.2 2021/05/18 11:02:58 hannken Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-NetBSD
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_lagg_lacp.c,v 1.1 2021/05/17 04:07:43 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg_lacp.c,v 1.2 2021/05/18 11:02:58 hannken Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_lagg.h"
@@ -504,7 +504,7 @@ void
 lacp_detach(struct lagg_proto_softc *xlsc)
 {
 	struct lacp_softc *lsc = (struct lacp_softc *)xlsc;
-	struct lagg_softc *sc = lsc->lsc_softc;
+	struct lagg_softc *sc __diagused = lsc->lsc_softc;
 
 	KASSERT(LAGG_LOCKED(lsc->lsc_softc));
 	KASSERT(TAILQ_EMPTY(>lsc_aggregators));
@@ -2149,7 +2149,7 @@ lacp_set_mux(struct lacp_softc *lsc, str
 static void
 lacp_sm_mux(struct lacp_softc *lsc, struct lacp_port *lacpp)
 {
-	struct lacp_aggregator *la;
+	struct lacp_aggregator *la __diagused;
 	enum lacp_mux_state  next_state;
 	enum lacp_selected selected;
 	bool p_sync, p_collecting;



CVS commit: src/sys/net

2021-05-17 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Tue May 18 01:46:29 UTC 2021

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

Log Message:
Added missing PPPOE_UNLOCK() on dropping PADS and PADT


To generate a diff of this commit:
cvs rdiff -u -r1.173 -r1.174 src/sys/net/if_pppoe.c

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

Modified files:

Index: src/sys/net/if_pppoe.c
diff -u src/sys/net/if_pppoe.c:1.173 src/sys/net/if_pppoe.c:1.174
--- src/sys/net/if_pppoe.c:1.173	Thu May 13 03:48:55 2021
+++ src/sys/net/if_pppoe.c	Tue May 18 01:46:29 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: if_pppoe.c,v 1.173 2021/05/13 03:48:55 yamaguchi Exp $ */
+/* $NetBSD: if_pppoe.c,v 1.174 2021/05/18 01:46:29 yamaguchi Exp $ */
 
 /*
  * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.173 2021/05/13 03:48:55 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.174 2021/05/18 01:46:29 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "pppoe.h"
@@ -1009,6 +1009,7 @@ breakbreak:;
 
 		if (memcmp(>sc_dest, eh->ether_shost,
 		sizeof sc->sc_dest) != 0) {
+			PPPOE_UNLOCK(sc);
 			goto done;
 		}
 
@@ -1036,6 +1037,7 @@ breakbreak:;
 
 		if (memcmp(>sc_dest, eh->ether_shost,
 		sizeof sc->sc_dest) != 0) {
+			PPPOE_UNLOCK(sc);
 			goto done;
 		}
 



CVS commit: src/sys/net

2021-05-14 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Fri May 14 08:11:08 UTC 2021

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

Log Message:
Send echo request even while user data is received
if pp_max_noreceive is 0


To generate a diff of this commit:
cvs rdiff -u -r1.238 -r1.239 src/sys/net/if_spppsubr.c

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

Modified files:

Index: src/sys/net/if_spppsubr.c
diff -u src/sys/net/if_spppsubr.c:1.238 src/sys/net/if_spppsubr.c:1.239
--- src/sys/net/if_spppsubr.c:1.238	Fri May 14 08:06:32 2021
+++ src/sys/net/if_spppsubr.c	Fri May 14 08:11:08 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppsubr.c,v 1.238 2021/05/14 08:06:32 yamaguchi Exp $	 */
+/*	$NetBSD: if_spppsubr.c,v 1.239 2021/05/14 08:11:08 yamaguchi Exp $	 */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.238 2021/05/14 08:06:32 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.239 2021/05/14 08:11:08 yamaguchi Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -5626,7 +5626,8 @@ sppp_keepalive(void *dummy)
 		}
 
 		/* No echo reply, but maybe user data passed through? */
-		if ((now - sp->pp_last_receive) < sp->pp_max_noreceive) {
+		if (sp->pp_max_noreceive != 0 &&
+		(now - sp->pp_last_receive) < sp->pp_max_noreceive) {
 			sp->pp_alivecnt = 0;
 			SPPP_UNLOCK(sp);
 			continue;



CVS commit: src/sys/net

2021-05-12 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu May 13 03:48:55 UTC 2021

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

Log Message:
Drop PADS and PADT from unknown host for safety


To generate a diff of this commit:
cvs rdiff -u -r1.172 -r1.173 src/sys/net/if_pppoe.c

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

Modified files:

Index: src/sys/net/if_pppoe.c
diff -u src/sys/net/if_pppoe.c:1.172 src/sys/net/if_pppoe.c:1.173
--- src/sys/net/if_pppoe.c:1.172	Thu May 13 03:28:36 2021
+++ src/sys/net/if_pppoe.c	Thu May 13 03:48:55 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: if_pppoe.c,v 1.172 2021/05/13 03:28:36 yamaguchi Exp $ */
+/* $NetBSD: if_pppoe.c,v 1.173 2021/05/13 03:48:55 yamaguchi Exp $ */
 
 /*
  * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.172 2021/05/13 03:28:36 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.173 2021/05/13 03:48:55 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "pppoe.h"
@@ -1007,6 +1007,11 @@ breakbreak:;
 		if (sc == NULL)
 			goto done;
 
+		if (memcmp(>sc_dest, eh->ether_shost,
+		sizeof sc->sc_dest) != 0) {
+			goto done;
+		}
+
 		sc->sc_session = session;
 		callout_stop(>sc_timeout);
 		pppoe_printf(sc, "session 0x%x connected\n", session);
@@ -1029,6 +1034,11 @@ breakbreak:;
 		if (sc == NULL)
 			goto done;
 
+		if (memcmp(>sc_dest, eh->ether_shost,
+		sizeof sc->sc_dest) != 0) {
+			goto done;
+		}
+
 		pppoe_clear_softc(sc, "received PADT");
 		if (sc->sc_sppp.pp_if.if_flags & IFF_RUNNING) {
 			pppoe_printf(sc, "wait for reconnect\n");



CVS commit: src/sys/net

2021-05-12 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu May 13 03:28:36 UTC 2021

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

Log Message:
Change reconnect delay after PADT received (15 sec -> 5 sec)

5 sec is the same as minimum PADI resending interval


To generate a diff of this commit:
cvs rdiff -u -r1.171 -r1.172 src/sys/net/if_pppoe.c

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

Modified files:

Index: src/sys/net/if_pppoe.c
diff -u src/sys/net/if_pppoe.c:1.171 src/sys/net/if_pppoe.c:1.172
--- src/sys/net/if_pppoe.c:1.171	Thu May 13 01:01:10 2021
+++ src/sys/net/if_pppoe.c	Thu May 13 03:28:36 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: if_pppoe.c,v 1.171 2021/05/13 01:01:10 yamaguchi Exp $ */
+/* $NetBSD: if_pppoe.c,v 1.172 2021/05/13 03:28:36 yamaguchi Exp $ */
 
 /*
  * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.171 2021/05/13 01:01:10 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.172 2021/05/13 03:28:36 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "pppoe.h"
@@ -129,6 +129,7 @@ struct pppoetag {
 #define	PPPOE_SLOW_RETRY	(hz*60)	/* persistent retry interval */
 #define	PPPOE_RECON_FAST	(hz*15)	/* first retry after auth failure */
 #define	PPPOE_RECON_IMMEDIATE	(hz/10)	/* "no delay" reconnect */
+#define	PPPOE_RECON_PADTRCVD	(hz*5)	/* reconnect delay after PADT received */
 #define	PPPOE_DISC_MAXPADI	4	/* retry PADI four times (quickly) */
 #define	PPPOE_DISC_MAXPADR	2	/* retry PADR twice */
 
@@ -1029,8 +1030,11 @@ breakbreak:;
 			goto done;
 
 		pppoe_clear_softc(sc, "received PADT");
-		if (sc->sc_sppp.pp_if.if_flags & IFF_RUNNING)
-			callout_schedule(>sc_timeout, PPPOE_RECON_FAST);
+		if (sc->sc_sppp.pp_if.if_flags & IFF_RUNNING) {
+			pppoe_printf(sc, "wait for reconnect\n");
+			callout_schedule(>sc_timeout,
+			PPPOE_RECON_PADTRCVD);
+		}
 		PPPOE_UNLOCK(sc);
 		break;
 



CVS commit: src/sys/net

2021-05-12 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu May 13 01:01:10 UTC 2021

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

Log Message:
Accept a frame like a PADT just containing PPPoE header


To generate a diff of this commit:
cvs rdiff -u -r1.170 -r1.171 src/sys/net/if_pppoe.c

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

Modified files:

Index: src/sys/net/if_pppoe.c
diff -u src/sys/net/if_pppoe.c:1.170 src/sys/net/if_pppoe.c:1.171
--- src/sys/net/if_pppoe.c:1.170	Thu Apr 22 10:26:24 2021
+++ src/sys/net/if_pppoe.c	Thu May 13 01:01:10 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: if_pppoe.c,v 1.170 2021/04/22 10:26:24 yamaguchi Exp $ */
+/* $NetBSD: if_pppoe.c,v 1.171 2021/05/13 01:01:10 yamaguchi Exp $ */
 
 /*
  * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.170 2021/04/22 10:26:24 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.171 2021/05/13 01:01:10 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "pppoe.h"
@@ -659,7 +659,7 @@ pppoe_dispatch_disc_pkt(struct mbuf *m, 
 	eh = mtod(m, struct ether_header *);
 	off += sizeof(*eh);
 
-	if (m->m_pkthdr.len - off <= PPPOE_HEADERLEN) {
+	if (m->m_pkthdr.len - off < PPPOE_HEADERLEN) {
 		goto done;
 	}
 



CVS commit: src/sys/net

2021-05-11 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Tue May 11 06:42:42 UTC 2021

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

Log Message:
clear authentication protocol when SPPP_AUTHPROTO_NONE is specified


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sys/net/if_sppp.h
cvs rdiff -u -r1.236 -r1.237 src/sys/net/if_spppsubr.c

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

Modified files:

Index: src/sys/net/if_sppp.h
diff -u src/sys/net/if_sppp.h:1.34 src/sys/net/if_sppp.h:1.35
--- src/sys/net/if_sppp.h:1.34	Tue May 11 01:27:45 2021
+++ src/sys/net/if_sppp.h	Tue May 11 06:42:42 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_sppp.h,v 1.34 2021/05/11 01:27:45 yamaguchi Exp $	*/
+/*	$NetBSD: if_sppp.h,v 1.35 2021/05/11 06:42:42 yamaguchi Exp $	*/
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -40,6 +40,7 @@
 #define	SPPP_AUTHPROTO_NONE	0
 #define SPPP_AUTHPROTO_PAP	1
 #define SPPP_AUTHPROTO_CHAP	2
+#define SPPP_AUTHPROTO_NOCHG	3
 
 #define SPPP_AUTHFLAG_NOCALLOUT		1	/* do not require authentication on */
 		/* callouts */

Index: src/sys/net/if_spppsubr.c
diff -u src/sys/net/if_spppsubr.c:1.236 src/sys/net/if_spppsubr.c:1.237
--- src/sys/net/if_spppsubr.c:1.236	Tue May 11 06:33:17 2021
+++ src/sys/net/if_spppsubr.c	Tue May 11 06:42:42 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppsubr.c,v 1.236 2021/05/11 06:33:17 yamaguchi Exp $	 */
+/*	$NetBSD: if_spppsubr.c,v 1.237 2021/05/11 06:42:42 yamaguchi Exp $	 */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.236 2021/05/11 06:33:17 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.237 2021/05/11 06:42:42 yamaguchi Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -185,6 +185,8 @@ __KERNEL_RCSID(0, "$NetBSD: if_spppsubr.
 #define CISCO_ADDR_REPLY	1	/* Cisco address reply */
 #define CISCO_KEEPALIVE_REQ	2	/* Cisco keepalive request */
 
+#define PPP_NOPROTO		0	/* no authentication protocol */
+
 enum {
 	STATE_INITIAL = SPPP_STATE_INITIAL,
 	STATE_STARTING = SPPP_STATE_STARTING,
@@ -528,6 +530,34 @@ static const struct cp *cps[IDX_COUNT] =
 	,			/* IDX_CHAP */
 };
 
+static inline u_int
+sppp_proto2authproto(u_short proto)
+{
+
+	switch (proto) {
+	case PPP_PAP:
+		return SPPP_AUTHPROTO_PAP;
+	case PPP_CHAP:
+		return SPPP_AUTHPROTO_CHAP;
+	}
+
+	return SPPP_AUTHPROTO_NONE;
+}
+
+static inline u_short
+sppp_authproto2proto(u_int authproto)
+{
+
+	switch (authproto) {
+	case SPPP_AUTHPROTO_PAP:
+		return PPP_PAP;
+	case SPPP_AUTHPROTO_CHAP:
+		return PPP_CHAP;
+	}
+
+	return PPP_NOPROTO;
+}
+
 static void
 sppp_change_phase(struct sppp *sp, int phase)
 {
@@ -2720,7 +2750,7 @@ sppp_lcp_open(struct sppp *sp, void *xcp
 	/*
 	 * If we are authenticator, negotiate LCP_AUTH
 	 */
-	if (sp->hisauth.proto != 0)
+	if (sp->hisauth.proto != PPP_NOPROTO)
 		SET(sp->lcp.opts, SPPP_LCP_OPT_AUTH_PROTO);
 	else
 		CLR(sp->lcp.opts, SPPP_LCP_OPT_AUTH_PROTO);
@@ -2854,7 +2884,7 @@ sppp_lcp_confreq(struct sppp *sp, struct
 if (authproto == PPP_PAP || authproto == PPP_CHAP)
 	sp->myauth.proto = authproto;
 			}
-			if (sp->myauth.proto == 0) {
+			if (sp->myauth.proto == PPP_NOPROTO) {
 /* we are not configured to do auth */
 if (debug)
 	addlog(" [not configured]");
@@ -5995,12 +6025,8 @@ sppp_params(struct sppp *sp, u_long cmd,
 		cfg->myauthflags = sp->myauth.flags;
 		cfg->hisauthflags = sp->hisauth.flags;
 		strlcpy(cfg->ifname, sp->pp_if.if_xname, sizeof(cfg->ifname));
-		cfg->hisauth = 0;
-		if (sp->hisauth.proto)
-		cfg->hisauth = (sp->hisauth.proto == PPP_PAP) ? SPPP_AUTHPROTO_PAP : SPPP_AUTHPROTO_CHAP;
-		cfg->myauth = 0;
-		if (sp->myauth.proto)
-		cfg->myauth = (sp->myauth.proto == PPP_PAP) ? SPPP_AUTHPROTO_PAP : SPPP_AUTHPROTO_CHAP;
+		cfg->hisauth = sppp_proto2authproto(sp->hisauth.proto);
+		cfg->myauth = sppp_proto2authproto(sp->myauth.proto);
 		if (cfg->myname_length == 0) {
 		if (sp->myauth.name != NULL)
 			cfg->myname_length = sp->myauth.name_len + 1;
@@ -6137,13 +6163,15 @@ sppp_params(struct sppp *sp, u_long cmd,
 			sp->myauth.secret[sp->myauth.secret_len] = 0;
 		}
 		sp->myauth.flags = cfg->myauthflags;
-		if (cfg->myauth)
-		sp->myauth.proto = (cfg->myauth == SPPP_AUTHPROTO_PAP) ? PPP_PAP : PPP_CHAP;
+		if (cfg->myauth != SPPP_AUTHPROTO_NOCHG) {
+			sp->myauth.proto = sppp_authproto2proto(cfg->myauth);
+		}
 		sp->hisauth.flags = cfg->hisauthflags;
-		if (cfg->hisauth)
-		sp->hisauth.proto = (cfg->hisauth == SPPP_AUTHPROTO_PAP) ? PPP_PAP : PPP_CHAP;
+		if (cfg->hisauth != SPPP_AUTHPROTO_NOCHG) {
+			sp->hisauth.proto = sppp_authproto2proto(cfg->hisauth);
+		}
 		sp->pp_auth_failures = 0;
-		if (sp->hisauth.proto != 0)
+		if (sp->hisauth.proto != PPP_NOPROTO)
 			SET(sp->lcp.opts, SPPP_LCP_OPT_AUTH_PROTO);
 		else
 			CLR(sp->lcp.opts, SPPP_LCP_OPT_AUTH_PROTO);



CVS commit: src/sys/net

2021-05-11 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Tue May 11 06:33:17 UTC 2021

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

Log Message:
Drop packets that have no NCP not to start auto-dial


To generate a diff of this commit:
cvs rdiff -u -r1.235 -r1.236 src/sys/net/if_spppsubr.c

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

Modified files:

Index: src/sys/net/if_spppsubr.c
diff -u src/sys/net/if_spppsubr.c:1.235 src/sys/net/if_spppsubr.c:1.236
--- src/sys/net/if_spppsubr.c:1.235	Tue May 11 06:27:18 2021
+++ src/sys/net/if_spppsubr.c	Tue May 11 06:33:17 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppsubr.c,v 1.235 2021/05/11 06:27:18 yamaguchi Exp $	 */
+/*	$NetBSD: if_spppsubr.c,v 1.236 2021/05/11 06:33:17 yamaguchi Exp $	 */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.235 2021/05/11 06:27:18 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.236 2021/05/11 06:33:17 yamaguchi Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -809,6 +809,18 @@ sppp_output(struct ifnet *ifp, struct mb
 	}
 
 	if ((ifp->if_flags & (IFF_RUNNING | IFF_AUTO)) == IFF_AUTO) {
+		/* ignore packets that have no enabled NCP */
+		if ((dst->sa_family == AF_INET &&
+		!ISSET(sp->pp_ncpflags, SPPP_NCP_IPCP)) ||
+		(dst->sa_family == AF_INET6 &&
+		!ISSET(sp->pp_ncpflags, SPPP_NCP_IPV6CP))) {
+			SPPP_UNLOCK(sp);
+			splx(s);
+
+			m_freem(m);
+			if_statinc(ifp, if_oerrors);
+			return (ENETDOWN);
+		}
 		/*
 		 * Interface is not yet running, but auto-dial.  Need
 		 * to start LCP for it.



CVS commit: src/sys/net

2021-05-11 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Tue May 11 06:27:19 UTC 2021

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

Log Message:
Added missing if_oerror incrementing


To generate a diff of this commit:
cvs rdiff -u -r1.234 -r1.235 src/sys/net/if_spppsubr.c

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

Modified files:

Index: src/sys/net/if_spppsubr.c
diff -u src/sys/net/if_spppsubr.c:1.234 src/sys/net/if_spppsubr.c:1.235
--- src/sys/net/if_spppsubr.c:1.234	Tue May 11 06:21:28 2021
+++ src/sys/net/if_spppsubr.c	Tue May 11 06:27:18 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppsubr.c,v 1.234 2021/05/11 06:21:28 yamaguchi Exp $	 */
+/*	$NetBSD: if_spppsubr.c,v 1.235 2021/05/11 06:27:18 yamaguchi Exp $	 */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.234 2021/05/11 06:21:28 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.235 2021/05/11 06:27:18 yamaguchi Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -804,7 +804,7 @@ sppp_output(struct ifnet *ifp, struct mb
 		splx(s);
 
 		m_freem(m);
-
+		if_statinc(ifp, if_oerrors);
 		return (ENETDOWN);
 	}
 
@@ -930,8 +930,19 @@ sppp_output(struct ifnet *ifp, struct mb
 			 * ENETDOWN, as opposed to ENOBUFS.
 			 */
 			protocol = htons(PPP_IP);
-			if (sp->scp[IDX_IPCP].state != STATE_OPENED)
-error = ENETDOWN;
+			if (sp->scp[IDX_IPCP].state != STATE_OPENED) {
+if (ifp->if_flags & IFF_AUTO) {
+	error = ENETDOWN;
+} else {
+	IF_DROP(>if_snd);
+	SPPP_UNLOCK(sp);
+	splx(s);
+
+	m_freem(m);
+	if_statinc(ifp, if_oerrors);
+	return (ENETDOWN);
+}
+			}
 		}
 		break;
 #endif
@@ -950,8 +961,19 @@ sppp_output(struct ifnet *ifp, struct mb
 			 * ENETDOWN, as opposed to ENOBUFS.
 			 */
 			protocol = htons(PPP_IPV6);
-			if (sp->scp[IDX_IPV6CP].state != STATE_OPENED)
-error = ENETDOWN;
+			if (sp->scp[IDX_IPV6CP].state != STATE_OPENED) {
+if (ifp->if_flags & IFF_AUTO) {
+	error = ENETDOWN;
+} else {
+	IF_DROP(>if_snd);
+	SPPP_UNLOCK(sp);
+	splx(s);
+
+	m_freem(m);
+	if_statinc(ifp, if_oerrors);
+	return (ENETDOWN);
+}
+			}
 		}
 		break;
 #endif



CVS commit: src/sys/net

2021-05-11 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Tue May 11 06:21:28 UTC 2021

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

Log Message:
Move RCA event after RCR event

A authentication failed by TO+ event between RCA and RCR events
 1. RCA event in REQ-SENT state
   - REQ-SENT => ACK-RCVD
 2. TO+ event
   - ACK-RCVD => REQ-SENT
 3. RCR+ event
   - REQ-SENT => ACK-SENT

By moving RCA after RCR, the state is transisted to OPENED
 1. RCR event
   - REQ-SENT => ACK-SENT
 2. TO+ event
   - state is not changed
 3. RCA event
   - ACK-SENT => OPENED


To generate a diff of this commit:
cvs rdiff -u -r1.233 -r1.234 src/sys/net/if_spppsubr.c

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

Modified files:

Index: src/sys/net/if_spppsubr.c
diff -u src/sys/net/if_spppsubr.c:1.233 src/sys/net/if_spppsubr.c:1.234
--- src/sys/net/if_spppsubr.c:1.233	Tue May 11 01:27:45 2021
+++ src/sys/net/if_spppsubr.c	Tue May 11 06:21:28 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppsubr.c,v 1.233 2021/05/11 01:27:45 yamaguchi Exp $	 */
+/*	$NetBSD: if_spppsubr.c,v 1.234 2021/05/11 06:21:28 yamaguchi Exp $	 */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.233 2021/05/11 01:27:45 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.234 2021/05/11 06:21:28 yamaguchi Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -4876,11 +4876,6 @@ sppp_chap_input(struct sppp *sp, struct 
 
 			if (memcmp(digest, value, value_len) == 0) {
 sp->scp[IDX_CHAP].rcr_type = CP_RCR_ACK;
-if (!ISSET(sppp_auth_role(, sp), SPPP_AUTH_PEER) ||
-sp->chap.rechallenging) {
-	/* generate a dummy RCA event*/
-	sppp_wq_add(sp->wq_cp, >scp[IDX_CHAP].work_rca);
-}
 			} else {
 sp->scp[IDX_CHAP].rcr_type = CP_RCR_NAK;
 			}
@@ -4896,6 +4891,13 @@ sppp_chap_input(struct sppp *sp, struct 
 		}
 
 		sppp_wq_add(sp->wq_cp, >scp[IDX_CHAP].work_rcr);
+
+		/* generate a dummy RCA event */
+		if (sp->scp[IDX_CHAP].rcr_type == CP_RCR_ACK &&
+		(!ISSET(sppp_auth_role(, sp), SPPP_AUTH_PEER) ||
+		sp->chap.rechallenging)) {
+			sppp_wq_add(sp->wq_cp, >scp[IDX_CHAP].work_rca);
+		}
 		break;
 
 	default:
@@ -5149,15 +5151,17 @@ sppp_pap_input(struct sppp *sp, struct m
 		secret_len == sp->hisauth.secret_len &&
 		memcmp(secret, sp->hisauth.secret, secret_len) == 0) {
 			sp->scp[IDX_PAP].rcr_type = CP_RCR_ACK;
-			if (!ISSET(sppp_auth_role(, sp), SPPP_AUTH_PEER)) {
-/* generate a dummy RCA event*/
-sppp_wq_add(sp->wq_cp, >scp[IDX_PAP].work_rca);
-			}
 		} else {
 			sp->scp[IDX_PAP].rcr_type = CP_RCR_NAK;
 		}
 
 		sppp_wq_add(sp->wq_cp, >scp[IDX_PAP].work_rcr);
+
+		/* generate a dummy RCA event */
+		if (sp->scp[IDX_PAP].rcr_type == CP_RCR_ACK &&
+		!ISSET(sppp_auth_role(, sp), SPPP_AUTH_PEER)) {
+			sppp_wq_add(sp->wq_cp, >scp[IDX_PAP].work_rca);
+		}
 		break;
 
 	/* ack and nak are his authproto */



CVS commit: src/sys/net

2021-05-10 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Tue May 11 01:27:45 UTC 2021

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

Log Message:
Added ioctl commands for configuring NCP of pppoe(4)


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/sys/net/if_sppp.h
cvs rdiff -u -r1.232 -r1.233 src/sys/net/if_spppsubr.c
cvs rdiff -u -r1.36 -r1.37 src/sys/net/if_spppvar.h

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

Modified files:

Index: src/sys/net/if_sppp.h
diff -u src/sys/net/if_sppp.h:1.33 src/sys/net/if_sppp.h:1.34
--- src/sys/net/if_sppp.h:1.33	Tue May 11 01:15:11 2021
+++ src/sys/net/if_sppp.h	Tue May 11 01:27:45 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_sppp.h,v 1.33 2021/05/11 01:15:11 yamaguchi Exp $	*/
+/*	$NetBSD: if_sppp.h,v 1.34 2021/05/11 01:27:45 yamaguchi Exp $	*/
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -233,5 +233,15 @@ struct spppipv6cpstatus {
 
 #define SPPPGETIPV6CPSTATUS	_IOWR('i', 137, struct spppipv6cpstatus)
 
+#define SPPP_NCP_IPCP		__BIT(0)
+#define SPPP_NCP_IPV6CP		__BIT(1)
+struct spppncpcfg {
+	char		ifname[IFNAMSIZ];
+	u_int		ncp_flags;
+};
+
+#define SPPPGETNCPCFG		_IOWR('i', 138, struct spppncpcfg)
+#define SPPPSETNCPCFG		_IOW('i', 139, struct spppncpcfg)
+
 #endif /* !_NET_IF_SPPP_H_ */
 

Index: src/sys/net/if_spppsubr.c
diff -u src/sys/net/if_spppsubr.c:1.232 src/sys/net/if_spppsubr.c:1.233
--- src/sys/net/if_spppsubr.c:1.232	Tue May 11 01:15:11 2021
+++ src/sys/net/if_spppsubr.c	Tue May 11 01:27:45 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppsubr.c,v 1.232 2021/05/11 01:15:11 yamaguchi Exp $	 */
+/*	$NetBSD: if_spppsubr.c,v 1.233 2021/05/11 01:27:45 yamaguchi Exp $	 */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.232 2021/05/11 01:15:11 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.233 2021/05/11 01:27:45 yamaguchi Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -585,11 +585,7 @@ sppp_input(struct ifnet *ifp, struct mbu
 			log(LOG_DEBUG,
 			"%s: input packet is too small, %d bytes\n",
 			ifp->if_xname, m->m_pkthdr.len);
-	  drop:
-		if_statadd2(ifp, if_ierrors, 1, if_iqdrops, 1);
-		m_freem(m);
-		SPPP_UNLOCK(sp);
-		return;
+		goto drop;
 	}
 
 	if (sp->pp_flags & PP_NOFRAMING) {
@@ -663,7 +659,7 @@ sppp_input(struct ifnet *ifp, struct mbu
 	}
 
 	switch (protocol) {
-	default:
+	reject_protocol:
 		if (sp->scp[IDX_LCP].state == STATE_OPENED) {
 			uint16_t prot = htons(protocol);
 
@@ -679,6 +675,8 @@ sppp_input(struct ifnet *ifp, struct mbu
 			"\n", ifp->if_xname, ntohs(protocol));
 		if_statinc(ifp, if_noproto);
 		goto drop;
+	default:
+		goto reject_protocol;
 	case PPP_LCP:
 		SPPP_UNLOCK(sp);
 		sppp_cp_input(, sp, m);
@@ -700,6 +698,8 @@ sppp_input(struct ifnet *ifp, struct mbu
 		return;
 #ifdef INET
 	case PPP_IPCP:
+		if (!ISSET(sp->pp_ncpflags, SPPP_NCP_IPCP))
+			goto reject_protocol;
 		SPPP_UNLOCK(sp);
 		if (sp->pp_phase == SPPP_PHASE_NETWORK) {
 			sppp_cp_input(, sp, m);
@@ -717,6 +717,8 @@ sppp_input(struct ifnet *ifp, struct mbu
 #endif
 #ifdef INET6
 	case PPP_IPV6CP:
+		if (!ISSET(sp->pp_ncpflags, SPPP_NCP_IPV6CP))
+			goto reject_protocol;
 		SPPP_UNLOCK(sp);
 		if (sp->pp_phase == SPPP_PHASE_NETWORK) {
 			sppp_cp_input(, sp, m);
@@ -766,6 +768,13 @@ queue_pkt:
 	IF_ENQUEUE(inq, m);
 	IFQ_UNLOCK(inq);
 	schednetisr(isr);
+	return;
+
+drop:
+	if_statadd2(ifp, if_ierrors, 1, if_iqdrops, 1);
+	m_freem(m);
+	SPPP_UNLOCK(sp);
+	return;
 }
 
 /*
@@ -1029,6 +1038,7 @@ sppp_attach(struct ifnet *ifp)
 	sp->pp_phase = SPPP_PHASE_DEAD;
 	sp->pp_up = sppp_notify_up;
 	sp->pp_down = sppp_notify_down;
+	sp->pp_ncpflags = SPPP_NCP_IPCP | SPPP_NCP_IPV6CP;
 	sppp_wq_set(>work_ifdown, sppp_ifdown, NULL);
 	memset(sp->scp, 0, sizeof(sp->scp));
 	rw_init(>pp_lock);
@@ -1265,6 +1275,7 @@ sppp_ioctl(struct ifnet *ifp, u_long cmd
 
 	case SPPPSETAUTHCFG:
 	case SPPPSETLCPCFG:
+	case SPPPSETNCPCFG:
 	case SPPPSETIDLETO:
 	case SPPPSETAUTHFAILURE:
 	case SPPPSETDNSOPTS:
@@ -1284,6 +1295,7 @@ sppp_ioctl(struct ifnet *ifp, u_long cmd
 
 	case SPPPGETAUTHCFG:
 	case SPPPGETLCPCFG:
+	case SPPPGETNCPCFG:
 	case SPPPGETAUTHFAILURES:
 		error = kauth_authorize_network(l->l_cred,
 		KAUTH_NETWORK_INTERFACE,
@@ -3491,6 +3503,9 @@ sppp_ipcp_open(struct sppp *sp, void *xc
 	KASSERT(SPPP_WLOCKED(sp));
 	KASSERT(!cpu_softintr_p());
 
+	if (!ISSET(sp->pp_ncpflags, SPPP_NCP_IPCP))
+		return;
+
 	sp->ipcp.flags &= ~(IPCP_HISADDR_SEEN|IPCP_MYADDR_SEEN|IPCP_MYADDR_DYN|IPCP_HISADDR_DYN);
 	sp->ipcp.req_myaddr = 0;
 	sp->ipcp.req_hisaddr = 0;
@@ -4065,6 +4080,9 @@ sppp_ipv6cp_open(struct sppp *sp, void *
 	KASSERT(SPPP_WLOCKED(sp));
 	KASSERT(!cpu_softintr_p());
 
+	if (!ISSET(sp->pp_ncpflags, SPPP_NCP_IPV6CP))
+		return;
+
 #ifdef IPV6CP_MYIFID_DYN
 	sp->ipv6cp.flags &= 

CVS commit: src/sys/net

2021-05-10 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Tue May 11 01:23:21 UTC 2021

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

Log Message:
back to r1.34 because of mistake of commit log


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/sys/net/if_spppvar.h

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

Modified files:

Index: src/sys/net/if_spppvar.h
diff -u src/sys/net/if_spppvar.h:1.35 src/sys/net/if_spppvar.h:1.36
--- src/sys/net/if_spppvar.h:1.35	Tue May 11 01:00:49 2021
+++ src/sys/net/if_spppvar.h	Tue May 11 01:23:21 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppvar.h,v 1.35 2021/05/11 01:00:49 yamaguchi Exp $	*/
+/*	$NetBSD: if_spppvar.h,v 1.36 2021/05/11 01:23:21 yamaguchi Exp $	*/
 
 #ifndef _NET_IF_SPPPVAR_H_
 #define _NET_IF_SPPPVAR_H_
@@ -141,7 +141,6 @@ struct sppp {
 	struct	ifqueue pp_cpq;	/* PPP control protocol queue */
 	struct  sppp *pp_next;  /* next interface in keepalive list */
 	u_int   pp_flags;   /* use Cisco protocol instead of PPP */
-	u_int	pp_ncpflags;	/* enable or disable each NCP */
 	u_int	pp_framebytes;	/* number of bytes added by (hardware) framing */
 	u_int   pp_alivecnt;/* keepalive packets counter */
 	u_int   pp_loopcnt; /* loopback detection counter */



CVS commit: src/sys/net

2021-05-10 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Tue May 11 01:15:11 UTC 2021

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

Log Message:
Revert previous commit because of mistake of commit log

back to r1.230(if_spppsubr.c) and r1.31(if_sppp.h)


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/sys/net/if_sppp.h
cvs rdiff -u -r1.231 -r1.232 src/sys/net/if_spppsubr.c

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

Modified files:

Index: src/sys/net/if_sppp.h
diff -u src/sys/net/if_sppp.h:1.32 src/sys/net/if_sppp.h:1.33
--- src/sys/net/if_sppp.h:1.32	Tue May 11 01:00:49 2021
+++ src/sys/net/if_sppp.h	Tue May 11 01:15:11 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_sppp.h,v 1.32 2021/05/11 01:00:49 yamaguchi Exp $	*/
+/*	$NetBSD: if_sppp.h,v 1.33 2021/05/11 01:15:11 yamaguchi Exp $	*/
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -233,15 +233,5 @@ struct spppipv6cpstatus {
 
 #define SPPPGETIPV6CPSTATUS	_IOWR('i', 137, struct spppipv6cpstatus)
 
-#define SPPP_NCP_IPCP		__BIT(0)
-#define SPPP_NCP_IPV6CP		__BIT(1)
-struct spppncpcfg {
-	char		ifname[IFNAMSIZ];
-	u_int		ncp_flags;
-};
-
-#define SPPPGETNCPCFG		_IOWR('i', 138, struct spppncpcfg)
-#define SPPPSETNCPCFG		_IOW('i', 139, struct spppncpcfg)
-
 #endif /* !_NET_IF_SPPP_H_ */
 

Index: src/sys/net/if_spppsubr.c
diff -u src/sys/net/if_spppsubr.c:1.231 src/sys/net/if_spppsubr.c:1.232
--- src/sys/net/if_spppsubr.c:1.231	Tue May 11 01:00:49 2021
+++ src/sys/net/if_spppsubr.c	Tue May 11 01:15:11 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppsubr.c,v 1.231 2021/05/11 01:00:49 yamaguchi Exp $	 */
+/*	$NetBSD: if_spppsubr.c,v 1.232 2021/05/11 01:15:11 yamaguchi Exp $	 */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.231 2021/05/11 01:00:49 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.232 2021/05/11 01:15:11 yamaguchi Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -585,7 +585,11 @@ sppp_input(struct ifnet *ifp, struct mbu
 			log(LOG_DEBUG,
 			"%s: input packet is too small, %d bytes\n",
 			ifp->if_xname, m->m_pkthdr.len);
-		goto drop;
+	  drop:
+		if_statadd2(ifp, if_ierrors, 1, if_iqdrops, 1);
+		m_freem(m);
+		SPPP_UNLOCK(sp);
+		return;
 	}
 
 	if (sp->pp_flags & PP_NOFRAMING) {
@@ -659,7 +663,7 @@ sppp_input(struct ifnet *ifp, struct mbu
 	}
 
 	switch (protocol) {
-	reject_protocol:
+	default:
 		if (sp->scp[IDX_LCP].state == STATE_OPENED) {
 			uint16_t prot = htons(protocol);
 
@@ -675,8 +679,6 @@ sppp_input(struct ifnet *ifp, struct mbu
 			"\n", ifp->if_xname, ntohs(protocol));
 		if_statinc(ifp, if_noproto);
 		goto drop;
-	default:
-		goto reject_protocol;
 	case PPP_LCP:
 		SPPP_UNLOCK(sp);
 		sppp_cp_input(, sp, m);
@@ -698,8 +700,6 @@ sppp_input(struct ifnet *ifp, struct mbu
 		return;
 #ifdef INET
 	case PPP_IPCP:
-		if (!ISSET(sp->pp_ncpflags, SPPP_NCP_IPCP))
-			goto reject_protocol;
 		SPPP_UNLOCK(sp);
 		if (sp->pp_phase == SPPP_PHASE_NETWORK) {
 			sppp_cp_input(, sp, m);
@@ -717,8 +717,6 @@ sppp_input(struct ifnet *ifp, struct mbu
 #endif
 #ifdef INET6
 	case PPP_IPV6CP:
-		if (!ISSET(sp->pp_ncpflags, SPPP_NCP_IPV6CP))
-			goto reject_protocol;
 		SPPP_UNLOCK(sp);
 		if (sp->pp_phase == SPPP_PHASE_NETWORK) {
 			sppp_cp_input(, sp, m);
@@ -768,13 +766,6 @@ queue_pkt:
 	IF_ENQUEUE(inq, m);
 	IFQ_UNLOCK(inq);
 	schednetisr(isr);
-	return;
-
-drop:
-	if_statadd2(ifp, if_ierrors, 1, if_iqdrops, 1);
-	m_freem(m);
-	SPPP_UNLOCK(sp);
-	return;
 }
 
 /*
@@ -1038,7 +1029,6 @@ sppp_attach(struct ifnet *ifp)
 	sp->pp_phase = SPPP_PHASE_DEAD;
 	sp->pp_up = sppp_notify_up;
 	sp->pp_down = sppp_notify_down;
-	sp->pp_ncpflags = SPPP_NCP_IPCP | SPPP_NCP_IPV6CP;
 	sppp_wq_set(>work_ifdown, sppp_ifdown, NULL);
 	memset(sp->scp, 0, sizeof(sp->scp));
 	rw_init(>pp_lock);
@@ -1275,7 +1265,6 @@ sppp_ioctl(struct ifnet *ifp, u_long cmd
 
 	case SPPPSETAUTHCFG:
 	case SPPPSETLCPCFG:
-	case SPPPSETNCPCFG:
 	case SPPPSETIDLETO:
 	case SPPPSETAUTHFAILURE:
 	case SPPPSETDNSOPTS:
@@ -1295,7 +1284,6 @@ sppp_ioctl(struct ifnet *ifp, u_long cmd
 
 	case SPPPGETAUTHCFG:
 	case SPPPGETLCPCFG:
-	case SPPPGETNCPCFG:
 	case SPPPGETAUTHFAILURES:
 		error = kauth_authorize_network(l->l_cred,
 		KAUTH_NETWORK_INTERFACE,
@@ -3503,9 +3491,6 @@ sppp_ipcp_open(struct sppp *sp, void *xc
 	KASSERT(SPPP_WLOCKED(sp));
 	KASSERT(!cpu_softintr_p());
 
-	if (!ISSET(sp->pp_ncpflags, SPPP_NCP_IPCP))
-		return;
-
 	sp->ipcp.flags &= ~(IPCP_HISADDR_SEEN|IPCP_MYADDR_SEEN|IPCP_MYADDR_DYN|IPCP_HISADDR_DYN);
 	sp->ipcp.req_myaddr = 0;
 	sp->ipcp.req_hisaddr = 0;
@@ -4080,9 +4065,6 @@ sppp_ipv6cp_open(struct sppp *sp, void *
 	KASSERT(SPPP_WLOCKED(sp));
 	KASSERT(!cpu_softintr_p());
 
-	if (!ISSET(sp->pp_ncpflags, SPPP_NCP_IPV6CP))
-		return;
-
 #ifdef IPV6CP_MYIFID_DYN
 	sp->ipv6cp.flags &= ~(IPV6CP_MYIFID_SEEN|IPV6CP_MYIFID_DYN);
 #else

CVS commit: src/sys/net

2021-05-10 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Tue May 11 01:00:49 UTC 2021

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

Log Message:
Added keywords that are ipcp, noipcp, ipv6cp, noipv6cp
for configuring NCP


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/sys/net/if_sppp.h
cvs rdiff -u -r1.230 -r1.231 src/sys/net/if_spppsubr.c
cvs rdiff -u -r1.34 -r1.35 src/sys/net/if_spppvar.h

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

Modified files:

Index: src/sys/net/if_sppp.h
diff -u src/sys/net/if_sppp.h:1.31 src/sys/net/if_sppp.h:1.32
--- src/sys/net/if_sppp.h:1.31	Fri Apr 23 01:13:25 2021
+++ src/sys/net/if_sppp.h	Tue May 11 01:00:49 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_sppp.h,v 1.31 2021/04/23 01:13:25 yamaguchi Exp $	*/
+/*	$NetBSD: if_sppp.h,v 1.32 2021/05/11 01:00:49 yamaguchi Exp $	*/
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -233,5 +233,15 @@ struct spppipv6cpstatus {
 
 #define SPPPGETIPV6CPSTATUS	_IOWR('i', 137, struct spppipv6cpstatus)
 
+#define SPPP_NCP_IPCP		__BIT(0)
+#define SPPP_NCP_IPV6CP		__BIT(1)
+struct spppncpcfg {
+	char		ifname[IFNAMSIZ];
+	u_int		ncp_flags;
+};
+
+#define SPPPGETNCPCFG		_IOWR('i', 138, struct spppncpcfg)
+#define SPPPSETNCPCFG		_IOW('i', 139, struct spppncpcfg)
+
 #endif /* !_NET_IF_SPPP_H_ */
 

Index: src/sys/net/if_spppsubr.c
diff -u src/sys/net/if_spppsubr.c:1.230 src/sys/net/if_spppsubr.c:1.231
--- src/sys/net/if_spppsubr.c:1.230	Thu May  6 06:18:16 2021
+++ src/sys/net/if_spppsubr.c	Tue May 11 01:00:49 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppsubr.c,v 1.230 2021/05/06 06:18:16 yamaguchi Exp $	 */
+/*	$NetBSD: if_spppsubr.c,v 1.231 2021/05/11 01:00:49 yamaguchi Exp $	 */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.230 2021/05/06 06:18:16 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.231 2021/05/11 01:00:49 yamaguchi Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -585,11 +585,7 @@ sppp_input(struct ifnet *ifp, struct mbu
 			log(LOG_DEBUG,
 			"%s: input packet is too small, %d bytes\n",
 			ifp->if_xname, m->m_pkthdr.len);
-	  drop:
-		if_statadd2(ifp, if_ierrors, 1, if_iqdrops, 1);
-		m_freem(m);
-		SPPP_UNLOCK(sp);
-		return;
+		goto drop;
 	}
 
 	if (sp->pp_flags & PP_NOFRAMING) {
@@ -663,7 +659,7 @@ sppp_input(struct ifnet *ifp, struct mbu
 	}
 
 	switch (protocol) {
-	default:
+	reject_protocol:
 		if (sp->scp[IDX_LCP].state == STATE_OPENED) {
 			uint16_t prot = htons(protocol);
 
@@ -679,6 +675,8 @@ sppp_input(struct ifnet *ifp, struct mbu
 			"\n", ifp->if_xname, ntohs(protocol));
 		if_statinc(ifp, if_noproto);
 		goto drop;
+	default:
+		goto reject_protocol;
 	case PPP_LCP:
 		SPPP_UNLOCK(sp);
 		sppp_cp_input(, sp, m);
@@ -700,6 +698,8 @@ sppp_input(struct ifnet *ifp, struct mbu
 		return;
 #ifdef INET
 	case PPP_IPCP:
+		if (!ISSET(sp->pp_ncpflags, SPPP_NCP_IPCP))
+			goto reject_protocol;
 		SPPP_UNLOCK(sp);
 		if (sp->pp_phase == SPPP_PHASE_NETWORK) {
 			sppp_cp_input(, sp, m);
@@ -717,6 +717,8 @@ sppp_input(struct ifnet *ifp, struct mbu
 #endif
 #ifdef INET6
 	case PPP_IPV6CP:
+		if (!ISSET(sp->pp_ncpflags, SPPP_NCP_IPV6CP))
+			goto reject_protocol;
 		SPPP_UNLOCK(sp);
 		if (sp->pp_phase == SPPP_PHASE_NETWORK) {
 			sppp_cp_input(, sp, m);
@@ -766,6 +768,13 @@ queue_pkt:
 	IF_ENQUEUE(inq, m);
 	IFQ_UNLOCK(inq);
 	schednetisr(isr);
+	return;
+
+drop:
+	if_statadd2(ifp, if_ierrors, 1, if_iqdrops, 1);
+	m_freem(m);
+	SPPP_UNLOCK(sp);
+	return;
 }
 
 /*
@@ -1029,6 +1038,7 @@ sppp_attach(struct ifnet *ifp)
 	sp->pp_phase = SPPP_PHASE_DEAD;
 	sp->pp_up = sppp_notify_up;
 	sp->pp_down = sppp_notify_down;
+	sp->pp_ncpflags = SPPP_NCP_IPCP | SPPP_NCP_IPV6CP;
 	sppp_wq_set(>work_ifdown, sppp_ifdown, NULL);
 	memset(sp->scp, 0, sizeof(sp->scp));
 	rw_init(>pp_lock);
@@ -1265,6 +1275,7 @@ sppp_ioctl(struct ifnet *ifp, u_long cmd
 
 	case SPPPSETAUTHCFG:
 	case SPPPSETLCPCFG:
+	case SPPPSETNCPCFG:
 	case SPPPSETIDLETO:
 	case SPPPSETAUTHFAILURE:
 	case SPPPSETDNSOPTS:
@@ -1284,6 +1295,7 @@ sppp_ioctl(struct ifnet *ifp, u_long cmd
 
 	case SPPPGETAUTHCFG:
 	case SPPPGETLCPCFG:
+	case SPPPGETNCPCFG:
 	case SPPPGETAUTHFAILURES:
 		error = kauth_authorize_network(l->l_cred,
 		KAUTH_NETWORK_INTERFACE,
@@ -3491,6 +3503,9 @@ sppp_ipcp_open(struct sppp *sp, void *xc
 	KASSERT(SPPP_WLOCKED(sp));
 	KASSERT(!cpu_softintr_p());
 
+	if (!ISSET(sp->pp_ncpflags, SPPP_NCP_IPCP))
+		return;
+
 	sp->ipcp.flags &= ~(IPCP_HISADDR_SEEN|IPCP_MYADDR_SEEN|IPCP_MYADDR_DYN|IPCP_HISADDR_DYN);
 	sp->ipcp.req_myaddr = 0;
 	sp->ipcp.req_hisaddr = 0;
@@ -4065,6 +4080,9 @@ sppp_ipv6cp_open(struct sppp *sp, void *
 	KASSERT(SPPP_WLOCKED(sp));
 	KASSERT(!cpu_softintr_p());
 
+	if (!ISSET(sp->pp_ncpflags, SPPP_NCP_IPV6CP))
+		return;
+
 #ifdef IPV6CP_MYIFID_DYN
 	sp->ipv6cp.flags &= 

CVS commit: src/sys/net

2021-05-06 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu May  6 06:18:16 UTC 2021

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

Log Message:
do not clear destination address if there is no saved address
and add initialization of saved_hisaddr for safety

0.0.0.0 was sometimes configured to destination address when
ipcp close was occurred before ipcp tlu.
Following messages will be appeared when the issue is encountered and
debug for pppoe(4) is enabled.

tc-so:[ 1.890005] pppoe0: ipcp close(starting)
(snip)
tc-so:[ 1.890005] pppoe0: ipcp_open(): no IP interface


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

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

Modified files:

Index: src/sys/net/if_spppsubr.c
diff -u src/sys/net/if_spppsubr.c:1.229 src/sys/net/if_spppsubr.c:1.230
--- src/sys/net/if_spppsubr.c:1.229	Thu May  6 02:05:09 2021
+++ src/sys/net/if_spppsubr.c	Thu May  6 06:18:16 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppsubr.c,v 1.229 2021/05/06 02:05:09 yamaguchi Exp $	 */
+/*	$NetBSD: if_spppsubr.c,v 1.230 2021/05/06 06:18:16 yamaguchi Exp $	 */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.229 2021/05/06 02:05:09 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.230 2021/05/06 06:18:16 yamaguchi Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -3531,6 +3531,7 @@ sppp_ipcp_open(struct sppp *sp, void *xc
 		 * remote has no valid address, we need to get one assigned.
 		 */
 		sp->ipcp.flags |= IPCP_HISADDR_DYN;
+		sp->ipcp.saved_hisaddr = htonl(hisaddr);
 	}
 
 	if (sp->query_dns & 1) {
@@ -5744,7 +5745,8 @@ sppp_clear_ip_addrs(struct sppp *sp)
 
 		if (sp->ipcp.flags & IPCP_MYADDR_DYN)
 			new_sin.sin_addr.s_addr = 0;
-		if (sp->ipcp.flags & IPCP_HISADDR_DYN)
+		if (sp->ipcp.flags & IPCP_HISADDR_DYN &&
+		ntohl(sp->ipcp.saved_hisaddr) != 0)
 			new_dst.sin_addr.s_addr = sp->ipcp.saved_hisaddr;
 
 		in_addrhash_remove(ifatoia(ifa));



CVS commit: src/sys/net

2021-05-05 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu May  6 02:05:09 UTC 2021

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

Log Message:
Added m_freem for safety

pointed out by knakahara@, thanks.


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

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

Modified files:

Index: src/sys/net/if_spppsubr.c
diff -u src/sys/net/if_spppsubr.c:1.228 src/sys/net/if_spppsubr.c:1.229
--- src/sys/net/if_spppsubr.c:1.228	Wed Apr 28 09:39:39 2021
+++ src/sys/net/if_spppsubr.c	Thu May  6 02:05:09 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppsubr.c,v 1.228 2021/04/28 09:39:39 yamaguchi Exp $	 */
+/*	$NetBSD: if_spppsubr.c,v 1.229 2021/05/06 02:05:09 yamaguchi Exp $	 */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.228 2021/04/28 09:39:39 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.229 2021/05/06 02:05:09 yamaguchi Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -1632,6 +1632,15 @@ sppp_cp_fini(const struct cp *cp, struct
 
 	callout_halt(>ch, NULL);
 	callout_destroy(>ch);
+
+	if (scp->mbuf_confreq != NULL) {
+		m_freem(scp->mbuf_confreq);
+		scp->mbuf_confreq = NULL;
+	}
+	if (scp->mbuf_confnak != NULL) {
+		m_freem(scp->mbuf_confnak);
+		scp->mbuf_confnak = NULL;
+	}
 }
 
 /*



CVS commit: src/sys/net

2021-04-29 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Thu Apr 29 17:55:51 UTC 2021

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

Log Message:
Sprinkle __noinline to reduce gigantic stack frames in ALL kernels.

In principle this might just push a real problem around, but this is
unlikely to be a real problem because:

1. The large stack frames are really only in the setup state machine
   message handlers, which run at the top loop of a thread with a
   shallow stack anyway.

2. If these are inlined, gcc might create multiple nonoverlapping
   stack buffers, whereas if not inlined, the stack frames from
   consecutive or alternative procedure calls would overlap anyway.

(I haven't investigated exactly what's going on leading to ~5 KB-byte
stack frames, but this shuts gcc up, at least, and the hypotheses
sound plausible to me!)


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 src/sys/net/if_wg.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_wg.c
diff -u src/sys/net/if_wg.c:1.62 src/sys/net/if_wg.c:1.63
--- src/sys/net/if_wg.c:1.62	Wed Nov 11 18:08:34 2020
+++ src/sys/net/if_wg.c	Thu Apr 29 17:55:51 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_wg.c,v 1.62 2020/11/11 18:08:34 riastradh Exp $	*/
+/*	$NetBSD: if_wg.c,v 1.63 2021/04/29 17:55:51 riastradh Exp $	*/
 
 /*
  * Copyright (C) Ryota Ozaki 
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_wg.c,v 1.62 2020/11/11 18:08:34 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_wg.c,v 1.63 2021/04/29 17:55:51 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_altq_enabled.h"
@@ -1075,7 +1075,7 @@ wg_algo_kdf(uint8_t out1[WG_KDF_OUTPUT_L
 	WG_DUMP_HASH("out3", out3);
 }
 
-static void
+static void __noinline
 wg_algo_dh_kdf(uint8_t ckey[WG_CHAINING_KEY_LEN],
 uint8_t cipher_key[WG_CIPHER_KEY_LEN],
 const uint8_t local_key[WG_STATIC_KEY_LEN],
@@ -1407,7 +1407,7 @@ wg_fill_msg_init(struct wg_softc *wg, st
 	WG_DLOG("%s: sender=%x\n", __func__, wgs->wgs_local_index);
 }
 
-static void
+static void __noinline
 wg_handle_msg_init(struct wg_softc *wg, const struct wg_msg_init *wgmi,
 const struct sockaddr *src)
 {
@@ -1838,7 +1838,7 @@ wg_swap_sessions(struct wg_peer *wgp)
 	wgp->wgp_session_unstable = wgs_prev;
 }
 
-static void
+static void __noinline
 wg_handle_msg_resp(struct wg_softc *wg, const struct wg_msg_resp *wgmr,
 const struct sockaddr *src)
 {
@@ -2497,7 +2497,7 @@ wg_update_endpoint_if_necessary(struct w
 	wg_put_sa(wgp, wgsa, );
 }
 
-static void
+static void __noinline
 wg_handle_msg_data(struct wg_softc *wg, struct mbuf *m,
 const struct sockaddr *src)
 {
@@ -2714,7 +2714,7 @@ out:
 		kmem_intr_free(encrypted_buf, encrypted_len);
 }
 
-static void
+static void __noinline
 wg_handle_msg_cookie(struct wg_softc *wg, const struct wg_msg_cookie *wgmc)
 {
 	struct wg_session *wgs;



CVS commit: src/sys/net

2021-04-28 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Wed Apr 28 09:39:39 UTC 2021

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

Log Message:
Introduce a pointer to refer sp->scp[cp->protoidx]

There is no functional difference.


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

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

Modified files:

Index: src/sys/net/if_spppsubr.c
diff -u src/sys/net/if_spppsubr.c:1.227 src/sys/net/if_spppsubr.c:1.228
--- src/sys/net/if_spppsubr.c:1.227	Wed Apr 28 09:36:24 2021
+++ src/sys/net/if_spppsubr.c	Wed Apr 28 09:39:39 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppsubr.c,v 1.227 2021/04/28 09:36:24 yamaguchi Exp $	 */
+/*	$NetBSD: if_spppsubr.c,v 1.228 2021/04/28 09:39:39 yamaguchi Exp $	 */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.227 2021/04/28 09:36:24 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.228 2021/04/28 09:39:39 yamaguchi Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -1642,12 +1642,15 @@ sppp_cp_input(const struct cp *cp, struc
 {
 	STDDCL;
 	struct lcp_header *h;
+	struct sppp_cp *scp;
 	int printlen, len = m->m_pkthdr.len;
 	u_char *p;
 	uint32_t u32;
 
 	SPPP_LOCK(sp, RW_WRITER);
 
+	scp = >scp[cp->protoidx];
+
 	if (len < 4) {
 		if (debug)
 			log(LOG_DEBUG,
@@ -1661,7 +1664,7 @@ sppp_cp_input(const struct cp *cp, struc
 		log(LOG_DEBUG,
 		"%s: %s input(%s): <%s id=0x%x len=%d",
 		ifp->if_xname, cp->name,
-		sppp_state_name(sp->scp[cp->protoidx].state),
+		sppp_state_name(scp->state),
 		sppp_cp_type_name(h->type), h->ident, printlen);
 		if (len < printlen)
 			printlen = len;
@@ -1683,62 +1686,62 @@ sppp_cp_input(const struct cp *cp, struc
 			break;
 		}
 
-		sp->scp[cp->protoidx].rcr_type = CP_RCR_NONE;
-		sp->scp[cp->protoidx].rconfid = h->ident;
-		if (sp->scp[cp->protoidx].mbuf_confreq != NULL) {
-			m_freem(sp->scp[cp->protoidx].mbuf_confreq);
+		scp->rcr_type = CP_RCR_NONE;
+		scp->rconfid = h->ident;
+		if (scp->mbuf_confreq != NULL) {
+			m_freem(scp->mbuf_confreq);
 		}
-		sp->scp[cp->protoidx].mbuf_confreq = m;
+		scp->mbuf_confreq = m;
 		m = NULL;
-		sppp_wq_add(sp->wq_cp, >scp[cp->protoidx].work_rcr);
+		sppp_wq_add(sp->wq_cp, >work_rcr);
 		break;
 	case CONF_ACK:
-		if (h->ident != sp->scp[cp->protoidx].confid) {
+		if (h->ident != scp->confid) {
 			if (debug)
 addlog("%s: %s id mismatch 0x%x != 0x%x\n",
    ifp->if_xname, cp->name,
-   h->ident, sp->scp[cp->protoidx].confid);
+   h->ident, scp->confid);
 			if_statinc(ifp, if_ierrors);
 			break;
 		}
-		sppp_wq_add(sp->wq_cp, >scp[cp->protoidx].work_rca);
+		sppp_wq_add(sp->wq_cp, >work_rca);
 		break;
 	case CONF_NAK:
 	case CONF_REJ:
-		if (h->ident != sp->scp[cp->protoidx].confid) {
+		if (h->ident != scp->confid) {
 			if (debug)
 addlog("%s: %s id mismatch 0x%x != 0x%x\n",
    ifp->if_xname, cp->name,
-   h->ident, sp->scp[cp->protoidx].confid);
+   h->ident, scp->confid);
 			if_statinc(ifp, if_ierrors);
 			break;
 		}
 
-		if (sp->scp[cp->protoidx].mbuf_confnak) {
-			m_freem(sp->scp[cp->protoidx].mbuf_confnak);
+		if (scp->mbuf_confnak) {
+			m_freem(scp->mbuf_confnak);
 		}
-		sp->scp[cp->protoidx].mbuf_confnak = m;
+		scp->mbuf_confnak = m;
 		m = NULL;
-		sppp_wq_add(sp->wq_cp, >scp[cp->protoidx].work_rcn);
+		sppp_wq_add(sp->wq_cp, >work_rcn);
 		break;
 	case TERM_REQ:
-		sp->scp[cp->protoidx].rseq = h->ident;
-		sppp_wq_add(sp->wq_cp, >scp[cp->protoidx].work_rtr);
+		scp->rseq = h->ident;
+		sppp_wq_add(sp->wq_cp, >work_rtr);
 		break;
 	case TERM_ACK:
-		if (h->ident != sp->scp[cp->protoidx].confid &&
-		h->ident != sp->scp[cp->protoidx].seq) {
+		if (h->ident != scp->confid &&
+		h->ident != scp->seq) {
 			if (debug)
 addlog("%s: %s id mismatch "
 "0x%x != 0x%x and 0x%x != %0lx\n",
 ifp->if_xname, cp->name,
-h->ident, sp->scp[cp->protoidx].confid,
-h->ident, sp->scp[cp->protoidx].seq);
+h->ident, scp->confid,
+h->ident, scp->seq);
 			if_statinc(ifp, if_ierrors);
 			break;
 		}
 
-		sppp_wq_add(sp->wq_cp, >scp[cp->protoidx].work_rta);
+		sppp_wq_add(sp->wq_cp, >work_rta);
 		break;
 	case CODE_REJ:
 		/* XXX catastrophic rejects (RXJ-) aren't handled yet. */
@@ -1747,7 +1750,7 @@ sppp_cp_input(const struct cp *cp, struc
 		"danger will robinson\n",
 		ifp->if_xname, cp->name,
 		sppp_cp_type_name(h->type));
-		sppp_wq_add(sp->wq_cp, >scp[cp->protoidx].work_rxj);
+		sppp_wq_add(sp->wq_cp, >work_rxj);
 		break;
 	case PROTO_REJ:
 	{
@@ -1787,7 +1790,7 @@ sppp_cp_input(const struct cp *cp, struc
 break;
 			}
 		}
-		sppp_wq_add(sp->wq_cp, >scp[cp->protoidx].work_rxj);
+		sppp_wq_add(sp->wq_cp, >work_rxj);
 		break;
 	}
 	case DISC_REQ:
@@ -1798,7 +1801,7 @@ 

CVS commit: src/sys/net

2021-04-28 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Wed Apr 28 09:36:24 UTC 2021

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

Log Message:
Move paese of conf-req, conf-nak and conf-rej into workqueue
from softint context

When the pases were processed in softint, the state machine
in if_spppsubr.c had been broken by simultaneous events
on rare occasions.

Example:
 1. Do ifconfig pppoe* up
- lcp open event is enqueued to workqueue
 2. Receive conf-ack, and parse the packet
- save mru to sp->lcp.their_mru
- lcp RCR+ event is enqueued to workqueue
 3. Process lcp open event
- initialize data including sp->lcp.their_mru
 4. Process lcp RCR+ event
- Use sp->lcp.their_mru
- but it was initialized


To generate a diff of this commit:
cvs rdiff -u -r1.226 -r1.227 src/sys/net/if_spppsubr.c
cvs rdiff -u -r1.33 -r1.34 src/sys/net/if_spppvar.h

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

Modified files:

Index: src/sys/net/if_spppsubr.c
diff -u src/sys/net/if_spppsubr.c:1.226 src/sys/net/if_spppsubr.c:1.227
--- src/sys/net/if_spppsubr.c:1.226	Mon Apr 26 08:45:57 2021
+++ src/sys/net/if_spppsubr.c	Wed Apr 28 09:36:24 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppsubr.c,v 1.226 2021/04/26 08:45:57 yamaguchi Exp $	 */
+/*	$NetBSD: if_spppsubr.c,v 1.227 2021/04/28 09:36:24 yamaguchi Exp $	 */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.226 2021/04/26 08:45:57 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.227 2021/04/28 09:36:24 yamaguchi Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -258,7 +258,8 @@ struct cp {
 	void	(*tls)(const struct cp *, struct sppp *);
 	void	(*tlf)(const struct cp *, struct sppp *);
 	void	(*scr)(struct sppp *);
-	void	(*scan)(const struct cp *, struct sppp *);
+	void	(*screply)(const struct cp *, struct sppp *, u_char,
+		uint8_t, size_t, void *);
 
 	/* message parser */
 	enum cp_rcr_type
@@ -347,8 +348,8 @@ static void sppp_auth_send(const struct 
 			unsigned int, unsigned int, ...);
 static int sppp_auth_role(const struct cp *, struct sppp *);
 static void sppp_auth_to_event(struct sppp *, void *);
-static void sppp_auth_sca_scn(const struct cp *, struct sppp *);
-
+static void sppp_auth_screply(const struct cp *, struct sppp *,
+			u_char, uint8_t, size_t, void *);
 static void sppp_up_event(struct sppp *, void *);
 static void sppp_down_event(struct sppp *, void *);
 static void sppp_open_event(struct sppp *, void *);
@@ -364,7 +365,8 @@ static void sppp_rxj_event(struct sppp *
 static void sppp_null(struct sppp *);
 static void sppp_tls(const struct cp *, struct sppp *);
 static void sppp_tlf(const struct cp *, struct sppp *);
-static void sppp_sca_scn(const struct cp *, struct sppp *);
+static void sppp_screply(const struct cp *, struct sppp *,
+		u_char, uint8_t, size_t, void *);
 static void sppp_ifdown(struct sppp *, void *);
 
 static void sppp_lcp_init(struct sppp *);
@@ -466,7 +468,7 @@ static const struct cp lcp = {
 	sppp_lcp_up, sppp_lcp_down, sppp_lcp_open,
 	sppp_close_event, sppp_to_event,
 	sppp_lcp_tlu, sppp_lcp_tld, sppp_lcp_tls,
-	sppp_lcp_tlf, sppp_lcp_scr, sppp_sca_scn,
+	sppp_lcp_tlf, sppp_lcp_scr, sppp_screply,
 	sppp_lcp_confreq, sppp_lcp_confrej, sppp_lcp_confnak
 };
 
@@ -481,7 +483,7 @@ static const struct cp ipcp = {
 	sppp_up_event, sppp_down_event, sppp_ipcp_open,
 	sppp_ipcp_close, sppp_to_event,
 	sppp_ipcp_tlu, sppp_null, sppp_tls,
-	sppp_tlf, sppp_ipcp_scr, sppp_sca_scn,
+	sppp_tlf, sppp_ipcp_scr, sppp_screply,
 	sppp_ipcp_confreq, sppp_ipcp_confrej, sppp_ipcp_confnak,
 };
 
@@ -496,7 +498,7 @@ static const struct cp ipv6cp = {
 	sppp_up_event, sppp_down_event, sppp_ipv6cp_open,
 	sppp_close_event, sppp_to_event,
 	sppp_ipv6cp_tlu, sppp_null, sppp_tls,
-	sppp_tlf, sppp_ipv6cp_scr, sppp_sca_scn,
+	sppp_tlf, sppp_ipv6cp_scr, sppp_screply,
 	sppp_ipv6cp_confreq, sppp_ipv6cp_confrej, sppp_ipv6cp_confnak,
 };
 
@@ -505,7 +507,7 @@ static const struct cp pap = {
 	sppp_up_event, sppp_down_event, sppp_open_event,
 	sppp_close_event, sppp_to_event,
 	sppp_pap_tlu, sppp_null, sppp_tls, sppp_tlf,
-	sppp_pap_scr, sppp_auth_sca_scn,
+	sppp_pap_scr, sppp_auth_screply,
 	NULL, NULL, NULL
 };
 
@@ -514,7 +516,7 @@ static const struct cp chap = {
 	sppp_up_event, sppp_down_event, sppp_chap_open,
 	sppp_close_event, sppp_auth_to_event,
 	sppp_chap_tlu, sppp_null, sppp_tls, sppp_tlf,
-	sppp_chap_scr, sppp_auth_sca_scn,
+	sppp_chap_scr, sppp_auth_screply,
 	NULL, NULL, NULL
 };
 
@@ -680,7 +682,7 @@ sppp_input(struct ifnet *ifp, struct mbu
 	case PPP_LCP:
 		SPPP_UNLOCK(sp);
 		sppp_cp_input(, sp, m);
-		m_freem(m);
+		/* already m_freem(m) */
 		return;
 	case PPP_PAP:
 		SPPP_UNLOCK(sp);
@@ -701,8 +703,10 @@ sppp_input(struct ifnet *ifp, struct mbu
 		SPPP_UNLOCK(sp);
 		if (sp->pp_phase == 

CVS commit: src/sys/net

2021-04-26 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Mon Apr 26 08:45:57 UTC 2021

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

Log Message:
Fix the wrong CHAP option length in conf-nak

RFC 1994 defines that the CHAP option length in conf-nak is 5.
However, 4 was used when CHAP is cofigured and PPP is proposed
by a peer.


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

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

Modified files:

Index: src/sys/net/if_spppsubr.c
diff -u src/sys/net/if_spppsubr.c:1.225 src/sys/net/if_spppsubr.c:1.226
--- src/sys/net/if_spppsubr.c:1.225	Mon Apr 26 08:42:19 2021
+++ src/sys/net/if_spppsubr.c	Mon Apr 26 08:45:57 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppsubr.c,v 1.225 2021/04/26 08:42:19 yamaguchi Exp $	 */
+/*	$NetBSD: if_spppsubr.c,v 1.226 2021/04/26 08:45:57 yamaguchi Exp $	 */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.225 2021/04/26 08:42:19 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.226 2021/04/26 08:45:57 yamaguchi Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -2876,22 +2876,39 @@ sppp_lcp_confreq(struct sppp *sp, struct
 if (authproto == PPP_PAP || authproto == PPP_CHAP)
 	sp->myauth.proto = authproto;
 			}
-			if (sp->myauth.proto != authproto) {
-/* not agreed, nak */
+			if (sp->myauth.proto == authproto) {
+if (authproto != PPP_CHAP || p[4] == CHAP_MD5) {
+	continue;
+}
+if (debug)
+	addlog(" [chap without MD5]");
+			} else {
 if (debug)
 	addlog(" [mine %s != his %s]",
 	   sppp_proto_name(sp->myauth.proto),
 	   sppp_proto_name(authproto));
-p[2] = sp->myauth.proto >> 8;
-p[3] = sp->myauth.proto;
-break;
 			}
-			if (authproto == PPP_CHAP && p[4] != CHAP_MD5) {
+			/* not agreed, nak */
+			if (sp->myauth.proto == PPP_CHAP) {
+l = 5;
+			} else {
+l = 4;
+			}
+
+			if (rlen + l > blen) {
 if (debug)
-	addlog(" [chap not MD5]");
-p[4] = CHAP_MD5;
-break;
+	addlog(" [overflow]");
+continue;
 			}
+
+			r[0] = LCP_OPT_AUTH_PROTO;
+			r[1] = l;
+			r[2] = sp->myauth.proto >> 8;
+			r[3] = sp->myauth.proto & 0xff;
+			if (sp->myauth.proto == PPP_CHAP)
+r[4] = CHAP_MD5;
+			rlen += l;
+			r += l;
 			continue;
 		case LCP_OPT_MP_EID:
 			/*



CVS commit: src/sys/net

2021-04-26 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Mon Apr 26 08:42:19 UTC 2021

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

Log Message:
Avoid updating of the state if the state is not changed
not to reset the timer for state machine


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

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

Modified files:

Index: src/sys/net/if_spppsubr.c
diff -u src/sys/net/if_spppsubr.c:1.224 src/sys/net/if_spppsubr.c:1.225
--- src/sys/net/if_spppsubr.c:1.224	Mon Apr 26 08:37:54 2021
+++ src/sys/net/if_spppsubr.c	Mon Apr 26 08:42:19 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppsubr.c,v 1.224 2021/04/26 08:37:54 yamaguchi Exp $	 */
+/*	$NetBSD: if_spppsubr.c,v 1.225 2021/04/26 08:42:19 yamaguchi Exp $	 */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.224 2021/04/26 08:37:54 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.225 2021/04/26 08:42:19 yamaguchi Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -2153,9 +2153,10 @@ sppp_rcr_event(struct sppp *sp, void *xc
 			cp->scr(sp);
 			cp->scan(cp, sp);
 			break;
-		case STATE_ACK_SENT:
 		case STATE_REQ_SENT:
 			sppp_cp_change_state(cp, sp, STATE_ACK_SENT);
+			/* fall through */
+		case STATE_ACK_SENT:
 			cp->scan(cp, sp);
 			break;
 		case STATE_STOPPED:
@@ -2202,8 +2203,9 @@ sppp_rcr_event(struct sppp *sp, void *xc
 			cp->scan(cp, sp);
 			break;
 		case STATE_ACK_SENT:
-		case STATE_REQ_SENT:
 			sppp_cp_change_state(cp, sp, STATE_REQ_SENT);
+			/* fall through */
+		case STATE_REQ_SENT:
 			cp->scan(cp, sp);
 			break;
 		case STATE_STOPPED:



CVS commit: src/sys/net

2021-04-26 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Mon Apr 26 08:37:54 UTC 2021

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

Log Message:
Reset LCP fail counter when doing "ifconfig pppoe* up"


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

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

Modified files:

Index: src/sys/net/if_spppsubr.c
diff -u src/sys/net/if_spppsubr.c:1.223 src/sys/net/if_spppsubr.c:1.224
--- src/sys/net/if_spppsubr.c:1.223	Mon Apr 26 08:34:22 2021
+++ src/sys/net/if_spppsubr.c	Mon Apr 26 08:37:54 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppsubr.c,v 1.223 2021/04/26 08:34:22 yamaguchi Exp $	 */
+/*	$NetBSD: if_spppsubr.c,v 1.224 2021/04/26 08:37:54 yamaguchi Exp $	 */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.223 2021/04/26 08:34:22 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.224 2021/04/26 08:37:54 yamaguchi Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -2593,6 +2593,7 @@ sppp_lcp_open(struct sppp *sp, void *xcp
 	KASSERT(!cpu_softintr_p());
 
 	sp->lcp.reestablish = false;
+	sp->scp[IDX_LCP].fail_counter = 0;
 
 	if (sp->pp_if.if_mtu < PP_MTU) {
 		sp->lcp.mru = sp->pp_if.if_mtu;



CVS commit: src/sys/net

2021-04-26 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Mon Apr 26 08:34:22 UTC 2021

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

Log Message:
Added ipcp option name for logging


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

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

Modified files:

Index: src/sys/net/if_spppsubr.c
diff -u src/sys/net/if_spppsubr.c:1.222 src/sys/net/if_spppsubr.c:1.223
--- src/sys/net/if_spppsubr.c:1.222	Mon Apr 26 08:31:21 2021
+++ src/sys/net/if_spppsubr.c	Mon Apr 26 08:34:22 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppsubr.c,v 1.222 2021/04/26 08:31:21 yamaguchi Exp $	 */
+/*	$NetBSD: if_spppsubr.c,v 1.223 2021/04/26 08:34:22 yamaguchi Exp $	 */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.222 2021/04/26 08:31:21 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.223 2021/04/26 08:34:22 yamaguchi Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -6297,6 +6297,8 @@ sppp_ipcp_opt_name(u_char opt)
 	case IPCP_OPT_ADDRESSES:	return "addresses";
 	case IPCP_OPT_COMPRESSION:	return "compression";
 	case IPCP_OPT_ADDRESS:		return "address";
+	case IPCP_OPT_PRIMDNS:		return "primdns";
+	case IPCP_OPT_SECDNS:		return "secdns";
 	}
 	snprintf(buf, sizeof(buf), "0x%x", opt);
 	return buf;



CVS commit: src/sys/net

2021-04-26 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Mon Apr 26 08:31:21 UTC 2021

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

Log Message:
Ignore 0.0.0.0 offered from PPPoE server


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

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

Modified files:

Index: src/sys/net/if_spppsubr.c
diff -u src/sys/net/if_spppsubr.c:1.221 src/sys/net/if_spppsubr.c:1.222
--- src/sys/net/if_spppsubr.c:1.221	Mon Apr 26 02:36:45 2021
+++ src/sys/net/if_spppsubr.c	Mon Apr 26 08:31:21 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppsubr.c,v 1.221 2021/04/26 02:36:45 yamaguchi Exp $	 */
+/*	$NetBSD: if_spppsubr.c,v 1.222 2021/04/26 08:31:21 yamaguchi Exp $	 */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.221 2021/04/26 02:36:45 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.222 2021/04/26 08:31:21 yamaguchi Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -3825,10 +3825,15 @@ sppp_ipcp_confnak(struct sppp *sp, struc
  * our already existing value.
  */
 if (sp->ipcp.flags & IPCP_MYADDR_DYN) {
-	if (debug)
-		addlog(" [agree]");
-	sp->ipcp.flags |= IPCP_MYADDR_SEEN;
-	sp->ipcp.req_myaddr = wantaddr;
+	if (ntohl(wantaddr) != INADDR_ANY) {
+		if (debug)
+			addlog(" [agree]");
+		sp->ipcp.flags |= IPCP_MYADDR_SEEN;
+		sp->ipcp.req_myaddr = wantaddr;
+	} else {
+		if (debug)
+			addlog(" [not agreed]");
+	}
 }
 			}
 			break;
@@ -3865,9 +3870,20 @@ static void
 sppp_ipcp_tlu(struct sppp *sp)
 {
 #ifdef INET
+	struct ifnet *ifp;
+
+	ifp = >pp_if;
 	KASSERT(SPPP_WLOCKED(sp));
-	/* we are up. Set addresses and notify anyone interested */
-	sppp_set_ip_addrs(sp);
+	if ((sp->ipcp.flags & IPCP_MYADDR_DYN) &&
+	((sp->ipcp.flags & IPCP_MYADDR_SEEN) == 0)) {
+		log(LOG_WARNING, "%s: no IP address, closing IPCP\n",
+		ifp->if_xname);
+		sppp_wq_add(sp->wq_cp,
+		>scp[IDX_IPCP].work_close);
+	} else {
+		/* we are up. Set addresses and notify anyone interested */
+		sppp_set_ip_addrs(sp);
+	}
 #endif
 }
 



CVS commit: src/sys/net

2021-04-25 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Mon Apr 26 02:36:46 UTC 2021

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

Log Message:
Fix locking order since IFNET_LOCK must be held
before acquiring SPPP_LOCK


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

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

Modified files:

Index: src/sys/net/if_spppsubr.c
diff -u src/sys/net/if_spppsubr.c:1.220 src/sys/net/if_spppsubr.c:1.221
--- src/sys/net/if_spppsubr.c:1.220	Fri Apr 23 03:36:13 2021
+++ src/sys/net/if_spppsubr.c	Mon Apr 26 02:36:45 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppsubr.c,v 1.220 2021/04/23 03:36:13 yamaguchi Exp $	 */
+/*	$NetBSD: if_spppsubr.c,v 1.221 2021/04/26 02:36:45 yamaguchi Exp $	 */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.220 2021/04/23 03:36:13 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.221 2021/04/26 02:36:45 yamaguchi Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -5542,7 +5542,10 @@ sppp_set_ip_addrs(struct sppp *sp)
 	uint32_t myaddr = 0, hisaddr = 0;
 	int s;
 
+	KASSERT(SPPP_WLOCKED(sp));
+	SPPP_UNLOCK(sp);
 	IFNET_LOCK(ifp);
+	SPPP_LOCK(sp, RW_WRITER);
 
 	/*
 	 * Pick the first AF_INET address from the list,
@@ -5614,7 +5617,10 @@ sppp_clear_ip_addrs(struct sppp *sp)
 	struct sockaddr_in *si, *dest;
 	int s;
 
+	KASSERT(SPPP_WLOCKED(sp));
+	SPPP_UNLOCK(sp);
 	IFNET_LOCK(ifp);
+	SPPP_LOCK(sp, RW_WRITER);
 
 	/*
 	 * Pick the first AF_INET address from the list,
@@ -5740,7 +5746,10 @@ sppp_set_ip6_addr(struct sppp *sp, const
 	int s;
 	struct psref psref;
 
+	KASSERT(SPPP_WLOCKED(sp));
+	SPPP_UNLOCK(sp);
 	IFNET_LOCK(ifp);
+	SPPP_LOCK(sp, RW_WRITER);
 
 	/*
 	 * Pick the first link-local AF_INET6 address from the list,



CVS commit: src/sys/net

2021-04-22 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Fri Apr 23 03:36:13 UTC 2021

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

Log Message:
Adjust mtu at LCP instead at IPCP

The adjustment must be done at LCP when a PPPoE connection
does not use IPCP.


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

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

Modified files:

Index: src/sys/net/if_spppsubr.c
diff -u src/sys/net/if_spppsubr.c:1.219 src/sys/net/if_spppsubr.c:1.220
--- src/sys/net/if_spppsubr.c:1.219	Fri Apr 23 03:31:33 2021
+++ src/sys/net/if_spppsubr.c	Fri Apr 23 03:36:13 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppsubr.c,v 1.219 2021/04/23 03:31:33 yamaguchi Exp $	 */
+/*	$NetBSD: if_spppsubr.c,v 1.220 2021/04/23 03:36:13 yamaguchi Exp $	 */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.219 2021/04/23 03:31:33 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.220 2021/04/23 03:36:13 yamaguchi Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -1166,6 +1166,7 @@ sppp_ioctl(struct ifnet *ifp, u_long cmd
 	struct sppp *sp = (struct sppp *) ifp;
 	int s, error=0, going_up, going_down;
 	u_short newmode;
+	u_long lcp_mru;
 
 	s = splnet();
 	switch (cmd) {
@@ -1221,17 +1222,31 @@ sppp_ioctl(struct ifnet *ifp, u_long cmd
 		if (error == ENETRESET)
 			error = 0;
 
-		if (sp->lcp.their_mru > 0 &&
+		SPPP_LOCK(sp, RW_WRITER);
+		lcp_mru = sp->lcp.mru;
+		if (ifp->if_mtu < PP_MTU) {
+			sp->lcp.mru = ifp->if_mtu;
+		} else {
+			sp->lcp.mru = PP_MTU;
+		}
+		if (lcp_mru != sp->lcp.mru)
+			SET(sp->lcp.opts, SPPP_LCP_OPT_MRU);
+
+		if (sp->scp[IDX_LCP].state == STATE_OPENED &&
 		ifp->if_mtu > sp->lcp.their_mru) {
 			sp->pp_saved_mtu = ifp->if_mtu;
 			ifp->if_mtu = sp->lcp.their_mru;
+
 			if (ifp->if_flags & IFF_DEBUG) {
 log(LOG_DEBUG,
-"%s: setting MTU to "
-"%"PRIu64" bytes\n",
-ifp->if_xname, ifp->if_mtu);
+"%s: setting MTU "
+"from %"PRIu64" bytes "
+"to %"PRIu64" bytes\n",
+ifp->if_xname, sp->pp_saved_mtu,
+ifp->if_mtu);
 			}
 		}
+		SPPP_UNLOCK(sp);
 		break;
 
 	case SIOCGIFMTU:
@@ -2582,8 +2597,9 @@ sppp_lcp_open(struct sppp *sp, void *xcp
 	if (sp->pp_if.if_mtu < PP_MTU) {
 		sp->lcp.mru = sp->pp_if.if_mtu;
 		SET(sp->lcp.opts, SPPP_LCP_OPT_MRU);
-	} else
+	} else {
 		sp->lcp.mru = PP_MTU;
+	}
 	sp->lcp.their_mru = PP_MTU;
 
 	/*
@@ -2597,6 +2613,7 @@ sppp_lcp_open(struct sppp *sp, void *xcp
 	sppp_open_event(sp, xcp);
 }
 
+
 /*
  * Analyze a configure request.  Return true if it was agreeable, and
  * caused action sca, false if it has been rejected or nak'ed, and
@@ -3115,20 +3132,38 @@ end:
 static void
 sppp_lcp_tlu(struct sppp *sp)
 {
-	struct ifnet *ifp = >pp_if;
+	STDDCL;
 	int i;
 
 	KASSERT(SPPP_WLOCKED(sp));
 
+	/* unlock for IFNET_LOCK and if_up() */
+	SPPP_UNLOCK(sp);
+
 	/* XXX ? */
 	if (! (ifp->if_flags & IFF_UP) &&
 	(ifp->if_flags & IFF_RUNNING)) {
 		/* Coming out of loopback mode. */
-		SPPP_UNLOCK(sp);
 		if_up(ifp);
-		SPPP_LOCK(sp, RW_WRITER);
 	}
 
+	IFNET_LOCK(ifp);
+	SPPP_LOCK(sp, RW_WRITER);
+
+	if (ifp->if_mtu > sp->lcp.their_mru) {
+		sp->pp_saved_mtu = ifp->if_mtu;
+		ifp->if_mtu = sp->lcp.their_mru;
+		if (debug) {
+			log(LOG_DEBUG,
+			"%s: setting MTU "
+			"from %"PRIu64" bytes "
+			"to %"PRIu64" bytes\n",
+			ifp->if_xname, sp->pp_saved_mtu,
+			ifp->if_mtu);
+		}
+	}
+	IFNET_UNLOCK(ifp);
+
 	if (ISSET(sp->lcp.opts, SPPP_LCP_OPT_AUTH_PROTO) ||
 	(sp->pp_flags & PP_NEEDAUTH) != 0)
 		sppp_change_phase(sp, SPPP_PHASE_AUTHENTICATE);
@@ -3164,6 +3199,7 @@ sppp_lcp_tlu(struct sppp *sp)
 static void
 sppp_lcp_tld(struct sppp *sp)
 {
+	STDDCL;
 	int i, pi, phase;
 
 	KASSERT(SPPP_WLOCKED(sp));
@@ -3172,6 +3208,25 @@ sppp_lcp_tld(struct sppp *sp)
 
 	sppp_change_phase(sp, SPPP_PHASE_TERMINATE);
 
+	if (sp->pp_saved_mtu > 0) {
+		SPPP_UNLOCK(sp);
+		IFNET_LOCK(ifp);
+		SPPP_LOCK(sp, RW_WRITER);
+
+		if (debug) {
+			log(LOG_DEBUG,
+			"%s: setting MTU "
+			"from %"PRIu64" bytes "
+			"to %"PRIu64" bytes\n",
+			ifp->if_xname, ifp->if_mtu,
+			sp->pp_saved_mtu);
+		}
+
+		ifp->if_mtu = sp->pp_saved_mtu;
+		sp->pp_saved_mtu = 0;
+		IFNET_UNLOCK(ifp);
+	}
+
 	/*
 	 * Take upper layers down.  We send the Down event first and
 	 * the Close second to prevent the upper layers from sending
@@ -5543,15 +5598,6 @@ sppp_set_ip_addrs(struct sppp *sp)
 		}
 	}
 
-	if (ifp->if_mtu > sp->lcp.their_mru) {
-		sp->pp_saved_mtu = ifp->if_mtu;
-		ifp->if_mtu = sp->lcp.their_mru;
-		if (debug)
-			log(LOG_DEBUG,
-			"%s: setting MTU to %" PRIu64 " bytes\n",
-			ifp->if_xname, ifp->if_mtu);
-	}
-
 	IFNET_UNLOCK(ifp);
 
 	sppp_notify_con(sp);
@@ -5611,15 +5657,6 @@ sppp_clear_ip_addrs(struct sppp *sp)
 		}
 	}
 
-	if 

CVS commit: src/sys/net

2021-04-22 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Fri Apr 23 03:31:33 UTC 2021

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

Log Message:
Fix to set mtu even if it is bigger than mru notified at LCP


To generate a diff of this commit:
cvs rdiff -u -r1.218 -r1.219 src/sys/net/if_spppsubr.c

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

Modified files:

Index: src/sys/net/if_spppsubr.c
diff -u src/sys/net/if_spppsubr.c:1.218 src/sys/net/if_spppsubr.c:1.219
--- src/sys/net/if_spppsubr.c:1.218	Fri Apr 23 01:13:25 2021
+++ src/sys/net/if_spppsubr.c	Fri Apr 23 03:31:33 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppsubr.c,v 1.218 2021/04/23 01:13:25 yamaguchi Exp $	 */
+/*	$NetBSD: if_spppsubr.c,v 1.219 2021/04/23 03:31:33 yamaguchi Exp $	 */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.218 2021/04/23 01:13:25 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.219 2021/04/23 03:31:33 yamaguchi Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -1212,11 +1212,28 @@ sppp_ioctl(struct ifnet *ifp, u_long cmd
 
 	case SIOCSIFMTU:
 		if (ifr->ifr_mtu < PPP_MINMRU ||
-		ifr->ifr_mtu > sp->lcp.their_mru) {
+		ifr->ifr_mtu > PP_MTU) {
 			error = EINVAL;
 			break;
 		}
-		/*FALLTHROUGH*/
+
+		error = ifioctl_common(ifp, cmd, data);
+		if (error == ENETRESET)
+			error = 0;
+
+		if (sp->lcp.their_mru > 0 &&
+		ifp->if_mtu > sp->lcp.their_mru) {
+			sp->pp_saved_mtu = ifp->if_mtu;
+			ifp->if_mtu = sp->lcp.their_mru;
+			if (ifp->if_flags & IFF_DEBUG) {
+log(LOG_DEBUG,
+"%s: setting MTU to "
+"%"PRIu64" bytes\n",
+ifp->if_xname, ifp->if_mtu);
+			}
+		}
+		break;
+
 	case SIOCGIFMTU:
 		if ((error = ifioctl_common(ifp, cmd, data)) == ENETRESET)
 			error = 0;



CVS commit: src/sys/net

2021-04-22 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Fri Apr 23 01:13:26 UTC 2021

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

Log Message:
Introduct a new flag to accept different authentication protocol
in myauthproto and hisauthproto

When the flag is enabled, a authentication protocol notified
at LCP negotiation is used as my authentication protocol.
When the flags is NOT enabled, my authentication protoco is
not changed at LCP negotiation.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/sys/net/if_sppp.h
cvs rdiff -u -r1.217 -r1.218 src/sys/net/if_spppsubr.c

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

Modified files:

Index: src/sys/net/if_sppp.h
diff -u src/sys/net/if_sppp.h:1.30 src/sys/net/if_sppp.h:1.31
--- src/sys/net/if_sppp.h:1.30	Wed Dec  2 14:20:20 2020
+++ src/sys/net/if_sppp.h	Fri Apr 23 01:13:25 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_sppp.h,v 1.30 2020/12/02 14:20:20 wiz Exp $	*/
+/*	$NetBSD: if_sppp.h,v 1.31 2021/04/23 01:13:25 yamaguchi Exp $	*/
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -44,6 +44,7 @@
 #define SPPP_AUTHFLAG_NOCALLOUT		1	/* do not require authentication on */
 		/* callouts */
 #define SPPP_AUTHFLAG_NORECHALLENGE	2	/* do not re-challenge CHAP */
+#define SPPP_AUTHFLAG_PASSIVEAUTHPROTO	4	/* use authproto proposed by peer */
 
 struct spppauthcfg {
 	char	ifname[IFNAMSIZ];	/* pppoe interface name */

Index: src/sys/net/if_spppsubr.c
diff -u src/sys/net/if_spppsubr.c:1.217 src/sys/net/if_spppsubr.c:1.218
--- src/sys/net/if_spppsubr.c:1.217	Fri Apr 16 02:12:00 2021
+++ src/sys/net/if_spppsubr.c	Fri Apr 23 01:13:25 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppsubr.c,v 1.217 2021/04/16 02:12:00 yamaguchi Exp $	 */
+/*	$NetBSD: if_spppsubr.c,v 1.218 2021/04/23 01:13:25 yamaguchi Exp $	 */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.217 2021/04/16 02:12:00 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.218 2021/04/23 01:13:25 yamaguchi Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -2701,6 +2701,10 @@ sppp_lcp_confreq(struct sppp *sp, struct
 	addlog(" [invalid chap len]");
 break;
 			}
+			if (ISSET(sp->myauth.flags, SPPP_AUTHFLAG_PASSIVEAUTHPROTO)) {
+if (authproto == PPP_PAP || authproto == PPP_CHAP)
+	sp->myauth.proto = authproto;
+			}
 			if (sp->myauth.proto == 0) {
 /* we are not configured to do auth */
 if (debug)
@@ -2831,6 +2835,10 @@ sppp_lcp_confreq(struct sppp *sp, struct
 
 		case LCP_OPT_AUTH_PROTO:
 			authproto = (p[2] << 8) + p[3];
+			if (ISSET(sp->myauth.flags, SPPP_AUTHFLAG_PASSIVEAUTHPROTO)) {
+if (authproto == PPP_PAP || authproto == PPP_CHAP)
+	sp->myauth.proto = authproto;
+			}
 			if (sp->myauth.proto != authproto) {
 /* not agreed, nak */
 if (debug)



CVS commit: src/sys/net

2021-04-22 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Thu Apr 22 10:26:24 UTC 2021

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

Log Message:
Added missing free of sc_hunique to prevent memory leak
when using PPPoE server


To generate a diff of this commit:
cvs rdiff -u -r1.169 -r1.170 src/sys/net/if_pppoe.c

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

Modified files:

Index: src/sys/net/if_pppoe.c
diff -u src/sys/net/if_pppoe.c:1.169 src/sys/net/if_pppoe.c:1.170
--- src/sys/net/if_pppoe.c:1.169	Fri Apr 16 02:23:25 2021
+++ src/sys/net/if_pppoe.c	Thu Apr 22 10:26:24 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: if_pppoe.c,v 1.169 2021/04/16 02:23:25 yamaguchi Exp $ */
+/* $NetBSD: if_pppoe.c,v 1.170 2021/04/22 10:26:24 yamaguchi Exp $ */
 
 /*
  * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.169 2021/04/16 02:23:25 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.170 2021/04/22 10:26:24 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "pppoe.h"
@@ -448,6 +448,13 @@ pppoe_clone_destroy(struct ifnet *ifp)
 	callout_halt(>sc_timeout, NULL);
 	callout_destroy(>sc_timeout);
 
+#ifdef PPPOE_SERVER
+	if (sc->sc_hunique) {
+		free(sc->sc_hunique, M_DEVBUF);
+		sc->sc_hunique = NULL;
+		sc->sc_hunique_len = 0;
+	}
+#endif
 	if (sc->sc_concentrator_name)
 		free(sc->sc_concentrator_name, M_DEVBUF);
 	if (sc->sc_service_name)



CVS commit: src/sys/net

2021-04-15 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Fri Apr 16 02:26:25 UTC 2021

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

Log Message:
Added missing locking order between sppp and IFNET_LOCK


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/sys/net/if_spppvar.h

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

Modified files:

Index: src/sys/net/if_spppvar.h
diff -u src/sys/net/if_spppvar.h:1.32 src/sys/net/if_spppvar.h:1.33
--- src/sys/net/if_spppvar.h:1.32	Wed Nov 25 10:30:51 2020
+++ src/sys/net/if_spppvar.h	Fri Apr 16 02:26:25 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppvar.h,v 1.32 2020/11/25 10:30:51 yamaguchi Exp $	*/
+/*	$NetBSD: if_spppvar.h,v 1.33 2021/04/16 02:26:25 yamaguchi Exp $	*/
 
 #ifndef _NET_IF_SPPPVAR_H_
 #define _NET_IF_SPPPVAR_H_
@@ -240,7 +240,7 @@ void sppp_flush (struct ifnet *);
  * if_spppsubr.c.
  *
  * Locking order:
- *- spppq_lock => struct sppp->pp_lock
+ *- IFNET_LOCK => spppq_lock => struct sppp->pp_lock
  *
  * NOTICE
  * - Lower layers must not acquire sppp->pp_lock



CVS commit: src/sys/net

2021-04-15 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Fri Apr 16 02:23:25 UTC 2021

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

Log Message:
Stop and destroy timeout after sppp_detach and if_detach
for safety

The functions may use resources of pppoe(4) while detaching,
so the release should move after it.


To generate a diff of this commit:
cvs rdiff -u -r1.168 -r1.169 src/sys/net/if_pppoe.c

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

Modified files:

Index: src/sys/net/if_pppoe.c
diff -u src/sys/net/if_pppoe.c:1.168 src/sys/net/if_pppoe.c:1.169
--- src/sys/net/if_pppoe.c:1.168	Fri Apr 16 02:12:00 2021
+++ src/sys/net/if_pppoe.c	Fri Apr 16 02:23:25 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: if_pppoe.c,v 1.168 2021/04/16 02:12:00 yamaguchi Exp $ */
+/* $NetBSD: if_pppoe.c,v 1.169 2021/04/16 02:23:25 yamaguchi Exp $ */
 
 /*
  * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.168 2021/04/16 02:12:00 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.169 2021/04/16 02:23:25 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "pppoe.h"
@@ -436,13 +436,18 @@ pppoe_clone_destroy(struct ifnet *ifp)
 	}
 	rw_exit(_softc_list_lock);
 
+	bpf_detach(ifp);
+	sppp_detach(>sc_sppp.pp_if);
+	if_detach(ifp);
+
 	callout_setfunc(>sc_timeout, pppoe_timeout_co_halt, sc);
+
 	workqueue_wait(sc->sc_timeout_wq, >sc_timeout_wk);
+	workqueue_destroy(sc->sc_timeout_wq);
+
 	callout_halt(>sc_timeout, NULL);
+	callout_destroy(>sc_timeout);
 
-	bpf_detach(ifp);
-	sppp_detach(>sc_sppp.pp_if);
-	if_detach(ifp);
 	if (sc->sc_concentrator_name)
 		free(sc->sc_concentrator_name, M_DEVBUF);
 	if (sc->sc_service_name)
@@ -451,8 +456,6 @@ pppoe_clone_destroy(struct ifnet *ifp)
 		free(sc->sc_ac_cookie, M_DEVBUF);
 	if (sc->sc_relay_sid)
 		free(sc->sc_relay_sid, M_DEVBUF);
-	callout_destroy(>sc_timeout);
-	workqueue_destroy(sc->sc_timeout_wq);
 
 	rw_destroy(>sc_lock);
 



CVS commit: src/sys/net

2021-04-15 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Fri Apr 16 02:12:00 UTC 2021

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

Log Message:
Remove unnecessaly lock holdings to avoid dead lock

The locks were held while callout_halt() and workqueue_wait()
without reason.
And the locks also were held at callout and workqueue handler
so that the handler kicked by those function couldn't acquire
the lock.

The reasons why those are unneccesary are:
 - Items of callout_t are protected by callout_lock
 - Items of struct workqueue and struct work are protected
   by q_mutex in struct workqueue
 - Items of struct sppp_work protected by atomic_cas(3)
 - struct pppoe_softc does not free before workqueue_wait() and
   callout_halt() even if the locks are not held


To generate a diff of this commit:
cvs rdiff -u -r1.167 -r1.168 src/sys/net/if_pppoe.c
cvs rdiff -u -r1.216 -r1.217 src/sys/net/if_spppsubr.c

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

Modified files:

Index: src/sys/net/if_pppoe.c
diff -u src/sys/net/if_pppoe.c:1.167 src/sys/net/if_pppoe.c:1.168
--- src/sys/net/if_pppoe.c:1.167	Fri Apr 16 01:59:50 2021
+++ src/sys/net/if_pppoe.c	Fri Apr 16 02:12:00 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: if_pppoe.c,v 1.167 2021/04/16 01:59:50 yamaguchi Exp $ */
+/* $NetBSD: if_pppoe.c,v 1.168 2021/04/16 02:12:00 yamaguchi Exp $ */
 
 /*
  * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.167 2021/04/16 01:59:50 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.168 2021/04/16 02:12:00 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "pppoe.h"
@@ -436,7 +436,6 @@ pppoe_clone_destroy(struct ifnet *ifp)
 	}
 	rw_exit(_softc_list_lock);
 
-	PPPOE_LOCK(sc, RW_WRITER);
 	callout_setfunc(>sc_timeout, pppoe_timeout_co_halt, sc);
 	workqueue_wait(sc->sc_timeout_wq, >sc_timeout_wk);
 	callout_halt(>sc_timeout, NULL);
@@ -455,7 +454,6 @@ pppoe_clone_destroy(struct ifnet *ifp)
 	callout_destroy(>sc_timeout);
 	workqueue_destroy(sc->sc_timeout_wq);
 
-	PPPOE_UNLOCK(sc);
 	rw_destroy(>sc_lock);
 
 	kmem_free(sc, sizeof(*sc));

Index: src/sys/net/if_spppsubr.c
diff -u src/sys/net/if_spppsubr.c:1.216 src/sys/net/if_spppsubr.c:1.217
--- src/sys/net/if_spppsubr.c:1.216	Fri Apr 16 02:05:37 2021
+++ src/sys/net/if_spppsubr.c	Fri Apr 16 02:12:00 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppsubr.c,v 1.216 2021/04/16 02:05:37 yamaguchi Exp $	 */
+/*	$NetBSD: if_spppsubr.c,v 1.217 2021/04/16 02:12:00 yamaguchi Exp $	 */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.216 2021/04/16 02:05:37 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.217 2021/04/16 02:12:00 yamaguchi Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -1074,8 +1074,6 @@ sppp_detach(struct ifnet *ifp)
 		spppq_lock = NULL;
 	}
 
-	SPPP_LOCK(sp, RW_WRITER);
-
 	sppp_cp_fini(, sp);
 	sppp_cp_fini(, sp);
 	sppp_cp_fini(, sp);
@@ -1090,7 +1088,6 @@ sppp_detach(struct ifnet *ifp)
 	if (sp->myauth.secret) free(sp->myauth.secret, M_DEVBUF);
 	if (sp->hisauth.name) free(sp->hisauth.name, M_DEVBUF);
 	if (sp->hisauth.secret) free(sp->hisauth.secret, M_DEVBUF);
-	SPPP_UNLOCK(sp);
 	rw_destroy(>pp_lock);
 }
 



CVS commit: src/sys/net

2021-04-15 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Fri Apr 16 02:05:37 UTC 2021

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

Log Message:
Fix not to put the wrong error message


To generate a diff of this commit:
cvs rdiff -u -r1.215 -r1.216 src/sys/net/if_spppsubr.c

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

Modified files:

Index: src/sys/net/if_spppsubr.c
diff -u src/sys/net/if_spppsubr.c:1.215 src/sys/net/if_spppsubr.c:1.216
--- src/sys/net/if_spppsubr.c:1.215	Fri Nov 27 03:37:11 2020
+++ src/sys/net/if_spppsubr.c	Fri Apr 16 02:05:37 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppsubr.c,v 1.215 2020/11/27 03:37:11 yamaguchi Exp $	 */
+/*	$NetBSD: if_spppsubr.c,v 1.216 2021/04/16 02:05:37 yamaguchi Exp $	 */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.215 2020/11/27 03:37:11 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.216 2021/04/16 02:05:37 yamaguchi Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -1933,6 +1933,13 @@ sppp_down_event(struct sppp *sp, void *x
 		sppp_cp_change_state(cp, sp, STATE_STARTING);
 		break;
 	default:
+		/*
+		 * a down event may be caused regardless
+		 * of state just in LCP case.
+		 */
+		if (cp->proto == PPP_LCP)
+			break;
+
 		printf("%s: %s illegal down in state %s\n",
 		   ifp->if_xname, cp->name,
 		   sppp_state_name(sp->scp[cp->protoidx].state));



CVS commit: src/sys/net

2021-04-15 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Fri Apr 16 01:59:50 UTC 2021

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

Log Message:
Stop ppp layer at first of destroying pppoe interface


To generate a diff of this commit:
cvs rdiff -u -r1.166 -r1.167 src/sys/net/if_pppoe.c

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

Modified files:

Index: src/sys/net/if_pppoe.c
diff -u src/sys/net/if_pppoe.c:1.166 src/sys/net/if_pppoe.c:1.167
--- src/sys/net/if_pppoe.c:1.166	Fri Apr 16 01:44:35 2021
+++ src/sys/net/if_pppoe.c	Fri Apr 16 01:59:50 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: if_pppoe.c,v 1.166 2021/04/16 01:44:35 yamaguchi Exp $ */
+/* $NetBSD: if_pppoe.c,v 1.167 2021/04/16 01:59:50 yamaguchi Exp $ */
 
 /*
  * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.166 2021/04/16 01:44:35 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.167 2021/04/16 01:59:50 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "pppoe.h"
@@ -188,6 +188,7 @@ struct pppoe_softc {
 	int sc_padi_retried;		/* number of PADI retries already done */
 	int sc_padr_retried;		/* number of PADR retries already done */
 	krwlock_t sc_lock;	/* lock of sc_state, sc_session, and sc_eth_if */
+	bool sc_detaching;
 };
 
 /* incoming traffic will be queued here */
@@ -417,13 +418,17 @@ pppoe_clone_destroy(struct ifnet *ifp)
 {
 	struct pppoe_softc * sc = ifp->if_softc;
 
-	rw_enter(_softc_list_lock, RW_WRITER);
-
 	PPPOE_LOCK(sc, RW_WRITER);
-	callout_setfunc(>sc_timeout, pppoe_timeout_co_halt, sc);
-	workqueue_wait(sc->sc_timeout_wq, >sc_timeout_wk);
-	callout_halt(>sc_timeout, NULL);
+	/* stop ioctls */
+	sc->sc_detaching = true;
 
+	if (ifp->if_flags & IFF_RUNNING) {
+		pppoe_clear_softc(sc, "destroy interface");
+		sc->sc_eth_if = NULL;
+	}
+	PPPOE_UNLOCK(sc);
+
+	rw_enter(_softc_list_lock, RW_WRITER);
 	LIST_REMOVE(sc, sc_list);
 
 	if (LIST_EMPTY(_softc_list)) {
@@ -431,6 +436,11 @@ pppoe_clone_destroy(struct ifnet *ifp)
 	}
 	rw_exit(_softc_list_lock);
 
+	PPPOE_LOCK(sc, RW_WRITER);
+	callout_setfunc(>sc_timeout, pppoe_timeout_co_halt, sc);
+	workqueue_wait(sc->sc_timeout_wq, >sc_timeout_wk);
+	callout_halt(>sc_timeout, NULL);
+
 	bpf_detach(ifp);
 	sppp_detach(>sc_sppp.pp_if);
 	if_detach(ifp);
@@ -1285,6 +1295,10 @@ pppoe_ioctl(struct ifnet *ifp, unsigned 
 			struct ifnet *eth_if;
 
 			PPPOE_LOCK(sc, RW_WRITER);
+			if (sc->sc_detaching) {
+PPPOE_UNLOCK(sc);
+return ENXIO;
+			}
 			eth_if = ifunit(parms->eth_ifname);
 			if (eth_if == NULL || eth_if->if_dlt != DLT_EN10MB) {
 sc->sc_eth_if = NULL;
@@ -1343,6 +1357,10 @@ pppoe_ioctl(struct ifnet *ifp, unsigned 
 		 * administrators choice.
 		 */
 		PPPOE_LOCK(sc, RW_WRITER);
+		if (sc->sc_detaching) {
+			PPPOE_UNLOCK(sc);
+			return ENXIO;
+		}
 
 		if ((ifr->ifr_flags & IFF_UP) == 0
 		 && sc->sc_state < PPPOE_STATE_SESSION) {
@@ -1506,7 +1524,8 @@ pppoe_timeout(struct pppoe_softc *sc)
 	switch (sc->sc_state) {
 	case PPPOE_STATE_INITIAL:
 		/* delayed connect from pppoe_tls() */
-		pppoe_connect(sc);
+		if (!sc->sc_detaching)
+			pppoe_connect(sc);
 		break;
 	case PPPOE_STATE_PADI_SENT:
 		/*



CVS commit: src/sys/net

2021-04-15 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Fri Apr 16 01:44:35 UTC 2021

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

Log Message:
Sort initialization sequence in pppoe_clone_create() out
for refactoring

It has no functionality impact


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

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

Modified files:

Index: src/sys/net/if_pppoe.c
diff -u src/sys/net/if_pppoe.c:1.165 src/sys/net/if_pppoe.c:1.166
--- src/sys/net/if_pppoe.c:1.165	Fri Apr 16 01:32:04 2021
+++ src/sys/net/if_pppoe.c	Fri Apr 16 01:44:35 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: if_pppoe.c,v 1.165 2021/04/16 01:32:04 yamaguchi Exp $ */
+/* $NetBSD: if_pppoe.c,v 1.166 2021/04/16 01:44:35 yamaguchi Exp $ */
 
 /*
  * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.165 2021/04/16 01:32:04 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.166 2021/04/16 01:44:35 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "pppoe.h"
@@ -339,34 +339,43 @@ static int
 pppoe_clone_create(struct if_clone *ifc, int unit)
 {
 	struct pppoe_softc *sc;
+	struct ifnet *ifp;
 	int rv;
 
 	sc = kmem_zalloc(sizeof(*sc), KM_SLEEP);
+	ifp = >sc_sppp.pp_if;
 
 	rw_init(>sc_lock);
 	pppoe_softc_genid(>sc_id);
+	/* changed to real address later */
+	memcpy(>sc_dest, etherbroadcastaddr, sizeof(sc->sc_dest));
 
-	if_initname(>sc_sppp.pp_if, "pppoe", unit);
-	sc->sc_sppp.pp_if.if_softc = sc;
-	sc->sc_sppp.pp_if.if_mtu = PPPOE_MAXMTU;
-	sc->sc_sppp.pp_if.if_flags = IFF_SIMPLEX|IFF_POINTOPOINT|IFF_MULTICAST;
+	if_initname(ifp, "pppoe", unit);
+	ifp->if_softc = sc;
+	ifp->if_mtu = PPPOE_MAXMTU;
+	ifp->if_flags = IFF_SIMPLEX|IFF_POINTOPOINT|IFF_MULTICAST;
+#ifdef PPPOE_MPSAFE
+	ifp->if_extflags = IFEF_MPSAFE;
+#endif
+	ifp->if_type = IFT_PPP;
+	ifp->if_hdrlen = sizeof(struct ether_header) + PPPOE_HEADERLEN;
+	ifp->if_dlt = DLT_PPP_ETHER;
+	ifp->if_ioctl = pppoe_ioctl;
+	ifp->if_start = pppoe_start;
 #ifdef PPPOE_MPSAFE
-	sc->sc_sppp.pp_if.if_extflags = IFEF_MPSAFE;
+	ifp->if_transmit = pppoe_transmit;
 #endif
-	sc->sc_sppp.pp_if.if_type = IFT_PPP;
-	sc->sc_sppp.pp_if.if_hdrlen = sizeof(struct ether_header) + PPPOE_HEADERLEN;
-	sc->sc_sppp.pp_if.if_dlt = DLT_PPP_ETHER;
+	IFQ_SET_MAXLEN(>if_snd, IFQ_MAXLEN);
+	IFQ_SET_READY(>if_snd);
+
+	sc->sc_sppp.pp_tls = pppoe_tls;
+	sc->sc_sppp.pp_tlf = pppoe_tlf;
 	sc->sc_sppp.pp_flags |= PP_KEEPALIVE |	/* use LCP keepalive */
 PP_NOFRAMING;	/* no serial encapsulation */
-	sc->sc_sppp.pp_if.if_ioctl = pppoe_ioctl;
-	IFQ_SET_MAXLEN(>sc_sppp.pp_if.if_snd, IFQ_MAXLEN);
-	IFQ_SET_READY(>sc_sppp.pp_if.if_snd);
-
-	/* changed to real address later */
-	memcpy(>sc_dest, etherbroadcastaddr, sizeof(sc->sc_dest));
+	sc->sc_sppp.pp_framebytes = PPPOE_HEADERLEN;	/* framing added to ppp packets */
 
 	rv = workqueue_create(>sc_timeout_wq,
-	sc->sc_sppp.pp_if.if_xname, pppoe_timeout_wk, sc,
+	ifp->if_xname, pppoe_timeout_wk, sc,
 	PRI_SOFTNET, IPL_SOFTNET, 0);
 	if (rv != 0)
 		goto destroy_sclock;
@@ -374,33 +383,23 @@ pppoe_clone_create(struct if_clone *ifc,
 	callout_init(>sc_timeout, CALLOUT_MPSAFE);
 	callout_setfunc(>sc_timeout, pppoe_timeout_co, sc);
 
-	sc->sc_sppp.pp_if.if_start = pppoe_start;
-#ifdef PPPOE_MPSAFE
-	sc->sc_sppp.pp_if.if_transmit = pppoe_transmit;
-#endif
-	sc->sc_sppp.pp_tls = pppoe_tls;
-	sc->sc_sppp.pp_tlf = pppoe_tlf;
-	sc->sc_sppp.pp_framebytes = PPPOE_HEADERLEN;	/* framing added to ppp packets */
-
-	rv = if_initialize(>sc_sppp.pp_if);
+	rv = if_initialize(ifp);
 	if (rv != 0)
 		goto destroy_timeout;
 
-	sc->sc_sppp.pp_if.if_percpuq = if_percpuq_create(>sc_sppp.pp_if);
-	sppp_attach(>sc_sppp.pp_if);
+	ifp->if_percpuq = if_percpuq_create(ifp);
 
-	bpf_attach(>sc_sppp.pp_if, DLT_PPP_ETHER, 0);
 	rw_enter(_softc_list_lock, RW_READER);
 	if (LIST_EMPTY(_softc_list)) {
 		pfil_add_ihook(pppoe_ifattach_hook, NULL, PFIL_IFNET, if_pfil);
 	}
+	LIST_INSERT_HEAD(_softc_list, sc, sc_list);
 	rw_exit(_softc_list_lock);
 
-	if_register(>sc_sppp.pp_if);
+	sppp_attach(ifp);
+	bpf_attach(ifp, DLT_PPP_ETHER, 0);
+	if_register(ifp);
 
-	rw_enter(_softc_list_lock, RW_WRITER);
-	LIST_INSERT_HEAD(_softc_list, sc, sc_list);
-	rw_exit(_softc_list_lock);
 	return 0;
 
 destroy_timeout:



CVS commit: src/sys/net

2021-04-15 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Fri Apr 16 01:32:04 UTC 2021

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

Log Message:
Use kmem_zalloc to allocate pppoe_softc


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

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

Modified files:

Index: src/sys/net/if_pppoe.c
diff -u src/sys/net/if_pppoe.c:1.164 src/sys/net/if_pppoe.c:1.165
--- src/sys/net/if_pppoe.c:1.164	Fri Apr 16 01:28:51 2021
+++ src/sys/net/if_pppoe.c	Fri Apr 16 01:32:04 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: if_pppoe.c,v 1.164 2021/04/16 01:28:51 yamaguchi Exp $ */
+/* $NetBSD: if_pppoe.c,v 1.165 2021/04/16 01:32:04 yamaguchi Exp $ */
 
 /*
  * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.164 2021/04/16 01:28:51 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.165 2021/04/16 01:32:04 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "pppoe.h"
@@ -341,7 +341,7 @@ pppoe_clone_create(struct if_clone *ifc,
 	struct pppoe_softc *sc;
 	int rv;
 
-	sc = malloc(sizeof(struct pppoe_softc), M_DEVBUF, M_WAITOK|M_ZERO);
+	sc = kmem_zalloc(sizeof(*sc), KM_SLEEP);
 
 	rw_init(>sc_lock);
 	pppoe_softc_genid(>sc_id);
@@ -408,7 +408,7 @@ destroy_timeout:
 	workqueue_destroy(sc->sc_timeout_wq);
 destroy_sclock:
 	rw_destroy(>sc_lock);
-	free(sc, M_DEVBUF);
+	kmem_free(sc, sizeof(*sc));
 
 	return rv;
 }
@@ -449,7 +449,7 @@ pppoe_clone_destroy(struct ifnet *ifp)
 	PPPOE_UNLOCK(sc);
 	rw_destroy(>sc_lock);
 
-	free(sc, M_DEVBUF);
+	kmem_free(sc, sizeof(*sc));
 
 	return 0;
 }



CVS commit: src/sys/net

2021-04-15 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Fri Apr 16 01:28:51 UTC 2021

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

Log Message:
Move initialization of sc_lock in pppoe_softc to first

The lock may be held in callbacks for ppp layer or other
components so that it should be initialized early.


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

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

Modified files:

Index: src/sys/net/if_pppoe.c
diff -u src/sys/net/if_pppoe.c:1.163 src/sys/net/if_pppoe.c:1.164
--- src/sys/net/if_pppoe.c:1.163	Fri Apr 16 01:24:35 2021
+++ src/sys/net/if_pppoe.c	Fri Apr 16 01:28:51 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: if_pppoe.c,v 1.163 2021/04/16 01:24:35 yamaguchi Exp $ */
+/* $NetBSD: if_pppoe.c,v 1.164 2021/04/16 01:28:51 yamaguchi Exp $ */
 
 /*
  * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.163 2021/04/16 01:24:35 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.164 2021/04/16 01:28:51 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "pppoe.h"
@@ -343,6 +343,7 @@ pppoe_clone_create(struct if_clone *ifc,
 
 	sc = malloc(sizeof(struct pppoe_softc), M_DEVBUF, M_WAITOK|M_ZERO);
 
+	rw_init(>sc_lock);
 	pppoe_softc_genid(>sc_id);
 
 	if_initname(>sc_sppp.pp_if, "pppoe", unit);
@@ -368,7 +369,7 @@ pppoe_clone_create(struct if_clone *ifc,
 	sc->sc_sppp.pp_if.if_xname, pppoe_timeout_wk, sc,
 	PRI_SOFTNET, IPL_SOFTNET, 0);
 	if (rv != 0)
-		goto free_sc;
+		goto destroy_sclock;
 
 	callout_init(>sc_timeout, CALLOUT_MPSAFE);
 	callout_setfunc(>sc_timeout, pppoe_timeout_co, sc);
@@ -397,8 +398,6 @@ pppoe_clone_create(struct if_clone *ifc,
 
 	if_register(>sc_sppp.pp_if);
 
-	rw_init(>sc_lock);
-
 	rw_enter(_softc_list_lock, RW_WRITER);
 	LIST_INSERT_HEAD(_softc_list, sc, sc_list);
 	rw_exit(_softc_list_lock);
@@ -407,8 +406,10 @@ pppoe_clone_create(struct if_clone *ifc,
 destroy_timeout:
 	callout_destroy(>sc_timeout);
 	workqueue_destroy(sc->sc_timeout_wq);
-free_sc:
+destroy_sclock:
+	rw_destroy(>sc_lock);
 	free(sc, M_DEVBUF);
+
 	return rv;
 }
 



CVS commit: src/sys/net

2021-04-15 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Fri Apr 16 01:24:35 UTC 2021

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

Log Message:
commonize error handling in pppoe_clone_create()


To generate a diff of this commit:
cvs rdiff -u -r1.162 -r1.163 src/sys/net/if_pppoe.c

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

Modified files:

Index: src/sys/net/if_pppoe.c
diff -u src/sys/net/if_pppoe.c:1.162 src/sys/net/if_pppoe.c:1.163
--- src/sys/net/if_pppoe.c:1.162	Tue Apr 13 05:04:54 2021
+++ src/sys/net/if_pppoe.c	Fri Apr 16 01:24:35 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: if_pppoe.c,v 1.162 2021/04/13 05:04:54 yamaguchi Exp $ */
+/* $NetBSD: if_pppoe.c,v 1.163 2021/04/16 01:24:35 yamaguchi Exp $ */
 
 /*
  * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.162 2021/04/13 05:04:54 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.163 2021/04/16 01:24:35 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "pppoe.h"
@@ -367,10 +367,8 @@ pppoe_clone_create(struct if_clone *ifc,
 	rv = workqueue_create(>sc_timeout_wq,
 	sc->sc_sppp.pp_if.if_xname, pppoe_timeout_wk, sc,
 	PRI_SOFTNET, IPL_SOFTNET, 0);
-	if (rv != 0) {
-		free(sc, M_DEVBUF);
-		return rv;
-	}
+	if (rv != 0)
+		goto free_sc;
 
 	callout_init(>sc_timeout, CALLOUT_MPSAFE);
 	callout_setfunc(>sc_timeout, pppoe_timeout_co, sc);
@@ -384,13 +382,9 @@ pppoe_clone_create(struct if_clone *ifc,
 	sc->sc_sppp.pp_framebytes = PPPOE_HEADERLEN;	/* framing added to ppp packets */
 
 	rv = if_initialize(>sc_sppp.pp_if);
-	if (rv != 0) {
-		workqueue_destroy(sc->sc_timeout_wq);
-		callout_halt(>sc_timeout, NULL);
-		callout_destroy(>sc_timeout);
-		free(sc, M_DEVBUF);
-		return rv;
-	}
+	if (rv != 0)
+		goto destroy_timeout;
+
 	sc->sc_sppp.pp_if.if_percpuq = if_percpuq_create(>sc_sppp.pp_if);
 	sppp_attach(>sc_sppp.pp_if);
 
@@ -409,6 +403,13 @@ pppoe_clone_create(struct if_clone *ifc,
 	LIST_INSERT_HEAD(_softc_list, sc, sc_list);
 	rw_exit(_softc_list_lock);
 	return 0;
+
+destroy_timeout:
+	callout_destroy(>sc_timeout);
+	workqueue_destroy(sc->sc_timeout_wq);
+free_sc:
+	free(sc, M_DEVBUF);
+	return rv;
 }
 
 static int



CVS commit: src/sys/net

2021-04-12 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Tue Apr 13 05:04:54 UTC 2021

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

Log Message:
Reschedule softint to process packets enqueued to ppoediscinq
while doing pppoe_data_input

And added a empty check for ppoeinq, for safety


To generate a diff of this commit:
cvs rdiff -u -r1.161 -r1.162 src/sys/net/if_pppoe.c

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

Modified files:

Index: src/sys/net/if_pppoe.c
diff -u src/sys/net/if_pppoe.c:1.161 src/sys/net/if_pppoe.c:1.162
--- src/sys/net/if_pppoe.c:1.161	Tue Apr 13 05:00:06 2021
+++ src/sys/net/if_pppoe.c	Tue Apr 13 05:04:54 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: if_pppoe.c,v 1.161 2021/04/13 05:00:06 yamaguchi Exp $ */
+/* $NetBSD: if_pppoe.c,v 1.162 2021/04/13 05:04:54 yamaguchi Exp $ */
 
 /*
  * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.161 2021/04/13 05:00:06 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.162 2021/04/13 05:04:54 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "pppoe.h"
@@ -602,6 +602,9 @@ pppoeintr(void)
 		}
 	} while (disc_done || data_done);
 
+	if (!IF_IS_EMPTY() || !IF_IS_EMPTY())
+		softint_schedule(pppoe_softintr);
+
 	SOFTNET_UNLOCK_UNLESS_NET_MPSAFE();
 }
 



CVS commit: src/sys/net

2021-04-12 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Tue Apr 13 05:00:06 UTC 2021

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

Log Message:
Added missing counter clear when a pppoe state changes to PADI_SENT


To generate a diff of this commit:
cvs rdiff -u -r1.160 -r1.161 src/sys/net/if_pppoe.c

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

Modified files:

Index: src/sys/net/if_pppoe.c
diff -u src/sys/net/if_pppoe.c:1.160 src/sys/net/if_pppoe.c:1.161
--- src/sys/net/if_pppoe.c:1.160	Tue Apr 13 04:57:15 2021
+++ src/sys/net/if_pppoe.c	Tue Apr 13 05:00:06 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: if_pppoe.c,v 1.160 2021/04/13 04:57:15 yamaguchi Exp $ */
+/* $NetBSD: if_pppoe.c,v 1.161 2021/04/13 05:00:06 yamaguchi Exp $ */
 
 /*
  * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.160 2021/04/13 04:57:15 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.161 2021/04/13 05:00:06 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "pppoe.h"
@@ -1547,6 +1547,7 @@ pppoe_timeout(struct pppoe_softc *sc)
 			memcpy(>sc_dest, etherbroadcastaddr,
 			sizeof(sc->sc_dest));
 			sc->sc_state = PPPOE_STATE_PADI_SENT;
+			sc->sc_padi_retried = 0;
 			sc->sc_padr_retried = 0;
 			if ((err = pppoe_send_padi(sc)) != 0) {
 pppoe_printf(sc,
@@ -1596,6 +1597,7 @@ pppoe_connect(struct pppoe_softc *sc)
 	ACQUIRE_SPLNET();
 	/* save state, in case we fail to send PADI */
 	sc->sc_state = PPPOE_STATE_PADI_SENT;
+	sc->sc_padi_retried = 0;
 	sc->sc_padr_retried = 0;
 	err = pppoe_send_padi(sc);
 	if (err != 0)



CVS commit: src/sys/net

2021-04-12 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Tue Apr 13 04:57:15 UTC 2021

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

Log Message:
Added a NULL check for parent interface of pppoe


To generate a diff of this commit:
cvs rdiff -u -r1.159 -r1.160 src/sys/net/if_pppoe.c

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

Modified files:

Index: src/sys/net/if_pppoe.c
diff -u src/sys/net/if_pppoe.c:1.159 src/sys/net/if_pppoe.c:1.160
--- src/sys/net/if_pppoe.c:1.159	Tue Apr 13 04:53:22 2021
+++ src/sys/net/if_pppoe.c	Tue Apr 13 04:57:15 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: if_pppoe.c,v 1.159 2021/04/13 04:53:22 yamaguchi Exp $ */
+/* $NetBSD: if_pppoe.c,v 1.160 2021/04/13 04:57:15 yamaguchi Exp $ */
 
 /*
  * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.159 2021/04/13 04:53:22 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.160 2021/04/13 04:57:15 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "pppoe.h"
@@ -533,7 +533,7 @@ pppoe_find_softc_by_hunique(uint8_t *tok
 
 	LIST_FOREACH(sc, _softc_list, sc_list) {
 		PPPOE_LOCK(sc, lock);
-		if (sc->sc_id == t) {
+		if (sc->sc_id == t && sc->sc_eth_if != NULL) {
 			break;
 		}
 		PPPOE_UNLOCK(sc);



CVS commit: src/sys/net

2021-04-12 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Tue Apr 13 04:53:22 UTC 2021

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

Log Message:
Hold the lock for pppoe while referencing sc_id
that is an item of struct pppoe_softc


To generate a diff of this commit:
cvs rdiff -u -r1.158 -r1.159 src/sys/net/if_pppoe.c

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

Modified files:

Index: src/sys/net/if_pppoe.c
diff -u src/sys/net/if_pppoe.c:1.158 src/sys/net/if_pppoe.c:1.159
--- src/sys/net/if_pppoe.c:1.158	Wed Nov 25 10:42:35 2020
+++ src/sys/net/if_pppoe.c	Tue Apr 13 04:53:22 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: if_pppoe.c,v 1.158 2020/11/25 10:42:35 yamaguchi Exp $ */
+/* $NetBSD: if_pppoe.c,v 1.159 2021/04/13 04:53:22 yamaguchi Exp $ */
 
 /*
  * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.158 2020/11/25 10:42:35 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.159 2021/04/13 04:53:22 yamaguchi Exp $");
 
 #ifdef _KERNEL_OPT
 #include "pppoe.h"
@@ -532,10 +532,11 @@ pppoe_find_softc_by_hunique(uint8_t *tok
 	memcpy(, token, len);
 
 	LIST_FOREACH(sc, _softc_list, sc_list) {
+		PPPOE_LOCK(sc, lock);
 		if (sc->sc_id == t) {
-			PPPOE_LOCK(sc, lock);
 			break;
 		}
+		PPPOE_UNLOCK(sc);
 	}
 	rw_exit(_softc_list_lock);
 



CVS commit: src/sys/net

2021-04-05 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Mon Apr  5 06:56:47 UTC 2021

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

Log Message:
s/nitems/__arraycount/


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/net/toeplitz.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/toeplitz.c
diff -u src/sys/net/toeplitz.c:1.1 src/sys/net/toeplitz.c:1.2
--- src/sys/net/toeplitz.c:1.1	Sat Jan 30 21:23:08 2021
+++ src/sys/net/toeplitz.c	Mon Apr  5 06:56:47 2021
@@ -165,7 +165,7 @@ stoeplitz_hash_ip6(const struct stoeplit
 	uint32_t n32 = 0;
 	size_t i;
 
-	for (i = 0; i < nitems(faddr6->s6_addr32); i++)
+	for (i = 0; i < __arraycount(faddr6->s6_addr32); i++)
 		n32 ^= faddr6->s6_addr32[i] ^ laddr6->s6_addr32[i];
 
 	return (stoeplitz_hash_n32(scache, n32));
@@ -179,7 +179,7 @@ stoeplitz_hash_ip6port(const struct stoe
 	uint32_t n32 = 0;
 	size_t i;
 
-	for (i = 0; i < nitems(faddr6->s6_addr32); i++)
+	for (i = 0; i < __arraycount(faddr6->s6_addr32); i++)
 		n32 ^= faddr6->s6_addr32[i] ^ laddr6->s6_addr32[i];
 
 	n32 ^= fport ^ lport;



CVS commit: src/sys/net

2021-04-05 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Mon Apr  5 06:53:45 UTC 2021

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

Log Message:
Include opt_inet.h for INET6


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/net/toeplitz.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/toeplitz.h
diff -u src/sys/net/toeplitz.h:1.1 src/sys/net/toeplitz.h:1.2
--- src/sys/net/toeplitz.h:1.1	Sat Jan 30 21:23:08 2021
+++ src/sys/net/toeplitz.h	Mon Apr  5 06:53:45 2021
@@ -19,6 +19,10 @@
 #ifndef _SYS_NET_TOEPLITZ_H_
 #define _SYS_NET_TOEPLITZ_H_
 
+#ifdef _KERNEL_OPT
+#include "opt_inet.h"
+#endif
+
 #include 
 
 /*



CVS commit: src/sys/net

2021-03-25 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Thu Mar 25 08:18:03 UTC 2021

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

Log Message:
Remove strange padding #define and replace with anonymous struct/union


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/net/pktqueue.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/pktqueue.c
diff -u src/sys/net/pktqueue.c:1.12 src/sys/net/pktqueue.c:1.13
--- src/sys/net/pktqueue.c:1.12	Fri Sep 11 14:29:00 2020
+++ src/sys/net/pktqueue.c	Thu Mar 25 08:18:03 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pktqueue.c,v 1.12 2020/09/11 14:29:00 riastradh Exp $	*/
+/*	$NetBSD: pktqueue.c,v 1.13 2021/03/25 08:18:03 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pktqueue.c,v 1.12 2020/09/11 14:29:00 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pktqueue.c,v 1.13 2021/03/25 08:18:03 skrll Exp $");
 
 #include 
 #include 
@@ -52,21 +52,19 @@ __KERNEL_RCSID(0, "$NetBSD: pktqueue.c,v
 
 #include 
 
-/*
- * WARNING: update this if struct pktqueue changes.
- */
-#define	PKTQ_CLPAD	\
-MAX(COHERENCY_UNIT, COHERENCY_UNIT - sizeof(kmutex_t) - sizeof(u_int))
-
 struct pktqueue {
 	/*
 	 * The lock used for a barrier mechanism.  The barrier counter,
 	 * as well as the drop counter, are managed atomically though.
 	 * Ensure this group is in a separate cache line.
 	 */
-	kmutex_t	pq_lock;
-	volatile u_int	pq_barrier;
-	uint8_t		_pad[PKTQ_CLPAD];
+	union {
+		struct {
+			kmutex_t	pq_lock;
+			volatile u_int	pq_barrier;
+		};
+		uint8_t	 _pad[COHERENCY_UNIT];
+	};
 
 	/* The size of the queue, counters and the interrupt handler. */
 	u_int		pq_maxlen;



CVS commit: src/sys/net

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

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

Log Message:
Add a list of names


To generate a diff of this commit:
cvs rdiff -u -r1.127 -r1.128 src/sys/net/route.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/route.h
diff -u src/sys/net/route.h:1.127 src/sys/net/route.h:1.128
--- src/sys/net/route.h:1.127	Mon Mar  9 17:20:55 2020
+++ src/sys/net/route.h	Mon Mar 22 14:40:18 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: route.h,v 1.127 2020/03/09 21:20:55 roy Exp $	*/
+/*	$NetBSD: route.h,v 1.128 2021/03/22 18:40:18 christos Exp $	*/
 
 /*
  * Copyright (c) 1980, 1986, 1993
@@ -266,6 +266,16 @@ struct rt_msghdr {
 #define RTM_DELADDR	0x17	/* address being removed from iface */
 #define RTM_CHGADDR	0x18	/* address properties changed */
 
+#ifdef RTM_NAMES
+static const char *rtm_names[] = {
+"*none*", "add", "delete", "change", "get",
+"losing", "redirect", "miss", "lock", "oldadd",
+"olddel", "*resolve*", "onewaddr", "odeladdr", "ooifinfo",
+"oifinfo", "ifannounce", "ieee80211", "setgate", "llinfo_upd",
+"ifinfo", "ochgaddr",  "newaddr", "deladdr", "chgaddr",
+};
+#endif
+
 /*
  * setsockopt defines used for the filtering.
  */



CVS commit: src/sys/net

2021-03-16 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Tue Mar 16 07:00:38 UTC 2021

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

Log Message:
Fix l2tp(4) ioctl type. Pointed out by yamaguchi@n.o, thanks.

XXX pullup-[89]


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 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.h
diff -u src/sys/net/if_l2tp.h:1.9 src/sys/net/if_l2tp.h:1.10
--- src/sys/net/if_l2tp.h:1.9	Sat Feb  1 02:58:05 2020
+++ src/sys/net/if_l2tp.h	Tue Mar 16 07:00:38 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_l2tp.h,v 1.9 2020/02/01 02:58:05 riastradh Exp $	*/
+/*	$NetBSD: if_l2tp.h,v 1.10 2021/03/16 07:00:38 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -44,11 +44,11 @@
 #include 
 #include 
 
-#define	SIOCSL2TPSESSION	_IOW('i', 151, struct l2tp_req)
-#define	SIOCDL2TPSESSION	_IOW('i', 152, struct l2tp_req)
-#define	SIOCSL2TPCOOKIE		_IOW('i', 153, struct l2tp_req)
-#define	SIOCDL2TPCOOKIE		_IOW('i', 154, struct l2tp_req)
-#define	SIOCSL2TPSTATE		_IOW('i', 155, struct l2tp_req)
+#define	SIOCSL2TPSESSION	_IOW('i', 151, struct ifreq)
+#define	SIOCDL2TPSESSION	_IOW('i', 152, struct ifreq)
+#define	SIOCSL2TPCOOKIE		_IOW('i', 153, struct ifreq)
+#define	SIOCDL2TPCOOKIE		_IOW('i', 154, struct ifreq)
+#define	SIOCSL2TPSTATE		_IOW('i', 155, struct ifreq)
 #define	SIOCGL2TP		SIOCGIFGENERIC
 
 struct l2tp_req {



CVS commit: src/sys/net

2021-02-16 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Feb 16 10:20:56 UTC 2021

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

Log Message:
ARP headers only need 2 byte alignment - pointed out by roy.


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/sys/net/if_arp.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_arp.h
diff -u src/sys/net/if_arp.h:1.40 src/sys/net/if_arp.h:1.41
--- src/sys/net/if_arp.h:1.40	Sun Feb 14 20:58:34 2021
+++ src/sys/net/if_arp.h	Tue Feb 16 10:20:56 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_arp.h,v 1.40 2021/02/14 20:58:34 christos Exp $	*/
+/*	$NetBSD: if_arp.h,v 1.41 2021/02/16 10:20:56 martin Exp $	*/
 
 /*
  * Copyright (c) 1986, 1993
@@ -72,7 +72,7 @@ struct	arphdr {
 	uint8_t  ar_tpa[];	/* target protocol address */
 #endif
 };
-#define	ARP_HDR_ALIGNMENT	3
+#define	ARP_HDR_ALIGNMENT	1
 
 static __inline uint8_t *
 ar_data(struct arphdr *ap)



CVS commit: src/sys/net

2021-02-14 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Sun Feb 14 19:35:38 UTC 2021

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

Log Message:
if_ether: revert prior alignment checks

Apparently not needed as our drivers ensure this.


To generate a diff of this commit:
cvs rdiff -u -r1.85 -r1.86 src/sys/net/if_ether.h
cvs rdiff -u -r1.291 -r1.292 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_ether.h
diff -u src/sys/net/if_ether.h:1.85 src/sys/net/if_ether.h:1.86
--- src/sys/net/if_ether.h:1.85	Sat Feb 13 07:28:04 2021
+++ src/sys/net/if_ether.h	Sun Feb 14 19:35:37 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ether.h,v 1.85 2021/02/13 07:28:04 roy Exp $	*/
+/*	$NetBSD: if_ether.h,v 1.86 2021/02/14 19:35:37 roy Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1993
@@ -89,15 +89,6 @@ struct ether_header {
 	uint8_t  ether_shost[ETHER_ADDR_LEN];
 	uint16_t ether_type;
 };
-#ifdef __NO_STRICT_ALIGNMENT
-#define	ETHER_HDR_ALIGNED_P(eh)	1
-#else
-#define	ETHER_HDR_ALIGNED_P(eh)	vaddr_t) (eh)) & 3) == 0)
-#endif
-#ifdef __CTASSERT
-__CTASSERT(sizeof(struct ether_addr) == 6);
-__CTASSERT(sizeof(struct ether_header) == 14);
-#endif
 
 #include 
 

Index: src/sys/net/if_ethersubr.c
diff -u src/sys/net/if_ethersubr.c:1.291 src/sys/net/if_ethersubr.c:1.292
--- src/sys/net/if_ethersubr.c:1.291	Sat Feb 13 13:00:16 2021
+++ src/sys/net/if_ethersubr.c	Sun Feb 14 19:35:37 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ethersubr.c,v 1.291 2021/02/13 13:00:16 roy Exp $	*/
+/*	$NetBSD: if_ethersubr.c,v 1.292 2021/02/14 19:35:37 roy Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.291 2021/02/13 13:00:16 roy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.292 2021/02/14 19:35:37 roy Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -164,6 +164,9 @@ extern u_char	aarp_org_code[3];
 #include 
 #endif
 
+CTASSERT(sizeof(struct ether_addr) == 6);
+CTASSERT(sizeof(struct ether_header) == 14);
+
 #ifdef DIAGNOSTIC
 static struct timeval bigpktppslim_last;
 static int bigpktppslim = 2;	/* XXX */
@@ -653,11 +656,7 @@ ether_input(struct ifnet *ifp, struct mb
 	m_claimm(m, >ec_rx_mowner);
 #endif
 
-	/* Enforce alignement */
-	if (ETHER_HDR_ALIGNED_P(mtod(m, void *)) == 0) {
-		if ((m = m_copyup(m, sizeof(*eh), 0)) == NULL)
-			goto dropped;
-	} else if (__predict_false(m->m_len < sizeof(*eh))) {
+	if (__predict_false(m->m_len < sizeof(*eh))) {
 		if ((m = m_pullup(m, sizeof(*eh))) == NULL)
 			goto dropped;
 	}



CVS commit: src/sys/net

2021-02-14 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Sun Feb 14 19:33:29 UTC 2021

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

Log Message:
if_gre: Remove alignment checks in favour copying to stack

Makes the code a lot simpler, idea from dyoung@


To generate a diff of this commit:
cvs rdiff -u -r1.179 -r1.180 src/sys/net/if_gre.c
cvs rdiff -u -r1.48 -r1.49 src/sys/net/if_gre.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_gre.c
diff -u src/sys/net/if_gre.c:1.179 src/sys/net/if_gre.c:1.180
--- src/sys/net/if_gre.c:1.179	Sat Feb 13 13:00:16 2021
+++ src/sys/net/if_gre.c	Sun Feb 14 19:33:29 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_gre.c,v 1.179 2021/02/13 13:00:16 roy Exp $ */
+/*	$NetBSD: if_gre.c,v 1.180 2021/02/14 19:33:29 roy Exp $ */
 
 /*
  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -45,7 +45,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_gre.c,v 1.179 2021/02/13 13:00:16 roy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_gre.c,v 1.180 2021/02/14 19:33:29 roy Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_atalk.h"
@@ -142,6 +142,8 @@ int gre_debug = 0;
 #define	GRE_DPRINTF(__sc, __fmt, ...)	do { } while (/*CONSTCOND*/0)
 #endif /* GRE_DEBUG */
 
+CTASSERT(sizeof(struct gre_h) == 4);
+
 int ip_gre_ttl = GRE_TTL;
 
 static u_int gre_count;
@@ -374,7 +376,7 @@ gre_receive(struct socket *so, void *arg
 {
 	struct gre_softc *sc = (struct gre_softc *)arg;
 	int rc;
-	const struct gre_h *gh;
+	struct gre_h gh;
 	struct mbuf *m;
 
 	GRE_DPRINTF(sc, "enter\n");
@@ -396,24 +398,16 @@ gre_receive(struct socket *so, void *arg
 		return;
 	}
 
-	/* Enforce alignment */
-	if (GRE_HDR_ALIGNED_P(mtod(m, void *)) == 0) {
-		if ((m = m_copyup(m, sizeof(struct gre_h), 0)) == NULL) {
-			/* XXXJRT new stat, please */
-			GRE_DPRINTF(sc, "m_copyup failed\n");
-			sc->sc_pullup_ev.ev_count++;
-			return;
-		}
-	} else if (__predict_false(m->m_len < sizeof(struct gre_h))) {
-		if ((m = m_pullup(m, sizeof(struct gre_h))) == NULL) {
+	if (__predict_false(m->m_len < sizeof(gh))) {
+		if ((m = m_pullup(m, sizeof(gh))) == NULL) {
 			GRE_DPRINTF(sc, "m_pullup failed\n");
 			sc->sc_pullup_ev.ev_count++;
 			return;
 		}
 	}
-	gh = mtod(m, const struct gre_h *);
+	memcpy(, mtod(m, void *), sizeof(gh));
 
-	if (gre_input(sc, m, gh) == 0) {
+	if (gre_input(sc, m, ) == 0) {
 		sc->sc_unsupp_ev.ev_count++;
 		GRE_DPRINTF(sc, "dropping unsupported\n");
 		m_freem(m);
@@ -898,7 +892,7 @@ gre_output(struct ifnet *ifp, struct mbu
 {
 	int error = 0;
 	struct gre_softc *sc = ifp->if_softc;
-	struct gre_h *gh;
+	struct gre_h gh = { .flags = 0 };
 	uint16_t etype = 0;
 
 	KASSERT((m->m_flags & M_PKTHDR) != 0);
@@ -950,17 +944,15 @@ gre_output(struct ifnet *ifp, struct mbu
 	}
 #endif
 
-	M_PREPEND(m, sizeof(*gh), M_DONTWAIT);
+	M_PREPEND(m, sizeof(gh), M_DONTWAIT);
 	if (m == NULL) {
 		IF_DROP(>if_snd);
 		error = ENOBUFS;
 		goto end;
 	}
 
-	gh = mtod(m, struct gre_h *);
-	KASSERT(GRE_HDR_ALIGNED_P(gh));
-	gh->flags = 0;
-	gh->ptype = etype;
+	gh.ptype = etype;
+	memcpy(mtod(m, void *), , sizeof(gh));
 	/* XXX Need to handle IP ToS.  Look at how I handle IP TTL. */
 
 	if_statadd2(ifp, if_opackets, 1, if_obytes, m->m_pkthdr.len);

Index: src/sys/net/if_gre.h
diff -u src/sys/net/if_gre.h:1.48 src/sys/net/if_gre.h:1.49
--- src/sys/net/if_gre.h:1.48	Fri Feb 12 19:57:49 2021
+++ src/sys/net/if_gre.h	Sun Feb 14 19:33:29 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_gre.h,v 1.48 2021/02/12 19:57:49 roy Exp $ */
+/*	$NetBSD: if_gre.h,v 1.49 2021/02/14 19:33:29 roy Exp $ */
 
 /*
  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -131,15 +131,6 @@ struct gre_h {
 Present if (rt_pres == 1)
  */
 };
-#ifdef __NO_STRICT_ALIGNMENT
-#define	GRE_HDR_ALIGNED_P(gh)	1
-#else
-#define	GRE_HDR_ALIGNED_P(gh)	vaddr_t) (gh)) & 3) == 0)
-#endif
-#ifdef __CTASSERT
-__CTASSERT(sizeof(struct gre_h) == 4);
-#endif
-
 #define GRE_CP		0x8000  /* Checksum Present */
 #define GRE_RP		0x4000  /* Routing Present */
 #define GRE_KP		0x2000  /* Key Present */



CVS commit: src/sys/net

2021-02-12 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Sat Feb 13 07:28:05 UTC 2021

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

Log Message:
if_ether: Ensure that ether_header is aligned


To generate a diff of this commit:
cvs rdiff -u -r1.84 -r1.85 src/sys/net/if_ether.h
cvs rdiff -u -r1.289 -r1.290 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_ether.h
diff -u src/sys/net/if_ether.h:1.84 src/sys/net/if_ether.h:1.85
--- src/sys/net/if_ether.h:1.84	Wed Feb  3 18:13:13 2021
+++ src/sys/net/if_ether.h	Sat Feb 13 07:28:04 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ether.h,v 1.84 2021/02/03 18:13:13 roy Exp $	*/
+/*	$NetBSD: if_ether.h,v 1.85 2021/02/13 07:28:04 roy Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1993
@@ -89,7 +89,11 @@ struct ether_header {
 	uint8_t  ether_shost[ETHER_ADDR_LEN];
 	uint16_t ether_type;
 };
-
+#ifdef __NO_STRICT_ALIGNMENT
+#define	ETHER_HDR_ALIGNED_P(eh)	1
+#else
+#define	ETHER_HDR_ALIGNED_P(eh)	vaddr_t) (eh)) & 3) == 0)
+#endif
 #ifdef __CTASSERT
 __CTASSERT(sizeof(struct ether_addr) == 6);
 __CTASSERT(sizeof(struct ether_header) == 14);

Index: src/sys/net/if_ethersubr.c
diff -u src/sys/net/if_ethersubr.c:1.289 src/sys/net/if_ethersubr.c:1.290
--- src/sys/net/if_ethersubr.c:1.289	Sat Sep 26 18:38:09 2020
+++ src/sys/net/if_ethersubr.c	Sat Feb 13 07:28:04 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ethersubr.c,v 1.289 2020/09/26 18:38:09 roy Exp $	*/
+/*	$NetBSD: if_ethersubr.c,v 1.290 2021/02/13 07:28:04 roy Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.289 2020/09/26 18:38:09 roy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.290 2021/02/13 07:28:04 roy Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -648,9 +648,18 @@ ether_input(struct ifnet *ifp, struct mb
 
 	if ((ifp->if_flags & IFF_UP) == 0)
 		goto drop;
-	if (m->m_len < sizeof(*eh)) {
-		m = m_pullup(m, sizeof(*eh));
-		if (m == NULL)
+
+	/* If the Ethernet header is not aligned, slurp it up into a new
+	 * mbuf with space for link headers, in the event we forward
+	 * it.  Otherwise, if it is aligned, make sure the entire
+	 * base Ethernet header is in the first mbuf of the chain.
+	 */
+	if (ETHER_HDR_ALIGNED_P(mtod(m, void *)) == 0) {
+		if ((m = m_copyup(m, sizeof(*eh),
+		(max_linkhdr + 3) & ~3)) == NULL)
+			goto dropped;
+	} else if (__predict_false(m->m_len < sizeof(*eh))) {
+		if ((m = m_pullup(m, sizeof(*eh))) == NULL)
 			goto dropped;
 	}
 



CVS commit: src/sys/net

2021-02-12 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Fri Feb 12 19:57:49 UTC 2021

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

Log Message:
if_gre: Ensure that gre_h is aligned


To generate a diff of this commit:
cvs rdiff -u -r1.177 -r1.178 src/sys/net/if_gre.c
cvs rdiff -u -r1.47 -r1.48 src/sys/net/if_gre.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_gre.c
diff -u src/sys/net/if_gre.c:1.177 src/sys/net/if_gre.c:1.178
--- src/sys/net/if_gre.c:1.177	Wed Jan 29 04:18:34 2020
+++ src/sys/net/if_gre.c	Fri Feb 12 19:57:49 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_gre.c,v 1.177 2020/01/29 04:18:34 thorpej Exp $ */
+/*	$NetBSD: if_gre.c,v 1.178 2021/02/12 19:57:49 roy Exp $ */
 
 /*
  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -45,7 +45,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_gre.c,v 1.177 2020/01/29 04:18:34 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_gre.c,v 1.178 2021/02/12 19:57:49 roy Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_atalk.h"
@@ -395,10 +395,26 @@ gre_receive(struct socket *so, void *arg
 		sc->sc_error_ev.ev_count++;
 		return;
 	}
-	if (m->m_len < sizeof(*gh) && (m = m_pullup(m, sizeof(*gh))) == NULL) {
-		GRE_DPRINTF(sc, "m_pullup failed\n");
-		sc->sc_pullup_ev.ev_count++;
-		return;
+
+	/* If the GRE header is not aligned, slurp it up into a new
+	 * mbuf with space for link headers, in the event we forward
+	 * it.  Otherwise, if it is aligned, make sure the entire
+	 * base GRE header is in the first mbuf of the chain.
+	 */
+	if (GRE_HDR_ALIGNED_P(mtod(m, void *)) == 0) {
+		if ((m = m_copyup(m, sizeof(struct gre_h),
+		(max_linkhdr + 3) & ~3)) == NULL) {
+			/* XXXJRT new stat, please */
+			GRE_DPRINTF(sc, "m_copyup failed\n");
+			sc->sc_pullup_ev.ev_count++;
+			return;
+		}
+	} else if (__predict_false(m->m_len < sizeof(struct gre_h))) {
+		if ((m = m_pullup(m, sizeof(struct gre_h))) == NULL) {
+			GRE_DPRINTF(sc, "m_pullup failed\n");
+			sc->sc_pullup_ev.ev_count++;
+			return;
+		}
 	}
 	gh = mtod(m, const struct gre_h *);
 
@@ -940,7 +956,6 @@ gre_output(struct ifnet *ifp, struct mbu
 #endif
 
 	M_PREPEND(m, sizeof(*gh), M_DONTWAIT);
-
 	if (m == NULL) {
 		IF_DROP(>if_snd);
 		error = ENOBUFS;
@@ -948,6 +963,7 @@ gre_output(struct ifnet *ifp, struct mbu
 	}
 
 	gh = mtod(m, struct gre_h *);
+	KASSERT(GRE_HDR_ALIGNED_P(gh));
 	gh->flags = 0;
 	gh->ptype = etype;
 	/* XXX Need to handle IP ToS.  Look at how I handle IP TTL. */

Index: src/sys/net/if_gre.h
diff -u src/sys/net/if_gre.h:1.47 src/sys/net/if_gre.h:1.48
--- src/sys/net/if_gre.h:1.47	Wed Feb  3 18:13:13 2021
+++ src/sys/net/if_gre.h	Fri Feb 12 19:57:49 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_gre.h,v 1.47 2021/02/03 18:13:13 roy Exp $ */
+/*	$NetBSD: if_gre.h,v 1.48 2021/02/12 19:57:49 roy Exp $ */
 
 /*
  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -131,6 +131,11 @@ struct gre_h {
 Present if (rt_pres == 1)
  */
 };
+#ifdef __NO_STRICT_ALIGNMENT
+#define	GRE_HDR_ALIGNED_P(gh)	1
+#else
+#define	GRE_HDR_ALIGNED_P(gh)	vaddr_t) (gh)) & 3) == 0)
+#endif
 #ifdef __CTASSERT
 __CTASSERT(sizeof(struct gre_h) == 4);
 #endif



CVS commit: src/sys/net

2021-02-03 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Wed Feb  3 12:11:34 UTC 2021

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

Log Message:
if_llc.h: Replace __packed with CTASSERT


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/net/if_llc.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_llc.h
diff -u src/sys/net/if_llc.h:1.21 src/sys/net/if_llc.h:1.22
--- src/sys/net/if_llc.h:1.21	Fri Sep  5 05:32:07 2014
+++ src/sys/net/if_llc.h	Wed Feb  3 12:11:34 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_llc.h,v 1.21 2014/09/05 05:32:07 matt Exp $	*/
+/*	$NetBSD: if_llc.h,v 1.22 2021/02/03 12:11:34 roy Exp $	*/
 
 /*
  * Copyright (c) 1988, 1993
@@ -82,7 +82,7 @@ struct llc {
 		uint8_t control_ext;
 	} type_raw /* XXX __packed ??? */;
 	} llc_un /* XXX __packed ??? */;
-} __packed;
+};
 
 struct frmrinfo {
 	uint8_t frmr_rej_pdu0;
@@ -90,7 +90,12 @@ struct frmrinfo {
 	uint8_t frmr_control;
 	uint8_t frmr_control_ext;
 	uint8_t frmr_cause;
-} __packed;
+};
+
+#ifdef CTASSERT
+CTASSERT(sizeof(struct llc) == 8);
+CTASSERT(sizeof(struct frmrinfo) == 5);
+#endif
 
 #define	llc_control		llc_un.type_u.control
 #define	llc_control_ext		llc_un.type_raw.control_ext



CVS commit: src/sys/net

2021-02-03 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Wed Feb  3 10:31:10 UTC 2021

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

Log Message:
Whitespace


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sys/net/if_arp.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_arp.h
diff -u src/sys/net/if_arp.h:1.34 src/sys/net/if_arp.h:1.35
--- src/sys/net/if_arp.h:1.34	Wed Feb  3 05:51:40 2021
+++ src/sys/net/if_arp.h	Wed Feb  3 10:31:10 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_arp.h,v 1.34 2021/02/03 05:51:40 roy Exp $	*/
+/*	$NetBSD: if_arp.h,v 1.35 2021/02/03 10:31:10 roy Exp $	*/
 
 /*
  * Copyright (c) 1986, 1993
@@ -45,22 +45,22 @@
  */
 struct	arphdr {
 	uint16_t ar_hrd;	/* format of hardware address */
-#define ARPHRD_ETHER 	1	/* ethernet hardware format */
-#define ARPHRD_IEEE802 	6	/* IEEE 802 hardware format */
-#define ARPHRD_ARCNET 	7	/* ethernet hardware format */
-#define ARPHRD_FRELAY 	15	/* frame relay hardware format */
-#define ARPHRD_STRIP 	23	/* Ricochet Starmode Radio hardware format */
-#define	ARPHRD_IEEE1394	24	/* IEEE 1394 (FireWire) hardware format */
-	uint16_t ar_pro;	/* format of protocol address */
-	uint8_t  ar_hln;	/* length of hardware address */
-	uint8_t  ar_pln;	/* length of protocol address */
-	uint16_t ar_op;		/* one of: */
-#define	ARPOP_REQUEST	1	/* request to resolve address */
-#define	ARPOP_REPLY	2	/* response to previous request */
-#define	ARPOP_REVREQUEST 3	/* request protocol address given hardware */
-#define	ARPOP_REVREPLY	4	/* response giving protocol address */
-#define	ARPOP_INVREQUEST 8 	/* request to identify peer */
-#define	ARPOP_INVREPLY	9	/* response identifying peer */
+#define ARPHRD_ETHER		1  /* ethernet hardware format */
+#define ARPHRD_IEEE802		6  /* IEEE 802 hardware format */
+#define ARPHRD_ARCNET		7  /* ethernet hardware format */
+#define ARPHRD_FRELAY		15 /* frame relay hardware format */
+#define ARPHRD_STRIP		23 /* Ricochet Starmode Radio hardware format */
+#define	ARPHRD_IEEE1394		24 /* IEEE 1394 (FireWire) hardware format */
+	uint16_t ar_pro;	   /* format of protocol address */
+	uint8_t  ar_hln;	   /* length of hardware address */
+	uint8_t  ar_pln;	   /* length of protocol address */
+	uint16_t ar_op;		   /* one of: */
+#define	ARPOP_REQUEST		1  /* request to resolve address */
+#define	ARPOP_REPLY		2  /* response to previous request */
+#define	ARPOP_REVREQUEST	3  /* request protocol address given hardware */
+#define	ARPOP_REVREPLY		4  /* response giving protocol address */
+#define	ARPOP_INVREQUEST	8  /* request to identify peer */
+#define	ARPOP_INVREPLY		9  /* response identifying peer */
 /*
  * The remaining fields are variable in size,
  * according to the sizes above.



CVS commit: src/sys/net

2021-01-30 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Jan 30 21:23:08 UTC 2021

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

Log Message:
Add symmetric toeplitz implementation with integration for NICs, from OpenBSD.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sys/net/files.net
cvs rdiff -u -r0 -r1.1 src/sys/net/toeplitz.c src/sys/net/toeplitz.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/files.net
diff -u src/sys/net/files.net:1.29 src/sys/net/files.net:1.30
--- src/sys/net/files.net:1.29	Sun Sep 27 13:31:04 2020
+++ src/sys/net/files.net	Sat Jan 30 21:23:08 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: files.net,v 1.29 2020/09/27 13:31:04 roy Exp $
+#	$NetBSD: files.net,v 1.30 2021/01/30 21:23:08 jmcneill Exp $
 
 # XXX CLEANUP
 define	net
@@ -49,6 +49,7 @@ file	net/rss_config.c		net
 file	net/rtbl.c			net
 file	net/rtsock.c			net
 file	net/slcompress.c		sl | ppp | (irip & irip_vj)
+file	net/toeplitz.c			toeplitz
 file	net/zlib.c			(ppp & ppp_deflate) | swcrypto | vnd_compression
 file	netinet/accf_data.c		accf_data
 file	netinet/accf_http.c		accf_http

Added files:

Index: src/sys/net/toeplitz.c
diff -u /dev/null src/sys/net/toeplitz.c:1.1
--- /dev/null	Sat Jan 30 21:23:08 2021
+++ src/sys/net/toeplitz.c	Sat Jan 30 21:23:08 2021
@@ -0,0 +1,204 @@
+/* $OpenBSD: toeplitz.c,v 1.9 2020/09/01 19:18:26 tb Exp $ */
+
+/*
+ * Copyright (c) 2009 The DragonFly Project.  All rights reserved.
+ *
+ * This code is derived from software contributed to The DragonFly Project
+ * by Sepherosa Ziehau 
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in
+ *the documentation and/or other materials provided with the
+ *distribution.
+ * 3. Neither the name of The DragonFly Project nor the names of its
+ *contributors may be used to endorse or promote products derived
+ *from this software without specific, prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Copyright (c) 2019 David Gwynne 
+ * Copyright (c) 2020 Theo Buehler 
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include 
+
+/*
+ * symmetric toeplitz
+ */
+
+static stoeplitz_key		stoeplitz_keyseed = STOEPLITZ_KEYSEED;
+static struct stoeplitz_cache	stoeplitz_syskey_cache;
+const struct stoeplitz_cache *const
+stoeplitz_cache = _syskey_cache;
+
+/* parity of n16: count (mod 2) of ones in the binary representation. */
+static int
+parity(uint16_t n16)
+{
+	n16 = ((n16 & 0x) >> 1) ^ (n16 & 0x);
+	n16 = ((n16 & 0x) >> 2) ^ (n16 & 0x);
+	n16 = ((n16 & 0xf0f0) >> 4) ^ (n16 & 0x0f0f);
+	n16 = ((n16 & 0xff00) >> 8) ^ (n16 & 0x00ff);
+
+	return (n16);
+}
+
+/*
+ * The Toeplitz matrix obtained from a seed is invertible if and only if the
+ * parity of the seed is 1. Generate such a seed uniformly at random.
+ */
+static stoeplitz_key
+stoeplitz_random_seed(void)
+{
+	stoeplitz_key seed;
+
+	seed = cprng_strong32() & UINT16_MAX;

CVS commit: src/sys/net/npf

2021-01-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Jan 27 17:39:13 UTC 2021

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

Log Message:
Don't silently ignore the errors from npfctl_run_op. We end up returning
packets to userland that are missing required fields (like in rule_add the
id of the rule) and npfctl aborts.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 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_os.c
diff -u src/sys/net/npf/npf_os.c:1.20 src/sys/net/npf/npf_os.c:1.21
--- src/sys/net/npf/npf_os.c:1.20	Mon Jan 25 12:17:19 2021
+++ src/sys/net/npf/npf_os.c	Wed Jan 27 12:39:13 2021
@@ -33,7 +33,7 @@
 
 #ifdef _KERNEL
 #include 
-__KERNEL_RCSID(0, "$NetBSD: npf_os.c,v 1.20 2021/01/25 17:17:19 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf_os.c,v 1.21 2021/01/27 17:39:13 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "pf.h"
@@ -298,8 +298,11 @@ npf_dev_ioctl(dev_t dev, u_long cmd, voi
 #endif
 	}
 	resp = nvlist_create(0);
-	npfctl_run_op(npf, cmd, req, resp);
-	error = nvlist_copyout(data, resp);
+
+	if ((error = npfctl_run_op(npf, cmd, req, resp)) == 0) {
+		error = nvlist_copyout(data, resp);
+	}
+
 	nvlist_destroy(resp);
 	nvlist_destroy(req);
 



CVS commit: src/sys/net/npf

2021-01-25 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Jan 25 17:18:55 UTC 2021

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

Log Message:
s/npf_config_lock/npf->config_lock/ in the comments


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/sys/net/npf/npf_conn.c
cvs rdiff -u -r1.35 -r1.36 src/sys/net/npf/npf_tableset.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.32 src/sys/net/npf/npf_conn.c:1.33
--- src/sys/net/npf/npf_conn.c:1.32	Sat May 30 10:16:56 2020
+++ src/sys/net/npf/npf_conn.c	Mon Jan 25 12:18:55 2021
@@ -97,14 +97,14 @@
  *
  * Lock order
  *
- *	npf_config_lock ->
+ *	npf->config_lock ->
  *		conn_lock ->
  *			npf_conn_t::c_lock
  */
 
 #ifdef _KERNEL
 #include 
-__KERNEL_RCSID(0, "$NetBSD: npf_conn.c,v 1.32 2020/05/30 14:16:56 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf_conn.c,v 1.33 2021/01/25 17:18:55 christos Exp $");
 
 #include 
 #include 

Index: src/sys/net/npf/npf_tableset.c
diff -u src/sys/net/npf/npf_tableset.c:1.35 src/sys/net/npf/npf_tableset.c:1.36
--- src/sys/net/npf/npf_tableset.c:1.35	Sat May 30 10:16:56 2020
+++ src/sys/net/npf/npf_tableset.c	Mon Jan 25 12:18:55 2021
@@ -46,7 +46,7 @@
 
 #ifdef _KERNEL
 #include 
-__KERNEL_RCSID(0, "$NetBSD: npf_tableset.c,v 1.35 2020/05/30 14:16:56 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf_tableset.c,v 1.36 2021/01/25 17:18:55 christos Exp $");
 
 #include 
 #include 
@@ -101,7 +101,7 @@ struct npf_table {
 
 	/*
 	 * Table ID, type and lock.  The ID may change during the
-	 * config reload, it is protected by the npf_config_lock.
+	 * config reload, it is protected by the npf->config_lock.
 	 */
 	int			t_type;
 	unsigned		t_id;



CVS commit: src/sys/net/npf

2021-01-25 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Jan 25 17:17:19 UTC 2021

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

Log Message:
Fix locking issue: npf_default_pass needs to be called with the config lock
held.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 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_os.c
diff -u src/sys/net/npf/npf_os.c:1.19 src/sys/net/npf/npf_os.c:1.20
--- src/sys/net/npf/npf_os.c:1.19	Tue Aug 18 03:53:24 2020
+++ src/sys/net/npf/npf_os.c	Mon Jan 25 12:17:19 2021
@@ -33,7 +33,7 @@
 
 #ifdef _KERNEL
 #include 
-__KERNEL_RCSID(0, "$NetBSD: npf_os.c,v 1.19 2020/08/18 07:53:24 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf_os.c,v 1.20 2021/01/25 17:17:19 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "pf.h"
@@ -321,8 +321,16 @@ npf_dev_read(dev_t dev, struct uio *uio,
 bool
 npf_autounload_p(void)
 {
+	if (npf_active_p())
+		return false;
+
 	npf_t *npf = npf_getkernctx();
-	return !npf_active_p() && npf_default_pass(npf);
+
+	npf_config_enter(npf);
+	bool pass = npf_default_pass(npf);
+	npf_config_exit(npf);
+
+	return pass;
 }
 
 /*



CVS commit: src/sys/net

2020-12-17 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Dec 18 01:31:49 UTC 2020

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

Log Message:
Use sel{record,remove}_knote().


To generate a diff of this commit:
cvs rdiff -u -r1.238 -r1.239 src/sys/net/bpf.c
cvs rdiff -u -r1.120 -r1.121 src/sys/net/if_tap.c
cvs rdiff -u -r1.161 -r1.162 src/sys/net/if_tun.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.238 src/sys/net/bpf.c:1.239
--- src/sys/net/bpf.c:1.238	Sun Aug  2 07:19:39 2020
+++ src/sys/net/bpf.c	Fri Dec 18 01:31:49 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpf.c,v 1.238 2020/08/02 07:19:39 maxv Exp $	*/
+/*	$NetBSD: bpf.c,v 1.239 2020/12/18 01:31:49 thorpej Exp $	*/
 
 /*
  * Copyright (c) 1990, 1991, 1993
@@ -39,7 +39,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.238 2020/08/02 07:19:39 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.239 2020/12/18 01:31:49 thorpej Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_bpf.h"
@@ -1528,7 +1528,7 @@ filt_bpfrdetach(struct knote *kn)
 	struct bpf_d *d = kn->kn_hook;
 
 	mutex_enter(d->bd_buf_mtx);
-	SLIST_REMOVE(>bd_sel.sel_klist, kn, knote, kn_selnext);
+	selremove_knote(>bd_sel, kn);
 	mutex_exit(d->bd_buf_mtx);
 }
 
@@ -1558,23 +1558,20 @@ static int
 bpf_kqfilter(struct file *fp, struct knote *kn)
 {
 	struct bpf_d *d = fp->f_bpf;
-	struct klist *klist;
 
-	mutex_enter(d->bd_buf_mtx);
 	switch (kn->kn_filter) {
 	case EVFILT_READ:
-		klist = >bd_sel.sel_klist;
 		kn->kn_fop = _filtops;
 		break;
 
 	default:
-		mutex_exit(d->bd_buf_mtx);
 		return (EINVAL);
 	}
 
 	kn->kn_hook = d;
 
-	SLIST_INSERT_HEAD(klist, kn, kn_selnext);
+	mutex_enter(d->bd_buf_mtx);
+	selrecord_knote(>bd_sel, kn);
 	mutex_exit(d->bd_buf_mtx);
 
 	return (0);

Index: src/sys/net/if_tap.c
diff -u src/sys/net/if_tap.c:1.120 src/sys/net/if_tap.c:1.121
--- src/sys/net/if_tap.c:1.120	Fri Oct 30 22:51:08 2020
+++ src/sys/net/if_tap.c	Fri Dec 18 01:31:49 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_tap.c,v 1.120 2020/10/30 22:51:08 christos Exp $	*/
+/*	$NetBSD: if_tap.c,v 1.121 2020/12/18 01:31:49 thorpej Exp $	*/
 
 /*
  *  Copyright (c) 2003, 2004, 2008, 2009 The NetBSD Foundation.
@@ -33,7 +33,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_tap.c,v 1.120 2020/10/30 22:51:08 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_tap.c,v 1.121 2020/12/18 01:31:49 thorpej Exp $");
 
 #if defined(_KERNEL_OPT)
 
@@ -1227,7 +1227,7 @@ tap_dev_kqfilter(int unit, struct knote 
 
 	kn->kn_hook = sc;
 	mutex_spin_enter(>sc_lock);
-	SLIST_INSERT_HEAD(>sc_rsel.sel_klist, kn, kn_selnext);
+	selrecord_knote(>sc_rsel, kn);
 	mutex_spin_exit(>sc_lock);
 	KERNEL_UNLOCK_ONE(NULL);
 	return 0;
@@ -1240,7 +1240,7 @@ tap_kqdetach(struct knote *kn)
 
 	KERNEL_LOCK(1, NULL);
 	mutex_spin_enter(>sc_lock);
-	SLIST_REMOVE(>sc_rsel.sel_klist, kn, knote, kn_selnext);
+	selremove_knote(>sc_rsel, kn);
 	mutex_spin_exit(>sc_lock);
 	KERNEL_UNLOCK_ONE(NULL);
 }

Index: src/sys/net/if_tun.c
diff -u src/sys/net/if_tun.c:1.161 src/sys/net/if_tun.c:1.162
--- src/sys/net/if_tun.c:1.161	Sun Sep 27 19:25:54 2020
+++ src/sys/net/if_tun.c	Fri Dec 18 01:31:49 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_tun.c,v 1.161 2020/09/27 19:25:54 roy Exp $	*/
+/*	$NetBSD: if_tun.c,v 1.162 2020/12/18 01:31:49 thorpej Exp $	*/
 
 /*
  * Copyright (c) 1988, Julian Onions 
@@ -19,7 +19,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_tun.c,v 1.161 2020/09/27 19:25:54 roy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_tun.c,v 1.162 2020/12/18 01:31:49 thorpej Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1051,7 +1051,7 @@ filt_tunrdetach(struct knote *kn)
 	struct tun_softc *tp = kn->kn_hook;
 
 	mutex_enter(>tun_lock);
-	SLIST_REMOVE(>tun_rsel.sel_klist, kn, knote, kn_selnext);
+	selremove_knote(>tun_rsel, kn);
 	mutex_exit(>tun_lock);
 }
 
@@ -1099,7 +1099,6 @@ int
 tunkqfilter(dev_t dev, struct knote *kn)
 {
 	struct tun_softc *tp;
-	struct klist *klist;
 	int rv = 0;
 
 	tp = tun_find_unit(dev);
@@ -1108,12 +1107,10 @@ tunkqfilter(dev_t dev, struct knote *kn)
 
 	switch (kn->kn_filter) {
 	case EVFILT_READ:
-		klist = >tun_rsel.sel_klist;
 		kn->kn_fop = _filtops;
 		break;
 
 	case EVFILT_WRITE:
-		klist = >tun_rsel.sel_klist;
 		kn->kn_fop = _seltrue_filtops;
 		break;
 
@@ -1124,7 +1121,7 @@ tunkqfilter(dev_t dev, struct knote *kn)
 
 	kn->kn_hook = tp;
 
-	SLIST_INSERT_HEAD(klist, kn, kn_selnext);
+	selrecord_knote(>tun_rsel, kn);
 
 out:
 	mutex_exit(>tun_lock);



CVS commit: src/sys/net

2020-11-26 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Fri Nov 27 03:37:11 UTC 2020

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

Log Message:
Fix missing disable of kpreempt while getting interface address


To generate a diff of this commit:
cvs rdiff -u -r1.214 -r1.215 src/sys/net/if_spppsubr.c

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

Modified files:

Index: src/sys/net/if_spppsubr.c
diff -u src/sys/net/if_spppsubr.c:1.214 src/sys/net/if_spppsubr.c:1.215
--- src/sys/net/if_spppsubr.c:1.214	Wed Nov 25 10:44:53 2020
+++ src/sys/net/if_spppsubr.c	Fri Nov 27 03:37:11 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppsubr.c,v 1.214 2020/11/25 10:44:53 yamaguchi Exp $	 */
+/*	$NetBSD: if_spppsubr.c,v 1.215 2020/11/27 03:37:11 yamaguchi Exp $	 */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.214 2020/11/25 10:44:53 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.215 2020/11/27 03:37:11 yamaguchi Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -3327,7 +3327,9 @@ sppp_ipcp_open(struct sppp *sp, void *xc
 	memset(>dns_addrs, 0, sizeof sp->dns_addrs);
 
 #ifdef INET
+	kpreempt_disable();
 	sppp_get_ip_addrs(sp, , , 0);
+	kpreempt_enable();
 #else
 	myaddr = hisaddr = 0;
 #endif
@@ -3809,10 +3811,13 @@ sppp_ipcp_scr(struct sppp *sp)
 
 #ifdef INET
 	if (ISSET(sp->ipcp.opts, SPPP_IPCP_OPT_ADDRESS)) {
-		if (sp->ipcp.flags & IPCP_MYADDR_SEEN)
+		if (sp->ipcp.flags & IPCP_MYADDR_SEEN) {
 			ouraddr = sp->ipcp.req_myaddr;	/* not sure if this can ever happen */
-		else
+		} else {
+			kpreempt_disable();
 			sppp_get_ip_addrs(sp, , 0, 0);
+			kpreempt_enable();
+		}
 		opt[i++] = IPCP_OPT_ADDRESS;
 		opt[i++] = 6;
 		opt[i++] = ouraddr >> 24;
@@ -3879,7 +3884,9 @@ sppp_ipv6cp_open(struct sppp *sp, void *
 	sp->ipv6cp.flags &= ~IPV6CP_MYIFID_SEEN;
 #endif
 
+	kpreempt_disable();
 	sppp_get_ip6_addrs(sp, , , 0);
+	kpreempt_enable();
 	/*
 	 * If we don't have our address, this probably means our
 	 * interface doesn't want to talk IPv6 at all.  (This could
@@ -4308,7 +4315,10 @@ sppp_ipv6cp_scr(struct sppp *sp)
 	KASSERT(SPPP_WLOCKED(sp));
 
 	if (ISSET(sp->ipv6cp.opts, SPPP_IPV6CP_OPT_IFID)) {
+		kpreempt_disable();
 		sppp_get_ip6_addrs(sp, , 0, 0);
+		kpreempt_enable();
+
 		opt[i++] = IPV6CP_OPT_IFID;
 		opt[i++] = 10;
 		memcpy([i], _addr[8], 8);
@@ -6056,7 +6066,9 @@ sppp_params(struct sppp *sp, u_long cmd,
 		status->state = sp->scp[IDX_IPCP].state;
 		status->opts = sp->ipcp.opts;
 #ifdef INET
+		kpreempt_disable();
 		sppp_get_ip_addrs(sp, , 0, 0);
+		kpreempt_enable();
 #else
 		myaddr = 0;
 #endif



CVS commit: src/sys/net

2020-11-25 Thread Shoichi YAMAGUCHI
Module Name:src
Committed By:   yamaguchi
Date:   Wed Nov 25 10:44:53 UTC 2020

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

Log Message:
add KASSERT(!cpu_softintr_p());

pointed out by knakahara@n.o., thanks.


To generate a diff of this commit:
cvs rdiff -u -r1.213 -r1.214 src/sys/net/if_spppsubr.c

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

Modified files:

Index: src/sys/net/if_spppsubr.c
diff -u src/sys/net/if_spppsubr.c:1.213 src/sys/net/if_spppsubr.c:1.214
--- src/sys/net/if_spppsubr.c:1.213	Wed Nov 25 10:30:51 2020
+++ src/sys/net/if_spppsubr.c	Wed Nov 25 10:44:53 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppsubr.c,v 1.213 2020/11/25 10:30:51 yamaguchi Exp $	 */
+/*	$NetBSD: if_spppsubr.c,v 1.214 2020/11/25 10:44:53 yamaguchi Exp $	 */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.213 2020/11/25 10:30:51 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.214 2020/11/25 10:44:53 yamaguchi Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -1869,6 +1869,7 @@ sppp_up_event(struct sppp *sp, void *xcp
 	STDDCL;
 
 	KASSERT(SPPP_WLOCKED(sp));
+	KASSERT(!cpu_softintr_p());
 
 	if ((cp->flags & CP_AUTH) != 0 &&
 	sppp_auth_role(cp, sp) == SPPP_AUTH_NOROLE)
@@ -1902,6 +1903,7 @@ sppp_down_event(struct sppp *sp, void *x
 	STDDCL;
 
 	KASSERT(SPPP_WLOCKED(sp));
+	KASSERT(!cpu_softintr_p());
 
 	if ((cp->flags & CP_AUTH) != 0 &&
 	sppp_auth_role(cp, sp) == SPPP_AUTH_NOROLE)
@@ -1944,6 +1946,7 @@ sppp_open_event(struct sppp *sp, void *x
 	STDDCL;
 
 	KASSERT(SPPP_WLOCKED(sp));
+	KASSERT(!cpu_softintr_p());
 
 	if ((cp->flags & CP_AUTH) != 0 &&
 	sppp_auth_role(cp, sp) == SPPP_AUTH_NOROLE)
@@ -1986,6 +1989,7 @@ sppp_close_event(struct sppp *sp, void *
 	STDDCL;
 
 	KASSERT(SPPP_WLOCKED(sp));
+	KASSERT(!cpu_softintr_p());
 
 	if ((cp->flags & CP_AUTH) != 0 &&
 	sppp_auth_role(cp, sp) == SPPP_AUTH_NOROLE)
@@ -2035,6 +2039,7 @@ sppp_to_event(struct sppp *sp, void *xcp
 	STDDCL;
 
 	KASSERT(SPPP_WLOCKED(sp));
+	KASSERT(!cpu_softintr_p());
 
 	s = splnet();
 
@@ -2097,6 +2102,8 @@ sppp_rcr_event(struct sppp *sp, void *xc
 	size_t blen;
 	STDDCL;
 
+	KASSERT(!cpu_softintr_p());
+
 	type = sp->scp[cp->protoidx].rcr_type;
 	buf = sp->scp[cp->protoidx].rcr_buf;
 	blen = sp->scp[cp->protoidx].rcr_blen;
@@ -2202,6 +2209,8 @@ sppp_rca_event(struct sppp *sp, void *xc
 	const struct cp *cp = xcp;
 	STDDCL;
 
+	KASSERT(!cpu_softintr_p());
+
 	switch (sp->scp[cp->protoidx].state) {
 	case STATE_CLOSED:
 	case STATE_STOPPED:
@@ -2246,6 +2255,8 @@ sppp_rcn_event(struct sppp *sp, void *xc
 	const struct cp *cp = xcp;
 	struct ifnet *ifp = >pp_if;
 
+	KASSERT(!cpu_softintr_p());
+
 	switch (sp->scp[cp->protoidx].state) {
 	case STATE_CLOSED:
 	case STATE_STOPPED:
@@ -2283,6 +2294,8 @@ sppp_rtr_event(struct sppp *sp, void *xc
 	const struct cp *cp = xcp;
 	STDDCL;
 
+	KASSERT(!cpu_softintr_p());
+
 	switch (sp->scp[cp->protoidx].state) {
 	case STATE_ACK_RCVD:
 	case STATE_ACK_SENT:
@@ -2323,6 +2336,8 @@ sppp_rta_event(struct sppp *sp, void *xc
 	const struct cp *cp = xcp;
 	struct ifnet *ifp = >pp_if;
 
+	KASSERT(!cpu_softintr_p());
+
 	switch (sp->scp[cp->protoidx].state) {
 	case STATE_CLOSED:
 	case STATE_STOPPED:
@@ -2359,6 +2374,8 @@ sppp_rxj_event(struct sppp *sp, void *xc
 	const struct cp *cp = xcp;
 	struct ifnet *ifp = >pp_if;
 
+	KASSERT(!cpu_softintr_p());
+
 	/* XXX catastrophic rejects (RXJ-) aren't handled yet. */
 	switch (sp->scp[cp->protoidx].state) {
 	case STATE_CLOSED:
@@ -2485,6 +2502,7 @@ sppp_lcp_down(struct sppp *sp, void *xcp
 	STDDCL;
 
 	KASSERT(SPPP_WLOCKED(sp));
+	KASSERT(!cpu_softintr_p());
 
 	pidx = cp->protoidx;
 	sppp_down_event(sp, xcp);
@@ -2536,6 +2554,7 @@ sppp_lcp_open(struct sppp *sp, void *xcp
 {
 
 	KASSERT(SPPP_WLOCKED(sp));
+	KASSERT(!cpu_softintr_p());
 
 	sp->lcp.reestablish = false;
 
@@ -3300,6 +3319,7 @@ sppp_ipcp_open(struct sppp *sp, void *xc
 	uint32_t myaddr, hisaddr;
 
 	KASSERT(SPPP_WLOCKED(sp));
+	KASSERT(!cpu_softintr_p());
 
 	sp->ipcp.flags &= ~(IPCP_HISADDR_SEEN|IPCP_MYADDR_SEEN|IPCP_MYADDR_DYN|IPCP_HISADDR_DYN);
 	sp->ipcp.req_myaddr = 0;
@@ -3360,6 +3380,7 @@ sppp_ipcp_close(struct sppp *sp, void *x
 {
 
 	KASSERT(SPPP_WLOCKED(sp));
+	KASSERT(!cpu_softintr_p());
 
 	sppp_close_event(sp, xcp);
 
@@ -3850,6 +3871,7 @@ sppp_ipv6cp_open(struct sppp *sp, void *
 	struct in6_addr myaddr, hisaddr;
 
 	KASSERT(SPPP_WLOCKED(sp));
+	KASSERT(!cpu_softintr_p());
 
 #ifdef IPV6CP_MYIFID_DYN
 	sp->ipv6cp.flags &= ~(IPV6CP_MYIFID_SEEN|IPV6CP_MYIFID_DYN);
@@ -4795,6 +4817,8 @@ sppp_chap_rcv_challenge_event(struct spp
 {
 	const struct cp *cp = xcp;
 
+	KASSERT(!cpu_softintr_p());
+
 	sp->chap.rechallenging = false;
 
 	switch (sp->scp[IDX_CHAP].state) {
@@ -5193,6 +5217,7 @@ sppp_auth_to_event(struct sppp *sp, void
 	STDDCL;
 
 	KASSERT(SPPP_WLOCKED(sp));
+	

  1   2   3   4   5   6   7   8   9   10   >