#include <linux/netfilter_bridge.h>
#include <linux/inetdevice.h>
#include <linux/list.h>
+#include <linux/rculist.h>
#include "openflow-netlink.h"
#include "datapath.h"
/* It's hard to imagine wanting more than one datapath, but... */
#define DP_MAX 32
-/* datapaths. Protected on the read side by rcu_read_lock, on the write side
- * by dp_mutex.
+/* Datapaths. Protected on the read side by rcu_read_lock, on the write side
+ * by dp_mutex. dp_mutex is almost completely redundant with genl_mutex
+ * maintained by the Generic Netlink code, but the timeout path needs mutual
+ * exclusion too.
*
* It is safe to access the datapath and net_bridge_port structures with just
- * the dp_mutex, but to access the chain you need to take the rcu_read_lock
- * also (because dp_mutex doesn't prevent flows from being destroyed).
+ * dp_mutex.
*/
static struct datapath *dps[DP_MAX];
-static DEFINE_MUTEX(dp_mutex);
+DEFINE_MUTEX(dp_mutex);
static int dp_maint_func(void *data);
static int send_port_status(struct net_bridge_port *p, uint8_t status);
}
/* Creates a new datapath numbered 'dp_idx'. Returns 0 for success or a
- * negative error code.
- *
- * Not called with any locks. */
+ * negative error code. */
static int new_dp(int dp_idx)
{
struct datapath *dp;
if (!try_module_get(THIS_MODULE))
return -ENODEV;
- mutex_lock(&dp_mutex);
- dp = rcu_dereference(dps[dp_idx]);
- if (dp != NULL) {
+ /* Exit early if a datapath with that number already exists. */
+ if (dps[dp_idx]) {
err = -EEXIST;
goto err_unlock;
}
if (IS_ERR(dp->dp_task))
goto err_destroy_chain;
- rcu_assign_pointer(dps[dp_idx], dp);
- mutex_unlock(&dp_mutex);
+ dps[dp_idx] = dp;
return 0;
err_free_dp:
kfree(dp);
err_unlock:
- mutex_unlock(&dp_mutex);
module_put(THIS_MODULE);
return err;
}
-/* Find and return a free port number under 'dp'. Called under dp_mutex. */
+/* Find and return a free port number under 'dp'. */
static int find_portno(struct datapath *dp)
{
int i;
return p;
}
-/* Called with dp_mutex. */
int add_switch_port(struct datapath *dp, struct net_device *dev)
{
struct net_bridge_port *p;
return 0;
}
-/* Delete 'p' from switch.
- * Called with dp_mutex. */
+/* Delete 'p' from switch. */
static int del_switch_port(struct net_bridge_port *p)
{
/* First drop references to device. */
return 0;
}
-/* Called with dp_mutex. */
static void del_dp(struct datapath *dp)
{
struct net_bridge_port *p, *n;
}
#else
/* NB: This has only been tested on 2.4.35 */
-
-/* Called without any locks (?) */
static void dp_frame_hook(struct sk_buff *skb)
{
struct net_bridge_port *p = skb->dev->br_port;
if (!info->attrs[DP_GENL_A_DP_IDX])
return -EINVAL;
- mutex_lock(&dp_mutex);
dp = dp_get(nla_get_u32((info->attrs[DP_GENL_A_DP_IDX])));
if (!dp)
err = -ENOENT;
del_dp(dp);
err = 0;
}
- mutex_unlock(&dp_mutex);
return err;
}
return -EINVAL;
/* Get datapath. */
- mutex_lock(&dp_mutex);
dp = dp_get(nla_get_u32(info->attrs[DP_GENL_A_DP_IDX]));
if (!dp) {
err = -ENOENT;
out_put:
dev_put(port);
out:
- mutex_unlock(&dp_mutex);
return err;
}
struct datapath *dp;
struct ofp_header *oh;
struct sender sender;
+ int err;
if (!info->attrs[DP_GENL_A_DP_IDX] || !va)
return -EINVAL;
sender.xid = oh->xid;
sender.pid = info->snd_pid;
sender.seq = info->snd_seq;
- return fwd_control_input(dp->chain, &sender,
- nla_data(va), nla_len(va));
+
+ mutex_lock(&dp_mutex);
+ err = fwd_control_input(dp->chain, &sender,
+ nla_data(va), nla_len(va));
+ mutex_unlock(&dp_mutex);
+ return err;
}
static struct nla_policy dp_genl_openflow_policy[DP_GENL_A_MAX + 1] = {