Skip to content

Commit

Permalink
util: Pass 128-bit arguments directly instead of using pointers.
Browse files Browse the repository at this point in the history
Commit f2d105b (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 <[email protected]>
Acked-by: Joe Stringer <[email protected]>
  • Loading branch information
justinpettit committed May 8, 2016
1 parent 20322d4 commit 2ff8484
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion lib/ct-dpif.c
Original file line number Diff line number Diff line change
Expand Up @@ -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=");
Expand Down
4 changes: 2 additions & 2 deletions lib/dpif-netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -1819,7 +1819,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;
}
}
Expand Down Expand Up @@ -1965,7 +1965,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;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/dpif.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
6 changes: 3 additions & 3 deletions lib/flow.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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++) {
Expand Down
4 changes: 2 additions & 2 deletions lib/match.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/meta-flow.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions lib/odp-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -1492,7 +1492,7 @@ parse_conntrack_action(const char *s_, struct ofpbuf *actions)
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);
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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));
}
Expand Down
20 changes: 10 additions & 10 deletions lib/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ofproto/ofproto-dpif-upcall.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion ofproto/ofproto-dpif-xlate.c
Original file line number Diff line number Diff line change
Expand Up @@ -4327,7 +4327,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;
Expand Down
2 changes: 1 addition & 1 deletion ofproto/ofproto-dpif.c
Original file line number Diff line number Diff line change
Expand Up @@ -3997,7 +3997,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;
}

Expand Down
4 changes: 2 additions & 2 deletions tests/test-hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 2ff8484

Please sign in to comment.