Add a MODULE_SYSCTL_TABLE call into register_net_sysctl{_sz}() for existing
callers to automatically use it.Add optional 'template arguments' to support a dynamic table/path defined at run-time based on a 'template' available at build-time. Split the update of callers with template arguments into separate commits, disabling the macro for now. Signed-off-by: Mauricio Faria de Oliveira <[email protected]> --- include/linux/sysctl.h | 3 +++ include/net/net_namespace.h | 45 ++++++++++++++++++++++++++++++++++++++++----- net/sysctl_net.c | 10 +++++----- 3 files changed, 48 insertions(+), 10 deletions(-) diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h index 7e05fafd5544e1c4a3283dc13b0692f39515d01e..9e00a086ff1d47ab18021b3d79b0e8a93037cb2d 100644 --- a/include/linux/sysctl.h +++ b/include/linux/sysctl.h @@ -309,6 +309,9 @@ struct ctl_table_root { * * Define the macro SYSCTL_MODULE_ALIASES_DISABLE to disable this. */ + +#define SYSCTL_MODULE_ALIASES_DISABLE + #if defined(CONFIG_SYSCTL_MODULE_ALIASES) && defined(MODULE) && \ !defined(SYSCTL_MODULE_ALIASES_DISABLE) diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h index e5ee673b9fcf846aefcc309d4cca1a8fc870aae2..2127049c71cedade45922d7f0d3b7a3ce0af67e0 100644 --- a/include/net/net_namespace.h +++ b/include/net/net_namespace.h @@ -520,13 +520,48 @@ void unregister_pernet_device(struct pernet_operations *); struct ctl_table; -#define register_net_sysctl(net, path, table) \ - register_net_sysctl_sz(net, path, table, ARRAY_SIZE(table)) +/* + * The register_net_sysctl{_sz}() wrappers for MODULE_SYSCTL_TABLE + * automatically create symbols in sysctl registration sites. + * + * See register_sysctl() and MODULE_SYSCTL_TABLE() in <linux/sysctl.h> + * for information about template arguments and options for the macro. + * + * Usage: + * - register_net_sysctl(net, path, table); + * - register_net_sysctl(net, path, table, table_tmpl); + * - register_net_sysctl(net, path, table, table_tmpl, path_tmpl); + * - register_net_sysctl_sz(net, path, table, size); + * - register_net_sysctl_sz(net, path, table, size, table_tmpl); + * - register_net_sysctl_sz(net, path, table, size, table_tmpl, path_tmpl); + */ +#define _register_net_sysctl_sz(net, path, table, size, table_tmpl, path_tmpl) \ +({ \ + MODULE_SYSCTL_TABLE(path_tmpl, table_tmpl); \ + __register_net_sysctl_sz(net, path, table, size); \ +}) + +#define register_net_sysctl_sz(net, path, table, size, tmpl_args...) \ + _register_net_sysctl_sz(net, path, table, size, \ + __sysctl_table_tmpl_or_default(table, \ + ## tmpl_args), \ + __sysctl_path_tmpl_or_default(path, \ + ## tmpl_args)) +#define register_net_sysctl(net, path, table, tmpl_args...) \ + register_net_sysctl_sz(net, path, table, \ + __sysctl_table_array_size(table, ## tmpl_args), \ + ## tmpl_args) + +/* Helper macro for optional template arguments */ +#define __sysctl_table_array_size(table, tmpl_args...) \ + ARRAY_SIZE(__sysctl_table_tmpl_or_default(table, ## tmpl_args)) + #ifdef CONFIG_SYSCTL int net_sysctl_init(void); -struct ctl_table_header *register_net_sysctl_sz(struct net *net, const char *path, - const struct ctl_table *table, - size_t table_size); +struct ctl_table_header *__register_net_sysctl_sz(struct net *net, + const char *path, + const struct ctl_table *table, + size_t table_size); void unregister_net_sysctl_table(struct ctl_table_header *header); #else static inline int net_sysctl_init(void) { return 0; } diff --git a/net/sysctl_net.c b/net/sysctl_net.c index e190a639eef2f6929c4aed85ad625aaf8a6ebd6a..e003210e0917760b707dae1e738c50d7c3969deb 100644 --- a/net/sysctl_net.c +++ b/net/sysctl_net.c @@ -160,10 +160,10 @@ static int ensure_safe_net_sysctl(struct net *net, const char *path, return 0; } -struct ctl_table_header *register_net_sysctl_sz(struct net *net, - const char *path, - const struct ctl_table *table, - size_t table_size) +struct ctl_table_header *__register_net_sysctl_sz(struct net *net, + const char *path, + const struct ctl_table *table, + size_t table_size) { if (!net_eq(net, &init_net)) if (ensure_safe_net_sysctl(net, path, table, table_size)) @@ -171,7 +171,7 @@ struct ctl_table_header *register_net_sysctl_sz(struct net *net, return __register_sysctl_table(&net->sysctls, path, table, table_size); } -EXPORT_SYMBOL_GPL(register_net_sysctl_sz); +EXPORT_SYMBOL_GPL(__register_net_sysctl_sz); void unregister_net_sysctl_table(struct ctl_table_header *header) { -- 2.47.3

