[PATCH hurd v2] pfinet: implement rudimentary SO_TIMESTAMP support

[email protected]
Newsgroups gmane.os.hurd.bugs
Message-ID <[email protected]>
From: Diego Nieto Cid <[email protected]>

This patch adds support for UDP packet timestamping only when
both SO_TIMESTAMP and SCM_TIMESTAMP are defined.

* pfinet/linux-src/include/net/sock.h: add timestamp flag

* pfinet/linux-src/net/core/sock.c: modify sock_*sockopt to set
  and query the timestamp flag.

* pfinet/linux-src/net/ipv4/udp.c: call put_cmsg in udp_recvmsg
  to write the packet timestamp to the message anciliary data.
---
 pfinet/linux-src/include/net/sock.h |  3 +++
 pfinet/linux-src/net/core/sock.c    | 10 ++++++++++
 pfinet/linux-src/net/ipv4/udp.c     |  5 +++++
 3 files changed, 18 insertions(+)

diff --git a/pfinet/linux-src/include/net/sock.h b/pfinet/linux-src/include/net/sock.h
index 5c4444d1..435f8870 100644
--- a/pfinet/linux-src/include/net/sock.h
+++ b/pfinet/linux-src/include/net/sock.h
@@ -411,6 +411,9 @@ struct sock {
 				broadcast,
 				bsdism;
 	unsigned char		debug;
+#if defined(SO_TIMESTAMP) && defined(SCM_TIMESTAMP)
+	unsigned char           timestamp;
+#endif
 	int			proc;
 	unsigned long	        lingertime;
 
diff --git a/pfinet/linux-src/net/core/sock.c b/pfinet/linux-src/net/core/sock.c
index c47c935b..5ab7d840 100644
--- a/pfinet/linux-src/net/core/sock.c
+++ b/pfinet/linux-src/net/core/sock.c
@@ -191,6 +191,11 @@ int sock_setsockopt(struct socket *sock, int level, int optname,
 			else
 				sk->debug=valbool;
 			break;
+#if defined(SO_TIMESTAMP) && defined(SCM_TIMESTAMP)
+		case SO_TIMESTAMP:
+			sk->timestamp = valbool;
+			break;
+#endif
 		case SO_REUSEADDR:
 			sk->reuse = valbool;
 			break;
@@ -384,6 +389,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
 		case SO_DEBUG:		
 			v.val = sk->debug;
 			break;
+#if defined(SO_TIMESTAMP) && defined(SCM_TIMESTAMP)
+		case SO_TIMESTAMP:
+			v.val = sk->timestamp;
+			break;
+#endif
 		
 		case SO_DONTROUTE:
 			v.val = sk->localroute;
diff --git a/pfinet/linux-src/net/ipv4/udp.c b/pfinet/linux-src/net/ipv4/udp.c
index c1da9886..52bae18e 100644
--- a/pfinet/linux-src/net/ipv4/udp.c
+++ b/pfinet/linux-src/net/ipv4/udp.c
@@ -813,6 +813,11 @@ int udp_recvmsg(struct sock *sk, struct msghdr *msg, int len,
 		msg->msg_flags |= MSG_TRUNC;
 	}
 
+#if defined(SO_TIMESTAMP) && defined(SCM_TIMESTAMP)
+	if (sk->timestamp)
+		put_cmsg(msg, SOL_SOCKET, SCM_TIMESTAMP, sizeof(skb->stamp), &skb->stamp);
+#endif
+
 #ifndef CONFIG_UDP_DELAY_CSUM
 	err = skb_copy_datagram_iovec(skb, sizeof(struct udphdr), msg->msg_iov,
 					copied);
-- 
2.53.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.