net: add missing SOF_TIMESTAMPING_OPT_ID support
authorWillem de Bruijn <willemb@google.com>
Wed, 6 Apr 2022 19:29:56 +0000 (22:29 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 15 Apr 2022 12:15:04 +0000 (14:15 +0200)
[ Upstream commit 8f932f762e7928d250e21006b00ff9b7718b0a64 ]

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>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
include/net/sock.h
net/can/raw.c
net/ipv4/raw.c
net/ipv6/raw.c
net/packet/af_packet.c

index 2bf8dcf863f2cd1d35c766340fb697f6047784dc..7d3a4c2eea95b9d16168e2cdc2cb3b6aed045ef0 100644 (file)
@@ -2400,22 +2400,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
index d0fb5a57c66d597002e24573bc7b468965f485bd..2a6db8752b61d21e7edaacc5f2b88b37aa95c566 100644 (file)
@@ -814,7 +814,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;
index 8cae691c3c9f4746539a5088d69a9410ce9b91d3..654f586fc0d7345f62ed3c6d5a6cbd7a2ad358fa 100644 (file)
@@ -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);
index 98c8f98a7660e76e32f0f1923c8e57f90be120b0..ad7bd40b6d5338e87f54ca4749a629e4bb3548d6 100644 (file)
@@ -660,7 +660,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);
index d65051959f85243159a7459dcb7ad75611eb3d3f..b951f411ddedcfee75aa9ae264e035311483c3df 100644 (file)
@@ -1978,7 +1978,7 @@ retry:
        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;
@@ -2501,7 +2501,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);
@@ -2965,7 +2965,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)) {