diff -Nuarp a/drivers/net/bonding/bond_alb.c b/drivers/net/bonding/bond_alb.c --- a/drivers/net/bonding/bond_alb.c Sun Dec 21 16:08:39 2003 +++ b/drivers/net/bonding/bond_alb.c Sun Dec 21 16:08:40 2003 @@ -141,19 +141,8 @@ _unlock_tx_hashtbl(struct bonding *bond) /* Caller must hold tx_hashtbl lock */ static inline void -tlb_init_table_entry(struct bonding *bond, u8 index, u8 save_load) +tlb_init_table_entry(struct tlb_client_info *entry, u8 save_load) { - struct tlb_client_info *entry; - - if (BOND_ALB_INFO(bond).tx_hashtbl == NULL) { - return; - } - - entry = &(BOND_ALB_INFO(bond).tx_hashtbl[index]); - /* at end of cycle, save the load that was transmitted to the client - * during the cycle, and set the tx_bytes counter to 0 for counting - * the load during the next cycle - */ if (save_load) { entry->load_history = 1 + entry->tx_bytes / BOND_TLB_REBALANCE_INTERVAL; @@ -167,10 +156,8 @@ tlb_init_table_entry(struct bonding *bon static inline void tlb_init_slave(struct slave *slave) { - struct tlb_slave_info *slave_info = &(SLAVE_TLB_INFO(slave)); - - slave_info->load = 0; - slave_info->head = TLB_NULL_INDEX; + SLAVE_TLB_INFO(slave).load = 0; + SLAVE_TLB_INFO(slave).head = TLB_NULL_INDEX; } /* Caller must hold bond lock for read */ @@ -178,19 +165,17 @@ static inline void tlb_clear_slave(struct bonding *bond, struct slave *slave, u8 save_load) { struct tlb_client_info *tx_hash_table = NULL; - u32 index, next_index; + u32 index; - /* clear slave from tx_hashtbl */ _lock_tx_hashtbl(bond); + /* clear slave from tx_hashtbl */ tx_hash_table = BOND_ALB_INFO(bond).tx_hashtbl; - if (tx_hash_table) { - index = SLAVE_TLB_INFO(slave).head; - while (index != TLB_NULL_INDEX) { - next_index = tx_hash_table[index].next; - tlb_init_table_entry(bond, index, save_load); - index = next_index; - } + index = SLAVE_TLB_INFO(slave).head; + while (index != TLB_NULL_INDEX) { + u32 next_index = tx_hash_table[index].next; + tlb_init_table_entry(&tx_hash_table[index], save_load); + index = next_index; } _unlock_tx_hashtbl(bond); @@ -205,21 +190,9 @@ tlb_initialize(struct bonding *bond) int i; size_t size; -#if(TLB_HASH_TABLE_SIZE != 256) - /* Key to the hash table is byte wide. Check the size! */ - #error Hash Table size is wrong. -#endif - spin_lock_init(&(bond_info->tx_hashtbl_lock)); _lock_tx_hashtbl(bond); - if (bond_info->tx_hashtbl != NULL) { - printk(KERN_ERR DRV_NAME - ": Error: %s: TLB hash table is not NULL\n", - bond->device->name); - _unlock_tx_hashtbl(bond); - return -1; - } size = TLB_HASH_TABLE_SIZE * sizeof(struct tlb_client_info); bond_info->tx_hashtbl = kmalloc(size, GFP_KERNEL); @@ -233,7 +206,7 @@ tlb_initialize(struct bonding *bond) memset(bond_info->tx_hashtbl, 0, size); for (i=0; itx_hashtbl[i], 1); } _unlock_tx_hashtbl(bond); @@ -247,10 +220,6 @@ tlb_deinitialize(struct bonding *bond) struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond)); _lock_tx_hashtbl(bond); - if (bond_info->tx_hashtbl == NULL) { - _unlock_tx_hashtbl(bond); - return; - } kfree(bond_info->tx_hashtbl); bond_info->tx_hashtbl = NULL; _unlock_tx_hashtbl(bond); @@ -309,14 +278,6 @@ tlb_choose_channel(struct bonding *bond, _lock_tx_hashtbl(bond); hash_table = bond_info->tx_hashtbl; - if (hash_table == NULL) { - printk(KERN_ERR DRV_NAME - ": Error: %s: TLB hash table is NULL\n", - bond->device->name); - _unlock_tx_hashtbl(bond); - return NULL; - } - assigned_slave = hash_table[hash_index].tx_slave; if (!assigned_slave) { assigned_slave = tlb_get_least_loaded_slave(bond); @@ -374,10 +335,6 @@ rlb_update_entry_from_arp(struct bonding _lock_rx_hashtbl(bond); - if (bond_info->rx_hashtbl == NULL) { - _unlock_rx_hashtbl(bond); - return; - } hash_index = _simple_hash((u8*)&(arp->ip_src), 4); client_info = &(bond_info->rx_hashtbl[hash_index]); @@ -500,13 +457,8 @@ rlb_clear_slave(struct bonding *bond, st /* clear slave from rx_hashtbl */ _lock_rx_hashtbl(bond); - rx_hash_table = bond_info->rx_hashtbl; - - if (rx_hash_table == NULL) { - _unlock_rx_hashtbl(bond); - return; - } + rx_hash_table = bond_info->rx_hashtbl; index = bond_info->rx_hashtbl_head; for (; index != RLB_NULL_INDEX; index = next_index) { next_index = rx_hash_table[index].next; @@ -575,11 +527,6 @@ rlb_update_rx_clients(struct bonding *bo _lock_rx_hashtbl(bond); - if (bond_info->rx_hashtbl == NULL) { - _unlock_rx_hashtbl(bond); - return; - } - hash_index = bond_info->rx_hashtbl_head; for (; hash_index != RLB_NULL_INDEX; hash_index = client_info->next) { client_info = &(bond_info->rx_hashtbl[hash_index]); @@ -611,11 +558,6 @@ rlb_req_update_slave_clients(struct bond _lock_rx_hashtbl(bond); - if (bond_info->rx_hashtbl == NULL) { - _unlock_rx_hashtbl(bond); - return; - } - hash_index = bond_info->rx_hashtbl_head; for (; hash_index != RLB_NULL_INDEX; hash_index = client_info->next) { client_info = &(bond_info->rx_hashtbl[hash_index]); @@ -648,11 +590,6 @@ rlb_req_update_subnet_clients(struct bon _lock_rx_hashtbl(bond); - if (bond_info->rx_hashtbl == NULL) { - _unlock_rx_hashtbl(bond); - return; - } - hash_index = bond_info->rx_hashtbl_head; for (; hash_index != RLB_NULL_INDEX; hash_index = client_info->next) { client_info = &(bond_info->rx_hashtbl[hash_index]); @@ -691,11 +628,6 @@ rlb_choose_channel(struct bonding *bond, _lock_rx_hashtbl(bond); - if (bond_info->rx_hashtbl == NULL) { - _unlock_rx_hashtbl(bond); - return NULL; - } - hash_index = _simple_hash((u8 *)&arp->ip_dst, 4); client_info = &(bond_info->rx_hashtbl[hash_index]); @@ -821,11 +753,6 @@ rlb_rebalance(struct bonding *bond) _lock_rx_hashtbl(bond); - if (bond_info->rx_hashtbl == NULL) { - _unlock_rx_hashtbl(bond); - return; - } - hash_index = bond_info->rx_hashtbl_head; for (; hash_index != RLB_NULL_INDEX; hash_index = client_info->next) { client_info = &(bond_info->rx_hashtbl[hash_index]); @@ -848,10 +775,9 @@ rlb_rebalance(struct bonding *bond) static inline void rlb_init_table_entry(struct rlb_client_info *entry) { + memset(entry, 0, sizeof(struct rlb_client_info)); entry->next = RLB_NULL_INDEX; entry->prev = RLB_NULL_INDEX; - entry->assigned = 0; - entry->ntt = 0; } static int @@ -865,13 +791,6 @@ rlb_initialize(struct bonding *bond) spin_lock_init(&(bond_info->rx_hashtbl_lock)); _lock_rx_hashtbl(bond); - if (bond_info->rx_hashtbl != NULL) { - printk(KERN_ERR DRV_NAME - ": Error: %s: RLB hash table is not NULL\n", - bond->device->name); - _unlock_rx_hashtbl(bond); - return -1; - } size = RLB_HASH_TABLE_SIZE * sizeof(struct rlb_client_info); bond_info->rx_hashtbl = kmalloc(size, GFP_KERNEL); @@ -890,14 +809,13 @@ rlb_initialize(struct bonding *bond) } _unlock_rx_hashtbl(bond); - /* register to receive ARPs */ - /*initialize packet type*/ pk_type->type = __constant_htons(ETH_P_ARP); pk_type->dev = bond->device; pk_type->func = rlb_arp_recv; pk_type->data = (void*)1; /* understand shared skbs */ + /* register to receive ARPs */ dev_add_pack(pk_type); return 0; @@ -911,10 +829,6 @@ rlb_deinitialize(struct bonding *bond) dev_remove_pack(&(bond_info->rlb_pkt_type)); _lock_rx_hashtbl(bond); - if (bond_info->rx_hashtbl == NULL) { - _unlock_rx_hashtbl(bond); - return; - } kfree(bond_info->rx_hashtbl); bond_info->rx_hashtbl = NULL; _unlock_rx_hashtbl(bond); diff -Nuarp a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c --- a/drivers/net/bonding/bond_main.c Sun Dec 21 16:08:39 2003 +++ b/drivers/net/bonding/bond_main.c Sun Dec 21 16:08:40 2003 @@ -505,7 +505,6 @@ static char *arp_ip_target[MAX_ARP_IP_TA static u32 arp_target[MAX_ARP_IP_TARGETS] = { 0, } ; static int arp_ip_count = 0; static u32 my_ip = 0; -char *arp_target_hw_addr = NULL; static char *primary= NULL; @@ -616,8 +615,8 @@ static void arp_send_all(struct slave *s for (i = 0; (idev, - my_ip, arp_target_hw_addr, slave->dev->dev_addr, - arp_target_hw_addr); + my_ip, NULL, slave->dev->dev_addr, + NULL); } } @@ -708,14 +707,6 @@ update_slave_cnt(struct bonding *bond, i static struct slave * bond_detach_slave(struct bonding *bond, struct slave *slave) { - if ((bond == NULL) || (slave == NULL) || - ((void *)bond == (void *)slave)) { - printk(KERN_ERR DRV_NAME - ": Error: trying to detach slave %p from bond %p\n", - bond, slave); - return slave; - } - if (bond->next == slave) { /* is the slave at the head ? */ if (bond->prev == slave) { /* is the slave alone ? */ bond->prev = bond->next = (struct slave *)bond; @@ -918,19 +909,6 @@ bond_check_dev_link(struct net_device *d return reporting ? -1 : BMSR_LSTATUS; } -static u16 bond_check_mii_link(struct bonding *bond) -{ - int has_active_interface = 0; - - read_lock_bh(&bond->lock); - read_lock(&bond->ptrlock); - has_active_interface = (bond->current_slave != NULL); - read_unlock(&bond->ptrlock); - read_unlock_bh(&bond->lock); - - return (has_active_interface ? BMSR_LSTATUS : 0); -} - /* register to receive lacpdus on a bond */ static void bond_register_lacpdu(struct bonding *bond) { @@ -1022,10 +1000,6 @@ static int bond_close(struct net_device } if (arp_interval> 0) { /* arp interval, in milliseconds. */ del_timer(&bond->arp_timer); - if (arp_target_hw_addr != NULL) { - kfree(arp_target_hw_addr); - arp_target_hw_addr = NULL; - } } if (bond_mode == BOND_MODE_8023AD) { @@ -1321,17 +1295,11 @@ static int bond_enslave(struct net_devic { struct bonding *bond = NULL; struct slave *new_slave = NULL; - unsigned long rflags = 0; int err = 0; struct dev_mc_list *dmi; - struct in_ifaddr **ifap; - struct in_ifaddr *ifa; int link_reporting; struct sockaddr addr; - if (master_dev == NULL || slave_dev == NULL) { - return -ENODEV; - } bond = (struct bonding *)master_dev->priv; if (slave_dev->do_ioctl == NULL) { @@ -1348,7 +1316,7 @@ static int bond_enslave(struct net_devic } /* already enslaved */ - if (master_dev->flags & IFF_SLAVE || slave_dev->flags & IFF_SLAVE) { + if (slave_dev->flags & IFF_SLAVE) { dprintk("Error, Device was already enslaved\n"); return -EBUSY; } @@ -1413,7 +1381,6 @@ static int bond_enslave(struct net_devic */ memcpy(new_slave->perm_hwaddr, slave_dev->dev_addr, ETH_ALEN); - if (bond->slave_cnt > 0) { /* set slave to master's mac address * The application already set the master's * mac address to that of the first slave @@ -1425,7 +1392,6 @@ static int bond_enslave(struct net_devic dprintk("Error %d calling set_mac_address\n", err); goto err_free; } - } /* open the slave since the application closed it */ err = dev_open(slave_dev); @@ -1582,15 +1548,6 @@ static int bond_enslave(struct net_devic dprintk("This is just a backup slave\n"); bond_set_slave_inactive_flags(new_slave); } - if (((struct in_device *)slave_dev->ip_ptr) != NULL) { - read_lock_irqsave(&(((struct in_device *)slave_dev->ip_ptr)->lock), rflags); - ifap= &(((struct in_device *)slave_dev->ip_ptr)->ifa_list); - ifa = *ifap; - if (ifa != NULL) - my_ip = ifa->ifa_address; - read_unlock_irqrestore(&(((struct in_device *)slave_dev->ip_ptr)->lock), rflags); - } - /* if there is a primary slave, remember it */ if (primary != NULL) { if (strcmp(primary, new_slave->dev->name) == 0) { @@ -1725,10 +1682,6 @@ static int bond_change_active(struct net struct slave *newactive = NULL; int ret = 0; - if (master_dev == NULL || slave_dev == NULL) { - return -ENODEV; - } - /* Verify that master_dev is indeed the master of slave_dev */ if (!(slave_dev->flags & IFF_SLAVE) || (slave_dev->master != master_dev)) { @@ -1936,18 +1889,14 @@ static void reselect_active_interface(st static int bond_release(struct net_device *master, struct net_device *slave) { struct bonding *bond; - struct slave *our_slave, *old_current; + struct slave *our_slave; struct sockaddr addr; - - if (master == NULL || slave == NULL) { - return -ENODEV; - } bond = (struct bonding *)master->priv; - /* master already enslaved, or slave not enslaved, - or no slave for this master */ - if ((master->flags & IFF_SLAVE) || !(slave->flags & IFF_SLAVE)) { + /* slave is not a slave or master is not master of this slave */ + if (!(slave->flags & IFF_SLAVE) || + (slave->master != master)) { printk(KERN_ERR DRV_NAME ": Error: %s: cannot release %s.\n", master->name, slave->name); @@ -1957,7 +1906,6 @@ static int bond_release(struct net_devic write_lock_bh(&bond->lock); bond->current_arp_slave = NULL; our_slave = (struct slave *)bond; - old_current = bond->current_slave; while ((our_slave = our_slave->prev) != (struct slave *)bond) { if (our_slave->dev == slave) { int mac_addr_differ = memcmp(bond->device->dev_addr, @@ -2098,28 +2046,18 @@ static int bond_release(struct net_devic static int bond_release_all(struct net_device *master) { struct bonding *bond; - struct slave *our_slave, *old_current; + struct slave *our_slave; struct net_device *slave_dev; struct sockaddr addr; int err = 0; - if (master == NULL) { - return -ENODEV; - } - - if (master->flags & IFF_SLAVE) { - return -EINVAL; - } - bond = (struct bonding *)master->priv; write_lock_bh(&bond->lock); if (bond->next == (struct slave *) bond) { - err = -EINVAL; goto out; } - old_current = bond->current_slave; change_active_interface(bond, NULL); bond->current_arp_slave = NULL; bond->primary_slave = NULL; @@ -2951,8 +2889,15 @@ static int bond_ioctl(struct net_device return -EINVAL; } if (mii->reg_num == 1) { - mii->val_out = bond_check_mii_link( - (struct bonding *)master_dev->priv); + struct bonding *bond = (struct bonding *)master_dev->priv; + mii->val_out = 0; + read_lock_bh(&bond->lock); + read_lock(&bond->ptrlock); + if (bond->current_slave) { + mii->val_out = BMSR_LSTATUS; + } + read_unlock(&bond->ptrlock); + read_unlock_bh(&bond->lock); } return 0; case BOND_INFO_QUERY_OLD: @@ -3244,28 +3189,6 @@ static int bond_xmit_activebackup(struct memcpy(&my_ip, the_ip, 4); } - /* if we are sending arp packets and don't know - * the target hw address, save it so we don't need - * to use a broadcast address. - * don't do this if in active backup mode because the slaves must - * receive packets to stay up, and the only ones they receive are - * broadcasts. - */ - if ( (bond_mode != BOND_MODE_ACTIVEBACKUP) && - (arp_ip_count == 1) && - (arp_interval > 0) && (arp_target_hw_addr == NULL) && - (skb->protocol == __constant_htons(ETH_P_IP) ) ) { - struct ethhdr *eth_hdr = - (struct ethhdr *) (((char *)skb->data)); - struct iphdr *ip_hdr = (struct iphdr *)(eth_hdr + 1); - - if (arp_target[0] == ip_hdr->daddr) { - arp_target_hw_addr = kmalloc(ETH_ALEN, GFP_KERNEL); - if (arp_target_hw_addr != NULL) - memcpy(arp_target_hw_addr, eth_hdr->h_dest, ETH_ALEN); - } - } - read_lock(&bond->lock); read_lock(&bond->ptrlock); @@ -3739,18 +3662,7 @@ static inline int bond_event_changename( static int bond_master_netdev_event(unsigned long event, struct net_device *event_dev) { - struct bonding *bond, *event_bond = NULL; - - list_for_each_entry(bond, &bond_dev_list, bond_list) { - if (bond == (struct bonding *)event_dev->priv) { - event_bond = bond; - break; - } - } - - if (event_bond == NULL) { - return NOTIFY_DONE; - } + struct bonding *event_bond = (struct bonding *)event_dev->priv; switch (event) { case NETDEV_CHANGENAME: @@ -3826,25 +3738,22 @@ static int bond_slave_netdev_event(unsig static int bond_netdev_event(struct notifier_block *this, unsigned long event, void *ptr) { struct net_device *event_dev = (struct net_device *)ptr; - unsigned short flags; - int res = NOTIFY_DONE; - dprintk("n_b %p ev %lx ptr %p\n", this, event, ptr); + dprintk("event_dev: %s, event: %lx\n", + (event_dev ? event_dev->name : "None"), + event); + + if (event_dev->flags & IFF_MASTER) { + dprintk("IFF_MASTER\n"); + return bond_master_netdev_event(event, event_dev); + } - flags = event_dev->flags & (IFF_MASTER | IFF_SLAVE); - switch (flags) { - case IFF_MASTER: - res = bond_master_netdev_event(event, event_dev); - break; - case IFF_SLAVE: - res = bond_slave_netdev_event(event, event_dev); - break; - default: - /* A master that is also a slave ? */ - break; + if (event_dev->flags & IFF_SLAVE) { + dprintk("IFF_SLAVE\n"); + return bond_slave_netdev_event(event, event_dev); } - return res; + return NOTIFY_DONE; } static struct notifier_block bond_netdev_notifier = { @@ -3982,14 +3891,6 @@ static int __init bond_init(struct net_d } /* -static int __init bond_probe(struct net_device *dev) -{ - bond_init(dev); - return 0; -} - */ - -/* * Convert string input module parms. Accept either the * number of the mode or its string name. */ @@ -4011,13 +3912,8 @@ bond_parse_parm(char *mode_arg, struct b } -static int __init bonding_init(void) +static int bond_check_params(void) { - int no; - int err; - - printk(KERN_INFO "%s", version); - /* * Convert string parameters. */ @@ -4261,6 +4157,21 @@ static int __init bonding_init(void) primary = NULL; } + return 0; +} + +static int __init bonding_init(void) +{ + int no; + int err; + + printk(KERN_INFO "%s", version); + + err = bond_check_params(); + if (err) { + return err; + } + rtnl_lock(); #ifdef CONFIG_PROC_FS