[ovs-dev] [PATCH 12/41] ofp-actions: Append in ofpacts_pull_openflow_actions(), instead of replace.

Ben Pfaff blp at ovn.org
Tue Jan 19 07:26:59 UTC 2016


An upcoming commit will have a need to parse actions incrementally, so this
change makes that easier to do.

Signed-off-by: Ben Pfaff <blp at ovn.org>
---
 lib/ofp-actions.c | 20 ++++++++------------
 lib/ofp-util.c    |  2 ++
 2 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/lib/ofp-actions.c b/lib/ofp-actions.c
index becf02d..ff3bc12 100644
--- a/lib/ofp-actions.c
+++ b/lib/ofp-actions.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Nicira, Inc.
+ * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -5631,12 +5631,9 @@ ofpacts_pull_openflow_actions__(struct ofpbuf *openflow,
                                 enum ofpact_type outer_action)
 {
     const struct ofp_action_header *actions;
+    size_t orig_size = ofpacts->size;
     enum ofperr error;
 
-    if (!outer_action) {
-        ofpbuf_clear(ofpacts);
-    }
-
     if (actions_len % OFP_ACTION_ALIGN != 0) {
         VLOG_WARN_RL(&rl, "OpenFlow message actions length %u is not a "
                      "multiple of %d", actions_len, OFP_ACTION_ALIGN);
@@ -5653,21 +5650,21 @@ ofpacts_pull_openflow_actions__(struct ofpbuf *openflow,
 
     error = ofpacts_decode(actions, actions_len, version, ofpacts);
     if (error) {
-        ofpbuf_clear(ofpacts);
+        ofpacts->size = orig_size;
         return error;
     }
 
     error = ofpacts_verify(ofpacts->data, ofpacts->size, allowed_ovsinsts,
                            outer_action);
     if (error) {
-        ofpbuf_clear(ofpacts);
+        ofpacts->size = orig_size;
     }
     return error;
 }
 
-/* Attempts to convert 'actions_len' bytes of OpenFlow actions from the
- * front of 'openflow' into ofpacts.  On success, replaces any existing content
- * in 'ofpacts' by the converted ofpacts; on failure, clears 'ofpacts'.
+/* Attempts to convert 'actions_len' bytes of OpenFlow actions from the front
+ * of 'openflow' into ofpacts.  On success, appends the converted actions to
+ * 'ofpacts'; on failure, 'ofpacts' is unchanged (but might be reallocated) .
  * Returns 0 if successful, otherwise an OpenFlow error.
  *
  * Actions are processed according to their OpenFlow version which
@@ -6229,6 +6226,7 @@ ofpacts_pull_openflow_instructions(struct ofpbuf *openflow,
     const struct ofp11_instruction *insts[N_OVS_INSTRUCTIONS];
     enum ofperr error;
 
+    ofpbuf_clear(ofpacts);
     if (version == OFP10_VERSION) {
         return ofpacts_pull_openflow_actions__(openflow, instructions_len,
                                                version,
@@ -6236,8 +6234,6 @@ ofpacts_pull_openflow_instructions(struct ofpbuf *openflow,
                                                ofpacts, 0);
     }
 
-    ofpbuf_clear(ofpacts);
-
     if (instructions_len % OFP11_INSTRUCTION_ALIGN != 0) {
         VLOG_WARN_RL(&rl, "OpenFlow message instructions length %u is not a "
                      "multiple of %d",
diff --git a/lib/ofp-util.c b/lib/ofp-util.c
index c1cbcea..58f7e23 100644
--- a/lib/ofp-util.c
+++ b/lib/ofp-util.c
@@ -3672,6 +3672,7 @@ ofputil_decode_packet_out(struct ofputil_packet_out *po,
     ofpbuf_use_const(&b, oh, ntohs(oh->length));
     raw = ofpraw_pull_assert(&b);
 
+    ofpbuf_clear(ofpacts);
     if (raw == OFPRAW_OFPT11_PACKET_OUT) {
         enum ofperr error;
         const struct ofp11_packet_out *opo = ofpbuf_pull(&b, sizeof *opo);
@@ -6265,6 +6266,7 @@ ofputil_decode_flow_update(struct ofputil_flow_update *update,
         ofpraw_pull_assert(msg);
     }
 
+    ofpbuf_clear(ofpacts);
     if (!msg->size) {
         return EOF;
     }
-- 
2.1.3




More information about the dev mailing list