jsm: Fixed EEH recovery error
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / include / net / netfilter / nf_conntrack_tuple.h
blob2f8fb77bfdd1f7d9583e42ddbee7cf0240228e17
1 /*
2 * Definitions and Declarations for tuple.
4 * 16 Dec 2003: Yasuyuki Kozakai @USAGI <yasuyuki.kozakai@toshiba.co.jp>
5 * - generalize L3 protocol dependent part.
7 * Derived from include/linux/netfiter_ipv4/ip_conntrack_tuple.h
8 */
10 #ifndef _NF_CONNTRACK_TUPLE_H
11 #define _NF_CONNTRACK_TUPLE_H
13 #include <linux/netfilter/x_tables.h>
14 #include <linux/netfilter/nf_conntrack_tuple_common.h>
15 #include <linux/netfilter_ipv4/nf_nat.h>
16 #include <linux/list_nulls.h>
18 /* A `tuple' is a structure containing the information to uniquely
19 identify a connection. ie. if two packets have the same tuple, they
20 are in the same connection; if not, they are not.
22 We divide the structure along "manipulatable" and
23 "non-manipulatable" lines, for the benefit of the NAT code.
26 #define NF_CT_TUPLE_L3SIZE ARRAY_SIZE(((union nf_inet_addr *)NULL)->all)
28 /* The manipulable part of the tuple. */
29 struct nf_conntrack_man {
30 union nf_inet_addr u3;
31 union nf_conntrack_man_proto u;
32 /* Layer 3 protocol */
33 u_int16_t l3num;
36 /* This contains the information to distinguish a connection. */
37 struct nf_conntrack_tuple {
38 struct nf_conntrack_man src;
40 /* These are the parts of the tuple which are fixed. */
41 struct {
42 union nf_inet_addr u3;
43 union {
44 /* Add other protocols here. */
45 __be16 all;
47 struct {
48 __be16 port;
49 } tcp;
50 struct {
51 __be16 port;
52 } udp;
53 struct {
54 u_int8_t type, code;
55 } icmp;
56 struct {
57 __be16 port;
58 } dccp;
59 struct {
60 __be16 port;
61 } sctp;
62 struct {
63 __be16 key;
64 } gre;
65 } u;
67 /* The protocol. */
68 u_int8_t protonum;
70 /* The direction (for tuplehash) */
71 u_int8_t dir;
72 } dst;
75 struct nf_conntrack_tuple_mask {
76 struct {
77 union nf_inet_addr u3;
78 union nf_conntrack_man_proto u;
79 } src;
82 static inline void nf_ct_dump_tuple_ip(const struct nf_conntrack_tuple *t)
84 #ifdef DEBUG
85 printk("tuple %p: %u %pI4:%hu -> %pI4:%hu\n",
86 t, t->dst.protonum,
87 &t->src.u3.ip, ntohs(t->src.u.all),
88 &t->dst.u3.ip, ntohs(t->dst.u.all));
89 #endif
92 static inline void nf_ct_dump_tuple_ipv6(const struct nf_conntrack_tuple *t)
94 #ifdef DEBUG
95 printk("tuple %p: %u %pI6 %hu -> %pI6 %hu\n",
96 t, t->dst.protonum,
97 t->src.u3.all, ntohs(t->src.u.all),
98 t->dst.u3.all, ntohs(t->dst.u.all));
99 #endif
102 static inline void nf_ct_dump_tuple(const struct nf_conntrack_tuple *t)
104 switch (t->src.l3num) {
105 case AF_INET:
106 nf_ct_dump_tuple_ip(t);
107 break;
108 case AF_INET6:
109 nf_ct_dump_tuple_ipv6(t);
110 break;
114 /* If we're the first tuple, it's the original dir. */
115 #define NF_CT_DIRECTION(h) \
116 ((enum ip_conntrack_dir)(h)->tuple.dst.dir)
118 /* Connections have two entries in the hash table: one for each way */
119 struct nf_conntrack_tuple_hash {
120 struct hlist_nulls_node hnnode;
121 struct nf_conntrack_tuple tuple;
124 static inline bool __nf_ct_tuple_src_equal(const struct nf_conntrack_tuple *t1,
125 const struct nf_conntrack_tuple *t2)
127 return (nf_inet_addr_cmp(&t1->src.u3, &t2->src.u3) &&
128 t1->src.u.all == t2->src.u.all &&
129 t1->src.l3num == t2->src.l3num);
132 static inline bool __nf_ct_tuple_dst_equal(const struct nf_conntrack_tuple *t1,
133 const struct nf_conntrack_tuple *t2)
135 return (nf_inet_addr_cmp(&t1->dst.u3, &t2->dst.u3) &&
136 t1->dst.u.all == t2->dst.u.all &&
137 t1->dst.protonum == t2->dst.protonum);
140 static inline bool nf_ct_tuple_equal(const struct nf_conntrack_tuple *t1,
141 const struct nf_conntrack_tuple *t2)
143 return __nf_ct_tuple_src_equal(t1, t2) &&
144 __nf_ct_tuple_dst_equal(t1, t2);
147 static inline bool
148 nf_ct_tuple_mask_equal(const struct nf_conntrack_tuple_mask *m1,
149 const struct nf_conntrack_tuple_mask *m2)
151 return (nf_inet_addr_cmp(&m1->src.u3, &m2->src.u3) &&
152 m1->src.u.all == m2->src.u.all);
155 static inline bool
156 nf_ct_tuple_src_mask_cmp(const struct nf_conntrack_tuple *t1,
157 const struct nf_conntrack_tuple *t2,
158 const struct nf_conntrack_tuple_mask *mask)
160 int count;
162 for (count = 0; count < NF_CT_TUPLE_L3SIZE; count++) {
163 if ((t1->src.u3.all[count] ^ t2->src.u3.all[count]) &
164 mask->src.u3.all[count])
165 return false;
168 if ((t1->src.u.all ^ t2->src.u.all) & mask->src.u.all)
169 return false;
171 if (t1->src.l3num != t2->src.l3num ||
172 t1->dst.protonum != t2->dst.protonum)
173 return false;
175 return true;
178 static inline bool
179 nf_ct_tuple_mask_cmp(const struct nf_conntrack_tuple *t,
180 const struct nf_conntrack_tuple *tuple,
181 const struct nf_conntrack_tuple_mask *mask)
183 return nf_ct_tuple_src_mask_cmp(t, tuple, mask) &&
184 __nf_ct_tuple_dst_equal(t, tuple);
187 #endif /* _NF_CONNTRACK_TUPLE_H */