Skip to content

Commit 1f6cc51

Browse files
Julian Anastasovgregkh
authored andcommitted
ipv4: Add FLOWI_FLAG_KNOWN_NH
[ Upstream commit c92b965 ] Add flag to request that output route should be returned with known rt_gateway, in case we want to use it as nexthop for neighbour resolving. The returned route can be cached as follows: - in NH exception: because the cached routes are not shared with other destinations - in FIB NH: when using gateway because all destinations for NH share same gateway As last option, to return rt_gateway!=0 we have to set DST_NOCACHE. Signed-off-by: Julian Anastasov <ja@ssi.bg> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 87a2496 commit 1f6cc51

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

‎include/net/flow.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ struct flowi_common {
2121
__u8 flowic_flags;
2222
#define FLOWI_FLAG_ANYSRC 0x01
2323
#define FLOWI_FLAG_CAN_SLEEP 0x02
24+
#define FLOWI_FLAG_KNOWN_NH 0x04
2425
__u32 flowic_secid;
2526
};
2627

‎net/ipv4/route.c‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,6 +1762,7 @@ static struct rtable *__mkroute_output(const struct fib_result *res,
17621762
struct in_device *in_dev;
17631763
u16 type = res->type;
17641764
struct rtable *rth;
1765+
bool do_cache;
17651766

17661767
in_dev = __in_dev_get_rcu(dev_out);
17671768
if (!in_dev)
@@ -1798,24 +1799,36 @@ static struct rtable *__mkroute_output(const struct fib_result *res,
17981799
}
17991800

18001801
fnhe = NULL;
1802+
do_cache = fi != NULL;
18011803
if (fi) {
18021804
struct rtable __rcu **prth;
1805+
struct fib_nh *nh = &FIB_RES_NH(*res);
18031806

1804-
fnhe = find_exception(&FIB_RES_NH(*res), fl4->daddr);
1807+
fnhe = find_exception(nh, fl4->daddr);
18051808
if (fnhe)
18061809
prth = &fnhe->fnhe_rth;
1807-
else
1808-
prth = __this_cpu_ptr(FIB_RES_NH(*res).nh_pcpu_rth_output);
1810+
else {
1811+
if (unlikely(fl4->flowi4_flags &
1812+
FLOWI_FLAG_KNOWN_NH &&
1813+
!(nh->nh_gw &&
1814+
nh->nh_scope == RT_SCOPE_LINK))) {
1815+
do_cache = false;
1816+
goto add;
1817+
}
1818+
prth = __this_cpu_ptr(nh->nh_pcpu_rth_output);
1819+
}
18091820
rth = rcu_dereference(*prth);
18101821
if (rt_cache_valid(rth)) {
18111822
dst_hold(&rth->dst);
18121823
return rth;
18131824
}
18141825
}
1826+
1827+
add:
18151828
rth = rt_dst_alloc(dev_out,
18161829
IN_DEV_CONF_GET(in_dev, NOPOLICY),
18171830
IN_DEV_CONF_GET(in_dev, NOXFRM),
1818-
fi);
1831+
do_cache);
18191832
if (!rth)
18201833
return ERR_PTR(-ENOBUFS);
18211834

0 commit comments

Comments
 (0)