From: Tony Lu <tonylu@linux.alibaba.com>
To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org
Cc: bpf@vger.kernel.org, netdev@vger.kernel.org
Subject: [PATCH bpf-next 2/2] bpf: Introduce TCP_ULP option for bpf_{set,get}sockopt
Date: Thu, 9 Dec 2021 17:02:51 +0800 [thread overview]
Message-ID: <20211209090250.73927-3-tonylu@linux.alibaba.com> (raw)
In-Reply-To: <20211209090250.73927-1-tonylu@linux.alibaba.com>
This introduces a new option TCP_ULP for bpf_{set,get}sockopt helper. It
helps prog to change TCP_ULP sockopt on demand.
People who want to set ULP based on strategies when socket create or
other's hook point, they can attach to BPF_CGROUP_INET_SOCK_CREATE or
other types, and judge based on user-defined rules to trigger
bpf_set_sockopt(.., IPPROTO_TCP, TCP_ULP) and set socket ULP. For
example, the bpf prog can control which socket should use tls ULP
modules without intrusively modifying the applications.
With this, it makes flexible to control ULP strategies with BPF prog.
Signed-off-by: Tony Lu <tonylu@linux.alibaba.com>
Reviewed-by: Qiao Ma <mqaio@linux.alibaba.com>
---
include/uapi/linux/bpf.h | 3 ++-
net/core/filter.c | 16 ++++++++++++++++
tools/include/uapi/linux/bpf.h | 3 ++-
3 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index c26871263f1f..7372283f92be 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -2505,7 +2505,8 @@ union bpf_attr {
* **TCP_CONGESTION**, **TCP_BPF_IW**,
* **TCP_BPF_SNDCWND_CLAMP**, **TCP_SAVE_SYN**,
* **TCP_KEEPIDLE**, **TCP_KEEPINTVL**, **TCP_KEEPCNT**,
- * **TCP_SYNCNT**, **TCP_USER_TIMEOUT**, **TCP_NOTSENT_LOWAT**.
+ * **TCP_SYNCNT**, **TCP_USER_TIMEOUT**, **TCP_NOTSENT_LOWAT**,
+ * **TCP_ULP**.
* * **IPPROTO_IP**, which supports *optname* **IP_TOS**.
* * **IPPROTO_IPV6**, which supports *optname* **IPV6_TCLASS**.
* Return
diff --git a/net/core/filter.c b/net/core/filter.c
index 1e6b68ff13db..88d7f047f9c0 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -4870,6 +4870,14 @@ static int _bpf_setsockopt(struct sock *sk, int level, int optname,
name[TCP_CA_NAME_MAX-1] = 0;
return tcp_set_congestion_control(sk, name, false, true);
}
+ case TCP_ULP: {
+ char name[TCP_ULP_NAME_MAX];
+
+ strncpy(name, optval, min_t(long, optlen,
+ TCP_ULP_NAME_MAX - 1));
+ name[TCP_ULP_NAME_MAX - 1] = 0;
+ return tcp_set_ulp(sk, name);
+ }
default:
break;
}
@@ -5000,6 +5008,14 @@ static int _bpf_getsockopt(struct sock *sk, int level, int optname,
strncpy(optval, icsk->icsk_ca_ops->name, optlen);
optval[optlen - 1] = 0;
break;
+ case TCP_ULP:
+ icsk = inet_csk(sk);
+
+ if (!icsk->icsk_ulp_ops || optlen <= 1)
+ goto err_clear;
+ strncpy(optval, icsk->icsk_ulp_ops->name, optlen);
+ optval[optlen - 1] = 0;
+ break;
case TCP_SAVED_SYN:
tp = tcp_sk(sk);
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index c26871263f1f..7372283f92be 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -2505,7 +2505,8 @@ union bpf_attr {
* **TCP_CONGESTION**, **TCP_BPF_IW**,
* **TCP_BPF_SNDCWND_CLAMP**, **TCP_SAVE_SYN**,
* **TCP_KEEPIDLE**, **TCP_KEEPINTVL**, **TCP_KEEPCNT**,
- * **TCP_SYNCNT**, **TCP_USER_TIMEOUT**, **TCP_NOTSENT_LOWAT**.
+ * **TCP_SYNCNT**, **TCP_USER_TIMEOUT**, **TCP_NOTSENT_LOWAT**,
+ * **TCP_ULP**.
* * **IPPROTO_IP**, which supports *optname* **IP_TOS**.
* * **IPPROTO_IPV6**, which supports *optname* **IPV6_TCLASS**.
* Return
--
2.32.0.3.g01195cf9f
next prev parent reply other threads:[~2021-12-09 9:03 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-09 9:02 [PATCH bpf-next 0/2] Introduce TCP_ULP option for bpf_{set,get}sockopt Tony Lu
2021-12-09 9:02 ` [PATCH bpf-next 1/2] bpf: Use switch statement in _bpf_setsockopt Tony Lu
2021-12-09 9:02 ` Tony Lu [this message]
2021-12-09 19:27 ` [PATCH bpf-next 0/2] Introduce TCP_ULP option for bpf_{set,get}sockopt John Fastabend
2021-12-10 2:54 ` Tony Lu
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=20211209090250.73927-3-tonylu@linux.alibaba.com \
--to=tonylu@linux.alibaba.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--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).