Skip to content

Commit dec9b0e

Browse files
dsaherndavem330
authored andcommitted
net/ipv6: Add rt6_info create function for ip6_pol_route_lookup
ip6_pol_route_lookup is the lookup function for ip6_route_lookup and rt6_lookup. At the moment it returns either a reference to a FIB entry or a cached exception. To move FIB entries to a separate struct, this lookup function needs to convert FIB entries to an rt6_info that is returned to the caller. Signed-off-by: David Ahern <dsahern@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 421842e commit dec9b0e

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

net/ipv6/route.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,19 @@ static bool ip6_hold_safe(struct net *net, struct rt6_info **prt,
10551055
return false;
10561056
}
10571057

1058+
/* called with rcu_lock held */
1059+
static struct rt6_info *ip6_create_rt_rcu(struct rt6_info *rt)
1060+
{
1061+
struct net_device *dev = rt->fib6_nh.nh_dev;
1062+
struct rt6_info *nrt;
1063+
1064+
nrt = __ip6_dst_alloc(dev_net(dev), dev, 0);
1065+
if (nrt)
1066+
ip6_rt_copy_init(nrt, rt);
1067+
1068+
return nrt;
1069+
}
1070+
10581071
static struct rt6_info *ip6_pol_route_lookup(struct net *net,
10591072
struct fib6_table *table,
10601073
struct flowi6 *fl6,
@@ -1087,18 +1100,26 @@ static struct rt6_info *ip6_pol_route_lookup(struct net *net,
10871100
}
10881101
/* Search through exception table */
10891102
rt_cache = rt6_find_cached_rt(rt, &fl6->daddr, &fl6->saddr);
1090-
if (rt_cache)
1103+
if (rt_cache) {
10911104
rt = rt_cache;
1105+
if (ip6_hold_safe(net, &rt, true))
1106+
dst_use_noref(&rt->dst, jiffies);
1107+
} else if (dst_hold_safe(&rt->dst)) {
1108+
struct rt6_info *nrt;
10921109

1093-
if (ip6_hold_safe(net, &rt, true))
1094-
dst_use_noref(&rt->dst, jiffies);
1110+
nrt = ip6_create_rt_rcu(rt);
1111+
dst_release(&rt->dst);
1112+
rt = nrt;
1113+
} else {
1114+
rt = net->ipv6.ip6_null_entry;
1115+
dst_hold(&rt->dst);
1116+
}
10951117

10961118
rcu_read_unlock();
10971119

10981120
trace_fib6_table_lookup(net, rt, table, fl6);
10991121

11001122
return rt;
1101-
11021123
}
11031124

11041125
struct dst_entry *ip6_route_lookup(struct net *net, struct flowi6 *fl6,

0 commit comments

Comments
 (0)