@@ -1996,5 +1996,5 @@ enum ofperr mf_vl_mff_map_mod_from_tun_metadata(
OVS_REQUIRES(vl_mff_map->mutex);
const struct mf_field * mf_get_vl_mff(const struct mf_field *,
const struct vl_mff_map *);
-bool mf_vl_mff_not_mapped(const struct mf_field *, const struct vl_mff_map *);
+bool mf_vl_mff_mapped(const struct mf_field *, const struct vl_mff_map *);
#endif /* meta-flow.h */
@@ -397,7 +397,7 @@ enum ofperr {
/* NX1.0-1.1(1,536), NX1.2+(37). Attempted to add a flow with an invalid
* variable length meta-flow field. */
- OFPERR_NXFMFC_INVALID_VL_MFF,
+ OFPERR_NXFMFC_INVALID_TLV_FIELD,
/* ## ---------------------- ## */
/* ## OFPET_GROUP_MOD_FAILED ## */
@@ -2659,6 +2659,35 @@ mf_vl_mff_map_clear(struct vl_mff_map *vl_mff_map)
}
}
+static struct mf_field *
+mf_get_vl_mff__(uint32_t id, const struct vl_mff_map *vl_mff_map)
+{
+ struct mf_field *field;
+
+ CMAP_FOR_EACH_WITH_HASH (field, cmap_node, mf_field_hash(id),
+ &vl_mff_map->cmap) {
+ if (field->id == id) {
+ return field;
+ }
+ }
+
+ return NULL;
+}
+
+/* If 'mff' is a variable length field, looks up 'vl_mff_map', returns a
+ * pointer to the variable length meta-flow field corresponding to 'mff'.
+ * Returns NULL if no mapping is existed for 'mff'. */
+const struct mf_field *
+mf_get_vl_mff(const struct mf_field *mff,
+ const struct vl_mff_map *vl_mff_map)
+{
+ if (mff && mff->variable_len && vl_mff_map) {
+ return mf_get_vl_mff__(mff->id, vl_mff_map);
+ }
+
+ return NULL;
+}
+
/* Updates the tun_metadata mf_field in 'vl_mff_map' according to 'ttm'.
* This function is supposed to be invoked after tun_metadata_table_mod(). */
enum ofperr
@@ -2667,17 +2696,22 @@ mf_vl_mff_map_mod_from_tun_metadata(struct
vl_mff_map *vl_mff_map,
OVS_REQUIRES(vl_mff_map->mutex)
{
struct ofputil_tlv_map *tlv_map;
- struct mf_field *mf;
- unsigned int idx;
-
- switch (ttm->command) {
- case NXTTMC_ADD:
- LIST_FOR_EACH (tlv_map, list_node, &ttm->mappings) {
- idx = MFF_TUN_METADATA0 + tlv_map->index;
- if (idx >= MFF_TUN_METADATA0 + TUN_METADATA_NUM_OPTS) {
- return OFPERR_NXTTMFC_BAD_FIELD_IDX;
- }
+ if (ttm->command == NXTTMC_CLEAR) {
+ mf_vl_mff_map_clear(vl_mff_map);
+ return 0;
+ }
+
+ LIST_FOR_EACH (tlv_map, list_node, &ttm->mappings) {
+ unsigned int idx = MFF_TUN_METADATA0 + tlv_map->index;
+ struct mf_field *mf;
+
+ if (idx >= MFF_TUN_METADATA0 + TUN_METADATA_NUM_OPTS) {
+ return OFPERR_NXTTMFC_BAD_FIELD_IDX;
+ }
+
+ switch (ttm->command) {
+ case NXTTMC_ADD:
mf = xmalloc(sizeof *mf);
*mf = mf_fields[idx];
mf->n_bytes = tlv_map->option_len;
@@ -2685,73 +2719,30 @@ mf_vl_mff_map_mod_from_tun_metadata(struct
vl_mff_map *vl_mff_map,
mf->mapped = true;
cmap_insert(&vl_mff_map->cmap, &mf->cmap_node, mf_field_hash(idx));
- }
- break;
+ break;
- case NXTTMC_DELETE:
- LIST_FOR_EACH (tlv_map, list_node, &ttm->mappings) {
- idx = MFF_TUN_METADATA0 + tlv_map->index;
- if (idx >= MFF_TUN_METADATA0 + TUN_METADATA_NUM_OPTS) {
- return OFPERR_NXTTMFC_BAD_FIELD_IDX;
+ case NXTTMC_DELETE:
+ mf = mf_get_vl_mff__(idx, vl_mff_map);
+ if (mf) {
+ cmap_remove(&vl_mff_map->cmap, &mf->cmap_node,
+ mf_field_hash(idx));
+ ovsrcu_postpone(free, mf);
}
+ break;
- CMAP_FOR_EACH_WITH_HASH (mf, cmap_node, mf_field_hash(idx),
- &vl_mff_map->cmap) {
- if (mf->id == idx) {
- cmap_remove(&vl_mff_map->cmap, &mf->cmap_node,
- mf_field_hash(idx));
- ovsrcu_postpone(free, mf);
- break;
- }
- }
+ case NXTTMC_CLEAR:
+ default:
+ OVS_NOT_REACHED();
}
- break;
-
- case NXTTMC_CLEAR:
- mf_vl_mff_map_clear(vl_mff_map);
- break;
-
- default:
- OVS_NOT_REACHED();
}
return 0;
}
-/* If 'mff' is a variable length field, looks up 'vl_mff_map', returns a
- * pointer to the variable length meta-flow field corresponding to 'mff'.
- * Returns NULL if no mapping is existed for 'mff'. */
-const struct mf_field *
-mf_get_vl_mff(const struct mf_field *mff,
- const struct vl_mff_map *vl_mff_map)
-{
- const struct mf_field *field;
-
- if (mff && mff->variable_len && vl_mff_map) {
- const uint32_t id = mff->id;
-
- CMAP_FOR_EACH_WITH_HASH (field, cmap_node, mf_field_hash(id),
- &vl_mff_map->cmap) {
- if (field->id == id) {
- return field;
- }
- }
- }
-
- return NULL;
-}
-
/* Returns true if a variable length meta-flow field 'mff' is not mapped in
* the 'vl_mff_map'. */
bool
-mf_vl_mff_not_mapped(const struct mf_field *mff,
- const struct vl_mff_map *vl_mff_map)
+mf_vl_mff_mapped(const struct mf_field *mff, const struct vl_mff_map *map)
{
- if (mff && vl_mff_map) {
- if (mff->variable_len && !mff->mapped) {
- return true;
- }
- }
-
- return false;
+ return !(map && mff && mff->variable_len && !mff->mapped);
}
@@ -232,8 +232,8 @@ mf_nxm_header(enum mf_field_id id)
}
/* Returns the 32-bit OXM or NXM header to use for field 'mff'. If 'mff' is
- * a mapped variable length mf_field, update header with the configured
- * lenght of 'mff'. Returns 0 if 'mff' cannot be expressed with a 32-bit NXM
+ * a mapped variable length mf_field, update the header with the configured
+ * length of 'mff'. Returns 0 if 'mff' cannot be expressed with a 32-bit NXM
* or OXM header.*/
uint32_t
nxm_header_from_mff(const struct mf_field *mff)
@@ -339,8 +339,8 @@ nx_pull_header__(struct ofpbuf *b, bool allow_cookie,
VLOG_DBG_RL(&rl, "OXM header "NXM_HEADER_FMT" is unknown",
NXM_HEADER_ARGS(*header));
return OFPERR_OFPBMC_BAD_FIELD;
- } else if (mf_vl_mff_not_mapped(*field, vl_mff_map)) {
- return OFPERR_NXFMFC_INVALID_VL_MFF;
+ } else if (!mf_vl_mff_mapped(*field, vl_mff_map)) {
+ return OFPERR_NXFMFC_INVALID_TLV_FIELD;
}
}
@@ -1135,8 +1135,8 @@ decode_NXAST_RAW_OUTPUT_REG(const struct
nx_action_output_reg *naor,
output_reg->src.n_bits = nxm_decode_n_bits(naor->ofs_nbits);
output_reg->max_len = ntohs(naor->max_len);
- if (mf_vl_mff_not_mapped(output_reg->src.field, vl_mff_map)) {
- return OFPERR_NXFMFC_INVALID_VL_MFF;
+ if (!mf_vl_mff_mapped(output_reg->src.field, vl_mff_map)) {
+ return OFPERR_NXFMFC_INVALID_TLV_FIELD;
}
return mf_check_src(&output_reg->src, NULL);
@@ -1325,8 +1325,8 @@ decode_bundle(bool load, const struct
nx_action_bundle *nab,
bundle->dst.field = mf_from_nxm_header(ntohl(nab->dst), vl_mff_map);
bundle->dst.ofs = nxm_decode_ofs(nab->ofs_nbits);
bundle->dst.n_bits = nxm_decode_n_bits(nab->ofs_nbits);
- if (mf_vl_mff_not_mapped(bundle->dst.field, vl_mff_map)) {
- return OFPERR_NXFMFC_INVALID_VL_MFF;
+ if (!mf_vl_mff_mapped(bundle->dst.field, vl_mff_map)) {
+ return OFPERR_NXFMFC_INVALID_TLV_FIELD;
}
if (bundle->dst.n_bits < 16) {
@@ -2565,8 +2565,8 @@ decode_NXAST_RAW_REG_LOAD(const struct
nx_action_reg_load *narl,
dst.field = mf_from_nxm_header(ntohl(narl->dst), vl_mff_map);
dst.ofs = nxm_decode_ofs(narl->ofs_nbits);
dst.n_bits = nxm_decode_n_bits(narl->ofs_nbits);
- if (mf_vl_mff_not_mapped(dst.field, vl_mff_map)) {
- return OFPERR_NXFMFC_INVALID_VL_MFF;
+ if (!mf_vl_mff_mapped(dst.field, vl_mff_map)) {
+ return OFPERR_NXFMFC_INVALID_TLV_FIELD;
}
error = mf_check_dst(&dst, NULL);
@@ -4283,8 +4283,8 @@ get_subfield(int n_bits, const void **p, struct
mf_subfield *sf,
sf->field = mf_from_nxm_header(ntohl(get_be32(p)), vl_mff_map);
sf->ofs = ntohs(get_be16(p));
sf->n_bits = n_bits;
- if (mf_vl_mff_not_mapped(sf->field, vl_mff_map)) {
- return OFPERR_NXFMFC_INVALID_VL_MFF;
+ if (!mf_vl_mff_mapped(sf->field, vl_mff_map)) {
+ return OFPERR_NXFMFC_INVALID_TLV_FIELD;
}
return 0;
}
@@ -4664,8 +4664,8 @@ decode_NXAST_RAW_MULTIPATH(const struct
nx_action_multipath *nam,
mp->dst.ofs = nxm_decode_ofs(nam->ofs_nbits);
mp->dst.n_bits = nxm_decode_n_bits(nam->ofs_nbits);
- if (mf_vl_mff_not_mapped(mp->dst.field, vl_mff_map)) {
- return OFPERR_NXFMFC_INVALID_VL_MFF;
+ if (!mf_vl_mff_mapped(mp->dst.field, vl_mff_map)) {
+ return OFPERR_NXFMFC_INVALID_TLV_FIELD;
}
if (!flow_hash_fields_valid(mp->fields)) {
@@ -5324,8 +5324,8 @@ decode_ct_zone(const struct nx_action_conntrack *nac,
vl_mff_map);
out->zone_src.ofs = nxm_decode_ofs(nac->zone_ofs_nbits);
out->zone_src.n_bits = nxm_decode_n_bits(nac->zone_ofs_nbits);
- if (mf_vl_mff_not_mapped(out->zone_src.field, vl_mff_map)) {
- return OFPERR_NXFMFC_INVALID_VL_MFF;
+ if (!mf_vl_mff_mapped(out->zone_src.field, vl_mff_map)) {
+ return OFPERR_NXFMFC_INVALID_TLV_FIELD;
}
error = mf_check_src(&out->zone_src, NULL);
@@ -128,7 +128,7 @@ struct ofproto {
/* Tunnel TLV mapping table. */
OVSRCU_TYPE(struct tun_table *) metadata_tab;
- /* Variable length mf_field mapping map. Stores all variable length
+ /* Variable length mf_field mapping. Stores all configured variable length
* meta-flow fields (struct mf_field) in a switch. */
struct vl_mff_map vl_mff_map;
};
@@ -5707,7 +5707,7 @@ NXST_FLOW reply (xid=0x4):
dnl Check actions that may use tun_metadata
AT_CHECK([ovs-ofctl add-flow br0 "in_port=2
actions=move:tun_metadata1[[0..31]]->NXM_NX_REG0[[]]"], [1], [],
[stderr])
AT_CHECK([strip_xids < stderr | sed '/FLOW_MOD/,$d'], [0], [dnl
-OFPT_ERROR: NXFMFC_INVALID_VL_MFF
+OFPT_ERROR: NXFMFC_INVALID_TLV_FIELD
])