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_keyid
{
49 * struct flow_dissector_key_ipv4_addrs:
50 * @src: source ip address
51 * @dst: destination ip address
53 struct flow_dissector_key_ipv4_addrs
{
54 /* (src,dst) must be grouped, in the same way than in IP header */
60 * struct flow_dissector_key_ipv6_addrs:
61 * @src: source ip address
62 * @dst: destination ip address
64 struct flow_dissector_key_ipv6_addrs
{
65 /* (src,dst) must be grouped, in the same way than in IP header */
71 * struct flow_dissector_key_tipc_addrs:
72 * @srcnode: source node address
74 struct flow_dissector_key_tipc_addrs
{
79 * struct flow_dissector_key_addrs:
80 * @v4addrs: IPv4 addresses
81 * @v6addrs: IPv6 addresses
83 struct flow_dissector_key_addrs
{
85 struct flow_dissector_key_ipv4_addrs v4addrs
;
86 struct flow_dissector_key_ipv6_addrs v6addrs
;
87 struct flow_dissector_key_tipc_addrs tipcaddrs
;
92 * flow_dissector_key_tp_ports:
93 * @ports: port numbers of Transport header
94 * src: source port number
95 * dst: destination port number
97 struct flow_dissector_key_ports
{
108 * flow_dissector_key_icmp:
109 * @ports: type and code of ICMP header
110 * icmp: ICMP type (high) and code (low)
114 struct flow_dissector_key_icmp
{
125 * struct flow_dissector_key_eth_addrs:
126 * @src: source Ethernet address
127 * @dst: destination Ethernet address
129 struct flow_dissector_key_eth_addrs
{
130 /* (dst,src) must be grouped, in the same way than in ETH header */
131 unsigned char dst
[ETH_ALEN
];
132 unsigned char src
[ETH_ALEN
];
135 enum flow_dissector_key_id
{
136 FLOW_DISSECTOR_KEY_CONTROL
, /* struct flow_dissector_key_control */
137 FLOW_DISSECTOR_KEY_BASIC
, /* struct flow_dissector_key_basic */
138 FLOW_DISSECTOR_KEY_IPV4_ADDRS
, /* struct flow_dissector_key_ipv4_addrs */
139 FLOW_DISSECTOR_KEY_IPV6_ADDRS
, /* struct flow_dissector_key_ipv6_addrs */
140 FLOW_DISSECTOR_KEY_PORTS
, /* struct flow_dissector_key_ports */
141 FLOW_DISSECTOR_KEY_ICMP
, /* struct flow_dissector_key_icmp */
142 FLOW_DISSECTOR_KEY_ETH_ADDRS
, /* struct flow_dissector_key_eth_addrs */
143 FLOW_DISSECTOR_KEY_TIPC_ADDRS
, /* struct flow_dissector_key_tipc_addrs */
144 FLOW_DISSECTOR_KEY_VLAN
, /* struct flow_dissector_key_flow_vlan */
145 FLOW_DISSECTOR_KEY_FLOW_LABEL
, /* struct flow_dissector_key_flow_tags */
146 FLOW_DISSECTOR_KEY_GRE_KEYID
, /* struct flow_dissector_key_keyid */
147 FLOW_DISSECTOR_KEY_MPLS_ENTROPY
, /* struct flow_dissector_key_keyid */
148 FLOW_DISSECTOR_KEY_ENC_KEYID
, /* struct flow_dissector_key_keyid */
149 FLOW_DISSECTOR_KEY_ENC_IPV4_ADDRS
, /* struct flow_dissector_key_ipv4_addrs */
150 FLOW_DISSECTOR_KEY_ENC_IPV6_ADDRS
, /* struct flow_dissector_key_ipv6_addrs */
151 FLOW_DISSECTOR_KEY_ENC_CONTROL
, /* struct flow_dissector_key_control */
152 FLOW_DISSECTOR_KEY_ENC_PORTS
, /* struct flow_dissector_key_ports */
154 FLOW_DISSECTOR_KEY_MAX
,
157 #define FLOW_DISSECTOR_F_PARSE_1ST_FRAG BIT(0)
158 #define FLOW_DISSECTOR_F_STOP_AT_L3 BIT(1)
159 #define FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL BIT(2)
160 #define FLOW_DISSECTOR_F_STOP_AT_ENCAP BIT(3)
162 struct flow_dissector_key
{
163 enum flow_dissector_key_id key_id
;
164 size_t offset
; /* offset of struct flow_dissector_key_*
165 in target the struct */
168 struct flow_dissector
{
169 unsigned int used_keys
; /* each bit repesents presence of one key id */
170 unsigned short int offset
[FLOW_DISSECTOR_KEY_MAX
];
174 struct flow_dissector_key_control control
;
175 #define FLOW_KEYS_HASH_START_FIELD basic
176 struct flow_dissector_key_basic basic
;
177 struct flow_dissector_key_tags tags
;
178 struct flow_dissector_key_vlan vlan
;
179 struct flow_dissector_key_keyid keyid
;
180 struct flow_dissector_key_ports ports
;
181 struct flow_dissector_key_addrs addrs
;
184 #define FLOW_KEYS_HASH_OFFSET \
185 offsetof(struct flow_keys, FLOW_KEYS_HASH_START_FIELD)
187 __be32
flow_get_u32_src(const struct flow_keys
*flow
);
188 __be32
flow_get_u32_dst(const struct flow_keys
*flow
);
190 extern struct flow_dissector flow_keys_dissector
;
191 extern struct flow_dissector flow_keys_buf_dissector
;
193 /* struct flow_keys_digest:
195 * This structure is used to hold a digest of the full flow keys. This is a
196 * larger "hash" of a flow to allow definitively matching specific flows where
197 * the 32 bit skb->hash is not large enough. The size is limited to 16 bytes so
198 * that it can by used in CB of skb (see sch_choke for an example).
200 #define FLOW_KEYS_DIGEST_LEN 16
201 struct flow_keys_digest
{
202 u8 data
[FLOW_KEYS_DIGEST_LEN
];
205 void make_flow_keys_digest(struct flow_keys_digest
*digest
,
206 const struct flow_keys
*flow
);
208 static inline bool flow_keys_have_l4(const struct flow_keys
*keys
)
210 return (keys
->ports
.ports
|| keys
->tags
.flow_label
);
213 u32
flow_hash_from_keys(struct flow_keys
*keys
);
215 static inline bool dissector_uses_key(const struct flow_dissector
*flow_dissector
,
216 enum flow_dissector_key_id key_id
)
218 return flow_dissector
->used_keys
& (1 << key_id
);
221 static inline void *skb_flow_dissector_target(struct flow_dissector
*flow_dissector
,
222 enum flow_dissector_key_id key_id
,
223 void *target_container
)
225 return ((char *)target_container
) + flow_dissector
->offset
[key_id
];