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