]>
Commit | Line | Data |
---|---|---|
9fb9cbb1 YK |
1 | /* (C) 1999-2001 Paul `Rusty' Russell |
2 | * (C) 2002-2004 Netfilter Core Team <coreteam@netfilter.org> | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License version 2 as | |
6 | * published by the Free Software Foundation. | |
9fb9cbb1 YK |
7 | */ |
8 | ||
9fb9cbb1 YK |
9 | #include <linux/types.h> |
10 | #include <linux/ip.h> | |
11 | #include <linux/netfilter.h> | |
12 | #include <linux/module.h> | |
13 | #include <linux/skbuff.h> | |
14 | #include <linux/icmp.h> | |
15 | #include <linux/sysctl.h> | |
0ae2cfe7 | 16 | #include <net/route.h> |
9fb9cbb1 YK |
17 | #include <net/ip.h> |
18 | ||
19 | #include <linux/netfilter_ipv4.h> | |
20 | #include <net/netfilter/nf_conntrack.h> | |
21 | #include <net/netfilter/nf_conntrack_helper.h> | |
605dcad6 | 22 | #include <net/netfilter/nf_conntrack_l4proto.h> |
9fb9cbb1 YK |
23 | #include <net/netfilter/nf_conntrack_l3proto.h> |
24 | #include <net/netfilter/nf_conntrack_core.h> | |
25 | #include <net/netfilter/ipv4/nf_conntrack_ipv4.h> | |
dd13b010 PM |
26 | #include <net/netfilter/nf_nat_helper.h> |
27 | ||
28 | int (*nf_nat_seq_adjust_hook)(struct sk_buff *skb, | |
29 | struct nf_conn *ct, | |
30 | enum ip_conntrack_info ctinfo); | |
31 | EXPORT_SYMBOL_GPL(nf_nat_seq_adjust_hook); | |
9fb9cbb1 | 32 | |
8ce8439a JE |
33 | static bool ipv4_pkt_to_tuple(const struct sk_buff *skb, unsigned int nhoff, |
34 | struct nf_conntrack_tuple *tuple) | |
9fb9cbb1 | 35 | { |
32948588 JE |
36 | const __be32 *ap; |
37 | __be32 _addrs[2]; | |
9fb9cbb1 YK |
38 | ap = skb_header_pointer(skb, nhoff + offsetof(struct iphdr, saddr), |
39 | sizeof(u_int32_t) * 2, _addrs); | |
40 | if (ap == NULL) | |
8ce8439a | 41 | return false; |
9fb9cbb1 YK |
42 | |
43 | tuple->src.u3.ip = ap[0]; | |
44 | tuple->dst.u3.ip = ap[1]; | |
45 | ||
8ce8439a | 46 | return true; |
9fb9cbb1 YK |
47 | } |
48 | ||
8ce8439a JE |
49 | static bool ipv4_invert_tuple(struct nf_conntrack_tuple *tuple, |
50 | const struct nf_conntrack_tuple *orig) | |
9fb9cbb1 YK |
51 | { |
52 | tuple->src.u3.ip = orig->dst.u3.ip; | |
53 | tuple->dst.u3.ip = orig->src.u3.ip; | |
54 | ||
8ce8439a | 55 | return true; |
9fb9cbb1 YK |
56 | } |
57 | ||
58 | static int ipv4_print_tuple(struct seq_file *s, | |
59 | const struct nf_conntrack_tuple *tuple) | |
60 | { | |
61 | return seq_printf(s, "src=%u.%u.%u.%u dst=%u.%u.%u.%u ", | |
e905a9ed | 62 | NIPQUAD(tuple->src.u3.ip), |
9fb9cbb1 YK |
63 | NIPQUAD(tuple->dst.u3.ip)); |
64 | } | |
65 | ||
9fb9cbb1 | 66 | /* Returns new sk_buff, or NULL */ |
776c729e | 67 | static int nf_ct_ipv4_gather_frags(struct sk_buff *skb, u_int32_t user) |
9fb9cbb1 | 68 | { |
776c729e HX |
69 | int err; |
70 | ||
9fb9cbb1 YK |
71 | skb_orphan(skb); |
72 | ||
e905a9ed | 73 | local_bh_disable(); |
776c729e | 74 | err = ip_defrag(skb, user); |
e905a9ed | 75 | local_bh_enable(); |
9fb9cbb1 | 76 | |
776c729e | 77 | if (!err) |
eddc9ec5 | 78 | ip_send_check(ip_hdr(skb)); |
9fb9cbb1 | 79 | |
776c729e | 80 | return err; |
9fb9cbb1 YK |
81 | } |
82 | ||
ffc30690 YK |
83 | static int ipv4_get_l4proto(const struct sk_buff *skb, unsigned int nhoff, |
84 | unsigned int *dataoff, u_int8_t *protonum) | |
9fb9cbb1 | 85 | { |
32948588 JE |
86 | const struct iphdr *iph; |
87 | struct iphdr _iph; | |
ffc30690 YK |
88 | |
89 | iph = skb_header_pointer(skb, nhoff, sizeof(_iph), &_iph); | |
90 | if (iph == NULL) | |
91 | return -NF_DROP; | |
92 | ||
0fb96701 PM |
93 | /* Conntrack defragments packets, we might still see fragments |
94 | * inside ICMP packets though. */ | |
95 | if (iph->frag_off & htons(IP_OFFSET)) | |
9fb9cbb1 | 96 | return -NF_DROP; |
9fb9cbb1 | 97 | |
ffc30690 YK |
98 | *dataoff = nhoff + (iph->ihl << 2); |
99 | *protonum = iph->protocol; | |
9fb9cbb1 YK |
100 | |
101 | return NF_ACCEPT; | |
102 | } | |
103 | ||
9fb9cbb1 | 104 | static unsigned int ipv4_confirm(unsigned int hooknum, |
3db05fea | 105 | struct sk_buff *skb, |
9fb9cbb1 YK |
106 | const struct net_device *in, |
107 | const struct net_device *out, | |
108 | int (*okfn)(struct sk_buff *)) | |
9fb9cbb1 YK |
109 | { |
110 | struct nf_conn *ct; | |
111 | enum ip_conntrack_info ctinfo; | |
32948588 JE |
112 | const struct nf_conn_help *help; |
113 | const struct nf_conntrack_helper *helper; | |
dd13b010 | 114 | unsigned int ret; |
9fb9cbb1 YK |
115 | |
116 | /* This is where we call the helper: as the packet goes out. */ | |
3db05fea | 117 | ct = nf_ct_get(skb, &ctinfo); |
6442f1cf | 118 | if (!ct || ctinfo == IP_CT_RELATED + IP_CT_IS_REPLY) |
dd13b010 | 119 | goto out; |
dc808fe2 HW |
120 | |
121 | help = nfct_help(ct); | |
3c158f7f | 122 | if (!help) |
dd13b010 PM |
123 | goto out; |
124 | ||
3c158f7f PM |
125 | /* rcu_read_lock()ed by nf_hook_slow */ |
126 | helper = rcu_dereference(help->helper); | |
127 | if (!helper) | |
dd13b010 PM |
128 | goto out; |
129 | ||
130 | ret = helper->help(skb, skb_network_offset(skb) + ip_hdrlen(skb), | |
131 | ct, ctinfo); | |
132 | if (ret != NF_ACCEPT) | |
133 | return ret; | |
134 | ||
135 | if (test_bit(IPS_SEQ_ADJUST_BIT, &ct->status)) { | |
136 | typeof(nf_nat_seq_adjust_hook) seq_adjust; | |
137 | ||
138 | seq_adjust = rcu_dereference(nf_nat_seq_adjust_hook); | |
139 | if (!seq_adjust || !seq_adjust(skb, ct, ctinfo)) | |
140 | return NF_DROP; | |
141 | } | |
142 | out: | |
143 | /* We've seen it coming out the other side: confirm it */ | |
144 | return nf_conntrack_confirm(skb); | |
9fb9cbb1 YK |
145 | } |
146 | ||
147 | static unsigned int ipv4_conntrack_defrag(unsigned int hooknum, | |
3db05fea | 148 | struct sk_buff *skb, |
9fb9cbb1 YK |
149 | const struct net_device *in, |
150 | const struct net_device *out, | |
151 | int (*okfn)(struct sk_buff *)) | |
152 | { | |
9fb9cbb1 YK |
153 | /* Previously seen (loopback)? Ignore. Do this before |
154 | fragment check. */ | |
3db05fea | 155 | if (skb->nfct) |
9fb9cbb1 | 156 | return NF_ACCEPT; |
9fb9cbb1 YK |
157 | |
158 | /* Gather fragments. */ | |
3db05fea HX |
159 | if (ip_hdr(skb)->frag_off & htons(IP_MF | IP_OFFSET)) { |
160 | if (nf_ct_ipv4_gather_frags(skb, | |
6e23ae2a | 161 | hooknum == NF_INET_PRE_ROUTING ? |
776c729e HX |
162 | IP_DEFRAG_CONNTRACK_IN : |
163 | IP_DEFRAG_CONNTRACK_OUT)) | |
9fb9cbb1 YK |
164 | return NF_STOLEN; |
165 | } | |
166 | return NF_ACCEPT; | |
167 | } | |
168 | ||
9fb9cbb1 | 169 | static unsigned int ipv4_conntrack_in(unsigned int hooknum, |
3db05fea | 170 | struct sk_buff *skb, |
9fb9cbb1 YK |
171 | const struct net_device *in, |
172 | const struct net_device *out, | |
173 | int (*okfn)(struct sk_buff *)) | |
174 | { | |
a702a65f | 175 | return nf_conntrack_in(dev_net(in), PF_INET, hooknum, skb); |
9fb9cbb1 YK |
176 | } |
177 | ||
178 | static unsigned int ipv4_conntrack_local(unsigned int hooknum, | |
3db05fea | 179 | struct sk_buff *skb, |
e905a9ed YH |
180 | const struct net_device *in, |
181 | const struct net_device *out, | |
182 | int (*okfn)(struct sk_buff *)) | |
9fb9cbb1 YK |
183 | { |
184 | /* root is playing with raw sockets. */ | |
3db05fea HX |
185 | if (skb->len < sizeof(struct iphdr) || |
186 | ip_hdrlen(skb) < sizeof(struct iphdr)) { | |
9fb9cbb1 YK |
187 | if (net_ratelimit()) |
188 | printk("ipt_hook: happy cracking.\n"); | |
189 | return NF_ACCEPT; | |
190 | } | |
a702a65f | 191 | return nf_conntrack_in(dev_net(out), PF_INET, hooknum, skb); |
9fb9cbb1 YK |
192 | } |
193 | ||
194 | /* Connection tracking may drop packets, but never alters them, so | |
195 | make it the first hook. */ | |
1999414a | 196 | static struct nf_hook_ops ipv4_conntrack_ops[] __read_mostly = { |
964ddaa1 PM |
197 | { |
198 | .hook = ipv4_conntrack_defrag, | |
199 | .owner = THIS_MODULE, | |
200 | .pf = PF_INET, | |
6e23ae2a | 201 | .hooknum = NF_INET_PRE_ROUTING, |
964ddaa1 PM |
202 | .priority = NF_IP_PRI_CONNTRACK_DEFRAG, |
203 | }, | |
204 | { | |
205 | .hook = ipv4_conntrack_in, | |
206 | .owner = THIS_MODULE, | |
207 | .pf = PF_INET, | |
6e23ae2a | 208 | .hooknum = NF_INET_PRE_ROUTING, |
964ddaa1 PM |
209 | .priority = NF_IP_PRI_CONNTRACK, |
210 | }, | |
211 | { | |
212 | .hook = ipv4_conntrack_defrag, | |
213 | .owner = THIS_MODULE, | |
214 | .pf = PF_INET, | |
6e23ae2a | 215 | .hooknum = NF_INET_LOCAL_OUT, |
964ddaa1 PM |
216 | .priority = NF_IP_PRI_CONNTRACK_DEFRAG, |
217 | }, | |
218 | { | |
219 | .hook = ipv4_conntrack_local, | |
220 | .owner = THIS_MODULE, | |
221 | .pf = PF_INET, | |
6e23ae2a | 222 | .hooknum = NF_INET_LOCAL_OUT, |
964ddaa1 PM |
223 | .priority = NF_IP_PRI_CONNTRACK, |
224 | }, | |
964ddaa1 PM |
225 | { |
226 | .hook = ipv4_confirm, | |
227 | .owner = THIS_MODULE, | |
228 | .pf = PF_INET, | |
6e23ae2a | 229 | .hooknum = NF_INET_POST_ROUTING, |
964ddaa1 PM |
230 | .priority = NF_IP_PRI_CONNTRACK_CONFIRM, |
231 | }, | |
232 | { | |
233 | .hook = ipv4_confirm, | |
234 | .owner = THIS_MODULE, | |
235 | .pf = PF_INET, | |
6e23ae2a | 236 | .hooknum = NF_INET_LOCAL_IN, |
964ddaa1 PM |
237 | .priority = NF_IP_PRI_CONNTRACK_CONFIRM, |
238 | }, | |
9fb9cbb1 YK |
239 | }; |
240 | ||
a999e683 PM |
241 | #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT) |
242 | static int log_invalid_proto_min = 0; | |
243 | static int log_invalid_proto_max = 255; | |
244 | ||
245 | static ctl_table ip_ct_sysctl_table[] = { | |
246 | { | |
247 | .ctl_name = NET_IPV4_NF_CONNTRACK_MAX, | |
248 | .procname = "ip_conntrack_max", | |
249 | .data = &nf_conntrack_max, | |
250 | .maxlen = sizeof(int), | |
251 | .mode = 0644, | |
252 | .proc_handler = &proc_dointvec, | |
253 | }, | |
254 | { | |
255 | .ctl_name = NET_IPV4_NF_CONNTRACK_COUNT, | |
256 | .procname = "ip_conntrack_count", | |
49ac8713 | 257 | .data = &init_net.ct.count, |
a999e683 PM |
258 | .maxlen = sizeof(int), |
259 | .mode = 0444, | |
260 | .proc_handler = &proc_dointvec, | |
261 | }, | |
262 | { | |
263 | .ctl_name = NET_IPV4_NF_CONNTRACK_BUCKETS, | |
264 | .procname = "ip_conntrack_buckets", | |
265 | .data = &nf_conntrack_htable_size, | |
266 | .maxlen = sizeof(unsigned int), | |
267 | .mode = 0444, | |
268 | .proc_handler = &proc_dointvec, | |
269 | }, | |
270 | { | |
271 | .ctl_name = NET_IPV4_NF_CONNTRACK_CHECKSUM, | |
272 | .procname = "ip_conntrack_checksum", | |
273 | .data = &nf_conntrack_checksum, | |
274 | .maxlen = sizeof(int), | |
275 | .mode = 0644, | |
276 | .proc_handler = &proc_dointvec, | |
277 | }, | |
278 | { | |
279 | .ctl_name = NET_IPV4_NF_CONNTRACK_LOG_INVALID, | |
280 | .procname = "ip_conntrack_log_invalid", | |
281 | .data = &nf_ct_log_invalid, | |
282 | .maxlen = sizeof(unsigned int), | |
283 | .mode = 0644, | |
284 | .proc_handler = &proc_dointvec_minmax, | |
285 | .strategy = &sysctl_intvec, | |
286 | .extra1 = &log_invalid_proto_min, | |
287 | .extra2 = &log_invalid_proto_max, | |
288 | }, | |
289 | { | |
290 | .ctl_name = 0 | |
291 | } | |
292 | }; | |
293 | #endif /* CONFIG_SYSCTL && CONFIG_NF_CONNTRACK_PROC_COMPAT */ | |
294 | ||
9fb9cbb1 YK |
295 | /* Fast function for those who don't want to parse /proc (and I don't |
296 | blame them). */ | |
297 | /* Reversing the socket's dst/src point of view gives us the reply | |
298 | mapping. */ | |
299 | static int | |
300 | getorigdst(struct sock *sk, int optval, void __user *user, int *len) | |
301 | { | |
32948588 JE |
302 | const struct inet_sock *inet = inet_sk(sk); |
303 | const struct nf_conntrack_tuple_hash *h; | |
9fb9cbb1 | 304 | struct nf_conntrack_tuple tuple; |
e905a9ed | 305 | |
443a70d5 | 306 | memset(&tuple, 0, sizeof(tuple)); |
9fb9cbb1 YK |
307 | tuple.src.u3.ip = inet->rcv_saddr; |
308 | tuple.src.u.tcp.port = inet->sport; | |
309 | tuple.dst.u3.ip = inet->daddr; | |
310 | tuple.dst.u.tcp.port = inet->dport; | |
311 | tuple.src.l3num = PF_INET; | |
312 | tuple.dst.protonum = IPPROTO_TCP; | |
313 | ||
314 | /* We only do TCP at the moment: is there a better way? */ | |
315 | if (strcmp(sk->sk_prot->name, "TCP")) { | |
0d53778e | 316 | pr_debug("SO_ORIGINAL_DST: Not a TCP socket\n"); |
9fb9cbb1 YK |
317 | return -ENOPROTOOPT; |
318 | } | |
319 | ||
320 | if ((unsigned int) *len < sizeof(struct sockaddr_in)) { | |
0d53778e PM |
321 | pr_debug("SO_ORIGINAL_DST: len %d not %Zu\n", |
322 | *len, sizeof(struct sockaddr_in)); | |
9fb9cbb1 YK |
323 | return -EINVAL; |
324 | } | |
325 | ||
400dad39 | 326 | h = nf_conntrack_find_get(sock_net(sk), &tuple); |
9fb9cbb1 YK |
327 | if (h) { |
328 | struct sockaddr_in sin; | |
329 | struct nf_conn *ct = nf_ct_tuplehash_to_ctrack(h); | |
330 | ||
331 | sin.sin_family = AF_INET; | |
332 | sin.sin_port = ct->tuplehash[IP_CT_DIR_ORIGINAL] | |
333 | .tuple.dst.u.tcp.port; | |
334 | sin.sin_addr.s_addr = ct->tuplehash[IP_CT_DIR_ORIGINAL] | |
335 | .tuple.dst.u3.ip; | |
6c813c3f | 336 | memset(sin.sin_zero, 0, sizeof(sin.sin_zero)); |
9fb9cbb1 | 337 | |
0d53778e PM |
338 | pr_debug("SO_ORIGINAL_DST: %u.%u.%u.%u %u\n", |
339 | NIPQUAD(sin.sin_addr.s_addr), ntohs(sin.sin_port)); | |
9fb9cbb1 YK |
340 | nf_ct_put(ct); |
341 | if (copy_to_user(user, &sin, sizeof(sin)) != 0) | |
342 | return -EFAULT; | |
343 | else | |
344 | return 0; | |
345 | } | |
0d53778e PM |
346 | pr_debug("SO_ORIGINAL_DST: Can't find %u.%u.%u.%u/%u-%u.%u.%u.%u/%u.\n", |
347 | NIPQUAD(tuple.src.u3.ip), ntohs(tuple.src.u.tcp.port), | |
348 | NIPQUAD(tuple.dst.u3.ip), ntohs(tuple.dst.u.tcp.port)); | |
9fb9cbb1 YK |
349 | return -ENOENT; |
350 | } | |
351 | ||
e281db5c | 352 | #if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE) |
c1d10adb PNA |
353 | |
354 | #include <linux/netfilter/nfnetlink.h> | |
355 | #include <linux/netfilter/nfnetlink_conntrack.h> | |
356 | ||
fdf70832 | 357 | static int ipv4_tuple_to_nlattr(struct sk_buff *skb, |
c1d10adb PNA |
358 | const struct nf_conntrack_tuple *tuple) |
359 | { | |
77236b6e PM |
360 | NLA_PUT_BE32(skb, CTA_IP_V4_SRC, tuple->src.u3.ip); |
361 | NLA_PUT_BE32(skb, CTA_IP_V4_DST, tuple->dst.u3.ip); | |
c1d10adb PNA |
362 | return 0; |
363 | ||
df6fb868 | 364 | nla_put_failure: |
c1d10adb PNA |
365 | return -1; |
366 | } | |
367 | ||
f73e924c PM |
368 | static const struct nla_policy ipv4_nla_policy[CTA_IP_MAX+1] = { |
369 | [CTA_IP_V4_SRC] = { .type = NLA_U32 }, | |
370 | [CTA_IP_V4_DST] = { .type = NLA_U32 }, | |
c1d10adb PNA |
371 | }; |
372 | ||
fdf70832 | 373 | static int ipv4_nlattr_to_tuple(struct nlattr *tb[], |
c1d10adb PNA |
374 | struct nf_conntrack_tuple *t) |
375 | { | |
df6fb868 | 376 | if (!tb[CTA_IP_V4_SRC] || !tb[CTA_IP_V4_DST]) |
c1d10adb PNA |
377 | return -EINVAL; |
378 | ||
77236b6e PM |
379 | t->src.u3.ip = nla_get_be32(tb[CTA_IP_V4_SRC]); |
380 | t->dst.u3.ip = nla_get_be32(tb[CTA_IP_V4_DST]); | |
c1d10adb PNA |
381 | |
382 | return 0; | |
383 | } | |
384 | #endif | |
385 | ||
9fb9cbb1 YK |
386 | static struct nf_sockopt_ops so_getorigdst = { |
387 | .pf = PF_INET, | |
388 | .get_optmin = SO_ORIGINAL_DST, | |
389 | .get_optmax = SO_ORIGINAL_DST+1, | |
390 | .get = &getorigdst, | |
16fcec35 | 391 | .owner = THIS_MODULE, |
9fb9cbb1 YK |
392 | }; |
393 | ||
61075af5 | 394 | struct nf_conntrack_l3proto nf_conntrack_l3proto_ipv4 __read_mostly = { |
9fb9cbb1 YK |
395 | .l3proto = PF_INET, |
396 | .name = "ipv4", | |
397 | .pkt_to_tuple = ipv4_pkt_to_tuple, | |
398 | .invert_tuple = ipv4_invert_tuple, | |
399 | .print_tuple = ipv4_print_tuple, | |
ffc30690 | 400 | .get_l4proto = ipv4_get_l4proto, |
e281db5c | 401 | #if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE) |
fdf70832 PM |
402 | .tuple_to_nlattr = ipv4_tuple_to_nlattr, |
403 | .nlattr_to_tuple = ipv4_nlattr_to_tuple, | |
f73e924c | 404 | .nla_policy = ipv4_nla_policy, |
a999e683 PM |
405 | #endif |
406 | #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT) | |
407 | .ctl_table_path = nf_net_ipv4_netfilter_sysctl_path, | |
408 | .ctl_table = ip_ct_sysctl_table, | |
c1d10adb | 409 | #endif |
9fb9cbb1 YK |
410 | .me = THIS_MODULE, |
411 | }; | |
412 | ||
fae718dd PM |
413 | module_param_call(hashsize, nf_conntrack_set_hashsize, param_get_uint, |
414 | &nf_conntrack_htable_size, 0600); | |
415 | ||
32292a7f | 416 | MODULE_ALIAS("nf_conntrack-" __stringify(AF_INET)); |
d2483dde | 417 | MODULE_ALIAS("ip_conntrack"); |
32292a7f PM |
418 | MODULE_LICENSE("GPL"); |
419 | ||
420 | static int __init nf_conntrack_l3proto_ipv4_init(void) | |
9fb9cbb1 YK |
421 | { |
422 | int ret = 0; | |
423 | ||
32292a7f | 424 | need_conntrack(); |
9fb9cbb1 YK |
425 | |
426 | ret = nf_register_sockopt(&so_getorigdst); | |
427 | if (ret < 0) { | |
428 | printk(KERN_ERR "Unable to register netfilter socket option\n"); | |
32292a7f | 429 | return ret; |
9fb9cbb1 YK |
430 | } |
431 | ||
605dcad6 | 432 | ret = nf_conntrack_l4proto_register(&nf_conntrack_l4proto_tcp4); |
9fb9cbb1 YK |
433 | if (ret < 0) { |
434 | printk("nf_conntrack_ipv4: can't register tcp.\n"); | |
435 | goto cleanup_sockopt; | |
436 | } | |
437 | ||
605dcad6 | 438 | ret = nf_conntrack_l4proto_register(&nf_conntrack_l4proto_udp4); |
9fb9cbb1 YK |
439 | if (ret < 0) { |
440 | printk("nf_conntrack_ipv4: can't register udp.\n"); | |
441 | goto cleanup_tcp; | |
442 | } | |
443 | ||
605dcad6 | 444 | ret = nf_conntrack_l4proto_register(&nf_conntrack_l4proto_icmp); |
9fb9cbb1 YK |
445 | if (ret < 0) { |
446 | printk("nf_conntrack_ipv4: can't register icmp.\n"); | |
447 | goto cleanup_udp; | |
448 | } | |
449 | ||
450 | ret = nf_conntrack_l3proto_register(&nf_conntrack_l3proto_ipv4); | |
451 | if (ret < 0) { | |
452 | printk("nf_conntrack_ipv4: can't register ipv4\n"); | |
453 | goto cleanup_icmp; | |
454 | } | |
455 | ||
964ddaa1 PM |
456 | ret = nf_register_hooks(ipv4_conntrack_ops, |
457 | ARRAY_SIZE(ipv4_conntrack_ops)); | |
9fb9cbb1 | 458 | if (ret < 0) { |
964ddaa1 | 459 | printk("nf_conntrack_ipv4: can't register hooks.\n"); |
9fb9cbb1 YK |
460 | goto cleanup_ipv4; |
461 | } | |
e4bd8bce PM |
462 | #if defined(CONFIG_PROC_FS) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT) |
463 | ret = nf_conntrack_ipv4_compat_init(); | |
464 | if (ret < 0) | |
465 | goto cleanup_hooks; | |
466 | #endif | |
9fb9cbb1 | 467 | return ret; |
e4bd8bce PM |
468 | #if defined(CONFIG_PROC_FS) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT) |
469 | cleanup_hooks: | |
e905a9ed | 470 | nf_unregister_hooks(ipv4_conntrack_ops, ARRAY_SIZE(ipv4_conntrack_ops)); |
e4bd8bce | 471 | #endif |
9fb9cbb1 YK |
472 | cleanup_ipv4: |
473 | nf_conntrack_l3proto_unregister(&nf_conntrack_l3proto_ipv4); | |
474 | cleanup_icmp: | |
605dcad6 | 475 | nf_conntrack_l4proto_unregister(&nf_conntrack_l4proto_icmp); |
9fb9cbb1 | 476 | cleanup_udp: |
605dcad6 | 477 | nf_conntrack_l4proto_unregister(&nf_conntrack_l4proto_udp4); |
9fb9cbb1 | 478 | cleanup_tcp: |
605dcad6 | 479 | nf_conntrack_l4proto_unregister(&nf_conntrack_l4proto_tcp4); |
9fb9cbb1 YK |
480 | cleanup_sockopt: |
481 | nf_unregister_sockopt(&so_getorigdst); | |
9fb9cbb1 YK |
482 | return ret; |
483 | } | |
484 | ||
65b4b4e8 | 485 | static void __exit nf_conntrack_l3proto_ipv4_fini(void) |
9fb9cbb1 | 486 | { |
32292a7f | 487 | synchronize_net(); |
e4bd8bce PM |
488 | #if defined(CONFIG_PROC_FS) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT) |
489 | nf_conntrack_ipv4_compat_fini(); | |
490 | #endif | |
32292a7f PM |
491 | nf_unregister_hooks(ipv4_conntrack_ops, ARRAY_SIZE(ipv4_conntrack_ops)); |
492 | nf_conntrack_l3proto_unregister(&nf_conntrack_l3proto_ipv4); | |
605dcad6 MJ |
493 | nf_conntrack_l4proto_unregister(&nf_conntrack_l4proto_icmp); |
494 | nf_conntrack_l4proto_unregister(&nf_conntrack_l4proto_udp4); | |
495 | nf_conntrack_l4proto_unregister(&nf_conntrack_l4proto_tcp4); | |
32292a7f | 496 | nf_unregister_sockopt(&so_getorigdst); |
9fb9cbb1 YK |
497 | } |
498 | ||
65b4b4e8 AM |
499 | module_init(nf_conntrack_l3proto_ipv4_init); |
500 | module_exit(nf_conntrack_l3proto_ipv4_fini); | |
591e6206 PM |
501 | |
502 | void need_ipv4_conntrack(void) | |
503 | { | |
504 | return; | |
505 | } | |
506 | EXPORT_SYMBOL_GPL(need_ipv4_conntrack); |