make sysctl per namespace
Subsystems (3)
PATCH 2/9 make the ipv6 sysctl to be a netns subsystem
In reply to Daniel LezcanoThe initialization of the sysctl for the ipv6 protocol is changed to a network namespace subsystem. That means when a new network namespace is created the initialization function for the sysctl will be called.
That do not change the behavior of the sysctl in case of the kernel with the network namespace disabled.
--- net/ipv6/sysctl_net_ipv6.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-)
net/ipv6/sysctl_net_ipv6.c +18 -3
@@ -90,16 +90,31 @@ static struct ctl_path ipv6_ctl_path[] =static struct ctl_table_header *ipv6_sysctl_header; -int ipv6_sysctl_register (void ) +static int ipv6_sysctl_net_init (struct net *net) { - ipv6_sysctl_header =register_sysctl_paths (ipv6_ctl_path, ipv6_table); + ipv6_sysctl_header =register_net_sysctl_table (net, ipv6_ctl_path, ipv6_table);if (!ipv6_sysctl_header)return -ENOMEM ;return 0 ; } +static void ipv6_sysctl_net_exit (struct net *net) +{ +unregister_net_sysctl_table (ipv6_sysctl_header); +} + +static struct pernet_operations ipv6_sysctl_net_ops = { + .init = ipv6_sysctl_net_init, + .exit = ipv6_sysctl_net_exit, +}; + +int ipv6_sysctl_register (void ) +{ +return register_pernet_subsys (&ipv6_sysctl_net_ops); +} +void ipv6_sysctl_unregister (void ) { -unregister_sysctl_table (ipv6_sysctl_header); +unregister_pernet_subsys (&ipv6_sysctl_net_ops); }
PATCH 4/9 make multiple instance of sysctl tables
In reply to Daniel LezcanoEach network namespace wants its own set of sysctl value, eg. we should not be able from a namespace to set a sysctl value for another namespace , especially for the initial network namespace.
This patch duplicates the sysctl table when we register a new network namespace for ipv6. The duplicated table are postfixed with the "template" word to notify the developper the table is cloned.
--- include/net/ipv6.h | 4 +- include/net/netns/ipv6.h | 9 ++++++ net/ipv6/icmp.c | 12 +++++++- net/ipv6/route.c | 11 ++++++- net/ipv6/sysctl_net_ipv6.c | 67 +++++++++++++++++++++++++++++++++++++-------- 5 files changed, 88 insertions(+), 15 deletions(-)
net/ipv6/sysctl_net_ipv6.c +56 -11
@@ -14,20 +14,23 @@#include <net/addrconf.h> #include <net/inet_frag.h> -static ctl_table ipv6_table[] = { +extern struct ctl_table *ipv6_route_sysctl_init (struct net *net); +extern struct ctl_table *ipv6_icmp_sysctl_init (struct net *net); + +static ctl_table ipv6_table_template[] = { { .ctl_name =NET_IPV6_ROUTE , .procname ="route" , .maxlen =0 , .mode =0555 , - .child = ipv6_route_table + .child = ipv6_route_table_template }, { .ctl_name =NET_IPV6_ICMP , .procname ="icmp" , .maxlen =0 , .mode =0555 , - .child = ipv6_icmp_table + .child = ipv6_icmp_table_template }, { .ctl_name =NET_IPV6_BINDV6ONLY ,
@@ -88,20 +91,62 @@ static struct ctl_path ipv6_ctl_path[] = { }, }; -static struct ctl_table_header *ipv6_sysctl_header; -static int ipv6_sysctl_net_init (struct net *net) { - ipv6_sysctl_header =register_net_sysctl_table (net, ipv6_ctl_path, ipv6_table); -if (!ipv6_sysctl_header) -return -ENOMEM ; - -return 0 ; +struct ctl_table *ipv6_table; +struct ctl_table *ipv6_route_table; +struct ctl_table *ipv6_icmp_table; +int err; + + err = -ENOMEM ; + ipv6_table =kmemdup (ipv6_table_template,sizeof (ipv6_table_template), +GFP_KERNEL ); +if (!ipv6_table) + goto out; + + ipv6_route_table =ipv6_route_sysctl_init (net); +if (!ipv6_route_table) + goto out_ipv6_table; + + ipv6_icmp_table =ipv6_icmp_sysctl_init (net); +if (!ipv6_icmp_table) + goto out_ipv6_route_table; + + ipv6_table[0 ].child = ipv6_route_table; + ipv6_table[1 ].child = ipv6_icmp_table; + + net->ipv6.sysctl.table =register_net_sysctl_table (net, ipv6_ctl_path, ipv6_table); +if (!net->ipv6.sysctl.table) + goto out_ipv6_icmp_table; + + err =0 ; +out: +return err; + +out_ipv6_icmp_table: +kfree (ipv6_icmp_table); +out_ipv6_route_table: +kfree (ipv6_route_table); +out_ipv6_table: +kfree (ipv6_table); + goto out; }static void ipv6_sysctl_net_exit (struct net *net) { -unregister_net_sysctl_table (ipv6_sysctl_header); +struct ctl_table *ipv6_table; +struct ctl_table *ipv6_route_table; +struct ctl_table *ipv6_icmp_table; + + ipv6_table = net->ipv6.sysctl.table->ctl_table_arg; + ipv6_route_table = ipv6_table[0 ].child; + ipv6_icmp_table = ipv6_table[1 ].child; + +unregister_net_sysctl_table (net->ipv6.sysctl.table); + +kfree (ipv6_table); +kfree (ipv6_route_table); +kfree (ipv6_icmp_table); }static struct pernet_operations ipv6_sysctl_net_ops = {
include/net/netns/ipv6.h +9 -0
@@ -5,6 +5,15 @@#ifndef __NETNS_IPV6_H__#define __NETNS_IPV6_H__ +struct ctl_table_header ; + +struct netns_sysctl_ipv6 { +struct ctl_table_header *table; +}; +struct netns_ipv6 { +#ifdef CONFIG_SYSCTL +struct netns_sysctl_ipv6 sysctl; +#endif };#endif
include/net/ipv6.h +2 -2
@@ -617,8 +617,8 @@ static inline int snmp6_unregister_dev(s#endif #ifdef CONFIG_SYSCTL -extern ctl_table ipv6_route_table[]; -extern ctl_table ipv6_icmp_table[]; +extern ctl_table ipv6_route_table_template[]; +extern ctl_table ipv6_icmp_table_template[];extern int ipv6_sysctl_register (void );extern void ipv6_sysctl_unregister (void );
net/ipv6/icmp.c +11 -1
@@ -909,7 +909,7 @@ int icmpv6_err_convert(int type, int codEXPORT_SYMBOL (icmpv6_err_convert); #ifdef CONFIG_SYSCTL -ctl_table ipv6_icmp_table[] = { +ctl_table ipv6_icmp_table_template[] = { { .ctl_name = NET_IPV6_ICMP_RATELIMIT, .procname = "ratelimit",
@@ -920,5 +920,15 @@ ctl_table ipv6_icmp_table[] = { }, { .ctl_name = 0 }, }; + +struct ctl_table *ipv6_icmp_sysctl_init (struct net *net) +{ +struct ctl_table *table; + + table =kmemdup (ipv6_icmp_table_template, +sizeof (ipv6_icmp_table_template), +GFP_KERNEL ); +return table; +}#endif
net/ipv6/route.c +10 -1
@@ -2404,7 +2404,7 @@ int ipv6_sysctl_rtcache_flush(ctl_tablereturn -EINVAL ; } -ctl_table ipv6_route_table[] = { +ctl_table ipv6_route_table_template[] = { { .procname ="flush" , .data = &flush_delay,
@@ -2494,6 +2494,15 @@ ctl_table ipv6_route_table[] = { { .ctl_name = 0 } }; +struct ctl_table *ipv6_route_sysctl_init (struct net *net) +{ +struct ctl_table *table; + + table =kmemdup (ipv6_route_table_template, +sizeof (ipv6_route_table_template), +GFP_KERNEL ); +return table; +}#endif int __init ip6_route_init (void )
PATCH 6/9 make ip6_frags per namespace
In reply to Daniel LezcanoThe ip6_frags is moved to the network namespace structure. Because there can be multiple instances of the network namespaces, and the ip6_frags is no longer a global static variable, a helper function has been added to facilitate the initialization of the variables.
Until the ipv6 protocol is not per namespace, the variables are accessed relatively from the initial network namespace.
--- include/net/ipv6.h | 3 --- include/net/netns/ipv6.h | 3 +++ net/ipv6/reassembly.c | 21 ++++++++++++--------- net/ipv6/sysctl_net_ipv6.c | 15 +++++++++++---- 4 files changed, 26 insertions(+), 16 deletions(-)
include/net/ipv6.h +0 -3
@@ -570,9 +570,6 @@ extern int inet6_hash_connect(struct ine/* * reassembly.c */ -struct inet_frags_ctl ; -extern struct inet_frags_ctl ip6_frags_ctl; -extern const struct proto_ops inet6_stream_ops;extern const struct proto_ops inet6_dgram_ops;
include/net/netns/ipv6.h +3 -0
@@ -2,6 +2,8 @@* ipv6 in net namespaces */ +#include <net/inet_frag.h> +#ifndef __NETNS_IPV6_H__#define __NETNS_IPV6_H__
@@ -9,6 +11,7 @@ struct ctl_table_header;struct netns_sysctl_ipv6 {struct ctl_table_header *table; +struct inet_frags_ctl frags;int bindv6only; };
net/ipv6/reassembly.c +12 -9
@@ -82,13 +82,6 @@ struct frag_queue__u16 nhoffset; }; -struct inet_frags_ctl ip6_frags_ctl__read_mostly = { - .high_thresh =256 *1024 , - .low_thresh =192 *1024 , - .timeout =IPV6_FRAG_TIMEOUT , - .secret_interval =10 *60 *HZ , -}; -static struct inet_frags ip6_frags;int ip6_frag_nqueues (void )
@@ -605,7 +598,7 @@ static int ipv6_frag_rcv(struct sk_buffreturn 1 ; } -if (atomic_read (&ip6_frags.mem) > ip6_frags_ctl.high_thresh) +if (atomic_read (&ip6_frags.mem) > init_net.ipv6.sysctl.frags.high_thresh)ip6_evictor (ip6_dst_idev (skb->dst)); if ((fq = fq_find(fhdr->identification, &hdr->saddr, &hdr->daddr,
@@ -632,6 +625,16 @@ static struct inet6_protocol frag_protoc .flags = INET6_PROTO_NOPOLICY, }; +void ipv6_frag_sysctl_init (struct net *net) +{ + net->ipv6.sysctl.frags.high_thresh =256 *1024 , + net->ipv6.sysctl.frags.low_thresh =192 *1024 , + net->ipv6.sysctl.frags.timeout =IPV6_FRAG_TIMEOUT , + net->ipv6.sysctl.frags.secret_interval =10 *60 *HZ , + + ip6_frags.ctl = &net->ipv6.sysctl.frags; +} +int __init ipv6_frag_init (void ) {int ret;
@@ -639,7 +642,7 @@ int __init ipv6_frag_init(void) ret =inet6_add_protocol (&frag_protocol,IPPROTO_FRAGMENT );if (ret) goto out; - ip6_frags.ctl = &ip6_frags_ctl; + ip6_frags.hashfn = ip6_hashfn; ip6_frags.constructor = ip6_frag_init; ip6_frags.destructor =NULL ;
net/ipv6/sysctl_net_ipv6.c +11 -4
@@ -16,6 +16,7 @@extern struct ctl_table *ipv6_route_sysctl_init (struct net *net);extern struct ctl_table *ipv6_icmp_sysctl_init (struct net *net); +extern void ipv6_frag_sysctl_init (struct net *net);static ctl_table ipv6_table_template[] = { {
@@ -43,7 +44,7 @@ static ctl_table ipv6_table_template[] = { .ctl_name = NET_IPV6_IP6FRAG_HIGH_THRESH, .procname = "ip6frag_high_thresh", - .data = &ip6_frags_ctl.high_thresh, + .data = &init_net.ipv6.sysctl.frags.high_thresh, .maxlen = sizeof(int), .mode =0644 , .proc_handler = &proc_dointvec
@@ -51,7 +52,7 @@ static ctl_table ipv6_table_template[] = { .ctl_name = NET_IPV6_IP6FRAG_LOW_THRESH, .procname = "ip6frag_low_thresh", - .data = &ip6_frags_ctl.low_thresh, + .data = &init_net.ipv6.sysctl.frags.low_thresh, .maxlen = sizeof(int), .mode =0644 , .proc_handler = &proc_dointvec
@@ -59,7 +60,7 @@ static ctl_table ipv6_table_template[] = { .ctl_name = NET_IPV6_IP6FRAG_TIME, .procname = "ip6frag_time", - .data = &ip6_frags_ctl.timeout, + .data = &init_net.ipv6.sysctl.frags.timeout, .maxlen = sizeof(int), .mode = 0644, .proc_handler = &proc_dointvec_jiffies,
@@ -68,7 +69,7 @@ static ctl_table ipv6_table_template[] = { .ctl_name = NET_IPV6_IP6FRAG_SECRET_INTERVAL, .procname = "ip6frag_secret_interval", - .data = &ip6_frags_ctl.secret_interval, + .data = &init_net.ipv6.sysctl.frags.secret_interval, .maxlen = sizeof(int), .mode = 0644, .proc_handler = &proc_dointvec_jiffies,
@@ -116,6 +117,12 @@ static int ipv6_sysctl_net_init(struct n ipv6_table[1 ].child = ipv6_icmp_table; ipv6_table[2 ].data = &net->ipv6.sysctl.bindv6only; + ipv6_table[3 ].data = &net->ipv6.sysctl.frags.high_thresh; + ipv6_table[4 ].data = &net->ipv6.sysctl.frags.low_thresh; + ipv6_table[5 ].data = &net->ipv6.sysctl.frags.timeout; + ipv6_table[6 ].data = &net->ipv6.sysctl.frags.secret_interval; + +ipv6_frag_sysctl_init (net); net->ipv6.sysctl.bindv6only =0 ;
PATCH 1/9 make ipv6_sysctl_register to return a value
In reply to Daniel LezcanoThis patch makes the function ipv6_sysctl_register to return a value. The af_inet6 init function is now able to catch and handle an error from the initialization of the sysctl.
--- include/net/ipv6.h | 2 +- net/ipv6/af_inet6.c | 5 ++++- net/ipv6/sysctl_net_ipv6.c | 6 +++++- 3 files changed, 10 insertions(+), 3 deletions(-)
include/net/ipv6.h +1 -1
@@ -620,7 +620,7 @@ static inline int snmp6_unregister_dev(sextern ctl_table ipv6_route_table[];extern ctl_table ipv6_icmp_table[]; -extern void ipv6_sysctl_register (void ); +extern int ipv6_sysctl_register (void );extern void ipv6_sysctl_unregister (void );#endif
net/ipv6/af_inet6.c +4 -1
@@ -783,7 +783,9 @@ static int __init inet6_init(void)*/ #ifdef CONFIG_SYSCTL -ipv6_sysctl_register (); + err =ipv6_sysctl_register (); +if (err) + goto sysctl_fail;#endif err =icmpv6_init (&inet6_family_ops);if (err)
@@ -897,6 +899,7 @@ ndisc_fail: icmp_fail: #ifdef CONFIG_SYSCTLipv6_sysctl_unregister (); +sysctl_fail: #endifcleanup_ipv6_mibs (); out_unregister_sock:
net/ipv6/sysctl_net_ipv6.c +5 -1
@@ -90,9 +90,13 @@ static struct ctl_path ipv6_ctl_path[] =static struct ctl_table_header *ipv6_sysctl_header; -void ipv6_sysctl_register (void ) +int ipv6_sysctl_register (void ) { ipv6_sysctl_header =register_sysctl_paths (ipv6_ctl_path, ipv6_table); +if (!ipv6_sysctl_header) +return -ENOMEM ; + +return 0 ; }void ipv6_sysctl_unregister (void )
cover make sysctl per namespace
The following patchset makes the ipv6 sysctl to handle multiple network namespaces. Each instance of a network namespace as its own set of sysctl values, that means the behavior of the ipv6 stack can be different depending on the sysctl values setup in the different network namespaces.
PATCH 7/9 make mld_max_msf per namespace
The mld_max_msf variable is moved to the network namespace structure. A helper function has been added to initialize the variable.
Because the ipv6 protocol is not yet per namespace, the variable is accessed relatively from the initial network namespace.
--- include/net/ipv6.h | 3 --- include/net/netns/ipv6.h | 1 + net/ipv6/ipv6_sockglue.c | 3 +-- net/ipv6/mcast.c | 9 ++++++--- net/ipv6/sysctl_net_ipv6.c | 5 ++++- 5 files changed, 12 insertions(+), 9 deletions(-)
include/net/ipv6.h +0 -3
@@ -108,9 +108,6 @@ struct frag_hdr {#include <net/sock.h> -/* sysctls */ -extern int sysctl_mld_max_msf; -#define _DEVINC (statname, modifier, idev, field) \ ({ \ struct inet6_dev *_idev = (idev); \
include/net/netns/ipv6.h +1 -0
@@ -13,6 +13,7 @@ struct netns_sysctl_ipv6 {struct ctl_table_header *table;struct inet_frags_ctl frags;int bindv6only; +int mld_max_msf; };struct netns_ipv6 {
net/ipv6/ipv6_sockglue.c +1 -2
@@ -656,7 +656,6 @@ done: }case MCAST_MSFILTER : { -extern int sysctl_mld_max_msf;struct group_filter *gsf;if (optlen <GROUP_FILTER_SIZE (0 ))
@@ -677,7 +676,7 @@ done: }/* numsrc >= (4G-140)/128 overflow in 32 bits */ if (gsf->gf_numsrc >=0x1ffffffU || - gsf->gf_numsrc > sysctl_mld_max_msf) { + gsf->gf_numsrc > init_net.ipv6.sysctl.mld_max_msf) {kfree (gsf); retv = -ENOBUFS ;break ;
net/ipv6/mcast.c +6 -3
@@ -172,8 +172,6 @@ static int ip6_mc_leave_src(struct sock#define IPV6_MLD_MAX_MSF 64 -int sysctl_mld_max_msf__read_mostly =IPV6_MLD_MAX_MSF ; -/* * socket join on multicast group */
@@ -441,7 +439,7 @@ int ip6_mc_source(int add, int omode, st }/* else, add a new source to the filter */ -if (psl && psl->sl_count >= sysctl_mld_max_msf) { +if (psl && psl->sl_count >= init_net.ipv6.sysctl.mld_max_msf) { err = -ENOBUFS ; goto done; }
@@ -2597,6 +2595,11 @@ static const struct file_operations igmp };#endif +void igmp6_sysctl_init (struct net *net) +{ + net->ipv6.sysctl.mld_max_msf =IPV6_MLD_MAX_MSF ; +} +int __init igmp6_init (struct net_proto_family *ops) {struct ipv6_pinfo *np;
net/ipv6/sysctl_net_ipv6.c +4 -1
@@ -17,6 +17,7 @@extern struct ctl_table *ipv6_route_sysctl_init (struct net *net);extern struct ctl_table *ipv6_icmp_sysctl_init (struct net *net);extern void ipv6_frag_sysctl_init (struct net *net); +extern void igmp6_sysctl_init (struct net *net);static ctl_table ipv6_table_template[] = { {
@@ -78,7 +79,7 @@ static ctl_table ipv6_table_template[] = { .ctl_name = NET_IPV6_MLD_MAX_MSF, .procname = "mld_max_msf", - .data = &sysctl_mld_max_msf, + .data = &init_net.ipv6.sysctl.mld_max_msf, .maxlen = sizeof(int), .mode =0644 , .proc_handler = &proc_dointvec
@@ -121,8 +122,10 @@ static int ipv6_sysctl_net_init(struct n ipv6_table[4 ].data = &net->ipv6.sysctl.frags.low_thresh; ipv6_table[5 ].data = &net->ipv6.sysctl.frags.timeout; ipv6_table[6 ].data = &net->ipv6.sysctl.frags.secret_interval; + ipv6_table[7 ].data = &net->ipv6.sysctl.mld_max_msf;ipv6_frag_sysctl_init (net); +igmp6_sysctl_init (net); net->ipv6.sysctl.bindv6only =0 ;
PATCH 8/9 make sysctls route per namespace
In reply to Daniel LezcanoAll the sysctl concerning the routes are moved to the network namespace structure.
Because the ipv6 protocol is not yet per namespace, the variables are accessed relatively from the network namespace.
--- include/net/ip6_route.h | 2 - include/net/netns/ipv6.h | 8 ++++++ net/ipv6/ip6_fib.c | 14 ++++++---- net/ipv6/route.c | 58 ++++++++++++++++++++++----------------------- net/ipv6/sysctl_net_ipv6.c | 9 ++++++ 5 files changed, 55 insertions(+), 36 deletions(-)
include/net/netns/ipv6.h +8 -0
@@ -14,6 +14,14 @@ struct netns_sysctl_ipv6 {struct inet_frags_ctl frags;int bindv6only;int mld_max_msf; +int flush_delay; +int ip6_rt_max_size; +int ip6_rt_gc_min_interval; +int ip6_rt_gc_timeout; +int ip6_rt_gc_interval; +int ip6_rt_gc_elasticity; +int ip6_rt_mtu_expires; +int ip6_rt_min_advmss; };struct netns_ipv6 {
net/ipv6/route.c +29 -29
168 lines not on this page · raw message
net/ipv6/sysctl_net_ipv6.c +9 -0
@@ -114,7 +114,16 @@ static int ipv6_sysctl_net_init(struct nif (!ipv6_icmp_table) goto out_ipv6_route_table; + ipv6_route_table[0 ].data = &net->ipv6.sysctl.flush_delay; + ipv6_route_table[2 ].data = &net->ipv6.sysctl.ip6_rt_max_size; + ipv6_route_table[3 ].data = &net->ipv6.sysctl.ip6_rt_gc_min_interval; + ipv6_route_table[4 ].data = &net->ipv6.sysctl.ip6_rt_gc_timeout; + ipv6_route_table[5 ].data = &net->ipv6.sysctl.ip6_rt_gc_interval; + ipv6_route_table[6 ].data = &net->ipv6.sysctl.ip6_rt_gc_elasticity; + ipv6_route_table[7 ].data = &net->ipv6.sysctl.ip6_rt_mtu_expires; + ipv6_route_table[8 ].data = &net->ipv6.sysctl.ip6_rt_min_advmss; ipv6_table[0 ].child = ipv6_route_table; + ipv6_table[1 ].child = ipv6_icmp_table; ipv6_table[2 ].data = &net->ipv6.sysctl.bindv6only;
include/net/ip6_route.h +0 -2
@@ -43,8 +43,6 @@ extern struct rt6_info ip6_prohibit_entrextern struct rt6_info ip6_blk_hole_entry;#endif -extern int ip6_rt_gc_interval; -extern void ip6_route_input (struct sk_buff *skb); extern struct dst_entry * ip6_route_output(struct sock *sk,
net/ipv6/ip6_fib.c +9 -5
@@ -681,13 +681,15 @@ static __inline__ void fib6_start_gc(str {if (ip6_fib_timer.expires ==0 && (rt->rt6i_flags & (RTF_EXPIRES |RTF_CACHE ))) -mod_timer (&ip6_fib_timer, jiffies + ip6_rt_gc_interval); +mod_timer (&ip6_fib_timer, jiffies + + init_net.ipv6.sysctl.ip6_rt_gc_interval); }void fib6_force_start_gc (void ) {if (ip6_fib_timer.expires ==0 ) -mod_timer (&ip6_fib_timer, jiffies + ip6_rt_gc_interval); +mod_timer (&ip6_fib_timer, jiffies + + init_net.ipv6.sysctl.ip6_rt_gc_interval); }/*
@@ -1447,7 +1449,8 @@ void fib6_run_gc(unsigned long dummy) {if (dummy != ~0UL ) {spin_lock_bh (&fib6_gc_lock); - gc_args.timeout = dummy ? (int )dummy : ip6_rt_gc_interval; + gc_args.timeout = dummy ? (int )dummy : + init_net.ipv6.sysctl.ip6_rt_gc_interval; }else {local_bh_disable ();if (!spin_trylock (&fib6_gc_lock)) {
@@ -1455,7 +1458,7 @@ void fib6_run_gc(unsigned long dummy)local_bh_enable ();return ; } - gc_args.timeout = ip6_rt_gc_interval; + gc_args.timeout = init_net.ipv6.sysctl.ip6_rt_gc_interval; } gc_args.more =0 ;
@@ -1463,7 +1466,8 @@ void fib6_run_gc(unsigned long dummy)fib6_clean_all (fib6_age,0 ,NULL );if (gc_args.more) -mod_timer (&ip6_fib_timer, jiffies + ip6_rt_gc_interval); +mod_timer (&ip6_fib_timer, jiffies + + init_net.ipv6.sysctl.ip6_rt_gc_interval);else {del_timer (&ip6_fib_timer); ip6_fib_timer.expires =0 ;
PATCH 3/9 make ipv6 structure for netns
In reply to Daniel LezcanoLike the ipv4 part, this patch adds an ipv6 structure in the net structure to aggregate the different resources to make ipv6 per namespace.
--- include/net/net_namespace.h | 2 ++ include/net/netns/ipv6.h | 10 ++++++++++ 2 files changed, 12 insertions(+)
include/net/net_namespace.h +2 -0
@@ -11,6 +11,7 @@#include <net/netns/unix.h> #include <net/netns/packet.h> #include <net/netns/ipv4.h> +#include <net/netns/ipv6.h> struct proc_dir_entry ;struct net_device ;
@@ -48,6 +49,7 @@ struct net {struct netns_packet packet;struct netns_unix unx;struct netns_ipv4 ipv4; +struct netns_ipv6 ipv6; };#ifdef CONFIG_NET
include/net/netns/ipv6.h new file +10 -0
@@ -0,0 +1,10 @@ +/* +* ipv6 in net namespaces +*/ + +#ifndef __NETNS_IPV6_H__ +#define __NETNS_IPV6_H__ + +struct netns_ipv6 { +}; +#endif
PATCH 9/9 make icmpv6_time sysctl per namespace
In reply to Daniel LezcanoThis patch moves the icmpv6_time sysctl to the network namespace structure. A small initialization helper function has been added.
Because the ipv6 protocol is not yet per namespace, the variable is accessed relatively to the initial network namespace.
--- include/net/netns/ipv6.h | 1 + net/ipv6/icmp.c | 8 ++++---- net/ipv6/sysctl_net_ipv6.c | 1 + 3 files changed, 6 insertions(+), 4 deletions(-)
include/net/netns/ipv6.h +1 -0
@@ -22,6 +22,7 @@ struct netns_sysctl_ipv6 {int ip6_rt_gc_elasticity;int ip6_rt_mtu_expires;int ip6_rt_min_advmss; +int icmpv6_time; };struct netns_ipv6 {
net/ipv6/icmp.c +4 -4
@@ -154,8 +154,6 @@ static int is_ineligible(struct sk_buffreturn 0 ; } -static int sysctl_icmpv6_time__read_mostly =1 *HZ ; -/* * Check the ICMP output rate limit */
@@ -186,7 +184,7 @@ static inline int icmpv6_xrlim_allow(str res =1 ; }else {struct rt6_info *rt = (struct rt6_info *)dst; -int tmo = sysctl_icmpv6_time; +int tmo = init_net.ipv6.sysctl.icmpv6_time;/* Give more bandwidth to wider prefixes. */ if (rt->rt6i_dst.plen <128 )
@@ -913,7 +911,7 @@ ctl_table ipv6_icmp_table_template[] = { { .ctl_name = NET_IPV6_ICMP_RATELIMIT, .procname = "ratelimit", - .data = &sysctl_icmpv6_time, + .data = &init_net.ipv6.sysctl.icmpv6_time, .maxlen = sizeof(int), .mode =0644 , .proc_handler = &proc_dointvec
@@ -925,6 +923,8 @@ struct ctl_table *ipv6_icmp_sysctl_init( {struct ctl_table *table; + net->ipv6.sysctl.icmpv6_time =1 *HZ ; + table =kmemdup (ipv6_icmp_table_template,sizeof (ipv6_icmp_table_template),GFP_KERNEL );
net/ipv6/sysctl_net_ipv6.c +1 -0
@@ -124,6 +124,7 @@ static int ipv6_sysctl_net_init(struct n ipv6_route_table[8 ].data = &net->ipv6.sysctl.ip6_rt_min_advmss; ipv6_table[0 ].child = ipv6_route_table; + ipv6_icmp_table[0 ].data = &net->ipv6.sysctl.icmpv6_time; ipv6_table[1 ].child = ipv6_icmp_table; ipv6_table[2 ].data = &net->ipv6.sysctl.bindv6only;
PATCH 5/9 make bindv6only sysctl per namespace
In reply to Daniel LezcanoThis patch moves the bindv6only sysctl to the network namespace structure. Until the ipv6 protocol is not per namespace, the sysctl variable is always from the initial network namespace.
--- include/net/ipv6.h | 1 - include/net/netns/ipv6.h | 1 + net/ipv6/af_inet6.c | 4 +--- net/ipv6/sysctl_net_ipv6.c | 6 +++++- 4 files changed, 7 insertions(+), 5 deletions(-)
include/net/ipv6.h +0 -1
@@ -109,7 +109,6 @@ struct frag_hdr {#include <net/sock.h> /* sysctls */ -extern int sysctl_ipv6_bindv6only;extern int sysctl_mld_max_msf;#define _DEVINC (statname, modifier, idev, field) \
include/net/netns/ipv6.h +1 -0
@@ -9,6 +9,7 @@ struct ctl_table_header;struct netns_sysctl_ipv6 {struct ctl_table_header *table; +int bindv6only; };struct netns_ipv6 {
net/ipv6/af_inet6.c +1 -3
@@ -66,8 +66,6 @@ MODULE_AUTHOR("Cast of dozens");MODULE_DESCRIPTION ("IPv6 protocol stack for Linux" );MODULE_LICENSE ("GPL" ); -int sysctl_ipv6_bindv6only__read_mostly ; -/* The inetsw6 table contains everything that inet6_create needs to * build a new socket. */
@@ -193,7 +191,7 @@ lookup_protocol: np->mcast_hops =-1 ; np->mc_loop =1 ; np->pmtudisc =IPV6_PMTUDISC_WANT ; - np->ipv6only = sysctl_ipv6_bindv6only; + np->ipv6only = init_net.ipv6.sysctl.bindv6only;/* Init the ipv4 part of the socket since we can have sockets * using v6 API for ipv4.
net/ipv6/sysctl_net_ipv6.c +5 -1
@@ -35,7 +35,7 @@ static ctl_table ipv6_table_template[] = { .ctl_name = NET_IPV6_BINDV6ONLY, .procname = "bindv6only", - .data = &sysctl_ipv6_bindv6only, + .data = &init_net.ipv6.sysctl.bindv6only, .maxlen = sizeof(int), .mode =0644 , .proc_handler = &proc_dointvec
@@ -115,6 +115,10 @@ static int ipv6_sysctl_net_init(struct n ipv6_table[0 ].child = ipv6_route_table; ipv6_table[1 ].child = ipv6_icmp_table; + ipv6_table[2 ].data = &net->ipv6.sysctl.bindv6only; + + net->ipv6.sysctl.bindv6only =0 ; + net->ipv6.sysctl.table =register_net_sysctl_table (net, ipv6_ctl_path, ipv6_table);if (!net->ipv6.sysctl.table) goto out_ipv6_icmp_table;
Quoted 5 lines · On Wed, 02 Jan 2008 13:25:48 +0100 Daniel Lezcano <[email protected]> wrote:
The following patchset makes the ipv6 sysctl to handle multiple network namespaces. Each instance of a network namespace as its own set of sysctl values, that means the behavior of the ipv6 stack can be different depending on the sysctl values setup in the different network namespaces.
Hi Daniel
Did you tested your patches with CONFIG_SYSCTL=n ?
For example, I had to apply this patch on current git.
Thank you
[PATCH] IPV4 : Should build with CONFIG_SYSCTL=n
Previous NETNS patches broke CONFIG_SYSCTL=n case
include/net/netns/ipv4.h +2 -0
@@ -8,7 +8,9 @@ struct ctl_table_header;struct ipv4_devconf ;struct netns_ipv4 { +#ifdef CONFIG_SYSCTL struct ctl_table_header *forw_hdr; +#endif struct ipv4_devconf *devconf_all;struct ipv4_devconf *devconf_dflt; };
net/ipv4/devinet.c +11 -8
@@ -1542,7 +1542,6 @@ static void devinet_sysctl_unregister(struct in_device *idev)__devinet_sysctl_unregister (&idev->cnf);neigh_sysctl_unregister (idev->arp_parms); } -#endif static struct ctl_table ctl_forward_entry[] = { {
@@ -1565,18 +1564,20 @@ static __net_initdata struct ctl_path net_ipv4_path[] = { { .procname = "ipv4", .ctl_name = NET_IPV4, }, { }, }; +#endif static __net_init int devinet_init_net (struct net *net) {int err; -struct ctl_table *tbl; -struct ipv4_devconf *all, *dflt; +#ifdef CONFIG_SYSCTL +struct ctl_table *tbl = ctl_forward_entry;struct ctl_table_header *forw_hdr; +#endif +struct ipv4_devconf *all, *dflt; err = -ENOMEM ; all = &ipv4_devconf; dflt = &ipv4_devconf_dflt; - tbl = ctl_forward_entry;if (net != &init_net) { all =kmemdup (all,sizeof (ipv4_devconf),GFP_KERNEL );
@@ -1587,6 +1588,7 @@ static __net_init int devinet_init_net(struct net *net)if (dflt ==NULL ) goto err_alloc_dflt; +#ifdef CONFIG_SYSCTL tbl =kmemdup (tbl,sizeof (ctl_forward_entry),GFP_KERNEL );if (tbl ==NULL ) goto err_alloc_ctl;
@@ -1594,6 +1596,7 @@ static __net_init int devinet_init_net(struct net *net) tbl[0 ].data = &all->data[NET_IPV4_CONF_FORWARDING -1 ]; tbl[0 ].extra1 = all; tbl[0 ].extra2 = net; +#endif }#ifdef CONFIG_SYSCTL
@@ -1611,9 +1614,9 @@ static __net_init int devinet_init_net(struct net *net) forw_hdr =register_net_sysctl_table (net, net_ipv4_path, tbl);if (forw_hdr ==NULL ) goto err_reg_ctl; + net->ipv4.forw_hdr = forw_hdr;#endif - net->ipv4.forw_hdr = forw_hdr; net->ipv4.devconf_all = all; net->ipv4.devconf_dflt = dflt;return 0 ;
@@ -1626,8 +1629,8 @@ err_reg_dflt: err_reg_all:if (tbl != ctl_forward_entry)kfree (tbl); -#endif err_alloc_ctl: +#endif if (dflt != &ipv4_devconf_dflt)kfree (dflt); err_alloc_dflt:
@@ -1639,15 +1642,15 @@ err_alloc_all: static __net_exit void devinet_exit_net(struct net *net) { +#ifdef CONFIG_SYSCTL struct ctl_table *tbl; tbl = net->ipv4.forw_hdr->ctl_table_arg; -#ifdef CONFIG_SYSCTL unregister_net_sysctl_table (net->ipv4.forw_hdr);__devinet_sysctl_unregister (net->ipv4.devconf_dflt);__devinet_sysctl_unregister (net->ipv4.devconf_all); -#endif kfree (tbl); +#endif kfree (net->ipv4.devconf_dflt);kfree (net->ipv4.devconf_all); }
Quoted 15 lines · Eric Dumazet
Quoted 5 lines · On Wed, 02 Jan 2008 13:25:48 +0100 Daniel Lezcano <[email protected]> wrote:
The following patchset makes the ipv6 sysctl to handle multiple network namespaces. Each instance of a network namespace as its own set of sysctl values, that means the behavior of the ipv6 stack can be different depending on the sysctl values setup in the different network namespaces.
Hi Daniel
Did you tested your patches with
CONFIG_SYSCTL=n?For example, I had to apply this patch on current git.
Quoted 7 lines
Thank you
[PATCH] IPV4 : Should build with
CONFIG_SYSCTL=nPrevious NETNS patches broke
CONFIG_SYSCTL=ncaseSigned-off-by Eric Dumazet <[email protected]>
Thanks Eric for fixing that.
I compiled with CONFIG_SYSCTL=n and booted.
I try to always do allmodconfig, allyesconfig, allnoconfig with a cross-compiler for different arch, i386, x86_64, s390, ppc, ia64, sh, sparc, arm and alpha, before sending to netdev@.
-- Daniel
Re: [patch 7/9][NETNS][IPV6] make mld_max_msf per namespace
In reply to Daniel LezcanoDaniel,
I'm not sure what benefit you get from making this per-namespace.
The point of it is really to prevent one (non-root, even) application from killing machine performance with source filters (because maintaining them is an n^2 algorithm). It's a weak constraint, but the resources it's protecting are
the processor and MLDv2 packet counts. If any one namespace has a large value, all will have a problem still, and (even without your patch),
lots of separate source filters can still cause a problem. What it catches is one application creating thousands (or millions) of source filters and killing the machine and network with MLDv2 reports as a result. Why shouldn't that remain global?
+-DLS
Re: [patch 7/9][NETNS][IPV6] make mld_max_msf per namespace
Quoted 12 lines · David Stevens
Daniel,
I'm not sure what benefit you get from making this per-namespace.
The point of it is really to prevent one (non-root, even) application from killing machine performance with source filters (because maintaining them is an n^2 algorithm). It's a weak constraint, but the resources it's protecting are the processor and MLDv2 packet counts. If any one namespace has a large value, all will have a problem still, and (even without your patch), lots of separate source filters can still cause a problem. What it catches is one application creating thousands (or millions) of source filters and killing the machine and network with MLDv2 reports as a result. Why shouldn't that remain global?
Quoted 1 line
+-DLS
Good point.
The problem you are pointing is in the case you have a namespace making this variable very big. And you are right this is a problem. But, if we make the variable global to all the namespaces, we will not able to reduce this value for a specific namespace.
I propose the following solution, at the namespace creation the variable value is copied from the initial network namespace, the modification of this variable is only valid if the value is less than the initial network namespace value.
With this solution, we can handle different values for the namespaces but these values are driven by the initial network namespace because their values are lesser or equal to the one from the initial network namespace.
Is it acceptable ?
Re: [patch 7/9][NETNS][IPV6] make mld_max_msf per namespace
Daniel Lezcano <[email protected]> wrote on 01/03/2008 03:00:48 AM:
...
Quoted 6 lines
With this solution, we can handle different values for the namespaces but these values are driven by the initial network namespace because their values are lesser or equal to the one from the initial network namespace.
Is it acceptable ?
Daniel,
If you have the premise that there's a reason for them to be
different, then your original implementation is fine already. It requires root privilege to change the value, so I don't mind the ability to raise it to a higher value later.
I don't object, but I don't understand. I can't think of
any circumstances where I would want to modify it per namespace. Making it small is not an effective restriction, since someone *wanting* to use lots of sources can simply do them on different sockets of the same group. The point is to catch accidental silly use and it's protecting a global resource so differing values just change the threshold at which you catch accidental silly use in different namespaces.
Setting it to "0" might be a method of preventing its
use entirely in some namespaces, but it's part of the socket interface-- disabling it isn't something you generally want to do, either.
Are you intending to convert all variables to be
per-namespace? If not -- that is, if you will have global sysctl variables, then I think this one should be one of those. Actually, all of the IGMP & MLD variables are tied naturally to the shared interfaces, so should be global, I think.
+-DLS