Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp1423252ybp; Wed, 9 Oct 2019 13:59:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqy2GZkiavXfErGBR4GKy28tyFu3BxLFxCQM8lLOw6nEQNYl0eHrDGspoKEdlN885AnGpzlm X-Received: by 2002:a17:907:366:: with SMTP id rs6mr4778416ejb.232.1570654785093; Wed, 09 Oct 2019 13:59:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570654785; cv=none; d=google.com; s=arc-20160816; b=y5nbkBQP76b/Cyy7EU2PpLNWB2lBgRbgcZeInE3AsHJ3dv3D66jtG2wtZgWKZbLcmW e2iJZhpDfKepcbqAAgUvMPTgTh9ckJgTlrbGky0H+R7L0njxTwegcsGpZSQpRxDfQcJM osyG815TEK6uOrvDdI39XF7s/I32dfX/VBBnz2UclRuF4FpODzTJ25bPZoilQVwGffnG MI6AtW+fcsDSg2oAyQXoUdy82hhZFGpgd3NCexPK6uUUv0IoLeUbRX/EBgdIgBqitIdk BetZz4B0J4Jp8iB5Txr7RGd/1EFkUsxcHURkDXg6AY57Vnk2Td57fQ3rOaeX4ObTS2Na LNtQ== 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=Jn9RVE0jjm06BTPDWySxguOBm26OqM2EXDg55RofaL0=; b=OBIl75yghq7seLtoWXs62MK0xMu5wykaj4JzxfEjeVfXrl+XXa1hJZFqM/6OOyw+wK UrGtZgkFkWiYcJtmwrQ+bwmf2Cad8+nxC23GVgeG/Rr8SdzuiXD0jwcnNgFbjYX2WfZv CW0kbDYgryFdxl82+efUqrArAhUKfJMP9S55gnqrq88+3Cbjtm0lmQ1H9FpIM6hQBxyF 6a//WvzyIVw2weqeOuCypCaBf8gt/mnhZjxoeL0vQQTCgEhfFfmDcgieJ/WmBavtt+x4 pprsSSZQ1pI/bRbTomAf/d3OeGg9GggPU+tQYag5yFtLJymhKG50/XJBbb4NT+y5pFdh jV/g== 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 t18si1857301ejr.416.2019.10.09.13.59.21; Wed, 09 Oct 2019 13:59:45 -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 S1732017AbfJIU7H (ORCPT + 99 others); Wed, 9 Oct 2019 16:59:07 -0400 Received: from mx2.suse.de ([195.135.220.15]:51262 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731937AbfJIU7H (ORCPT ); Wed, 9 Oct 2019 16:59:07 -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 1A2B3B231; Wed, 9 Oct 2019 20:59:04 +0000 (UTC) Received: by unicorn.suse.cz (Postfix, from userid 1000) id B10CAE3786; Wed, 9 Oct 2019 22:59:03 +0200 (CEST) Message-Id: <31de19d474dcce77dc17d31d2f31f015ddccb713.1570654310.git.mkubecek@suse.cz> In-Reply-To: References: From: Michal Kubecek Subject: [PATCH net-next v7 01/17] 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: Wed, 9 Oct 2019 22:59:03 +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 Acked-by: Jiri Pirko Acked-by: Stephen Hemminger --- 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 8aec8769d944..1d69f637c5d6 100644 --- a/include/uapi/linux/if_link.h +++ b/include/uapi/linux/if_link.h @@ -169,6 +169,7 @@ enum { IFLA_MAX_MTU, IFLA_PROP_LIST, IFLA_ALT_IFNAME, /* Alternative ifname */ + IFLA_PERM_ADDRESS, __IFLA_MAX }; diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 49fa910b58af..a3c1228db273 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -1041,6 +1041,7 @@ static noinline size_t if_nlmsg_size(const struct net_device *dev, + nla_total_size(4) /* IFLA_MIN_MTU */ + nla_total_size(4) /* IFLA_MAX_MTU */ + rtnl_prop_list_size(dev) + + nla_total_size(MAX_ADDR_LEN) /* IFLA_PERM_ADDRESS */ + 0; } @@ -1741,6 +1742,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)) @@ -1806,6 +1810,7 @@ static const struct nla_policy ifla_policy[IFLA_MAX+1] = { [IFLA_PROP_LIST] = { .type = NLA_NESTED }, [IFLA_ALT_IFNAME] = { .type = NLA_STRING, .len = ALTIFNAMSIZ - 1 }, + [IFLA_PERM_ADDRESS] = { .type = NLA_REJECT }, }; static const struct nla_policy ifla_info_policy[IFLA_INFO_MAX+1] = { -- 2.23.0