From patchwork Tue Jan 9 06:48:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: liuqifa X-Patchwork-Id: 857247 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3zG2n66dlPz9sBZ for ; Tue, 9 Jan 2018 17:49:30 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752966AbeAIGt2 (ORCPT ); Tue, 9 Jan 2018 01:49:28 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:39396 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1752396AbeAIGt1 (ORCPT ); Tue, 9 Jan 2018 01:49:27 -0500 Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 04B1F55B79A53; Tue, 9 Jan 2018 14:49:14 +0800 (CST) Received: from localhost (10.177.68.80) by DGGEMS410-HUB.china.huawei.com (10.3.19.210) with Microsoft SMTP Server id 14.3.361.1; Tue, 9 Jan 2018 14:49:12 +0800 From: To: , , , , , , , , CC: Subject: [PATCH] ipvlan: fix ipvlan MTU limits Date: Tue, 9 Jan 2018 14:48:37 +0800 Message-ID: <20180109064837.12916-1-liuqifa@huawei.com> X-Mailer: git-send-email 2.10.2.windows.1 MIME-Version: 1.0 X-Originating-IP: [10.177.68.80] X-CFilter-Loop: Reflected Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Keefe Liu The MTU of ipvlan interface should not bigger than the phy device, When we run following scripts, we will find there are some problems. Step1: ip link add link eth0 name ipv1 type ipvlan mode l2 ip netns add net1 ip link set dev ipv1 netns net1 Step2: ip netns exec net1 ip link set dev ipv1 mtu 1501 RTNETLINK answers: Invalid argument dmesg info: "ipv1: Invalid MTU 1501 requested, hw max 1500" Step3: ip link set dev eth0 mtu 1600 ip netns exec net1 ip link set dev ipv1 mtu 1501 RTNETLINK answers: Invalid argument dmesg info: "ipv1: Invalid MTU 1501 requested, hw max 1500" Step4: ip link set dev eth0 mtu 1400 ip netns exec net1 ip link set dev ipv1 mtu 1500 The result of Step2 is we expected, but the result of Step3 and Step4 are not. This patch set ipvlan's maximum MTU to ETH_MAX_MTU, and when we change the ipvlan device's MTU, ipvlan_change_mtu() will make sure the new MTU no larger than the phy device's MTU. Signed-off-by: Keefe Liu --- drivers/net/ipvlan/ipvlan_main.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/net/ipvlan/ipvlan_main.c b/drivers/net/ipvlan/ipvlan_main.c index 30cb803..84c007d 100644 --- a/drivers/net/ipvlan/ipvlan_main.c +++ b/drivers/net/ipvlan/ipvlan_main.c @@ -380,12 +380,24 @@ static int ipvlan_get_iflink(const struct net_device *dev) return ipvlan->phy_dev->ifindex; } +static int ipvlan_change_mtu(struct net_device *dev, int new_mtu) +{ + struct ipvl_dev *ipvlan = netdev_priv(dev); + + if (ipvlan->phy_dev->mtu < new_mtu) + return -EINVAL; + + dev->mtu = new_mtu; + return 0; +} + static const struct net_device_ops ipvlan_netdev_ops = { .ndo_init = ipvlan_init, .ndo_uninit = ipvlan_uninit, .ndo_open = ipvlan_open, .ndo_stop = ipvlan_stop, .ndo_start_xmit = ipvlan_start_xmit, + .ndo_change_mtu = ipvlan_change_mtu, .ndo_fix_features = ipvlan_fix_features, .ndo_change_rx_flags = ipvlan_change_rx_flags, .ndo_set_rx_mode = ipvlan_set_multicast_mac_filter, @@ -680,6 +692,8 @@ void ipvlan_link_setup(struct net_device *dev) { ether_setup(dev); + dev->min_mtu = 0; + dev->max_mtu = ETH_MAX_MTU; dev->priv_flags &= ~(IFF_XMIT_DST_RELEASE | IFF_TX_SKB_SHARING); dev->priv_flags |= IFF_UNICAST_FLT | IFF_NO_QUEUE; dev->netdev_ops = &ipvlan_netdev_ops;