[PATCH 2/2] add selftest for TCP_ULP in bpf_setsockopt

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

 



This case invokes bpf_setsockopt and bpf_getsockopt to set ulp. 
The existing smc_ulp_ops of the kernel is used as a test case to test
whether the setting and get operations can be performed normally.

Signed-off-by: zhangmingyi <zhangmingyi5@xxxxxxxxxx>
---
 .../selftests/bpf/progs/setget_sockopt.c      | 21 ++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/bpf/progs/setget_sockopt.c b/tools/testing/selftests/bpf/progs/setget_sockopt.c
index 6dd4318debbf..dcdf26ef41c4 100644
--- a/tools/testing/selftests/bpf/progs/setget_sockopt.c
+++ b/tools/testing/selftests/bpf/progs/setget_sockopt.c
@@ -327,6 +327,18 @@ static int test_tcp_maxseg(void *ctx, struct sock *sk)
 	return 0;
 }
 
+static int test_tcp_ulp(void *ctx, struct sock *sk)
+{
+	__u8 saved_syn[20];
+
+	if (sk->sk_state == TCP_SYN_SENT)
+		return bpf_setsockopt(ctx, IPPROTO_TCP, TCP_ULP,
+						"smc", sizeof("smc"));
+
+	return bpf_getsockopt(ctx, IPPROTO_TCP, TCP_ULP,
+			    saved_syn, sizeof(saved_syn));
+}
+
 static int test_tcp_saved_syn(void *ctx, struct sock *sk)
 {
 	__u8 saved_syn[20];
@@ -395,16 +407,19 @@ int skops_sockopt(struct bpf_sock_ops *skops)
 		break;
 	case BPF_SOCK_OPS_TCP_CONNECT_CB:
 		nr_connect += !(bpf_test_sockopt(skops, sk) ||
-				test_tcp_maxseg(skops, sk));
+				test_tcp_maxseg(skops, sk) ||
+				test_tcp_ulp(skops, sk));
 		break;
 	case BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB:
 		nr_active += !(bpf_test_sockopt(skops, sk) ||
-			       test_tcp_maxseg(skops, sk));
+			       test_tcp_maxseg(skops, sk) ||
+				   test_tcp_ulp(skops, sk));
 		break;
 	case BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB:
 		nr_passive += !(bpf_test_sockopt(skops, sk) ||
 				test_tcp_maxseg(skops, sk) ||
-				test_tcp_saved_syn(skops, sk));
+				test_tcp_saved_syn(skops, sk) ||
+				test_tcp_ulp(skops, sk));
 		flags = skops->bpf_sock_ops_cb_flags | BPF_SOCK_OPS_STATE_CB_FLAG;
 		bpf_setsockopt(skops, SOL_TCP, TCP_BPF_SOCK_OPS_CB_FLAGS, &flags, sizeof(flags));
 		break;
-- 
2.43.0





[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