xref: /openbmc/linux/include/net/flow_dissector.h (revision 1bd758eb1cab2fa5b71a23f9e5d3c8076f4ed650)
1*1bd758ebSJiri Pirko #ifndef _NET_FLOW_DISSECTOR_H
2*1bd758ebSJiri Pirko #define _NET_FLOW_DISSECTOR_H
3*1bd758ebSJiri Pirko 
4*1bd758ebSJiri Pirko /* struct flow_keys:
5*1bd758ebSJiri Pirko  *	@src: source ip address in case of IPv4
6*1bd758ebSJiri Pirko  *	      For IPv6 it contains 32bit hash of src address
7*1bd758ebSJiri Pirko  *	@dst: destination ip address in case of IPv4
8*1bd758ebSJiri Pirko  *	      For IPv6 it contains 32bit hash of dst address
9*1bd758ebSJiri Pirko  *	@ports: port numbers of Transport header
10*1bd758ebSJiri Pirko  *		port16[0]: src port number
11*1bd758ebSJiri Pirko  *		port16[1]: dst port number
12*1bd758ebSJiri Pirko  *	@thoff: Transport header offset
13*1bd758ebSJiri Pirko  *	@n_proto: Network header protocol (eg. IPv4/IPv6)
14*1bd758ebSJiri Pirko  *	@ip_proto: Transport header protocol (eg. TCP/UDP)
15*1bd758ebSJiri Pirko  * All the members, except thoff, are in network byte order.
16*1bd758ebSJiri Pirko  */
17*1bd758ebSJiri Pirko struct flow_keys {
18*1bd758ebSJiri Pirko 	/* (src,dst) must be grouped, in the same way than in IP header */
19*1bd758ebSJiri Pirko 	__be32 src;
20*1bd758ebSJiri Pirko 	__be32 dst;
21*1bd758ebSJiri Pirko 	union {
22*1bd758ebSJiri Pirko 		__be32 ports;
23*1bd758ebSJiri Pirko 		__be16 port16[2];
24*1bd758ebSJiri Pirko 	};
25*1bd758ebSJiri Pirko 	u16	thoff;
26*1bd758ebSJiri Pirko 	__be16	n_proto;
27*1bd758ebSJiri Pirko 	u8	ip_proto;
28*1bd758ebSJiri Pirko };
29*1bd758ebSJiri Pirko 
30*1bd758ebSJiri Pirko bool __skb_flow_dissect(const struct sk_buff *skb, struct flow_keys *flow,
31*1bd758ebSJiri Pirko 			void *data, __be16 proto, int nhoff, int hlen);
32*1bd758ebSJiri Pirko 
33*1bd758ebSJiri Pirko static inline bool skb_flow_dissect(const struct sk_buff *skb,
34*1bd758ebSJiri Pirko 				    struct flow_keys *flow)
35*1bd758ebSJiri Pirko {
36*1bd758ebSJiri Pirko 	return __skb_flow_dissect(skb, flow, NULL, 0, 0, 0);
37*1bd758ebSJiri Pirko }
38*1bd758ebSJiri Pirko 
39*1bd758ebSJiri Pirko __be32 __skb_flow_get_ports(const struct sk_buff *skb, int thoff, u8 ip_proto,
40*1bd758ebSJiri Pirko 			    void *data, int hlen_proto);
41*1bd758ebSJiri Pirko 
42*1bd758ebSJiri Pirko static inline __be32 skb_flow_get_ports(const struct sk_buff *skb,
43*1bd758ebSJiri Pirko 					int thoff, u8 ip_proto)
44*1bd758ebSJiri Pirko {
45*1bd758ebSJiri Pirko 	return __skb_flow_get_ports(skb, thoff, ip_proto, NULL, 0);
46*1bd758ebSJiri Pirko }
47*1bd758ebSJiri Pirko 
48*1bd758ebSJiri Pirko u32 flow_hash_from_keys(struct flow_keys *keys);
49*1bd758ebSJiri Pirko 
50*1bd758ebSJiri Pirko unsigned int flow_get_hlen(const unsigned char *data, unsigned int max_len,
51*1bd758ebSJiri Pirko 			   __be16 protocol);
52*1bd758ebSJiri Pirko 
53*1bd758ebSJiri Pirko /* struct flow_keys_digest:
54*1bd758ebSJiri Pirko  *
55*1bd758ebSJiri Pirko  * This structure is used to hold a digest of the full flow keys. This is a
56*1bd758ebSJiri Pirko  * larger "hash" of a flow to allow definitively matching specific flows where
57*1bd758ebSJiri Pirko  * the 32 bit skb->hash is not large enough. The size is limited to 16 bytes so
58*1bd758ebSJiri Pirko  * that it can by used in CB of skb (see sch_choke for an example).
59*1bd758ebSJiri Pirko  */
60*1bd758ebSJiri Pirko #define FLOW_KEYS_DIGEST_LEN	16
61*1bd758ebSJiri Pirko struct flow_keys_digest {
62*1bd758ebSJiri Pirko 	u8	data[FLOW_KEYS_DIGEST_LEN];
63*1bd758ebSJiri Pirko };
64*1bd758ebSJiri Pirko 
65*1bd758ebSJiri Pirko void make_flow_keys_digest(struct flow_keys_digest *digest,
66*1bd758ebSJiri Pirko 			   const struct flow_keys *flow);
67*1bd758ebSJiri Pirko 
68*1bd758ebSJiri Pirko #endif
69