Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2220854imm; Thu, 7 Jun 2018 07:16:34 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLAqszoibIZJleIYjJ3MXCzLEQzyCqtaW6nan8N1KA+W5wq+X3DrJ8TSeswh0nBrLqSk0F/ X-Received: by 2002:a63:87c8:: with SMTP id i191-v6mr1792251pge.124.1528380994847; Thu, 07 Jun 2018 07:16:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528380994; cv=none; d=google.com; s=arc-20160816; b=o+AbzOl34Enn7QUzz11HX1l2PoytAwCbPkTBFLV3XfJ7Nhj2zhUuA8chGZsRd1IEF+ L/KLWHVNMUgQTLHoQJ1SfQZxn1f4rnd2ETg18yD+wTOPy6SUiEVTp1ZG3ihiPEyx9UTD qLARCa5db+B4gkQKMOUMwmTgmsueqgJzW1+oIwhz8k+kDRQGx5rSWDHcyWnsu451ui9e eQ00ILwlLJZpOS9oIF8V3obT1xoq5s72Y1hvuZ6Nz74wJcdF3IFfx8DRKA2N+Ab9dw6a kQbLhjyd3AgC8ZC371+3hfPNSOwhJ60zl1NZO8NgNBRXx+gFW5gz2L7DTFzLez8gHviJ 2akQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=vvKu5C9IlGW6pyG7Q+4SGI9h4C/zwzsVwyJXZOGS+6M=; b=BVTOuM0zogOnoJcvjvIHUrEqiy+NRT7LJu8AzZl2HUtP3IdSOr9mu/1A7Dq/HYLdVL JZrL5PabC7OcIg7JuqCwTwBVRI7eO0L7YPX+XQjlAZhO8i/0b+zl5V/1/O8FrI/CkWGt B615lZWjTqAA+zTU6J/clsDOz4T0oDf7xUCdsMyOkRJ7OM4br0+6KohoQ31oKxuuhHMK PK5QlWkgwYpJB4JveGbLiFGZuneiwx8QpPlCupWagp4cFehETkfPnWPtQRnIpvDeqKpd 41/sPdQ5R1YQBNa0//HkrZwK7JMikmSxCutMdiCuG6xyl4iox2WAQjF/izRQefT6UD+b 3Ofg== ARC-Authentication-Results: i=1; mx.google.com; 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 t76-v6si10143634pgc.393.2018.06.07.07.16.20; Thu, 07 Jun 2018 07:16:34 -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; 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 S1753734AbeFGONv (ORCPT + 99 others); Thu, 7 Jun 2018 10:13:51 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:39538 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933162AbeFGOJj (ORCPT ); Thu, 7 Jun 2018 10:09:39 -0400 Received: from [148.252.241.226] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1fQvbJ-0005Zo-9I; Thu, 07 Jun 2018 15:09:17 +0100 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1fQvbF-0003IX-04; Thu, 07 Jun 2018 15:09:13 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Ido Schimmel" , "David S. Miller" , "Petr Machata" Date: Thu, 07 Jun 2018 15:05:21 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 393/410] ip_tunnel: Emit events for post-register MTU changes In-Reply-To: X-SA-Exim-Connect-IP: 148.252.241.226 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.57-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Petr Machata commit f6cc9c054e77b9a28d4594bcc201697edb21dfd2 upstream. For tunnels created with IFLA_MTU, MTU of the netdevice is set by rtnl_create_link() (called from rtnl_newlink()) before the device is registered. However without IFLA_MTU that's not done. rtnl_newlink() proceeds by calling struct rtnl_link_ops.newlink, which via ip_tunnel_newlink() calls register_netdevice(), and that emits NETDEV_REGISTER. Thus any listeners that inspect the netdevice get the MTU of 0. After ip_tunnel_newlink() corrects the MTU after registering the netdevice, but since there's no event, the listeners don't get to know about the MTU until something else happens--such as a NETDEV_UP event. That's not ideal. So instead of setting the MTU directly, go through dev_set_mtu(), which takes care of distributing the necessary NETDEV_PRECHANGEMTU and NETDEV_CHANGEMTU events. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Petr Machata Signed-off-by: Ido Schimmel Signed-off-by: David S. Miller [bwh: Backported to 3.16: Resolve conflict with commit 24fc79798b8d "ip_tunnel: Clamp MTU to bounds on new link", referring to commit 5568cdc368c3 "ip_tunnel: Resolve ipsec merge conflict properly."] Signed-off-by: Ben Hutchings --- --- a/net/ipv4/ip_tunnel.c +++ b/net/ipv4/ip_tunnel.c @@ -405,17 +405,26 @@ static struct ip_tunnel *ip_tunnel_creat { struct ip_tunnel *nt; struct net_device *dev; + int mtu; + int err; BUG_ON(!itn->fb_tunnel_dev); dev = __ip_tunnel_create(net, itn->fb_tunnel_dev->rtnl_link_ops, parms); if (IS_ERR(dev)) return ERR_CAST(dev); - dev->mtu = ip_tunnel_bind_dev(dev); + mtu = ip_tunnel_bind_dev(dev); + err = dev_set_mtu(dev, mtu); + if (err) + goto err_dev_set_mtu; nt = netdev_priv(dev); ip_tunnel_add(itn, nt); return nt; + +err_dev_set_mtu: + unregister_netdevice(dev); + return ERR_PTR(err); } int ip_tunnel_rcv(struct ip_tunnel *tunnel, struct sk_buff *skb, @@ -962,7 +971,7 @@ int ip_tunnel_newlink(struct net_device nt->parms = *p; err = register_netdevice(dev); if (err) - goto out; + goto err_register_netdevice; if (dev->type == ARPHRD_ETHER && !tb[IFLA_ADDRESS]) eth_hw_addr_random(dev); @@ -971,15 +980,20 @@ int ip_tunnel_newlink(struct net_device if (tb[IFLA_MTU]) { unsigned int max = 0xfff8 - dev->hard_header_len - nt->hlen; - dev->mtu = clamp(dev->mtu, (unsigned int)ETH_MIN_MTU, - (unsigned int)(max - sizeof(struct iphdr))); - } else { - dev->mtu = mtu; + mtu = clamp(dev->mtu, (unsigned int)ETH_MIN_MTU, + (unsigned int)(max - sizeof(struct iphdr))); } + err = dev_set_mtu(dev, mtu); + if (err) + goto err_dev_set_mtu; + ip_tunnel_add(itn, nt); + return 0; -out: +err_dev_set_mtu: + unregister_netdevice(dev); +err_register_netdevice: return err; } EXPORT_SYMBOL_GPL(ip_tunnel_newlink);