Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Merge the two copies SO_TIMESTAMP/SO_OTIMESTAMP processi...



details:   https://anonhg.NetBSD.org/src/rev/d6398259be3c
branches:  trunk
changeset: 825272:d6398259be3c
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Jul 06 17:08:57 2017 +0000

description:
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.

diffstat:

 sys/kern/uipc_socket2.c    |  37 +++++++++++++++++++++++++++++++++++--
 sys/netinet/ip_input.c     |  32 ++++----------------------------
 sys/netinet/raw_ip.c       |  14 +++-----------
 sys/netinet/udp_usrreq.c   |  14 +++-----------
 sys/netinet6/ip6_input.c   |  34 +++++-----------------------------
 sys/netinet6/udp6_usrreq.c |   9 +++------
 sys/sys/socketvar.h        |   7 ++++++-
 7 files changed, 59 insertions(+), 88 deletions(-)

diffs (truncated from 345 to 300 lines):

diff -r 18ead0b458e5 -r d6398259be3c sys/kern/uipc_socket2.c
--- a/sys/kern/uipc_socket2.c   Thu Jul 06 15:17:47 2017 +0000
+++ b/sys/kern/uipc_socket2.c   Thu Jul 06 17:08:57 2017 +0000
@@ -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 @@
                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;
+}
diff -r 18ead0b458e5 -r d6398259be3c sys/netinet/ip_input.c
--- a/sys/netinet/ip_input.c    Thu Jul 06 15:17:47 2017 +0000
+++ b/sys/netinet/ip_input.c    Thu Jul 06 17:08:57 2017 +0000
@@ -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 @@
 #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 @@
        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;
+       if (SOOPT_TIMESTAMP(so->so_options))
+               mp = sbsavetimestamp(so->so_options, m, mp);
 
-               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 (inpflags & INP_RECVDSTADDR) {
                *mp = sbcreatecontrol((void *) &ip->ip_dst,
                    sizeof(struct in_addr), IP_RECVDSTADDR, IPPROTO_IP);
diff -r 18ead0b458e5 -r d6398259be3c sys/netinet/raw_ip.c
--- a/sys/netinet/raw_ip.c      Thu Jul 06 15:17:47 2017 +0000
+++ b/sys/netinet/raw_ip.c      Thu Jul 06 17:08:57 2017 +0000
@@ -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 @@
 #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 @@
        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 */
diff -r 18ead0b458e5 -r d6398259be3c sys/netinet/udp_usrreq.c
--- a/sys/netinet/udp_usrreq.c  Thu Jul 06 15:17:47 2017 +0000
+++ b/sys/netinet/udp_usrreq.c  Thu Jul 06 17:08:57 2017 +0000
@@ -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 @@
 #endif
 #endif /* IPSEC */
 
-#ifdef COMPAT_50
-#include <compat/sys/socket.h>
-#endif
-
 #ifdef IPKDB
 #include <ipkdb/ipkdb.h>
 #endif
@@ -488,10 +483,7 @@
 
        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);
                }
diff -r 18ead0b458e5 -r d6398259be3c sys/netinet6/ip6_input.c
--- a/sys/netinet6/ip6_input.c  Thu Jul 06 15:17:47 2017 +0000
+++ b/sys/netinet6/ip6_input.c  Thu Jul 06 17:08:57 2017 +0000
@@ -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 @@
 #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 @@
 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)
diff -r 18ead0b458e5 -r d6398259be3c sys/netinet6/udp6_usrreq.c
--- a/sys/netinet6/udp6_usrreq.c        Thu Jul 06 15:17:47 2017 +0000
+++ b/sys/netinet6/udp6_usrreq.c        Thu Jul 06 17:08:57 2017 +0000
@@ -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>



Home | Main Index | Thread Index | Old Index