CVS commit: src/sys/netinet

2024-04-14 Thread Andrius Varanavicius
Module Name:src
Committed By:   andvar
Date:   Sun Apr 14 18:02:55 UTC 2024

Modified Files:
src/sys/netinet: sctputil.h

Log Message:
s/force_comile_error/force_compile_error/


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/netinet/sctputil.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/sctputil.h
diff -u src/sys/netinet/sctputil.h:1.3 src/sys/netinet/sctputil.h:1.4
--- src/sys/netinet/sctputil.h:1.3	Sun Jan 19 20:51:13 2020
+++ src/sys/netinet/sctputil.h	Sun Apr 14 18:02:55 2024
@@ -1,5 +1,5 @@
 /*	$KAME: sctputil.h,v 1.15 2005/03/06 16:04:19 itojun Exp $	*/
-/*	$NetBSD: sctputil.h,v 1.3 2020/01/19 20:51:13 riastradh Exp $ */
+/*	$NetBSD: sctputil.h,v 1.4 2024/04/14 18:02:55 andvar Exp $ */
 
 #ifndef __SCTPUTIL_H__
 #define __SCTPUTIL_H__
@@ -85,7 +85,7 @@
 	pool_init(&(zone), size, 0, 0, 0, name, NULL, IPL_NET);
 #else
 	/* don't know this OS! */
-	force_comile_error;
+	force_compile_error;
 #endif
 
 /* SCTP_ZONE_GET: allocate element from the zone */
@@ -105,7 +105,7 @@
 	pool_get(, PR_NOWAIT);
 #else
 	/* don't know this OS! */
-	force_comile_error;
+	force_compile_error;
 #endif
 
 /* SCTP_ZONE_FREE: free element from the zone */
@@ -125,7 +125,7 @@
 	pool_put(, element);
 #else
 	/* don't know this OS! */
-	force_comile_error;
+	force_compile_error;
 #endif
 
 #define sctp_get_associd(stcb) ((sctp_assoc_t)stcb->asoc.my_vtag)



CVS commit: src/sys/netinet

2024-04-14 Thread Andrius Varanavicius
Module Name:src
Committed By:   andvar
Date:   Sun Apr 14 18:02:55 UTC 2024

Modified Files:
src/sys/netinet: sctputil.h

Log Message:
s/force_comile_error/force_compile_error/


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/netinet/sctputil.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

2024-02-24 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Feb 24 21:39:05 UTC 2024

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

Log Message:
Attribute debug message.
Fixes PR 57959


To generate a diff of this commit:
cvs rdiff -u -r1.311 -r1.312 src/sys/netinet/if_arp.c

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

Modified files:

Index: src/sys/netinet/if_arp.c
diff -u src/sys/netinet/if_arp.c:1.311 src/sys/netinet/if_arp.c:1.312
--- src/sys/netinet/if_arp.c:1.311	Tue Nov 15 10:47:39 2022
+++ src/sys/netinet/if_arp.c	Sat Feb 24 21:39:05 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_arp.c,v 1.311 2022/11/15 10:47:39 roy Exp $	*/
+/*	$NetBSD: if_arp.c,v 1.312 2024/02/24 21:39:05 mlelstv Exp $	*/
 
 /*
  * Copyright (c) 1998, 2000, 2008 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.311 2022/11/15 10:47:39 roy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.312 2024/02/24 21:39:05 mlelstv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -1355,8 +1355,8 @@ arp_llinfo_output(struct ifnet *ifp, __u
 		if (sip.s_addr == INADDR_ANY) {
 			char ipbuf[INET_ADDRSTRLEN];
 
-			log(LOG_DEBUG, "source can't be "
-			"determined: dst=%s\n",
+			log(LOG_DEBUG, "%s: source can't be "
+			"determined: dst=%s\n", __func__,
 			IN_PRINT(ipbuf, ));
 			return;
 		}



CVS commit: src/sys/netinet

2024-02-24 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Feb 24 21:39:05 UTC 2024

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

Log Message:
Attribute debug message.
Fixes PR 57959


To generate a diff of this commit:
cvs rdiff -u -r1.311 -r1.312 src/sys/netinet/if_arp.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

2023-09-13 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Wed Sep 13 15:58:13 UTC 2023

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

Log Message:
handle EHOSTDOWN the same way as EHOSTUNREACH in sctp_med_chunk_output().
Compile-tested only (I don't have a sctp setup); proposed in
http://mail-index.netbsd.org/tech-net/2023/09/11/msg008611.html
LGTM from Greg Troxel and Robert Swindells


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/sys/netinet/sctp_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/sctp_output.c
diff -u src/sys/netinet/sctp_output.c:1.33 src/sys/netinet/sctp_output.c:1.34
--- src/sys/netinet/sctp_output.c:1.33	Fri Nov  4 09:01:53 2022
+++ src/sys/netinet/sctp_output.c	Wed Sep 13 15:58:13 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: sctp_output.c,v 1.33 2022/11/04 09:01:53 ozaki-r Exp $ */
+/*	$NetBSD: sctp_output.c,v 1.34 2023/09/13 15:58:13 bouyer Exp $ */
 /*	$KAME: sctp_output.c,v 1.48 2005/06/16 18:29:24 jinmei Exp $	*/
 
 /*
@@ -30,7 +30,7 @@
  * SUCH DAMAGE.
  */
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sctp_output.c,v 1.33 2022/11/04 09:01:53 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sctp_output.c,v 1.34 2023/09/13 15:58:13 bouyer Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ipsec.h"
@@ -5643,7 +5643,8 @@ sctp_med_chunk_output(struct sctp_inpcb 
 			}
 			hbflag = 0;
 		}
-		if (error == EHOSTUNREACH) {
+		if (error == EHOSTUNREACH ||
+		error == EHOSTDOWN) {
 			/*
 			 * Destination went
 			 * unreachable during
@@ -5921,7 +5922,8 @@ sctp_med_chunk_output(struct sctp_inpcb 
 	}
 	hbflag = 0;
 }
-if (error == EHOSTUNREACH) {
+if (error == EHOSTUNREACH ||
+error == EHOSTDOWN) {
 	/*
 	 * Destination went unreachable during
 	 * this send



CVS commit: src/sys/netinet

2023-09-13 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Wed Sep 13 15:58:13 UTC 2023

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

Log Message:
handle EHOSTDOWN the same way as EHOSTUNREACH in sctp_med_chunk_output().
Compile-tested only (I don't have a sctp setup); proposed in
http://mail-index.netbsd.org/tech-net/2023/09/11/msg008611.html
LGTM from Greg Troxel and Robert Swindells


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/sys/netinet/sctp_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

2023-09-13 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Wed Sep 13 15:54:28 UTC 2023

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

Log Message:
Handle EHOSTDOWN the same way as EHOSTUNREACH and ENETDOWN for established
connections. Avoid premature end of tcp connection with "Host is down" error
in case of transient link-layer failure.
Discussed and patch proposed in
http://mail-index.netbsd.org/tech-net/2023/09/11/msg008610.html
and followups.


To generate a diff of this commit:
cvs rdiff -u -r1.218 -r1.219 src/sys/netinet/tcp_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/tcp_output.c
diff -u src/sys/netinet/tcp_output.c:1.218 src/sys/netinet/tcp_output.c:1.219
--- src/sys/netinet/tcp_output.c:1.218	Fri Nov  4 09:01:53 2022
+++ src/sys/netinet/tcp_output.c	Wed Sep 13 15:54:28 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_output.c,v 1.218 2022/11/04 09:01:53 ozaki-r Exp $	*/
+/*	$NetBSD: tcp_output.c,v 1.219 2023/09/13 15:54:28 bouyer Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -135,7 +135,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tcp_output.c,v 1.218 2022/11/04 09:01:53 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_output.c,v 1.219 2023/09/13 15:54:28 bouyer Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1612,8 +1612,8 @@ out:
 			TCP_STATINC(TCP_STAT_SELFQUENCH);
 			tcp_quench(tp->t_inpcb);
 			error = 0;
-		} else if ((error == EHOSTUNREACH || error == ENETDOWN) &&
-		TCPS_HAVERCVDSYN(tp->t_state)) {
+		} else if ((error == EHOSTUNREACH || error == ENETDOWN ||
+		error == EHOSTDOWN) && TCPS_HAVERCVDSYN(tp->t_state)) {
 			tp->t_softerror = error;
 			error = 0;
 		}



CVS commit: src/sys/netinet

2023-09-13 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Wed Sep 13 15:54:28 UTC 2023

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

Log Message:
Handle EHOSTDOWN the same way as EHOSTUNREACH and ENETDOWN for established
connections. Avoid premature end of tcp connection with "Host is down" error
in case of transient link-layer failure.
Discussed and patch proposed in
http://mail-index.netbsd.org/tech-net/2023/09/11/msg008610.html
and followups.


To generate a diff of this commit:
cvs rdiff -u -r1.218 -r1.219 src/sys/netinet/tcp_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

2023-08-13 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Mon Aug 14 03:03:48 UTC 2023

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

Log Message:
avoid uninitialised variable use.

found by GCC 12.


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

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/dccp_tfrc.c
diff -u src/sys/netinet/dccp_tfrc.c:1.10 src/sys/netinet/dccp_tfrc.c:1.11
--- src/sys/netinet/dccp_tfrc.c:1.10	Mon Aug  7 23:28:58 2023
+++ src/sys/netinet/dccp_tfrc.c	Mon Aug 14 03:03:48 2023
@@ -1,5 +1,5 @@
 /*	$KAME: dccp_tfrc.c,v 1.16 2006/03/01 17:34:08 nishida Exp $	*/
-/*	$NetBSD: dccp_tfrc.c,v 1.10 2023/08/07 23:28:58 mrg Exp $ */
+/*	$NetBSD: dccp_tfrc.c,v 1.11 2023/08/14 03:03:48 mrg Exp $ */
 
 /*
  * Copyright (c) 2003  Nils-Erik Mattsson
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: dccp_tfrc.c,v 1.10 2023/08/07 23:28:58 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dccp_tfrc.c,v 1.11 2023/08/14 03:03:48 mrg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_dccp.h"
@@ -384,7 +384,7 @@ tfrc_time_no_feedback(void *ccb)
 		/* half send rate */
 		cb->x.denom *= 2;
 		v.num = cb->s;
-		v.denom *= TFRC_MAX_BACK_OFF_TIME;
+		v.denom = TFRC_MAX_BACK_OFF_TIME;
 		if (fixpoint_cmp(>x, ) < 0)
 			cb->x = v;
 
@@ -414,7 +414,7 @@ tfrc_time_no_feedback(void *ccb)
 
 		v.num = cb->s;
 		v.num *= 4;
-		v.denom *= cb->rtt;
+		v.denom = cb->rtt;
 		v.num *= 100;
 		normalize(, );
 		if (!cb->idle || fixpoint_cmp(>x_recv, ) >= 0) {



CVS commit: src/sys/netinet

2023-08-13 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Mon Aug 14 03:03:48 UTC 2023

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

Log Message:
avoid uninitialised variable use.

found by GCC 12.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/netinet/dccp_tfrc.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

2023-06-15 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Fri Jun 16 03:02:30 UTC 2023

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

Log Message:
White space fixes. No binary changes.


To generate a diff of this commit:
cvs rdiff -u -r1.114 -r1.115 src/sys/netinet/in.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/in.h
diff -u src/sys/netinet/in.h:1.114 src/sys/netinet/in.h:1.115
--- src/sys/netinet/in.h:1.114	Wed Feb  3 18:13:13 2021
+++ src/sys/netinet/in.h	Fri Jun 16 03:02:30 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: in.h,v 1.114 2021/02/03 18:13:13 roy Exp $	*/
+/*	$NetBSD: in.h,v 1.115 2023/06/16 03:02:30 rin Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1990, 1993
@@ -107,7 +107,7 @@ typedef __sa_family_t	sa_family_t;
 #define	IPPROTO_CARP		112		/* Common Address Resolution Protocol */
 #define	IPPROTO_L2TP		115		/* L2TPv3 */
 #define	IPPROTO_SCTP		132		/* SCTP */
-#define IPPROTO_PFSYNC  240 /* PFSYNC */
+#define IPPROTO_PFSYNC		240		/* PFSYNC */
 #define	IPPROTO_RAW		255		/* raw IP packet */
 #define	IPPROTO_MAX		256
 
@@ -353,22 +353,22 @@ struct ip_mreq {
 #define	IPCTL_ALLOWSRCRT	7	/* allow/drop all source-routed pkts */
 #define	IPCTL_SUBNETSARELOCAL	8	/* treat subnets as local addresses */
 #define	IPCTL_MTUDISC		9	/* allow path MTU discovery */
-#define	IPCTL_ANONPORTMIN  10	/* minimum ephemeral port */
-#define	IPCTL_ANONPORTMAX  11	/* maximum ephemeral port */
-#define	IPCTL_MTUDISCTIMEOUT   12	/* allow path MTU discovery */
-#define	IPCTL_MAXFLOWS 13	/* maximum ip flows allowed */
-#define	IPCTL_HOSTZEROBROADCAST 14	/* is host zero a broadcast addr? */
-#define	IPCTL_GIF_TTL 	   15	/* default TTL for gif encap packet */
-#define	IPCTL_LOWPORTMIN   16	/* minimum reserved port */
-#define	IPCTL_LOWPORTMAX   17	/* maximum reserved port */
-#define	IPCTL_MAXFRAGPACKETS   18	/* max packets reassembly queue */
-#define	IPCTL_GRE_TTL  19	/* default TTL for gre encap packet */
-#define	IPCTL_CHECKINTERFACE   20	/* drop pkts in from 'wrong' iface */
-#define	IPCTL_IFQ	   21	/* IP packet input queue */
-#define	IPCTL_RANDOMID	   22	/* use random IP ids (if configured) */
-#define	IPCTL_LOOPBACKCKSUM23	/* do IP checksum on loopback */
+#define	IPCTL_ANONPORTMIN	10	/* minimum ephemeral port */
+#define	IPCTL_ANONPORTMAX	11	/* maximum ephemeral port */
+#define	IPCTL_MTUDISCTIMEOUT	12	/* allow path MTU discovery */
+#define	IPCTL_MAXFLOWS		13	/* maximum ip flows allowed */
+#define	IPCTL_HOSTZEROBROADCAST	14	/* is host zero a broadcast addr? */
+#define	IPCTL_GIF_TTL		15	/* default TTL for gif encap packet */
+#define	IPCTL_LOWPORTMIN	16	/* minimum reserved port */
+#define	IPCTL_LOWPORTMAX	17	/* maximum reserved port */
+#define	IPCTL_MAXFRAGPACKETS	18	/* max packets reassembly queue */
+#define	IPCTL_GRE_TTL		19	/* default TTL for gre encap packet */
+#define	IPCTL_CHECKINTERFACE	20	/* drop pkts in from 'wrong' iface */
+#define	IPCTL_IFQ		21	/* IP packet input queue */
+#define	IPCTL_RANDOMID		22	/* use random IP ids (if configured) */
+#define	IPCTL_LOOPBACKCKSUM	23	/* do IP checksum on loopback */
 #define	IPCTL_STATS		24	/* IP statistics */
-#define	IPCTL_DAD_COUNT25	/* DAD packets to send */
+#define	IPCTL_DAD_COUNT		25	/* DAD packets to send */
 
 #endif /* _NETBSD_SOURCE */
 



CVS commit: src/sys/netinet

2023-06-15 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Fri Jun 16 03:02:30 UTC 2023

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

Log Message:
White space fixes. No binary changes.


To generate a diff of this commit:
cvs rdiff -u -r1.114 -r1.115 src/sys/netinet/in.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

2023-04-19 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Wed Apr 19 22:00:18 UTC 2023

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

Log Message:
Again allow multicast packets to be sent from unnumbered interfaces.


To generate a diff of this commit:
cvs rdiff -u -r1.325 -r1.326 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.325 src/sys/netinet/ip_output.c:1.326
--- src/sys/netinet/ip_output.c:1.325	Wed Apr 19 02:43:40 2023
+++ src/sys/netinet/ip_output.c	Wed Apr 19 22:00:18 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_output.c,v 1.325 2023/04/19 02:43:40 ozaki-r Exp $	*/
+/*	$NetBSD: ip_output.c,v 1.326 2023/04/19 22:00:18 mlelstv Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.325 2023/04/19 02:43:40 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.326 2023/04/19 22:00:18 mlelstv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -348,11 +348,6 @@ ip_output(struct mbuf *m0, struct mbuf *
 		}
 		mtu = ifp->if_mtu;
 		ia = in_get_ia_from_ifp_psref(ifp, _ia);
-		if (ia == NULL) {
-			IP_STATINC(IP_STAT_IFNOADDR);
-			error = EADDRNOTAVAIL;
-			goto bad;
-		}
 		if (IN_MULTICAST(ip->ip_dst.s_addr) ||
 		ip->ip_dst.s_addr == INADDR_BROADCAST) {
 			isbroadcast = 0;



CVS commit: src/sys/netinet

2023-04-19 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Wed Apr 19 22:00:18 UTC 2023

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

Log Message:
Again allow multicast packets to be sent from unnumbered interfaces.


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

2023-04-18 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Wed Apr 19 02:43:40 UTC 2023

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

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

The fix is mistakenly upstreamed.


To generate a diff of this commit:
cvs rdiff -u -r1.324 -r1.325 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.324 src/sys/netinet/ip_output.c:1.325
--- src/sys/netinet/ip_output.c:1.324	Mon Nov 21 09:51:13 2022
+++ src/sys/netinet/ip_output.c	Wed Apr 19 02:43:40 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_output.c,v 1.324 2022/11/21 09:51:13 knakahara Exp $	*/
+/*	$NetBSD: ip_output.c,v 1.325 2023/04/19 02:43:40 ozaki-r Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.324 2022/11/21 09:51:13 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.325 2023/04/19 02:43:40 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -531,15 +531,6 @@ 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);
@@ -591,15 +582,6 @@ 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

2023-04-18 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Wed Apr 19 02:43:40 UTC 2023

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

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

The fix is mistakenly upstreamed.


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

2023-04-07 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Fri Apr  7 06:44:08 UTC 2023

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

Log Message:
Select virtual address as sender if backing interface is anonymous.
Use correct scope for IPv6.


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

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

Modified files:

Index: src/sys/netinet/ip_carp.c
diff -u src/sys/netinet/ip_carp.c:1.118 src/sys/netinet/ip_carp.c:1.119
--- src/sys/netinet/ip_carp.c:1.118	Sun Mar 26 10:32:38 2023
+++ src/sys/netinet/ip_carp.c	Fri Apr  7 06:44:08 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_carp.c,v 1.118 2023/03/26 10:32:38 mlelstv Exp $	*/
+/*	$NetBSD: ip_carp.c,v 1.119 2023/04/07 06:44:08 mlelstv Exp $	*/
 /*	$OpenBSD: ip_carp.c,v 1.113 2005/11/04 08:11:54 mcbride Exp $	*/
 
 /*
@@ -33,7 +33,7 @@
 #endif
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip_carp.c,v 1.118 2023/03/26 10:32:38 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_carp.c,v 1.119 2023/04/07 06:44:08 mlelstv Exp $");
 
 /*
  * TODO:
@@ -1091,6 +1091,8 @@ carp_send_ad(void *v)
 		_s = pserialize_read_enter();
 		ifa = ifaof_ifpforaddr(, sc->sc_carpdev);
 		if (ifa == NULL)
+			ifa = ifaof_ifpforaddr(, >sc_if);
+		if (ifa == NULL)
 			ip->ip_src.s_addr = 0;
 		else
 			ip->ip_src.s_addr =
@@ -1142,6 +1144,7 @@ carp_send_ad(void *v)
 	if (sc->sc_naddrs6) {
 		struct ip6_hdr *ip6;
 		struct ifaddr *ifa;
+		struct ifnet *ifp;
 		int _s;
 
 		MGETHDR(m, M_DONTWAIT, MT_HEADER);
@@ -1168,7 +1171,12 @@ carp_send_ad(void *v)
 		memset(, 0, sizeof(sa));
 		sa.sa_family = AF_INET6;
 		_s = pserialize_read_enter();
-		ifa = ifaof_ifpforaddr(, sc->sc_carpdev);
+		ifp = sc->sc_carpdev;
+		ifa = ifaof_ifpforaddr(, ifp);
+		if (ifa == NULL) {	/* This should never happen with IPv6 */
+			ifp = >sc_if;
+			ifa = ifaof_ifpforaddr(, ifp);
+		}
 		if (ifa == NULL)	/* This should never happen with IPv6 */
 			memset(>ip6_src, 0, sizeof(struct in6_addr));
 		else
@@ -1179,7 +1187,7 @@ carp_send_ad(void *v)
 
 		ip6->ip6_dst.s6_addr16[0] = htons(0xff02);
 		ip6->ip6_dst.s6_addr8[15] = 0x12;
-		if (in6_setscope(>ip6_dst, >sc_if, NULL) != 0) {
+		if (in6_setscope(>ip6_dst, ifp, NULL) != 0) {
 			if_statinc(>sc_if, if_oerrors);
 			m_freem(m);
 			CARP_LOG(sc, ("in6_setscope failed"));



CVS commit: src/sys/netinet

2023-04-07 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Fri Apr  7 06:44:08 UTC 2023

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

Log Message:
Select virtual address as sender if backing interface is anonymous.
Use correct scope for IPv6.


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

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



CVS commit: src/sys/netinet

2023-03-26 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun Mar 26 10:32:38 UTC 2023

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

Log Message:
Use backing device to send advertisements. Otherwise the packets originate
from the virtual MAC address, which confuses switches.


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

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



CVS commit: src/sys/netinet

2023-03-26 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun Mar 26 10:32:38 UTC 2023

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

Log Message:
Use backing device to send advertisements. Otherwise the packets originate
from the virtual MAC address, which confuses switches.


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

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

Modified files:

Index: src/sys/netinet/ip_carp.c
diff -u src/sys/netinet/ip_carp.c:1.117 src/sys/netinet/ip_carp.c:1.118
--- src/sys/netinet/ip_carp.c:1.117	Fri Sep  2 23:48:11 2022
+++ src/sys/netinet/ip_carp.c	Sun Mar 26 10:32:38 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_carp.c,v 1.117 2022/09/02 23:48:11 thorpej Exp $	*/
+/*	$NetBSD: ip_carp.c,v 1.118 2023/03/26 10:32:38 mlelstv Exp $	*/
 /*	$OpenBSD: ip_carp.c,v 1.113 2005/11/04 08:11:54 mcbride Exp $	*/
 
 /*
@@ -33,7 +33,7 @@
 #endif
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip_carp.c,v 1.117 2022/09/02 23:48:11 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_carp.c,v 1.118 2023/03/26 10:32:38 mlelstv Exp $");
 
 /*
  * TODO:
@@ -1876,6 +1876,9 @@ carp_join_multicast(struct carp_softc *s
 	struct ip_moptions *imo = >sc_imo, tmpimo;
 	struct in_addr addr;
 
+	if (sc->sc_carpdev == NULL)
+		return (ENETDOWN);
+
 	memset(, 0, sizeof(tmpimo));
 	addr.s_addr = INADDR_CARP_GROUP;
 	if ((tmpimo.imo_membership[0] =
@@ -1885,7 +1888,7 @@ carp_join_multicast(struct carp_softc *s
 
 	imo->imo_membership[0] = tmpimo.imo_membership[0];
 	imo->imo_num_memberships = 1;
-	imo->imo_multicast_if_index = sc->sc_if.if_index;
+	imo->imo_multicast_if_index = sc->sc_carpdev->if_index;
 	imo->imo_multicast_ttl = CARP_DFLTTL;
 	imo->imo_multicast_loop = 0;
 	return (0);
@@ -1970,6 +1973,9 @@ carp_join_multicast6(struct carp_softc *
 	struct sockaddr_in6 addr6;
 	int error;
 
+	if (sc->sc_carpdev == NULL)
+		return (ENETDOWN);
+
 	/* Join IPv6 CARP multicast group */
 	memset(, 0, sizeof(addr6));
 	addr6.sin6_family = AF_INET6;
@@ -1996,7 +2002,7 @@ carp_join_multicast6(struct carp_softc *
 	}
 
 	/* apply v6 multicast membership */
-	im6o->im6o_multicast_if_index = sc->sc_if.if_index;
+	im6o->im6o_multicast_if_index = sc->sc_carpdev->if_index;
 	if (imm)
 		LIST_INSERT_HEAD(>im6o_memberships, imm,
 		i6mm_chain);



CVS commit: src/sys/netinet

2022-12-11 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun Dec 11 08:09:20 UTC 2022

Modified Files:
src/sys/netinet: tcp_vtw.h

Log Message:
Need larger fat pointers for 128bit cache lines.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/netinet/tcp_vtw.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-11 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun Dec 11 08:09:20 UTC 2022

Modified Files:
src/sys/netinet: tcp_vtw.h

Log Message:
Need larger fat pointers for 128bit cache lines.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/netinet/tcp_vtw.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/tcp_vtw.h
diff -u src/sys/netinet/tcp_vtw.h:1.9 src/sys/netinet/tcp_vtw.h:1.10
--- src/sys/netinet/tcp_vtw.h:1.9	Thu Apr 19 21:21:44 2018
+++ src/sys/netinet/tcp_vtw.h	Sun Dec 11 08:09:20 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_vtw.h,v 1.9 2018/04/19 21:21:44 christos Exp $	*/
+/*	$NetBSD: tcp_vtw.h,v 1.10 2022/12/11 08:09:20 mlelstv Exp $	*/
 /*
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -151,7 +151,11 @@
  */
 struct fatp_mi;
 
+#if CACHE_LINE_SIZE == 128
+typedef uint64_t fatp_word_t;
+#else
 typedef uint32_t fatp_word_t;
+#endif
 
 typedef struct fatp_mi	fatp_t;
 
@@ -161,7 +165,7 @@ typedef struct fatp_mi	fatp_t;
 #define	FATP_NTAGS	(CACHE_LINE_SIZE / sizeof(fatp_word_t) - 1)
 #define	FATP_NXT_WIDTH	(sizeof(fatp_word_t) * NBBY - FATP_NTAGS)
 
-#define	FATP_MAX	(1 << FATP_NXT_WIDTH)
+#define	FATP_MAX	(1 << (FATP_NXT_WIDTH < 31 ? FATP_NXT_WIDTH : 31))
 
 /* Worked example: ULP32 with 64-byte cacheline (32-bit x86):
  * 15 tags per cacheline.  At most 2^17 fat pointers per fatp_ctl_t.



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/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/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();



CVS commit: src/sys/netinet

2022-11-15 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Tue Nov 15 09:15:44 UTC 2022

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

Log Message:
Revert prior.


To generate a diff of this commit:
cvs rdiff -u -r1.309 -r1.310 src/sys/netinet/if_arp.c

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

Modified files:

Index: src/sys/netinet/if_arp.c
diff -u src/sys/netinet/if_arp.c:1.309 src/sys/netinet/if_arp.c:1.310
--- src/sys/netinet/if_arp.c:1.309	Mon Nov 14 09:32:21 2022
+++ src/sys/netinet/if_arp.c	Tue Nov 15 09:15:43 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_arp.c,v 1.309 2022/11/14 09:32:21 roy Exp $	*/
+/*	$NetBSD: if_arp.c,v 1.310 2022/11/15 09:15:43 roy Exp $	*/
 
 /*
  * Copyright (c) 1998, 2000, 2008 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.309 2022/11/14 09:32:21 roy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.310 2022/11/15 09:15:43 roy Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -932,8 +932,6 @@ again:
 
 	/*
 	 * DAD check, RFC 5227.
-	 * ARP sender hardware address must match the interface
-	 * address of the interface sending the packet.
 	 * Collision on sender address is always a duplicate.
 	 * Collision on target address is only a duplicate
 	 * IF the sender address is the null host (ie a DAD probe)
@@ -945,10 +943,7 @@ again:
 	(in_hosteq(isaddr, myaddr) ||
 	(in_nullhost(isaddr) && in_hosteq(itaddr, myaddr) &&
 	 m->m_flags & M_BCAST &&
-	 ia->ia4_flags & (IN_IFF_TENTATIVE | IN_IFF_DUPLICATED))) &&
-	m->m_pkthdr.l2_shalen == ah->ar_hln && (
-	ah->ar_hln == 0 ||
-	memcmp(m->m_pkthdr.l2_sha, ar_sha(ah), ah->ar_hln) == 0))
+	 ia->ia4_flags & (IN_IFF_TENTATIVE | IN_IFF_DUPLICATED
 	{
 		struct sockaddr_dl sdl, *sdlp;
 



CVS commit: src/sys/netinet

2022-11-15 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Tue Nov 15 09:15:44 UTC 2022

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

Log Message:
Revert prior.


To generate a diff of this commit:
cvs rdiff -u -r1.309 -r1.310 src/sys/netinet/if_arp.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-14 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Mon Nov 14 09:32:21 UTC 2022

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

Log Message:
arp: Validate L2 sender hardware address matches ARP probe

RFC 5227 section 1.1 states that for a DaD ARP probe the sender hardware
address must match the hardware address of the interface sending the
packet.

We can now verify this by checking the mbuf packet header.

This fixes an obsure issue where an old router was sending out bogus
ARP probes.


To generate a diff of this commit:
cvs rdiff -u -r1.308 -r1.309 src/sys/netinet/if_arp.c

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

Modified files:

Index: src/sys/netinet/if_arp.c
diff -u src/sys/netinet/if_arp.c:1.308 src/sys/netinet/if_arp.c:1.309
--- src/sys/netinet/if_arp.c:1.308	Sat Sep  3 01:35:03 2022
+++ src/sys/netinet/if_arp.c	Mon Nov 14 09:32:21 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_arp.c,v 1.308 2022/09/03 01:35:03 thorpej Exp $	*/
+/*	$NetBSD: if_arp.c,v 1.309 2022/11/14 09:32:21 roy Exp $	*/
 
 /*
  * Copyright (c) 1998, 2000, 2008 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.308 2022/09/03 01:35:03 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.309 2022/11/14 09:32:21 roy Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -932,6 +932,8 @@ again:
 
 	/*
 	 * DAD check, RFC 5227.
+	 * ARP sender hardware address must match the interface
+	 * address of the interface sending the packet.
 	 * Collision on sender address is always a duplicate.
 	 * Collision on target address is only a duplicate
 	 * IF the sender address is the null host (ie a DAD probe)
@@ -943,7 +945,10 @@ again:
 	(in_hosteq(isaddr, myaddr) ||
 	(in_nullhost(isaddr) && in_hosteq(itaddr, myaddr) &&
 	 m->m_flags & M_BCAST &&
-	 ia->ia4_flags & (IN_IFF_TENTATIVE | IN_IFF_DUPLICATED
+	 ia->ia4_flags & (IN_IFF_TENTATIVE | IN_IFF_DUPLICATED))) &&
+	m->m_pkthdr.l2_shalen == ah->ar_hln && (
+	ah->ar_hln == 0 ||
+	memcmp(m->m_pkthdr.l2_sha, ar_sha(ah), ah->ar_hln) == 0))
 	{
 		struct sockaddr_dl sdl, *sdlp;
 



CVS commit: src/sys/netinet

2022-11-14 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Mon Nov 14 09:32:21 UTC 2022

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

Log Message:
arp: Validate L2 sender hardware address matches ARP probe

RFC 5227 section 1.1 states that for a DaD ARP probe the sender hardware
address must match the hardware address of the interface sending the
packet.

We can now verify this by checking the mbuf packet header.

This fixes an obsure issue where an old router was sending out bogus
ARP probes.


To generate a diff of this commit:
cvs rdiff -u -r1.308 -r1.309 src/sys/netinet/if_arp.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-04 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Fri Nov  4 09:05:41 UTC 2022

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

Log Message:
ipcb: add/update the description of functions

>From rmind-smpnet patches


To generate a diff of this commit:
cvs rdiff -u -r1.201 -r1.202 src/sys/netinet/in_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/sys/netinet/in_pcb.c
diff -u src/sys/netinet/in_pcb.c:1.201 src/sys/netinet/in_pcb.c:1.202
--- src/sys/netinet/in_pcb.c:1.201	Fri Nov  4 09:05:04 2022
+++ src/sys/netinet/in_pcb.c	Fri Nov  4 09:05:41 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: in_pcb.c,v 1.201 2022/11/04 09:05:04 ozaki-r Exp $	*/
+/*	$NetBSD: in_pcb.c,v 1.202 2022/11/04 09:05:41 ozaki-r Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -93,7 +93,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in_pcb.c,v 1.201 2022/11/04 09:05:04 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in_pcb.c,v 1.202 2022/11/04 09:05:41 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -192,6 +192,10 @@ inpcb_init(struct inpcbtable *table, int
 	RUN_ONCE(, inpcb_poolinit);
 }
 
+/*
+ * inpcb_create: construct a new PCB and associated with a given socket.
+ * Sets the PCB state to INP_ATTACHED and makes PCB globally visible.
+ */
 int
 inpcb_create(struct socket *so, void *v)
 {
@@ -462,6 +466,14 @@ inpcb_bind_port(struct inpcb *inp, struc
 	return 0;
 }
 
+/*
+ * inpcb_bind: assign a local IP address and port number to the PCB.
+ *
+ * If the address is not a wildcard, verify that it corresponds to a
+ * local interface.  If a port is specified and it is privileged, then
+ * check the permission.  Check whether the address or port is in use,
+ * and if so, whether we can re-use them.
+ */
 int
 inpcb_bind(void *v, struct sockaddr_in *sin, struct lwp *l)
 {
@@ -501,10 +513,11 @@ inpcb_bind(void *v, struct sockaddr_in *
 }
 
 /*
- * Connect from a socket to a specified address.
- * Both address and port must be specified in argument sin.
- * If don't have a local address for this socket yet,
- * then pick one.
+ * inpcb_connect: connect from a socket to a specified address, i.e.,
+ * assign a foreign IP address and port number to the PCB.
+ *
+ * Both address and port must be specified in the name argument.
+ * If there is no local address for this socket yet, then pick one.
  */
 int
 inpcb_connect(void *v, struct sockaddr_in *sin, struct lwp *l)
@@ -638,6 +651,11 @@ inpcb_connect(void *v, struct sockaddr_i
 	return 0;
 }
 
+/*
+ * inpcb_disconnect: remove any foreign IP/port association.
+ *
+ * Note: destroys the PCB if socket was closed.
+ */
 void
 inpcb_disconnect(void *v)
 {
@@ -657,6 +675,9 @@ inpcb_disconnect(void *v)
 		inpcb_destroy(inp);
 }
 
+/*
+ * inpcb_destroy: destroy PCB as well as the associated socket.
+ */
 void
 inpcb_destroy(void *v)
 {
@@ -706,6 +727,9 @@ inpcb_destroy(void *v)
 	mutex_enter(softnet_lock);	/* reacquire the softnet_lock */
 }
 
+/*
+ * inpcb_fetch_sockaddr: fetch the local IP address and port number.
+ */
 void
 inpcb_fetch_sockaddr(struct inpcb *inp, struct sockaddr_in *sin)
 {
@@ -716,6 +740,9 @@ inpcb_fetch_sockaddr(struct inpcb *inp, 
 	sockaddr_in_init(sin, _laddr(inp), inp->inp_lport);
 }
 
+/*
+ * inpcb_fetch_peeraddr: fetch the foreign IP address and port number.
+ */
 void
 inpcb_fetch_peeraddr(struct inpcb *inp, struct sockaddr_in *sin)
 {
@@ -727,13 +754,14 @@ inpcb_fetch_peeraddr(struct inpcb *inp, 
 }
 
 /*
- * Pass some notification to all connections of a protocol
- * associated with address dst.  The local address and/or port numbers
- * may be specified to limit the search.  The "usual action" will be
- * taken, depending on the ctlinput cmd.  The caller must filter any
- * cmds that are uninteresting (e.g., no error in the map).
- * Call the protocol specific routine (if any) to report
- * any errors for each matching socket.
+ * inpcb_notify: pass some notification to all connections of a protocol
+ * associated with destination address.  The local address and/or port
+ * numbers may be specified to limit the search.  The "usual action" will
+ * be taken, depending on the command.
+ *
+ * The caller must filter any commands that are not interesting (e.g.,
+ * no error in the map).  Call the protocol specific routine (if any) to
+ * report any errors for each matching socket.
  *
  * Must be called at splsoftnet.
  */
@@ -859,10 +887,10 @@ inpcb_purgeif(struct inpcbtable *table, 
 }
 
 /*
- * Check for alternatives when higher level complains
- * about service problems.  For now, invalidate cached
- * routing information.  If the route was created dynamically
- * (by a redirect), time to try a default gateway again.
+ * inpcb_losing: check for alternatives when higher level complains about
+ * service problems.  For now, invalidate cached routing information.
+ * If the route was created dynamically (by a redirect), time to 

CVS commit: src/sys/netinet

2022-11-04 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Fri Nov  4 09:05:41 UTC 2022

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

Log Message:
ipcb: add/update the description of functions

>From rmind-smpnet patches


To generate a diff of this commit:
cvs rdiff -u -r1.201 -r1.202 src/sys/netinet/in_pcb.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-04 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Fri Nov  4 09:05:04 UTC 2022

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

Log Message:
inpcb: replace leading white spaces with tabs


To generate a diff of this commit:
cvs rdiff -u -r1.200 -r1.201 src/sys/netinet/in_pcb.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-04 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Fri Nov  4 09:05:04 UTC 2022

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

Log Message:
inpcb: replace leading white spaces with tabs


To generate a diff of this commit:
cvs rdiff -u -r1.200 -r1.201 src/sys/netinet/in_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/sys/netinet/in_pcb.c
diff -u src/sys/netinet/in_pcb.c:1.200 src/sys/netinet/in_pcb.c:1.201
--- src/sys/netinet/in_pcb.c:1.200	Fri Nov  4 09:04:27 2022
+++ src/sys/netinet/in_pcb.c	Fri Nov  4 09:05:04 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: in_pcb.c,v 1.200 2022/11/04 09:04:27 ozaki-r Exp $	*/
+/*	$NetBSD: in_pcb.c,v 1.201 2022/11/04 09:05:04 ozaki-r Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -93,7 +93,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in_pcb.c,v 1.200 2022/11/04 09:04:27 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in_pcb.c,v 1.201 2022/11/04 09:05:04 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -619,15 +619,15 @@ inpcb_connect(void *v, struct sockaddr_i
 	in4p_faddr(inp) = sin->sin_addr;
 	inp->inp_fport = sin->sin_port;
 
-/* Late bind, if needed */
+	/* Late bind, if needed */
 	if (inp->inp_bindportonsend) {
-   struct sockaddr_in lsin = *((const struct sockaddr_in *)
+		struct sockaddr_in lsin = *((const struct sockaddr_in *)
 		inp->inp_socket->so_proto->pr_domain->dom_sa_any);
 		lsin.sin_addr = in4p_laddr(inp);
 		lsin.sin_port = 0;
 
 		if ((error = inpcb_bind_port(inp, , l->l_cred)) != 0)
-   return error;
+			return error;
 	}
 
 	inpcb_set_state(inp, INP_CONNECTED);



CVS commit: src/sys/netinet

2022-11-04 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Fri Nov  4 09:03:56 UTC 2022

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

Log Message:
inpcb: use NULL


To generate a diff of this commit:
cvs rdiff -u -r1.198 -r1.199 src/sys/netinet/in_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/sys/netinet/in_pcb.c
diff -u src/sys/netinet/in_pcb.c:1.198 src/sys/netinet/in_pcb.c:1.199
--- src/sys/netinet/in_pcb.c:1.198	Fri Nov  4 09:03:20 2022
+++ src/sys/netinet/in_pcb.c	Fri Nov  4 09:03:56 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: in_pcb.c,v 1.198 2022/11/04 09:03:20 ozaki-r Exp $	*/
+/*	$NetBSD: in_pcb.c,v 1.199 2022/11/04 09:03:56 ozaki-r Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -93,7 +93,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in_pcb.c,v 1.198 2022/11/04 09:03:20 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in_pcb.c,v 1.199 2022/11/04 09:03:56 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -747,7 +747,7 @@ inpcb_notify(struct inpcbtable *table, s
 	in_port_t fport = fport_arg, lport = lport_arg;
 	int nmatch;
 
-	if (in_nullhost(faddr) || notify == 0)
+	if (in_nullhost(faddr) || notify == NULL)
 		return (0);
 
 	nmatch = 0;
@@ -773,7 +773,7 @@ inpcb_notifyall(struct inpcbtable *table
 {
 	struct inpcb *inp;
 
-	if (in_nullhost(faddr) || notify == 0)
+	if (in_nullhost(faddr) || notify == NULL)
 		return;
 
 	TAILQ_FOREACH(inp, >inpt_queue, inp_queue) {



CVS commit: src/sys/netinet

2022-11-04 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Fri Nov  4 09:03:56 UTC 2022

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

Log Message:
inpcb: use NULL


To generate a diff of this commit:
cvs rdiff -u -r1.198 -r1.199 src/sys/netinet/in_pcb.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-04 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Fri Nov  4 09:02:38 UTC 2022

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

Log Message:
inpcb: use pool_cache instead of pool


To generate a diff of this commit:
cvs rdiff -u -r1.196 -r1.197 src/sys/netinet/in_pcb.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-04 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Fri Nov  4 09:02:38 UTC 2022

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

Log Message:
inpcb: use pool_cache instead of pool


To generate a diff of this commit:
cvs rdiff -u -r1.196 -r1.197 src/sys/netinet/in_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/sys/netinet/in_pcb.c
diff -u src/sys/netinet/in_pcb.c:1.196 src/sys/netinet/in_pcb.c:1.197
--- src/sys/netinet/in_pcb.c:1.196	Fri Nov  4 09:01:53 2022
+++ src/sys/netinet/in_pcb.c	Fri Nov  4 09:02:38 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: in_pcb.c,v 1.196 2022/11/04 09:01:53 ozaki-r Exp $	*/
+/*	$NetBSD: in_pcb.c,v 1.197 2022/11/04 09:02:38 ozaki-r Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -93,7 +93,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in_pcb.c,v 1.196 2022/11/04 09:01:53 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in_pcb.c,v 1.197 2022/11/04 09:02:38 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -156,20 +156,20 @@ int	anonportmax = IPPORT_ANONMAX;
 int	lowportmin  = IPPORT_RESERVEDMIN;
 int	lowportmax  = IPPORT_RESERVEDMAX;
 
-static struct pool in4pcb_pool;
+static pool_cache_t	in4pcb_pool_cache;
 #ifdef INET6
-static struct pool in6pcb_pool;
+static pool_cache_t	in6pcb_pool_cache;
 #endif
 
 static int
 inpcb_poolinit(void)
 {
 
-	pool_init(_pool, sizeof(struct in4pcb), 0, 0, 0, "in4pcbpl", NULL,
-	IPL_NET);
+	in4pcb_pool_cache = pool_cache_init(sizeof(struct in4pcb), coherency_unit,
+	0, 0, "in4pcbpl", NULL, IPL_NET, NULL, NULL, NULL);
 #ifdef INET6
-	pool_init(_pool, sizeof(struct in6pcb), 0, 0, 0, "in6pcbpl", NULL,
-	IPL_NET);
+	in6pcb_pool_cache = pool_cache_init(sizeof(struct in6pcb), coherency_unit,
+	0, 0, "in6pcbpl", NULL, IPL_NET, NULL, NULL, NULL);
 #endif
 	return 0;
 }
@@ -203,22 +203,26 @@ inpcb_create(struct socket *so, void *v)
 	KASSERT(soaf(so) == AF_INET || soaf(so) == AF_INET6);
 
 	if (soaf(so) == AF_INET)
-		inp = pool_get(_pool, PR_NOWAIT|PR_ZERO);
+		inp = pool_cache_get(in4pcb_pool_cache, PR_NOWAIT);
 	else
-		inp = pool_get(_pool, PR_NOWAIT|PR_ZERO);
+		inp = pool_cache_get(in6pcb_pool_cache, PR_NOWAIT);
 #else
 	KASSERT(soaf(so) == AF_INET);
-	inp = pool_get(_pool, PR_NOWAIT|PR_ZERO);
+	inp = pool_cache_get(in4pcb_pool_cache, PR_NOWAIT);
 #endif
 	if (inp == NULL)
 		return (ENOBUFS);
+	if (soaf(so) == AF_INET)
+		memset(inp, 0, sizeof(struct in4pcb));
+#ifdef INET6
+	else
+		memset(inp, 0, sizeof(struct in6pcb));
+#endif
 	inp->inp_af = soaf(so);
 	inp->inp_table = table;
 	inp->inp_socket = so;
 	inp->inp_portalgo = PORTALGO_DEFAULT;
 	inp->inp_bindportonsend = false;
-	inp->inp_overudp_cb = NULL;
-	inp->inp_overudp_arg = NULL;
 
 	if (inp->inp_af == AF_INET) {
 		in4p_errormtu(inp) = -1;
@@ -237,12 +241,12 @@ inpcb_create(struct socket *so, void *v)
 		if (error != 0) {
 #ifdef INET6
 			if (inp->inp_af == AF_INET)
-pool_put(_pool, inp);
+pool_cache_put(in4pcb_pool_cache, inp);
 			else
-pool_put(_pool, inp);
+pool_cache_put(in6pcb_pool_cache, inp);
 #else
 			KASSERT(inp->inp_af == AF_INET);
-			pool_put(_pool, inp);
+			pool_cache_put(in4pcb_pool_cache, inp);
 #endif
 			return error;
 		}
@@ -692,12 +696,12 @@ inpcb_destroy(void *v)
 
 #ifdef INET6
 	if (inp->inp_af == AF_INET)
-		pool_put(_pool, inp);
+		pool_cache_put(in4pcb_pool_cache, inp);
 	else
-		pool_put(_pool, inp);
+		pool_cache_put(in6pcb_pool_cache, inp);
 #else
 	KASSERT(inp->inp_af == AF_INET);
-	pool_put(_pool, inp);
+	pool_cache_put(in4pcb_pool_cache, inp);
 #endif
 	mutex_enter(softnet_lock);	/* reacquire the softnet_lock */
 }



CVS commit: src/sys/netinet

2022-10-30 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Mon Oct 31 00:56:33 UTC 2022

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

Log Message:
tcp: fix wrong logic in tcp_drop

Pointed out by mlelstv@


To generate a diff of this commit:
cvs rdiff -u -r1.293 -r1.294 src/sys/netinet/tcp_subr.c

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/tcp_subr.c
diff -u src/sys/netinet/tcp_subr.c:1.293 src/sys/netinet/tcp_subr.c:1.294
--- src/sys/netinet/tcp_subr.c:1.293	Fri Oct 28 05:25:36 2022
+++ src/sys/netinet/tcp_subr.c	Mon Oct 31 00:56:33 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_subr.c,v 1.293 2022/10/28 05:25:36 ozaki-r Exp $	*/
+/*	$NetBSD: tcp_subr.c,v 1.294 2022/10/31 00:56:33 ozaki-r Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tcp_subr.c,v 1.293 2022/10/28 05:25:36 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_subr.c,v 1.294 2022/10/31 00:56:33 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1022,7 +1022,7 @@ tcp_drop(struct tcpcb *tp, int errno)
 	KASSERT(tp->t_inpcb != NULL);
 
 	so = tp->t_inpcb->inp_socket;
-	if (so != NULL)
+	if (so == NULL)
 		return NULL;
 
 	if (TCPS_HAVERCVDSYN(tp->t_state)) {



CVS commit: src/sys/netinet

2022-10-30 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Mon Oct 31 00:56:33 UTC 2022

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

Log Message:
tcp: fix wrong logic in tcp_drop

Pointed out by mlelstv@


To generate a diff of this commit:
cvs rdiff -u -r1.293 -r1.294 src/sys/netinet/tcp_subr.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-10-30 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Sun Oct 30 08:45:46 UTC 2022

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

Log Message:
tcp: restore NULL check for inp in tcp_ctloutput


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

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



CVS commit: src/sys/netinet

2022-10-30 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Sun Oct 30 08:45:46 UTC 2022

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

Log Message:
tcp: restore NULL check for inp in tcp_ctloutput


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

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

Modified files:

Index: src/sys/netinet/tcp_usrreq.c
diff -u src/sys/netinet/tcp_usrreq.c:1.235 src/sys/netinet/tcp_usrreq.c:1.236
--- src/sys/netinet/tcp_usrreq.c:1.235	Sat Oct 29 15:35:16 2022
+++ src/sys/netinet/tcp_usrreq.c	Sun Oct 30 08:45:46 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_usrreq.c,v 1.235 2022/10/29 15:35:16 ozaki-r Exp $	*/
+/*	$NetBSD: tcp_usrreq.c,v 1.236 2022/10/30 08:45:46 ozaki-r Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -99,7 +99,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tcp_usrreq.c,v 1.235 2022/10/29 15:35:16 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_usrreq.c,v 1.236 2022/10/30 08:45:46 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -272,6 +272,10 @@ tcp_ctloutput(int op, struct socket *so,
 
 	s = splsoftnet();
 	inp = sotoinpcb(so);
+	if (inp == NULL) {
+		splx(s);
+		return ECONNRESET;
+	}
 	if (level != IPPROTO_TCP) {
 		switch (family) {
 		case PF_INET:



CVS commit: src/sys/netinet

2022-10-29 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Sat Oct 29 15:35:17 UTC 2022

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

Log Message:
tcp: restore NULL checks for inp


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

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

Modified files:

Index: src/sys/netinet/tcp_usrreq.c
diff -u src/sys/netinet/tcp_usrreq.c:1.234 src/sys/netinet/tcp_usrreq.c:1.235
--- src/sys/netinet/tcp_usrreq.c:1.234	Fri Oct 28 05:25:36 2022
+++ src/sys/netinet/tcp_usrreq.c	Sat Oct 29 15:35:16 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_usrreq.c,v 1.234 2022/10/28 05:25:36 ozaki-r Exp $	*/
+/*	$NetBSD: tcp_usrreq.c,v 1.235 2022/10/29 15:35:16 ozaki-r Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -99,7 +99,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tcp_usrreq.c,v 1.234 2022/10/28 05:25:36 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_usrreq.c,v 1.235 2022/10/29 15:35:16 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -502,6 +502,8 @@ tcp_detach(struct socket *so)
 	int s;
 
 	inp = sotoinpcb(so);
+	if (inp == NULL)
+		return;
 	tp = intotcpcb(inp);
 
 	s = splsoftnet();
@@ -518,6 +520,8 @@ tcp_accept(struct socket *so, struct soc
 	int s;
 
 	inp = sotoinpcb(so);
+	if (inp == NULL)
+		return EINVAL;
 	tp = intotcpcb(inp);
 
 	ostate = tcp_debug_capture(tp, PRU_ACCEPT);
@@ -556,6 +560,8 @@ tcp_bind(struct socket *so, struct socka
 	int ostate = 0;
 
 	inp = sotoinpcb(so);
+	if (inp == NULL)
+		return EINVAL;
 	tp = intotcpcb(inp);
 
 	ostate = tcp_debug_capture(tp, PRU_BIND);
@@ -597,6 +603,8 @@ tcp_listen(struct socket *so, struct lwp
 	int s;
 
 	inp = sotoinpcb(so);
+	if (inp == NULL)
+		return EINVAL;
 	tp = intotcpcb(inp);
 
 	ostate = tcp_debug_capture(tp, PRU_LISTEN);
@@ -636,6 +644,8 @@ tcp_connect(struct socket *so, struct so
 	int ostate = 0;
 
 	inp = sotoinpcb(so);
+	if (inp == NULL)
+		return EINVAL;
 	tp = intotcpcb(inp);
 
 	ostate = tcp_debug_capture(tp, PRU_CONNECT);
@@ -719,6 +729,8 @@ tcp_connect2(struct socket *so, struct s
 	KASSERT(solocked(so));
 
 	inp = sotoinpcb(so);
+	if (inp == NULL)
+		return EINVAL;
 	tp = intotcpcb(inp);
 
 	ostate = tcp_debug_capture(tp, PRU_CONNECT2);
@@ -738,6 +750,8 @@ tcp_disconnect(struct socket *so)
 	int s;
 
 	inp = sotoinpcb(so);
+	if (inp == NULL)
+		return EINVAL;
 	tp = intotcpcb(inp);
 
 	ostate = tcp_debug_capture(tp, PRU_DISCONNECT);
@@ -771,6 +785,8 @@ tcp_shutdown(struct socket *so)
 	int s;
 
 	inp = sotoinpcb(so);
+	if (inp == NULL)
+		return EINVAL;
 	tp = intotcpcb(inp);
 
 	ostate = tcp_debug_capture(tp, PRU_SHUTDOWN);
@@ -798,6 +814,8 @@ tcp_abort(struct socket *so)
 	int s;
 
 	inp = sotoinpcb(so);
+	if (inp == NULL)
+		return EINVAL;
 	tp = intotcpcb(inp);
 
 	ostate = tcp_debug_capture(tp, PRU_ABORT);
@@ -846,6 +864,8 @@ tcp_peeraddr(struct socket *so, struct s
 	int s;
 
 	inp = sotoinpcb(so);
+	if (inp == NULL)
+		return EINVAL;
 	tp = intotcpcb(inp);
 
 	ostate = tcp_debug_capture(tp, PRU_PEERADDR);
@@ -874,6 +894,8 @@ tcp_sockaddr(struct socket *so, struct s
 	int s;
 
 	inp = sotoinpcb(so);
+	if (inp == NULL)
+		return EINVAL;
 	tp = intotcpcb(inp);
 
 	ostate = tcp_debug_capture(tp, PRU_SOCKADDR);
@@ -902,6 +924,8 @@ tcp_rcvd(struct socket *so, int flags, s
 	int s;
 
 	inp = sotoinpcb(so);
+	if (inp == NULL)
+		return EINVAL;
 	tp = intotcpcb(inp);
 
 	ostate = tcp_debug_capture(tp, PRU_RCVD);
@@ -934,6 +958,8 @@ tcp_recvoob(struct socket *so, struct mb
 	int s;
 
 	inp = sotoinpcb(so);
+	if (inp == NULL)
+		return EINVAL;
 	tp = intotcpcb(inp);
 
 	ostate = tcp_debug_capture(tp, PRU_RCVOOB);
@@ -976,6 +1002,8 @@ tcp_send(struct socket *so, struct mbuf 
 	int s;
 
 	inp = sotoinpcb(so);
+	if (inp == NULL)
+		return EINVAL;
 	tp = intotcpcb(inp);
 
 	ostate = tcp_debug_capture(tp, PRU_SEND);
@@ -1011,6 +1039,11 @@ tcp_sendoob(struct socket *so, struct mb
 	int s;
 
 	inp = sotoinpcb(so);
+	if (inp == NULL) {
+		m_freem(m);
+		m_freem(control);
+		return EINVAL;
+	}
 	tp = intotcpcb(inp);
 	if (tp->t_template == NULL) {
 		/*



CVS commit: src/sys/netinet

2022-10-29 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Sat Oct 29 15:35:17 UTC 2022

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

Log Message:
tcp: restore NULL checks for inp


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

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



CVS commit: src/sys/netinet

2022-10-28 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Sat Oct 29 02:56:29 UTC 2022

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

Log Message:
inpcb: fix for kernels without INET6


To generate a diff of this commit:
cvs rdiff -u -r1.193 -r1.194 src/sys/netinet/in_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/sys/netinet/in_pcb.c
diff -u src/sys/netinet/in_pcb.c:1.193 src/sys/netinet/in_pcb.c:1.194
--- src/sys/netinet/in_pcb.c:1.193	Fri Oct 28 05:25:36 2022
+++ src/sys/netinet/in_pcb.c	Sat Oct 29 02:56:29 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: in_pcb.c,v 1.193 2022/10/28 05:25:36 ozaki-r Exp $	*/
+/*	$NetBSD: in_pcb.c,v 1.194 2022/10/29 02:56:29 ozaki-r Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -93,7 +93,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in_pcb.c,v 1.193 2022/10/28 05:25:36 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in_pcb.c,v 1.194 2022/10/29 02:56:29 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -157,7 +157,9 @@ int	lowportmin  = IPPORT_RESERVEDMIN;
 int	lowportmax  = IPPORT_RESERVEDMAX;
 
 static struct pool in4pcb_pool;
+#ifdef INET6
 static struct pool in6pcb_pool;
+#endif
 
 static int
 inpcb_poolinit(void)
@@ -165,8 +167,10 @@ inpcb_poolinit(void)
 
 	pool_init(_pool, sizeof(struct in4pcb), 0, 0, 0, "in4pcbpl", NULL,
 	IPL_NET);
+#ifdef INET6
 	pool_init(_pool, sizeof(struct in6pcb), 0, 0, 0, "in6pcbpl", NULL,
 	IPL_NET);
+#endif
 	return 0;
 }
 
@@ -195,12 +199,17 @@ in_pcballoc(struct socket *so, void *v)
 	struct inpcb *inp;
 	int s;
 
+#ifdef INET6
 	KASSERT(soaf(so) == AF_INET || soaf(so) == AF_INET6);
 
 	if (soaf(so) == AF_INET)
 		inp = pool_get(_pool, PR_NOWAIT|PR_ZERO);
 	else
 		inp = pool_get(_pool, PR_NOWAIT|PR_ZERO);
+#else
+	KASSERT(soaf(so) == AF_INET);
+	inp = pool_get(_pool, PR_NOWAIT|PR_ZERO);
+#endif
 	if (inp == NULL)
 		return (ENOBUFS);
 	inp->inp_af = soaf(so);
@@ -226,10 +235,15 @@ in_pcballoc(struct socket *so, void *v)
 	if (ipsec_enabled) {
 		int error = ipsec_init_pcbpolicy(so, >inp_sp);
 		if (error != 0) {
+#ifdef INET6
 			if (inp->inp_af == AF_INET)
 pool_put(_pool, inp);
 			else
 pool_put(_pool, inp);
+#else
+			KASSERT(inp->inp_af == AF_INET);
+			pool_put(_pool, inp);
+#endif
 			return error;
 		}
 		inp->inp_sp->sp_inp = inp;
@@ -665,6 +679,7 @@ in_pcbdetach(void *v)
 	}
 	rtcache_free(>inp_route);
 	ip_freemoptions(inp->inp_moptions);
+#ifdef INET6
 	if (inp->inp_af == AF_INET6) {
 		if (in6p_outputopts(inp) != NULL) {
 			ip6_clearpktopts(in6p_outputopts(inp), -1);
@@ -672,12 +687,18 @@ in_pcbdetach(void *v)
 		}
 		ip6_freemoptions(in6p_moptions(inp));
 	}
+#endif
 	sofree(so);			/* drops the socket's lock */
 
+#ifdef INET6
 	if (inp->inp_af == AF_INET)
 		pool_put(_pool, inp);
 	else
 		pool_put(_pool, inp);
+#else
+	KASSERT(inp->inp_af == AF_INET);
+	pool_put(_pool, inp);
+#endif
 	mutex_enter(softnet_lock);	/* reacquire the softnet_lock */
 }
 
@@ -1096,10 +1117,15 @@ void
 in_pcbstate(struct inpcb *inp, int state)
 {
 
+#ifdef INET6
 	if (inp->inp_af == AF_INET6) {
 		in6_pcbstate(inp, state);
 		return;
 	}
+#else
+	if (inp->inp_af != AF_INET)
+		return;
+#endif
 
 	if (inp->inp_state > INP_ATTACHED)
 		LIST_REMOVE(inp, inp_hash);
@@ -1130,8 +1156,10 @@ in_pcbrtentry(struct inpcb *inp)
 		struct sockaddr_in	dst4;
 	} u;
 
+#ifdef INET6
 	if (inp->inp_af == AF_INET6)
 		return in6_pcbrtentry(inp);
+#endif
 	if (inp->inp_af != AF_INET)
 		return (NULL);
 



CVS commit: src/sys/netinet

2022-10-28 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Sat Oct 29 02:56:29 UTC 2022

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

Log Message:
inpcb: fix for kernels without INET6


To generate a diff of this commit:
cvs rdiff -u -r1.193 -r1.194 src/sys/netinet/in_pcb.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-09-20 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Tue Sep 20 10:12:18 UTC 2022

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

Log Message:
syncache: make some functions static


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/netinet/tcp_syncache.c \
src/sys/netinet/tcp_syncache.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/tcp_syncache.c
diff -u src/sys/netinet/tcp_syncache.c:1.1 src/sys/netinet/tcp_syncache.c:1.2
--- src/sys/netinet/tcp_syncache.c:1.1	Tue Sep 20 07:19:14 2022
+++ src/sys/netinet/tcp_syncache.c	Tue Sep 20 10:12:18 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_syncache.c,v 1.1 2022/09/20 07:19:14 ozaki-r Exp $	*/
+/*	$NetBSD: tcp_syncache.c,v 1.2 2022/09/20 10:12:18 ozaki-r Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tcp_syncache.c,v 1.1 2022/09/20 07:19:14 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_syncache.c,v 1.2 2022/09/20 10:12:18 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -201,7 +201,11 @@ __KERNEL_RCSID(0, "$NetBSD: tcp_syncache
 #endif	/* IPSEC*/
 #endif
 
-static void syn_cache_timer(void *);
+static void	syn_cache_timer(void *);
+static struct syn_cache *
+		syn_cache_lookup(const struct sockaddr *, const struct sockaddr *,
+		struct syn_cache_head **);
+static int	syn_cache_respond(struct syn_cache *);
 
 /* syn hash parameters */
 #define	TCP_SYN_HASH_SIZE	293
@@ -497,7 +501,7 @@ syn_cache_cleanup(struct tcpcb *tp)
 /*
  * Find an entry in the syn cache.
  */
-struct syn_cache *
+static struct syn_cache *
 syn_cache_lookup(const struct sockaddr *src, const struct sockaddr *dst,
 struct syn_cache_head **headp)
 {
@@ -1094,7 +1098,7 @@ syn_cache_add(struct sockaddr *src, stru
  * Returns 0 on success.
  */
 
-int
+static int
 syn_cache_respond(struct syn_cache *sc)
 {
 #ifdef INET6
Index: src/sys/netinet/tcp_syncache.h
diff -u src/sys/netinet/tcp_syncache.h:1.1 src/sys/netinet/tcp_syncache.h:1.2
--- src/sys/netinet/tcp_syncache.h:1.1	Tue Sep 20 07:19:14 2022
+++ src/sys/netinet/tcp_syncache.h	Tue Sep 20 10:12:18 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_syncache.h,v 1.1 2022/09/20 07:19:14 ozaki-r Exp $	*/
+/*	$NetBSD: tcp_syncache.h,v 1.2 2022/09/20 10:12:18 ozaki-r Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -207,15 +207,13 @@ int	 syn_cache_add(struct sockaddr *, st
 		struct mbuf *, u_char *, int, struct tcp_opt_info *);
 void	 syn_cache_unreach(const struct sockaddr *, const struct sockaddr *,
 	   struct tcphdr *);
-struct socket *syn_cache_get(struct sockaddr *, struct sockaddr *,
+struct socket
+	*syn_cache_get(struct sockaddr *, struct sockaddr *,
 		struct tcphdr *, struct socket *so, struct mbuf *);
 void	 syn_cache_init(void);
 void	 syn_cache_insert(struct syn_cache *, struct tcpcb *);
-struct syn_cache *syn_cache_lookup(const struct sockaddr *, const struct sockaddr *,
-		struct syn_cache_head **);
 void	 syn_cache_reset(struct sockaddr *, struct sockaddr *,
 		struct tcphdr *);
-int	 syn_cache_respond(struct syn_cache *);
 void	 syn_cache_cleanup(struct tcpcb *);
 #endif
 



CVS commit: src/sys/netinet

2022-09-20 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Tue Sep 20 10:12:18 UTC 2022

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

Log Message:
syncache: make some functions static


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/netinet/tcp_syncache.c \
src/sys/netinet/tcp_syncache.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-06-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jun 28 01:44:19 UTC 2022

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

Log Message:
tcp(4): Bail early on sendoob if not connected.

XXX Not sure if testing tp->t_template is the right way to discern
this -- I just reached for it because the downstream crash is a panic
on tp->t_template == NULL in tcp_output.

XXX In principle this could try connecting to the address, except
it's not passed down from the logic in uipc_socket.c to tcp_sendoob.

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


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

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

Modified files:

Index: src/sys/netinet/tcp_usrreq.c
diff -u src/sys/netinet/tcp_usrreq.c:1.230 src/sys/netinet/tcp_usrreq.c:1.231
--- src/sys/netinet/tcp_usrreq.c:1.230	Wed Aug  4 08:47:10 2021
+++ src/sys/netinet/tcp_usrreq.c	Tue Jun 28 01:44:19 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_usrreq.c,v 1.230 2021/08/04 08:47:10 christos Exp $	*/
+/*	$NetBSD: tcp_usrreq.c,v 1.231 2022/06/28 01:44:19 riastradh Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -99,7 +99,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tcp_usrreq.c,v 1.230 2021/08/04 08:47:10 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_usrreq.c,v 1.231 2022/06/28 01:44:19 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1158,6 +1158,16 @@ tcp_sendoob(struct socket *so, struct mb
 		m_freem(control);
 		return error;
 	}
+	if (tp->t_template == NULL) {
+		/*
+		 * XXX FreeBSD appears to open the connection
+		 * automagically in this case, but the socket address
+		 * isn't passed through here so we can't do that.
+		 */
+		m_freem(m);
+		m_freem(control);
+		return ENOTCONN;
+	}
 
 	ostate = tcp_debug_capture(tp, PRU_SENDOOB);
 



CVS commit: src/sys/netinet

2022-06-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jun 28 01:44:19 UTC 2022

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

Log Message:
tcp(4): Bail early on sendoob if not connected.

XXX Not sure if testing tp->t_template is the right way to discern
this -- I just reached for it because the downstream crash is a panic
on tp->t_template == NULL in tcp_output.

XXX In principle this could try connecting to the address, except
it's not passed down from the logic in uipc_socket.c to tcp_sendoob.

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


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

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



CVS commit: src/sys/netinet

2022-06-26 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Jun 27 01:29:51 UTC 2022

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

Log Message:
Remove confusable comment.

The comment was added in tcp_subr.c:r1.124 (2002/03/15).
tcp_drain() is called from softint context only, now.


To generate a diff of this commit:
cvs rdiff -u -r1.289 -r1.290 src/sys/netinet/tcp_subr.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-06-26 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Jun 27 01:29:51 UTC 2022

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

Log Message:
Remove confusable comment.

The comment was added in tcp_subr.c:r1.124 (2002/03/15).
tcp_drain() is called from softint context only, now.


To generate a diff of this commit:
cvs rdiff -u -r1.289 -r1.290 src/sys/netinet/tcp_subr.c

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/tcp_subr.c
diff -u src/sys/netinet/tcp_subr.c:1.289 src/sys/netinet/tcp_subr.c:1.290
--- src/sys/netinet/tcp_subr.c:1.289	Sat Jul 31 20:29:37 2021
+++ src/sys/netinet/tcp_subr.c	Mon Jun 27 01:29:51 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_subr.c,v 1.289 2021/07/31 20:29:37 andvar Exp $	*/
+/*	$NetBSD: tcp_subr.c,v 1.290 2022/06/27 01:29:51 knakahara Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tcp_subr.c,v 1.289 2021/07/31 20:29:37 andvar Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_subr.c,v 1.290 2022/06/27 01:29:51 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1297,8 +1297,7 @@ tcp_drain(void)
 		}
 		if (tp != NULL) {
 			/*
-			 * We may be called from a device's interrupt
-			 * context.  If the tcpcb is already busy,
+			 * If the tcpcb is already busy,
 			 * just bail out now.
 			 */
 			if (tcp_reass_lock_try(tp) == 0)



CVS commit: src/sys/netinet

2022-06-13 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Jun 13 09:23:23 UTC 2022

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

Log Message:
Refactor like in_pcb.c:r1.187 and in6_pcb.c:r1.168.

Use TAILQ_FOREACH instead of TAILQ_FOREACH_SAFE about inpt_queue.
rip_pcbnotify() doesn't use "ninph" pointer and doesn't remove elements.


To generate a diff of this commit:
cvs rdiff -u -r1.180 -r1.181 src/sys/netinet/raw_ip.c

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/raw_ip.c
diff -u src/sys/netinet/raw_ip.c:1.180 src/sys/netinet/raw_ip.c:1.181
--- src/sys/netinet/raw_ip.c:1.180	Tue Sep  8 14:12:57 2020
+++ src/sys/netinet/raw_ip.c	Mon Jun 13 09:23:23 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: raw_ip.c,v 1.180 2020/09/08 14:12:57 christos Exp $	*/
+/*	$NetBSD: raw_ip.c,v 1.181 2022/06/13 09:23:23 knakahara Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -65,7 +65,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: raw_ip.c,v 1.180 2020/09/08 14:12:57 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: raw_ip.c,v 1.181 2022/06/13 09:23:23 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -241,11 +241,11 @@ rip_pcbnotify(struct inpcbtable *table,
 struct in_addr faddr, struct in_addr laddr, int proto, int errno,
 void (*notify)(struct inpcb *, int))
 {
-	struct inpcb_hdr *inph, *ninph;
+	struct inpcb_hdr *inph;
 	int nmatch;
 
 	nmatch = 0;
-	TAILQ_FOREACH_SAFE(inph, >inpt_queue, inph_queue, ninph) {
+	TAILQ_FOREACH(inph, >inpt_queue, inph_queue) {
 		struct inpcb *inp = (struct inpcb *)inph;
 		if (inp->inp_af != AF_INET)
 			continue;



CVS commit: src/sys/netinet

2022-06-13 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Jun 13 09:23:23 UTC 2022

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

Log Message:
Refactor like in_pcb.c:r1.187 and in6_pcb.c:r1.168.

Use TAILQ_FOREACH instead of TAILQ_FOREACH_SAFE about inpt_queue.
rip_pcbnotify() doesn't use "ninph" pointer and doesn't remove elements.


To generate a diff of this commit:
cvs rdiff -u -r1.180 -r1.181 src/sys/netinet/raw_ip.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-06-10 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Jun 10 09:54:54 UTC 2022

Modified Files:
src/sys/netinet: in_pcb.h

Log Message:
"inp_hash" is not used now.


To generate a diff of this commit:
cvs rdiff -u -r1.69 -r1.70 src/sys/netinet/in_pcb.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/in_pcb.h
diff -u src/sys/netinet/in_pcb.h:1.69 src/sys/netinet/in_pcb.h:1.70
--- src/sys/netinet/in_pcb.h:1.69	Tue Sep  8 14:12:57 2020
+++ src/sys/netinet/in_pcb.h	Fri Jun 10 09:54:54 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: in_pcb.h,v 1.69 2020/09/08 14:12:57 christos Exp $	*/
+/*	$NetBSD: in_pcb.h,v 1.70 2022/06/10 09:54:54 knakahara Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -83,7 +83,6 @@ struct mbuf;
  */
 struct inpcb {
 	struct inpcb_hdr inp_head;
-#define inp_hash	inp_head.inph_hash
 #define inp_queue	inp_head.inph_queue
 #define inp_af		inp_head.inph_af
 #define inp_ppcb	inp_head.inph_ppcb



CVS commit: src/sys/netinet

2022-06-10 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Jun 10 09:54:54 UTC 2022

Modified Files:
src/sys/netinet: in_pcb.h

Log Message:
"inp_hash" is not used now.


To generate a diff of this commit:
cvs rdiff -u -r1.69 -r1.70 src/sys/netinet/in_pcb.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-06-10 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Jun 10 09:51:11 UTC 2022

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

Log Message:
Use LIST_FOREACH macro.


To generate a diff of this commit:
cvs rdiff -u -r1.187 -r1.188 src/sys/netinet/in_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/sys/netinet/in_pcb.c
diff -u src/sys/netinet/in_pcb.c:1.187 src/sys/netinet/in_pcb.c:1.188
--- src/sys/netinet/in_pcb.c:1.187	Thu Jun  9 07:01:27 2022
+++ src/sys/netinet/in_pcb.c	Fri Jun 10 09:51:10 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: in_pcb.c,v 1.187 2022/06/09 07:01:27 knakahara Exp $	*/
+/*	$NetBSD: in_pcb.c,v 1.188 2022/06/10 09:51:10 knakahara Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -93,7 +93,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in_pcb.c,v 1.187 2022/06/09 07:01:27 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in_pcb.c,v 1.188 2022/06/10 09:51:10 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -691,7 +691,8 @@ in_pcbnotify(struct inpcbtable *table, s
 void (*notify)(struct inpcb *, int))
 {
 	struct inpcbhead *head;
-	struct inpcb *inp, *ninp;
+	struct inpcb_hdr *inph;
+	struct inpcb *inp;
 	u_int16_t fport = fport_arg, lport = lport_arg;
 	int nmatch;
 
@@ -700,10 +701,11 @@ in_pcbnotify(struct inpcbtable *table, s
 
 	nmatch = 0;
 	head = INPCBHASH_CONNECT(table, faddr, fport, laddr, lport);
-	for (inp = (struct inpcb *)LIST_FIRST(head); inp != NULL; inp = ninp) {
-		ninp = (struct inpcb *)LIST_NEXT(inp, inp_hash);
+	LIST_FOREACH(inph, head, inph_hash) {
+		inp = (struct inpcb *)inph;
 		if (inp->inp_af != AF_INET)
 			continue;
+
 		if (in_hosteq(inp->inp_faddr, faddr) &&
 		inp->inp_fport == fport &&
 		inp->inp_lport == lport &&



CVS commit: src/sys/netinet

2022-06-10 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Jun 10 09:51:11 UTC 2022

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

Log Message:
Use LIST_FOREACH macro.


To generate a diff of this commit:
cvs rdiff -u -r1.187 -r1.188 src/sys/netinet/in_pcb.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-05-18 Thread Andrius Varanavicius
Module Name:src
Committed By:   andvar
Date:   Wed May 18 13:37:52 UTC 2022

Modified Files:
src/sys/netinet: sctp_constants.h

Log Message:
s/yeild/yield/


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/netinet/sctp_constants.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-05-18 Thread Andrius Varanavicius
Module Name:src
Committed By:   andvar
Date:   Wed May 18 13:37:52 UTC 2022

Modified Files:
src/sys/netinet: sctp_constants.h

Log Message:
s/yeild/yield/


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/netinet/sctp_constants.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/sctp_constants.h
diff -u src/sys/netinet/sctp_constants.h:1.3 src/sys/netinet/sctp_constants.h:1.4
--- src/sys/netinet/sctp_constants.h:1.3	Sat Jan  1 08:34:35 2022
+++ src/sys/netinet/sctp_constants.h	Wed May 18 13:37:52 2022
@@ -1,5 +1,5 @@
 /*	$KAME: sctp_constants.h,v 1.17 2005/03/06 16:04:17 itojun Exp $	*/
-/*	$NetBSD: sctp_constants.h,v 1.3 2022/01/01 08:34:35 msaitoh Exp $ */
+/*	$NetBSD: sctp_constants.h,v 1.4 2022/05/18 13:37:52 andvar Exp $ */
 
 #ifndef __SCTP_CONSTANTS_H__
 #define __SCTP_CONSTANTS_H__
@@ -755,7 +755,7 @@
  * course the overhead of the next pointer as well). Using 15 as
  * an example will yield * ((8 * 15) + 8) or 128 bytes of overhead
  * for each timewait block that gets initialized. Increasing it to
- * 31 would yeild 256 bytes per block.
+ * 31 would yield 256 bytes per block.
  */
 /* Undef the following turns on per EP behavior */
 #define SCTP_VTAG_TIMEWAIT_PER_STACK 1



CVS commit: src/sys/netinet

2022-03-15 Thread Andrius Varanavicius
Module Name:src
Committed By:   andvar
Date:   Tue Mar 15 21:40:00 UTC 2022

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

Log Message:
s/heaader/header/


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

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_mroute.c
diff -u src/sys/netinet/ip_mroute.c:1.164 src/sys/netinet/ip_mroute.c:1.165
--- src/sys/netinet/ip_mroute.c:1.164	Thu Nov 12 13:13:45 2020
+++ src/sys/netinet/ip_mroute.c	Tue Mar 15 21:39:59 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_mroute.c,v 1.164 2020/11/12 13:13:45 kardel Exp $	*/
+/*	$NetBSD: ip_mroute.c,v 1.165 2022/03/15 21:39:59 andvar Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -93,7 +93,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip_mroute.c,v 1.164 2020/11/12 13:13:45 kardel Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_mroute.c,v 1.165 2022/03/15 21:39:59 andvar Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1846,7 +1846,7 @@ vif_encapcheck(struct mbuf *m, int off, 
 #endif
 
 	/*
-	 * Accept the packet only if the inner heaader is multicast
+	 * Accept the packet only if the inner header is multicast
 	 * and the outer header matches a tunnel-mode vif.  Order
 	 * checks in the hope that common non-matching packets will be
 	 * rejected quickly.  Assume that unicast IPv4 traffic in a



CVS commit: src/sys/netinet

2022-03-15 Thread Andrius Varanavicius
Module Name:src
Committed By:   andvar
Date:   Tue Mar 15 21:40:00 UTC 2022

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

Log Message:
s/heaader/header/


To generate a diff of this commit:
cvs rdiff -u -r1.164 -r1.165 src/sys/netinet/ip_mroute.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-01-01 Thread Andrius Varanavicius
Module Name:src
Committed By:   andvar
Date:   Sat Jan  1 13:18:43 UTC 2022

Modified Files:
src/sys/netinet: accept_filter.h

Log Message:
s/creting/creating/


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/netinet/accept_filter.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/accept_filter.h
diff -u src/sys/netinet/accept_filter.h:1.2 src/sys/netinet/accept_filter.h:1.3
--- src/sys/netinet/accept_filter.h:1.2	Sun Aug 10 14:07:41 2008
+++ src/sys/netinet/accept_filter.h	Sat Jan  1 13:18:43 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: accept_filter.h,v 1.2 2008/08/10 14:07:41 tls Exp $	*/
+/*	$NetBSD: accept_filter.h,v 1.3 2022/01/01 13:18:43 andvar Exp $	*/
 
 /*
  * Copyright (c) 2006 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
 
 /*
  * Valid accept filter list
- * Currently it is used for creting sysctl object
+ * Currently it is used for creating sysctl object
  */
 
 #define ACCF_DATA	1		/* Data ready accept filter */



CVS commit: src/sys/netinet

2022-01-01 Thread Andrius Varanavicius
Module Name:src
Committed By:   andvar
Date:   Sat Jan  1 13:18:43 UTC 2022

Modified Files:
src/sys/netinet: accept_filter.h

Log Message:
s/creting/creating/


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/netinet/accept_filter.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

2021-12-30 Thread Andrius Varanavicius
Module Name:src
Committed By:   andvar
Date:   Thu Dec 30 23:03:44 UTC 2021

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

Log Message:
s/bandwith/bandwidth/


To generate a diff of this commit:
cvs rdiff -u -r1.213 -r1.214 src/sys/netinet/tcp_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/tcp_output.c
diff -u src/sys/netinet/tcp_output.c:1.213 src/sys/netinet/tcp_output.c:1.214
--- src/sys/netinet/tcp_output.c:1.213	Fri Jun 12 11:04:45 2020
+++ src/sys/netinet/tcp_output.c	Thu Dec 30 23:03:44 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_output.c,v 1.213 2020/06/12 11:04:45 roy Exp $	*/
+/*	$NetBSD: tcp_output.c,v 1.214 2021/12/30 23:03:44 andvar Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -135,7 +135,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tcp_output.c,v 1.213 2020/06/12 11:04:45 roy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_output.c,v 1.214 2021/12/30 23:03:44 andvar Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -907,9 +907,9 @@ again:
 	 * and does at most one step per received ACK.  This fast
 	 * scaling has the drawback of growing the send buffer beyond
 	 * what is strictly necessary to make full use of a given
-	 * delay*bandwith product.  However testing has shown this not
+	 * delay*bandwidth product.  However testing has shown this not
 	 * to be much of an problem.  At worst we are trading wasting
-	 * of available bandwith (the non-use of it) for wasting some
+	 * of available bandwidth (the non-use of it) for wasting some
 	 * socket buffer memory.
 	 *
 	 * TODO: Shrink send buffer during idle periods together



CVS commit: src/sys/netinet

2021-12-30 Thread Andrius Varanavicius
Module Name:src
Committed By:   andvar
Date:   Thu Dec 30 23:03:44 UTC 2021

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

Log Message:
s/bandwith/bandwidth/


To generate a diff of this commit:
cvs rdiff -u -r1.213 -r1.214 src/sys/netinet/tcp_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

2021-12-04 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Sun Dec  5 03:08:20 UTC 2021

Modified Files:
src/sys/netinet: sctp_output.c sctputil.c

Log Message:
s/measurment/measurement/ in comment.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/sys/netinet/sctp_output.c
cvs rdiff -u -r1.17 -r1.18 src/sys/netinet/sctputil.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

2021-12-04 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Sun Dec  5 03:08:20 UTC 2021

Modified Files:
src/sys/netinet: sctp_output.c sctputil.c

Log Message:
s/measurment/measurement/ in comment.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/sys/netinet/sctp_output.c
cvs rdiff -u -r1.17 -r1.18 src/sys/netinet/sctputil.c

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_output.c
diff -u src/sys/netinet/sctp_output.c:1.26 src/sys/netinet/sctp_output.c:1.27
--- src/sys/netinet/sctp_output.c:1.26	Thu Oct 21 13:21:55 2021
+++ src/sys/netinet/sctp_output.c	Sun Dec  5 03:08:19 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: sctp_output.c,v 1.26 2021/10/21 13:21:55 andvar Exp $ */
+/*	$NetBSD: sctp_output.c,v 1.27 2021/12/05 03:08:19 msaitoh Exp $ */
 /*	$KAME: sctp_output.c,v 1.48 2005/06/16 18:29:24 jinmei Exp $	*/
 
 /*
@@ -30,7 +30,7 @@
  * SUCH DAMAGE.
  */
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sctp_output.c,v 1.26 2021/10/21 13:21:55 andvar Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sctp_output.c,v 1.27 2021/12/05 03:08:19 msaitoh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ipsec.h"
@@ -4900,7 +4900,7 @@ sctp_clean_up_datalist(struct sctp_tcb *
 		if (i) {
 			/* Any chunk NOT 0 you zap the time
 			 * chunk 0 gets zapped or set based on
-			 * if a RTO measurment is needed.
+			 * if a RTO measurement is needed.
 			 */
 			data_list[i]->do_rtt = 0;
 		}

Index: src/sys/netinet/sctputil.c
diff -u src/sys/netinet/sctputil.c:1.17 src/sys/netinet/sctputil.c:1.18
--- src/sys/netinet/sctputil.c:1.17	Sat Jul 24 21:31:39 2021
+++ src/sys/netinet/sctputil.c	Sun Dec  5 03:08:19 2021
@@ -1,5 +1,5 @@
 /*	$KAME: sctputil.c,v 1.39 2005/06/16 20:54:06 jinmei Exp $	*/
-/*	$NetBSD: sctputil.c,v 1.17 2021/07/24 21:31:39 andvar Exp $	*/
+/*	$NetBSD: sctputil.c,v 1.18 2021/12/05 03:08:19 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 2001, 2002, 2003, 2004 Cisco Systems, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sctputil.c,v 1.17 2021/07/24 21:31:39 andvar Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sctputil.c,v 1.18 2021/12/05 03:08:19 msaitoh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1719,7 +1719,7 @@ sctp_calculate_rto(struct sctp_tcb *stcb
 			net->lastsv = SCTP_CLOCK_GRANULARITY;
 		}
 	} else {
-		/* First RTO measurment */
+		/* First RTO measurement */
 		net->lastsa = calc_time;
 		net->lastsv = calc_time >> 1;
 		first_measure = 1;



CVS commit: src/sys/netinet

2021-10-19 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Tue Oct 19 20:01:09 UTC 2021

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

Log Message:
netinet: Allow binding the unspecified address when no addresses exist

You should always be able to bind to the unspecified address even if
no addresses have been configured on any interface.

For example, a DHCP client could be started before the loopback interface
has been fully configured.


To generate a diff of this commit:
cvs rdiff -u -r1.185 -r1.186 src/sys/netinet/in_pcb.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

2021-10-19 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Tue Oct 19 20:01:09 UTC 2021

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

Log Message:
netinet: Allow binding the unspecified address when no addresses exist

You should always be able to bind to the unspecified address even if
no addresses have been configured on any interface.

For example, a DHCP client could be started before the loopback interface
has been fully configured.


To generate a diff of this commit:
cvs rdiff -u -r1.185 -r1.186 src/sys/netinet/in_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/sys/netinet/in_pcb.c
diff -u src/sys/netinet/in_pcb.c:1.185 src/sys/netinet/in_pcb.c:1.186
--- src/sys/netinet/in_pcb.c:1.185	Tue Sep  8 14:12:57 2020
+++ src/sys/netinet/in_pcb.c	Tue Oct 19 20:01:09 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: in_pcb.c,v 1.185 2020/09/08 14:12:57 christos Exp $	*/
+/*	$NetBSD: in_pcb.c,v 1.186 2021/10/19 20:01:09 roy Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -93,7 +93,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in_pcb.c,v 1.185 2020/09/08 14:12:57 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in_pcb.c,v 1.186 2021/10/19 20:01:09 roy Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -436,8 +436,6 @@ in_pcbbind(void *v, struct sockaddr_in *
 	if (inp->inp_af != AF_INET)
 		return (EINVAL);
 
-	if (IN_ADDRLIST_READER_EMPTY())
-		return (EADDRNOTAVAIL);
 	if (inp->inp_lport || !in_nullhost(inp->inp_laddr))
 		return (EINVAL);
 



CVS commit: src/sys/netinet

2021-09-21 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Sep 21 15:05:41 UTC 2021

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

Log Message:
don't opencode kauth_cred_get()


To generate a diff of this commit:
cvs rdiff -u -r1.241 -r1.242 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.241 src/sys/netinet/in.c:1.242
--- src/sys/netinet/in.c:1.241	Tue Sep 29 15:33:36 2020
+++ src/sys/netinet/in.c	Tue Sep 21 11:05:41 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: in.c,v 1.241 2020/09/29 19:33:36 roy Exp $	*/
+/*	$NetBSD: in.c,v 1.242 2021/09/21 15:05:41 christos Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in.c,v 1.241 2020/09/29 19:33:36 roy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in.c,v 1.242 2021/09/21 15:05:41 christos Exp $");
 
 #include "arp.h"
 
@@ -521,7 +521,8 @@ in_control0(struct socket *so, u_long cm
 			goto out;
 		}
 
-		if (kauth_authorize_network(curlwp->l_cred, KAUTH_NETWORK_INTERFACE,
+		if (kauth_authorize_network(kauth_cred_get(),
+		KAUTH_NETWORK_INTERFACE,
 		KAUTH_REQ_NETWORK_INTERFACE_SETPRIV, ifp, (void *)cmd,
 		NULL) != 0) {
 			error = EPERM;
@@ -565,7 +566,8 @@ in_control0(struct socket *so, u_long cm
 		break;
 
 	case SIOCSIFBRDADDR:
-		if (kauth_authorize_network(curlwp->l_cred, KAUTH_NETWORK_INTERFACE,
+		if (kauth_authorize_network(kauth_cred_get(),
+		KAUTH_NETWORK_INTERFACE,
 		KAUTH_REQ_NETWORK_INTERFACE_SETPRIV, ifp, (void *)cmd,
 		NULL) != 0) {
 			error = EPERM;



CVS commit: src/sys/netinet

2021-09-21 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Sep 21 15:05:41 UTC 2021

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

Log Message:
don't opencode kauth_cred_get()


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

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



Re: CVS commit: src/sys/netinet

2021-02-16 Thread Martin Husemann
On Tue, Feb 16, 2021 at 09:29:15AM +, Roy Marples wrote:
> In my testing on aarch64 and octeon (both of which I think are strict
> alignment) neither need pullups nor copyups as the mbuf already has enough
> and arphrd is aligned correctly already.

Ah, we asserted too much alignment - indeed, this variant works and I commited
it after testing on 32bit arm and sparc64.

Martin


Re: CVS commit: src/sys/netinet

2021-02-16 Thread Roy Marples

On 16/02/2021 09:20, Martin Husemann wrote:

On Tue, Feb 16, 2021 at 08:26:40AM +, Roy Marples wrote:

Is that because ARP_HDR_ALIGNMENT is forcing 4 byte alignment?


The KASSERT a few lines below triggerd, we need to be consistent.


For the purposes of using just the header we define I'm pretty sure we can
use 2 byte alignment and set ARP_HDR_ALIGNMENT to 1.


I can test (I have an alignment critical machine with non-ETHER_ALIGN'ing
network driver). Send me a patch, I lost track in the ongoing overhaul.


ARP_HDR_ALIGNED_P can now be removed from if_arp.c as well.


Not sure I understand what you mean here.



Index: net/if_arp.h
===
RCS file: /cvsroot/src/sys/net/if_arp.h,v
retrieving revision 1.40
diff -u -p -r1.40 if_arp.h
--- net/if_arp.h14 Feb 2021 20:58:34 -  1.40
+++ net/if_arp.h16 Feb 2021 09:26:23 -
@@ -72,7 +72,7 @@ structarphdr {
uint8_t  ar_tpa[];  /* target protocol address */
 #endif
 };
-#defineARP_HDR_ALIGNMENT   3
+#defineARP_HDR_ALIGNMENT   1

 static __inline uint8_t *
 ar_data(struct arphdr *ap)
Index: netinet/if_arp.c
===
RCS file: /cvsroot/src/sys/netinet/if_arp.c,v
retrieving revision 1.305
diff -u -p -r1.305 if_arp.c
--- netinet/if_arp.c16 Feb 2021 05:44:13 -  1.305
+++ netinet/if_arp.c16 Feb 2021 09:26:23 -
@@ -133,12 +133,6 @@ __KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1
  */
 #define ETHERTYPE_IPTRAILERS ETHERTYPE_TRAIL

-#ifdef __NO_STRICT_ALIGNMENT
-#defineARP_HDR_ALIGNED_P(ar)   1
-#else
-#defineARP_HDR_ALIGNED_P(ar)   vaddr_t) (ar)) & 1) == 0)
-#endif
-
 /* timers */
 static int arp_reachable = REACHABLE_TIME;
 static int arp_retrans = RETRANS_TIMER;


In my testing on aarch64 and octeon (both of which I think are strict alignment) 
neither need pullups nor copyups as the mbuf already has enough and arphrd is 
aligned correctly already.


Roy


Re: CVS commit: src/sys/netinet

2021-02-16 Thread Martin Husemann
On Tue, Feb 16, 2021 at 08:26:40AM +, Roy Marples wrote:
> Is that because ARP_HDR_ALIGNMENT is forcing 4 byte alignment?

The KASSERT a few lines below triggerd, we need to be consistent.

> For the purposes of using just the header we define I'm pretty sure we can
> use 2 byte alignment and set ARP_HDR_ALIGNMENT to 1.

I can test (I have an alignment critical machine with non-ETHER_ALIGN'ing
network driver). Send me a patch, I lost track in the ongoing overhaul.

> ARP_HDR_ALIGNED_P can now be removed from if_arp.c as well.

Not sure I understand what you mean here.

Martin


Re: CVS commit: src/sys/netinet

2021-02-16 Thread Roy Marples

On 16/02/2021 05:44, Martin Husemann wrote:

Module Name:src
Committed By:   martin
Date:   Tue Feb 16 05:44:14 UTC 2021

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

Log Message:
Undo previous backout: alignment is needed here.
The reason for the previous backout was a misunderstanding (POINTER_ALIGNED_P
was broken, but the assertion fired even after it got fixed).


Is that because ARP_HDR_ALIGNMENT is forcing 4 byte alignment?
For the purposes of using just the header we define I'm pretty sure we can use 2 
byte alignment and set ARP_HDR_ALIGNMENT to 1.


ARP_HDR_ALIGNED_P can now be removed from if_arp.c as well.

Roy


Re: CVS commit: src/sys/netinet

2020-12-04 Thread Jason Thorpe


> On Dec 4, 2020, at 8:57 AM, Christos Zoulas  wrote:
> 
> In article <20201204004439.90c25f...@cvs.netbsd.org>,
> Jason R Thorpe  wrote:
>> -=-=-=-=-=-
>> 
>> Module Name: src
>> Committed By:thorpej
>> Date:Fri Dec  4 00:44:39 UTC 2020
>> 
>> Modified Files:
>>  src/sys/netinet: files.ipfilter
>> 
>> Log Message:
>> Build ip_sync.c with -Wno-error to avoid failing due to excessive stack
>> usage.
> 
> Can you please make this more specific? Like -Wno-error=foo?

Feel free to try.  -Wno-error=stack-usage produced an error for me.

-- thorpej



Re: CVS commit: src/sys/netinet

2020-12-04 Thread Christos Zoulas
In article <20201204004439.90c25f...@cvs.netbsd.org>,
Jason R Thorpe  wrote:
>-=-=-=-=-=-
>
>Module Name:   src
>Committed By:  thorpej
>Date:  Fri Dec  4 00:44:39 UTC 2020
>
>Modified Files:
>   src/sys/netinet: files.ipfilter
>
>Log Message:
>Build ip_sync.c with -Wno-error to avoid failing due to excessive stack
>usage.

Can you please make this more specific? Like -Wno-error=foo?

christos



CVS commit: src/sys/netinet

2019-11-17 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun Nov 17 08:21:25 UTC 2019

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

Log Message:
Don't allow zero sized segments that will panic the stack.
Reported-by: syzbot+5542516fa4afe7a10...@syzkaller.appspotmail.com


To generate a diff of this commit:
cvs rdiff -u -r1.211 -r1.212 src/sys/netinet/tcp_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

2019-11-17 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun Nov 17 08:21:25 UTC 2019

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

Log Message:
Don't allow zero sized segments that will panic the stack.
Reported-by: syzbot+5542516fa4afe7a10...@syzkaller.appspotmail.com


To generate a diff of this commit:
cvs rdiff -u -r1.211 -r1.212 src/sys/netinet/tcp_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/tcp_output.c
diff -u src/sys/netinet/tcp_output.c:1.211 src/sys/netinet/tcp_output.c:1.212
--- src/sys/netinet/tcp_output.c:1.211	Mon Feb 25 10:49:16 2019
+++ src/sys/netinet/tcp_output.c	Sun Nov 17 08:21:25 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_output.c,v 1.211 2019/02/25 10:49:16 maxv Exp $	*/
+/*	$NetBSD: tcp_output.c,v 1.212 2019/11/17 08:21:25 mlelstv Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -135,7 +135,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tcp_output.c,v 1.211 2019/02/25 10:49:16 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_output.c,v 1.212 2019/11/17 08:21:25 mlelstv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -252,6 +252,7 @@ tcp_segsize(struct tcpcb *tp, int *txseg
 		break;
 #endif
 	default:
+		hdrlen = 1; /* prevent zero sized segments */
 		goto out;
 	}
 
@@ -386,6 +387,13 @@ tcp_segsize(struct tcpcb *tp, int *txseg
 		*txsegsizep = uimin(so->so_snd.sb_hiwat >> 1, *txsegsizep);
 	}
 
+	/*
+	 * A segment must at least store header + options
+	 */
+	if (*txsegsizep < hdrlen + optlen) {
+		return EMSGSIZE;
+	}
+
 	if (*txsegsizep != tp->t_segsz) {
 		/*
 		 * If the new segment size is larger, we don't want to



CVS commit: src/sys/netinet

2019-11-16 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat Nov 16 10:15:10 UTC 2019

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

Log Message:
Call rtcache_unref() only when the checks succeed, instead of relying on
another NULL check in rtcache_unref().

Because, in order to resolve the address of the second argument, we do a
dereference on 'tp', which is theoretically allowed to be NULL. The five
callers of nd6_hint() never pass a NULL argument however, so by luck the
actual NULL deref never happens.

Maybe the NULL check on 'tp' in should be replaced to a KASSERT ensuring
it isn't NULL, for clarity.

Reported by kUBSan.


To generate a diff of this commit:
cvs rdiff -u -r1.416 -r1.417 src/sys/netinet/tcp_input.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

2019-11-16 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat Nov 16 10:15:10 UTC 2019

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

Log Message:
Call rtcache_unref() only when the checks succeed, instead of relying on
another NULL check in rtcache_unref().

Because, in order to resolve the address of the second argument, we do a
dereference on 'tp', which is theoretically allowed to be NULL. The five
callers of nd6_hint() never pass a NULL argument however, so by luck the
actual NULL deref never happens.

Maybe the NULL check on 'tp' in should be replaced to a KASSERT ensuring
it isn't NULL, for clarity.

Reported by kUBSan.


To generate a diff of this commit:
cvs rdiff -u -r1.416 -r1.417 src/sys/netinet/tcp_input.c

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

Modified files:

Index: src/sys/netinet/tcp_input.c
diff -u src/sys/netinet/tcp_input.c:1.416 src/sys/netinet/tcp_input.c:1.417
--- src/sys/netinet/tcp_input.c:1.416	Wed Sep 25 19:06:30 2019
+++ src/sys/netinet/tcp_input.c	Sat Nov 16 10:15:10 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_input.c,v 1.416 2019/09/25 19:06:30 jnemeth Exp $	*/
+/*	$NetBSD: tcp_input.c,v 1.417 2019/11/16 10:15:10 maxv Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.416 2019/09/25 19:06:30 jnemeth Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.417 2019/11/16 10:15:10 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -260,9 +260,10 @@ nd6_hint(struct tcpcb *tp)
 	struct rtentry *rt = NULL;
 
 	if (tp != NULL && tp->t_in6pcb != NULL && tp->t_family == AF_INET6 &&
-	(rt = rtcache_validate(>t_in6pcb->in6p_route)) != NULL)
+	(rt = rtcache_validate(>t_in6pcb->in6p_route)) != NULL) {
 		nd6_nud_hint(rt);
-	rtcache_unref(rt, >t_in6pcb->in6p_route);
+		rtcache_unref(rt, >t_in6pcb->in6p_route);
+	}
 }
 #else
 static inline void



CVS commit: src/sys/netinet

2019-11-01 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Nov  1 13:54:59 UTC 2019

Modified Files:
src/sys/netinet: tcp.h

Log Message:
Add comments to the tcp flags.


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/sys/netinet/tcp.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/tcp.h
diff -u src/sys/netinet/tcp.h:1.33 src/sys/netinet/tcp.h:1.34
--- src/sys/netinet/tcp.h:1.33	Tue Jan 10 15:32:27 2017
+++ src/sys/netinet/tcp.h	Fri Nov  1 09:54:59 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp.h,v 1.33 2017/01/10 20:32:27 christos Exp $	*/
+/*	$NetBSD: tcp.h,v 1.34 2019/11/01 13:54:59 christos Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1993
@@ -61,14 +61,14 @@ struct tcphdr {
 		  th_x2:4;		/* (unused) */
 #endif
 	uint8_t  th_flags;
-#define	TH_FIN	  0x01
-#define	TH_SYN	  0x02
-#define	TH_RST	  0x04
-#define	TH_PUSH	  0x08
-#define	TH_ACK	  0x10
-#define	TH_URG	  0x20
-#define	TH_ECE	  0x40
-#define	TH_CWR	  0x80
+#define	TH_FIN	  0x01		/* Final: Set on the last segment */
+#define	TH_SYN	  0x02		/* Synchronization: New conn with dst port */
+#define	TH_RST	  0x04		/* Reset: Announce to peer conn terminated */
+#define	TH_PUSH	  0x08		/* Push: Immediately send, don't buffer seg */
+#define	TH_ACK	  0x10		/* Acknowledge: Part of connection establish */
+#define	TH_URG	  0x20		/* Urgent: send special marked segment now */
+#define	TH_ECE	  0x40		/* ECN Echo */
+#define	TH_CWR	  0x80		/* Congestion Window Reduced */
 	uint16_t th_win;			/* window */
 	uint16_t th_sum;			/* checksum */
 	uint16_t th_urp;			/* urgent pointer */



CVS commit: src/sys/netinet

2019-11-01 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Nov  1 13:54:59 UTC 2019

Modified Files:
src/sys/netinet: tcp.h

Log Message:
Add comments to the tcp flags.


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/sys/netinet/tcp.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

2019-10-11 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Fri Oct 11 13:32:46 UTC 2019

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

Log Message:
ARP: Don't defend ARP probes.

We should let the nature of ARP takes it's course here when our address
is neither tentative nor duplicated.
This allows the host to work with ARP ping, which was broken in r1.279.


To generate a diff of this commit:
cvs rdiff -u -r1.288 -r1.289 src/sys/netinet/if_arp.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

2019-10-11 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Fri Oct 11 13:32:46 UTC 2019

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

Log Message:
ARP: Don't defend ARP probes.

We should let the nature of ARP takes it's course here when our address
is neither tentative nor duplicated.
This allows the host to work with ARP ping, which was broken in r1.279.


To generate a diff of this commit:
cvs rdiff -u -r1.288 -r1.289 src/sys/netinet/if_arp.c

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

Modified files:

Index: src/sys/netinet/if_arp.c
diff -u src/sys/netinet/if_arp.c:1.288 src/sys/netinet/if_arp.c:1.289
--- src/sys/netinet/if_arp.c:1.288	Wed Sep 25 09:52:32 2019
+++ src/sys/netinet/if_arp.c	Fri Oct 11 13:32:46 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_arp.c,v 1.288 2019/09/25 09:52:32 ozaki-r Exp $	*/
+/*	$NetBSD: if_arp.c,v 1.289 2019/10/11 13:32:46 roy Exp $	*/
 
 /*
  * Copyright (c) 1998, 2000, 2008 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.288 2019/09/25 09:52:32 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.289 2019/10/11 13:32:46 roy Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -1157,15 +1157,17 @@ in_arpinput(struct mbuf *m)
 	/*
 	 * DAD check, RFC 5227.
 	 * Collision on sender address is always a duplicate.
-	 * Collision on target address is only a duplicate IF
-	 * the sender address is the null host (ie a DAD probe) AND
-	 * the message was broadcast - if it's unicast then it's
-	 * a valid Unicast Poll from RFC 1122.
+	 * Collision on target address is only a duplicate
+	 * IF the sender address is the null host (ie a DAD probe)
+	 * AND the message was broadcast
+	 * AND our address is either tentative or duplicated
+	 * If it was unicast then it's a valid Unicast Poll from RFC 1122.
 	 */
 	if (do_dad &&
 	(in_hosteq(isaddr, myaddr) ||
 	(in_nullhost(isaddr) && in_hosteq(itaddr, myaddr) &&
-	 m->m_flags & M_BCAST)))
+	 m->m_flags & M_BCAST &&
+	 ia->ia4_flags & (IN_IFF_TENTATIVE | IN_IFF_DUPLICATED
 	{
 		struct sockaddr_dl sdl, *sdlp;
 



CVS commit: src/sys/netinet

2019-10-08 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Wed Oct  9 05:29:18 UTC 2019

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

Log Message:
 All of snd_wnd, snd_cwnd and snd_ssthresh in stuct tcpcb are u_long,
so use u_long and ulmin() instead of u_int and uimin(). Found by lgtm bot.

XXX TCP's sequence number is uint32_t, so it might be good to change some
entries in struct tcpcb to uint32_t instead of u_long. FreeBSD did it.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/sys/netinet/tcp_congctl.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

2019-10-08 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Wed Oct  9 05:29:18 UTC 2019

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

Log Message:
 All of snd_wnd, snd_cwnd and snd_ssthresh in stuct tcpcb are u_long,
so use u_long and ulmin() instead of u_int and uimin(). Found by lgtm bot.

XXX TCP's sequence number is uint32_t, so it might be good to change some
entries in struct tcpcb to uint32_t instead of u_long. FreeBSD did it.


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

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/tcp_congctl.c
diff -u src/sys/netinet/tcp_congctl.c:1.26 src/sys/netinet/tcp_congctl.c:1.27
--- src/sys/netinet/tcp_congctl.c:1.26	Mon Sep  3 16:29:36 2018
+++ src/sys/netinet/tcp_congctl.c	Wed Oct  9 05:29:18 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_congctl.c,v 1.26 2018/09/03 16:29:36 riastradh Exp $	*/
+/*	$NetBSD: tcp_congctl.c,v 1.27 2019/10/09 05:29:18 msaitoh Exp $	*/
 
 /*-
  * Copyright (c) 1997, 1998, 1999, 2001, 2005, 2006 The NetBSD Foundation, Inc.
@@ -135,7 +135,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tcp_congctl.c,v 1.26 2018/09/03 16:29:36 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_congctl.c,v 1.27 2019/10/09 05:29:18 msaitoh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -427,12 +427,12 @@ tcp_congctl_fillnames(void)
 static void
 tcp_common_congestion_exp(struct tcpcb *tp, int betaa, int betab)
 {
-	u_int win;
+	u_long win;
 
 	/* 
 	 * Reduce the congestion window and the slow start threshold.
 	 */
-	win = uimin(tp->snd_wnd, tp->snd_cwnd) * betaa / betab / tp->t_segsz;
+	win = ulmin(tp->snd_wnd, tp->snd_cwnd) * betaa / betab / tp->t_segsz;
 	if (win < 2)
 		win = 2;
 
@@ -519,7 +519,7 @@ tcp_reno_fast_retransmit(struct tcpcb *t
 static void
 tcp_reno_slow_retransmit(struct tcpcb *tp)
 {
-	u_int win;
+	u_long win;
 
 	/*
 	 * Close the congestion window down to one segment
@@ -546,7 +546,7 @@ tcp_reno_slow_retransmit(struct tcpcb *t
 	 * to go below this.)
 	 */
 
-	win = uimin(tp->snd_wnd, tp->snd_cwnd) / 2 / tp->t_segsz;
+	win = ulmin(tp->snd_wnd, tp->snd_cwnd) / 2 / tp->t_segsz;
 	if (win < 2)
 		win = 2;
 	/* Loss Window MUST be one segment. */



CVS commit: src/sys/netinet

2019-09-25 Thread John Nemeth
Module Name:src
Committed By:   jnemeth
Date:   Wed Sep 25 19:06:30 UTC 2019

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

Log Message:
PR/54572 - Edgar Fu� -- error in comment


To generate a diff of this commit:
cvs rdiff -u -r1.415 -r1.416 src/sys/netinet/tcp_input.c

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

Modified files:

Index: src/sys/netinet/tcp_input.c
diff -u src/sys/netinet/tcp_input.c:1.415 src/sys/netinet/tcp_input.c:1.416
--- src/sys/netinet/tcp_input.c:1.415	Tue Aug  6 15:48:18 2019
+++ src/sys/netinet/tcp_input.c	Wed Sep 25 19:06:30 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_input.c,v 1.415 2019/08/06 15:48:18 riastradh Exp $	*/
+/*	$NetBSD: tcp_input.c,v 1.416 2019/09/25 19:06:30 jnemeth Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.415 2019/08/06 15:48:18 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.416 2019/09/25 19:06:30 jnemeth Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -2405,8 +2405,8 @@ after_listen:
 
 	/*
 	 * Since we've covered the SYN-SENT and SYN-RECEIVED states above
-	 * we must be in a synchronized state.  RFC791 states (under RST
-	 * generation) that any unacceptable segment (an out-of-order SYN
+	 * we must be in a synchronized state.  RFC793 states (under Reset
+	 * Generation) that any unacceptable segment (an out-of-order SYN
 	 * qualifies) received in a synchronized state must elicit only an
 	 * empty acknowledgment segment ... and the connection remains in
 	 * the same state.



CVS commit: src/sys/netinet

2019-09-25 Thread John Nemeth
Module Name:src
Committed By:   jnemeth
Date:   Wed Sep 25 19:06:30 UTC 2019

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

Log Message:
PR/54572 - Edgar Fu� -- error in comment


To generate a diff of this commit:
cvs rdiff -u -r1.415 -r1.416 src/sys/netinet/tcp_input.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

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

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

Log Message:
wqinput: avoid having struct wqinput_worklist directly in a percpu storage

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

Input handlers of wqinput normally involves sleepable operations so we must
avoid dereferencing a percpu data (struct wqinput_worklist) after executing
an input handler.  Address this situation by having just a pointer to the data
in a percpu storage instead.

Reviewed by knakahara@ and yamaguchi@


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/netinet/wqinput.c

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/wqinput.c
diff -u src/sys/netinet/wqinput.c:1.5 src/sys/netinet/wqinput.c:1.6
--- src/sys/netinet/wqinput.c:1.5	Fri Aug 10 07:20:59 2018
+++ src/sys/netinet/wqinput.c	Thu Sep 19 04:09:34 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: wqinput.c,v 1.5 2018/08/10 07:20:59 msaitoh Exp $	*/
+/*	$NetBSD: wqinput.c,v 1.6 2019/09/19 04:09:34 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -80,7 +80,8 @@ static void wqinput_sysctl_setup(const c
 static void
 wqinput_drops(void *p, void *arg, struct cpu_info *ci __unused)
 {
-	struct wqinput_worklist *const wwl = p;
+	struct wqinput_worklist **const wwlp = p;
+	struct wqinput_worklist *const wwl = *wwlp;
 	uint64_t *sum = arg;
 
 	*sum += wwl->wwl_dropped;
@@ -148,6 +149,28 @@ bad:
 	return;
 }
 
+static struct wqinput_worklist *
+wqinput_percpu_getref(percpu_t *pc)
+{
+
+	return *(struct wqinput_worklist **)percpu_getref(pc);
+}
+
+static void
+wqinput_percpu_putref(percpu_t *pc)
+{
+
+	percpu_putref(pc);
+}
+
+static void
+wqinput_percpu_init_cpu(void *p, void *arg __unused, struct cpu_info *ci __unused)
+{
+	struct wqinput_worklist **wwlp = p;
+
+	*wwlp = kmem_zalloc(sizeof(**wwlp), KM_SLEEP);
+}
+
 struct wqinput *
 wqinput_create(const char *name, void (*func)(struct mbuf *, int, int))
 {
@@ -165,7 +188,8 @@ wqinput_create(const char *name, void (*
 		panic("%s: workqueue_create failed (%d)\n", __func__, error);
 	pool_init(>wqi_work_pool, sizeof(struct wqinput_work), 0, 0, 0,
 	name, NULL, IPL_SOFTNET);
-	wqi->wqi_worklists = percpu_alloc(sizeof(struct wqinput_worklist));
+	wqi->wqi_worklists = percpu_alloc(sizeof(struct wqinput_worklist *));
+	percpu_foreach(wqi->wqi_worklists, wqinput_percpu_init_cpu, NULL);
 	wqi->wqi_input = func;
 
 	wqinput_sysctl_setup(name, wqi);
@@ -207,7 +231,7 @@ wqinput_work(struct work *wk, void *arg)
 	/* Users expect to run at IPL_SOFTNET */
 	s = splsoftnet();
 	/* This also prevents LWP migrations between CPUs */
-	wwl = percpu_getref(wqi->wqi_worklists);
+	wwl = wqinput_percpu_getref(wqi->wqi_worklists);
 
 	/* We can allow enqueuing another work at this point */
 	wwl->wwl_wq_is_active = false;
@@ -222,7 +246,7 @@ wqinput_work(struct work *wk, void *arg)
 		pool_put(>wqi_work_pool, work);
 	}
 
-	percpu_putref(wqi->wqi_worklists);
+	wqinput_percpu_putref(wqi->wqi_worklists);
 	splx(s);
 }
 
@@ -245,7 +269,7 @@ wqinput_input(struct wqinput *wqi, struc
 	struct wqinput_work *work;
 	struct wqinput_worklist *wwl;
 
-	wwl = percpu_getref(wqi->wqi_worklists);
+	wwl = wqinput_percpu_getref(wqi->wqi_worklists);
 
 	/* Prevent too much work and mbuf from being queued */
 	if (wwl->wwl_len >= WQINPUT_LIST_MAXLEN) {
@@ -274,5 +298,5 @@ wqinput_input(struct wqinput *wqi, struc
 
 	workqueue_enqueue(wqi->wqi_wq, >wwl_work, NULL);
 out:
-	percpu_putref(wqi->wqi_worklists);
+	wqinput_percpu_putref(wqi->wqi_worklists);
 }



CVS commit: src/sys/netinet

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

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

Log Message:
wqinput: avoid having struct wqinput_worklist directly in a percpu storage

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

Input handlers of wqinput normally involves sleepable operations so we must
avoid dereferencing a percpu data (struct wqinput_worklist) after executing
an input handler.  Address this situation by having just a pointer to the data
in a percpu storage instead.

Reviewed by knakahara@ and yamaguchi@


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/netinet/wqinput.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

2019-09-01 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Sun Sep  1 22:09:02 UTC 2019

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

Log Message:
inet: Send RTM_MISS when we fail to resolve an address.

Takes the same approach as when adding a new address - we no longer
announce the new lladdr right away but we announce the result.
This will either be RTM_ADD or RTM_MISS.
RTM_DELETE is only sent if we have a lladdr assigned OR gc'ed.

This tells us when a new lladdr has been added (RTM_ADD),
changed (RTM_CHANGE), deleted (RTM_DELETED) or has failed to been
resolved (RTM_MISS). The latter case can be interpreted as unreachable.


To generate a diff of this commit:
cvs rdiff -u -r1.286 -r1.287 src/sys/netinet/if_arp.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

2019-09-01 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Sun Sep  1 22:09:02 UTC 2019

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

Log Message:
inet: Send RTM_MISS when we fail to resolve an address.

Takes the same approach as when adding a new address - we no longer
announce the new lladdr right away but we announce the result.
This will either be RTM_ADD or RTM_MISS.
RTM_DELETE is only sent if we have a lladdr assigned OR gc'ed.

This tells us when a new lladdr has been added (RTM_ADD),
changed (RTM_CHANGE), deleted (RTM_DELETED) or has failed to been
resolved (RTM_MISS). The latter case can be interpreted as unreachable.


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

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

Modified files:

Index: src/sys/netinet/if_arp.c
diff -u src/sys/netinet/if_arp.c:1.286 src/sys/netinet/if_arp.c:1.287
--- src/sys/netinet/if_arp.c:1.286	Fri Aug 30 18:52:00 2019
+++ src/sys/netinet/if_arp.c	Sun Sep  1 22:09:02 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_arp.c,v 1.286 2019/08/30 18:52:00 roy Exp $	*/
+/*	$NetBSD: if_arp.c,v 1.287 2019/09/01 22:09:02 roy Exp $	*/
 
 /*
  * Copyright (c) 1998, 2000, 2008 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.286 2019/08/30 18:52:00 roy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.287 2019/09/01 22:09:02 roy Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -315,6 +315,17 @@ arptimer(void *arg)
 	if (lle->la_flags & LLE_LINKED) {
 		size_t pkts_dropped;
 
+		if (lle->la_flags & LLE_VALID) {
+			struct in_addr *in;
+			struct sockaddr_in sin;
+			const char *lladdr;
+
+			in = >r_l3addr.addr4;
+			sockaddr_in_init(, in, 0);
+			lladdr = (const char *)>ll_addr;
+			rt_clonedmsg(RTM_DELETE, sintosa(), lladdr, ifp);
+		}
+
 		LLE_REMREF(lle);
 		pkts_dropped = llentry_free(lle);
 		ARP_STATADD(ARP_STAT_DFRDROPPED, pkts_dropped);
@@ -745,14 +756,8 @@ notfound:
 			rt_unref(_rt);
 		if (la == NULL)
 			ARP_STATINC(ARP_STAT_ALLOCFAIL);
-		else {
-			struct sockaddr_in sin;
-
+		else
 			arp_init_llentry(ifp, la);
-			sockaddr_in_init(, >r_l3addr.addr4, 0);
-			if (rt != NULL)
-rt_clonedmsg(RTM_ADD, sintosa(), NULL, ifp);
-		}
 	} else if (LLE_TRY_UPGRADE(la) == 0) {
 		create_lookup = "lookup";
 		LLE_RUNLOCK(la);
@@ -852,9 +857,16 @@ notfound:
 
 	if (renew) {
 		const uint8_t *enaddr = CLLADDR(ifp->if_sadl);
+		struct sockaddr_in sin;
+
 		la->la_expire = time_uptime;
 		arp_settimer(la, arpt_down);
 		la->la_asked++;
+
+		sockaddr_in_init(, >r_l3addr.addr4, 0);
+		if (error != EWOULDBLOCK)
+			rt_clonedmsg(RTM_MISS, sintosa(), NULL, ifp);
+
 		LLE_WUNLOCK(la);
 
 		if (rt != NULL) {
@@ -862,11 +874,8 @@ notfound:
 			(rt->rt_ifa->ifa_addr)->sin_addr,
 			(dst)->sin_addr, enaddr);
 		} else {
-			struct sockaddr_in sin;
 			struct rtentry *_rt;
 
-			sockaddr_in_init(, >r_l3addr.addr4, 0);
-
 			/* XXX */
 			_rt = rtalloc1((struct sockaddr *), 0);
 			if (_rt == NULL)
@@ -1007,7 +1016,7 @@ in_arpinput(struct mbuf *m)
 #endif
 	struct sockaddr sa;
 	struct in_addr isaddr, itaddr, myaddr;
-	int op;
+	int op, rt_cmd;
 	void *tha;
 	uint64_t *arps;
 	struct psref psref, psref_ia;
@@ -1217,7 +1226,9 @@ in_arpinput(struct mbuf *m)
 "for %s by %s\n",
 IN_PRINT(ipbuf, ), llastr);
 		}
-	}
+		rt_cmd = RTM_CHANGE;
+	} else
+		rt_cmd = la->la_flags & LLE_VALID ? 0 : RTM_ADD;
 
 	KASSERT(ifp->if_sadl->sdl_alen == ifp->if_addrlen);
 
@@ -1259,6 +1270,13 @@ in_arpinput(struct mbuf *m)
 	la->la_asked = 0;
 	/* rt->rt_flags &= ~RTF_REJECT; */
 
+	if (rt_cmd != 0) {
+		struct sockaddr_in sin;
+
+		sockaddr_in_init(, >r_l3addr.addr4, 0);
+		rt_clonedmsg(rt_cmd, sintosa(), ar_sha(ah), ifp);
+	}
+
 	if (la->la_hold != NULL) {
 		int n = la->la_numheld;
 		struct mbuf *m_hold, *m_hold_next;



  1   2   3   >