Skip to content

Commit

Permalink
byte-order: Make hton128() and ntoh128() behave like their counterparts.
Browse files Browse the repository at this point in the history
Instead of taking the source and destination as arguments, make these
functions act like their short and long counterparts.

Signed-off-by: Justin Pettit <[email protected]>
Acked-by: Ben Pfaff <[email protected]>
  • Loading branch information
justinpettit committed Nov 24, 2015
1 parent 184dfff commit 32ea15f
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 39 deletions.
22 changes: 14 additions & 8 deletions lib/byte-order.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,24 @@ ovs_be64 htonll(uint64_t);
uint64_t ntohll(ovs_be64);
#endif

static inline void
hton128(const ovs_u128 *src, ovs_be128 *dst)
static inline ovs_be128
hton128(const ovs_u128 src)
{
dst->be64.hi = htonll(src->u64.hi);
dst->be64.lo = htonll(src->u64.lo);
ovs_be128 dst;

dst.be64.hi = htonll(src.u64.hi);
dst.be64.lo = htonll(src.u64.lo);
return dst;
}

static inline void
ntoh128(const ovs_be128 *src, ovs_u128 *dst)
static inline ovs_u128
ntoh128(const ovs_be128 src)
{
dst->u64.hi = ntohll(src->be64.hi);
dst->u64.lo = ntohll(src->be64.lo);
ovs_u128 dst;

dst.u64.hi = ntohll(src.be64.hi);
dst.u64.lo = ntohll(src.be64.lo);
return dst;
}

static inline uint32_t
Expand Down
6 changes: 2 additions & 4 deletions lib/match.c
Original file line number Diff line number Diff line change
Expand Up @@ -979,13 +979,11 @@ static void
format_ct_label_masked(struct ds *s, const ovs_u128 *key, const ovs_u128 *mask)
{
if (!ovs_u128_is_zero(mask)) {
ovs_be128 value;

hton128(key, &value);
ovs_be128 value = hton128(*key);
ds_put_format(s, "ct_label=");
ds_put_hex(s, &value, sizeof value);
if (!is_all_ones(mask, sizeof(*mask))) {
hton128(mask, &value);
value = hton128(*mask);
ds_put_char(s, '/');
ds_put_hex(s, &value, sizeof value);
}
Expand Down
26 changes: 7 additions & 19 deletions lib/meta-flow.c
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ mf_get_value(const struct mf_field *mf, const struct flow *flow,
break;

case MFF_CT_LABEL:
hton128(&flow->ct_label, &value->be128);
value->be128 = hton128(flow->ct_label);
break;

CASE_MFF_REGS:
Expand Down Expand Up @@ -918,13 +918,9 @@ mf_set_value(const struct mf_field *mf,
match_set_ct_mark(match, ntohl(value->be32));
break;

case MFF_CT_LABEL: {
ovs_u128 label;

ntoh128(&value->be128, &label);
match_set_ct_label(match, label);
case MFF_CT_LABEL:
match_set_ct_label(match, ntoh128(value->be128));
break;
}

CASE_MFF_REGS:
match_set_reg(match, mf->id - MFF_REG0, ntohl(value->be32));
Expand Down Expand Up @@ -1223,7 +1219,7 @@ mf_set_flow_value(const struct mf_field *mf,
break;

case MFF_CT_LABEL:
ntoh128(&value->be128, &flow->ct_label);
flow->ct_label = ntoh128(value->be128);
break;

CASE_MFF_REGS:
Expand Down Expand Up @@ -1810,18 +1806,10 @@ mf_set(const struct mf_field *mf,
match_set_ct_mark_masked(match, ntohl(value->be32), ntohl(mask->be32));
break;

case MFF_CT_LABEL: {
ovs_u128 hlabel, hmask;

ntoh128(&value->be128, &hlabel);
if (mask) {
ntoh128(&mask->be128, &hmask);
} else {
hmask.u64.lo = hmask.u64.hi = UINT64_MAX;
}
match_set_ct_label_masked(match, hlabel, hmask);
case MFF_CT_LABEL:
match_set_ct_label_masked(match, ntoh128(value->be128),
mask ? ntoh128(mask->be128) : OVS_U128_MAX);
break;
}

case MFF_ETH_DST:
match_set_dl_dst_masked(match, value->mac, mask->mac);
Expand Down
6 changes: 2 additions & 4 deletions lib/nx-match.c
Original file line number Diff line number Diff line change
Expand Up @@ -786,10 +786,8 @@ nxm_put_ct_label(struct ofpbuf *b,
enum mf_field_id field, enum ofp_version version,
const ovs_u128 value, const ovs_u128 mask)
{
ovs_be128 bevalue, bemask;

hton128(&value, &bevalue);
hton128(&mask, &bemask);
ovs_be128 bevalue = hton128(value);
ovs_be128 bemask = hton128(mask);
nxm_put(b, field, version, &bevalue, &bemask, sizeof(bevalue));
}

Expand Down
8 changes: 4 additions & 4 deletions lib/odp-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -2540,10 +2540,10 @@ format_u128(struct ds *ds, const ovs_u128 *key, const ovs_u128 *mask,
if (verbose || (mask && !ovs_u128_is_zero(mask))) {
ovs_be128 value;

hton128(key, &value);
value = hton128(*key);
ds_put_hex(ds, &value, sizeof value);
if (mask && !(ovs_u128_is_ones(mask))) {
hton128(mask, &value);
value = hton128(*mask);
ds_put_char(ds, '/');
ds_put_hex(ds, &value, sizeof value);
}
Expand All @@ -2558,7 +2558,7 @@ scan_u128(const char *s_, ovs_u128 *value, ovs_u128 *mask)
ovs_be128 be_mask;

if (!parse_int_string(s, (uint8_t *)&be_value, sizeof be_value, &s)) {
ntoh128(&be_value, value);
*value = ntoh128(be_value);

if (mask) {
int n;
Expand All @@ -2572,7 +2572,7 @@ scan_u128(const char *s_, ovs_u128 *value, ovs_u128 *mask)
if (error) {
return error;
}
ntoh128(&be_mask, mask);
*mask = ntoh128(be_mask);
} else {
*mask = OVS_U128_MAX;
}
Expand Down

0 comments on commit 32ea15f

Please sign in to comment.