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@whistle.com>
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
45 .Fd #include <netgraph/ng_pppoe.h>
49 node type performs the PPPoE protocol. It is used in conjunction with a the
51 extensions to the ethernet framework to divert and inject ethernet packets
52 to and from a PPP agent (which is not specified).
55 .Dv NGM_PPPOE_GET_STATUS
56 control message can be used at any time to query the current status
57 of the PPPOE module. The only statistics presently available are the
58 total packet counts for input and output. This node does not yet support
63 This node type supports the following hooks:
65 .Bl -tag -width foobarbaz
67 The hook that should normally be connected to an ethernet node.
71 Any other name is assumed to be a session hook that will be connected to
72 a PPP client agent, or a ppp server agent.
75 This node type supports the generic control messages, plus the following:
77 .It Dv NGM_PPPOE_GET_STATUS
78 This command returns status information in a
79 .Dv "struct ngpppoestat" :
80 .Bd -literal -offset 4n
82 u_int packets_in; /* packets in from ethernet */
83 u_int packets_out; /* packets out towards ethernet */
86 .It Dv NGM_TEXT_STATUS
87 This generic message returns is a human-readable version of the node status.
89 .It Dv NGM_PPPOE_CONNECT
90 Tell a nominated newly created hook that it's session should enter
91 the state machine in a manner to become a client. It must be newly created and
92 a service name can be given as an argument. It is legal to specify a zero length
93 service name. This is common on some DSL setups. A session request packet
94 will be broadcast on the ethernet.
97 structure shown below.
98 .It Dv NGM_PPPOE_LISTEN
99 Tell a nominated newly created hook that it's session should enter
100 the state machine in a manner to become a server listener. The argument
101 given is the name of the service to listen on behalf of. A zero length service
102 length will match all requests for service. A matching service request
103 packet will be passed unmodified back to the process responsible
104 for starting the service. It can then examine it and pass it on to
105 the session that is started to answer the request.
106 This command uses the
107 .Dv ngpppoe_init_data
108 structure shown below.
109 .It Dv NGM_PPPOE_OFFER
110 Tell a nominated newly created hook that it's session should enter
111 the state machine in a manner to become a server. The argument
112 given is the name of the service to offer. A zero length service
113 is legal. The State machine will progress to a state where it will await
114 a request packet to be forwarded to it from the startup server,
115 which in turn probably received it from a LISTEN mode hook ( see above).
117 that information that is required for the session that is embedded in
118 the original session request packet, is made available to the state machine
119 that eventually answers the request. When the Session request packet is
120 received, the session negotiation will proceed.
121 This command uses the
122 .Dv ngpppoe_init_data
123 structure shown below.
126 The three commands above use a common data structure.
127 .Dv "struct ngpppoe_init_data"
128 .Bd -literal -offset 4n
129 struct ngpppoe_init_data {
130 char hook[NG_HOOKLEN + 1]; /* hook to monitor on */
131 u_int16_t data_len; /* Length of the service name */
132 char data[0]; /* init data goes here */
136 .It Dv NGM_PPPOE_SUCCESS
137 This command is sent to the node that started this session with one of the
138 above messages, and reports a state change. This message reports
139 successful Session negotiation. It uses the structure shown below, and
140 reports back the hook name corresponding to the successful session.
141 .It Dv NGM_NGM_PPPOE_FAIL
142 This command is sent to the node that started this session with one of the
143 above messages, and reports a state change. This message reports
144 failed Session negotiation. It uses the structure shown below, and
145 reports back the hook name corresponding to the failed session.
146 The hook will probably have been removed immediately after sending this message
147 .It Dv NGM_NGM_PPPOE_CLOSE
148 This command is sent to the node that started this session with one of the
149 above messages, and reports a state change. This message reports
150 a request to close a session. It uses the structure shown below, and
151 reports back the hook name corresponding to the closed session.
152 The hook will probably have been removed immediately after sending this
153 message. At present this message is not yet used and a 'failed' message
154 will be received at closure instead.
156 The three commands above use a common data structure.
157 .Dv "struct ngpppoe_sts"
158 .Bd -literal -offset 4n
160 char hook[NG_HOOKLEN + 1]; /* hook associated with event session */
165 This node shuts down upon receipt of a
167 control message, when all session have been disconnected or when the
169 hook is disconnected.
171 The following code uses
175 node and connect it to both a socket node and an ethernet node. It can handle
178 node is already attached to the ethernet. It then starts a client session.
185 #include <sysexits.h>
189 #include <sys/types.h>
190 #include <sys/socket.h>
191 #include <sys/select.h>
192 #include <net/ethernet.h>
194 #include <netgraph.h>
195 #include <netgraph/ng_ether.h>
196 #include <netgraph/ng_pppoe.h>
197 #include <netgraph/ng_socket.h>
198 static int setup(char *ethername, char *service, char *sessname,
205 setup("xl0", NULL, "fred", &fd1, &fd2);
210 setup(char *ethername, char *service, char *sessname,
213 struct ngm_connect ngc; /* connect */
214 struct ngm_mkpeer mkp; /* mkpeer */
215 /******** nodeinfo stuff **********/
216 u_char rbuf[2 * 1024];
217 struct ng_mesg *const resp = (struct ng_mesg *) rbuf;
218 struct hooklist *const hlist
219 = (struct hooklist *) resp->data;
220 struct nodeinfo *const ninfo = &hlist->nodeinfo;
221 int ch, no_hooks = 0;
222 struct linkinfo *link;
223 struct nodeinfo *peer;
224 /****message to connect pppoe session*****/
226 struct ngPPPoE_init_data idata;
229 /********tracking our little graph ********/
231 char source_ID[NG_NODELEN + 1];
232 char pppoe_node_name[100];
236 * Create the data and control sockets
238 if (NgMkSockNode(NULL, cfd, dfd) < 0) {
242 * find the ether node of the name requested by asking it for
243 * it's inquiry information.
245 if (strlen(ethername) > 16)
247 sprintf(path, "%s:", ethername);
248 if (NgSendMsg(*cfd, path, NGM_GENERIC_COOKIE,
249 NGM_LISTHOOKS, NULL, 0) < 0) {
253 * the command was accepted so it exists. Await the reply (It's
254 * almost certainly already waiting).
256 if (NgRecvMsg(*cfd, resp, sizeof(rbuf), NULL) < 0) {
260 * The following is available about the node:
261 * ninfo->name (string)
262 * ninfo->type (string)
263 * ninfo->id (u_int32_t)
264 * ninfo->hooks (u_int32_t) (count of hooks)
265 * check it is the correct type. and get it's ID for use
268 if (strncmp(ninfo->type, NG_ETHER_NODE_TYPE,
269 strlen(NG_ETHER_NODE_TYPE)) != 0) {
272 sprintf(source_ID, "[%08x]:", ninfo->id);
275 * look for a hook already attached.
277 for (k = 0; k < ninfo->hooks; k++) {
279 * The following are available about each hook.
280 * link->ourhook (string)
281 * link->peerhook (string)
282 * peer->name (string)
283 * peer->type (string)
284 * peer->id (u_int32_t)
285 * peer->hooks (u_int32_t)
287 link = &hlist->link[k];
288 peer = &hlist->link[k].nodeinfo;
290 /* Ignore debug hooks */
291 if (strcmp("debug", link->ourhook) == 0)
294 /* If the orphans hook is attached, use that */
295 if (strcmp(NG_ETHER_HOOK_ORPHAN,
296 link->ourhook) == 0) {
299 /* the other option is the 'divert' hook */
300 if (strcmp("NG_ETHER_HOOK_DIVERT",
301 link->ourhook) == 0) {
307 * See if we found a hook there.
309 if (k < ninfo->hooks) {
310 if (strcmp(peer->type, NG_PPPOE_NODE_TYPE) == 0) {
312 * If it's a type pppoe, we skip making one
313 * ourself, but we continue, using
316 sprintf(pppoe_node_name, "[%08x]:", peer->id);
319 * There is already someone hogging the data,
320 * return an error. Some day we'll try
328 * Try make a node of type pppoe against node "ID"
329 * On hook NG_ETHER_HOOK_ORPHAN.
331 snprintf(mkp.type, sizeof(mkp.type),
332 "%s", NG_PPPOE_NODE_TYPE);
333 snprintf(mkp.ourhook, sizeof(mkp.ourhook),
334 "%s", NG_ETHER_HOOK_ORPHAN);
335 snprintf(mkp.peerhook, sizeof(mkp.peerhook),
336 "%s", NG_PPPOE_HOOK_ETHERNET);
338 if (NgSendMsg(*cfd, source_ID, NGM_GENERIC_COOKIE,
339 NGM_MKPEER, &mkp, sizeof(mkp)) < 0) {
343 * Work out a name for the new node.
345 sprintf(pppoe_node_name, "%s:%s",
346 source_ID, NG_ETHER_HOOK_ORPHAN);
349 * We now have a pppoe node attached to the ethernet
350 * card. The Ethernet is addressed as ethername: The pppoe
351 * node is addressed as pppoe_node_name: attach to it.
352 * Connect socket node to specified node Use the same hook
353 * name on both ends of the link.
355 snprintf(ngc.path, sizeof(ngc.path), "%s", pppoe_node_name);
356 snprintf(ngc.ourhook, sizeof(ngc.ourhook), "%s", sessname);
357 snprintf(ngc.peerhook, sizeof(ngc.peerhook), "%s", sessname);
359 if (NgSendMsg(*cfd, ".:", NGM_GENERIC_COOKIE,
360 NGM_CONNECT, &ngc, sizeof(ngc)) < 0) {
364 * Send it a message telling it to start up.
366 bzero(&message, sizeof(message));
367 snprintf(message.idata.hook, sizeof(message.idata.hook),
369 if (service == NULL) {
370 message.idata.data_len = 0;
372 snprintf(message.idata.data,
373 sizeof(message.idata.data), "%s", service);
374 message.idata.data_len = strlen(service);
376 /* Tell session/hook to start up as a client */
377 if (NgSendMsg(*cfd, ngc.path,
378 NGM_PPPOE_COOKIE, NGM_PPPOE_CONNECT, &message.idata,
379 sizeof(message.idata) + message.idata.data_len) < 0) {
391 .%T "RFC 2516 - A Method of transmitting PPP over Ethernet (PPPoE)"
394 Julian Elischer <julian@whistle.com>