[NETFILTER]: Clean up table initialization
[deliverable/linux.git] / net / ipv4 / netfilter / iptable_raw.c
1 /*
2 * 'raw' table, which is the very first hooked in at PRE_ROUTING and LOCAL_OUT .
3 *
4 * Copyright (C) 2003 Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
5 */
6 #include <linux/module.h>
7 #include <linux/netfilter_ipv4/ip_tables.h>
8
9 #define RAW_VALID_HOOKS ((1 << NF_IP_PRE_ROUTING) | (1 << NF_IP_LOCAL_OUT))
10
11 static struct
12 {
13 struct ipt_replace repl;
14 struct ipt_standard entries[2];
15 struct ipt_error term;
16 } initial_table __initdata = {
17 .repl = {
18 .name = "raw",
19 .valid_hooks = RAW_VALID_HOOKS,
20 .num_entries = 3,
21 .size = sizeof(struct ipt_standard) * 2 + sizeof(struct ipt_error),
22 .hook_entry = {
23 [NF_IP_PRE_ROUTING] = 0,
24 [NF_IP_LOCAL_OUT] = sizeof(struct ipt_standard)
25 },
26 .underflow = {
27 [NF_IP_PRE_ROUTING] = 0,
28 [NF_IP_LOCAL_OUT] = sizeof(struct ipt_standard)
29 },
30 },
31 .entries = {
32 IPT_STANDARD_INIT(NF_ACCEPT), /* PRE_ROUTING */
33 IPT_STANDARD_INIT(NF_ACCEPT), /* LOCAL_OUT */
34 },
35 .term = IPT_ERROR_INIT, /* ERROR */
36 };
37
38 static struct xt_table packet_raw = {
39 .name = "raw",
40 .valid_hooks = RAW_VALID_HOOKS,
41 .lock = RW_LOCK_UNLOCKED,
42 .me = THIS_MODULE,
43 .af = AF_INET,
44 };
45
46 /* The work comes in here from netfilter.c. */
47 static unsigned int
48 ipt_hook(unsigned int hook,
49 struct sk_buff **pskb,
50 const struct net_device *in,
51 const struct net_device *out,
52 int (*okfn)(struct sk_buff *))
53 {
54 return ipt_do_table(pskb, hook, in, out, &packet_raw);
55 }
56
57 /* 'raw' is the very first table. */
58 static struct nf_hook_ops ipt_ops[] = {
59 {
60 .hook = ipt_hook,
61 .pf = PF_INET,
62 .hooknum = NF_IP_PRE_ROUTING,
63 .priority = NF_IP_PRI_RAW,
64 .owner = THIS_MODULE,
65 },
66 {
67 .hook = ipt_hook,
68 .pf = PF_INET,
69 .hooknum = NF_IP_LOCAL_OUT,
70 .priority = NF_IP_PRI_RAW,
71 .owner = THIS_MODULE,
72 },
73 };
74
75 static int __init iptable_raw_init(void)
76 {
77 int ret;
78
79 /* Register table */
80 ret = ipt_register_table(&packet_raw, &initial_table.repl);
81 if (ret < 0)
82 return ret;
83
84 /* Register hooks */
85 ret = nf_register_hooks(ipt_ops, ARRAY_SIZE(ipt_ops));
86 if (ret < 0)
87 goto cleanup_table;
88
89 return ret;
90
91 cleanup_table:
92 ipt_unregister_table(&packet_raw);
93 return ret;
94 }
95
96 static void __exit iptable_raw_fini(void)
97 {
98 nf_unregister_hooks(ipt_ops, ARRAY_SIZE(ipt_ops));
99 ipt_unregister_table(&packet_raw);
100 }
101
102 module_init(iptable_raw_init);
103 module_exit(iptable_raw_fini);
104 MODULE_LICENSE("GPL");
This page took 0.033837 seconds and 6 git commands to generate.