From nobody Mon Jun 8 06:38:13 2026 Received: from stravinsky.debian.org (stravinsky.debian.org [82.195.75.108]) (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 8F09D4D9918; Fri, 5 Jun 2026 12:13:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=82.195.75.108 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780661625; cv=none; b=rvdZwHzz5as5T6EdvF10C8rb1BygKiZNEgF71W80xrrCtdckTF0n46lSCU4OdJngQojUDG466bRXRknfL+Sar7eIVCqikR/3E2q5lxMxuNn9VrTeR+bnbym/b0kOGx2MHSmVeuo/sG2/adH/0YlXvsNauJqUuVVTBzwHEUzb5ek= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780661625; c=relaxed/simple; bh=cb5Fl7qI+QrhlAQCSG7RGxk69W8WeNmqAvtfLFDwWng=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=jR2Yi+u83bPCyg6mGL57258y23E7jW90X8NkvrqPaDmFugIPYs6EgszpgBFJSZPu3fT7Irl7vC1vBNd97uwwW2yWCqek4qOWui9A89NMhGpUBJHH4S5V50dX6/bKbVhuZTkfVjyE+H46A50gUX1dRlo+OIn/1l8vh6bQJAGO6sQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=debian.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.b=rZnVx2jC; arc=none smtp.client-ip=82.195.75.108 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=debian.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.b="rZnVx2jC" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debian.org; s=smtpauto.stravinsky; h=X-Debian-User:Cc:To:In-Reply-To:References: Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description; bh=bV6PMNPiGvqiL3b8JXSN02wKJytn/9yKMzeTnAqzokY=; b=rZnVx2jCpig91mq5gbaUGzWkZk xKl1RK2SXpQU1T+t48KunylPAopZdDL4e2+knZlrEQpQ9jYAF1+fXckJkqPyIZGMYLo+NOPMpQmZY s0smzm+ZFY2hT7qxfKhGQp4TNWscQnCG8zsexwsWQMY7Nu8HgqPX/Jn+1PyI0bn2xa9Tthe27ZAh0 GWZd7LbYD//NtpInp6HkrnOZtYdaDMgF+yl7lBTZ5mCJdFWdmUfYTK6L6/Myjn1J/7wNDBBPJUGtq EJV/KHxIvFdDD9mKOXrfo6Og9xTPtVmcrpwoyB0yE3rMtIhgT6q/IgeEHFzSv1nQHj6avo4ej670p YLM4C6Dg==; Received: from authenticated-user by stravinsky.debian.org with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.96) (envelope-from ) id 1wVTQh-005HW8-1X; Fri, 05 Jun 2026 12:13:39 +0000 From: Breno Leitao Date: Fri, 05 Jun 2026 05:13:25 -0700 Subject: [PATCH net-next 1/2] smc: convert to getsockopt_iter Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260605-getsockopt_smc-v1-1-65da62fa44c4@debian.org> References: <20260605-getsockopt_smc-v1-0-65da62fa44c4@debian.org> In-Reply-To: <20260605-getsockopt_smc-v1-0-65da62fa44c4@debian.org> To: "D. Wythe" , Dust Li , Sidraya Jayagond , Wenjia Zhang , Mahanta Jambigi , Tony Lu , Wen Gu , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan Cc: linux-rdma@vger.kernel.org, linux-s390@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Breno Leitao , kernel-team@meta.com X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=5630; i=leitao@debian.org; h=from:subject:message-id; bh=cb5Fl7qI+QrhlAQCSG7RGxk69W8WeNmqAvtfLFDwWng=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBqIr1pm98zJvDjVKMkIUdQ3+teQcLhsKIXeJYWP 8NGNOrTh9uJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaiK9aQAKCRA1o5Of/Hh3 bZtSD/92C4xNep/Ux3iA2mmf3eEIneAzD3EZ4EzGEU4SzV8OfRzjdotDLLRVbe5HMn0msclaCzH GxqM22kJ2jFwYd1LCCdHqp6MFleph4meCYu5RlFTKG1i8l5eW7nVLANvZD1d0L13hCF2IyboLbA H4yvBvqnXwMd/2LByqQZMyKDtCfqrKhU6pbPO4/vAcf09ExxFrJCT4TRh0l88pKnxr78S3uvD3c Av3VusTco8ldf6/ubRfbfBk+wIJojinUJRPDKcwtCWe752q0r9hACreitDBt15aZFODhhSCyeg6 MxRa0/HC71a57z0FL5aLDy4sWQp3yGErmBFzvYktHAlsZ3hY3iFD75M8HWTpBiM5fhiB3VwLRQW J/QMXhCR6D728PuFogolbQncjv4Lg/ADx6tqFh9pyt5F5kDY7+KB4vBVwIcvyxsI5fIQGZsn0/h Q+QhFBxRFBl4QrDd/CvfI39t8TPv45cVgA5UmfxN/WgEaCM8AEZ6crExt5Bn12LbnRts6Yt3yzP VI6W5H0eWjXGXkF+K03dv+5W67y7SGzqAbegCfBa2JL2DfPGuHyoCPDYCSm+FYNN6WIO+4NLXi8 FBSeKYO1ItWaQOQ4UdSVOkUaCHgicj8Ue1lXZpfAvKdAeCdxSL8SsmHC76fw2dkKP7JjfCWbRGx eOohPoNGpa69jiQ== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D X-Debian-User: leitao Convert SMC socket's getsockopt implementation to use the new getsockopt_iter callback with sockopt_t. Key changes: - Replace (char __user *optval, int __user *optlen) with sockopt_t *opt - Use opt->optlen for buffer length (input) and returned size (output) - Use copy_to_iter() instead of put_user()/copy_to_user() - Add linux/uio.h for copy_to_iter() SMC is a proxy socket: only the SOL_SMC level is handled locally, while all other levels are forwarded to the underlying CLC (TCP) socket. That socket's getsockopt() still operates on __user buffers, so the pass-through is limited to user-backed iters: optval is reconstructed from iter_out, the original optlen pointer (preserved in sockopt_t) is forwarded, and the length reported by the clcsock is mirrored back into opt->optlen so the core writes the correct value to userspace. Signed-off-by: Breno Leitao --- net/smc/af_smc.c | 41 +++++++++++++++++++++++++++++------------ net/smc/smc.h | 2 +- net/smc/smc_inet.c | 4 ++-- 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c index b5db69073e20..064d752388d2 100644 --- a/net/smc/af_smc.c +++ b/net/smc/af_smc.c @@ -27,6 +27,7 @@ #include #include #include +#include =20 #include #include @@ -3017,17 +3018,14 @@ int smc_shutdown(struct socket *sock, int how) } =20 static int __smc_getsockopt(struct socket *sock, int level, int optname, - char __user *optval, int __user *optlen) + sockopt_t *opt) { struct smc_sock *smc; int val, len; =20 smc =3D smc_sk(sock->sk); =20 - if (get_user(len, optlen)) - return -EFAULT; - - len =3D min_t(int, len, sizeof(int)); + len =3D min_t(int, opt->optlen, sizeof(int)); =20 if (len < 0) return -EINVAL; @@ -3040,9 +3038,8 @@ static int __smc_getsockopt(struct socket *sock, int = level, int optname, return -EOPNOTSUPP; } =20 - if (put_user(len, optlen)) - return -EFAULT; - if (copy_to_user(optval, &val, len)) + opt->optlen =3D len; + if (copy_to_iter(&val, len, &opt->iter_out) !=3D len) return -EFAULT; =20 return 0; @@ -3168,13 +3165,26 @@ int smc_setsockopt(struct socket *sock, int level, = int optname, } =20 int smc_getsockopt(struct socket *sock, int level, int optname, - char __user *optval, int __user *optlen) + sockopt_t *opt) { struct smc_sock *smc; int rc; =20 if (level =3D=3D SOL_SMC) - return __smc_getsockopt(sock, level, optname, optval, optlen); + return __smc_getsockopt(sock, level, optname, opt); + + /* Other levels apply to the CLC socket, whose getsockopt() still + * operates on __user buffers. Reconstruct the userspace pointers and + * forward the call; kernel-backed callers (e.g. io_uring) are not + * supported for this pass-through. + * + * TODO: this pass-through is limited to user-backed iters because the + * underlying protocols (TCP/IP) have not been converted to + * getsockopt_iter() yet. Once they are, forward the sockopt_t directly + * and drop this restriction so all iov_iter types are supported. + */ + if (!iter_is_ubuf(&opt->iter_out) || !opt->optlen_user) + return -EOPNOTSUPP; =20 smc =3D smc_sk(sock->sk); mutex_lock(&smc->clcsock_release_lock); @@ -3188,8 +3198,15 @@ int smc_getsockopt(struct socket *sock, int level, i= nt optname, return -EOPNOTSUPP; } rc =3D smc->clcsock->ops->getsockopt(smc->clcsock, level, optname, - optval, optlen); + opt->iter_out.ubuf, opt->optlen_user); mutex_unlock(&smc->clcsock_release_lock); + + /* The clcsock wrote the resulting length to the user optlen pointer; + * mirror it into opt->optlen so the core writes the same value back. + */ + if (get_user(opt->optlen, opt->optlen_user)) + return -EFAULT; + return rc; } =20 @@ -3341,7 +3358,7 @@ static const struct proto_ops smc_sock_ops =3D { .listen =3D smc_listen, .shutdown =3D smc_shutdown, .setsockopt =3D smc_setsockopt, - .getsockopt =3D smc_getsockopt, + .getsockopt_iter =3D smc_getsockopt, .sendmsg =3D smc_sendmsg, .recvmsg =3D smc_recvmsg, .mmap =3D sock_no_mmap, diff --git a/net/smc/smc.h b/net/smc/smc.h index 52145df83f6e..e62549067b67 100644 --- a/net/smc/smc.h +++ b/net/smc/smc.h @@ -59,7 +59,7 @@ int smc_shutdown(struct socket *sock, int how); int smc_setsockopt(struct socket *sock, int level, int optname, sockptr_t optval, unsigned int optlen); int smc_getsockopt(struct socket *sock, int level, int optname, - char __user *optval, int __user *optlen); + sockopt_t *opt); int smc_sendmsg(struct socket *sock, struct msghdr *msg, size_t len); int smc_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, int flags); diff --git a/net/smc/smc_inet.c b/net/smc/smc_inet.c index a94084b4a498..419240fedbc3 100644 --- a/net/smc/smc_inet.c +++ b/net/smc/smc_inet.c @@ -44,7 +44,7 @@ static const struct proto_ops smc_inet_stream_ops =3D { .listen =3D smc_listen, .shutdown =3D smc_shutdown, .setsockopt =3D smc_setsockopt, - .getsockopt =3D smc_getsockopt, + .getsockopt_iter =3D smc_getsockopt, .sendmsg =3D smc_sendmsg, .recvmsg =3D smc_recvmsg, .mmap =3D sock_no_mmap, @@ -91,7 +91,7 @@ static const struct proto_ops smc_inet6_stream_ops =3D { .listen =3D smc_listen, .shutdown =3D smc_shutdown, .setsockopt =3D smc_setsockopt, - .getsockopt =3D smc_getsockopt, + .getsockopt_iter =3D smc_getsockopt, .sendmsg =3D smc_sendmsg, .recvmsg =3D smc_recvmsg, .mmap =3D sock_no_mmap, --=20 2.53.0-Meta From nobody Mon Jun 8 06:38:13 2026 Received: from stravinsky.debian.org (stravinsky.debian.org [82.195.75.108]) (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 ECB0E4DBD6E; Fri, 5 Jun 2026 12:13:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=82.195.75.108 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780661629; cv=none; b=jkswB90olzg0xcBB1wE9c+7MB6UTt4Uy0wqrKsqhL1eBD2iw8Jbn42tl44WdoUQK5BEIdwNIra0Do49iJWkqHUNe7xDxY2trh8EuIUX5ulh58G9CmVIl79pt77GnLJYyUmwXuf1h2ao6fPAsz9BVhUuxn59LuV4BmigY/cuTio4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780661629; c=relaxed/simple; bh=3dPr7qEVvxmzqp5Fa68RHp4F3vW5/2Q/V40NwuplFpg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PMP4WQESAkf3EOBTewO84kuvSHyU2u3izrV/+5hi4Zahkl4eWS+0wmMJLn5C2amWllzW/2oQoh2dnGeeCB8KiXK3wojHnlFGq4CUJ6CIwlSrO4vl7G9H3dU6kCTzupbqVsoE7kz//Cf8Gfi3EkKj7d/VrXq/hQUOIobayT9TpUI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=debian.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.b=Cg+RrNWC; arc=none smtp.client-ip=82.195.75.108 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=debian.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.b="Cg+RrNWC" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debian.org; s=smtpauto.stravinsky; h=X-Debian-User:Cc:To:In-Reply-To:References: Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description; bh=kFUydBL2VOJZxCjSY8+wesOl5nfUP1qHfnXLPzIPWck=; b=Cg+RrNWC1/3+bkJkbTflL8ztDI go10PZKiqgyCXY+ZgJ85TJniJwKYe7lOncmV6ur/xkQDLhGRarJ4KqUBiNoY2j9Q+eLEH/+dvBI8B 7aLDkGXm1u5ziV+SnwE4KLgjnfFCtXVPcLlDO2Hz4HYAPQL3NgAe53G6Q4dVi3A+d4WpUnDkmQrfX YiPtvqv0fgwecZHZKvyZffAm9Tvf2cSxo23GP23r3GHmFm7hNtkSYGvxNri3UJpv/t372ioqRcp3C lPy1jvwErc9oKrq5cxTZv0rgAH+n1L4NSIPyNzDG6cHKQT/WowD0Mzo1PtvNEc19cyj4HKSqwlFK9 zYwMa0hg==; Received: from authenticated-user by stravinsky.debian.org with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.96) (envelope-from ) id 1wVTQm-005HWG-1Y; Fri, 05 Jun 2026 12:13:44 +0000 From: Breno Leitao Date: Fri, 05 Jun 2026 05:13:26 -0700 Subject: [PATCH net-next 2/2] selftests: net: add SMC getsockopt_iter conversion test Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260605-getsockopt_smc-v1-2-65da62fa44c4@debian.org> References: <20260605-getsockopt_smc-v1-0-65da62fa44c4@debian.org> In-Reply-To: <20260605-getsockopt_smc-v1-0-65da62fa44c4@debian.org> To: "D. Wythe" , Dust Li , Sidraya Jayagond , Wenjia Zhang , Mahanta Jambigi , Tony Lu , Wen Gu , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan Cc: linux-rdma@vger.kernel.org, linux-s390@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Breno Leitao , kernel-team@meta.com X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=6628; i=leitao@debian.org; h=from:subject:message-id; bh=3dPr7qEVvxmzqp5Fa68RHp4F3vW5/2Q/V40NwuplFpg=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBqIr1qlb+aNt6A0tAWKYvap0Vpdt/edGJZQ6XHG i0dJttj2k6JAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaiK9agAKCRA1o5Of/Hh3 bSqnD/9aZpOTD0RZsKZbziT9z+aDoKf+Xw1RatCpANzHyubQazRzHF+T13BySpQNQvrQDLl94Z8 jXErk1WB1mcxWZ+wXKTvXT9CS74NP6O+PsAKYyObIC5z2HGMPtwzEWVCKxCarolZuXERmf2zu4K ABLPLo2bZbR4YVeXjX8e3RBbq9IG/vFb5U+4+mh/24qHAAv/W8i3tp2M8mn89ngmW+hhmwQJPHr aXevJKErr5GDvnFl3ho9EK5dq4xBpFWE7vsic5hv9482jfsb8/9Epsne75OesKyzMdXmt40Am7h JW+0EQfsiqz1nu0K78Oe+P21SHQa7ITtmq0vK1Hz5wwsef3ijPkTns555IVz6w4jMfFBAB0KSRy 0+xj0O24HFwWfuBBHJ/IJfY58BlKFCN6K9eguSvCc7ma7BHwrNUjQUFFHSvU7CZLS7kqMUeASPI GVI+nuRT1FbAnrSVaggd+JdgBafZWywzzMmxq8f9LggEOz0/1jur4o8Wkn9XWuPKfgMc9mNK9df inlYDAukb8PfDlN0GuL4T4pP3KnYLH/rhpNLsPMwh4r6nkIV3FiftoQkFao8xjvx/NEbIdcZIAa XVsMJ3n+DHAo3psms8LII+EcNq1IjLPLe0V2R09CpHVuWeZMcdxu684wd7O7LMlO14D3RQl5D2M j3/liRQy2BBJIpw== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D X-Debian-User: leitao Add a kselftest that exercises the SMC getsockopt() paths converted to the getsockopt_iter() / sockopt_t callback: - SOL_SMC options (SMC_LIMIT_HS), handled directly by smc_getsockopt(), which returns the int value through copy_to_iter() and reports the written length in opt->optlen. - The CLC pass-through (e.g. SOL_TCP), where smc_getsockopt() forwards to the underlying TCP socket: optval is reconstructed from iter_out, the optlen pointer is forwarded, and the clamped length is mirrored back through opt->optlen. The oversized-buffer case (input optlen differs from output) specifically guards against a missing writeback sync. Signed-off-by: Breno Leitao --- tools/testing/selftests/net/Makefile | 1 + tools/testing/selftests/net/getsockopt_smc.c | 175 +++++++++++++++++++++++= ++++ 2 files changed, 176 insertions(+) diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests= /net/Makefile index 5ca6c557fc3f..5b50f718dbde 100644 --- a/tools/testing/selftests/net/Makefile +++ b/tools/testing/selftests/net/Makefile @@ -177,6 +177,7 @@ TEST_GEN_PROGS :=3D \ bind_wildcard \ epoll_busy_poll \ getsockopt_iter \ + getsockopt_smc \ icmp_rfc4884 \ ipv6_fragmentation \ proc_net_pktgen \ diff --git a/tools/testing/selftests/net/getsockopt_smc.c b/tools/testing/s= elftests/net/getsockopt_smc.c new file mode 100644 index 000000000000..239deefb3187 --- /dev/null +++ b/tools/testing/selftests/net/getsockopt_smc.c @@ -0,0 +1,175 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Exercise the SMC getsockopt() paths that were converted to the + * getsockopt_iter() / sockopt_t callback. + * + * Two distinct paths are covered: + * + * - SOL_SMC options (SMC_LIMIT_HS) are handled directly by + * smc_getsockopt(), which returns the int value through copy_to_iter() + * and reports the written length in opt->optlen. + * + * - Other levels (e.g. SOL_TCP) are forwarded to the underlying CLC (TC= P) + * socket, whose getsockopt() still operates on __user buffers. The + * converted smc_getsockopt() reconstructs the userspace optval from + * iter_out, forwards the original optlen pointer, and mirrors the len= gth + * the clcsock reported back into opt->optlen so the core writes the r= ight + * value to userspace. + * + * The kernel-buffer (kvec) path of the CLC pass-through returns -EOPNOTSU= PP + * and is not reachable from a userspace getsockopt(), so it is not tested + * here. + * + * Author: Breno Leitao + */ +#include +#include +#include +#include +#include +#include +#include + +#include "kselftest_harness.h" + +#ifndef AF_SMC +#define AF_SMC 43 +#endif +#ifndef SMCPROTO_SMC +#define SMCPROTO_SMC 0 +#endif +#ifndef SOL_SMC +#define SOL_SMC 286 +#endif +#ifndef SMC_LIMIT_HS +#define SMC_LIMIT_HS 1 +#endif + +FIXTURE(smc) { + int fd; +}; + +FIXTURE_SETUP(smc) +{ + self->fd =3D socket(AF_SMC, SOCK_STREAM, SMCPROTO_SMC); + if (self->fd < 0) + SKIP(return, "AF_SMC unavailable (errno %d) - load the smc module", + errno); +} + +FIXTURE_TEARDOWN(smc) +{ + if (self->fd >=3D 0) + close(self->fd); +} + +/* ---------- SOL_SMC: handled directly by smc_getsockopt() ---------- */ + +/* SMC_LIMIT_HS is reported back as a 4-byte int via copy_to_iter(). */ +TEST_F(smc, limit_hs_default) +{ + socklen_t optlen =3D sizeof(int); + int val =3D 0xdeadbeef; + + ASSERT_EQ(0, getsockopt(self->fd, SOL_SMC, SMC_LIMIT_HS, &val, &optlen)); + EXPECT_EQ(sizeof(int), optlen); + EXPECT_TRUE(val =3D=3D 0 || val =3D=3D 1); +} + +/* A value set via setsockopt() must be readable back unchanged. */ +TEST_F(smc, limit_hs_set_get) +{ + socklen_t optlen =3D sizeof(int); + int val =3D 1; + + ASSERT_EQ(0, setsockopt(self->fd, SOL_SMC, SMC_LIMIT_HS, &val, optlen)); + + val =3D -1; + ASSERT_EQ(0, getsockopt(self->fd, SOL_SMC, SMC_LIMIT_HS, &val, &optlen)); + EXPECT_EQ(sizeof(int), optlen); + EXPECT_EQ(1, val); +} + +/* setsockopt() stores !!val, so a non-1 truthy value reads back as 1. */ +TEST_F(smc, limit_hs_set_get_clear) +{ + socklen_t optlen =3D sizeof(int); + int val =3D 0; + + ASSERT_EQ(0, setsockopt(self->fd, SOL_SMC, SMC_LIMIT_HS, &val, optlen)); + + val =3D -1; + ASSERT_EQ(0, getsockopt(self->fd, SOL_SMC, SMC_LIMIT_HS, &val, &optlen)); + EXPECT_EQ(sizeof(int), optlen); + EXPECT_EQ(0, val); +} + +/* An oversized buffer is clamped: optlen is reported back as sizeof(int).= */ +TEST_F(smc, limit_hs_oversize_clamped) +{ + socklen_t optlen; + char buf[16] =3D {}; + + optlen =3D sizeof(buf); + ASSERT_EQ(0, getsockopt(self->fd, SOL_SMC, SMC_LIMIT_HS, buf, &optlen)); + EXPECT_EQ(sizeof(int), optlen); +} + +/* An unknown SOL_SMC option is rejected with -EOPNOTSUPP. */ +TEST_F(smc, bad_optname) +{ + socklen_t optlen =3D sizeof(int); + int val; + + ASSERT_EQ(-1, getsockopt(self->fd, SOL_SMC, 0x7fff, &val, &optlen)); + EXPECT_EQ(EOPNOTSUPP, errno); +} + +/* ---------- CLC pass-through: forwarded to the underlying TCP socket ---= --- */ + +/* A TCP option set on the SMC socket is applied to the CLC socket and mus= t be + * readable back through the pass-through, exercising optval reconstructio= n. + */ +TEST_F(smc, clc_tcp_nodelay_set_get) +{ + socklen_t optlen =3D sizeof(int); + int val =3D 1; + + ASSERT_EQ(0, setsockopt(self->fd, IPPROTO_TCP, TCP_NODELAY, + &val, optlen)); + + val =3D -1; + ASSERT_EQ(0, getsockopt(self->fd, IPPROTO_TCP, TCP_NODELAY, + &val, &optlen)); + EXPECT_EQ(sizeof(int), optlen); + EXPECT_EQ(1, val); +} + +/* With an oversized buffer the clcsock clamps the reported length to + * sizeof(int). That length is produced by the clcsock writing the user op= tlen + * pointer, and must be mirrored back through opt->optlen; since the input + * optlen (16) differs from the output (4), this fails if the writeback sy= nc + * in smc_getsockopt() is missing. + */ +TEST_F(smc, clc_tcp_nodelay_oversize_clamped) +{ + socklen_t optlen; + char buf[16] =3D {}; + + optlen =3D sizeof(buf); + ASSERT_EQ(0, getsockopt(self->fd, IPPROTO_TCP, TCP_NODELAY, + buf, &optlen)); + EXPECT_EQ(sizeof(int), optlen); +} + +/* An error from the clcsock (unknown TCP option) is propagated unchanged.= */ +TEST_F(smc, clc_bad_optname) +{ + socklen_t optlen =3D sizeof(int); + int val; + + ASSERT_EQ(-1, getsockopt(self->fd, IPPROTO_TCP, 0x7fff, &val, &optlen)); + EXPECT_EQ(ENOPROTOOPT, errno); +} + +TEST_HARNESS_MAIN --=20 2.53.0-Meta