CVS commit: src/sys

2024-04-11 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Apr 11 07:34:37 UTC 2024

Modified Files:
src/sys/netinet: sctp_asconf.c
src/sys/netinet6: in6_ifattach.c nd6.c

Log Message:
Fix invalid IPv6 route when ipsecif(4) is deleted tunnel.  Pointed out by 
ohishi@IIJ.

The pointed bug is fixed by modification in nd6_need_cache().
Others are similar bugs.

XXX pullup-9, 10


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/netinet/sctp_asconf.c
cvs rdiff -u -r1.121 -r1.122 src/sys/netinet6/in6_ifattach.c
cvs rdiff -u -r1.281 -r1.282 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/netinet/sctp_asconf.c
diff -u src/sys/netinet/sctp_asconf.c:1.13 src/sys/netinet/sctp_asconf.c:1.14
--- src/sys/netinet/sctp_asconf.c:1.13	Fri Feb  9 22:08:37 2024
+++ src/sys/netinet/sctp_asconf.c	Thu Apr 11 07:34:37 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: sctp_asconf.c,v 1.13 2024/02/09 22:08:37 andvar Exp $ */
+/*	$NetBSD: sctp_asconf.c,v 1.14 2024/04/11 07:34:37 knakahara Exp $ */
 /*	$KAME: sctp_asconf.c,v 1.25 2005/06/16 20:44:24 jinmei Exp $	*/
 
 /*
@@ -30,7 +30,7 @@
  * SUCH DAMAGE.
  */
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sctp_asconf.c,v 1.13 2024/02/09 22:08:37 andvar Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sctp_asconf.c,v 1.14 2024/04/11 07:34:37 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ipsec.h"
@@ -1540,6 +1540,7 @@ sctp_is_desired_interface_type(struct if
 	case IFT_XETHER:
 	case IFT_SLIP:
 	case IFT_GIF:
+	case IFT_IPSEC:
 		result = 1;
 		break;
 	default:

Index: src/sys/netinet6/in6_ifattach.c
diff -u src/sys/netinet6/in6_ifattach.c:1.121 src/sys/netinet6/in6_ifattach.c:1.122
--- src/sys/netinet6/in6_ifattach.c:1.121	Thu Dec 22 02:52:35 2022
+++ src/sys/netinet6/in6_ifattach.c	Thu Apr 11 07:34:37 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: in6_ifattach.c,v 1.121 2022/12/22 02:52:35 msaitoh Exp $	*/
+/*	$NetBSD: in6_ifattach.c,v 1.122 2024/04/11 07:34:37 knakahara Exp $	*/
 /*	$KAME: in6_ifattach.c,v 1.124 2001/07/18 08:32:51 jinmei Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in6_ifattach.c,v 1.121 2022/12/22 02:52:35 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6_ifattach.c,v 1.122 2024/04/11 07:34:37 knakahara Exp $");
 
 #include 
 #include 
@@ -262,6 +262,7 @@ in6_get_hw_ifid(struct ifnet *ifp, struc
 		break;
 
 	case IFT_GIF:
+	case IFT_IPSEC:
 #ifdef IFT_STF
 	case IFT_STF:
 #endif

Index: src/sys/netinet6/nd6.c
diff -u src/sys/netinet6/nd6.c:1.281 src/sys/netinet6/nd6.c:1.282
--- src/sys/netinet6/nd6.c:1.281	Sat Dec  9 15:21:02 2023
+++ src/sys/netinet6/nd6.c	Thu Apr 11 07:34:37 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: nd6.c,v 1.281 2023/12/09 15:21:02 pgoyette Exp $	*/
+/*	$NetBSD: nd6.c,v 1.282 2024/04/11 07:34:37 knakahara 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.281 2023/12/09 15:21:02 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nd6.c,v 1.282 2024/04/11 07:34:37 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -1655,6 +1655,7 @@ nd6_need_cache(struct ifnet *ifp)
 	case IFT_IEEE1394:
 	case IFT_CARP:
 	case IFT_GIF:		/* XXX need more cases? */
+	case IFT_IPSEC:
 	case IFT_PPP:
 	case IFT_TUNNEL:
 		return 1;



CVS commit: src/sys

2024-04-11 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Apr 11 07:34:37 UTC 2024

Modified Files:
src/sys/netinet: sctp_asconf.c
src/sys/netinet6: in6_ifattach.c nd6.c

Log Message:
Fix invalid IPv6 route when ipsecif(4) is deleted tunnel.  Pointed out by 
ohishi@IIJ.

The pointed bug is fixed by modification in nd6_need_cache().
Others are similar bugs.

XXX pullup-9, 10


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/netinet/sctp_asconf.c
cvs rdiff -u -r1.121 -r1.122 src/sys/netinet6/in6_ifattach.c
cvs rdiff -u -r1.281 -r1.282 src/sys/netinet6/nd6.c

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



CVS commit: src/tests/net/if_ipsec

2023-09-27 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Sep 27 08:48:01 UTC 2023

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

Log Message:
Update for sys/net/if_ipsec.c:r1.35


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

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

Modified files:

Index: src/tests/net/if_ipsec/t_ipsec_unnumbered.sh
diff -u src/tests/net/if_ipsec/t_ipsec_unnumbered.sh:1.1 src/tests/net/if_ipsec/t_ipsec_unnumbered.sh:1.2
--- src/tests/net/if_ipsec/t_ipsec_unnumbered.sh:1.1	Fri Nov 25 08:43:16 2022
+++ src/tests/net/if_ipsec/t_ipsec_unnumbered.sh	Wed Sep 27 08:48:01 2023
@@ -1,4 +1,4 @@
-#	$NetBSD: t_ipsec_unnumbered.sh,v 1.1 2022/11/25 08:43:16 knakahara Exp $
+#	$NetBSD: t_ipsec_unnumbered.sh,v 1.2 2023/09/27 08:48:01 knakahara Exp $
 #
 # Copyright (c) 2022 Internet Initiative Japan Inc.
 # All rights reserved.
@@ -73,7 +73,7 @@ add_sa()
 	local tmpfile=./tmp
 	local spi=1
 	local algo_args="$(generate_algo_args esp $algo)"
-	local uniq=8200 # 8192(reqid_base) + 2 * 4(lo0, shmif0, shmif1 and ipsec0)
+	local uniq=8192 # 8192(reqid_base) + 2 * 0(unit id of "ipsec0")
 
 	export RUMP_SERVER=$SOCK_LOCAL
 	cat > $tmpfile <<-EOF



CVS commit: src/tests/net/if_ipsec

2023-09-27 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Sep 27 08:48:01 UTC 2023

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

Log Message:
Update for sys/net/if_ipsec.c:r1.35


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

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



CVS commit: src/sys/net

2023-09-25 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Tue Sep 26 03:43:27 UTC 2023

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

Log Message:
Use unit id instead of if_index to reduce fixed_reqid space.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sys/net/if_ipsec.c

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



CVS commit: src/sys/net

2023-09-25 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Tue Sep 26 03:43:27 UTC 2023

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

Log Message:
Use unit id instead of if_index to reduce fixed_reqid space.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sys/net/if_ipsec.c

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

Modified files:

Index: src/sys/net/if_ipsec.c
diff -u src/sys/net/if_ipsec.c:1.34 src/sys/net/if_ipsec.c:1.35
--- src/sys/net/if_ipsec.c:1.34	Tue Oct 11 09:51:47 2022
+++ src/sys/net/if_ipsec.c	Tue Sep 26 03:43:27 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ipsec.c,v 1.34 2022/10/11 09:51:47 knakahara Exp $  */
+/*	$NetBSD: if_ipsec.c,v 1.35 2023/09/26 03:43:27 knakahara Exp $  */
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_ipsec.c,v 1.34 2022/10/11 09:51:47 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ipsec.c,v 1.35 2023/09/26 03:43:27 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1798,9 +1798,10 @@ if_ipsec_get_reqids(struct ipsec_variant
 
 	mutex_enter(_softcs.lock);
 	if (ipsec_softcs.use_fixed_reqid) {
-		uint32_t reqid_base;
+		uint32_t unit, reqid_base;
 
-		reqid_base = ipsec_softcs.reqid_base + ifp->if_index * 2;
+		unit = strtoul(ifp->if_xname + sizeof("ipsec") - 1, NULL, 10);
+		reqid_base = ipsec_softcs.reqid_base + unit * 2;
 		if (reqid_base + 1 > ipsec_softcs.reqid_last) {
 			log(LOG_ERR,
 			"%s: invalid fixed reqid(%"PRIu32"), "



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

2023-08-10 Thread Kengo NAKAHARA

Hi,

On 2023/08/10 18:07, Nick Hudson wrote:

On 10/08/2023 09:42, Kengo NAKAHARA wrote:

Hi,

Could you tell me how you test this fix for future reference?


He didn't - I did. :)

Taylor suggested running with network traffic and doing ifconfig
down/up. To generate network traffic Taylor suggested


host$ nc -l 54321 /dev/null
guest$ nc host 54321 /dev/null

and I did

 for i in `jot 64`; do
     ifconfig vmx0 down
     sleep 1
     ifconfig vmx0 up
 done

Nick


I see.  I want to know the traffic generator and ioctl jobs, that is
exactly what is.  Thank you for your comment.


Thanks,

--
//
Internet Initiative Japan Inc.

Device Engineering Section,
Core Product Development Department,
Network Division,
Technology Unit

Kengo NAKAHARA 




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

2023-08-10 Thread Kengo NAKAHARA

Hi,

Could you tell me how you test this fix for future reference?


Thanks,

On 2023/08/10 17:24, Taylor R Campbell wrote:

Module Name:src
Committed By:   riastradh
Date:   Thu Aug 10 08:24:45 UTC 2023

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

Log Message:
vmxnet(4): Fix various MP bugs.

- Defer reset to workqueue.
   => vmxnet3_stop_locked is forbidden in softint.
   => XXX Problem: We still take the core lock in softint, and we
  still take the core lock around vmxnet3_stop_locked.  TBD.
- Touch if_flags only under IFNET_LOCK.
   => Cache ifp->if_flags & IFF_PROMISC in vmxnet3_ifflags_cb.
   => Don't call vmxnet3_set_rxfilter unless up and running; cache
  this as vmx_mcastactive.  Use ENETRESET in vmxnet3_ifflags_cb
  instead of calling vmxnet3_set_rxfilter directly.
  . (The cache is currently serialized by the core lock, but it
might reasonably be serialized by an independent lock like in
usbnet(9).)
- Fix vmxnet3_stop_rendezvous so it actually does something.
   => New vxtxq_stopping, vxrxq_stopping variables synchronize with
  Rx/Tx interrupt handlers.
- Sprinkle IFNET_LOCK and core lock assertions.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/dev/pci/if_vmx.c

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



--
//
Internet Initiative Japan Inc.

Device Engineering Section,
Core Product Development Department,
Network Division,
Technology Unit

Kengo NAKAHARA 




CVS commit: src/sys/netipsec

2023-07-20 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Jul 21 00:44:38 UTC 2023

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

Log Message:
Use kmem_free instead of kmem_intr_free, as key_freesaval() is not called in 
softint after key.c:r1.223.

E.g. key_freesaval() was called the following call path before SAD MP-ify.
  esp_input_cb()
KEY_FREESAV()
  key_freesav()
key_delsav()
  key_freesaval()

ok'ed by ozaki-r@n.o.


To generate a diff of this commit:
cvs rdiff -u -r1.280 -r1.281 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.280 src/sys/netipsec/key.c:1.281
--- src/sys/netipsec/key.c:1.280	Thu Dec  8 08:07:07 2022
+++ src/sys/netipsec/key.c	Fri Jul 21 00:44:38 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: key.c,v 1.280 2022/12/08 08:07:07 knakahara Exp $	*/
+/*	$NetBSD: key.c,v 1.281 2023/07/21 00:44:38 knakahara 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.280 2022/12/08 08:07:07 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: key.c,v 1.281 2023/07/21 00:44:38 knakahara Exp $");
 
 /*
  * This code is referred to RFC 2367
@@ -3589,21 +3589,21 @@ key_freesaval(struct secasvar *sav)
 	key_sa_refcnt(sav));
 
 	if (sav->replay != NULL)
-		kmem_intr_free(sav->replay, sav->replay_len);
+		kmem_free(sav->replay, sav->replay_len);
 	if (sav->key_auth != NULL)
-		kmem_intr_free(sav->key_auth, sav->key_auth_len);
+		kmem_free(sav->key_auth, sav->key_auth_len);
 	if (sav->key_enc != NULL)
-		kmem_intr_free(sav->key_enc, sav->key_enc_len);
+		kmem_free(sav->key_enc, sav->key_enc_len);
 	if (sav->lft_c_counters_percpu != NULL) {
 		percpu_free(sav->lft_c_counters_percpu,
 		sizeof(lifetime_counters_t));
 	}
 	if (sav->lft_c != NULL)
-		kmem_intr_free(sav->lft_c, sizeof(*(sav->lft_c)));
+		kmem_free(sav->lft_c, sizeof(*(sav->lft_c)));
 	if (sav->lft_h != NULL)
-		kmem_intr_free(sav->lft_h, sizeof(*(sav->lft_h)));
+		kmem_free(sav->lft_h, sizeof(*(sav->lft_h)));
 	if (sav->lft_s != NULL)
-		kmem_intr_free(sav->lft_s, sizeof(*(sav->lft_s)));
+		kmem_free(sav->lft_s, sizeof(*(sav->lft_s)));
 }
 
 /*



CVS commit: src/sys/netipsec

2023-07-20 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Jul 21 00:44:38 UTC 2023

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

Log Message:
Use kmem_free instead of kmem_intr_free, as key_freesaval() is not called in 
softint after key.c:r1.223.

E.g. key_freesaval() was called the following call path before SAD MP-ify.
  esp_input_cb()
KEY_FREESAV()
  key_freesav()
key_delsav()
  key_freesaval()

ok'ed by ozaki-r@n.o.


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

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



CVS commit: src/tests/net/ipsec

2023-06-19 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Jun 19 08:28:09 UTC 2023

Modified Files:
src/tests/net/ipsec: t_ipsec_ah_keys.sh t_ipsec_esp_keys.sh
t_ipsec_transport.sh t_ipsec_tunnel.sh t_ipsec_tunnel_ipcomp.sh
t_ipsec_tunnel_odd.sh

Log Message:
Repair test coverage.  I revert by proxy as the committer seems too busy to 
even reply mail.

TODO:
Provide some way for small machines to run subset test so that they get
shorter run time at the expense of test coverage.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/net/ipsec/t_ipsec_ah_keys.sh \
src/tests/net/ipsec/t_ipsec_esp_keys.sh \
src/tests/net/ipsec/t_ipsec_tunnel_ipcomp.sh
cvs rdiff -u -r1.7 -r1.8 src/tests/net/ipsec/t_ipsec_transport.sh
cvs rdiff -u -r1.10 -r1.11 src/tests/net/ipsec/t_ipsec_tunnel.sh
cvs rdiff -u -r1.4 -r1.5 src/tests/net/ipsec/t_ipsec_tunnel_odd.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_ah_keys.sh
diff -u src/tests/net/ipsec/t_ipsec_ah_keys.sh:1.3 src/tests/net/ipsec/t_ipsec_ah_keys.sh:1.4
--- src/tests/net/ipsec/t_ipsec_ah_keys.sh:1.3	Sun Jun  4 22:18:47 2023
+++ src/tests/net/ipsec/t_ipsec_ah_keys.sh	Mon Jun 19 08:28:09 2023
@@ -1,4 +1,4 @@
-#	$NetBSD: t_ipsec_ah_keys.sh,v 1.3 2023/06/04 22:18:47 chs Exp $
+#	$NetBSD: t_ipsec_ah_keys.sh,v 1.4 2023/06/19 08:28:09 knakahara Exp $
 #
 # Copyright (c) 2017 Internet Initiative Japan Inc.
 # All rights reserved.
@@ -152,7 +152,7 @@ add_test_invalid_keys()
 atf_init_test_cases()
 {
 
-	for aalgo in $AH_AUTHENTICATION_ALGORITHMS_MINIMUM; do
+	for aalgo in $AH_AUTHENTICATION_ALGORITHMS; do
 		add_test_valid_keys $aalgo
 		add_test_invalid_keys $aalgo
 	done
Index: src/tests/net/ipsec/t_ipsec_esp_keys.sh
diff -u src/tests/net/ipsec/t_ipsec_esp_keys.sh:1.3 src/tests/net/ipsec/t_ipsec_esp_keys.sh:1.4
--- src/tests/net/ipsec/t_ipsec_esp_keys.sh:1.3	Sun Jun  4 22:18:47 2023
+++ src/tests/net/ipsec/t_ipsec_esp_keys.sh	Mon Jun 19 08:28:09 2023
@@ -1,4 +1,4 @@
-#	$NetBSD: t_ipsec_esp_keys.sh,v 1.3 2023/06/04 22:18:47 chs Exp $
+#	$NetBSD: t_ipsec_esp_keys.sh,v 1.4 2023/06/19 08:28:09 knakahara Exp $
 #
 # Copyright (c) 2017 Internet Initiative Japan Inc.
 # All rights reserved.
@@ -152,7 +152,7 @@ add_test_invalid_keys()
 atf_init_test_cases()
 {
 
-	for ealgo in $ESP_ENCRYPTION_ALGORITHMS_MINIMUM; do
+	for ealgo in $ESP_ENCRYPTION_ALGORITHMS; do
 		add_test_valid_keys $ealgo
 		add_test_invalid_keys $ealgo
 	done
Index: src/tests/net/ipsec/t_ipsec_tunnel_ipcomp.sh
diff -u src/tests/net/ipsec/t_ipsec_tunnel_ipcomp.sh:1.3 src/tests/net/ipsec/t_ipsec_tunnel_ipcomp.sh:1.4
--- src/tests/net/ipsec/t_ipsec_tunnel_ipcomp.sh:1.3	Sun Jun  4 22:18:47 2023
+++ src/tests/net/ipsec/t_ipsec_tunnel_ipcomp.sh	Mon Jun 19 08:28:09 2023
@@ -1,4 +1,4 @@
-#	$NetBSD: t_ipsec_tunnel_ipcomp.sh,v 1.3 2023/06/04 22:18:47 chs Exp $
+#	$NetBSD: t_ipsec_tunnel_ipcomp.sh,v 1.4 2023/06/19 08:28:09 knakahara Exp $
 #
 # Copyright (c) 2017 Internet Initiative Japan Inc.
 # All rights reserved.
@@ -395,7 +395,7 @@ atf_init_test_cases()
 {
 	local calgo= algo=
 
-	for calgo in $IPCOMP_COMPRESSION_ALGORITHMS_MINIMUM; do
+	for calgo in $IPCOMP_COMPRESSION_ALGORITHMS; do
 		for algo in $ESP_ENCRYPTION_ALGORITHMS_MINIMUM; do
 			add_test_tunnel_mode ipv4 esp $algo $calgo
 			add_test_tunnel_mode ipv6 esp $algo $calgo

Index: src/tests/net/ipsec/t_ipsec_transport.sh
diff -u src/tests/net/ipsec/t_ipsec_transport.sh:1.7 src/tests/net/ipsec/t_ipsec_transport.sh:1.8
--- src/tests/net/ipsec/t_ipsec_transport.sh:1.7	Sun Jun  4 22:18:47 2023
+++ src/tests/net/ipsec/t_ipsec_transport.sh	Mon Jun 19 08:28:09 2023
@@ -1,4 +1,4 @@
-#	$NetBSD: t_ipsec_transport.sh,v 1.7 2023/06/04 22:18:47 chs Exp $
+#	$NetBSD: t_ipsec_transport.sh,v 1.8 2023/06/19 08:28:09 knakahara Exp $
 #
 # Copyright (c) 2017 Internet Initiative Japan Inc.
 # All rights reserved.
@@ -261,15 +261,15 @@ atf_init_test_cases()
 {
 	local algo=
 
-	for algo in $ESP_ENCRYPTION_ALGORITHMS_MINIMUM; do
+	for algo in $ESP_ENCRYPTION_ALGORITHMS; do
 		add_test_transport_mode ipv4 esp $algo
 		add_test_transport_mode ipv6 esp $algo
 	done
-	for algo in $AH_AUTHENTICATION_ALGORITHMS_MINIMUM; do
+	for algo in $AH_AUTHENTICATION_ALGORITHMS; do
 		add_test_transport_mode ipv4 ah $algo
 		add_test_transport_mode ipv6 ah $algo
 	done
-	for algo in $IPCOMP_COMPRESSION_ALGORITHMS_MINIMUM; do
+	for algo in $IPCOMP_COMPRESSION_ALGORITHMS; do
 		add_test_transport_mode ipv4 ipcomp $algo
 		add_test_transport_mode ipv6 ipcomp $algo
 	done

Index: src/tests/net/ipsec/t_ipsec_tunnel.sh
diff -u src/tests/net/ipsec/t_ipsec_tunnel.sh:1.10 src/tests/net/ipsec/t_ipsec_tunnel.sh:1.11
--- src/tests/net/ipsec/t_ipsec_tunnel.sh:1.10	Sun Jun  4 22:18:47 2023
+++ src/tests/net/ipsec/t_ipsec_tunnel.sh	Mon Jun 19 08:28:09 2023
@@ -1,4 +1,4 @@
-#	$NetBSD: t_ipsec_tunnel.sh,v 1.10 2023/06/04 22:18:47 chs Exp $

CVS commit: src/tests/net/ipsec

2023-06-19 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Jun 19 08:28:09 UTC 2023

Modified Files:
src/tests/net/ipsec: t_ipsec_ah_keys.sh t_ipsec_esp_keys.sh
t_ipsec_transport.sh t_ipsec_tunnel.sh t_ipsec_tunnel_ipcomp.sh
t_ipsec_tunnel_odd.sh

Log Message:
Repair test coverage.  I revert by proxy as the committer seems too busy to 
even reply mail.

TODO:
Provide some way for small machines to run subset test so that they get
shorter run time at the expense of test coverage.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/net/ipsec/t_ipsec_ah_keys.sh \
src/tests/net/ipsec/t_ipsec_esp_keys.sh \
src/tests/net/ipsec/t_ipsec_tunnel_ipcomp.sh
cvs rdiff -u -r1.7 -r1.8 src/tests/net/ipsec/t_ipsec_transport.sh
cvs rdiff -u -r1.10 -r1.11 src/tests/net/ipsec/t_ipsec_tunnel.sh
cvs rdiff -u -r1.4 -r1.5 src/tests/net/ipsec/t_ipsec_tunnel_odd.sh

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



CVS commit: src/sys/net

2023-01-03 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Jan  4 01:58:33 UTC 2023

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

Log Message:
Fix libreswan build failure.  Pointed out by Andrew Cagney, thanks.


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

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



CVS commit: src/sys/net

2023-01-03 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Jan  4 01:58:33 UTC 2023

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

Log Message:
Fix libreswan build failure.  Pointed out by Andrew Cagney, thanks.


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

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

Modified files:

Index: src/sys/net/pfkeyv2.h
diff -u src/sys/net/pfkeyv2.h:1.34 src/sys/net/pfkeyv2.h:1.35
--- src/sys/net/pfkeyv2.h:1.34	Tue Oct 11 09:51:47 2022
+++ src/sys/net/pfkeyv2.h	Wed Jan  4 01:58:33 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: pfkeyv2.h,v 1.34 2022/10/11 09:51:47 knakahara Exp $	*/
+/*	$NetBSD: pfkeyv2.h,v 1.35 2023/01/04 01:58:33 knakahara Exp $	*/
 /*	$KAME: pfkeyv2.h,v 1.36 2003/07/25 09:33:37 itojun Exp $	*/
 
 /*
@@ -230,6 +230,7 @@ struct sadb_x_policy {
   uint8_t sadb_x_policy_dir;		/* direction, see ipsec.h */
   uint8_t sadb_x_policy_flags;
 #define IPSEC_POLICY_FLAG_ORIGIN_KERNEL 0x80	/* policy is generated by kernel */
+#define	sadb_x_policy_reserved	sadb_x_policy_flags
   uint32_t sadb_x_policy_id;
   uint32_t sadb_x_policy_reserved2;
 };



CVS commit: src/sys/dev/ic

2022-12-08 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Dec  9 00:35:58 UTC 2022

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

Log Message:
Revert com.c:r1.381 because i386/qemu cannot boot.  Pointed out by gson@n.o and 
martin@n.o.


To generate a diff of this commit:
cvs rdiff -u -r1.381 -r1.382 src/sys/dev/ic/com.c

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/com.c
diff -u src/sys/dev/ic/com.c:1.381 src/sys/dev/ic/com.c:1.382
--- src/sys/dev/ic/com.c:1.381	Thu Dec  8 09:08:49 2022
+++ src/sys/dev/ic/com.c	Fri Dec  9 00:35:58 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: com.c,v 1.381 2022/12/08 09:08:49 knakahara Exp $ */
+/* $NetBSD: com.c,v 1.382 2022/12/09 00:35:58 knakahara Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2004, 2008 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: com.c,v 1.381 2022/12/08 09:08:49 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: com.c,v 1.382 2022/12/09 00:35:58 knakahara Exp $");
 
 #include "opt_com.h"
 #include "opt_ddb.h"
@@ -206,28 +206,6 @@ static struct consdev comcons = {
 	.cn_pri = CN_NORMAL
 };
 
-#define	CSR_WRITE_1_SYNC(r, o, v)	do {			\
-		CSR_WRITE_1(r, o, v);\
-		switch(o) {	\
-		case COM_REG_IER:\
-			(void)CSR_READ_1(r, COM_REG_IIR);	\
-			break;	\
-		case COM_REG_TXDATA:\
-			(void)CSR_READ_1(r, COM_REG_TLR);	\
-			break;	\
-		}		\
-	} while(0)
-#define	CSR_WRITE_MULTI_SYNC(r, o, p, n)	do {		\
-		CSR_WRITE_MULTI(r, o, p, n);			\
-		switch(o) {	\
-		case COM_REG_IER:\
-			(void)CSR_READ_1(r, COM_REG_IIR);	\
-			break;	\
-		case COM_REG_TXDATA:\
-			(void)CSR_READ_1(r, COM_REG_TLR);	\
-			break;	\
-		}		\
-	} while(0)
 
 const struct cdevsw com_cdevsw = {
 	.d_open = comopen,
@@ -1983,7 +1961,7 @@ comstart(struct tty *tp)
 	/* Enable transmit completion interrupts if necessary. */
 	if (!ISSET(sc->sc_ier, IER_ETXRDY)) {
 		SET(sc->sc_ier, IER_ETXRDY);
-		CSR_WRITE_1_SYNC(regsp, COM_REG_IER, sc->sc_ier);
+		CSR_WRITE_1(regsp, COM_REG_IER, sc->sc_ier);
 	}
 
 	/* Output the first chunk of the contiguous buffer. */
@@ -1993,7 +1971,7 @@ comstart(struct tty *tp)
 		n = sc->sc_tbc;
 		if (n > sc->sc_fifolen)
 			n = sc->sc_fifolen;
-		CSR_WRITE_MULTI_SYNC(regsp, COM_REG_TXDATA, sc->sc_tba, n);
+		CSR_WRITE_MULTI(regsp, COM_REG_TXDATA, sc->sc_tba, n);
 		sc->sc_tbc -= n;
 		sc->sc_tba += n;
 	}
@@ -2381,7 +2359,7 @@ again:	do {
 	CLR(sc->sc_ier, IER_ERXRDY);
 	break;
 }
-CSR_WRITE_1_SYNC(regsp, COM_REG_IER, sc->sc_ier);
+CSR_WRITE_1(regsp, COM_REG_IER, sc->sc_ier);
 			}
 		} else {
 			if ((iir & (IIR_RXRDY|IIR_TXRDY)) == IIR_RXRDY) {
@@ -2465,14 +2443,14 @@ do_tx:
 			n = sc->sc_tbc;
 			if (n > sc->sc_fifolen)
 n = sc->sc_fifolen;
-			CSR_WRITE_MULTI_SYNC(regsp, COM_REG_TXDATA, sc->sc_tba, n);
+			CSR_WRITE_MULTI(regsp, COM_REG_TXDATA, sc->sc_tba, n);
 			sc->sc_tbc -= n;
 			sc->sc_tba += n;
 		} else {
 			/* Disable transmit completion interrupts if necessary. */
 			if (ISSET(sc->sc_ier, IER_ETXRDY)) {
 CLR(sc->sc_ier, IER_ETXRDY);
-CSR_WRITE_1_SYNC(regsp, COM_REG_IER, sc->sc_ier);
+CSR_WRITE_1(regsp, COM_REG_IER, sc->sc_ier);
 			}
 			if (sc->sc_tx_busy) {
 sc->sc_tx_busy = 0;



CVS commit: src/sys/dev/ic

2022-12-08 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Dec  9 00:35:58 UTC 2022

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

Log Message:
Revert com.c:r1.381 because i386/qemu cannot boot.  Pointed out by gson@n.o and 
martin@n.o.


To generate a diff of this commit:
cvs rdiff -u -r1.381 -r1.382 src/sys/dev/ic/com.c

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



CVS commit: src/sys/dev/ic

2022-12-08 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Dec  8 09:08:49 UTC 2022

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

Log Message:
Fix hang up writing /dev/console rarely in specific environments.

Some BMC seems to require these syncronous operations.  If not,
it does not send transmit completion interrupts for some reason.


To generate a diff of this commit:
cvs rdiff -u -r1.380 -r1.381 src/sys/dev/ic/com.c

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/com.c
diff -u src/sys/dev/ic/com.c:1.380 src/sys/dev/ic/com.c:1.381
--- src/sys/dev/ic/com.c:1.380	Sat Dec  3 11:28:38 2022
+++ src/sys/dev/ic/com.c	Thu Dec  8 09:08:49 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: com.c,v 1.380 2022/12/03 11:28:38 skrll Exp $ */
+/* $NetBSD: com.c,v 1.381 2022/12/08 09:08:49 knakahara Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2004, 2008 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: com.c,v 1.380 2022/12/03 11:28:38 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: com.c,v 1.381 2022/12/08 09:08:49 knakahara Exp $");
 
 #include "opt_com.h"
 #include "opt_ddb.h"
@@ -206,6 +206,28 @@ static struct consdev comcons = {
 	.cn_pri = CN_NORMAL
 };
 
+#define	CSR_WRITE_1_SYNC(r, o, v)	do {			\
+		CSR_WRITE_1(r, o, v);\
+		switch(o) {	\
+		case COM_REG_IER:\
+			(void)CSR_READ_1(r, COM_REG_IIR);	\
+			break;	\
+		case COM_REG_TXDATA:\
+			(void)CSR_READ_1(r, COM_REG_TLR);	\
+			break;	\
+		}		\
+	} while(0)
+#define	CSR_WRITE_MULTI_SYNC(r, o, p, n)	do {		\
+		CSR_WRITE_MULTI(r, o, p, n);			\
+		switch(o) {	\
+		case COM_REG_IER:\
+			(void)CSR_READ_1(r, COM_REG_IIR);	\
+			break;	\
+		case COM_REG_TXDATA:\
+			(void)CSR_READ_1(r, COM_REG_TLR);	\
+			break;	\
+		}		\
+	} while(0)
 
 const struct cdevsw com_cdevsw = {
 	.d_open = comopen,
@@ -1961,7 +1983,7 @@ comstart(struct tty *tp)
 	/* Enable transmit completion interrupts if necessary. */
 	if (!ISSET(sc->sc_ier, IER_ETXRDY)) {
 		SET(sc->sc_ier, IER_ETXRDY);
-		CSR_WRITE_1(regsp, COM_REG_IER, sc->sc_ier);
+		CSR_WRITE_1_SYNC(regsp, COM_REG_IER, sc->sc_ier);
 	}
 
 	/* Output the first chunk of the contiguous buffer. */
@@ -1971,7 +1993,7 @@ comstart(struct tty *tp)
 		n = sc->sc_tbc;
 		if (n > sc->sc_fifolen)
 			n = sc->sc_fifolen;
-		CSR_WRITE_MULTI(regsp, COM_REG_TXDATA, sc->sc_tba, n);
+		CSR_WRITE_MULTI_SYNC(regsp, COM_REG_TXDATA, sc->sc_tba, n);
 		sc->sc_tbc -= n;
 		sc->sc_tba += n;
 	}
@@ -2359,7 +2381,7 @@ again:	do {
 	CLR(sc->sc_ier, IER_ERXRDY);
 	break;
 }
-CSR_WRITE_1(regsp, COM_REG_IER, sc->sc_ier);
+CSR_WRITE_1_SYNC(regsp, COM_REG_IER, sc->sc_ier);
 			}
 		} else {
 			if ((iir & (IIR_RXRDY|IIR_TXRDY)) == IIR_RXRDY) {
@@ -2443,14 +2465,14 @@ do_tx:
 			n = sc->sc_tbc;
 			if (n > sc->sc_fifolen)
 n = sc->sc_fifolen;
-			CSR_WRITE_MULTI(regsp, COM_REG_TXDATA, sc->sc_tba, n);
+			CSR_WRITE_MULTI_SYNC(regsp, COM_REG_TXDATA, sc->sc_tba, n);
 			sc->sc_tbc -= n;
 			sc->sc_tba += n;
 		} else {
 			/* Disable transmit completion interrupts if necessary. */
 			if (ISSET(sc->sc_ier, IER_ETXRDY)) {
 CLR(sc->sc_ier, IER_ETXRDY);
-CSR_WRITE_1(regsp, COM_REG_IER, sc->sc_ier);
+CSR_WRITE_1_SYNC(regsp, COM_REG_IER, sc->sc_ier);
 			}
 			if (sc->sc_tx_busy) {
 sc->sc_tx_busy = 0;



CVS commit: src/sys/dev/ic

2022-12-08 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Dec  8 09:08:49 UTC 2022

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

Log Message:
Fix hang up writing /dev/console rarely in specific environments.

Some BMC seems to require these syncronous operations.  If not,
it does not send transmit completion interrupts for some reason.


To generate a diff of this commit:
cvs rdiff -u -r1.380 -r1.381 src/sys/dev/ic/com.c

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



CVS commit: src/sys/dev/pci

2022-12-08 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Dec  8 08:14:28 UTC 2022

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

Log Message:
Workaround for some hypervisor environments.

The environments cannot stop e1000 interrupt immediately.


To generate a diff of this commit:
cvs rdiff -u -r1.766 -r1.767 src/sys/dev/pci/if_wm.c

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

Modified files:

Index: src/sys/dev/pci/if_wm.c
diff -u src/sys/dev/pci/if_wm.c:1.766 src/sys/dev/pci/if_wm.c:1.767
--- src/sys/dev/pci/if_wm.c:1.766	Wed Oct 26 06:36:39 2022
+++ src/sys/dev/pci/if_wm.c	Thu Dec  8 08:14:28 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_wm.c,v 1.766 2022/10/26 06:36:39 msaitoh Exp $	*/
+/*	$NetBSD: if_wm.c,v 1.767 2022/12/08 08:14:28 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2001, 2002, 2003, 2004 Wasabi Systems, Inc.
@@ -82,7 +82,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.766 2022/10/26 06:36:39 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.767 2022/12/08 08:14:28 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_if_wm.h"
@@ -478,6 +478,7 @@ struct wm_queue {
 	char sysctlname[32];		/* Name for sysctl */
 
 	bool wmq_txrx_use_workqueue;
+	bool wmq_wq_enqueued;
 	struct work wmq_cookie;
 	void *wmq_si;
 };
@@ -10308,9 +10309,13 @@ static inline void
 wm_sched_handle_queue(struct wm_softc *sc, struct wm_queue *wmq)
 {
 
-	if (wmq->wmq_txrx_use_workqueue)
-		workqueue_enqueue(sc->sc_queue_wq, >wmq_cookie, curcpu());
-	else
+	if (wmq->wmq_txrx_use_workqueue) {
+		if (!wmq->wmq_wq_enqueued) {
+			wmq->wmq_wq_enqueued = true;
+			workqueue_enqueue(sc->sc_queue_wq, >wmq_cookie,
+			curcpu());
+		}
+	} else
 		softint_schedule(wmq->wmq_si);
 }
 
@@ -10593,8 +10598,10 @@ wm_handle_queue_work(struct work *wk, vo
 	struct wm_queue *wmq = container_of(wk, struct wm_queue, wmq_cookie);
 
 	/*
-	 * "enqueued flag" is not required here.
+	 * Some qemu environment workaround.  They don't stop interrupt
+	 * immediately.
 	 */
+	wmq->wmq_wq_enqueued = false;
 	wm_handle_queue(wmq);
 }
 



CVS commit: src/sys/dev/pci

2022-12-08 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Dec  8 08:14:28 UTC 2022

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

Log Message:
Workaround for some hypervisor environments.

The environments cannot stop e1000 interrupt immediately.


To generate a diff of this commit:
cvs rdiff -u -r1.766 -r1.767 src/sys/dev/pci/if_wm.c

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



CVS commit: src/sys/netipsec

2022-12-08 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Dec  8 08:07:07 UTC 2022

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

Log Message:
Fix: sp->lastused should be updated by time_uptime, and refactor a little.


To generate a diff of this commit:
cvs rdiff -u -r1.176 -r1.177 src/sys/netipsec/ipsec.c
cvs rdiff -u -r1.279 -r1.280 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/ipsec.c
diff -u src/sys/netipsec/ipsec.c:1.176 src/sys/netipsec/ipsec.c:1.177
--- src/sys/netipsec/ipsec.c:1.176	Wed Nov  9 08:18:52 2022
+++ src/sys/netipsec/ipsec.c	Thu Dec  8 08:07:07 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: ipsec.c,v 1.176 2022/11/09 08:18:52 knakahara Exp $ */
+/* $NetBSD: ipsec.c,v 1.177 2022/12/08 08:07:07 knakahara 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.176 2022/11/09 08:18:52 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ipsec.c,v 1.177 2022/12/08 08:07:07 knakahara Exp $");
 
 /*
  * IPsec controller part.
@@ -248,7 +248,7 @@ ipsec_checkpcbcache(struct mbuf *m, stru
 		 */
 	}
 
-	sp->lastused = time_second;
+	key_sp_touch(sp);
 	KEY_SP_REF(sp);
 	KEYDEBUG_PRINTF(KEYDEBUG_IPSEC_STAMP,
 	"DP cause refcnt++:%d SP:%p\n",

Index: src/sys/netipsec/key.c
diff -u src/sys/netipsec/key.c:1.279 src/sys/netipsec/key.c:1.280
--- src/sys/netipsec/key.c:1.279	Thu Dec  8 08:05:03 2022
+++ src/sys/netipsec/key.c	Thu Dec  8 08:07:07 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: key.c,v 1.279 2022/12/08 08:05:03 knakahara Exp $	*/
+/*	$NetBSD: key.c,v 1.280 2022/12/08 08:07:07 knakahara 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.279 2022/12/08 08:05:03 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: key.c,v 1.280 2022/12/08 08:07:07 knakahara Exp $");
 
 /*
  * This code is referred to RFC 2367
@@ -972,7 +972,7 @@ found:
 		KEY_CHKSPDIR(sp->spidx.dir, dir);
 
 		/* found a SPD entry */
-		sp->lastused = time_uptime;
+		key_sp_touch(sp);
 		key_sp_ref(sp, where, tag);
 	}
 	pserialize_read_exit(s);
@@ -1049,7 +1049,7 @@ key_gettunnel(const struct sockaddr *osr
 	sp = NULL;
 found:
 	if (sp) {
-		sp->lastused = time_uptime;
+		key_sp_touch(sp);
 		key_sp_ref(sp, where, tag);
 	}
 	pserialize_read_exit(s);



CVS commit: src/sys/netipsec

2022-12-08 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Dec  8 08:07:07 UTC 2022

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

Log Message:
Fix: sp->lastused should be updated by time_uptime, and refactor a little.


To generate a diff of this commit:
cvs rdiff -u -r1.176 -r1.177 src/sys/netipsec/ipsec.c
cvs rdiff -u -r1.279 -r1.280 src/sys/netipsec/key.c

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



CVS commit: src/sys/netipsec

2022-12-08 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Dec  8 08:05:03 UTC 2022

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

Log Message:
Fix: update lastused of ipsecif(4) IPv6 out SP.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/netipsec/ipsecif.c
cvs rdiff -u -r1.278 -r1.279 src/sys/netipsec/key.c
cvs rdiff -u -r1.37 -r1.38 src/sys/netipsec/key.h

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

Modified files:

Index: src/sys/netipsec/ipsecif.c
diff -u src/sys/netipsec/ipsecif.c:1.20 src/sys/netipsec/ipsecif.c:1.21
--- src/sys/netipsec/ipsecif.c:1.20	Wed Dec  7 08:30:15 2022
+++ src/sys/netipsec/ipsecif.c	Thu Dec  8 08:05:03 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: ipsecif.c,v 1.20 2022/12/07 08:30:15 knakahara Exp $  */
+/*	$NetBSD: ipsecif.c,v 1.21 2022/12/08 08:05:03 knakahara Exp $  */
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ipsecif.c,v 1.20 2022/12/07 08:30:15 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ipsecif.c,v 1.21 2022/12/08 08:05:03 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -395,7 +395,10 @@ ipsecif4_output(struct ipsec_variant *va
 	/*
 	 * The SPs in ipsec_variant are prevented from freed by
 	 * ipsec_variant->iv_psref. So, KEY_SP_REF() is unnecessary here.
+	 *
+	 * However, lastused should be updated.
 	 */
+	key_sp_touch(sp);
 
 	KASSERT(sp->policy != IPSEC_POLICY_NONE);
 	KASSERT(sp->policy != IPSEC_POLICY_ENTRUST);

Index: src/sys/netipsec/key.c
diff -u src/sys/netipsec/key.c:1.278 src/sys/netipsec/key.c:1.279
--- src/sys/netipsec/key.c:1.278	Wed Oct 19 21:28:02 2022
+++ src/sys/netipsec/key.c	Thu Dec  8 08:05:03 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: key.c,v 1.278 2022/10/19 21:28:02 christos Exp $	*/
+/*	$NetBSD: key.c,v 1.279 2022/12/08 08:05:03 knakahara 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.278 2022/10/19 21:28:02 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: key.c,v 1.279 2022/12/08 08:05:03 knakahara Exp $");
 
 /*
  * This code is referred to RFC 2367
@@ -871,6 +871,13 @@ key_sp_refcnt(const struct secpolicy *sp
 	return 0;
 }
 
+void
+key_sp_touch(struct secpolicy *sp)
+{
+
+	sp->lastused = time_uptime;
+}
+
 static void
 key_spd_pserialize_perform(void)
 {

Index: src/sys/netipsec/key.h
diff -u src/sys/netipsec/key.h:1.37 src/sys/netipsec/key.h:1.38
--- src/sys/netipsec/key.h:1.37	Mon Aug  9 20:49:10 2021
+++ src/sys/netipsec/key.h	Thu Dec  8 08:05:03 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: key.h,v 1.37 2021/08/09 20:49:10 andvar Exp $	*/
+/*	$NetBSD: key.h,v 1.38 2022/12/08 08:05:03 knakahara Exp $	*/
 /*	$FreeBSD: key.h,v 1.1.4.1 2003/01/24 05:11:36 sam Exp $	*/
 /*	$KAME: key.h,v 1.21 2001/07/27 03:51:30 itojun Exp $	*/
 
@@ -67,6 +67,7 @@ void key_free_sp(struct secpolicy *);
 u_int key_sp_refcnt(const struct secpolicy *);
 void key_sp_ref(struct secpolicy *, const char *, int);
 void key_sp_unref(struct secpolicy *, const char *, int);
+void key_sp_touch(struct secpolicy *);
 void key_sa_ref(struct secasvar *, const char *, int);
 void key_sa_unref(struct secasvar *, const char *, int);
 u_int key_sa_refcnt(const struct secasvar *);



CVS commit: src/sys/netipsec

2022-12-08 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Dec  8 08:05:03 UTC 2022

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

Log Message:
Fix: update lastused of ipsecif(4) IPv6 out SP.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/netipsec/ipsecif.c
cvs rdiff -u -r1.278 -r1.279 src/sys/netipsec/key.c
cvs rdiff -u -r1.37 -r1.38 src/sys/netipsec/key.h

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



CVS commit: src/doc

2022-12-07 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Dec  8 06:19:26 UTC 2022

Modified Files:
src/doc: CHANGES

Log Message:
Fix typo.


To generate a diff of this commit:
cvs rdiff -u -r1.2933 -r1.2934 src/doc/CHANGES

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



CVS commit: src/doc

2022-12-07 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Dec  8 06:19:26 UTC 2022

Modified Files:
src/doc: CHANGES

Log Message:
Fix typo.


To generate a diff of this commit:
cvs rdiff -u -r1.2933 -r1.2934 src/doc/CHANGES

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

Modified files:

Index: src/doc/CHANGES
diff -u src/doc/CHANGES:1.2933 src/doc/CHANGES:1.2934
--- src/doc/CHANGES:1.2933	Mon Nov 28 10:23:56 2022
+++ src/doc/CHANGES	Thu Dec  8 06:19:26 2022
@@ -1,4 +1,4 @@
-# LIST OF CHANGES FROM LAST RELEASE:			<$Revision: 1.2933 $>
+# LIST OF CHANGES FROM LAST RELEASE:			<$Revision: 1.2934 $>
 #
 #
 # [Note: This file does not mention every change made to the NetBSD source tree.
@@ -748,4 +748,4 @@ Changes from NetBSD 9.0 to NetBSD 10.0:
 		machine-independent code, allowing dmidecode -d /dev/smbios
 		to be used on x86. [mrg 20221125]
 	ifconfig(8): Allow configuration of interfaces as
-		explicitly unnumbred. [knakahara 20221125]
+		explicitly unnumbered. [knakahara 20221125]



CVS commit: src/sys/netinet

2022-12-07 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Dec  7 08:33:02 UTC 2022

Modified Files:
src/sys/netinet: ip_encap.c ip_encap.h

Log Message:
Refactor ip_encap.[ch]

- remove encap_attach() which is no longer used
- remove USE_RADIX code in ip_encap.c, which is used for
  encap_attach() only
- remove mask members in encaptab


To generate a diff of this commit:
cvs rdiff -u -r1.76 -r1.77 src/sys/netinet/ip_encap.c
cvs rdiff -u -r1.27 -r1.28 src/sys/netinet/ip_encap.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_encap.c
diff -u src/sys/netinet/ip_encap.c:1.76 src/sys/netinet/ip_encap.c:1.77
--- src/sys/netinet/ip_encap.c:1.76	Wed Dec  7 08:28:46 2022
+++ src/sys/netinet/ip_encap.c	Wed Dec  7 08:33:02 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_encap.c,v 1.76 2022/12/07 08:28:46 knakahara Exp $	*/
+/*	$NetBSD: ip_encap.c,v 1.77 2022/12/07 08:33:02 knakahara Exp $	*/
 /*	$KAME: ip_encap.c,v 1.73 2001/10/02 08:30:58 itojun Exp $	*/
 
 /*
@@ -57,18 +57,8 @@
  */
 /* XXX is M_NETADDR correct? */
 
-/*
- * With USE_RADIX the code will use radix table for tunnel lookup, for
- * tunnels registered with encap_attach() with a addr/mask pair.
- * Faster on machines with thousands of tunnel registerations (= interfaces).
- *
- * The code assumes that radix table code can handle non-continuous netmask,
- * as it will pass radix table memory region with (src + dst) sockaddr pair.
- */
-#define USE_RADIX
-
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip_encap.c,v 1.76 2022/12/07 08:28:46 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_encap.c,v 1.77 2022/12/07 08:33:02 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_mrouting.h"
@@ -128,13 +118,6 @@ static struct encaptab *encap6_lookup(st
 static int encap_add(struct encaptab *);
 static int encap_remove(struct encaptab *);
 static void encap_afcheck(int, const struct sockaddr *, const struct sockaddr *);
-#ifdef USE_RADIX
-static struct radix_node_head *encap_rnh(int);
-static int mask_matchlen(const struct sockaddr *);
-#else
-static int mask_match(const struct encaptab *, const struct sockaddr *,
-		const struct sockaddr *);
-#endif
 static void encap_key_init(struct encap_key *, const struct sockaddr *,
 const struct sockaddr *);
 static void encap_key_inc(struct encap_key *);
@@ -158,11 +141,6 @@ static struct {
 	struct lwp	*busy;
 } encap_whole __cacheline_aligned;
 
-#ifdef USE_RADIX
-struct radix_node_head *encap_head[2];	/* 0 for AF_INET, 1 for AF_INET6 */
-static bool encap_head_updating = false;
-#endif
-
 static thmap_t *encap_map[2];	/* 0 for AF_INET, 1 for AF_INET6 */
 
 static bool encap_initialized = false;
@@ -205,18 +183,6 @@ encap_init(void)
 	PSLIST_INIT(_table);
 #endif
 
-#ifdef USE_RADIX
-	/*
-	 * initialize radix lookup table when the radix subsystem is inited.
-	 */
-	rn_delayedinit((void *)_head[0],
-	sizeof(struct sockaddr_pack) << 3);
-#ifdef INET6
-	rn_delayedinit((void *)_head[1],
-	sizeof(struct sockaddr_pack) << 3);
-#endif
-#endif
-
 	encap_map[0] = thmap_create(0, NULL, THMAP_NOCOPY);
 #ifdef INET6
 	encap_map[1] = thmap_create(0, NULL, THMAP_NOCOPY);
@@ -233,10 +199,6 @@ encap4_lookup(struct mbuf *m, int off, i
 	struct encaptab *ep, *match;
 	int prio, matchprio;
 	int s;
-#ifdef USE_RADIX
-	struct radix_node_head *rnh = encap_rnh(AF_INET);
-	struct radix_node *rn;
-#endif
 	thmap_t *emap = encap_map[0];
 	struct encap_key key;
 
@@ -260,26 +222,6 @@ encap4_lookup(struct mbuf *m, int off, i
 	matchprio = 0;
 
 	s = pserialize_read_enter();
-#ifdef USE_RADIX
-	if (encap_head_updating) {
-		/*
-		 * Update in progress. Do nothing.
-		 */
-		pserialize_read_exit(s);
-		return NULL;
-	}
-
-	rn = rnh->rnh_matchaddr((void *), rnh);
-	if (rn && (rn->rn_flags & RNF_ROOT) == 0) {
-		struct encaptab *encapp = (struct encaptab *)rn;
-
-		psref_acquire(match_psref, >psref,
-		encaptab.elem_class);
-		match = encapp;
-		matchprio = mask_matchlen(match->srcmask) +
-		mask_matchlen(match->dstmask);
-	}
-#endif
 
 	encap_key_init(, sintosa(), sintosa());
 	while ((ep = thmap_get(emap, , sizeof(key))) != NULL) {
@@ -335,42 +277,21 @@ encap4_lookup(struct mbuf *m, int off, i
 
 		psref_acquire(_psref, >psref,
 		encaptab.elem_class);
-		if (ep->func) {
-			pserialize_read_exit(s);
-			/* ep->func is sleepable. e.g. rtalloc1 */
-			prio = (*ep->func)(m, off, proto, ep->arg);
-			s = pserialize_read_enter();
-		} else {
-#ifdef USE_RADIX
-			psref_release(_psref, >psref,
-			encaptab.elem_class);
-			continue;
-#else
-			prio = mask_match(ep, (struct sockaddr *),
-			(struct sockaddr *));
-#endif
-		}
+		pserialize_read_exit(s);
+		/* ep->func is sleepable. e.g. rtalloc1 */
+		prio = (*ep->func)(m, off, proto, ep->arg);
+		s = pserialize_read_enter();
 
 		/*
 		 * We prioritize the matches by using bit length of the
-		 * matches.  mask_match() and user-supplied matching 

CVS commit: src/sys/netinet

2022-12-07 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Dec  7 08:33:02 UTC 2022

Modified Files:
src/sys/netinet: ip_encap.c ip_encap.h

Log Message:
Refactor ip_encap.[ch]

- remove encap_attach() which is no longer used
- remove USE_RADIX code in ip_encap.c, which is used for
  encap_attach() only
- remove mask members in encaptab


To generate a diff of this commit:
cvs rdiff -u -r1.76 -r1.77 src/sys/netinet/ip_encap.c
cvs rdiff -u -r1.27 -r1.28 src/sys/netinet/ip_encap.h

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



CVS commit: src/sys

2022-12-07 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Dec  7 08:30:15 UTC 2022

Modified Files:
src/sys/netinet: in_gif.c in_l2tp.c
src/sys/netinet6: in6_gif.c in6_l2tp.c
src/sys/netipsec: ipsecif.c

Log Message:
gif(4), ipsec(4) and l2tp(4) use encap_attach_addr().


To generate a diff of this commit:
cvs rdiff -u -r1.95 -r1.96 src/sys/netinet/in_gif.c
cvs rdiff -u -r1.20 -r1.21 src/sys/netinet/in_l2tp.c
cvs rdiff -u -r1.95 -r1.96 src/sys/netinet6/in6_gif.c
cvs rdiff -u -r1.21 -r1.22 src/sys/netinet6/in6_l2tp.c
cvs rdiff -u -r1.19 -r1.20 src/sys/netipsec/ipsecif.c

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

Modified files:

Index: src/sys/netinet/in_gif.c
diff -u src/sys/netinet/in_gif.c:1.95 src/sys/netinet/in_gif.c:1.96
--- src/sys/netinet/in_gif.c:1.95	Thu Sep 19 06:07:25 2019
+++ src/sys/netinet/in_gif.c	Wed Dec  7 08:30:15 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: in_gif.c,v 1.95 2019/09/19 06:07:25 knakahara Exp $	*/
+/*	$NetBSD: in_gif.c,v 1.96 2022/12/07 08:30:15 knakahara Exp $	*/
 /*	$KAME: in_gif.c,v 1.66 2001/07/29 04:46:09 itojun Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in_gif.c,v 1.95 2019/09/19 06:07:25 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in_gif.c,v 1.96 2022/12/07 08:30:15 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -369,12 +369,12 @@ in_gif_attach(struct gif_variant *var)
 
 	if (!var->gv_psrc || !var->gv_pdst)
 		return EINVAL;
-	var->gv_encap_cookie4 = encap_attach(AF_INET, -1, var->gv_psrc,
-	(struct sockaddr *), var->gv_pdst, (struct sockaddr *),
-	_gif_encapsw, var->gv_softc);
+
+	var->gv_encap_cookie4 = encap_attach_addr(AF_INET, -1, var->gv_psrc,
+	var->gv_pdst, NULL, _gif_encapsw, var->gv_softc);
 #else
-	var->gv_encap_cookie4 = encap_attach_func(AF_INET, -1, gif_encapcheck,
-	_gif_encapsw, var->gv_softc);
+	var->gv_encap_cookie4 = encap_attach_addr(AF_INET, -1, var->gv_psrc,
+	var->gv_pdst, gif_encapcheck, _gif_encapsw, var->gv_softc);
 #endif
 	if (var->gv_encap_cookie4 == NULL)
 		return EEXIST;

Index: src/sys/netinet/in_l2tp.c
diff -u src/sys/netinet/in_l2tp.c:1.20 src/sys/netinet/in_l2tp.c:1.21
--- src/sys/netinet/in_l2tp.c:1.20	Fri Feb 19 14:51:59 2021
+++ src/sys/netinet/in_l2tp.c	Wed Dec  7 08:30:15 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: in_l2tp.c,v 1.20 2021/02/19 14:51:59 christos Exp $	*/
+/*	$NetBSD: in_l2tp.c,v 1.21 2022/12/07 08:30:15 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in_l2tp.c,v 1.20 2021/02/19 14:51:59 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in_l2tp.c,v 1.21 2022/12/07 08:30:15 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_l2tp.h"
@@ -404,8 +404,9 @@ in_l2tp_attach(struct l2tp_variant *var)
 
 	if (sc == NULL)
 		return EINVAL;
-	var->lv_encap_cookie = encap_attach_func(AF_INET, IPPROTO_L2TP,
-	in_l2tp_match, _l2tp_encapsw, sc);
+
+	var->lv_encap_cookie = encap_attach_addr(AF_INET, IPPROTO_L2TP,
+	var->lv_psrc, var->lv_pdst, in_l2tp_match, _l2tp_encapsw, sc);
 	if (var->lv_encap_cookie == NULL)
 		return EEXIST;
 

Index: src/sys/netinet6/in6_gif.c
diff -u src/sys/netinet6/in6_gif.c:1.95 src/sys/netinet6/in6_gif.c:1.96
--- src/sys/netinet6/in6_gif.c:1.95	Wed Oct 30 03:45:59 2019
+++ src/sys/netinet6/in6_gif.c	Wed Dec  7 08:30:15 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: in6_gif.c,v 1.95 2019/10/30 03:45:59 knakahara Exp $	*/
+/*	$NetBSD: in6_gif.c,v 1.96 2022/12/07 08:30:15 knakahara Exp $	*/
 /*	$KAME: in6_gif.c,v 1.62 2001/07/29 04:27:25 itojun Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in6_gif.c,v 1.95 2019/10/30 03:45:59 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6_gif.c,v 1.96 2022/12/07 08:30:15 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -433,12 +433,12 @@ in6_gif_attach(struct gif_variant *var)
 
 	if (!var->gv_psrc || !var->gv_pdst)
 		return EINVAL;
-	var->gv_encap_cookie6 = encap_attach(AF_INET6, -1, var->gv_psrc,
-	sin6tosa(), var->gv_pdst, sin6tosa(),
-	(const void *)_gif_encapsw, var->gv_softc);
+
+	var->gv_encap_cookie6 = encap_attach_addr(AF_INET6, -1, var->gv_psrc,
+	var->gv_pdst, NULL, _gif_encapsw, var->gv_softc);
 #else
-	var->gv_encap_cookie6 = encap_attach_func(AF_INET6, -1, gif_encapcheck,
-	_gif_encapsw, var->gv_softc);
+	var->gv_encap_cookie6 = encap_attach_addr(AF_INET6, -1, var->gv_psrc,
+	var->gv_pdst, gif_encapcheck, _gif_encapsw, var->gv_softc);
 #endif
 	if (var->gv_encap_cookie6 == NULL)
 		return EEXIST;

Index: src/sys/netinet6/in6_l2tp.c
diff -u src/sys/netinet6/in6_l2tp.c:1.21 src/sys/netinet6/in6_l2tp.c:1.22
--- src/sys/netinet6/in6_l2tp.c:1.21	Fri Feb 19 14:52:00 2021
+++ src/sys/netinet6/in6_l2tp.c	Wed Dec  7 08:30:15 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: in6_l2tp.c,v 1.21 2021/02/19 14:52:00 christos Exp $	*/
+/*	$NetBSD: in6_l2tp.c,v 

CVS commit: src/sys

2022-12-07 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Dec  7 08:30:15 UTC 2022

Modified Files:
src/sys/netinet: in_gif.c in_l2tp.c
src/sys/netinet6: in6_gif.c in6_l2tp.c
src/sys/netipsec: ipsecif.c

Log Message:
gif(4), ipsec(4) and l2tp(4) use encap_attach_addr().


To generate a diff of this commit:
cvs rdiff -u -r1.95 -r1.96 src/sys/netinet/in_gif.c
cvs rdiff -u -r1.20 -r1.21 src/sys/netinet/in_l2tp.c
cvs rdiff -u -r1.95 -r1.96 src/sys/netinet6/in6_gif.c
cvs rdiff -u -r1.21 -r1.22 src/sys/netinet6/in6_l2tp.c
cvs rdiff -u -r1.19 -r1.20 src/sys/netipsec/ipsecif.c

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



CVS commit: src/sys/netinet

2022-12-07 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Dec  7 08:28:46 UTC 2022

Modified Files:
src/sys/netinet: ip_encap.c ip_encap.h

Log Message:
Implement encap_attach_addr() which is used by IP-encaped tunnels.

The tunnels attached by encap_attach() can process receiving packets
fastly as the softc is searched by radix-tree.  However, the tunnels
cannot use priority function which decides tunnel's softc by not only
source and destination but also other informations.
On the other hand, the tunnels attached by encap_attach_func() can
use priority function. However, the tunnels can be slow receiving
processing as the softc is searched by linear search (and uses each
priority function).

encap_attach_addr() can be used for tunnels which is fixed tunnel
source address and tunnel destination address.  The tunnels attached
by encap_attach_addr() is searched by thmap(9), so the receiving processing
can be fast.  Moreover, the tunnels can use priority function.


To generate a diff of this commit:
cvs rdiff -u -r1.75 -r1.76 src/sys/netinet/ip_encap.c
cvs rdiff -u -r1.26 -r1.27 src/sys/netinet/ip_encap.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_encap.c
diff -u src/sys/netinet/ip_encap.c:1.75 src/sys/netinet/ip_encap.c:1.76
--- src/sys/netinet/ip_encap.c:1.75	Wed Dec  7 08:27:03 2022
+++ src/sys/netinet/ip_encap.c	Wed Dec  7 08:28:46 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_encap.c,v 1.75 2022/12/07 08:27:03 knakahara Exp $	*/
+/*	$NetBSD: ip_encap.c,v 1.76 2022/12/07 08:28:46 knakahara Exp $	*/
 /*	$KAME: ip_encap.c,v 1.73 2001/10/02 08:30:58 itojun Exp $	*/
 
 /*
@@ -68,7 +68,7 @@
 #define USE_RADIX
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip_encap.c,v 1.75 2022/12/07 08:27:03 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_encap.c,v 1.76 2022/12/07 08:28:46 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_mrouting.h"
@@ -89,6 +89,7 @@ __KERNEL_RCSID(0, "$NetBSD: ip_encap.c,v
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -134,6 +135,9 @@ static int mask_matchlen(const struct so
 static int mask_match(const struct encaptab *, const struct sockaddr *,
 		const struct sockaddr *);
 #endif
+static void encap_key_init(struct encap_key *, const struct sockaddr *,
+const struct sockaddr *);
+static void encap_key_inc(struct encap_key *);
 
 /*
  * In encap[46]_lookup(), ep->func can sleep(e.g. rtalloc1) while walking
@@ -159,6 +163,8 @@ struct radix_node_head *encap_head[2];	/
 static bool encap_head_updating = false;
 #endif
 
+static thmap_t *encap_map[2];	/* 0 for AF_INET, 1 for AF_INET6 */
+
 static bool encap_initialized = false;
 /*
  * must be done before other encap interfaces initialization.
@@ -210,6 +216,11 @@ encap_init(void)
 	sizeof(struct sockaddr_pack) << 3);
 #endif
 #endif
+
+	encap_map[0] = thmap_create(0, NULL, THMAP_NOCOPY);
+#ifdef INET6
+	encap_map[1] = thmap_create(0, NULL, THMAP_NOCOPY);
+#endif
 }
 
 #ifdef INET
@@ -226,6 +237,8 @@ encap4_lookup(struct mbuf *m, int off, i
 	struct radix_node_head *rnh = encap_rnh(AF_INET);
 	struct radix_node *rn;
 #endif
+	thmap_t *emap = encap_map[0];
+	struct encap_key key;
 
 	KASSERT(m->m_len >= sizeof(*ip));
 
@@ -267,6 +280,51 @@ encap4_lookup(struct mbuf *m, int off, i
 		mask_matchlen(match->dstmask);
 	}
 #endif
+
+	encap_key_init(, sintosa(), sintosa());
+	while ((ep = thmap_get(emap, , sizeof(key))) != NULL) {
+		struct psref elem_psref;
+
+		KASSERT(ep->af == AF_INET);
+
+		if (ep->proto >= 0 && ep->proto != proto) {
+			encap_key_inc();
+			continue;
+		}
+
+		psref_acquire(_psref, >psref,
+		encaptab.elem_class);
+		if (ep->func) {
+			pserialize_read_exit(s);
+			prio = (*ep->func)(m, off, proto, ep->arg);
+			s = pserialize_read_enter();
+		} else {
+			prio = pack.mine.sin_len + pack.yours.sin_len;
+		}
+
+		if (prio <= 0) {
+			psref_release(_psref, >psref,
+			encaptab.elem_class);
+			encap_key_inc();
+			continue;
+		}
+		if (prio > matchprio) {
+			/* release last matched ep */
+			if (match != NULL)
+psref_release(match_psref, >psref,
+encaptab.elem_class);
+
+			psref_copy(match_psref, _psref,
+			encaptab.elem_class);
+			matchprio = prio;
+			match = ep;
+		}
+
+		psref_release(_psref, >psref,
+		encaptab.elem_class);
+		encap_key_inc();
+	}
+
 	PSLIST_READER_FOREACH(ep, _table, struct encaptab, chain) {
 		struct psref elem_psref;
 
@@ -386,6 +444,8 @@ encap6_lookup(struct mbuf *m, int off, i
 	struct radix_node_head *rnh = encap_rnh(AF_INET6);
 	struct radix_node *rn;
 #endif
+	thmap_t *emap = encap_map[1];
+	struct encap_key key;
 
 	KASSERT(m->m_len >= sizeof(*ip6));
 
@@ -427,6 +487,50 @@ encap6_lookup(struct mbuf *m, int off, i
 		mask_matchlen(match->dstmask);
 	}
 #endif
+
+	encap_key_init(, sin6tosa(), sin6tosa());
+	while ((ep = thmap_get(emap, , sizeof(key))) != NULL) {
+		struct psref elem_psref;
+
+		KASSERT(ep->af == 

CVS commit: src/sys/netinet

2022-12-07 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Dec  7 08:28:46 UTC 2022

Modified Files:
src/sys/netinet: ip_encap.c ip_encap.h

Log Message:
Implement encap_attach_addr() which is used by IP-encaped tunnels.

The tunnels attached by encap_attach() can process receiving packets
fastly as the softc is searched by radix-tree.  However, the tunnels
cannot use priority function which decides tunnel's softc by not only
source and destination but also other informations.
On the other hand, the tunnels attached by encap_attach_func() can
use priority function. However, the tunnels can be slow receiving
processing as the softc is searched by linear search (and uses each
priority function).

encap_attach_addr() can be used for tunnels which is fixed tunnel
source address and tunnel destination address.  The tunnels attached
by encap_attach_addr() is searched by thmap(9), so the receiving processing
can be fast.  Moreover, the tunnels can use priority function.


To generate a diff of this commit:
cvs rdiff -u -r1.75 -r1.76 src/sys/netinet/ip_encap.c
cvs rdiff -u -r1.26 -r1.27 src/sys/netinet/ip_encap.h

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



CVS commit: src/sys/netinet

2022-12-07 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Dec  7 08:27:03 UTC 2022

Modified Files:
src/sys/netinet: ip_encap.c ip_encap.h

Log Message:
refactor: use typedef for ip_encap priority function


To generate a diff of this commit:
cvs rdiff -u -r1.74 -r1.75 src/sys/netinet/ip_encap.c
cvs rdiff -u -r1.25 -r1.26 src/sys/netinet/ip_encap.h

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



CVS commit: src/sys/netinet

2022-12-07 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Dec  7 08:27:03 UTC 2022

Modified Files:
src/sys/netinet: ip_encap.c ip_encap.h

Log Message:
refactor: use typedef for ip_encap priority function


To generate a diff of this commit:
cvs rdiff -u -r1.74 -r1.75 src/sys/netinet/ip_encap.c
cvs rdiff -u -r1.25 -r1.26 src/sys/netinet/ip_encap.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_encap.c
diff -u src/sys/netinet/ip_encap.c:1.74 src/sys/netinet/ip_encap.c:1.75
--- src/sys/netinet/ip_encap.c:1.74	Sat Aug 22 01:43:07 2020
+++ src/sys/netinet/ip_encap.c	Wed Dec  7 08:27:03 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_encap.c,v 1.74 2020/08/22 01:43:07 riastradh Exp $	*/
+/*	$NetBSD: ip_encap.c,v 1.75 2022/12/07 08:27:03 knakahara Exp $	*/
 /*	$KAME: ip_encap.c,v 1.73 2001/10/02 08:30:58 itojun Exp $	*/
 
 /*
@@ -68,7 +68,7 @@
 #define USE_RADIX
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip_encap.c,v 1.74 2020/08/22 01:43:07 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_encap.c,v 1.75 2022/12/07 08:27:03 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_mrouting.h"
@@ -750,7 +750,7 @@ fail:
 
 const struct encaptab *
 encap_attach_func(int af, int proto,
-int (*func)(struct mbuf *, int, int, void *),
+encap_priofunc_t *func,
 const struct encapsw *esw, void *arg)
 {
 	struct encaptab *ep;

Index: src/sys/netinet/ip_encap.h
diff -u src/sys/netinet/ip_encap.h:1.25 src/sys/netinet/ip_encap.h:1.26
--- src/sys/netinet/ip_encap.h:1.25	Fri Sep 14 05:09:51 2018
+++ src/sys/netinet/ip_encap.h	Wed Dec  7 08:27:03 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_encap.h,v 1.25 2018/09/14 05:09:51 maxv Exp $	*/
+/*	$NetBSD: ip_encap.h,v 1.26 2022/12/07 08:27:03 knakahara Exp $	*/
 /*	$KAME: ip_encap.h,v 1.7 2000/03/25 07:23:37 sumikawa Exp $	*/
 
 /*
@@ -62,6 +62,8 @@ struct encapsw {
 #define encapsw4 encapsw46._encapsw4
 #define encapsw6 encapsw46._encapsw6
 
+typedef	int encap_priofunc_t(struct mbuf *, int, int, void *);
+
 struct encaptab {
 	struct radix_node nodes[2];
 	struct pslist_entry chain;
@@ -73,7 +75,7 @@ struct encaptab {
 	struct sockaddr *srcmask;
 	struct sockaddr *dst;		/* remote addr */
 	struct sockaddr *dstmask;
-	int (*func) (struct mbuf *, int, int, void *);
+	encap_priofunc_t *func;
 	const struct encapsw *esw;
 	void *arg;
 	struct psref_target	psref;
@@ -106,7 +108,7 @@ const struct encaptab *encap_attach(int,
 	const struct sockaddr *, const struct sockaddr *,
 	const struct sockaddr *, const struct encapsw *, void *);
 const struct encaptab *encap_attach_func(int, int,
-	int (*)(struct mbuf *, int, int, void *),
+	encap_priofunc_t *,
 	const struct encapsw *, void *);
 void	*encap6_ctlinput(int, const struct sockaddr *, void *);
 int	encap_detach(const struct encaptab *);



CVS commit: src

2022-11-25 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Nov 25 08:43:16 UTC 2022

Modified Files:
src/distrib/sets/lists/tests: mi
src/tests/net/if_gif: Makefile
src/tests/net/if_ipsec: Makefile
src/tests/net/if_pppoe: Makefile
Added Files:
src/tests/net/if_gif: t_gif_unnumbered.sh
src/tests/net/if_ipsec: t_ipsec_unnumbered.sh
src/tests/net/if_pppoe: t_pppoe_unnumbered.sh

Log Message:
Add ATF for unnumbered interfaces.


To generate a diff of this commit:
cvs rdiff -u -r1.1235 -r1.1236 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.2 -r1.3 src/tests/net/if_gif/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/net/if_gif/t_gif_unnumbered.sh
cvs rdiff -u -r1.3 -r1.4 src/tests/net/if_ipsec/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/net/if_ipsec/t_ipsec_unnumbered.sh
cvs rdiff -u -r1.3 -r1.4 src/tests/net/if_pppoe/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/net/if_pppoe/t_pppoe_unnumbered.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.1235 src/distrib/sets/lists/tests/mi:1.1236
--- src/distrib/sets/lists/tests/mi:1.1235	Tue Nov 22 17:35:45 2022
+++ src/distrib/sets/lists/tests/mi	Fri Nov 25 08:43:15 2022
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1235 2022/11/22 17:35:45 jakllsch Exp $
+# $NetBSD: mi,v 1.1236 2022/11/25 08:43:15 knakahara Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -4165,12 +4165,14 @@
 ./usr/tests/net/if_gif/Atffiletests-net-tests		atf,rump
 ./usr/tests/net/if_gif/Kyuafiletests-net-tests		atf,rump,kyua
 ./usr/tests/net/if_gif/t_giftests-net-tests		atf,rump
+./usr/tests/net/if_gif/t_gif_unnumbered			tests-net-tests		atf,rump
 ./usr/tests/net/if_ipsectests-net-tests		compattestfile,atf
 ./usr/tests/net/if_ipsec/Atffile			tests-net-tests		atf,rump
 ./usr/tests/net/if_ipsec/Kyuafile			tests-net-tests		atf,rump,kyua
 ./usr/tests/net/if_ipsec/t_ipsec			tests-net-tests		atf,rump
 ./usr/tests/net/if_ipsec/t_ipsec_natt			tests-net-tests		atf,rump
 ./usr/tests/net/if_ipsec/t_ipsec_pfil			tests-net-tests		atf,rump
+./usr/tests/net/if_ipsec/t_ipsec_unnumbered		tests-net-tests		atf,rump
 ./usr/tests/net/if_l2tp	tests-net-tests		compattestfile,atf
 ./usr/tests/net/if_l2tp/Atffiletests-net-tests		atf,rump
 ./usr/tests/net/if_l2tp/Kyuafile			tests-net-tests		atf,rump,kyua
@@ -4188,6 +4190,7 @@
 ./usr/tests/net/if_pppoe/Atffile			tests-net-tests		atf,rump
 ./usr/tests/net/if_pppoe/Kyuafile			tests-net-tests		atf,rump,kyua
 ./usr/tests/net/if_pppoe/t_pppoe			tests-net-tests		atf,rump
+./usr/tests/net/if_pppoe/t_pppoe_unnumbered		tests-net-tests		atf,rump
 ./usr/tests/net/if_tap	tests-net-tests		compattestfile,atf
 ./usr/tests/net/if_tap/Atffiletests-net-tests		atf,rump
 ./usr/tests/net/if_tap/Kyuafiletests-net-tests		atf,rump,kyua

Index: src/tests/net/if_gif/Makefile
diff -u src/tests/net/if_gif/Makefile:1.2 src/tests/net/if_gif/Makefile:1.3
--- src/tests/net/if_gif/Makefile:1.2	Thu Nov 24 09:03:53 2016
+++ src/tests/net/if_gif/Makefile	Fri Nov 25 08:43:16 2022
@@ -1,11 +1,11 @@
-# $NetBSD: Makefile,v 1.2 2016/11/24 09:03:53 ozaki-r Exp $
+# $NetBSD: Makefile,v 1.3 2022/11/25 08:43:16 knakahara Exp $
 #
 
 .include 
 
 TESTSDIR=	${TESTSBASE}/net/if_gif
 
-.for name in gif
+.for name in gif gif_unnumbered
 TESTS_SH+=		t_${name}
 TESTS_SH_SRC_t_${name}=	../net_common.sh t_${name}.sh
 .endfor

Index: src/tests/net/if_ipsec/Makefile
diff -u src/tests/net/if_ipsec/Makefile:1.3 src/tests/net/if_ipsec/Makefile:1.4
--- src/tests/net/if_ipsec/Makefile:1.3	Thu Jan 17 02:49:11 2019
+++ src/tests/net/if_ipsec/Makefile	Fri Nov 25 08:43:16 2022
@@ -1,11 +1,11 @@
-# $NetBSD: Makefile,v 1.3 2019/01/17 02:49:11 knakahara Exp $
+# $NetBSD: Makefile,v 1.4 2022/11/25 08:43:16 knakahara Exp $
 #
 
 .include 
 
 TESTSDIR=	${TESTSBASE}/net/if_ipsec
 
-.for name in ipsec ipsec_natt ipsec_pfil
+.for name in ipsec ipsec_natt ipsec_pfil ipsec_unnumbered
 TESTS_SH+=		t_${name}
 TESTS_SH_SRC_t_${name}=	../net_common.sh t_${name}.sh \
 	../ipsec/common.sh ../ipsec/algorithms.sh

Index: src/tests/net/if_pppoe/Makefile
diff -u src/tests/net/if_pppoe/Makefile:1.3 src/tests/net/if_pppoe/Makefile:1.4
--- src/tests/net/if_pppoe/Makefile:1.3	Thu Nov 24 09:03:53 2016
+++ src/tests/net/if_pppoe/Makefile	Fri Nov 25 08:43:16 2022
@@ -1,11 +1,11 @@
-# $NetBSD: Makefile,v 1.3 2016/11/24 09:03:53 ozaki-r Exp $
+# $NetBSD: Makefile,v 1.4 2022/11/25 08:43:16 knakahara Exp $
 #
 
 .include 
 
 TESTSDIR=	${TESTSBASE}/net/if_pppoe
 
-.for name in pppoe
+.for name in pppoe pppoe_unnumbered
 TESTS_SH+=		t_${name}
 TESTS_SH_SRC_t_${name}=	../net_common.sh t_${name}.sh
 .endfor

Added files:

Index: src/tests/net/if_gif/t_gif_unnumbered.sh
diff -u /dev/null src/tests/net/if_gif/t_gif_unnumbered.sh:1.1
--- /dev/null	Fri Nov 25 08:43:16 2022
+++ 

CVS commit: src

2022-11-25 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Nov 25 08:43:16 UTC 2022

Modified Files:
src/distrib/sets/lists/tests: mi
src/tests/net/if_gif: Makefile
src/tests/net/if_ipsec: Makefile
src/tests/net/if_pppoe: Makefile
Added Files:
src/tests/net/if_gif: t_gif_unnumbered.sh
src/tests/net/if_ipsec: t_ipsec_unnumbered.sh
src/tests/net/if_pppoe: t_pppoe_unnumbered.sh

Log Message:
Add ATF for unnumbered interfaces.


To generate a diff of this commit:
cvs rdiff -u -r1.1235 -r1.1236 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.2 -r1.3 src/tests/net/if_gif/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/net/if_gif/t_gif_unnumbered.sh
cvs rdiff -u -r1.3 -r1.4 src/tests/net/if_ipsec/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/net/if_ipsec/t_ipsec_unnumbered.sh
cvs rdiff -u -r1.3 -r1.4 src/tests/net/if_pppoe/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/net/if_pppoe/t_pppoe_unnumbered.sh

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



CVS commit: src/sbin/ifconfig

2022-11-25 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Nov 25 08:41:05 UTC 2022

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

Log Message:
ifconfig(8) support unnumbered flag.


To generate a diff of this commit:
cvs rdiff -u -r1.123 -r1.124 src/sbin/ifconfig/ifconfig.8
cvs rdiff -u -r1.248 -r1.249 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.8
diff -u src/sbin/ifconfig/ifconfig.8:1.123 src/sbin/ifconfig/ifconfig.8:1.124
--- src/sbin/ifconfig/ifconfig.8:1.123	Fri Jan  7 10:17:39 2022
+++ src/sbin/ifconfig/ifconfig.8	Fri Nov 25 08:41:05 2022
@@ -1,4 +1,4 @@
-.\"	$NetBSD: ifconfig.8,v 1.123 2022/01/07 10:17:39 bad Exp $
+.\"	$NetBSD: ifconfig.8,v 1.124 2022/11/25 08:41:05 knakahara 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 March 9, 2021
+.Dd November 25, 2022
 .Dt IFCONFIG 8
 .Os
 .Sh NAME
@@ -744,6 +744,10 @@ traffic can be protected using
 If the driver is a
 .Xr pfsync 4
 pseudo-device, broadcast the packets using multicast.
+.It Cm unnumbered
+Treat the interface as unnumbered.
+.It Cm -unnumbered
+Don't treat the interface as unnumbered.
 .El
 .Pp
 .Nm

Index: src/sbin/ifconfig/ifconfig.c
diff -u src/sbin/ifconfig/ifconfig.c:1.248 src/sbin/ifconfig/ifconfig.c:1.249
--- src/sbin/ifconfig/ifconfig.c:1.248	Wed Oct 14 13:37:14 2020
+++ src/sbin/ifconfig/ifconfig.c	Fri Nov 25 08:41:05 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: ifconfig.c,v 1.248 2020/10/14 13:37:14 roy Exp $	*/
+/*	$NetBSD: ifconfig.c,v 1.249 2022/11/25 08:41:05 knakahara 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.248 2020/10/14 13:37:14 roy Exp $");
+__RCSID("$NetBSD: ifconfig.c,v 1.249 2022/11/25 08:41:05 knakahara Exp $");
 #endif /* not lint */
 
 #include 
@@ -141,6 +141,7 @@ __dead static void usage(void);
 static const struct kwinst ifflagskw[] = {
 	  IFKW("arp", -IFF_NOARP)
 	, IFKW("debug", IFF_DEBUG)
+	, IFKW("unnumbered", IFF_UNNUMBERED)
 	, IFKW("link0", IFF_LINK0)
 	, IFKW("link1", IFF_LINK1)
 	, IFKW("link2", IFF_LINK2)
@@ -1524,6 +1525,7 @@ usage(void)
 		"\t[ preference n ]\n"
 		"\t[ link0 | -link0 ] [ link1 | -link1 ] [ link2 | -link2 ]\n"
 		"\t[ linkstr str | -linkstr ]\n"
+		"\t[ unnumbered | -unnumbered ]\n"
 		"\t[ description str | descr str | -description | -descr ]\n"
 		"   %s -a [-b] [-d] [-h] %s[-u] [-v] [-z] [ af ]\n"
 		"   %s -l [-b] [-d] [-s] [-u]\n"



CVS commit: src/sbin/ifconfig

2022-11-25 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Nov 25 08:41:05 UTC 2022

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

Log Message:
ifconfig(8) support unnumbered flag.


To generate a diff of this commit:
cvs rdiff -u -r1.123 -r1.124 src/sbin/ifconfig/ifconfig.8
cvs rdiff -u -r1.248 -r1.249 src/sbin/ifconfig/ifconfig.c

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



CVS commit: src/sys/sys

2022-11-25 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Nov 25 08:40:15 UTC 2022

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

Log Message:
Welcome to 9.99.107

- add IFF_UNNUMBERED flag


To generate a diff of this commit:
cvs rdiff -u -r1.719 -r1.720 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.719 src/sys/sys/param.h:1.720
--- src/sys/sys/param.h:1.719	Mon Nov  7 08:35:57 2022
+++ src/sys/sys/param.h	Fri Nov 25 08:40:15 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: param.h,v 1.719 2022/11/07 08:35:57 msaitoh Exp $	*/
+/*	$NetBSD: param.h,v 1.720 2022/11/25 08:40:15 knakahara Exp $	*/
 
 /*-
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -67,7 +67,7 @@
  *	2.99.9		(299000900)
  */
 
-#define	__NetBSD_Version__	999010600	/* NetBSD 9.99.106 */
+#define	__NetBSD_Version__	999010700	/* NetBSD 9.99.107 */
 
 #define __NetBSD_Prereq__(M,m,p) (M) * 1) + \
 (m) * 100) + (p) * 100) <= __NetBSD_Version__)



CVS commit: src/sys/sys

2022-11-25 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Nov 25 08:40:15 UTC 2022

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

Log Message:
Welcome to 9.99.107

- add IFF_UNNUMBERED flag


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

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



CVS commit: src/sys

2022-11-25 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Nov 25 08:39:32 UTC 2022

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

Log Message:
Support explicit unnumbered interface.

Currently, NetBSD supports implicit unnumbered interface by setting
the same IP address to two interfaces.  However, such interface is not
treated as unnumbered when one of the interfaces is being changed and
has been changed IP address.  That behavior can be harmful for some
routing daemons.


To generate a diff of this commit:
cvs rdiff -u -r1.303 -r1.304 src/sys/net/if.h
cvs rdiff -u -r1.234 -r1.235 src/sys/net/route.c
cvs rdiff -u -r1.246 -r1.247 src/sys/netinet/in.c

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.303 src/sys/net/if.h:1.304
--- src/sys/net/if.h:1.303	Mon Oct 24 08:11:25 2022
+++ src/sys/net/if.h	Fri Nov 25 08:39:32 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.h,v 1.303 2022/10/24 08:11:25 msaitoh Exp $	*/
+/*	$NetBSD: if.h,v 1.304 2022/11/25 08:39:32 knakahara Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc.
@@ -447,7 +447,15 @@ typedef struct ifnet {
 #define	IFF_DEBUG	0x0004		/* turn on debugging */
 #define	IFF_LOOPBACK	0x0008		/* is a loopback net */
 #define	IFF_POINTOPOINT	0x0010		/* interface is point-to-point link */
+#if 0
 /*			0x0020		   was IFF_NOTRAILERS */
+#else
+/*
+ * sys/compat/svr4 is remvoed on 19 Dec 2018.
+ * And then, IFF_NOTRAILERS itself is removed by if.h:r1.268 on 5 Feb 2019.
+ */
+#define	IFF_UNNUMBERED	0x0020		/* explicit unnumbered */
+#endif
 #define	IFF_RUNNING	0x0040		/* resources allocated */
 #define	IFF_NOARP	0x0080		/* no address resolution protocol */
 #define	IFF_PROMISC	0x0100		/* receive all packets */
@@ -599,7 +607,7 @@ if_start_lock(struct ifnet *ifp)
 #endif /* _KERNEL */
 
 #define	IFFBITS \
-"\020\1UP\2BROADCAST\3DEBUG\4LOOPBACK\5POINTOPOINT" \
+"\020\1UP\2BROADCAST\3DEBUG\4LOOPBACK\5POINTOPOINT\6UNNUMBERED" \
 "\7RUNNING\10NOARP\11PROMISC\12ALLMULTI\13OACTIVE\14SIMPLEX" \
 "\15LINK0\16LINK1\17LINK2\20MULTICAST"
 

Index: src/sys/net/route.c
diff -u src/sys/net/route.c:1.234 src/sys/net/route.c:1.235
--- src/sys/net/route.c:1.234	Tue Sep 20 02:23:37 2022
+++ src/sys/net/route.c	Fri Nov 25 08:39:32 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: route.c,v 1.234 2022/09/20 02:23:37 knakahara Exp $	*/
+/*	$NetBSD: route.c,v 1.235 2022/11/25 08:39:32 knakahara Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -97,7 +97,7 @@
 #endif
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.234 2022/09/20 02:23:37 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.235 2022/11/25 08:39:32 knakahara Exp $");
 
 #include 
 #ifdef RTFLUSH_DEBUG
@@ -1367,6 +1367,11 @@ rt_update_get_ifa(const struct rt_addrin
 		ifa = ifa_ifwithnet_psref(info->rti_info[RTAX_IFP], psref);
 		if (ifa == NULL)
 			goto next;
+		if (ifa->ifa_ifp->if_flags & IFF_UNNUMBERED) {
+			ifa_release(ifa, psref);
+			ifa = NULL;
+			goto next;
+		}
 		*ifp = ifa->ifa_ifp;
 		if_acquire(*ifp, psref_ifp);
 		if (info->rti_info[RTAX_IFA] == NULL &&

Index: src/sys/netinet/in.c
diff -u src/sys/netinet/in.c:1.246 src/sys/netinet/in.c:1.247
--- src/sys/netinet/in.c:1.246	Sat Nov 19 08:00:51 2022
+++ src/sys/netinet/in.c	Fri Nov 25 08:39:32 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: in.c,v 1.246 2022/11/19 08:00:51 yamt Exp $	*/
+/*	$NetBSD: in.c,v 1.247 2022/11/25 08:39:32 knakahara Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in.c,v 1.246 2022/11/19 08:00:51 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in.c,v 1.247 2022/11/25 08:39:32 knakahara Exp $");
 
 #include "arp.h"
 
@@ -790,6 +790,10 @@ in_ifaddlocal(struct ifaddr *ifa)
 	struct in_ifaddr *ia;
 
 	ia = (struct in_ifaddr *)ifa;
+	if ((ia->ia_ifp->if_flags & IFF_UNNUMBERED)) {
+		rt_addrmsg(RTM_NEWADDR, ifa);
+		return;
+	}
 	if (ia->ia_addr.sin_addr.s_addr == INADDR_ANY ||
 	(ia->ia_ifp->if_flags & IFF_POINTOPOINT &&
 	in_hosteq(ia->ia_dstaddr.sin_addr, ia->ia_addr.sin_addr)))
@@ -813,10 +817,17 @@ in_ifremlocal(struct ifaddr *ifa)
 	int bound = curlwp_bind();
 
 	ia = (struct in_ifaddr *)ifa;
+	if ((ia->ia_ifp->if_flags & IFF_UNNUMBERED)) {
+		rt_addrmsg(RTM_DELADDR, ifa);
+		goto out;
+	}
 	/* Delete the entry if exactly one ifaddr matches the
 	 * address, ifa->ifa_addr. */
 	s = pserialize_read_enter();
 	IN_ADDRLIST_READER_FOREACH(p) {
+		if ((p->ia_ifp->if_flags & IFF_UNNUMBERED))
+			continue;
+
 		if (!in_hosteq(p->ia_addr.sin_addr, ia->ia_addr.sin_addr))
 			continue;
 		if (p->ia_ifp != ia->ia_ifp)
@@ -1323,6 +1334,9 @@ in_addprefix(struct in_ifaddr *target, i
 		if (prefix.s_addr != p.s_addr)
 			continue;
 
+		if ((ia->ia_ifp->if_flags & IFF_UNNUMBERED))
+			continue;
+
 		/*
 		 * if we got a matching prefix route 

CVS commit: src/sys

2022-11-25 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Nov 25 08:39:32 UTC 2022

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

Log Message:
Support explicit unnumbered interface.

Currently, NetBSD supports implicit unnumbered interface by setting
the same IP address to two interfaces.  However, such interface is not
treated as unnumbered when one of the interfaces is being changed and
has been changed IP address.  That behavior can be harmful for some
routing daemons.


To generate a diff of this commit:
cvs rdiff -u -r1.303 -r1.304 src/sys/net/if.h
cvs rdiff -u -r1.234 -r1.235 src/sys/net/route.c
cvs rdiff -u -r1.246 -r1.247 src/sys/netinet/in.c

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



CVS commit: src/tests/net/ipsec

2022-11-23 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Nov 24 02:58:28 UTC 2022

Modified Files:
src/tests/net/ipsec: t_ipsec_forwarding.sh

Log Message:
clean up


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

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



CVS commit: src/tests/net/ipsec

2022-11-23 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Nov 24 02:58:28 UTC 2022

Modified Files:
src/tests/net/ipsec: t_ipsec_forwarding.sh

Log Message:
clean up


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/net/ipsec/t_ipsec_forwarding.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_forwarding.sh
diff -u src/tests/net/ipsec/t_ipsec_forwarding.sh:1.1 src/tests/net/ipsec/t_ipsec_forwarding.sh:1.2
--- src/tests/net/ipsec/t_ipsec_forwarding.sh:1.1	Wed Nov  9 08:21:20 2022
+++ src/tests/net/ipsec/t_ipsec_forwarding.sh	Thu Nov 24 02:58:28 2022
@@ -1,4 +1,4 @@
-#   $NetBSD: t_ipsec_forwarding.sh,v 1.1 2022/11/09 08:21:20 knakahara Exp $
+#   $NetBSD: t_ipsec_forwarding.sh,v 1.2 2022/11/24 02:58:28 knakahara Exp $
 #
 # Copyright (c) 2022 Internet Initiative Japan Inc.
 # All rights reserved.
@@ -456,33 +456,6 @@ test_ipsec_sp_port_ipv6()
 	atf_check -s exit:0 \
 	-o match:"${ip_remote_i}\.$port > ${ip_local_i}\.[0-9]+" \
 	cat $routfile
-
-#	# Check TCP communications from remote to local
-#	start_nc_server $SOCK_LOCAL $port $file_recv ipv6
-#	prepare_file $file_send
-#	export RUMP_SERVER=$SOCK_REMOTE
-#	atf_check -s exit:0 $HIJACKING nc -w 3 $ip_local_i $port < $file_send
-#	atf_check -s exit:0 diff -q $file_send $file_recv
-#	stop_nc_server
-#
-#	extract_new_packets $BUS_LOCAL_F > $loutfile
-#	extract_new_packets $BUS_REMOTE_F > $routfile
-#	$DEBUG && cat $loutfile
-#	atf_check -s exit:0 \
-#	-o match:"${ip_local_f}\.[0-9]+ > ${ip_remote_i}\.$port" \
-#	cat $loutfile
-#	atf_check -s exit:0 \
-#	-o match:"${ip_remote_i}\.$port > ${ip_local_f}\.[0-9]+" \
-#	cat $loutfile
-#	$DEBUG && cat $routfile
-#	atf_check -s exit:0 \
-#	-o match:"${ip_forward_l} > ${ip_remote_i}: ESP" \
-#	cat $routfile
-#	atf_check -s exit:0 \
-#	-o match:"${ip_remote_i} > ${ip_forward_l}: ESP" \
-#	cat $routfile
-
-
 }
 
 add_test_ipsec_sp_port()



CVS commit: src/sys/netinet

2022-11-21 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Nov 21 09:51:13 UTC 2022

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

Log Message:
Fix panic on packet sending via a route with rt_ifa of AF_LINK.

A route with rt_ifa of AF_LINK can be set by some routing daemons when
it adds a route that has a gateway of AF_LINK.  If there is no address on
a target interface, the kernel sets an AF_LINK address of the interface to
rt_ifa of the route.  In that case, a variable of a local address in
ip_output (ia) can be NULL and we need more NULL-checks of it.


To generate a diff of this commit:
cvs rdiff -u -r1.323 -r1.324 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.323 src/sys/netinet/ip_output.c:1.324
--- src/sys/netinet/ip_output.c:1.323	Fri Nov  4 09:00:58 2022
+++ src/sys/netinet/ip_output.c	Mon Nov 21 09:51:13 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_output.c,v 1.323 2022/11/04 09:00:58 ozaki-r Exp $	*/
+/*	$NetBSD: ip_output.c,v 1.324 2022/11/21 09:51:13 knakahara Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.323 2022/11/04 09:00:58 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.324 2022/11/21 09:51:13 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -531,6 +531,15 @@ ip_output(struct mbuf *m0, struct mbuf *
 	if (in_nullhost(ip->ip_src)) {
 		struct ifaddr *xifa;
 
+		/* If rt_ifa is AF_LINK, ia can be NULL. */
+		if (ia == NULL) {
+			KASSERTMSG(rt->rt_ifa->ifa_addr->sa_family == AF_LINK,
+			"sa_family=%d", rt->rt_ifa->ifa_addr->sa_family);
+			IP_STATINC(IP_STAT_NOROUTE);
+			error = EHOSTUNREACH;
+			goto bad;
+		}
+
 		xifa = >ia_ifa;
 		if (xifa->ifa_getifa != NULL) {
 			ia4_release(ia, _ia);
@@ -582,6 +591,15 @@ ip_output(struct mbuf *m0, struct mbuf *
 
 sendit:
 	if ((flags & (IP_FORWARDING|IP_NOIPNEWID)) == 0) {
+		/* If rt_ifa is AF_LINK, ia can be NULL. */
+		if (ia == NULL) {
+			KASSERTMSG(rt->rt_ifa->ifa_addr->sa_family == AF_LINK,
+			"sa_family=%d", rt->rt_ifa->ifa_addr->sa_family);
+			IP_STATINC(IP_STAT_NOROUTE);
+			error = EHOSTUNREACH;
+			goto bad;
+		}
+
 		if (m->m_pkthdr.len < IP_MINFRAGSIZE) {
 			ip->ip_id = 0;
 		} else if ((m->m_pkthdr.csum_flags & M_CSUM_TSOv4) == 0) {



CVS commit: src/sys/netinet

2022-11-21 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Nov 21 09:51:13 UTC 2022

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

Log Message:
Fix panic on packet sending via a route with rt_ifa of AF_LINK.

A route with rt_ifa of AF_LINK can be set by some routing daemons when
it adds a route that has a gateway of AF_LINK.  If there is no address on
a target interface, the kernel sets an AF_LINK address of the interface to
rt_ifa of the route.  In that case, a variable of a local address in
ip_output (ia) can be NULL and we need more NULL-checks of it.


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



CVS commit: src/sys/netinet

2022-11-16 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Nov 17 05:02:11 UTC 2022

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

Log Message:
Fix sending broken RTM_DELADDR message in some operations.

Here is mininum reproduction operation.

# ifconfig ixg0 172.16.0.1/29
# route monitor &
# ifconfig pppoe0 172.16.0.1/32 0.0.0.1


The broken RTM_DELADDR is the following.

got message of size 72 on Thu Nov 17 12:50:42 2022
#13: len 72, got message of size 80 on Thu Nov 17 12:50:42 2022
RTM_DELADDR: address being removed from iface: len 80, pid 3552, metric 0, 
addrflags: 0
sockaddrs: 0xb4
 Q00.00.ff.ff.ff.ff.00.00.00.00.00.00.00.00 pppoe0 default default


This problem is related to the following two commit.

(1) 
https://github.com/NetBSD/src/commit/b0210214689f17ec08988acd7ef8ae9cdc4c68bc
that is, sys/netinet/in.c:r1.183

(2) 
https://github.com/NetBSD/src/commit/61bad33c44f2f6a01a030e8aa5840c015716792a
that is, sys/netinet/in.c:r1.185

(1) adds in_scrubaddr() for old addresses to in_ifinit() without checking
IFA_ROUTE.
And then, (2) removes in_ifscrub() for POINTTOPOINT interface in in_control0.
The removed in_ifscrub() is called with checking IFA_ROUTE.
It seems these modifications about checking IFA_ROUTE logic causes this
problem, however the real reason is calling in_ifscrub() for the interface
which does not have IPv4 address.  So, scrubbing old address processing
should be done only if the interface already has IPv4 address.


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

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



CVS commit: src/sys/netinet

2022-11-16 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Nov 17 05:02:11 UTC 2022

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

Log Message:
Fix sending broken RTM_DELADDR message in some operations.

Here is mininum reproduction operation.

# ifconfig ixg0 172.16.0.1/29
# route monitor &
# ifconfig pppoe0 172.16.0.1/32 0.0.0.1


The broken RTM_DELADDR is the following.

got message of size 72 on Thu Nov 17 12:50:42 2022
#13: len 72, got message of size 80 on Thu Nov 17 12:50:42 2022
RTM_DELADDR: address being removed from iface: len 80, pid 3552, metric 0, 
addrflags: 0
sockaddrs: 0xb4
 Q00.00.ff.ff.ff.ff.00.00.00.00.00.00.00.00 pppoe0 default default


This problem is related to the following two commit.

(1) 
https://github.com/NetBSD/src/commit/b0210214689f17ec08988acd7ef8ae9cdc4c68bc
that is, sys/netinet/in.c:r1.183

(2) 
https://github.com/NetBSD/src/commit/61bad33c44f2f6a01a030e8aa5840c015716792a
that is, sys/netinet/in.c:r1.185

(1) adds in_scrubaddr() for old addresses to in_ifinit() without checking
IFA_ROUTE.
And then, (2) removes in_ifscrub() for POINTTOPOINT interface in in_control0.
The removed in_ifscrub() is called with checking IFA_ROUTE.
It seems these modifications about checking IFA_ROUTE logic causes this
problem, however the real reason is calling in_ifscrub() for the interface
which does not have IPv4 address.  So, scrubbing old address processing
should be done only if the interface already has IPv4 address.


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

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.244 src/sys/netinet/in.c:1.245
--- src/sys/netinet/in.c:1.244	Fri Nov  4 09:03:20 2022
+++ src/sys/netinet/in.c	Thu Nov 17 05:02:11 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: in.c,v 1.244 2022/11/04 09:03:20 ozaki-r Exp $	*/
+/*	$NetBSD: in.c,v 1.245 2022/11/17 05:02:11 knakahara Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in.c,v 1.244 2022/11/04 09:03:20 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in.c,v 1.245 2022/11/17 05:02:11 knakahara Exp $");
 
 #include "arp.h"
 
@@ -1194,7 +1194,11 @@ in_ifinit(struct ifnet *ifp, struct in_i
 		return error;
 	}
 
-	if (scrub || hostIsNew) {
+	/*
+	 * The interface which does not have IPv4 address is not required
+	 * to scrub old address.  So, skip scrub such cases.
+	 */
+	if (oldaddr.sin_family == AF_INET && (scrub || hostIsNew)) {
 		int newflags = ia->ia4_flags;
 
 		ia->ia_ifa.ifa_addr = sintosa();



Re: CVS commit: src/sys

2022-11-14 Thread Kengo NAKAHARA

Hi,

Thank you for your updating.


Thanks,

On 2022/11/14 19:15, Roy Marples wrote:

On 14/11/2022 09:49, Kengo NAKAHARA wrote:

Hi,

Please update the size in comment, when struct pkthdr is changed.
 https://github.com/NetBSD/src/blob/trunk/sys/sys/mbuf.h#L181


Thanks,


Done, thanks.

Roy


--
//
Internet Initiative Japan Inc.

Device Engineering Section,
Product Division,
Technology Unit

Kengo NAKAHARA 




Re: CVS commit: src/sys

2022-11-14 Thread Kengo NAKAHARA

Hi,

Please update the size in comment, when struct pkthdr is changed.
https://github.com/NetBSD/src/blob/trunk/sys/sys/mbuf.h#L181


Thanks,

On 2022/11/14 18:23, Roy Marples wrote:

Module Name:src
Committed By:   roy
Date:   Mon Nov 14 09:23:42 UTC 2022

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

Log Message:
net: Store a pointer to the Layer 2 Sender Hardware address in mbuf

The BSD networking stack is designed around passing a mbuf down the chain
and each layer removes the part it's interested in before passing it to
the next. This makes it easy for each layer to do it's work,
but non trivial to work backwards.

As such we now store a pointer to the Senders Hardware address in the
mbuf packet header so that protocols can perform any required validation.


To generate a diff of this commit:
cvs rdiff -u -r1.320 -r1.321 src/sys/net/if_ethersubr.c
cvs rdiff -u -r1.232 -r1.233 src/sys/sys/mbuf.h

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



--
//
Internet Initiative Japan Inc.

Device Engineering Section,
Product Division,
Technology Unit

Kengo NAKAHARA 




CVS commit: src

2022-11-09 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Nov  9 08:21:20 UTC 2022

Modified Files:
src/distrib/sets/lists/tests: mi
src/tests/net/ipsec: Makefile
Added Files:
src/tests/net/ipsec: t_ipsec_forwarding.sh

Log Message:
Add test for sys/netipsec/ipsec.c:r1.176.


To generate a diff of this commit:
cvs rdiff -u -r1.1228 -r1.1229 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.11 -r1.12 src/tests/net/ipsec/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/net/ipsec/t_ipsec_forwarding.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.1228 src/distrib/sets/lists/tests/mi:1.1229
--- src/distrib/sets/lists/tests/mi:1.1228	Tue Nov  8 06:08:33 2022
+++ src/distrib/sets/lists/tests/mi	Wed Nov  9 08:21:20 2022
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1228 2022/11/08 06:08:33 blymn Exp $
+# $NetBSD: mi,v 1.1229 2022/11/09 08:21:20 knakahara Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -4214,6 +4214,7 @@
 ./usr/tests/net/ipsec/natt_terminator			tests-net-tests		atf,rump
 ./usr/tests/net/ipsec/t_ipsec_ah_keys			tests-net-tests		atf,rump
 ./usr/tests/net/ipsec/t_ipsec_esp_keys			tests-net-tests		atf,rump
+./usr/tests/net/ipsec/t_ipsec_forwarding		tests-net-tests		atf,rump
 ./usr/tests/net/ipsec/t_ipsec_gif			tests-net-tests		atf,rump
 ./usr/tests/net/ipsec/t_ipsec_l2tp			tests-net-tests		atf,rump
 ./usr/tests/net/ipsec/t_ipsec_misc			tests-net-tests		atf,rump

Index: src/tests/net/ipsec/Makefile
diff -u src/tests/net/ipsec/Makefile:1.11 src/tests/net/ipsec/Makefile:1.12
--- src/tests/net/ipsec/Makefile:1.11	Tue Oct 11 09:55:21 2022
+++ src/tests/net/ipsec/Makefile	Wed Nov  9 08:21:20 2022
@@ -1,13 +1,13 @@
-# $NetBSD: Makefile,v 1.11 2022/10/11 09:55:21 knakahara Exp $
+# $NetBSD: Makefile,v 1.12 2022/11/09 08:21:20 knakahara Exp $
 #
 
 .include 
 
 TESTSDIR=	${TESTSBASE}/net/ipsec
 
-.for name in ipsec_ah_keys ipsec_esp_keys ipsec_gif ipsec_l2tp ipsec_misc \
-ipsec_natt ipsec_sockopt ipsec_spflags ipsec_sysctl ipsec_tcp \
-ipsec_transport ipsec_tunnel ipsec_tunnel_ipcomp ipsec_tunnel_odd
+.for name in ipsec_ah_keys ipsec_esp_keys ipsec_forwarding ipsec_gif \
+ipsec_l2tp ipsec_misc ipsec_natt ipsec_sockopt ipsec_spflags ipsec_sysctl \
+ipsec_tcp ipsec_transport ipsec_tunnel ipsec_tunnel_ipcomp ipsec_tunnel_odd
 TESTS_SH+=		t_${name}
 TESTS_SH_SRC_t_${name}=	../net_common.sh ./common.sh ./algorithms.sh \
 t_${name}.sh

Added files:

Index: src/tests/net/ipsec/t_ipsec_forwarding.sh
diff -u /dev/null src/tests/net/ipsec/t_ipsec_forwarding.sh:1.1
--- /dev/null	Wed Nov  9 08:21:20 2022
+++ src/tests/net/ipsec/t_ipsec_forwarding.sh	Wed Nov  9 08:21:20 2022
@@ -0,0 +1,525 @@
+#   $NetBSD: t_ipsec_forwarding.sh,v 1.1 2022/11/09 08:21:20 knakahara Exp $
+#
+# Copyright (c) 2022 Internet Initiative Japan Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#notice, this list of conditions and the following disclaimer in the
+#documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+SOCK_LOCAL=unix://ipsec_local
+SOCK_FORWARD=unix://ipsec_forward
+SOCK_REMOTE=unix://ipsec_remote
+BUS_LOCAL_I=./bus_ipsec_local
+BUS_LOCAL_F=./bus_ipsec_local_forward
+BUS_REMOTE_F=./bus_ipsec_remote_forward
+BUS_REMOTE_I=./bus_ipsec_remote
+
+DEBUG=${DEBUG:-false}
+
+setup_servers_ipv4()
+{
+
+	rump_server_crypto_start $SOCK_LOCAL netipsec
+	rump_server_crypto_start $SOCK_FORWARD netipsec
+	rump_server_crypto_start $SOCK_REMOTE netipsec
+	rump_server_add_iface $SOCK_LOCAL shmif0 $BUS_LOCAL_F
+	rump_server_add_iface $SOCK_LOCAL shmif1 $BUS_LOCAL_I
+	rump_server_add_iface $SOCK_FORWARD shmif0 $BUS_LOCAL_F
+	rump_server_add_iface $SOCK_FORWARD shmif1 

CVS commit: src

2022-11-09 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Nov  9 08:21:20 UTC 2022

Modified Files:
src/distrib/sets/lists/tests: mi
src/tests/net/ipsec: Makefile
Added Files:
src/tests/net/ipsec: t_ipsec_forwarding.sh

Log Message:
Add test for sys/netipsec/ipsec.c:r1.176.


To generate a diff of this commit:
cvs rdiff -u -r1.1228 -r1.1229 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.11 -r1.12 src/tests/net/ipsec/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/net/ipsec/t_ipsec_forwarding.sh

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



CVS commit: src/sys/netipsec

2022-11-09 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Nov  9 08:18:53 UTC 2022

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

Log Message:
Fix IPv4 security policy with port number does not work for forwarding packets.


To generate a diff of this commit:
cvs rdiff -u -r1.175 -r1.176 src/sys/netipsec/ipsec.c

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

Modified files:

Index: src/sys/netipsec/ipsec.c
diff -u src/sys/netipsec/ipsec.c:1.175 src/sys/netipsec/ipsec.c:1.176
--- src/sys/netipsec/ipsec.c:1.175	Fri Nov  4 09:00:58 2022
+++ src/sys/netipsec/ipsec.c	Wed Nov  9 08:18:52 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: ipsec.c,v 1.175 2022/11/04 09:00:58 ozaki-r Exp $ */
+/* $NetBSD: ipsec.c,v 1.176 2022/11/09 08:18:52 knakahara 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.175 2022/11/04 09:00:58 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ipsec.c,v 1.176 2022/11/09 08:18:52 knakahara Exp $");
 
 /*
  * IPsec controller part.
@@ -543,7 +543,7 @@ ipsec_getpolicybyaddr(struct mbuf *m, u_
 	sp = NULL;
 
 	/* Make an index to look for a policy. */
-	*error = ipsec_setspidx(m, , dir, (flag & IP_FORWARDING) ? 0 : 1);
+	*error = ipsec_setspidx(m, , dir, 1);
 	if (*error != 0) {
 		IPSECLOG(LOG_DEBUG, "setpidx failed, dir %u flag %u\n", dir, flag);
 		memset(, 0, sizeof(spidx));



CVS commit: src/sys/netipsec

2022-11-09 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Nov  9 08:18:53 UTC 2022

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

Log Message:
Fix IPv4 security policy with port number does not work for forwarding packets.


To generate a diff of this commit:
cvs rdiff -u -r1.175 -r1.176 src/sys/netipsec/ipsec.c

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



CVS commit: src

2022-10-23 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Oct 24 01:54:19 UTC 2022

Modified Files:
src/share/man/man7: sysctl.7
src/sys/netinet6: in6.c in6_proto.c ip6_input.c ip6_var.h

Log Message:
Fix PR kern/57037

Be able to change the behavior sending parameter changing routing messages.
When set net.inet6.ip6.param_rt_msg=0, don't send parameter changing
routing messages.
When set net.inet6.ip6.param_rt_msg=1(default), send parameter changing
routing messages by RTM_NEWADDR.


To generate a diff of this commit:
cvs rdiff -u -r1.161 -r1.162 src/share/man/man7/sysctl.7
cvs rdiff -u -r1.286 -r1.287 src/sys/netinet6/in6.c
cvs rdiff -u -r1.129 -r1.130 src/sys/netinet6/in6_proto.c
cvs rdiff -u -r1.225 -r1.226 src/sys/netinet6/ip6_input.c
cvs rdiff -u -r1.91 -r1.92 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/share/man/man7/sysctl.7
diff -u src/share/man/man7/sysctl.7:1.161 src/share/man/man7/sysctl.7:1.162
--- src/share/man/man7/sysctl.7:1.161	Mon Aug 29 09:14:02 2022
+++ src/share/man/man7/sysctl.7	Mon Oct 24 01:54:19 2022
@@ -1,4 +1,4 @@
-.\"	$NetBSD: sysctl.7,v 1.161 2022/08/29 09:14:02 knakahara Exp $
+.\"	$NetBSD: sysctl.7,v 1.162 2022/10/24 01:54:19 knakahara Exp $
 .\"
 .\" Copyright (c) 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\"	@(#)sysctl.3	8.4 (Berkeley) 5/9/95
 .\"
-.Dd August 29, 2022
+.Dd October 24, 2022
 .Dt SYSCTL 7
 .Os
 .Sh NAME
@@ -1888,6 +1888,7 @@ The currently defined protocols and name
 .It ip6	maxfragpackets	integer	yes
 .It ip6	maxfrags	integer	yes
 .It ip6	neighborgcthresh	integer	yes
+.It ip6	param_rt_msg	integer	yes
 .It ip6	redirect	integer	yes
 .It ip6	rr_prune	integer	yes
 .It ip6	use_deprecated	integer	yes
@@ -2023,6 +2024,10 @@ The flag is provided basically for avoid
 Maximum number of entries in neighbor cache per interface.
 Set to negative to disable.
 The default value is 2048.
+.It Li ip6.param_rt_msg
+If set to 0, parameter changing routing message is suppressed.
+If set to 1, parameter changing routing message is sent by RTM_NEWADDR.
+Other values are undefined yet.
 .It Li ip6.redirect
 If set to 1, ICMPv6 redirects may be sent by the node.
 This option is ignored unless the node is routing IP packets,

Index: src/sys/netinet6/in6.c
diff -u src/sys/netinet6/in6.c:1.286 src/sys/netinet6/in6.c:1.287
--- src/sys/netinet6/in6.c:1.286	Tue Sep 20 02:23:37 2022
+++ src/sys/netinet6/in6.c	Mon Oct 24 01:54:19 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: in6.c,v 1.286 2022/09/20 02:23:37 knakahara Exp $	*/
+/*	$NetBSD: in6.c,v 1.287 2022/10/24 01:54:19 knakahara 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.286 2022/09/20 02:23:37 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.287 2022/10/24 01:54:19 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1065,6 +1065,9 @@ in6_update_ifa1(struct ifnet *ifp, struc
 	int dad_delay, was_tentative;
 	struct in6_ifaddr *ia = iap ? *iap : NULL;
 	char ip6buf[INET6_ADDRSTRLEN];
+	bool addrmaskNotChanged = false;
+	bool send_rtm_newaddr = (ip6_param_rt_msg == 1);
+	int saved_flags;
 
 	KASSERT((iap == NULL && psref == NULL) ||
 	(iap != NULL && psref != NULL));
@@ -1186,6 +1189,21 @@ in6_update_ifa1(struct ifnet *ifp, struc
 			return 0; /* there's nothing to do */
 	}
 
+#define sin6eq(a, b) \
+	((a)->sin6_len == sizeof(struct sockaddr_in6) && \
+	 (b)->sin6_len == sizeof(struct sockaddr_in6) && \
+	 IN6_ARE_ADDR_EQUAL(&(a)->sin6_addr, &(b)->sin6_addr))
+
+	if (!send_rtm_newaddr) {
+		if (ia != NULL &&
+		sin6eq(>ifra_addr, >ia_addr) &&
+		sin6eq(>ifra_prefixmask, >ia_prefixmask)) {
+			addrmaskNotChanged = true;
+			saved_flags = ia->ia6_flags;  /* check it later */
+		}
+	}
+#undef sin6eq
+
 	/*
 	 * If this is a new address, allocate a new ifaddr and link it
 	 * into chains.
@@ -1291,6 +1309,17 @@ in6_update_ifa1(struct ifnet *ifp, struc
 		ia->ia6_lifetime.ia6t_preferred = time_uptime;
 	}
 
+	if (!send_rtm_newaddr) {
+		/*
+		 * We will not send RTM_NEWADDR if the only difference between
+		 * ia and ifra is preferred/valid lifetimes, because it is not
+		 * very useful for userland programs to be notified of that
+		 * changes.
+		 */
+		if (addrmaskNotChanged && ia->ia6_flags == saved_flags)
+			return 0;
+	}
+
 	if (hostIsNew) {
 		/*
 		 * We need a reference to ia before calling in6_ifinit.

Index: src/sys/netinet6/in6_proto.c
diff -u src/sys/netinet6/in6_proto.c:1.129 src/sys/netinet6/in6_proto.c:1.130
--- src/sys/netinet6/in6_proto.c:1.129	Sat Sep  3 02:53:18 2022
+++ src/sys/netinet6/in6_proto.c	Mon Oct 24 01:54:19 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: in6_proto.c,v 1.129 2022/09/03 02:53:18 thorpej Exp $	*/
+/*	$NetBSD: in6_proto.c,v 1.130 2022/10/24 01:54:19 knakahara Exp $	*/
 /*	

CVS commit: src

2022-10-23 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Oct 24 01:54:19 UTC 2022

Modified Files:
src/share/man/man7: sysctl.7
src/sys/netinet6: in6.c in6_proto.c ip6_input.c ip6_var.h

Log Message:
Fix PR kern/57037

Be able to change the behavior sending parameter changing routing messages.
When set net.inet6.ip6.param_rt_msg=0, don't send parameter changing
routing messages.
When set net.inet6.ip6.param_rt_msg=1(default), send parameter changing
routing messages by RTM_NEWADDR.


To generate a diff of this commit:
cvs rdiff -u -r1.161 -r1.162 src/share/man/man7/sysctl.7
cvs rdiff -u -r1.286 -r1.287 src/sys/netinet6/in6.c
cvs rdiff -u -r1.129 -r1.130 src/sys/netinet6/in6_proto.c
cvs rdiff -u -r1.225 -r1.226 src/sys/netinet6/ip6_input.c
cvs rdiff -u -r1.91 -r1.92 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.



CVS commit: src

2022-10-11 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Tue Oct 11 09:55:21 UTC 2022

Modified Files:
src/distrib/sets/lists/tests: mi
src/tests/net/ipsec: Makefile
Added Files:
src/tests/net/ipsec: t_ipsec_spflags.sh

Log Message:
Add test for sadb_x_policy->sadb_x_policy_flags.


To generate a diff of this commit:
cvs rdiff -u -r1.1223 -r1.1224 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.10 -r1.11 src/tests/net/ipsec/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/net/ipsec/t_ipsec_spflags.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.1223 src/distrib/sets/lists/tests/mi:1.1224
--- src/distrib/sets/lists/tests/mi:1.1223	Fri Sep  9 22:14:28 2022
+++ src/distrib/sets/lists/tests/mi	Tue Oct 11 09:55:21 2022
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1223 2022/09/09 22:14:28 wiz Exp $
+# $NetBSD: mi,v 1.1224 2022/10/11 09:55:21 knakahara Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -4217,6 +4217,7 @@
 ./usr/tests/net/ipsec/t_ipsec_misc			tests-net-tests		atf,rump
 ./usr/tests/net/ipsec/t_ipsec_natt			tests-net-tests		atf,rump
 ./usr/tests/net/ipsec/t_ipsec_sockopt			tests-net-tests		atf,rump
+./usr/tests/net/ipsec/t_ipsec_spflags			tests-net-tests		atf,rump
 ./usr/tests/net/ipsec/t_ipsec_sysctl			tests-net-tests		atf,rump
 ./usr/tests/net/ipsec/t_ipsec_tcp			tests-net-tests		atf,rump
 ./usr/tests/net/ipsec/t_ipsec_transport			tests-net-tests		atf,rump

Index: src/tests/net/ipsec/Makefile
diff -u src/tests/net/ipsec/Makefile:1.10 src/tests/net/ipsec/Makefile:1.11
--- src/tests/net/ipsec/Makefile:1.10	Mon Oct 30 15:59:23 2017
+++ src/tests/net/ipsec/Makefile	Tue Oct 11 09:55:21 2022
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.10 2017/10/30 15:59:23 ozaki-r Exp $
+# $NetBSD: Makefile,v 1.11 2022/10/11 09:55:21 knakahara Exp $
 #
 
 .include 
@@ -6,8 +6,8 @@
 TESTSDIR=	${TESTSBASE}/net/ipsec
 
 .for name in ipsec_ah_keys ipsec_esp_keys ipsec_gif ipsec_l2tp ipsec_misc \
-ipsec_natt ipsec_sockopt ipsec_sysctl ipsec_tcp ipsec_transport \
-ipsec_tunnel ipsec_tunnel_ipcomp ipsec_tunnel_odd
+ipsec_natt ipsec_sockopt ipsec_spflags ipsec_sysctl ipsec_tcp \
+ipsec_transport ipsec_tunnel ipsec_tunnel_ipcomp ipsec_tunnel_odd
 TESTS_SH+=		t_${name}
 TESTS_SH_SRC_t_${name}=	../net_common.sh ./common.sh ./algorithms.sh \
 t_${name}.sh

Added files:

Index: src/tests/net/ipsec/t_ipsec_spflags.sh
diff -u /dev/null src/tests/net/ipsec/t_ipsec_spflags.sh:1.1
--- /dev/null	Tue Oct 11 09:55:21 2022
+++ src/tests/net/ipsec/t_ipsec_spflags.sh	Tue Oct 11 09:55:21 2022
@@ -0,0 +1,97 @@
+#   $NetBSD: t_ipsec_spflags.sh,v 1.1 2022/10/11 09:55:21 knakahara Exp $
+#
+# Copyright (c) 2022 Internet Initiative Japan Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#notice, this list of conditions and the following disclaimer in the
+#documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+SOCK_LOCAL=unix://ipsec_local
+
+DEBUG=${DEBUG:-false}
+
+test_flag_if_ipsec_sp_common()
+{
+	local ip_gwlo_tun=20.0.0.1
+	local ip_gwre_tun=20.0.0.2
+
+	rump_server_crypto_start $SOCK_LOCAL netipsec ipsec
+	export RUMP_SERVER=$SOCK_LOCAL
+	atf_check -s exit:0 rump.ifconfig ipsec0 create
+	atf_check -s exit:0 rump.ifconfig ipsec0 \
+	tunnel $ip_gwlo_tun $ip_gwre_tun
+	atf_check -s exit:0 -o match:'sadb_x_policy\{ type=2 dir=2 flags=0x80' $HIJACKING setkey -DPv
+}
+
+test_flag_userland_sp_common()
+{
+	local ip_gwlo_tun=20.0.0.1
+	local ip_gwre_tun=20.0.0.2
+	local tmpfile=./tmp
+
+	name="ipsec_spflag_userland_sp"
+	desc="Tests of IPsec SPD flags at userland"
+
+	atf_test_case ${name} cleanup
+
+	rump_server_crypto_start $SOCK_LOCAL netipsec ipsec
+
+	export 

CVS commit: src

2022-10-11 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Tue Oct 11 09:55:21 UTC 2022

Modified Files:
src/distrib/sets/lists/tests: mi
src/tests/net/ipsec: Makefile
Added Files:
src/tests/net/ipsec: t_ipsec_spflags.sh

Log Message:
Add test for sadb_x_policy->sadb_x_policy_flags.


To generate a diff of this commit:
cvs rdiff -u -r1.1223 -r1.1224 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.10 -r1.11 src/tests/net/ipsec/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/net/ipsec/t_ipsec_spflags.sh

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



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

2022-10-11 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Tue Oct 11 09:54:15 UTC 2022

Modified Files:
src/crypto/dist/ipsec-tools/src/libipsec: key_debug.c

Log Message:
Add parser sadb_x_policy_flags to libipsec/key_debug.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 \
src/crypto/dist/ipsec-tools/src/libipsec/key_debug.c

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



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

2022-10-11 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Tue Oct 11 09:54:15 UTC 2022

Modified Files:
src/crypto/dist/ipsec-tools/src/libipsec: key_debug.c

Log Message:
Add parser sadb_x_policy_flags to libipsec/key_debug.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 \
src/crypto/dist/ipsec-tools/src/libipsec/key_debug.c

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

Modified files:

Index: src/crypto/dist/ipsec-tools/src/libipsec/key_debug.c
diff -u src/crypto/dist/ipsec-tools/src/libipsec/key_debug.c:1.16 src/crypto/dist/ipsec-tools/src/libipsec/key_debug.c:1.17
--- src/crypto/dist/ipsec-tools/src/libipsec/key_debug.c:1.16	Mon Sep  6 17:19:52 2021
+++ src/crypto/dist/ipsec-tools/src/libipsec/key_debug.c	Tue Oct 11 09:54:15 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: key_debug.c,v 1.16 2021/09/06 17:19:52 rillig Exp $	*/
+/*	$NetBSD: key_debug.c,v 1.17 2022/10/11 09:54:15 knakahara Exp $	*/
 
 /*	$KAME: key_debug.c,v 1.29 2001/08/16 14:25:41 itojun Exp $	*/
 
@@ -453,11 +453,11 @@ kdebug_sadb_x_policy(struct sadb_ext *ex
 		panic("kdebug_sadb_x_policy: NULL pointer was passed.\n");
 
 #ifdef HAVE_PFKEY_POLICY_PRIORITY
-	printf("sadb_x_policy{ type=%u dir=%u id=%x priority=%u }\n",
+	printf("sadb_x_policy{ type=%u dir=%u flags=0x%02x id=%x priority=%u }\n",
 #else
-	printf("sadb_x_policy{ type=%u dir=%u id=%x }\n",
+	printf("sadb_x_policy{ type=%u dir=%u flags=0x%02x id=%x }\n",
 #endif
-		xpl->sadb_x_policy_type, xpl->sadb_x_policy_dir,
+		xpl->sadb_x_policy_type, xpl->sadb_x_policy_dir, xpl->sadb_x_policy_flags,
 #ifdef HAVE_PFKEY_POLICY_PRIORITY
 		xpl->sadb_x_policy_id, xpl->sadb_x_policy_priority);
 #else



CVS commit: src/sys/sys

2022-10-11 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Tue Oct 11 09:52:50 UTC 2022

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

Log Message:
Welcome to 9.99.101

- changed struct sadb_x_policy in pfkeyv2.h


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

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



CVS commit: src/sys/sys

2022-10-11 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Tue Oct 11 09:52:50 UTC 2022

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

Log Message:
Welcome to 9.99.101

- changed struct sadb_x_policy in pfkeyv2.h


To generate a diff of this commit:
cvs rdiff -u -r1.713 -r1.714 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.713 src/sys/sys/param.h:1.714
--- src/sys/sys/param.h:1.713	Tue Sep 20 02:24:18 2022
+++ src/sys/sys/param.h	Tue Oct 11 09:52:49 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: param.h,v 1.713 2022/09/20 02:24:18 knakahara Exp $	*/
+/*	$NetBSD: param.h,v 1.714 2022/10/11 09:52:49 knakahara Exp $	*/
 
 /*-
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -67,7 +67,7 @@
  *	2.99.9		(299000900)
  */
 
-#define	__NetBSD_Version__	99901	/* NetBSD 9.99.100 */
+#define	__NetBSD_Version__	999010100	/* NetBSD 9.99.101 */
 
 #define __NetBSD_Prereq__(M,m,p) (M) * 1) + \
 (m) * 100) + (p) * 100) <= __NetBSD_Version__)



CVS commit: src/sys

2022-10-11 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Tue Oct 11 09:51:47 UTC 2022

Modified Files:
src/sys/net: if_ipsec.c pfkeyv2.h
src/sys/netipsec: key.c key_debug.c

Log Message:
Add sadb_x_policy_flags to inform SP origination.

This extension(struct sadb_x_policy) is *not* defined by RFC2367.

OpenBSD does not have reserved fields in struct sadb_x_policy.
Linux does not use this field yet.
FreeBSD uses this field as "sadb_x_policy_scope"; the value range is
from 0x00 to 0x04.

We use from most significant bit to avoid the above usage.


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/sys/net/if_ipsec.c src/sys/net/pfkeyv2.h
cvs rdiff -u -r1.276 -r1.277 src/sys/netipsec/key.c
cvs rdiff -u -r1.24 -r1.25 src/sys/netipsec/key_debug.c

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

Modified files:

Index: src/sys/net/if_ipsec.c
diff -u src/sys/net/if_ipsec.c:1.33 src/sys/net/if_ipsec.c:1.34
--- src/sys/net/if_ipsec.c:1.33	Thu Oct  6 06:59:24 2022
+++ src/sys/net/if_ipsec.c	Tue Oct 11 09:51:47 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ipsec.c,v 1.33 2022/10/06 06:59:24 knakahara Exp $  */
+/*	$NetBSD: if_ipsec.c,v 1.34 2022/10/11 09:51:47 knakahara Exp $  */
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_ipsec.c,v 1.33 2022/10/06 06:59:24 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ipsec.c,v 1.34 2022/10/11 09:51:47 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1706,7 +1706,7 @@ if_ipsec_set_sadb_x_policy(struct sadb_x
 	xpl->sadb_x_policy_exttype = SADB_X_EXT_POLICY;
 	xpl->sadb_x_policy_type = policy;
 	xpl->sadb_x_policy_dir = dir;
-	xpl->sadb_x_policy_reserved = 0;
+	xpl->sadb_x_policy_flags = 0;
 	xpl->sadb_x_policy_id = id;
 	xpl->sadb_x_policy_reserved2 = 0;
 
Index: src/sys/net/pfkeyv2.h
diff -u src/sys/net/pfkeyv2.h:1.33 src/sys/net/pfkeyv2.h:1.34
--- src/sys/net/pfkeyv2.h:1.33	Sat Apr 16 18:15:22 2022
+++ src/sys/net/pfkeyv2.h	Tue Oct 11 09:51:47 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: pfkeyv2.h,v 1.33 2022/04/16 18:15:22 andvar Exp $	*/
+/*	$NetBSD: pfkeyv2.h,v 1.34 2022/10/11 09:51:47 knakahara Exp $	*/
 /*	$KAME: pfkeyv2.h,v 1.36 2003/07/25 09:33:37 itojun Exp $	*/
 
 /*
@@ -228,7 +228,8 @@ struct sadb_x_policy {
   uint16_t sadb_x_policy_exttype;
   uint16_t sadb_x_policy_type;		/* See policy type of ipsec.h */
   uint8_t sadb_x_policy_dir;		/* direction, see ipsec.h */
-  uint8_t sadb_x_policy_reserved;
+  uint8_t sadb_x_policy_flags;
+#define IPSEC_POLICY_FLAG_ORIGIN_KERNEL 0x80	/* policy is generated by kernel */
   uint32_t sadb_x_policy_id;
   uint32_t sadb_x_policy_reserved2;
 };

Index: src/sys/netipsec/key.c
diff -u src/sys/netipsec/key.c:1.276 src/sys/netipsec/key.c:1.277
--- src/sys/netipsec/key.c:1.276	Tue Aug  9 08:03:22 2022
+++ src/sys/netipsec/key.c	Tue Oct 11 09:51:47 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: key.c,v 1.276 2022/08/09 08:03:22 knakahara Exp $	*/
+/*	$NetBSD: key.c,v 1.277 2022/10/11 09:51:47 knakahara 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.276 2022/08/09 08:03:22 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: key.c,v 1.277 2022/10/11 09:51:47 knakahara Exp $");
 
 /*
  * This code is referred to RFC 2367
@@ -2089,6 +2089,8 @@ key_sp2msg(const struct secpolicy *sp, i
 	xpl->sadb_x_policy_type = sp->policy;
 	xpl->sadb_x_policy_dir = sp->spidx.dir;
 	xpl->sadb_x_policy_id = sp->id;
+	if (sp->origin == IPSEC_SPORIGIN_KERNEL)
+		xpl->sadb_x_policy_flags |= IPSEC_POLICY_FLAG_ORIGIN_KERNEL;
 	p = (char *)xpl + sizeof(*xpl);
 
 	/* if is the policy for ipsec ? */

Index: src/sys/netipsec/key_debug.c
diff -u src/sys/netipsec/key_debug.c:1.24 src/sys/netipsec/key_debug.c:1.25
--- src/sys/netipsec/key_debug.c:1.24	Wed May 18 15:20:18 2022
+++ src/sys/netipsec/key_debug.c	Tue Oct 11 09:51:47 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: key_debug.c,v 1.24 2022/05/18 15:20:18 christos Exp $	*/
+/*	$NetBSD: key_debug.c,v 1.25 2022/10/11 09:51:47 knakahara Exp $	*/
 /*	$FreeBSD: key_debug.c,v 1.1.4.1 2003/01/24 05:11:36 sam Exp $	*/
 /*	$KAME: key_debug.c,v 1.26 2001/06/27 10:46:50 sakane Exp $	*/
 
@@ -33,7 +33,7 @@
 
 #ifdef _KERNEL
 #include 
-__KERNEL_RCSID(0, "$NetBSD: key_debug.c,v 1.24 2022/05/18 15:20:18 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: key_debug.c,v 1.25 2022/10/11 09:51:47 knakahara Exp $");
 #endif
 
 #if defined(_KERNEL_OPT)
@@ -377,9 +377,9 @@ kdebug_sadb_x_policy(const struct sadb_e
 	if (ext == NULL)
 		panic("%s: NULL pointer was passed", __func__);
 
-	printf(" sadb_x_policy { type=%u dir=%u id=%x }",
+	printf(" sadb_x_policy { type=%u dir=%u flags=0x%02x id=%x }",
 		xpl->sadb_x_policy_type, xpl->sadb_x_policy_dir,
-		xpl->sadb_x_policy_id);
+		xpl->sadb_x_policy_flags, 

CVS commit: src/sys

2022-10-11 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Tue Oct 11 09:51:47 UTC 2022

Modified Files:
src/sys/net: if_ipsec.c pfkeyv2.h
src/sys/netipsec: key.c key_debug.c

Log Message:
Add sadb_x_policy_flags to inform SP origination.

This extension(struct sadb_x_policy) is *not* defined by RFC2367.

OpenBSD does not have reserved fields in struct sadb_x_policy.
Linux does not use this field yet.
FreeBSD uses this field as "sadb_x_policy_scope"; the value range is
from 0x00 to 0x04.

We use from most significant bit to avoid the above usage.


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/sys/net/if_ipsec.c src/sys/net/pfkeyv2.h
cvs rdiff -u -r1.276 -r1.277 src/sys/netipsec/key.c
cvs rdiff -u -r1.24 -r1.25 src/sys/netipsec/key_debug.c

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



CVS commit: src/sys/net

2022-10-06 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Oct  6 06:59:25 UTC 2022

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

Log Message:
Fix overflow case detected by clang.  Pointed out by wsh@IIJ, thanks.


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

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

Modified files:

Index: src/sys/net/if_ipsec.c
diff -u src/sys/net/if_ipsec.c:1.32 src/sys/net/if_ipsec.c:1.33
--- src/sys/net/if_ipsec.c:1.32	Fri Sep 30 07:36:36 2022
+++ src/sys/net/if_ipsec.c	Thu Oct  6 06:59:24 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ipsec.c,v 1.32 2022/09/30 07:36:36 knakahara Exp $  */
+/*	$NetBSD: if_ipsec.c,v 1.33 2022/10/06 06:59:24 knakahara Exp $  */
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_ipsec.c,v 1.32 2022/09/30 07:36:36 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ipsec.c,v 1.33 2022/10/06 06:59:24 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1798,12 +1798,12 @@ if_ipsec_get_reqids(struct ipsec_variant
 
 	mutex_enter(_softcs.lock);
 	if (ipsec_softcs.use_fixed_reqid) {
-		u_int16_t reqid_base;
+		uint32_t reqid_base;
 
 		reqid_base = ipsec_softcs.reqid_base + ifp->if_index * 2;
 		if (reqid_base + 1 > ipsec_softcs.reqid_last) {
 			log(LOG_ERR,
-			"%s: invalid fixed reqid(%"PRIu16"), "
+			"%s: invalid fixed reqid(%"PRIu32"), "
 			"current range %"PRIu16" <= reqid <= %"PRIu16"\n",
 			ifp->if_xname, reqid_base + 1,
 			ipsec_softcs.reqid_base, ipsec_softcs.reqid_last);



CVS commit: src/sys/net

2022-10-06 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Oct  6 06:59:25 UTC 2022

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

Log Message:
Fix overflow case detected by clang.  Pointed out by wsh@IIJ, thanks.


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

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



CVS commit: src/sys/net

2022-09-30 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Sep 30 07:36:36 UTC 2022

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

Log Message:
ipsecif(4) can use fixed SP reqid based on ifindex, that can reduce number of 
reqid.

If we want to use fixed SP reqid for ipsecif(4), set
net.ipsecif.use_fixed_reqid=1  Default(=0) is the same as before.
net.ipsecif.use_fixed_reqid can be changed only if there is no ipsecif(4) yet.

If we want to change the range of ipseif(4) SP reqid,
set net.ipsecif.reqid_base and net.ipsecif.reqid_last.
These can also be changed only if there is no ipsecif(4) yet.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/sys/net/if_ipsec.c

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

Modified files:

Index: src/sys/net/if_ipsec.c
diff -u src/sys/net/if_ipsec.c:1.31 src/sys/net/if_ipsec.c:1.32
--- src/sys/net/if_ipsec.c:1.31	Mon Oct 11 05:13:11 2021
+++ src/sys/net/if_ipsec.c	Fri Sep 30 07:36:36 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ipsec.c,v 1.31 2021/10/11 05:13:11 knakahara Exp $  */
+/*	$NetBSD: if_ipsec.c,v 1.32 2022/09/30 07:36:36 knakahara Exp $  */
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_ipsec.c,v 1.31 2021/10/11 05:13:11 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ipsec.c,v 1.32 2022/09/30 07:36:36 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -110,7 +110,7 @@ static inline size_t if_ipsec_set_sadb_d
 struct sockaddr *, int);
 static inline size_t if_ipsec_set_sadb_x_policy(struct sadb_x_policy *,
 struct sadb_x_ipsecrequest *, uint16_t, uint8_t, uint32_t, uint8_t,
-struct sockaddr *, struct sockaddr *);
+struct sockaddr *, struct sockaddr *, uint16_t);
 static inline void if_ipsec_set_sadb_msg(struct sadb_msg *, uint16_t, uint8_t);
 static inline void if_ipsec_set_sadb_msg_add(struct sadb_msg *, uint16_t);
 static inline void if_ipsec_set_sadb_msg_del(struct sadb_msg *, uint16_t);
@@ -118,7 +118,7 @@ static inline void if_ipsec_set_sadb_msg
 static int if_ipsec_share_sp(struct ipsec_variant *);
 static int if_ipsec_unshare_sp(struct ipsec_variant *);
 static inline struct secpolicy *if_ipsec_add_sp0(struct sockaddr *,
-in_port_t, struct sockaddr *, in_port_t, int, int, int, u_int);
+in_port_t, struct sockaddr *, in_port_t, int, int, int, u_int, uint16_t);
 static inline int if_ipsec_del_sp0(struct secpolicy *);
 static int if_ipsec_add_sp(struct ipsec_variant *,
 struct sockaddr *, in_port_t, struct sockaddr *, in_port_t);
@@ -140,8 +140,17 @@ static int if_ipsec_set_addr_port(struct
 /* This list is used in ioctl context only. */
 static struct {
 	LIST_HEAD(ipsec_sclist, ipsec_softc) list;
+	bool use_fixed_reqid;
+#define REQID_BASE_DEFAULT	0x2000
+#define REQID_LAST_DEFAULT	0x2fff
+	u_int16_t reqid_base;
+	u_int16_t reqid_last;
 	kmutex_t lock;
-} ipsec_softcs __cacheline_aligned;
+} ipsec_softcs __cacheline_aligned = {
+	.use_fixed_reqid = false,
+	.reqid_base = REQID_BASE_DEFAULT,
+	.reqid_last = REQID_LAST_DEFAULT,
+};
 
 struct psref_class *iv_psref_class __read_mostly;
 
@@ -153,6 +162,14 @@ static struct sysctllog *if_ipsec_sysctl
 
 static pktq_rps_hash_func_t if_ipsec_pktq_rps_hash_p;
 
+enum {
+	REQID_INDEX_IPV4IN = 0,
+	REQID_INDEX_IPV4OUT,
+	REQID_INDEX_IPV6IN,
+	REQID_INDEX_IPV6OUT,
+	REQID_INDEX_NUM,
+};
+
 #ifdef INET6
 static int
 sysctl_if_ipsec_pmtu_global(SYSCTLFN_ARGS)
@@ -205,6 +222,84 @@ sysctl_if_ipsec_pmtu_perif(SYSCTLFN_ARGS
 }
 #endif
 
+static int
+sysctl_if_ipsec_use_fixed_reqid(SYSCTLFN_ARGS)
+{
+	bool fixed;
+	int error;
+	struct sysctlnode node = *rnode;
+
+	mutex_enter(_softcs.lock);
+	fixed = ipsec_softcs.use_fixed_reqid;
+	node.sysctl_data = 
+	error = sysctl_lookup(SYSCTLFN_CALL());
+	if (error || newp == NULL) {
+		mutex_exit(_softcs.lock);
+		return error;
+	}
+
+	if (!LIST_EMPTY(_softcs.list)) {
+		mutex_exit(_softcs.lock);
+		return EBUSY;
+	}
+	ipsec_softcs.use_fixed_reqid = fixed;
+	mutex_exit(_softcs.lock);
+
+	return 0;
+}
+
+static int
+sysctl_if_ipsec_reqid_base(SYSCTLFN_ARGS)
+{
+	int base;
+	int error;
+	struct sysctlnode node = *rnode;
+
+	mutex_enter(_softcs.lock);
+	base = ipsec_softcs.reqid_base;
+	node.sysctl_data = 
+	error = sysctl_lookup(SYSCTLFN_CALL());
+	if (error || newp == NULL) {
+		mutex_exit(_softcs.lock);
+		return error;
+	}
+
+	if (!LIST_EMPTY(_softcs.list)) {
+		mutex_exit(_softcs.lock);
+		return EBUSY;
+	}
+	ipsec_softcs.reqid_base = base;
+	mutex_exit(_softcs.lock);
+
+	return 0;
+}
+
+static int
+sysctl_if_ipsec_reqid_last(SYSCTLFN_ARGS)
+{
+	int last;
+	int error;
+	struct sysctlnode node = *rnode;
+
+	mutex_enter(_softcs.lock);
+	last = ipsec_softcs.reqid_last;
+	node.sysctl_data = 
+	error = sysctl_lookup(SYSCTLFN_CALL());
+	if (error || newp == NULL) {
+		mutex_exit(_softcs.lock);
+		return error;
+	}
+
+	if (!LIST_EMPTY(_softcs.list)) {
+		

CVS commit: src/sys/net

2022-09-30 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Sep 30 07:36:36 UTC 2022

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

Log Message:
ipsecif(4) can use fixed SP reqid based on ifindex, that can reduce number of 
reqid.

If we want to use fixed SP reqid for ipsecif(4), set
net.ipsecif.use_fixed_reqid=1  Default(=0) is the same as before.
net.ipsecif.use_fixed_reqid can be changed only if there is no ipsecif(4) yet.

If we want to change the range of ipseif(4) SP reqid,
set net.ipsecif.reqid_base and net.ipsecif.reqid_last.
These can also be changed only if there is no ipsecif(4) yet.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/sys/net/if_ipsec.c

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



CVS commit: src/tests/net/route

2022-09-19 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Tue Sep 20 02:25:07 UTC 2022

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

Log Message:
tests: add tests for automatic route deletions on an address removal


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/tests/net/route/t_route.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_route.sh
diff -u src/tests/net/route/t_route.sh:1.14 src/tests/net/route/t_route.sh:1.15
--- src/tests/net/route/t_route.sh:1.14	Mon Dec 18 04:11:46 2017
+++ src/tests/net/route/t_route.sh	Tue Sep 20 02:25:07 2022
@@ -1,4 +1,4 @@
-#	$NetBSD: t_route.sh,v 1.14 2017/12/18 04:11:46 ozaki-r Exp $
+#	$NetBSD: t_route.sh,v 1.15 2022/09/20 02:25:07 knakahara Exp $
 #
 # Copyright (c) 2016 Internet Initiative Japan Inc.
 # All rights reserved.
@@ -539,6 +539,156 @@ route_command_add6_cleanup()
 	cleanup
 }
 
+test_route_address_removal()
+{
+
+	rump_server_start $SOCKHOST netinet6
+
+	export RUMP_SERVER=${SOCKHOST}
+	rump_server_add_iface $SOCKHOST shmif0 $BUS
+
+	#
+	# 1. test auto removal of a route that depends a removing address
+	#
+	atf_check -s exit:0 rump.ifconfig shmif0 $af $addr1/$prefix
+	atf_check -s exit:0 -o match:"add net $alt_net(/$prefix)?: gateway $addrgw" \
+	rump.route -n add -$af -net $alt_net/$prefix $addrgw
+	$DEBUG && rump.netstat -nr -f $af
+	atf_check -s exit:0 rump.ifconfig shmif0 $af $addr1 delete
+	$DEBUG && rump.netstat -nr -f $af
+
+	# The route should be deleted on the address removal
+	atf_check -s not-exit:0 -e match:"writing to routing socket: not in table" \
+	rump.route -n get -$af $alt_addr
+
+	#
+	# 2. test auto update of a route that depends a removing address where
+	#there is another address with the same prefix sharing a connected
+	#route
+	#
+	atf_check -s exit:0 rump.ifconfig shmif0 $af $addr1/$prefix
+	atf_check -s exit:0 rump.ifconfig shmif0 $af $addr2/$prefix alias
+	atf_check -s exit:0 -o match:"add net $alt_net(/$prefix)?: gateway $addrgw" \
+	rump.route -n add -$af -net $alt_net/$prefix $addrgw
+	$DEBUG && rump.netstat -nr -f $af
+
+	atf_check -s exit:0 -o match:"local addr: $addr1" \
+	rump.route -n get -$af $addrgw
+	atf_check -s exit:0 -o match:"local addr: $addr1" \
+	rump.route -n get -$af $alt_addr
+
+	atf_check -s exit:0 rump.ifconfig shmif0 $af $addr1 delete
+	$DEBUG && rump.netstat -nr -f $af
+
+	# local addr (rt_ifa) of the connected route should be changed
+	# on the address removal
+	atf_check -s exit:0 -o match:"local addr: $addr2" \
+	rump.route -n get -$af $addrgw
+	# local addr (rt_ifa) of the related route should be changed
+	# on the address removal too
+	atf_check -s exit:0 -o match:"local addr: $addr2" \
+	rump.route -n get -$af $alt_addr
+
+	# cleanup
+	atf_check -s exit:0 rump.ifconfig shmif0 $af $addr2 delete
+
+	#
+	# 3. test auto update of a route that depends a removing address where
+	#there is another address with a different (short) prefix
+	#
+	atf_check -s exit:0 rump.ifconfig shmif0 $af $addr1/$prefix
+	atf_check -s exit:0 rump.ifconfig shmif0 $af $addr2/$prefix_short alias
+	atf_check -s exit:0 -o match:"add net $alt_net(/$prefix)?: gateway $addrgw" \
+	rump.route -n add -$af -net $alt_net/$prefix $addrgw
+	$DEBUG && rump.netstat -nr -f $af
+
+	atf_check -s exit:0 -o match:"local addr: $addr1" \
+	rump.route -n get -$af $addrgw
+	atf_check -s exit:0 -o match:"local addr: $addr1" \
+	rump.route -n get -$af $alt_addr
+
+	atf_check -s exit:0 rump.ifconfig shmif0 $af $addr1 delete
+	$DEBUG && rump.netstat -nr -f $af
+
+	# local addr (rt_ifa) of the connected route should be changed
+	# on the address removal
+	atf_check -s exit:0 -o match:"local addr: $addr2" \
+	rump.route -n get -$af $addrgw
+	if [ $af = inet ]; then
+		# local addr (rt_ifa) of the related route should be changed
+		# on the address removal too
+		atf_check -s exit:0 -o match:"local addr: $addr2" \
+		rump.route -n get -$af $alt_addr
+	else
+		# For IPv6, each address has its own connected route so the
+		# address removal just results in a removal of the related route
+		atf_check -s not-exit:0 \
+		-e match:"writing to routing socket: not in table" \
+		rump.route -n get -$af $alt_addr
+	fi
+
+	rump_server_destroy_ifaces
+}
+
+atf_test_case route_address_removal cleanup
+route_address_removal_head()
+{
+
+	atf_set "descr" "tests of auto removal/update of routes on address removal (IPv4)"
+	atf_set "require.progs" "rump_server"
+}
+
+route_address_removal_body()
+{
+	local addr1=10.0.0.1
+	local addr2=10.0.0.2
+	local addrgw=10.0.0.3
+	local prefix=24
+	local prefix_short=16
+	local alt_net=10.0.1.0
+	local alt_addr=10.0.1.1
+	local af=inet
+
+	test_route_address_removal
+}
+
+route_address_removal_cleanup()
+{
+
+	$DEBUG && dump
+	cleanup
+}
+
+atf_test_case route_address_removal6 cleanup
+route_address_removal6_head()

CVS commit: src/tests/net/route

2022-09-19 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Tue Sep 20 02:25:07 UTC 2022

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

Log Message:
tests: add tests for automatic route deletions on an address removal


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

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



CVS commit: src/sys/sys

2022-09-19 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Tue Sep 20 02:24:18 UTC 2022

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

Log Message:
Welcome to 9.99.100

- changed the prototype of rt_replace_ifa_matched_entries()

See also the follwoing thread
https://mail-index.netbsd.org/tech-kern/2022/09/15/msg028385.html
Advised by kre@n.o, pgoyette@n.o, gutteridge@n.o and dholland@n.o, thanks.


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

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



CVS commit: src/sys/sys

2022-09-19 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Tue Sep 20 02:24:18 UTC 2022

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

Log Message:
Welcome to 9.99.100

- changed the prototype of rt_replace_ifa_matched_entries()

See also the follwoing thread
https://mail-index.netbsd.org/tech-kern/2022/09/15/msg028385.html
Advised by kre@n.o, pgoyette@n.o, gutteridge@n.o and dholland@n.o, thanks.


To generate a diff of this commit:
cvs rdiff -u -r1.712 -r1.713 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.712 src/sys/sys/param.h:1.713
--- src/sys/sys/param.h:1.712	Mon Jul 18 04:30:30 2022
+++ src/sys/sys/param.h	Tue Sep 20 02:24:18 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: param.h,v 1.712 2022/07/18 04:30:30 thorpej Exp $	*/
+/*	$NetBSD: param.h,v 1.713 2022/09/20 02:24:18 knakahara Exp $	*/
 
 /*-
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -55,7 +55,7 @@
  *
  *	M = major version
  *	m = minor version; a minor number of 99 indicates current.
- *	r = 0 (*)
+ *	r = 0 (*) or patchlevel in 9.99
  *	p = patchlevel
  *
  * When new releases are made, src/gnu/usr.bin/groff/tmac/mdoc.local
@@ -67,7 +67,7 @@
  *	2.99.9		(299000900)
  */
 
-#define	__NetBSD_Version__	999009900	/* NetBSD 9.99.99 */
+#define	__NetBSD_Version__	99901	/* NetBSD 9.99.100 */
 
 #define __NetBSD_Prereq__(M,m,p) (M) * 1) + \
 (m) * 100) + (p) * 100) <= __NetBSD_Version__)



CVS commit: src/sys

2022-09-19 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Tue Sep 20 02:23:38 UTC 2022

Modified Files:
src/sys/net: if.c route.c route.h
src/sys/netinet: in.c
src/sys/netinet6: in6.c
src/sys/nfs: nfs_boot.c

Log Message:
Remove routes on an address removal if the routes referencing to the address.  
Implemented by ozaki-r@n.o.

A route that has a gateway is on a connected route can be invalid if the
connected route is deleted, i.e., an associated address is removed.
Traditionally NetBSD doesn't sweep such a route on the address removal.  Sending
packets over the route fails with "No route to host".  Also the route holds an
orphan ifaddr as rt_ifa that is destructed say by in_purgeaddr.

If the same address is assgined again in such a state, there can be two
different ifaddr objects with the same address.  Until recently it's not a
big problem because we can send packets anyway.  However after MP-ification
of the network stack, we can't send packets because we strictly check if rt_ifa
(i.e., the (old) ifaddr) is valid.

This change automatically removes such routes on a removal of an associated
address to avoid keeping inconsistent routes.


To generate a diff of this commit:
cvs rdiff -u -r1.525 -r1.526 src/sys/net/if.c
cvs rdiff -u -r1.233 -r1.234 src/sys/net/route.c
cvs rdiff -u -r1.131 -r1.132 src/sys/net/route.h
cvs rdiff -u -r1.242 -r1.243 src/sys/netinet/in.c
cvs rdiff -u -r1.285 -r1.286 src/sys/netinet6/in6.c
cvs rdiff -u -r1.88 -r1.89 src/sys/nfs/nfs_boot.c

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.525 src/sys/net/if.c:1.526
--- src/sys/net/if.c:1.525	Sat Sep  3 02:53:18 2022
+++ src/sys/net/if.c	Tue Sep 20 02:23:37 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.525 2022/09/03 02:53:18 thorpej Exp $	*/
+/*	$NetBSD: if.c,v 1.526 2022/09/20 02:23:37 knakahara Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc.
@@ -90,7 +90,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.525 2022/09/03 02:53:18 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.526 2022/09/20 02:23:37 knakahara Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -1479,7 +1479,7 @@ restart:
 
 	/* Delete stray routes from the routing table. */
 	for (i = 0; i <= AF_MAX; i++)
-		rt_delete_matched_entries(i, if_delroute_matcher, ifp);
+		rt_delete_matched_entries(i, if_delroute_matcher, ifp, false);
 
 	DOMAIN_FOREACH(dp) {
 		if (dp->dom_ifdetach != NULL && ifp->if_afdata[dp->dom_family])

Index: src/sys/net/route.c
diff -u src/sys/net/route.c:1.233 src/sys/net/route.c:1.234
--- src/sys/net/route.c:1.233	Mon Aug 29 23:48:18 2022
+++ src/sys/net/route.c	Tue Sep 20 02:23:37 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: route.c,v 1.233 2022/08/29 23:48:18 knakahara Exp $	*/
+/*	$NetBSD: route.c,v 1.234 2022/09/20 02:23:37 knakahara Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -97,7 +97,7 @@
 #endif
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.233 2022/08/29 23:48:18 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.234 2022/09/20 02:23:37 knakahara Exp $");
 
 #include 
 #ifdef RTFLUSH_DEBUG
@@ -2291,7 +2291,7 @@ rt_check_reject_route(const struct rtent
 
 void
 rt_delete_matched_entries(sa_family_t family, int (*f)(struct rtentry *, void *),
-void *v)
+void *v, bool notify)
 {
 
 	for (;;) {
@@ -2308,6 +2308,7 @@ rt_delete_matched_entries(sa_family_t fa
 			return;
 		}
 		rt_ref(rt);
+		RT_REFCNT_TRACE(rt);
 		splx(s);
 		RT_UNLOCK();
 
@@ -2316,12 +2317,16 @@ rt_delete_matched_entries(sa_family_t fa
 		if (error == 0) {
 			KASSERT(retrt == rt);
 			KASSERT((retrt->rt_flags & RTF_UP) == 0);
+			if (notify)
+rt_newmsg(RTM_DELETE, retrt);
 			retrt->rt_ifp = NULL;
 			rt_unref(rt);
+			RT_REFCNT_TRACE(rt);
 			rt_free(retrt);
 		} else if (error == ESRCH) {
 			/* Someone deleted the entry already. */
 			rt_unref(rt);
+			RT_REFCNT_TRACE(rt);
 		} else {
 			log(LOG_ERR, "%s: unable to delete rtentry @ %p, "
 			"error = %d\n", rt->rt_ifp->if_xname, rt, error);
@@ -2338,6 +2343,53 @@ rt_walktree_locked(sa_family_t family, i
 	return rtbl_walktree(family, f, v);
 }
 
+void
+rt_replace_ifa_matched_entries(sa_family_t family,
+int (*f)(struct rtentry *, void *), void *v, struct ifaddr *ifa)
+{
+
+	for (;;) {
+		int s;
+#ifdef NET_MPSAFE
+		int error;
+#endif
+		struct rtentry *rt;
+
+		RT_RLOCK();
+		s = splsoftnet();
+		rt = rtbl_search_matched_entry(family, f, v);
+		if (rt == NULL) {
+			splx(s);
+			RT_UNLOCK();
+			return;
+		}
+		rt_ref(rt);
+		RT_REFCNT_TRACE(rt);
+		splx(s);
+		RT_UNLOCK();
+
+#ifdef NET_MPSAFE
+		error = rt_update_prepare(rt);
+		if (error == 0) {
+			rt_replace_ifa(rt, ifa);
+			rt_update_finish(rt);
+			rt_newmsg(RTM_CHANGE, rt);
+		} else {
+			/*
+			 * If error != 0, the rtentry is being
+			 * destroyed, so doing nothing 

CVS commit: src/sys

2022-09-19 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Tue Sep 20 02:23:38 UTC 2022

Modified Files:
src/sys/net: if.c route.c route.h
src/sys/netinet: in.c
src/sys/netinet6: in6.c
src/sys/nfs: nfs_boot.c

Log Message:
Remove routes on an address removal if the routes referencing to the address.  
Implemented by ozaki-r@n.o.

A route that has a gateway is on a connected route can be invalid if the
connected route is deleted, i.e., an associated address is removed.
Traditionally NetBSD doesn't sweep such a route on the address removal.  Sending
packets over the route fails with "No route to host".  Also the route holds an
orphan ifaddr as rt_ifa that is destructed say by in_purgeaddr.

If the same address is assgined again in such a state, there can be two
different ifaddr objects with the same address.  Until recently it's not a
big problem because we can send packets anyway.  However after MP-ification
of the network stack, we can't send packets because we strictly check if rt_ifa
(i.e., the (old) ifaddr) is valid.

This change automatically removes such routes on a removal of an associated
address to avoid keeping inconsistent routes.


To generate a diff of this commit:
cvs rdiff -u -r1.525 -r1.526 src/sys/net/if.c
cvs rdiff -u -r1.233 -r1.234 src/sys/net/route.c
cvs rdiff -u -r1.131 -r1.132 src/sys/net/route.h
cvs rdiff -u -r1.242 -r1.243 src/sys/netinet/in.c
cvs rdiff -u -r1.285 -r1.286 src/sys/netinet6/in6.c
cvs rdiff -u -r1.88 -r1.89 src/sys/nfs/nfs_boot.c

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



CVS commit: src/sys/dev/pci

2022-09-16 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Sep 16 07:55:34 UTC 2022

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

Log Message:
It is correct to update ifp statistics per packet, just remove commented out 
old statistics code.

The code is commented out by if_vmx.c:r1.57.


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

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



CVS commit: src/sys/dev/pci

2022-09-16 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Sep 16 07:55:34 UTC 2022

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

Log Message:
It is correct to update ifp statistics per packet, just remove commented out 
old statistics code.

The code is commented out by if_vmx.c:r1.57.


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

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

Modified files:

Index: src/sys/dev/pci/if_vmx.c
diff -u src/sys/dev/pci/if_vmx.c:1.10 src/sys/dev/pci/if_vmx.c:1.11
--- src/sys/dev/pci/if_vmx.c:1.10	Fri Sep 16 03:10:12 2022
+++ src/sys/dev/pci/if_vmx.c	Fri Sep 16 07:55:34 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vmx.c,v 1.10 2022/09/16 03:10:12 knakahara Exp $	*/
+/*	$NetBSD: if_vmx.c,v 1.11 2022/09/16 07:55:34 knakahara Exp $	*/
 /*	$OpenBSD: if_vmx.c,v 1.16 2014/01/22 06:04:17 brad Exp $	*/
 
 /*
@@ -19,7 +19,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.10 2022/09/16 03:10:12 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.11 2022/09/16 07:55:34 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_if_vmx.h"
@@ -185,11 +185,6 @@ struct vmxnet3_comp_ring {
 };
 
 struct vmxnet3_txq_stats {
-#if 0
-	uint64_t vmtxs_opackets;	/* if_opackets */
-	uint64_t vmtxs_obytes;		/* if_obytes */
-	uint64_t vmtxs_omcasts;		/* if_omcasts */
-#endif
 	uint64_t vmtxs_csum;
 	uint64_t vmtxs_tso;
 	uint64_t vmtxs_full;
@@ -219,14 +214,6 @@ struct vmxnet3_txqueue {
 	struct evcnt vxtxq_defrag_failed;
 };
 
-#if 0
-struct vmxnet3_rxq_stats {
-	uint64_t vmrxs_ipackets;	/* if_ipackets */
-	uint64_t vmrxs_ibytes;		/* if_ibytes */
-	uint64_t vmrxs_iqdrops;		/* if_iqdrops */
-	uint64_t vmrxs_ierrors;		/* if_ierrors */
-};
-#endif
 
 struct vmxnet3_rxqueue {
 	kmutex_t *vxrxq_mtx;
@@ -235,9 +222,6 @@ struct vmxnet3_rxqueue {
 	struct mbuf *vxrxq_mtail;
 	struct vmxnet3_rxring vxrxq_cmd_ring[VMXNET3_RXRINGS_PERQ];
 	struct vmxnet3_comp_ring vxrxq_comp_ring;
-#if 0
-	struct vmxnet3_rxq_stats vxrxq_stats;
-#endif
 	struct vmxnet3_rxq_shared *vxrxq_rs;
 	char vxrxq_name[16];
 



CVS commit: src/sys/dev/pci

2022-09-15 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Sep 16 03:12:03 UTC 2022

Modified Files:
src/sys/dev/pci: files.pci if_ixl.c

Log Message:
Add ALWAYS_TXDEFER option to ixl(4), too.


To generate a diff of this commit:
cvs rdiff -u -r1.443 -r1.444 src/sys/dev/pci/files.pci
cvs rdiff -u -r1.87 -r1.88 src/sys/dev/pci/if_ixl.c

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

Modified files:

Index: src/sys/dev/pci/files.pci
diff -u src/sys/dev/pci/files.pci:1.443 src/sys/dev/pci/files.pci:1.444
--- src/sys/dev/pci/files.pci:1.443	Fri Sep 16 03:10:12 2022
+++ src/sys/dev/pci/files.pci	Fri Sep 16 03:12:03 2022
@@ -1,4 +1,4 @@
-#	$NetBSD: files.pci,v 1.443 2022/09/16 03:10:12 knakahara Exp $
+#	$NetBSD: files.pci,v 1.444 2022/09/16 03:12:03 knakahara Exp $
 #
 # Config file and device description for machine-independent PCI code.
 # Included by ports that need it.  Requires that the SCSI files be
@@ -1166,7 +1166,7 @@ file	dev/pci/qat/qat_d15xx.c		qat
 device	ixl: ether, ifnet, arp
 attach	ixl at pci
 file	dev/pci/if_ixl.c	ixl
-defflag	opt_if_ixl.h	IXL_DEBUG
+defflag	opt_if_ixl.h	IXL_DEBUG IXL_ALWAYS_TXDEFER
 defparam opt_if_ixl.h	IXL_STATS_INTERVAL_MSEC
 			IXL_QUEUE_NUM
 

Index: src/sys/dev/pci/if_ixl.c
diff -u src/sys/dev/pci/if_ixl.c:1.87 src/sys/dev/pci/if_ixl.c:1.88
--- src/sys/dev/pci/if_ixl.c:1.87	Sun Aug 28 07:54:03 2022
+++ src/sys/dev/pci/if_ixl.c	Fri Sep 16 03:12:03 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ixl.c,v 1.87 2022/08/28 07:54:03 skrll Exp $	*/
+/*	$NetBSD: if_ixl.c,v 1.88 2022/09/16 03:12:03 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2013-2015, Intel Corporation
@@ -74,7 +74,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_ixl.c,v 1.87 2022/08/28 07:54:03 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ixl.c,v 1.88 2022/09/16 03:12:03 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -2883,6 +2883,11 @@ ixl_transmit(struct ifnet *ifp, struct m
 		return ENOBUFS;
 	}
 
+#ifdef IXL_ALWAYS_TXDEFER
+	kpreempt_disable();
+	softint_schedule(txr->txr_si);
+	kpreempt_enable();
+#else
 	if (mutex_tryenter(>txr_lock)) {
 		ixl_tx_common_locked(ifp, txr, true);
 		mutex_exit(>txr_lock);
@@ -2891,6 +2896,7 @@ ixl_transmit(struct ifnet *ifp, struct m
 		softint_schedule(txr->txr_si);
 		kpreempt_enable();
 	}
+#endif
 
 	return 0;
 }



CVS commit: src/sys/dev/pci

2022-09-15 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Sep 16 03:12:03 UTC 2022

Modified Files:
src/sys/dev/pci: files.pci if_ixl.c

Log Message:
Add ALWAYS_TXDEFER option to ixl(4), too.


To generate a diff of this commit:
cvs rdiff -u -r1.443 -r1.444 src/sys/dev/pci/files.pci
cvs rdiff -u -r1.87 -r1.88 src/sys/dev/pci/if_ixl.c

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



CVS commit: src/sys/dev/pci

2022-09-15 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Sep 16 03:10:12 UTC 2022

Modified Files:
src/sys/dev/pci: files.pci if_vmx.c

Log Message:
Add ALWAYS_TXDEFER option to vmx(4), too.


To generate a diff of this commit:
cvs rdiff -u -r1.442 -r1.443 src/sys/dev/pci/files.pci
cvs rdiff -u -r1.9 -r1.10 src/sys/dev/pci/if_vmx.c

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

Modified files:

Index: src/sys/dev/pci/files.pci
diff -u src/sys/dev/pci/files.pci:1.442 src/sys/dev/pci/files.pci:1.443
--- src/sys/dev/pci/files.pci:1.442	Fri Sep 16 03:05:51 2022
+++ src/sys/dev/pci/files.pci	Fri Sep 16 03:10:12 2022
@@ -1,4 +1,4 @@
-#	$NetBSD: files.pci,v 1.442 2022/09/16 03:05:51 knakahara Exp $
+#	$NetBSD: files.pci,v 1.443 2022/09/16 03:10:12 knakahara Exp $
 #
 # Config file and device description for machine-independent PCI code.
 # Included by ports that need it.  Requires that the SCSI files be
@@ -1186,6 +1186,7 @@ filedev/pci/xmm7360.c   
 device	vmx: ether, ifnet, arp
 attach	vmx at pci
 file	dev/pci/if_vmx.c	vmx
+defflag	opt_if_vmx.h	VMXNET3_ALWAYS_TXDEFER
 
 # Realtek RTL8125 2.5GBASE-T Ethernet
 device	rge: ether, ifnet, arp, mii

Index: src/sys/dev/pci/if_vmx.c
diff -u src/sys/dev/pci/if_vmx.c:1.9 src/sys/dev/pci/if_vmx.c:1.10
--- src/sys/dev/pci/if_vmx.c:1.9	Wed Jul  6 06:32:50 2022
+++ src/sys/dev/pci/if_vmx.c	Fri Sep 16 03:10:12 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vmx.c,v 1.9 2022/07/06 06:32:50 msaitoh Exp $	*/
+/*	$NetBSD: if_vmx.c,v 1.10 2022/09/16 03:10:12 knakahara Exp $	*/
 /*	$OpenBSD: if_vmx.c,v 1.16 2014/01/22 06:04:17 brad Exp $	*/
 
 /*
@@ -19,7 +19,11 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.9 2022/07/06 06:32:50 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vmx.c,v 1.10 2022/09/16 03:10:12 knakahara Exp $");
+
+#ifdef _KERNEL_OPT
+#include "opt_if_vmx.h"
+#endif
 
 #include 
 #include 
@@ -3286,6 +3290,11 @@ vmxnet3_transmit(struct ifnet *ifp, stru
 		return ENOBUFS;
 	}
 
+#ifdef VMXNET3_ALWAYS_TXDEFER
+	kpreempt_disable();
+	softint_schedule(txq->vxtxq_si);
+	kpreempt_enable();
+#else
 	if (VMXNET3_TXQ_TRYLOCK(txq)) {
 		vmxnet3_transmit_locked(ifp, txq);
 		VMXNET3_TXQ_UNLOCK(txq);
@@ -3294,6 +3303,7 @@ vmxnet3_transmit(struct ifnet *ifp, stru
 		softint_schedule(txq->vxtxq_si);
 		kpreempt_enable();
 	}
+#endif
 
 	return 0;
 }



CVS commit: src/sys/dev/pci

2022-09-15 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Sep 16 03:10:12 UTC 2022

Modified Files:
src/sys/dev/pci: files.pci if_vmx.c

Log Message:
Add ALWAYS_TXDEFER option to vmx(4), too.


To generate a diff of this commit:
cvs rdiff -u -r1.442 -r1.443 src/sys/dev/pci/files.pci
cvs rdiff -u -r1.9 -r1.10 src/sys/dev/pci/if_vmx.c

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



CVS commit: src/sys/dev/pci

2022-09-15 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Sep 16 03:05:52 UTC 2022

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

Log Message:
ixg(4) add an option for Tx to use deferred softint regardless of whether can 
get txq lock or not.

That imporve (7%) and stabilize throughput.  But that can cause
latency degradation, so off by default.

ok'ed by msaitoh@n.o.


To generate a diff of this commit:
cvs rdiff -u -r1.441 -r1.442 src/sys/dev/pci/files.pci
cvs rdiff -u -r1.99 -r1.100 src/sys/dev/pci/ixgbe/ix_txrx.c
cvs rdiff -u -r1.16 -r1.17 src/sys/dev/pci/ixgbe/ixgbe_netbsd.h

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

Modified files:

Index: src/sys/dev/pci/files.pci
diff -u src/sys/dev/pci/files.pci:1.441 src/sys/dev/pci/files.pci:1.442
--- src/sys/dev/pci/files.pci:1.441	Wed Sep  7 06:37:04 2022
+++ src/sys/dev/pci/files.pci	Fri Sep 16 03:05:51 2022
@@ -1,4 +1,4 @@
-#	$NetBSD: files.pci,v 1.441 2022/09/07 06:37:04 martin Exp $
+#	$NetBSD: files.pci,v 1.442 2022/09/16 03:05:51 knakahara Exp $
 #
 # Config file and device description for machine-independent PCI code.
 # Included by ports that need it.  Requires that the SCSI files be
@@ -665,6 +665,7 @@ file	dev/pci/ixgbe/ixgbe_phy.c	ixg | ixv
 file	dev/pci/ixgbe/ixgbe_vf.c	ixg | ixv
 file	dev/pci/ixgbe/if_bypass.c	ixg | ixv
 file	dev/pci/ixgbe/if_fdir.c		ixg | ixv
+defflag	opt_if_ixg.h	IXGBE_ALWAYS_TXDEFER
 
 # This appears to be the driver for virtual instances of i82599.
 device	ixv: ether, ifnet, arp, mii, mii_phy

Index: src/sys/dev/pci/ixgbe/ix_txrx.c
diff -u src/sys/dev/pci/ixgbe/ix_txrx.c:1.99 src/sys/dev/pci/ixgbe/ix_txrx.c:1.100
--- src/sys/dev/pci/ixgbe/ix_txrx.c:1.99	Sun Aug  7 09:37:47 2022
+++ src/sys/dev/pci/ixgbe/ix_txrx.c	Fri Sep 16 03:05:51 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: ix_txrx.c,v 1.99 2022/08/07 09:37:47 andvar Exp $ */
+/* $NetBSD: ix_txrx.c,v 1.100 2022/09/16 03:05:51 knakahara Exp $ */
 
 /**
 
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ix_txrx.c,v 1.99 2022/08/07 09:37:47 andvar Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ix_txrx.c,v 1.100 2022/09/16 03:05:51 knakahara Exp $");
 
 #include "opt_inet.h"
 #include "opt_inet6.h"
@@ -250,6 +250,11 @@ ixgbe_mq_start(struct ifnet *ifp, struct
 		IXGBE_EVC_ADD(>pcq_drops, 1);
 		return ENOBUFS;
 	}
+#ifdef IXGBE_ALWAYS_TXDEFER
+	kpreempt_disable();
+	softint_schedule(txr->txr_si);
+	kpreempt_enable();
+#else
 	if (IXGBE_TX_TRYLOCK(txr)) {
 		ixgbe_mq_start_locked(ifp, txr);
 		IXGBE_TX_UNLOCK(txr);
@@ -279,6 +284,7 @@ ixgbe_mq_start(struct ifnet *ifp, struct
 			kpreempt_enable();
 		}
 	}
+#endif
 
 	return (0);
 } /* ixgbe_mq_start */

Index: src/sys/dev/pci/ixgbe/ixgbe_netbsd.h
diff -u src/sys/dev/pci/ixgbe/ixgbe_netbsd.h:1.16 src/sys/dev/pci/ixgbe/ixgbe_netbsd.h:1.17
--- src/sys/dev/pci/ixgbe/ixgbe_netbsd.h:1.16	Tue Jan 25 03:40:29 2022
+++ src/sys/dev/pci/ixgbe/ixgbe_netbsd.h	Fri Sep 16 03:05:51 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe_netbsd.h,v 1.16 2022/01/25 03:40:29 msaitoh Exp $ */
+/* $NetBSD: ixgbe_netbsd.h,v 1.17 2022/09/16 03:05:51 knakahara Exp $ */
 /*
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -31,6 +31,10 @@
 #ifndef _IXGBE_NETBSD_H
 #define _IXGBE_NETBSD_H
 
+#ifdef _KERNEL_OPT
+#include "opt_if_ixg.h"
+#endif
+
 #if 0 /* Enable this if you don't want to use TX multiqueue function */
 #define	IXGBE_LEGACY_TX	1
 #endif



CVS commit: src/sys/dev/pci

2022-09-15 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Sep 16 03:05:52 UTC 2022

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

Log Message:
ixg(4) add an option for Tx to use deferred softint regardless of whether can 
get txq lock or not.

That imporve (7%) and stabilize throughput.  But that can cause
latency degradation, so off by default.

ok'ed by msaitoh@n.o.


To generate a diff of this commit:
cvs rdiff -u -r1.441 -r1.442 src/sys/dev/pci/files.pci
cvs rdiff -u -r1.99 -r1.100 src/sys/dev/pci/ixgbe/ix_txrx.c
cvs rdiff -u -r1.16 -r1.17 src/sys/dev/pci/ixgbe/ixgbe_netbsd.h

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



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

2022-09-12 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Tue Sep 13 05:36:29 UTC 2022

Modified Files:
src/sys/arch/amd64/amd64: lock_stubs.S

Log Message:
Fix PR kern/57007.  I missed applying a part of the original patch.


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/sys/arch/amd64/amd64/lock_stubs.S

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

Modified files:

Index: src/sys/arch/amd64/amd64/lock_stubs.S
diff -u src/sys/arch/amd64/amd64/lock_stubs.S:1.37 src/sys/arch/amd64/amd64/lock_stubs.S:1.38
--- src/sys/arch/amd64/amd64/lock_stubs.S:1.37	Wed Sep  7 00:40:18 2022
+++ src/sys/arch/amd64/amd64/lock_stubs.S	Tue Sep 13 05:36:29 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: lock_stubs.S,v 1.37 2022/09/07 00:40:18 knakahara Exp $	*/
+/*	$NetBSD: lock_stubs.S,v 1.38 2022/09/13 05:36:29 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2006, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -124,13 +124,13 @@ ENTRY(mutex_spin_exit)
 	movl	CPU_INFO_MTX_OLDSPL(%r8), %edi
 	incl	CPU_INFO_MTX_COUNT(%r8)
 	jnz	1f
-	cmpl	CPU_INFO_ILEVEL(%r8), %edi
+	cmpb	CPU_INFO_ILEVEL(%r8), %dil
 	jae	1f
-	movl	CPU_INFO_IUNMASK(%r8,%rdi,4), %esi
+	movq	CPU_INFO_IUNMASK(%r8,%rdi,8), %rsi
 	CLI(ax)
-	testl	CPU_INFO_IPENDING(%r8), %esi
+	testq	CPU_INFO_IPENDING(%r8), %rsi
 	jnz	_C_LABEL(Xspllower)
-	movl	%edi, CPU_INFO_ILEVEL(%r8)
+	movb	%dil, CPU_INFO_ILEVEL(%r8)
 	STI(ax)
 1:	rep	/* double byte ret as branch */
 	ret	/* target: see AMD docs */
@@ -141,23 +141,27 @@ ENTRY(mutex_spin_exit)
 	movb	$0x00, MTX_LOCK(%rdi)
 	movl	CPU_INFO_MTX_OLDSPL(%rsi), %ecx
 	incl	CPU_INFO_MTX_COUNT(%rsi)
-	movl	CPU_INFO_ILEVEL(%rsi),%edx
+	movzbl	CPU_INFO_ILEVEL(%rsi),%edx
 	cmovnzl	%edx,%ecx
-	pushq	%rbx
 	cmpl	%edx,%ecx			/* new level is lower? */
 	jae	2f
+	xorq	%rdi,%rdi			/* rdi: ci_ipending mask */
+	notq	%rdi
+	shrq	$8,%rdi
+	movq	%rcx,%r9			/* r9: shifted new level */
+	shlq	$56,%r9
 1:
-	movl	CPU_INFO_IPENDING(%rsi),%eax
-	testl	%eax,CPU_INFO_IUNMASK(%rsi,%rcx,4)/* deferred interrupts? */
+	movq	CPU_INFO_IPENDING(%rsi),%rax
+	testq	%rax,CPU_INFO_IUNMASK(%rsi,%rcx,8)/* deferred interrupts? */
 	jnz	3f
-	movl	%eax,%ebx
-	cmpxchg8b CPU_INFO_ISTATE(%rsi)		/* swap in new ilevel */
+	movq	%rax,%r8
+	andq	%rdi,%r8
+	orq	%r9,%r8
+	cmpxchgq %r8,CPU_INFO_ISTATE(%rsi)	/* swap in new ilevel */
 	jnz	4f
 2:
-	popq	%rbx
 	ret
 3:
-	popq	%rbx
 	movl	%ecx, %edi
 	jmp	_C_LABEL(Xspllower)
 4:



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

2022-09-12 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Tue Sep 13 05:36:29 UTC 2022

Modified Files:
src/sys/arch/amd64/amd64: lock_stubs.S

Log Message:
Fix PR kern/57007.  I missed applying a part of the original patch.


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/sys/arch/amd64/amd64/lock_stubs.S

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



CVS commit: src/sys/dev/pci

2022-09-12 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Sep 12 07:26:04 UTC 2022

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

Log Message:
Uniform vioif's link status to if_link_state.  Implemented by yamaguchi@n.o.

Let vioif(4) know LINK_STATE_UNKNOWN.


To generate a diff of this commit:
cvs rdiff -u -r1.81 -r1.82 src/sys/dev/pci/if_vioif.c

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



CVS commit: src/sys/dev/pci

2022-09-12 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Sep 12 07:26:04 UTC 2022

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

Log Message:
Uniform vioif's link status to if_link_state.  Implemented by yamaguchi@n.o.

Let vioif(4) know LINK_STATE_UNKNOWN.


To generate a diff of this commit:
cvs rdiff -u -r1.81 -r1.82 src/sys/dev/pci/if_vioif.c

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

Modified files:

Index: src/sys/dev/pci/if_vioif.c
diff -u src/sys/dev/pci/if_vioif.c:1.81 src/sys/dev/pci/if_vioif.c:1.82
--- src/sys/dev/pci/if_vioif.c:1.81	Wed May  4 02:38:27 2022
+++ src/sys/dev/pci/if_vioif.c	Mon Sep 12 07:26:04 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vioif.c,v 1.81 2022/05/04 02:38:27 simonb Exp $	*/
+/*	$NetBSD: if_vioif.c,v 1.82 2022/09/12 07:26:04 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_vioif.c,v 1.81 2022/05/04 02:38:27 simonb Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vioif.c,v 1.82 2022/09/12 07:26:04 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -319,7 +319,7 @@ struct vioif_softc {
 
 	uint8_t			sc_mac[ETHER_ADDR_LEN];
 	struct ethercom		sc_ethercom;
-	bool			sc_link_active;
+	int			sc_link_state;
 
 	struct vioif_txqueue	*sc_txq;
 	struct vioif_rxqueue	*sc_rxq;
@@ -349,6 +349,8 @@ struct vioif_softc {
 #define VIOIF_RX_PROCESS_LIMIT		256
 
 #define VIOIF_WORKQUEUE_PRI		PRI_SOFTNET
+#define VIOIF_IS_LINK_ACTIVE(_sc)	((_sc)->sc_link_state == LINK_STATE_UP ? \
+	true : false)
 
 /* cfattach interface functions */
 static int	vioif_match(device_t, cfdata_t, void *);
@@ -401,7 +403,7 @@ static void	vioif_work_add(struct workqu
 static void	vioif_work_wait(struct workqueue *, struct vioif_work *);
 
 /* other control */
-static bool	vioif_is_link_up(struct vioif_softc *);
+static int	vioif_get_link_status(struct vioif_softc *);
 static void	vioif_update_link_status(struct vioif_softc *);
 static int	vioif_ctrl_rx(struct vioif_softc *, int, bool);
 static int	vioif_set_promisc(struct vioif_softc *, bool);
@@ -830,7 +832,7 @@ vioif_attach(device_t parent, device_t s
 
 	sc->sc_dev = self;
 	sc->sc_virtio = vsc;
-	sc->sc_link_active = false;
+	sc->sc_link_state = LINK_STATE_UNKNOWN;
 
 	sc->sc_max_nvq_pairs = 1;
 	sc->sc_req_nvq_pairs = 1;
@@ -983,7 +985,7 @@ vioif_attach(device_t parent, device_t s
 		nvqs++;
 		txq->txq_vq->vq_intrhand = vioif_tx_intr;
 		txq->txq_vq->vq_intrhand_arg = (void *)txq;
-		txq->txq_link_active = sc->sc_link_active;
+		txq->txq_link_active = VIOIF_IS_LINK_ACTIVE(sc);
 		txq->txq_stopping = false;
 		txq->txq_intrq = pcq_create(txq->txq_vq->vq_num, KM_SLEEP);
 		vioif_work_set(>txq_work, vioif_tx_handle, txq);
@@ -1257,14 +1259,11 @@ vioif_stop(struct ifnet *ifp, int disabl
 	}
 
 	ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
-	sc->sc_link_active = false;
 
 	for (i = 0; i < sc->sc_act_nvq_pairs; i++) {
 		txq = >sc_txq[i];
 		rxq = >sc_rxq[i];
 
-		txq->txq_link_active = false;
-
 		if (disable)
 			vioif_rx_drain(rxq);
 
@@ -2393,8 +2392,8 @@ set_ifflags:
 	return r;
 }
 
-static bool
-vioif_is_link_up(struct vioif_softc *sc)
+static int
+vioif_get_link_status(struct vioif_softc *sc)
 {
 	struct virtio_softc *vsc = sc->sc_virtio;
 	uint16_t status;
@@ -2405,7 +2404,10 @@ vioif_is_link_up(struct vioif_softc *sc)
 	else
 		status = VIRTIO_NET_S_LINK_UP;
 
-	return ((status & VIRTIO_NET_S_LINK_UP) != 0);
+	if ((status & VIRTIO_NET_S_LINK_UP) != 0)
+		return LINK_STATE_UP;
+
+	return LINK_STATE_DOWN;
 }
 
 /* change link status */
@@ -2414,40 +2416,30 @@ vioif_update_link_status(struct vioif_so
 {
 	struct ifnet *ifp = >sc_ethercom.ec_if;
 	struct vioif_txqueue *txq;
-	bool active, changed;
+	bool active;
 	int link, i;
 
 	mutex_enter(>sc_lock);
 
-	active = vioif_is_link_up(sc);
-	changed = false;
+	link = vioif_get_link_status(sc);
 
-	if (active) {
-		if (!sc->sc_link_active)
-			changed = true;
+	if (link == sc->sc_link_state)
+		goto done;
 
-		link = LINK_STATE_UP;
-		sc->sc_link_active = true;
-	} else {
-		if (sc->sc_link_active)
-			changed = true;
-
-		link = LINK_STATE_DOWN;
-		sc->sc_link_active = false;
-	}
+	sc->sc_link_state = link;
 
-	if (changed) {
-		for (i = 0; i < sc->sc_act_nvq_pairs; i++) {
-			txq = >sc_txq[i];
-
-			mutex_enter(txq->txq_lock);
-			txq->txq_link_active = sc->sc_link_active;
-			mutex_exit(txq->txq_lock);
-		}
+	active = VIOIF_IS_LINK_ACTIVE(sc);
+	for (i = 0; i < sc->sc_act_nvq_pairs; i++) {
+		txq = >sc_txq[i];
 
-		if_link_state_change(ifp, link);
+		mutex_enter(txq->txq_lock);
+		txq->txq_link_active = active;
+		mutex_exit(txq->txq_lock);
 	}
 
+	if_link_state_change(ifp, sc->sc_link_state);
+
+done:
 	mutex_exit(>sc_lock);
 }
 



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

2022-09-11 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Sep 12 02:21:11 UTC 2022

Modified Files:
src/sys/arch/amd64/amd64: vector.S

Log Message:
Update register name at fault.  Pointed out by hgutch@n.o, thanks.

In vetor.S:r1.78

IDTVEC(handle_hypervisor_callback)
  movlCPUVAR(ILEVEL),%edi
  pushq   %rdi /* for Xdoreti */

So, use %edi as before.


To generate a diff of this commit:
cvs rdiff -u -r1.79 -r1.80 src/sys/arch/amd64/amd64/vector.S

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



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

2022-09-11 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Sep 12 02:21:11 UTC 2022

Modified Files:
src/sys/arch/amd64/amd64: vector.S

Log Message:
Update register name at fault.  Pointed out by hgutch@n.o, thanks.

In vetor.S:r1.78

IDTVEC(handle_hypervisor_callback)
  movlCPUVAR(ILEVEL),%edi
  pushq   %rdi /* for Xdoreti */

So, use %edi as before.


To generate a diff of this commit:
cvs rdiff -u -r1.79 -r1.80 src/sys/arch/amd64/amd64/vector.S

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

Modified files:

Index: src/sys/arch/amd64/amd64/vector.S
diff -u src/sys/arch/amd64/amd64/vector.S:1.79 src/sys/arch/amd64/amd64/vector.S:1.80
--- src/sys/arch/amd64/amd64/vector.S:1.79	Wed Sep  7 00:40:18 2022
+++ src/sys/arch/amd64/amd64/vector.S	Mon Sep 12 02:21:11 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: vector.S,v 1.79 2022/09/07 00:40:18 knakahara Exp $	*/
+/*	$NetBSD: vector.S,v 1.80 2022/09/12 02:21:11 knakahara Exp $	*/
 
 /*
  * Copyright (c) 1998, 2007, 2008 The NetBSD Foundation, Inc.
@@ -728,7 +728,7 @@ ENTRY(hypervisor_callback)
 	pushq	$T_ASTFLT
 	INTRENTRY
 IDTVEC(handle_hypervisor_callback)
-	movzbl	CPUVAR(ILEVEL),%rdi
+	movzbl	CPUVAR(ILEVEL),%edi
 	pushq   %rdi /* for Xdoreti */
 	incl	CPUVAR(IDEPTH)
 	movq	%rsp,%rdi



CVS commit: src/sys/arch/i386/i386

2022-09-08 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Sep  8 06:57:44 UTC 2022

Modified Files:
src/sys/arch/i386/i386: lock_stubs.S spl.S

Log Message:
Fix PR port-i386/57000 (boot failure on qemu).


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/sys/arch/i386/i386/lock_stubs.S
cvs rdiff -u -r1.56 -r1.57 src/sys/arch/i386/i386/spl.S

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/i386/i386/lock_stubs.S
diff -u src/sys/arch/i386/i386/lock_stubs.S:1.37 src/sys/arch/i386/i386/lock_stubs.S:1.38
--- src/sys/arch/i386/i386/lock_stubs.S:1.37	Wed Sep  7 00:40:18 2022
+++ src/sys/arch/i386/i386/lock_stubs.S	Thu Sep  8 06:57:44 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: lock_stubs.S,v 1.37 2022/09/07 00:40:18 knakahara Exp $	*/
+/*	$NetBSD: lock_stubs.S,v 1.38 2022/09/08 06:57:44 knakahara Exp $	*/
 
 /*-
  * Copyright (c) 2006, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lock_stubs.S,v 1.37 2022/09/07 00:40:18 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lock_stubs.S,v 1.38 2022/09/08 06:57:44 knakahara Exp $");
 
 #include "opt_lockdebug.h"
 
@@ -255,10 +255,10 @@ END(mutex_spin_enter)
 
 #ifndef XENPV
 /*
- * Release a spin mutex and post a store fence. Must occupy 96 bytes.
+ * Release a spin mutex and post a store fence. Must occupy 128 bytes.
  */
 ENTRY(mutex_spin_exit)
-	HOTPATCH(HP_NAME_MUTEX_EXIT, 96)
+	HOTPATCH(HP_NAME_MUTEX_EXIT, 128)
 	movl	4(%esp), %edx
 	movl	CPUVAR(MTX_OLDSPL), %ecx
 	incl	CPUVAR(MTX_COUNT)
@@ -284,7 +284,7 @@ STRONG_ALIAS(mutex_spin_exit, i686_mutex
 
 /*
  * Patch for i686 CPUs where cli/sti is prohibitively expensive.
- * Must be the same size as mutex_spin_exit(), that is, 96 bytes.
+ * Must be the same size as mutex_spin_exit(), that is, 128 bytes.
  */
 ENTRY(i686_mutex_spin_exit)
 	mov	4(%esp),%edx

Index: src/sys/arch/i386/i386/spl.S
diff -u src/sys/arch/i386/i386/spl.S:1.56 src/sys/arch/i386/i386/spl.S:1.57
--- src/sys/arch/i386/i386/spl.S:1.56	Wed Sep  7 00:40:18 2022
+++ src/sys/arch/i386/i386/spl.S	Thu Sep  8 06:57:44 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: spl.S,v 1.56 2022/09/07 00:40:18 knakahara Exp $	*/
+/*	$NetBSD: spl.S,v 1.57 2022/09/08 06:57:44 knakahara Exp $	*/
 
 /*
  * Copyright (c) 1998, 2007, 2008, 2020 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: spl.S,v 1.56 2022/09/07 00:40:18 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: spl.S,v 1.57 2022/09/08 06:57:44 knakahara Exp $");
 
 #include "opt_ddb.h"
 #include "opt_spldebug.h"
@@ -72,11 +72,11 @@ END(splraise)
  * void spllower(int s);
  *
  * spllower() for i486 and Pentium. Must be the same size as cx8_spllower(),
- * that is, 64 bytes. This must use pushf/cli/popf as it is used early in boot
+ * that is, 96 bytes. This must use pushf/cli/popf as it is used early in boot
  * where interrupts are disabled via eflags/IE.
  */
 ENTRY(spllower)
-	HOTPATCH(HP_NAME_SPLLOWER, 64)
+	HOTPATCH(HP_NAME_SPLLOWER, 96)
 #ifdef SPLDEBUG
 	movl	4(%esp),%ecx
 	pushl	%ebp
@@ -115,7 +115,7 @@ STRONG_ALIAS(spllower, cx8_spllower)
  *
  * spllower() optimized for Pentium Pro and later, which have long pipelines
  * that will be stalled by pushf/cli/popf.  Must be the same size as
- * spllower(), ie 64 bytes.  Does not need to restore eflags/IE as is patched
+ * spllower(), ie 96 bytes.  Does not need to restore eflags/IE as is patched
  * in once autoconf is underway.
  *
  * For cmpxchg8b, edx/ecx are the high words and eax/ebx the low.



CVS commit: src/sys/arch/i386/i386

2022-09-08 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Sep  8 06:57:44 UTC 2022

Modified Files:
src/sys/arch/i386/i386: lock_stubs.S spl.S

Log Message:
Fix PR port-i386/57000 (boot failure on qemu).


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/sys/arch/i386/i386/lock_stubs.S
cvs rdiff -u -r1.56 -r1.57 src/sys/arch/i386/i386/spl.S

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



CVS commit: src/sys/arch

2022-09-06 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Sep  7 00:40:19 UTC 2022

Modified Files:
src/sys/arch/amd64/amd64: amd64_trap.S genassym.cf lock_stubs.S
locore.S spl.S vector.S
src/sys/arch/i386/i386: genassym.cf i386_trap.S lock_stubs.S locore.S
spl.S vector.S
src/sys/arch/x86/include: cpu.h intr.h intrdefs.h
src/sys/arch/x86/x86: intr.c lapic.c x86_softintr.c
src/sys/arch/xen/include: hypervisor.h intr.h
src/sys/arch/xen/x86: hypervisor_machdep.c
src/sys/arch/xen/xen: evtchn.c xenevt.c

Log Message:
NetBSD/x86: Raise the number of interrupt sources per CPU from 32 to 56.

There has been no objection for three years.
https://mail-index.netbsd.org/port-amd64/2019/09/22/msg003012.html
Implemented by nonaka@n.o, updated by me.


To generate a diff of this commit:
cvs rdiff -u -r1.53 -r1.54 src/sys/arch/amd64/amd64/amd64_trap.S
cvs rdiff -u -r1.88 -r1.89 src/sys/arch/amd64/amd64/genassym.cf
cvs rdiff -u -r1.36 -r1.37 src/sys/arch/amd64/amd64/lock_stubs.S
cvs rdiff -u -r1.213 -r1.214 src/sys/arch/amd64/amd64/locore.S
cvs rdiff -u -r1.47 -r1.48 src/sys/arch/amd64/amd64/spl.S
cvs rdiff -u -r1.78 -r1.79 src/sys/arch/amd64/amd64/vector.S
cvs rdiff -u -r1.125 -r1.126 src/sys/arch/i386/i386/genassym.cf
cvs rdiff -u -r1.22 -r1.23 src/sys/arch/i386/i386/i386_trap.S
cvs rdiff -u -r1.36 -r1.37 src/sys/arch/i386/i386/lock_stubs.S
cvs rdiff -u -r1.189 -r1.190 src/sys/arch/i386/i386/locore.S
cvs rdiff -u -r1.55 -r1.56 src/sys/arch/i386/i386/spl.S
cvs rdiff -u -r1.88 -r1.89 src/sys/arch/i386/i386/vector.S
cvs rdiff -u -r1.132 -r1.133 src/sys/arch/x86/include/cpu.h
cvs rdiff -u -r1.65 -r1.66 src/sys/arch/x86/include/intr.h
cvs rdiff -u -r1.25 -r1.26 src/sys/arch/x86/include/intrdefs.h
cvs rdiff -u -r1.160 -r1.161 src/sys/arch/x86/x86/intr.c
cvs rdiff -u -r1.88 -r1.89 src/sys/arch/x86/x86/lapic.c
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/x86/x86/x86_softintr.c
cvs rdiff -u -r1.54 -r1.55 src/sys/arch/xen/include/hypervisor.h
cvs rdiff -u -r1.59 -r1.60 src/sys/arch/xen/include/intr.h
cvs rdiff -u -r1.44 -r1.45 src/sys/arch/xen/x86/hypervisor_machdep.c
cvs rdiff -u -r1.99 -r1.100 src/sys/arch/xen/xen/evtchn.c
cvs rdiff -u -r1.66 -r1.67 src/sys/arch/xen/xen/xenevt.c

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



CVS commit: src/sys/arch

2022-09-06 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Wed Sep  7 00:40:19 UTC 2022

Modified Files:
src/sys/arch/amd64/amd64: amd64_trap.S genassym.cf lock_stubs.S
locore.S spl.S vector.S
src/sys/arch/i386/i386: genassym.cf i386_trap.S lock_stubs.S locore.S
spl.S vector.S
src/sys/arch/x86/include: cpu.h intr.h intrdefs.h
src/sys/arch/x86/x86: intr.c lapic.c x86_softintr.c
src/sys/arch/xen/include: hypervisor.h intr.h
src/sys/arch/xen/x86: hypervisor_machdep.c
src/sys/arch/xen/xen: evtchn.c xenevt.c

Log Message:
NetBSD/x86: Raise the number of interrupt sources per CPU from 32 to 56.

There has been no objection for three years.
https://mail-index.netbsd.org/port-amd64/2019/09/22/msg003012.html
Implemented by nonaka@n.o, updated by me.


To generate a diff of this commit:
cvs rdiff -u -r1.53 -r1.54 src/sys/arch/amd64/amd64/amd64_trap.S
cvs rdiff -u -r1.88 -r1.89 src/sys/arch/amd64/amd64/genassym.cf
cvs rdiff -u -r1.36 -r1.37 src/sys/arch/amd64/amd64/lock_stubs.S
cvs rdiff -u -r1.213 -r1.214 src/sys/arch/amd64/amd64/locore.S
cvs rdiff -u -r1.47 -r1.48 src/sys/arch/amd64/amd64/spl.S
cvs rdiff -u -r1.78 -r1.79 src/sys/arch/amd64/amd64/vector.S
cvs rdiff -u -r1.125 -r1.126 src/sys/arch/i386/i386/genassym.cf
cvs rdiff -u -r1.22 -r1.23 src/sys/arch/i386/i386/i386_trap.S
cvs rdiff -u -r1.36 -r1.37 src/sys/arch/i386/i386/lock_stubs.S
cvs rdiff -u -r1.189 -r1.190 src/sys/arch/i386/i386/locore.S
cvs rdiff -u -r1.55 -r1.56 src/sys/arch/i386/i386/spl.S
cvs rdiff -u -r1.88 -r1.89 src/sys/arch/i386/i386/vector.S
cvs rdiff -u -r1.132 -r1.133 src/sys/arch/x86/include/cpu.h
cvs rdiff -u -r1.65 -r1.66 src/sys/arch/x86/include/intr.h
cvs rdiff -u -r1.25 -r1.26 src/sys/arch/x86/include/intrdefs.h
cvs rdiff -u -r1.160 -r1.161 src/sys/arch/x86/x86/intr.c
cvs rdiff -u -r1.88 -r1.89 src/sys/arch/x86/x86/lapic.c
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/x86/x86/x86_softintr.c
cvs rdiff -u -r1.54 -r1.55 src/sys/arch/xen/include/hypervisor.h
cvs rdiff -u -r1.59 -r1.60 src/sys/arch/xen/include/intr.h
cvs rdiff -u -r1.44 -r1.45 src/sys/arch/xen/x86/hypervisor_machdep.c
cvs rdiff -u -r1.99 -r1.100 src/sys/arch/xen/xen/evtchn.c
cvs rdiff -u -r1.66 -r1.67 src/sys/arch/xen/xen/xenevt.c

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

Modified files:

Index: src/sys/arch/amd64/amd64/amd64_trap.S
diff -u src/sys/arch/amd64/amd64/amd64_trap.S:1.53 src/sys/arch/amd64/amd64/amd64_trap.S:1.54
--- src/sys/arch/amd64/amd64/amd64_trap.S:1.53	Mon Jun 29 23:04:56 2020
+++ src/sys/arch/amd64/amd64/amd64_trap.S	Wed Sep  7 00:40:18 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: amd64_trap.S,v 1.53 2020/06/29 23:04:56 riastradh Exp $	*/
+/*	$NetBSD: amd64_trap.S,v 1.54 2022/09/07 00:40:18 knakahara Exp $	*/
 
 /*
  * Copyright (c) 1998, 2007, 2008, 2017 The NetBSD Foundation, Inc.
@@ -347,7 +347,7 @@ IDTVEC(trap07)
 	ZTRAP_NJ(T_DNA)
 	INTRENTRY
 #ifdef DIAGNOSTIC
-	movl	CPUVAR(ILEVEL),%ebx
+	movzbl	CPUVAR(ILEVEL),%ebx
 #endif
 	movq	%rsp,%rdi
 	call	_C_LABEL(fpudna)
@@ -439,7 +439,7 @@ IDTVEC(trap15)
 	ZTRAP_NJ(T_ASTFLT)
 	INTRENTRY
 #ifdef DIAGNOSTIC
-	movl	CPUVAR(ILEVEL),%ebx
+	movzbl	CPUVAR(ILEVEL),%ebx
 #endif
 	jmp	.Lalltraps_checkusr
 IDTVEC_END(trap15)
@@ -457,7 +457,7 @@ IDTVEC(trap16)
 	HANDLE_DEFERRED_FPU
 #endif /* XENPV */
 #ifdef DIAGNOSTIC
-	movl	CPUVAR(ILEVEL),%ebx
+	movzbl	CPUVAR(ILEVEL),%ebx
 #endif
 	movq	%rsp,%rdi
 	call	_C_LABEL(fputrap)
@@ -508,7 +508,7 @@ IDTVEC(intrspurious)
 	ZTRAP_NJ(T_ASTFLT)
 	INTRENTRY
 #ifdef DIAGNOSTIC
-	movl	CPUVAR(ILEVEL),%ebx
+	movzbl	CPUVAR(ILEVEL),%ebx
 #endif
 	jmp	.Lalltraps_checkusr
 IDTVEC_END(intrspurious)
@@ -658,7 +658,7 @@ ENTRY(alltraps)
 
 calltrap:
 #ifdef DIAGNOSTIC
-	movl	CPUVAR(ILEVEL),%ebx
+	movzbl	CPUVAR(ILEVEL),%ebx
 #endif
 	movq	%rsp,%rdi
 	incq	CPUVAR(NTRAP)
@@ -688,7 +688,7 @@ calltrap:
 
 6:
 #ifdef DIAGNOSTIC
-	cmpl	CPUVAR(ILEVEL),%ebx
+	cmpb	CPUVAR(ILEVEL),%bl
 	jne	.Lspl_error
 #endif
 	INTRFASTEXIT
@@ -701,7 +701,7 @@ calltrap:
 .Lspl_error:
 	STI(si)
 	movabsq	$4f,%rdi
-	movl	CPUVAR(ILEVEL),%esi
+	movzbl	CPUVAR(ILEVEL),%esi
 	call	_C_LABEL(panic)
 4:	.asciz	"spl not lowered on trap exit, ilevel=%x"
 #endif

Index: src/sys/arch/amd64/amd64/genassym.cf
diff -u src/sys/arch/amd64/amd64/genassym.cf:1.88 src/sys/arch/amd64/amd64/genassym.cf:1.89
--- src/sys/arch/amd64/amd64/genassym.cf:1.88	Sat Aug 20 23:48:50 2022
+++ src/sys/arch/amd64/amd64/genassym.cf	Wed Sep  7 00:40:18 2022
@@ -1,4 +1,4 @@
-#	$NetBSD: genassym.cf,v 1.88 2022/08/20 23:48:50 riastradh Exp $
+#	$NetBSD: genassym.cf,v 1.89 2022/09/07 00:40:18 knakahara Exp $
 
 #
 # Copyright (c) 1998, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -247,9 +247,9 @@ define	CPU_INFO_NINTR		offsetof(struct c
 define	CPU_INFO_CURPRIORITY	offsetof(struct cpu_info, ci_schedstate.spc_curpriority)
 
 define	CPU_INFO_GDT		offsetof(struct cpu_info, ci_gdt)
-define	CPU_INFO_ILEVEL		offsetof(struct 

CVS commit: src/sys/net

2022-08-29 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Aug 29 23:48:18 UTC 2022

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

Log Message:
Fix build failure when no options INET6.


To generate a diff of this commit:
cvs rdiff -u -r1.232 -r1.233 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.232 src/sys/net/route.c:1.233
--- src/sys/net/route.c:1.232	Mon Aug 29 09:14:02 2022
+++ src/sys/net/route.c	Mon Aug 29 23:48:18 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: route.c,v 1.232 2022/08/29 09:14:02 knakahara Exp $	*/
+/*	$NetBSD: route.c,v 1.233 2022/08/29 23:48:18 knakahara Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -97,7 +97,7 @@
 #endif
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.232 2022/08/29 09:14:02 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.233 2022/08/29 23:48:18 knakahara Exp $");
 
 #include 
 #ifdef RTFLUSH_DEBUG
@@ -1553,23 +1553,29 @@ rt_newmsg(const int cmd, const struct rt
 void
 rt_newmsg_dynamic(const int cmd, const struct rtentry *rt)
 {
-	extern bool icmp_dynamic_rt_msg;
-	extern bool icmp6_dynamic_rt_msg;
 	struct rt_addrinfo info;
 	struct sockaddr *gateway = rt->rt_gateway;
 
 	if (gateway == NULL)
 		return;
 
-	switch(gateway->sa_family){
-	case AF_INET:
+	switch(gateway->sa_family) {
+#ifdef INET
+	case AF_INET: {
+		extern bool icmp_dynamic_rt_msg;
 		if (!icmp_dynamic_rt_msg)
 			return;
 		break;
-	case AF_INET6:
+	}
+#endif
+#ifdef INET6
+	case AF_INET6: {
+		extern bool icmp6_dynamic_rt_msg;
 		if (!icmp6_dynamic_rt_msg)
 			return;
 		break;
+	}
+#endif
 	default:
 		return;
 	}



CVS commit: src/sys/net

2022-08-29 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Aug 29 23:48:18 UTC 2022

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

Log Message:
Fix build failure when no options INET6.


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

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



CVS commit: src

2022-08-29 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Aug 29 09:14:02 UTC 2022

Modified Files:
src/share/man/man7: sysctl.7
src/sys/net: route.c route.h
src/sys/netinet: icmp6.h icmp_var.h in_pcb.c ip_icmp.c
src/sys/netinet6: icmp6.c in6_pcb.c

Log Message:
Add sysctl entry to control to send routing message for RTM_DYNAMIC.

Some routing daemons require such routing message to keep coherency.

If we want to let kernel send such message, set net.inet.icmp.dynamic_rt_msg=1
for IPv4, net.inet6.icmp6.dynamic_rt_msg=1 for IPv6.
Default(=0) is the same as before, that is, not send such routing message.


To generate a diff of this commit:
cvs rdiff -u -r1.160 -r1.161 src/share/man/man7/sysctl.7
cvs rdiff -u -r1.231 -r1.232 src/sys/net/route.c
cvs rdiff -u -r1.130 -r1.131 src/sys/net/route.h
cvs rdiff -u -r1.58 -r1.59 src/sys/netinet/icmp6.h
cvs rdiff -u -r1.31 -r1.32 src/sys/netinet/icmp_var.h
cvs rdiff -u -r1.189 -r1.190 src/sys/netinet/in_pcb.c
cvs rdiff -u -r1.177 -r1.178 src/sys/netinet/ip_icmp.c
cvs rdiff -u -r1.251 -r1.252 src/sys/netinet6/icmp6.c
cvs rdiff -u -r1.169 -r1.170 src/sys/netinet6/in6_pcb.c

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



CVS commit: src

2022-08-29 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Aug 29 09:14:02 UTC 2022

Modified Files:
src/share/man/man7: sysctl.7
src/sys/net: route.c route.h
src/sys/netinet: icmp6.h icmp_var.h in_pcb.c ip_icmp.c
src/sys/netinet6: icmp6.c in6_pcb.c

Log Message:
Add sysctl entry to control to send routing message for RTM_DYNAMIC.

Some routing daemons require such routing message to keep coherency.

If we want to let kernel send such message, set net.inet.icmp.dynamic_rt_msg=1
for IPv4, net.inet6.icmp6.dynamic_rt_msg=1 for IPv6.
Default(=0) is the same as before, that is, not send such routing message.


To generate a diff of this commit:
cvs rdiff -u -r1.160 -r1.161 src/share/man/man7/sysctl.7
cvs rdiff -u -r1.231 -r1.232 src/sys/net/route.c
cvs rdiff -u -r1.130 -r1.131 src/sys/net/route.h
cvs rdiff -u -r1.58 -r1.59 src/sys/netinet/icmp6.h
cvs rdiff -u -r1.31 -r1.32 src/sys/netinet/icmp_var.h
cvs rdiff -u -r1.189 -r1.190 src/sys/netinet/in_pcb.c
cvs rdiff -u -r1.177 -r1.178 src/sys/netinet/ip_icmp.c
cvs rdiff -u -r1.251 -r1.252 src/sys/netinet6/icmp6.c
cvs rdiff -u -r1.169 -r1.170 src/sys/netinet6/in6_pcb.c

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

Modified files:

Index: src/share/man/man7/sysctl.7
diff -u src/share/man/man7/sysctl.7:1.160 src/share/man/man7/sysctl.7:1.161
--- src/share/man/man7/sysctl.7:1.160	Mon Aug 22 09:25:55 2022
+++ src/share/man/man7/sysctl.7	Mon Aug 29 09:14:02 2022
@@ -1,4 +1,4 @@
-.\"	$NetBSD: sysctl.7,v 1.160 2022/08/22 09:25:55 knakahara Exp $
+.\"	$NetBSD: sysctl.7,v 1.161 2022/08/29 09:14:02 knakahara Exp $
 .\"
 .\" Copyright (c) 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\"	@(#)sysctl.3	8.4 (Berkeley) 5/9/95
 .\"
-.Dd August 9, 2022
+.Dd August 29, 2022
 .Dt SYSCTL 7
 .Os
 .Sh NAME
@@ -1457,6 +1457,7 @@ The currently defined protocols and name
 .It icmp	rediraccept	integer	yes
 .It icmp	redirtimeout	integer	yes
 .It icmp	bmcastecho	integer	yes
+.It icmp	dynamic_rt_msg	boolean	yes
 .It ip	allowsrcrt	integer	yes
 .It ip 	anonportalgo.selected	string	yes
 .It ip 	anonportalgo.available	string	yes
@@ -1703,6 +1704,9 @@ Number of bytes to return in an ICMP err
 .It Li icmp.bmcastecho
 If set to 1, enables responding to ICMP echo or timestamp request to the
 broadcast address.
+.It Li icmp.dynamic_rt_msg
+A boolean that the kernel sends routing message for RTM_DYNAMIC or not.
+If set to true, sends such routing message.
 .It Li tcp.ack_on_push
 If set to 1, TCP is to immediately transmit an ACK upon reception of
 a packet with PUSH set.
@@ -1856,6 +1860,7 @@ The currently defined protocols and name
 .It icmp6	rediraccept	integer	yes
 .It icmp6	redirtimeout	integer	yes
 .It icmp6	reflect_pmtu	boolean	yes
+.It icmp6	dynamic_rt_msg	boolean	yes
 .It ip6	accept_rtadv	integer	yes
 .It ip6	addctlpolicy	struct in6_addrpolicy	no
 .It ip6	anonportalgo.selected	string	yes
@@ -2120,7 +2125,9 @@ ICMPv6 redirect.
 .It Li icmp6.reflect_pmtu
 A boolean that icmpv6 reflecting uses path MTU discovery or not.
 When not, icmpv6 reflecting uses IPV6_MINMTU.
-ICMPv6 redirect.
+.It Li icmp6.dynamic_rt_msg
+A boolean that the kernel sends routing message for RTM_DYNAMIC or not.
+If set to true, sends such routing message.
 .It Li udp6.do_loopback_cksum
 Perform UDP checksum on loopback.
 .It Li udp6.recvspace

Index: src/sys/net/route.c
diff -u src/sys/net/route.c:1.231 src/sys/net/route.c:1.232
--- src/sys/net/route.c:1.231	Fri Aug 26 08:32:22 2022
+++ src/sys/net/route.c	Mon Aug 29 09:14:02 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: route.c,v 1.231 2022/08/26 08:32:22 knakahara Exp $	*/
+/*	$NetBSD: route.c,v 1.232 2022/08/29 09:14:02 knakahara Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -97,7 +97,7 @@
 #endif
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.231 2022/08/26 08:32:22 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.232 2022/08/29 09:14:02 knakahara Exp $");
 
 #include 
 #ifdef RTFLUSH_DEBUG
@@ -884,6 +884,8 @@ rtredirect(const struct sockaddr *dst, c
 			error = rtrequest1(RTM_ADD, , );
 			if (rt != NULL)
 flags = rt->rt_flags;
+			if (error == 0)
+rt_newmsg_dynamic(RTM_ADD, rt);
 			stat = _dynamic;
 		} else {
 			/*
@@ -1546,6 +1548,45 @@ rt_newmsg(const int cmd, const struct rt
 }
 
 /*
+ * Inform the routing socket of a route change for RTF_DYNAMIC.
+ */
+void
+rt_newmsg_dynamic(const int cmd, const struct rtentry *rt)
+{
+	extern bool icmp_dynamic_rt_msg;
+	extern bool icmp6_dynamic_rt_msg;
+	struct rt_addrinfo info;
+	struct sockaddr *gateway = rt->rt_gateway;
+
+	if (gateway == NULL)
+		return;
+
+	switch(gateway->sa_family){
+	case AF_INET:
+		if (!icmp_dynamic_rt_msg)
+			return;
+		break;
+	case AF_INET6:
+		if (!icmp6_dynamic_rt_msg)
+			return;
+		break;
+	default:
+		return;
+	}
+
+	memset((void *), 0, sizeof(info));
+	info.rti_info[RTAX_DST] = 

CVS commit: src/sys/net

2022-08-26 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Aug 26 08:32:23 UTC 2022

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

Log Message:
Refactor: rtrequest_newmsg() is no longer used after nd6_rtr.c:r1.149

That has bumped up to 9.99.66 when nd6_rtr.c:r1.149 was commited.


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

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

Modified files:

Index: src/sys/net/route.c
diff -u src/sys/net/route.c:1.230 src/sys/net/route.c:1.231
--- src/sys/net/route.c:1.230	Sun Dec  5 04:57:38 2021
+++ src/sys/net/route.c	Fri Aug 26 08:32:22 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: route.c,v 1.230 2021/12/05 04:57:38 msaitoh Exp $	*/
+/*	$NetBSD: route.c,v 1.231 2022/08/26 08:32:22 knakahara Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -97,7 +97,7 @@
 #endif
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.230 2021/12/05 04:57:38 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.231 2022/08/26 08:32:22 knakahara Exp $");
 
 #include 
 #ifdef RTFLUSH_DEBUG
@@ -1055,35 +1055,6 @@ rtrequest(int req, const struct sockaddr
 	return rtrequest1(req, , ret_nrt);
 }
 
-/*
- * It's a utility function to add/remove a route to/from the routing table
- * and tell user processes the addition/removal on success.
- */
-int
-rtrequest_newmsg(const int req, const struct sockaddr *dst,
-	const struct sockaddr *gateway, const struct sockaddr *netmask,
-	const int flags)
-{
-	int error;
-	struct rtentry *ret_nrt = NULL;
-
-	KASSERT(req == RTM_ADD || req == RTM_DELETE);
-
-	error = rtrequest(req, dst, gateway, netmask, flags, _nrt);
-	if (error != 0)
-		return error;
-
-	KASSERT(ret_nrt != NULL);
-
-	rt_newmsg(req, ret_nrt); /* tell user process */
-	if (req == RTM_DELETE)
-		rt_free(ret_nrt);
-	else
-		rt_unref(ret_nrt);
-
-	return 0;
-}
-
 static struct ifnet *
 rt_getifp(struct rt_addrinfo *info, struct psref *psref)
 {

Index: src/sys/net/route.h
diff -u src/sys/net/route.h:1.129 src/sys/net/route.h:1.130
--- src/sys/net/route.h:1.129	Mon Aug  9 20:49:10 2021
+++ src/sys/net/route.h	Fri Aug 26 08:32:22 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: route.h,v 1.129 2021/08/09 20:49:10 andvar Exp $	*/
+/*	$NetBSD: route.h,v 1.130 2022/08/26 08:32:22 knakahara Exp $	*/
 
 /*
  * Copyright (c) 1980, 1986, 1993
@@ -447,8 +447,6 @@ int	rtrequest(int, const struct sockaddr
 	const struct sockaddr *, const struct sockaddr *, int,
 	struct rtentry **);
 int	rtrequest1(int, struct rt_addrinfo *, struct rtentry **);
-int	rtrequest_newmsg(const int, const struct sockaddr *,
-	const struct sockaddr *, const struct sockaddr *, const int);
 
 int	rt_ifa_addlocal(struct ifaddr *);
 int	rt_ifa_remlocal(struct ifaddr *, struct ifaddr *);



CVS commit: src/sys/net

2022-08-26 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Aug 26 08:32:23 UTC 2022

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

Log Message:
Refactor: rtrequest_newmsg() is no longer used after nd6_rtr.c:r1.149

That has bumped up to 9.99.66 when nd6_rtr.c:r1.149 was commited.


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

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



CVS commit: src/sys/dev/pci

2022-08-25 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Aug 25 09:15:14 UTC 2022

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

Log Message:
Tune number of Rx descriptors for ixl(4), ok'ed by yamaguchi@n.o.

In some tunneling measurement cases, that improve performance.
In other cases, that keep up performance.


To generate a diff of this commit:
cvs rdiff -u -r1.85 -r1.86 src/sys/dev/pci/if_ixl.c

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

Modified files:

Index: src/sys/dev/pci/if_ixl.c
diff -u src/sys/dev/pci/if_ixl.c:1.85 src/sys/dev/pci/if_ixl.c:1.86
--- src/sys/dev/pci/if_ixl.c:1.85	Fri Jun 17 06:26:00 2022
+++ src/sys/dev/pci/if_ixl.c	Thu Aug 25 09:15:14 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ixl.c,v 1.85 2022/06/17 06:26:00 yamaguchi Exp $	*/
+/*	$NetBSD: if_ixl.c,v 1.86 2022/08/25 09:15:14 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2013-2015, Intel Corporation
@@ -74,7 +74,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_ixl.c,v 1.85 2022/06/17 06:26:00 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ixl.c,v 1.86 2022/08/25 09:15:14 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -718,7 +718,7 @@ static bool		 ixl_param_nomsix = false;
 static int		 ixl_param_stats_interval = IXL_STATS_INTERVAL_MSEC;
 static int		 ixl_param_nqps_limit = IXL_QUEUE_NUM;
 static unsigned int	 ixl_param_tx_ndescs = 512;
-static unsigned int	 ixl_param_rx_ndescs = 256;
+static unsigned int	 ixl_param_rx_ndescs = 512;
 
 static enum i40e_mac_type
 	ixl_mactype(pci_product_id_t);



CVS commit: src/sys/dev/pci

2022-08-25 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Aug 25 09:15:14 UTC 2022

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

Log Message:
Tune number of Rx descriptors for ixl(4), ok'ed by yamaguchi@n.o.

In some tunneling measurement cases, that improve performance.
In other cases, that keep up performance.


To generate a diff of this commit:
cvs rdiff -u -r1.85 -r1.86 src/sys/dev/pci/if_ixl.c

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



  1   2   3   >