blob: 78775038f011f8880922419f25d325ffedd524f8 [file] [log] [blame]
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -07001/*
2 * INET An implementation of the TCP/IP protocol suite for the LINUX
3 * operating system. INET is implemented using the BSD Socket
4 * interface as the means of communication with the user level.
5 *
6 * Definitions for a generic INET TIMEWAIT sock
7 *
8 * From code originally in net/tcp.h
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version
13 * 2 of the License, or (at your option) any later version.
14 */
15#ifndef _INET_TIMEWAIT_SOCK_
16#define _INET_TIMEWAIT_SOCK_
17
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070018#include <linux/list.h>
Arnaldo Carvalho de Melo295ff7e2005-08-09 20:44:40 -070019#include <linux/timer.h>
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070020#include <linux/types.h>
Arnaldo Carvalho de Melo295ff7e2005-08-09 20:44:40 -070021#include <linux/workqueue.h>
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070022
Arnaldo Carvalho de Melo14c85022005-12-27 02:43:12 -020023#include <net/inet_sock.h>
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070024#include <net/sock.h>
25#include <net/tcp_states.h>
Arnaldo Carvalho de Melo6d6ee432005-12-13 23:25:19 -080026#include <net/timewait_sock.h>
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070027
Arun Sharma600634972011-07-26 16:09:06 -070028#include <linux/atomic.h>
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070029
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070030struct inet_bind_bucket;
31
32/*
33 * This is a TIME_WAIT sock. It works around the memory consumption
34 * problems of sockets in such a state on heavily loaded servers, but
35 * without violating the protocol specification.
36 */
37struct inet_timewait_sock {
38 /*
39 * Now struct sock also uses sock_common, so please just
40 * don't add nothing before this first member (__tw_common) --acme
41 */
42 struct sock_common __tw_common;
43#define tw_family __tw_common.skc_family
44#define tw_state __tw_common.skc_state
45#define tw_reuse __tw_common.skc_reuse
Eric Dumazet3099a522018-04-07 13:42:43 -070046#define tw_reuseport __tw_common.skc_reuseport
Eric Dumazet9fe516b2014-06-27 08:36:16 -070047#define tw_ipv6only __tw_common.skc_ipv6only
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070048#define tw_bound_dev_if __tw_common.skc_bound_dev_if
Eric Dumazet3ab5aee2008-11-16 19:40:17 -080049#define tw_node __tw_common.skc_nulls_node
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070050#define tw_bind_node __tw_common.skc_bind_node
51#define tw_refcnt __tw_common.skc_refcnt
Eric Dumazet81c3d542005-10-03 14:13:38 -070052#define tw_hash __tw_common.skc_hash
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070053#define tw_prot __tw_common.skc_prot
Eric W. Biederman07feaeb2007-09-12 11:58:02 +020054#define tw_net __tw_common.skc_net
Eric Dumazet68835ab2010-11-30 19:04:07 +000055#define tw_daddr __tw_common.skc_daddr
Eric Dumazetefe42082013-10-03 15:42:29 -070056#define tw_v6_daddr __tw_common.skc_v6_daddr
Eric Dumazet68835ab2010-11-30 19:04:07 +000057#define tw_rcv_saddr __tw_common.skc_rcv_saddr
Eric Dumazetefe42082013-10-03 15:42:29 -070058#define tw_v6_rcv_saddr __tw_common.skc_v6_rcv_saddr
Eric Dumazetce43b032012-11-30 09:49:27 +000059#define tw_dport __tw_common.skc_dport
60#define tw_num __tw_common.skc_num
Eric Dumazet33cf7c92015-03-11 18:53:14 -070061#define tw_cookie __tw_common.skc_cookie
Eric Dumazet8e5eb542015-10-08 19:33:22 -070062#define tw_dr __tw_common.skc_tw_dr
Eric Dumazetce43b032012-11-30 09:49:27 +000063
Jon Maxwell00483692018-05-10 16:53:51 +100064 __u32 tw_mark;
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070065 volatile unsigned char tw_substate;
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070066 unsigned char tw_rcv_wscale;
Eric Dumazet68835ab2010-11-30 19:04:07 +000067
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070068 /* Socket demultiplex comparisons on incoming packets. */
Eric Dumazet68835ab2010-11-30 19:04:07 +000069 /* these three are in inet_sock */
Al Viro23f33c22006-09-27 18:43:50 -070070 __be16 tw_sport;
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070071 /* And these are ours. */
Eric Dumazet789f5582015-04-12 18:51:09 -070072 unsigned int tw_kill : 1,
Eric Dumazetabf90cc2009-10-18 22:48:51 +000073 tw_transparent : 1,
Florent Fourcot1d13a962014-01-16 17:21:22 +010074 tw_flowlabel : 20,
75 tw_pad : 2, /* 2 bits hole */
76 tw_tos : 8;
Eric Dumazet789f5582015-04-12 18:51:09 -070077 struct timer_list tw_timer;
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070078 struct inet_bind_bucket *tw_tb;
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070079};
Eric Dumazetb903d322011-10-27 00:44:35 -040080#define tw_tclass tw_tos
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070081
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070082static inline struct inet_timewait_sock *inet_twsk(const struct sock *sk)
83{
84 return (struct inet_timewait_sock *)sk;
85}
86
Eric Dumazet05dbc7b2013-10-03 00:22:02 -070087void inet_twsk_free(struct inet_timewait_sock *tw);
Joe Perches1fd51152013-09-21 10:22:41 -070088void inet_twsk_put(struct inet_timewait_sock *tw);
Arnaldo Carvalho de Meloe48c4142005-08-09 20:09:46 -070089
Eric Dumazetfc01538f2015-07-08 14:28:29 -070090void inet_twsk_bind_unhash(struct inet_timewait_sock *tw,
91 struct inet_hashinfo *hashinfo);
Eric Dumazet3cdaeda2009-12-04 03:47:42 +000092
Joe Perches1fd51152013-09-21 10:22:41 -070093struct inet_timewait_sock *inet_twsk_alloc(const struct sock *sk,
Eric Dumazet789f5582015-04-12 18:51:09 -070094 struct inet_timewait_death_row *dr,
Joe Perches1fd51152013-09-21 10:22:41 -070095 const int state);
Arnaldo Carvalho de Meloc6762702005-08-09 20:09:59 -070096
Eric Dumazetec94c262017-12-11 21:25:12 -080097void inet_twsk_hashdance(struct inet_timewait_sock *tw, struct sock *sk,
98 struct inet_hashinfo *hashinfo);
Arnaldo Carvalho de Melo696ab2d2005-08-09 20:45:03 -070099
Eric Dumazeted2e9232015-09-19 09:08:34 -0700100void __inet_twsk_schedule(struct inet_timewait_sock *tw, int timeo,
101 bool rearm);
102
Raanan Avargil8695a142015-10-01 04:48:53 -0700103static inline void inet_twsk_schedule(struct inet_timewait_sock *tw, int timeo)
Eric Dumazeted2e9232015-09-19 09:08:34 -0700104{
105 __inet_twsk_schedule(tw, timeo, false);
106}
107
Raanan Avargil8695a142015-10-01 04:48:53 -0700108static inline void inet_twsk_reschedule(struct inet_timewait_sock *tw, int timeo)
Eric Dumazeted2e9232015-09-19 09:08:34 -0700109{
110 __inet_twsk_schedule(tw, timeo, true);
111}
112
Eric Dumazetdbe7faa2015-07-08 14:28:30 -0700113void inet_twsk_deschedule_put(struct inet_timewait_sock *tw);
YOSHIFUJI Hideaki3b1e0a62008-03-26 02:26:21 +0900114
Haishuang Yan1946e672016-12-28 17:52:32 +0800115void inet_twsk_purge(struct inet_hashinfo *hashinfo, int family);
Daniel Lezcanod3154922008-09-08 13:17:27 -0700116
YOSHIFUJI Hideaki3b1e0a62008-03-26 02:26:21 +0900117static inline
118struct net *twsk_net(const struct inet_timewait_sock *twsk)
119{
Eric Dumazetf943cbe2011-12-14 04:58:33 +0000120 return read_pnet(&twsk->tw_net);
YOSHIFUJI Hideaki3b1e0a62008-03-26 02:26:21 +0900121}
122
123static inline
Denis V. Lunevf5aa23f2008-03-26 00:48:17 -0700124void twsk_net_set(struct inet_timewait_sock *twsk, struct net *net)
YOSHIFUJI Hideaki3b1e0a62008-03-26 02:26:21 +0900125{
Eric Dumazetf943cbe2011-12-14 04:58:33 +0000126 write_pnet(&twsk->tw_net, net);
YOSHIFUJI Hideaki3b1e0a62008-03-26 02:26:21 +0900127}
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -0700128#endif /* _INET_TIMEWAIT_SOCK_ */