CVS commit: src/sys/netinet6

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

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

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


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

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

Modified files:

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



CVS commit: src/sys/sys

2021-07-21 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Wed Jul 21 07:39:58 UTC 2021

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

Log Message:
Bump the version for ALTQ/CBQ changes

Welcome to 9.99.87


To generate a diff of this commit:
cvs rdiff -u -r1.698 -r1.699 src/sys/sys/param.h

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

Modified files:

Index: src/sys/sys/param.h
diff -u src/sys/sys/param.h:1.698 src/sys/sys/param.h:1.699
--- src/sys/sys/param.h:1.698	Mon Jul 19 19:13:33 2021
+++ src/sys/sys/param.h	Wed Jul 21 07:39:58 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: param.h,v 1.698 2021/07/19 19:13:33 christos Exp $	*/
+/*	$NetBSD: param.h,v 1.699 2021/07/21 07:39:58 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -67,7 +67,7 @@
  *	2.99.9		(299000900)
  */
 
-#define	__NetBSD_Version__	999008600	/* NetBSD 9.99.86 */
+#define	__NetBSD_Version__	999008700	/* NetBSD 9.99.87 */
 
 #define __NetBSD_Prereq__(M,m,p) (M) * 1) + \
 (m) * 100) + (p) * 100) <= __NetBSD_Version__)



CVS commit: src/sys/altq

2021-07-21 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Wed Jul 21 07:34:44 UTC 2021

Modified Files:
src/sys/altq: altq_cbq.c altq_rmclass.c

Log Message:
altq: fix CBQ with RED and/or pf


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/sys/altq/altq_cbq.c
cvs rdiff -u -r1.28 -r1.29 src/sys/altq/altq_rmclass.c

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

Modified files:

Index: src/sys/altq/altq_cbq.c
diff -u src/sys/altq/altq_cbq.c:1.35 src/sys/altq/altq_cbq.c:1.36
--- src/sys/altq/altq_cbq.c:1.35	Wed Jul 21 06:33:30 2021
+++ src/sys/altq/altq_cbq.c	Wed Jul 21 07:34:44 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: altq_cbq.c,v 1.35 2021/07/21 06:33:30 ozaki-r Exp $	*/
+/*	$NetBSD: altq_cbq.c,v 1.36 2021/07/21 07:34:44 ozaki-r Exp $	*/
 /*	$KAME: altq_cbq.c,v 1.21 2005/04/13 03:44:24 suz Exp $	*/
 
 /*
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: altq_cbq.c,v 1.35 2021/07/21 06:33:30 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: altq_cbq.c,v 1.36 2021/07/21 07:34:44 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_altq.h"
@@ -306,6 +306,7 @@ cbq_remove_altq(struct pf_altq *a)
 	return (0);
 }
 
+#define NSEC_TO_PSEC(s)	((uint64_t)(s) * 1000 * 1000)
 int
 cbq_add_queue(struct pf_altq *a)
 {
@@ -384,7 +385,7 @@ cbq_add_queue(struct pf_altq *a)
 	 */
 	if ((opts->flags & CBQCLF_ROOTCLASS) != 0) {
 		error = rmc_init(cbqp->ifnp.ifq_, &cbqp->ifnp,
-		opts->ps_per_byte, cbqrestart, a->qlimit, RM_MAXQUEUED,
+		NSEC_TO_PSEC(opts->ns_per_byte), cbqrestart, a->qlimit, RM_MAXQUEUED,
 		opts->maxidle, opts->minidle, opts->offtime,
 		opts->flags);
 		if (error != 0)
@@ -392,7 +393,7 @@ cbq_add_queue(struct pf_altq *a)
 		cl = cbqp->ifnp.root_;
 	} else {
 		cl = rmc_newclass(a->priority,
-  &cbqp->ifnp, opts->ps_per_byte,
+  &cbqp->ifnp, NSEC_TO_PSEC(opts->ns_per_byte),
   rmc_delay_action, a->qlimit, parent, borrow,
   opts->maxidle, opts->minidle, opts->offtime,
   opts->pktsize, opts->flags);

Index: src/sys/altq/altq_rmclass.c
diff -u src/sys/altq/altq_rmclass.c:1.28 src/sys/altq/altq_rmclass.c:1.29
--- src/sys/altq/altq_rmclass.c:1.28	Wed Jul 21 06:49:25 2021
+++ src/sys/altq/altq_rmclass.c	Wed Jul 21 07:34:44 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: altq_rmclass.c,v 1.28 2021/07/21 06:49:25 ozaki-r Exp $	*/
+/*	$NetBSD: altq_rmclass.c,v 1.29 2021/07/21 07:34:44 ozaki-r Exp $	*/
 /*	$KAME: altq_rmclass.c,v 1.19 2005/04/13 03:44:25 suz Exp $	*/
 
 /*
@@ -38,7 +38,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: altq_rmclass.c,v 1.28 2021/07/21 06:49:25 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: altq_rmclass.c,v 1.29 2021/07/21 07:34:44 ozaki-r Exp $");
 
 /* #ident "@(#)rm_class.c  1.48 97/12/05 SMI" */
 
@@ -287,7 +287,7 @@ rmc_newclass(int pri, struct rm_ifdat *i
 		if (flags & RMCF_CLEARDSCP)
 			red_flags |= RIOF_CLEARDSCP;
 #endif
-		red_pkttime = nsecPerByte * pktsize  / 1000;
+		red_pkttime = PSEC_TO_NSEC(psecPerByte) * pktsize  / 1000;
 
 		if (flags & RMCF_RED) {
 			cl->red_ = red_alloc(0, 0,



CVS commit: src/sys/altq

2021-07-20 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Wed Jul 21 06:49:26 UTC 2021

Modified Files:
src/sys/altq: altq_rmclass.c

Log Message:
altq, cbq: apply tweaks for PPP to only PPP interfaces


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

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

Modified files:

Index: src/sys/altq/altq_rmclass.c
diff -u src/sys/altq/altq_rmclass.c:1.27 src/sys/altq/altq_rmclass.c:1.28
--- src/sys/altq/altq_rmclass.c:1.27	Wed Jul 21 06:47:33 2021
+++ src/sys/altq/altq_rmclass.c	Wed Jul 21 06:49:25 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: altq_rmclass.c,v 1.27 2021/07/21 06:47:33 ozaki-r Exp $	*/
+/*	$NetBSD: altq_rmclass.c,v 1.28 2021/07/21 06:49:25 ozaki-r Exp $	*/
 /*	$KAME: altq_rmclass.c,v 1.19 2005/04/13 03:44:25 suz Exp $	*/
 
 /*
@@ -38,7 +38,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: altq_rmclass.c,v 1.27 2021/07/21 06:47:33 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: altq_rmclass.c,v 1.28 2021/07/21 06:49:25 ozaki-r Exp $");
 
 /* #ident "@(#)rm_class.c  1.48 97/12/05 SMI" */
 
@@ -62,6 +62,7 @@ __KERNEL_RCSID(0, "$NetBSD: altq_rmclass
 #include 
 
 #include 
+#include 
 #ifdef ALTQ3_COMPAT
 #include 
 #include 
@@ -1291,32 +1292,32 @@ rmc_update_class_util(struct rm_ifdat *i
 #else
 	pkt_time = ifd->curlen_[ifd->qo_] * ifd->ns_per_byte_ / 1000;
 #endif
-#if 1 /* ALTQ4PPP */
-	if (TS_LT(nowp, &ifd->ifnow_)) {
-		int iftime;
+	if (ifd->ifq_->altq_ifp->if_type == IFT_PPP) {
+		if (TS_LT(nowp, &ifd->ifnow_)) {
+			int iftime;
 
-		/*
-		 * make sure the estimated completion time does not go
-		 * too far.  it can happen when the link layer supports
-		 * data compression or the interface speed is set to
-		 * a much lower value.
-		 */
-		TS_DELTA(&ifd->ifnow_, nowp, iftime);
-		if (iftime+pkt_time < ifd->maxiftime_) {
-			TS_ADD_DELTA(&ifd->ifnow_, pkt_time, &ifd->ifnow_);
+			/*
+			 * make sure the estimated completion time does not go
+			 * too far.  it can happen when the link layer supports
+			 * data compression or the interface speed is set to
+			 * a much lower value.
+			 */
+			TS_DELTA(&ifd->ifnow_, nowp, iftime);
+			if (iftime+pkt_time < ifd->maxiftime_) {
+TS_ADD_DELTA(&ifd->ifnow_, pkt_time, &ifd->ifnow_);
+			} else {
+TS_ADD_DELTA(nowp, ifd->maxiftime_, &ifd->ifnow_);
+			}
 		} else {
-			TS_ADD_DELTA(nowp, ifd->maxiftime_, &ifd->ifnow_);
+			TS_ADD_DELTA(nowp, pkt_time, &ifd->ifnow_);
 		}
 	} else {
-		TS_ADD_DELTA(nowp, pkt_time, &ifd->ifnow_);
-	}
-#else
-	if (TS_LT(nowp, &ifd->ifnow_)) {
-		TS_ADD_DELTA(&ifd->ifnow_, pkt_time, &ifd->ifnow_);
-	} else {
-		TS_ADD_DELTA(nowp, pkt_time, &ifd->ifnow_);
+		if (TS_LT(nowp, &ifd->ifnow_)) {
+			TS_ADD_DELTA(&ifd->ifnow_, pkt_time, &ifd->ifnow_);
+		} else {
+			TS_ADD_DELTA(nowp, pkt_time, &ifd->ifnow_);
+		}
 	}
-#endif
 
 	while (cl != NULL) {
 		TS_DELTA(&ifd->ifnow_, &cl->last_, idle);



CVS commit: src/usr.sbin/altq/altqstat

2021-07-20 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Wed Jul 21 06:48:28 UTC 2021

Modified Files:
src/usr.sbin/altq/altqstat: qdisc_cbq.c

Log Message:
altqstat, cbq: follow uint64_t changes

PR kern/56319


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/usr.sbin/altq/altqstat/qdisc_cbq.c

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

Modified files:

Index: src/usr.sbin/altq/altqstat/qdisc_cbq.c
diff -u src/usr.sbin/altq/altqstat/qdisc_cbq.c:1.10 src/usr.sbin/altq/altqstat/qdisc_cbq.c:1.11
--- src/usr.sbin/altq/altqstat/qdisc_cbq.c:1.10	Wed Jul 21 06:45:10 2021
+++ src/usr.sbin/altq/altqstat/qdisc_cbq.c	Wed Jul 21 06:48:28 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: qdisc_cbq.c,v 1.10 2021/07/21 06:45:10 ozaki-r Exp $	*/
+/*	$NetBSD: qdisc_cbq.c,v 1.11 2021/07/21 06:48:28 ozaki-r Exp $	*/
 /*	$KAME: qdisc_cbq.c,v 1.7 2003/09/17 14:27:37 kjc Exp $	*/
 /*
  * Copyright (C) 1999-2000
@@ -105,9 +105,9 @@ cbq_stat_loop(int fd, const char *ifname
 
 			printf("\tpriority: %d depth: %d",
 			   sp->priority, sp->depth);
-			printf(" offtime: %ld [ns] wrr_allot: %d bytes\n",
+			printf(" offtime: %"PRIi64" [ns] wrr_allot: %d bytes\n",
 			   sp->offtime, sp->wrr_allot);
-			printf("\tpsPerByte: %ld", sp->ps_per_byte);
+			printf("\tpsPerByte: %"PRIu64, sp->ps_per_byte);
 			printf("\t(%sbps)", rate2str(flow_bps));
 			if (lp->handle != NULL_CLASS_HANDLE) {
 printf(",\tMeasured: %s [bps]\n",
@@ -139,7 +139,7 @@ cbq_stat_loop(int fd, const char *ifname
 			   sp->maxidle >> RM_FILTER_GAIN,
 			   sp->minidle / RM_POWER);
 #else
-			printf("\tAvgIdle: %ld [ns],\t(maxidle: %ld minidle: %ld [ns])\n",
+			printf("\tAvgIdle: %"PRIi64" [ns],\t(maxidle: %"PRIi64" minidle: %"PRIi64" [ns])\n",
 			   sp->avgidle, sp->maxidle, sp->minidle);
 #endif
 		}



CVS commit: src/sys/altq

2021-07-20 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Wed Jul 21 06:47:33 UTC 2021

Modified Files:
src/sys/altq: altq_cbq.h altq_rmclass.c altq_rmclass.h

Log Message:
altq, cbq: change long to uint64_t for ILP32 archs

PR kern/56319


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/altq/altq_cbq.h
cvs rdiff -u -r1.26 -r1.27 src/sys/altq/altq_rmclass.c
cvs rdiff -u -r1.11 -r1.12 src/sys/altq/altq_rmclass.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/altq/altq_cbq.h
diff -u src/sys/altq/altq_cbq.h:1.10 src/sys/altq/altq_cbq.h:1.11
--- src/sys/altq/altq_cbq.h:1.10	Wed Jul 21 06:41:22 2021
+++ src/sys/altq/altq_cbq.h	Wed Jul 21 06:47:33 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: altq_cbq.h,v 1.10 2021/07/21 06:41:22 ozaki-r Exp $	*/
+/*	$NetBSD: altq_cbq.h,v 1.11 2021/07/21 06:47:33 ozaki-r Exp $	*/
 /*	$KAME: altq_cbq.h,v 1.12 2003/10/03 05:05:15 kjc Exp $	*/
 
 /*
@@ -81,15 +81,15 @@ typedef struct _cbq_class_stats_ {
 
 	/* other static class parameters useful for debugging */
 	int		priority;
-	long		maxidle;
-	long		minidle;
-	long		offtime;
+	int64_t		maxidle;
+	int64_t		minidle;
+	int64_t		offtime;
 	int		qmax;
-	u_long		ps_per_byte;
+	uint64_t	ps_per_byte;
 	int		wrr_allot;
 
 	int		qcnt;		/* # packets in queue */
-	long		avgidle;
+	int64_t		avgidle;
 
 	/* red and rio related info */
 	int		qtype;
@@ -112,7 +112,7 @@ struct cbq_interface {
 
 typedef struct cbq_class_spec {
 	u_int		priority;
-	u_long		pico_sec_per_byte;
+	uint64_t	pico_sec_per_byte;
 	u_int		maxq;
 	u_int		maxidle;
 	int		minidle;

Index: src/sys/altq/altq_rmclass.c
diff -u src/sys/altq/altq_rmclass.c:1.26 src/sys/altq/altq_rmclass.c:1.27
--- src/sys/altq/altq_rmclass.c:1.26	Wed Jul 21 06:41:22 2021
+++ src/sys/altq/altq_rmclass.c	Wed Jul 21 06:47:33 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: altq_rmclass.c,v 1.26 2021/07/21 06:41:22 ozaki-r Exp $	*/
+/*	$NetBSD: altq_rmclass.c,v 1.27 2021/07/21 06:47:33 ozaki-r Exp $	*/
 /*	$KAME: altq_rmclass.c,v 1.19 2005/04/13 03:44:25 suz Exp $	*/
 
 /*
@@ -38,7 +38,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: altq_rmclass.c,v 1.26 2021/07/21 06:41:22 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: altq_rmclass.c,v 1.27 2021/07/21 06:47:33 ozaki-r Exp $");
 
 /* #ident "@(#)rm_class.c  1.48 97/12/05 SMI" */
 
@@ -194,7 +194,7 @@ static void	rmc_root_overlimit(struct rm
  * 	offtime = offtime * (8.0 / nsecPerByte);
  */
 struct rm_class *
-rmc_newclass(int pri, struct rm_ifdat *ifd, u_long psecPerByte,
+rmc_newclass(int pri, struct rm_ifdat *ifd, uint64_t psecPerByte,
 void (*action)(rm_class_t *, rm_class_t *), int maxq,
 struct rm_class *parent, struct rm_class *borrow, u_int maxidle,
 int minidle, u_int offtime, int pktsize, int flags)
@@ -253,18 +253,18 @@ rmc_newclass(int pri, struct rm_ifdat *i
 	cl->flags_ = flags;
 
 #if 1 /* minidle is also scaled in ALTQ */
-	cl->minidle_ = ((long)minidle * (long)psecPerByte) / 8;
+	cl->minidle_ = ((int64_t)minidle * (int64_t)psecPerByte) / 8;
 	if (cl->minidle_ > 0)
 		cl->minidle_ = 0;
 #else
 	cl->minidle_ = minidle;
 #endif
-	cl->maxidle_ = ((long)maxidle * (long)psecPerByte) / 8;
+	cl->maxidle_ = ((int64_t)maxidle * (int64_t)psecPerByte) / 8;
 	if (cl->maxidle_ == 0)
 		cl->maxidle_ = 1;
 #if 1 /* offtime is also scaled in ALTQ */
 	cl->avgidle_ = cl->maxidle_;
-	cl->offtime_ = (((long)offtime * (long)psecPerByte) / 8) >> RM_FILTER_GAIN;
+	cl->offtime_ = (((int64_t)offtime * (int64_t)psecPerByte) / 8) >> RM_FILTER_GAIN;
 	if (cl->offtime_ == 0)
 		cl->offtime_ = 1;
 #else
@@ -347,7 +347,7 @@ rmc_newclass(int pri, struct rm_ifdat *i
 }
 
 int
-rmc_modclass(struct rm_class *cl, u_long psecPerByte, int maxq, u_int maxidle,
+rmc_modclass(struct rm_class *cl, uint64_t psecPerByte, int maxq, u_int maxidle,
 int minidle, u_int offtime, int pktsize)
 {
 	struct rm_ifdat	*ifd;
@@ -365,18 +365,18 @@ rmc_modclass(struct rm_class *cl, u_long
 	qlimit(cl->q_) = maxq;
 
 #if 1 /* minidle is also scaled in ALTQ */
-	cl->minidle_ = ((long)minidle * (long)psecPerByte) / 8;
+	cl->minidle_ = ((int64_t)minidle * (int64_t)psecPerByte) / 8;
 	if (cl->minidle_ > 0)
 		cl->minidle_ = 0;
 #else
 	cl->minidle_ = minidle;
 #endif
-	cl->maxidle_ = ((long)maxidle * (long)psecPerByte) / 8;
+	cl->maxidle_ = ((int64_t)maxidle * (int64_t)psecPerByte) / 8;
 	if (cl->maxidle_ == 0)
 		cl->maxidle_ = 1;
 #if 1 /* offtime is also scaled in ALTQ */
 	cl->avgidle_ = cl->maxidle_;
-	cl->offtime_ = (((long)offtime * (long)psecPerByte) / 8) >> RM_FILTER_GAIN;
+	cl->offtime_ = (((int64_t)offtime * (int64_t)psecPerByte) / 8) >> RM_FILTER_GAIN;
 	if (cl->offtime_ == 0)
 		cl->offtime_ = 1;
 #else
@@ -661,7 +661,7 @@ rmc_delete_class(struct rm_ifdat *ifd, s
  */
 
 int
-rmc_init(struct ifaltq *ifq, struct rm_ifdat *ifd, u_long psecPerByte,
+rmc_init(struct ifaltq *ifq, struct rm_ifdat *ifd, uint64_t psecPerByte,
 void (*restart)(struct ifaltq *),

CVS commit: src/usr.sbin/altq/altqstat

2021-07-20 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Wed Jul 21 06:45:10 UTC 2021

Modified Files:
src/usr.sbin/altq/altqstat: qdisc_cbq.c

Log Message:
altqstat: follow changes of types of variables

PR kern/56319


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/usr.sbin/altq/altqstat/qdisc_cbq.c

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

Modified files:

Index: src/usr.sbin/altq/altqstat/qdisc_cbq.c
diff -u src/usr.sbin/altq/altqstat/qdisc_cbq.c:1.9 src/usr.sbin/altq/altqstat/qdisc_cbq.c:1.10
--- src/usr.sbin/altq/altqstat/qdisc_cbq.c:1.9	Wed Jul 21 06:42:07 2021
+++ src/usr.sbin/altq/altqstat/qdisc_cbq.c	Wed Jul 21 06:45:10 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: qdisc_cbq.c,v 1.9 2021/07/21 06:42:07 ozaki-r Exp $	*/
+/*	$NetBSD: qdisc_cbq.c,v 1.10 2021/07/21 06:45:10 ozaki-r Exp $	*/
 /*	$KAME: qdisc_cbq.c,v 1.7 2003/09/17 14:27:37 kjc Exp $	*/
 /*
  * Copyright (C) 1999-2000
@@ -105,7 +105,7 @@ cbq_stat_loop(int fd, const char *ifname
 
 			printf("\tpriority: %d depth: %d",
 			   sp->priority, sp->depth);
-			printf(" offtime: %d [us] wrr_allot: %d bytes\n",
+			printf(" offtime: %ld [ns] wrr_allot: %d bytes\n",
 			   sp->offtime, sp->wrr_allot);
 			printf("\tpsPerByte: %ld", sp->ps_per_byte);
 			printf("\t(%sbps)", rate2str(flow_bps));
@@ -139,7 +139,7 @@ cbq_stat_loop(int fd, const char *ifname
 			   sp->maxidle >> RM_FILTER_GAIN,
 			   sp->minidle / RM_POWER);
 #else
-			printf("\tAvgIdle: %d [us],\t(maxidle: %d minidle: %d [us])\n",
+			printf("\tAvgIdle: %ld [ns],\t(maxidle: %ld minidle: %ld [ns])\n",
 			   sp->avgidle, sp->maxidle, sp->minidle);
 #endif
 		}



CVS commit: src/usr.sbin/altq/altqstat

2021-07-20 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Wed Jul 21 06:42:07 UTC 2021

Modified Files:
src/usr.sbin/altq/altqstat: qdisc_cbq.c

Log Message:
altqstat: show raw values of avgidle, maxidle and minidle

The values are sometimes small and cooked values of them can be less
informative such as 0 or -1.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/usr.sbin/altq/altqstat/qdisc_cbq.c

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

Modified files:

Index: src/usr.sbin/altq/altqstat/qdisc_cbq.c
diff -u src/usr.sbin/altq/altqstat/qdisc_cbq.c:1.8 src/usr.sbin/altq/altqstat/qdisc_cbq.c:1.9
--- src/usr.sbin/altq/altqstat/qdisc_cbq.c:1.8	Wed Jul 21 06:38:57 2021
+++ src/usr.sbin/altq/altqstat/qdisc_cbq.c	Wed Jul 21 06:42:07 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: qdisc_cbq.c,v 1.8 2021/07/21 06:38:57 ozaki-r Exp $	*/
+/*	$NetBSD: qdisc_cbq.c,v 1.9 2021/07/21 06:42:07 ozaki-r Exp $	*/
 /*	$KAME: qdisc_cbq.c,v 1.7 2003/09/17 14:27:37 kjc Exp $	*/
 /*
  * Copyright (C) 1999-2000
@@ -133,10 +133,15 @@ cbq_stat_loop(int fd, const char *ifname
 
 			printf("\tQCount: %d,\t(qmax: %d)\n",
 			   sp->qcnt, sp->qmax);
+#if 0
 			printf("\tAvgIdle: %d [us],\t(maxidle: %d minidle: %d [us])\n",
 			   sp->avgidle >> RM_FILTER_GAIN,
 			   sp->maxidle >> RM_FILTER_GAIN,
 			   sp->minidle / RM_POWER);
+#else
+			printf("\tAvgIdle: %d [us],\t(maxidle: %d minidle: %d [us])\n",
+			   sp->avgidle, sp->maxidle, sp->minidle);
+#endif
 		}
 
 		/* swap the buffer pointers */



CVS commit: src/sys/altq

2021-07-20 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Wed Jul 21 06:41:22 UTC 2021

Modified Files:
src/sys/altq: altq_cbq.h altq_rmclass.c altq_rmclass.h

Log Message:
altq, cbq: treat time in nanoseconds

Time granularity in microseconds is sometimes not enough to provide
accurate bandwidth control; actual bandwidth on a capped class
can exceed its limit considerably in some cases.

Treating time in nanoseconds requires the following changes:
- Use timespec instead of timeval
- Use nanotime(9) instead of microtime(9)
- Change the type of some variables, especially *idle, to long


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/altq/altq_cbq.h
cvs rdiff -u -r1.25 -r1.26 src/sys/altq/altq_rmclass.c
cvs rdiff -u -r1.10 -r1.11 src/sys/altq/altq_rmclass.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/altq/altq_cbq.h
diff -u src/sys/altq/altq_cbq.h:1.9 src/sys/altq/altq_cbq.h:1.10
--- src/sys/altq/altq_cbq.h:1.9	Wed Jul 21 06:33:30 2021
+++ src/sys/altq/altq_cbq.h	Wed Jul 21 06:41:22 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: altq_cbq.h,v 1.9 2021/07/21 06:33:30 ozaki-r Exp $	*/
+/*	$NetBSD: altq_cbq.h,v 1.10 2021/07/21 06:41:22 ozaki-r Exp $	*/
 /*	$KAME: altq_cbq.h,v 1.12 2003/10/03 05:05:15 kjc Exp $	*/
 
 /*
@@ -81,15 +81,15 @@ typedef struct _cbq_class_stats_ {
 
 	/* other static class parameters useful for debugging */
 	int		priority;
-	int		maxidle;
-	int		minidle;
-	int		offtime;
+	long		maxidle;
+	long		minidle;
+	long		offtime;
 	int		qmax;
 	u_long		ps_per_byte;
 	int		wrr_allot;
 
 	int		qcnt;		/* # packets in queue */
-	int		avgidle;
+	long		avgidle;
 
 	/* red and rio related info */
 	int		qtype;

Index: src/sys/altq/altq_rmclass.c
diff -u src/sys/altq/altq_rmclass.c:1.25 src/sys/altq/altq_rmclass.c:1.26
--- src/sys/altq/altq_rmclass.c:1.25	Wed Jul 21 06:33:30 2021
+++ src/sys/altq/altq_rmclass.c	Wed Jul 21 06:41:22 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: altq_rmclass.c,v 1.25 2021/07/21 06:33:30 ozaki-r Exp $	*/
+/*	$NetBSD: altq_rmclass.c,v 1.26 2021/07/21 06:41:22 ozaki-r Exp $	*/
 /*	$KAME: altq_rmclass.c,v 1.19 2005/04/13 03:44:25 suz Exp $	*/
 
 /*
@@ -38,7 +38,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: altq_rmclass.c,v 1.25 2021/07/21 06:33:30 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: altq_rmclass.c,v 1.26 2021/07/21 06:41:22 ozaki-r Exp $");
 
 /* #ident "@(#)rm_class.c  1.48 97/12/05 SMI" */
 
@@ -86,7 +86,7 @@ __KERNEL_RCSID(0, "$NetBSD: altq_rmclass
  * Local routines.
  */
 
-static int	rmc_satisfied(struct rm_class *, struct timeval *);
+static int	rmc_satisfied(struct rm_class *, struct timespec *);
 static void	rmc_wrr_set_weights(struct rm_ifdat *);
 static void	rmc_depth_compute(struct rm_class *);
 static void	rmc_depth_recompute(rm_class_t *);
@@ -99,8 +99,8 @@ static void	_rmc_dropq(rm_class_t *);
 static mbuf_t	*_rmc_getq(rm_class_t *);
 static mbuf_t	*_rmc_pollq(rm_class_t *);
 
-static int	rmc_under_limit(struct rm_class *, struct timeval *);
-static void	rmc_tl_satisfied(struct rm_ifdat *, struct timeval *);
+static int	rmc_under_limit(struct rm_class *, struct timespec *);
+static void	rmc_tl_satisfied(struct rm_ifdat *, struct timespec *);
 static void	rmc_drop_action(struct rm_class *);
 static void	rmc_restart(struct rm_class *);
 static void	rmc_root_overlimit(struct rm_class *, struct rm_class *);
@@ -253,18 +253,18 @@ rmc_newclass(int pri, struct rm_ifdat *i
 	cl->flags_ = flags;
 
 #if 1 /* minidle is also scaled in ALTQ */
-	cl->minidle_ = (minidle * (int)PSEC_TO_NSEC(psecPerByte)) / 8;
+	cl->minidle_ = ((long)minidle * (long)psecPerByte) / 8;
 	if (cl->minidle_ > 0)
 		cl->minidle_ = 0;
 #else
 	cl->minidle_ = minidle;
 #endif
-	cl->maxidle_ = (maxidle * PSEC_TO_NSEC(psecPerByte)) / 8;
+	cl->maxidle_ = ((long)maxidle * (long)psecPerByte) / 8;
 	if (cl->maxidle_ == 0)
 		cl->maxidle_ = 1;
 #if 1 /* offtime is also scaled in ALTQ */
 	cl->avgidle_ = cl->maxidle_;
-	cl->offtime_ = ((offtime * PSEC_TO_NSEC(psecPerByte)) / 8) >> RM_FILTER_GAIN;
+	cl->offtime_ = (((long)offtime * (long)psecPerByte) / 8) >> RM_FILTER_GAIN;
 	if (cl->offtime_ == 0)
 		cl->offtime_ = 1;
 #else
@@ -365,18 +365,18 @@ rmc_modclass(struct rm_class *cl, u_long
 	qlimit(cl->q_) = maxq;
 
 #if 1 /* minidle is also scaled in ALTQ */
-	cl->minidle_ = (minidle * PSEC_TO_NSEC(psecPerByte)) / 8;
+	cl->minidle_ = ((long)minidle * (long)psecPerByte) / 8;
 	if (cl->minidle_ > 0)
 		cl->minidle_ = 0;
 #else
 	cl->minidle_ = minidle;
 #endif
-	cl->maxidle_ = (maxidle * PSEC_TO_NSEC(psecPerByte)) / 8;
+	cl->maxidle_ = ((long)maxidle * (long)psecPerByte) / 8;
 	if (cl->maxidle_ == 0)
 		cl->maxidle_ = 1;
 #if 1 /* offtime is also scaled in ALTQ */
 	cl->avgidle_ = cl->maxidle_;
-	cl->offtime_ = ((offtime * PSEC_TO_NSEC(psecPerByte)) / 8) >> RM_FILTER_GAIN;
+	cl->offtime_ = (((long)offtime * (long)psecPerByte) / 8) >> RM_FILTER_GAIN;
 	if (cl->offtime_ == 0)
 		cl->offti

CVS commit: src/usr.sbin/altq/altqstat

2021-07-20 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Wed Jul 21 06:38:57 UTC 2021

Modified Files:
src/usr.sbin/altq/altqstat: qdisc_cbq.c

Log Message:
altqstat: adopt ps_per_byte

PR kern/56319


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/usr.sbin/altq/altqstat/qdisc_cbq.c

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

Modified files:

Index: src/usr.sbin/altq/altqstat/qdisc_cbq.c
diff -u src/usr.sbin/altq/altqstat/qdisc_cbq.c:1.7 src/usr.sbin/altq/altqstat/qdisc_cbq.c:1.8
--- src/usr.sbin/altq/altqstat/qdisc_cbq.c:1.7	Sat Oct 28 11:43:02 2006
+++ src/usr.sbin/altq/altqstat/qdisc_cbq.c	Wed Jul 21 06:38:57 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: qdisc_cbq.c,v 1.7 2006/10/28 11:43:02 peter Exp $	*/
+/*	$NetBSD: qdisc_cbq.c,v 1.8 2021/07/21 06:38:57 ozaki-r Exp $	*/
 /*	$KAME: qdisc_cbq.c,v 1.7 2003/09/17 14:27:37 kjc Exp $	*/
 /*
  * Copyright (C) 1999-2000
@@ -100,14 +100,14 @@ cbq_stat_loop(int fd, const char *ifname
 			printf("Class %d on Interface %s: %s\n",
 			sp->handle, ifname, clnames[i]);
 
-			flow_bps = 8.0 / (double)sp->ns_per_byte
-			* 1000*1000*1000;
+			flow_bps = 8.0 / (double)sp->ps_per_byte
+			* 1000*1000*1000*1000;
 
 			printf("\tpriority: %d depth: %d",
 			   sp->priority, sp->depth);
 			printf(" offtime: %d [us] wrr_allot: %d bytes\n",
 			   sp->offtime, sp->wrr_allot);
-			printf("\tnsPerByte: %d", sp->ns_per_byte);
+			printf("\tpsPerByte: %ld", sp->ps_per_byte);
 			printf("\t(%sbps)", rate2str(flow_bps));
 			if (lp->handle != NULL_CLASS_HANDLE) {
 printf(",\tMeasured: %s [bps]\n",



CVS commit: src/usr.sbin/altq/libaltq

2021-07-20 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Wed Jul 21 06:36:33 UTC 2021

Modified Files:
src/usr.sbin/altq/libaltq: qop_cbq.c qop_cbq.h

Log Message:
libaltq, cbq: convert ns_per_byte to ps_per_byte

PR kern/56319


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/usr.sbin/altq/libaltq/qop_cbq.c
cvs rdiff -u -r1.3 -r1.4 src/usr.sbin/altq/libaltq/qop_cbq.h

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

Modified files:

Index: src/usr.sbin/altq/libaltq/qop_cbq.c
diff -u src/usr.sbin/altq/libaltq/qop_cbq.c:1.11 src/usr.sbin/altq/libaltq/qop_cbq.c:1.12
--- src/usr.sbin/altq/libaltq/qop_cbq.c:1.11	Wed Jul 14 08:32:13 2021
+++ src/usr.sbin/altq/libaltq/qop_cbq.c	Wed Jul 21 06:36:33 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: qop_cbq.c,v 1.11 2021/07/14 08:32:13 ozaki-r Exp $	*/
+/*	$NetBSD: qop_cbq.c,v 1.12 2021/07/21 06:36:33 ozaki-r Exp $	*/
 /*	$KAME: qop_cbq.c,v 1.7 2002/05/31 06:03:35 kjc Exp $	*/
 /*
  * Copyright (c) Sun Microsystems, Inc. 1993-1998 All rights reserved.
@@ -78,8 +78,12 @@ static int cbq_delete_filter(struct fltr
 #define CTL_PBANDWIDTH	2
 #define NS_PER_MS	(100.0)
 #define NS_PER_SEC	(NS_PER_MS*1000.0)
+#define PS_PER_MS	(10.0)
+#define PS_PER_SEC	(PS_PER_MS*1000.0)
 #define RM_FILTER_GAIN	5
 
+#define PSEC_TO_USEC(ps)	((ps) / 1000.0 / 1000.0)
+
 #define CBQ_DEVICE	"/dev/altq/cbq"
 
 static int cbq_fd = -1;
@@ -484,8 +488,8 @@ qop_cbq_add_if(struct ifinfo **rp, const
 	if ((cbq_ifinfo = calloc(1, sizeof(*cbq_ifinfo))) == NULL)
 		return (QOPERR_NOMEM);
 
-	cbq_ifinfo->nsPerByte =
-		(1.0 / (double)bandwidth) * NS_PER_SEC * 8;
+	cbq_ifinfo->psPerByte =
+		(1.0 / (double)bandwidth) * PS_PER_SEC * 8;
 	cbq_ifinfo->is_wrr = is_wrr;
 	cbq_ifinfo->is_efficient = efficient;
 	cbq_ifinfo->no_control = no_control;
@@ -768,7 +772,7 @@ cbq_class_spec(struct ifinfo *ifinfo, u_
 {
 	struct cbq_ifinfo *cbq_ifinfo = ifinfo->private;
 	double  maxq, maxidle_s, maxidle, minidle,
-			lofftime, nsPerByte, ptime, cptime;
+			lofftime, psPerByte, ptime, cptime;
 	double		z = (double)(1 << RM_FILTER_GAIN);
 	double  g = (1.0 - 1.0 / z);
 	double  f;
@@ -792,22 +796,12 @@ cbq_class_spec(struct ifinfo *ifinfo, u_
 	else if (max_pkt_size > ifinfo->ifmtu)
 		max_pkt_size = ifinfo->ifmtu;
 
-nsPerByte = cbq_ifinfo->nsPerByte / f;
-	ptime = (double) av_pkt_size * (double)cbq_ifinfo->nsPerByte;
+psPerByte = cbq_ifinfo->psPerByte / f;
+	ptime = (double) av_pkt_size * (double)cbq_ifinfo->psPerByte;
 	cptime = ptime * (1.0 - f) / f;
-#if 1 /* ALTQ */
-	if (nsPerByte * (double)max_pkt_size > (double)INT_MAX) {
-		/*
-		 * this causes integer overflow in kernel!
-		 * (bandwidth < 6Kbps when max_pkt_size=1500)
-		 */
-		if (bandwidth != 0)
-			LOG(LOG_WARNING, 0, "warning: class is too slow!!");
-		nsPerByte = (double)(INT_MAX / max_pkt_size);
-	}
-#endif
+
 	if (maxburst == 0) {  /* use default */
-		if (cptime > 10.0 * NS_PER_MS)
+		if (cptime > 10.0 * PS_PER_MS)
 			maxburst = 4;
 		else
 			maxburst = 16;
@@ -823,9 +817,9 @@ cbq_class_spec(struct ifinfo *ifinfo, u_
 		"cbq_flowspec: maxburst=%d,minburst=%d,pkt_size=%d",
 		maxburst, minburst, av_pkt_size);
 		LOG(LOG_DEBUG, 0,
-		"  nsPerByte=%.2f ns, link's nsPerByte=%.2f, f=%.3f",
-		nsPerByte, cbq_ifinfo->nsPerByte, f);
-		packet_time = av_pkt_size * (int)nsPerByte / 1000;
+		"  psPerByte=%.2f ps, link's psPerByte=%.2f, f=%.3f",
+		psPerByte, cbq_ifinfo->psPerByte, f);
+		packet_time = av_pkt_size * (int)PSEC_TO_USEC(psPerByte);
 		LOG(LOG_DEBUG, 0,
 		"  packet time=%d [us]\n", packet_time);
 		if (maxburst * packet_time < 2) {
@@ -845,21 +839,21 @@ cbq_class_spec(struct ifinfo *ifinfo, u_
 	else
 		maxidle = ptime * maxidle_s;
 	if (IsDebug(DEBUG_ALTQ))
-		LOG(LOG_DEBUG, 0, "  maxidle=%.2f us", maxidle/1000.0);
+		LOG(LOG_DEBUG, 0, "  maxidle=%.2f us", PSEC_TO_USEC(maxidle));
 	if (minburst)
 		lofftime = cptime * (1.0 + 1.0/(1.0 - g) * (1.0 - gtom) / gtom);
 	else
 		lofftime = cptime;
-	minidle = -((double)max_pkt_size * (double)nsPerByte);
+	minidle = -((double)max_pkt_size * (double)psPerByte);
 	if (IsDebug(DEBUG_ALTQ))
 		LOG(LOG_DEBUG, 0, "  lofftime=%.2f us minidle=%.2f us",
-		lofftime/1000.0, minidle/1000.0);
+		PSEC_TO_USEC(lofftime), PSEC_TO_USEC(minidle));
 
-	maxidle = ((maxidle * 8.0) / nsPerByte) * pow(2, RM_FILTER_GAIN);
+	maxidle = ((maxidle * 8.0) / psPerByte) * pow(2, RM_FILTER_GAIN);
 #if 1 /* ALTQ */
 	/* also scale lofftime and minidle */
- 	lofftime = (lofftime * 8.0) / nsPerByte * pow(2, RM_FILTER_GAIN);
-	minidle = ((minidle * 8.0) / nsPerByte) * pow(2, RM_FILTER_GAIN);
+	lofftime = (lofftime * 8.0) / psPerByte * pow(2, RM_FILTER_GAIN);
+	minidle = ((minidle * 8.0) / psPerByte) * pow(2, RM_FILTER_GAIN);
 #endif
 	maxidle = maxidle / 1000.0;
 	lofftime = lofftime / 1000.0;
@@ -872,7 +866,7 @@ cbq_class_spec(struct ifinfo *ifinfo, u_
 		else
 			maxq = 

CVS commit: src/sys/altq

2021-07-20 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Wed Jul 21 06:33:30 UTC 2021

Modified Files:
src/sys/altq: altq_cbq.c altq_cbq.h altq_rmclass.c altq_rmclass.h

Log Message:
altq, cbq: convert ns_per_byte to ps_per_byte

Also the type of variables of it is changed to u_long from int.

This change provides fine-grain resolution of bandwidth.  For example
750 Mbps was treated as 800 Mbps internally because bandwidth was
represented as nanoseconds per byte.  Converting the representation
to picoseconds per byte enables to treat 750 Mbps as-is.

PR kern/56319


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sys/altq/altq_cbq.c
cvs rdiff -u -r1.8 -r1.9 src/sys/altq/altq_cbq.h
cvs rdiff -u -r1.24 -r1.25 src/sys/altq/altq_rmclass.c
cvs rdiff -u -r1.9 -r1.10 src/sys/altq/altq_rmclass.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/altq/altq_cbq.c
diff -u src/sys/altq/altq_cbq.c:1.34 src/sys/altq/altq_cbq.c:1.35
--- src/sys/altq/altq_cbq.c:1.34	Wed Jul 14 08:31:15 2021
+++ src/sys/altq/altq_cbq.c	Wed Jul 21 06:33:30 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: altq_cbq.c,v 1.34 2021/07/14 08:31:15 ozaki-r Exp $	*/
+/*	$NetBSD: altq_cbq.c,v 1.35 2021/07/21 06:33:30 ozaki-r Exp $	*/
 /*	$KAME: altq_cbq.c,v 1.21 2005/04/13 03:44:24 suz Exp $	*/
 
 /*
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: altq_cbq.c,v 1.34 2021/07/14 08:31:15 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: altq_cbq.c,v 1.35 2021/07/21 06:33:30 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_altq.h"
@@ -226,7 +226,7 @@ get_class_stats(class_stats_t *statsp, s
 	statsp->minidle		= cl->minidle_;
 	statsp->offtime		= cl->offtime_;
 	statsp->qmax		= qlimit(cl->q_);
-	statsp->ns_per_byte	= cl->ns_per_byte_;
+	statsp->ps_per_byte	= cl->ps_per_byte_;
 	statsp->wrr_allot	= cl->w_allotment_;
 	statsp->qcnt		= qlen(cl->q_);
 	statsp->avgidle		= cl->avgidle_;
@@ -384,7 +384,7 @@ cbq_add_queue(struct pf_altq *a)
 	 */
 	if ((opts->flags & CBQCLF_ROOTCLASS) != 0) {
 		error = rmc_init(cbqp->ifnp.ifq_, &cbqp->ifnp,
-		opts->ns_per_byte, cbqrestart, a->qlimit, RM_MAXQUEUED,
+		opts->ps_per_byte, cbqrestart, a->qlimit, RM_MAXQUEUED,
 		opts->maxidle, opts->minidle, opts->offtime,
 		opts->flags);
 		if (error != 0)
@@ -392,7 +392,7 @@ cbq_add_queue(struct pf_altq *a)
 		cl = cbqp->ifnp.root_;
 	} else {
 		cl = rmc_newclass(a->priority,
-  &cbqp->ifnp, opts->ns_per_byte,
+  &cbqp->ifnp, opts->ps_per_byte,
   rmc_delay_action, a->qlimit, parent, borrow,
   opts->maxidle, opts->minidle, opts->offtime,
   opts->pktsize, opts->flags);
@@ -681,7 +681,7 @@ cbq_modify_class(struct cbq_modify_class
 	if ((cl = clh_to_clp(cbqp, acp->cbq_class_handle)) == NULL)
 		return (EINVAL);
 
-	if (rmc_modclass(cl, acp->cbq_class.nano_sec_per_byte,
+	if (rmc_modclass(cl, acp->cbq_class.pico_sec_per_byte,
 			 acp->cbq_class.maxq, acp->cbq_class.maxidle,
 			 acp->cbq_class.minidle, acp->cbq_class.offtime,
 			 acp->cbq_class.pktsize) < 0)
@@ -724,7 +724,7 @@ cbq_class_create(cbq_state_t *cbqp, stru
 	 */
 	if ((spec->flags & CBQCLF_ROOTCLASS) != 0) {
 		error = rmc_init(cbqp->ifnp.ifq_, &cbqp->ifnp,
-		spec->nano_sec_per_byte, cbqrestart, spec->maxq,
+		spec->pico_sec_per_byte, cbqrestart, spec->maxq,
 		RM_MAXQUEUED, spec->maxidle, spec->minidle, spec->offtime,
 		spec->flags);
 		if (error)
@@ -732,7 +732,7 @@ cbq_class_create(cbq_state_t *cbqp, stru
 		cl = cbqp->ifnp.root_;
 	} else {
 		cl = rmc_newclass(spec->priority,
-  &cbqp->ifnp, spec->nano_sec_per_byte,
+  &cbqp->ifnp, spec->pico_sec_per_byte,
   rmc_delay_action, spec->maxq, parent, borrow,
   spec->maxidle, spec->minidle, spec->offtime,
   spec->pktsize, spec->flags);

Index: src/sys/altq/altq_cbq.h
diff -u src/sys/altq/altq_cbq.h:1.8 src/sys/altq/altq_cbq.h:1.9
--- src/sys/altq/altq_cbq.h:1.8	Thu Oct 12 19:59:08 2006
+++ src/sys/altq/altq_cbq.h	Wed Jul 21 06:33:30 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: altq_cbq.h,v 1.8 2006/10/12 19:59:08 peter Exp $	*/
+/*	$NetBSD: altq_cbq.h,v 1.9 2021/07/21 06:33:30 ozaki-r Exp $	*/
 /*	$KAME: altq_cbq.h,v 1.12 2003/10/03 05:05:15 kjc Exp $	*/
 
 /*
@@ -85,7 +85,7 @@ typedef struct _cbq_class_stats_ {
 	int		minidle;
 	int		offtime;
 	int		qmax;
-	int		ns_per_byte;
+	u_long		ps_per_byte;
 	int		wrr_allot;
 
 	int		qcnt;		/* # packets in queue */
@@ -112,7 +112,7 @@ struct cbq_interface {
 
 typedef struct cbq_class_spec {
 	u_int		priority;
-	u_int		nano_sec_per_byte;
+	u_long		pico_sec_per_byte;
 	u_int		maxq;
 	u_int		maxidle;
 	int		minidle;

Index: src/sys/altq/altq_rmclass.c
diff -u src/sys/altq/altq_rmclass.c:1.24 src/sys/altq/altq_rmclass.c:1.25
--- src/sys/altq/altq_rmclass.c:1.24	Tue Jul 13 08:23:39 2021
+++ src/sys/altq/altq_rmclass.c	Wed Jul 21 06:33:30 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: altq_rmclass.c,v 1.24 2021/07/13 08:23:39 ozaki-r Exp $	*/
+/*	$NetBSD

CVS commit: src/tests/net/altq

2021-07-15 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Fri Jul 16 02:33:32 UTC 2021

Modified Files:
src/tests/net/altq: t_cbq.sh

Log Message:
tests, altq: fix checks of altqd startup

Hopefully the fix stabilizes test results on qemu/anita.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/net/altq/t_cbq.sh

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

Modified files:

Index: src/tests/net/altq/t_cbq.sh
diff -u src/tests/net/altq/t_cbq.sh:1.2 src/tests/net/altq/t_cbq.sh:1.3
--- src/tests/net/altq/t_cbq.sh:1.2	Wed Jul 14 08:33:47 2021
+++ src/tests/net/altq/t_cbq.sh	Fri Jul 16 02:33:32 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: t_cbq.sh,v 1.2 2021/07/14 08:33:47 ozaki-r Exp $
+#	$NetBSD: t_cbq.sh,v 1.3 2021/07/16 02:33:32 ozaki-r Exp $
 #
 # Copyright (c) 2021 Internet Initiative Japan Inc.
 # All rights reserved.
@@ -45,6 +45,23 @@ IP_REMOTE21=10.0.1.2
 IP_REMOTE22=10.0.1.22
 ALTQD_PIDFILE=./pid
 
+start_altqd()
+{
+
+	$HIJACKING_ALTQ altqd
+
+	sleep 0.1
+	if $HIJACKING_ALTQ test ! -f /var/run/altqd.pid; then
+		sleep 1
+	fi
+
+	$HIJACKING_ALTQ test -f /var/run/altqd.pid
+	if [ $? != 0 ]; then
+		atf_fail "starting altqd failed"
+	fi
+
+	$HIJACKING_ALTQ cat /var/run/altqd.pid > $ALTQD_PIDFILE
+}
 
 start_altqd_basic()
 {
@@ -64,18 +81,9 @@ start_altqd_basic()
 	EOF
 	$DEBUG && cat ./altq.conf
 	atf_check -s exit:0 $HIJACKING_ALTQ cp ./altq.conf /rump/etc/altq.conf
-	$HIJACKING_ALTQ test -f /rump/etc/altq.conf
-
-	#atf_check -s exit:0 $HIJACKING_ALTQ altqd
-	$HIJACKING_ALTQ altqd
-
-	$HIJACKING_ALTQ test -f /var/run/altqd.pid
-	if [ $? != 0 ]; then
-		atf_check -s exit:0 $HIJACKING_ALTQ altqd -d
-		# Should abort
-	fi
+	atf_check -s exit:0 $HIJACKING_ALTQ test -f /rump/etc/altq.conf
 
-	$HIJACKING_ALTQ cat /var/run/altqd.pid > $ALTQD_PIDFILE
+	start_altqd
 
 	$DEBUG && $HIJACKING_ALTQ altqstat -s
 	$HIJACKING_ALTQ altqstat -c 1 >./out
@@ -196,16 +204,7 @@ start_altqd_multi_ifaces()
 	atf_check -s exit:0 $HIJACKING_ALTQ cp ./altq.conf /rump/etc/altq.conf
 	$HIJACKING_ALTQ test -f /rump/etc/altq.conf
 
-	#atf_check -s exit:0 $HIJACKING_ALTQ altqd
-	$HIJACKING_ALTQ altqd
-
-	$HIJACKING_ALTQ test -f /var/run/altqd.pid
-	if [ $? != 0 ]; then
-		atf_check -s exit:0 $HIJACKING_ALTQ altqd -d
-		# Should abort
-	fi
-
-	$HIJACKING_ALTQ cat /var/run/altqd.pid > $ALTQD_PIDFILE
+	start_altqd
 
 	$DEBUG && $HIJACKING_ALTQ altqstat -s
 
@@ -335,15 +334,7 @@ start_altqd_options()
 	atf_check -s exit:0 $HIJACKING_ALTQ cp ./altq.conf /rump/etc/altq.conf
 	$HIJACKING_ALTQ test -f /rump/etc/altq.conf
 
-	$HIJACKING_ALTQ altqd
-
-	$HIJACKING_ALTQ test -f /var/run/altqd.pid
-	if [ $? != 0 ]; then
-		atf_check -s exit:0 $HIJACKING_ALTQ altqd -d
-		# Should abort
-	fi
-
-	$HIJACKING_ALTQ cat /var/run/altqd.pid > $ALTQD_PIDFILE
+	start_altqd
 
 	$DEBUG && $HIJACKING_ALTQ altqstat -s
 	$HIJACKING_ALTQ altqstat -c 1 >./out



CVS commit: src/tests/net/altq

2021-07-14 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Wed Jul 14 08:33:47 UTC 2021

Modified Files:
src/tests/net/altq: t_cbq.sh

Log Message:
tests, altq: test new options


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/net/altq/t_cbq.sh

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

Modified files:

Index: src/tests/net/altq/t_cbq.sh
diff -u src/tests/net/altq/t_cbq.sh:1.1 src/tests/net/altq/t_cbq.sh:1.2
--- src/tests/net/altq/t_cbq.sh:1.1	Wed Jul 14 03:22:33 2021
+++ src/tests/net/altq/t_cbq.sh	Wed Jul 14 08:33:47 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: t_cbq.sh,v 1.1 2021/07/14 03:22:33 ozaki-r Exp $
+#	$NetBSD: t_cbq.sh,v 1.2 2021/07/14 08:33:47 ozaki-r Exp $
 #
 # Copyright (c) 2021 Internet Initiative Japan Inc.
 # All rights reserved.
@@ -40,6 +40,7 @@ IP_LOCAL1=10.0.0.1
 IP_LOCAL2=10.0.1.1
 IP_REMOTE11=10.0.0.2
 IP_REMOTE12=10.0.0.22
+IP_REMOTE13=10.0.0.23
 IP_REMOTE21=10.0.1.2
 IP_REMOTE22=10.0.1.22
 ALTQD_PIDFILE=./pid
@@ -312,6 +313,118 @@ test_altq_cbq_multi_ifaces_ipv4()
 	rump_server_destroy_ifaces
 }
 
+start_altqd_options()
+{
+
+	export RUMP_SERVER=$SOCK_LOCAL
+
+	$HIJACKING_ALTQ mkdir -p /rump/etc
+	$HIJACKING_ALTQ mkdir -p /rump/var/run
+
+	# - no-tbr and no-control are specified
+	# - root_class is the default class
+	cat > ./altq.conf <<-EOF
+	interface shmif0 cbq no-tbr no-control
+	class cbq shmif0 root_class NULL pbandwidth 100 default
+	class cbq shmif0 normal_class root_class pbandwidth 50
+	filter shmif0 normal_class $IP_REMOTE11 0 0 0 0
+	class cbq shmif0 drop_class root_class pbandwidth 0
+	filter shmif0 drop_class $IP_REMOTE12 0 0 0 0
+	EOF
+	$DEBUG && cat ./altq.conf
+	atf_check -s exit:0 $HIJACKING_ALTQ cp ./altq.conf /rump/etc/altq.conf
+	$HIJACKING_ALTQ test -f /rump/etc/altq.conf
+
+	$HIJACKING_ALTQ altqd
+
+	$HIJACKING_ALTQ test -f /var/run/altqd.pid
+	if [ $? != 0 ]; then
+		atf_check -s exit:0 $HIJACKING_ALTQ altqd -d
+		# Should abort
+	fi
+
+	$HIJACKING_ALTQ cat /var/run/altqd.pid > $ALTQD_PIDFILE
+
+	$DEBUG && $HIJACKING_ALTQ altqstat -s
+	$HIJACKING_ALTQ altqstat -c 1 >./out
+	$DEBUG && cat ./out
+	atf_check -s exit:0 \
+	-o match:"altqstat: cbq on interface shmif0" \
+	-o match:'Class 1 on Interface shmif0: root_class' \
+	-o match:'Class 2 on Interface shmif0: normal_class' \
+	-o match:'Class 3 on Interface shmif0: drop_class' \
+	cat ./out
+	atf_check -s exit:0 -o not-match:'shmif0: ctl_class' cat ./out
+
+	rm -f ./out
+}
+
+test_altq_cbq_options_ipv4()
+{
+	local ifconfig="atf_check -s exit:0 rump.ifconfig"
+	local ping="atf_check -s exit:0 -o ignore rump.ping"
+	local opts="-q -c 1 -w 1"
+
+	rump_server_fs_start $SOCK_LOCAL local altq
+	rump_server_start $SOCK_REMOTE
+
+	rump_server_add_iface $SOCK_LOCAL shmif0 $BUS
+	rump_server_add_iface $SOCK_REMOTE shmif0 $BUS
+
+	export RUMP_SERVER=$SOCK_LOCAL
+	$ifconfig shmif0 inet $IP_LOCAL1/24
+	export RUMP_SERVER=$SOCK_REMOTE
+	$ifconfig shmif0 inet $IP_REMOTE11/24
+	$ifconfig shmif0 inet $IP_REMOTE12/24 alias
+	$ifconfig shmif0 inet $IP_REMOTE13/24 alias
+	$ifconfig -w 10
+
+	export RUMP_SERVER=$SOCK_LOCAL
+	# Invoke ARP
+	$ping $opts $IP_REMOTE11
+	$ping $opts $IP_REMOTE12
+	$ping $opts $IP_REMOTE13
+
+	start_altqd_options
+
+	export RUMP_SERVER=$SOCK_LOCAL
+	$ping $opts $IP_REMOTE11
+
+	$HIJACKING_ALTQ altqstat -c 1 >./out
+	$DEBUG && cat ./out
+
+	check_counter ./out normal 'pkts: 1'
+	check_counter ./out root   'pkts: 1'
+	check_counter ./out drop   'pkts: 0'
+
+	atf_check -s not-exit:0 -o ignore -e match:"No buffer space available" \
+	rump.ping $opts $IP_REMOTE12
+
+	$HIJACKING_ALTQ altqstat -c 1 >./out
+	$DEBUG && cat ./out
+
+	check_counter ./out drop   'drops: 1'
+	check_counter ./out drop   'pkts: 0'
+	check_counter ./out normal 'pkts: 1'
+	check_counter ./out root   'pkts: 1'
+
+	# The packet goes to the default class
+	$ping $opts $IP_REMOTE13
+
+	$HIJACKING_ALTQ altqstat -c 1 >./out
+	$DEBUG && cat ./out
+
+	check_counter ./out drop   'pkts: 0'
+	check_counter ./out normal 'pkts: 1'
+	check_counter ./out root   'pkts: 2'
+
+	rm -f ./out
+
+	shutdown_altqd
+
+	rump_server_destroy_ifaces
+}
+
 add_test_case()
 {
 	local algo=$1
@@ -344,4 +457,5 @@ atf_init_test_cases()
 
 	add_test_case cbq basicipv4
 	add_test_case cbq multi_ifaces ipv4
+	add_test_case cbq options  ipv4
 }



CVS commit: src/usr.sbin/altq/libaltq

2021-07-14 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Wed Jul 14 08:33:05 UTC 2021

Modified Files:
src/usr.sbin/altq/libaltq: parser.c

Log Message:
libaltq: allow longer config lines


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/usr.sbin/altq/libaltq/parser.c

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

Modified files:

Index: src/usr.sbin/altq/libaltq/parser.c
diff -u src/usr.sbin/altq/libaltq/parser.c:1.11 src/usr.sbin/altq/libaltq/parser.c:1.12
--- src/usr.sbin/altq/libaltq/parser.c:1.11	Tue Aug 16 12:49:13 2011
+++ src/usr.sbin/altq/libaltq/parser.c	Wed Jul 14 08:33:05 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: parser.c,v 1.11 2011/08/16 12:49:13 christos Exp $	*/
+/*	$NetBSD: parser.c,v 1.12 2021/07/14 08:33:05 ozaki-r Exp $	*/
 /*	$KAME: parser.c,v 1.16 2002/02/20 10:40:39 kjc Exp $	*/
 /*
  * Copyright (C) 1999-2002
@@ -76,7 +76,7 @@ static int conditioner_parser(char *);
 static int tc_action_parser(char *, char **, struct tc_action *);
 
 #define MAX_LINE	1024
-#define MAX_WORD	64
+#define MAX_WORD	128
 #define MAX_ARGS	64
 #define MAX_ACTIONS	16
 



CVS commit: src/usr.sbin/altq

2021-07-14 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Wed Jul 14 08:32:13 UTC 2021

Modified Files:
src/usr.sbin/altq/altqd: altq.conf.5
src/usr.sbin/altq/libaltq: qop_cbq.c qop_cbq.h

Log Message:
libaltq, cbq: add two options to interface

- no-control: don't create a control class automatically
- no-tbr: don't install TBR


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/usr.sbin/altq/altqd/altq.conf.5
cvs rdiff -u -r1.10 -r1.11 src/usr.sbin/altq/libaltq/qop_cbq.c
cvs rdiff -u -r1.2 -r1.3 src/usr.sbin/altq/libaltq/qop_cbq.h

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

Modified files:

Index: src/usr.sbin/altq/altqd/altq.conf.5
diff -u src/usr.sbin/altq/altqd/altq.conf.5:1.18 src/usr.sbin/altq/altqd/altq.conf.5:1.19
--- src/usr.sbin/altq/altqd/altq.conf.5:1.18	Tue Apr  9 19:10:21 2019
+++ src/usr.sbin/altq/altqd/altq.conf.5	Wed Jul 14 08:32:13 2021
@@ -1,4 +1,4 @@
-.\"	$NetBSD: altq.conf.5,v 1.18 2019/04/09 19:10:21 sevan Exp $
+.\"	$NetBSD: altq.conf.5,v 1.19 2021/07/14 08:32:13 ozaki-r Exp $
 .\"	$KAME: altq.conf.5,v 1.15 2002/11/17 02:51:49 kjc Exp $
 .\"
 .\" Copyright (C) 2000
@@ -25,7 +25,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd April 9, 2019
+.Dd July 14, 2021
 .Dt ALTQ.CONF 5
 .Os
 .\"
@@ -281,6 +281,8 @@ excess bandwidth is available.
 .Op Cm tbrsize Ar bytes
 .Op Ar sched_type
 .Op Cm efficient
+.Op Cm no-control
+.Op Cm no-tbr
 .El
 .Bl -tag -width 8n -offset indent
 .It Ar if_name
@@ -310,6 +312,13 @@ By default, this mode is turned off.
 By adding the keyword
 .Cm efficient
 to the interface specification line, enables this mode.
+.It Cm no-control
+By default, the control class is automatically created when default class is
+created and one doesn't exist yet.
+This option suppresses the behavior on the interface.
+.It Cm no-tbr
+By default, a token bucket regulator is automatically created on each interface.
+This option suppresses the behavior on the interface.
 .El
 .Bl -tag -width class -offset indent
 .It Cm class

Index: src/usr.sbin/altq/libaltq/qop_cbq.c
diff -u src/usr.sbin/altq/libaltq/qop_cbq.c:1.10 src/usr.sbin/altq/libaltq/qop_cbq.c:1.11
--- src/usr.sbin/altq/libaltq/qop_cbq.c:1.10	Sat Oct 19 17:16:37 2013
+++ src/usr.sbin/altq/libaltq/qop_cbq.c	Wed Jul 14 08:32:13 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: qop_cbq.c,v 1.10 2013/10/19 17:16:37 christos Exp $	*/
+/*	$NetBSD: qop_cbq.c,v 1.11 2021/07/14 08:32:13 ozaki-r Exp $	*/
 /*	$KAME: qop_cbq.c,v 1.7 2002/05/31 06:03:35 kjc Exp $	*/
 /*
  * Copyright (c) Sun Microsystems, Inc. 1993-1998 All rights reserved.
@@ -112,6 +112,8 @@ cbq_interface_parser(const char *ifname,
 	u_int	tbrsize = 0;
 	u_int	is_efficient = 0;
 	u_int	is_wrr = 1;	/* weighted round-robin is default */
+	bool	no_control = false;
+	bool	no_tbr = false;
 
 	/*
 	 * process options
@@ -133,6 +135,10 @@ cbq_interface_parser(const char *ifname,
 			is_wrr = 1;
 		} else if (EQUAL(*argv, "cbq-prr")) {
 			is_wrr = 0;
+		} else if (EQUAL(*argv, "no-tbr")) {
+			no_tbr = true;
+		} else if (EQUAL(*argv, "no-control")) {
+			no_control = true;
 		} else {
 			LOG(LOG_ERR, 0, "Unknown keyword '%s'", *argv);
 			return (0);
@@ -140,12 +146,15 @@ cbq_interface_parser(const char *ifname,
 		argc--; argv++;
 	}
 
-	if (qcmd_tbr_register(ifname, bandwidth, tbrsize) != 0)
-		return (0);
+	if (!no_tbr) {
+		if (qcmd_tbr_register(ifname, bandwidth, tbrsize) != 0)
+			return (0);
+	}
 
 	if (qcmd_cbq_add_if(ifname, bandwidth,
-			is_wrr, is_efficient) != 0)
+			is_wrr, is_efficient, no_control) != 0)
 		return (0);
+
 	return (1);
 }
 
@@ -296,11 +305,13 @@ cbq_class_parser(const char *ifname, con
  * qcmd api
  */
 int
-qcmd_cbq_add_if(const char *ifname, u_int bandwidth, int is_wrr, int efficient)
+qcmd_cbq_add_if(const char *ifname, u_int bandwidth, int is_wrr, int efficient,
+bool no_control)
 {
 	int error;
 	
-	error = qop_cbq_add_if(NULL, ifname, bandwidth, is_wrr, efficient);
+	error = qop_cbq_add_if(NULL, ifname, bandwidth, is_wrr, efficient,
+	no_control);
 	if (error != 0)
 		LOG(LOG_ERR, errno, "%s: can't add cbq on interface '%s'",
 		qoperror(error), ifname);
@@ -333,7 +344,7 @@ qcmd_cbq_add_class(const char *ifname, c
 	(borrow = clname2clinfo(ifinfo, borrow_name)) == NULL)
 		error = QOPERR_BADCLASS;
 
-	if (flags & CBQCLF_DEFCLASS) {
+	if (flags & CBQCLF_DEFCLASS && !cbq_ifinfo->no_control) {
 		/*
 		 * if this is a default class and no ctl_class is defined,
 		 * we will create a ctl_class.
@@ -464,7 +475,7 @@ qcmd_cbq_add_ctl_filters(const char *ifn
  */
 int 
 qop_cbq_add_if(struct ifinfo **rp, const char *ifname,
-	   u_int bandwidth, int is_wrr, int efficient)
+	   u_int bandwidth, int is_wrr, int efficient, bool no_control)
 {
 	struct ifinfo *ifinfo = NULL;
 	struct cbq_ifinfo *cbq_ifinfo = NULL;
@@ -477,6 +488,7 @@ qop_cbq_add_if(struct ifinfo **rp, const

CVS commit: src/sys/altq

2021-07-14 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Wed Jul 14 08:31:15 UTC 2021

Modified Files:
src/sys/altq: altq_cbq.c

Log Message:
altq, cbq: allow the root class to be default


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/sys/altq/altq_cbq.c

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

Modified files:

Index: src/sys/altq/altq_cbq.c
diff -u src/sys/altq/altq_cbq.c:1.33 src/sys/altq/altq_cbq.c:1.34
--- src/sys/altq/altq_cbq.c:1.33	Wed Jul 14 08:27:59 2021
+++ src/sys/altq/altq_cbq.c	Wed Jul 14 08:31:15 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: altq_cbq.c,v 1.33 2021/07/14 08:27:59 ozaki-r Exp $	*/
+/*	$NetBSD: altq_cbq.c,v 1.34 2021/07/14 08:31:15 ozaki-r Exp $	*/
 /*	$KAME: altq_cbq.c,v 1.21 2005/04/13 03:44:24 suz Exp $	*/
 
 /*
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: altq_cbq.c,v 1.33 2021/07/14 08:27:59 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: altq_cbq.c,v 1.34 2021/07/14 08:31:15 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_altq.h"
@@ -363,31 +363,26 @@ cbq_add_queue(struct pf_altq *a)
 	/*
 	 * check parameters
 	 */
-	switch (opts->flags & CBQCLF_CLASSMASK) {
-	case CBQCLF_ROOTCLASS:
+	if ((opts->flags & CBQCLF_ROOTCLASS) != 0) {
 		if (parent != NULL)
 			return (EINVAL);
 		if (cbqp->ifnp.root_)
 			return (EINVAL);
-		break;
-	case CBQCLF_DEFCLASS:
+	}
+	if ((opts->flags & CBQCLF_DEFCLASS) != 0) {
 		if (cbqp->ifnp.default_)
 			return (EINVAL);
-		break;
-	case 0:
+	}
+	if ((opts->flags & CBQCLF_CLASSMASK) == 0) {
 		if (a->qid == 0)
 			return (EINVAL);
-		break;
-	default:
-		/* more than two flags bits set */
-		return (EINVAL);
 	}
 
 	/*
 	 * create a class.  if this is a root class, initialize the
 	 * interface.
 	 */
-	if ((opts->flags & CBQCLF_CLASSMASK) == CBQCLF_ROOTCLASS) {
+	if ((opts->flags & CBQCLF_ROOTCLASS) != 0) {
 		error = rmc_init(cbqp->ifnp.ifq_, &cbqp->ifnp,
 		opts->ns_per_byte, cbqrestart, a->qlimit, RM_MAXQUEUED,
 		opts->maxidle, opts->minidle, opts->offtime,
@@ -412,7 +407,7 @@ cbq_add_queue(struct pf_altq *a)
 	/* save the allocated class */
 	cbqp->cbq_class_tbl[i] = cl;
 
-	if ((opts->flags & CBQCLF_CLASSMASK) == CBQCLF_DEFCLASS)
+	if ((opts->flags & CBQCLF_DEFCLASS) != 0)
 		cbqp->ifnp.default_ = cl;
 
 	return (0);
@@ -727,7 +722,7 @@ cbq_class_create(cbq_state_t *cbqp, stru
 	 * create a class.  if this is a root class, initialize the
 	 * interface.
 	 */
-	if ((spec->flags & CBQCLF_CLASSMASK) == CBQCLF_ROOTCLASS) {
+	if ((spec->flags & CBQCLF_ROOTCLASS) != 0) {
 		error = rmc_init(cbqp->ifnp.ifq_, &cbqp->ifnp,
 		spec->nano_sec_per_byte, cbqrestart, spec->maxq,
 		RM_MAXQUEUED, spec->maxidle, spec->minidle, spec->offtime,
@@ -754,9 +749,9 @@ cbq_class_create(cbq_state_t *cbqp, stru
 	/* save the allocated class */
 	cbqp->cbq_class_tbl[i] = cl;
 
-	if ((spec->flags & CBQCLF_CLASSMASK) == CBQCLF_DEFCLASS)
+	if ((spec->flags & CBQCLF_CLASSMASK) != 0)
 		cbqp->ifnp.default_ = cl;
-	if ((spec->flags & CBQCLF_CLASSMASK) == CBQCLF_CTLCLASS)
+	if ((spec->flags & CBQCLF_CTLCLASS) != 0)
 		cbqp->ifnp.ctl_ = cl;
 
 	return (0);



CVS commit: src/sys/altq

2021-07-14 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Wed Jul 14 08:27:59 UTC 2021

Modified Files:
src/sys/altq: altq_cbq.c

Log Message:
altq, cbq: allow no control class


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/sys/altq/altq_cbq.c

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

Modified files:

Index: src/sys/altq/altq_cbq.c
diff -u src/sys/altq/altq_cbq.c:1.32 src/sys/altq/altq_cbq.c:1.33
--- src/sys/altq/altq_cbq.c:1.32	Thu Nov 15 10:23:55 2018
+++ src/sys/altq/altq_cbq.c	Wed Jul 14 08:27:59 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: altq_cbq.c,v 1.32 2018/11/15 10:23:55 maxv Exp $	*/
+/*	$NetBSD: altq_cbq.c,v 1.33 2021/07/14 08:27:59 ozaki-r Exp $	*/
 /*	$KAME: altq_cbq.c,v 1.21 2005/04/13 03:44:24 suz Exp $	*/
 
 /*
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: altq_cbq.c,v 1.32 2018/11/15 10:23:55 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: altq_cbq.c,v 1.33 2021/07/14 08:27:59 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_altq.h"
@@ -836,14 +836,11 @@ cbq_set_enable(struct cbq_interface *ep,
 
 	switch (enable) {
 	case ENABLE:
-		if (cbqp->ifnp.root_ == NULL || cbqp->ifnp.default_ == NULL ||
-		cbqp->ifnp.ctl_ == NULL) {
+		if (cbqp->ifnp.root_ == NULL || cbqp->ifnp.default_ == NULL) {
 			if (cbqp->ifnp.root_ == NULL)
 printf("No Root Class for %s\n", ifacename);
 			if (cbqp->ifnp.default_ == NULL)
 printf("No Default Class for %s\n", ifacename);
-			if (cbqp->ifnp.ctl_ == NULL)
-printf("No Control Class for %s\n", ifacename);
 			error = EINVAL;
 		} else if ((error = altq_enable(cbqp->ifnp.ifq_)) == 0) {
 			cbqp->cbq_qlen = 0;



CVS commit: src

2021-07-13 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Wed Jul 14 03:22:33 UTC 2021

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

Log Message:
tests: add tests for ALTQ CBQ


To generate a diff of this commit:
cvs rdiff -u -r1.1086 -r1.1087 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.184 -r1.185 src/etc/mtree/NetBSD.dist.tests
cvs rdiff -u -r1.38 -r1.39 src/tests/net/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/net/altq/Makefile \
src/tests/net/altq/t_cbq.sh

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

Modified files:

Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.1086 src/distrib/sets/lists/tests/mi:1.1087
--- src/distrib/sets/lists/tests/mi:1.1086	Tue Jul 13 19:38:10 2021
+++ src/distrib/sets/lists/tests/mi	Wed Jul 14 03:22:33 2021
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1086 2021/07/13 19:38:10 rillig Exp $
+# $NetBSD: mi,v 1.1087 2021/07/14 03:22:33 ozaki-r Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -4042,6 +4042,10 @@
 ./usr/tests/net		tests-net-tests		compattestfile,atf
 ./usr/tests/net/Atffile	tests-net-tests		compattestfile,atf
 ./usr/tests/net/Kyuafiletests-net-tests		compattestfile,atf,kyua
+./usr/tests/net/altq	tests-net-tests		compattestfile,atf
+./usr/tests/net/altq/Atffiletests-net-tests		atf,rump
+./usr/tests/net/altq/Kyuafiletests-net-tests		atf,rump,kyua
+./usr/tests/net/altq/t_cbqtests-net-tests		atf,rump
 ./usr/tests/net/arp	tests-net-tests		compattestfile,atf
 ./usr/tests/net/arp/Atffiletests-net-tests		atf,rump
 ./usr/tests/net/arp/Kyuafiletests-net-tests		atf,rump,kyua

Index: src/etc/mtree/NetBSD.dist.tests
diff -u src/etc/mtree/NetBSD.dist.tests:1.184 src/etc/mtree/NetBSD.dist.tests:1.185
--- src/etc/mtree/NetBSD.dist.tests:1.184	Mon May 17 04:07:42 2021
+++ src/etc/mtree/NetBSD.dist.tests	Wed Jul 14 03:22:33 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: NetBSD.dist.tests,v 1.184 2021/05/17 04:07:42 yamaguchi Exp $
+#	$NetBSD: NetBSD.dist.tests,v 1.185 2021/07/14 03:22:33 ozaki-r Exp $
 
 ./usr/libdata/debug/usr/tests
 ./usr/libdata/debug/usr/tests/atf
@@ -345,6 +345,7 @@
 ./usr/tests/libexec/ld.elf_so/h_helper_symver_dso2
 ./usr/tests/modules
 ./usr/tests/net
+./usr/tests/net/altq
 ./usr/tests/net/arp
 ./usr/tests/net/bpf
 ./usr/tests/net/bpfilter

Index: src/tests/net/Makefile
diff -u src/tests/net/Makefile:1.38 src/tests/net/Makefile:1.39
--- src/tests/net/Makefile:1.38	Mon May 17 04:07:44 2021
+++ src/tests/net/Makefile	Wed Jul 14 03:22:33 2021
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.38 2021/05/17 04:07:44 yamaguchi Exp $
+# $NetBSD: Makefile,v 1.39 2021/07/14 03:22:33 ozaki-r Exp $
 
 .include 
 
@@ -6,7 +6,7 @@ TESTSDIR=	${TESTSBASE}/net
 
 TESTS_SUBDIRS=		fdpass in_cksum net sys
 .if (${MKRUMP} != "no") && !defined(BSD_MK_COMPAT_FILE)
-TESTS_SUBDIRS+=		arp bpf bpfilter can carp icmp if if_bridge if_gif
+TESTS_SUBDIRS+=		altq arp bpf bpfilter can carp icmp if if_bridge if_gif
 TESTS_SUBDIRS+=		if_ipsec if_l2tp if_lagg if_loop if_pppoe if_tap
 TESTS_SUBDIRS+=		if_tun if_vether if_vlan if_wg ipsec mcast mpls
 TESTS_SUBDIRS+=		ndp npf route

Added files:

Index: src/tests/net/altq/Makefile
diff -u /dev/null src/tests/net/altq/Makefile:1.1
--- /dev/null	Wed Jul 14 03:22:33 2021
+++ src/tests/net/altq/Makefile	Wed Jul 14 03:22:33 2021
@@ -0,0 +1,13 @@
+# $NetBSD: Makefile,v 1.1 2021/07/14 03:22:33 ozaki-r Exp $
+#
+
+.include 
+
+TESTSDIR=	${TESTSBASE}/net/altq
+
+.for name in cbq
+ TESTS_SH+=	t_${name}
+ TESTS_SH_SRC_t_${name}=	../net_common.sh t_${name}.sh
+.endfor
+
+.include 
Index: src/tests/net/altq/t_cbq.sh
diff -u /dev/null src/tests/net/altq/t_cbq.sh:1.1
--- /dev/null	Wed Jul 14 03:22:33 2021
+++ src/tests/net/altq/t_cbq.sh	Wed Jul 14 03:22:33 2021
@@ -0,0 +1,347 @@
+#	$NetBSD: t_cbq.sh,v 1.1 2021/07/14 03:22:33 ozaki-r 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, INDIRE

CVS commit: src

2021-07-13 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Wed Jul 14 03:19:24 UTC 2021

Modified Files:
src/distrib/sets/lists/base: shl.mi
src/distrib/sets/lists/comp: mi shl.mi
src/distrib/sets/lists/debug: mi shl.mi
src/sys/rump/include/opt: opt_rumpkernel.h
src/sys/rump/librump/rumpnet: net_stub.c
src/sys/rump/net: Makefile.rumpnetcomp
Added Files:
src/sys/rump/net/lib/libaltq: Makefile altq_component.c

Log Message:
Rump-ify ALTQ (librumpnet_altq.so)


To generate a diff of this commit:
cvs rdiff -u -r1.921 -r1.922 src/distrib/sets/lists/base/shl.mi
cvs rdiff -u -r1.2389 -r1.2390 src/distrib/sets/lists/comp/mi
cvs rdiff -u -r1.346 -r1.347 src/distrib/sets/lists/comp/shl.mi
cvs rdiff -u -r1.355 -r1.356 src/distrib/sets/lists/debug/mi
cvs rdiff -u -r1.278 -r1.279 src/distrib/sets/lists/debug/shl.mi
cvs rdiff -u -r1.6 -r1.7 src/sys/rump/include/opt/opt_rumpkernel.h
cvs rdiff -u -r1.42 -r1.43 src/sys/rump/librump/rumpnet/net_stub.c
cvs rdiff -u -r1.24 -r1.25 src/sys/rump/net/Makefile.rumpnetcomp
cvs rdiff -u -r0 -r1.1 src/sys/rump/net/lib/libaltq/Makefile \
src/sys/rump/net/lib/libaltq/altq_component.c

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

Modified files:

Index: src/distrib/sets/lists/base/shl.mi
diff -u src/distrib/sets/lists/base/shl.mi:1.921 src/distrib/sets/lists/base/shl.mi:1.922
--- src/distrib/sets/lists/base/shl.mi:1.921	Thu Jun 17 01:17:27 2021
+++ src/distrib/sets/lists/base/shl.mi	Wed Jul 14 03:19:23 2021
@@ -1,4 +1,4 @@
-# $NetBSD: shl.mi,v 1.921 2021/06/17 01:17:27 christos Exp $
+# $NetBSD: shl.mi,v 1.922 2021/07/14 03:19:23 ozaki-r Exp $
 #
 # Note:	Don't delete entries from here - mark them as "obsolete" instead,
 #	unless otherwise stated below.
@@ -765,6 +765,9 @@
 ./usr/lib/librumpnet_agr.so			base-rump-shlib		rump
 ./usr/lib/librumpnet_agr.so.0			base-rump-shlib		rump
 ./usr/lib/librumpnet_agr.so.0.0			base-rump-shlib		rump
+./usr/lib/librumpnet_altq.so			base-rump-shlib		rump
+./usr/lib/librumpnet_altq.so.0			base-rump-shlib		rump
+./usr/lib/librumpnet_altq.so.0.0		base-rump-shlib		rump
 ./usr/lib/librumpnet_bpfjit.so			base-rump-shlib		rump,sljit
 ./usr/lib/librumpnet_bpfjit.so.0		base-rump-shlib		rump,sljit
 ./usr/lib/librumpnet_bpfjit.so.0.0		base-rump-shlib		rump,sljit

Index: src/distrib/sets/lists/comp/mi
diff -u src/distrib/sets/lists/comp/mi:1.2389 src/distrib/sets/lists/comp/mi:1.2390
--- src/distrib/sets/lists/comp/mi:1.2389	Thu Jun 17 01:17:28 2021
+++ src/distrib/sets/lists/comp/mi	Wed Jul 14 03:19:24 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: mi,v 1.2389 2021/06/17 01:17:28 christos Exp $
+#	$NetBSD: mi,v 1.2390 2021/07/14 03:19:24 ozaki-r Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 ./etc/mtree/set.compcomp-sys-root
@@ -4011,8 +4011,12 @@
 ./usr/lib/librumpkern_z.a			comp-c-lib		rump
 ./usr/lib/librumpkern_z_p.a			comp-c-proflib		rump,profile
 ./usr/lib/librumpnet.acomp-c-lib		compatfile,rump
+./usr/lib/librumpnet_altq.a			comp-c-lib		rump
+./usr/lib/librumpnet_altq_p.a			comp-c-proflib		rump,profile
 ./usr/lib/librumpnet_agr.a			comp-c-lib		rump
 ./usr/lib/librumpnet_agr_p.a			comp-c-proflib		rump,profile
+./usr/lib/librumpnet_altq.a			comp-c-lib		rump
+./usr/lib/librumpnet_altq_p.a			comp-c-proflib		rump,profile
 ./usr/lib/librumpnet_bpfjit.a			comp-c-lib		rump,sljit
 ./usr/lib/librumpnet_bpfjit_p.a			comp-c-proflib		rump,sljit,profile
 ./usr/lib/librumpnet_bridge.a			comp-c-lib		rump

Index: src/distrib/sets/lists/comp/shl.mi
diff -u src/distrib/sets/lists/comp/shl.mi:1.346 src/distrib/sets/lists/comp/shl.mi:1.347
--- src/distrib/sets/lists/comp/shl.mi:1.346	Mon May 17 04:07:41 2021
+++ src/distrib/sets/lists/comp/shl.mi	Wed Jul 14 03:19:24 2021
@@ -1,4 +1,4 @@
-# $NetBSD: shl.mi,v 1.346 2021/05/17 04:07:41 yamaguchi Exp $
+# $NetBSD: shl.mi,v 1.347 2021/07/14 03:19:24 ozaki-r Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -225,6 +225,7 @@
 ./usr/lib/librumpkern_tty_pic.a			comp-c-piclib		picinstall,rump
 ./usr/lib/librumpkern_z_pic.a			comp-c-piclib		picinstall,rump
 ./usr/lib/librumpnet_agr_pic.a			comp-c-piclib		picinstall,rump
+./usr/lib/librumpnet_altq_pic.a			comp-c-piclib		picinstall,rump
 ./usr/lib/librumpnet_bpfjit_pic.a		comp-c-piclib		picinstall,rump,sljit
 ./usr/lib/librumpnet_bridge_pic.a		comp-c-piclib		picinstall,rump
 ./usr/lib/librumpnet_gif_pic.a			comp-c-piclib		picinstall,rump

Index: src/distrib/sets/lists/debug/mi
diff -u src/distrib/sets/lists/debug/mi:1.355 src/distrib/sets/lists/debug/mi:1.356
--- src/distrib/sets/lists/debug/mi:1.355	Fri Jul  9 05:54:11 2021
+++ src/distrib/sets/lists/debug/mi	Wed Jul 14 03:19:24 2021
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.355 2021/07/09 05:54:11 yamaguchi Exp $
+# $NetBSD: mi,v 1.356 2021/07/14 03:19:24 ozaki-r Exp $
 ./etc/mtree/set.debug   comp-sys-root
 ./usr/lib	com

CVS commit: src/sys/rump/net/lib/libshmif

2021-07-13 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Wed Jul 14 03:16:06 UTC 2021

Modified Files:
src/sys/rump/net/lib/libshmif: if_shmem.c

Log Message:
shmif: support ALTQ


To generate a diff of this commit:
cvs rdiff -u -r1.82 -r1.83 src/sys/rump/net/lib/libshmif/if_shmem.c

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

Modified files:

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.82 src/sys/rump/net/lib/libshmif/if_shmem.c:1.83
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.82	Wed Jun 16 00:21:19 2021
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Wed Jul 14 03:16:06 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.82 2021/06/16 00:21:19 riastradh Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.83 2021/07/14 03:16:06 ozaki-r Exp $	*/
 
 /*
  * Copyright (c) 2009, 2010 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_shmem.c,v 1.82 2021/06/16 00:21:19 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_shmem.c,v 1.83 2021/07/14 03:16:06 ozaki-r Exp $");
 
 #include 
 #include 
@@ -191,6 +191,7 @@ allocif(int unit, struct shmif_sc **scp)
 	IFCAP_CSUM_UDPv4_Rx	| IFCAP_CSUM_UDPv4_Tx |
 	IFCAP_CSUM_TCPv6_Rx	| IFCAP_CSUM_TCPv6_Tx |
 	IFCAP_CSUM_UDPv6_Rx	| IFCAP_CSUM_UDPv6_Tx;
+	IFQ_SET_READY(&ifp->if_snd);
 
 	mutex_init(&sc->sc_mtx, MUTEX_DEFAULT, IPL_NONE);
 	cv_init(&sc->sc_cv, "shmifcv");
@@ -206,6 +207,7 @@ allocif(int unit, struct shmif_sc **scp)
 	}
 #endif
 
+	if_deferred_start_init(ifp, NULL);
 	ether_ifattach(ifp, enaddr);
 	if_register(ifp);
 
@@ -545,7 +547,7 @@ shmif_start(struct ifnet *ifp)
 	ifp->if_flags |= IFF_OACTIVE;
 
 	for (;;) {
-		IF_DEQUEUE(&ifp->if_snd, m);
+		IFQ_DEQUEUE(&ifp->if_snd, m);
 		if (m == NULL)
 			break;
 



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(&ifq->if_send);
+	IFQ_SET_READY(&ifp->if_snd);
 
 	error = lagg_setup_sysctls(sc);
 	if (error != 0)



CVS commit: src/sys/altq

2021-07-13 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Tue Jul 13 08:23:39 UTC 2021

Modified Files:
src/sys/altq: altq_rmclass.c

Log Message:
altq, cbq: calculate a delay period based on a borrowed class

A delay period was calculated based on a suspended class even if the
class can borrow bandwidth from another class.  In that case a delay
period should be calculated based on a borrowed class.  Otherwise
a borrowing class can't borrow bandwidth correctly.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/altq/altq_rmclass.c

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

Modified files:

Index: src/sys/altq/altq_rmclass.c
diff -u src/sys/altq/altq_rmclass.c:1.23 src/sys/altq/altq_rmclass.c:1.24
--- src/sys/altq/altq_rmclass.c:1.23	Tue Jul 13 07:59:48 2021
+++ src/sys/altq/altq_rmclass.c	Tue Jul 13 08:23:39 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: altq_rmclass.c,v 1.23 2021/07/13 07:59:48 ozaki-r Exp $	*/
+/*	$NetBSD: altq_rmclass.c,v 1.24 2021/07/13 08:23:39 ozaki-r Exp $	*/
 /*	$KAME: altq_rmclass.c,v 1.19 2005/04/13 03:44:25 suz Exp $	*/
 
 /*
@@ -38,7 +38,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: altq_rmclass.c,v 1.23 2021/07/13 07:59:48 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: altq_rmclass.c,v 1.24 2021/07/13 08:23:39 ozaki-r Exp $");
 
 /* #ident "@(#)rm_class.c  1.48 97/12/05 SMI" */
 
@@ -1482,7 +1482,10 @@ rmc_delay_action(struct rm_class *cl, st
 	int	ndelay, t, extradelay;
 
 	cl->stats_.overactions++;
-	TV_DELTA(&cl->undertime_, &cl->overtime_, ndelay);
+	if (borrow != NULL)
+		TV_DELTA(&borrow->undertime_, &cl->overtime_, ndelay);
+	else
+		TV_DELTA(&cl->undertime_, &cl->overtime_, ndelay);
 #ifndef BORROW_OFFTIME
 	ndelay += cl->offtime_;
 #endif



CVS commit: src/sys/altq

2021-07-13 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Tue Jul 13 08:04:31 UTC 2021

Modified Files:
src/sys/altq: altq_rmclass.h

Log Message:
altq, cbq: apply the do-while idiom to TV_* macros


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/altq/altq_rmclass.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/altq/altq_rmclass.h
diff -u src/sys/altq/altq_rmclass.h:1.8 src/sys/altq/altq_rmclass.h:1.9
--- src/sys/altq/altq_rmclass.h:1.8	Sat Oct 28 11:35:17 2006
+++ src/sys/altq/altq_rmclass.h	Tue Jul 13 08:04:31 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: altq_rmclass.h,v 1.8 2006/10/28 11:35:17 peter Exp $	*/
+/*	$NetBSD: altq_rmclass.h,v 1.9 2021/07/13 08:04:31 ozaki-r Exp $	*/
 /*	$KAME: altq_rmclass.h,v 1.10 2003/08/20 23:30:23 itojun Exp $	*/
 
 /*
@@ -76,7 +76,7 @@ struct red;
 #define	TV_LT(a, b) (((a)->tv_sec < (b)->tv_sec) ||  \
 	(((a)->tv_usec < (b)->tv_usec) && ((a)->tv_sec <= (b)->tv_sec)))
 
-#define	TV_DELTA(a, b, delta) { \
+#define	TV_DELTA(a, b, delta) do { \
 	register int	xxs;	\
 			\
 	delta = (a)->tv_usec - (b)->tv_usec; \
@@ -95,9 +95,9 @@ struct red;
 			break; \
 		} \
 	} \
-}
+} while (0)
 
-#define	TV_ADD_DELTA(a, delta, res) { \
+#define	TV_ADD_DELTA(a, delta, res) do { \
 	register int xxus = (a)->tv_usec + (delta); \
 	\
 	(res)->tv_sec = (a)->tv_sec; \
@@ -106,7 +106,7 @@ struct red;
 		xxus -= 100; \
 	} \
 	(res)->tv_usec = xxus; \
-}
+} while (0)
 
 #define	RM_TIMEOUT	2	/* 1 Clock tick. */
 



CVS commit: src/sys/altq

2021-07-13 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Tue Jul 13 07:59:48 UTC 2021

Modified Files:
src/sys/altq: altq_rmclass.c

Log Message:
altq, cbq: don't increment the xmit counter of the root class twice wrongly


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

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

Modified files:

Index: src/sys/altq/altq_rmclass.c
diff -u src/sys/altq/altq_rmclass.c:1.22 src/sys/altq/altq_rmclass.c:1.23
--- src/sys/altq/altq_rmclass.c:1.22	Sat Nov 19 22:51:18 2011
+++ src/sys/altq/altq_rmclass.c	Tue Jul 13 07:59:48 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: altq_rmclass.c,v 1.22 2011/11/19 22:51:18 tls Exp $	*/
+/*	$NetBSD: altq_rmclass.c,v 1.23 2021/07/13 07:59:48 ozaki-r Exp $	*/
 /*	$KAME: altq_rmclass.c,v 1.19 2005/04/13 03:44:25 suz Exp $	*/
 
 /*
@@ -38,7 +38,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: altq_rmclass.c,v 1.22 2011/11/19 22:51:18 tls Exp $");
+__KERNEL_RCSID(0, "$NetBSD: altq_rmclass.c,v 1.23 2021/07/13 07:59:48 ozaki-r Exp $");
 
 /* #ident "@(#)rm_class.c  1.48 97/12/05 SMI" */
 
@@ -1251,7 +1251,7 @@ rmc_update_class_util(struct rm_ifdat *i
 {
 	int		 idle, avgidle, pktlen;
 	int		 pkt_time, tidle;
-	rm_class_t	*cl, *borrowed;
+	rm_class_t	*cl, *cl0, *borrowed;
 	rm_class_t	*borrows;
 	struct timeval	*nowp;
 
@@ -1261,6 +1261,7 @@ rmc_update_class_util(struct rm_ifdat *i
 	if ((cl = ifd->class_[ifd->qo_]) == NULL)
 		return;
 
+	cl0 = cl;
 	pktlen = ifd->curlen_[ifd->qo_];
 	borrowed = ifd->borrowed_[ifd->qo_];
 	borrows = borrowed;
@@ -1370,7 +1371,7 @@ rmc_update_class_util(struct rm_ifdat *i
 		cl->last_pkttime_ = pkt_time;
 
 #if 1
-		if (cl->parent_ == NULL) {
+		if (cl->parent_ == NULL && cl != cl0) {
 			/* take stats of root class */
 			PKTCNTR_ADD(&cl->stats_.xmit_cnt, pktlen);
 		}



CVS commit: src/sys/sys

2020-08-28 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Fri Aug 28 07:29:12 UTC 2020

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

Log Message:
Bump the version for entry additions to IP_STAT and IP6_STAT

Welcome to 9.99.72


To generate a diff of this commit:
cvs rdiff -u -r1.674 -r1.675 src/sys/sys/param.h

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

Modified files:

Index: src/sys/sys/param.h
diff -u src/sys/sys/param.h:1.674 src/sys/sys/param.h:1.675
--- src/sys/sys/param.h:1.674	Sun Aug 16 09:41:50 2020
+++ src/sys/sys/param.h	Fri Aug 28 07:29:12 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: param.h,v 1.674 2020/08/16 09:41:50 skrll Exp $	*/
+/*	$NetBSD: param.h,v 1.675 2020/08/28 07:29:12 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -67,7 +67,7 @@
  *	2.99.9		(299000900)
  */
 
-#define	__NetBSD_Version__	999007100	/* NetBSD 9.99.71 */
+#define	__NetBSD_Version__	999007200	/* NetBSD 9.99.72 */
 
 #define __NetBSD_Prereq__(M,m,p) (M) * 1) + \
 (m) * 100) + (p) * 100) <= __NetBSD_Version__)



CVS commit: src/usr.bin/netstat

2020-08-28 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Fri Aug 28 07:23:48 UTC 2020

Modified Files:
src/usr.bin/netstat: atalk.c bpf.c inet.c inet6.c pfkey.c pfsync.c

Log Message:
netstat: strengthen against kernel changes

netstat uses sysctlbyname to get counter data from the kernel.
sysctlbyname fails with ENOMEM if actual counter data in the kernel is
larger than a passed buffer.  netstat just skips showing counters of a
category if sysctlbyname fails, so if we added new counters of the
category to the kernel, nestat shows nothing for the category.

Fortunately sysctlbyname fills data as much as possible even if a passed
buffer is short.  So we can allow netstat to show the filled data anyway
if sysctlbyname fails with ENOMEM.

Note that this backcompat mechanism works only if new counters are
appended, and doesn't work if new counters are inserted into the middle
or counters are moved.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/usr.bin/netstat/atalk.c
cvs rdiff -u -r1.14 -r1.15 src/usr.bin/netstat/bpf.c
cvs rdiff -u -r1.112 -r1.113 src/usr.bin/netstat/inet.c
cvs rdiff -u -r1.76 -r1.77 src/usr.bin/netstat/inet6.c
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/netstat/pfkey.c \
src/usr.bin/netstat/pfsync.c

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

Modified files:

Index: src/usr.bin/netstat/atalk.c
diff -u src/usr.bin/netstat/atalk.c:1.18 src/usr.bin/netstat/atalk.c:1.19
--- src/usr.bin/netstat/atalk.c:1.18	Thu Apr 23 00:23:31 2020
+++ src/usr.bin/netstat/atalk.c	Fri Aug 28 07:23:48 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: atalk.c,v 1.18 2020/04/23 00:23:31 joerg Exp $	*/
+/*	$NetBSD: atalk.c,v 1.19 2020/08/28 07:23:48 ozaki-r Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from @(#)atalk.c	1.1 (Whistle) 6/6/96";
 #else
-__RCSID("$NetBSD: atalk.c,v 1.18 2020/04/23 00:23:31 joerg Exp $");
+__RCSID("$NetBSD: atalk.c,v 1.19 2020/08/28 07:23:48 ozaki-r Exp $");
 #endif
 #endif /* not lint */
 
@@ -291,7 +291,7 @@ ddp_stats(u_long off, const char *name)
 		size_t size = sizeof(ddpstat);
 
 		if (prog_sysctlbyname("net.atalk.ddp.stats", ddpstat, &size,
- NULL, 0) == -1)
+ NULL, 0) == -1 && errno != ENOMEM)
 			return;
 	} else {
 		warnx("%s stats not available via KVM.", name);

Index: src/usr.bin/netstat/bpf.c
diff -u src/usr.bin/netstat/bpf.c:1.14 src/usr.bin/netstat/bpf.c:1.15
--- src/usr.bin/netstat/bpf.c:1.14	Sun Aug 18 04:14:40 2019
+++ src/usr.bin/netstat/bpf.c	Fri Aug 28 07:23:48 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpf.c,v 1.14 2019/08/18 04:14:40 kamil Exp $	*/
+/*	$NetBSD: bpf.c,v 1.15 2020/08/28 07:23:48 ozaki-r Exp $	*/
 
 /*
  * Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -53,7 +53,8 @@ bpf_stats(void)
 	size_t len = sizeof(bpf_s);
 
 	if (use_sysctl) {
-		if (prog_sysctlbyname("net.bpf.stats", &bpf_s, &len, NULL, 0) == -1)
+		if (prog_sysctlbyname("net.bpf.stats", &bpf_s, &len, NULL, 0) == -1 &&
+		errno != ENOMEM)
 			err(1, "net.bpf.stats");
 	
 		printf("bpf:\n");

Index: src/usr.bin/netstat/inet.c
diff -u src/usr.bin/netstat/inet.c:1.112 src/usr.bin/netstat/inet.c:1.113
--- src/usr.bin/netstat/inet.c:1.112	Fri Aug 28 06:34:17 2020
+++ src/usr.bin/netstat/inet.c	Fri Aug 28 07:23:48 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet.c,v 1.112 2020/08/28 06:34:17 ozaki-r Exp $	*/
+/*	$NetBSD: inet.c,v 1.113 2020/08/28 07:23:48 ozaki-r Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)inet.c	8.4 (Berkeley) 4/20/94";
 #else
-__RCSID("$NetBSD: inet.c,v 1.112 2020/08/28 06:34:17 ozaki-r Exp $");
+__RCSID("$NetBSD: inet.c,v 1.113 2020/08/28 07:23:48 ozaki-r Exp $");
 #endif
 #endif /* not lint */
 
@@ -404,7 +404,7 @@ tcp_stats(u_long off, const char *name)
 		size_t size = sizeof(tcpstat);
 
 		if (prog_sysctlbyname("net.inet.tcp.stats", tcpstat, &size,
- NULL, 0) == -1)
+ NULL, 0) == -1 && errno != ENOMEM)
 			return;
 	} else {
 		warnx("%s stats not available via KVM.", name);
@@ -531,7 +531,7 @@ udp_stats(u_long off, const char *name)
 		size_t size = sizeof(udpstat);
 
 		if (prog_sysctlbyname("net.inet.udp.stats", udpstat, &size,
- NULL, 0) == -1)
+ NULL, 0) == -1 && errno != ENOMEM)
 			return;
 	} else {
 		warnx("%s stats not available via KVM.", name);
@@ -584,7 +584,7 @@ ip_stats(u_long off, const char *name)
 		size_t size = sizeof(ipstat);
 
 		if (prog_sysctlbyname("net.inet.ip.stats", ipstat, &size,
- NULL, 0) == -1)
+ NULL, 0) == -1 && errno != ENOMEM)
 			return;
 	} else {
 		warnx("%s stats not available via KVM.", name);
@@ -657,7 +657,7 @@ icmp_stats(u_long off, const char *name)
 		size_t size = sizeof(icmpstat);
 
 		if (prog_sysctlbyname("net.inet.icmp.stats", icmpstat, &size,
- NULL, 0) == -1)
+ NULL, 0) == -1 && errno != ENOMEM)
 			return;
 	} else {
 		warnx("%s stats not available via KVM.", name);
@@ -713,7 +713,7 @@ igmp_stat

CVS commit: src/usr.bin/netstat

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

Modified Files:
src/usr.bin/netstat: inet.c inet6.c

Log Message:
netstat: support new packet counters


To generate a diff of this commit:
cvs rdiff -u -r1.111 -r1.112 src/usr.bin/netstat/inet.c
cvs rdiff -u -r1.75 -r1.76 src/usr.bin/netstat/inet6.c

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

Modified files:

Index: src/usr.bin/netstat/inet.c
diff -u src/usr.bin/netstat/inet.c:1.111 src/usr.bin/netstat/inet.c:1.112
--- src/usr.bin/netstat/inet.c:1.111	Thu Aug  6 07:38:54 2020
+++ src/usr.bin/netstat/inet.c	Fri Aug 28 06:34:17 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet.c,v 1.111 2020/08/06 07:38:54 knakahara Exp $	*/
+/*	$NetBSD: inet.c,v 1.112 2020/08/28 06:34:17 ozaki-r Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)inet.c	8.4 (Berkeley) 4/20/94";
 #else
-__RCSID("$NetBSD: inet.c,v 1.111 2020/08/06 07:38:54 knakahara Exp $");
+__RCSID("$NetBSD: inet.c,v 1.112 2020/08/28 06:34:17 ozaki-r Exp $");
 #endif
 #endif /* not lint */
 
@@ -633,6 +633,13 @@ ip_stats(u_long off, const char *name)
 	p(IP_STAT_BADADDR, "\t%" PRIu64 " datagram%s with bad address in header\n");
 	p(IP_STAT_PFILDROP_IN, "\t%" PRIu64 " input packet%s dropped by pfil\n");
 	p(IP_STAT_PFILDROP_OUT, "\t%" PRIu64 " output packet%s dropped by pfil\n");
+	p(IP_STAT_IPSECDROP_IN, "\t%" PRIu64 " input packet%s dropped by IPsec\n");
+	p(IP_STAT_IPSECDROP_OUT, "\t%" PRIu64 " output packet%s dropped by IPsec\n");
+	p(IP_STAT_IFDROP, "\t%" PRIu64 " input packet%s dropped due to interface state\n");
+	p(IP_STAT_TIMXCEED, "\t%" PRIu64 " packet%s dropped due to TTL exceeded\n");
+	p(IP_STAT_IFNOADDR, "\t%" PRIu64 " output packet%s dropped (no IP address)\n");
+	p(IP_STAT_RTREJECT, "\t%" PRIu64 " output packet%s discarded due to reject route\n");
+	p(IP_STAT_BCASTDENIED, "\t%" PRIu64 " output packet%s dropped (broadcast prohibited)\n");
 #undef ps
 #undef p
 }

Index: src/usr.bin/netstat/inet6.c
diff -u src/usr.bin/netstat/inet6.c:1.75 src/usr.bin/netstat/inet6.c:1.76
--- src/usr.bin/netstat/inet6.c:1.75	Thu Aug  6 07:38:54 2020
+++ src/usr.bin/netstat/inet6.c	Fri Aug 28 06:34:17 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: inet6.c,v 1.75 2020/08/06 07:38:54 knakahara Exp $	*/
+/*	$NetBSD: inet6.c,v 1.76 2020/08/28 06:34:17 ozaki-r Exp $	*/
 /*	BSDI inet.c,v 2.3 1995/10/24 02:19:29 prb Exp	*/
 
 /*
@@ -64,7 +64,7 @@
 #if 0
 static char sccsid[] = "@(#)inet.c	8.4 (Berkeley) 4/20/94";
 #else
-__RCSID("$NetBSD: inet6.c,v 1.75 2020/08/06 07:38:54 knakahara Exp $");
+__RCSID("$NetBSD: inet6.c,v 1.76 2020/08/28 06:34:17 ozaki-r Exp $");
 #endif
 #endif /* not lint */
 
@@ -801,6 +801,13 @@ ip6_stats(u_long off, const char *name)
 	p1(IP6_STAT_FORWARD_CACHEMISS, "\t%llu forward cache miss\n");
 	p(IP6_STAT_PFILDROP_IN, "\t%llu input packet%s dropped by pfil\n");
 	p(IP6_STAT_PFILDROP_OUT, "\t%llu output packet%s dropped by pfil\n");
+	p(IP6_STAT_IPSECDROP_IN, "\t%llu input packet%s dropped by IPsec\n");
+	p(IP6_STAT_IPSECDROP_OUT, "\t%llu output packet%s dropped by IPsec\n");
+	p(IP6_STAT_IFDROP, "\t%llu input packet%s dropped due to interface state\n");
+	p(IP6_STAT_IDROPPED, "\t%llu input packet%s dropped due to no bufs, etc.\n");
+	p(IP6_STAT_TIMXCEED, "\t%llu packet%s dropped due to hop limit exceeded\n");
+	p(IP6_STAT_TOOBIG, "\t%llu packet%s dropped (too big)\n");
+	p(IP6_STAT_RTREJECT, "\t%llu output packet%s discarded due to reject route\n");
 #undef p
 #undef p1
 }



CVS commit: src/sys/netinet

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

Modified Files:
src/sys/netinet: ip_input.c ip_output.c ip_var.h

Log Message:
inet: reduce silent packet discards


To generate a diff of this commit:
cvs rdiff -u -r1.396 -r1.397 src/sys/netinet/ip_input.c
cvs rdiff -u -r1.317 -r1.318 src/sys/netinet/ip_output.c
cvs rdiff -u -r1.129 -r1.130 src/sys/netinet/ip_var.h

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

Modified files:

Index: src/sys/netinet/ip_input.c
diff -u src/sys/netinet/ip_input.c:1.396 src/sys/netinet/ip_input.c:1.397
--- src/sys/netinet/ip_input.c:1.396	Fri Aug 28 06:30:08 2020
+++ src/sys/netinet/ip_input.c	Fri Aug 28 06:31:42 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_input.c,v 1.396 2020/08/28 06:30:08 ozaki-r Exp $	*/
+/*	$NetBSD: ip_input.c,v 1.397 2020/08/28 06:31:42 ozaki-r Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.396 2020/08/28 06:30:08 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.397 2020/08/28 06:31:42 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -404,6 +404,7 @@ ipintr(void *arg __unused)
 
 		ifp = m_get_rcvif_psref(m, &psref);
 		if (__predict_false(ifp == NULL)) {
+			IP_STATINC(IP_STAT_IFDROP);
 			m_freem(m);
 			continue;
 		}
@@ -440,8 +441,11 @@ ip_input(struct mbuf *m, struct ifnet *i
 	 * are receiving, can't do anything with incoming packets yet.
 	 * Note: we pre-check without locks held.
 	 */
-	if (IN_ADDRLIST_READER_EMPTY())
+	if (IN_ADDRLIST_READER_EMPTY()) {
+		IP_STATINC(IP_STAT_IFDROP);
 		goto out;
+	}
+
 	IP_STATINC(IP_STAT_TOTAL);
 
 	/*
@@ -1363,6 +1367,7 @@ ip_forward(struct mbuf *m, int srcrt, st
 	}
 
 	if (ip->ip_ttl <= IPTTLDEC) {
+		IP_STATINC(IP_STAT_TIMXCEED);
 		icmp_error(m, ICMP_TIMXCEED, ICMP_TIMXCEED_INTRANS, dest, 0);
 		return;
 	}
@@ -1373,6 +1378,7 @@ ip_forward(struct mbuf *m, int srcrt, st
 	rt = rtcache_lookup(ro, &u.dst);
 	if (rt == NULL) {
 		rtcache_percpu_putref(ipforward_rt_percpu);
+		IP_STATINC(IP_STAT_NOROUTE);
 		icmp_error(m, ICMP_UNREACH, ICMP_UNREACH_NET, dest, 0);
 		return;
 	}

Index: src/sys/netinet/ip_output.c
diff -u src/sys/netinet/ip_output.c:1.317 src/sys/netinet/ip_output.c:1.318
--- src/sys/netinet/ip_output.c:1.317	Fri Aug 28 06:22:25 2020
+++ src/sys/netinet/ip_output.c	Fri Aug 28 06:31:42 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_output.c,v 1.317 2020/08/28 06:22:25 ozaki-r Exp $	*/
+/*	$NetBSD: ip_output.c,v 1.318 2020/08/28 06:31:42 ozaki-r Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.317 2020/08/28 06:22:25 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.318 2020/08/28 06:31:42 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -202,6 +202,7 @@ ip_if_output(struct ifnet * const ifp, s
 	if (rt != NULL) {
 		error = rt_check_reject_route(rt, ifp);
 		if (error != 0) {
+			IP_STATINC(IP_STAT_RTREJECT);
 			m_freem(m);
 			return error;
 		}
@@ -312,8 +313,10 @@ ip_output(struct mbuf *m0, struct mbuf *
 	(rt = rtcache_update(ro, 1)) == NULL) {
 		dst = &udst.sin;
 		error = rtcache_setdst(ro, &udst.sa);
-		if (error != 0)
+		if (error != 0) {
+			IP_STATINC(IP_STAT_ODROPPED);
 			goto bad;
+		}
 	}
 
 	/*
@@ -346,6 +349,7 @@ ip_output(struct mbuf *m0, struct mbuf *
 		mtu = ifp->if_mtu;
 		ia = in_get_ia_from_ifp_psref(ifp, &psref_ia);
 		if (ia == NULL) {
+			IP_STATINC(IP_STAT_IFNOADDR);
 			error = EADDRNOTAVAIL;
 			goto bad;
 		}
@@ -451,6 +455,7 @@ ip_output(struct mbuf *m0, struct mbuf *
 
 			xia = in_get_ia_from_ifp_psref(ifp, &_psref);
 			if (!xia) {
+IP_STATINC(IP_STAT_IFNOADDR);
 error = EADDRNOTAVAIL;
 goto bad;
 			}
@@ -460,6 +465,7 @@ ip_output(struct mbuf *m0, struct mbuf *
 /* FIXME ifa_getifa is NOMPSAFE */
 xia = ifatoia((*xifa->ifa_getifa)(xifa, rdst));
 if (xia == NULL) {
+	IP_STATINC(IP_STAT_IFNOADDR);
 	error = EADDRNOTAVAIL;
 	goto bad;
 }
@@ -511,6 +517,7 @@ ip_output(struct mbuf *m0, struct mbuf *
 		 * destination group on the loopback interface.
 		 */
 		if (ip->ip_ttl == 0 || (ifp->if_flags & IFF_LOOPBACK) != 0) {
+			IP_STATINC(IP_STAT_ODROPPED);
 			m_freem(m);
 			goto done;
 		}
@@ -554,15 +561,18 @@ ip_output(struct mbuf *m0, struct mbuf *
 	 */
 	if (isbroadcast) {
 		if ((ifp->if_flags & IFF_BROADCAST) == 0) {
+			IP_STATINC(IP_STAT_BCASTDENIED);
 			error = EADDRNOTAVAIL;
 			goto bad;
 		}
 		if ((flags & IP_ALLOWBROADCAST) == 0) {
+			IP_STATINC(IP_STAT_BCASTDENIED);
 			error = EACCES;
 			goto bad;
 		}
 		/* don't allow broadcast messages to be fragmented */
 		if (ntohs(ip->ip_len) > ifp->if_mtu) {
+			IP_STATINC(IP_STAT_BCASTDENIED);
 			error = EMSGSIZE;
 			goto bad;
 		}
@@ -840,6 +850,7 @@ ip_fragment(struct mbuf *m, struct ifnet
 
 

CVS commit: src/sys/netinet6

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

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

Log Message:
inet6: reduce silent packet discards


To generate a diff of this commit:
cvs rdiff -u -r1.86 -r1.87 src/sys/netinet6/in6_src.c \
src/sys/netinet6/ip6_var.h
cvs rdiff -u -r1.101 -r1.102 src/sys/netinet6/ip6_forward.c
cvs rdiff -u -r1.221 -r1.222 src/sys/netinet6/ip6_input.c
cvs rdiff -u -r1.224 -r1.225 src/sys/netinet6/ip6_output.c

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

Modified files:

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

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

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

CVS commit: src/sys/netinet

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

Modified Files:
src/sys/netinet: ip_input.c

Log Message:
inet: pull m_get_rcvif_psref out of ip_input for simplicity

Same as ip6_input.


To generate a diff of this commit:
cvs rdiff -u -r1.395 -r1.396 src/sys/netinet/ip_input.c

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

Modified files:

Index: src/sys/netinet/ip_input.c
diff -u src/sys/netinet/ip_input.c:1.395 src/sys/netinet/ip_input.c:1.396
--- src/sys/netinet/ip_input.c:1.395	Fri Aug 28 06:20:44 2020
+++ src/sys/netinet/ip_input.c	Fri Aug 28 06:30:08 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_input.c,v 1.395 2020/08/28 06:20:44 ozaki-r Exp $	*/
+/*	$NetBSD: ip_input.c,v 1.396 2020/08/28 06:30:08 ozaki-r Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.395 2020/08/28 06:20:44 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.396 2020/08/28 06:30:08 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -243,7 +243,7 @@ struct mowner ip_tx_mowner = MOWNER_INIT
 #endif
 
 static void		ipintr(void *);
-static void		ip_input(struct mbuf *);
+static void		ip_input(struct mbuf *, struct ifnet *);
 static void		ip_forward(struct mbuf *, int, struct ifnet *);
 static bool		ip_dooptions(struct mbuf *);
 static struct in_ifaddr *ip_rtaddr(struct in_addr, struct psref *);
@@ -399,7 +399,18 @@ ipintr(void *arg __unused)
 
 	SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE();
 	while ((m = pktq_dequeue(ip_pktq)) != NULL) {
-		ip_input(m);
+		struct ifnet *ifp;
+		struct psref psref;
+
+		ifp = m_get_rcvif_psref(m, &psref);
+		if (__predict_false(ifp == NULL)) {
+			m_freem(m);
+			continue;
+		}
+
+		ip_input(m, ifp);
+
+		m_put_rcvif_psref(ifp, &psref);
 	}
 	SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE();
 }
@@ -409,15 +420,13 @@ ipintr(void *arg __unused)
  * try to reassemble.  Process options.  Pass to next level.
  */
 static void
-ip_input(struct mbuf *m)
+ip_input(struct mbuf *m, struct ifnet *ifp)
 {
 	struct ip *ip = NULL;
 	struct in_ifaddr *ia = NULL;
 	int hlen = 0, len;
 	int downmatch;
 	int srcrt = 0;
-	ifnet_t *ifp;
-	struct psref psref;
 	int s;
 
 	KASSERTMSG(cpu_softintr_p(), "ip_input: not in the software "
@@ -426,10 +435,6 @@ ip_input(struct mbuf *m)
 	MCLAIM(m, &ip_rx_mowner);
 	KASSERT((m->m_flags & M_PKTHDR) != 0);
 
-	ifp = m_get_rcvif_psref(m, &psref);
-	if (__predict_false(ifp == NULL))
-		goto out;
-
 	/*
 	 * If no IP addresses have been set yet but the interfaces
 	 * are receiving, can't do anything with incoming packets yet.
@@ -721,7 +726,6 @@ ip_input(struct mbuf *m)
 	 * Not for us; forward if possible and desirable.
 	 */
 	if (ipforwarding == 0) {
-		m_put_rcvif_psref(ifp, &psref);
 		IP_STATINC(IP_STAT_CANTFORWARD);
 		m_freem(m);
 	} else {
@@ -732,7 +736,6 @@ ip_input(struct mbuf *m)
 		 * forwarding loop till TTL goes to 0.
 		 */
 		if (downmatch) {
-			m_put_rcvif_psref(ifp, &psref);
 			icmp_error(m, ICMP_UNREACH, ICMP_UNREACH_HOST, 0, 0);
 			IP_STATINC(IP_STAT_CANTFORWARD);
 			return;
@@ -747,14 +750,10 @@ ip_input(struct mbuf *m)
 		}
 #endif
 		ip_forward(m, srcrt, ifp);
-		m_put_rcvif_psref(ifp, &psref);
 	}
 	return;
 
 ours:
-	m_put_rcvif_psref(ifp, &psref);
-	ifp = NULL;
-
 	/*
 	 * If offset or IP_MF are set, must reassemble.
 	 */
@@ -819,7 +818,6 @@ ours:
 	return;
 
 out:
-	m_put_rcvif_psref(ifp, &psref);
 	if (m != NULL)
 		m_freem(m);
 }



CVS commit: src/sys/netinet6

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

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

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


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

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

Modified files:

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

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

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



CVS commit: src/sys/net

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

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

Log Message:
ether: count dropped packets on output


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

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

Modified files:

Index: src/sys/net/if_ethersubr.c
diff -u src/sys/net/if_ethersubr.c:1.287 src/sys/net/if_ethersubr.c:1.288
--- src/sys/net/if_ethersubr.c:1.287	Fri Aug 28 06:27:16 2020
+++ src/sys/net/if_ethersubr.c	Fri Aug 28 06:27:49 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ethersubr.c,v 1.287 2020/08/28 06:27:16 ozaki-r Exp $	*/
+/*	$NetBSD: if_ethersubr.c,v 1.288 2020/08/28 06:27:49 ozaki-r Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.287 2020/08/28 06:27:16 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.288 2020/08/28 06:27:49 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -456,6 +456,7 @@ ether_output(struct ifnet * const ifp0, 
 	return ifq_enqueue(ifp, m);
 
 bad:
+	if_statinc(ifp, if_oerrors);
 	if (m)
 		m_freem(m);
 	return error;



CVS commit: src/sys/net

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

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

Log Message:
ether: count dropped packets on input


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

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

Modified files:

Index: src/sys/net/if_ethersubr.c
diff -u src/sys/net/if_ethersubr.c:1.286 src/sys/net/if_ethersubr.c:1.287
--- src/sys/net/if_ethersubr.c:1.286	Fri Aug 28 06:25:52 2020
+++ src/sys/net/if_ethersubr.c	Fri Aug 28 06:27:16 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ethersubr.c,v 1.286 2020/08/28 06:25:52 ozaki-r Exp $	*/
+/*	$NetBSD: if_ethersubr.c,v 1.287 2020/08/28 06:27:16 ozaki-r Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.286 2020/08/28 06:25:52 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.287 2020/08/28 06:27:16 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -620,6 +620,7 @@ ether_input_llc(struct ifnet *ifp, struc
 
 drop:
 	m_freem(m);
+	if_statinc(ifp, if_ierrors); /* XXX should have a dedicated counter? */
 	return;
 }
 #endif /* defined (LLC) || defined (NETATALK) */
@@ -644,14 +645,12 @@ ether_input(struct ifnet *ifp, struct mb
 	KASSERT(!cpu_intr_p());
 	KASSERT((m->m_flags & M_PKTHDR) != 0);
 
-	if ((ifp->if_flags & IFF_UP) == 0) {
-		m_freem(m);
-		return;
-	}
+	if ((ifp->if_flags & IFF_UP) == 0)
+		goto drop;
 	if (m->m_len < sizeof(*eh)) {
 		m = m_pullup(m, sizeof(*eh));
 		if (m == NULL)
-			return;
+			goto dropped;
 	}
 
 #ifdef MBUFTRACE
@@ -682,9 +681,7 @@ ether_input(struct ifnet *ifp, struct mb
 		}
 		mutex_exit(&bigpktpps_lock);
 #endif
-		if_statinc(ifp, if_iqdrops);
-		m_freem(m);
-		return;
+		goto drop;
 	}
 
 	if (ETHER_IS_MULTICAST(eh->ether_dhost)) {
@@ -695,8 +692,7 @@ ether_input(struct ifnet *ifp, struct mb
 		if ((ifp->if_flags & IFF_SIMPLEX) == 0 &&
 		memcmp(CLLADDR(ifp->if_sadl), eh->ether_shost,
 		ETHER_ADDR_LEN) == 0) {
-			m_freem(m);
-			return;
+			goto drop;
 		}
 
 		if (memcmp(etherbroadcastaddr,
@@ -766,10 +762,10 @@ ether_input(struct ifnet *ifp, struct mb
 		 * or drop the packet.
 		 */
 		vlan_input(ifp, m);
+		return;
 #else
-		m_freem(m);
+		goto drop;
 #endif
-		return;
 	}
 
 	/*
@@ -800,13 +796,12 @@ ether_input(struct ifnet *ifp, struct mb
 		 * vlan_input() will either recursively call ether_input()
 		 * or drop the packet.
 		 */
-		if (ec->ec_nvlans != 0)
+		if (ec->ec_nvlans != 0) {
 			vlan_input(ifp, m);
-		else
+			return;
+		} else
 #endif
-			m_freem(m);
-
-		return;
+			goto drop;
 	}
 
 #if NPPPOE > 0
@@ -822,10 +817,8 @@ ether_input(struct ifnet *ifp, struct mb
 	case ETHERTYPE_SLOWPROTOCOLS: {
 		uint8_t subtype;
 
-		if (m->m_pkthdr.len < sizeof(*eh) + sizeof(subtype)) {
-			m_freem(m);
-			return;
-		}
+		if (m->m_pkthdr.len < sizeof(*eh) + sizeof(subtype))
+			goto drop;
 
 		m_copydata(m, sizeof(*eh), sizeof(subtype), &subtype);
 		switch (subtype) {
@@ -848,8 +841,7 @@ ether_input(struct ifnet *ifp, struct mb
 		default:
 			if (subtype == 0 || subtype > 10) {
 /* illegal value */
-m_freem(m);
-return;
+goto drop;
 			}
 			/* unknown subtype */
 			break;
@@ -857,10 +849,8 @@ ether_input(struct ifnet *ifp, struct mb
 	}
 	/* FALLTHROUGH */
 	default:
-		if (m->m_flags & M_PROMISC) {
-			m_freem(m);
-			return;
-		}
+		if (m->m_flags & M_PROMISC)
+			goto drop;
 	}
 
 	/* If the CRC is still on the packet, trim it off. */
@@ -876,8 +866,7 @@ ether_input(struct ifnet *ifp, struct mb
 		ether_input_llc(ifp, m, eh);
 		return;
 #else
-		m_freem(m);
-		return;
+		goto drop;
 #endif
 	}
 
@@ -906,10 +895,8 @@ ether_input(struct ifnet *ifp, struct mb
 
 #ifdef INET6
 	case ETHERTYPE_IPV6:
-		if (__predict_false(!in6_present)) {
-			m_freem(m);
-			return;
-		}
+		if (__predict_false(!in6_present))
+			goto drop;
 #ifdef GATEWAY
 		if (ip6flow_fastforward(&m))
 			return;
@@ -937,8 +924,7 @@ ether_input(struct ifnet *ifp, struct mb
 #endif
 
 	default:
-		m_freem(m);
-		return;
+		goto drop;
 	}
 
 	if (__predict_true(pktq)) {
@@ -955,11 +941,16 @@ ether_input(struct ifnet *ifp, struct mb
 
 	if (__predict_false(!inq)) {
 		/* Should not happen. */
-		m_freem(m);
-		return;
+		goto drop;
 	}
 
 	IFQ_ENQUEUE_ISR(inq, m, isr);
+	return;
+
+drop:
+	m_freem(m);
+dropped:
+	if_statinc(ifp, if_ierrors); /* XXX should have a dedicated counter? */
 }
 
 /*



CVS commit: src/sys/net

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

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

Log Message:
ether: separate handling of LLC frames as ether_input_llc (NFCI)


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

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

Modified files:

Index: src/sys/net/if_ethersubr.c
diff -u src/sys/net/if_ethersubr.c:1.285 src/sys/net/if_ethersubr.c:1.286
--- src/sys/net/if_ethersubr.c:1.285	Fri Aug 28 06:23:42 2020
+++ src/sys/net/if_ethersubr.c	Fri Aug 28 06:25:52 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ethersubr.c,v 1.285 2020/08/28 06:23:42 ozaki-r Exp $	*/
+/*	$NetBSD: if_ethersubr.c,v 1.286 2020/08/28 06:25:52 ozaki-r Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.285 2020/08/28 06:23:42 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.286 2020/08/28 06:25:52 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -563,6 +563,67 @@ bad:
 }
 #endif /* ALTQ */
 
+#if defined (LLC) || defined (NETATALK)
+static void
+ether_input_llc(struct ifnet *ifp, struct mbuf *m, struct ether_header *eh)
+{
+	struct ifqueue *inq = NULL;
+	int isr = 0;
+	struct llc *l;
+
+	if (m->m_len < sizeof(*eh) + sizeof(struct llc))
+		goto drop;
+
+	l = (struct llc *)(eh+1);
+	switch (l->llc_dsap) {
+#ifdef NETATALK
+	case LLC_SNAP_LSAP:
+		switch (l->llc_control) {
+		case LLC_UI:
+			if (l->llc_ssap != LLC_SNAP_LSAP)
+goto drop;
+
+			if (memcmp(&(l->llc_snap_org_code)[0],
+			at_org_code, sizeof(at_org_code)) == 0 &&
+			ntohs(l->llc_snap_ether_type) ==
+			ETHERTYPE_ATALK) {
+inq = &atintrq2;
+m_adj(m, sizeof(struct ether_header)
++ sizeof(struct llc));
+isr = NETISR_ATALK;
+break;
+			}
+
+			if (memcmp(&(l->llc_snap_org_code)[0],
+			aarp_org_code,
+			sizeof(aarp_org_code)) == 0 &&
+			ntohs(l->llc_snap_ether_type) ==
+			ETHERTYPE_AARP) {
+m_adj(m, sizeof(struct ether_header)
++ sizeof(struct llc));
+aarpinput(ifp, m); /* XXX queue? */
+return;
+			}
+
+		default:
+			goto drop;
+		}
+		break;
+#endif
+	default:
+		goto drop;
+	}
+
+	KASSERT(inq != NULL);
+	IFQ_ENQUEUE_ISR(inq, m, isr);
+	return;
+
+drop:
+	m_freem(m);
+	return;
+}
+#endif /* defined (LLC) || defined (NETATALK) */
+
 /*
  * Process a received Ethernet packet;
  * the packet is in the mbuf chain m with
@@ -579,9 +640,6 @@ ether_input(struct ifnet *ifp, struct mb
 	size_t ehlen;
 	static int earlypkts;
 	int isr = 0;
-#if defined (LLC) || defined(NETATALK)
-	struct llc *l;
-#endif
 
 	KASSERT(!cpu_intr_p());
 	KASSERT((m->m_flags & M_PKTHDR) != 0);
@@ -811,119 +869,76 @@ ether_input(struct ifnet *ifp, struct mb
 		m->m_flags &= ~M_HASFCS;
 	}
 
-	if (etype > ETHERMTU + sizeof(struct ether_header)) {
-		/* Strip off the Ethernet header. */
-		m_adj(m, ehlen);
+	/* etype represents the size of the payload in this case */
+	if (etype <= ETHERMTU + sizeof(struct ether_header)) {
+		KASSERT(ehlen == sizeof(*eh));
+#if defined (LLC) || defined (NETATALK)
+		ether_input_llc(ifp, m, eh);
+		return;
+#else
+		m_freem(m);
+		return;
+#endif
+	}
 
-		switch (etype) {
+	/* Strip off the Ethernet header. */
+	m_adj(m, ehlen);
+
+	switch (etype) {
 #ifdef INET
-		case ETHERTYPE_IP:
+	case ETHERTYPE_IP:
 #ifdef GATEWAY
-			if (ipflow_fastforward(m))
-return;
+		if (ipflow_fastforward(m))
+			return;
 #endif
-			pktq = ip_pktq;
-			break;
+		pktq = ip_pktq;
+		break;
 
-		case ETHERTYPE_ARP:
-			isr = NETISR_ARP;
-			inq = &arpintrq;
-			break;
+	case ETHERTYPE_ARP:
+		isr = NETISR_ARP;
+		inq = &arpintrq;
+		break;
 
-		case ETHERTYPE_REVARP:
-			revarpinput(m);	/* XXX queue? */
-			return;
+	case ETHERTYPE_REVARP:
+		revarpinput(m);	/* XXX queue? */
+		return;
 #endif
 
 #ifdef INET6
-		case ETHERTYPE_IPV6:
-			if (__predict_false(!in6_present)) {
-m_freem(m);
-return;
-			}
+	case ETHERTYPE_IPV6:
+		if (__predict_false(!in6_present)) {
+			m_freem(m);
+			return;
+		}
 #ifdef GATEWAY
-			if (ip6flow_fastforward(&m))
-return;
+		if (ip6flow_fastforward(&m))
+			return;
 #endif
-			pktq = ip6_pktq;
-			break;
+		pktq = ip6_pktq;
+		break;
 #endif
 
 #ifdef NETATALK
-		case ETHERTYPE_ATALK:
-			isr = NETISR_ATALK;
-			inq = &atintrq1;
-			break;
+	case ETHERTYPE_ATALK:
+		isr = NETISR_ATALK;
+		inq = &atintrq1;
+		break;
 
-		case ETHERTYPE_AARP:
-			aarpinput(ifp, m); /* XXX queue? */
-			return;
+	case ETHERTYPE_AARP:
+		aarpinput(ifp, m); /* XXX queue? */
+		return;
 #endif
 
 #ifdef MPLS
-		case ETHERTYPE_MPLS:
-			isr = NETISR_MPLS;
-			inq = &mplsintrq;
-			break;
+	case ETHERTYPE_MPLS:
+		isr = NETISR_MPLS;
+		inq = &mplsintrq;
+		break;
 #endif
 
-		default:
-			m_freem(m);
-			return;
-		}
-	} else {
-		KASSERT(ehlen == sizeof(*eh));
-#if defined (LLC

CVS commit: src/sys/net

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

Modified Files:
src/sys/net: if.h if_arcsubr.c if_ethersubr.c if_ieee1394subr.c

Log Message:
net: introduce IFQ_ENQUEUE_ISR to assemble packet queuing routines (NFCI)


To generate a diff of this commit:
cvs rdiff -u -r1.283 -r1.284 src/sys/net/if.h
cvs rdiff -u -r1.81 -r1.82 src/sys/net/if_arcsubr.c
cvs rdiff -u -r1.284 -r1.285 src/sys/net/if_ethersubr.c
cvs rdiff -u -r1.65 -r1.66 src/sys/net/if_ieee1394subr.c

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.h
diff -u src/sys/net/if.h:1.283 src/sys/net/if.h:1.284
--- src/sys/net/if.h:1.283	Tue May  5 08:05:03 2020
+++ src/sys/net/if.h	Fri Aug 28 06:23:42 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.h,v 1.283 2020/05/05 08:05:03 jdolecek Exp $	*/
+/*	$NetBSD: if.h,v 1.284 2020/08/28 06:23:42 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc.
@@ -1069,6 +1069,20 @@ do {	\
 #define	IFQ_INC_DROPS(ifq)		((ifq)->ifq_drops++)
 #define	IFQ_SET_MAXLEN(ifq, len)	((ifq)->ifq_maxlen = (len))
 
+#define	IFQ_ENQUEUE_ISR(ifq, m, isr)	\
+do {	\
+	IFQ_LOCK(inq);			\
+	if (IF_QFULL(inq)) {		\
+		IF_DROP(inq);		\
+		IFQ_UNLOCK(inq);	\
+		m_freem(m);		\
+	} else {			\
+		IF_ENQUEUE(inq, m);	\
+		IFQ_UNLOCK(inq);	\
+		schednetisr(isr);	\
+	}\
+} while (/*CONSTCOND*/ 0)
+
 #include 
 MALLOC_DECLARE(M_IFADDR);
 MALLOC_DECLARE(M_IFMADDR);

Index: src/sys/net/if_arcsubr.c
diff -u src/sys/net/if_arcsubr.c:1.81 src/sys/net/if_arcsubr.c:1.82
--- src/sys/net/if_arcsubr.c:1.81	Wed Jan 29 04:11:35 2020
+++ src/sys/net/if_arcsubr.c	Fri Aug 28 06:23:42 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_arcsubr.c,v 1.81 2020/01/29 04:11:35 thorpej Exp $	*/
+/*	$NetBSD: if_arcsubr.c,v 1.82 2020/08/28 06:23:42 ozaki-r Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Ignatios Souvatzis
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_arcsubr.c,v 1.81 2020/01/29 04:11:35 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_arcsubr.c,v 1.82 2020/08/28 06:23:42 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -580,16 +580,7 @@ arc_input(struct ifnet *ifp, struct mbuf
 		return;
 	}
 
-	IFQ_LOCK(inq);
-	if (IF_QFULL(inq)) {
-		IF_DROP(inq);
-		IFQ_UNLOCK(inq);
-		m_freem(m);
-	} else {
-		IF_ENQUEUE(inq, m);
-		IFQ_UNLOCK(inq);
-		schednetisr(isr);
-	}
+	IFQ_ENQUEUE_ISR(inq, m, isr);
 }
 
 /*

Index: src/sys/net/if_ethersubr.c
diff -u src/sys/net/if_ethersubr.c:1.284 src/sys/net/if_ethersubr.c:1.285
--- src/sys/net/if_ethersubr.c:1.284	Thu Apr 30 03:29:55 2020
+++ src/sys/net/if_ethersubr.c	Fri Aug 28 06:23:42 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ethersubr.c,v 1.284 2020/04/30 03:29:55 riastradh Exp $	*/
+/*	$NetBSD: if_ethersubr.c,v 1.285 2020/08/28 06:23:42 ozaki-r Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.284 2020/04/30 03:29:55 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.285 2020/08/28 06:23:42 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -944,16 +944,7 @@ ether_input(struct ifnet *ifp, struct mb
 		return;
 	}
 
-	IFQ_LOCK(inq);
-	if (IF_QFULL(inq)) {
-		IF_DROP(inq);
-		IFQ_UNLOCK(inq);
-		m_freem(m);
-	} else {
-		IF_ENQUEUE(inq, m);
-		IFQ_UNLOCK(inq);
-		schednetisr(isr);
-	}
+	IFQ_ENQUEUE_ISR(inq, m, isr);
 }
 
 /*

Index: src/sys/net/if_ieee1394subr.c
diff -u src/sys/net/if_ieee1394subr.c:1.65 src/sys/net/if_ieee1394subr.c:1.66
--- src/sys/net/if_ieee1394subr.c:1.65	Sat Dec 22 14:28:56 2018
+++ src/sys/net/if_ieee1394subr.c	Fri Aug 28 06:23:42 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ieee1394subr.c,v 1.65 2018/12/22 14:28:56 maxv Exp $	*/
+/*	$NetBSD: if_ieee1394subr.c,v 1.66 2020/08/28 06:23:42 ozaki-r Exp $	*/
 
 /*
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_ieee1394subr.c,v 1.65 2018/12/22 14:28:56 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ieee1394subr.c,v 1.66 2020/08/28 06:23:42 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -404,16 +404,7 @@ ieee1394_input(struct ifnet *ifp, struct
 		return;
 	}
 
-	IFQ_LOCK(inq);
-	if (IF_QFULL(inq)) {
-		IF_DROP(inq);
-		IFQ_UNLOCK(inq);
-		m_freem(m);
-	} else {
-		IF_ENQUEUE(inq, m);
-		IFQ_UNLOCK(inq);
-		schednetisr(isr);
-	}
+	IFQ_ENQUEUE_ISR(inq, m, isr);
 }
 
 static struct mbuf *



CVS commit: src/sys/netinet

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

Modified Files:
src/sys/netinet: ip_output.c

Log Message:
inet: reduce indents of a normal path to improve readability (NFCI)


To generate a diff of this commit:
cvs rdiff -u -r1.316 -r1.317 src/sys/netinet/ip_output.c

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

Modified files:

Index: src/sys/netinet/ip_output.c
diff -u src/sys/netinet/ip_output.c:1.316 src/sys/netinet/ip_output.c:1.317
--- src/sys/netinet/ip_output.c:1.316	Fri Aug 28 06:19:13 2020
+++ src/sys/netinet/ip_output.c	Fri Aug 28 06:22:25 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_output.c,v 1.316 2020/08/28 06:19:13 ozaki-r Exp $	*/
+/*	$NetBSD: ip_output.c,v 1.317 2020/08/28 06:22:25 ozaki-r Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.316 2020/08/28 06:19:13 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.317 2020/08/28 06:22:25 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -252,6 +252,7 @@ ip_output(struct mbuf *m0, struct mbuf *
 	struct psref psref, psref_ia;
 	int bound;
 	bool bind_need_restore = false;
+	const struct sockaddr *sa;
 
 	len = 0;
 
@@ -679,59 +680,59 @@ sendit:
 	}
 	sw_csum = m->m_pkthdr.csum_flags & ~ifp->if_csum_flags_tx;
 
-	/*
-	 * If small enough for mtu of path, or if using TCP segmentation
-	 * offload, can just send directly.
-	 */
-	if (ntohs(ip->ip_len) <= mtu ||
-	(m->m_pkthdr.csum_flags & M_CSUM_TSOv4) != 0) {
-		const struct sockaddr *sa;
+	sa = (m->m_flags & M_MCAST) ? sintocsa(rdst) : sintocsa(dst);
+
+	/* Need to fragment the packet */
+	if (ntohs(ip->ip_len) > mtu &&
+	(m->m_pkthdr.csum_flags & M_CSUM_TSOv4) == 0) {
+		goto fragment;
+	}
 
 #if IFA_STATS
-		if (ia)
-			ia->ia_ifa.ifa_data.ifad_outbytes += ntohs(ip->ip_len);
+	if (ia)
+		ia->ia_ifa.ifa_data.ifad_outbytes += ntohs(ip->ip_len);
 #endif
+	/*
+	 * Always initialize the sum to 0!  Some HW assisted
+	 * checksumming requires this.
+	 */
+	ip->ip_sum = 0;
+
+	if ((m->m_pkthdr.csum_flags & M_CSUM_TSOv4) == 0) {
 		/*
-		 * Always initialize the sum to 0!  Some HW assisted
-		 * checksumming requires this.
+		 * Perform any checksums that the hardware can't do
+		 * for us.
+		 *
+		 * XXX Does any hardware require the {th,uh}_sum
+		 * XXX fields to be 0?
 		 */
-		ip->ip_sum = 0;
-
-		if ((m->m_pkthdr.csum_flags & M_CSUM_TSOv4) == 0) {
-			/*
-			 * Perform any checksums that the hardware can't do
-			 * for us.
-			 *
-			 * XXX Does any hardware require the {th,uh}_sum
-			 * XXX fields to be 0?
-			 */
-			if (sw_csum & M_CSUM_IPv4) {
-KASSERT(IN_NEED_CHECKSUM(ifp, M_CSUM_IPv4));
-ip->ip_sum = in_cksum(m, hlen);
-m->m_pkthdr.csum_flags &= ~M_CSUM_IPv4;
-			}
-			if (sw_csum & (M_CSUM_TCPv4|M_CSUM_UDPv4)) {
-if (IN_NEED_CHECKSUM(ifp,
-sw_csum & (M_CSUM_TCPv4|M_CSUM_UDPv4))) {
-	in_undefer_cksum_tcpudp(m);
-}
-m->m_pkthdr.csum_flags &=
-~(M_CSUM_TCPv4|M_CSUM_UDPv4);
+		if (sw_csum & M_CSUM_IPv4) {
+			KASSERT(IN_NEED_CHECKSUM(ifp, M_CSUM_IPv4));
+			ip->ip_sum = in_cksum(m, hlen);
+			m->m_pkthdr.csum_flags &= ~M_CSUM_IPv4;
+		}
+		if (sw_csum & (M_CSUM_TCPv4|M_CSUM_UDPv4)) {
+			if (IN_NEED_CHECKSUM(ifp,
+			sw_csum & (M_CSUM_TCPv4|M_CSUM_UDPv4))) {
+in_undefer_cksum_tcpudp(m);
 			}
+			m->m_pkthdr.csum_flags &=
+			~(M_CSUM_TCPv4|M_CSUM_UDPv4);
 		}
-
-		sa = (m->m_flags & M_MCAST) ? sintocsa(rdst) : sintocsa(dst);
-		if (__predict_false(sw_csum & M_CSUM_TSOv4)) {
-			/*
-			 * TSO4 is required by a packet, but disabled for
-			 * the interface.
-			 */
-			error = ip_tso_output(ifp, m, sa, rt);
-		} else
-			error = ip_if_output(ifp, m, sa, rt);
-		goto done;
 	}
 
+	/* Send it */
+	if (__predict_false(sw_csum & M_CSUM_TSOv4)) {
+		/*
+		 * TSO4 is required by a packet, but disabled for
+		 * the interface.
+		 */
+		error = ip_tso_output(ifp, m, sa, rt);
+	} else
+		error = ip_if_output(ifp, m, sa, rt);
+	goto done;
+
+fragment:
 	/*
 	 * We can't use HW checksumming if we're about to fragment the packet.
 	 *
@@ -789,9 +790,7 @@ sendit:
 		} else {
 			KASSERT((m->m_pkthdr.csum_flags &
 			(M_CSUM_UDPv4 | M_CSUM_TCPv4)) == 0);
-			error = ip_if_output(ifp, m,
-			(m->m_flags & M_MCAST) ?
-			sintocsa(rdst) : sintocsa(dst), rt);
+			error = ip_if_output(ifp, m, sa, rt);
 		}
 	}
 	if (error == 0) {



CVS commit: src/sys

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

Modified Files:
src/sys/netinet: ip_input.c
src/sys/netinet6: ip6_input.c
src/sys/netipsec: ipsec.c ipsec.h
src/sys/rump/librump/rumpnet: net_stub.c

Log Message:
ipsec: rename ipsec_ip_input to ipsec_ip_input_checkpolicy

Because it just checks if a packet passes security policies.


To generate a diff of this commit:
cvs rdiff -u -r1.394 -r1.395 src/sys/netinet/ip_input.c
cvs rdiff -u -r1.219 -r1.220 src/sys/netinet6/ip6_input.c
cvs rdiff -u -r1.171 -r1.172 src/sys/netipsec/ipsec.c
cvs rdiff -u -r1.90 -r1.91 src/sys/netipsec/ipsec.h
cvs rdiff -u -r1.37 -r1.38 src/sys/rump/librump/rumpnet/net_stub.c

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

Modified files:

Index: src/sys/netinet/ip_input.c
diff -u src/sys/netinet/ip_input.c:1.394 src/sys/netinet/ip_input.c:1.395
--- src/sys/netinet/ip_input.c:1.394	Fri Aug 28 06:19:13 2020
+++ src/sys/netinet/ip_input.c	Fri Aug 28 06:20:44 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_input.c,v 1.394 2020/08/28 06:19:13 ozaki-r Exp $	*/
+/*	$NetBSD: ip_input.c,v 1.395 2020/08/28 06:20:44 ozaki-r Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.394 2020/08/28 06:19:13 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.395 2020/08/28 06:20:44 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -740,7 +740,7 @@ ip_input(struct mbuf *m)
 #ifdef IPSEC
 		/* Check the security policy (SP) for the packet */
 		if (ipsec_used) {
-			if (ipsec_ip_input(m, true) != 0) {
+			if (ipsec_ip_input_checkpolicy(m, true) != 0) {
 IP_STATINC(IP_STAT_IPSECDROP_IN);
 goto out;
 			}
@@ -788,7 +788,7 @@ ours:
 	 */
 	if (ipsec_used &&
 	(inetsw[ip_protox[ip->ip_p]].pr_flags & PR_LASTHDR) != 0) {
-		if (ipsec_ip_input(m, false) != 0) {
+		if (ipsec_ip_input_checkpolicy(m, false) != 0) {
 			IP_STATINC(IP_STAT_IPSECDROP_IN);
 			goto out;
 		}

Index: src/sys/netinet6/ip6_input.c
diff -u src/sys/netinet6/ip6_input.c:1.219 src/sys/netinet6/ip6_input.c:1.220
--- src/sys/netinet6/ip6_input.c:1.219	Fri Aug 28 06:19:13 2020
+++ src/sys/netinet6/ip6_input.c	Fri Aug 28 06:20:44 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6_input.c,v 1.219 2020/08/28 06:19:13 ozaki-r Exp $	*/
+/*	$NetBSD: ip6_input.c,v 1.220 2020/08/28 06:20:44 ozaki-r Exp $	*/
 /*	$KAME: ip6_input.c,v 1.188 2001/03/29 05:34:31 itojun Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.219 2020/08/28 06:19:13 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.220 2020/08/28 06:20:44 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_gateway.h"
@@ -755,7 +755,7 @@ hbhcheck:
 			& PR_LASTHDR) != 0) {
 int error;
 
-error = ipsec_ip_input(m, false);
+error = ipsec_ip_input_checkpolicy(m, false);
 if (error) {
 	IP6_STATINC(IP6_STAT_IPSECDROP_IN);
 	goto bad;

Index: src/sys/netipsec/ipsec.c
diff -u src/sys/netipsec/ipsec.c:1.171 src/sys/netipsec/ipsec.c:1.172
--- src/sys/netipsec/ipsec.c:1.171	Fri Aug 28 06:19:13 2020
+++ src/sys/netipsec/ipsec.c	Fri Aug 28 06:20:44 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: ipsec.c,v 1.171 2020/08/28 06:19:13 ozaki-r Exp $ */
+/* $NetBSD: ipsec.c,v 1.172 2020/08/28 06:20:44 ozaki-r Exp $ */
 /* $FreeBSD: ipsec.c,v 1.2.2.2 2003/07/01 01:38:13 sam Exp $ */
 /* $KAME: ipsec.c,v 1.103 2001/05/24 07:14:18 sakane Exp $ */
 
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ipsec.c,v 1.171 2020/08/28 06:19:13 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ipsec.c,v 1.172 2020/08/28 06:20:44 ozaki-r Exp $");
 
 /*
  * IPsec controller part.
@@ -705,7 +705,7 @@ ipsec4_output(struct mbuf *m, struct inp
 }
 
 int
-ipsec_ip_input(struct mbuf *m, bool forward)
+ipsec_ip_input_checkpolicy(struct mbuf *m, bool forward)
 {
 	struct secpolicy *sp;
 	int error, s;

Index: src/sys/netipsec/ipsec.h
diff -u src/sys/netipsec/ipsec.h:1.90 src/sys/netipsec/ipsec.h:1.91
--- src/sys/netipsec/ipsec.h:1.90	Fri Aug 28 06:19:13 2020
+++ src/sys/netipsec/ipsec.h	Fri Aug 28 06:20:44 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ipsec.h,v 1.90 2020/08/28 06:19:13 ozaki-r Exp $	*/
+/*	$NetBSD: ipsec.h,v 1.91 2020/08/28 06:20:44 ozaki-r Exp $	*/
 /*	$FreeBSD: ipsec.h,v 1.2.4.2 2004/02/14 22:23:23 bms Exp $	*/
 /*	$KAME: ipsec.h,v 1.53 2001/11/20 08:32:38 itojun Exp $	*/
 
@@ -277,7 +277,7 @@ void ipsec_invalpcbcacheall(void);
 struct inpcb;
 int ipsec4_output(struct mbuf *, struct inpcb *, int, u_long *, bool *, bool *, bool *);
 
-int ipsec_ip_input(struct mbuf *, bool);
+int ipsec_ip_input_checkpolicy(struct mbuf *, bool);
 void ipsec_mtu(struct mbuf *, int *);
 #ifdef INET6
 void ipsec6_udp_cksum(struct mbuf *);

Index: src/sys/rump/librump/rumpnet/net_stub.c
diff -u src/sys/rump/librump/rumpnet/net_stub.c:1.37 src/sys/rump/librump/rumpnet/net_stub

CVS commit: src/sys

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

Modified Files:
src/sys/netinet: ip_input.c ip_output.c ip_var.h
src/sys/netinet6: ip6_forward.c ip6_input.c ip6_output.c ip6_var.h
src/sys/netipsec: ipsec.c ipsec.h

Log Message:
inet, inet6: count packets dropped by IPsec

The counters count packets dropped due to security policy checks.


To generate a diff of this commit:
cvs rdiff -u -r1.393 -r1.394 src/sys/netinet/ip_input.c
cvs rdiff -u -r1.315 -r1.316 src/sys/netinet/ip_output.c
cvs rdiff -u -r1.128 -r1.129 src/sys/netinet/ip_var.h
cvs rdiff -u -r1.99 -r1.100 src/sys/netinet6/ip6_forward.c
cvs rdiff -u -r1.218 -r1.219 src/sys/netinet6/ip6_input.c
cvs rdiff -u -r1.223 -r1.224 src/sys/netinet6/ip6_output.c
cvs rdiff -u -r1.84 -r1.85 src/sys/netinet6/ip6_var.h
cvs rdiff -u -r1.170 -r1.171 src/sys/netipsec/ipsec.c
cvs rdiff -u -r1.89 -r1.90 src/sys/netipsec/ipsec.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/netinet/ip_input.c
diff -u src/sys/netinet/ip_input.c:1.393 src/sys/netinet/ip_input.c:1.394
--- src/sys/netinet/ip_input.c:1.393	Wed Nov 13 02:51:22 2019
+++ src/sys/netinet/ip_input.c	Fri Aug 28 06:19:13 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_input.c,v 1.393 2019/11/13 02:51:22 ozaki-r Exp $	*/
+/*	$NetBSD: ip_input.c,v 1.394 2020/08/28 06:19:13 ozaki-r Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.393 2019/11/13 02:51:22 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.394 2020/08/28 06:19:13 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -741,6 +741,7 @@ ip_input(struct mbuf *m)
 		/* Check the security policy (SP) for the packet */
 		if (ipsec_used) {
 			if (ipsec_ip_input(m, true) != 0) {
+IP_STATINC(IP_STAT_IPSECDROP_IN);
 goto out;
 			}
 		}
@@ -788,6 +789,7 @@ ours:
 	if (ipsec_used &&
 	(inetsw[ip_protox[ip->ip_p]].pr_flags & PR_LASTHDR) != 0) {
 		if (ipsec_ip_input(m, false) != 0) {
+			IP_STATINC(IP_STAT_IPSECDROP_IN);
 			goto out;
 		}
 	}

Index: src/sys/netinet/ip_output.c
diff -u src/sys/netinet/ip_output.c:1.315 src/sys/netinet/ip_output.c:1.316
--- src/sys/netinet/ip_output.c:1.315	Fri Dec 27 10:17:56 2019
+++ src/sys/netinet/ip_output.c	Fri Aug 28 06:19:13 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_output.c,v 1.315 2019/12/27 10:17:56 msaitoh Exp $	*/
+/*	$NetBSD: ip_output.c,v 1.316 2020/08/28 06:19:13 ozaki-r Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.315 2019/12/27 10:17:56 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.316 2020/08/28 06:19:13 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -609,10 +609,13 @@ sendit:
 #ifdef IPSEC
 	if (ipsec_used) {
 		bool ipsec_done = false;
+		bool count_drop = false;
 
 		/* Perform IPsec processing, if any. */
 		error = ipsec4_output(m, inp, flags, &mtu, &natt_frag,
-		&ipsec_done);
+		&ipsec_done, &count_drop);
+		if (count_drop)
+			IP_STATINC(IP_STAT_IPSECDROP_OUT);
 		if (error || ipsec_done)
 			goto done;
 	}

Index: src/sys/netinet/ip_var.h
diff -u src/sys/netinet/ip_var.h:1.128 src/sys/netinet/ip_var.h:1.129
--- src/sys/netinet/ip_var.h:1.128	Mon May 13 07:47:59 2019
+++ src/sys/netinet/ip_var.h	Fri Aug 28 06:19:13 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_var.h,v 1.128 2019/05/13 07:47:59 ozaki-r Exp $	*/
+/*	$NetBSD: ip_var.h,v 1.129 2020/08/28 06:19:13 ozaki-r Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1993
@@ -149,8 +149,10 @@ struct ip_pktopts {
 #define	IP_STAT_NOIPSEC		31	/* no match ipsec(4) found */
 #define	IP_STAT_PFILDROP_IN	32	/* dropped by pfil (PFIL_IN) */
 #define	IP_STAT_PFILDROP_OUT	33	/* dropped by pfil (PFIL_OUT) */
+#define	IP_STAT_IPSECDROP_IN	34	/* dropped by IPsec SP check */
+#define	IP_STAT_IPSECDROP_OUT	35	/* dropped by IPsec SP check */
 
-#define	IP_NSTATS		34
+#define	IP_NSTATS		36
 
 #ifdef _KERNEL
 

Index: src/sys/netinet6/ip6_forward.c
diff -u src/sys/netinet6/ip6_forward.c:1.99 src/sys/netinet6/ip6_forward.c:1.100
--- src/sys/netinet6/ip6_forward.c:1.99	Fri Jun 12 11:04:45 2020
+++ src/sys/netinet6/ip6_forward.c	Fri Aug 28 06:19:13 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6_forward.c,v 1.99 2020/06/12 11:04:45 roy Exp $	*/
+/*	$NetBSD: ip6_forward.c,v 1.100 2020/08/28 06:19:13 ozaki-r Exp $	*/
 /*	$KAME: ip6_forward.c,v 1.109 2002/09/11 08:10:17 sakane Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip6_forward.c,v 1.99 2020/06/12 11:04:45 roy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_forward.c,v 1.100 2020/08/28 06:19:13 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_gateway.h"
@@ -192,6 +192,7 @@ ip6_forward(struct mbuf *m, int srcrt)
 			if (error == -EINVAL)
 error = 0;
 			m_freem(m);
+			IP6_STATINC(

CVS commit: src/sys/rump/net/lib/libshmif

2020-02-24 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Tue Feb 25 03:26:18 UTC 2020

Modified Files:
src/sys/rump/net/lib/libshmif: if_shmem.c

Log Message:
shmif: reduce the number of calls of cprng(9)


To generate a diff of this commit:
cvs rdiff -u -r1.80 -r1.81 src/sys/rump/net/lib/libshmif/if_shmem.c

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

Modified files:

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.80 src/sys/rump/net/lib/libshmif/if_shmem.c:1.81
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.80	Tue Feb 25 03:25:36 2020
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Tue Feb 25 03:26:18 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.80 2020/02/25 03:25:36 ozaki-r Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.81 2020/02/25 03:26:18 ozaki-r Exp $	*/
 
 /*
  * Copyright (c) 2009, 2010 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_shmem.c,v 1.80 2020/02/25 03:25:36 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_shmem.c,v 1.81 2020/02/25 03:26:18 ozaki-r Exp $");
 
 #include 
 #include 
@@ -163,16 +163,16 @@ allocif(int unit, struct shmif_sc **scp)
 	uint8_t enaddr[ETHER_ADDR_LEN] = { 0xb2, 0xa0, 0x00, 0x00, 0x00, 0x00 };
 	struct shmif_sc *sc;
 	struct ifnet *ifp;
-	uint32_t randnum;
+	uint64_t randnum;
 	int error;
 
-	randnum = cprng_strong32();
-	memcpy(&enaddr[2], &randnum, sizeof(randnum));
+	randnum = cprng_strong64();
+	memcpy(&enaddr[2], &randnum, 4);
 
 	sc = kmem_zalloc(sizeof(*sc), KM_SLEEP);
 	sc->sc_memfd = -1;
 	sc->sc_unit = unit;
-	sc->sc_uid = cprng_strong64();
+	sc->sc_uid = randnum;
 
 	ifp = &sc->sc_ec.ec_if;
 



CVS commit: src/sys/rump/net/lib/libshmif

2020-02-24 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Tue Feb 25 03:25:36 UTC 2020

Modified Files:
src/sys/rump/net/lib/libshmif: if_shmem.c

Log Message:
shmif: s/sc_uuid/sc_uid/

It's not UUID :-/


To generate a diff of this commit:
cvs rdiff -u -r1.79 -r1.80 src/sys/rump/net/lib/libshmif/if_shmem.c

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

Modified files:

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.79 src/sys/rump/net/lib/libshmif/if_shmem.c:1.80
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.79	Tue Feb 25 03:24:48 2020
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Tue Feb 25 03:25:36 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.79 2020/02/25 03:24:48 ozaki-r Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.80 2020/02/25 03:25:36 ozaki-r Exp $	*/
 
 /*
  * Copyright (c) 2009, 2010 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_shmem.c,v 1.79 2020/02/25 03:24:48 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_shmem.c,v 1.80 2020/02/25 03:25:36 ozaki-r Exp $");
 
 #include 
 #include 
@@ -101,7 +101,7 @@ struct shmif_sc {
 	struct lwp *sc_rcvl;
 	bool sc_dying;
 
-	uint64_t sc_uuid;
+	uint64_t sc_uid;
 };
 
 static void shmif_rcv(void *);
@@ -172,7 +172,7 @@ allocif(int unit, struct shmif_sc **scp)
 	sc = kmem_zalloc(sizeof(*sc), KM_SLEEP);
 	sc->sc_memfd = -1;
 	sc->sc_unit = unit;
-	sc->sc_uuid = cprng_strong64();
+	sc->sc_uid = cprng_strong64();
 
 	ifp = &sc->sc_ec.ec_if;
 
@@ -605,7 +605,7 @@ shmif_snd(struct ifnet *ifp, struct mbuf
 	sp.sp_len = pktsize;
 	sp.sp_sec = tv.tv_sec;
 	sp.sp_usec = tv.tv_usec;
-	sp.sp_sender = sc->sc_uuid;
+	sp.sp_sender = sc->sc_uid;
 
 	bpf_mtap(ifp, m0, BPF_D_OUT);
 
@@ -798,7 +798,7 @@ shmif_rcv(void *arg)
 		 * Test if we want to pass the packet upwards
 		 */
 		eth = mtod(m, struct ether_header *);
-		if (sp.sp_sender == sc->sc_uuid) {
+		if (sp.sp_sender == sc->sc_uid) {
 			passup = false;
 		} else if (memcmp(eth->ether_dhost, CLLADDR(ifp->if_sadl),
 		ETHER_ADDR_LEN) == 0) {



CVS commit: src/sys/rump/net/lib/libshmif

2020-02-24 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Tue Feb 25 03:24:48 UTC 2020

Modified Files:
src/sys/rump/net/lib/libshmif: if_shmem.c

Log Message:
shmif: use cprng_strong64 instead of cprng_fast64 to generate a unique ID

shmif uses random bytes generated by cprng(9) as a unique device ID
between rump kernels to identify packets fed by itself and not receive
them.  So if generated bytes are identical between shmif interfaces on
different rump kernels, shmif may drop incoming packets unintentionally.
This is one cause of recent ATF test failures of IPsec.

Fix it by using cprng_strong64 instead of cprng_fast64.  This is a
workaround and we should also investigate why cprng_fast64 starts
failing on rump kernels, although using cprng_strong64 in initialization
itself is feasible.

Fix PR kern/54897


To generate a diff of this commit:
cvs rdiff -u -r1.78 -r1.79 src/sys/rump/net/lib/libshmif/if_shmem.c

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

Modified files:

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.78 src/sys/rump/net/lib/libshmif/if_shmem.c:1.79
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.78	Thu Feb 20 08:06:15 2020
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Tue Feb 25 03:24:48 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.78 2020/02/20 08:06:15 ozaki-r Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.79 2020/02/25 03:24:48 ozaki-r Exp $	*/
 
 /*
  * Copyright (c) 2009, 2010 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_shmem.c,v 1.78 2020/02/20 08:06:15 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_shmem.c,v 1.79 2020/02/25 03:24:48 ozaki-r Exp $");
 
 #include 
 #include 
@@ -172,7 +172,7 @@ allocif(int unit, struct shmif_sc **scp)
 	sc = kmem_zalloc(sizeof(*sc), KM_SLEEP);
 	sc->sc_memfd = -1;
 	sc->sc_unit = unit;
-	sc->sc_uuid = cprng_fast64();
+	sc->sc_uuid = cprng_strong64();
 
 	ifp = &sc->sc_ec.ec_if;
 



CVS commit: src/sys/rump/net/lib/libshmif

2020-02-20 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Thu Feb 20 08:06:15 UTC 2020

Modified Files:
src/sys/rump/net/lib/libshmif: if_shmem.c

Log Message:
shmif: use cprng_strong32 to generate random bytes for a MAC address

cprng_fast32 sometimes returns indentical bytes, which look
"20:0e:11:33" in a MAC address, on different rump_server instances.
That leads MAC address duplications resulting in a test failure.

Fix it by using cprng_strong32 instead of cprng_fast32.  However
we should rather fix cprng_fast32 (or rump itself) somehow.

The fix mitigates PR kern/54897 but test failures due to other
causes still remain.


To generate a diff of this commit:
cvs rdiff -u -r1.77 -r1.78 src/sys/rump/net/lib/libshmif/if_shmem.c

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

Modified files:

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.77 src/sys/rump/net/lib/libshmif/if_shmem.c:1.78
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.77	Sat Feb  1 22:38:31 2020
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Thu Feb 20 08:06:15 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.77 2020/02/01 22:38:31 thorpej Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.78 2020/02/20 08:06:15 ozaki-r Exp $	*/
 
 /*
  * Copyright (c) 2009, 2010 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_shmem.c,v 1.77 2020/02/01 22:38:31 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_shmem.c,v 1.78 2020/02/20 08:06:15 ozaki-r Exp $");
 
 #include 
 #include 
@@ -166,7 +166,7 @@ allocif(int unit, struct shmif_sc **scp)
 	uint32_t randnum;
 	int error;
 
-	randnum = cprng_fast32();
+	randnum = cprng_strong32();
 	memcpy(&enaddr[2], &randnum, sizeof(randnum));
 
 	sc = kmem_zalloc(sizeof(*sc), KM_SLEEP);



CVS commit: src/tests/net

2020-02-20 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Thu Feb 20 08:02:26 UTC 2020

Modified Files:
src/tests/net: net_common.sh

Log Message:
tests: abort if MAC address duplication found


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/tests/net/net_common.sh

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

Modified files:

Index: src/tests/net/net_common.sh
diff -u src/tests/net/net_common.sh:1.38 src/tests/net/net_common.sh:1.39
--- src/tests/net/net_common.sh:1.38	Thu Feb 20 07:58:19 2020
+++ src/tests/net/net_common.sh	Thu Feb 20 08:02:26 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: net_common.sh,v 1.38 2020/02/20 07:58:19 ozaki-r Exp $
+#	$NetBSD: net_common.sh,v 1.39 2020/02/20 08:02:26 ozaki-r Exp $
 #
 # Copyright (c) 2016 Internet Initiative Japan Inc.
 # All rights reserved.
@@ -183,6 +183,7 @@ CRYPTO_NPF_LIBS="$CRYPTO_LIBS -lrumpvfs 
 _rump_server_socks=./.__socks
 _rump_server_ifaces=./.__ifaces
 _rump_server_buses=./.__buses
+_rump_server_macaddrs=./.__macaddrs
 
 DEBUG_SYSCTL_ENTRIES="net.inet.arp.debug net.inet6.icmp6.nd6_debug \
 net.inet.ipsec.debug"
@@ -318,14 +319,21 @@ rump_server_add_iface()
 	local ifname=$2
 	local bus=$3
 	local backup=$RUMP_SERVER
+	local macaddr=
 
 	export RUMP_SERVER=$sock
 	atf_check -s exit:0 rump.ifconfig $ifname create
 	if [ -n "$bus" ]; then
 		atf_check -s exit:0 rump.ifconfig $ifname linkstr $bus
 	fi
+	macaddr=$(get_macaddr $sock $ifname)
 	export RUMP_SERVER=$backup
 
+	if [ -f $_rump_server_macaddrs ]; then
+		atf_check -s not-exit:0 grep -q $macaddr $_rump_server_macaddrs
+	fi
+	echo $macaddr >> $_rump_server_macaddrs
+
 	echo $sock $ifname >> $_rump_server_ifaces
 	$DEBUG && cat $_rump_server_ifaces
 



CVS commit: src/tests/net

2020-02-19 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Thu Feb 20 07:58:19 UTC 2020

Modified Files:
src/tests/net: net_common.sh

Log Message:
tests: dump stats of an interface before destroying it


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/tests/net/net_common.sh

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

Modified files:

Index: src/tests/net/net_common.sh
diff -u src/tests/net/net_common.sh:1.37 src/tests/net/net_common.sh:1.38
--- src/tests/net/net_common.sh:1.37	Mon Aug 26 04:50:32 2019
+++ src/tests/net/net_common.sh	Thu Feb 20 07:58:19 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: net_common.sh,v 1.37 2019/08/26 04:50:32 ozaki-r Exp $
+#	$NetBSD: net_common.sh,v 1.38 2020/02/20 07:58:19 ozaki-r Exp $
 #
 # Copyright (c) 2016 Internet Initiative Japan Inc.
 # All rights reserved.
@@ -398,6 +398,9 @@ rump_server_destroy_ifaces()
 	while read sock ifname; do
 		export RUMP_SERVER=$sock
 		if rump.ifconfig -l |grep -q $ifname; then
+			if $DEBUG; then
+rump.ifconfig -v $ifname
+			fi
 			atf_check -s exit:0 rump.ifconfig $ifname destroy
 		fi
 		atf_check -s exit:0 -o ignore rump.ifconfig



CVS commit: src/tests/net/ipsec

2020-02-17 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Mon Feb 17 08:46:10 UTC 2020

Modified Files:
src/tests/net/ipsec: t_ipsec_gif.sh t_ipsec_l2tp.sh

Log Message:
tests: add missing ifconfig -w

This change mitigates PR kern/54897.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/tests/net/ipsec/t_ipsec_gif.sh \
src/tests/net/ipsec/t_ipsec_l2tp.sh

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

Modified files:

Index: src/tests/net/ipsec/t_ipsec_gif.sh
diff -u src/tests/net/ipsec/t_ipsec_gif.sh:1.8 src/tests/net/ipsec/t_ipsec_gif.sh:1.9
--- src/tests/net/ipsec/t_ipsec_gif.sh:1.8	Mon Aug 19 03:22:05 2019
+++ src/tests/net/ipsec/t_ipsec_gif.sh	Mon Feb 17 08:46:10 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: t_ipsec_gif.sh,v 1.8 2019/08/19 03:22:05 ozaki-r Exp $
+#	$NetBSD: t_ipsec_gif.sh,v 1.9 2020/02/17 08:46:10 ozaki-r Exp $
 #
 # Copyright (c) 2017 Internet Initiative Japan Inc.
 # All rights reserved.
@@ -59,6 +59,15 @@ make_gif_pktstr()
 	echo "$src > $dst: $proto_cap.+$inner_str"
 }
 
+wait_for_all_dad_completions()
+{
+
+	for sock in $SOCK_LOCAL $SOCK_TUN_LOCAL $SOCK_TUN_REMOTE $SOCK_REMOTE; do
+		export RUMP_SERVER=$sock
+		atf_check -s exit:0 rump.ifconfig -w 10
+	done
+}
+
 test_ipsec4_gif()
 {
 	local mode=$1
@@ -121,8 +130,9 @@ test_ipsec4_gif()
 
 	export RUMP_SERVER=$SOCK_REMOTE
 	atf_check -s exit:0 rump.ifconfig shmif0 $ip_remote/24
-	# Run ifconfig -w 10 just once for optimization
-	atf_check -s exit:0 rump.ifconfig -w 10
+
+	wait_for_all_dad_completions
+
 	atf_check -s exit:0 -o ignore \
 	rump.route -n add -net $subnet_local $ip_gw_remote
 
@@ -273,8 +283,9 @@ test_ipsec6_gif()
 
 	export RUMP_SERVER=$SOCK_REMOTE
 	atf_check -s exit:0 rump.ifconfig shmif0 inet6 $ip_remote
-	# Run ifconfig -w 10 just once for optimization
-	atf_check -s exit:0 rump.ifconfig -w 10
+
+	wait_for_all_dad_completions
+
 	atf_check -s exit:0 -o ignore \
 	rump.route -n add -inet6 -net $subnet_local/64 $ip_gw_remote
 
Index: src/tests/net/ipsec/t_ipsec_l2tp.sh
diff -u src/tests/net/ipsec/t_ipsec_l2tp.sh:1.8 src/tests/net/ipsec/t_ipsec_l2tp.sh:1.9
--- src/tests/net/ipsec/t_ipsec_l2tp.sh:1.8	Mon Aug 19 03:22:05 2019
+++ src/tests/net/ipsec/t_ipsec_l2tp.sh	Mon Feb 17 08:46:10 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: t_ipsec_l2tp.sh,v 1.8 2019/08/19 03:22:05 ozaki-r Exp $
+#	$NetBSD: t_ipsec_l2tp.sh,v 1.9 2020/02/17 08:46:10 ozaki-r Exp $
 #
 # Copyright (c) 2017 Internet Initiative Japan Inc.
 # All rights reserved.
@@ -62,6 +62,15 @@ make_l2tp_pktstr()
 	echo "$src > $dst: $proto_cap.+$proto_str"
 }
 
+wait_for_all_dad_completions()
+{
+
+	for sock in $SOCK_LOCAL $SOCK_TUN_LOCAL $SOCK_TUN_REMOTE $SOCK_REMOTE; do
+		export RUMP_SERVER=$sock
+		atf_check -s exit:0 rump.ifconfig -w 10
+	done
+}
+
 test_ipsec4_l2tp()
 {
 	local mode=$1
@@ -121,8 +130,8 @@ test_ipsec4_l2tp()
 
 	export RUMP_SERVER=$SOCK_REMOTE
 	atf_check -s exit:0 rump.ifconfig shmif0 $ip_remote/24
-	# Run ifconfig -w 10 just once for optimization
-	atf_check -s exit:0 rump.ifconfig -w 10
+
+	wait_for_all_dad_completions
 
 	extract_new_packets $BUS_TUNNEL > $outfile
 
@@ -263,8 +272,8 @@ test_ipsec6_l2tp()
 
 	export RUMP_SERVER=$SOCK_REMOTE
 	atf_check -s exit:0 rump.ifconfig shmif0 inet6 $ip_remote
-	# Run ifconfig -w 10 just once for optimization
-	atf_check -s exit:0 rump.ifconfig -w 10
+
+	wait_for_all_dad_completions
 
 	extract_new_packets $BUS_TUNNEL > $outfile
 



CVS commit: src/sys

2019-05-08 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Thu May  9 05:00:32 UTC 2019

Modified Files:
src/sys/external/bsd/drm2/linux: linux_ww_mutex.c
src/sys/kern: kern_lock.c kern_mutex.c kern_rwlock.c subr_lockdebug.c
src/sys/sys: lockdebug.h

Log Message:
Avoid prepending a timestamp to lock debug outputs on ddb

Lock printer functions (lockops_t#lo_dump) use printf_nolog to print, but
printf_nolog now prepends a timestamp which is unnecessary for ddb:

db{0}> show all locks/t
[Locks tracked through LWPs]
Locks held by an LWP (iperf):
Lock 0 (initialized at soinit)
lock address : 0xedeb84b06080 type : sleep/adaptive
initialized  : 0x806d8c3f
shared holds :  0 exclusive:  1
shares wanted:  0 exclusive: 11
current cpu  :  0 last held:  1
current lwp  : 0xedeb849ff040 last held: 0xedeb7dfdb240
last locked* : 0x806d8335 unlocked : 0x806d8385
[ 79103.0868574] owner field  : 0xedeb7dfdb240 wait/spin:   
 1/0

Fix it by passing a printer function to lo_dump functions, i.e., make the
functions use db_printf on ddb.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/external/bsd/drm2/linux/linux_ww_mutex.c
cvs rdiff -u -r1.162 -r1.163 src/sys/kern/kern_lock.c
cvs rdiff -u -r1.78 -r1.79 src/sys/kern/kern_mutex.c
cvs rdiff -u -r1.53 -r1.54 src/sys/kern/kern_rwlock.c
cvs rdiff -u -r1.69 -r1.70 src/sys/kern/subr_lockdebug.c
cvs rdiff -u -r1.20 -r1.21 src/sys/sys/lockdebug.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/external/bsd/drm2/linux/linux_ww_mutex.c
diff -u src/sys/external/bsd/drm2/linux/linux_ww_mutex.c:1.6 src/sys/external/bsd/drm2/linux/linux_ww_mutex.c:1.7
--- src/sys/external/bsd/drm2/linux/linux_ww_mutex.c:1.6	Tue Apr 16 10:00:04 2019
+++ src/sys/external/bsd/drm2/linux/linux_ww_mutex.c	Thu May  9 05:00:31 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_ww_mutex.c,v 1.6 2019/04/16 10:00:04 mrg Exp $	*/
+/*	$NetBSD: linux_ww_mutex.c,v 1.7 2019/05/09 05:00:31 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_ww_mutex.c,v 1.6 2019/04/16 10:00:04 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_ww_mutex.c,v 1.7 2019/05/09 05:00:31 ozaki-r Exp $");
 
 #include 
 #include 
@@ -123,40 +123,40 @@ ww_acquire_fini(struct ww_acquire_ctx *c
 
 #ifdef LOCKDEBUG
 static void
-ww_dump(const volatile void *cookie)
+ww_dump(const volatile void *cookie, lockop_printer_t pr)
 {
 	const volatile struct ww_mutex *mutex = cookie;
 
-	printf_nolog("%-13s: ", "state");
+	pr("%-13s: ", "state");
 	switch (mutex->wwm_state) {
 	case WW_UNLOCKED:
-		printf_nolog("unlocked\n");
+		pr("unlocked\n");
 		break;
 	case WW_OWNED:
-		printf_nolog("owned by lwp\n");
-		printf_nolog("%-13s: %p\n", "owner", mutex->wwm_u.owner);
-		printf_nolog("%-13s: %s\n", "waiters",
+		pr("owned by lwp\n");
+		pr("%-13s: %p\n", "owner", mutex->wwm_u.owner);
+		pr("%-13s: %s\n", "waiters",
 		cv_has_waiters((void *)(intptr_t)&mutex->wwm_cv)
 			? "yes" : "no");
 		break;
 	case WW_CTX:
-		printf_nolog("owned via ctx\n");
-		printf_nolog("%-13s: %p\n", "context", mutex->wwm_u.ctx);
-		printf_nolog("%-13s: %p\n", "lwp",
+		pr("owned via ctx\n");
+		pr("%-13s: %p\n", "context", mutex->wwm_u.ctx);
+		pr("%-13s: %p\n", "lwp",
 		mutex->wwm_u.ctx->wwx_owner);
-		printf_nolog("%-13s: %s\n", "waiters",
+		pr("%-13s: %s\n", "waiters",
 		cv_has_waiters((void *)(intptr_t)&mutex->wwm_cv)
 			? "yes" : "no");
 		break;
 	case WW_WANTOWN:
-		printf_nolog("owned via ctx\n");
-		printf_nolog("%-13s: %p\n", "context", mutex->wwm_u.ctx);
-		printf_nolog("%-13s: %p\n", "lwp",
+		pr("owned via ctx\n");
+		pr("%-13s: %p\n", "context", mutex->wwm_u.ctx);
+		pr("%-13s: %p\n", "lwp",
 		mutex->wwm_u.ctx->wwx_owner);
-		printf_nolog("%-13s: %s\n", "waiters", "yes (noctx)");
+		pr("%-13s: %s\n", "waiters", "yes (noctx)");
 		break;
 	default:
-		printf_nolog("unknown\n");
+		pr("unknown\n");
 		break;
 	}
 }

Index: src/sys/kern/kern_lock.c
diff -u src/sys/kern/kern_lock.c:1.162 src/sys/kern/kern_lock.c:1.163
--- src/sys/kern/kern_lock.c:1.162	Thu May  9 04:53:52 2019
+++ src/sys/kern/kern_lock.c	Thu May  9 05:00:31 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_lock.c,v 1.162 2019/05/09 04:53:52 ozaki-r Exp $	*/
+/*	$NetBSD: kern_lock.c,v 1.163 2019/05/09 05:00:31 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 2002, 2006, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_lock.c,v 1.162 2019/05/09 04:53:52 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_lock.c,v 1.163 2019/05/09 05:00:31 ozaki-r Exp $");
 
 #include 
 #include 
@@ -117,7 +117,7 @@ do {	\
 #define	_KE

CVS commit: src/sys/kern

2019-05-08 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Thu May  9 04:53:52 UTC 2019

Modified Files:
src/sys/kern: kern_lock.c

Log Message:
Make _kernel_lock_dump static


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

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

Modified files:

Index: src/sys/kern/kern_lock.c
diff -u src/sys/kern/kern_lock.c:1.161 src/sys/kern/kern_lock.c:1.162
--- src/sys/kern/kern_lock.c:1.161	Mon Dec 25 09:13:40 2017
+++ src/sys/kern/kern_lock.c	Thu May  9 04:53:52 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_lock.c,v 1.161 2017/12/25 09:13:40 ozaki-r Exp $	*/
+/*	$NetBSD: kern_lock.c,v 1.162 2019/05/09 04:53:52 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 2002, 2006, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_lock.c,v 1.161 2017/12/25 09:13:40 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_lock.c,v 1.162 2019/05/09 04:53:52 ozaki-r Exp $");
 
 #include 
 #include 
@@ -117,7 +117,7 @@ do {	\
 #define	_KERNEL_LOCK_ASSERT(cond)	/* nothing */
 #endif
 
-void	_kernel_lock_dump(const volatile void *);
+static void	_kernel_lock_dump(const volatile void *);
 
 lockops_t _kernel_lock_ops = {
 	.lo_name = "Kernel lock",
@@ -141,7 +141,7 @@ CTASSERT(CACHE_LINE_SIZE >= sizeof(__cpu
 /*
  * Print debugging information about the kernel lock.
  */
-void
+static void
 _kernel_lock_dump(const volatile void *junk)
 {
 	struct cpu_info *ci = curcpu();



CVS commit: src/sys/kern

2019-05-08 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Thu May  9 04:53:00 UTC 2019

Modified Files:
src/sys/kern: kern_mutex.c

Log Message:
Add missing "static" declaration


To generate a diff of this commit:
cvs rdiff -u -r1.77 -r1.78 src/sys/kern/kern_mutex.c

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

Modified files:

Index: src/sys/kern/kern_mutex.c
diff -u src/sys/kern/kern_mutex.c:1.77 src/sys/kern/kern_mutex.c:1.78
--- src/sys/kern/kern_mutex.c:1.77	Wed Apr 17 02:29:43 2019
+++ src/sys/kern/kern_mutex.c	Thu May  9 04:52:59 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_mutex.c,v 1.77 2019/04/17 02:29:43 ozaki-r Exp $	*/
+/*	$NetBSD: kern_mutex.c,v 1.78 2019/05/09 04:52:59 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 2002, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -40,7 +40,7 @@
 #define	__MUTEX_PRIVATE
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_mutex.c,v 1.77 2019/04/17 02:29:43 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_mutex.c,v 1.78 2019/05/09 04:52:59 ozaki-r Exp $");
 
 #include 
 #include 
@@ -298,7 +298,7 @@ syncobj_t mutex_syncobj = {
  *
  *	Dump the contents of a mutex structure.
  */
-void
+static void
 mutex_dump(const volatile void *cookie)
 {
 	const volatile kmutex_t *mtx = cookie;
@@ -315,7 +315,7 @@ mutex_dump(const volatile void *cookie)
  *	generates a lot of machine code in the DIAGNOSTIC case, so
  *	we ask the compiler to not inline it.
  */
-void __noinline
+static void __noinline
 mutex_abort(const char *func, size_t line, const kmutex_t *mtx, const char *msg)
 {
 



CVS commit: src/sys/arch/arm/sunxi

2019-05-08 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Thu May  9 01:46:37 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sunxi_emac.c

Log Message:
Protect ether_multi list

The list can be racy if NET_MPSAFE is enabled and the driver is executed without
KERNEL_LOCK.

Fix PR 54153


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sys/arch/arm/sunxi/sunxi_emac.c

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

Modified files:

Index: src/sys/arch/arm/sunxi/sunxi_emac.c
diff -u src/sys/arch/arm/sunxi/sunxi_emac.c:1.25 src/sys/arch/arm/sunxi/sunxi_emac.c:1.26
--- src/sys/arch/arm/sunxi/sunxi_emac.c:1.25	Mon Apr 22 14:53:51 2019
+++ src/sys/arch/arm/sunxi/sunxi_emac.c	Thu May  9 01:46:37 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_emac.c,v 1.25 2019/04/22 14:53:51 maya Exp $ */
+/* $NetBSD: sunxi_emac.c,v 1.26 2019/05/09 01:46:37 ozaki-r Exp $ */
 
 /*-
  * Copyright (c) 2016-2017 Jared McNeill 
@@ -33,7 +33,7 @@
 #include "opt_net_mpsafe.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_emac.c,v 1.25 2019/04/22 14:53:51 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_emac.c,v 1.26 2019/05/09 01:46:37 ozaki-r Exp $");
 
 #include 
 #include 
@@ -543,6 +543,7 @@ sunxi_emac_setup_rxfilter(struct sunxi_e
 		hash[0] = hash[1] = ~0;
 	} else {
 		val |= HASH_MULTICAST;
+		ETHER_LOCK(&sc->ec);
 		ETHER_FIRST_MULTI(step, &sc->ec, enm);
 		while (enm != NULL) {
 			crc = ether_crc32_le(enm->enm_addrlo, ETHER_ADDR_LEN);
@@ -553,6 +554,7 @@ sunxi_emac_setup_rxfilter(struct sunxi_e
 			hash[hashreg] |= (1 << hashbit);
 			ETHER_NEXT_MULTI(step, enm);
 		}
+		ETHER_UNLOCK(&sc->ec);
 	}
 
 	/* Write our unicast address */



CVS commit: src/sys/arch/arm/sunxi

2019-05-08 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Wed May  8 09:53:43 UTC 2019

Modified Files:
src/sys/arch/arm/sunxi: sun4i_emac.c

Log Message:
Protect ether_multi list

PR 54153


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/arm/sunxi/sun4i_emac.c

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

Modified files:

Index: src/sys/arch/arm/sunxi/sun4i_emac.c
diff -u src/sys/arch/arm/sunxi/sun4i_emac.c:1.7 src/sys/arch/arm/sunxi/sun4i_emac.c:1.8
--- src/sys/arch/arm/sunxi/sun4i_emac.c:1.7	Mon Apr 22 07:51:16 2019
+++ src/sys/arch/arm/sunxi/sun4i_emac.c	Wed May  8 09:53:43 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sun4i_emac.c,v 1.7 2019/04/22 07:51:16 msaitoh Exp $ */
+/* $NetBSD: sun4i_emac.c,v 1.8 2019/05/08 09:53:43 ozaki-r Exp $ */
 
 /*-
  * Copyright (c) 2013-2017 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 
 
-__KERNEL_RCSID(1, "$NetBSD: sun4i_emac.c,v 1.7 2019/04/22 07:51:16 msaitoh Exp $");
+__KERNEL_RCSID(1, "$NetBSD: sun4i_emac.c,v 1.8 2019/05/08 09:53:43 ozaki-r Exp $");
 
 #include 
 #include 
@@ -864,9 +864,11 @@ sun4i_emac_rx_hash(struct sun4i_emac_sof
 	if ((ifp->if_flags & IFF_PROMISC) == 0) {
 		hash[0] = hash[1] = 0;
 
+		ETHER_LOCK(&sc->sc_ec);
 		ETHER_FIRST_MULTI(step, &sc->sc_ec, enm);
 		while (enm != NULL) {
 			if (memcmp(enm->enm_addrlo, enm->enm_addrhi, ETHER_ADDR_LEN)) {
+ETHER_UNLOCK(&sc->sc_ec);
 /*
  * We must listen to a range of multicast addresses.
  * For now, just accept all multicasts, rather than
@@ -889,6 +891,7 @@ sun4i_emac_rx_hash(struct sun4i_emac_sof
 			hash[crc >> 5] |= __BIT(crc & 31);
 	ETHER_NEXT_MULTI(step, enm);
 		}
+		ETHER_UNLOCK(&sc->sc_ec);
 		ifp->if_flags &= ~IFF_ALLMULTI;
 		rxctl |= EMAC_RX_CTL_MHF;
 	}



CVS commit: src/sys

2019-04-18 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Fri Apr 19 01:52:56 UTC 2019

Modified Files:
src/sys/kern: kern_lwp.c kern_softint.c subr_psref.c
src/sys/rump/kern/lib/libsysproxy: sysproxy.c
src/sys/sys: lwp.h userret.h

Log Message:
Implement a simple psref leak detector

It detects leaks by counting up the number of held psref by an LWP and checking
its zeroness at the end of syscalls and softint handlers.  For the counter, a
unused field of struct lwp is reused.

The detector runs only if DIAGNOSTIC is turned on.


To generate a diff of this commit:
cvs rdiff -u -r1.196 -r1.197 src/sys/kern/kern_lwp.c
cvs rdiff -u -r1.45 -r1.46 src/sys/kern/kern_softint.c
cvs rdiff -u -r1.11 -r1.12 src/sys/kern/subr_psref.c
cvs rdiff -u -r1.5 -r1.6 src/sys/rump/kern/lib/libsysproxy/sysproxy.c
cvs rdiff -u -r1.181 -r1.182 src/sys/sys/lwp.h
cvs rdiff -u -r1.26 -r1.27 src/sys/sys/userret.h

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

Modified files:

Index: src/sys/kern/kern_lwp.c
diff -u src/sys/kern/kern_lwp.c:1.196 src/sys/kern/kern_lwp.c:1.197
--- src/sys/kern/kern_lwp.c:1.196	Fri Mar  1 09:02:03 2019
+++ src/sys/kern/kern_lwp.c	Fri Apr 19 01:52:55 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_lwp.c,v 1.196 2019/03/01 09:02:03 hannken Exp $	*/
+/*	$NetBSD: kern_lwp.c,v 1.197 2019/04/19 01:52:55 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2006, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -211,7 +211,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.196 2019/03/01 09:02:03 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.197 2019/04/19 01:52:55 ozaki-r Exp $");
 
 #include "opt_ddb.h"
 #include "opt_lockdebug.h"
@@ -836,6 +836,7 @@ lwp_create(lwp_t *l1, proc_t *p2, vaddr_
 	l2->l_flag = 0;
 	l2->l_pflag = LP_MPSAFE;
 	TAILQ_INIT(&l2->l_ld_locks);
+	l2->l_psrefs = 0;
 
 	/*
 	 * For vfork, borrow parent's lwpctl context if it exists.

Index: src/sys/kern/kern_softint.c
diff -u src/sys/kern/kern_softint.c:1.45 src/sys/kern/kern_softint.c:1.46
--- src/sys/kern/kern_softint.c:1.45	Thu Dec 28 03:39:48 2017
+++ src/sys/kern/kern_softint.c	Fri Apr 19 01:52:55 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_softint.c,v 1.45 2017/12/28 03:39:48 msaitoh Exp $	*/
+/*	$NetBSD: kern_softint.c,v 1.46 2019/04/19 01:52:55 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008 The NetBSD Foundation, Inc.
@@ -170,7 +170,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_softint.c,v 1.45 2017/12/28 03:39:48 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_softint.c,v 1.46 2019/04/19 01:52:55 ozaki-r Exp $");
 
 #include 
 #include 
@@ -595,6 +595,9 @@ softint_execute(softint_t *si, lwp_t *l,
 		KASSERTMSG(curcpu()->ci_mtx_count == 0,
 		"%s: ci_mtx_count (%d) != 0, sh_func %p\n",
 		__func__, curcpu()->ci_mtx_count, sh->sh_func);
+		/* Diagnostic: check that psrefs have not leaked. */
+		KASSERTMSG(l->l_psrefs == 0, "%s: l_psrefs=%d, sh_func=%p\n",
+		__func__, l->l_psrefs, sh->sh_func);
 
 		(void)splhigh();
 		KASSERT((sh->sh_flags & SOFTINT_ACTIVE) != 0);

Index: src/sys/kern/subr_psref.c
diff -u src/sys/kern/subr_psref.c:1.11 src/sys/kern/subr_psref.c:1.12
--- src/sys/kern/subr_psref.c:1.11	Thu Feb  1 03:17:00 2018
+++ src/sys/kern/subr_psref.c	Fri Apr 19 01:52:55 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_psref.c,v 1.11 2018/02/01 03:17:00 ozaki-r Exp $	*/
+/*	$NetBSD: subr_psref.c,v 1.12 2019/04/19 01:52:55 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: subr_psref.c,v 1.11 2018/02/01 03:17:00 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_psref.c,v 1.12 2019/04/19 01:52:55 ozaki-r Exp $");
 
 #include 
 #include 
@@ -278,6 +278,10 @@ psref_acquire(struct psref *psref, const
 	/* Release the CPU list and restore interrupts.  */
 	percpu_putref(class->prc_percpu);
 	splx(s);
+
+#ifdef DIAGNOSTIC
+	curlwp->l_psrefs++;
+#endif
 }
 
 /*
@@ -332,6 +336,11 @@ psref_release(struct psref *psref, const
 	percpu_putref(class->prc_percpu);
 	splx(s);
 
+#ifdef DIAGNOSTIC
+	KASSERT(curlwp->l_psrefs > 0);
+	curlwp->l_psrefs--;
+#endif
+
 	/* If someone is waiting for users to drain, notify 'em.  */
 	if (__predict_false(target->prt_draining))
 		cv_broadcast(&class->prc_cv);
@@ -388,6 +397,10 @@ psref_copy(struct psref *pto, const stru
 	/* Release the CPU list and restore interrupts.  */
 	percpu_putref(class->prc_percpu);
 	splx(s);
+
+#ifdef DIAGNOSTIC
+	curlwp->l_psrefs++;
+#endif
 }
 
 /*

Index: src/sys/rump/kern/lib/libsysproxy/sysproxy.c
diff -u src/sys/rump/kern/lib/libsysproxy/sysproxy.c:1.5 src/sys/rump/kern/lib/libsysproxy/sysproxy.c:1.6
--- src/sys/rump/kern/lib/libsysproxy/sysproxy.c:1.5	Thu Apr 18 08:31:44 2019
+++ src/sys/rump/kern/lib/libsysproxy/sysproxy.c	Fri Apr 19 01:52:55 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysproxy.c,v 1.5 2019/04/18 08:31:44 ozaki-r Exp $	*/
+/*	$NetBSD: sysproxy.c,v 1.6 2019

CVS commit: src/sys/rump/kern/lib/libsysproxy

2019-04-18 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Thu Apr 18 08:31:44 UTC 2019

Modified Files:
src/sys/rump/kern/lib/libsysproxy: sysproxy.c

Log Message:
rump: add missing sanity checks at the end of syscalls


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/rump/kern/lib/libsysproxy/sysproxy.c

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

Modified files:

Index: src/sys/rump/kern/lib/libsysproxy/sysproxy.c
diff -u src/sys/rump/kern/lib/libsysproxy/sysproxy.c:1.4 src/sys/rump/kern/lib/libsysproxy/sysproxy.c:1.5
--- src/sys/rump/kern/lib/libsysproxy/sysproxy.c:1.4	Tue Jan 26 23:12:17 2016
+++ src/sys/rump/kern/lib/libsysproxy/sysproxy.c	Thu Apr 18 08:31:44 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysproxy.c,v 1.4 2016/01/26 23:12:17 pooka Exp $	*/
+/*	$NetBSD: sysproxy.c,v 1.5 2019/04/18 08:31:44 ozaki-r Exp $	*/
 
 /*
  * Copyright (c) 2010, 2011 Antti Kantee.  All Rights Reserved.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysproxy.c,v 1.4 2016/01/26 23:12:17 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysproxy.c,v 1.5 2019/04/18 08:31:44 ozaki-r Exp $");
 
 #include 
 #include 
@@ -35,6 +35,7 @@ __KERNEL_RCSID(0, "$NetBSD: sysproxy.c,v
 #include 
 #include 
 #include 
+#include 
 
 #define _RUMP_SYSPROXY
 #include 
@@ -73,6 +74,10 @@ hyp_syscall(int num, void *arg, long *re
 	retval[0] = regrv[0];
 	retval[1] = regrv[1];
 
+	/* Sanity checks (from mi_userret) */
+	LOCKDEBUG_BARRIER(NULL, 0);
+	KASSERT(l->l_nopreempt == 0);
+
 	return rv;
 }
 



CVS commit: src/tests/net/route

2019-04-18 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Thu Apr 18 07:56:54 UTC 2019

Modified Files:
src/tests/net/route: t_change.sh

Log Message:
tests: dump kernel stats on cleanup


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/tests/net/route/t_change.sh

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

Modified files:

Index: src/tests/net/route/t_change.sh
diff -u src/tests/net/route/t_change.sh:1.12 src/tests/net/route/t_change.sh:1.13
--- src/tests/net/route/t_change.sh:1.12	Mon Dec 18 04:11:46 2017
+++ src/tests/net/route/t_change.sh	Thu Apr 18 07:56:54 2019
@@ -1,4 +1,4 @@
-#	$NetBSD: t_change.sh,v 1.12 2017/12/18 04:11:46 ozaki-r Exp $
+#	$NetBSD: t_change.sh,v 1.13 2019/04/18 07:56:54 ozaki-r Exp $
 #
 # Copyright (c) 2011 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -32,6 +32,14 @@ export RUMP_SERVER=unix://commsock
 
 DEBUG=${DEBUG:-false}
 
+route_cleanup_common()
+{
+
+	$DEBUG && dump_kernel_stats unix://commsock
+	$DEBUG && extract_rump_server_core
+	env RUMP_SERVER=unix://commsock rump.halt
+}
+
 atf_test_case route_change_reject2blackhole cleanup
 route_change_reject2blackhole_head()
 {
@@ -58,7 +66,7 @@ route_change_reject2blackhole_body()
 route_change_reject2blackhole_cleanup()
 {
 
-	env RUMP_SERVER=unix://commsock rump.halt
+	route_cleanup_common
 }
 
 atf_test_case route_change_gateway cleanup
@@ -91,7 +99,7 @@ route_change_gateway_body()
 route_change_gateway_cleanup()
 {
 
-	env RUMP_SERVER=unix://commsock rump.halt
+	route_cleanup_common
 }
 
 atf_test_case route_change_ifa cleanup
@@ -156,7 +164,7 @@ destination: 192.168.0.0
 route_change_ifa_cleanup()
 {
 
-	env RUMP_SERVER=unix://commsock rump.halt
+	route_cleanup_common
 }
 
 atf_test_case route_change_ifp cleanup
@@ -223,7 +231,7 @@ destination: 192.168.0.0
 route_change_ifp_cleanup()
 {
 
-	env RUMP_SERVER=unix://commsock rump.halt
+	route_cleanup_common
 }
 
 atf_test_case route_change_ifp_ifa cleanup
@@ -290,7 +298,7 @@ destination: 192.168.0.0
 route_change_ifp_ifa_cleanup()
 {
 
-	env RUMP_SERVER=unix://commsock rump.halt
+	route_cleanup_common
 }
 
 atf_test_case route_change_flags cleanup
@@ -326,7 +334,7 @@ route_change_flags_body()
 route_change_flags_cleanup()
 {
 
-	env RUMP_SERVER=unix://commsock rump.halt
+	route_cleanup_common
 }
 
 atf_test_case route_change_default_flags cleanup
@@ -361,7 +369,7 @@ route_change_default_flags_body()
 route_change_default_flags_cleanup()
 {
 
-	env RUMP_SERVER=unix://commsock rump.halt
+	route_cleanup_common
 }
 
 atf_init_test_cases()



CVS commit: src/tests/net

2019-04-18 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Thu Apr 18 07:56:05 UTC 2019

Modified Files:
src/tests/net: net_common.sh

Log Message:
tests: make utility funtions easy to use for tests that don't use the framework


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/tests/net/net_common.sh

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

Modified files:

Index: src/tests/net/net_common.sh
diff -u src/tests/net/net_common.sh:1.29 src/tests/net/net_common.sh:1.30
--- src/tests/net/net_common.sh:1.29	Thu Jan 17 02:49:11 2019
+++ src/tests/net/net_common.sh	Thu Apr 18 07:56:04 2019
@@ -1,4 +1,4 @@
-#	$NetBSD: net_common.sh,v 1.29 2019/01/17 02:49:11 knakahara Exp $
+#	$NetBSD: net_common.sh,v 1.30 2019/04/18 07:56:04 ozaki-r Exp $
 #
 # Copyright (c) 2016 Internet Initiative Japan Inc.
 # All rights reserved.
@@ -384,29 +384,42 @@ rump_server_halt_servers()
 	return 0
 }
 
+extract_rump_server_core()
+{
+
+	if [ -f rump_server.core ]; then
+		gdb -ex bt /usr/bin/rump_server rump_server.core
+		strings rump_server.core |grep panic
+	fi
+}
+
+dump_kernel_stats()
+{
+	local sock=$1
+
+	echo "### Dumping $sock"
+	export RUMP_SERVER=$sock
+	rump.ifconfig -av
+	rump.netstat -nr
+	# XXX still need hijacking
+	$HIJACKING rump.netstat -nai
+	rump.arp -na
+	rump.ndp -na
+	$HIJACKING ifmcstat
+	$HIJACKING dmesg
+}
+
 rump_server_dump_servers()
 {
 	local backup=$RUMP_SERVER
 
 	$DEBUG && cat $_rump_server_socks
 	for sock in $(cat $_rump_server_socks); do
-		echo "### Dumping $sock"
-		export RUMP_SERVER=$sock
-		rump.ifconfig -av
-		rump.netstat -nr
-		# XXX still need hijacking
-		$HIJACKING rump.netstat -nai
-		rump.arp -na
-		rump.ndp -na
-		$HIJACKING ifmcstat
-		$HIJACKING dmesg
+		dump_kernel_stats $sock
 	done
 	export RUMP_SERVER=$backup
 
-	if [ -f rump_server.core ]; then
-		gdb -ex bt /usr/bin/rump_server rump_server.core
-		strings rump_server.core |grep panic
-	fi
+	extract_rump_server_core
 	return 0
 }
 



CVS commit: src/sys/kern

2019-04-16 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Wed Apr 17 02:29:43 UTC 2019

Modified Files:
src/sys/kern: kern_mutex.c kern_rwlock.c

Log Message:
Don't check pserialize_not_in_read_section after panic

It can cause a false positive assertion failure.


To generate a diff of this commit:
cvs rdiff -u -r1.76 -r1.77 src/sys/kern/kern_mutex.c
cvs rdiff -u -r1.52 -r1.53 src/sys/kern/kern_rwlock.c

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

Modified files:

Index: src/sys/kern/kern_mutex.c
diff -u src/sys/kern/kern_mutex.c:1.76 src/sys/kern/kern_mutex.c:1.77
--- src/sys/kern/kern_mutex.c:1.76	Sun Mar 10 12:49:48 2019
+++ src/sys/kern/kern_mutex.c	Wed Apr 17 02:29:43 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_mutex.c,v 1.76 2019/03/10 12:49:48 skrll Exp $	*/
+/*	$NetBSD: kern_mutex.c,v 1.77 2019/04/17 02:29:43 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 2002, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -40,7 +40,7 @@
 #define	__MUTEX_PRIVATE
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_mutex.c,v 1.76 2019/03/10 12:49:48 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_mutex.c,v 1.77 2019/04/17 02:29:43 ozaki-r Exp $");
 
 #include 
 #include 
@@ -524,9 +524,9 @@ mutex_vector_enter(kmutex_t *mtx)
 	MUTEX_ASSERT(mtx, curthread != 0);
 	MUTEX_ASSERT(mtx, !cpu_intr_p());
 	MUTEX_WANTLOCK(mtx);
-	KDASSERT(pserialize_not_in_read_section());
 
 	if (panicstr == NULL) {
+		KDASSERT(pserialize_not_in_read_section());
 		LOCKDEBUG_BARRIER(&kernel_lock, 1);
 	}
 

Index: src/sys/kern/kern_rwlock.c
diff -u src/sys/kern/kern_rwlock.c:1.52 src/sys/kern/kern_rwlock.c:1.53
--- src/sys/kern/kern_rwlock.c:1.52	Fri Aug 31 01:23:57 2018
+++ src/sys/kern/kern_rwlock.c	Wed Apr 17 02:29:43 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_rwlock.c,v 1.52 2018/08/31 01:23:57 ozaki-r Exp $	*/
+/*	$NetBSD: kern_rwlock.c,v 1.53 2019/04/17 02:29:43 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 2002, 2006, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_rwlock.c,v 1.52 2018/08/31 01:23:57 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_rwlock.c,v 1.53 2019/04/17 02:29:43 ozaki-r Exp $");
 
 #define	__RWLOCK_PRIVATE
 
@@ -290,9 +290,9 @@ rw_vector_enter(krwlock_t *rw, const krw
 	RW_ASSERT(rw, !cpu_intr_p());
 	RW_ASSERT(rw, curthread != 0);
 	RW_WANTLOCK(rw, op);
-	KDASSERT(pserialize_not_in_read_section());
 
 	if (panicstr == NULL) {
+		KDASSERT(pserialize_not_in_read_section());
 		LOCKDEBUG_BARRIER(&kernel_lock, 1);
 	}
 



CVS commit: src/sys/dev/ic

2019-04-14 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Mon Apr 15 06:00:04 UTC 2019

Modified Files:
src/sys/dev/ic: dwc_gmac.c

Log Message:
Protect ether_multi list

Fix this driver because it can set IFEF_MPSAFE.


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 src/sys/dev/ic/dwc_gmac.c

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

Modified files:

Index: src/sys/dev/ic/dwc_gmac.c
diff -u src/sys/dev/ic/dwc_gmac.c:1.58 src/sys/dev/ic/dwc_gmac.c:1.59
--- src/sys/dev/ic/dwc_gmac.c:1.58	Thu Mar  7 14:02:16 2019
+++ src/sys/dev/ic/dwc_gmac.c	Mon Apr 15 06:00:04 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: dwc_gmac.c,v 1.58 2019/03/07 14:02:16 msaitoh Exp $ */
+/* $NetBSD: dwc_gmac.c,v 1.59 2019/04/15 06:00:04 ozaki-r Exp $ */
 
 /*-
  * Copyright (c) 2013, 2014 The NetBSD Foundation, Inc.
@@ -41,7 +41,7 @@
 
 #include 
 
-__KERNEL_RCSID(1, "$NetBSD: dwc_gmac.c,v 1.58 2019/03/07 14:02:16 msaitoh Exp $");
+__KERNEL_RCSID(1, "$NetBSD: dwc_gmac.c,v 1.59 2019/04/15 06:00:04 ozaki-r Exp $");
 
 /* #define	DWC_GMAC_DEBUG	1 */
 
@@ -1343,6 +1343,7 @@ dwc_gmac_setmulti(struct dwc_gmac_softc 
 	struct ifnet * const ifp = &sc->sc_ec.ec_if;
 	struct ether_multi *enm;
 	struct ether_multistep step;
+	struct ethercom *ec = &sc->sc_ec;
 	uint32_t hashes[2] = { 0, 0 };
 	uint32_t ffilt, h;
 	int mcnt;
@@ -1362,11 +1363,13 @@ dwc_gmac_setmulti(struct dwc_gmac_softc 
 	bus_space_write_4(sc->sc_bst, sc->sc_bsh, AWIN_GMAC_MAC_HTLOW, 0);
 	bus_space_write_4(sc->sc_bst, sc->sc_bsh, AWIN_GMAC_MAC_HTHIGH, 0);
 
-	ETHER_FIRST_MULTI(step, &sc->sc_ec, enm);
+	ETHER_LOCK(ec);
+	ETHER_FIRST_MULTI(step, ec, enm);
 	mcnt = 0;
 	while (enm != NULL) {
 		if (memcmp(enm->enm_addrlo, enm->enm_addrhi,
 		ETHER_ADDR_LEN) != 0) {
+			ETHER_UNLOCK(ec);
 			ffilt |= AWIN_GMAC_MAC_FFILT_PM;
 			ifp->if_flags |= IFF_ALLMULTI;
 			goto special_filter;
@@ -1380,6 +1383,7 @@ dwc_gmac_setmulti(struct dwc_gmac_softc 
 		mcnt++;
 		ETHER_NEXT_MULTI(step, enm);
 	}
+	ETHER_UNLOCK(ec);
 
 	if (mcnt)
 		ffilt |= AWIN_GMAC_MAC_FFILT_HMC;



CVS commit: src/doc

2019-03-26 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Wed Mar 27 06:56:38 UTC 2019

Modified Files:
src/doc: TODO.smpnet

Log Message:
Add another known issue (if_flags)


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

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

Modified files:

Index: src/doc/TODO.smpnet
diff -u src/doc/TODO.smpnet:1.28 src/doc/TODO.smpnet:1.29
--- src/doc/TODO.smpnet:1.28	Tue Mar 26 05:17:17 2019
+++ src/doc/TODO.smpnet	Wed Mar 27 06:56:37 2019
@@ -1,4 +1,4 @@
-$NetBSD: TODO.smpnet,v 1.28 2019/03/26 05:17:17 ozaki-r Exp $
+$NetBSD: TODO.smpnet,v 1.29 2019/03/27 06:56:37 ozaki-r Exp $
 
 MP-safe components
 ==
@@ -229,3 +229,24 @@ One solution of the issue is to reorder 
 first register an address to the hash table then create its routes.  Another
 solution is to use the routing table for the to-self check instead of using the
 global hash table, like IPv6.
+
+if_flags
+
+
+To avoid data race on if_flags it should be protected by a lock (currently it's
+IFNET_LOCK).  Thus, if_flags should not be accessed on packet processing to
+avoid performance degradation by lock contentions.  Traditionally IFF_RUNNING,
+IFF_UP and IFF_OACTIVE flags of if_flags are checked on packet processing.  If
+you make a driver MP-safe you must remove such checks.
+
+IFF_ALLMULTI can be set/unset via if_mcast_op.  To protect updates of the flag,
+we had added IFNET_LOCK around if_mcast_op.  However that was not a good
+approach because if_mcast_op is typically called in the middle of a call path
+and holding IFNET_LOCK such places is problematic.  Actually a deadlock is
+observed.  Probably we should remove IFNET_LOCK and manage IFF_ALLMULTI
+somewhere other than if_flags, for example ethercom or driver itself (or a
+common driver framework once it appears).  Such a change is feasible because
+IFF_ALLMULTI is only set/unset by a driver and not accessed from any common
+components such as network protocols.
+
+Also IFF_PROMISC is checked in ether_input and we should get rid of it somehow.



CVS commit: src/doc

2019-03-25 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Tue Mar 26 05:17:17 UTC 2019

Modified Files:
src/doc: TODO.smpnet

Log Message:
Add another known issue


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

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

Modified files:

Index: src/doc/TODO.smpnet
diff -u src/doc/TODO.smpnet:1.27 src/doc/TODO.smpnet:1.28
--- src/doc/TODO.smpnet:1.27	Mon Jan 21 02:28:25 2019
+++ src/doc/TODO.smpnet	Tue Mar 26 05:17:17 2019
@@ -1,4 +1,4 @@
-$NetBSD: TODO.smpnet,v 1.27 2019/01/21 02:28:25 pgoyette Exp $
+$NetBSD: TODO.smpnet,v 1.28 2019/03/26 05:17:17 ozaki-r Exp $
 
 MP-safe components
 ==
@@ -203,3 +203,29 @@ Makefile:
 	CPPFLAGS+=	NET_MPSAFE
 
 Failure to do this may result in unpredictable behavior.
+
+IPv4 address initialization atomicity
+-
+
+An IPv4 address is referenced by several data structures: an associated
+interface, its local route, a connected route (if necessary), the global list,
+the global hash table, etc.  These data structures are not updated atomically,
+i.e., there can be inconsistent states on an IPv4 address in the kernel during
+the initialization of an IPv4 address.
+
+One known failure of the issue is that incoming packets destinating to an
+initializing address can loop in the network stack in a short period of time.
+The address initialization creates an local route first and then registers an
+initializing address to the global hash table that is used to decide if an
+incoming packet destinates to the host by checking the destination of the packet
+is registered to the hash table.  So, if the host allows forwaring, an incoming
+packet can match on a local route of an initializing address at ip_output while
+it fails the to-self check described above at ip_input.  Because a matched local
+route points a loopback interface as its destination interface, an incoming
+packet sends to the network stack (ip_input) again, which results in looping.
+The loop stops once an initializing address is registered to the hash table.
+
+One solution of the issue is to reorder the address initialization instructions,
+first register an address to the hash table then create its routes.  Another
+solution is to use the routing table for the to-self check instead of using the
+global hash table, like IPv6.



CVS commit: src/sys/netinet

2019-03-14 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Thu Mar 14 07:05:07 UTC 2019

Modified Files:
src/sys/netinet: ip_carp.c

Log Message:
carp: don't skip pserialize_read_enter and ifa_release


To generate a diff of this commit:
cvs rdiff -u -r1.101 -r1.102 src/sys/netinet/ip_carp.c

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

Modified files:

Index: src/sys/netinet/ip_carp.c
diff -u src/sys/netinet/ip_carp.c:1.101 src/sys/netinet/ip_carp.c:1.102
--- src/sys/netinet/ip_carp.c:1.101	Sat Dec 22 14:28:57 2018
+++ src/sys/netinet/ip_carp.c	Thu Mar 14 07:05:07 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_carp.c,v 1.101 2018/12/22 14:28:57 maxv Exp $	*/
+/*	$NetBSD: ip_carp.c,v 1.102 2019/03/14 07:05:07 ozaki-r Exp $	*/
 /*	$OpenBSD: ip_carp.c,v 1.113 2005/11/04 08:11:54 mcbride Exp $	*/
 
 /*
@@ -33,7 +33,7 @@
 #endif
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip_carp.c,v 1.101 2018/12/22 14:28:57 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_carp.c,v 1.102 2019/03/14 07:05:07 ozaki-r Exp $");
 
 /*
  * TODO:
@@ -410,7 +410,7 @@ carp_setroute(struct carp_softc *sc, int
 ifatoia(ifa), CARP_COUNT_MASTER);
 if ((cmd == RTM_ADD && count != 1) ||
 (cmd == RTM_DELETE && count != 0))
-	continue;
+	goto next;
 			}
 
 			/* Remove the existing host route, if any */
@@ -485,6 +485,7 @@ carp_setroute(struct carp_softc *sc, int
 		default:
 			break;
 		}
+	next:
 		s = pserialize_read_enter();
 		ifa_release(ifa, &psref);
 	}



CVS commit: src/sys/net

2019-03-10 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Mon Mar 11 03:00:41 UTC 2019

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

Log Message:
Add missing ifa_release on error paths


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

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

Modified files:

Index: src/sys/net/route.c
diff -u src/sys/net/route.c:1.216 src/sys/net/route.c:1.217
--- src/sys/net/route.c:1.216	Tue Oct 30 05:56:02 2018
+++ src/sys/net/route.c	Mon Mar 11 03:00:41 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: route.c,v 1.216 2018/10/30 05:56:02 ozaki-r Exp $	*/
+/*	$NetBSD: route.c,v 1.217 2019/03/11 03:00:41 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -97,7 +97,7 @@
 #endif
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.216 2018/10/30 05:56:02 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.217 2019/03/11 03:00:41 ozaki-r Exp $");
 
 #include 
 #ifdef RTFLUSH_DEBUG
@@ -1504,6 +1504,8 @@ rt_update(struct rtentry *rt, struct rt_
 		}
 		if (new_ifa == NULL)
 			ifa_release(ifa, &psref_ifa);
+		/* To avoid ifa_release below */
+		ifa = NULL;
 	}
 	ifa_release(new_ifa, &psref_new_ifa);
 	if (new_ifp && rt->rt_ifp != new_ifp && !if_is_deactivated(new_ifp)) {
@@ -1525,6 +1527,7 @@ rt_update(struct rtentry *rt, struct rt_
 	(void)ifp_changed; /* XXX gcc */
 #endif
 out:
+	ifa_release(ifa, &psref_ifa);
 	if_put(new_ifp, &psref_new_ifp);
 	if_put(ifp, &psref_ifp);
 



CVS commit: src/sys/net

2019-02-26 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Wed Feb 27 04:03:06 UTC 2019

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

Log Message:
Protect sysctl_rtable with KERNEL_LOCK and softnet_lock

In the function the routing table could be accessed without any locks, which was
unsafe.  Actually, on netbsd-7, a kernel panic happened(*).  The situation of
locking hasn't changed since netbsd-7 so we still need to hold the big locks on
-current (and netbsd-8) too.

Note that if NET_MPSAFE is enabled, the routing table is protected by its own
lock and we don't need the locks.

Reported and tested on netbsd-7 by sborrill@

(*) http://mail-index.netbsd.org/tech-net/2018/11/08/msg007153.html


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

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

Modified files:

Index: src/sys/net/rtsock.c
diff -u src/sys/net/rtsock.c:1.246 src/sys/net/rtsock.c:1.247
--- src/sys/net/rtsock.c:1.246	Tue Jan 29 09:28:51 2019
+++ src/sys/net/rtsock.c	Wed Feb 27 04:03:06 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtsock.c,v 1.246 2019/01/29 09:28:51 pgoyette Exp $	*/
+/*	$NetBSD: rtsock.c,v 1.247 2019/02/27 04:03:06 ozaki-r Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.246 2019/01/29 09:28:51 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.247 2019/02/27 04:03:06 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -432,6 +432,7 @@ again:
 	w.w_needed = 0 - w.w_given;
 	w.w_where = where;
 
+	SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE();
 	s = splsoftnet();
 	switch (w.w_op) {
 
@@ -478,6 +479,7 @@ again:
 		break;
 	}
 	splx(s);
+	SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE();
 
 	/* check to see if we couldn't allocate memory with NOWAIT */
 	if (error == ENOBUFS && w.w_tmem == 0 && w.w_tmemneeded)



CVS commit: src/tests/net/if_vlan

2018-12-10 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Tue Dec 11 03:47:51 UTC 2018

Modified Files:
src/tests/net/if_vlan: t_vlan.sh

Log Message:
tests: add missing $af


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/tests/net/if_vlan/t_vlan.sh

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

Modified files:

Index: src/tests/net/if_vlan/t_vlan.sh
diff -u src/tests/net/if_vlan/t_vlan.sh:1.14 src/tests/net/if_vlan/t_vlan.sh:1.15
--- src/tests/net/if_vlan/t_vlan.sh:1.14	Fri Dec  7 09:29:01 2018
+++ src/tests/net/if_vlan/t_vlan.sh	Tue Dec 11 03:47:51 2018
@@ -1,4 +1,4 @@
-#	$NetBSD: t_vlan.sh,v 1.14 2018/12/07 09:29:01 ozaki-r Exp $
+#	$NetBSD: t_vlan.sh,v 1.15 2018/12/11 03:47:51 ozaki-r Exp $
 #
 # Copyright (c) 2016 Internet Initiative Japan Inc.
 # All rights reserved.
@@ -376,7 +376,7 @@ vlan_vlanid_body_common()
 
 	$atf_ifconfig vlan0 -vlanif
 	atf_check -s not-exit:0 -e match:"Invalid argument" \
-	rump.ifconfig vlan0 $local0/$prefix
+	rump.ifconfig vlan0 $af $local0/$prefix
 
 	export RUMP_SERVER=$SOCK_LOCAL
 	$atf_ifconfig vlan0 vlan 10 vlanif shmif0



CVS commit: src/tests/net/if_vlan

2018-12-07 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Fri Dec  7 09:29:01 UTC 2018

Modified Files:
src/tests/net/if_vlan: t_vlan.sh

Log Message:
tests: check error messages strictly


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/tests/net/if_vlan/t_vlan.sh

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

Modified files:

Index: src/tests/net/if_vlan/t_vlan.sh
diff -u src/tests/net/if_vlan/t_vlan.sh:1.13 src/tests/net/if_vlan/t_vlan.sh:1.14
--- src/tests/net/if_vlan/t_vlan.sh:1.13	Fri Dec  7 09:28:31 2018
+++ src/tests/net/if_vlan/t_vlan.sh	Fri Dec  7 09:29:01 2018
@@ -1,4 +1,4 @@
-#	$NetBSD: t_vlan.sh,v 1.13 2018/12/07 09:28:31 ozaki-r Exp $
+#	$NetBSD: t_vlan.sh,v 1.14 2018/12/07 09:29:01 ozaki-r Exp $
 #
 # Copyright (c) 2016 Internet Initiative Japan Inc.
 # All rights reserved.
@@ -342,7 +342,7 @@ vlan_vlanid_body_common()
 	$atf_ifconfig vlan0 create
 
 	export RUMP_SERVER=$SOCK_LOCAL
-	atf_check -s not-exit:0 -e ignore\
+	atf_check -s not-exit:0 -e match:"^usage: rump.ifconfig" \
 	rump.ifconfig vlan0 vlan -1 vlanif shmif0
 
 	# $config_and_ping 0 # reserved vlan id
@@ -368,14 +368,14 @@ vlan_vlanid_body_common()
 	done
 
 	$atf_ifconfig vlan0 vlan 1 vlanif shmif0
-	atf_check -s not-exit:0 -e ignore \
+	atf_check -s not-exit:0 -e match:"SIOCSETVLAN: Device busy" \
 	rump.ifconfig vlan0 vlan 2 vlanif shmif0
 
-	atf_check -s not-exit:0 -e ignore \
+	atf_check -s not-exit:0 -e match:"SIOCSETVLAN: Device busy" \
 	rump.ifconfig vlan0 vlan 1 vlanif shmif1
 
 	$atf_ifconfig vlan0 -vlanif
-	atf_check -s not-exit:0 -e ignore \
+	atf_check -s not-exit:0 -e match:"Invalid argument" \
 	rump.ifconfig vlan0 $local0/$prefix
 
 	export RUMP_SERVER=$SOCK_LOCAL
@@ -469,8 +469,8 @@ vlan_configs_body_common()
 	$atf_ifconfig vlan0 -vlanif shmif0
 
 	$atf_ifconfig vlan0 vlan 10 vlanif shmif0
-	atf_check -s exit:0 -e ignore rump.ifconfig vlan0 -vlanif shmif1
-	atf_check -s exit:0 -e ignore rump.ifconfig vlan0 -vlanif shmif2
+	atf_check -s exit:0 rump.ifconfig vlan0 -vlanif shmif1
+	atf_check -s exit:0 rump.ifconfig vlan0 -vlanif shmif2
 
 	$atf_ifconfig vlan0 -vlanif
 
@@ -659,7 +659,8 @@ vlan_multicast_body_common()
 	atf_check -s exit:0 -o not-match:"$eth_mcaddr" $HIJACKING ifmcstat
 
 	# delete a non-existing address
-	atf_check -s not-exit:0 -e ignore $HIJACKING $siocXmulti del vlan0 $mcaddr
+	atf_check -s not-exit:0 -e match:"Invalid argument" \
+	$HIJACKING $siocXmulti del vlan0 $mcaddr
 
 	# add an address to different interfaces
 	$atf_siocXmulti add vlan0 $mcaddr



CVS commit: src/tests/net/if_vlan

2018-12-07 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Fri Dec  7 09:28:31 UTC 2018

Modified Files:
src/tests/net/if_vlan: t_vlan.sh

Log Message:
tests: reduce repeated phrases... (NFC)


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/tests/net/if_vlan/t_vlan.sh

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

Modified files:

Index: src/tests/net/if_vlan/t_vlan.sh
diff -u src/tests/net/if_vlan/t_vlan.sh:1.12 src/tests/net/if_vlan/t_vlan.sh:1.13
--- src/tests/net/if_vlan/t_vlan.sh:1.12	Wed Nov 14 05:07:48 2018
+++ src/tests/net/if_vlan/t_vlan.sh	Fri Dec  7 09:28:31 2018
@@ -1,4 +1,4 @@
-#	$NetBSD: t_vlan.sh,v 1.12 2018/11/14 05:07:48 knakahara Exp $
+#	$NetBSD: t_vlan.sh,v 1.13 2018/12/07 09:28:31 ozaki-r Exp $
 #
 # Copyright (c) 2016 Internet Initiative Japan Inc.
 # All rights reserved.
@@ -45,43 +45,45 @@ DEBUG=${DEBUG:-false}
 
 vlan_create_destroy_body_common()
 {
+	local atf_ifconfig="atf_check -s exit:0 rump.ifconfig"
+
 	export RUMP_SERVER=${SOCK_LOCAL}
 
-	atf_check -s exit:0 rump.ifconfig vlan0 create
-	atf_check -s exit:0 rump.ifconfig vlan0 destroy
+	$atf_ifconfig vlan0 create
+	$atf_ifconfig vlan0 destroy
 
-	atf_check -s exit:0 rump.ifconfig vlan0 create
-	atf_check -s exit:0 rump.ifconfig vlan0 up
-	atf_check -s exit:0 rump.ifconfig vlan0 down
-	atf_check -s exit:0 rump.ifconfig vlan0 destroy
-
-	atf_check -s exit:0 rump.ifconfig shmif0 create
-	atf_check -s exit:0 rump.ifconfig vlan0 create
-	atf_check -s exit:0 rump.ifconfig vlan0 vlan 1 vlanif shmif0
-	atf_check -s exit:0 rump.ifconfig vlan0 up
-	atf_check -s exit:0 rump.ifconfig vlan0 destroy
+	$atf_ifconfig vlan0 create
+	$atf_ifconfig vlan0 up
+	$atf_ifconfig vlan0 down
+	$atf_ifconfig vlan0 destroy
+
+	$atf_ifconfig shmif0 create
+	$atf_ifconfig vlan0 create
+	$atf_ifconfig vlan0 vlan 1 vlanif shmif0
+	$atf_ifconfig vlan0 up
+	$atf_ifconfig vlan0 destroy
 
 	# more than one vlan interface with a same parent interface
-	atf_check -s exit:0 rump.ifconfig shmif1 create
-	atf_check -s exit:0 rump.ifconfig vlan0 create
-	atf_check -s exit:0 rump.ifconfig vlan0 vlan 10 vlanif shmif0
-	atf_check -s exit:0 rump.ifconfig vlan1 create
-	atf_check -s exit:0 rump.ifconfig vlan1 vlan 11 vlanif shmif0
+	$atf_ifconfig shmif1 create
+	$atf_ifconfig vlan0 create
+	$atf_ifconfig vlan0 vlan 10 vlanif shmif0
+	$atf_ifconfig vlan1 create
+	$atf_ifconfig vlan1 vlan 11 vlanif shmif0
 
 	# more than one interface with another parent interface
-	atf_check -s exit:0 rump.ifconfig vlan2 create
-	atf_check -s exit:0 rump.ifconfig vlan2 vlan 12 vlanif shmif1
-	atf_check -s exit:0 rump.ifconfig vlan3 create
-	atf_check -s exit:0 rump.ifconfig vlan3 vlan 13 vlanif shmif1
-	atf_check -s exit:0 rump.ifconfig shmif0 destroy
+	$atf_ifconfig vlan2 create
+	$atf_ifconfig vlan2 vlan 12 vlanif shmif1
+	$atf_ifconfig vlan3 create
+	$atf_ifconfig vlan3 vlan 13 vlanif shmif1
+	$atf_ifconfig shmif0 destroy
 	atf_check -s exit:0 -o not-match:'shmif0' rump.ifconfig vlan0
 	atf_check -s exit:0 -o not-match:'shmif0' rump.ifconfig vlan1
 	atf_check -s exit:0 -o match:'shmif1' rump.ifconfig vlan2
 	atf_check -s exit:0 -o match:'shmif1' rump.ifconfig vlan3
-	atf_check -s exit:0 rump.ifconfig vlan0 destroy
-	atf_check -s exit:0 rump.ifconfig vlan1 destroy
-	atf_check -s exit:0 rump.ifconfig vlan2 destroy
-	atf_check -s exit:0 rump.ifconfig vlan3 destroy
+	$atf_ifconfig vlan0 destroy
+	$atf_ifconfig vlan1 destroy
+	$atf_ifconfig vlan2 destroy
+	$atf_ifconfig vlan3 destroy
 
 }
 
@@ -133,6 +135,7 @@ vlan_create_destroy6_cleanup()
 
 vlan_basic_body_common()
 {
+	local atf_ifconfig="atf_check -s exit:0 rump.ifconfig"
 	local outfile=./out
 	local af=inet
 	local prefix=24
@@ -152,23 +155,23 @@ vlan_basic_body_common()
 	rump_server_add_iface $SOCK_REMOTE shmif0 $BUS
 
 	export RUMP_SERVER=$SOCK_LOCAL
-	atf_check -s exit:0 rump.ifconfig shmif0 up
+	$atf_ifconfig shmif0 up
 	export RUMP_SERVER=$SOCK_REMOTE
-	atf_check -s exit:0 rump.ifconfig shmif0 up
+	$atf_ifconfig shmif0 up
 
 	export RUMP_SERVER=$SOCK_LOCAL
-	atf_check -s exit:0 rump.ifconfig vlan0 create
-	atf_check -s exit:0 rump.ifconfig vlan0 vlan 10 vlanif shmif0
-	atf_check -s exit:0 rump.ifconfig vlan0 $af $local0/$prefix
-	atf_check -s exit:0 rump.ifconfig vlan0 up
-	atf_check -s exit:0 rump.ifconfig -w 10
+	$atf_ifconfig vlan0 create
+	$atf_ifconfig vlan0 vlan 10 vlanif shmif0
+	$atf_ifconfig vlan0 $af $local0/$prefix
+	$atf_ifconfig vlan0 up
+	$atf_ifconfig -w 10
 
 	export RUMP_SERVER=$SOCK_REMOTE
-	atf_check -s exit:0 rump.ifconfig vlan0 create
-	atf_check -s exit:0 rump.ifconfig vlan0 vlan 10 vlanif shmif0
-	atf_check -s exit:0 rump.ifconfig vlan0 $af $remote0/$prefix
-	atf_check -s exit:0 rump.ifconfig vlan0 up
-	atf_check -s exit:0 rump.ifconfig -w 10
+	$atf_ifconfig vlan0 create
+	$atf_ifconfig vlan0 vlan 10 vlanif shmif0
+	$atf_ifconfig vlan0 $af $remote0/$prefix
+	$atf_ifconfig vlan0 up
+	$atf_ifconfig -w 10
 
 	extract_

CVS commit: src/sys/netinet6

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

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

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


To generate a diff of this commit:
cvs rdiff -u -r1.212 -r1.213 src/sys/netinet6/ip6_output.c

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

Modified files:

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



CVS commit: src/sys

2018-11-29 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Thu Nov 29 09:54:23 UTC 2018

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

Log Message:
Don't run DAD on link-up if it's explicitly disabled


To generate a diff of this commit:
cvs rdiff -u -r1.232 -r1.233 src/sys/netinet/in.c
cvs rdiff -u -r1.271 -r1.272 src/sys/netinet6/in6.c

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

Modified files:

Index: src/sys/netinet/in.c
diff -u src/sys/netinet/in.c:1.232 src/sys/netinet/in.c:1.233
--- src/sys/netinet/in.c:1.232	Thu Nov 29 09:51:20 2018
+++ src/sys/netinet/in.c	Thu Nov 29 09:54:22 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: in.c,v 1.232 2018/11/29 09:51:20 ozaki-r Exp $	*/
+/*	$NetBSD: in.c,v 1.233 2018/11/29 09:54:22 ozaki-r Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in.c,v 1.232 2018/11/29 09:51:20 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in.c,v 1.233 2018/11/29 09:54:22 ozaki-r Exp $");
 
 #include "arp.h"
 
@@ -1470,7 +1470,8 @@ in_if_link_up(struct ifnet *ifp)
 		/* If detached then mark as tentative */
 		if (ia->ia4_flags & IN_IFF_DETACHED) {
 			ia->ia4_flags &= ~IN_IFF_DETACHED;
-			if (if_do_dad(ifp) && ia->ia_dad_start != NULL)
+			if (ip_dad_enabled() && if_do_dad(ifp) &&
+			ia->ia_dad_start != NULL)
 ia->ia4_flags |= IN_IFF_TENTATIVE;
 			else if ((ia->ia4_flags & IN_IFF_TENTATIVE) == 0)
 rt_newaddrmsg(RTM_NEWADDR, ifa, 0, NULL);

Index: src/sys/netinet6/in6.c
diff -u src/sys/netinet6/in6.c:1.271 src/sys/netinet6/in6.c:1.272
--- src/sys/netinet6/in6.c:1.271	Thu Nov 29 09:51:21 2018
+++ src/sys/netinet6/in6.c	Thu Nov 29 09:54:23 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: in6.c,v 1.271 2018/11/29 09:51:21 ozaki-r Exp $	*/
+/*	$NetBSD: in6.c,v 1.272 2018/11/29 09:54:23 ozaki-r Exp $	*/
 /*	$KAME: in6.c,v 1.198 2001/07/18 09:12:38 itojun Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.271 2018/11/29 09:51:21 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.272 2018/11/29 09:54:23 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -2204,7 +2204,7 @@ in6_if_link_up(struct ifnet *ifp)
 		/* If detached then mark as tentative */
 		if (ia->ia6_flags & IN6_IFF_DETACHED) {
 			ia->ia6_flags &= ~IN6_IFF_DETACHED;
-			if (if_do_dad(ifp)) {
+			if (ip6_dad_enabled() && if_do_dad(ifp)) {
 ia->ia6_flags |= IN6_IFF_TENTATIVE;
 nd6log(LOG_ERR, "%s marked tentative\n",
 IN6_PRINT(ip6buf,



CVS commit: src/sys

2018-11-29 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Thu Nov 29 09:51:21 UTC 2018

Modified Files:
src/sys/netinet: if_arp.c in.c in_var.h
src/sys/netinet6: in6.c ip6_var.h nd6_nbr.c

Log Message:
Introduce and use ip_dad_enabled() and ip6_dad_enabled() functions


To generate a diff of this commit:
cvs rdiff -u -r1.276 -r1.277 src/sys/netinet/if_arp.c
cvs rdiff -u -r1.231 -r1.232 src/sys/netinet/in.c
cvs rdiff -u -r1.96 -r1.97 src/sys/netinet/in_var.h
cvs rdiff -u -r1.270 -r1.271 src/sys/netinet6/in6.c
cvs rdiff -u -r1.80 -r1.81 src/sys/netinet6/ip6_var.h
cvs rdiff -u -r1.156 -r1.157 src/sys/netinet6/nd6_nbr.c

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

Modified files:

Index: src/sys/netinet/if_arp.c
diff -u src/sys/netinet/if_arp.c:1.276 src/sys/netinet/if_arp.c:1.277
--- src/sys/netinet/if_arp.c:1.276	Tue Oct 30 05:54:41 2018
+++ src/sys/netinet/if_arp.c	Thu Nov 29 09:51:20 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_arp.c,v 1.276 2018/10/30 05:54:41 ozaki-r Exp $	*/
+/*	$NetBSD: if_arp.c,v 1.277 2018/11/29 09:51:20 ozaki-r Exp $	*/
 
 /*
  * Copyright (c) 1998, 2000, 2008 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.276 2018/10/30 05:54:41 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.277 2018/11/29 09:51:20 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -1491,7 +1491,7 @@ arp_ifinit(struct ifnet *ifp, struct ifa
 	} else {
 		ia->ia_dad_start = arp_dad_start;
 		ia->ia_dad_stop = arp_dad_stop;
-		if (ia->ia4_flags & IN_IFF_TRYTENTATIVE && ip_dad_count > 0)
+		if (ia->ia4_flags & IN_IFF_TRYTENTATIVE && ip_dad_enabled())
 			ia->ia4_flags |= IN_IFF_TENTATIVE;
 		else
 			arpannounce1(ifa);
@@ -1597,7 +1597,7 @@ arp_dad_start(struct ifaddr *ifa)
 
 	/*
 	 * If we don't need DAD, don't do it.
-	 * - DAD is disabled (ip_dad_count == 0)
+	 * - DAD is disabled
 	 */
 	if (!(ia->ia4_flags & IN_IFF_TENTATIVE)) {
 		log(LOG_DEBUG,
@@ -1606,7 +1606,7 @@ arp_dad_start(struct ifaddr *ifa)
 		ifa->ifa_ifp ? if_name(ifa->ifa_ifp) : "???");
 		return;
 	}
-	if (!ip_dad_count) {
+	if (!ip_dad_enabled()) {
 		ia->ia4_flags &= ~IN_IFF_TENTATIVE;
 		rt_newaddrmsg(RTM_NEWADDR, ifa, 0, NULL);
 		arpannounce1(ifa);
@@ -1806,7 +1806,7 @@ arp_dad_duplicated(struct ifaddr *ifa, c
 		return;
 	} else {
 		/* If DAD is disabled, just report the duplicate. */
-		if (ip_dad_count == 0) {
+		if (!ip_dad_enabled()) {
 			log(LOG_ERR,
 			"%s: DAD ignoring duplicate address %s from %s\n",
 			if_name(ifp), iastr, sha);

Index: src/sys/netinet/in.c
diff -u src/sys/netinet/in.c:1.231 src/sys/netinet/in.c:1.232
--- src/sys/netinet/in.c:1.231	Sun May 13 22:42:51 2018
+++ src/sys/netinet/in.c	Thu Nov 29 09:51:20 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: in.c,v 1.231 2018/05/13 22:42:51 khorben Exp $	*/
+/*	$NetBSD: in.c,v 1.232 2018/11/29 09:51:20 ozaki-r Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in.c,v 1.231 2018/05/13 22:42:51 khorben Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in.c,v 1.232 2018/11/29 09:51:20 ozaki-r Exp $");
 
 #include "arp.h"
 
@@ -1155,11 +1155,7 @@ in_ifinit(struct ifnet *ifp, struct in_i
 	if (ifp->if_link_state == LINK_STATE_DOWN) {
 		ia->ia4_flags |= IN_IFF_DETACHED;
 		ia->ia4_flags &= ~IN_IFF_TENTATIVE;
-	} else if (hostIsNew && if_do_dad(ifp)
-#if NARP > 0
-	&& ip_dad_count > 0
-#endif
-	)
+	} else if (hostIsNew && if_do_dad(ifp) && ip_dad_enabled())
 		ia->ia4_flags |= IN_IFF_TRYTENTATIVE;
 
 	/*

Index: src/sys/netinet/in_var.h
diff -u src/sys/netinet/in_var.h:1.96 src/sys/netinet/in_var.h:1.97
--- src/sys/netinet/in_var.h:1.96	Thu Apr 19 21:21:44 2018
+++ src/sys/netinet/in_var.h	Thu Nov 29 09:51:20 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: in_var.h,v 1.96 2018/04/19 21:21:44 christos Exp $	*/
+/*	$NetBSD: in_var.h,v 1.97 2018/11/29 09:51:20 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -378,6 +378,17 @@ struct in_multi {
 extern pktqueue_t *ip_pktq;
 
 extern int ip_dad_count;		/* Duplicate Address Detection probes */
+
+static inline bool
+ip_dad_enabled(void)
+{
+#if NARP > 0
+	return ip_dad_count > 0;
+#else
+	return false;
+#endif
+}
+
 #if defined(INET) && NARP > 0
 extern int arp_debug;
 #define ARPLOGADDR(a) IN_PRINT(_ipbuf, a)

Index: src/sys/netinet6/in6.c
diff -u src/sys/netinet6/in6.c:1.270 src/sys/netinet6/in6.c:1.271
--- src/sys/netinet6/in6.c:1.270	Tue Oct 30 05:56:02 2018
+++ src/sys/netinet6/in6.c	Thu Nov 29 09:51:21 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: in6.c,v 1.270 2018/10/30 05:56:02 ozaki-r Exp $	*/
+/*	$NetBSD: in6.c,v 1.271 2018/11/29 09:51:21 ozaki-r Exp $	*/
 /*	$KAME: in6.c,v 1.198 2001/07/18 09:12:38 itojun Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.270 2018/10/30 05:56:02 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.271 2018/11/

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

2018-11-18 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Mon Nov 19 04:54:37 UTC 2018

Modified Files:
src/crypto/dist/ipsec-tools/src/setkey: setkey.8

Log Message:
Use Cm instead of Li or Ar for fixed command strings


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/crypto/dist/ipsec-tools/src/setkey/setkey.8

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

Modified files:

Index: src/crypto/dist/ipsec-tools/src/setkey/setkey.8
diff -u src/crypto/dist/ipsec-tools/src/setkey/setkey.8:1.34 src/crypto/dist/ipsec-tools/src/setkey/setkey.8:1.35
--- src/crypto/dist/ipsec-tools/src/setkey/setkey.8:1.34	Sat Feb 18 13:51:29 2012
+++ src/crypto/dist/ipsec-tools/src/setkey/setkey.8	Mon Nov 19 04:54:37 2018
@@ -1,4 +1,4 @@
-.\"	$NetBSD: setkey.8,v 1.34 2012/02/18 13:51:29 wiz Exp $
+.\"	$NetBSD: setkey.8,v 1.35 2018/11/19 04:54:37 ozaki-r Exp $
 .\"
 .\" Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
 .\" All rights reserved.
@@ -27,7 +27,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd February 18, 2012
+.Dd November 19, 2018
 .Dt SETKEY 8
 .Os
 .\"
@@ -160,60 +160,60 @@ Lines starting with hash signs
 .Pq Sq #
 are treated as comment lines.
 .Bl -tag -width Ds
-.It Li add Oo Fl 46n Oc Ar src Ar dst Ar protocol Ar spi \
+.It Cm add Oo Fl 46n Oc Ar src Ar dst Ar protocol Ar spi \
 Oo Ar extensions Oc Ar algorithm ... Li ;
 Add an SAD entry.
-.Li add
+.Cm add
 can fail for multiple reasons, including when the key length does
 not match the specified algorithm.
 .\"
-.It Li get Oo Fl 46n Oc Ar src Ar dst Ar protocol Ar spi Li ;
+.It Cm get Oo Fl 46n Oc Ar src Ar dst Ar protocol Ar spi Li ;
 Show an SAD entry.
 .\"
-.It Li delete Oo Fl 46n Oc Ar src Ar dst Ar protocol Ar spi Li ;
+.It Cm delete Oo Fl 46n Oc Ar src Ar dst Ar protocol Ar spi Li ;
 Remove an SAD entry.
 .\"
-.It Li deleteall Oo Fl 46n Oc Ar src Ar dst Ar protocol Li ;
+.It Cm deleteall Oo Fl 46n Oc Ar src Ar dst Ar protocol Li ;
 Remove all SAD entries that match the specification.
 .\"
-.It Li flush Oo Ar protocol Oc Li ;
+.It Cm flush Oo Ar protocol Oc Li ;
 Clear all SAD entries matched by the options.
 .Fl F
 on the command line achieves the same functionality.
 .\"
-.It Li dump Oo Ar protocol Oc Li ;
+.It Cm dump Oo Ar protocol Oc Li ;
 Dumps all SAD entries matched by the options.
 .Fl D
 on the command line achieves the same functionality.
 .\"
-.It Li spdadd Oo Fl 46n Oc Ar src_range Ar dst_range Ar upperspec \
+.It Cm spdadd Oo Fl 46n Oc Ar src_range Ar dst_range Ar upperspec \
 Ar label Ar policy Li ;
 Add an SPD entry.
 .\"
-.It Li spdadd tagged Ar tag Ar policy Li ;
+.It Cm spdadd tagged Ar tag Ar policy Li ;
 Add an SPD entry based on a PF tag.
 .Ar tag
 must be a string surrounded by double quotes.
 .\"
-.It Li spdupdate Oo Fl 46n Oc Ar src_range Ar dst_range Ar upperspec \
+.It Cm spdupdate Oo Fl 46n Oc Ar src_range Ar dst_range Ar upperspec \
 Ar label Ar policy Li ;
 Updates an SPD entry.
 .\"
-.It Li spdupdate tagged Ar tag Ar policy Li ;
+.It Cm spdupdate tagged Ar tag Ar policy Li ;
 Update an SPD entry based on a PF tag.
 .Ar tag
 must be a string surrounded by double quotes.
 .\"
-.It Li spddelete Oo Fl 46n Oc Ar src_range Ar dst_range Ar upperspec \
+.It Cm spddelete Oo Fl 46n Oc Ar src_range Ar dst_range Ar upperspec \
 Fl P Ar direction Li ;
 Delete an SPD entry.
 .\"
-.It Li spdflush Li ;
+.It Cm spdflush Li ;
 Clear all SPD entries.
 .Fl FP
 on the command line achieves the same functionality.
 .\"
-.It Li spddump Li ;
+.It Cm spddump Li ;
 Dumps all SPD entries.
 .Fl DP
 on the command line achieves the same functionality.
@@ -251,19 +251,19 @@ avoids FQDN resolution and requires addr
 .Ar protocol
 is one of following:
 .Bl -tag -width Fl -compact
-.It Li esp
+.It Cm esp
 ESP based on rfc2406
-.It Li esp-old
+.It Cm esp-old
 ESP based on rfc1827
-.It Li esp-udp
+.It Cm esp-udp
 UDP encapsulated ESP for NAT traversal (rfc3948)
-.It Li ah
+.It Cm ah
 AH based on rfc2402
-.It Li ah-old
+.It Cm ah-old
 AH based on rfc1826
-.It Li ipcomp
+.It Cm ipcomp
 IPComp
-.It Li tcp
+.It Cm tcp
 TCP-MD5 based on rfc2385
 .El
 .\"
@@ -290,11 +290,11 @@ take some of the following:
 Specify a security protocol mode for use.
 .Ar mode
 is one of following:
-.Li transport , tunnel ,
+.Cm transport , tunnel ,
 or
-.Li any .
+.Cm any .
 The default value is
-.Li any .
+.Cm any .
 .\"
 .It Fl r Ar size
 Specify window size of bytes for replay prevention.
@@ -314,11 +314,11 @@ defines the content of the ESP padding.
 .Ar pad_option
 is one of following:
 .Bl -tag -width random-pad -compact
-.It Li zero-pad
+.It Cm zero-pad
 All the paddings are zero.
-.It Li random-pad
+.It Cm random-pad
 A series of randomized values are used.
-.It Li seq-pad
+.It Cm seq-pad
 A series of sequential increasing numbers started from 1 are used.
 .El
 .\"
@@ -433,12 +433,12 @@ You can use one of the words i

CVS commit: src/usr.sbin/rtadvd

2018-11-16 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Fri Nov 16 08:57:10 UTC 2018

Modified Files:
src/usr.sbin/rtadvd: dump.c

Log Message:
rtadvd: use %u to print unsigned variables


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/usr.sbin/rtadvd/dump.c

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

Modified files:

Index: src/usr.sbin/rtadvd/dump.c
diff -u src/usr.sbin/rtadvd/dump.c:1.16 src/usr.sbin/rtadvd/dump.c:1.17
--- src/usr.sbin/rtadvd/dump.c:1.16	Fri Apr 20 10:39:37 2018
+++ src/usr.sbin/rtadvd/dump.c	Fri Nov 16 08:57:10 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: dump.c,v 1.16 2018/04/20 10:39:37 roy Exp $	*/
+/*	$NetBSD: dump.c,v 1.17 2018/11/16 08:57:10 ozaki-r Exp $	*/
 /*	$KAME: dump.c,v 1.34 2004/06/14 05:35:59 itojun Exp $	*/
 
 /*
@@ -138,23 +138,23 @@ if_dump(void)
 		if (rai->advlinkopt)
 			fprintf(fp, "  Link-layer address: %s\n",
 			ether_str(rai->sdl));
-		fprintf(fp, "  MTU: %d\n", rai->phymtu);
+		fprintf(fp, "  MTU: %u\n", rai->phymtu);
 
 		/* Router configuration variables */
-		fprintf(fp, "  DefaultLifetime: %d, MaxAdvInterval: %d, "
-		"MinAdvInterval: %d\n", rai->lifetime, rai->maxinterval,
+		fprintf(fp, "  DefaultLifetime: %u, MaxAdvInterval: %u, "
+		"MinAdvInterval: %u\n", rai->lifetime, rai->maxinterval,
 		rai->mininterval);
 		fprintf(fp, "  Flags: %s%s%s, ",
 		rai->managedflg ? "M" : "", rai->otherflg ? "O" : "",
 		"");
 		fprintf(fp, "Preference: %s, ",
 			rtpref_str[(rai->rtpref >> 3) & 0xff]);
-		fprintf(fp, "MTU: %d\n", rai->linkmtu);
-		fprintf(fp, "  ReachableTime: %d, RetransTimer: %d, "
-			"CurHopLimit: %d\n", rai->reachabletime,
+		fprintf(fp, "MTU: %u\n", rai->linkmtu);
+		fprintf(fp, "  ReachableTime: %u, RetransTimer: %u, "
+			"CurHopLimit: %u\n", rai->reachabletime,
 			rai->retranstimer, rai->hoplimit);
 		if (rai->clockskew)
-			fprintf(fp, "  Clock skew: %dsec\n",
+			fprintf(fp, "  Clock skew: %usec\n",
 			rai->clockskew);
 		TAILQ_FOREACH(pfx, &rai->prefix, next) {
 			if (pfx == TAILQ_FIRST(&rai->prefix))
@@ -176,8 +176,7 @@ if_dump(void)
 			if (pfx->validlifetime == ND6_INFINITE_LIFETIME)
 fprintf(fp, "vltime: infinity");
 			else
-fprintf(fp, "vltime: %ld",
-	(long)pfx->validlifetime);
+fprintf(fp, "vltime: %u", pfx->validlifetime);
 			if (pfx->vltimeexpire != 0)
 fprintf(fp, "(decr,expire %lld), ", (long long)
 	(pfx->vltimeexpire > now.tv_sec ?
@@ -187,8 +186,7 @@ if_dump(void)
 			if (pfx->preflifetime ==  ND6_INFINITE_LIFETIME)
 fprintf(fp, "pltime: infinity");
 			else
-fprintf(fp, "pltime: %ld",
-	(long)pfx->preflifetime);
+fprintf(fp, "pltime: %u", pfx->preflifetime);
 			if (pfx->pltimeexpire != 0)
 fprintf(fp, "(decr,expire %lld), ", (long long)
 	(pfx->pltimeexpire > now.tv_sec ?



CVS commit: src/sbin/ifconfig

2018-11-14 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Thu Nov 15 04:37:20 UTC 2018

Modified Files:
src/sbin/ifconfig: ifconfig.8

Log Message:
Fix the format of ifconfig linkstr; it takes an argument


To generate a diff of this commit:
cvs rdiff -u -r1.115 -r1.116 src/sbin/ifconfig/ifconfig.8

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

Modified files:

Index: src/sbin/ifconfig/ifconfig.8
diff -u src/sbin/ifconfig/ifconfig.8:1.115 src/sbin/ifconfig/ifconfig.8:1.116
--- src/sbin/ifconfig/ifconfig.8:1.115	Tue Jul 31 20:54:18 2018
+++ src/sbin/ifconfig/ifconfig.8	Thu Nov 15 04:37:20 2018
@@ -1,4 +1,4 @@
-.\"	$NetBSD: ifconfig.8,v 1.115 2018/07/31 20:54:18 sevan Exp $
+.\"	$NetBSD: ifconfig.8,v 1.116 2018/11/15 04:37:20 ozaki-r Exp $
 .\"
 .\" Copyright (c) 1983, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\" @(#)ifconfig.8	8.4 (Berkeley) 6/1/94
 .\"
-.Dd July 31, 2018
+.Dd November 15, 2018
 .Dt IFCONFIG 8
 .Os
 .Sh NAME
@@ -528,7 +528,7 @@ Refer to the man page for the specific d
 for more information.
 .It Fl link[0-2]
 Disable special processing at the link level with the specified interface.
-.It Cm linkstr
+.It Cm linkstr Ar str
 Set a link-level string parameter for the interface.
 This functionality varies from interface to interface.
 Refer to the man page for the specific driver



CVS commit: src/sbin/ifconfig

2018-11-14 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Thu Nov 15 04:36:46 UTC 2018

Modified Files:
src/sbin/ifconfig: ifconfig.c

Log Message:
ifconfig: add linkstr/-linkstr to the help message


To generate a diff of this commit:
cvs rdiff -u -r1.236 -r1.237 src/sbin/ifconfig/ifconfig.c

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

Modified files:

Index: src/sbin/ifconfig/ifconfig.c
diff -u src/sbin/ifconfig/ifconfig.c:1.236 src/sbin/ifconfig/ifconfig.c:1.237
--- src/sbin/ifconfig/ifconfig.c:1.236	Thu Jan  7 11:32:21 2016
+++ src/sbin/ifconfig/ifconfig.c	Thu Nov 15 04:36:46 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ifconfig.c,v 1.236 2016/01/07 11:32:21 roy Exp $	*/
+/*	$NetBSD: ifconfig.c,v 1.237 2018/11/15 04:36:46 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 1997, 1998, 2000 The NetBSD Foundation, Inc.
@@ -63,7 +63,7 @@
 #ifndef lint
 __COPYRIGHT("@(#) Copyright (c) 1983, 1993\
  The Regents of the University of California.  All rights reserved.");
-__RCSID("$NetBSD: ifconfig.c,v 1.236 2016/01/07 11:32:21 roy Exp $");
+__RCSID("$NetBSD: ifconfig.c,v 1.237 2018/11/15 04:36:46 ozaki-r Exp $");
 #endif /* not lint */
 
 #include 
@@ -1484,6 +1484,7 @@ usage(void)
 		"\t[ arp | -arp ]\n"
 		"\t[ preference n ]\n"
 		"\t[ link0 | -link0 ] [ link1 | -link1 ] [ link2 | -link2 ]\n"
+		"\t[ linkstr str | -linkstr ]\n"
 		"   %s -a [-b] [-d] [-h] %s[-u] [-v] [-z] [ af ]\n"
 		"   %s -l [-b] [-d] [-s] [-u]\n"
 		"   %s -C\n"



CVS commit: src/tests/net/if_bridge

2018-11-08 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Fri Nov  9 06:45:03 UTC 2018

Modified Files:
src/tests/net/if_bridge: t_rtable.sh

Log Message:
Add a test to show a large number of MAC addresses cached in a bridge


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

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

Modified files:

Index: src/tests/net/if_bridge/t_rtable.sh
diff -u src/tests/net/if_bridge/t_rtable.sh:1.3 src/tests/net/if_bridge/t_rtable.sh:1.4
--- src/tests/net/if_bridge/t_rtable.sh:1.3	Wed Apr 18 04:03:12 2018
+++ src/tests/net/if_bridge/t_rtable.sh	Fri Nov  9 06:45:03 2018
@@ -1,4 +1,4 @@
-#	$NetBSD: t_rtable.sh,v 1.3 2018/04/18 04:03:12 ozaki-r Exp $
+#	$NetBSD: t_rtable.sh,v 1.4 2018/11/09 06:45:03 ozaki-r Exp $
 #
 # Copyright (c) 2017 Internet Initiative Japan Inc.
 # All rights reserved.
@@ -96,7 +96,7 @@ get_number_of_caches()
 
 	export RUMP_SERVER=$SOCK2
 	export LD_PRELOAD=/usr/lib/librumphijack.so
-	echo $(($(/sbin/brconfig bridge0 |grep -A 100 "Address cache" |wc -l) - 1))
+	echo $(/sbin/brconfig bridge0 addr |wc -l)
 	unset LD_PRELOAD
 }
 
@@ -441,6 +441,49 @@ bridge_rtable_delete_member_cleanup()
 }
 
 
+atf_test_case bridge_rtable_manyaddrs cleanup
+bridge_rtable_manyaddrs_head()
+{
+
+	atf_set "descr" "Tests brconfig addr under many MAC addresses"
+	atf_set "require.progs" "rump_server"
+}
+
+bridge_rtable_manyaddrs_body()
+{
+	local addr=
+
+	setup
+	setup_bridge
+
+	export RUMP_SERVER=$SOCK2
+	export LD_PRELOAD=/usr/lib/librumphijack.so
+	atf_check -s exit:0 -o ignore /sbin/brconfig bridge0 maxaddr 1024
+
+	# Fill the MAC addresses
+	for i in 1 2 3 4; do
+		for j in $(seq 0 255); do
+			addr="00:11:22:33:4$i:$(printf "%02x" $j)"
+			atf_check -s exit:0 -o empty \
+			/sbin/brconfig bridge0 static shmif0 $addr
+		done
+
+		n=$(get_number_of_caches)
+		atf_check_equal $n $((i * 256))
+	done
+
+
+	rump_server_destroy_ifaces
+}
+
+bridge_rtable_manyaddrs_cleanup()
+{
+
+	$DEBUG && dump
+	cleanup
+}
+
+
 atf_init_test_cases()
 {
 
@@ -449,5 +492,6 @@ atf_init_test_cases()
 	atf_add_test_case bridge_rtable_timeout
 	atf_add_test_case bridge_rtable_maxaddr
 	atf_add_test_case bridge_rtable_delete_member
+	atf_add_test_case bridge_rtable_manyaddrs
 	# TODO: brconfig static/flushall/discover/learn
 }



CVS commit: src/sys/net

2018-11-08 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Fri Nov  9 06:44:31 UTC 2018

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

Log Message:
Fix that brconfig  (addr) can't show a large number of MAC addresses

The command shows only 256 addresses at maximum even if a bridge caches more
addresses.  It occurs because the kernel doesn't return an error if the command
passes a short buffer that can't store all cached addresses; the kernel fills
cached addresses as much as possible and returns it without telling that the
result is truncated.

Fix the issue by telling a required size of a buffer if a buffer passed from the
command is not enough, which lets the command retry with an enough buffer.

Reported by k-goda@IIJ


To generate a diff of this commit:
cvs rdiff -u -r1.159 -r1.160 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.159 src/sys/net/if_bridge.c:1.160
--- src/sys/net/if_bridge.c:1.159	Wed Sep 19 07:51:23 2018
+++ src/sys/net/if_bridge.c	Fri Nov  9 06:44:31 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_bridge.c,v 1.159 2018/09/19 07:51:23 msaitoh Exp $	*/
+/*	$NetBSD: if_bridge.c,v 1.160 2018/11/09 06:44:31 ozaki-r Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -80,7 +80,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_bridge.c,v 1.159 2018/09/19 07:51:23 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_bridge.c,v 1.160 2018/11/09 06:44:31 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_bridge_ipf.h"
@@ -1060,6 +1060,12 @@ bridge_ioctl_rts(struct bridge_softc *sc
 
 	BRIDGE_RT_LOCK(sc);
 
+	/* The passed buffer is not enough, tell a required size. */
+	if (bac->ifbac_len < (sizeof(bareq) * sc->sc_brtcnt)) {
+		count = sc->sc_brtcnt;
+		goto out;
+	}
+
 	len = bac->ifbac_len;
 	BRIDGE_RTLIST_WRITER_FOREACH(brt, sc) {
 		if (len < sizeof(bareq))



CVS commit: src/sys/netinet6

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

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

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

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

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

Reported by Paul Ripke


To generate a diff of this commit:
cvs rdiff -u -r1.142 -r1.143 src/sys/netinet6/udp6_usrreq.c

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

Modified files:

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



CVS commit: src/sys

2018-10-29 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Tue Oct 30 05:56:02 UTC 2018

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

Log Message:
Use rt_update framework on updating a rtentry


To generate a diff of this commit:
cvs rdiff -u -r1.215 -r1.216 src/sys/net/route.c
cvs rdiff -u -r1.269 -r1.270 src/sys/netinet6/in6.c

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

Modified files:

Index: src/sys/net/route.c
diff -u src/sys/net/route.c:1.215 src/sys/net/route.c:1.216
--- src/sys/net/route.c:1.215	Tue Oct 30 05:54:42 2018
+++ src/sys/net/route.c	Tue Oct 30 05:56:02 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: route.c,v 1.215 2018/10/30 05:54:42 ozaki-r Exp $	*/
+/*	$NetBSD: route.c,v 1.216 2018/10/30 05:56:02 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -97,7 +97,7 @@
 #endif
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.215 2018/10/30 05:54:42 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.216 2018/10/30 05:56:02 ozaki-r Exp $");
 
 #include 
 #ifdef RTFLUSH_DEBUG
@@ -1730,7 +1730,21 @@ rt_ifa_remlocal(struct ifaddr *ifa, stru
 			}
 			rt_newaddrmsg(RTM_DELADDR, ifa, 0, NULL);
 		} else {
+#ifdef NET_MPSAFE
+			int error = rt_update_prepare(rt);
+			if (error == 0) {
+rt_replace_ifa(rt, alt_ifa);
+rt_update_finish(rt);
+			} else {
+/*
+ * If error != 0, the rtentry is being
+ * destroyed, so doing nothing doesn't
+ * matter.
+ */
+			}
+#else
 			rt_replace_ifa(rt, alt_ifa);
+#endif
 			rt_newmsg(RTM_CHANGE, rt);
 		}
 	} else

Index: src/sys/netinet6/in6.c
diff -u src/sys/netinet6/in6.c:1.269 src/sys/netinet6/in6.c:1.270
--- src/sys/netinet6/in6.c:1.269	Wed Jul  4 00:35:33 2018
+++ src/sys/netinet6/in6.c	Tue Oct 30 05:56:02 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: in6.c,v 1.269 2018/07/04 00:35:33 kamil Exp $	*/
+/*	$NetBSD: in6.c,v 1.270 2018/10/30 05:56:02 ozaki-r Exp $	*/
 /*	$KAME: in6.c,v 1.198 2001/07/18 09:12:38 itojun Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.269 2018/07/04 00:35:33 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.270 2018/10/30 05:56:02 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -867,8 +867,23 @@ in6_join_mcastgroups(struct in6_aliasreq
 			ntohs(mltaddr.sin6_addr.s6_addr16[1]),
 			satocsin6(rt_getkey(rt))->sin6_addr.s6_addr16[0],
 			satocsin6(rt_getkey(rt))->sin6_addr.s6_addr16[1]);
+#ifdef NET_MPSAFE
+			error = rt_update_prepare(rt);
+			if (error == 0) {
+rt_replace_ifa(rt, &ia->ia_ifa);
+rt->rt_ifp = ifp;
+rt_update_finish(rt);
+			} else {
+/*
+ * If error != 0, the rtentry is being
+ * destroyed, so doing nothing doesn't
+ * matter.
+ */
+			}
+#else
 			rt_replace_ifa(rt, &ia->ia_ifa);
 			rt->rt_ifp = ifp;
+#endif
 		}
 	}
 	if (!rt) {
@@ -951,8 +966,23 @@ in6_join_mcastgroups(struct in6_aliasreq
 			ntohs(mltaddr.sin6_addr.s6_addr16[1]),
 			satocsin6(rt_getkey(rt))->sin6_addr.s6_addr16[0],
 			satocsin6(rt_getkey(rt))->sin6_addr.s6_addr16[1]);
+#ifdef NET_MPSAFE
+			error = rt_update_prepare(rt);
+			if (error == 0) {
+rt_replace_ifa(rt, &ia->ia_ifa);
+rt->rt_ifp = ifp;
+rt_update_finish(rt);
+			} else {
+/*
+ * If error != 0, the rtentry is being
+ * destroyed, so doing nothing doesn't
+ * matter.
+ */
+			}
+#else
 			rt_replace_ifa(rt, &ia->ia_ifa);
 			rt->rt_ifp = ifp;
+#endif
 		}
 	}
 	if (!rt) {



CVS commit: src/sys

2018-10-29 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Tue Oct 30 05:54:42 UTC 2018

Modified Files:
src/sys/net: if.c route.c route.h
src/sys/netinet: if_arp.c
src/sys/netinet6: nd6.c

Log Message:
Avoid double rt_replace_ifa on rtrequest1(RTM_ADD)

Some callers of rtrequest1(RTM_ADD) adjust rt_ifa of an rtentry created by
rtrequest1 that may change rt_ifa (in ifa_rtrequest) with another ifa that is
different from requested one.  It's wasteful and even worse introduces a race
condition.  rtrequest1 should just use a passed ifa as is if a caller hopes so.


To generate a diff of this commit:
cvs rdiff -u -r1.439 -r1.440 src/sys/net/if.c
cvs rdiff -u -r1.214 -r1.215 src/sys/net/route.c
cvs rdiff -u -r1.119 -r1.120 src/sys/net/route.h
cvs rdiff -u -r1.275 -r1.276 src/sys/netinet/if_arp.c
cvs rdiff -u -r1.250 -r1.251 src/sys/netinet6/nd6.c

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

Modified files:

Index: src/sys/net/if.c
diff -u src/sys/net/if.c:1.439 src/sys/net/if.c:1.440
--- src/sys/net/if.c:1.439	Tue Oct 30 05:29:21 2018
+++ src/sys/net/if.c	Tue Oct 30 05:54:42 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.439 2018/10/30 05:29:21 ozaki-r Exp $	*/
+/*	$NetBSD: if.c,v 1.440 2018/10/30 05:54:42 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc.
@@ -90,7 +90,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.439 2018/10/30 05:29:21 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.440 2018/10/30 05:54:42 ozaki-r Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -2183,7 +2183,8 @@ link_rtrequest(int cmd, struct rtentry *
 	struct psref psref;
 
 	if (cmd != RTM_ADD || (ifa = rt->rt_ifa) == NULL ||
-	(ifp = ifa->ifa_ifp) == NULL || (dst = rt_getkey(rt)) == NULL)
+	(ifp = ifa->ifa_ifp) == NULL || (dst = rt_getkey(rt)) == NULL ||
+	ISSET(info->rti_flags, RTF_DONTCHANGEIFA))
 		return;
 	if ((ifa = ifaof_ifpforaddr_psref(dst, ifp, &psref)) != NULL) {
 		rt_replace_ifa(rt, ifa);
@@ -2437,6 +2438,9 @@ p2p_rtrequest(int req, struct rtentry *r
 
 		rt->rt_ifp = lo0ifp;
 
+		if (ISSET(info->rti_flags, RTF_DONTCHANGEIFA))
+			break;
+
 		IFADDR_READER_FOREACH(ifa, ifp) {
 			if (equal(rt_getkey(rt), ifa->ifa_addr))
 break;

Index: src/sys/net/route.c
diff -u src/sys/net/route.c:1.214 src/sys/net/route.c:1.215
--- src/sys/net/route.c:1.214	Tue Oct 30 05:30:31 2018
+++ src/sys/net/route.c	Tue Oct 30 05:54:42 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: route.c,v 1.214 2018/10/30 05:30:31 ozaki-r Exp $	*/
+/*	$NetBSD: route.c,v 1.215 2018/10/30 05:54:42 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -97,7 +97,7 @@
 #endif
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.214 2018/10/30 05:30:31 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.215 2018/10/30 05:54:42 ozaki-r Exp $");
 
 #include 
 #ifdef RTFLUSH_DEBUG
@@ -1242,7 +1242,7 @@ rtrequest1(int req, struct rt_addrinfo *
 		if (rt == NULL)
 			senderr(ENOBUFS);
 		memset(rt, 0, sizeof(*rt));
-		rt->rt_flags = RTF_UP | flags;
+		rt->rt_flags = RTF_UP | (flags & ~RTF_DONTCHANGEIFA);
 		LIST_INIT(&rt->rt_timer);
 
 		RT_DPRINTF("rt->_rt_key = %p\n", (void *)rt->_rt_key);
@@ -1605,7 +1605,7 @@ rtinit(struct ifaddr *ifa, int cmd, int 
 	}
 	memset(&info, 0, sizeof(info));
 	info.rti_ifa = ifa;
-	info.rti_flags = flags | ifa->ifa_flags;
+	info.rti_flags = flags | ifa->ifa_flags | RTF_DONTCHANGEIFA;
 	info.rti_info[RTAX_DST] = dst;
 	info.rti_info[RTAX_GATEWAY] = ifa->ifa_addr;
 
@@ -1636,40 +1636,7 @@ rtinit(struct ifaddr *ifa, int cmd, int 
 		rt_unref(rt);
 		break;
 	case RTM_ADD:
-		/*
-		 * XXX it looks just reverting rt_ifa replaced by ifa_rtrequest
-		 * called via rtrequest1. Can we just prevent the replacement
-		 * somehow and remove the following code? And also doesn't
-		 * calling ifa_rtrequest(RTM_ADD) replace rt_ifa again?
-		 */
-		if (rt->rt_ifa != ifa) {
-			printf("rtinit: wrong ifa (%p) was (%p)\n", ifa,
-rt->rt_ifa);
-#ifdef NET_MPSAFE
-			KASSERT(!cpu_softintr_p());
-
-			error = rt_update_prepare(rt);
-			if (error == 0) {
-#endif
-if (rt->rt_ifa->ifa_rtrequest != NULL) {
-	rt->rt_ifa->ifa_rtrequest(RTM_DELETE,
-	rt, &info);
-}
-rt_replace_ifa(rt, ifa);
-rt->rt_ifp = ifa->ifa_ifp;
-if (ifa->ifa_rtrequest != NULL)
-	ifa->ifa_rtrequest(RTM_ADD, rt, &info);
-#ifdef NET_MPSAFE
-rt_update_finish(rt);
-			} else {
-/*
- * If error != 0, the rtentry is being
- * destroyed, so doing nothing doesn't
- * matter.
- */
-			}
-#endif
-		}
+		KASSERT(rt->rt_ifa == ifa);
 		rt_newmsg(cmd, rt);
 		rt_unref(rt);
 		RT_REFCNT_TRACE(rt);
@@ -1701,17 +1668,16 @@ rt_ifa_addlocal(struct ifaddr *ifa)
 		struct rtentry *nrt;
 
 		memset(&info, 0, sizeof(info));
-		info.rti_flags = RTF_HOST | RTF_LOCAL;
+		info.rti_flags = RTF_HOST | RTF_LOCAL | RTF_DONTCHANGEIFA;
 		info.rti_info[RTAX_DST] =

CVS commit: src/sys/net

2018-10-29 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Tue Oct 30 05:30:31 UTC 2018

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

Log Message:
Avoid a dangling pointer during rt_replace_ifa


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

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

Modified files:

Index: src/sys/net/route.c
diff -u src/sys/net/route.c:1.213 src/sys/net/route.c:1.214
--- src/sys/net/route.c:1.213	Wed Sep  5 02:49:40 2018
+++ src/sys/net/route.c	Tue Oct 30 05:30:31 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: route.c,v 1.213 2018/09/05 02:49:40 ozaki-r Exp $	*/
+/*	$NetBSD: route.c,v 1.214 2018/10/30 05:30:31 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -97,7 +97,7 @@
 #endif
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.213 2018/09/05 02:49:40 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.214 2018/10/30 05:30:31 ozaki-r Exp $");
 
 #include 
 #ifdef RTFLUSH_DEBUG
@@ -406,6 +406,11 @@ rt_ifa_connected(const struct rtentry *r
 void
 rt_replace_ifa(struct rtentry *rt, struct ifaddr *ifa)
 {
+	struct ifaddr *old;
+
+	if (rt->rt_ifa == ifa)
+		return;
+
 	if (rt->rt_ifa &&
 	rt->rt_ifa != ifa &&
 	rt->rt_ifa->ifa_flags & IFA_ROUTE &&
@@ -424,8 +429,9 @@ rt_replace_ifa(struct rtentry *rt, struc
 	}
 
 	ifaref(ifa);
-	ifafree(rt->rt_ifa);
+	old = rt->rt_ifa;
 	rt_set_ifa1(rt, ifa);
+	ifafree(old);
 }
 
 static void



CVS commit: src/sys/net

2018-10-29 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Tue Oct 30 05:29:21 UTC 2018

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

Log Message:
Use atomic operations for ifa_refcnt


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

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

Modified files:

Index: src/sys/net/if.c
diff -u src/sys/net/if.c:1.438 src/sys/net/if.c:1.439
--- src/sys/net/if.c:1.438	Tue Oct 30 05:27:51 2018
+++ src/sys/net/if.c	Tue Oct 30 05:29:21 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.438 2018/10/30 05:27:51 ozaki-r Exp $	*/
+/*	$NetBSD: if.c,v 1.439 2018/10/30 05:29:21 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc.
@@ -90,7 +90,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.438 2018/10/30 05:27:51 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.439 2018/10/30 05:29:21 ozaki-r Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -1784,7 +1784,7 @@ void
 ifaref(struct ifaddr *ifa)
 {
 
-	ifa->ifa_refcnt++;
+	atomic_inc_uint(&ifa->ifa_refcnt);
 }
 
 void
@@ -1793,7 +1793,7 @@ ifafree(struct ifaddr *ifa)
 	KASSERT(ifa != NULL);
 	KASSERT(ifa->ifa_refcnt > 0);
 
-	if (--ifa->ifa_refcnt == 0) {
+	if (atomic_dec_uint_nv(&ifa->ifa_refcnt) == 0) {
 		free(ifa, M_IFADDR);
 	}
 }



CVS commit: src/sys/net

2018-10-29 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Tue Oct 30 05:27:51 UTC 2018

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

Log Message:
Remove a wrong assertion in ifaref

Doing ifref on an ifa with IFA_DESTROYING is not a problem; the reference should
be dropped during the destruction of the ifa.


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

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

Modified files:

Index: src/sys/net/if.c
diff -u src/sys/net/if.c:1.437 src/sys/net/if.c:1.438
--- src/sys/net/if.c:1.437	Thu Oct 18 11:34:54 2018
+++ src/sys/net/if.c	Tue Oct 30 05:27:51 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.437 2018/10/18 11:34:54 knakahara Exp $	*/
+/*	$NetBSD: if.c,v 1.438 2018/10/30 05:27:51 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc.
@@ -90,7 +90,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.437 2018/10/18 11:34:54 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.438 2018/10/30 05:27:51 ozaki-r Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -1783,7 +1783,7 @@ ifa_psref_init(struct ifaddr *ifa)
 void
 ifaref(struct ifaddr *ifa)
 {
-	KASSERT(!ISSET(ifa->ifa_flags, IFA_DESTROYING));
+
 	ifa->ifa_refcnt++;
 }
 



CVS commit: src/sys/netinet6

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

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

Log Message:
Remove a leftover debug printf

Pointed out by hannken@


To generate a diff of this commit:
cvs rdiff -u -r1.239 -r1.240 src/sys/netinet6/icmp6.c

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

Modified files:

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



CVS commit: src/sys/net

2018-09-04 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Wed Sep  5 02:49:09 UTC 2018

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

Log Message:
route: don't take an extra reference of a rtentry for the delayed free mechanism

Because a reference is already taken at that point.


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

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

Modified files:

Index: src/sys/net/route.c
diff -u src/sys/net/route.c:1.211 src/sys/net/route.c:1.212
--- src/sys/net/route.c:1.211	Thu Jul 12 02:26:04 2018
+++ src/sys/net/route.c	Wed Sep  5 02:49:09 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: route.c,v 1.211 2018/07/12 02:26:04 ozaki-r Exp $	*/
+/*	$NetBSD: route.c,v 1.212 2018/09/05 02:49:09 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -97,7 +97,7 @@
 #endif
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.211 2018/07/12 02:26:04 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.212 2018/09/05 02:49:09 ozaki-r Exp $");
 
 #include 
 #ifdef RTFLUSH_DEBUG
@@ -726,7 +726,7 @@ rt_free(struct rtentry *rt)
 	}
 
 	mutex_enter(&rt_free_global.lock);
-	rt_ref(rt);
+	/* No need to add a reference here. */
 	SLIST_INSERT_HEAD(&rt_free_global.queue, rt, rt_free);
 	if (!rt_free_global.enqueued) {
 		workqueue_enqueue(rt_free_global.wq, &rt_free_global.wk, NULL);



CVS commit: src/sys/net

2018-09-04 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Wed Sep  5 02:49:41 UTC 2018

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

Log Message:
route: avoid overwriting rt_free_global.enqueued unexpectedly

rt_free_global.enqueued can be set to true by rt_free during rt_free_work
because rt_free_work releases rt_free_global.lock.  So rt_free_work must update
it once and not update after releasing the lock.


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

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

Modified files:

Index: src/sys/net/route.c
diff -u src/sys/net/route.c:1.212 src/sys/net/route.c:1.213
--- src/sys/net/route.c:1.212	Wed Sep  5 02:49:09 2018
+++ src/sys/net/route.c	Wed Sep  5 02:49:40 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: route.c,v 1.212 2018/09/05 02:49:09 ozaki-r Exp $	*/
+/*	$NetBSD: route.c,v 1.213 2018/09/05 02:49:40 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -97,7 +97,7 @@
 #endif
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.212 2018/09/05 02:49:09 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.213 2018/09/05 02:49:40 ozaki-r Exp $");
 
 #include 
 #ifdef RTFLUSH_DEBUG
@@ -702,8 +702,8 @@ rt_free_work(struct work *wk, void *arg)
 		struct rtentry *rt;
 
 		mutex_enter(&rt_free_global.lock);
-		rt_free_global.enqueued = false;
 		if ((rt = SLIST_FIRST(&rt_free_global.queue)) == NULL) {
+			rt_free_global.enqueued = false;
 			mutex_exit(&rt_free_global.lock);
 			return;
 		}



CVS commit: src/sys/kern

2018-08-30 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Fri Aug 31 01:23:57 UTC 2018

Modified Files:
src/sys/kern: kern_mutex.c kern_rwlock.c

Log Message:
Sprinkle __predict_false to dedicated assertions of mutex and rwlock


To generate a diff of this commit:
cvs rdiff -u -r1.74 -r1.75 src/sys/kern/kern_mutex.c
cvs rdiff -u -r1.51 -r1.52 src/sys/kern/kern_rwlock.c

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

Modified files:

Index: src/sys/kern/kern_mutex.c
diff -u src/sys/kern/kern_mutex.c:1.74 src/sys/kern/kern_mutex.c:1.75
--- src/sys/kern/kern_mutex.c:1.74	Tue Aug 14 01:09:53 2018
+++ src/sys/kern/kern_mutex.c	Fri Aug 31 01:23:57 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_mutex.c,v 1.74 2018/08/14 01:09:53 ozaki-r Exp $	*/
+/*	$NetBSD: kern_mutex.c,v 1.75 2018/08/31 01:23:57 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 2002, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -40,7 +40,7 @@
 #define	__MUTEX_PRIVATE
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_mutex.c,v 1.74 2018/08/14 01:09:53 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_mutex.c,v 1.75 2018/08/31 01:23:57 ozaki-r Exp $");
 
 #include 
 #include 
@@ -96,7 +96,7 @@ __KERNEL_RCSID(0, "$NetBSD: kern_mutex.c
 
 #define	MUTEX_DASSERT(mtx, cond)\
 do {\
-	if (!(cond))		\
+	if (__predict_false(!(cond)))\
 		MUTEX_ABORT(mtx, "assertion failed: " #cond);	\
 } while (/* CONSTCOND */ 0);
 
@@ -110,7 +110,7 @@ do {\
 
 #define	MUTEX_ASSERT(mtx, cond)	\
 do {\
-	if (!(cond))		\
+	if (__predict_false(!(cond)))\
 		MUTEX_ABORT(mtx, "assertion failed: " #cond);	\
 } while (/* CONSTCOND */ 0)
 

Index: src/sys/kern/kern_rwlock.c
diff -u src/sys/kern/kern_rwlock.c:1.51 src/sys/kern/kern_rwlock.c:1.52
--- src/sys/kern/kern_rwlock.c:1.51	Tue Aug 14 01:09:53 2018
+++ src/sys/kern/kern_rwlock.c	Fri Aug 31 01:23:57 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_rwlock.c,v 1.51 2018/08/14 01:09:53 ozaki-r Exp $	*/
+/*	$NetBSD: kern_rwlock.c,v 1.52 2018/08/31 01:23:57 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 2002, 2006, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_rwlock.c,v 1.51 2018/08/14 01:09:53 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_rwlock.c,v 1.52 2018/08/31 01:23:57 ozaki-r Exp $");
 
 #define	__RWLOCK_PRIVATE
 
@@ -73,7 +73,7 @@ __KERNEL_RCSID(0, "$NetBSD: kern_rwlock.
 	(uintptr_t)__builtin_return_address(0), op == RW_READER);
 #define	RW_DASSERT(rw, cond)		\
 do {	\
-	if (!(cond))			\
+	if (__predict_false(!(cond)))	\
 		rw_abort(__func__, __LINE__, rw, "assertion failed: " #cond);\
 } while (/* CONSTCOND */ 0);
 
@@ -94,7 +94,7 @@ do {	\
 
 #define	RW_ASSERT(rw, cond)		\
 do {	\
-	if (!(cond))			\
+	if (__predict_false(!(cond)))	\
 		rw_abort(__func__, __LINE__, rw, "assertion failed: " #cond);\
 } while (/* CONSTCOND */ 0)
 



CVS commit: src/sys/net

2018-08-26 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Mon Aug 27 04:53:24 UTC 2018

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

Log Message:
Restore splx removed accidentally at v1.406

Pointed out by k-goda@IIJ


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

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

Modified files:

Index: src/sys/net/if.c
diff -u src/sys/net/if.c:1.433 src/sys/net/if.c:1.434
--- src/sys/net/if.c:1.433	Fri Aug 10 10:31:01 2018
+++ src/sys/net/if.c	Mon Aug 27 04:53:24 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.433 2018/08/10 10:31:01 knakahara Exp $	*/
+/*	$NetBSD: if.c,v 1.434 2018/08/27 04:53:24 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc.
@@ -90,7 +90,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.433 2018/08/10 10:31:01 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.434 2018/08/27 04:53:24 ozaki-r Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -2326,6 +2326,7 @@ if_link_state_change_softint(struct ifne
 	/* Ensure the change is still valid. */
 	if (ifp->if_link_state == link_state) {
 		IF_LINK_STATE_CHANGE_UNLOCK(ifp);
+		splx(s);
 		return;
 	}
 



CVS commit: src/sys/netipsec

2018-08-22 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Thu Aug 23 01:55:38 UTC 2018

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

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

Use mutex here instead of pserialize because using mutex is simpler than
using psz+ref, which is another solution, and key_checkspidup isn't called in
any performance-sensitive paths.


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

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

Modified files:

Index: src/sys/netipsec/key.c
diff -u src/sys/netipsec/key.c:1.256 src/sys/netipsec/key.c:1.257
--- src/sys/netipsec/key.c:1.256	Wed Jul  4 19:20:25 2018
+++ src/sys/netipsec/key.c	Thu Aug 23 01:55:38 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: key.c,v 1.256 2018/07/04 19:20:25 christos Exp $	*/
+/*	$NetBSD: key.c,v 1.257 2018/08/23 01:55:38 ozaki-r Exp $	*/
 /*	$FreeBSD: key.c,v 1.3.2.3 2004/02/14 22:23:23 bms Exp $	*/
 /*	$KAME: key.c,v 1.191 2001/06/27 10:46:49 sakane Exp $	*/
 
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: key.c,v 1.256 2018/07/04 19:20:25 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: key.c,v 1.257 2018/08/23 01:55:38 ozaki-r Exp $");
 
 /*
  * This code is referred to RFC 2367
@@ -3455,7 +3455,6 @@ key_checkspidup(const struct secasindex 
 {
 	struct secashead *sah;
 	struct secasvar *sav;
-	int s;
 
 	/* check address family */
 	if (saidx->src.sa.sa_family != saidx->dst.sa.sa_family) {
@@ -3466,18 +3465,19 @@ key_checkspidup(const struct secasindex 
 	}
 
 	/* check all SAD */
-	s = pserialize_read_enter();
-	SAHLIST_READER_FOREACH(sah) {
+	/* key_ismyaddr may sleep, so use mutex, not pserialize, here. */
+	mutex_enter(&key_sad.lock);
+	SAHLIST_WRITER_FOREACH(sah) {
 		if (!key_ismyaddr((struct sockaddr *)&sah->saidx.dst))
 			continue;
 		sav = key_getsavbyspi(sah, spi);
 		if (sav != NULL) {
-			pserialize_read_exit(s);
 			KEY_SA_UNREF(&sav);
+			mutex_exit(&key_sad.lock);
 			return true;
 		}
 	}
-	pserialize_read_exit(s);
+	mutex_exit(&key_sad.lock);
 
 	return false;
 }



CVS commit: src/sys/netinet6

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

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

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

Found by knakahara@


To generate a diff of this commit:
cvs rdiff -u -r1.143 -r1.144 src/sys/netinet6/nd6_rtr.c

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

Modified files:

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



CVS commit: src/sys/kern

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

Modified Files:
src/sys/kern: kern_mutex.c kern_rwlock.c

Log Message:
Check pserialize_not_in_read_section for adaptive mutexes and rwlocks

The overhead of the checks is not negligible so they're turned on only if both
DEBUG and LOCKDEBUG are enabled.


To generate a diff of this commit:
cvs rdiff -u -r1.73 -r1.74 src/sys/kern/kern_mutex.c
cvs rdiff -u -r1.50 -r1.51 src/sys/kern/kern_rwlock.c

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

Modified files:

Index: src/sys/kern/kern_mutex.c
diff -u src/sys/kern/kern_mutex.c:1.73 src/sys/kern/kern_mutex.c:1.74
--- src/sys/kern/kern_mutex.c:1.73	Sun Feb 25 18:54:29 2018
+++ src/sys/kern/kern_mutex.c	Tue Aug 14 01:09:53 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_mutex.c,v 1.73 2018/02/25 18:54:29 chs Exp $	*/
+/*	$NetBSD: kern_mutex.c,v 1.74 2018/08/14 01:09:53 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 2002, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -40,7 +40,7 @@
 #define	__MUTEX_PRIVATE
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_mutex.c,v 1.73 2018/02/25 18:54:29 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_mutex.c,v 1.74 2018/08/14 01:09:53 ozaki-r Exp $");
 
 #include 
 #include 
@@ -55,6 +55,7 @@ __KERNEL_RCSID(0, "$NetBSD: kern_mutex.c
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -523,6 +524,7 @@ mutex_vector_enter(kmutex_t *mtx)
 	MUTEX_ASSERT(mtx, curthread != 0);
 	MUTEX_ASSERT(mtx, !cpu_intr_p());
 	MUTEX_WANTLOCK(mtx);
+	KDASSERT(pserialize_not_in_read_section());
 
 	if (panicstr == NULL) {
 		LOCKDEBUG_BARRIER(&kernel_lock, 1);

Index: src/sys/kern/kern_rwlock.c
diff -u src/sys/kern/kern_rwlock.c:1.50 src/sys/kern/kern_rwlock.c:1.51
--- src/sys/kern/kern_rwlock.c:1.50	Mon Feb  5 04:25:04 2018
+++ src/sys/kern/kern_rwlock.c	Tue Aug 14 01:09:53 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_rwlock.c,v 1.50 2018/02/05 04:25:04 ozaki-r Exp $	*/
+/*	$NetBSD: kern_rwlock.c,v 1.51 2018/08/14 01:09:53 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 2002, 2006, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_rwlock.c,v 1.50 2018/02/05 04:25:04 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_rwlock.c,v 1.51 2018/08/14 01:09:53 ozaki-r Exp $");
 
 #define	__RWLOCK_PRIVATE
 
@@ -52,6 +52,7 @@ __KERNEL_RCSID(0, "$NetBSD: kern_rwlock.
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -289,6 +290,7 @@ rw_vector_enter(krwlock_t *rw, const krw
 	RW_ASSERT(rw, !cpu_intr_p());
 	RW_ASSERT(rw, curthread != 0);
 	RW_WANTLOCK(rw, op);
+	KDASSERT(pserialize_not_in_read_section());
 
 	if (panicstr == NULL) {
 		LOCKDEBUG_BARRIER(&kernel_lock, 1);



CVS commit: src/sys/kern

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

Modified Files:
src/sys/kern: kern_synch.c subr_pserialize.c

Log Message:
Change the place to check if a context switch doesn't happen within a 
pserialize read section

The previous place (pserialize_switchpoint) was not a good place because at that
point a suspect thread is already switched so that a backtrace gotten on
a KASSERT failure doesn't point out where a context switch happens.


To generate a diff of this commit:
cvs rdiff -u -r1.317 -r1.318 src/sys/kern/kern_synch.c
cvs rdiff -u -r1.11 -r1.12 src/sys/kern/subr_pserialize.c

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

Modified files:

Index: src/sys/kern/kern_synch.c
diff -u src/sys/kern/kern_synch.c:1.317 src/sys/kern/kern_synch.c:1.318
--- src/sys/kern/kern_synch.c:1.317	Tue Jul 24 15:09:37 2018
+++ src/sys/kern/kern_synch.c	Tue Aug 14 01:06:01 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_synch.c,v 1.317 2018/07/24 15:09:37 bouyer Exp $	*/
+/*	$NetBSD: kern_synch.c,v 1.318 2018/08/14 01:06:01 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2004, 2006, 2007, 2008, 2009
@@ -69,7 +69,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_synch.c,v 1.317 2018/07/24 15:09:37 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_synch.c,v 1.318 2018/08/14 01:06:01 ozaki-r Exp $");
 
 #include "opt_kstack.h"
 #include "opt_dtrace.h"
@@ -699,6 +699,11 @@ mi_switch(lwp_t *l)
 			(*dtrace_vtime_switch_func)(newl);
 		}
 
+		/*
+		 * We must ensure not to come here from inside a read section.
+		 */
+		KASSERT(pserialize_not_in_read_section());
+
 		/* Switch to the new LWP.. */
 #ifdef MULTIPROCESSOR
 		KASSERT(curlwp == ci->ci_curlwp);

Index: src/sys/kern/subr_pserialize.c
diff -u src/sys/kern/subr_pserialize.c:1.11 src/sys/kern/subr_pserialize.c:1.12
--- src/sys/kern/subr_pserialize.c:1.11	Mon Apr 16 20:25:21 2018
+++ src/sys/kern/subr_pserialize.c	Tue Aug 14 01:06:01 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_pserialize.c,v 1.11 2018/04/16 20:25:21 hannken Exp $	*/
+/*	$NetBSD: subr_pserialize.c,v 1.12 2018/08/14 01:06:01 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: subr_pserialize.c,v 1.11 2018/04/16 20:25:21 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_pserialize.c,v 1.12 2018/08/14 01:06:01 ozaki-r Exp $");
 
 #include 
 
@@ -248,9 +248,6 @@ pserialize_switchpoint(void)
 	pserialize_t psz, next;
 	cpuid_t cid;
 
-	/* We must to ensure not to come here from inside a read section. */
-	KASSERT(pserialize_not_in_read_section());
-
 	/*
 	 * If no updates pending, bail out.  No need to lock in order to
 	 * test psz_work_todo; the only ill effect of missing an update



CVS commit: src/doc

2018-08-07 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Tue Aug  7 07:19:28 UTC 2018

Modified Files:
src/doc: TODO.smpnet

Log Message:
Add ipsecif(4)


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

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

Modified files:

Index: src/doc/TODO.smpnet
diff -u src/doc/TODO.smpnet:1.21 src/doc/TODO.smpnet:1.22
--- src/doc/TODO.smpnet:1.21	Tue Aug  7 07:19:09 2018
+++ src/doc/TODO.smpnet	Tue Aug  7 07:19:28 2018
@@ -1,4 +1,4 @@
-$NetBSD: TODO.smpnet,v 1.21 2018/08/07 07:19:09 ozaki-r Exp $
+$NetBSD: TODO.smpnet,v 1.22 2018/08/07 07:19:28 ozaki-r Exp $
 
 MP-safe components
 ==
@@ -21,6 +21,7 @@ kernel option.  Some components scale up
- All except for items in the below section
  - Interfaces
- gif(4)
+   - ipsecif(4)
- l2tp(4)
- pppoe(4)
  - if_spppsubr.c



CVS commit: src/doc

2018-08-07 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Tue Aug  7 07:19:09 UTC 2018

Modified Files:
src/doc: TODO.smpnet

Log Message:
Categorize non MP-safe components into protected and unprotected ones


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

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

Modified files:

Index: src/doc/TODO.smpnet
diff -u src/doc/TODO.smpnet:1.20 src/doc/TODO.smpnet:1.21
--- src/doc/TODO.smpnet:1.20	Mon Jun 25 09:32:28 2018
+++ src/doc/TODO.smpnet	Tue Aug  7 07:19:09 2018
@@ -1,8 +1,11 @@
-$NetBSD: TODO.smpnet,v 1.20 2018/06/25 09:32:28 msaitoh Exp $
+$NetBSD: TODO.smpnet,v 1.21 2018/08/07 07:19:09 ozaki-r Exp $
 
 MP-safe components
 ==
 
+They work without the big kernel lock (KERNEL_LOCK), i.e., with NET_MPSAFE
+kernel option.  Some components scale up and some don't.
+
  - Device drivers
- vioif(4)
- vmx(4)
@@ -34,8 +37,25 @@ MP-safe components
 Non MP-safe components and kernel options
 =
 
+The components and options aren't MP-safe, i.e., requires the big kernel lock,
+yet.  Some of them can be used safely even if NET_MPSAFE is enabled because
+they're still protected by the big kernel lock.  The others aren't protected and
+so unsafe, e.g, they may crash the kernel.
+
+Protected ones
+--
+
  - Device drivers
- Most drivers other than ones listed in the above section
+ - Layer 4
+   - DCCP
+   - SCTP
+   - TCP
+   - UDP
+
+Unprotected ones
+
+
  - Layer 2
- ARCNET (if_arcsubr.c)
- ATM (if_atmsubr.c)
@@ -51,11 +71,6 @@ Non MP-safe components and kernel option
- PIM
- MPLS (mpls(4))
- IPv6 address selection policy
- - Layer 4
-   - DCCP
-   - SCTP
-   - TCP
-   - UDP
  - Interfaces
- agr(4)
- carp(4)



CVS commit: src/sys/net

2018-08-05 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Mon Aug  6 03:58:59 UTC 2018

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

Log Message:
Fix tun(4) kevent locking

filt_tunread gets called in two contexts:

- by calls to selnotify in if_tun.c (or knote, as the case may be,
  but not here), in which case tp->tun_lock is held; and

- by internal logic in kevent, in which tp->tun_lock is not held.

The standard convention to discriminate between these two cases is by
setting the kernel-only NOTE_SUBMIT bit in the hint to selnotify or
knote; then in filt_*:

if (hint & NOTE_SUBMIT)
KASSERT(mutex_owned(&tp->tun_lock));
else
mutex_enter(&tp->tun_lock);
...
if (hint & NOTE_SUBMIT)
KASSERT(mutex_owned(&tp->tun_lock));
else
mutex_exit(&tp->tun_lock);

Pointed out by and patch from riastradh@
Tested by ozaki-r@ (only the former path)


To generate a diff of this commit:
cvs rdiff -u -r1.145 -r1.146 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/if_tun.c
diff -u src/sys/net/if_tun.c:1.145 src/sys/net/if_tun.c:1.146
--- src/sys/net/if_tun.c:1.145	Fri Aug  3 09:54:40 2018
+++ src/sys/net/if_tun.c	Mon Aug  6 03:58:59 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_tun.c,v 1.145 2018/08/03 09:54:40 ozaki-r Exp $	*/
+/*	$NetBSD: if_tun.c,v 1.146 2018/08/06 03:58:59 ozaki-r Exp $	*/
 
 /*
  * Copyright (c) 1988, Julian Onions 
@@ -19,7 +19,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_tun.c,v 1.145 2018/08/03 09:54:40 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_tun.c,v 1.146 2018/08/06 03:58:59 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -288,7 +288,7 @@ tun_clone_destroy(struct ifnet *ifp)
 		tp->tun_flags &= ~TUN_RWAIT;
 		cv_broadcast(&tp->tun_cv);
 	}
-	selnotify(&tp->tun_rsel, 0, 0);
+	selnotify(&tp->tun_rsel, 0, NOTE_SUBMIT);
 
 	mutex_exit(&tp->tun_lock);
 
@@ -381,7 +381,7 @@ tunclose(dev_t dev, int flag, int mode,
 	tp->tun_flags &= ~TUN_OPEN;
 
 	tp->tun_pgid = 0;
-	selnotify(&tp->tun_rsel, 0, 0);
+	selnotify(&tp->tun_rsel, 0, NOTE_SUBMIT);
 
 	TUNDEBUG ("%s: closed\n", ifp->if_xname);
 	mutex_exit(&tp->tun_lock);
@@ -625,7 +625,7 @@ tun_output(struct ifnet *ifp, struct mbu
 	if (tp->tun_flags & TUN_ASYNC && tp->tun_pgid)
 		softint_schedule(tp->tun_isih);
 
-	selnotify(&tp->tun_rsel, 0, 0);
+	selnotify(&tp->tun_rsel, 0, NOTE_SUBMIT);
 
 	mutex_exit(&tp->tun_lock);
 out:
@@ -996,7 +996,7 @@ tunstart(struct ifnet *ifp)
 		if (tp->tun_flags & TUN_ASYNC && tp->tun_pgid)
 			softint_schedule(tp->tun_osih);
 
-		selnotify(&tp->tun_rsel, 0, 0);
+		selnotify(&tp->tun_rsel, 0, NOTE_SUBMIT);
 	}
 	mutex_exit(&tp->tun_lock);
 }
@@ -1057,17 +1057,24 @@ filt_tunread(struct knote *kn, long hint
 	struct tun_softc *tp = kn->kn_hook;
 	struct ifnet *ifp = &tp->tun_if;
 	struct mbuf *m;
+	int ready;
 
-	KASSERT(mutex_owned(&tp->tun_lock));
+	if (hint & NOTE_SUBMIT)
+		KASSERT(mutex_owned(&tp->tun_lock));
+	else
+		mutex_enter(&tp->tun_lock);
 
 	IF_POLL(&ifp->if_snd, m);
-	if (m == NULL)
-		return 0;
-
+	ready = (m != NULL);
 	for (kn->kn_data = 0; m != NULL; m = m->m_next)
 		kn->kn_data += m->m_len;
 
-	return 1;
+	if (hint & NOTE_SUBMIT)
+		KASSERT(mutex_owned(&tp->tun_lock));
+	else
+		mutex_exit(&tp->tun_lock);
+
+	return ready;
 }
 
 static const struct filterops tunread_filtops = {



CVS commit: src/sys/net

2018-08-03 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Fri Aug  3 09:54:40 UTC 2018

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

Log Message:
tun: fix locking against myself

filt_tunread is called with tun_lock held from tun_output (via tun_output =>
selnotify => knote), so we must not take tun_lock in filt_tunread.  The bug
is triggered only if a tun is used through kqueue.

Found by k-goda@IIJ


To generate a diff of this commit:
cvs rdiff -u -r1.144 -r1.145 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/if_tun.c
diff -u src/sys/net/if_tun.c:1.144 src/sys/net/if_tun.c:1.145
--- src/sys/net/if_tun.c:1.144	Tue Jun 26 06:48:02 2018
+++ src/sys/net/if_tun.c	Fri Aug  3 09:54:40 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_tun.c,v 1.144 2018/06/26 06:48:02 msaitoh Exp $	*/
+/*	$NetBSD: if_tun.c,v 1.145 2018/08/03 09:54:40 ozaki-r Exp $	*/
 
 /*
  * Copyright (c) 1988, Julian Onions 
@@ -19,7 +19,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_tun.c,v 1.144 2018/06/26 06:48:02 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_tun.c,v 1.145 2018/08/03 09:54:40 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1058,18 +1058,15 @@ filt_tunread(struct knote *kn, long hint
 	struct ifnet *ifp = &tp->tun_if;
 	struct mbuf *m;
 
-	mutex_enter(&tp->tun_lock);
+	KASSERT(mutex_owned(&tp->tun_lock));
+
 	IF_POLL(&ifp->if_snd, m);
-	if (m == NULL) {
-		mutex_exit(&tp->tun_lock);
+	if (m == NULL)
 		return 0;
-	}
 
 	for (kn->kn_data = 0; m != NULL; m = m->m_next)
 		kn->kn_data += m->m_len;
 
-	mutex_exit(&tp->tun_lock);
-
 	return 1;
 }
 



CVS commit: src/sys/ufs/ffs

2018-07-18 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Thu Jul 19 05:09:34 UTC 2018

Modified Files:
src/sys/ufs/ffs: ffs_alloc.c

Log Message:
Avoid using magic numbers for arguments of workqueue_create (NFC)


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

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

Modified files:

Index: src/sys/ufs/ffs/ffs_alloc.c
diff -u src/sys/ufs/ffs/ffs_alloc.c:1.159 src/sys/ufs/ffs/ffs_alloc.c:1.160
--- src/sys/ufs/ffs/ffs_alloc.c:1.159	Thu Dec  7 21:53:41 2017
+++ src/sys/ufs/ffs/ffs_alloc.c	Thu Jul 19 05:09:34 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_alloc.c,v 1.159 2017/12/07 21:53:41 chs Exp $	*/
+/*	$NetBSD: ffs_alloc.c,v 1.160 2018/07/19 05:09:34 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ffs_alloc.c,v 1.159 2017/12/07 21:53:41 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_alloc.c,v 1.160 2018/07/19 05:09:34 ozaki-r Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -1641,7 +1641,7 @@ ffs_discard_init(struct vnode *devvp, st
 
 	ts = kmem_zalloc(sizeof (*ts), KM_SLEEP);
 	error = workqueue_create(&ts->wq, "trimwq", ffs_discardcb, ts,
- 0, 0, 0);
+ PRI_USER, IPL_NONE, 0);
 	if (error) {
 		kmem_free(ts, sizeof (*ts));
 		return NULL;



CVS commit: src/sys/net

2018-07-11 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Thu Jul 12 02:26:04 UTC 2018

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

Log Message:
Don't use aprint_* functions for logging unrelated to autoconf(9)


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/net/if_llatbl.h
cvs rdiff -u -r1.210 -r1.211 src/sys/net/route.c

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

Modified files:

Index: src/sys/net/if_llatbl.h
diff -u src/sys/net/if_llatbl.h:1.15 src/sys/net/if_llatbl.h:1.16
--- src/sys/net/if_llatbl.h:1.15	Thu Apr 19 21:20:43 2018
+++ src/sys/net/if_llatbl.h	Thu Jul 12 02:26:04 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_llatbl.h,v 1.15 2018/04/19 21:20:43 christos Exp $	*/
+/*	$NetBSD: if_llatbl.h,v 1.16 2018/07/12 02:26:04 ozaki-r Exp $	*/
 /*
  * Copyright (c) 2004 Luigi Rizzo, Alessandro Cerri. All rights reserved.
  * Copyright (c) 2004-2008 Qing Li. All rights reserved.
@@ -37,6 +37,7 @@
 #endif
 
 #include 
+#include 
 
 #include 
 
@@ -106,7 +107,7 @@ struct llentry {
 
 
 #if 0
-#define LLE_LOCK_TRACE(t, lle)	aprint_normal( \
+#define LLE_LOCK_TRACE(t, lle)	log(LOG_DEBUG, \
 "%s:%d: LOCK(" #t "): lle=%p\n", \
 __func__, __LINE__, (lle))
 #else
@@ -142,7 +143,7 @@ struct llentry {
 #define LLE_IS_VALID(lle)	(((lle) != NULL) && ((lle) != (void *)-1))
 
 #if 0
-#define LLE_REF_TRACE(t, n)	aprint_normal("%s:%d: REF(" #t "): refcnt=%d\n", \
+#define LLE_REF_TRACE(t, n)	log(LOG_DEBUG, "%s:%d: REF(" #t "): refcnt=%d\n", \
 __func__, __LINE__, (n))
 #else
 #define LLE_REF_TRACE(t, n)	do {} while (0)

Index: src/sys/net/route.c
diff -u src/sys/net/route.c:1.210 src/sys/net/route.c:1.211
--- src/sys/net/route.c:1.210	Fri Jun  1 07:13:35 2018
+++ src/sys/net/route.c	Thu Jul 12 02:26:04 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: route.c,v 1.210 2018/06/01 07:13:35 ozaki-r Exp $	*/
+/*	$NetBSD: route.c,v 1.211 2018/07/12 02:26:04 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -97,7 +97,7 @@
 #endif
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.210 2018/06/01 07:13:35 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.211 2018/07/12 02:26:04 ozaki-r Exp $");
 
 #include 
 #ifdef RTFLUSH_DEBUG
@@ -509,27 +509,27 @@ dump_rt(const struct rtentry *rt)
 {
 	char buf[512];
 
-	aprint_normal("rt: ");
-	aprint_normal("p=%p ", rt);
+	log(LOG_DEBUG, "rt: ");
+	log(LOG_DEBUG, "p=%p ", rt);
 	if (rt->_rt_key == NULL) {
-		aprint_normal("dst=(NULL) ");
+		log(LOG_DEBUG, "dst=(NULL) ");
 	} else {
 		sockaddr_format(rt->_rt_key, buf, sizeof(buf));
-		aprint_normal("dst=%s ", buf);
+		log(LOG_DEBUG, "dst=%s ", buf);
 	}
 	if (rt->rt_gateway == NULL) {
-		aprint_normal("gw=(NULL) ");
+		log(LOG_DEBUG, "gw=(NULL) ");
 	} else {
 		sockaddr_format(rt->_rt_key, buf, sizeof(buf));
-		aprint_normal("gw=%s ", buf);
+		log(LOG_DEBUG, "gw=%s ", buf);
 	}
-	aprint_normal("flags=%x ", rt->rt_flags);
+	log(LOG_DEBUG, "flags=%x ", rt->rt_flags);
 	if (rt->rt_ifp == NULL) {
-		aprint_normal("if=(NULL) ");
+		log(LOG_DEBUG, "if=(NULL) ");
 	} else {
-		aprint_normal("if=%s ", rt->rt_ifp->if_xname);
+		log(LOG_DEBUG, "if=%s ", rt->rt_ifp->if_xname);
 	}
-	aprint_normal("\n");
+	log(LOG_DEBUG, "\n");
 }
 #endif /* RT_DEBUG */
 



CVS commit: src/usr.sbin/arp

2018-07-10 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Wed Jul 11 03:10:48 UTC 2018

Modified Files:
src/usr.sbin/arp: arp.c

Log Message:
arp: warn if failed to delete a specified arp entry

This restores the original behavior of arp in NetBSD 7.


To generate a diff of this commit:
cvs rdiff -u -r1.61 -r1.62 src/usr.sbin/arp/arp.c

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

Modified files:

Index: src/usr.sbin/arp/arp.c
diff -u src/usr.sbin/arp/arp.c:1.61 src/usr.sbin/arp/arp.c:1.62
--- src/usr.sbin/arp/arp.c:1.61	Sat Jul  7 15:44:27 2018
+++ src/usr.sbin/arp/arp.c	Wed Jul 11 03:10:48 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: arp.c,v 1.61 2018/07/07 15:44:27 christos Exp $ */
+/*	$NetBSD: arp.c,v 1.62 2018/07/11 03:10:48 ozaki-r Exp $ */
 
 /*
  * Copyright (c) 1984, 1993
@@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1984, 19
 #if 0
 static char sccsid[] = "@(#)arp.c	8.3 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: arp.c,v 1.61 2018/07/07 15:44:27 christos Exp $");
+__RCSID("$NetBSD: arp.c,v 1.62 2018/07/11 03:10:48 ozaki-r Exp $");
 #endif
 #endif /* not lint */
 
@@ -502,6 +502,7 @@ delete(const char *host, const char *inf
 	struct rt_msghdr *rtm;
 	struct sockaddr_inarp *sina;
 	struct sockaddr_inarp sin_m = blank_sin; /* struct copy */
+	bool found = false;
 
 	if (host != NULL) {
 		int ret = getinetaddr(host, &sin_m.sin_addr);
@@ -539,12 +540,15 @@ retry:
 		if (host != NULL &&
 		sina->sin_addr.s_addr != sin_m.sin_addr.s_addr)
 			continue;
+		found = true;
 		ret = delete_one(rtm);
 		if (vflag && ret == 0) {
 			(void)printf("%s (%s) deleted\n", host,
 			inet_ntoa(sina->sin_addr));
 		}
 	}
+	if (host != NULL && !found)
+		warnx("delete: can't locate %s", host);
 	free(buf);
 }
 



CVS commit: src/sys/net

2018-07-09 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Tue Jul 10 01:23:13 UTC 2018

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

Log Message:
Don't overwrite an existing llentry on RTM_ADD to avoid race conditions

Reported and tested by christos@


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

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

Modified files:

Index: src/sys/net/if_llatbl.c
diff -u src/sys/net/if_llatbl.c:1.27 src/sys/net/if_llatbl.c:1.28
--- src/sys/net/if_llatbl.c:1.27	Tue Jun  5 01:25:59 2018
+++ src/sys/net/if_llatbl.c	Tue Jul 10 01:23:13 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_llatbl.c,v 1.27 2018/06/05 01:25:59 nonaka Exp $	*/
+/*	$NetBSD: if_llatbl.c,v 1.28 2018/07/10 01:23:13 ozaki-r Exp $	*/
 /*
  * Copyright (c) 2004 Luigi Rizzo, Alessandro Cerri. All rights reserved.
  * Copyright (c) 2004-2008 Qing Li. All rights reserved.
@@ -672,7 +672,7 @@ lla_rt_output(const u_char rtm_type, con
 
 		/* Add static LLE */
 		IF_AFDATA_WLOCK(ifp);
-		lle = lla_lookup(llt, 0, dst);
+		lle = lla_lookup(llt, LLE_EXCLUSIVE, dst);
 
 		/* Cannot overwrite an existing static entry */
 		if (lle != NULL &&
@@ -684,8 +684,18 @@ lla_rt_output(const u_char rtm_type, con
 			error = EEXIST;
 			goto out;
 		}
-		if (lle != NULL)
-			LLE_RUNLOCK(lle);
+
+		/*
+		 * We can't overwrite an existing entry to avoid race
+		 * conditions so remove it first.
+		 */
+		if (lle != NULL) {
+			size_t pkts_dropped = llentry_free(lle);
+			if (dst->sa_family == AF_INET) {
+arp_stat_add(ARP_STAT_DFRDROPPED,
+(uint64_t)pkts_dropped);
+			}
+		}
 
 		lle = lla_create(llt, 0, dst, rt);
 		if (lle == NULL) {



CVS commit: src/sys

2018-07-02 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Tue Jul  3 03:37:04 UTC 2018

Modified Files:
src/sys/kern: init_main.c
src/sys/net: if.c if.h
src/sys/rump/net/lib/libnet: net_component.c

Log Message:
Fix net.inet6.ip6.ifq node doesn't exist

The node (and child nodes) is initialized in sysctl_net_pktq_setup, but the call
of sysctl_net_pktq_setup is skipped unexpectedly.

sysctl_net_pktq_setup is skipped if in6_present is false that indicates the
netinet6 component isn't loaded on rump kernels.  However the flag is
accidentally always false because the flag is turned on in in6_dom_init that is
called after if_sysctl_setup on both normal and rump kernels.

Fix the issue by moving if_sysctl_setup after in6_dom_init (domaininit on normal
kernels).  This fix is ad-hoc but good enough for netbsd-8.  We should refine
the initialization order of network components in the future.

Pointed out by hikaru@


To generate a diff of this commit:
cvs rdiff -u -r1.497 -r1.498 src/sys/kern/init_main.c
cvs rdiff -u -r1.428 -r1.429 src/sys/net/if.c
cvs rdiff -u -r1.263 -r1.264 src/sys/net/if.h
cvs rdiff -u -r1.9 -r1.10 src/sys/rump/net/lib/libnet/net_component.c

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

Modified files:

Index: src/sys/kern/init_main.c
diff -u src/sys/kern/init_main.c:1.497 src/sys/kern/init_main.c:1.498
--- src/sys/kern/init_main.c:1.497	Mon Apr 16 14:51:59 2018
+++ src/sys/kern/init_main.c	Tue Jul  3 03:37:03 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: init_main.c,v 1.497 2018/04/16 14:51:59 kamil Exp $	*/
+/*	$NetBSD: init_main.c,v 1.498 2018/07/03 03:37:03 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -97,7 +97,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.497 2018/04/16 14:51:59 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.498 2018/07/03 03:37:03 ozaki-r Exp $");
 
 #include "opt_ddb.h"
 #include "opt_inet.h"
@@ -572,6 +572,7 @@ main(void)
 	lltableinit();
 #endif
 	domaininit(true);
+	ifinit_post();
 	if_attachdomain();
 	splx(s);
 

Index: src/sys/net/if.c
diff -u src/sys/net/if.c:1.428 src/sys/net/if.c:1.429
--- src/sys/net/if.c:1.428	Tue Jun 26 06:48:02 2018
+++ src/sys/net/if.c	Tue Jul  3 03:37:03 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.428 2018/06/26 06:48:02 msaitoh Exp $	*/
+/*	$NetBSD: if.c,v 1.429 2018/07/03 03:37:03 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc.
@@ -90,7 +90,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.428 2018/06/26 06:48:02 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.429 2018/07/03 03:37:03 ozaki-r Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -279,8 +279,6 @@ void
 ifinit(void)
 {
 
-	if_sysctl_setup(NULL);
-
 #if (defined(INET) || defined(INET6))
 	encapinit();
 #endif
@@ -323,6 +321,14 @@ ifinit1(void)
 #endif
 }
 
+/* XXX must be after domaininit() */
+void
+ifinit_post(void)
+{
+
+	if_sysctl_setup(NULL);
+}
+
 ifnet_t *
 if_alloc(u_char type)
 {

Index: src/sys/net/if.h
diff -u src/sys/net/if.h:1.263 src/sys/net/if.h:1.264
--- src/sys/net/if.h:1.263	Thu Jun 21 10:37:49 2018
+++ src/sys/net/if.h	Tue Jul  3 03:37:03 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.h,v 1.263 2018/06/21 10:37:49 knakahara Exp $	*/
+/*	$NetBSD: if.h,v 1.264 2018/07/03 03:37:03 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc.
@@ -1090,6 +1090,7 @@ void	if_link_state_change_softint(struct
 void	if_up(struct ifnet *);
 void	ifinit(void);
 void	ifinit1(void);
+void	ifinit_post(void);
 int	ifaddrpref_ioctl(struct socket *, u_long, void *, struct ifnet *);
 extern int (*ifioctl)(struct socket *, u_long, void *, struct lwp *);
 int	ifioctl_common(struct ifnet *, u_long, void *);

Index: src/sys/rump/net/lib/libnet/net_component.c
diff -u src/sys/rump/net/lib/libnet/net_component.c:1.9 src/sys/rump/net/lib/libnet/net_component.c:1.10
--- src/sys/rump/net/lib/libnet/net_component.c:1.9	Thu Feb 16 08:39:10 2017
+++ src/sys/rump/net/lib/libnet/net_component.c	Tue Jul  3 03:37:03 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: net_component.c,v 1.9 2017/02/16 08:39:10 knakahara Exp $	*/
+/*	$NetBSD: net_component.c,v 1.10 2018/07/03 03:37:03 ozaki-r Exp $	*/
 
 /*
  * Copyright (c) 2009 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: net_component.c,v 1.9 2017/02/16 08:39:10 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: net_component.c,v 1.10 2018/07/03 03:37:03 ozaki-r Exp $");
 
 #include 
 #include 
@@ -65,5 +65,6 @@ RUMP_COMPONENT(RUMP_COMPONENT_NET_ROUTE)
 RUMP_COMPONENT(RUMP_COMPONENT_NET_IF)
 {
 
+	ifinit_post();
 	loopinit();
 }



CVS commit: src/lib/librumphijack

2018-06-27 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Thu Jun 28 06:20:36 UTC 2018

Modified Files:
src/lib/librumphijack: hijack.c

Log Message:
rumphijack: don't modify a cmsg on just validating it

Pointed out by k-goda@IIJ


To generate a diff of this commit:
cvs rdiff -u -r1.124 -r1.125 src/lib/librumphijack/hijack.c

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

Modified files:

Index: src/lib/librumphijack/hijack.c
diff -u src/lib/librumphijack/hijack.c:1.124 src/lib/librumphijack/hijack.c:1.125
--- src/lib/librumphijack/hijack.c:1.124	Mon Oct 23 06:52:17 2017
+++ src/lib/librumphijack/hijack.c	Thu Jun 28 06:20:36 2018
@@ -1,4 +1,4 @@
-/*  $NetBSD: hijack.c,v 1.124 2017/10/23 06:52:17 ozaki-r Exp $	*/
+/*  $NetBSD: hijack.c,v 1.125 2018/06/28 06:20:36 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 2011 Antti Kantee.  All Rights Reserved.
@@ -34,7 +34,7 @@
 #include 
 
 #if !defined(lint)
-__RCSID("$NetBSD: hijack.c,v 1.124 2017/10/23 06:52:17 ozaki-r Exp $");
+__RCSID("$NetBSD: hijack.c,v 1.125 2018/06/28 06:20:36 ozaki-r Exp $");
 #endif
 
 #include 
@@ -1587,7 +1587,7 @@ write(int fd, const void *buf, size_t bl
  */
 
 static int
-msg_convert(struct msghdr *msg, int (*func)(int))
+_msg_convert_fds(struct msghdr *msg, int (*func)(int), bool dryrun)
 {
 	struct cmsghdr *cmsg;
 
@@ -1607,7 +1607,8 @@ msg_convert(struct msghdr *msg, int (*fu
 if (newval < 0) {
 	return ENOTSUP;
 }
-*fdp = newval;
+if (!dryrun)
+	*fdp = newval;
 fdp++;
 			}
 		}
@@ -1615,6 +1616,20 @@ msg_convert(struct msghdr *msg, int (*fu
 	return 0;
 }
 
+static int
+msg_convert_fds(struct msghdr *msg, int (*func)(int))
+{
+
+	return _msg_convert_fds(msg, func, false);
+}
+
+static int
+msg_check_fds(struct msghdr *msg, int (*func)(int))
+{
+
+	return _msg_convert_fds(msg, func, true);
+}
+
 ssize_t
 recvmsg(int fd, struct msghdr *msg, int flags)
 {
@@ -1636,9 +1651,9 @@ recvmsg(int fd, struct msghdr *msg, int 
 	 * convert descriptors in the message.
 	 */
 	if (isrump) {
-		msg_convert(msg, fd_rump2host);
+		msg_convert_fds(msg, fd_rump2host);
 	} else {
-		msg_convert(msg, fd_host2host);
+		msg_convert_fds(msg, fd_host2host);
 	}
 	return ret;
 }
@@ -1681,7 +1696,7 @@ sendmsg(int fd, const struct msghdr *msg
 	/*
 	 * reject descriptors from a different kernel.
 	 */
-	error = msg_convert(__UNCONST(msg),
+	error = msg_check_fds(__UNCONST(msg),
 	isrump ? fd_check_rump: fd_check_host);
 	if (error != 0) {
 		errno = error;
@@ -1700,7 +1715,7 @@ sendmsg(int fd, const struct msghdr *msg
 		 *
 		 * it's safer to copy and modify instead.
 		 */
-		msg_convert(__UNCONST(msg), fd_host2rump);
+		msg_convert_fds(__UNCONST(msg), fd_host2rump);
 		op_sendmsg = GETSYSCALL(rump, SENDMSG);
 	} else {
 		op_sendmsg = GETSYSCALL(host, SENDMSG);



CVS commit: src/sys/net

2018-06-27 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Thu Jun 28 06:02:24 UTC 2018

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

Log Message:
loop: don't allocate a unnecessary link-state-change thread


To generate a diff of this commit:
cvs rdiff -u -r1.102 -r1.103 src/sys/net/if_loop.c

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

Modified files:

Index: src/sys/net/if_loop.c
diff -u src/sys/net/if_loop.c:1.102 src/sys/net/if_loop.c:1.103
--- src/sys/net/if_loop.c:1.102	Tue Jun 26 06:48:02 2018
+++ src/sys/net/if_loop.c	Thu Jun 28 06:02:24 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_loop.c,v 1.102 2018/06/26 06:48:02 msaitoh Exp $	*/
+/*	$NetBSD: if_loop.c,v 1.103 2018/06/28 06:02:24 ozaki-r Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -65,7 +65,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_loop.c,v 1.102 2018/06/26 06:48:02 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_loop.c,v 1.103 2018/06/28 06:02:24 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -183,8 +183,9 @@ loop_clone_create(struct if_clone *ifc, 
 
 	ifp->if_mtu = LOMTU;
 	ifp->if_flags = IFF_LOOPBACK | IFF_MULTICAST;
+	ifp->if_extflags = IFEF_NO_LINK_STATE_CHANGE;
 #ifdef NET_MPSAFE
-	ifp->if_extflags = IFEF_MPSAFE;
+	ifp->if_extflags |= IFEF_MPSAFE;
 #endif
 	ifp->if_ioctl = loioctl;
 	ifp->if_output = looutput;



  1   2   3   4   5   6   7   8   9   10   >