Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 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. |
| 7 | * |
| 8 | * 16 Dec 2003: Yasuyuki Kozakai @USAGI <yasuyuki.kozakai@toshiba.co.jp> |
| 9 | * - move L3 protocol dependent part to this file. |
| 10 | * 23 Mar 2004: Yasuyuki Kozakai @USAGI <yasuyuki.kozakai@toshiba.co.jp> |
| 11 | * - add get_features() to support various size of conntrack |
| 12 | * structures. |
| 13 | * |
| 14 | * Derived from net/ipv4/netfilter/ip_conntrack_standalone.c |
| 15 | */ |
| 16 | |
| 17 | #include <linux/config.h> |
| 18 | #include <linux/types.h> |
| 19 | #include <linux/ip.h> |
| 20 | #include <linux/netfilter.h> |
| 21 | #include <linux/module.h> |
| 22 | #include <linux/skbuff.h> |
| 23 | #include <linux/icmp.h> |
| 24 | #include <linux/sysctl.h> |
Patrick McHardy | 0ae2cfe | 2006-01-05 12:21:52 -0800 | [diff] [blame] | 25 | #include <net/route.h> |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 26 | #include <net/ip.h> |
| 27 | |
| 28 | #include <linux/netfilter_ipv4.h> |
| 29 | #include <net/netfilter/nf_conntrack.h> |
| 30 | #include <net/netfilter/nf_conntrack_helper.h> |
| 31 | #include <net/netfilter/nf_conntrack_protocol.h> |
| 32 | #include <net/netfilter/nf_conntrack_l3proto.h> |
| 33 | #include <net/netfilter/nf_conntrack_core.h> |
| 34 | #include <net/netfilter/ipv4/nf_conntrack_ipv4.h> |
| 35 | |
| 36 | #if 0 |
| 37 | #define DEBUGP printk |
| 38 | #else |
| 39 | #define DEBUGP(format, args...) |
| 40 | #endif |
| 41 | |
| 42 | DECLARE_PER_CPU(struct nf_conntrack_stat, nf_conntrack_stat); |
| 43 | |
| 44 | static int ipv4_pkt_to_tuple(const struct sk_buff *skb, unsigned int nhoff, |
| 45 | struct nf_conntrack_tuple *tuple) |
| 46 | { |
| 47 | u_int32_t _addrs[2], *ap; |
| 48 | ap = skb_header_pointer(skb, nhoff + offsetof(struct iphdr, saddr), |
| 49 | sizeof(u_int32_t) * 2, _addrs); |
| 50 | if (ap == NULL) |
| 51 | return 0; |
| 52 | |
| 53 | tuple->src.u3.ip = ap[0]; |
| 54 | tuple->dst.u3.ip = ap[1]; |
| 55 | |
| 56 | return 1; |
| 57 | } |
| 58 | |
| 59 | static int ipv4_invert_tuple(struct nf_conntrack_tuple *tuple, |
| 60 | const struct nf_conntrack_tuple *orig) |
| 61 | { |
| 62 | tuple->src.u3.ip = orig->dst.u3.ip; |
| 63 | tuple->dst.u3.ip = orig->src.u3.ip; |
| 64 | |
| 65 | return 1; |
| 66 | } |
| 67 | |
| 68 | static int ipv4_print_tuple(struct seq_file *s, |
| 69 | const struct nf_conntrack_tuple *tuple) |
| 70 | { |
| 71 | return seq_printf(s, "src=%u.%u.%u.%u dst=%u.%u.%u.%u ", |
| 72 | NIPQUAD(tuple->src.u3.ip), |
| 73 | NIPQUAD(tuple->dst.u3.ip)); |
| 74 | } |
| 75 | |
| 76 | static int ipv4_print_conntrack(struct seq_file *s, |
| 77 | const struct nf_conn *conntrack) |
| 78 | { |
| 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | /* Returns new sk_buff, or NULL */ |
| 83 | static struct sk_buff * |
| 84 | nf_ct_ipv4_gather_frags(struct sk_buff *skb, u_int32_t user) |
| 85 | { |
| 86 | skb_orphan(skb); |
| 87 | |
| 88 | local_bh_disable(); |
| 89 | skb = ip_defrag(skb, user); |
| 90 | local_bh_enable(); |
| 91 | |
| 92 | if (skb) |
| 93 | ip_send_check(skb->nh.iph); |
| 94 | |
| 95 | return skb; |
| 96 | } |
| 97 | |
| 98 | static int |
| 99 | ipv4_prepare(struct sk_buff **pskb, unsigned int hooknum, unsigned int *dataoff, |
| 100 | u_int8_t *protonum) |
| 101 | { |
| 102 | /* Never happen */ |
| 103 | if ((*pskb)->nh.iph->frag_off & htons(IP_OFFSET)) { |
| 104 | if (net_ratelimit()) { |
| 105 | printk(KERN_ERR "ipv4_prepare: Frag of proto %u (hook=%u)\n", |
| 106 | (*pskb)->nh.iph->protocol, hooknum); |
| 107 | } |
| 108 | return -NF_DROP; |
| 109 | } |
| 110 | |
| 111 | *dataoff = (*pskb)->nh.raw - (*pskb)->data + (*pskb)->nh.iph->ihl*4; |
| 112 | *protonum = (*pskb)->nh.iph->protocol; |
| 113 | |
| 114 | return NF_ACCEPT; |
| 115 | } |
| 116 | |
| 117 | int nat_module_is_loaded = 0; |
| 118 | static u_int32_t ipv4_get_features(const struct nf_conntrack_tuple *tuple) |
| 119 | { |
| 120 | if (nat_module_is_loaded) |
| 121 | return NF_CT_F_NAT; |
| 122 | |
| 123 | return NF_CT_F_BASIC; |
| 124 | } |
| 125 | |
| 126 | static unsigned int ipv4_confirm(unsigned int hooknum, |
| 127 | struct sk_buff **pskb, |
| 128 | const struct net_device *in, |
| 129 | const struct net_device *out, |
| 130 | int (*okfn)(struct sk_buff *)) |
| 131 | { |
| 132 | /* We've seen it coming out the other side: confirm it */ |
| 133 | return nf_conntrack_confirm(pskb); |
| 134 | } |
| 135 | |
| 136 | static unsigned int ipv4_conntrack_help(unsigned int hooknum, |
| 137 | struct sk_buff **pskb, |
| 138 | const struct net_device *in, |
| 139 | const struct net_device *out, |
| 140 | int (*okfn)(struct sk_buff *)) |
| 141 | { |
| 142 | struct nf_conn *ct; |
| 143 | enum ip_conntrack_info ctinfo; |
Harald Welte | dc808fe | 2006-03-20 17:56:32 -0800 | [diff] [blame] | 144 | struct nf_conn_help *help; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 145 | |
| 146 | /* This is where we call the helper: as the packet goes out. */ |
| 147 | ct = nf_ct_get(*pskb, &ctinfo); |
Harald Welte | dc808fe | 2006-03-20 17:56:32 -0800 | [diff] [blame] | 148 | if (!ct) |
| 149 | return NF_ACCEPT; |
| 150 | |
| 151 | help = nfct_help(ct); |
| 152 | if (!help || !help->helper) |
| 153 | return NF_ACCEPT; |
| 154 | |
| 155 | return help->helper->help(pskb, |
| 156 | (*pskb)->nh.raw - (*pskb)->data |
| 157 | + (*pskb)->nh.iph->ihl*4, |
| 158 | ct, ctinfo); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | static unsigned int ipv4_conntrack_defrag(unsigned int hooknum, |
| 162 | struct sk_buff **pskb, |
| 163 | const struct net_device *in, |
| 164 | const struct net_device *out, |
| 165 | int (*okfn)(struct sk_buff *)) |
| 166 | { |
| 167 | #if !defined(CONFIG_IP_NF_NAT) && !defined(CONFIG_IP_NF_NAT_MODULE) |
| 168 | /* Previously seen (loopback)? Ignore. Do this before |
| 169 | fragment check. */ |
| 170 | if ((*pskb)->nfct) |
| 171 | return NF_ACCEPT; |
| 172 | #endif |
| 173 | |
| 174 | /* Gather fragments. */ |
| 175 | if ((*pskb)->nh.iph->frag_off & htons(IP_MF|IP_OFFSET)) { |
| 176 | *pskb = nf_ct_ipv4_gather_frags(*pskb, |
| 177 | hooknum == NF_IP_PRE_ROUTING ? |
| 178 | IP_DEFRAG_CONNTRACK_IN : |
| 179 | IP_DEFRAG_CONNTRACK_OUT); |
| 180 | if (!*pskb) |
| 181 | return NF_STOLEN; |
| 182 | } |
| 183 | return NF_ACCEPT; |
| 184 | } |
| 185 | |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 186 | static unsigned int ipv4_conntrack_in(unsigned int hooknum, |
| 187 | struct sk_buff **pskb, |
| 188 | const struct net_device *in, |
| 189 | const struct net_device *out, |
| 190 | int (*okfn)(struct sk_buff *)) |
| 191 | { |
| 192 | return nf_conntrack_in(PF_INET, hooknum, pskb); |
| 193 | } |
| 194 | |
| 195 | static unsigned int ipv4_conntrack_local(unsigned int hooknum, |
| 196 | struct sk_buff **pskb, |
| 197 | const struct net_device *in, |
| 198 | const struct net_device *out, |
| 199 | int (*okfn)(struct sk_buff *)) |
| 200 | { |
| 201 | /* root is playing with raw sockets. */ |
| 202 | if ((*pskb)->len < sizeof(struct iphdr) |
| 203 | || (*pskb)->nh.iph->ihl * 4 < sizeof(struct iphdr)) { |
| 204 | if (net_ratelimit()) |
| 205 | printk("ipt_hook: happy cracking.\n"); |
| 206 | return NF_ACCEPT; |
| 207 | } |
| 208 | return nf_conntrack_in(PF_INET, hooknum, pskb); |
| 209 | } |
| 210 | |
| 211 | /* Connection tracking may drop packets, but never alters them, so |
| 212 | make it the first hook. */ |
Patrick McHardy | 964ddaa | 2006-04-06 14:09:49 -0700 | [diff] [blame] | 213 | static struct nf_hook_ops ipv4_conntrack_ops[] = { |
| 214 | { |
| 215 | .hook = ipv4_conntrack_defrag, |
| 216 | .owner = THIS_MODULE, |
| 217 | .pf = PF_INET, |
| 218 | .hooknum = NF_IP_PRE_ROUTING, |
| 219 | .priority = NF_IP_PRI_CONNTRACK_DEFRAG, |
| 220 | }, |
| 221 | { |
| 222 | .hook = ipv4_conntrack_in, |
| 223 | .owner = THIS_MODULE, |
| 224 | .pf = PF_INET, |
| 225 | .hooknum = NF_IP_PRE_ROUTING, |
| 226 | .priority = NF_IP_PRI_CONNTRACK, |
| 227 | }, |
| 228 | { |
| 229 | .hook = ipv4_conntrack_defrag, |
| 230 | .owner = THIS_MODULE, |
| 231 | .pf = PF_INET, |
| 232 | .hooknum = NF_IP_LOCAL_OUT, |
| 233 | .priority = NF_IP_PRI_CONNTRACK_DEFRAG, |
| 234 | }, |
| 235 | { |
| 236 | .hook = ipv4_conntrack_local, |
| 237 | .owner = THIS_MODULE, |
| 238 | .pf = PF_INET, |
| 239 | .hooknum = NF_IP_LOCAL_OUT, |
| 240 | .priority = NF_IP_PRI_CONNTRACK, |
| 241 | }, |
| 242 | { |
| 243 | .hook = ipv4_conntrack_help, |
| 244 | .owner = THIS_MODULE, |
| 245 | .pf = PF_INET, |
| 246 | .hooknum = NF_IP_POST_ROUTING, |
| 247 | .priority = NF_IP_PRI_CONNTRACK_HELPER, |
| 248 | }, |
| 249 | { |
| 250 | .hook = ipv4_conntrack_help, |
| 251 | .owner = THIS_MODULE, |
| 252 | .pf = PF_INET, |
| 253 | .hooknum = NF_IP_LOCAL_IN, |
| 254 | .priority = NF_IP_PRI_CONNTRACK_HELPER, |
| 255 | }, |
| 256 | { |
| 257 | .hook = ipv4_confirm, |
| 258 | .owner = THIS_MODULE, |
| 259 | .pf = PF_INET, |
| 260 | .hooknum = NF_IP_POST_ROUTING, |
| 261 | .priority = NF_IP_PRI_CONNTRACK_CONFIRM, |
| 262 | }, |
| 263 | { |
| 264 | .hook = ipv4_confirm, |
| 265 | .owner = THIS_MODULE, |
| 266 | .pf = PF_INET, |
| 267 | .hooknum = NF_IP_LOCAL_IN, |
| 268 | .priority = NF_IP_PRI_CONNTRACK_CONFIRM, |
| 269 | }, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 270 | }; |
| 271 | |
| 272 | #ifdef CONFIG_SYSCTL |
| 273 | /* From nf_conntrack_proto_icmp.c */ |
Patrick McHardy | babbdb1 | 2006-01-09 17:48:09 -0800 | [diff] [blame] | 274 | extern unsigned int nf_ct_icmp_timeout; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 275 | static struct ctl_table_header *nf_ct_ipv4_sysctl_header; |
| 276 | |
| 277 | static ctl_table nf_ct_sysctl_table[] = { |
| 278 | { |
| 279 | .ctl_name = NET_NF_CONNTRACK_ICMP_TIMEOUT, |
| 280 | .procname = "nf_conntrack_icmp_timeout", |
| 281 | .data = &nf_ct_icmp_timeout, |
| 282 | .maxlen = sizeof(unsigned int), |
| 283 | .mode = 0644, |
| 284 | .proc_handler = &proc_dointvec_jiffies, |
| 285 | }, |
| 286 | { .ctl_name = 0 } |
| 287 | }; |
| 288 | |
| 289 | static ctl_table nf_ct_netfilter_table[] = { |
| 290 | { |
| 291 | .ctl_name = NET_NETFILTER, |
| 292 | .procname = "netfilter", |
| 293 | .mode = 0555, |
| 294 | .child = nf_ct_sysctl_table, |
| 295 | }, |
| 296 | { .ctl_name = 0 } |
| 297 | }; |
| 298 | |
| 299 | static ctl_table nf_ct_net_table[] = { |
| 300 | { |
| 301 | .ctl_name = CTL_NET, |
| 302 | .procname = "net", |
| 303 | .mode = 0555, |
| 304 | .child = nf_ct_netfilter_table, |
| 305 | }, |
| 306 | { .ctl_name = 0 } |
| 307 | }; |
| 308 | #endif |
| 309 | |
| 310 | /* Fast function for those who don't want to parse /proc (and I don't |
| 311 | blame them). */ |
| 312 | /* Reversing the socket's dst/src point of view gives us the reply |
| 313 | mapping. */ |
| 314 | static int |
| 315 | getorigdst(struct sock *sk, int optval, void __user *user, int *len) |
| 316 | { |
| 317 | struct inet_sock *inet = inet_sk(sk); |
| 318 | struct nf_conntrack_tuple_hash *h; |
| 319 | struct nf_conntrack_tuple tuple; |
| 320 | |
| 321 | NF_CT_TUPLE_U_BLANK(&tuple); |
| 322 | tuple.src.u3.ip = inet->rcv_saddr; |
| 323 | tuple.src.u.tcp.port = inet->sport; |
| 324 | tuple.dst.u3.ip = inet->daddr; |
| 325 | tuple.dst.u.tcp.port = inet->dport; |
| 326 | tuple.src.l3num = PF_INET; |
| 327 | tuple.dst.protonum = IPPROTO_TCP; |
| 328 | |
| 329 | /* We only do TCP at the moment: is there a better way? */ |
| 330 | if (strcmp(sk->sk_prot->name, "TCP")) { |
| 331 | DEBUGP("SO_ORIGINAL_DST: Not a TCP socket\n"); |
| 332 | return -ENOPROTOOPT; |
| 333 | } |
| 334 | |
| 335 | if ((unsigned int) *len < sizeof(struct sockaddr_in)) { |
| 336 | DEBUGP("SO_ORIGINAL_DST: len %u not %u\n", |
| 337 | *len, sizeof(struct sockaddr_in)); |
| 338 | return -EINVAL; |
| 339 | } |
| 340 | |
| 341 | h = nf_conntrack_find_get(&tuple, NULL); |
| 342 | if (h) { |
| 343 | struct sockaddr_in sin; |
| 344 | struct nf_conn *ct = nf_ct_tuplehash_to_ctrack(h); |
| 345 | |
| 346 | sin.sin_family = AF_INET; |
| 347 | sin.sin_port = ct->tuplehash[IP_CT_DIR_ORIGINAL] |
| 348 | .tuple.dst.u.tcp.port; |
| 349 | sin.sin_addr.s_addr = ct->tuplehash[IP_CT_DIR_ORIGINAL] |
| 350 | .tuple.dst.u3.ip; |
Marcel Holtmann | 6c813c3 | 2006-05-28 22:50:18 -0700 | [diff] [blame] | 351 | memset(sin.sin_zero, 0, sizeof(sin.sin_zero)); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 352 | |
| 353 | DEBUGP("SO_ORIGINAL_DST: %u.%u.%u.%u %u\n", |
| 354 | NIPQUAD(sin.sin_addr.s_addr), ntohs(sin.sin_port)); |
| 355 | nf_ct_put(ct); |
| 356 | if (copy_to_user(user, &sin, sizeof(sin)) != 0) |
| 357 | return -EFAULT; |
| 358 | else |
| 359 | return 0; |
| 360 | } |
| 361 | DEBUGP("SO_ORIGINAL_DST: Can't find %u.%u.%u.%u/%u-%u.%u.%u.%u/%u.\n", |
| 362 | NIPQUAD(tuple.src.u3.ip), ntohs(tuple.src.u.tcp.port), |
| 363 | NIPQUAD(tuple.dst.u3.ip), ntohs(tuple.dst.u.tcp.port)); |
| 364 | return -ENOENT; |
| 365 | } |
| 366 | |
Pablo Neira Ayuso | c1d10ad | 2006-01-05 12:19:05 -0800 | [diff] [blame] | 367 | #if defined(CONFIG_NF_CT_NETLINK) || \ |
| 368 | defined(CONFIG_NF_CT_NETLINK_MODULE) |
| 369 | |
| 370 | #include <linux/netfilter/nfnetlink.h> |
| 371 | #include <linux/netfilter/nfnetlink_conntrack.h> |
| 372 | |
| 373 | static int ipv4_tuple_to_nfattr(struct sk_buff *skb, |
| 374 | const struct nf_conntrack_tuple *tuple) |
| 375 | { |
| 376 | NFA_PUT(skb, CTA_IP_V4_SRC, sizeof(u_int32_t), |
| 377 | &tuple->src.u3.ip); |
| 378 | NFA_PUT(skb, CTA_IP_V4_DST, sizeof(u_int32_t), |
| 379 | &tuple->dst.u3.ip); |
| 380 | return 0; |
| 381 | |
| 382 | nfattr_failure: |
| 383 | return -1; |
| 384 | } |
| 385 | |
| 386 | static const size_t cta_min_ip[CTA_IP_MAX] = { |
| 387 | [CTA_IP_V4_SRC-1] = sizeof(u_int32_t), |
| 388 | [CTA_IP_V4_DST-1] = sizeof(u_int32_t), |
| 389 | }; |
| 390 | |
| 391 | static int ipv4_nfattr_to_tuple(struct nfattr *tb[], |
| 392 | struct nf_conntrack_tuple *t) |
| 393 | { |
| 394 | if (!tb[CTA_IP_V4_SRC-1] || !tb[CTA_IP_V4_DST-1]) |
| 395 | return -EINVAL; |
| 396 | |
| 397 | if (nfattr_bad_size(tb, CTA_IP_MAX, cta_min_ip)) |
| 398 | return -EINVAL; |
| 399 | |
| 400 | t->src.u3.ip = |
| 401 | *(u_int32_t *)NFA_DATA(tb[CTA_IP_V4_SRC-1]); |
| 402 | t->dst.u3.ip = |
| 403 | *(u_int32_t *)NFA_DATA(tb[CTA_IP_V4_DST-1]); |
| 404 | |
| 405 | return 0; |
| 406 | } |
| 407 | #endif |
| 408 | |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 409 | static struct nf_sockopt_ops so_getorigdst = { |
| 410 | .pf = PF_INET, |
| 411 | .get_optmin = SO_ORIGINAL_DST, |
| 412 | .get_optmax = SO_ORIGINAL_DST+1, |
| 413 | .get = &getorigdst, |
| 414 | }; |
| 415 | |
| 416 | struct nf_conntrack_l3proto nf_conntrack_l3proto_ipv4 = { |
| 417 | .l3proto = PF_INET, |
| 418 | .name = "ipv4", |
| 419 | .pkt_to_tuple = ipv4_pkt_to_tuple, |
| 420 | .invert_tuple = ipv4_invert_tuple, |
| 421 | .print_tuple = ipv4_print_tuple, |
| 422 | .print_conntrack = ipv4_print_conntrack, |
| 423 | .prepare = ipv4_prepare, |
| 424 | .get_features = ipv4_get_features, |
Pablo Neira Ayuso | c1d10ad | 2006-01-05 12:19:05 -0800 | [diff] [blame] | 425 | #if defined(CONFIG_NF_CT_NETLINK) || \ |
| 426 | defined(CONFIG_NF_CT_NETLINK_MODULE) |
| 427 | .tuple_to_nfattr = ipv4_tuple_to_nfattr, |
| 428 | .nfattr_to_tuple = ipv4_nfattr_to_tuple, |
| 429 | #endif |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 430 | .me = THIS_MODULE, |
| 431 | }; |
| 432 | |
| 433 | extern struct nf_conntrack_protocol nf_conntrack_protocol_tcp4; |
| 434 | extern struct nf_conntrack_protocol nf_conntrack_protocol_udp4; |
| 435 | extern struct nf_conntrack_protocol nf_conntrack_protocol_icmp; |
Patrick McHardy | 32292a7 | 2006-04-06 14:11:30 -0700 | [diff] [blame] | 436 | |
| 437 | MODULE_ALIAS("nf_conntrack-" __stringify(AF_INET)); |
| 438 | MODULE_LICENSE("GPL"); |
| 439 | |
| 440 | static int __init nf_conntrack_l3proto_ipv4_init(void) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 441 | { |
| 442 | int ret = 0; |
| 443 | |
Patrick McHardy | 32292a7 | 2006-04-06 14:11:30 -0700 | [diff] [blame] | 444 | need_conntrack(); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 445 | |
| 446 | ret = nf_register_sockopt(&so_getorigdst); |
| 447 | if (ret < 0) { |
| 448 | printk(KERN_ERR "Unable to register netfilter socket option\n"); |
Patrick McHardy | 32292a7 | 2006-04-06 14:11:30 -0700 | [diff] [blame] | 449 | return ret; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | ret = nf_conntrack_protocol_register(&nf_conntrack_protocol_tcp4); |
| 453 | if (ret < 0) { |
| 454 | printk("nf_conntrack_ipv4: can't register tcp.\n"); |
| 455 | goto cleanup_sockopt; |
| 456 | } |
| 457 | |
| 458 | ret = nf_conntrack_protocol_register(&nf_conntrack_protocol_udp4); |
| 459 | if (ret < 0) { |
| 460 | printk("nf_conntrack_ipv4: can't register udp.\n"); |
| 461 | goto cleanup_tcp; |
| 462 | } |
| 463 | |
| 464 | ret = nf_conntrack_protocol_register(&nf_conntrack_protocol_icmp); |
| 465 | if (ret < 0) { |
| 466 | printk("nf_conntrack_ipv4: can't register icmp.\n"); |
| 467 | goto cleanup_udp; |
| 468 | } |
| 469 | |
| 470 | ret = nf_conntrack_l3proto_register(&nf_conntrack_l3proto_ipv4); |
| 471 | if (ret < 0) { |
| 472 | printk("nf_conntrack_ipv4: can't register ipv4\n"); |
| 473 | goto cleanup_icmp; |
| 474 | } |
| 475 | |
Patrick McHardy | 964ddaa | 2006-04-06 14:09:49 -0700 | [diff] [blame] | 476 | ret = nf_register_hooks(ipv4_conntrack_ops, |
| 477 | ARRAY_SIZE(ipv4_conntrack_ops)); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 478 | if (ret < 0) { |
Patrick McHardy | 964ddaa | 2006-04-06 14:09:49 -0700 | [diff] [blame] | 479 | printk("nf_conntrack_ipv4: can't register hooks.\n"); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 480 | goto cleanup_ipv4; |
| 481 | } |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 482 | #ifdef CONFIG_SYSCTL |
| 483 | nf_ct_ipv4_sysctl_header = register_sysctl_table(nf_ct_net_table, 0); |
| 484 | if (nf_ct_ipv4_sysctl_header == NULL) { |
| 485 | printk("nf_conntrack: can't register to sysctl.\n"); |
| 486 | ret = -ENOMEM; |
Patrick McHardy | 964ddaa | 2006-04-06 14:09:49 -0700 | [diff] [blame] | 487 | goto cleanup_hooks; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 488 | } |
| 489 | #endif |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 490 | return ret; |
| 491 | |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 492 | #ifdef CONFIG_SYSCTL |
Patrick McHardy | 964ddaa | 2006-04-06 14:09:49 -0700 | [diff] [blame] | 493 | cleanup_hooks: |
Patrick McHardy | 964ddaa | 2006-04-06 14:09:49 -0700 | [diff] [blame] | 494 | nf_unregister_hooks(ipv4_conntrack_ops, ARRAY_SIZE(ipv4_conntrack_ops)); |
Patrick McHardy | 32292a7 | 2006-04-06 14:11:30 -0700 | [diff] [blame] | 495 | #endif |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 496 | cleanup_ipv4: |
| 497 | nf_conntrack_l3proto_unregister(&nf_conntrack_l3proto_ipv4); |
| 498 | cleanup_icmp: |
| 499 | nf_conntrack_protocol_unregister(&nf_conntrack_protocol_icmp); |
| 500 | cleanup_udp: |
| 501 | nf_conntrack_protocol_unregister(&nf_conntrack_protocol_udp4); |
| 502 | cleanup_tcp: |
| 503 | nf_conntrack_protocol_unregister(&nf_conntrack_protocol_tcp4); |
| 504 | cleanup_sockopt: |
| 505 | nf_unregister_sockopt(&so_getorigdst); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 506 | return ret; |
| 507 | } |
| 508 | |
Andrew Morton | 65b4b4e | 2006-03-28 16:37:06 -0800 | [diff] [blame] | 509 | static void __exit nf_conntrack_l3proto_ipv4_fini(void) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 510 | { |
Patrick McHardy | 32292a7 | 2006-04-06 14:11:30 -0700 | [diff] [blame] | 511 | synchronize_net(); |
| 512 | #ifdef CONFIG_SYSCTL |
| 513 | unregister_sysctl_table(nf_ct_ipv4_sysctl_header); |
| 514 | #endif |
| 515 | nf_unregister_hooks(ipv4_conntrack_ops, ARRAY_SIZE(ipv4_conntrack_ops)); |
| 516 | nf_conntrack_l3proto_unregister(&nf_conntrack_l3proto_ipv4); |
| 517 | nf_conntrack_protocol_unregister(&nf_conntrack_protocol_icmp); |
| 518 | nf_conntrack_protocol_unregister(&nf_conntrack_protocol_udp4); |
| 519 | nf_conntrack_protocol_unregister(&nf_conntrack_protocol_tcp4); |
| 520 | nf_unregister_sockopt(&so_getorigdst); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 521 | } |
| 522 | |
Andrew Morton | 65b4b4e | 2006-03-28 16:37:06 -0800 | [diff] [blame] | 523 | module_init(nf_conntrack_l3proto_ipv4_init); |
| 524 | module_exit(nf_conntrack_l3proto_ipv4_fini); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 525 | |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 526 | EXPORT_SYMBOL(nf_ct_ipv4_gather_frags); |