Commit 5b998545 authored by Tariq Toukan's avatar Tariq Toukan Committed by Jakub Kicinski
Browse files

net/bonding: Take IP hash logic into a helper



Hash logic on L3 will be used in a downstream patch for one more use
case.
Take it to a function for a better code reuse.

Signed-off-by: default avatarTariq Toukan <tariqt@nvidia.com>
Reviewed-by: default avatarBoris Pismenny <borisp@nvidia.com>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 719a402c
Loading
Loading
Loading
Loading
+11 −5
Original line number Original line Diff line number Diff line
@@ -3541,6 +3541,16 @@ static bool bond_flow_dissect(struct bonding *bond, struct sk_buff *skb,
	return true;
	return true;
}
}


static u32 bond_ip_hash(u32 hash, struct flow_keys *flow)
{
	hash ^= (__force u32)flow_get_u32_dst(flow) ^
		(__force u32)flow_get_u32_src(flow);
	hash ^= (hash >> 16);
	hash ^= (hash >> 8);
	/* discard lowest hash bit to deal with the common even ports pattern */
	return hash >> 1;
}

/**
/**
 * bond_xmit_hash - generate a hash value based on the xmit policy
 * bond_xmit_hash - generate a hash value based on the xmit policy
 * @bond: bonding device
 * @bond: bonding device
@@ -3571,12 +3581,8 @@ u32 bond_xmit_hash(struct bonding *bond, struct sk_buff *skb)
		else
		else
			memcpy(&hash, &flow.ports.ports, sizeof(hash));
			memcpy(&hash, &flow.ports.ports, sizeof(hash));
	}
	}
	hash ^= (__force u32)flow_get_u32_dst(&flow) ^
		(__force u32)flow_get_u32_src(&flow);
	hash ^= (hash >> 16);
	hash ^= (hash >> 8);


	return hash >> 1;
	return bond_ip_hash(hash, &flow);
}
}


/*-------------------------- Device entry points ----------------------------*/
/*-------------------------- Device entry points ----------------------------*/