Re: [PATCH v3 net-next 2/2] bpf: selftests: add bind retry for post_bind{4, 6}
From: Menglong Dong <hidden>
Date: 2022-01-05 14:46:04
Also in:
bpf, linux-kselftest, lkml
On Wed, Jan 5, 2022 at 9:57 PM Eric Dumazet [off-list ref] wrote:
On Wed, Jan 5, 2022 at 5:21 AM [off-list ref] wrote:quoted
From: Menglong Dong <redacted> With previous patch, kernel is able to 'put_port' after sys_bind() fails. Add the test for that case: rebind another port after sys_bind() fails. If the bind success, it means previous bind operation is already undoed. Signed-off-by: Menglong Dong <redacted> --- tools/testing/selftests/bpf/test_sock.c | 166 +++++++++++++++++++++--- 1 file changed, 146 insertions(+), 20 deletions(-)diff --git a/tools/testing/selftests/bpf/test_sock.c b/tools/testing/selftests/bpf/test_sock.c index e8edd3dd3ec2..68525d68d4e5 100644 --- a/tools/testing/selftests/bpf/test_sock.c +++ b/tools/testing/selftests/bpf/test_sock.c@@ -35,12 +35,15 @@ struct sock_test { /* Endpoint to bind() to */ const char *ip; unsigned short port; + unsigned short port_retry; /* Expected test result */ enum { LOAD_REJECT, ATTACH_REJECT, BIND_REJECT, SUCCESS, + RETRY_SUCCESS, + RETRY_REJECT } result; };@@ -60,6 +63,7 @@ static struct sock_test tests[] = { 0, NULL, 0, + 0, LOAD_REJECT, },I assume we tried C99 initializers here, and this failed for some reason ?
Yeah, C99 initializers should be a good choice here, therefore I don't need to change every entry here after I add a new field to 'struct sock_test'. I think C99 initializers should work here, I'll give it a try. Thanks! Menglong Dong
quoted hunk ↗ jump to hunk
diff --git a/tools/testing/selftests/bpf/test_sock.cb/tools/testing/selftests/bpf/test_sock.c index e8edd3dd3ec2..b57ce9f3eabf 100644--- a/tools/testing/selftests/bpf/test_sock.c +++ b/tools/testing/selftests/bpf/test_sock.c@@ -54,13 +54,13 @@ static struct sock_test tests[] = { BPF_MOV64_IMM(BPF_REG_0, 1), BPF_EXIT_INSN(), }, - BPF_CGROUP_INET4_POST_BIND, - BPF_CGROUP_INET4_POST_BIND, - 0, - 0, - NULL, - 0, - LOAD_REJECT, + .expected_attach_type = BPF_CGROUP_INET4_POST_BIND, + .attach_type = BPF_CGROUP_INET4_POST_BIND, + .domain = 0, + .type = 0, + .ip = NULL, + .port = 0, + .result = LOAD_REJECT, }, { "bind4 load with invalid access: mark",