14cf49a43SJulian Elischer.\" Copyright (c) 1996-1999 Whistle Communications, Inc. 24cf49a43SJulian Elischer.\" All rights reserved. 34cf49a43SJulian Elischer.\" 44cf49a43SJulian Elischer.\" Subject to the following obligations and disclaimer of warranty, use and 54cf49a43SJulian Elischer.\" redistribution of this software, in source or object code forms, with or 64cf49a43SJulian Elischer.\" without modifications are expressly permitted by Whistle Communications; 74cf49a43SJulian Elischer.\" provided, however, that: 84cf49a43SJulian Elischer.\" 1. Any and all reproductions of the source or object code must include the 94cf49a43SJulian Elischer.\" copyright notice above and the following disclaimer of warranties; and 104cf49a43SJulian Elischer.\" 2. No rights are granted, in any manner or form, to use Whistle 114cf49a43SJulian Elischer.\" Communications, Inc. trademarks, including the mark "WHISTLE 124cf49a43SJulian Elischer.\" COMMUNICATIONS" on advertising, endorsements, or otherwise except as 134cf49a43SJulian Elischer.\" such appears in the above copyright notice or in the software. 144cf49a43SJulian Elischer.\" 154cf49a43SJulian Elischer.\" THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND 164cf49a43SJulian Elischer.\" TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO 174cf49a43SJulian Elischer.\" REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE, 184cf49a43SJulian Elischer.\" INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF 194cf49a43SJulian Elischer.\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. 204cf49a43SJulian Elischer.\" WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY 214cf49a43SJulian Elischer.\" REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS 224cf49a43SJulian Elischer.\" SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE. 234cf49a43SJulian Elischer.\" IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES 244cf49a43SJulian Elischer.\" RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING 254cf49a43SJulian Elischer.\" WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 264cf49a43SJulian Elischer.\" PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR 274cf49a43SJulian Elischer.\" SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY 284cf49a43SJulian Elischer.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 294cf49a43SJulian Elischer.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 304cf49a43SJulian Elischer.\" THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY 314cf49a43SJulian Elischer.\" OF SUCH DAMAGE. 324cf49a43SJulian Elischer.\" 33eddc45e7SJeroen Ruigrok van der Werven.\" Author: Archie Cobbs <archie@FreeBSD.org> 340332e30bSJulian Elischer.\" $Whistle: ng_pppoe.8,v 1.1 1999/01/25 23:46:27 archie Exp $ 354cf49a43SJulian Elischer.\" 362e547442SEugene Grosbein.Dd May 1, 2022 37bec35b9aSArchie Cobbs.Dt NG_PPPOE 4 383d45e180SRuslan Ermilov.Os 394cf49a43SJulian Elischer.Sh NAME 400332e30bSJulian Elischer.Nm ng_pppoe 419e76dcaeSYaroslav Tykhiy.Nd RFC 2516 PPPoE protocol netgraph node type 424cf49a43SJulian Elischer.Sh SYNOPSIS 43fbad9e2dSRuslan Ermilov.In sys/types.h 4432eef9aeSRuslan Ermilov.In net/ethernet.h 45fbad9e2dSRuslan Ermilov.In netgraph.h 4632eef9aeSRuslan Ermilov.In netgraph/ng_pppoe.h 474cf49a43SJulian Elischer.Sh DESCRIPTION 484cf49a43SJulian ElischerThe 4951291597SJulian Elischer.Nm pppoe 50417de5c6SYaroslav Tykhiynode type performs the PPPoE protocol. 51417de5c6SYaroslav TykhiyIt is used in conjunction with the 5201e86e31SArchie Cobbs.Xr netgraph 4 5301e86e31SArchie Cobbsextensions to the Ethernet framework to divert and inject Ethernet packets 540332e30bSJulian Elischerto and from a PPP agent (which is not specified). 554cf49a43SJulian Elischer.Pp 564cf49a43SJulian ElischerThe 570332e30bSJulian Elischer.Dv NGM_PPPOE_GET_STATUS 584cf49a43SJulian Elischercontrol message can be used at any time to query the current status 59417de5c6SYaroslav Tykhiyof the PPPoE module. 60417de5c6SYaroslav TykhiyThe only statistics presently available are the 61b5e7e999SRuslan Ermilovtotal packet counts for input and output. 62b5e7e999SRuslan ErmilovThis node does not yet support 630332e30bSJulian Elischerthe 644cf49a43SJulian Elischer.Dv NGM_TEXT_STATUS 654cf49a43SJulian Elischercontrol message. 664cf49a43SJulian Elischer.Sh HOOKS 674cf49a43SJulian ElischerThis node type supports the following hooks: 68c60bda17SJoel Dahl.Bl -tag -width ".Va [unspecified]" 69c60bda17SJoel Dahl.It Va ethernet 70b1ba28dfSGleb SmirnoffThe hook that should normally be connected to an 71b1ba28dfSGleb Smirnoff.Xr ng_ether 4 72b1ba28dfSGleb Smirnoffnode. 73b1ba28dfSGleb SmirnoffOnce connected, 74b1ba28dfSGleb Smirnoff.Nm 75b1ba28dfSGleb Smirnoffwill send a message down this hook to determine Ethernet address of 76b1ba28dfSGleb Smirnoffthe underlying node. 77b1ba28dfSGleb SmirnoffObtained address will be stored and then used for outgoing datagrams. 78c60bda17SJoel Dahl.It Va debug 790332e30bSJulian ElischerPresently no use. 80c60bda17SJoel Dahl.It Va [unspecified] 810332e30bSJulian ElischerAny other name is assumed to be a session hook that will be connected to 829e76dcaeSYaroslav Tykhiya PPP client agent, or a PPP server agent. 834cf49a43SJulian Elischer.El 844cf49a43SJulian Elischer.Sh CONTROL MESSAGES 854cf49a43SJulian ElischerThis node type supports the generic control messages, plus the following: 86f6156c39SGleb Smirnoff.Bl -tag -width 3n 870332e30bSJulian Elischer.It Dv NGM_PPPOE_GET_STATUS 884cf49a43SJulian ElischerThis command returns status information in a 890332e30bSJulian Elischer.Dv "struct ngpppoestat" : 904cf49a43SJulian Elischer.Bd -literal -offset 4n 910332e30bSJulian Elischerstruct ngpppoestat { 929e76dcaeSYaroslav Tykhiy u_int packets_in; /* packets in from Ethernet */ 939e76dcaeSYaroslav Tykhiy u_int packets_out; /* packets out towards Ethernet */ 944cf49a43SJulian Elischer}; 954cf49a43SJulian Elischer.Ed 964cf49a43SJulian Elischer.It Dv NGM_TEXT_STATUS 97bbc6c313SMaxim KonovalovThis generic message returns a human-readable version of the node status. 980332e30bSJulian Elischer(not yet) 99c60bda17SJoel Dahl.It Dv NGM_PPPOE_CONNECT Pq Ic pppoe_connect 10036a142c4SRuslan ErmilovTell a nominated newly created hook that its session should enter 10101139e41SRuslan Ermilovthe state machine as a client. 102f1c24d6dSAlexander MotinIt must be newly created and a service name can be given as an argument. 103f1c24d6dSAlexander MotinIt is legal to specify a zero-length service name, this is common 104ba730654SChristian Bruefferon some DSL setups. 1058be8c756SEugene GrosbeinIt is possible to request a connection to a specific access concentrator, 1068be8c756SEugene Grosbeinand/or set a specific Host-Uniq tag, required by some Internet providers, 1078be8c756SEugene Grosbeinusing the 1088be8c756SEugene Grosbein.Qq Li [AC-Name\\][Host-Uniq|]Service-Name 1098be8c756SEugene Grosbeinsyntax. 1108be8c756SEugene GrosbeinTo set a binary Host-Uniq, it must be encoded as a hexadecimal lowercase 1118be8c756SEugene Grosbeinstring and prefixed with 1128be8c756SEugene Grosbein.Qq Li 0x , 1138be8c756SEugene Grosbeinfor example 1148be8c756SEugene Grosbein.Qq Li 0x6d792d746167 1158be8c756SEugene Grosbeinis equivalent to 1168be8c756SEugene Grosbein.Qq Li my-tag . 1178be8c756SEugene GrosbeinA session request packet will be broadcast on the Ethernet. 1180332e30bSJulian ElischerThis command uses the 1190332e30bSJulian Elischer.Dv ngpppoe_init_data 1200332e30bSJulian Elischerstructure shown below. 1218be8c756SEugene GrosbeinFor example, this init data argument can be used to 1228be8c756SEugene Grosbeinconnect to 1238be8c756SEugene Grosbein.Qq Li my-isp 1248be8c756SEugene Grosbeinservice with 1258be8c756SEugene Grosbein.Qq Li my-host 1268be8c756SEugene Grosbeinuniq tag, accepting only 1278be8c756SEugene Grosbein.Qq Li remote-ac 1288be8c756SEugene Grosbeinas access concentrator: 1298be8c756SEugene Grosbein.Bd -literal -offset indent 1308be8c756SEugene Grosbein"remote-ac\\my-host|my-isp" 1318be8c756SEugene Grosbein.Ed 132c60bda17SJoel Dahl.It Dv NGM_PPPOE_LISTEN Pq Ic pppoe_listen 13336a142c4SRuslan ErmilovTell a nominated newly created hook that its session should enter 13401139e41SRuslan Ermilovthe state machine as a server listener. 135b5e7e999SRuslan ErmilovThe argument 13601139e41SRuslan Ermilovgiven is the name of the service to listen for. 13701139e41SRuslan ErmilovA zero-length service name will match all requests for service. 138b5e7e999SRuslan ErmilovA matching service request 1390332e30bSJulian Elischerpacket will be passed unmodified back to the process responsible 140b5e7e999SRuslan Ermilovfor starting the service. 141b5e7e999SRuslan ErmilovIt can then examine it and pass it on to 1420332e30bSJulian Elischerthe session that is started to answer the request. 1430332e30bSJulian ElischerThis command uses the 1440332e30bSJulian Elischer.Dv ngpppoe_init_data 1450332e30bSJulian Elischerstructure shown below. 146c60bda17SJoel Dahl.It Dv NGM_PPPOE_OFFER Pq Ic pppoe_offer 14736a142c4SRuslan ErmilovTell a nominated newly created hook that its session should enter 14801139e41SRuslan Ermilovthe state machine as a server. 149b5e7e999SRuslan ErmilovThe argument given is the name of the service to offer. 15001139e41SRuslan ErmilovA zero-length service 151b5e7e999SRuslan Ermilovis legal. 152b5e7e999SRuslan ErmilovThe State machine will progress to a state where it will await 1530332e30bSJulian Elischera request packet to be forwarded to it from the startup server, 1540332e30bSJulian Elischerwhich in turn probably received it from a LISTEN mode hook (see above). 1550332e30bSJulian ElischerThis is so 1560332e30bSJulian Elischerthat information that is required for the session that is embedded in 1570332e30bSJulian Elischerthe original session request packet, is made available to the state machine 158b5e7e999SRuslan Ermilovthat eventually answers the request. 159b5e7e999SRuslan ErmilovWhen the Session request packet is 1600332e30bSJulian Elischerreceived, the session negotiation will proceed. 1610332e30bSJulian ElischerThis command uses the 1620332e30bSJulian Elischer.Dv ngpppoe_init_data 1630332e30bSJulian Elischerstructure shown below. 164f6156c39SGleb Smirnoff.El 1650332e30bSJulian Elischer.Pp 16601e86e31SArchie CobbsThe three commands above use a common data structure: 1670332e30bSJulian Elischer.Bd -literal -offset 4n 1680332e30bSJulian Elischerstruct ngpppoe_init_data { 16989624a34SHartmut Brandt char hook[NG_HOOKSIZ]; /* hook to monitor on */ 170c60bda17SJoel Dahl uint16_t data_len; /* length of the service name */ 1710332e30bSJulian Elischer char data[0]; /* init data goes here */ 1720332e30bSJulian Elischer}; 1730332e30bSJulian Elischer.Ed 174f6156c39SGleb Smirnoff.Bl -tag -width 3n 175c60bda17SJoel Dahl.It Dv NGM_PPPOE_SUCCESS Pq Ic pppoe_success 1760332e30bSJulian ElischerThis command is sent to the node that started this session with one of the 177b5e7e999SRuslan Ermilovabove messages, and reports a state change. 178b5e7e999SRuslan ErmilovThis message reports successful Session negotiation. 179b5e7e999SRuslan ErmilovIt uses the structure shown below, and 1800332e30bSJulian Elischerreports back the hook name corresponding to the successful session. 181c60bda17SJoel Dahl.It Dv NGM_PPPOE_FAIL Pq Ic pppoe_fail 1820332e30bSJulian ElischerThis command is sent to the node that started this session with one of the 183b5e7e999SRuslan Ermilovabove messages, and reports a state change. 184b5e7e999SRuslan ErmilovThis message reports failed Session negotiation. 185b5e7e999SRuslan ErmilovIt uses the structure shown below, and 1860332e30bSJulian Elischerreports back the hook name corresponding to the failed session. 18701139e41SRuslan ErmilovThe hook will probably have been removed immediately after sending this 18801139e41SRuslan Ermilovmessage. 189c60bda17SJoel Dahl.It Dv NGM_PPPOE_CLOSE Pq Ic pppoe_close 1900332e30bSJulian ElischerThis command is sent to the node that started this session with one of the 191417de5c6SYaroslav Tykhiyabove messages, and reports a state change. 192417de5c6SYaroslav TykhiyThis message reports a request to close a session. 193b5e7e999SRuslan ErmilovIt uses the structure shown below, and 1940332e30bSJulian Elischerreports back the hook name corresponding to the closed session. 1957f9d26bdSMike PritchardThe hook will probably have been removed immediately after sending this 196b5e7e999SRuslan Ermilovmessage. 19701139e41SRuslan ErmilovAt present this message is not yet used and a 19801139e41SRuslan Ermilov.Dv NGM_PPPOE_FAIL 19901139e41SRuslan Ermilovmessage 2000332e30bSJulian Elischerwill be received at closure instead. 201637612f0SBrian Somers.It Dv NGM_PPPOE_ACNAME 202637612f0SBrian SomersThis command is sent to the node that started this session with one of the 203637612f0SBrian Somersabove messages, and reports the Access Concentrator Name. 204f6156c39SGleb Smirnoff.El 2050332e30bSJulian Elischer.Pp 206637612f0SBrian SomersThe four commands above use a common data structure: 2070332e30bSJulian Elischer.Bd -literal -offset 4n 2080332e30bSJulian Elischerstruct ngpppoe_sts { 20934d8949dSGleb Smirnoff char hook[NG_HOOKSIZ]; 2100332e30bSJulian Elischer}; 211404d68d4SRuslan Ermilov.Ed 212f6156c39SGleb Smirnoff.Bl -tag -width 3n 213c60bda17SJoel Dahl.It Dv NGM_PPPOE_GETMODE Pq Ic pppoe_getmode 214f6883559SGleb SmirnoffThis command returns the current compatibility mode of the node 215f6883559SGleb Smirnoffas a string. 216f217d18aSGleb Smirnoff.Tn ASCII 217f217d18aSGleb Smirnoffform of this message is 218f6156c39SGleb Smirnoff.Qq Li pppoe_getmode . 21981ae4b8dSRuslan ErmilovThe following keywords can be returned: 220f6883559SGleb Smirnoff.Bl -tag -width 3n 221f6883559SGleb Smirnoff.It Qq standard 222f6883559SGleb SmirnoffThe node operates according to RFC 2516. 223f6883559SGleb Smirnoff.It Qq 3Com 224f6883559SGleb SmirnoffWhen 225f6883559SGleb Smirnoff.Nm 226f6883559SGleb Smirnoffis a PPPoE client, it initiates a session encapsulating packets into 227f6883559SGleb Smirnoffincorrect 3Com ethertypes. 228fbf9b468SJoel DahlThis compatibility option does not affect server mode. 229f6883559SGleb SmirnoffIn server mode 230f6883559SGleb Smirnoff.Nm 231f6883559SGleb Smirnoffsupports both modes simultaneously, depending on the ethertype, the 232f6883559SGleb Smirnoffclient used when connecting. 233f6883559SGleb Smirnoff.It Qq D-Link 234f6883559SGleb SmirnoffWhen 235f6883559SGleb Smirnoff.Nm 236f6883559SGleb Smirnoffis a PPPoE server serving only specific Service-Name(s), it will respond 237f6883559SGleb Smirnoffto a PADI requests with empty Service-Name tag, returning all available 238f6883559SGleb SmirnoffService-Name(s) on node. 239f6883559SGleb SmirnoffThis option is necessary for compatibility with D-Link DI-614+ and DI-624+ 240f6883559SGleb SmirnoffSOHO routers as clients, when serving only specific Service-Name. 241fbf9b468SJoel DahlThis compatibility option does not affect client mode. 242f6883559SGleb Smirnoff.El 243c60bda17SJoel Dahl.It Dv NGM_PPPOE_SETMODE Pq Ic pppoe_setmode 244f217d18aSGleb SmirnoffConfigure node to the specified mode. 245f6156c39SGleb SmirnoffThe string argument is required. 24681ae4b8dSRuslan ErmilovThis command understands the same keywords that are returned by the 247f6883559SGleb Smirnoff.Dv NGM_PPPOE_GETMODE 248f6883559SGleb Smirnoffcommand. 249f217d18aSGleb Smirnoff.Tn ASCII 250f6156c39SGleb Smirnoffform of this message is 251f6156c39SGleb Smirnoff.Qq Li pppoe_setmode . 252f6156c39SGleb SmirnoffFor example, the following command will configure the node to initiate 253f6156c39SGleb Smirnoffthe next session in the proprietary 3Com mode: 25478b6fc8dSGleb Smirnoff.Bd -literal -offset indent 25578b6fc8dSGleb Smirnoffngctl msg fxp0:orphans pppoe_setmode '"3Com"' 25678b6fc8dSGleb Smirnoff.Ed 257c60bda17SJoel Dahl.It Dv NGM_PPPOE_SETENADDR Pq Ic setenaddr 258b1ba28dfSGleb SmirnoffSet the node Ethernet address for outgoing datagrams. 259f366efa9SGleb SmirnoffThis message is important when a node has failed to obtain an Ethernet 260f366efa9SGleb Smirnoffaddress from its peer on the 261b1ba28dfSGleb Smirnoff.Dv ethernet 262b1ba28dfSGleb Smirnoffhook, or when user wants to override this address with another one. 263b1ba28dfSGleb Smirnoff.Tn ASCII 264b1ba28dfSGleb Smirnoffform of this message is 265b1ba28dfSGleb Smirnoff.Qq Li setenaddr . 26634d8949dSGleb Smirnoff.It Dv NGM_PPPOE_SETMAXP Pq Ic setmaxp 26734d8949dSGleb SmirnoffSet the node PPP-Max-Payload value as described in RFC 4638. 26834d8949dSGleb SmirnoffThis message applies only to a client configuration. 26934d8949dSGleb Smirnoff.Tn ASCII 27034d8949dSGleb Smirnoffform of this message is 27134d8949dSGleb Smirnoff.Qq Li setmaxp . 27234d8949dSGleb Smirnoff.Pp 27334d8949dSGleb SmirnoffData structure returned to client is: 27434d8949dSGleb Smirnoff.Bd -literal -offset 4n 27534d8949dSGleb Smirnoffstruct ngpppoe_maxp { 27634d8949dSGleb Smirnoff char hook[NG_HOOKSIZ]; 27734d8949dSGleb Smirnoff uint16_t data; 27834d8949dSGleb Smirnoff}; 27934d8949dSGleb Smirnoff.Ed 2808be8c756SEugene Grosbein.It Dv NGM_PPPOE_SEND_HURL Pq Ic send_hurl 2818be8c756SEugene GrosbeinTell a nominated hook with an active session to send a PADM message with 2828be8c756SEugene Grosbeina HURL tag. 2838be8c756SEugene GrosbeinThe argument is the URL to be delivered to the client: 2848be8c756SEugene Grosbein.Bd -literal -offset indent 2858be8c756SEugene Grosbeinngctl msg fxp0:orphans send_hurl '{ hook="myHook" data="http://example.net/cpe" }' 2868be8c756SEugene Grosbein.Ed 2878be8c756SEugene Grosbein.It Dv NGM_PPPOE_SEND_MOTM Pq Ic send_motm 2888be8c756SEugene GrosbeinTell a nominated hook with an active session to send a PADM message with 2898be8c756SEugene Grosbeina MOTM tag. 2908be8c756SEugene GrosbeinThe argument is the message to be delivered to the client: 2918be8c756SEugene Grosbein.Bd -literal -offset indent 2928be8c756SEugene Grosbeinngctl msg fxp0:orphans send_motm '{ hook="myHook" data="Welcome aboard" }' 2938be8c756SEugene Grosbein.Ed 294f217d18aSGleb Smirnoff.El 2958be8c756SEugene Grosbein.Pp 2968be8c756SEugene GrosbeinThe two commands above use the same ngpppoe_init_data structure described 2978be8c756SEugene Grosbeinabove. 2988be8c756SEugene Grosbein.Bl -tag -width 3n 2998be8c756SEugene Grosbein.It Dv NGM_PPPOE_HURL 3008be8c756SEugene GrosbeinThis command is sent to the node that started this session when a PADM 3018be8c756SEugene Grosbeinmessage with a HURL tag is received, and contains a URL that the host can 3028be8c756SEugene Grosbeinpass to a web browser for presentation to the user. 3038be8c756SEugene Grosbein.It Dv NGM_PPPOE_MOTM 3048be8c756SEugene GrosbeinThis command is sent to the node that started this session when a PADM 3058be8c756SEugene Grosbeinmessage with a MOTM tag is received, and contains a Message Of The 3068be8c756SEugene GrosbeinMinute that the host can display to the user. 3078be8c756SEugene Grosbein.El 3088be8c756SEugene Grosbein.Pp 3098be8c756SEugene GrosbeinThe two commands above use a common data structure: 3108be8c756SEugene Grosbein.Bd -literal -offset 4n 3118be8c756SEugene Grosbeinstruct ngpppoe_padm { 3128be8c756SEugene Grosbein char msg[PPPOE_PADM_VALUE_SIZE]; 3138be8c756SEugene Grosbein}; 3148be8c756SEugene Grosbein.Ed 3154cf49a43SJulian Elischer.Sh SHUTDOWN 3164cf49a43SJulian ElischerThis node shuts down upon receipt of a 3174cf49a43SJulian Elischer.Dv NGM_SHUTDOWN 3180332e30bSJulian Elischercontrol message, when all session have been disconnected or when the 3190332e30bSJulian Elischer.Dv ethernet 3207f9d26bdSMike Pritchardhook is disconnected. 3212e547442SEugene Grosbein.Sh SYSCTL VARIABLES 3222e547442SEugene GrosbeinThe node can mark transmitted LCP Ethernet packets (protocol 0xc021) 32328903f39SEugene Grosbeinwith 3-bit Priority Code Point (PCP) referring to IEEE 802.1p 3242e547442SEugene Grosbeinclass of service with following 3252e547442SEugene Grosbein.Xr sysctl 8 3262e547442SEugene Grosbeinvariable. 3272e547442SEugene Grosbein.Bl -tag -width indent 3282e547442SEugene Grosbein.It Va net.graph.pppoe.lcp_pcp: 0..7 (default: 0) 3292e547442SEugene GrosbeinSet it to non-zero value to be used by parent network interface driver 3302e547442SEugene Grosbeinlike 3312e547442SEugene Grosbein.Xr vlan 4 3322e547442SEugene Grosbein.El 33351291597SJulian Elischer.Sh EXAMPLES 3340332e30bSJulian ElischerThe following code uses 3350332e30bSJulian Elischer.Dv libnetgraph 3360332e30bSJulian Elischerto set up a 3370332e30bSJulian Elischer.Nm 338b5e7e999SRuslan Ermilovnode and connect it to both a socket node and an Ethernet node. 339b5e7e999SRuslan ErmilovIt can handle the case of when a 3400332e30bSJulian Elischer.Nm 341b5e7e999SRuslan Ermilovnode is already attached to the Ethernet. 342b5e7e999SRuslan ErmilovIt then starts a client session. 3430332e30bSJulian Elischer.Bd -literal 3440332e30bSJulian Elischer#include <stdio.h> 3450332e30bSJulian Elischer#include <stdlib.h> 3460332e30bSJulian Elischer#include <string.h> 3470332e30bSJulian Elischer#include <ctype.h> 3480332e30bSJulian Elischer#include <unistd.h> 3490332e30bSJulian Elischer#include <sysexits.h> 3500332e30bSJulian Elischer#include <errno.h> 3510332e30bSJulian Elischer#include <err.h> 3520332e30bSJulian Elischer 3530332e30bSJulian Elischer#include <sys/types.h> 3540332e30bSJulian Elischer#include <sys/socket.h> 3550332e30bSJulian Elischer#include <sys/select.h> 3560332e30bSJulian Elischer#include <net/ethernet.h> 3570332e30bSJulian Elischer 3580332e30bSJulian Elischer#include <netgraph.h> 3590332e30bSJulian Elischer#include <netgraph/ng_ether.h> 3600332e30bSJulian Elischer#include <netgraph/ng_pppoe.h> 3610332e30bSJulian Elischer#include <netgraph/ng_socket.h> 3620332e30bSJulian Elischerstatic int setup(char *ethername, char *service, char *sessname, 3630332e30bSJulian Elischer int *dfd, int *cfd); 3640332e30bSJulian Elischer 3650332e30bSJulian Elischerint 3660332e30bSJulian Elischermain() 3670332e30bSJulian Elischer{ 3680332e30bSJulian Elischer int fd1, fd2; 3690332e30bSJulian Elischer setup("xl0", NULL, "fred", &fd1, &fd2); 3700332e30bSJulian Elischer sleep (30); 3710332e30bSJulian Elischer} 3720332e30bSJulian Elischer 3730332e30bSJulian Elischerstatic int 3740332e30bSJulian Elischersetup(char *ethername, char *service, char *sessname, 3750332e30bSJulian Elischer int *dfd, int *cfd) 3760332e30bSJulian Elischer{ 3770332e30bSJulian Elischer struct ngm_connect ngc; /* connect */ 3780332e30bSJulian Elischer struct ngm_mkpeer mkp; /* mkpeer */ 3790332e30bSJulian Elischer /******** nodeinfo stuff **********/ 3800332e30bSJulian Elischer u_char rbuf[2 * 1024]; 3810332e30bSJulian Elischer struct ng_mesg *const resp = (struct ng_mesg *) rbuf; 3820332e30bSJulian Elischer struct hooklist *const hlist 3830332e30bSJulian Elischer = (struct hooklist *) resp->data; 3840332e30bSJulian Elischer struct nodeinfo *const ninfo = &hlist->nodeinfo; 3850332e30bSJulian Elischer int ch, no_hooks = 0; 3860332e30bSJulian Elischer struct linkinfo *link; 3870332e30bSJulian Elischer struct nodeinfo *peer; 3889e76dcaeSYaroslav Tykhiy /****message to connect PPPoE session*****/ 3890332e30bSJulian Elischer struct { 3905dccc9f0SJulian Elischer struct ngpppoe_init_data idata; 3910332e30bSJulian Elischer char service[100]; 3920332e30bSJulian Elischer } message; 3930332e30bSJulian Elischer /********tracking our little graph ********/ 3940332e30bSJulian Elischer char path[100]; 39589624a34SHartmut Brandt char source_ID[NG_NODESIZ]; 3960332e30bSJulian Elischer char pppoe_node_name[100]; 3970332e30bSJulian Elischer int k; 3980332e30bSJulian Elischer 3990332e30bSJulian Elischer /* 4000332e30bSJulian Elischer * Create the data and control sockets 4010332e30bSJulian Elischer */ 4020332e30bSJulian Elischer if (NgMkSockNode(NULL, cfd, dfd) < 0) { 4030332e30bSJulian Elischer return (errno); 4040332e30bSJulian Elischer } 4050332e30bSJulian Elischer /* 4060332e30bSJulian Elischer * find the ether node of the name requested by asking it for 4070332e30bSJulian Elischer * it's inquiry information. 4080332e30bSJulian Elischer */ 4090332e30bSJulian Elischer if (strlen(ethername) > 16) 4100332e30bSJulian Elischer return (EINVAL); 4110332e30bSJulian Elischer sprintf(path, "%s:", ethername); 4120332e30bSJulian Elischer if (NgSendMsg(*cfd, path, NGM_GENERIC_COOKIE, 4130332e30bSJulian Elischer NGM_LISTHOOKS, NULL, 0) < 0) { 4140332e30bSJulian Elischer return (errno); 4150332e30bSJulian Elischer } 4160332e30bSJulian Elischer /* 4170332e30bSJulian Elischer * the command was accepted so it exists. Await the reply (It's 4180332e30bSJulian Elischer * almost certainly already waiting). 4190332e30bSJulian Elischer */ 4200332e30bSJulian Elischer if (NgRecvMsg(*cfd, resp, sizeof(rbuf), NULL) < 0) { 4210332e30bSJulian Elischer return (errno); 4220332e30bSJulian Elischer } 4230332e30bSJulian Elischer /** 4240332e30bSJulian Elischer * The following is available about the node: 4250332e30bSJulian Elischer * ninfo->name (string) 4260332e30bSJulian Elischer * ninfo->type (string) 4276b99842aSEd Schouten * ninfo->id (uint32_t) 4286b99842aSEd Schouten * ninfo->hooks (uint32_t) (count of hooks) 4290332e30bSJulian Elischer * check it is the correct type. and get it's ID for use 4300332e30bSJulian Elischer * with mkpeer later. 4310332e30bSJulian Elischer */ 4320332e30bSJulian Elischer if (strncmp(ninfo->type, NG_ETHER_NODE_TYPE, 4330332e30bSJulian Elischer strlen(NG_ETHER_NODE_TYPE)) != 0) { 4340332e30bSJulian Elischer return (EPROTOTYPE); 4350332e30bSJulian Elischer } 4360332e30bSJulian Elischer sprintf(source_ID, "[%08x]:", ninfo->id); 4370332e30bSJulian Elischer 4380332e30bSJulian Elischer /* 4390332e30bSJulian Elischer * look for a hook already attached. 4400332e30bSJulian Elischer */ 4410332e30bSJulian Elischer for (k = 0; k < ninfo->hooks; k++) { 4420332e30bSJulian Elischer /** 4430332e30bSJulian Elischer * The following are available about each hook. 4440332e30bSJulian Elischer * link->ourhook (string) 4450332e30bSJulian Elischer * link->peerhook (string) 4460332e30bSJulian Elischer * peer->name (string) 4470332e30bSJulian Elischer * peer->type (string) 4486b99842aSEd Schouten * peer->id (uint32_t) 4496b99842aSEd Schouten * peer->hooks (uint32_t) 4500332e30bSJulian Elischer */ 4510332e30bSJulian Elischer link = &hlist->link[k]; 4520332e30bSJulian Elischer peer = &hlist->link[k].nodeinfo; 4530332e30bSJulian Elischer 4540332e30bSJulian Elischer /* Ignore debug hooks */ 4550332e30bSJulian Elischer if (strcmp("debug", link->ourhook) == 0) 4560332e30bSJulian Elischer continue; 4570332e30bSJulian Elischer 4580332e30bSJulian Elischer /* If the orphans hook is attached, use that */ 4590332e30bSJulian Elischer if (strcmp(NG_ETHER_HOOK_ORPHAN, 4600332e30bSJulian Elischer link->ourhook) == 0) { 4610332e30bSJulian Elischer break; 4620332e30bSJulian Elischer } 4630332e30bSJulian Elischer /* the other option is the 'divert' hook */ 4640332e30bSJulian Elischer if (strcmp("NG_ETHER_HOOK_DIVERT", 4650332e30bSJulian Elischer link->ourhook) == 0) { 4660332e30bSJulian Elischer break; 4670332e30bSJulian Elischer } 4680332e30bSJulian Elischer } 4690332e30bSJulian Elischer 4700332e30bSJulian Elischer /* 4710332e30bSJulian Elischer * See if we found a hook there. 4720332e30bSJulian Elischer */ 4730332e30bSJulian Elischer if (k < ninfo->hooks) { 4740332e30bSJulian Elischer if (strcmp(peer->type, NG_PPPOE_NODE_TYPE) == 0) { 4750332e30bSJulian Elischer /* 4769e76dcaeSYaroslav Tykhiy * If it's a type PPPoE, we skip making one 4770332e30bSJulian Elischer * ourself, but we continue, using 4780332e30bSJulian Elischer * the existing one. 4790332e30bSJulian Elischer */ 4800332e30bSJulian Elischer sprintf(pppoe_node_name, "[%08x]:", peer->id); 4810332e30bSJulian Elischer } else { 4820332e30bSJulian Elischer /* 4837f9d26bdSMike Pritchard * There is already someone hogging the data, 4847f9d26bdSMike Pritchard * return an error. Some day we'll try 4850332e30bSJulian Elischer * daisy-chaining.. 4860332e30bSJulian Elischer */ 4870332e30bSJulian Elischer return (EBUSY); 4880332e30bSJulian Elischer } 4890332e30bSJulian Elischer } else { 4900332e30bSJulian Elischer 4910332e30bSJulian Elischer /* 4929e76dcaeSYaroslav Tykhiy * Try make a node of type PPPoE against node "ID" 4930332e30bSJulian Elischer * On hook NG_ETHER_HOOK_ORPHAN. 4940332e30bSJulian Elischer */ 4950332e30bSJulian Elischer snprintf(mkp.type, sizeof(mkp.type), 4960332e30bSJulian Elischer "%s", NG_PPPOE_NODE_TYPE); 4970332e30bSJulian Elischer snprintf(mkp.ourhook, sizeof(mkp.ourhook), 4980332e30bSJulian Elischer "%s", NG_ETHER_HOOK_ORPHAN); 4990332e30bSJulian Elischer snprintf(mkp.peerhook, sizeof(mkp.peerhook), 5000332e30bSJulian Elischer "%s", NG_PPPOE_HOOK_ETHERNET); 5010332e30bSJulian Elischer /* Send message */ 5020332e30bSJulian Elischer if (NgSendMsg(*cfd, source_ID, NGM_GENERIC_COOKIE, 5030332e30bSJulian Elischer NGM_MKPEER, &mkp, sizeof(mkp)) < 0) { 5040332e30bSJulian Elischer return (errno); 5050332e30bSJulian Elischer } 5060332e30bSJulian Elischer /* 5070332e30bSJulian Elischer * Work out a name for the new node. 5080332e30bSJulian Elischer */ 5090332e30bSJulian Elischer sprintf(pppoe_node_name, "%s:%s", 5100332e30bSJulian Elischer source_ID, NG_ETHER_HOOK_ORPHAN); 5110332e30bSJulian Elischer } 5120332e30bSJulian Elischer /* 5139e76dcaeSYaroslav Tykhiy * We now have a PPPoE node attached to the Ethernet 5149e76dcaeSYaroslav Tykhiy * card. The Ethernet is addressed as ethername: The PPPoE 5150332e30bSJulian Elischer * node is addressed as pppoe_node_name: attach to it. 5160332e30bSJulian Elischer * Connect socket node to specified node Use the same hook 5170332e30bSJulian Elischer * name on both ends of the link. 5180332e30bSJulian Elischer */ 5190332e30bSJulian Elischer snprintf(ngc.path, sizeof(ngc.path), "%s", pppoe_node_name); 5200332e30bSJulian Elischer snprintf(ngc.ourhook, sizeof(ngc.ourhook), "%s", sessname); 5210332e30bSJulian Elischer snprintf(ngc.peerhook, sizeof(ngc.peerhook), "%s", sessname); 5220332e30bSJulian Elischer 5230332e30bSJulian Elischer if (NgSendMsg(*cfd, ".:", NGM_GENERIC_COOKIE, 5240332e30bSJulian Elischer NGM_CONNECT, &ngc, sizeof(ngc)) < 0) { 5250332e30bSJulian Elischer return (errno); 5260332e30bSJulian Elischer } 527f217d18aSGleb Smirnoff 528f217d18aSGleb Smirnoff#ifdef NONSTANDARD 529f217d18aSGleb Smirnoff /* 530f217d18aSGleb Smirnoff * In some cases we are speaking to 3Com hardware, so 531f217d18aSGleb Smirnoff * configure node to non-standard mode. 532f217d18aSGleb Smirnoff */ 533f217d18aSGleb Smirnoff if (NgSendMsg(*cfd, ngc.path, NGM_PPPOE_COOKIE, 534f217d18aSGleb Smirnoff NGM_PPPOE_SETMODE, NG_PPPOE_NONSTANDARD, 535f217d18aSGleb Smirnoff strlen(NG_PPPOE_NONSTANDARD) + 1) == -1) { 536f217d18aSGleb Smirnoff return (errno); 537f217d18aSGleb Smirnoff } 538f217d18aSGleb Smirnoff#endif 539f217d18aSGleb Smirnoff 5400332e30bSJulian Elischer /* 5410332e30bSJulian Elischer * Send it a message telling it to start up. 5420332e30bSJulian Elischer */ 5430332e30bSJulian Elischer bzero(&message, sizeof(message)); 5440332e30bSJulian Elischer snprintf(message.idata.hook, sizeof(message.idata.hook), 5450332e30bSJulian Elischer "%s", sessname); 5460332e30bSJulian Elischer if (service == NULL) { 5470332e30bSJulian Elischer message.idata.data_len = 0; 5480332e30bSJulian Elischer } else { 5490332e30bSJulian Elischer snprintf(message.idata.data, 5500332e30bSJulian Elischer sizeof(message.idata.data), "%s", service); 5510332e30bSJulian Elischer message.idata.data_len = strlen(service); 5520332e30bSJulian Elischer } 5530332e30bSJulian Elischer /* Tell session/hook to start up as a client */ 5540332e30bSJulian Elischer if (NgSendMsg(*cfd, ngc.path, 5550332e30bSJulian Elischer NGM_PPPOE_COOKIE, NGM_PPPOE_CONNECT, &message.idata, 5560332e30bSJulian Elischer sizeof(message.idata) + message.idata.data_len) < 0) { 5570332e30bSJulian Elischer return (errno); 5580332e30bSJulian Elischer } 5590332e30bSJulian Elischer return (0); 5600332e30bSJulian Elischer} 5610332e30bSJulian Elischer.Ed 5624cf49a43SJulian Elischer.Sh SEE ALSO 5630332e30bSJulian Elischer.Xr netgraph 3 , 5644cf49a43SJulian Elischer.Xr netgraph 4 , 565b1ba28dfSGleb Smirnoff.Xr ng_ether 4 , 566bec35b9aSArchie Cobbs.Xr ng_ppp 4 , 5675521ff5aSRuslan Ermilov.Xr ng_socket 4 , 568*6e1fc011SGraham Percival.Xr vlan 4 , 569f217d18aSGleb Smirnoff.Xr ngctl 8 , 570*6e1fc011SGraham Percival.Xr ppp 8 5714cf49a43SJulian Elischer.Rs 57201e86e31SArchie Cobbs.%A L. Mamakos 57301e86e31SArchie Cobbs.%A K. Lidl 57401e86e31SArchie Cobbs.%A J. Evarts 57501e86e31SArchie Cobbs.%A D. Carrel 57601e86e31SArchie Cobbs.%A D. Simone 57701e86e31SArchie Cobbs.%A R. Wheeler 57801e86e31SArchie Cobbs.%T "A Method for transmitting PPP over Ethernet (PPPoE)" 57901e86e31SArchie Cobbs.%O RFC 2516 5804cf49a43SJulian Elischer.Re 58151291597SJulian Elischer.Sh HISTORY 58251291597SJulian ElischerThe 58351291597SJulian Elischer.Nm 58451291597SJulian Elischernode type was implemented in 58551291597SJulian Elischer.Fx 4.0 . 58651291597SJulian Elischer.Sh AUTHORS 5876c899950SBaptiste Daroussin.An Julian Elischer Aq Mt julian@FreeBSD.org 588