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.
/* 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;
}
#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