]> git.baikalelectronics.ru Git - kernel.git/commit
net: avoid a full fib lookup when rp_filter is disabled.
authorPaolo Abeni <pabeni@redhat.com>
Wed, 20 Sep 2017 16:26:53 +0000 (18:26 +0200)
committerDavid S. Miller <davem@davemloft.net>
Thu, 21 Sep 2017 22:15:22 +0000 (15:15 -0700)
commit4bd1d18b2ccc06e683852bdc4ee714bb83a6181c
tree1bbc7e3a49f22574422489dd654f9e3668fe6e41
parent0800605137d164e1ab768a94c3eead985111a584
net: avoid a full fib lookup when rp_filter is disabled.

Since commit 628f4f7e8073 ("ipv4: Restore accept_local behaviour
in fib_validate_source()") a full fib lookup is needed even if
the rp_filter is disabled, if accept_local is false - which is
the default.

What we really need in the above scenario is just checking
that the source IP address is not local, and in most case we
can do that is a cheaper way looking up the ifaddr hash table.

This commit adds a helper for such lookup, and uses it to
validate the src address when rp_filter is disabled and no
'local' routes are created by the user space in the relevant
namespace.

A new ipv4 netns flag is added to account for such routes.
We need that to preserve the same behavior we had before this
patch.

It also drops the checks to bail early from __fib_validate_source,
added by the commit 628f4f7e8073 ("ipv4: Restore accept_local
behaviour in fib_validate_source()") they do not give any
measurable performance improvement: if we do the lookup with are
on a slower path.

This improves UDP performances for unconnected sockets
when rp_filter is disabled by 5% and also gives small but
measurable performance improvement for TCP flood scenarios.

v1 -> v2:
 - use the ifaddr lookup helper in __ip_dev_find(), as suggested
   by Eric
 - fall-back to full lookup if custom local routes are present

Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/linux/inetdevice.h
include/net/netns/ipv4.h
net/ipv4/devinet.c
net/ipv4/fib_frontend.c