diff options
author | John Fastabend <john.fastabend@gmail.com> | 2017-08-28 07:11:05 -0700 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2017-08-28 11:13:21 -0700 |
commit | 6fd28865c2a7e5ea12cb1f7ef3edee5a2042905e (patch) | |
tree | 94e1075e7705c812987453b5eb6b9ad230f20ffb /tools/testing/selftests/bpf/sockmap_verdict_prog.c | |
parent | d26e597d87635d90128fafb3f6bb0a14d972d952 (diff) | |
download | linux-6fd28865c2a7e5ea12cb1f7ef3edee5a2042905e.tar.gz linux-6fd28865c2a7e5ea12cb1f7ef3edee5a2042905e.tar.bz2 linux-6fd28865c2a7e5ea12cb1f7ef3edee5a2042905e.zip |
bpf: additional sockmap self tests
Add some more sockmap tests to cover,
- forwarding to NULL entries
- more than two maps to test list ops
- forwarding to different map
Signed-off-by: John Fastabend <john.fastabend@gmail.com>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'tools/testing/selftests/bpf/sockmap_verdict_prog.c')
-rw-r--r-- | tools/testing/selftests/bpf/sockmap_verdict_prog.c | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/tools/testing/selftests/bpf/sockmap_verdict_prog.c b/tools/testing/selftests/bpf/sockmap_verdict_prog.c index 0573c1db2519..dada2072dec5 100644 --- a/tools/testing/selftests/bpf/sockmap_verdict_prog.c +++ b/tools/testing/selftests/bpf/sockmap_verdict_prog.c @@ -12,7 +12,14 @@ int _version SEC("version") = 1; ##__VA_ARGS__); \ }) -struct bpf_map_def SEC("maps") sock_map = { +struct bpf_map_def SEC("maps") sock_map_rx = { + .type = BPF_MAP_TYPE_SOCKMAP, + .key_size = sizeof(int), + .value_size = sizeof(int), + .max_entries = 20, +}; + +struct bpf_map_def SEC("maps") sock_map_tx = { .type = BPF_MAP_TYPE_SOCKMAP, .key_size = sizeof(int), .value_size = sizeof(int), @@ -26,11 +33,15 @@ int bpf_prog2(struct __sk_buff *skb) void *data = (void *)(long) skb->data; __u32 lport = skb->local_port; __u32 rport = skb->remote_port; - char *d = data; + __u8 *d = data; + __u8 sk, map; if (data + 8 > data_end) return SK_DROP; + map = d[0]; + sk = d[1]; + d[0] = 0xd; d[1] = 0xe; d[2] = 0xa; @@ -40,9 +51,11 @@ int bpf_prog2(struct __sk_buff *skb) d[6] = 0xe; d[7] = 0xf; - bpf_printk("verdict: data[0] = (%u): local_port %i remote %i redirect 5\n", - d[0], lport, bpf_ntohl(rport)); - return bpf_sk_redirect_map(&sock_map, 5, 0); + bpf_printk("verdict: data[0] = redir(%u:%u)\n", map, sk); + + if (!map) + return bpf_sk_redirect_map(&sock_map_rx, sk, 0); + return bpf_sk_redirect_map(&sock_map_tx, sk, 0); } char _license[] SEC("license") = "GPL"; |