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