Jiri Pirko | 1bd758e | 2015-05-12 14:56:07 +0200 | [diff] [blame] | 1 | #ifndef _NET_FLOW_DISSECTOR_H |
| 2 | #define _NET_FLOW_DISSECTOR_H |
Eric Dumazet | 0744dd0 | 2011-11-28 05:22:18 +0000 | [diff] [blame] | 3 | |
Jiri Pirko | c3f8eae | 2015-05-12 14:56:17 +0200 | [diff] [blame] | 4 | #include <linux/types.h> |
Jiri Pirko | b924933 | 2015-05-12 14:56:18 +0200 | [diff] [blame] | 5 | #include <linux/in6.h> |
Jiri Pirko | 67a900c | 2015-05-12 14:56:19 +0200 | [diff] [blame] | 6 | #include <uapi/linux/if_ether.h> |
Jiri Pirko | c3f8eae | 2015-05-12 14:56:17 +0200 | [diff] [blame] | 7 | |
Jiri Pirko | fbff949 | 2015-05-12 14:56:15 +0200 | [diff] [blame] | 8 | /** |
Tom Herbert | 42aecaa | 2015-06-04 09:16:39 -0700 | [diff] [blame] | 9 | * struct flow_dissector_key_control: |
| 10 | * @thoff: Transport header offset |
| 11 | */ |
| 12 | struct flow_dissector_key_control { |
| 13 | u16 thoff; |
Tom Herbert | c3f8324 | 2015-06-04 09:16:40 -0700 | [diff] [blame] | 14 | u16 addr_type; |
David S. Miller | 4b36993 | 2015-09-01 16:46:08 -0700 | [diff] [blame] | 15 | u32 flags; |
Tom Herbert | 42aecaa | 2015-06-04 09:16:39 -0700 | [diff] [blame] | 16 | }; |
| 17 | |
David S. Miller | 4b36993 | 2015-09-01 16:46:08 -0700 | [diff] [blame] | 18 | #define FLOW_DIS_IS_FRAGMENT BIT(0) |
| 19 | #define FLOW_DIS_FIRST_FRAG BIT(1) |
| 20 | #define FLOW_DIS_ENCAPSULATION BIT(2) |
| 21 | |
Tom Herbert | 42aecaa | 2015-06-04 09:16:39 -0700 | [diff] [blame] | 22 | /** |
Jiri Pirko | fbff949 | 2015-05-12 14:56:15 +0200 | [diff] [blame] | 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) |
| 27 | */ |
| 28 | struct flow_dissector_key_basic { |
Jiri Pirko | fbff949 | 2015-05-12 14:56:15 +0200 | [diff] [blame] | 29 | __be16 n_proto; |
| 30 | u8 ip_proto; |
Tom Herbert | 42aecaa | 2015-06-04 09:16:39 -0700 | [diff] [blame] | 31 | u8 padding; |
Jiri Pirko | fbff949 | 2015-05-12 14:56:15 +0200 | [diff] [blame] | 32 | }; |
| 33 | |
Tom Herbert | d34af82 | 2015-06-04 09:16:43 -0700 | [diff] [blame] | 34 | struct flow_dissector_key_tags { |
Hadar Hen Zion | f6a6692 | 2016-08-17 13:36:11 +0300 | [diff] [blame] | 35 | u32 flow_label; |
| 36 | }; |
| 37 | |
| 38 | struct flow_dissector_key_vlan { |
| 39 | u16 vlan_id:12, |
| 40 | vlan_priority:3; |
| 41 | u16 padding; |
Tom Herbert | d34af82 | 2015-06-04 09:16:43 -0700 | [diff] [blame] | 42 | }; |
| 43 | |
Tom Herbert | 1fdd512 | 2015-06-04 09:16:45 -0700 | [diff] [blame] | 44 | struct flow_dissector_key_keyid { |
| 45 | __be32 keyid; |
| 46 | }; |
| 47 | |
Jiri Pirko | fbff949 | 2015-05-12 14:56:15 +0200 | [diff] [blame] | 48 | /** |
Tom Herbert | c3f8324 | 2015-06-04 09:16:40 -0700 | [diff] [blame] | 49 | * struct flow_dissector_key_ipv4_addrs: |
| 50 | * @src: source ip address |
| 51 | * @dst: destination ip address |
Jiri Pirko | fbff949 | 2015-05-12 14:56:15 +0200 | [diff] [blame] | 52 | */ |
Tom Herbert | c3f8324 | 2015-06-04 09:16:40 -0700 | [diff] [blame] | 53 | struct flow_dissector_key_ipv4_addrs { |
Jiri Pirko | fbff949 | 2015-05-12 14:56:15 +0200 | [diff] [blame] | 54 | /* (src,dst) must be grouped, in the same way than in IP header */ |
| 55 | __be32 src; |
| 56 | __be32 dst; |
| 57 | }; |
| 58 | |
| 59 | /** |
Tom Herbert | c3f8324 | 2015-06-04 09:16:40 -0700 | [diff] [blame] | 60 | * struct flow_dissector_key_ipv6_addrs: |
| 61 | * @src: source ip address |
| 62 | * @dst: destination ip address |
| 63 | */ |
| 64 | struct flow_dissector_key_ipv6_addrs { |
| 65 | /* (src,dst) must be grouped, in the same way than in IP header */ |
| 66 | struct in6_addr src; |
| 67 | struct in6_addr dst; |
| 68 | }; |
| 69 | |
| 70 | /** |
Tom Herbert | 9f24908 | 2015-06-04 09:16:41 -0700 | [diff] [blame] | 71 | * struct flow_dissector_key_tipc_addrs: |
| 72 | * @srcnode: source node address |
| 73 | */ |
| 74 | struct flow_dissector_key_tipc_addrs { |
| 75 | __be32 srcnode; |
| 76 | }; |
| 77 | |
| 78 | /** |
Tom Herbert | c3f8324 | 2015-06-04 09:16:40 -0700 | [diff] [blame] | 79 | * struct flow_dissector_key_addrs: |
| 80 | * @v4addrs: IPv4 addresses |
| 81 | * @v6addrs: IPv6 addresses |
| 82 | */ |
| 83 | struct flow_dissector_key_addrs { |
| 84 | union { |
| 85 | struct flow_dissector_key_ipv4_addrs v4addrs; |
| 86 | struct flow_dissector_key_ipv6_addrs v6addrs; |
Tom Herbert | 9f24908 | 2015-06-04 09:16:41 -0700 | [diff] [blame] | 87 | struct flow_dissector_key_tipc_addrs tipcaddrs; |
Tom Herbert | c3f8324 | 2015-06-04 09:16:40 -0700 | [diff] [blame] | 88 | }; |
| 89 | }; |
| 90 | |
| 91 | /** |
Simon Horman | 5573335 | 2017-01-11 14:05:42 +0100 | [diff] [blame] | 92 | * flow_dissector_key_arp: |
| 93 | * @ports: Operation, source and target addresses for an ARP header |
| 94 | * for Ethernet hardware addresses and IPv4 protocol addresses |
| 95 | * sip: Sender IP address |
| 96 | * tip: Target IP address |
| 97 | * op: Operation |
| 98 | * sha: Sender hardware address |
| 99 | * tpa: Target hardware address |
| 100 | */ |
| 101 | struct flow_dissector_key_arp { |
| 102 | __u32 sip; |
| 103 | __u32 tip; |
| 104 | __u8 op; |
| 105 | unsigned char sha[ETH_ALEN]; |
| 106 | unsigned char tha[ETH_ALEN]; |
| 107 | }; |
| 108 | |
| 109 | /** |
Jiri Pirko | fbff949 | 2015-05-12 14:56:15 +0200 | [diff] [blame] | 110 | * flow_dissector_key_tp_ports: |
| 111 | * @ports: port numbers of Transport header |
Jiri Pirko | 59346af | 2015-05-12 14:56:20 +0200 | [diff] [blame] | 112 | * src: source port number |
| 113 | * dst: destination port number |
Jiri Pirko | fbff949 | 2015-05-12 14:56:15 +0200 | [diff] [blame] | 114 | */ |
| 115 | struct flow_dissector_key_ports { |
| 116 | union { |
| 117 | __be32 ports; |
Jiri Pirko | 59346af | 2015-05-12 14:56:20 +0200 | [diff] [blame] | 118 | struct { |
| 119 | __be16 src; |
| 120 | __be16 dst; |
| 121 | }; |
Jiri Pirko | fbff949 | 2015-05-12 14:56:15 +0200 | [diff] [blame] | 122 | }; |
| 123 | }; |
| 124 | |
Simon Horman | 972d387 | 2016-12-07 13:48:27 +0100 | [diff] [blame] | 125 | /** |
| 126 | * flow_dissector_key_icmp: |
| 127 | * @ports: type and code of ICMP header |
| 128 | * icmp: ICMP type (high) and code (low) |
| 129 | * type: ICMP type |
| 130 | * code: ICMP code |
| 131 | */ |
| 132 | struct flow_dissector_key_icmp { |
| 133 | union { |
| 134 | __be16 icmp; |
| 135 | struct { |
| 136 | u8 type; |
| 137 | u8 code; |
| 138 | }; |
| 139 | }; |
| 140 | }; |
Jiri Pirko | b924933 | 2015-05-12 14:56:18 +0200 | [diff] [blame] | 141 | |
Jiri Pirko | 67a900c | 2015-05-12 14:56:19 +0200 | [diff] [blame] | 142 | /** |
| 143 | * struct flow_dissector_key_eth_addrs: |
| 144 | * @src: source Ethernet address |
| 145 | * @dst: destination Ethernet address |
| 146 | */ |
| 147 | struct flow_dissector_key_eth_addrs { |
| 148 | /* (dst,src) must be grouped, in the same way than in ETH header */ |
| 149 | unsigned char dst[ETH_ALEN]; |
| 150 | unsigned char src[ETH_ALEN]; |
| 151 | }; |
| 152 | |
Jiri Pirko | fbff949 | 2015-05-12 14:56:15 +0200 | [diff] [blame] | 153 | enum flow_dissector_key_id { |
Tom Herbert | 42aecaa | 2015-06-04 09:16:39 -0700 | [diff] [blame] | 154 | FLOW_DISSECTOR_KEY_CONTROL, /* struct flow_dissector_key_control */ |
Jiri Pirko | fbff949 | 2015-05-12 14:56:15 +0200 | [diff] [blame] | 155 | FLOW_DISSECTOR_KEY_BASIC, /* struct flow_dissector_key_basic */ |
Tom Herbert | c3f8324 | 2015-06-04 09:16:40 -0700 | [diff] [blame] | 156 | FLOW_DISSECTOR_KEY_IPV4_ADDRS, /* struct flow_dissector_key_ipv4_addrs */ |
| 157 | FLOW_DISSECTOR_KEY_IPV6_ADDRS, /* struct flow_dissector_key_ipv6_addrs */ |
Jiri Pirko | fbff949 | 2015-05-12 14:56:15 +0200 | [diff] [blame] | 158 | FLOW_DISSECTOR_KEY_PORTS, /* struct flow_dissector_key_ports */ |
Simon Horman | 972d387 | 2016-12-07 13:48:27 +0100 | [diff] [blame] | 159 | FLOW_DISSECTOR_KEY_ICMP, /* struct flow_dissector_key_icmp */ |
Jiri Pirko | 67a900c | 2015-05-12 14:56:19 +0200 | [diff] [blame] | 160 | FLOW_DISSECTOR_KEY_ETH_ADDRS, /* struct flow_dissector_key_eth_addrs */ |
Tom Herbert | 9f24908 | 2015-06-04 09:16:41 -0700 | [diff] [blame] | 161 | FLOW_DISSECTOR_KEY_TIPC_ADDRS, /* struct flow_dissector_key_tipc_addrs */ |
Simon Horman | 5573335 | 2017-01-11 14:05:42 +0100 | [diff] [blame] | 162 | FLOW_DISSECTOR_KEY_ARP, /* struct flow_dissector_key_arp */ |
Hadar Hen Zion | f6a6692 | 2016-08-17 13:36:11 +0300 | [diff] [blame] | 163 | FLOW_DISSECTOR_KEY_VLAN, /* struct flow_dissector_key_flow_vlan */ |
Tom Herbert | 87ee9e5 | 2015-06-04 09:16:44 -0700 | [diff] [blame] | 164 | FLOW_DISSECTOR_KEY_FLOW_LABEL, /* struct flow_dissector_key_flow_tags */ |
Tom Herbert | 1fdd512 | 2015-06-04 09:16:45 -0700 | [diff] [blame] | 165 | FLOW_DISSECTOR_KEY_GRE_KEYID, /* struct flow_dissector_key_keyid */ |
Tom Herbert | b3baa0f | 2015-06-04 09:16:46 -0700 | [diff] [blame] | 166 | FLOW_DISSECTOR_KEY_MPLS_ENTROPY, /* struct flow_dissector_key_keyid */ |
Hadar Hen Zion | 9ba6a9a | 2016-11-07 15:14:37 +0200 | [diff] [blame] | 167 | FLOW_DISSECTOR_KEY_ENC_KEYID, /* struct flow_dissector_key_keyid */ |
| 168 | FLOW_DISSECTOR_KEY_ENC_IPV4_ADDRS, /* struct flow_dissector_key_ipv4_addrs */ |
| 169 | FLOW_DISSECTOR_KEY_ENC_IPV6_ADDRS, /* struct flow_dissector_key_ipv6_addrs */ |
| 170 | FLOW_DISSECTOR_KEY_ENC_CONTROL, /* struct flow_dissector_key_control */ |
Hadar Hen Zion | f4d997f | 2016-11-07 15:14:39 +0200 | [diff] [blame] | 171 | FLOW_DISSECTOR_KEY_ENC_PORTS, /* struct flow_dissector_key_ports */ |
Jiri Pirko | fbff949 | 2015-05-12 14:56:15 +0200 | [diff] [blame] | 172 | |
| 173 | FLOW_DISSECTOR_KEY_MAX, |
| 174 | }; |
| 175 | |
Tom Herbert | 807e165 | 2015-09-01 09:24:28 -0700 | [diff] [blame] | 176 | #define FLOW_DISSECTOR_F_PARSE_1ST_FRAG BIT(0) |
Tom Herbert | 8306b68 | 2015-09-01 09:24:30 -0700 | [diff] [blame] | 177 | #define FLOW_DISSECTOR_F_STOP_AT_L3 BIT(1) |
Tom Herbert | 872b1ab | 2015-09-01 09:24:31 -0700 | [diff] [blame] | 178 | #define FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL BIT(2) |
Tom Herbert | 823b969 | 2015-09-01 09:24:32 -0700 | [diff] [blame] | 179 | #define FLOW_DISSECTOR_F_STOP_AT_ENCAP BIT(3) |
Tom Herbert | 807e165 | 2015-09-01 09:24:28 -0700 | [diff] [blame] | 180 | |
Jiri Pirko | fbff949 | 2015-05-12 14:56:15 +0200 | [diff] [blame] | 181 | struct flow_dissector_key { |
| 182 | enum flow_dissector_key_id key_id; |
| 183 | size_t offset; /* offset of struct flow_dissector_key_* |
| 184 | in target the struct */ |
| 185 | }; |
| 186 | |
| 187 | struct flow_dissector { |
| 188 | unsigned int used_keys; /* each bit repesents presence of one key id */ |
| 189 | unsigned short int offset[FLOW_DISSECTOR_KEY_MAX]; |
| 190 | }; |
| 191 | |
Jiri Pirko | 06635a3 | 2015-05-12 14:56:16 +0200 | [diff] [blame] | 192 | struct flow_keys { |
Tom Herbert | 42aecaa | 2015-06-04 09:16:39 -0700 | [diff] [blame] | 193 | struct flow_dissector_key_control control; |
| 194 | #define FLOW_KEYS_HASH_START_FIELD basic |
Jiri Pirko | 06635a3 | 2015-05-12 14:56:16 +0200 | [diff] [blame] | 195 | struct flow_dissector_key_basic basic; |
Tom Herbert | d34af82 | 2015-06-04 09:16:43 -0700 | [diff] [blame] | 196 | struct flow_dissector_key_tags tags; |
Hadar Hen Zion | f6a6692 | 2016-08-17 13:36:11 +0300 | [diff] [blame] | 197 | struct flow_dissector_key_vlan vlan; |
Tom Herbert | 1fdd512 | 2015-06-04 09:16:45 -0700 | [diff] [blame] | 198 | struct flow_dissector_key_keyid keyid; |
Tom Herbert | 42aecaa | 2015-06-04 09:16:39 -0700 | [diff] [blame] | 199 | struct flow_dissector_key_ports ports; |
| 200 | struct flow_dissector_key_addrs addrs; |
Jiri Pirko | 06635a3 | 2015-05-12 14:56:16 +0200 | [diff] [blame] | 201 | }; |
| 202 | |
Tom Herbert | 42aecaa | 2015-06-04 09:16:39 -0700 | [diff] [blame] | 203 | #define FLOW_KEYS_HASH_OFFSET \ |
| 204 | offsetof(struct flow_keys, FLOW_KEYS_HASH_START_FIELD) |
| 205 | |
Tom Herbert | c3f8324 | 2015-06-04 09:16:40 -0700 | [diff] [blame] | 206 | __be32 flow_get_u32_src(const struct flow_keys *flow); |
| 207 | __be32 flow_get_u32_dst(const struct flow_keys *flow); |
| 208 | |
Jiri Pirko | 06635a3 | 2015-05-12 14:56:16 +0200 | [diff] [blame] | 209 | extern struct flow_dissector flow_keys_dissector; |
| 210 | extern struct flow_dissector flow_keys_buf_dissector; |
| 211 | |
Tom Herbert | 2f59e1e | 2015-05-01 11:30:17 -0700 | [diff] [blame] | 212 | /* struct flow_keys_digest: |
| 213 | * |
| 214 | * This structure is used to hold a digest of the full flow keys. This is a |
| 215 | * larger "hash" of a flow to allow definitively matching specific flows where |
| 216 | * the 32 bit skb->hash is not large enough. The size is limited to 16 bytes so |
| 217 | * that it can by used in CB of skb (see sch_choke for an example). |
| 218 | */ |
| 219 | #define FLOW_KEYS_DIGEST_LEN 16 |
| 220 | struct flow_keys_digest { |
| 221 | u8 data[FLOW_KEYS_DIGEST_LEN]; |
| 222 | }; |
| 223 | |
| 224 | void make_flow_keys_digest(struct flow_keys_digest *digest, |
| 225 | const struct flow_keys *flow); |
| 226 | |
Gao Feng | 66fdd05 | 2016-08-31 11:16:22 +0800 | [diff] [blame] | 227 | static inline bool flow_keys_have_l4(const struct flow_keys *keys) |
Tom Herbert | bcc8383 | 2015-09-01 09:24:24 -0700 | [diff] [blame] | 228 | { |
| 229 | return (keys->ports.ports || keys->tags.flow_label); |
| 230 | } |
| 231 | |
Tom Herbert | c6cc1ca | 2015-09-01 09:24:25 -0700 | [diff] [blame] | 232 | u32 flow_hash_from_keys(struct flow_keys *keys); |
| 233 | |
Amir Vadai | 8de2d79 | 2016-03-08 12:42:30 +0200 | [diff] [blame] | 234 | static inline bool dissector_uses_key(const struct flow_dissector *flow_dissector, |
| 235 | enum flow_dissector_key_id key_id) |
| 236 | { |
| 237 | return flow_dissector->used_keys & (1 << key_id); |
| 238 | } |
| 239 | |
| 240 | static inline void *skb_flow_dissector_target(struct flow_dissector *flow_dissector, |
| 241 | enum flow_dissector_key_id key_id, |
| 242 | void *target_container) |
| 243 | { |
| 244 | return ((char *)target_container) + flow_dissector->offset[key_id]; |
| 245 | } |
| 246 | |
Eric Dumazet | 0744dd0 | 2011-11-28 05:22:18 +0000 | [diff] [blame] | 247 | #endif |