summaryrefslogtreecommitdiff
path: root/include/openvswitch/meta-flow.h
diff options
context:
space:
mode:
authorYi-Hung Wei <yihung.wei@gmail.com>2017-01-20 15:12:21 -0800
committerJoe Stringer <joe@ovn.org>2017-02-01 13:05:34 -0800
commit04f48a68c42851348ad0ff6105c79b32f26c050a (patch)
treecc0d424c83e34a3bc66b5d8ea8acfc5780b4b011 /include/openvswitch/meta-flow.h
parentdc2dab6e6de50a6b6ef25eb2cf761fae3a3a33a7 (diff)
downloadopenvswitch-04f48a68c42851348ad0ff6105c79b32f26c050a.tar.gz
ofp-actions: Fix variable length meta-flow OXMs.
Previously, if a flow action that involves a tunnel metadata meta-flow field is dumped from vswitchd, the replied field length in the OXM header is filled with the maximum possible field length, instead of the length configured in the tunnel TLV mapping table. To solve this issue, this patch introduces the following changes. In order to maintain the correct length of variable length mf_fields (i.e. tun_metadata), this patch creates a per-switch based map (struct vl_mff_map) that hosts the variable length mf_fields. This map is updated when a controller adds/deletes tlv-mapping entries to/from a switch. Although the per-swtch based vl_mff_map only hosts tun_metadata for now, it is able to support new variable length mf_fields in the future. With this commit, when a switch decodes a flow action with mf_field, the switch firstly looks up the global mf_fields map to identify the mf_field type. For the variable length mf_fields, the switch uses the vl_mff_map to get the configured mf_field entries. By lookig up vl_mff_map, the switch can check if the added flow action access beyond the configured size of a variable length mf_field, and the switch reports an ofperr if the controller adds a flow with unmapped variable length mf_field. Later on, when a controller request flows from the switch, with the per-switch based mf_fields, the switch will encode the OXM header with correct length for variable length mf_fields. To use the vl_mff_map for decoding flow actions, extract-ofp-actions is updated to pass the vl_mff_map to the required action decoding functions. Also, a new error code is introduced to identify a flow with an invalid variable length mf_field. Moreover, a testcase is added to prevent future regressions. Committer notes: - Factor out common code - Style fixups - Rename OFPERR_NXFMFC_INVALID_VL_MFF -> OFPERR_NXFMFC_INVALID_TLV_FIELD VMWare-BZ: #1768370 Reported-by: Harold Lim <haroldl@vmware.com> Suggested-by: Joe Stringer <joe@ovn.org> Suggested-by: Jarno Rajahalme <jarno@ovn.org> Signed-off-by: Yi-Hung Wei <yihung.wei@gmail.com> Signed-off-by: Joe Stringer <joe@ovn.org>
Diffstat (limited to 'include/openvswitch/meta-flow.h')
-rw-r--r--include/openvswitch/meta-flow.h26
1 files changed, 25 insertions, 1 deletions
diff --git a/include/openvswitch/meta-flow.h b/include/openvswitch/meta-flow.h
index 6db4bcc62..d5c097179 100644
--- a/include/openvswitch/meta-flow.h
+++ b/include/openvswitch/meta-flow.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016 Nicira, Inc.
+ * Copyright (c) 2011-2017 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,13 +23,16 @@
#include <sys/types.h>
#include <netinet/in.h>
#include <netinet/ip6.h>
+#include "cmap.h"
#include "openvswitch/flow.h"
#include "openvswitch/ofp-errors.h"
#include "openvswitch/packets.h"
+#include "openvswitch/thread.h"
#include "openvswitch/util.h"
struct ds;
struct match;
+struct ofputil_tlv_table_mod;
/* Open vSwitch fields
* ===================
@@ -1751,6 +1754,7 @@ struct mf_field {
enum mf_string string;
enum mf_prereqs prereqs;
bool writable; /* May be written by actions? */
+ bool mapped; /* Variable length mf_field is mapped. */
/* Usable protocols.
*
@@ -1770,6 +1774,9 @@ struct mf_field {
int flow_be32ofs; /* Field's be32 offset in "struct flow", if prefix tree
* lookup is supported for the field, or -1. */
+
+ /* For variable length mf_fields only. In ofproto->vl_mff_map->cmap. */
+ struct cmap_node cmap_node;
};
/* The representation of a field's value. */
@@ -1846,6 +1853,14 @@ union mf_subvalue {
};
BUILD_ASSERT_DECL(sizeof(union mf_value) == sizeof (union mf_subvalue));
+/* Variable length mf_fields mapping map. This is a single writer,
+ * multiple-reader hash table that a writer must hold the following mutex
+ * to access this map. */
+struct vl_mff_map {
+ struct cmap cmap; /* Contains 'struct mf_field' */
+ struct ovs_mutex mutex;
+};
+
bool mf_subvalue_intersect(const union mf_subvalue *a_value,
const union mf_subvalue *a_mask,
const union mf_subvalue *b_value,
@@ -1973,4 +1988,13 @@ void mf_format_subvalue(const union mf_subvalue *subvalue, struct ds *s);
void field_array_set(enum mf_field_id id, const union mf_value *,
struct field_array *);
+/* Variable length fields. */
+void mf_vl_mff_map_clear(struct vl_mff_map *vl_mff_map)
+ OVS_REQUIRES(vl_mff_map->mutex);
+enum ofperr mf_vl_mff_map_mod_from_tun_metadata(
+ struct vl_mff_map *vl_mff_map, const struct ofputil_tlv_table_mod *)
+ 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_invalid(const struct mf_field *, const struct vl_mff_map *);
#endif /* meta-flow.h */