blob: 0c8d406fb73001207c3e72f3bf55cb6873318601 [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 Pirkofbff9492015-05-12 14:56:15 +02004/**
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 */
10struct 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 */
23struct 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 */
35struct flow_dissector_key_ports {
36 union {
37 __be32 ports;
38 __be16 port16[2];
39 };
40};
41
42enum 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
51struct 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
57struct 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 Pirkofbff9492015-05-12 14:56:15 +020062void skb_flow_dissector_init(struct flow_dissector *flow_dissector,
63 const struct flow_dissector_key *key,
64 unsigned int key_count);
Jiri Pirko06635a32015-05-12 14:56:16 +020065
66bool __skb_flow_dissect(const struct sk_buff *skb,
67 struct flow_dissector *flow_dissector,
68 void *target_container,
WANG Cong453a9402014-08-25 17:03:47 -070069 void *data, __be16 proto, int nhoff, int hlen);
Jiri Pirko1bd758e2015-05-12 14:56:07 +020070
71static inline bool skb_flow_dissect(const struct sk_buff *skb,
Jiri Pirko06635a32015-05-12 14:56:16 +020072 struct flow_dissector *flow_dissector,
73 void *target_container)
David S. Miller690e36e2014-08-23 12:13:41 -070074{
Jiri Pirko06635a32015-05-12 14:56:16 +020075 return __skb_flow_dissect(skb, flow_dissector, target_container,
76 NULL, 0, 0, 0);
77}
78
79struct 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
85extern struct flow_dissector flow_keys_dissector;
86extern struct flow_dissector flow_keys_buf_dissector;
87
88static 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
96static 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. Miller690e36e2014-08-23 12:13:41 -0700103}
Jiri Pirko1bd758e2015-05-12 14:56:07 +0200104
David S. Miller690e36e2014-08-23 12:13:41 -0700105__be32 __skb_flow_get_ports(const struct sk_buff *skb, int thoff, u8 ip_proto,
106 void *data, int hlen_proto);
Jiri Pirko1bd758e2015-05-12 14:56:07 +0200107
108static inline __be32 skb_flow_get_ports(const struct sk_buff *skb,
109 int thoff, u8 ip_proto)
David S. Miller690e36e2014-08-23 12:13:41 -0700110{
111 return __skb_flow_get_ports(skb, thoff, ip_proto, NULL, 0);
112}
Jiri Pirko1bd758e2015-05-12 14:56:07 +0200113
Tom Herbert5ed20a62014-07-01 21:32:05 -0700114u32 flow_hash_from_keys(struct flow_keys *keys);
Jiri Pirko9c684b52015-05-12 14:56:11 +0200115void __skb_get_hash(struct sk_buff *skb);
Jiri Pirko10b89ee42015-05-12 14:56:09 +0200116u32 skb_get_poff(const struct sk_buff *skb);
117u32 __skb_get_poff(const struct sk_buff *skb, void *data,
118 const struct flow_keys *keys, int hlen);
Jiri Pirko1bd758e2015-05-12 14:56:07 +0200119
Tom Herbert2f59e1e2015-05-01 11:30:17 -0700120/* 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
128struct flow_keys_digest {
129 u8 data[FLOW_KEYS_DIGEST_LEN];
130};
131
132void make_flow_keys_digest(struct flow_keys_digest *digest,
133 const struct flow_keys *flow);
134
Eric Dumazet0744dd02011-11-28 05:22:18 +0000135#endif