Skip to content

Commit dae8ca9

Browse files
congwangjfvogel
authored andcommitted
flow_dissector: Fix handling of mixed port and port-range keys
[ Upstream commit 3e57968 ] This patch fixes a bug in TC flower filter where rules combining a specific destination port with a source port range weren't working correctly. The specific case was when users tried to configure rules like: tc filter add dev ens38 ingress protocol ip flower ip_proto udp \ dst_port 5000 src_port 2000-3000 action drop The root cause was in the flow dissector code. While both FLOW_DISSECTOR_KEY_PORTS and FLOW_DISSECTOR_KEY_PORTS_RANGE flags were being set correctly in the classifier, the __skb_flow_dissect_ports() function was only populating one of them: whichever came first in the enum check. This meant that when the code needed both a specific port and a port range, one of them would be left as 0, causing the filter to not match packets as expected. Fix it by removing the either/or logic and instead checking and populating both key types independently when they're in use. Fixes: 8ffb055 ("cls_flower: Fix the behavior using port ranges with hw-offload") Reported-by: Qiang Zhang <[email protected]> Closes: https://lore.kernel.org/netdev/CAPx+-5uvFxkhkz4=j_Xuwkezjn9U6kzKTD5jz4tZ9msSJ0fOJA@mail.gmail.com/ Cc: Yoshiki Komachi <[email protected]> Cc: Jamal Hadi Salim <[email protected]> Cc: Jiri Pirko <[email protected]> Signed-off-by: Cong Wang <[email protected]> Reviewed-by: Ido Schimmel <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]> Signed-off-by: Sasha Levin <[email protected]> (cherry picked from commit 90c7f5cd592009ba469610dc618b045a40a5ed12) Signed-off-by: Jack Vogel <[email protected]>
1 parent 9d7db6d commit dae8ca9

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

net/core/flow_dissector.c

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -853,23 +853,30 @@ __skb_flow_dissect_ports(const struct sk_buff *skb,
853853
void *target_container, const void *data,
854854
int nhoff, u8 ip_proto, int hlen)
855855
{
856-
enum flow_dissector_key_id dissector_ports = FLOW_DISSECTOR_KEY_MAX;
857-
struct flow_dissector_key_ports *key_ports;
856+
struct flow_dissector_key_ports_range *key_ports_range = NULL;
857+
struct flow_dissector_key_ports *key_ports = NULL;
858+
__be32 ports;
858859

859860
if (dissector_uses_key(flow_dissector, FLOW_DISSECTOR_KEY_PORTS))
860-
dissector_ports = FLOW_DISSECTOR_KEY_PORTS;
861-
else if (dissector_uses_key(flow_dissector,
862-
FLOW_DISSECTOR_KEY_PORTS_RANGE))
863-
dissector_ports = FLOW_DISSECTOR_KEY_PORTS_RANGE;
861+
key_ports = skb_flow_dissector_target(flow_dissector,
862+
FLOW_DISSECTOR_KEY_PORTS,
863+
target_container);
864864

865-
if (dissector_ports == FLOW_DISSECTOR_KEY_MAX)
865+
if (dissector_uses_key(flow_dissector, FLOW_DISSECTOR_KEY_PORTS_RANGE))
866+
key_ports_range = skb_flow_dissector_target(flow_dissector,
867+
FLOW_DISSECTOR_KEY_PORTS_RANGE,
868+
target_container);
869+
870+
if (!key_ports && !key_ports_range)
866871
return;
867872

868-
key_ports = skb_flow_dissector_target(flow_dissector,
869-
dissector_ports,
870-
target_container);
871-
key_ports->ports = __skb_flow_get_ports(skb, nhoff, ip_proto,
872-
data, hlen);
873+
ports = __skb_flow_get_ports(skb, nhoff, ip_proto, data, hlen);
874+
875+
if (key_ports)
876+
key_ports->ports = ports;
877+
878+
if (key_ports_range)
879+
key_ports_range->tp.ports = ports;
873880
}
874881

875882
static void

0 commit comments

Comments
 (0)