Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3259334ybi; Tue, 2 Jul 2019 04:53:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqxbPPiObgVd+9rW/LxI0G650gQwchWMAyYEw5c2vQz6rZ9oYOMgkKXxlpJFE0JZP+uJxgL/ X-Received: by 2002:a63:d410:: with SMTP id a16mr29253320pgh.122.1562068391770; Tue, 02 Jul 2019 04:53:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562068391; cv=none; d=google.com; s=arc-20160816; b=SS2/GNWfbpJF7v8JowajIBQXs5d2fHBwiQ8abAGG+5iwdosqDRpxb6sZtyEY05kEKZ h6GJ8wZddiENe5fnX7S5c96P6eiA7Ey0/K1nZEWAEhaPf7oCyT6V8Tf3Yg9AM4OmhkZo 0GcakkcMyx+x+aT0hEHec0uYEGqDUM/UdYbzeVuqY+uBShGfdCdtOweSf4bTUDaFbxnR psfH7UmEEEVPzaB2DuNBaoMsR25ErRGLS5qYmmk6dbOrI61wNTSARY8rXsefpCrmVpYI /qEQ0+Sm/tUC2i9A1S4nezCqrSEkW0So1d43MYBZAKEh81g2KuCT60J+cO8wTsvHa6Ti 0kyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:cc:to:subject:from:references :in-reply-to:message-id; bh=BV7SQPvE1j/BJoaMWgVteTzkeAqM7cMgYLT8b0nTTVg=; b=BNgrlaTrdqg0EnDdDTtRMTuG4QvUKPilTQP6UeDeWbsyJQVoA/92crztefeGHNYMZp 5ISC/pn97bOAQ9GOlhXXHTVF64PZrugNKH0awXXCUgFDk3xWBknh8PxY5Cpo9e/5kEC5 m5ICjJZA0D2G/tT3Z3rZLyeDOdSbrslClZ3ZHQSekvbN+4EuMQ58RP4se1jqtIAdSnXt g0VqPJ2i8KbdTKMRn5nIvhWKeYME/npJ23jM4UWtXihjPiaA/WClHUkDTnPsi5xrFsKn EaaBwvx1sd2RDeryZ0X/EKLR1uYmc+E4rZmHuiFKI7x/8rJqEIBN/f9ab6Lz8X1N2Qrr v5sg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f4si12326057plt.81.2019.07.02.04.52.57; Tue, 02 Jul 2019 04:53:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726526AbfGBLtp (ORCPT + 99 others); Tue, 2 Jul 2019 07:49:45 -0400 Received: from mx2.suse.de ([195.135.220.15]:38270 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725867AbfGBLtp (ORCPT ); Tue, 2 Jul 2019 07:49:45 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 65B2FB090; Tue, 2 Jul 2019 11:49:44 +0000 (UTC) Received: by unicorn.suse.cz (Postfix, from userid 1000) id 1945BE0159; Tue, 2 Jul 2019 13:49:44 +0200 (CEST) Message-Id: In-Reply-To: References: From: Michal Kubecek Subject: [PATCH net-next v6 01/15] rtnetlink: provide permanent hardware address in RTM_NEWLINK To: David Miller , netdev@vger.kernel.org Cc: Jakub Kicinski , Jiri Pirko , Andrew Lunn , Florian Fainelli , John Linville , Stephen Hemminger , Johannes Berg , linux-kernel@vger.kernel.org Date: Tue, 2 Jul 2019 13:49:44 +0200 (CEST) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- include/uapi/linux/if_link.h | 1 + net/core/rtnetlink.c | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h index 6f75bda2c2d7..1c79d6283a4d 100644 --- a/include/uapi/linux/if_link.h +++ b/include/uapi/linux/if_link.h @@ -167,6 +167,7 @@ enum { IFLA_NEW_IFINDEX, IFLA_MIN_MTU, IFLA_MAX_MTU, + IFLA_PERM_ADDRESS, __IFLA_MAX }; diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 1ee6460f8275..9aae53e8914e 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -1027,6 +1027,7 @@ static noinline size_t if_nlmsg_size(const struct net_device *dev, + nla_total_size(4) /* IFLA_CARRIER_DOWN_COUNT */ + nla_total_size(4) /* IFLA_MIN_MTU */ + nla_total_size(4) /* IFLA_MAX_MTU */ + + nla_total_size(MAX_ADDR_LEN) /* IFLA_PERM_ADDRESS */ + 0; } @@ -1691,6 +1692,9 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, nla_put_s32(skb, IFLA_NEW_IFINDEX, new_ifindex) < 0) goto nla_put_failure; + if (memchr_inv(dev->perm_addr, '\0', dev->addr_len) && + nla_put(skb, IFLA_PERM_ADDRESS, dev->addr_len, dev->perm_addr)) + goto nla_put_failure; rcu_read_lock(); if (rtnl_fill_link_af(skb, dev, ext_filter_mask)) @@ -1750,6 +1754,7 @@ static const struct nla_policy ifla_policy[IFLA_MAX+1] = { [IFLA_CARRIER_DOWN_COUNT] = { .type = NLA_U32 }, [IFLA_MIN_MTU] = { .type = NLA_U32 }, [IFLA_MAX_MTU] = { .type = NLA_U32 }, + [IFLA_PERM_ADDRESS] = { .type = NLA_REJECT }, }; static const struct nla_policy ifla_info_policy[IFLA_INFO_MAX+1] = { -- 2.22.0