The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/modules/netgraph/pppoe/ng_pppoe.4

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    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 October 28, 1999
   39 .Dt NG_PPPOE 4
   40 .Os FreeBSD
   41 .Sh NAME
   42 .Nm ng_pppoe
   43 .Nd RFC 2516 PPPOE protocol netgraph node type
   44 .Sh SYNOPSIS
   45 .Fd #include <net/ethernet.h>
   46 .Fd #include <netgraph/ng_pppoe.h>
   47 .Sh DESCRIPTION
   48 The
   49 .Nm pppoe
   50 node type performs the PPPoE protocol. It is used in conjunction with the
   51 .Xr netgraph 4
   52 extensions to the Ethernet framework to divert and inject Ethernet packets
   53 to and from a PPP agent (which is not specified).
   54 .Pp
   55 The
   56 .Dv NGM_PPPOE_GET_STATUS
   57 control message can be used at any time to query the current status
   58 of the PPPOE module. The only statistics presently available are the
   59 total packet counts for input and output.  This node does not yet support
   60 the
   61 .Dv NGM_TEXT_STATUS
   62 control message.
   63 .Sh HOOKS
   64 This node type supports the following hooks:
   65 .Pp
   66 .Bl -tag -width foobarbaz
   67 .It Dv ethernet
   68 The hook that should normally be connected to an Ethernet node.
   69 .It Dv debug
   70 Presently no use.
   71 .It Dv [unspecified]
   72 Any other name is assumed to be a session hook that will be connected to
   73 a PPP client agent, or a ppp server agent.
   74 .El
   75 .Sh CONTROL MESSAGES
   76 This node type supports the generic control messages, plus the following:
   77 .Bl -tag -width foo
   78 .It Dv NGM_PPPOE_GET_STATUS
   79 This command returns status information in a
   80 .Dv "struct ngpppoestat" :
   81 .Bd -literal -offset 4n
   82 struct ngpppoestat {
   83     u_int   packets_in;     /* packets in from ethernet */
   84     u_int   packets_out;    /* packets out towards ethernet */
   85 };
   86 .Ed
   87 .It Dv NGM_TEXT_STATUS
   88 This generic message returns is a human-readable version of the node status.
   89 (not yet)
   90 .It Dv NGM_PPPOE_CONNECT
   91 Tell a nominated newly created hook that it's session should enter
   92 the state machine in a manner to become a client. It must be newly created and 
   93 a service name can be given as an argument. It is legal to specify a zero length
   94 service name. This is common on some DSL setups. A session request packet
   95 will be broadcast on the Ethernet.
   96 This command uses the 
   97 .Dv ngpppoe_init_data
   98 structure shown below.
   99 .It Dv NGM_PPPOE_LISTEN
  100 Tell a nominated newly created hook that it's session should enter
  101 the state machine in a manner to become a server listener. The argument
  102 given is the name of the service to listen on behalf of. A zero length service
  103 length will match all requests for service. A matching service request
  104 packet will be passed unmodified back to the process responsible
  105 for starting the service. It can then examine it and pass it on to 
  106 the session that is started to answer the request. 
  107 This command uses the 
  108 .Dv ngpppoe_init_data
  109 structure shown below.
  110 .It Dv NGM_PPPOE_OFFER
  111 Tell a nominated newly created hook that it's session should enter
  112 the state machine in a manner to become a server. The argument
  113 given is the name of the service to offer. A zero length service
  114 is legal. The State machine will progress to a state where it will await
  115 a request packet to be forwarded to it from  the startup server,
  116 which in turn probably received it from a LISTEN mode hook ( see above).
  117 This is so
  118 that information that is required for the session that is embedded in
  119 the original session request packet, is made available to the state machine 
  120 that eventually answers the request. When the Session request packet is
  121 received, the session negotiation will proceed. 
  122 This command uses the 
  123 .Dv ngpppoe_init_data
  124 structure shown below.
  125 .Pp
  126 The three commands above use a common data structure:
  127 .Bd -literal -offset 4n
  128 struct ngpppoe_init_data {
  129     char       hook[NG_HOOKLEN + 1];   /* hook to monitor on */
  130     u_int16_t  data_len;               /* service name length */
  131     char       data[0];                /* init data goes here */
  132 };
  133 .Ed
  134 .It Dv NGM_PPPOE_SUCCESS
  135 This command is sent to the node that started this session with one of the
  136 above messages, and reports a state change. This message reports
  137 successful Session negotiation. It uses the structure shown below, and
  138 reports back the hook name corresponding to the successful session.
  139 .It Dv NGM_NGM_PPPOE_FAIL
  140 This command is sent to the node that started this session with one of the
  141 above messages, and reports a state change. This message reports
  142 failed Session negotiation. It uses the structure shown below, and
  143 reports back the hook name corresponding to the failed session.
  144 The hook will probably have been removed immediately after sending this message
  145 .It Dv NGM_NGM_PPPOE_CLOSE
  146 This command is sent to the node that started this session with one of the
  147 above messages, and reports a state change. This message reports
  148 a request to close a session. It uses the structure shown below, and
  149 reports back the hook name corresponding to the closed session.
  150 The hook will probably have been removed immediately after sending this
  151 message. At present this message is not yet used and a 'failed' message
  152 will be received at closure instead.
  153 .Pp
  154 The three commands above use a common data structure:
  155 .Bd -literal -offset 4n
  156 struct ngpppoe_sts {
  157     char    hook[NG_HOOKLEN + 1]; /* hook associated with event session */
  158 };
  159 
  160 .El
  161 .Sh SHUTDOWN
  162 This node shuts down upon receipt of a
  163 .Dv NGM_SHUTDOWN
  164 control message, when all session have been disconnected or when the
  165 .Dv ethernet
  166 hook is disconnected.
  167 .Sh EXAMPLES
  168 The following code uses 
  169 .Dv libnetgraph
  170 to set up a
  171 .Nm 
  172 node and connect it to both a socket node and an Ethernet node. It can handle
  173 the case of when a
  174 .Nm
  175 node is already attached to the Ethernet. It then starts a client session.
  176 .Bd -literal
  177 #include <stdio.h>
  178 #include <stdlib.h>
  179 #include <string.h>
  180 #include <ctype.h>
  181 #include <unistd.h>
  182 #include <sysexits.h>
  183 #include <errno.h>
  184 #include <err.h>
  185 
  186 #include <sys/types.h>
  187 #include <sys/socket.h>
  188 #include <sys/select.h>
  189 #include <net/ethernet.h>
  190 
  191 #include <netgraph.h>
  192 #include <netgraph/ng_ether.h>
  193 #include <netgraph/ng_pppoe.h>
  194 #include <netgraph/ng_socket.h>
  195 static int setup(char *ethername, char *service, char *sessname,
  196                                 int *dfd, int *cfd);
  197 
  198 int
  199 main()
  200 {
  201         int  fd1, fd2;
  202         setup("xl0", NULL, "fred", &fd1, &fd2);
  203         sleep (30);
  204 }
  205 
  206 static int
  207 setup(char *ethername, char *service, char *sessname,
  208                         int *dfd, int *cfd)
  209 {
  210         struct ngm_connect ngc; /* connect */
  211         struct ngm_mkpeer mkp;  /* mkpeer */
  212         /******** nodeinfo stuff **********/
  213         u_char          rbuf[2 * 1024];
  214         struct ng_mesg *const resp = (struct ng_mesg *) rbuf;
  215         struct hooklist *const hlist
  216                         = (struct hooklist *) resp->data;
  217         struct nodeinfo *const ninfo = &hlist->nodeinfo;
  218         int             ch, no_hooks = 0;
  219         struct linkinfo *link;
  220         struct nodeinfo *peer;
  221         /****message to connect pppoe session*****/
  222         struct {
  223                 struct ngPPPoE_init_data idata;
  224                 char            service[100];
  225         }               message;
  226         /********tracking our little graph ********/
  227         char            path[100];
  228         char            source_ID[NG_NODELEN + 1];
  229         char            pppoe_node_name[100];
  230         int             k;
  231 
  232         /*
  233          * Create the data and control sockets
  234          */
  235         if (NgMkSockNode(NULL, cfd, dfd) < 0) {
  236                 return (errno);
  237         }
  238         /*
  239          * find the ether node of the name requested by asking it for
  240          * it's inquiry information.
  241          */
  242         if (strlen(ethername) > 16)
  243                 return (EINVAL);
  244         sprintf(path, "%s:", ethername);
  245         if (NgSendMsg(*cfd, path, NGM_GENERIC_COOKIE,
  246                       NGM_LISTHOOKS, NULL, 0) < 0) {
  247                 return (errno);
  248         }
  249         /*
  250          * the command was accepted so it exists. Await the reply (It's
  251          * almost certainly already waiting).
  252          */
  253         if (NgRecvMsg(*cfd, resp, sizeof(rbuf), NULL) < 0) {
  254                 return (errno);
  255         }
  256         /**
  257          * The following is available about the node:
  258          * ninfo->name          (string)
  259          * ninfo->type          (string)
  260          * ninfo->id            (u_int32_t)
  261          * ninfo->hooks         (u_int32_t) (count of hooks)
  262          * check it is the correct type. and get it's ID for use
  263          * with mkpeer later.
  264          */
  265         if (strncmp(ninfo->type, NG_ETHER_NODE_TYPE,
  266                     strlen(NG_ETHER_NODE_TYPE)) != 0) {
  267                 return (EPROTOTYPE);
  268         }
  269         sprintf(source_ID, "[%08x]:", ninfo->id);
  270 
  271         /*
  272          * look for a hook already attached.
  273          */
  274         for (k = 0; k < ninfo->hooks; k++) {
  275                 /**
  276                  * The following are available about each hook.
  277                  * link->ourhook        (string)
  278                  * link->peerhook       (string)
  279                  * peer->name           (string)
  280                  * peer->type           (string)
  281                  * peer->id             (u_int32_t)
  282                  * peer->hooks          (u_int32_t)
  283                  */
  284                 link = &hlist->link[k];
  285                 peer = &hlist->link[k].nodeinfo;
  286 
  287                 /* Ignore debug hooks */
  288                 if (strcmp("debug", link->ourhook) == 0)
  289                         continue;
  290 
  291                 /* If the orphans hook is attached, use that */
  292                 if (strcmp(NG_ETHER_HOOK_ORPHAN,
  293                     link->ourhook) == 0) {
  294                         break;
  295                 }
  296                 /* the other option is the 'divert' hook */
  297                 if (strcmp("NG_ETHER_HOOK_DIVERT",
  298                     link->ourhook) == 0) {
  299                         break;
  300                 }
  301         }
  302 
  303         /*
  304          * See if we found a hook there.
  305          */
  306         if (k < ninfo->hooks) {
  307                 if (strcmp(peer->type, NG_PPPOE_NODE_TYPE) == 0) {
  308                         /*
  309                          * If it's a type pppoe, we skip making one
  310                          * ourself, but we continue, using
  311                          * the existing one.
  312                          */
  313                         sprintf(pppoe_node_name, "[%08x]:", peer->id);
  314                 } else {
  315                         /*
  316                          * There is already someone hogging the data,
  317                          * return an error. Some day we'll try
  318                          * daisy-chaining..
  319                          */
  320                         return (EBUSY);
  321                 }
  322         } else {
  323 
  324                 /*
  325                  * Try make a node of type pppoe against node "ID"
  326                  * On hook NG_ETHER_HOOK_ORPHAN.
  327                  */
  328                 snprintf(mkp.type, sizeof(mkp.type),
  329                          "%s", NG_PPPOE_NODE_TYPE);
  330                 snprintf(mkp.ourhook, sizeof(mkp.ourhook),
  331                          "%s", NG_ETHER_HOOK_ORPHAN);
  332                 snprintf(mkp.peerhook, sizeof(mkp.peerhook),
  333                          "%s", NG_PPPOE_HOOK_ETHERNET);
  334                 /* Send message */
  335                 if (NgSendMsg(*cfd, source_ID, NGM_GENERIC_COOKIE,
  336                               NGM_MKPEER, &mkp, sizeof(mkp)) < 0) {
  337                         return (errno);
  338                 }
  339                 /*
  340                  * Work out a name for the new node.
  341                  */
  342                 sprintf(pppoe_node_name, "%s:%s",
  343                         source_ID, NG_ETHER_HOOK_ORPHAN);
  344         }
  345         /*
  346          * We now have a pppoe node attached to the ethernet
  347          * card. The Ethernet is addressed as ethername: The pppoe
  348          * node is addressed as pppoe_node_name: attach to it.
  349          * Connect socket node to specified node Use the same hook
  350          * name on both ends of the link.
  351          */
  352         snprintf(ngc.path, sizeof(ngc.path), "%s", pppoe_node_name);
  353         snprintf(ngc.ourhook, sizeof(ngc.ourhook), "%s", sessname);
  354         snprintf(ngc.peerhook, sizeof(ngc.peerhook), "%s", sessname);
  355 
  356         if (NgSendMsg(*cfd, ".:", NGM_GENERIC_COOKIE,
  357                       NGM_CONNECT, &ngc, sizeof(ngc)) < 0) {
  358                 return (errno);
  359         }
  360         /*
  361          * Send it a message telling it to start up.
  362          */
  363         bzero(&message, sizeof(message));
  364         snprintf(message.idata.hook, sizeof(message.idata.hook),
  365                                 "%s", sessname);
  366         if (service == NULL) {
  367                 message.idata.data_len = 0;
  368         } else {
  369                 snprintf(message.idata.data,
  370                          sizeof(message.idata.data), "%s", service);
  371                 message.idata.data_len = strlen(service);
  372         }
  373         /* Tell session/hook to start up as a client */
  374         if (NgSendMsg(*cfd, ngc.path,
  375                       NGM_PPPOE_COOKIE, NGM_PPPOE_CONNECT, &message.idata,
  376                       sizeof(message.idata) + message.idata.data_len) < 0) {
  377                 return (errno);
  378         }
  379         return (0);
  380 }
  381 .Ed
  382 .Sh SEE ALSO
  383 .Xr netgraph 3 ,
  384 .Xr netgraph 4 ,
  385 .Xr ng_socket 4 ,
  386 .Xr ng_ppp 4 ,
  387 .Xr ngctl 8
  388 .Rs
  389 .%A L. Mamakos
  390 .%A K. Lidl
  391 .%A J. Evarts
  392 .%A D. Carrel
  393 .%A D. Simone
  394 .%A R. Wheeler
  395 .%T "A Method for transmitting PPP over Ethernet (PPPoE)"
  396 .%O RFC 2516
  397 .Re
  398 .Sh HISTORY
  399 The
  400 .Nm
  401 node type was implemented in
  402 .Fx 4.0 .
  403 .Sh AUTHORS
  404 .An Julian Elischer Aq julian@freebsd.org

Cache object: f289fe23f313f5eacd60444a5d1f6e4a


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.