[ovs-dev] [PATCH 3/3] datapath: Tunnel port without destination IP.

Pravin B Shelar pshelar at nicira.com
Mon Oct 15 01:41:47 UTC 2012


Following patch allow port create without any parameters. This is
required for compatibility with future flow based tunneling
where each type would have single vport with all parameter
wild carded. So that all packet for all ports are received on
the port and same port is used for sending all traffic for
that tunnel type.

Signed-off-by: Pravin B Shelar <pshelar at nicira.com>
CC: Kyle Mestery <kmestery at cisco.com>
Cc: Simon Horman <horms at verge.net.au>
Cc: Jesse Gross <jesse at nicira.com>
---
 datapath/tunnel.c |   35 +++++++++++++++++++++++++----------
 1 file changed, 25 insertions(+), 10 deletions(-)

diff --git a/datapath/tunnel.c b/datapath/tunnel.c
index 72ead8f..104e182 100644
--- a/datapath/tunnel.c
+++ b/datapath/tunnel.c
@@ -100,6 +100,7 @@ static unsigned int key_remote_ports __read_mostly;
 static unsigned int key_multicast_ports __read_mostly;
 static unsigned int local_remote_ports __read_mostly;
 static unsigned int remote_ports __read_mostly;
+static unsigned int null_ports __read_mostly;
 static unsigned int multicast_ports __read_mostly;
 
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,36)
@@ -218,8 +219,10 @@ static unsigned int *find_port_pool(const struct tnl_mutable_config *mutable)
 			return &key_local_remote_ports;
 		else if (is_multicast)
 			return &key_multicast_ports;
-		else
+		else if (mutable->key.daddr)
 			return &key_remote_ports;
+		else
+			return &null_ports;
 	}
 }
 
@@ -364,6 +367,14 @@ struct vport *ovs_tnl_find_port(struct net *net, __be32 saddr, __be32 daddr,
 		}
 	}
 
+	if (null_ports) {
+		lookup.daddr = 0;
+		lookup.saddr = 0;
+		lookup.tunnel_type = tunnel_type;
+		vport = port_table_lookup(&lookup, mutable);
+		if (vport)
+			return vport;
+	}
 	return NULL;
 }
 
@@ -1435,8 +1446,10 @@ static int tnl_set_config(struct net *net, struct nlattr *options,
 	struct nlattr *a[OVS_TUNNEL_ATTR_MAX + 1];
 	int err;
 
+	port_key_set_net(&mutable->key, net);
+	mutable->key.tunnel_type = tnl_ops->tunnel_type;
 	if (!options)
-		return -EINVAL;
+		goto out;
 
 	err = nla_parse_nested(a, OVS_TUNNEL_ATTR_MAX, options, tnl_policy);
 	if (err)
@@ -1446,9 +1459,8 @@ static int tnl_set_config(struct net *net, struct nlattr *options,
 		return -EINVAL;
 
 	mutable->flags = nla_get_u32(a[OVS_TUNNEL_ATTR_FLAGS]) & TNL_F_PUBLIC;
-
-	port_key_set_net(&mutable->key, net);
 	mutable->key.daddr = nla_get_be32(a[OVS_TUNNEL_ATTR_DST_IPV4]);
+
 	if (a[OVS_TUNNEL_ATTR_SRC_IPV4]) {
 		if (ipv4_is_multicast(mutable->key.daddr))
 			return -EINVAL;
@@ -1465,7 +1477,6 @@ static int tnl_set_config(struct net *net, struct nlattr *options,
 	if (a[OVS_TUNNEL_ATTR_TTL])
 		mutable->ttl = nla_get_u8(a[OVS_TUNNEL_ATTR_TTL]);
 
-	mutable->key.tunnel_type = tnl_ops->tunnel_type;
 	if (!a[OVS_TUNNEL_ATTR_IN_KEY]) {
 		mutable->key.tunnel_type |= TNL_T_KEY_MATCH;
 		mutable->flags |= TNL_F_IN_KEY_MATCH;
@@ -1479,10 +1490,6 @@ static int tnl_set_config(struct net *net, struct nlattr *options,
 	else
 		mutable->out_key = nla_get_be64(a[OVS_TUNNEL_ATTR_OUT_KEY]);
 
-	old_vport = port_table_lookup(&mutable->key, &old_mutable);
-	if (old_vport && old_vport != cur_vport)
-		return -EEXIST;
-
 	mutable->mlink = 0;
 	if (ipv4_is_multicast(mutable->key.daddr)) {
 		struct net_device *dev;
@@ -1500,6 +1507,11 @@ static int tnl_set_config(struct net *net, struct nlattr *options,
 		ip_mc_inc_group(__in_dev_get_rtnl(dev), mutable->key.daddr);
 	}
 
+out:
+	old_vport = port_table_lookup(&mutable->key, &old_mutable);
+	if (old_vport && old_vport != cur_vport)
+		return -EEXIST;
+
 	return 0;
 }
 
@@ -1568,6 +1580,10 @@ int ovs_tnl_set_options(struct vport *vport, struct nlattr *options)
 	struct tnl_mutable_config *mutable;
 	int err;
 
+	old_mutable = rtnl_dereference(tnl_vport->mutable);
+	if (!old_mutable->key.daddr)
+		return -EINVAL;
+
 	mutable = kzalloc(sizeof(struct tnl_mutable_config), GFP_KERNEL);
 	if (!mutable) {
 		err = -ENOMEM;
@@ -1575,7 +1591,6 @@ int ovs_tnl_set_options(struct vport *vport, struct nlattr *options)
 	}
 
 	/* Copy fields whose values should be retained. */
-	old_mutable = rtnl_dereference(tnl_vport->mutable);
 	mutable->seq = old_mutable->seq + 1;
 	memcpy(mutable->eth_addr, old_mutable->eth_addr, ETH_ALEN);
 
-- 
1.7.10




More information about the dev mailing list