bpf, selftests: Add option to test_sockmap to omit adding parser program
authorJohn Fastabend <john.fastabend@gmail.com>
Sun, 11 Oct 2020 05:10:04 +0000 (22:10 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Mon, 12 Oct 2020 01:09:44 +0000 (18:09 -0700)
Add option to allow running without a parser program in place. To test
with ping/pong program use,

 # test_sockmap -t ping --txmsg_omit_skb_parser

this will send packets between two socket bouncing through a proxy
socket that does not use a parser program.

   (ping)                                    (pong)
   sender         proxy_recv proxy_send      recv
     |                |                       |
     |              verdict -----+            |
     |                |          |            |
     +----------------+          +------------+

Signed-off-by: John Fastabend <john.fastabend@gmail.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/160239300387.8495.11908295143121563076.stgit@john-Precision-5820-Tower
tools/testing/selftests/bpf/test_sockmap.c

index 5cf45455de42a1163d350791ffff16f6e85cce98..419c0b010d142444b2468b1df5a2fcb6c217276f 100644 (file)
@@ -86,6 +86,7 @@ int txmsg_ktls_skb_redir;
 int ktls;
 int peek_flag;
 int skb_use_parser;
+int txmsg_omit_skb_parser;
 
 static const struct option long_options[] = {
        {"help",        no_argument,            NULL, 'h' },
@@ -111,6 +112,7 @@ static const struct option long_options[] = {
        {"txmsg_redir_skb", no_argument,        &txmsg_redir_skb, 1 },
        {"ktls", no_argument,                   &ktls, 1 },
        {"peek", no_argument,                   &peek_flag, 1 },
+       {"txmsg_omit_skb_parser", no_argument,      &txmsg_omit_skb_parser, 1},
        {"whitelist", required_argument,        NULL, 'n' },
        {"blacklist", required_argument,        NULL, 'b' },
        {0, 0, NULL, 0 }
@@ -175,6 +177,7 @@ static void test_reset(void)
        txmsg_apply = txmsg_cork = 0;
        txmsg_ingress = txmsg_redir_skb = 0;
        txmsg_ktls_skb = txmsg_ktls_skb_drop = txmsg_ktls_skb_redir = 0;
+       txmsg_omit_skb_parser = 0;
        skb_use_parser = 0;
 }
 
@@ -912,13 +915,15 @@ static int run_options(struct sockmap_options *options, int cg_fd,  int test)
                goto run;
 
        /* Attach programs to sockmap */
-       err = bpf_prog_attach(prog_fd[0], map_fd[0],
-                               BPF_SK_SKB_STREAM_PARSER, 0);
-       if (err) {
-               fprintf(stderr,
-                       "ERROR: bpf_prog_attach (sockmap %i->%i): %d (%s)\n",
-                       prog_fd[0], map_fd[0], err, strerror(errno));
-               return err;
+       if (!txmsg_omit_skb_parser) {
+               err = bpf_prog_attach(prog_fd[0], map_fd[0],
+                                     BPF_SK_SKB_STREAM_PARSER, 0);
+               if (err) {
+                       fprintf(stderr,
+                               "ERROR: bpf_prog_attach (sockmap %i->%i): %d (%s)\n",
+                               prog_fd[0], map_fd[0], err, strerror(errno));
+                       return err;
+               }
        }
 
        err = bpf_prog_attach(prog_fd[1], map_fd[0],
@@ -931,13 +936,15 @@ static int run_options(struct sockmap_options *options, int cg_fd,  int test)
 
        /* Attach programs to TLS sockmap */
        if (txmsg_ktls_skb) {
-               err = bpf_prog_attach(prog_fd[0], map_fd[8],
-                                       BPF_SK_SKB_STREAM_PARSER, 0);
-               if (err) {
-                       fprintf(stderr,
-                               "ERROR: bpf_prog_attach (TLS sockmap %i->%i): %d (%s)\n",
-                               prog_fd[0], map_fd[8], err, strerror(errno));
-                       return err;
+               if (!txmsg_omit_skb_parser) {
+                       err = bpf_prog_attach(prog_fd[0], map_fd[8],
+                                             BPF_SK_SKB_STREAM_PARSER, 0);
+                       if (err) {
+                               fprintf(stderr,
+                                       "ERROR: bpf_prog_attach (TLS sockmap %i->%i): %d (%s)\n",
+                                       prog_fd[0], map_fd[8], err, strerror(errno));
+                               return err;
+                       }
                }
 
                err = bpf_prog_attach(prog_fd[2], map_fd[8],