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