1 #ifndef _NET_FLOW_DISSECTOR_H
2 #define _NET_FLOW_DISSECTOR_H
4 #include <linux/types.h>
6 #include <uapi/linux/if_ether.h>
9 * struct flow_dissector_key_control:
10 * @thoff: Transport header offset
12 struct flow_dissector_key_control
{
18 #define FLOW_DIS_IS_FRAGMENT BIT(0)
19 #define FLOW_DIS_FIRST_FRAG BIT(1)
20 #define FLOW_DIS_ENCAPSULATION BIT(2)
23 * struct flow_dissector_key_basic:
24 * @thoff: Transport header offset
25 * @n_proto: Network header protocol (eg. IPv4/IPv6)
26 * @ip_proto: Transport header protocol (eg. TCP/UDP)
28 struct flow_dissector_key_basic
{
34 struct flow_dissector_key_tags
{
38 struct flow_dissector_key_vlan
{
44 struct flow_dissector_key_mpls
{
51 struct flow_dissector_key_keyid
{
56 * struct flow_dissector_key_ipv4_addrs:
57 * @src: source ip address
58 * @dst: destination ip address
60 struct flow_dissector_key_ipv4_addrs
{
61 /* (src,dst) must be grouped, in the same way than in IP header */
67 * struct flow_dissector_key_ipv6_addrs:
68 * @src: source ip address
69 * @dst: destination ip address
71 struct flow_dissector_key_ipv6_addrs
{
72 /* (src,dst) must be grouped, in the same way than in IP header */
78 * struct flow_dissector_key_tipc_addrs:
79 * @srcnode: source node address
81 struct flow_dissector_key_tipc_addrs
{
86 * struct flow_dissector_key_addrs:
87 * @v4addrs: IPv4 addresses
88 * @v6addrs: IPv6 addresses
90 struct flow_dissector_key_addrs
{
92 struct flow_dissector_key_ipv4_addrs v4addrs
;
93 struct flow_dissector_key_ipv6_addrs v6addrs
;
94 struct flow_dissector_key_tipc_addrs tipcaddrs
;
99 * flow_dissector_key_arp:
100 * @ports: Operation, source and target addresses for an ARP header
101 * for Ethernet hardware addresses and IPv4 protocol addresses
102 * sip: Sender IP address
103 * tip: Target IP address
105 * sha: Sender hardware address
106 * tpa: Target hardware address
108 struct flow_dissector_key_arp
{
112 unsigned char sha
[ETH_ALEN
];
113 unsigned char tha
[ETH_ALEN
];
117 * flow_dissector_key_tp_ports:
118 * @ports: port numbers of Transport header
119 * src: source port number
120 * dst: destination port number
122 struct flow_dissector_key_ports
{
133 * flow_dissector_key_icmp:
134 * @ports: type and code of ICMP header
135 * icmp: ICMP type (high) and code (low)
139 struct flow_dissector_key_icmp
{
150 * struct flow_dissector_key_eth_addrs:
151 * @src: source Ethernet address
152 * @dst: destination Ethernet address
154 struct flow_dissector_key_eth_addrs
{
155 /* (dst,src) must be grouped, in the same way than in ETH header */
156 unsigned char dst
[ETH_ALEN
];
157 unsigned char src
[ETH_ALEN
];
161 * struct flow_dissector_key_tcp:
164 struct flow_dissector_key_tcp
{
169 * struct flow_dissector_key_ip:
173 struct flow_dissector_key_ip
{
178 enum flow_dissector_key_id
{
179 FLOW_DISSECTOR_KEY_CONTROL
, /* struct flow_dissector_key_control */
180 FLOW_DISSECTOR_KEY_BASIC
, /* struct flow_dissector_key_basic */
181 FLOW_DISSECTOR_KEY_IPV4_ADDRS
, /* struct flow_dissector_key_ipv4_addrs */
182 FLOW_DISSECTOR_KEY_IPV6_ADDRS
, /* struct flow_dissector_key_ipv6_addrs */
183 FLOW_DISSECTOR_KEY_PORTS
, /* struct flow_dissector_key_ports */
184 FLOW_DISSECTOR_KEY_ICMP
, /* struct flow_dissector_key_icmp */
185 FLOW_DISSECTOR_KEY_ETH_ADDRS
, /* struct flow_dissector_key_eth_addrs */
186 FLOW_DISSECTOR_KEY_TIPC_ADDRS
, /* struct flow_dissector_key_tipc_addrs */
187 FLOW_DISSECTOR_KEY_ARP
, /* struct flow_dissector_key_arp */
188 FLOW_DISSECTOR_KEY_VLAN
, /* struct flow_dissector_key_flow_vlan */
189 FLOW_DISSECTOR_KEY_FLOW_LABEL
, /* struct flow_dissector_key_flow_tags */
190 FLOW_DISSECTOR_KEY_GRE_KEYID
, /* struct flow_dissector_key_keyid */
191 FLOW_DISSECTOR_KEY_MPLS_ENTROPY
, /* struct flow_dissector_key_keyid */
192 FLOW_DISSECTOR_KEY_ENC_KEYID
, /* struct flow_dissector_key_keyid */
193 FLOW_DISSECTOR_KEY_ENC_IPV4_ADDRS
, /* struct flow_dissector_key_ipv4_addrs */
194 FLOW_DISSECTOR_KEY_ENC_IPV6_ADDRS
, /* struct flow_dissector_key_ipv6_addrs */
195 FLOW_DISSECTOR_KEY_ENC_CONTROL
, /* struct flow_dissector_key_control */
196 FLOW_DISSECTOR_KEY_ENC_PORTS
, /* struct flow_dissector_key_ports */
197 FLOW_DISSECTOR_KEY_MPLS
, /* struct flow_dissector_key_mpls */
198 FLOW_DISSECTOR_KEY_TCP
, /* struct flow_dissector_key_tcp */
199 FLOW_DISSECTOR_KEY_IP
, /* struct flow_dissector_key_ip */
201 FLOW_DISSECTOR_KEY_MAX
,
204 #define FLOW_DISSECTOR_F_PARSE_1ST_FRAG BIT(0)
205 #define FLOW_DISSECTOR_F_STOP_AT_L3 BIT(1)
206 #define FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL BIT(2)
207 #define FLOW_DISSECTOR_F_STOP_AT_ENCAP BIT(3)
209 struct flow_dissector_key
{
210 enum flow_dissector_key_id key_id
;
211 size_t offset
; /* offset of struct flow_dissector_key_*
212 in target the struct */
215 struct flow_dissector
{
216 unsigned int used_keys
; /* each bit repesents presence of one key id */
217 unsigned short int offset
[FLOW_DISSECTOR_KEY_MAX
];
221 struct flow_dissector_key_control control
;
222 #define FLOW_KEYS_HASH_START_FIELD basic
223 struct flow_dissector_key_basic basic
;
224 struct flow_dissector_key_tags tags
;
225 struct flow_dissector_key_vlan vlan
;
226 struct flow_dissector_key_keyid keyid
;
227 struct flow_dissector_key_ports ports
;
228 struct flow_dissector_key_addrs addrs
;
231 #define FLOW_KEYS_HASH_OFFSET \
232 offsetof(struct flow_keys, FLOW_KEYS_HASH_START_FIELD)
234 __be32
flow_get_u32_src(const struct flow_keys
*flow
);
235 __be32
flow_get_u32_dst(const struct flow_keys
*flow
);
237 extern struct flow_dissector flow_keys_dissector
;
238 extern struct flow_dissector flow_keys_buf_dissector
;
240 /* struct flow_keys_digest:
242 * This structure is used to hold a digest of the full flow keys. This is a
243 * larger "hash" of a flow to allow definitively matching specific flows where
244 * the 32 bit skb->hash is not large enough. The size is limited to 16 bytes so
245 * that it can by used in CB of skb (see sch_choke for an example).
247 #define FLOW_KEYS_DIGEST_LEN 16
248 struct flow_keys_digest
{
249 u8 data
[FLOW_KEYS_DIGEST_LEN
];
252 void make_flow_keys_digest(struct flow_keys_digest
*digest
,
253 const struct flow_keys
*flow
);
255 static inline bool flow_keys_have_l4(const struct flow_keys
*keys
)
257 return (keys
->ports
.ports
|| keys
->tags
.flow_label
);
260 u32
flow_hash_from_keys(struct flow_keys
*keys
);
262 static inline bool dissector_uses_key(const struct flow_dissector
*flow_dissector
,
263 enum flow_dissector_key_id key_id
)
265 return flow_dissector
->used_keys
& (1 << key_id
);
268 static inline void *skb_flow_dissector_target(struct flow_dissector
*flow_dissector
,
269 enum flow_dissector_key_id key_id
,
270 void *target_container
)
272 return ((char *)target_container
) + flow_dissector
->offset
[key_id
];