On 1/27/25 1:07 AM, zhangmingyi wrote:
> We want call bpf_setsockopt to replace the kernel module in the TCP_ULP
> case. The purpose is to customize the behavior in connect and sendmsg.
> We have an open source community project kmesh (kmesh.net). Based on
> this, we refer to some processes of tcp fastopen to implement delayed
> connet and perform HTTP DNAT when sendmsg.In this case, we need to parse
> HTTP packets in the bpf program and set TCP_ULP for the specified socket.
The ulp could be a kernel module. Which ulp is needed in your use case?
> Note that tcp_getsockopt and tcp_setsockopt support TCP_ULP, while
> bpf_getsockopt and bpf_setsockopt do not support TCP_ULP.
> I'm not sure why there is such a difference, but I noticed that
You are right that bpf_get/setsockopt should be able to support most of the
TCP_* optname.
After looking at tcp_set_ulp, I believe TCP_ULP is one of the few exceptions. I
didn't drill down further and I stopped at __tcp_ulp_find_autoload which I
believe it might_sleep. The BPF programs that support bpf_setsockopt cannot
sleep. Take a look at how do_tcp_setsockopt(TCP_CONGESTION) is done.
pw-bot: cr
> tcp_setsockopt is called in bpf_setsockopt.I think we can add the
> handling of this case.
>
> zhangmingyi (2):
> ipv4, bpf: Introduced to support the ULP to get or set sockets
> add selftest for TCP_ULP in bpf_setsockopt
>
> net/core/filter.c | 1 +
> .../selftests/bpf/progs/setget_sockopt.c | 21 ++++++++++++++++---
> 2 files changed, 19 insertions(+), 3 deletions(-)
>