Skip to content

Commit f333ee0

Browse files
rdnaborkmann
authored andcommitted
bpf: Add BPF_SOCK_OPS_TCP_LISTEN_CB
Add new TCP-BPF callback that is called on listen(2) right after socket transition to TCP_LISTEN state. It fills the gap for listening sockets in TCP-BPF. For example BPF program can set BPF_SOCK_OPS_STATE_CB_FLAG when socket becomes listening and track later transition from TCP_LISTEN to TCP_CLOSE with BPF_SOCK_OPS_STATE_CB callback. Before there was no way to do it with TCP-BPF and other options were much harder to work with. E.g. socket state tracking can be done with tracepoints (either raw or regular) but they can't be attached to cgroup and their lifetime has to be managed separately. Signed-off-by: Andrey Ignatov <rdna@fb.com> Acked-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
1 parent 2d3feca commit f333ee0

2 files changed

Lines changed: 4 additions & 0 deletions

File tree

‎include/uapi/linux/bpf.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2555,6 +2555,9 @@ enum {
25552555
* Arg1: old_state
25562556
* Arg2: new_state
25572557
*/
2558+
BPF_SOCK_OPS_TCP_LISTEN_CB, /* Called on listen(2), right after
2559+
* socket transition to LISTEN state.
2560+
*/
25582561
};
25592562

25602563
/* List of TCP states. There is a build check in net/ipv4/tcp.c to detect

‎net/ipv4/af_inet.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ int inet_listen(struct socket *sock, int backlog)
229229
err = inet_csk_listen_start(sk, backlog);
230230
if (err)
231231
goto out;
232+
tcp_call_bpf(sk, BPF_SOCK_OPS_TCP_LISTEN_CB, 0, NULL);
232233
}
233234
sk->sk_max_ack_backlog = backlog;
234235
err = 0;

0 commit comments

Comments
 (0)