ng_pppoe.h revision 52722
1
2/*
3 * ng_pppoe.h
4 *
5 * Copyright (c) 1996-1999 Whistle Communications, Inc.
6 * All rights reserved.
7 *
8 * Subject to the following obligations and disclaimer of warranty, use and
9 * redistribution of this software, in source or object code forms, with or
10 * without modifications are expressly permitted by Whistle Communications;
11 * provided, however, that:
12 * 1. Any and all reproductions of the source or object code must include the
13 *    copyright notice above and the following disclaimer of warranties; and
14 * 2. No rights are granted, in any manner or form, to use Whistle
15 *    Communications, Inc. trademarks, including the mark "WHISTLE
16 *    COMMUNICATIONS" on advertising, endorsements, or otherwise except as
17 *    such appears in the above copyright notice or in the software.
18 *
19 * THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND
20 * TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO
21 * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE,
22 * INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF
23 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
24 * WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY
25 * REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS
26 * SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE.
27 * IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES
28 * RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING
29 * WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
30 * PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR
31 * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY
32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34 * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY
35 * OF SUCH DAMAGE.
36 *
37 * Author: Julian Elischer <julian@whistle.com>
38 *
39 * $FreeBSD: head/sys/netgraph/ng_pppoe.h 52722 1999-11-01 00:31:14Z julian $
40 * $Whistle: ng_pppoe.h,v 1.7 1999/10/16 10:16:43 julian Exp $
41 */
42
43#ifndef _NETGRAPH_PPPOE_H_
44#define _NETGRAPH_PPPOE_H_
45
46/********************************************************************
47 * Netgraph hook constants etc.
48 ********************************************************************/
49/* Node type name. This should be unique among all netgraph node types */
50#define NG_PPPOE_NODE_TYPE	"pppoe"
51
52#define NGM_PPPOE_COOKIE		939032003
53
54/* Number of active sessions we can handle */
55#define	PPPOE_NUM_SESSIONS		16 /* for now */
56#define	PPPOE_SERVICE_NAME_SIZE		64 /* for now */
57
58/* Hook names */
59#define NG_PPPOE_HOOK_ETHERNET	"ethernet"
60#define NG_PPPOE_HOOK_PADI	"PADI"    /* default PADI requests come here */
61#define NG_PPPOE_HOOK_S_LEADIN	"service" /* PADO responses from PADI */
62#define NG_PPPOE_HOOK_C_LEADIN	"client"  /* Connect message starts this */
63#define NG_PPPOE_HOOK_DEBUG	"debug"
64
65/**********************************************************************
66 * Netgraph commands understood by this node type.
67 * FAIL, SUCCESS and CLOSE are sent by the node rather than received.
68 ********************************************************************/
69enum cmd {
70	NGM_PPPOE_SET_FLAG = 1,
71	NGM_PPPOE_CONNECT  = 2,	/* Client, Try find this service */
72	NGM_PPPOE_LISTEN   = 3,	/* Server, Await a request for this service */
73	NGM_PPPOE_OFFER    = 4,	/* Server, hook X should respond (*) */
74	NGM_PPPOE_SUCCESS  = 5,	/* State machine connected */
75	NGM_PPPOE_FAIL     = 6,	/* State machine could not connect */
76	NGM_PPPOE_CLOSE    = 7,	/* Session closed down */
77	NGM_PPPOE_GET_STATUS
78};
79
80/***********************
81 * Structures passed in the various netgraph command messages.
82 ***********************/
83/* This structure is returned by the NGM_PPPOE_GET_STATUS command */
84struct ngpppoestat {
85	u_int   packets_in;	/* packets in from ethernet */
86	u_int   packets_out;	/* packets out towards ethernet */
87};
88
89/*
90 * When this structure is accepted by the NGM_PPPOE_CONNECT command :
91 * The data field is MANDATORY.
92 * The session sends out a PADI request for the named service.
93 *
94 *
95 * When this structure is accepted by the NGM_PPPOE_WAIT command.
96 * If no service is given this is assumed to accept ALL PADI requests.
97 * This may at some time take a regexp exporession, but not yet.
98 * Matching PADI requests will be passed up the named hook.
99 *
100 *
101 * When this structure is accepted by the NGM_PPPOE_OFFER command:
102 * The AC-NAme field is set from that given and a PADI
103 * packet is expected to arrive from the session control daemon, on the
104 * named hook. The session will then issue the appropriate PADO
105 * and begin negotiation.
106 */
107struct ngpppoe_init_data {
108	char	hook[NG_HOOKLEN + 1];	/* hook to monitor on */
109	u_int16_t	data_len;		/* Length of the service name */
110	char	data[0];		/* init data goes here */
111};
112
113/*
114 * This structure is used by the asychronous success and failure messages.
115 * (to report which hook has failed or connected). The message is sent
116 * to whoever requested the connection. (close may use this too).
117 */
118struct ngpppoe_sts {
119	char	hook[NG_HOOKLEN + 1]; /* hook associated with event session */
120};
121
122
123/********************************************************************
124 * Constants and definitions specific to pppoe
125 ********************************************************************/
126
127#define PPPOE_TIMEOUT_LIMIT 64
128#define PPPOE_OFFER_TIMEOUT 16
129
130/* Codes to identify message types */
131#define PADI_CODE	0x09
132#define PADO_CODE	0x07
133#define PADR_CODE	0x19
134#define PADS_CODE	0x65
135#define PADT_CODE	0xa7
136
137/* Tag identifiers */
138#if BYTE_ORDER == BIG_ENDIAN
139#define PTT_EOL		(0x0000)
140#define PTT_SRV_NAME	(0x0101)
141#define PTT_AC_NAME	(0x0102)
142#define PTT_HOST_UNIQ	(0x0103)
143#define PTT_AC_COOKIE	(0x0104)
144#define PTT_VENDOR 	(0x0105)
145#define PTT_RELAY_SID	(0x0106)
146#define PTT_SRV_ERR     (0x0201)
147#define PTT_SYS_ERR  	(0x0202)
148#define PTT_GEN_ERR  	(0x0203)
149
150#define ETHERTYPE_PPPOE_DISC	0x8863	/* pppoe discovery packets     */
151#define ETHERTYPE_PPPOE_SESS	0x8864	/* pppoe session packets       */
152#else
153#define PTT_EOL		(0x0000)
154#define PTT_SRV_NAME	(0x0101)
155#define PTT_AC_NAME	(0x0201)
156#define PTT_HOST_UNIQ	(0x0301)
157#define PTT_AC_COOKIE	(0x0401)
158#define PTT_VENDOR 	(0x0501)
159#define PTT_RELAY_SID	(0x0601)
160#define PTT_SRV_ERR     (0x0102)
161#define PTT_SYS_ERR  	(0x0202)
162#define PTT_GEN_ERR  	(0x0302)
163
164#define ETHERTYPE_PPPOE_DISC	0x6388	/* pppoe discovery packets     */
165#define ETHERTYPE_PPPOE_SESS	0x6488	/* pppoe session packets       */
166#endif
167
168struct pppoe_tag {
169	u_int16_t tag_type;
170	u_int16_t tag_len;
171	char tag_data[0];
172}__attribute ((packed));
173
174struct pppoe_hdr{
175	u_int8_t ver:4;
176	u_int8_t type:4;
177	u_int8_t code;
178	u_int16_t sid;
179	u_int16_t length;
180	struct pppoe_tag tag[0];
181}__attribute__ ((packed));
182
183
184struct pppoe_full_hdr {
185	struct  ether_header eh;
186	struct pppoe_hdr ph;
187}__attribute__ ((packed));
188
189union	packet {
190	struct pppoe_full_hdr	pkt_header;
191	u_int8_t	bytes[2048];
192};
193
194struct datatag {
195        struct pppoe_tag hdr;
196	u_int8_t        data[PPPOE_SERVICE_NAME_SIZE];
197};
198
199
200/*
201 * Define the order in which we will place tags in packets
202 * this may be ignored
203 */
204/* for PADI */
205#define TAGI_SVC 0
206#define TAGI_HUNIQ 1
207/* for PADO */
208#define TAGO_ACNAME 0
209#define TAGO_SVC 1
210#define TAGO_COOKIE 2
211#define TAGO_HUNIQ 3
212/* for PADR */
213#define TAGR_SVC 0
214#define TAGR_HUNIQ 1
215#define TAGR_COOKIE 2
216/* for PADS */
217#define TAGS_ACNAME 0
218#define TAGS_SVC 1
219#define TAGS_COOKIE 2
220#define TAGS_HUNIQ 3
221/* for PADT */
222
223#endif /* _NETGRAPH_PPPOE_H_ */
224
225