转:http://blog.csdn.net/nerdx/article/details/12280945
-
-
-
-
-
1.1 void br_configuration_update(struct net_bridge *br)
-
{
-
br_root_selection(br);
-
br_designated_port_selection(br);
-
}
-
-
-
-
-
-
-
-
-
-
-
1.2 static void br_root_selection(struct net_bridge *br)
-
{
-
struct net_bridge_port *p;
-
u16 root_port = 0;
-
-
list_for_each_entry(p, &br->port_list, list) {
-
if (br_should_become_root_port(p, root_port))
-
root_port = p->port_no;
-
}
-
-
br->root_port = root_port;
-
-
if (!root_port) {
-
br->designated_root = br->bridge_id;
-
br->root_path_cost = 0;
-
} else {
-
p = br_get_port(br, root_port);
-
br->designated_root = p->designated_root;
-
br->root_path_cost = p->designated_cost + p->path_cost;
-
}
-
}
-
-
-
-
-
-
-
-
-
-
1.3 static int br_should_become_root_port(const struct net_bridge_port *p,
-
u16 root_port)
-
{
-
struct net_bridge *br;
-
struct net_bridge_port *rp;
-
int t;
-
-
br = p->br;
-
if (p->state == BR_STATE_DISABLED ||
-
br_is_designated_port(p))
-
return 0;
-
-
if (memcmp(&br->bridge_id, &p->designated_root, 8) <= 0)
-
return 0;
-
-
if (!root_port)
-
return 1;
-
-
rp = br_get_port(br, root_port);
-
-
t = memcmp(&p->designated_root, &rp->designated_root, 8);
-
if (t < 0)
-
return 1;
-
else if (t > 0)
-
return 0;
-
-
if (p->designated_cost + p->path_cost <
-
rp->designated_cost + rp->path_cost)
-
return 1;
-
else if (p->designated_cost + p->path_cost >
-
rp->designated_cost + rp->path_cost)
-
return 0;
-
-
t = memcmp(&p->designated_bridge, &rp->designated_bridge, 8);
-
if (t < 0)
-
return 1;
-
else if (t > 0)
-
return 0;
-
-
if (p->designated_port < rp->designated_port)
-
return 1;
-
else if (p->designated_port > rp->designated_port)
-
return 0;
-
-
if (p->port_id < rp->port_id)
-
return 1;
-
-
return 0;
-
}
-
-
-
-
-
-
-
-
1.4 static void br_designated_port_selection(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_should_become_designated_port(p))
-
br_become_designated_port(p);
-
-
}
-
}
-
-
-
-
-
-
-
1.5 static int br_should_become_designated_port(const struct net_bridge_port *p)
-
{
-
struct net_bridge *br;
-
int t;
-
-
br = p->br;
-
if (br_is_designated_port(p))
-
return 1;
-
-
if (memcmp(&p->designated_root, &br->designated_root, 8))
-
return 1;
-
-
if (br->root_path_cost < p->designated_cost)
-
return 1;
-
else if (br->root_path_cost > p->designated_cost)
-
return 0;
-
-
t = memcmp(&br->bridge_id, &p->designated_bridge, 8);
-
if (t < 0)
-
return 1;
-
else if (t > 0)
-
return 0;
-
-
if (p->port_id < p->designated_port)
-
return 1;
-
-
return 0;
-
}
-
阅读(757) | 评论(0) | 转发(0) |