From nobody Sun May 19 00:47:40 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 31FB2433B1 for ; Thu, 15 Feb 2024 11:40:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707997218; cv=none; b=vF14EKPnPlt2W4ikNrpDVGVQrJtIpNnv2jCWJXwiBOWili2L8DF4MXgYUAujuBJIxibCMN8H97TRdp5CszjAYzR+Wzit5eIpFHmR9C87MUVstCmzWqxyyJTmx8Ns6gbUXe00bwpMuGcAyrtsjE0/5C/6IStcZ8vn1ceV782NEKw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707997218; c=relaxed/simple; bh=uCboPJ0LRaDIGMdWuBXqejhsmk8WqCnmSpXCIwZJHFI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=SXj1y0JjpHKwio9hk30nkw9tOknRXilmXTOBBxfqhjprhsa/wPpx9M+xd/pjYq2Cdr78+kYar2V5NEQzjLLAAjhLUE2hsd2zqJJ2ZVJQuSv93TMDk9bbQ4onGL/obsZTke1QNUckQz1lNEnevNAHIxf90glcJ9e5H5JQIQoWTV8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qsN81ax3; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="qsN81ax3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CBBD7C433F1; Thu, 15 Feb 2024 11:40:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707997217; bh=uCboPJ0LRaDIGMdWuBXqejhsmk8WqCnmSpXCIwZJHFI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=qsN81ax3SrOqCmj6TOD4pPXe8OG3VZ8BIUE2xy3ZC5WVAYo+Uy4JTgJpfqR6ruq6e BSPM3CNpzb+0rRX4puNNJuApgWnkvSBReVpk2FN0U+JAAOwejnTsl6WPzsqvbPLzMk py+m/6vgHodCnvMFyQ0J+qDiTOLzsrTi6rp0Fws0zNo4GMZY+Yp0GAnlqcKA2qGASZ VELgc+6oyVTChqr7gIfQWnptt5Nclq4xsKxEsa3F8AhzLS3JBuPxdY6GRNtLxhhWNo wqqLZZZ1cC5BdkmscysN3VJoxQ6oYptoWnVTP6AclgPU3piF42Dmbadxw+OpFDD1so jEQQ+WQNkf0jA== From: "Matthieu Baerts (NGI0)" Date: Thu, 15 Feb 2024 12:40:02 +0100 Subject: [PATCH mptcp-next v4 1/3] mptcp: token kunit: set protocol Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240215-mptcp-check-protocol-v4-1-16e932665e21@kernel.org> References: <20240215-mptcp-check-protocol-v4-0-16e932665e21@kernel.org> In-Reply-To: <20240215-mptcp-check-protocol-v4-0-16e932665e21@kernel.org> To: mptcp@lists.linux.dev Cc: Mat Martineau , "Matthieu Baerts (NGI0)" X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=openpgp-sha256; l=1184; i=matttbe@kernel.org; h=from:subject:message-id; bh=uCboPJ0LRaDIGMdWuBXqejhsmk8WqCnmSpXCIwZJHFI=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBlzfge/pF3aM0PypTWAngC+cOFobG6J8uvf0s3K WzbPlVN9RWJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZc34HgAKCRD2t4JPQmmg cwMqD/4keG0Z57qB3VeJjvDaRFgQI9uQK1cqPTBjfdpcI47nQi/lROp9scWB/qp285l2soY+d0S kvsL2JLDabr0PsW2+uJtY/m4zPsPi3RI5dl0dsVx0EFNQXo45+XfEwJ9OnH+YHmPoK2jdzfercG 6BsUm/SwW8WrtYOjVCWJcdwzB9fBZ3mxQY8Q/Vf2b5O/vSXYs8eCnPxZtrQIoBI5GRZJf3/2H33 c/4Z3/xsdPkFDwENumU3Ajv2tM+zhQXlkCIf8BDGUPYIbi+3/rgdElqWbukTap6EDE2aurllYA2 mhhCDTjruomt1DVLU+8DoFKAozGb3LPNDpaclwUfkirdkO9a+1PjHZO/cjQMNIuqfjXmR2z/KG6 AOjxrRELXD7KO77t0wfxFsNwFofDGyaXbzUGDmtSU2hnQISpHAdug7owVy8YK4o+FeqENzWRtbL smekq4mgcgoU4o1tAsaeAJqzZKn2LP7VkCGEkdV9c1lFS4rUbJSa2mVCDxfzwfwsyUvzZmoTEkg VzReA5Or5GcZfZUnHgBuuLZvDFBvHSntPLsgvXs34phRgHamMeb+o6GV7DdnNnMD4sA9kzl8T/n 2Y691jrL+vg52jYzqRarjywYluYlxQrGH5levAL9O2XxgYO/iIMMwGUKwHeQ6Bu2EG3sk/Wyqb6 gqkQ2M/olYXDRlw== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 As it would be done when initiating an MPTCP sock. This is not strictly needed for this test, but it will be when a later patch will check if the right protocol is being used when calling mptcp_sk(). Signed-off-by: Matthieu Baerts (NGI0) Reviewed-by: Mat Martineau --- net/mptcp/token_test.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/net/mptcp/token_test.c b/net/mptcp/token_test.c index bfff53e668da..4fc39fa2e262 100644 --- a/net/mptcp/token_test.c +++ b/net/mptcp/token_test.c @@ -52,14 +52,19 @@ static struct mptcp_subflow_context *build_ctx(struct k= unit *test) static struct mptcp_sock *build_msk(struct kunit *test) { struct mptcp_sock *msk; + struct sock *sk; =20 msk =3D kunit_kzalloc(test, sizeof(struct mptcp_sock), GFP_USER); KUNIT_EXPECT_NOT_ERR_OR_NULL(test, msk); refcount_set(&((struct sock *)msk)->sk_refcnt, 1); sock_net_set((struct sock *)msk, &init_net); =20 + sk =3D (struct sock *)msk; + /* be sure the token helpers can dereference sk->sk_prot */ - ((struct sock *)msk)->sk_prot =3D &tcp_prot; + sk->sk_prot =3D &tcp_prot; + sk->sk_protocol =3D IPPROTO_MPTCP; + return msk; } =20 --=20 2.43.0 From nobody Sun May 19 00:47:40 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 2B8934A08 for ; Thu, 15 Feb 2024 11:40:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707997221; cv=none; b=DtnEygwPxclzGLe+9+NdFYhfEpgzfxosNGvtbfo5Wh5Jz6pe9QJl7cKP+pepIWVFQoSGo7rBzgEf3np3VGM4/QYO5ypcyYHNCjsEwXaSJwLeh1ISHLBWAKBFOkqRU4OieDbiIr06Mdi3WX4+R9xKcl7pAfEdP3kJ3zM12gX8VFE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707997221; c=relaxed/simple; bh=V9U8JdYBuAENa7dPeEa3fBLaft+F3rz8fQrkjeJFwY0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=hyO2/wb4yRHcMeEGe/bWQtxSc0xHGEQXcn9Lf7c+AQWg/ClmQrnZLcgDHqJiO5dsd0IbDtHXoLLxba1wrA07dwWJ7GXGldwFfrPcBomZscFTrjMnPUtMv8r5xEJB/DGt2jqPoiAScMNlGx8+Q0xSdIfAWXv1PaCRuNGcN6qg0KU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dTPGW923; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="dTPGW923" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C3024C433F1; Thu, 15 Feb 2024 11:40:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707997220; bh=V9U8JdYBuAENa7dPeEa3fBLaft+F3rz8fQrkjeJFwY0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=dTPGW923SyWclM7OdOEBOZFMxc5avFUOWFWEKJqyapi3SvT9j9UpJzfwIqPaO/ozY s37nF8tu41dAx3sXoz+j38T0YQeySoI5Z/dgtyreimXisp1pzFFnD+zIiIaBrzmauR W5f4HeTYhNa0e8PHJ85fxMkeSbSmJar66wiBepuecMWFAyeZsxrZ9LAxhk5kXqtg9I 0mHZDEvIsaNQ7lF/e/G/P6eOvGZ2nE0wulsuFYs+f58HmZTjTOAflHhNtzulGRiZFV xNxDlPxvqyTtRw+KujOLtcPOwsEHrnY8dWEIWQWhYF0hpenbmEa3G34aaiUmxg9Zeg Ex/+bwifjBIGQ== From: "Matthieu Baerts (NGI0)" Date: Thu, 15 Feb 2024 12:40:03 +0100 Subject: [PATCH mptcp-next v4 2/3] mptcp: check the protocol in tcp_sk() with DEBUG_NET Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240215-mptcp-check-protocol-v4-2-16e932665e21@kernel.org> References: <20240215-mptcp-check-protocol-v4-0-16e932665e21@kernel.org> In-Reply-To: <20240215-mptcp-check-protocol-v4-0-16e932665e21@kernel.org> To: mptcp@lists.linux.dev Cc: Mat Martineau , "Matthieu Baerts (NGI0)" X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=openpgp-sha256; l=2228; i=matttbe@kernel.org; h=from:subject:message-id; bh=V9U8JdYBuAENa7dPeEa3fBLaft+F3rz8fQrkjeJFwY0=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBlzfge7sANFnV17/WO8Y/k3xc3xSDFxC3//jFR7 tp3lgOKc02JAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZc34HgAKCRD2t4JPQmmg cy49EACd3mQBJH6XVttA7IOkBGv7bJaovBGPnZigYVF0pe9VFaHMbdOBKvVMQjh3koKv7sP4WV7 n5o+IFZiv+SUwZA0qxGX6kVc4kGrBD9S/gGWzIZFjogLmQEZmFD1fK09UuhsGdMwihoNamVplSK QHy9PLT9KTbX0Sh4II1Euett+ZMV1I3HO4qKhR3D3ZdkSyLwF8zzxRweQyIwpxUKvX9ys1IVG0o XT/4fAOGTbROzZlJ5gzN4t1zaro+2KG9FeL0Jjwzw+lIOqKFmv2PfnNDGvCLhUwFsJz/rbMBvhI 2tADvgeDfqqauUwEDPhzTItMOU+xz7WP88j6LO0fhXs1k8Fr7LZjx0QpfLQNnH+U+OQ6DQ3/1lA AjUjlb20HgaHOGxo0FhGcB9PL1m+Y7sKSV1E58rw1eFUddDjgUyt7qA5KpJtlmuwsVQMy5lTpmI ATBqOpm10+f11wYc1EPLCGvpqaGyOhoW4RVbuT8rSeKarQWnLr3ehLh6VafyEBTRzWA7dZayhqw CeFJW7dsPHKSc/oCJKUG4Y1EAfZIIZSu75juXxlGogmh6ZZLo5GN/Ev+Fb/x6LWW+xBHbyHDDpQ 9u5WIcnjuZw4nF6MNHO5xNzCF+YQ47vztCqYNQRqFcat+NvAl0XsVPUb8+zuqgwRab9du4k0bT+ TOc/0u+BZOxyUVA== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 Fuzzers and static checkers might not detect when tcp_sk() is used with a non tcp_sock structure. This kind of mistake already happened a few times with MPTCP: when wrongly using TCP-specific helpers with mptcp_sock pointers. On the other hand, there are many 'tcp_xxx()' helpers that are taking a 'struct sock' pointer as arguments, and some of them are only looking at fields from 'struct sock', and nothing from 'struct tcp_sock'. It is then tempting to use them with a 'struct mptcp_sock'. So a new simple check is done when CONFIG_DEBUG_NET is enabled to tell kernel devs when a non-TCP socket is being used as a TCP one. 'tcp_sk()' macro is then re-defined to add a WARN when an unexpected socket is being used. Signed-off-by: Matthieu Baerts (NGI0) Reviewed-by: Mat Martineau --- Notes: - v2: - Move from include/linux/tcp.h to net/mptcp/protocol.h: specific to TCP (Paolo) - Use a macro instead of an inlined function (Paolo) - Adapt the commit message after the recent changes. - v3: - add parenthesis around 'ptr' (checkpatch) - there is still this check from checkpatch but I guess that's fine: Macro argument reuse 'ptr' - possible side-effects? - v4: - avoid reusing 'ptr' to fix checkpatch warning (Mat) - remove extra parenthesis in WARN_ON, no longer needed --- net/mptcp/protocol.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 486fff865803..32cf98bd2961 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -348,6 +348,16 @@ static inline void msk_owned_by_me(const struct mptcp_= sock *msk) sock_owned_by_me((const struct sock *)msk); } =20 +#ifdef CONFIG_DEBUG_NET +/* MPTCP-specific: we might (indirectly) call this helper with the wrong s= k */ +#undef tcp_sk +#define tcp_sk(ptr) ({ \ + typeof(ptr) _ptr =3D (ptr); \ + WARN_ON(_ptr->sk_protocol !=3D IPPROTO_TCP); \ + container_of_const(_ptr, struct tcp_sock, inet_conn.icsk_inet.sk); \ +}) +#endif + #define mptcp_sk(ptr) container_of_const(ptr, struct mptcp_sock, sk.icsk_i= net.sk) =20 /* the msk socket don't use the backlog, also account for the bulk --=20 2.43.0 From nobody Sun May 19 00:47:40 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 52C1E433B1 for ; Thu, 15 Feb 2024 11:40:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707997223; cv=none; b=X7y2htkaQrBVhUj3TKPM04Qsxj8rZOkYOFCs4H++7Ylh/4RD9dytSKqr5JqTBTA9BmKnuvl04hckRjOIZ1qeLj8crnrfML0JVDQODRGdn3fi39QUxHlSmhiW86si82vAOYxDH7YN+nu5wECFIusCkKXtgT8aY8eP3ZHtprZFOSg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707997223; c=relaxed/simple; bh=yn3HDvwvTHvw/SrDF028FlsUMAUFy1J3KeYXRRH+gkc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FwDohMZ7dsiRqlfszxTIoGDVCcXXtm+fqxm4w3mjhfdJ9AiKpENs3+PISGU2wVOqo5vFqGFrsZcvs6KVQchYfnxn28Ts8+V7UdQZ78x0opCW1jPAQdD3jq0i31KeRW6u24e2BDWfsfxSj+qz3CJ5Jm2K2jNuodPZxw9BlQuG4UY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dX7G+KlX; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="dX7G+KlX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 449F7C43390; Thu, 15 Feb 2024 11:40:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707997222; bh=yn3HDvwvTHvw/SrDF028FlsUMAUFy1J3KeYXRRH+gkc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=dX7G+KlXQZA/hr7bkU2N9d7WauuuYEuhMAbk6r9sNvQyvpRYlXQmfeLYK1LKht8UH EkFZ5Anj9ckRYSCRsQin4DhVB/lopcvTYNMUo+u3hQqyMjuT7RdPWMxNtSCH+63fxN sV2lQQKhbLWreSn3ACWlGCjo8tcvyq74pXK8CSoAbEMvZ8NRNSQN6YTF0OZjV1KdRi 8/5G+e54oD995OYOAE3Uo0soZsAAbVADYmrjGNGwWrMtbKyfDvFttZ/QETMCRL9pBz 0G/LA0GpkBJhtNZ98mo9JamFz4DSySgeHAmuHVNHlqdRNAoLHgQFcxQt+MLGU9P5Ig ogEDjRifnfZVg== From: "Matthieu Baerts (NGI0)" Date: Thu, 15 Feb 2024 12:40:04 +0100 Subject: [PATCH mptcp-next v4 3/3] mptcp: check the protocol in mptcp_sk() with DEBUG_NET Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240215-mptcp-check-protocol-v4-3-16e932665e21@kernel.org> References: <20240215-mptcp-check-protocol-v4-0-16e932665e21@kernel.org> In-Reply-To: <20240215-mptcp-check-protocol-v4-0-16e932665e21@kernel.org> To: mptcp@lists.linux.dev Cc: Mat Martineau , "Matthieu Baerts (NGI0)" X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=openpgp-sha256; l=1844; i=matttbe@kernel.org; h=from:subject:message-id; bh=yn3HDvwvTHvw/SrDF028FlsUMAUFy1J3KeYXRRH+gkc=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBlzfgegJeJn1g2jr79HtrcYJVxYgoFFbQMJcfhO OwTT5fSZUuJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZc34HgAKCRD2t4JPQmmg cyvPEACaBTsNhBoosy5nFvIucifZ9Gl5zV1JYaIMDSnM5OQpL4vpg/IpPcYPaIzwdtQmE/BTzSw W0gxvk849vhyEaMIJRKHbCUZ0QPEkrAuzSCXocSWZ2yWNDlQrD+rENLHrrMHOfLYh5ykLsBZNED Pk5sDMadtKKqXm4ZmEvkZ9lhtDH4FzO8jc4DgprYl8cBH+sA1PdIPCh9FDKOPEmwiO+ifeSpVSf 4K5CKDocjuhRqnSwnFK9YFDenSiJK/AsucBx6fMh0y6Eo11wezq8h5IM0oEqIUzVBfRYpZpH+4l wSQ2Omn/oeW8HpwTYLmHWyW73DzzwGuVkohEX2V+NiNyH0VxwosL74UIuCZdln7xYarWA+moT0B d0mLv9cJj++ec4zMjgdRlFC+AAZkYCZ2Mo11mNGDYYXWW6VpccUO3wcgwP9rcnpVpfxVvARE3I8 gnfi71QqgJLKMghDMwFQDWOzNs7icvKDuQkECAKEgahD3d02k2vp0X61cVg3FuVYL4pWC5vAH/i S+llN84t1wKnQx9epXbKW+OEXz4QqsWjO37VeVe7VyyszCr1DmzKhGEWrfyeoNgcJju6jqa4zQs /16HUFaaPoM7O6YF5zH/ynkFVZMoljkDBTQhxzAeNb/p0nf7QKa361NK6kCXjkAp8IK1+6Q7iKd xZGsQ7MCYoZ+KaQ== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 Fuzzers and static checkers might not detect when mptcp_sk() is used with a non mptcp_sock structure. This is similar to the parent commit, where it is easy to use mptcp_sk() with a TCP sock, e.g. with a subflow sk. So a new simple check is done when CONFIG_DEBUG_NET is enabled to tell kernel devs when a non-MPTCP socket is being used as an MPTCP one. 'mptcp_sk()' macro is then defined differently: with an extra WARN to complain when an unexpected socket is being used. Signed-off-by: Matthieu Baerts (NGI0) Reviewed-by: Mat Martineau --- Notes: - v2: - Use a macro instead of an inlined function (Paolo) - v3: - add parenthesis around 'ptr' (checkpatch) - there is still this check from checkpatch but I guess that's fine: Macro argument reuse 'ptr' - possible side-effects? - v4: - avoid reusing 'ptr' to fix checkpatch warning (Mat) - remove extra parenthesis in WARN_ON, no longer needed --- net/mptcp/protocol.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 32cf98bd2961..459859b107ba 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -356,9 +356,15 @@ static inline void msk_owned_by_me(const struct mptcp_= sock *msk) WARN_ON(_ptr->sk_protocol !=3D IPPROTO_TCP); \ container_of_const(_ptr, struct tcp_sock, inet_conn.icsk_inet.sk); \ }) -#endif +#define mptcp_sk(ptr) ({ \ + typeof(ptr) _ptr =3D (ptr); \ + WARN_ON(_ptr->sk_protocol !=3D IPPROTO_MPTCP); \ + container_of_const(_ptr, struct mptcp_sock, sk.icsk_inet.sk); \ +}) =20 +#else /* !CONFIG_DEBUG_NET */ #define mptcp_sk(ptr) container_of_const(ptr, struct mptcp_sock, sk.icsk_i= net.sk) +#endif =20 /* the msk socket don't use the backlog, also account for the bulk * free memory --=20 2.43.0