Skip to content

Commit 7f6ca95

Browse files
jtdordavem330
authored andcommitted
net: Implement missing getsockopt(SO_TIMESTAMPING_NEW)
Commit 9718475 ("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: 9718475 ("socket: Add SO_TIMESTAMPING_NEW") Link: https://lore.kernel.org/lkml/[email protected]/ Link: https://lore.kernel.org/netdev/[email protected]/ Signed-off-by: Jörn-Thorben Hinz <[email protected]> Reviewed-by: Willem de Bruijn <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 9bf2e91 commit 7f6ca95

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

net/core/sock.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,9 +1711,16 @@ int sk_getsockopt(struct sock *sk, int level, int optname,
17111711
break;
17121712

17131713
case SO_TIMESTAMPING_OLD:
1714+
case SO_TIMESTAMPING_NEW:
17141715
lv = sizeof(v.timestamping);
1715-
v.timestamping.flags = READ_ONCE(sk->sk_tsflags);
1716-
v.timestamping.bind_phc = READ_ONCE(sk->sk_bind_phc);
1716+
/* For the later-added case SO_TIMESTAMPING_NEW: Be strict about only
1717+
* returning the flags when they were set through the same option.
1718+
* Don't change the beviour for the old case SO_TIMESTAMPING_OLD.
1719+
*/
1720+
if (optname == SO_TIMESTAMPING_OLD || sock_flag(sk, SOCK_TSTAMP_NEW)) {
1721+
v.timestamping.flags = READ_ONCE(sk->sk_tsflags);
1722+
v.timestamping.bind_phc = READ_ONCE(sk->sk_bind_phc);
1723+
}
17171724
break;
17181725

17191726
case SO_RCVTIMEO_OLD:

0 commit comments

Comments
 (0)