Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ipv4: Add FLOWI_FLAG_KNOWN_NH

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>

authored by

Julian Anastasov and committed by
David S. Miller
c92b9655 155e8336

+18 -4
+1
include/net/flow.h
··· 21 21 __u8 flowic_flags; 22 22 #define FLOWI_FLAG_ANYSRC 0x01 23 23 #define FLOWI_FLAG_CAN_SLEEP 0x02 24 + #define FLOWI_FLAG_KNOWN_NH 0x04 24 25 __u32 flowic_secid; 25 26 }; 26 27
+17 -4
net/ipv4/route.c
··· 1762 1762 struct in_device *in_dev; 1763 1763 u16 type = res->type; 1764 1764 struct rtable *rth; 1765 + bool do_cache; 1765 1766 1766 1767 in_dev = __in_dev_get_rcu(dev_out); 1767 1768 if (!in_dev) ··· 1799 1798 } 1800 1799 1801 1800 fnhe = NULL; 1801 + do_cache = fi != NULL; 1802 1802 if (fi) { 1803 1803 struct rtable __rcu **prth; 1804 + struct fib_nh *nh = &FIB_RES_NH(*res); 1804 1805 1805 - fnhe = find_exception(&FIB_RES_NH(*res), fl4->daddr); 1806 + fnhe = find_exception(nh, fl4->daddr); 1806 1807 if (fnhe) 1807 1808 prth = &fnhe->fnhe_rth; 1808 - else 1809 - prth = __this_cpu_ptr(FIB_RES_NH(*res).nh_pcpu_rth_output); 1809 + else { 1810 + if (unlikely(fl4->flowi4_flags & 1811 + FLOWI_FLAG_KNOWN_NH && 1812 + !(nh->nh_gw && 1813 + nh->nh_scope == RT_SCOPE_LINK))) { 1814 + do_cache = false; 1815 + goto add; 1816 + } 1817 + prth = __this_cpu_ptr(nh->nh_pcpu_rth_output); 1818 + } 1810 1819 rth = rcu_dereference(*prth); 1811 1820 if (rt_cache_valid(rth)) { 1812 1821 dst_hold(&rth->dst); 1813 1822 return rth; 1814 1823 } 1815 1824 } 1825 + 1826 + add: 1816 1827 rth = rt_dst_alloc(dev_out, 1817 1828 IN_DEV_CONF_GET(in_dev, NOPOLICY), 1818 1829 IN_DEV_CONF_GET(in_dev, NOXFRM), 1819 - fi); 1830 + do_cache); 1820 1831 if (!rth) 1821 1832 return ERR_PTR(-ENOBUFS); 1822 1833