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