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