aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexey Dobriyan <adobriyan@sw.ru>2008-03-20 10:15:43 -0400
committerPatrick McHardy <kaber@trash.net>2008-04-14 03:56:01 -0400
commitb916f7d4b7b4b427ad9a9486de3da41a16b24d67 (patch)
tree165543933f74602f21582580d595927d1a36fbb7
parentf5572855ec492334d8c3ec0e0e86c31865d5cf07 (diff)
[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>
-rw-r--r--net/netfilter/nf_conntrack_standalone.c116
1 files changed, 76 insertions, 40 deletions
diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
index 9d0b8bb4113c..01d1f7e178f3 100644
--- a/net/netfilter/nf_conntrack_standalone.c
+++ b/net/netfilter/nf_conntrack_standalone.c
@@ -295,6 +295,41 @@ static const struct file_operations ct_cpu_seq_fops = {
295 .llseek = seq_lseek, 295 .llseek = seq_lseek,
296 .release = seq_release, 296 .release = seq_release,
297}; 297};
298
299static int nf_conntrack_standalone_init_proc(void)
300{
301 struct proc_dir_entry *pde;
302
303 pde = proc_net_fops_create(&init_net, "nf_conntrack", 0440, &ct_file_ops);
304 if (!pde)
305 goto out_nf_conntrack;
306 pde = create_proc_entry("nf_conntrack", S_IRUGO, init_net.proc_net_stat);
307 if (!pde)
308 goto out_stat_nf_conntrack;
309 pde->proc_fops = &ct_cpu_seq_fops;
310 pde->owner = THIS_MODULE;
311 return 0;
312
313out_stat_nf_conntrack:
314 proc_net_remove(&init_net, "nf_conntrack");
315out_nf_conntrack:
316 return -ENOMEM;
317}
318
319static void nf_conntrack_standalone_fini_proc(void)
320{
321 remove_proc_entry("nf_conntrack", init_net.proc_net_stat);
322 proc_net_remove(&init_net, "nf_conntrack");
323}
324#else
325static int nf_conntrack_standalone_init_proc(void)
326{
327 return 0;
328}
329
330static void nf_conntrack_standalone_fini_proc(void)
331{
332}
298#endif /* CONFIG_PROC_FS */ 333#endif /* CONFIG_PROC_FS */
299 334
300/* Sysctl support */ 335/* Sysctl support */
@@ -390,60 +425,61 @@ static struct ctl_path nf_ct_path[] = {
390}; 425};
391 426
392EXPORT_SYMBOL_GPL(nf_ct_log_invalid); 427EXPORT_SYMBOL_GPL(nf_ct_log_invalid);
428
429static int nf_conntrack_standalone_init_sysctl(void)
430{
431 nf_ct_sysctl_header =
432 register_sysctl_paths(nf_ct_path, nf_ct_netfilter_table);
433 if (nf_ct_sysctl_header == NULL) {
434 printk("nf_conntrack: can't register to sysctl.\n");
435 return -ENOMEM;
436 }
437 return 0;
438
439}
440
441static void nf_conntrack_standalone_fini_sysctl(void)
442{
443 unregister_sysctl_table(nf_ct_sysctl_header);
444}
445#else
446static int nf_conntrack_standalone_init_sysctl(void)
447{
448 return 0;
449}
450
451static void nf_conntrack_standalone_fini_sysctl(void)
452{
453}
393#endif /* CONFIG_SYSCTL */ 454#endif /* CONFIG_SYSCTL */
394 455
395static int __init nf_conntrack_standalone_init(void) 456static int __init nf_conntrack_standalone_init(void)
396{ 457{
397#ifdef CONFIG_PROC_FS 458 int ret;
398 struct proc_dir_entry *proc;
399#endif
400 int ret = 0;
401 459
402 ret = nf_conntrack_init(); 460 ret = nf_conntrack_init();
403 if (ret < 0) 461 if (ret < 0)
404 return ret; 462 goto out;
405 463 ret = nf_conntrack_standalone_init_proc();
406#ifdef CONFIG_PROC_FS 464 if (ret < 0)
407 proc = proc_net_fops_create(&init_net, "nf_conntrack", 0440, &ct_file_ops); 465 goto out_proc;
408 if (!proc) goto cleanup_init; 466 ret = nf_conntrack_standalone_init_sysctl();
409 467 if (ret < 0)
410 if (!proc_create("nf_conntrack", S_IRUGO, 468 goto out_sysctl;
411 init_net.proc_net_stat, &ct_cpu_seq_fops)) 469 return 0;
412 goto cleanup_proc;
413#endif
414#ifdef CONFIG_SYSCTL
415 nf_ct_sysctl_header = register_sysctl_paths(nf_ct_path,
416 nf_ct_netfilter_table);
417 if (nf_ct_sysctl_header == NULL) {
418 printk("nf_conntrack: can't register to sysctl.\n");
419 ret = -ENOMEM;
420 goto cleanup_proc_stat;
421 }
422#endif
423 return ret;
424 470
425#ifdef CONFIG_SYSCTL 471out_sysctl:
426 cleanup_proc_stat: 472 nf_conntrack_standalone_fini_proc();
427#endif 473out_proc:
428#ifdef CONFIG_PROC_FS
429 remove_proc_entry("nf_conntrack", init_net. proc_net_stat);
430 cleanup_proc:
431 proc_net_remove(&init_net, "nf_conntrack");
432 cleanup_init:
433#endif /* CNFIG_PROC_FS */
434 nf_conntrack_cleanup(); 474 nf_conntrack_cleanup();
475out:
435 return ret; 476 return ret;
436} 477}
437 478
438static void __exit nf_conntrack_standalone_fini(void) 479static void __exit nf_conntrack_standalone_fini(void)
439{ 480{
440#ifdef CONFIG_SYSCTL 481 nf_conntrack_standalone_fini_sysctl();
441 unregister_sysctl_table(nf_ct_sysctl_header); 482 nf_conntrack_standalone_fini_proc();
442#endif
443#ifdef CONFIG_PROC_FS
444 remove_proc_entry("nf_conntrack", init_net.proc_net_stat);
445 proc_net_remove(&init_net, "nf_conntrack");
446#endif /* CNFIG_PROC_FS */
447 nf_conntrack_cleanup(); 483 nf_conntrack_cleanup();
448} 484}
449 485