Skip to content

Commit f74877a

Browse files
mkubecekdavem330
authored andcommitted
rtnetlink: provide permanent hardware address in RTM_NEWLINK
Permanent hardware address of a network device was traditionally provided via ethtool ioctl interface but as Jiri Pirko pointed out in a review of ethtool netlink interface, rtnetlink is much more suitable for it so let's add it to the RTM_NEWLINK message. Add IFLA_PERM_ADDRESS attribute to RTM_NEWLINK messages unless the permanent address is all zeros (i.e. device driver did not fill it). As permanent address is not modifiable, reject userspace requests containing IFLA_PERM_ADDRESS attribute. Note: we already provide permanent hardware address for bond slaves; unfortunately we cannot drop that attribute for backward compatibility reasons. v5 -> v6: only add the attribute if permanent address is not zero Signed-off-by: Michal Kubecek <mkubecek@suse.cz> Acked-by: Jiri Pirko <jiri@mellanox.com> Acked-by: Stephen Hemminger <stephen@networkplumber.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 545a682 commit f74877a

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

‎include/uapi/linux/if_link.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ enum {
169169
IFLA_MAX_MTU,
170170
IFLA_PROP_LIST,
171171
IFLA_ALT_IFNAME, /* Alternative ifname */
172+
IFLA_PERM_ADDRESS,
172173
__IFLA_MAX
173174
};
174175

‎net/core/rtnetlink.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,7 @@ static noinline size_t if_nlmsg_size(const struct net_device *dev,
10411041
+ nla_total_size(4) /* IFLA_MIN_MTU */
10421042
+ nla_total_size(4) /* IFLA_MAX_MTU */
10431043
+ rtnl_prop_list_size(dev)
1044+
+ nla_total_size(MAX_ADDR_LEN) /* IFLA_PERM_ADDRESS */
10441045
+ 0;
10451046
}
10461047

@@ -1757,6 +1758,9 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb,
17571758
nla_put_s32(skb, IFLA_NEW_IFINDEX, new_ifindex) < 0)
17581759
goto nla_put_failure;
17591760

1761+
if (memchr_inv(dev->perm_addr, '\0', dev->addr_len) &&
1762+
nla_put(skb, IFLA_PERM_ADDRESS, dev->addr_len, dev->perm_addr))
1763+
goto nla_put_failure;
17601764

17611765
rcu_read_lock();
17621766
if (rtnl_fill_link_af(skb, dev, ext_filter_mask))
@@ -1822,6 +1826,7 @@ static const struct nla_policy ifla_policy[IFLA_MAX+1] = {
18221826
[IFLA_PROP_LIST] = { .type = NLA_NESTED },
18231827
[IFLA_ALT_IFNAME] = { .type = NLA_STRING,
18241828
.len = ALTIFNAMSIZ - 1 },
1829+
[IFLA_PERM_ADDRESS] = { .type = NLA_REJECT },
18251830
};
18261831

18271832
static const struct nla_policy ifla_info_policy[IFLA_INFO_MAX+1] = {

0 commit comments

Comments
 (0)