From patchwork Fri Apr 14 01:31:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarno Rajahalme X-Patchwork-Id: 750689 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3w40Vg1C9Dz9sNb for ; Fri, 14 Apr 2017 11:31:23 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id E1D11BE0; Fri, 14 Apr 2017 01:31:20 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id CC1BCBD6 for ; Fri, 14 Apr 2017 01:31:19 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id B8050140 for ; Fri, 14 Apr 2017 01:31:18 +0000 (UTC) Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by relay8-d.mail.gandi.net (Postfix) with ESMTPS id 6B7CC406C3; Fri, 14 Apr 2017 03:31:17 +0200 (CEST) Received: from mfilter14-d.gandi.net (mfilter14-d.gandi.net [217.70.178.142]) by relay5-d.mail.gandi.net (Postfix) with ESMTP id 5A29841C07D; Fri, 14 Apr 2017 03:31:17 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mfilter14-d.gandi.net Received: from relay5-d.mail.gandi.net ([IPv6:::ffff:217.70.183.197]) by mfilter14-d.gandi.net (mfilter14-d.gandi.net [::ffff:10.0.15.180]) (amavisd-new, port 10024) with ESMTP id 2SLHq06_MFkO; Fri, 14 Apr 2017 03:31:16 +0200 (CEST) X-Originating-IP: 208.91.1.34 Received: from sc9-mailhost1.vmware.com (unknown [208.91.1.34]) (Authenticated sender: jarno@ovn.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 34C3F41C074; Fri, 14 Apr 2017 03:31:14 +0200 (CEST) From: Jarno Rajahalme To: dev@openvswitch.org Date: Thu, 13 Apr 2017 18:31:06 -0700 Message-Id: <1492133466-38862-1-git-send-email-jarno@ovn.org> X-Mailer: git-send-email 2.1.4 X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH] ofp-parse: Fix match parsing with [x..y]=z format. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org Commit 21b2fa617126 ("ofp-parse: Allow match field names in actions and brackets in matches.") added support for matching a consecutive set of bits with the [x..y]=z format, but the copying of the parsed value ('z') to the match was done from a wrong offset, so that the actual value matched would be incorrect. Fix this and add a test case preventing regression in future. Fixes: 21b2fa617126 ("ofp-parse: Allow match field names in actions and brackets in matches.") Signed-off-by: Jarno Rajahalme Acked-by: Ben Pfaff --- lib/ofp-parse.c | 6 +++--- tests/ovs-ofctl.at | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/ofp-parse.c b/lib/ofp-parse.c index 7826bc5..c8cac5b 100644 --- a/lib/ofp-parse.c +++ b/lib/ofp-parse.c @@ -290,11 +290,11 @@ parse_subfield(const char *name, const char *str_value, struct match *match, const struct mf_field *field = sf.field; union mf_value value, mask; - unsigned int size = DIV_ROUND_UP(sf.n_bits, 8); + unsigned int size = field->n_bytes; mf_get(field, match, &value, &mask); - bitwise_copy(&val, size, 0, &value, field->n_bytes, sf.ofs, sf.n_bits); - bitwise_one ( &mask, field->n_bytes, sf.ofs, sf.n_bits); + bitwise_copy(&val, size, 0, &value, size, sf.ofs, sf.n_bits); + bitwise_one ( &mask, size, sf.ofs, sf.n_bits); *usable_protocols &= mf_set(field, &value, &mask, match, &error); } return error; diff --git a/tests/ovs-ofctl.at b/tests/ovs-ofctl.at index 737f609..18ab788 100644 --- a/tests/ovs-ofctl.at +++ b/tests/ovs-ofctl.at @@ -285,6 +285,7 @@ AT_CLEANUP AT_SETUP([ovs-ofctl parse-flows (OpenFlow 1.2)]) AT_DATA([flows.txt], [[ # comment +tcp,tp_src[5]=1,actions=flood tcp,tp_src=123,actions=flood in_port=LOCAL dl_vlan=9 dl_src=00:0A:E4:25:6B:B0 actions=mod_vlan_vid:7,mod_vlan_pcp:2 udp dl_vlan_pcp=7 idle_timeout=5 actions=strip_vlan output:0 @@ -309,6 +310,7 @@ AT_CHECK([ovs-ofctl --protocols OpenFlow12 parse-flows flows.txt AT_CHECK([[sed 's/ (xid=0x[0-9a-fA-F]*)//' stdout]], [0], [[usable protocols: NXM,OXM chosen protocol: OXM-OpenFlow12 +OFPT_FLOW_MOD (OF1.2): ADD tcp,tp_src=0x20/0x20 actions=FLOOD OFPT_FLOW_MOD (OF1.2): ADD tcp,tp_src=123 actions=FLOOD OFPT_FLOW_MOD (OF1.2): ADD in_port=LOCAL,dl_vlan=9,dl_src=00:0a:e4:25:6b:b0 actions=set_field:4103->vlan_vid,set_field:2->vlan_pcp OFPT_FLOW_MOD (OF1.2): ADD udp,dl_vlan_pcp=7 idle:5 actions=pop_vlan,output:0