udp: Move the udp sysctl to namespace.
authorTonghao Zhang <xiangxia.m.yue@gmail.com>
Wed, 14 Mar 2018 04:57:16 +0000 (21:57 -0700)
committerDavid S. Miller <davem@davemloft.net>
Fri, 16 Mar 2018 16:03:30 +0000 (12:03 -0400)
This patch moves the udp_rmem_min, udp_wmem_min
to namespace and init the udp_l3mdev_accept explicitly.

The udp_rmem_min/udp_wmem_min affect udp rx/tx queue,
with this patch namespaces can set them differently.

Signed-off-by: Tonghao Zhang <xiangxia.m.yue@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/netns/ipv4.h
net/ipv4/sysctl_net_ipv4.c
net/ipv4/udp.c
net/ipv6/udp.c

index 3a970e429ab6c324c38610b435dec77c523b72ac..382bfd7583cfc0008d164ca31e11e6ca4f04acaf 100644 (file)
@@ -168,6 +168,9 @@ struct netns_ipv4 {
        atomic_t tfo_active_disable_times;
        unsigned long tfo_active_disable_stamp;
 
+       int sysctl_udp_wmem_min;
+       int sysctl_udp_rmem_min;
+
 #ifdef CONFIG_NET_L3_MASTER_DEV
        int sysctl_udp_l3mdev_accept;
 #endif
index 011de9a20ec630b79986847ac907b8cc85ed024a..5b72d97693f82ef56bed43b14865d649a6e59d38 100644 (file)
@@ -520,22 +520,6 @@ static struct ctl_table ipv4_table[] = {
                .mode           = 0644,
                .proc_handler   = proc_doulongvec_minmax,
        },
-       {
-               .procname       = "udp_rmem_min",
-               .data           = &sysctl_udp_rmem_min,
-               .maxlen         = sizeof(sysctl_udp_rmem_min),
-               .mode           = 0644,
-               .proc_handler   = proc_dointvec_minmax,
-               .extra1         = &one
-       },
-       {
-               .procname       = "udp_wmem_min",
-               .data           = &sysctl_udp_wmem_min,
-               .maxlen         = sizeof(sysctl_udp_wmem_min),
-               .mode           = 0644,
-               .proc_handler   = proc_dointvec_minmax,
-               .extra1         = &one
-       },
        { }
 };
 
@@ -1167,6 +1151,22 @@ static struct ctl_table ipv4_net_table[] = {
                .proc_handler   = proc_dointvec_minmax,
                .extra1         = &one,
        },
+       {
+               .procname       = "udp_rmem_min",
+               .data           = &init_net.ipv4.sysctl_udp_rmem_min,
+               .maxlen         = sizeof(init_net.ipv4.sysctl_udp_rmem_min),
+               .mode           = 0644,
+               .proc_handler   = proc_dointvec_minmax,
+               .extra1         = &one
+       },
+       {
+               .procname       = "udp_wmem_min",
+               .data           = &init_net.ipv4.sysctl_udp_wmem_min,
+               .maxlen         = sizeof(init_net.ipv4.sysctl_udp_wmem_min),
+               .mode           = 0644,
+               .proc_handler   = proc_dointvec_minmax,
+               .extra1         = &one
+       },
        { }
 };
 
index 3013404d093550069c42e214d6ee0a38ff6ec1d9..908fc02fb4f83e7533cb38ab1ba7b4fe5857c022 100644 (file)
@@ -122,12 +122,6 @@ EXPORT_SYMBOL(udp_table);
 long sysctl_udp_mem[3] __read_mostly;
 EXPORT_SYMBOL(sysctl_udp_mem);
 
-int sysctl_udp_rmem_min __read_mostly;
-EXPORT_SYMBOL(sysctl_udp_rmem_min);
-
-int sysctl_udp_wmem_min __read_mostly;
-EXPORT_SYMBOL(sysctl_udp_wmem_min);
-
 atomic_long_t udp_memory_allocated;
 EXPORT_SYMBOL(udp_memory_allocated);
 
@@ -2533,35 +2527,35 @@ int udp_abort(struct sock *sk, int err)
 EXPORT_SYMBOL_GPL(udp_abort);
 
 struct proto udp_prot = {
-       .name              = "UDP",
-       .owner             = THIS_MODULE,
-       .close             = udp_lib_close,
-       .connect           = ip4_datagram_connect,
-       .disconnect        = udp_disconnect,
-       .ioctl             = udp_ioctl,
-       .init              = udp_init_sock,
-       .destroy           = udp_destroy_sock,
-       .setsockopt        = udp_setsockopt,
-       .getsockopt        = udp_getsockopt,
-       .sendmsg           = udp_sendmsg,
-       .recvmsg           = udp_recvmsg,
-       .sendpage          = udp_sendpage,
-       .release_cb        = ip4_datagram_release_cb,
-       .hash              = udp_lib_hash,
-       .unhash            = udp_lib_unhash,
-       .rehash            = udp_v4_rehash,
-       .get_port          = udp_v4_get_port,
-       .memory_allocated  = &udp_memory_allocated,
-       .sysctl_mem        = sysctl_udp_mem,
-       .sysctl_wmem       = &sysctl_udp_wmem_min,
-       .sysctl_rmem       = &sysctl_udp_rmem_min,
-       .obj_size          = sizeof(struct udp_sock),
-       .h.udp_table       = &udp_table,
+       .name                   = "UDP",
+       .owner                  = THIS_MODULE,
+       .close                  = udp_lib_close,
+       .connect                = ip4_datagram_connect,
+       .disconnect             = udp_disconnect,
+       .ioctl                  = udp_ioctl,
+       .init                   = udp_init_sock,
+       .destroy                = udp_destroy_sock,
+       .setsockopt             = udp_setsockopt,
+       .getsockopt             = udp_getsockopt,
+       .sendmsg                = udp_sendmsg,
+       .recvmsg                = udp_recvmsg,
+       .sendpage               = udp_sendpage,
+       .release_cb             = ip4_datagram_release_cb,
+       .hash                   = udp_lib_hash,
+       .unhash                 = udp_lib_unhash,
+       .rehash                 = udp_v4_rehash,
+       .get_port               = udp_v4_get_port,
+       .memory_allocated       = &udp_memory_allocated,
+       .sysctl_mem             = sysctl_udp_mem,
+       .sysctl_wmem_offset     = offsetof(struct net, ipv4.sysctl_udp_wmem_min),
+       .sysctl_rmem_offset     = offsetof(struct net, ipv4.sysctl_udp_rmem_min),
+       .obj_size               = sizeof(struct udp_sock),
+       .h.udp_table            = &udp_table,
 #ifdef CONFIG_COMPAT
-       .compat_setsockopt = compat_udp_setsockopt,
-       .compat_getsockopt = compat_udp_getsockopt,
+       .compat_setsockopt      = compat_udp_setsockopt,
+       .compat_getsockopt      = compat_udp_getsockopt,
 #endif
-       .diag_destroy      = udp_abort,
+       .diag_destroy           = udp_abort,
 };
 EXPORT_SYMBOL(udp_prot);
 
@@ -2831,6 +2825,26 @@ u32 udp_flow_hashrnd(void)
 }
 EXPORT_SYMBOL(udp_flow_hashrnd);
 
+static void __udp_sysctl_init(struct net *net)
+{
+       net->ipv4.sysctl_udp_rmem_min = SK_MEM_QUANTUM;
+       net->ipv4.sysctl_udp_wmem_min = SK_MEM_QUANTUM;
+
+#ifdef CONFIG_NET_L3_MASTER_DEV
+       net->ipv4.sysctl_udp_l3mdev_accept = 0;
+#endif
+}
+
+static int __net_init udp_sysctl_init(struct net *net)
+{
+       __udp_sysctl_init(net);
+       return 0;
+}
+
+static struct pernet_operations __net_initdata udp_sysctl_ops = {
+       .init       = udp_sysctl_init,
+};
+
 void __init udp_init(void)
 {
        unsigned long limit;
@@ -2843,8 +2857,7 @@ void __init udp_init(void)
        sysctl_udp_mem[1] = limit;
        sysctl_udp_mem[2] = sysctl_udp_mem[0] * 2;
 
-       sysctl_udp_rmem_min = SK_MEM_QUANTUM;
-       sysctl_udp_wmem_min = SK_MEM_QUANTUM;
+       __udp_sysctl_init(&init_net);
 
        /* 16 spinlocks per cpu */
        udp_busylocks_log = ilog2(nr_cpu_ids) + 4;
@@ -2854,4 +2867,7 @@ void __init udp_init(void)
                panic("UDP: failed to alloc udp_busylocks\n");
        for (i = 0; i < (1U << udp_busylocks_log); i++)
                spin_lock_init(udp_busylocks + i);
+
+       if (register_pernet_subsys(&udp_sysctl_ops))
+               panic("UDP: failed to init sysctl parameters.\n");
 }
index 52e3ea0e6f507702251b3dade8ae43181331d975..ad30f5e319699d0d79c976d8a7544d5d4a85e2cd 100644 (file)
@@ -1509,34 +1509,34 @@ void udp6_proc_exit(struct net *net)
 /* ------------------------------------------------------------------------ */
 
 struct proto udpv6_prot = {
-       .name              = "UDPv6",
-       .owner             = THIS_MODULE,
-       .close             = udp_lib_close,
-       .connect           = ip6_datagram_connect,
-       .disconnect        = udp_disconnect,
-       .ioctl             = udp_ioctl,
-       .init              = udp_init_sock,
-       .destroy           = udpv6_destroy_sock,
-       .setsockopt        = udpv6_setsockopt,
-       .getsockopt        = udpv6_getsockopt,
-       .sendmsg           = udpv6_sendmsg,
-       .recvmsg           = udpv6_recvmsg,
-       .release_cb        = ip6_datagram_release_cb,
-       .hash              = udp_lib_hash,
-       .unhash            = udp_lib_unhash,
-       .rehash            = udp_v6_rehash,
-       .get_port          = udp_v6_get_port,
-       .memory_allocated  = &udp_memory_allocated,
-       .sysctl_mem        = sysctl_udp_mem,
-       .sysctl_wmem       = &sysctl_udp_wmem_min,
-       .sysctl_rmem       = &sysctl_udp_rmem_min,
-       .obj_size          = sizeof(struct udp6_sock),
-       .h.udp_table       = &udp_table,
+       .name                   = "UDPv6",
+       .owner                  = THIS_MODULE,
+       .close                  = udp_lib_close,
+       .connect                = ip6_datagram_connect,
+       .disconnect             = udp_disconnect,
+       .ioctl                  = udp_ioctl,
+       .init                   = udp_init_sock,
+       .destroy                = udpv6_destroy_sock,
+       .setsockopt             = udpv6_setsockopt,
+       .getsockopt             = udpv6_getsockopt,
+       .sendmsg                = udpv6_sendmsg,
+       .recvmsg                = udpv6_recvmsg,
+       .release_cb             = ip6_datagram_release_cb,
+       .hash                   = udp_lib_hash,
+       .unhash                 = udp_lib_unhash,
+       .rehash                 = udp_v6_rehash,
+       .get_port               = udp_v6_get_port,
+       .memory_allocated       = &udp_memory_allocated,
+       .sysctl_mem             = sysctl_udp_mem,
+       .sysctl_wmem_offset     = offsetof(struct net, ipv4.sysctl_udp_wmem_min),
+       .sysctl_rmem_offset     = offsetof(struct net, ipv4.sysctl_udp_rmem_min),
+       .obj_size               = sizeof(struct udp6_sock),
+       .h.udp_table            = &udp_table,
 #ifdef CONFIG_COMPAT
-       .compat_setsockopt = compat_udpv6_setsockopt,
-       .compat_getsockopt = compat_udpv6_getsockopt,
+       .compat_setsockopt      = compat_udpv6_setsockopt,
+       .compat_getsockopt      = compat_udpv6_getsockopt,
 #endif
-       .diag_destroy      = udp_abort,
+       .diag_destroy           = udp_abort,
 };
 
 static struct inet_protosw udpv6_protosw = {