blob: 1054461df63465a28c28fda5e40c02bc51d05b7a [file] [log] [blame]
Lorenz Brund842aaf2025-02-17 17:39:46 +01001From c3812bf1e990bdb282fd27cfa3dc3987e5a80607 Mon Sep 17 00:00:00 2001
Lorenz Brunc7a332b2024-09-12 17:58:42 +02002From: Lorenz Brun <lorenz@monogon.tech>
3Date: Thu, 12 Sep 2024 17:22:04 +0200
4Subject: [PATCH] net: add config option for tunnel fallback devs
5
6This adds a Kconfig option to set the default behavior regarding tunnel
7fallback devices.
8For setups where the initial namespace should also not have these, the
9only preexisting option is to use a kernel command line option which
10needs to be passed to every kernel invocation, which can be inconvenient
11in certain setups.
12If a kernel is built for a specific environment this knob allows
13disabling the compatibility behavior outright, without requiring any
14additional actions.
15---
16 net/Kconfig | 33 +++++++++++++++++++++++++++++++++
17 net/core/sysctl_net_core.c | 2 +-
18 2 files changed, 34 insertions(+), 1 deletion(-)
19
20diff --git a/net/Kconfig b/net/Kconfig
Lorenz Brund842aaf2025-02-17 17:39:46 +010021index a629f92dc86b..13d508908a66 100644
Lorenz Brunc7a332b2024-09-12 17:58:42 +020022--- a/net/Kconfig
23+++ b/net/Kconfig
Lorenz Brund842aaf2025-02-17 17:39:46 +010024@@ -453,6 +453,39 @@ config LWTUNNEL_BPF
Lorenz Brunc7a332b2024-09-12 17:58:42 +020025 Allows to run BPF programs as a nexthop action following a route
26 lookup for incoming and outgoing packets.
27
28+choice
29+ prompt "Create fallback tunnel devices"
30+ default FB_TUNNELS_DEFAULT_ALL
31+ help
32+ Fallback tunnel devices predate the Netlink API for managing network
33+ devices in Linux and get created when the respective tunnel kernel module
34+ is loaded. With a modern userspace these are no longer used but for
35+ compatibility reasons the default is to keep them around as the kernel
36+ cannot know if a given userspace needs them.
37+ There is a sysctl (net.core.fb_tunnels_only_for_init_net) for changing
38+ this, but it cannot retroactively remove fallback tunnel devices created
39+ before it was changed.
40+
41+ This knob provides the possibility to set this behavior in the kernel,
42+ making it work in all cases. Note that changing this value to anything
43+ other than the default will break compatibility with old userspace.
44+
45+ config FB_TUNNELS_DEFAULT_ALL
46+ bool "In every namespace"
47+
48+ config FB_TUNNELS_DEFAULT_INITNS
49+ bool "Only in the initial namespace"
50+
51+ config FB_TUNNELS_DEFAULT_NONE
52+ bool "Never"
53+endchoice
54+
55+config FB_TUNNELS_DEFAULT
56+ int
57+ default 0 if FB_TUNNELS_DEFAULT_ALL
58+ default 1 if FB_TUNNELS_DEFAULT_INITNS
59+ default 2 if FB_TUNNELS_DEFAULT_NONE
60+
61 config DST_CACHE
62 bool
63 default n
64diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
Lorenz Brund842aaf2025-02-17 17:39:46 +010065index 5dd54a813398..45d0d5dab5ff 100644
Lorenz Brunc7a332b2024-09-12 17:58:42 +020066--- a/net/core/sysctl_net_core.c
67+++ b/net/core/sysctl_net_core.c
68@@ -37,7 +37,7 @@ static int min_mem_pcpu_rsv = SK_MEMORY_PCPU_RESERVE;
69
70 static int net_msg_warn; /* Unused, but still a sysctl */
71
72-int sysctl_fb_tunnels_only_for_init_net __read_mostly = 0;
73+int sysctl_fb_tunnels_only_for_init_net __read_mostly = CONFIG_FB_TUNNELS_DEFAULT;
74 EXPORT_SYMBOL(sysctl_fb_tunnels_only_for_init_net);
75
76 /* 0 - Keep current behavior:
77--
Lorenz Brund842aaf2025-02-17 17:39:46 +0100782.47.2
Lorenz Brunc7a332b2024-09-12 17:58:42 +020079