From patchwork Tue Jul 29 09:29:32 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhu Yanjun X-Patchwork-Id: 374381 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 A24F2140199 for ; Tue, 29 Jul 2014 19:30:25 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753159AbaG2J37 (ORCPT ); Tue, 29 Jul 2014 05:29:59 -0400 Received: from mail-pa0-f47.google.com ([209.85.220.47]:61428 "EHLO mail-pa0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753138AbaG2J35 (ORCPT ); Tue, 29 Jul 2014 05:29:57 -0400 Received: by mail-pa0-f47.google.com with SMTP id kx10so12060011pab.20 for ; Tue, 29 Jul 2014 02:29:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :content-type; bh=90asjwe8TTS8k1lB73+qs8lPGGwiycaZqy/Ulq0F+z4=; b=IjLXbrmcFYS9euc/JYvgUraX4xkqwZvA4laComQHxlhh7JgdUIRZT1d+Ndqf8IC7LU d4/HNZT8cG1coy7PTYmFAsYvusrclBJ3ypDaTQDg25712twtap1APviF2s+vFNQDP+cK y0U9Ybs/CU4rMPEBoPInyEHrlx9cx4H5s/oCXj6coaOlKjkO+zNnRghq1Duv5TRhX0dF eHRFqXKJ6ub5TZ8v2NZ2InRISEe/59MN7vt4JjSR+A4B82J9Vgdihec5Ij33r+MuWPzP UHmDeImZgSKKOYXvrhTH4vBrl4u9WdbMUocYgyh76g5TZV6hh91cTppbvf/VnflF/TfT l9Xg== X-Received: by 10.66.65.169 with SMTP id y9mr669671pas.145.1406626197002; Tue, 29 Jul 2014 02:29:57 -0700 (PDT) Received: from [128.224.162.201] ([1.202.252.122]) by mx.google.com with ESMTPSA id dv3sm33915931pac.26.2014.07.29.02.29.53 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 29 Jul 2014 02:29:56 -0700 (PDT) Message-ID: <53D7697C.6020103@gmail.com> Date: Tue, 29 Jul 2014 17:29:32 +0800 From: zhuyj User-Agent: Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 To: "David S. Miller" , Hong Zhiguo CC: LKML , netdev , zhuyj , "Tao, Yue" , Alexandre Dietsch Subject: ipv4: net namespace does not inherit network configurations Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Hi,all I did a test on kernel3.16 rc6: root@qemu1:~# echo 1 > /proc/sys/net/ipv6/conf/all/forwarding root@qemu1:~# echo 1 > /proc/sys/net/ipv4/conf/all/forwarding root@qemu1:~# ip netns list root@qemu1:~# ip netns add fib1 root@qemu1:~# ip netns exec fib1 bash root@qemu1:~# cat /proc/sys/net/ipv6/conf/all/forwarding 0 root@qemu1:~# cat /proc/sys/net/ipv4/conf/all/forwarding 1 The behavior of ipv4 and ipv6 is very inconsistent. I checked the kernel source code. I found that from this patch [ipv6: fix bad free of addrconf_init_net], the above difference appeared. Since a net namespace is independent to another. That is, there is no any relationship between the net namespaces. So the behavior of ipv4 is not correct. Based on this patch [ipv6: fix bad free of addrconf_init_net], I made a new patch to fix this problem on ipv4. Any reply is appreciated. Zhu Yanjun From f3a68831d7c58b185d57f30130217b22a8e2c71f Mon Sep 17 00:00:00 2001 From: Zhu Yanjun Date: Tue, 29 Jul 2014 17:23:10 +0800 Subject: [PATCH 1/1] ipv4: net namespace does not inherit network configurations Ipv4 net namespace requires a similar logic change as commit c900a800 [ipv6: fix bad free of addrconf_init_net] introduces for newer kernels. Since a net namespace is independent to another. That is, there is no any relationship between the net namespaces. So a new net namespace should not inherit network configurations from another net namespace including the host. CC: Hong Zhiguo CC: David S. Miller Signed-off-by: Zhu Yanjun --- net/ipv4/devinet.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c index e944937..a16aa39 100644 --- a/net/ipv4/devinet.c +++ b/net/ipv4/devinet.c @@ -2220,28 +2220,23 @@ static __net_init int devinet_init_net(struct net *net) #endif err = -ENOMEM; - all = &ipv4_devconf; - dflt = &ipv4_devconf_dflt; - if (!net_eq(net, &init_net)) { - all = kmemdup(all, sizeof(ipv4_devconf), GFP_KERNEL); - if (all == NULL) - goto err_alloc_all; - - dflt = kmemdup(dflt, sizeof(ipv4_devconf_dflt), GFP_KERNEL); - if (dflt == NULL) - goto err_alloc_dflt; + all = kmemdup(&ipv4_devconf, sizeof(ipv4_devconf), GFP_KERNEL); + if (all == NULL) + goto err_alloc_all; + dflt = kmemdup(&ipv4_devconf_dflt, sizeof(ipv4_devconf_dflt), GFP_KERNEL); + if (dflt == NULL) + goto err_alloc_dflt; #ifdef CONFIG_SYSCTL - tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL); - if (tbl == NULL) - goto err_alloc_ctl; + tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL); + if (tbl == NULL) + goto err_alloc_ctl; - tbl[0].data = &all->data[IPV4_DEVCONF_FORWARDING - 1]; - tbl[0].extra1 = all; - tbl[0].extra2 = net; + tbl[0].data = &all->data[IPV4_DEVCONF_FORWARDING - 1]; + tbl[0].extra1 = all; + tbl[0].extra2 = net; #endif - } #ifdef CONFIG_SYSCTL err = __devinet_sysctl_register(net, "all", all); -- 1.9.1