/*
 *  Show RLB hash table
 */
static int bond_debug_rlb_hash_show(struct seq_file *m, void *v)
{
	struct bonding *bond = m->private;
	struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
	struct rlb_client_info *client_info;
	u32 hash_index;

	if (bond->params.mode != BOND_MODE_ALB)
		return 0;

	seq_printf(m, "SourceIP        DestinationIP   "
			"Destination MAC   DEV\n");

	spin_lock_bh(&(BOND_ALB_INFO(bond).rx_hashtbl_lock));

	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]);
		seq_printf(m, "%-15pI4 %-15pI4 %-17pM %s\n",
			&client_info->ip_src,
			&client_info->ip_dst,
			&client_info->mac_dst,
			client_info->slave->dev->name);
	}

	spin_unlock_bh(&(BOND_ALB_INFO(bond).rx_hashtbl_lock));

	return 0;
}
Beispiel #2
0
/* sends ARP REPLIES that update the clients that need updating */
static void
rlb_update_rx_clients(struct bonding *bond)
{
	u32 hash_index;
	struct rlb_client_info *client_info = NULL;
	struct alb_bond_info *bond_info = &(BOND_ALB_INFO(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]);
		if (client_info->ntt) {
			rlb_update_client(client_info);
			if (bond_info->rlb_update_retry_counter == 0) {
				client_info->ntt = 0;
			}
		}
	}

	/* do not update the entries again untill this counter is zero so that
	 * not to confuse the clients.
	 */
	bond_info->rlb_update_delay_counter = RLB_UPDATE_DELAY;

	_unlock_rx_hashtbl(bond);
}
Beispiel #3
0
/* Must be called before starting the monitor timer */
static int tlb_initialize(struct bonding *bond)
{
	struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
	int size = TLB_HASH_TABLE_SIZE * sizeof(struct tlb_client_info);
	struct tlb_client_info *new_hashtbl;
	int i;

	spin_lock_init(&(bond_info->tx_hashtbl_lock));

	new_hashtbl = kzalloc(size, GFP_KERNEL);
	if (!new_hashtbl) {
		pr_err("%s: Error: Failed to allocate TLB hash table\n",
		       bond->dev->name);
		return -1;
	}
	_lock_tx_hashtbl(bond);

	bond_info->tx_hashtbl = new_hashtbl;

	for (i = 0; i < TLB_HASH_TABLE_SIZE; i++) {
		tlb_init_table_entry(&bond_info->tx_hashtbl[i], 1);
	}

	_unlock_tx_hashtbl(bond);

	return 0;
}
Beispiel #4
0
/* Caller must hold bond lock for read */
static void
rlb_rebalance(struct bonding *bond)
{
	struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
	struct slave *assigned_slave = NULL;
	u32 hash_index;
	struct rlb_client_info *client_info = NULL;
	u8 ntt = 0;

	_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]);
		assigned_slave = rlb_next_rx_slave(bond);
		if (assigned_slave && (client_info->slave != assigned_slave)){
			client_info->slave = assigned_slave;
			client_info->ntt = 1;
			ntt = 1;
		}
	}

	/* update the team's flag only after the whole iteration */
	if (ntt) {
		bond_info->rx_ntt = 1;
	}
	_unlock_rx_hashtbl(bond);
}
Beispiel #5
0
/* when an ARP REPLY is received from a client update its info
 * in the rx_hashtbl
 */
static void
rlb_update_entry_from_arp(struct bonding *bond, struct arp_pkt *arp)
{
	u32 hash_index;
	struct rlb_client_info *client_info = NULL;
	struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));

	_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]);

	if ((client_info->assigned) &&
	    (client_info->ip_src == arp->ip_dst) &&
	    (client_info->ip_dst == arp->ip_src)) {

		/* update the clients MAC address */
		memcpy(client_info->mac_dst, arp->mac_src, ETH_ALEN);
		client_info->ntt = 1;
		bond_info->rx_ntt = 1;
	}

	_unlock_rx_hashtbl(bond);
}
Beispiel #6
0
/* Caller must hold bond lock for read */
static struct slave*
rlb_next_rx_slave(struct bonding *bond)
{
	struct slave *rx_slave = NULL, *slave = NULL;
	unsigned int i = 0;
	struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));

	slave = bond_info->next_rx_slave;
	if (slave == NULL) {
		slave = bond->next;
	}

	/* this loop uses the circular linked list property of the
	 * slave's list to go through all slaves
	 */
	for (i = 0; i < bond->slave_cnt; i++, slave = slave->next) {

		if (SLAVE_IS_OK(slave)) {
			if (!rx_slave) {
				rx_slave = slave;
			}
			else if (slave->speed > rx_slave->speed) {
				rx_slave = slave;
			}
		}
	}

	if (rx_slave) {
		bond_info->next_rx_slave = rx_slave->next;
	}

	return rx_slave;
}
Beispiel #7
0
/* Caller must hold bond lock for read */
static struct slave *tlb_choose_channel(struct bonding *bond, u32 hash_index, u32 skb_len)
{
	struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
	struct tlb_client_info *hash_table;
	struct slave *assigned_slave,max_assigned_slave,slave;
	int i;

	_lock_tx_hashtbl(bond);

	hash_table = bond_info->tx_hashtbl;
	assigned_slave = hash_table[hash_index].tx_slave;
	if (!assigned_slave) {
		assigned_slave = tlb_get_least_loaded_slave(bond);
		if(assigned_slave == assigend_slave_old) {
			max_assigned_slave = assigned_slave;
			assigned_slave = max_assigned_slave->next;
			bond_for_each_slave_from(bond,slave,i) {
				if (IS_UP(slave->dev) && (slave->link == BOND_LINK_UP) 
					&& (slave->state == BOND_STATE_ACTIVE)) {
					if (compute_gap(slave) > compute_gap(assigned_slave) 
							&& slave != max_assigned_slave)
						assigned_slave = slave;
				}
			}
		}
Beispiel #8
0
static int
rlb_initialize(struct bonding *bond)
{
	struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
	struct packet_type *pk_type = &(BOND_ALB_INFO(bond).rlb_pkt_type);
	int i;
	size_t size;

	spin_lock_init(&(bond_info->rx_hashtbl_lock));

	_lock_rx_hashtbl(bond);
	if (bond_info->rx_hashtbl != NULL) {
		printk (KERN_ERR "%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);
	if (bond_info->rx_hashtbl == NULL) {
		printk (KERN_ERR "%s: Failed to allocate"
			" RLB hash table\n", bond->device->name);
		_unlock_rx_hashtbl(bond);
		return -1;
	}

	bond_info->rx_hashtbl_head = RLB_NULL_INDEX;

	for (i=0; i<RLB_HASH_TABLE_SIZE; i++) {
		rlb_init_table_entry(bond_info->rx_hashtbl + i);
	}
	_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 */

	dev_add_pack(pk_type);

	return 0;
}
Beispiel #9
0
/* Must be called only after all slaves have been released */
static void tlb_deinitialize(struct bonding *bond)
{
	struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));

	_lock_tx_hashtbl(bond);

	kfree(bond_info->tx_hashtbl);
	bond_info->tx_hashtbl = NULL;

	_unlock_tx_hashtbl(bond);
}
Beispiel #10
0
/* slave being removed should not be active at this point
 *
 * Caller must hold bond lock for read
 */
static void
rlb_clear_slave(struct bonding *bond, struct slave *slave)
{
	struct rlb_client_info *rx_hash_table = NULL;
	struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
	u8 mac_bcast[ETH_ALEN] = {0xff,0xff,0xff,0xff,0xff,0xff};
	u32 index, next_index;

	/* 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;
	}

	index = bond_info->rx_hashtbl_head;
	for (; index != RLB_NULL_INDEX; index = next_index) {
		next_index = rx_hash_table[index].next;

		if (rx_hash_table[index].slave == slave) {
			struct slave *assigned_slave = rlb_next_rx_slave(bond);

			if (assigned_slave) {
				rx_hash_table[index].slave = assigned_slave;
				if (memcmp(rx_hash_table[index].mac_dst,
					   mac_bcast, ETH_ALEN)) {
					bond_info->rx_hashtbl[index].ntt = 1;
					bond_info->rx_ntt = 1;
					/* A slave has been removed from the
					 * table because it is either disabled
					 * or being released. We must retry the
					 * update to avoid clients from not
					 * being updated & disconnecting when
					 * there is stress
					 */
					bond_info->rlb_update_retry_counter =
						RLB_UPDATE_RETRY;
				}
			} else {  /* there is no active slave */
				rx_hash_table[index].slave = NULL;
			}
		}
	}

	_unlock_rx_hashtbl(bond);

	write_lock(&bond->ptrlock);
	if (slave != bond->current_slave) {
		rlb_teach_disabled_mac_on_primary(bond, slave->dev->dev_addr);
	}
	write_unlock(&bond->ptrlock);
}
Beispiel #11
0
void
bond_alb_deinitialize(struct bonding *bond)
{
	struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));

	tlb_deinitialize(bond);

	if (bond_info->rlb_enabled) {
		rlb_deinitialize(bond);
	}
}
Beispiel #12
0
/* Caller must hold tx_hashtbl lock */
static inline void
tlb_init_table_entry(struct bonding *bond, u8 index, 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;
		entry->tx_bytes = 0;
	}
	entry->tx_slave = NULL;
	entry->next = TLB_NULL_INDEX;
	entry->prev = TLB_NULL_INDEX;
}
Beispiel #13
0
/* Caller must hold bond lock for read */
struct slave*
tlb_choose_channel(struct bonding *bond, u32 hash_index, u32 skb_len)
{
	struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
	struct tlb_client_info *hash_table = NULL;
	struct slave *assigned_slave = NULL;

	_lock_tx_hashtbl(bond);

	hash_table = bond_info->tx_hashtbl;
	if (hash_table == NULL) {
		printk (KERN_ERR "%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);

		if (assigned_slave) {
			struct tlb_slave_info *slave_info =
				&(SLAVE_TLB_INFO(assigned_slave));
			u32 next_index = slave_info->head;

			hash_table[hash_index].tx_slave = assigned_slave;
			hash_table[hash_index].next = next_index;
			hash_table[hash_index].prev = TLB_NULL_INDEX;

			if (next_index != TLB_NULL_INDEX) {
				hash_table[next_index].prev = hash_index;
			}

			slave_info->head = hash_index;
			slave_info->load +=
				hash_table[hash_index].load_history;
		}
	}

	if (assigned_slave) {
		hash_table[hash_index].tx_bytes += skb_len;
	}

	_unlock_tx_hashtbl(bond);

	return assigned_slave;
}
Beispiel #14
0
static void
rlb_deinitialize(struct bonding *bond)
{
	struct alb_bond_info *bond_info = &(BOND_ALB_INFO(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);
}
Beispiel #15
0
/* mark all clients using src_ip to be updated */
static void
rlb_req_update_subnet_clients(struct bonding *bond, u32 src_ip)
{
	u32 hash_index;
	struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
	u8 mac_bcast[ETH_ALEN] = {0xff,0xff,0xff,0xff,0xff,0xff};
	struct rlb_client_info *client_info = NULL;

	_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]);

		if (!client_info->slave) {
			printk(KERN_ERR "Bonding: Error: found a client with no"
			       " channel in the client's hash table\n");
			continue;
		}
		/*update all clients using this src_ip, that are not assigned
		 * to the team's address (current_slave) and have a known
		 * unicast mac address.
		 */
		if ((client_info->ip_src == src_ip) &&
		    memcmp(client_info->slave->dev->dev_addr,
			   bond->device->dev_addr, ETH_ALEN) &&
		    memcmp(client_info->mac_dst, mac_bcast, ETH_ALEN)) {
			client_info->ntt = 1;
			bond_info->rx_ntt = 1;
		}
	}

	_unlock_rx_hashtbl(bond);
}
Beispiel #16
0
/* Must be called before starting the monitor timer */
static int
tlb_initialize(struct bonding *bond)
{
	struct alb_bond_info *bond_info = &(BOND_ALB_INFO(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 "%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);
	if (bond_info->tx_hashtbl == NULL) {
		printk (KERN_ERR "%s: Failed to allocate TLB hash table\n",
			bond->device->name);
		_unlock_tx_hashtbl(bond);
		return -1;
	}

	memset(bond_info->tx_hashtbl, 0, size);
	for (i=0; i<TLB_HASH_TABLE_SIZE; i++) {
		tlb_init_table_entry(bond, i, 1);
	}
	_unlock_tx_hashtbl(bond);

	return 0;
}
Beispiel #17
0
/* Caller must hold bond lock for read */
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;

	/* clear slave from tx_hashtbl */
	_lock_tx_hashtbl(bond);
	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;
		}
	}
	_unlock_tx_hashtbl(bond);

	tlb_init_slave(slave);
}
Beispiel #18
0
/* Caller must hold bond lock for read */
void
bond_alb_handle_link_change(struct bonding *bond, struct slave *slave,
			    char link)
{
	struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));

	if (link == BOND_LINK_DOWN) {
		tlb_clear_slave(bond, slave, 0);
		if (bond->alb_info.rlb_enabled) {
			rlb_clear_slave(bond, slave);
		}
	} else if (link == BOND_LINK_UP) {
		/* order a rebalance ASAP */
		bond_info->tx_rebalance_counter = BOND_TLB_REBALANCE_TICKS;
		if (bond->alb_info.rlb_enabled) {
			bond->alb_info.rlb_rebalance = 1;
			/* If the updelay module parameter is smaller than the
			 * forwarding delay of the switch the rebalance will
			 * not work because the rebalance arp replies will
			 * not be forwarded to the clients..
			 */
		}
	}
}
Beispiel #19
0
/* The slave was assigned a new mac address - update the clients */
static void
rlb_req_update_slave_clients(struct bonding *bond, struct slave *slave)
{
	u32 hash_index;
	u8 ntt = 0;
	struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
	u8 mac_bcast[ETH_ALEN] = {0xff,0xff,0xff,0xff,0xff,0xff};
	struct rlb_client_info* client_info = NULL;

	_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]);

		if ((client_info->slave == slave) &&
		    memcmp(client_info->mac_dst, mac_bcast, ETH_ALEN)) {
			client_info->ntt = 1;
			ntt = 1;
		}
	}

	// update the team's flag only after the whole iteration
	if (ntt) {
		bond_info->rx_ntt = 1;
		//fasten the change
		bond_info->rlb_update_retry_counter = RLB_UPDATE_RETRY;
	}

	_unlock_rx_hashtbl(bond);
}
Beispiel #20
0
/* Caller must hold bond lock for read */
static void tlb_clear_slave(struct bonding *bond, struct slave *slave, int save_load)
{
	struct tlb_client_info *tx_hash_table;
	u32 index;

	_lock_tx_hashtbl(bond);

	/* clear slave from tx_hashtbl */
	tx_hash_table = BOND_ALB_INFO(bond).tx_hashtbl;

	/* skip this if we've already freed the tx hash table */
	if (tx_hash_table) {
		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;
		}
	}

	tlb_init_slave(slave);

	_unlock_tx_hashtbl(bond);
}
Beispiel #21
0
void
bond_alb_monitor(struct bonding *bond)
{
	struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
	struct slave *slave = NULL;

	read_lock(&bond->lock);

	if ((bond->slave_cnt == 0) || !(bond->device->flags & IFF_UP)) {
		bond_info->tx_rebalance_counter = 0;
		bond_info->lp_counter = 0;
		goto out;
	}

	bond_info->tx_rebalance_counter++;
	bond_info->lp_counter++;

	/* send learning packets */
	if (bond_info->lp_counter >= BOND_ALB_LP_TICKS) {
		/* change of current_slave involves swapping of mac addresses.
		 * in order to avoid this swapping from happening while
		 * sending the learning packets, the ptrlock must be held for
		 * read.
		 */
		read_lock(&bond->ptrlock);
		slave = bond_get_first_slave(bond);
		while (slave) {
			alb_send_learning_packets(slave,slave->dev->dev_addr);
			slave = bond_get_next_slave(bond, slave);
		}
		read_unlock(&bond->ptrlock);

		bond_info->lp_counter = 0;
	}

	/* rebalance tx traffic */
	if (bond_info->tx_rebalance_counter >= BOND_TLB_REBALANCE_TICKS) {
		read_lock(&bond->ptrlock);
		slave = bond_get_first_slave(bond);
		while (slave) {
			tlb_clear_slave(bond, slave, 1);
			if (slave == bond->current_slave) {
				SLAVE_TLB_INFO(slave).load =
					bond_info->unbalanced_load /
						BOND_TLB_REBALANCE_INTERVAL;
				bond_info->unbalanced_load = 0;
			}
			slave = bond_get_next_slave(bond, slave);
		}
		read_unlock(&bond->ptrlock);
		bond_info->tx_rebalance_counter = 0;
	}

	/* handle rlb stuff */
	if (bond_info->rlb_enabled) {
		/* the following code changes the promiscuity of the
		 * the current_slave. It needs to be locked with a
		 * write lock to protect from other code that also
		 * sets the promiscuity.
		 */
		write_lock(&bond->ptrlock);
		if (bond_info->primary_is_promisc &&
		    (++bond_info->rlb_promisc_timeout_counter >=
			RLB_PROMISC_TIMEOUT)) {

			bond_info->rlb_promisc_timeout_counter = 0;

			/* If the primary was set to promiscuous mode
			 * because a slave was disabled then
			 * it can now leave promiscuous mode.
			 */
			dev_set_promiscuity(bond->current_slave->dev, -1);
			bond_info->primary_is_promisc = 0;
		}
		write_unlock(&bond->ptrlock);

		if (bond_info->rlb_rebalance == 1) {
			bond_info->rlb_rebalance = 0;
			rlb_rebalance(bond);
		}

		/* check if clients need updating */
		if (bond_info->rx_ntt) {
			if (bond_info->rlb_update_delay_counter) {
				--bond_info->rlb_update_delay_counter;
			} else {
				rlb_update_rx_clients(bond);
				if (bond_info->rlb_update_retry_counter) {
					--bond_info->rlb_update_retry_counter;
				} else {
					bond_info->rx_ntt = 0;
				}
			}
		}
	}

out:
	read_unlock(&bond->lock);

	if (bond->device->flags & IFF_UP) {
		/* re-arm the timer */
		mod_timer(&(bond_info->alb_timer),
			jiffies + (HZ/ALB_TIMER_TICKS_PER_SEC));
	}
}
Beispiel #22
0
/*********************** rlb specific functions ***************************/
static inline void
_lock_rx_hashtbl(struct bonding *bond)
{
	spin_lock(&(BOND_ALB_INFO(bond).rx_hashtbl_lock));
}
Beispiel #23
0
int
bond_alb_xmit(struct sk_buff *skb, struct net_device *dev)
{
	struct bonding *bond = (struct bonding *) dev->priv;
	struct ethhdr *eth_data = (struct ethhdr *)skb->data;
	struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
	struct slave *tx_slave = NULL;
	char do_tx_balance = 1;
	int hash_size = 0;
	u32 hash_index = 0;
	u8 *hash_start = NULL;
	u8 mac_bcast[ETH_ALEN] = {0xff,0xff,0xff,0xff,0xff,0xff};

	if (!IS_UP(dev)) { /* bond down */
		dev_kfree_skb(skb);
		return 0;
	}

	/* make sure that the current_slave and the slaves list do
	 * not change during tx
	 */
	read_lock(&bond->lock);

	if (bond->slave_cnt == 0) {
		/* no suitable interface, frame not sent */
		dev_kfree_skb(skb);
		read_unlock(&bond->lock);
		return 0;
	}

	read_lock(&bond->ptrlock);

	switch (ntohs(skb->protocol)) {
	case ETH_P_IP:
		if ((memcmp(eth_data->h_dest, mac_bcast, ETH_ALEN) == 0) ||
		    (skb->nh.iph->daddr == 0xffffffff)) {
			do_tx_balance = 0;
			break;
		}
		hash_start = (char*)&(skb->nh.iph->daddr);
		hash_size = 4;
		break;

	case ETH_P_IPV6:
		if (memcmp(eth_data->h_dest, mac_bcast, ETH_ALEN) == 0) {
			do_tx_balance = 0;
			break;
		}

		hash_start = (char*)&(skb->nh.ipv6h->daddr);
		hash_size = 16;
		break;

	case ETH_P_IPX:
		if (skb->nh.ipxh->ipx_checksum !=
		    __constant_htons(IPX_NO_CHECKSUM)) {
			/* something is wrong with this packet */
			do_tx_balance = 0;
			break;
		}

		if (skb->nh.ipxh->ipx_type !=
		    __constant_htons(IPX_TYPE_NCP)) {
			/* The only protocol worth balancing in
			 * this family since it has an "ARP" like
			 * mechanism
			 */
			do_tx_balance = 0;
			break;
		}

		hash_start = (char*)eth_data->h_dest;
		hash_size = ETH_ALEN;
		break;

	case ETH_P_ARP:
		do_tx_balance = 0;
		if (bond_info->rlb_enabled) {
			tx_slave = rlb_arp_xmit(skb, bond);
		}
		break;

	default:
		do_tx_balance = 0;
		break;
	}

	if (do_tx_balance) {
		hash_index = _simple_hash(hash_start, hash_size);
		tx_slave = tlb_choose_channel(bond, hash_index, skb->len);
	}

	if (!tx_slave) {
		/* unbalanced or unassigned, send through primary */
		tx_slave = bond->current_slave;
		bond_info->unbalanced_load += skb->len;
	}

	if (tx_slave && SLAVE_IS_OK(tx_slave)) {
		skb->dev = tx_slave->dev;
		if (tx_slave != bond->current_slave) {
			memcpy(eth_data->h_source,
				tx_slave->dev->dev_addr,
				ETH_ALEN);
		}
		dev_queue_xmit(skb);
	} else {
		/* no suitable interface, frame not sent */
		if (tx_slave) {
			tlb_clear_slave(bond, tx_slave, 0);
		}
		dev_kfree_skb(skb);
	}

	read_unlock(&bond->ptrlock);
	read_unlock(&bond->lock);
	return 0;
}
Beispiel #24
0
/* Caller must hold both bond and ptr locks for read */
struct slave*
rlb_choose_channel(struct bonding *bond, struct arp_pkt *arp)
{
	struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
	struct rlb_client_info *client_info = NULL;
	u32 hash_index = 0;
	struct slave *assigned_slave = NULL;
	u8 mac_bcast[ETH_ALEN] = {0xff,0xff,0xff,0xff,0xff,0xff};

	_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]);

	if (client_info->assigned == 1) {
		if ((client_info->ip_src == arp->ip_src) &&
		    (client_info->ip_dst == arp->ip_dst)) {
			/* the entry is already assigned to this client */

			if (memcmp(arp->mac_dst, mac_bcast, ETH_ALEN)) {
				/* update mac address from arp */
				memcpy(client_info->mac_dst, arp->mac_dst, ETH_ALEN);
			}

			assigned_slave = client_info->slave;
			if (assigned_slave) {
				_unlock_rx_hashtbl(bond);
				return assigned_slave;
			}
		} else {
			/* the entry is already assigned to some other client,
			 * move the old client to primary (current_slave) so
			 * that the new client can be assigned to this entry.
			 */
			if (bond->current_slave &&
			    client_info->slave != bond->current_slave) {
				client_info->slave = bond->current_slave;
				rlb_update_client(client_info);
			}
		}
	}
	/* assign a new slave */
	assigned_slave = rlb_next_rx_slave(bond);

	if (assigned_slave) {
		client_info->ip_src = arp->ip_src;
		client_info->ip_dst = arp->ip_dst;
		/* arp->mac_dst is broadcast for arp reqeusts.
		 * will be updated with clients actual unicast mac address
		 * upon receiving an arp reply.
		 */
		memcpy(client_info->mac_dst, arp->mac_dst, ETH_ALEN);
		client_info->slave = assigned_slave;

		if (memcmp(client_info->mac_dst, mac_bcast, ETH_ALEN)) {
			client_info->ntt = 1;
			bond->alb_info.rx_ntt = 1;
		}
		else {
			client_info->ntt = 0;
		}

		if (!client_info->assigned) {
			u32 prev_tbl_head = bond_info->rx_hashtbl_head;
			bond_info->rx_hashtbl_head = hash_index;
			client_info->next = prev_tbl_head;
			if (prev_tbl_head != RLB_NULL_INDEX) {
				bond_info->rx_hashtbl[prev_tbl_head].prev =
					hash_index;
			}
			client_info->assigned = 1;
		}
	}

	_unlock_rx_hashtbl(bond);

	return assigned_slave;
}
Beispiel #25
0
static inline void _unlock_tx_hashtbl(struct bonding *bond)
{
	spin_unlock_bh(&(BOND_ALB_INFO(bond).tx_hashtbl_lock));
}