diff mbox

[ovs-dev,PATCHv2,4/6] ofp-actions: Refactor ofpact_get_mf_dst().

Message ID 1447270794-21103-5-git-send-email-joestringer@nicira.com
State Awaiting Upstream
Headers show

Commit Message

Joe Stringer Nov. 11, 2015, 7:39 p.m. UTC
This function finds the mf destination field for any ofpact, returning
NULL if not applicable. It will be used by the next patch to properly
reject OpenFlow flows with conntrack actions when conntrack is
unsupported by the datapath.

Signed-off-by: Joe Stringer <joestringer@nicira.com>
Acked-by: Jarno Rajahalme <jrajahalme@nicira.com>
---
 lib/ofp-actions.c | 18 +++++++++++-------
 lib/ofp-actions.h |  1 +
 2 files changed, 12 insertions(+), 7 deletions(-)

Comments

Jarno Rajahalme Nov. 11, 2015, 10:21 p.m. UTC | #1
I guess this did not change?

  Jarno

> On Nov 11, 2015, at 11:39 AM, Joe Stringer <joestringer@nicira.com> wrote:
> 
> This function finds the mf destination field for any ofpact, returning
> NULL if not applicable. It will be used by the next patch to properly
> reject OpenFlow flows with conntrack actions when conntrack is
> unsupported by the datapath.
> 
> Signed-off-by: Joe Stringer <joestringer@nicira.com>
> Acked-by: Jarno Rajahalme <jrajahalme@nicira.com>
> ---
> lib/ofp-actions.c | 18 +++++++++++-------
> lib/ofp-actions.h |  1 +
> 2 files changed, 12 insertions(+), 7 deletions(-)
> 
> diff --git a/lib/ofp-actions.c b/lib/ofp-actions.c
> index 5f72fda16154..625e7b8168a8 100644
> --- a/lib/ofp-actions.c
> +++ b/lib/ofp-actions.c
> @@ -6270,16 +6270,20 @@ ofpacts_check_consistency(struct ofpact ofpacts[], size_t ofpacts_len,
>             : 0);
> }
> 
> -static const struct mf_field *
> -ofpact_get_mf_field(enum ofpact_type type, const void *ofpact)
> +/* Returns the destination field that 'ofpact' would write to, or NULL
> + * if the action would not write to an mf_field. */
> +const struct mf_field *
> +ofpact_get_mf_dst(const struct ofpact *ofpact)
> {
> -    if (type == OFPACT_SET_FIELD) {
> -        const struct ofpact_set_field *orl = ofpact;
> +    if (ofpact->type == OFPACT_SET_FIELD) {
> +        const struct ofpact_set_field *orl;
> 
> +        orl = CONTAINER_OF(ofpact, struct ofpact_set_field, ofpact);
>         return orl->field;
> -    } else if (type == OFPACT_REG_MOVE) {
> -        const struct ofpact_reg_move *orm = ofpact;
> +    } else if (ofpact->type == OFPACT_REG_MOVE) {
> +        const struct ofpact_reg_move *orm;
> 
> +        orm = CONTAINER_OF(ofpact, struct ofpact_reg_move, ofpact);
>         return orm->dst.field;
>     }
> 
> @@ -6304,7 +6308,7 @@ field_requires_ct(enum mf_field_id field)
> static enum ofperr
> ofpacts_verify_nested(const struct ofpact *a, enum ofpact_type outer_action)
> {
> -    const struct mf_field *field = ofpact_get_mf_field(a->type, a);
> +    const struct mf_field *field = ofpact_get_mf_dst(a);
> 
>     if (field && field_requires_ct(field->id) && outer_action != OFPACT_CT) {
>         VLOG_WARN("cannot set CT fields outside of ct action");
> diff --git a/lib/ofp-actions.h b/lib/ofp-actions.h
> index 773b6170474d..6d893eafc83e 100644
> --- a/lib/ofp-actions.h
> +++ b/lib/ofp-actions.h
> @@ -821,6 +821,7 @@ bool ofpacts_output_to_group(const struct ofpact[], size_t ofpacts_len,
>                              uint32_t group_id);
> bool ofpacts_equal(const struct ofpact a[], size_t a_len,
>                    const struct ofpact b[], size_t b_len);
> +const struct mf_field *ofpact_get_mf_dst(const struct ofpact *ofpact);
> uint32_t ofpacts_get_meter(const struct ofpact[], size_t ofpacts_len);
> 
> /* Formatting and parsing ofpacts. */
> -- 
> 2.1.4
>
Joe Stringer Nov. 12, 2015, 12:12 a.m. UTC | #2
On 11 November 2015 at 14:21, Jarno Rajahalme <jarno@ovn.org> wrote:
> I guess this did not change?

Correct, I just added the Ack. (Perhaps I should have mentioned that
below the commit message.)
diff mbox

Patch

diff --git a/lib/ofp-actions.c b/lib/ofp-actions.c
index 5f72fda16154..625e7b8168a8 100644
--- a/lib/ofp-actions.c
+++ b/lib/ofp-actions.c
@@ -6270,16 +6270,20 @@  ofpacts_check_consistency(struct ofpact ofpacts[], size_t ofpacts_len,
             : 0);
 }
 
-static const struct mf_field *
-ofpact_get_mf_field(enum ofpact_type type, const void *ofpact)
+/* Returns the destination field that 'ofpact' would write to, or NULL
+ * if the action would not write to an mf_field. */
+const struct mf_field *
+ofpact_get_mf_dst(const struct ofpact *ofpact)
 {
-    if (type == OFPACT_SET_FIELD) {
-        const struct ofpact_set_field *orl = ofpact;
+    if (ofpact->type == OFPACT_SET_FIELD) {
+        const struct ofpact_set_field *orl;
 
+        orl = CONTAINER_OF(ofpact, struct ofpact_set_field, ofpact);
         return orl->field;
-    } else if (type == OFPACT_REG_MOVE) {
-        const struct ofpact_reg_move *orm = ofpact;
+    } else if (ofpact->type == OFPACT_REG_MOVE) {
+        const struct ofpact_reg_move *orm;
 
+        orm = CONTAINER_OF(ofpact, struct ofpact_reg_move, ofpact);
         return orm->dst.field;
     }
 
@@ -6304,7 +6308,7 @@  field_requires_ct(enum mf_field_id field)
 static enum ofperr
 ofpacts_verify_nested(const struct ofpact *a, enum ofpact_type outer_action)
 {
-    const struct mf_field *field = ofpact_get_mf_field(a->type, a);
+    const struct mf_field *field = ofpact_get_mf_dst(a);
 
     if (field && field_requires_ct(field->id) && outer_action != OFPACT_CT) {
         VLOG_WARN("cannot set CT fields outside of ct action");
diff --git a/lib/ofp-actions.h b/lib/ofp-actions.h
index 773b6170474d..6d893eafc83e 100644
--- a/lib/ofp-actions.h
+++ b/lib/ofp-actions.h
@@ -821,6 +821,7 @@  bool ofpacts_output_to_group(const struct ofpact[], size_t ofpacts_len,
                              uint32_t group_id);
 bool ofpacts_equal(const struct ofpact a[], size_t a_len,
                    const struct ofpact b[], size_t b_len);
+const struct mf_field *ofpact_get_mf_dst(const struct ofpact *ofpact);
 uint32_t ofpacts_get_meter(const struct ofpact[], size_t ofpacts_len);
 
 /* Formatting and parsing ofpacts. */