Commit cdf43c4b authored by John Fastabend's avatar John Fastabend Committed by Alexei Starovoitov
Browse files

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: default avatarJohn Fastabend <john.fastabend@gmail.com>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/160239300387.8495.11908295143121563076.stgit@john-Precision-5820-Tower
parent ef565928
Loading
Loading
Loading
Loading
+21 −14
Original line number Diff line number Diff line
@@ -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,6 +915,7 @@ static int run_options(struct sockmap_options *options, int cg_fd, int test)
		goto run;

	/* Attach programs to sockmap */
	if (!txmsg_omit_skb_parser) {
		err = bpf_prog_attach(prog_fd[0], map_fd[0],
				      BPF_SK_SKB_STREAM_PARSER, 0);
		if (err) {
@@ -920,6 +924,7 @@ static int run_options(struct sockmap_options *options, int cg_fd, int test)
				prog_fd[0], map_fd[0], err, strerror(errno));
			return err;
		}
	}

	err = bpf_prog_attach(prog_fd[1], map_fd[0],
				BPF_SK_SKB_STREAM_VERDICT, 0);
@@ -931,6 +936,7 @@ static int run_options(struct sockmap_options *options, int cg_fd, int test)

	/* Attach programs to TLS sockmap */
	if (txmsg_ktls_skb) {
		if (!txmsg_omit_skb_parser) {
			err = bpf_prog_attach(prog_fd[0], map_fd[8],
					      BPF_SK_SKB_STREAM_PARSER, 0);
			if (err) {
@@ -939,6 +945,7 @@ static int run_options(struct sockmap_options *options, int cg_fd, int test)
					prog_fd[0], map_fd[8], err, strerror(errno));
				return err;
			}
		}

		err = bpf_prog_attach(prog_fd[2], map_fd[8],
				      BPF_SK_SKB_STREAM_VERDICT, 0);