[ovs-dev] [PATCH 4/5] ofp-util: Add OFPUTIL_ACTION_INVALID to enum ofputil_action_code.

Ben Pfaff blp at nicira.com
Sat Jun 9 15:57:29 UTC 2012


Possibly the ofputil_decode_action() interface should be rethought now
that ofputil_action_code has an invalid value.

Signed-off-by: Ben Pfaff <blp at nicira.com>
---
 lib/ofp-parse.c        |    3 +++
 lib/ofp-print.c        |    3 +++
 lib/ofp-util.c         |    7 +++++++
 lib/ofp-util.h         |    3 ++-
 ofproto/ofproto-dpif.c |    3 +++
 5 files changed, 18 insertions(+), 1 deletions(-)

diff --git a/lib/ofp-parse.c b/lib/ofp-parse.c
index 73a70c6..1d331bb 100644
--- a/lib/ofp-parse.c
+++ b/lib/ofp-parse.c
@@ -323,6 +323,9 @@ parse_named_action(enum ofputil_action_code code, const struct flow *flow,
     struct ofp_action_tp_port *oata;
 
     switch (code) {
+    case OFPUTIL_ACTION_INVALID:
+        NOT_REACHED();
+
     case OFPUTIL_OFPAT10_OUTPUT:
         parse_output(b, arg);
         break;
diff --git a/lib/ofp-print.c b/lib/ofp-print.c
index 9d4396c..ef5d41f 100644
--- a/lib/ofp-print.c
+++ b/lib/ofp-print.c
@@ -183,6 +183,9 @@ ofp_print_action(struct ds *s, const union ofp_action *a,
     uint16_t port;
 
     switch (code) {
+    case OFPUTIL_ACTION_INVALID:
+        NOT_REACHED();
+
     case OFPUTIL_OFPAT10_OUTPUT:
         port = ntohs(a->output.port);
         if (port < OFPP_MAX) {
diff --git a/lib/ofp-util.c b/lib/ofp-util.c
index 79a879f..c2b9545 100644
--- a/lib/ofp-util.c
+++ b/lib/ofp-util.c
@@ -3430,6 +3430,9 @@ validate_actions(const union ofp_action *actions, size_t n_actions,
 
         error = 0;
         switch ((enum ofputil_action_code) code) {
+        case OFPUTIL_ACTION_INVALID:
+            NOT_REACHED();
+
         case OFPUTIL_OFPAT10_OUTPUT:
             error = ofputil_check_output_port(ntohs(a->output.port),
                                               max_ports);
@@ -3660,6 +3663,7 @@ int
 ofputil_action_code_from_name(const char *name)
 {
     static const char *names[OFPUTIL_N_ACTIONS] = {
+        NULL,
 #define OFPAT10_ACTION(ENUM, STRUCT, NAME)             NAME,
 #define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) NAME,
 #include "ofp-util.def"
@@ -3684,6 +3688,9 @@ void *
 ofputil_put_action(enum ofputil_action_code code, struct ofpbuf *buf)
 {
     switch (code) {
+    case OFPUTIL_ACTION_INVALID:
+        NOT_REACHED();
+
 #define OFPAT10_ACTION(ENUM, STRUCT, NAME)                    \
     case OFPUTIL_##ENUM: return ofputil_put_##ENUM(buf);
 #define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME)        \
diff --git a/lib/ofp-util.h b/lib/ofp-util.h
index bdde8f1..2abc0ca 100644
--- a/lib/ofp-util.h
+++ b/lib/ofp-util.h
@@ -589,6 +589,7 @@ bool ofputil_frag_handling_from_string(const char *, enum ofp_config_flags *);
  * (The above list helps developers who want to "grep" for these definitions.)
  */
 enum ofputil_action_code {
+    OFPUTIL_ACTION_INVALID,
 #define OFPAT10_ACTION(ENUM, STRUCT, NAME)             OFPUTIL_##ENUM,
 #define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) OFPUTIL_##ENUM,
 #include "ofp-util.def"
@@ -598,7 +599,7 @@ enum ofputil_action_code {
 enum {
 #define OFPAT10_ACTION(ENUM, STRUCT, NAME)             + 1
 #define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) + 1
-    OFPUTIL_N_ACTIONS = 0
+    OFPUTIL_N_ACTIONS = 1
 #include "ofp-util.def"
 };
 
diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c
index 962df15..5dcb3f0 100644
--- a/ofproto/ofproto-dpif.c
+++ b/ofproto/ofproto-dpif.c
@@ -5361,6 +5361,9 @@ do_xlate_actions(const union ofp_action *in, size_t n_in,
 
         code = ofputil_decode_action_unsafe(ia);
         switch (code) {
+        case OFPUTIL_ACTION_INVALID:
+            NOT_REACHED();
+
         case OFPUTIL_OFPAT10_OUTPUT:
             xlate_output_action(ctx, &ia->output);
             break;
-- 
1.7.2.5




More information about the dev mailing list