[ovs-dev] [PATCH 03/10] actions: Make "arp { drop; }; " acceptable.

Ben Pfaff blp at ovn.org
Fri Jan 20 17:16:25 UTC 2017


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 <blp at ovn.org>
---
 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);
-- 
2.10.2



More information about the dev mailing list