All of lore.kernel.org
 help / color / mirror / Atom feed
From: Deepa Dinamani <deepa.kernel@gmail.com>
To: netdev@vger.kernel.org, y2038@lists.linaro.org
Cc: arnd@arndb.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 2/4] net: ipv4: Use y2038 safe functions and data structures
Date: Wed, 24 Feb 2016 23:07:09 -0800	[thread overview]
Message-ID: <1456384031-29244-3-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 UT format.

Timestamps are calculated from realtime by making a call
to getnstimeofday() which uses struct timespec.
timespec is not y2038 safe.
Replace the above calls with y2038 safe current_nw_time() to
obtain network timestamps which uses y2038 safe struct timespec64.

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: James Morris <jmorris@namei.org>
Cc: Hideaki YOSHIFUJI <yoshfuji@linux-ipv6.org>
Cc: Patrick McHardy <kaber@trash.net>
---
 net/ipv4/icmp.c       |  5 +----
 net/ipv4/ip_options.c | 13 +++++--------
 2 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c
index 36e2697..e43dfa3 100644
--- a/net/ipv4/icmp.c
+++ b/net/ipv4/icmp.c
@@ -931,7 +931,6 @@ static bool icmp_echo(struct sk_buff *skb)
  */
 static bool icmp_timestamp(struct sk_buff *skb)
 {
-	struct timespec tv;
 	struct icmp_bxm icmp_param;
 	/*
 	 *	Too short.
@@ -942,9 +941,7 @@ static bool icmp_timestamp(struct sk_buff *skb)
 	/*
 	 *	Fill in the current time as ms since midnight UT:
 	 */
-	getnstimeofday(&tv);
-	icmp_param.data.times[1] = htonl((tv.tv_sec % 86400) * MSEC_PER_SEC +
-					 tv.tv_nsec / NSEC_PER_MSEC);
+	icmp_param.data.times[1] = current_nw_timestamp();
 	icmp_param.data.times[2] = icmp_param.data.times[1];
 	if (skb_copy_bits(skb, 0, &icmp_param.data.times[0], 4))
 		BUG();
diff --git a/net/ipv4/ip_options.c b/net/ipv4/ip_options.c
index bd24679..6958e7c 100644
--- a/net/ipv4/ip_options.c
+++ b/net/ipv4/ip_options.c
@@ -58,10 +58,8 @@ void ip_options_build(struct sk_buff *skb, struct ip_options *opt,
 		if (opt->ts_needaddr)
 			ip_rt_get_source(iph+opt->ts+iph[opt->ts+2]-9, skb, rt);
 		if (opt->ts_needtime) {
-			struct timespec tv;
 			__be32 midtime;
-			getnstimeofday(&tv);
-			midtime = htonl((tv.tv_sec % 86400) * MSEC_PER_SEC + tv.tv_nsec / NSEC_PER_MSEC);
+			midtime = current_nw_timestamp();
 			memcpy(iph+opt->ts+iph[opt->ts+2]-5, &midtime, 4);
 		}
 		return;
@@ -415,11 +413,10 @@ int ip_options_compile(struct net *net,
 					break;
 				}
 				if (timeptr) {
-					struct timespec tv;
-					u32  midtime;
-					getnstimeofday(&tv);
-					midtime = (tv.tv_sec % 86400) * MSEC_PER_SEC + tv.tv_nsec / NSEC_PER_MSEC;
-					put_unaligned_be32(midtime, timeptr);
+					__be32  midtime;
+
+					midtime = current_nw_timestamp();
+					memcpy(timeptr, &midtime, 4);
 					opt->is_changed = 1;
 				}
 			} else if ((optptr[3]&0xF) != IPOPT_TS_PRESPEC) {
-- 
1.9.1

  parent reply	other threads:[~2016-02-25  7:09 UTC|newest]

Thread overview: 20+ 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
2016-02-25  7:07 ` [PATCH 1/4] kernel: time: Add current_nw_timestamp() for network timestamps Deepa Dinamani
2016-02-25  8:49   ` 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 ` Deepa Dinamani [this message]
2016-02-25 14:57   ` [PATCH 2/4] net: ipv4: Use y2038 safe functions and data structures 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  7:07   ` Deepa Dinamani
2016-02-25 14:09   ` Neil Horman
2016-02-25 14:09     ` Neil Horman
2016-02-25 14:56   ` [Y2038] " Arnd Bergmann
2016-02-25 14:56     ` Arnd Bergmann
2016-02-26 20:19 ` [PATCH 0/4] Convert network " David Miller
2016-02-26 20:19   ` 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-3-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=kaber@trash.net \
    --cc=kuznet@ms2.inr.ac.ru \
    --cc=netdev@vger.kernel.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.