1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _NET_FLOW_DISSECTOR_H
3 #define _NET_FLOW_DISSECTOR_H
5 #include <linux/types.h>
7 #include <uapi/linux/if_ether.h>
10 * struct flow_dissector_key_control:
11 * @thoff: Transport header offset
13 struct flow_dissector_key_control
{
19 #define FLOW_DIS_IS_FRAGMENT BIT(0)
20 #define FLOW_DIS_FIRST_FRAG BIT(1)
21 #define FLOW_DIS_ENCAPSULATION BIT(2)
23 enum flow_dissect_ret
{
24 FLOW_DISSECT_RET_OUT_GOOD
,
25 FLOW_DISSECT_RET_OUT_BAD
,
26 FLOW_DISSECT_RET_PROTO_AGAIN
,
27 FLOW_DISSECT_RET_IPPROTO_AGAIN
,
28 FLOW_DISSECT_RET_CONTINUE
,
32 * struct flow_dissector_key_basic:
33 * @thoff: Transport header offset
34 * @n_proto: Network header protocol (eg. IPv4/IPv6)
35 * @ip_proto: Transport header protocol (eg. TCP/UDP)
37 struct flow_dissector_key_basic
{
43 struct flow_dissector_key_tags
{
47 struct flow_dissector_key_vlan
{
53 struct flow_dissector_key_mpls
{
60 struct flow_dissector_key_keyid
{
65 * struct flow_dissector_key_ipv4_addrs:
66 * @src: source ip address
67 * @dst: destination ip address
69 struct flow_dissector_key_ipv4_addrs
{
70 /* (src,dst) must be grouped, in the same way than in IP header */
76 * struct flow_dissector_key_ipv6_addrs:
77 * @src: source ip address
78 * @dst: destination ip address
80 struct flow_dissector_key_ipv6_addrs
{
81 /* (src,dst) must be grouped, in the same way than in IP header */
87 * struct flow_dissector_key_tipc_addrs:
88 * @srcnode: source node address
90 struct flow_dissector_key_tipc_addrs
{
95 * struct flow_dissector_key_addrs:
96 * @v4addrs: IPv4 addresses
97 * @v6addrs: IPv6 addresses
99 struct flow_dissector_key_addrs
{
101 struct flow_dissector_key_ipv4_addrs v4addrs
;
102 struct flow_dissector_key_ipv6_addrs v6addrs
;
103 struct flow_dissector_key_tipc_addrs tipcaddrs
;
108 * flow_dissector_key_arp:
109 * @ports: Operation, source and target addresses for an ARP header
110 * for Ethernet hardware addresses and IPv4 protocol addresses
111 * sip: Sender IP address
112 * tip: Target IP address
114 * sha: Sender hardware address
115 * tpa: Target hardware address
117 struct flow_dissector_key_arp
{
121 unsigned char sha
[ETH_ALEN
];
122 unsigned char tha
[ETH_ALEN
];
126 * flow_dissector_key_tp_ports:
127 * @ports: port numbers of Transport header
128 * src: source port number
129 * dst: destination port number
131 struct flow_dissector_key_ports
{
142 * flow_dissector_key_icmp:
143 * @ports: type and code of ICMP header
144 * icmp: ICMP type (high) and code (low)
148 struct flow_dissector_key_icmp
{
159 * struct flow_dissector_key_eth_addrs:
160 * @src: source Ethernet address
161 * @dst: destination Ethernet address
163 struct flow_dissector_key_eth_addrs
{
164 /* (dst,src) must be grouped, in the same way than in ETH header */
165 unsigned char dst
[ETH_ALEN
];
166 unsigned char src
[ETH_ALEN
];
170 * struct flow_dissector_key_tcp:
173 struct flow_dissector_key_tcp
{
178 * struct flow_dissector_key_ip:
182 struct flow_dissector_key_ip
{
187 enum flow_dissector_key_id
{
188 FLOW_DISSECTOR_KEY_CONTROL
, /* struct flow_dissector_key_control */
189 FLOW_DISSECTOR_KEY_BASIC
, /* struct flow_dissector_key_basic */
190 FLOW_DISSECTOR_KEY_IPV4_ADDRS
, /* struct flow_dissector_key_ipv4_addrs */
191 FLOW_DISSECTOR_KEY_IPV6_ADDRS
, /* struct flow_dissector_key_ipv6_addrs */
192 FLOW_DISSECTOR_KEY_PORTS
, /* struct flow_dissector_key_ports */
193 FLOW_DISSECTOR_KEY_ICMP
, /* struct flow_dissector_key_icmp */
194 FLOW_DISSECTOR_KEY_ETH_ADDRS
, /* struct flow_dissector_key_eth_addrs */
195 FLOW_DISSECTOR_KEY_TIPC_ADDRS
, /* struct flow_dissector_key_tipc_addrs */
196 FLOW_DISSECTOR_KEY_ARP
, /* struct flow_dissector_key_arp */
197 FLOW_DISSECTOR_KEY_VLAN
, /* struct flow_dissector_key_flow_vlan */
198 FLOW_DISSECTOR_KEY_FLOW_LABEL
, /* struct flow_dissector_key_flow_tags */
199 FLOW_DISSECTOR_KEY_GRE_KEYID
, /* struct flow_dissector_key_keyid */
200 FLOW_DISSECTOR_KEY_MPLS_ENTROPY
, /* struct flow_dissector_key_keyid */
201 FLOW_DISSECTOR_KEY_ENC_KEYID
, /* struct flow_dissector_key_keyid */
202 FLOW_DISSECTOR_KEY_ENC_IPV4_ADDRS
, /* struct flow_dissector_key_ipv4_addrs */
203 FLOW_DISSECTOR_KEY_ENC_IPV6_ADDRS
, /* struct flow_dissector_key_ipv6_addrs */
204 FLOW_DISSECTOR_KEY_ENC_CONTROL
, /* struct flow_dissector_key_control */
205 FLOW_DISSECTOR_KEY_ENC_PORTS
, /* struct flow_dissector_key_ports */
206 FLOW_DISSECTOR_KEY_MPLS
, /* struct flow_dissector_key_mpls */
207 FLOW_DISSECTOR_KEY_TCP
, /* struct flow_dissector_key_tcp */
208 FLOW_DISSECTOR_KEY_IP
, /* struct flow_dissector_key_ip */
210 FLOW_DISSECTOR_KEY_MAX
,
213 #define FLOW_DISSECTOR_F_PARSE_1ST_FRAG BIT(0)
214 #define FLOW_DISSECTOR_F_STOP_AT_L3 BIT(1)
215 #define FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL BIT(2)
216 #define FLOW_DISSECTOR_F_STOP_AT_ENCAP BIT(3)
218 struct flow_dissector_key
{
219 enum flow_dissector_key_id key_id
;
220 size_t offset
; /* offset of struct flow_dissector_key_*
221 in target the struct */
224 struct flow_dissector
{
225 unsigned int used_keys
; /* each bit repesents presence of one key id */
226 unsigned short int offset
[FLOW_DISSECTOR_KEY_MAX
];
230 struct flow_dissector_key_control control
;
231 #define FLOW_KEYS_HASH_START_FIELD basic
232 struct flow_dissector_key_basic basic
;
233 struct flow_dissector_key_tags tags
;
234 struct flow_dissector_key_vlan vlan
;
235 struct flow_dissector_key_keyid keyid
;
236 struct flow_dissector_key_ports ports
;
237 struct flow_dissector_key_addrs addrs
;
240 #define FLOW_KEYS_HASH_OFFSET \
241 offsetof(struct flow_keys, FLOW_KEYS_HASH_START_FIELD)
243 __be32
flow_get_u32_src(const struct flow_keys
*flow
);
244 __be32
flow_get_u32_dst(const struct flow_keys
*flow
);
246 extern struct flow_dissector flow_keys_dissector
;
247 extern struct flow_dissector flow_keys_buf_dissector
;
249 /* struct flow_keys_digest:
251 * This structure is used to hold a digest of the full flow keys. This is a
252 * larger "hash" of a flow to allow definitively matching specific flows where
253 * the 32 bit skb->hash is not large enough. The size is limited to 16 bytes so
254 * that it can by used in CB of skb (see sch_choke for an example).
256 #define FLOW_KEYS_DIGEST_LEN 16
257 struct flow_keys_digest
{
258 u8 data
[FLOW_KEYS_DIGEST_LEN
];
261 void make_flow_keys_digest(struct flow_keys_digest
*digest
,
262 const struct flow_keys
*flow
);
264 static inline bool flow_keys_have_l4(const struct flow_keys
*keys
)
266 return (keys
->ports
.ports
|| keys
->tags
.flow_label
);
269 u32
flow_hash_from_keys(struct flow_keys
*keys
);
271 static inline bool dissector_uses_key(const struct flow_dissector
*flow_dissector
,
272 enum flow_dissector_key_id key_id
)
274 return flow_dissector
->used_keys
& (1 << key_id
);
277 static inline void *skb_flow_dissector_target(struct flow_dissector
*flow_dissector
,
278 enum flow_dissector_key_id key_id
,
279 void *target_container
)
281 return ((char *)target_container
) + flow_dissector
->offset
[key_id
];