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 | |
Govindarajulu Varadarajan | e0f31d8 | 2014-06-23 16:07:58 +0530 | [diff] [blame] | 62 | /* struct flow_keys: |
| 63 | * @src: source ip address in case of IPv4 |
| 64 | * For IPv6 it contains 32bit hash of src address |
| 65 | * @dst: destination ip address in case of IPv4 |
| 66 | * For IPv6 it contains 32bit hash of dst address |
| 67 | * @ports: port numbers of Transport header |
| 68 | * port16[0]: src port number |
| 69 | * port16[1]: dst port number |
| 70 | * @thoff: Transport header offset |
| 71 | * @n_proto: Network header protocol (eg. IPv4/IPv6) |
| 72 | * @ip_proto: Transport header protocol (eg. TCP/UDP) |
| 73 | * All the members, except thoff, are in network byte order. |
| 74 | */ |
Eric Dumazet | 0744dd0 | 2011-11-28 05:22:18 +0000 | [diff] [blame] | 75 | struct flow_keys { |
Eric Dumazet | 4d77d2b | 2011-11-28 20:30:35 +0000 | [diff] [blame] | 76 | /* (src,dst) must be grouped, in the same way than in IP header */ |
Eric Dumazet | 0744dd0 | 2011-11-28 05:22:18 +0000 | [diff] [blame] | 77 | __be32 src; |
| 78 | __be32 dst; |
| 79 | union { |
| 80 | __be32 ports; |
| 81 | __be16 port16[2]; |
| 82 | }; |
Eric Dumazet | f4575d3 | 2015-02-04 13:31:54 -0800 | [diff] [blame] | 83 | u16 thoff; |
| 84 | __be16 n_proto; |
| 85 | u8 ip_proto; |
Eric Dumazet | 0744dd0 | 2011-11-28 05:22:18 +0000 | [diff] [blame] | 86 | }; |
| 87 | |
Jiri Pirko | fbff949 | 2015-05-12 14:56:15 +0200 | [diff] [blame^] | 88 | void skb_flow_dissector_init(struct flow_dissector *flow_dissector, |
| 89 | const struct flow_dissector_key *key, |
| 90 | unsigned int key_count); |
David S. Miller | 690e36e | 2014-08-23 12:13:41 -0700 | [diff] [blame] | 91 | bool __skb_flow_dissect(const struct sk_buff *skb, struct flow_keys *flow, |
WANG Cong | 453a940 | 2014-08-25 17:03:47 -0700 | [diff] [blame] | 92 | void *data, __be16 proto, int nhoff, int hlen); |
Jiri Pirko | 1bd758e | 2015-05-12 14:56:07 +0200 | [diff] [blame] | 93 | |
| 94 | static inline bool skb_flow_dissect(const struct sk_buff *skb, |
| 95 | struct flow_keys *flow) |
David S. Miller | 690e36e | 2014-08-23 12:13:41 -0700 | [diff] [blame] | 96 | { |
WANG Cong | 453a940 | 2014-08-25 17:03:47 -0700 | [diff] [blame] | 97 | return __skb_flow_dissect(skb, flow, NULL, 0, 0, 0); |
David S. Miller | 690e36e | 2014-08-23 12:13:41 -0700 | [diff] [blame] | 98 | } |
Jiri Pirko | 1bd758e | 2015-05-12 14:56:07 +0200 | [diff] [blame] | 99 | |
David S. Miller | 690e36e | 2014-08-23 12:13:41 -0700 | [diff] [blame] | 100 | __be32 __skb_flow_get_ports(const struct sk_buff *skb, int thoff, u8 ip_proto, |
| 101 | void *data, int hlen_proto); |
Jiri Pirko | 1bd758e | 2015-05-12 14:56:07 +0200 | [diff] [blame] | 102 | |
| 103 | static inline __be32 skb_flow_get_ports(const struct sk_buff *skb, |
| 104 | int thoff, u8 ip_proto) |
David S. Miller | 690e36e | 2014-08-23 12:13:41 -0700 | [diff] [blame] | 105 | { |
| 106 | return __skb_flow_get_ports(skb, thoff, ip_proto, NULL, 0); |
| 107 | } |
Jiri Pirko | 1bd758e | 2015-05-12 14:56:07 +0200 | [diff] [blame] | 108 | |
Tom Herbert | 5ed20a6 | 2014-07-01 21:32:05 -0700 | [diff] [blame] | 109 | u32 flow_hash_from_keys(struct flow_keys *keys); |
Jiri Pirko | 9c684b5 | 2015-05-12 14:56:11 +0200 | [diff] [blame] | 110 | void __skb_get_hash(struct sk_buff *skb); |
Jiri Pirko | 10b89ee4 | 2015-05-12 14:56:09 +0200 | [diff] [blame] | 111 | u32 skb_get_poff(const struct sk_buff *skb); |
| 112 | u32 __skb_get_poff(const struct sk_buff *skb, void *data, |
| 113 | const struct flow_keys *keys, int hlen); |
Jiri Pirko | 1bd758e | 2015-05-12 14:56:07 +0200 | [diff] [blame] | 114 | |
Tom Herbert | 2f59e1e | 2015-05-01 11:30:17 -0700 | [diff] [blame] | 115 | /* struct flow_keys_digest: |
| 116 | * |
| 117 | * This structure is used to hold a digest of the full flow keys. This is a |
| 118 | * larger "hash" of a flow to allow definitively matching specific flows where |
| 119 | * the 32 bit skb->hash is not large enough. The size is limited to 16 bytes so |
| 120 | * that it can by used in CB of skb (see sch_choke for an example). |
| 121 | */ |
| 122 | #define FLOW_KEYS_DIGEST_LEN 16 |
| 123 | struct flow_keys_digest { |
| 124 | u8 data[FLOW_KEYS_DIGEST_LEN]; |
| 125 | }; |
| 126 | |
| 127 | void make_flow_keys_digest(struct flow_keys_digest *digest, |
| 128 | const struct flow_keys *flow); |
| 129 | |
Eric Dumazet | 0744dd0 | 2011-11-28 05:22:18 +0000 | [diff] [blame] | 130 | #endif |