1.\" Copyright (c) 1996-1999 Whistle Communications, Inc. 2.\" All rights reserved. 3.\" 4.\" Subject to the following obligations and disclaimer of warranty, use and 5.\" redistribution of this software, in source or object code forms, with or 6.\" without modifications are expressly permitted by Whistle Communications; 7.\" provided, however, that: 8.\" 1. Any and all reproductions of the source or object code must include the 9.\" copyright notice above and the following disclaimer of warranties; and 10.\" 2. No rights are granted, in any manner or form, to use Whistle 11.\" Communications, Inc. trademarks, including the mark "WHISTLE 12.\" COMMUNICATIONS" on advertising, endorsements, or otherwise except as 13.\" such appears in the above copyright notice or in the software. 14.\" 15.\" THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND 16.\" TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO 17.\" REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE, 18.\" INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF 19.\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. 20.\" WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY 21.\" REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS 22.\" SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE. 23.\" IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES 24.\" RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING 25.\" WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 26.\" PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR 27.\" SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY 28.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30.\" THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY 31.\" OF SUCH DAMAGE. 32.\" 33.\" Author: Archie Cobbs <archie@FreeBSD.org> 34.\" 35.\" $FreeBSD$ 36.\" $Whistle: ng_pppoe.8,v 1.1 1999/01/25 23:46:27 archie Exp $ 37.\" 38.Dd October 28, 1999 39.Dt NG_PPPOE 4 40.Os 41.Sh NAME 42.Nm ng_pppoe 43.Nd RFC 2516 PPPOE protocol netgraph node type 44.Sh SYNOPSIS 45.In net/ethernet.h 46.In netgraph/ng_pppoe.h 47.Sh DESCRIPTION 48The 49.Nm pppoe 50node type performs the PPPoE protocol. It is used in conjunction with the 51.Xr netgraph 4 52extensions to the Ethernet framework to divert and inject Ethernet packets 53to and from a PPP agent (which is not specified). 54.Pp 55The 56.Dv NGM_PPPOE_GET_STATUS 57control message can be used at any time to query the current status 58of the PPPOE module. The only statistics presently available are the 59total packet counts for input and output. This node does not yet support 60the 61.Dv NGM_TEXT_STATUS 62control message. 63.Sh HOOKS 64This node type supports the following hooks: 65.Pp 66.Bl -tag -width foobarbaz 67.It Dv ethernet 68The hook that should normally be connected to an Ethernet node. 69.It Dv debug 70Presently no use. 71.It Dv [unspecified] 72Any other name is assumed to be a session hook that will be connected to 73a PPP client agent, or a ppp server agent. 74.El 75.Sh CONTROL MESSAGES 76This node type supports the generic control messages, plus the following: 77.Bl -tag -width foo 78.It Dv NGM_PPPOE_GET_STATUS 79This command returns status information in a 80.Dv "struct ngpppoestat" : 81.Bd -literal -offset 4n 82struct ngpppoestat { 83 u_int packets_in; /* packets in from ethernet */ 84 u_int packets_out; /* packets out towards ethernet */ 85}; 86.Ed 87.It Dv NGM_TEXT_STATUS 88This generic message returns is a human-readable version of the node status. 89(not yet) 90.It Dv NGM_PPPOE_CONNECT 91Tell a nominated newly created hook that it's session should enter 92the state machine in a manner to become a client. It must be newly created and 93a service name can be given as an argument. It is legal to specify a zero length 94service name. This is common on some DSL setups. A session request packet 95will be broadcast on the Ethernet. 96This command uses the 97.Dv ngpppoe_init_data 98structure shown below. 99.It Dv NGM_PPPOE_LISTEN 100Tell a nominated newly created hook that it's session should enter 101the state machine in a manner to become a server listener. The argument 102given is the name of the service to listen on behalf of. A zero length service 103length will match all requests for service. A matching service request 104packet will be passed unmodified back to the process responsible 105for starting the service. It can then examine it and pass it on to 106the session that is started to answer the request. 107This command uses the 108.Dv ngpppoe_init_data 109structure shown below. 110.It Dv NGM_PPPOE_OFFER 111Tell a nominated newly created hook that it's session should enter 112the state machine in a manner to become a server. The argument 113given is the name of the service to offer. A zero length service 114is legal. The State machine will progress to a state where it will await 115a request packet to be forwarded to it from the startup server, 116which in turn probably received it from a LISTEN mode hook ( see above). 117This is so 118that information that is required for the session that is embedded in 119the original session request packet, is made available to the state machine 120that eventually answers the request. When the Session request packet is 121received, the session negotiation will proceed. 122This command uses the 123.Dv ngpppoe_init_data 124structure shown below. 125.Pp 126The three commands above use a common data structure: 127.Bd -literal -offset 4n 128struct ngpppoe_init_data { 129 char hook[NG_HOOKLEN + 1]; /* hook to monitor on */ 130 u_int16_t data_len; /* service name length */ 131 char data[0]; /* init data goes here */ 132}; 133.Ed 134.It Dv NGM_PPPOE_SUCCESS 135This command is sent to the node that started this session with one of the 136above messages, and reports a state change. This message reports 137successful Session negotiation. It uses the structure shown below, and 138reports back the hook name corresponding to the successful session. 139.It Dv NGM_NGM_PPPOE_FAIL 140This command is sent to the node that started this session with one of the 141above messages, and reports a state change. This message reports 142failed Session negotiation. It uses the structure shown below, and 143reports back the hook name corresponding to the failed session. 144The hook will probably have been removed immediately after sending this message 145.It Dv NGM_NGM_PPPOE_CLOSE 146This command is sent to the node that started this session with one of the 147above messages, and reports a state change. This message reports 148a request to close a session. It uses the structure shown below, and 149reports back the hook name corresponding to the closed session. 150The hook will probably have been removed immediately after sending this 151message. At present this message is not yet used and a 'failed' message 152will be received at closure instead. 153.It Dv NGM_PPPOE_ACNAME 154This command is sent to the node that started this session with one of the 155above messages, and reports the Access Concentrator Name. 156.El 157.Pp 158The four commands above use a common data structure: 159.Bd -literal -offset 4n 160struct ngpppoe_sts { 161 char hook[NG_HOOKLEN + 1]; /* hook associated with event session */ 162}; 163.Ed 164.Sh SHUTDOWN 165This node shuts down upon receipt of a 166.Dv NGM_SHUTDOWN 167control message, when all session have been disconnected or when the 168.Dv ethernet 169hook is disconnected. 170.Sh SYSCTLs 171If you are one of the unfortunate people who have an ISP that 172uses some "pppoe" equipment from (I believe) 3com, and who have to 173use a different ethertype on pppoe packets 174(hey why not change it from the standard for 175no reason?) then after you have kldloaded or compiled in your pppoe node, 176you may have to do the following sysctl: 177.Bd -literal 178(kldload netgraph) 179(kldload ng_pppoe) 180sysctl net.graph.stupid_isp=1 181.Ed 182.Pp 183to enable the alternate ethertypes. Then phone your ISP and ask them 184why you need to set option "stupid_isp" for you to be able to connect. 185.Sh EXAMPLES 186The following code uses 187.Dv libnetgraph 188to set up a 189.Nm 190node and connect it to both a socket node and an Ethernet node. It can handle 191the case of when a 192.Nm 193node is already attached to the Ethernet. It then starts a client session. 194.Bd -literal 195#include <stdio.h> 196#include <stdlib.h> 197#include <string.h> 198#include <ctype.h> 199#include <unistd.h> 200#include <sysexits.h> 201#include <errno.h> 202#include <err.h> 203 204#include <sys/types.h> 205#include <sys/socket.h> 206#include <sys/select.h> 207#include <net/ethernet.h> 208 209#include <netgraph.h> 210#include <netgraph/ng_ether.h> 211#include <netgraph/ng_pppoe.h> 212#include <netgraph/ng_socket.h> 213static int setup(char *ethername, char *service, char *sessname, 214 int *dfd, int *cfd); 215 216int 217main() 218{ 219 int fd1, fd2; 220 setup("xl0", NULL, "fred", &fd1, &fd2); 221 sleep (30); 222} 223 224static int 225setup(char *ethername, char *service, char *sessname, 226 int *dfd, int *cfd) 227{ 228 struct ngm_connect ngc; /* connect */ 229 struct ngm_mkpeer mkp; /* mkpeer */ 230 /******** nodeinfo stuff **********/ 231 u_char rbuf[2 * 1024]; 232 struct ng_mesg *const resp = (struct ng_mesg *) rbuf; 233 struct hooklist *const hlist 234 = (struct hooklist *) resp->data; 235 struct nodeinfo *const ninfo = &hlist->nodeinfo; 236 int ch, no_hooks = 0; 237 struct linkinfo *link; 238 struct nodeinfo *peer; 239 /****message to connect pppoe session*****/ 240 struct { 241 struct ngpppoe_init_data idata; 242 char service[100]; 243 } message; 244 /********tracking our little graph ********/ 245 char path[100]; 246 char source_ID[NG_NODELEN + 1]; 247 char pppoe_node_name[100]; 248 int k; 249 250 /* 251 * Create the data and control sockets 252 */ 253 if (NgMkSockNode(NULL, cfd, dfd) < 0) { 254 return (errno); 255 } 256 /* 257 * find the ether node of the name requested by asking it for 258 * it's inquiry information. 259 */ 260 if (strlen(ethername) > 16) 261 return (EINVAL); 262 sprintf(path, "%s:", ethername); 263 if (NgSendMsg(*cfd, path, NGM_GENERIC_COOKIE, 264 NGM_LISTHOOKS, NULL, 0) < 0) { 265 return (errno); 266 } 267 /* 268 * the command was accepted so it exists. Await the reply (It's 269 * almost certainly already waiting). 270 */ 271 if (NgRecvMsg(*cfd, resp, sizeof(rbuf), NULL) < 0) { 272 return (errno); 273 } 274 /** 275 * The following is available about the node: 276 * ninfo->name (string) 277 * ninfo->type (string) 278 * ninfo->id (u_int32_t) 279 * ninfo->hooks (u_int32_t) (count of hooks) 280 * check it is the correct type. and get it's ID for use 281 * with mkpeer later. 282 */ 283 if (strncmp(ninfo->type, NG_ETHER_NODE_TYPE, 284 strlen(NG_ETHER_NODE_TYPE)) != 0) { 285 return (EPROTOTYPE); 286 } 287 sprintf(source_ID, "[%08x]:", ninfo->id); 288 289 /* 290 * look for a hook already attached. 291 */ 292 for (k = 0; k < ninfo->hooks; k++) { 293 /** 294 * The following are available about each hook. 295 * link->ourhook (string) 296 * link->peerhook (string) 297 * peer->name (string) 298 * peer->type (string) 299 * peer->id (u_int32_t) 300 * peer->hooks (u_int32_t) 301 */ 302 link = &hlist->link[k]; 303 peer = &hlist->link[k].nodeinfo; 304 305 /* Ignore debug hooks */ 306 if (strcmp("debug", link->ourhook) == 0) 307 continue; 308 309 /* If the orphans hook is attached, use that */ 310 if (strcmp(NG_ETHER_HOOK_ORPHAN, 311 link->ourhook) == 0) { 312 break; 313 } 314 /* the other option is the 'divert' hook */ 315 if (strcmp("NG_ETHER_HOOK_DIVERT", 316 link->ourhook) == 0) { 317 break; 318 } 319 } 320 321 /* 322 * See if we found a hook there. 323 */ 324 if (k < ninfo->hooks) { 325 if (strcmp(peer->type, NG_PPPOE_NODE_TYPE) == 0) { 326 /* 327 * If it's a type pppoe, we skip making one 328 * ourself, but we continue, using 329 * the existing one. 330 */ 331 sprintf(pppoe_node_name, "[%08x]:", peer->id); 332 } else { 333 /* 334 * There is already someone hogging the data, 335 * return an error. Some day we'll try 336 * daisy-chaining.. 337 */ 338 return (EBUSY); 339 } 340 } else { 341 342 /* 343 * Try make a node of type pppoe against node "ID" 344 * On hook NG_ETHER_HOOK_ORPHAN. 345 */ 346 snprintf(mkp.type, sizeof(mkp.type), 347 "%s", NG_PPPOE_NODE_TYPE); 348 snprintf(mkp.ourhook, sizeof(mkp.ourhook), 349 "%s", NG_ETHER_HOOK_ORPHAN); 350 snprintf(mkp.peerhook, sizeof(mkp.peerhook), 351 "%s", NG_PPPOE_HOOK_ETHERNET); 352 /* Send message */ 353 if (NgSendMsg(*cfd, source_ID, NGM_GENERIC_COOKIE, 354 NGM_MKPEER, &mkp, sizeof(mkp)) < 0) { 355 return (errno); 356 } 357 /* 358 * Work out a name for the new node. 359 */ 360 sprintf(pppoe_node_name, "%s:%s", 361 source_ID, NG_ETHER_HOOK_ORPHAN); 362 } 363 /* 364 * We now have a pppoe node attached to the ethernet 365 * card. The Ethernet is addressed as ethername: The pppoe 366 * node is addressed as pppoe_node_name: attach to it. 367 * Connect socket node to specified node Use the same hook 368 * name on both ends of the link. 369 */ 370 snprintf(ngc.path, sizeof(ngc.path), "%s", pppoe_node_name); 371 snprintf(ngc.ourhook, sizeof(ngc.ourhook), "%s", sessname); 372 snprintf(ngc.peerhook, sizeof(ngc.peerhook), "%s", sessname); 373 374 if (NgSendMsg(*cfd, ".:", NGM_GENERIC_COOKIE, 375 NGM_CONNECT, &ngc, sizeof(ngc)) < 0) { 376 return (errno); 377 } 378 /* 379 * Send it a message telling it to start up. 380 */ 381 bzero(&message, sizeof(message)); 382 snprintf(message.idata.hook, sizeof(message.idata.hook), 383 "%s", sessname); 384 if (service == NULL) { 385 message.idata.data_len = 0; 386 } else { 387 snprintf(message.idata.data, 388 sizeof(message.idata.data), "%s", service); 389 message.idata.data_len = strlen(service); 390 } 391 /* Tell session/hook to start up as a client */ 392 if (NgSendMsg(*cfd, ngc.path, 393 NGM_PPPOE_COOKIE, NGM_PPPOE_CONNECT, &message.idata, 394 sizeof(message.idata) + message.idata.data_len) < 0) { 395 return (errno); 396 } 397 return (0); 398} 399.Ed 400.Sh SEE ALSO 401.Xr netgraph 3 , 402.Xr netgraph 4 , 403.Xr ng_ppp 4 , 404.Xr ng_socket 4 , 405.Xr ngctl 8 406.Rs 407.%A L. Mamakos 408.%A K. Lidl 409.%A J. Evarts 410.%A D. Carrel 411.%A D. Simone 412.%A R. Wheeler 413.%T "A Method for transmitting PPP over Ethernet (PPPoE)" 414.%O RFC 2516 415.Re 416.Sh HISTORY 417The 418.Nm 419node type was implemented in 420.Fx 4.0 . 421.Sh AUTHORS 422.An Julian Elischer Aq julian@FreeBSD.org 423