FreeBSD kernel netgraph code
ng_socket.c File Reference
#include <sys/param.h>
#include <sys/domain.h>
#include <sys/hash.h>
#include <sys/kernel.h>
#include <sys/linker.h>
#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/mbuf.h>
#include <sys/mutex.h>
#include <sys/proc.h>
#include <sys/epoch.h>
#include <sys/priv.h>
#include <sys/protosw.h>
#include <sys/queue.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
#include <sys/syscallsubr.h>
#include <sys/sysctl.h>
#include <net/vnet.h>
#include <netgraph/ng_message.h>
#include <netgraph/netgraph.h>
#include <netgraph/ng_socketvar.h>
#include <netgraph/ng_socket.h>
Include dependency graph for ng_socket.c:

Go to the source code of this file.

Data Structures

struct  ngsock
 

Macros

#define M_NETGRAPH_PATH   M_NETGRAPH
 
#define M_NETGRAPH_SOCK   M_NETGRAPH
 
#define sotongpcb(so)   ((struct ngpcb *)(so)->so_pcb)
 
#define TRAP_ERROR
 
#define NGS_FLAG_NOLINGER   1 /* close with last hook */
 

Functions

static int ng_attach_data (struct socket *so)
 
static int ng_attach_cntl (struct socket *so)
 
static int ng_attach_common (struct socket *so, int type)
 
static void ng_detach_common (struct ngpcb *pcbp, int type)
 
static void ng_socket_free_priv (struct ngsock *priv)
 
static int ng_connect_data (struct sockaddr *nam, struct ngpcb *pcbp)
 
static int ng_bind (struct sockaddr *nam, struct ngpcb *pcbp)
 
static int ngs_mod_event (module_t mod, int event, void *data)
 
static void ng_socket_item_applied (void *context, int error)
 
 NETGRAPH_INIT_ORDERED (socket, &typestruct, SI_SUB_PROTO_DOMAIN, SI_ORDER_ANY)
 
 SYSCTL_ULONG (_net_graph, OID_AUTO, maxdgram, CTLFLAG_RW, &ngpdg_sendspace, 0, "Maximum outgoing Netgraph datagram size")
 
 SYSCTL_ULONG (_net_graph, OID_AUTO, recvspace, CTLFLAG_RW, &ngpdg_recvspace, 0, "Maximum space for incoming Netgraph datagrams")
 
static LIST_HEAD (ngpcb)
 
 LIST_HEAD (ngshash, hookpriv)
 
static int ngc_attach (struct socket *so, int proto, struct thread *td)
 
static void ngc_detach (struct socket *so)
 
static int ngc_send (struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr, struct mbuf *control, struct thread *td)
 
static int ngc_bind (struct socket *so, struct sockaddr *nam, struct thread *td)
 
static int ngc_connect (struct socket *so, struct sockaddr *nam, struct thread *td)
 
static int ngd_attach (struct socket *so, int proto, struct thread *td)
 
static void ngd_detach (struct socket *so)
 
static int ngd_send (struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr, struct mbuf *control, struct thread *td)
 
static int ngd_connect (struct socket *so, struct sockaddr *nam, struct thread *td)
 
static int ng_getsockaddr (struct socket *so, struct sockaddr **addr)
 
static int ngs_constructor (node_p nodep)
 
static void ngs_rehash (node_p node)
 
static int ngs_newhook (node_p node, hook_p hook, const char *name)
 
static int ngs_connect (hook_p hook)
 
static hook_p ngs_findhook (node_p node, const char *name)
 
static int ngs_rcvmsg (node_p node, item_p item, hook_p lasthook)
 
static int ngs_rcvdata (hook_p hook, item_p item)
 
static int ngs_disconnect (hook_p hook)
 
static int ngs_shutdown (node_p node)
 
static int dummy_disconnect (struct socket *so)
 
 DOMAIN_SET (ng)
 
 SYSCTL_INT (_net_graph, OID_AUTO, family, CTLFLAG_RD, SYSCTL_NULL_INT_PTR, AF_NETGRAPH, "")
 
static SYSCTL_NODE (_net_graph, OID_AUTO, data, CTLFLAG_RW|CTLFLAG_MPSAFE, 0, "DATA")
 
 SYSCTL_INT (_net_graph_data, OID_AUTO, proto, CTLFLAG_RD, SYSCTL_NULL_INT_PTR, NG_DATA, "")
 
static SYSCTL_NODE (_net_graph, OID_AUTO, control, CTLFLAG_RW|CTLFLAG_MPSAFE, 0, "CONTROL")
 
 SYSCTL_INT (_net_graph_control, OID_AUTO, proto, CTLFLAG_RD, SYSCTL_NULL_INT_PTR, NG_CONTROL, "")
 

Variables

static ng_constructor_t ngs_constructor
 
static ng_rcvmsg_t ngs_rcvmsg
 
static ng_shutdown_t ngs_shutdown
 
static ng_newhook_t ngs_newhook
 
static ng_connect_t ngs_connect
 
static ng_findhook_t ngs_findhook
 
static ng_rcvdata_t ngs_rcvdata
 
static ng_disconnect_t ngs_disconnect
 
static struct ng_type typestruct
 
static u_long ngpdg_sendspace = 20 * 1024
 
static u_long ngpdg_recvspace = 20 * 1024
 
static struct pr_usrreqs ngc_usrreqs
 
static struct pr_usrreqs ngd_usrreqs
 
struct domain ngdomain
 
static struct protosw ngsw []
 

Macro Definition Documentation

◆ M_NETGRAPH_PATH

#define M_NETGRAPH_PATH   M_NETGRAPH

Definition at line 82 of file ng_socket.c.

◆ M_NETGRAPH_SOCK

#define M_NETGRAPH_SOCK   M_NETGRAPH

Definition at line 83 of file ng_socket.c.

◆ NGS_FLAG_NOLINGER

#define NGS_FLAG_NOLINGER   1 /* close with last hook */

Definition at line 189 of file ng_socket.c.

◆ sotongpcb

#define sotongpcb (   so)    ((struct ngpcb *)(so)->so_pcb)

◆ TRAP_ERROR

#define TRAP_ERROR

Function Documentation

◆ DOMAIN_SET()

DOMAIN_SET ( ng  )

◆ dummy_disconnect()

static int dummy_disconnect ( struct socket *  so)
static

Definition at line 1127 of file ng_socket.c.

◆ LIST_HEAD() [1/2]

static LIST_HEAD ( ngpcb  )
static

Definition at line 159 of file ng_socket.c.

◆ LIST_HEAD() [2/2]

LIST_HEAD ( ngshash  ,
hookpriv   
)

◆ NETGRAPH_INIT_ORDERED()

NETGRAPH_INIT_ORDERED ( socket  ,
typestruct,
SI_SUB_PROTO_DOMAIN  ,
SI_ORDER_ANY   
)

◆ ng_attach_cntl()

static int ng_attach_cntl ( struct socket *  so)
static

Definition at line 549 of file ng_socket.c.

References M_NETGRAPH_SOCK, ng_node::nd_ID, ng_attach_common(), NG_CONTROL, ng_detach_common(), ng_make_node_common(), NG_NODE_REF, NG_NODE_SET_PRIVATE, ngpcb::node_id, ngpcb::sockdata, sotongpcb, and typestruct.

Referenced by ngc_attach().

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

◆ ng_attach_common()

static int ng_attach_common ( struct socket *  so,
int  type 
)
static

Definition at line 605 of file ng_socket.c.

References ngpcb::ng_socket, ngpdg_recvspace, ngpdg_sendspace, type, and ngpcb::type.

Referenced by ng_attach_cntl(), and ng_attach_data().

Here is the caller graph for this function:

◆ ng_attach_data()

static int ng_attach_data ( struct socket *  so)
static

Definition at line 595 of file ng_socket.c.

References ng_attach_common(), and NG_DATA.

Referenced by ngd_attach().

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

◆ ng_bind()

static int ng_bind ( struct sockaddr *  nam,
struct ngpcb pcbp 
)
static

Definition at line 758 of file ng_socket.c.

References ng_name_node(), NG_NODESIZ, sockaddr_ng::sg_data, sockaddr_ng::sg_len, ngpcb::sockdata, and TRAP_ERROR.

Referenced by ngc_bind().

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

◆ ng_connect_data()

static int ng_connect_data ( struct sockaddr *  nam,
struct ngpcb pcbp 
)
static

Definition at line 699 of file ng_socket.c.

References ng_item::el_dest, ngsock::error, ng_type::name, ng_node::nd_type, ng_address_path(), NG_FREE_ITEM, NG_NODE_PRIVATE, ng_package_data(), NG_SOCKET_NODE_TYPE, NG_WAITOK, ngpcb::node_id, sockaddr_ng::sg_data, and ngpcb::sockdata.

Referenced by ngd_connect().

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

◆ ng_detach_common()

static void ng_detach_common ( struct ngpcb pcbp,
int  type 
)
static

Definition at line 637 of file ng_socket.c.

References NG_CONTROL, NG_DATA, ngpcb::ng_socket, ng_socket_free_priv(), ngpcb::node_id, and ngpcb::sockdata.

Referenced by ng_attach_cntl(), ngc_detach(), and ngd_detach().

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

◆ ng_getsockaddr()

static int ng_getsockaddr ( struct socket *  so,
struct sockaddr **  addr 
)
static

◆ ng_socket_free_priv()

static void ng_socket_free_priv ( struct ngsock priv)
static

Definition at line 671 of file ng_socket.c.

References M_NETGRAPH_SOCK, NG_NODE_UNREF, ng_rmnode_self(), and ngsock::node.

Referenced by ng_detach_common(), and ngs_shutdown().

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

◆ ng_socket_item_applied()

static void ng_socket_item_applied ( void *  context,
int  error 
)
static

Definition at line 1115 of file ng_socket.c.

References ngsock::error.

Referenced by ngc_send().

Here is the caller graph for this function:

◆ ngc_attach()

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

Definition at line 196 of file ng_socket.c.

References ng_attach_cntl(), and sotongpcb.

Here is the call graph for this function:

◆ ngc_bind()

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

Definition at line 366 of file ng_socket.c.

References ng_bind(), and sotongpcb.

Here is the call graph for this function:

◆ ngc_connect()

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

Definition at line 376 of file ng_socket.c.

◆ ngc_detach()

static void ngc_detach ( struct socket *  so)
static

Definition at line 210 of file ng_socket.c.

References NG_CONTROL, ng_detach_common(), and sotongpcb.

Here is the call graph for this function:

◆ ngc_send()

◆ ngd_attach()

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

Definition at line 391 of file ng_socket.c.

References ng_attach_data(), and sotongpcb.

Here is the call graph for this function:

◆ ngd_connect()

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

Definition at line 492 of file ng_socket.c.

References ng_connect_data(), and sotongpcb.

Here is the call graph for this function:

◆ ngd_detach()

static void ngd_detach ( struct socket *  so)
static

Definition at line 401 of file ng_socket.c.

References NG_DATA, ng_detach_common(), and sotongpcb.

Here is the call graph for this function:

◆ ngd_send()

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

◆ ngs_connect()

static int ngs_connect ( hook_p  hook)
static

Definition at line 846 of file ng_socket.c.

References NG_HOOK_NODE, NG_NODE_NUMHOOKS, NG_NODE_PRIVATE, and ngsock::node.

◆ ngs_constructor()

static int ngs_constructor ( node_p  nodep)
static

Definition at line 784 of file ng_socket.c.

◆ ngs_disconnect()

static int ngs_disconnect ( hook_p  hook)
static

Definition at line 1062 of file ng_socket.c.

References M_NETGRAPH_SOCK, NG_HOOK_NODE, NG_HOOK_PRIVATE, NG_NODE_IS_VALID, NG_NODE_NUMHOOKS, NG_NODE_PRIVATE, ng_rmnode_self(), NGS_FLAG_NOLINGER, and ngsock::node.

Here is the call graph for this function:

◆ ngs_findhook()

static hook_p ngs_findhook ( node_p  node,
const char *  name 
)
static

Definition at line 862 of file ng_socket.c.

References name, ng_node::nd_numhooks, NG_HOOK_NAME, NG_NODE_PRIVATE, and ngsock::node.

◆ ngs_mod_event()

static int ngs_mod_event ( module_t  mod,
int  event,
void *  data 
)
static

Definition at line 1200 of file ng_socket.c.

References event.

◆ ngs_newhook()

static int ngs_newhook ( node_p  node,
hook_p  hook,
const char *  name 
)
static

Definition at line 823 of file ng_socket.c.

References M_NETGRAPH_SOCK, name, ng_node::nd_numhooks, NG_HOOK_SET_PRIVATE, NG_NODE_PRIVATE, ngs_rehash(), and ngsock::node.

Here is the call graph for this function:

◆ ngs_rcvdata()

◆ ngs_rcvmsg()

◆ ngs_rehash()

static void ngs_rehash ( node_p  node)
static

Definition at line 790 of file ng_socket.c.

References M_NETGRAPH_SOCK, NG_HOOK_NAME, NG_HOOK_PRIVATE, NG_NODE_PRIVATE, and ngsock::node.

Referenced by ngs_newhook().

Here is the caller graph for this function:

◆ ngs_shutdown()

static int ngs_shutdown ( node_p  node)
static

Definition at line 1091 of file ng_socket.c.

References NG_NODE_PRIVATE, NG_NODE_SET_PRIVATE, NG_NODE_UNREF, ngpcb::ng_socket, ng_socket_free_priv(), and ngsock::node.

Here is the call graph for this function:

◆ SYSCTL_INT() [1/3]

SYSCTL_INT ( _net_graph  ,
OID_AUTO  ,
family  ,
CTLFLAG_RD  ,
SYSCTL_NULL_INT_PTR  ,
AF_NETGRAPH  ,
""   
)

◆ SYSCTL_INT() [2/3]

SYSCTL_INT ( _net_graph_control  ,
OID_AUTO  ,
proto  ,
CTLFLAG_RD  ,
SYSCTL_NULL_INT_PTR  ,
NG_CONTROL  ,
""   
)

◆ SYSCTL_INT() [3/3]

SYSCTL_INT ( _net_graph_data  ,
OID_AUTO  ,
proto  ,
CTLFLAG_RD  ,
SYSCTL_NULL_INT_PTR  ,
NG_DATA  ,
""   
)

◆ SYSCTL_NODE() [1/2]

static SYSCTL_NODE ( _net_graph  ,
OID_AUTO  ,
control  ,
CTLFLAG_RW|  CTLFLAG_MPSAFE,
,
"CONTROL"   
)
static

◆ SYSCTL_NODE() [2/2]

static SYSCTL_NODE ( _net_graph  ,
OID_AUTO  ,
data  ,
CTLFLAG_RW|  CTLFLAG_MPSAFE,
,
"DATA"   
)
static

◆ SYSCTL_ULONG() [1/2]

SYSCTL_ULONG ( _net_graph  ,
OID_AUTO  ,
maxdgram  ,
CTLFLAG_RW  ,
ngpdg_sendspace,
,
"Maximum outgoing Netgraph datagram size"   
)

◆ SYSCTL_ULONG() [2/2]

SYSCTL_ULONG ( _net_graph  ,
OID_AUTO  ,
recvspace  ,
CTLFLAG_RW  ,
ngpdg_recvspace,
,
"Maximum space for incoming Netgraph datagrams"   
)

Variable Documentation

◆ ngc_usrreqs

struct pr_usrreqs ngc_usrreqs
static
Initial value:
= {
.pru_abort = NULL,
.pru_attach = ngc_attach,
.pru_bind = ngc_bind,
.pru_connect = ngc_connect,
.pru_detach = ngc_detach,
.pru_disconnect = dummy_disconnect,
.pru_peeraddr = NULL,
.pru_send = ngc_send,
.pru_shutdown = NULL,
.pru_sockaddr = ng_getsockaddr,
.pru_close = NULL,
}
static int ngc_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
Definition: ng_socket.c:366
static int dummy_disconnect(struct socket *so)
Definition: ng_socket.c:1127
static int ngc_attach(struct socket *so, int proto, struct thread *td)
Definition: ng_socket.c:196
static int ngc_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
Definition: ng_socket.c:376
static int ngc_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr, struct mbuf *control, struct thread *td)
Definition: ng_socket.c:219
static int ng_getsockaddr(struct socket *so, struct sockaddr **addr)
Definition: ng_socket.c:505
static void ngc_detach(struct socket *so)
Definition: ng_socket.c:210

Definition at line 1137 of file ng_socket.c.

◆ ngd_usrreqs

struct pr_usrreqs ngd_usrreqs
static
Initial value:
= {
.pru_abort = NULL,
.pru_attach = ngd_attach,
.pru_bind = NULL,
.pru_connect = ngd_connect,
.pru_detach = ngd_detach,
.pru_disconnect = dummy_disconnect,
.pru_peeraddr = NULL,
.pru_send = ngd_send,
.pru_shutdown = NULL,
.pru_sockaddr = ng_getsockaddr,
.pru_close = NULL,
}
static int ngd_attach(struct socket *so, int proto, struct thread *td)
Definition: ng_socket.c:391
static void ngd_detach(struct socket *so)
Definition: ng_socket.c:401
static int ngd_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr, struct mbuf *control, struct thread *td)
Definition: ng_socket.c:410
static int ngd_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
Definition: ng_socket.c:492

Definition at line 1151 of file ng_socket.c.

◆ ngdomain

struct domain ngdomain
Initial value:
= {
.dom_family = AF_NETGRAPH,
.dom_name = "netgraph",
.dom_protosw = ngsw,
.dom_protoswNPROTOSW = &ngsw[nitems(ngsw)]
}
static struct protosw ngsw[]
Definition: ng_socket.c:1171

Definition at line 1188 of file ng_socket.c.

◆ ngpdg_recvspace

u_long ngpdg_recvspace = 20 * 1024
static

Definition at line 154 of file ng_socket.c.

Referenced by ng_attach_common().

◆ ngpdg_sendspace

u_long ngpdg_sendspace = 20 * 1024
static

Definition at line 151 of file ng_socket.c.

Referenced by ng_attach_common().

◆ ngs_connect

ng_connect_t ngs_connect
static

Definition at line 117 of file ng_socket.c.

◆ ngs_constructor

ng_constructor_t ngs_constructor
static

Definition at line 113 of file ng_socket.c.

◆ ngs_disconnect

ng_disconnect_t ngs_disconnect
static

Definition at line 120 of file ng_socket.c.

◆ ngs_findhook

ng_findhook_t ngs_findhook
static

Definition at line 118 of file ng_socket.c.

◆ ngs_newhook

ng_newhook_t ngs_newhook
static

Definition at line 116 of file ng_socket.c.

◆ ngs_rcvdata

ng_rcvdata_t ngs_rcvdata
static

Definition at line 119 of file ng_socket.c.

◆ ngs_rcvmsg

ng_rcvmsg_t ngs_rcvmsg
static

Definition at line 114 of file ng_socket.c.

◆ ngs_shutdown

ng_shutdown_t ngs_shutdown
static

Definition at line 115 of file ng_socket.c.

◆ ngsw

struct protosw ngsw[]
static
Initial value:
= {
{
.pr_type = SOCK_DGRAM,
.pr_domain = &ngdomain,
.pr_protocol = NG_CONTROL,
.pr_flags = PR_ATOMIC | PR_ADDR ,
.pr_usrreqs = &ngc_usrreqs
},
{
.pr_type = SOCK_DGRAM,
.pr_domain = &ngdomain,
.pr_protocol = NG_DATA,
.pr_flags = PR_ATOMIC | PR_ADDR,
.pr_usrreqs = &ngd_usrreqs
}
}
struct domain ngdomain
Definition: ng_socket.c:1188
static struct pr_usrreqs ngd_usrreqs
Definition: ng_socket.c:1151
static struct pr_usrreqs ngc_usrreqs
Definition: ng_socket.c:1137
#define NG_DATA
Definition: ng_socket.h:52
#define NG_CONTROL
Definition: ng_socket.h:53

Definition at line 1171 of file ng_socket.c.

◆ typestruct

struct ng_type typestruct
static
Initial value:
= {
.version = NG_ABI_VERSION,
.mod_event = ngs_mod_event,
.constructor = ngs_constructor,
.rcvmsg = ngs_rcvmsg,
.shutdown = ngs_shutdown,
.newhook = ngs_newhook,
.connect = ngs_connect,
.findhook = ngs_findhook,
.rcvdata = ngs_rcvdata,
.disconnect = ngs_disconnect,
}
#define NG_ABI_VERSION
Definition: netgraph.h:77
static ng_connect_t ngs_connect
Definition: ng_socket.c:117
static ng_newhook_t ngs_newhook
Definition: ng_socket.c:116
static ng_rcvdata_t ngs_rcvdata
Definition: ng_socket.c:119
static ng_shutdown_t ngs_shutdown
Definition: ng_socket.c:115
static ng_constructor_t ngs_constructor
Definition: ng_socket.c:113
static ng_findhook_t ngs_findhook
Definition: ng_socket.c:118
static ng_disconnect_t ngs_disconnect
Definition: ng_socket.c:120
static int ngs_mod_event(module_t mod, int event, void *data)
Definition: ng_socket.c:1200
static ng_rcvmsg_t ngs_rcvmsg
Definition: ng_socket.c:114
#define NG_SOCKET_NODE_TYPE
Definition: ng_socket.h:48

Definition at line 135 of file ng_socket.c.

Referenced by ng_attach_cntl().