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-or-later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * INET		An implementation of the TCP/IP protocol suite for the LINUX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *		operating system.  INET is implemented using the  BSD Socket
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *		interface as the means of communication with the user level.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *		Definitions for inet_sock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * Authors:	Many, reorganised here by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * 		Arnaldo Carvalho de Melo <acme@mandriva.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #ifndef _INET_SOCK_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #define _INET_SOCK_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/bitops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/jhash.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <net/flow.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <net/sock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <net/request_sock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <net/netns/hash.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <net/tcp_states.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <net/l3mdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) /** struct ip_options - IP Options
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  * @faddr - Saved first hop address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  * @nexthop - Saved nexthop address in LSRR and SSRR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  * @is_strictroute - Strict source route
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  * @srr_is_hit - Packet destination addr was our one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  * @is_changed - IP checksum more not valid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  * @rr_needaddr - Need to record addr of outgoing dev
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  * @ts_needtime - Need to record timestamp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  * @ts_needaddr - Need to record addr of outgoing dev
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) struct ip_options {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	__be32		faddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	__be32		nexthop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	unsigned char	optlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	unsigned char	srr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	unsigned char	rr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	unsigned char	ts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	unsigned char	is_strictroute:1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 			srr_is_hit:1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 			is_changed:1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 			rr_needaddr:1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 			ts_needtime:1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 			ts_needaddr:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	unsigned char	router_alert;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	unsigned char	cipso;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	unsigned char	__pad2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	unsigned char	__data[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) struct ip_options_rcu {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	struct rcu_head rcu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	struct ip_options opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) struct ip_options_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	struct ip_options_rcu	opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	char			data[40];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) struct inet_request_sock {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	struct request_sock	req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) #define ir_loc_addr		req.__req_common.skc_rcv_saddr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) #define ir_rmt_addr		req.__req_common.skc_daddr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) #define ir_num			req.__req_common.skc_num
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) #define ir_rmt_port		req.__req_common.skc_dport
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) #define ir_v6_rmt_addr		req.__req_common.skc_v6_daddr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) #define ir_v6_loc_addr		req.__req_common.skc_v6_rcv_saddr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) #define ir_iif			req.__req_common.skc_bound_dev_if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) #define ir_cookie		req.__req_common.skc_cookie
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) #define ireq_net		req.__req_common.skc_net
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) #define ireq_state		req.__req_common.skc_state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) #define ireq_family		req.__req_common.skc_family
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	u16			snd_wscale : 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 				rcv_wscale : 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 				tstamp_ok  : 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 				sack_ok	   : 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 				wscale_ok  : 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 				ecn_ok	   : 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 				acked	   : 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 				no_srccheck: 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 				smc_ok	   : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	u32                     ir_mark;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		struct ip_options_rcu __rcu	*ireq_opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) #if IS_ENABLED(CONFIG_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 			struct ipv6_txoptions	*ipv6_opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 			struct sk_buff		*pktopts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) #endif
^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) static inline struct inet_request_sock *inet_rsk(const struct request_sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	return (struct inet_request_sock *)sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) static inline u32 inet_request_mark(const struct sock *sk, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	if (!sk->sk_mark && sock_net(sk)->ipv4.sysctl_tcp_fwmark_accept)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		return skb->mark;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	return sk->sk_mark;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) static inline int inet_request_bound_dev_if(const struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 					    struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) #ifdef CONFIG_NET_L3_MASTER_DEV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	struct net *net = sock_net(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	if (!sk->sk_bound_dev_if && net->ipv4.sysctl_tcp_l3mdev_accept)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		return l3mdev_master_ifindex_by_index(net, skb->skb_iif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	return sk->sk_bound_dev_if;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) static inline int inet_sk_bound_l3mdev(const struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) #ifdef CONFIG_NET_L3_MASTER_DEV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	struct net *net = sock_net(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	if (!net->ipv4.sysctl_tcp_l3mdev_accept)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		return l3mdev_master_ifindex_by_index(net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 						      sk->sk_bound_dev_if);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) static inline bool inet_bound_dev_eq(bool l3mdev_accept, int bound_dev_if,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 				     int dif, int sdif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	if (!bound_dev_if)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		return !sdif || l3mdev_accept;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	return bound_dev_if == dif || bound_dev_if == sdif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) struct inet_cork {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	unsigned int		flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	__be32			addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	struct ip_options	*opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	unsigned int		fragsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	int			length; /* Total length of all frames */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	struct dst_entry	*dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	u8			tx_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	__u8			ttl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	__s16			tos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	char			priority;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	__u16			gso_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	u64			transmit_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	u32			mark;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) struct inet_cork_full {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	struct inet_cork	base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	struct flowi		fl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) struct ip_mc_socklist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) struct ipv6_pinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) struct rtable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) /** struct inet_sock - representation of INET sockets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)  * @sk - ancestor class
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)  * @pinet6 - pointer to IPv6 control block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)  * @inet_daddr - Foreign IPv4 addr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)  * @inet_rcv_saddr - Bound local IPv4 addr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)  * @inet_dport - Destination port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)  * @inet_num - Local port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)  * @inet_saddr - Sending source
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)  * @uc_ttl - Unicast TTL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)  * @inet_sport - Source port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)  * @inet_id - ID counter for DF pkts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)  * @tos - TOS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)  * @mc_ttl - Multicasting TTL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)  * @is_icsk - is this an inet_connection_sock?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)  * @uc_index - Unicast outgoing device index
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)  * @mc_index - Multicast device index
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)  * @mc_list - Group array
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)  * @cork - info to build ip hdr on each ip frag while socket is corked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) struct inet_sock {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	/* sk and pinet6 has to be the first two members of inet_sock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	struct sock		sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) #if IS_ENABLED(CONFIG_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	struct ipv6_pinfo	*pinet6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	/* Socket demultiplex comparisons on incoming packets. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) #define inet_daddr		sk.__sk_common.skc_daddr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) #define inet_rcv_saddr		sk.__sk_common.skc_rcv_saddr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) #define inet_dport		sk.__sk_common.skc_dport
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) #define inet_num		sk.__sk_common.skc_num
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	__be32			inet_saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	__s16			uc_ttl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	__u16			cmsg_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	__be16			inet_sport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	__u16			inet_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	struct ip_options_rcu __rcu	*inet_opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	int			rx_dst_ifindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	__u8			tos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	__u8			min_ttl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	__u8			mc_ttl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	__u8			pmtudisc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	__u8			recverr:1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 				is_icsk:1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 				freebind:1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 				hdrincl:1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 				mc_loop:1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 				transparent:1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 				mc_all:1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 				nodefrag:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	__u8			bind_address_no_port:1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 				recverr_rfc4884:1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 				defer_connect:1; /* Indicates that fastopen_connect is set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 						  * and cookie exists so we defer connect
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 						  * until first data frame is written
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 						  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	__u8			rcv_tos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	__u8			convert_csum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	int			uc_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	int			mc_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	__be32			mc_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	struct ip_mc_socklist __rcu	*mc_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	struct inet_cork_full	cork;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) #define IPCORK_OPT	1	/* ip-options has been held in ipcork.opt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) #define IPCORK_ALLFRAG	2	/* always fragment (for ipv6 for now) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) /* cmsg flags for inet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) #define IP_CMSG_PKTINFO		BIT(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) #define IP_CMSG_TTL		BIT(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) #define IP_CMSG_TOS		BIT(2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) #define IP_CMSG_RECVOPTS	BIT(3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) #define IP_CMSG_RETOPTS		BIT(4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) #define IP_CMSG_PASSSEC		BIT(5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) #define IP_CMSG_ORIGDSTADDR	BIT(6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) #define IP_CMSG_CHECKSUM	BIT(7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) #define IP_CMSG_RECVFRAGSIZE	BIT(8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)  * sk_to_full_sk - Access to a full socket
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)  * @sk: pointer to a socket
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)  * SYNACK messages might be attached to request sockets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)  * Some places want to reach the listener in this case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) static inline struct sock *sk_to_full_sk(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) #ifdef CONFIG_INET
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	if (sk && sk->sk_state == TCP_NEW_SYN_RECV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		sk = inet_reqsk(sk)->rsk_listener;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	return sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) /* sk_to_full_sk() variant with a const argument */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) static inline const struct sock *sk_const_to_full_sk(const struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) #ifdef CONFIG_INET
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	if (sk && sk->sk_state == TCP_NEW_SYN_RECV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		sk = ((const struct request_sock *)sk)->rsk_listener;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	return sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) static inline struct sock *skb_to_full_sk(const struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	return sk_to_full_sk(skb->sk);
^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) static inline struct inet_sock *inet_sk(const struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	return (struct inet_sock *)sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) static inline void __inet_sk_copy_descendant(struct sock *sk_to,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 					     const struct sock *sk_from,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 					     const int ancestor_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	memcpy(inet_sk(sk_to) + 1, inet_sk(sk_from) + 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	       sk_from->sk_prot->obj_size - ancestor_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) int inet_sk_rebuild_header(struct sock *sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)  * inet_sk_state_load - read sk->sk_state for lockless contexts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)  * @sk: socket pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)  * Paired with inet_sk_state_store(). Used in places we don't hold socket lock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)  * tcp_diag_get_info(), tcp_get_info(), tcp_poll(), get_tcp4_sock() ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) static inline int inet_sk_state_load(const struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	/* state change might impact lockless readers. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	return smp_load_acquire(&sk->sk_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)  * inet_sk_state_store - update sk->sk_state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)  * @sk: socket pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)  * @newstate: new state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)  * Paired with inet_sk_state_load(). Should be used in contexts where
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)  * state change might impact lockless readers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) void inet_sk_state_store(struct sock *sk, int newstate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) void inet_sk_set_state(struct sock *sk, int state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) static inline unsigned int __inet_ehashfn(const __be32 laddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 					  const __u16 lport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 					  const __be32 faddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 					  const __be16 fport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 					  u32 initval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	return jhash_3words((__force __u32) laddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 			    (__force __u32) faddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 			    ((__u32) lport) << 16 | (__force __u32)fport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 			    initval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) struct request_sock *inet_reqsk_alloc(const struct request_sock_ops *ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 				      struct sock *sk_listener,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 				      bool attach_listener);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) static inline __u8 inet_sk_flowi_flags(const struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	__u8 flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	if (inet_sk(sk)->transparent || inet_sk(sk)->hdrincl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 		flags |= FLOWI_FLAG_ANYSRC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	return flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) static inline void inet_inc_convert_csum(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	inet_sk(sk)->convert_csum++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) static inline void inet_dec_convert_csum(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	if (inet_sk(sk)->convert_csum > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 		inet_sk(sk)->convert_csum--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) static inline bool inet_get_convert_csum(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	return !!inet_sk(sk)->convert_csum;
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) static inline bool inet_can_nonlocal_bind(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 					  struct inet_sock *inet)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	return net->ipv4.sysctl_ip_nonlocal_bind ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 		inet->freebind || inet->transparent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) #endif	/* _INET_SOCK_H */