Linux-2.6.12-rc2
[GitHub/mt8127/android_kernel_alcatel_ttab.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 .underflow = {
26 [NF_IP_PRE_ROUTING] = 0,
27 [NF_IP_LOCAL_OUT] = sizeof(struct ipt_standard) },
28 },
29 .entries = {
30 /* PRE_ROUTING */
31 {
32 .entry = {
33 .target_offset = sizeof(struct ipt_entry),
34 .next_offset = sizeof(struct ipt_standard),
35 },
36 .target = {
37 .target = {
38 .u = {
39 .target_size = IPT_ALIGN(sizeof(struct ipt_standard_target)),
40 },
41 },
42 .verdict = -NF_ACCEPT - 1,
43 },
44 },
45
46 /* LOCAL_OUT */
47 {
48 .entry = {
49 .target_offset = sizeof(struct ipt_entry),
50 .next_offset = sizeof(struct ipt_standard),
51 },
52 .target = {
53 .target = {
54 .u = {
55 .target_size = IPT_ALIGN(sizeof(struct ipt_standard_target)),
56 },
57 },
58 .verdict = -NF_ACCEPT - 1,
59 },
60 },
61 },
62 /* ERROR */
63 .term = {
64 .entry = {
65 .target_offset = sizeof(struct ipt_entry),
66 .next_offset = sizeof(struct ipt_error),
67 },
68 .target = {
69 .target = {
70 .u = {
71 .user = {
72 .target_size = IPT_ALIGN(sizeof(struct ipt_error_target)),
73 .name = IPT_ERROR_TARGET,
74 },
75 },
76 },
77 .errorname = "ERROR",
78 },
79 }
80 };
81
82 static struct ipt_table packet_raw = {
83 .name = "raw",
84 .valid_hooks = RAW_VALID_HOOKS,
85 .lock = RW_LOCK_UNLOCKED,
86 .me = THIS_MODULE
87 };
88
89 /* The work comes in here from netfilter.c. */
90 static unsigned int
91 ipt_hook(unsigned int hook,
92 struct sk_buff **pskb,
93 const struct net_device *in,
94 const struct net_device *out,
95 int (*okfn)(struct sk_buff *))
96 {
97 return ipt_do_table(pskb, hook, in, out, &packet_raw, NULL);
98 }
99
100 /* 'raw' is the very first table. */
101 static struct nf_hook_ops ipt_ops[] = {
102 {
103 .hook = ipt_hook,
104 .pf = PF_INET,
105 .hooknum = NF_IP_PRE_ROUTING,
106 .priority = NF_IP_PRI_RAW
107 },
108 {
109 .hook = ipt_hook,
110 .pf = PF_INET,
111 .hooknum = NF_IP_LOCAL_OUT,
112 .priority = NF_IP_PRI_RAW
113 },
114 };
115
116 static int __init init(void)
117 {
118 int ret;
119
120 /* Register table */
121 ret = ipt_register_table(&packet_raw, &initial_table.repl);
122 if (ret < 0)
123 return ret;
124
125 /* Register hooks */
126 ret = nf_register_hook(&ipt_ops[0]);
127 if (ret < 0)
128 goto cleanup_table;
129
130 ret = nf_register_hook(&ipt_ops[1]);
131 if (ret < 0)
132 goto cleanup_hook0;
133
134 return ret;
135
136 cleanup_hook0:
137 nf_unregister_hook(&ipt_ops[0]);
138 cleanup_table:
139 ipt_unregister_table(&packet_raw);
140
141 return ret;
142 }
143
144 static void __exit fini(void)
145 {
146 unsigned int i;
147
148 for (i = 0; i < sizeof(ipt_ops)/sizeof(struct nf_hook_ops); i++)
149 nf_unregister_hook(&ipt_ops[i]);
150
151 ipt_unregister_table(&packet_raw);
152 }
153
154 module_init(init);
155 module_exit(fini);
156 MODULE_LICENSE("GPL");