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