[PATCH] ipv4, bpf: Introduced to support the ULP to modify sockets during setopt

zhangmingyi posted 1 patch 11 months ago
net/core/filter.c | 4 ++++
1 file changed, 4 insertions(+)
[PATCH] ipv4, bpf: Introduced to support the ULP to modify sockets during setopt
Posted by zhangmingyi 11 months ago
Note that tcp_getsockopt and tcp_setsockopt support TCP_ULP, while
bpf_getsockopt and bpf_setsockopt do not support TCP_ULP.
I think we can add the handling of this case.

Signed-off-by: zhangmingyi <zhangmingyi5@huawei.com>
---
 net/core/filter.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/net/core/filter.c b/net/core/filter.c
index 713d6f454df3..f23d3f87e690 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -5383,6 +5383,10 @@ static int sol_tcp_sockopt(struct sock *sk, int optname,
 		if (*optlen < 1)
 			return -EINVAL;
 		break;
+	case TCP_ULP:
+		if (getopt)
+			return -EINVAL;
+		break;
 	case TCP_BPF_SOCK_OPS_CB_FLAGS:
 		if (*optlen != sizeof(int))
 			return -EINVAL;
-- 
2.43.0
Re: [PATCH] ipv4, bpf: Introduced to support the ULP to modify sockets during setopt
Posted by Daniel Borkmann 11 months ago
On 1/21/25 9:05 AM, zhangmingyi wrote:
> Note that tcp_getsockopt and tcp_setsockopt support TCP_ULP, while
> bpf_getsockopt and bpf_setsockopt do not support TCP_ULP.
> I think we can add the handling of this case.

Please elaborate on the use case you're trying to solve, and also a
BPF selftest is needed to back this use case up. Your latter sentence
does not sound overly sure which makes me wonder if you've tested this
code at all?

> Signed-off-by: zhangmingyi <zhangmingyi5@huawei.com>
> ---
>   net/core/filter.c | 4 ++++
>   1 file changed, 4 insertions(+)
> 
> diff --git a/net/core/filter.c b/net/core/filter.c
> index 713d6f454df3..f23d3f87e690 100644
> --- a/net/core/filter.c
> +++ b/net/core/filter.c
> @@ -5383,6 +5383,10 @@ static int sol_tcp_sockopt(struct sock *sk, int optname,
>   		if (*optlen < 1)
>   			return -EINVAL;
>   		break;
> +	case TCP_ULP:
> +		if (getopt)
> +			return -EINVAL;
> +		break;
>   	case TCP_BPF_SOCK_OPS_CB_FLAGS:
>   		if (*optlen != sizeof(int))
>   			return -EINVAL;
Re: [PATCH] ipv4, bpf: Introduced to support the ULP to modify sockets during setopt
Posted by zhangmingyi 10 months, 3 weeks ago
We want to 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 Fast Open to implement delayed connect and perform HTTP DNAT when `sendmsg`.

I'll send a patch with a full description and test cases later.

> > Signed-off-by: zhangmingyi <zhangmingyi5@huawei.com>
> > ---
> >   net/core/filter.c | 4 ++++
> >   1 file changed, 4 insertions(+)
> > 
> > diff --git a/net/core/filter.c b/net/core/filter.c
> > index 713d6f454df3..f23d3f87e690 100644
> > --- a/net/core/filter.c
> > +++ b/net/core/filter.c
> > @@ -5383,6 +5383,10 @@ static int sol_tcp_sockopt(struct sock *sk, int optname,
> >             if (*optlen < 1)
> >                     return -EINVAL;
> >             break;
> > +   case TCP_ULP:
> > +           if (getopt)
> > +                   return -EINVAL;
> > +           break;
> >     case TCP_BPF_SOCK_OPS_CB_FLAGS:
> >             if (*optlen != sizeof(int))
> >                     return -EINVAL;
>