11bd758ebSJiri Pirko #ifndef _NET_FLOW_DISSECTOR_H 21bd758ebSJiri Pirko #define _NET_FLOW_DISSECTOR_H 31bd758ebSJiri Pirko 4c3f8eaebSJiri Pirko #include <linux/types.h> 5b924933cSJiri Pirko #include <linux/in6.h> 667a900ccSJiri Pirko #include <uapi/linux/if_ether.h> 7c3f8eaebSJiri Pirko 8fbff949eSJiri Pirko /** 942aecaa9STom Herbert * struct flow_dissector_key_control: 1042aecaa9STom Herbert * @thoff: Transport header offset 1142aecaa9STom Herbert */ 1242aecaa9STom Herbert struct flow_dissector_key_control { 1342aecaa9STom Herbert u16 thoff; 14c3f83241STom Herbert u16 addr_type; 154b36993dSDavid S. Miller u32 flags; 1642aecaa9STom Herbert }; 1742aecaa9STom Herbert 184b36993dSDavid S. Miller #define FLOW_DIS_IS_FRAGMENT BIT(0) 194b36993dSDavid S. Miller #define FLOW_DIS_FIRST_FRAG BIT(1) 204b36993dSDavid S. Miller #define FLOW_DIS_ENCAPSULATION BIT(2) 214b36993dSDavid S. Miller 2242aecaa9STom Herbert /** 23fbff949eSJiri Pirko * struct flow_dissector_key_basic: 24fbff949eSJiri Pirko * @thoff: Transport header offset 25fbff949eSJiri Pirko * @n_proto: Network header protocol (eg. IPv4/IPv6) 26fbff949eSJiri Pirko * @ip_proto: Transport header protocol (eg. TCP/UDP) 27fbff949eSJiri Pirko */ 28fbff949eSJiri Pirko struct flow_dissector_key_basic { 29fbff949eSJiri Pirko __be16 n_proto; 30fbff949eSJiri Pirko u8 ip_proto; 3142aecaa9STom Herbert u8 padding; 32fbff949eSJiri Pirko }; 33fbff949eSJiri Pirko 34d34af823STom Herbert struct flow_dissector_key_tags { 35*f6a66927SHadar Hen Zion u32 flow_label; 36*f6a66927SHadar Hen Zion }; 37*f6a66927SHadar Hen Zion 38*f6a66927SHadar Hen Zion struct flow_dissector_key_vlan { 39*f6a66927SHadar Hen Zion u16 vlan_id:12, 40*f6a66927SHadar Hen Zion vlan_priority:3; 41*f6a66927SHadar Hen Zion u16 padding; 42d34af823STom Herbert }; 43d34af823STom Herbert 441fdd512cSTom Herbert struct flow_dissector_key_keyid { 451fdd512cSTom Herbert __be32 keyid; 461fdd512cSTom Herbert }; 471fdd512cSTom Herbert 48fbff949eSJiri Pirko /** 49c3f83241STom Herbert * struct flow_dissector_key_ipv4_addrs: 50c3f83241STom Herbert * @src: source ip address 51c3f83241STom Herbert * @dst: destination ip address 52fbff949eSJiri Pirko */ 53c3f83241STom Herbert struct flow_dissector_key_ipv4_addrs { 54fbff949eSJiri Pirko /* (src,dst) must be grouped, in the same way than in IP header */ 55fbff949eSJiri Pirko __be32 src; 56fbff949eSJiri Pirko __be32 dst; 57fbff949eSJiri Pirko }; 58fbff949eSJiri Pirko 59fbff949eSJiri Pirko /** 60c3f83241STom Herbert * struct flow_dissector_key_ipv6_addrs: 61c3f83241STom Herbert * @src: source ip address 62c3f83241STom Herbert * @dst: destination ip address 63c3f83241STom Herbert */ 64c3f83241STom Herbert struct flow_dissector_key_ipv6_addrs { 65c3f83241STom Herbert /* (src,dst) must be grouped, in the same way than in IP header */ 66c3f83241STom Herbert struct in6_addr src; 67c3f83241STom Herbert struct in6_addr dst; 68c3f83241STom Herbert }; 69c3f83241STom Herbert 70c3f83241STom Herbert /** 719f249089STom Herbert * struct flow_dissector_key_tipc_addrs: 729f249089STom Herbert * @srcnode: source node address 739f249089STom Herbert */ 749f249089STom Herbert struct flow_dissector_key_tipc_addrs { 759f249089STom Herbert __be32 srcnode; 769f249089STom Herbert }; 779f249089STom Herbert 789f249089STom Herbert /** 79c3f83241STom Herbert * struct flow_dissector_key_addrs: 80c3f83241STom Herbert * @v4addrs: IPv4 addresses 81c3f83241STom Herbert * @v6addrs: IPv6 addresses 82c3f83241STom Herbert */ 83c3f83241STom Herbert struct flow_dissector_key_addrs { 84c3f83241STom Herbert union { 85c3f83241STom Herbert struct flow_dissector_key_ipv4_addrs v4addrs; 86c3f83241STom Herbert struct flow_dissector_key_ipv6_addrs v6addrs; 879f249089STom Herbert struct flow_dissector_key_tipc_addrs tipcaddrs; 88c3f83241STom Herbert }; 89c3f83241STom Herbert }; 90c3f83241STom Herbert 91c3f83241STom Herbert /** 92fbff949eSJiri Pirko * flow_dissector_key_tp_ports: 93fbff949eSJiri Pirko * @ports: port numbers of Transport header 9459346afeSJiri Pirko * src: source port number 9559346afeSJiri Pirko * dst: destination port number 96fbff949eSJiri Pirko */ 97fbff949eSJiri Pirko struct flow_dissector_key_ports { 98fbff949eSJiri Pirko union { 99fbff949eSJiri Pirko __be32 ports; 10059346afeSJiri Pirko struct { 10159346afeSJiri Pirko __be16 src; 10259346afeSJiri Pirko __be16 dst; 10359346afeSJiri Pirko }; 104fbff949eSJiri Pirko }; 105fbff949eSJiri Pirko }; 106fbff949eSJiri Pirko 107b924933cSJiri Pirko 10867a900ccSJiri Pirko /** 10967a900ccSJiri Pirko * struct flow_dissector_key_eth_addrs: 11067a900ccSJiri Pirko * @src: source Ethernet address 11167a900ccSJiri Pirko * @dst: destination Ethernet address 11267a900ccSJiri Pirko */ 11367a900ccSJiri Pirko struct flow_dissector_key_eth_addrs { 11467a900ccSJiri Pirko /* (dst,src) must be grouped, in the same way than in ETH header */ 11567a900ccSJiri Pirko unsigned char dst[ETH_ALEN]; 11667a900ccSJiri Pirko unsigned char src[ETH_ALEN]; 11767a900ccSJiri Pirko }; 11867a900ccSJiri Pirko 119fbff949eSJiri Pirko enum flow_dissector_key_id { 12042aecaa9STom Herbert FLOW_DISSECTOR_KEY_CONTROL, /* struct flow_dissector_key_control */ 121fbff949eSJiri Pirko FLOW_DISSECTOR_KEY_BASIC, /* struct flow_dissector_key_basic */ 122c3f83241STom Herbert FLOW_DISSECTOR_KEY_IPV4_ADDRS, /* struct flow_dissector_key_ipv4_addrs */ 123c3f83241STom Herbert FLOW_DISSECTOR_KEY_IPV6_ADDRS, /* struct flow_dissector_key_ipv6_addrs */ 124fbff949eSJiri Pirko FLOW_DISSECTOR_KEY_PORTS, /* struct flow_dissector_key_ports */ 12567a900ccSJiri Pirko FLOW_DISSECTOR_KEY_ETH_ADDRS, /* struct flow_dissector_key_eth_addrs */ 1269f249089STom Herbert FLOW_DISSECTOR_KEY_TIPC_ADDRS, /* struct flow_dissector_key_tipc_addrs */ 127*f6a66927SHadar Hen Zion FLOW_DISSECTOR_KEY_VLAN, /* struct flow_dissector_key_flow_vlan */ 12887ee9e52STom Herbert FLOW_DISSECTOR_KEY_FLOW_LABEL, /* struct flow_dissector_key_flow_tags */ 1291fdd512cSTom Herbert FLOW_DISSECTOR_KEY_GRE_KEYID, /* struct flow_dissector_key_keyid */ 130b3baa0fbSTom Herbert FLOW_DISSECTOR_KEY_MPLS_ENTROPY, /* struct flow_dissector_key_keyid */ 131fbff949eSJiri Pirko 132fbff949eSJiri Pirko FLOW_DISSECTOR_KEY_MAX, 133fbff949eSJiri Pirko }; 134fbff949eSJiri Pirko 135807e165dSTom Herbert #define FLOW_DISSECTOR_F_PARSE_1ST_FRAG BIT(0) 1368306b688STom Herbert #define FLOW_DISSECTOR_F_STOP_AT_L3 BIT(1) 137872b1abbSTom Herbert #define FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL BIT(2) 138823b9693STom Herbert #define FLOW_DISSECTOR_F_STOP_AT_ENCAP BIT(3) 139807e165dSTom Herbert 140fbff949eSJiri Pirko struct flow_dissector_key { 141fbff949eSJiri Pirko enum flow_dissector_key_id key_id; 142fbff949eSJiri Pirko size_t offset; /* offset of struct flow_dissector_key_* 143fbff949eSJiri Pirko in target the struct */ 144fbff949eSJiri Pirko }; 145fbff949eSJiri Pirko 146fbff949eSJiri Pirko struct flow_dissector { 147fbff949eSJiri Pirko unsigned int used_keys; /* each bit repesents presence of one key id */ 148fbff949eSJiri Pirko unsigned short int offset[FLOW_DISSECTOR_KEY_MAX]; 149fbff949eSJiri Pirko }; 150fbff949eSJiri Pirko 15106635a35SJiri Pirko struct flow_keys { 15242aecaa9STom Herbert struct flow_dissector_key_control control; 15342aecaa9STom Herbert #define FLOW_KEYS_HASH_START_FIELD basic 15406635a35SJiri Pirko struct flow_dissector_key_basic basic; 155d34af823STom Herbert struct flow_dissector_key_tags tags; 156*f6a66927SHadar Hen Zion struct flow_dissector_key_vlan vlan; 1571fdd512cSTom Herbert struct flow_dissector_key_keyid keyid; 15842aecaa9STom Herbert struct flow_dissector_key_ports ports; 15942aecaa9STom Herbert struct flow_dissector_key_addrs addrs; 16006635a35SJiri Pirko }; 16106635a35SJiri Pirko 16242aecaa9STom Herbert #define FLOW_KEYS_HASH_OFFSET \ 16342aecaa9STom Herbert offsetof(struct flow_keys, FLOW_KEYS_HASH_START_FIELD) 16442aecaa9STom Herbert 165c3f83241STom Herbert __be32 flow_get_u32_src(const struct flow_keys *flow); 166c3f83241STom Herbert __be32 flow_get_u32_dst(const struct flow_keys *flow); 167c3f83241STom Herbert 16806635a35SJiri Pirko extern struct flow_dissector flow_keys_dissector; 16906635a35SJiri Pirko extern struct flow_dissector flow_keys_buf_dissector; 17006635a35SJiri Pirko 1711bd758ebSJiri Pirko /* struct flow_keys_digest: 1721bd758ebSJiri Pirko * 1731bd758ebSJiri Pirko * This structure is used to hold a digest of the full flow keys. This is a 1741bd758ebSJiri Pirko * larger "hash" of a flow to allow definitively matching specific flows where 1751bd758ebSJiri Pirko * the 32 bit skb->hash is not large enough. The size is limited to 16 bytes so 1761bd758ebSJiri Pirko * that it can by used in CB of skb (see sch_choke for an example). 1771bd758ebSJiri Pirko */ 1781bd758ebSJiri Pirko #define FLOW_KEYS_DIGEST_LEN 16 1791bd758ebSJiri Pirko struct flow_keys_digest { 1801bd758ebSJiri Pirko u8 data[FLOW_KEYS_DIGEST_LEN]; 1811bd758ebSJiri Pirko }; 1821bd758ebSJiri Pirko 1831bd758ebSJiri Pirko void make_flow_keys_digest(struct flow_keys_digest *digest, 1841bd758ebSJiri Pirko const struct flow_keys *flow); 1851bd758ebSJiri Pirko 186bcc83839STom Herbert static inline bool flow_keys_have_l4(struct flow_keys *keys) 187bcc83839STom Herbert { 188bcc83839STom Herbert return (keys->ports.ports || keys->tags.flow_label); 189bcc83839STom Herbert } 190bcc83839STom Herbert 191c6cc1ca7STom Herbert u32 flow_hash_from_keys(struct flow_keys *keys); 192c6cc1ca7STom Herbert 1938de2d793SAmir Vadai static inline bool dissector_uses_key(const struct flow_dissector *flow_dissector, 1948de2d793SAmir Vadai enum flow_dissector_key_id key_id) 1958de2d793SAmir Vadai { 1968de2d793SAmir Vadai return flow_dissector->used_keys & (1 << key_id); 1978de2d793SAmir Vadai } 1988de2d793SAmir Vadai 1998de2d793SAmir Vadai static inline void *skb_flow_dissector_target(struct flow_dissector *flow_dissector, 2008de2d793SAmir Vadai enum flow_dissector_key_id key_id, 2018de2d793SAmir Vadai void *target_container) 2028de2d793SAmir Vadai { 2038de2d793SAmir Vadai return ((char *)target_container) + flow_dissector->offset[key_id]; 2048de2d793SAmir Vadai } 2058de2d793SAmir Vadai 2061bd758ebSJiri Pirko #endif 207