Commit d2126838 authored by Davide Caratti's avatar Davide Caratti Committed by David S. Miller

flow_dissector: fix TTL and TOS dissection on IPv4 fragments

the following command:

 # tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \
   $tcflags dst_ip 192.0.2.2 ip_ttl 63 action drop

doesn't drop all IPv4 packets that match the configured TTL / destination
address. In particular, if "fragment offset" or "more fragments" have non
zero value in the IPv4 header, setting of FLOW_DISSECTOR_KEY_IP is simply
ignored. Fix this dissecting IPv4 TTL and TOS before fragment info; while
at it, add a selftest for tc flower's match on 'ip_ttl' that verifies the
correct behavior.

Fixes: 518d8a2e ("net/flow_dissector: add support for dissection of misc ip header fields")
Reported-by: default avatarShuang Li <shuali@redhat.com>
Signed-off-by: default avatarDavide Caratti <dcaratti@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 39935dcc
...@@ -1050,6 +1050,9 @@ bool __skb_flow_dissect(const struct net *net, ...@@ -1050,6 +1050,9 @@ bool __skb_flow_dissect(const struct net *net,
key_control->addr_type = FLOW_DISSECTOR_KEY_IPV4_ADDRS; key_control->addr_type = FLOW_DISSECTOR_KEY_IPV4_ADDRS;
} }
__skb_flow_dissect_ipv4(skb, flow_dissector,
target_container, data, iph);
if (ip_is_fragment(iph)) { if (ip_is_fragment(iph)) {
key_control->flags |= FLOW_DIS_IS_FRAGMENT; key_control->flags |= FLOW_DIS_IS_FRAGMENT;
...@@ -1066,9 +1069,6 @@ bool __skb_flow_dissect(const struct net *net, ...@@ -1066,9 +1069,6 @@ bool __skb_flow_dissect(const struct net *net,
} }
} }
__skb_flow_dissect_ipv4(skb, flow_dissector,
target_container, data, iph);
break; break;
} }
case htons(ETH_P_IPV6): { case htons(ETH_P_IPV6): {
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
ALL_TESTS="match_dst_mac_test match_src_mac_test match_dst_ip_test \ ALL_TESTS="match_dst_mac_test match_src_mac_test match_dst_ip_test \
match_src_ip_test match_ip_flags_test match_pcp_test match_vlan_test \ match_src_ip_test match_ip_flags_test match_pcp_test match_vlan_test \
match_ip_tos_test match_indev_test" match_ip_tos_test match_indev_test match_ip_ttl_test"
NUM_NETIFS=2 NUM_NETIFS=2
source tc_common.sh source tc_common.sh
source lib.sh source lib.sh
...@@ -310,6 +310,42 @@ match_ip_tos_test() ...@@ -310,6 +310,42 @@ match_ip_tos_test()
log_test "ip_tos match ($tcflags)" log_test "ip_tos match ($tcflags)"
} }
match_ip_ttl_test()
{
RET=0
tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \
$tcflags dst_ip 192.0.2.2 ip_ttl 63 action drop
tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \
$tcflags dst_ip 192.0.2.2 action drop
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
-t ip "ttl=63" -q
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
-t ip "ttl=63,mf,frag=256" -q
tc_check_packets "dev $h2 ingress" 102 1
check_fail $? "Matched on the wrong filter (no check on ttl)"
tc_check_packets "dev $h2 ingress" 101 2
check_err $? "Did not match on correct filter (ttl=63)"
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
-t ip "ttl=255" -q
tc_check_packets "dev $h2 ingress" 101 3
check_fail $? "Matched on a wrong filter (ttl=63)"
tc_check_packets "dev $h2 ingress" 102 1
check_err $? "Did not match on correct filter (no check on ttl)"
tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower
tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
log_test "ip_ttl match ($tcflags)"
}
match_indev_test() match_indev_test()
{ {
RET=0 RET=0
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment