From: Martin KaFai Lau <kafai@fb.com>
To: <bpf@vger.kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
David Miller <davem@davemloft.net>, <kernel-team@fb.com>,
<netdev@vger.kernel.org>
Subject: [PATCH bpf-next v4 08/11] bpf: Add BPF_FUNC_tcp_send_ack helper
Date: Wed, 8 Jan 2020 16:45:51 -0800 [thread overview]
Message-ID: <20200109004551.3900448-1-kafai@fb.com> (raw)
In-Reply-To: <20200109003453.3854769-1-kafai@fb.com>
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.
Acked-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Martin KaFai Lau <kafai@fb.com>
---
include/uapi/linux/bpf.h | 11 ++++++++++-
net/ipv4/bpf_tcp_ca.c | 24 +++++++++++++++++++++++-
2 files changed, 33 insertions(+), 2 deletions(-)
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index 38059880963e..2d6a2e572f56 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -2837,6 +2837,14 @@ union bpf_attr {
* Return
* On success, the strictly positive length of the string, including
* the trailing NUL character. On error, a negative value.
+ *
+ * int bpf_tcp_send_ack(void *tp, u32 rcv_nxt)
+ * Description
+ * Send out a tcp-ack. *tp* is the in-kernel struct tcp_sock.
+ * *rcv_nxt* is the ack_seq to be sent out.
+ * Return
+ * 0 on success, or a negative error in case of failure.
+ *
*/
#define __BPF_FUNC_MAPPER(FN) \
FN(unspec), \
@@ -2954,7 +2962,8 @@ union bpf_attr {
FN(probe_read_user), \
FN(probe_read_kernel), \
FN(probe_read_user_str), \
- FN(probe_read_kernel_str),
+ FN(probe_read_kernel_str), \
+ FN(tcp_send_ack),
/* integer value in 'imm' field of BPF_CALL instruction selects which helper
* function eBPF program intends to call
diff --git a/net/ipv4/bpf_tcp_ca.c b/net/ipv4/bpf_tcp_ca.c
index 9c7745b958d7..574972bc7299 100644
--- a/net/ipv4/bpf_tcp_ca.c
+++ b/net/ipv4/bpf_tcp_ca.c
@@ -143,11 +143,33 @@ static int bpf_tcp_ca_btf_struct_access(struct bpf_verifier_log *log,
return NOT_INIT;
}
+BPF_CALL_2(bpf_tcp_send_ack, struct tcp_sock *, tp, u32, rcv_nxt)
+{
+ /* bpf_tcp_ca prog cannot have NULL tp */
+ __tcp_send_ack((struct sock *)tp, rcv_nxt);
+ return 0;
+}
+
+static const struct bpf_func_proto bpf_tcp_send_ack_proto = {
+ .func = bpf_tcp_send_ack,
+ .gpl_only = false,
+ /* In case we want to report error later */
+ .ret_type = RET_INTEGER,
+ .arg1_type = ARG_PTR_TO_BTF_ID,
+ .arg2_type = ARG_ANYTHING,
+ .btf_id = &tcp_sock_id,
+};
+
static const struct bpf_func_proto *
bpf_tcp_ca_get_func_proto(enum bpf_func_id func_id,
const struct bpf_prog *prog)
{
- return bpf_base_func_proto(func_id);
+ switch (func_id) {
+ case BPF_FUNC_tcp_send_ack:
+ return &bpf_tcp_send_ack_proto;
+ default:
+ return bpf_base_func_proto(func_id);
+ }
}
static const struct bpf_verifier_ops bpf_tcp_ca_verifier_ops = {
--
2.17.1
next prev parent reply other threads:[~2020-01-09 0:45 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-09 0:34 [PATCH bpf-next v4 00/11] Introduce BPF STRUCT_OPS Martin KaFai Lau
2020-01-09 0:34 ` [PATCH bpf-next v4 01/11] bpf: Save PTR_TO_BTF_ID register state when spilling to stack Martin KaFai Lau
2020-01-09 0:34 ` [PATCH bpf-next v4 02/11] bpf: Avoid storing modifier to info->btf_id Martin KaFai Lau
2020-01-09 0:34 ` [PATCH bpf-next v4 03/11] bpf: Add enum support to btf_ctx_access() Martin KaFai Lau
2020-01-09 0:35 ` [PATCH bpf-next v4 04/11] bpf: Support bitfield read access in btf_struct_access Martin KaFai Lau
2020-01-09 0:35 ` [PATCH bpf-next v4 05/11] bpf: Introduce BPF_PROG_TYPE_STRUCT_OPS Martin KaFai Lau
2020-01-09 0:35 ` [PATCH bpf-next v4 06/11] bpf: Introduce BPF_MAP_TYPE_STRUCT_OPS Martin KaFai Lau
2020-01-09 0:35 ` [PATCH bpf-next v4 07/11] bpf: tcp: Support tcp_congestion_ops in bpf Martin KaFai Lau
2020-01-09 0:35 ` [PATCH bpf-next v4 08/11] bpf: Add BPF_FUNC_tcp_send_ack helper Martin KaFai Lau
2020-01-09 0:35 ` [PATCH bpf-next v4 09/11] bpf: Synch uapi bpf.h to tools/ Martin KaFai Lau
2020-01-09 0:35 ` [PATCH bpf-next v4 10/11] bpf: libbpf: Add STRUCT_OPS support Martin KaFai Lau
2020-01-09 0:35 ` [PATCH bpf-next v4 11/11] bpf: Add bpf_dctcp example Martin KaFai Lau
2020-01-09 0:44 ` [PATCH bpf-next v4 01/11] bpf: Save PTR_TO_BTF_ID register state when spilling to stack Martin KaFai Lau
2020-01-09 1:06 ` Arnaldo Carvalho de Melo
2020-01-09 5:47 ` Martin Lau
2020-01-09 13:23 ` Arnaldo Carvalho de Melo
2020-01-09 0:45 ` Martin KaFai Lau [this message]
2020-01-09 17:52 ` [PATCH bpf-next v4 00/11] Introduce BPF STRUCT_OPS Alexei Starovoitov
2020-01-09 22:36 ` Andrii Nakryiko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200109004551.3900448-1-kafai@fb.com \
--to=kafai@fb.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=kernel-team@fb.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).