From patchwork Wed Jun 25 16:58:22 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 364075 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3307D1400B9 for ; Thu, 26 Jun 2014 02:58:34 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757534AbaFYQ6a (ORCPT ); Wed, 25 Jun 2014 12:58:30 -0400 Received: from mail-wi0-f181.google.com ([209.85.212.181]:55962 "EHLO mail-wi0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757215AbaFYQ63 (ORCPT ); Wed, 25 Jun 2014 12:58:29 -0400 Received: by mail-wi0-f181.google.com with SMTP id n3so2926787wiv.2 for ; Wed, 25 Jun 2014 09:58:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=MIbQZLG/9hIqsYP+Ixb0vVBooGzpu47GOJCmwStWW/E=; b=fnlsIlp5t29oPkeZoL3n2o3Ox77+HSBHlHBqtiLmKmoXlsebem25ZzreYDJZBtAsNG iWAZimduCwflu/mPAC1paToaO65XeCKdzkzYrr9WWNlTfbbdIhdgT/9bkdyDBlzLFdIg d/VIaonMuzM7EXyve46Sy1GuCa4EBXcXH488wjSoiahSn4W4gPsA+csVj2OW5zsHwPlm SbS+4CuzxI+Pu9lAsfiP0+YlnSGGXJmJC0KM7KEFgPVPP151DNPOvLXszeHs57EEEnH9 VyX6B14+EEEW6w3L8a7B3K69W7IK6SPMRVPz30zL9pZm0XqWDcg+tt+jJ/QE3h9x/Ro2 Yf/A== X-Gm-Message-State: ALoCoQlDSGauwm4EgDOC7+bdCsoOziIAaoUppxzyiVfWcgWtgKJqL9rolpOuAJAvbfCQYlcLhpi7 X-Received: by 10.180.89.193 with SMTP id bq1mr8070398wib.81.1403715507328; Wed, 25 Jun 2014 09:58:27 -0700 (PDT) Received: from localhost (ip-94-113-121-85.net.upcbroadband.cz. [94.113.121.85]) by mx.google.com with ESMTPSA id fb15sm14212967wid.23.2014.06.25.09.58.26 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Jun 2014 09:58:26 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, pshelar@nicira.com, cwang@twopensource.com, nicolas.dichtel@6wind.com, ebiederm@xmission.com, david@gibson.dropbear.id.au, sfeldma@cumulusnetworks.com, sucheta.chakraborty@qlogic.com, stephen@networkplumber.org Subject: [patch net-next v2 1/2] rtnetlink: allow to register ops without ops->setup set Date: Wed, 25 Jun 2014 18:58:22 +0200 Message-Id: <1403715503-9059-1-git-send-email-jiri@resnulli.us> X-Mailer: git-send-email 1.9.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org So far, it is assumed that ops->setup is filled up. But there might be case that ops might make sense even without ->setup. In that case, forbid to newlink and dellink. This allows to register simple rtnl link ops containing only ->kind. That allows consistent way of passing device kind (either device-kind or slave-kind) to userspace. Signed-off-by: Jiri Pirko Nacked-by: "Eric W. Biederman" --- v1->v2: included comments from Eric fixing default_device_exit_batch, not checking setup in dellink and added hopefully clearer description and comment. net/core/rtnetlink.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 1063996..27acaf7 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -299,7 +299,12 @@ int __rtnl_link_register(struct rtnl_link_ops *ops) if (rtnl_link_ops_get(ops->kind)) return -EEXIST; - if (!ops->dellink) + /* The check for setup is here because if ops + * does not have that filled up, it is not possible + * to use the ops for creating device. So do not + * fill up dellink as well. That disables rtnl_dellink. + */ + if (ops->setup && !ops->dellink) ops->dellink = unregister_netdevice_queue; list_add_tail(&ops->list, &link_ops); @@ -1777,7 +1782,7 @@ static int rtnl_dellink(struct sk_buff *skb, struct nlmsghdr *nlh) return -ENODEV; ops = dev->rtnl_link_ops; - if (!ops) + if (!ops || !ops->dellink) return -EOPNOTSUPP; ops->dellink(dev, &list_kill); @@ -2038,6 +2043,9 @@ replay: return -EOPNOTSUPP; } + if (!ops->setup) + return -EOPNOTSUPP; + if (!ifname[0]) snprintf(ifname, IFNAMSIZ, "%s%%d", ops->kind);