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