If set to 1, both IPv4 and IPv6 settings are forced to inherit from
 current ones in init_net. If set to 2, both IPv4 and IPv6 settings are
-forced to reset to their default values.
+forced to reset to their default values. If set to 3, both IPv4 and IPv6
+settings are forced to inherit from current ones in the netns where this
+new netns has been created.
 
 Default : 0  (for compatibility reasons)
 
 
 #include <net/pkt_sched.h>
 
 static int two __maybe_unused = 2;
+static int three = 3;
 static int min_sndbuf = SOCK_MIN_SNDBUF;
 static int min_rcvbuf = SOCK_MIN_RCVBUF;
 static int max_skb_frags = MAX_SKB_FRAGS;
  *     IPv6: reset all settings to default
  * 1 - Both inherit all current settings from init_net
  * 2 - Both reset all settings to default
+ * 3 - Both inherit all settings from current netns
  */
 int sysctl_devconf_inherit_init_net __read_mostly;
 EXPORT_SYMBOL(sysctl_devconf_inherit_init_net);
                .mode           = 0644,
                .proc_handler   = proc_dointvec_minmax,
                .extra1         = SYSCTL_ZERO,
-               .extra2         = &two,
+               .extra2         = &three,
        },
        {
                .procname       = "high_order_alloc_disable",
 
        tbl[0].extra2 = net;
 #endif
 
-       if ((!IS_ENABLED(CONFIG_SYSCTL) ||
-            sysctl_devconf_inherit_init_net != 2) &&
-           !net_eq(net, &init_net)) {
-               memcpy(all, init_net.ipv4.devconf_all, sizeof(ipv4_devconf));
-               memcpy(dflt, init_net.ipv4.devconf_dflt, sizeof(ipv4_devconf_dflt));
+       if (!net_eq(net, &init_net)) {
+               if (IS_ENABLED(CONFIG_SYSCTL) &&
+                   sysctl_devconf_inherit_init_net == 3) {
+                       /* copy from the current netns */
+                       memcpy(all, current->nsproxy->net_ns->ipv4.devconf_all,
+                              sizeof(ipv4_devconf));
+                       memcpy(dflt,
+                              current->nsproxy->net_ns->ipv4.devconf_dflt,
+                              sizeof(ipv4_devconf_dflt));
+               } else if (!IS_ENABLED(CONFIG_SYSCTL) ||
+                          sysctl_devconf_inherit_init_net != 2) {
+                       /* inherit == 0 or 1: copy from init_net */
+                       memcpy(all, init_net.ipv4.devconf_all,
+                              sizeof(ipv4_devconf));
+                       memcpy(dflt, init_net.ipv4.devconf_dflt,
+                              sizeof(ipv4_devconf_dflt));
+               }
+               /* else inherit == 2: use compiled values */
        }
 
 #ifdef CONFIG_SYSCTL
 
                goto err_alloc_dflt;
 
        if (IS_ENABLED(CONFIG_SYSCTL) &&
-           sysctl_devconf_inherit_init_net == 1 && !net_eq(net, &init_net)) {
-               memcpy(all, init_net.ipv6.devconf_all, sizeof(ipv6_devconf));
-               memcpy(dflt, init_net.ipv6.devconf_dflt, sizeof(ipv6_devconf_dflt));
+           !net_eq(net, &init_net)) {
+               switch (sysctl_devconf_inherit_init_net) {
+               case 1:  /* copy from init_net */
+                       memcpy(all, init_net.ipv6.devconf_all,
+                              sizeof(ipv6_devconf));
+                       memcpy(dflt, init_net.ipv6.devconf_dflt,
+                              sizeof(ipv6_devconf_dflt));
+                       break;
+               case 3: /* copy from the current netns */
+                       memcpy(all, current->nsproxy->net_ns->ipv6.devconf_all,
+                              sizeof(ipv6_devconf));
+                       memcpy(dflt,
+                              current->nsproxy->net_ns->ipv6.devconf_dflt,
+                              sizeof(ipv6_devconf_dflt));
+                       break;
+               case 0:
+               case 2:
+                       /* use compiled values */
+                       break;
+               }
        }
 
        /* these will be inherited by all namespaces */