summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorChris Kuethe <ckuethe@cvs.openbsd.org>2008-05-02 06:49:33 +0000
committerChris Kuethe <ckuethe@cvs.openbsd.org>2008-05-02 06:49:33 +0000
commitac62022e3319b58cd03e552240772872ff219a70 (patch)
tree11d64a9c749b3f2f1d31c20967ddf7faef658b0f /sys
parent7f740532bb7e0e07efa3aea9fae9139a1f135642 (diff)
Make the SO_TIMESTAMP sockopt work. When set, this allows the user to
get a timestamp of when the datagram was accepted (by udp(4), for example) rather than having to take a timestamp with gettimeofday(2) when recv(2) returns - possibly several hundreds of microseconds later. May be of use to those interested in precision network timing schemes or QoS for media applications. Tested on alpha, amd64, i386 and sparc64. manpage suggestions from jmc, ok deraadt
Diffstat (limited to 'sys')
-rw-r--r--sys/kern/uipc_socket.c4
-rw-r--r--sys/netinet/raw_ip.c8
-rw-r--r--sys/netinet/udp_usrreq.c22
-rw-r--r--sys/sys/socket.h4
4 files changed, 26 insertions, 12 deletions
diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c
index c79d828130f..45728e18533 100644
--- a/sys/kern/uipc_socket.c
+++ b/sys/kern/uipc_socket.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uipc_socket.c,v 1.67 2007/12/20 17:16:50 chl Exp $ */
+/* $OpenBSD: uipc_socket.c,v 1.68 2008/05/02 06:49:32 ckuethe Exp $ */
/* $NetBSD: uipc_socket.c,v 1.21 1996/02/04 02:17:52 christos Exp $ */
/*
@@ -1001,6 +1001,7 @@ sosetopt(struct socket *so, int level, int optname, struct mbuf *m0)
case SO_REUSEPORT:
case SO_OOBINLINE:
case SO_JUMBO:
+ case SO_TIMESTAMP:
if (m == NULL || m->m_len < sizeof (int)) {
error = EINVAL;
goto bad;
@@ -1135,6 +1136,7 @@ sogetopt(struct socket *so, int level, int optname, struct mbuf **mp)
case SO_BROADCAST:
case SO_OOBINLINE:
case SO_JUMBO:
+ case SO_TIMESTAMP:
*mtod(m, int *) = so->so_options & optname;
break;
diff --git a/sys/netinet/raw_ip.c b/sys/netinet/raw_ip.c
index c06aa1bc0ea..a92c9870bf3 100644
--- a/sys/netinet/raw_ip.c
+++ b/sys/netinet/raw_ip.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: raw_ip.c,v 1.40 2006/11/25 18:04:44 claudio Exp $ */
+/* $OpenBSD: raw_ip.c,v 1.41 2008/05/02 06:49:32 ckuethe Exp $ */
/* $NetBSD: raw_ip.c,v 1.25 1996/02/18 18:58:33 christos Exp $ */
/*
@@ -141,7 +141,8 @@ rip_input(struct mbuf *m, ...)
struct mbuf *n;
if ((n = m_copy(m, 0, (int)M_COPYALL)) != NULL) {
- if (last->inp_flags & INP_CONTROLOPTS)
+ if (last->inp_flags & INP_CONTROLOPTS ||
+ last->inp_socket->so_options & SO_TIMESTAMP)
ip_savecontrol(last, &opts, ip, n);
if (sbappendaddr(&last->inp_socket->so_rcv,
sintosa(&ripsrc), n, opts) == 0) {
@@ -157,7 +158,8 @@ rip_input(struct mbuf *m, ...)
last = inp;
}
if (last) {
- if (last->inp_flags & INP_CONTROLOPTS)
+ if (last->inp_flags & INP_CONTROLOPTS ||
+ last->inp_socket->so_options & SO_TIMESTAMP)
ip_savecontrol(last, &opts, ip, m);
if (sbappendaddr(&last->inp_socket->so_rcv, sintosa(&ripsrc), m,
opts) == 0) {
diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c
index 7f4370c04b1..2244f620efb 100644
--- a/sys/netinet/udp_usrreq.c
+++ b/sys/netinet/udp_usrreq.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: udp_usrreq.c,v 1.115 2007/12/13 20:00:53 reyk Exp $ */
+/* $OpenBSD: udp_usrreq.c,v 1.116 2008/05/02 06:49:32 ckuethe Exp $ */
/* $NetBSD: udp_usrreq.c,v 1.28 1996/03/16 23:54:03 christos Exp $ */
/*
@@ -459,11 +459,15 @@ udp_input(struct mbuf *m, ...)
if ((n = m_copy(m, 0, M_COPYALL)) != NULL) {
#ifdef INET6
if (ip6 && (last->inp_flags &
- IN6P_CONTROLOPTS))
+ IN6P_CONTROLOPTS ||
+ last->inp_socket->so_options &
+ SO_TIMESTAMP))
ip6_savecontrol(last, n, &opts);
#endif /* INET6 */
if (ip && (last->inp_flags &
- INP_CONTROLOPTS))
+ INP_CONTROLOPTS ||
+ last->inp_socket->so_options &
+ SO_TIMESTAMP))
ip_savecontrol(last, &opts,
ip, n);
@@ -505,10 +509,12 @@ udp_input(struct mbuf *m, ...)
}
#ifdef INET6
- if (ip6 && (last->inp_flags & IN6P_CONTROLOPTS))
+ if (ip6 && (last->inp_flags & IN6P_CONTROLOPTS ||
+ last->inp_socket->so_options & SO_TIMESTAMP))
ip6_savecontrol(last, m, &opts);
#endif /* INET6 */
- if (ip && (last->inp_flags & INP_CONTROLOPTS))
+ if (ip && (last->inp_flags & INP_CONTROLOPTS ||
+ last->inp_socket->so_options & SO_TIMESTAMP))
ip_savecontrol(last, &opts, ip, m);
m_adj(m, iphlen);
@@ -623,10 +629,12 @@ udp_input(struct mbuf *m, ...)
opts = NULL;
#ifdef INET6
- if (ip6 && (inp->inp_flags & IN6P_CONTROLOPTS))
+ if (ip6 && (inp->inp_flags & IN6P_CONTROLOPTS ||
+ inp->inp_socket->so_options & SO_TIMESTAMP))
ip6_savecontrol(inp, m, &opts);
#endif /* INET6 */
- if (ip && (inp->inp_flags & INP_CONTROLOPTS))
+ if (ip && (inp->inp_flags & INP_CONTROLOPTS ||
+ inp->inp_socket->so_options & SO_TIMESTAMP))
ip_savecontrol(inp, &opts, ip, m);
iphlen += sizeof(struct udphdr);
diff --git a/sys/sys/socket.h b/sys/sys/socket.h
index b29ec70c4bd..a5bb2afeacb 100644
--- a/sys/sys/socket.h
+++ b/sys/sys/socket.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: socket.h,v 1.56 2008/04/23 10:55:14 norby Exp $ */
+/* $OpenBSD: socket.h,v 1.57 2008/05/02 06:49:32 ckuethe Exp $ */
/* $NetBSD: socket.h,v 1.14 1996/02/09 18:25:36 christos Exp $ */
/*
@@ -67,6 +67,7 @@
#define SO_OOBINLINE 0x0100 /* leave received OOB data in line */
#define SO_REUSEPORT 0x0200 /* allow local address & port reuse */
#define SO_JUMBO 0x0400 /* try to use jumbograms */
+#define SO_TIMESTAMP 0x0800 /* timestamp received dgram traffic */
/*
* Additional options, not kept in so_options.
@@ -417,6 +418,7 @@ struct cmsghdr {
/* "Socket"-level control message types: */
#define SCM_RIGHTS 0x01 /* access rights (array of int) */
#define SCM_CREDS 0x02 /* credentials (struct sockcred) */
+#define SCM_TIMESTAMP 0x04 /* timestamp (struct timeval) */
/*
* 4.3 compat sockaddr, move to compat file later