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> |
| 5 | #include <linux/skbuff.h> |
Jiri Pirko | b924933 | 2015-05-12 14:56:18 +0200 | [diff] [blame] | 6 | #include <linux/in6.h> |
Jiri Pirko | 67a900c | 2015-05-12 14:56:19 +0200 | [diff] [blame] | 7 | #include <uapi/linux/if_ether.h> |
Jiri Pirko | c3f8eae | 2015-05-12 14:56:17 +0200 | [diff] [blame] | 8 | |
Jiri Pirko | fbff949 | 2015-05-12 14:56:15 +0200 | [diff] [blame] | 9 | /** |
| 10 | * struct flow_dissector_key_basic: |
| 11 | * @thoff: Transport header offset |
| 12 | * @n_proto: Network header protocol (eg. IPv4/IPv6) |
| 13 | * @ip_proto: Transport header protocol (eg. TCP/UDP) |
| 14 | */ |
| 15 | struct flow_dissector_key_basic { |
| 16 | u16 thoff; |
| 17 | __be16 n_proto; |
| 18 | u8 ip_proto; |
| 19 | }; |
| 20 | |
| 21 | /** |
| 22 | * struct flow_dissector_key_addrs: |
| 23 | * @src: source ip address in case of IPv4 |
| 24 | * For IPv6 it contains 32bit hash of src address |
| 25 | * @dst: destination ip address in case of IPv4 |
| 26 | * For IPv6 it contains 32bit hash of dst address |
| 27 | */ |
| 28 | struct flow_dissector_key_addrs { |
| 29 | /* (src,dst) must be grouped, in the same way than in IP header */ |
| 30 | __be32 src; |
| 31 | __be32 dst; |
| 32 | }; |
| 33 | |
| 34 | /** |
| 35 | * flow_dissector_key_tp_ports: |
| 36 | * @ports: port numbers of Transport header |
Jiri Pirko | 59346af | 2015-05-12 14:56:20 +0200 | [diff] [blame^] | 37 | * src: source port number |
| 38 | * dst: destination port number |
Jiri Pirko | fbff949 | 2015-05-12 14:56:15 +0200 | [diff] [blame] | 39 | */ |
| 40 | struct flow_dissector_key_ports { |
| 41 | union { |
| 42 | __be32 ports; |
Jiri Pirko | 59346af | 2015-05-12 14:56:20 +0200 | [diff] [blame^] | 43 | struct { |
| 44 | __be16 src; |
| 45 | __be16 dst; |
| 46 | }; |
Jiri Pirko | fbff949 | 2015-05-12 14:56:15 +0200 | [diff] [blame] | 47 | }; |
| 48 | }; |
| 49 | |
Jiri Pirko | b924933 | 2015-05-12 14:56:18 +0200 | [diff] [blame] | 50 | /** |
| 51 | * struct flow_dissector_key_ipv6_addrs: |
| 52 | * @src: source ip address |
| 53 | * @dst: destination ip address |
| 54 | */ |
| 55 | struct flow_dissector_key_ipv6_addrs { |
| 56 | /* (src,dst) must be grouped, in the same way than in IP header */ |
| 57 | struct in6_addr src; |
| 58 | struct in6_addr dst; |
| 59 | }; |
| 60 | |
Jiri Pirko | 67a900c | 2015-05-12 14:56:19 +0200 | [diff] [blame] | 61 | /** |
| 62 | * struct flow_dissector_key_eth_addrs: |
| 63 | * @src: source Ethernet address |
| 64 | * @dst: destination Ethernet address |
| 65 | */ |
| 66 | struct flow_dissector_key_eth_addrs { |
| 67 | /* (dst,src) must be grouped, in the same way than in ETH header */ |
| 68 | unsigned char dst[ETH_ALEN]; |
| 69 | unsigned char src[ETH_ALEN]; |
| 70 | }; |
| 71 | |
Jiri Pirko | fbff949 | 2015-05-12 14:56:15 +0200 | [diff] [blame] | 72 | enum flow_dissector_key_id { |
| 73 | FLOW_DISSECTOR_KEY_BASIC, /* struct flow_dissector_key_basic */ |
| 74 | FLOW_DISSECTOR_KEY_IPV4_ADDRS, /* struct flow_dissector_key_addrs */ |
| 75 | FLOW_DISSECTOR_KEY_IPV6_HASH_ADDRS, /* struct flow_dissector_key_addrs */ |
| 76 | FLOW_DISSECTOR_KEY_PORTS, /* struct flow_dissector_key_ports */ |
Jiri Pirko | b924933 | 2015-05-12 14:56:18 +0200 | [diff] [blame] | 77 | FLOW_DISSECTOR_KEY_IPV6_ADDRS, /* struct flow_dissector_key_ipv6_addrs */ |
Jiri Pirko | 67a900c | 2015-05-12 14:56:19 +0200 | [diff] [blame] | 78 | FLOW_DISSECTOR_KEY_ETH_ADDRS, /* struct flow_dissector_key_eth_addrs */ |
Jiri Pirko | fbff949 | 2015-05-12 14:56:15 +0200 | [diff] [blame] | 79 | |
| 80 | FLOW_DISSECTOR_KEY_MAX, |
| 81 | }; |
| 82 | |
| 83 | struct flow_dissector_key { |
| 84 | enum flow_dissector_key_id key_id; |
| 85 | size_t offset; /* offset of struct flow_dissector_key_* |
| 86 | in target the struct */ |
| 87 | }; |
| 88 | |
| 89 | struct flow_dissector { |
| 90 | unsigned int used_keys; /* each bit repesents presence of one key id */ |
| 91 | unsigned short int offset[FLOW_DISSECTOR_KEY_MAX]; |
| 92 | }; |
| 93 | |
Jiri Pirko | fbff949 | 2015-05-12 14:56:15 +0200 | [diff] [blame] | 94 | void skb_flow_dissector_init(struct flow_dissector *flow_dissector, |
| 95 | const struct flow_dissector_key *key, |
| 96 | unsigned int key_count); |
Jiri Pirko | 06635a3 | 2015-05-12 14:56:16 +0200 | [diff] [blame] | 97 | |
| 98 | bool __skb_flow_dissect(const struct sk_buff *skb, |
| 99 | struct flow_dissector *flow_dissector, |
| 100 | void *target_container, |
WANG Cong | 453a940 | 2014-08-25 17:03:47 -0700 | [diff] [blame] | 101 | void *data, __be16 proto, int nhoff, int hlen); |
Jiri Pirko | 1bd758e | 2015-05-12 14:56:07 +0200 | [diff] [blame] | 102 | |
| 103 | static inline bool skb_flow_dissect(const struct sk_buff *skb, |
Jiri Pirko | 06635a3 | 2015-05-12 14:56:16 +0200 | [diff] [blame] | 104 | struct flow_dissector *flow_dissector, |
| 105 | void *target_container) |
David S. Miller | 690e36e | 2014-08-23 12:13:41 -0700 | [diff] [blame] | 106 | { |
Jiri Pirko | 06635a3 | 2015-05-12 14:56:16 +0200 | [diff] [blame] | 107 | return __skb_flow_dissect(skb, flow_dissector, target_container, |
| 108 | NULL, 0, 0, 0); |
| 109 | } |
| 110 | |
| 111 | struct flow_keys { |
| 112 | struct flow_dissector_key_addrs addrs; |
| 113 | struct flow_dissector_key_ports ports; |
| 114 | struct flow_dissector_key_basic basic; |
| 115 | }; |
| 116 | |
| 117 | extern struct flow_dissector flow_keys_dissector; |
| 118 | extern struct flow_dissector flow_keys_buf_dissector; |
| 119 | |
| 120 | static inline bool skb_flow_dissect_flow_keys(const struct sk_buff *skb, |
| 121 | struct flow_keys *flow) |
| 122 | { |
| 123 | memset(flow, 0, sizeof(*flow)); |
| 124 | return __skb_flow_dissect(skb, &flow_keys_dissector, flow, |
| 125 | NULL, 0, 0, 0); |
| 126 | } |
| 127 | |
| 128 | static inline bool skb_flow_dissect_flow_keys_buf(struct flow_keys *flow, |
| 129 | void *data, __be16 proto, |
| 130 | int nhoff, int hlen) |
| 131 | { |
| 132 | memset(flow, 0, sizeof(*flow)); |
| 133 | return __skb_flow_dissect(NULL, &flow_keys_buf_dissector, flow, |
| 134 | data, proto, nhoff, hlen); |
David S. Miller | 690e36e | 2014-08-23 12:13:41 -0700 | [diff] [blame] | 135 | } |
Jiri Pirko | 1bd758e | 2015-05-12 14:56:07 +0200 | [diff] [blame] | 136 | |
David S. Miller | 690e36e | 2014-08-23 12:13:41 -0700 | [diff] [blame] | 137 | __be32 __skb_flow_get_ports(const struct sk_buff *skb, int thoff, u8 ip_proto, |
| 138 | void *data, int hlen_proto); |
Jiri Pirko | 1bd758e | 2015-05-12 14:56:07 +0200 | [diff] [blame] | 139 | |
| 140 | static inline __be32 skb_flow_get_ports(const struct sk_buff *skb, |
| 141 | int thoff, u8 ip_proto) |
David S. Miller | 690e36e | 2014-08-23 12:13:41 -0700 | [diff] [blame] | 142 | { |
| 143 | return __skb_flow_get_ports(skb, thoff, ip_proto, NULL, 0); |
| 144 | } |
Jiri Pirko | 1bd758e | 2015-05-12 14:56:07 +0200 | [diff] [blame] | 145 | |
Tom Herbert | 5ed20a6 | 2014-07-01 21:32:05 -0700 | [diff] [blame] | 146 | u32 flow_hash_from_keys(struct flow_keys *keys); |
Jiri Pirko | 9c684b5 | 2015-05-12 14:56:11 +0200 | [diff] [blame] | 147 | void __skb_get_hash(struct sk_buff *skb); |
Jiri Pirko | 10b89ee4 | 2015-05-12 14:56:09 +0200 | [diff] [blame] | 148 | u32 skb_get_poff(const struct sk_buff *skb); |
| 149 | u32 __skb_get_poff(const struct sk_buff *skb, void *data, |
| 150 | const struct flow_keys *keys, int hlen); |
Jiri Pirko | 1bd758e | 2015-05-12 14:56:07 +0200 | [diff] [blame] | 151 | |
Tom Herbert | 2f59e1e | 2015-05-01 11:30:17 -0700 | [diff] [blame] | 152 | /* struct flow_keys_digest: |
| 153 | * |
| 154 | * This structure is used to hold a digest of the full flow keys. This is a |
| 155 | * larger "hash" of a flow to allow definitively matching specific flows where |
| 156 | * the 32 bit skb->hash is not large enough. The size is limited to 16 bytes so |
| 157 | * that it can by used in CB of skb (see sch_choke for an example). |
| 158 | */ |
| 159 | #define FLOW_KEYS_DIGEST_LEN 16 |
| 160 | struct flow_keys_digest { |
| 161 | u8 data[FLOW_KEYS_DIGEST_LEN]; |
| 162 | }; |
| 163 | |
| 164 | void make_flow_keys_digest(struct flow_keys_digest *digest, |
| 165 | const struct flow_keys *flow); |
| 166 | |
Eric Dumazet | 0744dd0 | 2011-11-28 05:22:18 +0000 | [diff] [blame] | 167 | #endif |