OSDN Git Service

net_tstamp: add SOF_TIMESTAMPING_OPT_ID_TCP
authorWillem de Bruijn <willemb@google.com>
Wed, 7 Dec 2022 14:37:01 +0000 (09:37 -0500)
committerJakub Kicinski <kuba@kernel.org>
Fri, 9 Dec 2022 03:49:21 +0000 (19:49 -0800)
commitb534dc46c8ae0165b1b2509be24dbea4fa9c4011
treefb5430445edefccc6a6a9c79c5a20cb95912e516
parentecd6df3c1ba8ad8befd82fc8f0d2438e8d3c75cc
net_tstamp: add SOF_TIMESTAMPING_OPT_ID_TCP

Add an option to initialize SOF_TIMESTAMPING_OPT_ID for TCP from
write_seq sockets instead of snd_una.

This should have been the behavior from the start. Because processes
may now exist that rely on the established behavior, do not change
behavior of the existing option, but add the right behavior with a new
flag. It is encouraged to always set SOF_TIMESTAMPING_OPT_ID_TCP on
stream sockets along with the existing SOF_TIMESTAMPING_OPT_ID.

Intuitively the contract is that the counter is zero after the
setsockopt, so that the next write N results in a notification for
the last byte N - 1.

On idle sockets snd_una == write_seq and this holds for both. But on
sockets with data in transmission, snd_una records the unacked offset
in the stream. This depends on the ACK response from the peer. A
process cannot learn this in a race free manner (ioctl SIOCOUTQ is one
racy approach).

write_seq records the offset at the last byte written by the process.
This is a better starting point. It matches the intuitive contract in
all circumstances, unaffected by external behavior.

The new timestamp flag necessitates increasing sk_tsflags to 32 bits.
Move the field in struct sock to avoid growing the socket (for some
common CONFIG variants). The UAPI interface so_timestamping.flags is
already int, so 32 bits wide.

Reported-by: Sotirios Delimanolis <sotodel@meta.com>
Signed-off-by: Willem de Bruijn <willemb@google.com>
Link: https://lore.kernel.org/r/20221207143701.29861-1-willemdebruijn.kernel@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Documentation/networking/timestamping.rst
include/net/sock.h
include/uapi/linux/net_tstamp.h
net/core/sock.c
net/ethtool/common.c