]>
git.ipfire.org Git - people/arne_f/kernel.git/blob - include/net/netfilter/nf_conntrack_tuple.h
1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Definitions and Declarations for tuple.
5 * 16 Dec 2003: Yasuyuki Kozakai @USAGI <yasuyuki.kozakai@toshiba.co.jp>
6 * - generalize L3 protocol dependent part.
8 * Derived from include/linux/netfiter_ipv4/ip_conntrack_tuple.h
11 #ifndef _NF_CONNTRACK_TUPLE_H
12 #define _NF_CONNTRACK_TUPLE_H
14 #include <linux/netfilter/x_tables.h>
15 #include <linux/netfilter/nf_conntrack_tuple_common.h>
16 #include <linux/list_nulls.h>
18 /* A `tuple' is a structure containing the information to uniquely
19 identify a connection. ie. if two packets have the same tuple, they
20 are in the same connection; if not, they are not.
22 We divide the structure along "manipulatable" and
23 "non-manipulatable" lines, for the benefit of the NAT code.
26 #define NF_CT_TUPLE_L3SIZE ARRAY_SIZE(((union nf_inet_addr *)NULL)->all)
28 /* The manipulable part of the tuple. */
29 struct nf_conntrack_man
{
30 union nf_inet_addr u3
;
31 union nf_conntrack_man_proto u
;
32 /* Layer 3 protocol */
36 /* This contains the information to distinguish a connection. */
37 struct nf_conntrack_tuple
{
38 struct nf_conntrack_man src
;
40 /* These are the parts of the tuple which are fixed. */
42 union nf_inet_addr u3
;
44 /* Add other protocols here. */
70 /* The direction (for tuplehash) */
75 struct nf_conntrack_tuple_mask
{
77 union nf_inet_addr u3
;
78 union nf_conntrack_man_proto u
;
82 static inline void nf_ct_dump_tuple_ip(const struct nf_conntrack_tuple
*t
)
85 printk("tuple %p: %u %pI4:%hu -> %pI4:%hu\n",
87 &t
->src
.u3
.ip
, ntohs(t
->src
.u
.all
),
88 &t
->dst
.u3
.ip
, ntohs(t
->dst
.u
.all
));
92 static inline void nf_ct_dump_tuple_ipv6(const struct nf_conntrack_tuple
*t
)
95 printk("tuple %p: %u %pI6 %hu -> %pI6 %hu\n",
97 t
->src
.u3
.all
, ntohs(t
->src
.u
.all
),
98 t
->dst
.u3
.all
, ntohs(t
->dst
.u
.all
));
102 static inline void nf_ct_dump_tuple(const struct nf_conntrack_tuple
*t
)
104 switch (t
->src
.l3num
) {
106 nf_ct_dump_tuple_ip(t
);
109 nf_ct_dump_tuple_ipv6(t
);
114 /* If we're the first tuple, it's the original dir. */
115 #define NF_CT_DIRECTION(h) \
116 ((enum ip_conntrack_dir)(h)->tuple.dst.dir)
118 /* Connections have two entries in the hash table: one for each way */
119 struct nf_conntrack_tuple_hash
{
120 struct hlist_nulls_node hnnode
;
121 struct nf_conntrack_tuple tuple
;
124 static inline bool __nf_ct_tuple_src_equal(const struct nf_conntrack_tuple
*t1
,
125 const struct nf_conntrack_tuple
*t2
)
127 return (nf_inet_addr_cmp(&t1
->src
.u3
, &t2
->src
.u3
) &&
128 t1
->src
.u
.all
== t2
->src
.u
.all
&&
129 t1
->src
.l3num
== t2
->src
.l3num
);
132 static inline bool __nf_ct_tuple_dst_equal(const struct nf_conntrack_tuple
*t1
,
133 const struct nf_conntrack_tuple
*t2
)
135 return (nf_inet_addr_cmp(&t1
->dst
.u3
, &t2
->dst
.u3
) &&
136 t1
->dst
.u
.all
== t2
->dst
.u
.all
&&
137 t1
->dst
.protonum
== t2
->dst
.protonum
);
140 static inline bool nf_ct_tuple_equal(const struct nf_conntrack_tuple
*t1
,
141 const struct nf_conntrack_tuple
*t2
)
143 return __nf_ct_tuple_src_equal(t1
, t2
) &&
144 __nf_ct_tuple_dst_equal(t1
, t2
);
148 nf_ct_tuple_mask_equal(const struct nf_conntrack_tuple_mask
*m1
,
149 const struct nf_conntrack_tuple_mask
*m2
)
151 return (nf_inet_addr_cmp(&m1
->src
.u3
, &m2
->src
.u3
) &&
152 m1
->src
.u
.all
== m2
->src
.u
.all
);
156 nf_ct_tuple_src_mask_cmp(const struct nf_conntrack_tuple
*t1
,
157 const struct nf_conntrack_tuple
*t2
,
158 const struct nf_conntrack_tuple_mask
*mask
)
162 for (count
= 0; count
< NF_CT_TUPLE_L3SIZE
; count
++) {
163 if ((t1
->src
.u3
.all
[count
] ^ t2
->src
.u3
.all
[count
]) &
164 mask
->src
.u3
.all
[count
])
168 if ((t1
->src
.u
.all
^ t2
->src
.u
.all
) & mask
->src
.u
.all
)
171 if (t1
->src
.l3num
!= t2
->src
.l3num
||
172 t1
->dst
.protonum
!= t2
->dst
.protonum
)
179 nf_ct_tuple_mask_cmp(const struct nf_conntrack_tuple
*t
,
180 const struct nf_conntrack_tuple
*tuple
,
181 const struct nf_conntrack_tuple_mask
*mask
)
183 return nf_ct_tuple_src_mask_cmp(t
, tuple
, mask
) &&
184 __nf_ct_tuple_dst_equal(t
, tuple
);
187 #endif /* _NF_CONNTRACK_TUPLE_H */