From patchwork Mon Oct 26 03:40:56 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Toshiaki Makita X-Patchwork-Id: 535684 X-Patchwork-Delegate: jeffrey.t.kirsher@intel.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by ozlabs.org (Postfix) with ESMTP id 7F68A141355 for ; Mon, 26 Oct 2015 14:41:37 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 89C6C8775A; Mon, 26 Oct 2015 03:41:36 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id NU3_0AF7aPIL; Mon, 26 Oct 2015 03:41:34 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by fraxinus.osuosl.org (Postfix) with ESMTP id E6D96876CE; Mon, 26 Oct 2015 03:41:34 +0000 (UTC) X-Original-To: intel-wired-lan@lists.osuosl.org Delivered-To: intel-wired-lan@lists.osuosl.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by ash.osuosl.org (Postfix) with ESMTP id 85AE21C11D6 for ; Mon, 26 Oct 2015 03:41:33 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 81E628694A for ; Mon, 26 Oct 2015 03:41:33 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id rsz+LHIVUMyl for ; Mon, 26 Oct 2015 03:41:32 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from tama50.ecl.ntt.co.jp (tama50.ecl.ntt.co.jp [129.60.39.147]) by hemlock.osuosl.org (Postfix) with ESMTP id 398D386525 for ; Mon, 26 Oct 2015 03:41:31 +0000 (UTC) Received: from vc1.ecl.ntt.co.jp (vc1.ecl.ntt.co.jp [129.60.86.153]) by tama50.ecl.ntt.co.jp (8.13.8/8.13.8) with ESMTP id t9Q3fRJf005146; Mon, 26 Oct 2015 12:41:27 +0900 Received: from vc1.ecl.ntt.co.jp (localhost [127.0.0.1]) by vc1.ecl.ntt.co.jp (Postfix) with ESMTP id 3DCF25F623; Mon, 26 Oct 2015 12:41:27 +0900 (JST) Received: from imail3.m.ecl.ntt.co.jp (imail3.m.ecl.ntt.co.jp [129.60.5.248]) by vc1.ecl.ntt.co.jp (Postfix) with ESMTP id 2F2FD5F611; Mon, 26 Oct 2015 12:41:27 +0900 (JST) Received: from ubuntu-vm-makita ([129.60.241.200]) by imail3.m.ecl.ntt.co.jp (8.13.8/8.13.8) with ESMTP id t9Q3fOkS018937; Mon, 26 Oct 2015 12:41:27 +0900 Received: by ubuntu-vm-makita (Postfix, from userid 1000) id 333C51E6EFA; Mon, 26 Oct 2015 12:41:22 +0900 (JST) From: Toshiaki Makita To: "David S . Miller" Date: Mon, 26 Oct 2015 12:40:56 +0900 Message-Id: <1445830859-4651-2-git-send-email-makita.toshiaki@lab.ntt.co.jp> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1445830859-4651-1-git-send-email-makita.toshiaki@lab.ntt.co.jp> References: <1445830859-4651-1-git-send-email-makita.toshiaki@lab.ntt.co.jp> X-TM-AS-MML: disable Cc: netdev@vger.kernel.org, Vlad Yasevich , toshiaki.makita1@gmail.com, Stephen Hemminger , intel-wired-lan@lists.osuosl.org, Toshiaki Makita , Patrick McHardy Subject: [Intel-wired-lan] [PATCH v2 net-next 1/4] net: Add ndo_enc_hdr_len to notify extra header room for encapsulated frames X-BeenThere: intel-wired-lan@lists.osuosl.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Intel Wired Ethernet Linux Kernel Driver Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-wired-lan-bounces@lists.osuosl.org Sender: "Intel-wired-lan" Currently most NICs reserve 1522 bytes space for frames to handle 4 bytes VLAN header in addition to 1518, maximum size of ethernet frame. This is, however, not sufficient when stacked vlan or other encapsulation protocols are used. To accommodate this, add .ndo_enc_hdr_len() and inform drivers of needed encapsulation header size. Signed-off-by: Toshiaki Makita --- include/linux/netdevice.h | 9 +++++++++ net/core/dev.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 4ac653b..1b2b587 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -1059,6 +1059,10 @@ typedef u16 (*select_queue_fallback_t)(struct net_device *dev, * This function is used to get egress tunnel information for given skb. * This is useful for retrieving outer tunnel header parameters while * sampling packet. + * int (*ndo_enc_hdr_len)(struct net_device *dev, int hdr_len); + * Called to notify addtional encapsulation header length to reserve. + * Implements should reserve hdr_len room in addition to MTU to handle + * encapsulated frames. * */ struct net_device_ops { @@ -1236,6 +1240,8 @@ struct net_device_ops { bool proto_down); int (*ndo_fill_metadata_dst)(struct net_device *dev, struct sk_buff *skb); + int (*ndo_enc_hdr_len)(struct net_device *dev, + int hdr_len); }; /** @@ -1396,6 +1402,7 @@ enum netdev_priv_flags { * @if_port: Selectable AUI, TP, ... * @dma: DMA channel * @mtu: Interface MTU value + * @enc_hdr_len: Additional encapsulation header length to MTU * @type: Interface hardware type * @hard_header_len: Hardware header length * @@ -1616,6 +1623,7 @@ struct net_device { unsigned char dma; unsigned int mtu; + unsigned int enc_hdr_len; unsigned short type; unsigned short hard_header_len; @@ -3031,6 +3039,7 @@ int dev_change_name(struct net_device *, const char *); int dev_set_alias(struct net_device *, const char *, size_t); int dev_change_net_namespace(struct net_device *, struct net *, const char *); int dev_set_mtu(struct net_device *, int); +int dev_set_enc_hdr_len(struct net_device *, int); void dev_set_group(struct net_device *, int); int dev_set_mac_address(struct net_device *, struct sockaddr *); int dev_change_carrier(struct net_device *, bool new_carrier); diff --git a/net/core/dev.c b/net/core/dev.c index 13f49f8..7c4114b 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -6051,6 +6051,42 @@ int dev_set_mtu(struct net_device *dev, int new_mtu) EXPORT_SYMBOL(dev_set_mtu); /** + * dev_set_enc_hdr_len - Expand encapsulation header room + * @dev: device + * @new_len: new length + */ +int dev_set_enc_hdr_len(struct net_device *dev, int new_len) +{ + const struct net_device_ops *ops = dev->netdev_ops; + + if (new_len < 0) + return -EINVAL; + + if (!netif_device_present(dev)) + return -ENODEV; + + if (new_len <= dev->enc_hdr_len) + return 0; + + if (ops->ndo_enc_hdr_len) { + int err; + + /* This function can be called from child user/net namespace */ + if (!ns_capable(dev_net(dev)->user_ns, CAP_NET_ADMIN)) + return -EPERM; + + err = ops->ndo_enc_hdr_len(dev, new_len); + if (err) + return err; + } + + dev->enc_hdr_len = new_len; + + return 0; +} +EXPORT_SYMBOL(dev_set_enc_hdr_len); + +/** * dev_set_group - Change group this device belongs to * @dev: device * @new_group: group this device should belong to