diff options
-rw-r--r-- | drivers/net/macvlan.c | 23 | ||||
-rw-r--r-- | include/linux/if_macvlan.h | 6 |
2 files changed, 29 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 | } |
diff --git a/include/linux/if_macvlan.h b/include/linux/if_macvlan.h index f65e8d250f7e..84dde1dd1da4 100644 --- a/include/linux/if_macvlan.h +++ b/include/linux/if_macvlan.h | |||
@@ -52,6 +52,9 @@ struct macvlan_pcpu_stats { | |||
52 | */ | 52 | */ |
53 | #define MAX_MACVTAP_QUEUES (NR_CPUS < 16 ? NR_CPUS : 16) | 53 | #define MAX_MACVTAP_QUEUES (NR_CPUS < 16 ? NR_CPUS : 16) |
54 | 54 | ||
55 | #define MACVLAN_MC_FILTER_BITS 8 | ||
56 | #define MACVLAN_MC_FILTER_SZ (1 << MACVLAN_MC_FILTER_BITS) | ||
57 | |||
55 | struct macvlan_dev { | 58 | struct macvlan_dev { |
56 | struct net_device *dev; | 59 | struct net_device *dev; |
57 | struct list_head list; | 60 | struct list_head list; |
@@ -59,6 +62,9 @@ struct macvlan_dev { | |||
59 | struct macvlan_port *port; | 62 | struct macvlan_port *port; |
60 | struct net_device *lowerdev; | 63 | struct net_device *lowerdev; |
61 | struct macvlan_pcpu_stats __percpu *pcpu_stats; | 64 | struct macvlan_pcpu_stats __percpu *pcpu_stats; |
65 | |||
66 | DECLARE_BITMAP(mc_filter, MACVLAN_MC_FILTER_SZ); | ||
67 | |||
62 | enum macvlan_mode mode; | 68 | enum macvlan_mode mode; |
63 | u16 flags; | 69 | u16 flags; |
64 | int (*receive)(struct sk_buff *skb); | 70 | int (*receive)(struct sk_buff *skb); |