FreeBSD kernel IPv4 code
udp_usrreq.c File Reference
#include <sys/cdefs.h>
#include "opt_inet.h"
#include "opt_inet6.h"
#include "opt_ipsec.h"
#include "opt_route.h"
#include "opt_rss.h"
#include <sys/param.h>
#include <sys/domain.h>
#include <sys/eventhandler.h>
#include <sys/jail.h>
#include <sys/kernel.h>
#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/mbuf.h>
#include <sys/priv.h>
#include <sys/proc.h>
#include <sys/protosw.h>
#include <sys/sdt.h>
#include <sys/signalvar.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
#include <sys/sx.h>
#include <sys/sysctl.h>
#include <sys/syslog.h>
#include <sys/systm.h>
#include <vm/uma.h>
#include <net/if.h>
#include <net/if_var.h>
#include <net/route.h>
#include <net/route/nhop.h>
#include <net/rss_config.h>
#include <netinet/in.h>
#include <netinet/in_kdtrace.h>
#include <netinet/in_fib.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/icmp_var.h>
#include <netinet/ip_var.h>
#include <netinet/ip_options.h>
#include <netinet/udp.h>
#include <netinet/udp_var.h>
#include <netinet/udplite.h>
#include <netinet/in_rss.h>
#include <netipsec/ipsec_support.h>
#include <machine/in_cksum.h>
#include <security/mac/mac_framework.h>
Include dependency graph for udp_usrreq.c:

Go to the source code of this file.

Macros

#define V_udpcb_zone   VNET(udpcb_zone)
 
#define UDBHASHSIZE   128
 

Functions

 __FBSDID ("$FreeBSD$")
 
 VNET_DEFINE (int, udp_cksum)
 
 SYSCTL_INT (_net_inet_udp, UDPCTL_CHECKSUM, checksum, CTLFLAG_VNET|CTLFLAG_RW, &VNET_NAME(udp_cksum), 0, "compute udp checksum")
 
 VNET_DEFINE (int, udp_log_in_vain)=0
 
 SYSCTL_INT (_net_inet_udp, OID_AUTO, log_in_vain, CTLFLAG_VNET|CTLFLAG_RW, &VNET_NAME(udp_log_in_vain), 0, "Log all incoming UDP packets")
 
 VNET_DEFINE (int, udp_blackhole)=0
 
 SYSCTL_INT (_net_inet_udp, OID_AUTO, blackhole, CTLFLAG_VNET|CTLFLAG_RW, &VNET_NAME(udp_blackhole), 0, "Do not send port unreachables for refused connects")
 
 VNET_DEFINE (bool, udp_blackhole_local)
 
 SYSCTL_BOOL (_net_inet_udp, OID_AUTO, blackhole_local, CTLFLAG_VNET|CTLFLAG_RW, &VNET_NAME(udp_blackhole_local), false, "Enforce net.inet.udp.blackhole for locally originated packets")
 
 SYSCTL_ULONG (_net_inet_udp, UDPCTL_MAXDGRAM, maxdgram, CTLFLAG_RW, &udp_sendspace, 0, "Maximum outgoing UDP datagram size")
 
 SYSCTL_ULONG (_net_inet_udp, UDPCTL_RECVSPACE, recvspace, CTLFLAG_RW, &udp_recvspace, 0, "Maximum space for incoming UDP datagrams")
 
 VNET_DEFINE (struct inpcbinfo, udbinfo)
 
 VNET_DEFINE (struct inpcbinfo, ulitecbinfo)
 
 VNET_DEFINE_STATIC (uma_zone_t, udpcb_zone)
 
 VNET_PCPUSTAT_DEFINE (struct udpstat, udpstat)
 
 VNET_PCPUSTAT_SYSINIT (udpstat)
 
 SYSCTL_VNET_PCPUSTAT (_net_inet_udp, UDPCTL_STATS, stats, struct udpstat, udpstat, "UDP statistics (struct udpstat, netinet/udp_var.h)")
 
 INPCBSTORAGE_DEFINE (udpcbstor, "udpinp", "udp_inpcb", "udp", "udphash")
 
 INPCBSTORAGE_DEFINE (udplitecbstor, "udpliteinp", "udplite_inpcb", "udplite", "udplitehash")
 
static void udp_init (void *arg __unused)
 
 VNET_SYSINIT (udp_init, SI_SUB_PROTO_DOMAIN, SI_ORDER_THIRD, udp_init, NULL)
 
void kmod_udpstat_inc (int statnum)
 
int udp_newudpcb (struct inpcb *inp)
 
void udp_discardcb (struct udpcb *up)
 
struct inpcbudp_notify (struct inpcb *inp, int errno)
 
static int udp_pcblist (SYSCTL_HANDLER_ARGS)
 
 SYSCTL_PROC (_net_inet_udp, UDPCTL_PCBLIST, pcblist, CTLTYPE_OPAQUE|CTLFLAG_RD|CTLFLAG_MPSAFE, NULL, 0, udp_pcblist, "S,xinpcb", "List of active UDP sockets")
 
int udp_ctloutput (struct socket *so, struct sockopt *sopt)
 
int udp_set_kernel_tunneling (struct socket *so, udp_tun_func_t f, udp_tun_icmp_t i, void *ctx)
 
int udp_shutdown (struct socket *so)
 

Variables

u_long udp_sendspace = 9216
 
u_long udp_recvspace
 

Macro Definition Documentation

◆ UDBHASHSIZE

#define UDBHASHSIZE   128

Definition at line 156 of file udp_usrreq.c.

◆ V_udpcb_zone

#define V_udpcb_zone   VNET(udpcb_zone)

Definition at line 153 of file udp_usrreq.c.

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ INPCBSTORAGE_DEFINE() [1/2]

INPCBSTORAGE_DEFINE ( udpcbstor  ,
"udpinp"  ,
"udp_inpcb"  ,
"udp"  ,
"udphash"   
)

◆ INPCBSTORAGE_DEFINE() [2/2]

INPCBSTORAGE_DEFINE ( udplitecbstor  ,
"udpliteinp"  ,
"udplite_inpcb"  ,
"udplite"  ,
"udplitehash"   
)

◆ kmod_udpstat_inc()

void kmod_udpstat_inc ( int  statnum)

Definition at line 208 of file udp_usrreq.c.

◆ SYSCTL_BOOL()

SYSCTL_BOOL ( _net_inet_udp  ,
OID_AUTO  ,
blackhole_local  ,
CTLFLAG_VNET|  CTLFLAG_RW,
VNET_NAMEudp_blackhole_local,
false  ,
"Enforce net.inet.udp.blackhole for locally originated packets"   
)

◆ SYSCTL_INT() [1/3]

SYSCTL_INT ( _net_inet_udp  ,
OID_AUTO  ,
blackhole  ,
CTLFLAG_VNET|  CTLFLAG_RW,
VNET_NAMEudp_blackhole,
,
"Do not send port unreachables for refused connects"   
)

◆ SYSCTL_INT() [2/3]

SYSCTL_INT ( _net_inet_udp  ,
OID_AUTO  ,
log_in_vain  ,
CTLFLAG_VNET|  CTLFLAG_RW,
VNET_NAMEudp_log_in_vain,
,
"Log all incoming UDP packets"   
)

◆ SYSCTL_INT() [3/3]

SYSCTL_INT ( _net_inet_udp  ,
UDPCTL_CHECKSUM  ,
checksum  ,
CTLFLAG_VNET|  CTLFLAG_RW,
VNET_NAMEudp_cksum,
,
"compute udp checksum"   
)

◆ SYSCTL_PROC()

SYSCTL_PROC ( _net_inet_udp  ,
UDPCTL_PCBLIST  ,
pcblist  ,
CTLTYPE_OPAQUE|CTLFLAG_RD|  CTLFLAG_MPSAFE,
NULL  ,
,
udp_pcblist  ,
S,
xinpcb"  ,
"List of active UDP sockets"   
)

◆ SYSCTL_ULONG() [1/2]

SYSCTL_ULONG ( _net_inet_udp  ,
UDPCTL_MAXDGRAM  ,
maxdgram  ,
CTLFLAG_RW  ,
udp_sendspace,
,
"Maximum outgoing UDP datagram size"   
)

◆ SYSCTL_ULONG() [2/2]

SYSCTL_ULONG ( _net_inet_udp  ,
UDPCTL_RECVSPACE  ,
recvspace  ,
CTLFLAG_RW  ,
udp_recvspace,
,
"Maximum space for incoming UDP datagrams"   
)

◆ SYSCTL_VNET_PCPUSTAT()

SYSCTL_VNET_PCPUSTAT ( _net_inet_udp  ,
UDPCTL_STATS  ,
stats  ,
struct udpstat  ,
udpstat  ,
"UDP statistics (struct udpstat, netinet/udp_var.h)"   
)

◆ udp_ctloutput()

int udp_ctloutput ( struct socket *  so,
struct sockopt *  sopt 
)

Definition at line 925 of file udp_usrreq.c.

References INP_CHECK_SOCKAF, INP_WLOCK, INP_WUNLOCK, intoudpcb, ip_ctloutput(), sotoinpcb, udpcb::u_rxcslen, udpcb::u_txcslen, UDP_ENCAP, UDPLITE_RECV_CSCOV, and UDPLITE_SEND_CSCOV.

Here is the call graph for this function:

◆ udp_discardcb()

void udp_discardcb ( struct udpcb up)

Definition at line 227 of file udp_usrreq.c.

References V_udpcb_zone.

◆ udp_init()

static void udp_init ( void *arg  __unused)
static

Definition at line 178 of file udp_usrreq.c.

References in_pcbinfo_init(), UDBHASHSIZE, V_udbinfo, V_udpcb_zone, and V_ulitecbinfo.

Here is the call graph for this function:

◆ udp_newudpcb()

int udp_newudpcb ( struct inpcb inp)

Definition at line 215 of file udp_usrreq.c.

References inpcb::inp_ppcb, and V_udpcb_zone.

◆ udp_notify()

struct inpcb * udp_notify ( struct inpcb inp,
int  errno 
)

Definition at line 721 of file udp_usrreq.c.

References inpcb::inp_route, inpcb::inp_socket, and INP_WLOCK_ASSERT.

◆ udp_pcblist()

static int udp_pcblist ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 814 of file udp_usrreq.c.

References cr_canseeinpcb(), in_pcbtoxinpcb(), INP_ALL_ITERATOR, inpcb::inp_gencnt, inp_next(), INP_RUNLOCK, INPLOOKUP_RLOCKPCB, and V_udbinfo.

Here is the call graph for this function:

◆ udp_set_kernel_tunneling()

int udp_set_kernel_tunneling ( struct socket *  so,
udp_tun_func_t  f,
udp_tun_icmp_t  i,
void *  ctx 
)

Definition at line 1547 of file udp_usrreq.c.

References INP_WLOCK, INP_WUNLOCK, intoudpcb, sotoinpcb, udpcb::u_icmp_func, udpcb::u_tun_ctx, and udpcb::u_tun_func.

Referenced by in_gre_setup_socket(), sctp_over_udp_start(), and tcp_over_udp_start().

Here is the caller graph for this function:

◆ udp_shutdown()

int udp_shutdown ( struct socket *  so)

Definition at line 1736 of file udp_usrreq.c.

References INP_WLOCK, INP_WUNLOCK, and sotoinpcb.

◆ VNET_DEFINE() [1/6]

VNET_DEFINE ( bool  ,
udp_blackhole_local   
)

◆ VNET_DEFINE() [2/6]

VNET_DEFINE ( int  ,
udp_blackhole   
)
pure virtual

◆ VNET_DEFINE() [3/6]

VNET_DEFINE ( int  ,
udp_cksum   
)

◆ VNET_DEFINE() [4/6]

VNET_DEFINE ( int  ,
udp_log_in_vain   
)
pure virtual

◆ VNET_DEFINE() [5/6]

VNET_DEFINE ( struct inpcbinfo  ,
udbinfo   
)

◆ VNET_DEFINE() [6/6]

VNET_DEFINE ( struct inpcbinfo  ,
ulitecbinfo   
)

◆ VNET_DEFINE_STATIC()

VNET_DEFINE_STATIC ( uma_zone_t  ,
udpcb_zone   
)

◆ VNET_PCPUSTAT_DEFINE()

VNET_PCPUSTAT_DEFINE ( struct udpstat  ,
udpstat   
)

◆ VNET_PCPUSTAT_SYSINIT()

VNET_PCPUSTAT_SYSINIT ( udpstat  )

◆ VNET_SYSINIT()

VNET_SYSINIT ( udp_init  ,
SI_SUB_PROTO_DOMAIN  ,
SI_ORDER_THIRD  ,
udp_init  ,
NULL   
)

Variable Documentation

◆ udp_recvspace

u_long udp_recvspace
Initial value:
= 40 * (1024 +
sizeof(struct sockaddr_in)
)
Definition: in.h:97

Definition at line 139 of file udp_usrreq.c.

◆ udp_sendspace

u_long udp_sendspace = 9216

Definition at line 135 of file udp_usrreq.c.