Skip to content

Commit 1489568

Browse files
dsaherndavem330
authored andcommitted
net/ipv6: move expires into rt6_info
Add expires to rt6_info for FIB entries, and add fib6 helpers to manage it. Data path use of dst.expires remains. The transition is fairly straightforward: when working with fib entries, rt->dst.expires is just rt->expires, rt6_clean_expires is replaced with fib6_clean_expires, rt6_set_expires becomes fib6_set_expires, and rt6_check_expired becomes fib6_check_expired, where the fib6 versions are added by this patch. Signed-off-by: David Ahern <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent d4ead6b commit 1489568

File tree

5 files changed

+42
-21
lines changed

5 files changed

+42
-21
lines changed

Diff for: include/net/ip6_fib.h

+23-4
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ struct rt6_info {
179179
should_flush:1,
180180
unused:6;
181181

182+
unsigned long expires;
182183
struct dst_metrics *fib6_metrics;
183184
#define fib6_pmtu fib6_metrics->metrics[RTAX_MTU-1]
184185
struct fib6_nh fib6_nh;
@@ -197,6 +198,26 @@ static inline struct inet6_dev *ip6_dst_idev(struct dst_entry *dst)
197198
return ((struct rt6_info *)dst)->rt6i_idev;
198199
}
199200

201+
static inline void fib6_clean_expires(struct rt6_info *f6i)
202+
{
203+
f6i->rt6i_flags &= ~RTF_EXPIRES;
204+
f6i->expires = 0;
205+
}
206+
207+
static inline void fib6_set_expires(struct rt6_info *f6i,
208+
unsigned long expires)
209+
{
210+
f6i->expires = expires;
211+
f6i->rt6i_flags |= RTF_EXPIRES;
212+
}
213+
214+
static inline bool fib6_check_expired(const struct rt6_info *f6i)
215+
{
216+
if (f6i->rt6i_flags & RTF_EXPIRES)
217+
return time_after(jiffies, f6i->expires);
218+
return false;
219+
}
220+
200221
static inline void rt6_clean_expires(struct rt6_info *rt)
201222
{
202223
rt->rt6i_flags &= ~RTF_EXPIRES;
@@ -211,11 +232,9 @@ static inline void rt6_set_expires(struct rt6_info *rt, unsigned long expires)
211232

212233
static inline void rt6_update_expires(struct rt6_info *rt0, int timeout)
213234
{
214-
struct rt6_info *rt;
235+
if (!(rt0->rt6i_flags & RTF_EXPIRES) && rt0->from)
236+
rt0->dst.expires = rt0->from->expires;
215237

216-
for (rt = rt0; rt && !(rt->rt6i_flags & RTF_EXPIRES); rt = rt->from);
217-
if (rt && rt != rt0)
218-
rt0->dst.expires = rt->dst.expires;
219238
dst_set_expires(&rt0->dst, timeout);
220239
rt0->rt6i_flags |= RTF_EXPIRES;
221240
}

Diff for: net/ipv6/addrconf.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -1190,7 +1190,7 @@ cleanup_prefix_route(struct inet6_ifaddr *ifp, unsigned long expires, bool del_r
11901190
ip6_del_rt(dev_net(ifp->idev->dev), rt);
11911191
else {
11921192
if (!(rt->rt6i_flags & RTF_EXPIRES))
1193-
rt6_set_expires(rt, expires);
1193+
fib6_set_expires(rt, expires);
11941194
ip6_rt_put(rt);
11951195
}
11961196
}
@@ -2672,9 +2672,9 @@ void addrconf_prefix_rcv(struct net_device *dev, u8 *opt, int len, bool sllao)
26722672
rt = NULL;
26732673
} else if (addrconf_finite_timeout(rt_expires)) {
26742674
/* not infinity */
2675-
rt6_set_expires(rt, jiffies + rt_expires);
2675+
fib6_set_expires(rt, jiffies + rt_expires);
26762676
} else {
2677-
rt6_clean_expires(rt);
2677+
fib6_clean_expires(rt);
26782678
}
26792679
} else if (valid_lft) {
26802680
clock_t expires = 0;

Diff for: net/ipv6/ip6_fib.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -906,9 +906,9 @@ static int fib6_add_rt2node(struct fib6_node *fn, struct rt6_info *rt,
906906
if (!(iter->rt6i_flags & RTF_EXPIRES))
907907
return -EEXIST;
908908
if (!(rt->rt6i_flags & RTF_EXPIRES))
909-
rt6_clean_expires(iter);
909+
fib6_clean_expires(iter);
910910
else
911-
rt6_set_expires(iter, rt->dst.expires);
911+
fib6_set_expires(iter, rt->expires);
912912
fib6_metric_set(iter, RTAX_MTU, rt->fib6_pmtu);
913913
return -EEXIST;
914914
}
@@ -2003,8 +2003,8 @@ static int fib6_age(struct rt6_info *rt, void *arg)
20032003
* Routes are expired even if they are in use.
20042004
*/
20052005

2006-
if (rt->rt6i_flags & RTF_EXPIRES && rt->dst.expires) {
2007-
if (time_after(now, rt->dst.expires)) {
2006+
if (rt->rt6i_flags & RTF_EXPIRES && rt->expires) {
2007+
if (time_after(now, rt->expires)) {
20082008
RT6_TRACE("expiring %p\n", rt);
20092009
return -1;
20102010
}

Diff for: net/ipv6/ndisc.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1318,7 +1318,7 @@ static void ndisc_router_discovery(struct sk_buff *skb)
13181318
}
13191319

13201320
if (rt)
1321-
rt6_set_expires(rt, jiffies + (HZ * lifetime));
1321+
fib6_set_expires(rt, jiffies + (HZ * lifetime));
13221322
if (in6_dev->cnf.accept_ra_min_hop_limit < 256 &&
13231323
ra_msg->icmph.icmp6_hop_limit) {
13241324
if (in6_dev->cnf.accept_ra_min_hop_limit <= ra_msg->icmph.icmp6_hop_limit) {

Diff for: net/ipv6/route.c

+11-9
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ static bool rt6_check_expired(const struct rt6_info *rt)
435435
return true;
436436
} else if (rt->from) {
437437
return rt->dst.obsolete != DST_OBSOLETE_FORCE_CHK ||
438-
rt6_check_expired(rt->from);
438+
fib6_check_expired(rt->from);
439439
}
440440
return false;
441441
}
@@ -687,7 +687,7 @@ static struct rt6_info *find_match(struct rt6_info *rt, int oif, int strict,
687687
!(strict & RT6_LOOKUP_F_IGNORE_LINKSTATE))
688688
goto out;
689689

690-
if (rt6_check_expired(rt))
690+
if (fib6_check_expired(rt))
691691
goto out;
692692

693693
m = rt6_score_route(rt, oif, strict);
@@ -871,9 +871,9 @@ int rt6_route_rcv(struct net_device *dev, u8 *opt, int len,
871871

872872
if (rt) {
873873
if (!addrconf_finite_timeout(lifetime))
874-
rt6_clean_expires(rt);
874+
fib6_clean_expires(rt);
875875
else
876-
rt6_set_expires(rt, jiffies + HZ * lifetime);
876+
fib6_set_expires(rt, jiffies + HZ * lifetime);
877877

878878
ip6_rt_put(rt);
879879
}
@@ -2383,7 +2383,7 @@ static struct rt6_info *__ip6_route_redirect(struct net *net,
23832383
for_each_fib6_node_rt_rcu(fn) {
23842384
if (rt->fib6_nh.nh_flags & RTNH_F_DEAD)
23852385
continue;
2386-
if (rt6_check_expired(rt))
2386+
if (fib6_check_expired(rt))
23872387
continue;
23882388
if (rt->rt6i_flags & RTF_REJECT)
23892389
break;
@@ -2909,10 +2909,10 @@ static struct rt6_info *ip6_route_info_create(struct fib6_config *cfg,
29092909
goto out;
29102910

29112911
if (cfg->fc_flags & RTF_EXPIRES)
2912-
rt6_set_expires(rt, jiffies +
2912+
fib6_set_expires(rt, jiffies +
29132913
clock_t_to_jiffies(cfg->fc_expires));
29142914
else
2915-
rt6_clean_expires(rt);
2915+
fib6_clean_expires(rt);
29162916

29172917
if (cfg->fc_protocol == RTPROT_UNSPEC)
29182918
cfg->fc_protocol = RTPROT_BOOT;
@@ -4599,8 +4599,10 @@ static int rt6_fill_node(struct net *net, struct sk_buff *skb,
45994599
goto nla_put_failure;
46004600
}
46014601

4602-
if (rt->rt6i_flags & RTF_EXPIRES && dst)
4603-
expires = dst->expires - jiffies;
4602+
if (rt->rt6i_flags & RTF_EXPIRES) {
4603+
expires = dst ? dst->expires : rt->expires;
4604+
expires -= jiffies;
4605+
}
46044606

46054607
if (rtnl_put_cacheinfo(skb, dst, 0, expires, dst ? dst->error : 0) < 0)
46064608
goto nla_put_failure;

0 commit comments

Comments
 (0)