d47e80885cbf5158dbbe2f15fe30b3c75f0780e7
[openwrt.git] / target / linux / generic / patches-4.3 / 192-net-Fix-presrc-lookups.patch
1 From patchwork Tue Nov  3 23:59:28 2015
2 Content-Type: text/plain; charset="utf-8"
3 MIME-Version: 1.0
4 Content-Transfer-Encoding: 7bit
5 Subject: net: Fix prefsrc lookups
6 From: David Ahern <dsa@cumulusnetworks.com>
7 X-Patchwork-Id: 539645
8 Message-Id: <1446595168-27323-1-git-send-email-dsa@cumulusnetworks.com>
9 To: netdev@vger.kernel.org
10 Cc: vladi@aresgate.net, David Ahern <dsa@cumulusnetworks.com>
11 Date: Tue,  3 Nov 2015 15:59:28 -0800
12
13 A bug report (https://bugzilla.kernel.org/show_bug.cgi?id=107071) noted
14 that the follwoing ip command is failing with v4.3:
15
16     $ ip route add 10.248.5.0/24 dev bond0.250 table vlan_250 src 10.248.5.154
17     RTNETLINK answers: Invalid argument
18
19 021dd3b8a142d changed the lookup of the given preferred source address to
20 use the table id passed in, but this assumes the local entries are in the
21 given table which is not necessarily true for non-VRF use cases. When
22 validating the preferred source fallback to the local table on failure.
23
24 Fixes: 021dd3b8a142d ("net: Add routes to the table associated with the device")
25 Signed-off-by: David Ahern <dsa@cumulusnetworks.com>
26 ---
27 This is needed in v4.3.
28
29  net/ipv4/fib_semantics.c | 13 ++++++++++---
30  1 file changed, 10 insertions(+), 3 deletions(-)
31
32 --- a/net/ipv4/fib_semantics.c
33 +++ b/net/ipv4/fib_semantics.c
34 @@ -864,14 +864,21 @@ static bool fib_valid_prefsrc(struct fib
35         if (cfg->fc_type != RTN_LOCAL || !cfg->fc_dst ||
36             fib_prefsrc != cfg->fc_dst) {
37                 u32 tb_id = cfg->fc_table;
38 +               int rc;
39  
40                 if (tb_id == RT_TABLE_MAIN)
41                         tb_id = RT_TABLE_LOCAL;
42  
43 -               if (inet_addr_type_table(cfg->fc_nlinfo.nl_net,
44 -                                        fib_prefsrc, tb_id) != RTN_LOCAL) {
45 -                       return false;
46 +               rc = inet_addr_type_table(cfg->fc_nlinfo.nl_net,
47 +                                         fib_prefsrc, tb_id);
48 +
49 +               if (rc != RTN_LOCAL && tb_id != RT_TABLE_LOCAL) {
50 +                       rc = inet_addr_type_table(cfg->fc_nlinfo.nl_net,
51 +                                                 fib_prefsrc, RT_TABLE_LOCAL);
52                 }
53 +
54 +               if (rc != RTN_LOCAL)
55 +                       return false;
56         }
57         return true;
58  }