[NETFILTER]: nf_conntrack: less hairy ifdefs around proc and sysctl

Patch splits creation of /proc/net/nf_conntrack, /proc/net/stat/nf_conntrack
and net.netfilter hierarchy into their own functions with dummy ones
if PROC_FS or SYSCTL is not set. Also, remove dead "ret = 0" write
while I'm at it.

Signed-off-by: Alexey Dobriyan <adobriyan@sw.ru>
Signed-off-by: Patrick McHardy <kaber@trash.net>
This commit is contained in:
Alexey Dobriyan 2008-03-20 15:15:43 +01:00 коммит произвёл Patrick McHardy
Родитель f5572855ec
Коммит b916f7d4b7
1 изменённых файлов: 76 добавлений и 40 удалений

Просмотреть файл

@ -295,6 +295,41 @@ static const struct file_operations ct_cpu_seq_fops = {
.llseek = seq_lseek,
.release = seq_release,
};
static int nf_conntrack_standalone_init_proc(void)
{
struct proc_dir_entry *pde;
pde = proc_net_fops_create(&init_net, "nf_conntrack", 0440, &ct_file_ops);
if (!pde)
goto out_nf_conntrack;
pde = create_proc_entry("nf_conntrack", S_IRUGO, init_net.proc_net_stat);
if (!pde)
goto out_stat_nf_conntrack;
pde->proc_fops = &ct_cpu_seq_fops;
pde->owner = THIS_MODULE;
return 0;
out_stat_nf_conntrack:
proc_net_remove(&init_net, "nf_conntrack");
out_nf_conntrack:
return -ENOMEM;
}
static void nf_conntrack_standalone_fini_proc(void)
{
remove_proc_entry("nf_conntrack", init_net.proc_net_stat);
proc_net_remove(&init_net, "nf_conntrack");
}
#else
static int nf_conntrack_standalone_init_proc(void)
{
return 0;
}
static void nf_conntrack_standalone_fini_proc(void)
{
}
#endif /* CONFIG_PROC_FS */
/* Sysctl support */
@ -390,60 +425,61 @@ static struct ctl_path nf_ct_path[] = {
};
EXPORT_SYMBOL_GPL(nf_ct_log_invalid);
static int nf_conntrack_standalone_init_sysctl(void)
{
nf_ct_sysctl_header =
register_sysctl_paths(nf_ct_path, nf_ct_netfilter_table);
if (nf_ct_sysctl_header == NULL) {
printk("nf_conntrack: can't register to sysctl.\n");
return -ENOMEM;
}
return 0;
}
static void nf_conntrack_standalone_fini_sysctl(void)
{
unregister_sysctl_table(nf_ct_sysctl_header);
}
#else
static int nf_conntrack_standalone_init_sysctl(void)
{
return 0;
}
static void nf_conntrack_standalone_fini_sysctl(void)
{
}
#endif /* CONFIG_SYSCTL */
static int __init nf_conntrack_standalone_init(void)
{
#ifdef CONFIG_PROC_FS
struct proc_dir_entry *proc;
#endif
int ret = 0;
int ret;
ret = nf_conntrack_init();
if (ret < 0)
return ret;
goto out;
ret = nf_conntrack_standalone_init_proc();
if (ret < 0)
goto out_proc;
ret = nf_conntrack_standalone_init_sysctl();
if (ret < 0)
goto out_sysctl;
return 0;
#ifdef CONFIG_PROC_FS
proc = proc_net_fops_create(&init_net, "nf_conntrack", 0440, &ct_file_ops);
if (!proc) goto cleanup_init;
if (!proc_create("nf_conntrack", S_IRUGO,
init_net.proc_net_stat, &ct_cpu_seq_fops))
goto cleanup_proc;
#endif
#ifdef CONFIG_SYSCTL
nf_ct_sysctl_header = register_sysctl_paths(nf_ct_path,
nf_ct_netfilter_table);
if (nf_ct_sysctl_header == NULL) {
printk("nf_conntrack: can't register to sysctl.\n");
ret = -ENOMEM;
goto cleanup_proc_stat;
}
#endif
return ret;
#ifdef CONFIG_SYSCTL
cleanup_proc_stat:
#endif
#ifdef CONFIG_PROC_FS
remove_proc_entry("nf_conntrack", init_net. proc_net_stat);
cleanup_proc:
proc_net_remove(&init_net, "nf_conntrack");
cleanup_init:
#endif /* CNFIG_PROC_FS */
out_sysctl:
nf_conntrack_standalone_fini_proc();
out_proc:
nf_conntrack_cleanup();
out:
return ret;
}
static void __exit nf_conntrack_standalone_fini(void)
{
#ifdef CONFIG_SYSCTL
unregister_sysctl_table(nf_ct_sysctl_header);
#endif
#ifdef CONFIG_PROC_FS
remove_proc_entry("nf_conntrack", init_net.proc_net_stat);
proc_net_remove(&init_net, "nf_conntrack");
#endif /* CNFIG_PROC_FS */
nf_conntrack_standalone_fini_sysctl();
nf_conntrack_standalone_fini_proc();
nf_conntrack_cleanup();
}