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