Commit 5b036bf3 authored by Stephen Hemminger's avatar Stephen Hemminger Committed by David S. Miller

[BRIDGE]: Bridge using alloc_netdev.

parent 2022e705
...@@ -110,10 +110,6 @@ static int br_dev_accept_fastpath(struct net_device *dev, struct dst_entry *dst) ...@@ -110,10 +110,6 @@ static int br_dev_accept_fastpath(struct net_device *dev, struct dst_entry *dst)
return -1; return -1;
} }
static void br_dev_destruct(struct net_device *dev)
{
kfree(dev->priv);
}
void br_dev_setup(struct net_device *dev) void br_dev_setup(struct net_device *dev)
{ {
...@@ -124,10 +120,13 @@ void br_dev_setup(struct net_device *dev) ...@@ -124,10 +120,13 @@ void br_dev_setup(struct net_device *dev)
dev->hard_start_xmit = br_dev_xmit; dev->hard_start_xmit = br_dev_xmit;
dev->open = br_dev_open; dev->open = br_dev_open;
dev->set_multicast_list = br_dev_set_multicast_list; dev->set_multicast_list = br_dev_set_multicast_list;
dev->destructor = br_dev_destruct; dev->destructor = (void (*)(struct net_device *))kfree;
SET_MODULE_OWNER(dev); SET_MODULE_OWNER(dev);
dev->stop = br_dev_stop; dev->stop = br_dev_stop;
dev->accept_fastpath = br_dev_accept_fastpath; dev->accept_fastpath = br_dev_accept_fastpath;
dev->tx_queue_len = 0; dev->tx_queue_len = 0;
dev->set_mac_address = NULL; dev->set_mac_address = NULL;
dev->priv_flags = IFF_EBRIDGE;
ether_setup(dev);
} }
...@@ -78,17 +78,14 @@ static struct net_bridge *new_nb(const char *name) ...@@ -78,17 +78,14 @@ static struct net_bridge *new_nb(const char *name)
struct net_bridge *br; struct net_bridge *br;
struct net_device *dev; struct net_device *dev;
if ((br = kmalloc(sizeof(*br), GFP_KERNEL)) == NULL) dev = alloc_netdev(sizeof(struct net_bridge), name,
br_dev_setup);
if (!dev)
return NULL; return NULL;
memset(br, 0, sizeof(*br)); br = dev->priv;
dev = &br->dev; br->dev = dev;
strlcpy(dev->name, name, sizeof(dev->name));
dev->priv = br;
dev->priv_flags = IFF_EBRIDGE;
ether_setup(dev);
br_dev_setup(dev);
br->lock = SPIN_LOCK_UNLOCKED; br->lock = SPIN_LOCK_UNLOCKED;
INIT_LIST_HEAD(&br->port_list); INIT_LIST_HEAD(&br->port_list);
...@@ -159,9 +156,9 @@ int br_add_bridge(const char *name) ...@@ -159,9 +156,9 @@ int br_add_bridge(const char *name)
if ((br = new_nb(name)) == NULL) if ((br = new_nb(name)) == NULL)
return -ENOMEM; return -ENOMEM;
ret = register_netdev(&br->dev); ret = register_netdev(br->dev);
if (ret) if (ret)
kfree(br); kfree(br->dev);
return ret; return ret;
} }
...@@ -219,7 +216,7 @@ int br_add_if(struct net_bridge *br, struct net_device *dev) ...@@ -219,7 +216,7 @@ int br_add_if(struct net_bridge *br, struct net_device *dev)
br_stp_recalculate_bridge_id(br); br_stp_recalculate_bridge_id(br);
br_fdb_insert(br, p, dev->dev_addr, 1); br_fdb_insert(br, p, dev->dev_addr, 1);
if ((br->dev.flags & IFF_UP) && (dev->flags & IFF_UP)) if ((br->dev->flags & IFF_UP) && (dev->flags & IFF_UP))
br_stp_enable_port(p); br_stp_enable_port(p);
spin_unlock_bh(&br->lock); spin_unlock_bh(&br->lock);
......
...@@ -40,7 +40,7 @@ static void br_pass_frame_up(struct net_bridge *br, struct sk_buff *skb) ...@@ -40,7 +40,7 @@ static void br_pass_frame_up(struct net_bridge *br, struct sk_buff *skb)
br->statistics.rx_bytes += skb->len; br->statistics.rx_bytes += skb->len;
indev = skb->dev; indev = skb->dev;
skb->dev = &br->dev; skb->dev = br->dev;
NF_HOOK(PF_BRIDGE, NF_BR_LOCAL_IN, skb, indev, NULL, NF_HOOK(PF_BRIDGE, NF_BR_LOCAL_IN, skb, indev, NULL,
br_pass_frame_up_finish); br_pass_frame_up_finish);
...@@ -67,7 +67,7 @@ int br_handle_frame_finish(struct sk_buff *skb) ...@@ -67,7 +67,7 @@ int br_handle_frame_finish(struct sk_buff *skb)
br = p->br; br = p->br;
passedup = 0; passedup = 0;
if (br->dev.flags & IFF_PROMISC) { if (br->dev->flags & IFF_PROMISC) {
struct sk_buff *skb2; struct sk_buff *skb2;
skb2 = skb_clone(skb, GFP_ATOMIC); skb2 = skb_clone(skb, GFP_ATOMIC);
...@@ -140,7 +140,7 @@ int br_handle_frame(struct sk_buff *skb) ...@@ -140,7 +140,7 @@ int br_handle_frame(struct sk_buff *skb)
return -1; return -1;
} }
if (!memcmp(p->br->dev.dev_addr, dest, ETH_ALEN)) if (!memcmp(p->br->dev->dev_addr, dest, ETH_ALEN))
skb->pkt_type = PACKET_HOST; skb->pkt_type = PACKET_HOST;
NF_HOOK(PF_BRIDGE, NF_BR_PRE_ROUTING, skb, skb->dev, NULL, NF_HOOK(PF_BRIDGE, NF_BR_PRE_ROUTING, skb, skb->dev, NULL,
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
sizeof(struct bridge_skb_cb))) sizeof(struct bridge_skb_cb)))
#define has_bridge_parent(device) ((device)->br_port != NULL) #define has_bridge_parent(device) ((device)->br_port != NULL)
#define bridge_parent(device) (&((device)->br_port->br->dev)) #define bridge_parent(device) ((device)->br_port->br->dev)
/* We need these fake structures to make netfilter happy -- /* We need these fake structures to make netfilter happy --
* lots of places assume that skb->dst != NULL, which isn't * lots of places assume that skb->dst != NULL, which isn't
......
...@@ -52,7 +52,7 @@ static int br_device_event(struct notifier_block *unused, unsigned long event, v ...@@ -52,7 +52,7 @@ static int br_device_event(struct notifier_block *unused, unsigned long event, v
break; break;
case NETDEV_DOWN: case NETDEV_DOWN:
if (br->dev.flags & IFF_UP) { if (br->dev->flags & IFF_UP) {
spin_lock_bh(&br->lock); spin_lock_bh(&br->lock);
br_stp_disable_port(p); br_stp_disable_port(p);
spin_unlock_bh(&br->lock); spin_unlock_bh(&br->lock);
...@@ -60,7 +60,7 @@ static int br_device_event(struct notifier_block *unused, unsigned long event, v ...@@ -60,7 +60,7 @@ static int br_device_event(struct notifier_block *unused, unsigned long event, v
break; break;
case NETDEV_UP: case NETDEV_UP:
if (!(br->dev.flags & IFF_UP)) { if (!(br->dev->flags & IFF_UP)) {
spin_lock_bh(&br->lock); spin_lock_bh(&br->lock);
br_stp_enable_port(p); br_stp_enable_port(p);
spin_unlock_bh(&br->lock); spin_unlock_bh(&br->lock);
......
...@@ -81,7 +81,7 @@ struct net_bridge ...@@ -81,7 +81,7 @@ struct net_bridge
{ {
spinlock_t lock; spinlock_t lock;
struct list_head 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;
struct hlist_head hash[BR_HASH_SIZE]; struct hlist_head hash[BR_HASH_SIZE];
......
...@@ -26,7 +26,7 @@ static const char *br_port_state_names[] = { ...@@ -26,7 +26,7 @@ static const char *br_port_state_names[] = {
void br_log_state(const struct net_bridge_port *p) void br_log_state(const struct net_bridge_port *p)
{ {
pr_info("%s: port %d(%s) entering %s state\n", pr_info("%s: port %d(%s) entering %s state\n",
p->br->dev.name, p->port_no, p->dev->name, p->br->dev->name, p->port_no, p->dev->name,
br_port_state_names[p->state]); br_port_state_names[p->state]);
} }
...@@ -130,7 +130,7 @@ void br_become_root_bridge(struct net_bridge *br) ...@@ -130,7 +130,7 @@ void br_become_root_bridge(struct net_bridge *br)
br_topology_change_detection(br); br_topology_change_detection(br);
del_timer(&br->tcn_timer); del_timer(&br->tcn_timer);
if (br->dev.flags & IFF_UP) { if (br->dev->flags & IFF_UP) {
br_config_bpdu_generation(br); br_config_bpdu_generation(br);
mod_timer(&br->hello_timer, jiffies + br->hello_time); mod_timer(&br->hello_timer, jiffies + br->hello_time);
} }
...@@ -289,10 +289,10 @@ static inline void br_topology_change_acknowledged(struct net_bridge *br) ...@@ -289,10 +289,10 @@ static inline void br_topology_change_acknowledged(struct net_bridge *br)
/* called under bridge lock */ /* called under bridge lock */
void br_topology_change_detection(struct net_bridge *br) void br_topology_change_detection(struct net_bridge *br)
{ {
if (!(br->dev.flags & IFF_UP)) if (!(br->dev->flags & IFF_UP))
return; return;
pr_info("%s: topology change detected", br->dev.name); pr_info("%s: topology change detected", br->dev->name);
if (br_is_root_bridge(br)) { if (br_is_root_bridge(br)) {
printk(", propagating"); printk(", propagating");
br->topology_change = 1; br->topology_change = 1;
...@@ -446,7 +446,7 @@ void br_received_tcn_bpdu(struct net_bridge_port *p) ...@@ -446,7 +446,7 @@ void br_received_tcn_bpdu(struct net_bridge_port *p)
{ {
if (br_is_designated_port(p)) { if (br_is_designated_port(p)) {
pr_info("%s: received tcn bpdu on port %i(%s)\n", pr_info("%s: received tcn bpdu on port %i(%s)\n",
p->br->dev.name, p->port_no, p->dev->name); p->br->dev->name, p->port_no, p->dev->name);
br_topology_change_detection(p->br); br_topology_change_detection(p->br);
br_topology_change_acknowledge(p); br_topology_change_acknowledge(p);
......
...@@ -145,7 +145,7 @@ void br_stp_handle_bpdu(struct sk_buff *skb) ...@@ -145,7 +145,7 @@ void br_stp_handle_bpdu(struct sk_buff *skb)
spin_lock_bh(&br->lock); spin_lock_bh(&br->lock);
if (p->state == BR_STATE_DISABLED if (p->state == BR_STATE_DISABLED
|| !(br->dev.flags & IFF_UP) || !(br->dev->flags & IFF_UP)
|| !br->stp_enabled || !br->stp_enabled
|| memcmp(buf, header, 6)) || memcmp(buf, header, 6))
goto out; goto out;
......
...@@ -93,7 +93,7 @@ void br_stp_disable_port(struct net_bridge_port *p) ...@@ -93,7 +93,7 @@ void br_stp_disable_port(struct net_bridge_port *p)
br = p->br; br = p->br;
printk(KERN_INFO "%s: port %i(%s) entering %s state\n", printk(KERN_INFO "%s: port %i(%s) entering %s state\n",
br->dev.name, p->port_no, p->dev->name, "disabled"); br->dev->name, p->port_no, p->dev->name, "disabled");
wasroot = br_is_root_bridge(br); wasroot = br_is_root_bridge(br);
br_become_designated_port(p); br_become_designated_port(p);
...@@ -124,7 +124,7 @@ static void br_stp_change_bridge_id(struct net_bridge *br, unsigned char *addr) ...@@ -124,7 +124,7 @@ static void br_stp_change_bridge_id(struct net_bridge *br, unsigned char *addr)
memcpy(oldaddr, br->bridge_id.addr, ETH_ALEN); memcpy(oldaddr, br->bridge_id.addr, ETH_ALEN);
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);
list_for_each_entry(p, &br->port_list, list) { list_for_each_entry(p, &br->port_list, list) {
if (!memcmp(p->designated_bridge.addr, oldaddr, ETH_ALEN)) if (!memcmp(p->designated_bridge.addr, oldaddr, ETH_ALEN))
......
...@@ -38,9 +38,9 @@ static void br_hello_timer_expired(unsigned long arg) ...@@ -38,9 +38,9 @@ static void br_hello_timer_expired(unsigned long arg)
{ {
struct net_bridge *br = (struct net_bridge *)arg; struct net_bridge *br = (struct net_bridge *)arg;
pr_debug("%s: hello timer expired\n", br->dev.name); pr_debug("%s: hello timer expired\n", br->dev->name);
spin_lock_bh(&br->lock); spin_lock_bh(&br->lock);
if (br->dev.flags & IFF_UP) { if (br->dev->flags & IFF_UP) {
br_config_bpdu_generation(br); br_config_bpdu_generation(br);
br->hello_timer.expires = jiffies + br->hello_time; br->hello_timer.expires = jiffies + br->hello_time;
...@@ -61,7 +61,7 @@ static void br_message_age_timer_expired(unsigned long arg) ...@@ -61,7 +61,7 @@ static void br_message_age_timer_expired(unsigned long arg)
pr_info("%s: neighbor %.2x%.2x.%.2x:%.2x:%.2x:%.2x:%.2x:%.2x lost on port %d(%s)\n", pr_info("%s: neighbor %.2x%.2x.%.2x:%.2x:%.2x:%.2x:%.2x:%.2x lost on port %d(%s)\n",
br->dev.name, br->dev->name,
id->prio[0], id->prio[1], id->prio[0], id->prio[1],
id->addr[0], id->addr[1], id->addr[2], id->addr[0], id->addr[1], id->addr[2],
id->addr[3], id->addr[4], id->addr[5], id->addr[3], id->addr[4], id->addr[5],
...@@ -89,7 +89,7 @@ static void br_forward_delay_timer_expired(unsigned long arg) ...@@ -89,7 +89,7 @@ static void br_forward_delay_timer_expired(unsigned long arg)
struct net_bridge *br = p->br; struct net_bridge *br = p->br;
pr_debug("%s: %d(%s) forward delay timer\n", pr_debug("%s: %d(%s) forward delay timer\n",
br->dev.name, p->port_no, p->dev->name); br->dev->name, p->port_no, p->dev->name);
spin_lock_bh(&br->lock); spin_lock_bh(&br->lock);
if (p->state == BR_STATE_LISTENING) { if (p->state == BR_STATE_LISTENING) {
p->state = BR_STATE_LEARNING; p->state = BR_STATE_LEARNING;
...@@ -108,9 +108,9 @@ static void br_tcn_timer_expired(unsigned long arg) ...@@ -108,9 +108,9 @@ static void br_tcn_timer_expired(unsigned long arg)
{ {
struct net_bridge *br = (struct net_bridge *) arg; struct net_bridge *br = (struct net_bridge *) arg;
pr_debug("%s: tcn timer expired\n", br->dev.name); pr_debug("%s: tcn timer expired\n", br->dev->name);
spin_lock_bh(&br->lock); spin_lock_bh(&br->lock);
if (br->dev.flags & IFF_UP) { if (br->dev->flags & IFF_UP) {
br_transmit_tcn(br); br_transmit_tcn(br);
br->tcn_timer.expires = jiffies + br->bridge_hello_time; br->tcn_timer.expires = jiffies + br->bridge_hello_time;
...@@ -123,7 +123,7 @@ static void br_topology_change_timer_expired(unsigned long arg) ...@@ -123,7 +123,7 @@ static void br_topology_change_timer_expired(unsigned long arg)
{ {
struct net_bridge *br = (struct net_bridge *) arg; struct net_bridge *br = (struct net_bridge *) arg;
pr_debug("%s: topo change timer expired\n", br->dev.name); pr_debug("%s: topo change timer expired\n", br->dev->name);
spin_lock_bh(&br->lock); spin_lock_bh(&br->lock);
br->topology_change_detected = 0; br->topology_change_detected = 0;
br->topology_change = 0; br->topology_change = 0;
...@@ -135,7 +135,7 @@ static void br_hold_timer_expired(unsigned long arg) ...@@ -135,7 +135,7 @@ static void br_hold_timer_expired(unsigned long arg)
struct net_bridge_port *p = (struct net_bridge_port *) arg; struct net_bridge_port *p = (struct net_bridge_port *) arg;
pr_debug("%s: %d(%s) hold timer expired\n", pr_debug("%s: %d(%s) hold timer expired\n",
p->br->dev.name, p->port_no, p->dev->name); p->br->dev->name, p->port_no, p->dev->name);
spin_lock_bh(&p->br->lock); spin_lock_bh(&p->br->lock);
if (p->config_pending) if (p->config_pending)
......
...@@ -22,7 +22,7 @@ static int ebt_target_redirect(struct sk_buff **pskb, unsigned int hooknr, ...@@ -22,7 +22,7 @@ static int ebt_target_redirect(struct sk_buff **pskb, unsigned int hooknr,
if (hooknr != NF_BR_BROUTING) if (hooknr != NF_BR_BROUTING)
memcpy((**pskb).mac.ethernet->h_dest, memcpy((**pskb).mac.ethernet->h_dest,
in->br_port->br->dev.dev_addr, ETH_ALEN); in->br_port->br->dev->dev_addr, ETH_ALEN);
else { else {
memcpy((**pskb).mac.ethernet->h_dest, memcpy((**pskb).mac.ethernet->h_dest,
in->dev_addr, ETH_ALEN); in->dev_addr, ETH_ALEN);
......
...@@ -135,10 +135,10 @@ static inline int ebt_basic_match(struct ebt_entry *e, struct ethhdr *h, ...@@ -135,10 +135,10 @@ static inline int ebt_basic_match(struct ebt_entry *e, struct ethhdr *h,
if (FWINV2(ebt_dev_check(e->out, out), EBT_IOUT)) if (FWINV2(ebt_dev_check(e->out, out), EBT_IOUT))
return 1; return 1;
if ((!in || !in->br_port) ? 0 : FWINV2(ebt_dev_check( if ((!in || !in->br_port) ? 0 : FWINV2(ebt_dev_check(
e->logical_in, &in->br_port->br->dev), EBT_ILOGICALIN)) e->logical_in, in->br_port->br->dev), EBT_ILOGICALIN))
return 1; return 1;
if ((!out || !out->br_port) ? 0 : FWINV2(ebt_dev_check( if ((!out || !out->br_port) ? 0 : FWINV2(ebt_dev_check(
e->logical_out, &out->br_port->br->dev), EBT_ILOGICALOUT)) e->logical_out, out->br_port->br->dev), EBT_ILOGICALOUT))
return 1; return 1;
if (e->bitmask & EBT_SOURCEMAC) { if (e->bitmask & EBT_SOURCEMAC) {
......
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