2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-31 22:35:15 +00:00

byte-order: Make hton128() and ntoh128() behave like their counterparts.

Instead of taking the source and destination as arguments, make these
functions act like their short and long counterparts.

Signed-off-by: Justin Pettit <jpettit@ovn.org>
Acked-by: Ben Pfaff <blp@ovn.org>
This commit is contained in:
Justin Pettit
2015-10-31 03:12:38 -07:00
parent 184dfff00a
commit 32ea15f6f5
5 changed files with 29 additions and 39 deletions

View File

@@ -42,18 +42,24 @@ ovs_be64 htonll(uint64_t);
uint64_t ntohll(ovs_be64); uint64_t ntohll(ovs_be64);
#endif #endif
static inline void static inline ovs_be128
hton128(const ovs_u128 *src, ovs_be128 *dst) hton128(const ovs_u128 src)
{ {
dst->be64.hi = htonll(src->u64.hi); ovs_be128 dst;
dst->be64.lo = htonll(src->u64.lo);
dst.be64.hi = htonll(src.u64.hi);
dst.be64.lo = htonll(src.u64.lo);
return dst;
} }
static inline void static inline ovs_u128
ntoh128(const ovs_be128 *src, ovs_u128 *dst) ntoh128(const ovs_be128 src)
{ {
dst->u64.hi = ntohll(src->be64.hi); ovs_u128 dst;
dst->u64.lo = ntohll(src->be64.lo);
dst.u64.hi = ntohll(src.be64.hi);
dst.u64.lo = ntohll(src.be64.lo);
return dst;
} }
static inline uint32_t static inline uint32_t

View File

@@ -979,13 +979,11 @@ static void
format_ct_label_masked(struct ds *s, const ovs_u128 *key, const ovs_u128 *mask) 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; ovs_be128 value = hton128(*key);
hton128(key, &value);
ds_put_format(s, "ct_label="); ds_put_format(s, "ct_label=");
ds_put_hex(s, &value, sizeof value); ds_put_hex(s, &value, sizeof value);
if (!is_all_ones(mask, sizeof(*mask))) { if (!is_all_ones(mask, sizeof(*mask))) {
hton128(mask, &value); value = hton128(*mask);
ds_put_char(s, '/'); ds_put_char(s, '/');
ds_put_hex(s, &value, sizeof value); ds_put_hex(s, &value, sizeof value);
} }

View File

@@ -671,7 +671,7 @@ mf_get_value(const struct mf_field *mf, const struct flow *flow,
break; break;
case MFF_CT_LABEL: case MFF_CT_LABEL:
hton128(&flow->ct_label, &value->be128); value->be128 = hton128(flow->ct_label);
break; break;
CASE_MFF_REGS: CASE_MFF_REGS:
@@ -918,13 +918,9 @@ mf_set_value(const struct mf_field *mf,
match_set_ct_mark(match, ntohl(value->be32)); match_set_ct_mark(match, ntohl(value->be32));
break; break;
case MFF_CT_LABEL: { case MFF_CT_LABEL:
ovs_u128 label; match_set_ct_label(match, ntoh128(value->be128));
ntoh128(&value->be128, &label);
match_set_ct_label(match, label);
break; break;
}
CASE_MFF_REGS: CASE_MFF_REGS:
match_set_reg(match, mf->id - MFF_REG0, ntohl(value->be32)); match_set_reg(match, mf->id - MFF_REG0, ntohl(value->be32));
@@ -1223,7 +1219,7 @@ mf_set_flow_value(const struct mf_field *mf,
break; break;
case MFF_CT_LABEL: case MFF_CT_LABEL:
ntoh128(&value->be128, &flow->ct_label); flow->ct_label = ntoh128(value->be128);
break; break;
CASE_MFF_REGS: CASE_MFF_REGS:
@@ -1810,18 +1806,10 @@ mf_set(const struct mf_field *mf,
match_set_ct_mark_masked(match, ntohl(value->be32), ntohl(mask->be32)); match_set_ct_mark_masked(match, ntohl(value->be32), ntohl(mask->be32));
break; break;
case MFF_CT_LABEL: { case MFF_CT_LABEL:
ovs_u128 hlabel, hmask; match_set_ct_label_masked(match, ntoh128(value->be128),
mask ? ntoh128(mask->be128) : OVS_U128_MAX);
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);
break; break;
}
case MFF_ETH_DST: case MFF_ETH_DST:
match_set_dl_dst_masked(match, value->mac, mask->mac); match_set_dl_dst_masked(match, value->mac, mask->mac);

View File

@@ -786,10 +786,8 @@ nxm_put_ct_label(struct ofpbuf *b,
enum mf_field_id field, enum ofp_version version, enum mf_field_id field, enum ofp_version version,
const ovs_u128 value, const ovs_u128 mask) const ovs_u128 value, const ovs_u128 mask)
{ {
ovs_be128 bevalue, bemask; ovs_be128 bevalue = hton128(value);
ovs_be128 bemask = hton128(mask);
hton128(&value, &bevalue);
hton128(&mask, &bemask);
nxm_put(b, field, version, &bevalue, &bemask, sizeof(bevalue)); nxm_put(b, field, version, &bevalue, &bemask, sizeof(bevalue));
} }

View File

@@ -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))) { if (verbose || (mask && !ovs_u128_is_zero(mask))) {
ovs_be128 value; ovs_be128 value;
hton128(key, &value); value = hton128(*key);
ds_put_hex(ds, &value, sizeof value); ds_put_hex(ds, &value, sizeof value);
if (mask && !(ovs_u128_is_ones(mask))) { if (mask && !(ovs_u128_is_ones(mask))) {
hton128(mask, &value); value = hton128(*mask);
ds_put_char(ds, '/'); ds_put_char(ds, '/');
ds_put_hex(ds, &value, sizeof value); ds_put_hex(ds, &value, sizeof value);
} }
@@ -2558,7 +2558,7 @@ scan_u128(const char *s_, ovs_u128 *value, ovs_u128 *mask)
ovs_be128 be_mask; ovs_be128 be_mask;
if (!parse_int_string(s, (uint8_t *)&be_value, sizeof be_value, &s)) { if (!parse_int_string(s, (uint8_t *)&be_value, sizeof be_value, &s)) {
ntoh128(&be_value, value); *value = ntoh128(be_value);
if (mask) { if (mask) {
int n; int n;
@@ -2572,7 +2572,7 @@ scan_u128(const char *s_, ovs_u128 *value, ovs_u128 *mask)
if (error) { if (error) {
return error; return error;
} }
ntoh128(&be_mask, mask); *mask = ntoh128(be_mask);
} else { } else {
*mask = OVS_U128_MAX; *mask = OVS_U128_MAX;
} }