tech-net archive

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

SO_TIMESTAMPNS option



Hi there!

I've made some changes to source tree doing my GSoC work on timestamps.

This patch introduces SO_TIMESTAMPNS socket option similiar to SO_TIMESTAMP.

This information is accessible in cmsg (Timestamp is contained in struct 
timespec.)

SO_OTIMESTAMPNS option is made as a compatibility with older userland
since tv_sec is 64 bit in -current but 32 bit in 5.1

In case of SO_OTIMESTAMPNS struct timespec50 will be return

Could you please take a look at the code and express your ideas about it?


Index: sys/kern/uipc_socket.c
===================================================================
RCS file: /cvsroot/src/sys/kern/uipc_socket.c,v
retrieving revision 1.203
diff -u -b -B -w -p -r1.203 uipc_socket.c
--- sys/kern/uipc_socket.c      1 Feb 2011 01:39:20 -0000       1.203
+++ sys/kern/uipc_socket.c      31 May 2011 20:51:35 -0000
@@ -1732,6 +1732,10 @@ sosetopt1(struct socket *so, const struc
        case SO_REUSEPORT:
        case SO_OOBINLINE:
        case SO_TIMESTAMP:
+       case SO_TIMESTAMPNS:
+       case SO_OTIMESTAMPNS:
+
+
 #ifdef SO_OTIMESTAMP
        case SO_OTIMESTAMP:
 #endif
@@ -1932,6 +1936,10 @@ sogetopt1(struct socket *so, struct sock
        case SO_BROADCAST:
        case SO_OOBINLINE:
        case SO_TIMESTAMP:
+       case SO_TIMESTAMPNS:
+       case SO_OTIMESTAMPNS:
+
+
 #ifdef SO_OTIMESTAMP
        case SO_OTIMESTAMP:
 #endif
Index: sys/netinet/ip_input.c
===================================================================
RCS file: /cvsroot/src/sys/netinet/ip_input.c,v
retrieving revision 1.295
diff -u -b -B -w -p -r1.295 ip_input.c
--- sys/netinet/ip_input.c      3 May 2011 17:44:31 -0000       1.295
+++ sys/netinet/ip_input.c      31 May 2011 20:51:36 -0000
@@ -1529,6 +1529,28 @@ void
 ip_savecontrol(struct inpcb *inp, struct mbuf **mp, struct ip *ip,
     struct mbuf *m)
 {
+       if (inp->inp_socket->so_options & SO_TIMESTAMPNS ||
+               inp->inp_socket->so_options & SO_OTIMESTAMPNS) {
+
+               struct timespec ts;
+               
+               nanotime(&ts);
+               
+               if (inp->inp_socket->so_options & SO_OTIMESTAMPNS) {
+
+                       struct timespec50 ts50;
+                       timespec_to_timespec50(&ts, &ts50);
+                       
+                       *mp = sbcreatecontrol((void *) &ts50, sizeof(ts50),
+                                                                 
SCM_TIMESTAMPNS, SOL_SOCKET);
+               }
+               else 
+                       *mp = sbcreatecontrol((void *) &ts, sizeof(ts),
+                                                                 
SCM_TIMESTAMPNS, SOL_SOCKET);
+               
+               if (*mp)
+                       mp = &(*mp)->m_next;
+       }
 
        if (inp->inp_socket->so_options & SO_TIMESTAMP
 #ifdef SO_OTIMESTAMP
Index: sys/netinet/raw_ip.c
===================================================================
RCS file: /cvsroot/src/sys/netinet/raw_ip.c,v
retrieving revision 1.111
diff -u -b -B -w -p -r1.111 raw_ip.c
--- sys/netinet/raw_ip.c        9 Dec 2009 00:45:25 -0000       1.111
+++ sys/netinet/raw_ip.c        31 May 2011 20:51:36 -0000
@@ -152,7 +152,9 @@ rip_sbappendaddr(struct inpcb *last, str
 #ifdef SO_OTIMESTAMP
            || last->inp_socket->so_options & SO_OTIMESTAMP
 #endif
-           || last->inp_socket->so_options & SO_TIMESTAMP)
+           || last->inp_socket->so_options & SO_TIMESTAMP
+               || last->inp_socket->so_options & SO_TIMESTAMPNS
+               || last->inp_socket->so_options & SO_OTIMESTAMPNS)
                ip_savecontrol(last, &opts, ip, n);
        if (sbappendaddr(&last->inp_socket->so_rcv, sa, n, opts) == 0) {
                /* should notify about lost packet */
Index: sys/netinet/udp_usrreq.c
===================================================================
RCS file: /cvsroot/src/sys/netinet/udp_usrreq.c,v
retrieving revision 1.180
diff -u -b -B -w -p -r1.180 udp_usrreq.c
--- sys/netinet/udp_usrreq.c    3 May 2011 18:28:45 -0000       1.180
+++ sys/netinet/udp_usrreq.c    31 May 2011 20:51:37 -0000
@@ -651,7 +651,10 @@ udp4_sendup(struct mbuf *m, int off /* o
 #ifdef SO_OTIMESTAMP
                         || so->so_options & SO_OTIMESTAMP
 #endif
-                        || so->so_options & SO_TIMESTAMP)) {
+                        || so->so_options & SO_TIMESTAMP
+                        || so->so_options & SO_TIMESTAMPNS 
+                        || so->so_options & SO_OTIMESTAMPNS 
+                        )) {
                        struct ip *ip = mtod(n, struct ip *);
                        ip_savecontrol(inp, &opts, ip, n);
                }
Index: sys/sys/socket.h
===================================================================
RCS file: /cvsroot/src/sys/sys/socket.h,v
retrieving revision 1.99
diff -u -b -B -w -p -r1.99 socket.h
--- sys/sys/socket.h    1 Feb 2011 01:39:21 -0000       1.99
+++ sys/sys/socket.h    31 May 2011 20:51:38 -0000
@@ -123,6 +123,10 @@ typedef    _BSD_SSIZE_T_   ssize_t;
 /*     SO_OTIMESTAMP   0x0400          */
 #define        SO_ACCEPTFILTER 0x1000          /* there is an accept filter */
 #define        SO_TIMESTAMP    0x2000          /* timestamp received dgram 
traffic */
+#define        SO_TIMESTAMPNS  0x4000          /* timestamp received dgram 
traffic (nanoseconds) */
+#define        SO_OTIMESTAMPNS 0x8000          /* timestamp received dgram 
traffic (nanoseconds) 32 bit */
+
+
 
 
 /*
@@ -554,6 +558,7 @@ struct cmsghdr {
 /*                     0x02               timestamp (struct timeval50) */
 #define        SCM_CREDS       0x04            /* credentials (struct 
sockcred) */
 #define        SCM_TIMESTAMP   0x08            /* timestamp (struct timeval) */
+#define        SCM_TIMESTAMPNS 0x10            /* timestampns (struct 
timespec) */
 #endif
 
 /*



-- 
With best regards,
Dmitry


Home | Main Index | Thread Index | Old Index