• Vlad Buslov's avatar
    net/sched: flower: fix parsing of ethertype following VLAN header · 2105f700
    Vlad Buslov authored
    A tc flower filter matching TCA_FLOWER_KEY_VLAN_ETH_TYPE is expected to
    match the L2 ethertype following the first VLAN header, as confirmed by
    linked discussion with the maintainer. However, such rule also matches
    packets that have additional second VLAN header, even though filter has
    both eth_type and vlan_ethtype set to "ipv4". Looking at the code this
    seems to be mostly an artifact of the way flower uses flow dissector.
    First, even though looking at the uAPI eth_type and vlan_ethtype appear
    like a distinct fields, in flower they are all mapped to the same
    key->basic.n_proto. Second, flow dissector skips following VLAN header as
    no keys for FLOW_DISSECTOR_KEY_CVLAN are set and eventually assigns the
    value of n_proto to last parsed header. With these, such filters ignore any
    headers present between first VLAN header and first "non magic"
    header (ipv4 in this case) that doesn't result
    FLOW_DISSECT_RET_PROTO_AGAIN.
    
    Fix the issue by extending flow dissector VLAN key structure with new
    'vlan_eth_type' field that matches first ethertype following previously
    parsed VLAN header. Modify flower classifier to set the new
    flow_dissector_key_vlan->vlan_eth_type with value obtained from
    TCA_FLOWER_KEY_VLAN_ETH_TYPE/TCA_FLOWER_KEY_CVLAN_ETH_TYPE uAPIs.
    
    Link: https://lore.kernel.org/all/Yjhgi48BpTGh6dig@nanopsycho/
    Fixes: 9399ae9a ("net_sched: flower: Add vlan support")
    Fixes: d64efd09 ("net/sched: flower: Add supprt for matching on QinQ vlan headers")
    Signed-off-by: default avatarVlad Buslov <vladbu@nvidia.com>
    Reviewed-by: default avatarJiri Pirko <jiri@nvidia.com>
    Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
    2105f700
flow_dissector.c 49.5 KB