Patchwork [RFC,3/4] bond: support more Layer 4 protocols

login
register
mail settings
Submitter stephen hemminger
Date Feb. 4, 2010, 5:11 p.m.
Message ID <20100204171241.393163298@vyatta.com>
Download mbox | patch
Permalink /patch/44538/
State RFC
Delegated to: David Miller
Headers show

Comments

stephen hemminger - Feb. 4, 2010, 5:11 p.m.
There are several protocols similar to TCP and UDP which share common L4
header format. Since proto is only one byte, use a map rather than big
conditonal.

Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>
Patrick McHardy - Feb. 5, 2010, 10:38 a.m.
Stephen Hemminger wrote:
> +/* Map of protocols with standard ports available to include in hash */
> +static const bool has_layer4[256] = {
> +	[IPPROTO_TCP] = 1,
> +	[IPPROTO_UDP] = 1,
> +	[IPPROTO_UDPLITE] = 1,
> +	[IPPROTO_SCTP] = 1,
> +	[IPPROTO_DCCP] = 1,
> +	[IPPROTO_ESP] = 1,
> +};
> +

How about using a bitmap or u8s to keep this more compact?
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
stephen hemminger - Feb. 5, 2010, 4:42 p.m.
On Fri, 05 Feb 2010 11:38:05 +0100
Patrick McHardy <kaber@trash.net> wrote:

> Stephen Hemminger wrote:
> > +/* Map of protocols with standard ports available to include in hash */
> > +static const bool has_layer4[256] = {
> > +	[IPPROTO_TCP] = 1,
> > +	[IPPROTO_UDP] = 1,
> > +	[IPPROTO_UDPLITE] = 1,
> > +	[IPPROTO_SCTP] = 1,
> > +	[IPPROTO_DCCP] = 1,
> > +	[IPPROTO_ESP] = 1,
> > +};
> > +
> 
> How about using a bitmap or u8s to keep this more compact?

I thought about that, but couldn't find a clever way to initialize at
compile time other than hardcoding constants?
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Patrick McHardy - Feb. 8, 2010, 1:11 p.m.
Stephen Hemminger wrote:
> On Fri, 05 Feb 2010 11:38:05 +0100
> Patrick McHardy <kaber@trash.net> wrote:
> 
>> Stephen Hemminger wrote:
>>> +/* Map of protocols with standard ports available to include in hash */
>>> +static const bool has_layer4[256] = {
>>> +	[IPPROTO_TCP] = 1,
>>> +	[IPPROTO_UDP] = 1,
>>> +	[IPPROTO_UDPLITE] = 1,
>>> +	[IPPROTO_SCTP] = 1,
>>> +	[IPPROTO_DCCP] = 1,
>>> +	[IPPROTO_ESP] = 1,
>>> +};
>>> +
>> How about using a bitmap or u8s to keep this more compact?
> 
> I thought about that, but couldn't find a clever way to initialize at
> compile time other than hardcoding constants?

Maybe an __init function with a couple of set_bit() calls?
Otherwise I'd suggest to simply use u8.

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

--- a/drivers/net/bonding/bond_main.c	2010-02-04 09:08:00.447069200 -0800
+++ b/drivers/net/bonding/bond_main.c	2010-02-04 09:08:42.545818691 -0800
@@ -3621,6 +3621,16 @@  static u16 bond_xmit_hash_policy_l23(con
 	}
 }
 
+/* Map of protocols with standard ports available to include in hash */
+static const bool has_layer4[256] = {
+	[IPPROTO_TCP] = 1,
+	[IPPROTO_UDP] = 1,
+	[IPPROTO_UDPLITE] = 1,
+	[IPPROTO_SCTP] = 1,
+	[IPPROTO_DCCP] = 1,
+	[IPPROTO_ESP] = 1,
+};
+
 /*
  * Hash for the output device based upon layer 3 and layer 4 data. If
  * the packet is a frag or not TCP or UDP, just use layer 3 data.  If it is
@@ -3634,11 +3644,10 @@  static u16 bond_xmit_hash_policy_l34(con
 		const struct iphdr *iph = ip_hdr(skb);
 		const __be16 *layer4hdr
 			= ((const void *)iph + iph->ihl);
-		u32 layer4_xor = 0;
+		u16 layer4_xor = 0;
 
 		if (!(iph->frag_off & htons(IP_MF|IP_OFFSET)) &&
-		    (iph->protocol == IPPROTO_TCP ||
-		     iph->protocol == IPPROTO_UDP))
+		    has_layer4[iph->protocol])
 			layer4_xor = ntohs((*layer4hdr ^ *(layer4hdr + 1)));
 
 		return layer4_xor ^ ntohl(iph->saddr ^ iph->daddr);
@@ -3647,10 +3656,9 @@  static u16 bond_xmit_hash_policy_l34(con
 	{
 		const struct ipv6hdr *iph = ipv6_hdr(skb);
 		const __be16 *layer4hdr = (const __be16 *) (iph + 1);
-		u32 layer4_xor = 0;
+		u16 layer4_xor = 0;
 
-		if (iph->nexthdr == IPPROTO_TCP ||
-		     iph->nexthdr == IPPROTO_UDP)
+		if (has_layer4[iph->nexthdr])
 			layer4_xor = ntohs((*layer4hdr ^ *(layer4hdr + 1)));
 
 		return layer4_xor ^