1 #ifndef _IP_CONNTRACK_TUPLE_H
2 #define _IP_CONNTRACK_TUPLE_H
4 /* A `tuple' is a structure containing the information to uniquely
5 identify a connection. ie. if two packets have the same tuple, they
6 are in the same connection; if not, they are not.
8 We divide the structure along "manipulatable" and
9 "non-manipulatable" lines, for the benefit of the NAT code.
12 /* The protocol-specific manipulable parts of the tuple: always in
14 union ip_conntrack_manip_proto
16 /* Add other protocols here. */
30 /* The manipulable part of the tuple. */
31 struct ip_conntrack_manip
34 union ip_conntrack_manip_proto u;
37 /* This contains the information to distinguish a connection. */
38 struct ip_conntrack_tuple
40 struct ip_conntrack_manip src;
42 /* These are the parts of the tuple which are fixed. */
46 /* Add other protocols here. */
65 /* This is optimized opposed to a memset of the whole structure. Everything we
66 * really care about is the source/destination unions */
67 #define IP_CT_TUPLE_U_BLANK(tuple) \
69 (tuple)->src.u.all = 0; \
70 (tuple)->dst.u.all = 0; \
82 #define DUMP_TUPLE(tp) \
83 DEBUGP("tuple %p: %u %u.%u.%u.%u:%hu -> %u.%u.%u.%u:%hu\n", \
84 (tp), (tp)->dst.protonum, \
85 NIPQUAD((tp)->src.ip), ntohs((tp)->src.u.all), \
86 NIPQUAD((tp)->dst.ip), ntohs((tp)->dst.u.all))
88 #define CTINFO2DIR(ctinfo) ((ctinfo) >= IP_CT_IS_REPLY ? IP_CT_DIR_REPLY : IP_CT_DIR_ORIGINAL)
90 /* If we're the first tuple, it's the original dir. */
91 #define DIRECTION(h) ((enum ip_conntrack_dir)(&(h)->ctrack->tuplehash[1] == (h)))
93 /* Connections have two entries in the hash table: one for each way */
94 struct ip_conntrack_tuple_hash
96 struct list_head list;
98 struct ip_conntrack_tuple tuple;
100 /* this == &ctrack->tuplehash[DIRECTION(this)]. */
101 struct ip_conntrack *ctrack;
104 #endif /* __KERNEL__ */
106 static inline int ip_ct_tuple_src_equal(const struct ip_conntrack_tuple *t1,
107 const struct ip_conntrack_tuple *t2)
109 return t1->src.ip == t2->src.ip
110 && t1->src.u.all == t2->src.u.all;
113 static inline int ip_ct_tuple_dst_equal(const struct ip_conntrack_tuple *t1,
114 const struct ip_conntrack_tuple *t2)
116 return t1->dst.ip == t2->dst.ip
117 && t1->dst.u.all == t2->dst.u.all
118 && t1->dst.protonum == t2->dst.protonum;
121 static inline int ip_ct_tuple_equal(const struct ip_conntrack_tuple *t1,
122 const struct ip_conntrack_tuple *t2)
124 return ip_ct_tuple_src_equal(t1, t2) && ip_ct_tuple_dst_equal(t1, t2);
127 static inline int ip_ct_tuple_mask_cmp(const struct ip_conntrack_tuple *t,
128 const struct ip_conntrack_tuple *tuple,
129 const struct ip_conntrack_tuple *mask)
131 return !(((t->src.ip ^ tuple->src.ip) & mask->src.ip)
132 || ((t->dst.ip ^ tuple->dst.ip) & mask->dst.ip)
133 || ((t->src.u.all ^ tuple->src.u.all) & mask->src.u.all)
134 || ((t->dst.u.all ^ tuple->dst.u.all) & mask->dst.u.all)
135 || ((t->dst.protonum ^ tuple->dst.protonum)
136 & mask->dst.protonum));
139 #endif /* _IP_CONNTRACK_TUPLE_H */