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