转:http://blog.csdn.net/nerdx/article/details/12279949
-
-
-
-
-
-
1.1 static int br_dev_open(struct net_device *dev)
-
{
-
-
netif_start_queue(dev);
-
-
br_stp_enable_bridge(dev->priv);
-
-
return 0;
-
}
-
-
-
-
-
-
-
-
1.2 void br_stp_enable_bridge(struct net_bridge *br)
-
{
-
struct net_bridge_port *p;
-
-
spin_lock_bh(&br->lock);
-
mod_timer(&br->hello_timer, jiffies + br->hello_time);
-
br_config_bpdu_generation(br);
-
-
list_for_each_entry(p, &br->port_list, list) {
-
if ((p->dev->flags & IFF_UP) && netif_carrier_ok(p->dev))
-
br_stp_enable_port(p);
-
}
-
spin_unlock_bh(&br->lock);
-
}
-
-
-
-
-
-
1.3 void br_config_bpdu_generation(struct net_bridge *br)
-
{
-
struct net_bridge_port *p;
-
-
list_for_each_entry(p, &br->port_list, list) {
-
if (p->state != BR_STATE_DISABLED &&
-
br_is_designated_port(p))
-
br_transmit_config(p);
-
}
-
}
-
-
-
-
-
1.4 void br_stp_enable_port(struct net_bridge_port *p)
-
{
-
br_init_port(p);
-
br_port_state_selection(p->br);
-
}
-
-
-
-
-
-
-
-
1.5 void br_init_port(struct net_bridge_port *p)
-
{
-
p->port_id = br_make_port_id(p->priority, p->port_no);
-
br_become_designated_port(p);
-
p->state = BR_STATE_BLOCKING;
-
p->topology_change_ack = 0;
-
p->config_pending = 0;
-
-
br_stp_port_timer_init(p);
-
}
-
-
-
-
-
-
-
2.1 static int br_dev_stop(struct net_device *dev)
-
{
-
br_stp_disable_bridge(dev->priv);
-
-
netif_stop_queue(dev);
-
-
return 0;
-
}
-
-
-
-
-
-
-
-
2.2 void br_stp_disable_bridge(struct net_bridge *br)
-
{
-
struct net_bridge_port *p;
-
-
spin_lock(&br->lock);
-
list_for_each_entry(p, &br->port_list, list) {
-
if (p->state != BR_STATE_DISABLED)
-
br_stp_disable_port(p);
-
-
}
-
-
br->topology_change = 0;
-
br->topology_change_detected = 0;
-
spin_unlock(&br->lock);
-
-
del_timer_sync(&br->hello_timer);
-
del_timer_sync(&br->topology_change_timer);
-
del_timer_sync(&br->tcn_timer);
-
}
-
-
-
-
-
-
-
-
-
-
2.3 void br_stp_disable_port(struct net_bridge_port *p)
-
{
-
struct net_bridge *br;
-
int wasroot;
-
-
br = p->br;
-
printk(KERN_INFO "%s: port %i(%s) entering %s state\n",
-
br->dev->name, p->port_no, p->dev->name, "disabled");
-
-
wasroot = br_is_root_bridge(br);
-
br_become_designated_port(p);
-
p->state = BR_STATE_DISABLED;
-
p->topology_change_ack = 0;
-
p->config_pending = 0;
-
-
-
del_timer(&p->message_age_timer);
-
del_timer(&p->forward_delay_timer);
-
del_timer(&p->hold_timer);
-
-
br_configuration_update(br);
-
-
br_port_state_selection(br);
-
-
if (br_is_root_bridge(br) && !wasroot)
-
br_become_root_bridge(br);
-
}
-
-
-
-
-
-
-
-
-
2.4 void br_become_root_bridge(struct net_bridge *br)
-
{
-
br->max_age = br->bridge_max_age;
-
br->hello_time = br->bridge_hello_time;
-
br->forward_delay = br->bridge_forward_delay;
-
br_topology_change_detection(br);
-
del_timer(&br->tcn_timer);
-
-
if (br->dev->flags & IFF_UP) {
-
br_config_bpdu_generation(br);
-
mod_timer(&br->hello_timer, jiffies + br->hello_time);
-
}
-
}
-
-
-
-
-
-
-
-
-
-
-
2.5 void br_topology_change_detection(struct net_bridge *br)
-
{
-
int isroot = br_is_root_bridge(br);
-
-
if (isroot) {
-
br->topology_change = 1;
-
mod_timer(&br->topology_change_timer, jiffies
-
+ br->bridge_forward_delay + br->bridge_max_age);
-
} else if (!br->topology_change_detected) {
-
br_transmit_tcn(br);
-
mod_timer(&br->tcn_timer, jiffies + br->bridge_hello_time);
-
}
-
-
br->topology_change_detected = 1;
-
}
-
阅读(716) | 评论(0) | 转发(0) |