EXPORT_SYMBOL(dp_mutex);
static int dp_maint_func(void *data);
-static int update_port_status(struct net_bridge_port *p);
-static int send_port_status(struct net_bridge_port *p, uint8_t status);
+static void init_port_status(struct net_bridge_port *p);
static int dp_genl_openflow_done(struct netlink_callback *);
static struct net_bridge_port *new_nbp(struct datapath *,
struct net_device *, int port_no);
-static int del_switch_port(struct net_bridge_port *);
/* nla_shrink - reduce amount of space reserved by nla_reserve
* @skb: socket buffer from which to recover room
return 0;
err_destroy_local_port:
- del_switch_port(dp->local_port);
+ dp_del_switch_port(dp->local_port);
err_destroy_chain:
chain_destroy(dp->chain);
err_destroy_dp_dev:
if (IS_ERR(p))
return PTR_ERR(p);
- update_port_status(p);
+ init_port_status(p);
/* Notify the ctlpath that this port has been added */
- send_port_status(p, OFPPR_ADD);
+ dp_send_port_status(p, OFPPR_ADD);
return 0;
}
/* Delete 'p' from switch. */
-static int del_switch_port(struct net_bridge_port *p)
+int dp_del_switch_port(struct net_bridge_port *p)
{
/* First drop references to device. */
cancel_work_sync(&p->port_task);
synchronize_rcu();
/* Notify the ctlpath that this port no longer exists */
- send_port_status(p, OFPPR_DELETE);
+ dp_send_port_status(p, OFPPR_DELETE);
dev_put(p->dev);
kfree(p);
/* Drop references to DP. */
list_for_each_entry_safe (p, n, &dp->port_list, node)
- del_switch_port(p);
+ dp_del_switch_port(p);
rcu_assign_pointer(dps[dp->dp_idx], NULL);
/* Kill off local_port dev references from buffered packets that have
struct datapath *dp = (struct datapath *) data;
while (!kthread_should_stop()) {
- struct net_bridge_port *p;
-
- /* Check if port status has changed */
- rcu_read_lock();
- list_for_each_entry_rcu (p, &dp->port_list, node)
- if (update_port_status(p))
- send_port_status(p, OFPPR_MOD);
- rcu_read_unlock();
-
/* Timeout old entries */
chain_timeout(dp->chain);
msleep_interruptible(MAINT_SLEEP_MSECS);
return 0;
}
-/* Update the port status field of the bridge port. A non-zero return
- * value indicates some field has changed.
- *
- * NB: Callers of this function may hold the RCU read lock, so any
- * additional checks must not sleep.
- */
-static int
-update_port_status(struct net_bridge_port *p)
+/* Initialize the port status field of the bridge port. */
+static void
+init_port_status(struct net_bridge_port *p)
{
unsigned long int flags;
- uint32_t orig_status;
spin_lock_irqsave(&p->lock, flags);
- orig_status = p->status;
if (p->dev->flags & IFF_UP)
p->status &= ~OFPPFL_PORT_DOWN;
p->status |= OFPPFL_LINK_DOWN;
spin_unlock_irqrestore(&p->lock, flags);
- return (orig_status != p->status);
}
-static int
-send_port_status(struct net_bridge_port *p, uint8_t status)
+int
+dp_send_port_status(struct net_bridge_port *p, uint8_t status)
{
struct sk_buff *skb;
struct ofp_port_status *ops;
err = -ENOENT;
goto out_put;
}
- err = del_switch_port(port->br_port);
+ err = dp_del_switch_port(port->br_port);
}
out_put:
if (err)
goto error;
- err = dp_init_netlink();
+ err = register_netdevice_notifier(&dp_device_notifier);
if (err)
goto error_flow_exit;
+ err = dp_init_netlink();
+ if (err)
+ goto error_unreg_notifier;
+
/* Hook into callback used by the bridge to intercept packets.
* Parasites we are. */
if (br_handle_frame_hook)
return 0;
+error_unreg_notifier:
+ unregister_netdevice_notifier(&dp_device_notifier);
error_flow_exit:
flow_exit();
error:
{
fwd_exit();
dp_uninit_netlink();
+ unregister_netdevice_notifier(&dp_device_notifier);
flow_exit();
br_handle_frame_hook = NULL;
}
};
extern struct mutex dp_mutex;
+extern struct notifier_block dp_device_notifier;
+int dp_del_switch_port(struct net_bridge_port *);
int dp_output_port(struct datapath *, struct sk_buff *, int out_port,
int ignore_no_fwd);
int dp_output_control(struct datapath *, struct sk_buff *, uint32_t,
int dp_set_origin(struct datapath *, uint16_t, struct sk_buff *);
int dp_send_features_reply(struct datapath *, const struct sender *);
int dp_send_config_reply(struct datapath *, const struct sender *);
+int dp_send_port_status(struct net_bridge_port *p, uint8_t status);
int dp_send_flow_expired(struct datapath *, struct sw_flow *,
enum ofp_flow_expired_reason);
int dp_send_error_msg(struct datapath *, const struct sender *,
--- /dev/null
+/*
+ * Distributed under the terms of the GNU GPL version 2.
+ * Copyright (c) 2007, 2008 The Board of Trustees of The Leland
+ * Stanford Junior University
+ */
+
+/* Handle changes to managed devices */
+
+#include <linux/netdevice.h>
+
+#include "datapath.h"
+
+
+static int dp_device_event(struct notifier_block *unused, unsigned long event,
+ void *ptr)
+{
+ struct net_device *dev = ptr;
+ struct net_bridge_port *p = dev->br_port;
+ unsigned long int flags;
+ uint32_t orig_status;
+
+
+ /* Check if monitored port */
+ if (!p)
+ return NOTIFY_DONE;
+
+ spin_lock_irqsave(&p->lock, flags);
+ orig_status = p->status;
+
+ switch (event) {
+ case NETDEV_CHANGE:
+ if (netif_carrier_ok(p->dev))
+ p->status &= ~OFPPFL_LINK_DOWN;
+ else
+ p->status |= OFPPFL_LINK_DOWN;
+ break;
+
+ case NETDEV_DOWN:
+ p->status |= OFPPFL_PORT_DOWN;
+ break;
+
+ case NETDEV_UP:
+ p->status &= ~OFPPFL_PORT_DOWN;
+ break;
+
+ case NETDEV_UNREGISTER:
+ /* xxx Make sure this is correct */
+ spin_unlock_irqrestore(&p->lock, flags);
+ dp_del_switch_port(p);
+ return NOTIFY_DONE;
+ break;
+ }
+ spin_unlock_irqrestore(&p->lock, flags);
+
+ if (orig_status != p->status)
+ dp_send_port_status(p, OFPPR_MOD);
+
+ return NOTIFY_DONE;
+}
+
+struct notifier_block dp_device_notifier = {
+ .notifier_call = dp_device_event
+};