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:
@@ -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
|
||||
|
@@ -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);
|
||||
}
|
||||
|
@@ -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:
|
||||
@@ -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));
|
||||
@@ -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:
|
||||
@@ -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);
|
||||
|
@@ -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));
|
||||
}
|
||||
|
||||
|
@@ -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);
|
||||
}
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user