bonding support for IPv6 transmit hashing
Subsystems (3)
PATCH v2 1/2 bonding support for IPv6 transmit hashing
drivers/net/bonding/bond_main.c +54 -23
@@ -3352,56 +3352,87 @@/*---------------------------- Hashing Policies -----------------------------*/ /* +* Hash for the output device based upon layer 2 data +*/ +static int bond_xmit_hash_policy_l2 (struct sk_buff *skb,int count) +{ +struct ethhdr *data = (struct ethhdr *)skb->data; + +if (skb_headlen (skb) >=6 ) +return (data->h_dest[5 ] ^ data->h_source[5 ]) % count; + +return 0 ; +} + +/* * Hash for the output device based upon layer 2 and layer 3 data. If -* the packet is not IP mimic bond_xmit_hash_policy_l2() +* the packet is not IP, fall back on bond_xmit_hash_policy_l2() */ static int bond_xmit_hash_policy_l23 (struct sk_buff *skb,int count) {struct ethhdr *data = (struct ethhdr *)skb->data; -struct iphdr *iph =ip_hdr (skb); -if (skb->protocol ==htons (ETH_P_IP )) { +if (skb->protocol ==htons (ETH_P_IP ) && +skb_network_header_len (skb) >=sizeof (struct iphdr )) { +struct iphdr *iph =ip_hdr (skb);return ((ntohl (iph->saddr ^ iph->daddr) &0xffff ) ^ (data->h_dest[5 ] ^ data->h_source[5 ])) % count; + }else if (skb->protocol ==htons (ETH_P_IPV6 ) && +skb_network_header_len (skb) >=sizeof (struct ipv6hdr )) { +struct ipv6hdr *ipv6h =ipv6_hdr (skb); +u32 v6hash = + (ipv6h->saddr.s6_addr32[1 ] ^ ipv6h->daddr.s6_addr32[1 ]) ^ + (ipv6h->saddr.s6_addr32[2 ] ^ ipv6h->daddr.s6_addr32[2 ]) ^ + (ipv6h->saddr.s6_addr32[3 ] ^ ipv6h->daddr.s6_addr32[3 ]); + v6hash = (v6hash >>16 ) ^ (v6hash >>8 ) ^ v6hash; +return (v6hash ^ data->h_dest[5 ] ^ data->h_source[5 ]) % count; } -return (data->h_dest[5 ] ^ data->h_source[5 ]) % count; +return bond_xmit_hash_policy_l2 (skb, count); }/* * 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 -* altogether not IP, mimic bond_xmit_hash_policy_l2() +* altogether not IP, fall back on bond_xmit_hash_policy_l2() */ static int bond_xmit_hash_policy_l34 (struct sk_buff *skb,int count) { -struct ethhdr *data = (struct ethhdr *)skb->data; -struct iphdr *iph =ip_hdr (skb); -__be16 *layer4hdr = (__be16 *)((u32 *)iph + iph->ihl); -int layer4_xor =0 ; +u32 layer4_xor =0 ;if (skb->protocol ==htons (ETH_P_IP )) { +struct iphdr *iph =ip_hdr (skb);if (!ip_is_fragment (iph) && - (iph->protocol ==IPPROTO_TCP || - iph->protocol ==IPPROTO_UDP )) { + (iph->protocol ==IPPROTO_TCP || + iph->protocol ==IPPROTO_UDP )) { +__be16 *layer4hdr = (__be16 *)((u32 *)iph + iph->ihl); +if (iph->ihl *sizeof (u32) +sizeof (__be16) *2 > +skb_headlen (skb) -skb_network_offset (skb)) goto SHORT_HEADER; layer4_xor =ntohs ((*layer4hdr ^ *(layer4hdr +1 ))); + }else if (skb_network_header_len (skb) <sizeof (struct iphdr )) { + goto SHORT_HEADER; }return (layer4_xor ^ ((ntohl (iph->saddr ^ iph->daddr)) &0xffff )) % count; - + }else if (skb->protocol ==htons (ETH_P_IPV6 )) { +struct ipv6hdr *ipv6h =ipv6_hdr (skb); +if (ipv6h->nexthdr ==IPPROTO_TCP || ipv6h->nexthdr ==IPPROTO_UDP ) { +__be16 *layer4hdrv6 = (__be16 *)((u8 *)ipv6h +sizeof (struct ipv6hdr )); +if (sizeof (struct ipv6hdr ) +sizeof (__be16) *2 > +skb_headlen (skb) -skb_network_offset (skb)) goto SHORT_HEADER; + layer4_xor = (*layer4hdrv6 ^ *(layer4hdrv6 +1 )); + }else if (skb_network_header_len (skb) <sizeof (struct ipv6hdr )) { + goto SHORT_HEADER; + } + layer4_xor ^= + (ipv6h->saddr.s6_addr32[1 ] ^ ipv6h->daddr.s6_addr32[1 ]) ^ + (ipv6h->saddr.s6_addr32[2 ] ^ ipv6h->daddr.s6_addr32[2 ]) ^ + (ipv6h->saddr.s6_addr32[3 ] ^ ipv6h->daddr.s6_addr32[3 ]); +return ((layer4_xor >>16 ) ^ (layer4_xor >>8 ) ^ layer4_xor) % count; } -return (data->h_dest[5 ] ^ data->h_source[5 ]) % count; -} - -/* -* Hash for the output device based upon layer 2 data -*/ -static int bond_xmit_hash_policy_l2 (struct sk_buff *skb,int count) -{ -struct ethhdr *data = (struct ethhdr *)skb->data; - -return (data->h_dest[5 ] ^ data->h_source[5 ]) % count; + SHORT_HEADER: +return bond_xmit_hash_policy_l2 (skb, count); }/*-------------------------- Device entry points ----------------------------*/
John <[email protected]> wrote:
In principle, I think this is a good idea, but the patch has
some (mostly style) issues, and does not apply to net-next (you don't say what tree it is based on).
Can you address the comments noted below, and repost against the
current net-next?
Quoted 4 lines
drivers/net/bonding/bond_main.c +0
-0@@ -3352,56 +3352,87 @@/*---------------------------- Hashing Policies -----------------------------*/
drivers/net/bonding/bond_main.c line 3362
Quoted 10 lines
drivers/net/bonding/bond_main.c +8
-0/* +* Hash for the output device based upon layer 2 data +*/ +static int bond_xmit_hash_policy_l2 (struct sk_buff *skb,int count) +{ +struct ethhdr *data = (struct ethhdr *)skb->data; + +if (skb_headlen (skb) >=6 ) +return (data->h_dest[5 ] ^ data->h_source[5 ]) % count;
Can skb_headlen ever be less than 6 here? And why >= 6, anyway?
The offset of ->h_source[5] from skb->data is 11.
Quoted 14 lines
drivers/net/bonding/bond_main.c +6
-2+ +return 0 ; +} + +/* * Hash for the output device based upon layer 2 and layer 3 data. If -* the packet is not IP mimic bond_xmit_hash_policy_l2() +* the packet is not IP, fall back on bond_xmit_hash_policy_l2() */ static int bond_xmit_hash_policy_l23 (struct sk_buff *skb,int count) {struct ethhdr *data = (struct ethhdr *)skb->data; -struct iphdr *iph =ip_hdr (skb);
drivers/net/bonding/bond_main.c line 3383
Quoted 10 lines
drivers/net/bonding/bond_main.c +7
-1-if (skb->protocol ==htons (ETH_P_IP )) { +if (skb->protocol ==htons (ETH_P_IP ) && +skb_network_header_len (skb) >=sizeof (struct iphdr )) { +struct iphdr *iph =ip_hdr (skb);return ((ntohl (iph->saddr ^ iph->daddr) &0xffff ) ^ (data->h_dest[5 ] ^ data->h_source[5 ])) % count; + }else if (skb->protocol ==htons (ETH_P_IPV6 ) && +skb_network_header_len (skb) >=sizeof (struct ipv6hdr )) { +struct ipv6hdr *ipv6h =ipv6_hdr (skb); + u32 v6hash =
I personally prefer having variables declared at the head of the
function, not inside inner blocks, but if you're going to do this, there needs to be a blank line after the declaration.
Quoted 18 lines
drivers/net/bonding/bond_main.c +7
-2+ (ipv6h->saddr.s6_addr32[1 ] ^ ipv6h->daddr.s6_addr32[1 ]) ^ + (ipv6h->saddr.s6_addr32[2 ] ^ ipv6h->daddr.s6_addr32[2 ]) ^ + (ipv6h->saddr.s6_addr32[3 ] ^ ipv6h->daddr.s6_addr32[3 ]); + v6hash = (v6hash >>16 ) ^ (v6hash >>8 ) ^ v6hash; +return (v6hash ^ data->h_dest[5 ] ^ data->h_source[5 ]) % count; } -return (data->h_dest[5 ] ^ data->h_source[5 ]) % count; +return bond_xmit_hash_policy_l2 (skb, count); }/* * 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 -* altogether not IP, mimic bond_xmit_hash_policy_l2() +* altogether not IP, fall back on bond_xmit_hash_policy_l2() */ static int bond_xmit_hash_policy_l34 (struct sk_buff *skb,int count)
drivers/net/bonding/bond_main.c line 3405
Quoted 10 lines
drivers/net/bonding/bond_main.c +2
-4{ -struct ethhdr *data = (struct ethhdr *)skb->data; -struct iphdr *iph =ip_hdr (skb); -__be16 *layer4hdr = (__be16 *)((u32 *)iph + iph->ihl); -int layer4_xor =0 ; +u32 layer4_xor =0 ;if (skb->protocol ==htons (ETH_P_IP )) { +struct iphdr *iph =ip_hdr (skb); if (!ip_is_fragment(iph) &&
Blank line after iph declaration.
drivers/net/bonding/bond_main.c line 3408
Quoted 5 lines
drivers/net/bonding/bond_main.c +3
-2- (iph->protocol == IPPROTO_TCP || - iph->protocol == IPPROTO_UDP)) { + (iph->protocol == IPPROTO_TCP || + iph->protocol == IPPROTO_UDP)) { +__be16 *layer4hdr = (__be16 *)((u32 *)iph + iph->ihl);
Blank line afret the layer4hdr declaration.
drivers/net/bonding/bond_main.c line 3410
Quoted 2 lines
drivers/net/bonding/bond_main.c +2
-0+if (iph->ihl *sizeof (u32) +sizeof (__be16) *2 > +skb_headlen (skb) -skb_network_offset (skb)) goto SHORT_HEADER;
The goto needs to be on a separate line.
drivers/net/bonding/bond_main.c line 3419
Quoted 10 lines
drivers/net/bonding/bond_main.c +5
-1layer4_xor =ntohs ((*layer4hdr ^ *(layer4hdr +1 ))); + }else if (skb_network_header_len (skb) <sizeof (struct iphdr )) { + goto SHORT_HEADER; }return (layer4_xor ^ ((ntohl (iph->saddr ^ iph->daddr)) &0xffff )) % count; - + }else if (skb->protocol ==htons (ETH_P_IPV6 )) { +struct ipv6hdr *ipv6h =ipv6_hdr (skb); +if (ipv6h->nexthdr ==IPPROTO_TCP || ipv6h->nexthdr ==IPPROTO_UDP ) {
Blank line after ipv6h.
drivers/net/bonding/bond_main.c line 3422
Quoted 3 lines
drivers/net/bonding/bond_main.c +3
-0+__be16 *layer4hdrv6 = (__be16 *)((u8 *)ipv6h +sizeof (struct ipv6hdr )); +if (sizeof (struct ipv6hdr ) +sizeof (__be16) *2 > +skb_headlen (skb) -skb_network_offset (skb)) goto SHORT_HEADER;
The goto goes on a separate line.
Quoted 13 lines
drivers/net/bonding/bond_main.c +9
-2+ layer4_xor = (*layer4hdrv6 ^ *(layer4hdrv6 +1 )); + }else if (skb_network_header_len (skb) <sizeof (struct ipv6hdr )) { + goto SHORT_HEADER; + } + layer4_xor ^= + (ipv6h->saddr.s6_addr32[1 ] ^ ipv6h->daddr.s6_addr32[1 ]) ^ + (ipv6h->saddr.s6_addr32[2 ] ^ ipv6h->daddr.s6_addr32[2 ]) ^ + (ipv6h->saddr.s6_addr32[3 ] ^ ipv6h->daddr.s6_addr32[3 ]); +return ((layer4_xor >>16 ) ^ (layer4_xor >>8 ) ^ layer4_xor) % count; } -return (data->h_dest[5 ] ^ data->h_source[5 ]) % count; -}
drivers/net/bonding/bond_main.c line 3434
Quoted 10 lines
drivers/net/bonding/bond_main.c +1
-9- -/* -* Hash for the output device based upon layer 2 data -*/ -static int bond_xmit_hash_policy_l2 (struct sk_buff *skb,int count) -{ -struct ethhdr *data = (struct ethhdr *)skb->data; - -return (data->h_dest[5 ] ^ data->h_source[5 ]) % count; + SHORT_HEADER:
This label should be lower case, and not indented at all. -J
drivers/net/bonding/bond_main.c line 3438
Quoted 4 lines
drivers/net/bonding/bond_main.c +1
-0+return bond_xmit_hash_policy_l2 (skb, count); }/*-------------------------- Device entry points ----------------------------*/
---
-Jay Vosburgh, IBM Linux Technology Center, [email protected]
Thanks Jay. It was against Linux 3.3.0. I will update my patch and re-post.
John
Quoted 9 lines · Jay Vosburgh
John<[email protected]> wrote:
In principle, I think this is a good idea, but the patch has
some (mostly style) issues, and does not apply to net-next (you don't say what tree it is based on).Can you address the comments noted below, and repost against the
current net-next?