Commit 91274ca5 authored by John Fastabend's avatar John Fastabend Committed by Alexei Starovoitov

bpf, sockmap: Update selftests to use skb_adjust_room

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: default avatarJohn Fastabend <john.fastabend@gmail.com>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/160160100932.7052.3646935243867660528.stgit@john-Precision-5820-Tower
parent 18ebe16d
...@@ -131,39 +131,55 @@ int bpf_prog2(struct __sk_buff *skb) ...@@ -131,39 +131,55 @@ int bpf_prog2(struct __sk_buff *skb)
} }
SEC("sk_skb3") static inline void bpf_write_pass(struct __sk_buff *skb, int offset)
int bpf_prog3(struct __sk_buff *skb)
{ {
const int one = 1; int err = bpf_skb_pull_data(skb, 6 + offset);
int err, *f, ret = SK_PASS;
void *data_end; void *data_end;
char *c; char *c;
err = bpf_skb_pull_data(skb, 19);
if (err) if (err)
goto tls_out; return;
c = (char *)(long)skb->data; c = (char *)(long)skb->data;
data_end = (void *)(long)skb->data_end; data_end = (void *)(long)skb->data_end;
if (c + 18 < data_end) if (c + 5 + offset < data_end)
memcpy(&c[13], "PASS", 4); 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); f = bpf_map_lookup_elem(&sock_skb_opts, &one);
if (f && *f) { if (f && *f) {
__u64 flags = 0; __u64 flags = 0;
ret = 0; ret = 0;
flags = *f; 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 #ifdef SOCKMAP
return bpf_sk_redirect_map(skb, &tls_sock_map, ret, flags); return bpf_sk_redirect_map(skb, &tls_sock_map, ret, flags);
#else #else
return bpf_sk_redirect_hash(skb, &tls_sock_map, &ret, flags); return bpf_sk_redirect_hash(skb, &tls_sock_map, &ret, flags);
#endif #endif
} }
f = bpf_map_lookup_elem(&sock_skb_opts, &one); f = bpf_map_lookup_elem(&sock_skb_opts, &one);
if (f && *f) if (f && *f)
ret = SK_DROP; ret = SK_DROP;
err = bpf_skb_adjust_room(skb, 4, 0, 0);
if (err)
return SK_DROP;
bpf_write_pass(skb, 13);
tls_out: tls_out:
return ret; return ret;
} }
......
...@@ -518,28 +518,13 @@ static int msg_verify_data(struct msghdr *msg, int size, int chunk_sz) ...@@ -518,28 +518,13 @@ static int msg_verify_data(struct msghdr *msg, int size, int chunk_sz)
if (i == 0 && txmsg_ktls_skb) { if (i == 0 && txmsg_ktls_skb) {
if (msg->msg_iov[i].iov_len < 4) if (msg->msg_iov[i].iov_len < 4)
return -EIO; return -EIO;
if (txmsg_ktls_skb_redir) { if (memcmp(d, "PASS", 4) != 0) {
if (memcmp(&d[13], "PASS", 4) != 0) { fprintf(stderr,
fprintf(stderr, "detected skb data error with skb ingress update @iov[%i]:%i \"%02x %02x %02x %02x\" != \"PASS\"\n",
"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]); i, 0, d[0], d[1], d[2], d[3]);
return -EIO; 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;
} }
j = 4; /* advance index past PASS header */
} }
for (; j < msg->msg_iov[i].iov_len && size; j++) { for (; j < msg->msg_iov[i].iov_len && size; j++) {
......
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