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