From patchwork Fri Jan 20 17:16:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Pfaff X-Patchwork-Id: 717828 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 3v4nTM2BVRz9sCg for ; Sat, 21 Jan 2017 04:17:43 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id B44E6B93; Fri, 20 Jan 2017 17:16:48 +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 1722AB4C for ; Fri, 20 Jan 2017 17:16:46 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 9738F8E for ; Fri, 20 Jan 2017 17:16:45 +0000 (UTC) Received: from mfilter6-d.gandi.net (mfilter6-d.gandi.net [217.70.178.135]) by relay2-d.mail.gandi.net (Postfix) with ESMTP id 6A177C5A56; Fri, 20 Jan 2017 18:16:44 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mfilter6-d.gandi.net Received: from relay2-d.mail.gandi.net ([IPv6:::ffff:217.70.183.194]) by mfilter6-d.gandi.net (mfilter6-d.gandi.net [::ffff:10.0.15.180]) (amavisd-new, port 10024) with ESMTP id 48fJ2hMMExrv; Fri, 20 Jan 2017 18:16:42 +0100 (CET) X-Originating-IP: 173.228.112.82 Received: from sigabrt.gateway.sonic.net (173-228-112-82.dsl.dynamic.fusionbroadband.com [173.228.112.82]) (Authenticated sender: blp@ovn.org) by relay2-d.mail.gandi.net (Postfix) with ESMTPSA id 2147BC5A49; Fri, 20 Jan 2017 18:16:41 +0100 (CET) From: Ben Pfaff To: dev@openvswitch.org Date: Fri, 20 Jan 2017 09:16:25 -0800 Message-Id: <20170120171632.29991-4-blp@ovn.org> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20170120171632.29991-1-blp@ovn.org> References: <20170120171632.29991-1-blp@ovn.org> 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 Cc: Ben Pfaff Subject: [ovs-dev] [PATCH 03/10] actions: Make "arp { drop; }; " acceptable. 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 Before this commit, the OVN action parser would accept "arp {};" and then the formatter would format it back as "arp { drop; };", but the parser didn't accept the latter. There were basically two choices: make the parser accept "arp { drop; };" or make the formatter output "arp {};" (or both). This patch does (only) the former, and adds a test to avoid regression. Signed-off-by: Ben Pfaff --- ovn/lib/actions.c | 16 ++++++---------- tests/ovn.at | 4 ++++ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ovn/lib/actions.c b/ovn/lib/actions.c index 5770488..f1faab3 100644 --- a/ovn/lib/actions.c +++ b/ovn/lib/actions.c @@ -179,7 +179,7 @@ struct action_context { struct expr *prereqs; /* Prerequisites to apply to match. */ }; -static bool parse_action(struct action_context *); +static void parse_actions(struct action_context *, enum lex_type sentinel); static bool action_parse_field(struct action_context *ctx, @@ -1040,11 +1040,7 @@ parse_nested_action(struct action_context *ctx, enum ovnact_type type, .ovnacts = &nested, .prereqs = NULL }; - while (!lexer_match(ctx->lexer, LEX_T_RCURLY)) { - if (!parse_action(&inner_ctx)) { - break; - } - } + parse_actions(&inner_ctx, LEX_T_RCURLY); /* XXX Not really sure what we should do with prerequisites for nested * actions. */ @@ -1743,7 +1739,7 @@ parse_action(struct action_context *ctx) } static void -parse_actions(struct action_context *ctx) +parse_actions(struct action_context *ctx, enum lex_type sentinel) { /* "drop;" by itself is a valid (empty) set of actions, but it can't be * combined with other actions because that doesn't make sense. */ @@ -1752,11 +1748,11 @@ parse_actions(struct action_context *ctx) && lexer_lookahead(ctx->lexer) == LEX_T_SEMICOLON) { lexer_get(ctx->lexer); /* Skip "drop". */ lexer_get(ctx->lexer); /* Skip ";". */ - lexer_force_end(ctx->lexer); + lexer_force_match(ctx->lexer, sentinel); return; } - while (ctx->lexer->token.type != LEX_T_END) { + while (!lexer_match(ctx->lexer, sentinel)) { if (!parse_action(ctx)) { return; } @@ -1791,7 +1787,7 @@ ovnacts_parse(struct lexer *lexer, const struct ovnact_parse_params *pp, .prereqs = NULL, }; if (!lexer->error) { - parse_actions(&ctx); + parse_actions(&ctx, LEX_T_END); } if (!lexer->error) { diff --git a/tests/ovn.at b/tests/ovn.at index bc915c6..a514ebbd 100644 --- a/tests/ovn.at +++ b/tests/ovn.at @@ -871,6 +871,10 @@ ct_snat(); arp { eth.dst = ff:ff:ff:ff:ff:ff; output; }; output; encodes as controller(userdata=00.00.00.00.00.00.00.00.00.19.00.10.80.00.06.06.ff.ff.ff.ff.ff.ff.00.00.ff.ff.00.10.00.00.23.20.00.0e.ff.f8.40.00.00.00),resubmit(,64) has prereqs ip4 +arp { }; + formats as arp { drop; }; + encodes as controller(userdata=00.00.00.00.00.00.00.00) + has prereqs ip4 # get_arp get_arp(outport, ip4.dst);