]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
bpf, sockmap: Update selftests to use skb_adjust_room
authorJohn Fastabend <john.fastabend@gmail.com>
Fri, 2 Oct 2020 01:10:09 +0000 (18:10 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 2 Oct 2020 22:18:39 +0000 (15:18 -0700)
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>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/160160100932.7052.3646935243867660528.stgit@john-Precision-5820-Tower
tools/testing/selftests/bpf/progs/test_sockmap_kern.h
tools/testing/selftests/bpf/test_sockmap.c

index 3dca4c2e24185480540fd7c283148b28ee6a08d2..1858435de7aaf91a3f2ef12e1c8a74e9ee934c4e 100644 (file)
@@ -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;
 }
index 9b6fb00dc7a06a51ced6a544117c97b94d2158ad..5cf45455de42a1163d350791ffff16f6e85cce98 100644 (file)
@@ -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++) {