blob: 6a75d67a30fd80d15e40e86b59d6216da5e94989 [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
Vegard Nossum9e337b02008-10-18 17:37:51 +020019#include <linux/kmemcheck.h>
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070020#include <linux/list.h>
Arnaldo Carvalho de Melo295ff7e2005-08-09 20:44:40 -070021#include <linux/timer.h>
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070022#include <linux/types.h>
Arnaldo Carvalho de Melo295ff7e2005-08-09 20:44:40 -070023#include <linux/workqueue.h>
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070024
Arnaldo Carvalho de Melo14c85022005-12-27 02:43:12 -020025#include <net/inet_sock.h>
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070026#include <net/sock.h>
27#include <net/tcp_states.h>
Arnaldo Carvalho de Melo6d6ee432005-12-13 23:25:19 -080028#include <net/timewait_sock.h>
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070029
Arun Sharma600634972011-07-26 16:09:06 -070030#include <linux/atomic.h>
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070031
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070032struct inet_bind_bucket;
33
34/*
35 * This is a TIME_WAIT sock. It works around the memory consumption
36 * problems of sockets in such a state on heavily loaded servers, but
37 * without violating the protocol specification.
38 */
39struct inet_timewait_sock {
40 /*
41 * Now struct sock also uses sock_common, so please just
42 * don't add nothing before this first member (__tw_common) --acme
43 */
44 struct sock_common __tw_common;
45#define tw_family __tw_common.skc_family
46#define tw_state __tw_common.skc_state
47#define tw_reuse __tw_common.skc_reuse
Eric Dumazet9fe516b2014-06-27 08:36:16 -070048#define tw_ipv6only __tw_common.skc_ipv6only
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070049#define tw_bound_dev_if __tw_common.skc_bound_dev_if
Eric Dumazet3ab5aee2008-11-16 19:40:17 -080050#define tw_node __tw_common.skc_nulls_node
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070051#define tw_bind_node __tw_common.skc_bind_node
52#define tw_refcnt __tw_common.skc_refcnt
Eric Dumazet81c3d542005-10-03 14:13:38 -070053#define tw_hash __tw_common.skc_hash
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070054#define tw_prot __tw_common.skc_prot
Eric W. Biederman07feaeb2007-09-12 11:58:02 +020055#define tw_net __tw_common.skc_net
Eric Dumazet68835ab2010-11-30 19:04:07 +000056#define tw_daddr __tw_common.skc_daddr
Eric Dumazetefe42082013-10-03 15:42:29 -070057#define tw_v6_daddr __tw_common.skc_v6_daddr
Eric Dumazet68835ab2010-11-30 19:04:07 +000058#define tw_rcv_saddr __tw_common.skc_rcv_saddr
Eric Dumazetefe42082013-10-03 15:42:29 -070059#define tw_v6_rcv_saddr __tw_common.skc_v6_rcv_saddr
Eric Dumazetce43b032012-11-30 09:49:27 +000060#define tw_dport __tw_common.skc_dport
61#define tw_num __tw_common.skc_num
Eric Dumazet33cf7c92015-03-11 18:53:14 -070062#define tw_cookie __tw_common.skc_cookie
Eric Dumazet8e5eb542015-10-08 19:33:22 -070063#define tw_dr __tw_common.skc_tw_dr
Eric Dumazetce43b032012-11-30 09:49:27 +000064
Arnaldo Carvalho de Meload8bb782008-02-03 04:08:26 -080065 int tw_timeout;
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070066 volatile unsigned char tw_substate;
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070067 unsigned char tw_rcv_wscale;
Eric Dumazet68835ab2010-11-30 19:04:07 +000068
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070069 /* Socket demultiplex comparisons on incoming packets. */
Eric Dumazet68835ab2010-11-30 19:04:07 +000070 /* these three are in inet_sock */
Al Viro23f33c22006-09-27 18:43:50 -070071 __be16 tw_sport;
Vegard Nossum9e337b02008-10-18 17:37:51 +020072 kmemcheck_bitfield_begin(flags);
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070073 /* And these are ours. */
Eric Dumazet789f5582015-04-12 18:51:09 -070074 unsigned int tw_kill : 1,
Eric Dumazetabf90cc2009-10-18 22:48:51 +000075 tw_transparent : 1,
Florent Fourcot1d13a962014-01-16 17:21:22 +010076 tw_flowlabel : 20,
77 tw_pad : 2, /* 2 bits hole */
78 tw_tos : 8;
Vegard Nossum9e337b02008-10-18 17:37:51 +020079 kmemcheck_bitfield_end(flags);
Eric Dumazet789f5582015-04-12 18:51:09 -070080 struct timer_list tw_timer;
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070081 struct inet_bind_bucket *tw_tb;
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070082};
Eric Dumazetb903d322011-10-27 00:44:35 -040083#define tw_tclass tw_tos
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070084
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -070085static inline struct inet_timewait_sock *inet_twsk(const struct sock *sk)
86{
87 return (struct inet_timewait_sock *)sk;
88}
89
Eric Dumazet05dbc7b2013-10-03 00:22:02 -070090void inet_twsk_free(struct inet_timewait_sock *tw);
Joe Perches1fd51152013-09-21 10:22:41 -070091void inet_twsk_put(struct inet_timewait_sock *tw);
Arnaldo Carvalho de Meloe48c4142005-08-09 20:09:46 -070092
Eric Dumazetfc01538f2015-07-08 14:28:29 -070093void inet_twsk_bind_unhash(struct inet_timewait_sock *tw,
94 struct inet_hashinfo *hashinfo);
Eric Dumazet3cdaeda2009-12-04 03:47:42 +000095
Joe Perches1fd51152013-09-21 10:22:41 -070096struct inet_timewait_sock *inet_twsk_alloc(const struct sock *sk,
Eric Dumazet789f5582015-04-12 18:51:09 -070097 struct inet_timewait_death_row *dr,
Joe Perches1fd51152013-09-21 10:22:41 -070098 const int state);
Arnaldo Carvalho de Meloc6762702005-08-09 20:09:59 -070099
Joe Perches1fd51152013-09-21 10:22:41 -0700100void __inet_twsk_hashdance(struct inet_timewait_sock *tw, struct sock *sk,
101 struct inet_hashinfo *hashinfo);
Arnaldo Carvalho de Melo696ab2d2005-08-09 20:45:03 -0700102
Eric Dumazeted2e9232015-09-19 09:08:34 -0700103void __inet_twsk_schedule(struct inet_timewait_sock *tw, int timeo,
104 bool rearm);
105
Raanan Avargil8695a142015-10-01 04:48:53 -0700106static inline void inet_twsk_schedule(struct inet_timewait_sock *tw, int timeo)
Eric Dumazeted2e9232015-09-19 09:08:34 -0700107{
108 __inet_twsk_schedule(tw, timeo, false);
109}
110
Raanan Avargil8695a142015-10-01 04:48:53 -0700111static inline void inet_twsk_reschedule(struct inet_timewait_sock *tw, int timeo)
Eric Dumazeted2e9232015-09-19 09:08:34 -0700112{
113 __inet_twsk_schedule(tw, timeo, true);
114}
115
Eric Dumazetdbe7faa2015-07-08 14:28:30 -0700116void inet_twsk_deschedule_put(struct inet_timewait_sock *tw);
YOSHIFUJI Hideaki3b1e0a62008-03-26 02:26:21 +0900117
Haishuang Yan1946e672016-12-28 17:52:32 +0800118void inet_twsk_purge(struct inet_hashinfo *hashinfo, int family);
Daniel Lezcanod3154922008-09-08 13:17:27 -0700119
YOSHIFUJI Hideaki3b1e0a62008-03-26 02:26:21 +0900120static inline
121struct net *twsk_net(const struct inet_timewait_sock *twsk)
122{
Eric Dumazetf943cbe2011-12-14 04:58:33 +0000123 return read_pnet(&twsk->tw_net);
YOSHIFUJI Hideaki3b1e0a62008-03-26 02:26:21 +0900124}
125
126static inline
Denis V. Lunevf5aa23f2008-03-26 00:48:17 -0700127void twsk_net_set(struct inet_timewait_sock *twsk, struct net *net)
YOSHIFUJI Hideaki3b1e0a62008-03-26 02:26:21 +0900128{
Eric Dumazetf943cbe2011-12-14 04:58:33 +0000129 write_pnet(&twsk->tw_net, net);
YOSHIFUJI Hideaki3b1e0a62008-03-26 02:26:21 +0900130}
Arnaldo Carvalho de Melo8feaf0c02005-08-09 20:09:30 -0700131#endif /* _INET_TIMEWAIT_SOCK_ */