Skip to content

Commit 9872a4b

Browse files
Lawrence Brakmodavem330
authored andcommitted
bpf: Add TCP connection BPF callbacks
Added callbacks to BPF SOCK_OPS type program before an active connection is intialized and after a passive or active connection is established. The following patch demostrates how they can be used to set send and receive buffer sizes. Signed-off-by: Lawrence Brakmo <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 8c4b4c7 commit 9872a4b

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

include/uapi/linux/bpf.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,17 @@ enum {
767767
* window (in packets) or -1 if default
768768
* value should be used
769769
*/
770+
BPF_SOCK_OPS_TCP_CONNECT_CB, /* Calls BPF program right before an
771+
* active connection is initialized
772+
*/
773+
BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB, /* Calls BPF program when an
774+
* active connection is
775+
* established
776+
*/
777+
BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB, /* Calls BPF program when a
778+
* passive connection is
779+
* established
780+
*/
770781
};
771782

772783
#endif /* _UAPI__LINUX_BPF_H__ */

net/ipv4/tcp_fastopen.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ static struct sock *tcp_fastopen_create_child(struct sock *sk,
221221
tcp_init_congestion_control(child);
222222
tcp_mtup_init(child);
223223
tcp_init_metrics(child);
224+
tcp_call_bpf(child, BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB);
224225
tcp_init_buffer_space(child);
225226

226227
tp->rcv_nxt = TCP_SKB_CB(skb)->seq + 1;

net/ipv4/tcp_input.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5571,7 +5571,7 @@ void tcp_finish_connect(struct sock *sk, struct sk_buff *skb)
55715571
icsk->icsk_af_ops->rebuild_header(sk);
55725572

55735573
tcp_init_metrics(sk);
5574-
5574+
tcp_call_bpf(sk, BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB);
55755575
tcp_init_congestion_control(sk);
55765576

55775577
/* Prevent spurious tcp_cwnd_restart() on first data
@@ -5977,6 +5977,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb)
59775977
} else {
59785978
/* Make sure socket is routed, for correct metrics. */
59795979
icsk->icsk_af_ops->rebuild_header(sk);
5980+
tcp_call_bpf(sk, BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB);
59805981
tcp_init_congestion_control(sk);
59815982

59825983
tcp_mtup_init(sk);

net/ipv4/tcp_output.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3444,6 +3444,7 @@ int tcp_connect(struct sock *sk)
34443444
struct sk_buff *buff;
34453445
int err;
34463446

3447+
tcp_call_bpf(sk, BPF_SOCK_OPS_TCP_CONNECT_CB);
34473448
tcp_connect_init(sk);
34483449

34493450
if (unlikely(tp->repair)) {

0 commit comments

Comments
 (0)