162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * INET An implementation of the TCP/IP protocol suite for the LINUX 462306a36Sopenharmony_ci * operating system. INET is implemented using the BSD Socket 562306a36Sopenharmony_ci * interface as the means of communication with the user level. 662306a36Sopenharmony_ci * 762306a36Sopenharmony_ci * Definitions for a generic INET TIMEWAIT sock 862306a36Sopenharmony_ci * 962306a36Sopenharmony_ci * From code originally in net/tcp.h 1062306a36Sopenharmony_ci */ 1162306a36Sopenharmony_ci#ifndef _INET_TIMEWAIT_SOCK_ 1262306a36Sopenharmony_ci#define _INET_TIMEWAIT_SOCK_ 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ci#include <linux/list.h> 1562306a36Sopenharmony_ci#include <linux/timer.h> 1662306a36Sopenharmony_ci#include <linux/types.h> 1762306a36Sopenharmony_ci#include <linux/workqueue.h> 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_ci#include <net/inet_sock.h> 2062306a36Sopenharmony_ci#include <net/sock.h> 2162306a36Sopenharmony_ci#include <net/tcp_states.h> 2262306a36Sopenharmony_ci#include <net/timewait_sock.h> 2362306a36Sopenharmony_ci 2462306a36Sopenharmony_ci#include <linux/atomic.h> 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_cistruct inet_bind_bucket; 2762306a36Sopenharmony_ci 2862306a36Sopenharmony_ci/* 2962306a36Sopenharmony_ci * This is a TIME_WAIT sock. It works around the memory consumption 3062306a36Sopenharmony_ci * problems of sockets in such a state on heavily loaded servers, but 3162306a36Sopenharmony_ci * without violating the protocol specification. 3262306a36Sopenharmony_ci */ 3362306a36Sopenharmony_cistruct inet_timewait_sock { 3462306a36Sopenharmony_ci /* 3562306a36Sopenharmony_ci * Now struct sock also uses sock_common, so please just 3662306a36Sopenharmony_ci * don't add nothing before this first member (__tw_common) --acme 3762306a36Sopenharmony_ci */ 3862306a36Sopenharmony_ci struct sock_common __tw_common; 3962306a36Sopenharmony_ci#define tw_family __tw_common.skc_family 4062306a36Sopenharmony_ci#define tw_state __tw_common.skc_state 4162306a36Sopenharmony_ci#define tw_reuse __tw_common.skc_reuse 4262306a36Sopenharmony_ci#define tw_reuseport __tw_common.skc_reuseport 4362306a36Sopenharmony_ci#define tw_ipv6only __tw_common.skc_ipv6only 4462306a36Sopenharmony_ci#define tw_bound_dev_if __tw_common.skc_bound_dev_if 4562306a36Sopenharmony_ci#define tw_node __tw_common.skc_nulls_node 4662306a36Sopenharmony_ci#define tw_bind_node __tw_common.skc_bind_node 4762306a36Sopenharmony_ci#define tw_refcnt __tw_common.skc_refcnt 4862306a36Sopenharmony_ci#define tw_hash __tw_common.skc_hash 4962306a36Sopenharmony_ci#define tw_prot __tw_common.skc_prot 5062306a36Sopenharmony_ci#define tw_net __tw_common.skc_net 5162306a36Sopenharmony_ci#define tw_daddr __tw_common.skc_daddr 5262306a36Sopenharmony_ci#define tw_v6_daddr __tw_common.skc_v6_daddr 5362306a36Sopenharmony_ci#define tw_rcv_saddr __tw_common.skc_rcv_saddr 5462306a36Sopenharmony_ci#define tw_v6_rcv_saddr __tw_common.skc_v6_rcv_saddr 5562306a36Sopenharmony_ci#define tw_dport __tw_common.skc_dport 5662306a36Sopenharmony_ci#define tw_num __tw_common.skc_num 5762306a36Sopenharmony_ci#define tw_cookie __tw_common.skc_cookie 5862306a36Sopenharmony_ci#define tw_dr __tw_common.skc_tw_dr 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_ci __u32 tw_mark; 6162306a36Sopenharmony_ci volatile unsigned char tw_substate; 6262306a36Sopenharmony_ci unsigned char tw_rcv_wscale; 6362306a36Sopenharmony_ci 6462306a36Sopenharmony_ci /* Socket demultiplex comparisons on incoming packets. */ 6562306a36Sopenharmony_ci /* these three are in inet_sock */ 6662306a36Sopenharmony_ci __be16 tw_sport; 6762306a36Sopenharmony_ci /* And these are ours. */ 6862306a36Sopenharmony_ci unsigned int tw_transparent : 1, 6962306a36Sopenharmony_ci tw_flowlabel : 20, 7062306a36Sopenharmony_ci tw_pad : 3, /* 3 bits hole */ 7162306a36Sopenharmony_ci tw_tos : 8; 7262306a36Sopenharmony_ci u32 tw_txhash; 7362306a36Sopenharmony_ci u32 tw_priority; 7462306a36Sopenharmony_ci struct timer_list tw_timer; 7562306a36Sopenharmony_ci struct inet_bind_bucket *tw_tb; 7662306a36Sopenharmony_ci struct inet_bind2_bucket *tw_tb2; 7762306a36Sopenharmony_ci struct hlist_node tw_bind2_node; 7862306a36Sopenharmony_ci}; 7962306a36Sopenharmony_ci#define tw_tclass tw_tos 8062306a36Sopenharmony_ci 8162306a36Sopenharmony_ci#define twsk_for_each_bound_bhash2(__tw, list) \ 8262306a36Sopenharmony_ci hlist_for_each_entry(__tw, list, tw_bind2_node) 8362306a36Sopenharmony_ci 8462306a36Sopenharmony_cistatic inline struct inet_timewait_sock *inet_twsk(const struct sock *sk) 8562306a36Sopenharmony_ci{ 8662306a36Sopenharmony_ci return (struct inet_timewait_sock *)sk; 8762306a36Sopenharmony_ci} 8862306a36Sopenharmony_ci 8962306a36Sopenharmony_civoid inet_twsk_free(struct inet_timewait_sock *tw); 9062306a36Sopenharmony_civoid inet_twsk_put(struct inet_timewait_sock *tw); 9162306a36Sopenharmony_ci 9262306a36Sopenharmony_civoid inet_twsk_bind_unhash(struct inet_timewait_sock *tw, 9362306a36Sopenharmony_ci struct inet_hashinfo *hashinfo); 9462306a36Sopenharmony_ci 9562306a36Sopenharmony_cistruct inet_timewait_sock *inet_twsk_alloc(const struct sock *sk, 9662306a36Sopenharmony_ci struct inet_timewait_death_row *dr, 9762306a36Sopenharmony_ci const int state); 9862306a36Sopenharmony_ci 9962306a36Sopenharmony_civoid inet_twsk_hashdance(struct inet_timewait_sock *tw, struct sock *sk, 10062306a36Sopenharmony_ci struct inet_hashinfo *hashinfo); 10162306a36Sopenharmony_ci 10262306a36Sopenharmony_civoid __inet_twsk_schedule(struct inet_timewait_sock *tw, int timeo, 10362306a36Sopenharmony_ci bool rearm); 10462306a36Sopenharmony_ci 10562306a36Sopenharmony_cistatic inline void inet_twsk_schedule(struct inet_timewait_sock *tw, int timeo) 10662306a36Sopenharmony_ci{ 10762306a36Sopenharmony_ci __inet_twsk_schedule(tw, timeo, false); 10862306a36Sopenharmony_ci} 10962306a36Sopenharmony_ci 11062306a36Sopenharmony_cistatic inline void inet_twsk_reschedule(struct inet_timewait_sock *tw, int timeo) 11162306a36Sopenharmony_ci{ 11262306a36Sopenharmony_ci __inet_twsk_schedule(tw, timeo, true); 11362306a36Sopenharmony_ci} 11462306a36Sopenharmony_ci 11562306a36Sopenharmony_civoid inet_twsk_deschedule_put(struct inet_timewait_sock *tw); 11662306a36Sopenharmony_ci 11762306a36Sopenharmony_civoid inet_twsk_purge(struct inet_hashinfo *hashinfo, int family); 11862306a36Sopenharmony_ci 11962306a36Sopenharmony_cistatic inline 12062306a36Sopenharmony_cistruct net *twsk_net(const struct inet_timewait_sock *twsk) 12162306a36Sopenharmony_ci{ 12262306a36Sopenharmony_ci return read_pnet(&twsk->tw_net); 12362306a36Sopenharmony_ci} 12462306a36Sopenharmony_ci 12562306a36Sopenharmony_cistatic inline 12662306a36Sopenharmony_civoid twsk_net_set(struct inet_timewait_sock *twsk, struct net *net) 12762306a36Sopenharmony_ci{ 12862306a36Sopenharmony_ci write_pnet(&twsk->tw_net, net); 12962306a36Sopenharmony_ci} 13062306a36Sopenharmony_ci#endif /* _INET_TIMEWAIT_SOCK_ */ 131