FreeBSD kernel netgraph code
ng_l2tp.c File Reference
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/time.h>
#include <sys/conf.h>
#include <sys/mbuf.h>
#include <sys/malloc.h>
#include <sys/errno.h>
#include <sys/epoch.h>
#include <sys/libkern.h>
#include <net/vnet.h>
#include <netgraph/ng_message.h>
#include <netgraph/netgraph.h>
#include <netgraph/ng_parse.h>
#include <netgraph/ng_l2tp.h>
Include dependency graph for ng_l2tp.c:

Go to the source code of this file.

Data Structures

struct  ng_l2tp_hook_private
 
struct  l2tp_seq
 
struct  ng_l2tp_private
 

Macros

#define M_NETGRAPH_L2TP   M_NETGRAPH
 
#define L2TP_HDR_CTRL   0x8000 /* control packet */
 
#define L2TP_HDR_LEN   0x4000 /* has length field */
 
#define L2TP_HDR_SEQ   0x0800 /* has ns, nr fields */
 
#define L2TP_HDR_OFF   0x0200 /* has offset field */
 
#define L2TP_HDR_PRIO   0x0100 /* give priority */
 
#define L2TP_HDR_VERS_MASK   0x000f /* version field mask */
 
#define L2TP_HDR_VERSION   0x0002 /* version field */
 
#define L2TP_CTRL_0BITS   0x030d /* ctrl: must be 0 */
 
#define L2TP_CTRL_1BITS   0xc802 /* ctrl: must be 1 */
 
#define L2TP_DATA_0BITS   0x800d /* data: must be 0 */
 
#define L2TP_DATA_1BITS   0x0002 /* data: must be 1 */
 
#define L2TP_CTRL_HDR
 
#define L2TP_DATA_HDR   (L2TP_HDR_VERSION) /* optional: len, seq */
 
#define L2TP_MAX_XWIN   128 /* my max xmit window */
 
#define L2TP_MAX_REXMIT   5 /* default max rexmit */
 
#define L2TP_MAX_REXMIT_TO   30 /* default rexmit to */
 
#define L2TP_DELAYED_ACK   ((hz + 19) / 20) /* delayed ack: 50 ms */
 
#define L2TP_CONTROL_DSEQ   1 /* we are the lns */
 
#define L2TP_ENABLE_DSEQ   1 /* enable data seq # */
 
#define L2TP_SEQ_DIFF(x, y)   ((int16_t)((x) - (y)))
 
#define SESSHASHSIZE   0x0020
 
#define SESSHASH(x)   (((x) ^ ((x) >> 8)) & (SESSHASHSIZE - 1))
 
#define SEQ_LOCK(seq)   mtx_lock(&(seq)->mtx)
 
#define SEQ_UNLOCK(seq)   mtx_unlock(&(seq)->mtx)
 
#define SEQ_LOCK_ASSERT(seq)   mtx_assert(&(seq)->mtx, MA_OWNED)
 
#define L2TP_COPY_MBUF   m_copypacket
 
#define ERROUT(x)   do { error = (x); goto done; } while (0)
 

Typedefs

typedef struct ng_l2tp_hook_privatehookpriv_p
 
typedef struct ng_l2tp_privatepriv_p
 

Functions

static int ng_l2tp_xmit_ctrl (priv_p priv, struct mbuf *m, u_int16_t ns)
 
static void ng_l2tp_seq_init (priv_p priv)
 
static int ng_l2tp_seq_set (priv_p priv, const struct ng_l2tp_seq_config *conf)
 
static int ng_l2tp_seq_adjust (priv_p priv, const struct ng_l2tp_config *conf)
 
static void ng_l2tp_seq_reset (priv_p priv)
 
static void ng_l2tp_seq_failure (priv_p priv)
 
static void ng_l2tp_seq_recv_nr (priv_p priv, u_int16_t nr)
 
static void ng_l2tp_seq_xack_timeout (void *)
 
static void ng_l2tp_seq_rack_timeout (void *)
 
static hookpriv_p ng_l2tp_find_session (priv_p privp, u_int16_t sid)
 
 NETGRAPH_INIT (l2tp, &ng_l2tp_typestruct)
 
static int ng_l2tp_constructor (node_p node)
 
static int ng_l2tp_newhook (node_p node, hook_p hook, const char *name)
 
static int ng_l2tp_rcvmsg (node_p node, item_p item, hook_p lasthook)
 
static int ng_l2tp_shutdown (node_p node)
 
static int ng_l2tp_disconnect (hook_p hook)
 
static int ng_l2tp_reset_session (hook_p hook, void *arg)
 
static int ng_l2tp_rcvdata_lower (hook_p h, item_p item)
 
static int ng_l2tp_rcvdata_ctrl (hook_p hook, item_p item)
 
static int ng_l2tp_rcvdata (hook_p hook, item_p item)
 

Variables

static ng_constructor_t ng_l2tp_constructor
 
static ng_rcvmsg_t ng_l2tp_rcvmsg
 
static ng_shutdown_t ng_l2tp_shutdown
 
static ng_newhook_t ng_l2tp_newhook
 
static ng_rcvdata_t ng_l2tp_rcvdata
 
static ng_rcvdata_t ng_l2tp_rcvdata_lower
 
static ng_rcvdata_t ng_l2tp_rcvdata_ctrl
 
static ng_disconnect_t ng_l2tp_disconnect
 
static ng_fn_eachhook ng_l2tp_reset_session
 
static const struct ng_parse_struct_field ng_l2tp_seq_config_fields [] = NG_L2TP_SEQ_CONFIG_TYPE_INFO
 
static const struct ng_parse_type ng_l2tp_seq_config_type
 
static const struct ng_parse_struct_field ng_l2tp_config_type_fields [] = NG_L2TP_CONFIG_TYPE_INFO
 
static const struct ng_parse_type ng_l2tp_config_type
 
static const struct ng_parse_struct_field ng_l2tp_sess_config_type_fields [] = NG_L2TP_SESS_CONFIG_TYPE_INFO
 
static const struct ng_parse_type ng_l2tp_sess_config_type
 
static const struct ng_parse_struct_field ng_l2tp_stats_type_fields [] = NG_L2TP_STATS_TYPE_INFO
 
static const struct ng_parse_type ng_l2tp_stats_type
 
static const struct ng_parse_struct_field ng_l2tp_session_stats_type_fields [] = NG_L2TP_SESSION_STATS_TYPE_INFO
 
static const struct ng_parse_type ng_l2tp_session_stats_type
 
static const struct ng_cmdlist ng_l2tp_cmdlist []
 
static struct ng_type ng_l2tp_typestruct
 

Macro Definition Documentation

◆ ERROUT

#define ERROUT (   x)    do { error = (x); goto done; } while (0)

Definition at line 355 of file ng_l2tp.c.

◆ L2TP_CONTROL_DSEQ

#define L2TP_CONTROL_DSEQ   1 /* we are the lns */

Definition at line 100 of file ng_l2tp.c.

◆ L2TP_COPY_MBUF

#define L2TP_COPY_MBUF   m_copypacket

Definition at line 353 of file ng_l2tp.c.

◆ L2TP_CTRL_0BITS

#define L2TP_CTRL_0BITS   0x030d /* ctrl: must be 0 */

Definition at line 83 of file ng_l2tp.c.

◆ L2TP_CTRL_1BITS

#define L2TP_CTRL_1BITS   0xc802 /* ctrl: must be 1 */

Definition at line 84 of file ng_l2tp.c.

◆ L2TP_CTRL_HDR

#define L2TP_CTRL_HDR
Value:
#define L2TP_HDR_VERSION
Definition: ng_l2tp.c:80
#define L2TP_HDR_SEQ
Definition: ng_l2tp.c:76
#define L2TP_HDR_LEN
Definition: ng_l2tp.c:75
#define L2TP_HDR_CTRL
Definition: ng_l2tp.c:74

Definition at line 89 of file ng_l2tp.c.

◆ L2TP_DATA_0BITS

#define L2TP_DATA_0BITS   0x800d /* data: must be 0 */

Definition at line 85 of file ng_l2tp.c.

◆ L2TP_DATA_1BITS

#define L2TP_DATA_1BITS   0x0002 /* data: must be 1 */

Definition at line 86 of file ng_l2tp.c.

◆ L2TP_DATA_HDR

#define L2TP_DATA_HDR   (L2TP_HDR_VERSION) /* optional: len, seq */

Definition at line 91 of file ng_l2tp.c.

◆ L2TP_DELAYED_ACK

#define L2TP_DELAYED_ACK   ((hz + 19) / 20) /* delayed ack: 50 ms */

Definition at line 97 of file ng_l2tp.c.

◆ L2TP_ENABLE_DSEQ

#define L2TP_ENABLE_DSEQ   1 /* enable data seq # */

Definition at line 101 of file ng_l2tp.c.

◆ L2TP_HDR_CTRL

#define L2TP_HDR_CTRL   0x8000 /* control packet */

Definition at line 74 of file ng_l2tp.c.

◆ L2TP_HDR_LEN

#define L2TP_HDR_LEN   0x4000 /* has length field */

Definition at line 75 of file ng_l2tp.c.

◆ L2TP_HDR_OFF

#define L2TP_HDR_OFF   0x0200 /* has offset field */

Definition at line 77 of file ng_l2tp.c.

◆ L2TP_HDR_PRIO

#define L2TP_HDR_PRIO   0x0100 /* give priority */

Definition at line 78 of file ng_l2tp.c.

◆ L2TP_HDR_SEQ

#define L2TP_HDR_SEQ   0x0800 /* has ns, nr fields */

Definition at line 76 of file ng_l2tp.c.

◆ L2TP_HDR_VERS_MASK

#define L2TP_HDR_VERS_MASK   0x000f /* version field mask */

Definition at line 79 of file ng_l2tp.c.

◆ L2TP_HDR_VERSION

#define L2TP_HDR_VERSION   0x0002 /* version field */

Definition at line 80 of file ng_l2tp.c.

◆ L2TP_MAX_REXMIT

#define L2TP_MAX_REXMIT   5 /* default max rexmit */

Definition at line 95 of file ng_l2tp.c.

◆ L2TP_MAX_REXMIT_TO

#define L2TP_MAX_REXMIT_TO   30 /* default rexmit to */

Definition at line 96 of file ng_l2tp.c.

◆ L2TP_MAX_XWIN

#define L2TP_MAX_XWIN   128 /* my max xmit window */

Definition at line 94 of file ng_l2tp.c.

◆ L2TP_SEQ_DIFF

#define L2TP_SEQ_DIFF (   x,
 
)    ((int16_t)((x) - (y)))

Definition at line 104 of file ng_l2tp.c.

◆ M_NETGRAPH_L2TP

#define M_NETGRAPH_L2TP   M_NETGRAPH

Definition at line 70 of file ng_l2tp.c.

◆ SEQ_LOCK

#define SEQ_LOCK (   seq)    mtx_lock(&(seq)->mtx)

Definition at line 347 of file ng_l2tp.c.

◆ SEQ_LOCK_ASSERT

#define SEQ_LOCK_ASSERT (   seq)    mtx_assert(&(seq)->mtx, MA_OWNED)

Definition at line 350 of file ng_l2tp.c.

◆ SEQ_UNLOCK

#define SEQ_UNLOCK (   seq)    mtx_unlock(&(seq)->mtx)

Definition at line 348 of file ng_l2tp.c.

◆ SESSHASH

#define SESSHASH (   x)    (((x) ^ ((x) >> 8)) & (SESSHASHSIZE - 1))

Definition at line 107 of file ng_l2tp.c.

◆ SESSHASHSIZE

#define SESSHASHSIZE   0x0020

Definition at line 106 of file ng_l2tp.c.

Typedef Documentation

◆ hookpriv_p

Definition at line 118 of file ng_l2tp.c.

◆ priv_p

typedef struct ng_l2tp_private* priv_p

Definition at line 163 of file ng_l2tp.c.

Function Documentation

◆ NETGRAPH_INIT()

NETGRAPH_INIT ( l2tp  ,
ng_l2tp_typestruct 
)

◆ ng_l2tp_constructor()

static int ng_l2tp_constructor ( node_p  node)
static

Definition at line 365 of file ng_l2tp.c.

References L2TP_MAX_REXMIT, L2TP_MAX_REXMIT_TO, M_NETGRAPH_L2TP, ng_l2tp_seq_init(), NG_NODE_SET_PRIVATE, and SESSHASHSIZE.

Here is the call graph for this function:

◆ ng_l2tp_disconnect()

static int ng_l2tp_disconnect ( hook_p  hook)
static

Definition at line 682 of file ng_l2tp.c.

References priv::lower, M_NETGRAPH_L2TP, NG_HOOK_NODE, NG_HOOK_PRIVATE, NG_HOOK_SET_PRIVATE, NG_NODE_IS_VALID, NG_NODE_NUMHOOKS, NG_NODE_PRIVATE, and ng_rmnode_self().

Here is the call graph for this function:

◆ ng_l2tp_find_session()

static hookpriv_p ng_l2tp_find_session ( priv_p  privp,
u_int16_t  sid 
)
static

Definition at line 713 of file ng_l2tp.c.

References ng_l2tp_hook_private::conf, SESSHASH, and ng_l2tp_sess_config::session_id.

Referenced by ng_l2tp_rcvdata_lower(), and ng_l2tp_rcvmsg().

Here is the caller graph for this function:

◆ ng_l2tp_newhook()

◆ ng_l2tp_rcvdata()

◆ ng_l2tp_rcvdata_ctrl()

static int ng_l2tp_rcvdata_ctrl ( hook_p  hook,
item_p  item 
)
static

◆ ng_l2tp_rcvdata_lower()

◆ ng_l2tp_rcvmsg()

◆ ng_l2tp_reset_session()

◆ ng_l2tp_seq_adjust()

static int ng_l2tp_seq_adjust ( priv_p  priv,
const struct ng_l2tp_config conf 
)
static

Definition at line 1230 of file ng_l2tp.c.

References ng_l2tp_config::enabled, ERROUT, L2TP_MAX_XWIN, ng_l2tp_seq_reset(), ng_l2tp_config::peer_win, SEQ_LOCK, SEQ_UNLOCK, and l2tp_seq::wmax.

Referenced by ng_l2tp_rcvmsg().

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

◆ ng_l2tp_seq_failure()

static void ng_l2tp_seq_failure ( priv_p  priv)
static

Definition at line 1165 of file ng_l2tp.c.

References NG_MKMESSAGE, NG_SEND_MSG_ID, NGM_L2TP_ACK_FAILURE, and NGM_L2TP_COOKIE.

Referenced by ng_l2tp_seq_rack_timeout().

Here is the caller graph for this function:

◆ ng_l2tp_seq_init()

static void ng_l2tp_seq_init ( priv_p  priv)
static

Definition at line 1184 of file ng_l2tp.c.

References l2tp_seq::cwnd, L2TP_MAX_XWIN, l2tp_seq::mtx, l2tp_seq::rack_timer, l2tp_seq::ssth, l2tp_seq::wmax, and l2tp_seq::xack_timer.

Referenced by ng_l2tp_constructor().

Here is the caller graph for this function:

◆ ng_l2tp_seq_rack_timeout()

static void ng_l2tp_seq_rack_timeout ( void *  arg)
static

◆ ng_l2tp_seq_recv_nr()

static void ng_l2tp_seq_recv_nr ( priv_p  priv,
u_int16_t  nr 
)
static

◆ ng_l2tp_seq_reset()

◆ ng_l2tp_seq_set()

static int ng_l2tp_seq_set ( priv_p  priv,
const struct ng_l2tp_seq_config conf 
)
static

Definition at line 1205 of file ng_l2tp.c.

References priv::enabled, l2tp_seq::nr, ng_l2tp_seq_config::nr, l2tp_seq::ns, ng_l2tp_seq_config::ns, l2tp_seq::rack, ng_l2tp_seq_config::rack, l2tp_seq::xack, and ng_l2tp_seq_config::xack.

Referenced by ng_l2tp_rcvmsg().

Here is the caller graph for this function:

◆ ng_l2tp_seq_xack_timeout()

static void ng_l2tp_seq_xack_timeout ( void *  arg)
static

Definition at line 1407 of file ng_l2tp.c.

References ng_node::nd_vnet, ng_l2tp_xmit_ctrl(), NG_NODE_PRIVATE, l2tp_seq::ns, SEQ_LOCK_ASSERT, and l2tp_seq::xack_timer.

Referenced by ng_l2tp_rcvdata_lower().

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

◆ ng_l2tp_shutdown()

static int ng_l2tp_shutdown ( node_p  node)
static

Definition at line 655 of file ng_l2tp.c.

References M_NETGRAPH_L2TP, l2tp_seq::mtx, ng_l2tp_seq_reset(), NG_NODE_PRIVATE, NG_NODE_UNREF, l2tp_seq::rack_timer, SEQ_LOCK, SEQ_UNLOCK, and l2tp_seq::xack_timer.

Here is the call graph for this function:

◆ ng_l2tp_xmit_ctrl()

static int ng_l2tp_xmit_ctrl ( priv_p  priv,
struct mbuf *  m,
u_int16_t  ns 
)
static

Variable Documentation

◆ ng_l2tp_cmdlist

const struct ng_cmdlist ng_l2tp_cmdlist[]
static

Definition at line 233 of file ng_l2tp.c.

◆ ng_l2tp_config_type

const struct ng_parse_type ng_l2tp_config_type
static
Initial value:
= {
}
static const struct ng_parse_struct_field ng_l2tp_config_type_fields[]
Definition: ng_l2tp.c:202
const struct ng_parse_type ng_parse_struct_type
Definition: ng_parse.c:222

Definition at line 203 of file ng_l2tp.c.

◆ ng_l2tp_config_type_fields

const struct ng_parse_struct_field ng_l2tp_config_type_fields[] = NG_L2TP_CONFIG_TYPE_INFO
static

Definition at line 202 of file ng_l2tp.c.

◆ ng_l2tp_constructor

ng_constructor_t ng_l2tp_constructor
static

Definition at line 166 of file ng_l2tp.c.

◆ ng_l2tp_disconnect

ng_disconnect_t ng_l2tp_disconnect
static

Definition at line 173 of file ng_l2tp.c.

◆ ng_l2tp_newhook

ng_newhook_t ng_l2tp_newhook
static

Definition at line 169 of file ng_l2tp.c.

◆ ng_l2tp_rcvdata

ng_rcvdata_t ng_l2tp_rcvdata
static

Definition at line 170 of file ng_l2tp.c.

◆ ng_l2tp_rcvdata_ctrl

ng_rcvdata_t ng_l2tp_rcvdata_ctrl
static

Definition at line 172 of file ng_l2tp.c.

Referenced by ng_l2tp_newhook().

◆ ng_l2tp_rcvdata_lower

ng_rcvdata_t ng_l2tp_rcvdata_lower
static

Definition at line 171 of file ng_l2tp.c.

Referenced by ng_l2tp_newhook().

◆ ng_l2tp_rcvmsg

ng_rcvmsg_t ng_l2tp_rcvmsg
static

Definition at line 167 of file ng_l2tp.c.

◆ ng_l2tp_reset_session

ng_fn_eachhook ng_l2tp_reset_session
static

Definition at line 190 of file ng_l2tp.c.

Referenced by ng_l2tp_seq_reset().

◆ ng_l2tp_seq_config_fields

const struct ng_parse_struct_field ng_l2tp_seq_config_fields[] = NG_L2TP_SEQ_CONFIG_TYPE_INFO
static

Definition at line 194 of file ng_l2tp.c.

◆ ng_l2tp_seq_config_type

const struct ng_parse_type ng_l2tp_seq_config_type
static
Initial value:
= {
}
static const struct ng_parse_struct_field ng_l2tp_seq_config_fields[]
Definition: ng_l2tp.c:194

Definition at line 195 of file ng_l2tp.c.

◆ ng_l2tp_sess_config_type

const struct ng_parse_type ng_l2tp_sess_config_type
static
Initial value:
= {
}
static const struct ng_parse_struct_field ng_l2tp_sess_config_type_fields[]
Definition: ng_l2tp.c:210

Definition at line 211 of file ng_l2tp.c.

◆ ng_l2tp_sess_config_type_fields

const struct ng_parse_struct_field ng_l2tp_sess_config_type_fields[] = NG_L2TP_SESS_CONFIG_TYPE_INFO
static

Definition at line 210 of file ng_l2tp.c.

◆ ng_l2tp_session_stats_type

const struct ng_parse_type ng_l2tp_session_stats_type
static
Initial value:
= {
}
static const struct ng_parse_struct_field ng_l2tp_session_stats_type_fields[]
Definition: ng_l2tp.c:226

Definition at line 227 of file ng_l2tp.c.

◆ ng_l2tp_session_stats_type_fields

const struct ng_parse_struct_field ng_l2tp_session_stats_type_fields[] = NG_L2TP_SESSION_STATS_TYPE_INFO
static

Definition at line 226 of file ng_l2tp.c.

◆ ng_l2tp_shutdown

ng_shutdown_t ng_l2tp_shutdown
static

Definition at line 168 of file ng_l2tp.c.

◆ ng_l2tp_stats_type

const struct ng_parse_type ng_l2tp_stats_type
static
Initial value:
= {
}
static const struct ng_parse_struct_field ng_l2tp_stats_type_fields[]
Definition: ng_l2tp.c:218

Definition at line 219 of file ng_l2tp.c.

◆ ng_l2tp_stats_type_fields

const struct ng_parse_struct_field ng_l2tp_stats_type_fields[] = NG_L2TP_STATS_TYPE_INFO
static

Definition at line 218 of file ng_l2tp.c.

◆ ng_l2tp_typestruct

struct ng_type ng_l2tp_typestruct
static
Initial value:
= {
.version = NG_ABI_VERSION,
.constructor = ng_l2tp_constructor,
.rcvmsg = ng_l2tp_rcvmsg,
.shutdown = ng_l2tp_shutdown,
.newhook = ng_l2tp_newhook,
.rcvdata = ng_l2tp_rcvdata,
.disconnect = ng_l2tp_disconnect,
.cmdlist = ng_l2tp_cmdlist,
}
#define NG_ABI_VERSION
Definition: netgraph.h:77
static ng_constructor_t ng_l2tp_constructor
Definition: ng_l2tp.c:166
static const struct ng_cmdlist ng_l2tp_cmdlist[]
Definition: ng_l2tp.c:233
static ng_rcvdata_t ng_l2tp_rcvdata
Definition: ng_l2tp.c:170
static ng_disconnect_t ng_l2tp_disconnect
Definition: ng_l2tp.c:173
static ng_newhook_t ng_l2tp_newhook
Definition: ng_l2tp.c:169
static ng_shutdown_t ng_l2tp_shutdown
Definition: ng_l2tp.c:168
static ng_rcvmsg_t ng_l2tp_rcvmsg
Definition: ng_l2tp.c:167
#define NG_L2TP_NODE_TYPE
Definition: ng_l2tp.h:46

Definition at line 322 of file ng_l2tp.c.