[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210508220835.53801-9-xiyou.wangcong@gmail.com>
Date: Sat, 8 May 2021 15:08:31 -0700
From: Cong Wang <xiyou.wangcong@...il.com>
To: netdev@...r.kernel.org
Cc: bpf@...r.kernel.org, jiang.wang@...edance.com,
duanxiongchun@...edance.com, wangdongdong.6@...edance.com,
Cong Wang <cong.wang@...edance.com>,
John Fastabend <john.fastabend@...il.com>,
Daniel Borkmann <daniel@...earbox.net>,
Jakub Sitnicki <jakub@...udflare.com>,
Lorenz Bauer <lmb@...udflare.com>
Subject: [Patch bpf-next v4 08/12] sock_map: update sock type checks for AF_UNIX
From: Cong Wang <cong.wang@...edance.com>
Now AF_UNIX datagram supports sockmap and redirection,
we can update the sock type checks for them accordingly.
Cc: John Fastabend <john.fastabend@...il.com>
Cc: Daniel Borkmann <daniel@...earbox.net>
Cc: Jakub Sitnicki <jakub@...udflare.com>
Cc: Lorenz Bauer <lmb@...udflare.com>
Signed-off-by: Cong Wang <cong.wang@...edance.com>
---
net/core/sock_map.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/net/core/sock_map.c b/net/core/sock_map.c
index 13b474d89f93..ee9a6dfcf269 100644
--- a/net/core/sock_map.c
+++ b/net/core/sock_map.c
@@ -533,6 +533,12 @@ static bool sk_is_udp(const struct sock *sk)
sk->sk_protocol == IPPROTO_UDP;
}
+static bool sk_is_unix(const struct sock *sk)
+{
+ return sk->sk_type == SOCK_DGRAM &&
+ sk->sk_family == AF_UNIX;
+}
+
static bool sock_map_redirect_allowed(const struct sock *sk)
{
if (sk_is_tcp(sk))
@@ -552,6 +558,8 @@ static bool sock_map_sk_state_allowed(const struct sock *sk)
return (1 << sk->sk_state) & (TCPF_ESTABLISHED | TCPF_LISTEN);
else if (sk_is_udp(sk))
return sk_hashed(sk);
+ else if (sk_is_unix(sk))
+ return sk->sk_state == TCP_ESTABLISHED;
return false;
}
--
2.25.1
Powered by blists - more mailing lists