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; |
Tom Herbert | 42aecaa | 2015-06-04 09:16:39 -0700 | [diff] [blame] | 15 | }; |
| 16 | |
| 17 | /** |
Jiri Pirko | fbff949 | 2015-05-12 14:56:15 +0200 | [diff] [blame] | 18 | * 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 | */ |
| 23 | struct flow_dissector_key_basic { |
Jiri Pirko | fbff949 | 2015-05-12 14:56:15 +0200 | [diff] [blame] | 24 | __be16 n_proto; |
| 25 | u8 ip_proto; |
Tom Herbert | 42aecaa | 2015-06-04 09:16:39 -0700 | [diff] [blame] | 26 | u8 padding; |
Jiri Pirko | fbff949 | 2015-05-12 14:56:15 +0200 | [diff] [blame] | 27 | }; |
| 28 | |
Tom Herbert | d34af82 | 2015-06-04 09:16:43 -0700 | [diff] [blame] | 29 | struct flow_dissector_key_tags { |
Tom Herbert | 87ee9e5 | 2015-06-04 09:16:44 -0700 | [diff] [blame] | 30 | u32 vlan_id:12, |
| 31 | flow_label:20; |
Tom Herbert | d34af82 | 2015-06-04 09:16:43 -0700 | [diff] [blame] | 32 | }; |
| 33 | |
Tom Herbert | 1fdd512 | 2015-06-04 09:16:45 -0700 | [diff] [blame] | 34 | struct flow_dissector_key_keyid { |
| 35 | __be32 keyid; |
| 36 | }; |
| 37 | |
Jiri Pirko | fbff949 | 2015-05-12 14:56:15 +0200 | [diff] [blame] | 38 | /** |
Tom Herbert | c3f8324 | 2015-06-04 09:16:40 -0700 | [diff] [blame] | 39 | * struct flow_dissector_key_ipv4_addrs: |
| 40 | * @src: source ip address |
| 41 | * @dst: destination ip address |
Jiri Pirko | fbff949 | 2015-05-12 14:56:15 +0200 | [diff] [blame] | 42 | */ |
Tom Herbert | c3f8324 | 2015-06-04 09:16:40 -0700 | [diff] [blame] | 43 | struct flow_dissector_key_ipv4_addrs { |
Jiri Pirko | fbff949 | 2015-05-12 14:56:15 +0200 | [diff] [blame] | 44 | /* (src,dst) must be grouped, in the same way than in IP header */ |
| 45 | __be32 src; |
| 46 | __be32 dst; |
| 47 | }; |
| 48 | |
| 49 | /** |
Tom Herbert | c3f8324 | 2015-06-04 09:16:40 -0700 | [diff] [blame] | 50 | * struct flow_dissector_key_ipv6_addrs: |
| 51 | * @src: source ip address |
| 52 | * @dst: destination ip address |
| 53 | */ |
| 54 | struct 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 Herbert | 9f24908 | 2015-06-04 09:16:41 -0700 | [diff] [blame] | 61 | * struct flow_dissector_key_tipc_addrs: |
| 62 | * @srcnode: source node address |
| 63 | */ |
| 64 | struct flow_dissector_key_tipc_addrs { |
| 65 | __be32 srcnode; |
| 66 | }; |
| 67 | |
| 68 | /** |
Tom Herbert | c3f8324 | 2015-06-04 09:16:40 -0700 | [diff] [blame] | 69 | * struct flow_dissector_key_addrs: |
| 70 | * @v4addrs: IPv4 addresses |
| 71 | * @v6addrs: IPv6 addresses |
| 72 | */ |
| 73 | struct flow_dissector_key_addrs { |
| 74 | union { |
| 75 | struct flow_dissector_key_ipv4_addrs v4addrs; |
| 76 | struct flow_dissector_key_ipv6_addrs v6addrs; |
Tom Herbert | 9f24908 | 2015-06-04 09:16:41 -0700 | [diff] [blame] | 77 | struct flow_dissector_key_tipc_addrs tipcaddrs; |
Tom Herbert | c3f8324 | 2015-06-04 09:16:40 -0700 | [diff] [blame] | 78 | }; |
| 79 | }; |
| 80 | |
| 81 | /** |
Jiri Pirko | fbff949 | 2015-05-12 14:56:15 +0200 | [diff] [blame] | 82 | * flow_dissector_key_tp_ports: |
| 83 | * @ports: port numbers of Transport header |
Jiri Pirko | 59346af | 2015-05-12 14:56:20 +0200 | [diff] [blame] | 84 | * src: source port number |
| 85 | * dst: destination port number |
Jiri Pirko | fbff949 | 2015-05-12 14:56:15 +0200 | [diff] [blame] | 86 | */ |
| 87 | struct flow_dissector_key_ports { |
| 88 | union { |
| 89 | __be32 ports; |
Jiri Pirko | 59346af | 2015-05-12 14:56:20 +0200 | [diff] [blame] | 90 | struct { |
| 91 | __be16 src; |
| 92 | __be16 dst; |
| 93 | }; |
Jiri Pirko | fbff949 | 2015-05-12 14:56:15 +0200 | [diff] [blame] | 94 | }; |
| 95 | }; |
| 96 | |
Jiri Pirko | b924933 | 2015-05-12 14:56:18 +0200 | [diff] [blame] | 97 | |
Jiri Pirko | 67a900c | 2015-05-12 14:56:19 +0200 | [diff] [blame] | 98 | /** |
| 99 | * struct flow_dissector_key_eth_addrs: |
| 100 | * @src: source Ethernet address |
| 101 | * @dst: destination Ethernet address |
| 102 | */ |
| 103 | struct 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 Pirko | fbff949 | 2015-05-12 14:56:15 +0200 | [diff] [blame] | 109 | enum flow_dissector_key_id { |
Tom Herbert | 42aecaa | 2015-06-04 09:16:39 -0700 | [diff] [blame] | 110 | FLOW_DISSECTOR_KEY_CONTROL, /* struct flow_dissector_key_control */ |
Jiri Pirko | fbff949 | 2015-05-12 14:56:15 +0200 | [diff] [blame] | 111 | FLOW_DISSECTOR_KEY_BASIC, /* struct flow_dissector_key_basic */ |
Tom Herbert | c3f8324 | 2015-06-04 09:16:40 -0700 | [diff] [blame] | 112 | FLOW_DISSECTOR_KEY_IPV4_ADDRS, /* struct flow_dissector_key_ipv4_addrs */ |
| 113 | FLOW_DISSECTOR_KEY_IPV6_ADDRS, /* struct flow_dissector_key_ipv6_addrs */ |
Jiri Pirko | fbff949 | 2015-05-12 14:56:15 +0200 | [diff] [blame] | 114 | FLOW_DISSECTOR_KEY_PORTS, /* struct flow_dissector_key_ports */ |
Jiri Pirko | 67a900c | 2015-05-12 14:56:19 +0200 | [diff] [blame] | 115 | FLOW_DISSECTOR_KEY_ETH_ADDRS, /* struct flow_dissector_key_eth_addrs */ |
Tom Herbert | 9f24908 | 2015-06-04 09:16:41 -0700 | [diff] [blame] | 116 | FLOW_DISSECTOR_KEY_TIPC_ADDRS, /* struct flow_dissector_key_tipc_addrs */ |
Tom Herbert | d34af82 | 2015-06-04 09:16:43 -0700 | [diff] [blame] | 117 | FLOW_DISSECTOR_KEY_VLANID, /* struct flow_dissector_key_flow_tags */ |
Tom Herbert | 87ee9e5 | 2015-06-04 09:16:44 -0700 | [diff] [blame] | 118 | FLOW_DISSECTOR_KEY_FLOW_LABEL, /* struct flow_dissector_key_flow_tags */ |
Tom Herbert | 1fdd512 | 2015-06-04 09:16:45 -0700 | [diff] [blame] | 119 | FLOW_DISSECTOR_KEY_GRE_KEYID, /* struct flow_dissector_key_keyid */ |
Tom Herbert | b3baa0f | 2015-06-04 09:16:46 -0700 | [diff] [blame] | 120 | FLOW_DISSECTOR_KEY_MPLS_ENTROPY, /* struct flow_dissector_key_keyid */ |
Jiri Pirko | fbff949 | 2015-05-12 14:56:15 +0200 | [diff] [blame] | 121 | |
| 122 | FLOW_DISSECTOR_KEY_MAX, |
| 123 | }; |
| 124 | |
| 125 | struct 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 | |
| 131 | struct 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 Pirko | 06635a3 | 2015-05-12 14:56:16 +0200 | [diff] [blame] | 136 | struct flow_keys { |
Tom Herbert | 42aecaa | 2015-06-04 09:16:39 -0700 | [diff] [blame] | 137 | struct flow_dissector_key_control control; |
| 138 | #define FLOW_KEYS_HASH_START_FIELD basic |
Jiri Pirko | 06635a3 | 2015-05-12 14:56:16 +0200 | [diff] [blame] | 139 | struct flow_dissector_key_basic basic; |
Tom Herbert | d34af82 | 2015-06-04 09:16:43 -0700 | [diff] [blame] | 140 | struct flow_dissector_key_tags tags; |
Tom Herbert | 1fdd512 | 2015-06-04 09:16:45 -0700 | [diff] [blame] | 141 | struct flow_dissector_key_keyid keyid; |
Tom Herbert | 42aecaa | 2015-06-04 09:16:39 -0700 | [diff] [blame] | 142 | struct flow_dissector_key_ports ports; |
| 143 | struct flow_dissector_key_addrs addrs; |
Jiri Pirko | 06635a3 | 2015-05-12 14:56:16 +0200 | [diff] [blame] | 144 | }; |
| 145 | |
Tom Herbert | 42aecaa | 2015-06-04 09:16:39 -0700 | [diff] [blame] | 146 | #define FLOW_KEYS_HASH_OFFSET \ |
| 147 | offsetof(struct flow_keys, FLOW_KEYS_HASH_START_FIELD) |
| 148 | |
Tom Herbert | c3f8324 | 2015-06-04 09:16:40 -0700 | [diff] [blame] | 149 | __be32 flow_get_u32_src(const struct flow_keys *flow); |
| 150 | __be32 flow_get_u32_dst(const struct flow_keys *flow); |
| 151 | |
Jiri Pirko | 06635a3 | 2015-05-12 14:56:16 +0200 | [diff] [blame] | 152 | extern struct flow_dissector flow_keys_dissector; |
| 153 | extern struct flow_dissector flow_keys_buf_dissector; |
| 154 | |
Tom Herbert | 2f59e1e | 2015-05-01 11:30:17 -0700 | [diff] [blame] | 155 | /* 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 |
| 163 | struct flow_keys_digest { |
| 164 | u8 data[FLOW_KEYS_DIGEST_LEN]; |
| 165 | }; |
| 166 | |
| 167 | void make_flow_keys_digest(struct flow_keys_digest *digest, |
| 168 | const struct flow_keys *flow); |
| 169 | |
Tom Herbert | bcc8383 | 2015-09-01 09:24:24 -0700 | [diff] [blame^] | 170 | static inline bool flow_keys_have_l4(struct flow_keys *keys) |
| 171 | { |
| 172 | return (keys->ports.ports || keys->tags.flow_label); |
| 173 | } |
| 174 | |
Eric Dumazet | 0744dd0 | 2011-11-28 05:22:18 +0000 | [diff] [blame] | 175 | #endif |