Skip to content

Commit

Permalink
bpf, sockmap: update selftests to use skb_adjust_room
Browse files Browse the repository at this point in the history
Instead of working around TLS headers in sockmap selftests use the
new skb_adjust_room helper. This allows us to avoid special casing
the receive side to skip headers.

Signed-off-by: John Fastabend <john.fastabend@gmail.com>
  • Loading branch information
jrfastab authored and kernel-patches-bot committed Oct 2, 2020
1 parent 9f2d59e commit 8ec30c8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 30 deletions.
34 changes: 25 additions & 9 deletions tools/testing/selftests/bpf/progs/test_sockmap_kern.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,39 +131,55 @@ int bpf_prog2(struct __sk_buff *skb)

}

SEC("sk_skb3")
int bpf_prog3(struct __sk_buff *skb)
static inline void bpf_write_pass(struct __sk_buff *skb, int offset)
{
const int one = 1;
int err, *f, ret = SK_PASS;
int err = bpf_skb_pull_data(skb, 6 + offset);
void *data_end;
char *c;

err = bpf_skb_pull_data(skb, 19);
if (err)
goto tls_out;
return;

c = (char *)(long)skb->data;
data_end = (void *)(long)skb->data_end;

if (c + 18 < data_end)
memcpy(&c[13], "PASS", 4);
if (c + 5 + offset < data_end)
memcpy(c + offset, "PASS", 4);
}

SEC("sk_skb3")
int bpf_prog3(struct __sk_buff *skb)
{
int err, *f, ret = SK_PASS;
const int one = 1;

f = bpf_map_lookup_elem(&sock_skb_opts, &one);
if (f && *f) {
__u64 flags = 0;

ret = 0;
flags = *f;

err = bpf_skb_adjust_room(skb, -13, 0, 0);
if (err)
return SK_DROP;
err = bpf_skb_adjust_room(skb, 4, 0, 0);
if (err)
return SK_DROP;
bpf_write_pass(skb, 0);
#ifdef SOCKMAP
return bpf_sk_redirect_map(skb, &tls_sock_map, ret, flags);
#else
return bpf_sk_redirect_hash(skb, &tls_sock_map, &ret, flags);
#endif
}

f = bpf_map_lookup_elem(&sock_skb_opts, &one);
if (f && *f)
ret = SK_DROP;
err = bpf_skb_adjust_room(skb, 4, 0, 0);
if (err)
return SK_DROP;
bpf_write_pass(skb, 13);
tls_out:
return ret;
}
Expand Down
27 changes: 6 additions & 21 deletions tools/testing/selftests/bpf/test_sockmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -518,28 +518,13 @@ static int msg_verify_data(struct msghdr *msg, int size, int chunk_sz)
if (i == 0 && txmsg_ktls_skb) {
if (msg->msg_iov[i].iov_len < 4)
return -EIO;
if (txmsg_ktls_skb_redir) {
if (memcmp(&d[13], "PASS", 4) != 0) {
fprintf(stderr,
"detected redirect ktls_skb data error with skb ingress update @iov[%i]:%i \"%02x %02x %02x %02x\" != \"PASS\"\n", i, 0, d[13], d[14], d[15], d[16]);
return -EIO;
}
d[13] = 0;
d[14] = 1;
d[15] = 2;
d[16] = 3;
j = 13;
} else if (txmsg_ktls_skb) {
if (memcmp(d, "PASS", 4) != 0) {
fprintf(stderr,
"detected ktls_skb data error with skb ingress update @iov[%i]:%i \"%02x %02x %02x %02x\" != \"PASS\"\n", i, 0, d[0], d[1], d[2], d[3]);
return -EIO;
}
d[0] = 0;
d[1] = 1;
d[2] = 2;
d[3] = 3;
if (memcmp(d, "PASS", 4) != 0) {
fprintf(stderr,
"detected skb data error with skb ingress update @iov[%i]:%i \"%02x %02x %02x %02x\" != \"PASS\"\n",
i, 0, d[0], d[1], d[2], d[3]);
return -EIO;
}
j = 4; /* advance index past PASS header */
}

for (; j < msg->msg_iov[i].iov_len && size; j++) {
Expand Down

0 comments on commit 8ec30c8

Please sign in to comment.