diff options
author | Soheil Hassas Yeganeh <soheil@google.com> | 2016-04-02 23:08:12 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2016-04-04 15:50:30 -0400 |
commit | c14ac9451c34832554db33386a4393be8bba3a7b (patch) | |
tree | 99f4d7c46d01732fcbfdf8de89e1d9846d56c3b3 /net/ipv4/udp.c | |
parent | ad1e46a837163a3e7160a1250825bcfafd2e714b (diff) |
sock: enable timestamping using control messages
Currently, SOL_TIMESTAMPING can only be enabled using setsockopt.
This is very costly when users want to sample writes to gather
tx timestamps.
Add support for enabling SO_TIMESTAMPING via control messages by
using tsflags added in `struct sockcm_cookie` (added in the previous
patches in this series) to set the tx_flags of the last skb created in
a sendmsg. With this patch, the timestamp recording bits in tx_flags
of the skbuff is overridden if SO_TIMESTAMPING is passed in a cmsg.
Please note that this is only effective for overriding the recording
timestamps flags. Users should enable timestamp reporting (e.g.,
SOF_TIMESTAMPING_SOFTWARE | SOF_TIMESTAMPING_OPT_ID) using
socket options and then should ask for SOF_TIMESTAMPING_TX_*
using control messages per sendmsg to sample timestamps for each
write.
Signed-off-by: Soheil Hassas Yeganeh <soheil@google.com>
Acked-by: Willem de Bruijn <willemb@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4/udp.c')
-rw-r--r-- | net/ipv4/udp.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index bccb4e11047a..45ff590661f4 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c | |||
@@ -1027,12 +1027,11 @@ int udp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) | |||
1027 | */ | 1027 | */ |
1028 | connected = 1; | 1028 | connected = 1; |
1029 | } | 1029 | } |
1030 | ipc.addr = inet->inet_saddr; | ||
1031 | 1030 | ||
1031 | ipc.sockc.tsflags = sk->sk_tsflags; | ||
1032 | ipc.addr = inet->inet_saddr; | ||
1032 | ipc.oif = sk->sk_bound_dev_if; | 1033 | ipc.oif = sk->sk_bound_dev_if; |
1033 | 1034 | ||
1034 | sock_tx_timestamp(sk, &ipc.tx_flags); | ||
1035 | |||
1036 | if (msg->msg_controllen) { | 1035 | if (msg->msg_controllen) { |
1037 | err = ip_cmsg_send(sk, msg, &ipc, sk->sk_family == AF_INET6); | 1036 | err = ip_cmsg_send(sk, msg, &ipc, sk->sk_family == AF_INET6); |
1038 | if (unlikely(err)) { | 1037 | if (unlikely(err)) { |
@@ -1059,6 +1058,8 @@ int udp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) | |||
1059 | saddr = ipc.addr; | 1058 | saddr = ipc.addr; |
1060 | ipc.addr = faddr = daddr; | 1059 | ipc.addr = faddr = daddr; |
1061 | 1060 | ||
1061 | sock_tx_timestamp(sk, ipc.sockc.tsflags, &ipc.tx_flags); | ||
1062 | |||
1062 | if (ipc.opt && ipc.opt->opt.srr) { | 1063 | if (ipc.opt && ipc.opt->opt.srr) { |
1063 | if (!daddr) | 1064 | if (!daddr) |
1064 | return -EINVAL; | 1065 | return -EINVAL; |