Linux-2.6.12-rc2
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / net / ipv4 / netfilter / ipt_state.c
blobb1511b97ea5f9c674452ee7c891b3a6eab7b4790
1 /* Kernel module to match connection tracking information. */
3 /* (C) 1999-2001 Paul `Rusty' Russell
4 * (C) 2002-2004 Netfilter Core Team <coreteam@netfilter.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
11 #include <linux/module.h>
12 #include <linux/skbuff.h>
13 #include <linux/netfilter_ipv4/ip_conntrack.h>
14 #include <linux/netfilter_ipv4/ip_tables.h>
15 #include <linux/netfilter_ipv4/ipt_state.h>
17 MODULE_LICENSE("GPL");
18 MODULE_AUTHOR("Rusty Russell <rusty@rustcorp.com.au>");
19 MODULE_DESCRIPTION("iptables connection tracking state match module");
21 static int
22 match(const struct sk_buff *skb,
23 const struct net_device *in,
24 const struct net_device *out,
25 const void *matchinfo,
26 int offset,
27 int *hotdrop)
29 const struct ipt_state_info *sinfo = matchinfo;
30 enum ip_conntrack_info ctinfo;
31 unsigned int statebit;
33 if (skb->nfct == &ip_conntrack_untracked.ct_general)
34 statebit = IPT_STATE_UNTRACKED;
35 else if (!ip_conntrack_get(skb, &ctinfo))
36 statebit = IPT_STATE_INVALID;
37 else
38 statebit = IPT_STATE_BIT(ctinfo);
40 return (sinfo->statemask & statebit);
43 static int check(const char *tablename,
44 const struct ipt_ip *ip,
45 void *matchinfo,
46 unsigned int matchsize,
47 unsigned int hook_mask)
49 if (matchsize != IPT_ALIGN(sizeof(struct ipt_state_info)))
50 return 0;
52 return 1;
55 static struct ipt_match state_match = {
56 .name = "state",
57 .match = &match,
58 .checkentry = &check,
59 .me = THIS_MODULE,
62 static int __init init(void)
64 need_ip_conntrack();
65 return ipt_register_match(&state_match);
68 static void __exit fini(void)
70 ipt_unregister_match(&state_match);
73 module_init(init);
74 module_exit(fini);