Commit 4394542c authored by Eric Dumazet's avatar Eric Dumazet Committed by David S. Miller

bonding: fix l23 and l34 load balancing in forwarding path

Since commit 6b923cb7 (bonding: support for IPv6 transmit hashing)
bonding doesn't properly hash traffic in forwarding setups.

Vitaly V. Bursov diagnosed that skb_network_header_len() returned 0 in
this case.

More generally, the transport header might not be in the skb head.

Use pskb_may_pull() & skb_header_pointer() to get it right, and use
proto_ports_offset() in bond_xmit_hash_policy_l34() to get support for
more protocols than TCP and UDP.
Reported-by: default avatarVitaly V. Bursov <vitalyb@telenet.dn.ua>
Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Cc: Jay Vosburgh <fubar@us.ibm.com>
Cc: Andy Gospodarek <andy@greyhouse.net>
Cc: John Eaglesham <linux@8192.net>
Tested-by: default avatarVitaly V. Bursov <vitalyb@telenet.dn.ua>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 0c14e5ce
...@@ -3296,20 +3296,22 @@ static int bond_xmit_hash_policy_l2(struct sk_buff *skb, int count) ...@@ -3296,20 +3296,22 @@ static int bond_xmit_hash_policy_l2(struct sk_buff *skb, int count)
*/ */
static int bond_xmit_hash_policy_l23(struct sk_buff *skb, int count) static int bond_xmit_hash_policy_l23(struct sk_buff *skb, int count)
{ {
struct ethhdr *data = (struct ethhdr *)skb->data; const struct ethhdr *data;
struct iphdr *iph; const struct iphdr *iph;
struct ipv6hdr *ipv6h; const struct ipv6hdr *ipv6h;
u32 v6hash; u32 v6hash;
__be32 *s, *d; const __be32 *s, *d;
if (skb->protocol == htons(ETH_P_IP) && if (skb->protocol == htons(ETH_P_IP) &&
skb_network_header_len(skb) >= sizeof(*iph)) { pskb_network_may_pull(skb, sizeof(*iph))) {
iph = ip_hdr(skb); iph = ip_hdr(skb);
data = (struct ethhdr *)skb->data;
return ((ntohl(iph->saddr ^ iph->daddr) & 0xffff) ^ return ((ntohl(iph->saddr ^ iph->daddr) & 0xffff) ^
(data->h_dest[5] ^ data->h_source[5])) % count; (data->h_dest[5] ^ data->h_source[5])) % count;
} else if (skb->protocol == htons(ETH_P_IPV6) && } else if (skb->protocol == htons(ETH_P_IPV6) &&
skb_network_header_len(skb) >= sizeof(*ipv6h)) { pskb_network_may_pull(skb, sizeof(*ipv6h))) {
ipv6h = ipv6_hdr(skb); ipv6h = ipv6_hdr(skb);
data = (struct ethhdr *)skb->data;
s = &ipv6h->saddr.s6_addr32[0]; s = &ipv6h->saddr.s6_addr32[0];
d = &ipv6h->daddr.s6_addr32[0]; d = &ipv6h->daddr.s6_addr32[0];
v6hash = (s[1] ^ d[1]) ^ (s[2] ^ d[2]) ^ (s[3] ^ d[3]); v6hash = (s[1] ^ d[1]) ^ (s[2] ^ d[2]) ^ (s[3] ^ d[3]);
...@@ -3328,33 +3330,36 @@ static int bond_xmit_hash_policy_l23(struct sk_buff *skb, int count) ...@@ -3328,33 +3330,36 @@ static int bond_xmit_hash_policy_l23(struct sk_buff *skb, int count)
static int bond_xmit_hash_policy_l34(struct sk_buff *skb, int count) static int bond_xmit_hash_policy_l34(struct sk_buff *skb, int count)
{ {
u32 layer4_xor = 0; u32 layer4_xor = 0;
struct iphdr *iph; const struct iphdr *iph;
struct ipv6hdr *ipv6h; const struct ipv6hdr *ipv6h;
__be32 *s, *d; const __be32 *s, *d;
__be16 *layer4hdr; const __be16 *l4 = NULL;
__be16 _l4[2];
int noff = skb_network_offset(skb);
int poff;
if (skb->protocol == htons(ETH_P_IP) && if (skb->protocol == htons(ETH_P_IP) &&
skb_network_header_len(skb) >= sizeof(*iph)) { pskb_may_pull(skb, noff + sizeof(*iph))) {
iph = ip_hdr(skb); iph = ip_hdr(skb);
if (!ip_is_fragment(iph) && poff = proto_ports_offset(iph->protocol);
(iph->protocol == IPPROTO_TCP ||
iph->protocol == IPPROTO_UDP) && if (!ip_is_fragment(iph) && poff >= 0) {
(skb_headlen(skb) - skb_network_offset(skb) >= l4 = skb_header_pointer(skb, noff + (iph->ihl << 2) + poff,
iph->ihl * sizeof(u32) + sizeof(*layer4hdr) * 2)) { sizeof(_l4), &_l4);
layer4hdr = (__be16 *)((u32 *)iph + iph->ihl); if (l4)
layer4_xor = ntohs(*layer4hdr ^ *(layer4hdr + 1)); layer4_xor = ntohs(l4[0] ^ l4[1]);
} }
return (layer4_xor ^ return (layer4_xor ^
((ntohl(iph->saddr ^ iph->daddr)) & 0xffff)) % count; ((ntohl(iph->saddr ^ iph->daddr)) & 0xffff)) % count;
} else if (skb->protocol == htons(ETH_P_IPV6) && } else if (skb->protocol == htons(ETH_P_IPV6) &&
skb_network_header_len(skb) >= sizeof(*ipv6h)) { pskb_may_pull(skb, noff + sizeof(*ipv6h))) {
ipv6h = ipv6_hdr(skb); ipv6h = ipv6_hdr(skb);
if ((ipv6h->nexthdr == IPPROTO_TCP || poff = proto_ports_offset(ipv6h->nexthdr);
ipv6h->nexthdr == IPPROTO_UDP) && if (poff >= 0) {
(skb_headlen(skb) - skb_network_offset(skb) >= l4 = skb_header_pointer(skb, noff + sizeof(*ipv6h) + poff,
sizeof(*ipv6h) + sizeof(*layer4hdr) * 2)) { sizeof(_l4), &_l4);
layer4hdr = (__be16 *)(ipv6h + 1); if (l4)
layer4_xor = ntohs(*layer4hdr ^ *(layer4hdr + 1)); layer4_xor = ntohs(l4[0] ^ l4[1]);
} }
s = &ipv6h->saddr.s6_addr32[0]; s = &ipv6h->saddr.s6_addr32[0];
d = &ipv6h->daddr.s6_addr32[0]; d = &ipv6h->daddr.s6_addr32[0];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment