xref: /dragonfly/share/man/man4/ng_pppoe.4 (revision fcce2b94)
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: src/share/man/man4/ng_pppoe.4,v 1.18.2.1 2001/12/21 09:00:51 ru Exp $
36.\" $DragonFly: src/share/man/man4/ng_pppoe.4,v 1.3 2006/05/26 19:39:39 swildner Exp $
37.\" $Whistle: ng_pppoe.8,v 1.1 1999/01/25 23:46:27 archie Exp $
38.\"
39.Dd October 28, 1999
40.Dt NG_PPPOE 4
41.Os
42.Sh NAME
43.Nm ng_pppoe
44.Nd RFC 2516 PPPOE protocol netgraph node type
45.Sh SYNOPSIS
46.In net/ethernet.h
47.In netgraph/pppoe/ng_pppoe.h
48.Sh DESCRIPTION
49The
50.Nm pppoe
51node type performs the PPPoE protocol. It 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. The only statistics presently available are the
60total packet counts for input and output.  This 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. It must be newly created and
94a service name can be given as an argument. It is legal to specify a zero length
95service name. This is common on some DSL setups. A session request packet
96will be broadcast on the Ethernet.
97This command uses the
98.Dv ngpppoe_init_data
99structure shown below.
100.It Dv NGM_PPPOE_LISTEN
101Tell a nominated newly created hook that it's session should enter
102the state machine in a manner to become a server listener. The argument
103given is the name of the service to listen on behalf of. A zero length service
104length will match all requests for service. A matching service request
105packet will be passed unmodified back to the process responsible
106for starting the service. It can then examine it and pass it on to
107the session that is started to answer the request.
108This command uses the
109.Dv ngpppoe_init_data
110structure shown below.
111.It Dv NGM_PPPOE_OFFER
112Tell a nominated newly created hook that it's session should enter
113the state machine in a manner to become a server. The argument
114given is the name of the service to offer. A zero length service
115is legal. The State machine will progress to a state where it will await
116a request packet to be forwarded to it from  the startup server,
117which in turn probably received it from a LISTEN mode hook ( see above).
118This is so
119that information that is required for the session that is embedded in
120the original session request packet, is made available to the state machine
121that eventually answers the request. When the Session request packet is
122received, the session negotiation will proceed.
123This command uses the
124.Dv ngpppoe_init_data
125structure shown below.
126.Pp
127The three commands above use a common data structure:
128.Bd -literal -offset 4n
129struct ngpppoe_init_data {
130    char       hook[NG_HOOKLEN + 1];   /* hook to monitor on */
131    u_int16_t  data_len;               /* service name length */
132    char       data[0];                /* init data goes here */
133};
134.Ed
135.It Dv NGM_PPPOE_SUCCESS
136This command is sent to the node that started this session with one of the
137above messages, and reports a state change. This message reports
138successful Session negotiation. It uses the structure shown below, and
139reports back the hook name corresponding to the successful session.
140.It Dv NGM_NGM_PPPOE_FAIL
141This command is sent to the node that started this session with one of the
142above messages, and reports a state change. This message reports
143failed Session negotiation. It uses the structure shown below, and
144reports back the hook name corresponding to the failed session.
145The hook will probably have been removed immediately after sending this message
146.It Dv NGM_NGM_PPPOE_CLOSE
147This command is sent to the node that started this session with one of the
148above messages, and reports a state change. This message reports
149a request to close a session. It uses the structure shown below, and
150reports back the hook name corresponding to the closed session.
151The hook will probably have been removed immediately after sending this
152message. At present this message is not yet used and a 'failed' message
153will be received at closure instead.
154.Pp
155The three commands above use a common data structure:
156.Bd -literal -offset 4n
157struct ngpppoe_sts {
158    char    hook[NG_HOOKLEN + 1]; /* hook associated with event session */
159};
160.Ed
161.El
162.Sh SHUTDOWN
163This node shuts down upon receipt of a
164.Dv NGM_SHUTDOWN
165control message, when all session have been disconnected or when the
166.Dv ethernet
167hook is disconnected.
168.Sh EXAMPLES
169The following code uses
170.Dv libnetgraph
171to set up a
172.Nm
173node and connect it to both a socket node and an Ethernet node. It can handle
174the case of when a
175.Nm
176node is already attached to the Ethernet. It then starts a client session.
177.Bd -literal
178#include <stdio.h>
179#include <stdlib.h>
180#include <string.h>
181#include <ctype.h>
182#include <unistd.h>
183#include <sysexits.h>
184#include <errno.h>
185#include <err.h>
186
187#include <sys/types.h>
188#include <sys/socket.h>
189#include <sys/select.h>
190#include <net/ethernet.h>
191
192#include <netgraph.h>
193#include <netgraph/ng_ether.h>
194#include <netgraph/ng_pppoe.h>
195#include <netgraph/ng_socket.h>
196static int setup(char *ethername, char *service, char *sessname,
197				int *dfd, int *cfd);
198
199int
200main()
201{
202	int  fd1, fd2;
203	setup("xl0", NULL, "fred", &fd1, &fd2);
204	sleep (30);
205}
206
207static int
208setup(char *ethername, char *service, char *sessname,
209			int *dfd, int *cfd)
210{
211	struct ngm_connect ngc;	/* connect */
212	struct ngm_mkpeer mkp;	/* mkpeer */
213	/******** nodeinfo stuff **********/
214	u_char          rbuf[2 * 1024];
215	struct ng_mesg *const resp = (struct ng_mesg *) rbuf;
216	struct hooklist *const hlist
217			= (struct hooklist *) resp->data;
218	struct nodeinfo *const ninfo = &hlist->nodeinfo;
219	int             ch, no_hooks = 0;
220	struct linkinfo *link;
221	struct nodeinfo *peer;
222	/****message to connect pppoe session*****/
223	struct {
224		struct ngpppoe_init_data idata;
225		char            service[100];
226	}               message;
227	/********tracking our little graph ********/
228	char            path[100];
229	char            source_ID[NG_NODELEN + 1];
230	char            pppoe_node_name[100];
231	int             k;
232
233	/*
234	 * Create the data and control sockets
235	 */
236	if (NgMkSockNode(NULL, cfd, dfd) < 0) {
237		return (errno);
238	}
239	/*
240	 * find the ether node of the name requested by asking it for
241	 * it's inquiry information.
242	 */
243	if (strlen(ethername) > 16)
244		return (EINVAL);
245	sprintf(path, "%s:", ethername);
246	if (NgSendMsg(*cfd, path, NGM_GENERIC_COOKIE,
247		      NGM_LISTHOOKS, NULL, 0) < 0) {
248		return (errno);
249	}
250	/*
251	 * the command was accepted so it exists. Await the reply (It's
252	 * almost certainly already waiting).
253	 */
254	if (NgRecvMsg(*cfd, resp, sizeof(rbuf), NULL) < 0) {
255		return (errno);
256	}
257	/**
258	 * The following is available about the node:
259	 * ninfo->name		(string)
260	 * ninfo->type		(string)
261	 * ninfo->id		(u_int32_t)
262	 * ninfo->hooks		(u_int32_t) (count of hooks)
263	 * check it is the correct type. and get it's ID for use
264	 * with mkpeer later.
265	 */
266	if (strncmp(ninfo->type, NG_ETHER_NODE_TYPE,
267		    strlen(NG_ETHER_NODE_TYPE)) != 0) {
268		return (EPROTOTYPE);
269	}
270	sprintf(source_ID, "[%08x]:", ninfo->id);
271
272	/*
273	 * look for a hook already attached.
274	 */
275	for (k = 0; k < ninfo->hooks; k++) {
276		/**
277		 * The following are available about each hook.
278		 * link->ourhook	(string)
279		 * link->peerhook	(string)
280		 * peer->name		(string)
281		 * peer->type		(string)
282		 * peer->id		(u_int32_t)
283		 * peer->hooks		(u_int32_t)
284		 */
285		link = &hlist->link[k];
286		peer = &hlist->link[k].nodeinfo;
287
288		/* Ignore debug hooks */
289		if (strcmp("debug", link->ourhook) == 0)
290			continue;
291
292		/* If the orphans hook is attached, use that */
293		if (strcmp(NG_ETHER_HOOK_ORPHAN,
294		    link->ourhook) == 0) {
295			break;
296		}
297		/* the other option is the 'divert' hook */
298		if (strcmp("NG_ETHER_HOOK_DIVERT",
299		    link->ourhook) == 0) {
300			break;
301		}
302	}
303
304	/*
305	 * See if we found a hook there.
306	 */
307	if (k < ninfo->hooks) {
308		if (strcmp(peer->type, NG_PPPOE_NODE_TYPE) == 0) {
309			/*
310			 * If it's a type pppoe, we skip making one
311			 * ourself, but we continue, using
312			 * the existing one.
313			 */
314			sprintf(pppoe_node_name, "[%08x]:", peer->id);
315		} else {
316			/*
317			 * There is already someone hogging the data,
318			 * return an error. Some day we'll try
319			 * daisy-chaining..
320			 */
321			return (EBUSY);
322		}
323	} else {
324
325		/*
326		 * Try make a node of type pppoe against node "ID"
327		 * On hook NG_ETHER_HOOK_ORPHAN.
328		 */
329		snprintf(mkp.type, sizeof(mkp.type),
330			 "%s", NG_PPPOE_NODE_TYPE);
331		snprintf(mkp.ourhook, sizeof(mkp.ourhook),
332			 "%s", NG_ETHER_HOOK_ORPHAN);
333		snprintf(mkp.peerhook, sizeof(mkp.peerhook),
334			 "%s", NG_PPPOE_HOOK_ETHERNET);
335		/* Send message */
336		if (NgSendMsg(*cfd, source_ID, NGM_GENERIC_COOKIE,
337			      NGM_MKPEER, &mkp, sizeof(mkp)) < 0) {
338			return (errno);
339		}
340		/*
341		 * Work out a name for the new node.
342		 */
343		sprintf(pppoe_node_name, "%s:%s",
344			source_ID, NG_ETHER_HOOK_ORPHAN);
345	}
346	/*
347	 * We now have a pppoe node attached to the ethernet
348	 * card. The Ethernet is addressed as ethername: The pppoe
349	 * node is addressed as pppoe_node_name: attach to it.
350	 * Connect socket node to specified node Use the same hook
351	 * name on both ends of the link.
352	 */
353	snprintf(ngc.path, sizeof(ngc.path), "%s", pppoe_node_name);
354	snprintf(ngc.ourhook, sizeof(ngc.ourhook), "%s", sessname);
355	snprintf(ngc.peerhook, sizeof(ngc.peerhook), "%s", sessname);
356
357	if (NgSendMsg(*cfd, ".:", NGM_GENERIC_COOKIE,
358		      NGM_CONNECT, &ngc, sizeof(ngc)) < 0) {
359		return (errno);
360	}
361	/*
362	 * Send it a message telling it to start up.
363	 */
364	bzero(&message, sizeof(message));
365	snprintf(message.idata.hook, sizeof(message.idata.hook),
366				"%s", sessname);
367	if (service == NULL) {
368		message.idata.data_len = 0;
369	} else {
370		snprintf(message.idata.data,
371			 sizeof(message.idata.data), "%s", service);
372		message.idata.data_len = strlen(service);
373	}
374	/* Tell session/hook to start up as a client */
375	if (NgSendMsg(*cfd, ngc.path,
376		      NGM_PPPOE_COOKIE, NGM_PPPOE_CONNECT, &message.idata,
377		      sizeof(message.idata) + message.idata.data_len) < 0) {
378		return (errno);
379	}
380	return (0);
381}
382.Ed
383.Sh SEE ALSO
384.Xr netgraph 3 ,
385.Xr netgraph 4 ,
386.Xr ng_ppp 4 ,
387.Xr ng_socket 4 ,
388.Xr ngctl 8
389.Rs
390.%A L. Mamakos
391.%A K. Lidl
392.%A J. Evarts
393.%A D. Carrel
394.%A D. Simone
395.%A R. Wheeler
396.%T "A Method for transmitting PPP over Ethernet (PPPoE)"
397.%O RFC 2516
398.Re
399.Sh HISTORY
400The
401.Nm
402node type was implemented in
403.Fx 4.0 .
404.Sh AUTHORS
405.An Julian Elischer Aq julian@FreeBSD.org
406