]>
Commit | Line | Data |
---|---|---|
e905a9ed | 1 | /* |
1da177e4 LT |
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 = { | |
e905a9ed YH |
18 | .name = "raw", |
19 | .valid_hooks = RAW_VALID_HOOKS, | |
1da177e4 LT |
20 | .num_entries = 3, |
21 | .size = sizeof(struct ipt_standard) * 2 + sizeof(struct ipt_error), | |
e905a9ed | 22 | .hook_entry = { |
1da177e4 LT |
23 | [NF_IP_PRE_ROUTING] = 0, |
24 | [NF_IP_LOCAL_OUT] = sizeof(struct ipt_standard) }, | |
e905a9ed | 25 | .underflow = { |
1da177e4 LT |
26 | [NF_IP_PRE_ROUTING] = 0, |
27 | [NF_IP_LOCAL_OUT] = sizeof(struct ipt_standard) }, | |
28 | }, | |
29 | .entries = { | |
30 | /* PRE_ROUTING */ | |
e905a9ed YH |
31 | { |
32 | .entry = { | |
1da177e4 LT |
33 | .target_offset = sizeof(struct ipt_entry), |
34 | .next_offset = sizeof(struct ipt_standard), | |
35 | }, | |
e905a9ed YH |
36 | .target = { |
37 | .target = { | |
1da177e4 LT |
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 = { | |
e905a9ed | 72 | .target_size = IPT_ALIGN(sizeof(struct ipt_error_target)), |
1da177e4 LT |
73 | .name = IPT_ERROR_TARGET, |
74 | }, | |
75 | }, | |
76 | }, | |
77 | .errorname = "ERROR", | |
78 | }, | |
79 | } | |
80 | }; | |
81 | ||
e60a13e0 | 82 | static struct xt_table packet_raw = { |
e905a9ed YH |
83 | .name = "raw", |
84 | .valid_hooks = RAW_VALID_HOOKS, | |
85 | .lock = RW_LOCK_UNLOCKED, | |
2e4e6a17 HW |
86 | .me = THIS_MODULE, |
87 | .af = AF_INET, | |
1da177e4 LT |
88 | }; |
89 | ||
90 | /* The work comes in here from netfilter.c. */ | |
91 | static unsigned int | |
92 | ipt_hook(unsigned int hook, | |
93 | struct sk_buff **pskb, | |
94 | const struct net_device *in, | |
95 | const struct net_device *out, | |
96 | int (*okfn)(struct sk_buff *)) | |
97 | { | |
fe1cb108 | 98 | return ipt_do_table(pskb, hook, in, out, &packet_raw); |
1da177e4 LT |
99 | } |
100 | ||
101 | /* 'raw' is the very first table. */ | |
102 | static struct nf_hook_ops ipt_ops[] = { | |
103 | { | |
964ddaa1 PM |
104 | .hook = ipt_hook, |
105 | .pf = PF_INET, | |
106 | .hooknum = NF_IP_PRE_ROUTING, | |
107 | .priority = NF_IP_PRI_RAW, | |
108 | .owner = THIS_MODULE, | |
1da177e4 LT |
109 | }, |
110 | { | |
964ddaa1 PM |
111 | .hook = ipt_hook, |
112 | .pf = PF_INET, | |
113 | .hooknum = NF_IP_LOCAL_OUT, | |
114 | .priority = NF_IP_PRI_RAW, | |
115 | .owner = THIS_MODULE, | |
1da177e4 LT |
116 | }, |
117 | }; | |
118 | ||
65b4b4e8 | 119 | static int __init iptable_raw_init(void) |
1da177e4 LT |
120 | { |
121 | int ret; | |
122 | ||
123 | /* Register table */ | |
124 | ret = ipt_register_table(&packet_raw, &initial_table.repl); | |
125 | if (ret < 0) | |
126 | return ret; | |
127 | ||
128 | /* Register hooks */ | |
964ddaa1 | 129 | ret = nf_register_hooks(ipt_ops, ARRAY_SIZE(ipt_ops)); |
1da177e4 LT |
130 | if (ret < 0) |
131 | goto cleanup_table; | |
132 | ||
1da177e4 LT |
133 | return ret; |
134 | ||
1da177e4 LT |
135 | cleanup_table: |
136 | ipt_unregister_table(&packet_raw); | |
1da177e4 LT |
137 | return ret; |
138 | } | |
139 | ||
65b4b4e8 | 140 | static void __exit iptable_raw_fini(void) |
1da177e4 | 141 | { |
964ddaa1 | 142 | nf_unregister_hooks(ipt_ops, ARRAY_SIZE(ipt_ops)); |
1da177e4 LT |
143 | ipt_unregister_table(&packet_raw); |
144 | } | |
145 | ||
65b4b4e8 AM |
146 | module_init(iptable_raw_init); |
147 | module_exit(iptable_raw_fini); | |
1da177e4 | 148 | MODULE_LICENSE("GPL"); |