Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1716a961 authored by Gao feng's avatar Gao feng Committed by David S. Miller
Browse files

ipv6: fix problem with expired dst cache



If the ipv6 dst cache which copy from the dst generated by ICMPV6 RA packet.
this dst cache will not check expire because it has no RTF_EXPIRES flag.
So this dst cache will always be used until the dst gc run.

Change the struct dst_entry,add a union contains new pointer from and expires.
When rt6_info.rt6i_flags has no RTF_EXPIRES flag,the dst.expires has no use.
we can use this field to point to where the dst cache copy from.
The dst.from is only used in IPV6.

rt6_check_expired check if rt6_info.dst.from is expired.

ip6_rt_copy only set dst.from when the ort has flag RTF_ADDRCONF
and RTF_DEFAULT.then hold the ort.

ip6_dst_destroy release the ort.

Add some functions to operate the RTF_EXPIRES flag and expires(from) together.
and change the code to use these new adding functions.

Changes from v5:
modify ip6_route_add and ndisc_router_discovery to use new adding functions.

Only set dst.from when the ort has flag RTF_ADDRCONF
and RTF_DEFAULT.then hold the ort.

Signed-off-by: default avatarGao feng <gaofeng@cn.fujitsu.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent d62f8dbb
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -36,7 +36,11 @@ struct dst_entry {
	struct net_device       *dev;
	struct  dst_ops	        *ops;
	unsigned long		_metrics;
	union {
		unsigned long           expires;
		/* point to where the dst_entry copied from */
		struct dst_entry        *from;
	};
	struct dst_entry	*path;
	struct neighbour __rcu	*_neighbour;
#ifdef CONFIG_XFRM
+42 −0
Original line number Diff line number Diff line
@@ -123,6 +123,48 @@ static inline struct inet6_dev *ip6_dst_idev(struct dst_entry *dst)
	return ((struct rt6_info *)dst)->rt6i_idev;
}

static inline void rt6_clean_expires(struct rt6_info *rt)
{
	if (!(rt->rt6i_flags & RTF_EXPIRES) && rt->dst.from)
		dst_release(rt->dst.from);

	rt->rt6i_flags &= ~RTF_EXPIRES;
	rt->dst.expires = 0;
}

static inline void rt6_set_expires(struct rt6_info *rt, unsigned long expires)
{
	if (!(rt->rt6i_flags & RTF_EXPIRES) && rt->dst.from)
		dst_release(rt->dst.from);

	rt->rt6i_flags |= RTF_EXPIRES;
	rt->dst.expires = expires;
}

static inline void rt6_update_expires(struct rt6_info *rt, int timeout)
{
	if (!(rt->rt6i_flags & RTF_EXPIRES) && rt->dst.from)
		dst_release(rt->dst.from);

	dst_set_expires(&rt->dst, timeout);
	rt->rt6i_flags |= RTF_EXPIRES;
}

static inline void rt6_set_from(struct rt6_info *rt, struct rt6_info *from)
{
	struct dst_entry *new = (struct dst_entry *) from;

	if (!(rt->rt6i_flags & RTF_EXPIRES) && rt->dst.from) {
		if (new == rt->dst.from)
			return;
		dst_release(rt->dst.from);
	}

	rt->rt6i_flags &= ~RTF_EXPIRES;
	rt->dst.from = new;
	dst_hold(new);
}

struct fib6_walker_t {
	struct list_head lh;
	struct fib6_node *root, *node;
+3 −6
Original line number Diff line number Diff line
@@ -803,8 +803,7 @@ static void ipv6_del_addr(struct inet6_ifaddr *ifp)
				ip6_del_rt(rt);
				rt = NULL;
			} else if (!(rt->rt6i_flags & RTF_EXPIRES)) {
				rt->dst.expires = expires;
				rt->rt6i_flags |= RTF_EXPIRES;
				rt6_set_expires(rt, expires);
			}
		}
		dst_release(&rt->dst);
@@ -1887,11 +1886,9 @@ void addrconf_prefix_rcv(struct net_device *dev, u8 *opt, int len, bool sllao)
				rt = NULL;
			} else if (addrconf_finite_timeout(rt_expires)) {
				/* not infinity */
				rt->dst.expires = jiffies + rt_expires;
				rt->rt6i_flags |= RTF_EXPIRES;
				rt6_set_expires(rt, jiffies + rt_expires);
			} else {
				rt->rt6i_flags &= ~RTF_EXPIRES;
				rt->dst.expires = 0;
				rt6_clean_expires(rt);
			}
		} else if (valid_lft) {
			clock_t expires = 0;
+4 −5
Original line number Diff line number Diff line
@@ -673,11 +673,10 @@ static int fib6_add_rt2node(struct fib6_node *fn, struct rt6_info *rt,
					    &rt->rt6i_gateway)) {
				if (!(iter->rt6i_flags & RTF_EXPIRES))
					return -EEXIST;
				iter->dst.expires = rt->dst.expires;
				if (!(rt->rt6i_flags & RTF_EXPIRES)) {
					iter->rt6i_flags &= ~RTF_EXPIRES;
					iter->dst.expires = 0;
				}
				if (!(rt->rt6i_flags & RTF_EXPIRES))
					rt6_clean_expires(iter);
				else
					rt6_set_expires(iter, rt->dst.expires);
				return -EEXIST;
			}
		}
+1 −2
Original line number Diff line number Diff line
@@ -1264,8 +1264,7 @@ static void ndisc_router_discovery(struct sk_buff *skb)
	}

	if (rt)
		rt->dst.expires = jiffies + (HZ * lifetime);

		rt6_set_expires(rt, jiffies + (HZ * lifetime));
	if (ra_msg->icmph.icmp6_hop_limit) {
		in6_dev->cnf.hop_limit = ra_msg->icmph.icmp6_hop_limit;
		if (rt)
Loading