Skip to content

Commit c3c41c3

Browse files
jrfastabkernel-patches-bot
authored andcommitted
bpf, selftests: Add option to test_sockmap to omit adding parser program
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 <[email protected]>
1 parent 583d094 commit c3c41c3

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

tools/testing/selftests/bpf/test_sockmap.c

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ int txmsg_ktls_skb_redir;
8686
int ktls;
8787
int peek_flag;
8888
int skb_use_parser;
89+
int txmsg_omit_skb_parser;
8990

9091
static const struct option long_options[] = {
9192
{"help", no_argument, NULL, 'h' },
@@ -111,6 +112,7 @@ static const struct option long_options[] = {
111112
{"txmsg_redir_skb", no_argument, &txmsg_redir_skb, 1 },
112113
{"ktls", no_argument, &ktls, 1 },
113114
{"peek", no_argument, &peek_flag, 1 },
115+
{"txmsg_omit_skb_parser", no_argument, &txmsg_omit_skb_parser, 1},
114116
{"whitelist", required_argument, NULL, 'n' },
115117
{"blacklist", required_argument, NULL, 'b' },
116118
{0, 0, NULL, 0 }
@@ -175,6 +177,7 @@ static void test_reset(void)
175177
txmsg_apply = txmsg_cork = 0;
176178
txmsg_ingress = txmsg_redir_skb = 0;
177179
txmsg_ktls_skb = txmsg_ktls_skb_drop = txmsg_ktls_skb_redir = 0;
180+
txmsg_omit_skb_parser = 0;
178181
skb_use_parser = 0;
179182
}
180183

@@ -912,13 +915,15 @@ static int run_options(struct sockmap_options *options, int cg_fd, int test)
912915
goto run;
913916

914917
/* Attach programs to sockmap */
915-
err = bpf_prog_attach(prog_fd[0], map_fd[0],
916-
BPF_SK_SKB_STREAM_PARSER, 0);
917-
if (err) {
918-
fprintf(stderr,
919-
"ERROR: bpf_prog_attach (sockmap %i->%i): %d (%s)\n",
920-
prog_fd[0], map_fd[0], err, strerror(errno));
921-
return err;
918+
if (!txmsg_omit_skb_parser) {
919+
err = bpf_prog_attach(prog_fd[0], map_fd[0],
920+
BPF_SK_SKB_STREAM_PARSER, 0);
921+
if (err) {
922+
fprintf(stderr,
923+
"ERROR: bpf_prog_attach (sockmap %i->%i): %d (%s)\n",
924+
prog_fd[0], map_fd[0], err, strerror(errno));
925+
return err;
926+
}
922927
}
923928

924929
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)
931936

932937
/* Attach programs to TLS sockmap */
933938
if (txmsg_ktls_skb) {
934-
err = bpf_prog_attach(prog_fd[0], map_fd[8],
935-
BPF_SK_SKB_STREAM_PARSER, 0);
936-
if (err) {
937-
fprintf(stderr,
938-
"ERROR: bpf_prog_attach (TLS sockmap %i->%i): %d (%s)\n",
939-
prog_fd[0], map_fd[8], err, strerror(errno));
940-
return err;
939+
if (!txmsg_omit_skb_parser) {
940+
err = bpf_prog_attach(prog_fd[0], map_fd[8],
941+
BPF_SK_SKB_STREAM_PARSER, 0);
942+
if (err) {
943+
fprintf(stderr,
944+
"ERROR: bpf_prog_attach (TLS sockmap %i->%i): %d (%s)\n",
945+
prog_fd[0], map_fd[8], err, strerror(errno));
946+
return err;
947+
}
941948
}
942949

943950
err = bpf_prog_attach(prog_fd[2], map_fd[8],

0 commit comments

Comments
 (0)