FreeBSD kernel IPv4 code
tcp_timewait.c File Reference
#include <sys/cdefs.h>
#include "opt_inet.h"
#include "opt_inet6.h"
#include "opt_ipsec.h"
#include "opt_tcpdebug.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/callout.h>
#include <sys/kernel.h>
#include <sys/sysctl.h>
#include <sys/malloc.h>
#include <sys/mbuf.h>
#include <sys/priv.h>
#include <sys/proc.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
#include <sys/syslog.h>
#include <sys/protosw.h>
#include <sys/random.h>
#include <vm/uma.h>
#include <net/route.h>
#include <net/if.h>
#include <net/if_var.h>
#include <net/vnet.h>
#include <netinet/in.h>
#include <netinet/in_kdtrace.h>
#include <netinet/in_pcb.h>
#include <netinet/in_systm.h>
#include <netinet/in_var.h>
#include <netinet/ip.h>
#include <netinet/ip_icmp.h>
#include <netinet/ip_var.h>
#include <netinet/tcp.h>
#include <netinet/tcp_fsm.h>
#include <netinet/tcp_seq.h>
#include <netinet/tcp_timer.h>
#include <netinet/tcp_var.h>
#include <netinet/tcp_hpts.h>
#include <netinet/tcpip.h>
#include <netinet/udp.h>
#include <netinet/udp_var.h>
#include <netipsec/ipsec_support.h>
#include <machine/in_cksum.h>
#include <security/mac/mac_framework.h>
Include dependency graph for tcp_timewait.c:

Go to the source code of this file.

Macros

#define V_tcptw_zone   VNET(tcptw_zone)
 
#define V_twq_2msl   VNET(twq_2msl)
 
#define V_tw_lock   VNET(tw_lock)
 
#define TW_LOCK_INIT(tw, d)   rw_init_flags(&(tw), (d), 0)
 
#define TW_LOCK_DESTROY(tw)   rw_destroy(&(tw))
 
#define TW_RLOCK(tw)   rw_rlock(&(tw))
 
#define TW_WLOCK(tw)   rw_wlock(&(tw))
 
#define TW_RUNLOCK(tw)   rw_runlock(&(tw))
 
#define TW_WUNLOCK(tw)   rw_wunlock(&(tw))
 
#define TW_LOCK_ASSERT(tw)   rw_assert(&(tw), RA_LOCKED)
 
#define TW_RLOCK_ASSERT(tw)   rw_assert(&(tw), RA_RLOCKED)
 
#define TW_WLOCK_ASSERT(tw)   rw_assert(&(tw), RA_WLOCKED)
 
#define TW_UNLOCK_ASSERT(tw)   rw_assert(&(tw), RA_UNLOCKED)
 
#define V_nolocaltimewait   VNET(nolocaltimewait)
 

Functions

 __FBSDID ("$FreeBSD$")
 
 VNET_DEFINE_STATIC (uma_zone_t, tcptw_zone)
 
 VNET_DEFINE_STATIC (TAILQ_HEAD(, tcptw), twq_2msl)
 
 VNET_DEFINE_STATIC (struct rwlock, tw_lock)
 
static void tcp_tw_2msl_reset (struct tcptw *, int)
 
static void tcp_tw_2msl_stop (struct tcptw *, int)
 
static int tcp_twrespond (struct tcptw *, int)
 
static int tcptw_auto_size (void)
 
static int sysctl_maxtcptw (SYSCTL_HANDLER_ARGS)
 
 SYSCTL_PROC (_net_inet_tcp, OID_AUTO, maxtcptw, CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_NEEDGIANT, &maxtcptw, 0, sysctl_maxtcptw, "IU", "Maximum number of compressed TCP TIME_WAIT entries")
 
 VNET_DEFINE_STATIC (bool, nolocaltimewait)
 
 SYSCTL_BOOL (_net_inet_tcp, OID_AUTO, nolocaltimewait, CTLFLAG_VNET|CTLFLAG_RW, &VNET_NAME(nolocaltimewait), true, "Do not create compressed TCP TIME_WAIT entries for local connections")
 
void tcp_tw_zone_change (void)
 
void tcp_tw_init (void)
 
void tcp_twstart (struct tcpcb *tp)
 
int tcp_twcheck (struct inpcb *inp, struct tcpopt *to, struct tcphdr *th, struct mbuf *m, int tlen)
 
void tcp_twclose (struct tcptw *tw, int reuse)
 
struct tcptwtcp_tw_2msl_scan (int reuse)
 

Variables

static int maxtcptw
 

Macro Definition Documentation

◆ TW_LOCK_ASSERT

#define TW_LOCK_ASSERT (   tw)    rw_assert(&(tw), RA_LOCKED)

Definition at line 135 of file tcp_timewait.c.

◆ TW_LOCK_DESTROY

#define TW_LOCK_DESTROY (   tw)    rw_destroy(&(tw))

Definition at line 130 of file tcp_timewait.c.

◆ TW_LOCK_INIT

#define TW_LOCK_INIT (   tw,
 
)    rw_init_flags(&(tw), (d), 0)

Definition at line 129 of file tcp_timewait.c.

◆ TW_RLOCK

#define TW_RLOCK (   tw)    rw_rlock(&(tw))

Definition at line 131 of file tcp_timewait.c.

◆ TW_RLOCK_ASSERT

#define TW_RLOCK_ASSERT (   tw)    rw_assert(&(tw), RA_RLOCKED)

Definition at line 136 of file tcp_timewait.c.

◆ TW_RUNLOCK

#define TW_RUNLOCK (   tw)    rw_runlock(&(tw))

Definition at line 133 of file tcp_timewait.c.

◆ TW_UNLOCK_ASSERT

#define TW_UNLOCK_ASSERT (   tw)    rw_assert(&(tw), RA_UNLOCKED)

Definition at line 138 of file tcp_timewait.c.

◆ TW_WLOCK

#define TW_WLOCK (   tw)    rw_wlock(&(tw))

Definition at line 132 of file tcp_timewait.c.

◆ TW_WLOCK_ASSERT

#define TW_WLOCK_ASSERT (   tw)    rw_assert(&(tw), RA_WLOCKED)

Definition at line 137 of file tcp_timewait.c.

◆ TW_WUNLOCK

#define TW_WUNLOCK (   tw)    rw_wunlock(&(tw))

Definition at line 134 of file tcp_timewait.c.

◆ V_nolocaltimewait

#define V_nolocaltimewait   VNET(nolocaltimewait)

Definition at line 185 of file tcp_timewait.c.

◆ V_tcptw_zone

#define V_tcptw_zone   VNET(tcptw_zone)

Definition at line 108 of file tcp_timewait.c.

◆ V_tw_lock

#define V_tw_lock   VNET(tw_lock)

Definition at line 127 of file tcp_timewait.c.

◆ V_twq_2msl

#define V_twq_2msl   VNET(twq_2msl)

Definition at line 123 of file tcp_timewait.c.

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ SYSCTL_BOOL()

SYSCTL_BOOL ( _net_inet_tcp  ,
OID_AUTO  ,
nolocaltimewait  ,
CTLFLAG_VNET|  CTLFLAG_RW,
VNET_NAMEnolocaltimewait,
true  ,
"Do not create compressed TCP TIME_WAIT entries for local connections"   
)

◆ sysctl_maxtcptw()

static int sysctl_maxtcptw ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 162 of file tcp_timewait.c.

References maxtcptw, tcptw_auto_size(), and V_tcptw_zone.

Here is the call graph for this function:

◆ SYSCTL_PROC()

SYSCTL_PROC ( _net_inet_tcp  ,
OID_AUTO  ,
maxtcptw  ,
CTLTYPE_INT|CTLFLAG_RW|  CTLFLAG_NEEDGIANT,
maxtcptw,
,
sysctl_maxtcptw  ,
"IU"  ,
"Maximum number of compressed TCP TIME_WAIT entries"   
)

◆ tcp_tw_2msl_reset()

static void tcp_tw_2msl_reset ( struct tcptw tw,
int  rearm 
)
static

Definition at line 759 of file tcp_timewait.c.

References INP_WLOCK_ASSERT, tcptw::tw_inpcb, tcptw::tw_time, TW_WLOCK, TW_WUNLOCK, V_tcp_msl, V_tw_lock, and V_twq_2msl.

Referenced by tcp_twcheck(), and tcp_twstart().

Here is the caller graph for this function:

◆ tcp_tw_2msl_scan()

struct tcptw * tcp_tw_2msl_scan ( int  reuse)

Definition at line 803 of file tcp_timewait.c.

References in_pcbref(), in_pcbrele_wlocked(), INP_WLOCK, INP_WUNLOCK, intotw, tcp_twclose(), tcptw::tw_inpcb, TW_RLOCK, TW_RUNLOCK, tcptw::tw_time, V_tw_lock, and V_twq_2msl.

Referenced by tcp_slowtimo(), and tcp_twstart().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ tcp_tw_2msl_stop()

static void tcp_tw_2msl_stop ( struct tcptw tw,
int  reuse 
)
static

Definition at line 774 of file tcp_timewait.c.

References in_pcbrele_wlocked(), TCPS_TIME_WAIT, TCPSTATES_DEC, tcptw::tw_cred, tcptw::tw_inpcb, TW_WLOCK, TW_WUNLOCK, V_tcptw_zone, V_tw_lock, and V_twq_2msl.

Referenced by tcp_twclose().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ tcp_tw_init()

void tcp_tw_init ( void  )

Definition at line 199 of file tcp_timewait.c.

References maxtcptw, tcptw_auto_size(), TW_LOCK_INIT, V_tcptw_zone, V_tw_lock, and V_twq_2msl.

Referenced by tcp_vnet_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ tcp_tw_zone_change()

void tcp_tw_zone_change ( void  )

Definition at line 191 of file tcp_timewait.c.

References maxtcptw, tcptw_auto_size(), and V_tcptw_zone.

Here is the call graph for this function:

◆ tcp_twcheck()

int tcp_twcheck ( struct inpcb inp,
struct tcpopt to,
struct tcphdr *  th,
struct mbuf *  m,
int  tlen 
)

◆ tcp_twclose()

void tcp_twclose ( struct tcptw tw,
int  reuse 
)

Definition at line 541 of file tcp_timewait.c.

References in_pcbdrop(), in_pcbfree(), inpcb::inp_flags, inpcb::inp_ppcb, inpcb::inp_socket, INP_SOCKREF, INP_TIMEWAIT, INP_WLOCK_ASSERT, INP_WUNLOCK, intotw, tcp_tw_2msl_stop(), TCPSTAT_INC, and tcptw::tw_inpcb.

Referenced by sysctl_drop(), tcp_tw_2msl_scan(), and tcp_twcheck().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ tcp_twrespond()

◆ tcp_twstart()

◆ tcptw_auto_size()

static int tcptw_auto_size ( void  )
static

Definition at line 145 of file tcp_timewait.c.

References V_ipport_firstauto, and V_ipport_lastauto.

Referenced by sysctl_maxtcptw(), tcp_tw_init(), and tcp_tw_zone_change().

Here is the caller graph for this function:

◆ VNET_DEFINE_STATIC() [1/4]

VNET_DEFINE_STATIC ( bool  ,
nolocaltimewait   
)

◆ VNET_DEFINE_STATIC() [2/4]

VNET_DEFINE_STATIC ( struct rwlock  ,
tw_lock   
)

◆ VNET_DEFINE_STATIC() [3/4]

VNET_DEFINE_STATIC ( TAILQ_HEAD(, tcptw ,
twq_2msl   
)

◆ VNET_DEFINE_STATIC() [4/4]

VNET_DEFINE_STATIC ( uma_zone_t  ,
tcptw_zone   
)

Variable Documentation

◆ maxtcptw

int maxtcptw
static

Definition at line 109 of file tcp_timewait.c.

Referenced by sysctl_maxtcptw(), tcp_tw_init(), and tcp_tw_zone_change().