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