blob: dfd919b3119e8efcbc436a67e3e6fbd02091db10 [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -07002/*
3 * INET An implementation of the TCP/IP protocol suite for the LINUX
4 * operating system. INET is implemented using the BSD Socket
5 * interface as the means of communication with the user level.
6 *
7 * Definitions for a generic INET TIMEWAIT sock
8 *
9 * From code originally in net/tcp.h
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070010 */
11#ifndef _INET_TIMEWAIT_SOCK_
12#define _INET_TIMEWAIT_SOCK_
13
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070014#include <linux/list.h>
Arnaldo Carvalho de Melo295ff7e2005-08-09 20:44:40 -070015#include <linux/timer.h>
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070016#include <linux/types.h>
Arnaldo Carvalho de Melo295ff7e2005-08-09 20:44:40 -070017#include <linux/workqueue.h>
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070018
Arnaldo Carvalho de Melo14c85022005-12-27 02:43:12 -020019#include <net/inet_sock.h>
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070020#include <net/sock.h>
21#include <net/tcp_states.h>
Arnaldo Carvalho de Melo6d6ee432005-12-13 23:25:19 -080022#include <net/timewait_sock.h>
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070023
Arun Sharma600634972011-07-26 16:09:06 -070024#include <linux/atomic.h>
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070025
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070026struct inet_bind_bucket;
27
28/*
29 * This is a TIME_WAIT sock. It works around the memory consumption
30 * problems of sockets in such a state on heavily loaded servers, but
31 * without violating the protocol specification.
32 */
33struct inet_timewait_sock {
34 /*
35 * Now struct sock also uses sock_common, so please just
36 * don't add nothing before this first member (__tw_common) --acme
37 */
38 struct sock_common __tw_common;
39#define tw_family __tw_common.skc_family
40#define tw_state __tw_common.skc_state
41#define tw_reuse __tw_common.skc_reuse
Eric Dumazet3099a522018-04-07 13:42:43 -070042#define tw_reuseport __tw_common.skc_reuseport
Eric Dumazet9fe516b2014-06-27 08:36:16 -070043#define tw_ipv6only __tw_common.skc_ipv6only
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070044#define tw_bound_dev_if __tw_common.skc_bound_dev_if
Eric Dumazet3ab5aee2008-11-16 19:40:17 -080045#define tw_node __tw_common.skc_nulls_node
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070046#define tw_bind_node __tw_common.skc_bind_node
47#define tw_refcnt __tw_common.skc_refcnt
Eric Dumazet81c3d542005-10-03 14:13:38 -070048#define tw_hash __tw_common.skc_hash
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070049#define tw_prot __tw_common.skc_prot
Eric W. Biederman07feaeb2007-09-12 11:58:02 +020050#define tw_net __tw_common.skc_net
Eric Dumazet68835ab2010-11-30 19:04:07 +000051#define tw_daddr __tw_common.skc_daddr
Eric Dumazetefe42082013-10-03 15:42:29 -070052#define tw_v6_daddr __tw_common.skc_v6_daddr
Eric Dumazet68835ab2010-11-30 19:04:07 +000053#define tw_rcv_saddr __tw_common.skc_rcv_saddr
Eric Dumazetefe42082013-10-03 15:42:29 -070054#define tw_v6_rcv_saddr __tw_common.skc_v6_rcv_saddr
Eric Dumazetce43b032012-11-30 09:49:27 +000055#define tw_dport __tw_common.skc_dport
56#define tw_num __tw_common.skc_num
Eric Dumazet33cf7c92015-03-11 18:53:14 -070057#define tw_cookie __tw_common.skc_cookie
Eric Dumazet8e5eb542015-10-08 19:33:22 -070058#define tw_dr __tw_common.skc_tw_dr
Eric Dumazetce43b032012-11-30 09:49:27 +000059
Jon Maxwell00483692018-05-10 16:53:51 +100060 __u32 tw_mark;
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070061 volatile unsigned char tw_substate;
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070062 unsigned char tw_rcv_wscale;
Eric Dumazet68835ab2010-11-30 19:04:07 +000063
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070064 /* Socket demultiplex comparisons on incoming packets. */
Eric Dumazet68835ab2010-11-30 19:04:07 +000065 /* these three are in inet_sock */
Al Viro23f33c22006-09-27 18:43:50 -070066 __be16 tw_sport;
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070067 /* And these are ours. */
Eric Dumazet789f5582015-04-12 18:51:09 -070068 unsigned int tw_kill : 1,
Eric Dumazetabf90cc2009-10-18 22:48:51 +000069 tw_transparent : 1,
Florent Fourcot1d13a962014-01-16 17:21:22 +010070 tw_flowlabel : 20,
71 tw_pad : 2, /* 2 bits hole */
72 tw_tos : 8;
Eric Dumazetc67b8552019-06-08 17:58:51 -070073 u32 tw_txhash;
Eric Dumazetf6c0f5d2019-09-24 08:01:16 -070074 u32 tw_priority;
Eric Dumazet789f5582015-04-12 18:51:09 -070075 struct timer_list tw_timer;
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070076 struct inet_bind_bucket *tw_tb;
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070077};
Eric Dumazetb903d322011-10-27 00:44:35 -040078#define tw_tclass tw_tos
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070079
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070080static inline struct inet_timewait_sock *inet_twsk(const struct sock *sk)
81{
82 return (struct inet_timewait_sock *)sk;
83}
84
Eric Dumazet05dbc7b2013-10-03 00:22:02 -070085void inet_twsk_free(struct inet_timewait_sock *tw);
Joe Perches1fd51152013-09-21 10:22:41 -070086void inet_twsk_put(struct inet_timewait_sock *tw);
Arnaldo Carvalho de Meloe48c4142005-08-09 20:09:46 -070087
Eric Dumazetfc01538f2015-07-08 14:28:29 -070088void inet_twsk_bind_unhash(struct inet_timewait_sock *tw,
89 struct inet_hashinfo *hashinfo);
Eric Dumazet3cdaeda2009-12-04 03:47:42 +000090
Joe Perches1fd51152013-09-21 10:22:41 -070091struct inet_timewait_sock *inet_twsk_alloc(const struct sock *sk,
Eric Dumazet789f5582015-04-12 18:51:09 -070092 struct inet_timewait_death_row *dr,
Joe Perches1fd51152013-09-21 10:22:41 -070093 const int state);
Arnaldo Carvalho de Meloc6762702005-08-09 20:09:59 -070094
Eric Dumazetec94c262017-12-11 21:25:12 -080095void inet_twsk_hashdance(struct inet_timewait_sock *tw, struct sock *sk,
96 struct inet_hashinfo *hashinfo);
Arnaldo Carvalho de Melo696ab2d2005-08-09 20:45:03 -070097
Eric Dumazeted2e9232015-09-19 09:08:34 -070098void __inet_twsk_schedule(struct inet_timewait_sock *tw, int timeo,
99 bool rearm);
100
Raanan Avargil8695a142015-10-01 04:48:53 -0700101static inline void inet_twsk_schedule(struct inet_timewait_sock *tw, int timeo)
Eric Dumazeted2e9232015-09-19 09:08:34 -0700102{
103 __inet_twsk_schedule(tw, timeo, false);
104}
105
Raanan Avargil8695a142015-10-01 04:48:53 -0700106static inline void inet_twsk_reschedule(struct inet_timewait_sock *tw, int timeo)
Eric Dumazeted2e9232015-09-19 09:08:34 -0700107{
108 __inet_twsk_schedule(tw, timeo, true);
109}
110
Eric Dumazetdbe7faa2015-07-08 14:28:30 -0700111void inet_twsk_deschedule_put(struct inet_timewait_sock *tw);
YOSHIFUJI Hideaki3b1e0a62008-03-26 02:26:21 +0900112
Haishuang Yan1946e672016-12-28 17:52:32 +0800113void inet_twsk_purge(struct inet_hashinfo *hashinfo, int family);
Daniel Lezcanod3154922008-09-08 13:17:27 -0700114
YOSHIFUJI Hideaki3b1e0a62008-03-26 02:26:21 +0900115static inline
116struct net *twsk_net(const struct inet_timewait_sock *twsk)
117{
Eric Dumazetf943cbe2011-12-14 04:58:33 +0000118 return read_pnet(&twsk->tw_net);
YOSHIFUJI Hideaki3b1e0a62008-03-26 02:26:21 +0900119}
120
121static inline
Denis V. Lunevf5aa23f2008-03-26 00:48:17 -0700122void twsk_net_set(struct inet_timewait_sock *twsk, struct net *net)
YOSHIFUJI Hideaki3b1e0a62008-03-26 02:26:21 +0900123{
Eric Dumazetf943cbe2011-12-14 04:58:33 +0000124 write_pnet(&twsk->tw_net, net);
YOSHIFUJI Hideaki3b1e0a62008-03-26 02:26:21 +0900125}
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -0700126#endif /* _INET_TIMEWAIT_SOCK_ */