FreeBSD kernel kern code
uipc_sockbuf.c File Reference
#include <sys/cdefs.h>
#include "opt_kern_tls.h"
#include "opt_param.h"
#include <sys/param.h>
#include <sys/aio.h>
#include <sys/kernel.h>
#include <sys/ktls.h>
#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/mbuf.h>
#include <sys/mutex.h>
#include <sys/proc.h>
#include <sys/protosw.h>
#include <sys/resourcevar.h>
#include <sys/signalvar.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
#include <sys/sx.h>
#include <sys/sysctl.h>
Include dependency graph for uipc_sockbuf.c:

Go to the source code of this file.

Macros

#define SBLINKRECORD(sb, m0)
 

Functions

 __FBSDID ("$FreeBSD$")
 
static struct mbuf * sbcut_internal (struct sockbuf *sb, int len)
 
static void sbflush_internal (struct sockbuf *sb)
 
static void sbm_clrprotoflags (struct mbuf *m, int flags)
 
static void sbready_compress (struct sockbuf *sb, struct mbuf *m0, struct mbuf *end)
 
int sbready (struct sockbuf *sb, struct mbuf *m0, int count)
 
void sballoc (struct sockbuf *sb, struct mbuf *m)
 
void sbfree (struct sockbuf *sb, struct mbuf *m)
 
void socantsendmore_locked (struct socket *so)
 
void socantsendmore (struct socket *so)
 
void socantrcvmore_locked (struct socket *so)
 
void socantrcvmore (struct socket *so)
 
void soroverflow_locked (struct socket *so)
 
void soroverflow (struct socket *so)
 
int sbwait (struct sockbuf *sb)
 
void sowakeup (struct socket *so, struct sockbuf *sb)
 
int soreserve (struct socket *so, u_long sndcc, u_long rcvcc)
 
static int sysctl_handle_sb_max (SYSCTL_HANDLER_ARGS)
 
int sbreserve_locked (struct sockbuf *sb, u_long cc, struct socket *so, struct thread *td)
 
int sbsetopt (struct socket *so, int cmd, u_long cc)
 
void sbrelease_internal (struct sockbuf *sb, struct socket *so)
 
void sbrelease_locked (struct sockbuf *sb, struct socket *so)
 
void sbrelease (struct sockbuf *sb, struct socket *so)
 
void sbdestroy (struct sockbuf *sb, struct socket *so)
 
void sbappend_locked (struct sockbuf *sb, struct mbuf *m, int flags)
 
void sbappend (struct sockbuf *sb, struct mbuf *m, int flags)
 
void sbappendstream_locked (struct sockbuf *sb, struct mbuf *m, int flags)
 
void sbappendstream (struct sockbuf *sb, struct mbuf *m, int flags)
 
void sbappendrecord_locked (struct sockbuf *sb, struct mbuf *m0)
 
void sbappendrecord (struct sockbuf *sb, struct mbuf *m0)
 
static int sbappendaddr_locked_internal (struct sockbuf *sb, const struct sockaddr *asa, struct mbuf *m0, struct mbuf *control, struct mbuf *ctrl_last)
 
int sbappendaddr_locked (struct sockbuf *sb, const struct sockaddr *asa, struct mbuf *m0, struct mbuf *control)
 
int sbappendaddr_nospacecheck_locked (struct sockbuf *sb, const struct sockaddr *asa, struct mbuf *m0, struct mbuf *control)
 
int sbappendaddr (struct sockbuf *sb, const struct sockaddr *asa, struct mbuf *m0, struct mbuf *control)
 
void sbappendcontrol_locked (struct sockbuf *sb, struct mbuf *m0, struct mbuf *control, int flags)
 
void sbappendcontrol (struct sockbuf *sb, struct mbuf *m0, struct mbuf *control, int flags)
 
void sbcompress (struct sockbuf *sb, struct mbuf *m, struct mbuf *n)
 
void sbflush_locked (struct sockbuf *sb)
 
void sbflush (struct sockbuf *sb)
 
void sbdrop_locked (struct sockbuf *sb, int len)
 
struct mbuf * sbcut_locked (struct sockbuf *sb, int len)
 
void sbdrop (struct sockbuf *sb, int len)
 
struct mbuf * sbsndptr_noadv (struct sockbuf *sb, uint32_t off, uint32_t *moff)
 
void sbsndptr_adv (struct sockbuf *sb, struct mbuf *mb, uint32_t len)
 
struct mbuf * sbsndmbuf (struct sockbuf *sb, u_int off, u_int *moff)
 
void sbdroprecord_locked (struct sockbuf *sb)
 
void sbdroprecord (struct sockbuf *sb)
 
struct mbuf * sbcreatecontrol_how (void *p, int size, int type, int level, int wait)
 
struct mbuf * sbcreatecontrol (caddr_t p, int size, int type, int level)
 
void sbtoxsockbuf (struct sockbuf *sb, struct xsockbuf *xsb)
 
 SYSCTL_INT (_kern, KERN_DUMMY, dummy, CTLFLAG_RW|CTLFLAG_SKIP, &dummy, 0, "")
 
 SYSCTL_OID (_kern_ipc, KIPC_MAXSOCKBUF, maxsockbuf, CTLTYPE_ULONG|CTLFLAG_RW|CTLFLAG_MPSAFE, &sb_max, 0, sysctl_handle_sb_max, "LU", "Maximum socket buffer size")
 
 SYSCTL_ULONG (_kern_ipc, KIPC_SOCKBUF_WASTE, sockbuf_waste_factor, CTLFLAG_RW, &sb_efficiency, 0, "Socket buffer size waste factor")
 

Variables

void(* aio_swake )(struct socket *, struct sockbuf *)
 
u_long sb_max = SB_MAX
 
u_long sb_max_adj
 
static u_long sb_efficiency = 8
 
static int dummy
 

Macro Definition Documentation

◆ SBLINKRECORD

#define SBLINKRECORD (   sb,
  m0 
)
Value:
do { \
SOCKBUF_LOCK_ASSERT(sb); \
if ((sb)->sb_lastrecord != NULL) \
(sb)->sb_lastrecord->m_nextpkt = (m0); \
else \
(sb)->sb_mb = (m0); \
(sb)->sb_lastrecord = (m0); \
} while (/*CONSTCOND*/0)

Definition at line 843 of file uipc_sockbuf.c.

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ sballoc()

void sballoc ( struct sockbuf *  sb,
struct mbuf *  m 
)

Definition at line 265 of file uipc_sockbuf.c.

Referenced by sbappendaddr_locked_internal(), sbappendcontrol_locked(), sbappendrecord_locked(), and sbcompress().

Here is the caller graph for this function:

◆ sbappend()

void sbappend ( struct sockbuf *  sb,
struct mbuf *  m,
int  flags 
)

Definition at line 909 of file uipc_sockbuf.c.

References flags, and sbappend_locked().

Here is the call graph for this function:

◆ sbappend_locked()

void sbappend_locked ( struct sockbuf *  sb,
struct mbuf *  m,
int  flags 
)

Definition at line 858 of file uipc_sockbuf.c.

References flags, sbappendrecord_locked(), sbcompress(), and sbm_clrprotoflags().

Referenced by sbappend(), and uipc_send().

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

◆ sbappendaddr()

int sbappendaddr ( struct sockbuf *  sb,
const struct sockaddr *  asa,
struct mbuf *  m0,
struct mbuf *  control 
)

Definition at line 1230 of file uipc_sockbuf.c.

References sbappendaddr_locked().

Here is the call graph for this function:

◆ sbappendaddr_locked()

int sbappendaddr_locked ( struct sockbuf *  sb,
const struct sockaddr *  asa,
struct mbuf *  m0,
struct mbuf *  control 
)

Definition at line 1186 of file uipc_sockbuf.c.

References m_length(), panic(), and sbappendaddr_locked_internal().

Referenced by sbappendaddr(), and uipc_send().

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

◆ sbappendaddr_locked_internal()

static int sbappendaddr_locked_internal ( struct sockbuf *  sb,
const struct sockaddr *  asa,
struct mbuf *  m0,
struct mbuf *  control,
struct mbuf *  ctrl_last 
)
static

Definition at line 1133 of file uipc_sockbuf.c.

References m_tag_delete_chain(), sballoc(), and SBLINKRECORD.

Referenced by sbappendaddr_locked(), and sbappendaddr_nospacecheck_locked().

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

◆ sbappendaddr_nospacecheck_locked()

int sbappendaddr_nospacecheck_locked ( struct sockbuf *  sb,
const struct sockaddr *  asa,
struct mbuf *  m0,
struct mbuf *  control 
)

Definition at line 1212 of file uipc_sockbuf.c.

References sbappendaddr_locked_internal().

Referenced by uipc_send().

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

◆ sbappendcontrol()

void sbappendcontrol ( struct sockbuf *  sb,
struct mbuf *  m0,
struct mbuf *  control,
int  flags 
)

Definition at line 1265 of file uipc_sockbuf.c.

References flags, and sbappendcontrol_locked().

Here is the call graph for this function:

◆ sbappendcontrol_locked()

void sbappendcontrol_locked ( struct sockbuf *  sb,
struct mbuf *  m0,
struct mbuf *  control,
int  flags 
)

Definition at line 1242 of file uipc_sockbuf.c.

References flags, sballoc(), SBLINKRECORD, and sbm_clrprotoflags().

Referenced by ktls_decrypt(), sbappendcontrol(), and uipc_send().

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

◆ sbappendrecord()

void sbappendrecord ( struct sockbuf *  sb,
struct mbuf *  m0 
)

Definition at line 1123 of file uipc_sockbuf.c.

References sbappendrecord_locked().

Here is the call graph for this function:

◆ sbappendrecord_locked()

void sbappendrecord_locked ( struct sockbuf *  sb,
struct mbuf *  m0 
)

Definition at line 1092 of file uipc_sockbuf.c.

References sballoc(), sbcompress(), and SBLINKRECORD.

Referenced by sbappend_locked(), and sbappendrecord().

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

◆ sbappendstream()

void sbappendstream ( struct sockbuf *  sb,
struct mbuf *  m,
int  flags 
)

Definition at line 988 of file uipc_sockbuf.c.

References flags, and sbappendstream_locked().

Here is the call graph for this function:

◆ sbappendstream_locked()

void sbappendstream_locked ( struct sockbuf *  sb,
struct mbuf *  m,
int  flags 
)

Definition at line 946 of file uipc_sockbuf.c.

References flags, ktls_seq(), m_demote(), and sbcompress().

Referenced by sbappendstream().

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

◆ sbcompress()

void sbcompress ( struct sockbuf *  sb,
struct mbuf *  m,
struct mbuf *  n 
)

Definition at line 1295 of file uipc_sockbuf.c.

References m_copydata(), mb_unmapped_compress(), and sballoc().

Referenced by sbappend_locked(), sbappendrecord_locked(), and sbappendstream_locked().

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

◆ sbcreatecontrol()

struct mbuf * sbcreatecontrol ( caddr_t  p,
int  size,
int  type,
int  level 
)

Definition at line 1756 of file uipc_sockbuf.c.

References level, sbcreatecontrol_how(), and type.

Referenced by unp_addsockcred(), unp_externalize(), and unp_internalize().

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

◆ sbcreatecontrol_how()

struct mbuf * sbcreatecontrol_how ( void *  p,
int  size,
int  type,
int  level,
int  wait 
)

Definition at line 1723 of file uipc_sockbuf.c.

References level, and type.

Referenced by ktls_decrypt(), and sbcreatecontrol().

Here is the caller graph for this function:

◆ sbcut_internal()

static struct mbuf * sbcut_internal ( struct sockbuf *  sb,
int  len 
)
static

Definition at line 1456 of file uipc_sockbuf.c.

References sbfree().

Referenced by sbcut_locked(), sbdrop(), sbdrop_locked(), and sbflush_internal().

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

◆ sbcut_locked()

struct mbuf * sbcut_locked ( struct sockbuf *  sb,
int  len 
)

Definition at line 1584 of file uipc_sockbuf.c.

References sbcut_internal().

Referenced by soreceive_generic().

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

◆ sbdestroy()

void sbdestroy ( struct sockbuf *  sb,
struct socket *  so 
)

Definition at line 742 of file uipc_sockbuf.c.

References sbrelease_internal().

Referenced by sofree(), and solisten_proto().

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

◆ sbdrop()

void sbdrop ( struct sockbuf *  sb,
int  len 
)

Definition at line 1592 of file uipc_sockbuf.c.

References m_freem(), and sbcut_internal().

Here is the call graph for this function:

◆ sbdrop_locked()

void sbdrop_locked ( struct sockbuf *  sb,
int  len 
)

Definition at line 1572 of file uipc_sockbuf.c.

References m_freem(), and sbcut_internal().

Referenced by soisdisconnected(), and soreceive_stream().

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

◆ sbdroprecord()

void sbdroprecord ( struct sockbuf *  sb)

Definition at line 1710 of file uipc_sockbuf.c.

References sbdroprecord_locked().

Here is the call graph for this function:

◆ sbdroprecord_locked()

void sbdroprecord_locked ( struct sockbuf *  sb)

Definition at line 1688 of file uipc_sockbuf.c.

References sbfree().

Referenced by sbdroprecord(), and soreceive_generic().

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

◆ sbflush()

void sbflush ( struct sockbuf *  sb)

Definition at line 1444 of file uipc_sockbuf.c.

References sbflush_locked().

Here is the call graph for this function:

◆ sbflush_internal()

static void sbflush_internal ( struct sockbuf *  sb)
static

Definition at line 1418 of file uipc_sockbuf.c.

References m_freem(), and sbcut_internal().

Referenced by sbflush_locked(), and sbrelease_internal().

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

◆ sbflush_locked()

void sbflush_locked ( struct sockbuf *  sb)

Definition at line 1436 of file uipc_sockbuf.c.

References sbflush_internal().

Referenced by sbflush().

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

◆ sbfree()

void sbfree ( struct sockbuf *  sb,
struct mbuf *  m 
)

Definition at line 296 of file uipc_sockbuf.c.

Referenced by sbcut_internal(), sbdroprecord_locked(), soreceive_dgram(), soreceive_generic(), and soreceive_stream().

Here is the caller graph for this function:

◆ sbm_clrprotoflags()

static void sbm_clrprotoflags ( struct mbuf *  m,
int  flags 
)
static

Definition at line 84 of file uipc_sockbuf.c.

References flags, and mask.

Referenced by sbappend_locked(), and sbappendcontrol_locked().

Here is the caller graph for this function:

◆ sbready()

int sbready ( struct sockbuf *  sb,
struct mbuf *  m0,
int  count 
)

Definition at line 200 of file uipc_sockbuf.c.

References count, and sbready_compress().

Referenced by uipc_ready(), and uipc_ready_scan().

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

◆ sbready_compress()

static void sbready_compress ( struct sockbuf *  sb,
struct mbuf *  m0,
struct mbuf *  end 
)
static

Definition at line 107 of file uipc_sockbuf.c.

References m_copydata(), and mb_unmapped_compress().

Referenced by sbready().

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

◆ sbrelease()

void sbrelease ( struct sockbuf *  sb,
struct socket *  so 
)

Definition at line 733 of file uipc_sockbuf.c.

References sbrelease_locked().

Referenced by uipc_detach().

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

◆ sbrelease_internal()

void sbrelease_internal ( struct sockbuf *  sb,
struct socket *  so 
)

Definition at line 714 of file uipc_sockbuf.c.

References chgsbsize(), and sbflush_internal().

Referenced by sbdestroy(), sbrelease_locked(), and sorflush().

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

◆ sbrelease_locked()

void sbrelease_locked ( struct sockbuf *  sb,
struct socket *  so 
)

Definition at line 724 of file uipc_sockbuf.c.

References sbrelease_internal().

Referenced by sbrelease(), and soreserve().

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

◆ sbreserve_locked()

int sbreserve_locked ( struct sockbuf *  sb,
u_long  cc,
struct socket *  so,
struct thread *  td 
)

Definition at line 604 of file uipc_sockbuf.c.

References chgsbsize(), lim_cur(), sb_efficiency, sb_max, and sb_max_adj.

Referenced by sbsetopt(), and soreserve().

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

◆ sbsetopt()

int sbsetopt ( struct socket *  so,
int  cmd,
u_long  cc 
)

Definition at line 634 of file uipc_sockbuf.c.

References flags, sb_max_adj, and sbreserve_locked().

Referenced by sosetopt().

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

◆ sbsndmbuf()

struct mbuf * sbsndmbuf ( struct sockbuf *  sb,
u_int  off,
u_int *  moff 
)

Definition at line 1657 of file uipc_sockbuf.c.

◆ sbsndptr_adv()

void sbsndptr_adv ( struct sockbuf *  sb,
struct mbuf *  mb,
uint32_t  len 
)

Definition at line 1625 of file uipc_sockbuf.c.

◆ sbsndptr_noadv()

struct mbuf * sbsndptr_noadv ( struct sockbuf *  sb,
uint32_t  off,
uint32_t *  moff 
)

Definition at line 1604 of file uipc_sockbuf.c.

◆ sbtoxsockbuf()

void sbtoxsockbuf ( struct sockbuf *  sb,
struct xsockbuf *  xsb 
)

Definition at line 1770 of file uipc_sockbuf.c.

Referenced by sotoxsocket().

Here is the caller graph for this function:

◆ sbwait()

int sbwait ( struct sockbuf *  sb)

Definition at line 467 of file uipc_sockbuf.c.

Referenced by soreceive_dgram(), soreceive_generic(), soreceive_stream(), sosend_generic(), and vn_sendfile().

Here is the caller graph for this function:

◆ socantrcvmore()

void socantrcvmore ( struct socket *  so)

Definition at line 431 of file uipc_sockbuf.c.

References socantrcvmore_locked().

Referenced by sorflush(), and unp_shutdown().

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

◆ socantrcvmore_locked()

void socantrcvmore_locked ( struct socket *  so)

Definition at line 416 of file uipc_sockbuf.c.

References ktls_check_rx().

Referenced by socantrcvmore(), soisdisconnected(), and soisdisconnecting().

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

◆ socantsendmore()

void socantsendmore ( struct socket *  so)

Definition at line 407 of file uipc_sockbuf.c.

References socantsendmore_locked().

Referenced by uipc_send(), and uipc_shutdown().

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

◆ socantsendmore_locked()

void socantsendmore_locked ( struct socket *  so)

Definition at line 396 of file uipc_sockbuf.c.

Referenced by socantsendmore(), soisdisconnected(), and soisdisconnecting().

Here is the caller graph for this function:

◆ soreserve()

int soreserve ( struct socket *  so,
u_long  sndcc,
u_long  rcvcc 
)

Definition at line 556 of file uipc_sockbuf.c.

References sbrelease_locked(), and sbreserve_locked().

Referenced by sonewconn(), and uipc_attach().

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

◆ soroverflow()

void soroverflow ( struct socket *  so)

Definition at line 455 of file uipc_sockbuf.c.

References soroverflow_locked().

Here is the call graph for this function:

◆ soroverflow_locked()

void soroverflow_locked ( struct socket *  so)

Definition at line 440 of file uipc_sockbuf.c.

Referenced by soroverflow(), and uipc_send().

Here is the caller graph for this function:

◆ sowakeup()

void sowakeup ( struct socket *  so,
struct sockbuf *  sb 
)

Definition at line 491 of file uipc_sockbuf.c.

References pgsigio(), selwakeuppri(), soisconnected(), soupcall_clear(), sowakeup_aio(), and wakeup().

Here is the call graph for this function:

◆ sysctl_handle_sb_max()

static int sysctl_handle_sb_max ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 584 of file uipc_sockbuf.c.

References sb_max, sb_max_adj, and sysctl_handle_long().

Here is the call graph for this function:

◆ SYSCTL_INT()

SYSCTL_INT ( _kern  ,
KERN_DUMMY  ,
dummy  ,
CTLFLAG_RW|  CTLFLAG_SKIP,
dummy,
,
""   
)

◆ SYSCTL_OID()

SYSCTL_OID ( _kern_ipc  ,
KIPC_MAXSOCKBUF  ,
maxsockbuf  ,
CTLTYPE_ULONG|CTLFLAG_RW|  CTLFLAG_MPSAFE,
sb_max,
,
sysctl_handle_sb_max  ,
"LU"  ,
"Maximum socket buffer size"   
)

◆ SYSCTL_ULONG()

SYSCTL_ULONG ( _kern_ipc  ,
KIPC_SOCKBUF_WASTE  ,
sockbuf_waste_factor  ,
CTLFLAG_RW  ,
sb_efficiency,
,
"Socket buffer size waste factor"   
)

Variable Documentation

◆ aio_swake

void(* aio_swake) (struct socket *, struct sockbuf *) ( struct socket *  ,
struct sockbuf *   
)

Definition at line 61 of file uipc_sockbuf.c.

◆ dummy

int dummy
static

Definition at line 1785 of file uipc_sockbuf.c.

◆ sb_efficiency

u_long sb_efficiency = 8
static

Definition at line 71 of file uipc_sockbuf.c.

Referenced by sbreserve_locked().

◆ sb_max

u_long sb_max = SB_MAX

Definition at line 67 of file uipc_sockbuf.c.

Referenced by sbreserve_locked(), and sysctl_handle_sb_max().

◆ sb_max_adj

u_long sb_max_adj
Initial value:
=
(quad_t)SB_MAX * MCLBYTES / (MSIZE + MCLBYTES)

Definition at line 68 of file uipc_sockbuf.c.

Referenced by sbreserve_locked(), sbsetopt(), and sysctl_handle_sb_max().