[ovs-dev] [RFC v2] datapath/flow_netlink: Avoid wildcarding tunnel key with disabled megaflows

Daniele Di Proietto ddiproietto at vmware.com
Tue Jul 15 18:41:29 UTC 2014


If the userspace wants to match on a flow with some tunnel attributesset to 0,
it simply omits them in the netlink attributes stream.
Since our wildcarding logic (when megaflows are disabled) is based on the
attributes in the netlink stream, we set our mask incorrectly.

This commit adds a check to detect if the userspace wants to match on a tunnel,
in which case we simply unwildcard the whole tun_key

Reported-by: Andy Zhou <azhou at nicira.com>
Signed-off-by: Daniele Di Proietto <ddiproietto at vmware.com>
---
v2:
using memset() instead of setting individual members, as suggested by Andy
---
 datapath/flow_netlink.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/datapath/flow_netlink.c b/datapath/flow_netlink.c
index 5f975a1..7c5175d 100644
--- a/datapath/flow_netlink.c
+++ b/datapath/flow_netlink.c
@@ -79,10 +79,15 @@ static void update_range__(struct sw_flow_match *match,
 		range->end = end;
 }
 
-#define SW_FLOW_KEY_PUT(match, field, value, is_mask) \
+#define SW_FLOW_KEY_UPDATE_RANGE(match, field, is_mask) \
 	do { \
 		update_range__(match, offsetof(struct sw_flow_key, field),  \
 				     sizeof((match)->key->field), is_mask); \
+	} while (0)
+
+#define SW_FLOW_KEY_PUT(match, field, value, is_mask) \
+	do { \
+		SW_FLOW_KEY_UPDATE_RANGE(match, field, is_mask);     \
 		if (is_mask) {						    \
 			if ((match)->mask)				    \
 				(match)->mask->key.field = value;	    \
@@ -912,6 +917,14 @@ int ovs_nla_get_match(struct sw_flow_match *match,
 
 		mask_set_nlattr(newmask, 0xff);
 
+		/* The userspace does not send tunnel attributes that are 0,
+		 * but we should not wildcard them nonetheless. */
+		if (match->key->tun_key.ipv4_dst) {
+			memset(&match->mask->key.tun_key, 0xff,
+			       sizeof(match->mask->key.tun_key));
+			SW_FLOW_KEY_UPDATE_RANGE(match, tun_key, true);
+		}
+
 		mask = newmask;
 	}
 
-- 
2.0.0




More information about the dev mailing list