All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next] net-loopback: allow lo dev initial state to be controlled
@ 2020-11-11 20:43 Jian Yang
  2020-11-12 16:08 ` Andrew Lunn
                   ` (2 more replies)
  0 siblings, 3 replies; 26+ messages in thread
From: Jian Yang @ 2020-11-11 20:43 UTC (permalink / raw)
  To: davem, kuba, netdev; +Cc: Mahesh Bandewar, Jian Yang

From: Mahesh Bandewar <maheshb@google.com>

Traditionally loopback devices comes up with initial state as DOWN for
any new network-namespace. This would mean that anyone needing this
device (which is mostly true except sandboxes where networking in not
needed at all), would have to bring this UP by issuing something like
'ip link set lo up' which can be avoided if the initial state can be set
as UP. Also ICMP error propagation needs loopback to be UP.

The default value for this sysctl is set to ZERO which will preserve the
backward compatible behavior for the root-netns while changing the
sysctl will only alter the behavior of the newer network namespaces.

Signed-off-by: Mahesh Bandewar <maheshb@google.com>
Signed-off-by: Jian Yang <jianyang@google.com>
---
 Documentation/admin-guide/sysctl/net.rst | 11 +++++++++++
 drivers/net/loopback.c                   |  7 +++++++
 include/linux/netdevice.h                |  1 +
 net/core/sysctl_net_core.c               | 14 ++++++++++++++
 4 files changed, 33 insertions(+)

diff --git a/Documentation/admin-guide/sysctl/net.rst b/Documentation/admin-guide/sysctl/net.rst
index f2ab8a5b6a4b..6902232ff57a 100644
--- a/Documentation/admin-guide/sysctl/net.rst
+++ b/Documentation/admin-guide/sysctl/net.rst
@@ -268,6 +268,17 @@ Maximum number of microseconds in one NAPI polling cycle. Polling
 will exit when either netdev_budget_usecs have elapsed during the
 poll cycle or the number of packets processed reaches netdev_budget.
 
+netdev_loopback_state
+---------------------
+
+Controls the loopback device initial state for any new network namespaces. By
+default, we keep the initial state as DOWN.
+
+If set to 1, the loopback device will be brought UP during namespace creation.
+This will only apply to all new network namespaces.
+
+Default : 0  (for compatibility reasons)
+
 netdev_max_backlog
 ------------------
 
diff --git a/drivers/net/loopback.c b/drivers/net/loopback.c
index a1c77cc00416..76dc92ac65a2 100644
--- a/drivers/net/loopback.c
+++ b/drivers/net/loopback.c
@@ -219,6 +219,13 @@ static __net_init int loopback_net_init(struct net *net)
 
 	BUG_ON(dev->ifindex != LOOPBACK_IFINDEX);
 	net->loopback_dev = dev;
+
+	if (sysctl_netdev_loopback_state) {
+		/* Bring loopback device UP */
+		rtnl_lock();
+		dev_open(dev, NULL);
+		rtnl_unlock();
+	}
 	return 0;
 
 out_free_netdev:
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 7ce648a564f7..27c0a7e8a8ea 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -625,6 +625,7 @@ struct netdev_queue {
 
 extern int sysctl_fb_tunnels_only_for_init_net;
 extern int sysctl_devconf_inherit_init_net;
+extern int sysctl_netdev_loopback_state;
 
 /*
  * sysctl_fb_tunnels_only_for_init_net == 0 : For all netns
diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
index d86d8d11cfe4..d2cf435f5991 100644
--- a/net/core/sysctl_net_core.c
+++ b/net/core/sysctl_net_core.c
@@ -35,6 +35,11 @@ static int net_msg_warn;	/* Unused, but still a sysctl */
 int sysctl_fb_tunnels_only_for_init_net __read_mostly = 0;
 EXPORT_SYMBOL(sysctl_fb_tunnels_only_for_init_net);
 
+/* 0 - default (backward compatible) state: DOWN by default
+ * 1 - UP by default (for all new network namespaces)
+ */
+int sysctl_netdev_loopback_state __read_mostly;
+
 /* 0 - Keep current behavior:
  *     IPv4: inherit all current settings from init_net
  *     IPv6: reset all settings to default
@@ -507,6 +512,15 @@ static struct ctl_table net_core_table[] = {
 		.proc_handler	= set_default_qdisc
 	},
 #endif
+	{
+		.procname	= "netdev_loopback_state",
+		.data		= &sysctl_netdev_loopback_state,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec_minmax,
+		.extra1		= SYSCTL_ZERO,
+		.extra2		= SYSCTL_ONE
+	},
 #endif /* CONFIG_NET */
 	{
 		.procname	= "netdev_budget",
-- 
2.29.2.222.g5d2a92d10f8-goog


^ permalink raw reply related	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2020-12-02 20:55 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-11 20:43 [PATCH net-next] net-loopback: allow lo dev initial state to be controlled Jian Yang
2020-11-12 16:08 ` Andrew Lunn
2020-11-12 19:54   ` Dan Williams
2020-11-14 18:17 ` Jakub Kicinski
2020-11-16 20:02   ` Mahesh Bandewar (महेश बंडेवार)
2020-11-16 20:17     ` Jakub Kicinski
2020-11-16 20:50       ` Mahesh Bandewar (महेश बंडेवार)
2020-11-16 21:20         ` Jakub Kicinski
2020-11-16 21:42           ` Mahesh Bandewar (महेश बंडेवार)
2020-11-16 20:34     ` Jakub Kicinski
2020-11-16 21:03       ` Mahesh Bandewar (महेश बंडेवार)
2020-11-17 17:18         ` Ido Schimmel
2020-11-17 20:53           ` Mahesh Bandewar (महेश बंडेवार)
2020-11-18  1:12             ` David Ahern
2020-11-18 16:58               ` Nicolas Dichtel
2020-11-18 17:39                 ` Mahesh Bandewar (महेश बंडेवार)
2020-11-18 18:04                   ` David Ahern
2020-11-18 19:54                     ` Mahesh Bandewar (महेश बंडेवार)
2020-11-19  8:03                   ` Nicolas Dichtel
2020-11-20  3:55                     ` Mahesh Bandewar (महेश बंडेवार)
2020-11-20  4:56                       ` Jakub Kicinski
2020-12-01 20:24                         ` Mahesh Bandewar (महेश बंडेवार)
2020-12-02  2:38                           ` Jakub Kicinski
2020-12-02 20:53                             ` Mahesh Bandewar (महेश बंडेवार)
2020-11-17  4:50 ` kernel test robot
2020-11-17  4:50   ` kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.