Skip to content

Commit 206057f

Browse files
iamkafaiAlexei Starovoitov
authored and
Alexei Starovoitov
committed
bpf: Add BPF_FUNC_tcp_send_ack helper
Add a helper to send out a tcp-ack. It will be used in the later bpf_dctcp implementation that requires to send out an ack when the CE state changed. Signed-off-by: Martin KaFai Lau <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Acked-by: Yonghong Song <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 0baf26b commit 206057f

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

include/uapi/linux/bpf.h

+10-1
Original file line numberDiff line numberDiff line change
@@ -2837,6 +2837,14 @@ union bpf_attr {
28372837
* Return
28382838
* On success, the strictly positive length of the string, including
28392839
* the trailing NUL character. On error, a negative value.
2840+
*
2841+
* int bpf_tcp_send_ack(void *tp, u32 rcv_nxt)
2842+
* Description
2843+
* Send out a tcp-ack. *tp* is the in-kernel struct tcp_sock.
2844+
* *rcv_nxt* is the ack_seq to be sent out.
2845+
* Return
2846+
* 0 on success, or a negative error in case of failure.
2847+
*
28402848
*/
28412849
#define __BPF_FUNC_MAPPER(FN) \
28422850
FN(unspec), \
@@ -2954,7 +2962,8 @@ union bpf_attr {
29542962
FN(probe_read_user), \
29552963
FN(probe_read_kernel), \
29562964
FN(probe_read_user_str), \
2957-
FN(probe_read_kernel_str),
2965+
FN(probe_read_kernel_str), \
2966+
FN(tcp_send_ack),
29582967

29592968
/* integer value in 'imm' field of BPF_CALL instruction selects which helper
29602969
* function eBPF program intends to call

net/ipv4/bpf_tcp_ca.c

+23-1
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,33 @@ static int bpf_tcp_ca_btf_struct_access(struct bpf_verifier_log *log,
143143
return NOT_INIT;
144144
}
145145

146+
BPF_CALL_2(bpf_tcp_send_ack, struct tcp_sock *, tp, u32, rcv_nxt)
147+
{
148+
/* bpf_tcp_ca prog cannot have NULL tp */
149+
__tcp_send_ack((struct sock *)tp, rcv_nxt);
150+
return 0;
151+
}
152+
153+
static const struct bpf_func_proto bpf_tcp_send_ack_proto = {
154+
.func = bpf_tcp_send_ack,
155+
.gpl_only = false,
156+
/* In case we want to report error later */
157+
.ret_type = RET_INTEGER,
158+
.arg1_type = ARG_PTR_TO_BTF_ID,
159+
.arg2_type = ARG_ANYTHING,
160+
.btf_id = &tcp_sock_id,
161+
};
162+
146163
static const struct bpf_func_proto *
147164
bpf_tcp_ca_get_func_proto(enum bpf_func_id func_id,
148165
const struct bpf_prog *prog)
149166
{
150-
return bpf_base_func_proto(func_id);
167+
switch (func_id) {
168+
case BPF_FUNC_tcp_send_ack:
169+
return &bpf_tcp_send_ack_proto;
170+
default:
171+
return bpf_base_func_proto(func_id);
172+
}
151173
}
152174

153175
static const struct bpf_verifier_ops bpf_tcp_ca_verifier_ops = {

0 commit comments

Comments
 (0)