Jiri Pirko | fbff949 | 2015-05-12 14:56:15 +0200 | [diff] [blame] | 1 | #include <linux/kernel.h> |
Eric Dumazet | 0744dd0 | 2011-11-28 05:22:18 +0000 | [diff] [blame] | 2 | #include <linux/skbuff.h> |
Jesper Dangaard Brouer | c452ed7 | 2012-01-24 16:03:33 -0500 | [diff] [blame] | 3 | #include <linux/export.h> |
Eric Dumazet | 0744dd0 | 2011-11-28 05:22:18 +0000 | [diff] [blame] | 4 | #include <linux/ip.h> |
| 5 | #include <linux/ipv6.h> |
| 6 | #include <linux/if_vlan.h> |
| 7 | #include <net/ip.h> |
Eric Dumazet | ddbe503 | 2012-07-18 08:11:12 +0000 | [diff] [blame] | 8 | #include <net/ipv6.h> |
Daniel Borkmann | f77668d | 2013-03-19 06:39:30 +0000 | [diff] [blame] | 9 | #include <linux/igmp.h> |
| 10 | #include <linux/icmp.h> |
| 11 | #include <linux/sctp.h> |
| 12 | #include <linux/dccp.h> |
Eric Dumazet | 0744dd0 | 2011-11-28 05:22:18 +0000 | [diff] [blame] | 13 | #include <linux/if_tunnel.h> |
| 14 | #include <linux/if_pppox.h> |
| 15 | #include <linux/ppp_defs.h> |
Jiri Pirko | 06635a3 | 2015-05-12 14:56:16 +0200 | [diff] [blame] | 16 | #include <linux/stddef.h> |
Jiri Pirko | 67a900c | 2015-05-12 14:56:19 +0200 | [diff] [blame] | 17 | #include <linux/if_ether.h> |
Jiri Pirko | 1bd758e | 2015-05-12 14:56:07 +0200 | [diff] [blame] | 18 | #include <net/flow_dissector.h> |
Alexander Duyck | 56193d1 | 2014-09-05 19:20:26 -0400 | [diff] [blame] | 19 | #include <scsi/fc/fc_fcoe.h> |
Eric Dumazet | 0744dd0 | 2011-11-28 05:22:18 +0000 | [diff] [blame] | 20 | |
Jiri Pirko | fbff949 | 2015-05-12 14:56:15 +0200 | [diff] [blame] | 21 | static bool skb_flow_dissector_uses_key(struct flow_dissector *flow_dissector, |
| 22 | enum flow_dissector_key_id key_id) |
| 23 | { |
| 24 | return flow_dissector->used_keys & (1 << key_id); |
| 25 | } |
| 26 | |
| 27 | static void skb_flow_dissector_set_key(struct flow_dissector *flow_dissector, |
| 28 | enum flow_dissector_key_id key_id) |
| 29 | { |
| 30 | flow_dissector->used_keys |= (1 << key_id); |
| 31 | } |
| 32 | |
| 33 | static void *skb_flow_dissector_target(struct flow_dissector *flow_dissector, |
| 34 | enum flow_dissector_key_id key_id, |
| 35 | void *target_container) |
| 36 | { |
| 37 | return ((char *) target_container) + flow_dissector->offset[key_id]; |
| 38 | } |
| 39 | |
| 40 | void skb_flow_dissector_init(struct flow_dissector *flow_dissector, |
| 41 | const struct flow_dissector_key *key, |
| 42 | unsigned int key_count) |
| 43 | { |
| 44 | unsigned int i; |
| 45 | |
| 46 | memset(flow_dissector, 0, sizeof(*flow_dissector)); |
| 47 | |
| 48 | for (i = 0; i < key_count; i++, key++) { |
| 49 | /* User should make sure that every key target offset is withing |
| 50 | * boundaries of unsigned short. |
| 51 | */ |
| 52 | BUG_ON(key->offset > USHRT_MAX); |
| 53 | BUG_ON(skb_flow_dissector_uses_key(flow_dissector, |
| 54 | key->key_id)); |
| 55 | |
| 56 | skb_flow_dissector_set_key(flow_dissector, key->key_id); |
| 57 | flow_dissector->offset[key->key_id] = key->offset; |
| 58 | } |
| 59 | |
Tom Herbert | 42aecaa | 2015-06-04 09:16:39 -0700 | [diff] [blame] | 60 | /* Ensure that the dissector always includes control and basic key. |
| 61 | * That way we are able to avoid handling lack of these in fast path. |
Jiri Pirko | fbff949 | 2015-05-12 14:56:15 +0200 | [diff] [blame] | 62 | */ |
| 63 | BUG_ON(!skb_flow_dissector_uses_key(flow_dissector, |
Tom Herbert | 42aecaa | 2015-06-04 09:16:39 -0700 | [diff] [blame] | 64 | FLOW_DISSECTOR_KEY_CONTROL)); |
| 65 | BUG_ON(!skb_flow_dissector_uses_key(flow_dissector, |
Jiri Pirko | fbff949 | 2015-05-12 14:56:15 +0200 | [diff] [blame] | 66 | FLOW_DISSECTOR_KEY_BASIC)); |
| 67 | } |
| 68 | EXPORT_SYMBOL(skb_flow_dissector_init); |
| 69 | |
Nikolay Aleksandrov | 357afe9 | 2013-10-02 13:39:24 +0200 | [diff] [blame] | 70 | /** |
WANG Cong | 6451b3f | 2014-08-25 17:03:46 -0700 | [diff] [blame] | 71 | * __skb_flow_get_ports - extract the upper layer ports and return them |
| 72 | * @skb: sk_buff to extract the ports from |
Nikolay Aleksandrov | 357afe9 | 2013-10-02 13:39:24 +0200 | [diff] [blame] | 73 | * @thoff: transport header offset |
| 74 | * @ip_proto: protocol for which to get port offset |
WANG Cong | 6451b3f | 2014-08-25 17:03:46 -0700 | [diff] [blame] | 75 | * @data: raw buffer pointer to the packet, if NULL use skb->data |
| 76 | * @hlen: packet header length, if @data is NULL use skb_headlen(skb) |
Nikolay Aleksandrov | 357afe9 | 2013-10-02 13:39:24 +0200 | [diff] [blame] | 77 | * |
| 78 | * The function will try to retrieve the ports at offset thoff + poff where poff |
| 79 | * is the protocol port offset returned from proto_ports_offset |
| 80 | */ |
David S. Miller | 690e36e | 2014-08-23 12:13:41 -0700 | [diff] [blame] | 81 | __be32 __skb_flow_get_ports(const struct sk_buff *skb, int thoff, u8 ip_proto, |
| 82 | void *data, int hlen) |
Nikolay Aleksandrov | 357afe9 | 2013-10-02 13:39:24 +0200 | [diff] [blame] | 83 | { |
| 84 | int poff = proto_ports_offset(ip_proto); |
| 85 | |
David S. Miller | 690e36e | 2014-08-23 12:13:41 -0700 | [diff] [blame] | 86 | if (!data) { |
| 87 | data = skb->data; |
| 88 | hlen = skb_headlen(skb); |
| 89 | } |
| 90 | |
Nikolay Aleksandrov | 357afe9 | 2013-10-02 13:39:24 +0200 | [diff] [blame] | 91 | if (poff >= 0) { |
| 92 | __be32 *ports, _ports; |
| 93 | |
David S. Miller | 690e36e | 2014-08-23 12:13:41 -0700 | [diff] [blame] | 94 | ports = __skb_header_pointer(skb, thoff + poff, |
| 95 | sizeof(_ports), data, hlen, &_ports); |
Nikolay Aleksandrov | 357afe9 | 2013-10-02 13:39:24 +0200 | [diff] [blame] | 96 | if (ports) |
| 97 | return *ports; |
| 98 | } |
| 99 | |
| 100 | return 0; |
| 101 | } |
David S. Miller | 690e36e | 2014-08-23 12:13:41 -0700 | [diff] [blame] | 102 | EXPORT_SYMBOL(__skb_flow_get_ports); |
Nikolay Aleksandrov | 357afe9 | 2013-10-02 13:39:24 +0200 | [diff] [blame] | 103 | |
WANG Cong | 453a940 | 2014-08-25 17:03:47 -0700 | [diff] [blame] | 104 | /** |
| 105 | * __skb_flow_dissect - extract the flow_keys struct and return it |
| 106 | * @skb: sk_buff to extract the flow from, can be NULL if the rest are specified |
Jiri Pirko | 06635a3 | 2015-05-12 14:56:16 +0200 | [diff] [blame] | 107 | * @flow_dissector: list of keys to dissect |
| 108 | * @target_container: target structure to put dissected values into |
WANG Cong | 453a940 | 2014-08-25 17:03:47 -0700 | [diff] [blame] | 109 | * @data: raw buffer pointer to the packet, if NULL use skb->data |
| 110 | * @proto: protocol for which to get the flow, if @data is NULL use skb->protocol |
| 111 | * @nhoff: network header offset, if @data is NULL use skb_network_offset(skb) |
| 112 | * @hlen: packet header length, if @data is NULL use skb_headlen(skb) |
| 113 | * |
Jiri Pirko | 06635a3 | 2015-05-12 14:56:16 +0200 | [diff] [blame] | 114 | * The function will try to retrieve individual keys into target specified |
| 115 | * by flow_dissector from either the skbuff or a raw buffer specified by the |
| 116 | * rest parameters. |
| 117 | * |
| 118 | * Caller must take care of zeroing target container memory. |
WANG Cong | 453a940 | 2014-08-25 17:03:47 -0700 | [diff] [blame] | 119 | */ |
Jiri Pirko | 06635a3 | 2015-05-12 14:56:16 +0200 | [diff] [blame] | 120 | bool __skb_flow_dissect(const struct sk_buff *skb, |
| 121 | struct flow_dissector *flow_dissector, |
| 122 | void *target_container, |
WANG Cong | 453a940 | 2014-08-25 17:03:47 -0700 | [diff] [blame] | 123 | void *data, __be16 proto, int nhoff, int hlen) |
Eric Dumazet | 0744dd0 | 2011-11-28 05:22:18 +0000 | [diff] [blame] | 124 | { |
Tom Herbert | 42aecaa | 2015-06-04 09:16:39 -0700 | [diff] [blame] | 125 | struct flow_dissector_key_control *key_control; |
Jiri Pirko | 06635a3 | 2015-05-12 14:56:16 +0200 | [diff] [blame] | 126 | struct flow_dissector_key_basic *key_basic; |
| 127 | struct flow_dissector_key_addrs *key_addrs; |
| 128 | struct flow_dissector_key_ports *key_ports; |
Eric Dumazet | 0744dd0 | 2011-11-28 05:22:18 +0000 | [diff] [blame] | 129 | u8 ip_proto; |
Eric Dumazet | 0744dd0 | 2011-11-28 05:22:18 +0000 | [diff] [blame] | 130 | |
David S. Miller | 690e36e | 2014-08-23 12:13:41 -0700 | [diff] [blame] | 131 | if (!data) { |
| 132 | data = skb->data; |
WANG Cong | 453a940 | 2014-08-25 17:03:47 -0700 | [diff] [blame] | 133 | proto = skb->protocol; |
| 134 | nhoff = skb_network_offset(skb); |
David S. Miller | 690e36e | 2014-08-23 12:13:41 -0700 | [diff] [blame] | 135 | hlen = skb_headlen(skb); |
| 136 | } |
| 137 | |
Tom Herbert | 42aecaa | 2015-06-04 09:16:39 -0700 | [diff] [blame] | 138 | /* It is ensured by skb_flow_dissector_init() that control key will |
| 139 | * be always present. |
| 140 | */ |
| 141 | key_control = skb_flow_dissector_target(flow_dissector, |
| 142 | FLOW_DISSECTOR_KEY_CONTROL, |
| 143 | target_container); |
| 144 | |
Jiri Pirko | 06635a3 | 2015-05-12 14:56:16 +0200 | [diff] [blame] | 145 | /* It is ensured by skb_flow_dissector_init() that basic key will |
| 146 | * be always present. |
| 147 | */ |
| 148 | key_basic = skb_flow_dissector_target(flow_dissector, |
| 149 | FLOW_DISSECTOR_KEY_BASIC, |
| 150 | target_container); |
Eric Dumazet | 0744dd0 | 2011-11-28 05:22:18 +0000 | [diff] [blame] | 151 | |
Jiri Pirko | 67a900c | 2015-05-12 14:56:19 +0200 | [diff] [blame] | 152 | if (skb_flow_dissector_uses_key(flow_dissector, |
| 153 | FLOW_DISSECTOR_KEY_ETH_ADDRS)) { |
| 154 | struct ethhdr *eth = eth_hdr(skb); |
| 155 | struct flow_dissector_key_eth_addrs *key_eth_addrs; |
| 156 | |
| 157 | key_eth_addrs = skb_flow_dissector_target(flow_dissector, |
| 158 | FLOW_DISSECTOR_KEY_ETH_ADDRS, |
| 159 | target_container); |
| 160 | memcpy(key_eth_addrs, ð->h_dest, sizeof(*key_eth_addrs)); |
| 161 | } |
| 162 | |
Eric Dumazet | 0744dd0 | 2011-11-28 05:22:18 +0000 | [diff] [blame] | 163 | again: |
| 164 | switch (proto) { |
Joe Perches | 2b8837a | 2014-03-12 10:04:17 -0700 | [diff] [blame] | 165 | case htons(ETH_P_IP): { |
Eric Dumazet | 0744dd0 | 2011-11-28 05:22:18 +0000 | [diff] [blame] | 166 | const struct iphdr *iph; |
| 167 | struct iphdr _iph; |
| 168 | ip: |
David S. Miller | 690e36e | 2014-08-23 12:13:41 -0700 | [diff] [blame] | 169 | iph = __skb_header_pointer(skb, nhoff, sizeof(_iph), data, hlen, &_iph); |
Jason Wang | 6f09234 | 2013-11-01 15:01:10 +0800 | [diff] [blame] | 170 | if (!iph || iph->ihl < 5) |
Eric Dumazet | 0744dd0 | 2011-11-28 05:22:18 +0000 | [diff] [blame] | 171 | return false; |
Eric Dumazet | 3797d3e | 2013-11-07 08:37:28 -0800 | [diff] [blame] | 172 | nhoff += iph->ihl * 4; |
Eric Dumazet | 0744dd0 | 2011-11-28 05:22:18 +0000 | [diff] [blame] | 173 | |
Eric Dumazet | 3797d3e | 2013-11-07 08:37:28 -0800 | [diff] [blame] | 174 | ip_proto = iph->protocol; |
Eric Dumazet | 0744dd0 | 2011-11-28 05:22:18 +0000 | [diff] [blame] | 175 | if (ip_is_fragment(iph)) |
| 176 | ip_proto = 0; |
Eric Dumazet | 3797d3e | 2013-11-07 08:37:28 -0800 | [diff] [blame] | 177 | |
Jiri Pirko | 06635a3 | 2015-05-12 14:56:16 +0200 | [diff] [blame] | 178 | if (!skb_flow_dissector_uses_key(flow_dissector, |
| 179 | FLOW_DISSECTOR_KEY_IPV4_ADDRS)) |
Alexander Duyck | 5af7fb6 | 2014-10-10 12:09:12 -0700 | [diff] [blame] | 180 | break; |
Tom Herbert | c3f8324 | 2015-06-04 09:16:40 -0700 | [diff] [blame^] | 181 | |
Jiri Pirko | 06635a3 | 2015-05-12 14:56:16 +0200 | [diff] [blame] | 182 | key_addrs = skb_flow_dissector_target(flow_dissector, |
Tom Herbert | c3f8324 | 2015-06-04 09:16:40 -0700 | [diff] [blame^] | 183 | FLOW_DISSECTOR_KEY_IPV4_ADDRS, target_container); |
| 184 | memcpy(&key_addrs->v4addrs, &iph->saddr, |
| 185 | sizeof(key_addrs->v4addrs)); |
| 186 | key_control->addr_type = FLOW_DISSECTOR_KEY_IPV4_ADDRS; |
Eric Dumazet | 0744dd0 | 2011-11-28 05:22:18 +0000 | [diff] [blame] | 187 | break; |
| 188 | } |
Joe Perches | 2b8837a | 2014-03-12 10:04:17 -0700 | [diff] [blame] | 189 | case htons(ETH_P_IPV6): { |
Eric Dumazet | 0744dd0 | 2011-11-28 05:22:18 +0000 | [diff] [blame] | 190 | const struct ipv6hdr *iph; |
| 191 | struct ipv6hdr _iph; |
Tom Herbert | 19469a8 | 2014-07-01 21:33:01 -0700 | [diff] [blame] | 192 | __be32 flow_label; |
| 193 | |
Eric Dumazet | 0744dd0 | 2011-11-28 05:22:18 +0000 | [diff] [blame] | 194 | ipv6: |
David S. Miller | 690e36e | 2014-08-23 12:13:41 -0700 | [diff] [blame] | 195 | iph = __skb_header_pointer(skb, nhoff, sizeof(_iph), data, hlen, &_iph); |
Eric Dumazet | 0744dd0 | 2011-11-28 05:22:18 +0000 | [diff] [blame] | 196 | if (!iph) |
| 197 | return false; |
| 198 | |
| 199 | ip_proto = iph->nexthdr; |
Eric Dumazet | 0744dd0 | 2011-11-28 05:22:18 +0000 | [diff] [blame] | 200 | nhoff += sizeof(struct ipv6hdr); |
Tom Herbert | 19469a8 | 2014-07-01 21:33:01 -0700 | [diff] [blame] | 201 | |
Jiri Pirko | b924933 | 2015-05-12 14:56:18 +0200 | [diff] [blame] | 202 | if (skb_flow_dissector_uses_key(flow_dissector, |
| 203 | FLOW_DISSECTOR_KEY_IPV6_HASH_ADDRS)) { |
| 204 | key_addrs = skb_flow_dissector_target(flow_dissector, |
| 205 | FLOW_DISSECTOR_KEY_IPV6_HASH_ADDRS, |
| 206 | target_container); |
Alexander Duyck | 56193d1 | 2014-09-05 19:20:26 -0400 | [diff] [blame] | 207 | |
Tom Herbert | c3f8324 | 2015-06-04 09:16:40 -0700 | [diff] [blame^] | 208 | key_addrs->v4addrs.src = |
| 209 | (__force __be32)ipv6_addr_hash(&iph->saddr); |
| 210 | key_addrs->v4addrs.dst = |
| 211 | (__force __be32)ipv6_addr_hash(&iph->daddr); |
| 212 | key_control->addr_type = FLOW_DISSECTOR_KEY_IPV4_ADDRS; |
Jiri Pirko | b924933 | 2015-05-12 14:56:18 +0200 | [diff] [blame] | 213 | goto flow_label; |
| 214 | } |
| 215 | if (skb_flow_dissector_uses_key(flow_dissector, |
| 216 | FLOW_DISSECTOR_KEY_IPV6_ADDRS)) { |
| 217 | struct flow_dissector_key_ipv6_addrs *key_ipv6_addrs; |
Alexander Duyck | 5af7fb6 | 2014-10-10 12:09:12 -0700 | [diff] [blame] | 218 | |
Jiri Pirko | b924933 | 2015-05-12 14:56:18 +0200 | [diff] [blame] | 219 | key_ipv6_addrs = skb_flow_dissector_target(flow_dissector, |
| 220 | FLOW_DISSECTOR_KEY_IPV6_ADDRS, |
| 221 | target_container); |
| 222 | |
| 223 | memcpy(key_ipv6_addrs, &iph->saddr, sizeof(*key_ipv6_addrs)); |
Tom Herbert | c3f8324 | 2015-06-04 09:16:40 -0700 | [diff] [blame^] | 224 | key_control->addr_type = FLOW_DISSECTOR_KEY_IPV6_ADDRS; |
Jiri Pirko | b924933 | 2015-05-12 14:56:18 +0200 | [diff] [blame] | 225 | goto flow_label; |
| 226 | } |
| 227 | break; |
| 228 | flow_label: |
Tom Herbert | 19469a8 | 2014-07-01 21:33:01 -0700 | [diff] [blame] | 229 | flow_label = ip6_flowlabel(iph); |
| 230 | if (flow_label) { |
| 231 | /* Awesome, IPv6 packet has a flow label so we can |
| 232 | * use that to represent the ports without any |
| 233 | * further dissection. |
| 234 | */ |
Jiri Pirko | 06635a3 | 2015-05-12 14:56:16 +0200 | [diff] [blame] | 235 | |
| 236 | key_basic->n_proto = proto; |
| 237 | key_basic->ip_proto = ip_proto; |
Tom Herbert | 42aecaa | 2015-06-04 09:16:39 -0700 | [diff] [blame] | 238 | key_control->thoff = (u16)nhoff; |
Jiri Pirko | 06635a3 | 2015-05-12 14:56:16 +0200 | [diff] [blame] | 239 | |
Jiri Pirko | 12c227e | 2015-05-22 11:05:58 +0200 | [diff] [blame] | 240 | if (skb_flow_dissector_uses_key(flow_dissector, |
| 241 | FLOW_DISSECTOR_KEY_PORTS)) { |
| 242 | key_ports = skb_flow_dissector_target(flow_dissector, |
| 243 | FLOW_DISSECTOR_KEY_PORTS, |
| 244 | target_container); |
| 245 | key_ports->ports = flow_label; |
| 246 | } |
Tom Herbert | 19469a8 | 2014-07-01 21:33:01 -0700 | [diff] [blame] | 247 | |
| 248 | return true; |
| 249 | } |
| 250 | |
Eric Dumazet | 0744dd0 | 2011-11-28 05:22:18 +0000 | [diff] [blame] | 251 | break; |
| 252 | } |
Joe Perches | 2b8837a | 2014-03-12 10:04:17 -0700 | [diff] [blame] | 253 | case htons(ETH_P_8021AD): |
| 254 | case htons(ETH_P_8021Q): { |
Eric Dumazet | 0744dd0 | 2011-11-28 05:22:18 +0000 | [diff] [blame] | 255 | const struct vlan_hdr *vlan; |
| 256 | struct vlan_hdr _vlan; |
| 257 | |
David S. Miller | 690e36e | 2014-08-23 12:13:41 -0700 | [diff] [blame] | 258 | vlan = __skb_header_pointer(skb, nhoff, sizeof(_vlan), data, hlen, &_vlan); |
Eric Dumazet | 0744dd0 | 2011-11-28 05:22:18 +0000 | [diff] [blame] | 259 | if (!vlan) |
| 260 | return false; |
| 261 | |
| 262 | proto = vlan->h_vlan_encapsulated_proto; |
| 263 | nhoff += sizeof(*vlan); |
| 264 | goto again; |
| 265 | } |
Joe Perches | 2b8837a | 2014-03-12 10:04:17 -0700 | [diff] [blame] | 266 | case htons(ETH_P_PPP_SES): { |
Eric Dumazet | 0744dd0 | 2011-11-28 05:22:18 +0000 | [diff] [blame] | 267 | struct { |
| 268 | struct pppoe_hdr hdr; |
| 269 | __be16 proto; |
| 270 | } *hdr, _hdr; |
David S. Miller | 690e36e | 2014-08-23 12:13:41 -0700 | [diff] [blame] | 271 | hdr = __skb_header_pointer(skb, nhoff, sizeof(_hdr), data, hlen, &_hdr); |
Eric Dumazet | 0744dd0 | 2011-11-28 05:22:18 +0000 | [diff] [blame] | 272 | if (!hdr) |
| 273 | return false; |
| 274 | proto = hdr->proto; |
| 275 | nhoff += PPPOE_SES_HLEN; |
| 276 | switch (proto) { |
Joe Perches | 2b8837a | 2014-03-12 10:04:17 -0700 | [diff] [blame] | 277 | case htons(PPP_IP): |
Eric Dumazet | 0744dd0 | 2011-11-28 05:22:18 +0000 | [diff] [blame] | 278 | goto ip; |
Joe Perches | 2b8837a | 2014-03-12 10:04:17 -0700 | [diff] [blame] | 279 | case htons(PPP_IPV6): |
Eric Dumazet | 0744dd0 | 2011-11-28 05:22:18 +0000 | [diff] [blame] | 280 | goto ipv6; |
| 281 | default: |
| 282 | return false; |
| 283 | } |
| 284 | } |
Erik Hugne | 08bfc9c | 2015-01-22 17:10:32 +0100 | [diff] [blame] | 285 | case htons(ETH_P_TIPC): { |
| 286 | struct { |
| 287 | __be32 pre[3]; |
| 288 | __be32 srcnode; |
| 289 | } *hdr, _hdr; |
| 290 | hdr = __skb_header_pointer(skb, nhoff, sizeof(_hdr), data, hlen, &_hdr); |
| 291 | if (!hdr) |
| 292 | return false; |
Jiri Pirko | 06635a3 | 2015-05-12 14:56:16 +0200 | [diff] [blame] | 293 | key_basic->n_proto = proto; |
Tom Herbert | 42aecaa | 2015-06-04 09:16:39 -0700 | [diff] [blame] | 294 | key_control->thoff = (u16)nhoff; |
Jiri Pirko | 06635a3 | 2015-05-12 14:56:16 +0200 | [diff] [blame] | 295 | |
| 296 | if (skb_flow_dissector_uses_key(flow_dissector, |
| 297 | FLOW_DISSECTOR_KEY_IPV6_HASH_ADDRS)) { |
Jiri Pirko | 06635a3 | 2015-05-12 14:56:16 +0200 | [diff] [blame] | 298 | key_addrs = skb_flow_dissector_target(flow_dissector, |
| 299 | FLOW_DISSECTOR_KEY_IPV6_HASH_ADDRS, |
| 300 | target_container); |
Tom Herbert | c3f8324 | 2015-06-04 09:16:40 -0700 | [diff] [blame^] | 301 | key_addrs->v4addrs.src = hdr->srcnode; |
| 302 | key_addrs->v4addrs.dst = 0; |
| 303 | key_control->addr_type = FLOW_DISSECTOR_KEY_IPV4_ADDRS; |
Jiri Pirko | 06635a3 | 2015-05-12 14:56:16 +0200 | [diff] [blame] | 304 | } |
Erik Hugne | 08bfc9c | 2015-01-22 17:10:32 +0100 | [diff] [blame] | 305 | return true; |
| 306 | } |
Alexander Duyck | 56193d1 | 2014-09-05 19:20:26 -0400 | [diff] [blame] | 307 | case htons(ETH_P_FCOE): |
Tom Herbert | 42aecaa | 2015-06-04 09:16:39 -0700 | [diff] [blame] | 308 | key_control->thoff = (u16)(nhoff + FCOE_HEADER_LEN); |
Alexander Duyck | 56193d1 | 2014-09-05 19:20:26 -0400 | [diff] [blame] | 309 | /* fall through */ |
Eric Dumazet | 0744dd0 | 2011-11-28 05:22:18 +0000 | [diff] [blame] | 310 | default: |
| 311 | return false; |
| 312 | } |
| 313 | |
| 314 | switch (ip_proto) { |
| 315 | case IPPROTO_GRE: { |
| 316 | struct gre_hdr { |
| 317 | __be16 flags; |
| 318 | __be16 proto; |
| 319 | } *hdr, _hdr; |
| 320 | |
David S. Miller | 690e36e | 2014-08-23 12:13:41 -0700 | [diff] [blame] | 321 | hdr = __skb_header_pointer(skb, nhoff, sizeof(_hdr), data, hlen, &_hdr); |
Eric Dumazet | 0744dd0 | 2011-11-28 05:22:18 +0000 | [diff] [blame] | 322 | if (!hdr) |
| 323 | return false; |
| 324 | /* |
| 325 | * Only look inside GRE if version zero and no |
| 326 | * routing |
| 327 | */ |
Tom Herbert | ce3b535 | 2015-06-04 09:16:36 -0700 | [diff] [blame] | 328 | if (hdr->flags & (GRE_VERSION | GRE_ROUTING)) |
| 329 | break; |
Michael Dalton | e1733de | 2013-03-11 06:52:28 +0000 | [diff] [blame] | 330 | |
Tom Herbert | ce3b535 | 2015-06-04 09:16:36 -0700 | [diff] [blame] | 331 | proto = hdr->proto; |
| 332 | nhoff += 4; |
| 333 | if (hdr->flags & GRE_CSUM) |
| 334 | nhoff += 4; |
| 335 | if (hdr->flags & GRE_KEY) |
| 336 | nhoff += 4; |
| 337 | if (hdr->flags & GRE_SEQ) |
| 338 | nhoff += 4; |
| 339 | if (proto == htons(ETH_P_TEB)) { |
| 340 | const struct ethhdr *eth; |
| 341 | struct ethhdr _eth; |
| 342 | |
| 343 | eth = __skb_header_pointer(skb, nhoff, |
| 344 | sizeof(_eth), |
| 345 | data, hlen, &_eth); |
| 346 | if (!eth) |
| 347 | return false; |
| 348 | proto = eth->h_proto; |
| 349 | nhoff += sizeof(*eth); |
Eric Dumazet | 0744dd0 | 2011-11-28 05:22:18 +0000 | [diff] [blame] | 350 | } |
Tom Herbert | ce3b535 | 2015-06-04 09:16:36 -0700 | [diff] [blame] | 351 | goto again; |
Eric Dumazet | 0744dd0 | 2011-11-28 05:22:18 +0000 | [diff] [blame] | 352 | } |
| 353 | case IPPROTO_IPIP: |
Tom Herbert | fca4189 | 2013-07-29 11:07:36 -0700 | [diff] [blame] | 354 | proto = htons(ETH_P_IP); |
| 355 | goto ip; |
Tom Herbert | b438f94 | 2013-07-29 11:07:42 -0700 | [diff] [blame] | 356 | case IPPROTO_IPV6: |
| 357 | proto = htons(ETH_P_IPV6); |
| 358 | goto ipv6; |
Eric Dumazet | 0744dd0 | 2011-11-28 05:22:18 +0000 | [diff] [blame] | 359 | default: |
| 360 | break; |
| 361 | } |
| 362 | |
Jiri Pirko | 06635a3 | 2015-05-12 14:56:16 +0200 | [diff] [blame] | 363 | key_basic->n_proto = proto; |
| 364 | key_basic->ip_proto = ip_proto; |
Tom Herbert | 42aecaa | 2015-06-04 09:16:39 -0700 | [diff] [blame] | 365 | key_control->thoff = (u16)nhoff; |
Daniel Borkmann | 8ed7816 | 2013-03-19 06:39:29 +0000 | [diff] [blame] | 366 | |
Jiri Pirko | 06635a3 | 2015-05-12 14:56:16 +0200 | [diff] [blame] | 367 | if (skb_flow_dissector_uses_key(flow_dissector, |
| 368 | FLOW_DISSECTOR_KEY_PORTS)) { |
| 369 | key_ports = skb_flow_dissector_target(flow_dissector, |
| 370 | FLOW_DISSECTOR_KEY_PORTS, |
| 371 | target_container); |
| 372 | key_ports->ports = __skb_flow_get_ports(skb, nhoff, ip_proto, |
| 373 | data, hlen); |
| 374 | } |
Alexander Duyck | 5af7fb6 | 2014-10-10 12:09:12 -0700 | [diff] [blame] | 375 | |
Eric Dumazet | 0744dd0 | 2011-11-28 05:22:18 +0000 | [diff] [blame] | 376 | return true; |
| 377 | } |
David S. Miller | 690e36e | 2014-08-23 12:13:41 -0700 | [diff] [blame] | 378 | EXPORT_SYMBOL(__skb_flow_dissect); |
Cong Wang | 441d9d3 | 2013-01-21 00:39:24 +0000 | [diff] [blame] | 379 | |
| 380 | static u32 hashrnd __read_mostly; |
Hannes Frederic Sowa | 66415cf | 2013-10-23 20:06:00 +0200 | [diff] [blame] | 381 | static __always_inline void __flow_hash_secret_init(void) |
| 382 | { |
| 383 | net_get_random_once(&hashrnd, sizeof(hashrnd)); |
| 384 | } |
| 385 | |
Tom Herbert | 42aecaa | 2015-06-04 09:16:39 -0700 | [diff] [blame] | 386 | static __always_inline u32 __flow_hash_words(u32 *words, u32 length, u32 keyval) |
Hannes Frederic Sowa | 66415cf | 2013-10-23 20:06:00 +0200 | [diff] [blame] | 387 | { |
Tom Herbert | 42aecaa | 2015-06-04 09:16:39 -0700 | [diff] [blame] | 388 | return jhash2(words, length, keyval); |
| 389 | } |
| 390 | |
| 391 | static inline void *flow_keys_hash_start(struct flow_keys *flow) |
| 392 | { |
| 393 | BUILD_BUG_ON(FLOW_KEYS_HASH_OFFSET % sizeof(u32)); |
| 394 | return (void *)flow + FLOW_KEYS_HASH_OFFSET; |
| 395 | } |
| 396 | |
| 397 | static inline size_t flow_keys_hash_length(struct flow_keys *flow) |
| 398 | { |
Tom Herbert | c3f8324 | 2015-06-04 09:16:40 -0700 | [diff] [blame^] | 399 | size_t diff = FLOW_KEYS_HASH_OFFSET + sizeof(flow->addrs); |
Tom Herbert | 42aecaa | 2015-06-04 09:16:39 -0700 | [diff] [blame] | 400 | BUILD_BUG_ON((sizeof(*flow) - FLOW_KEYS_HASH_OFFSET) % sizeof(u32)); |
Tom Herbert | c3f8324 | 2015-06-04 09:16:40 -0700 | [diff] [blame^] | 401 | BUILD_BUG_ON(offsetof(typeof(*flow), addrs) != |
| 402 | sizeof(*flow) - sizeof(flow->addrs)); |
| 403 | |
| 404 | switch (flow->control.addr_type) { |
| 405 | case FLOW_DISSECTOR_KEY_IPV4_ADDRS: |
| 406 | diff -= sizeof(flow->addrs.v4addrs); |
| 407 | break; |
| 408 | case FLOW_DISSECTOR_KEY_IPV6_ADDRS: |
| 409 | diff -= sizeof(flow->addrs.v6addrs); |
| 410 | break; |
| 411 | } |
| 412 | return (sizeof(*flow) - diff) / sizeof(u32); |
| 413 | } |
| 414 | |
| 415 | __be32 flow_get_u32_src(const struct flow_keys *flow) |
| 416 | { |
| 417 | switch (flow->control.addr_type) { |
| 418 | case FLOW_DISSECTOR_KEY_IPV4_ADDRS: |
| 419 | return flow->addrs.v4addrs.src; |
| 420 | case FLOW_DISSECTOR_KEY_IPV6_ADDRS: |
| 421 | return (__force __be32)ipv6_addr_hash( |
| 422 | &flow->addrs.v6addrs.src); |
| 423 | default: |
| 424 | return 0; |
| 425 | } |
| 426 | } |
| 427 | EXPORT_SYMBOL(flow_get_u32_src); |
| 428 | |
| 429 | __be32 flow_get_u32_dst(const struct flow_keys *flow) |
| 430 | { |
| 431 | switch (flow->control.addr_type) { |
| 432 | case FLOW_DISSECTOR_KEY_IPV4_ADDRS: |
| 433 | return flow->addrs.v4addrs.dst; |
| 434 | case FLOW_DISSECTOR_KEY_IPV6_ADDRS: |
| 435 | return (__force __be32)ipv6_addr_hash( |
| 436 | &flow->addrs.v6addrs.dst); |
| 437 | default: |
| 438 | return 0; |
| 439 | } |
| 440 | } |
| 441 | EXPORT_SYMBOL(flow_get_u32_dst); |
| 442 | |
| 443 | static inline void __flow_hash_consistentify(struct flow_keys *keys) |
| 444 | { |
| 445 | int addr_diff, i; |
| 446 | |
| 447 | switch (keys->control.addr_type) { |
| 448 | case FLOW_DISSECTOR_KEY_IPV4_ADDRS: |
| 449 | addr_diff = (__force u32)keys->addrs.v4addrs.dst - |
| 450 | (__force u32)keys->addrs.v4addrs.src; |
| 451 | if ((addr_diff < 0) || |
| 452 | (addr_diff == 0 && |
| 453 | ((__force u16)keys->ports.dst < |
| 454 | (__force u16)keys->ports.src))) { |
| 455 | swap(keys->addrs.v4addrs.src, keys->addrs.v4addrs.dst); |
| 456 | swap(keys->ports.src, keys->ports.dst); |
| 457 | } |
| 458 | break; |
| 459 | case FLOW_DISSECTOR_KEY_IPV6_ADDRS: |
| 460 | addr_diff = memcmp(&keys->addrs.v6addrs.dst, |
| 461 | &keys->addrs.v6addrs.src, |
| 462 | sizeof(keys->addrs.v6addrs.dst)); |
| 463 | if ((addr_diff < 0) || |
| 464 | (addr_diff == 0 && |
| 465 | ((__force u16)keys->ports.dst < |
| 466 | (__force u16)keys->ports.src))) { |
| 467 | for (i = 0; i < 4; i++) |
| 468 | swap(keys->addrs.v6addrs.src.s6_addr32[i], |
| 469 | keys->addrs.v6addrs.dst.s6_addr32[i]); |
| 470 | swap(keys->ports.src, keys->ports.dst); |
| 471 | } |
| 472 | break; |
| 473 | } |
Hannes Frederic Sowa | 66415cf | 2013-10-23 20:06:00 +0200 | [diff] [blame] | 474 | } |
| 475 | |
Tom Herbert | 50fb799 | 2015-05-01 11:30:12 -0700 | [diff] [blame] | 476 | static inline u32 __flow_hash_from_keys(struct flow_keys *keys, u32 keyval) |
Tom Herbert | 5ed20a6 | 2014-07-01 21:32:05 -0700 | [diff] [blame] | 477 | { |
| 478 | u32 hash; |
| 479 | |
Tom Herbert | c3f8324 | 2015-06-04 09:16:40 -0700 | [diff] [blame^] | 480 | __flow_hash_consistentify(keys); |
Tom Herbert | 5ed20a6 | 2014-07-01 21:32:05 -0700 | [diff] [blame] | 481 | |
Tom Herbert | 42aecaa | 2015-06-04 09:16:39 -0700 | [diff] [blame] | 482 | hash = __flow_hash_words((u32 *)flow_keys_hash_start(keys), |
| 483 | flow_keys_hash_length(keys), keyval); |
Tom Herbert | 5ed20a6 | 2014-07-01 21:32:05 -0700 | [diff] [blame] | 484 | if (!hash) |
| 485 | hash = 1; |
| 486 | |
| 487 | return hash; |
| 488 | } |
| 489 | |
| 490 | u32 flow_hash_from_keys(struct flow_keys *keys) |
| 491 | { |
Tom Herbert | 50fb799 | 2015-05-01 11:30:12 -0700 | [diff] [blame] | 492 | __flow_hash_secret_init(); |
| 493 | return __flow_hash_from_keys(keys, hashrnd); |
Tom Herbert | 5ed20a6 | 2014-07-01 21:32:05 -0700 | [diff] [blame] | 494 | } |
| 495 | EXPORT_SYMBOL(flow_hash_from_keys); |
| 496 | |
Tom Herbert | 50fb799 | 2015-05-01 11:30:12 -0700 | [diff] [blame] | 497 | static inline u32 ___skb_get_hash(const struct sk_buff *skb, |
| 498 | struct flow_keys *keys, u32 keyval) |
| 499 | { |
Jiri Pirko | 06635a3 | 2015-05-12 14:56:16 +0200 | [diff] [blame] | 500 | if (!skb_flow_dissect_flow_keys(skb, keys)) |
Tom Herbert | 50fb799 | 2015-05-01 11:30:12 -0700 | [diff] [blame] | 501 | return 0; |
| 502 | |
| 503 | return __flow_hash_from_keys(keys, keyval); |
| 504 | } |
| 505 | |
Tom Herbert | 2f59e1e | 2015-05-01 11:30:17 -0700 | [diff] [blame] | 506 | struct _flow_keys_digest_data { |
| 507 | __be16 n_proto; |
| 508 | u8 ip_proto; |
| 509 | u8 padding; |
| 510 | __be32 ports; |
| 511 | __be32 src; |
| 512 | __be32 dst; |
| 513 | }; |
| 514 | |
| 515 | void make_flow_keys_digest(struct flow_keys_digest *digest, |
| 516 | const struct flow_keys *flow) |
| 517 | { |
| 518 | struct _flow_keys_digest_data *data = |
| 519 | (struct _flow_keys_digest_data *)digest; |
| 520 | |
| 521 | BUILD_BUG_ON(sizeof(*data) > sizeof(*digest)); |
| 522 | |
| 523 | memset(digest, 0, sizeof(*digest)); |
| 524 | |
Jiri Pirko | 06635a3 | 2015-05-12 14:56:16 +0200 | [diff] [blame] | 525 | data->n_proto = flow->basic.n_proto; |
| 526 | data->ip_proto = flow->basic.ip_proto; |
| 527 | data->ports = flow->ports.ports; |
Tom Herbert | c3f8324 | 2015-06-04 09:16:40 -0700 | [diff] [blame^] | 528 | data->src = flow->addrs.v4addrs.src; |
| 529 | data->dst = flow->addrs.v4addrs.dst; |
Tom Herbert | 2f59e1e | 2015-05-01 11:30:17 -0700 | [diff] [blame] | 530 | } |
| 531 | EXPORT_SYMBOL(make_flow_keys_digest); |
| 532 | |
Jiri Pirko | d4fd327 | 2015-05-12 14:56:10 +0200 | [diff] [blame] | 533 | /** |
| 534 | * __skb_get_hash: calculate a flow hash |
| 535 | * @skb: sk_buff to calculate flow hash from |
| 536 | * |
| 537 | * This function calculates a flow hash based on src/dst addresses |
Tom Herbert | 61b905d | 2014-03-24 15:34:47 -0700 | [diff] [blame] | 538 | * and src/dst port numbers. Sets hash in skb to non-zero hash value |
| 539 | * on success, zero indicates no valid hash. Also, sets l4_hash in skb |
Cong Wang | 441d9d3 | 2013-01-21 00:39:24 +0000 | [diff] [blame] | 540 | * if hash is a canonical 4-tuple hash over transport ports. |
| 541 | */ |
Tom Herbert | 3958afa1b | 2013-12-15 22:12:06 -0800 | [diff] [blame] | 542 | void __skb_get_hash(struct sk_buff *skb) |
Cong Wang | 441d9d3 | 2013-01-21 00:39:24 +0000 | [diff] [blame] | 543 | { |
| 544 | struct flow_keys keys; |
Tom Herbert | 50fb799 | 2015-05-01 11:30:12 -0700 | [diff] [blame] | 545 | u32 hash; |
Cong Wang | 441d9d3 | 2013-01-21 00:39:24 +0000 | [diff] [blame] | 546 | |
Tom Herbert | 50fb799 | 2015-05-01 11:30:12 -0700 | [diff] [blame] | 547 | __flow_hash_secret_init(); |
| 548 | |
| 549 | hash = ___skb_get_hash(skb, &keys, hashrnd); |
| 550 | if (!hash) |
Cong Wang | 441d9d3 | 2013-01-21 00:39:24 +0000 | [diff] [blame] | 551 | return; |
Jiri Pirko | 06635a3 | 2015-05-12 14:56:16 +0200 | [diff] [blame] | 552 | if (keys.ports.ports) |
Tom Herbert | 61b905d | 2014-03-24 15:34:47 -0700 | [diff] [blame] | 553 | skb->l4_hash = 1; |
Tom Herbert | a3b18dd | 2014-07-01 21:33:17 -0700 | [diff] [blame] | 554 | skb->sw_hash = 1; |
Tom Herbert | 50fb799 | 2015-05-01 11:30:12 -0700 | [diff] [blame] | 555 | skb->hash = hash; |
Cong Wang | 441d9d3 | 2013-01-21 00:39:24 +0000 | [diff] [blame] | 556 | } |
Tom Herbert | 3958afa1b | 2013-12-15 22:12:06 -0800 | [diff] [blame] | 557 | EXPORT_SYMBOL(__skb_get_hash); |
Cong Wang | 441d9d3 | 2013-01-21 00:39:24 +0000 | [diff] [blame] | 558 | |
Tom Herbert | 50fb799 | 2015-05-01 11:30:12 -0700 | [diff] [blame] | 559 | __u32 skb_get_hash_perturb(const struct sk_buff *skb, u32 perturb) |
| 560 | { |
| 561 | struct flow_keys keys; |
| 562 | |
| 563 | return ___skb_get_hash(skb, &keys, perturb); |
| 564 | } |
| 565 | EXPORT_SYMBOL(skb_get_hash_perturb); |
| 566 | |
Alexander Duyck | 56193d1 | 2014-09-05 19:20:26 -0400 | [diff] [blame] | 567 | u32 __skb_get_poff(const struct sk_buff *skb, void *data, |
| 568 | const struct flow_keys *keys, int hlen) |
Daniel Borkmann | f77668d | 2013-03-19 06:39:30 +0000 | [diff] [blame] | 569 | { |
Tom Herbert | 42aecaa | 2015-06-04 09:16:39 -0700 | [diff] [blame] | 570 | u32 poff = keys->control.thoff; |
Daniel Borkmann | f77668d | 2013-03-19 06:39:30 +0000 | [diff] [blame] | 571 | |
Jiri Pirko | 06635a3 | 2015-05-12 14:56:16 +0200 | [diff] [blame] | 572 | switch (keys->basic.ip_proto) { |
Daniel Borkmann | f77668d | 2013-03-19 06:39:30 +0000 | [diff] [blame] | 573 | case IPPROTO_TCP: { |
Alexander Duyck | 5af7fb6 | 2014-10-10 12:09:12 -0700 | [diff] [blame] | 574 | /* access doff as u8 to avoid unaligned access */ |
| 575 | const u8 *doff; |
| 576 | u8 _doff; |
Daniel Borkmann | f77668d | 2013-03-19 06:39:30 +0000 | [diff] [blame] | 577 | |
Alexander Duyck | 5af7fb6 | 2014-10-10 12:09:12 -0700 | [diff] [blame] | 578 | doff = __skb_header_pointer(skb, poff + 12, sizeof(_doff), |
| 579 | data, hlen, &_doff); |
| 580 | if (!doff) |
Daniel Borkmann | f77668d | 2013-03-19 06:39:30 +0000 | [diff] [blame] | 581 | return poff; |
| 582 | |
Alexander Duyck | 5af7fb6 | 2014-10-10 12:09:12 -0700 | [diff] [blame] | 583 | poff += max_t(u32, sizeof(struct tcphdr), (*doff & 0xF0) >> 2); |
Daniel Borkmann | f77668d | 2013-03-19 06:39:30 +0000 | [diff] [blame] | 584 | break; |
| 585 | } |
| 586 | case IPPROTO_UDP: |
| 587 | case IPPROTO_UDPLITE: |
| 588 | poff += sizeof(struct udphdr); |
| 589 | break; |
| 590 | /* For the rest, we do not really care about header |
| 591 | * extensions at this point for now. |
| 592 | */ |
| 593 | case IPPROTO_ICMP: |
| 594 | poff += sizeof(struct icmphdr); |
| 595 | break; |
| 596 | case IPPROTO_ICMPV6: |
| 597 | poff += sizeof(struct icmp6hdr); |
| 598 | break; |
| 599 | case IPPROTO_IGMP: |
| 600 | poff += sizeof(struct igmphdr); |
| 601 | break; |
| 602 | case IPPROTO_DCCP: |
| 603 | poff += sizeof(struct dccp_hdr); |
| 604 | break; |
| 605 | case IPPROTO_SCTP: |
| 606 | poff += sizeof(struct sctphdr); |
| 607 | break; |
| 608 | } |
| 609 | |
| 610 | return poff; |
| 611 | } |
| 612 | |
Jiri Pirko | 0db89b8 | 2015-05-12 14:56:14 +0200 | [diff] [blame] | 613 | /** |
| 614 | * skb_get_poff - get the offset to the payload |
| 615 | * @skb: sk_buff to get the payload offset from |
| 616 | * |
| 617 | * The function will get the offset to the payload as far as it could |
| 618 | * be dissected. The main user is currently BPF, so that we can dynamically |
Alexander Duyck | 56193d1 | 2014-09-05 19:20:26 -0400 | [diff] [blame] | 619 | * truncate packets without needing to push actual payload to the user |
| 620 | * space and can analyze headers only, instead. |
| 621 | */ |
| 622 | u32 skb_get_poff(const struct sk_buff *skb) |
| 623 | { |
| 624 | struct flow_keys keys; |
| 625 | |
Jiri Pirko | 06635a3 | 2015-05-12 14:56:16 +0200 | [diff] [blame] | 626 | if (!skb_flow_dissect_flow_keys(skb, &keys)) |
Alexander Duyck | 56193d1 | 2014-09-05 19:20:26 -0400 | [diff] [blame] | 627 | return 0; |
| 628 | |
| 629 | return __skb_get_poff(skb, skb->data, &keys, skb_headlen(skb)); |
| 630 | } |
Jiri Pirko | 06635a3 | 2015-05-12 14:56:16 +0200 | [diff] [blame] | 631 | |
| 632 | static const struct flow_dissector_key flow_keys_dissector_keys[] = { |
| 633 | { |
Tom Herbert | 42aecaa | 2015-06-04 09:16:39 -0700 | [diff] [blame] | 634 | .key_id = FLOW_DISSECTOR_KEY_CONTROL, |
| 635 | .offset = offsetof(struct flow_keys, control), |
| 636 | }, |
| 637 | { |
Jiri Pirko | 06635a3 | 2015-05-12 14:56:16 +0200 | [diff] [blame] | 638 | .key_id = FLOW_DISSECTOR_KEY_BASIC, |
| 639 | .offset = offsetof(struct flow_keys, basic), |
| 640 | }, |
| 641 | { |
| 642 | .key_id = FLOW_DISSECTOR_KEY_IPV4_ADDRS, |
Tom Herbert | c3f8324 | 2015-06-04 09:16:40 -0700 | [diff] [blame^] | 643 | .offset = offsetof(struct flow_keys, addrs.v4addrs), |
| 644 | }, |
| 645 | { |
| 646 | .key_id = FLOW_DISSECTOR_KEY_IPV6_ADDRS, |
| 647 | .offset = offsetof(struct flow_keys, addrs.v6addrs), |
Jiri Pirko | 06635a3 | 2015-05-12 14:56:16 +0200 | [diff] [blame] | 648 | }, |
| 649 | { |
| 650 | .key_id = FLOW_DISSECTOR_KEY_IPV6_HASH_ADDRS, |
Tom Herbert | c3f8324 | 2015-06-04 09:16:40 -0700 | [diff] [blame^] | 651 | .offset = offsetof(struct flow_keys, addrs.v4addrs), |
Jiri Pirko | 06635a3 | 2015-05-12 14:56:16 +0200 | [diff] [blame] | 652 | }, |
| 653 | { |
| 654 | .key_id = FLOW_DISSECTOR_KEY_PORTS, |
| 655 | .offset = offsetof(struct flow_keys, ports), |
| 656 | }, |
| 657 | }; |
| 658 | |
| 659 | static const struct flow_dissector_key flow_keys_buf_dissector_keys[] = { |
| 660 | { |
Tom Herbert | 42aecaa | 2015-06-04 09:16:39 -0700 | [diff] [blame] | 661 | .key_id = FLOW_DISSECTOR_KEY_CONTROL, |
| 662 | .offset = offsetof(struct flow_keys, control), |
| 663 | }, |
| 664 | { |
Jiri Pirko | 06635a3 | 2015-05-12 14:56:16 +0200 | [diff] [blame] | 665 | .key_id = FLOW_DISSECTOR_KEY_BASIC, |
| 666 | .offset = offsetof(struct flow_keys, basic), |
| 667 | }, |
| 668 | }; |
| 669 | |
| 670 | struct flow_dissector flow_keys_dissector __read_mostly; |
| 671 | EXPORT_SYMBOL(flow_keys_dissector); |
| 672 | |
| 673 | struct flow_dissector flow_keys_buf_dissector __read_mostly; |
| 674 | |
| 675 | static int __init init_default_flow_dissectors(void) |
| 676 | { |
| 677 | skb_flow_dissector_init(&flow_keys_dissector, |
| 678 | flow_keys_dissector_keys, |
| 679 | ARRAY_SIZE(flow_keys_dissector_keys)); |
| 680 | skb_flow_dissector_init(&flow_keys_buf_dissector, |
| 681 | flow_keys_buf_dissector_keys, |
| 682 | ARRAY_SIZE(flow_keys_buf_dissector_keys)); |
| 683 | return 0; |
| 684 | } |
| 685 | |
| 686 | late_initcall_sync(init_default_flow_dissectors); |