From: Ben Pfaff Date: Wed, 11 Mar 2009 18:13:01 +0000 (-0700) Subject: datapath: Refuse module load if an active bridge exists. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fb8dc8eff38ae583fa692111bd5b515e9e627f1d;p=openvswitch datapath: Refuse module load if an active bridge exists. Loading when an active bridge exists will cause an OOPS as soon as any packet is received on a bridged interface, because the datapath will attempt to interpret the bridge's "struct net_bridge_port" as a datapath "struct net_bridge_port", which is completely wrong. --- diff --git a/datapath/datapath.c b/datapath/datapath.c index 6aee55fa..851af969 100644 --- a/datapath/datapath.c +++ b/datapath/datapath.c @@ -1522,9 +1522,23 @@ static int __init dp_init(void) /* Hook into callback used by the bridge to intercept packets. * Parasites we are. */ - if (br_handle_frame_hook) + rtnl_lock(); + if (br_handle_frame_hook) { + struct net_device *dev; + for_each_netdev (&init_net, dev) { + if (!dev->br_port) + continue; + + rtnl_unlock(); + printk("openflow: must delete bridges " + "before loading\n"); + err = -EBUSY; + goto error_unreg_notifier; + } printk("openflow: hijacking bridge hook\n"); + } br_handle_frame_hook = dp_frame_hook; + rtnl_unlock(); return 0; diff --git a/datapath/linux-2.6/compat-2.6/include/linux/netdevice.h b/datapath/linux-2.6/compat-2.6/include/linux/netdevice.h index 015c6efd..042e30d7 100644 --- a/datapath/linux-2.6/compat-2.6/include/linux/netdevice.h +++ b/datapath/linux-2.6/compat-2.6/include/linux/netdevice.h @@ -17,4 +17,13 @@ struct net *dev_net(const struct net_device *dev) } #endif /* linux kernel < 2.6.26 */ +#ifndef for_each_netdev +/* Linux before 2.6.22 didn't have for_each_netdev at all. */ +#define for_each_netdev(net, d) for (d = dev_base; d; d = d->next) +#elif LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24) +/* Linux 2.6.24 added a network namespace pointer to the macro. */ +#undef for_each_netdev +#define for_each_netdev(net,d) list_for_each_entry(d, &dev_base_head, dev_list) +#endif + #endif