Currently, OVS checks the UDP destination port first, even when
check_tnl_key is enabled. This unnecessarily masks UDP destination
port bits for ordinary non-BFD traffic with a nonzero tunnel key.

Check the tunnel key before the UDP destination port so that packets
with a nonzero key do not acquire a UDP port mask from the BFD check.

Fixes: 2ccd0d2f0b63 ("bfd: Make the tp_dst masking megaflow-friendly.")
Signed-off-by: Alexandra Rukomoinikova <[email protected]>
---
 lib/bfd.c    | 25 ++++++++++++++-----------
 tests/bfd.at | 38 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+), 11 deletions(-)

diff --git a/lib/bfd.c b/lib/bfd.c
index b8149e789..50e9293dd 100644
--- a/lib/bfd.c
+++ b/lib/bfd.c
@@ -676,24 +676,27 @@ bfd_should_process_flow(const struct bfd *bfd_, const 
struct flow *flow,
     if (flow->dl_type == htons(ETH_TYPE_IP)) {
         memset(&wc->masks.nw_proto, 0xff, sizeof wc->masks.nw_proto);
         if (flow->nw_proto == IPPROTO_UDP
-            && !(flow->nw_frag & FLOW_NW_FRAG_LATER)
-            && tp_dst_equals(flow, BFD_DEST_PORT, wc)
-            && (bfd->ip_src == htonl(BFD_DEFAULT_SRC_IP)
-                || bfd->ip_src == flow->nw_dst)) {
-
-            if (bfd->ip_src == flow->nw_dst) {
-                memset(&wc->masks.nw_dst, 0xffffffff, sizeof wc->masks.nw_dst);
-            }
-
+            && !(flow->nw_frag & FLOW_NW_FRAG_LATER)) {
             bool check_tnl_key;
 
             atomic_read_relaxed(&bfd->check_tnl_key, &check_tnl_key);
             if (check_tnl_key) {
                 memset(&wc->masks.tunnel.tun_id, 0xff,
                        sizeof wc->masks.tunnel.tun_id);
-                return flow->tunnel.tun_id == htonll(0);
+                if (flow->tunnel.tun_id != htonll(0)) {
+                    return false;
+                }
+            }
+
+            if (tp_dst_equals(flow, BFD_DEST_PORT, wc)
+                && (bfd->ip_src == htonl(BFD_DEFAULT_SRC_IP)
+                    || bfd->ip_src == flow->nw_dst)) {
+                if (bfd->ip_src == flow->nw_dst) {
+                    memset(&wc->masks.nw_dst, 0xff, sizeof wc->masks.nw_dst);
+                }
+
+                return true;
             }
-            return true;
         }
     }
     return false;
diff --git a/tests/bfd.at b/tests/bfd.at
index 3069b3722..b857b8482 100644
--- a/tests/bfd.at
+++ b/tests/bfd.at
@@ -1135,3 +1135,41 @@ Datapath actions: 100
 
 OVS_VSWITCHD_STOP
 AT_CLEANUP
+
+AT_SETUP([bfd - tunnel key check avoids UDP port masking])
+OVS_VSWITCHD_START([add-port br0 p1 -- set Interface p1 type=gre \
+                    options:remote_ip=2.2.2.2 options:key=flow 
ofport_request=1 -- \
+                    set interface p1 bfd:enable=true bfd:bfd_src_ip=2.2.2.1 
bfd:check_tnl_key=true -- \
+                    set bridge br0 fail-mode=standalone])
+
+# With zero tun key BFD checks the UDP destination port.
+AT_CHECK([ovs-appctl ofproto/trace --l7-len 0 ovs-dummy 
'tunnel(tun_id=0x0,src=2.2.2.2,dst=2.2.2.1,tos=0x0,ttl=64,tp_src=0,tp_dst=0,flags(key)),in_port(1),skb_mark(0/0),eth(src=00:11:22:33:44:66,dst=00:23:20:00:00:77),eth_type(0x0800),ipv4(src=192.168.2.2/0.0.0.0,dst=192.168.2.1/0.0.0.0,proto=17/0xff,tos=0/0,ttl=255/0,frag=no),udp(src=49152/0,dst=3784/0xffff)'
 -generate], [0], [stdout])
+AT_CHECK([tail -10 stdout], [0], [dnl
+bridge("br0")
+-------------
+ 0. priority 0
+    NORMAL
+     -> learned that 00:11:22:33:44:66 is on port p1 in VLAN 0
+     -> no learned MAC for destination, flooding
+
+Final flow: unchanged
+Megaflow: 
recirc_id=0,eth,udp,tun_id=0,tun_src=2.2.2.2,tun_dst=2.2.2.1,tun_tos=0,tun_flags=+key,in_port=1,dl_src=00:11:22:33:44:66,dl_dst=00:23:20:00:00:77,nw_frag=no,tp_dst=3784
+Datapath actions: 100
+], [])
+
+# With a nonzero tunnel key, BFD rejects the packet before checking the UDP 
destination port, leaving that field wildcarded.
+AT_CHECK([ovs-appctl ofproto/trace --l7-len 0 ovs-dummy 
'tunnel(tun_id=0x1,src=2.2.2.2,dst=2.2.2.1,tos=0x0,ttl=64,tp_src=0,tp_dst=0,flags(key)),in_port(1),skb_mark(0/0),eth(src=00:11:22:33:44:66,dst=00:23:20:00:00:77),eth_type(0x0800),ipv4(src=192.168.2.2/0.0.0.0,dst=192.168.2.1/0.0.0.0,proto=17/0xff,tos=0/0,ttl=255/0,frag=no),udp(src=49152/0,dst=3784/0xffff)'
 -generate], [0], [stdout])
+AT_CHECK([tail -9 stdout], [0], [dnl
+bridge("br0")
+-------------
+ 0. priority 0
+    NORMAL
+     -> no learned MAC for destination, flooding
+
+Final flow: unchanged
+Megaflow: 
recirc_id=0,eth,udp,tun_id=0x1,tun_src=2.2.2.2,tun_dst=2.2.2.1,tun_tos=0,tun_flags=+key,in_port=1,dl_src=00:11:22:33:44:66,dl_dst=00:23:20:00:00:77,nw_frag=no
+Datapath actions: 100
+], [])
+
+OVS_VSWITCHD_STOP
+AT_CLEANUP
-- 
2.48.1

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to