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 { |
Tom Herbert | 87ee9e5 | 2015-06-04 09:16:44 -0700 | [diff] [blame] | 35 | u32 vlan_id:12, |
| 36 | flow_label:20; |
Tom Herbert | d34af82 | 2015-06-04 09:16:43 -0700 | [diff] [blame] | 37 | }; |
| 38 | |
Tom Herbert | 1fdd512 | 2015-06-04 09:16:45 -0700 | [diff] [blame] | 39 | struct flow_dissector_key_keyid { |
| 40 | __be32 keyid; |
| 41 | }; |
| 42 | |
Jiri Pirko | fbff949 | 2015-05-12 14:56:15 +0200 | [diff] [blame] | 43 | /** |
Tom Herbert | c3f8324 | 2015-06-04 09:16:40 -0700 | [diff] [blame] | 44 | * struct flow_dissector_key_ipv4_addrs: |
| 45 | * @src: source ip address |
| 46 | * @dst: destination ip address |
Jiri Pirko | fbff949 | 2015-05-12 14:56:15 +0200 | [diff] [blame] | 47 | */ |
Tom Herbert | c3f8324 | 2015-06-04 09:16:40 -0700 | [diff] [blame] | 48 | struct flow_dissector_key_ipv4_addrs { |
Jiri Pirko | fbff949 | 2015-05-12 14:56:15 +0200 | [diff] [blame] | 49 | /* (src,dst) must be grouped, in the same way than in IP header */ |
| 50 | __be32 src; |
| 51 | __be32 dst; |
| 52 | }; |
| 53 | |
| 54 | /** |
Tom Herbert | c3f8324 | 2015-06-04 09:16:40 -0700 | [diff] [blame] | 55 | * struct flow_dissector_key_ipv6_addrs: |
| 56 | * @src: source ip address |
| 57 | * @dst: destination ip address |
| 58 | */ |
| 59 | struct flow_dissector_key_ipv6_addrs { |
| 60 | /* (src,dst) must be grouped, in the same way than in IP header */ |
| 61 | struct in6_addr src; |
| 62 | struct in6_addr dst; |
| 63 | }; |
| 64 | |
| 65 | /** |
Tom Herbert | 9f24908 | 2015-06-04 09:16:41 -0700 | [diff] [blame] | 66 | * struct flow_dissector_key_tipc_addrs: |
| 67 | * @srcnode: source node address |
| 68 | */ |
| 69 | struct flow_dissector_key_tipc_addrs { |
| 70 | __be32 srcnode; |
| 71 | }; |
| 72 | |
| 73 | /** |
Tom Herbert | c3f8324 | 2015-06-04 09:16:40 -0700 | [diff] [blame] | 74 | * struct flow_dissector_key_addrs: |
| 75 | * @v4addrs: IPv4 addresses |
| 76 | * @v6addrs: IPv6 addresses |
| 77 | */ |
| 78 | struct flow_dissector_key_addrs { |
| 79 | union { |
| 80 | struct flow_dissector_key_ipv4_addrs v4addrs; |
| 81 | struct flow_dissector_key_ipv6_addrs v6addrs; |
Tom Herbert | 9f24908 | 2015-06-04 09:16:41 -0700 | [diff] [blame] | 82 | struct flow_dissector_key_tipc_addrs tipcaddrs; |
Tom Herbert | c3f8324 | 2015-06-04 09:16:40 -0700 | [diff] [blame] | 83 | }; |
| 84 | }; |
| 85 | |
| 86 | /** |
Jiri Pirko | fbff949 | 2015-05-12 14:56:15 +0200 | [diff] [blame] | 87 | * flow_dissector_key_tp_ports: |
| 88 | * @ports: port numbers of Transport header |
Jiri Pirko | 59346af | 2015-05-12 14:56:20 +0200 | [diff] [blame] | 89 | * src: source port number |
| 90 | * dst: destination port number |
Jiri Pirko | fbff949 | 2015-05-12 14:56:15 +0200 | [diff] [blame] | 91 | */ |
| 92 | struct flow_dissector_key_ports { |
| 93 | union { |
| 94 | __be32 ports; |
Jiri Pirko | 59346af | 2015-05-12 14:56:20 +0200 | [diff] [blame] | 95 | struct { |
| 96 | __be16 src; |
| 97 | __be16 dst; |
| 98 | }; |
Jiri Pirko | fbff949 | 2015-05-12 14:56:15 +0200 | [diff] [blame] | 99 | }; |
| 100 | }; |
| 101 | |
Jiri Pirko | b924933 | 2015-05-12 14:56:18 +0200 | [diff] [blame] | 102 | |
Jiri Pirko | 67a900c | 2015-05-12 14:56:19 +0200 | [diff] [blame] | 103 | /** |
| 104 | * struct flow_dissector_key_eth_addrs: |
| 105 | * @src: source Ethernet address |
| 106 | * @dst: destination Ethernet address |
| 107 | */ |
| 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]; |
| 112 | }; |
| 113 | |
Jiri Pirko | fbff949 | 2015-05-12 14:56:15 +0200 | [diff] [blame] | 114 | enum flow_dissector_key_id { |
Tom Herbert | 42aecaa | 2015-06-04 09:16:39 -0700 | [diff] [blame] | 115 | FLOW_DISSECTOR_KEY_CONTROL, /* struct flow_dissector_key_control */ |
Jiri Pirko | fbff949 | 2015-05-12 14:56:15 +0200 | [diff] [blame] | 116 | FLOW_DISSECTOR_KEY_BASIC, /* struct flow_dissector_key_basic */ |
Tom Herbert | c3f8324 | 2015-06-04 09:16:40 -0700 | [diff] [blame] | 117 | FLOW_DISSECTOR_KEY_IPV4_ADDRS, /* struct flow_dissector_key_ipv4_addrs */ |
| 118 | FLOW_DISSECTOR_KEY_IPV6_ADDRS, /* struct flow_dissector_key_ipv6_addrs */ |
Jiri Pirko | fbff949 | 2015-05-12 14:56:15 +0200 | [diff] [blame] | 119 | FLOW_DISSECTOR_KEY_PORTS, /* struct flow_dissector_key_ports */ |
Jiri Pirko | 67a900c | 2015-05-12 14:56:19 +0200 | [diff] [blame] | 120 | FLOW_DISSECTOR_KEY_ETH_ADDRS, /* struct flow_dissector_key_eth_addrs */ |
Tom Herbert | 9f24908 | 2015-06-04 09:16:41 -0700 | [diff] [blame] | 121 | FLOW_DISSECTOR_KEY_TIPC_ADDRS, /* struct flow_dissector_key_tipc_addrs */ |
Tom Herbert | d34af82 | 2015-06-04 09:16:43 -0700 | [diff] [blame] | 122 | FLOW_DISSECTOR_KEY_VLANID, /* struct flow_dissector_key_flow_tags */ |
Tom Herbert | 87ee9e5 | 2015-06-04 09:16:44 -0700 | [diff] [blame] | 123 | FLOW_DISSECTOR_KEY_FLOW_LABEL, /* struct flow_dissector_key_flow_tags */ |
Tom Herbert | 1fdd512 | 2015-06-04 09:16:45 -0700 | [diff] [blame] | 124 | FLOW_DISSECTOR_KEY_GRE_KEYID, /* struct flow_dissector_key_keyid */ |
Tom Herbert | b3baa0f | 2015-06-04 09:16:46 -0700 | [diff] [blame] | 125 | FLOW_DISSECTOR_KEY_MPLS_ENTROPY, /* struct flow_dissector_key_keyid */ |
Jiri Pirko | fbff949 | 2015-05-12 14:56:15 +0200 | [diff] [blame] | 126 | |
| 127 | FLOW_DISSECTOR_KEY_MAX, |
| 128 | }; |
| 129 | |
Tom Herbert | 807e165 | 2015-09-01 09:24:28 -0700 | [diff] [blame] | 130 | #define FLOW_DISSECTOR_F_PARSE_1ST_FRAG BIT(0) |
Tom Herbert | 8306b68 | 2015-09-01 09:24:30 -0700 | [diff] [blame] | 131 | #define FLOW_DISSECTOR_F_STOP_AT_L3 BIT(1) |
Tom Herbert | 872b1ab | 2015-09-01 09:24:31 -0700 | [diff] [blame] | 132 | #define FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL BIT(2) |
Tom Herbert | 823b969 | 2015-09-01 09:24:32 -0700 | [diff] [blame] | 133 | #define FLOW_DISSECTOR_F_STOP_AT_ENCAP BIT(3) |
Tom Herbert | 807e165 | 2015-09-01 09:24:28 -0700 | [diff] [blame] | 134 | |
Jiri Pirko | fbff949 | 2015-05-12 14:56:15 +0200 | [diff] [blame] | 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 */ |
| 139 | }; |
| 140 | |
| 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]; |
| 144 | }; |
| 145 | |
Jiri Pirko | 06635a3 | 2015-05-12 14:56:16 +0200 | [diff] [blame] | 146 | struct flow_keys { |
Tom Herbert | 42aecaa | 2015-06-04 09:16:39 -0700 | [diff] [blame] | 147 | struct flow_dissector_key_control control; |
| 148 | #define FLOW_KEYS_HASH_START_FIELD basic |
Jiri Pirko | 06635a3 | 2015-05-12 14:56:16 +0200 | [diff] [blame] | 149 | struct flow_dissector_key_basic basic; |
Tom Herbert | d34af82 | 2015-06-04 09:16:43 -0700 | [diff] [blame] | 150 | struct flow_dissector_key_tags tags; |
Tom Herbert | 1fdd512 | 2015-06-04 09:16:45 -0700 | [diff] [blame] | 151 | struct flow_dissector_key_keyid keyid; |
Tom Herbert | 42aecaa | 2015-06-04 09:16:39 -0700 | [diff] [blame] | 152 | struct flow_dissector_key_ports ports; |
| 153 | struct flow_dissector_key_addrs addrs; |
Jiri Pirko | 06635a3 | 2015-05-12 14:56:16 +0200 | [diff] [blame] | 154 | }; |
| 155 | |
Tom Herbert | 42aecaa | 2015-06-04 09:16:39 -0700 | [diff] [blame] | 156 | #define FLOW_KEYS_HASH_OFFSET \ |
| 157 | offsetof(struct flow_keys, FLOW_KEYS_HASH_START_FIELD) |
| 158 | |
Tom Herbert | c3f8324 | 2015-06-04 09:16:40 -0700 | [diff] [blame] | 159 | __be32 flow_get_u32_src(const struct flow_keys *flow); |
| 160 | __be32 flow_get_u32_dst(const struct flow_keys *flow); |
| 161 | |
Jiri Pirko | 06635a3 | 2015-05-12 14:56:16 +0200 | [diff] [blame] | 162 | extern struct flow_dissector flow_keys_dissector; |
| 163 | extern struct flow_dissector flow_keys_buf_dissector; |
| 164 | |
Tom Herbert | 2f59e1e | 2015-05-01 11:30:17 -0700 | [diff] [blame] | 165 | /* struct flow_keys_digest: |
| 166 | * |
| 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). |
| 171 | */ |
| 172 | #define FLOW_KEYS_DIGEST_LEN 16 |
| 173 | struct flow_keys_digest { |
| 174 | u8 data[FLOW_KEYS_DIGEST_LEN]; |
| 175 | }; |
| 176 | |
| 177 | void make_flow_keys_digest(struct flow_keys_digest *digest, |
| 178 | const struct flow_keys *flow); |
| 179 | |
Tom Herbert | bcc8383 | 2015-09-01 09:24:24 -0700 | [diff] [blame] | 180 | static inline bool flow_keys_have_l4(struct flow_keys *keys) |
| 181 | { |
| 182 | return (keys->ports.ports || keys->tags.flow_label); |
| 183 | } |
| 184 | |
Tom Herbert | c6cc1ca | 2015-09-01 09:24:25 -0700 | [diff] [blame] | 185 | u32 flow_hash_from_keys(struct flow_keys *keys); |
| 186 | |
Amir Vadai | 8de2d79 | 2016-03-08 12:42:30 +0200 | [diff] [blame^] | 187 | static inline bool dissector_uses_key(const struct flow_dissector *flow_dissector, |
| 188 | enum flow_dissector_key_id key_id) |
| 189 | { |
| 190 | return flow_dissector->used_keys & (1 << key_id); |
| 191 | } |
| 192 | |
| 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) |
| 196 | { |
| 197 | return ((char *)target_container) + flow_dissector->offset[key_id]; |
| 198 | } |
| 199 | |
Eric Dumazet | 0744dd0 | 2011-11-28 05:22:18 +0000 | [diff] [blame] | 200 | #endif |