blob: 586b12306a52f9ca6d510230a1a86bc2c229aa3a [file] [log] [blame]
Jiri Pirko1bd758e2015-05-12 14:56:07 +02001#ifndef _NET_FLOW_DISSECTOR_H
2#define _NET_FLOW_DISSECTOR_H
Eric Dumazet0744dd02011-11-28 05:22:18 +00003
Jiri Pirkoc3f8eae2015-05-12 14:56:17 +02004#include <linux/types.h>
5#include <linux/skbuff.h>
Jiri Pirkob9249332015-05-12 14:56:18 +02006#include <linux/in6.h>
Jiri Pirkoc3f8eae2015-05-12 14:56:17 +02007
Jiri Pirkofbff9492015-05-12 14:56:15 +02008/**
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 */
14struct 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 */
27struct 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 */
39struct flow_dissector_key_ports {
40 union {
41 __be32 ports;
42 __be16 port16[2];
43 };
44};
45
Jiri Pirkob9249332015-05-12 14:56:18 +020046/**
47 * struct flow_dissector_key_ipv6_addrs:
48 * @src: source ip address
49 * @dst: destination ip address
50 */
51struct 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 Pirkofbff9492015-05-12 14:56:15 +020057enum 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 Pirkob9249332015-05-12 14:56:18 +020062 FLOW_DISSECTOR_KEY_IPV6_ADDRS, /* struct flow_dissector_key_ipv6_addrs */
Jiri Pirkofbff9492015-05-12 14:56:15 +020063
64 FLOW_DISSECTOR_KEY_MAX,
65};
66
67struct 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
73struct 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 Pirkofbff9492015-05-12 14:56:15 +020078void skb_flow_dissector_init(struct flow_dissector *flow_dissector,
79 const struct flow_dissector_key *key,
80 unsigned int key_count);
Jiri Pirko06635a32015-05-12 14:56:16 +020081
82bool __skb_flow_dissect(const struct sk_buff *skb,
83 struct flow_dissector *flow_dissector,
84 void *target_container,
WANG Cong453a9402014-08-25 17:03:47 -070085 void *data, __be16 proto, int nhoff, int hlen);
Jiri Pirko1bd758e2015-05-12 14:56:07 +020086
87static inline bool skb_flow_dissect(const struct sk_buff *skb,
Jiri Pirko06635a32015-05-12 14:56:16 +020088 struct flow_dissector *flow_dissector,
89 void *target_container)
David S. Miller690e36e2014-08-23 12:13:41 -070090{
Jiri Pirko06635a32015-05-12 14:56:16 +020091 return __skb_flow_dissect(skb, flow_dissector, target_container,
92 NULL, 0, 0, 0);
93}
94
95struct 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
101extern struct flow_dissector flow_keys_dissector;
102extern struct flow_dissector flow_keys_buf_dissector;
103
104static 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
112static 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. Miller690e36e2014-08-23 12:13:41 -0700119}
Jiri Pirko1bd758e2015-05-12 14:56:07 +0200120
David S. Miller690e36e2014-08-23 12:13:41 -0700121__be32 __skb_flow_get_ports(const struct sk_buff *skb, int thoff, u8 ip_proto,
122 void *data, int hlen_proto);
Jiri Pirko1bd758e2015-05-12 14:56:07 +0200123
124static inline __be32 skb_flow_get_ports(const struct sk_buff *skb,
125 int thoff, u8 ip_proto)
David S. Miller690e36e2014-08-23 12:13:41 -0700126{
127 return __skb_flow_get_ports(skb, thoff, ip_proto, NULL, 0);
128}
Jiri Pirko1bd758e2015-05-12 14:56:07 +0200129
Tom Herbert5ed20a62014-07-01 21:32:05 -0700130u32 flow_hash_from_keys(struct flow_keys *keys);
Jiri Pirko9c684b52015-05-12 14:56:11 +0200131void __skb_get_hash(struct sk_buff *skb);
Jiri Pirko10b89ee42015-05-12 14:56:09 +0200132u32 skb_get_poff(const struct sk_buff *skb);
133u32 __skb_get_poff(const struct sk_buff *skb, void *data,
134 const struct flow_keys *keys, int hlen);
Jiri Pirko1bd758e2015-05-12 14:56:07 +0200135
Tom Herbert2f59e1e2015-05-01 11:30:17 -0700136/* 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
144struct flow_keys_digest {
145 u8 data[FLOW_KEYS_DIGEST_LEN];
146};
147
148void make_flow_keys_digest(struct flow_keys_digest *digest,
149 const struct flow_keys *flow);
150
Eric Dumazet0744dd02011-11-28 05:22:18 +0000151#endif