1 .\" Copyright (c) 1996-1999 Whistle Communications, Inc.
2 .\" All rights reserved.
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.
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
33 .\" Author: Archie Cobbs <archie@FreeBSD.org>
36 .\" $Whistle: ng_pppoe.8,v 1.1 1999/01/25 23:46:27 archie Exp $
43 .Nd RFC 2516 PPPoE protocol netgraph node type
48 .In netgraph/ng_pppoe.h
52 node type performs the PPPoE protocol.
53 It is used in conjunction with the
55 extensions to the Ethernet framework to divert and inject Ethernet packets
56 to and from a PPP agent (which is not specified).
59 .Dv NGM_PPPOE_GET_STATUS
60 control message can be used at any time to query the current status
62 The only statistics presently available are the
63 total packet counts for input and output.
64 This node does not yet support
69 This node type supports the following hooks:
70 .Bl -tag -width ".Va [unspecified]"
72 The hook that should normally be connected to an
77 will send a message down this hook to determine Ethernet address of
79 Obtained address will be stored and then used for outgoing datagrams.
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.
87 This node type supports the generic control messages, plus the following:
89 .It Dv NGM_PPPOE_GET_STATUS
90 This command returns status information in a
91 .Dv "struct ngpppoestat" :
92 .Bd -literal -offset 4n
94 u_int packets_in; /* packets in from Ethernet */
95 u_int packets_out; /* packets out towards Ethernet */
98 .It Dv NGM_TEXT_STATUS
99 This generic message returns a human-readable version of the node status.
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
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.
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
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).
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.
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 */
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
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
178 At present this message is not yet used and a
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.
187 The four commands above use a common data structure:
188 .Bd -literal -offset 4n
190 char hook[NG_HOOKSIZ]; /* hook associated with event session */
194 .It Dv NGM_PPPOE_GETMODE Pq Ic pppoe_getmode
195 This command returns the current compatibility mode of the node
198 form of this message is
199 .Qq Li pppoe_getmode .
200 The following keywords can be returned:
203 The node operates according to RFC 2516.
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.
212 supports both modes simultaneously, depending on the ethertype, the
213 client used when connecting.
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.
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
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"'
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
243 hook, or when user wants to override this address with another one.
245 form of this message is
249 This node shuts down upon receipt of a
251 control message, when all session have been disconnected or when the
253 hook is disconnected.
255 The following code uses
259 node and connect it to both a socket node and an Ethernet node.
260 It can handle the case of when a
262 node is already attached to the Ethernet.
263 It then starts a client session.
270 #include <sysexits.h>
274 #include <sys/types.h>
275 #include <sys/socket.h>
276 #include <sys/select.h>
277 #include <net/ethernet.h>
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,
290 setup("xl0", NULL, "fred", &fd1, &fd2);
295 setup(char *ethername, char *service, char *sessname,
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*****/
311 struct ngpppoe_init_data idata;
314 /********tracking our little graph ********/
316 char source_ID[NG_NODESIZ];
317 char pppoe_node_name[100];
321 * Create the data and control sockets
323 if (NgMkSockNode(NULL, cfd, dfd) < 0) {
327 * find the ether node of the name requested by asking it for
328 * it's inquiry information.
330 if (strlen(ethername) > 16)
332 sprintf(path, "%s:", ethername);
333 if (NgSendMsg(*cfd, path, NGM_GENERIC_COOKIE,
334 NGM_LISTHOOKS, NULL, 0) < 0) {
338 * the command was accepted so it exists. Await the reply (It's
339 * almost certainly already waiting).
341 if (NgRecvMsg(*cfd, resp, sizeof(rbuf), NULL) < 0) {
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
353 if (strncmp(ninfo->type, NG_ETHER_NODE_TYPE,
354 strlen(NG_ETHER_NODE_TYPE)) != 0) {
357 sprintf(source_ID, "[%08x]:", ninfo->id);
360 * look for a hook already attached.
362 for (k = 0; k < ninfo->hooks; k++) {
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)
372 link = &hlist->link[k];
373 peer = &hlist->link[k].nodeinfo;
375 /* Ignore debug hooks */
376 if (strcmp("debug", link->ourhook) == 0)
379 /* If the orphans hook is attached, use that */
380 if (strcmp(NG_ETHER_HOOK_ORPHAN,
381 link->ourhook) == 0) {
384 /* the other option is the 'divert' hook */
385 if (strcmp("NG_ETHER_HOOK_DIVERT",
386 link->ourhook) == 0) {
392 * See if we found a hook there.
394 if (k < ninfo->hooks) {
395 if (strcmp(peer->type, NG_PPPOE_NODE_TYPE) == 0) {
397 * If it's a type PPPoE, we skip making one
398 * ourself, but we continue, using
401 sprintf(pppoe_node_name, "[%08x]:", peer->id);
404 * There is already someone hogging the data,
405 * return an error. Some day we'll try
413 * Try make a node of type PPPoE against node "ID"
414 * On hook NG_ETHER_HOOK_ORPHAN.
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);
423 if (NgSendMsg(*cfd, source_ID, NGM_GENERIC_COOKIE,
424 NGM_MKPEER, &mkp, sizeof(mkp)) < 0) {
428 * Work out a name for the new node.
430 sprintf(pppoe_node_name, "%s:%s",
431 source_ID, NG_ETHER_HOOK_ORPHAN);
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.
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);
444 if (NgSendMsg(*cfd, ".:", NGM_GENERIC_COOKIE,
445 NGM_CONNECT, &ngc, sizeof(ngc)) < 0) {
451 * In some cases we are speaking to 3Com hardware, so
452 * configure node to non-standard mode.
454 if (NgSendMsg(*cfd, ngc.path, NGM_PPPOE_COOKIE,
455 NGM_PPPOE_SETMODE, NG_PPPOE_NONSTANDARD,
456 strlen(NG_PPPOE_NONSTANDARD) + 1) == -1) {
462 * Send it a message telling it to start up.
464 bzero(&message, sizeof(message));
465 snprintf(message.idata.hook, sizeof(message.idata.hook),
467 if (service == NULL) {
468 message.idata.data_len = 0;
470 snprintf(message.idata.data,
471 sizeof(message.idata.data), "%s", service);
472 message.idata.data_len = strlen(service);
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) {
498 .%T "A Method for transmitting PPP over Ethernet (PPPoE)"
504 node type was implemented in
507 .An Julian Elischer Aq julian@FreeBSD.org