diff mbox series

[ovs-dev,v2] dpctl/add-flow: Fix ovs-dpdk crash when add dp flow without in_port field.

Message ID 1614307742-11842-1-git-send-email-maoyingming@baidu.com
State Superseded
Headers show
Series [ovs-dev,v2] dpctl/add-flow: Fix ovs-dpdk crash when add dp flow without in_port field. | expand

Commit Message

Mao,Yingming Feb. 26, 2021, 2:49 a.m. UTC
Fix the following ovs-dpdk crash and add a unit test for this issue
to tests/dpif-netdev.at

$ ovs-appctl dpctl/add-flow  netdev@ovs-netdev "eth(),eth_type(0x0800),ipv4()" "3"
unixctl|WARN|error communicating with unix:/usr/local/var/run/openvswitch/ovs-vswitchd.1995.ctl: End of file
ovs-appctl: ovs-vswitchd: transaction error (End of file)

ovs-vswitchd.log record:
util(ovs-vswitchd)|EMER|lib/dpif-netdev.c:3638: assertion match->wc.masks.in_port.odp_port == ODPP_NONE failed in dp_netdev_flow_add()
daemon_unix(monitor)|ERR|2 crashes: pid 1995 died, killed (Aborted), core dumped, restarting

Fix result:

$ ovs-appctl dpctl/add-flow  netdev@ovs-netdev "eth(),eth_type(0x0800),ipv4()" "3"
ovs-vswitchd: updating flow table (Invalid argument)
ovs-appctl: ovs-vswitchd: server returned an error

ovs-vswitchd.log record:
dpif_netdev|ERR|failed to put[create] flow: in_port is not an exact match
dpif|WARN|netdev@ovs-netdev: failed to put[create] (Invalid argument) ufid:7ee62592-88ca-4ff2-9e42-38c5d844ffd1 eth(src=00:00:00:00:00:00/00:00:00:00:00:00,dst=00:00:00:00:00:00/00:00:00:00:00:00),eth_type(0x0800),ipv4(src=0.0.0.0/0.0.0.0,dst=0.0.0.0/0.0.0.0,proto=0/0,tos=0/0,ttl=0/0), actions:3

Signed-off-by: Mao YingMing <maoyingming@baidu.com>
---
 lib/dpif-netdev.c    |  9 +++++++++
 tests/dpif-netdev.at | 24 +++++++++++++++++++++++-
 2 files changed, 32 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
index e3fd0a0..d4561e2 100644
--- a/lib/dpif-netdev.c
+++ b/lib/dpif-netdev.c
@@ -3834,6 +3834,15 @@  dpif_netdev_flow_put(struct dpif *dpif, const struct dpif_flow_put *put)
         return error;
     }
 
+    if (match.wc.masks.in_port.odp_port != ODPP_NONE) {
+        static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
+
+        VLOG_ERR_RL(&rl, "failed to put%s flow: in_port is not an exact match",
+                (put->flags & DPIF_FP_CREATE) ? "[create]"
+                : (put->flags & DPIF_FP_MODIFY) ? "[modify]" : "[zero]");
+        return EINVAL;
+    }
+
     if (put->ufid) {
         ufid = *put->ufid;
     } else {
diff --git a/tests/dpif-netdev.at b/tests/dpif-netdev.at
index 2862a3c..a6fb1c6 100644
--- a/tests/dpif-netdev.at
+++ b/tests/dpif-netdev.at
@@ -146,7 +146,7 @@  recirc_id(0),in_port(1),packet_type(ns=0,id=0),eth(src=50:54:00:00:00:09,dst=50:
 ])
 
    # Now, the same again without megaflows.
-   AT_CHECK([ovs-appctl upcall/disable-megaflows], [0], [megaflows disabled
+   AT_CHECK([ovs-appctl upcall/disable-megaflowsx], [0], [megaflows disabled
 ])
    AT_CHECK([ovs-appctl netdev-dummy/receive p1 'in_port(1),packet_type(ns=0,id=0),eth(src=50:54:00:00:00:09,dst=50:54:00:00:00:0a),eth_type(0x0800),ipv4(src=10.0.0.2,dst=10.0.0.1,proto=1,tos=0,ttl=64,frag=no),icmp(type=8,code=0)'])
 
@@ -589,3 +589,25 @@  arp,in_port=ANY,dl_vlan=11,dl_vlan_pcp=7,vlan_tci1=0x0000,dl_src=00:06:07:08:09:
 
 DPIF_NETDEV_FLOW_HW_OFFLOAD_OFFSETS_VID_ARP([dummy])
 DPIF_NETDEV_FLOW_HW_OFFLOAD_OFFSETS_VID_ARP([dummy-pmd])
+
+m4_define([DPIF_NETDEV_CHECK_IN_PORT_EXACT_MATCH],
+  [AT_SETUP([dpif-netdev - check dpctl/add-flow in_port exact match - $1])
+   OVS_VSWITCHD_START(
+     [add-port br0 p1 \
+      -- set interface p1 type=$1 options:pstream=punix:$OVS_RUNDIR/p0.sock \
+      -- set bridge br0 datapath-type=dummy \
+                        other-config:datapath-id=1234 fail-mode=secure], [], [],
+      [m4_if([$1], [dummy-pmd], [--dummy-numa="0,0,0,0,1,1,1,1"], [])])
+
+   AT_CHECK([ovs-appctl dpctl/add-flow "eth(),eth_type(0x0800),ipv4()" "3"], [2], [],
+     [ovs-vswitchd: updating flow table (Invalid argument)
+ovs-appctl: ovs-vswitchd: server returned an error
+])
+   OVS_WAIT_UNTIL([grep "flow: in_port is not an exact match" ovs-vswitchd.log])
+
+   AT_CHECK([grep 'flow: in_port is not an exact match' ovs-vswitchd.log],[0], [ignore], [ignore])
+   OVS_VSWITCHD_STOP(["/flow: in_port is not an exact match/d
+/failed to put/d"])
+   AT_CLEANUP])
+
+DPIF_NETDEV_CHECK_IN_PORT_EXACT_MATCH([dummy-pmd])