Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2740556imj; Mon, 18 Feb 2019 11:16:43 -0800 (PST) X-Google-Smtp-Source: AHgI3IZb5PW6cbbLpxQQswoKMSWmlAr1zyO66R7y8dhUfXc5T2DDi7AyjCqrREK1v4Sh5ycUSr+y X-Received: by 2002:a63:6ac5:: with SMTP id f188mr20405769pgc.165.1550517403667; Mon, 18 Feb 2019 11:16:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550517403; cv=none; d=google.com; s=arc-20160816; b=gj0y277wsXkZOGhTVzhRBsqbRNCev/HJfnC291DW/JFpc4wRaENAMe5K6q1Zk1yhzb 7Tf4vNuSDsHMUeDtLZ/4Ng1a2QuAPkvRMiE3Gy2GugvCv/a0BrYUEikEvnpqg4zd42TG pb/wDBbib81KC5peOmNGJPy6XEdv4jwIH6OdU/GAPqHhwIsFLNi0+ozheHHsY4tqhI5e lx8Tn8Af6Ickj0pDTILzXPhumY0XnxDAm3/69X4eBhw7ngvBaMzfUZPnVxcqPc7TAQkE ZC0wb1R28e17gHX7fQkbAOT0b42tObagO/1+B9sCk88hjRF8eutQ/kZSouKNzelEE1Cs Y0Cw== 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=NzGFGX83obitZUaceht/VaQuZ8rN96XWM6PLoIKs6nc=; b=pWnQYdgLytLUDGSHKbWaBOahxrHbIetb2cNPyBqu7sL9u7Lwm7zBKh4hlIpSBua9Zo 9alerW/LuO8avgfUoKPn0MvdZdjvR/BM09BgzuKy13IB35VYYLJSiuKZrBBjDDd4LObJ M/114h+sBBxge6iyvJyqmigJk5NJi2IQsjUoXP1+ohF1M1NAoDW2mSX45FQKomdnmLbO fML2Zn1qEHc1r+n6l39fAD0pb0gKabeAGcSq1TgE9fo1piMrQsaG2mXCbiEH2qpOssgl ubLLQlCHNeGbCkC8vuA5wbLAX77x3xr4FjSHdxFCawgv6tOOE5ImqlEWPRcpr3jy8sAi OGRw== 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 e9si3208827pgg.199.2019.02.18.11.16.28; Mon, 18 Feb 2019 11:16:43 -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 S2403957AbfBRSW3 (ORCPT + 99 others); Mon, 18 Feb 2019 13:22:29 -0500 Received: from mx2.suse.de ([195.135.220.15]:46784 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2391476AbfBRSW1 (ORCPT ); Mon, 18 Feb 2019 13:22:27 -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 2F7D6AFD4; Mon, 18 Feb 2019 18:22:25 +0000 (UTC) Received: by unicorn.suse.cz (Postfix, from userid 1000) id D265FE0122; Mon, 18 Feb 2019 19:22:24 +0100 (CET) Message-Id: <4e5879e36289c526dc79db37e55e5fc7d89d15fe.1550513384.git.mkubecek@suse.cz> In-Reply-To: References: From: Michal Kubecek Subject: [RFC PATCH net-next v3 12/21] ethtool: provide permanent hardware address in GET_INFO request To: netdev@vger.kernel.org Cc: David Miller , Andrew Lunn , Jakub Kicinski , Jiri Pirko , linux-kernel@vger.kernel.org Date: Mon, 18 Feb 2019 19:22:24 +0100 (CET) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add information about permanent hadware address of a device (as provided by ETHTOOL_GPERMADDR ioctl command) in GET_INFO reply if ETH_INFO_IM_PERMADDR flag is set in the request. There is no separate attribute for hardware address length as nla_len gives this information. The reply also provides address type (net_device::type). Signed-off-by: Michal Kubecek --- Documentation/networking/ethtool-netlink.txt | 9 ++++- include/uapi/linux/ethtool_netlink.h | 12 +++++- net/ethtool/info.c | 39 ++++++++++++++++++++ 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/Documentation/networking/ethtool-netlink.txt b/Documentation/networking/ethtool-netlink.txt index b6999a2167e8..1e615e111262 100644 --- a/Documentation/networking/ethtool-netlink.txt +++ b/Documentation/networking/ethtool-netlink.txt @@ -239,6 +239,9 @@ Kernel response contents: ETHA_DRVINFO_FWVERSION (string) firmware version ETHA_DRVINFO_BUSINFO (string) device bus address ETHA_DRVINFO_EROM_VER (string) expansion ROM version + ETHA_INFO_PERMADDR (nested) + ETHA_PERMADDR_ADDRESS (binary) permanent HW address + ETHA_PERMADDR_TYPE (u16) dev->type The meaning of DRVINFO attributes follows the corresponding fields of ETHTOOL_GDRVINFO response. Second part with various counts and sizes is @@ -246,6 +249,10 @@ omitted as these are not really needed (and if they are, they can be easily found by different means). Driver version is also omitted as it is rather misleading in most cases. +There is no separate attribute for permanent address length as the length can +be determined from attribute length (nla_len()). ETHA_PERMADDR_TYPE provides +net_device::type value to give a hint about what kind of address device has. + GET_INFO requests allow dumps. @@ -288,7 +295,7 @@ ETHTOOL_PHYS_ID n/a ETHTOOL_GSTATS n/a ETHTOOL_GTSO n/a ETHTOOL_STSO n/a -ETHTOOL_GPERMADDR n/a +ETHTOOL_GPERMADDR ETHNL_CMD_GET_INFO ETHTOOL_GUFO n/a ETHTOOL_SUFO n/a ETHTOOL_GGSO n/a diff --git a/include/uapi/linux/ethtool_netlink.h b/include/uapi/linux/ethtool_netlink.h index fdae12b6c6b6..fb756b6a8592 100644 --- a/include/uapi/linux/ethtool_netlink.h +++ b/include/uapi/linux/ethtool_netlink.h @@ -153,8 +153,9 @@ enum { }; #define ETH_INFO_IM_DRVINFO 0x01 +#define ETH_INFO_IM_PERMADDR 0x02 -#define ETH_INFO_IM_ALL 0x01 +#define ETH_INFO_IM_ALL 0x03 enum { ETHA_DRVINFO_UNSPEC, @@ -167,6 +168,15 @@ enum { ETHA_DRVINFO_MAX = (__ETHA_DRVINFO_CNT - 1) }; +enum { + ETHA_PERMADDR_UNSPEC, + ETHA_PERMADDR_ADDRESS, /* binary */ + ETHA_PERMADDR_TYPE, /* u16 */ + + __ETHA_PERMADDR_CNT, + ETHA_PERMADDR_MAX = (__ETHA_PERMADDR_CNT - 1) +}; + /* generic netlink info */ #define ETHTOOL_GENL_NAME "ethtool" #define ETHTOOL_GENL_VERSION 1 diff --git a/net/ethtool/info.c b/net/ethtool/info.c index 1a2e78d238e3..05dbd87ebc41 100644 --- a/net/ethtool/info.c +++ b/net/ethtool/info.c @@ -18,6 +18,7 @@ static const struct nla_policy get_info_policy[ETHA_INFO_MAX + 1] = { [ETHA_INFO_INFOMASK] = { .type = NLA_U32 }, [ETHA_INFO_COMPACT] = { .type = NLA_FLAG }, [ETHA_INFO_DRVINFO] = { .type = NLA_REJECT }, + [ETHA_INFO_PERMADDR] = { .type = NLA_REJECT }, }; static int parse_info(struct common_req_info *req_info, struct sk_buff *skb, @@ -86,16 +87,29 @@ static int drvinfo_size(const struct ethtool_drvinfo *drvinfo) return nla_total_size(len); } +static int permaddr_size(const struct net_device *dev) +{ + int len = 0; + + len += nla_total_size(dev->addr_len); + len += nla_total_size(sizeof(u16)); + + return nla_total_size(len); +} + static int info_size(const struct common_req_info *req_info) { const struct info_data *data = container_of(req_info, struct info_data, reqinfo_base); + const struct net_device *dev = data->repdata_base.dev; u32 info_mask = data->repdata_base.info_mask; int len = 0; len += dev_ident_size(); if (info_mask & ETH_INFO_IM_DRVINFO) len += drvinfo_size(&data->drvinfo); + if (info_mask & ETH_INFO_IM_PERMADDR) + len += permaddr_size(dev); return len; } @@ -124,6 +138,26 @@ static int fill_drvinfo(struct sk_buff *skb, return ret; } +static int fill_permaddr(struct sk_buff *skb, const struct net_device *dev) +{ + struct nlattr *nest = ethnl_nest_start(skb, ETHA_INFO_PERMADDR); + int ret; + + if (!nest) + return -EMSGSIZE; + ret = -EMSGSIZE; + if (nla_put(skb, ETHA_PERMADDR_ADDRESS, dev->addr_len, dev->perm_addr)) + goto err; + if (nla_put_u16(skb, ETHA_PERMADDR_TYPE, dev->type)) + goto err; + + nla_nest_end(skb, nest); + return 0; +err: + nla_nest_cancel(skb, nest); + return ret; +} + static int fill_info(struct sk_buff *skb, const struct common_req_info *req_info) { @@ -137,6 +171,11 @@ static int fill_info(struct sk_buff *skb, if (ret < 0) return ret; } + if (info_mask & ETH_INFO_IM_PERMADDR) { + ret = fill_permaddr(skb, data->repdata_base.dev); + if (ret < 0) + return ret; + } return 0; } -- 2.20.1