blob: af76c496f7db03af6586a9a34103f6c775b9ea51 [file] [log] [blame]
Jiri Pirko1bd758e2015-05-12 14:56:07 +02001#ifndef _NET_FLOW_DISSECTOR_H
2#define _NET_FLOW_DISSECTOR_H
Eric Dumazet0744dd02011-11-28 05:22:18 +00003
Jiri Pirkoc3f8eae2015-05-12 14:56:17 +02004#include <linux/types.h>
Jiri Pirkob9249332015-05-12 14:56:18 +02005#include <linux/in6.h>
Jiri Pirko67a900c2015-05-12 14:56:19 +02006#include <uapi/linux/if_ether.h>
Jiri Pirkoc3f8eae2015-05-12 14:56:17 +02007
Jiri Pirkofbff9492015-05-12 14:56:15 +02008/**
Tom Herbert42aecaa2015-06-04 09:16:39 -07009 * struct flow_dissector_key_control:
10 * @thoff: Transport header offset
11 */
12struct flow_dissector_key_control {
13 u16 thoff;
Tom Herbertc3f83242015-06-04 09:16:40 -070014 u16 addr_type;
Tom Herbert42aecaa2015-06-04 09:16:39 -070015};
16
17/**
Jiri Pirkofbff9492015-05-12 14:56:15 +020018 * struct flow_dissector_key_basic:
19 * @thoff: Transport header offset
20 * @n_proto: Network header protocol (eg. IPv4/IPv6)
21 * @ip_proto: Transport header protocol (eg. TCP/UDP)
22 */
23struct flow_dissector_key_basic {
Jiri Pirkofbff9492015-05-12 14:56:15 +020024 __be16 n_proto;
25 u8 ip_proto;
Tom Herbert42aecaa2015-06-04 09:16:39 -070026 u8 padding;
Jiri Pirkofbff9492015-05-12 14:56:15 +020027};
28
Tom Herbertd34af822015-06-04 09:16:43 -070029struct flow_dissector_key_tags {
Tom Herbert87ee9e52015-06-04 09:16:44 -070030 u32 vlan_id:12,
31 flow_label:20;
Tom Herbertd34af822015-06-04 09:16:43 -070032};
33
Tom Herbert1fdd5122015-06-04 09:16:45 -070034struct flow_dissector_key_keyid {
35 __be32 keyid;
36};
37
Jiri Pirkofbff9492015-05-12 14:56:15 +020038/**
Tom Herbertc3f83242015-06-04 09:16:40 -070039 * struct flow_dissector_key_ipv4_addrs:
40 * @src: source ip address
41 * @dst: destination ip address
Jiri Pirkofbff9492015-05-12 14:56:15 +020042 */
Tom Herbertc3f83242015-06-04 09:16:40 -070043struct flow_dissector_key_ipv4_addrs {
Jiri Pirkofbff9492015-05-12 14:56:15 +020044 /* (src,dst) must be grouped, in the same way than in IP header */
45 __be32 src;
46 __be32 dst;
47};
48
49/**
Tom Herbertc3f83242015-06-04 09:16:40 -070050 * struct flow_dissector_key_ipv6_addrs:
51 * @src: source ip address
52 * @dst: destination ip address
53 */
54struct flow_dissector_key_ipv6_addrs {
55 /* (src,dst) must be grouped, in the same way than in IP header */
56 struct in6_addr src;
57 struct in6_addr dst;
58};
59
60/**
Tom Herbert9f249082015-06-04 09:16:41 -070061 * struct flow_dissector_key_tipc_addrs:
62 * @srcnode: source node address
63 */
64struct flow_dissector_key_tipc_addrs {
65 __be32 srcnode;
66};
67
68/**
Tom Herbertc3f83242015-06-04 09:16:40 -070069 * struct flow_dissector_key_addrs:
70 * @v4addrs: IPv4 addresses
71 * @v6addrs: IPv6 addresses
72 */
73struct flow_dissector_key_addrs {
74 union {
75 struct flow_dissector_key_ipv4_addrs v4addrs;
76 struct flow_dissector_key_ipv6_addrs v6addrs;
Tom Herbert9f249082015-06-04 09:16:41 -070077 struct flow_dissector_key_tipc_addrs tipcaddrs;
Tom Herbertc3f83242015-06-04 09:16:40 -070078 };
79};
80
81/**
Jiri Pirkofbff9492015-05-12 14:56:15 +020082 * flow_dissector_key_tp_ports:
83 * @ports: port numbers of Transport header
Jiri Pirko59346af2015-05-12 14:56:20 +020084 * src: source port number
85 * dst: destination port number
Jiri Pirkofbff9492015-05-12 14:56:15 +020086 */
87struct flow_dissector_key_ports {
88 union {
89 __be32 ports;
Jiri Pirko59346af2015-05-12 14:56:20 +020090 struct {
91 __be16 src;
92 __be16 dst;
93 };
Jiri Pirkofbff9492015-05-12 14:56:15 +020094 };
95};
96
Jiri Pirkob9249332015-05-12 14:56:18 +020097
Jiri Pirko67a900c2015-05-12 14:56:19 +020098/**
99 * struct flow_dissector_key_eth_addrs:
100 * @src: source Ethernet address
101 * @dst: destination Ethernet address
102 */
103struct flow_dissector_key_eth_addrs {
104 /* (dst,src) must be grouped, in the same way than in ETH header */
105 unsigned char dst[ETH_ALEN];
106 unsigned char src[ETH_ALEN];
107};
108
Jiri Pirkofbff9492015-05-12 14:56:15 +0200109enum flow_dissector_key_id {
Tom Herbert42aecaa2015-06-04 09:16:39 -0700110 FLOW_DISSECTOR_KEY_CONTROL, /* struct flow_dissector_key_control */
Jiri Pirkofbff9492015-05-12 14:56:15 +0200111 FLOW_DISSECTOR_KEY_BASIC, /* struct flow_dissector_key_basic */
Tom Herbertc3f83242015-06-04 09:16:40 -0700112 FLOW_DISSECTOR_KEY_IPV4_ADDRS, /* struct flow_dissector_key_ipv4_addrs */
113 FLOW_DISSECTOR_KEY_IPV6_ADDRS, /* struct flow_dissector_key_ipv6_addrs */
Jiri Pirkofbff9492015-05-12 14:56:15 +0200114 FLOW_DISSECTOR_KEY_PORTS, /* struct flow_dissector_key_ports */
Jiri Pirko67a900c2015-05-12 14:56:19 +0200115 FLOW_DISSECTOR_KEY_ETH_ADDRS, /* struct flow_dissector_key_eth_addrs */
Tom Herbert9f249082015-06-04 09:16:41 -0700116 FLOW_DISSECTOR_KEY_TIPC_ADDRS, /* struct flow_dissector_key_tipc_addrs */
Tom Herbertd34af822015-06-04 09:16:43 -0700117 FLOW_DISSECTOR_KEY_VLANID, /* struct flow_dissector_key_flow_tags */
Tom Herbert87ee9e52015-06-04 09:16:44 -0700118 FLOW_DISSECTOR_KEY_FLOW_LABEL, /* struct flow_dissector_key_flow_tags */
Tom Herbert1fdd5122015-06-04 09:16:45 -0700119 FLOW_DISSECTOR_KEY_GRE_KEYID, /* struct flow_dissector_key_keyid */
Tom Herbertb3baa0f2015-06-04 09:16:46 -0700120 FLOW_DISSECTOR_KEY_MPLS_ENTROPY, /* struct flow_dissector_key_keyid */
Jiri Pirkofbff9492015-05-12 14:56:15 +0200121
122 FLOW_DISSECTOR_KEY_MAX,
123};
124
125struct flow_dissector_key {
126 enum flow_dissector_key_id key_id;
127 size_t offset; /* offset of struct flow_dissector_key_*
128 in target the struct */
129};
130
131struct flow_dissector {
132 unsigned int used_keys; /* each bit repesents presence of one key id */
133 unsigned short int offset[FLOW_DISSECTOR_KEY_MAX];
134};
135
Jiri Pirko06635a32015-05-12 14:56:16 +0200136struct flow_keys {
Tom Herbert42aecaa2015-06-04 09:16:39 -0700137 struct flow_dissector_key_control control;
138#define FLOW_KEYS_HASH_START_FIELD basic
Jiri Pirko06635a32015-05-12 14:56:16 +0200139 struct flow_dissector_key_basic basic;
Tom Herbertd34af822015-06-04 09:16:43 -0700140 struct flow_dissector_key_tags tags;
Tom Herbert1fdd5122015-06-04 09:16:45 -0700141 struct flow_dissector_key_keyid keyid;
Tom Herbert42aecaa2015-06-04 09:16:39 -0700142 struct flow_dissector_key_ports ports;
143 struct flow_dissector_key_addrs addrs;
Jiri Pirko06635a32015-05-12 14:56:16 +0200144};
145
Tom Herbert42aecaa2015-06-04 09:16:39 -0700146#define FLOW_KEYS_HASH_OFFSET \
147 offsetof(struct flow_keys, FLOW_KEYS_HASH_START_FIELD)
148
Tom Herbertc3f83242015-06-04 09:16:40 -0700149__be32 flow_get_u32_src(const struct flow_keys *flow);
150__be32 flow_get_u32_dst(const struct flow_keys *flow);
151
Jiri Pirko06635a32015-05-12 14:56:16 +0200152extern struct flow_dissector flow_keys_dissector;
153extern struct flow_dissector flow_keys_buf_dissector;
154
Tom Herbert2f59e1e2015-05-01 11:30:17 -0700155/* struct flow_keys_digest:
156 *
157 * This structure is used to hold a digest of the full flow keys. This is a
158 * larger "hash" of a flow to allow definitively matching specific flows where
159 * the 32 bit skb->hash is not large enough. The size is limited to 16 bytes so
160 * that it can by used in CB of skb (see sch_choke for an example).
161 */
162#define FLOW_KEYS_DIGEST_LEN 16
163struct flow_keys_digest {
164 u8 data[FLOW_KEYS_DIGEST_LEN];
165};
166
167void make_flow_keys_digest(struct flow_keys_digest *digest,
168 const struct flow_keys *flow);
169
Tom Herbertbcc83832015-09-01 09:24:24 -0700170static inline bool flow_keys_have_l4(struct flow_keys *keys)
171{
172 return (keys->ports.ports || keys->tags.flow_label);
173}
174
Eric Dumazet0744dd02011-11-28 05:22:18 +0000175#endif