1 #ifndef _IP_CONNTRACK_TUPLE_H
2 #define _IP_CONNTRACK_TUPLE_H
4 #include <linux/types.h>
6 /* A `tuple' is a structure containing the information to uniquely
7 identify a connection. ie. if two packets have the same tuple, they
8 are in the same connection; if not, they are not.
10 We divide the structure along "manipulatable" and
11 "non-manipulatable" lines, for the benefit of the NAT code.
14 /* The protocol-specific manipulable parts of the tuple: always in
16 union ip_conntrack_manip_proto
18 /* Add other protocols here. */
34 __be16 key; /* key is 32bit, pptp only uses 16 */
38 /* The manipulable part of the tuple. */
39 struct ip_conntrack_manip
42 union ip_conntrack_manip_proto u;
45 /* This contains the information to distinguish a connection. */
46 struct ip_conntrack_tuple
48 struct ip_conntrack_manip src;
50 /* These are the parts of the tuple which are fixed. */
54 /* Add other protocols here. */
70 __be16 key; /* key is 32bit,
71 * pptp only uses 16 */
78 /* The direction (for tuplehash) */
83 /* This is optimized opposed to a memset of the whole structure. Everything we
84 * really care about is the source/destination unions */
85 #define IP_CT_TUPLE_U_BLANK(tuple) \
87 (tuple)->src.u.all = 0; \
88 (tuple)->dst.u.all = 0; \
100 #define DUMP_TUPLE(tp) \
101 DEBUGP("tuple %p: %u %u.%u.%u.%u:%hu -> %u.%u.%u.%u:%hu\n", \
102 (tp), (tp)->dst.protonum, \
103 NIPQUAD((tp)->src.ip), ntohs((tp)->src.u.all), \
104 NIPQUAD((tp)->dst.ip), ntohs((tp)->dst.u.all))
106 #define CTINFO2DIR(ctinfo) ((ctinfo) >= IP_CT_IS_REPLY ? IP_CT_DIR_REPLY : IP_CT_DIR_ORIGINAL)
108 /* If we're the first tuple, it's the original dir. */
109 #define DIRECTION(h) ((enum ip_conntrack_dir)(h)->tuple.dst.dir)
111 /* Connections have two entries in the hash table: one for each way */
112 struct ip_conntrack_tuple_hash
114 struct list_head list;
116 struct ip_conntrack_tuple tuple;
119 #endif /* __KERNEL__ */
121 static inline int ip_ct_tuple_src_equal(const struct ip_conntrack_tuple *t1,
122 const struct ip_conntrack_tuple *t2)
124 return t1->src.ip == t2->src.ip
125 && t1->src.u.all == t2->src.u.all;
128 static inline int ip_ct_tuple_dst_equal(const struct ip_conntrack_tuple *t1,
129 const struct ip_conntrack_tuple *t2)
131 return t1->dst.ip == t2->dst.ip
132 && t1->dst.u.all == t2->dst.u.all
133 && t1->dst.protonum == t2->dst.protonum;
136 static inline int ip_ct_tuple_equal(const struct ip_conntrack_tuple *t1,
137 const struct ip_conntrack_tuple *t2)
139 return ip_ct_tuple_src_equal(t1, t2) && ip_ct_tuple_dst_equal(t1, t2);
142 static inline int ip_ct_tuple_mask_cmp(const struct ip_conntrack_tuple *t,
143 const struct ip_conntrack_tuple *tuple,
144 const struct ip_conntrack_tuple *mask)
146 return !(((t->src.ip ^ tuple->src.ip) & mask->src.ip)
147 || ((t->dst.ip ^ tuple->dst.ip) & mask->dst.ip)
148 || ((t->src.u.all ^ tuple->src.u.all) & mask->src.u.all)
149 || ((t->dst.u.all ^ tuple->dst.u.all) & mask->dst.u.all)
150 || ((t->dst.protonum ^ tuple->dst.protonum)
151 & mask->dst.protonum));
154 #endif /* _IP_CONNTRACK_TUPLE_H */