]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - share/man/man4/ng_pppoe.4
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.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 November 13, 2012
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];    /* hook associated with event session */
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 .El
248 .Sh SHUTDOWN
249 This node shuts down upon receipt of a
250 .Dv NGM_SHUTDOWN
251 control message, when all session have been disconnected or when the
252 .Dv ethernet
253 hook is disconnected.
254 .Sh EXAMPLES
255 The following code uses
256 .Dv libnetgraph
257 to set up a
258 .Nm
259 node and connect it to both a socket node and an Ethernet node.
260 It can handle the case of when a
261 .Nm
262 node is already attached to the Ethernet.
263 It then starts a client session.
264 .Bd -literal
265 #include <stdio.h>
266 #include <stdlib.h>
267 #include <string.h>
268 #include <ctype.h>
269 #include <unistd.h>
270 #include <sysexits.h>
271 #include <errno.h>
272 #include <err.h>
273
274 #include <sys/types.h>
275 #include <sys/socket.h>
276 #include <sys/select.h>
277 #include <net/ethernet.h>
278
279 #include <netgraph.h>
280 #include <netgraph/ng_ether.h>
281 #include <netgraph/ng_pppoe.h>
282 #include <netgraph/ng_socket.h>
283 static int setup(char *ethername, char *service, char *sessname,
284                                 int *dfd, int *cfd);
285
286 int
287 main()
288 {
289         int  fd1, fd2;
290         setup("xl0", NULL, "fred", &fd1, &fd2);
291         sleep (30);
292 }
293
294 static int
295 setup(char *ethername, char *service, char *sessname,
296                         int *dfd, int *cfd)
297 {
298         struct ngm_connect ngc; /* connect */
299         struct ngm_mkpeer mkp;  /* mkpeer */
300         /******** nodeinfo stuff **********/
301         u_char          rbuf[2 * 1024];
302         struct ng_mesg *const resp = (struct ng_mesg *) rbuf;
303         struct hooklist *const hlist
304                         = (struct hooklist *) resp->data;
305         struct nodeinfo *const ninfo = &hlist->nodeinfo;
306         int             ch, no_hooks = 0;
307         struct linkinfo *link;
308         struct nodeinfo *peer;
309         /****message to connect PPPoE session*****/
310         struct {
311                 struct ngpppoe_init_data idata;
312                 char            service[100];
313         }               message;
314         /********tracking our little graph ********/
315         char            path[100];
316         char            source_ID[NG_NODESIZ];
317         char            pppoe_node_name[100];
318         int             k;
319
320         /*
321          * Create the data and control sockets
322          */
323         if (NgMkSockNode(NULL, cfd, dfd) < 0) {
324                 return (errno);
325         }
326         /*
327          * find the ether node of the name requested by asking it for
328          * it's inquiry information.
329          */
330         if (strlen(ethername) > 16)
331                 return (EINVAL);
332         sprintf(path, "%s:", ethername);
333         if (NgSendMsg(*cfd, path, NGM_GENERIC_COOKIE,
334                       NGM_LISTHOOKS, NULL, 0) < 0) {
335                 return (errno);
336         }
337         /*
338          * the command was accepted so it exists. Await the reply (It's
339          * almost certainly already waiting).
340          */
341         if (NgRecvMsg(*cfd, resp, sizeof(rbuf), NULL) < 0) {
342                 return (errno);
343         }
344         /**
345          * The following is available about the node:
346          * ninfo->name          (string)
347          * ninfo->type          (string)
348          * ninfo->id            (uint32_t)
349          * ninfo->hooks         (uint32_t) (count of hooks)
350          * check it is the correct type. and get it's ID for use
351          * with mkpeer later.
352          */
353         if (strncmp(ninfo->type, NG_ETHER_NODE_TYPE,
354                     strlen(NG_ETHER_NODE_TYPE)) != 0) {
355                 return (EPROTOTYPE);
356         }
357         sprintf(source_ID, "[%08x]:", ninfo->id);
358
359         /*
360          * look for a hook already attached.
361          */
362         for (k = 0; k < ninfo->hooks; k++) {
363                 /**
364                  * The following are available about each hook.
365                  * link->ourhook        (string)
366                  * link->peerhook       (string)
367                  * peer->name           (string)
368                  * peer->type           (string)
369                  * peer->id             (uint32_t)
370                  * peer->hooks          (uint32_t)
371                  */
372                 link = &hlist->link[k];
373                 peer = &hlist->link[k].nodeinfo;
374
375                 /* Ignore debug hooks */
376                 if (strcmp("debug", link->ourhook) == 0)
377                         continue;
378
379                 /* If the orphans hook is attached, use that */
380                 if (strcmp(NG_ETHER_HOOK_ORPHAN,
381                     link->ourhook) == 0) {
382                         break;
383                 }
384                 /* the other option is the 'divert' hook */
385                 if (strcmp("NG_ETHER_HOOK_DIVERT",
386                     link->ourhook) == 0) {
387                         break;
388                 }
389         }
390
391         /*
392          * See if we found a hook there.
393          */
394         if (k < ninfo->hooks) {
395                 if (strcmp(peer->type, NG_PPPOE_NODE_TYPE) == 0) {
396                         /*
397                          * If it's a type PPPoE, we skip making one
398                          * ourself, but we continue, using
399                          * the existing one.
400                          */
401                         sprintf(pppoe_node_name, "[%08x]:", peer->id);
402                 } else {
403                         /*
404                          * There is already someone hogging the data,
405                          * return an error. Some day we'll try
406                          * daisy-chaining..
407                          */
408                         return (EBUSY);
409                 }
410         } else {
411
412                 /*
413                  * Try make a node of type PPPoE against node "ID"
414                  * On hook NG_ETHER_HOOK_ORPHAN.
415                  */
416                 snprintf(mkp.type, sizeof(mkp.type),
417                          "%s", NG_PPPOE_NODE_TYPE);
418                 snprintf(mkp.ourhook, sizeof(mkp.ourhook),
419                          "%s", NG_ETHER_HOOK_ORPHAN);
420                 snprintf(mkp.peerhook, sizeof(mkp.peerhook),
421                          "%s", NG_PPPOE_HOOK_ETHERNET);
422                 /* Send message */
423                 if (NgSendMsg(*cfd, source_ID, NGM_GENERIC_COOKIE,
424                               NGM_MKPEER, &mkp, sizeof(mkp)) < 0) {
425                         return (errno);
426                 }
427                 /*
428                  * Work out a name for the new node.
429                  */
430                 sprintf(pppoe_node_name, "%s:%s",
431                         source_ID, NG_ETHER_HOOK_ORPHAN);
432         }
433         /*
434          * We now have a PPPoE node attached to the Ethernet
435          * card. The Ethernet is addressed as ethername: The PPPoE
436          * node is addressed as pppoe_node_name: attach to it.
437          * Connect socket node to specified node Use the same hook
438          * name on both ends of the link.
439          */
440         snprintf(ngc.path, sizeof(ngc.path), "%s", pppoe_node_name);
441         snprintf(ngc.ourhook, sizeof(ngc.ourhook), "%s", sessname);
442         snprintf(ngc.peerhook, sizeof(ngc.peerhook), "%s", sessname);
443
444         if (NgSendMsg(*cfd, ".:", NGM_GENERIC_COOKIE,
445                       NGM_CONNECT, &ngc, sizeof(ngc)) < 0) {
446                 return (errno);
447         }
448
449 #ifdef  NONSTANDARD
450         /*
451          * In some cases we are speaking to 3Com hardware, so
452          * configure node to non-standard mode.
453          */
454         if (NgSendMsg(*cfd, ngc.path, NGM_PPPOE_COOKIE,
455                         NGM_PPPOE_SETMODE, NG_PPPOE_NONSTANDARD,
456                         strlen(NG_PPPOE_NONSTANDARD) + 1) == -1) {
457                 return (errno);
458         }
459 #endif
460
461         /*
462          * Send it a message telling it to start up.
463          */
464         bzero(&message, sizeof(message));
465         snprintf(message.idata.hook, sizeof(message.idata.hook),
466                                 "%s", sessname);
467         if (service == NULL) {
468                 message.idata.data_len = 0;
469         } else {
470                 snprintf(message.idata.data,
471                          sizeof(message.idata.data), "%s", service);
472                 message.idata.data_len = strlen(service);
473         }
474         /* Tell session/hook to start up as a client */
475         if (NgSendMsg(*cfd, ngc.path,
476                       NGM_PPPOE_COOKIE, NGM_PPPOE_CONNECT, &message.idata,
477                       sizeof(message.idata) + message.idata.data_len) < 0) {
478                 return (errno);
479         }
480         return (0);
481 }
482 .Ed
483 .Sh SEE ALSO
484 .Xr netgraph 3 ,
485 .Xr netgraph 4 ,
486 .Xr ng_ether 4 ,
487 .Xr ng_ppp 4 ,
488 .Xr ng_socket 4 ,
489 .Xr ngctl 8 ,
490 .Xr ppp 8
491 .Rs
492 .%A L. Mamakos
493 .%A K. Lidl
494 .%A J. Evarts
495 .%A D. Carrel
496 .%A D. Simone
497 .%A R. Wheeler
498 .%T "A Method for transmitting PPP over Ethernet (PPPoE)"
499 .%O RFC 2516
500 .Re
501 .Sh HISTORY
502 The
503 .Nm
504 node type was implemented in
505 .Fx 4.0 .
506 .Sh AUTHORS
507 .An Julian Elischer Aq julian@FreeBSD.org