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. 60This node does not yet support 61the 62.Dv NGM_TEXT_STATUS 63control message. 64.Sh HOOKS 65This node type supports the following hooks: 66.Pp 67.Bl -tag -width foobarbaz 68.It Dv ethernet 69The hook that should normally be connected to an Ethernet node. 70.It Dv debug 71Presently no use. 72.It Dv [unspecified] 73Any other name is assumed to be a session hook that will be connected to 74a PPP client agent, or a ppp server agent. 75.El 76.Sh CONTROL MESSAGES 77This node type supports the generic control messages, plus the following: 78.Bl -tag -width foo 79.It Dv NGM_PPPOE_GET_STATUS 80This command returns status information in a 81.Dv "struct ngpppoestat" : 82.Bd -literal -offset 4n 83struct ngpppoestat { 84 u_int packets_in; /* packets in from ethernet */ 85 u_int packets_out; /* packets out towards ethernet */ 86}; 87.Ed 88.It Dv NGM_TEXT_STATUS 89This generic message returns is a human-readable version of the node status. 90(not yet) 91.It Dv NGM_PPPOE_CONNECT 92Tell a nominated newly created hook that it's session should enter 93the state machine in a manner to become a client. 94It must be newly created and 95a service name can be given as an argument. It is legal to specify a zero length 96service name. 97This is common on some DSL setups. A session request packet 98will be broadcast on the Ethernet. 99This command uses the 100.Dv ngpppoe_init_data 101structure shown below. 102.It Dv NGM_PPPOE_LISTEN 103Tell a nominated newly created hook that it's session should enter 104the state machine in a manner to become a server listener. 105The argument 106given is the name of the service to listen on behalf of 107a zero length service length will match all requests for service. 108A matching service request 109packet will be passed unmodified back to the process responsible 110for starting the service. 111It can then examine it and pass it on to 112the session that is started to answer the request. 113This command uses the 114.Dv ngpppoe_init_data 115structure shown below. 116.It Dv NGM_PPPOE_OFFER 117Tell a nominated newly created hook that it's session should enter 118the state machine in a manner to become a server. 119The argument given is the name of the service to offer. 120A zero length service 121is legal. 122The State machine will progress to a state where it will await 123a request packet to be forwarded to it from the startup server, 124which in turn probably received it from a LISTEN mode hook ( see above). 125This is so 126that information that is required for the session that is embedded in 127the original session request packet, is made available to the state machine 128that eventually answers the request. 129When the Session request packet is 130received, the session negotiation will proceed. 131This command uses the 132.Dv ngpppoe_init_data 133structure shown below. 134.Pp 135The three commands above use a common data structure: 136.Bd -literal -offset 4n 137struct ngpppoe_init_data { 138 char hook[NG_HOOKLEN + 1]; /* hook to monitor on */ 139 u_int16_t data_len; /* service name length */ 140 char data[0]; /* init data goes here */ 141}; 142.Ed 143.It Dv NGM_PPPOE_SUCCESS 144This command is sent to the node that started this session with one of the 145above messages, and reports a state change. 146This message reports successful Session negotiation. 147It uses the structure shown below, and 148reports back the hook name corresponding to the successful session. 149.It Dv NGM_NGM_PPPOE_FAIL 150This command is sent to the node that started this session with one of the 151above messages, and reports a state change. 152This message reports failed Session negotiation. 153It uses the structure shown below, and 154reports back the hook name corresponding to the failed session. 155The hook will probably have been removed immediately after sending this message 156.It Dv NGM_NGM_PPPOE_CLOSE 157This command is sent to the node that started this session with one of the 158above messages, and reports a state change. This message reports 159a request to close a session. 160It uses the structure shown below, and 161reports back the hook name corresponding to the closed session. 162The hook will probably have been removed immediately after sending this 163message. 164At present this message is not yet used and a 'failed' message 165will be received at closure instead. 166.It Dv NGM_PPPOE_ACNAME 167This command is sent to the node that started this session with one of the 168above messages, and reports the Access Concentrator Name. 169.El 170.Pp 171The four commands above use a common data structure: 172.Bd -literal -offset 4n 173struct ngpppoe_sts { 174 char hook[NG_HOOKLEN + 1]; /* hook associated with event session */ 175}; 176.Ed 177.Sh SHUTDOWN 178This node shuts down upon receipt of a 179.Dv NGM_SHUTDOWN 180control message, when all session have been disconnected or when the 181.Dv ethernet 182hook is disconnected. 183.Sh SYSCTLs 184If you are one of the unfortunate people who have an ISP that 185uses some "pppoe" equipment from (I believe) 3com, and who have to 186use a different ethertype on pppoe packets 187(hey why not change it from the standard for 188no reason?) then after you have kldloaded or compiled in your pppoe node, 189you may have to do the following sysctl: 190.Bd -literal 191(kldload netgraph) 192(kldload ng_pppoe) 193sysctl net.graph.stupid_isp=1 194.Ed 195.Pp 196to enable the alternate ethertypes. Then phone your ISP and ask them 197why you need to set option "stupid_isp" for you to be able to connect. 198.Sh EXAMPLES 199The following code uses 200.Dv libnetgraph 201to set up a 202.Nm 203node and connect it to both a socket node and an Ethernet node. 204It can handle the case of when a 205.Nm 206node is already attached to the Ethernet. 207It then starts a client session. 208.Bd -literal 209#include <stdio.h> 210#include <stdlib.h> 211#include <string.h> 212#include <ctype.h> 213#include <unistd.h> 214#include <sysexits.h> 215#include <errno.h> 216#include <err.h> 217 218#include <sys/types.h> 219#include <sys/socket.h> 220#include <sys/select.h> 221#include <net/ethernet.h> 222 223#include <netgraph.h> 224#include <netgraph/ng_ether.h> 225#include <netgraph/ng_pppoe.h> 226#include <netgraph/ng_socket.h> 227static int setup(char *ethername, char *service, char *sessname, 228 int *dfd, int *cfd); 229 230int 231main() 232{ 233 int fd1, fd2; 234 setup("xl0", NULL, "fred", &fd1, &fd2); 235 sleep (30); 236} 237 238static int 239setup(char *ethername, char *service, char *sessname, 240 int *dfd, int *cfd) 241{ 242 struct ngm_connect ngc; /* connect */ 243 struct ngm_mkpeer mkp; /* mkpeer */ 244 /******** nodeinfo stuff **********/ 245 u_char rbuf[2 * 1024]; 246 struct ng_mesg *const resp = (struct ng_mesg *) rbuf; 247 struct hooklist *const hlist 248 = (struct hooklist *) resp->data; 249 struct nodeinfo *const ninfo = &hlist->nodeinfo; 250 int ch, no_hooks = 0; 251 struct linkinfo *link; 252 struct nodeinfo *peer; 253 /****message to connect pppoe session*****/ 254 struct { 255 struct ngpppoe_init_data idata; 256 char service[100]; 257 } message; 258 /********tracking our little graph ********/ 259 char path[100]; 260 char source_ID[NG_NODELEN + 1]; 261 char pppoe_node_name[100]; 262 int k; 263 264 /* 265 * Create the data and control sockets 266 */ 267 if (NgMkSockNode(NULL, cfd, dfd) < 0) { 268 return (errno); 269 } 270 /* 271 * find the ether node of the name requested by asking it for 272 * it's inquiry information. 273 */ 274 if (strlen(ethername) > 16) 275 return (EINVAL); 276 sprintf(path, "%s:", ethername); 277 if (NgSendMsg(*cfd, path, NGM_GENERIC_COOKIE, 278 NGM_LISTHOOKS, NULL, 0) < 0) { 279 return (errno); 280 } 281 /* 282 * the command was accepted so it exists. Await the reply (It's 283 * almost certainly already waiting). 284 */ 285 if (NgRecvMsg(*cfd, resp, sizeof(rbuf), NULL) < 0) { 286 return (errno); 287 } 288 /** 289 * The following is available about the node: 290 * ninfo->name (string) 291 * ninfo->type (string) 292 * ninfo->id (u_int32_t) 293 * ninfo->hooks (u_int32_t) (count of hooks) 294 * check it is the correct type. and get it's ID for use 295 * with mkpeer later. 296 */ 297 if (strncmp(ninfo->type, NG_ETHER_NODE_TYPE, 298 strlen(NG_ETHER_NODE_TYPE)) != 0) { 299 return (EPROTOTYPE); 300 } 301 sprintf(source_ID, "[%08x]:", ninfo->id); 302 303 /* 304 * look for a hook already attached. 305 */ 306 for (k = 0; k < ninfo->hooks; k++) { 307 /** 308 * The following are available about each hook. 309 * link->ourhook (string) 310 * link->peerhook (string) 311 * peer->name (string) 312 * peer->type (string) 313 * peer->id (u_int32_t) 314 * peer->hooks (u_int32_t) 315 */ 316 link = &hlist->link[k]; 317 peer = &hlist->link[k].nodeinfo; 318 319 /* Ignore debug hooks */ 320 if (strcmp("debug", link->ourhook) == 0) 321 continue; 322 323 /* If the orphans hook is attached, use that */ 324 if (strcmp(NG_ETHER_HOOK_ORPHAN, 325 link->ourhook) == 0) { 326 break; 327 } 328 /* the other option is the 'divert' hook */ 329 if (strcmp("NG_ETHER_HOOK_DIVERT", 330 link->ourhook) == 0) { 331 break; 332 } 333 } 334 335 /* 336 * See if we found a hook there. 337 */ 338 if (k < ninfo->hooks) { 339 if (strcmp(peer->type, NG_PPPOE_NODE_TYPE) == 0) { 340 /* 341 * If it's a type pppoe, we skip making one 342 * ourself, but we continue, using 343 * the existing one. 344 */ 345 sprintf(pppoe_node_name, "[%08x]:", peer->id); 346 } else { 347 /* 348 * There is already someone hogging the data, 349 * return an error. Some day we'll try 350 * daisy-chaining.. 351 */ 352 return (EBUSY); 353 } 354 } else { 355 356 /* 357 * Try make a node of type pppoe against node "ID" 358 * On hook NG_ETHER_HOOK_ORPHAN. 359 */ 360 snprintf(mkp.type, sizeof(mkp.type), 361 "%s", NG_PPPOE_NODE_TYPE); 362 snprintf(mkp.ourhook, sizeof(mkp.ourhook), 363 "%s", NG_ETHER_HOOK_ORPHAN); 364 snprintf(mkp.peerhook, sizeof(mkp.peerhook), 365 "%s", NG_PPPOE_HOOK_ETHERNET); 366 /* Send message */ 367 if (NgSendMsg(*cfd, source_ID, NGM_GENERIC_COOKIE, 368 NGM_MKPEER, &mkp, sizeof(mkp)) < 0) { 369 return (errno); 370 } 371 /* 372 * Work out a name for the new node. 373 */ 374 sprintf(pppoe_node_name, "%s:%s", 375 source_ID, NG_ETHER_HOOK_ORPHAN); 376 } 377 /* 378 * We now have a pppoe node attached to the ethernet 379 * card. The Ethernet is addressed as ethername: The pppoe 380 * node is addressed as pppoe_node_name: attach to it. 381 * Connect socket node to specified node Use the same hook 382 * name on both ends of the link. 383 */ 384 snprintf(ngc.path, sizeof(ngc.path), "%s", pppoe_node_name); 385 snprintf(ngc.ourhook, sizeof(ngc.ourhook), "%s", sessname); 386 snprintf(ngc.peerhook, sizeof(ngc.peerhook), "%s", sessname); 387 388 if (NgSendMsg(*cfd, ".:", NGM_GENERIC_COOKIE, 389 NGM_CONNECT, &ngc, sizeof(ngc)) < 0) { 390 return (errno); 391 } 392 /* 393 * Send it a message telling it to start up. 394 */ 395 bzero(&message, sizeof(message)); 396 snprintf(message.idata.hook, sizeof(message.idata.hook), 397 "%s", sessname); 398 if (service == NULL) { 399 message.idata.data_len = 0; 400 } else { 401 snprintf(message.idata.data, 402 sizeof(message.idata.data), "%s", service); 403 message.idata.data_len = strlen(service); 404 } 405 /* Tell session/hook to start up as a client */ 406 if (NgSendMsg(*cfd, ngc.path, 407 NGM_PPPOE_COOKIE, NGM_PPPOE_CONNECT, &message.idata, 408 sizeof(message.idata) + message.idata.data_len) < 0) { 409 return (errno); 410 } 411 return (0); 412} 413.Ed 414.Sh SEE ALSO 415.Xr netgraph 3 , 416.Xr netgraph 4 , 417.Xr ng_ppp 4 , 418.Xr ng_socket 4 , 419.Xr ngctl 8 420.Rs 421.%A L. Mamakos 422.%A K. Lidl 423.%A J. Evarts 424.%A D. Carrel 425.%A D. Simone 426.%A R. Wheeler 427.%T "A Method for transmitting PPP over Ethernet (PPPoE)" 428.%O RFC 2516 429.Re 430.Sh HISTORY 431The 432.Nm 433node type was implemented in 434.Fx 4.0 . 435.Sh AUTHORS 436.An Julian Elischer Aq julian@FreeBSD.org 437