• Florian Westphal's avatar
    bridge: netfilter: don't call iptables on vlan packets if sysctl is off · 739e4505
    Florian Westphal authored
    When net.bridge.bridge-nf-filter-vlan-tagged is 0 (default), vlan packets
    arriving should not be sent to ip(6)tables by bridge netfilter.
    
    However, it turns out that we currently always send VLAN packets to
    netfilter, if ..
    a), CONFIG_VLAN_8021Q is enabled ; or
    b), CONFIG_VLAN_8021Q is not set but rx vlan offload is enabled
       on the bridge port.
    
    This is because bridge netfilter treats skb with
    skb->protocol == ETH_P_IP{V6} as "non-vlan packet".
    
    With rx vlan offload on or CONFIG_VLAN_8021Q=y, the vlan header has
    already been removed here, and we cannot rely on skb->protocol alone.
    
    Fix this by only using skb->protocol if the skb has no vlan tag,
    or if a vlan tag is present and filter-vlan-tagged bridge netfilter
    sysctl is enabled.
    
    We cannot remove the skb->protocol == htons(ETH_P_8021Q) test
    because the vlan tag is still around in the CONFIG_VLAN_8021Q=n &&
    "ethtool -K $itf rxvlan off" case.
    
    reproducer:
    iptables -t raw -I PREROUTING -i br0
    iptables -t raw -I PREROUTING -i br0.1
    
    Then send packets to an ip address configured on br0.1 interface.
    Even with net.bridge.bridge-nf-filter-vlan-tagged=0, the 1st rule
    will match instead of the 2nd one.
    
    With this patch applied, the 2nd rule will match instead.
    In the non-local address case, netfilter won't be consulted after
    this patch unless the sysctl is switched on.
    Signed-off-by: default avatarFlorian Westphal <fw@strlen.de>
    Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
    Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
    739e4505
br_netfilter.c 27.4 KB