Commit b2da2b35 authored by Stephen Hemminger's avatar Stephen Hemminger Committed by Hideaki Yoshifuji

[BRIDGE]: Use list macros for ports.

parent 32003a7d
......@@ -115,8 +115,7 @@ static void br_flood(struct net_bridge *br, struct sk_buff *skb, int clone,
prev = NULL;
p = br->port_list;
while (p != NULL) {
list_for_each_entry(p, &br->port_list, list) {
if (should_deliver(p, skb)) {
if (prev != NULL) {
struct sk_buff *skb2;
......@@ -132,8 +131,6 @@ static void br_flood(struct net_bridge *br, struct sk_buff *skb, int clone,
prev = p;
}
p = p->next;
}
if (prev != NULL) {
......
......@@ -39,42 +39,31 @@ static int br_initial_port_cost(struct net_device *dev)
}
/* called under BR_NETPROTO_LOCK and bridge lock */
static int __br_del_if(struct net_bridge *br, struct net_device *dev)
static void del_nbp(struct net_bridge_port *p)
{
struct net_bridge_port *p;
struct net_bridge_port **pptr;
if ((p = dev->br_port) == NULL)
return -EINVAL;
struct net_device *dev = p->dev;
br_stp_disable_port(p);
dev_set_promiscuity(dev, -1);
dev->br_port = NULL;
pptr = &br->port_list;
while (*pptr != NULL) {
if (*pptr == p) {
*pptr = p->next;
break;
}
pptr = &((*pptr)->next);
}
list_del(&p->list);
br_fdb_delete_by_port(br, p);
br_fdb_delete_by_port(p->br, p);
kfree(p);
dev_put(dev);
return 0;
}
static void del_ifs(struct net_bridge *br)
{
struct list_head *p, *n;
br_write_lock_bh(BR_NETPROTO_LOCK);
write_lock(&br->lock);
while (br->port_list != NULL)
__br_del_if(br, br->port_list->dev);
list_for_each_safe(p, n, &br->port_list) {
del_nbp(list_entry(p, struct net_bridge_port, list));
}
write_unlock(&br->lock);
br_write_unlock_bh(BR_NETPROTO_LOCK);
}
......@@ -99,6 +88,7 @@ static struct net_bridge *new_nb(const char *name)
br_dev_setup(dev);
br->lock = RW_LOCK_UNLOCKED;
INIT_LIST_HEAD(&br->port_list);
br->hash_lock = RW_LOCK_UNLOCKED;
br->bridge_id.prio[0] = 0x80;
......@@ -155,8 +145,7 @@ static struct net_bridge_port *new_nbp(struct net_bridge *br, struct net_device
br_init_port(p);
p->state = BR_STATE_DISABLED;
p->next = br->port_list;
br->port_list = p;
list_add(&p->list, &br->port_list);
return p;
}
......@@ -238,12 +227,17 @@ int br_add_if(struct net_bridge *br, struct net_device *dev)
int br_del_if(struct net_bridge *br, struct net_device *dev)
{
int retval;
struct net_bridge_port *p;
int retval = 0;
br_write_lock_bh(BR_NETPROTO_LOCK);
write_lock(&br->lock);
retval = __br_del_if(br, dev);
br_stp_recalculate_bridge_id(br);
if ((p = dev->br_port) == NULL || p->br != br)
retval = -EINVAL;
else {
del_nbp(p);
br_stp_recalculate_bridge_id(br);
}
write_unlock(&br->lock);
br_write_unlock_bh(BR_NETPROTO_LOCK);
......@@ -270,10 +264,8 @@ void br_get_port_ifindices(struct net_bridge *br, int *ifindices)
struct net_bridge_port *p;
read_lock(&br->lock);
p = br->port_list;
while (p != NULL) {
list_for_each_entry(p, &br->port_list, list) {
ifindices[p->port_no] = p->dev->ifindex;
p = p->next;
}
read_unlock(&br->lock);
}
......
......@@ -55,9 +55,9 @@ struct net_bridge_fdb_entry
struct net_bridge_port
{
struct net_bridge_port *next;
struct net_bridge *br;
struct net_device *dev;
struct list_head list;
int port_no;
/* STP */
......@@ -80,7 +80,7 @@ struct net_bridge_port
struct net_bridge
{
rwlock_t lock;
struct net_bridge_port *port_list;
struct list_head port_list;
struct net_device dev;
struct net_device_stats statistics;
rwlock_t hash_lock;
......
......@@ -40,12 +40,9 @@ struct net_bridge_port *br_get_port(struct net_bridge *br, int port_no)
{
struct net_bridge_port *p;
p = br->port_list;
while (p != NULL) {
list_for_each_entry(p, &br->port_list, list) {
if (p->port_no == port_no)
return p;
p = p->next;
}
return NULL;
......@@ -109,12 +106,10 @@ static void br_root_selection(struct net_bridge *br)
root_port = 0;
p = br->port_list;
while (p != NULL) {
list_for_each_entry(p, &br->port_list, list) {
if (br_should_become_root_port(p, root_port))
root_port = p->port_no;
p = p->next;
}
br->root_port = root_port;
......@@ -241,13 +236,11 @@ static void br_designated_port_selection(struct net_bridge *br)
{
struct net_bridge_port *p;
p = br->port_list;
while (p != NULL) {
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);
p = p->next;
}
}
......@@ -313,13 +306,10 @@ void br_config_bpdu_generation(struct net_bridge *br)
{
struct net_bridge_port *p;
p = br->port_list;
while (p != NULL) {
list_for_each_entry(p, &br->port_list, list) {
if (p->state != BR_STATE_DISABLED &&
br_is_designated_port(p))
br_transmit_config(p);
p = p->next;
}
}
......@@ -391,8 +381,7 @@ void br_port_state_selection(struct net_bridge *br)
{
struct net_bridge_port *p;
p = br->port_list;
while (p != NULL) {
list_for_each_entry(p, &br->port_list, list) {
if (p->state != BR_STATE_DISABLED) {
if (p->port_no == br->root_port) {
p->config_pending = 0;
......@@ -407,8 +396,6 @@ void br_port_state_selection(struct net_bridge *br)
br_make_blocking(p);
}
}
p = p->next;
}
}
......
......@@ -53,12 +53,9 @@ void br_stp_enable_bridge(struct net_bridge *br)
br_timer_set(&br->hello_timer, jiffies);
br_config_bpdu_generation(br);
p = br->port_list;
while (p != NULL) {
list_for_each_entry(p, &br->port_list, list) {
if (p->dev->flags & IFF_UP)
br_stp_enable_port(p);
p = p->next;
}
br_timer_set(&br->gc_timer, jiffies);
......@@ -78,12 +75,9 @@ void br_stp_disable_bridge(struct net_bridge *br)
br_timer_clear(&br->gc_timer);
br_fdb_cleanup(br);
p = br->port_list;
while (p != NULL) {
list_for_each_entry(p, &br->port_list, list) {
if (p->state != BR_STATE_DISABLED)
br_stp_disable_port(p);
p = p->next;
}
write_unlock(&br->lock);
......@@ -135,15 +129,13 @@ static void br_stp_change_bridge_id(struct net_bridge *br, unsigned char *addr)
memcpy(br->bridge_id.addr, addr, ETH_ALEN);
memcpy(br->dev.dev_addr, addr, ETH_ALEN);
p = br->port_list;
while (p != NULL) {
list_for_each_entry(p, &br->port_list, list) {
if (!memcmp(p->designated_bridge.addr, oldaddr, ETH_ALEN))
memcpy(p->designated_bridge.addr, addr, ETH_ALEN);
if (!memcmp(p->designated_root.addr, oldaddr, ETH_ALEN))
memcpy(p->designated_root.addr, addr, ETH_ALEN);
p = p->next;
}
br_configuration_update(br);
......@@ -162,13 +154,11 @@ void br_stp_recalculate_bridge_id(struct net_bridge *br)
addr = br_mac_zero;
p = br->port_list;
while (p != NULL) {
list_for_each_entry(p, &br->port_list, list) {
if (addr == br_mac_zero ||
memcmp(p->dev->dev_addr, addr, ETH_ALEN) < 0)
addr = p->dev->dev_addr;
p = p->next;
}
if (memcmp(br->bridge_id.addr, addr, ETH_ALEN))
......@@ -183,15 +173,13 @@ void br_stp_set_bridge_priority(struct net_bridge *br, int newprio)
wasroot = br_is_root_bridge(br);
p = br->port_list;
while (p != NULL) {
list_for_each_entry(p, &br->port_list, list) {
if (p->state != BR_STATE_DISABLED &&
br_is_designated_port(p)) {
p->designated_bridge.prio[0] = (newprio >> 8) & 0xFF;
p->designated_bridge.prio[1] = newprio & 0xFF;
}
p = p->next;
}
br->bridge_id.prio[0] = (newprio >> 8) & 0xFF;
......
......@@ -32,13 +32,10 @@ static int br_is_designated_for_some_port(struct net_bridge *br)
{
struct net_bridge_port *p;
p = br->port_list;
while (p != NULL) {
list_for_each_entry(p, &br->port_list, list) {
if (p->state != BR_STATE_DISABLED &&
!memcmp(&p->designated_bridge, &br->bridge_id, 8))
return 1;
p = p->next;
}
return 0;
......@@ -162,12 +159,9 @@ static void br_check_timers(struct net_bridge *br)
br_topology_change_timer_expired(br);
}
p = br->port_list;
while (p != NULL) {
list_for_each_entry(p, &br->port_list, list) {
if (p->state != BR_STATE_DISABLED)
br_check_port_timers(p);
p = p->next;
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment