FreeBSD kernel netgraph code
ng_pppoe.c File Reference
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/ktr.h>
#include <sys/mbuf.h>
#include <sys/malloc.h>
#include <sys/errno.h>
#include <sys/epoch.h>
#include <sys/syslog.h>
#include <net/ethernet.h>
#include <netgraph/ng_message.h>
#include <netgraph/netgraph.h>
#include <netgraph/ng_parse.h>
#include <netgraph/ng_pppoe.h>
#include <netgraph/ng_ether.h>
Include dependency graph for ng_pppoe.c:

Go to the source code of this file.

Data Structures

struct  sess_neg
 
struct  sess_con
 
struct  sess_hash_entry
 
struct  PPPoE
 
union  uniq
 

Macros

#define M_NETGRAPH_PPPOE   M_NETGRAPH
 
#define SIGNOFF   "session closed"
 
#define NUMTAGS   20 /* number of tags we are set up to work with */
 
#define SESSHASHSIZE   0x0100
 
#define SESSHASH(x)   (((x) ^ ((x) >> 8)) & (SESSHASHSIZE - 1))
 
#define COMPAT_3COM   0x00000001
 
#define COMPAT_DLINK   0x00000002
 
#define LEAVE(x)   do { error = x; goto quit; } while(0)
 

Typedefs

typedef struct sess_negnegp
 
typedef struct sess_consessp
 
typedef struct PPPoEpriv_p
 

Enumerations

enum  state {
  PPPOE_SNONE =0 , PPPOE_LISTENING , PPPOE_SINIT , PPPOE_PRIMED ,
  PPPOE_SOFFER , PPPOE_SREQ , PPPOE_NEWCONNECTED , PPPOE_CONNECTED ,
  PPPOE_DEAD
}
 

Functions

 NETGRAPH_INIT (pppoe, &typestruct)
 
static void pppoe_start (sessp sp)
 
static void pppoe_ticker (node_p node, hook_p hook, void *arg1, int arg2)
 
static const struct pppoe_tagscan_tags (sessp sp, const struct pppoe_hdr *ph)
 
static int pppoe_send_event (sessp sp, enum cmd cmdid)
 
static __inline const struct pppoe_tagnext_tag (const struct pppoe_hdr *ph)
 
static const struct pppoe_tagget_tag (const struct pppoe_hdr *ph, uint16_t idx)
 
static void init_tags (sessp sp)
 
static void insert_tag (sessp sp, const struct pppoe_tag *tp)
 
static void make_packet (sessp sp)
 
static hook_p pppoe_match_svc (node_p node, const struct pppoe_tag *tag)
 
static int pppoe_broadcast_padi (node_p node, struct mbuf *m0)
 
static hook_p pppoe_find_svc (node_p node, const char *svc_name, int svc_len)
 
static uint16_t pppoe_getnewsession (sessp sp)
 
static void pppoe_addsession (sessp sp)
 
static void pppoe_delsession (sessp sp)
 
static sessp pppoe_findsession (priv_p privp, const struct pppoe_full_hdr *wh)
 
static hook_p pppoe_finduniq (node_p node, const struct pppoe_tag *tag)
 
static hook_p pppoe_findcookie (node_p node, const struct pppoe_tag *tag)
 
static int ng_pppoe_constructor (node_p node)
 
static int ng_pppoe_newhook (node_p node, hook_p hook, const char *name)
 
static int ng_pppoe_connect (hook_p hook)
 
static int ng_pppoe_rcvmsg (node_p node, item_p item, hook_p lasthook)
 
static int send_acname (sessp sp, const struct pppoe_tag *tag)
 
static int send_sessionid (sessp sp)
 
static int send_maxp (sessp sp, const struct pppoe_tag *tag)
 
static int send_hurl (sessp sp, const struct pppoe_tag *tag)
 
static int send_motm (sessp sp, const struct pppoe_tag *tag)
 
static int ng_pppoe_rcvdata (hook_p hook, item_p item)
 
static int ng_pppoe_rcvdata_ether (hook_p hook, item_p item)
 
static int ng_pppoe_rcvdata_debug (hook_p hook, item_p item)
 
static int ng_pppoe_shutdown (node_p node)
 
static int ng_pppoe_disconnect (hook_p hook)
 

Variables

static ng_constructor_t ng_pppoe_constructor
 
static ng_rcvmsg_t ng_pppoe_rcvmsg
 
static ng_shutdown_t ng_pppoe_shutdown
 
static ng_newhook_t ng_pppoe_newhook
 
static ng_connect_t ng_pppoe_connect
 
static ng_rcvdata_t ng_pppoe_rcvdata
 
static ng_rcvdata_t ng_pppoe_rcvdata_ether
 
static ng_rcvdata_t ng_pppoe_rcvdata_debug
 
static ng_disconnect_t ng_pppoe_disconnect
 
static const struct ng_parse_struct_field ngpppoe_init_data_type_fields [] = NG_PPPOE_INIT_DATA_TYPE_INFO
 
static const struct ng_parse_type ngpppoe_init_data_state_type
 
static const struct ng_parse_struct_field ng_pppoe_sts_type_fields [] = NG_PPPOE_STS_TYPE_INFO
 
static const struct ng_parse_type ng_pppoe_sts_state_type
 
static const struct ng_cmdlist ng_pppoe_cmds []
 
static struct ng_type typestruct
 

Macro Definition Documentation

◆ COMPAT_3COM

#define COMPAT_3COM   0x00000001

Definition at line 284 of file ng_pppoe.c.

◆ COMPAT_DLINK

#define COMPAT_DLINK   0x00000002

Definition at line 285 of file ng_pppoe.c.

◆ LEAVE

#define LEAVE (   x)    do { error = x; goto quit; } while(0)

Definition at line 298 of file ng_pppoe.c.

◆ M_NETGRAPH_PPPOE

#define M_NETGRAPH_PPPOE   M_NETGRAPH

Definition at line 64 of file ng_pppoe.c.

◆ NUMTAGS

#define NUMTAGS   20 /* number of tags we are set up to work with */

Definition at line 227 of file ng_pppoe.c.

◆ SESSHASH

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

Definition at line 267 of file ng_pppoe.c.

◆ SESSHASHSIZE

#define SESSHASHSIZE   0x0100

Definition at line 266 of file ng_pppoe.c.

◆ SIGNOFF

#define SIGNOFF   "session closed"

Definition at line 67 of file ng_pppoe.c.

Typedef Documentation

◆ negp

typedef struct sess_neg* negp

Definition at line 250 of file ng_pppoe.c.

◆ priv_p

typedef struct PPPoE* priv_p

Definition at line 291 of file ng_pppoe.c.

◆ sessp

typedef struct sess_con* sessp

Definition at line 264 of file ng_pppoe.c.

Enumeration Type Documentation

◆ state

enum state
Enumerator
PPPOE_SNONE 
PPPOE_LISTENING 
PPPOE_SINIT 
PPPOE_PRIMED 
PPPOE_SOFFER 
PPPOE_SREQ 
PPPOE_NEWCONNECTED 
PPPOE_CONNECTED 
PPPOE_DEAD 

Definition at line 215 of file ng_pppoe.c.

Function Documentation

◆ get_tag()

static const struct pppoe_tag * get_tag ( const struct pppoe_hdr ph,
uint16_t  idx 
)
static

Definition at line 326 of file ng_pppoe.c.

References next_tag(), pppoe_tag::tag_len, and pppoe_tag::tag_type.

Referenced by ng_pppoe_rcvdata(), and ng_pppoe_rcvdata_ether().

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

◆ init_tags()

static void init_tags ( sessp  sp)
static

Definition at line 364 of file ng_pppoe.c.

References sess_con::neg, and sess_neg::numtags.

Referenced by ng_pppoe_rcvdata(), ng_pppoe_rcvdata_ether(), and pppoe_start().

Here is the caller graph for this function:

◆ insert_tag()

static void insert_tag ( sessp  sp,
const struct pppoe_tag tp 
)
static

Definition at line 371 of file ng_pppoe.c.

References sess_con::neg, NUMTAGS, sess_neg::numtags, and sess_neg::tags.

Referenced by ng_pppoe_rcvdata(), ng_pppoe_rcvdata_ether(), pppoe_start(), and scan_tags().

Here is the caller graph for this function:

◆ make_packet()

static void make_packet ( sessp  sp)
static

◆ NETGRAPH_INIT()

NETGRAPH_INIT ( pppoe  ,
typestruct 
)

◆ next_tag()

static __inline const struct pppoe_tag * next_tag ( const struct pppoe_hdr ph)
static

Definition at line 314 of file ng_pppoe.c.

References pppoe_hdr::length.

Referenced by get_tag(), and scan_tags().

Here is the caller graph for this function:

◆ ng_pppoe_connect()

static int ng_pppoe_connect ( hook_p  hook)
static

◆ ng_pppoe_constructor()

static int ng_pppoe_constructor ( node_p  node)
static

◆ ng_pppoe_disconnect()

◆ ng_pppoe_newhook()

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

◆ ng_pppoe_rcvdata()

◆ ng_pppoe_rcvdata_debug()

static int ng_pppoe_rcvdata_debug ( hook_p  hook,
item_p  item 
)
static

◆ ng_pppoe_rcvdata_ether()

◆ ng_pppoe_rcvmsg()

static int ng_pppoe_rcvmsg ( node_p  node,
item_p  item,
hook_p  lasthook 
)
static

Definition at line 763 of file ng_pppoe.c.

References sess_neg::ac_name, sess_neg::ac_name_len, ng_mesg::ng_msghdr::arglen, ng_mesg::ng_msghdr::cmd, pppoe_hdr::code, COMPAT_3COM, COMPAT_DLINK, sess_con::creator, ng_mesg::data, ngpppoe_init_data::data, datatag::data, ngpppoe_init_data::data_len, pppoe_full_hdr::eh, ETHERTYPE_PPPOE_3COM_DISC, ETHERTYPE_PPPOE_3COM_SESS, ETHERTYPE_PPPOE_DISC, ng_mesg::ng_msghdr::flags, sess_neg::handle, datatag::hdr, ng_mesg::header, ngpppoe_init_data::hook, sess_neg::host_uniq, sess_neg::host_uniq_len, LEAVE, pppoe_hdr::length, sess_neg::m, M_NETGRAPH_PPPOE, ng_node::nd_ID, sess_con::neg, ng_callout_init, ng_findhook(), NG_FREE_MSG, NG_HOOK_PRIVATE, NG_MKRESPONSE, NG_NODE_PRIVATE, NG_PPPOE_3COM, NG_PPPOE_DLINK, NG_PPPOE_STANDARD, NG_RESPOND_MSG, NG_SEND_DATA_ONLY, NGF_RESP, NGI_GET_MSG, NGI_RETADDR, NGM_ETHER_COOKIE, NGM_ETHER_GET_ENADDR, NGM_PPPOE_CONNECT, NGM_PPPOE_COOKIE, NGM_PPPOE_GET_STATUS, NGM_PPPOE_GETMODE, NGM_PPPOE_LISTEN, NGM_PPPOE_OFFER, NGM_PPPOE_SEND_HURL, NGM_PPPOE_SEND_MOTM, NGM_PPPOE_SERVICE, NGM_PPPOE_SETENADDR, NGM_PPPOE_SETMAXP, NGM_PPPOE_SETMODE, PADM_CODE, PADO_CODE, PADT_CODE, pppoe_full_hdr::ph, sess_neg::pkt, sess_con::pkt_hdr, packet::pkt_header, PPPOE_CONNECTED, pppoe_find_svc(), PPPOE_LISTENING, PPPOE_NEWCONNECTED, PPPOE_PADM_VALUE_SIZE, PPPOE_PRIMED, PPPOE_SERVICE_NAME_SIZE, PPPOE_SNONE, pppoe_start(), PTT_AC_NAME, PTT_HOST_UNIQ, PTT_HURL, PTT_MAX_PAYL, PTT_MOTM, PTT_SRV_NAME, sess_neg::service, sess_neg::service_len, pppoe_hdr::sid, sess_con::state, pppoe_tag::tag_len, pppoe_tag::tag_type, sess_neg::timeout, pppoe_hdr::type, ng_mesg::ng_msghdr::typecookie, and pppoe_hdr::ver.

Here is the call graph for this function:

◆ ng_pppoe_shutdown()

static int ng_pppoe_shutdown ( node_p  node)
static

◆ pppoe_addsession()

static void pppoe_addsession ( sessp  sp)
static

Definition at line 558 of file ng_pppoe.c.

References sess_con::hook, NG_HOOK_NODE, NG_NODE_PRIVATE, SESSHASH, and sess_con::Session_ID.

Referenced by ng_pppoe_rcvdata_ether().

Here is the caller graph for this function:

◆ pppoe_broadcast_padi()

static int pppoe_broadcast_padi ( node_p  node,
struct mbuf *  m0 
)
static

Definition at line 477 of file ng_pppoe.c.

References sess_con::hook, NG_NODE_PRIVATE, and NG_SEND_DATA_ONLY.

Referenced by ng_pppoe_rcvdata_ether().

Here is the caller graph for this function:

◆ pppoe_delsession()

static void pppoe_delsession ( sessp  sp)
static

Definition at line 570 of file ng_pppoe.c.

References sess_con::hook, NG_HOOK_NODE, NG_NODE_PRIVATE, SESSHASH, and sess_con::Session_ID.

Referenced by ng_pppoe_disconnect().

Here is the caller graph for this function:

◆ pppoe_find_svc()

static hook_p pppoe_find_svc ( node_p  node,
const char *  svc_name,
int  svc_len 
)
static

Definition at line 501 of file ng_pppoe.c.

References datatag::data, sess_con::hook, sess_con::neg, NG_NODE_PRIVATE, sess_neg::service, and sess_neg::service_len.

Referenced by ng_pppoe_rcvmsg().

Here is the caller graph for this function:

◆ pppoe_findcookie()

static hook_p pppoe_findcookie ( node_p  node,
const struct pppoe_tag tag 
)
static

Definition at line 629 of file ng_pppoe.c.

References uniq::bytes, NG_HOOK_PRIVATE, and uniq::pointer.

Referenced by ng_pppoe_rcvdata_ether().

Here is the caller graph for this function:

◆ pppoe_findsession()

static sessp pppoe_findsession ( priv_p  privp,
const struct pppoe_full_hdr wh 
)
static

Definition at line 582 of file ng_pppoe.c.

References pppoe_full_hdr::eh, sess_con::hook, pppoe_full_hdr::ph, sess_con::pkt_hdr, SESSHASH, sess_con::Session_ID, and pppoe_hdr::sid.

Referenced by ng_pppoe_rcvdata_ether().

Here is the caller graph for this function:

◆ pppoe_finduniq()

static hook_p pppoe_finduniq ( node_p  node,
const struct pppoe_tag tag 
)
static

Definition at line 604 of file ng_pppoe.c.

References datatag::data, sess_neg::host_uniq, sess_neg::host_uniq_len, sess_con::neg, NG_HOOK_PRIVATE, and pppoe_tag::tag_len.

Referenced by ng_pppoe_rcvdata_ether().

Here is the caller graph for this function:

◆ pppoe_getnewsession()

static uint16_t pppoe_getnewsession ( sessp  sp)
static

Definition at line 522 of file ng_pppoe.c.

References sess_con::hook, NG_HOOK_NODE, NG_NODE_PRIVATE, SESSHASH, and sess_con::Session_ID.

Referenced by ng_pppoe_rcvdata_ether().

Here is the caller graph for this function:

◆ pppoe_match_svc()

static hook_p pppoe_match_svc ( node_p  node,
const struct pppoe_tag tag 
)
static

Definition at line 440 of file ng_pppoe.c.

References datatag::data, sess_con::hook, sess_con::neg, NG_NODE_PRIVATE, sess_neg::service, sess_neg::service_len, and pppoe_tag::tag_len.

Referenced by ng_pppoe_rcvdata_ether().

Here is the caller graph for this function:

◆ pppoe_send_event()

static int pppoe_send_event ( sessp  sp,
enum cmd  cmdid 
)
static

◆ pppoe_start()

◆ pppoe_ticker()

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

◆ scan_tags()

static const struct pppoe_tag * scan_tags ( sessp  sp,
const struct pppoe_hdr ph 
)
static

Definition at line 2149 of file ng_pppoe.c.

References insert_tag(), next_tag(), PTT_AC_COOKIE, PTT_AC_NAME, PTT_EOL, PTT_GEN_ERR, PTT_HOST_UNIQ, PTT_HURL, PTT_MAX_PAYL, PTT_MOTM, PTT_RELAY_SID, PTT_SRV_ERR, PTT_SRV_NAME, PTT_SYS_ERR, PTT_VENDOR, sess_con::Session_ID, pppoe_tag::tag_len, and pppoe_tag::tag_type.

Referenced by ng_pppoe_rcvdata(), and ng_pppoe_rcvdata_ether().

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

◆ send_acname()

static int send_acname ( sessp  sp,
const struct pppoe_tag tag 
)
static

◆ send_hurl()

static int send_hurl ( sessp  sp,
const struct pppoe_tag tag 
)
static

◆ send_maxp()

static int send_maxp ( sessp  sp,
const struct pppoe_tag tag 
)
static

◆ send_motm()

static int send_motm ( sessp  sp,
const struct pppoe_tag tag 
)
static

◆ send_sessionid()

static int send_sessionid ( sessp  sp)
static

Definition at line 1322 of file ng_pppoe.c.

References sess_con::creator, ng_mesg::data, sess_con::hook, NG_HOOK_NODE, NG_MKMESSAGE, NG_SEND_MSG_ID, NGM_PPPOE_COOKIE, NGM_PPPOE_SESSIONID, and sess_con::Session_ID.

Referenced by ng_pppoe_rcvdata_ether().

Here is the caller graph for this function:

Variable Documentation

◆ ng_pppoe_cmds

const struct ng_cmdlist ng_pppoe_cmds[]
static

Definition at line 101 of file ng_pppoe.c.

◆ ng_pppoe_connect

ng_connect_t ng_pppoe_connect
static

Definition at line 78 of file ng_pppoe.c.

◆ ng_pppoe_constructor

ng_constructor_t ng_pppoe_constructor
static

Definition at line 74 of file ng_pppoe.c.

◆ ng_pppoe_disconnect

ng_disconnect_t ng_pppoe_disconnect
static

Definition at line 82 of file ng_pppoe.c.

◆ ng_pppoe_newhook

ng_newhook_t ng_pppoe_newhook
static

Definition at line 77 of file ng_pppoe.c.

◆ ng_pppoe_rcvdata

ng_rcvdata_t ng_pppoe_rcvdata
static

Definition at line 79 of file ng_pppoe.c.

◆ ng_pppoe_rcvdata_debug

ng_rcvdata_t ng_pppoe_rcvdata_debug
static

Definition at line 81 of file ng_pppoe.c.

Referenced by ng_pppoe_newhook().

◆ ng_pppoe_rcvdata_ether

ng_rcvdata_t ng_pppoe_rcvdata_ether
static

Definition at line 80 of file ng_pppoe.c.

Referenced by ng_pppoe_newhook().

◆ ng_pppoe_rcvmsg

ng_rcvmsg_t ng_pppoe_rcvmsg
static

Definition at line 75 of file ng_pppoe.c.

◆ ng_pppoe_shutdown

ng_shutdown_t ng_pppoe_shutdown
static

Definition at line 76 of file ng_pppoe.c.

◆ ng_pppoe_sts_state_type

const struct ng_parse_type ng_pppoe_sts_state_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_pppoe_sts_type_fields[]
Definition: ng_pppoe.c:94

Definition at line 95 of file ng_pppoe.c.

◆ ng_pppoe_sts_type_fields

const struct ng_parse_struct_field ng_pppoe_sts_type_fields[] = NG_PPPOE_STS_TYPE_INFO
static

Definition at line 93 of file ng_pppoe.c.

◆ ngpppoe_init_data_state_type

const struct ng_parse_type ngpppoe_init_data_state_type
static
Initial value:
= {
}
static const struct ng_parse_struct_field ngpppoe_init_data_type_fields[]
Definition: ng_pppoe.c:86

Definition at line 87 of file ng_pppoe.c.

◆ ngpppoe_init_data_type_fields

const struct ng_parse_struct_field ngpppoe_init_data_type_fields[] = NG_PPPOE_INIT_DATA_TYPE_INFO
static

Definition at line 85 of file ng_pppoe.c.

◆ typestruct

struct ng_type typestruct
static
Initial value:
= {
.version = NG_ABI_VERSION,
.constructor = ng_pppoe_constructor,
.rcvmsg = ng_pppoe_rcvmsg,
.shutdown = ng_pppoe_shutdown,
.newhook = ng_pppoe_newhook,
.connect = ng_pppoe_connect,
.rcvdata = ng_pppoe_rcvdata,
.disconnect = ng_pppoe_disconnect,
.cmdlist = ng_pppoe_cmds,
}
#define NG_ABI_VERSION
Definition: netgraph.h:77
static ng_connect_t ng_pppoe_connect
Definition: ng_pppoe.c:78
static ng_shutdown_t ng_pppoe_shutdown
Definition: ng_pppoe.c:76
static const struct ng_cmdlist ng_pppoe_cmds[]
Definition: ng_pppoe.c:101
static ng_disconnect_t ng_pppoe_disconnect
Definition: ng_pppoe.c:82
static ng_constructor_t ng_pppoe_constructor
Definition: ng_pppoe.c:74
static ng_rcvmsg_t ng_pppoe_rcvmsg
Definition: ng_pppoe.c:75
static ng_newhook_t ng_pppoe_newhook
Definition: ng_pppoe.c:77
static ng_rcvdata_t ng_pppoe_rcvdata
Definition: ng_pppoe.c:79
#define NG_PPPOE_NODE_TYPE
Definition: ng_pppoe.h:51

Definition at line 197 of file ng_pppoe.c.