Skip to content

Commit 48eab83

Browse files
kuba-moodavem330
authored andcommitted
net: create netdev->dev_addr assignment helpers
Recent work on converting address list to a tree made it obvious we need an abstraction around writing netdev->dev_addr. Without such abstraction updating the main device address is invisible to the core. Introduce a number of helpers which for now just wrap memcpy() but in the future can make necessary changes to the address tree. Signed-off-by: Jakub Kicinski <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 8c9bc82 commit 48eab83

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

include/linux/etherdevice.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,18 @@ static inline void ether_addr_copy(u8 *dst, const u8 *src)
299299
#endif
300300
}
301301

302+
/**
303+
* eth_hw_addr_set - Assign Ethernet address to a net_device
304+
* @dev: pointer to net_device structure
305+
* @addr: address to assign
306+
*
307+
* Assign given address to the net_device, addr_assign_type is not changed.
308+
*/
309+
static inline void eth_hw_addr_set(struct net_device *dev, const u8 *addr)
310+
{
311+
ether_addr_copy(dev->dev_addr, addr);
312+
}
313+
302314
/**
303315
* eth_hw_addr_inherit - Copy dev_addr from another net_device
304316
* @dst: pointer to net_device to copy dev_addr to

include/linux/netdevice.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4641,6 +4641,24 @@ void __hw_addr_unsync_dev(struct netdev_hw_addr_list *list,
46414641
void __hw_addr_init(struct netdev_hw_addr_list *list);
46424642

46434643
/* Functions used for device addresses handling */
4644+
static inline void
4645+
__dev_addr_set(struct net_device *dev, const u8 *addr, size_t len)
4646+
{
4647+
memcpy(dev->dev_addr, addr, len);
4648+
}
4649+
4650+
static inline void dev_addr_set(struct net_device *dev, const u8 *addr)
4651+
{
4652+
__dev_addr_set(dev, addr, dev->addr_len);
4653+
}
4654+
4655+
static inline void
4656+
dev_addr_mod(struct net_device *dev, unsigned int offset,
4657+
const u8 *addr, size_t len)
4658+
{
4659+
memcpy(&dev->dev_addr[offset], addr, len);
4660+
}
4661+
46444662
int dev_addr_add(struct net_device *dev, const unsigned char *addr,
46454663
unsigned char addr_type);
46464664
int dev_addr_del(struct net_device *dev, const unsigned char *addr,

0 commit comments

Comments
 (0)