Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp5376056ybl; Tue, 10 Dec 2019 05:08:54 -0800 (PST) X-Google-Smtp-Source: APXvYqy4zzF4/GAJLQJCARw/eqpmEbDN27avf34E3dHkpA1iTUwSJGjeV6d4Gm7yRXF8puaIFdC9 X-Received: by 2002:a05:6830:18e6:: with SMTP id d6mr26678216otf.170.1575983334336; Tue, 10 Dec 2019 05:08:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575983334; cv=none; d=google.com; s=arc-20160816; b=tV0NnrS2yWYJxOB8Zmqm9dk6Rm30a/1nNpuz51i1CWvdZsGfYDZlwGvQOK8VDdRER0 DE5QBUlOk+3Yetf5zg/E9EEoT8mE7c7wpXeXxod73EwO4ARk95R3fYQqhWl7WqPo29y1 twGdSWf3HX5G91Nl/7Rm0mgiLn5bT09u4Hc+hPwu1JCNWaniV6PDS61lXoxknBTLXT7D PruVMOrQ7/qPblPKaMfDpjETV/rse/nC5R2Y0aB5GkAuVAsyFy+Ei/ceWlt/FAFnW/nU sSXOToj+QL41DOBo7YyYJizpAEtS5O3XinLCOYP6lTH4dFiMH78o2YXLSaS88xwV3m49 DIag== 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=GmuJqdjYlQ5LOowU/IFERYMtbdKnErE5tGr0o+ttqGw=; b=wOdDm9j8kUlpEbHZRCsap0B6m37BCtNUanBvjz/DIPMz6C2XCV8tBmY14bJSr2fb+S GbZZNVMV26R6bbGW9zJk+oZ6i/j1x3clhAWCs5PHQomF13bm8zwQLs60GI6ORxlUtz0t x7f+M524G/9xISKCagSWB8LBq3lc1avC60rSRO3ddHqFjQqWAkEB/j+eRZshDiWzP/Aq Pu0Y7qqVZRdJtZXD+iRhCQKbM4CC8ApPETJr+eqZN2LUBeHxvQYuCpZsVW8NSGvdrgBg qvL6HC5H8UcKhdAJ3kSLCsWWhrtDZX+cv1OGK+6o9jdfVAjXVSg2Q/boCNJeGtO+aWsH NF+w== 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 b133si1925869oii.155.2019.12.10.05.08.39; Tue, 10 Dec 2019 05:08:54 -0800 (PST) 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 S1727536AbfLJNH7 (ORCPT + 99 others); Tue, 10 Dec 2019 08:07:59 -0500 Received: from mx2.suse.de ([195.135.220.15]:49002 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727387AbfLJNHz (ORCPT ); Tue, 10 Dec 2019 08:07:55 -0500 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 A2CF7ABC4; Tue, 10 Dec 2019 13:07:53 +0000 (UTC) Received: by unicorn.suse.cz (Postfix, from userid 1000) id 52FD9E00E0; Tue, 10 Dec 2019 14:07:53 +0100 (CET) Message-Id: <7c28b1aa87436515de39e04206db36f6f374dc2f.1575982069.git.mkubecek@suse.cz> In-Reply-To: References: From: Michal Kubecek Subject: [PATCH net-next v2 1/5] 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, 10 Dec 2019 14:07:53 +0100 (CET) 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 02916f43bf63..20bc406f3871 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; } @@ -1757,6 +1758,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)) @@ -1822,6 +1826,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.24.0