ng_pppoe.h revision 96578
152419Sjulian
252419Sjulian/*
352419Sjulian * ng_pppoe.h
452419Sjulian *
552419Sjulian * Copyright (c) 1996-1999 Whistle Communications, Inc.
652419Sjulian * All rights reserved.
752419Sjulian *
852419Sjulian * Subject to the following obligations and disclaimer of warranty, use and
952419Sjulian * redistribution of this software, in source or object code forms, with or
1052419Sjulian * without modifications are expressly permitted by Whistle Communications;
1152419Sjulian * provided, however, that:
1252419Sjulian * 1. Any and all reproductions of the source or object code must include the
1352419Sjulian *    copyright notice above and the following disclaimer of warranties; and
1452419Sjulian * 2. No rights are granted, in any manner or form, to use Whistle
1552419Sjulian *    Communications, Inc. trademarks, including the mark "WHISTLE
1652419Sjulian *    COMMUNICATIONS" on advertising, endorsements, or otherwise except as
1752419Sjulian *    such appears in the above copyright notice or in the software.
1852419Sjulian *
1952419Sjulian * THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND
2052419Sjulian * TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO
2152419Sjulian * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE,
2252419Sjulian * INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF
2352419Sjulian * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
2452419Sjulian * WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY
2552419Sjulian * REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS
2652419Sjulian * SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE.
2752419Sjulian * IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES
2852419Sjulian * RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING
2952419Sjulian * WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
3052419Sjulian * PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR
3152419Sjulian * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY
3252419Sjulian * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3352419Sjulian * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
3452419Sjulian * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY
3552419Sjulian * OF SUCH DAMAGE.
3652419Sjulian *
3767506Sjulian * Author: Julian Elischer <julian@freebsd.org>
3852419Sjulian *
3952419Sjulian * $FreeBSD: head/sys/netgraph/ng_pppoe.h 96578 2002-05-14 12:32:41Z brian $
4052419Sjulian * $Whistle: ng_pppoe.h,v 1.7 1999/10/16 10:16:43 julian Exp $
4152419Sjulian */
4252419Sjulian
4352419Sjulian#ifndef _NETGRAPH_PPPOE_H_
4452419Sjulian#define _NETGRAPH_PPPOE_H_
4552419Sjulian
4652419Sjulian/********************************************************************
4752419Sjulian * Netgraph hook constants etc.
4852419Sjulian ********************************************************************/
4952419Sjulian/* Node type name. This should be unique among all netgraph node types */
5052562Sjulian#define NG_PPPOE_NODE_TYPE	"pppoe"
5152419Sjulian
5268845Sbrian#define NGM_PPPOE_COOKIE		939032003
5352419Sjulian
5452419Sjulian/* Number of active sessions we can handle */
5552419Sjulian#define	PPPOE_NUM_SESSIONS		16 /* for now */
5652419Sjulian#define	PPPOE_SERVICE_NAME_SIZE		64 /* for now */
5752419Sjulian
5852419Sjulian/* Hook names */
5952419Sjulian#define NG_PPPOE_HOOK_ETHERNET	"ethernet"
6052419Sjulian#define NG_PPPOE_HOOK_PADI	"PADI"    /* default PADI requests come here */
6152419Sjulian#define NG_PPPOE_HOOK_S_LEADIN	"service" /* PADO responses from PADI */
6252419Sjulian#define NG_PPPOE_HOOK_C_LEADIN	"client"  /* Connect message starts this */
6352419Sjulian#define NG_PPPOE_HOOK_DEBUG	"debug"
6452419Sjulian
6552419Sjulian/**********************************************************************
6652419Sjulian * Netgraph commands understood by this node type.
6790973Sbrian * FAIL, SUCCESS, CLOSE and ACNAME are sent by the node rather than received.
6852419Sjulian ********************************************************************/
6952441Sjulianenum cmd {
7052419Sjulian	NGM_PPPOE_SET_FLAG = 1,
7152419Sjulian	NGM_PPPOE_CONNECT  = 2,	/* Client, Try find this service */
7252419Sjulian	NGM_PPPOE_LISTEN   = 3,	/* Server, Await a request for this service */
7352419Sjulian	NGM_PPPOE_OFFER    = 4,	/* Server, hook X should respond (*) */
7452419Sjulian	NGM_PPPOE_SUCCESS  = 5,	/* State machine connected */
7552419Sjulian	NGM_PPPOE_FAIL     = 6,	/* State machine could not connect */
7652419Sjulian	NGM_PPPOE_CLOSE    = 7,	/* Session closed down */
7769934Sjulian	NGM_PPPOE_SERVICE  = 8,	/* additional Service to advertise (in PADO) */
7890973Sbrian	NGM_PPPOE_ACNAME   = 9,	/* AC_NAME for informational purposes */
7996578Sbrian	NGM_PPPOE_GET_STATUS = 10, /* data in/out */
8096578Sbrian	NGM_PPPOE_SESSIONID  = 11  /* Session_ID for informational purposes */
8152419Sjulian};
8252419Sjulian
8352419Sjulian/***********************
8452419Sjulian * Structures passed in the various netgraph command messages.
8552419Sjulian ***********************/
8652419Sjulian/* This structure is returned by the NGM_PPPOE_GET_STATUS command */
8752562Sjulianstruct ngpppoestat {
8852722Sjulian	u_int   packets_in;	/* packets in from ethernet */
8952722Sjulian	u_int   packets_out;	/* packets out towards ethernet */
9052419Sjulian};
9152419Sjulian
9268031Sbrian/* Keep this in sync with the above structure definition */
9368031Sbrian#define NG_PPPOESTAT_TYPE_INFO	{				\
9468031Sbrian	{							\
9568031Sbrian	  { "packets_in",	&ng_parse_uint_type	},	\
9668031Sbrian	  { "packets_out",	&ng_parse_uint_type	},	\
9768031Sbrian	  { NULL }						\
9868031Sbrian	}							\
9968031Sbrian}
10068031Sbrian
10152419Sjulian/*
10252419Sjulian * When this structure is accepted by the NGM_PPPOE_CONNECT command :
10352419Sjulian * The data field is MANDATORY.
10452419Sjulian * The session sends out a PADI request for the named service.
10552419Sjulian *
10652419Sjulian *
10769934Sjulian * When this structure is accepted by the NGM_PPPOE_LISTEN command.
10852419Sjulian * If no service is given this is assumed to accept ALL PADI requests.
10953042Sjulian * This may at some time take a regexp expression, but not yet.
11052419Sjulian * Matching PADI requests will be passed up the named hook.
11152419Sjulian *
11252419Sjulian *
11352419Sjulian * When this structure is accepted by the NGM_PPPOE_OFFER command:
11452419Sjulian * The AC-NAme field is set from that given and a PADI
11552419Sjulian * packet is expected to arrive from the session control daemon, on the
11652419Sjulian * named hook. The session will then issue the appropriate PADO
11752419Sjulian * and begin negotiation.
11852419Sjulian */
11952562Sjulianstruct ngpppoe_init_data {
12068845Sbrian	char		hook[NG_HOOKLEN + 1];	/* hook to monitor on */
12168845Sbrian	u_int16_t	data_len;		/* Length of the service name */
12268845Sbrian	char		data[0];		/* init data goes here */
12352419Sjulian};
12452419Sjulian
12568031Sbrian/* Keep this in sync with the above structure definition */
12668031Sbrian#define NG_PPPOE_INIT_DATA_TYPE_INFO	{		\
12768031Sbrian	{						\
12868031Sbrian	  { "hook",	&ng_parse_hookbuf_type	},	\
12968845Sbrian	  { "data",	&ng_parse_sizedstring_type },	\
13068031Sbrian	  { NULL }					\
13168031Sbrian	}						\
13268031Sbrian}
13368031Sbrian
13452419Sjulian/*
13552419Sjulian * This structure is used by the asychronous success and failure messages.
13652419Sjulian * (to report which hook has failed or connected). The message is sent
13752419Sjulian * to whoever requested the connection. (close may use this too).
13852419Sjulian */
13952562Sjulianstruct ngpppoe_sts {
14052419Sjulian	char	hook[NG_HOOKLEN + 1]; /* hook associated with event session */
14152419Sjulian};
14252419Sjulian
14368031Sbrian/* Keep this in sync with the above structure definition */
14468031Sbrian#define NG_PPPOE_STS_TYPE_INFO		{		\
14568031Sbrian	{						\
14668031Sbrian	  { "hook",	&ng_parse_hookbuf_type	},	\
14768031Sbrian	  { NULL }					\
14868031Sbrian	}						\
14968031Sbrian}
15052419Sjulian
15168031Sbrian
15252419Sjulian/********************************************************************
15352562Sjulian * Constants and definitions specific to pppoe
15452419Sjulian ********************************************************************/
15552419Sjulian
15652419Sjulian#define PPPOE_TIMEOUT_LIMIT 64
15752419Sjulian#define PPPOE_OFFER_TIMEOUT 16
15853979Sjulian#define PPPOE_INITIAL_TIMEOUT 2
15952419Sjulian
16052419Sjulian/* Codes to identify message types */
16152419Sjulian#define PADI_CODE	0x09
16252419Sjulian#define PADO_CODE	0x07
16352419Sjulian#define PADR_CODE	0x19
16452419Sjulian#define PADS_CODE	0x65
16552419Sjulian#define PADT_CODE	0xa7
16652419Sjulian
16752419Sjulian/* Tag identifiers */
16852419Sjulian#if BYTE_ORDER == BIG_ENDIAN
16952419Sjulian#define PTT_EOL		(0x0000)
17052419Sjulian#define PTT_SRV_NAME	(0x0101)
17152419Sjulian#define PTT_AC_NAME	(0x0102)
17252419Sjulian#define PTT_HOST_UNIQ	(0x0103)
17352419Sjulian#define PTT_AC_COOKIE	(0x0104)
17452419Sjulian#define PTT_VENDOR 	(0x0105)
17552419Sjulian#define PTT_RELAY_SID	(0x0106)
17652419Sjulian#define PTT_SRV_ERR     (0x0201)
17752419Sjulian#define PTT_SYS_ERR  	(0x0202)
17852419Sjulian#define PTT_GEN_ERR  	(0x0203)
17952419Sjulian
18052562Sjulian#define ETHERTYPE_PPPOE_DISC	0x8863	/* pppoe discovery packets     */
18152562Sjulian#define ETHERTYPE_PPPOE_SESS	0x8864	/* pppoe session packets       */
18272946Sjulian#define ETHERTYPE_PPPOE_STUPID_DISC 0x3c12 /* pppoe discovery packets 3com? */
18372946Sjulian#define ETHERTYPE_PPPOE_STUPID_SESS 0x3c13 /* pppoe session packets   3com? */
18452419Sjulian#else
18552419Sjulian#define PTT_EOL		(0x0000)
18652419Sjulian#define PTT_SRV_NAME	(0x0101)
18752419Sjulian#define PTT_AC_NAME	(0x0201)
18852419Sjulian#define PTT_HOST_UNIQ	(0x0301)
18952419Sjulian#define PTT_AC_COOKIE	(0x0401)
19052419Sjulian#define PTT_VENDOR 	(0x0501)
19152419Sjulian#define PTT_RELAY_SID	(0x0601)
19252419Sjulian#define PTT_SRV_ERR     (0x0102)
19352419Sjulian#define PTT_SYS_ERR  	(0x0202)
19452419Sjulian#define PTT_GEN_ERR  	(0x0302)
19552419Sjulian
19652562Sjulian#define ETHERTYPE_PPPOE_DISC	0x6388	/* pppoe discovery packets     */
19752562Sjulian#define ETHERTYPE_PPPOE_SESS	0x6488	/* pppoe session packets       */
19872946Sjulian#define ETHERTYPE_PPPOE_STUPID_DISC 0x123c /* pppoe discovery packets 3com? */
19972946Sjulian#define ETHERTYPE_PPPOE_STUPID_SESS 0x133c /* pppoe session packets   3com? */
20052419Sjulian#endif
20152419Sjulian
20252419Sjulianstruct pppoe_tag {
20352419Sjulian	u_int16_t tag_type;
20452419Sjulian	u_int16_t tag_len;
20552419Sjulian	char tag_data[0];
20652419Sjulian}__attribute ((packed));
20752419Sjulian
20852419Sjulianstruct pppoe_hdr{
20952419Sjulian	u_int8_t ver:4;
21052419Sjulian	u_int8_t type:4;
21152419Sjulian	u_int8_t code;
21252419Sjulian	u_int16_t sid;
21352419Sjulian	u_int16_t length;
21452419Sjulian	struct pppoe_tag tag[0];
21552419Sjulian}__attribute__ ((packed));
21652419Sjulian
21752419Sjulian
21852419Sjulianstruct pppoe_full_hdr {
21952419Sjulian	struct  ether_header eh;
22052419Sjulian	struct pppoe_hdr ph;
22152419Sjulian}__attribute__ ((packed));
22252419Sjulian
22352419Sjulianunion	packet {
22452419Sjulian	struct pppoe_full_hdr	pkt_header;
22552419Sjulian	u_int8_t	bytes[2048];
22652419Sjulian};
22752419Sjulian
22852419Sjulianstruct datatag {
22952419Sjulian        struct pppoe_tag hdr;
23052419Sjulian	u_int8_t        data[PPPOE_SERVICE_NAME_SIZE];
23152419Sjulian};
23252419Sjulian
23352419Sjulian
23452419Sjulian/*
23552419Sjulian * Define the order in which we will place tags in packets
23652419Sjulian * this may be ignored
23752419Sjulian */
23852419Sjulian/* for PADI */
23952419Sjulian#define TAGI_SVC 0
24052419Sjulian#define TAGI_HUNIQ 1
24152419Sjulian/* for PADO */
24252419Sjulian#define TAGO_ACNAME 0
24352419Sjulian#define TAGO_SVC 1
24452419Sjulian#define TAGO_COOKIE 2
24552419Sjulian#define TAGO_HUNIQ 3
24652419Sjulian/* for PADR */
24752419Sjulian#define TAGR_SVC 0
24852419Sjulian#define TAGR_HUNIQ 1
24952419Sjulian#define TAGR_COOKIE 2
25052419Sjulian/* for PADS */
25152419Sjulian#define TAGS_ACNAME 0
25252419Sjulian#define TAGS_SVC 1
25352419Sjulian#define TAGS_COOKIE 2
25452419Sjulian#define TAGS_HUNIQ 3
25552419Sjulian/* for PADT */
25652419Sjulian
25752419Sjulian#endif /* _NETGRAPH_PPPOE_H_ */
25852419Sjulian
259