Skip to content

Commit

Permalink
openvswitch/types.h: New macros OVS_BE16_MAX, OVS_BE32_MAX, OVS_BE64_…
Browse files Browse the repository at this point in the history
…MAX.

These seem slightly nicer than e.g. htons(UINT16_MAX).

Signed-off-by: Ben Pfaff <[email protected]>
  • Loading branch information
blp committed Sep 17, 2013
1 parent 7c01803 commit b826639
Show file tree
Hide file tree
Showing 14 changed files with 66 additions and 64 deletions.
4 changes: 4 additions & 0 deletions include/openvswitch/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
typedef __be16 ovs_be16;
typedef __be32 ovs_be32;
typedef __be64 ovs_be64;

#define OVS_BE16_MAX ((OVS_FORCE ovs_be16) 0xffff)
#define OVS_BE32_MAX ((OVS_FORCE ovs_be32) 0xffffffff)
#define OVS_BE64_MAX ((OVS_FORCE ovs_be64) 0xffffffffffffffffULL)

/* These types help with a few funny situations:
*
Expand Down
2 changes: 1 addition & 1 deletion lib/learn.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ learn_execute(const struct ofpact_learn *learn, const struct flow *flow,
fm->cookie = htonll(0);
fm->cookie_mask = htonll(0);
fm->new_cookie = htonll(learn->cookie);
fm->modify_cookie = fm->new_cookie != htonll(UINT64_MAX);
fm->modify_cookie = fm->new_cookie != OVS_BE64_MAX;
fm->table_id = learn->table_id;
fm->command = OFPFC_MODIFY_STRICT;
fm->idle_timeout = learn->idle_timeout;
Expand Down
30 changes: 15 additions & 15 deletions lib/match.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ match_set_reg_masked(struct match *match, unsigned int reg_idx,
void
match_set_metadata(struct match *match, ovs_be64 metadata)
{
match_set_metadata_masked(match, metadata, htonll(UINT64_MAX));
match_set_metadata_masked(match, metadata, OVS_BE64_MAX);
}

void
Expand All @@ -195,7 +195,7 @@ match_set_metadata_masked(struct match *match,
void
match_set_tun_id(struct match *match, ovs_be64 tun_id)
{
match_set_tun_id_masked(match, tun_id, htonll(UINT64_MAX));
match_set_tun_id_masked(match, tun_id, OVS_BE64_MAX);
}

void
Expand All @@ -208,7 +208,7 @@ match_set_tun_id_masked(struct match *match, ovs_be64 tun_id, ovs_be64 mask)
void
match_set_tun_src(struct match *match, ovs_be32 src)
{
match_set_tun_src_masked(match, src, htonl(UINT32_MAX));
match_set_tun_src_masked(match, src, OVS_BE32_MAX);
}

void
Expand All @@ -221,7 +221,7 @@ match_set_tun_src_masked(struct match *match, ovs_be32 src, ovs_be32 mask)
void
match_set_tun_dst(struct match *match, ovs_be32 dst)
{
match_set_tun_dst_masked(match, dst, htonl(UINT32_MAX));
match_set_tun_dst_masked(match, dst, OVS_BE32_MAX);
}

void
Expand Down Expand Up @@ -300,7 +300,7 @@ match_set_pkt_mark_masked(struct match *match, uint32_t pkt_mark, uint32_t mask)
void
match_set_dl_type(struct match *match, ovs_be16 dl_type)
{
match->wc.masks.dl_type = htons(UINT16_MAX);
match->wc.masks.dl_type = OVS_BE16_MAX;
match->flow.dl_type = dl_type;
}

Expand Down Expand Up @@ -411,7 +411,7 @@ match_set_dl_vlan(struct match *match, ovs_be16 dl_vlan)
{
flow_set_dl_vlan(&match->flow, dl_vlan);
if (dl_vlan == htons(OFP10_VLAN_NONE)) {
match->wc.masks.vlan_tci = htons(UINT16_MAX);
match->wc.masks.vlan_tci = OVS_BE16_MAX;
} else {
match->wc.masks.vlan_tci |= htons(VLAN_VID_MASK | VLAN_CFI);
}
Expand Down Expand Up @@ -518,7 +518,7 @@ match_set_mpls_bos(struct match *match, uint8_t mpls_bos)
void
match_set_tp_src(struct match *match, ovs_be16 tp_src)
{
match_set_tp_src_masked(match, tp_src, htons(UINT16_MAX));
match_set_tp_src_masked(match, tp_src, OVS_BE16_MAX);
}

void
Expand All @@ -531,7 +531,7 @@ match_set_tp_src_masked(struct match *match, ovs_be16 port, ovs_be16 mask)
void
match_set_tp_dst(struct match *match, ovs_be16 tp_dst)
{
match_set_tp_dst_masked(match, tp_dst, htons(UINT16_MAX));
match_set_tp_dst_masked(match, tp_dst, OVS_BE16_MAX);
}

void
Expand All @@ -552,7 +552,7 @@ void
match_set_nw_src(struct match *match, ovs_be32 nw_src)
{
match->flow.nw_src = nw_src;
match->wc.masks.nw_src = htonl(UINT32_MAX);
match->wc.masks.nw_src = OVS_BE32_MAX;
}

void
Expand All @@ -567,7 +567,7 @@ void
match_set_nw_dst(struct match *match, ovs_be32 nw_dst)
{
match->flow.nw_dst = nw_dst;
match->wc.masks.nw_dst = htonl(UINT32_MAX);
match->wc.masks.nw_dst = OVS_BE32_MAX;
}

void
Expand Down Expand Up @@ -692,7 +692,7 @@ match_set_ipv6_dst_masked(struct match *match, const struct in6_addr *dst,
void
match_set_ipv6_label(struct match *match, ovs_be32 ipv6_label)
{
match->wc.masks.ipv6_label = htonl(UINT32_MAX);
match->wc.masks.ipv6_label = OVS_BE32_MAX;
match->flow.ipv6_label = ipv6_label;
}

Expand Down Expand Up @@ -779,7 +779,7 @@ format_be16_masked(struct ds *s, const char *name,
{
if (mask != htons(0)) {
ds_put_format(s, "%s=", name);
if (mask == htons(UINT16_MAX)) {
if (mask == OVS_BE16_MAX) {
ds_put_format(s, "%"PRIu16, ntohs(value));
} else {
ds_put_format(s, "0x%"PRIx16"/0x%"PRIx16,
Expand All @@ -798,7 +798,7 @@ format_flow_tunnel(struct ds *s, const struct match *match)
switch (wc->masks.tunnel.tun_id) {
case 0:
break;
case CONSTANT_HTONLL(UINT64_MAX):
case OVS_BE64_MAX:
ds_put_format(s, "tun_id=%#"PRIx64",", ntohll(tnl->tun_id));
break;
default:
Expand Down Expand Up @@ -926,7 +926,7 @@ match_format(const struct match *match, struct ds *s, unsigned int priority)
switch (wc->masks.metadata) {
case 0:
break;
case CONSTANT_HTONLL(UINT64_MAX):
case OVS_BE64_MAX:
ds_put_format(s, "metadata=%#"PRIx64",", ntohll(f->metadata));
break;
default:
Expand Down Expand Up @@ -972,7 +972,7 @@ match_format(const struct match *match, struct ds *s, unsigned int priority)
format_ipv6_netmask(s, "ipv6_src", &f->ipv6_src, &wc->masks.ipv6_src);
format_ipv6_netmask(s, "ipv6_dst", &f->ipv6_dst, &wc->masks.ipv6_dst);
if (wc->masks.ipv6_label) {
if (wc->masks.ipv6_label == htonl(UINT32_MAX)) {
if (wc->masks.ipv6_label == OVS_BE32_MAX) {
ds_put_format(s, "ipv6_label=0x%05"PRIx32",",
ntohl(f->ipv6_label));
} else {
Expand Down
13 changes: 6 additions & 7 deletions lib/meta-flow.c
Original file line number Diff line number Diff line change
Expand Up @@ -2310,12 +2310,12 @@ mf_from_ipv4_string(const struct mf_field *mf, const char *s,
return xasprintf("%s: network prefix bits not between 1 and "
"32", s);
} else if (prefix == 32) {
*mask = htonl(UINT32_MAX);
*mask = OVS_BE32_MAX;
} else {
*mask = htonl(((1u << prefix) - 1) << (32 - prefix));
}
} else if (sscanf(s, IP_SCAN_FMT, IP_SCAN_ARGS(ip)) == IP_SCAN_COUNT) {
*mask = htonl(UINT32_MAX);
*mask = OVS_BE32_MAX;
} else {
return xasprintf("%s: invalid IP address", s);
}
Expand Down Expand Up @@ -2373,7 +2373,7 @@ mf_from_ofp_port_string(const struct mf_field *mf, const char *s,

if (ofputil_port_from_string(s, &port)) {
*valuep = htons(ofp_to_u16(port));
*maskp = htons(UINT16_MAX);
*maskp = OVS_BE16_MAX;
return NULL;
}
return xasprintf("%s: port value out of range for %s", s, mf->name);
Expand All @@ -2388,7 +2388,7 @@ mf_from_ofp_port_string32(const struct mf_field *mf, const char *s,
ovs_assert(mf->n_bytes == sizeof(ovs_be32));
if (ofputil_port_from_string(s, &port)) {
*valuep = ofputil_port_to_ofp11(port);
*maskp = htonl(UINT32_MAX);
*maskp = OVS_BE32_MAX;
return NULL;
}
return xasprintf("%s: port value out of range for %s", s, mf->name);
Expand Down Expand Up @@ -2493,7 +2493,7 @@ static char *
mf_from_tun_flags_string(const char *s, ovs_be16 *valuep, ovs_be16 *maskp)
{
if (!parse_flow_tun_flags(s, flow_tun_flag_to_string, valuep)) {
*maskp = htons(UINT16_MAX);
*maskp = OVS_BE16_MAX;
return NULL;
}

Expand Down Expand Up @@ -2661,8 +2661,7 @@ mf_format(const struct mf_field *mf,
break;

case MFS_IPV4:
ip_format_masked(value->be32, mask ? mask->be32 : htonl(UINT32_MAX),
s);
ip_format_masked(value->be32, mask ? mask->be32 : OVS_BE32_MAX, s);
break;

case MFS_IPV6:
Expand Down
8 changes: 4 additions & 4 deletions lib/nx-match.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ nx_pull_raw(const uint8_t *p, unsigned int match_len, bool strict,
if (NXM_HASMASK(header)) {
memcpy(cookie_mask, p + 4 + width, width);
} else {
*cookie_mask = htonll(UINT64_MAX);
*cookie_mask = OVS_BE64_MAX;
}
error = 0;
}
Expand Down Expand Up @@ -361,7 +361,7 @@ nxm_put_16m(struct ofpbuf *b, uint32_t header, ovs_be16 value, ovs_be16 mask)
case 0:
break;

case CONSTANT_HTONS(UINT16_MAX):
case OVS_BE16_MAX:
nxm_put_16(b, header, value);
break;

Expand Down Expand Up @@ -393,7 +393,7 @@ nxm_put_32m(struct ofpbuf *b, uint32_t header, ovs_be32 value, ovs_be32 mask)
case 0:
break;

case CONSTANT_HTONL(UINT32_MAX):
case OVS_BE32_MAX:
nxm_put_32(b, header, value);
break;

Expand Down Expand Up @@ -425,7 +425,7 @@ nxm_put_64m(struct ofpbuf *b, uint32_t header, ovs_be64 value, ovs_be64 mask)
case 0:
break;

case CONSTANT_HTONLL(UINT64_MAX):
case OVS_BE64_MAX:
nxm_put_64(b, header, value);
break;

Expand Down
13 changes: 6 additions & 7 deletions lib/odp-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -1735,7 +1735,7 @@ parse_odp_key_mask_attr(const char *s, const struct simap *port_names,
(pcp << VLAN_PCP_SHIFT) |
VLAN_CFI));
if (mask) {
nl_msg_put_be16(mask, OVS_KEY_ATTR_VLAN, htons(UINT16_MAX));
nl_msg_put_be16(mask, OVS_KEY_ATTR_VLAN, OVS_BE16_MAX);
}
return n;
} else if (mask && (sscanf(s, "vlan(vid=%"SCNi16"/%"SCNi16",pcp=%i/%i,cfi=%i/%i)%n",
Expand All @@ -1756,7 +1756,7 @@ parse_odp_key_mask_attr(const char *s, const struct simap *port_names,
(pcp << VLAN_PCP_SHIFT) |
(cfi ? VLAN_CFI : 0)));
if (mask) {
nl_msg_put_be16(mask, OVS_KEY_ATTR_VLAN, htons(UINT16_MAX));
nl_msg_put_be16(mask, OVS_KEY_ATTR_VLAN, OVS_BE16_MAX);
}
return n;
}
Expand All @@ -1777,8 +1777,7 @@ parse_odp_key_mask_attr(const char *s, const struct simap *port_names,
} else if (sscanf(s, "eth_type(%i)%n", &eth_type, &n) > 0 && n > 0) {
nl_msg_put_be16(key, OVS_KEY_ATTR_ETHERTYPE, htons(eth_type));
if (mask) {
nl_msg_put_be16(mask, OVS_KEY_ATTR_ETHERTYPE,
htons(UINT16_MAX));
nl_msg_put_be16(mask, OVS_KEY_ATTR_ETHERTYPE, OVS_BE16_MAX);
}
return n;
}
Expand Down Expand Up @@ -1813,7 +1812,7 @@ parse_odp_key_mask_attr(const char *s, const struct simap *port_names,
if (mask) {
mpls = nl_msg_put_unspec_uninit(mask, OVS_KEY_ATTR_MPLS,
sizeof *mpls);
mpls->mpls_lse = htonl(UINT32_MAX);
mpls->mpls_lse = OVS_BE32_MAX;
}
return n;
}
Expand Down Expand Up @@ -2434,7 +2433,7 @@ odp_flow_key_from_flow__(struct ofpbuf *buf, const struct flow *data,

if (flow->vlan_tci != htons(0) || flow->dl_type == htons(ETH_TYPE_VLAN)) {
if (is_mask) {
nl_msg_put_be16(buf, OVS_KEY_ATTR_ETHERTYPE, htons(UINT16_MAX));
nl_msg_put_be16(buf, OVS_KEY_ATTR_ETHERTYPE, OVS_BE16_MAX);
} else {
nl_msg_put_be16(buf, OVS_KEY_ATTR_ETHERTYPE, htons(ETH_TYPE_VLAN));
}
Expand All @@ -2460,7 +2459,7 @@ odp_flow_key_from_flow__(struct ofpbuf *buf, const struct flow *data,
* 802.3 SNAP packet with valid eth_type).
*/
if (is_mask) {
nl_msg_put_be16(buf, OVS_KEY_ATTR_ETHERTYPE, htons(UINT16_MAX));
nl_msg_put_be16(buf, OVS_KEY_ATTR_ETHERTYPE, OVS_BE16_MAX);
}
goto unencap;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/ofp-actions.c
Original file line number Diff line number Diff line change
Expand Up @@ -2428,7 +2428,7 @@ ofpact_format(const struct ofpact *a, struct ds *s)
ovs_instruction_name_from_type(
OVSINST_OFPIT11_WRITE_METADATA),
ntohll(metadata->metadata));
if (metadata->mask != htonll(UINT64_MAX)) {
if (metadata->mask != OVS_BE64_MAX) {
ds_put_format(s, "/%#"PRIx64, ntohll(metadata->mask));
}
break;
Expand Down
6 changes: 3 additions & 3 deletions lib/ofp-parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ parse_metadata(struct ofpbuf *b, char *arg)
return error;
}
} else {
om->mask = htonll(UINT64_MAX);
om->mask = OVS_BE64_MAX;
}

return str_to_be64(arg, &om->metadata);
Expand Down Expand Up @@ -1149,7 +1149,7 @@ parse_ofp_str__(struct ofputil_flow_mod *fm, int command, char *string,
fm->cookie_mask = htonll(0);
if (command == OFPFC_MODIFY || command == OFPFC_MODIFY_STRICT) {
/* For modify, by default, don't update the cookie. */
fm->new_cookie = htonll(UINT64_MAX);
fm->new_cookie = OVS_BE64_MAX;
} else{
fm->new_cookie = htonll(0);
}
Expand Down Expand Up @@ -1290,7 +1290,7 @@ parse_ofp_str__(struct ofputil_flow_mod *fm, int command, char *string,
*usable_protocols &= OFPUTIL_P_NXM_OXM_ANY;
}
}
if (!fm->cookie_mask && fm->new_cookie == htonll(UINT64_MAX)
if (!fm->cookie_mask && fm->new_cookie == OVS_BE64_MAX
&& (command == OFPFC_MODIFY || command == OFPFC_MODIFY_STRICT)) {
/* On modifies without a mask, we are supposed to add a flow if
* one does not exist. If a cookie wasn't been specified, use a
Expand Down
2 changes: 1 addition & 1 deletion lib/ofp-print.c
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ ofp_print_flow_mod(struct ds *s, const struct ofp_header *oh, int verbosity)
if (ds_last(s) != ' ') {
ds_put_char(s, ' ');
}
if (fm.new_cookie != htonll(0) && fm.new_cookie != htonll(UINT64_MAX)) {
if (fm.new_cookie != htonll(0) && fm.new_cookie != OVS_BE64_MAX) {
ds_put_format(s, "cookie:0x%"PRIx64" ", ntohll(fm.new_cookie));
}
if (fm.cookie_mask != htonll(0)) {
Expand Down
Loading

0 comments on commit b826639

Please sign in to comment.