Add a read-only TCP_TS_ID option so applications and tests can see which TSval identifier, if any, was assigned to a connection. The value packs the identifier width into bits 8..15 and the identifier into bits 0..7. Zero means no identifier is encoded. The option cannot be set. The identifier is chosen by BPF_SOCK_OPS_TCP_TS_ID_CB when the SYN arrives, and there is no way to restore it onto a new socket, so connections that carry one do not survive TCP_REPAIR. ip-sysctl.rst already documents that limitation. Signed-off-by: Willem Ferguson --- Documentation/networking/ip-sysctl.rst | 3 ++- include/uapi/linux/tcp.h | 8 ++++++++ net/ipv4/tcp.c | 3 +++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Documentation/networking/ip-sysctl.rst b/Documentation/networking/ip-sysctl.rst index ce669f282250..d5e992623326 100644 --- a/Documentation/networking/ip-sysctl.rst +++ b/Documentation/networking/ip-sysctl.rst @@ -1123,7 +1123,8 @@ tcp_ts_id_bits - INTEGER often than this interval prevents it. Progress is visible through the TCPTSId* counters in - /proc/net/netstat. + /proc/net/netstat, and a connection's identifier can be read with the + TCP_TS_ID socket option. Checkpoint/restore is not supported. The identifier is selected by BPF when the SYN arrives and cannot be restored onto a new socket, so a diff --git a/include/uapi/linux/tcp.h b/include/uapi/linux/tcp.h index 03772dd4d399..5d7f37b6f8d9 100644 --- a/include/uapi/linux/tcp.h +++ b/include/uapi/linux/tcp.h @@ -142,6 +142,14 @@ enum { #define TCP_RTO_MAX_MS 44 /* max rto time in ms */ #define TCP_RTO_MIN_US 45 /* min rto time in us */ #define TCP_DELACK_MAX_US 46 /* max delayed ack time in us */ +#define TCP_TS_ID 47 /* Read TSval identifier and its width */ + +/* TCP_TS_ID value layout: identifier width in bits 8..15, identifier in + * bits 0..7. A value of 0 means no identifier is encoded. Read-only: the + * identifier is chosen by BPF_SOCK_OPS_TCP_TS_ID_CB and cannot be restored, + * so connections with an identifier do not survive TCP_REPAIR. + */ +#define TCP_TS_ID_BITS_SHIFT 8 #define TCP_REPAIR_ON 1 #define TCP_REPAIR_OFF 0 diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index af994edde7f7..5991b16396b9 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -4711,6 +4711,9 @@ int do_tcp_getsockopt(struct sock *sk, int level, else val &= ~1; break; + case TCP_TS_ID: + val = ((u32)tp->ts_id_bits << TCP_TS_ID_BITS_SHIFT) | tp->ts_id; + break; case TCP_NOTSENT_LOWAT: val = READ_ONCE(tp->notsent_lowat); break; -- 2.47.3