From 04f01c24b522f893b663a34126beb6775176e536 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Wed, 23 Oct 2013 09:58:34 -0700 Subject: [PATCH] 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. Also, rename OFPACT_SET_IPV4_DSCP to OFPACT_SET_IP_DSCP. Signed-off-by: Jarno Rajahalme Signed-off-by: Ben Pfaff --- 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 c00c03677..30e13ec77 100644 --- a/lib/ofp-actions.c +++ b/lib/ofp-actions.c @@ -552,7 +552,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: @@ -844,7 +844,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: @@ -916,7 +916,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: @@ -977,7 +977,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: @@ -1247,7 +1247,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: @@ -1566,7 +1566,7 @@ ofpact_check__(const struct ofpact *a, struct flow *flow, ofp_port_t max_ports, 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: return 0; @@ -1952,7 +1952,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: @@ -2033,9 +2033,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: @@ -2183,9 +2183,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: @@ -2391,7 +2391,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: @@ -2649,8 +2649,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 d6aabf977..25e95aa48 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 17bd7e2cc..0e0d2f808 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 1eb09532e..75fd84bc0 100644 --- a/ofproto/ofproto-dpif-xlate.c +++ b/ofproto/ofproto-dpif-xlate.c @@ -2368,12 +2368,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 3d3879d19..bf90498ff 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 -- 2.20.1