5a0be1d75fad7d72012d4b15fcec60145d79b73f
[linux-2.6.git] / linux-2.6-720-bonding-hashes.patch
1 diff -Nurp linux-2.6.22.19-vs2.3.0.34/drivers/net/bonding/bond_main.c linux-2.6.22.19-vs2.3.0.34.bonding/drivers/net/bonding/bond_main.c
2 --- linux-2.6.22.19-vs2.3.0.34/drivers/net/bonding/bond_main.c  2007-09-05 07:07:59.000000000 +0200
3 +++ linux-2.6.22.19-vs2.3.0.34.bonding/drivers/net/bonding/bond_main.c  2009-06-15 19:26:31.000000000 +0200
4 @@ -123,7 +123,7 @@ MODULE_PARM_DESC(lacp_rate, "LACPDU tx r
5                             "(slow/fast)");
6  module_param(xmit_hash_policy, charp, 0);
7  MODULE_PARM_DESC(xmit_hash_policy, "XOR hashing method: 0 for layer 2 (default)"
8 -                                  ", 1 for layer 3+4");
9 +                                  ", 1 for layer 3+4, 2 for layer2+3, 3 for layer3");
10  module_param(arp_interval, int, 0);
11  MODULE_PARM_DESC(arp_interval, "arp interval in milliseconds");
12  module_param_array(arp_ip_target, charp, NULL, 0);
13 @@ -170,6 +170,8 @@ struct bond_parm_tbl bond_mode_tbl[] = {
14  struct bond_parm_tbl xmit_hashtype_tbl[] = {
15  {      "layer2",               BOND_XMIT_POLICY_LAYER2},
16  {      "layer3+4",             BOND_XMIT_POLICY_LAYER34},
17 +{      "layer2+3",             BOND_XMIT_POLICY_LAYER23},
18 +{      "layer3",               BOND_XMIT_POLICY_LAYER3},
19  {      NULL,                   -1},
20  };
21  
22 @@ -3447,6 +3449,40 @@ void bond_unregister_arp(struct bonding 
23  }
24  
25  /*---------------------------- Hashing Policies -----------------------------*/
26
27 +/*
28 + * Hash for the output device based upon layer 3 data. If the packet
29 + * is not IP mimic bond_xmit_hash_policy_l2()
30 + */
31 +static int bond_xmit_hash_policy_l3(struct sk_buff *skb,
32 +                                   struct net_device *bond_dev, int count)
33 +{
34 +       struct ethhdr *data = (struct ethhdr *)skb->data;
35 +       struct iphdr *iph = ip_hdr(skb);
36 +
37 +       if (skb->protocol == __constant_htons(ETH_P_IP))
38 +               return (ntohl(iph->saddr ^ iph->daddr) & 0xffff) % count;
39 +       else
40 +               return (data->h_dest[5] ^ bond_dev->dev_addr[5]) % count;
41 +}
42 +
43 +/*
44 + * Hash for the output device based upon layer 2 and layer 3 data. If
45 + * the packet is not IP mimic bond_xmit_hash_policy_l2()
46 + */
47 +static int bond_xmit_hash_policy_l23(struct sk_buff *skb,
48 +                                    struct net_device *bond_dev, int count)
49 +{
50 +       struct ethhdr *data = (struct ethhdr *)skb->data;
51 +       struct iphdr *iph = ip_hdr(skb);
52 +
53 +       if (skb->protocol == __constant_htons(ETH_P_IP)) {
54 +               return ((ntohl(iph->saddr ^ iph->daddr) & 0xffff) ^
55 +                       (data->h_dest[5] ^ bond_dev->dev_addr[5])) % count;
56 +       }
57 +
58 +       return (data->h_dest[5] ^ bond_dev->dev_addr[5]) % count;
59 +}
60  
61  /*
62   * Hash for the output device based upon layer 3 and layer 4 data. If
63 @@ -4183,6 +4219,10 @@ void bond_set_mode_ops(struct bonding *b
64                 bond_dev->hard_start_xmit = bond_xmit_xor;
65                 if (bond->params.xmit_policy == BOND_XMIT_POLICY_LAYER34)
66                         bond->xmit_hash_policy = bond_xmit_hash_policy_l34;
67 +               else if (bond->params.xmit_policy == BOND_XMIT_POLICY_LAYER23)
68 +                       bond->xmit_hash_policy = bond_xmit_hash_policty_l23;
69 +               else if (bond->params.xmit_policy == BOND_XMIT_POLICY_LAYER3)
70 +                       bond->xmit_hash_policy = bond_xmit_hash_policy_l3;
71                 else
72                         bond->xmit_hash_policy = bond_xmit_hash_policy_l2;
73                 break;
74 @@ -4194,6 +4234,10 @@ void bond_set_mode_ops(struct bonding *b
75                 bond_dev->hard_start_xmit = bond_3ad_xmit_xor;
76                 if (bond->params.xmit_policy == BOND_XMIT_POLICY_LAYER34)
77                         bond->xmit_hash_policy = bond_xmit_hash_policy_l34;
78 +               else if (bond->params.xmit_policy == BOND_XMIT_POLICY_LAYER23)
79 +                       bond->xmit_hash_policy = bond_xmit_hash_policty_l23;
80 +               else if (bond->params.xmit_policy == BOND_XMIT_POLICY_LAYER3)
81 +                       bond->xmit_hash_policy = bond_xmit_hash_policy_l3;
82                 else
83                         bond->xmit_hash_policy = bond_xmit_hash_policy_l2;
84                 break;
85 diff -Nurp linux-2.6.22.19-vs2.3.0.34/include/linux/if_bonding.h linux-2.6.22.19-vs2.3.0.34.bonding/include/linux/if_bonding.h
86 --- linux-2.6.22.19-vs2.3.0.34/include/linux/if_bonding.h       2006-06-18 03:49:35.000000000 +0200
87 +++ linux-2.6.22.19-vs2.3.0.34.bonding/include/linux/if_bonding.h       2009-06-15 19:29:16.000000000 +0200
88 @@ -86,6 +86,8 @@
89  /* hashing types */
90  #define BOND_XMIT_POLICY_LAYER2                0 /* layer 2 (MAC only), default */
91  #define BOND_XMIT_POLICY_LAYER34       1 /* layer 3+4 (IP ^ MAC) */
92 +#define BOND_XMIT_POLICY_LAYER23       2 /* layer 2+3 (IP ^ MAC) */
93 +#define BOND_XMIT_POLICY_LAYER3                3 /* layer3 (IP only) */
94  
95  typedef struct ifbond {
96         __s32 bond_mode;