1999-10-21 09:06:11 +00:00
|
|
|
/*
|
|
|
|
* ng_pppoe.c
|
2005-01-07 01:45:51 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*-
|
1999-10-21 09:06:11 +00:00
|
|
|
* Copyright (c) 1996-1999 Whistle Communications, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Subject to the following obligations and disclaimer of warranty, use and
|
|
|
|
* redistribution of this software, in source or object code forms, with or
|
|
|
|
* without modifications are expressly permitted by Whistle Communications;
|
|
|
|
* provided, however, that:
|
|
|
|
* 1. Any and all reproductions of the source or object code must include the
|
|
|
|
* copyright notice above and the following disclaimer of warranties; and
|
|
|
|
* 2. No rights are granted, in any manner or form, to use Whistle
|
|
|
|
* Communications, Inc. trademarks, including the mark "WHISTLE
|
|
|
|
* COMMUNICATIONS" on advertising, endorsements, or otherwise except as
|
|
|
|
* such appears in the above copyright notice or in the software.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND
|
|
|
|
* TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO
|
|
|
|
* REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE,
|
|
|
|
* INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
|
|
|
|
* WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY
|
|
|
|
* REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS
|
|
|
|
* SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE.
|
|
|
|
* IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES
|
|
|
|
* RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING
|
|
|
|
* WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
|
|
|
* PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY
|
|
|
|
* OF SUCH DAMAGE.
|
|
|
|
*
|
2000-10-24 17:32:45 +00:00
|
|
|
* Author: Julian Elischer <julian@freebsd.org>
|
1999-10-21 09:06:11 +00:00
|
|
|
*
|
|
|
|
* $FreeBSD$
|
1999-11-01 10:00:40 +00:00
|
|
|
* $Whistle: ng_pppoe.c,v 1.10 1999/11/01 09:24:52 julian Exp $
|
1999-10-21 09:06:11 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
2006-01-21 08:13:19 +00:00
|
|
|
#include <sys/ktr.h>
|
1999-10-21 09:06:11 +00:00
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/errno.h>
|
2006-08-07 08:05:10 +00:00
|
|
|
#include <sys/syslog.h>
|
1999-10-21 09:06:11 +00:00
|
|
|
#include <net/ethernet.h>
|
|
|
|
|
|
|
|
#include <netgraph/ng_message.h>
|
|
|
|
#include <netgraph/netgraph.h>
|
2000-10-31 02:45:24 +00:00
|
|
|
#include <netgraph/ng_parse.h>
|
1999-10-21 09:06:11 +00:00
|
|
|
#include <netgraph/ng_pppoe.h>
|
2006-08-09 09:56:58 +00:00
|
|
|
#include <netgraph/ng_ether.h>
|
1999-10-21 09:06:11 +00:00
|
|
|
|
2001-01-10 07:13:58 +00:00
|
|
|
#ifdef NG_SEPARATE_MALLOC
|
2011-11-07 06:44:47 +00:00
|
|
|
static MALLOC_DEFINE(M_NETGRAPH_PPPOE, "netgraph_pppoe", "netgraph pppoe node");
|
2001-01-10 07:13:58 +00:00
|
|
|
#else
|
|
|
|
#define M_NETGRAPH_PPPOE M_NETGRAPH
|
|
|
|
#endif
|
|
|
|
|
1999-11-19 05:49:18 +00:00
|
|
|
#define SIGNOFF "session closed"
|
|
|
|
|
1999-10-21 09:06:11 +00:00
|
|
|
/*
|
|
|
|
* This section contains the netgraph method declarations for the
|
2001-02-23 16:34:22 +00:00
|
|
|
* pppoe node. These methods define the netgraph pppoe 'type'.
|
1999-10-21 09:06:11 +00:00
|
|
|
*/
|
|
|
|
|
1999-11-01 10:00:40 +00:00
|
|
|
static ng_constructor_t ng_pppoe_constructor;
|
|
|
|
static ng_rcvmsg_t ng_pppoe_rcvmsg;
|
2001-01-06 00:46:47 +00:00
|
|
|
static ng_shutdown_t ng_pppoe_shutdown;
|
1999-11-01 10:00:40 +00:00
|
|
|
static ng_newhook_t ng_pppoe_newhook;
|
2006-08-09 09:56:58 +00:00
|
|
|
static ng_connect_t ng_pppoe_connect;
|
1999-11-01 10:00:40 +00:00
|
|
|
static ng_rcvdata_t ng_pppoe_rcvdata;
|
2007-10-14 09:58:22 +00:00
|
|
|
static ng_rcvdata_t ng_pppoe_rcvdata_ether;
|
|
|
|
static ng_rcvdata_t ng_pppoe_rcvdata_debug;
|
1999-11-01 10:00:40 +00:00
|
|
|
static ng_disconnect_t ng_pppoe_disconnect;
|
1999-10-21 09:06:11 +00:00
|
|
|
|
2000-10-31 02:45:24 +00:00
|
|
|
/* Parse type for struct ngpppoe_init_data */
|
2002-05-31 23:48:03 +00:00
|
|
|
static const struct ng_parse_struct_field ngpppoe_init_data_type_fields[]
|
2000-10-31 02:45:24 +00:00
|
|
|
= NG_PPPOE_INIT_DATA_TYPE_INFO;
|
2000-11-16 23:14:53 +00:00
|
|
|
static const struct ng_parse_type ngpppoe_init_data_state_type = {
|
2000-10-31 02:45:24 +00:00
|
|
|
&ng_parse_struct_type,
|
2002-05-31 23:48:03 +00:00
|
|
|
&ngpppoe_init_data_type_fields
|
2000-10-31 02:45:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Parse type for struct ngpppoe_sts */
|
2002-05-31 23:48:03 +00:00
|
|
|
static const struct ng_parse_struct_field ng_pppoe_sts_type_fields[]
|
2000-10-31 02:45:24 +00:00
|
|
|
= NG_PPPOE_STS_TYPE_INFO;
|
|
|
|
static const struct ng_parse_type ng_pppoe_sts_state_type = {
|
|
|
|
&ng_parse_struct_type,
|
2002-05-31 23:48:03 +00:00
|
|
|
&ng_pppoe_sts_type_fields
|
2000-10-31 02:45:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* List of commands and how to convert arguments to/from ASCII */
|
|
|
|
static const struct ng_cmdlist ng_pppoe_cmds[] = {
|
|
|
|
{
|
|
|
|
NGM_PPPOE_COOKIE,
|
|
|
|
NGM_PPPOE_CONNECT,
|
|
|
|
"pppoe_connect",
|
2000-11-16 23:14:53 +00:00
|
|
|
&ngpppoe_init_data_state_type,
|
2000-10-31 02:45:24 +00:00
|
|
|
NULL
|
|
|
|
},
|
|
|
|
{
|
|
|
|
NGM_PPPOE_COOKIE,
|
|
|
|
NGM_PPPOE_LISTEN,
|
|
|
|
"pppoe_listen",
|
2000-11-16 23:14:53 +00:00
|
|
|
&ngpppoe_init_data_state_type,
|
2000-10-31 02:45:24 +00:00
|
|
|
NULL
|
|
|
|
},
|
|
|
|
{
|
|
|
|
NGM_PPPOE_COOKIE,
|
|
|
|
NGM_PPPOE_OFFER,
|
|
|
|
"pppoe_offer",
|
2000-11-16 23:14:53 +00:00
|
|
|
&ngpppoe_init_data_state_type,
|
2000-10-31 02:45:24 +00:00
|
|
|
NULL
|
|
|
|
},
|
2000-12-12 18:52:14 +00:00
|
|
|
{
|
|
|
|
NGM_PPPOE_COOKIE,
|
|
|
|
NGM_PPPOE_SERVICE,
|
|
|
|
"pppoe_service",
|
|
|
|
&ngpppoe_init_data_state_type,
|
|
|
|
NULL
|
|
|
|
},
|
2000-10-31 02:45:24 +00:00
|
|
|
{
|
|
|
|
NGM_PPPOE_COOKIE,
|
|
|
|
NGM_PPPOE_SUCCESS,
|
|
|
|
"pppoe_success",
|
|
|
|
&ng_pppoe_sts_state_type,
|
|
|
|
NULL
|
|
|
|
},
|
|
|
|
{
|
|
|
|
NGM_PPPOE_COOKIE,
|
|
|
|
NGM_PPPOE_FAIL,
|
|
|
|
"pppoe_fail",
|
|
|
|
&ng_pppoe_sts_state_type,
|
|
|
|
NULL
|
|
|
|
},
|
|
|
|
{
|
|
|
|
NGM_PPPOE_COOKIE,
|
|
|
|
NGM_PPPOE_CLOSE,
|
|
|
|
"pppoe_close",
|
|
|
|
&ng_pppoe_sts_state_type,
|
|
|
|
NULL
|
|
|
|
},
|
2004-07-27 19:47:13 +00:00
|
|
|
{
|
|
|
|
NGM_PPPOE_COOKIE,
|
|
|
|
NGM_PPPOE_SETMODE,
|
|
|
|
"pppoe_setmode",
|
|
|
|
&ng_parse_string_type,
|
|
|
|
NULL
|
|
|
|
},
|
|
|
|
{
|
|
|
|
NGM_PPPOE_COOKIE,
|
|
|
|
NGM_PPPOE_GETMODE,
|
|
|
|
"pppoe_getmode",
|
|
|
|
NULL,
|
|
|
|
&ng_parse_string_type
|
|
|
|
},
|
2006-08-09 09:56:58 +00:00
|
|
|
{
|
|
|
|
NGM_PPPOE_COOKIE,
|
|
|
|
NGM_PPPOE_SETENADDR,
|
|
|
|
"setenaddr",
|
|
|
|
&ng_parse_enaddr_type,
|
|
|
|
NULL
|
|
|
|
},
|
2000-10-31 02:45:24 +00:00
|
|
|
{ 0 }
|
|
|
|
};
|
|
|
|
|
1999-10-21 09:06:11 +00:00
|
|
|
/* Netgraph node type descriptor */
|
|
|
|
static struct ng_type typestruct = {
|
2004-05-29 00:51:19 +00:00
|
|
|
.version = NG_ABI_VERSION,
|
|
|
|
.name = NG_PPPOE_NODE_TYPE,
|
|
|
|
.constructor = ng_pppoe_constructor,
|
|
|
|
.rcvmsg = ng_pppoe_rcvmsg,
|
|
|
|
.shutdown = ng_pppoe_shutdown,
|
|
|
|
.newhook = ng_pppoe_newhook,
|
2006-08-09 09:56:58 +00:00
|
|
|
.connect = ng_pppoe_connect,
|
2004-05-29 00:51:19 +00:00
|
|
|
.rcvdata = ng_pppoe_rcvdata,
|
|
|
|
.disconnect = ng_pppoe_disconnect,
|
|
|
|
.cmdlist = ng_pppoe_cmds,
|
1999-10-21 09:06:11 +00:00
|
|
|
};
|
1999-10-27 11:29:51 +00:00
|
|
|
NETGRAPH_INIT(pppoe, &typestruct);
|
1999-10-21 09:06:11 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* States for the session state machine.
|
|
|
|
* These have no meaning if there is no hook attached yet.
|
|
|
|
*/
|
|
|
|
enum state {
|
|
|
|
PPPOE_SNONE=0, /* [both] Initial state */
|
1999-11-21 10:43:05 +00:00
|
|
|
PPPOE_LISTENING, /* [Daemon] Listening for discover initiation pkt */
|
1999-10-21 09:06:11 +00:00
|
|
|
PPPOE_SINIT, /* [Client] Sent discovery initiation */
|
1999-11-21 10:43:05 +00:00
|
|
|
PPPOE_PRIMED, /* [Server] Awaiting PADI from daemon */
|
|
|
|
PPPOE_SOFFER, /* [Server] Sent offer message (got PADI)*/
|
1999-10-21 09:06:11 +00:00
|
|
|
PPPOE_SREQ, /* [Client] Sent a Request */
|
1999-11-21 10:43:05 +00:00
|
|
|
PPPOE_NEWCONNECTED, /* [Server] Connection established, No data received */
|
1999-10-21 09:06:11 +00:00
|
|
|
PPPOE_CONNECTED, /* [Both] Connection established, Data received */
|
|
|
|
PPPOE_DEAD /* [Both] */
|
|
|
|
};
|
|
|
|
|
|
|
|
#define NUMTAGS 20 /* number of tags we are set up to work with */
|
|
|
|
|
|
|
|
/*
|
2006-01-21 08:13:19 +00:00
|
|
|
* Information we store for each hook on each node for negotiating the
|
1999-10-21 09:06:11 +00:00
|
|
|
* session. The mbuf and cluster are freed once negotiation has completed.
|
|
|
|
* The whole negotiation block is then discarded.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct sess_neg {
|
|
|
|
struct mbuf *m; /* holds cluster with last sent packet */
|
|
|
|
union packet *pkt; /* points within the above cluster */
|
2004-12-08 13:27:54 +00:00
|
|
|
struct callout handle; /* see timeout(9) */
|
1999-10-21 09:06:11 +00:00
|
|
|
u_int timeout; /* 0,1,2,4,8,16 etc. seconds */
|
|
|
|
u_int numtags;
|
2002-06-05 23:35:31 +00:00
|
|
|
const struct pppoe_tag *tags[NUMTAGS];
|
1999-10-21 09:06:11 +00:00
|
|
|
u_int service_len;
|
|
|
|
u_int ac_name_len;
|
|
|
|
|
|
|
|
struct datatag service;
|
|
|
|
struct datatag ac_name;
|
|
|
|
};
|
|
|
|
typedef struct sess_neg *negp;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Session information that is needed after connection.
|
|
|
|
*/
|
2000-09-19 03:22:06 +00:00
|
|
|
struct sess_con {
|
1999-10-21 09:06:11 +00:00
|
|
|
hook_p hook;
|
2006-01-21 08:13:19 +00:00
|
|
|
uint16_t Session_ID;
|
1999-10-21 09:06:11 +00:00
|
|
|
enum state state;
|
2006-01-21 08:13:19 +00:00
|
|
|
ng_ID_t creator; /* who to notify */
|
1999-10-21 09:06:11 +00:00
|
|
|
struct pppoe_full_hdr pkt_hdr; /* used when connected */
|
|
|
|
negp neg; /* used when negotiating */
|
2008-03-03 19:36:03 +00:00
|
|
|
LIST_ENTRY(sess_con) sessions;
|
1999-10-21 09:06:11 +00:00
|
|
|
};
|
2000-09-19 03:22:06 +00:00
|
|
|
typedef struct sess_con *sessp;
|
1999-10-21 09:06:11 +00:00
|
|
|
|
2008-01-31 22:42:37 +00:00
|
|
|
#define SESSHASHSIZE 0x0100
|
|
|
|
#define SESSHASH(x) (((x) ^ ((x) >> 8)) & (SESSHASHSIZE - 1))
|
|
|
|
|
|
|
|
struct sess_hash_entry {
|
|
|
|
struct mtx mtx;
|
2008-03-03 19:36:03 +00:00
|
|
|
LIST_HEAD(hhead, sess_con) head;
|
2008-01-31 22:42:37 +00:00
|
|
|
};
|
|
|
|
|
1999-10-21 09:06:11 +00:00
|
|
|
/*
|
|
|
|
* Information we store for each node
|
|
|
|
*/
|
2006-01-21 08:13:19 +00:00
|
|
|
struct PPPoE {
|
1999-10-21 09:06:11 +00:00
|
|
|
node_p node; /* back pointer to node */
|
|
|
|
hook_p ethernet_hook;
|
|
|
|
hook_p debug_hook;
|
|
|
|
u_int packets_in; /* packets in from ethernet */
|
|
|
|
u_int packets_out; /* packets out towards ethernet */
|
2006-01-21 08:13:19 +00:00
|
|
|
uint32_t flags;
|
2006-01-27 10:56:22 +00:00
|
|
|
#define COMPAT_3COM 0x00000001
|
|
|
|
#define COMPAT_DLINK 0x00000002
|
2006-08-09 09:56:58 +00:00
|
|
|
struct ether_header eh;
|
2008-03-03 19:36:03 +00:00
|
|
|
LIST_HEAD(, sess_con) listeners;
|
2008-01-31 22:42:37 +00:00
|
|
|
struct sess_hash_entry sesshash[SESSHASHSIZE];
|
1999-10-21 09:06:11 +00:00
|
|
|
};
|
2006-01-21 08:13:19 +00:00
|
|
|
typedef struct PPPoE *priv_p;
|
1999-10-21 09:06:11 +00:00
|
|
|
|
|
|
|
union uniq {
|
|
|
|
char bytes[sizeof(void *)];
|
2006-01-21 08:13:19 +00:00
|
|
|
void *pointer;
|
|
|
|
};
|
1999-10-21 09:06:11 +00:00
|
|
|
|
|
|
|
#define LEAVE(x) do { error = x; goto quit; } while(0)
|
|
|
|
static void pppoe_start(sessp sp);
|
2004-12-08 13:27:54 +00:00
|
|
|
static void pppoe_ticker(node_p node, hook_p hook, void *arg1, int arg2);
|
2002-06-05 23:35:31 +00:00
|
|
|
static const struct pppoe_tag *scan_tags(sessp sp,
|
|
|
|
const struct pppoe_hdr* ph);
|
1999-10-23 04:28:11 +00:00
|
|
|
static int pppoe_send_event(sessp sp, enum cmd cmdid);
|
1999-10-21 09:06:11 +00:00
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* Some basic utilities from the Linux version with author's permission.*
|
|
|
|
* Author: Michal Ostrowski <mostrows@styx.uwaterloo.ca> *
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2006-01-21 08:13:19 +00:00
|
|
|
* Return the location where the next tag can be put
|
1999-10-21 09:06:11 +00:00
|
|
|
*/
|
2002-06-05 23:35:31 +00:00
|
|
|
static __inline const struct pppoe_tag*
|
|
|
|
next_tag(const struct pppoe_hdr* ph)
|
1999-10-21 09:06:11 +00:00
|
|
|
{
|
2009-03-03 18:47:33 +00:00
|
|
|
return (const struct pppoe_tag*)(((const char*)(ph + 1))
|
2002-06-05 23:35:31 +00:00
|
|
|
+ ntohs(ph->length));
|
1999-10-21 09:06:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2006-01-21 08:13:19 +00:00
|
|
|
* Look for a tag of a specific type.
|
|
|
|
* Don't trust any length the other end says,
|
1999-10-21 09:06:11 +00:00
|
|
|
* but assume we already sanity checked ph->length.
|
|
|
|
*/
|
2002-06-05 23:35:31 +00:00
|
|
|
static const struct pppoe_tag*
|
2006-01-21 08:13:19 +00:00
|
|
|
get_tag(const struct pppoe_hdr* ph, uint16_t idx)
|
1999-10-21 09:06:11 +00:00
|
|
|
{
|
2002-06-05 23:35:31 +00:00
|
|
|
const char *const end = (const char *)next_tag(ph);
|
2009-03-03 18:47:33 +00:00
|
|
|
const struct pppoe_tag *pt = (const void *)(ph + 1);
|
2006-01-21 08:13:19 +00:00
|
|
|
const char *ptn;
|
|
|
|
|
1999-10-21 09:06:11 +00:00
|
|
|
/*
|
|
|
|
* Keep processing tags while a tag header will still fit.
|
|
|
|
*/
|
2002-06-05 23:35:31 +00:00
|
|
|
while((const char*)(pt + 1) <= end) {
|
2006-01-21 08:13:19 +00:00
|
|
|
/*
|
|
|
|
* If the tag data would go past the end of the packet, abort.
|
|
|
|
*/
|
|
|
|
ptn = (((const char *)(pt + 1)) + ntohs(pt->tag_len));
|
|
|
|
if (ptn > end) {
|
|
|
|
CTR2(KTR_NET, "%20s: invalid length for tag %d",
|
|
|
|
__func__, idx);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
if (pt->tag_type == idx) {
|
|
|
|
CTR2(KTR_NET, "%20s: found tag %d", __func__, idx);
|
|
|
|
return (pt);
|
|
|
|
}
|
1999-10-21 09:06:11 +00:00
|
|
|
|
2006-01-21 08:13:19 +00:00
|
|
|
pt = (const struct pppoe_tag*)ptn;
|
1999-10-21 09:06:11 +00:00
|
|
|
}
|
2006-01-21 08:13:19 +00:00
|
|
|
|
|
|
|
CTR2(KTR_NET, "%20s: not found tag %d", __func__, idx);
|
|
|
|
return (NULL);
|
1999-10-21 09:06:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
2006-01-21 08:13:19 +00:00
|
|
|
* Inlines to initialise or add tags to a session's tag list.
|
1999-10-21 09:06:11 +00:00
|
|
|
**************************************************************************/
|
|
|
|
/*
|
2006-01-21 08:13:19 +00:00
|
|
|
* Initialise the session's tag list.
|
1999-10-21 09:06:11 +00:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
init_tags(sessp sp)
|
|
|
|
{
|
2006-01-21 08:13:19 +00:00
|
|
|
KASSERT(sp->neg != NULL, ("%s: no neg", __func__));
|
1999-10-21 09:06:11 +00:00
|
|
|
sp->neg->numtags = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-06-05 23:35:31 +00:00
|
|
|
insert_tag(sessp sp, const struct pppoe_tag *tp)
|
1999-10-21 09:06:11 +00:00
|
|
|
{
|
2006-01-21 08:13:19 +00:00
|
|
|
negp neg = sp->neg;
|
|
|
|
int i;
|
1999-10-21 09:06:11 +00:00
|
|
|
|
2006-01-21 08:13:19 +00:00
|
|
|
KASSERT(neg != NULL, ("%s: no neg", __func__));
|
1999-10-21 09:06:11 +00:00
|
|
|
if ((i = neg->numtags++) < NUMTAGS) {
|
|
|
|
neg->tags[i] = tp;
|
|
|
|
} else {
|
2006-08-07 08:05:10 +00:00
|
|
|
log(LOG_NOTICE, "ng_pppoe: asked to add too many tags to "
|
|
|
|
"packet\n");
|
1999-11-09 00:31:04 +00:00
|
|
|
neg->numtags--;
|
1999-10-21 09:06:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make up a packet, using the tags filled out for the session.
|
|
|
|
*
|
2006-01-21 08:13:19 +00:00
|
|
|
* Assume that the actual pppoe header and ethernet header
|
1999-10-21 09:06:11 +00:00
|
|
|
* are filled out externally to this routine.
|
2006-01-21 08:13:19 +00:00
|
|
|
* Also assume that neg->wh points to the correct
|
1999-10-21 09:06:11 +00:00
|
|
|
* location at the front of the buffer space.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
make_packet(sessp sp) {
|
|
|
|
struct pppoe_full_hdr *wh = &sp->neg->pkt->pkt_header;
|
2002-06-05 23:35:31 +00:00
|
|
|
const struct pppoe_tag **tag;
|
1999-10-21 09:06:11 +00:00
|
|
|
char *dp;
|
|
|
|
int count;
|
|
|
|
int tlen;
|
2006-01-21 08:13:19 +00:00
|
|
|
uint16_t length = 0;
|
|
|
|
|
|
|
|
KASSERT((sp->neg != NULL) && (sp->neg->m != NULL),
|
2006-08-07 08:05:10 +00:00
|
|
|
("%s: called from wrong state", __func__));
|
2006-01-21 08:13:19 +00:00
|
|
|
CTR2(KTR_NET, "%20s: called %d", __func__, sp->Session_ID);
|
1999-10-21 09:06:11 +00:00
|
|
|
|
2009-03-03 18:47:33 +00:00
|
|
|
dp = (char *)(&wh->ph + 1);
|
1999-10-21 09:06:11 +00:00
|
|
|
for (count = 0, tag = sp->neg->tags;
|
2006-01-21 08:13:19 +00:00
|
|
|
((count < sp->neg->numtags) && (count < NUMTAGS));
|
1999-10-21 09:06:11 +00:00
|
|
|
tag++, count++) {
|
|
|
|
tlen = ntohs((*tag)->tag_len) + sizeof(**tag);
|
|
|
|
if ((length + tlen) > (ETHER_MAX_LEN - 4 - sizeof(*wh))) {
|
2006-08-07 08:05:10 +00:00
|
|
|
log(LOG_NOTICE, "ng_pppoe: tags too long\n");
|
1999-10-21 09:06:11 +00:00
|
|
|
sp->neg->numtags = count;
|
|
|
|
break; /* XXX chop off what's too long */
|
|
|
|
}
|
2002-06-05 23:35:31 +00:00
|
|
|
bcopy(*tag, (char *)dp, tlen);
|
1999-10-21 09:06:11 +00:00
|
|
|
length += tlen;
|
|
|
|
dp += tlen;
|
|
|
|
}
|
|
|
|
wh->ph.length = htons(length);
|
|
|
|
sp->neg->m->m_len = length + sizeof(*wh);
|
|
|
|
sp->neg->m->m_pkthdr.len = length + sizeof(*wh);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
From the RFC2516 it is not clear, what is the correct behavior for a
PPPoE AC, servicing a specific Service-Name, when client sends a PADI
with an empty Service-Name. Should it reply with all available service
names or should it be silent? Our implementation had chosen the latter,
while some other had chosen the former (they say Linux and Cisco). Now
some PPPoE clients appear, that rely on the assumption that AC will
send all names in a PADO reply to a PADI with wildcard Service-Name.
These clients can't connect to FreeBSD AC.
I have requested comments from authors of RFC2516 via email, but
received no reply.
This change makes FreeBSD AC compatible with D-Link DI-614+ and
D-Link DI-624+ SOHO routers, and probably others.
Big thanks to D-Link's Russian office, namely Victor Platov, for
assistance and support in investigation and testing of this change.
Details:
o Split pppoe_match_svc() into three different functions serving
different purposes:
- pppoe_match_svc() - match non-empty Service-Name tag from PADI
against all available hooks in listening state.
- pppoe_find_svc() - check that given Service-Name is not yet
registered.
- pppoe_broadcast_padi() - send a copy of PADI packet with empty
Service-Name tag to all listening hooks.
o For NGM_PPPOE_LISTEN message use pppoe_find_svc().
o In ng_pppoe_rcvdata() in a PADI case use pppoe_match_svc() for
a non-empty Service-Name tag, and pppoe_broadcast_padi() in
either case.
A side effect from the above changes is that now pppoed(8) and mpd
will reply to a empty Service-Name PADI sending a PADO with two
Service-Name tags - an empty one and correct one. This is not fatal,
and will be corrected in pppoed(8) and mpd later. No need to update
node interface version.
Supported by: D-Link
2006-01-26 13:06:49 +00:00
|
|
|
* Routines to match a service. *
|
1999-10-21 09:06:11 +00:00
|
|
|
**************************************************************************/
|
From the RFC2516 it is not clear, what is the correct behavior for a
PPPoE AC, servicing a specific Service-Name, when client sends a PADI
with an empty Service-Name. Should it reply with all available service
names or should it be silent? Our implementation had chosen the latter,
while some other had chosen the former (they say Linux and Cisco). Now
some PPPoE clients appear, that rely on the assumption that AC will
send all names in a PADO reply to a PADI with wildcard Service-Name.
These clients can't connect to FreeBSD AC.
I have requested comments from authors of RFC2516 via email, but
received no reply.
This change makes FreeBSD AC compatible with D-Link DI-614+ and
D-Link DI-624+ SOHO routers, and probably others.
Big thanks to D-Link's Russian office, namely Victor Platov, for
assistance and support in investigation and testing of this change.
Details:
o Split pppoe_match_svc() into three different functions serving
different purposes:
- pppoe_match_svc() - match non-empty Service-Name tag from PADI
against all available hooks in listening state.
- pppoe_find_svc() - check that given Service-Name is not yet
registered.
- pppoe_broadcast_padi() - send a copy of PADI packet with empty
Service-Name tag to all listening hooks.
o For NGM_PPPOE_LISTEN message use pppoe_find_svc().
o In ng_pppoe_rcvdata() in a PADI case use pppoe_match_svc() for
a non-empty Service-Name tag, and pppoe_broadcast_padi() in
either case.
A side effect from the above changes is that now pppoed(8) and mpd
will reply to a empty Service-Name PADI sending a PADO with two
Service-Name tags - an empty one and correct one. This is not fatal,
and will be corrected in pppoed(8) and mpd later. No need to update
node interface version.
Supported by: D-Link
2006-01-26 13:06:49 +00:00
|
|
|
|
2006-01-21 08:13:19 +00:00
|
|
|
/*
|
1999-10-21 09:06:11 +00:00
|
|
|
* Find a hook that has a service string that matches that
|
From the RFC2516 it is not clear, what is the correct behavior for a
PPPoE AC, servicing a specific Service-Name, when client sends a PADI
with an empty Service-Name. Should it reply with all available service
names or should it be silent? Our implementation had chosen the latter,
while some other had chosen the former (they say Linux and Cisco). Now
some PPPoE clients appear, that rely on the assumption that AC will
send all names in a PADO reply to a PADI with wildcard Service-Name.
These clients can't connect to FreeBSD AC.
I have requested comments from authors of RFC2516 via email, but
received no reply.
This change makes FreeBSD AC compatible with D-Link DI-614+ and
D-Link DI-624+ SOHO routers, and probably others.
Big thanks to D-Link's Russian office, namely Victor Platov, for
assistance and support in investigation and testing of this change.
Details:
o Split pppoe_match_svc() into three different functions serving
different purposes:
- pppoe_match_svc() - match non-empty Service-Name tag from PADI
against all available hooks in listening state.
- pppoe_find_svc() - check that given Service-Name is not yet
registered.
- pppoe_broadcast_padi() - send a copy of PADI packet with empty
Service-Name tag to all listening hooks.
o For NGM_PPPOE_LISTEN message use pppoe_find_svc().
o In ng_pppoe_rcvdata() in a PADI case use pppoe_match_svc() for
a non-empty Service-Name tag, and pppoe_broadcast_padi() in
either case.
A side effect from the above changes is that now pppoed(8) and mpd
will reply to a empty Service-Name PADI sending a PADO with two
Service-Name tags - an empty one and correct one. This is not fatal,
and will be corrected in pppoed(8) and mpd later. No need to update
node interface version.
Supported by: D-Link
2006-01-26 13:06:49 +00:00
|
|
|
* we are seeking. For now use a simple string.
|
1999-10-21 09:06:11 +00:00
|
|
|
* In the future we may need something like regexp().
|
From the RFC2516 it is not clear, what is the correct behavior for a
PPPoE AC, servicing a specific Service-Name, when client sends a PADI
with an empty Service-Name. Should it reply with all available service
names or should it be silent? Our implementation had chosen the latter,
while some other had chosen the former (they say Linux and Cisco). Now
some PPPoE clients appear, that rely on the assumption that AC will
send all names in a PADO reply to a PADI with wildcard Service-Name.
These clients can't connect to FreeBSD AC.
I have requested comments from authors of RFC2516 via email, but
received no reply.
This change makes FreeBSD AC compatible with D-Link DI-614+ and
D-Link DI-624+ SOHO routers, and probably others.
Big thanks to D-Link's Russian office, namely Victor Platov, for
assistance and support in investigation and testing of this change.
Details:
o Split pppoe_match_svc() into three different functions serving
different purposes:
- pppoe_match_svc() - match non-empty Service-Name tag from PADI
against all available hooks in listening state.
- pppoe_find_svc() - check that given Service-Name is not yet
registered.
- pppoe_broadcast_padi() - send a copy of PADI packet with empty
Service-Name tag to all listening hooks.
o For NGM_PPPOE_LISTEN message use pppoe_find_svc().
o In ng_pppoe_rcvdata() in a PADI case use pppoe_match_svc() for
a non-empty Service-Name tag, and pppoe_broadcast_padi() in
either case.
A side effect from the above changes is that now pppoed(8) and mpd
will reply to a empty Service-Name PADI sending a PADO with two
Service-Name tags - an empty one and correct one. This is not fatal,
and will be corrected in pppoed(8) and mpd later. No need to update
node interface version.
Supported by: D-Link
2006-01-26 13:06:49 +00:00
|
|
|
*
|
|
|
|
* Null string is a wildcard (ANY service), according to RFC2516.
|
|
|
|
* And historical FreeBSD wildcard is also "*".
|
1999-10-21 09:06:11 +00:00
|
|
|
*/
|
2001-07-25 03:34:07 +00:00
|
|
|
|
1999-10-21 09:06:11 +00:00
|
|
|
static hook_p
|
From the RFC2516 it is not clear, what is the correct behavior for a
PPPoE AC, servicing a specific Service-Name, when client sends a PADI
with an empty Service-Name. Should it reply with all available service
names or should it be silent? Our implementation had chosen the latter,
while some other had chosen the former (they say Linux and Cisco). Now
some PPPoE clients appear, that rely on the assumption that AC will
send all names in a PADO reply to a PADI with wildcard Service-Name.
These clients can't connect to FreeBSD AC.
I have requested comments from authors of RFC2516 via email, but
received no reply.
This change makes FreeBSD AC compatible with D-Link DI-614+ and
D-Link DI-624+ SOHO routers, and probably others.
Big thanks to D-Link's Russian office, namely Victor Platov, for
assistance and support in investigation and testing of this change.
Details:
o Split pppoe_match_svc() into three different functions serving
different purposes:
- pppoe_match_svc() - match non-empty Service-Name tag from PADI
against all available hooks in listening state.
- pppoe_find_svc() - check that given Service-Name is not yet
registered.
- pppoe_broadcast_padi() - send a copy of PADI packet with empty
Service-Name tag to all listening hooks.
o For NGM_PPPOE_LISTEN message use pppoe_find_svc().
o In ng_pppoe_rcvdata() in a PADI case use pppoe_match_svc() for
a non-empty Service-Name tag, and pppoe_broadcast_padi() in
either case.
A side effect from the above changes is that now pppoed(8) and mpd
will reply to a empty Service-Name PADI sending a PADO with two
Service-Name tags - an empty one and correct one. This is not fatal,
and will be corrected in pppoed(8) and mpd later. No need to update
node interface version.
Supported by: D-Link
2006-01-26 13:06:49 +00:00
|
|
|
pppoe_match_svc(node_p node, const struct pppoe_tag *tag)
|
1999-10-21 09:06:11 +00:00
|
|
|
{
|
2008-03-03 19:36:03 +00:00
|
|
|
const priv_p privp = NG_NODE_PRIVATE(node);
|
|
|
|
sessp sp;
|
1999-10-21 09:06:11 +00:00
|
|
|
|
2008-03-03 19:36:03 +00:00
|
|
|
LIST_FOREACH(sp, &privp->listeners, sessions) {
|
|
|
|
negp neg = sp->neg;
|
1999-10-21 09:06:11 +00:00
|
|
|
|
From the RFC2516 it is not clear, what is the correct behavior for a
PPPoE AC, servicing a specific Service-Name, when client sends a PADI
with an empty Service-Name. Should it reply with all available service
names or should it be silent? Our implementation had chosen the latter,
while some other had chosen the former (they say Linux and Cisco). Now
some PPPoE clients appear, that rely on the assumption that AC will
send all names in a PADO reply to a PADI with wildcard Service-Name.
These clients can't connect to FreeBSD AC.
I have requested comments from authors of RFC2516 via email, but
received no reply.
This change makes FreeBSD AC compatible with D-Link DI-614+ and
D-Link DI-624+ SOHO routers, and probably others.
Big thanks to D-Link's Russian office, namely Victor Platov, for
assistance and support in investigation and testing of this change.
Details:
o Split pppoe_match_svc() into three different functions serving
different purposes:
- pppoe_match_svc() - match non-empty Service-Name tag from PADI
against all available hooks in listening state.
- pppoe_find_svc() - check that given Service-Name is not yet
registered.
- pppoe_broadcast_padi() - send a copy of PADI packet with empty
Service-Name tag to all listening hooks.
o For NGM_PPPOE_LISTEN message use pppoe_find_svc().
o In ng_pppoe_rcvdata() in a PADI case use pppoe_match_svc() for
a non-empty Service-Name tag, and pppoe_broadcast_padi() in
either case.
A side effect from the above changes is that now pppoed(8) and mpd
will reply to a empty Service-Name PADI sending a PADO with two
Service-Name tags - an empty one and correct one. This is not fatal,
and will be corrected in pppoed(8) and mpd later. No need to update
node interface version.
Supported by: D-Link
2006-01-26 13:06:49 +00:00
|
|
|
/* Empty Service-Name matches any service. */
|
|
|
|
if (neg->service_len == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Special case for a blank or "*" service name (wildcard). */
|
|
|
|
if (neg->service_len == 1 && neg->service.data[0] == '*')
|
|
|
|
break;
|
1999-10-21 09:06:11 +00:00
|
|
|
|
|
|
|
/* If the lengths don't match, that aint it. */
|
From the RFC2516 it is not clear, what is the correct behavior for a
PPPoE AC, servicing a specific Service-Name, when client sends a PADI
with an empty Service-Name. Should it reply with all available service
names or should it be silent? Our implementation had chosen the latter,
while some other had chosen the former (they say Linux and Cisco). Now
some PPPoE clients appear, that rely on the assumption that AC will
send all names in a PADO reply to a PADI with wildcard Service-Name.
These clients can't connect to FreeBSD AC.
I have requested comments from authors of RFC2516 via email, but
received no reply.
This change makes FreeBSD AC compatible with D-Link DI-614+ and
D-Link DI-624+ SOHO routers, and probably others.
Big thanks to D-Link's Russian office, namely Victor Platov, for
assistance and support in investigation and testing of this change.
Details:
o Split pppoe_match_svc() into three different functions serving
different purposes:
- pppoe_match_svc() - match non-empty Service-Name tag from PADI
against all available hooks in listening state.
- pppoe_find_svc() - check that given Service-Name is not yet
registered.
- pppoe_broadcast_padi() - send a copy of PADI packet with empty
Service-Name tag to all listening hooks.
o For NGM_PPPOE_LISTEN message use pppoe_find_svc().
o In ng_pppoe_rcvdata() in a PADI case use pppoe_match_svc() for
a non-empty Service-Name tag, and pppoe_broadcast_padi() in
either case.
A side effect from the above changes is that now pppoed(8) and mpd
will reply to a empty Service-Name PADI sending a PADO with two
Service-Name tags - an empty one and correct one. This is not fatal,
and will be corrected in pppoed(8) and mpd later. No need to update
node interface version.
Supported by: D-Link
2006-01-26 13:06:49 +00:00
|
|
|
if (neg->service_len != ntohs(tag->tag_len))
|
1999-10-21 09:06:11 +00:00
|
|
|
continue;
|
|
|
|
|
2009-03-03 18:47:33 +00:00
|
|
|
if (strncmp((const char *)(tag + 1), neg->service.data,
|
From the RFC2516 it is not clear, what is the correct behavior for a
PPPoE AC, servicing a specific Service-Name, when client sends a PADI
with an empty Service-Name. Should it reply with all available service
names or should it be silent? Our implementation had chosen the latter,
while some other had chosen the former (they say Linux and Cisco). Now
some PPPoE clients appear, that rely on the assumption that AC will
send all names in a PADO reply to a PADI with wildcard Service-Name.
These clients can't connect to FreeBSD AC.
I have requested comments from authors of RFC2516 via email, but
received no reply.
This change makes FreeBSD AC compatible with D-Link DI-614+ and
D-Link DI-624+ SOHO routers, and probably others.
Big thanks to D-Link's Russian office, namely Victor Platov, for
assistance and support in investigation and testing of this change.
Details:
o Split pppoe_match_svc() into three different functions serving
different purposes:
- pppoe_match_svc() - match non-empty Service-Name tag from PADI
against all available hooks in listening state.
- pppoe_find_svc() - check that given Service-Name is not yet
registered.
- pppoe_broadcast_padi() - send a copy of PADI packet with empty
Service-Name tag to all listening hooks.
o For NGM_PPPOE_LISTEN message use pppoe_find_svc().
o In ng_pppoe_rcvdata() in a PADI case use pppoe_match_svc() for
a non-empty Service-Name tag, and pppoe_broadcast_padi() in
either case.
A side effect from the above changes is that now pppoed(8) and mpd
will reply to a empty Service-Name PADI sending a PADO with two
Service-Name tags - an empty one and correct one. This is not fatal,
and will be corrected in pppoed(8) and mpd later. No need to update
node interface version.
Supported by: D-Link
2006-01-26 13:06:49 +00:00
|
|
|
ntohs(tag->tag_len)) == 0)
|
2001-07-25 03:34:07 +00:00
|
|
|
break;
|
From the RFC2516 it is not clear, what is the correct behavior for a
PPPoE AC, servicing a specific Service-Name, when client sends a PADI
with an empty Service-Name. Should it reply with all available service
names or should it be silent? Our implementation had chosen the latter,
while some other had chosen the former (they say Linux and Cisco). Now
some PPPoE clients appear, that rely on the assumption that AC will
send all names in a PADO reply to a PADI with wildcard Service-Name.
These clients can't connect to FreeBSD AC.
I have requested comments from authors of RFC2516 via email, but
received no reply.
This change makes FreeBSD AC compatible with D-Link DI-614+ and
D-Link DI-624+ SOHO routers, and probably others.
Big thanks to D-Link's Russian office, namely Victor Platov, for
assistance and support in investigation and testing of this change.
Details:
o Split pppoe_match_svc() into three different functions serving
different purposes:
- pppoe_match_svc() - match non-empty Service-Name tag from PADI
against all available hooks in listening state.
- pppoe_find_svc() - check that given Service-Name is not yet
registered.
- pppoe_broadcast_padi() - send a copy of PADI packet with empty
Service-Name tag to all listening hooks.
o For NGM_PPPOE_LISTEN message use pppoe_find_svc().
o In ng_pppoe_rcvdata() in a PADI case use pppoe_match_svc() for
a non-empty Service-Name tag, and pppoe_broadcast_padi() in
either case.
A side effect from the above changes is that now pppoed(8) and mpd
will reply to a empty Service-Name PADI sending a PADO with two
Service-Name tags - an empty one and correct one. This is not fatal,
and will be corrected in pppoed(8) and mpd later. No need to update
node interface version.
Supported by: D-Link
2006-01-26 13:06:49 +00:00
|
|
|
}
|
2008-03-03 19:36:03 +00:00
|
|
|
CTR3(KTR_NET, "%20s: matched %p for %s", __func__,
|
2009-03-03 18:47:33 +00:00
|
|
|
sp?sp->hook:NULL, (const char *)(tag + 1));
|
2001-07-25 03:34:07 +00:00
|
|
|
|
2008-03-03 19:36:03 +00:00
|
|
|
return (sp?sp->hook:NULL);
|
From the RFC2516 it is not clear, what is the correct behavior for a
PPPoE AC, servicing a specific Service-Name, when client sends a PADI
with an empty Service-Name. Should it reply with all available service
names or should it be silent? Our implementation had chosen the latter,
while some other had chosen the former (they say Linux and Cisco). Now
some PPPoE clients appear, that rely on the assumption that AC will
send all names in a PADO reply to a PADI with wildcard Service-Name.
These clients can't connect to FreeBSD AC.
I have requested comments from authors of RFC2516 via email, but
received no reply.
This change makes FreeBSD AC compatible with D-Link DI-614+ and
D-Link DI-624+ SOHO routers, and probably others.
Big thanks to D-Link's Russian office, namely Victor Platov, for
assistance and support in investigation and testing of this change.
Details:
o Split pppoe_match_svc() into three different functions serving
different purposes:
- pppoe_match_svc() - match non-empty Service-Name tag from PADI
against all available hooks in listening state.
- pppoe_find_svc() - check that given Service-Name is not yet
registered.
- pppoe_broadcast_padi() - send a copy of PADI packet with empty
Service-Name tag to all listening hooks.
o For NGM_PPPOE_LISTEN message use pppoe_find_svc().
o In ng_pppoe_rcvdata() in a PADI case use pppoe_match_svc() for
a non-empty Service-Name tag, and pppoe_broadcast_padi() in
either case.
A side effect from the above changes is that now pppoed(8) and mpd
will reply to a empty Service-Name PADI sending a PADO with two
Service-Name tags - an empty one and correct one. This is not fatal,
and will be corrected in pppoed(8) and mpd later. No need to update
node interface version.
Supported by: D-Link
2006-01-26 13:06:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Broadcast the PADI packet in m0 to all listening hooks.
|
|
|
|
* This routine is called when a PADI with empty Service-Name
|
|
|
|
* tag is received. Client should receive PADOs with all
|
|
|
|
* available services.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
pppoe_broadcast_padi(node_p node, struct mbuf *m0)
|
|
|
|
{
|
2008-03-03 19:36:03 +00:00
|
|
|
const priv_p privp = NG_NODE_PRIVATE(node);
|
|
|
|
sessp sp;
|
From the RFC2516 it is not clear, what is the correct behavior for a
PPPoE AC, servicing a specific Service-Name, when client sends a PADI
with an empty Service-Name. Should it reply with all available service
names or should it be silent? Our implementation had chosen the latter,
while some other had chosen the former (they say Linux and Cisco). Now
some PPPoE clients appear, that rely on the assumption that AC will
send all names in a PADO reply to a PADI with wildcard Service-Name.
These clients can't connect to FreeBSD AC.
I have requested comments from authors of RFC2516 via email, but
received no reply.
This change makes FreeBSD AC compatible with D-Link DI-614+ and
D-Link DI-624+ SOHO routers, and probably others.
Big thanks to D-Link's Russian office, namely Victor Platov, for
assistance and support in investigation and testing of this change.
Details:
o Split pppoe_match_svc() into three different functions serving
different purposes:
- pppoe_match_svc() - match non-empty Service-Name tag from PADI
against all available hooks in listening state.
- pppoe_find_svc() - check that given Service-Name is not yet
registered.
- pppoe_broadcast_padi() - send a copy of PADI packet with empty
Service-Name tag to all listening hooks.
o For NGM_PPPOE_LISTEN message use pppoe_find_svc().
o In ng_pppoe_rcvdata() in a PADI case use pppoe_match_svc() for
a non-empty Service-Name tag, and pppoe_broadcast_padi() in
either case.
A side effect from the above changes is that now pppoed(8) and mpd
will reply to a empty Service-Name PADI sending a PADO with two
Service-Name tags - an empty one and correct one. This is not fatal,
and will be corrected in pppoed(8) and mpd later. No need to update
node interface version.
Supported by: D-Link
2006-01-26 13:06:49 +00:00
|
|
|
int error = 0;
|
|
|
|
|
2008-03-03 19:36:03 +00:00
|
|
|
LIST_FOREACH(sp, &privp->listeners, sessions) {
|
From the RFC2516 it is not clear, what is the correct behavior for a
PPPoE AC, servicing a specific Service-Name, when client sends a PADI
with an empty Service-Name. Should it reply with all available service
names or should it be silent? Our implementation had chosen the latter,
while some other had chosen the former (they say Linux and Cisco). Now
some PPPoE clients appear, that rely on the assumption that AC will
send all names in a PADO reply to a PADI with wildcard Service-Name.
These clients can't connect to FreeBSD AC.
I have requested comments from authors of RFC2516 via email, but
received no reply.
This change makes FreeBSD AC compatible with D-Link DI-614+ and
D-Link DI-624+ SOHO routers, and probably others.
Big thanks to D-Link's Russian office, namely Victor Platov, for
assistance and support in investigation and testing of this change.
Details:
o Split pppoe_match_svc() into three different functions serving
different purposes:
- pppoe_match_svc() - match non-empty Service-Name tag from PADI
against all available hooks in listening state.
- pppoe_find_svc() - check that given Service-Name is not yet
registered.
- pppoe_broadcast_padi() - send a copy of PADI packet with empty
Service-Name tag to all listening hooks.
o For NGM_PPPOE_LISTEN message use pppoe_find_svc().
o In ng_pppoe_rcvdata() in a PADI case use pppoe_match_svc() for
a non-empty Service-Name tag, and pppoe_broadcast_padi() in
either case.
A side effect from the above changes is that now pppoed(8) and mpd
will reply to a empty Service-Name PADI sending a PADO with two
Service-Name tags - an empty one and correct one. This is not fatal,
and will be corrected in pppoed(8) and mpd later. No need to update
node interface version.
Supported by: D-Link
2006-01-26 13:06:49 +00:00
|
|
|
struct mbuf *m;
|
|
|
|
|
2012-12-05 08:04:20 +00:00
|
|
|
m = m_dup(m0, M_NOWAIT);
|
From the RFC2516 it is not clear, what is the correct behavior for a
PPPoE AC, servicing a specific Service-Name, when client sends a PADI
with an empty Service-Name. Should it reply with all available service
names or should it be silent? Our implementation had chosen the latter,
while some other had chosen the former (they say Linux and Cisco). Now
some PPPoE clients appear, that rely on the assumption that AC will
send all names in a PADO reply to a PADI with wildcard Service-Name.
These clients can't connect to FreeBSD AC.
I have requested comments from authors of RFC2516 via email, but
received no reply.
This change makes FreeBSD AC compatible with D-Link DI-614+ and
D-Link DI-624+ SOHO routers, and probably others.
Big thanks to D-Link's Russian office, namely Victor Platov, for
assistance and support in investigation and testing of this change.
Details:
o Split pppoe_match_svc() into three different functions serving
different purposes:
- pppoe_match_svc() - match non-empty Service-Name tag from PADI
against all available hooks in listening state.
- pppoe_find_svc() - check that given Service-Name is not yet
registered.
- pppoe_broadcast_padi() - send a copy of PADI packet with empty
Service-Name tag to all listening hooks.
o For NGM_PPPOE_LISTEN message use pppoe_find_svc().
o In ng_pppoe_rcvdata() in a PADI case use pppoe_match_svc() for
a non-empty Service-Name tag, and pppoe_broadcast_padi() in
either case.
A side effect from the above changes is that now pppoed(8) and mpd
will reply to a empty Service-Name PADI sending a PADO with two
Service-Name tags - an empty one and correct one. This is not fatal,
and will be corrected in pppoed(8) and mpd later. No need to update
node interface version.
Supported by: D-Link
2006-01-26 13:06:49 +00:00
|
|
|
if (m == NULL)
|
|
|
|
return (ENOMEM);
|
2008-03-03 19:36:03 +00:00
|
|
|
NG_SEND_DATA_ONLY(error, sp->hook, m);
|
From the RFC2516 it is not clear, what is the correct behavior for a
PPPoE AC, servicing a specific Service-Name, when client sends a PADI
with an empty Service-Name. Should it reply with all available service
names or should it be silent? Our implementation had chosen the latter,
while some other had chosen the former (they say Linux and Cisco). Now
some PPPoE clients appear, that rely on the assumption that AC will
send all names in a PADO reply to a PADI with wildcard Service-Name.
These clients can't connect to FreeBSD AC.
I have requested comments from authors of RFC2516 via email, but
received no reply.
This change makes FreeBSD AC compatible with D-Link DI-614+ and
D-Link DI-624+ SOHO routers, and probably others.
Big thanks to D-Link's Russian office, namely Victor Platov, for
assistance and support in investigation and testing of this change.
Details:
o Split pppoe_match_svc() into three different functions serving
different purposes:
- pppoe_match_svc() - match non-empty Service-Name tag from PADI
against all available hooks in listening state.
- pppoe_find_svc() - check that given Service-Name is not yet
registered.
- pppoe_broadcast_padi() - send a copy of PADI packet with empty
Service-Name tag to all listening hooks.
o For NGM_PPPOE_LISTEN message use pppoe_find_svc().
o In ng_pppoe_rcvdata() in a PADI case use pppoe_match_svc() for
a non-empty Service-Name tag, and pppoe_broadcast_padi() in
either case.
A side effect from the above changes is that now pppoed(8) and mpd
will reply to a empty Service-Name PADI sending a PADO with two
Service-Name tags - an empty one and correct one. This is not fatal,
and will be corrected in pppoed(8) and mpd later. No need to update
node interface version.
Supported by: D-Link
2006-01-26 13:06:49 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find a hook, which name equals to given service.
|
|
|
|
*/
|
|
|
|
static hook_p
|
|
|
|
pppoe_find_svc(node_p node, const char *svc_name, int svc_len)
|
|
|
|
{
|
2008-03-03 19:36:03 +00:00
|
|
|
const priv_p privp = NG_NODE_PRIVATE(node);
|
|
|
|
sessp sp;
|
From the RFC2516 it is not clear, what is the correct behavior for a
PPPoE AC, servicing a specific Service-Name, when client sends a PADI
with an empty Service-Name. Should it reply with all available service
names or should it be silent? Our implementation had chosen the latter,
while some other had chosen the former (they say Linux and Cisco). Now
some PPPoE clients appear, that rely on the assumption that AC will
send all names in a PADO reply to a PADI with wildcard Service-Name.
These clients can't connect to FreeBSD AC.
I have requested comments from authors of RFC2516 via email, but
received no reply.
This change makes FreeBSD AC compatible with D-Link DI-614+ and
D-Link DI-624+ SOHO routers, and probably others.
Big thanks to D-Link's Russian office, namely Victor Platov, for
assistance and support in investigation and testing of this change.
Details:
o Split pppoe_match_svc() into three different functions serving
different purposes:
- pppoe_match_svc() - match non-empty Service-Name tag from PADI
against all available hooks in listening state.
- pppoe_find_svc() - check that given Service-Name is not yet
registered.
- pppoe_broadcast_padi() - send a copy of PADI packet with empty
Service-Name tag to all listening hooks.
o For NGM_PPPOE_LISTEN message use pppoe_find_svc().
o In ng_pppoe_rcvdata() in a PADI case use pppoe_match_svc() for
a non-empty Service-Name tag, and pppoe_broadcast_padi() in
either case.
A side effect from the above changes is that now pppoed(8) and mpd
will reply to a empty Service-Name PADI sending a PADO with two
Service-Name tags - an empty one and correct one. This is not fatal,
and will be corrected in pppoed(8) and mpd later. No need to update
node interface version.
Supported by: D-Link
2006-01-26 13:06:49 +00:00
|
|
|
|
2008-03-03 19:36:03 +00:00
|
|
|
LIST_FOREACH(sp, &privp->listeners, sessions) {
|
|
|
|
negp neg = sp->neg;
|
From the RFC2516 it is not clear, what is the correct behavior for a
PPPoE AC, servicing a specific Service-Name, when client sends a PADI
with an empty Service-Name. Should it reply with all available service
names or should it be silent? Our implementation had chosen the latter,
while some other had chosen the former (they say Linux and Cisco). Now
some PPPoE clients appear, that rely on the assumption that AC will
send all names in a PADO reply to a PADI with wildcard Service-Name.
These clients can't connect to FreeBSD AC.
I have requested comments from authors of RFC2516 via email, but
received no reply.
This change makes FreeBSD AC compatible with D-Link DI-614+ and
D-Link DI-624+ SOHO routers, and probably others.
Big thanks to D-Link's Russian office, namely Victor Platov, for
assistance and support in investigation and testing of this change.
Details:
o Split pppoe_match_svc() into three different functions serving
different purposes:
- pppoe_match_svc() - match non-empty Service-Name tag from PADI
against all available hooks in listening state.
- pppoe_find_svc() - check that given Service-Name is not yet
registered.
- pppoe_broadcast_padi() - send a copy of PADI packet with empty
Service-Name tag to all listening hooks.
o For NGM_PPPOE_LISTEN message use pppoe_find_svc().
o In ng_pppoe_rcvdata() in a PADI case use pppoe_match_svc() for
a non-empty Service-Name tag, and pppoe_broadcast_padi() in
either case.
A side effect from the above changes is that now pppoed(8) and mpd
will reply to a empty Service-Name PADI sending a PADO with two
Service-Name tags - an empty one and correct one. This is not fatal,
and will be corrected in pppoed(8) and mpd later. No need to update
node interface version.
Supported by: D-Link
2006-01-26 13:06:49 +00:00
|
|
|
|
|
|
|
if (neg->service_len == svc_len &&
|
2007-12-26 19:33:53 +00:00
|
|
|
strncmp(svc_name, neg->service.data, svc_len) == 0)
|
2008-03-03 19:36:03 +00:00
|
|
|
return (sp->hook);
|
1999-10-21 09:06:11 +00:00
|
|
|
}
|
2006-01-21 08:13:19 +00:00
|
|
|
|
From the RFC2516 it is not clear, what is the correct behavior for a
PPPoE AC, servicing a specific Service-Name, when client sends a PADI
with an empty Service-Name. Should it reply with all available service
names or should it be silent? Our implementation had chosen the latter,
while some other had chosen the former (they say Linux and Cisco). Now
some PPPoE clients appear, that rely on the assumption that AC will
send all names in a PADO reply to a PADI with wildcard Service-Name.
These clients can't connect to FreeBSD AC.
I have requested comments from authors of RFC2516 via email, but
received no reply.
This change makes FreeBSD AC compatible with D-Link DI-614+ and
D-Link DI-624+ SOHO routers, and probably others.
Big thanks to D-Link's Russian office, namely Victor Platov, for
assistance and support in investigation and testing of this change.
Details:
o Split pppoe_match_svc() into three different functions serving
different purposes:
- pppoe_match_svc() - match non-empty Service-Name tag from PADI
against all available hooks in listening state.
- pppoe_find_svc() - check that given Service-Name is not yet
registered.
- pppoe_broadcast_padi() - send a copy of PADI packet with empty
Service-Name tag to all listening hooks.
o For NGM_PPPOE_LISTEN message use pppoe_find_svc().
o In ng_pppoe_rcvdata() in a PADI case use pppoe_match_svc() for
a non-empty Service-Name tag, and pppoe_broadcast_padi() in
either case.
A side effect from the above changes is that now pppoed(8) and mpd
will reply to a empty Service-Name PADI sending a PADO with two
Service-Name tags - an empty one and correct one. This is not fatal,
and will be corrected in pppoed(8) and mpd later. No need to update
node interface version.
Supported by: D-Link
2006-01-26 13:06:49 +00:00
|
|
|
return (NULL);
|
1999-10-21 09:06:11 +00:00
|
|
|
}
|
2006-01-21 08:13:19 +00:00
|
|
|
|
1999-10-21 09:06:11 +00:00
|
|
|
/**************************************************************************
|
2008-01-31 22:42:37 +00:00
|
|
|
* Routines to find a particular session that matches an incoming packet. *
|
1999-10-21 09:06:11 +00:00
|
|
|
**************************************************************************/
|
2008-03-02 23:26:35 +00:00
|
|
|
/* Find free session and add to hash. */
|
|
|
|
static uint16_t
|
|
|
|
pppoe_getnewsession(sessp sp)
|
|
|
|
{
|
|
|
|
const priv_p privp = NG_NODE_PRIVATE(NG_HOOK_NODE(sp->hook));
|
|
|
|
static uint16_t pppoe_sid = 1;
|
|
|
|
sessp tsp;
|
|
|
|
uint16_t val, hash;
|
|
|
|
|
|
|
|
restart:
|
|
|
|
/* Atomicity is not needed here as value will be checked. */
|
|
|
|
val = pppoe_sid++;
|
|
|
|
/* Spec says 0xFFFF is reserved, also don't use 0x0000. */
|
|
|
|
if (val == 0xffff || val == 0x0000)
|
|
|
|
val = pppoe_sid = 1;
|
|
|
|
|
|
|
|
/* Check it isn't already in use. */
|
|
|
|
hash = SESSHASH(val);
|
|
|
|
mtx_lock(&privp->sesshash[hash].mtx);
|
2008-03-03 19:36:03 +00:00
|
|
|
LIST_FOREACH(tsp, &privp->sesshash[hash].head, sessions) {
|
2008-03-02 23:26:35 +00:00
|
|
|
if (tsp->Session_ID == val)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!tsp) {
|
|
|
|
sp->Session_ID = val;
|
2008-03-03 19:36:03 +00:00
|
|
|
LIST_INSERT_HEAD(&privp->sesshash[hash].head, sp, sessions);
|
2008-03-02 23:26:35 +00:00
|
|
|
}
|
|
|
|
mtx_unlock(&privp->sesshash[hash].mtx);
|
|
|
|
if (tsp)
|
|
|
|
goto restart;
|
|
|
|
|
|
|
|
CTR2(KTR_NET, "%20s: new sid %d", __func__, val);
|
|
|
|
|
|
|
|
return (val);
|
|
|
|
}
|
|
|
|
|
2008-01-31 22:42:37 +00:00
|
|
|
/* Add specified session to hash. */
|
|
|
|
static void
|
|
|
|
pppoe_addsession(sessp sp)
|
1999-10-21 09:06:11 +00:00
|
|
|
{
|
2008-01-31 22:42:37 +00:00
|
|
|
const priv_p privp = NG_NODE_PRIVATE(NG_HOOK_NODE(sp->hook));
|
|
|
|
uint16_t hash = SESSHASH(sp->Session_ID);
|
1999-10-21 09:06:11 +00:00
|
|
|
|
2008-01-31 22:42:37 +00:00
|
|
|
mtx_lock(&privp->sesshash[hash].mtx);
|
2008-03-03 19:36:03 +00:00
|
|
|
LIST_INSERT_HEAD(&privp->sesshash[hash].head, sp, sessions);
|
2008-01-31 22:42:37 +00:00
|
|
|
mtx_unlock(&privp->sesshash[hash].mtx);
|
|
|
|
}
|
2007-09-21 08:24:08 +00:00
|
|
|
|
2008-01-31 22:42:37 +00:00
|
|
|
/* Delete specified session from hash. */
|
|
|
|
static void
|
|
|
|
pppoe_delsession(sessp sp)
|
|
|
|
{
|
|
|
|
const priv_p privp = NG_NODE_PRIVATE(NG_HOOK_NODE(sp->hook));
|
|
|
|
uint16_t hash = SESSHASH(sp->Session_ID);
|
|
|
|
|
|
|
|
mtx_lock(&privp->sesshash[hash].mtx);
|
2008-03-03 19:36:03 +00:00
|
|
|
LIST_REMOVE(sp, sessions);
|
2008-01-31 22:42:37 +00:00
|
|
|
mtx_unlock(&privp->sesshash[hash].mtx);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find matching peer/session combination. */
|
|
|
|
static sessp
|
|
|
|
pppoe_findsession(priv_p privp, const struct pppoe_full_hdr *wh)
|
|
|
|
{
|
|
|
|
uint16_t session = ntohs(wh->ph.sid);
|
|
|
|
uint16_t hash = SESSHASH(session);
|
|
|
|
sessp sp = NULL;
|
|
|
|
|
|
|
|
mtx_lock(&privp->sesshash[hash].mtx);
|
2008-03-03 19:36:03 +00:00
|
|
|
LIST_FOREACH(sp, &privp->sesshash[hash].head, sessions) {
|
2007-09-21 08:24:08 +00:00
|
|
|
if (sp->Session_ID == session &&
|
|
|
|
bcmp(sp->pkt_hdr.eh.ether_dhost,
|
|
|
|
wh->eh.ether_shost, ETHER_ADDR_LEN) == 0) {
|
1999-10-21 09:06:11 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-01-31 22:42:37 +00:00
|
|
|
mtx_unlock(&privp->sesshash[hash].mtx);
|
2008-02-01 07:25:06 +00:00
|
|
|
CTR3(KTR_NET, "%20s: matched %p for %d", __func__, sp?sp->hook:NULL,
|
|
|
|
session);
|
2006-01-21 08:13:19 +00:00
|
|
|
|
2008-01-31 22:42:37 +00:00
|
|
|
return (sp);
|
1999-10-21 09:06:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static hook_p
|
2002-06-05 23:35:31 +00:00
|
|
|
pppoe_finduniq(node_p node, const struct pppoe_tag *tag)
|
1999-10-21 09:06:11 +00:00
|
|
|
{
|
2006-01-21 08:13:19 +00:00
|
|
|
hook_p hook = NULL;
|
|
|
|
union uniq uniq;
|
1999-10-21 09:06:11 +00:00
|
|
|
|
2009-03-03 18:47:33 +00:00
|
|
|
bcopy(tag + 1, uniq.bytes, sizeof(void *));
|
2006-01-21 08:13:19 +00:00
|
|
|
/* Cycle through all known hooks. */
|
2001-01-08 05:34:06 +00:00
|
|
|
LIST_FOREACH(hook, &node->nd_hooks, hk_hooks) {
|
2007-09-21 08:24:08 +00:00
|
|
|
/* Skip any nonsession hook. */
|
|
|
|
if (NG_HOOK_PRIVATE(hook) == NULL)
|
1999-10-21 09:06:11 +00:00
|
|
|
continue;
|
2001-01-08 05:34:06 +00:00
|
|
|
if (uniq.pointer == NG_HOOK_PRIVATE(hook))
|
1999-10-21 09:06:11 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-01-21 08:13:19 +00:00
|
|
|
CTR3(KTR_NET, "%20s: matched %p for %p", __func__, hook, uniq.pointer);
|
|
|
|
|
1999-10-21 09:06:11 +00:00
|
|
|
return (hook);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
2006-01-21 08:13:19 +00:00
|
|
|
* Start of Netgraph entrypoints. *
|
1999-10-21 09:06:11 +00:00
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
/*
|
2006-01-21 08:13:19 +00:00
|
|
|
* Allocate the private data structure and link it with node.
|
1999-10-21 09:06:11 +00:00
|
|
|
*/
|
|
|
|
static int
|
2001-01-06 00:46:47 +00:00
|
|
|
ng_pppoe_constructor(node_p node)
|
1999-10-21 09:06:11 +00:00
|
|
|
{
|
2008-01-31 22:42:37 +00:00
|
|
|
priv_p privp;
|
|
|
|
int i;
|
1999-10-21 09:06:11 +00:00
|
|
|
|
2006-01-21 08:13:19 +00:00
|
|
|
/* Initialize private descriptor. */
|
2011-04-18 09:12:27 +00:00
|
|
|
privp = malloc(sizeof(*privp), M_NETGRAPH_PPPOE, M_WAITOK | M_ZERO);
|
1999-10-21 09:06:11 +00:00
|
|
|
|
2006-01-21 08:13:19 +00:00
|
|
|
/* Link structs together; this counts as our one reference to *node. */
|
|
|
|
NG_NODE_SET_PRIVATE(node, privp);
|
|
|
|
privp->node = node;
|
2004-07-27 19:47:13 +00:00
|
|
|
|
2006-01-27 10:56:22 +00:00
|
|
|
/* Initialize to standard mode. */
|
2006-08-09 09:56:58 +00:00
|
|
|
memset(&privp->eh.ether_dhost, 0xff, ETHER_ADDR_LEN);
|
|
|
|
privp->eh.ether_type = ETHERTYPE_PPPOE_DISC;
|
2006-01-21 08:13:19 +00:00
|
|
|
|
2008-03-03 19:36:03 +00:00
|
|
|
LIST_INIT(&privp->listeners);
|
2008-01-31 22:42:37 +00:00
|
|
|
for (i = 0; i < SESSHASHSIZE; i++) {
|
|
|
|
mtx_init(&privp->sesshash[i].mtx, "PPPoE hash mutex", NULL, MTX_DEF);
|
2008-03-03 19:36:03 +00:00
|
|
|
LIST_INIT(&privp->sesshash[i].head);
|
2008-01-31 22:42:37 +00:00
|
|
|
}
|
|
|
|
|
2006-01-21 08:13:19 +00:00
|
|
|
CTR3(KTR_NET, "%20s: created node [%x] (%p)",
|
|
|
|
__func__, node->nd_ID, node);
|
|
|
|
|
1999-10-21 09:06:11 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Give our ok for a hook to be added...
|
|
|
|
* point the hook's private info to the hook structure.
|
|
|
|
*
|
|
|
|
* The following hook names are special:
|
2006-01-21 08:13:19 +00:00
|
|
|
* "ethernet": the hook that should be connected to a NIC.
|
|
|
|
* "debug": copies of data sent out here (when I write the code).
|
2000-12-12 18:52:14 +00:00
|
|
|
* All other hook names need only be unique. (the framework checks this).
|
1999-10-21 09:06:11 +00:00
|
|
|
*/
|
|
|
|
static int
|
1999-10-27 11:29:51 +00:00
|
|
|
ng_pppoe_newhook(node_p node, hook_p hook, const char *name)
|
1999-10-21 09:06:11 +00:00
|
|
|
{
|
2001-01-08 05:34:06 +00:00
|
|
|
const priv_p privp = NG_NODE_PRIVATE(node);
|
1999-10-21 09:06:11 +00:00
|
|
|
sessp sp;
|
|
|
|
|
|
|
|
if (strcmp(name, NG_PPPOE_HOOK_ETHERNET) == 0) {
|
|
|
|
privp->ethernet_hook = hook;
|
2007-10-14 09:58:22 +00:00
|
|
|
NG_HOOK_SET_RCVDATA(hook, ng_pppoe_rcvdata_ether);
|
1999-10-21 09:06:11 +00:00
|
|
|
} else if (strcmp(name, NG_PPPOE_HOOK_DEBUG) == 0) {
|
|
|
|
privp->debug_hook = hook;
|
2007-10-14 09:58:22 +00:00
|
|
|
NG_HOOK_SET_RCVDATA(hook, ng_pppoe_rcvdata_debug);
|
1999-10-21 09:06:11 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Any other unique name is OK.
|
|
|
|
* The infrastructure has already checked that it's unique,
|
|
|
|
* so just allocate it and hook it in.
|
|
|
|
*/
|
2006-01-21 08:13:19 +00:00
|
|
|
sp = malloc(sizeof(*sp), M_NETGRAPH_PPPOE, M_NOWAIT | M_ZERO);
|
|
|
|
if (sp == NULL)
|
|
|
|
return (ENOMEM);
|
1999-10-21 09:06:11 +00:00
|
|
|
|
2001-01-08 05:34:06 +00:00
|
|
|
NG_HOOK_SET_PRIVATE(hook, sp);
|
1999-10-21 09:06:11 +00:00
|
|
|
sp->hook = hook;
|
|
|
|
}
|
2006-01-21 08:13:19 +00:00
|
|
|
CTR5(KTR_NET, "%20s: node [%x] (%p) connected hook %s (%p)",
|
|
|
|
__func__, node->nd_ID, node, name, hook);
|
|
|
|
|
1999-10-21 09:06:11 +00:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2006-08-09 09:56:58 +00:00
|
|
|
/*
|
|
|
|
* Hook has been added successfully. Request the MAC address of
|
|
|
|
* the underlying Ethernet node.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ng_pppoe_connect(hook_p hook)
|
|
|
|
{
|
|
|
|
const priv_p privp = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
|
|
|
|
struct ng_mesg *msg;
|
2006-08-10 11:07:11 +00:00
|
|
|
int error;
|
2006-08-09 09:56:58 +00:00
|
|
|
|
|
|
|
if (hook != privp->ethernet_hook)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If this is Ethernet hook, then request MAC address
|
|
|
|
* from our downstream.
|
|
|
|
*/
|
|
|
|
NG_MKMESSAGE(msg, NGM_ETHER_COOKIE, NGM_ETHER_GET_ENADDR, 0, M_NOWAIT);
|
|
|
|
if (msg == NULL)
|
|
|
|
return (ENOBUFS);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Our hook and peer hook have HK_INVALID flag set,
|
|
|
|
* so we can't use NG_SEND_MSG_HOOK() macro here.
|
|
|
|
*/
|
|
|
|
NG_SEND_MSG_ID(error, privp->node, msg,
|
|
|
|
NG_NODE_ID(NG_PEER_NODE(privp->ethernet_hook)),
|
|
|
|
NG_NODE_ID(privp->node));
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
1999-10-21 09:06:11 +00:00
|
|
|
/*
|
|
|
|
* Get a netgraph control message.
|
|
|
|
* Check it is one we understand. If needed, send a response.
|
|
|
|
* We sometimes save the address for an async action later.
|
|
|
|
* Always free the message.
|
|
|
|
*/
|
|
|
|
static int
|
2001-01-06 00:46:47 +00:00
|
|
|
ng_pppoe_rcvmsg(node_p node, item_p item, hook_p lasthook)
|
1999-10-21 09:06:11 +00:00
|
|
|
{
|
2001-01-08 05:34:06 +00:00
|
|
|
priv_p privp = NG_NODE_PRIVATE(node);
|
1999-10-27 11:29:51 +00:00
|
|
|
struct ngpppoe_init_data *ourmsg = NULL;
|
1999-10-21 09:06:11 +00:00
|
|
|
struct ng_mesg *resp = NULL;
|
|
|
|
int error = 0;
|
|
|
|
hook_p hook = NULL;
|
|
|
|
sessp sp = NULL;
|
|
|
|
negp neg = NULL;
|
2001-01-06 00:46:47 +00:00
|
|
|
struct ng_mesg *msg;
|
1999-10-21 09:06:11 +00:00
|
|
|
|
2001-01-06 00:46:47 +00:00
|
|
|
NGI_GET_MSG(item, msg);
|
2006-01-21 08:13:19 +00:00
|
|
|
CTR5(KTR_NET, "%20s: node [%x] (%p) got message %d with cookie %d",
|
|
|
|
__func__, node->nd_ID, node, msg->header.cmd,
|
|
|
|
msg->header.typecookie);
|
|
|
|
|
|
|
|
/* Deal with message according to cookie and command. */
|
1999-10-21 09:06:11 +00:00
|
|
|
switch (msg->header.typecookie) {
|
2006-01-21 08:13:19 +00:00
|
|
|
case NGM_PPPOE_COOKIE:
|
1999-10-21 09:06:11 +00:00
|
|
|
switch (msg->header.cmd) {
|
|
|
|
case NGM_PPPOE_CONNECT:
|
2006-01-21 08:13:19 +00:00
|
|
|
case NGM_PPPOE_LISTEN:
|
|
|
|
case NGM_PPPOE_OFFER:
|
|
|
|
case NGM_PPPOE_SERVICE:
|
1999-10-27 11:29:51 +00:00
|
|
|
ourmsg = (struct ngpppoe_init_data *)msg->data;
|
2000-11-16 23:14:53 +00:00
|
|
|
if (msg->header.arglen < sizeof(*ourmsg)) {
|
2006-08-07 08:05:10 +00:00
|
|
|
log(LOG_ERR, "ng_pppoe[%x]: init data too "
|
|
|
|
"small\n", node->nd_ID);
|
2000-11-16 23:14:53 +00:00
|
|
|
LEAVE(EMSGSIZE);
|
|
|
|
}
|
2006-01-21 08:13:19 +00:00
|
|
|
if (msg->header.arglen - sizeof(*ourmsg) >
|
2000-10-31 02:45:24 +00:00
|
|
|
PPPOE_SERVICE_NAME_SIZE) {
|
2006-08-07 08:05:10 +00:00
|
|
|
log(LOG_ERR, "ng_pppoe[%x]: service name "
|
|
|
|
"too big\n", node->nd_ID);
|
1999-10-21 09:06:11 +00:00
|
|
|
LEAVE(EMSGSIZE);
|
|
|
|
}
|
2000-11-16 23:14:53 +00:00
|
|
|
if (msg->header.arglen - sizeof(*ourmsg) <
|
|
|
|
ourmsg->data_len) {
|
2006-08-07 08:05:10 +00:00
|
|
|
log(LOG_ERR, "ng_pppoe[%x]: init data has bad "
|
|
|
|
"length, %d should be %zd\n", node->nd_ID,
|
|
|
|
ourmsg->data_len,
|
2000-11-16 23:14:53 +00:00
|
|
|
msg->header.arglen - sizeof (*ourmsg));
|
1999-10-21 09:06:11 +00:00
|
|
|
LEAVE(EMSGSIZE);
|
|
|
|
}
|
2000-10-31 02:45:24 +00:00
|
|
|
|
2006-01-21 08:13:19 +00:00
|
|
|
/* Make sure strcmp will terminate safely. */
|
1999-10-21 09:06:11 +00:00
|
|
|
ourmsg->hook[sizeof(ourmsg->hook) - 1] = '\0';
|
|
|
|
|
2008-03-03 19:36:03 +00:00
|
|
|
/* Find hook by name. */
|
|
|
|
hook = ng_findhook(node, ourmsg->hook);
|
2006-01-21 08:13:19 +00:00
|
|
|
if (hook == NULL)
|
1999-10-21 09:06:11 +00:00
|
|
|
LEAVE(ENOENT);
|
2006-01-21 08:13:19 +00:00
|
|
|
|
2001-01-08 05:34:06 +00:00
|
|
|
sp = NG_HOOK_PRIVATE(hook);
|
2007-09-21 08:24:08 +00:00
|
|
|
if (sp == NULL)
|
|
|
|
LEAVE(EINVAL);
|
|
|
|
|
2001-07-25 03:34:07 +00:00
|
|
|
if (msg->header.cmd == NGM_PPPOE_LISTEN) {
|
|
|
|
/*
|
|
|
|
* Ensure we aren't already listening for this
|
|
|
|
* service.
|
|
|
|
*/
|
From the RFC2516 it is not clear, what is the correct behavior for a
PPPoE AC, servicing a specific Service-Name, when client sends a PADI
with an empty Service-Name. Should it reply with all available service
names or should it be silent? Our implementation had chosen the latter,
while some other had chosen the former (they say Linux and Cisco). Now
some PPPoE clients appear, that rely on the assumption that AC will
send all names in a PADO reply to a PADI with wildcard Service-Name.
These clients can't connect to FreeBSD AC.
I have requested comments from authors of RFC2516 via email, but
received no reply.
This change makes FreeBSD AC compatible with D-Link DI-614+ and
D-Link DI-624+ SOHO routers, and probably others.
Big thanks to D-Link's Russian office, namely Victor Platov, for
assistance and support in investigation and testing of this change.
Details:
o Split pppoe_match_svc() into three different functions serving
different purposes:
- pppoe_match_svc() - match non-empty Service-Name tag from PADI
against all available hooks in listening state.
- pppoe_find_svc() - check that given Service-Name is not yet
registered.
- pppoe_broadcast_padi() - send a copy of PADI packet with empty
Service-Name tag to all listening hooks.
o For NGM_PPPOE_LISTEN message use pppoe_find_svc().
o In ng_pppoe_rcvdata() in a PADI case use pppoe_match_svc() for
a non-empty Service-Name tag, and pppoe_broadcast_padi() in
either case.
A side effect from the above changes is that now pppoed(8) and mpd
will reply to a empty Service-Name PADI sending a PADO with two
Service-Name tags - an empty one and correct one. This is not fatal,
and will be corrected in pppoed(8) and mpd later. No need to update
node interface version.
Supported by: D-Link
2006-01-26 13:06:49 +00:00
|
|
|
if (pppoe_find_svc(node, ourmsg->data,
|
|
|
|
ourmsg->data_len) != NULL)
|
2001-07-25 03:34:07 +00:00
|
|
|
LEAVE(EEXIST);
|
|
|
|
}
|
|
|
|
|
2000-12-12 18:52:14 +00:00
|
|
|
/*
|
|
|
|
* PPPOE_SERVICE advertisments are set up
|
|
|
|
* on sessions that are in PRIMED state.
|
|
|
|
*/
|
2006-01-21 08:13:19 +00:00
|
|
|
if (msg->header.cmd == NGM_PPPOE_SERVICE)
|
2000-12-12 18:52:14 +00:00
|
|
|
break;
|
2006-01-21 08:13:19 +00:00
|
|
|
|
2005-09-19 11:49:54 +00:00
|
|
|
if (sp->state != PPPOE_SNONE) {
|
2006-08-07 08:05:10 +00:00
|
|
|
log(LOG_NOTICE, "ng_pppoe[%x]: Session already "
|
|
|
|
"active\n", node->nd_ID);
|
1999-10-21 09:06:11 +00:00
|
|
|
LEAVE(EISCONN);
|
|
|
|
}
|
1999-10-23 15:15:42 +00:00
|
|
|
|
1999-10-21 09:06:11 +00:00
|
|
|
/*
|
2006-01-21 08:13:19 +00:00
|
|
|
* Set up prototype header.
|
1999-10-21 09:06:11 +00:00
|
|
|
*/
|
2006-01-21 08:13:19 +00:00
|
|
|
neg = malloc(sizeof(*neg), M_NETGRAPH_PPPOE,
|
2000-11-18 15:17:43 +00:00
|
|
|
M_NOWAIT | M_ZERO);
|
1999-10-21 09:06:11 +00:00
|
|
|
|
2006-01-21 08:13:19 +00:00
|
|
|
if (neg == NULL)
|
1999-10-21 09:06:11 +00:00
|
|
|
LEAVE(ENOMEM);
|
2006-01-21 08:13:19 +00:00
|
|
|
|
2012-12-05 08:04:20 +00:00
|
|
|
neg->m = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR);
|
2006-01-21 08:13:19 +00:00
|
|
|
if (neg->m == NULL) {
|
|
|
|
free(neg, M_NETGRAPH_PPPOE);
|
1999-10-21 09:06:11 +00:00
|
|
|
LEAVE(ENOBUFS);
|
|
|
|
}
|
|
|
|
neg->m->m_pkthdr.rcvif = NULL;
|
|
|
|
sp->neg = neg;
|
2004-12-08 13:27:54 +00:00
|
|
|
ng_callout_init(&neg->handle);
|
1999-10-21 09:06:11 +00:00
|
|
|
neg->m->m_len = sizeof(struct pppoe_full_hdr);
|
|
|
|
neg->pkt = mtod(neg->m, union packet*);
|
2004-07-27 19:47:13 +00:00
|
|
|
memcpy((void *)&neg->pkt->pkt_header.eh,
|
2006-08-09 09:56:58 +00:00
|
|
|
&privp->eh, sizeof(struct ether_header));
|
1999-10-21 09:06:11 +00:00
|
|
|
neg->pkt->pkt_header.ph.ver = 0x1;
|
|
|
|
neg->pkt->pkt_header.ph.type = 0x1;
|
|
|
|
neg->pkt->pkt_header.ph.sid = 0x0000;
|
|
|
|
neg->timeout = 0;
|
|
|
|
|
2001-01-06 00:46:47 +00:00
|
|
|
sp->creator = NGI_RETADDR(item);
|
1999-10-21 09:06:11 +00:00
|
|
|
}
|
|
|
|
switch (msg->header.cmd) {
|
|
|
|
case NGM_PPPOE_GET_STATUS:
|
|
|
|
{
|
1999-10-27 11:29:51 +00:00
|
|
|
struct ngpppoestat *stats;
|
1999-10-21 09:06:11 +00:00
|
|
|
|
|
|
|
NG_MKRESPONSE(resp, msg, sizeof(*stats), M_NOWAIT);
|
2006-01-21 08:13:19 +00:00
|
|
|
if (!resp)
|
1999-10-21 09:06:11 +00:00
|
|
|
LEAVE(ENOMEM);
|
2006-01-21 08:13:19 +00:00
|
|
|
|
1999-10-27 11:29:51 +00:00
|
|
|
stats = (struct ngpppoestat *) resp->data;
|
1999-10-21 09:06:11 +00:00
|
|
|
stats->packets_in = privp->packets_in;
|
|
|
|
stats->packets_out = privp->packets_out;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NGM_PPPOE_CONNECT:
|
2007-12-29 19:44:41 +00:00
|
|
|
{
|
1999-10-21 09:06:11 +00:00
|
|
|
/*
|
|
|
|
* Check the hook exists and is Uninitialised.
|
|
|
|
* Send a PADI request, and start the timeout logic.
|
|
|
|
* Store the originator of this message so we can send
|
|
|
|
* a success of fail message to them later.
|
2006-01-21 08:13:19 +00:00
|
|
|
* Move the session to SINIT.
|
1999-10-21 09:06:11 +00:00
|
|
|
* Set up the session to the correct state and
|
|
|
|
* start it.
|
|
|
|
*/
|
2007-12-29 19:44:41 +00:00
|
|
|
int i, acnlen = 0, acnsep = 0, srvlen;
|
|
|
|
for (i = 0; i < ourmsg->data_len; i++) {
|
|
|
|
if (ourmsg->data[i] == '\\') {
|
|
|
|
acnlen = i;
|
|
|
|
acnsep = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
srvlen = ourmsg->data_len - acnlen - acnsep;
|
|
|
|
|
|
|
|
bcopy(ourmsg->data, neg->ac_name.data, acnlen);
|
|
|
|
neg->ac_name_len = acnlen;
|
|
|
|
|
1999-10-21 09:06:11 +00:00
|
|
|
neg->service.hdr.tag_type = PTT_SRV_NAME;
|
2007-12-29 19:44:41 +00:00
|
|
|
neg->service.hdr.tag_len = htons((uint16_t)srvlen);
|
|
|
|
bcopy(ourmsg->data + acnlen + acnsep,
|
|
|
|
neg->service.data, srvlen);
|
|
|
|
neg->service_len = srvlen;
|
1999-10-21 09:06:11 +00:00
|
|
|
pppoe_start(sp);
|
|
|
|
break;
|
2007-12-29 19:44:41 +00:00
|
|
|
}
|
1999-10-21 09:06:11 +00:00
|
|
|
case NGM_PPPOE_LISTEN:
|
|
|
|
/*
|
|
|
|
* Check the hook exists and is Uninitialised.
|
|
|
|
* Install the service matching string.
|
|
|
|
* Store the originator of this message so we can send
|
|
|
|
* a success of fail message to them later.
|
|
|
|
* Move the hook to 'LISTENING'
|
|
|
|
*/
|
|
|
|
neg->service.hdr.tag_type = PTT_SRV_NAME;
|
2000-11-16 23:14:53 +00:00
|
|
|
neg->service.hdr.tag_len =
|
2006-01-21 08:13:19 +00:00
|
|
|
htons((uint16_t)ourmsg->data_len);
|
1999-10-23 15:15:42 +00:00
|
|
|
|
2000-11-16 23:14:53 +00:00
|
|
|
if (ourmsg->data_len)
|
|
|
|
bcopy(ourmsg->data, neg->service.data,
|
|
|
|
ourmsg->data_len);
|
|
|
|
neg->service_len = ourmsg->data_len;
|
1999-10-21 09:06:11 +00:00
|
|
|
neg->pkt->pkt_header.ph.code = PADT_CODE;
|
|
|
|
/*
|
2006-01-21 08:13:19 +00:00
|
|
|
* Wait for PADI packet coming from Ethernet.
|
1999-10-21 09:06:11 +00:00
|
|
|
*/
|
|
|
|
sp->state = PPPOE_LISTENING;
|
2008-03-03 19:36:03 +00:00
|
|
|
LIST_INSERT_HEAD(&privp->listeners, sp, sessions);
|
1999-10-21 09:06:11 +00:00
|
|
|
break;
|
|
|
|
case NGM_PPPOE_OFFER:
|
|
|
|
/*
|
|
|
|
* Check the hook exists and is Uninitialised.
|
|
|
|
* Store the originator of this message so we can send
|
|
|
|
* a success of fail message to them later.
|
|
|
|
* Store the AC-Name given and go to PRIMED.
|
|
|
|
*/
|
|
|
|
neg->ac_name.hdr.tag_type = PTT_AC_NAME;
|
2000-11-16 23:14:53 +00:00
|
|
|
neg->ac_name.hdr.tag_len =
|
2006-01-21 08:13:19 +00:00
|
|
|
htons((uint16_t)ourmsg->data_len);
|
2000-11-16 23:14:53 +00:00
|
|
|
if (ourmsg->data_len)
|
|
|
|
bcopy(ourmsg->data, neg->ac_name.data,
|
|
|
|
ourmsg->data_len);
|
|
|
|
neg->ac_name_len = ourmsg->data_len;
|
1999-10-21 09:06:11 +00:00
|
|
|
neg->pkt->pkt_header.ph.code = PADO_CODE;
|
|
|
|
/*
|
2006-01-21 08:13:19 +00:00
|
|
|
* Wait for PADI packet coming from hook.
|
1999-10-21 09:06:11 +00:00
|
|
|
*/
|
|
|
|
sp->state = PPPOE_PRIMED;
|
|
|
|
break;
|
2006-01-21 08:13:19 +00:00
|
|
|
case NGM_PPPOE_SERVICE:
|
|
|
|
/*
|
2000-12-12 18:52:14 +00:00
|
|
|
* Check the session is primed.
|
|
|
|
* for now just allow ONE service to be advertised.
|
|
|
|
* If you do it twice you just overwrite.
|
|
|
|
*/
|
2000-12-18 13:41:46 +00:00
|
|
|
if (sp->state != PPPOE_PRIMED) {
|
2006-08-07 08:05:10 +00:00
|
|
|
log(LOG_NOTICE, "ng_pppoe[%x]: session not "
|
|
|
|
"primed\n", node->nd_ID);
|
2000-12-12 18:52:14 +00:00
|
|
|
LEAVE(EISCONN);
|
|
|
|
}
|
2001-01-11 15:42:22 +00:00
|
|
|
neg = sp->neg;
|
2000-12-12 18:52:14 +00:00
|
|
|
neg->service.hdr.tag_type = PTT_SRV_NAME;
|
|
|
|
neg->service.hdr.tag_len =
|
2006-01-21 08:13:19 +00:00
|
|
|
htons((uint16_t)ourmsg->data_len);
|
2000-12-12 18:52:14 +00:00
|
|
|
|
|
|
|
if (ourmsg->data_len)
|
|
|
|
bcopy(ourmsg->data, neg->service.data,
|
|
|
|
ourmsg->data_len);
|
|
|
|
neg->service_len = ourmsg->data_len;
|
|
|
|
break;
|
2004-07-27 19:47:13 +00:00
|
|
|
case NGM_PPPOE_SETMODE:
|
|
|
|
{
|
|
|
|
char *s;
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
if (msg->header.arglen == 0)
|
|
|
|
LEAVE(EINVAL);
|
|
|
|
|
|
|
|
s = (char *)msg->data;
|
|
|
|
len = msg->header.arglen - 1;
|
|
|
|
|
2006-01-21 08:13:19 +00:00
|
|
|
/* Search for matching mode string. */
|
2006-01-27 10:56:22 +00:00
|
|
|
if (len == strlen(NG_PPPOE_STANDARD) &&
|
|
|
|
(strncmp(NG_PPPOE_STANDARD, s, len) == 0)) {
|
|
|
|
privp->flags = 0;
|
2006-08-09 09:56:58 +00:00
|
|
|
privp->eh.ether_type = ETHERTYPE_PPPOE_DISC;
|
2006-01-27 10:56:22 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (len == strlen(NG_PPPOE_3COM) &&
|
|
|
|
(strncmp(NG_PPPOE_3COM, s, len) == 0)) {
|
|
|
|
privp->flags |= COMPAT_3COM;
|
2006-08-09 09:56:58 +00:00
|
|
|
privp->eh.ether_type =
|
|
|
|
ETHERTYPE_PPPOE_3COM_DISC;
|
2006-01-27 10:56:22 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (len == strlen(NG_PPPOE_DLINK) &&
|
|
|
|
(strncmp(NG_PPPOE_DLINK, s, len) == 0)) {
|
|
|
|
privp->flags |= COMPAT_DLINK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
error = EINVAL;
|
2004-07-27 19:47:13 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NGM_PPPOE_GETMODE:
|
2006-01-27 10:56:22 +00:00
|
|
|
{
|
|
|
|
char *s;
|
|
|
|
size_t len = 0;
|
|
|
|
|
|
|
|
if (privp->flags == 0)
|
|
|
|
len += strlen(NG_PPPOE_STANDARD) + 1;
|
|
|
|
if (privp->flags & COMPAT_3COM)
|
|
|
|
len += strlen(NG_PPPOE_3COM) + 1;
|
|
|
|
if (privp->flags & COMPAT_DLINK)
|
|
|
|
len += strlen(NG_PPPOE_DLINK) + 1;
|
|
|
|
|
|
|
|
NG_MKRESPONSE(resp, msg, len, M_NOWAIT);
|
2004-07-27 19:47:13 +00:00
|
|
|
if (resp == NULL)
|
|
|
|
LEAVE(ENOMEM);
|
2006-01-27 10:56:22 +00:00
|
|
|
|
|
|
|
s = (char *)resp->data;
|
|
|
|
if (privp->flags == 0) {
|
|
|
|
len = strlen(NG_PPPOE_STANDARD);
|
|
|
|
strlcpy(s, NG_PPPOE_STANDARD, len + 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (privp->flags & COMPAT_3COM) {
|
|
|
|
len = strlen(NG_PPPOE_3COM);
|
|
|
|
strlcpy(s, NG_PPPOE_3COM, len + 1);
|
|
|
|
s += len;
|
|
|
|
}
|
|
|
|
if (privp->flags & COMPAT_DLINK) {
|
|
|
|
if (s != resp->data)
|
|
|
|
*s++ = '|';
|
|
|
|
len = strlen(NG_PPPOE_DLINK);
|
|
|
|
strlcpy(s, NG_PPPOE_DLINK, len + 1);
|
|
|
|
}
|
2004-07-27 19:47:13 +00:00
|
|
|
break;
|
2006-01-27 10:56:22 +00:00
|
|
|
}
|
2006-08-09 09:56:58 +00:00
|
|
|
case NGM_PPPOE_SETENADDR:
|
|
|
|
if (msg->header.arglen != ETHER_ADDR_LEN)
|
|
|
|
LEAVE(EINVAL);
|
|
|
|
bcopy(msg->data, &privp->eh.ether_shost,
|
|
|
|
ETHER_ADDR_LEN);
|
|
|
|
break;
|
1999-10-21 09:06:11 +00:00
|
|
|
default:
|
|
|
|
LEAVE(EINVAL);
|
|
|
|
}
|
|
|
|
break;
|
2006-08-09 09:56:58 +00:00
|
|
|
case NGM_ETHER_COOKIE:
|
|
|
|
if (!(msg->header.flags & NGF_RESP))
|
|
|
|
LEAVE(EINVAL);
|
|
|
|
switch (msg->header.cmd) {
|
|
|
|
case NGM_ETHER_GET_ENADDR:
|
|
|
|
if (msg->header.arglen != ETHER_ADDR_LEN)
|
|
|
|
LEAVE(EINVAL);
|
|
|
|
bcopy(msg->data, &privp->eh.ether_shost,
|
|
|
|
ETHER_ADDR_LEN);
|
|
|
|
break;
|
|
|
|
default:
|
2006-08-10 11:07:11 +00:00
|
|
|
LEAVE(EINVAL);
|
2006-08-09 09:56:58 +00:00
|
|
|
}
|
|
|
|
break;
|
1999-10-21 09:06:11 +00:00
|
|
|
default:
|
|
|
|
LEAVE(EINVAL);
|
|
|
|
}
|
|
|
|
|
2006-01-21 08:13:19 +00:00
|
|
|
/* Take care of synchronous response, if any. */
|
1999-10-21 09:06:11 +00:00
|
|
|
quit:
|
2006-01-27 10:56:22 +00:00
|
|
|
CTR2(KTR_NET, "%20s: returning %d", __func__, error);
|
2001-01-06 00:46:47 +00:00
|
|
|
NG_RESPOND_MSG(error, node, item, resp);
|
2006-01-21 08:13:19 +00:00
|
|
|
/* Free the message and return. */
|
2001-01-06 00:46:47 +00:00
|
|
|
NG_FREE_MSG(msg);
|
1999-10-21 09:06:11 +00:00
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
|
1999-10-23 15:15:42 +00:00
|
|
|
/*
|
|
|
|
* Start a client into the first state. A separate function because
|
|
|
|
* it can be needed if the negotiation times out.
|
|
|
|
*/
|
1999-10-21 09:06:11 +00:00
|
|
|
static void
|
|
|
|
pppoe_start(sessp sp)
|
|
|
|
{
|
2007-10-14 09:51:19 +00:00
|
|
|
hook_p hook = sp->hook;
|
|
|
|
node_p node = NG_HOOK_NODE(hook);
|
|
|
|
priv_p privp = NG_NODE_PRIVATE(node);
|
|
|
|
negp neg = sp->neg;
|
1999-10-21 09:06:11 +00:00
|
|
|
struct {
|
|
|
|
struct pppoe_tag hdr;
|
|
|
|
union uniq data;
|
2002-09-23 18:54:32 +00:00
|
|
|
} __packed uniqtag;
|
2007-10-14 09:51:19 +00:00
|
|
|
struct mbuf *m0;
|
|
|
|
int error;
|
1999-10-21 09:06:11 +00:00
|
|
|
|
2006-01-21 08:13:19 +00:00
|
|
|
/*
|
|
|
|
* Kick the state machine into starting up.
|
1999-10-21 09:06:11 +00:00
|
|
|
*/
|
2006-01-21 08:13:19 +00:00
|
|
|
CTR2(KTR_NET, "%20s: called %d", __func__, sp->Session_ID);
|
1999-10-21 09:06:11 +00:00
|
|
|
sp->state = PPPOE_SINIT;
|
2006-01-21 08:13:19 +00:00
|
|
|
/*
|
|
|
|
* Reset the packet header to broadcast. Since we are
|
2006-08-09 09:56:58 +00:00
|
|
|
* in a client mode use configured ethertype.
|
2006-01-21 08:13:19 +00:00
|
|
|
*/
|
2007-10-14 09:51:19 +00:00
|
|
|
memcpy((void *)&neg->pkt->pkt_header.eh, &privp->eh,
|
2006-08-09 09:56:58 +00:00
|
|
|
sizeof(struct ether_header));
|
2007-10-14 09:51:19 +00:00
|
|
|
neg->pkt->pkt_header.ph.code = PADI_CODE;
|
1999-10-21 09:06:11 +00:00
|
|
|
uniqtag.hdr.tag_type = PTT_HOST_UNIQ;
|
|
|
|
uniqtag.hdr.tag_len = htons((u_int16_t)sizeof(uniqtag.data));
|
|
|
|
uniqtag.data.pointer = sp;
|
|
|
|
init_tags(sp);
|
1999-11-14 17:26:58 +00:00
|
|
|
insert_tag(sp, &uniqtag.hdr);
|
2007-10-14 09:51:19 +00:00
|
|
|
insert_tag(sp, &neg->service.hdr);
|
1999-10-21 09:06:11 +00:00
|
|
|
make_packet(sp);
|
2007-10-14 09:51:19 +00:00
|
|
|
/*
|
|
|
|
* Send packet and prepare to retransmit it after timeout.
|
|
|
|
*/
|
|
|
|
ng_callout(&neg->handle, node, hook, PPPOE_INITIAL_TIMEOUT * hz,
|
|
|
|
pppoe_ticker, NULL, 0);
|
|
|
|
neg->timeout = PPPOE_INITIAL_TIMEOUT * 2;
|
2012-12-05 08:04:20 +00:00
|
|
|
m0 = m_copypacket(neg->m, M_NOWAIT);
|
2007-10-14 09:51:19 +00:00
|
|
|
NG_SEND_DATA_ONLY(error, privp->ethernet_hook, m0);
|
1999-10-21 09:06:11 +00:00
|
|
|
}
|
|
|
|
|
2002-02-20 15:51:11 +00:00
|
|
|
static int
|
2002-06-05 23:35:31 +00:00
|
|
|
send_acname(sessp sp, const struct pppoe_tag *tag)
|
2002-02-20 15:51:11 +00:00
|
|
|
{
|
2002-06-22 21:00:53 +00:00
|
|
|
int error, tlen;
|
2002-02-20 15:51:11 +00:00
|
|
|
struct ng_mesg *msg;
|
|
|
|
struct ngpppoe_sts *sts;
|
|
|
|
|
2006-01-21 08:13:19 +00:00
|
|
|
CTR2(KTR_NET, "%20s: called %d", __func__, sp->Session_ID);
|
|
|
|
|
2002-02-20 15:51:11 +00:00
|
|
|
NG_MKMESSAGE(msg, NGM_PPPOE_COOKIE, NGM_PPPOE_ACNAME,
|
|
|
|
sizeof(struct ngpppoe_sts), M_NOWAIT);
|
|
|
|
if (msg == NULL)
|
|
|
|
return (ENOMEM);
|
|
|
|
|
|
|
|
sts = (struct ngpppoe_sts *)msg->data;
|
2004-01-26 14:05:31 +00:00
|
|
|
tlen = min(NG_HOOKSIZ - 1, ntohs(tag->tag_len));
|
2009-03-03 18:47:33 +00:00
|
|
|
strncpy(sts->hook, (const char *)(tag + 1), tlen);
|
2002-06-22 21:00:53 +00:00
|
|
|
sts->hook[tlen] = '\0';
|
2002-08-22 00:30:03 +00:00
|
|
|
NG_SEND_MSG_ID(error, NG_HOOK_NODE(sp->hook), msg, sp->creator, 0);
|
2002-02-20 15:51:11 +00:00
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2002-05-14 12:32:41 +00:00
|
|
|
static int
|
|
|
|
send_sessionid(sessp sp)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
struct ng_mesg *msg;
|
|
|
|
|
2006-01-21 08:13:19 +00:00
|
|
|
CTR2(KTR_NET, "%20s: called %d", __func__, sp->Session_ID);
|
|
|
|
|
2002-05-14 12:32:41 +00:00
|
|
|
NG_MKMESSAGE(msg, NGM_PPPOE_COOKIE, NGM_PPPOE_SESSIONID,
|
2006-01-21 08:13:19 +00:00
|
|
|
sizeof(uint16_t), M_NOWAIT);
|
2002-05-14 12:32:41 +00:00
|
|
|
if (msg == NULL)
|
|
|
|
return (ENOMEM);
|
|
|
|
|
2006-01-21 08:13:19 +00:00
|
|
|
*(uint16_t *)msg->data = sp->Session_ID;
|
2002-08-22 00:30:03 +00:00
|
|
|
NG_SEND_MSG_ID(error, NG_HOOK_NODE(sp->hook), msg, sp->creator, 0);
|
2002-05-14 12:32:41 +00:00
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
1999-10-21 09:06:11 +00:00
|
|
|
/*
|
2007-10-14 09:58:22 +00:00
|
|
|
* Receive data from session hook and do something with it.
|
1999-10-21 09:06:11 +00:00
|
|
|
*/
|
|
|
|
static int
|
2001-01-06 00:46:47 +00:00
|
|
|
ng_pppoe_rcvdata(hook_p hook, item_p item)
|
1999-10-21 09:06:11 +00:00
|
|
|
{
|
2001-01-08 05:34:06 +00:00
|
|
|
node_p node = NG_HOOK_NODE(hook);
|
|
|
|
const priv_p privp = NG_NODE_PRIVATE(node);
|
|
|
|
sessp sp = NG_HOOK_PRIVATE(hook);
|
2007-10-14 09:58:22 +00:00
|
|
|
struct pppoe_full_hdr *wh;
|
2006-01-21 08:13:19 +00:00
|
|
|
struct mbuf *m;
|
2007-10-14 09:58:22 +00:00
|
|
|
int error;
|
1999-10-21 09:06:11 +00:00
|
|
|
|
2006-01-21 08:13:19 +00:00
|
|
|
CTR6(KTR_NET, "%20s: node [%x] (%p) received %p on \"%s\" (%p)",
|
|
|
|
__func__, node->nd_ID, node, item, hook->hk_name, hook);
|
|
|
|
|
2001-01-06 00:46:47 +00:00
|
|
|
NGI_GET_M(item, m);
|
2007-10-14 09:58:22 +00:00
|
|
|
switch (sp->state) {
|
|
|
|
case PPPOE_NEWCONNECTED:
|
|
|
|
case PPPOE_CONNECTED: {
|
|
|
|
/*
|
|
|
|
* Remove PPP address and control fields, if any.
|
|
|
|
* For example, ng_ppp(4) always sends LCP packets
|
|
|
|
* with address and control fields as required by
|
|
|
|
* generic PPP. PPPoE is an exception to the rule.
|
|
|
|
*/
|
|
|
|
if (m->m_pkthdr.len >= 2) {
|
|
|
|
if (m->m_len < 2 && !(m = m_pullup(m, 2)))
|
|
|
|
LEAVE(ENOBUFS);
|
2008-02-06 20:37:34 +00:00
|
|
|
if (mtod(m, u_char *)[0] == 0xff &&
|
|
|
|
mtod(m, u_char *)[1] == 0x03)
|
2007-10-14 09:58:22 +00:00
|
|
|
m_adj(m, 2);
|
|
|
|
}
|
1999-10-21 09:06:11 +00:00
|
|
|
/*
|
2007-10-14 09:58:22 +00:00
|
|
|
* Bang in a pre-made header, and set the length up
|
|
|
|
* to be correct. Then send it to the ethernet driver.
|
1999-10-21 09:06:11 +00:00
|
|
|
*/
|
2012-12-05 08:04:20 +00:00
|
|
|
M_PREPEND(m, sizeof(*wh), M_NOWAIT);
|
2007-10-14 09:58:22 +00:00
|
|
|
if (m == NULL)
|
|
|
|
LEAVE(ENOBUFS);
|
|
|
|
|
|
|
|
wh = mtod(m, struct pppoe_full_hdr *);
|
|
|
|
bcopy(&sp->pkt_hdr, wh, sizeof(*wh));
|
|
|
|
wh->ph.length = htons(m->m_pkthdr.len - sizeof(*wh));
|
|
|
|
NG_FWD_NEW_DATA(error, item, privp->ethernet_hook, m);
|
|
|
|
privp->packets_out++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PPPOE_PRIMED: {
|
|
|
|
struct {
|
|
|
|
struct pppoe_tag hdr;
|
|
|
|
union uniq data;
|
|
|
|
} __packed uniqtag;
|
|
|
|
const struct pppoe_tag *tag;
|
|
|
|
struct mbuf *m0;
|
|
|
|
const struct pppoe_hdr *ph;
|
|
|
|
negp neg = sp->neg;
|
|
|
|
uint16_t session;
|
|
|
|
uint16_t length;
|
|
|
|
uint8_t code;
|
|
|
|
|
1999-10-21 09:06:11 +00:00
|
|
|
/*
|
2007-10-14 09:58:22 +00:00
|
|
|
* A PADI packet is being returned by the application
|
|
|
|
* that has set up this hook. This indicates that it
|
|
|
|
* wants us to offer service.
|
1999-10-21 09:06:11 +00:00
|
|
|
*/
|
2007-10-14 09:58:22 +00:00
|
|
|
if (m->m_len < sizeof(*wh)) {
|
|
|
|
m = m_pullup(m, sizeof(*wh));
|
|
|
|
if (m == NULL)
|
1999-10-26 08:08:48 +00:00
|
|
|
LEAVE(ENOBUFS);
|
1999-10-21 09:06:11 +00:00
|
|
|
}
|
|
|
|
wh = mtod(m, struct pppoe_full_hdr *);
|
2007-10-14 09:58:22 +00:00
|
|
|
ph = &wh->ph;
|
|
|
|
session = ntohs(wh->ph.sid);
|
1999-10-21 09:06:11 +00:00
|
|
|
length = ntohs(wh->ph.length);
|
2007-10-14 09:58:22 +00:00
|
|
|
code = wh->ph.code;
|
|
|
|
/* Use peers mode in session. */
|
|
|
|
neg->pkt->pkt_header.eh.ether_type = wh->eh.ether_type;
|
|
|
|
if (code != PADI_CODE)
|
|
|
|
LEAVE(EINVAL);
|
|
|
|
ng_uncallout(&neg->handle, node);
|
1999-10-21 09:06:11 +00:00
|
|
|
|
2007-10-14 09:58:22 +00:00
|
|
|
/*
|
|
|
|
* This is the first time we hear
|
|
|
|
* from the client, so note it's
|
|
|
|
* unicast address, replacing the
|
|
|
|
* broadcast address.
|
|
|
|
*/
|
|
|
|
bcopy(wh->eh.ether_shost,
|
|
|
|
neg->pkt->pkt_header.eh.ether_dhost,
|
|
|
|
ETHER_ADDR_LEN);
|
|
|
|
sp->state = PPPOE_SOFFER;
|
|
|
|
neg->timeout = 0;
|
|
|
|
neg->pkt->pkt_header.ph.code = PADO_CODE;
|
1999-10-21 09:06:11 +00:00
|
|
|
|
2007-10-14 09:58:22 +00:00
|
|
|
/*
|
|
|
|
* Start working out the tags to respond with.
|
|
|
|
*/
|
|
|
|
uniqtag.hdr.tag_type = PTT_AC_COOKIE;
|
|
|
|
uniqtag.hdr.tag_len = htons((u_int16_t)sizeof(sp));
|
|
|
|
uniqtag.data.pointer = sp;
|
|
|
|
init_tags(sp);
|
|
|
|
insert_tag(sp, &neg->ac_name.hdr); /* AC_NAME */
|
|
|
|
if ((tag = get_tag(ph, PTT_SRV_NAME)))
|
|
|
|
insert_tag(sp, tag); /* return service */
|
|
|
|
/*
|
|
|
|
* If we have a NULL service request
|
|
|
|
* and have an extra service defined in this hook,
|
|
|
|
* then also add a tag for the extra service.
|
|
|
|
* XXX this is a hack. eventually we should be able
|
|
|
|
* to support advertising many services, not just one
|
|
|
|
*/
|
|
|
|
if (((tag == NULL) || (tag->tag_len == 0)) &&
|
|
|
|
(neg->service.hdr.tag_len != 0)) {
|
|
|
|
insert_tag(sp, &neg->service.hdr); /* SERVICE */
|
|
|
|
}
|
|
|
|
if ((tag = get_tag(ph, PTT_HOST_UNIQ)))
|
|
|
|
insert_tag(sp, tag); /* returned hostunique */
|
|
|
|
insert_tag(sp, &uniqtag.hdr);
|
|
|
|
scan_tags(sp, ph);
|
|
|
|
make_packet(sp);
|
|
|
|
/*
|
|
|
|
* Send the offer but if they don't respond
|
|
|
|
* in PPPOE_OFFER_TIMEOUT seconds, forget about it.
|
|
|
|
*/
|
|
|
|
ng_callout(&neg->handle, node, hook, PPPOE_OFFER_TIMEOUT * hz,
|
|
|
|
pppoe_ticker, NULL, 0);
|
2012-12-05 08:04:20 +00:00
|
|
|
m0 = m_copypacket(sp->neg->m, M_NOWAIT);
|
2007-10-14 09:58:22 +00:00
|
|
|
NG_FWD_NEW_DATA(error, item, privp->ethernet_hook, m0);
|
|
|
|
privp->packets_out++;
|
|
|
|
break;
|
|
|
|
}
|
1999-10-21 09:06:11 +00:00
|
|
|
|
2007-10-14 09:58:22 +00:00
|
|
|
/*
|
|
|
|
* Packets coming from the hook make no sense
|
|
|
|
* to sessions in the rest of states. Throw them away.
|
|
|
|
*/
|
|
|
|
default:
|
|
|
|
LEAVE(ENETUNREACH);
|
|
|
|
}
|
|
|
|
quit:
|
|
|
|
if (item)
|
|
|
|
NG_FREE_ITEM(item);
|
|
|
|
NG_FREE_M(m);
|
|
|
|
return (error);
|
|
|
|
}
|
1999-10-21 09:06:11 +00:00
|
|
|
|
2007-10-14 09:58:22 +00:00
|
|
|
/*
|
|
|
|
* Receive data from ether and do something with it.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ng_pppoe_rcvdata_ether(hook_p hook, item_p item)
|
|
|
|
{
|
|
|
|
node_p node = NG_HOOK_NODE(hook);
|
|
|
|
const priv_p privp = NG_NODE_PRIVATE(node);
|
2010-06-05 10:16:23 +00:00
|
|
|
sessp sp;
|
2007-10-14 09:58:22 +00:00
|
|
|
const struct pppoe_tag *utag = NULL, *tag = NULL;
|
|
|
|
const struct pppoe_full_hdr *wh;
|
|
|
|
const struct pppoe_hdr *ph;
|
|
|
|
negp neg = NULL;
|
|
|
|
struct mbuf *m;
|
|
|
|
hook_p sendhook;
|
|
|
|
int error = 0;
|
|
|
|
uint16_t session;
|
|
|
|
uint16_t length;
|
|
|
|
uint8_t code;
|
|
|
|
struct mbuf *m0;
|
2007-10-14 09:51:19 +00:00
|
|
|
|
2007-10-14 09:58:22 +00:00
|
|
|
CTR6(KTR_NET, "%20s: node [%x] (%p) received %p on \"%s\" (%p)",
|
|
|
|
__func__, node->nd_ID, node, item, hook->hk_name, hook);
|
1999-10-21 09:06:11 +00:00
|
|
|
|
2007-10-14 09:58:22 +00:00
|
|
|
NGI_GET_M(item, m);
|
|
|
|
/*
|
|
|
|
* Dig out various fields from the packet.
|
|
|
|
* Use them to decide where to send it.
|
|
|
|
*/
|
|
|
|
privp->packets_in++;
|
|
|
|
if( m->m_len < sizeof(*wh)) {
|
|
|
|
m = m_pullup(m, sizeof(*wh)); /* Checks length */
|
|
|
|
if (m == NULL) {
|
|
|
|
log(LOG_NOTICE, "ng_pppoe[%x]: couldn't "
|
|
|
|
"m_pullup(wh)\n", node->nd_ID);
|
|
|
|
LEAVE(ENOBUFS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
wh = mtod(m, struct pppoe_full_hdr *);
|
|
|
|
length = ntohs(wh->ph.length);
|
|
|
|
switch(wh->eh.ether_type) {
|
|
|
|
case ETHERTYPE_PPPOE_3COM_DISC: /* fall through */
|
|
|
|
case ETHERTYPE_PPPOE_DISC:
|
|
|
|
/*
|
|
|
|
* We need to try to make sure that the tag area
|
|
|
|
* is contiguous, or we could wander off the end
|
|
|
|
* of a buffer and make a mess.
|
|
|
|
* (Linux wouldn't have this problem).
|
|
|
|
*/
|
|
|
|
if (m->m_pkthdr.len <= MHLEN) {
|
|
|
|
if( m->m_len < m->m_pkthdr.len) {
|
|
|
|
m = m_pullup(m, m->m_pkthdr.len);
|
|
|
|
if (m == NULL) {
|
|
|
|
log(LOG_NOTICE, "ng_pppoe[%x]: "
|
|
|
|
"couldn't m_pullup(pkthdr)\n",
|
|
|
|
node->nd_ID);
|
|
|
|
LEAVE(ENOBUFS);
|
1999-10-21 09:06:11 +00:00
|
|
|
}
|
|
|
|
}
|
2007-10-14 09:58:22 +00:00
|
|
|
}
|
|
|
|
if (m->m_len != m->m_pkthdr.len) {
|
1999-10-21 09:06:11 +00:00
|
|
|
/*
|
2007-10-14 09:58:22 +00:00
|
|
|
* It's not all in one piece.
|
|
|
|
* We need to do extra work.
|
|
|
|
* Put it into a cluster.
|
1999-10-21 09:06:11 +00:00
|
|
|
*/
|
2007-10-14 09:58:22 +00:00
|
|
|
struct mbuf *n;
|
2012-12-05 08:04:20 +00:00
|
|
|
n = m_dup(m, M_NOWAIT);
|
2007-10-14 09:58:22 +00:00
|
|
|
m_freem(m);
|
|
|
|
m = n;
|
|
|
|
if (m) {
|
|
|
|
/* just check we got a cluster */
|
|
|
|
if (m->m_len != m->m_pkthdr.len) {
|
|
|
|
m_freem(m);
|
|
|
|
m = NULL;
|
|
|
|
}
|
1999-10-21 09:06:11 +00:00
|
|
|
}
|
2007-10-14 09:58:22 +00:00
|
|
|
if (m == NULL) {
|
|
|
|
log(LOG_NOTICE, "ng_pppoe[%x]: packet "
|
|
|
|
"fragmented\n", node->nd_ID);
|
1999-10-21 09:06:11 +00:00
|
|
|
LEAVE(EMSGSIZE);
|
|
|
|
}
|
|
|
|
}
|
2007-10-14 09:58:22 +00:00
|
|
|
wh = mtod(m, struct pppoe_full_hdr *);
|
|
|
|
length = ntohs(wh->ph.length);
|
|
|
|
ph = &wh->ph;
|
|
|
|
session = ntohs(wh->ph.sid);
|
|
|
|
code = wh->ph.code;
|
2000-08-10 20:05:12 +00:00
|
|
|
|
2007-10-14 09:58:22 +00:00
|
|
|
switch(code) {
|
|
|
|
case PADI_CODE:
|
2000-08-10 20:05:12 +00:00
|
|
|
/*
|
2007-10-14 09:58:22 +00:00
|
|
|
* We are a server:
|
|
|
|
* Look for a hook with the required service and send
|
|
|
|
* the ENTIRE packet up there. It should come back to
|
|
|
|
* a new hook in PRIMED state. Look there for further
|
|
|
|
* processing.
|
2000-08-10 20:05:12 +00:00
|
|
|
*/
|
2007-10-14 09:58:22 +00:00
|
|
|
tag = get_tag(ph, PTT_SRV_NAME);
|
|
|
|
if (tag == NULL) {
|
|
|
|
CTR1(KTR_NET, "%20s: PADI w/o Service-Name",
|
|
|
|
__func__);
|
|
|
|
LEAVE(ENETUNREACH);
|
2000-08-10 20:05:12 +00:00
|
|
|
}
|
2007-10-14 09:58:22 +00:00
|
|
|
|
1999-10-21 09:06:11 +00:00
|
|
|
/*
|
2007-10-14 09:58:22 +00:00
|
|
|
* First, try to match Service-Name against our
|
|
|
|
* listening hooks. If no success and we are in D-Link
|
|
|
|
* compat mode and Service-Name is empty, then we
|
|
|
|
* broadcast the PADI to all listening hooks.
|
1999-10-21 09:06:11 +00:00
|
|
|
*/
|
2007-10-14 09:58:22 +00:00
|
|
|
sendhook = pppoe_match_svc(node, tag);
|
|
|
|
if (sendhook != NULL)
|
|
|
|
NG_FWD_NEW_DATA(error, item, sendhook, m);
|
|
|
|
else if (privp->flags & COMPAT_DLINK &&
|
|
|
|
ntohs(tag->tag_len) == 0)
|
|
|
|
error = pppoe_broadcast_padi(node, m);
|
|
|
|
else
|
|
|
|
error = ENETUNREACH;
|
1999-10-21 09:06:11 +00:00
|
|
|
break;
|
2007-10-14 09:58:22 +00:00
|
|
|
case PADO_CODE:
|
|
|
|
/*
|
|
|
|
* We are a client:
|
|
|
|
* Use the host_uniq tag to find the hook this is in
|
|
|
|
* response to. Received #2, now send #3
|
|
|
|
* For now simply accept the first we receive.
|
|
|
|
*/
|
|
|
|
utag = get_tag(ph, PTT_HOST_UNIQ);
|
|
|
|
if ((utag == NULL) ||
|
|
|
|
(ntohs(utag->tag_len) != sizeof(sp))) {
|
|
|
|
log(LOG_NOTICE, "ng_pppoe[%x]: no host "
|
|
|
|
"unique field\n", node->nd_ID);
|
|
|
|
LEAVE(ENETUNREACH);
|
|
|
|
}
|
|
|
|
|
|
|
|
sendhook = pppoe_finduniq(node, utag);
|
|
|
|
if (sendhook == NULL) {
|
|
|
|
log(LOG_NOTICE, "ng_pppoe[%x]: no "
|
|
|
|
"matching session\n", node->nd_ID);
|
|
|
|
LEAVE(ENETUNREACH);
|
1999-10-21 09:06:11 +00:00
|
|
|
}
|
2007-10-14 09:58:22 +00:00
|
|
|
|
1999-10-21 09:06:11 +00:00
|
|
|
/*
|
2007-10-14 09:58:22 +00:00
|
|
|
* Check the session is in the right state.
|
|
|
|
* It needs to be in PPPOE_SINIT.
|
1999-10-21 09:06:11 +00:00
|
|
|
*/
|
2007-10-14 09:58:22 +00:00
|
|
|
sp = NG_HOOK_PRIVATE(sendhook);
|
2007-12-29 19:44:41 +00:00
|
|
|
if (sp->state == PPPOE_SREQ ||
|
|
|
|
sp->state == PPPOE_CONNECTED) {
|
|
|
|
break; /* Multiple PADO is OK. */
|
|
|
|
}
|
2007-10-14 09:58:22 +00:00
|
|
|
if (sp->state != PPPOE_SINIT) {
|
|
|
|
log(LOG_NOTICE, "ng_pppoe[%x]: session "
|
|
|
|
"in wrong state\n", node->nd_ID);
|
|
|
|
LEAVE(ENETUNREACH);
|
1999-10-21 09:06:11 +00:00
|
|
|
}
|
2007-10-14 09:58:22 +00:00
|
|
|
neg = sp->neg;
|
2007-12-29 19:44:41 +00:00
|
|
|
/* If requested specific AC-name, check it. */
|
|
|
|
if (neg->ac_name_len) {
|
|
|
|
tag = get_tag(ph, PTT_AC_NAME);
|
|
|
|
if (!tag) {
|
|
|
|
/* No PTT_AC_NAME in PADO */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (neg->ac_name_len != htons(tag->tag_len) ||
|
2009-03-03 18:47:33 +00:00
|
|
|
strncmp(neg->ac_name.data,
|
|
|
|
(const char *)(tag + 1),
|
2007-12-29 19:44:41 +00:00
|
|
|
neg->ac_name_len) != 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sp->state = PPPOE_SREQ;
|
2004-12-08 13:27:54 +00:00
|
|
|
ng_uncallout(&neg->handle, node);
|
1999-10-21 09:06:11 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This is the first time we hear
|
2007-10-14 09:58:22 +00:00
|
|
|
* from the server, so note it's
|
1999-10-21 09:06:11 +00:00
|
|
|
* unicast address, replacing the
|
2007-10-14 09:58:22 +00:00
|
|
|
* broadcast address .
|
1999-10-21 09:06:11 +00:00
|
|
|
*/
|
|
|
|
bcopy(wh->eh.ether_shost,
|
|
|
|
neg->pkt->pkt_header.eh.ether_dhost,
|
|
|
|
ETHER_ADDR_LEN);
|
|
|
|
neg->timeout = 0;
|
2007-10-14 09:58:22 +00:00
|
|
|
neg->pkt->pkt_header.ph.code = PADR_CODE;
|
|
|
|
init_tags(sp);
|
|
|
|
insert_tag(sp, utag); /* Host Unique */
|
|
|
|
if ((tag = get_tag(ph, PTT_AC_COOKIE)))
|
|
|
|
insert_tag(sp, tag); /* return cookie */
|
|
|
|
if ((tag = get_tag(ph, PTT_AC_NAME))) {
|
|
|
|
insert_tag(sp, tag); /* return it */
|
|
|
|
send_acname(sp, tag);
|
|
|
|
}
|
|
|
|
insert_tag(sp, &neg->service.hdr); /* Service */
|
|
|
|
scan_tags(sp, ph);
|
|
|
|
make_packet(sp);
|
|
|
|
sp->state = PPPOE_SREQ;
|
|
|
|
ng_callout(&neg->handle, node, sp->hook,
|
|
|
|
PPPOE_INITIAL_TIMEOUT * hz,
|
|
|
|
pppoe_ticker, NULL, 0);
|
|
|
|
neg->timeout = PPPOE_INITIAL_TIMEOUT * 2;
|
2012-12-05 08:04:20 +00:00
|
|
|
m0 = m_copypacket(neg->m, M_NOWAIT);
|
2007-10-14 09:58:22 +00:00
|
|
|
NG_FWD_NEW_DATA(error, item, privp->ethernet_hook, m0);
|
|
|
|
break;
|
|
|
|
case PADR_CODE:
|
|
|
|
/*
|
|
|
|
* We are a server:
|
|
|
|
* Use the ac_cookie tag to find the
|
|
|
|
* hook this is in response to.
|
|
|
|
*/
|
|
|
|
utag = get_tag(ph, PTT_AC_COOKIE);
|
|
|
|
if ((utag == NULL) ||
|
|
|
|
(ntohs(utag->tag_len) != sizeof(sp))) {
|
|
|
|
LEAVE(ENETUNREACH);
|
|
|
|
}
|
1999-10-21 09:06:11 +00:00
|
|
|
|
2007-10-14 09:58:22 +00:00
|
|
|
sendhook = pppoe_finduniq(node, utag);
|
|
|
|
if (sendhook == NULL)
|
|
|
|
LEAVE(ENETUNREACH);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check the session is in the right state.
|
|
|
|
* It needs to be in PPPOE_SOFFER or PPPOE_NEWCONNECTED.
|
|
|
|
* If the latter, then this is a retry by the client,
|
|
|
|
* so be nice, and resend.
|
|
|
|
*/
|
|
|
|
sp = NG_HOOK_PRIVATE(sendhook);
|
|
|
|
if (sp->state == PPPOE_NEWCONNECTED) {
|
|
|
|
/*
|
|
|
|
* Whoa! drop back to resend that PADS packet.
|
|
|
|
* We should still have a copy of it.
|
|
|
|
*/
|
|
|
|
sp->state = PPPOE_SOFFER;
|
2008-01-31 22:42:37 +00:00
|
|
|
} else if (sp->state != PPPOE_SOFFER)
|
2007-10-14 09:58:22 +00:00
|
|
|
LEAVE (ENETUNREACH);
|
|
|
|
neg = sp->neg;
|
|
|
|
ng_uncallout(&neg->handle, node);
|
|
|
|
neg->pkt->pkt_header.ph.code = PADS_CODE;
|
2008-01-31 22:42:37 +00:00
|
|
|
if (sp->Session_ID == 0) {
|
2007-10-14 09:58:22 +00:00
|
|
|
neg->pkt->pkt_header.ph.sid =
|
2008-03-02 23:26:35 +00:00
|
|
|
htons(pppoe_getnewsession(sp));
|
2008-01-31 22:42:37 +00:00
|
|
|
}
|
2007-10-14 09:58:22 +00:00
|
|
|
send_sessionid(sp);
|
|
|
|
neg->timeout = 0;
|
1999-10-21 09:06:11 +00:00
|
|
|
/*
|
2007-10-14 09:58:22 +00:00
|
|
|
* start working out the tags to respond with.
|
1999-10-21 09:06:11 +00:00
|
|
|
*/
|
|
|
|
init_tags(sp);
|
|
|
|
insert_tag(sp, &neg->ac_name.hdr); /* AC_NAME */
|
1999-11-14 17:26:58 +00:00
|
|
|
if ((tag = get_tag(ph, PTT_SRV_NAME)))
|
2007-10-14 09:58:22 +00:00
|
|
|
insert_tag(sp, tag);/* return service */
|
1999-11-14 17:26:58 +00:00
|
|
|
if ((tag = get_tag(ph, PTT_HOST_UNIQ)))
|
2007-10-14 09:58:22 +00:00
|
|
|
insert_tag(sp, tag); /* return it */
|
|
|
|
insert_tag(sp, utag); /* ac_cookie */
|
1999-10-21 09:06:11 +00:00
|
|
|
scan_tags(sp, ph);
|
|
|
|
make_packet(sp);
|
2007-10-14 09:58:22 +00:00
|
|
|
sp->state = PPPOE_NEWCONNECTED;
|
|
|
|
|
|
|
|
/* Send the PADS without a timeout - we're now connected. */
|
2012-12-05 08:04:20 +00:00
|
|
|
m0 = m_copypacket(sp->neg->m, M_NOWAIT);
|
2007-10-14 09:58:22 +00:00
|
|
|
NG_FWD_NEW_DATA(error, item, privp->ethernet_hook, m0);
|
|
|
|
|
2007-10-14 09:51:19 +00:00
|
|
|
/*
|
2007-10-14 09:58:22 +00:00
|
|
|
* Having sent the last Negotiation header,
|
|
|
|
* Set up the stored packet header to be correct for
|
|
|
|
* the actual session. But keep the negotialtion stuff
|
|
|
|
* around in case we need to resend this last packet.
|
|
|
|
* We'll discard it when we move from NEWCONNECTED
|
|
|
|
* to CONNECTED
|
2007-10-14 09:51:19 +00:00
|
|
|
*/
|
2007-10-14 09:58:22 +00:00
|
|
|
sp->pkt_hdr = neg->pkt->pkt_header;
|
|
|
|
/* Configure ethertype depending on what
|
|
|
|
* ethertype was used at discovery phase */
|
|
|
|
if (sp->pkt_hdr.eh.ether_type ==
|
|
|
|
ETHERTYPE_PPPOE_3COM_DISC)
|
|
|
|
sp->pkt_hdr.eh.ether_type
|
|
|
|
= ETHERTYPE_PPPOE_3COM_SESS;
|
|
|
|
else
|
|
|
|
sp->pkt_hdr.eh.ether_type
|
|
|
|
= ETHERTYPE_PPPOE_SESS;
|
|
|
|
sp->pkt_hdr.ph.code = 0;
|
|
|
|
pppoe_send_event(sp, NGM_PPPOE_SUCCESS);
|
1999-10-21 09:06:11 +00:00
|
|
|
break;
|
2007-10-14 09:58:22 +00:00
|
|
|
case PADS_CODE:
|
|
|
|
/*
|
|
|
|
* We are a client:
|
|
|
|
* Use the host_uniq tag to find the hook this is in
|
|
|
|
* response to. Take the session ID and store it away.
|
|
|
|
* Also make sure the pre-made header is correct and
|
|
|
|
* set us into Session mode.
|
|
|
|
*/
|
|
|
|
utag = get_tag(ph, PTT_HOST_UNIQ);
|
|
|
|
if ((utag == NULL) ||
|
|
|
|
(ntohs(utag->tag_len) != sizeof(sp))) {
|
|
|
|
LEAVE (ENETUNREACH);
|
|
|
|
}
|
|
|
|
sendhook = pppoe_finduniq(node, utag);
|
|
|
|
if (sendhook == NULL)
|
|
|
|
LEAVE(ENETUNREACH);
|
1999-10-21 09:06:11 +00:00
|
|
|
|
2007-10-14 09:58:22 +00:00
|
|
|
/*
|
|
|
|
* Check the session is in the right state.
|
|
|
|
* It needs to be in PPPOE_SREQ.
|
|
|
|
*/
|
|
|
|
sp = NG_HOOK_PRIVATE(sendhook);
|
|
|
|
if (sp->state != PPPOE_SREQ)
|
|
|
|
LEAVE(ENETUNREACH);
|
|
|
|
neg = sp->neg;
|
|
|
|
ng_uncallout(&neg->handle, node);
|
|
|
|
neg->pkt->pkt_header.ph.sid = wh->ph.sid;
|
|
|
|
sp->Session_ID = ntohs(wh->ph.sid);
|
2008-01-31 22:42:37 +00:00
|
|
|
pppoe_addsession(sp);
|
2007-10-14 09:58:22 +00:00
|
|
|
send_sessionid(sp);
|
|
|
|
neg->timeout = 0;
|
|
|
|
sp->state = PPPOE_CONNECTED;
|
|
|
|
/*
|
|
|
|
* Now we have gone to Connected mode,
|
|
|
|
* Free all resources needed for negotiation.
|
|
|
|
* Keep a copy of the header we will be using.
|
|
|
|
*/
|
|
|
|
sp->pkt_hdr = neg->pkt->pkt_header;
|
|
|
|
if (privp->flags & COMPAT_3COM)
|
|
|
|
sp->pkt_hdr.eh.ether_type
|
|
|
|
= ETHERTYPE_PPPOE_3COM_SESS;
|
|
|
|
else
|
|
|
|
sp->pkt_hdr.eh.ether_type
|
|
|
|
= ETHERTYPE_PPPOE_SESS;
|
|
|
|
sp->pkt_hdr.ph.code = 0;
|
|
|
|
m_freem(neg->m);
|
|
|
|
free(sp->neg, M_NETGRAPH_PPPOE);
|
|
|
|
sp->neg = NULL;
|
|
|
|
pppoe_send_event(sp, NGM_PPPOE_SUCCESS);
|
|
|
|
break;
|
|
|
|
case PADT_CODE:
|
|
|
|
/*
|
|
|
|
* Find matching peer/session combination.
|
|
|
|
*/
|
2008-01-31 22:42:37 +00:00
|
|
|
sp = pppoe_findsession(privp, wh);
|
|
|
|
if (sp == NULL)
|
2007-10-14 09:58:22 +00:00
|
|
|
LEAVE(ENETUNREACH);
|
|
|
|
/* Disconnect that hook. */
|
2008-01-31 22:42:37 +00:00
|
|
|
ng_rmhook_self(sp->hook);
|
2007-10-14 09:58:22 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
LEAVE(EPFNOSUPPORT);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ETHERTYPE_PPPOE_3COM_SESS:
|
|
|
|
case ETHERTYPE_PPPOE_SESS:
|
1999-10-21 09:06:11 +00:00
|
|
|
/*
|
2007-10-14 09:58:22 +00:00
|
|
|
* Find matching peer/session combination.
|
1999-10-21 09:06:11 +00:00
|
|
|
*/
|
2008-01-31 22:42:37 +00:00
|
|
|
sp = pppoe_findsession(privp, wh);
|
|
|
|
if (sp == NULL)
|
2007-10-14 09:58:22 +00:00
|
|
|
LEAVE (ENETUNREACH);
|
|
|
|
m_adj(m, sizeof(*wh));
|
|
|
|
|
|
|
|
/* If packet too short, dump it. */
|
|
|
|
if (m->m_pkthdr.len < length)
|
|
|
|
LEAVE(EMSGSIZE);
|
|
|
|
/* Also need to trim excess at the end */
|
|
|
|
if (m->m_pkthdr.len > length) {
|
|
|
|
m_adj(m, -((int)(m->m_pkthdr.len - length)));
|
|
|
|
}
|
|
|
|
if ( sp->state != PPPOE_CONNECTED) {
|
|
|
|
if (sp->state == PPPOE_NEWCONNECTED) {
|
|
|
|
sp->state = PPPOE_CONNECTED;
|
|
|
|
/*
|
|
|
|
* Now we have gone to Connected mode,
|
|
|
|
* Free all resources needed for negotiation.
|
|
|
|
* Be paranoid about whether there may be
|
|
|
|
* a timeout.
|
|
|
|
*/
|
|
|
|
m_freem(sp->neg->m);
|
|
|
|
ng_uncallout(&sp->neg->handle, node);
|
|
|
|
free(sp->neg, M_NETGRAPH_PPPOE);
|
|
|
|
sp->neg = NULL;
|
|
|
|
} else {
|
|
|
|
LEAVE (ENETUNREACH);
|
|
|
|
}
|
1999-10-21 09:06:11 +00:00
|
|
|
}
|
2008-01-31 22:42:37 +00:00
|
|
|
NG_FWD_NEW_DATA(error, item, sp->hook, m);
|
2007-10-14 09:58:22 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
LEAVE(EPFNOSUPPORT);
|
1999-10-21 09:06:11 +00:00
|
|
|
}
|
|
|
|
quit:
|
2001-01-10 23:49:03 +00:00
|
|
|
if (item)
|
|
|
|
NG_FREE_ITEM(item);
|
2001-01-06 00:46:47 +00:00
|
|
|
NG_FREE_M(m);
|
2007-10-14 09:58:22 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Receive data from debug hook and bypass it to ether.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ng_pppoe_rcvdata_debug(hook_p hook, item_p item)
|
|
|
|
{
|
|
|
|
node_p node = NG_HOOK_NODE(hook);
|
|
|
|
const priv_p privp = NG_NODE_PRIVATE(node);
|
|
|
|
int error;
|
|
|
|
|
|
|
|
CTR6(KTR_NET, "%20s: node [%x] (%p) received %p on \"%s\" (%p)",
|
|
|
|
__func__, node->nd_ID, node, item, hook->hk_name, hook);
|
|
|
|
|
|
|
|
NG_FWD_ITEM_HOOK(error, item, privp->ethernet_hook);
|
|
|
|
privp->packets_out++;
|
|
|
|
return (error);
|
1999-10-21 09:06:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do local shutdown processing..
|
|
|
|
* If we are a persistant device, we might refuse to go away, and
|
|
|
|
* we'd only remove our links and reset ourself.
|
|
|
|
*/
|
|
|
|
static int
|
2001-01-06 00:46:47 +00:00
|
|
|
ng_pppoe_shutdown(node_p node)
|
1999-10-21 09:06:11 +00:00
|
|
|
{
|
2008-01-31 22:42:37 +00:00
|
|
|
const priv_p privp = NG_NODE_PRIVATE(node);
|
|
|
|
int i;
|
1999-10-21 09:06:11 +00:00
|
|
|
|
2008-01-31 22:42:37 +00:00
|
|
|
for (i = 0; i < SESSHASHSIZE; i++)
|
|
|
|
mtx_destroy(&privp->sesshash[i].mtx);
|
2001-01-08 05:34:06 +00:00
|
|
|
NG_NODE_SET_PRIVATE(node, NULL);
|
2008-01-31 22:42:37 +00:00
|
|
|
NG_NODE_UNREF(privp->node);
|
|
|
|
free(privp, M_NETGRAPH_PPPOE);
|
1999-10-21 09:06:11 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Hook disconnection
|
|
|
|
*
|
1999-11-21 10:43:05 +00:00
|
|
|
* Clean up all dangling links and information about the session/hook.
|
2006-01-21 08:13:19 +00:00
|
|
|
* For this type, removal of the last link destroys the node.
|
1999-10-21 09:06:11 +00:00
|
|
|
*/
|
|
|
|
static int
|
1999-10-27 11:29:51 +00:00
|
|
|
ng_pppoe_disconnect(hook_p hook)
|
1999-10-21 09:06:11 +00:00
|
|
|
{
|
2001-01-08 05:34:06 +00:00
|
|
|
node_p node = NG_HOOK_NODE(hook);
|
|
|
|
priv_p privp = NG_NODE_PRIVATE(node);
|
1999-10-21 09:06:11 +00:00
|
|
|
sessp sp;
|
|
|
|
|
2007-09-21 08:24:08 +00:00
|
|
|
if (hook == privp->debug_hook) {
|
1999-10-21 09:06:11 +00:00
|
|
|
privp->debug_hook = NULL;
|
2007-09-21 08:24:08 +00:00
|
|
|
} else if (hook == privp->ethernet_hook) {
|
1999-10-21 09:06:11 +00:00
|
|
|
privp->ethernet_hook = NULL;
|
2001-01-08 05:34:06 +00:00
|
|
|
if (NG_NODE_IS_VALID(node))
|
2001-01-06 00:46:47 +00:00
|
|
|
ng_rmnode_self(node);
|
1999-10-21 09:06:11 +00:00
|
|
|
} else {
|
2001-01-08 05:34:06 +00:00
|
|
|
sp = NG_HOOK_PRIVATE(hook);
|
1999-10-23 04:28:11 +00:00
|
|
|
if (sp->state != PPPOE_SNONE ) {
|
|
|
|
pppoe_send_event(sp, NGM_PPPOE_CLOSE);
|
|
|
|
}
|
2000-04-28 17:09:00 +00:00
|
|
|
/*
|
|
|
|
* According to the spec, if we are connected,
|
|
|
|
* we should send a DISC packet if we are shutting down
|
|
|
|
* a session.
|
|
|
|
*/
|
1999-10-26 11:04:25 +00:00
|
|
|
if ((privp->ethernet_hook)
|
|
|
|
&& ((sp->state == PPPOE_CONNECTED)
|
|
|
|
|| (sp->state == PPPOE_NEWCONNECTED))) {
|
|
|
|
struct mbuf *m;
|
|
|
|
|
2006-01-21 08:13:19 +00:00
|
|
|
/* Generate a packet of that type. */
|
2012-12-05 08:04:20 +00:00
|
|
|
MGETHDR(m, M_NOWAIT, MT_DATA);
|
2006-08-07 08:05:10 +00:00
|
|
|
if (m == NULL)
|
|
|
|
log(LOG_NOTICE, "ng_pppoe[%x]: session out of "
|
|
|
|
"mbufs\n", node->nd_ID);
|
1999-11-21 10:43:05 +00:00
|
|
|
else {
|
2007-09-21 08:16:33 +00:00
|
|
|
struct pppoe_full_hdr *wh;
|
|
|
|
struct pppoe_tag *tag;
|
|
|
|
int msglen = strlen(SIGNOFF);
|
|
|
|
int error = 0;
|
|
|
|
|
1999-11-21 10:43:05 +00:00
|
|
|
m->m_pkthdr.rcvif = NULL;
|
|
|
|
m->m_pkthdr.len = m->m_len = sizeof(*wh);
|
2007-09-21 08:16:33 +00:00
|
|
|
wh = mtod(m, struct pppoe_full_hdr *);
|
|
|
|
bcopy(&sp->pkt_hdr, wh, sizeof(*wh));
|
|
|
|
|
|
|
|
/* Revert the stored header to DISC/PADT mode. */
|
|
|
|
wh->ph.code = PADT_CODE;
|
|
|
|
/*
|
|
|
|
* Configure ethertype depending on what
|
|
|
|
* was used during sessions stage.
|
|
|
|
*/
|
|
|
|
if (wh->eh.ether_type ==
|
|
|
|
ETHERTYPE_PPPOE_3COM_SESS)
|
|
|
|
wh->eh.ether_type = ETHERTYPE_PPPOE_3COM_DISC;
|
|
|
|
else
|
|
|
|
wh->eh.ether_type = ETHERTYPE_PPPOE_DISC;
|
1999-11-21 10:43:05 +00:00
|
|
|
/*
|
|
|
|
* Add a General error message and adjust
|
2006-01-21 08:13:19 +00:00
|
|
|
* sizes.
|
1999-11-21 10:43:05 +00:00
|
|
|
*/
|
2009-03-03 18:47:33 +00:00
|
|
|
tag = (void *)(&wh->ph + 1);
|
1999-11-21 10:43:05 +00:00
|
|
|
tag->tag_type = PTT_GEN_ERR;
|
|
|
|
tag->tag_len = htons((u_int16_t)msglen);
|
2009-03-03 18:47:33 +00:00
|
|
|
strncpy((char *)(tag + 1), SIGNOFF, msglen);
|
1999-11-21 10:43:05 +00:00
|
|
|
m->m_pkthdr.len = (m->m_len += sizeof(*tag) +
|
|
|
|
msglen);
|
|
|
|
wh->ph.length = htons(sizeof(*tag) + msglen);
|
2001-01-06 00:46:47 +00:00
|
|
|
NG_SEND_DATA_ONLY(error,
|
|
|
|
privp->ethernet_hook, m);
|
1999-11-21 10:43:05 +00:00
|
|
|
}
|
1999-10-26 11:04:25 +00:00
|
|
|
}
|
2008-03-03 19:36:03 +00:00
|
|
|
if (sp->state == PPPOE_LISTENING)
|
|
|
|
LIST_REMOVE(sp, sessions);
|
|
|
|
else if (sp->Session_ID)
|
2008-01-31 22:42:37 +00:00
|
|
|
pppoe_delsession(sp);
|
2000-04-28 17:09:00 +00:00
|
|
|
/*
|
2000-07-14 11:17:16 +00:00
|
|
|
* As long as we have somewhere to store the timeout handle,
|
2000-04-28 17:09:00 +00:00
|
|
|
* we may have a timeout pending.. get rid of it.
|
|
|
|
*/
|
1999-10-23 15:15:42 +00:00
|
|
|
if (sp->neg) {
|
2004-12-08 13:27:54 +00:00
|
|
|
ng_uncallout(&sp->neg->handle, node);
|
1999-10-23 15:15:42 +00:00
|
|
|
if (sp->neg->m)
|
|
|
|
m_freem(sp->neg->m);
|
2006-01-21 08:13:19 +00:00
|
|
|
free(sp->neg, M_NETGRAPH_PPPOE);
|
1999-10-23 15:15:42 +00:00
|
|
|
}
|
2006-01-21 08:13:19 +00:00
|
|
|
free(sp, M_NETGRAPH_PPPOE);
|
2001-01-08 05:34:06 +00:00
|
|
|
NG_HOOK_SET_PRIVATE(hook, NULL);
|
1999-10-21 09:06:11 +00:00
|
|
|
}
|
2006-01-21 08:13:19 +00:00
|
|
|
if ((NG_NODE_NUMHOOKS(node) == 0) &&
|
|
|
|
(NG_NODE_IS_VALID(node)))
|
2001-01-06 00:46:47 +00:00
|
|
|
ng_rmnode_self(node);
|
1999-10-21 09:06:11 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2006-01-21 08:13:19 +00:00
|
|
|
* Timeouts come here.
|
1999-10-21 09:06:11 +00:00
|
|
|
*/
|
|
|
|
static void
|
2004-12-08 13:27:54 +00:00
|
|
|
pppoe_ticker(node_p node, hook_p hook, void *arg1, int arg2)
|
1999-10-21 09:06:11 +00:00
|
|
|
{
|
2006-01-21 08:13:19 +00:00
|
|
|
priv_p privp = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
|
2001-01-08 05:34:06 +00:00
|
|
|
sessp sp = NG_HOOK_PRIVATE(hook);
|
1999-10-21 09:06:11 +00:00
|
|
|
negp neg = sp->neg;
|
|
|
|
struct mbuf *m0 = NULL;
|
2006-01-21 08:13:19 +00:00
|
|
|
int error = 0;
|
1999-10-21 09:06:11 +00:00
|
|
|
|
2006-01-21 08:13:19 +00:00
|
|
|
CTR6(KTR_NET, "%20s: node [%x] (%p) hook \"%s\" (%p) session %d",
|
|
|
|
__func__, node->nd_ID, node, hook->hk_name, hook, sp->Session_ID);
|
1999-10-21 09:06:11 +00:00
|
|
|
switch(sp->state) {
|
|
|
|
/*
|
2006-01-21 08:13:19 +00:00
|
|
|
* Resend the last packet, using an exponential backoff.
|
1999-10-21 09:06:11 +00:00
|
|
|
* After a period of time, stop growing the backoff,
|
2006-01-21 08:13:19 +00:00
|
|
|
* And either leave it, or revert to the start.
|
1999-10-21 09:06:11 +00:00
|
|
|
*/
|
|
|
|
case PPPOE_SINIT:
|
|
|
|
case PPPOE_SREQ:
|
2006-01-21 08:13:19 +00:00
|
|
|
/* Timeouts on these produce resends. */
|
2012-12-05 08:04:20 +00:00
|
|
|
m0 = m_copypacket(sp->neg->m, M_NOWAIT);
|
2001-01-06 00:46:47 +00:00
|
|
|
NG_SEND_DATA_ONLY( error, privp->ethernet_hook, m0);
|
2004-12-08 13:27:54 +00:00
|
|
|
ng_callout(&neg->handle, node, hook, neg->timeout * hz,
|
|
|
|
pppoe_ticker, NULL, 0);
|
1999-10-21 09:06:11 +00:00
|
|
|
if ((neg->timeout <<= 1) > PPPOE_TIMEOUT_LIMIT) {
|
|
|
|
if (sp->state == PPPOE_SREQ) {
|
2006-01-21 08:13:19 +00:00
|
|
|
/* Revert to SINIT mode. */
|
1999-10-23 04:28:11 +00:00
|
|
|
pppoe_start(sp);
|
1999-10-21 09:06:11 +00:00
|
|
|
} else {
|
|
|
|
neg->timeout = PPPOE_TIMEOUT_LIMIT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PPPOE_PRIMED:
|
|
|
|
case PPPOE_SOFFER:
|
2006-01-21 08:13:19 +00:00
|
|
|
/* A timeout on these says "give up" */
|
2001-01-11 19:27:54 +00:00
|
|
|
ng_rmhook_self(hook);
|
1999-10-21 09:06:11 +00:00
|
|
|
break;
|
|
|
|
default:
|
2006-01-21 08:13:19 +00:00
|
|
|
/* Timeouts have no meaning in other states. */
|
2006-08-07 08:05:10 +00:00
|
|
|
log(LOG_NOTICE, "ng_pppoe[%x]: unexpected timeout\n",
|
|
|
|
node->nd_ID);
|
1999-10-21 09:06:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Parse an incoming packet to see if any tags should be copied to the
|
1999-11-14 10:21:26 +00:00
|
|
|
* output packet. Don't do any tags that have been handled in the main
|
|
|
|
* state machine.
|
1999-10-21 09:06:11 +00:00
|
|
|
*/
|
2006-01-21 08:13:19 +00:00
|
|
|
static const struct pppoe_tag*
|
2002-06-05 23:35:31 +00:00
|
|
|
scan_tags(sessp sp, const struct pppoe_hdr* ph)
|
1999-10-21 09:06:11 +00:00
|
|
|
{
|
2002-06-05 23:35:31 +00:00
|
|
|
const char *const end = (const char *)next_tag(ph);
|
|
|
|
const char *ptn;
|
2009-03-03 18:47:33 +00:00
|
|
|
const struct pppoe_tag *pt = (const void *)(ph + 1);
|
2006-01-21 08:13:19 +00:00
|
|
|
|
1999-10-21 09:06:11 +00:00
|
|
|
/*
|
|
|
|
* Keep processing tags while a tag header will still fit.
|
|
|
|
*/
|
2006-01-21 08:13:19 +00:00
|
|
|
CTR2(KTR_NET, "%20s: called %d", __func__, sp->Session_ID);
|
|
|
|
|
2002-06-05 23:35:31 +00:00
|
|
|
while((const char*)(pt + 1) <= end) {
|
1999-10-21 09:06:11 +00:00
|
|
|
/*
|
|
|
|
* If the tag data would go past the end of the packet, abort.
|
|
|
|
*/
|
2002-06-05 23:35:31 +00:00
|
|
|
ptn = (((const char *)(pt + 1)) + ntohs(pt->tag_len));
|
1999-10-21 09:06:11 +00:00
|
|
|
if(ptn > end)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
switch (pt->tag_type) {
|
|
|
|
case PTT_RELAY_SID:
|
|
|
|
insert_tag(sp, pt);
|
|
|
|
break;
|
|
|
|
case PTT_EOL:
|
|
|
|
return NULL;
|
|
|
|
case PTT_SRV_NAME:
|
|
|
|
case PTT_AC_NAME:
|
|
|
|
case PTT_HOST_UNIQ:
|
|
|
|
case PTT_AC_COOKIE:
|
|
|
|
case PTT_VENDOR:
|
|
|
|
case PTT_SRV_ERR:
|
|
|
|
case PTT_SYS_ERR:
|
|
|
|
case PTT_GEN_ERR:
|
2013-07-23 10:25:34 +00:00
|
|
|
case PTT_MAX_PAYL:
|
1999-10-21 09:06:11 +00:00
|
|
|
break;
|
|
|
|
}
|
2002-06-05 23:35:31 +00:00
|
|
|
pt = (const struct pppoe_tag*)ptn;
|
1999-10-21 09:06:11 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1999-10-23 04:28:11 +00:00
|
|
|
static int
|
|
|
|
pppoe_send_event(sessp sp, enum cmd cmdid)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
struct ng_mesg *msg;
|
1999-10-27 11:29:51 +00:00
|
|
|
struct ngpppoe_sts *sts;
|
1999-10-23 04:28:11 +00:00
|
|
|
|
2006-01-21 08:13:19 +00:00
|
|
|
CTR2(KTR_NET, "%20s: called %d", __func__, sp->Session_ID);
|
|
|
|
|
2000-11-16 23:14:53 +00:00
|
|
|
NG_MKMESSAGE(msg, NGM_PPPOE_COOKIE, cmdid,
|
1999-10-27 11:29:51 +00:00
|
|
|
sizeof(struct ngpppoe_sts), M_NOWAIT);
|
2000-12-12 18:52:14 +00:00
|
|
|
if (msg == NULL)
|
|
|
|
return (ENOMEM);
|
1999-10-27 11:29:51 +00:00
|
|
|
sts = (struct ngpppoe_sts *)msg->data;
|
2004-01-26 14:05:31 +00:00
|
|
|
strncpy(sts->hook, NG_HOOK_NAME(sp->hook), NG_HOOKSIZ);
|
2002-08-22 00:30:03 +00:00
|
|
|
NG_SEND_MSG_ID(error, NG_HOOK_NODE(sp->hook), msg, sp->creator, 0);
|
1999-10-23 04:28:11 +00:00
|
|
|
return (error);
|
|
|
|
}
|