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
{
39 struct flow_dissector_key_keyid
{
44 * struct flow_dissector_key_ipv4_addrs:
45 * @src: source ip address
46 * @dst: destination ip address
48 struct flow_dissector_key_ipv4_addrs
{
49 /* (src,dst) must be grouped, in the same way than in IP header */
55 * struct flow_dissector_key_ipv6_addrs:
56 * @src: source ip address
57 * @dst: destination ip address
59 struct flow_dissector_key_ipv6_addrs
{
60 /* (src,dst) must be grouped, in the same way than in IP header */
66 * struct flow_dissector_key_tipc_addrs:
67 * @srcnode: source node address
69 struct flow_dissector_key_tipc_addrs
{
74 * struct flow_dissector_key_addrs:
75 * @v4addrs: IPv4 addresses
76 * @v6addrs: IPv6 addresses
78 struct flow_dissector_key_addrs
{
80 struct flow_dissector_key_ipv4_addrs v4addrs
;
81 struct flow_dissector_key_ipv6_addrs v6addrs
;
82 struct flow_dissector_key_tipc_addrs tipcaddrs
;
87 * flow_dissector_key_tp_ports:
88 * @ports: port numbers of Transport header
89 * src: source port number
90 * dst: destination port number
92 struct flow_dissector_key_ports
{
104 * struct flow_dissector_key_eth_addrs:
105 * @src: source Ethernet address
106 * @dst: destination Ethernet address
108 struct flow_dissector_key_eth_addrs
{
109 /* (dst,src) must be grouped, in the same way than in ETH header */
110 unsigned char dst
[ETH_ALEN
];
111 unsigned char src
[ETH_ALEN
];
114 enum flow_dissector_key_id
{
115 FLOW_DISSECTOR_KEY_CONTROL
, /* struct flow_dissector_key_control */
116 FLOW_DISSECTOR_KEY_BASIC
, /* struct flow_dissector_key_basic */
117 FLOW_DISSECTOR_KEY_IPV4_ADDRS
, /* struct flow_dissector_key_ipv4_addrs */
118 FLOW_DISSECTOR_KEY_IPV6_ADDRS
, /* struct flow_dissector_key_ipv6_addrs */
119 FLOW_DISSECTOR_KEY_PORTS
, /* struct flow_dissector_key_ports */
120 FLOW_DISSECTOR_KEY_ETH_ADDRS
, /* struct flow_dissector_key_eth_addrs */
121 FLOW_DISSECTOR_KEY_TIPC_ADDRS
, /* struct flow_dissector_key_tipc_addrs */
122 FLOW_DISSECTOR_KEY_VLANID
, /* struct flow_dissector_key_flow_tags */
123 FLOW_DISSECTOR_KEY_FLOW_LABEL
, /* struct flow_dissector_key_flow_tags */
124 FLOW_DISSECTOR_KEY_GRE_KEYID
, /* struct flow_dissector_key_keyid */
125 FLOW_DISSECTOR_KEY_MPLS_ENTROPY
, /* struct flow_dissector_key_keyid */
127 FLOW_DISSECTOR_KEY_MAX
,
130 #define FLOW_DISSECTOR_F_PARSE_1ST_FRAG BIT(0)
131 #define FLOW_DISSECTOR_F_STOP_AT_L3 BIT(1)
132 #define FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL BIT(2)
133 #define FLOW_DISSECTOR_F_STOP_AT_ENCAP BIT(3)
135 struct flow_dissector_key
{
136 enum flow_dissector_key_id key_id
;
137 size_t offset
; /* offset of struct flow_dissector_key_*
138 in target the struct */
141 struct flow_dissector
{
142 unsigned int used_keys
; /* each bit repesents presence of one key id */
143 unsigned short int offset
[FLOW_DISSECTOR_KEY_MAX
];
147 struct flow_dissector_key_control control
;
148 #define FLOW_KEYS_HASH_START_FIELD basic
149 struct flow_dissector_key_basic basic
;
150 struct flow_dissector_key_tags tags
;
151 struct flow_dissector_key_keyid keyid
;
152 struct flow_dissector_key_ports ports
;
153 struct flow_dissector_key_addrs addrs
;
156 #define FLOW_KEYS_HASH_OFFSET \
157 offsetof(struct flow_keys, FLOW_KEYS_HASH_START_FIELD)
159 __be32
flow_get_u32_src(const struct flow_keys
*flow
);
160 __be32
flow_get_u32_dst(const struct flow_keys
*flow
);
162 extern struct flow_dissector flow_keys_dissector
;
163 extern struct flow_dissector flow_keys_buf_dissector
;
165 /* struct flow_keys_digest:
167 * This structure is used to hold a digest of the full flow keys. This is a
168 * larger "hash" of a flow to allow definitively matching specific flows where
169 * the 32 bit skb->hash is not large enough. The size is limited to 16 bytes so
170 * that it can by used in CB of skb (see sch_choke for an example).
172 #define FLOW_KEYS_DIGEST_LEN 16
173 struct flow_keys_digest
{
174 u8 data
[FLOW_KEYS_DIGEST_LEN
];
177 void make_flow_keys_digest(struct flow_keys_digest
*digest
,
178 const struct flow_keys
*flow
);
180 static inline bool flow_keys_have_l4(struct flow_keys
*keys
)
182 return (keys
->ports
.ports
|| keys
->tags
.flow_label
);
185 u32
flow_hash_from_keys(struct flow_keys
*keys
);
187 static inline bool dissector_uses_key(const struct flow_dissector
*flow_dissector
,
188 enum flow_dissector_key_id key_id
)
190 return flow_dissector
->used_keys
& (1 << key_id
);
193 static inline void *skb_flow_dissector_target(struct flow_dissector
*flow_dissector
,
194 enum flow_dissector_key_id key_id
,
195 void *target_container
)
197 return ((char *)target_container
) + flow_dissector
->offset
[key_id
];