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