Skip to content
  1. Jun 27, 2019
    • Eric Dumazet's avatar
      ipv4: fix suspicious RCU usage in fib_dump_info_fnhe() · 93ed54b1
      Eric Dumazet authored
      sysbot reported that we lack appropriate rcu_read_lock()
      protection in fib_dump_info_fnhe()
      
      net/ipv4/route.c:2875 suspicious rcu_dereference_check() usage!
      
      other info that might help us debug this:
      
      rcu_scheduler_active = 2, debug_locks = 1
      1 lock held by syz-executor609/8966:
       #0: 00000000b7dbe288 (rtnl_mutex){+.+.}, at: netlink_dump+0xe7/0xfb0 net/netlink/af_netlink.c:2199
      
      stack backtrace:
      CPU: 0 PID: 8966 Comm: syz-executor609 Not tainted 5.2.0-rc5+ #43
      Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
      Call Trace:
       __dump_stack lib/dump_stack.c:77 [inline]
       dump_stack+0x172/0x1f0 lib/dump_stack.c:113
       lockdep_rcu_suspicious+0x153/0x15d kernel/locking/lockdep.c:5250
       fib_dump_info_fnhe+0x9d9/0x1080 net/ipv4/route.c:2875
       fn_trie_dump_leaf net/ipv4/fib_trie.c:2141 [inline]
       fib_table_dump+0x64a/0xd00 net/ipv4/fib_trie.c:2175
       inet_dump_fib+0x83c/0xa90 net/ipv4/fib_frontend.c:1004
       rtnl_dump_all+0x295/0x490 net/core/rtnetlink.c:3445
       netlink_dump+0x558/0xfb0 net/netlink/af_netlink.c:2244
       __netlink_dump_start+0x5b1/0x7d0 net/netlink/af_netlink.c:2352
       netlink_dump_start include/linux/netlink.h:226 [inline]
       rtnetlink_rcv_msg+0x73d/0xb00 net/core/rtnetlink.c:5182
       netlink_rcv_skb+0x177/0x450 net/netlink/af_netlink.c:2477
       rtnetlink_rcv+0x1d/0x30 net/core/rtnetlink.c:5237
       netlink_unicast_kernel net/netlink/af_netlink.c:1302 [inline]
       netlink_unicast+0x531/0x710 net/netlink/af_netlink.c:1328
       netlink_sendmsg+0x8ae/0xd70 net/netlink/af_netlink.c:1917
       sock_sendmsg_nosec net/socket.c:646 [inline]
       sock_sendmsg+0xd7/0x130 net/socket.c:665
       sock_write_iter+0x27c/0x3e0 net/socket.c:994
       call_write_iter include/linux/fs.h:1872 [inline]
       new_sync_write+0x4d3/0x770 fs/read_write.c:483
       __vfs_write+0xe1/0x110 fs/read_write.c:496
       vfs_write+0x20c/0x580 fs/read_write.c:558
       ksys_write+0x14f/0x290 fs/read_write.c:611
       __do_sys_write fs/read_write.c:623 [inline]
       __se_sys_write fs/read_write.c:620 [inline]
       __x64_sys_write+0x73/0xb0 fs/read_write.c:620
       do_syscall_64+0xfd/0x680 arch/x86/entry/common.c:301
       entry_SYSCALL_64_after_hwframe+0x49/0xbe
      RIP: 0033:0x4401b9
      Code: 18 89 d0 c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 0f 83 fb 13 fc ff c3 66 2e 0f 1f 84 00 00 00 00
      RSP: 002b:00007ffc8e134978 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
      RAX: ffffffffffffffda RBX: 00000000004002c8 RCX: 00000000004401b9
      RDX: 000000000000001c RSI: 0000000020000000 RDI: 0000000000000003
      RBP: 00000000006ca018 R08: 00000000004002c8 R09: 00000000004002c8
      R10: 0000000000000010 R11: 0000000000000246 R12: 0000000000401a40
      R13: 0000000000401ad0 R14: 0000000000000000 R15: 0000000000000000
      
      Fixes: ee28906f
      
       ("ipv4: Dump route exceptions if requested")
      Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
      Cc: Stefano Brivio <sbrivio@redhat.com>
      Cc: David Ahern <dsahern@gmail.com>
      Reported-by: default avatarsyzbot <syzkaller@googlegroups.com>
      Reviewed-by: default avatarStefano Brivio <sbrivio@redhat.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      93ed54b1
    • Jakub Kicinski's avatar
      Revert "net: ena: ethtool: add extra properties retrieval via get_priv_flags" · eb203bae
      Jakub Kicinski authored
      This reverts commit 315c28d2
      
       ("net: ena: ethtool: add extra properties retrieval via get_priv_flags").
      
      As discussed at netconf and on the mailing list we can't allow
      for the the abuse of private flags for exposing arbitrary device
      labels.
      
      Signed-off-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      eb203bae
  2. Jun 26, 2019
  3. Jun 25, 2019
    • Pablo Neira Ayuso's avatar
      Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next · 1c5ba67d
      Pablo Neira Ayuso authored
      Resolve conflict between d2912cb1 ("treewide: Replace GPLv2
      boilerplate/reference with SPDX - rule 500") removing the GPL disclaimer
      and fe03d474
      
       ("Update my email address") which updates Jozsef
      Kadlecsik's email.
      
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      1c5ba67d
    • David S. Miller's avatar
      Merge branch 'cxgb4-Reference-count-MPS-TCAM-entries-within-a-PF' · 045df37e
      David S. Miller authored
      
      
      Raju Rangoju says:
      
      ====================
      cxgb4: Reference count MPS TCAM entries within a PF
      
      Firmware reference counts the MPS TCAM entries by PF and VF,
      but it does not do it for usage within a PF or VF. This patch
      adds the support to track MPS TCAM entries within a PF.
      
      v2->v3:
       Fixed the compiler errors due to incorrect patch
       Also, removed the new blank line at EOF
      v1->v2:
       Use refcount_t type instead of atomic_t for mps reference count
      ====================
      
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      045df37e
    • Raju Rangoju's avatar
      cxgb4: Add MPS refcounting for alloc/free mac filters · f9f329ad
      Raju Rangoju authored
      
      
      This patch adds reference counting support for
      alloc/free mac filters
      
      Signed-off-by: default avatarRaju Rangoju <rajur@chelsio.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      f9f329ad
    • Raju Rangoju's avatar
      cxgb4: Add MPS TCAM refcounting for cxgb4 change mac · 2f0b9406
      Raju Rangoju authored
      
      
      This patch adds TCAM reference counting
      support for cxgb4 change mac path
      
      Signed-off-by: default avatarRaju Rangoju <rajur@chelsio.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      2f0b9406
    • Raju Rangoju's avatar
      cxgb4: Add MPS TCAM refcounting for raw mac filters · 5fab5158
      Raju Rangoju authored
      
      
      This patch adds TCAM reference counting
      support for raw mac filters.
      
      Signed-off-by: default avatarRaju Rangoju <rajur@chelsio.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      5fab5158
    • Raju Rangoju's avatar
      cxgb4: Re-work the logic for mps refcounting · 28b38705
      Raju Rangoju authored
      
      
      Remove existing mps refcounting code which was
      added only for encap filters and add necessary
      data structures/functions to support mps reference
      counting for all the mac filters. Also add wrapper
      functions for allocating and freeing encap mac
      filters.
      
      Signed-off-by: default avatarRaju Rangoju <rajur@chelsio.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      28b38705
    • Icenowy Zheng's avatar
      net: stmmac: sun8i: force select external PHY when no internal one · 0fec7e72
      Icenowy Zheng authored
      
      
      The PHY selection bit also exists on SoCs without an internal PHY; if it's
      set to 1 (internal PHY, default value) then the MAC will not make use of
      any PHY on such SoCs.
      
      This problem appears when adapting for H6, which has no real internal PHY
      (the "internal PHY" on H6 is not on-die, but on a co-packaged AC200 chip,
      connected via RMII interface at GPIO bank A).
      
      Force the PHY selection bit to 0 when the SOC doesn't have an internal PHY,
      to address the problem of a wrong default value.
      
      Signed-off-by: default avatarIcenowy Zheng <icenowy@aosc.io>
      Signed-off-by: default avatarOndrej Jirman <megous@megous.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      0fec7e72
    • Icenowy Zheng's avatar
      net: stmmac: sun8i: add support for Allwinner H6 EMAC · adadd38c
      Icenowy Zheng authored
      
      
      The EMAC on Allwinner H6 is just like the one on A64. The "internal PHY" on
      H6 is on a co-packaged AC200 chip, and it's not really internal (it's
      connected via RMII at PA GPIO bank).
      
      Add support for the Allwinner H6 EMAC in the dwmac-sun8i driver.
      
      Signed-off-by: default avatarIcenowy Zheng <icenowy@aosc.io>
      Signed-off-by: default avatarOndrej Jirman <megous@megous.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      adadd38c
    • David S. Miller's avatar
      Merge branch 'cached-route-listings' · dcdfa50e
      David S. Miller authored
      Stefano Brivio says:
      
      ====================
      Fix listing (IPv4, IPv6) and flushing (IPv6) of cached route exceptions
      
      For IPv6 cached routes, the commands 'ip -6 route list cache' and
      'ip -6 route flush cache' don't work at all after route exceptions have
      been moved to a separate hash table in commit 2b760fcf ("ipv6: hook
      up exception table to store dst cache").
      
      For IPv4 cached routes, the command 'ip route list cache' has also
      stopped working in kernel 3.5 after commit 4895c771
      
       ("ipv4: Add FIB
      nexthop exceptions.") introduced storage for route exceptions as a
      separate entity.
      
      Fix this by allowing userspace to clearly request cached routes with
      the RTM_F_CLONED flag used as a filter (in conjuction with strict
      checking) and by retrieving and dumping cached routes if requested.
      
      If strict checking is not requested (iproute2 < 5.0.0), we don't have a
      way to consistently filter results on other selectors (e.g. on tables),
      so skip filtering entirely and dump both regular routes and exceptions.
      
      For IPv4, cache flushing uses a completely different mechanism, so it
      wasn't affected. Listing of exception routes (modified routes pre-3.5) was
      tested against these versions of kernel and iproute2:
      
                          iproute2
      kernel         4.14.0   4.15.0   4.19.0   5.0.0   5.1.0
       3.5-rc4         +        +        +        +       +
       4.4
       4.9
       4.14
       4.15
       4.19
       5.0
       5.1
       fixed           +        +        +        +       +
      
      For IPv6, a separate iproute2 patch is required. Versions of iproute2
      and kernel tested:
      
                          iproute2
      kernel             4.14.0   4.15.0   4.19.0   5.0.0   5.1.0    5.1.0, patched
       3.18    list        +        +        +        +       +            +
               flush       +        +        +        +       +            +
       4.4     list        +        +        +        +       +            +
               flush       +        +        +        +       +            +
       4.9     list        +        +        +        +       +            +
               flush       +        +        +        +       +            +
       4.14    list        +        +        +        +       +            +
               flush       +        +        +        +       +            +
       4.15    list
               flush
       4.19    list
               flush
       5.0     list
               flush
       5.1     list
               flush
       with    list        +        +        +        +       +            +
       fix     flush       +        +        +                             +
      
      v7: Make sure r->rtm_tos is initialised in 3/11, move loop over nexthop
          objects in 4/11, add comments about usage of "skip" counters in commit
          messages of 4/11 and 8/11
      
      v6: Target for net-next, rebase and adapt to nexthop objects for IPv6 paths.
          Merge selftests into this series (as they were addressed for net-next).
          A number of minor changes detailed in logs of single patches.
      
      v5: Skip filtering altogether if no strict checking is requested: selecting
          routes or exceptions only would be inconsistent with the fact we can't
          filter on tables. Drop 1/8 (non-strict dump filter function no longer
          needed), replace 2/8 (don't use NLM_F_MATCH, decide to skip routes or
          exceptions in filter function), drop 6/8 (2/8 is enough for IPv6 too).
          Introduce dump_routes and dump_exceptions flags in filter, adapt other
          patches to that.
      
      v4: Fix the listing issue also for IPv4, making the behaviour consistent
          with IPv6. Honour NLM_F_MATCH as per RFC 3549 and allow usage of
          RTM_F_CLONED filter. Split patches into smaller logical changes.
      
      v3: Drop check on RTM_F_CLONED and rework logic of return values of
          rt6_dump_route()
      
      v2: Add count of routes handled in partial dumps, and skip them, in patch 1/2.
      ====================
      
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      dcdfa50e
    • Stefano Brivio's avatar
      selftests: pmtu: Make list_flush_ipv6_exception test more demanding · b964641e
      Stefano Brivio authored
      
      
      Instead of just listing and flushing two cached exceptions, create
      a relatively big number of them, and count how many are listed. Single
      netlink dump messages contain approximately 25 entries each, and this
      way we can make sure the partial dump tracking mechanism is working
      properly.
      
      While at it, also ensure that no cached routes can be listed after
      flush, and remove 'sleep 1' calls, they are not actually needed.
      
      v7: No changes
      
      v6:
        - Merge this patch into series including fix, as it's also targeted
          for net-next. No actual changes
      
      Signed-off-by: default avatarStefano Brivio <sbrivio@redhat.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      b964641e
    • Stefano Brivio's avatar
      selftests: pmtu: Introduce list_flush_ipv4_exception test case · de755a85
      Stefano Brivio authored
      
      
      This test checks that route exceptions can be successfully listed and
      flushed using ip -6 route {list,flush} cache.
      
      v7: No changes
      
      v6:
        - Merge this patch into series including fix, as it's also targeted
          for net-next
        - Drop left-over print of 'ip route list cache | wc -l'
      
      Signed-off-by: default avatarStefano Brivio <sbrivio@redhat.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      de755a85
    • Stefano Brivio's avatar
      ip6_fib: Don't discard nodes with valid routing information in fib6_locate_1() · 40cb35d5
      Stefano Brivio authored
      When we perform an inexact match on FIB nodes via fib6_locate_1(), longer
      prefixes will be preferred to shorter ones. However, it might happen that
      a node, with higher fn_bit value than some other, has no valid routing
      information.
      
      In this case, we'll pick that node, but it will be discarded by the check
      on RTN_RTINFO in fib6_locate(), and we might miss nodes with valid routing
      information but with lower fn_bit value.
      
      This is apparent when a routing exception is created for a default route:
       # ip -6 route list
       fc00:1::/64 dev veth_A-R1 proto kernel metric 256 pref medium
       fc00:2::/64 dev veth_A-R2 proto kernel metric 256 pref medium
       fc00:4::1 via fc00:2::2 dev veth_A-R2 metric 1024 pref medium
       fe80::/64 dev veth_A-R1 proto kernel metric 256 pref medium
       fe80::/64 dev veth_A-R2 proto kernel metric 256 pref medium
       default via fc00:1::2 dev veth_A-R1 metric 1024 pref medium
       # ip -6 route list cache
       fc00:4::1 via fc00:2::2 dev veth_A-R2 metric 1024 expires 593sec mtu 1500 pref medium
       fc00:3::1 via fc00:1::2 dev veth_A-R1 metric 1024 expires 593sec mtu 1500 pref medium
       # ip -6 route flush cache    # node for default route is discarded
       Failed to send flush request: No such process
       # ip -6 route list cache
       fc00:3::1 via fc00:1::2 dev veth_A-R1 metric 1024 expires 586sec mtu 1500 pref medium
      
      Check right away if the node has a RTN_RTINFO flag, before replacing the
      'prev' pointer, that indicates the longest matching prefix found so far.
      
      Fixes: 38fbeeee
      
       ("ipv6: prepare fib6_locate() for exception table")
      Signed-off-by: default avatarStefano Brivio <sbrivio@redhat.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      40cb35d5
    • Stefano Brivio's avatar
      ipv6: Dump route exceptions if requested · 1e47b483
      Stefano Brivio authored
      Since commit 2b760fcf ("ipv6: hook up exception table to store dst
      cache"), route exceptions reside in a separate hash table, and won't be
      found by walking the FIB, so they won't be dumped to userspace on a
      RTM_GETROUTE message.
      
      This causes 'ip -6 route list cache' and 'ip -6 route flush cache' to
      have no function anymore:
      
       # ip -6 route get fc00:3::1
       fc00:3::1 via fc00:1::2 dev veth_A-R1 src fc00:1::1 metric 1024 expires 539sec mtu 1400 pref medium
       # ip -6 route get fc00:4::1
       fc00:4::1 via fc00:2::2 dev veth_A-R2 src fc00:2::1 metric 1024 expires 536sec mtu 1500 pref medium
       # ip -6 route list cache
       # ip -6 route flush cache
       # ip -6 route get fc00:3::1
       fc00:3::1 via fc00:1::2 dev veth_A-R1 src fc00:1::1 metric 1024 expires 520sec mtu 1400 pref medium
       # ip -6 route get fc00:4::1
       fc00:4::1 via fc00:2::2 dev veth_A-R2 src fc00:2::1 metric 1024 expires 519sec mtu 1500 pref medium
      
      because iproute2 lists cached routes using RTM_GETROUTE, and flushes them
      by listing all the routes, and deleting them with RTM_DELROUTE one by one.
      
      If cached routes are requested using the RTM_F_CLONED flag together with
      strict checking, or if no strict checking is requested (and hence we can't
      consistently apply filters), look up exceptions in the hash table
      associated with the current fib6_info in rt6_dump_route(), and, if present
      and not expired, add them to the dump.
      
      We might be unable to dump all the entries for a given node in a single
      message, so keep track of how many entries were handled for the current
      node in fib6_walker, and skip that amount in case we start from the same
      partially dumped node.
      
      When a partial dump restarts, as the starting node might change when
      'sernum' changes, we have no guarantee that we need to skip the same
      amount of in-node entries. Therefore, we need two counters, and we need to
      zero the in-node counter if the node from which the dump is resumed
      differs.
      
      Note that, with the current version of iproute2, this only fixes the
      'ip -6 route list cache': on a flush command, iproute2 doesn't pass
      RTM_F_CLONED and, due to this inconsistency, 'ip -6 route flush cache' is
      still unable to fetch the routes to be flushed. This will be addressed in
      a patch for iproute2.
      
      To flush cached routes, a procfs entry could be introduced instead: that's
      how it works for IPv4. We already have a rt6_flush_exception() function
      ready to be wired to it. However, this would not solve the issue for
      listing.
      
      Versions of iproute2 and kernel tested:
      
                          iproute2
      kernel             4.14.0   4.15.0   4.19.0   5.0.0   5.1.0    5.1.0, patched
       3.18    list        +        +        +        +       +            +
               flush       +        +        +        +       +            +
       4.4     list        +        +        +        +       +            +
               flush       +        +        +        +       +            +
       4.9     list        +        +        +        +       +            +
               flush       +        +        +        +       +            +
       4.14    list        +        +        +        +       +            +
               flush       +        +        +        +       +            +
       4.15    list
               flush
       4.19    list
               flush
       5.0     list
               flush
       5.1     list
               flush
       with    list        +        +        +        +       +            +
       fix     flush       +        +        +                             +
      
      v7:
        - Explain usage of "skip" counters in commit message (suggested by
          David Ahern)
      
      v6:
        - Rebase onto net-next, use recently introduced nexthop walker
        - Make rt6_nh_dump_exceptions() a separate function (suggested by David
          Ahern)
      
      v5:
        - Use dump_routes and dump_exceptions from filter, ignore NLM_F_MATCH,
          update test results (flushing works with iproute2 < 5.0.0 now)
      
      v4:
        - Split NLM_F_MATCH and strict check handling in separate patches
        - Filter routes using RTM_F_CLONED: if it's not set, only return
          non-cached routes, and if it's set, only return cached routes:
          change requested by David Ahern and Martin Lau. This implies that
          iproute2 needs a separate patch to be able to flush IPv6 cached
          routes. This is not ideal because we can't fix the breakage caused
          by 2b760fcf
      
       entirely in kernel. However, two years have passed
          since then, and this makes it more tolerable
      
      v3:
        - More descriptive comment about expired exceptions in rt6_dump_route()
        - Swap return values of rt6_dump_route() (suggested by Martin Lau)
        - Don't zero skip_in_node in case we don't dump anything in a given pass
          (also suggested by Martin Lau)
        - Remove check on RTM_F_CLONED altogether: in the current UAPI semantic,
          it's just a flag to indicate the route was cloned, not to filter on
          routes
      
      v2: Add tracking of number of entries to be skipped in current node after
          a partial dump. As we restart from the same node, if not all the
          exceptions for a given node fit in a single message, the dump will
          not terminate, as suggested by Martin Lau. This is a concrete
          possibility, setting up a big number of exceptions for the same route
          actually causes the issue, suggested by David Ahern.
      
      Reported-by: default avatarJianlin Shi <jishi@redhat.com>
      Fixes: 2b760fcf
      
       ("ipv6: hook up exception table to store dst cache")
      Signed-off-by: default avatarStefano Brivio <sbrivio@redhat.com>
      Reviewed-by: default avatarDavid Ahern <dsahern@gmail.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      1e47b483
    • Stefano Brivio's avatar
      ipv6/route: Change return code of rt6_dump_route() for partial node dumps · bf9a8a06
      Stefano Brivio authored
      
      
      In the next patch, we are going to add optional dump of exceptions to
      rt6_dump_route().
      
      Change the return code of rt6_dump_route() to accomodate partial node
      dumps: we might dump multiple routes per node, and might be able to dump
      only a given number of them, so fib6_dump_node() will need to know how
      many routes have been dumped on partial dump, to restart the dump from the
      point where it was interrupted.
      
      Note that fib6_dump_node() is the only caller and already handles all
      non-negative return codes as success: those become -1 to signal that we're
      done with the node. If we fail, return 0, as we were unable to dump the
      single route in the node, but we're not done with it.
      
      Signed-off-by: default avatarStefano Brivio <sbrivio@redhat.com>
      Reviewed-by: default avatarDavid Ahern <dsahern@gmail.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      bf9a8a06
    • Stefano Brivio's avatar
      ipv6/route: Don't match on fc_nh_id if not set in ip6_route_del() · 3401bfb1
      Stefano Brivio authored
      If fc_nh_id isn't set, we shouldn't try to match against it. This
      actually matters just for the RTF_CACHE below (where this case is
      already handled): if iproute2 gets a route exception and tries to
      delete it, it won't reference it by fc_nh_id, even if a nexthop
      object might be associated to the originating route.
      
      Fixes: 5b98324e
      
       ("ipv6: Allow routes to use nexthop objects")
      Signed-off-by: default avatarStefano Brivio <sbrivio@redhat.com>
      Reviewed-by: default avatarDavid Ahern <dsahern@gmail.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      3401bfb1
    • Stefano Brivio's avatar
      Revert "net/ipv6: Bail early if user only wants cloned entries" · ef11209d
      Stefano Brivio authored
      This reverts commit 08e814c9
      
      : as we
      are preparing to fix listing and dumping of IPv6 cached routes, we
      need to allow RTM_F_CLONED as a flag to match routes against while
      dumping them.
      
      Signed-off-by: default avatarStefano Brivio <sbrivio@redhat.com>
      Reviewed-by: default avatarDavid Ahern <dsahern@gmail.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      ef11209d
    • Stefano Brivio's avatar
      ipv4: Dump route exceptions if requested · ee28906f
      Stefano Brivio authored
      Since commit 4895c771 ("ipv4: Add FIB nexthop exceptions."), cached
      exception routes are stored as a separate entity, so they are not dumped
      on a FIB dump, even if the RTM_F_CLONED flag is passed.
      
      This implies that the command 'ip route list cache' doesn't return any
      result anymore.
      
      If the RTM_F_CLONED is passed, and strict checking requested, retrieve
      nexthop exception routes and dump them. If no strict checking is
      requested, filtering can't be performed consistently: dump everything in
      that case.
      
      With this, we need to add an argument to the netlink callback in order to
      track how many entries were already dumped for the last leaf included in
      a partial netlink dump.
      
      A single additional argument is sufficient, even if we traverse logically
      nested structures (nexthop objects, hash table buckets, bucket chains): it
      doesn't matter if we stop in the middle of any of those, because they are
      always traversed the same way. As an example, s_i values in [], s_fa
      values in ():
      
        node (fa) #1 [1]
          nexthop #1
          bucket #1 -> #0 in chain (1)
          bucket #2 -> #0 in chain (2) -> #1 in chain (3) -> #2 in chain (4)
          bucket #3 -> #0 in chain (5) -> #1 in chain (6)
      
          nexthop #2
          bucket #1 -> #0 in chain (7) -> #1 in chain (8)
          bucket #2 -> #0 in chain (9)
        --
        node (fa) #2 [2]
          nexthop #1
          bucket #1 -> #0 in chain (1) -> #1 in chain (2)
          bucket #2 -> #0 in chain (3)
      
      it doesn't matter if we stop at (3), (4), (7) for "node #1", or at (2)
      for "node #2": walking flattens all that.
      
      It would even be possible to drop the distinction between the in-tree
      (s_i) and in-node (s_fa) counter, but a further improvement might
      advise against this. This is only as accurate as the existing tracking
      mechanism for leaves: if a partial dump is restarted after exceptions
      are removed or expired, we might skip some non-dumped entries.
      
      To improve this, we could attach a 'sernum' attribute (similar to the
      one used for IPv6) to nexthop entities, and bump this counter whenever
      exceptions change: having a distinction between the two counters would
      make this more convenient.
      
      Listing of exception routes (modified routes pre-3.5) was tested against
      these versions of kernel and iproute2:
      
                          iproute2
      kernel         4.14.0   4.15.0   4.19.0   5.0.0   5.1.0
       3.5-rc4         +        +        +        +       +
       4.4
       4.9
       4.14
       4.15
       4.19
       5.0
       5.1
       fixed           +        +        +        +       +
      
      v7:
         - Move loop over nexthop objects to route.c, and pass struct fib_info
           and table ID to it, not a struct fib_alias (suggested by David Ahern)
         - While at it, note that the NULL check on fa->fa_info is redundant,
           and the check on RTNH_F_DEAD is also not consistent with what's done
           with regular route listing: just keep it for nhc_flags
         - Rename entry point function for dumping exceptions to
           fib_dump_info_fnhe(), and rearrange arguments for consistency with
           fib_dump_info()
         - Rename fnhe_dump_buckets() to fnhe_dump_bucket() and make it handle
           one bucket at a time
         - Expand commit message to describe why we can have a single "skip"
           counter for all exceptions stored in bucket chains in nexthop objects
           (suggested by David Ahern)
      
      v6:
         - Rebased onto net-next
         - Loop over nexthop paths too. Move loop over fnhe buckets to route.c,
           avoids need to export rt_fill_info() and to touch exceptions from
           fib_trie.c. Pass NULL as flow to rt_fill_info(), it now allows that
           (suggested by David Ahern)
      
      Fixes: 4895c771
      
       ("ipv4: Add FIB nexthop exceptions.")
      Signed-off-by: default avatarStefano Brivio <sbrivio@redhat.com>
      Reviewed-by: default avatarDavid Ahern <dsahern@gmail.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      ee28906f
    • Stefano Brivio's avatar
      ipv4/route: Allow NULL flowinfo in rt_fill_info() · d948974c
      Stefano Brivio authored
      
      
      In the next patch, we're going to use rt_fill_info() to dump exception
      routes upon RTM_GETROUTE with NLM_F_ROOT, meaning userspace is requesting
      a dump and not a specific route selection, which in turn implies the input
      interface is not relevant. Update rt_fill_info() to handle a NULL
      flowinfo.
      
      v7: If fl4 is NULL, explicitly set r->rtm_tos to 0: it's not initialised
          otherwise (spotted by David Ahern)
      
      v6: New patch
      
      Suggested-by: default avatarDavid Ahern <dsahern@gmail.com>
      Signed-off-by: default avatarStefano Brivio <sbrivio@redhat.com>
      Reviewed-by: default avatarDavid Ahern <dsahern@gmail.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      d948974c
    • Stefano Brivio's avatar
      ipv4/fib_frontend: Allow RTM_F_CLONED flag to be used for filtering · b597ca6e
      Stefano Brivio authored
      This functionally reverts the check introduced by commit
      e8ba330a ("rtnetlink: Update fib dumps for strict data checking")
      as modified by commit e4e92fb1
      
       ("net/ipv4: Bail early if user only
      wants prefix entries").
      
      As we are preparing to fix listing of IPv4 cached routes, we need to
      give userspace a way to request them.
      
      Signed-off-by: default avatarStefano Brivio <sbrivio@redhat.com>
      Reviewed-by: default avatarDavid Ahern <dsahern@gmail.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      b597ca6e
    • Stefano Brivio's avatar
      fib_frontend, ip6_fib: Select routes or exceptions dump from RTM_F_CLONED · 564c91f7
      Stefano Brivio authored
      
      
      The following patches add back the ability to dump IPv4 and IPv6 exception
      routes, and we need to allow selection of regular routes or exceptions.
      
      Use RTM_F_CLONED as filter to decide whether to dump routes or exceptions:
      iproute2 passes it in dump requests (except for IPv6 cache flush requests,
      this will be fixed in iproute2) and this used to work as long as
      exceptions were stored directly in the FIB, for both IPv4 and IPv6.
      
      Caveat: if strict checking is not requested (that is, if the dump request
      doesn't go through ip_valid_fib_dump_req()), we can't filter on protocol,
      tables or route types.
      
      In this case, filtering on RTM_F_CLONED would be inconsistent: we would
      fix 'ip route list cache' by returning exception routes and at the same
      time introduce another bug in case another selector is present, e.g. on
      'ip route list cache table main' we would return all exception routes,
      without filtering on tables.
      
      Keep this consistent by applying no filters at all, and dumping both
      routes and exceptions, if strict checking is not requested. iproute2
      currently filters results anyway, and no unwanted results will be
      presented to the user. The kernel will just dump more data than needed.
      
      v7: No changes
      
      v6: Rebase onto net-next, no changes
      
      v5: New patch: add dump_routes and dump_exceptions flags in filter and
          simply clear the unwanted one if strict checking is enabled, don't
          ignore NLM_F_MATCH and don't set filter_set if NLM_F_MATCH is set.
          Skip filtering altogether if no strict checking is requested:
          selecting routes or exceptions only would be inconsistent with the
          fact we can't filter on tables.
      
      Signed-off-by: default avatarStefano Brivio <sbrivio@redhat.com>
      Reviewed-by: default avatarDavid Ahern <dsahern@gmail.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      564c91f7