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>
15 #include <linux/list_nulls.h>
17 /* A `tuple' is a structure containing the information to uniquely
18 identify a connection. ie. if two packets have the same tuple, they
19 are in the same connection; if not, they are not.
21 We divide the structure along "manipulatable" and
22 "non-manipulatable" lines, for the benefit of the NAT code.
25 #define NF_CT_TUPLE_L3SIZE ARRAY_SIZE(((union nf_inet_addr *)NULL)->all)
27 /* The manipulable part of the tuple. */
28 struct nf_conntrack_man
{
29 union nf_inet_addr u3
;
30 union nf_conntrack_man_proto u
;
31 /* Layer 3 protocol */
35 /* This contains the information to distinguish a connection. */
36 struct nf_conntrack_tuple
{
37 struct nf_conntrack_man src
;
39 /* These are the parts of the tuple which are fixed. */
41 union nf_inet_addr u3
;
43 /* Add other protocols here. */
69 /* The direction (for tuplehash) */
74 struct nf_conntrack_tuple_mask
{
76 union nf_inet_addr u3
;
77 union nf_conntrack_man_proto u
;
81 static inline void nf_ct_dump_tuple_ip(const struct nf_conntrack_tuple
*t
)
84 printk("tuple %p: %u %pI4:%hu -> %pI4:%hu\n",
86 &t
->src
.u3
.ip
, ntohs(t
->src
.u
.all
),
87 &t
->dst
.u3
.ip
, ntohs(t
->dst
.u
.all
));
91 static inline void nf_ct_dump_tuple_ipv6(const struct nf_conntrack_tuple
*t
)
94 printk("tuple %p: %u %pI6 %hu -> %pI6 %hu\n",
96 t
->src
.u3
.all
, ntohs(t
->src
.u
.all
),
97 t
->dst
.u3
.all
, ntohs(t
->dst
.u
.all
));
101 static inline void nf_ct_dump_tuple(const struct nf_conntrack_tuple
*t
)
103 switch (t
->src
.l3num
) {
105 nf_ct_dump_tuple_ip(t
);
108 nf_ct_dump_tuple_ipv6(t
);
113 /* If we're the first tuple, it's the original dir. */
114 #define NF_CT_DIRECTION(h) \
115 ((enum ip_conntrack_dir)(h)->tuple.dst.dir)
117 /* Connections have two entries in the hash table: one for each way */
118 struct nf_conntrack_tuple_hash
{
119 struct hlist_nulls_node hnnode
;
120 struct nf_conntrack_tuple tuple
;
123 static inline bool __nf_ct_tuple_src_equal(const struct nf_conntrack_tuple
*t1
,
124 const struct nf_conntrack_tuple
*t2
)
126 return (nf_inet_addr_cmp(&t1
->src
.u3
, &t2
->src
.u3
) &&
127 t1
->src
.u
.all
== t2
->src
.u
.all
&&
128 t1
->src
.l3num
== t2
->src
.l3num
);
131 static inline bool __nf_ct_tuple_dst_equal(const struct nf_conntrack_tuple
*t1
,
132 const struct nf_conntrack_tuple
*t2
)
134 return (nf_inet_addr_cmp(&t1
->dst
.u3
, &t2
->dst
.u3
) &&
135 t1
->dst
.u
.all
== t2
->dst
.u
.all
&&
136 t1
->dst
.protonum
== t2
->dst
.protonum
);
139 static inline bool nf_ct_tuple_equal(const struct nf_conntrack_tuple
*t1
,
140 const struct nf_conntrack_tuple
*t2
)
142 return __nf_ct_tuple_src_equal(t1
, t2
) &&
143 __nf_ct_tuple_dst_equal(t1
, t2
);
147 nf_ct_tuple_mask_equal(const struct nf_conntrack_tuple_mask
*m1
,
148 const struct nf_conntrack_tuple_mask
*m2
)
150 return (nf_inet_addr_cmp(&m1
->src
.u3
, &m2
->src
.u3
) &&
151 m1
->src
.u
.all
== m2
->src
.u
.all
);
155 nf_ct_tuple_src_mask_cmp(const struct nf_conntrack_tuple
*t1
,
156 const struct nf_conntrack_tuple
*t2
,
157 const struct nf_conntrack_tuple_mask
*mask
)
161 for (count
= 0; count
< NF_CT_TUPLE_L3SIZE
; count
++) {
162 if ((t1
->src
.u3
.all
[count
] ^ t2
->src
.u3
.all
[count
]) &
163 mask
->src
.u3
.all
[count
])
167 if ((t1
->src
.u
.all
^ t2
->src
.u
.all
) & mask
->src
.u
.all
)
170 if (t1
->src
.l3num
!= t2
->src
.l3num
||
171 t1
->dst
.protonum
!= t2
->dst
.protonum
)
178 nf_ct_tuple_mask_cmp(const struct nf_conntrack_tuple
*t
,
179 const struct nf_conntrack_tuple
*tuple
,
180 const struct nf_conntrack_tuple_mask
*mask
)
182 return nf_ct_tuple_src_mask_cmp(t
, tuple
, mask
) &&
183 __nf_ct_tuple_dst_equal(t
, tuple
);
186 #endif /* _NF_CONNTRACK_TUPLE_H */
This page took 0.035281 seconds and 5 git commands to generate.