• David Ahern's avatar
    net: l3mdev: address selection should only consider devices in L3 domain · 3f2fb9a8
    David Ahern authored
    David Lamparter noted a use case where the source address selection fails
    to pick an address from a VRF interface - unnumbered interfaces.
    Relevant commands from his script:
        ip addr add dev lo
        ip link set lo up
        ip link add name vrf0 type vrf table 101
        ip rule add oif vrf0 table 101
        ip rule add iif vrf0 table 101
        ip link set vrf0 up
        ip addr add dev vrf0
        ip link add name dummy2 type dummy
        ip link set dummy2 master vrf0 up
        --> note dummy2 has no address - unnumbered device
        ip route add dev dummy2 table 101
        ip neigh add dev dummy2 lladdr 02:00:00:00:00:02
        tcpdump -ni dummy2 &
    And using ping instead of his socat example:
        $ ping -I vrf0 -c1
        ping: Warning: source address might be selected on device other than vrf0.
        PING ( from vrf0: 56(84) bytes of data.
    >From tcpdump:
        12:57:29.449128 IP > ICMP echo request, id 2491, seq 1, length 64
    Note the source address is from lo and is not a VRF local address. With
    this patch:
        $ ping -I vrf0 -c1
        PING ( from vrf0: 56(84) bytes of data.
    >From tcpdump:
        12:59:25.096426 IP > ICMP echo request, id 2113, seq 1, length 64
    Now the source address comes from vrf0.
    The ipv4 function for selecting source address takes a const argument.
    Removing the const requires touching a lot of places, so instead
    l3mdev_master_ifindex_rcu is changed to take a const argument and then
    do the typecast to non-const as required by netdev_master_upper_dev_get_rcu.
    This is similar to what l3mdev_fib_table_rcu does.
    IPv6 for unnumbered interfaces appears to be selecting the addresses
    Cc: David Lamparter <david@opensourcerouting.org>
    Signed-off-by: default avatarDavid Ahern <dsa@cumulusnetworks.com>
    Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
l3mdev.h 5.19 KB