From patchwork Wed Dec 6 10:58:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zoltan Balogh X-Patchwork-Id: 845127 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) 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 3ysFvv6lmlz9s84 for ; Wed, 6 Dec 2017 21:58:19 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 3967ED8C; Wed, 6 Dec 2017 10:58:18 +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 DAF7CD67 for ; Wed, 6 Dec 2017 10:58:16 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from sesbmg22.ericsson.net (sesbmg22.ericsson.net [193.180.251.48]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id E4ACE40D for ; Wed, 6 Dec 2017 10:58:15 +0000 (UTC) X-AuditID: c1b4fb30-ca9ff700000029e3-e3-5a27cd452362 Received: from ESESSHC012.ericsson.se (Unknown_Domain [153.88.183.54]) by sesbmg22.ericsson.net (Symantec Mail Security) with SMTP id BA.38.10723.54DC72A5; Wed, 6 Dec 2017 11:58:14 +0100 (CET) Received: from labserv2.eth.ericsson.se (153.88.183.153) by smtp.internal.ericsson.com (153.88.183.56) with Microsoft SMTP Server id 14.3.352.0; Wed, 6 Dec 2017 11:58:13 +0100 Received: from gep5.sdn.hu.eld.ericsson.se (unknown [172.31.40.105]) by labserv2.eth.ericsson.se (Postfix) with ESMTP id 90D9529C72C; Wed, 6 Dec 2017 11:51:40 +0100 (CET) From: Zoltan Balogh To: Date: Wed, 6 Dec 2017 11:58:10 +0100 Message-ID: <1512557890-31128-1-git-send-email-zoltan.balogh@ericsson.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprNLMWRmVeSWpSXmKPExsUyM2K7ma7bWfUog+MXOSxeTW5gtDh6eg+z xdOLv5gdmD0W73nJ5PHs5n9Gj+fXelgCmKO4bFJSczLLUov07RK4MqZP+MhYMFe9YuqXD8wN jG/luhg5OSQETCQ2tD9h7GLk4hASOMwocWTPLHYIZzOjxLQLt6Cc9YwSxx4sZwVpYRMwkPhx +QsTiC0iICnxb/EWti5GDg5mgTKJ69vBwsICbhLzrl8Bs1kEVCQaPt1jAbF5BbwkXp39xgix WU7i5LHJrBBxQYmTM5+A1TALSEgcfPGCGcQWElCXONTymm0CI98sJGWzkJQtYGRaxShanFqc lJtuZKSXWpSZXFycn6eXl1qyiREYZAe3/DbYwfjyueMhRgEORiUe3odH1KOEWBPLiitzDzFK cDArifAKHAQK8aYkVlalFuXHF5XmpBYfYpTmYFES5z3pyRslJJCeWJKanZpakFoEk2Xi4JRq YMys0eGKUJwupviy+614iEWv6OzOzNlcT+rrjE7cL/Hm9RGt9d61zfLxcj9erYWK10Oeih4R tPVM+6iklv3iV6ohZ8T2p9L/A75/WPSxSsvwrUb0Odks3YkH5m2pExC4qlb0SZ2va0c1/9GN Xd2FET/vz9ybtfflz5D12hk6jX16ORuUjS2uKbEUZyQaajEXFScCAIBwh7suAgAA X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED 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 v2 2/2] xlate: normalize the actions after translation 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: , Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org When all OF actions have been translated, there could be actions at the end of list of odp actions which are not needed to be executed. So, the list can be normalized at the end of xlate_actions(). Signed-off-by: Zoltan Balogh Signed-off-by: Sugesh Chandran Co-authored-by: Sugesh Chandran CC: Ben Pfaff --- ofproto/ofproto-dpif-xlate.c | 67 ++++++++++++++++++++++++++++++++++++++++++++ tests/ofproto-dpif.at | 48 +++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+) diff --git a/ofproto/ofproto-dpif-xlate.c b/ofproto/ofproto-dpif-xlate.c index 36d0a0e1f..2af1ec1e8 100644 --- a/ofproto/ofproto-dpif-xlate.c +++ b/ofproto/ofproto-dpif-xlate.c @@ -6954,6 +6954,70 @@ xlate_wc_finish(struct xlate_ctx *ctx) } } +/* Returns true if the action stored in 'nla' can be a valid last action of a + * datapath flow. */ +static bool +is_valid_last_action(const struct nlattr *nla) +{ + enum ovs_action_attr action_type = nl_attr_type(nla); + + switch (action_type) { + case OVS_ACTION_ATTR_USERSPACE: + case OVS_ACTION_ATTR_SAMPLE: + case OVS_ACTION_ATTR_TRUNC: + case OVS_ACTION_ATTR_RECIRC: + case OVS_ACTION_ATTR_TUNNEL_PUSH: + case OVS_ACTION_ATTR_TUNNEL_POP: + case OVS_ACTION_ATTR_OUTPUT: + case OVS_ACTION_ATTR_CLONE: + case OVS_ACTION_ATTR_CT: + return true; + case OVS_ACTION_ATTR_UNSPEC: + case OVS_ACTION_ATTR_SET: + case OVS_ACTION_ATTR_PUSH_VLAN: + case OVS_ACTION_ATTR_POP_VLAN: + case OVS_ACTION_ATTR_HASH: + case OVS_ACTION_ATTR_PUSH_MPLS: + case OVS_ACTION_ATTR_POP_MPLS: + case OVS_ACTION_ATTR_SET_MASKED: + case OVS_ACTION_ATTR_PUSH_ETH: + case OVS_ACTION_ATTR_POP_ETH: + case OVS_ACTION_ATTR_METER: + case OVS_ACTION_ATTR_ENCAP_NSH: + case OVS_ACTION_ATTR_DECAP_NSH: + case __OVS_ACTION_ATTR_MAX: + default: + return false; + } +} + +/* Returns offset of last netlink attribute storing valid action in array + * 'data'. Execution of actions beyond this last attribute does not make sense. + */ +static size_t +last_action_offset(const struct nlattr *data, const size_t data_len) +{ + const struct nlattr *last = data; + + uint16_t left; + const struct nlattr *a; + NL_ATTR_FOR_EACH (a, left, data, data_len) { + if (is_valid_last_action(a)) { + last = nl_attr_next(a); + } + } + + return (char *) last - (char *) data; +} + +/* Get rid of any unneeded actions at the tail end. */ +static void +normalize_odp_actions(struct xlate_ctx *ctx) +{ + struct ofpbuf *oa = ctx->odp_actions; + oa->size = last_action_offset(oa->data, oa->size); +} + /* Translates the flow, actions, or rule in 'xin' into datapath actions in * 'xout'. * The caller must take responsibility for eventually freeing 'xout', with @@ -7364,7 +7428,10 @@ exit: if (xin->odp_actions) { ofpbuf_clear(xin->odp_actions); } + } else { + normalize_odp_actions(&ctx); } + return ctx.error; } diff --git a/tests/ofproto-dpif.at b/tests/ofproto-dpif.at index e7df1504a..5bcd8bb46 100644 --- a/tests/ofproto-dpif.at +++ b/tests/ofproto-dpif.at @@ -10133,3 +10133,51 @@ AT_CHECK([grep "Datapath actions" stdout], [0], OVS_VSWITCHD_STOP AT_CLEANUP + +AT_SETUP([ofproto-dpif - xlate error - normalize actions]) + +# ->-+ +# | p1 +# +-o-------+ +# | br0 | +# +-o-----o-+ +# patch0| |patch1 +# +-->--+ + +OVS_VSWITCHD_START([dnl + -- add-port br0 patch0 \ + -- set interface patch0 type=patch options:peer=patch1 ofport_request=10 \ + -- add-port br0 patch1 \ + -- set interface patch1 type=patch options:peer=patch0 ofport_request=20 +]) + +AT_CHECK([ + ovs-vsctl add-port br0 p1 -- set interface p1 type=dummy ofport_request=1 +]) + +AT_CHECK([ + ovs-appctl dpif/show | grep -v hit | sed "s/$(printf \\t)/ /g" | sed 's./[[0-9]]\{1,\}..' +], [0], [dnl + br0: + br0 65534: (dummy-internal) + p1 1: (dummy) + patch0 10/none: (patch: peer=patch1) + patch1 20/none: (patch: peer=patch0) +]) + +# Error due to pushing too many MPLS labels. +AT_CHECK([ + ovs-ofctl del-flows br0 + ovs-ofctl add-flow br0 "table=0,in_port=1,actions=mod_dl_src:aa:aa:aa:bb:bb:00,goto_table:1" -OOpenFlow13 + ovs-ofctl add-flow br0 "table=0,in_port=patch1,actions=goto_table:2" -OOpenFlow13 + ovs-ofctl add-flow br0 "table=1,actions=push_vlan:0x8100,set_field:4196->vlan_vid,output:patch0" -OOpenFlow13 + ovs-ofctl add-flow br0 "table=2,actions=push_mpls:0x8847,output:patch0" +], [0]) + +AT_CHECK([ovs-appctl ofproto/trace br0 'in_port=1,ip'], [0], [stdout]) +AT_CHECK([tail -1 stdout], [0], + [Datapath actions: drop +]) + +OVS_VSWITCHD_STOP +AT_CLEANUP