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