diff options
author | Eric Dumazet <edumazet@google.com> | 2013-02-05 15:22:50 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2013-02-06 15:59:47 -0500 |
commit | cd431e738509e74726055390c9e5e81e8e7e03ec (patch) | |
tree | f5efeea14ae9aa00bb18cf96dc357c73a34d6b0a /drivers/net/macvlan.c | |
parent | 6d1ccff627806829c46091bd9d9835302a3fbf5f (diff) |
macvlan: add multicast filter
Setting up IPv6 addresses on configurations with many macvlans
is not really working, as many multicast messages are dropped.
Add a multicast filter to macvlan to reduce the amount of cloned
skbs and overhead.
Successfully tested with 1024 macvlans on one ethernet device.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Ben Greear <greearb@candelatech.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/macvlan.c')
-rw-r--r-- | drivers/net/macvlan.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c index 7b44ebd7770e..f494da82c33f 100644 --- a/drivers/net/macvlan.c +++ b/drivers/net/macvlan.c | |||
@@ -29,6 +29,7 @@ | |||
29 | #include <linux/if_vlan.h> | 29 | #include <linux/if_vlan.h> |
30 | #include <linux/if_link.h> | 30 | #include <linux/if_link.h> |
31 | #include <linux/if_macvlan.h> | 31 | #include <linux/if_macvlan.h> |
32 | #include <linux/hash.h> | ||
32 | #include <net/rtnetlink.h> | 33 | #include <net/rtnetlink.h> |
33 | #include <net/xfrm.h> | 34 | #include <net/xfrm.h> |
34 | 35 | ||
@@ -126,6 +127,13 @@ static int macvlan_broadcast_one(struct sk_buff *skb, | |||
126 | return vlan->receive(skb); | 127 | return vlan->receive(skb); |
127 | } | 128 | } |
128 | 129 | ||
130 | static unsigned int mc_hash(const unsigned char *addr) | ||
131 | { | ||
132 | u32 val = __get_unaligned_cpu32(addr + 2); | ||
133 | |||
134 | return hash_32(val, MACVLAN_MC_FILTER_BITS); | ||
135 | } | ||
136 | |||
129 | static void macvlan_broadcast(struct sk_buff *skb, | 137 | static void macvlan_broadcast(struct sk_buff *skb, |
130 | const struct macvlan_port *port, | 138 | const struct macvlan_port *port, |
131 | struct net_device *src, | 139 | struct net_device *src, |
@@ -137,6 +145,7 @@ static void macvlan_broadcast(struct sk_buff *skb, | |||
137 | struct sk_buff *nskb; | 145 | struct sk_buff *nskb; |
138 | unsigned int i; | 146 | unsigned int i; |
139 | int err; | 147 | int err; |
148 | unsigned int hash = mc_hash(eth->h_dest); | ||
140 | 149 | ||
141 | if (skb->protocol == htons(ETH_P_PAUSE)) | 150 | if (skb->protocol == htons(ETH_P_PAUSE)) |
142 | return; | 151 | return; |
@@ -146,6 +155,8 @@ static void macvlan_broadcast(struct sk_buff *skb, | |||
146 | if (vlan->dev == src || !(vlan->mode & mode)) | 155 | if (vlan->dev == src || !(vlan->mode & mode)) |
147 | continue; | 156 | continue; |
148 | 157 | ||
158 | if (!test_bit(hash, vlan->mc_filter)) | ||
159 | continue; | ||
149 | nskb = skb_clone(skb, GFP_ATOMIC); | 160 | nskb = skb_clone(skb, GFP_ATOMIC); |
150 | err = macvlan_broadcast_one(nskb, vlan, eth, | 161 | err = macvlan_broadcast_one(nskb, vlan, eth, |
151 | mode == MACVLAN_MODE_BRIDGE); | 162 | mode == MACVLAN_MODE_BRIDGE); |
@@ -405,6 +416,18 @@ static void macvlan_set_mac_lists(struct net_device *dev) | |||
405 | { | 416 | { |
406 | struct macvlan_dev *vlan = netdev_priv(dev); | 417 | struct macvlan_dev *vlan = netdev_priv(dev); |
407 | 418 | ||
419 | if (dev->flags & (IFF_PROMISC | IFF_ALLMULTI)) { | ||
420 | bitmap_fill(vlan->mc_filter, MACVLAN_MC_FILTER_SZ); | ||
421 | } else { | ||
422 | struct netdev_hw_addr *ha; | ||
423 | DECLARE_BITMAP(filter, MACVLAN_MC_FILTER_SZ); | ||
424 | |||
425 | bitmap_zero(filter, MACVLAN_MC_FILTER_SZ); | ||
426 | netdev_for_each_mc_addr(ha, dev) { | ||
427 | __set_bit(mc_hash(ha->addr), filter); | ||
428 | } | ||
429 | bitmap_copy(vlan->mc_filter, filter, MACVLAN_MC_FILTER_SZ); | ||
430 | } | ||
408 | dev_uc_sync(vlan->lowerdev, dev); | 431 | dev_uc_sync(vlan->lowerdev, dev); |
409 | dev_mc_sync(vlan->lowerdev, dev); | 432 | dev_mc_sync(vlan->lowerdev, dev); |
410 | } | 433 | } |