sizeof ((union mf_value *)0)->MEMBER, \
8 * sizeof ((union mf_value *)0)->MEMBER
-static const struct mf_field mf_fields[MFF_N_IDS] = {
+extern const struct mf_field mf_fields[MFF_N_IDS]; /* Silence a warning. */
+
+const struct mf_field mf_fields[MFF_N_IDS] = {
/* ## -------- ## */
/* ## metadata ## */
/* ## -------- ## */
{
- MFF_TUN_ID, "tun_id", NULL,
+ MFF_TUN_ID, "tun_id", "tunnel_id",
MF_FIELD_SIZES(be64),
MFM_FULLY,
MFS_HEXADECIMAL,
OFPUTIL_P_NONE,
OFPUTIL_P_NONE,
}, {
- MFF_TUN_TOS, "tun_tos", NULL,
+ MFF_TUN_TTL, "tun_ttl", NULL,
MF_FIELD_SIZES(u8),
MFM_NONE,
MFS_DECIMAL,
OFPUTIL_P_NONE,
OFPUTIL_P_NONE,
}, {
- MFF_TUN_TTL, "tun_ttl", NULL,
+ MFF_TUN_TOS, "tun_tos", NULL,
MF_FIELD_SIZES(u8),
MFM_NONE,
MFS_DECIMAL,
},
{
- MFF_IP_PROTO, "nw_proto", NULL,
+ MFF_IP_PROTO, "nw_proto", "ip_proto",
MF_FIELD_SIZES(u8),
MFM_NONE,
MFS_DECIMAL,
OFPUTIL_P_ANY, /* Will be shifted for OXM. */
OFPUTIL_P_NONE,
}, {
- MFF_IP_DSCP_SHIFTED, "nw_tos_shifted", NULL,
- MF_FIELD_SIZES(u8),
+ MFF_IP_DSCP_SHIFTED, "ip_dscp", NULL,
+ 1, 6,
MFM_NONE,
MFS_DECIMAL,
MFP_IP_ANY,
OFPUTIL_P_ANY, /* Will be shifted for non-OXM. */
OFPUTIL_P_NONE,
}, {
- MFF_IP_ECN, "nw_ecn", NULL,
+ MFF_IP_ECN, "nw_ecn", "ip_ecn",
1, 2,
MFM_NONE,
MFS_DECIMAL,
MFM_NONE,
MFS_DECIMAL,
MFP_ARP,
- false,
+ true,
NXM_OF_ARP_OP, "NXM_OF_ARP_OP",
OXM_OF_ARP_OP, "OXM_OF_ARP_OP",
OFPUTIL_P_ANY,
MFM_FULLY,
MFS_IPV4,
MFP_ARP,
- false,
+ true,
NXM_OF_ARP_SPA, "NXM_OF_ARP_SPA",
OXM_OF_ARP_SPA, "OXM_OF_ARP_SPA",
OFPUTIL_P_ANY,
MFM_FULLY,
MFS_IPV4,
MFP_ARP,
- false,
+ true,
NXM_OF_ARP_TPA, "NXM_OF_ARP_TPA",
OXM_OF_ARP_TPA, "OXM_OF_ARP_TPA",
OFPUTIL_P_ANY,
MFM_FULLY,
MFS_ETHERNET,
MFP_ARP,
- false,
+ true,
NXM_NX_ARP_SHA, "NXM_NX_ARP_SHA",
OXM_OF_ARP_SHA, "OXM_OF_ARP_SHA",
OFPUTIL_P_NXM_OXM_ANY,
MFM_FULLY,
MFS_ETHERNET,
MFP_ARP,
- false,
+ true,
NXM_NX_ARP_THA, "NXM_NX_ARP_THA",
OXM_OF_ARP_THA, "OXM_OF_ARP_THA",
OFPUTIL_P_NXM_OXM_ANY,
OXM_OF_TCP_DST, "OXM_OF_TCP_DST",
OFPUTIL_P_ANY,
OFPUTIL_P_NXM_OXM_ANY,
+ }, {
+ MFF_TCP_FLAGS, "tcp_flags", NULL,
+ 2, 12,
+ MFM_FULLY,
+ MFS_HEXADECIMAL,
+ MFP_TCP,
+ false,
+ NXM_NX_TCP_FLAGS, "NXM_NX_TCP_FLAGS",
+ NXM_NX_TCP_FLAGS, "NXM_NX_TCP_FLAGS",
+ OFPUTIL_P_NXM_OXM_ANY,
+ OFPUTIL_P_NXM_OXM_ANY,
},
{
const struct mf_field *mf_from_nxm_header__(uint32_t header);
static void nxm_init(void);
-/* Returns the field with the given 'id'. */
-const struct mf_field *
-mf_from_id(enum mf_field_id id)
-{
- ovs_assert((unsigned int) id < MFF_N_IDS);
- return &mf_fields[id];
-}
-
/* Returns the field with the given 'name', or a null pointer if no field has
* that name. */
const struct mf_field *
static void
nxm_do_init(void)
{
- const struct mf_field *mf;
+ int i;
hmap_init(&all_fields);
shash_init(&mf_by_name);
- for (mf = mf_fields; mf < &mf_fields[MFF_N_IDS]; mf++) {
+ for (i = 0; i < MFF_N_IDS; i++) {
+ const struct mf_field *mf = &mf_fields[i];
+
+ ovs_assert(mf->id == i); /* Fields must be in the enum order. */
+
nxm_init_add_field(mf, mf->nxm_header);
if (mf->oxm_header != mf->nxm_header) {
nxm_init_add_field(mf, mf->oxm_header);
case MFF_ICMPV4_CODE:
case MFF_ICMPV6_CODE:
return !wc->masks.tp_dst;
+ case MFF_TCP_FLAGS:
+ return !wc->masks.tcp_flags;
case MFF_N_IDS:
default:
NOT_REACHED();
}
+/* Set field and it's prerequisities in the mask.
+ * This is only ever called for writeable 'mf's, but we do not make the
+ * distinction here. */
+void
+mf_mask_field_and_prereqs(const struct mf_field *mf, struct flow *mask)
+{
+ static const union mf_value exact_match_mask = MF_EXACT_MASK_INITIALIZER;
+
+ mf_set_flow_value(mf, &exact_match_mask, mask);
+
+ switch (mf->prereqs) {
+ case MFP_ND:
+ case MFP_ND_SOLICIT:
+ case MFP_ND_ADVERT:
+ mask->tp_src = OVS_BE16_MAX;
+ mask->tp_dst = OVS_BE16_MAX;
+ /* Fall through. */
+ case MFP_TCP:
+ case MFP_UDP:
+ case MFP_SCTP:
+ case MFP_ICMPV4:
+ case MFP_ICMPV6:
+ mask->nw_proto = 0xff;
+ /* Fall through. */
+ case MFP_ARP:
+ case MFP_IPV4:
+ case MFP_IPV6:
+ case MFP_MPLS:
+ case MFP_IP_ANY:
+ mask->dl_type = OVS_BE16_MAX;
+ break;
+ case MFP_VLAN_VID:
+ mask->vlan_tci |= htons(VLAN_CFI);
+ break;
+ case MFP_NONE:
+ break;
+ }
+}
+
+
/* Returns true if 'value' may be a valid value *as part of a masked match*,
* false otherwise.
*
return !(value->u8 & ~IP_ECN_MASK);
case MFF_IP_FRAG:
return !(value->u8 & ~FLOW_NW_FRAG_MASK);
+ case MFF_TCP_FLAGS:
+ return !(value->be16 & ~htons(0x0fff));
case MFF_ARP_OP:
return !(value->be16 & htons(0xff00));
value->be16 = flow->tp_dst;
break;
+ case MFF_TCP_FLAGS:
+ value->be16 = flow->tcp_flags;
+ break;
+
case MFF_ICMPV4_TYPE:
case MFF_ICMPV6_TYPE:
value->u8 = ntohs(flow->tp_src);
match_set_tp_dst(match, value->be16);
break;
+ case MFF_TCP_FLAGS:
+ match_set_tcp_flags(match, value->be16);
+ break;
+
case MFF_ICMPV4_TYPE:
case MFF_ICMPV6_TYPE:
match_set_icmp_type(match, value->u8);
}
}
+/* Unwildcard 'mask' member field described by 'mf'. The caller is
+ * responsible for ensuring that 'mask' meets 'mf''s prerequisites. */
+void
+mf_mask_field(const struct mf_field *mf, struct flow *mask)
+{
+ static const union mf_value exact_match_mask = MF_EXACT_MASK_INITIALIZER;
+
+ /* For MFF_DL_VLAN, we cannot send a all 1's to flow_set_dl_vlan()
+ * as that will be considered as OFP10_VLAN_NONE. So consider it as a
+ * special case. For the rest, calling mf_set_flow_value() is good
+ * enough. */
+ if (mf->id == MFF_DL_VLAN) {
+ flow_set_dl_vlan(mask, htons(VLAN_VID_MASK));
+ } else {
+ mf_set_flow_value(mf, &exact_match_mask, mask);
+ }
+}
+
/* Sets 'flow' member field described by 'mf' to 'value'. The caller is
* responsible for ensuring that 'flow' meets 'mf''s prerequisites.*/
void
flow->tp_dst = value->be16;
break;
+ case MFF_TCP_FLAGS:
+ flow->tcp_flags = value->be16;
+ break;
+
case MFF_ICMPV4_TYPE:
case MFF_ICMPV6_TYPE:
flow->tp_src = htons(value->u8);
match->flow.tp_dst = htons(0);
break;
+ case MFF_TCP_FLAGS:
+ match->wc.masks.tcp_flags = htons(0);
+ match->flow.tcp_flags = htons(0);
+ break;
+
case MFF_ND_TARGET:
memset(&match->wc.masks.nd_target, 0,
sizeof match->wc.masks.nd_target);
case MFF_ICMPV4_CODE:
case MFF_ICMPV6_TYPE:
case MFF_ICMPV6_CODE:
- NOT_REACHED();
+ return OFPUTIL_P_NONE;
case MFF_TUN_ID:
match_set_tun_id_masked(match, value->be64, mask->be64);
match_set_tp_dst_masked(match, value->be16, mask->be16);
break;
+ case MFF_TCP_FLAGS:
+ match_set_tcp_flags_masked(match, value->be16, mask->be16);
+ break;
+
case MFF_N_IDS:
default:
NOT_REACHED();
case MFF_ND_TLL:
break;
+ case MFF_TCP_FLAGS:
+ value->be16 &= htons(0x0fff);
+ break;
+
case MFF_IN_PORT_OXM:
value->be32 = ofputil_port_to_ofp11(u16_to_ofp(ntohs(value->be16)));
break;
mf_parse(const struct mf_field *mf, const char *s,
union mf_value *value, union mf_value *mask)
{
+ char *error;
+
if (!strcmp(s, "*")) {
memset(value, 0, mf->n_bytes);
memset(mask, 0, mf->n_bytes);
switch (mf->string) {
case MFS_DECIMAL:
case MFS_HEXADECIMAL:
- return mf_from_integer_string(mf, s,
- (uint8_t *) value, (uint8_t *) mask);
+ error = mf_from_integer_string(mf, s,
+ (uint8_t *) value, (uint8_t *) mask);
+ break;
case MFS_ETHERNET:
- return mf_from_ethernet_string(mf, s, value->mac, mask->mac);
+ error = mf_from_ethernet_string(mf, s, value->mac, mask->mac);
+ break;
case MFS_IPV4:
- return mf_from_ipv4_string(mf, s, &value->be32, &mask->be32);
+ error = mf_from_ipv4_string(mf, s, &value->be32, &mask->be32);
+ break;
case MFS_IPV6:
- return mf_from_ipv6_string(mf, s, &value->ipv6, &mask->ipv6);
+ error = mf_from_ipv6_string(mf, s, &value->ipv6, &mask->ipv6);
+ break;
case MFS_OFP_PORT:
- return mf_from_ofp_port_string(mf, s, &value->be16, &mask->be16);
+ error = mf_from_ofp_port_string(mf, s, &value->be16, &mask->be16);
+ break;
case MFS_OFP_PORT_OXM:
- return mf_from_ofp_port_string32(mf, s, &value->be32, &mask->be32);
+ error = mf_from_ofp_port_string32(mf, s, &value->be32, &mask->be32);
+ break;
case MFS_FRAG:
- return mf_from_frag_string(s, &value->u8, &mask->u8);
+ error = mf_from_frag_string(s, &value->u8, &mask->u8);
+ break;
case MFS_TNL_FLAGS:
ovs_assert(mf->n_bytes == sizeof(ovs_be16));
- return mf_from_tun_flags_string(s, &value->be16, &mask->be16);
+ error = mf_from_tun_flags_string(s, &value->be16, &mask->be16);
+ break;
+
+ default:
+ NOT_REACHED();
}
- NOT_REACHED();
+
+ if (!error && !mf_is_mask_valid(mf, mask)) {
+ error = xasprintf("%s: invalid mask for field %s", s, mf->name);
+ }
+ return error;
}
/* Parses 's', a string value for field 'mf', into 'value'. Returns NULL if