netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net 0/2] SO_TIMESTAMPING fixes
@ 2018-12-17 17:23 Willem de Bruijn
  2018-12-17 17:23 ` [PATCH net 1/2] ipv6: add missing tx timestamping on IPPROTO_RAW Willem de Bruijn
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Willem de Bruijn @ 2018-12-17 17:23 UTC (permalink / raw)
  To: netdev; +Cc: davem, Willem de Bruijn

From: Willem de Bruijn <willemb@google.com>

Fix two omissions:

- tx timestamping is missing for AF_INET6/SOCK_RAW/IPPROTO_RAW
- SOF_TIMESTAMPING_OPT_ID is missing for IPPROTO_RAW, PF_PACKET, CAN

Discovered while expanding the selftest in

  tools/testing/selftests/networking/timestamping/txtimestamp.c

Will send the test patchset to net-next once the fixes make it to that
branch. For now, it is available at

  https://github.com/wdebruij/linux/commits/txtimestamp-test-1

Willem de Bruijn (2):
  ipv6: add missing tx timestamping on IPPROTO_RAW
  net: add missing SOF_TIMESTAMPING_OPT_ID support

 include/net/sock.h     | 25 +++++++++++++++++++++----
 net/can/raw.c          |  2 +-
 net/ipv4/raw.c         |  2 +-
 net/ipv6/raw.c         |  2 ++
 net/packet/af_packet.c |  6 +++---
 5 files changed, 28 insertions(+), 9 deletions(-)

-- 
2.20.0.405.gbc1bbc6f85-goog

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH net 1/2] ipv6: add missing tx timestamping on IPPROTO_RAW
  2018-12-17 17:23 [PATCH net 0/2] SO_TIMESTAMPING fixes Willem de Bruijn
@ 2018-12-17 17:23 ` Willem de Bruijn
  2018-12-17 17:24 ` [PATCH net 2/2] net: add missing SOF_TIMESTAMPING_OPT_ID support Willem de Bruijn
  2018-12-18  7:27 ` [PATCH net 0/2] SO_TIMESTAMPING fixes David Miller
  2 siblings, 0 replies; 5+ messages in thread
From: Willem de Bruijn @ 2018-12-17 17:23 UTC (permalink / raw)
  To: netdev; +Cc: davem, Willem de Bruijn, Soheil Hassas Yeganeh

From: Willem de Bruijn <willemb@google.com>

Raw sockets support tx timestamping, but one case is missing.

IPPROTO_RAW takes a separate packet construction path. raw_send_hdrinc
has an explicit call to sock_tx_timestamp, but rawv6_send_hdrinc does
not. Add it.

Fixes: 11878b40ed5c ("net-timestamp: SOCK_RAW and PING timestamping")
Signed-off-by: Willem de Bruijn <willemb@google.com>
Acked-by: Soheil Hassas Yeganeh <soheil@google.com>
---
 net/ipv6/raw.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
index 5e0efd3954e90..c8562432fcc39 100644
--- a/net/ipv6/raw.c
+++ b/net/ipv6/raw.c
@@ -658,6 +658,8 @@ static int rawv6_send_hdrinc(struct sock *sk, struct msghdr *msg, int length,
 
 	skb->ip_summed = CHECKSUM_NONE;
 
+	sock_tx_timestamp(sk, sockc->tsflags, &skb_shinfo(skb)->tx_flags);
+
 	if (flags & MSG_CONFIRM)
 		skb_set_dst_pending_confirm(skb, 1);
 
-- 
2.20.0.405.gbc1bbc6f85-goog

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH net 2/2] net: add missing SOF_TIMESTAMPING_OPT_ID support
  2018-12-17 17:23 [PATCH net 0/2] SO_TIMESTAMPING fixes Willem de Bruijn
  2018-12-17 17:23 ` [PATCH net 1/2] ipv6: add missing tx timestamping on IPPROTO_RAW Willem de Bruijn
@ 2018-12-17 17:24 ` Willem de Bruijn
  2018-12-18  7:27 ` [PATCH net 0/2] SO_TIMESTAMPING fixes David Miller
  2 siblings, 0 replies; 5+ messages in thread
From: Willem de Bruijn @ 2018-12-17 17:24 UTC (permalink / raw)
  To: netdev; +Cc: davem, Willem de Bruijn, Soheil Hassas Yeganeh

From: Willem de Bruijn <willemb@google.com>

SOF_TIMESTAMPING_OPT_ID is supported on TCP, UDP and RAW sockets.
But it was missing on RAW with IPPROTO_IP, PF_PACKET and CAN.

Add skb_setup_tx_timestamp that configures both tx_flags and tskey
for these paths that do not need corking or use bytestream keys.

Fixes: 09c2d251b707 ("net-timestamp: add key to disambiguate concurrent datagrams")
Signed-off-by: Willem de Bruijn <willemb@google.com>
Acked-by: Soheil Hassas Yeganeh <soheil@google.com>
---
 include/net/sock.h     | 25 +++++++++++++++++++++----
 net/can/raw.c          |  2 +-
 net/ipv4/raw.c         |  2 +-
 net/ipv6/raw.c         |  2 +-
 net/packet/af_packet.c |  6 +++---
 5 files changed, 27 insertions(+), 10 deletions(-)

diff --git a/include/net/sock.h b/include/net/sock.h
index f665d74ae509b..0e3a09380655e 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -2340,22 +2340,39 @@ static inline void sock_recv_ts_and_drops(struct msghdr *msg, struct sock *sk,
 void __sock_tx_timestamp(__u16 tsflags, __u8 *tx_flags);
 
 /**
- * sock_tx_timestamp - checks whether the outgoing packet is to be time stamped
+ * _sock_tx_timestamp - checks whether the outgoing packet is to be time stamped
  * @sk:		socket sending this packet
  * @tsflags:	timestamping flags to use
  * @tx_flags:	completed with instructions for time stamping
+ * @tskey:      filled in with next sk_tskey (not for TCP, which uses seqno)
  *
  * Note: callers should take care of initial ``*tx_flags`` value (usually 0)
  */
-static inline void sock_tx_timestamp(const struct sock *sk, __u16 tsflags,
-				     __u8 *tx_flags)
+static inline void _sock_tx_timestamp(struct sock *sk, __u16 tsflags,
+				      __u8 *tx_flags, __u32 *tskey)
 {
-	if (unlikely(tsflags))
+	if (unlikely(tsflags)) {
 		__sock_tx_timestamp(tsflags, tx_flags);
+		if (tsflags & SOF_TIMESTAMPING_OPT_ID && tskey &&
+		    tsflags & SOF_TIMESTAMPING_TX_RECORD_MASK)
+			*tskey = sk->sk_tskey++;
+	}
 	if (unlikely(sock_flag(sk, SOCK_WIFI_STATUS)))
 		*tx_flags |= SKBTX_WIFI_STATUS;
 }
 
+static inline void sock_tx_timestamp(struct sock *sk, __u16 tsflags,
+				     __u8 *tx_flags)
+{
+	_sock_tx_timestamp(sk, tsflags, tx_flags, NULL);
+}
+
+static inline void skb_setup_tx_timestamp(struct sk_buff *skb, __u16 tsflags)
+{
+	_sock_tx_timestamp(skb->sk, tsflags, &skb_shinfo(skb)->tx_flags,
+			   &skb_shinfo(skb)->tskey);
+}
+
 /**
  * sk_eat_skb - Release a skb if it is no longer needed
  * @sk: socket to eat this skb from
diff --git a/net/can/raw.c b/net/can/raw.c
index 3aab7664933fd..c70207537488f 100644
--- a/net/can/raw.c
+++ b/net/can/raw.c
@@ -771,7 +771,7 @@ static int raw_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
 	if (err < 0)
 		goto free_skb;
 
-	sock_tx_timestamp(sk, sk->sk_tsflags, &skb_shinfo(skb)->tx_flags);
+	skb_setup_tx_timestamp(skb, sk->sk_tsflags);
 
 	skb->dev = dev;
 	skb->sk  = sk;
diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
index 8ca3eb06ba042..169a652b3dd1a 100644
--- a/net/ipv4/raw.c
+++ b/net/ipv4/raw.c
@@ -391,7 +391,7 @@ static int raw_send_hdrinc(struct sock *sk, struct flowi4 *fl4,
 
 	skb->ip_summed = CHECKSUM_NONE;
 
-	sock_tx_timestamp(sk, sockc->tsflags, &skb_shinfo(skb)->tx_flags);
+	skb_setup_tx_timestamp(skb, sockc->tsflags);
 
 	if (flags & MSG_CONFIRM)
 		skb_set_dst_pending_confirm(skb, 1);
diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
index c8562432fcc39..fc2b5e845fdf3 100644
--- a/net/ipv6/raw.c
+++ b/net/ipv6/raw.c
@@ -658,7 +658,7 @@ static int rawv6_send_hdrinc(struct sock *sk, struct msghdr *msg, int length,
 
 	skb->ip_summed = CHECKSUM_NONE;
 
-	sock_tx_timestamp(sk, sockc->tsflags, &skb_shinfo(skb)->tx_flags);
+	skb_setup_tx_timestamp(skb, sockc->tsflags);
 
 	if (flags & MSG_CONFIRM)
 		skb_set_dst_pending_confirm(skb, 1);
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index a74650e98f423..6655793765b2d 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -1965,7 +1965,7 @@ static int packet_sendmsg_spkt(struct socket *sock, struct msghdr *msg,
 	skb->mark = sk->sk_mark;
 	skb->tstamp = sockc.transmit_time;
 
-	sock_tx_timestamp(sk, sockc.tsflags, &skb_shinfo(skb)->tx_flags);
+	skb_setup_tx_timestamp(skb, sockc.tsflags);
 
 	if (unlikely(extra_len == 4))
 		skb->no_fcs = 1;
@@ -2460,7 +2460,7 @@ static int tpacket_fill_skb(struct packet_sock *po, struct sk_buff *skb,
 	skb->priority = po->sk.sk_priority;
 	skb->mark = po->sk.sk_mark;
 	skb->tstamp = sockc->transmit_time;
-	sock_tx_timestamp(&po->sk, sockc->tsflags, &skb_shinfo(skb)->tx_flags);
+	skb_setup_tx_timestamp(skb, sockc->tsflags);
 	skb_zcopy_set_nouarg(skb, ph.raw);
 
 	skb_reserve(skb, hlen);
@@ -2898,7 +2898,7 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)
 		goto out_free;
 	}
 
-	sock_tx_timestamp(sk, sockc.tsflags, &skb_shinfo(skb)->tx_flags);
+	skb_setup_tx_timestamp(skb, sockc.tsflags);
 
 	if (!vnet_hdr.gso_type && (len > dev->mtu + reserve + extra_len) &&
 	    !packet_extra_vlan_len_allowed(dev, skb)) {
-- 
2.20.0.405.gbc1bbc6f85-goog

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH net 0/2] SO_TIMESTAMPING fixes
  2018-12-17 17:23 [PATCH net 0/2] SO_TIMESTAMPING fixes Willem de Bruijn
  2018-12-17 17:23 ` [PATCH net 1/2] ipv6: add missing tx timestamping on IPPROTO_RAW Willem de Bruijn
  2018-12-17 17:24 ` [PATCH net 2/2] net: add missing SOF_TIMESTAMPING_OPT_ID support Willem de Bruijn
@ 2018-12-18  7:27 ` David Miller
  2018-12-18 14:33   ` Willem de Bruijn
  2 siblings, 1 reply; 5+ messages in thread
From: David Miller @ 2018-12-18  7:27 UTC (permalink / raw)
  To: willemdebruijn.kernel; +Cc: netdev, willemb

From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
Date: Mon, 17 Dec 2018 12:23:58 -0500

> From: Willem de Bruijn <willemb@google.com>
> 
> Fix two omissions:
> 
> - tx timestamping is missing for AF_INET6/SOCK_RAW/IPPROTO_RAW
> - SOF_TIMESTAMPING_OPT_ID is missing for IPPROTO_RAW, PF_PACKET, CAN
> 
> Discovered while expanding the selftest in
> 
>   tools/testing/selftests/networking/timestamping/txtimestamp.c
> 
> Will send the test patchset to net-next once the fixes make it to that
> branch. For now, it is available at
> 
>   https://github.com/wdebruij/linux/commits/txtimestamp-test-1

Series applied.

What is your opinion about -stable for this?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net 0/2] SO_TIMESTAMPING fixes
  2018-12-18  7:27 ` [PATCH net 0/2] SO_TIMESTAMPING fixes David Miller
@ 2018-12-18 14:33   ` Willem de Bruijn
  0 siblings, 0 replies; 5+ messages in thread
From: Willem de Bruijn @ 2018-12-18 14:33 UTC (permalink / raw)
  To: David Miller; +Cc: Network Development, Willem de Bruijn

On Tue, Dec 18, 2018 at 2:27 AM David Miller <davem@davemloft.net> wrote:
>
> From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
> Date: Mon, 17 Dec 2018 12:23:58 -0500
>
> > From: Willem de Bruijn <willemb@google.com>
> >
> > Fix two omissions:
> >
> > - tx timestamping is missing for AF_INET6/SOCK_RAW/IPPROTO_RAW
> > - SOF_TIMESTAMPING_OPT_ID is missing for IPPROTO_RAW, PF_PACKET, CAN
> >
> > Discovered while expanding the selftest in
> >
> >   tools/testing/selftests/networking/timestamping/txtimestamp.c
> >
> > Will send the test patchset to net-next once the fixes make it to that
> > branch. For now, it is available at
> >
> >   https://github.com/wdebruij/linux/commits/txtimestamp-test-1
>
> Series applied.
>
> What is your opinion about -stable for this?

Thanks David. Since these are just missing features that no one has
reported as actually having been missing a whole lot, I don't think
that they are worth the effort or risk.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-12-18 14:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-17 17:23 [PATCH net 0/2] SO_TIMESTAMPING fixes Willem de Bruijn
2018-12-17 17:23 ` [PATCH net 1/2] ipv6: add missing tx timestamping on IPPROTO_RAW Willem de Bruijn
2018-12-17 17:24 ` [PATCH net 2/2] net: add missing SOF_TIMESTAMPING_OPT_ID support Willem de Bruijn
2018-12-18  7:27 ` [PATCH net 0/2] SO_TIMESTAMPING fixes David Miller
2018-12-18 14:33   ` Willem de Bruijn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).