From nobody Thu Jan 30 19:07:30 2025 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 07F591FCCE6; Mon, 27 Jan 2025 09:09:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.191 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737968993; cv=none; b=iHzSqy0b5aIhGrTfLztTHAOYdibJWLbFzUBBO5eZqWl1I3TR3w5M549UqugDOF/F6bmiUNqLm/JB1AiPsml7jIgslU+hhWO5Z01/MLelkmDqdWdpbcw2GO/YMV0nmbGIaNOjzvhgbxnE1k1qFFopeTQbOO12hj8YdNeem8H726A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737968993; c=relaxed/simple; bh=XJDI1RtH284Ughaa9zhcE+X7NmxYm8WZ4N2i80Ek0rY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=tMIIoOZIPcVtzQzVbOnhnV4IPvXzYZqi821UMeOJpRzr8oPRA01yR2R+4c9TgK2qMFe1dsGYE4t9SxuKs+QCJQWkNLkTfH9YLZ9HldZckc/32eWRAdg25o7+vhuoDSitjSF3dMzqlTg1QCl4EFNkilXHiNq0Fx/17GloPzR/L5w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.191 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.234]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4YhMz85wTmz1JJ9V; Mon, 27 Jan 2025 17:08:36 +0800 (CST) Received: from dggemv703-chm.china.huawei.com (unknown [10.3.19.46]) by mail.maildlp.com (Postfix) with ESMTPS id 948F1140257; Mon, 27 Jan 2025 17:09:42 +0800 (CST) Received: from kwepemn200003.china.huawei.com (7.202.194.126) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Mon, 27 Jan 2025 17:09:42 +0800 Received: from localhost.localdomain (10.175.101.6) by kwepemn200003.china.huawei.com (7.202.194.126) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Mon, 27 Jan 2025 17:09:40 +0800 From: zhangmingyi To: , , , , , , , , , , CC: , , , , , , , , Subject: [PATCH 1/2] ipv4, bpf: Introduced to support the ULP to get or set sockets Date: Mon, 27 Jan 2025 17:07:23 +0800 Message-ID: <20250127090724.3168791-2-zhangmingyi5@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250127090724.3168791-1-zhangmingyi5@huawei.com> References: <20250127090724.3168791-1-zhangmingyi5@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemn200003.china.huawei.com (7.202.194.126) Content-Type: text/plain; charset="utf-8" Note that tcp_getsockopt and tcp_setsockopt support TCP_ULP, while bpf_getsockopt and bpf_setsockopt do not support TCP_ULP. I'm not sure why there is such a difference, but I noticed that tcp_setsockopt is called in bpf_setsockopt.I think we can add the handling of this case. Signed-off-by: zhangmingyi --- net/core/filter.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/core/filter.c b/net/core/filter.c index 713d6f454df3..bdb5c43d6fb0 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -5380,6 +5380,7 @@ static int sol_tcp_sockopt(struct sock *sk, int optna= me, case TCP_CONGESTION: return sol_tcp_sockopt_congestion(sk, optval, optlen, getopt); case TCP_SAVED_SYN: + case TCP_ULP: if (*optlen < 1) return -EINVAL; break; --=20 2.43.0 From nobody Thu Jan 30 19:07:30 2025 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A73D21FCFE6; Mon, 27 Jan 2025 09:09:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.191 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737968995; cv=none; b=lmkuJufEoWCjskt4bDUJinfs/Z06OfWvjBjhXTpymO2plxgIBTHm5gTGSKOWQSOHQQp6akKUKolEAVf2gpynhu5MjP1jh9+HHy7JEmJENQOXnDj9feT+OU6F2QkFLjtY9fuaaVIvpDWuVyDIc2LyiSRGthFAxDg4DjjJ/z5TFFY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737968995; c=relaxed/simple; bh=ZubBlVElppc3zps+tVo58hGyz9tBp1Gtae18sdb6aQQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FqO+RdsrIZg7hrBQGXDIFIy6xcmpUL60PzyGxyVA2HcW/Xll46yxm0TW460KAsqxcyJiri2ukOswBImEr79SmYTGymW3+ZgCzWdMfy9n4pmxA4nM0XP2tMpYvSuAEoFPOQ6/zv9eDSe9+3JlHRdObEivC5HZWeuBa5Ym+hxCPGQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.191 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.17]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4YhMwW3DTlz1l0C9; Mon, 27 Jan 2025 17:06:19 +0800 (CST) Received: from dggemv705-chm.china.huawei.com (unknown [10.3.19.32]) by mail.maildlp.com (Postfix) with ESMTPS id BBA9A1A0188; Mon, 27 Jan 2025 17:09:44 +0800 (CST) Received: from kwepemn200003.china.huawei.com (7.202.194.126) by dggemv705-chm.china.huawei.com (10.3.19.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Mon, 27 Jan 2025 17:09:44 +0800 Received: from localhost.localdomain (10.175.101.6) by kwepemn200003.china.huawei.com (7.202.194.126) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Mon, 27 Jan 2025 17:09:42 +0800 From: zhangmingyi To: , , , , , , , , , , CC: , , , , , , , , Subject: [PATCH 2/2] add selftest for TCP_ULP in bpf_setsockopt Date: Mon, 27 Jan 2025 17:07:24 +0800 Message-ID: <20250127090724.3168791-3-zhangmingyi5@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250127090724.3168791-1-zhangmingyi5@huawei.com> References: <20250127090724.3168791-1-zhangmingyi5@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemn200003.china.huawei.com (7.202.194.126) Content-Type: text/plain; charset="utf-8" This case invokes bpf_setsockopt and bpf_getsockopt to set ulp.=20 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 --- .../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/tes= ting/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; } =20 +static int test_tcp_ulp(void *ctx, struct sock *sk) +{ + __u8 saved_syn[20]; + + if (sk->sk_state =3D=3D 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 +=3D !(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 +=3D !(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 +=3D !(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 =3D 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; --=20 2.43.0