Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp507076ybp; Thu, 10 Oct 2019 23:07:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqxogC+y8c4AMnzPu9+8VF5eJM+KDwRIF+A8amb85W6+XJurX94FG2VpFwh6t86fx5vzyRwI X-Received: by 2002:a05:6402:657:: with SMTP id u23mr11798251edx.159.1570774064024; Thu, 10 Oct 2019 23:07:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570774064; cv=none; d=google.com; s=arc-20160816; b=M7nUklsEMW/tRdWMbHw+SLnUFEqQ4ymtkCnOfdIigcZeHiQJ/6KB5CKm447uCY1S92 8IVR8jqG7egpBxLNYeg5J81+q3fO0rtQtdawAragsomI9a+Tv6KZ06ViaRaPeu+ZHhaf vkNzqTWIWhDlLzSPzrfM6CIUcR5u3xxZEy/EKT+3fNYQcd/Piinq811abqK5I2dTrqfl sv70WwCmjv7xp4gy/CNhjf5v9FTWxp0KOp8iwqDB4mshS4Rwwwj5wNm8EkFDfBWs7MV6 0Bm/xijPmAsksxScEipDy/Xgj+zpejrtZ+sXiPweRCDjSzEvETCuvcoaBSn3s/U4Qm2X QnHw== 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=3c0Nh1nl7bfCKYDWMo6YBu1F2vfCDmy0MmjZnscBG0g=; b=AOvM8DVDi7dS458vrlTLXrPboV04ysQiVQwHyH6oBmshYrh5nVVkdTpmlluMeYF9xb mAqH+ZkN0wJyTyiX0HsDoDMOW7g+skgG26ViKINh75G9PFKeqEm3rvpgJJXAfV9spiUl xTx/zBIUGLyA4gwSHJRjY+XFOilkd4fAxcFEZTw+URmjGWkH+i14jparhuS+E26vSo83 Dxa2y8Gf7190ZmBblwEQEhYnsjvSLyG7aA0j9CYcSAiHjrTrW6+QwBfC3H8L1AxBqmIL jDmpxNx9YFcPBRikwpaJLPZ1rvgyUhefCyAX5e2Z8StP0/vVxjLwGkUjKwDvttHCbeVE rbiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@resnulli-us.20150623.gappssmtp.com header.s=20150623 header.b=WyVKVt5Q; 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 e22si4450785ejr.19.2019.10.10.23.07.20; Thu, 10 Oct 2019 23:07:44 -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=WyVKVt5Q; 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 S1727014AbfJKGHB (ORCPT + 99 others); Fri, 11 Oct 2019 02:07:01 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:34255 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726116AbfJKGHB (ORCPT ); Fri, 11 Oct 2019 02:07:01 -0400 Received: by mail-wr1-f67.google.com with SMTP id j11so10443057wrp.1 for ; Thu, 10 Oct 2019 23:06:57 -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=3c0Nh1nl7bfCKYDWMo6YBu1F2vfCDmy0MmjZnscBG0g=; b=WyVKVt5QOLSPRbgNDDvSj2Y0YxDMaLTkTz+Ox7Wk4QgNlzEfXEiSD7kaqsOOZzb1Lo LF2tdc8Sl8WLRUepsFc2TV35mao25gY/hIu9GOWfm1E4Rcz1N+2ehwygWpXiQ0GS4QAN T33qT5Ck8xXBAUaRTJ5XeKCiuIeHdEvbdPFCNGRKM2Tm2B66Oe7D80FAl8wKU2bIzVDB go8bRROgToWLqKOMGHfdaBDbgsGvt3h7Q+AekzwbxlqQkmthRiueUKxAmdyuxDMZpj52 8JnPxY4/SUR4zYesI5gV8uXomBt/dgHG60goR7m0tUiITI/YobwxUTTH7aERvRSg7lvO Sn/Q== 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=3c0Nh1nl7bfCKYDWMo6YBu1F2vfCDmy0MmjZnscBG0g=; b=AWIKR1S8+jMx1wWvoBCxIcx6PLSgdC6Se6XfZIKRMC1A+299EpuEReXCzMsZecyo2g ZGRFeprZzjsr08WzpSb3sW/CPX8sSEkTdBQE0NNyfGEU9L6Sea6Y3lmqQNzJ7pGcJo+6 Z/h9p4eo/lhPtzUOanXT0+Gm5JmM+sqpGTyrKsMwdCK0YTQfiMTElXrKg/mXiZycLxet QZOZxYGBbo6x+RHjdMSrjXGzAxpsY6xpPENv84xD43e2YRRYxS78yG0GcuZFI7J2lYOR Jiga9HdZScZWk9RLHZM2X4ZBqCz3U9z3ZK7XnelKoLk9qUe61q4AZsuYPHwEyEH41JwI z0UA== X-Gm-Message-State: APjAAAXUNSoCC1p24zCQNfhGuxykP8PVX9jc9uNPRu6poGahW5M9pVZi YJeyVow13vN7eVuXAbNvkmfXMg== X-Received: by 2002:a5d:4ecc:: with SMTP id s12mr8554196wrv.73.1570774016719; Thu, 10 Oct 2019 23:06:56 -0700 (PDT) Received: from localhost (jirka.pirko.cz. [84.16.102.26]) by smtp.gmail.com with ESMTPSA id z22sm7618060wmf.2.2019.10.10.23.06.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2019 23:06:56 -0700 (PDT) Date: Fri, 11 Oct 2019 08:06:55 +0200 From: Jiri Pirko To: Michal Kubecek Cc: netdev@vger.kernel.org, David Miller , Jakub Kicinski , Andrew Lunn , Florian Fainelli , John Linville , Stephen Hemminger , Johannes Berg , linux-kernel@vger.kernel.org Subject: Re: [PATCH net-next v7 09/17] ethtool: generic handlers for GET requests Message-ID: <20191011060655.GE2901@nanopsycho> References: <20191010135639.GJ2223@nanopsycho> <20191010180401.GD22163@unicorn.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191010180401.GD22163@unicorn.suse.cz> 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 Thu, Oct 10, 2019 at 08:04:01PM CEST, mkubecek@suse.cz wrote: >On Thu, Oct 10, 2019 at 03:56:39PM +0200, Jiri Pirko wrote: >> Wed, Oct 09, 2019 at 10:59:27PM CEST, mkubecek@suse.cz wrote: [...] >> >+ const struct nlmsghdr *nlhdr, struct net *net, >> >+ const struct get_request_ops *request_ops, >> >+ struct netlink_ext_ack *extack, bool require_dev) >> >+{ >> >+ struct nlattr **tb; >> >+ int ret; >> >+ >> >+ tb = kmalloc_array(request_ops->max_attr + 1, sizeof(tb[0]), >> >+ GFP_KERNEL); >> >+ if (!tb) >> >+ return -ENOMEM; >> >+ >> >+ ret = nlmsg_parse(nlhdr, GENL_HDRLEN, tb, request_ops->max_attr, >> >+ request_ops->request_policy, extack); >> >+ if (ret < 0) >> >+ goto out; >> >+ ret = ethnl_parse_header(req_info, tb[request_ops->hdr_attr], net, >> >+ extack, request_ops->header_policy, >> >+ require_dev); >> >> This is odd. It's the other way around in compare what I would expect. >> There is a request-specific header attr that contains common header >> attributes parsed in ethnl_parse_header. >> >> Why don't you have the common header as a root then then have one nested >> attr that would carry the request-specific attrs? >> >> Similar to how it is done in rtnl IFLA_INFO_KIND. > >To me, what you suggest feels much more odd. I thought about it last >time, I thought about it now and the only reason for such layout I could >come with would be to work around the unfortunate design flaw of the way >validation and parsing is done in genetlink (see below). > >The situation with IFLA_INFO_KIND is a bit different, what you suggest >would rather correspond to having only attributes common for all RTNL on >top level and hiding all IFLA_* attributes into a nest (and the same >with attributes specific to "ip addr", "ip route", "ip rule" etc.) > >> You can parse the common stuff in pre_doit/start genl ops and you >> don't have to explicitly call ethnl_parse_header. >> Also, that would allow you to benefit from the genl doit/dumpit initial >> attr parsing and save basically this whole function (alloc,parse). >> >> Code would be much more simple to follow then. >> >> Still seems to me that you use the generic netlink but you don't like >> the infra too much so you make it up yourself again in parallel - that is >> my feeling reading the code. I get the argument about the similarities >> of the individual requests and why you have this request_ops (alhough I >> don't like it too much). > >The only thing I don't like about the genetlink infrastructure is the >design decision that policy and corresponding maxattr is an attribute of >the family rather than a command. This forces anyone who wants to use it >to essentially have one common message format for all commands and if >that is not possible, to do what you suggest above, hide the actual >request into a nest. But that is fine, the genetlink code would parse the common attributes for you according to the family, then you inside ethnl_get_doit prepare (alloc, parse) data for ops->prepare_data and other callbacks, according to per-request ops->policy and ops->maxattr. Then the request callbacks would get parsed attrs according to their type. And you can use similar technique for set dumpit/ops. Would be neat. > >Whether you use one common attribute type for "command specific nest" or >different attribute for each request type, you do not actually make >things simpler, you just move the complexity one level lower. You will >still have to do your own (per request) parsing of the actual request, >the only difference is that you will do it in a different place and use >nla_parse_nested() rather than nlmsg_parse(). > >Rather than bending the message layout to fit into the limitations of >unified genetlink parsing, I prefer to keep the logical message >structure and do the parsing on my own. You are going to still have it but the person looking at the traffic by nlmon would know what is happening and also you are going to use genetlink in non-abusive way :) > [...]