FreeBSD kernel IPv4 code
ip_divert.c File Reference
#include <sys/cdefs.h>
#include "opt_inet.h"
#include "opt_inet6.h"
#include "opt_sctp.h"
#include <sys/param.h>
#include <sys/eventhandler.h>
#include <sys/kernel.h>
#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/mbuf.h>
#include <sys/module.h>
#include <sys/priv.h>
#include <sys/proc.h>
#include <sys/protosw.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
#include <sys/sysctl.h>
#include <net/vnet.h>
#include <net/if.h>
#include <net/if_var.h>
#include <net/netisr.h>
#include <netinet/in.h>
#include <netinet/in_pcb.h>
#include <netinet/in_systm.h>
#include <netinet/in_var.h>
#include <netinet/ip.h>
#include <netinet/ip_var.h>
#include <security/mac/mac_framework.h>
Include dependency graph for ip_divert.c:

Go to the source code of this file.

Macros

#define DIVSNDQ   (65536 + 100)
 
#define DIVRCVQ   (65536 + 100)
 
#define V_divcbinfo   VNET(divcbinfo)
 

Functions

 __FBSDID ("$FreeBSD$")
 
 VNET_DEFINE_STATIC (struct inpcbinfo, divcbinfo)
 
static int div_output_inbound (int fmaily, struct socket *so, struct mbuf *m, struct sockaddr_in *sin)
 
static int div_output_outbound (int family, struct socket *so, struct mbuf *m)
 
 INPCBSTORAGE_DEFINE (divcbstor, "divinp", "divcb", "div", "divhash")
 
static void div_init (void *arg __unused)
 
 VNET_SYSINIT (div_init, SI_SUB_PROTO_DOMAIN, SI_ORDER_THIRD, div_init, NULL)
 
static void div_destroy (void *unused __unused)
 
 VNET_SYSUNINIT (divert, SI_SUB_PROTO_DOMAIN, SI_ORDER_THIRD, div_destroy, NULL)
 
static int div_input (struct mbuf **mp, int *offp, int proto)
 
static bool div_port_match (const struct inpcb *inp, void *v)
 
static void divert_packet (struct mbuf *m, bool incoming)
 
static int div_output (struct socket *so, struct mbuf *m, struct sockaddr_in *sin, struct mbuf *control)
 
static int div_attach (struct socket *so, int proto, struct thread *td)
 
static void div_detach (struct socket *so)
 
static int div_bind (struct socket *so, struct sockaddr *nam, struct thread *td)
 
static int div_shutdown (struct socket *so)
 
static int div_send (struct socket *so, int flags, struct mbuf *m, struct sockaddr *nam, struct mbuf *control, struct thread *td)
 
static int div_pcblist (SYSCTL_HANDLER_ARGS)
 
static int div_modevent (module_t mod, int type, void *unused)
 
 DECLARE_MODULE (ipdivert, ipdivertmod, SI_SUB_PROTO_FIREWALL, SI_ORDER_ANY)
 
 MODULE_DEPEND (ipdivert, ipfw, 3, 3, 3)
 
 MODULE_VERSION (ipdivert, 1)
 

Variables

static u_long div_sendspace = DIVSNDQ
 
static u_long div_recvspace = DIVRCVQ
 
struct pr_usrreqs div_usrreqs
 
struct protosw div_protosw
 
static moduledata_t ipdivertmod
 

Macro Definition Documentation

◆ DIVRCVQ

#define DIVRCVQ   (65536 + 100)

Definition at line 85 of file ip_divert.c.

◆ DIVSNDQ

#define DIVSNDQ   (65536 + 100)

Definition at line 84 of file ip_divert.c.

◆ V_divcbinfo

#define V_divcbinfo   VNET(divcbinfo)

Definition at line 115 of file ip_divert.c.

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ DECLARE_MODULE()

DECLARE_MODULE ( ipdivert  ,
ipdivertmod  ,
SI_SUB_PROTO_FIREWALL  ,
SI_ORDER_ANY   
)

◆ div_attach()

static int div_attach ( struct socket *  so,
int  proto,
struct thread *  td 
)
static

Definition at line 574 of file ip_divert.c.

References div_recvspace, div_sendspace, in_pcballoc(), inpcb::inp_flags, INP_HDRINCL, inpcb::inp_ip_p, INP_IPV4, inpcb::inp_vflag, INP_WUNLOCK, sotoinpcb, and V_divcbinfo.

Here is the call graph for this function:

◆ div_bind()

static int div_bind ( struct socket *  so,
struct sockaddr *  nam,
struct thread *  td 
)
static

Definition at line 613 of file ip_divert.c.

References in_pcbbind(), INADDR_ANY, INP_HASH_WLOCK, INP_HASH_WUNLOCK, INP_WLOCK, INP_WUNLOCK, sotoinpcb, and V_divcbinfo.

Here is the call graph for this function:

◆ div_destroy()

static void div_destroy ( void *unused  __unused)
static

Definition at line 143 of file ip_divert.c.

References in_pcbinfo_destroy(), and V_divcbinfo.

Referenced by div_modevent().

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

◆ div_detach()

static void div_detach ( struct socket *  so)
static

Definition at line 601 of file ip_divert.c.

References in_pcbdetach(), in_pcbfree(), INP_WLOCK, and sotoinpcb.

Here is the call graph for this function:

◆ div_init()

static void div_init ( void *arg  __unused)
static

Definition at line 130 of file ip_divert.c.

References in_pcbinfo_init(), and V_divcbinfo.

Here is the call graph for this function:

◆ div_input()

static int div_input ( struct mbuf **  mp,
int *  offp,
int  proto 
)
static

Definition at line 155 of file ip_divert.c.

References KMOD_IPSTAT_INC.

◆ div_modevent()

static int div_modevent ( module_t  mod,
int  type,
void *  unused 
)
static

Definition at line 766 of file ip_divert.c.

References div_destroy(), div_protosw, divert_packet(), INP_INFO_WLOCK, INP_INFO_WUNLOCK, ip_divert_ptr, and V_divcbinfo.

Here is the call graph for this function:

◆ div_output()

static int div_output ( struct socket *  so,
struct mbuf *  m,
struct sockaddr_in sin,
struct mbuf *  control 
)
static

◆ div_output_inbound()

static int div_output_inbound ( int  fmaily,
struct socket *  so,
struct mbuf *  m,
struct sockaddr_in sin 
)
static

Definition at line 520 of file ip_divert.c.

References in_broadcast(), ip::ip_dst, in_addr::s_addr, sockaddr_in::sin_port, and sockaddr_in::sin_zero.

Referenced by div_output().

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

◆ div_output_outbound()

static int div_output_outbound ( int  family,
struct socket *  so,
struct mbuf *  m 
)
static

Definition at line 417 of file ip_divert.c.

References inpcb::inp_moptions, inpcb::inp_options, INP_RLOCK, INP_RUNLOCK, IP_ALLOWBROADCAST, ip::ip_hl, ip::ip_len, ip_output(), IP_RAWOUTPUT, IP_ROUTETOIF, KMOD_IPSTAT_INC, and sotoinpcb.

Referenced by div_output().

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

◆ div_pcblist()

static int div_pcblist ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 673 of file ip_divert.c.

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

Here is the call graph for this function:

◆ div_port_match()

static bool div_port_match ( const struct inpcb inp,
void *  v 
)
static

Definition at line 165 of file ip_divert.c.

Referenced by divert_packet().

Here is the caller graph for this function:

◆ div_send()

static int div_send ( struct socket *  so,
int  flags,
struct mbuf *  m,
struct sockaddr *  nam,
struct mbuf *  control,
struct thread *  td 
)
static

Definition at line 654 of file ip_divert.c.

References div_output(), and KMOD_IPSTAT_INC.

Here is the call graph for this function:

◆ div_shutdown()

static int div_shutdown ( struct socket *  so)
static

Definition at line 641 of file ip_divert.c.

References INP_WLOCK, INP_WUNLOCK, and sotoinpcb.

◆ divert_packet()

static void divert_packet ( struct mbuf *  m,
bool  incoming 
)
static

◆ INPCBSTORAGE_DEFINE()

INPCBSTORAGE_DEFINE ( divcbstor  ,
"divinp"  ,
"divcb"  ,
"div"  ,
"divhash"   
)

◆ MODULE_DEPEND()

MODULE_DEPEND ( ipdivert  ,
ipfw  ,
,
,
 
)

◆ MODULE_VERSION()

MODULE_VERSION ( ipdivert  ,
 
)

◆ VNET_DEFINE_STATIC()

VNET_DEFINE_STATIC ( struct inpcbinfo  ,
divcbinfo   
)

◆ VNET_SYSINIT()

VNET_SYSINIT ( div_init  ,
SI_SUB_PROTO_DOMAIN  ,
SI_ORDER_THIRD  ,
div_init  ,
NULL   
)

◆ VNET_SYSUNINIT()

VNET_SYSUNINIT ( divert  ,
SI_SUB_PROTO_DOMAIN  ,
SI_ORDER_THIRD  ,
div_destroy  ,
NULL   
)

Variable Documentation

◆ div_protosw

struct protosw div_protosw
Initial value:
= {
.pr_type = SOCK_RAW,
.pr_protocol = IPPROTO_DIVERT,
.pr_flags = PR_ATOMIC|PR_ADDR,
.pr_input = div_input,
.pr_usrreqs = &div_usrreqs
}
static int div_input(struct mbuf **mp, int *offp, int proto)
Definition: ip_divert.c:155
struct pr_usrreqs div_usrreqs
Definition: ip_divert.c:745

Definition at line 757 of file ip_divert.c.

Referenced by div_modevent().

◆ div_recvspace

u_long div_recvspace = DIVRCVQ
static

Definition at line 118 of file ip_divert.c.

Referenced by div_attach().

◆ div_sendspace

u_long div_sendspace = DIVSNDQ
static

Definition at line 117 of file ip_divert.c.

Referenced by div_attach().

◆ div_usrreqs

struct pr_usrreqs div_usrreqs
Initial value:
= {
.pru_attach = div_attach,
.pru_bind = div_bind,
.pru_control = in_control,
.pru_detach = div_detach,
.pru_peeraddr = in_getpeeraddr,
.pru_send = div_send,
.pru_shutdown = div_shutdown,
.pru_sockaddr = in_getsockaddr,
.pru_sosetlabel = in_pcbsosetlabel
}
int in_control(struct socket *so, u_long cmd, caddr_t data, struct ifnet *ifp, struct thread *td)
Definition: in.c:281
void in_pcbsosetlabel(struct socket *so)
Definition: in_pcb.c:2589
int in_getsockaddr(struct socket *so, struct sockaddr **nam)
int in_getpeeraddr(struct socket *so, struct sockaddr **nam)
static int div_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *nam, struct mbuf *control, struct thread *td)
Definition: ip_divert.c:654
static int div_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
Definition: ip_divert.c:613
static int div_shutdown(struct socket *so)
Definition: ip_divert.c:641
static void div_detach(struct socket *so)
Definition: ip_divert.c:601
static int div_attach(struct socket *so, int proto, struct thread *td)
Definition: ip_divert.c:574

Definition at line 745 of file ip_divert.c.

◆ ipdivertmod

moduledata_t ipdivertmod
static
Initial value:
= {
"ipdivert",
0
}
static int div_modevent(module_t mod, int type, void *unused)
Definition: ip_divert.c:766

Definition at line 822 of file ip_divert.c.