mirror of
https://github.com/Fishwaldo/linux-bl808.git
synced 2025-06-17 20:25:19 +00:00
net: ipv4: Convert IP network timestamps to be y2038 safe
ICMP timestamp messages and IP source route options require timestamps to be in milliseconds modulo 24 hours from midnight UT format. Add inet_current_timestamp() function to support this. The function returns the required timestamp in network byte order. Timestamp calculation is also changed to call ktime_get_real_ts64() which uses struct timespec64. struct timespec64 is y2038 safe. Previously it called getnstimeofday() which uses struct timespec. struct timespec is not y2038 safe. Signed-off-by: Deepa Dinamani <deepa.kernel@gmail.com> Cc: "David S. Miller" <davem@davemloft.net> Cc: Alexey Kuznetsov <kuznet@ms2.inr.ac.ru> Cc: Hideaki YOSHIFUJI <yoshfuji@linux-ipv6.org> Cc: James Morris <jmorris@namei.org> Cc: Patrick McHardy <kaber@trash.net> Acked-by: YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org> Acked-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
e9c0d61d5f
commit
822c868532
4 changed files with 35 additions and 12 deletions
|
@ -1380,6 +1380,32 @@ out:
|
|||
return pp;
|
||||
}
|
||||
|
||||
#define SECONDS_PER_DAY 86400
|
||||
|
||||
/* inet_current_timestamp - Return IP network timestamp
|
||||
*
|
||||
* Return milliseconds since midnight in network byte order.
|
||||
*/
|
||||
__be32 inet_current_timestamp(void)
|
||||
{
|
||||
u32 secs;
|
||||
u32 msecs;
|
||||
struct timespec64 ts;
|
||||
|
||||
ktime_get_real_ts64(&ts);
|
||||
|
||||
/* Get secs since midnight. */
|
||||
(void)div_u64_rem(ts.tv_sec, SECONDS_PER_DAY, &secs);
|
||||
/* Convert to msecs. */
|
||||
msecs = secs * MSEC_PER_SEC;
|
||||
/* Convert nsec to msec. */
|
||||
msecs += (u32)ts.tv_nsec / NSEC_PER_MSEC;
|
||||
|
||||
/* Convert to network byte order. */
|
||||
return htons(msecs);
|
||||
}
|
||||
EXPORT_SYMBOL(inet_current_timestamp);
|
||||
|
||||
int inet_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len)
|
||||
{
|
||||
if (sk->sk_family == AF_INET)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue