Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) #ifndef _NET_FLOW_DISSECTOR_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) #define _NET_FLOW_DISSECTOR_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <linux/in6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/siphash.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <uapi/linux/if_ether.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) struct bpf_prog;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) struct net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) struct sk_buff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  * struct flow_dissector_key_control:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  * @thoff: Transport header offset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) struct flow_dissector_key_control {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	u16	thoff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	u16	addr_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	u32	flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #define FLOW_DIS_IS_FRAGMENT	BIT(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define FLOW_DIS_FIRST_FRAG	BIT(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #define FLOW_DIS_ENCAPSULATION	BIT(2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) enum flow_dissect_ret {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	FLOW_DISSECT_RET_OUT_GOOD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	FLOW_DISSECT_RET_OUT_BAD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	FLOW_DISSECT_RET_PROTO_AGAIN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	FLOW_DISSECT_RET_IPPROTO_AGAIN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	FLOW_DISSECT_RET_CONTINUE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  * struct flow_dissector_key_basic:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  * @n_proto: Network header protocol (eg. IPv4/IPv6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  * @ip_proto: Transport header protocol (eg. TCP/UDP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) struct flow_dissector_key_basic {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	__be16	n_proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	u8	ip_proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	u8	padding;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) struct flow_dissector_key_tags {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	u32	flow_label;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) struct flow_dissector_key_vlan {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 			u16	vlan_id:12,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 				vlan_dei:1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 				vlan_priority:3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		__be16	vlan_tci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	__be16	vlan_tpid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) struct flow_dissector_mpls_lse {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	u32	mpls_ttl:8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		mpls_bos:1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		mpls_tc:3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		mpls_label:20;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) #define FLOW_DIS_MPLS_MAX 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) struct flow_dissector_key_mpls {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	struct flow_dissector_mpls_lse ls[FLOW_DIS_MPLS_MAX]; /* Label Stack */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	u8 used_lses; /* One bit set for each Label Stack Entry in use */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) static inline void dissector_set_mpls_lse(struct flow_dissector_key_mpls *mpls,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 					  int lse_index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	mpls->used_lses |= 1 << lse_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) #define FLOW_DIS_TUN_OPTS_MAX 255
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85)  * struct flow_dissector_key_enc_opts:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86)  * @data: tunnel option data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87)  * @len: length of tunnel option data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88)  * @dst_opt_type: tunnel option type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) struct flow_dissector_key_enc_opts {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	u8 data[FLOW_DIS_TUN_OPTS_MAX];	/* Using IP_TUNNEL_OPTS_MAX is desired
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 					 * here but seems difficult to #include
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 					 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	u8 len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	__be16 dst_opt_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) struct flow_dissector_key_keyid {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	__be32	keyid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)  * struct flow_dissector_key_ipv4_addrs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)  * @src: source ip address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)  * @dst: destination ip address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) struct flow_dissector_key_ipv4_addrs {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	/* (src,dst) must be grouped, in the same way than in IP header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	__be32 src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	__be32 dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)  * struct flow_dissector_key_ipv6_addrs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)  * @src: source ip address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)  * @dst: destination ip address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) struct flow_dissector_key_ipv6_addrs {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	/* (src,dst) must be grouped, in the same way than in IP header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	struct in6_addr src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	struct in6_addr dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)  * struct flow_dissector_key_tipc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)  * @key: source node address combined with selector
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) struct flow_dissector_key_tipc {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	__be32 key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)  * struct flow_dissector_key_addrs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)  * @v4addrs: IPv4 addresses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)  * @v6addrs: IPv6 addresses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) struct flow_dissector_key_addrs {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		struct flow_dissector_key_ipv4_addrs v4addrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		struct flow_dissector_key_ipv6_addrs v6addrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		struct flow_dissector_key_tipc tipckey;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)  * flow_dissector_key_arp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)  *	@ports: Operation, source and target addresses for an ARP header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)  *              for Ethernet hardware addresses and IPv4 protocol addresses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)  *		sip: Sender IP address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)  *		tip: Target IP address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)  *		op:  Operation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)  *		sha: Sender hardware address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)  *		tpa: Target hardware address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) struct flow_dissector_key_arp {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	__u32 sip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	__u32 tip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	__u8 op;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	unsigned char sha[ETH_ALEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	unsigned char tha[ETH_ALEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)  * flow_dissector_key_tp_ports:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)  *	@ports: port numbers of Transport header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)  *		src: source port number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)  *		dst: destination port number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) struct flow_dissector_key_ports {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		__be32 ports;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 			__be16 src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 			__be16 dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)  * flow_dissector_key_icmp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)  *		type: ICMP type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)  *		code: ICMP code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)  *		id:   session identifier
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) struct flow_dissector_key_icmp {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		u8 type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		u8 code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	u16 id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)  * struct flow_dissector_key_eth_addrs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)  * @src: source Ethernet address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)  * @dst: destination Ethernet address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) struct flow_dissector_key_eth_addrs {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	/* (dst,src) must be grouped, in the same way than in ETH header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	unsigned char dst[ETH_ALEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	unsigned char src[ETH_ALEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)  * struct flow_dissector_key_tcp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)  * @flags: flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) struct flow_dissector_key_tcp {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	__be16 flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)  * struct flow_dissector_key_ip:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)  * @tos: tos
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)  * @ttl: ttl
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) struct flow_dissector_key_ip {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	__u8	tos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	__u8	ttl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)  * struct flow_dissector_key_meta:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)  * @ingress_ifindex: ingress ifindex
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)  * @ingress_iftype: ingress interface type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) struct flow_dissector_key_meta {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	int ingress_ifindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	u16 ingress_iftype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)  * struct flow_dissector_key_ct:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)  * @ct_state: conntrack state after converting with map
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)  * @ct_mark: conttrack mark
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)  * @ct_zone: conntrack zone
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)  * @ct_labels: conntrack labels
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) struct flow_dissector_key_ct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	u16	ct_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	u16	ct_zone;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	u32	ct_mark;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	u32	ct_labels[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)  * struct flow_dissector_key_hash:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)  * @hash: hash value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) struct flow_dissector_key_hash {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	u32 hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) enum flow_dissector_key_id {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	FLOW_DISSECTOR_KEY_CONTROL, /* struct flow_dissector_key_control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	FLOW_DISSECTOR_KEY_BASIC, /* struct flow_dissector_key_basic */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	FLOW_DISSECTOR_KEY_IPV4_ADDRS, /* struct flow_dissector_key_ipv4_addrs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	FLOW_DISSECTOR_KEY_IPV6_ADDRS, /* struct flow_dissector_key_ipv6_addrs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	FLOW_DISSECTOR_KEY_PORTS, /* struct flow_dissector_key_ports */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	FLOW_DISSECTOR_KEY_PORTS_RANGE, /* struct flow_dissector_key_ports */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	FLOW_DISSECTOR_KEY_ICMP, /* struct flow_dissector_key_icmp */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	FLOW_DISSECTOR_KEY_ETH_ADDRS, /* struct flow_dissector_key_eth_addrs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	FLOW_DISSECTOR_KEY_TIPC, /* struct flow_dissector_key_tipc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	FLOW_DISSECTOR_KEY_ARP, /* struct flow_dissector_key_arp */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	FLOW_DISSECTOR_KEY_VLAN, /* struct flow_dissector_key_vlan */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	FLOW_DISSECTOR_KEY_FLOW_LABEL, /* struct flow_dissector_key_tags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	FLOW_DISSECTOR_KEY_GRE_KEYID, /* struct flow_dissector_key_keyid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	FLOW_DISSECTOR_KEY_MPLS_ENTROPY, /* struct flow_dissector_key_keyid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	FLOW_DISSECTOR_KEY_ENC_KEYID, /* struct flow_dissector_key_keyid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	FLOW_DISSECTOR_KEY_ENC_IPV4_ADDRS, /* struct flow_dissector_key_ipv4_addrs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	FLOW_DISSECTOR_KEY_ENC_IPV6_ADDRS, /* struct flow_dissector_key_ipv6_addrs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	FLOW_DISSECTOR_KEY_ENC_CONTROL, /* struct flow_dissector_key_control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	FLOW_DISSECTOR_KEY_ENC_PORTS, /* struct flow_dissector_key_ports */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	FLOW_DISSECTOR_KEY_MPLS, /* struct flow_dissector_key_mpls */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	FLOW_DISSECTOR_KEY_TCP, /* struct flow_dissector_key_tcp */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	FLOW_DISSECTOR_KEY_IP, /* struct flow_dissector_key_ip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	FLOW_DISSECTOR_KEY_CVLAN, /* struct flow_dissector_key_vlan */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	FLOW_DISSECTOR_KEY_ENC_IP, /* struct flow_dissector_key_ip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	FLOW_DISSECTOR_KEY_ENC_OPTS, /* struct flow_dissector_key_enc_opts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	FLOW_DISSECTOR_KEY_META, /* struct flow_dissector_key_meta */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	FLOW_DISSECTOR_KEY_CT, /* struct flow_dissector_key_ct */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	FLOW_DISSECTOR_KEY_HASH, /* struct flow_dissector_key_hash */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	FLOW_DISSECTOR_KEY_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) #define FLOW_DISSECTOR_F_PARSE_1ST_FRAG		BIT(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) #define FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL	BIT(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) #define FLOW_DISSECTOR_F_STOP_AT_ENCAP		BIT(2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) struct flow_dissector_key {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	enum flow_dissector_key_id key_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	size_t offset; /* offset of struct flow_dissector_key_*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 			  in target the struct */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) struct flow_dissector {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	unsigned int used_keys; /* each bit repesents presence of one key id */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	unsigned short int offset[FLOW_DISSECTOR_KEY_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) struct flow_keys_basic {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	struct flow_dissector_key_control control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	struct flow_dissector_key_basic basic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) struct flow_keys {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	struct flow_dissector_key_control control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) #define FLOW_KEYS_HASH_START_FIELD basic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	struct flow_dissector_key_basic basic __aligned(SIPHASH_ALIGNMENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	struct flow_dissector_key_tags tags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	struct flow_dissector_key_vlan vlan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	struct flow_dissector_key_vlan cvlan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	struct flow_dissector_key_keyid keyid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	struct flow_dissector_key_ports ports;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	struct flow_dissector_key_icmp icmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	/* 'addrs' must be the last member */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	struct flow_dissector_key_addrs addrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) #define FLOW_KEYS_HASH_OFFSET		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	offsetof(struct flow_keys, FLOW_KEYS_HASH_START_FIELD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) __be32 flow_get_u32_src(const struct flow_keys *flow);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) __be32 flow_get_u32_dst(const struct flow_keys *flow);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) extern struct flow_dissector flow_keys_dissector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) extern struct flow_dissector flow_keys_basic_dissector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) /* struct flow_keys_digest:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)  * This structure is used to hold a digest of the full flow keys. This is a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)  * larger "hash" of a flow to allow definitively matching specific flows where
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)  * the 32 bit skb->hash is not large enough. The size is limited to 16 bytes so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)  * that it can be used in CB of skb (see sch_choke for an example).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) #define FLOW_KEYS_DIGEST_LEN	16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) struct flow_keys_digest {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	u8	data[FLOW_KEYS_DIGEST_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) void make_flow_keys_digest(struct flow_keys_digest *digest,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 			   const struct flow_keys *flow);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) static inline bool flow_keys_have_l4(const struct flow_keys *keys)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	return (keys->ports.ports || keys->tags.flow_label);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) u32 flow_hash_from_keys(struct flow_keys *keys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) void skb_flow_get_icmp_tci(const struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 			   struct flow_dissector_key_icmp *key_icmp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 			   void *data, int thoff, int hlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) static inline bool dissector_uses_key(const struct flow_dissector *flow_dissector,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 				      enum flow_dissector_key_id key_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	return flow_dissector->used_keys & (1 << key_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) static inline void *skb_flow_dissector_target(struct flow_dissector *flow_dissector,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 					      enum flow_dissector_key_id key_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 					      void *target_container)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	return ((char *)target_container) + flow_dissector->offset[key_id];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) struct bpf_flow_dissector {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	struct bpf_flow_keys	*flow_keys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	const struct sk_buff	*skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	void			*data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	void			*data_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) flow_dissector_init_keys(struct flow_dissector_key_control *key_control,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 			 struct flow_dissector_key_basic *key_basic)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	memset(key_control, 0, sizeof(*key_control));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	memset(key_basic, 0, sizeof(*key_basic));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) #ifdef CONFIG_BPF_SYSCALL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) int flow_dissector_bpf_prog_attach_check(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 					 struct bpf_prog *prog);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) #endif /* CONFIG_BPF_SYSCALL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) #endif