Skip to contentSkip to conversation

ethtool: Drop check for vlan etype and vlan tci when parsing flow_rule

PATCH In review Maxime Chevallier 2 participants 2 messages May 29, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ethtool: Drop check for vlan etype and vlan tci when parsing flow_rule

When parsing an ethtool flow spec to build a flow_rule, the code checks if both the vlan etype and the vlan tci are specified by the user to add a FLOW_DISSECTOR_KEY_VLAN match.

However, when the user only specified a vlan etype or a vlan tci, this check silently ignores these parameters.

For example, the following rule :

ethtool -N eth0 flow-type udp4 vlan 0x0010 action -1 loc 0

will result in no error being issued, but the equivalent rule will be created and passed to the NIC driver :

ethtool -N eth0 flow-type udp4 action -1 loc 0

In the end, neither the NIC driver using the rule nor the end user have a way to know that these keys were dropped along the way, or that incorrect parameters were entered.

This kind of check should be left to either the driver, or the ethtool flow spec layer.

This commit makes so that ethtool parameters are forwarded as-is to the NIC driver.

Since none of the users of ethtool_rx_flow_rule_create are using the VLAN dissector, I don't think this qualifies as a regression.

Fixes eca4205f9ec3 ("ethtool: add ethtool_rx_flow_spec to flow_rule structure translator")

---
V2: Added Fixes: tag, targetted to -net.

 net/core/ethtool.c | 31 ++++++++++++++-----------------
 1 file changed, 14 insertions(+), 17 deletions(-)
net/core/ethtool.c +14 -17
index 4a593853cbf2..2fe86893e9b5 100644
@@ -3010,26 +3010,23 @@ ethtool_rx_flow_rule_create(const struct ethtool_rx_flow_spec_input *input)
 		const struct ethtool_flow_ext *ext_h_spec = &fs->h_ext;
 		const struct ethtool_flow_ext *ext_m_spec = &fs->m_ext;
 
-		if (ext_m_spec->vlan_etype &&
-		    ext_m_spec->vlan_tci) {
-			match->key.vlan.vlan_tpid = ext_h_spec->vlan_etype;
-			match->mask.vlan.vlan_tpid = ext_m_spec->vlan_etype;
+		match->key.vlan.vlan_tpid = ext_h_spec->vlan_etype;
+		match->mask.vlan.vlan_tpid = ext_m_spec->vlan_etype;
 
-			match->key.vlan.vlan_id =
-				ntohs(ext_h_spec->vlan_tci) & 0x0fff;
-			match->mask.vlan.vlan_id =
-				ntohs(ext_m_spec->vlan_tci) & 0x0fff;
+		match->key.vlan.vlan_id =
+			ntohs(ext_h_spec->vlan_tci) & 0x0fff;
+		match->mask.vlan.vlan_id =
+			ntohs(ext_m_spec->vlan_tci) & 0x0fff;
 
-			match->key.vlan.vlan_priority =
-				(ntohs(ext_h_spec->vlan_tci) & 0xe000) >> 13;
-			match->mask.vlan.vlan_priority =
-				(ntohs(ext_m_spec->vlan_tci) & 0xe000) >> 13;
+		match->key.vlan.vlan_priority =
+			(ntohs(ext_h_spec->vlan_tci) & 0xe000) >> 13;
+		match->mask.vlan.vlan_priority =
+			(ntohs(ext_m_spec->vlan_tci) & 0xe000) >> 13;
 
-			match->dissector.used_keys |=
-				BIT(FLOW_DISSECTOR_KEY_VLAN);
-			match->dissector.offset[FLOW_DISSECTOR_KEY_VLAN] =
-				offsetof(struct ethtool_rx_flow_key, vlan);
-		}
+		match->dissector.used_keys |=
+			BIT(FLOW_DISSECTOR_KEY_VLAN);
+		match->dissector.offset[FLOW_DISSECTOR_KEY_VLAN] =
+			offsetof(struct ethtool_rx_flow_key, vlan);
 	}
 	if (fs->flow_type & FLOW_MAC_EXT) {
 		const struct ethtool_flow_ext *ext_h_spec = &fs->h_ext;
Signature · 1 line
2.20.1
#1 lore raw
Quoted 42 lines · Maxime Chevallier

When parsing an ethtool flow spec to build a flow_rule, the code checks if both the vlan etype and the vlan tci are specified by the user to add a FLOW_DISSECTOR_KEY_VLAN match.

However, when the user only specified a vlan etype or a vlan tci, this check silently ignores these parameters.

For example, the following rule :

ethtool -N eth0 flow-type udp4 vlan 0x0010 action -1 loc 0

will result in no error being issued, but the equivalent rule will be created and passed to the NIC driver :

ethtool -N eth0 flow-type udp4 action -1 loc 0

In the end, neither the NIC driver using the rule nor the end user have a way to know that these keys were dropped along the way, or that incorrect parameters were entered.

This kind of check should be left to either the driver, or the ethtool flow spec layer.

This commit makes so that ethtool parameters are forwarded as-is to the NIC driver.

Since none of the users of ethtool_rx_flow_rule_create are using the VLAN dissector, I don't think this qualifies as a regression.

Fixes eca4205f9ec3 ("ethtool: add ethtool_rx_flow_spec to flow_rule structure translator")

---
V2: Added Fixes: tag, targetted to -net.

 net/core/ethtool.c | 31 ++++++++++++++-----------------
 1 file changed, 14 insertions(+), 17 deletions(-)
net/core/ethtool.c +0 -0
index 4a593853cbf2..2fe86893e9b5 100644

net/core/ethtool.c ethtool_rx_flow_rule_create(const struct ethtool_rx_flow_spec_input *input) · line 3014

Quoted 9 lines
net/core/ethtool.c +2 -4
@@ -3010,26 +3010,23 @@ ethtool_rx_flow_rule_create(const struct ethtool_rx_flow_spec_input *input)
 		const struct ethtool_flow_ext *ext_h_spec = &fs->h_ext;
 		const struct ethtool_flow_ext *ext_m_spec = &fs->m_ext;
 
-		if (ext_m_spec->vlan_etype &&
-		    ext_m_spec->vlan_tci) {
-			match->key.vlan.vlan_tpid = ext_h_spec->vlan_etype;
-			match->mask.vlan.vlan_tpid = ext_m_spec->vlan_etype;
+		match->key.vlan.vlan_tpid = ext_h_spec->vlan_etype;
+		match->mask.vlan.vlan_tpid = ext_m_spec->vlan_etype;

Could you just check for ext_m_spec->vlan_etype, then set vlan_tpid accordingly? ie.

        if (ext_m_spec->vlan_etype) {
		match->key.vlan.vlan_tpid = ext_h_spec->vlan_etype;
		match->mask.vlan.vlan_tpid = ext_m_spec->vlan_etype;
        }
        if (ext_m_spec->vlan_tci) {
                match->key.vlan.vlan_id = ...;
                match->mask.vlan.vlan_id = ...;
                match->key.vlan.vlan_priority = ...;
                match->mask.vlan.vlan_priority = ...;
        }

        if (ext_m_spec->vlan_etype ||
            ext_m_spec->vlan_tci) {
		match->dissector.used_keys |=
			BIT(FLOW_DISSECTOR_KEY_VLAN);
		match->dissector.offset[FLOW_DISSECTOR_KEY_VLAN] =
			offsetof(struct ethtool_rx_flow_key, vlan);
        }

Something like this above.