FreeBSD kernel netgraph code
ng_iface.c File Reference
#include "opt_inet.h"
#include "opt_inet6.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/errno.h>
#include <sys/kernel.h>
#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/mbuf.h>
#include <sys/proc.h>
#include <sys/random.h>
#include <sys/rmlock.h>
#include <sys/sockio.h>
#include <sys/socket.h>
#include <sys/sysctl.h>
#include <sys/syslog.h>
#include <sys/libkern.h>
#include <net/if.h>
#include <net/if_var.h>
#include <net/if_types.h>
#include <net/bpf.h>
#include <net/netisr.h>
#include <net/route.h>
#include <net/vnet.h>
#include <netinet/in.h>
#include <netgraph/ng_message.h>
#include <netgraph/netgraph.h>
#include <netgraph/ng_parse.h>
#include <netgraph/ng_iface.h>
Include dependency graph for ng_iface.c:

Go to the source code of this file.

Data Structures

struct  iffam
 
struct  ng_iface_private
 

Macros

#define M_NETGRAPH_IFACE   M_NETGRAPH
 
#define V_ng_iface_max_nest   VNET(ng_iface_max_nest)
 
#define NUM_FAMILIES   nitems(gFamilies)
 
#define PRIV_RLOCK(priv, t)   rm_rlock(&priv->lock, t)
 
#define PRIV_RUNLOCK(priv, t)   rm_runlock(&priv->lock, t)
 
#define PRIV_WLOCK(priv)   rm_wlock(&priv->lock)
 
#define PRIV_WUNLOCK(priv)   rm_wunlock(&priv->lock)
 
#define V_ng_iface_unit   VNET(ng_iface_unit)
 

Typedefs

typedef const struct iffamiffam_p
 
typedef struct ng_iface_privatepriv_p
 

Functions

static SYSCTL_NODE (_net_graph, OID_AUTO, iface, CTLFLAG_RW|CTLFLAG_MPSAFE, 0, "Point to point netgraph interface")
 
 VNET_DEFINE_STATIC (int, ng_iface_max_nest)
 
 SYSCTL_INT (_net_graph_iface, OID_AUTO, max_nesting, CTLFLAG_VNET|CTLFLAG_RW, &VNET_NAME(ng_iface_max_nest), 0, "Max nested tunnels")
 
static void ng_iface_start (struct ifnet *ifp)
 
static int ng_iface_ioctl (struct ifnet *ifp, u_long cmd, caddr_t data)
 
static int ng_iface_output (struct ifnet *ifp, struct mbuf *m0, const struct sockaddr *dst, struct route *ro)
 
static void ng_iface_bpftap (struct ifnet *ifp, struct mbuf *m, sa_family_t family)
 
static int ng_iface_send (struct ifnet *ifp, struct mbuf *m, sa_family_t sa)
 
static int ng_iface_mod_event (module_t, int, void *)
 
static iffam_p get_iffam_from_af (sa_family_t family)
 
static iffam_p get_iffam_from_hook (priv_p priv, hook_p hook)
 
static iffam_p get_iffam_from_name (const char *name)
 
static hook_pget_hook_from_iffam (priv_p priv, iffam_p iffam)
 
 NETGRAPH_INIT (iface, &typestruct)
 
 VNET_DEFINE_STATIC (struct unrhdr *, ng_iface_unit)
 
static int ng_iface_constructor (node_p node)
 
static int ng_iface_newhook (node_p node, hook_p hook, const char *name)
 
static int ng_iface_rcvmsg (node_p node, item_p item, hook_p lasthook)
 
static int ng_iface_rcvdata (hook_p hook, item_p item)
 
static int ng_iface_shutdown (node_p node)
 
static int ng_iface_disconnect (hook_p hook)
 
static void vnet_ng_iface_init (const void *unused)
 
 VNET_SYSINIT (vnet_ng_iface_init, SI_SUB_PSEUDO, SI_ORDER_ANY, vnet_ng_iface_init, NULL)
 
static void vnet_ng_iface_uninit (const void *unused)
 
 VNET_SYSUNINIT (vnet_ng_iface_uninit, SI_SUB_INIT_IF, SI_ORDER_ANY, vnet_ng_iface_uninit, NULL)
 

Variables

static const struct iffam gFamilies []
 
static ng_constructor_t ng_iface_constructor
 
static ng_rcvmsg_t ng_iface_rcvmsg
 
static ng_shutdown_t ng_iface_shutdown
 
static ng_newhook_t ng_iface_newhook
 
static ng_rcvdata_t ng_iface_rcvdata
 
static ng_disconnect_t ng_iface_disconnect
 
static const struct ng_cmdlist ng_iface_cmds []
 
static struct ng_type typestruct
 

Macro Definition Documentation

◆ M_NETGRAPH_IFACE

#define M_NETGRAPH_IFACE   M_NETGRAPH

Definition at line 93 of file ng_iface.c.

◆ NUM_FAMILIES

#define NUM_FAMILIES   nitems(gFamilies)

Definition at line 115 of file ng_iface.c.

◆ PRIV_RLOCK

#define PRIV_RLOCK (   priv,
 
)    rm_rlock(&priv->lock, t)

Definition at line 127 of file ng_iface.c.

◆ PRIV_RUNLOCK

#define PRIV_RUNLOCK (   priv,
 
)    rm_runlock(&priv->lock, t)

Definition at line 128 of file ng_iface.c.

◆ PRIV_WLOCK

#define PRIV_WLOCK (   priv)    rm_wlock(&priv->lock)

Definition at line 129 of file ng_iface.c.

◆ PRIV_WUNLOCK

#define PRIV_WUNLOCK (   priv)    rm_wunlock(&priv->lock)

Definition at line 130 of file ng_iface.c.

◆ V_ng_iface_max_nest

#define V_ng_iface_max_nest   VNET(ng_iface_max_nest)

Definition at line 99 of file ng_iface.c.

◆ V_ng_iface_unit

#define V_ng_iface_unit   VNET(ng_iface_unit)

Definition at line 209 of file ng_iface.c.

Typedef Documentation

◆ iffam_p

typedef const struct iffam* iffam_p

Definition at line 108 of file ng_iface.c.

◆ priv_p

typedef struct ng_iface_private* priv_p

Definition at line 125 of file ng_iface.c.

Function Documentation

◆ get_hook_from_iffam()

static __inline hook_p * get_hook_from_iffam ( priv_p  priv,
iffam_p  iffam 
)
static

Definition at line 251 of file ng_iface.c.

References gFamilies.

Referenced by ng_iface_disconnect(), ng_iface_newhook(), and ng_iface_send().

Here is the caller graph for this function:

◆ get_iffam_from_af()

static __inline iffam_p get_iffam_from_af ( sa_family_t  family)
static

Definition at line 219 of file ng_iface.c.

References iffam::family, gFamilies, and NUM_FAMILIES.

Referenced by ng_iface_send().

Here is the caller graph for this function:

◆ get_iffam_from_hook()

static __inline iffam_p get_iffam_from_hook ( priv_p  priv,
hook_p  hook 
)
static

Definition at line 236 of file ng_iface.c.

References gFamilies, and NUM_FAMILIES.

Referenced by ng_iface_disconnect(), and ng_iface_rcvdata().

Here is the caller graph for this function:

◆ get_iffam_from_name()

static __inline iffam_p get_iffam_from_name ( const char *  name)
static

Definition at line 260 of file ng_iface.c.

References gFamilies, iffam::hookname, name, and NUM_FAMILIES.

Referenced by ng_iface_newhook().

Here is the caller graph for this function:

◆ NETGRAPH_INIT()

NETGRAPH_INIT ( iface  ,
typestruct 
)

◆ ng_iface_bpftap()

static void ng_iface_bpftap ( struct ifnet *  ifp,
struct mbuf *  m,
sa_family_t  family 
)
static

Definition at line 419 of file ng_iface.c.

Referenced by ng_iface_output(), and ng_iface_rcvdata().

Here is the caller graph for this function:

◆ ng_iface_constructor()

static int ng_iface_constructor ( node_p  node)
static

◆ ng_iface_disconnect()

static int ng_iface_disconnect ( hook_p  hook)
static

Definition at line 770 of file ng_iface.c.

References get_hook_from_iffam(), get_iffam_from_hook(), NG_HOOK_NODE, NG_NODE_PRIVATE, PRIV_WLOCK, and PRIV_WUNLOCK.

Here is the call graph for this function:

◆ ng_iface_ioctl()

static int ng_iface_ioctl ( struct ifnet *  ifp,
u_long  cmd,
caddr_t  data 
)
static

Definition at line 281 of file ng_iface.c.

References data, NG_IFACE_MTU_MAX, and NG_IFACE_MTU_MIN.

Referenced by ng_iface_constructor().

Here is the caller graph for this function:

◆ ng_iface_mod_event()

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

Definition at line 787 of file ng_iface.c.

References event.

◆ ng_iface_newhook()

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

Definition at line 578 of file ng_iface.c.

References get_hook_from_iffam(), get_iffam_from_name(), name, NG_HOOK_HI_STACK, NG_HOOK_SET_TO_INBOUND, NG_NODE_PRIVATE, PRIV_WLOCK, and PRIV_WUNLOCK.

Here is the call graph for this function:

◆ ng_iface_output()

static int ng_iface_output ( struct ifnet *  ifp,
struct mbuf *  m0,
const struct sockaddr *  dst,
struct route *  ro 
)
static

Definition at line 349 of file ng_iface.c.

References ng_iface_bpftap(), ng_iface_send(), NGM_IFACE_COOKIE, and V_ng_iface_max_nest.

Referenced by ng_iface_constructor().

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

◆ ng_iface_rcvdata()

static int ng_iface_rcvdata ( hook_p  hook,
item_p  item 
)
static

Definition at line 684 of file ng_iface.c.

References iffam::family, get_iffam_from_hook(), NG_FREE_ITEM, NG_FREE_M, NG_HOOK_NODE, ng_iface_bpftap(), NG_NODE_PRIVATE, and NGI_GET_M.

Here is the call graph for this function:

◆ ng_iface_rcvmsg()

◆ ng_iface_send()

static int ng_iface_send ( struct ifnet *  ifp,
struct mbuf *  m,
sa_family_t  sa 
)
static

Definition at line 434 of file ng_iface.c.

References get_hook_from_iffam(), get_iffam_from_af(), NG_FREE_M, NG_HOOK_REF, NG_HOOK_UNREF, NG_OUTBOUND_THREAD_REF, NG_OUTBOUND_THREAD_UNREF, NG_SEND_DATA_ONLY, PRIV_RLOCK, and PRIV_RUNLOCK.

Referenced by ng_iface_output(), and ng_iface_start().

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

◆ ng_iface_shutdown()

static int ng_iface_shutdown ( node_p  node)
static

◆ ng_iface_start()

static void ng_iface_start ( struct ifnet *  ifp)
static

Definition at line 397 of file ng_iface.c.

References ng_iface_send().

Referenced by ng_iface_constructor().

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

◆ SYSCTL_INT()

SYSCTL_INT ( _net_graph_iface  ,
OID_AUTO  ,
max_nesting  ,
CTLFLAG_VNET|  CTLFLAG_RW,
VNET_NAMEng_iface_max_nest,
,
"Max nested tunnels"   
)

◆ SYSCTL_NODE()

static SYSCTL_NODE ( _net_graph  ,
OID_AUTO  ,
iface  ,
CTLFLAG_RW|  CTLFLAG_MPSAFE,
,
"Point to point netgraph interface"   
)
static

◆ VNET_DEFINE_STATIC() [1/2]

VNET_DEFINE_STATIC ( int  ,
ng_iface_max_nest   
)

◆ VNET_DEFINE_STATIC() [2/2]

VNET_DEFINE_STATIC ( struct unrhdr *  ,
ng_iface_unit   
)

◆ vnet_ng_iface_init()

static void vnet_ng_iface_init ( const void *  unused)
static

Definition at line 803 of file ng_iface.c.

References V_ng_iface_unit.

◆ vnet_ng_iface_uninit()

static void vnet_ng_iface_uninit ( const void *  unused)
static

Definition at line 812 of file ng_iface.c.

References V_ng_iface_unit.

◆ VNET_SYSINIT()

VNET_SYSINIT ( vnet_ng_iface_init  ,
SI_SUB_PSEUDO  ,
SI_ORDER_ANY  ,
vnet_ng_iface_init  ,
NULL   
)

◆ VNET_SYSUNINIT()

VNET_SYSUNINIT ( vnet_ng_iface_uninit  ,
SI_SUB_INIT_IF  ,
SI_ORDER_ANY  ,
vnet_ng_iface_uninit  ,
NULL   
)

Variable Documentation

◆ gFamilies

const struct iffam gFamilies[]
static
Initial value:
= {
{ AF_INET, NG_IFACE_HOOK_INET },
{ AF_INET6, NG_IFACE_HOOK_INET6 },
}
#define NG_IFACE_HOOK_INET6
Definition: ng_iface.h:56
#define NG_IFACE_HOOK_INET
Definition: ng_iface.h:55

Definition at line 111 of file ng_iface.c.

Referenced by get_hook_from_iffam(), get_iffam_from_af(), get_iffam_from_hook(), and get_iffam_from_name().

◆ ng_iface_cmds

const struct ng_cmdlist ng_iface_cmds[]
static

Definition at line 161 of file ng_iface.c.

◆ ng_iface_constructor

ng_constructor_t ng_iface_constructor
static

Definition at line 147 of file ng_iface.c.

◆ ng_iface_disconnect

ng_disconnect_t ng_iface_disconnect
static

Definition at line 152 of file ng_iface.c.

◆ ng_iface_newhook

ng_newhook_t ng_iface_newhook
static

Definition at line 150 of file ng_iface.c.

◆ ng_iface_rcvdata

ng_rcvdata_t ng_iface_rcvdata
static

Definition at line 151 of file ng_iface.c.

◆ ng_iface_rcvmsg

ng_rcvmsg_t ng_iface_rcvmsg
static

Definition at line 148 of file ng_iface.c.

◆ ng_iface_shutdown

ng_shutdown_t ng_iface_shutdown
static

Definition at line 149 of file ng_iface.c.

◆ typestruct

struct ng_type typestruct
static
Initial value:
= {
.version = NG_ABI_VERSION,
.mod_event = ng_iface_mod_event,
.constructor = ng_iface_constructor,
.rcvmsg = ng_iface_rcvmsg,
.shutdown = ng_iface_shutdown,
.newhook = ng_iface_newhook,
.rcvdata = ng_iface_rcvdata,
.disconnect = ng_iface_disconnect,
.cmdlist = ng_iface_cmds,
}
#define NG_ABI_VERSION
Definition: netgraph.h:77
static const struct ng_cmdlist ng_iface_cmds[]
Definition: ng_iface.c:161
static ng_shutdown_t ng_iface_shutdown
Definition: ng_iface.c:149
static int ng_iface_mod_event(module_t, int, void *)
Definition: ng_iface.c:787
static ng_rcvmsg_t ng_iface_rcvmsg
Definition: ng_iface.c:148
static ng_disconnect_t ng_iface_disconnect
Definition: ng_iface.c:152
static ng_newhook_t ng_iface_newhook
Definition: ng_iface.c:150
static ng_constructor_t ng_iface_constructor
Definition: ng_iface.c:147
static ng_rcvdata_t ng_iface_rcvdata
Definition: ng_iface.c:151
#define NG_IFACE_NODE_TYPE
Definition: ng_iface.h:48

Definition at line 194 of file ng_iface.c.