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