diff mbox series

[bpf-next,v2,8/9] sock_map: update sock type checks for UDP

Message ID 20210302023743.24123-9-xiyou.wangcong@gmail.com
State Superseded
Headers show
Series sockmap: introduce BPF_SK_SKB_VERDICT and support UDP | expand

Commit Message

Cong Wang March 2, 2021, 2:37 a.m. UTC
From: Cong Wang <cong.wang@bytedance.com>

Now UDP supports sockmap and redirection, we can safely update
the sock type checks for it accordingly.

Cc: John Fastabend <john.fastabend@gmail.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Jakub Sitnicki <jakub@cloudflare.com>
Cc: Lorenz Bauer <lmb@cloudflare.com>
Signed-off-by: Cong Wang <cong.wang@bytedance.com>
---
 net/core/sock_map.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Yonghong Song March 3, 2021, 6:37 a.m. UTC | #1
On 3/1/21 6:37 PM, Cong Wang wrote:
> From: Cong Wang <cong.wang@bytedance.com>

> 

> Now UDP supports sockmap and redirection, we can safely update

> the sock type checks for it accordingly.

> 

> Cc: John Fastabend <john.fastabend@gmail.com>

> Cc: Daniel Borkmann <daniel@iogearbox.net>

> Cc: Jakub Sitnicki <jakub@cloudflare.com>

> Cc: Lorenz Bauer <lmb@cloudflare.com>

> Signed-off-by: Cong Wang <cong.wang@bytedance.com>

> ---

>   net/core/sock_map.c | 5 ++++-

>   1 file changed, 4 insertions(+), 1 deletion(-)

> 

> diff --git a/net/core/sock_map.c b/net/core/sock_map.c

> index 13d2af5bb81c..f7eee4b7b994 100644

> --- a/net/core/sock_map.c

> +++ b/net/core/sock_map.c

> @@ -549,7 +549,10 @@ static bool sk_is_udp(const struct sock *sk)

>   

>   static bool sock_map_redirect_allowed(const struct sock *sk)

>   {

> -	return sk_is_tcp(sk) && sk->sk_state != TCP_LISTEN;

> +	if (sk_is_tcp(sk))

> +		return sk->sk_state != TCP_LISTEN;

> +	else

> +		return sk->sk_state == TCP_ESTABLISHED;


Not a networking expert, a dump question. Here we tested
whether sk_is_tcp(sk) or not, if not we compare
sk->sk_state == TCP_ESTABLISHED, could this be
always false? Mostly I missed something, some comments
here will be good.

>   }

>   

>   static bool sock_map_sk_is_suitable(const struct sock *sk)

>
diff mbox series

Patch

diff --git a/net/core/sock_map.c b/net/core/sock_map.c
index 13d2af5bb81c..f7eee4b7b994 100644
--- a/net/core/sock_map.c
+++ b/net/core/sock_map.c
@@ -549,7 +549,10 @@  static bool sk_is_udp(const struct sock *sk)
 
 static bool sock_map_redirect_allowed(const struct sock *sk)
 {
-	return sk_is_tcp(sk) && sk->sk_state != TCP_LISTEN;
+	if (sk_is_tcp(sk))
+		return sk->sk_state != TCP_LISTEN;
+	else
+		return sk->sk_state == TCP_ESTABLISHED;
 }
 
 static bool sock_map_sk_is_suitable(const struct sock *sk)