CVS commit: src/sys/netinet

2021-08-04 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Aug  4 08:47:10 UTC 2021

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

Log Message:
Get the value of the right variable (from RVP)


To generate a diff of this commit:
cvs rdiff -u -r1.229 -r1.230 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.229 src/sys/netinet/tcp_usrreq.c:1.230
--- src/sys/netinet/tcp_usrreq.c:1.229	Mon Mar  8 13:17:27 2021
+++ src/sys/netinet/tcp_usrreq.c	Wed Aug  4 04:47:10 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_usrreq.c,v 1.229 2021/03/08 18:17:27 christos Exp $	*/
+/*	$NetBSD: tcp_usrreq.c,v 1.230 2021/08/04 08:47:10 christos Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -99,7 +99,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tcp_usrreq.c,v 1.229 2021/03/08 18:17:27 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_usrreq.c,v 1.230 2021/08/04 08:47:10 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -480,7 +480,7 @@ tcp_ctloutput(int op, struct socket *so,
 			optval = tp->t_keepcnt;
 			goto setval;
 		case TCP_KEEPINIT:
-			optval = tp->t_keepcnt;
+			optval = tp->t_keepinit;
 setval:			error = sockopt_set(sopt, , sizeof(optval));
 			break;
 		default:



CVS commit: src/sys/netinet

2021-03-09 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Mar  9 13:48:16 UTC 2021

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

Log Message:
Move the offset addition in one place and mask the random generated value
to make sure that the isn is monotonic.


To generate a diff of this commit:
cvs rdiff -u -r1.287 -r1.288 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.287 src/sys/netinet/tcp_subr.c:1.288
--- src/sys/netinet/tcp_subr.c:1.287	Mon Mar  8 13:17:27 2021
+++ src/sys/netinet/tcp_subr.c	Tue Mar  9 08:48:16 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_subr.c,v 1.287 2021/03/08 18:17:27 christos Exp $	*/
+/*	$NetBSD: tcp_subr.c,v 1.288 2021/03/09 13:48:16 christos Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tcp_subr.c,v 1.287 2021/03/08 18:17:27 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_subr.c,v 1.288 2021/03/09 13:48:16 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -2210,23 +2210,23 @@ tcp_new_iss1(void *laddr, void *faddr, u
 #ifdef TCPISS_DEBUG
 		printf("ISS hash 0x%08x, ", tcp_iss);
 #endif
-		/*
-		 * Add the offset in to the computed value.
-		 */
-		tcp_iss += tcp_iss_seq;
-#ifdef TCPISS_DEBUG
-		printf("ISS %08x\n", tcp_iss);
-#endif
 	} else {
 		/*
 		 * Randomize.
 		 */
-		tcp_iss = cprng_fast32();
+		tcp_iss = cprng_fast32() & TCP_ISS_RANDOM_MASK;
 #ifdef TCPISS_DEBUG
 		printf("ISS random 0x%08x, ", tcp_iss);
 #endif
 	}
 
+	/*
+	 * Add the offset in to the computed value.
+	 */
+	tcp_iss += tcp_iss_seq;
+#ifdef TCPISS_DEBUG
+	printf("ISS %08x\n", tcp_iss);
+#endif
 	return tcp_iss;
 }
 



CVS commit: src/sys/netinet

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

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

Log Message:
mv  include to the kernel portion


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

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

Modified files:

Index: src/sys/netinet/in_var.h
diff -u src/sys/netinet/in_var.h:1.101 src/sys/netinet/in_var.h:1.102
--- src/sys/netinet/in_var.h:1.101	Mon Mar  8 15:01:54 2021
+++ src/sys/netinet/in_var.h	Mon Mar  8 17:01:18 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: in_var.h,v 1.101 2021/03/08 20:01:54 christos Exp $	*/
+/*	$NetBSD: in_var.h,v 1.102 2021/03/08 22:01:18 christos Exp $	*/
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -65,7 +65,6 @@
 #define _NETINET_IN_VAR_H_
 
 #include 
-#include 
 
 #define IN_IFF_TENTATIVE	0x01	/* tentative address */
 #define IN_IFF_DUPLICATED	0x02	/* DAD detected duplicate */
@@ -383,6 +382,7 @@ struct in_multi {
 #ifdef _KERNEL
 
 #include 
+#include 
 
 extern pktqueue_t *ip_pktq;
 



CVS commit: src/sys/netinet

2021-03-08 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Mar  8 18:17:27 UTC 2021

Modified Files:
src/sys/netinet: tcp_input.c tcp_subr.c tcp_usrreq.c tcp_var.h

Log Message:
Remove the unused "addin" argument (it was always 0) and go back using
a random iss by default (instead of rfc1948)


To generate a diff of this commit:
cvs rdiff -u -r1.427 -r1.428 src/sys/netinet/tcp_input.c
cvs rdiff -u -r1.286 -r1.287 src/sys/netinet/tcp_subr.c
cvs rdiff -u -r1.228 -r1.229 src/sys/netinet/tcp_usrreq.c
cvs rdiff -u -r1.194 -r1.195 src/sys/netinet/tcp_var.h

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

Modified files:

Index: src/sys/netinet/tcp_input.c
diff -u src/sys/netinet/tcp_input.c:1.427 src/sys/netinet/tcp_input.c:1.428
--- src/sys/netinet/tcp_input.c:1.427	Fri Feb 19 10:43:56 2021
+++ src/sys/netinet/tcp_input.c	Mon Mar  8 13:17:27 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_input.c,v 1.427 2021/02/19 15:43:56 jakllsch Exp $	*/
+/*	$NetBSD: tcp_input.c,v 1.428 2021/03/08 18:17:27 christos Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.427 2021/02/19 15:43:56 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.428 2021/03/08 18:17:27 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -4258,7 +4258,7 @@ syn_cache_add(struct sockaddr *src, stru
 
 		sc->sc_iss = tcp_new_iss1(>sin_addr,
 		>sin_addr, dstin->sin_port,
-		srcin->sin_port, sizeof(dstin->sin_addr), 0);
+		srcin->sin_port, sizeof(dstin->sin_addr));
 		break;
 	}
 #ifdef INET6
@@ -4269,7 +4269,7 @@ syn_cache_add(struct sockaddr *src, stru
 
 		sc->sc_iss = tcp_new_iss1(>sin6_addr,
 		>sin6_addr, dstin6->sin6_port,
-		srcin6->sin6_port, sizeof(dstin6->sin6_addr), 0);
+		srcin6->sin6_port, sizeof(dstin6->sin6_addr));
 		break;
 	}
 #endif

Index: src/sys/netinet/tcp_subr.c
diff -u src/sys/netinet/tcp_subr.c:1.286 src/sys/netinet/tcp_subr.c:1.287
--- src/sys/netinet/tcp_subr.c:1.286	Mon Mar  8 12:53:20 2021
+++ src/sys/netinet/tcp_subr.c	Mon Mar  8 13:17:27 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_subr.c,v 1.286 2021/03/08 17:53:20 christos Exp $	*/
+/*	$NetBSD: tcp_subr.c,v 1.287 2021/03/08 18:17:27 christos Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tcp_subr.c,v 1.286 2021/03/08 17:53:20 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_subr.c,v 1.287 2021/03/08 18:17:27 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -163,7 +163,7 @@ int 	tcp_mssdflt = TCP_MSS;
 int	tcp_minmss = TCP_MINMSS;
 int 	tcp_rttdflt = TCPTV_SRTTDFLT / PR_SLOWHZ;
 int	tcp_do_rfc1323 = 1;	/* window scaling / timestamps (obsolete) */
-int	tcp_do_rfc1948 = 1;	/* ISS by cryptographic hash */
+int	tcp_do_rfc1948 = 0;	/* ISS by cryptographic hash */
 int	tcp_do_sack = 1;	/* selective acknowledgement */
 int	tcp_do_win_scale = 1;	/* RFC1323 window scaling */
 int	tcp_do_timestamps = 1;	/* RFC1323 timestamps */
@@ -2136,21 +2136,19 @@ tcp_seq	 tcp_iss_seq = 0;	/* tcp initial
  * Get a new sequence value given a tcp control block
  */
 tcp_seq
-tcp_new_iss(struct tcpcb *tp, tcp_seq addin)
+tcp_new_iss(struct tcpcb *tp)
 {
 
 	if (tp->t_inpcb != NULL) {
-		return (tcp_new_iss1(>t_inpcb->inp_laddr,
+		return tcp_new_iss1(>t_inpcb->inp_laddr,
 		>t_inpcb->inp_faddr, tp->t_inpcb->inp_lport,
-		tp->t_inpcb->inp_fport, sizeof(tp->t_inpcb->inp_laddr),
-		addin));
+		tp->t_inpcb->inp_fport, sizeof(tp->t_inpcb->inp_laddr));
 	}
 #ifdef INET6
 	if (tp->t_in6pcb != NULL) {
-		return (tcp_new_iss1(>t_in6pcb->in6p_laddr,
+		return tcp_new_iss1(>t_in6pcb->in6p_laddr,
 		>t_in6pcb->in6p_faddr, tp->t_in6pcb->in6p_lport,
-		tp->t_in6pcb->in6p_fport, sizeof(tp->t_in6pcb->in6p_laddr),
-		addin));
+		tp->t_in6pcb->in6p_fport, sizeof(tp->t_in6pcb->in6p_laddr));
 	}
 #endif
 
@@ -2176,7 +2174,7 @@ tcp_iss_secret_init(void)
  */
 tcp_seq
 tcp_new_iss1(void *laddr, void *faddr, u_int16_t lport, u_int16_t fport,
-size_t addrsz, tcp_seq addin)
+size_t addrsz)
 {
 	tcp_seq tcp_iss;
 
@@ -2209,55 +2207,27 @@ tcp_new_iss1(void *laddr, void *faddr, u
 
 		memcpy(_iss, hash, sizeof(tcp_iss));
 
-		/*
-		 * Now increment our "timer", and add it in to
-		 * the computed value.
-		 *
-		 * XXX Use `addin'?
-		 * XXX TCP_ISSINCR too large to use?
-		 */
 #ifdef TCPISS_DEBUG
 		printf("ISS hash 0x%08x, ", tcp_iss);
 #endif
-		tcp_iss += tcp_iss_seq + addin;
+		/*
+		 * Add the offset in to the computed value.
+		 */
+		tcp_iss += tcp_iss_seq;
 #ifdef TCPISS_DEBUG
-		printf("new ISS 0x%08x\n", tcp_iss);
+		printf("ISS %08x\n", tcp_iss);
 #endif
 	} else {
 		/*
 		 * Randomize.
 		 */
 		tcp_iss = cprng_fast32();
-
-		/*
-		 * If we were asked to add some amount to a known value,
-		 * we will take a random value obtained above, 

CVS commit: src/sys/netinet

2021-03-08 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Mar  8 18:03:25 UTC 2021

Modified Files:
src/sys/netinet: files.netinet in_var.h ip_input.c
Removed Files:
src/sys/netinet: ip_id.c

Log Message:
remove now unused pseudo-random ip id code.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sys/netinet/files.netinet
cvs rdiff -u -r1.99 -r1.100 src/sys/netinet/in_var.h
cvs rdiff -u -r1.16 -r0 src/sys/netinet/ip_id.c
cvs rdiff -u -r1.400 -r1.401 src/sys/netinet/ip_input.c

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

Modified files:

Index: src/sys/netinet/files.netinet
diff -u src/sys/netinet/files.netinet:1.28 src/sys/netinet/files.netinet:1.29
--- src/sys/netinet/files.netinet:1.28	Sat Jul 29 01:48:16 2017
+++ src/sys/netinet/files.netinet	Mon Mar  8 13:03:25 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: files.netinet,v 1.28 2017/07/29 05:48:16 maxv Exp $
+#	$NetBSD: files.netinet,v 1.29 2021/03/08 18:03:25 christos Exp $
 
 defflag opt_tcp_debug.h		TCP_DEBUG
 defparam opt_tcp_debug.h	TCP_NDEBUG
@@ -34,7 +34,6 @@ file	netinet/in_proto.c	inet
 file	netinet/in_selsrc.c	inet & ipselsrc
 file	netinet/ip_flow.c	inet & gateway
 file	netinet/ip_icmp.c	inet
-file	netinet/ip_id.c		inet
 file	netinet/ip_input.c	inet
 file	netinet/ip_mroute.c	inet & mrouting
 file	netinet/ip_output.c	inet

Index: src/sys/netinet/in_var.h
diff -u src/sys/netinet/in_var.h:1.99 src/sys/netinet/in_var.h:1.100
--- src/sys/netinet/in_var.h:1.99	Mon Mar  8 12:54:23 2021
+++ src/sys/netinet/in_var.h	Mon Mar  8 13:03:25 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: in_var.h,v 1.99 2021/03/08 17:54:23 christos Exp $	*/
+/*	$NetBSD: in_var.h,v 1.100 2021/03/08 18:03:25 christos Exp $	*/
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -447,14 +447,6 @@ void	in_addrhash_insert(struct in_ifaddr
 void	in_addrhash_remove(struct in_ifaddr *);
 int	ipflow_fastforward(struct mbuf *);
 
-struct ipid_state;
-typedef struct ipid_state ipid_state_t;
-
-ipid_state_t *	ip_id_init(void);
-void		ip_id_fini(ipid_state_t *);
-uint16_t	ip_randomid(ipid_state_t *, uint16_t);
-
-extern ipid_state_t *	ip_ids;
 extern uint16_t		ip_id;
 extern int		ip_do_randomid;
 

Index: src/sys/netinet/ip_input.c
diff -u src/sys/netinet/ip_input.c:1.400 src/sys/netinet/ip_input.c:1.401
--- src/sys/netinet/ip_input.c:1.400	Sun Mar  7 09:58:27 2021
+++ src/sys/netinet/ip_input.c	Mon Mar  8 13:03:25 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_input.c,v 1.400 2021/03/07 14:58:27 christos Exp $	*/
+/*	$NetBSD: ip_input.c,v 1.401 2021/03/08 18:03:25 christos Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.400 2021/03/07 14:58:27 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.401 2021/03/08 18:03:25 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -189,7 +189,6 @@ struct rttimer_queue *ip_mtudisc_timeout
 
 pktqueue_t *		ip_pktq			__read_mostly;
 pfil_head_t *		inet_pfil_hook		__read_mostly;
-ipid_state_t *		ip_ids			__read_mostly;
 percpu_t *		ipstat_percpu		__read_mostly;
 
 static percpu_t		*ipforward_rt_percpu	__cacheline_aligned;
@@ -291,7 +290,6 @@ ip_init(void)
 
 	ip_reass_init();
 
-	ip_ids = ip_id_init();
 	ip_id = time_uptime & 0xf;
 
 #ifdef GATEWAY



CVS commit: src/sys/netinet

2021-03-08 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Mar  8 17:54:43 UTC 2021

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

Log Message:
Add some randomness to the iss offset


To generate a diff of this commit:
cvs rdiff -u -r1.95 -r1.96 src/sys/netinet/tcp_timer.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_timer.c
diff -u src/sys/netinet/tcp_timer.c:1.95 src/sys/netinet/tcp_timer.c:1.96
--- src/sys/netinet/tcp_timer.c:1.95	Thu May  3 03:13:48 2018
+++ src/sys/netinet/tcp_timer.c	Mon Mar  8 12:54:43 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_timer.c,v 1.95 2018/05/03 07:13:48 maxv Exp $	*/
+/*	$NetBSD: tcp_timer.c,v 1.96 2021/03/08 17:54:43 christos Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -93,7 +93,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tcp_timer.c,v 1.95 2018/05/03 07:13:48 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_timer.c,v 1.96 2021/03/08 17:54:43 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -111,6 +111,7 @@ __KERNEL_RCSID(0, "$NetBSD: tcp_timer.c,
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -257,7 +258,7 @@ tcp_slowtimo_work(struct work *wk, void 
 {
 
 	mutex_enter(softnet_lock);
-	tcp_iss_seq += TCP_ISSINCR;			/* increment iss */
+	tcp_iss_seq += TCP_ISSINCR + (TCP_ISS_RANDOM_MASK & cprng_fast32());
 	tcp_now++;	/* for timestamps */
 	mutex_exit(softnet_lock);
 



CVS commit: src/sys/netinet

2021-03-08 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Mar  8 17:54:23 UTC 2021

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

Log Message:
Use a random IPv4 ID because the shuffling algorithm used before could expose
information (Amit Klein)


To generate a diff of this commit:
cvs rdiff -u -r1.98 -r1.99 src/sys/netinet/in_var.h

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

Modified files:

Index: src/sys/netinet/in_var.h
diff -u src/sys/netinet/in_var.h:1.98 src/sys/netinet/in_var.h:1.99
--- src/sys/netinet/in_var.h:1.98	Fri Sep 11 11:22:12 2020
+++ src/sys/netinet/in_var.h	Mon Mar  8 12:54:23 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: in_var.h,v 1.98 2020/09/11 15:22:12 roy Exp $	*/
+/*	$NetBSD: in_var.h,v 1.99 2021/03/08 17:54:23 christos Exp $	*/
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -65,6 +65,7 @@
 #define _NETINET_IN_VAR_H_
 
 #include 
+#include 
 
 #define IN_IFF_TENTATIVE	0x01	/* tentative address */
 #define IN_IFF_DUPLICATED	0x02	/* DAD detected duplicate */
@@ -469,7 +470,8 @@ ip_newid_range(const struct in_ifaddr *i
 
 	if (ip_do_randomid) {
 		/* XXX ignore num */
-		return ip_randomid(ip_ids, ia ? ia->ia_idsalt : 0);
+		id = (uint16_t)cprng_fast32();
+		return id ? id : 1;
 	}
 
 	/* Never allow an IP ID of 0 (detect wrap). */



CVS commit: src/sys/netinet

2021-03-08 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Mar  8 17:53:20 UTC 2021

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

Log Message:
Don't increment the iss sequence on each connection because it exposes
information (Amit Klein)


To generate a diff of this commit:
cvs rdiff -u -r1.285 -r1.286 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.285 src/sys/netinet/tcp_subr.c:1.286
--- src/sys/netinet/tcp_subr.c:1.285	Sun Mar  7 09:58:54 2021
+++ src/sys/netinet/tcp_subr.c	Mon Mar  8 12:53:20 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_subr.c,v 1.285 2021/03/07 14:58:54 christos Exp $	*/
+/*	$NetBSD: tcp_subr.c,v 1.286 2021/03/08 17:53:20 christos Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tcp_subr.c,v 1.285 2021/03/07 14:58:54 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_subr.c,v 1.286 2021/03/08 17:53:20 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -2216,7 +2216,6 @@ tcp_new_iss1(void *laddr, void *faddr, u
 		 * XXX Use `addin'?
 		 * XXX TCP_ISSINCR too large to use?
 		 */
-		tcp_iss_seq += TCP_ISSINCR;
 #ifdef TCPISS_DEBUG
 		printf("ISS hash 0x%08x, ", tcp_iss);
 #endif
@@ -2252,7 +2251,6 @@ tcp_new_iss1(void *laddr, void *faddr, u
 		} else {
 			tcp_iss &= TCP_ISS_RANDOM_MASK;
 			tcp_iss += tcp_iss_seq;
-			tcp_iss_seq += TCP_ISSINCR;
 #ifdef TCPISS_DEBUG
 			printf("ISS %08x\n", tcp_iss);
 #endif



CVS commit: src/sys/netinet

2021-03-07 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Mar  7 15:01:00 UTC 2021

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

Log Message:
netinet/netinet6: Add necessary includes to make these standalone.
(from riastradh)


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sys/netinet/ip6.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/ip6.h
diff -u src/sys/netinet/ip6.h:1.29 src/sys/netinet/ip6.h:1.30
--- src/sys/netinet/ip6.h:1.29	Wed Feb  3 13:13:13 2021
+++ src/sys/netinet/ip6.h	Sun Mar  7 10:01:00 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6.h,v 1.29 2021/02/03 18:13:13 roy Exp $	*/
+/*	$NetBSD: ip6.h,v 1.30 2021/03/07 15:01:00 christos Exp $	*/
 /*	$KAME: ip6.h,v 1.45 2003/06/05 04:46:38 keiichi Exp $	*/
 
 /*
@@ -64,6 +64,11 @@
 #ifndef _NETINET_IP6_H_
 #define _NETINET_IP6_H_
 
+#include 
+#include 
+
+#include 
+
 /*
  * Definition for internet protocol version 6.
  * RFC 2460



CVS commit: src/sys/netinet

2021-03-07 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Mar  7 14:58:54 UTC 2021

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

Log Message:
netinet: Enable RFC 1948 pseudorandom TCP ISS selection by default.
(from riastradh)


To generate a diff of this commit:
cvs rdiff -u -r1.284 -r1.285 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.284 src/sys/netinet/tcp_subr.c:1.285
--- src/sys/netinet/tcp_subr.c:1.284	Fri Jun 12 07:04:45 2020
+++ src/sys/netinet/tcp_subr.c	Sun Mar  7 09:58:54 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_subr.c,v 1.284 2020/06/12 11:04:45 roy Exp $	*/
+/*	$NetBSD: tcp_subr.c,v 1.285 2021/03/07 14:58:54 christos Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tcp_subr.c,v 1.284 2020/06/12 11:04:45 roy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_subr.c,v 1.285 2021/03/07 14:58:54 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -163,7 +163,7 @@ int 	tcp_mssdflt = TCP_MSS;
 int	tcp_minmss = TCP_MINMSS;
 int 	tcp_rttdflt = TCPTV_SRTTDFLT / PR_SLOWHZ;
 int	tcp_do_rfc1323 = 1;	/* window scaling / timestamps (obsolete) */
-int	tcp_do_rfc1948 = 0;	/* ISS by cryptographic hash */
+int	tcp_do_rfc1948 = 1;	/* ISS by cryptographic hash */
 int	tcp_do_sack = 1;	/* selective acknowledgement */
 int	tcp_do_win_scale = 1;	/* RFC1323 window scaling */
 int	tcp_do_timestamps = 1;	/* RFC1323 timestamps */



CVS commit: src/sys/netinet

2021-03-07 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Mar  7 14:58:28 UTC 2021

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

Log Message:
netinet: Enable random IP fragment ids by default (from riastradh)


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

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

Modified files:

Index: src/sys/netinet/ip_input.c
diff -u src/sys/netinet/ip_input.c:1.399 src/sys/netinet/ip_input.c:1.400
--- src/sys/netinet/ip_input.c:1.399	Fri Feb 19 09:51:59 2021
+++ src/sys/netinet/ip_input.c	Sun Mar  7 09:58:27 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_input.c,v 1.399 2021/02/19 14:51:59 christos Exp $	*/
+/*	$NetBSD: ip_input.c,v 1.400 2021/03/07 14:58:27 christos Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.399 2021/02/19 14:51:59 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.400 2021/03/07 14:58:27 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -168,7 +168,7 @@ int ip_directedbcast = 0;
 int ip_allowsrcrt = 0;
 int ip_mtudisc = 1;
 int ip_mtudisc_timeout = IPMTUDISCTIMEOUT;
-int ip_do_randomid = 0;
+int ip_do_randomid = 1;
 
 /*
  * XXX - Setting ip_checkinterface mostly implements the receive side of



CVS commit: src/sys/netinet

2021-02-19 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Fri Feb 19 15:43:56 UTC 2021

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

Log Message:
it's spelled struct tcphdr, not struct tcp_hdr


To generate a diff of this commit:
cvs rdiff -u -r1.426 -r1.427 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.426 src/sys/netinet/tcp_input.c:1.427
--- src/sys/netinet/tcp_input.c:1.426	Fri Feb 19 14:51:59 2021
+++ src/sys/netinet/tcp_input.c	Fri Feb 19 15:43:56 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_input.c,v 1.426 2021/02/19 14:51:59 christos Exp $	*/
+/*	$NetBSD: tcp_input.c,v 1.427 2021/02/19 15:43:56 jakllsch Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.426 2021/02/19 14:51:59 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.427 2021/02/19 15:43:56 jakllsch Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1274,7 +1274,7 @@ tcp_input(struct mbuf *m, int off, int p
 	 * Enforce alignment requirements that are violated in
 	 * some cases, see kern/50766 for details.
 	 */
-	if (ACCESSIBLE_POINTER(th, struct tcp_hdr) == 0) {
+	if (ACCESSIBLE_POINTER(th, struct tcphdr) == 0) {
 		m = m_copyup(m, off + sizeof(struct tcphdr), 0);
 		if (m == NULL) {
 			TCP_STATINC(TCP_STAT_RCVSHORT);
@@ -1282,7 +1282,7 @@ tcp_input(struct mbuf *m, int off, int p
 		}
 		th = (struct tcphdr *)(mtod(m, char *) + off);
 	}
-	KASSERT(ACCESSIBLE_POINTER(th, struct tcp_hdr));
+	KASSERT(ACCESSIBLE_POINTER(th, struct tcphdr));
 
 	/*
 	 * Get IP and TCP header.
@@ -1362,7 +1362,7 @@ tcp_input(struct mbuf *m, int off, int p
 			TCP_STATINC(TCP_STAT_RCVSHORT);
 			return;
 		}
-		KASSERT(ACCESSIBLE_POINTER(th, struct tcp_hdr));
+		KASSERT(ACCESSIBLE_POINTER(th, struct tcphdr));
 		optlen = thlen - sizeof(struct tcphdr);
 		optp = ((u_int8_t *)th) + sizeof(struct tcphdr);
 



CVS commit: src/sys/netinet

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

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

Log Message:
One more time: backout arp header alignment, now that the alignment
asserted has been aligned to reality.
Also remove unused ARP_HDR_ALIGNED_P macro. Pointed out by roy.


To generate a diff of this commit:
cvs rdiff -u -r1.305 -r1.306 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.305 src/sys/netinet/if_arp.c:1.306
--- src/sys/netinet/if_arp.c:1.305	Tue Feb 16 05:44:13 2021
+++ src/sys/netinet/if_arp.c	Tue Feb 16 10:22:52 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_arp.c,v 1.305 2021/02/16 05:44:13 martin Exp $	*/
+/*	$NetBSD: if_arp.c,v 1.306 2021/02/16 10:22:52 martin Exp $	*/
 
 /*
  * Copyright (c) 1998, 2000, 2008 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.305 2021/02/16 05:44:13 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.306 2021/02/16 10:22:52 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -133,12 +133,6 @@ __KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1
  */
 #define ETHERTYPE_IPTRAILERS ETHERTYPE_TRAIL
 
-#ifdef __NO_STRICT_ALIGNMENT
-#define	ARP_HDR_ALIGNED_P(ar)	1
-#else
-#define	ARP_HDR_ALIGNED_P(ar)	vaddr_t) (ar)) & 1) == 0)
-#endif
-
 /* timers */
 static int arp_reachable = REACHABLE_TIME;
 static int arp_retrans = RETRANS_TIMER;
@@ -707,9 +701,10 @@ arpintr(void)
 		MCLAIM(m, _mowner);
 		ARP_STATINC(ARP_STAT_RCVTOTAL);
 
-		if (m_get_aligned_hdr(, ARP_HDR_ALIGNMENT, sizeof(*ar),
-		false) != 0)
-			goto badlen;
+		if (__predict_false(m->m_len < sizeof(*ar))) {
+			if ((m = m_pullup(m, sizeof(*ar))) == NULL)
+goto badlen;
+		}
 		ar = mtod(m, struct arphdr *);
 		KASSERT(POINTER_ALIGNED_P(ar, ARP_HDR_ALIGNMENT));
 



CVS commit: src/sys/netinet

2021-02-15 Thread Martin Husemann
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).


To generate a diff of this commit:
cvs rdiff -u -r1.304 -r1.305 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.304 src/sys/netinet/if_arp.c:1.305
--- src/sys/netinet/if_arp.c:1.304	Mon Feb 15 19:49:17 2021
+++ src/sys/netinet/if_arp.c	Tue Feb 16 05:44:13 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_arp.c,v 1.304 2021/02/15 19:49:17 christos Exp $	*/
+/*	$NetBSD: if_arp.c,v 1.305 2021/02/16 05:44:13 martin Exp $	*/
 
 /*
  * Copyright (c) 1998, 2000, 2008 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.304 2021/02/15 19:49:17 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.305 2021/02/16 05:44:13 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -707,10 +707,9 @@ arpintr(void)
 		MCLAIM(m, _mowner);
 		ARP_STATINC(ARP_STAT_RCVTOTAL);
 
-		if (__predict_false(m->m_len < sizeof(*ar))) {
-			if ((m = m_pullup(m, sizeof(*ar))) == NULL)
-goto badlen;
-		}
+		if (m_get_aligned_hdr(, ARP_HDR_ALIGNMENT, sizeof(*ar),
+		false) != 0)
+			goto badlen;
 		ar = mtod(m, struct arphdr *);
 		KASSERT(POINTER_ALIGNED_P(ar, ARP_HDR_ALIGNMENT));
 



CVS commit: src/sys/netinet

2021-02-15 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Feb 15 19:49:17 UTC 2021

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

Log Message:
Undo previous; POINTER_ALIGNED_P was broken.


To generate a diff of this commit:
cvs rdiff -u -r1.303 -r1.304 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.303 src/sys/netinet/if_arp.c:1.304
--- src/sys/netinet/if_arp.c:1.303	Mon Feb 15 14:19:29 2021
+++ src/sys/netinet/if_arp.c	Mon Feb 15 14:49:17 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_arp.c,v 1.303 2021/02/15 19:19:29 christos Exp $	*/
+/*	$NetBSD: if_arp.c,v 1.304 2021/02/15 19:49:17 christos Exp $	*/
 
 /*
  * Copyright (c) 1998, 2000, 2008 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.303 2021/02/15 19:19:29 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.304 2021/02/15 19:49:17 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -707,9 +707,10 @@ arpintr(void)
 		MCLAIM(m, _mowner);
 		ARP_STATINC(ARP_STAT_RCVTOTAL);
 
-		if (m_get_aligned_hdr(, ARP_HDR_ALIGNMENT, sizeof(*ar),
-		false) != 0)
-			goto badlen;
+		if (__predict_false(m->m_len < sizeof(*ar))) {
+			if ((m = m_pullup(m, sizeof(*ar))) == NULL)
+goto badlen;
+		}
 		ar = mtod(m, struct arphdr *);
 		KASSERT(POINTER_ALIGNED_P(ar, ARP_HDR_ALIGNMENT));
 



CVS commit: src/sys/netinet

2021-02-15 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Feb 15 19:19:30 UTC 2021

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

Log Message:
put back alignment (reported by martin@)


To generate a diff of this commit:
cvs rdiff -u -r1.302 -r1.303 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.302 src/sys/netinet/if_arp.c:1.303
--- src/sys/netinet/if_arp.c:1.302	Sun Feb 14 15:58:35 2021
+++ src/sys/netinet/if_arp.c	Mon Feb 15 14:19:29 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_arp.c,v 1.302 2021/02/14 20:58:35 christos Exp $	*/
+/*	$NetBSD: if_arp.c,v 1.303 2021/02/15 19:19:29 christos Exp $	*/
 
 /*
  * Copyright (c) 1998, 2000, 2008 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.302 2021/02/14 20:58:35 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.303 2021/02/15 19:19:29 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -707,10 +707,9 @@ arpintr(void)
 		MCLAIM(m, _mowner);
 		ARP_STATINC(ARP_STAT_RCVTOTAL);
 
-		if (__predict_false(m->m_len < sizeof(*ar))) {
-			if ((m = m_pullup(m, sizeof(*ar))) == NULL)
-goto badlen;
-		}
+		if (m_get_aligned_hdr(, ARP_HDR_ALIGNMENT, sizeof(*ar),
+		false) != 0)
+			goto badlen;
 		ar = mtod(m, struct arphdr *);
 		KASSERT(POINTER_ALIGNED_P(ar, ARP_HDR_ALIGNMENT));
 



CVS commit: src/sys/netinet

2021-02-14 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Feb 15 03:41:01 UTC 2021

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

Log Message:
Fix build failure for options GATEWAY.


To generate a diff of this commit:
cvs rdiff -u -r1.83 -r1.84 src/sys/netinet/ip_flow.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_flow.c
diff -u src/sys/netinet/ip_flow.c:1.83 src/sys/netinet/ip_flow.c:1.84
--- src/sys/netinet/ip_flow.c:1.83	Sun Feb 14 20:58:35 2021
+++ src/sys/netinet/ip_flow.c	Mon Feb 15 03:41:01 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_flow.c,v 1.83 2021/02/14 20:58:35 christos Exp $	*/
+/*	$NetBSD: ip_flow.c,v 1.84 2021/02/15 03:41:01 knakahara Exp $	*/
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip_flow.c,v 1.83 2021/02/14 20:58:35 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_flow.c,v 1.84 2021/02/15 03:41:01 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -231,7 +231,7 @@ ipflow_fastforward(struct mbuf *m)
 	 * IP header with no option and valid version and length
 	 */
 	ip = mtod(m, struct ip *);
-	if (!POINTER_ALIGNED_P(ip, IP_HDR_ALIGNMENT) {
+	if (!POINTER_ALIGNED_P(ip, IP_HDR_ALIGNMENT)) {
 		memcpy(_store, mtod(m, const void *), sizeof(ip_store));
 		ip = _store;
 	}



CVS commit: src/sys/netinet

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

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

Log Message:
Guard CTASSERT


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/sys/netinet/if_ether.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/if_ether.h
diff -u src/sys/netinet/if_ether.h:1.36 src/sys/netinet/if_ether.h:1.37
--- src/sys/netinet/if_ether.h:1.36	Wed Feb  3 11:53:43 2021
+++ src/sys/netinet/if_ether.h	Wed Feb  3 17:10:13 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ether.h,v 1.36 2021/02/03 11:53:43 roy Exp $	*/
+/*	$NetBSD: if_ether.h,v 1.37 2021/02/03 17:10:13 roy Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1993
@@ -76,7 +76,9 @@ struct	ether_arp {
 	u_int8_t arp_tha[ETHER_ADDR_LEN];	/* target hardware address */
 	u_int8_t arp_tpa[4];			/* target protocol address */
 };
+#ifdef CTASSERT
 CTASSERT(sizeof(struct ether_arp) == 28);
+#endif
 #define	arp_hrd	ea_hdr.ar_hrd
 #define	arp_pro	ea_hdr.ar_pro
 #define	arp_hln	ea_hdr.ar_hln



CVS commit: src/sys/netinet

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

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

Log Message:
tcp_debug: restore __packed


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/netinet/tcp_debug.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_debug.h
diff -u src/sys/netinet/tcp_debug.h:1.19 src/sys/netinet/tcp_debug.h:1.20
--- src/sys/netinet/tcp_debug.h:1.19	Wed Feb  3 05:51:40 2021
+++ src/sys/netinet/tcp_debug.h	Wed Feb  3 11:52:23 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_debug.h,v 1.19 2021/02/03 05:51:40 roy Exp $	*/
+/*	$NetBSD: tcp_debug.h,v 1.20 2021/02/03 11:52:23 roy Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1993
@@ -58,7 +58,7 @@ struct	tcp_debug {
 	} td_ti6;
 	short	td_req;
 	struct	tcpcb td_cb;
-};
+} __packed;
 
 #define	TA_INPUT	0
 #define	TA_OUTPUT	1



CVS commit: src/sys/netinet

2021-02-02 Thread YAMAMOTO Takashi
Module Name:src
Committed By:   yamt
Date:   Tue Feb  2 10:48:33 UTC 2021

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

Log Message:
arp: Plug an mbuf leak


To generate a diff of this commit:
cvs rdiff -u -r1.297 -r1.298 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.297 src/sys/netinet/if_arp.c:1.298
--- src/sys/netinet/if_arp.c:1.297	Tue Sep 15 10:05:36 2020
+++ src/sys/netinet/if_arp.c	Tue Feb  2 10:48:33 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_arp.c,v 1.297 2020/09/15 10:05:36 roy Exp $	*/
+/*	$NetBSD: if_arp.c,v 1.298 2021/02/02 10:48:33 yamt Exp $	*/
 
 /*
  * Copyright (c) 1998, 2000, 2008 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.297 2020/09/15 10:05:36 roy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.298 2021/02/02 10:48:33 yamt Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -1389,7 +1389,7 @@ arp_llinfo_missed(struct ifnet *ifp, con
 			mdaddr = ip->ip_src;
 
 		/* ip_input() will send ICMP_UNREACH_HOST, not us. */
-		m_free(m);
+		m_freem(m);
 	}
 
 	if (mdaddr.s_addr != INADDR_ANY) {



CVS commit: src/sys/netinet

2020-12-03 Thread Jason R Thorpe
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.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/netinet/files.ipfilter

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/files.ipfilter
diff -u src/sys/netinet/files.ipfilter:1.15 src/sys/netinet/files.ipfilter:1.16
--- src/sys/netinet/files.ipfilter:1.15	Fri Mar 23 21:30:18 2012
+++ src/sys/netinet/files.ipfilter	Fri Dec  4 00:44:39 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: files.ipfilter,v 1.15 2012/03/23 21:30:18 christos Exp $
+#	$NetBSD: files.ipfilter,v 1.16 2020/12/04 00:44:39 thorpej Exp $
 
 defflag	opt_ipfilter.h	IPFILTER_LOG		# logging of ip packets
 defflag	opt_ipfilter.h	IPFILTER_DEFAULT_BLOCK
@@ -41,3 +41,4 @@ file	external/bsd/ipf/netinet/ip_fil_com
 file	external/bsd/ipf/netinet/radix_ipf.c		ipfilter
 
 makeoptions	ipfilter	CPPFLAGS+="-I$S/external/bsd/ipf"
+makeoptions	ipfilter	"CWARNFLAGS.ip_sync.c"+="-Wno-error"



CVS commit: src/sys/netinet

2020-11-12 Thread Frank Kardel
Module Name:src
Committed By:   kardel
Date:   Thu Nov 12 13:13:45 UTC 2020

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

Log Message:
PR kern/55779:

restore non-desctructive guarantee of ip_mforward() mbuf
argument. This avoids generation invalid UDP checksums
on multicast packets in ip_output().

XXX the root cause of the misguided fix in 2008 should be
XXX investigated


To generate a diff of this commit:
cvs rdiff -u -r1.163 -r1.164 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.163 src/sys/netinet/ip_mroute.c:1.164
--- src/sys/netinet/ip_mroute.c:1.163	Fri Sep 14 05:09:51 2018
+++ src/sys/netinet/ip_mroute.c	Thu Nov 12 13:13:45 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_mroute.c,v 1.163 2018/09/14 05:09:51 maxv Exp $	*/
+/*	$NetBSD: ip_mroute.c,v 1.164 2020/11/12 13:13:45 kardel Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -93,7 +93,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip_mroute.c,v 1.163 2018/09/14 05:09:51 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_mroute.c,v 1.164 2020/11/12 13:13:45 kardel Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -225,6 +225,8 @@ static int tbf_dq_sel(struct vif *, stru
 static void tbf_send_packet(struct vif *, struct mbuf *);
 static void tbf_update_tokens(struct vif *);
 static int priority(struct vif *, struct ip *);
+static int ip_mforward_real(struct mbuf *, struct ifnet *);
+
 
 /*
  * Bandwidth monitoring
@@ -1268,6 +1270,34 @@ socket_send(struct socket *s, struct mbu
 int
 ip_mforward(struct mbuf *m, struct ifnet *ifp)
 {
+	int rc;
+	/*
+	 * save csum_flags to uphold the 
+	 * "unscathed" guarantee.
+	 * ip_output() relies on that and
+	 * without it we send out
+	 * multicast packets with an invalid
+	 * checksum
+	 *
+	 * see PR kern/55779
+	 */
+	int csum_flags = m->m_pkthdr.csum_flags;
+
+	/*
+	 * Temporarily clear any in-bound checksum flags for this packet.
+	 */
+	m->m_pkthdr.csum_flags = 0;
+
+	rc = ip_mforward_real(m, ifp);
+
+	m->m_pkthdr.csum_flags = csum_flags;
+
+	return rc;
+}
+
+static int
+ip_mforward_real(struct mbuf *m, struct ifnet *ifp)
+{
 	struct ip *ip = mtod(m, struct ip *);
 	struct mfc *rt;
 	static int srctun = 0;
@@ -1305,11 +1335,6 @@ ip_mforward(struct mbuf *m, struct ifnet
 	}
 
 	/*
-	 * Clear any in-bound checksum flags for this packet.
-	 */
-	m->m_pkthdr.csum_flags = 0;
-
-	/*
 	 * Don't forward a packet with time-to-live of zero or one,
 	 * or a packet destined to a local-only group.
 	 */



CVS commit: src/sys/netinet

2020-10-17 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Oct 17 08:50:38 UTC 2020

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

Log Message:
Fix RTT values reported by TCP_INFO.


To generate a diff of this commit:
cvs rdiff -u -r1.226 -r1.227 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.226 src/sys/netinet/tcp_usrreq.c:1.227
--- src/sys/netinet/tcp_usrreq.c:1.226	Mon Apr 13 15:54:45 2020
+++ src/sys/netinet/tcp_usrreq.c	Sat Oct 17 08:50:38 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_usrreq.c,v 1.226 2020/04/13 15:54:45 maxv Exp $	*/
+/*	$NetBSD: tcp_usrreq.c,v 1.227 2020/10/17 08:50:38 mlelstv Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -99,7 +99,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tcp_usrreq.c,v 1.226 2020/04/13 15:54:45 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_usrreq.c,v 1.227 2020/10/17 08:50:38 mlelstv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -258,8 +258,10 @@ tcp_fill_info(struct tcpcb *tp, struct t
 	ti->tcpi_rto = tp->t_rxtcur * tick;
 	ti->tcpi_last_data_recv = (long)(getticks() -
 	 (int)tp->t_rcvtime) * tick;
-	ti->tcpi_rtt = ((u_int64_t)tp->t_srtt * tick) >> TCP_RTT_SHIFT;
-	ti->tcpi_rttvar = ((u_int64_t)tp->t_rttvar * tick) >> TCP_RTTVAR_SHIFT;
+	ti->tcpi_rtt = ((u_int64_t)tp->t_srtt * tick / PR_SLOWHZ)
+	   >> (TCP_RTT_SHIFT + 2);
+	ti->tcpi_rttvar = ((u_int64_t)tp->t_rttvar * tick / PR_SLOWHZ)
+	   >> (TCP_RTTVAR_SHIFT + 2);
 
 	ti->tcpi_snd_ssthresh = tp->snd_ssthresh;
 	/* Linux API wants these in # of segments, apparently */



CVS commit: src/sys/netinet

2020-10-14 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Wed Oct 14 13:43:56 UTC 2020

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

Log Message:
carp: Don't set a link level address if vhid == -1

Link level address for carp is dervied from vhid.
Until vhid is set, carp is useless, so don't give it a link level address
until a vhid is set.

This fixes recent test case breakage where carp was fixed to actually
print the ethernet address set by default. Note that neither carp nor
the test case itself was actually broken as the error is the common
ATF net code assuming that a cloned interface's link level address is
unique upon creation.


To generate a diff of this commit:
cvs rdiff -u -r1.113 -r1.114 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.113 src/sys/netinet/ip_carp.c:1.114
--- src/sys/netinet/ip_carp.c:1.113	Mon Oct 12 15:18:48 2020
+++ src/sys/netinet/ip_carp.c	Wed Oct 14 13:43:56 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_carp.c,v 1.113 2020/10/12 15:18:48 roy Exp $	*/
+/*	$NetBSD: ip_carp.c,v 1.114 2020/10/14 13:43:56 roy 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.113 2020/10/12 15:18:48 roy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_carp.c,v 1.114 2020/10/14 13:43:56 roy Exp $");
 
 /*
  * TODO:
@@ -878,7 +878,7 @@ carp_clone_create(struct if_clone *ifc, 
 	IFQ_SET_MAXLEN(>if_snd, ifqmaxlen);
 	IFQ_SET_READY(>if_snd);
 	rv = if_initialize(ifp);
-	if (rv != 0) {	
+	if (rv != 0) {
 		callout_destroy(>sc_ad_tmo);
 		callout_destroy(>sc_md_tmo);
 		callout_destroy(>sc_md6_tmo);
@@ -1733,7 +1733,15 @@ carp_set_ifp(struct carp_softc *sc, stru
 static void
 carp_set_enaddr(struct carp_softc *sc)
 {
+	struct ifnet *ifp = >sc_if;
 	uint8_t enaddr[ETHER_ADDR_LEN];
+
+	if (sc->sc_vhid == -1) {
+		ifp->if_addrlen = 0;
+		if_alloc_sadl(ifp);
+		return;
+	}
+
 	if (sc->sc_carpdev && sc->sc_carpdev->if_type == IFT_ISO88025) {
 		enaddr[0] = 3;
 		enaddr[1] = 0;
@@ -1749,7 +1757,8 @@ carp_set_enaddr(struct carp_softc *sc)
 		enaddr[4] = 1;
 		enaddr[5] = sc->sc_vhid;
 	}
-	if_set_sadl(>sc_if, enaddr, sizeof(enaddr), false);
+
+	if_set_sadl(ifp, enaddr, sizeof(enaddr), false);
 }
 
 #if 0



CVS commit: src/sys/netinet

2020-10-12 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Mon Oct 12 11:07:27 UTC 2020

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

Log Message:
carp: Set ethernet address just before interface registation

Otherwise ifconfig reports SIOCGLIFADDR errors.


To generate a diff of this commit:
cvs rdiff -u -r1.111 -r1.112 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.111 src/sys/netinet/ip_carp.c:1.112
--- src/sys/netinet/ip_carp.c:1.111	Fri Oct  9 08:10:41 2020
+++ src/sys/netinet/ip_carp.c	Mon Oct 12 11:07:27 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_carp.c,v 1.111 2020/10/09 08:10:41 roy Exp $	*/
+/*	$NetBSD: ip_carp.c,v 1.112 2020/10/12 11:07:27 roy 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.111 2020/10/09 08:10:41 roy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_carp.c,v 1.112 2020/10/12 11:07:27 roy Exp $");
 
 /*
  * TODO:
@@ -887,10 +887,10 @@ carp_clone_create(struct if_clone *ifc, 
 		return rv;
 	}
 	ether_ifattach(ifp, NULL);
-	carp_set_enaddr(sc);
 	/* Overwrite ethernet defaults */
 	ifp->if_type = IFT_CARP;
 	ifp->if_output = carp_output;
+	carp_set_enaddr(sc);
 	if_register(ifp);
 
 	return (0);



CVS commit: src/sys/netinet

2020-10-09 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Fri Oct  9 08:10:41 UTC 2020

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

Log Message:
carp: Remove media, software should use link status.

carp literally has no media just like ppp, vlan, etc.


To generate a diff of this commit:
cvs rdiff -u -r1.110 -r1.111 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.110 src/sys/netinet/ip_carp.c:1.111
--- src/sys/netinet/ip_carp.c:1.110	Thu Feb  6 23:30:20 2020
+++ src/sys/netinet/ip_carp.c	Fri Oct  9 08:10:41 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_carp.c,v 1.110 2020/02/06 23:30:20 thorpej Exp $	*/
+/*	$NetBSD: ip_carp.c,v 1.111 2020/10/09 08:10:41 roy 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.110 2020/02/06 23:30:20 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_carp.c,v 1.111 2020/10/09 08:10:41 roy Exp $");
 
 /*
  * TODO:
@@ -67,7 +67,6 @@ __KERNEL_RCSID(0, "$NetBSD: ip_carp.c,v 
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -116,7 +115,6 @@ struct carp_softc {
 #define	sc_carpdev	sc_ac.ec_if.if_carpdev
 	int ah_cookie;
 	int lh_cookie;
-	struct ifmedia  sc_im;	/* ifmedia for link status */
 	struct ip_moptions sc_imo;
 #ifdef INET6
 	struct ip6_moptions sc_im6o;
@@ -228,8 +226,6 @@ static int	carp_clone_destroy(struct ifn
 static int	carp_ether_addmulti(struct carp_softc *, struct ifreq *);
 static int	carp_ether_delmulti(struct carp_softc *, struct ifreq *);
 static void	carp_ether_purgemulti(struct carp_softc *);
-static int  carp_mediachange(struct ifnet *ifp);
-static void	carp_mediastatus(struct ifnet *ifp, struct ifmediareq *imr);
 static void	carp_update_link_state(struct carp_softc *sc);
 
 static void	sysctl_net_inet_carp_setup(struct sysctllog **);
@@ -890,8 +886,6 @@ carp_clone_create(struct if_clone *ifc, 
 
 		return rv;
 	}
-	ifmedia_init(>sc_im, 0, carp_mediachange, carp_mediastatus);
-	sc->sc_im.ifm_media = IFM_CARP;
 	ether_ifattach(ifp, NULL);
 	carp_set_enaddr(sc);
 	/* Overwrite ethernet defaults */
@@ -910,7 +904,6 @@ carp_clone_destroy(struct ifnet *ifp)
 	carpdetach(ifp->if_softc);
 	ether_ifdetach(ifp);
 	if_detach(ifp);
-	ifmedia_fini(>sc_im);
 	callout_destroy(>sc_ad_tmo);
 	callout_destroy(>sc_md_tmo);
 	callout_destroy(>sc_md6_tmo);
@@ -2173,10 +2166,6 @@ carp_ioctl(struct ifnet *ifp, u_long cmd
 			error = 0;
 		break;
 
-case SIOCGIFMEDIA:
-		error = ifmedia_ioctl(ifp, ifr, >sc_im, cmd);
-		break;
-
 	default:
 		error = ether_ioctl(ifp, cmd, data);
 	}
@@ -2212,28 +2201,6 @@ carp_output(struct ifnet *ifp, struct mb
 	}
 }
 
-static int
-carp_mediachange(struct ifnet *ifp)
-{
-return (0);
-}
-
-static void
-carp_mediastatus(struct ifnet *ifp, struct ifmediareq *imr)
-{
-switch (ifp->if_link_state) {
-case LINK_STATE_UP:
-imr->ifm_status = IFM_AVALID | IFM_ACTIVE;
-break;
-case LINK_STATE_DOWN:
-imr->ifm_status = IFM_AVALID;
-break;
-default:
-imr->ifm_status = 0;
-break;
-}
-}
-
 static void
 carp_set_state(struct carp_softc *sc, int state)
 {



CVS commit: src/sys/netinet

2020-09-13 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Sun Sep 13 11:47:12 UTC 2020

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

Log Message:
inet: Fix build without ARP


To generate a diff of this commit:
cvs rdiff -u -r1.422 -r1.423 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.422 src/sys/netinet/tcp_input.c:1.423
--- src/sys/netinet/tcp_input.c:1.422	Fri Sep 11 15:16:00 2020
+++ src/sys/netinet/tcp_input.c	Sun Sep 13 11:47:12 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_input.c,v 1.422 2020/09/11 15:16:00 roy Exp $	*/
+/*	$NetBSD: tcp_input.c,v 1.423 2020/09/13 11:47:12 roy Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.422 2020/09/11 15:16:00 roy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.423 2020/09/13 11:47:12 roy Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -186,7 +186,7 @@ __KERNEL_RCSID(0, "$NetBSD: tcp_input.c,
 #include 
 #include 
 
-#ifdef INET
+#if NARP > 0
 #include 
 #endif
 #ifdef INET6
@@ -266,7 +266,7 @@ nd_hint(struct tcpcb *tp)
 		return;
 
 	switch (tp->t_family) {
-#ifdef INET
+#if NARP > 0
 	case AF_INET:
 		if (tp->t_inpcb != NULL)
 			ro = >t_inpcb->inp_route;
@@ -288,7 +288,7 @@ nd_hint(struct tcpcb *tp)
 		return;
 
 	switch (tp->t_family) {
-#ifdef INET
+#if NARP > 0
 	case AF_INET:
 		arp_nud_hint(rt);
 		break;



CVS commit: src/sys/netinet

2020-09-11 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Fri Sep 11 15:19:31 UTC 2020

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

Log Message:
in: No need to set expire here anymore


To generate a diff of this commit:
cvs rdiff -u -r1.238 -r1.239 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.238 src/sys/netinet/in.c:1.239
--- src/sys/netinet/in.c:1.238	Sat Aug 29 17:41:14 2020
+++ src/sys/netinet/in.c	Fri Sep 11 15:19:31 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: in.c,v 1.238 2020/08/29 17:41:14 christos Exp $	*/
+/*	$NetBSD: in.c,v 1.239 2020/09/11 15:19:31 roy Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in.c,v 1.238 2020/08/29 17:41:14 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in.c,v 1.239 2020/09/11 15:19:31 roy Exp $");
 
 #include "arp.h"
 
@@ -1959,11 +1959,6 @@ in_lltable_new(struct in_addr addr4, u_i
 	if (lle == NULL)		/* NB: caller generates msg */
 		return NULL;
 
-	/*
-	 * For IPv4 this will trigger "arpresolve" to generate
-	 * an ARP request.
-	 */
-	lle->la_expire = time_uptime; /* mark expired */
 	lle->r_l3addr.addr4 = addr4;
 	lle->lle_refcnt = 1;
 	lle->lle_free = in_lltable_destroy_lle;



CVS commit: src/sys/netinet

2020-09-11 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Fri Sep 11 15:08:25 UTC 2020

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

Log Message:
tcp_input: Adjust for ND changes


To generate a diff of this commit:
cvs rdiff -u -r1.420 -r1.421 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.420 src/sys/netinet/tcp_input.c:1.421
--- src/sys/netinet/tcp_input.c:1.420	Fri Sep 11 09:08:47 2020
+++ src/sys/netinet/tcp_input.c	Fri Sep 11 15:08:25 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_input.c,v 1.420 2020/09/11 09:08:47 kardel Exp $	*/
+/*	$NetBSD: tcp_input.c,v 1.421 2020/09/11 15:08:25 roy Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.420 2020/09/11 09:08:47 kardel Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.421 2020/09/11 15:08:25 roy Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -253,24 +253,46 @@ static void syn_cache_timer(void *);
 /*
  * Neighbor Discovery, Neighbor Unreachability Detection Upper layer hint.
  */
-#ifdef INET6
-static inline void
-nd6_hint(struct tcpcb *tp)
+static void
+nd_hint(struct tcpcb *tp)
 {
-	struct rtentry *rt = NULL;
+	struct route *ro = NULL;
+	struct rtentry *rt;
+
+	if (tp == NULL)
+		return;
+
+	switch (tp->t_family) {
+#ifdef INET6
+	case AF_INET6:
+		if (tp->t_in6pcb != NULL)
+			ro = >t_in6pcb->in6p_route;
+		break;
+#endif
+	}
+
+	if (ro == NULL)
+		return;
 
-	if (tp != NULL && tp->t_in6pcb != NULL && tp->t_family == AF_INET6 &&
-	(rt = rtcache_validate(>t_in6pcb->in6p_route)) != NULL) {
+	rt = rtcache_validate(ro);
+	if (rt == NULL)
+		return;
+
+	switch (tp->t_family) {
+#ifdef INET
+	case AF_INET:
+		arp_nud_hint(rt);
+		break;
+#endif
+#ifdef INET6
+	case AF_INET6:
 		nd6_nud_hint(rt);
-		rtcache_unref(rt, >t_in6pcb->in6p_route);
+		break;
+#endif
 	}
+
+	rtcache_unref(rt, ro);
 }
-#else
-static inline void
-nd6_hint(struct tcpcb *tp)
-{
-}
-#endif
 
 /*
  * Compute ACK transmission behavior.  Delay the ACK unless
@@ -769,7 +791,7 @@ present:
 
 	tp->rcv_nxt += q->ipqe_len;
 	pkt_flags = q->ipqe_flags & TH_FIN;
-	nd6_hint(tp);
+	nd_hint(tp);
 
 	TAILQ_REMOVE(>segq, q, ipqe_q);
 	TAILQ_REMOVE(>timeq, q, ipqe_timeq);
@@ -1884,7 +1906,7 @@ after_listen:
 tcps[TCP_STAT_RCVACKPACK]++;
 tcps[TCP_STAT_RCVACKBYTE] += acked;
 TCP_STAT_PUTREF();
-nd6_hint(tp);
+nd_hint(tp);
 
 if (acked > (tp->t_lastoff - tp->t_inoff))
 	tp->t_lastm = NULL;
@@ -1967,7 +1989,7 @@ after_listen:
 			tcps[TCP_STAT_RCVPACK]++;
 			tcps[TCP_STAT_RCVBYTE] += tlen;
 			TCP_STAT_PUTREF();
-			nd6_hint(tp);
+			nd_hint(tp);
 		/*
 		 * Automatic sizing enables the performance of large buffers
 		 * and most of the efficiency of small ones by only allocating
@@ -2595,7 +2617,7 @@ after_listen:
 		 */
 		tp->t_congctl->newack(tp, th);
 
-		nd6_hint(tp);
+		nd_hint(tp);
 		if (acked > so->so_snd.sb_cc) {
 			tp->snd_wnd -= so->so_snd.sb_cc;
 			sbdrop(>so_snd, (int)so->so_snd.sb_cc);
@@ -2801,7 +2823,7 @@ dodata:
 			tcps[TCP_STAT_RCVPACK]++;
 			tcps[TCP_STAT_RCVBYTE] += tlen;
 			TCP_STAT_PUTREF();
-			nd6_hint(tp);
+			nd_hint(tp);
 			if (so->so_state & SS_CANTRCVMORE) {
 m_freem(m);
 			} else {



CVS commit: src/sys/netinet

2020-09-11 Thread Frank Kardel
Module Name:src
Committed By:   kardel
Date:   Fri Sep 11 09:08:47 UTC 2020

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

Log Message:
PR/kern 55567

fix the data-only fast path. RCV.UP and SND.WL1 could be left behind
on long sequences of data only packets. pull them along to avoid relative
sequence wraps.

consistent with FreeBSD

addresses second failure mode of PR/kern 55567.

pullup to netbsd-8
pullup to netbsd-9


To generate a diff of this commit:
cvs rdiff -u -r1.419 -r1.420 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.419 src/sys/netinet/tcp_input.c:1.420
--- src/sys/netinet/tcp_input.c:1.419	Wed Sep  2 15:08:46 2020
+++ src/sys/netinet/tcp_input.c	Fri Sep 11 09:08:47 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_input.c,v 1.419 2020/09/02 15:08:46 kardel Exp $	*/
+/*	$NetBSD: tcp_input.c,v 1.420 2020/09/11 09:08:47 kardel Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.419 2020/09/02 15:08:46 kardel Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.420 2020/09/11 09:08:47 kardel Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1949,13 +1949,25 @@ after_listen:
 			 * we have enough buffer space to take it.
 			 */
 			tp->rcv_nxt += tlen;
+
+			/*
+			 * Pull rcv_up up to prevent seq wrap relative to
+			 * rcv_nxt.
+			 */
+			tp->rcv_up = tp->rcv_nxt;
+
+			/*
+			 * Pull snd_wl1 up to prevent seq wrap relative to
+			 * th_seq.
+			 */
+			tp->snd_wl1 = th->th_seq;
+
 			tcps = TCP_STAT_GETREF();
 			tcps[TCP_STAT_PREDDAT]++;
 			tcps[TCP_STAT_RCVPACK]++;
 			tcps[TCP_STAT_RCVBYTE] += tlen;
 			TCP_STAT_PUTREF();
 			nd6_hint(tp);
-
 		/*
 		 * Automatic sizing enables the performance of large buffers
 		 * and most of the efficiency of small ones by only allocating



CVS commit: src/sys/netinet

2020-09-02 Thread Frank Kardel
Module Name:src
Committed By:   kardel
Date:   Wed Sep  2 15:08:46 UTC 2020

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

Log Message:
Fix fast path for uni directional transfers
pure ACK case:

drag snd_wl2 along so only newer
ACKs can update the window size.
also avoids the state where snd_wl2
is eventually larger than th_ack and thus
blocking the window update mechanism and
the connection gets stuck for a lng
time in the zero sized send window state.

see PR/kern 55567

ok thorpej@, also found in FreeBSD


To generate a diff of this commit:
cvs rdiff -u -r1.418 -r1.419 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.418 src/sys/netinet/tcp_input.c:1.419
--- src/sys/netinet/tcp_input.c:1.418	Mon Jul  6 18:49:12 2020
+++ src/sys/netinet/tcp_input.c	Wed Sep  2 15:08:46 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_input.c,v 1.418 2020/07/06 18:49:12 christos Exp $	*/
+/*	$NetBSD: tcp_input.c,v 1.419 2020/09/02 15:08:46 kardel Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.418 2020/07/06 18:49:12 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.419 2020/09/02 15:08:46 kardel Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1897,6 +1897,19 @@ after_listen:
 tp->snd_fack = tp->snd_una;
 if (SEQ_LT(tp->snd_high, tp->snd_una))
 	tp->snd_high = tp->snd_una;
+/*
+ * drag snd_wl2 along so only newer
+ * ACKs can update the window size.
+ * also avoids the state where snd_wl2
+ * is eventually larger than th_ack and thus
+ * blocking the window update mechanism and
+ * the connection gets stuck for a lng
+ * time in the zero sized send window state.
+ *
+ * see PR/kern 55567
+ */
+tp->snd_wl2 = tp->snd_una;
+
 m_freem(m);
 
 /*



CVS commit: src/sys/netinet

2020-08-29 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Aug 29 17:41:14 UTC 2020

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

Log Message:
Partially revert previous: set RTF_HOST regardless of mask for point-to-point
links. Unbreaks IPSEC/L2TP configurations.


To generate a diff of this commit:
cvs rdiff -u -r1.237 -r1.238 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.237 src/sys/netinet/in.c:1.238
--- src/sys/netinet/in.c:1.237	Thu Aug 20 17:21:32 2020
+++ src/sys/netinet/in.c	Sat Aug 29 13:41:14 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: in.c,v 1.237 2020/08/20 21:21:32 riastradh Exp $	*/
+/*	$NetBSD: in.c,v 1.238 2020/08/29 17:41:14 christos Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in.c,v 1.237 2020/08/20 21:21:32 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in.c,v 1.238 2020/08/29 17:41:14 christos Exp $");
 
 #include "arp.h"
 
@@ -1231,11 +1231,9 @@ in_ifinit(struct ifnet *ifp, struct in_i
 		ia->ia_dstaddr = ia->ia_addr;
 		flags |= RTF_HOST;
 	} else if (ifp->if_flags & IFF_POINTOPOINT) {
-		if (in_mask2len(>ia_sockmask.sin_addr) == 32) {
-			if (ia->ia_dstaddr.sin_family != AF_INET)
-return (0);
-			flags |= RTF_HOST;
-		}
+		if (ia->ia_dstaddr.sin_family != AF_INET)
+			return (0);
+		flags |= RTF_HOST;
 	}
 
 	/* Add the local route to the address */



CVS commit: src/sys/netinet

2020-08-28 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Aug 28 17:01:48 UTC 2020

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

Log Message:
Don't cache the sa, because we are dealing with multiple mbufs (from ozaki-r)


To generate a diff of this commit:
cvs rdiff -u -r1.318 -r1.319 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.318 src/sys/netinet/ip_output.c:1.319
--- src/sys/netinet/ip_output.c:1.318	Fri Aug 28 02:31:42 2020
+++ src/sys/netinet/ip_output.c	Fri Aug 28 13:01:48 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_output.c,v 1.318 2020/08/28 06:31:42 ozaki-r Exp $	*/
+/*	$NetBSD: ip_output.c,v 1.319 2020/08/28 17:01:48 christos Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.318 2020/08/28 06:31:42 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.319 2020/08/28 17:01:48 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -690,8 +690,6 @@ sendit:
 	}
 	sw_csum = m->m_pkthdr.csum_flags & ~ifp->if_csum_flags_tx;
 
-	sa = (m->m_flags & M_MCAST) ? sintocsa(rdst) : sintocsa(dst);
-
 	/* Need to fragment the packet */
 	if (ntohs(ip->ip_len) > mtu &&
 	(m->m_pkthdr.csum_flags & M_CSUM_TSOv4) == 0) {
@@ -731,6 +729,8 @@ sendit:
 		}
 	}
 
+	sa = (m->m_flags & M_MCAST) ? sintocsa(rdst) : sintocsa(dst);
+
 	/* Send it */
 	if (__predict_false(sw_csum & M_CSUM_TSOv4)) {
 		/*
@@ -800,7 +800,8 @@ fragment:
 		} else {
 			KASSERT((m->m_pkthdr.csum_flags &
 			(M_CSUM_UDPv4 | M_CSUM_TCPv4)) == 0);
-			error = ip_if_output(ifp, m, sa, rt);
+			error = ip_if_output(ifp, m, (m->m_flags & M_MCAST) ?
+			sintocsa(rdst) : sintocsa(dst), rt);
 		}
 	}
 	if (error == 0) {



CVS commit: src/sys/netinet

2020-08-28 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Aug 28 07:01:57 UTC 2020

Modified Files:
src/sys/netinet: in_pcb.h in_pcb_hdr.h in_systm.h ip.h

Log Message:
netinet: Include the needful so include order doesn't matter.


To generate a diff of this commit:
cvs rdiff -u -r1.67 -r1.68 src/sys/netinet/in_pcb.h
cvs rdiff -u -r1.14 -r1.15 src/sys/netinet/in_pcb_hdr.h
cvs rdiff -u -r1.13 -r1.14 src/sys/netinet/in_systm.h
cvs rdiff -u -r1.34 -r1.35 src/sys/netinet/ip.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.67 src/sys/netinet/in_pcb.h:1.68
--- src/sys/netinet/in_pcb.h:1.67	Thu Aug 20 21:21:32 2020
+++ src/sys/netinet/in_pcb.h	Fri Aug 28 07:01:57 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: in_pcb.h,v 1.67 2020/08/20 21:21:32 riastradh Exp $	*/
+/*	$NetBSD: in_pcb.h,v 1.68 2020/08/28 07:01:57 riastradh Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -63,9 +63,16 @@
 #ifndef _NETINET_IN_PCB_H_
 #define _NETINET_IN_PCB_H_
 
-#include 
+#include 
+
 #include 
+
+#include 
 #include 
+#include 
+
+struct ip_moptions;
+struct mbuf;
 
 /*
  * Common structure pcb for internet protocol implementation.
@@ -133,6 +140,17 @@ struct inpcb {
 #define	inp_locked(inp)		solocked((inp)->inp_socket)
 
 #ifdef _KERNEL
+
+#include 
+#include 
+
+struct inpcbtable;
+struct lwp;
+struct rtentry;
+struct sockaddr_in;
+struct socket;
+struct vestigial_inpcb;
+
 void	in_losing(struct inpcb *);
 int	in_pcballoc(struct socket *, void *);
 int	in_pcbbindableaddr(struct sockaddr_in *, kauth_cred_t);
@@ -173,6 +191,7 @@ in_pcb_register_overudp_cb(struct inpcb 
 	inp->inp_overudp_cb = cb;
 	inp->inp_overudp_arg = arg;
 }
-#endif
 
-#endif /* !_NETINET_IN_PCB_H_ */
+#endif	/* _KERNEL */
+
+#endif	/* !_NETINET_IN_PCB_H_ */

Index: src/sys/netinet/in_pcb_hdr.h
diff -u src/sys/netinet/in_pcb_hdr.h:1.14 src/sys/netinet/in_pcb_hdr.h:1.15
--- src/sys/netinet/in_pcb_hdr.h:1.14	Thu Aug 20 21:21:32 2020
+++ src/sys/netinet/in_pcb_hdr.h	Fri Aug 28 07:01:57 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: in_pcb_hdr.h,v 1.14 2020/08/20 21:21:32 riastradh Exp $	*/
+/*	$NetBSD: in_pcb_hdr.h,v 1.15 2020/08/28 07:01:57 riastradh Exp $	*/
 
 /*
  * Copyright (C) 2003 WIDE Project.
@@ -63,9 +63,16 @@
 #ifndef _NETINET_IN_PCB_HDR_H_
 #define _NETINET_IN_PCB_HDR_H_
 
+#include 
 #include 
 
+#include 
+
 struct inpcbpolicy;
+struct inpcbtable;
+struct mbuf;
+struct sockaddr;
+struct socket;
 
 /*
  * align it with inpcb and in6pcb!

Index: src/sys/netinet/in_systm.h
diff -u src/sys/netinet/in_systm.h:1.13 src/sys/netinet/in_systm.h:1.14
--- src/sys/netinet/in_systm.h:1.13	Sat Dec 10 23:36:23 2005
+++ src/sys/netinet/in_systm.h	Fri Aug 28 07:01:57 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: in_systm.h,v 1.13 2005/12/10 23:36:23 elad Exp $	*/
+/*	$NetBSD: in_systm.h,v 1.14 2020/08/28 07:01:57 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1993
@@ -39,6 +39,8 @@
  * definitions for kernel.
  */
 
+#include 
+
 /*
  * Network types.
  *

Index: src/sys/netinet/ip.h
diff -u src/sys/netinet/ip.h:1.34 src/sys/netinet/ip.h:1.35
--- src/sys/netinet/ip.h:1.34	Fri Nov  2 21:07:07 2012
+++ src/sys/netinet/ip.h	Fri Aug 28 07:01:57 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip.h,v 1.34 2012/11/02 21:07:07 christos Exp $	*/
+/*	$NetBSD: ip.h,v 1.35 2020/08/28 07:01:57 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1993
@@ -34,7 +34,11 @@
 #ifndef _NETINET_IP_H_
 #define _NETINET_IP_H_
 
+#include 
+
+#include 
 #include 	/* for n_time */
+
 /*
  * Definitions for internet protocol version 4.
  * Per RFC 791, September 1981.
@@ -243,4 +247,5 @@ struct ippseudo {
 	u_int8_t	ippseudo_p;	/* protocol */
 	u_int16_t	ippseudo_len;	/* protocol length */
 } __packed;
-#endif /* !_NETINET_IP_H_ */
+
+#endif	/* !_NETINET_IP_H_ */



CVS commit: src/sys/netinet

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

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

Log Message:
inet: reduce silent packet discards


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

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

Modified files:

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

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

CVS commit: src/sys/netinet

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

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

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

Same as ip6_input.


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

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

Modified files:

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



CVS commit: src/sys/netinet

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

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

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


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

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

Modified files:

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



CVS commit: src/sys/netinet

2020-08-21 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Aug 22 01:43:07 UTC 2020

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

Log Message:
Mark KASSERT-only variable __diagused.


To generate a diff of this commit:
cvs rdiff -u -r1.73 -r1.74 src/sys/netinet/ip_encap.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_encap.c
diff -u src/sys/netinet/ip_encap.c:1.73 src/sys/netinet/ip_encap.c:1.74
--- src/sys/netinet/ip_encap.c:1.73	Thu Aug 20 21:21:32 2020
+++ src/sys/netinet/ip_encap.c	Sat Aug 22 01:43:07 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_encap.c,v 1.73 2020/08/20 21:21:32 riastradh Exp $	*/
+/*	$NetBSD: ip_encap.c,v 1.74 2020/08/22 01:43:07 riastradh 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.73 2020/08/20 21:21:32 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_encap.c,v 1.74 2020/08/22 01:43:07 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_mrouting.h"
@@ -609,7 +609,7 @@ encap_afcheck(int af, const struct socka
 	KASSERT(sp->sa_len == dp->sa_len);
 	KASSERT(af == sp->sa_family && af == dp->sa_family);
 
-	socklen_t len = sockaddr_getsize_by_family(af);
+	socklen_t len __diagused = sockaddr_getsize_by_family(af);
 	KASSERT(len != 0 && len == sp->sa_len && len == dp->sa_len);
 }
 



CVS commit: src/sys/netinet

2020-07-06 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Jul  6 18:49:12 UTC 2020

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

Log Message:
- always set both ip and ip6, otherwise a kernel assertion can be triggered
- move alignment early so that we do less work


To generate a diff of this commit:
cvs rdiff -u -r1.417 -r1.418 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.417 src/sys/netinet/tcp_input.c:1.418
--- src/sys/netinet/tcp_input.c:1.417	Sat Nov 16 05:15:10 2019
+++ src/sys/netinet/tcp_input.c	Mon Jul  6 14:49:12 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_input.c,v 1.417 2019/11/16 10:15:10 maxv Exp $	*/
+/*	$NetBSD: tcp_input.c,v 1.418 2020/07/06 18:49:12 christos Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.417 2019/11/16 10:15:10 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.418 2020/07/06 18:49:12 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1240,15 +1240,29 @@ tcp_input(struct mbuf *m, int off, int p
 	}
 
 	/*
+	 * Enforce alignment requirements that are violated in
+	 * some cases, see kern/50766 for details.
+	 */
+	if (TCP_HDR_ALIGNED_P(th) == 0) {
+		m = m_copyup(m, off + sizeof(struct tcphdr), 0);
+		if (m == NULL) {
+			TCP_STATINC(TCP_STAT_RCVSHORT);
+			return;
+		}
+		th = (struct tcphdr *)(mtod(m, char *) + off);
+	}
+	KASSERT(TCP_HDR_ALIGNED_P(th));
+
+	/*
 	 * Get IP and TCP header.
 	 * Note: IP leaves IP header in first mbuf.
 	 */
 	ip = mtod(m, struct ip *);
-	switch (ip->ip_v) {
-	case 4:
 #ifdef INET6
-		ip6 = NULL;
+	ip6 = mtod(m, struct ip6_hdr *);
 #endif
+	switch (ip->ip_v) {
+	case 4:
 		af = AF_INET;
 		iphlen = sizeof(struct ip);
 
@@ -1263,10 +1277,8 @@ tcp_input(struct mbuf *m, int off, int p
 		break;
 #ifdef INET6
 	case 6:
-		ip = NULL;
 		iphlen = sizeof(struct ip6_hdr);
 		af = AF_INET6;
-		ip6 = mtod(m, struct ip6_hdr *);
 
 		/*
 		 * Be proactive about unspecified IPv6 address in source.
@@ -1301,23 +1313,6 @@ tcp_input(struct mbuf *m, int off, int p
 		return;
 	}
 
-	/*
-	 * Enforce alignment requirements that are violated in
-	 * some cases, see kern/50766 for details.
-	 */
-	if (TCP_HDR_ALIGNED_P(th) == 0) {
-		m = m_copyup(m, off + sizeof(struct tcphdr), 0);
-		if (m == NULL) {
-			TCP_STATINC(TCP_STAT_RCVSHORT);
-			return;
-		}
-		ip = mtod(m, struct ip *);
-#ifdef INET6
-		ip6 = mtod(m, struct ip6_hdr *);
-#endif
-		th = (struct tcphdr *)(mtod(m, char *) + off);
-	}
-	KASSERT(TCP_HDR_ALIGNED_P(th));
 
 	/*
 	 * Check that TCP offset makes sense, pull out TCP options and
@@ -1515,7 +1510,6 @@ findpcb:
 			m_freem(in6p->in6p_options);
 			in6p->in6p_options = NULL;
 		}
-		KASSERT(ip6 != NULL);
 		ip6_savecontrol(in6p, >in6p_options, ip6, m);
 	}
 #endif



CVS commit: src/sys/netinet

2020-06-15 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Mon Jun 15 23:41:35 UTC 2020

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

Log Message:
icmp6.h: #define ND_RA_FLAG_PROXY

RFC 4389, experimental. Maybe someone will implement it one day.


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 src/sys/netinet/icmp6.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/icmp6.h
diff -u src/sys/netinet/icmp6.h:1.55 src/sys/netinet/icmp6.h:1.56
--- src/sys/netinet/icmp6.h:1.55	Mon Jun 15 23:38:17 2020
+++ src/sys/netinet/icmp6.h	Mon Jun 15 23:41:35 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: icmp6.h,v 1.55 2020/06/15 23:38:17 roy Exp $	*/
+/*	$NetBSD: icmp6.h,v 1.56 2020/06/15 23:41:35 roy Exp $	*/
 /*	$KAME: icmp6.h,v 1.84 2003/04/23 10:26:51 itojun Exp $	*/
 
 
@@ -233,6 +233,7 @@ struct nd_router_advert {	/* router adve
 #define ND_RA_FLAG_MANAGED	0x80
 #define ND_RA_FLAG_OTHER	0x40
 #define ND_RA_FLAG_HOME_AGENT	0x20
+#define ND_RA_FLAG_PROXY	0x04
 
 /*
  * Router preference values based on RFC4191.



CVS commit: src/sys/netinet

2020-06-15 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Mon Jun 15 23:38:17 UTC 2020

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

Log Message:
icmp6.h: #define ND_OPT_PI_FLAG_ROUTER

We already define ND_RA_FLAG_HOME_AGENT and that kind of requires
ND_OPT_PI_FLAG_ROUTER.


To generate a diff of this commit:
cvs rdiff -u -r1.54 -r1.55 src/sys/netinet/icmp6.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/icmp6.h
diff -u src/sys/netinet/icmp6.h:1.54 src/sys/netinet/icmp6.h:1.55
--- src/sys/netinet/icmp6.h:1.54	Fri Jun 12 11:04:45 2020
+++ src/sys/netinet/icmp6.h	Mon Jun 15 23:38:17 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: icmp6.h,v 1.54 2020/06/12 11:04:45 roy Exp $	*/
+/*	$NetBSD: icmp6.h,v 1.55 2020/06/15 23:38:17 roy Exp $	*/
 /*	$KAME: icmp6.h,v 1.84 2003/04/23 10:26:51 itojun Exp $	*/
 
 
@@ -335,6 +335,7 @@ struct nd_opt_prefix_info {	/* prefix in
 
 #define ND_OPT_PI_FLAG_ONLINK		0x80
 #define ND_OPT_PI_FLAG_AUTO		0x40
+#define ND_OPT_PI_FLAG_ROUTER		0x20
 
 struct nd_opt_rd_hdr {		/* redirected header */
 	u_int8_t	nd_opt_rh_type;



CVS commit: src/sys/netinet

2020-06-12 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Sat Jun 13 01:41:59 UTC 2020

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

Log Message:
SCTP: Use ifp->if_mtu rather than ND_IFINFO(ifp)->linkmtu


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 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.21 src/sys/netinet/sctp_output.c:1.22
--- src/sys/netinet/sctp_output.c:1.21	Thu Dec 26 04:44:10 2019
+++ src/sys/netinet/sctp_output.c	Sat Jun 13 01:41:59 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: sctp_output.c,v 1.21 2019/12/26 04:44:10 msaitoh Exp $ */
+/*	$NetBSD: sctp_output.c,v 1.22 2020/06/13 01:41:59 roy 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.21 2019/12/26 04:44:10 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sctp_output.c,v 1.22 2020/06/13 01:41:59 roy Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ipsec.h"
@@ -2476,11 +2476,11 @@ sctp_lowlevel_chunk_output(struct sctp_i
 }
 rtcache_unref(rt, ro);
 			} else if (ifp) {
-if (ND_IFINFO(ifp)->linkmtu &&
-(stcb->asoc.smallest_mtu > ND_IFINFO(ifp)->linkmtu)) {
+if (ifp->if_mtu &&
+(stcb->asoc.smallest_mtu > ifp->if_mtu)) {
 	sctp_mtu_size_reset(inp,
 			>asoc,
-			ND_IFINFO(ifp)->linkmtu);
+			ifp->if_mtu);
 }
 			}
 		}



CVS commit: src/sys/netinet

2020-05-15 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri May 15 06:34:34 UTC 2020

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

Log Message:
igmp_sendpkt() expects ip_output() to set 'imo.imo_multicast_ttl' into
'ip->ip_ttl'; but ip_output() won't if the target is not a multicast
address, meaning that the uninitialized 'ip->ip_ttl' byte gets sent to
the network. This leaks one byte of kernel heap.

Fix this by filling 'ip->ip_ttl' with a TTL of one.

Found by KMSAN.

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


To generate a diff of this commit:
cvs rdiff -u -r1.69 -r1.70 src/sys/netinet/igmp.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/igmp.c
diff -u src/sys/netinet/igmp.c:1.69 src/sys/netinet/igmp.c:1.70
--- src/sys/netinet/igmp.c:1.69	Fri Sep 14 05:09:51 2018
+++ src/sys/netinet/igmp.c	Fri May 15 06:34:34 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: igmp.c,v 1.69 2018/09/14 05:09:51 maxv Exp $	*/
+/*	$NetBSD: igmp.c,v 1.70 2020/05/15 06:34:34 maxv Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -40,7 +40,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: igmp.c,v 1.69 2018/09/14 05:09:51 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: igmp.c,v 1.70 2020/05/15 06:34:34 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_mrouting.h"
@@ -613,6 +613,7 @@ igmp_sendpkt(struct in_multi *inm, int t
 	ip->ip_tos = 0;
 	ip->ip_len = htons(sizeof(struct ip) + IGMP_MINLEN);
 	ip->ip_off = htons(0);
+	ip->ip_ttl = IP_DEFAULT_MULTICAST_TTL;
 	ip->ip_p = IPPROTO_IGMP;
 	ip->ip_src = zeroin_addr;
 	ip->ip_dst = inm->inm_addr;



CVS commit: src/sys/netinet

2020-03-27 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Fri Mar 27 16:34:58 UTC 2020

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

Log Message:
fix in4_cksum() panic "in4_cksum: mbuf 14 too short for IP header 20"
triggered by bridge_output() when passing packet originally for
interface supporting hw csum offload to destination interface
not supporting it

problem happens because bridge_output() is called after ether_output()
M_PREPEND() the ether_header into the mbuf chain, if there is not
enough space on the first mbuf of the chain, it ends up prepending
a new short mbuf with just ether_header

triggered by running UDP (IPv4) 'netio -u' benchmark with packet size 2 KB

XXX seems in6_undefer_cksum() should have similar fix, however I was
XXX not able to trigger the problem there


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/netinet/in_offload.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_offload.c
diff -u src/sys/netinet/in_offload.c:1.13 src/sys/netinet/in_offload.c:1.14
--- src/sys/netinet/in_offload.c:1.13	Wed Dec 12 01:40:20 2018
+++ src/sys/netinet/in_offload.c	Fri Mar 27 16:34:58 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: in_offload.c,v 1.13 2018/12/12 01:40:20 rin Exp $	*/
+/*	$NetBSD: in_offload.c,v 1.14 2020/03/27 16:34:58 jdolecek Exp $	*/
 
 /*
  * Copyright (c)2005, 2006 YAMAMOTO Takashi,
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in_offload.c,v 1.13 2018/12/12 01:40:20 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in_offload.c,v 1.14 2020/03/27 16:34:58 jdolecek Exp $");
 
 #include 
 #include 
@@ -197,15 +197,29 @@ ip_tso_output(struct ifnet *ifp, struct 
  * hardware offloading.
  */
 void
-in_undefer_cksum(struct mbuf *m, size_t hdrlen, int csum_flags)
+in_undefer_cksum(struct mbuf *mh, size_t hdrlen, int csum_flags)
 {
-	const size_t iphdrlen = M_CSUM_DATA_IPv4_IPHL(m->m_pkthdr.csum_data);
+	const size_t iphdrlen = M_CSUM_DATA_IPv4_IPHL(mh->m_pkthdr.csum_data);
 	uint16_t csum;
 	uint16_t ip_len;
 	uint16_t *csump;
+	struct mbuf *m = mh;
 
-	KASSERT(m->m_flags & M_PKTHDR);
-	KASSERT((m->m_pkthdr.csum_flags & csum_flags) == csum_flags);
+	KASSERT(mh->m_flags & M_PKTHDR);
+	KASSERT(mh->m_pkthdr.len > hdrlen);
+	KASSERT((mh->m_pkthdr.csum_flags & csum_flags) == csum_flags);
+
+	/*
+	 * Deal with prepended frame header as done by e.g. ether_output().
+	 * If first mbuf in chain has just the header, use second mbuf
+	 * for the actual checksum. in4_csum() expects the passed mbuf
+	 * to have the whole (struct ip) area contiguous.
+	 */
+	if (m->m_len <= hdrlen) {
+		hdrlen -= m->m_len;
+		m = m->m_next;
+		KASSERT(m != NULL);
+	}
 
 	if (__predict_true(hdrlen + sizeof(struct ip) <= m->m_len)) {
 		struct ip *ip = (struct ip *)(mtod(m, uint8_t *) + hdrlen);
@@ -249,7 +263,7 @@ in_undefer_cksum(struct mbuf *m, size_t 
 		}
 	}
 
-	m->m_pkthdr.csum_flags ^= csum_flags;
+	mh->m_pkthdr.csum_flags ^= csum_flags;
 }
 
 /*



CVS commit: src/sys/netinet

2020-03-09 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Mon Mar  9 17:57:19 UTC 2020

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

Log Message:
arp: report RTM_MISS when removing an unresolved entry in the arp table

Otherwise we only get it when renewing and we've sent too many requests.
This mirrors INET6 behaviour.


To generate a diff of this commit:
cvs rdiff -u -r1.292 -r1.293 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.292 src/sys/netinet/if_arp.c:1.293
--- src/sys/netinet/if_arp.c:1.292	Thu Jan 23 17:27:35 2020
+++ src/sys/netinet/if_arp.c	Mon Mar  9 17:57:19 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_arp.c,v 1.292 2020/01/23 17:27:35 roy Exp $	*/
+/*	$NetBSD: if_arp.c,v 1.293 2020/03/09 17:57:19 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.292 2020/01/23 17:27:35 roy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.293 2020/03/09 17:57:19 roy Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -307,18 +307,22 @@ arptimer(void *arg)
 
 	/* Guard against race with other llentry_free(). */
 	if (lle->la_flags & LLE_LINKED) {
+		int rt_cmd;
+		struct in_addr *in;
+		struct sockaddr_in sin;
+		const char *lladdr;
 		size_t pkts_dropped;
 
+		in = >r_l3addr.addr4;
+		sockaddr_in_init(, in, 0);
 		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);
+			rt_cmd = RTM_DELETE;
 			lladdr = (const char *)>ll_addr;
-			rt_clonedmsg(RTM_DELETE, sintosa(), lladdr, ifp);
+		} else {
+			rt_cmd = RTM_MISS;
+			lladdr = NULL;
 		}
+		rt_clonedmsg(rt_cmd, sintosa(), lladdr, ifp);
 
 		LLE_REMREF(lle);
 		pkts_dropped = llentry_free(lle);



CVS commit: src/sys/netinet

2020-01-28 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed Jan 29 04:37:24 UTC 2020

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

Log Message:
Adopt .


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/netinet/in_l2tp.c
cvs rdiff -u -r1.107 -r1.108 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/in_l2tp.c
diff -u src/sys/netinet/in_l2tp.c:1.17 src/sys/netinet/in_l2tp.c:1.18
--- src/sys/netinet/in_l2tp.c:1.17	Thu Sep 19 06:07:25 2019
+++ src/sys/netinet/in_l2tp.c	Wed Jan 29 04:37:24 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: in_l2tp.c,v 1.17 2019/09/19 06:07:25 knakahara Exp $	*/
+/*	$NetBSD: in_l2tp.c,v 1.18 2020/01/29 04:37:24 thorpej Exp $	*/
 
 /*
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in_l2tp.c,v 1.17 2019/09/19 06:07:25 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in_l2tp.c,v 1.18 2020/01/29 04:37:24 thorpej Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_l2tp.h"
@@ -239,7 +239,7 @@ in_l2tp_output(struct l2tp_variant *var,
 
 looped:
 	if (error)
-		ifp->if_oerrors++;
+		if_statinc(ifp, if_oerrors);
 
 out:
 	return error;

Index: src/sys/netinet/ip_carp.c
diff -u src/sys/netinet/ip_carp.c:1.107 src/sys/netinet/ip_carp.c:1.108
--- src/sys/netinet/ip_carp.c:1.107	Mon Jan 20 18:38:22 2020
+++ src/sys/netinet/ip_carp.c	Wed Jan 29 04:37:24 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_carp.c,v 1.107 2020/01/20 18:38:22 thorpej Exp $	*/
+/*	$NetBSD: ip_carp.c,v 1.108 2020/01/29 04:37:24 thorpej 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.107 2020/01/20 18:38:22 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_carp.c,v 1.108 2020/01/29 04:37:24 thorpej Exp $");
 
 /*
  * TODO:
@@ -712,13 +712,12 @@ carp_proto_input_c(struct mbuf *m, struc
 	}
 
 	nanotime(>sc_if.if_lastchange);
-	sc->sc_if.if_ipackets++;
-	sc->sc_if.if_ibytes += m->m_pkthdr.len;
+	if_statadd2(>sc_if, if_ipackets, 1, if_ibytes, m->m_pkthdr.len);
 
 	/* verify the CARP version. */
 	if (ch->carp_version != CARP_VERSION) {
 		CARP_STATINC(CARP_STAT_BADVER);
-		sc->sc_if.if_ierrors++;
+		if_statinc(>sc_if, if_ierrors);
 		CARP_LOG(sc, ("invalid version %d != %d",
 		ch->carp_version, CARP_VERSION));
 		m_freem(m);
@@ -735,7 +734,7 @@ carp_proto_input_c(struct mbuf *m, struc
 #endif
 
 		CARP_STATINC(CARP_STAT_BADAUTH);
-		sc->sc_if.if_ierrors++;
+		if_statinc(>sc_if, if_ierrors);
 
 		switch(af) {
 		case AF_INET:
@@ -1038,7 +1037,7 @@ carp_send_ad(void *v)
 
 	advbase = advskew = 0; /* Sh compiler */
 	if (sc->sc_carpdev == NULL) {
-		sc->sc_if.if_oerrors++;
+		if_statinc(>sc_if, if_oerrors);
 		goto retry_later;
 	}
 
@@ -1075,7 +1074,7 @@ carp_send_ad(void *v)
 
 		MGETHDR(m, M_DONTWAIT, MT_HEADER);
 		if (m == NULL) {
-			sc->sc_if.if_oerrors++;
+			if_statinc(>sc_if, if_oerrors);
 			CARP_STATINC(CARP_STAT_ONOMEM);
 			/* XXX maybe less ? */
 			goto retry_later;
@@ -1119,8 +1118,7 @@ carp_send_ad(void *v)
 		m->m_data -= sizeof(*ip);
 
 		nanotime(>sc_if.if_lastchange);
-		sc->sc_if.if_opackets++;
-		sc->sc_if.if_obytes += len;
+		if_statadd2(>sc_if, if_opackets, 1, if_obytes, len);
 		CARP_STATINC(CARP_STAT_OPACKETS);
 
 		error = ip_output(m, NULL, NULL, IP_RAWOUTPUT, >sc_imo,
@@ -1130,7 +1128,7 @@ carp_send_ad(void *v)
 CARP_STATINC(CARP_STAT_ONOMEM);
 			else
 CARP_LOG(sc, ("ip_output failed: %d", error));
-			sc->sc_if.if_oerrors++;
+			if_statinc(>sc_if, if_oerrors);
 			if (sc->sc_sendad_errors < INT_MAX)
 sc->sc_sendad_errors++;
 			if (sc->sc_sendad_errors == CARP_SENDAD_MAX_ERRORS) {
@@ -1159,7 +1157,7 @@ carp_send_ad(void *v)
 
 		MGETHDR(m, M_DONTWAIT, MT_HEADER);
 		if (m == NULL) {
-			sc->sc_if.if_oerrors++;
+			if_statinc(>sc_if, if_oerrors);
 			CARP_STATINC(CARP_STAT_ONOMEM);
 			/* XXX maybe less ? */
 			goto retry_later;
@@ -1193,7 +1191,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) {
-			sc->sc_if.if_oerrors++;
+			if_statinc(>sc_if, if_oerrors);
 			m_freem(m);
 			CARP_LOG(sc, ("in6_setscope failed"));
 			goto retry_later;
@@ -1207,8 +1205,7 @@ carp_send_ad(void *v)
 		len - sizeof(*ip6));
 
 		nanotime(>sc_if.if_lastchange);
-		sc->sc_if.if_opackets++;
-		sc->sc_if.if_obytes += len;
+		if_statadd2(>sc_if, if_opackets, 1, if_obytes, len);
 		CARP_STATINC(CARP_STAT_OPACKETS6);
 
 		error = ip6_output(m, NULL, NULL, 0, >sc_im6o, NULL, NULL);
@@ -1217,7 +1214,7 @@ carp_send_ad(void *v)
 CARP_STATINC(CARP_STAT_ONOMEM);
 			else
 CARP_LOG(sc, ("ip6_output failed: %d", error));
-			sc->sc_if.if_oerrors++;
+			if_statinc(>sc_if, if_oerrors);
 			if (sc->sc_sendad_errors < INT_MAX)
 sc->sc_sendad_errors++;
 			if 

CVS commit: src/sys/netinet

2020-01-23 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Thu Jan 23 17:27:35 UTC 2020

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

Log Message:
arp: find source address then target address when processing input

This fixes the case where another host having a duplicate ip address
starts using it right away without probing for it's availability.

While here, prefer ifatoia over a strict cast.


To generate a diff of this commit:
cvs rdiff -u -r1.291 -r1.292 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.291 src/sys/netinet/if_arp.c:1.292
--- src/sys/netinet/if_arp.c:1.291	Mon Jan 20 18:38:22 2020
+++ src/sys/netinet/if_arp.c	Thu Jan 23 17:27:35 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_arp.c,v 1.291 2020/01/20 18:38:22 thorpej Exp $	*/
+/*	$NetBSD: if_arp.c,v 1.292 2020/01/23 17:27:35 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.291 2020/01/20 18:38:22 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.292 2020/01/23 17:27:35 roy Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -988,7 +988,7 @@ in_arpinput(struct mbuf *m)
 	struct psref psref, psref_ia;
 	int s;
 	char ipbuf[INET_ADDRSTRLEN];
-	bool do_dad;
+	bool find_source, do_dad;
 
 	if (__predict_false(m_makewritable(, 0, m->m_pkthdr.len, M_DONTWAIT)))
 		goto out;
@@ -1023,11 +1023,20 @@ in_arpinput(struct mbuf *m)
 	 * or any address on the interface to use
 	 * as a dummy address in the rest of this function.
 	 *
-	 * If the target IP address is zero then try and find
-	 * the sender address for DAD.
+	 * First try and find the source address for early
+	 * duplicate address detection.
 	 */
-	myaddr = in_nullhost(itaddr) ? isaddr : itaddr;
+	if (in_nullhost(isaddr)) {
+		if (in_nullhost(itaddr)) /* very bogus ARP */
+			goto out;
+		find_source = false;
+		myaddr = itaddr;
+	} else {
+		find_source = true;
+		myaddr = isaddr;
+	}
 	s = pserialize_read_enter();
+again:
 	IN_ADDRHASH_READER_FOREACH(ia, myaddr.s_addr) {
 		if (!in_hosteq(ia->ia_addr.sin_addr, myaddr))
 			continue;
@@ -1069,6 +1078,15 @@ in_arpinput(struct mbuf *m)
 		ifp = bridge_ia->ia_ifp;
 	}
 #endif
+
+	/* If we failed to find the source address then find
+	 * the target address. */
+	if (ia == NULL && find_source && !in_nullhost(itaddr)) {
+		find_source = false;
+		myaddr = itaddr;
+		goto again;
+	}
+
 	if (ia != NULL)
 		ia4_acquire(ia, _ia);
 	pserialize_read_exit(s);
@@ -1722,7 +1740,7 @@ done:
 static void
 arp_dad_duplicated(struct ifaddr *ifa, const struct sockaddr_dl *from)
 {
-	struct in_ifaddr *ia = (struct in_ifaddr *)ifa;
+	struct in_ifaddr *ia = ifatoia(ifa);
 	struct ifnet *ifp = ifa->ifa_ifp;
 	char ipbuf[INET_ADDRSTRLEN], llabuf[LLA_ADDRSTRLEN];
 	const char *iastr, *llastr;



CVS commit: src/sys/netinet

2020-01-23 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Jan 23 09:09:59 UTC 2020

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

Log Message:
Fix PR security/54881.  Pointed out by ohishi@IIJ, thanks.


To generate a diff of this commit:
cvs rdiff -u -r1.71 -r1.72 src/sys/netinet/ip_encap.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_encap.c
diff -u src/sys/netinet/ip_encap.c:1.71 src/sys/netinet/ip_encap.c:1.72
--- src/sys/netinet/ip_encap.c:1.71	Wed May 15 03:33:41 2019
+++ src/sys/netinet/ip_encap.c	Thu Jan 23 09:09:59 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_encap.c,v 1.71 2019/05/15 03:33:41 knakahara Exp $	*/
+/*	$NetBSD: ip_encap.c,v 1.72 2020/01/23 09:09:59 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.71 2019/05/15 03:33:41 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_encap.c,v 1.72 2020/01/23 09:09:59 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_mrouting.h"
@@ -884,10 +884,11 @@ encap6_ctlinput(int cmd, const struct so
 		 	*/
 			match = encap6_lookup(m, off, nxt, OUTBOUND,
 			_psref);
-			if (match)
+			if (match) {
 valid++;
-			psref_release(_psref, >psref,
-			encaptab.elem_class);
+psref_release(_psref, >psref,
+encaptab.elem_class);
+			}
 
 			/*
 		 	* Depending on the value of "valid" and routing table



CVS commit: src/sys/netinet

2020-01-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Jan 19 20:51:13 UTC 2020

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

Log Message:
Replace kooky sctp random number generation by cprng_strong32().


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/netinet/sctp_pcb.c
cvs rdiff -u -r1.2 -r1.3 src/sys/netinet/sctp_pcb.h \
src/sys/netinet/sctputil.h
cvs rdiff -u -r1.15 -r1.16 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_pcb.c
diff -u src/sys/netinet/sctp_pcb.c:1.19 src/sys/netinet/sctp_pcb.c:1.20
--- src/sys/netinet/sctp_pcb.c:1.19	Thu Dec 26 04:44:10 2019
+++ src/sys/netinet/sctp_pcb.c	Sun Jan 19 20:51:13 2020
@@ -1,5 +1,5 @@
 /* $KAME: sctp_pcb.c,v 1.39 2005/06/16 18:29:25 jinmei Exp $ */
-/* $NetBSD: sctp_pcb.c,v 1.19 2019/12/26 04:44:10 msaitoh Exp $ */
+/* $NetBSD: sctp_pcb.c,v 1.20 2020/01/19 20:51:13 riastradh Exp $ */
 
 /*
  * Copyright (c) 2001, 2002, 2003, 2004 Cisco Systems, Inc.
@@ -33,7 +33,7 @@
  * SUCH DAMAGE.
  */
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sctp_pcb.c,v 1.19 2019/12/26 04:44:10 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sctp_pcb.c,v 1.20 2020/01/19 20:51:13 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1465,29 +1465,6 @@ sctp_inpcb_alloc(struct socket *so)
 	/* Add adaption cookie */
 	m->adaption_layer_indicator = 0x504C5253;
 
-	/* seed random number generator */
-	m->random_counter = 1;
-	m->store_at = SCTP_SIGNATURE_SIZE;
-#if NRND > 0
-	rnd_extract_data(m->random_numbers, sizeof(m->random_numbers),
-			 RND_EXTRACT_ANY);
-#else
-	{
-		u_int32_t *ranm, *ranp;
-		ranp = (u_int32_t *)>random_numbers;
-		ranm = ranp + (SCTP_SIGNATURE_ALOC_SIZE/sizeof(u_int32_t));
-		if ((u_long)ranp % 4) {
-			/* not a even boundary? */
-			ranp = (u_int32_t *)SCTP_SIZE32((u_long)ranp);
-		}
-		while (ranp < ranm) {
-			*ranp = random();
-			ranp++;
-		}
-	}
-#endif
-	sctp_fill_random_store(m);
-
 	/* Minimum cookie size */
 	m->size_of_a_cookie = (sizeof(struct sctp_init_msg) * 2) +
 		sizeof(struct sctp_state_cookie);

Index: src/sys/netinet/sctp_pcb.h
diff -u src/sys/netinet/sctp_pcb.h:1.2 src/sys/netinet/sctp_pcb.h:1.3
--- src/sys/netinet/sctp_pcb.h:1.2	Sat Jun  8 23:23:34 2019
+++ src/sys/netinet/sctp_pcb.h	Sun Jan 19 20:51:13 2020
@@ -1,5 +1,5 @@
 /*	$KAME: sctp_pcb.h,v 1.21 2005/07/16 01:18:47 suz Exp $	*/
-/*	$NetBSD: sctp_pcb.h,v 1.2 2019/06/08 23:23:34 rjs Exp $ */
+/*	$NetBSD: sctp_pcb.h,v 1.3 2020/01/19 20:51:13 riastradh Exp $ */
 
 #ifndef __SCTP_PCB_H__
 #define __SCTP_PCB_H__
@@ -250,11 +250,6 @@ struct sctp_pcb {
 	uint16_t pre_open_stream_count;
 	uint16_t max_open_streams_intome;
 
-	/* random number generator */
-	uint32_t random_counter;
-	uint8_t random_numbers[SCTP_SIGNATURE_ALOC_SIZE];
-	uint8_t random_store[SCTP_SIGNATURE_ALOC_SIZE];
-
 	/*
 	 * This timer is kept running per endpoint.  When it fires it
 	 * will change the secret key.  The default is once a hour
@@ -265,7 +260,6 @@ struct sctp_pcb {
 	int auto_close_time;
 	uint32_t initial_sequence_debug;
 	uint32_t adaption_layer_indicator;
-	char store_at;
 	uint8_t max_burst;
 	char current_secret_number;
 	char last_secret_number;
@@ -447,7 +441,7 @@ void SCTP_INP_INFO_WLOCK(void);
 
 /* The INP locks we will use for locking an SCTP endpoint, so for
  * example if we want to change something at the endpoint level for
- * example random_store or cookie secrets we lock the INP level.
+ * example cookie secrets we lock the INP level.
  */
 #define SCTP_INP_LOCK_INIT(_inp) \
 	mtx_init(&(_inp)->inp_mtx, "sctp", "inp", MTX_DEF | MTX_DUPOK)
@@ -556,7 +550,7 @@ void SCTP_INP_WLOCK(struct sctp_inpcb *)
 
 /* The INP locks we will use for locking an SCTP endpoint, so for
  * example if we want to change something at the endpoint level for
- * example random_store or cookie secrets we lock the INP level.
+ * example cookie secrets we lock the INP level.
  */
 #define SCTP_INP_LOCK_INIT(_inp) \
 	mutex_init(&(_inp)->inp_mtx, MUTEX_DEFAULT, IPL_NET)
Index: src/sys/netinet/sctputil.h
diff -u src/sys/netinet/sctputil.h:1.2 src/sys/netinet/sctputil.h:1.3
--- src/sys/netinet/sctputil.h:1.2	Sun May 22 23:04:27 2016
+++ src/sys/netinet/sctputil.h	Sun Jan 19 20:51:13 2020
@@ -1,5 +1,5 @@
 /*	$KAME: sctputil.h,v 1.15 2005/03/06 16:04:19 itojun Exp $	*/
-/*	$NetBSD: sctputil.h,v 1.2 2016/05/22 23:04:27 rjs Exp $ */
+/*	$NetBSD: sctputil.h,v 1.3 2020/01/19 20:51:13 riastradh Exp $ */
 
 #ifndef __SCTPUTIL_H__
 #define __SCTPUTIL_H__
@@ -141,8 +141,6 @@ u_int32_t sctp_select_a_tag(struct sctp_
 
 int sctp_init_asoc(struct sctp_inpcb *, struct sctp_association *, int, uint32_t);
 
-void sctp_fill_random_store(struct sctp_pcb *);
-
 int sctp_timer_start(int, struct sctp_inpcb *, struct sctp_tcb *,
 	struct sctp_nets *);
 

Index: src/sys/netinet/sctputil.c
diff -u src/sys/netinet/sctputil.c:1.15 

CVS commit: src/sys/netinet

2019-12-25 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Thu Dec 26 04:44:10 UTC 2019

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

Log Message:
 Fix typo in comment.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/netinet/sctp_output.c
cvs rdiff -u -r1.18 -r1.19 src/sys/netinet/sctp_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/sctp_output.c
diff -u src/sys/netinet/sctp_output.c:1.20 src/sys/netinet/sctp_output.c:1.21
--- src/sys/netinet/sctp_output.c:1.20	Tue Dec  3 03:25:28 2019
+++ src/sys/netinet/sctp_output.c	Thu Dec 26 04:44:10 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: sctp_output.c,v 1.20 2019/12/03 03:25:28 msaitoh Exp $ */
+/*	$NetBSD: sctp_output.c,v 1.21 2019/12/26 04:44:10 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.20 2019/12/03 03:25:28 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sctp_output.c,v 1.21 2019/12/26 04:44:10 msaitoh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ipsec.h"
@@ -1761,7 +1761,7 @@ sctp_choose_v6_boundall(struct sctp_inpc
 			/* by definition the scope (from to->sin6_scopeid)
 			 * must match that of the interface. If not then
 			 * we could pick a wrong scope for the address.
-			 * Ususally we don't hit plan-b since the route
+			 * Usually we don't hit plan-b since the route
 			 * handles this. However we can hit plan-b when
 			 * we send to local-host so the route is the
 			 * loopback interface, but the destination is a

Index: src/sys/netinet/sctp_pcb.c
diff -u src/sys/netinet/sctp_pcb.c:1.18 src/sys/netinet/sctp_pcb.c:1.19
--- src/sys/netinet/sctp_pcb.c:1.18	Tue Dec 11 14:38:45 2018
+++ src/sys/netinet/sctp_pcb.c	Thu Dec 26 04:44:10 2019
@@ -1,5 +1,5 @@
 /* $KAME: sctp_pcb.c,v 1.39 2005/06/16 18:29:25 jinmei Exp $ */
-/* $NetBSD: sctp_pcb.c,v 1.18 2018/12/11 14:38:45 christos Exp $ */
+/* $NetBSD: sctp_pcb.c,v 1.19 2019/12/26 04:44:10 msaitoh Exp $ */
 
 /*
  * Copyright (c) 2001, 2002, 2003, 2004 Cisco Systems, Inc.
@@ -33,7 +33,7 @@
  * SUCH DAMAGE.
  */
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sctp_pcb.c,v 1.18 2018/12/11 14:38:45 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sctp_pcb.c,v 1.19 2019/12/26 04:44:10 msaitoh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -212,7 +212,7 @@ sctp_fill_pcbinfo(struct sctp_pcbinfo *s
  * Notes on locks for FreeBSD 5 and up. All association
  * lookups that have a definte ep, the INP structure is
  * assumed to be locked for reading. If we need to go
- * find the INP (ususally when a **inp is passed) then
+ * find the INP (usually when a **inp is passed) then
  * we must lock the INFO structure first and if needed
  * lock the INP too. Note that if we lock it we must
  *



CVS commit: src/sys/netinet

2019-12-17 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Wed Dec 18 00:49:16 UTC 2019

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

Log Message:
inet: Add support for IPv4 /31 prefixes, as described in RFC 3021.

To run a /31 network, participating hosts MUST drop support
for directed broadcasts, and treat the first and last addresses
on subnet as unicast. The broadcast address for the prefix
should be the link local broadcast address, INADDR_BROADCAST.

Taken from FreeBSD, r226402.
Fixes PR kern/51388.


To generate a diff of this commit:
cvs rdiff -u -r1.235 -r1.236 src/sys/netinet/in.c
cvs rdiff -u -r1.108 -r1.109 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.c
diff -u src/sys/netinet/in.c:1.235 src/sys/netinet/in.c:1.236
--- src/sys/netinet/in.c:1.235	Wed Sep 25 09:53:38 2019
+++ src/sys/netinet/in.c	Wed Dec 18 00:49:15 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: in.c,v 1.235 2019/09/25 09:53:38 ozaki-r Exp $	*/
+/*	$NetBSD: in.c,v 1.236 2019/12/18 00:49:15 roy Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in.c,v 1.235 2019/09/25 09:53:38 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in.c,v 1.236 2019/12/18 00:49:15 roy Exp $");
 
 #include "arp.h"
 
@@ -1219,10 +1219,15 @@ in_ifinit(struct ifnet *ifp, struct in_i
 
 	ia->ia_ifa.ifa_metric = ifp->if_metric;
 	if (ifp->if_flags & IFF_BROADCAST) {
-		ia->ia_broadaddr.sin_addr.s_addr =
-			ia->ia_subnet | ~ia->ia_subnetmask;
-		ia->ia_netbroadcast.s_addr =
-			ia->ia_net | ~ia->ia_netmask;
+		if (ia->ia_subnetmask == IN_RFC3021_MASK) {
+			ia->ia_broadaddr.sin_addr.s_addr = INADDR_BROADCAST;
+			ia->ia_netbroadcast.s_addr = INADDR_BROADCAST;
+		} else {
+			ia->ia_broadaddr.sin_addr.s_addr =
+ia->ia_subnet | ~ia->ia_subnetmask;
+			ia->ia_netbroadcast.s_addr =
+ia->ia_net | ~ia->ia_netmask;
+		}
 	} else if (ifp->if_flags & IFF_LOOPBACK) {
 		ia->ia_dstaddr = ia->ia_addr;
 		flags |= RTF_HOST;
@@ -1426,8 +1431,10 @@ in_broadcast(struct in_addr in, struct i
 		 in_hosteq(in, ia->ia_netbroadcast) ||
 		 (hostzeroisbroadcast &&
 		  /*
-		   * Check for old-style (host 0) broadcast.
+		   * Check for old-style (host 0) broadcast, but
+		   * taking into account that RFC 3021 obsoletes it.
 		   */
+		  ia->ia_subnetmask != IN_RFC3021_MASK &&
 		  (in.s_addr == ia->ia_subnet ||
 		   in.s_addr == ia->ia_net {
 			pserialize_read_exit(s);

Index: src/sys/netinet/in.h
diff -u src/sys/netinet/in.h:1.108 src/sys/netinet/in.h:1.109
--- src/sys/netinet/in.h:1.108	Fri Nov  9 11:46:28 2018
+++ src/sys/netinet/in.h	Wed Dec 18 00:49:16 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: in.h,v 1.108 2018/11/09 11:46:28 maya Exp $	*/
+/*	$NetBSD: in.h,v 1.109 2019/12/18 00:49:16 roy Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1990, 1993
@@ -235,6 +235,8 @@ struct in_addr {
 
 #define	IN_LOOPBACKNET		127			/* official! */
 
+#define	IN_RFC3021_MASK		__IPADDR(0xfffe)
+
 /*
  * Socket address, internet style.
  */



CVS commit: src/sys/netinet

2019-04-24 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Wed Apr 24 10:20:36 UTC 2019

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

Log Message:
ARP: Enable Address Defence again.

Revert the tentative/duplicated check and test for if it's been broadcast
or not. This reverts r1.245.


To generate a diff of this commit:
cvs rdiff -u -r1.278 -r1.279 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.278 src/sys/netinet/if_arp.c:1.279
--- src/sys/netinet/if_arp.c:1.278	Sat Dec 22 14:28:57 2018
+++ src/sys/netinet/if_arp.c	Wed Apr 24 10:20:36 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_arp.c,v 1.278 2018/12/22 14:28:57 maxv Exp $	*/
+/*	$NetBSD: if_arp.c,v 1.279 2019/04/24 10:20:36 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.278 2018/12/22 14:28:57 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.279 2019/04/24 10:20:36 roy Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -1171,14 +1171,13 @@ in_arpinput(struct mbuf *m)
 	 * 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
-	 * our address is in the TENTATIVE state.
-	 * DUPLICATED state is also checked so that processing stops here
-	 * and an error can be logged.
+	 * the message was broadcast - if it's 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)
-	&& ia->ia4_flags & (IN_IFF_TENTATIVE | IN_IFF_DUPLICATED
+	(in_nullhost(isaddr) && in_hosteq(itaddr, myaddr) &&
+	 m->m_flags & M_BCAST)))
 	{
 		arp_dad_duplicated((struct ifaddr *)ia,
 		lla_snprintf(llabuf, ar_sha(ah), ah->ar_hln));



CVS commit: src/sys/netinet

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

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

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


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

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

Modified files:

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



CVS commit: src/sys/netinet

2019-02-25 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Mon Feb 25 10:49:16 UTC 2019

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

Log Message:
Improve panic messages.


To generate a diff of this commit:
cvs rdiff -u -r1.210 -r1.211 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.210 src/sys/netinet/tcp_output.c:1.211
--- src/sys/netinet/tcp_output.c:1.210	Thu Dec 27 16:59:17 2018
+++ src/sys/netinet/tcp_output.c	Mon Feb 25 10:49:16 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_output.c,v 1.210 2018/12/27 16:59:17 maxv Exp $	*/
+/*	$NetBSD: tcp_output.c,v 1.211 2019/02/25 10:49:16 maxv Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -135,7 +135,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tcp_output.c,v 1.210 2018/12/27 16:59:17 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_output.c,v 1.211 2019/02/25 10:49:16 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1340,9 +1340,9 @@ reset:			TCP_REASS_UNLOCK(tp);
 		break;
 	}
 	if (tp->t_template == NULL)
-		panic("tcp_output");
+		panic("%s: no template", __func__);
 	if (tp->t_template->m_len < iphdrlen)
-		panic("tcp_output");
+		panic("%s: %d < %d", __func__, tp->t_template->m_len, iphdrlen);
 	bcopy(mtod(tp->t_template, void *), mtod(m, void *), iphdrlen);
 
 	/*



CVS commit: src/sys/netinet

2019-02-24 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sun Feb 24 21:07:59 UTC 2019

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

Log Message:
Add missing FALLTHROUGH in sctp_input.c

Requested by GCC NetBSD/i386 kUBSan KCOC build.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/netinet/sctp_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/sctp_input.c
diff -u src/sys/netinet/sctp_input.c:1.12 src/sys/netinet/sctp_input.c:1.13
--- src/sys/netinet/sctp_input.c:1.12	Tue Feb 12 14:40:38 2019
+++ src/sys/netinet/sctp_input.c	Sun Feb 24 21:07:59 2019
@@ -1,5 +1,5 @@
 /*	$KAME: sctp_input.c,v 1.28 2005/04/21 18:36:21 nishida Exp $	*/
-/*	$NetBSD: sctp_input.c,v 1.12 2019/02/12 14:40:38 rjs Exp $	*/
+/*	$NetBSD: sctp_input.c,v 1.13 2019/02/24 21:07:59 kamil Exp $	*/
 
 /*
  * Copyright (C) 2002, 2003, 2004 Cisco Systems Inc,
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sctp_input.c,v 1.12 2019/02/12 14:40:38 rjs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sctp_input.c,v 1.13 2019/02/24 21:07:59 kamil Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ipsec.h"
@@ -682,6 +682,7 @@ sctp_process_unrecog_chunk(struct sctp_t
 			printf("Strange peer, snds ASCONF but does not recongnize asconf-ack?\n");
 		}
 #endif
+		/* FALLTHROUGH */
 	case SCTP_ASCONF:
 #ifdef SCTP_DEBUG
 		if (sctp_debug_on & SCTP_DEBUG_INPUT2) {



CVS commit: src/sys/netinet

2019-02-24 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sun Feb 24 17:01:52 UTC 2019

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

Log Message:
Appease GCC7 in sctp_asconf.h

Do not declare types inside function parameter list.
Add decklarations of types before these function prototypes.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/netinet/sctp_asconf.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_asconf.h
diff -u src/sys/netinet/sctp_asconf.h:1.1 src/sys/netinet/sctp_asconf.h:1.2
--- src/sys/netinet/sctp_asconf.h:1.1	Tue Oct 13 21:28:35 2015
+++ src/sys/netinet/sctp_asconf.h	Sun Feb 24 17:01:52 2019
@@ -1,5 +1,5 @@
 /*	$KAME: sctp_asconf.h,v 1.8 2005/03/06 16:04:16 itojun Exp $	*/
-/*	$NetBSD: sctp_asconf.h,v 1.1 2015/10/13 21:28:35 rjs Exp $ */
+/*	$NetBSD: sctp_asconf.h,v 1.2 2019/02/24 17:01:52 kamil Exp $ */
 
 #ifndef _NETINET_SCTP_ASCONF_H_
 #define _NETINET_SCTP_ASCONF_H_
@@ -36,6 +36,13 @@
 
 #if defined(_KERNEL)
 
+struct sctp_tcb;
+struct sctp_nets;
+struct sctp_asconf_chunk;
+struct sockaddr;
+struct sctp_inpcb;
+struct sctp_asconf_ack_chunk;
+
 extern void sctp_asconf_cleanup(struct sctp_tcb *, struct sctp_nets *);
 
 extern struct mbuf *sctp_compose_asconf(struct sctp_tcb *);



CVS commit: src/sys/netinet

2019-02-15 Thread Robert Swindells
Module Name:src
Committed By:   rjs
Date:   Fri Feb 15 14:13:32 UTC 2019

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

Log Message:
This really was a missing break.

Spotted by Rin Okuyama.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/netinet/sctp_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/sctp_usrreq.c
diff -u src/sys/netinet/sctp_usrreq.c:1.15 src/sys/netinet/sctp_usrreq.c:1.16
--- src/sys/netinet/sctp_usrreq.c:1.15	Tue Feb 12 14:40:38 2019
+++ src/sys/netinet/sctp_usrreq.c	Fri Feb 15 14:13:32 2019
@@ -1,5 +1,5 @@
 /*	$KAME: sctp_usrreq.c,v 1.50 2005/06/16 20:45:29 jinmei Exp $	*/
-/*	$NetBSD: sctp_usrreq.c,v 1.15 2019/02/12 14:40:38 rjs Exp $	*/
+/*	$NetBSD: sctp_usrreq.c,v 1.16 2019/02/15 14:13:32 rjs Exp $	*/
 
 /*
  * Copyright (c) 2001, 2002, 2003, 2004 Cisco Systems, Inc.
@@ -33,7 +33,7 @@
  * SUCH DAMAGE.
  */
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sctp_usrreq.c,v 1.15 2019/02/12 14:40:38 rjs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sctp_usrreq.c,v 1.16 2019/02/15 14:13:32 rjs Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -2289,7 +2289,8 @@ sctp_optsget(struct socket *so, struct s
 		*s_info = stcb->asoc.def_send;
 		SCTP_TCB_UNLOCK(stcb);
 		sopt->sopt_size = sizeof(*s_info);
-	} /* FALLTHROUGH */
+	}
+	break;
 	case SCTP_INITMSG:
 	{
 		struct sctp_initmsg *sinit;



CVS commit: src/sys/netinet

2019-02-12 Thread Robert Swindells
Module Name:src
Committed By:   rjs
Date:   Tue Feb 12 14:40:38 UTC 2019

Modified Files:
src/sys/netinet: sctp_input.c sctp_usrreq.c

Log Message:
Add some fallthrough annotations.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/netinet/sctp_input.c
cvs rdiff -u -r1.14 -r1.15 src/sys/netinet/sctp_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/sctp_input.c
diff -u src/sys/netinet/sctp_input.c:1.11 src/sys/netinet/sctp_input.c:1.12
--- src/sys/netinet/sctp_input.c:1.11	Fri Sep 14 05:09:51 2018
+++ src/sys/netinet/sctp_input.c	Tue Feb 12 14:40:38 2019
@@ -1,5 +1,5 @@
 /*	$KAME: sctp_input.c,v 1.28 2005/04/21 18:36:21 nishida Exp $	*/
-/*	$NetBSD: sctp_input.c,v 1.11 2018/09/14 05:09:51 maxv Exp $	*/
+/*	$NetBSD: sctp_input.c,v 1.12 2019/02/12 14:40:38 rjs Exp $	*/
 
 /*
  * Copyright (C) 2002, 2003, 2004 Cisco Systems Inc,
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sctp_input.c,v 1.11 2018/09/14 05:09:51 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sctp_input.c,v 1.12 2019/02/12 14:40:38 rjs Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ipsec.h"
@@ -1156,6 +1156,7 @@ sctp_process_cookie_existing(struct mbuf
 #endif
 return (NULL);
 			}
+			/* FALLTHROUGH */
 			/* intentional fall through to below... */
 
 		case SCTP_STATE_COOKIE_ECHOED:

Index: src/sys/netinet/sctp_usrreq.c
diff -u src/sys/netinet/sctp_usrreq.c:1.14 src/sys/netinet/sctp_usrreq.c:1.15
--- src/sys/netinet/sctp_usrreq.c:1.14	Mon Jan 28 12:53:01 2019
+++ src/sys/netinet/sctp_usrreq.c	Tue Feb 12 14:40:38 2019
@@ -1,5 +1,5 @@
 /*	$KAME: sctp_usrreq.c,v 1.50 2005/06/16 20:45:29 jinmei Exp $	*/
-/*	$NetBSD: sctp_usrreq.c,v 1.14 2019/01/28 12:53:01 martin Exp $	*/
+/*	$NetBSD: sctp_usrreq.c,v 1.15 2019/02/12 14:40:38 rjs Exp $	*/
 
 /*
  * Copyright (c) 2001, 2002, 2003, 2004 Cisco Systems, Inc.
@@ -33,7 +33,7 @@
  * SUCH DAMAGE.
  */
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sctp_usrreq.c,v 1.14 2019/01/28 12:53:01 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sctp_usrreq.c,v 1.15 2019/02/12 14:40:38 rjs Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -2289,7 +2289,7 @@ sctp_optsget(struct socket *so, struct s
 		*s_info = stcb->asoc.def_send;
 		SCTP_TCB_UNLOCK(stcb);
 		sopt->sopt_size = sizeof(*s_info);
-	}
+	} /* FALLTHROUGH */
 	case SCTP_INITMSG:
 	{
 		struct sctp_initmsg *sinit;



CVS commit: src/sys/netinet

2018-12-11 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Dec 11 14:38:46 UTC 2018

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

Log Message:
PR/53775: Havard Eidnes: bind(2) may inaccurately return EADDRNOTAVAIL,
it should return EADDRINUSE.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/netinet/sctp_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/sctp_pcb.c
diff -u src/sys/netinet/sctp_pcb.c:1.17 src/sys/netinet/sctp_pcb.c:1.18
--- src/sys/netinet/sctp_pcb.c:1.17	Mon Sep  3 12:29:36 2018
+++ src/sys/netinet/sctp_pcb.c	Tue Dec 11 09:38:45 2018
@@ -1,5 +1,5 @@
 /* $KAME: sctp_pcb.c,v 1.39 2005/06/16 18:29:25 jinmei Exp $ */
-/* $NetBSD: sctp_pcb.c,v 1.17 2018/09/03 16:29:36 riastradh Exp $ */
+/* $NetBSD: sctp_pcb.c,v 1.18 2018/12/11 14:38:45 christos Exp $ */
 
 /*
  * Copyright (c) 2001, 2002, 2003, 2004 Cisco Systems, Inc.
@@ -33,7 +33,7 @@
  * SUCH DAMAGE.
  */
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sctp_pcb.c,v 1.17 2018/09/03 16:29:36 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sctp_pcb.c,v 1.18 2018/12/11 14:38:45 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1763,7 +1763,7 @@ sctp_inpcb_bind(struct socket *so, struc
 
 			/* unlock info */
 			SCTP_INP_INFO_WUNLOCK();
-			return (EADDRNOTAVAIL);
+			return EADDRINUSE;
 		}
 		SCTP_INP_WLOCK(inp);
 		if (bindall) {
@@ -1773,7 +1773,7 @@ sctp_inpcb_bind(struct socket *so, struc
 SCTP_INP_DECR_REF(inp);
 SCTP_INP_WUNLOCK(inp);
 SCTP_INP_INFO_WUNLOCK();
-return (EADDRNOTAVAIL);
+return EADDRINUSE;
 			}
 		}
 	} else {



CVS commit: src/sys/netinet

2018-11-24 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat Nov 24 17:05:54 UTC 2018

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

Log Message:
KNF, no functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.220 -r1.221 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.220 src/sys/netinet/tcp_usrreq.c:1.221
--- src/sys/netinet/tcp_usrreq.c:1.220	Sat Nov 24 16:58:40 2018
+++ src/sys/netinet/tcp_usrreq.c	Sat Nov 24 17:05:54 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_usrreq.c,v 1.220 2018/11/24 16:58:40 maxv Exp $	*/
+/*	$NetBSD: tcp_usrreq.c,v 1.221 2018/11/24 17:05:54 maxv Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -99,7 +99,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tcp_usrreq.c,v 1.220 2018/11/24 16:58:40 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_usrreq.c,v 1.221 2018/11/24 17:05:54 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -152,8 +152,8 @@ __KERNEL_RCSID(0, "$NetBSD: tcp_usrreq.c
 #include 
 #include 
 
-static int  
-tcp_debug_capture(struct tcpcb *tp, int req)  
+static int
+tcp_debug_capture(struct tcpcb *tp, int req)
 {
 #ifdef TCP_DEBUG
 	return tp->t_state;
@@ -163,7 +163,7 @@ tcp_debug_capture(struct tcpcb *tp, int 
 
 static inline void
 tcp_debug_trace(struct socket *so, struct tcpcb *tp, int ostate, int req)
-{
+{
 #ifdef TCP_DEBUG
 	if (tp && (so->so_options & SO_DEBUG))
 		tcp_trace(TA_USER, ostate, tp, NULL, req);
@@ -216,7 +216,7 @@ change_keepalive(struct socket *so, stru
 	if (tp->t_state == TCPS_SYN_RECEIVED ||
 	tp->t_state == TCPS_SYN_SENT) {
 		TCP_TIMER_ARM(tp, TCPT_KEEP, tp->t_keepinit);
-	} else if (so->so_options & SO_KEEPALIVE && 
+	} else if (so->so_options & SO_KEEPALIVE &&
 	tp->t_state <= TCPS_CLOSE_WAIT) {
 		TCP_TIMER_ARM(tp, TCPT_KEEP, tp->t_keepintvl);
 	} else {
@@ -330,7 +330,7 @@ tcp_ctloutput(int op, struct socket *so,
 #endif
 	{
 		splx(s);
-		return (ECONNRESET);
+		return ECONNRESET;
 	}
 	if (level != IPPROTO_TCP) {
 		switch (family) {
@@ -344,7 +344,7 @@ tcp_ctloutput(int op, struct socket *so,
 #endif
 		}
 		splx(s);
-		return (error);
+		return error;
 	}
 	if (inp)
 		tp = intotcpcb(inp);
@@ -487,7 +487,7 @@ setval:			error = sockopt_set(sopt, 
 		break;
 	}
 	splx(s);
-	return (error);
+	return error;
 }
 
 #ifndef TCP_SENDSPACE
@@ -1255,7 +1255,7 @@ tcp_disconnect1(struct tcpcb *tp)
 		if (tp)
 			(void) tcp_output(tp);
 	}
-	return (tp);
+	return tp;
 }
 
 /*
@@ -1322,7 +1322,7 @@ tcp_usrclosed(struct tcpcb *tp)
 			tp = 0;
 		}
 	}
-	return (tp);
+	return tp;
 }
 
 /*
@@ -1340,17 +1340,17 @@ sysctl_net_inet_tcp_mssdflt(SYSCTLFN_ARG
 	node.sysctl_data = 
 	error = sysctl_lookup(SYSCTLFN_CALL());
 	if (error || newp == NULL)
-		return (error);
+		return error;
 
 	if (mssdflt < 32)
-		return (EINVAL);
+		return EINVAL;
 	tcp_mssdflt = mssdflt;
 
 	mutex_enter(softnet_lock);
 	tcp_tcpcb_template();
 	mutex_exit(softnet_lock);
 
-	return (0);
+	return 0;
 }
 
 /*
@@ -1401,7 +1401,7 @@ sysctl_net_inet_ip_ports(SYSCTLFN_ARGS)
 	struct sysctlnode node;
 
 	if (namelen != 0)
-		return (EINVAL);
+		return EINVAL;
 
 	switch (name[-3]) {
 	case PF_INET:
@@ -1423,7 +1423,7 @@ sysctl_net_inet_ip_ports(SYSCTLFN_ARGS)
 		break;
 #endif /* INET6 */
 	default:
-		return (EINVAL);
+		return EINVAL;
 	}
 
 	/*
@@ -1435,13 +1435,13 @@ sysctl_net_inet_ip_ports(SYSCTLFN_ARGS)
 	node.sysctl_data = 
 	error = sysctl_lookup(SYSCTLFN_CALL());
 	if (error || newp == NULL)
-		return (error);
+		return error;
 
 	/*
 	 * simple port range check
 	 */
 	if (tmp < 0 || tmp > 65535)
-		return (EINVAL);
+		return EINVAL;
 
 	/*
 	 * per-node range checks
@@ -1450,20 +1450,20 @@ sysctl_net_inet_ip_ports(SYSCTLFN_ARGS)
 	case IPCTL_ANONPORTMIN:
 	case IPV6CTL_ANONPORTMIN:
 		if (tmp >= apmax)
-			return (EINVAL);
+			return EINVAL;
 #ifndef IPNOPRIVPORTS
 		if (tmp < IPPORT_RESERVED)
-return (EINVAL);
+return EINVAL;
 #endif /* IPNOPRIVPORTS */
 		break;
 
 	case IPCTL_ANONPORTMAX:
 	case IPV6CTL_ANONPORTMAX:
 if (apmin >= tmp)
-			return (EINVAL);
+			return EINVAL;
 #ifndef IPNOPRIVPORTS
 		if (tmp < IPPORT_RESERVED)
-return (EINVAL);
+return EINVAL;
 #endif /* IPNOPRIVPORTS */
 		break;
 
@@ -1473,7 +1473,7 @@ sysctl_net_inet_ip_ports(SYSCTLFN_ARGS)
 		if (tmp >= lpmax ||
 		tmp > IPPORT_RESERVEDMAX ||
 		tmp < IPPORT_RESERVEDMIN)
-			return (EINVAL);
+			return EINVAL;
 		break;
 
 	case IPCTL_LOWPORTMAX:
@@ -1481,17 +1481,17 @@ sysctl_net_inet_ip_ports(SYSCTLFN_ARGS)
 		if (lpmin >= tmp ||
 		tmp > IPPORT_RESERVEDMAX ||
 		tmp < IPPORT_RESERVEDMIN)
-			return (EINVAL);
+			return EINVAL;
 		break;
 #endif /* IPNOPRIVPORTS */
 
 	default:
-		return (EINVAL);
+		

CVS commit: src/sys/netinet

2018-11-24 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat Nov 24 16:58:40 UTC 2018

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

Log Message:
Fix kernel pointer leaks in sysctl_inpcblist.


To generate a diff of this commit:
cvs rdiff -u -r1.219 -r1.220 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.219 src/sys/netinet/tcp_usrreq.c:1.220
--- src/sys/netinet/tcp_usrreq.c:1.219	Thu May  3 07:13:48 2018
+++ src/sys/netinet/tcp_usrreq.c	Sat Nov 24 16:58:40 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_usrreq.c,v 1.219 2018/05/03 07:13:48 maxv Exp $	*/
+/*	$NetBSD: tcp_usrreq.c,v 1.220 2018/11/24 16:58:40 maxv Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -99,7 +99,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tcp_usrreq.c,v 1.219 2018/05/03 07:13:48 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_usrreq.c,v 1.220 2018/11/24 16:58:40 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1713,6 +1713,7 @@ sysctl_net_inet_tcp_ident(SYSCTLFN_ARGS)
 int
 sysctl_inpcblist(SYSCTLFN_ARGS)
 {
+	const bool allowaddr = get_expose_address(curproc);
 	struct sockaddr_in *in;
 	const struct inpcb *inp;
 #ifdef INET6
@@ -1798,9 +1799,12 @@ sysctl_inpcblist(SYSCTLFN_ARGS)
 pcb.ki_tflags = tp->t_flags;
 			}
 
-			pcb.ki_pcbaddr = PTRTOUINT64(inp);
-			pcb.ki_ppcbaddr = PTRTOUINT64(inp->inp_ppcb);
-			pcb.ki_sockaddr = PTRTOUINT64(inp->inp_socket);
+			COND_SET_VALUE(pcb.ki_pcbaddr,
+			PTRTOUINT64(inp), allowaddr);
+			COND_SET_VALUE(pcb.ki_ppcbaddr,
+			PTRTOUINT64(inp->inp_ppcb), allowaddr);
+			COND_SET_VALUE(pcb.ki_sockaddr,
+			PTRTOUINT64(inp->inp_socket), allowaddr);
 
 			pcb.ki_rcvq = inp->inp_socket->so_rcv.sb_cc;
 			pcb.ki_sndq = inp->inp_socket->so_snd.sb_cc;
@@ -1835,9 +1839,12 @@ sysctl_inpcblist(SYSCTLFN_ARGS)
 pcb.ki_tflags = tp->t_flags;
 			}
 
-			pcb.ki_pcbaddr = PTRTOUINT64(in6p);
-			pcb.ki_ppcbaddr = PTRTOUINT64(in6p->in6p_ppcb);
-			pcb.ki_sockaddr = PTRTOUINT64(in6p->in6p_socket);
+			COND_SET_VALUE(pcb.ki_pcbaddr,
+			PTRTOUINT64(in6p), allowaddr);
+			COND_SET_VALUE(pcb.ki_ppcbaddr,
+			PTRTOUINT64(in6p->in6p_ppcb), allowaddr);
+			COND_SET_VALUE(pcb.ki_sockaddr,
+			PTRTOUINT64(in6p->in6p_socket), allowaddr);
 
 			pcb.ki_rcvq = in6p->in6p_socket->so_rcv.sb_cc;
 			pcb.ki_sndq = in6p->in6p_socket->so_snd.sb_cc;



CVS commit: src/sys/netinet

2018-11-09 Thread Maya Rashish
Module Name:src
Committed By:   maya
Date:   Fri Nov  9 11:46:28 UTC 2018

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

Log Message:
Use the same type redefinition guards as stdint.h since rev1.8

PR pkg/53713


To generate a diff of this commit:
cvs rdiff -u -r1.107 -r1.108 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.107 src/sys/netinet/in.h:1.108
--- src/sys/netinet/in.h:1.107	Wed Aug 22 01:05:24 2018
+++ src/sys/netinet/in.h	Fri Nov  9 11:46:28 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: in.h,v 1.107 2018/08/22 01:05:24 msaitoh Exp $	*/
+/*	$NetBSD: in.h,v 1.108 2018/11/09 11:46:28 maya Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1990, 1993
@@ -42,14 +42,14 @@
 #include 
 #include 
 
-#ifndef uint8_t
+#ifndef	_BSD_UINT8_T_
 typedef __uint8_t	uint8_t;
-#define	uint8_t		__uint8_t
+#define	_BSD_UINT8_T_
 #endif
 
-#ifndef uint32_t
+#ifndef	_BSD_UINT32_T_
 typedef __uint32_t	uint32_t;
-#define	uint32_t	__uint32_t
+#define	_BSD_UINT32_T_
 #endif
 
 #include 



CVS commit: src/sys/netinet

2018-10-11 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Oct 12 05:41:18 UTC 2018

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

Log Message:
Force ip_off to zero when the reassembly is complete. This was lost in my
rev1.19 - before that the IP struct was clobbered for the reassembly, but
it actually implicitly guaranteed that the first fragment of the packet
would end up with ip_off = 0, and this was a desired behavior.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/netinet/ip_reass.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_reass.c
diff -u src/sys/netinet/ip_reass.c:1.20 src/sys/netinet/ip_reass.c:1.21
--- src/sys/netinet/ip_reass.c:1.20	Mon Sep 17 08:11:27 2018
+++ src/sys/netinet/ip_reass.c	Fri Oct 12 05:41:18 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_reass.c,v 1.20 2018/09/17 08:11:27 maxv Exp $	*/
+/*	$NetBSD: ip_reass.c,v 1.21 2018/10/12 05:41:18 maxv Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1988, 1993
@@ -46,7 +46,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip_reass.c,v 1.20 2018/09/17 08:11:27 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_reass.c,v 1.21 2018/10/12 05:41:18 maxv Exp $");
 
 #include 
 #include 
@@ -402,6 +402,7 @@ insert:
 	 * header visible.
 	 */
 	ip->ip_len = htons((ip->ip_hl << 2) + next);
+	ip->ip_off = htons(0);
 	ip->ip_src = fp->ipq_src;
 	ip->ip_dst = fp->ipq_dst;
 	free(fp, M_FTABLE);



CVS commit: src/sys/netinet

2018-09-17 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Mon Sep 17 08:11:27 UTC 2018

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

Log Message:
Kick fragments that would introduce several !MFFs in a reassembly chain.

The problem arises if we receive three fragments of the kind

3.  A -> has MFF
1.  B -> doesn't have MFF
2.  C -> doesn't have MFF

Because of the received order B->C->A, we don't see that B is !MFF, and
therefore that there is a problem in this chain.

Now we do two checks, and drop us if:

 * there is a fragment preceding us, and this fragment is !MFF, or
 * there is a fragment following us, and we are !MFF

Spotted a long time ago.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/netinet/ip_reass.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_reass.c
diff -u src/sys/netinet/ip_reass.c:1.19 src/sys/netinet/ip_reass.c:1.20
--- src/sys/netinet/ip_reass.c:1.19	Mon Sep 17 06:01:36 2018
+++ src/sys/netinet/ip_reass.c	Mon Sep 17 08:11:27 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_reass.c,v 1.19 2018/09/17 06:01:36 maxv Exp $	*/
+/*	$NetBSD: ip_reass.c,v 1.20 2018/09/17 08:11:27 maxv Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1988, 1993
@@ -46,7 +46,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip_reass.c,v 1.19 2018/09/17 06:01:36 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_reass.c,v 1.20 2018/09/17 08:11:27 maxv Exp $");
 
 #include 
 #include 
@@ -287,9 +287,13 @@ ip_reass(ipfr_qent_t *ipqe, ipfr_queue_t
 	}
 
 	/*
-	 * If there is a preceding segment, it may provide some of our
-	 * data already.  If so, drop the data from the incoming segment.
-	 * If it provides all of our data, drop us.
+	 * Look at the preceding segment.
+	 *
+	 * If it provides some of our data already, in part or entirely, trim
+	 * us or drop us.
+	 *
+	 * If a preceding segment exists, and was marked as the last segment,
+	 * drop us.
 	 */
 	if (p != NULL) {
 		i = p->ipqe_off + p->ipqe_len - ipqe->ipqe_off;
@@ -302,10 +306,17 @@ ip_reass(ipfr_qent_t *ipqe, ipfr_queue_t
 			ipqe->ipqe_len = ipqe->ipqe_len - i;
 		}
 	}
+	if (p != NULL && !p->ipqe_mff) {
+		goto dropfrag;
+	}
 
 	/*
-	 * While we overlap succeeding segments trim them or, if they are
-	 * completely covered, dequeue them.
+	 * Look at the segments that follow.
+	 *
+	 * If we cover them, in part or entirely, trim them or dequeue them.
+	 *
+	 * If a following segment exists, and we are marked as the last
+	 * segment, drop us.
 	 */
 	while (q != NULL) {
 		i = ipqe->ipqe_off + ipqe->ipqe_len - q->ipqe_off;
@@ -326,6 +337,9 @@ ip_reass(ipfr_qent_t *ipqe, ipfr_queue_t
 		ip_nfrags--;
 		q = nq;
 	}
+	if (q != NULL && !ipqe->ipqe_mff) {
+		goto dropfrag;
+	}
 
 insert:
 	/*



CVS commit: src/sys/netinet

2018-09-17 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Mon Sep 17 06:01:36 UTC 2018

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

Log Message:
Hold ip_off and ip_len in the fragment entry, instead of always reading
the associated mbuf (and converting to host order). This reduces the
cache/TLB misses when processing long lists.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/netinet/ip_reass.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_reass.c
diff -u src/sys/netinet/ip_reass.c:1.18 src/sys/netinet/ip_reass.c:1.19
--- src/sys/netinet/ip_reass.c:1.18	Tue Jul 10 15:46:58 2018
+++ src/sys/netinet/ip_reass.c	Mon Sep 17 06:01:36 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_reass.c,v 1.18 2018/07/10 15:46:58 maxv Exp $	*/
+/*	$NetBSD: ip_reass.c,v 1.19 2018/09/17 06:01:36 maxv Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1988, 1993
@@ -46,7 +46,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip_reass.c,v 1.18 2018/07/10 15:46:58 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_reass.c,v 1.19 2018/09/17 06:01:36 maxv Exp $");
 
 #include 
 #include 
@@ -80,6 +80,8 @@ typedef struct ipfr_qent {
 	struct ip *		ipqe_ip;
 	struct mbuf *		ipqe_m;
 	bool			ipqe_mff;
+	uint16_t		ipqe_off;
+	uint16_t		ipqe_len;
 } ipfr_qent_t;
 
 TAILQ_HEAD(ipfr_qent_head, ipfr_qent);
@@ -215,7 +217,7 @@ ip_nmbclusters_changed(void)
 static struct mbuf *
 ip_reass(ipfr_qent_t *ipqe, ipfr_queue_t *fp, const u_int hash)
 {
-	struct ip *ip = ipqe->ipqe_ip, *qip;
+	struct ip *ip = ipqe->ipqe_ip;
 	const int hlen = ip->ip_hl << 2;
 	struct mbuf *m = ipqe->ipqe_m, *t;
 	int ipsecflags = m->m_flags & (M_DECRYPTED|M_AUTHIPHDR);
@@ -230,16 +232,6 @@ ip_reass(ipfr_qent_t *ipqe, ipfr_queue_t
 	m->m_data += hlen;
 	m->m_len -= hlen;
 
-#ifdef	notyet
-	/* Make sure fragment limit is up-to-date. */
-	CHECK_NMBCLUSTER_PARAMS();
-
-	/* If we have too many fragments, drop the older half. */
-	if (ip_nfrags >= ip_maxfrags) {
-		ip_reass_drophalf(void);
-	}
-#endif
-
 	/*
 	 * We are about to add a fragment; increment frag count.
 	 */
@@ -255,9 +247,9 @@ ip_reass(ipfr_qent_t *ipqe, ipfr_queue_t
 		 * never accept fragments  b) if maxfrag is -1, accept
 		 * all fragments without limitation.
 		 */
-		if (ip_maxfragpackets < 0)
-			;
-		else if (ip_nfragpackets >= ip_maxfragpackets) {
+		if (ip_maxfragpackets < 0) {
+			/* no limit */
+		} else if (ip_nfragpackets >= ip_maxfragpackets) {
 			goto dropfrag;
 		}
 		fp = malloc(sizeof(ipfr_queue_t), M_FTABLE, M_NOWAIT);
@@ -285,7 +277,7 @@ ip_reass(ipfr_qent_t *ipqe, ipfr_queue_t
 	 * Find a segment which begins after this one does.
 	 */
 	TAILQ_FOREACH(q, >ipq_fragq, ipqe_q) {
-		if (ntohs(q->ipqe_ip->ip_off) > ntohs(ip->ip_off))
+		if (q->ipqe_off > ipqe->ipqe_off)
 			break;
 	}
 	if (q != NULL) {
@@ -300,15 +292,14 @@ ip_reass(ipfr_qent_t *ipqe, ipfr_queue_t
 	 * If it provides all of our data, drop us.
 	 */
 	if (p != NULL) {
-		i = ntohs(p->ipqe_ip->ip_off) + ntohs(p->ipqe_ip->ip_len) -
-		ntohs(ip->ip_off);
+		i = p->ipqe_off + p->ipqe_len - ipqe->ipqe_off;
 		if (i > 0) {
-			if (i >= ntohs(ip->ip_len)) {
+			if (i >= ipqe->ipqe_len) {
 goto dropfrag;
 			}
 			m_adj(ipqe->ipqe_m, i);
-			ip->ip_off = htons(ntohs(ip->ip_off) + i);
-			ip->ip_len = htons(ntohs(ip->ip_len) - i);
+			ipqe->ipqe_off = ipqe->ipqe_off + i;
+			ipqe->ipqe_len = ipqe->ipqe_len - i;
 		}
 	}
 
@@ -317,17 +308,13 @@ ip_reass(ipfr_qent_t *ipqe, ipfr_queue_t
 	 * completely covered, dequeue them.
 	 */
 	while (q != NULL) {
-		size_t end;
-
-		qip = q->ipqe_ip;
-		end = ntohs(ip->ip_off) + ntohs(ip->ip_len);
-		if (end <= ntohs(qip->ip_off)) {
+		i = ipqe->ipqe_off + ipqe->ipqe_len - q->ipqe_off;
+		if (i <= 0) {
 			break;
 		}
-		i = end - ntohs(qip->ip_off);
-		if (i < ntohs(qip->ip_len)) {
-			qip->ip_len = htons(ntohs(qip->ip_len) - i);
-			qip->ip_off = htons(ntohs(qip->ip_off) + i);
+		if (i < q->ipqe_len) {
+			q->ipqe_off = q->ipqe_off + i;
+			q->ipqe_len = q->ipqe_len - i;
 			m_adj(q->ipqe_m, i);
 			break;
 		}
@@ -351,12 +338,11 @@ insert:
 	}
 	next = 0;
 	TAILQ_FOREACH(q, >ipq_fragq, ipqe_q) {
-		qip = q->ipqe_ip;
-		if (ntohs(qip->ip_off) != next) {
+		if (q->ipqe_off != next) {
 			mutex_exit(_lock);
 			return NULL;
 		}
-		next += ntohs(qip->ip_len);
+		next += q->ipqe_len;
 	}
 	p = TAILQ_LAST(>ipq_fragq, ipfr_qent_head);
 	if (p->ipqe_mff) {
@@ -652,13 +638,6 @@ ip_reass_packet(struct mbuf **m0)
 		return EINVAL;
 	}
 
-	/*
-	 * Adjust total IP length to not reflect header and convert
-	 * offset of this to bytes.  XXX: clobbers struct ip.
-	 */
-	ip->ip_len = htons(flen);
-	ip->ip_off = htons(off);
-
 	/* Look for queue of fragments of this datagram. */
 	mutex_enter(_lock);
 	hash = IPREASS_HASH(ip->ip_src.s_addr, ip->ip_id);
@@ -703,6 +682,8 @@ ip_reass_packet(struct mbuf **m0)
 	ipqe->ipqe_mff = mff;
 	ipqe->ipqe_m = m;
 	ipqe->ipqe_ip = ip;
+	

CVS commit: src/sys/netinet

2018-09-13 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Sep 14 04:29:46 UTC 2018

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

Log Message:
rename toff -> off


To generate a diff of this commit:
cvs rdiff -u -r1.410 -r1.411 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.410 src/sys/netinet/tcp_input.c:1.411
--- src/sys/netinet/tcp_input.c:1.410	Fri Sep 14 04:25:16 2018
+++ src/sys/netinet/tcp_input.c	Fri Sep 14 04:29:46 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_input.c,v 1.410 2018/09/14 04:25:16 maxv Exp $	*/
+/*	$NetBSD: tcp_input.c,v 1.411 2018/09/14 04:29:46 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.410 2018/09/14 04:25:16 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.411 2018/09/14 04:29:46 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1183,7 +1183,7 @@ tcp_input(struct mbuf *m, ...)
 #endif
 	u_int8_t *optp = NULL;
 	int optlen = 0;
-	int len, tlen, toff, hdroptlen = 0;
+	int len, tlen, off, hdroptlen = 0;
 	struct tcpcb *tp = NULL;
 	int tiflags;
 	struct socket *so = NULL;
@@ -1207,7 +1207,7 @@ tcp_input(struct mbuf *m, ...)
 
 	MCLAIM(m, _rx_mowner);
 	va_start(ap, m);
-	toff = va_arg(ap, int);
+	off = va_arg(ap, int);
 	(void)va_arg(ap, int);		/* ignore value, advance ap */
 	va_end(ap);
 
@@ -1237,7 +1237,7 @@ tcp_input(struct mbuf *m, ...)
 	}
 #endif
 
-	M_REGION_GET(th, struct tcphdr *, m, toff, sizeof(struct tcphdr));
+	M_REGION_GET(th, struct tcphdr *, m, off, sizeof(struct tcphdr));
 	if (th == NULL) {
 		TCP_STATINC(TCP_STAT_RCVSHORT);
 		return;
@@ -1262,7 +1262,7 @@ tcp_input(struct mbuf *m, ...)
 
 		/* We do the checksum after PCB lookup... */
 		len = ntohs(ip->ip_len);
-		tlen = len - toff;
+		tlen = len - off;
 		iptos = ip->ip_tos;
 		break;
 #ifdef INET6
@@ -1296,7 +1296,7 @@ tcp_input(struct mbuf *m, ...)
 
 		/* We do the checksum after PCB lookup... */
 		len = m->m_pkthdr.len;
-		tlen = len - toff;
+		tlen = len - off;
 		iptos = (ntohl(ip6->ip6_flow) >> 20) & 0xff;
 		break;
 #endif
@@ -1310,7 +1310,7 @@ tcp_input(struct mbuf *m, ...)
 	 * some cases, see kern/50766 for details.
 	 */
 	if (TCP_HDR_ALIGNED_P(th) == 0) {
-		m = m_copyup(m, toff + sizeof(struct tcphdr), 0);
+		m = m_copyup(m, off + sizeof(struct tcphdr), 0);
 		if (m == NULL) {
 			TCP_STATINC(TCP_STAT_RCVSHORT);
 			return;
@@ -1319,7 +1319,7 @@ tcp_input(struct mbuf *m, ...)
 #ifdef INET6
 		ip6 = mtod(m, struct ip6_hdr *);
 #endif
-		th = (struct tcphdr *)(mtod(m, char *) + toff);
+		th = (struct tcphdr *)(mtod(m, char *) + off);
 	}
 	KASSERT(TCP_HDR_ALIGNED_P(th));
 
@@ -1335,7 +1335,7 @@ tcp_input(struct mbuf *m, ...)
 	tlen -= thlen;
 
 	if (thlen > sizeof(struct tcphdr)) {
-		M_REGION_GET(th, struct tcphdr *, m, toff, thlen);
+		M_REGION_GET(th, struct tcphdr *, m, off, thlen);
 		if (th == NULL) {
 			TCP_STATINC(TCP_STAT_RCVSHORT);
 			return;
@@ -1368,7 +1368,7 @@ tcp_input(struct mbuf *m, ...)
 	/*
 	 * Checksum extended TCP header and data
 	 */
-	if (tcp_input_checksum(af, m, th, toff, thlen, tlen))
+	if (tcp_input_checksum(af, m, th, off, thlen, tlen))
 		goto badcsum;
 
 	/*
@@ -1743,7 +1743,7 @@ nosave:;
 			 * state for it.
 			 */
 			if (so->so_qlen <= so->so_qlimit &&
-			syn_cache_add(, , th, toff,
+			syn_cache_add(, , th, off,
 			so, m, optp, optlen, ))
 m = NULL;
 		}
@@ -1773,7 +1773,7 @@ after_listen:
 #else
 	if (optp)
 #endif
-		if (tcp_dooptions(tp, optp, optlen, th, m, toff, ) < 0)
+		if (tcp_dooptions(tp, optp, optlen, th, m, off, ) < 0)
 			goto drop;
 
 	if (TCP_SACK_ENABLED(tp)) {
@@ -2020,7 +2020,7 @@ after_listen:
 	if (!sbreserve(>so_rcv,
 	newsize, so))
 		so->so_rcv.sb_flags &= ~SB_AUTOSIZE;
-m_adj(m, toff + thlen);
+m_adj(m, off + thlen);
 sbappendstream(>so_rcv, m);
 			}
 			sorwakeup(so);
@@ -2039,7 +2039,7 @@ after_listen:
 	/*
 	 * Compute mbuf offset to TCP data segment.
 	 */
-	hdroptlen = toff + thlen;
+	hdroptlen = off + thlen;
 
 	/*
 	 * Calculate amount of space in receive window. Receive window is



CVS commit: src/sys/netinet

2018-09-13 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Sep 14 04:25:16 UTC 2018

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

Log Message:
rename off -> thlen


To generate a diff of this commit:
cvs rdiff -u -r1.409 -r1.410 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.409 src/sys/netinet/tcp_input.c:1.410
--- src/sys/netinet/tcp_input.c:1.409	Mon Sep  3 16:29:36 2018
+++ src/sys/netinet/tcp_input.c	Fri Sep 14 04:25:16 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_input.c,v 1.409 2018/09/03 16:29:36 riastradh Exp $	*/
+/*	$NetBSD: tcp_input.c,v 1.410 2018/09/14 04:25:16 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.409 2018/09/03 16:29:36 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.410 2018/09/14 04:25:16 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1194,7 +1194,7 @@ tcp_input(struct mbuf *m, ...)
 #endif
 	u_long tiwin;
 	struct tcp_opt_info opti;
-	int off, iphlen;
+	int thlen, iphlen;
 	va_list ap;
 	int af;		/* af on the wire */
 	struct mbuf *tcp_saveti = NULL;
@@ -1327,21 +1327,21 @@ tcp_input(struct mbuf *m, ...)
 	 * Check that TCP offset makes sense, pull out TCP options and
 	 * adjust length.
 	 */
-	off = th->th_off << 2;
-	if (off < sizeof(struct tcphdr) || off > tlen) {
+	thlen = th->th_off << 2;
+	if (thlen < sizeof(struct tcphdr) || thlen > tlen) {
 		TCP_STATINC(TCP_STAT_RCVBADOFF);
 		goto drop;
 	}
-	tlen -= off;
+	tlen -= thlen;
 
-	if (off > sizeof(struct tcphdr)) {
-		M_REGION_GET(th, struct tcphdr *, m, toff, off);
+	if (thlen > sizeof(struct tcphdr)) {
+		M_REGION_GET(th, struct tcphdr *, m, toff, thlen);
 		if (th == NULL) {
 			TCP_STATINC(TCP_STAT_RCVSHORT);
 			return;
 		}
 		KASSERT(TCP_HDR_ALIGNED_P(th));
-		optlen = off - sizeof(struct tcphdr);
+		optlen = thlen - sizeof(struct tcphdr);
 		optp = ((u_int8_t *)th) + sizeof(struct tcphdr);
 
 		/*
@@ -1368,7 +1368,7 @@ tcp_input(struct mbuf *m, ...)
 	/*
 	 * Checksum extended TCP header and data
 	 */
-	if (tcp_input_checksum(af, m, th, toff, off, tlen))
+	if (tcp_input_checksum(af, m, th, toff, thlen, tlen))
 		goto badcsum;
 
 	/*
@@ -2020,7 +2020,7 @@ after_listen:
 	if (!sbreserve(>so_rcv,
 	newsize, so))
 		so->so_rcv.sb_flags &= ~SB_AUTOSIZE;
-m_adj(m, toff + off);
+m_adj(m, toff + thlen);
 sbappendstream(>so_rcv, m);
 			}
 			sorwakeup(so);
@@ -2039,7 +2039,7 @@ after_listen:
 	/*
 	 * Compute mbuf offset to TCP data segment.
 	 */
-	hdroptlen = toff + off;
+	hdroptlen = toff + thlen;
 
 	/*
 	 * Calculate amount of space in receive window. Receive window is



CVS commit: src/sys/netinet

2018-09-02 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sun Sep  2 16:05:33 UTC 2018

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

Log Message:
remove reference to ipnat, and duplicate comments


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

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

Modified files:

Index: src/sys/netinet/ip_input.c
diff -u src/sys/netinet/ip_input.c:1.385 src/sys/netinet/ip_input.c:1.386
--- src/sys/netinet/ip_input.c:1.385	Tue Jul 10 15:46:58 2018
+++ src/sys/netinet/ip_input.c	Sun Sep  2 16:05:33 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_input.c,v 1.385 2018/07/10 15:46:58 maxv Exp $	*/
+/*	$NetBSD: ip_input.c,v 1.386 2018/09/02 16:05:33 maxv Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.385 2018/07/10 15:46:58 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.386 2018/09/02 16:05:33 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -176,7 +176,7 @@ int ip_do_randomid = 0;
  * and transmit implementation do not implement the Strong ES model,
  * setting this to 1 results in an odd hybrid.
  *
- * XXX - ip_checkinterface currently must be disabled if you use ipnat
+ * XXX - ip_checkinterface currently must be disabled if you use NAT
  * to translate the destination address to another local interface.
  *
  * XXX - ip_checkinterface must be disabled if you add IP aliases
@@ -324,13 +324,6 @@ ip_match_our_address(struct ifnet *ifp, 
 	 * strong ES model) if IP forwarding is disabled and the packet
 	 * is not locally generated.
 	 *
-	 * XXX - Checking also should be disabled if the destination
-	 * address is ipnat'ed to a different interface.
-	 *
-	 * XXX - Checking is incompatible with IP aliases added
-	 * to the loopback interface instead of the interface where
-	 * the packets are received.
-	 *
 	 * XXX - We need to add a per ifaddr flag for this so that
 	 * we get finer grain control.
 	 */



CVS commit: src/sys/netinet

2018-08-28 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Tue Aug 28 07:28:01 UTC 2018

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

Log Message:
No need to update mlen also in the case of (meln & 16) != 0.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/netinet/cpu_in_cksum.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/cpu_in_cksum.c
diff -u src/sys/netinet/cpu_in_cksum.c:1.1 src/sys/netinet/cpu_in_cksum.c:1.2
--- src/sys/netinet/cpu_in_cksum.c:1.1	Fri Jan 25 21:12:14 2008
+++ src/sys/netinet/cpu_in_cksum.c	Tue Aug 28 07:28:01 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu_in_cksum.c,v 1.1 2008/01/25 21:12:14 joerg Exp $	*/
+/*	$NetBSD: cpu_in_cksum.c,v 1.2 2018/08/28 07:28:01 rin Exp $	*/
 /*-
  * Copyright (c) 2008 Joerg Sonnenberger .
  * All rights reserved.
@@ -29,7 +29,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpu_in_cksum.c,v 1.1 2008/01/25 21:12:14 joerg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu_in_cksum.c,v 1.2 2018/08/28 07:28:01 rin Exp $");
 
 #include 
 #include 
@@ -162,6 +162,10 @@ cpu_in_cksum(struct mbuf *m, int len, in
 partial = 0;
 			}
 		}
+		/*
+		 * mlen is not updated below as the remaining tests
+		 * are using bit masks, which are not affected.
+		 */
 		if (mlen & 16) {
 			partial += *(uint16_t *)data;
 			partial += *(uint16_t *)(data + 2);
@@ -172,12 +176,7 @@ cpu_in_cksum(struct mbuf *m, int len, in
 			partial += *(uint16_t *)(data + 12);
 			partial += *(uint16_t *)(data + 14);
 			data += 16;
-			mlen -= 16;
 		}
-		/*
-		 * mlen is not updated below as the remaining tests
-		 * are using bit masks, which are not affected.
-		 */
 		if (mlen & 8) {
 			partial += *(uint16_t *)data;
 			partial += *(uint16_t *)(data + 2);



CVS commit: src/sys/netinet

2018-08-10 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Fri Aug 10 07:20:59 UTC 2018

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

Log Message:
 Change the type of wqinput's drop counter to uint64_t. OK'd by ozaki-r@.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 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.4 src/sys/netinet/wqinput.c:1.5
--- src/sys/netinet/wqinput.c:1.4	Sat Feb 24 07:37:09 2018
+++ src/sys/netinet/wqinput.c	Fri Aug 10 07:20:59 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: wqinput.c,v 1.4 2018/02/24 07:37:09 ozaki-r Exp $	*/
+/*	$NetBSD: wqinput.c,v 1.5 2018/08/10 07:20:59 msaitoh Exp $	*/
 
 /*-
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -62,7 +62,7 @@ struct wqinput_worklist {
 	struct wqinput_work *wwl_head;
 	struct wqinput_work *wwl_tail;
 	unsigned int	wwl_len;
-	unsigned long	wwl_dropped;
+	uint64_t	wwl_dropped;
 	struct work	wwl_work;
 	bool		wwl_wq_is_active;
 };
@@ -81,7 +81,7 @@ static void
 wqinput_drops(void *p, void *arg, struct cpu_info *ci __unused)
 {
 	struct wqinput_worklist *const wwl = p;
-	int *sum = arg;
+	uint64_t *sum = arg;
 
 	*sum += wwl->wwl_dropped;
 }
@@ -91,7 +91,7 @@ wqinput_sysctl_drops_handler(SYSCTLFN_AR
 {
 	struct sysctlnode node;
 	struct wqinput *wqi;
-	int sum = 0;
+	uint64_t sum = 0;
 	int error;
 
 	node = *rnode;
@@ -135,7 +135,7 @@ wqinput_sysctl_setup(const char *name, s
 		goto bad;
 
 	error = sysctl_createv(NULL, 0, , ,
-	CTLFLAG_PERMANENT, CTLTYPE_INT, "drops",
+	CTLFLAG_PERMANENT, CTLTYPE_QUAD, "drops",
 	SYSCTL_DESCR("Total packets dropped due to full input queue"),
 	wqinput_sysctl_drops_handler, 0, (void *)wqi, 0, CTL_CREATE, CTL_EOL);
 	if (error != 0)



CVS commit: src/sys/netinet

2018-07-31 Thread Robert Swindells
Module Name:src
Committed By:   rjs
Date:   Tue Jul 31 16:28:56 UTC 2018

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

Log Message:
Enable SCTP sysctl nodes.

Rename auto asconf one to match FreeBSD.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/netinet/sctp_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/sctp_usrreq.c
diff -u src/sys/netinet/sctp_usrreq.c:1.11 src/sys/netinet/sctp_usrreq.c:1.12
--- src/sys/netinet/sctp_usrreq.c:1.11	Tue Jul 31 13:36:31 2018
+++ src/sys/netinet/sctp_usrreq.c	Tue Jul 31 16:28:56 2018
@@ -1,5 +1,5 @@
 /*	$KAME: sctp_usrreq.c,v 1.50 2005/06/16 20:45:29 jinmei Exp $	*/
-/*	$NetBSD: sctp_usrreq.c,v 1.11 2018/07/31 13:36:31 rjs Exp $	*/
+/*	$NetBSD: sctp_usrreq.c,v 1.12 2018/07/31 16:28:56 rjs Exp $	*/
 
 /*
  * Copyright (c) 2001, 2002, 2003, 2004 Cisco Systems, Inc.
@@ -33,7 +33,7 @@
  * SUCH DAMAGE.
  */
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sctp_usrreq.c,v 1.11 2018/07/31 13:36:31 rjs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sctp_usrreq.c,v 1.12 2018/07/31 16:28:56 rjs Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -131,12 +131,16 @@ unsigned int sctp_assoc_rtx_max_default 
 unsigned int sctp_path_rtx_max_default = SCTP_DEF_MAX_SEND/2;
 unsigned int sctp_nr_outgoing_streams_default = SCTP_OSTREAM_INITIAL;
 
+static void sysctl_net_inet_sctp_setup(struct sysctllog **);
+
 void
 sctp_init(void)
 {
 	/* Init the SCTP pcb in sctp_pcb.c */
 	u_long sb_max_adj;
 
+	sysctl_net_inet_sctp_setup(NULL);
+
 	sctp_pcb_init();
 
 	if (nmbclusters > SCTP_ASOC_MAX_CHUNKS_ON_QUEUE)
@@ -3882,7 +3886,8 @@ sctp_purgeif(struct socket *so, struct i
 /*
  * Sysctl for sctp variables.
  */
-SYSCTL_SETUP(sysctl_net_inet_sctp_setup, "sysctl net.inet.sctp subtree setup")
+static void
+sysctl_net_inet_sctp_setup(struct sysctllog **clog)
 {
 
 	sysctl_createv(clog, 0, NULL, NULL,
@@ -3920,7 +3925,7 @@ SYSCTL_SETUP(sysctl_net_inet_sctp_setup,
 
sysctl_createv(clog, 0, NULL, NULL,
CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
-   CTLTYPE_INT, "autoasconf",
+   CTLTYPE_INT, "auto_asconf",
SYSCTL_DESCR("Enable SCTP Auto-ASCONF"),
NULL, 0, _auto_asconf, 0,
CTL_NET, PF_INET, IPPROTO_SCTP, SCTPCTL_AUTOASCONF,



CVS commit: src/sys/netinet

2018-07-31 Thread Robert Swindells
Module Name:src
Committed By:   rjs
Date:   Tue Jul 31 13:36:31 UTC 2018

Modified Files:
src/sys/netinet: sctp_uio.h sctp_usrreq.c

Log Message:
Change implementation of sctp_connectx() to use ioctl(2).


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/netinet/sctp_uio.h
cvs rdiff -u -r1.10 -r1.11 src/sys/netinet/sctp_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/sctp_uio.h
diff -u src/sys/netinet/sctp_uio.h:1.3 src/sys/netinet/sctp_uio.h:1.4
--- src/sys/netinet/sctp_uio.h:1.3	Sun Dec 10 11:52:14 2017
+++ src/sys/netinet/sctp_uio.h	Tue Jul 31 13:36:31 2018
@@ -1,5 +1,5 @@
 /*	$KAME: sctp_uio.h,v 1.11 2005/03/06 16:04:18 itojun Exp $	*/
-/*	$NetBSD: sctp_uio.h,v 1.3 2017/12/10 11:52:14 rjs Exp $ */
+/*	$NetBSD: sctp_uio.h,v 1.4 2018/07/31 13:36:31 rjs Exp $ */
 
 #ifndef __SCTP_UIO_H__
 #define __SCTP_UIO_H__
@@ -584,6 +584,14 @@ struct sctp_recvv_rn {
 #define SCTP_RECVV_NXTINFO	0x0002
 #define SCTP_RECVV_RN		0x0003
 
+struct sctp_connectx_addrs {
+	int cx_num;
+	int cx_len;
+	void *cx_addrs;
+} __packed;
+
+#define SIOCCONNECTX	_IOWR('s', 11, struct sctp_connectx_addrs)
+#define SIOCCONNECTXDEL	_IOWR('s', 12, struct sctp_connectx_addrs)
 
 /*
  * API system calls

Index: src/sys/netinet/sctp_usrreq.c
diff -u src/sys/netinet/sctp_usrreq.c:1.10 src/sys/netinet/sctp_usrreq.c:1.11
--- src/sys/netinet/sctp_usrreq.c:1.10	Tue May  1 07:21:39 2018
+++ src/sys/netinet/sctp_usrreq.c	Tue Jul 31 13:36:31 2018
@@ -1,5 +1,5 @@
 /*	$KAME: sctp_usrreq.c,v 1.50 2005/06/16 20:45:29 jinmei Exp $	*/
-/*	$NetBSD: sctp_usrreq.c,v 1.10 2018/05/01 07:21:39 maxv Exp $	*/
+/*	$NetBSD: sctp_usrreq.c,v 1.11 2018/07/31 13:36:31 rjs Exp $	*/
 
 /*
  * Copyright (c) 2001, 2002, 2003, 2004 Cisco Systems, Inc.
@@ -33,7 +33,7 @@
  * SUCH DAMAGE.
  */
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sctp_usrreq.c,v 1.10 2018/05/01 07:21:39 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sctp_usrreq.c,v 1.11 2018/07/31 13:36:31 rjs Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1134,19 +1134,27 @@ sctp_count_max_addresses(struct sctp_inp
 }
 
 static int
-sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, struct mbuf *m,
-		  struct lwp *l, int delay)
+sctp_do_connect_x(struct socket *so, struct sctp_connectx_addrs *sca,
+struct lwp *l, int delay)
 {
 int error = 0;
+	struct sctp_inpcb *inp;
 	struct sctp_tcb *stcb = NULL;
 	struct sockaddr *sa;
-	int num_v6=0, num_v4=0, *totaddrp, totaddr, i, incr, at;
+	int num_v6=0, num_v4=0, totaddr, i, incr, at;
+	char buf[2048];
+	size_t len;
+	sctp_assoc_t id;
 #ifdef SCTP_DEBUG
 	if (sctp_debug_on & SCTP_DEBUG_PCB1) {
 		printf("Connectx called\n");
 	}
 #endif /* SCTP_DEBUG */
 
+	inp = (struct sctp_inpcb *)so->so_pcb;
+	if (inp == 0)
+		return EINVAL;
+
 	if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
 	(inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
 		/* We are already connected AND the TCP model */
@@ -1168,9 +1176,16 @@ sctp_do_connect_x(struct socket *so, str
 		return (EFAULT);
 	}
 
-	totaddrp = mtod(m, int *);
-	totaddr = *totaddrp;
-	sa = (struct sockaddr *)(totaddrp + 1);
+	len = sca->cx_len;
+	totaddr = sca->cx_num;
+	if (len > sizeof(buf)) {
+		return E2BIG;
+	}
+	error = copyin(sca->cx_addrs, buf, len);
+	if (error) {
+		return error;
+	}
+	sa = (struct sockaddr *)buf;
 	at = incr = 0;
 	/* account and validate addresses */
 	SCTP_INP_WLOCK(inp);
@@ -1201,13 +1216,13 @@ sctp_do_connect_x(struct socket *so, str
 			SCTP_TCB_UNLOCK(stcb);
 			return (EALREADY);
 		}
-		if ((at + incr) > m->m_len) {
+		if ((at + incr) > len) {
 			totaddr = i;
 			break;
 		}
 		sa = (struct sockaddr *)((vaddr_t)sa + incr);
 	}
-	sa = (struct sockaddr *)(totaddrp + 1);
+	sa = (struct sockaddr *)buf;
 	SCTP_INP_WLOCK(inp);
 	SCTP_INP_DECR_REF(inp);
 	SCTP_INP_WUNLOCK(inp);
@@ -1252,6 +1267,7 @@ sctp_do_connect_x(struct socket *so, str
 		SCTP_ASOC_CREATE_UNLOCK(inp);
 		return (error);
 	}
+
 	/* move to second address */
 	if (sa->sa_family == AF_INET)
 		sa = (struct sockaddr *)((vaddr_t)sa + sizeof(struct sockaddr_in));
@@ -1280,6 +1296,10 @@ sctp_do_connect_x(struct socket *so, str
 		sa = (struct sockaddr *)((vaddr_t)sa + incr);
 	}
 	stcb->asoc.state = SCTP_STATE_COOKIE_WAIT;
+
+	id = sctp_get_associd(stcb);
+	memcpy(>cx_num, , sizeof(sctp_assoc_t));
+
 	if (delay) {
 		/* doing delayed connection */
 		stcb->asoc.delayed_connection = 1;
@@ -1922,7 +1942,7 @@ sctp_optsget(struct socket *so, struct s
 break;
 			}
 		}
-		if (	(stcb == NULL) &&
+		if ((stcb == NULL) &&
 			struct sockaddr *)>spp_address)->sa_family == AF_INET) ||
 			 (((struct sockaddr *)>spp_address)->sa_family == AF_INET6))) {
 			/* Lookup via address */
@@ -2099,6 +2119,7 @@ sctp_optsget(struct socket *so, struct s
 			stcb = sctp_findassociation_ep_asocid(inp, sstat->sstat_assoc_id);
 
 		if (stcb == NULL) {
+			printf("SCTP status, no 

CVS commit: src/sys/netinet

2018-07-11 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Wed Jul 11 12:48:42 UTC 2018

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

Log Message:
Add missing  include.


To generate a diff of this commit:
cvs rdiff -u -r1.161 -r1.162 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.161 src/sys/netinet/ip_mroute.c:1.162
--- src/sys/netinet/ip_mroute.c:1.161	Wed Jul 11 05:25:45 2018
+++ src/sys/netinet/ip_mroute.c	Wed Jul 11 12:48:42 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_mroute.c,v 1.161 2018/07/11 05:25:45 maxv Exp $	*/
+/*	$NetBSD: ip_mroute.c,v 1.162 2018/07/11 12:48:42 martin Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -93,7 +93,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip_mroute.c,v 1.161 2018/07/11 05:25:45 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_mroute.c,v 1.162 2018/07/11 12:48:42 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -124,6 +124,7 @@ __KERNEL_RCSID(0, "$NetBSD: ip_mroute.c,
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 



CVS commit: src/sys/netinet

2018-07-11 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Wed Jul 11 06:25:05 UTC 2018

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

Log Message:
Add KASSERTs in in_undefer_cksum_tcpudp.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/netinet/in_offload.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_offload.c
diff -u src/sys/netinet/in_offload.c:1.10 src/sys/netinet/in_offload.c:1.11
--- src/sys/netinet/in_offload.c:1.10	Wed Jul 11 06:00:34 2018
+++ src/sys/netinet/in_offload.c	Wed Jul 11 06:25:05 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: in_offload.c,v 1.10 2018/07/11 06:00:34 maxv Exp $	*/
+/*	$NetBSD: in_offload.c,v 1.11 2018/07/11 06:25:05 maxv Exp $	*/
 
 /*
  * Copyright (c)2005, 2006 YAMAMOTO Takashi,
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in_offload.c,v 1.10 2018/07/11 06:00:34 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in_offload.c,v 1.11 2018/07/11 06:25:05 maxv Exp $");
 
 #include 
 #include 
@@ -239,6 +239,10 @@ in_undefer_cksum_tcpudp(struct mbuf *m)
 	struct ip *ip;
 	uint16_t csum, offset;
 
+	KASSERT((m->m_flags & M_PKTHDR) != 0);
+	KASSERT((m->m_pkthdr.csum_flags & (M_CSUM_TCPv4|M_CSUM_UDPv4)) != 0);
+	KASSERT((m->m_pkthdr.csum_flags & (M_CSUM_TCPv6|M_CSUM_UDPv6)) == 0);
+
 	ip = mtod(m, struct ip *);
 	offset = ip->ip_hl << 2;
 



CVS commit: src/sys/netinet

2018-07-11 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Wed Jul 11 06:00:34 UTC 2018

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

Log Message:
Style, rename 'iph' -> 'ip', and reduce the diff between
in_undefer_cksum_tcpudp and the last part of in_undefer_cksum.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/netinet/in_offload.c
cvs rdiff -u -r1.10 -r1.11 src/sys/netinet/in_offload.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_offload.c
diff -u src/sys/netinet/in_offload.c:1.9 src/sys/netinet/in_offload.c:1.10
--- src/sys/netinet/in_offload.c:1.9	Wed Jul 11 05:38:55 2018
+++ src/sys/netinet/in_offload.c	Wed Jul 11 06:00:34 2018
@@ -1,6 +1,6 @@
-/*	$NetBSD: in_offload.c,v 1.9 2018/07/11 05:38:55 maxv Exp $	*/
+/*	$NetBSD: in_offload.c,v 1.10 2018/07/11 06:00:34 maxv Exp $	*/
 
-/*-
+/*
  * Copyright (c)2005, 2006 YAMAMOTO Takashi,
  * All rights reserved.
  *
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in_offload.c,v 1.9 2018/07/11 05:38:55 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in_offload.c,v 1.10 2018/07/11 06:00:34 maxv Exp $");
 
 #include 
 #include 
@@ -50,11 +50,9 @@ tcp4_segment(struct ifnet *ifp, struct m
 struct rtentry *rt)
 {
 	int mss;
-	int iphlen;
-	int thlen;
-	int hlen;
-	int len;
-	struct ip *iph;
+	int iphlen, thlen;
+	int hlen, len;
+	struct ip *ip;
 	struct tcphdr *th;
 	uint16_t ipid;
 	uint32_t tcpseq;
@@ -68,21 +66,21 @@ tcp4_segment(struct ifnet *ifp, struct m
 	m->m_pkthdr.csum_flags = 0;
 
 	len = m->m_pkthdr.len;
-	KASSERT(len >= sizeof(*iph) + sizeof(*th));
+	KASSERT(len >= sizeof(*ip) + sizeof(*th));
 
-	if (m->m_len < sizeof(*iph)) {
-		m = m_pullup(m, sizeof(*iph));
+	if (m->m_len < sizeof(*ip)) {
+		m = m_pullup(m, sizeof(*ip));
 		if (m == NULL) {
 			error = ENOMEM;
 			goto quit;
 		}
 	}
-	iph = mtod(m, struct ip *);
-	iphlen = iph->ip_hl * 4;
-	KASSERT(iph->ip_v == IPVERSION);
-	KASSERT(iphlen >= sizeof(*iph));
-	KASSERT(iph->ip_p == IPPROTO_TCP);
-	ipid = ntohs(iph->ip_id);
+	ip = mtod(m, struct ip *);
+	iphlen = ip->ip_hl * 4;
+	KASSERT(ip->ip_v == IPVERSION);
+	KASSERT(iphlen >= sizeof(*ip));
+	KASSERT(ip->ip_p == IPPROTO_TCP);
+	ipid = ntohs(ip->ip_id);
 
 	hlen = iphlen + sizeof(*th);
 	if (m->m_len < hlen) {
@@ -132,14 +130,14 @@ tcp4_segment(struct ifnet *ifp, struct m
 		KASSERT(n->m_len >= hlen); /* XXX */
 
 		n->m_pkthdr.len = hlen + mss;
-		iph = mtod(n, struct ip *);
-		KASSERT(iph->ip_v == IPVERSION);
-		iph->ip_len = htons(n->m_pkthdr.len);
-		iph->ip_id = htons(ipid);
+		ip = mtod(n, struct ip *);
+		KASSERT(ip->ip_v == IPVERSION);
+		ip->ip_len = htons(n->m_pkthdr.len);
+		ip->ip_id = htons(ipid);
 		th = (void *)(mtod(n, char *) + iphlen);
 		th->th_seq = htonl(tcpseq);
-		iph->ip_sum = 0;
-		iph->ip_sum = in_cksum(n, iphlen);
+		ip->ip_sum = 0;
+		ip->ip_sum = in_cksum(n, iphlen);
 		th->th_sum = 0;
 		th->th_sum = in4_cksum(n, IPPROTO_TCP, iphlen, thlen + mss);
 
@@ -224,7 +222,7 @@ in_undefer_cksum(struct mbuf *m, size_t 
 		if (__predict_true(l4offset + sizeof(uint16_t) <= m->m_len)) {
 			*(uint16_t *)(mtod(m, char *) + l4offset) = csum;
 		} else {
-			m_copyback(m, l4offset, sizeof(csum), (void *) );
+			m_copyback(m, l4offset, sizeof(csum), (void *));
 		}
 	}
 
@@ -239,20 +237,20 @@ void
 in_undefer_cksum_tcpudp(struct mbuf *m)
 {
 	struct ip *ip;
-	u_int16_t csum, offset;
+	uint16_t csum, offset;
 
 	ip = mtod(m, struct ip *);
 	offset = ip->ip_hl << 2;
+
 	csum = in4_cksum(m, 0, offset, ntohs(ip->ip_len) - offset);
 	if (csum == 0 && (m->m_pkthdr.csum_flags & M_CSUM_UDPv4) != 0)
 		csum = 0x;
 
 	offset += M_CSUM_DATA_IPv4_OFFSET(m->m_pkthdr.csum_data);
 
-	if ((offset + sizeof(u_int16_t)) > m->m_len) {
-		/* This happens when ip options were inserted */
-		m_copyback(m, offset, sizeof(csum), (void *));
+	if ((offset + sizeof(uint16_t)) <= m->m_len) {
+		*(uint16_t *)(mtod(m, char *) + offset) = csum;
 	} else {
-		*(u_int16_t *)(mtod(m, char *) + offset) = csum;
+		m_copyback(m, offset, sizeof(csum), (void *));
 	}
 }

Index: src/sys/netinet/in_offload.h
diff -u src/sys/netinet/in_offload.h:1.10 src/sys/netinet/in_offload.h:1.11
--- src/sys/netinet/in_offload.h:1.10	Wed Jul 11 05:38:55 2018
+++ src/sys/netinet/in_offload.h	Wed Jul 11 06:00:34 2018
@@ -1,6 +1,6 @@
-/*	$NetBSD: in_offload.h,v 1.10 2018/07/11 05:38:55 maxv Exp $	*/
+/*	$NetBSD: in_offload.h,v 1.11 2018/07/11 06:00:34 maxv Exp $	*/
 
-/*-
+/*
  * Copyright (c)2005, 2006 YAMAMOTO Takashi,
  * All rights reserved.
  *
@@ -30,21 +30,19 @@
 #define	_NETINET_IN_OFFLOAD_H_
 
 /*
- * subroutines to do software-only equivalent of h/w offloading.
+ * Subroutines to do software-only equivalent of h/w offloading.
  */
-
 int ip_tso_output(struct ifnet *, struct mbuf *, const struct sockaddr *,
 struct rtentry *);
 void in_undefer_cksum(struct mbuf *, size_t, int);
 void 

CVS commit: src/sys/netinet

2018-07-10 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Wed Jul 11 05:38:55 UTC 2018

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

Log Message:
Remove the callback, localify, and add a comment.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/netinet/in_offload.c
cvs rdiff -u -r1.9 -r1.10 src/sys/netinet/in_offload.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_offload.c
diff -u src/sys/netinet/in_offload.c:1.8 src/sys/netinet/in_offload.c:1.9
--- src/sys/netinet/in_offload.c:1.8	Wed Jul 11 05:25:45 2018
+++ src/sys/netinet/in_offload.c	Wed Jul 11 05:38:55 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: in_offload.c,v 1.8 2018/07/11 05:25:45 maxv Exp $	*/
+/*	$NetBSD: in_offload.c,v 1.9 2018/07/11 05:38:55 maxv Exp $	*/
 
 /*-
  * Copyright (c)2005, 2006 YAMAMOTO Takashi,
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in_offload.c,v 1.8 2018/07/11 05:25:45 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in_offload.c,v 1.9 2018/07/11 05:38:55 maxv Exp $");
 
 #include 
 #include 
@@ -41,46 +41,13 @@ __KERNEL_RCSID(0, "$NetBSD: in_offload.c
 #include 
 #include 
 
-struct ip_tso_output_args {
-	struct ifnet *ifp;
-	const struct sockaddr *sa;
-	struct rtentry *rt;
-};
-
-static int ip_tso_output_callback(void *, struct mbuf *);
-
-static int
-ip_tso_output_callback(void *vp, struct mbuf *m)
-{
-	struct ip_tso_output_args *args = vp;
-	struct ifnet *ifp = args->ifp;
-
-	return ip_if_output(ifp, m, args->sa, args->rt);
-}
-
-int
-ip_tso_output(struct ifnet *ifp, struct mbuf *m, const struct sockaddr *sa,
-struct rtentry *rt)
-{
-	struct ip_tso_output_args args;
-
-	args.ifp = ifp;
-	args.sa = sa;
-	args.rt = rt;
-
-	return tcp4_segment(m, ip_tso_output_callback, );
-}
-
 /*
- * tcp4_segment: handle M_CSUM_TSOv4 by software.
- *
- * => always consume m.
- * => call output_func with output_arg for each segments.
+ * Handle M_CSUM_TSOv4 in software. Split the TCP payload in chunks of
+ * size MSS, and send them.
  */
-
-int
-tcp4_segment(struct mbuf *m, int (*output_func)(void *, struct mbuf *),
-void *output_arg)
+static int
+tcp4_segment(struct ifnet *ifp, struct mbuf *m, const struct sockaddr *sa,
+struct rtentry *rt)
 {
 	int mss;
 	int iphlen;
@@ -176,7 +143,7 @@ tcp4_segment(struct mbuf *m, int (*outpu
 		th->th_sum = 0;
 		th->th_sum = in4_cksum(n, IPPROTO_TCP, iphlen, thlen + mss);
 
-		error = (*output_func)(output_arg, n);
+		error = ip_if_output(ifp, n, sa, rt);
 		if (error) {
 			goto quit;
 		}
@@ -197,6 +164,13 @@ quit:
 	return error;
 }
 
+int
+ip_tso_output(struct ifnet *ifp, struct mbuf *m, const struct sockaddr *sa,
+struct rtentry *rt)
+{
+	return tcp4_segment(ifp, m, sa, rt);
+}
+
 /*
  * Compute now in software the IP and TCP/UDP checksums. Cancel the
  * hardware offloading.

Index: src/sys/netinet/in_offload.h
diff -u src/sys/netinet/in_offload.h:1.9 src/sys/netinet/in_offload.h:1.10
--- src/sys/netinet/in_offload.h:1.9	Wed Jul 11 05:25:45 2018
+++ src/sys/netinet/in_offload.h	Wed Jul 11 05:38:55 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: in_offload.h,v 1.9 2018/07/11 05:25:45 maxv Exp $	*/
+/*	$NetBSD: in_offload.h,v 1.10 2018/07/11 05:38:55 maxv Exp $	*/
 
 /*-
  * Copyright (c)2005, 2006 YAMAMOTO Takashi,
@@ -33,11 +33,10 @@
  * subroutines to do software-only equivalent of h/w offloading.
  */
 
-int tcp4_segment(struct mbuf *, int (*)(void *, struct mbuf *), void *);
 int ip_tso_output(struct ifnet *, struct mbuf *, const struct sockaddr *,
 struct rtentry *);
 void in_undefer_cksum(struct mbuf *, size_t, int);
-void in_undefer_cksum_tcpudp(struct mbuf *m);
+void in_undefer_cksum_tcpudp(struct mbuf *);
 
 /*
  * offloading related sysctl variables.



CVS commit: src/sys/netinet

2018-06-02 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat Jun  2 11:56:57 UTC 2018

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

Log Message:
Copy more mbuf flags.


To generate a diff of this commit:
cvs rdiff -u -r1.305 -r1.306 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.305 src/sys/netinet/ip_output.c:1.306
--- src/sys/netinet/ip_output.c:1.305	Tue May 29 17:21:57 2018
+++ src/sys/netinet/ip_output.c	Sat Jun  2 11:56:57 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_output.c,v 1.305 2018/05/29 17:21:57 maxv Exp $	*/
+/*	$NetBSD: ip_output.c,v 1.306 2018/06/02 11:56:57 maxv Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.305 2018/05/29 17:21:57 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.306 2018/06/02 11:56:57 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -863,8 +863,8 @@ ip_fragment(struct mbuf *m, struct ifnet
 		mhip = mtod(m, struct ip *);
 		*mhip = *ip;
 
-		/* we must inherit MCAST and BCAST flags */
-		m->m_flags |= m0->m_flags & (M_MCAST|M_BCAST);
+		/* we must inherit the flags */
+		m->m_flags |= m0->m_flags & M_COPYFLAGS;
 
 		if (hlen > sizeof(struct ip)) {
 			mhlen = ip_optcopy(ip, mhip) + sizeof(struct ip);



CVS commit: src/sys/netinet

2018-05-31 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu May 31 13:51:57 UTC 2018

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

Log Message:
Remove the non-IKE part of the computation, too.


To generate a diff of this commit:
cvs rdiff -u -r1.253 -r1.254 src/sys/netinet/udp_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/udp_usrreq.c
diff -u src/sys/netinet/udp_usrreq.c:1.253 src/sys/netinet/udp_usrreq.c:1.254
--- src/sys/netinet/udp_usrreq.c:1.253	Thu May 31 07:03:57 2018
+++ src/sys/netinet/udp_usrreq.c	Thu May 31 13:51:56 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: udp_usrreq.c,v 1.253 2018/05/31 07:03:57 maxv Exp $	*/
+/*	$NetBSD: udp_usrreq.c,v 1.254 2018/05/31 13:51:56 maxv Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -66,7 +66,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c,v 1.253 2018/05/31 07:03:57 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c,v 1.254 2018/05/31 13:51:56 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1259,11 +1259,7 @@ udp4_espinudp(struct mbuf **mp, int off,
 	struct mbuf *m = *mp;
 	uint32_t *marker;
 
-	/*
-	 * Collapse the mbuf chain if the first mbuf is too short.
-	 * The longest case is: UDP + max(Non-ESP, Non-IKE) + ESP.
-	 */
-	minlen = off + 2 * sizeof(uint32_t) + sizeof(struct esp);
+	minlen = off + sizeof(struct esp);
 	if (minlen > m->m_pkthdr.len)
 		minlen = m->m_pkthdr.len;
 



CVS commit: src/sys/netinet

2018-05-29 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Tue May 29 17:21:57 UTC 2018

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

Log Message:
Fix an XXX of mine, be clearer about what we're doing. Basically we want to
preserve the fragment offset and flags. That's necessary if the packet
we're fragmenting is itself a fragment.


To generate a diff of this commit:
cvs rdiff -u -r1.304 -r1.305 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.304 src/sys/netinet/ip_output.c:1.305
--- src/sys/netinet/ip_output.c:1.304	Sun Apr 29 11:51:08 2018
+++ src/sys/netinet/ip_output.c	Tue May 29 17:21:57 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_output.c,v 1.304 2018/04/29 11:51:08 maxv Exp $	*/
+/*	$NetBSD: ip_output.c,v 1.305 2018/05/29 17:21:57 maxv Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.304 2018/04/29 11:51:08 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.305 2018/05/29 17:21:57 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -820,16 +820,14 @@ ip_fragment(struct mbuf *m, struct ifnet
 	int sw_csum = m->m_pkthdr.csum_flags;
 	int fragments = 0;
 	int error = 0;
-	int ipoff;
-	bool mff;
+	int ipoff, ipflg;
 
 	ip = mtod(m, struct ip *);
 	hlen = ip->ip_hl << 2;
 
-	/* XXX: Why don't we remove IP_RF? */
-	ipoff = ntohs(ip->ip_off) & ~IP_MF;
-
-	mff = (ip->ip_off & htons(IP_MF)) != 0;
+	/* Preserve the offset and flags. */
+	ipoff = ntohs(ip->ip_off) & IP_OFFMASK;
+	ipflg = ntohs(ip->ip_off) & (IP_RF|IP_DF|IP_MF);
 
 	if (ifp != NULL)
 		sw_csum &= ~ifp->if_csum_flags_tx;
@@ -875,8 +873,7 @@ ip_fragment(struct mbuf *m, struct ifnet
 		m->m_len = mhlen;
 
 		mhip->ip_off = ((off - hlen) >> 3) + ipoff;
-		if (mff)
-			mhip->ip_off |= IP_MF;
+		mhip->ip_off |= ipflg;
 		if (off + len >= ntohs(ip->ip_len))
 			len = ntohs(ip->ip_len) - off;
 		else



CVS commit: src/sys/netinet

2018-05-23 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Wed May 23 18:40:30 UTC 2018

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

Log Message:
Add XXX.


To generate a diff of this commit:
cvs rdiff -u -r1.279 -r1.280 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.279 src/sys/netinet/tcp_subr.c:1.280
--- src/sys/netinet/tcp_subr.c:1.279	Thu May  3 07:13:48 2018
+++ src/sys/netinet/tcp_subr.c	Wed May 23 18:40:29 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_subr.c,v 1.279 2018/05/03 07:13:48 maxv Exp $	*/
+/*	$NetBSD: tcp_subr.c,v 1.280 2018/05/23 18:40:29 maxv Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tcp_subr.c,v 1.279 2018/05/03 07:13:48 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_subr.c,v 1.280 2018/05/23 18:40:29 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1918,6 +1918,10 @@ tcp_mss_from_peer(struct tcpcb *tp, int 
 	if (tp->t_in6pcb)
 		mss -= ip6_optlen(tp->t_in6pcb);
 #endif
+	/*
+	 * XXX XXX What if mss goes negative or zero? This can happen if a
+	 * socket has large IPv6 options. We crash below.
+	 */
 
 	/*
 	 * If there's a pipesize, change the socket buffer to that size.



CVS commit: src/sys/netinet

2018-05-18 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri May 18 18:58:51 UTC 2018

Modified Files:
src/sys/netinet: dccp_usrreq.c ip_carp.c tcp_input.c tcp_sack.c
udp_usrreq.c

Log Message:
IP6_EXTHDR_GET -> M_REGION_GET, no functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/netinet/dccp_usrreq.c
cvs rdiff -u -r1.95 -r1.96 src/sys/netinet/ip_carp.c
cvs rdiff -u -r1.407 -r1.408 src/sys/netinet/tcp_input.c
cvs rdiff -u -r1.35 -r1.36 src/sys/netinet/tcp_sack.c
cvs rdiff -u -r1.251 -r1.252 src/sys/netinet/udp_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/dccp_usrreq.c
diff -u src/sys/netinet/dccp_usrreq.c:1.18 src/sys/netinet/dccp_usrreq.c:1.19
--- src/sys/netinet/dccp_usrreq.c:1.18	Thu May  3 07:01:08 2018
+++ src/sys/netinet/dccp_usrreq.c	Fri May 18 18:58:51 2018
@@ -1,5 +1,5 @@
 /*	$KAME: dccp_usrreq.c,v 1.67 2005/11/03 16:05:04 nishida Exp $	*/
-/*	$NetBSD: dccp_usrreq.c,v 1.18 2018/05/03 07:01:08 maxv Exp $ */
+/*	$NetBSD: dccp_usrreq.c,v 1.19 2018/05/18 18:58:51 maxv Exp $ */
 
 /*
  * Copyright (c) 2003 Joacim Häggmark, Magnus Erixzon, Nils-Erik Mattsson 
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: dccp_usrreq.c,v 1.18 2018/05/03 07:01:08 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dccp_usrreq.c,v 1.19 2018/05/18 18:58:51 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -230,7 +230,7 @@ dccp_input(struct mbuf *m, ...)
 	if (isipv6) {
 		DCCP_DEBUG((LOG_INFO, "Got DCCP ipv6 packet, iphlen = %u!\n", iphlen));
 		ip6 = mtod(m, struct ip6_hdr *);
-		IP6_EXTHDR_GET(dh, struct dccphdr *, m, iphlen, sizeof(*dh));
+		M_REGION_GET(dh, struct dccphdr *, m, iphlen, sizeof(*dh));
 		if (dh == NULL) {
 			dccpstat.dccps_badlen++;
 			return;
@@ -256,7 +256,7 @@ dccp_input(struct mbuf *m, ...)
 		 * Get IP and DCCP header together in first mbuf.
 		 */
 		ip = mtod(m, struct ip *);
-		IP6_EXTHDR_GET(dh, struct dccphdr *, m, iphlen, sizeof(*dh));
+		M_REGION_GET(dh, struct dccphdr *, m, iphlen, sizeof(*dh));
 		if (dh == NULL) {
 			dccpstat.dccps_badlen++;
 			return;

Index: src/sys/netinet/ip_carp.c
diff -u src/sys/netinet/ip_carp.c:1.95 src/sys/netinet/ip_carp.c:1.96
--- src/sys/netinet/ip_carp.c:1.95	Wed Mar 21 15:33:25 2018
+++ src/sys/netinet/ip_carp.c	Fri May 18 18:58:51 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_carp.c,v 1.95 2018/03/21 15:33:25 maxv Exp $	*/
+/*	$NetBSD: ip_carp.c,v 1.96 2018/05/18 18:58:51 maxv 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.95 2018/03/21 15:33:25 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_carp.c,v 1.96 2018/05/18 18:58:51 maxv Exp $");
 
 /*
  * TODO:
@@ -615,7 +615,7 @@ _carp6_proto_input(struct mbuf *m, int o
 
 	/* verify that we have a complete carp packet */
 	len = m->m_len;
-	IP6_EXTHDR_GET(ch, struct carp_header *, m, off, sizeof(*ch));
+	M_REGION_GET(ch, struct carp_header *, m, off, sizeof(*ch));
 	if (ch == NULL) {
 		CARP_STATINC(CARP_STAT_BADLEN);
 		CARP_LOG(sc, ("packet size %u too small", len));

Index: src/sys/netinet/tcp_input.c
diff -u src/sys/netinet/tcp_input.c:1.407 src/sys/netinet/tcp_input.c:1.408
--- src/sys/netinet/tcp_input.c:1.407	Thu May  3 07:13:48 2018
+++ src/sys/netinet/tcp_input.c	Fri May 18 18:58:51 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_input.c,v 1.407 2018/05/03 07:13:48 maxv Exp $	*/
+/*	$NetBSD: tcp_input.c,v 1.408 2018/05/18 18:58:51 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.407 2018/05/03 07:13:48 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.408 2018/05/18 18:58:51 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -200,7 +200,6 @@ __KERNEL_RCSID(0, "$NetBSD: tcp_input.c,
 #endif
 
 #ifndef INET6
-/* always need ip6.h for IP6_EXTHDR_GET */
 #include 
 #endif
 
@@ -1238,7 +1237,7 @@ tcp_input(struct mbuf *m, ...)
 	}
 #endif
 
-	IP6_EXTHDR_GET(th, struct tcphdr *, m, toff, sizeof(struct tcphdr));
+	M_REGION_GET(th, struct tcphdr *, m, toff, sizeof(struct tcphdr));
 	if (th == NULL) {
 		TCP_STATINC(TCP_STAT_RCVSHORT);
 		return;
@@ -1336,7 +1335,7 @@ tcp_input(struct mbuf *m, ...)
 	tlen -= off;
 
 	if (off > sizeof(struct tcphdr)) {
-		IP6_EXTHDR_GET(th, struct tcphdr *, m, toff, off);
+		M_REGION_GET(th, struct tcphdr *, m, toff, off);
 		if (th == NULL) {
 			TCP_STATINC(TCP_STAT_RCVSHORT);
 			return;

Index: src/sys/netinet/tcp_sack.c
diff -u src/sys/netinet/tcp_sack.c:1.35 src/sys/netinet/tcp_sack.c:1.36
--- src/sys/netinet/tcp_sack.c:1.35	Thu May  3 07:13:48 2018
+++ src/sys/netinet/tcp_sack.c	Fri May 18 18:58:51 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: tcp_sack.c,v 1.35 2018/05/03 07:13:48 maxv Exp $ */
+/* $NetBSD: tcp_sack.c,v 1.36 2018/05/18 18:58:51 maxv Exp $ */
 

CVS commit: src/sys/netinet

2018-05-18 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri May 18 18:28:40 UTC 2018

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

Log Message:
Remove IP6_EXTHDR_GET0, remove pointless XXXs, and style.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/netinet/ip6.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/ip6.h
diff -u src/sys/netinet/ip6.h:1.23 src/sys/netinet/ip6.h:1.24
--- src/sys/netinet/ip6.h:1.23	Tue Dec 25 18:33:46 2007
+++ src/sys/netinet/ip6.h	Fri May 18 18:28:40 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6.h,v 1.23 2007/12/25 18:33:46 perry Exp $	*/
+/*	$NetBSD: ip6.h,v 1.24 2018/05/18 18:28:40 maxv Exp $	*/
 /*	$KAME: ip6.h,v 1.45 2003/06/05 04:46:38 keiichi Exp $	*/
 
 /*
@@ -126,13 +126,12 @@ struct ip6_hdr_pseudo {
  * Extension Headers
  */
 
-struct	ip6_ext {
+struct ip6_ext {
 	u_int8_t ip6e_nxt;
 	u_int8_t ip6e_len;
 } __packed;
 
 /* Hop-by-Hop options header */
-/* XXX should we pad it to force alignment on an 8-byte boundary? */
 struct ip6_hbh {
 	u_int8_t ip6h_nxt;	/* next header */
 	u_int8_t ip6h_len;	/* length in units of 8 octets */
@@ -140,7 +139,6 @@ struct ip6_hbh {
 } __packed;
 
 /* Destination options header */
-/* XXX should we pad it to force alignment on an 8-byte boundary? */
 struct ip6_dest {
 	u_int8_t ip6d_nxt;	/* next header */
 	u_int8_t ip6d_len;	/* length in units of 8 octets */
@@ -159,7 +157,7 @@ struct ip6_dest {
 #define IP6OPT_RTALERT_LEN	4
 #define IP6OPT_RTALERT_MLD	0	/* Datagram contains an MLD message */
 #define IP6OPT_RTALERT_RSVP	1	/* Datagram contains an RSVP message */
-#define IP6OPT_RTALERT_ACTNET	2 	/* contains an Active Networks msg */
+#define IP6OPT_RTALERT_ACTNET	2	/* contains an Active Networks msg */
 #define IP6OPT_MINLEN		2
 
 #define IP6OPT_TYPE(o)		((o) & 0xC0)
@@ -222,10 +220,10 @@ struct ip6_opt_router {
 
 /* Routing header */
 struct ip6_rthdr {
-	u_int8_t  ip6r_nxt;	/* next header */
-	u_int8_t  ip6r_len;	/* length in units of 8 octets */
-	u_int8_t  ip6r_type;	/* routing type */
-	u_int8_t  ip6r_segleft;	/* segments left */
+	u_int8_t ip6r_nxt;	/* next header */
+	u_int8_t ip6r_len;	/* length in units of 8 octets */
+	u_int8_t ip6r_type;	/* routing type */
+	u_int8_t ip6r_segleft;	/* segments left */
 	/* followed by routing type specific data */
 } __packed;
 
@@ -273,10 +271,6 @@ struct ip6_frag {
  * "len") is located in single mbuf, on contiguous memory region.
  * The pointer to the region will be returned to pointer variable "val",
  * with type "typ".
- * IP6_EXTHDR_GET0 does the same, except that it aligns the structure at the
- * very top of mbuf.  GET0 is likely to make memory copy than GET.
- *
- * XXX we're now testing this, needs m_pulldown()
  */
 #define IP6_EXTHDR_GET(val, typ, m, off, len) \
 do {	\
@@ -296,24 +290,6 @@ do {	\
 		}			\
 	}\
 } while (/*CONSTCOND*/ 0)
-
-#define IP6_EXTHDR_GET0(val, typ, m, off, len) \
-do {	\
-	struct mbuf *_t;		\
-	if ((off) == 0 && (m)->m_len >= len)\
-		(val) = (typ)mtod((m), void *);			\
-	else {\
-		_t = m_pulldown((m), (off), (len), NULL);		\
-		if (_t) {		\
-			if (_t->m_len < (len))\
-panic("m_pulldown malfunction");	\
-			(val) = (typ)mtod(_t, void *);			\
-		} else {		\
-			(val) = (typ)NULL;\
-			(m) = NULL;	\
-		}			\
-	}\
-} while (/*CONSTCOND*/ 0)
 #endif /*_KERNEL*/
 
 #endif /* !_NETINET_IP6_H_ */



CVS commit: src/sys/netinet

2018-05-17 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu May 17 07:30:14 UTC 2018

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

Log Message:
Remove reference to tcpiphdr in comment.


To generate a diff of this commit:
cvs rdiff -u -r1.207 -r1.208 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.207 src/sys/netinet/tcp_output.c:1.208
--- src/sys/netinet/tcp_output.c:1.207	Mon May  7 23:42:13 2018
+++ src/sys/netinet/tcp_output.c	Thu May 17 07:30:13 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_output.c,v 1.207 2018/05/07 23:42:13 uwe Exp $	*/
+/*	$NetBSD: tcp_output.c,v 1.208 2018/05/17 07:30:13 maxv Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -135,7 +135,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tcp_output.c,v 1.207 2018/05/07 23:42:13 uwe Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_output.c,v 1.208 2018/05/17 07:30:13 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1073,12 +1073,12 @@ just_return:
 
 send:
 	/*
-	 * Before ESTABLISHED, force sending of initial options
-	 * unless TCP set not to do any options.
-	 * NOTE: we assume that the IP/TCP header plus TCP options
-	 * always fit in a single mbuf, leaving room for a maximum
-	 * link header, i.e.
-	 *	max_linkhdr + sizeof (struct tcpiphdr) + optlen <= MCLBYTES
+	 * Before ESTABLISHED, force sending of initial options unless TCP set
+	 * not to do any options.
+	 *
+	 * Note: we assume that the IP/TCP header plus TCP options always fit
+	 * in a single mbuf, leaving room for a maximum link header, i.e.:
+	 * max_linkhdr + IP_header + TCP_header + optlen <= MCLBYTES
 	 */
 	optlen = 0;
 	optp = opt;



CVS commit: src/sys/netinet

2018-05-14 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Mon May 14 17:26:16 UTC 2018

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

Log Message:
Don't crash if there is no inner IP header.


To generate a diff of this commit:
cvs rdiff -u -r1.158 -r1.159 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.158 src/sys/netinet/ip_mroute.c:1.159
--- src/sys/netinet/ip_mroute.c:1.158	Mon May  7 19:34:03 2018
+++ src/sys/netinet/ip_mroute.c	Mon May 14 17:26:16 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_mroute.c,v 1.158 2018/05/07 19:34:03 maxv Exp $	*/
+/*	$NetBSD: ip_mroute.c,v 1.159 2018/05/14 17:26:16 maxv Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -93,7 +93,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip_mroute.c,v 1.158 2018/05/07 19:34:03 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_mroute.c,v 1.159 2018/05/14 17:26:16 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1828,7 +1828,7 @@ vif_encapcheck(struct mbuf *m, int off, 
 	 */
 
 	/* Obtain the outer IP header and the vif pointer. */
-	m_copydata((struct mbuf *)m, 0, sizeof(ip), (void *));
+	m_copydata(m, 0, sizeof(ip), (void *));
 	vifp = (struct vif *)arg;
 
 	/*
@@ -1849,7 +1849,9 @@ vif_encapcheck(struct mbuf *m, int off, 
 		return 0;
 
 	/* Check that the inner destination is multicast. */
-	m_copydata((struct mbuf *)m, off, sizeof(ip), (void *));
+	if (off + sizeof(ip) > m->m_pkthdr.len)
+		return 0;
+	m_copydata(m, off, sizeof(ip), (void *));
 	if (!IN_MULTICAST(ip.ip_dst.s_addr))
 		return 0;
 



CVS commit: src/sys/netinet

2018-05-13 Thread Pierre Pronchery
Module Name:src
Committed By:   khorben
Date:   Sun May 13 22:42:52 UTC 2018

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

Log Message:
Fix spello in a comment


To generate a diff of this commit:
cvs rdiff -u -r1.230 -r1.231 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.230 src/sys/netinet/in.c:1.231
--- src/sys/netinet/in.c:1.230	Tue Apr 24 01:32:30 2018
+++ src/sys/netinet/in.c	Sun May 13 22:42:51 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: in.c,v 1.230 2018/04/24 01:32:30 knakahara Exp $	*/
+/*	$NetBSD: in.c,v 1.231 2018/05/13 22:42:51 khorben Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in.c,v 1.230 2018/04/24 01:32:30 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in.c,v 1.231 2018/05/13 22:42:51 khorben Exp $");
 
 #include "arp.h"
 
@@ -1145,7 +1145,7 @@ in_ifinit(struct ifnet *ifp, struct in_i
 
 	/*
 	 * Configure address flags.
-	 * We need to do this early because they maybe adjusted
+	 * We need to do this early because they may be adjusted
 	 * by if_addr_init depending on the address.
 	 */
 	if (ia->ia4_flags & IN_IFF_DUPLICATED) {



CVS commit: src/sys/netinet

2018-05-13 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sun May 13 18:39:06 UTC 2018

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

Log Message:
Clarify ESP-in-UDP.


To generate a diff of this commit:
cvs rdiff -u -r1.250 -r1.251 src/sys/netinet/udp_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/udp_usrreq.c
diff -u src/sys/netinet/udp_usrreq.c:1.250 src/sys/netinet/udp_usrreq.c:1.251
--- src/sys/netinet/udp_usrreq.c:1.250	Tue May  1 08:42:41 2018
+++ src/sys/netinet/udp_usrreq.c	Sun May 13 18:39:06 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: udp_usrreq.c,v 1.250 2018/05/01 08:42:41 maxv Exp $	*/
+/*	$NetBSD: udp_usrreq.c,v 1.251 2018/05/13 18:39:06 maxv Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -66,7 +66,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c,v 1.250 2018/05/01 08:42:41 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c,v 1.251 2018/05/13 18:39:06 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1239,6 +1239,14 @@ udp_statinc(u_int stat)
 
 #if defined(INET) && defined(IPSEC)
 /*
+ * Handle ESP-in-UDP packets (RFC3948).
+ *
+ * We need to distinguish between ESP packets and IKE packets. We do so by
+ * looking at the Non-ESP and Non-IKE markers.
+ *
+ * If IKE, we process the UDP packet as usual. Otherwise, ESP, we invoke
+ * IPsec.
+ *
  * Returns:
  * 1 if the packet was processed
  * 0 if normal UDP processing should take place
@@ -1248,7 +1256,7 @@ static int
 udp4_espinudp(struct mbuf **mp, int off, struct socket *so)
 {
 	size_t len;
-	void *data;
+	uint8_t *data;
 	struct inpcb *inp;
 	size_t skip = 0;
 	size_t minlen;
@@ -1260,10 +1268,10 @@ udp4_espinudp(struct mbuf **mp, int off,
 	struct mbuf *m = *mp;
 
 	/*
-	 * Collapse the mbuf chain if the first mbuf is too short
-	 * The longest case is: UDP + non ESP marker + ESP.
+	 * Collapse the mbuf chain if the first mbuf is too short.
+	 * The longest case is: UDP + max(Non-ESP, Non-IKE) + ESP.
 	 */
-	minlen = off + sizeof(u_int64_t) + sizeof(struct esp);
+	minlen = off + 2 * sizeof(uint32_t) + sizeof(struct esp);
 	if (minlen > m->m_pkthdr.len)
 		minlen = m->m_pkthdr.len;
 
@@ -1275,51 +1283,52 @@ udp4_espinudp(struct mbuf **mp, int off,
 	}
 
 	len = m->m_len - off;
-	data = mtod(m, char *) + off;
+	data = mtod(m, uint8_t *) + off;
 	inp = sotoinpcb(so);
 
-	/* Ignore keepalive packets */
-	if ((len == 1) && (*(unsigned char *)data == 0xff)) {
+	/* Ignore keepalive packets. */
+	if ((len == 1) && (*data == 0xff)) {
 		m_freem(m);
-		*mp = NULL; /* avoid any further processing by caller ... */
+		*mp = NULL; /* avoid any further processing by caller */
 		return 1;
 	}
 
-	/*
-	 * Check that the payload is long enough to hold
-	 * an ESP header and compute the length of encapsulation
-	 * header to remove
-	 */
+	/* Handle Non-ESP marker (32bit). If zero, then IKE. */
 	if (inp->inp_flags & INP_ESPINUDP) {
-		u_int32_t *st = (u_int32_t *)data;
+		uint32_t *marker = (uint32_t *)data;
 
-		if ((len <= sizeof(struct esp)) || (*st == 0))
-			return 0; /* Normal UDP processing */
+		if (len <= sizeof(uint32_t))
+			return 0;
+		if (marker[0] == 0)
+			return 0;
 
 		skip = sizeof(struct udphdr);
 	}
 
+	/* Handle Non-IKE marker (64bit). If non-zero, then IKE. */
 	if (inp->inp_flags & INP_ESPINUDP_NON_IKE) {
-		u_int32_t *st = (u_int32_t *)data;
+		uint32_t *marker = (uint32_t *)data;
 
-		if ((len <= sizeof(u_int64_t) + sizeof(struct esp)) ||
-		((st[0] | st[1]) != 0))
-			return 0; /* Normal UDP processing */
+		if (len <= 2 * sizeof(uint32_t) + sizeof(struct esp))
+			return 0;
+		if (marker[0] != 0 || marker[1] != 0)
+			return 0;
 
-		skip = sizeof(struct udphdr) + sizeof(u_int64_t);
+		skip = sizeof(struct udphdr) + 2 * sizeof(uint32_t);
 	}
 
 	/*
-	 * Get the UDP ports. They are handled in network
-	 * order everywhere in IPSEC_NAT_T code.
+	 * Get the UDP ports. They are handled in network order
+	 * everywhere in the IPSEC_NAT_T code.
 	 */
 	udphdr = (struct udphdr *)((char *)data - skip);
 	sport = udphdr->uh_sport;
 	dport = udphdr->uh_dport;
 
 	/*
-	 * Remove the UDP header (and possibly the non ESP marker)
-	 * IP header length is iphdrlen
+	 * Remove the UDP header, plus a possible marker. IP header
+	 * length is iphdrlen.
+	 *
 	 * Before:
 	 *   <--- off --->
 	 *   ++--+-+
@@ -1342,12 +1351,11 @@ udp4_espinudp(struct mbuf **mp, int off,
 
 	/*
 	 * We have modified the packet - it is now ESP, so we should not
-	 * return to UDP processing ...
+	 * return to UDP processing.
 	 *
-	 * Add a PACKET_TAG_IPSEC_NAT_T_PORT tag to remember
-	 * the source UDP port. This is required if we want
-	 * to select the right SPD for multiple hosts behind
-	 * same NAT
+	 * Add a PACKET_TAG_IPSEC_NAT_T_PORTS tag to remember the source
+	 * UDP port. This is required if we want to select the right SPD
+	 * for multiple hosts 

CVS commit: src/sys/netinet

2018-05-11 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri May 11 14:07:58 UTC 2018

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

Log Message:
Make sure we have at least an IP header, and remove pointless XXXs (there
is no issue).


To generate a diff of this commit:
cvs rdiff -u -r1.176 -r1.177 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.176 src/sys/netinet/raw_ip.c:1.177
--- src/sys/netinet/raw_ip.c:1.176	Sat Apr 28 13:26:57 2018
+++ src/sys/netinet/raw_ip.c	Fri May 11 14:07:58 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: raw_ip.c,v 1.176 2018/04/28 13:26:57 maxv Exp $	*/
+/*	$NetBSD: raw_ip.c,v 1.177 2018/05/11 14:07:58 maxv Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -65,7 +65,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: raw_ip.c,v 1.176 2018/04/28 13:26:57 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: raw_ip.c,v 1.177 2018/05/11 14:07:58 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -355,6 +355,10 @@ rip_output(struct mbuf *m, struct inpcb 
 			error = EMSGSIZE;
 			goto release;
 		}
+		if (m->m_pkthdr.len < sizeof(struct ip)) {
+			error = EINVAL;
+			goto release;
+		}
 		ip = mtod(m, struct ip *);
 
 		/*
@@ -367,7 +371,7 @@ rip_output(struct mbuf *m, struct inpcb 
 
 			m = m_copyup(m, hlen, (max_linkhdr + 3) & ~3);
 			if (m == NULL) {
-error = ENOMEM;	/* XXX */
+error = ENOMEM;
 goto release;
 			}
 			ip = mtod(m, struct ip *);
@@ -380,11 +384,14 @@ rip_output(struct mbuf *m, struct inpcb 
 		}
 		HTONS(ip->ip_len);
 		HTONS(ip->ip_off);
+
 		if (ip->ip_id != 0 || m->m_pkthdr.len < IP_MINFRAGSIZE)
 			flags |= IP_NOIPNEWID;
 		opts = NULL;
-		/* XXX prevent ip_output from overwriting header fields */
+
+		/* Prevent ip_output from overwriting header fields. */
 		flags |= IP_RAWOUTPUT;
+
 		IP_STATINC(IP_STAT_RAWOUT);
 	}
 



CVS commit: src/sys/netinet

2018-05-11 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri May 11 13:56:43 UTC 2018

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

Log Message:
static


To generate a diff of this commit:
cvs rdiff -u -r1.274 -r1.275 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.274 src/sys/netinet/if_arp.c:1.275
--- src/sys/netinet/if_arp.c:1.274	Tue May  1 07:21:39 2018
+++ src/sys/netinet/if_arp.c	Fri May 11 13:56:43 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_arp.c,v 1.274 2018/05/01 07:21:39 maxv Exp $	*/
+/*	$NetBSD: if_arp.c,v 1.275 2018/05/11 13:56:43 maxv Exp $	*/
 
 /*
  * Copyright (c) 1998, 2000, 2008 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.274 2018/05/01 07:21:39 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.275 2018/05/11 13:56:43 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -255,7 +255,7 @@ arp_fasttimo(void)
 	}
 }
 
-const struct protosw arpsw[] = {
+static const struct protosw arpsw[] = {
 	{
 		.pr_type = 0,
 		.pr_domain = ,



CVS commit: src/sys/netinet

2018-05-07 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Mon May  7 23:42:13 UTC 2018

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

Log Message:
Fix unsigned wraparound on window size calculations.

This is another instance where tp->rcv_adv - tp->rcv_nxt can wrap
around after successful zero-window probe from the peer.  The first
one was fixed by chs@ in revision 1.112 on 2004-05-08.

While here, CSE and de-obfuscate the code a bit.


To generate a diff of this commit:
cvs rdiff -u -r1.206 -r1.207 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.206 src/sys/netinet/tcp_output.c:1.207
--- src/sys/netinet/tcp_output.c:1.206	Thu May  3 07:13:48 2018
+++ src/sys/netinet/tcp_output.c	Mon May  7 23:42:13 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_output.c,v 1.206 2018/05/03 07:13:48 maxv Exp $	*/
+/*	$NetBSD: tcp_output.c,v 1.207 2018/05/07 23:42:13 uwe Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -135,7 +135,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tcp_output.c,v 1.206 2018/05/03 07:13:48 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_output.c,v 1.207 2018/05/07 23:42:13 uwe Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -987,16 +987,27 @@ again:
 		 * taking into account that we are limited by
 		 * TCP_MAXWIN << tp->rcv_scale.
 		 */
-		long adv = min(win, (long)TCP_MAXWIN << tp->rcv_scale) -
-			(tp->rcv_adv - tp->rcv_nxt);
+		long recwin = min(win, (long)TCP_MAXWIN << tp->rcv_scale);
+		long oldwin, adv;
 
 		/*
-		 * If the new window size ends up being the same as the old
-		 * size when it is scaled, then don't force a window update.
+		 * rcv_nxt may overtake rcv_adv when we accept a
+		 * zero-window probe.
 		 */
-		if ((tp->rcv_adv - tp->rcv_nxt) >> tp->rcv_scale ==
-		(adv + tp->rcv_adv - tp->rcv_nxt) >> tp->rcv_scale)
+		if (SEQ_GT(tp->rcv_adv, tp->rcv_nxt))
+			oldwin = tp->rcv_adv - tp->rcv_nxt;
+		else
+			oldwin = 0;
+
+		/*
+		 * If the new window size ends up being the same as or
+		 * less than the old size when it is scaled, then
+		 * don't force a window update.
+		 */
+		if (recwin >> tp->rcv_scale <= oldwin >> tp->rcv_scale)
 			goto dontupdate;
+
+		adv = recwin - oldwin;
 		if (adv >= (long) (2 * rxsegsize))
 			goto send;
 		if (2 * adv >= (long) so->so_rcv.sb_hiwat)



CVS commit: src/sys/netinet

2018-05-07 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Mon May  7 19:34:04 UTC 2018

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

Log Message:
Fix possible buffer overflow. We need to make sure the inner IPv4 packet
doesn't have options, because we validate only an option-less header.


To generate a diff of this commit:
cvs rdiff -u -r1.157 -r1.158 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.157 src/sys/netinet/ip_mroute.c:1.158
--- src/sys/netinet/ip_mroute.c:1.157	Wed Apr 11 06:26:00 2018
+++ src/sys/netinet/ip_mroute.c	Mon May  7 19:34:03 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_mroute.c,v 1.157 2018/04/11 06:26:00 maxv Exp $	*/
+/*	$NetBSD: ip_mroute.c,v 1.158 2018/05/07 19:34:03 maxv Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -93,7 +93,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip_mroute.c,v 1.157 2018/04/11 06:26:00 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_mroute.c,v 1.158 2018/05/07 19:34:03 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -3070,6 +3070,13 @@ pim_input(struct mbuf *m, ...)
 			return;
 		}
 
+		/* verify the inner packet doesn't have options */
+		if (encap_ip->ip_hl != (sizeof(struct ip) >> 2)) {
+			pimstat.pims_rcv_badregisters++;
+			m_freem(m);
+			return;
+		}
+
 		/* verify the inner packet is destined to a mcast group */
 		if (!IN_MULTICAST(encap_ip->ip_dst.s_addr)) {
 			pimstat.pims_rcv_badregisters++;



CVS commit: src/sys/netinet

2018-05-01 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Tue May  1 08:42:41 UTC 2018

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

Log Message:
Remove unused argument from udp4_espinudp, and remove unused includes.


To generate a diff of this commit:
cvs rdiff -u -r1.249 -r1.250 src/sys/netinet/udp_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/udp_usrreq.c
diff -u src/sys/netinet/udp_usrreq.c:1.249 src/sys/netinet/udp_usrreq.c:1.250
--- src/sys/netinet/udp_usrreq.c:1.249	Sat Apr 28 13:26:57 2018
+++ src/sys/netinet/udp_usrreq.c	Tue May  1 08:42:41 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: udp_usrreq.c,v 1.249 2018/04/28 13:26:57 maxv Exp $	*/
+/*	$NetBSD: udp_usrreq.c,v 1.250 2018/05/01 08:42:41 maxv Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -66,7 +66,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c,v 1.249 2018/04/28 13:26:57 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c,v 1.250 2018/05/01 08:42:41 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -103,7 +103,6 @@ __KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c
 
 #ifdef INET6
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -119,9 +118,6 @@ __KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c
 #ifdef IPSEC
 #include 
 #include 
-#ifdef INET6
-#include 
-#endif
 #endif
 
 #ifdef IPKDB
@@ -137,8 +133,7 @@ percpu_t *udpstat_percpu;
 
 #ifdef INET
 #ifdef IPSEC
-static int udp4_espinudp(struct mbuf **, int, struct sockaddr *,
-struct socket *);
+static int udp4_espinudp(struct mbuf **, int, struct socket *);
 #endif
 static void udp4_sendup(struct mbuf *, int, struct sockaddr *,
 struct socket *);
@@ -605,9 +600,7 @@ udp4_realinput(struct sockaddr_in *src, 
 #ifdef IPSEC
 		/* Handle ESP over UDP */
 		if (inp->inp_flags & INP_ESPINUDP_ALL) {
-			struct sockaddr *sa = (struct sockaddr *)src;
-
-			switch (udp4_espinudp(mp, off, sa, inp->inp_socket)) {
+			switch (udp4_espinudp(mp, off, inp->inp_socket)) {
 			case -1: /* Error, m was freed */
 rcvcnt = -1;
 goto bad;
@@ -1252,8 +1245,7 @@ udp_statinc(u_int stat)
  *-1 if an error occurred and m was freed
  */
 static int
-udp4_espinudp(struct mbuf **mp, int off, struct sockaddr *src,
-struct socket *so)
+udp4_espinudp(struct mbuf **mp, int off, struct socket *so)
 {
 	size_t len;
 	void *data;



CVS commit: src/sys/netinet

2018-05-01 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Tue May  1 07:03:33 UTC 2018

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

Log Message:
Redefine the structure, not to rely on tcpiphdr.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/netinet/tcp_debug.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_debug.h
diff -u src/sys/netinet/tcp_debug.h:1.17 src/sys/netinet/tcp_debug.h:1.18
--- src/sys/netinet/tcp_debug.h:1.17	Sun Mar  4 06:03:22 2007
+++ src/sys/netinet/tcp_debug.h	Tue May  1 07:03:33 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_debug.h,v 1.17 2007/03/04 06:03:22 christos Exp $	*/
+/*	$NetBSD: tcp_debug.h,v 1.18 2018/05/01 07:03:33 maxv Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1993
@@ -44,7 +44,10 @@ struct	tcp_debug {
 	short	td_ostate;
 	void *	td_tcb;
 	int	td_family;
-	struct	tcpiphdr td_ti;
+	struct {
+		struct ip ip4;
+		struct tcphdr th;
+	} __packed td_ti;
 	struct {
 #ifdef INET6
 		struct ip6_hdr ip6;



CVS commit: src/sys/netinet

2018-04-29 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sun Apr 29 12:12:42 UTC 2018

Modified Files:
src/sys/netinet: tcp_var.h tcpip.h

Log Message:
Move struct tcpiphdr from tcpip.h to tcp_var.h, to match UDP (udpiphdr in
udp_var.h).

tcpip.h is now empty, and can be removed.


To generate a diff of this commit:
cvs rdiff -u -r1.185 -r1.186 src/sys/netinet/tcp_var.h
cvs rdiff -u -r1.11 -r1.12 src/sys/netinet/tcpip.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_var.h
diff -u src/sys/netinet/tcp_var.h:1.185 src/sys/netinet/tcp_var.h:1.186
--- src/sys/netinet/tcp_var.h:1.185	Wed Mar 28 14:22:16 2018
+++ src/sys/netinet/tcp_var.h	Sun Apr 29 12:12:42 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_var.h,v 1.185 2018/03/28 14:22:16 maxv Exp $	*/
+/*	$NetBSD: tcp_var.h,v 1.186 2018/04/29 12:12:42 maxv Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -142,7 +142,7 @@
 #endif
 
 /*
- * Kernel variables for tcp.
+ * TCP kernel structures and variables.
  */
 
 #include 
@@ -163,6 +163,29 @@
 #endif /* TCP_SIGNATURE */
 
 /*
+ * Tcp+ip header, after ip options removed.
+ */
+struct tcpiphdr {
+	struct ipovly ti_i;		/* overlaid ip structure */
+	struct tcphdr ti_t;		/* tcp header */
+} __packed;
+#define	ti_x1		ti_i.ih_x1
+#define	ti_pr		ti_i.ih_pr
+#define	ti_len		ti_i.ih_len
+#define	ti_src		ti_i.ih_src
+#define	ti_dst		ti_i.ih_dst
+#define	ti_sport	ti_t.th_sport
+#define	ti_dport	ti_t.th_dport
+#define	ti_seq		ti_t.th_seq
+#define	ti_ack		ti_t.th_ack
+#define	ti_x2		ti_t.th_x2
+#define	ti_off		ti_t.th_off
+#define	ti_flags	ti_t.th_flags
+#define	ti_win		ti_t.th_win
+#define	ti_sum		ti_t.th_sum
+#define	ti_urp		ti_t.th_urp
+
+/*
  * SACK option block.
  */
 struct sackblk {

Index: src/sys/netinet/tcpip.h
diff -u src/sys/netinet/tcpip.h:1.11 src/sys/netinet/tcpip.h:1.12
--- src/sys/netinet/tcpip.h:1.11	Tue Dec 25 18:33:47 2007
+++ src/sys/netinet/tcpip.h	Sun Apr 29 12:12:42 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcpip.h,v 1.11 2007/12/25 18:33:47 perry Exp $	*/
+/*	$NetBSD: tcpip.h,v 1.12 2018/04/29 12:12:42 maxv Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1993
@@ -34,27 +34,5 @@
 #ifndef _NETINET_TCPIP_H_
 #define _NETINET_TCPIP_H_
 
-/*
- * Tcp+ip header, after ip options removed.
- */
-struct tcpiphdr {
-	struct 	ipovly ti_i;		/* overlaid ip structure */
-	struct	tcphdr ti_t;		/* tcp header */
-} __packed;
-#define	ti_x1		ti_i.ih_x1
-#define	ti_pr		ti_i.ih_pr
-#define	ti_len		ti_i.ih_len
-#define	ti_src		ti_i.ih_src
-#define	ti_dst		ti_i.ih_dst
-#define	ti_sport	ti_t.th_sport
-#define	ti_dport	ti_t.th_dport
-#define	ti_seq		ti_t.th_seq
-#define	ti_ack		ti_t.th_ack
-#define	ti_x2		ti_t.th_x2
-#define	ti_off		ti_t.th_off
-#define	ti_flags	ti_t.th_flags
-#define	ti_win		ti_t.th_win
-#define	ti_sum		ti_t.th_sum
-#define	ti_urp		ti_t.th_urp
 
 #endif /* !_NETINET_TCPIP_H_ */



CVS commit: src/sys/netinet

2018-04-23 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Tue Apr 24 01:32:30 UTC 2018

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

Log Message:
Fix sys/netinet/in.c:r1.229 problem. I have missed FALLTHROUGH, sorry.


To generate a diff of this commit:
cvs rdiff -u -r1.229 -r1.230 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.229 src/sys/netinet/in.c:1.230
--- src/sys/netinet/in.c:1.229	Fri Apr 20 09:56:22 2018
+++ src/sys/netinet/in.c	Tue Apr 24 01:32:30 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: in.c,v 1.229 2018/04/20 09:56:22 knakahara Exp $	*/
+/*	$NetBSD: in.c,v 1.230 2018/04/24 01:32:30 knakahara Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: in.c,v 1.229 2018/04/20 09:56:22 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in.c,v 1.230 2018/04/24 01:32:30 knakahara Exp $");
 
 #include "arp.h"
 
@@ -479,9 +479,14 @@ in_control0(struct socket *so, u_long cm
 		} else if (in_hosteq(ia->ia_addr.sin_addr,
 		   ifra->ifra_addr.sin_addr))
 			hostIsNew = 0;
+		if (ifra->ifra_addr.sin_family != AF_INET) {
+			error = EAFNOSUPPORT;
+			goto out;
+		}
 		/* FALLTHROUGH */
 	case SIOCSIFDSTADDR:
-		if (ifreq_getaddr(cmd, ifr)->sa_family != AF_INET) {
+		if (cmd == SIOCSIFDSTADDR &&
+		ifreq_getaddr(cmd, ifr)->sa_family != AF_INET) {
 			error = EAFNOSUPPORT;
 			goto out;
 		}



CVS commit: src/sys/netinet

2018-04-21 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat Apr 21 13:22:06 UTC 2018

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

Log Message:
Remove #ifndef __vax__.

The check enforces a 4-byte-aligned size for the option mbuf. If the size
is not multiple of 4, the computation of ip_hl gets truncated in the
output path. There is no reason for this check not to be present on VAX.

While here add a KASSERT in ip_insertoptions to enforce the assumption.

Discussed briefly on tech-net@


To generate a diff of this commit:
cvs rdiff -u -r1.302 -r1.303 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.302 src/sys/netinet/ip_output.c:1.303
--- src/sys/netinet/ip_output.c:1.302	Fri Apr 13 09:00:29 2018
+++ src/sys/netinet/ip_output.c	Sat Apr 21 13:22:06 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_output.c,v 1.302 2018/04/13 09:00:29 maxv Exp $	*/
+/*	$NetBSD: ip_output.c,v 1.303 2018/04/21 13:22:06 maxv Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.302 2018/04/13 09:00:29 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.303 2018/04/21 13:22:06 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1016,6 +1016,7 @@ ip_insertoptions(struct mbuf *m, struct 
 	unsigned optlen;
 
 	optlen = opt->m_len - sizeof(p->ipopt_dst);
+	KASSERT(optlen % 4 == 0);
 	if (optlen + ntohs(ip->ip_len) > IP_MAXPACKET)
 		return m;		/* XXX should fail */
 	if (!in_nullhost(p->ipopt_dst))
@@ -1577,10 +1578,10 @@ ip_pcbopts(struct inpcb *inp, const stru
 	}
 	cp = sopt->sopt_data;
 
-#ifndef	__vax__
-	if (cnt % sizeof(int32_t))
+	if (cnt % 4) {
+		/* Must be 4-byte aligned, because there's no padding. */
 		return EINVAL;
-#endif
+	}
 
 	m = m_get(M_DONTWAIT, MT_SOOPTS);
 	if (m == NULL)



CVS commit: src/sys/netinet

2018-04-19 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Apr 19 21:21:44 UTC 2018

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

Log Message:
s/static inline/static __inline/g for consistency.


To generate a diff of this commit:
cvs rdiff -u -r1.104 -r1.105 src/sys/netinet/in.h
cvs rdiff -u -r1.95 -r1.96 src/sys/netinet/in_var.h
cvs rdiff -u -r1.8 -r1.9 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/in.h
diff -u src/sys/netinet/in.h:1.104 src/sys/netinet/in.h:1.105
--- src/sys/netinet/in.h:1.104	Fri Feb  9 13:31:52 2018
+++ src/sys/netinet/in.h	Thu Apr 19 17:21:44 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: in.h,v 1.104 2018/02/09 18:31:52 maxv Exp $	*/
+/*	$NetBSD: in.h,v 1.105 2018/04/19 21:21:44 christos Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1990, 1993
@@ -601,7 +601,7 @@ int sockaddr_in_cmp(const struct sockadd
 const void *sockaddr_in_const_addr(const struct sockaddr *, socklen_t *);
 void *sockaddr_in_addr(struct sockaddr *, socklen_t *);
 
-static inline void
+static __inline void
 sockaddr_in_init1(struct sockaddr_in *sin, const struct in_addr *addr,
 in_port_t port)
 {
@@ -610,7 +610,7 @@ sockaddr_in_init1(struct sockaddr_in *si
 	memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
 }
 
-static inline void
+static __inline void
 sockaddr_in_init(struct sockaddr_in *sin, const struct in_addr *addr,
 in_port_t port)
 {
@@ -619,7 +619,7 @@ sockaddr_in_init(struct sockaddr_in *sin
 	sockaddr_in_init1(sin, addr, port);
 }
 
-static inline struct sockaddr *
+static __inline struct sockaddr *
 sockaddr_in_alloc(const struct in_addr *addr, in_port_t port, int flags)
 {
 	struct sockaddr *sa;

Index: src/sys/netinet/in_var.h
diff -u src/sys/netinet/in_var.h:1.95 src/sys/netinet/in_var.h:1.96
--- src/sys/netinet/in_var.h:1.95	Fri May 12 13:53:54 2017
+++ src/sys/netinet/in_var.h	Thu Apr 19 17:21:44 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: in_var.h,v 1.95 2017/05/12 17:53:54 ryo Exp $	*/
+/*	$NetBSD: in_var.h,v 1.96 2018/04/19 21:21:44 christos Exp $	*/
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -116,7 +116,7 @@ struct in_ifaddr {
 };
 
 #ifdef _KERNEL
-static inline void
+static __inline void
 ia4_acquire(struct in_ifaddr *ia, struct psref *psref)
 {
 
@@ -124,7 +124,7 @@ ia4_acquire(struct in_ifaddr *ia, struct
 	ifa_acquire(>ia_ifa, psref);
 }
 
-static inline void
+static __inline void
 ia4_release(struct in_ifaddr *ia, struct psref *psref)
 {
 
@@ -249,7 +249,7 @@ extern	const	int	inetctlerrmap[];
  * Find whether an internet address (in_addr) belongs to one
  * of our interfaces (in_ifaddr).  NULL if the address isn't ours.
  */
-static inline struct in_ifaddr *
+static __inline struct in_ifaddr *
 in_get_ia(struct in_addr addr)
 {
 	struct in_ifaddr *ia;
@@ -262,7 +262,7 @@ in_get_ia(struct in_addr addr)
 	return ia;
 }
 
-static inline struct in_ifaddr *
+static __inline struct in_ifaddr *
 in_get_ia_psref(struct in_addr addr, struct psref *psref)
 {
 	struct in_ifaddr *ia;
@@ -281,7 +281,7 @@ in_get_ia_psref(struct in_addr addr, str
  * Find whether an internet address (in_addr) belongs to a specified
  * interface.  NULL if the address isn't ours.
  */
-static inline struct in_ifaddr *
+static __inline struct in_ifaddr *
 in_get_ia_on_iface(struct in_addr addr, struct ifnet *ifp)
 {
 	struct in_ifaddr *ia;
@@ -295,7 +295,7 @@ in_get_ia_on_iface(struct in_addr addr, 
 	return ia;
 }
 
-static inline struct in_ifaddr *
+static __inline struct in_ifaddr *
 in_get_ia_on_iface_psref(struct in_addr addr, struct ifnet *ifp, struct psref *psref)
 {
 	struct in_ifaddr *ia;
@@ -314,7 +314,7 @@ in_get_ia_on_iface_psref(struct in_addr 
  * Find an internet address structure (in_ifaddr) corresponding
  * to a given interface (ifnet structure).
  */
-static inline struct in_ifaddr *
+static __inline struct in_ifaddr *
 in_get_ia_from_ifp(struct ifnet *ifp)
 {
 	struct ifaddr *ifa;
@@ -327,7 +327,7 @@ in_get_ia_from_ifp(struct ifnet *ifp)
 	return ifatoia(ifa);
 }
 
-static inline struct in_ifaddr *
+static __inline struct in_ifaddr *
 in_get_ia_from_ifp_psref(struct ifnet *ifp, struct psref *psref)
 {
 	struct in_ifaddr *ia;

Index: src/sys/netinet/tcp_vtw.h
diff -u src/sys/netinet/tcp_vtw.h:1.8 src/sys/netinet/tcp_vtw.h:1.9
--- src/sys/netinet/tcp_vtw.h:1.8	Tue Dec 13 03:29:03 2016
+++ src/sys/netinet/tcp_vtw.h	Thu Apr 19 17:21:44 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_vtw.h,v 1.8 2016/12/13 08:29:03 ozaki-r Exp $	*/
+/*	$NetBSD: tcp_vtw.h,v 1.9 2018/04/19 21:21:44 christos Exp $	*/
 /*
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -174,13 +174,13 @@ struct fatp_mi {
 	fatp_word_t	tag[FATP_NTAGS];	/* 15 tags per CL */
 };
 
-static inline int
+static __inline int
 fatp_ntags(void)
 {
 	return FATP_NTAGS;
 }
 
-static inline int
+static __inline int
 fatp_full(fatp_t *fp) 
 {
 	fatp_t full;
@@ -297,7 +297,7 

CVS commit: src/sys/netinet

2018-04-13 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Apr 13 09:29:04 UTC 2018

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

Log Message:
Improve the check, we want to have len >= udphdr all the time, and not
just when the packet size doesn't match the mbuf size.

Normally that's not a huge problem, since IP6_EXTHDR_GET gets called
earlier, so we can't have

(ip_len == iphlen + len) && (len < sizeof(struct udphdr))


To generate a diff of this commit:
cvs rdiff -u -r1.247 -r1.248 src/sys/netinet/udp_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/udp_usrreq.c
diff -u src/sys/netinet/udp_usrreq.c:1.247 src/sys/netinet/udp_usrreq.c:1.248
--- src/sys/netinet/udp_usrreq.c:1.247	Thu Apr 12 06:49:39 2018
+++ src/sys/netinet/udp_usrreq.c	Fri Apr 13 09:29:04 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: udp_usrreq.c,v 1.247 2018/04/12 06:49:39 maxv Exp $	*/
+/*	$NetBSD: udp_usrreq.c,v 1.248 2018/04/13 09:29:04 maxv Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -66,7 +66,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c,v 1.247 2018/04/12 06:49:39 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c,v 1.248 2018/04/13 09:29:04 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -374,8 +374,12 @@ udp_input(struct mbuf *m, ...)
 	 */
 	ip_len = ntohs(ip->ip_len);
 	len = ntohs((u_int16_t)uh->uh_ulen);
+	if (len < sizeof(struct udphdr)) {
+		UDP_STATINC(UDP_STAT_BADLEN);
+		goto bad;
+	}
 	if (ip_len != iphlen + len) {
-		if (ip_len < iphlen + len || len < sizeof(struct udphdr)) {
+		if (ip_len < iphlen + len) {
 			UDP_STATINC(UDP_STAT_BADLEN);
 			goto bad;
 		}



CVS commit: src/sys/netinet

2018-04-13 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Apr 13 09:00:29 UTC 2018

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

Log Message:
Remove useless comment and style.


To generate a diff of this commit:
cvs rdiff -u -r1.301 -r1.302 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.301 src/sys/netinet/ip_output.c:1.302
--- src/sys/netinet/ip_output.c:1.301	Fri Apr 13 08:47:46 2018
+++ src/sys/netinet/ip_output.c	Fri Apr 13 09:00:29 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_output.c,v 1.301 2018/04/13 08:47:46 maxv Exp $	*/
+/*	$NetBSD: ip_output.c,v 1.302 2018/04/13 09:00:29 maxv Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.301 2018/04/13 08:47:46 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.302 2018/04/13 09:00:29 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -980,13 +980,11 @@ in_delayed_cksum(struct mbuf *m)
 	offset += M_CSUM_DATA_IPv4_OFFSET(m->m_pkthdr.csum_data);
 
 	if ((offset + sizeof(u_int16_t)) > m->m_len) {
-		/* This happen when ip options were inserted
-		printf("in_delayed_cksum: pullup len %d off %d proto %d\n",
-		m->m_len, offset, ip->ip_p);
-		 */
-		m_copyback(m, offset, sizeof(csum), (void *) );
-	} else
+		/* This happens when ip options were inserted */
+		m_copyback(m, offset, sizeof(csum), (void *));
+	} else {
 		*(u_int16_t *)(mtod(m, char *) + offset) = csum;
+	}
 }
 
 /*



CVS commit: src/sys/netinet

2018-04-13 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Apr 13 08:47:46 UTC 2018

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

Log Message:
Reduce the diff between similar blocks.


To generate a diff of this commit:
cvs rdiff -u -r1.300 -r1.301 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.300 src/sys/netinet/ip_output.c:1.301
--- src/sys/netinet/ip_output.c:1.300	Fri Apr 13 08:12:51 2018
+++ src/sys/netinet/ip_output.c	Fri Apr 13 08:47:46 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_output.c,v 1.300 2018/04/13 08:12:51 maxv Exp $	*/
+/*	$NetBSD: ip_output.c,v 1.301 2018/04/13 08:47:46 maxv Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.300 2018/04/13 08:12:51 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.301 2018/04/13 08:47:46 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1822,12 +1822,13 @@ ip_add_membership(struct ip_moptions *im
 	bound = curlwp_bind();
 	if (sopt->sopt_size == sizeof(struct ip_mreq))
 		error = ip_get_membership(sopt, , , , true);
-	else
+	else {
 #ifdef INET6
 		error = ip6_get_membership(sopt, , , , sizeof(ia));
 #else
 		error = EINVAL;
 #endif
+	}
 
 	if (error)
 		goto out;
@@ -1902,7 +1903,6 @@ ip_drop_membership(struct ip_moptions *i
 		error = ip6_get_membership(sopt, , , , sizeof(ia));
 #else
 		error = EINVAL;
-		goto out;
 #endif
 	}
 



CVS commit: src/sys/netinet

2018-04-13 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Apr 13 08:12:51 UTC 2018

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

Log Message:
Reorder a few instructions to clarify. Replace two bcopy by memcpy.


To generate a diff of this commit:
cvs rdiff -u -r1.299 -r1.300 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.299 src/sys/netinet/ip_output.c:1.300
--- src/sys/netinet/ip_output.c:1.299	Fri Mar 30 22:54:37 2018
+++ src/sys/netinet/ip_output.c	Fri Apr 13 08:12:51 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_output.c,v 1.299 2018/03/30 22:54:37 maya Exp $	*/
+/*	$NetBSD: ip_output.c,v 1.300 2018/04/13 08:12:51 maxv Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.299 2018/03/30 22:54:37 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.300 2018/04/13 08:12:51 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1031,10 +1031,10 @@ ip_insertoptions(struct mbuf *m, struct 
 		m->m_len -= sizeof(struct ip);
 		m->m_data += sizeof(struct ip);
 		n->m_next = m;
+		n->m_len = optlen + sizeof(struct ip);
+		n->m_data += max_linkhdr;
+		memcpy(mtod(n, void *), ip, sizeof(struct ip));
 		m = n;
-		m->m_len = optlen + sizeof(struct ip);
-		m->m_data += max_linkhdr;
-		bcopy((void *)ip, mtod(m, void *), sizeof(struct ip));
 	} else {
 		m->m_data -= optlen;
 		m->m_len += optlen;
@@ -1042,7 +1042,7 @@ ip_insertoptions(struct mbuf *m, struct 
 	}
 	m->m_pkthdr.len += optlen;
 	ip = mtod(m, struct ip *);
-	bcopy((void *)p->ipopt_list, (void *)(ip + 1), (unsigned)optlen);
+	memcpy(ip + 1, p->ipopt_list, optlen);
 	*phlen = sizeof(struct ip) + optlen;
 	ip->ip_len = htons(ntohs(ip->ip_len) + optlen);
 	return m;



  1   2   3   4   5   6   7   >