Skip to content

Commit 8b9df26

Browse files
iamkafaidavem330
authored andcommitted
ipv6: Combine rt6_alloc_cow and rt6_alloc_clone
A prep work for creating RTF_CACHE on exception only. After this patch, the same condition (rt->rt6i_flags & (RTF_NONEXTHOP | RTF_GATEWAY)) is checked twice. This redundancy will be removed in the later patch. Signed-off-by: Martin KaFai Lau <[email protected]> Cc: Hannes Frederic Sowa <[email protected]> Cc: Steffen Klassert <[email protected]> Cc: Julian Anastasov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 2647a9b commit 8b9df26

File tree

1 file changed

+20
-25
lines changed

1 file changed

+20
-25
lines changed

net/ipv6/route.c

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,11 @@ static struct rt6_info *rt6_select(struct fib6_node *fn, int oif, int strict)
655655
return match ? match : net->ipv6.ip6_null_entry;
656656
}
657657

658+
static bool rt6_is_gw_or_nonexthop(const struct rt6_info *rt)
659+
{
660+
return (rt->rt6i_flags & (RTF_NONEXTHOP | RTF_GATEWAY));
661+
}
662+
658663
#ifdef CONFIG_IPV6_ROUTE_INFO
659664
int rt6_route_rcv(struct net_device *dev, u8 *opt, int len,
660665
const struct in6_addr *gwaddr)
@@ -833,9 +838,9 @@ int ip6_ins_rt(struct rt6_info *rt)
833838
return __ip6_ins_rt(rt, &info, &mxc);
834839
}
835840

836-
static struct rt6_info *rt6_alloc_cow(struct rt6_info *ort,
837-
const struct in6_addr *daddr,
838-
const struct in6_addr *saddr)
841+
static struct rt6_info *ip6_rt_cache_alloc(struct rt6_info *ort,
842+
const struct in6_addr *daddr,
843+
const struct in6_addr *saddr)
839844
{
840845
struct rt6_info *rt;
841846

@@ -846,33 +851,24 @@ static struct rt6_info *rt6_alloc_cow(struct rt6_info *ort,
846851
rt = ip6_rt_copy(ort, daddr);
847852

848853
if (rt) {
849-
if (ort->rt6i_dst.plen != 128 &&
850-
ipv6_addr_equal(&ort->rt6i_dst.addr, daddr))
851-
rt->rt6i_flags |= RTF_ANYCAST;
852-
853854
rt->rt6i_flags |= RTF_CACHE;
854855

856+
if (!rt6_is_gw_or_nonexthop(ort)) {
857+
if (ort->rt6i_dst.plen != 128 &&
858+
ipv6_addr_equal(&ort->rt6i_dst.addr, daddr))
859+
rt->rt6i_flags |= RTF_ANYCAST;
855860
#ifdef CONFIG_IPV6_SUBTREES
856-
if (rt->rt6i_src.plen && saddr) {
857-
rt->rt6i_src.addr = *saddr;
858-
rt->rt6i_src.plen = 128;
859-
}
861+
if (rt->rt6i_src.plen && saddr) {
862+
rt->rt6i_src.addr = *saddr;
863+
rt->rt6i_src.plen = 128;
864+
}
860865
#endif
866+
}
861867
}
862868

863869
return rt;
864870
}
865871

866-
static struct rt6_info *rt6_alloc_clone(struct rt6_info *ort,
867-
const struct in6_addr *daddr)
868-
{
869-
struct rt6_info *rt = ip6_rt_copy(ort, daddr);
870-
871-
if (rt)
872-
rt->rt6i_flags |= RTF_CACHE;
873-
return rt;
874-
}
875-
876872
static struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table, int oif,
877873
struct flowi6 *fl6, int flags)
878874
{
@@ -918,10 +914,9 @@ static struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table,
918914
if (rt->rt6i_flags & RTF_CACHE)
919915
goto out2;
920916

921-
if (!(rt->rt6i_flags & (RTF_NONEXTHOP | RTF_GATEWAY)))
922-
nrt = rt6_alloc_cow(rt, &fl6->daddr, &fl6->saddr);
923-
else if (!(rt->dst.flags & DST_HOST) || !(rt->rt6i_flags & RTF_LOCAL))
924-
nrt = rt6_alloc_clone(rt, &fl6->daddr);
917+
if (!rt6_is_gw_or_nonexthop(rt) ||
918+
!(rt->dst.flags & DST_HOST) || !(rt->rt6i_flags & RTF_LOCAL))
919+
nrt = ip6_rt_cache_alloc(rt, &fl6->daddr, &fl6->saddr);
925920
else
926921
goto out2;
927922

0 commit comments

Comments
 (0)