Message ID | 1708531057-67392-2-git-send-email-jdamato@fastly.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-75055-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1127164dyc; Wed, 21 Feb 2024 08:00:30 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX204knlqvyiMme2QrTAhJcs4oVHu/u60LxBMhjGDVk/NNX4O2x66aOQjFoBI+yFdjYJDPTEisMzbXEfXktgMeFK2csyA== X-Google-Smtp-Source: AGHT+IGI4Zr7Y7lPDwKE2G/ei6IMpch8cExWPHRZSu6K94qz+8z5hUsxZfu+YCV4s5JrAWv6HFv2 X-Received: by 2002:a17:902:f78e:b0:1db:92e1:2e50 with SMTP id q14-20020a170902f78e00b001db92e12e50mr21785349pln.43.1708531230305; Wed, 21 Feb 2024 08:00:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708531230; cv=pass; d=google.com; s=arc-20160816; b=O8SP1YlSl+0UWQyMRSoeT9jeYWQqLGrL8MGMvD6BkQSg2Y40KbDxMURjFMR6/WWVhT KC0e3CfTDnbVOCBDhP7ahhuhUAqB+cRu+e/Z+j/tUNQEJEZeBCE2igk/XhyFYVfNB3oX bap1KNba+TvCnoJ2jFzaX7A3tbtOGya2w2IHKaBbsFtAYqndvw3nBr+qFDhqiPQMiyRv zzKIFDs8kT9KDVuZMQzyj6roJdqarZYYCSx5sijoJUAJ5p17VBxn/GanJzOyXGeUmfTi 2lvfPK5lLzPK1fIZx1Py8uHI+Mx0nv4l+0hRUwQJSgOjahH8fnGzl9KcG1DSgOgsKhab 6LZw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-id:precedence:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=4XNkLiaptlpOdgR8Lz2aXc5/cIA8mvoaalETxdH3pHc=; fh=ptGulEeiwet0VfiVPYK95EQcYytOm7Hj6lyN2EwWrck=; b=Y6p4L49U8+uRD9NvOFDAPwTaFQoRsKs344fhTA4oOF7mUKPBCnoKOJPiUJ2jJUQxLD 5UdXLOslBkbl35owBdxC7RaSmj/6LY9p7qJyNZwCVjWxrLLLJvlysqY3btQ0w2BL0C+q Uul3klDJp+EoNnhQZm/zSSO5ioeW8vuAHjetyEePSJgq6DHFhgAKjT9wBP19rGVHSBRb Wsd5vSI0InCJBbOBz0UcY6wOfuCH+HaqSzW1/WYmO68f+w8D2GTLKreHriGe4HqdaPUy D8U+jNJfECW8avMSuC/gLK3cWeo43HX4gnX3DNgNTQdKJ7KthnCPbwQtl+9NtIwGIxjr lZ5Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@fastly.com header.s=google header.b=lSb3bVQd; arc=pass (i=1 spf=pass spfdomain=fastly.com dkim=pass dkdomain=fastly.com dmarc=pass fromdomain=fastly.com); spf=pass (google.com: domain of linux-kernel+bounces-75055-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75055-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fastly.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id j6-20020a17090276c600b001db4585552bsi8234897plt.426.2024.02.21.08.00.30 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 08:00:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-75055-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@fastly.com header.s=google header.b=lSb3bVQd; arc=pass (i=1 spf=pass spfdomain=fastly.com dkim=pass dkdomain=fastly.com dmarc=pass fromdomain=fastly.com); spf=pass (google.com: domain of linux-kernel+bounces-75055-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75055-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fastly.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id AA0072869AA for <ouuuleilei@gmail.com>; Wed, 21 Feb 2024 16:00:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EC2DE82865; Wed, 21 Feb 2024 15:58:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=fastly.com header.i=@fastly.com header.b="lSb3bVQd" Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A7E83823C9 for <linux-kernel@vger.kernel.org>; Wed, 21 Feb 2024 15:58:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708531120; cv=none; b=kyslax3Ep1XA393++xgy4zwojQ0uVA896HmSVcVruEwvFMTxQTy5b5FphuG/RmOrUI2fMV+tdl5nYrTypZws396BZraFG3g0Qu/8AiMJTtLB8+pk2yFFggtvw74sQgLWXhxaq9AiCOvdMe5xEObmGOKdZebvNFrq9vkb18XtIlQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708531120; c=relaxed/simple; bh=b3I8DtEPynqthfDKMzjPijqG7ifvwN2QGor5pJwwtFs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=lbg0JV39mh3uA4jy+ieckrrlSVBNDZcxfJnoYP5g7AhHwoNTzuqCq6Z6pUAH4F82WRen4gUdwFFZTQmgi223RV+gCmGvsDSg91SYxlkxZ3csO/Ks5ZNDO91wl6XTbR3UcnPQqiGQnmX7e5EERHX9bTJ5qxcPRLqisdJrTWGuf+4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fastly.com; spf=pass smtp.mailfrom=fastly.com; dkim=pass (1024-bit key) header.d=fastly.com header.i=@fastly.com header.b=lSb3bVQd; arc=none smtp.client-ip=209.85.210.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fastly.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fastly.com Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-6e484011e28so1187087b3a.3 for <linux-kernel@vger.kernel.org>; Wed, 21 Feb 2024 07:58:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; t=1708531118; x=1709135918; darn=vger.kernel.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=4XNkLiaptlpOdgR8Lz2aXc5/cIA8mvoaalETxdH3pHc=; b=lSb3bVQdFNV5mWZVm6FPosSkw0o53PNt+pIe6I2s4h/XNnJNWxE5OSsKxRgAi6LeeB dwmRNn2puLPQny3HkXD/VKXfzEh25EckQSEpIh0v56K/l+0ZEK7cfZsY16/G1Qt1Y1Ef gTDoy3ntxlMm1/p/qNuYUsXRMXAuumFlczIiI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708531118; x=1709135918; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=4XNkLiaptlpOdgR8Lz2aXc5/cIA8mvoaalETxdH3pHc=; b=WdKOy3zCP1dm5iLFflxrHSgl/EAhUmqmKkd6EzgOGshcJ3eIhINfgJoqKYDQlj6x6E /RWjV9rHJat2KxExgxe1lwNyL/EX08V3CNQa/GTN3IWftKIMHSwiTL5FRxjd7eDi8qUy Tx5MeJ5J3QQtvc4WGhTrNDRd8tKwsIHvmwIOntPnOxe27Iu0sQQwUWKgTfGWY/Ev8w+S i1EGNKjQOcSofBW0DupNMGVuYMcNhCbV2XXJHtk5X7zxOCVshm4d/49ORVeRh+5rLOcW gMYcMRBZK/wH4/HxOga3TC/r1zZzK0XK/CmWZcao/eqJ6txNopJRErp+Rw8v4zfXVa4z w5rg== X-Forwarded-Encrypted: i=1; AJvYcCXGa+956i+CkAtesuEK4jSaoyIXVPp90AJHVrXjJa5PCL2VGcYWIg5uWmQCsPZFsOQuebZfiqZd/dJ/h4p6Y9jYCR/cEPgOMnfNo59j X-Gm-Message-State: AOJu0YwayrsXX2ksUebsPiZWBPWcPssrsGi8K/uenHoEoBA7rXbm44q/ 9jF++drfhtRME6l0Q3dMPa8V1BazgccLAd8aDMg/GuQm/8eCb4LE6jJ92pwyYLo= X-Received: by 2002:a05:6a00:2f81:b0:6e4:688e:2072 with SMTP id fm1-20020a056a002f8100b006e4688e2072mr6922023pfb.34.1708531118043; Wed, 21 Feb 2024 07:58:38 -0800 (PST) Received: from localhost.localdomain (c-24-6-151-244.hsd1.ca.comcast.net. [24.6.151.244]) by smtp.gmail.com with ESMTPSA id du17-20020a056a002b5100b006e46672df97sm5751327pfb.75.2024.02.21.07.58.36 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Feb 2024 07:58:37 -0800 (PST) From: Joe Damato <jdamato@fastly.com> To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Joe Damato <jdamato@fastly.com>, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, Jesper Dangaard Brouer <hawk@kernel.org>, Stanislav Fomichev <sdf@google.com>, Amritha Nambiar <amritha.nambiar@intel.com>, Larysa Zaremba <larysa.zaremba@intel.com>, Lorenzo Bianconi <lorenzo@kernel.org>, Tariq Toukan <tariqt@nvidia.com>, Sridhar Samudrala <sridhar.samudrala@intel.com>, Alexei Starovoitov <ast@kernel.org>, Maciej Fijalkowski <maciej.fijalkowski@intel.com> Subject: [PATCH net-next 1/2] netdev-genl: Add ifname for queue and NAPI APIs Date: Wed, 21 Feb 2024 07:57:29 -0800 Message-Id: <1708531057-67392-2-git-send-email-jdamato@fastly.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1708531057-67392-1-git-send-email-jdamato@fastly.com> References: <1708531057-67392-1-git-send-email-jdamato@fastly.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791524843281397403 X-GMAIL-MSGID: 1791524843281397403 |
Series |
[net-next,1/2] netdev-genl: Add ifname for queue and NAPI APIs
|
|
Commit Message
Joe Damato
Feb. 21, 2024, 3:57 p.m. UTC
Expose the netdevice name when queue and NAPI netdev-genl APIs are used
Signed-off-by: Joe Damato <jdamato@fastly.com>
---
include/uapi/linux/netdev.h | 2 ++
net/core/netdev-genl.c | 22 +++++++++++++++++-----
2 files changed, 19 insertions(+), 5 deletions(-)
Comments
On Wed, 21 Feb 2024 07:57:29 -0800 Joe Damato wrote: > if (GENL_REQ_ATTR_CHECK(info, NETDEV_A_QUEUE_ID) || > GENL_REQ_ATTR_CHECK(info, NETDEV_A_QUEUE_TYPE) || > - GENL_REQ_ATTR_CHECK(info, NETDEV_A_QUEUE_IFINDEX)) > + GENL_REQ_ATTR_CHECK(info, NETDEV_A_QUEUE_IFINDEX) || > + GENL_REQ_ATTR_CHECK(info, NETDEV_A_QUEUE_IFNAME)) This means user always has to provide both ifindex and ifname, right?
On 2/21/2024 7:57 AM, Joe Damato wrote: > Expose the netdevice name when queue and NAPI netdev-genl APIs are used > > Signed-off-by: Joe Damato <jdamato@fastly.com> > --- > include/uapi/linux/netdev.h | 2 ++ > net/core/netdev-genl.c | 22 +++++++++++++++++----- > 2 files changed, 19 insertions(+), 5 deletions(-) > > diff --git a/include/uapi/linux/netdev.h b/include/uapi/linux/netdev.h > index 93cb411..80762bc 100644 > --- a/include/uapi/linux/netdev.h > +++ b/include/uapi/linux/netdev.h > @@ -117,6 +117,7 @@ enum { > NETDEV_A_NAPI_ID, > NETDEV_A_NAPI_IRQ, > NETDEV_A_NAPI_PID, > + NETDEV_A_NAPI_IFNAME, > > __NETDEV_A_NAPI_MAX, > NETDEV_A_NAPI_MAX = (__NETDEV_A_NAPI_MAX - 1) > @@ -127,6 +128,7 @@ enum { > NETDEV_A_QUEUE_IFINDEX, > NETDEV_A_QUEUE_TYPE, > NETDEV_A_QUEUE_NAPI_ID, > + NETDEV_A_QUEUE_IFNAME, > > __NETDEV_A_QUEUE_MAX, > NETDEV_A_QUEUE_MAX = (__NETDEV_A_QUEUE_MAX - 1) > diff --git a/net/core/netdev-genl.c b/net/core/netdev-genl.c > index fd98936..a886e6a 100644 > --- a/net/core/netdev-genl.c > +++ b/net/core/netdev-genl.c > @@ -181,6 +181,9 @@ netdev_nl_napi_fill_one(struct sk_buff *rsp, struct napi_struct *napi, > if (nla_put_u32(rsp, NETDEV_A_NAPI_IFINDEX, napi->dev->ifindex)) > goto nla_put_failure; > > + if (nla_put_string(rsp, NETDEV_A_NAPI_IFNAME, napi->dev->name)) > + goto nla_put_failure; > + > if (napi->irq >= 0 && nla_put_u32(rsp, NETDEV_A_NAPI_IRQ, napi->irq)) > goto nla_put_failure; > > @@ -307,7 +310,8 @@ netdev_nl_queue_fill_one(struct sk_buff *rsp, struct net_device *netdev, > > if (nla_put_u32(rsp, NETDEV_A_QUEUE_ID, q_idx) || > nla_put_u32(rsp, NETDEV_A_QUEUE_TYPE, q_type) || > - nla_put_u32(rsp, NETDEV_A_QUEUE_IFINDEX, netdev->ifindex)) > + nla_put_u32(rsp, NETDEV_A_QUEUE_IFINDEX, netdev->ifindex) || > + nla_put_string(rsp, NETDEV_A_QUEUE_IFNAME, netdev->name)) > goto nla_put_failure; > > switch (q_type) { > @@ -369,16 +373,19 @@ int netdev_nl_queue_get_doit(struct sk_buff *skb, struct genl_info *info) > u32 q_id, q_type, ifindex; > struct net_device *netdev; > struct sk_buff *rsp; > + char *ifname; > int err; > > if (GENL_REQ_ATTR_CHECK(info, NETDEV_A_QUEUE_ID) || > GENL_REQ_ATTR_CHECK(info, NETDEV_A_QUEUE_TYPE) || > - GENL_REQ_ATTR_CHECK(info, NETDEV_A_QUEUE_IFINDEX)) > + GENL_REQ_ATTR_CHECK(info, NETDEV_A_QUEUE_IFINDEX) || > + GENL_REQ_ATTR_CHECK(info, NETDEV_A_QUEUE_IFNAME)) > return -EINVAL; > > q_id = nla_get_u32(info->attrs[NETDEV_A_QUEUE_ID]); > q_type = nla_get_u32(info->attrs[NETDEV_A_QUEUE_TYPE]); > ifindex = nla_get_u32(info->attrs[NETDEV_A_QUEUE_IFINDEX]); > + nla_strscpy(ifname, info->attrs[NETDEV_A_QUEUE_IFNAME], IFNAMSIZ); > > rsp = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL); > if (!rsp) > @@ -387,10 +394,15 @@ int netdev_nl_queue_get_doit(struct sk_buff *skb, struct genl_info *info) > rtnl_lock(); > > netdev = __dev_get_by_index(genl_info_net(info), ifindex); > - if (netdev) > - err = netdev_nl_queue_fill(rsp, netdev, q_id, q_type, info); > - else > + > + if (strcmp(netdev->name, ifname)) { > err = -ENODEV; > + } else { > + if (netdev) > + err = netdev_nl_queue_fill(rsp, netdev, q_id, q_type, info); > + else > + err = -ENODEV; > + } > This looks bit incorrect to me that the netdev is checked after netdev->name is accessed. Shouldn't this be something like: if (netdev && !strcmp(netdev->name, ifname)) err = netdev_nl_queue_fill(rsp, netdev, q_id, q_type, info); else err = -ENODEV; > rtnl_unlock(); >
On Wed, Feb 21, 2024 at 11:12:20AM -0800, Jakub Kicinski wrote: > On Wed, 21 Feb 2024 07:57:29 -0800 Joe Damato wrote: > > if (GENL_REQ_ATTR_CHECK(info, NETDEV_A_QUEUE_ID) || > > GENL_REQ_ATTR_CHECK(info, NETDEV_A_QUEUE_TYPE) || > > - GENL_REQ_ATTR_CHECK(info, NETDEV_A_QUEUE_IFINDEX)) > > + GENL_REQ_ATTR_CHECK(info, NETDEV_A_QUEUE_IFINDEX) || > > + GENL_REQ_ATTR_CHECK(info, NETDEV_A_QUEUE_IFNAME)) > > This means user always has to provide both ifindex and ifname, > right? That's right. I'm OK with omitting this requirement, though. I feel like to your earlier point on name changes, maybe ifindex is enough as far as required params go.
On Wed, Feb 21, 2024 at 11:12:47AM -0800, Nambiar, Amritha wrote: > On 2/21/2024 7:57 AM, Joe Damato wrote: > >Expose the netdevice name when queue and NAPI netdev-genl APIs are used > > > >Signed-off-by: Joe Damato <jdamato@fastly.com> > >--- > > include/uapi/linux/netdev.h | 2 ++ > > net/core/netdev-genl.c | 22 +++++++++++++++++----- > > 2 files changed, 19 insertions(+), 5 deletions(-) > > > >diff --git a/include/uapi/linux/netdev.h b/include/uapi/linux/netdev.h > >index 93cb411..80762bc 100644 > >--- a/include/uapi/linux/netdev.h > >+++ b/include/uapi/linux/netdev.h > >@@ -117,6 +117,7 @@ enum { > > NETDEV_A_NAPI_ID, > > NETDEV_A_NAPI_IRQ, > > NETDEV_A_NAPI_PID, > >+ NETDEV_A_NAPI_IFNAME, > > __NETDEV_A_NAPI_MAX, > > NETDEV_A_NAPI_MAX = (__NETDEV_A_NAPI_MAX - 1) > >@@ -127,6 +128,7 @@ enum { > > NETDEV_A_QUEUE_IFINDEX, > > NETDEV_A_QUEUE_TYPE, > > NETDEV_A_QUEUE_NAPI_ID, > >+ NETDEV_A_QUEUE_IFNAME, > > __NETDEV_A_QUEUE_MAX, > > NETDEV_A_QUEUE_MAX = (__NETDEV_A_QUEUE_MAX - 1) > >diff --git a/net/core/netdev-genl.c b/net/core/netdev-genl.c > >index fd98936..a886e6a 100644 > >--- a/net/core/netdev-genl.c > >+++ b/net/core/netdev-genl.c > >@@ -181,6 +181,9 @@ netdev_nl_napi_fill_one(struct sk_buff *rsp, struct napi_struct *napi, > > if (nla_put_u32(rsp, NETDEV_A_NAPI_IFINDEX, napi->dev->ifindex)) > > goto nla_put_failure; > >+ if (nla_put_string(rsp, NETDEV_A_NAPI_IFNAME, napi->dev->name)) > >+ goto nla_put_failure; > >+ > > if (napi->irq >= 0 && nla_put_u32(rsp, NETDEV_A_NAPI_IRQ, napi->irq)) > > goto nla_put_failure; > >@@ -307,7 +310,8 @@ netdev_nl_queue_fill_one(struct sk_buff *rsp, struct net_device *netdev, > > if (nla_put_u32(rsp, NETDEV_A_QUEUE_ID, q_idx) || > > nla_put_u32(rsp, NETDEV_A_QUEUE_TYPE, q_type) || > >- nla_put_u32(rsp, NETDEV_A_QUEUE_IFINDEX, netdev->ifindex)) > >+ nla_put_u32(rsp, NETDEV_A_QUEUE_IFINDEX, netdev->ifindex) || > >+ nla_put_string(rsp, NETDEV_A_QUEUE_IFNAME, netdev->name)) > > goto nla_put_failure; > > switch (q_type) { > >@@ -369,16 +373,19 @@ int netdev_nl_queue_get_doit(struct sk_buff *skb, struct genl_info *info) > > u32 q_id, q_type, ifindex; > > struct net_device *netdev; > > struct sk_buff *rsp; > >+ char *ifname; > > int err; > > if (GENL_REQ_ATTR_CHECK(info, NETDEV_A_QUEUE_ID) || > > GENL_REQ_ATTR_CHECK(info, NETDEV_A_QUEUE_TYPE) || > >- GENL_REQ_ATTR_CHECK(info, NETDEV_A_QUEUE_IFINDEX)) > >+ GENL_REQ_ATTR_CHECK(info, NETDEV_A_QUEUE_IFINDEX) || > >+ GENL_REQ_ATTR_CHECK(info, NETDEV_A_QUEUE_IFNAME)) > > return -EINVAL; > > q_id = nla_get_u32(info->attrs[NETDEV_A_QUEUE_ID]); > > q_type = nla_get_u32(info->attrs[NETDEV_A_QUEUE_TYPE]); > > ifindex = nla_get_u32(info->attrs[NETDEV_A_QUEUE_IFINDEX]); > >+ nla_strscpy(ifname, info->attrs[NETDEV_A_QUEUE_IFNAME], IFNAMSIZ); > > rsp = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL); > > if (!rsp) > >@@ -387,10 +394,15 @@ int netdev_nl_queue_get_doit(struct sk_buff *skb, struct genl_info *info) > > rtnl_lock(); > > netdev = __dev_get_by_index(genl_info_net(info), ifindex); > >- if (netdev) > >- err = netdev_nl_queue_fill(rsp, netdev, q_id, q_type, info); > >- else > >+ > >+ if (strcmp(netdev->name, ifname)) { > > err = -ENODEV; > >+ } else { > >+ if (netdev) > >+ err = netdev_nl_queue_fill(rsp, netdev, q_id, q_type, info); > >+ else > >+ err = -ENODEV; > >+ } > > This looks bit incorrect to me that the netdev is checked after netdev->name > is accessed. Shouldn't this be something like: > > if (netdev && !strcmp(netdev->name, ifname)) > err = netdev_nl_queue_fill(rsp, netdev, q_id, q_type, info); > else > err = -ENODEV; Yes, you are right. Thanks. Based on Jakub's comment re exposing names, though, it seems that perhaps this change is not desirable overall.
Hi Joe, kernel test robot noticed the following build warnings: [auto build test WARNING on net-next/main] url: https://github.com/intel-lab-lkp/linux/commits/Joe-Damato/netdev-genl-Add-ifname-for-queue-and-NAPI-APIs/20240222-000134 base: net-next/main patch link: https://lore.kernel.org/r/1708531057-67392-2-git-send-email-jdamato%40fastly.com patch subject: [PATCH net-next 1/2] netdev-genl: Add ifname for queue and NAPI APIs config: powerpc-acadia_defconfig (https://download.01.org/0day-ci/archive/20240223/202402230429.g2qC2zMK-lkp@intel.com/config) compiler: clang version 19.0.0git (https://github.com/llvm/llvm-project edd4aee4dd9b5b98b2576a6f783e4086173d902a) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240223/202402230429.g2qC2zMK-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202402230429.g2qC2zMK-lkp@intel.com/ All warnings (new ones prefixed by >>): >> net/core/netdev-genl.c:388:14: warning: variable 'ifname' is uninitialized when used here [-Wuninitialized] 388 | nla_strscpy(ifname, info->attrs[NETDEV_A_QUEUE_IFNAME], IFNAMSIZ); | ^~~~~~ net/core/netdev-genl.c:376:14: note: initialize the variable 'ifname' to silence this warning 376 | char *ifname; | ^ | = NULL 1 warning generated. vim +/ifname +388 net/core/netdev-genl.c 370 371 int netdev_nl_queue_get_doit(struct sk_buff *skb, struct genl_info *info) 372 { 373 u32 q_id, q_type, ifindex; 374 struct net_device *netdev; 375 struct sk_buff *rsp; 376 char *ifname; 377 int err; 378 379 if (GENL_REQ_ATTR_CHECK(info, NETDEV_A_QUEUE_ID) || 380 GENL_REQ_ATTR_CHECK(info, NETDEV_A_QUEUE_TYPE) || 381 GENL_REQ_ATTR_CHECK(info, NETDEV_A_QUEUE_IFINDEX) || 382 GENL_REQ_ATTR_CHECK(info, NETDEV_A_QUEUE_IFNAME)) 383 return -EINVAL; 384 385 q_id = nla_get_u32(info->attrs[NETDEV_A_QUEUE_ID]); 386 q_type = nla_get_u32(info->attrs[NETDEV_A_QUEUE_TYPE]); 387 ifindex = nla_get_u32(info->attrs[NETDEV_A_QUEUE_IFINDEX]); > 388 nla_strscpy(ifname, info->attrs[NETDEV_A_QUEUE_IFNAME], IFNAMSIZ); 389 390 rsp = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL); 391 if (!rsp) 392 return -ENOMEM; 393 394 rtnl_lock(); 395 396 netdev = __dev_get_by_index(genl_info_net(info), ifindex); 397 398 if (strcmp(netdev->name, ifname)) { 399 err = -ENODEV; 400 } else { 401 if (netdev) 402 err = netdev_nl_queue_fill(rsp, netdev, q_id, q_type, info); 403 else 404 err = -ENODEV; 405 } 406 407 rtnl_unlock(); 408 409 if (err) 410 goto err_free_msg; 411 412 return genlmsg_reply(rsp, info); 413 414 err_free_msg: 415 nlmsg_free(rsp); 416 return err; 417 } 418
Hi Joe, kernel test robot noticed the following build warnings: url: https://github.com/intel-lab-lkp/linux/commits/Joe-Damato/netdev-genl-Add-ifname-for-queue-and-NAPI-APIs/20240222-000134 base: net-next/main patch link: https://lore.kernel.org/r/1708531057-67392-2-git-send-email-jdamato%40fastly.com patch subject: [PATCH net-next 1/2] netdev-genl: Add ifname for queue and NAPI APIs config: i386-randconfig-141-20240222 (https://download.01.org/0day-ci/archive/20240223/202402231851.2NeORqwi-lkp@intel.com/config) compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Reported-by: Dan Carpenter <dan.carpenter@linaro.org> | Closes: https://lore.kernel.org/r/202402231851.2NeORqwi-lkp@intel.com/ New smatch warnings: net/core/netdev-genl.c:388 netdev_nl_queue_get_doit() error: uninitialized symbol 'ifname'. vim +/ifname +388 net/core/netdev-genl.c bc877956272f05 Amritha Nambiar 2023-12-01 371 int netdev_nl_queue_get_doit(struct sk_buff *skb, struct genl_info *info) bc877956272f05 Amritha Nambiar 2023-12-01 372 { 6b6171db7fc8f7 Amritha Nambiar 2023-12-01 373 u32 q_id, q_type, ifindex; 6b6171db7fc8f7 Amritha Nambiar 2023-12-01 374 struct net_device *netdev; 6b6171db7fc8f7 Amritha Nambiar 2023-12-01 375 struct sk_buff *rsp; f340b224321fa6 Joe Damato 2024-02-21 376 char *ifname; 6b6171db7fc8f7 Amritha Nambiar 2023-12-01 377 int err; 6b6171db7fc8f7 Amritha Nambiar 2023-12-01 378 6b6171db7fc8f7 Amritha Nambiar 2023-12-01 379 if (GENL_REQ_ATTR_CHECK(info, NETDEV_A_QUEUE_ID) || 6b6171db7fc8f7 Amritha Nambiar 2023-12-01 380 GENL_REQ_ATTR_CHECK(info, NETDEV_A_QUEUE_TYPE) || f340b224321fa6 Joe Damato 2024-02-21 381 GENL_REQ_ATTR_CHECK(info, NETDEV_A_QUEUE_IFINDEX) || f340b224321fa6 Joe Damato 2024-02-21 382 GENL_REQ_ATTR_CHECK(info, NETDEV_A_QUEUE_IFNAME)) 6b6171db7fc8f7 Amritha Nambiar 2023-12-01 383 return -EINVAL; 6b6171db7fc8f7 Amritha Nambiar 2023-12-01 384 6b6171db7fc8f7 Amritha Nambiar 2023-12-01 385 q_id = nla_get_u32(info->attrs[NETDEV_A_QUEUE_ID]); 6b6171db7fc8f7 Amritha Nambiar 2023-12-01 386 q_type = nla_get_u32(info->attrs[NETDEV_A_QUEUE_TYPE]); 6b6171db7fc8f7 Amritha Nambiar 2023-12-01 387 ifindex = nla_get_u32(info->attrs[NETDEV_A_QUEUE_IFINDEX]); f340b224321fa6 Joe Damato 2024-02-21 @388 nla_strscpy(ifname, info->attrs[NETDEV_A_QUEUE_IFNAME], IFNAMSIZ); ^^^^^^ missing initialization 6b6171db7fc8f7 Amritha Nambiar 2023-12-01 389 6b6171db7fc8f7 Amritha Nambiar 2023-12-01 390 rsp = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL); 6b6171db7fc8f7 Amritha Nambiar 2023-12-01 391 if (!rsp) 6b6171db7fc8f7 Amritha Nambiar 2023-12-01 392 return -ENOMEM; 6b6171db7fc8f7 Amritha Nambiar 2023-12-01 393 6b6171db7fc8f7 Amritha Nambiar 2023-12-01 394 rtnl_lock(); 6b6171db7fc8f7 Amritha Nambiar 2023-12-01 395 6b6171db7fc8f7 Amritha Nambiar 2023-12-01 396 netdev = __dev_get_by_index(genl_info_net(info), ifindex); f340b224321fa6 Joe Damato 2024-02-21 397 f340b224321fa6 Joe Damato 2024-02-21 398 if (strcmp(netdev->name, ifname)) { f340b224321fa6 Joe Damato 2024-02-21 399 err = -ENODEV; f340b224321fa6 Joe Damato 2024-02-21 400 } else { 6b6171db7fc8f7 Amritha Nambiar 2023-12-01 401 if (netdev) 6b6171db7fc8f7 Amritha Nambiar 2023-12-01 402 err = netdev_nl_queue_fill(rsp, netdev, q_id, q_type, info); 6b6171db7fc8f7 Amritha Nambiar 2023-12-01 403 else 6b6171db7fc8f7 Amritha Nambiar 2023-12-01 404 err = -ENODEV; f340b224321fa6 Joe Damato 2024-02-21 405 } 6b6171db7fc8f7 Amritha Nambiar 2023-12-01 406 6b6171db7fc8f7 Amritha Nambiar 2023-12-01 407 rtnl_unlock(); 6b6171db7fc8f7 Amritha Nambiar 2023-12-01 408 6b6171db7fc8f7 Amritha Nambiar 2023-12-01 409 if (err) 6b6171db7fc8f7 Amritha Nambiar 2023-12-01 410 goto err_free_msg; 6b6171db7fc8f7 Amritha Nambiar 2023-12-01 411 6b6171db7fc8f7 Amritha Nambiar 2023-12-01 412 return genlmsg_reply(rsp, info); 6b6171db7fc8f7 Amritha Nambiar 2023-12-01 413 6b6171db7fc8f7 Amritha Nambiar 2023-12-01 414 err_free_msg: 6b6171db7fc8f7 Amritha Nambiar 2023-12-01 415 nlmsg_free(rsp); 6b6171db7fc8f7 Amritha Nambiar 2023-12-01 416 return err; 6b6171db7fc8f7 Amritha Nambiar 2023-12-01 417 }
diff --git a/include/uapi/linux/netdev.h b/include/uapi/linux/netdev.h index 93cb411..80762bc 100644 --- a/include/uapi/linux/netdev.h +++ b/include/uapi/linux/netdev.h @@ -117,6 +117,7 @@ enum { NETDEV_A_NAPI_ID, NETDEV_A_NAPI_IRQ, NETDEV_A_NAPI_PID, + NETDEV_A_NAPI_IFNAME, __NETDEV_A_NAPI_MAX, NETDEV_A_NAPI_MAX = (__NETDEV_A_NAPI_MAX - 1) @@ -127,6 +128,7 @@ enum { NETDEV_A_QUEUE_IFINDEX, NETDEV_A_QUEUE_TYPE, NETDEV_A_QUEUE_NAPI_ID, + NETDEV_A_QUEUE_IFNAME, __NETDEV_A_QUEUE_MAX, NETDEV_A_QUEUE_MAX = (__NETDEV_A_QUEUE_MAX - 1) diff --git a/net/core/netdev-genl.c b/net/core/netdev-genl.c index fd98936..a886e6a 100644 --- a/net/core/netdev-genl.c +++ b/net/core/netdev-genl.c @@ -181,6 +181,9 @@ netdev_nl_napi_fill_one(struct sk_buff *rsp, struct napi_struct *napi, if (nla_put_u32(rsp, NETDEV_A_NAPI_IFINDEX, napi->dev->ifindex)) goto nla_put_failure; + if (nla_put_string(rsp, NETDEV_A_NAPI_IFNAME, napi->dev->name)) + goto nla_put_failure; + if (napi->irq >= 0 && nla_put_u32(rsp, NETDEV_A_NAPI_IRQ, napi->irq)) goto nla_put_failure; @@ -307,7 +310,8 @@ netdev_nl_queue_fill_one(struct sk_buff *rsp, struct net_device *netdev, if (nla_put_u32(rsp, NETDEV_A_QUEUE_ID, q_idx) || nla_put_u32(rsp, NETDEV_A_QUEUE_TYPE, q_type) || - nla_put_u32(rsp, NETDEV_A_QUEUE_IFINDEX, netdev->ifindex)) + nla_put_u32(rsp, NETDEV_A_QUEUE_IFINDEX, netdev->ifindex) || + nla_put_string(rsp, NETDEV_A_QUEUE_IFNAME, netdev->name)) goto nla_put_failure; switch (q_type) { @@ -369,16 +373,19 @@ int netdev_nl_queue_get_doit(struct sk_buff *skb, struct genl_info *info) u32 q_id, q_type, ifindex; struct net_device *netdev; struct sk_buff *rsp; + char *ifname; int err; if (GENL_REQ_ATTR_CHECK(info, NETDEV_A_QUEUE_ID) || GENL_REQ_ATTR_CHECK(info, NETDEV_A_QUEUE_TYPE) || - GENL_REQ_ATTR_CHECK(info, NETDEV_A_QUEUE_IFINDEX)) + GENL_REQ_ATTR_CHECK(info, NETDEV_A_QUEUE_IFINDEX) || + GENL_REQ_ATTR_CHECK(info, NETDEV_A_QUEUE_IFNAME)) return -EINVAL; q_id = nla_get_u32(info->attrs[NETDEV_A_QUEUE_ID]); q_type = nla_get_u32(info->attrs[NETDEV_A_QUEUE_TYPE]); ifindex = nla_get_u32(info->attrs[NETDEV_A_QUEUE_IFINDEX]); + nla_strscpy(ifname, info->attrs[NETDEV_A_QUEUE_IFNAME], IFNAMSIZ); rsp = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL); if (!rsp) @@ -387,10 +394,15 @@ int netdev_nl_queue_get_doit(struct sk_buff *skb, struct genl_info *info) rtnl_lock(); netdev = __dev_get_by_index(genl_info_net(info), ifindex); - if (netdev) - err = netdev_nl_queue_fill(rsp, netdev, q_id, q_type, info); - else + + if (strcmp(netdev->name, ifname)) { err = -ENODEV; + } else { + if (netdev) + err = netdev_nl_queue_fill(rsp, netdev, q_id, q_type, info); + else + err = -ENODEV; + } rtnl_unlock();