Skip to content

Commit 1e80295

Browse files
hao022davem330
authored andcommitted
udp: Move the udp sysctl to namespace.
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 <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 859844e commit 1e80295

File tree

4 files changed

+96
-77
lines changed

4 files changed

+96
-77
lines changed

include/net/netns/ipv4.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ struct netns_ipv4 {
168168
atomic_t tfo_active_disable_times;
169169
unsigned long tfo_active_disable_stamp;
170170

171+
int sysctl_udp_wmem_min;
172+
int sysctl_udp_rmem_min;
173+
171174
#ifdef CONFIG_NET_L3_MASTER_DEV
172175
int sysctl_udp_l3mdev_accept;
173176
#endif

net/ipv4/sysctl_net_ipv4.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -520,22 +520,6 @@ static struct ctl_table ipv4_table[] = {
520520
.mode = 0644,
521521
.proc_handler = proc_doulongvec_minmax,
522522
},
523-
{
524-
.procname = "udp_rmem_min",
525-
.data = &sysctl_udp_rmem_min,
526-
.maxlen = sizeof(sysctl_udp_rmem_min),
527-
.mode = 0644,
528-
.proc_handler = proc_dointvec_minmax,
529-
.extra1 = &one
530-
},
531-
{
532-
.procname = "udp_wmem_min",
533-
.data = &sysctl_udp_wmem_min,
534-
.maxlen = sizeof(sysctl_udp_wmem_min),
535-
.mode = 0644,
536-
.proc_handler = proc_dointvec_minmax,
537-
.extra1 = &one
538-
},
539523
{ }
540524
};
541525

@@ -1167,6 +1151,22 @@ static struct ctl_table ipv4_net_table[] = {
11671151
.proc_handler = proc_dointvec_minmax,
11681152
.extra1 = &one,
11691153
},
1154+
{
1155+
.procname = "udp_rmem_min",
1156+
.data = &init_net.ipv4.sysctl_udp_rmem_min,
1157+
.maxlen = sizeof(init_net.ipv4.sysctl_udp_rmem_min),
1158+
.mode = 0644,
1159+
.proc_handler = proc_dointvec_minmax,
1160+
.extra1 = &one
1161+
},
1162+
{
1163+
.procname = "udp_wmem_min",
1164+
.data = &init_net.ipv4.sysctl_udp_wmem_min,
1165+
.maxlen = sizeof(init_net.ipv4.sysctl_udp_wmem_min),
1166+
.mode = 0644,
1167+
.proc_handler = proc_dointvec_minmax,
1168+
.extra1 = &one
1169+
},
11701170
{ }
11711171
};
11721172

net/ipv4/udp.c

Lines changed: 51 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,6 @@ EXPORT_SYMBOL(udp_table);
122122
long sysctl_udp_mem[3] __read_mostly;
123123
EXPORT_SYMBOL(sysctl_udp_mem);
124124

125-
int sysctl_udp_rmem_min __read_mostly;
126-
EXPORT_SYMBOL(sysctl_udp_rmem_min);
127-
128-
int sysctl_udp_wmem_min __read_mostly;
129-
EXPORT_SYMBOL(sysctl_udp_wmem_min);
130-
131125
atomic_long_t udp_memory_allocated;
132126
EXPORT_SYMBOL(udp_memory_allocated);
133127

@@ -2533,35 +2527,35 @@ int udp_abort(struct sock *sk, int err)
25332527
EXPORT_SYMBOL_GPL(udp_abort);
25342528

25352529
struct proto udp_prot = {
2536-
.name = "UDP",
2537-
.owner = THIS_MODULE,
2538-
.close = udp_lib_close,
2539-
.connect = ip4_datagram_connect,
2540-
.disconnect = udp_disconnect,
2541-
.ioctl = udp_ioctl,
2542-
.init = udp_init_sock,
2543-
.destroy = udp_destroy_sock,
2544-
.setsockopt = udp_setsockopt,
2545-
.getsockopt = udp_getsockopt,
2546-
.sendmsg = udp_sendmsg,
2547-
.recvmsg = udp_recvmsg,
2548-
.sendpage = udp_sendpage,
2549-
.release_cb = ip4_datagram_release_cb,
2550-
.hash = udp_lib_hash,
2551-
.unhash = udp_lib_unhash,
2552-
.rehash = udp_v4_rehash,
2553-
.get_port = udp_v4_get_port,
2554-
.memory_allocated = &udp_memory_allocated,
2555-
.sysctl_mem = sysctl_udp_mem,
2556-
.sysctl_wmem = &sysctl_udp_wmem_min,
2557-
.sysctl_rmem = &sysctl_udp_rmem_min,
2558-
.obj_size = sizeof(struct udp_sock),
2559-
.h.udp_table = &udp_table,
2530+
.name = "UDP",
2531+
.owner = THIS_MODULE,
2532+
.close = udp_lib_close,
2533+
.connect = ip4_datagram_connect,
2534+
.disconnect = udp_disconnect,
2535+
.ioctl = udp_ioctl,
2536+
.init = udp_init_sock,
2537+
.destroy = udp_destroy_sock,
2538+
.setsockopt = udp_setsockopt,
2539+
.getsockopt = udp_getsockopt,
2540+
.sendmsg = udp_sendmsg,
2541+
.recvmsg = udp_recvmsg,
2542+
.sendpage = udp_sendpage,
2543+
.release_cb = ip4_datagram_release_cb,
2544+
.hash = udp_lib_hash,
2545+
.unhash = udp_lib_unhash,
2546+
.rehash = udp_v4_rehash,
2547+
.get_port = udp_v4_get_port,
2548+
.memory_allocated = &udp_memory_allocated,
2549+
.sysctl_mem = sysctl_udp_mem,
2550+
.sysctl_wmem_offset = offsetof(struct net, ipv4.sysctl_udp_wmem_min),
2551+
.sysctl_rmem_offset = offsetof(struct net, ipv4.sysctl_udp_rmem_min),
2552+
.obj_size = sizeof(struct udp_sock),
2553+
.h.udp_table = &udp_table,
25602554
#ifdef CONFIG_COMPAT
2561-
.compat_setsockopt = compat_udp_setsockopt,
2562-
.compat_getsockopt = compat_udp_getsockopt,
2555+
.compat_setsockopt = compat_udp_setsockopt,
2556+
.compat_getsockopt = compat_udp_getsockopt,
25632557
#endif
2564-
.diag_destroy = udp_abort,
2558+
.diag_destroy = udp_abort,
25652559
};
25662560
EXPORT_SYMBOL(udp_prot);
25672561

@@ -2831,6 +2825,26 @@ u32 udp_flow_hashrnd(void)
28312825
}
28322826
EXPORT_SYMBOL(udp_flow_hashrnd);
28332827

2828+
static void __udp_sysctl_init(struct net *net)
2829+
{
2830+
net->ipv4.sysctl_udp_rmem_min = SK_MEM_QUANTUM;
2831+
net->ipv4.sysctl_udp_wmem_min = SK_MEM_QUANTUM;
2832+
2833+
#ifdef CONFIG_NET_L3_MASTER_DEV
2834+
net->ipv4.sysctl_udp_l3mdev_accept = 0;
2835+
#endif
2836+
}
2837+
2838+
static int __net_init udp_sysctl_init(struct net *net)
2839+
{
2840+
__udp_sysctl_init(net);
2841+
return 0;
2842+
}
2843+
2844+
static struct pernet_operations __net_initdata udp_sysctl_ops = {
2845+
.init = udp_sysctl_init,
2846+
};
2847+
28342848
void __init udp_init(void)
28352849
{
28362850
unsigned long limit;
@@ -2843,8 +2857,7 @@ void __init udp_init(void)
28432857
sysctl_udp_mem[1] = limit;
28442858
sysctl_udp_mem[2] = sysctl_udp_mem[0] * 2;
28452859

2846-
sysctl_udp_rmem_min = SK_MEM_QUANTUM;
2847-
sysctl_udp_wmem_min = SK_MEM_QUANTUM;
2860+
__udp_sysctl_init(&init_net);
28482861

28492862
/* 16 spinlocks per cpu */
28502863
udp_busylocks_log = ilog2(nr_cpu_ids) + 4;
@@ -2854,4 +2867,7 @@ void __init udp_init(void)
28542867
panic("UDP: failed to alloc udp_busylocks\n");
28552868
for (i = 0; i < (1U << udp_busylocks_log); i++)
28562869
spin_lock_init(udp_busylocks + i);
2870+
2871+
if (register_pernet_subsys(&udp_sysctl_ops))
2872+
panic("UDP: failed to init sysctl parameters.\n");
28572873
}

net/ipv6/udp.c

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,34 +1509,34 @@ void udp6_proc_exit(struct net *net)
15091509
/* ------------------------------------------------------------------------ */
15101510

15111511
struct proto udpv6_prot = {
1512-
.name = "UDPv6",
1513-
.owner = THIS_MODULE,
1514-
.close = udp_lib_close,
1515-
.connect = ip6_datagram_connect,
1516-
.disconnect = udp_disconnect,
1517-
.ioctl = udp_ioctl,
1518-
.init = udp_init_sock,
1519-
.destroy = udpv6_destroy_sock,
1520-
.setsockopt = udpv6_setsockopt,
1521-
.getsockopt = udpv6_getsockopt,
1522-
.sendmsg = udpv6_sendmsg,
1523-
.recvmsg = udpv6_recvmsg,
1524-
.release_cb = ip6_datagram_release_cb,
1525-
.hash = udp_lib_hash,
1526-
.unhash = udp_lib_unhash,
1527-
.rehash = udp_v6_rehash,
1528-
.get_port = udp_v6_get_port,
1529-
.memory_allocated = &udp_memory_allocated,
1530-
.sysctl_mem = sysctl_udp_mem,
1531-
.sysctl_wmem = &sysctl_udp_wmem_min,
1532-
.sysctl_rmem = &sysctl_udp_rmem_min,
1533-
.obj_size = sizeof(struct udp6_sock),
1534-
.h.udp_table = &udp_table,
1512+
.name = "UDPv6",
1513+
.owner = THIS_MODULE,
1514+
.close = udp_lib_close,
1515+
.connect = ip6_datagram_connect,
1516+
.disconnect = udp_disconnect,
1517+
.ioctl = udp_ioctl,
1518+
.init = udp_init_sock,
1519+
.destroy = udpv6_destroy_sock,
1520+
.setsockopt = udpv6_setsockopt,
1521+
.getsockopt = udpv6_getsockopt,
1522+
.sendmsg = udpv6_sendmsg,
1523+
.recvmsg = udpv6_recvmsg,
1524+
.release_cb = ip6_datagram_release_cb,
1525+
.hash = udp_lib_hash,
1526+
.unhash = udp_lib_unhash,
1527+
.rehash = udp_v6_rehash,
1528+
.get_port = udp_v6_get_port,
1529+
.memory_allocated = &udp_memory_allocated,
1530+
.sysctl_mem = sysctl_udp_mem,
1531+
.sysctl_wmem_offset = offsetof(struct net, ipv4.sysctl_udp_wmem_min),
1532+
.sysctl_rmem_offset = offsetof(struct net, ipv4.sysctl_udp_rmem_min),
1533+
.obj_size = sizeof(struct udp6_sock),
1534+
.h.udp_table = &udp_table,
15351535
#ifdef CONFIG_COMPAT
1536-
.compat_setsockopt = compat_udpv6_setsockopt,
1537-
.compat_getsockopt = compat_udpv6_getsockopt,
1536+
.compat_setsockopt = compat_udpv6_setsockopt,
1537+
.compat_getsockopt = compat_udpv6_getsockopt,
15381538
#endif
1539-
.diag_destroy = udp_abort,
1539+
.diag_destroy = udp_abort,
15401540
};
15411541

15421542
static struct inet_protosw udpv6_protosw = {

0 commit comments

Comments
 (0)