From: Deepa Dinamani <deepa.kernel@gmail.com>
To: netdev@vger.kernel.org, y2038@lists.linaro.org
Cc: arnd@arndb.de, John Stultz <john.stultz@linaro.org>,
Thomas Gleixner <tglx@linutronix.de>,
"David S. Miller" <davem@davemloft.net>,
Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>,
James Morris <jmorris@namei.org>,
Hideaki YOSHIFUJI <yoshfuji@linux-ipv6.org>,
Patrick McHardy <kaber@trash.net>
Subject: [PATCH 1/4] kernel: time: Add current_nw_timestamp() for network timestamps
Date: Wed, 24 Feb 2016 23:07:08 -0800 [thread overview]
Message-ID: <1456384031-29244-2-git-send-email-deepa.kernel@gmail.com> (raw)
In-Reply-To: <1456384031-29244-1-git-send-email-deepa.kernel@gmail.com>
ICMP timestamp messages and IP source route options require
timestamps to be in milliseconds modulo 24 hours from
midnight UTC format.
Add a time function to support this. The function returns the
required timestamp in network byte order.
The function also uses y2038 safe time functions and data
structures.
Signed-off-by: Deepa Dinamani <deepa.kernel@gmail.com>
Cc: John Stultz <john.stultz@linaro.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
Cc: James Morris <jmorris@namei.org>
Cc: Hideaki YOSHIFUJI <yoshfuji@linux-ipv6.org>
Cc: Patrick McHardy <kaber@trash.net>
---
include/linux/ip.h | 2 ++
include/linux/time64.h | 3 +++
kernel/time/time.c | 26 ++++++++++++++++++++++++++
3 files changed, 31 insertions(+)
diff --git a/include/linux/ip.h b/include/linux/ip.h
index 492bc65..edf923e 100644
--- a/include/linux/ip.h
+++ b/include/linux/ip.h
@@ -34,4 +34,6 @@ static inline struct iphdr *ipip_hdr(const struct sk_buff *skb)
{
return (struct iphdr *)skb_transport_header(skb);
}
+
+extern __be32 current_nw_timestamp(void);
#endif /* _LINUX_IP_H */
diff --git a/include/linux/time64.h b/include/linux/time64.h
index 367d5af..5b5db3b 100644
--- a/include/linux/time64.h
+++ b/include/linux/time64.h
@@ -35,6 +35,9 @@ struct itimerspec64 {
#define NSEC_PER_SEC 1000000000L
#define FSEC_PER_SEC 1000000000000000LL
+#define SECONDS_PER_DAY 86400
+#define MSEC_PER_DAY (SECONDS_PER_DAY * MSEC_PER_SEC)
+
/* Located here for timespec[64]_valid_strict */
#define TIME64_MAX ((s64)~((u64)1 << 63))
#define KTIME_MAX ((s64)~((u64)1 << 63))
diff --git a/kernel/time/time.c b/kernel/time/time.c
index 86751c6..6df15df 100644
--- a/kernel/time/time.c
+++ b/kernel/time/time.c
@@ -245,6 +245,32 @@ struct timespec current_fs_time(struct super_block *sb)
EXPORT_SYMBOL(current_fs_time);
/*
+ * current_nw_timestamp - Return network time
+ *
+ * Return milliseconds since midnight in network byte order.
+ */
+__be32 current_nw_timestamp(void)
+{
+ u64 now;
+ u32 secs;
+ u32 msecs;
+ struct timespec64 ts;
+
+ ktime_get_ts64(&ts);
+
+ /* Get secs since midnight. */
+ now = 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(current_nw_timestamp);
+
+/*
* Convert jiffies to milliseconds and back.
*
* Avoid unnecessary multiplications/divisions in the
--
1.9.1
next prev parent reply other threads:[~2016-02-25 7:08 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-25 7:07 [PATCH 0/4] Convert network timestamps to be y2038 safe Deepa Dinamani
2016-02-25 7:07 ` Deepa Dinamani [this message]
2016-02-25 8:49 ` [PATCH 1/4] kernel: time: Add current_nw_timestamp() for network timestamps YOSHIFUJI Hideaki
2016-02-25 9:45 ` Deepa Dinamani
2016-02-26 6:49 ` YOSHIFUJI Hideaki/吉藤英明
2016-02-25 14:56 ` [Y2038] " Arnd Bergmann
2016-02-25 7:07 ` [PATCH 2/4] net: ipv4: Use y2038 safe functions and data structures Deepa Dinamani
2016-02-25 14:57 ` Arnd Bergmann
2016-02-25 7:07 ` [PATCH 3/4] net: ipv4: tcp_probe: Replace timespec with timespec64 Deepa Dinamani
2016-02-25 15:01 ` Arnd Bergmann
2016-02-27 2:56 ` Deepa Dinamani
2016-02-25 7:07 ` [PATCH 4/4] net: sctp: Convert log timestamps to be y2038 safe Deepa Dinamani
2016-02-25 14:09 ` Neil Horman
2016-02-25 14:56 ` [Y2038] " Arnd Bergmann
2016-02-26 20:19 ` [PATCH 0/4] Convert network " David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1456384031-29244-2-git-send-email-deepa.kernel@gmail.com \
--to=deepa.kernel@gmail.com \
--cc=arnd@arndb.de \
--cc=davem@davemloft.net \
--cc=jmorris@namei.org \
--cc=john.stultz@linaro.org \
--cc=kaber@trash.net \
--cc=kuznet@ms2.inr.ac.ru \
--cc=netdev@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=y2038@lists.linaro.org \
--cc=yoshfuji@linux-ipv6.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).