FreeBSD kernel IPv4 code
in_pcb.c File Reference
#include <sys/cdefs.h>
#include "opt_ddb.h"
#include "opt_ipsec.h"
#include "opt_inet.h"
#include "opt_inet6.h"
#include "opt_ratelimit.h"
#include "opt_route.h"
#include "opt_rss.h"
#include <sys/param.h>
#include <sys/hash.h>
#include <sys/systm.h>
#include <sys/libkern.h>
#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/mbuf.h>
#include <sys/callout.h>
#include <sys/eventhandler.h>
#include <sys/domain.h>
#include <sys/protosw.h>
#include <sys/smp.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
#include <sys/sockio.h>
#include <sys/priv.h>
#include <sys/proc.h>
#include <sys/refcount.h>
#include <sys/jail.h>
#include <sys/kernel.h>
#include <sys/sysctl.h>
#include <vm/uma.h>
#include <vm/vm.h>
#include <net/if.h>
#include <net/if_var.h>
#include <net/if_types.h>
#include <net/if_llatbl.h>
#include <net/route.h>
#include <net/rss_config.h>
#include <net/vnet.h>
#include <netipsec/ipsec_support.h>
#include <security/mac/mac_framework.h>
Include dependency graph for in_pcb.c:

Go to the source code of this file.

Macros

#define INPCBLBGROUP_SIZMIN   8
 
#define INPCBLBGROUP_SIZMAX   256
 
#define INP_FREED   0x00000200 /* See in_pcb.h. */
 
#define V_ipport_tcplastcount   VNET(ipport_tcplastcount)
 
#define II_LIST_FIRST(ipi, hash)
 
#define II_LIST_NEXT(inp, hash)
 
#define II_LOCK_ASSERT(inp, lock)
 

Functions

 __FBSDID ("$FreeBSD$")
 
 VNET_DEFINE (int, ipport_lowfirstauto)
 
 VNET_DEFINE (int, ipport_lowlastauto)
 
 VNET_DEFINE (int, ipport_firstauto)
 
 VNET_DEFINE (int, ipport_lastauto)
 
 VNET_DEFINE (int, ipport_hifirstauto)
 
 VNET_DEFINE (int, ipport_hilastauto)
 
 VNET_DEFINE (int, ipport_reservedhigh)
 
 VNET_DEFINE (int, ipport_reservedlow)
 
 VNET_DEFINE (int, ipport_randomized)
 
 VNET_DEFINE (int, ipport_randomcps)
 
 VNET_DEFINE (int, ipport_randomtime)
 
 VNET_DEFINE (int, ipport_stoprandom)
 
 VNET_DEFINE (int, ipport_tcpallocs)
 
 VNET_DEFINE_STATIC (int, ipport_tcplastcount)
 
 VNET_DEFINE (uint32_t, in_pcbhashseed)
 
static void in_pcbhashseed_init (void)
 
 VNET_SYSINIT (in_pcbhashseed_init, SI_SUB_PROTO_DOMAIN, SI_ORDER_FIRST, in_pcbhashseed_init, 0)
 
static struct inpcblbgroupin_pcblbgroup_alloc (struct inpcblbgrouphead *hdr, u_char vflag, uint16_t port, const union in_dependaddr *addr, int size, uint8_t numa_domain)
 
static void in_pcblbgroup_free_deferred (epoch_context_t ctx)
 
static void in_pcblbgroup_free (struct inpcblbgroup *grp)
 
static struct inpcblbgroupin_pcblbgroup_resize (struct inpcblbgrouphead *hdr, struct inpcblbgroup *old_grp, int size)
 
static void in_pcblbgroup_reorder (struct inpcblbgrouphead *hdr, struct inpcblbgroup **grpp, int i)
 
static int in_pcbinslbgrouphash (struct inpcb *inp, uint8_t numa_domain)
 
static void in_pcbremlbgrouphash (struct inpcb *inp)
 
int in_pcblbgroup_numa (struct inpcb *inp, int arg)
 
 CTASSERT (sizeof(struct inpcbhead)==sizeof(LIST_HEAD(, inpcb)))
 
void in_pcbinfo_init (struct inpcbinfo *pcbinfo, struct inpcbstorage *pcbstor, u_int hash_nelements, u_int porthash_nelements)
 
void in_pcbinfo_destroy (struct inpcbinfo *pcbinfo)
 
static void inpcb_dtor (void *, int, void *)
 
static void inpcb_fini (void *, int)
 
void in_pcbstorage_init (void *arg)
 
void in_pcbstorage_destroy (void *arg)
 
int in_pcballoc (struct socket *so, struct inpcbinfo *pcbinfo)
 
int in_pcbbind_check_bindmulti (const struct inpcb *ni, const struct inpcb *oi)
 
void in_pcbdetach (struct inpcb *inp)
 
static void inp_lock (struct inpcb *inp, const inp_lookup_t lock)
 
static void inp_unlock (struct inpcb *inp, const inp_lookup_t lock)
 
static int inp_trylock (struct inpcb *inp, const inp_lookup_t lock)
 
static bool in_pcbrele (struct inpcb *inp, const inp_lookup_t lock)
 
bool inp_smr_lock (struct inpcb *inp, const inp_lookup_t lock)
 
struct inpcbinp_next (struct inpcb_iterator *ii)
 
void in_pcbref (struct inpcb *inp)
 
bool in_pcbrele_rlocked (struct inpcb *inp)
 
bool in_pcbrele_wlocked (struct inpcb *inp)
 
void in_pcbfree (struct inpcb *inp)
 
void in_pcbdrop (struct inpcb *inp)
 
int in_pcbinshash (struct inpcb *inp)
 
void in_pcbrehash (struct inpcb *inp)
 
void in_losing (struct inpcb *inp)
 
void in_pcbsosetlabel (struct socket *so)
 
static void ipport_tick (void *xtp)
 
static void ip_fini (void *xtp)
 
static void ipport_tick_init (const void *unused __unused)
 
 SYSINIT (ipport_tick_init, SI_SUB_PROTO_DOMAIN, SI_ORDER_MIDDLE, ipport_tick_init, NULL)
 
void inp_wlock (struct inpcb *inp)
 
void inp_wunlock (struct inpcb *inp)
 
void inp_rlock (struct inpcb *inp)
 
void inp_runlock (struct inpcb *inp)
 
void inp_apply_all (void(*func)(struct inpcb *, void *), void *arg)
 
struct socket * inp_inpcbtosocket (struct inpcb *inp)
 
struct tcpcbinp_inpcbtotcpcb (struct inpcb *inp)
 
int inp_ip_tos_get (const struct inpcb *inp)
 
void inp_ip_tos_set (struct inpcb *inp, int val)
 
void inp_4tuple_get (struct inpcb *inp, uint32_t *laddr, uint16_t *lp, uint32_t *faddr, uint16_t *fp)
 
struct inpcbso_sotoinpcb (struct socket *so)
 
struct tcpcbso_sototcpcb (struct socket *so)
 
void in_pcbtoxinpcb (const struct inpcb *inp, struct xinpcb *xi)
 
int sysctl_setsockopt (SYSCTL_HANDLER_ARGS, struct inpcbinfo *pcbinfo, int(*ctloutput_set)(struct inpcb *, struct sockopt *))
 

Variables

static struct callout ipport_tick_callout
 

Macro Definition Documentation

◆ II_LIST_FIRST

#define II_LIST_FIRST (   ipi,
  hash 
)
Value:
(((hash) == INP_ALL_LIST) ? \
CK_LIST_FIRST(&(ipi)->ipi_listhead) : \
CK_LIST_FIRST(&(ipi)->ipi_hashbase[(hash)]))
#define INP_ALL_LIST
Definition: in_pcb.h:782

Definition at line 1643 of file in_pcb.c.

◆ II_LIST_NEXT

#define II_LIST_NEXT (   inp,
  hash 
)
Value:
(((hash) == INP_ALL_LIST) ? \
CK_LIST_NEXT((inp), inp_list) : \
CK_LIST_NEXT((inp), inp_hash))

Definition at line 1647 of file in_pcb.c.

◆ II_LOCK_ASSERT

#define II_LOCK_ASSERT (   inp,
  lock 
)
Value:
rw_assert(&(inp)->inp_lock, \
(lock) == INPLOOKUP_RLOCKPCB ? RA_RLOCKED : RA_WLOCKED )
static void inp_lock(struct inpcb *inp, const inp_lookup_t lock)
Definition: in_pcb.c:1546
@ INPLOOKUP_RLOCKPCB
Definition: in_pcb.h:693

Definition at line 1651 of file in_pcb.c.

◆ INP_FREED

#define INP_FREED   0x00000200 /* See in_pcb.h. */

Definition at line 118 of file in_pcb.c.

◆ INPCBLBGROUP_SIZMAX

#define INPCBLBGROUP_SIZMAX   256

Definition at line 117 of file in_pcb.c.

◆ INPCBLBGROUP_SIZMIN

#define INPCBLBGROUP_SIZMIN   8

Definition at line 116 of file in_pcb.c.

◆ V_ipport_tcplastcount

#define V_ipport_tcplastcount   VNET(ipport_tcplastcount)

Definition at line 149 of file in_pcb.c.

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ CTASSERT()

CTASSERT ( sizeof(struct inpcbhead)  = =sizeof(LIST_HEAD(, inpcb)))

◆ in_losing()

void in_losing ( struct inpcb inp)

Definition at line 2577 of file in_pcb.c.

References inpcb::inp_route.

Referenced by bbr_timeout_rxt(), rack_timeout_rxt(), and tcp_timer_rexmt().

Here is the caller graph for this function:

◆ in_pcballoc()

◆ in_pcbbind_check_bindmulti()

int in_pcbbind_check_bindmulti ( const struct inpcb ni,
const struct inpcb oi 
)

Definition at line 904 of file in_pcb.c.

References INP_BINDMULTI, inpcb::inp_cred, and inpcb::inp_flags2.

◆ in_pcbdetach()

void in_pcbdetach ( struct inpcb inp)

Definition at line 1524 of file in_pcb.c.

References inpcb::inp_snd_tag, and inpcb::inp_socket.

Referenced by div_detach(), tcp_usr_attach(), and tcp_usr_detach().

Here is the caller graph for this function:

◆ in_pcbdrop()

void in_pcbdrop ( struct inpcb inp)

◆ in_pcbfree()

◆ in_pcbhashseed_init()

static void in_pcbhashseed_init ( void  )
static

Definition at line 253 of file in_pcb.c.

References V_in_pcbhashseed.

◆ in_pcbinfo_destroy()

void in_pcbinfo_destroy ( struct inpcbinfo pcbinfo)

◆ in_pcbinfo_init()

◆ in_pcbinshash()

◆ in_pcbinslbgrouphash()

◆ in_pcblbgroup_alloc()

static struct inpcblbgroup * in_pcblbgroup_alloc ( struct inpcblbgrouphead *  hdr,
u_char  vflag,
uint16_t  port,
const union in_dependaddr addr,
int  size,
uint8_t  numa_domain 
)
static

◆ in_pcblbgroup_free()

static void in_pcblbgroup_free ( struct inpcblbgroup grp)
static

Definition at line 300 of file in_pcb.c.

References inpcblbgroup::il_epoch_ctx, and in_pcblbgroup_free_deferred().

Referenced by in_pcblbgroup_resize(), and in_pcbremlbgrouphash().

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

◆ in_pcblbgroup_free_deferred()

static void in_pcblbgroup_free_deferred ( epoch_context_t  ctx)
static

Definition at line 291 of file in_pcb.c.

References inpcblbgroup::il_epoch_ctx.

Referenced by in_pcblbgroup_free().

Here is the caller graph for this function:

◆ in_pcblbgroup_numa()

int in_pcblbgroup_numa ( struct inpcb inp,
int  arg 
)

◆ in_pcblbgroup_reorder()

static void in_pcblbgroup_reorder ( struct inpcblbgrouphead *  hdr,
struct inpcblbgroup **  grpp,
int  i 
)
static

Definition at line 336 of file in_pcb.c.

References inpcblbgroup::il_inp, inpcblbgroup::il_inpcnt, inpcblbgroup::il_inpsiz, in_pcblbgroup_resize(), and INPCBLBGROUP_SIZMIN.

Referenced by in_pcbremlbgrouphash().

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

◆ in_pcblbgroup_resize()

static struct inpcblbgroup * in_pcblbgroup_resize ( struct inpcblbgrouphead *  hdr,
struct inpcblbgroup old_grp,
int  size 
)
static

◆ in_pcbref()

void in_pcbref ( struct inpcb inp)

Definition at line 1762 of file in_pcb.c.

References inpcb::inp_refcount.

Referenced by inp_hpts_insert(), inp_join_group(), tcp_log_tcpcbfini(), tcp_newtcpcb(), tcp_tw_2msl_scan(), and tcp_twstart().

Here is the caller graph for this function:

◆ in_pcbrehash()

◆ in_pcbrele()

static bool in_pcbrele ( struct inpcb inp,
const inp_lookup_t  lock 
)
inlinestatic

Definition at line 1570 of file in_pcb.c.

References in_pcbrele_rlocked(), in_pcbrele_wlocked(), and INPLOOKUP_RLOCKPCB.

Referenced by inp_next(), and inp_smr_lock().

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

◆ in_pcbrele_rlocked()

bool in_pcbrele_rlocked ( struct inpcb inp)

Definition at line 1775 of file in_pcb.c.

References inpcb::inp_flags, INP_FREED, inpcb::inp_in_hpts, inpcb::inp_pcbinfo, inpcb::inp_refcount, INP_RLOCK_ASSERT, INP_RUNLOCK, inpcb::inp_socket, and inpcbinfo::ipi_zone.

Referenced by in_pcbrele().

Here is the caller graph for this function:

◆ in_pcbrele_wlocked()

◆ in_pcbremlbgrouphash()

static void in_pcbremlbgrouphash ( struct inpcb inp)
static

◆ in_pcbsosetlabel()

void in_pcbsosetlabel ( struct socket *  so)

Definition at line 2589 of file in_pcb.c.

References INP_WLOCK, INP_WUNLOCK, and sotoinpcb.

◆ in_pcbstorage_destroy()

void in_pcbstorage_destroy ( void *  arg)

Definition at line 590 of file in_pcb.c.

References inpcbstorage::ips_portzone, and inpcbstorage::ips_zone.

◆ in_pcbstorage_init()

void in_pcbstorage_init ( void *  arg)

◆ in_pcbtoxinpcb()

◆ inp_4tuple_get()

void inp_4tuple_get ( struct inpcb inp,
uint32_t laddr,
uint16_t lp,
uint32_t faddr,
uint16_t fp 
)

Definition at line 2743 of file in_pcb.c.

References INP_LOCK_ASSERT.

◆ inp_apply_all()

void inp_apply_all ( void(*)(struct inpcb *, void *)  func,
void *  arg 
)

Definition at line 2702 of file in_pcb.c.

References INP_ALL_ITERATOR, inp_next(), INPLOOKUP_WLOCKPCB, and V_tcbinfo.

Referenced by register_toedev().

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

◆ inp_inpcbtosocket()

struct socket * inp_inpcbtosocket ( struct inpcb inp)

Definition at line 2713 of file in_pcb.c.

References inpcb::inp_socket, and INP_WLOCK_ASSERT.

◆ inp_inpcbtotcpcb()

struct tcpcb * inp_inpcbtotcpcb ( struct inpcb inp)

Definition at line 2721 of file in_pcb.c.

References inpcb::inp_ppcb, and INP_WLOCK_ASSERT.

◆ inp_ip_tos_get()

int inp_ip_tos_get ( const struct inpcb inp)

Definition at line 2729 of file in_pcb.c.

References inpcb::inp_ip_tos.

◆ inp_ip_tos_set()

void inp_ip_tos_set ( struct inpcb inp,
int  val 
)

Definition at line 2736 of file in_pcb.c.

References inpcb::inp_ip_tos.

◆ inp_lock()

static void inp_lock ( struct inpcb inp,
const inp_lookup_t  lock 
)
inlinestatic

Definition at line 1546 of file in_pcb.c.

References inpcb::inp_lock, and INPLOOKUP_RLOCKPCB.

Referenced by inp_next(), and inp_smr_lock().

Here is the caller graph for this function:

◆ inp_next()

◆ inp_rlock()

void inp_rlock ( struct inpcb inp)

Definition at line 2672 of file in_pcb.c.

References INP_RLOCK.

◆ inp_runlock()

void inp_runlock ( struct inpcb inp)

Definition at line 2679 of file in_pcb.c.

References INP_RUNLOCK.

◆ inp_smr_lock()

bool inp_smr_lock ( struct inpcb inp,
const inp_lookup_t  lock 
)

Definition at line 1578 of file in_pcb.c.

References in_pcbrele(), inpcb::inp_flags, INP_FREED, inp_lock(), inpcb::inp_pcbinfo, inpcb::inp_refcount, inp_trylock(), inp_unlock(), INPLOOKUP_RLOCKPCB, INPLOOKUP_WLOCKPCB, and inpcbinfo::ipi_smr.

Referenced by inp_next().

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

◆ inp_trylock()

static int inp_trylock ( struct inpcb inp,
const inp_lookup_t  lock 
)
inlinestatic

Definition at line 1562 of file in_pcb.c.

References inpcb::inp_lock, and INPLOOKUP_RLOCKPCB.

Referenced by inp_next(), and inp_smr_lock().

Here is the caller graph for this function:

◆ inp_unlock()

static void inp_unlock ( struct inpcb inp,
const inp_lookup_t  lock 
)
inlinestatic

Definition at line 1554 of file in_pcb.c.

References inpcb::inp_lock, and INPLOOKUP_RLOCKPCB.

Referenced by inp_next(), inp_smr_lock(), and siftr_chkpkt().

Here is the caller graph for this function:

◆ inp_wlock()

void inp_wlock ( struct inpcb inp)

Definition at line 2658 of file in_pcb.c.

References INP_WLOCK.

◆ inp_wunlock()

void inp_wunlock ( struct inpcb inp)

Definition at line 2665 of file in_pcb.c.

References INP_WUNLOCK.

◆ inpcb_dtor()

static void inpcb_dtor ( void *  mem,
int  size,
void *  arg 
)
static

Definition at line 1891 of file in_pcb.c.

References inpcb::inp_cred.

Referenced by in_pcbstorage_init().

Here is the caller graph for this function:

◆ inpcb_fini()

static void inpcb_fini ( void *  mem,
int  size 
)
static

Definition at line 1906 of file in_pcb.c.

References INP_LOCK_DESTROY.

Referenced by in_pcbstorage_init().

Here is the caller graph for this function:

◆ ip_fini()

static void ip_fini ( void *  xtp)
static

Definition at line 2634 of file in_pcb.c.

References ipport_tick_callout.

Referenced by ipport_tick_init().

Here is the caller graph for this function:

◆ ipport_tick()

static void ipport_tick ( void *  xtp)
static

Definition at line 2613 of file in_pcb.c.

References ipport_tick(), ipport_tick_callout, V_ipport_randomcps, V_ipport_randomtime, V_ipport_stoprandom, V_ipport_tcpallocs, and V_ipport_tcplastcount.

Referenced by ipport_tick(), and ipport_tick_init().

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

◆ ipport_tick_init()

static void ipport_tick_init ( const void *unused  __unused)
static

Definition at line 2645 of file in_pcb.c.

References ip_fini(), ipport_tick(), and ipport_tick_callout.

Here is the call graph for this function:

◆ so_sotoinpcb()

struct inpcb * so_sotoinpcb ( struct socket *  so)

Definition at line 2755 of file in_pcb.c.

References sotoinpcb.

◆ so_sototcpcb()

struct tcpcb * so_sototcpcb ( struct socket *  so)

Definition at line 2762 of file in_pcb.c.

References sototcpcb.

◆ sysctl_setsockopt()

int sysctl_setsockopt ( SYSCTL_HANDLER_ARGS  ,
struct inpcbinfo pcbinfo,
int(*)(struct inpcb *, struct sockopt *)  ctloutput_set 
)

Definition at line 2803 of file in_pcb.c.

References inpcb_iterator::hash, INC_ISIPV6, INP6_PCBHASH, INP_ALL_ITERATOR, INP_DROPPED, inpcb::inp_flags, inpcb::inp_gencnt, inp_next(), INP_PCBHASH, INP_PCBHASH_WILD, inpcb::inp_socket, INP_TIMEWAIT, INP_WUNLOCK, INPLOOKUP_WLOCKPCB, and inpcbinfo::ipi_hashmask.

Referenced by tcp_sysctl_setsockopt().

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

◆ SYSINIT()

SYSINIT ( ipport_tick_init  ,
SI_SUB_PROTO_DOMAIN  ,
SI_ORDER_MIDDLE  ,
ipport_tick_init  ,
NULL   
)

◆ VNET_DEFINE() [1/14]

VNET_DEFINE ( int  ,
ipport_firstauto   
)

◆ VNET_DEFINE() [2/14]

VNET_DEFINE ( int  ,
ipport_hifirstauto   
)

◆ VNET_DEFINE() [3/14]

VNET_DEFINE ( int  ,
ipport_hilastauto   
)

◆ VNET_DEFINE() [4/14]

VNET_DEFINE ( int  ,
ipport_lastauto   
)

◆ VNET_DEFINE() [5/14]

VNET_DEFINE ( int  ,
ipport_lowfirstauto   
)

◆ VNET_DEFINE() [6/14]

VNET_DEFINE ( int  ,
ipport_lowlastauto   
)

◆ VNET_DEFINE() [7/14]

VNET_DEFINE ( int  ,
ipport_randomcps   
)

◆ VNET_DEFINE() [8/14]

VNET_DEFINE ( int  ,
ipport_randomized   
)

◆ VNET_DEFINE() [9/14]

VNET_DEFINE ( int  ,
ipport_randomtime   
)

◆ VNET_DEFINE() [10/14]

VNET_DEFINE ( int  ,
ipport_reservedhigh   
)

◆ VNET_DEFINE() [11/14]

VNET_DEFINE ( int  ,
ipport_reservedlow   
)

◆ VNET_DEFINE() [12/14]

VNET_DEFINE ( int  ,
ipport_stoprandom   
)

◆ VNET_DEFINE() [13/14]

VNET_DEFINE ( int  ,
ipport_tcpallocs   
)

◆ VNET_DEFINE() [14/14]

VNET_DEFINE ( uint32_t  ,
in_pcbhashseed   
)

◆ VNET_DEFINE_STATIC()

VNET_DEFINE_STATIC ( int  ,
ipport_tcplastcount   
)

◆ VNET_SYSINIT()

VNET_SYSINIT ( in_pcbhashseed_init  ,
SI_SUB_PROTO_DOMAIN  ,
SI_ORDER_FIRST  ,
in_pcbhashseed_init  ,
 
)

Variable Documentation

◆ ipport_tick_callout

struct callout ipport_tick_callout
static

Definition at line 120 of file in_pcb.c.

Referenced by ip_fini(), ipport_tick(), and ipport_tick_init().