[ovs-dev] [PATCH] util: Pass 128-bit arguments directly instead of using pointers.

Justin Pettit jpettit at ovn.org
Wed May 4 01:31:10 UTC 2016


Commit f2d105b5 (ofproto-dpif-xlate: xlate ct_{mark, label} correctly.)
introduced the ovs_u128_and() function.  It directly takes ovs_u128
values as arguments instead of pointers to them.  As this is a bit more
direct way to deal with 128-bit values, modify the other utility
functions to do the same.

Signed-off-by: Justin Pettit <jpettit at ovn.org>
---
 lib/ct-dpif.c                 |  2 +-
 lib/dpif-netdev.c             |  4 ++--
 lib/dpif.c                    |  2 +-
 lib/flow.c                    |  6 +++---
 lib/match.c                   |  4 ++--
 lib/meta-flow.c               |  2 +-
 lib/odp-util.c                |  8 ++++----
 lib/util.h                    | 20 ++++++++++----------
 ofproto/ofproto-dpif-upcall.c |  2 +-
 ofproto/ofproto-dpif-xlate.c  |  2 +-
 ofproto/ofproto-dpif.c        |  2 +-
 tests/test-hash.c             |  4 ++--
 12 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/lib/ct-dpif.c b/lib/ct-dpif.c
index d255a71..63ca498 100644
--- a/lib/ct-dpif.c
+++ b/lib/ct-dpif.c
@@ -168,7 +168,7 @@ ct_dpif_format_entry(const struct ct_dpif_entry *entry, struct ds *ds,
     if (entry->mark) {
         ds_put_format(ds, ",mark=%"PRIu32, entry->mark);
     }
-    if (!ovs_u128_is_zero(&entry->labels)) {
+    if (!ovs_u128_is_zero(entry->labels)) {
         ovs_be128 value;
 
         ds_put_cstr(ds, ",labels=");
diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
index 1e8a37c..3a9c2a4 100644
--- a/lib/dpif-netdev.c
+++ b/lib/dpif-netdev.c
@@ -1821,7 +1821,7 @@ dp_netdev_pmd_find_flow(const struct dp_netdev_pmd_thread *pmd,
     if (ufidp) {
         CMAP_FOR_EACH_WITH_HASH (netdev_flow, node, dp_netdev_flow_hash(ufidp),
                                  &pmd->flow_table) {
-            if (ovs_u128_equals(&netdev_flow->ufid, ufidp)) {
+            if (ovs_u128_equals(netdev_flow->ufid, *ufidp)) {
                 return netdev_flow;
             }
         }
@@ -1967,7 +1967,7 @@ dpif_netdev_flow_from_nlattrs(const struct nlattr *key, uint32_t key_len,
 
     /* Userspace datapath doesn't support conntrack. */
     if (flow->ct_state || flow->ct_zone || flow->ct_mark
-        || !ovs_u128_is_zero(&flow->ct_label)) {
+        || !ovs_u128_is_zero(flow->ct_label)) {
         return EINVAL;
     }
 
diff --git a/lib/dpif.c b/lib/dpif.c
index 2c64d9e..5037ac6 100644
--- a/lib/dpif.c
+++ b/lib/dpif.c
@@ -903,7 +903,7 @@ dpif_probe_feature(struct dpif *dpif, const char *name,
                           PMD_ID_NULL, &reply, &flow);
     if (!error
         && (!ufid || (flow.ufid_present
-                      && ovs_u128_equals(ufid, &flow.ufid)))) {
+                      && ovs_u128_equals(*ufid, flow.ufid)))) {
         enable_feature = true;
     }
 
diff --git a/lib/flow.c b/lib/flow.c
index 343ae6d..fc8843e 100644
--- a/lib/flow.c
+++ b/lib/flow.c
@@ -524,7 +524,7 @@ miniflow_extract(struct dp_packet *packet, struct miniflow *dst)
         miniflow_push_uint32(mf, ct_mark, md->ct_mark);
         miniflow_pad_to_64(mf, ct_mark);
 
-        if (!ovs_u128_is_zero(&md->ct_label)) {
+        if (!ovs_u128_is_zero(md->ct_label)) {
             miniflow_push_words(mf, ct_label, &md->ct_label,
                                 sizeof md->ct_label / sizeof(uint64_t));
         }
@@ -895,7 +895,7 @@ flow_get_metadata(const struct flow *flow, struct match *flow_metadata)
     if (flow->ct_mark != 0) {
         match_set_ct_mark(flow_metadata, flow->ct_mark);
     }
-    if (!ovs_u128_is_zero(&flow->ct_label)) {
+    if (!ovs_u128_is_zero(flow->ct_label)) {
         match_set_ct_label(flow_metadata, flow->ct_label);
     }
 }
@@ -1206,7 +1206,7 @@ flow_format(struct ds *ds, const struct flow *flow)
     if (!flow->ct_mark) {
         WC_UNMASK_FIELD(wc, ct_mark);
     }
-    if (ovs_u128_is_zero(&flow->ct_label)) {
+    if (ovs_u128_is_zero(flow->ct_label)) {
         WC_UNMASK_FIELD(wc, ct_label);
     }
     for (int i = 0; i < FLOW_N_REGS; i++) {
diff --git a/lib/match.c b/lib/match.c
index 052130a..db78831 100644
--- a/lib/match.c
+++ b/lib/match.c
@@ -1033,7 +1033,7 @@ format_flow_tunnel(struct ds *s, const struct match *match)
 static void
 format_ct_label_masked(struct ds *s, const ovs_u128 *key, const ovs_u128 *mask)
 {
-    if (!ovs_u128_is_zero(mask)) {
+    if (!ovs_u128_is_zero(*mask)) {
         ovs_be128 value = hton128(*key);
         ds_put_format(s, "%sct_label=%s", colors.param, colors.end);
         ds_put_hex(s, &value, sizeof value);
@@ -1118,7 +1118,7 @@ match_format(const struct match *match, struct ds *s, int priority)
         format_uint32_masked(s, "ct_mark", f->ct_mark, wc->masks.ct_mark);
     }
 
-    if (!ovs_u128_is_zero(&wc->masks.ct_label)) {
+    if (!ovs_u128_is_zero(wc->masks.ct_label)) {
         format_ct_label_masked(s, &f->ct_label, &wc->masks.ct_label);
     }
 
diff --git a/lib/meta-flow.c b/lib/meta-flow.c
index ce60f22..2a129ea 100644
--- a/lib/meta-flow.c
+++ b/lib/meta-flow.c
@@ -232,7 +232,7 @@ mf_is_all_wild(const struct mf_field *mf, const struct flow_wildcards *wc)
     case MFF_CT_MARK:
         return !wc->masks.ct_mark;
     case MFF_CT_LABEL:
-        return ovs_u128_is_zero(&wc->masks.ct_label);
+        return ovs_u128_is_zero(wc->masks.ct_label);
     CASE_MFF_REGS:
         return !wc->masks.regs[mf->id - MFF_REG0];
     CASE_MFF_XREGS:
diff --git a/lib/odp-util.c b/lib/odp-util.c
index e0a1ad4..2cdd504 100644
--- a/lib/odp-util.c
+++ b/lib/odp-util.c
@@ -1492,7 +1492,7 @@ find_end:
             nl_msg_put_unspec(actions, OVS_CT_ATTR_MARK, &ct_mark,
                               sizeof(ct_mark));
         }
-        if (!ovs_u128_is_zero(&ct_label.mask)) {
+        if (!ovs_u128_is_zero(ct_label.mask)) {
             nl_msg_put_unspec(actions, OVS_CT_ATTR_LABELS, &ct_label,
                               sizeof ct_label);
         }
@@ -2950,12 +2950,12 @@ static void
 format_u128(struct ds *ds, const ovs_u128 *key, const ovs_u128 *mask,
             bool verbose)
 {
-    if (verbose || (mask && !ovs_u128_is_zero(mask))) {
+    if (verbose || (mask && !ovs_u128_is_zero(*mask))) {
         ovs_be128 value;
 
         value = hton128(*key);
         ds_put_hex(ds, &value, sizeof value);
-        if (mask && !(ovs_u128_is_ones(mask))) {
+        if (mask && !(ovs_u128_is_ones(*mask))) {
             value = hton128(*mask);
             ds_put_char(ds, '/');
             ds_put_hex(ds, &value, sizeof value);
@@ -4464,7 +4464,7 @@ odp_key_from_pkt_metadata(struct ofpbuf *buf, const struct pkt_metadata *md)
         if (md->ct_mark) {
             nl_msg_put_u32(buf, OVS_KEY_ATTR_CT_MARK, md->ct_mark);
         }
-        if (!ovs_u128_is_zero(&md->ct_label)) {
+        if (!ovs_u128_is_zero(md->ct_label)) {
             nl_msg_put_unspec(buf, OVS_KEY_ATTR_CT_LABELS, &md->ct_label,
                               sizeof(md->ct_label));
         }
diff --git a/lib/util.h b/lib/util.h
index f631bdf..7be4a30 100644
--- a/lib/util.h
+++ b/lib/util.h
@@ -392,37 +392,37 @@ void bitwise_toggle_bit(void *dst, unsigned int len, unsigned int ofs);
 
 /* Returns non-zero if the parameters have equal value. */
 static inline int
-ovs_u128_equals(const ovs_u128 *a, const ovs_u128 *b)
+ovs_u128_equals(const ovs_u128 a, const ovs_u128 b)
 {
-    return (a->u64.hi == b->u64.hi) && (a->u64.lo == b->u64.lo);
+    return (a.u64.hi == b.u64.hi) && (a.u64.lo == b.u64.lo);
 }
 
 /* Returns true if 'val' is 0. */
 static inline bool
-ovs_u128_is_zero(const ovs_u128 *val)
+ovs_u128_is_zero(const ovs_u128 val)
 {
-    return !(val->u64.hi || val->u64.lo);
+    return !(val.u64.hi || val.u64.lo);
 }
 
 /* Returns true if 'val' is all ones. */
 static inline bool
-ovs_u128_is_ones(const ovs_u128 *val)
+ovs_u128_is_ones(const ovs_u128 val)
 {
-    return ovs_u128_equals(val, &OVS_U128_MAX);
+    return ovs_u128_equals(val, OVS_U128_MAX);
 }
 
 /* Returns non-zero if the parameters have equal value. */
 static inline int
-ovs_be128_equals(const ovs_be128 *a, const ovs_be128 *b)
+ovs_be128_equals(const ovs_be128 a, const ovs_be128 b)
 {
-    return (a->be64.hi == b->be64.hi) && (a->be64.lo == b->be64.lo);
+    return (a.be64.hi == b.be64.hi) && (a.be64.lo == b.be64.lo);
 }
 
 /* Returns true if 'val' is 0. */
 static inline bool
-ovs_be128_is_zero(const ovs_be128 *val)
+ovs_be128_is_zero(const ovs_be128 val)
 {
-    return !(val->be64.hi || val->be64.lo);
+    return !(val.be64.hi || val.be64.lo);
 }
 
 static inline ovs_u128
diff --git a/ofproto/ofproto-dpif-upcall.c b/ofproto/ofproto-dpif-upcall.c
index f62f46b..ae8c2d3 100644
--- a/ofproto/ofproto-dpif-upcall.c
+++ b/ofproto/ofproto-dpif-upcall.c
@@ -1391,7 +1391,7 @@ ukey_lookup(struct udpif *udpif, const ovs_u128 *ufid, const unsigned pmd_id)
 
     CMAP_FOR_EACH_WITH_HASH (ukey, cmap_node,
                              get_ukey_hash(ufid, pmd_id), cmap) {
-        if (ovs_u128_equals(&ukey->ufid, ufid)) {
+        if (ovs_u128_equals(ukey->ufid, *ufid)) {
             return ukey;
         }
     }
diff --git a/ofproto/ofproto-dpif-xlate.c b/ofproto/ofproto-dpif-xlate.c
index cdf5a83..0114c0a 100644
--- a/ofproto/ofproto-dpif-xlate.c
+++ b/ofproto/ofproto-dpif-xlate.c
@@ -4291,7 +4291,7 @@ static void
 put_ct_label(const struct flow *flow, struct ofpbuf *odp_actions,
              struct flow_wildcards *wc)
 {
-    if (!ovs_u128_is_zero(&wc->masks.ct_label)) {
+    if (!ovs_u128_is_zero(wc->masks.ct_label)) {
         struct {
             ovs_u128 key;
             ovs_u128 mask;
diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c
index a1e0407..d3dd636 100644
--- a/ofproto/ofproto-dpif.c
+++ b/ofproto/ofproto-dpif.c
@@ -3998,7 +3998,7 @@ check_mask(struct ofproto_dpif *ofproto, const struct miniflow *flow)
         || ((ct_state & (CS_SRC_NAT | CS_DST_NAT)) && !support->ct_state_nat)
         || (ct_zone && !support->ct_zone)
         || (ct_mark && !support->ct_mark)
-        || (!ovs_u128_is_zero(&ct_label) && !support->ct_label)) {
+        || (!ovs_u128_is_zero(ct_label) && !support->ct_label)) {
         return OFPERR_OFPBMC_BAD_MASK;
     }
 
diff --git a/tests/test-hash.c b/tests/test-hash.c
index 67a1f6c..d1beead 100644
--- a/tests/test-hash.c
+++ b/tests/test-hash.c
@@ -162,7 +162,7 @@ check_hash_bytes128(void (*hash)(const void *, size_t, uint32_t, ovs_u128 *),
         set_bit128(&in1, i, n_bits);
         hash(in0, sizeof(ovs_u128), 0, &out0);
         hash(&in1, sizeof(ovs_u128), 0, &out1);
-        if (!ovs_u128_equals(&out0, &out1)) {
+        if (!ovs_u128_equals(out0, out1)) {
             printf("%s hash not the same for non-64 aligned data "
                    "%016"PRIx64"%016"PRIx64" != %016"PRIx64"%016"PRIx64"\n",
                    name, out0.u64.lo, out0.u64.hi, out1.u64.lo, out1.u64.hi);
@@ -214,7 +214,7 @@ check_256byte_hash(void (*hash)(const void *, size_t, uint32_t, ovs_u128 *),
         set_bit128(in1, i, n_bits);
         hash(in0, sizeof(ovs_u128) * 16, 0, &out0);
         hash(in1, sizeof(ovs_u128) * 16, 0, &out1);
-        if (!ovs_u128_equals(&out0, &out1)) {
+        if (!ovs_u128_equals(out0, out1)) {
             printf("%s hash not the same for non-64 aligned data "
                    "%016"PRIx64"%016"PRIx64" != %016"PRIx64"%016"PRIx64"\n",
                    name, out0.u64.lo, out0.u64.hi, out1.u64.lo, out1.u64.hi);
-- 
1.9.1




More information about the dev mailing list