FreeBSD kernel netgraph code
ng_pptpgre.c File Reference
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/time.h>
#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/mbuf.h>
#include <sys/mutex.h>
#include <sys/endian.h>
#include <sys/errno.h>
#include <sys/sysctl.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <netgraph/ng_message.h>
#include <netgraph/netgraph.h>
#include <netgraph/ng_parse.h>
#include <netgraph/ng_pptpgre.h>
Include dependency graph for ng_pptpgre.c:

Go to the source code of this file.

Data Structures

struct  greheader
 
struct  ng_pptpgre_roq
 
struct  ng_pptpgre_sess
 
struct  ng_pptpgre_private
 

Macros

#define PPTP_GRE_PROTO   0x880b
 
#define PPTP_INIT_VALUE   ((0x2001 << 16) | PPTP_GRE_PROTO)
 
#define PPTP_INIT_MASK   0xef7fffff
 
#define PPTP_MAX_PAYLOAD   (0xffff - sizeof(struct greheader) - 8)
 
#define PPTP_TIME_SCALE   1024 /* milliseconds */
 
#define PPTP_XMIT_WIN   16 /* max xmit window */
 
#define PPTP_MIN_TIMEOUT   (PPTP_TIME_SCALE / 83) /* 12 milliseconds */
 
#define PPTP_MAX_TIMEOUT   (3 * PPTP_TIME_SCALE) /* 3 seconds */
 
#define PPTP_REORDER_TIMEOUT   1
 
#define PPTP_MIN_ACK_DELAY   (PPTP_TIME_SCALE / 500) /* 2 milliseconds */
 
#define PPTP_MAX_ACK_DELAY   (PPTP_TIME_SCALE / 2) /* 500 milliseconds */
 
#define PPTP_ACK_ALPHA(x)   (((x) + 4) >> 3) /* alpha = 0.125 */
 
#define PPTP_ACK_BETA(x)   (((x) + 2) >> 2) /* beta = 0.25 */
 
#define PPTP_ACK_CHI(x)   ((x) << 2) /* chi = 4 */
 
#define PPTP_ACK_DELTA(x)   ((x) << 1) /* delta = 2 */
 
#define PPTP_SEQ_DIFF(x, y)   ((int32_t)(x) - (int32_t)(y))
 
#define SESSHASHSIZE   0x0020
 
#define SESSHASH(x)   (((x) ^ ((x) >> 8)) & (SESSHASHSIZE - 1))
 
#define ERROUT(x)   do { error = (x); goto done; } while (0)
 
#define INIT_SENDQ(t)
 

Typedefs

typedef u_int64_t pptptime_t
 
typedef struct ng_pptpgre_roq_head roqh
 
typedef struct ng_pptpgre_sesshpriv_p
 
typedef struct ng_pptpgre_privatepriv_p
 

Functions

 SYSCTL_NODE (_net_graph, OID_AUTO, pptpgre, CTLFLAG_RW|CTLFLAG_MPSAFE, 0, "PPTPGRE")
 
 SYSCTL_UINT (_net_graph_pptpgre, OID_AUTO, reorder_max, CTLFLAG_RWTUN, &reorder_max, 0, "Reorder queue maximum length")
 
 SYSCTL_UINT (_net_graph_pptpgre, OID_AUTO, reorder_timeout, CTLFLAG_RWTUN, &reorder_timeout, 0, "Reorder timeout is milliseconds")
 
 SLIST_HEAD (ng_pptpgre_roq_head, ng_pptpgre_roq)
 
static int ng_pptpgre_xmit (hpriv_p hpriv, item_p item)
 
static void ng_pptpgre_start_send_ack_timer (hpriv_p hpriv)
 
static void ng_pptpgre_start_recv_ack_timer (hpriv_p hpriv)
 
static void ng_pptpgre_start_reorder_timer (hpriv_p hpriv)
 
static void ng_pptpgre_recv_ack_timeout (node_p node, hook_p hook, void *arg1, int arg2)
 
static void ng_pptpgre_send_ack_timeout (node_p node, hook_p hook, void *arg1, int arg2)
 
static void ng_pptpgre_reorder_timeout (node_p node, hook_p hook, void *arg1, int arg2)
 
static hpriv_p ng_pptpgre_find_session (priv_p privp, u_int16_t cid)
 
static void ng_pptpgre_reset (hpriv_p hpriv)
 
static pptptime_t ng_pptpgre_time (void)
 
static void ng_pptpgre_ack (const hpriv_p hpriv)
 
static int ng_pptpgre_sendq (const hpriv_p hpriv, roqh *q, const struct ng_pptpgre_roq *st)
 
 NETGRAPH_INIT (pptpgre, &ng_pptpgre_typestruct)
 
static int ng_pptpgre_constructor (node_p node)
 
static int ng_pptpgre_newhook (node_p node, hook_p hook, const char *name)
 
static int ng_pptpgre_rcvmsg (node_p node, item_p item, hook_p lasthook)
 
static int ng_pptpgre_rcvdata (hook_p hook, item_p item)
 
static int ng_pptpgre_disconnect (hook_p hook)
 
static int ng_pptpgre_shutdown (node_p node)
 
static int ng_pptpgre_rcvdata_lower (hook_p hook, item_p item)
 

Variables

static int reorder_max = 1
 
static int reorder_timeout = PPTP_REORDER_TIMEOUT
 
static ng_constructor_t ng_pptpgre_constructor
 
static ng_rcvmsg_t ng_pptpgre_rcvmsg
 
static ng_shutdown_t ng_pptpgre_shutdown
 
static ng_newhook_t ng_pptpgre_newhook
 
static ng_rcvdata_t ng_pptpgre_rcvdata
 
static ng_rcvdata_t ng_pptpgre_rcvdata_lower
 
static ng_disconnect_t ng_pptpgre_disconnect
 
static const struct ng_parse_struct_field ng_pptpgre_conf_type_fields [] = NG_PPTPGRE_CONF_TYPE_INFO
 
static const struct ng_parse_type ng_pptpgre_conf_type
 
static const struct ng_parse_struct_field ng_pptpgre_stats_type_fields [] = NG_PPTPGRE_STATS_TYPE_INFO
 
static const struct ng_parse_type ng_pptp_stats_type
 
static const struct ng_cmdlist ng_pptpgre_cmdlist []
 
static struct ng_type ng_pptpgre_typestruct
 

Macro Definition Documentation

◆ ERROUT

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

Definition at line 309 of file ng_pptpgre.c.

◆ INIT_SENDQ

#define INIT_SENDQ (   t)
Value:
do { \
t.item = item; \
t.seq = seq; \
SLIST_INSERT_HEAD(&sendq, &t, next); \
last = &t; \
hpriv->recvSeq = seq; \
goto deliver; \
} while(0)

◆ PPTP_ACK_ALPHA

#define PPTP_ACK_ALPHA (   x)    (((x) + 4) >> 3) /* alpha = 0.125 */

Definition at line 138 of file ng_pptpgre.c.

◆ PPTP_ACK_BETA

#define PPTP_ACK_BETA (   x)    (((x) + 2) >> 2) /* beta = 0.25 */

Definition at line 139 of file ng_pptpgre.c.

◆ PPTP_ACK_CHI

#define PPTP_ACK_CHI (   x)    ((x) << 2) /* chi = 4 */

Definition at line 140 of file ng_pptpgre.c.

◆ PPTP_ACK_DELTA

#define PPTP_ACK_DELTA (   x)    ((x) << 1) /* delta = 2 */

Definition at line 141 of file ng_pptpgre.c.

◆ PPTP_GRE_PROTO

#define PPTP_GRE_PROTO   0x880b

Definition at line 110 of file ng_pptpgre.c.

◆ PPTP_INIT_MASK

#define PPTP_INIT_MASK   0xef7fffff

Definition at line 114 of file ng_pptpgre.c.

◆ PPTP_INIT_VALUE

#define PPTP_INIT_VALUE   ((0x2001 << 16) | PPTP_GRE_PROTO)

Definition at line 113 of file ng_pptpgre.c.

◆ PPTP_MAX_ACK_DELAY

#define PPTP_MAX_ACK_DELAY   (PPTP_TIME_SCALE / 2) /* 500 milliseconds */

Definition at line 135 of file ng_pptpgre.c.

◆ PPTP_MAX_PAYLOAD

#define PPTP_MAX_PAYLOAD   (0xffff - sizeof(struct greheader) - 8)

Definition at line 117 of file ng_pptpgre.c.

◆ PPTP_MAX_TIMEOUT

#define PPTP_MAX_TIMEOUT   (3 * PPTP_TIME_SCALE) /* 3 seconds */

Definition at line 126 of file ng_pptpgre.c.

◆ PPTP_MIN_ACK_DELAY

#define PPTP_MIN_ACK_DELAY   (PPTP_TIME_SCALE / 500) /* 2 milliseconds */

Definition at line 134 of file ng_pptpgre.c.

◆ PPTP_MIN_TIMEOUT

#define PPTP_MIN_TIMEOUT   (PPTP_TIME_SCALE / 83) /* 12 milliseconds */

Definition at line 125 of file ng_pptpgre.c.

◆ PPTP_REORDER_TIMEOUT

#define PPTP_REORDER_TIMEOUT   1

Definition at line 128 of file ng_pptpgre.c.

◆ PPTP_SEQ_DIFF

#define PPTP_SEQ_DIFF (   x,
 
)    ((int32_t)(x) - (int32_t)(y))

Definition at line 143 of file ng_pptpgre.c.

◆ PPTP_TIME_SCALE

#define PPTP_TIME_SCALE   1024 /* milliseconds */

Definition at line 120 of file ng_pptpgre.c.

◆ PPTP_XMIT_WIN

#define PPTP_XMIT_WIN   16 /* max xmit window */

Definition at line 124 of file ng_pptpgre.c.

◆ SESSHASH

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

Definition at line 146 of file ng_pptpgre.c.

◆ SESSHASHSIZE

#define SESSHASHSIZE   0x0020

Definition at line 145 of file ng_pptpgre.c.

Typedef Documentation

◆ hpriv_p

typedef struct ng_pptpgre_sess* hpriv_p

Definition at line 200 of file ng_pptpgre.c.

◆ pptptime_t

typedef u_int64_t pptptime_t

Definition at line 121 of file ng_pptpgre.c.

◆ priv_p

typedef struct ng_pptpgre_private* priv_p

Definition at line 210 of file ng_pptpgre.c.

◆ roqh

typedef struct ng_pptpgre_roq_head roqh

Definition at line 175 of file ng_pptpgre.c.

Function Documentation

◆ NETGRAPH_INIT()

NETGRAPH_INIT ( pptpgre  ,
ng_pptpgre_typestruct 
)

◆ ng_pptpgre_ack()

static void ng_pptpgre_ack ( const hpriv_p  hpriv)
static

Definition at line 699 of file ng_pptpgre.c.

References ng_pptpgre_start_send_ack_timer(), and ng_pptpgre_xmit().

Referenced by ng_pptpgre_rcvdata_lower(), and ng_pptpgre_reorder_timeout().

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

◆ ng_pptpgre_constructor()

static int ng_pptpgre_constructor ( node_p  node)
static

Definition at line 319 of file ng_pptpgre.c.

References ng_callout_init, NG_NODE_SET_PRIVATE, and SESSHASHSIZE.

◆ ng_pptpgre_disconnect()

static int ng_pptpgre_disconnect ( hook_p  hook)
static

Definition at line 529 of file ng_pptpgre.c.

References priv::lower, NG_HOOK_NODE, NG_HOOK_PRIVATE, NG_NODE_IS_VALID, NG_NODE_NUMHOOKS, NG_NODE_PRIVATE, ng_pptpgre_reset(), ng_rmnode_self(), and priv::upper.

Here is the call graph for this function:

◆ ng_pptpgre_find_session()

static hpriv_p ng_pptpgre_find_session ( priv_p  privp,
u_int16_t  cid 
)
static

Definition at line 1218 of file ng_pptpgre.c.

References SESSHASH.

Referenced by ng_pptpgre_rcvdata_lower(), and ng_pptpgre_rcvmsg().

Here is the caller graph for this function:

◆ ng_pptpgre_newhook()

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

◆ ng_pptpgre_rcvdata()

static int ng_pptpgre_rcvdata ( hook_p  hook,
item_p  item 
)
static

Definition at line 505 of file ng_pptpgre.c.

References NG_FREE_ITEM, NG_HOOK_PRIVATE, and ng_pptpgre_xmit().

Here is the call graph for this function:

◆ ng_pptpgre_rcvdata_lower()

◆ ng_pptpgre_rcvmsg()

◆ ng_pptpgre_recv_ack_timeout()

static void ng_pptpgre_recv_ack_timeout ( node_p  node,
hook_p  hook,
void *  arg1,
int  arg2 
)
static

Definition at line 1089 of file ng_pptpgre.c.

References NG_NODE_PRIVATE, PPTP_ACK_CHI, PPTP_ACK_DELTA, PPTP_MAX_TIMEOUT, PPTP_MIN_TIMEOUT, and priv::stats.

Referenced by ng_pptpgre_start_recv_ack_timer().

Here is the caller graph for this function:

◆ ng_pptpgre_reorder_timeout()

static void ng_pptpgre_reorder_timeout ( node_p  node,
hook_p  hook,
void *  arg1,
int  arg2 
)
static

Definition at line 1168 of file ng_pptpgre.c.

References last, NG_NODE_PRIVATE, ng_pptpgre_ack(), ng_pptpgre_sendq(), ng_pptpgre_start_reorder_timer(), PPTP_SEQ_DIFF, and priv::stats.

Referenced by ng_pptpgre_start_reorder_timer().

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

◆ ng_pptpgre_reset()

static void ng_pptpgre_reset ( hpriv_p  hpriv)
static

Definition at line 1235 of file ng_pptpgre.c.

References NG_FREE_ITEM, ng_uncallout(), PPTP_MAX_TIMEOUT, PPTP_TIME_SCALE, and PPTP_XMIT_WIN.

Referenced by ng_pptpgre_disconnect(), ng_pptpgre_rcvmsg(), and ng_pptpgre_shutdown().

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

◆ ng_pptpgre_send_ack_timeout()

static void ng_pptpgre_send_ack_timeout ( node_p  node,
hook_p  hook,
void *  arg1,
int  arg2 
)
static

Definition at line 1138 of file ng_pptpgre.c.

References ng_pptpgre_xmit().

Referenced by ng_pptpgre_start_send_ack_timer().

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

◆ ng_pptpgre_sendq()

static int ng_pptpgre_sendq ( const hpriv_p  hpriv,
roqh q,
const struct ng_pptpgre_roq st 
)
static

Definition at line 723 of file ng_pptpgre.c.

References NG_FWD_NEW_DATA, and NGI_GET_M.

Referenced by ng_pptpgre_rcvdata_lower(), and ng_pptpgre_reorder_timeout().

Here is the caller graph for this function:

◆ ng_pptpgre_shutdown()

static int ng_pptpgre_shutdown ( node_p  node)
static

Definition at line 561 of file ng_pptpgre.c.

References NG_NODE_PRIVATE, NG_NODE_UNREF, and ng_pptpgre_reset().

Here is the call graph for this function:

◆ ng_pptpgre_start_recv_ack_timer()

static void ng_pptpgre_start_recv_ack_timer ( hpriv_p  hpriv)
static

Definition at line 1067 of file ng_pptpgre.c.

References ng_callout(), ng_pptpgre_recv_ack_timeout(), ng_pptpgre_time(), and PPTP_TIME_SCALE.

Referenced by ng_pptpgre_rcvdata_lower(), and ng_pptpgre_xmit().

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

◆ ng_pptpgre_start_reorder_timer()

static void ng_pptpgre_start_reorder_timer ( hpriv_p  hpriv)
static

Definition at line 1153 of file ng_pptpgre.c.

References ng_callout(), ng_pptpgre_reorder_timeout(), and reorder_timeout.

Referenced by ng_pptpgre_rcvdata_lower(), and ng_pptpgre_reorder_timeout().

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

◆ ng_pptpgre_start_send_ack_timer()

static void ng_pptpgre_start_send_ack_timer ( hpriv_p  hpriv)
static

Definition at line 1114 of file ng_pptpgre.c.

References ng_callout(), ng_pptpgre_send_ack_timeout(), PPTP_MAX_ACK_DELAY, PPTP_MIN_ACK_DELAY, and PPTP_TIME_SCALE.

Referenced by ng_pptpgre_ack().

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

◆ ng_pptpgre_time()

static pptptime_t ng_pptpgre_time ( void  )
static

Definition at line 1277 of file ng_pptpgre.c.

References PPTP_TIME_SCALE.

Referenced by ng_pptpgre_rcvdata_lower(), ng_pptpgre_start_recv_ack_timer(), and ng_pptpgre_xmit().

Here is the caller graph for this function:

◆ ng_pptpgre_xmit()

◆ SLIST_HEAD()

SLIST_HEAD ( ng_pptpgre_roq_head  ,
ng_pptpgre_roq   
)

◆ SYSCTL_NODE()

SYSCTL_NODE ( _net_graph  ,
OID_AUTO  ,
pptpgre  ,
CTLFLAG_RW|  CTLFLAG_MPSAFE,
,
"PPTPGRE"   
)

◆ SYSCTL_UINT() [1/2]

SYSCTL_UINT ( _net_graph_pptpgre  ,
OID_AUTO  ,
reorder_max  ,
CTLFLAG_RWTUN  ,
reorder_max,
,
"Reorder queue maximum length  
)

◆ SYSCTL_UINT() [2/2]

SYSCTL_UINT ( _net_graph_pptpgre  ,
OID_AUTO  ,
reorder_timeout  ,
CTLFLAG_RWTUN  ,
reorder_timeout,
,
"Reorder timeout is milliseconds"   
)

Variable Documentation

◆ ng_pptp_stats_type

const struct ng_parse_type ng_pptp_stats_type
static
Initial value:
= {
}
const struct ng_parse_type ng_parse_struct_type
Definition: ng_parse.c:222
static const struct ng_parse_struct_field ng_pptpgre_stats_type_fields[]
Definition: ng_pptpgre.c:249

Definition at line 250 of file ng_pptpgre.c.

◆ ng_pptpgre_cmdlist

const struct ng_cmdlist ng_pptpgre_cmdlist[]
static

Definition at line 256 of file ng_pptpgre.c.

◆ ng_pptpgre_conf_type

const struct ng_parse_type ng_pptpgre_conf_type
static
Initial value:
= {
}
static const struct ng_parse_struct_field ng_pptpgre_conf_type_fields[]
Definition: ng_pptpgre.c:241

Definition at line 242 of file ng_pptpgre.c.

◆ ng_pptpgre_conf_type_fields

const struct ng_parse_struct_field ng_pptpgre_conf_type_fields[] = NG_PPTPGRE_CONF_TYPE_INFO
static

Definition at line 240 of file ng_pptpgre.c.

◆ ng_pptpgre_constructor

ng_constructor_t ng_pptpgre_constructor
static

Definition at line 213 of file ng_pptpgre.c.

◆ ng_pptpgre_disconnect

ng_disconnect_t ng_pptpgre_disconnect
static

Definition at line 219 of file ng_pptpgre.c.

◆ ng_pptpgre_newhook

ng_newhook_t ng_pptpgre_newhook
static

Definition at line 216 of file ng_pptpgre.c.

◆ ng_pptpgre_rcvdata

ng_rcvdata_t ng_pptpgre_rcvdata
static

Definition at line 217 of file ng_pptpgre.c.

◆ ng_pptpgre_rcvdata_lower

ng_rcvdata_t ng_pptpgre_rcvdata_lower
static

Definition at line 218 of file ng_pptpgre.c.

Referenced by ng_pptpgre_newhook().

◆ ng_pptpgre_rcvmsg

ng_rcvmsg_t ng_pptpgre_rcvmsg
static

Definition at line 214 of file ng_pptpgre.c.

◆ ng_pptpgre_shutdown

ng_shutdown_t ng_pptpgre_shutdown
static

Definition at line 215 of file ng_pptpgre.c.

◆ ng_pptpgre_stats_type_fields

const struct ng_parse_struct_field ng_pptpgre_stats_type_fields[] = NG_PPTPGRE_STATS_TYPE_INFO
static

Definition at line 248 of file ng_pptpgre.c.

◆ ng_pptpgre_typestruct

struct ng_type ng_pptpgre_typestruct
static
Initial value:
= {
.version = NG_ABI_VERSION,
.constructor = ng_pptpgre_constructor,
.rcvmsg = ng_pptpgre_rcvmsg,
.shutdown = ng_pptpgre_shutdown,
.newhook = ng_pptpgre_newhook,
.rcvdata = ng_pptpgre_rcvdata,
.disconnect = ng_pptpgre_disconnect,
.cmdlist = ng_pptpgre_cmdlist,
}
#define NG_ABI_VERSION
Definition: netgraph.h:77
static ng_shutdown_t ng_pptpgre_shutdown
Definition: ng_pptpgre.c:215
static ng_newhook_t ng_pptpgre_newhook
Definition: ng_pptpgre.c:216
static ng_rcvmsg_t ng_pptpgre_rcvmsg
Definition: ng_pptpgre.c:214
static ng_constructor_t ng_pptpgre_constructor
Definition: ng_pptpgre.c:213
static const struct ng_cmdlist ng_pptpgre_cmdlist[]
Definition: ng_pptpgre.c:256
static ng_rcvdata_t ng_pptpgre_rcvdata
Definition: ng_pptpgre.c:217
static ng_disconnect_t ng_pptpgre_disconnect
Definition: ng_pptpgre.c:219
#define NG_PPTPGRE_NODE_TYPE
Definition: ng_pptpgre.h:48

Definition at line 296 of file ng_pptpgre.c.

◆ reorder_max

int reorder_max = 1
static

Definition at line 160 of file ng_pptpgre.c.

Referenced by ng_pptpgre_rcvdata_lower().

◆ reorder_timeout

int reorder_timeout = PPTP_REORDER_TIMEOUT
static

Definition at line 164 of file ng_pptpgre.c.

Referenced by ng_pptpgre_start_reorder_timer().