diff mbox series

[bpf-next,10/10] bpf: selftest: Add test for TCP_BPF_DELACK_MAX and TCP_BPF_RTO_MIN

Message ID 20200626175604.1462935-1-kafai@fb.com
State New
Headers show
Series None | expand

Commit Message

Martin KaFai Lau June 26, 2020, 5:56 p.m. UTC
This patch tests a bpf prog that parses/writes a max_delack_ms bpf header
option and also bpf_setsockopt its TCP_BPF_DELACK_MAX/TCP_BPF_RTO_MIN
accordingly.

Signed-off-by: Martin KaFai Lau <kafai@fb.com>
---
 .../bpf/prog_tests/tcp_hdr_options.c          |  6 ++--
 .../bpf/progs/test_tcp_hdr_options.c          | 34 +++++++++++++++++++
 2 files changed, 38 insertions(+), 2 deletions(-)
diff mbox series

Patch

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 f8daf36783f3..5a58f60d2889 100644
--- a/tools/testing/selftests/bpf/prog_tests/tcp_hdr_options.c
+++ b/tools/testing/selftests/bpf/prog_tests/tcp_hdr_options.c
@@ -447,11 +447,13 @@  static void simple_estab(void)
 	struct bpf_link *link;
 	struct sk_fds sk_fds;
 
-	exp_passive_estab_in.flags = OPTION_F_MAGIC;
+	exp_passive_estab_in.flags = OPTION_F_MAGIC | OPTION_F_MAX_DELACK_MS;
 	exp_passive_estab_in.magic = 0xfa;
+	exp_passive_estab_in.max_delack_ms = 11;
 
-	exp_active_estab_in.flags = OPTION_F_MAGIC;
+	exp_active_estab_in.flags = OPTION_F_MAGIC | OPTION_F_MAX_DELACK_MS;
 	exp_active_estab_in.magic = 0xce;
+	exp_active_estab_in.max_delack_ms = 22;
 
 	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 631181bfb4cc..eb3b3c2a21f9 100644
--- a/tools/testing/selftests/bpf/progs/test_tcp_hdr_options.c
+++ b/tools/testing/selftests/bpf/progs/test_tcp_hdr_options.c
@@ -465,6 +465,24 @@  static __always_inline int handle_write_hdr_opt(struct bpf_sock_ops *skops)
 	return write_nodata_opt(skops);
 }
 
+static __always_inline int set_delack_max(struct bpf_sock_ops *skops,
+					  __u8 max_delack_ms)
+{
+	__u32 max_delack_us = max_delack_ms * 1000;
+
+	return bpf_setsockopt(skops, SOL_TCP, TCP_BPF_DELACK_MAX,
+			      &max_delack_us, sizeof(max_delack_us));
+}
+
+static __always_inline int set_rto_min(struct bpf_sock_ops *skops,
+				       __u8 peer_max_delack_ms)
+{
+	__u32 min_rto_us = peer_max_delack_ms * 1000;
+
+	return bpf_setsockopt(skops, SOL_TCP, TCP_BPF_RTO_MIN, &min_rto_us,
+			      sizeof(min_rto_us));
+}
+
 static __always_inline int handle_active_estab(struct bpf_sock_ops *skops)
 {
 	__u8 bpf_hdr_opt_off = skops->skb_bpf_hdr_opt_off;
@@ -505,6 +523,14 @@  static __always_inline int handle_active_estab(struct bpf_sock_ops *skops)
 		/* No options will be written from now */
 		clear_hdr_cb_flags(skops);
 
+	if (active_syn_out.max_delack_ms &&
+	    set_delack_max(skops, active_syn_out.max_delack_ms))
+		RET_CG_ERR(skops);
+
+	if (active_estab_in.max_delack_ms &&
+	    set_rto_min(skops, active_estab_in.max_delack_ms))
+		RET_CG_ERR(skops);
+
 	return CG_OK;
 }
 
@@ -590,6 +616,14 @@  static __always_inline int handle_passive_estab(struct bpf_sock_ops *skops)
 		/* No options will be written from now */
 		clear_hdr_cb_flags(skops);
 
+	if (passive_synack_out.max_delack_ms &&
+	    set_delack_max(skops, passive_synack_out.max_delack_ms))
+		RET_CG_ERR(skops);
+
+	if (passive_estab_in.max_delack_ms &&
+	    set_rto_min(skops, passive_estab_in.max_delack_ms))
+		RET_CG_ERR(skops);
+
 	return CG_OK;
 }