Commit 3dd7669f authored by Arnd Bergmann's avatar Arnd Bergmann Committed by David S. Miller

ipv6: use ktime_t for internal timestamps

The ipv6 mip6 implementation is one of only a few users of the
skb_get_timestamp() function in the kernel, which is both unsafe
on 32-bit architectures because of the 2038 overflow, and slightly
less efficient than the skb_get_ktime() based approach.

This converts the function call and the mip6_report_rate_limiter
structure that stores the time stamp, eliminating all uses of
timeval in the ipv6 code.
Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
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>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent f6389ecb
...@@ -118,7 +118,7 @@ static int mip6_mh_filter(struct sock *sk, struct sk_buff *skb) ...@@ -118,7 +118,7 @@ static int mip6_mh_filter(struct sock *sk, struct sk_buff *skb)
struct mip6_report_rate_limiter { struct mip6_report_rate_limiter {
spinlock_t lock; spinlock_t lock;
struct timeval stamp; ktime_t stamp;
int iif; int iif;
struct in6_addr src; struct in6_addr src;
struct in6_addr dst; struct in6_addr dst;
...@@ -184,20 +184,18 @@ static int mip6_destopt_output(struct xfrm_state *x, struct sk_buff *skb) ...@@ -184,20 +184,18 @@ static int mip6_destopt_output(struct xfrm_state *x, struct sk_buff *skb)
return 0; return 0;
} }
static inline int mip6_report_rl_allow(struct timeval *stamp, static inline int mip6_report_rl_allow(ktime_t stamp,
const struct in6_addr *dst, const struct in6_addr *dst,
const struct in6_addr *src, int iif) const struct in6_addr *src, int iif)
{ {
int allow = 0; int allow = 0;
spin_lock_bh(&mip6_report_rl.lock); spin_lock_bh(&mip6_report_rl.lock);
if (mip6_report_rl.stamp.tv_sec != stamp->tv_sec || if (!ktime_equal(mip6_report_rl.stamp, stamp) ||
mip6_report_rl.stamp.tv_usec != stamp->tv_usec ||
mip6_report_rl.iif != iif || mip6_report_rl.iif != iif ||
!ipv6_addr_equal(&mip6_report_rl.src, src) || !ipv6_addr_equal(&mip6_report_rl.src, src) ||
!ipv6_addr_equal(&mip6_report_rl.dst, dst)) { !ipv6_addr_equal(&mip6_report_rl.dst, dst)) {
mip6_report_rl.stamp.tv_sec = stamp->tv_sec; mip6_report_rl.stamp = stamp;
mip6_report_rl.stamp.tv_usec = stamp->tv_usec;
mip6_report_rl.iif = iif; mip6_report_rl.iif = iif;
mip6_report_rl.src = *src; mip6_report_rl.src = *src;
mip6_report_rl.dst = *dst; mip6_report_rl.dst = *dst;
...@@ -216,7 +214,7 @@ static int mip6_destopt_reject(struct xfrm_state *x, struct sk_buff *skb, ...@@ -216,7 +214,7 @@ static int mip6_destopt_reject(struct xfrm_state *x, struct sk_buff *skb,
struct ipv6_destopt_hao *hao = NULL; struct ipv6_destopt_hao *hao = NULL;
struct xfrm_selector sel; struct xfrm_selector sel;
int offset; int offset;
struct timeval stamp; ktime_t stamp;
int err = 0; int err = 0;
if (unlikely(fl6->flowi6_proto == IPPROTO_MH && if (unlikely(fl6->flowi6_proto == IPPROTO_MH &&
...@@ -230,9 +228,9 @@ static int mip6_destopt_reject(struct xfrm_state *x, struct sk_buff *skb, ...@@ -230,9 +228,9 @@ static int mip6_destopt_reject(struct xfrm_state *x, struct sk_buff *skb,
(skb_network_header(skb) + offset); (skb_network_header(skb) + offset);
} }
skb_get_timestamp(skb, &stamp); stamp = skb_get_ktime(skb);
if (!mip6_report_rl_allow(&stamp, &ipv6_hdr(skb)->daddr, if (!mip6_report_rl_allow(stamp, &ipv6_hdr(skb)->daddr,
hao ? &hao->addr : &ipv6_hdr(skb)->saddr, hao ? &hao->addr : &ipv6_hdr(skb)->saddr,
opt->iif)) opt->iif))
goto out; goto out;
......
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