netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] net: Implement missing getsockopt(SO_TIMESTAMPING_NEW)
@ 2023-12-21 23:19 Jörn-Thorben Hinz
  2023-12-22 15:03 ` Willem de Bruijn
  2024-01-02 13:30 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Jörn-Thorben Hinz @ 2023-12-21 23:19 UTC (permalink / raw)
  To: netdev, linux-kernel
  Cc: Jörn-Thorben Hinz, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Willem de Bruijn, Deepa Dinamani

Commit 9718475e6908 ("socket: Add SO_TIMESTAMPING_NEW") added the new
socket option SO_TIMESTAMPING_NEW. Setting the option is handled in
sk_setsockopt(), querying it was not handled in sk_getsockopt(), though.

Following remarks on an earlier submission of this patch, keep the old
behavior of getsockopt(SO_TIMESTAMPING_OLD) which returns the active
flags even if they actually have been set through SO_TIMESTAMPING_NEW.

The new getsockopt(SO_TIMESTAMPING_NEW) is stricter, returning flags
only if they have been set through the same option.

Fixes: 9718475e6908 ("socket: Add SO_TIMESTAMPING_NEW")
Link: https://lore.kernel.org/lkml/20230703175048.151683-1-jthinz@mailbox.tu-berlin.de/
Link: https://lore.kernel.org/netdev/0d7cddc9-03fa-43db-a579-14f3e822615b@app.fastmail.com/
Signed-off-by: Jörn-Thorben Hinz <jthinz@mailbox.tu-berlin.de>
---
 net/core/sock.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/net/core/sock.c b/net/core/sock.c
index fef349dd72fa..51d52859e942 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -1711,9 +1711,16 @@ int sk_getsockopt(struct sock *sk, int level, int optname,
 		break;
 
 	case SO_TIMESTAMPING_OLD:
+	case SO_TIMESTAMPING_NEW:
 		lv = sizeof(v.timestamping);
-		v.timestamping.flags = READ_ONCE(sk->sk_tsflags);
-		v.timestamping.bind_phc = READ_ONCE(sk->sk_bind_phc);
+		/* For the later-added case SO_TIMESTAMPING_NEW: Be strict about only
+		 * returning the flags when they were set through the same option.
+		 * Don't change the beviour for the old case SO_TIMESTAMPING_OLD.
+		 */
+		if (optname == SO_TIMESTAMPING_OLD || sock_flag(sk, SOCK_TSTAMP_NEW)) {
+			v.timestamping.flags = READ_ONCE(sk->sk_tsflags);
+			v.timestamping.bind_phc = READ_ONCE(sk->sk_bind_phc);
+		}
 		break;
 
 	case SO_RCVTIMEO_OLD:
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net] net: Implement missing getsockopt(SO_TIMESTAMPING_NEW)
  2023-12-21 23:19 [PATCH net] net: Implement missing getsockopt(SO_TIMESTAMPING_NEW) Jörn-Thorben Hinz
@ 2023-12-22 15:03 ` Willem de Bruijn
  2024-01-02 13:30 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Willem de Bruijn @ 2023-12-22 15:03 UTC (permalink / raw)
  To: Jörn-Thorben Hinz, netdev, linux-kernel
  Cc: Jörn-Thorben Hinz, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Willem de Bruijn, Deepa Dinamani

Jörn-Thorben Hinz wrote:
> Commit 9718475e6908 ("socket: Add SO_TIMESTAMPING_NEW") added the new
> socket option SO_TIMESTAMPING_NEW. Setting the option is handled in
> sk_setsockopt(), querying it was not handled in sk_getsockopt(), though.
> 
> Following remarks on an earlier submission of this patch, keep the old
> behavior of getsockopt(SO_TIMESTAMPING_OLD) which returns the active
> flags even if they actually have been set through SO_TIMESTAMPING_NEW.
> 
> The new getsockopt(SO_TIMESTAMPING_NEW) is stricter, returning flags
> only if they have been set through the same option.
> 
> Fixes: 9718475e6908 ("socket: Add SO_TIMESTAMPING_NEW")
> Link: https://lore.kernel.org/lkml/20230703175048.151683-1-jthinz@mailbox.tu-berlin.de/
> Link: https://lore.kernel.org/netdev/0d7cddc9-03fa-43db-a579-14f3e822615b@app.fastmail.com/
> Signed-off-by: Jörn-Thorben Hinz <jthinz@mailbox.tu-berlin.de>

Reviewed-by: Willem de Bruijn <willemb@google.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net] net: Implement missing getsockopt(SO_TIMESTAMPING_NEW)
  2023-12-21 23:19 [PATCH net] net: Implement missing getsockopt(SO_TIMESTAMPING_NEW) Jörn-Thorben Hinz
  2023-12-22 15:03 ` Willem de Bruijn
@ 2024-01-02 13:30 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-01-02 13:30 UTC (permalink / raw)
  To: =?utf-8?q?J=C3=B6rn-Thorben_Hinz_=3Cjthinz=40mailbox=2Etu-berlin=2Ede=3E?=
  Cc: netdev, linux-kernel, davem, edumazet, kuba, pabeni, willemb,
	deepa.kernel

Hello:

This patch was applied to netdev/net.git (main)
by David S. Miller <davem@davemloft.net>:

On Fri, 22 Dec 2023 00:19:01 +0100 you wrote:
> Commit 9718475e6908 ("socket: Add SO_TIMESTAMPING_NEW") added the new
> socket option SO_TIMESTAMPING_NEW. Setting the option is handled in
> sk_setsockopt(), querying it was not handled in sk_getsockopt(), though.
> 
> Following remarks on an earlier submission of this patch, keep the old
> behavior of getsockopt(SO_TIMESTAMPING_OLD) which returns the active
> flags even if they actually have been set through SO_TIMESTAMPING_NEW.
> 
> [...]

Here is the summary with links:
  - [net] net: Implement missing getsockopt(SO_TIMESTAMPING_NEW)
    https://git.kernel.org/netdev/net/c/7f6ca95d16b9

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-01-02 13:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-21 23:19 [PATCH net] net: Implement missing getsockopt(SO_TIMESTAMPING_NEW) Jörn-Thorben Hinz
2023-12-22 15:03 ` Willem de Bruijn
2024-01-02 13:30 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).