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
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>
16 /* A `tuple' is a structure containing the information to uniquely
17 identify a connection. ie. if two packets have the same tuple, they
18 are in the same connection; if not, they are not.
20 We divide the structure along "manipulatable" and
21 "non-manipulatable" lines, for the benefit of the NAT code.
24 #define NF_CT_TUPLE_L3SIZE ARRAY_SIZE(((union nf_inet_addr *)NULL)->all)
26 /* The protocol-specific manipulable parts of the tuple: always in
28 union nf_conntrack_man_proto
30 /* Add other protocols here. */
46 __be16 key
; /* GRE key is 32bit, PPtP only uses 16bit */
50 /* The manipulable part of the tuple. */
51 struct nf_conntrack_man
53 union nf_inet_addr u3
;
54 union nf_conntrack_man_proto u
;
55 /* Layer 3 protocol */
59 /* This contains the information to distinguish a connection. */
60 struct nf_conntrack_tuple
62 struct nf_conntrack_man src
;
64 /* These are the parts of the tuple which are fixed. */
66 union nf_inet_addr u3
;
68 /* Add other protocols here. */
91 /* The direction (for tuplehash) */
96 struct nf_conntrack_tuple_mask
99 union nf_inet_addr u3
;
100 union nf_conntrack_man_proto u
;
106 #define NF_CT_DUMP_TUPLE(tp) \
107 pr_debug("tuple %p: %u %u " NIP6_FMT " %hu -> " NIP6_FMT " %hu\n", \
108 (tp), (tp)->src.l3num, (tp)->dst.protonum, \
109 NIP6(*(struct in6_addr *)(tp)->src.u3.all), ntohs((tp)->src.u.all), \
110 NIP6(*(struct in6_addr *)(tp)->dst.u3.all), ntohs((tp)->dst.u.all))
112 /* If we're the first tuple, it's the original dir. */
113 #define NF_CT_DIRECTION(h) \
114 ((enum ip_conntrack_dir)(h)->tuple.dst.dir)
116 /* Connections have two entries in the hash table: one for each way */
117 struct nf_conntrack_tuple_hash
119 struct hlist_node hnode
;
120 struct nf_conntrack_tuple tuple
;
123 #endif /* __KERNEL__ */
125 static inline int __nf_ct_tuple_src_equal(const struct nf_conntrack_tuple
*t1
,
126 const struct nf_conntrack_tuple
*t2
)
128 return (t1
->src
.u3
.all
[0] == t2
->src
.u3
.all
[0] &&
129 t1
->src
.u3
.all
[1] == t2
->src
.u3
.all
[1] &&
130 t1
->src
.u3
.all
[2] == t2
->src
.u3
.all
[2] &&
131 t1
->src
.u3
.all
[3] == t2
->src
.u3
.all
[3] &&
132 t1
->src
.u
.all
== t2
->src
.u
.all
&&
133 t1
->src
.l3num
== t2
->src
.l3num
);
136 static inline int __nf_ct_tuple_dst_equal(const struct nf_conntrack_tuple
*t1
,
137 const struct nf_conntrack_tuple
*t2
)
139 return (t1
->dst
.u3
.all
[0] == t2
->dst
.u3
.all
[0] &&
140 t1
->dst
.u3
.all
[1] == t2
->dst
.u3
.all
[1] &&
141 t1
->dst
.u3
.all
[2] == t2
->dst
.u3
.all
[2] &&
142 t1
->dst
.u3
.all
[3] == t2
->dst
.u3
.all
[3] &&
143 t1
->dst
.u
.all
== t2
->dst
.u
.all
&&
144 t1
->dst
.protonum
== t2
->dst
.protonum
);
147 static inline int nf_ct_tuple_equal(const struct nf_conntrack_tuple
*t1
,
148 const struct nf_conntrack_tuple
*t2
)
150 return __nf_ct_tuple_src_equal(t1
, t2
) &&
151 __nf_ct_tuple_dst_equal(t1
, t2
);
154 static inline int nf_ct_tuple_mask_equal(const struct nf_conntrack_tuple_mask
*m1
,
155 const struct nf_conntrack_tuple_mask
*m2
)
157 return (m1
->src
.u3
.all
[0] == m2
->src
.u3
.all
[0] &&
158 m1
->src
.u3
.all
[1] == m2
->src
.u3
.all
[1] &&
159 m1
->src
.u3
.all
[2] == m2
->src
.u3
.all
[2] &&
160 m1
->src
.u3
.all
[3] == m2
->src
.u3
.all
[3] &&
161 m1
->src
.u
.all
== m2
->src
.u
.all
);
164 static inline int nf_ct_tuple_src_mask_cmp(const struct nf_conntrack_tuple
*t1
,
165 const struct nf_conntrack_tuple
*t2
,
166 const struct nf_conntrack_tuple_mask
*mask
)
170 for (count
= 0; count
< NF_CT_TUPLE_L3SIZE
; count
++) {
171 if ((t1
->src
.u3
.all
[count
] ^ t2
->src
.u3
.all
[count
]) &
172 mask
->src
.u3
.all
[count
])
176 if ((t1
->src
.u
.all
^ t2
->src
.u
.all
) & mask
->src
.u
.all
)
179 if (t1
->src
.l3num
!= t2
->src
.l3num
||
180 t1
->dst
.protonum
!= t2
->dst
.protonum
)
186 static inline int nf_ct_tuple_mask_cmp(const struct nf_conntrack_tuple
*t
,
187 const struct nf_conntrack_tuple
*tuple
,
188 const struct nf_conntrack_tuple_mask
*mask
)
190 return nf_ct_tuple_src_mask_cmp(t
, tuple
, mask
) &&
191 __nf_ct_tuple_dst_equal(t
, tuple
);
194 #endif /* _NF_CONNTRACK_TUPLE_H */