2021-08-09 21:38:05

by Jiang Wang .

[permalink] [raw]
Subject: [PATCH bpf-next v6 0/5] sockmap: add sockmap support for unix stream socket

This patch series add support for unix stream type
for sockmap. Sockmap already supports TCP, UDP,
unix dgram types. The unix stream support is similar
to unix dgram.

Also add selftests for unix stream type in sockmap tests.


Jiang Wang (5):
af_unix: add read_sock for stream socket types
af_unix: add unix_stream_proto for sockmap
selftest/bpf: add tests for sockmap with unix stream type.
selftest/bpf: change udp to inet in some function names
selftest/bpf: add new tests in sockmap for unix stream to tcp.

include/net/af_unix.h | 8 +-
net/unix/af_unix.c | 91 +++++++++++++++---
net/unix/unix_bpf.c | 93 ++++++++++++++-----
.../selftests/bpf/prog_tests/sockmap_listen.c | 48 ++++++----
4 files changed, 187 insertions(+), 53 deletions(-)

v1 -> v2 :
- Call unhash in shutdown.
- Clean up unix_create1 a bit.
- Return -ENOTCONN if socket is not connected.

v2 -> v3 :
- check for stream type in update_proto
- remove intermediate variable in __unix_stream_recvmsg
- fix compile warning in unix_stream_recvmsg

v3 -> v4 :
- remove sk_is_unix_stream, just check TCP_ESTABLISHED for UNIX sockets.
- add READ_ONCE in unix_dgram_recvmsg
- remove type check in unix_stream_bpf_update_proto

v4 -> v5 :
- add two missing READ_ONCE for sk_prot.

v5 -> v6 :
- fix READ_ONCE by reading to a local variable first.

--
2.20.1


2021-08-09 21:38:16

by Jiang Wang .

[permalink] [raw]
Subject: [PATCH bpf-next v6 3/5] selftest/bpf: add tests for sockmap with unix stream type.

Add two tests for unix stream to unix stream redirection
in sockmap tests.

Signed-off-by: Jiang Wang <[email protected]>
Reviewed-by: Cong Wang <[email protected]>
Acked-by: John Fastabend <[email protected]>
---
tools/testing/selftests/bpf/prog_tests/sockmap_listen.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/tools/testing/selftests/bpf/prog_tests/sockmap_listen.c b/tools/testing/selftests/bpf/prog_tests/sockmap_listen.c
index a9f1bf9d5dff..7a976d43281a 100644
--- a/tools/testing/selftests/bpf/prog_tests/sockmap_listen.c
+++ b/tools/testing/selftests/bpf/prog_tests/sockmap_listen.c
@@ -2020,11 +2020,13 @@ void test_sockmap_listen(void)
run_tests(skel, skel->maps.sock_map, AF_INET);
run_tests(skel, skel->maps.sock_map, AF_INET6);
test_unix_redir(skel, skel->maps.sock_map, SOCK_DGRAM);
+ test_unix_redir(skel, skel->maps.sock_map, SOCK_STREAM);

skel->bss->test_sockmap = false;
run_tests(skel, skel->maps.sock_hash, AF_INET);
run_tests(skel, skel->maps.sock_hash, AF_INET6);
test_unix_redir(skel, skel->maps.sock_hash, SOCK_DGRAM);
+ test_unix_redir(skel, skel->maps.sock_hash, SOCK_STREAM);

test_sockmap_listen__destroy(skel);
}
--
2.20.1

2021-08-09 21:38:55

by Jiang Wang .

[permalink] [raw]
Subject: [PATCH bpf-next v6 5/5] selftest/bpf: add new tests in sockmap for unix stream to tcp.

Add two new test cases in sockmap tests, where unix stream is
redirected to tcp and vice versa.

Signed-off-by: Jiang Wang <[email protected]>
Reviewed-by: Cong Wang <[email protected]>
Acked-by: John Fastabend <[email protected]>
---
.../selftests/bpf/prog_tests/sockmap_listen.c | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/sockmap_listen.c b/tools/testing/selftests/bpf/prog_tests/sockmap_listen.c
index 07ed8081f9ae..afa14fb66f08 100644
--- a/tools/testing/selftests/bpf/prog_tests/sockmap_listen.c
+++ b/tools/testing/selftests/bpf/prog_tests/sockmap_listen.c
@@ -1884,7 +1884,7 @@ static void inet_unix_redir_to_connected(int family, int type, int sock_mapfd,
xclose(p0);
}

-static void udp_unix_skb_redir_to_connected(struct test_sockmap_listen *skel,
+static void inet_unix_skb_redir_to_connected(struct test_sockmap_listen *skel,
struct bpf_map *inner_map, int family)
{
int verdict = bpf_program__fd(skel->progs.prog_skb_verdict);
@@ -1899,9 +1899,13 @@ static void udp_unix_skb_redir_to_connected(struct test_sockmap_listen *skel,
skel->bss->test_ingress = false;
inet_unix_redir_to_connected(family, SOCK_DGRAM, sock_map, verdict_map,
REDIR_EGRESS);
+ inet_unix_redir_to_connected(family, SOCK_STREAM, sock_map, verdict_map,
+ REDIR_EGRESS);
skel->bss->test_ingress = true;
inet_unix_redir_to_connected(family, SOCK_DGRAM, sock_map, verdict_map,
REDIR_INGRESS);
+ inet_unix_redir_to_connected(family, SOCK_STREAM, sock_map, verdict_map,
+ REDIR_INGRESS);

xbpf_prog_detach2(verdict, sock_map, BPF_SK_SKB_VERDICT);
}
@@ -1961,7 +1965,7 @@ static void unix_inet_redir_to_connected(int family, int type, int sock_mapfd,

}

-static void unix_udp_skb_redir_to_connected(struct test_sockmap_listen *skel,
+static void unix_inet_skb_redir_to_connected(struct test_sockmap_listen *skel,
struct bpf_map *inner_map, int family)
{
int verdict = bpf_program__fd(skel->progs.prog_skb_verdict);
@@ -1976,9 +1980,13 @@ static void unix_udp_skb_redir_to_connected(struct test_sockmap_listen *skel,
skel->bss->test_ingress = false;
unix_inet_redir_to_connected(family, SOCK_DGRAM, sock_map, verdict_map,
REDIR_EGRESS);
+ unix_inet_redir_to_connected(family, SOCK_STREAM, sock_map, verdict_map,
+ REDIR_EGRESS);
skel->bss->test_ingress = true;
unix_inet_redir_to_connected(family, SOCK_DGRAM, sock_map, verdict_map,
REDIR_INGRESS);
+ unix_inet_redir_to_connected(family, SOCK_STREAM, sock_map, verdict_map,
+ REDIR_INGRESS);

xbpf_prog_detach2(verdict, sock_map, BPF_SK_SKB_VERDICT);
}
@@ -1994,8 +2002,8 @@ static void test_udp_unix_redir(struct test_sockmap_listen *skel, struct bpf_map
snprintf(s, sizeof(s), "%s %s %s", map_name, family_name, __func__);
if (!test__start_subtest(s))
return;
- udp_unix_skb_redir_to_connected(skel, map, family);
- unix_udp_skb_redir_to_connected(skel, map, family);
+ inet_unix_skb_redir_to_connected(skel, map, family);
+ unix_inet_skb_redir_to_connected(skel, map, family);
}

static void run_tests(struct test_sockmap_listen *skel, struct bpf_map *map,
--
2.20.1

2021-08-10 18:56:37

by John Fastabend

[permalink] [raw]
Subject: RE: [PATCH bpf-next v6 0/5] sockmap: add sockmap support for unix stream socket

Jiang Wang wrote:
> This patch series add support for unix stream type
> for sockmap. Sockmap already supports TCP, UDP,
> unix dgram types. The unix stream support is similar
> to unix dgram.
>
> Also add selftests for unix stream type in sockmap tests.
>
>
> Jiang Wang (5):
> af_unix: add read_sock for stream socket types
> af_unix: add unix_stream_proto for sockmap
> selftest/bpf: add tests for sockmap with unix stream type.
> selftest/bpf: change udp to inet in some function names
> selftest/bpf: add new tests in sockmap for unix stream to tcp.

For the series.

Acked-by: John Fastabend <[email protected]>

2021-08-12 07:51:49

by Jakub Sitnicki

[permalink] [raw]
Subject: Re: [PATCH bpf-next v6 0/5] sockmap: add sockmap support for unix stream socket

On Mon, Aug 09, 2021 at 09:47 PM CEST, Jiang Wang wrote:
> This patch series add support for unix stream type
> for sockmap. Sockmap already supports TCP, UDP,
> unix dgram types. The unix stream support is similar
> to unix dgram.
>
> Also add selftests for unix stream type in sockmap tests.
>
>
> Jiang Wang (5):
> af_unix: add read_sock for stream socket types
> af_unix: add unix_stream_proto for sockmap
> selftest/bpf: add tests for sockmap with unix stream type.
> selftest/bpf: change udp to inet in some function names
> selftest/bpf: add new tests in sockmap for unix stream to tcp.
>
> include/net/af_unix.h | 8 +-
> net/unix/af_unix.c | 91 +++++++++++++++---
> net/unix/unix_bpf.c | 93 ++++++++++++++-----
> .../selftests/bpf/prog_tests/sockmap_listen.c | 48 ++++++----
> 4 files changed, 187 insertions(+), 53 deletions(-)
>
> v1 -> v2 :
> - Call unhash in shutdown.
> - Clean up unix_create1 a bit.
> - Return -ENOTCONN if socket is not connected.
>
> v2 -> v3 :
> - check for stream type in update_proto
> - remove intermediate variable in __unix_stream_recvmsg
> - fix compile warning in unix_stream_recvmsg
>
> v3 -> v4 :
> - remove sk_is_unix_stream, just check TCP_ESTABLISHED for UNIX sockets.
> - add READ_ONCE in unix_dgram_recvmsg
> - remove type check in unix_stream_bpf_update_proto
>
> v4 -> v5 :
> - add two missing READ_ONCE for sk_prot.
>
> v5 -> v6 :
> - fix READ_ONCE by reading to a local variable first.

For the series:

Acked-by: Jakub Sitnicki <[email protected]>

2021-08-13 22:47:48

by Andrii Nakryiko

[permalink] [raw]
Subject: Re: [PATCH bpf-next v6 0/5] sockmap: add sockmap support for unix stream socket

On Mon, Aug 9, 2021 at 12:47 PM Jiang Wang <[email protected]> wrote:
>
> This patch series add support for unix stream type
> for sockmap. Sockmap already supports TCP, UDP,
> unix dgram types. The unix stream support is similar
> to unix dgram.
>
> Also add selftests for unix stream type in sockmap tests.
>

Hey Jiang,

This patch doesn't apply cleanly to bpf-next anymore ([0]), can you
please rebase and resubmit, adding John's and Jakub's acks along the
way? Thanks!

[0] https://github.com/kernel-patches/bpf/pull/1563#issuecomment-896128082

>
> Jiang Wang (5):
> af_unix: add read_sock for stream socket types
> af_unix: add unix_stream_proto for sockmap
> selftest/bpf: add tests for sockmap with unix stream type.
> selftest/bpf: change udp to inet in some function names
> selftest/bpf: add new tests in sockmap for unix stream to tcp.
>
> include/net/af_unix.h | 8 +-
> net/unix/af_unix.c | 91 +++++++++++++++---
> net/unix/unix_bpf.c | 93 ++++++++++++++-----
> .../selftests/bpf/prog_tests/sockmap_listen.c | 48 ++++++----
> 4 files changed, 187 insertions(+), 53 deletions(-)
>
> v1 -> v2 :
> - Call unhash in shutdown.
> - Clean up unix_create1 a bit.
> - Return -ENOTCONN if socket is not connected.
>
> v2 -> v3 :
> - check for stream type in update_proto
> - remove intermediate variable in __unix_stream_recvmsg
> - fix compile warning in unix_stream_recvmsg
>
> v3 -> v4 :
> - remove sk_is_unix_stream, just check TCP_ESTABLISHED for UNIX sockets.
> - add READ_ONCE in unix_dgram_recvmsg
> - remove type check in unix_stream_bpf_update_proto
>
> v4 -> v5 :
> - add two missing READ_ONCE for sk_prot.
>
> v5 -> v6 :
> - fix READ_ONCE by reading to a local variable first.
>
> --
> 2.20.1
>

2021-08-14 04:34:47

by Jiang Wang .

[permalink] [raw]
Subject: Re: Re: [PATCH bpf-next v6 0/5] sockmap: add sockmap support for unix stream socket

On Fri, Aug 13, 2021 at 3:42 PM Andrii Nakryiko
<[email protected]> wrote:
>
> On Mon, Aug 9, 2021 at 12:47 PM Jiang Wang <[email protected]> wrote:
> >
> > This patch series add support for unix stream type
> > for sockmap. Sockmap already supports TCP, UDP,
> > unix dgram types. The unix stream support is similar
> > to unix dgram.
> >
> > Also add selftests for unix stream type in sockmap tests.
> >
>
> Hey Jiang,
>
> This patch doesn't apply cleanly to bpf-next anymore ([0]), can you
> please rebase and resubmit, adding John's and Jakub's acks along the
> way? Thanks!
>

Sure, I just rebased, added ack and sent the patch again with the same title.
Let me know if there is any problem. Thanks.


> [0] https://github.com/kernel-patches/bpf/pull/1563#issuecomment-896128082
>
> >
> > Jiang Wang (5):
> > af_unix: add read_sock for stream socket types
> > af_unix: add unix_stream_proto for sockmap
> > selftest/bpf: add tests for sockmap with unix stream type.
> > selftest/bpf: change udp to inet in some function names
> > selftest/bpf: add new tests in sockmap for unix stream to tcp.
> >
> > include/net/af_unix.h | 8 +-
> > net/unix/af_unix.c | 91 +++++++++++++++---
> > net/unix/unix_bpf.c | 93 ++++++++++++++-----
> > .../selftests/bpf/prog_tests/sockmap_listen.c | 48 ++++++----
> > 4 files changed, 187 insertions(+), 53 deletions(-)
> >
> > v1 -> v2 :
> > - Call unhash in shutdown.
> > - Clean up unix_create1 a bit.
> > - Return -ENOTCONN if socket is not connected.
> >
> > v2 -> v3 :
> > - check for stream type in update_proto
> > - remove intermediate variable in __unix_stream_recvmsg
> > - fix compile warning in unix_stream_recvmsg
> >
> > v3 -> v4 :
> > - remove sk_is_unix_stream, just check TCP_ESTABLISHED for UNIX sockets.
> > - add READ_ONCE in unix_dgram_recvmsg
> > - remove type check in unix_stream_bpf_update_proto
> >
> > v4 -> v5 :
> > - add two missing READ_ONCE for sk_prot.
> >
> > v5 -> v6 :
> > - fix READ_ONCE by reading to a local variable first.
> >
> > --
> > 2.20.1
> >