ofproto-dpif-xlate: New helper function ctx_cancel_recirculation().
[cascardo/ovs.git] / ofproto / ofproto-dpif-xlate.c
index 1edc1b0..aa10217 100644 (file)
@@ -368,6 +368,16 @@ exit_recirculates(const struct xlate_ctx *ctx)
     return ctx->recirc_action_offset >= 0;
 }
 
+static void
+ctx_cancel_recirculation(struct xlate_ctx *ctx)
+{
+    if (exit_recirculates(ctx)) {
+        ctx->action_set.size = ctx->recirc_action_offset;
+        ctx->recirc_action_offset = -1;
+        ctx->last_unroll_offset = -1;
+    }
+}
+
 static void compose_recirculate_action(struct xlate_ctx *ctx);
 
 /* A controller may use OFPP_NONE as the ingress port to indicate that
@@ -457,11 +467,11 @@ struct xc_entry {
     } u;
 };
 
-#define XC_ENTRY_FOR_EACH(entry, entries, xcache)               \
-    entries = xcache->entries;                                  \
-    for (entry = ofpbuf_try_pull(&entries, sizeof *entry);      \
-         entry;                                                 \
-         entry = ofpbuf_try_pull(&entries, sizeof *entry))
+#define XC_ENTRY_FOR_EACH(ENTRY, ENTRIES, XCACHE)               \
+    ENTRIES = XCACHE->entries;                                  \
+    for (ENTRY = ofpbuf_try_pull(&ENTRIES, sizeof *ENTRY);      \
+         ENTRY;                                                 \
+         ENTRY = ofpbuf_try_pull(&ENTRIES, sizeof *ENTRY))
 
 struct xlate_cache {
     struct ofpbuf entries;
@@ -3009,11 +3019,7 @@ compose_output_action__(struct xlate_ctx *ctx, ofp_port_t ofp_port,
                 ctx->odp_actions->size = old_size;
 
                 /* Undo changes that may have been done for recirculation. */
-                if (exit_recirculates(ctx)) {
-                    ctx->action_set.size = ctx->recirc_action_offset;
-                    ctx->recirc_action_offset = -1;
-                    ctx->last_unroll_offset = -1;
-                }
+                ctx_cancel_recirculation(ctx);
             }
         }
 
@@ -3668,9 +3674,7 @@ compose_recirculate_action__(struct xlate_ctx *ctx, uint8_t table)
     nl_msg_put_u32(ctx->odp_actions, OVS_ACTION_ATTR_RECIRC, id);
 
     /* Undo changes done by recirculation. */
-    ctx->action_set.size = ctx->recirc_action_offset;
-    ctx->recirc_action_offset = -1;
-    ctx->last_unroll_offset = -1;
+    ctx_cancel_recirculation(ctx);
 }
 
 /* Called only when ctx->recirc_action_offset is set. */
@@ -4163,16 +4167,14 @@ recirc_put_unroll_xlate(struct xlate_ctx *ctx)
 }
 
 
-/* Copy remaining actions to the action_set to be executed after recirculation.
- * UNROLL_XLATE action is inserted, if not already done so, before actions that
- * may depend on the current table ID or flow cookie. */
+/* Copy actions 'a' through 'end' to the action_set to be executed after
+ * recirculation.  UNROLL_XLATE action is inserted, if not already done so,
+ * before actions that may depend on the current table ID or flow cookie. */
 static void
-recirc_unroll_actions(const struct ofpact *ofpacts, size_t ofpacts_len,
+recirc_unroll_actions(const struct ofpact *a, const struct ofpact *end,
                       struct xlate_ctx *ctx)
 {
-    const struct ofpact *a;
-
-    OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) {
+    for (; a < end; a = ofpact_next(a)) {
         switch (a->type) {
         case OFPACT_OUTPUT_REG:
         case OFPACT_GROUP:
@@ -4439,9 +4441,7 @@ do_xlate_actions(const struct ofpact *ofpacts, size_t ofpacts_len,
             /* Check if need to store the remaining actions for later
              * execution. */
             if (exit_recirculates(ctx)) {
-                recirc_unroll_actions(a, OFPACT_ALIGN(ofpacts_len -
-                                                      ((uint8_t *)a -
-                                                       (uint8_t *)ofpacts)),
+                recirc_unroll_actions(a, ofpact_end(ofpacts, ofpacts_len),
                                       ctx);
             }
             break;
@@ -4817,10 +4817,7 @@ do_xlate_actions(const struct ofpact *ofpacts, size_t ofpacts_len,
         /* Check if need to store this and the remaining actions for later
          * execution. */
         if (!ctx->error && ctx->exit && ctx_first_recirculation_action(ctx)) {
-            recirc_unroll_actions(a, OFPACT_ALIGN(ofpacts_len -
-                                                  ((uint8_t *)a -
-                                                   (uint8_t *)ofpacts)),
-                                  ctx);
+            recirc_unroll_actions(a, ofpact_end(ofpacts, ofpacts_len), ctx);
             break;
         }
     }
@@ -5349,11 +5346,7 @@ xlate_actions(struct xlate_in *xin, struct xlate_out *xout)
                 ctx.odp_actions->size = sample_actions_len;
 
                 /* Undo changes that may have been done for recirculation. */
-                if (exit_recirculates(&ctx)) {
-                    ctx.action_set.size = ctx.recirc_action_offset;
-                    ctx.recirc_action_offset = -1;
-                    ctx.last_unroll_offset = -1;
-                }
+                ctx_cancel_recirculation(&ctx);
             } else if (ctx.action_set.size) {
                 /* Translate action set only if not dropping the packet and
                  * not recirculating. */