Commit 6fd92c7f authored by Menglong Dong's avatar Menglong Dong Committed by Alexei Starovoitov

bpf: selftests: Use C99 initializers in test_sock.c

Use C99 initializers for the initialization of 'tests' in test_sock.c.
Signed-off-by: default avatarMenglong Dong <imagedong@tencent.com>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20220106132022.3470772-3-imagedong@tencent.com
parent 91a760b2
...@@ -46,7 +46,7 @@ struct sock_test { ...@@ -46,7 +46,7 @@ struct sock_test {
static struct sock_test tests[] = { static struct sock_test tests[] = {
{ {
"bind4 load with invalid access: src_ip6", .descr = "bind4 load with invalid access: src_ip6",
.insns = { .insns = {
BPF_MOV64_REG(BPF_REG_6, BPF_REG_1), BPF_MOV64_REG(BPF_REG_6, BPF_REG_1),
BPF_LDX_MEM(BPF_W, BPF_REG_7, BPF_REG_6, BPF_LDX_MEM(BPF_W, BPF_REG_7, BPF_REG_6,
...@@ -54,16 +54,12 @@ static struct sock_test tests[] = { ...@@ -54,16 +54,12 @@ static struct sock_test tests[] = {
BPF_MOV64_IMM(BPF_REG_0, 1), BPF_MOV64_IMM(BPF_REG_0, 1),
BPF_EXIT_INSN(), BPF_EXIT_INSN(),
}, },
BPF_CGROUP_INET4_POST_BIND, .expected_attach_type = BPF_CGROUP_INET4_POST_BIND,
BPF_CGROUP_INET4_POST_BIND, .attach_type = BPF_CGROUP_INET4_POST_BIND,
0, .result = LOAD_REJECT,
0,
NULL,
0,
LOAD_REJECT,
}, },
{ {
"bind4 load with invalid access: mark", .descr = "bind4 load with invalid access: mark",
.insns = { .insns = {
BPF_MOV64_REG(BPF_REG_6, BPF_REG_1), BPF_MOV64_REG(BPF_REG_6, BPF_REG_1),
BPF_LDX_MEM(BPF_W, BPF_REG_7, BPF_REG_6, BPF_LDX_MEM(BPF_W, BPF_REG_7, BPF_REG_6,
...@@ -71,16 +67,12 @@ static struct sock_test tests[] = { ...@@ -71,16 +67,12 @@ static struct sock_test tests[] = {
BPF_MOV64_IMM(BPF_REG_0, 1), BPF_MOV64_IMM(BPF_REG_0, 1),
BPF_EXIT_INSN(), BPF_EXIT_INSN(),
}, },
BPF_CGROUP_INET4_POST_BIND, .expected_attach_type = BPF_CGROUP_INET4_POST_BIND,
BPF_CGROUP_INET4_POST_BIND, .attach_type = BPF_CGROUP_INET4_POST_BIND,
0, .result = LOAD_REJECT,
0,
NULL,
0,
LOAD_REJECT,
}, },
{ {
"bind6 load with invalid access: src_ip4", .descr = "bind6 load with invalid access: src_ip4",
.insns = { .insns = {
BPF_MOV64_REG(BPF_REG_6, BPF_REG_1), BPF_MOV64_REG(BPF_REG_6, BPF_REG_1),
BPF_LDX_MEM(BPF_W, BPF_REG_7, BPF_REG_6, BPF_LDX_MEM(BPF_W, BPF_REG_7, BPF_REG_6,
...@@ -88,16 +80,12 @@ static struct sock_test tests[] = { ...@@ -88,16 +80,12 @@ static struct sock_test tests[] = {
BPF_MOV64_IMM(BPF_REG_0, 1), BPF_MOV64_IMM(BPF_REG_0, 1),
BPF_EXIT_INSN(), BPF_EXIT_INSN(),
}, },
BPF_CGROUP_INET6_POST_BIND, .expected_attach_type = BPF_CGROUP_INET6_POST_BIND,
BPF_CGROUP_INET6_POST_BIND, .attach_type = BPF_CGROUP_INET6_POST_BIND,
0, .result = LOAD_REJECT,
0,
NULL,
0,
LOAD_REJECT,
}, },
{ {
"sock_create load with invalid access: src_port", .descr = "sock_create load with invalid access: src_port",
.insns = { .insns = {
BPF_MOV64_REG(BPF_REG_6, BPF_REG_1), BPF_MOV64_REG(BPF_REG_6, BPF_REG_1),
BPF_LDX_MEM(BPF_W, BPF_REG_7, BPF_REG_6, BPF_LDX_MEM(BPF_W, BPF_REG_7, BPF_REG_6,
...@@ -105,128 +93,106 @@ static struct sock_test tests[] = { ...@@ -105,128 +93,106 @@ static struct sock_test tests[] = {
BPF_MOV64_IMM(BPF_REG_0, 1), BPF_MOV64_IMM(BPF_REG_0, 1),
BPF_EXIT_INSN(), BPF_EXIT_INSN(),
}, },
BPF_CGROUP_INET_SOCK_CREATE, .expected_attach_type = BPF_CGROUP_INET_SOCK_CREATE,
BPF_CGROUP_INET_SOCK_CREATE, .attach_type = BPF_CGROUP_INET_SOCK_CREATE,
0, .result = LOAD_REJECT,
0,
NULL,
0,
LOAD_REJECT,
}, },
{ {
"sock_create load w/o expected_attach_type (compat mode)", .descr = "sock_create load w/o expected_attach_type (compat mode)",
.insns = { .insns = {
BPF_MOV64_IMM(BPF_REG_0, 1), BPF_MOV64_IMM(BPF_REG_0, 1),
BPF_EXIT_INSN(), BPF_EXIT_INSN(),
}, },
0, .expected_attach_type = 0,
BPF_CGROUP_INET_SOCK_CREATE, .attach_type = BPF_CGROUP_INET_SOCK_CREATE,
AF_INET, .domain = AF_INET,
SOCK_STREAM, .type = SOCK_STREAM,
"127.0.0.1", .ip = "127.0.0.1",
8097, .port = 8097,
SUCCESS, .result = SUCCESS,
}, },
{ {
"sock_create load w/ expected_attach_type", .descr = "sock_create load w/ expected_attach_type",
.insns = { .insns = {
BPF_MOV64_IMM(BPF_REG_0, 1), BPF_MOV64_IMM(BPF_REG_0, 1),
BPF_EXIT_INSN(), BPF_EXIT_INSN(),
}, },
BPF_CGROUP_INET_SOCK_CREATE, .expected_attach_type = BPF_CGROUP_INET_SOCK_CREATE,
BPF_CGROUP_INET_SOCK_CREATE, .attach_type = BPF_CGROUP_INET_SOCK_CREATE,
AF_INET, .domain = AF_INET,
SOCK_STREAM, .type = SOCK_STREAM,
"127.0.0.1", .ip = "127.0.0.1",
8097, .port = 8097,
SUCCESS, .result = SUCCESS,
}, },
{ {
"attach type mismatch bind4 vs bind6", .descr = "attach type mismatch bind4 vs bind6",
.insns = { .insns = {
BPF_MOV64_IMM(BPF_REG_0, 1), BPF_MOV64_IMM(BPF_REG_0, 1),
BPF_EXIT_INSN(), BPF_EXIT_INSN(),
}, },
BPF_CGROUP_INET4_POST_BIND, .expected_attach_type = BPF_CGROUP_INET4_POST_BIND,
BPF_CGROUP_INET6_POST_BIND, .attach_type = BPF_CGROUP_INET6_POST_BIND,
0, .result = ATTACH_REJECT,
0,
NULL,
0,
ATTACH_REJECT,
}, },
{ {
"attach type mismatch bind6 vs bind4", .descr = "attach type mismatch bind6 vs bind4",
.insns = { .insns = {
BPF_MOV64_IMM(BPF_REG_0, 1), BPF_MOV64_IMM(BPF_REG_0, 1),
BPF_EXIT_INSN(), BPF_EXIT_INSN(),
}, },
BPF_CGROUP_INET6_POST_BIND, .expected_attach_type = BPF_CGROUP_INET6_POST_BIND,
BPF_CGROUP_INET4_POST_BIND, .attach_type = BPF_CGROUP_INET4_POST_BIND,
0, .result = ATTACH_REJECT,
0,
NULL,
0,
ATTACH_REJECT,
}, },
{ {
"attach type mismatch default vs bind4", .descr = "attach type mismatch default vs bind4",
.insns = { .insns = {
BPF_MOV64_IMM(BPF_REG_0, 1), BPF_MOV64_IMM(BPF_REG_0, 1),
BPF_EXIT_INSN(), BPF_EXIT_INSN(),
}, },
0, .expected_attach_type = 0,
BPF_CGROUP_INET4_POST_BIND, .attach_type = BPF_CGROUP_INET4_POST_BIND,
0, .result = ATTACH_REJECT,
0,
NULL,
0,
ATTACH_REJECT,
}, },
{ {
"attach type mismatch bind6 vs sock_create", .descr = "attach type mismatch bind6 vs sock_create",
.insns = { .insns = {
BPF_MOV64_IMM(BPF_REG_0, 1), BPF_MOV64_IMM(BPF_REG_0, 1),
BPF_EXIT_INSN(), BPF_EXIT_INSN(),
}, },
BPF_CGROUP_INET6_POST_BIND, .expected_attach_type = BPF_CGROUP_INET6_POST_BIND,
BPF_CGROUP_INET_SOCK_CREATE, .attach_type = BPF_CGROUP_INET_SOCK_CREATE,
0, .result = ATTACH_REJECT,
0,
NULL,
0,
ATTACH_REJECT,
}, },
{ {
"bind4 reject all", .descr = "bind4 reject all",
.insns = { .insns = {
BPF_MOV64_IMM(BPF_REG_0, 0), BPF_MOV64_IMM(BPF_REG_0, 0),
BPF_EXIT_INSN(), BPF_EXIT_INSN(),
}, },
BPF_CGROUP_INET4_POST_BIND, .expected_attach_type = BPF_CGROUP_INET4_POST_BIND,
BPF_CGROUP_INET4_POST_BIND, .attach_type = BPF_CGROUP_INET4_POST_BIND,
AF_INET, .domain = AF_INET,
SOCK_STREAM, .type = SOCK_STREAM,
"0.0.0.0", .ip = "0.0.0.0",
0, .result = BIND_REJECT,
BIND_REJECT,
}, },
{ {
"bind6 reject all", .descr = "bind6 reject all",
.insns = { .insns = {
BPF_MOV64_IMM(BPF_REG_0, 0), BPF_MOV64_IMM(BPF_REG_0, 0),
BPF_EXIT_INSN(), BPF_EXIT_INSN(),
}, },
BPF_CGROUP_INET6_POST_BIND, .expected_attach_type = BPF_CGROUP_INET6_POST_BIND,
BPF_CGROUP_INET6_POST_BIND, .attach_type = BPF_CGROUP_INET6_POST_BIND,
AF_INET6, .domain = AF_INET6,
SOCK_STREAM, .type = SOCK_STREAM,
"::", .ip = "::",
0, .result = BIND_REJECT,
BIND_REJECT,
}, },
{ {
"bind6 deny specific IP & port", .descr = "bind6 deny specific IP & port",
.insns = { .insns = {
BPF_MOV64_REG(BPF_REG_6, BPF_REG_1), BPF_MOV64_REG(BPF_REG_6, BPF_REG_1),
...@@ -247,16 +213,16 @@ static struct sock_test tests[] = { ...@@ -247,16 +213,16 @@ static struct sock_test tests[] = {
BPF_MOV64_IMM(BPF_REG_0, 1), BPF_MOV64_IMM(BPF_REG_0, 1),
BPF_EXIT_INSN(), BPF_EXIT_INSN(),
}, },
BPF_CGROUP_INET6_POST_BIND, .expected_attach_type = BPF_CGROUP_INET6_POST_BIND,
BPF_CGROUP_INET6_POST_BIND, .attach_type = BPF_CGROUP_INET6_POST_BIND,
AF_INET6, .domain = AF_INET6,
SOCK_STREAM, .type = SOCK_STREAM,
"::1", .ip = "::1",
8193, .port = 8193,
BIND_REJECT, .result = BIND_REJECT,
}, },
{ {
"bind4 allow specific IP & port", .descr = "bind4 allow specific IP & port",
.insns = { .insns = {
BPF_MOV64_REG(BPF_REG_6, BPF_REG_1), BPF_MOV64_REG(BPF_REG_6, BPF_REG_1),
...@@ -277,41 +243,39 @@ static struct sock_test tests[] = { ...@@ -277,41 +243,39 @@ static struct sock_test tests[] = {
BPF_MOV64_IMM(BPF_REG_0, 0), BPF_MOV64_IMM(BPF_REG_0, 0),
BPF_EXIT_INSN(), BPF_EXIT_INSN(),
}, },
BPF_CGROUP_INET4_POST_BIND, .expected_attach_type = BPF_CGROUP_INET4_POST_BIND,
BPF_CGROUP_INET4_POST_BIND, .attach_type = BPF_CGROUP_INET4_POST_BIND,
AF_INET, .domain = AF_INET,
SOCK_STREAM, .type = SOCK_STREAM,
"127.0.0.1", .ip = "127.0.0.1",
4098, .port = 4098,
SUCCESS, .result = SUCCESS,
}, },
{ {
"bind4 allow all", .descr = "bind4 allow all",
.insns = { .insns = {
BPF_MOV64_IMM(BPF_REG_0, 1), BPF_MOV64_IMM(BPF_REG_0, 1),
BPF_EXIT_INSN(), BPF_EXIT_INSN(),
}, },
BPF_CGROUP_INET4_POST_BIND, .expected_attach_type = BPF_CGROUP_INET4_POST_BIND,
BPF_CGROUP_INET4_POST_BIND, .attach_type = BPF_CGROUP_INET4_POST_BIND,
AF_INET, .domain = AF_INET,
SOCK_STREAM, .type = SOCK_STREAM,
"0.0.0.0", .ip = "0.0.0.0",
0, .result = SUCCESS,
SUCCESS,
}, },
{ {
"bind6 allow all", .descr = "bind6 allow all",
.insns = { .insns = {
BPF_MOV64_IMM(BPF_REG_0, 1), BPF_MOV64_IMM(BPF_REG_0, 1),
BPF_EXIT_INSN(), BPF_EXIT_INSN(),
}, },
BPF_CGROUP_INET6_POST_BIND, .expected_attach_type = BPF_CGROUP_INET6_POST_BIND,
BPF_CGROUP_INET6_POST_BIND, .attach_type = BPF_CGROUP_INET6_POST_BIND,
AF_INET6, .domain = AF_INET6,
SOCK_STREAM, .type = SOCK_STREAM,
"::", .ip = "::",
0, .result = SUCCESS,
SUCCESS,
}, },
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment