18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * INET		An implementation of the TCP/IP protocol suite for the LINUX
48c2ecf20Sopenharmony_ci *		operating system.  INET is implemented using the  BSD Socket
58c2ecf20Sopenharmony_ci *		interface as the means of communication with the user level.
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci *		Definitions for a generic INET TIMEWAIT sock
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci *		From code originally in net/tcp.h
108c2ecf20Sopenharmony_ci */
118c2ecf20Sopenharmony_ci#ifndef _INET_TIMEWAIT_SOCK_
128c2ecf20Sopenharmony_ci#define _INET_TIMEWAIT_SOCK_
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#include <linux/list.h>
158c2ecf20Sopenharmony_ci#include <linux/timer.h>
168c2ecf20Sopenharmony_ci#include <linux/types.h>
178c2ecf20Sopenharmony_ci#include <linux/workqueue.h>
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci#include <net/inet_sock.h>
208c2ecf20Sopenharmony_ci#include <net/sock.h>
218c2ecf20Sopenharmony_ci#include <net/tcp_states.h>
228c2ecf20Sopenharmony_ci#include <net/timewait_sock.h>
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci#include <linux/atomic.h>
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_cistruct inet_bind_bucket;
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci/*
298c2ecf20Sopenharmony_ci * This is a TIME_WAIT sock. It works around the memory consumption
308c2ecf20Sopenharmony_ci * problems of sockets in such a state on heavily loaded servers, but
318c2ecf20Sopenharmony_ci * without violating the protocol specification.
328c2ecf20Sopenharmony_ci */
338c2ecf20Sopenharmony_cistruct inet_timewait_sock {
348c2ecf20Sopenharmony_ci	/*
358c2ecf20Sopenharmony_ci	 * Now struct sock also uses sock_common, so please just
368c2ecf20Sopenharmony_ci	 * don't add nothing before this first member (__tw_common) --acme
378c2ecf20Sopenharmony_ci	 */
388c2ecf20Sopenharmony_ci	struct sock_common	__tw_common;
398c2ecf20Sopenharmony_ci#define tw_family		__tw_common.skc_family
408c2ecf20Sopenharmony_ci#define tw_state		__tw_common.skc_state
418c2ecf20Sopenharmony_ci#define tw_reuse		__tw_common.skc_reuse
428c2ecf20Sopenharmony_ci#define tw_reuseport		__tw_common.skc_reuseport
438c2ecf20Sopenharmony_ci#define tw_ipv6only		__tw_common.skc_ipv6only
448c2ecf20Sopenharmony_ci#define tw_bound_dev_if		__tw_common.skc_bound_dev_if
458c2ecf20Sopenharmony_ci#define tw_node			__tw_common.skc_nulls_node
468c2ecf20Sopenharmony_ci#define tw_bind_node		__tw_common.skc_bind_node
478c2ecf20Sopenharmony_ci#define tw_refcnt		__tw_common.skc_refcnt
488c2ecf20Sopenharmony_ci#define tw_hash			__tw_common.skc_hash
498c2ecf20Sopenharmony_ci#define tw_prot			__tw_common.skc_prot
508c2ecf20Sopenharmony_ci#define tw_net			__tw_common.skc_net
518c2ecf20Sopenharmony_ci#define tw_daddr        	__tw_common.skc_daddr
528c2ecf20Sopenharmony_ci#define tw_v6_daddr		__tw_common.skc_v6_daddr
538c2ecf20Sopenharmony_ci#define tw_rcv_saddr    	__tw_common.skc_rcv_saddr
548c2ecf20Sopenharmony_ci#define tw_v6_rcv_saddr    	__tw_common.skc_v6_rcv_saddr
558c2ecf20Sopenharmony_ci#define tw_dport		__tw_common.skc_dport
568c2ecf20Sopenharmony_ci#define tw_num			__tw_common.skc_num
578c2ecf20Sopenharmony_ci#define tw_cookie		__tw_common.skc_cookie
588c2ecf20Sopenharmony_ci#define tw_dr			__tw_common.skc_tw_dr
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci	__u32			tw_mark;
618c2ecf20Sopenharmony_ci	volatile unsigned char	tw_substate;
628c2ecf20Sopenharmony_ci	unsigned char		tw_rcv_wscale;
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci	/* Socket demultiplex comparisons on incoming packets. */
658c2ecf20Sopenharmony_ci	/* these three are in inet_sock */
668c2ecf20Sopenharmony_ci	__be16			tw_sport;
678c2ecf20Sopenharmony_ci	/* And these are ours. */
688c2ecf20Sopenharmony_ci	unsigned int		tw_kill		: 1,
698c2ecf20Sopenharmony_ci				tw_transparent  : 1,
708c2ecf20Sopenharmony_ci				tw_flowlabel	: 20,
718c2ecf20Sopenharmony_ci				tw_pad		: 2,	/* 2 bits hole */
728c2ecf20Sopenharmony_ci				tw_tos		: 8;
738c2ecf20Sopenharmony_ci	u32			tw_txhash;
748c2ecf20Sopenharmony_ci	u32			tw_priority;
758c2ecf20Sopenharmony_ci	struct timer_list	tw_timer;
768c2ecf20Sopenharmony_ci	struct inet_bind_bucket	*tw_tb;
778c2ecf20Sopenharmony_ci};
788c2ecf20Sopenharmony_ci#define tw_tclass tw_tos
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_cistatic inline struct inet_timewait_sock *inet_twsk(const struct sock *sk)
818c2ecf20Sopenharmony_ci{
828c2ecf20Sopenharmony_ci	return (struct inet_timewait_sock *)sk;
838c2ecf20Sopenharmony_ci}
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_civoid inet_twsk_free(struct inet_timewait_sock *tw);
868c2ecf20Sopenharmony_civoid inet_twsk_put(struct inet_timewait_sock *tw);
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_civoid inet_twsk_bind_unhash(struct inet_timewait_sock *tw,
898c2ecf20Sopenharmony_ci			   struct inet_hashinfo *hashinfo);
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_cistruct inet_timewait_sock *inet_twsk_alloc(const struct sock *sk,
928c2ecf20Sopenharmony_ci					   struct inet_timewait_death_row *dr,
938c2ecf20Sopenharmony_ci					   const int state);
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_civoid inet_twsk_hashdance(struct inet_timewait_sock *tw, struct sock *sk,
968c2ecf20Sopenharmony_ci			 struct inet_hashinfo *hashinfo);
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_civoid __inet_twsk_schedule(struct inet_timewait_sock *tw, int timeo,
998c2ecf20Sopenharmony_ci			  bool rearm);
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_cistatic inline void inet_twsk_schedule(struct inet_timewait_sock *tw, int timeo)
1028c2ecf20Sopenharmony_ci{
1038c2ecf20Sopenharmony_ci	__inet_twsk_schedule(tw, timeo, false);
1048c2ecf20Sopenharmony_ci}
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_cistatic inline void inet_twsk_reschedule(struct inet_timewait_sock *tw, int timeo)
1078c2ecf20Sopenharmony_ci{
1088c2ecf20Sopenharmony_ci	__inet_twsk_schedule(tw, timeo, true);
1098c2ecf20Sopenharmony_ci}
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_civoid inet_twsk_deschedule_put(struct inet_timewait_sock *tw);
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_civoid inet_twsk_purge(struct inet_hashinfo *hashinfo, int family);
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_cistatic inline
1168c2ecf20Sopenharmony_cistruct net *twsk_net(const struct inet_timewait_sock *twsk)
1178c2ecf20Sopenharmony_ci{
1188c2ecf20Sopenharmony_ci	return read_pnet(&twsk->tw_net);
1198c2ecf20Sopenharmony_ci}
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_cistatic inline
1228c2ecf20Sopenharmony_civoid twsk_net_set(struct inet_timewait_sock *twsk, struct net *net)
1238c2ecf20Sopenharmony_ci{
1248c2ecf20Sopenharmony_ci	write_pnet(&twsk->tw_net, net);
1258c2ecf20Sopenharmony_ci}
1268c2ecf20Sopenharmony_ci#endif	/* _INET_TIMEWAIT_SOCK_ */
127