bpf: tcp: Avoid socket skips and repeats during iteration
authorJordan Rife <jordan@jrife.io>
Mon, 14 Jul 2025 18:09:09 +0000 (11:09 -0700)
committerMartin KaFai Lau <martin.lau@kernel.org>
Mon, 14 Jul 2025 19:09:09 +0000 (12:09 -0700)
commitf5080f612a1c587bf636bb23d2a2f4de276d60e4
tree73ace996945ed66273de2da6070bc43553e1cfff
parentefeb820951ebf3778830256496ff72d00d135310
bpf: tcp: Avoid socket skips and repeats during iteration

Replace the offset-based approach for tracking progress through a bucket
in the TCP table with one based on socket cookies. Remember the cookies
of unprocessed sockets from the last batch and use this list to
pick up where we left off or, in the case that the next socket
disappears between reads, find the first socket after that point that
still exists in the bucket and resume from there.

This approach guarantees that all sockets that existed when iteration
began and continue to exist throughout will be visited exactly once.
Sockets that are added to the table during iteration may or may not be
seen, but if they are they will be seen exactly once.

Signed-off-by: Jordan Rife <jordan@jrife.io>
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Acked-by: Stanislav Fomichev <sdf@fomichev.me>
net/ipv4/tcp_ipv4.c