Allow OFPACT_SET_IP_DSCP to act on both IPv4 and IPv6 packets.
This removes semantic differences between different OpenFlow
versions, making it easier to translate between them.

Signed-off-by: Jarno Rajahalme <jrajaha...@nicira.com>
---
 lib/ofp-actions.c            |   28 ++++++++++++++--------------
 lib/ofp-actions.h            |    4 ++--
 lib/ofp-parse.c              |    2 +-
 ofproto/ofproto-dpif-xlate.c |    7 +++----
 utilities/ovs-ofctl.8.in     |    6 +++---
 5 files changed, 23 insertions(+), 24 deletions(-)

diff --git a/lib/ofp-actions.c b/lib/ofp-actions.c
index f02ba4d..75c32d8 100644
--- a/lib/ofp-actions.c
+++ b/lib/ofp-actions.c
@@ -554,7 +554,7 @@ ofpact_from_openflow10(const union ofp_action *a, struct 
ofpbuf *out)
         if (a->nw_tos.nw_tos & ~IP_DSCP_MASK) {
             return OFPERR_OFPBAC_BAD_ARGUMENT;
         }
-        ofpact_put_SET_IPV4_DSCP(out)->dscp = a->nw_tos.nw_tos;
+        ofpact_put_SET_IP_DSCP(out)->dscp = a->nw_tos.nw_tos;
         break;
 
     case OFPUTIL_OFPAT10_SET_TP_SRC:
@@ -843,7 +843,7 @@ ofpact_from_openflow11(const union ofp_action *a, struct 
ofpbuf *out)
         if (a->nw_tos.nw_tos & ~IP_DSCP_MASK) {
             return OFPERR_OFPBAC_BAD_ARGUMENT;
         }
-        ofpact_put_SET_IPV4_DSCP(out)->dscp = a->nw_tos.nw_tos;
+        ofpact_put_SET_IP_DSCP(out)->dscp = a->nw_tos.nw_tos;
         break;
 
     case OFPUTIL_OFPAT11_SET_TP_SRC:
@@ -906,7 +906,7 @@ ofpact_is_set_action(const struct ofpact *a)
     case OFPACT_REG_LOAD:
     case OFPACT_SET_ETH_DST:
     case OFPACT_SET_ETH_SRC:
-    case OFPACT_SET_IPV4_DSCP:
+    case OFPACT_SET_IP_DSCP:
     case OFPACT_SET_IPV4_DST:
     case OFPACT_SET_IPV4_SRC:
     case OFPACT_SET_L4_DST_PORT:
@@ -967,7 +967,7 @@ ofpact_is_allowed_in_actions_set(const struct ofpact *a)
     case OFPACT_REG_LOAD:
     case OFPACT_SET_ETH_DST:
     case OFPACT_SET_ETH_SRC:
-    case OFPACT_SET_IPV4_DSCP:
+    case OFPACT_SET_IP_DSCP:
     case OFPACT_SET_IPV4_DST:
     case OFPACT_SET_IPV4_SRC:
     case OFPACT_SET_L4_DST_PORT:
@@ -1237,7 +1237,7 @@ ovs_instruction_type_from_ofpact_type(enum ofpact_type 
type)
     case OFPACT_SET_ETH_DST:
     case OFPACT_SET_IPV4_SRC:
     case OFPACT_SET_IPV4_DST:
-    case OFPACT_SET_IPV4_DSCP:
+    case OFPACT_SET_IP_DSCP:
     case OFPACT_SET_L4_SRC_PORT:
     case OFPACT_SET_L4_DST_PORT:
     case OFPACT_REG_MOVE:
@@ -1571,7 +1571,6 @@ ofpact_check__(const struct ofpact *a, struct flow *flow, 
ofp_port_t max_ports,
 
     case OFPACT_SET_IPV4_SRC:
     case OFPACT_SET_IPV4_DST:
-    case OFPACT_SET_IPV4_DSCP:
         if (flow->dl_type != htons(ETH_TYPE_IP)) {
             goto inconsistent;
         }
@@ -1598,6 +1597,7 @@ ofpact_check__(const struct ofpact *a, struct flow *flow, 
ofp_port_t max_ports,
     case OFPACT_STACK_POP:
         return nxm_stack_pop_check(ofpact_get_STACK_POP(a), flow);
 
+    case OFPACT_SET_IP_DSCP:
     case OFPACT_DEC_TTL:
         if (!is_ip_any(flow)) {
             goto inconsistent;
@@ -1993,7 +1993,7 @@ ofpact_to_nxast(const struct ofpact *a, struct ofpbuf 
*out)
     case OFPACT_SET_ETH_DST:
     case OFPACT_SET_IPV4_SRC:
     case OFPACT_SET_IPV4_DST:
-    case OFPACT_SET_IPV4_DSCP:
+    case OFPACT_SET_IP_DSCP:
     case OFPACT_SET_L4_SRC_PORT:
     case OFPACT_SET_L4_DST_PORT:
     case OFPACT_WRITE_ACTIONS:
@@ -2074,9 +2074,9 @@ ofpact_to_openflow10(const struct ofpact *a, struct 
ofpbuf *out)
             = ofpact_get_SET_IPV4_DST(a)->ipv4;
         break;
 
-    case OFPACT_SET_IPV4_DSCP:
+    case OFPACT_SET_IP_DSCP:
         ofputil_put_OFPAT10_SET_NW_TOS(out)->nw_tos
-            = ofpact_get_SET_IPV4_DSCP(a)->dscp;
+            = ofpact_get_SET_IP_DSCP(a)->dscp;
         break;
 
     case OFPACT_SET_L4_SRC_PORT:
@@ -2224,9 +2224,9 @@ ofpact_to_openflow11(const struct ofpact *a, struct 
ofpbuf *out)
             = ofpact_get_SET_IPV4_DST(a)->ipv4;
         break;
 
-    case OFPACT_SET_IPV4_DSCP:
+    case OFPACT_SET_IP_DSCP:
         ofputil_put_OFPAT11_SET_NW_TOS(out)->nw_tos
-            = ofpact_get_SET_IPV4_DSCP(a)->dscp;
+            = ofpact_get_SET_IP_DSCP(a)->dscp;
         break;
 
     case OFPACT_SET_L4_SRC_PORT:
@@ -2432,7 +2432,7 @@ ofpact_outputs_to_port(const struct ofpact *ofpact, 
ofp_port_t port)
     case OFPACT_SET_ETH_DST:
     case OFPACT_SET_IPV4_SRC:
     case OFPACT_SET_IPV4_DST:
-    case OFPACT_SET_IPV4_DSCP:
+    case OFPACT_SET_IP_DSCP:
     case OFPACT_SET_L4_SRC_PORT:
     case OFPACT_SET_L4_DST_PORT:
     case OFPACT_REG_MOVE:
@@ -2690,8 +2690,8 @@ ofpact_format(const struct ofpact *a, struct ds *s)
                       IP_ARGS(ofpact_get_SET_IPV4_DST(a)->ipv4));
         break;
 
-    case OFPACT_SET_IPV4_DSCP:
-        ds_put_format(s, "mod_nw_tos:%d", ofpact_get_SET_IPV4_DSCP(a)->dscp);
+    case OFPACT_SET_IP_DSCP:
+        ds_put_format(s, "mod_nw_tos:%d", ofpact_get_SET_IP_DSCP(a)->dscp);
         break;
 
     case OFPACT_SET_L4_SRC_PORT:
diff --git a/lib/ofp-actions.h b/lib/ofp-actions.h
index 199acdf..e45521d 100644
--- a/lib/ofp-actions.h
+++ b/lib/ofp-actions.h
@@ -67,7 +67,7 @@
     DEFINE_OFPACT(SET_ETH_DST,     ofpact_mac,           ofpact)    \
     DEFINE_OFPACT(SET_IPV4_SRC,    ofpact_ipv4,          ofpact)    \
     DEFINE_OFPACT(SET_IPV4_DST,    ofpact_ipv4,          ofpact)    \
-    DEFINE_OFPACT(SET_IPV4_DSCP,   ofpact_dscp,          ofpact)    \
+    DEFINE_OFPACT(SET_IP_DSCP,     ofpact_dscp,          ofpact)    \
     DEFINE_OFPACT(SET_L4_SRC_PORT, ofpact_l4_port,       ofpact)    \
     DEFINE_OFPACT(SET_L4_DST_PORT, ofpact_l4_port,       ofpact)    \
     DEFINE_OFPACT(REG_MOVE,        ofpact_reg_move,      ofpact)    \
@@ -285,7 +285,7 @@ struct ofpact_ipv4 {
     ovs_be32 ipv4;
 };
 
-/* OFPACT_SET_IPV4_DSCP.
+/* OFPACT_SET_IP_DSCP.
  *
  * Used for OFPAT10_SET_NW_TOS. */
 struct ofpact_dscp {
diff --git a/lib/ofp-parse.c b/lib/ofp-parse.c
index f8fa9eb..506d76f 100644
--- a/lib/ofp-parse.c
+++ b/lib/ofp-parse.c
@@ -697,7 +697,7 @@ parse_named_action(enum ofputil_action_code code,
         if (tos & ~IP_DSCP_MASK) {
             return xasprintf("%s: not a valid TOS", arg);
         }
-        ofpact_put_SET_IPV4_DSCP(ofpacts)->dscp = tos;
+        ofpact_put_SET_IP_DSCP(ofpacts)->dscp = tos;
         break;
 
     case OFPUTIL_OFPAT11_DEC_NW_TTL:
diff --git a/ofproto/ofproto-dpif-xlate.c b/ofproto/ofproto-dpif-xlate.c
index 7371750..11563aa 100644
--- a/ofproto/ofproto-dpif-xlate.c
+++ b/ofproto/ofproto-dpif-xlate.c
@@ -2364,12 +2364,11 @@ do_xlate_actions(const struct ofpact *ofpacts, size_t 
ofpacts_len,
             }
             break;
 
-        case OFPACT_SET_IPV4_DSCP:
-            /* OpenFlow 1.0 only supports IPv4. */
-            if (flow->dl_type == htons(ETH_TYPE_IP)) {
+        case OFPACT_SET_IP_DSCP:
+            if (is_ip_any(flow)) {
                 wc->masks.nw_tos |= IP_DSCP_MASK;
                 flow->nw_tos &= ~IP_DSCP_MASK;
-                flow->nw_tos |= ofpact_get_SET_IPV4_DSCP(a)->dscp;
+                flow->nw_tos |= ofpact_get_SET_IP_DSCP(a)->dscp;
             }
             break;
 
diff --git a/utilities/ovs-ofctl.8.in b/utilities/ovs-ofctl.8.in
index 3d3879d..bf90498 100644
--- a/utilities/ovs-ofctl.8.in
+++ b/utilities/ovs-ofctl.8.in
@@ -1099,9 +1099,9 @@ Sets the TCP or UDP or SCTP source port to \fIport\fR.
 Sets the TCP or UDP or SCTP destination port to \fIport\fR.
 .
 .IP \fBmod_nw_tos\fB:\fItos\fR
-Sets the IPv4 ToS/DSCP field to \fItos\fR, which must be a multiple of
-4 between 0 and 255.  This action does not modify the two least
-significant bits of the ToS field (the ECN bits).
+Sets the DSCP bits in the IPv4 ToS/DSCP or IPv6 traffic class field to
+\fItos\fR, which must be a multiple of 4 between 0 and 255.  This action
+does not modify the two least significant bits of the ToS field (the ECN bits).
 .RE
 .IP
 The following actions are Nicira vendor extensions that, as of this writing, 
are
-- 
1.7.10.4

_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to