diff options
author | Jiri Pirko <jpirko@redhat.com> | 2009-05-04 22:48:28 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2009-05-05 15:26:24 -0400 |
commit | f001fde5eadd915f4858d22ed70d7040f48767cf (patch) | |
tree | f03fd0216b411e4a076e464861aa959e5b51edb0 /include/linux | |
parent | b6907b0c705b6db221f937b4d343e2a6b280c8c5 (diff) |
net: introduce a list of device addresses dev_addr_list (v6)
v5 -> v6 (current):
-removed so far unused static functions
-corrected dev_addr_del_multiple to call del instead of add
v4 -> v5:
-added device address type (suggested by davem)
-removed refcounting (better to have simplier code then safe potentially few
bytes)
v3 -> v4:
-changed kzalloc to kmalloc in __hw_addr_add_ii()
-ASSERT_RTNL() avoided in dev_addr_flush() and dev_addr_init()
v2 -> v3:
-removed unnecessary rcu read locking
-moved dev_addr_flush() calling to ensure no null dereference of dev_addr
v1 -> v2:
-added forgotten ASSERT_RTNL to dev_addr_init and dev_addr_flush
-removed unnecessary rcu_read locking in dev_addr_init
-use compare_ether_addr_64bits instead of compare_ether_addr
-use L1_CACHE_BYTES as size for allocating struct netdev_hw_addr
-use call_rcu instead of rcu_synchronize
-moved is_etherdev_addr into __KERNEL__ ifdef
This patch introduces a new list in struct net_device and brings a set of
functions to handle the work with device address list. The list is a replacement
for the original dev_addr field and because in some situations there is need to
carry several device addresses with the net device. To be backward compatible,
dev_addr is made to point to the first member of the list so original drivers
sees no difference.
Signed-off-by: Jiri Pirko <jpirko@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/linux')
-rw-r--r-- | include/linux/etherdevice.h | 27 | ||||
-rw-r--r-- | include/linux/netdevice.h | 37 |
2 files changed, 62 insertions, 2 deletions
diff --git a/include/linux/etherdevice.h b/include/linux/etherdevice.h index a1f17abba7dc..3d7a6687d247 100644 --- a/include/linux/etherdevice.h +++ b/include/linux/etherdevice.h | |||
@@ -182,6 +182,33 @@ static inline unsigned compare_ether_addr_64bits(const u8 addr1[6+2], | |||
182 | return compare_ether_addr(addr1, addr2); | 182 | return compare_ether_addr(addr1, addr2); |
183 | #endif | 183 | #endif |
184 | } | 184 | } |
185 | |||
186 | /** | ||
187 | * is_etherdev_addr - Tell if given Ethernet address belongs to the device. | ||
188 | * @dev: Pointer to a device structure | ||
189 | * @addr: Pointer to a six-byte array containing the Ethernet address | ||
190 | * | ||
191 | * Compare passed address with all addresses of the device. Return true if the | ||
192 | * address if one of the device addresses. | ||
193 | * | ||
194 | * Note that this function calls compare_ether_addr_64bits() so take care of | ||
195 | * the right padding. | ||
196 | */ | ||
197 | static inline bool is_etherdev_addr(const struct net_device *dev, | ||
198 | const u8 addr[6 + 2]) | ||
199 | { | ||
200 | struct netdev_hw_addr *ha; | ||
201 | int res = 1; | ||
202 | |||
203 | rcu_read_lock(); | ||
204 | for_each_dev_addr(dev, ha) { | ||
205 | res = compare_ether_addr_64bits(addr, ha->addr); | ||
206 | if (!res) | ||
207 | break; | ||
208 | } | ||
209 | rcu_read_unlock(); | ||
210 | return !res; | ||
211 | } | ||
185 | #endif /* __KERNEL__ */ | 212 | #endif /* __KERNEL__ */ |
186 | 213 | ||
187 | /** | 214 | /** |
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index ff42aba403c5..02882e2ebd49 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h | |||
@@ -210,6 +210,16 @@ struct dev_addr_list | |||
210 | #define dmi_users da_users | 210 | #define dmi_users da_users |
211 | #define dmi_gusers da_gusers | 211 | #define dmi_gusers da_gusers |
212 | 212 | ||
213 | struct netdev_hw_addr { | ||
214 | struct list_head list; | ||
215 | unsigned char addr[MAX_ADDR_LEN]; | ||
216 | unsigned char type; | ||
217 | #define NETDEV_HW_ADDR_T_LAN 1 | ||
218 | #define NETDEV_HW_ADDR_T_SAN 2 | ||
219 | #define NETDEV_HW_ADDR_T_SLAVE 3 | ||
220 | struct rcu_head rcu_head; | ||
221 | }; | ||
222 | |||
213 | struct hh_cache | 223 | struct hh_cache |
214 | { | 224 | { |
215 | struct hh_cache *hh_next; /* Next entry */ | 225 | struct hh_cache *hh_next; /* Next entry */ |
@@ -784,8 +794,11 @@ struct net_device | |||
784 | */ | 794 | */ |
785 | unsigned long last_rx; /* Time of last Rx */ | 795 | unsigned long last_rx; /* Time of last Rx */ |
786 | /* Interface address info used in eth_type_trans() */ | 796 | /* Interface address info used in eth_type_trans() */ |
787 | unsigned char dev_addr[MAX_ADDR_LEN]; /* hw address, (before bcast | 797 | unsigned char *dev_addr; /* hw address, (before bcast |
788 | because most packets are unicast) */ | 798 | because most packets are |
799 | unicast) */ | ||
800 | |||
801 | struct list_head dev_addr_list; /* list of device hw addresses */ | ||
789 | 802 | ||
790 | unsigned char broadcast[MAX_ADDR_LEN]; /* hw bcast add */ | 803 | unsigned char broadcast[MAX_ADDR_LEN]; /* hw bcast add */ |
791 | 804 | ||
@@ -1791,6 +1804,13 @@ static inline void netif_addr_unlock_bh(struct net_device *dev) | |||
1791 | spin_unlock_bh(&dev->addr_list_lock); | 1804 | spin_unlock_bh(&dev->addr_list_lock); |
1792 | } | 1805 | } |
1793 | 1806 | ||
1807 | /* | ||
1808 | * dev_addr_list walker. Should be used only for read access. Call with | ||
1809 | * rcu_read_lock held. | ||
1810 | */ | ||
1811 | #define for_each_dev_addr(dev, ha) \ | ||
1812 | list_for_each_entry_rcu(ha, &dev->dev_addr_list, list) | ||
1813 | |||
1794 | /* These functions live elsewhere (drivers/net/net_init.c, but related) */ | 1814 | /* These functions live elsewhere (drivers/net/net_init.c, but related) */ |
1795 | 1815 | ||
1796 | extern void ether_setup(struct net_device *dev); | 1816 | extern void ether_setup(struct net_device *dev); |
@@ -1803,6 +1823,19 @@ extern struct net_device *alloc_netdev_mq(int sizeof_priv, const char *name, | |||
1803 | alloc_netdev_mq(sizeof_priv, name, setup, 1) | 1823 | alloc_netdev_mq(sizeof_priv, name, setup, 1) |
1804 | extern int register_netdev(struct net_device *dev); | 1824 | extern int register_netdev(struct net_device *dev); |
1805 | extern void unregister_netdev(struct net_device *dev); | 1825 | extern void unregister_netdev(struct net_device *dev); |
1826 | |||
1827 | /* Functions used for device addresses handling */ | ||
1828 | extern int dev_addr_add(struct net_device *dev, unsigned char *addr, | ||
1829 | unsigned char addr_type); | ||
1830 | extern int dev_addr_del(struct net_device *dev, unsigned char *addr, | ||
1831 | unsigned char addr_type); | ||
1832 | extern int dev_addr_add_multiple(struct net_device *to_dev, | ||
1833 | struct net_device *from_dev, | ||
1834 | unsigned char addr_type); | ||
1835 | extern int dev_addr_del_multiple(struct net_device *to_dev, | ||
1836 | struct net_device *from_dev, | ||
1837 | unsigned char addr_type); | ||
1838 | |||
1806 | /* Functions used for secondary unicast and multicast support */ | 1839 | /* Functions used for secondary unicast and multicast support */ |
1807 | extern void dev_set_rx_mode(struct net_device *dev); | 1840 | extern void dev_set_rx_mode(struct net_device *dev); |
1808 | extern void __dev_set_rx_mode(struct net_device *dev); | 1841 | extern void __dev_set_rx_mode(struct net_device *dev); |