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. */
36 /* The manipulable part of the tuple. */
37 struct ip_conntrack_manip
40 union ip_conntrack_manip_proto u;
43 /* This contains the information to distinguish a connection. */
44 struct ip_conntrack_tuple
46 struct ip_conntrack_manip src;
48 /* These are the parts of the tuple which are fixed. */
52 /* Add other protocols here. */
79 /* This is optimized opposed to a memset of the whole structure. Everything we
80 * really care about is the source/destination unions */
81 #define IP_CT_TUPLE_U_BLANK(tuple) \
83 (tuple)->src.u.all = 0; \
84 (tuple)->dst.u.all = 0; \
96 #define DUMP_TUPLE(tp) \
97 DEBUGP("tuple %p: %u %u.%u.%u.%u:%u -> %u.%u.%u.%u:%u\n", \
98 (tp), (tp)->dst.protonum, \
99 NIPQUAD((tp)->src.ip), ntohl((tp)->src.u.all), \
100 NIPQUAD((tp)->dst.ip), ntohl((tp)->dst.u.all))
102 #define DUMP_TUPLE_RAW(x) \
103 DEBUGP("tuple %p: %u %u.%u.%u.%u:0x%08x -> %u.%u.%u.%u:0x%08x\n",\
104 (x), (x)->dst.protonum, \
105 NIPQUAD((x)->src.ip), ntohl((x)->src.u.all), \
106 NIPQUAD((x)->dst.ip), ntohl((x)->dst.u.all))
108 #define CTINFO2DIR(ctinfo) ((ctinfo) >= IP_CT_IS_REPLY ? IP_CT_DIR_REPLY : IP_CT_DIR_ORIGINAL)
110 /* If we're the first tuple, it's the original dir. */
111 #define DIRECTION(h) ((enum ip_conntrack_dir)(&(h)->ctrack->tuplehash[1] == (h)))
113 /* Connections have two entries in the hash table: one for each way */
114 struct ip_conntrack_tuple_hash
116 struct list_head list;
118 struct ip_conntrack_tuple tuple;
120 /* this == &ctrack->tuplehash[DIRECTION(this)]. */
121 struct ip_conntrack *ctrack;
124 #endif /* __KERNEL__ */
126 static inline int ip_ct_tuple_src_equal(const struct ip_conntrack_tuple *t1,
127 const struct ip_conntrack_tuple *t2)
129 return t1->src.ip == t2->src.ip
130 && t1->src.u.all == t2->src.u.all;
133 static inline int ip_ct_tuple_dst_equal(const struct ip_conntrack_tuple *t1,
134 const struct ip_conntrack_tuple *t2)
136 return t1->dst.ip == t2->dst.ip
137 && t1->dst.u.all == t2->dst.u.all
138 && t1->dst.protonum == t2->dst.protonum;
141 static inline int ip_ct_tuple_equal(const struct ip_conntrack_tuple *t1,
142 const struct ip_conntrack_tuple *t2)
144 return ip_ct_tuple_src_equal(t1, t2) && ip_ct_tuple_dst_equal(t1, t2);
147 static inline int ip_ct_tuple_mask_cmp(const struct ip_conntrack_tuple *t,
148 const struct ip_conntrack_tuple *tuple,
149 const struct ip_conntrack_tuple *mask)
151 return !(((t->src.ip ^ tuple->src.ip) & mask->src.ip)
152 || ((t->dst.ip ^ tuple->dst.ip) & mask->dst.ip)
153 || ((t->src.u.all ^ tuple->src.u.all) & mask->src.u.all)
154 || ((t->dst.u.all ^ tuple->dst.u.all) & mask->dst.u.all)
155 || ((t->dst.protonum ^ tuple->dst.protonum)
156 & mask->dst.protonum));
159 #endif /* _IP_CONNTRACK_TUPLE_H */