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