Skip to content

Commit 82650da

Browse files
committed
Merge branch 'bpf-flow-dissector-fix-port-ranges'
Yoshiki Komachi says: ==================== When I tried a test based on the selftest program for BPF flow dissector (test_flow_dissector.sh), I observed unexpected result as below: $ tc filter add dev lo parent ffff: protocol ip pref 1337 flower ip_proto \ udp src_port 8-10 action drop $ tools/testing/selftests/bpf/test_flow_dissector -i 4 -f 9 -F inner.dest4: 127.0.0.1 inner.source4: 127.0.0.3 pkts: tx=10 rx=10 The last rx means the number of received packets. I expected rx=0 in this test (i.e., all received packets should have been dropped), but it resulted in acceptance. Although the previous commit 8ffb055 ("cls_flower: Fix the behavior using port ranges with hw-offload") added new flag and field toward filtering based on port ranges with hw-offload, it missed applying for BPF flow dissector then. As a result, BPF flow dissector currently stores data extracted from packets in incorrect field used for exact match whenever packets are classified by filters based on port ranges. Thus, they never match rules in such cases because flow dissector gives rise to generating incorrect flow keys. This series fixes the issue by replacing incorrect flag and field with new ones in BPF flow dissector, and adds a test for filtering based on specified port ranges to the existing selftest program. Changes in v2: - set key_ports to NULL at the top of __skb_flow_bpf_to_target() ==================== Signed-off-by: Daniel Borkmann <[email protected]>
2 parents b23bfa5 + 265bb35 commit 82650da

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

net/core/flow_dissector.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -834,10 +834,10 @@ static void __skb_flow_bpf_to_target(const struct bpf_flow_keys *flow_keys,
834834
struct flow_dissector *flow_dissector,
835835
void *target_container)
836836
{
837+
struct flow_dissector_key_ports *key_ports = NULL;
837838
struct flow_dissector_key_control *key_control;
838839
struct flow_dissector_key_basic *key_basic;
839840
struct flow_dissector_key_addrs *key_addrs;
840-
struct flow_dissector_key_ports *key_ports;
841841
struct flow_dissector_key_tags *key_tags;
842842

843843
key_control = skb_flow_dissector_target(flow_dissector,
@@ -876,10 +876,17 @@ static void __skb_flow_bpf_to_target(const struct bpf_flow_keys *flow_keys,
876876
key_control->addr_type = FLOW_DISSECTOR_KEY_IPV6_ADDRS;
877877
}
878878

879-
if (dissector_uses_key(flow_dissector, FLOW_DISSECTOR_KEY_PORTS)) {
879+
if (dissector_uses_key(flow_dissector, FLOW_DISSECTOR_KEY_PORTS))
880880
key_ports = skb_flow_dissector_target(flow_dissector,
881881
FLOW_DISSECTOR_KEY_PORTS,
882882
target_container);
883+
else if (dissector_uses_key(flow_dissector,
884+
FLOW_DISSECTOR_KEY_PORTS_RANGE))
885+
key_ports = skb_flow_dissector_target(flow_dissector,
886+
FLOW_DISSECTOR_KEY_PORTS_RANGE,
887+
target_container);
888+
889+
if (key_ports) {
883890
key_ports->src = flow_keys->sport;
884891
key_ports->dst = flow_keys->dport;
885892
}

tools/testing/selftests/bpf/test_flow_dissector.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,20 @@ echo "Testing IPv4 + GRE..."
139139

140140
tc filter del dev lo ingress pref 1337
141141

142+
echo "Testing port range..."
143+
# Drops all IP/UDP packets coming from port 8-10
144+
tc filter add dev lo parent ffff: protocol ip pref 1337 flower ip_proto \
145+
udp src_port 8-10 action drop
146+
147+
# Send 10 IPv4/UDP packets from port 7. Filter should not drop any.
148+
./test_flow_dissector -i 4 -f 7
149+
# Send 10 IPv4/UDP packets from port 9. Filter should drop all.
150+
./test_flow_dissector -i 4 -f 9 -F
151+
# Send 10 IPv4/UDP packets from port 11. Filter should not drop any.
152+
./test_flow_dissector -i 4 -f 11
153+
154+
tc filter del dev lo ingress pref 1337
155+
142156
echo "Testing IPv6..."
143157
# Drops all IPv6/UDP packets coming from port 9
144158
tc filter add dev lo parent ffff: protocol ipv6 pref 1337 flower ip_proto \

0 commit comments

Comments
 (0)