Module Name:    src
Committed By:   christos
Date:           Thu Jul  6 17:08:57 UTC 2017

Modified Files:
        src/sys/kern: uipc_socket2.c
        src/sys/netinet: ip_input.c raw_ip.c udp_usrreq.c
        src/sys/netinet6: ip6_input.c udp6_usrreq.c
        src/sys/sys: socketvar.h

Log Message:
Merge the two copies SO_TIMESTAMP/SO_OTIMESTAMP processing to a single
function, and add a SOOPT_TIMESTAMP define reducing compat pollution from
5 places to 1.


To generate a diff of this commit:
cvs rdiff -u -r1.124 -r1.125 src/sys/kern/uipc_socket2.c
cvs rdiff -u -r1.355 -r1.356 src/sys/netinet/ip_input.c
cvs rdiff -u -r1.164 -r1.165 src/sys/netinet/raw_ip.c
cvs rdiff -u -r1.233 -r1.234 src/sys/netinet/udp_usrreq.c
cvs rdiff -u -r1.178 -r1.179 src/sys/netinet6/ip6_input.c
cvs rdiff -u -r1.129 -r1.130 src/sys/netinet6/udp6_usrreq.c
cvs rdiff -u -r1.144 -r1.145 src/sys/sys/socketvar.h

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

Modified files:

Index: src/sys/kern/uipc_socket2.c
diff -u src/sys/kern/uipc_socket2.c:1.124 src/sys/kern/uipc_socket2.c:1.125
--- src/sys/kern/uipc_socket2.c:1.124	Sun Oct  2 15:26:46 2016
+++ src/sys/kern/uipc_socket2.c	Thu Jul  6 13:08:57 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: uipc_socket2.c,v 1.124 2016/10/02 19:26:46 christos Exp $	*/
+/*	$NetBSD: uipc_socket2.c,v 1.125 2017/07/06 17:08:57 christos Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -58,11 +58,12 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_socket2.c,v 1.124 2016/10/02 19:26:46 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_socket2.c,v 1.125 2017/07/06 17:08:57 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_mbuftrace.h"
 #include "opt_sb_max.h"
+#include "opt_compat_netbsd.h"
 #endif
 
 #include <sys/param.h>
@@ -1527,3 +1528,35 @@ sowait(struct socket *so, bool catch_p, 
 		solockretry(so, lock);
 	return error;
 }
+
+#ifdef COMPAT_50
+#include <compat/sys/time.h>
+#include <compat/sys/socket.h>
+#endif
+
+struct mbuf **
+sbsavetimestamp(int opt, struct mbuf *m, struct mbuf **mp)
+{
+	struct timeval tv;
+	microtime(&tv);
+
+#ifdef SO_OTIMESTAMP
+	if (opt & SO_OTIMESTAMP) {
+		struct timeval50 tv50;
+
+		timeval_to_timeval50(&tv, &tv50);
+		*mp = sbcreatecontrol(&tv50, sizeof(tv50),
+		    SCM_OTIMESTAMP, SOL_SOCKET);
+		if (*mp)
+			mp = &(*mp)->m_next;
+	} else
+#endif
+
+	if (opt & SO_TIMESTAMP) {
+		*mp = sbcreatecontrol(&tv, sizeof(tv),
+		    SCM_TIMESTAMP, SOL_SOCKET);
+		if (*mp)
+			mp = &(*mp)->m_next;
+	}
+	return mp;
+}

Index: src/sys/netinet/ip_input.c
diff -u src/sys/netinet/ip_input.c:1.355 src/sys/netinet/ip_input.c:1.356
--- src/sys/netinet/ip_input.c:1.355	Wed May 31 22:45:14 2017
+++ src/sys/netinet/ip_input.c	Thu Jul  6 13:08:57 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_input.c,v 1.355 2017/06/01 02:45:14 chs Exp $	*/
+/*	$NetBSD: ip_input.c,v 1.356 2017/07/06 17:08:57 christos Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,11 +91,10 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.355 2017/06/01 02:45:14 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.356 2017/07/06 17:08:57 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
-#include "opt_compat_netbsd.h"
 #include "opt_gateway.h"
 #include "opt_ipsec.h"
 #include "opt_mrouting.h"
@@ -174,11 +173,6 @@ __KERNEL_RCSID(0, "$NetBSD: ip_input.c,v
 #define IPMTUDISCTIMEOUT (10 * 60)	/* as per RFC 1191 */
 #endif
 
-#ifdef COMPAT_50
-#include <compat/sys/time.h>
-#include <compat/sys/socket.h>
-#endif
-
 /*
  * Note: DIRECTED_BROADCAST is handled this way so that previous
  * configuration using this option will Just Work.
@@ -1529,27 +1523,9 @@ ip_savecontrol(struct inpcb *inp, struct
 	if (__predict_false(ifp == NULL))
 		return; /* XXX should report error? */
 
-	if (so->so_options & SO_TIMESTAMP
-#ifdef SO_OTIMESTAMP
-	    || so->so_options & SO_OTIMESTAMP
-#endif
-	    ) {
-		struct timeval tv;
-
-		microtime(&tv);
-#ifdef SO_OTIMESTAMP
-		if (so->so_options & SO_OTIMESTAMP) {
-			struct timeval50 tv50;
-			timeval_to_timeval50(&tv, &tv50);
-			*mp = sbcreatecontrol((void *) &tv50, sizeof(tv50),
-			    SCM_OTIMESTAMP, SOL_SOCKET);
-		} else
-#endif
-		*mp = sbcreatecontrol((void *) &tv, sizeof(tv),
-		    SCM_TIMESTAMP, SOL_SOCKET);
-		if (*mp)
-			mp = &(*mp)->m_next;
-	}
+	if (SOOPT_TIMESTAMP(so->so_options))
+		mp = sbsavetimestamp(so->so_options, m, mp);
+
 	if (inpflags & INP_RECVDSTADDR) {
 		*mp = sbcreatecontrol((void *) &ip->ip_dst,
 		    sizeof(struct in_addr), IP_RECVDSTADDR, IPPROTO_IP);

Index: src/sys/netinet/raw_ip.c
diff -u src/sys/netinet/raw_ip.c:1.164 src/sys/netinet/raw_ip.c:1.165
--- src/sys/netinet/raw_ip.c:1.164	Thu Apr 20 04:46:07 2017
+++ src/sys/netinet/raw_ip.c	Thu Jul  6 13:08:57 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: raw_ip.c,v 1.164 2017/04/20 08:46:07 ozaki-r Exp $	*/
+/*	$NetBSD: raw_ip.c,v 1.165 2017/07/06 17:08:57 christos Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -65,11 +65,10 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: raw_ip.c,v 1.164 2017/04/20 08:46:07 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: raw_ip.c,v 1.165 2017/07/06 17:08:57 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
-#include "opt_compat_netbsd.h"
 #include "opt_ipsec.h"
 #include "opt_mrouting.h"
 #include "opt_net_mpsafe.h"
@@ -105,10 +104,6 @@ __KERNEL_RCSID(0, "$NetBSD: raw_ip.c,v 1
 #include <netipsec/ipsec_private.h>
 #endif	/* IPSEC */
 
-#ifdef COMPAT_50
-#include <compat/sys/socket.h>
-#endif
-
 struct inpcbtable rawcbtable;
 
 int	 rip_pcbnotify(struct inpcbtable *, struct in_addr,
@@ -149,10 +144,7 @@ rip_sbappendaddr(struct inpcb *last, str
 	if (last->inp_flags & INP_NOHEADER)
 		m_adj(n, hlen);
 	if (last->inp_flags & INP_CONTROLOPTS 
-#ifdef SO_OTIMESTAMP
-	    || last->inp_socket->so_options & SO_OTIMESTAMP
-#endif
-	    || last->inp_socket->so_options & SO_TIMESTAMP)
+	    || SOOPT_TIMESTAMP(last->inp_socket->so_options))
 		ip_savecontrol(last, &opts, ip, n);
 	if (sbappendaddr(&last->inp_socket->so_rcv, sa, n, opts) == 0) {
 		/* should notify about lost packet */

Index: src/sys/netinet/udp_usrreq.c
diff -u src/sys/netinet/udp_usrreq.c:1.233 src/sys/netinet/udp_usrreq.c:1.234
--- src/sys/netinet/udp_usrreq.c:1.233	Thu Apr 20 04:46:07 2017
+++ src/sys/netinet/udp_usrreq.c	Thu Jul  6 13:08:57 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: udp_usrreq.c,v 1.233 2017/04/20 08:46:07 ozaki-r Exp $	*/
+/*	$NetBSD: udp_usrreq.c,v 1.234 2017/07/06 17:08:57 christos Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -66,11 +66,10 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c,v 1.233 2017/04/20 08:46:07 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c,v 1.234 2017/07/06 17:08:57 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
-#include "opt_compat_netbsd.h"
 #include "opt_ipsec.h"
 #include "opt_inet_csum.h"
 #include "opt_ipkdb.h"
@@ -127,10 +126,6 @@ __KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c
 #endif
 #endif	/* IPSEC */
 
-#ifdef COMPAT_50
-#include <compat/sys/socket.h>
-#endif
-
 #ifdef IPKDB
 #include <ipkdb/ipkdb.h>
 #endif
@@ -488,10 +483,7 @@ udp4_sendup(struct mbuf *m, int off /* o
 
 	if ((n = m_copypacket(m, M_DONTWAIT)) != NULL) {
 		if (inp->inp_flags & INP_CONTROLOPTS
-#ifdef SO_OTIMESTAMP
-			 || so->so_options & SO_OTIMESTAMP
-#endif
-			 || so->so_options & SO_TIMESTAMP) {
+		    || SOOPT_TIMESTAMP(so->so_options)) {
 			struct ip *ip = mtod(n, struct ip *);
 			ip_savecontrol(inp, &opts, ip, n);
 		}

Index: src/sys/netinet6/ip6_input.c
diff -u src/sys/netinet6/ip6_input.c:1.178 src/sys/netinet6/ip6_input.c:1.179
--- src/sys/netinet6/ip6_input.c:1.178	Wed May 31 22:45:14 2017
+++ src/sys/netinet6/ip6_input.c	Thu Jul  6 13:08:57 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6_input.c,v 1.178 2017/06/01 02:45:14 chs Exp $	*/
+/*	$NetBSD: ip6_input.c,v 1.179 2017/07/06 17:08:57 christos Exp $	*/
 /*	$KAME: ip6_input.c,v 1.188 2001/03/29 05:34:31 itojun Exp $	*/
 
 /*
@@ -62,14 +62,13 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.178 2017/06/01 02:45:14 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.179 2017/07/06 17:08:57 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_gateway.h"
 #include "opt_inet.h"
 #include "opt_inet6.h"
 #include "opt_ipsec.h"
-#include "opt_compat_netbsd.h"
 #include "opt_net_mpsafe.h"
 #endif
 
@@ -120,11 +119,6 @@ __KERNEL_RCSID(0, "$NetBSD: ip6_input.c,
 #include <netipsec/key.h>
 #endif /* IPSEC */
 
-#ifdef COMPAT_50
-#include <compat/sys/time.h>
-#include <compat/sys/socket.h>
-#endif
-
 #include <netinet6/ip6protosw.h>
 
 #include "faith.h"
@@ -1085,33 +1079,15 @@ void
 ip6_savecontrol(struct in6pcb *in6p, struct mbuf **mp, 
 	struct ip6_hdr *ip6, struct mbuf *m)
 {
+	struct socket *so = in6p->in6p_socket;
 #ifdef RFC2292
 #define IS2292(x, y)	((in6p->in6p_flags & IN6P_RFC2292) ? (x) : (y))
 #else
 #define IS2292(x, y)	(y)
 #endif
 
-	if (in6p->in6p_socket->so_options & SO_TIMESTAMP
-#ifdef SO_OTIMESTAMP
-	    || in6p->in6p_socket->so_options & SO_OTIMESTAMP
-#endif
-	) {
-		struct timeval tv;
-
-		microtime(&tv);
-#ifdef SO_OTIMESTAMP
-		if (in6p->in6p_socket->so_options & SO_OTIMESTAMP) {
-			struct timeval50 tv50;
-			timeval_to_timeval50(&tv, &tv50);
-			*mp = sbcreatecontrol((void *) &tv50, sizeof(tv50),
-			    SCM_OTIMESTAMP, SOL_SOCKET);
-		} else
-#endif
-		*mp = sbcreatecontrol((void *) &tv, sizeof(tv),
-		    SCM_TIMESTAMP, SOL_SOCKET);
-		if (*mp)
-			mp = &(*mp)->m_next;
-	}
+	if (SOOPT_TIMESTAMP(so->so_options))
+		mp = sbsavetimestamp(so->so_options, m, mp);
 
 	/* some OSes call this logic with IPv4 packet, for SO_TIMESTAMP */
 	if ((ip6->ip6_vfc & IPV6_VERSION_MASK) != IPV6_VERSION)

Index: src/sys/netinet6/udp6_usrreq.c
diff -u src/sys/netinet6/udp6_usrreq.c:1.129 src/sys/netinet6/udp6_usrreq.c:1.130
--- src/sys/netinet6/udp6_usrreq.c:1.129	Thu Apr 20 04:46:07 2017
+++ src/sys/netinet6/udp6_usrreq.c	Thu Jul  6 13:08:57 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: udp6_usrreq.c,v 1.129 2017/04/20 08:46:07 ozaki-r Exp $	*/
+/*	$NetBSD: udp6_usrreq.c,v 1.130 2017/07/06 17:08:57 christos Exp $	*/
 /*	$KAME: udp6_usrreq.c,v 1.86 2001/05/27 17:33:00 itojun Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: udp6_usrreq.c,v 1.129 2017/04/20 08:46:07 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: udp6_usrreq.c,v 1.130 2017/07/06 17:08:57 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -363,10 +363,7 @@ udp6_sendup(struct mbuf *m, int off /* o
 
 	if ((n = m_copypacket(m, M_DONTWAIT)) != NULL) {
 		if (in6p->in6p_flags & IN6P_CONTROLOPTS
-#ifdef SO_OTIMESTAMP
-		    || in6p->in6p_socket->so_options & SO_OTIMESTAMP
-#endif
-		    || in6p->in6p_socket->so_options & SO_TIMESTAMP) {
+		    || SOOPT_TIMESTAMP(in6p->in6p_socket->so_options)) {
 			struct ip6_hdr *ip6 = mtod(n, struct ip6_hdr *);
 			ip6_savecontrol(in6p, &opts, ip6, n);
 		}

Index: src/sys/sys/socketvar.h
diff -u src/sys/sys/socketvar.h:1.144 src/sys/sys/socketvar.h:1.145
--- src/sys/sys/socketvar.h:1.144	Fri Feb  3 11:06:45 2017
+++ src/sys/sys/socketvar.h	Thu Jul  6 13:08:57 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: socketvar.h,v 1.144 2017/02/03 16:06:45 christos Exp $	*/
+/*	$NetBSD: socketvar.h,v 1.145 2017/07/06 17:08:57 christos Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -251,6 +251,9 @@ struct sockaddr_big;
 
 struct	mbuf *getsombuf(struct socket *, int);
 
+/* 0x400 is SO_OTIMESTAMP */
+#define SOOPT_TIMESTAMP(o)	((o) & (SO_TIMESTAMP | 0x400))
+
 /*
  * File operations on sockets.
  */
@@ -277,6 +280,8 @@ struct mbuf *
 	sbcreatecontrol(void *, int, int, int);
 struct mbuf *
 	sbcreatecontrol1(void **, int, int, int, int);
+struct mbuf **
+	sbsavetimestamp(int, struct mbuf *, struct mbuf **);
 void	sbdrop(struct sockbuf *, int);
 void	sbdroprecord(struct sockbuf *);
 void	sbflush(struct sockbuf *);

Reply via email to