xref: /freebsd/share/man/man4/ng_pppoe.4 (revision 9a14aa017b21c292740c00ee098195cd46642730)
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 December 27, 2007
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 sys/types.h
46.In net/ethernet.h
47.In netgraph.h
48.In netgraph/ng_pppoe.h
49.Sh DESCRIPTION
50The
51.Nm pppoe
52node type performs the PPPoE protocol.
53It is used in conjunction with the
54.Xr netgraph 4
55extensions to the Ethernet framework to divert and inject Ethernet packets
56to and from a PPP agent (which is not specified).
57.Pp
58The
59.Dv NGM_PPPOE_GET_STATUS
60control message can be used at any time to query the current status
61of the PPPoE module.
62The only statistics presently available are the
63total packet counts for input and output.
64This node does not yet support
65the
66.Dv NGM_TEXT_STATUS
67control message.
68.Sh HOOKS
69This node type supports the following hooks:
70.Bl -tag -width [unspecified]
71.It Dv ethernet
72The hook that should normally be connected to an
73.Xr ng_ether 4
74node.
75Once connected,
76.Nm
77will send a message down this hook to determine Ethernet address of
78the underlying node.
79Obtained address will be stored and then used for outgoing datagrams.
80.It Dv debug
81Presently no use.
82.It Dv [unspecified]
83Any other name is assumed to be a session hook that will be connected to
84a PPP client agent, or a PPP server agent.
85.El
86.Sh CONTROL MESSAGES
87This node type supports the generic control messages, plus the following:
88.Bl -tag -width 3n
89.It Dv NGM_PPPOE_GET_STATUS
90This command returns status information in a
91.Dv "struct ngpppoestat" :
92.Bd -literal -offset 4n
93struct ngpppoestat {
94    u_int   packets_in;     /* packets in from Ethernet */
95    u_int   packets_out;    /* packets out towards Ethernet */
96};
97.Ed
98.It Dv NGM_TEXT_STATUS
99This generic message returns a human-readable version of the node status.
100(not yet)
101.It Dv NGM_PPPOE_CONNECT
102Tell a nominated newly created hook that its session should enter
103the state machine as a client.
104It must be newly created and a service name can be given as an argument.
105It is legal to specify a zero-length service name, this is common
106on some DSL setups.
107It is possible to request a connection to a specific
108access concentrator by its name using the "AC-Name\\Service-Name" syntax.
109A session request packet will be broadcasted on the Ethernet.
110This command uses the
111.Dv ngpppoe_init_data
112structure shown below.
113.It Dv NGM_PPPOE_LISTEN
114Tell a nominated newly created hook that its session should enter
115the state machine as a server listener.
116The argument
117given is the name of the service to listen for.
118A zero-length service name will match all requests for service.
119A matching service request
120packet will be passed unmodified back to the process responsible
121for starting the service.
122It can then examine it and pass it on to
123the session that is started to answer the request.
124This command uses the
125.Dv ngpppoe_init_data
126structure shown below.
127.It Dv NGM_PPPOE_OFFER
128Tell a nominated newly created hook that its session should enter
129the state machine as a server.
130The argument given is the name of the service to offer.
131A zero-length service
132is legal.
133The State machine will progress to a state where it will await
134a request packet to be forwarded to it from the startup server,
135which in turn probably received it from a LISTEN mode hook (see above).
136This is so
137that information that is required for the session that is embedded in
138the original session request packet, is made available to the state machine
139that eventually answers the request.
140When the Session request packet is
141received, the session negotiation will proceed.
142This command uses the
143.Dv ngpppoe_init_data
144structure shown below.
145.El
146.Pp
147The three commands above use a common data structure:
148.Bd -literal -offset 4n
149struct ngpppoe_init_data {
150    char       hook[NG_HOOKSIZ];       /* hook to monitor on */
151    u_int16_t  data_len;               /* service name length */
152    char       data[0];                /* init data goes here */
153};
154.Ed
155.Bl -tag -width 3n
156.It Dv NGM_PPPOE_SUCCESS
157This command is sent to the node that started this session with one of the
158above messages, and reports a state change.
159This message reports successful Session negotiation.
160It uses the structure shown below, and
161reports back the hook name corresponding to the successful session.
162.It Dv NGM_PPPOE_FAIL
163This command is sent to the node that started this session with one of the
164above messages, and reports a state change.
165This message reports failed Session negotiation.
166It uses the structure shown below, and
167reports back the hook name corresponding to the failed session.
168The hook will probably have been removed immediately after sending this
169message.
170.It Dv NGM_PPPOE_CLOSE
171This command is sent to the node that started this session with one of the
172above messages, and reports a state change.
173This message reports a request to close a session.
174It uses the structure shown below, and
175reports back the hook name corresponding to the closed session.
176The hook will probably have been removed immediately after sending this
177message.
178At present this message is not yet used and a
179.Dv NGM_PPPOE_FAIL
180message
181will be received at closure instead.
182.It Dv NGM_PPPOE_ACNAME
183This command is sent to the node that started this session with one of the
184above messages, and reports the Access Concentrator Name.
185.El
186.Pp
187The four commands above use a common data structure:
188.Bd -literal -offset 4n
189struct ngpppoe_sts {
190    char    hook[NG_HOOKSIZ];    /* hook associated with event session */
191};
192.Ed
193.Bl -tag -width 3n
194.It Dv NGM_PPPOE_GETMODE
195This command returns the current compatibility mode of the node
196as a string.
197.Tn ASCII
198form of this message is
199.Qq Li pppoe_getmode .
200The following keywords can be returned:
201.Bl -tag -width 3n
202.It Qq standard
203The node operates according to RFC 2516.
204.It Qq 3Com
205When
206.Nm
207is a PPPoE client, it initiates a session encapsulating packets into
208incorrect 3Com ethertypes.
209This compatibility option does not affect server mode.
210In server mode
211.Nm
212supports both modes simultaneously, depending on the ethertype, the
213client used when connecting.
214.It Qq D-Link
215When
216.Nm
217is a PPPoE server serving only specific Service-Name(s), it will respond
218to a PADI requests with empty Service-Name tag, returning all available
219Service-Name(s) on node.
220This option is necessary for compatibility with D-Link DI-614+ and DI-624+
221SOHO routers as clients, when serving only specific Service-Name.
222This compatibility option does not affect client mode.
223.El
224.It Dv NGM_PPPOE_SETMODE
225Configure node to the specified mode.
226The string argument is required.
227This command understands the same keywords that are returned by the
228.Dv NGM_PPPOE_GETMODE
229command.
230.Tn ASCII
231form of this message is
232.Qq Li pppoe_setmode .
233For example, the following command will configure the node to initiate
234the next session in the proprietary 3Com mode:
235.Bd -literal -offset indent
236ngctl msg fxp0:orphans pppoe_setmode '"3Com"'
237.Ed
238.It Dv NGM_PPPOE_SETENADDR
239Set the node Ethernet address for outgoing datagrams.
240This message is important when a node has failed to obtain an Ethernet
241address from its peer on the
242.Dv ethernet
243hook, or when user wants to override this address with another one.
244.Tn ASCII
245form of this message is
246.Qq Li setenaddr .
247.El
248.Sh SHUTDOWN
249This node shuts down upon receipt of a
250.Dv NGM_SHUTDOWN
251control message, when all session have been disconnected or when the
252.Dv ethernet
253hook is disconnected.
254.Sh EXAMPLES
255The following code uses
256.Dv libnetgraph
257to set up a
258.Nm
259node and connect it to both a socket node and an Ethernet node.
260It can handle the case of when a
261.Nm
262node is already attached to the Ethernet.
263It then starts a client session.
264.Bd -literal
265#include <stdio.h>
266#include <stdlib.h>
267#include <string.h>
268#include <ctype.h>
269#include <unistd.h>
270#include <sysexits.h>
271#include <errno.h>
272#include <err.h>
273
274#include <sys/types.h>
275#include <sys/socket.h>
276#include <sys/select.h>
277#include <net/ethernet.h>
278
279#include <netgraph.h>
280#include <netgraph/ng_ether.h>
281#include <netgraph/ng_pppoe.h>
282#include <netgraph/ng_socket.h>
283static int setup(char *ethername, char *service, char *sessname,
284				int *dfd, int *cfd);
285
286int
287main()
288{
289	int  fd1, fd2;
290	setup("xl0", NULL, "fred", &fd1, &fd2);
291	sleep (30);
292}
293
294static int
295setup(char *ethername, char *service, char *sessname,
296			int *dfd, int *cfd)
297{
298	struct ngm_connect ngc;	/* connect */
299	struct ngm_mkpeer mkp;	/* mkpeer */
300	/******** nodeinfo stuff **********/
301	u_char          rbuf[2 * 1024];
302	struct ng_mesg *const resp = (struct ng_mesg *) rbuf;
303	struct hooklist *const hlist
304			= (struct hooklist *) resp->data;
305	struct nodeinfo *const ninfo = &hlist->nodeinfo;
306	int             ch, no_hooks = 0;
307	struct linkinfo *link;
308	struct nodeinfo *peer;
309	/****message to connect PPPoE session*****/
310	struct {
311		struct ngpppoe_init_data idata;
312		char            service[100];
313	}               message;
314	/********tracking our little graph ********/
315	char            path[100];
316	char            source_ID[NG_NODESIZ];
317	char            pppoe_node_name[100];
318	int             k;
319
320	/*
321	 * Create the data and control sockets
322	 */
323	if (NgMkSockNode(NULL, cfd, dfd) < 0) {
324		return (errno);
325	}
326	/*
327	 * find the ether node of the name requested by asking it for
328	 * it's inquiry information.
329	 */
330	if (strlen(ethername) > 16)
331		return (EINVAL);
332	sprintf(path, "%s:", ethername);
333	if (NgSendMsg(*cfd, path, NGM_GENERIC_COOKIE,
334		      NGM_LISTHOOKS, NULL, 0) < 0) {
335		return (errno);
336	}
337	/*
338	 * the command was accepted so it exists. Await the reply (It's
339	 * almost certainly already waiting).
340	 */
341	if (NgRecvMsg(*cfd, resp, sizeof(rbuf), NULL) < 0) {
342		return (errno);
343	}
344	/**
345	 * The following is available about the node:
346	 * ninfo->name		(string)
347	 * ninfo->type		(string)
348	 * ninfo->id		(u_int32_t)
349	 * ninfo->hooks		(u_int32_t) (count of hooks)
350	 * check it is the correct type. and get it's ID for use
351	 * with mkpeer later.
352	 */
353	if (strncmp(ninfo->type, NG_ETHER_NODE_TYPE,
354		    strlen(NG_ETHER_NODE_TYPE)) != 0) {
355		return (EPROTOTYPE);
356	}
357	sprintf(source_ID, "[%08x]:", ninfo->id);
358
359	/*
360	 * look for a hook already attached.
361	 */
362	for (k = 0; k < ninfo->hooks; k++) {
363		/**
364		 * The following are available about each hook.
365		 * link->ourhook	(string)
366		 * link->peerhook	(string)
367		 * peer->name		(string)
368		 * peer->type		(string)
369		 * peer->id		(u_int32_t)
370		 * peer->hooks		(u_int32_t)
371		 */
372		link = &hlist->link[k];
373		peer = &hlist->link[k].nodeinfo;
374
375		/* Ignore debug hooks */
376		if (strcmp("debug", link->ourhook) == 0)
377			continue;
378
379		/* If the orphans hook is attached, use that */
380		if (strcmp(NG_ETHER_HOOK_ORPHAN,
381		    link->ourhook) == 0) {
382			break;
383		}
384		/* the other option is the 'divert' hook */
385		if (strcmp("NG_ETHER_HOOK_DIVERT",
386		    link->ourhook) == 0) {
387			break;
388		}
389	}
390
391	/*
392	 * See if we found a hook there.
393	 */
394	if (k < ninfo->hooks) {
395		if (strcmp(peer->type, NG_PPPOE_NODE_TYPE) == 0) {
396			/*
397			 * If it's a type PPPoE, we skip making one
398			 * ourself, but we continue, using
399			 * the existing one.
400			 */
401			sprintf(pppoe_node_name, "[%08x]:", peer->id);
402		} else {
403			/*
404			 * There is already someone hogging the data,
405			 * return an error. Some day we'll try
406			 * daisy-chaining..
407			 */
408			return (EBUSY);
409		}
410	} else {
411
412		/*
413		 * Try make a node of type PPPoE against node "ID"
414		 * On hook NG_ETHER_HOOK_ORPHAN.
415		 */
416		snprintf(mkp.type, sizeof(mkp.type),
417			 "%s", NG_PPPOE_NODE_TYPE);
418		snprintf(mkp.ourhook, sizeof(mkp.ourhook),
419			 "%s", NG_ETHER_HOOK_ORPHAN);
420		snprintf(mkp.peerhook, sizeof(mkp.peerhook),
421			 "%s", NG_PPPOE_HOOK_ETHERNET);
422		/* Send message */
423		if (NgSendMsg(*cfd, source_ID, NGM_GENERIC_COOKIE,
424			      NGM_MKPEER, &mkp, sizeof(mkp)) < 0) {
425			return (errno);
426		}
427		/*
428		 * Work out a name for the new node.
429		 */
430		sprintf(pppoe_node_name, "%s:%s",
431			source_ID, NG_ETHER_HOOK_ORPHAN);
432	}
433	/*
434	 * We now have a PPPoE node attached to the Ethernet
435	 * card. The Ethernet is addressed as ethername: The PPPoE
436	 * node is addressed as pppoe_node_name: attach to it.
437	 * Connect socket node to specified node Use the same hook
438	 * name on both ends of the link.
439	 */
440	snprintf(ngc.path, sizeof(ngc.path), "%s", pppoe_node_name);
441	snprintf(ngc.ourhook, sizeof(ngc.ourhook), "%s", sessname);
442	snprintf(ngc.peerhook, sizeof(ngc.peerhook), "%s", sessname);
443
444	if (NgSendMsg(*cfd, ".:", NGM_GENERIC_COOKIE,
445		      NGM_CONNECT, &ngc, sizeof(ngc)) < 0) {
446		return (errno);
447	}
448
449#ifdef	NONSTANDARD
450	/*
451	 * In some cases we are speaking to 3Com hardware, so
452	 * configure node to non-standard mode.
453	 */
454	if (NgSendMsg(*cfd, ngc.path, NGM_PPPOE_COOKIE,
455			NGM_PPPOE_SETMODE, NG_PPPOE_NONSTANDARD,
456			strlen(NG_PPPOE_NONSTANDARD) + 1) == -1) {
457		return (errno);
458	}
459#endif
460
461	/*
462	 * Send it a message telling it to start up.
463	 */
464	bzero(&message, sizeof(message));
465	snprintf(message.idata.hook, sizeof(message.idata.hook),
466				"%s", sessname);
467	if (service == NULL) {
468		message.idata.data_len = 0;
469	} else {
470		snprintf(message.idata.data,
471			 sizeof(message.idata.data), "%s", service);
472		message.idata.data_len = strlen(service);
473	}
474	/* Tell session/hook to start up as a client */
475	if (NgSendMsg(*cfd, ngc.path,
476		      NGM_PPPOE_COOKIE, NGM_PPPOE_CONNECT, &message.idata,
477		      sizeof(message.idata) + message.idata.data_len) < 0) {
478		return (errno);
479	}
480	return (0);
481}
482.Ed
483.Sh SEE ALSO
484.Xr netgraph 3 ,
485.Xr netgraph 4 ,
486.Xr ng_ether 4 ,
487.Xr ng_ppp 4 ,
488.Xr ng_socket 4 ,
489.Xr ngctl 8 ,
490.Xr ppp 8
491.Rs
492.%A L. Mamakos
493.%A K. Lidl
494.%A J. Evarts
495.%A D. Carrel
496.%A D. Simone
497.%A R. Wheeler
498.%T "A Method for transmitting PPP over Ethernet (PPPoE)"
499.%O RFC 2516
500.Re
501.Sh HISTORY
502The
503.Nm
504node type was implemented in
505.Fx 4.0 .
506.Sh AUTHORS
507.An Julian Elischer Aq julian@FreeBSD.org
508