1 #ifndef _IP_CONNTRACK_TUPLE_H
2 #define _IP_CONNTRACK_TUPLE_H
4 #include <linux/types.h>
5 #include <linux/netfilter/nf_conntrack_tuple_common.h>
7 /* A `tuple' is a structure containing the information to uniquely
8 identify a connection. ie. if two packets have the same tuple, they
9 are in the same connection; if not, they are not.
11 We divide the structure along "manipulatable" and
12 "non-manipulatable" lines, for the benefit of the NAT code.
15 /* The protocol-specific manipulable parts of the tuple: always in
17 union ip_conntrack_manip_proto
19 /* Add other protocols here. */
35 __be16 key
; /* key is 32bit, pptp only uses 16 */
39 /* The manipulable part of the tuple. */
40 struct ip_conntrack_manip
43 union ip_conntrack_manip_proto u
;
46 /* This contains the information to distinguish a connection. */
47 struct ip_conntrack_tuple
49 struct ip_conntrack_manip src
;
51 /* These are the parts of the tuple which are fixed. */
55 /* Add other protocols here. */
71 __be16 key
; /* key is 32bit,
72 * pptp only uses 16 */
79 /* The direction (for tuplehash) */
84 /* This is optimized opposed to a memset of the whole structure. Everything we
85 * really care about is the source/destination unions */
86 #define IP_CT_TUPLE_U_BLANK(tuple) \
88 (tuple)->src.u.all = 0; \
89 (tuple)->dst.u.all = 0; \
94 #define DUMP_TUPLE(tp) \
95 DEBUGP("tuple %p: %u %u.%u.%u.%u:%hu -> %u.%u.%u.%u:%hu\n", \
96 (tp), (tp)->dst.protonum, \
97 NIPQUAD((tp)->src.ip), ntohs((tp)->src.u.all), \
98 NIPQUAD((tp)->dst.ip), ntohs((tp)->dst.u.all))
100 /* If we're the first tuple, it's the original dir. */
101 #define DIRECTION(h) ((enum ip_conntrack_dir)(h)->tuple.dst.dir)
103 /* Connections have two entries in the hash table: one for each way */
104 struct ip_conntrack_tuple_hash
106 struct list_head list
;
108 struct ip_conntrack_tuple tuple
;
111 #endif /* __KERNEL__ */
113 static inline int ip_ct_tuple_src_equal(const struct ip_conntrack_tuple
*t1
,
114 const struct ip_conntrack_tuple
*t2
)
116 return t1
->src
.ip
== t2
->src
.ip
117 && t1
->src
.u
.all
== t2
->src
.u
.all
;
120 static inline int ip_ct_tuple_dst_equal(const struct ip_conntrack_tuple
*t1
,
121 const struct ip_conntrack_tuple
*t2
)
123 return t1
->dst
.ip
== t2
->dst
.ip
124 && t1
->dst
.u
.all
== t2
->dst
.u
.all
125 && t1
->dst
.protonum
== t2
->dst
.protonum
;
128 static inline int ip_ct_tuple_equal(const struct ip_conntrack_tuple
*t1
,
129 const struct ip_conntrack_tuple
*t2
)
131 return ip_ct_tuple_src_equal(t1
, t2
) && ip_ct_tuple_dst_equal(t1
, t2
);
134 static inline int ip_ct_tuple_mask_cmp(const struct ip_conntrack_tuple
*t
,
135 const struct ip_conntrack_tuple
*tuple
,
136 const struct ip_conntrack_tuple
*mask
)
138 return !(((t
->src
.ip
^ tuple
->src
.ip
) & mask
->src
.ip
)
139 || ((t
->dst
.ip
^ tuple
->dst
.ip
) & mask
->dst
.ip
)
140 || ((t
->src
.u
.all
^ tuple
->src
.u
.all
) & mask
->src
.u
.all
)
141 || ((t
->dst
.u
.all
^ tuple
->dst
.u
.all
) & mask
->dst
.u
.all
)
142 || ((t
->dst
.protonum
^ tuple
->dst
.protonum
)
143 & mask
->dst
.protonum
));
146 #endif /* _IP_CONNTRACK_TUPLE_H */