Commit 783da70e authored by Christoph Hellwig's avatar Christoph Hellwig Committed by David S. Miller

net: add sock_enable_timestamps

Add a helper to directly enable timestamps instead of setting the
SO_TIMESTAMP* sockopts from kernel space and going through a fake
uaccess.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 7594888c
...@@ -2689,6 +2689,7 @@ static inline bool sk_dev_equal_l3scope(struct sock *sk, int dif) ...@@ -2689,6 +2689,7 @@ static inline bool sk_dev_equal_l3scope(struct sock *sk, int dif)
void sock_def_readable(struct sock *sk); void sock_def_readable(struct sock *sk);
int sock_bindtoindex(struct sock *sk, int ifindex); int sock_bindtoindex(struct sock *sk, int ifindex);
void sock_enable_timestamps(struct sock *sk);
void sock_no_linger(struct sock *sk); void sock_no_linger(struct sock *sk);
void sock_set_priority(struct sock *sk, u32 priority); void sock_set_priority(struct sock *sk, u32 priority);
void sock_set_reuseaddr(struct sock *sk); void sock_set_reuseaddr(struct sock *sk);
......
...@@ -757,6 +757,28 @@ void sock_set_sndtimeo(struct sock *sk, s64 secs) ...@@ -757,6 +757,28 @@ void sock_set_sndtimeo(struct sock *sk, s64 secs)
} }
EXPORT_SYMBOL(sock_set_sndtimeo); EXPORT_SYMBOL(sock_set_sndtimeo);
static void __sock_set_timestamps(struct sock *sk, bool val, bool new, bool ns)
{
if (val) {
sock_valbool_flag(sk, SOCK_TSTAMP_NEW, new);
sock_valbool_flag(sk, SOCK_RCVTSTAMPNS, ns);
sock_set_flag(sk, SOCK_RCVTSTAMP);
sock_enable_timestamp(sk, SOCK_TIMESTAMP);
} else {
sock_reset_flag(sk, SOCK_RCVTSTAMP);
sock_reset_flag(sk, SOCK_RCVTSTAMPNS);
sock_reset_flag(sk, SOCK_TSTAMP_NEW);
}
}
void sock_enable_timestamps(struct sock *sk)
{
lock_sock(sk);
__sock_set_timestamps(sk, true, false, true);
release_sock(sk);
}
EXPORT_SYMBOL(sock_enable_timestamps);
/* /*
* This is meant for all protocols to use and covers goings on * This is meant for all protocols to use and covers goings on
* at the socket level. Everything here is generic. * at the socket level. Everything here is generic.
...@@ -948,28 +970,17 @@ int sock_setsockopt(struct socket *sock, int level, int optname, ...@@ -948,28 +970,17 @@ int sock_setsockopt(struct socket *sock, int level, int optname,
break; break;
case SO_TIMESTAMP_OLD: case SO_TIMESTAMP_OLD:
__sock_set_timestamps(sk, valbool, false, false);
break;
case SO_TIMESTAMP_NEW: case SO_TIMESTAMP_NEW:
__sock_set_timestamps(sk, valbool, true, false);
break;
case SO_TIMESTAMPNS_OLD: case SO_TIMESTAMPNS_OLD:
__sock_set_timestamps(sk, valbool, false, true);
break;
case SO_TIMESTAMPNS_NEW: case SO_TIMESTAMPNS_NEW:
if (valbool) { __sock_set_timestamps(sk, valbool, true, true);
if (optname == SO_TIMESTAMP_NEW || optname == SO_TIMESTAMPNS_NEW)
sock_set_flag(sk, SOCK_TSTAMP_NEW);
else
sock_reset_flag(sk, SOCK_TSTAMP_NEW);
if (optname == SO_TIMESTAMP_OLD || optname == SO_TIMESTAMP_NEW)
sock_reset_flag(sk, SOCK_RCVTSTAMPNS);
else
sock_set_flag(sk, SOCK_RCVTSTAMPNS);
sock_set_flag(sk, SOCK_RCVTSTAMP);
sock_enable_timestamp(sk, SOCK_TIMESTAMP);
} else {
sock_reset_flag(sk, SOCK_RCVTSTAMP);
sock_reset_flag(sk, SOCK_RCVTSTAMPNS);
sock_reset_flag(sk, SOCK_TSTAMP_NEW);
}
break; break;
case SO_TIMESTAMPING_NEW: case SO_TIMESTAMPING_NEW:
sock_set_flag(sk, SOCK_TSTAMP_NEW); sock_set_flag(sk, SOCK_TSTAMP_NEW);
/* fall through */ /* fall through */
......
...@@ -189,13 +189,7 @@ static int rxrpc_open_socket(struct rxrpc_local *local, struct net *net) ...@@ -189,13 +189,7 @@ static int rxrpc_open_socket(struct rxrpc_local *local, struct net *net)
} }
/* We want receive timestamps. */ /* We want receive timestamps. */
opt = 1; sock_enable_timestamps(local->socket->sk);
ret = kernel_setsockopt(local->socket, SOL_SOCKET, SO_TIMESTAMPNS_OLD,
(char *)&opt, sizeof(opt));
if (ret < 0) {
_debug("setsockopt failed");
goto error;
}
break; break;
default: default:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment