转:http://blog.csdn.net/nerdx/article/details/12223295
-
-
-
-
-
-
-
1.1 static int __init br_init(void)
-
{
-
-
br_fdb_init();
-
-
...
-
-
-
brioctl_set(br_ioctl_deviceless_stub);
-
-
br_handle_frame_hook = br_handle_frame;
-
-
-
register_netdevice_notifier(&br_device_notifier);
-
-
return 0;
-
}
-
-
-
-
1.2 struct notifier_block br_device_notifier = {
-
.notifier_call = br_device_event
-
};
-
-
-
-
-
-
-
-
-
-
1.3 static int br_device_event(struct notifier_block *unused, unsigned long event, void *ptr)
-
{
-
struct net_device *dev = ptr;
-
struct net_bridge_port *p = dev->br_port;
-
struct net_bridge *br;
-
-
if (p == NULL)
-
return NOTIFY_DONE;
-
-
br = p->br;
-
-
spin_lock_bh(&br->lock);
-
switch (event) {
-
case NETDEV_CHANGEMTU:
-
dev_set_mtu(br->dev, br_min_mtu(br));
-
break;
-
-
case NETDEV_CHANGEADDR:
-
br_fdb_changeaddr(p, dev->dev_addr);
-
br_stp_recalculate_bridge_id(br);
-
break;
-
-
case NETDEV_CHANGE:
-
if (!(br->dev->flags & IFF_UP))
-
break;
-
-
if (netif_carrier_ok(dev)) {
-
if (p->state == BR_STATE_DISABLED)
-
br_stp_enable_port(p);
-
} else {
-
if (p->state != BR_STATE_DISABLED)
-
br_stp_disable_port(p);
-
}
-
break;
-
-
case NETDEV_DOWN:
-
if (br->dev->flags & IFF_UP)
-
br_stp_disable_port(p);
-
break;
-
-
case NETDEV_UP:
-
if (netif_carrier_ok(dev) && (br->dev->flags & IFF_UP))
-
br_stp_enable_port(p);
-
break;
-
-
case NETDEV_UNREGISTER:
-
spin_unlock_bh(&br->lock);
-
br_del_if(br, dev);
-
goto done;
-
}
-
spin_unlock_bh(&br->lock);
-
-
done:
-
return NOTIFY_DONE;
-
}
-
-
-
2.1 void brioctl_set(int (*hook)(unsigned int, void __user *))
-
{
-
down(&br_ioctl_mutex);
-
br_ioctl_hook = hook;
-
up(&br_ioctl_mutex);
-
}
阅读(789) | 评论(0) | 转发(0) |