blob: 20239e807f77bb676817cba9b941324ef8f2535a [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
Govindarajulu Varadarajane0f31d82014-06-23 16:07:58 +053062/* 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 Dumazet0744dd02011-11-28 05:22:18 +000075struct flow_keys {
Eric Dumazet4d77d2b2011-11-28 20:30:35 +000076 /* (src,dst) must be grouped, in the same way than in IP header */
Eric Dumazet0744dd02011-11-28 05:22:18 +000077 __be32 src;
78 __be32 dst;
79 union {
80 __be32 ports;
81 __be16 port16[2];
82 };
Eric Dumazetf4575d32015-02-04 13:31:54 -080083 u16 thoff;
84 __be16 n_proto;
85 u8 ip_proto;
Eric Dumazet0744dd02011-11-28 05:22:18 +000086};
87
Jiri Pirkofbff9492015-05-12 14:56:15 +020088void skb_flow_dissector_init(struct flow_dissector *flow_dissector,
89 const struct flow_dissector_key *key,
90 unsigned int key_count);
David S. Miller690e36e2014-08-23 12:13:41 -070091bool __skb_flow_dissect(const struct sk_buff *skb, struct flow_keys *flow,
WANG Cong453a9402014-08-25 17:03:47 -070092 void *data, __be16 proto, int nhoff, int hlen);
Jiri Pirko1bd758e2015-05-12 14:56:07 +020093
94static inline bool skb_flow_dissect(const struct sk_buff *skb,
95 struct flow_keys *flow)
David S. Miller690e36e2014-08-23 12:13:41 -070096{
WANG Cong453a9402014-08-25 17:03:47 -070097 return __skb_flow_dissect(skb, flow, NULL, 0, 0, 0);
David S. Miller690e36e2014-08-23 12:13:41 -070098}
Jiri Pirko1bd758e2015-05-12 14:56:07 +020099
David S. Miller690e36e2014-08-23 12:13:41 -0700100__be32 __skb_flow_get_ports(const struct sk_buff *skb, int thoff, u8 ip_proto,
101 void *data, int hlen_proto);
Jiri Pirko1bd758e2015-05-12 14:56:07 +0200102
103static inline __be32 skb_flow_get_ports(const struct sk_buff *skb,
104 int thoff, u8 ip_proto)
David S. Miller690e36e2014-08-23 12:13:41 -0700105{
106 return __skb_flow_get_ports(skb, thoff, ip_proto, NULL, 0);
107}
Jiri Pirko1bd758e2015-05-12 14:56:07 +0200108
Tom Herbert5ed20a62014-07-01 21:32:05 -0700109u32 flow_hash_from_keys(struct flow_keys *keys);
Jiri Pirko9c684b52015-05-12 14:56:11 +0200110void __skb_get_hash(struct sk_buff *skb);
Jiri Pirko10b89ee42015-05-12 14:56:09 +0200111u32 skb_get_poff(const struct sk_buff *skb);
112u32 __skb_get_poff(const struct sk_buff *skb, void *data,
113 const struct flow_keys *keys, int hlen);
Jiri Pirko1bd758e2015-05-12 14:56:07 +0200114
Tom Herbert2f59e1e2015-05-01 11:30:17 -0700115/* 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
123struct flow_keys_digest {
124 u8 data[FLOW_KEYS_DIGEST_LEN];
125};
126
127void make_flow_keys_digest(struct flow_keys_digest *digest,
128 const struct flow_keys *flow);
129
Eric Dumazet0744dd02011-11-28 05:22:18 +0000130#endif