Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp2515407ybp; Thu, 10 Oct 2019 08:28:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqy/SSW9Bid1n4MQGQ5ZuwWLBMnGLOfWR188yfFOvomSbr8Zg+f3ZPv81QvfRPgHjMfhZ0Bx X-Received: by 2002:a50:cb85:: with SMTP id k5mr8626608edi.131.1570721326106; Thu, 10 Oct 2019 08:28:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570721326; cv=none; d=google.com; s=arc-20160816; b=QN0ecCBvLwqnKZ9vSH9a4T5G2rSuNX77QeVzRuW+qILd8BX5APAtPrhaCQXTeoKR4Y 8fD2TFgyBqKKqNF1rFKjIAYy59yOXDt/Wfvv6h57L/nDZucVV/yNiwrbKSG2/NipnLXN U8/HnVwGqQrcJXU3gcRoQhjor382jJBaG5ABFIpktUNyWseGpZVo1zY9wpMrsHaoJEv4 X8Caw7cwvlrHcW3Zszs/LpiZ3qBfSpqjx9PZd+kPc54GjBvOYkhuZ/tJ3wLsjjP0RILq fXEkyr1xIvgQ1/b3o5RQ/+jQVf9zdrGjMhmymRMF1eEcXaCSFCliohG5/i0AGxv8tYOw yDwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=4KtpyJcZymMDldmeqsuGE5WoW9tQnlMUYqvVj3l3rIE=; b=INnYbnmEZOx5zDBecszkDLFQ7ThS1VVh6nbDEscxHFL4ow06meWopWbdXlxBm8SuY+ nNifjXRkJxwi+cDIW+Tp0AUStVxdpUBqc30KykFaDraJsosO0uEgCaOATd+piJ9CMQso iSkMVevcvBUARphbILqLuzZjqFt5cr9v7LYvt3ww9+h8pF8Z30bO7AZduuuF4VEp5xnC a3FRlzoVpRYpG9BLt0NKgz8Q6eMLX3vrdNxcCy/hsdi92k8MEXiqeMlhMiydrLWQvbbF oPGLodKkOBgZB1Njx+AkqSgBrCWaDgYokysEQA3lZKu1o9Ov6mQilQEF+ltpEACBJ/GG M0yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@resnulli-us.20150623.gappssmtp.com header.s=20150623 header.b=GFYqlOXd; 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 v20si3354509edq.195.2019.10.10.08.28.21; Thu, 10 Oct 2019 08:28:46 -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; dkim=pass header.i=@resnulli-us.20150623.gappssmtp.com header.s=20150623 header.b=GFYqlOXd; 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 S1726655AbfJJP0D (ORCPT + 99 others); Thu, 10 Oct 2019 11:26:03 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:34013 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726088AbfJJP0D (ORCPT ); Thu, 10 Oct 2019 11:26:03 -0400 Received: by mail-wr1-f65.google.com with SMTP id j11so8446418wrp.1 for ; Thu, 10 Oct 2019 08:26:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=4KtpyJcZymMDldmeqsuGE5WoW9tQnlMUYqvVj3l3rIE=; b=GFYqlOXdzrwPAyel1BaDfJev7DNqRpkIRadg+7l1w/DTWcBEtewg5uv6e5wu9aDBlk ZxrZcisq0IwOpa48yRTfgn8LgeJdI9MIGinoZA7gOpP7Lf+yl8GimEoa4j/Lkf9ArSIK G3SpIH8zvJJmoPPP6TZYDj6VAcbC/3LnYX//iRu6cS6CRw4SuKPet/VRcMUEKOU6UPDs Smhl1vwUqhCfXypJr8QqaevLLrDeTlCm1PHQUZGkA6swbv/S1tb18vCne91Z7OMuihg3 3sOLbqa2la6QfR8phsyB9g1DHGMzbuaqNJ3cbw4PXxM0JKfiQYSwsSKVRpiM9/IicyxU 5DKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=4KtpyJcZymMDldmeqsuGE5WoW9tQnlMUYqvVj3l3rIE=; b=IpETcldnz/hrs0dtJR96tOSxvDswQi3voKfy4L8REimT8Gxcw6L8ynFxV1M9WXJAqa PYbWvxHHEZTfStvvJUkeKtla0XPnLuyKZqm1eE83xHMD5hEb2wil0MB1PsnYIO9Nf1nC TZcik416wk5qdyUUmcEMmD6qG748OeVAN3Tw4c5A1TihGWCYuWV+aEzJMbgwkhRa9Xf1 H7S+SzskD09OnVV5vttlb5kl48iOGK01myfgOYjAtj/7JUSX/RmGjCfzigc68ngQYoM5 rEmkB1Dj3yV32eNNR50ClPlaJy/o4/pSDzgIbKwyKrbDmuNfoDc5lz64xMNLgZNPTbW/ UnOQ== X-Gm-Message-State: APjAAAUOM41ZhPTarDnp2tJ5kEkeAQ2XuGA99KXMVtCDGl/uURbkNJjY 4EZ3PgOs8Et+UM/26lAXjw88PQ== X-Received: by 2002:a05:6000:354:: with SMTP id e20mr6255987wre.383.1570721161065; Thu, 10 Oct 2019 08:26:01 -0700 (PDT) Received: from localhost (jirka.pirko.cz. [84.16.102.26]) by smtp.gmail.com with ESMTPSA id w18sm6903683wmc.9.2019.10.10.08.26.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2019 08:26:00 -0700 (PDT) Date: Thu, 10 Oct 2019 17:25:59 +0200 From: Jiri Pirko To: Michal Kubecek Cc: David Miller , netdev@vger.kernel.org, Jakub Kicinski , Andrew Lunn , Florian Fainelli , John Linville , Stephen Hemminger , Johannes Berg , linux-kernel@vger.kernel.org Subject: Re: [PATCH net-next v7 13/17] ethtool: add standard notification handler Message-ID: <20191010152559.GA2994@nanopsycho> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.4 (2019-03-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Wed, Oct 09, 2019 at 10:59:40PM CEST, mkubecek@suse.cz wrote: >The ethtool netlink notifications have the same format as related GET >replies so that if generic GET handling framework is used to process GET >requests, its callbacks and instance of struct get_request_ops can be >also used to compose corresponding notification message. > >Provide function ethnl_std_notify() to be used as notification handler in >ethnl_notify_handlers table. > >Signed-off-by: Michal Kubecek >--- > net/ethtool/netlink.c | 89 +++++++++++++++++++++++++++++++++++++++++++ > net/ethtool/netlink.h | 3 +- > 2 files changed, 91 insertions(+), 1 deletion(-) > >diff --git a/net/ethtool/netlink.c b/net/ethtool/netlink.c >index 47b6aefa0bf9..dc52d912e0dd 100644 >--- a/net/ethtool/netlink.c >+++ b/net/ethtool/netlink.c >@@ -7,6 +7,7 @@ > static struct genl_family ethtool_genl_family; > > static bool ethnl_ok __read_mostly; >+static u32 ethnl_bcast_seq; > > #define __LINK_MODE_NAME(speed, type, duplex) \ > #speed "base" #type "/" #duplex >@@ -257,6 +258,18 @@ struct sk_buff *ethnl_reply_init(size_t payload, struct net_device *dev, u8 cmd, > return NULL; > } > >+static void *ethnl_bcastmsg_put(struct sk_buff *skb, u8 cmd) >+{ >+ return genlmsg_put(skb, 0, ++ethnl_bcast_seq, ðtool_genl_family, 0, >+ cmd); >+} >+ >+static int ethnl_multicast(struct sk_buff *skb, struct net_device *dev) >+{ >+ return genlmsg_multicast_netns(ðtool_genl_family, dev_net(dev), skb, >+ 0, ETHNL_MCGRP_MONITOR, GFP_KERNEL); >+} No need for these 2 helpers. Just put the code directly into ethnl_std_notify() and make the code easier to read. >+ > /* GET request helpers */ > > /** >@@ -588,6 +601,82 @@ static int ethnl_get_done(struct netlink_callback *cb) > return 0; > } > >+static const struct get_request_ops *ethnl_std_notify_to_ops(unsigned int cmd) >+{ >+ WARN_ONCE(1, "unexpected notification type %u\n", cmd); >+ return NULL; >+} Why this isn't a table similar to get_requests ? >+ >+/* generic notification handler */ >+static void ethnl_std_notify(struct net_device *dev, unsigned int cmd, Better "common" comparing to "standard", I believe. >+ const void *data) >+{ >+ struct ethnl_reply_data *reply_data; >+ const struct get_request_ops *ops; >+ struct ethnl_req_info *req_info; >+ struct sk_buff *skb; >+ void *reply_payload; >+ int reply_len; >+ int ret; >+ >+ ops = ethnl_std_notify_to_ops(cmd); >+ if (!ops) >+ return; >+ req_info = kzalloc(ops->req_info_size, GFP_KERNEL); >+ if (!req_info) >+ return; >+ reply_data = kmalloc(ops->reply_data_size, GFP_KERNEL); >+ if (!reply_data) { >+ kfree(req_info); >+ return; >+ } >+ >+ req_info->dev = dev; >+ req_info->global_flags |= ETHTOOL_GFLAG_COMPACT_BITSETS; >+ >+ ethnl_init_reply_data(reply_data, ops, dev); >+ ret = ops->prepare_data(req_info, reply_data, NULL); >+ if (ret < 0) >+ goto err_cleanup; >+ reply_len = ops->reply_size(req_info, reply_data); >+ if (ret < 0) >+ goto err_cleanup; >+ ret = -ENOMEM; >+ skb = genlmsg_new(reply_len, GFP_KERNEL); >+ if (!skb) >+ goto err_cleanup; >+ reply_payload = ethnl_bcastmsg_put(skb, cmd); >+ if (!reply_payload) >+ goto err_skb; >+ ret = ethnl_fill_reply_header(skb, dev, ops->hdr_attr); >+ if (ret < 0) >+ goto err_msg; >+ ret = ops->fill_reply(skb, req_info, reply_data); >+ if (ret < 0) >+ goto err_msg; >+ if (ops->cleanup_data) >+ ops->cleanup_data(reply_data); >+ >+ genlmsg_end(skb, reply_payload); >+ kfree(reply_data); >+ kfree(req_info); >+ ethnl_multicast(skb, dev); >+ return; >+ >+err_msg: >+ WARN_ONCE(ret == -EMSGSIZE, >+ "calculated message payload length (%d) not sufficient\n", >+ reply_len); >+err_skb: >+ nlmsg_free(skb); >+err_cleanup: >+ if (ops->cleanup_data) >+ ops->cleanup_data(reply_data); >+ kfree(reply_data); >+ kfree(req_info); >+ return; >+} >+ > /* notifications */ > > typedef void (*ethnl_notify_handler_t)(struct net_device *dev, unsigned int cmd, >diff --git a/net/ethtool/netlink.h b/net/ethtool/netlink.h >index a0ae47bebe51..23e82a4dd265 100644 >--- a/net/ethtool/netlink.h >+++ b/net/ethtool/netlink.h >@@ -316,7 +316,8 @@ static inline void ethnl_after_ops(struct net_device *dev) > * infrastructure. When used, a pointer to an instance of this structure is to > * be added to &get_requests array and generic handlers ethnl_get_doit(), > * ethnl_get_dumpit(), ethnl_get_start() and ethnl_get_done() used in >- * @ethnl_genl_ops >+ * @ethnl_genl_ops; ethnl_std_notify() can be used in @ethnl_notify_handlers >+ * to send notifications of the corresponding type. > */ > struct get_request_ops { > u8 request_cmd; >-- >2.23.0 >