[PATCH net-next 3/3] selftests/bpf: add rto max for bpf_setsockopt test

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add TCP_BPF_RTO_MAX selftests for active and passive flows
in the BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB and
BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB bpf callbacks.

Signed-off-by: Jason Xing <kerneljasonxing@xxxxxxxxx>
---
 .../bpf/prog_tests/tcp_hdr_options.c          | 28 +++++++++++++------
 .../bpf/progs/test_tcp_hdr_options.c          | 26 +++++++++++++++++
 .../selftests/bpf/test_tcp_hdr_options.h      |  3 ++
 3 files changed, 49 insertions(+), 8 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/tcp_hdr_options.c b/tools/testing/selftests/bpf/prog_tests/tcp_hdr_options.c
index 56685fc03c7e..714d48df6b3a 100644
--- a/tools/testing/selftests/bpf/prog_tests/tcp_hdr_options.c
+++ b/tools/testing/selftests/bpf/prog_tests/tcp_hdr_options.c
@@ -60,8 +60,9 @@ static void print_hdr_stg(const struct hdr_stg *hdr_stg, const char *prefix)
 
 static void print_option(const struct bpf_test_option *opt, const char *prefix)
 {
-	fprintf(stderr, "%s{flags:0x%x, max_delack_ms:%u, rand:0x%x}\n",
-		prefix ? : "", opt->flags, opt->max_delack_ms, opt->rand);
+	fprintf(stderr, "%s{flags:0x%x, max_delack_ms:%u, rand:0x%x}, max_rto_sec:%u\n",
+		prefix ? : "", opt->flags, opt->max_delack_ms, opt->rand,
+		opt->max_rto_sec);
 }
 
 static void sk_fds_close(struct sk_fds *sk_fds)
@@ -300,13 +301,17 @@ static void fastopen_estab(void)
 	hdr_stg_map_fd = bpf_map__fd(skel->maps.hdr_stg_map);
 	lport_linum_map_fd = bpf_map__fd(skel->maps.lport_linum_map);
 
-	exp_passive_estab_in.flags = OPTION_F_RAND | OPTION_F_MAX_DELACK_MS;
+	exp_passive_estab_in.flags = OPTION_F_RAND | OPTION_F_MAX_DELACK_MS |
+				     OPTION_F_MAX_RTO_SEC;
 	exp_passive_estab_in.rand = 0xfa;
 	exp_passive_estab_in.max_delack_ms = 11;
+	exp_passive_estab_in.max_rto_sec = 1;
 
-	exp_active_estab_in.flags = OPTION_F_RAND | OPTION_F_MAX_DELACK_MS;
+	exp_active_estab_in.flags = OPTION_F_RAND | OPTION_F_MAX_DELACK_MS |
+				    OPTION_F_MAX_RTO_SEC;
 	exp_active_estab_in.rand = 0xce;
 	exp_active_estab_in.max_delack_ms = 22;
+	exp_active_estab_in.max_rto_sec = 2;
 
 	exp_passive_hdr_stg.fastopen = true;
 
@@ -337,14 +342,17 @@ static void syncookie_estab(void)
 	hdr_stg_map_fd = bpf_map__fd(skel->maps.hdr_stg_map);
 	lport_linum_map_fd = bpf_map__fd(skel->maps.lport_linum_map);
 
-	exp_passive_estab_in.flags = OPTION_F_RAND | OPTION_F_MAX_DELACK_MS;
+	exp_passive_estab_in.flags = OPTION_F_RAND | OPTION_F_MAX_DELACK_MS |
+				     OPTION_F_MAX_RTO_SEC;
 	exp_passive_estab_in.rand = 0xfa;
 	exp_passive_estab_in.max_delack_ms = 11;
+	exp_passive_estab_in.max_rto_sec = 1;
 
 	exp_active_estab_in.flags = OPTION_F_RAND | OPTION_F_MAX_DELACK_MS |
-					OPTION_F_RESEND;
+				    OPTION_F_RESEND | OPTION_F_MAX_RTO_SEC;
 	exp_active_estab_in.rand = 0xce;
 	exp_active_estab_in.max_delack_ms = 22;
+	exp_active_estab_in.max_rto_sec = 2;
 
 	exp_passive_hdr_stg.syncookie = true;
 	exp_active_hdr_stg.resend_syn = true;
@@ -413,13 +421,17 @@ static void __simple_estab(bool exprm)
 	hdr_stg_map_fd = bpf_map__fd(skel->maps.hdr_stg_map);
 	lport_linum_map_fd = bpf_map__fd(skel->maps.lport_linum_map);
 
-	exp_passive_estab_in.flags = OPTION_F_RAND | OPTION_F_MAX_DELACK_MS;
+	exp_passive_estab_in.flags = OPTION_F_RAND | OPTION_F_MAX_DELACK_MS |
+				     OPTION_F_MAX_RTO_SEC;
 	exp_passive_estab_in.rand = 0xfa;
 	exp_passive_estab_in.max_delack_ms = 11;
+	exp_passive_estab_in.max_rto_sec = 1;
 
-	exp_active_estab_in.flags = OPTION_F_RAND | OPTION_F_MAX_DELACK_MS;
+	exp_active_estab_in.flags = OPTION_F_RAND | OPTION_F_MAX_DELACK_MS |
+				    OPTION_F_MAX_RTO_SEC;
 	exp_active_estab_in.rand = 0xce;
 	exp_active_estab_in.max_delack_ms = 22;
+	exp_active_estab_in.max_rto_sec = 2;
 
 	prepare_out();
 
diff --git a/tools/testing/selftests/bpf/progs/test_tcp_hdr_options.c b/tools/testing/selftests/bpf/progs/test_tcp_hdr_options.c
index 5f4e87ee949a..92da239adb49 100644
--- a/tools/testing/selftests/bpf/progs/test_tcp_hdr_options.c
+++ b/tools/testing/selftests/bpf/progs/test_tcp_hdr_options.c
@@ -80,6 +80,9 @@ static void write_test_option(const struct bpf_test_option *test_opt,
 
 	if (TEST_OPTION_FLAGS(test_opt->flags, OPTION_RAND))
 		data[offset++] = test_opt->rand;
+
+	if (TEST_OPTION_FLAGS(test_opt->flags, OPTION_MAX_RTO_SEC))
+		data[offset++] = test_opt->max_rto_sec;
 }
 
 static int store_option(struct bpf_sock_ops *skops,
@@ -124,6 +127,9 @@ static int parse_test_option(struct bpf_test_option *opt, const __u8 *start)
 	if (TEST_OPTION_FLAGS(opt->flags, OPTION_RAND))
 		opt->rand = *start++;
 
+	if (TEST_OPTION_FLAGS(opt->flags, OPTION_MAX_RTO_SEC))
+		opt->max_rto_sec = *start++;
+
 	return 0;
 }
 
@@ -411,6 +417,14 @@ static int set_rto_min(struct bpf_sock_ops *skops, __u8 peer_max_delack_ms)
 			      sizeof(min_rto_us));
 }
 
+static int set_rto_max(struct bpf_sock_ops *skops, __u8 max_rto_sec)
+{
+	__u32 max_rto_ms = max_rto_sec * 1000;
+
+	return bpf_setsockopt(skops, SOL_TCP, TCP_BPF_RTO_MAX, &max_rto_ms,
+			      sizeof(max_rto_ms));
+}
+
 static int handle_active_estab(struct bpf_sock_ops *skops)
 {
 	struct hdr_stg init_stg = {
@@ -459,6 +473,12 @@ static int handle_active_estab(struct bpf_sock_ops *skops)
 			RET_CG_ERR(err);
 	}
 
+	if (active_estab_in.max_rto_sec) {
+		err = set_rto_max(skops, active_estab_in.max_rto_sec);
+		if (err)
+			RET_CG_ERR(err);
+	}
+
 	return CG_OK;
 }
 
@@ -525,6 +545,12 @@ static int handle_passive_estab(struct bpf_sock_ops *skops)
 			RET_CG_ERR(err);
 	}
 
+	if (passive_estab_in.max_rto_sec) {
+		err = set_rto_max(skops, passive_estab_in.max_rto_sec);
+		if (err)
+			RET_CG_ERR(err);
+	}
+
 	return CG_OK;
 }
 
diff --git a/tools/testing/selftests/bpf/test_tcp_hdr_options.h b/tools/testing/selftests/bpf/test_tcp_hdr_options.h
index 56c9f8a3ad3d..c91fad861f84 100644
--- a/tools/testing/selftests/bpf/test_tcp_hdr_options.h
+++ b/tools/testing/selftests/bpf/test_tcp_hdr_options.h
@@ -8,18 +8,21 @@ struct bpf_test_option {
 	__u8 flags;
 	__u8 max_delack_ms;
 	__u8 rand;
+	__u8 max_rto_sec;
 } __attribute__((packed));
 
 enum {
 	OPTION_RESEND,
 	OPTION_MAX_DELACK_MS,
 	OPTION_RAND,
+	OPTION_MAX_RTO_SEC,
 	__NR_OPTION_FLAGS,
 };
 
 #define OPTION_F_RESEND		(1 << OPTION_RESEND)
 #define OPTION_F_MAX_DELACK_MS	(1 << OPTION_MAX_DELACK_MS)
 #define OPTION_F_RAND		(1 << OPTION_RAND)
+#define OPTION_F_MAX_RTO_SEC	(1 << OPTION_MAX_RTO_SEC)
 #define OPTION_MASK		((1 << __NR_OPTION_FLAGS) - 1)
 
 #define TEST_OPTION_FLAGS(flags, option) (1 & ((flags) >> (option)))
-- 
2.43.5





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux