2016-10-03 14:06:06 +03:00
|
|
|
/* $NetBSD: if_pppoe.c,v 1.118 2016/10/03 11:06:06 ozaki-r Exp $ */
|
2001-04-29 13:50:36 +04:00
|
|
|
|
2002-04-14 16:24:26 +04:00
|
|
|
/*-
|
2008-08-19 00:43:50 +04:00
|
|
|
* Copyright (c) 2002, 2008 The NetBSD Foundation, Inc.
|
2002-04-14 16:24:26 +04:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
2003-11-28 11:56:48 +03:00
|
|
|
* by Martin Husemann <martin@NetBSD.org>.
|
2001-04-29 13:50:36 +04:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
2002-04-14 16:24:26 +04:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON 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 ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
2001-04-29 13:50:36 +04:00
|
|
|
*/
|
|
|
|
|
2001-11-13 02:49:33 +03:00
|
|
|
#include <sys/cdefs.h>
|
2016-10-03 14:06:06 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.118 2016/10/03 11:06:06 ozaki-r Exp $");
|
2015-08-25 01:21:26 +03:00
|
|
|
|
|
|
|
#ifdef _KERNEL_OPT
|
2016-08-07 02:46:30 +03:00
|
|
|
#include "pppoe.h"
|
2006-08-05 21:20:54 +04:00
|
|
|
#include "opt_pppoe.h"
|
2015-08-25 01:21:26 +03:00
|
|
|
#endif
|
2001-04-29 13:50:36 +04:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/callout.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/ioctl.h>
|
2006-05-15 01:19:33 +04:00
|
|
|
#include <sys/kauth.h>
|
2007-10-08 20:18:02 +04:00
|
|
|
#include <sys/intr.h>
|
2008-04-24 15:38:36 +04:00
|
|
|
#include <sys/socketvar.h>
|
2016-08-07 02:46:30 +03:00
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/module.h>
|
2016-08-07 04:59:43 +03:00
|
|
|
#include <sys/sysctl.h>
|
2007-10-08 20:18:02 +04:00
|
|
|
|
2001-04-29 13:50:36 +04:00
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_types.h>
|
|
|
|
#include <net/if_ether.h>
|
|
|
|
#include <net/if_sppp.h>
|
2002-01-04 15:21:24 +03:00
|
|
|
#include <net/if_spppvar.h>
|
2001-04-29 13:50:36 +04:00
|
|
|
#include <net/if_pppoe.h>
|
|
|
|
|
|
|
|
#include <net/bpf.h>
|
|
|
|
|
2015-08-20 17:40:16 +03:00
|
|
|
#include "ioconf.h"
|
2002-01-13 13:57:57 +03:00
|
|
|
|
2002-06-22 15:37:48 +04:00
|
|
|
struct pppoehdr {
|
2008-02-20 20:05:52 +03:00
|
|
|
uint8_t vertype;
|
|
|
|
uint8_t code;
|
|
|
|
uint16_t session;
|
|
|
|
uint16_t plen;
|
2007-12-25 21:33:32 +03:00
|
|
|
} __packed;
|
2002-06-22 15:37:48 +04:00
|
|
|
|
|
|
|
struct pppoetag {
|
2008-02-20 20:05:52 +03:00
|
|
|
uint16_t tag;
|
|
|
|
uint16_t len;
|
2007-12-25 21:33:32 +03:00
|
|
|
} __packed;
|
2002-06-22 15:37:48 +04:00
|
|
|
|
2008-08-19 14:41:10 +04:00
|
|
|
#define PPPOE_HEADERLEN sizeof(struct pppoehdr)
|
2006-04-28 00:04:26 +04:00
|
|
|
#define PPPOE_OVERHEAD (PPPOE_HEADERLEN + 2)
|
2001-04-29 13:50:36 +04:00
|
|
|
#define PPPOE_VERTYPE 0x11 /* VER=1, TYPE = 1 */
|
|
|
|
|
|
|
|
#define PPPOE_TAG_EOL 0x0000 /* end of list */
|
|
|
|
#define PPPOE_TAG_SNAME 0x0101 /* service name */
|
|
|
|
#define PPPOE_TAG_ACNAME 0x0102 /* access concentrator name */
|
|
|
|
#define PPPOE_TAG_HUNIQUE 0x0103 /* host unique */
|
|
|
|
#define PPPOE_TAG_ACCOOKIE 0x0104 /* AC cookie */
|
|
|
|
#define PPPOE_TAG_VENDOR 0x0105 /* vendor specific */
|
|
|
|
#define PPPOE_TAG_RELAYSID 0x0110 /* relay session id */
|
2011-09-05 16:19:09 +04:00
|
|
|
#define PPPOE_TAG_MAX_PAYLOAD 0x0120 /* max payload */
|
2001-04-29 13:50:36 +04:00
|
|
|
#define PPPOE_TAG_SNAME_ERR 0x0201 /* service name error */
|
|
|
|
#define PPPOE_TAG_ACSYS_ERR 0x0202 /* AC system error */
|
2011-08-31 02:23:06 +04:00
|
|
|
#define PPPOE_TAG_GENERIC_ERR 0x0203 /* generic error */
|
2001-04-29 13:50:36 +04:00
|
|
|
|
2008-08-19 14:41:10 +04:00
|
|
|
#define PPPOE_CODE_PADI 0x09 /* Active Discovery Initiation */
|
2001-04-29 13:50:36 +04:00
|
|
|
#define PPPOE_CODE_PADO 0x07 /* Active Discovery Offer */
|
|
|
|
#define PPPOE_CODE_PADR 0x19 /* Active Discovery Request */
|
|
|
|
#define PPPOE_CODE_PADS 0x65 /* Active Discovery Session confirmation */
|
|
|
|
#define PPPOE_CODE_PADT 0xA7 /* Active Discovery Terminate */
|
|
|
|
|
2002-02-01 16:40:16 +03:00
|
|
|
/* two byte PPP protocol discriminator, then IP data */
|
2006-04-28 00:04:26 +04:00
|
|
|
#define PPPOE_MAXMTU (ETHERMTU - PPPOE_OVERHEAD)
|
2002-02-01 16:40:16 +03:00
|
|
|
|
2001-04-29 13:50:36 +04:00
|
|
|
/* Add a 16 bit unsigned value to a buffer pointed to by PTR */
|
|
|
|
#define PPPOE_ADD_16(PTR, VAL) \
|
|
|
|
*(PTR)++ = (VAL) / 256; \
|
|
|
|
*(PTR)++ = (VAL) % 256
|
|
|
|
|
|
|
|
/* Add a complete PPPoE header to the buffer pointed to by PTR */
|
2008-08-19 14:41:10 +04:00
|
|
|
#define PPPOE_ADD_HEADER(PTR, CODE, SESS, LEN) \
|
2001-04-29 13:50:36 +04:00
|
|
|
*(PTR)++ = PPPOE_VERTYPE; \
|
|
|
|
*(PTR)++ = (CODE); \
|
|
|
|
PPPOE_ADD_16(PTR, SESS); \
|
|
|
|
PPPOE_ADD_16(PTR, LEN)
|
|
|
|
|
2001-12-16 14:40:52 +03:00
|
|
|
#define PPPOE_DISC_TIMEOUT (hz*5) /* base for quick timeout calculation */
|
2002-02-01 16:40:16 +03:00
|
|
|
#define PPPOE_SLOW_RETRY (hz*60) /* persistent retry interval */
|
2008-08-19 01:43:49 +04:00
|
|
|
#define PPPOE_RECON_FAST (hz*15) /* first retry after auth failure */
|
2008-08-20 02:03:05 +04:00
|
|
|
#define PPPOE_RECON_IMMEDIATE (hz/10) /* "no delay" reconnect */
|
2008-08-19 14:41:10 +04:00
|
|
|
#define PPPOE_DISC_MAXPADI 4 /* retry PADI four times (quickly) */
|
2001-12-15 23:43:31 +03:00
|
|
|
#define PPPOE_DISC_MAXPADR 2 /* retry PADR twice */
|
|
|
|
|
2003-06-18 12:12:51 +04:00
|
|
|
#ifdef PPPOE_SERVER
|
|
|
|
/* from if_spppsubr.c */
|
2008-08-19 14:41:10 +04:00
|
|
|
#define IFF_PASSIVE IFF_LINK0 /* wait passively for connection */
|
2003-06-18 12:12:51 +04:00
|
|
|
#endif
|
|
|
|
|
2001-04-29 13:50:36 +04:00
|
|
|
struct pppoe_softc {
|
|
|
|
struct sppp sc_sppp; /* contains a struct ifnet as first element */
|
2001-09-05 00:41:32 +04:00
|
|
|
LIST_ENTRY(pppoe_softc) sc_list;
|
2001-04-29 13:50:36 +04:00
|
|
|
struct ifnet *sc_eth_if; /* ethernet interface we are using */
|
2002-06-22 09:52:00 +04:00
|
|
|
|
2001-04-29 13:50:36 +04:00
|
|
|
int sc_state; /* discovery phase or session connected */
|
|
|
|
struct ether_addr sc_dest; /* hardware address of concentrator */
|
2008-02-20 20:05:52 +03:00
|
|
|
uint16_t sc_session; /* PPPoE session id */
|
2001-04-29 13:50:36 +04:00
|
|
|
|
|
|
|
char *sc_service_name; /* if != NULL: requested name of service */
|
|
|
|
char *sc_concentrator_name; /* if != NULL: requested concentrator id */
|
2008-02-20 20:05:52 +03:00
|
|
|
uint8_t *sc_ac_cookie; /* content of AC cookie we must echo back */
|
2001-04-29 13:50:36 +04:00
|
|
|
size_t sc_ac_cookie_len; /* length of cookie data */
|
2009-02-19 18:17:50 +03:00
|
|
|
uint8_t *sc_relay_sid; /* content of relay SID we must echo back */
|
|
|
|
size_t sc_relay_sid_len; /* length of relay SID data */
|
2003-06-18 12:12:51 +04:00
|
|
|
#ifdef PPPOE_SERVER
|
2008-02-20 20:05:52 +03:00
|
|
|
uint8_t *sc_hunique; /* content of host unique we must echo back */
|
2003-06-18 12:12:51 +04:00
|
|
|
size_t sc_hunique_len; /* length of host unique */
|
|
|
|
#endif
|
2007-07-10 00:51:58 +04:00
|
|
|
callout_t sc_timeout; /* timeout while not in session state */
|
2001-04-29 13:50:36 +04:00
|
|
|
int sc_padi_retried; /* number of PADI retries already done */
|
|
|
|
int sc_padr_retried; /* number of PADR retries already done */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* incoming traffic will be queued here */
|
2006-08-30 20:57:59 +04:00
|
|
|
struct ifqueue ppoediscinq = { .ifq_maxlen = IFQ_MAXLEN };
|
|
|
|
struct ifqueue ppoeinq = { .ifq_maxlen = IFQ_MAXLEN };
|
2001-04-29 13:50:36 +04:00
|
|
|
|
2007-03-04 08:59:00 +03:00
|
|
|
void *pppoe_softintr = NULL;
|
2001-04-29 13:50:36 +04:00
|
|
|
static void pppoe_softintr_handler(void *);
|
|
|
|
|
2002-06-22 09:33:42 +04:00
|
|
|
extern int sppp_ioctl(struct ifnet *, unsigned long, void *);
|
2001-04-29 13:50:36 +04:00
|
|
|
|
|
|
|
/* input routines */
|
2016-04-15 04:31:29 +03:00
|
|
|
static void pppoeintr(void);
|
2002-06-22 09:33:42 +04:00
|
|
|
static void pppoe_disc_input(struct mbuf *);
|
2002-06-22 15:37:48 +04:00
|
|
|
static void pppoe_dispatch_disc_pkt(struct mbuf *, int);
|
|
|
|
static void pppoe_data_input(struct mbuf *);
|
2016-04-15 04:31:29 +03:00
|
|
|
static void pppoe_enqueue(struct ifqueue *, struct mbuf *);
|
2001-04-29 13:50:36 +04:00
|
|
|
|
|
|
|
/* management routines */
|
2002-06-22 09:33:42 +04:00
|
|
|
static int pppoe_connect(struct pppoe_softc *);
|
|
|
|
static int pppoe_disconnect(struct pppoe_softc *);
|
|
|
|
static void pppoe_abort_connect(struct pppoe_softc *);
|
2007-03-04 08:59:00 +03:00
|
|
|
static int pppoe_ioctl(struct ifnet *, unsigned long, void *);
|
2002-06-22 09:33:42 +04:00
|
|
|
static void pppoe_tls(struct sppp *);
|
|
|
|
static void pppoe_tlf(struct sppp *);
|
|
|
|
static void pppoe_start(struct ifnet *);
|
2004-12-08 10:43:29 +03:00
|
|
|
static void pppoe_clear_softc(struct pppoe_softc *, const char *);
|
2001-04-29 13:50:36 +04:00
|
|
|
|
|
|
|
/* internal timeout handling */
|
2002-06-22 09:52:00 +04:00
|
|
|
static void pppoe_timeout(void *);
|
2001-04-29 13:50:36 +04:00
|
|
|
|
|
|
|
/* sending actual protocol controll packets */
|
2002-06-22 09:33:42 +04:00
|
|
|
static int pppoe_send_padi(struct pppoe_softc *);
|
|
|
|
static int pppoe_send_padr(struct pppoe_softc *);
|
2003-06-18 12:12:51 +04:00
|
|
|
#ifdef PPPOE_SERVER
|
|
|
|
static int pppoe_send_pado(struct pppoe_softc *);
|
|
|
|
static int pppoe_send_pads(struct pppoe_softc *);
|
|
|
|
#endif
|
2008-02-20 20:05:52 +03:00
|
|
|
static int pppoe_send_padt(struct ifnet *, u_int, const uint8_t *);
|
2001-04-29 13:50:36 +04:00
|
|
|
|
|
|
|
/* raw output */
|
2002-06-22 09:52:00 +04:00
|
|
|
static int pppoe_output(struct pppoe_softc *, struct mbuf *);
|
2001-04-29 13:50:36 +04:00
|
|
|
|
|
|
|
/* internal helper functions */
|
2002-06-22 09:33:42 +04:00
|
|
|
static struct pppoe_softc * pppoe_find_softc_by_session(u_int, struct ifnet *);
|
2008-02-20 20:05:52 +03:00
|
|
|
static struct pppoe_softc * pppoe_find_softc_by_hunique(uint8_t *, size_t, struct ifnet *);
|
2002-09-01 21:21:40 +04:00
|
|
|
static struct mbuf *pppoe_get_mbuf(size_t len);
|
2001-04-29 13:50:36 +04:00
|
|
|
|
2004-11-28 14:44:36 +03:00
|
|
|
static int pppoe_ifattach_hook(void *, struct mbuf **, struct ifnet *, int);
|
|
|
|
|
2005-12-12 02:05:24 +03:00
|
|
|
static LIST_HEAD(pppoe_softc_head, pppoe_softc) pppoe_softc_list;
|
2001-04-29 13:50:36 +04:00
|
|
|
|
2005-12-12 02:05:24 +03:00
|
|
|
static int pppoe_clone_create(struct if_clone *, int);
|
|
|
|
static int pppoe_clone_destroy(struct ifnet *);
|
2001-09-05 00:41:32 +04:00
|
|
|
|
2016-08-07 04:59:43 +03:00
|
|
|
static bool pppoe_term_unknown = false;
|
|
|
|
|
|
|
|
static struct sysctllog *pppoe_sysctl_clog;
|
2016-08-11 18:16:07 +03:00
|
|
|
static void sysctl_net_pppoe_setup(struct sysctllog **);
|
2016-08-07 04:59:43 +03:00
|
|
|
|
2005-12-12 02:05:24 +03:00
|
|
|
static struct if_clone pppoe_cloner =
|
2001-09-05 00:41:32 +04:00
|
|
|
IF_CLONE_INITIALIZER("pppoe", pppoe_clone_create, pppoe_clone_destroy);
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
2001-04-29 13:50:36 +04:00
|
|
|
void
|
2006-11-16 04:32:37 +03:00
|
|
|
pppoeattach(int count)
|
2001-09-05 00:41:32 +04:00
|
|
|
{
|
2016-08-07 02:46:30 +03:00
|
|
|
|
|
|
|
/*
|
2016-08-07 20:38:33 +03:00
|
|
|
* Nothing to do here, initialization is handled by the
|
|
|
|
* module initialization code in pppoeinit() below).
|
2016-08-07 02:46:30 +03:00
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pppoeinit(void)
|
|
|
|
{
|
|
|
|
|
2001-09-05 00:41:32 +04:00
|
|
|
LIST_INIT(&pppoe_softc_list);
|
|
|
|
if_clone_attach(&pppoe_cloner);
|
|
|
|
|
2016-07-07 09:55:38 +03:00
|
|
|
pppoe_softintr = softint_establish(SOFTINT_NET, pppoe_softintr_handler,
|
|
|
|
NULL);
|
2016-08-07 20:38:33 +03:00
|
|
|
sysctl_net_pppoe_setup(&pppoe_sysctl_clog);
|
2016-10-03 14:06:06 +03:00
|
|
|
|
|
|
|
IFQ_LOCK_INIT(&ppoediscinq);
|
|
|
|
IFQ_LOCK_INIT(&ppoeinq);
|
2001-09-05 00:41:32 +04:00
|
|
|
}
|
|
|
|
|
2016-08-07 02:46:30 +03:00
|
|
|
static int
|
|
|
|
pppoedetach(void)
|
|
|
|
{
|
2016-08-07 20:38:33 +03:00
|
|
|
int error = 0;
|
2016-08-07 02:46:30 +03:00
|
|
|
|
2016-08-07 20:38:33 +03:00
|
|
|
if (!LIST_EMPTY(&pppoe_softc_list))
|
|
|
|
error = EBUSY;
|
2016-08-07 02:46:30 +03:00
|
|
|
|
2016-08-07 20:38:33 +03:00
|
|
|
if (error == 0) {
|
|
|
|
if_clone_detach(&pppoe_cloner);
|
|
|
|
softint_disestablish(pppoe_softintr);
|
|
|
|
/* Remove our sysctl sub-tree */
|
|
|
|
sysctl_teardown(&pppoe_sysctl_clog);
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
2016-08-07 02:46:30 +03:00
|
|
|
}
|
|
|
|
|
2005-12-12 02:05:24 +03:00
|
|
|
static int
|
2006-11-16 04:32:37 +03:00
|
|
|
pppoe_clone_create(struct if_clone *ifc, int unit)
|
2001-04-29 13:50:36 +04:00
|
|
|
{
|
|
|
|
struct pppoe_softc *sc;
|
2001-09-05 00:41:32 +04:00
|
|
|
|
2008-06-15 20:37:21 +04:00
|
|
|
sc = malloc(sizeof(struct pppoe_softc), M_DEVBUF, M_WAITOK|M_ZERO);
|
2001-09-05 00:41:32 +04:00
|
|
|
|
2008-06-15 20:37:21 +04:00
|
|
|
if_initname(&sc->sc_sppp.pp_if, "pppoe", unit);
|
2001-09-05 00:41:32 +04:00
|
|
|
sc->sc_sppp.pp_if.if_softc = sc;
|
2002-02-01 16:40:16 +03:00
|
|
|
sc->sc_sppp.pp_if.if_mtu = PPPOE_MAXMTU;
|
2001-12-10 03:24:12 +03:00
|
|
|
sc->sc_sppp.pp_if.if_flags = IFF_SIMPLEX|IFF_POINTOPOINT|IFF_MULTICAST;
|
2001-09-05 00:41:32 +04:00
|
|
|
sc->sc_sppp.pp_if.if_type = IFT_PPP;
|
2002-06-22 09:59:27 +04:00
|
|
|
sc->sc_sppp.pp_if.if_hdrlen = sizeof(struct ether_header) + PPPOE_HEADERLEN;
|
2001-09-05 00:41:32 +04:00
|
|
|
sc->sc_sppp.pp_if.if_dlt = DLT_PPP_ETHER;
|
2002-06-22 09:59:27 +04:00
|
|
|
sc->sc_sppp.pp_flags |= PP_KEEPALIVE | /* use LCP keepalive */
|
2001-12-11 02:23:24 +03:00
|
|
|
PP_NOFRAMING; /* no serial encapsulation */
|
2001-09-05 00:41:32 +04:00
|
|
|
sc->sc_sppp.pp_if.if_ioctl = pppoe_ioctl;
|
|
|
|
IFQ_SET_MAXLEN(&sc->sc_sppp.pp_if.if_snd, IFQ_MAXLEN);
|
|
|
|
IFQ_SET_READY(&sc->sc_sppp.pp_if.if_snd);
|
|
|
|
|
|
|
|
/* changed to real address later */
|
|
|
|
memcpy(&sc->sc_dest, etherbroadcastaddr, sizeof(sc->sc_dest));
|
|
|
|
|
2007-07-10 00:51:58 +04:00
|
|
|
callout_init(&sc->sc_timeout, 0);
|
2001-09-05 00:41:32 +04:00
|
|
|
|
|
|
|
sc->sc_sppp.pp_if.if_start = pppoe_start;
|
|
|
|
sc->sc_sppp.pp_tls = pppoe_tls;
|
|
|
|
sc->sc_sppp.pp_tlf = pppoe_tlf;
|
|
|
|
sc->sc_sppp.pp_framebytes = PPPOE_HEADERLEN; /* framing added to ppp packets */
|
2002-06-22 09:52:00 +04:00
|
|
|
|
2001-09-05 00:41:32 +04:00
|
|
|
if_attach(&sc->sc_sppp.pp_if);
|
|
|
|
sppp_attach(&sc->sc_sppp.pp_if);
|
2001-04-29 13:50:36 +04:00
|
|
|
|
2010-04-05 11:19:28 +04:00
|
|
|
bpf_attach(&sc->sc_sppp.pp_if, DLT_PPP_ETHER, 0);
|
2013-06-30 01:06:57 +04:00
|
|
|
if (LIST_EMPTY(&pppoe_softc_list)) {
|
|
|
|
pfil_add_hook(pppoe_ifattach_hook, NULL, PFIL_IFNET, if_pfil);
|
|
|
|
}
|
2001-09-05 00:41:32 +04:00
|
|
|
LIST_INSERT_HEAD(&pppoe_softc_list, sc, sc_list);
|
|
|
|
return 0;
|
|
|
|
}
|
2001-04-29 13:50:36 +04:00
|
|
|
|
2005-12-12 02:05:24 +03:00
|
|
|
static int
|
|
|
|
pppoe_clone_destroy(struct ifnet *ifp)
|
2001-09-05 00:41:32 +04:00
|
|
|
{
|
|
|
|
struct pppoe_softc * sc = ifp->if_softc;
|
2001-04-29 13:50:36 +04:00
|
|
|
|
2005-01-19 18:05:55 +03:00
|
|
|
callout_stop(&sc->sc_timeout);
|
2001-09-05 00:41:32 +04:00
|
|
|
LIST_REMOVE(sc, sc_list);
|
2013-06-30 01:06:57 +04:00
|
|
|
if (LIST_EMPTY(&pppoe_softc_list)) {
|
|
|
|
pfil_remove_hook(pppoe_ifattach_hook, NULL, PFIL_IFNET, if_pfil);
|
|
|
|
}
|
2010-04-05 11:19:28 +04:00
|
|
|
bpf_detach(ifp);
|
2001-10-28 12:48:20 +03:00
|
|
|
sppp_detach(&sc->sc_sppp.pp_if);
|
2001-09-05 00:41:32 +04:00
|
|
|
if_detach(ifp);
|
2002-06-22 21:41:23 +04:00
|
|
|
if (sc->sc_concentrator_name)
|
|
|
|
free(sc->sc_concentrator_name, M_DEVBUF);
|
|
|
|
if (sc->sc_service_name)
|
|
|
|
free(sc->sc_service_name, M_DEVBUF);
|
|
|
|
if (sc->sc_ac_cookie)
|
|
|
|
free(sc->sc_ac_cookie, M_DEVBUF);
|
2009-02-19 18:17:50 +03:00
|
|
|
if (sc->sc_relay_sid)
|
|
|
|
free(sc->sc_relay_sid, M_DEVBUF);
|
2007-07-10 00:51:58 +04:00
|
|
|
callout_destroy(&sc->sc_timeout);
|
2001-09-05 00:41:32 +04:00
|
|
|
free(sc, M_DEVBUF);
|
2004-12-04 21:31:43 +03:00
|
|
|
|
|
|
|
return (0);
|
2001-04-29 13:50:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the interface handling the specified session.
|
|
|
|
* Note: O(number of sessions open), this is a client-side only, mean
|
|
|
|
* and lean implementation, so number of open sessions typically should
|
|
|
|
* be 1.
|
|
|
|
*/
|
|
|
|
static struct pppoe_softc *
|
|
|
|
pppoe_find_softc_by_session(u_int session, struct ifnet *rcvif)
|
|
|
|
{
|
2001-09-05 00:41:32 +04:00
|
|
|
struct pppoe_softc *sc;
|
2001-04-29 13:50:36 +04:00
|
|
|
|
2002-06-22 09:52:00 +04:00
|
|
|
if (session == 0)
|
|
|
|
return NULL;
|
2001-04-29 13:50:36 +04:00
|
|
|
|
2001-09-05 00:41:32 +04:00
|
|
|
LIST_FOREACH(sc, &pppoe_softc_list, sc_list) {
|
|
|
|
if (sc->sc_state == PPPOE_STATE_SESSION
|
2008-10-16 00:08:33 +04:00
|
|
|
&& sc->sc_session == session
|
|
|
|
&& sc->sc_eth_if == rcvif)
|
|
|
|
return sc;
|
2001-04-29 13:50:36 +04:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check host unique token passed and return appropriate softc pointer,
|
|
|
|
* or NULL if token is bogus. */
|
|
|
|
static struct pppoe_softc *
|
2008-02-20 20:05:52 +03:00
|
|
|
pppoe_find_softc_by_hunique(uint8_t *token, size_t len, struct ifnet *rcvif)
|
2001-04-29 13:50:36 +04:00
|
|
|
{
|
2001-09-05 00:41:32 +04:00
|
|
|
struct pppoe_softc *sc, *t;
|
2001-12-01 21:25:23 +03:00
|
|
|
|
2002-06-22 09:52:00 +04:00
|
|
|
if (LIST_EMPTY(&pppoe_softc_list))
|
|
|
|
return NULL;
|
2001-12-01 21:25:23 +03:00
|
|
|
|
2002-06-22 09:52:00 +04:00
|
|
|
if (len != sizeof sc)
|
|
|
|
return NULL;
|
2001-09-05 00:41:32 +04:00
|
|
|
memcpy(&t, token, len);
|
|
|
|
|
|
|
|
LIST_FOREACH(sc, &pppoe_softc_list, sc_list)
|
|
|
|
if (sc == t) break;
|
|
|
|
|
2003-03-01 18:10:13 +03:00
|
|
|
if (sc == NULL) {
|
2001-04-29 13:50:36 +04:00
|
|
|
#ifdef PPPOE_DEBUG
|
2001-12-15 23:43:31 +03:00
|
|
|
printf("pppoe: alien host unique tag, no session found\n");
|
2001-04-29 13:50:36 +04:00
|
|
|
#endif
|
|
|
|
return NULL;
|
|
|
|
}
|
2001-09-05 00:41:32 +04:00
|
|
|
|
2001-04-29 13:50:36 +04:00
|
|
|
/* should be safe to access *sc now */
|
|
|
|
if (sc->sc_state < PPPOE_STATE_PADI_SENT || sc->sc_state >= PPPOE_STATE_SESSION) {
|
2001-12-15 23:43:31 +03:00
|
|
|
printf("%s: host unique tag found, but it belongs to a connection in state %d\n",
|
2001-04-29 13:50:36 +04:00
|
|
|
sc->sc_sppp.pp_if.if_xname, sc->sc_state);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (sc->sc_eth_if != rcvif) {
|
|
|
|
printf("%s: wrong interface, not accepting host unique\n",
|
|
|
|
sc->sc_sppp.pp_if.if_xname);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return sc;
|
|
|
|
}
|
|
|
|
|
2005-12-12 02:05:24 +03:00
|
|
|
static void
|
2006-11-16 04:32:37 +03:00
|
|
|
pppoe_softintr_handler(void *dummy)
|
2001-04-29 13:50:36 +04:00
|
|
|
{
|
|
|
|
/* called at splsoftnet() */
|
2008-04-24 15:38:36 +04:00
|
|
|
mutex_enter(softnet_lock);
|
2016-04-15 04:31:29 +03:00
|
|
|
pppoeintr();
|
2008-04-24 15:38:36 +04:00
|
|
|
mutex_exit(softnet_lock);
|
2001-04-29 13:50:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* called at appropriate protection level */
|
|
|
|
static void
|
2016-04-15 04:31:29 +03:00
|
|
|
pppoeintr(void)
|
2001-04-29 13:50:36 +04:00
|
|
|
{
|
|
|
|
struct mbuf *m;
|
2016-10-03 14:06:06 +03:00
|
|
|
int disc_done, data_done;
|
2001-04-29 13:50:36 +04:00
|
|
|
|
2001-06-18 16:32:47 +04:00
|
|
|
do {
|
|
|
|
disc_done = 0;
|
|
|
|
data_done = 0;
|
|
|
|
for (;;) {
|
2016-10-03 14:06:06 +03:00
|
|
|
IFQ_LOCK(&ppoediscinq);
|
2001-04-29 13:50:36 +04:00
|
|
|
IF_DEQUEUE(&ppoediscinq, m);
|
2016-10-03 14:06:06 +03:00
|
|
|
IFQ_UNLOCK(&ppoediscinq);
|
2001-06-18 16:32:47 +04:00
|
|
|
if (m == NULL) break;
|
|
|
|
disc_done = 1;
|
2001-04-29 13:50:36 +04:00
|
|
|
pppoe_disc_input(m);
|
|
|
|
}
|
2001-06-18 16:32:47 +04:00
|
|
|
|
|
|
|
for (;;) {
|
2016-10-03 14:06:06 +03:00
|
|
|
IFQ_LOCK(&ppoeinq);
|
2001-04-29 13:50:36 +04:00
|
|
|
IF_DEQUEUE(&ppoeinq, m);
|
2016-10-03 14:06:06 +03:00
|
|
|
IFQ_UNLOCK(&ppoeinq);
|
2001-06-18 16:32:47 +04:00
|
|
|
if (m == NULL) break;
|
|
|
|
data_done = 1;
|
2001-04-29 13:50:36 +04:00
|
|
|
pppoe_data_input(m);
|
|
|
|
}
|
2001-06-18 16:32:47 +04:00
|
|
|
} while (disc_done || data_done);
|
2001-04-29 13:50:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* analyze and handle a single received packet while not in session state */
|
2005-12-12 02:05:24 +03:00
|
|
|
static void
|
|
|
|
pppoe_dispatch_disc_pkt(struct mbuf *m, int off)
|
2001-04-29 13:50:36 +04:00
|
|
|
{
|
2008-02-20 20:05:52 +03:00
|
|
|
uint16_t tag, len;
|
|
|
|
uint16_t session, plen;
|
2001-04-29 13:50:36 +04:00
|
|
|
struct pppoe_softc *sc;
|
2006-02-01 02:50:15 +03:00
|
|
|
const char *err_msg, *devname;
|
|
|
|
char *error;
|
2008-02-20 20:05:52 +03:00
|
|
|
uint8_t *ac_cookie;
|
2001-04-29 13:50:36 +04:00
|
|
|
size_t ac_cookie_len;
|
2009-02-19 18:17:50 +03:00
|
|
|
uint8_t *relay_sid;
|
|
|
|
size_t relay_sid_len;
|
2003-06-18 12:12:51 +04:00
|
|
|
#ifdef PPPOE_SERVER
|
2008-02-20 20:05:52 +03:00
|
|
|
uint8_t *hunique;
|
2003-06-18 12:12:51 +04:00
|
|
|
size_t hunique_len;
|
|
|
|
#endif
|
2002-06-22 15:37:48 +04:00
|
|
|
struct pppoehdr *ph;
|
|
|
|
struct pppoetag *pt;
|
|
|
|
struct mbuf *n;
|
2003-09-04 01:36:31 +04:00
|
|
|
int noff, err, errortag;
|
2002-06-22 15:37:48 +04:00
|
|
|
struct ether_header *eh;
|
|
|
|
|
2006-02-01 02:50:15 +03:00
|
|
|
devname = "pppoe"; /* as long as we don't know which instance */
|
|
|
|
err_msg = NULL;
|
2003-09-04 01:36:31 +04:00
|
|
|
errortag = 0;
|
2002-06-22 15:37:48 +04:00
|
|
|
if (m->m_len < sizeof(*eh)) {
|
|
|
|
m = m_pullup(m, sizeof(*eh));
|
|
|
|
if (!m)
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
eh = mtod(m, struct ether_header *);
|
|
|
|
off += sizeof(*eh);
|
2001-04-29 13:50:36 +04:00
|
|
|
|
|
|
|
ac_cookie = NULL;
|
|
|
|
ac_cookie_len = 0;
|
2009-02-19 18:17:50 +03:00
|
|
|
relay_sid = NULL;
|
|
|
|
relay_sid_len = 0;
|
2003-06-18 12:12:51 +04:00
|
|
|
#ifdef PPPOE_SERVER
|
|
|
|
hunique = NULL;
|
|
|
|
hunique_len = 0;
|
|
|
|
#endif
|
2001-04-29 13:50:36 +04:00
|
|
|
session = 0;
|
2002-06-22 15:37:48 +04:00
|
|
|
if (m->m_pkthdr.len - off <= PPPOE_HEADERLEN) {
|
|
|
|
printf("pppoe: packet too short: %d\n", m->m_pkthdr.len);
|
|
|
|
goto done;
|
2001-04-29 13:50:36 +04:00
|
|
|
}
|
2002-06-22 15:37:48 +04:00
|
|
|
|
|
|
|
n = m_pulldown(m, off, sizeof(*ph), &noff);
|
|
|
|
if (!n) {
|
|
|
|
printf("pppoe: could not get PPPoE header\n");
|
|
|
|
m = NULL;
|
|
|
|
goto done;
|
2001-04-29 13:50:36 +04:00
|
|
|
}
|
2007-03-04 08:59:00 +03:00
|
|
|
ph = (struct pppoehdr *)(mtod(n, char *) + noff);
|
2002-06-22 15:37:48 +04:00
|
|
|
if (ph->vertype != PPPOE_VERTYPE) {
|
|
|
|
printf("pppoe: unknown version/type packet: 0x%x\n",
|
|
|
|
ph->vertype);
|
|
|
|
goto done;
|
2001-04-29 13:50:36 +04:00
|
|
|
}
|
2002-06-22 15:37:48 +04:00
|
|
|
session = ntohs(ph->session);
|
|
|
|
plen = ntohs(ph->plen);
|
|
|
|
off += sizeof(*ph);
|
|
|
|
|
|
|
|
if (plen + off > m->m_pkthdr.len) {
|
|
|
|
printf("pppoe: packet content does not fit: data available = %d, packet size = %u\n",
|
|
|
|
m->m_pkthdr.len - off, plen);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
m_adj(m, off + plen - m->m_pkthdr.len); /* ignore trailing garbage */
|
2001-04-29 13:50:36 +04:00
|
|
|
tag = 0;
|
|
|
|
len = 0;
|
|
|
|
sc = NULL;
|
2002-06-22 20:56:11 +04:00
|
|
|
while (off + sizeof(*pt) <= m->m_pkthdr.len) {
|
2002-06-22 15:37:48 +04:00
|
|
|
n = m_pulldown(m, off, sizeof(*pt), &noff);
|
|
|
|
if (!n) {
|
2006-02-01 02:50:15 +03:00
|
|
|
printf("%s: parse error\n", devname);
|
2002-06-22 15:37:48 +04:00
|
|
|
m = NULL;
|
|
|
|
goto done;
|
|
|
|
}
|
2007-03-04 08:59:00 +03:00
|
|
|
pt = (struct pppoetag *)(mtod(n, char *) + noff);
|
2002-06-22 15:37:48 +04:00
|
|
|
tag = ntohs(pt->tag);
|
|
|
|
len = ntohs(pt->len);
|
2008-08-08 18:31:00 +04:00
|
|
|
if (off + len + sizeof(*pt) > m->m_pkthdr.len) {
|
2002-06-22 09:59:27 +04:00
|
|
|
printf("pppoe: tag 0x%x len 0x%x is too long\n",
|
|
|
|
tag, len);
|
2002-06-22 15:37:48 +04:00
|
|
|
goto done;
|
2001-04-29 13:50:36 +04:00
|
|
|
}
|
|
|
|
switch (tag) {
|
|
|
|
case PPPOE_TAG_EOL:
|
2002-06-22 15:37:48 +04:00
|
|
|
goto breakbreak;
|
2001-04-29 13:50:36 +04:00
|
|
|
case PPPOE_TAG_SNAME:
|
|
|
|
break; /* ignored */
|
|
|
|
case PPPOE_TAG_ACNAME:
|
2007-09-09 13:58:55 +04:00
|
|
|
error = NULL;
|
|
|
|
if (sc != NULL && len > 0) {
|
|
|
|
error = malloc(len+1, M_TEMP, M_NOWAIT);
|
|
|
|
if (error) {
|
|
|
|
n = m_pulldown(m, off + sizeof(*pt),
|
|
|
|
len, &noff);
|
|
|
|
if (n) {
|
2016-04-24 19:59:15 +03:00
|
|
|
strlcpy(error,
|
2007-09-09 13:58:55 +04:00
|
|
|
mtod(n, char*) + noff,
|
|
|
|
len);
|
|
|
|
}
|
|
|
|
printf("%s: connected to %s\n",
|
|
|
|
devname, error);
|
|
|
|
free(error, M_TEMP);
|
|
|
|
}
|
|
|
|
}
|
2001-04-29 13:50:36 +04:00
|
|
|
break; /* ignored */
|
2016-06-10 16:31:43 +03:00
|
|
|
case PPPOE_TAG_HUNIQUE: {
|
|
|
|
struct ifnet *rcvif;
|
|
|
|
int s;
|
2002-06-22 15:37:48 +04:00
|
|
|
if (sc != NULL)
|
|
|
|
break;
|
|
|
|
n = m_pulldown(m, off + sizeof(*pt), len, &noff);
|
|
|
|
if (!n) {
|
|
|
|
m = NULL;
|
2003-09-04 01:36:31 +04:00
|
|
|
err_msg = "TAG HUNIQUE ERROR";
|
|
|
|
break;
|
2002-06-22 15:37:48 +04:00
|
|
|
}
|
2003-06-18 12:12:51 +04:00
|
|
|
#ifdef PPPOE_SERVER
|
2008-02-20 20:05:52 +03:00
|
|
|
hunique = mtod(n, uint8_t *) + noff;
|
2003-06-18 12:12:51 +04:00
|
|
|
hunique_len = len;
|
|
|
|
#endif
|
2016-06-10 16:31:43 +03:00
|
|
|
rcvif = m_get_rcvif(m, &s);
|
2007-03-04 08:59:00 +03:00
|
|
|
sc = pppoe_find_softc_by_hunique(mtod(n, char *) + noff,
|
2016-06-10 16:31:43 +03:00
|
|
|
len, rcvif);
|
|
|
|
m_put_rcvif(rcvif, &s);
|
2006-02-01 02:50:15 +03:00
|
|
|
if (sc != NULL)
|
|
|
|
devname = sc->sc_sppp.pp_if.if_xname;
|
2001-04-29 13:50:36 +04:00
|
|
|
break;
|
2016-06-10 16:31:43 +03:00
|
|
|
}
|
2001-04-29 13:50:36 +04:00
|
|
|
case PPPOE_TAG_ACCOOKIE:
|
|
|
|
if (ac_cookie == NULL) {
|
2002-06-22 15:37:48 +04:00
|
|
|
n = m_pulldown(m, off + sizeof(*pt), len,
|
|
|
|
&noff);
|
|
|
|
if (!n) {
|
|
|
|
err_msg = "TAG ACCOOKIE ERROR";
|
|
|
|
m = NULL;
|
|
|
|
break;
|
|
|
|
}
|
2007-03-04 08:59:00 +03:00
|
|
|
ac_cookie = mtod(n, char *) + noff;
|
2001-04-29 13:50:36 +04:00
|
|
|
ac_cookie_len = len;
|
|
|
|
}
|
|
|
|
break;
|
2009-02-19 18:17:50 +03:00
|
|
|
case PPPOE_TAG_RELAYSID:
|
|
|
|
if (relay_sid == NULL) {
|
|
|
|
n = m_pulldown(m, off + sizeof(*pt), len,
|
|
|
|
&noff);
|
|
|
|
if (!n) {
|
|
|
|
err_msg = "TAG RELAYSID ERROR";
|
|
|
|
m = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
relay_sid = mtod(n, char *) + noff;
|
|
|
|
relay_sid_len = len;
|
|
|
|
}
|
|
|
|
break;
|
2001-04-29 13:50:36 +04:00
|
|
|
case PPPOE_TAG_SNAME_ERR:
|
|
|
|
err_msg = "SERVICE NAME ERROR";
|
2003-09-04 01:36:31 +04:00
|
|
|
errortag = 1;
|
2001-04-29 13:50:36 +04:00
|
|
|
break;
|
|
|
|
case PPPOE_TAG_ACSYS_ERR:
|
|
|
|
err_msg = "AC SYSTEM ERROR";
|
2003-09-04 01:36:31 +04:00
|
|
|
errortag = 1;
|
2001-04-29 13:50:36 +04:00
|
|
|
break;
|
|
|
|
case PPPOE_TAG_GENERIC_ERR:
|
|
|
|
err_msg = "GENERIC ERROR";
|
2003-09-04 01:36:31 +04:00
|
|
|
errortag = 1;
|
2001-04-29 13:50:36 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (err_msg) {
|
2006-02-01 02:50:15 +03:00
|
|
|
error = NULL;
|
2003-09-04 01:36:31 +04:00
|
|
|
if (errortag && len) {
|
2006-02-01 02:50:15 +03:00
|
|
|
error = malloc(len+1, M_TEMP, M_NOWAIT);
|
2003-09-04 01:36:31 +04:00
|
|
|
n = m_pulldown(m, off + sizeof(*pt), len,
|
|
|
|
&noff);
|
2006-02-01 02:50:15 +03:00
|
|
|
if (n && error) {
|
2016-04-24 19:59:15 +03:00
|
|
|
strlcpy(error,
|
2007-03-04 08:59:00 +03:00
|
|
|
mtod(n, char *) + noff, len);
|
2006-02-01 02:50:15 +03:00
|
|
|
}
|
2003-09-04 01:36:31 +04:00
|
|
|
}
|
2006-02-01 02:50:15 +03:00
|
|
|
if (error) {
|
|
|
|
printf("%s: %s: %s\n", devname,
|
|
|
|
err_msg, error);
|
|
|
|
free(error, M_TEMP);
|
|
|
|
} else
|
|
|
|
printf("%s: %s\n", devname, err_msg);
|
2008-08-08 18:31:00 +04:00
|
|
|
if (errortag || m == NULL)
|
2003-09-04 01:36:31 +04:00
|
|
|
goto done;
|
2001-04-29 13:50:36 +04:00
|
|
|
}
|
2002-06-22 15:37:48 +04:00
|
|
|
off += sizeof(*pt) + len;
|
2001-04-29 13:50:36 +04:00
|
|
|
}
|
2002-06-22 15:37:48 +04:00
|
|
|
breakbreak:;
|
|
|
|
switch (ph->code) {
|
2001-04-29 13:50:36 +04:00
|
|
|
case PPPOE_CODE_PADI:
|
2003-06-18 12:12:51 +04:00
|
|
|
#ifdef PPPOE_SERVER
|
|
|
|
/*
|
|
|
|
* got service name, concentrator name, and/or host unique.
|
|
|
|
* ignore if we have no interfaces with IFF_PASSIVE|IFF_UP.
|
|
|
|
*/
|
|
|
|
if (LIST_EMPTY(&pppoe_softc_list))
|
|
|
|
goto done;
|
|
|
|
LIST_FOREACH(sc, &pppoe_softc_list, sc_list) {
|
|
|
|
if (!(sc->sc_sppp.pp_if.if_flags & IFF_UP))
|
|
|
|
continue;
|
|
|
|
if (!(sc->sc_sppp.pp_if.if_flags & IFF_PASSIVE))
|
|
|
|
continue;
|
|
|
|
if (sc->sc_state == PPPOE_STATE_INITIAL)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (sc == NULL) {
|
|
|
|
/* printf("pppoe: free passive interface is not found\n");*/
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
if (hunique) {
|
|
|
|
if (sc->sc_hunique)
|
|
|
|
free(sc->sc_hunique, M_DEVBUF);
|
|
|
|
sc->sc_hunique = malloc(hunique_len, M_DEVBUF,
|
|
|
|
M_DONTWAIT);
|
|
|
|
if (sc->sc_hunique == NULL)
|
|
|
|
goto done;
|
|
|
|
sc->sc_hunique_len = hunique_len;
|
|
|
|
memcpy(sc->sc_hunique, hunique, hunique_len);
|
|
|
|
}
|
2003-06-27 20:24:32 +04:00
|
|
|
memcpy(&sc->sc_dest, eh->ether_shost, sizeof sc->sc_dest);
|
2003-06-18 12:12:51 +04:00
|
|
|
sc->sc_state = PPPOE_STATE_PADO_SENT;
|
|
|
|
pppoe_send_pado(sc);
|
|
|
|
break;
|
|
|
|
#endif /* PPPOE_SERVER */
|
2001-04-29 13:50:36 +04:00
|
|
|
case PPPOE_CODE_PADR:
|
2003-06-18 12:12:51 +04:00
|
|
|
#ifdef PPPOE_SERVER
|
|
|
|
/*
|
|
|
|
* get sc from ac_cookie if IFF_PASSIVE
|
|
|
|
*/
|
|
|
|
if (ac_cookie == NULL) {
|
|
|
|
/* be quiet if there is not a single pppoe instance */
|
|
|
|
printf("pppoe: received PADR but not includes ac_cookie\n");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
sc = pppoe_find_softc_by_hunique(ac_cookie,
|
|
|
|
ac_cookie_len,
|
2016-06-10 16:31:43 +03:00
|
|
|
m_get_rcvif_NOMPSAFE(m));
|
2003-06-18 12:12:51 +04:00
|
|
|
if (sc == NULL) {
|
|
|
|
/* be quiet if there is not a single pppoe instance */
|
|
|
|
if (!LIST_EMPTY(&pppoe_softc_list))
|
|
|
|
printf("pppoe: received PADR but could not find request for it\n");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
if (sc->sc_state != PPPOE_STATE_PADO_SENT) {
|
|
|
|
printf("%s: received unexpected PADR\n",
|
|
|
|
sc->sc_sppp.pp_if.if_xname);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
if (hunique) {
|
|
|
|
if (sc->sc_hunique)
|
|
|
|
free(sc->sc_hunique, M_DEVBUF);
|
|
|
|
sc->sc_hunique = malloc(hunique_len, M_DEVBUF,
|
|
|
|
M_DONTWAIT);
|
|
|
|
if (sc->sc_hunique == NULL)
|
|
|
|
goto done;
|
|
|
|
sc->sc_hunique_len = hunique_len;
|
|
|
|
memcpy(sc->sc_hunique, hunique, hunique_len);
|
|
|
|
}
|
|
|
|
pppoe_send_pads(sc);
|
|
|
|
sc->sc_state = PPPOE_STATE_SESSION;
|
|
|
|
sc->sc_sppp.pp_up(&sc->sc_sppp);
|
|
|
|
break;
|
|
|
|
#else
|
2001-04-29 13:50:36 +04:00
|
|
|
/* ignore, we are no access concentrator */
|
2002-06-22 15:37:48 +04:00
|
|
|
goto done;
|
2003-06-18 12:12:51 +04:00
|
|
|
#endif /* PPPOE_SERVER */
|
2001-04-29 13:50:36 +04:00
|
|
|
case PPPOE_CODE_PADO:
|
|
|
|
if (sc == NULL) {
|
2002-08-25 23:21:47 +04:00
|
|
|
/* be quiet if there is not a single pppoe instance */
|
2002-03-04 18:15:05 +03:00
|
|
|
if (!LIST_EMPTY(&pppoe_softc_list))
|
|
|
|
printf("pppoe: received PADO but could not find request for it\n");
|
2002-06-22 15:37:48 +04:00
|
|
|
goto done;
|
2001-04-29 13:50:36 +04:00
|
|
|
}
|
|
|
|
if (sc->sc_state != PPPOE_STATE_PADI_SENT) {
|
2002-06-22 09:59:27 +04:00
|
|
|
printf("%s: received unexpected PADO\n",
|
|
|
|
sc->sc_sppp.pp_if.if_xname);
|
2002-06-22 15:37:48 +04:00
|
|
|
goto done;
|
2001-04-29 13:50:36 +04:00
|
|
|
}
|
|
|
|
if (ac_cookie) {
|
2002-06-22 21:41:23 +04:00
|
|
|
if (sc->sc_ac_cookie)
|
|
|
|
free(sc->sc_ac_cookie, M_DEVBUF);
|
2002-06-22 15:37:48 +04:00
|
|
|
sc->sc_ac_cookie = malloc(ac_cookie_len, M_DEVBUF,
|
|
|
|
M_DONTWAIT);
|
2008-08-19 00:43:50 +04:00
|
|
|
if (sc->sc_ac_cookie == NULL) {
|
|
|
|
printf("%s: FATAL: could not allocate memory "
|
|
|
|
"for AC cookie\n",
|
|
|
|
sc->sc_sppp.pp_if.if_xname);
|
2002-06-22 15:37:48 +04:00
|
|
|
goto done;
|
2008-08-19 00:43:50 +04:00
|
|
|
}
|
2001-04-29 13:50:36 +04:00
|
|
|
sc->sc_ac_cookie_len = ac_cookie_len;
|
|
|
|
memcpy(sc->sc_ac_cookie, ac_cookie, ac_cookie_len);
|
|
|
|
}
|
2009-02-19 18:17:50 +03:00
|
|
|
if (relay_sid) {
|
|
|
|
if (sc->sc_relay_sid)
|
|
|
|
free(sc->sc_relay_sid, M_DEVBUF);
|
|
|
|
sc->sc_relay_sid = malloc(relay_sid_len, M_DEVBUF,
|
|
|
|
M_DONTWAIT);
|
|
|
|
if (sc->sc_relay_sid == NULL) {
|
|
|
|
printf("%s: FATAL: could not allocate memory "
|
|
|
|
"for relay SID\n",
|
|
|
|
sc->sc_sppp.pp_if.if_xname);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
sc->sc_relay_sid_len = relay_sid_len;
|
|
|
|
memcpy(sc->sc_relay_sid, relay_sid, relay_sid_len);
|
|
|
|
}
|
2001-04-29 13:50:36 +04:00
|
|
|
memcpy(&sc->sc_dest, eh->ether_shost, sizeof sc->sc_dest);
|
|
|
|
callout_stop(&sc->sc_timeout);
|
|
|
|
sc->sc_padr_retried = 0;
|
|
|
|
sc->sc_state = PPPOE_STATE_PADR_SENT;
|
2003-08-23 20:42:41 +04:00
|
|
|
if ((err = pppoe_send_padr(sc)) != 0) {
|
|
|
|
if (sc->sc_sppp.pp_if.if_flags & IFF_DEBUG)
|
|
|
|
printf("%s: failed to send PADR, "
|
|
|
|
"error=%d\n", sc->sc_sppp.pp_if.if_xname,
|
|
|
|
err);
|
|
|
|
}
|
|
|
|
callout_reset(&sc->sc_timeout,
|
|
|
|
PPPOE_DISC_TIMEOUT * (1 + sc->sc_padr_retried),
|
|
|
|
pppoe_timeout, sc);
|
2001-04-29 13:50:36 +04:00
|
|
|
break;
|
|
|
|
case PPPOE_CODE_PADS:
|
|
|
|
if (sc == NULL)
|
2002-06-22 15:37:48 +04:00
|
|
|
goto done;
|
2001-04-29 13:50:36 +04:00
|
|
|
sc->sc_session = session;
|
|
|
|
callout_stop(&sc->sc_timeout);
|
2002-02-01 16:50:00 +03:00
|
|
|
if (sc->sc_sppp.pp_if.if_flags & IFF_DEBUG)
|
2002-06-22 09:59:27 +04:00
|
|
|
printf("%s: session 0x%x connected\n",
|
|
|
|
sc->sc_sppp.pp_if.if_xname, session);
|
2001-04-29 13:50:36 +04:00
|
|
|
sc->sc_state = PPPOE_STATE_SESSION;
|
|
|
|
sc->sc_sppp.pp_up(&sc->sc_sppp); /* notify upper layers */
|
|
|
|
break;
|
2016-06-10 16:31:43 +03:00
|
|
|
case PPPOE_CODE_PADT: {
|
|
|
|
struct ifnet *rcvif;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
rcvif = m_get_rcvif(m, &s);
|
|
|
|
sc = pppoe_find_softc_by_session(session, rcvif);
|
|
|
|
m_put_rcvif(rcvif, &s);
|
2001-04-29 13:50:36 +04:00
|
|
|
if (sc == NULL)
|
2002-06-22 15:37:48 +04:00
|
|
|
goto done;
|
2004-12-08 10:43:29 +03:00
|
|
|
pppoe_clear_softc(sc, "received PADT");
|
2002-06-22 09:33:42 +04:00
|
|
|
break;
|
2016-06-10 16:31:43 +03:00
|
|
|
}
|
2002-06-22 09:33:42 +04:00
|
|
|
default:
|
|
|
|
printf("%s: unknown code (0x%04x) session = 0x%04x\n",
|
|
|
|
sc? sc->sc_sppp.pp_if.if_xname : "pppoe",
|
2002-06-22 15:37:48 +04:00
|
|
|
ph->code, session);
|
2002-06-22 09:33:42 +04:00
|
|
|
break;
|
|
|
|
}
|
2002-06-22 15:37:48 +04:00
|
|
|
|
|
|
|
done:
|
2006-04-15 06:22:44 +04:00
|
|
|
if (m)
|
|
|
|
m_freem(m);
|
2002-06-22 15:37:48 +04:00
|
|
|
return;
|
2001-04-29 13:50:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pppoe_disc_input(struct mbuf *m)
|
|
|
|
{
|
2002-06-22 09:33:42 +04:00
|
|
|
|
|
|
|
/* avoid error messages if there is not a single pppoe instance */
|
|
|
|
if (!LIST_EMPTY(&pppoe_softc_list)) {
|
|
|
|
KASSERT(m->m_flags & M_PKTHDR);
|
2002-06-22 15:37:48 +04:00
|
|
|
pppoe_dispatch_disc_pkt(m, 0);
|
|
|
|
} else
|
|
|
|
m_freem(m);
|
2001-04-29 13:50:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pppoe_data_input(struct mbuf *m)
|
|
|
|
{
|
2008-02-20 20:05:52 +03:00
|
|
|
uint16_t session, plen;
|
2002-06-22 09:33:42 +04:00
|
|
|
struct pppoe_softc *sc;
|
2002-06-22 15:37:48 +04:00
|
|
|
struct pppoehdr *ph;
|
2016-06-10 16:31:43 +03:00
|
|
|
struct ifnet *rcvif;
|
|
|
|
struct psref psref;
|
2008-02-20 20:05:52 +03:00
|
|
|
uint8_t shost[ETHER_ADDR_LEN];
|
2001-04-29 13:50:36 +04:00
|
|
|
|
2002-06-22 09:33:42 +04:00
|
|
|
KASSERT(m->m_flags & M_PKTHDR);
|
2001-04-29 13:50:36 +04:00
|
|
|
|
2016-08-11 18:16:07 +03:00
|
|
|
if (pppoe_term_unknown)
|
|
|
|
memcpy(shost, mtod(m, struct ether_header*)->ether_shost,
|
|
|
|
ETHER_ADDR_LEN);
|
2002-06-22 09:33:42 +04:00
|
|
|
m_adj(m, sizeof(struct ether_header));
|
|
|
|
if (m->m_pkthdr.len <= PPPOE_HEADERLEN) {
|
2002-06-22 15:37:48 +04:00
|
|
|
printf("pppoe (data): dropping too short packet: %d bytes\n",
|
|
|
|
m->m_pkthdr.len);
|
2002-06-22 09:33:42 +04:00
|
|
|
goto drop;
|
|
|
|
}
|
2001-04-29 13:50:36 +04:00
|
|
|
|
2002-06-22 15:46:16 +04:00
|
|
|
if (m->m_len < sizeof(*ph)) {
|
|
|
|
m = m_pullup(m, sizeof(*ph));
|
|
|
|
if (!m) {
|
|
|
|
printf("pppoe: could not get PPPoE header\n");
|
|
|
|
return;
|
|
|
|
}
|
2002-06-22 15:37:48 +04:00
|
|
|
}
|
|
|
|
ph = mtod(m, struct pppoehdr *);
|
2001-04-29 13:50:36 +04:00
|
|
|
|
2002-06-22 15:37:48 +04:00
|
|
|
if (ph->vertype != PPPOE_VERTYPE) {
|
|
|
|
printf("pppoe (data): unknown version/type packet: 0x%x\n",
|
|
|
|
ph->vertype);
|
2002-06-22 09:33:42 +04:00
|
|
|
goto drop;
|
|
|
|
}
|
2002-06-22 15:37:48 +04:00
|
|
|
if (ph->code != 0)
|
2002-06-22 09:33:42 +04:00
|
|
|
goto drop;
|
2001-04-29 13:50:36 +04:00
|
|
|
|
2002-06-22 15:37:48 +04:00
|
|
|
session = ntohs(ph->session);
|
2016-06-10 16:31:43 +03:00
|
|
|
rcvif = m_get_rcvif_psref(m, &psref);
|
2016-06-28 05:02:56 +03:00
|
|
|
if (__predict_false(rcvif == NULL))
|
|
|
|
goto drop;
|
2016-06-10 16:31:43 +03:00
|
|
|
sc = pppoe_find_softc_by_session(session, rcvif);
|
2002-09-01 21:21:40 +04:00
|
|
|
if (sc == NULL) {
|
2016-08-07 04:59:43 +03:00
|
|
|
if (pppoe_term_unknown) {
|
2016-08-11 18:16:07 +03:00
|
|
|
printf("pppoe: input for unknown session %#x, "
|
2016-08-07 04:59:43 +03:00
|
|
|
"sending PADT\n", session);
|
|
|
|
pppoe_send_padt(rcvif, session, shost);
|
|
|
|
}
|
2016-06-10 16:31:43 +03:00
|
|
|
m_put_rcvif_psref(rcvif, &psref);
|
2002-06-22 09:33:42 +04:00
|
|
|
goto drop;
|
2002-09-01 21:21:40 +04:00
|
|
|
}
|
2016-06-10 16:31:43 +03:00
|
|
|
m_put_rcvif_psref(rcvif, &psref);
|
2001-04-29 13:50:36 +04:00
|
|
|
|
2002-06-22 15:37:48 +04:00
|
|
|
plen = ntohs(ph->plen);
|
2001-04-29 13:50:36 +04:00
|
|
|
|
2010-04-05 11:19:28 +04:00
|
|
|
bpf_mtap(&sc->sc_sppp.pp_if, m);
|
2001-04-29 13:50:36 +04:00
|
|
|
|
2002-06-22 09:33:42 +04:00
|
|
|
m_adj(m, PPPOE_HEADERLEN);
|
2001-04-29 13:50:36 +04:00
|
|
|
|
|
|
|
#ifdef PPPOE_DEBUG
|
2002-06-22 09:33:42 +04:00
|
|
|
{
|
|
|
|
struct mbuf *p;
|
|
|
|
|
|
|
|
printf("%s: pkthdr.len=%d, pppoe.len=%d",
|
|
|
|
sc->sc_sppp.pp_if.if_xname,
|
|
|
|
m->m_pkthdr.len, plen);
|
|
|
|
p = m;
|
|
|
|
while (p) {
|
|
|
|
printf(" l=%d", p->m_len);
|
|
|
|
p = p->m_next;
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
2001-04-29 13:50:36 +04:00
|
|
|
#endif
|
2002-06-22 09:52:00 +04:00
|
|
|
|
2002-06-22 09:33:42 +04:00
|
|
|
if (m->m_pkthdr.len < plen)
|
|
|
|
goto drop;
|
2001-04-29 13:50:36 +04:00
|
|
|
|
2002-06-22 09:33:42 +04:00
|
|
|
/* fix incoming interface pointer (not the raw ethernet interface anymore) */
|
2016-06-10 16:27:10 +03:00
|
|
|
m_set_rcvif(m, &sc->sc_sppp.pp_if);
|
2001-04-29 13:50:36 +04:00
|
|
|
|
2002-06-22 09:33:42 +04:00
|
|
|
/* pass packet up and account for it */
|
|
|
|
sc->sc_sppp.pp_if.if_ipackets++;
|
|
|
|
sppp_input(&sc->sc_sppp.pp_if, m);
|
|
|
|
return;
|
2001-04-29 13:50:36 +04:00
|
|
|
|
|
|
|
drop:
|
2002-06-22 15:37:48 +04:00
|
|
|
m_freem(m);
|
2001-04-29 13:50:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pppoe_output(struct pppoe_softc *sc, struct mbuf *m)
|
|
|
|
{
|
2002-06-22 09:33:42 +04:00
|
|
|
struct sockaddr dst;
|
|
|
|
struct ether_header *eh;
|
2008-02-20 20:05:52 +03:00
|
|
|
uint16_t etype;
|
2001-04-29 13:50:36 +04:00
|
|
|
|
2004-03-30 10:00:13 +04:00
|
|
|
if (sc->sc_eth_if == NULL) {
|
|
|
|
m_freem(m);
|
2002-06-22 09:33:42 +04:00
|
|
|
return EIO;
|
2004-03-30 10:00:13 +04:00
|
|
|
}
|
2001-04-29 13:50:36 +04:00
|
|
|
|
2002-06-22 09:33:42 +04:00
|
|
|
memset(&dst, 0, sizeof dst);
|
|
|
|
dst.sa_family = AF_UNSPEC;
|
|
|
|
eh = (struct ether_header*)&dst.sa_data;
|
2002-06-22 09:59:27 +04:00
|
|
|
etype = sc->sc_state == PPPOE_STATE_SESSION ? ETHERTYPE_PPPOE : ETHERTYPE_PPPOEDISC;
|
2002-06-22 09:33:42 +04:00
|
|
|
eh->ether_type = htons(etype);
|
|
|
|
memcpy(&eh->ether_dhost, &sc->sc_dest, sizeof sc->sc_dest);
|
2001-04-29 13:50:36 +04:00
|
|
|
|
|
|
|
#ifdef PPPOE_DEBUG
|
2002-06-22 09:33:42 +04:00
|
|
|
printf("%s (%x) state=%d, session=0x%x output -> %s, len=%d\n",
|
|
|
|
sc->sc_sppp.pp_if.if_xname, etype,
|
|
|
|
sc->sc_state, sc->sc_session,
|
2001-04-29 13:50:36 +04:00
|
|
|
ether_sprintf((const unsigned char *)&sc->sc_dest), m->m_pkthdr.len);
|
|
|
|
#endif
|
|
|
|
|
2002-02-24 20:11:53 +03:00
|
|
|
m->m_flags &= ~(M_BCAST|M_MCAST);
|
2001-12-16 14:40:52 +03:00
|
|
|
sc->sc_sppp.pp_if.if_opackets++;
|
2016-06-20 09:46:37 +03:00
|
|
|
return if_output_lock(sc->sc_eth_if, sc->sc_eth_if, m, &dst, NULL);
|
2001-04-29 13:50:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2007-03-04 08:59:00 +03:00
|
|
|
pppoe_ioctl(struct ifnet *ifp, unsigned long cmd, void *data)
|
2001-04-29 13:50:36 +04:00
|
|
|
{
|
2006-07-24 02:06:03 +04:00
|
|
|
struct lwp *l = curlwp; /* XXX */
|
2001-04-29 13:50:36 +04:00
|
|
|
struct pppoe_softc *sc = (struct pppoe_softc*)ifp;
|
2008-02-07 04:21:52 +03:00
|
|
|
struct ifreq *ifr = data;
|
2001-04-29 13:50:36 +04:00
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case PPPOESETPARMS:
|
|
|
|
{
|
|
|
|
struct pppoediscparms *parms = (struct pppoediscparms*)data;
|
2006-10-26 00:28:45 +04:00
|
|
|
if (kauth_authorize_network(l->l_cred, KAUTH_NETWORK_INTERFACE,
|
|
|
|
KAUTH_REQ_NETWORK_INTERFACE_SETPRIV, ifp, (void *)cmd,
|
|
|
|
NULL) != 0)
|
|
|
|
return (EPERM);
|
2001-04-29 13:50:36 +04:00
|
|
|
if (parms->eth_ifname[0] != 0) {
|
2006-04-28 00:04:26 +04:00
|
|
|
struct ifnet *eth_if;
|
|
|
|
|
|
|
|
eth_if = ifunit(parms->eth_ifname);
|
|
|
|
if (eth_if == NULL || eth_if->if_dlt != DLT_EN10MB) {
|
2006-04-27 17:19:04 +04:00
|
|
|
sc->sc_eth_if = NULL;
|
2001-04-29 13:50:36 +04:00
|
|
|
return ENXIO;
|
2006-04-27 17:19:04 +04:00
|
|
|
}
|
2006-04-28 00:04:26 +04:00
|
|
|
|
2011-09-05 16:19:09 +04:00
|
|
|
if (sc->sc_sppp.pp_if.if_mtu !=
|
2006-04-28 00:04:26 +04:00
|
|
|
eth_if->if_mtu - PPPOE_OVERHEAD) {
|
|
|
|
sc->sc_sppp.pp_if.if_mtu = eth_if->if_mtu -
|
|
|
|
PPPOE_OVERHEAD;
|
|
|
|
}
|
|
|
|
sc->sc_eth_if = eth_if;
|
2001-04-29 13:50:36 +04:00
|
|
|
}
|
2006-04-27 17:19:04 +04:00
|
|
|
if (parms->ac_name != NULL) {
|
2001-04-29 13:50:36 +04:00
|
|
|
size_t s;
|
2005-05-30 01:22:52 +04:00
|
|
|
char *b = malloc(parms->ac_name_len + 1, M_DEVBUF,
|
2003-09-17 00:59:04 +04:00
|
|
|
M_WAITOK);
|
2005-05-30 01:22:52 +04:00
|
|
|
if (b == NULL)
|
2003-09-17 00:59:04 +04:00
|
|
|
return ENOMEM;
|
2005-05-30 01:22:52 +04:00
|
|
|
error = copyinstr(parms->ac_name, b,
|
2003-09-17 00:59:04 +04:00
|
|
|
parms->ac_name_len+1, &s);
|
|
|
|
if (error != 0) {
|
2005-05-30 01:22:52 +04:00
|
|
|
free(b, M_DEVBUF);
|
2003-09-17 00:59:04 +04:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
if (s != parms->ac_name_len+1) {
|
2005-05-30 01:22:52 +04:00
|
|
|
free(b, M_DEVBUF);
|
2003-09-17 00:59:04 +04:00
|
|
|
return EINVAL;
|
|
|
|
}
|
2001-04-29 13:50:36 +04:00
|
|
|
if (sc->sc_concentrator_name)
|
|
|
|
free(sc->sc_concentrator_name, M_DEVBUF);
|
2005-05-30 01:22:52 +04:00
|
|
|
sc->sc_concentrator_name = b;
|
2001-04-29 13:50:36 +04:00
|
|
|
}
|
2006-04-27 17:19:04 +04:00
|
|
|
if (parms->service_name != NULL) {
|
2001-04-29 13:50:36 +04:00
|
|
|
size_t s;
|
2005-05-30 01:22:52 +04:00
|
|
|
char *b = malloc(parms->service_name_len + 1, M_DEVBUF,
|
2003-09-17 00:59:04 +04:00
|
|
|
M_WAITOK);
|
2005-05-30 01:22:52 +04:00
|
|
|
if (b == NULL)
|
2003-09-17 00:59:04 +04:00
|
|
|
return ENOMEM;
|
2005-05-30 01:22:52 +04:00
|
|
|
error = copyinstr(parms->service_name, b,
|
2003-09-17 00:59:04 +04:00
|
|
|
parms->service_name_len+1, &s);
|
|
|
|
if (error != 0) {
|
2005-05-30 01:22:52 +04:00
|
|
|
free(b, M_DEVBUF);
|
2003-09-17 00:59:04 +04:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
if (s != parms->service_name_len+1) {
|
2005-05-30 01:22:52 +04:00
|
|
|
free(b, M_DEVBUF);
|
2003-09-17 00:59:04 +04:00
|
|
|
return EINVAL;
|
|
|
|
}
|
2001-04-29 13:50:36 +04:00
|
|
|
if (sc->sc_service_name)
|
|
|
|
free(sc->sc_service_name, M_DEVBUF);
|
2005-05-30 01:22:52 +04:00
|
|
|
sc->sc_service_name = b;
|
2001-04-29 13:50:36 +04:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PPPOEGETPARMS:
|
|
|
|
{
|
|
|
|
struct pppoediscparms *parms = (struct pppoediscparms*)data;
|
|
|
|
memset(parms, 0, sizeof *parms);
|
|
|
|
if (sc->sc_eth_if)
|
2016-04-24 19:59:15 +03:00
|
|
|
strlcpy(parms->ifname, sc->sc_eth_if->if_xname,
|
|
|
|
sizeof(parms->ifname));
|
2001-04-29 13:50:36 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
2002-01-04 15:21:24 +03:00
|
|
|
case PPPOEGETSESSION:
|
|
|
|
{
|
|
|
|
struct pppoeconnectionstate *state = (struct pppoeconnectionstate*)data;
|
|
|
|
state->state = sc->sc_state;
|
|
|
|
state->session_id = sc->sc_session;
|
|
|
|
state->padi_retry_no = sc->sc_padi_retried;
|
|
|
|
state->padr_retry_no = sc->sc_padr_retried;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
2001-12-16 14:40:52 +03:00
|
|
|
case SIOCSIFFLAGS:
|
|
|
|
/*
|
|
|
|
* Prevent running re-establishment timers overriding
|
|
|
|
* administrators choice.
|
|
|
|
*/
|
2001-12-17 02:53:31 +03:00
|
|
|
if ((ifr->ifr_flags & IFF_UP) == 0
|
|
|
|
&& sc->sc_state >= PPPOE_STATE_PADI_SENT
|
|
|
|
&& sc->sc_state < PPPOE_STATE_SESSION) {
|
2001-12-16 14:40:52 +03:00
|
|
|
callout_stop(&sc->sc_timeout);
|
2001-12-17 02:53:31 +03:00
|
|
|
sc->sc_state = PPPOE_STATE_INITIAL;
|
2001-12-16 14:40:52 +03:00
|
|
|
sc->sc_padi_retried = 0;
|
|
|
|
sc->sc_padr_retried = 0;
|
2002-06-22 09:59:27 +04:00
|
|
|
memcpy(&sc->sc_dest, etherbroadcastaddr,
|
|
|
|
sizeof(sc->sc_dest));
|
2001-12-16 14:40:52 +03:00
|
|
|
}
|
2002-02-01 16:40:16 +03:00
|
|
|
return sppp_ioctl(ifp, cmd, data);
|
|
|
|
case SIOCSIFMTU:
|
2006-04-28 00:04:26 +04:00
|
|
|
if (ifr->ifr_mtu > (sc->sc_eth_if == NULL ?
|
|
|
|
PPPOE_MAXMTU : (sc->sc_eth_if->if_mtu - PPPOE_OVERHEAD))) {
|
2002-02-01 16:40:16 +03:00
|
|
|
return EINVAL;
|
2006-04-28 00:04:26 +04:00
|
|
|
}
|
2008-02-07 04:21:52 +03:00
|
|
|
/*FALLTHROUGH*/
|
2001-04-29 13:50:36 +04:00
|
|
|
default:
|
|
|
|
return sppp_ioctl(ifp, cmd, data);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate a mbuf/cluster with space to store the given data length
|
|
|
|
* of payload, leaving space for prepending an ethernet header
|
2005-02-27 01:45:09 +03:00
|
|
|
* in front.
|
2001-04-29 13:50:36 +04:00
|
|
|
*/
|
|
|
|
static struct mbuf *
|
|
|
|
pppoe_get_mbuf(size_t len)
|
|
|
|
{
|
|
|
|
struct mbuf *m;
|
|
|
|
|
|
|
|
MGETHDR(m, M_DONTWAIT, MT_DATA);
|
|
|
|
if (m == NULL)
|
|
|
|
return NULL;
|
2002-06-22 09:52:00 +04:00
|
|
|
if (len + sizeof(struct ether_header) > MHLEN) {
|
2001-04-29 13:50:36 +04:00
|
|
|
MCLGET(m, M_DONTWAIT);
|
|
|
|
if ((m->m_flags & M_EXT) == 0) {
|
2013-09-14 01:09:40 +04:00
|
|
|
m_free(m);
|
|
|
|
return NULL;
|
2001-04-29 13:50:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
m->m_data += sizeof(struct ether_header);
|
|
|
|
m->m_len = len;
|
|
|
|
m->m_pkthdr.len = len;
|
2016-06-10 16:27:10 +03:00
|
|
|
m_reset_rcvif(m);
|
2001-04-29 13:50:36 +04:00
|
|
|
|
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pppoe_send_padi(struct pppoe_softc *sc)
|
|
|
|
{
|
|
|
|
struct mbuf *m0;
|
2003-10-25 22:29:12 +04:00
|
|
|
int len, l1 = 0, l2 = 0; /* XXX: gcc */
|
2008-02-20 20:05:52 +03:00
|
|
|
uint8_t *p;
|
2001-04-29 13:50:36 +04:00
|
|
|
|
|
|
|
if (sc->sc_state >PPPOE_STATE_PADI_SENT)
|
|
|
|
panic("pppoe_send_padi in state %d", sc->sc_state);
|
|
|
|
|
|
|
|
/* calculate length of frame (excluding ethernet header + pppoe header) */
|
2002-06-22 09:52:00 +04:00
|
|
|
len = 2 + 2 + 2 + 2 + sizeof sc; /* service name tag is required, host unique is send too */
|
2001-04-29 13:50:36 +04:00
|
|
|
if (sc->sc_service_name != NULL) {
|
|
|
|
l1 = strlen(sc->sc_service_name);
|
|
|
|
len += l1;
|
|
|
|
}
|
|
|
|
if (sc->sc_concentrator_name != NULL) {
|
|
|
|
l2 = strlen(sc->sc_concentrator_name);
|
2002-06-22 09:52:00 +04:00
|
|
|
len += 2 + 2 + l2;
|
2001-04-29 13:50:36 +04:00
|
|
|
}
|
2011-09-05 16:19:09 +04:00
|
|
|
if (sc->sc_sppp.pp_if.if_mtu > PPPOE_MAXMTU) {
|
|
|
|
len += 2 + 2 + 2;
|
|
|
|
}
|
2001-04-29 13:50:36 +04:00
|
|
|
|
|
|
|
/* allocate a buffer */
|
2002-06-22 09:52:00 +04:00
|
|
|
m0 = pppoe_get_mbuf(len + PPPOE_HEADERLEN); /* header len + payload len */
|
|
|
|
if (!m0)
|
|
|
|
return ENOBUFS;
|
2001-04-29 13:50:36 +04:00
|
|
|
|
|
|
|
/* fill in pkt */
|
2008-02-20 20:05:52 +03:00
|
|
|
p = mtod(m0, uint8_t *);
|
2001-04-29 13:50:36 +04:00
|
|
|
PPPOE_ADD_HEADER(p, PPPOE_CODE_PADI, 0, len);
|
|
|
|
PPPOE_ADD_16(p, PPPOE_TAG_SNAME);
|
|
|
|
if (sc->sc_service_name != NULL) {
|
|
|
|
PPPOE_ADD_16(p, l1);
|
|
|
|
memcpy(p, sc->sc_service_name, l1);
|
|
|
|
p += l1;
|
|
|
|
} else {
|
|
|
|
PPPOE_ADD_16(p, 0);
|
|
|
|
}
|
|
|
|
if (sc->sc_concentrator_name != NULL) {
|
|
|
|
PPPOE_ADD_16(p, PPPOE_TAG_ACNAME);
|
|
|
|
PPPOE_ADD_16(p, l2);
|
|
|
|
memcpy(p, sc->sc_concentrator_name, l2);
|
|
|
|
p += l2;
|
|
|
|
}
|
|
|
|
PPPOE_ADD_16(p, PPPOE_TAG_HUNIQUE);
|
|
|
|
PPPOE_ADD_16(p, sizeof(sc));
|
|
|
|
memcpy(p, &sc, sizeof sc);
|
2011-09-05 16:19:09 +04:00
|
|
|
p += sizeof(sc);
|
|
|
|
|
|
|
|
if (sc->sc_sppp.pp_if.if_mtu > PPPOE_MAXMTU) {
|
|
|
|
PPPOE_ADD_16(p, PPPOE_TAG_MAX_PAYLOAD);
|
|
|
|
PPPOE_ADD_16(p, 2);
|
|
|
|
PPPOE_ADD_16(p, (uint16_t)sc->sc_sppp.pp_if.if_mtu);
|
|
|
|
}
|
2001-04-29 13:50:36 +04:00
|
|
|
|
|
|
|
#ifdef PPPOE_DEBUG
|
|
|
|
p += sizeof sc;
|
2008-02-20 20:05:52 +03:00
|
|
|
if (p - mtod(m0, uint8_t *) != len + PPPOE_HEADERLEN)
|
2001-04-29 13:50:36 +04:00
|
|
|
panic("pppoe_send_padi: garbled output len, should be %ld, is %ld",
|
2008-02-20 20:05:52 +03:00
|
|
|
(long)(len + PPPOE_HEADERLEN), (long)(p - mtod(m0, uint8_t *)));
|
2001-04-29 13:50:36 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* send pkt */
|
|
|
|
return pppoe_output(sc, m0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pppoe_timeout(void *arg)
|
|
|
|
{
|
2003-08-23 20:42:41 +04:00
|
|
|
int x, retry_wait, err;
|
2001-04-29 13:50:36 +04:00
|
|
|
struct pppoe_softc *sc = (struct pppoe_softc*)arg;
|
|
|
|
|
|
|
|
#ifdef PPPOE_DEBUG
|
|
|
|
printf("%s: timeout\n", sc->sc_sppp.pp_if.if_xname);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
switch (sc->sc_state) {
|
2008-08-19 01:43:49 +04:00
|
|
|
case PPPOE_STATE_INITIAL:
|
|
|
|
/* delayed connect from pppoe_tls() */
|
|
|
|
pppoe_connect(sc);
|
|
|
|
break;
|
2001-04-29 13:50:36 +04:00
|
|
|
case PPPOE_STATE_PADI_SENT:
|
2001-12-16 14:40:52 +03:00
|
|
|
/*
|
|
|
|
* We have two basic ways of retrying:
|
|
|
|
* - Quick retry mode: try a few times in short sequence
|
|
|
|
* - Slow retry mode: we already had a connection successfully
|
|
|
|
* established and will try infinitely (without user
|
|
|
|
* intervention)
|
|
|
|
* We only enter slow retry mode if IFF_LINK1 (aka autodial)
|
2002-09-01 22:06:59 +04:00
|
|
|
* is not set.
|
2001-12-16 14:40:52 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* initialize for quick retry mode */
|
2002-06-22 15:46:16 +04:00
|
|
|
retry_wait = PPPOE_DISC_TIMEOUT * (1 + sc->sc_padi_retried);
|
2001-12-16 14:40:52 +03:00
|
|
|
|
2001-04-29 13:50:36 +04:00
|
|
|
x = splnet();
|
|
|
|
sc->sc_padi_retried++;
|
|
|
|
if (sc->sc_padi_retried >= PPPOE_DISC_MAXPADI) {
|
2002-09-01 22:06:59 +04:00
|
|
|
if ((sc->sc_sppp.pp_if.if_flags & IFF_LINK1) == 0) {
|
2002-06-22 09:59:27 +04:00
|
|
|
/* slow retry mode */
|
|
|
|
retry_wait = PPPOE_SLOW_RETRY;
|
2001-12-16 14:40:52 +03:00
|
|
|
} else {
|
2002-06-22 09:59:27 +04:00
|
|
|
pppoe_abort_connect(sc);
|
|
|
|
splx(x);
|
|
|
|
return;
|
2001-12-16 14:40:52 +03:00
|
|
|
}
|
2001-04-29 13:50:36 +04:00
|
|
|
}
|
2003-08-23 20:42:41 +04:00
|
|
|
if ((err = pppoe_send_padi(sc)) != 0) {
|
|
|
|
sc->sc_padi_retried--;
|
|
|
|
if (sc->sc_sppp.pp_if.if_flags & IFF_DEBUG)
|
|
|
|
printf("%s: failed to transmit PADI, "
|
|
|
|
"error=%d\n",
|
|
|
|
sc->sc_sppp.pp_if.if_xname, err);
|
|
|
|
}
|
|
|
|
callout_reset(&sc->sc_timeout, retry_wait,
|
|
|
|
pppoe_timeout, sc);
|
2001-04-29 13:50:36 +04:00
|
|
|
splx(x);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PPPOE_STATE_PADR_SENT:
|
|
|
|
x = splnet();
|
|
|
|
sc->sc_padr_retried++;
|
|
|
|
if (sc->sc_padr_retried >= PPPOE_DISC_MAXPADR) {
|
2002-06-22 09:59:27 +04:00
|
|
|
memcpy(&sc->sc_dest, etherbroadcastaddr,
|
|
|
|
sizeof(sc->sc_dest));
|
2001-04-29 13:50:36 +04:00
|
|
|
sc->sc_state = PPPOE_STATE_PADI_SENT;
|
|
|
|
sc->sc_padr_retried = 0;
|
2003-08-23 20:42:41 +04:00
|
|
|
if ((err = pppoe_send_padi(sc)) != 0) {
|
|
|
|
if (sc->sc_sppp.pp_if.if_flags & IFF_DEBUG)
|
|
|
|
printf("%s: failed to send PADI"
|
|
|
|
", error=%d\n",
|
|
|
|
sc->sc_sppp.pp_if.if_xname,
|
|
|
|
err);
|
|
|
|
}
|
|
|
|
callout_reset(&sc->sc_timeout,
|
|
|
|
PPPOE_DISC_TIMEOUT * (1 + sc->sc_padi_retried),
|
|
|
|
pppoe_timeout, sc);
|
2001-04-29 13:50:36 +04:00
|
|
|
splx(x);
|
|
|
|
return;
|
|
|
|
}
|
2003-08-23 20:42:41 +04:00
|
|
|
if ((err = pppoe_send_padr(sc)) != 0) {
|
|
|
|
sc->sc_padr_retried--;
|
|
|
|
if (sc->sc_sppp.pp_if.if_flags & IFF_DEBUG)
|
|
|
|
printf("%s: failed to send PADR, "
|
|
|
|
"error=%d\n", sc->sc_sppp.pp_if.if_xname,
|
|
|
|
err);
|
|
|
|
}
|
|
|
|
callout_reset(&sc->sc_timeout,
|
|
|
|
PPPOE_DISC_TIMEOUT * (1 + sc->sc_padr_retried),
|
|
|
|
pppoe_timeout, sc);
|
2001-04-29 13:50:36 +04:00
|
|
|
splx(x);
|
|
|
|
break;
|
|
|
|
case PPPOE_STATE_CLOSING:
|
|
|
|
pppoe_disconnect(sc);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return; /* all done, work in peace */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Start a connection (i.e. initiate discovery phase) */
|
|
|
|
static int
|
|
|
|
pppoe_connect(struct pppoe_softc *sc)
|
|
|
|
{
|
2003-10-30 04:43:08 +03:00
|
|
|
int x, err;
|
2001-04-29 13:50:36 +04:00
|
|
|
|
|
|
|
if (sc->sc_state != PPPOE_STATE_INITIAL)
|
|
|
|
return EBUSY;
|
|
|
|
|
2003-06-18 12:12:51 +04:00
|
|
|
#ifdef PPPOE_SERVER
|
|
|
|
/* wait PADI if IFF_PASSIVE */
|
|
|
|
if ((sc->sc_sppp.pp_if.if_flags & IFF_PASSIVE))
|
|
|
|
return 0;
|
|
|
|
#endif
|
2001-04-29 13:50:36 +04:00
|
|
|
x = splnet();
|
2002-12-25 14:54:33 +03:00
|
|
|
/* save state, in case we fail to send PADI */
|
2001-04-29 13:50:36 +04:00
|
|
|
sc->sc_state = PPPOE_STATE_PADI_SENT;
|
|
|
|
sc->sc_padr_retried = 0;
|
|
|
|
err = pppoe_send_padi(sc);
|
2003-08-23 20:42:41 +04:00
|
|
|
if (err != 0 && sc->sc_sppp.pp_if.if_flags & IFF_DEBUG)
|
|
|
|
printf("%s: failed to send PADI, error=%d\n",
|
|
|
|
sc->sc_sppp.pp_if.if_xname, err);
|
|
|
|
callout_reset(&sc->sc_timeout, PPPOE_DISC_TIMEOUT, pppoe_timeout, sc);
|
2001-04-29 13:50:36 +04:00
|
|
|
splx(x);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* disconnect */
|
|
|
|
static int
|
|
|
|
pppoe_disconnect(struct pppoe_softc *sc)
|
|
|
|
{
|
|
|
|
int err, x;
|
|
|
|
|
|
|
|
x = splnet();
|
|
|
|
|
|
|
|
if (sc->sc_state < PPPOE_STATE_SESSION)
|
|
|
|
err = EBUSY;
|
|
|
|
else {
|
2002-02-01 16:50:00 +03:00
|
|
|
if (sc->sc_sppp.pp_if.if_flags & IFF_DEBUG)
|
2002-06-22 09:59:27 +04:00
|
|
|
printf("%s: disconnecting\n",
|
|
|
|
sc->sc_sppp.pp_if.if_xname);
|
2008-02-20 20:05:52 +03:00
|
|
|
err = pppoe_send_padt(sc->sc_eth_if, sc->sc_session, (const uint8_t *)&sc->sc_dest);
|
2001-04-29 13:50:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* cleanup softc */
|
|
|
|
sc->sc_state = PPPOE_STATE_INITIAL;
|
|
|
|
memcpy(&sc->sc_dest, etherbroadcastaddr, sizeof(sc->sc_dest));
|
|
|
|
if (sc->sc_ac_cookie) {
|
2002-06-22 21:41:23 +04:00
|
|
|
free(sc->sc_ac_cookie, M_DEVBUF);
|
2001-04-29 13:50:36 +04:00
|
|
|
sc->sc_ac_cookie = NULL;
|
|
|
|
}
|
|
|
|
sc->sc_ac_cookie_len = 0;
|
2009-02-19 18:17:50 +03:00
|
|
|
if (sc->sc_relay_sid) {
|
|
|
|
free(sc->sc_relay_sid, M_DEVBUF);
|
|
|
|
sc->sc_relay_sid = NULL;
|
|
|
|
}
|
|
|
|
sc->sc_relay_sid_len = 0;
|
2003-06-18 12:12:51 +04:00
|
|
|
#ifdef PPPOE_SERVER
|
|
|
|
if (sc->sc_hunique) {
|
|
|
|
free(sc->sc_hunique, M_DEVBUF);
|
|
|
|
sc->sc_hunique = NULL;
|
|
|
|
}
|
|
|
|
sc->sc_hunique_len = 0;
|
|
|
|
#endif
|
2001-04-29 13:50:36 +04:00
|
|
|
sc->sc_session = 0;
|
|
|
|
|
|
|
|
/* notify upper layer */
|
|
|
|
sc->sc_sppp.pp_down(&sc->sc_sppp);
|
|
|
|
|
|
|
|
splx(x);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Connection attempt aborted */
|
|
|
|
static void
|
|
|
|
pppoe_abort_connect(struct pppoe_softc *sc)
|
|
|
|
{
|
|
|
|
printf("%s: could not establish connection\n",
|
|
|
|
sc->sc_sppp.pp_if.if_xname);
|
2002-12-25 14:54:33 +03:00
|
|
|
sc->sc_state = PPPOE_STATE_CLOSING;
|
2001-04-29 13:50:36 +04:00
|
|
|
|
|
|
|
/* notify upper layer */
|
|
|
|
sc->sc_sppp.pp_down(&sc->sc_sppp);
|
2002-12-25 14:54:33 +03:00
|
|
|
|
|
|
|
/* clear connection state */
|
|
|
|
memcpy(&sc->sc_dest, etherbroadcastaddr, sizeof(sc->sc_dest));
|
|
|
|
sc->sc_state = PPPOE_STATE_INITIAL;
|
2001-04-29 13:50:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Send a PADR packet */
|
|
|
|
static int
|
|
|
|
pppoe_send_padr(struct pppoe_softc *sc)
|
|
|
|
{
|
|
|
|
struct mbuf *m0;
|
2008-02-20 20:05:52 +03:00
|
|
|
uint8_t *p;
|
2003-10-25 22:29:12 +04:00
|
|
|
size_t len, l1 = 0; /* XXX: gcc */
|
2001-04-29 13:50:36 +04:00
|
|
|
|
|
|
|
if (sc->sc_state != PPPOE_STATE_PADR_SENT)
|
|
|
|
return EIO;
|
|
|
|
|
2002-06-22 09:52:00 +04:00
|
|
|
len = 2 + 2 + 2 + 2 + sizeof(sc); /* service name, host unique */
|
2001-04-29 13:50:36 +04:00
|
|
|
if (sc->sc_service_name != NULL) { /* service name tag maybe empty */
|
|
|
|
l1 = strlen(sc->sc_service_name);
|
|
|
|
len += l1;
|
|
|
|
}
|
|
|
|
if (sc->sc_ac_cookie_len > 0)
|
2002-06-22 09:52:00 +04:00
|
|
|
len += 2 + 2 + sc->sc_ac_cookie_len; /* AC cookie */
|
2009-02-19 18:17:50 +03:00
|
|
|
if (sc->sc_relay_sid_len > 0)
|
|
|
|
len += 2 + 2 + sc->sc_relay_sid_len; /* Relay SID */
|
2011-09-05 16:19:09 +04:00
|
|
|
if (sc->sc_sppp.pp_if.if_mtu > PPPOE_MAXMTU) {
|
|
|
|
len += 2 + 2 + 2;
|
|
|
|
}
|
2002-06-22 09:52:00 +04:00
|
|
|
m0 = pppoe_get_mbuf(len + PPPOE_HEADERLEN);
|
|
|
|
if (!m0)
|
|
|
|
return ENOBUFS;
|
2008-02-20 20:05:52 +03:00
|
|
|
p = mtod(m0, uint8_t *);
|
2001-04-29 13:50:36 +04:00
|
|
|
PPPOE_ADD_HEADER(p, PPPOE_CODE_PADR, 0, len);
|
|
|
|
PPPOE_ADD_16(p, PPPOE_TAG_SNAME);
|
|
|
|
if (sc->sc_service_name != NULL) {
|
|
|
|
PPPOE_ADD_16(p, l1);
|
|
|
|
memcpy(p, sc->sc_service_name, l1);
|
|
|
|
p += l1;
|
|
|
|
} else {
|
|
|
|
PPPOE_ADD_16(p, 0);
|
|
|
|
}
|
|
|
|
if (sc->sc_ac_cookie_len > 0) {
|
|
|
|
PPPOE_ADD_16(p, PPPOE_TAG_ACCOOKIE);
|
|
|
|
PPPOE_ADD_16(p, sc->sc_ac_cookie_len);
|
|
|
|
memcpy(p, sc->sc_ac_cookie, sc->sc_ac_cookie_len);
|
|
|
|
p += sc->sc_ac_cookie_len;
|
|
|
|
}
|
2009-02-19 18:17:50 +03:00
|
|
|
if (sc->sc_relay_sid_len > 0) {
|
|
|
|
PPPOE_ADD_16(p, PPPOE_TAG_RELAYSID);
|
|
|
|
PPPOE_ADD_16(p, sc->sc_relay_sid_len);
|
|
|
|
memcpy(p, sc->sc_relay_sid, sc->sc_relay_sid_len);
|
|
|
|
p += sc->sc_relay_sid_len;
|
|
|
|
}
|
2001-04-29 13:50:36 +04:00
|
|
|
PPPOE_ADD_16(p, PPPOE_TAG_HUNIQUE);
|
|
|
|
PPPOE_ADD_16(p, sizeof(sc));
|
|
|
|
memcpy(p, &sc, sizeof sc);
|
2011-09-05 16:19:09 +04:00
|
|
|
p += sizeof(sc);
|
|
|
|
|
|
|
|
if (sc->sc_sppp.pp_if.if_mtu > PPPOE_MAXMTU) {
|
|
|
|
PPPOE_ADD_16(p, PPPOE_TAG_MAX_PAYLOAD);
|
|
|
|
PPPOE_ADD_16(p, 2);
|
|
|
|
PPPOE_ADD_16(p, (uint16_t)sc->sc_sppp.pp_if.if_mtu);
|
|
|
|
}
|
2001-04-29 13:50:36 +04:00
|
|
|
|
|
|
|
#ifdef PPPOE_DEBUG
|
|
|
|
p += sizeof sc;
|
2008-02-20 20:05:52 +03:00
|
|
|
if (p - mtod(m0, uint8_t *) != len + PPPOE_HEADERLEN)
|
2001-04-29 13:50:36 +04:00
|
|
|
panic("pppoe_send_padr: garbled output len, should be %ld, is %ld",
|
2008-02-20 20:05:52 +03:00
|
|
|
(long)(len + PPPOE_HEADERLEN), (long)(p - mtod(m0, uint8_t *)));
|
2001-04-29 13:50:36 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return pppoe_output(sc, m0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* send a PADT packet */
|
|
|
|
static int
|
2008-02-20 20:05:52 +03:00
|
|
|
pppoe_send_padt(struct ifnet *outgoing_if, u_int session, const uint8_t *dest)
|
2001-04-29 13:50:36 +04:00
|
|
|
{
|
2003-02-04 23:52:23 +03:00
|
|
|
struct ether_header *eh;
|
|
|
|
struct sockaddr dst;
|
2001-04-29 13:50:36 +04:00
|
|
|
struct mbuf *m0;
|
2008-02-20 20:05:52 +03:00
|
|
|
uint8_t *p;
|
2001-04-29 13:50:36 +04:00
|
|
|
|
|
|
|
m0 = pppoe_get_mbuf(PPPOE_HEADERLEN);
|
2002-06-22 09:52:00 +04:00
|
|
|
if (!m0)
|
2003-02-04 23:52:23 +03:00
|
|
|
return EIO;
|
2008-02-20 20:05:52 +03:00
|
|
|
p = mtod(m0, uint8_t *);
|
2003-02-04 23:52:23 +03:00
|
|
|
PPPOE_ADD_HEADER(p, PPPOE_CODE_PADT, session, 0);
|
|
|
|
|
|
|
|
memset(&dst, 0, sizeof dst);
|
|
|
|
dst.sa_family = AF_UNSPEC;
|
|
|
|
eh = (struct ether_header*)&dst.sa_data;
|
|
|
|
eh->ether_type = htons(ETHERTYPE_PPPOEDISC);
|
|
|
|
memcpy(&eh->ether_dhost, dest, ETHER_ADDR_LEN);
|
|
|
|
|
|
|
|
m0->m_flags &= ~(M_BCAST|M_MCAST);
|
2016-06-20 09:46:37 +03:00
|
|
|
return if_output_lock(outgoing_if, outgoing_if, m0, &dst, NULL);
|
2001-04-29 13:50:36 +04:00
|
|
|
}
|
|
|
|
|
2003-06-18 12:12:51 +04:00
|
|
|
#ifdef PPPOE_SERVER
|
|
|
|
static int
|
|
|
|
pppoe_send_pado(struct pppoe_softc *sc)
|
|
|
|
{
|
|
|
|
struct mbuf *m0;
|
2008-02-20 20:05:52 +03:00
|
|
|
uint8_t *p;
|
2003-06-18 12:12:51 +04:00
|
|
|
size_t len;
|
|
|
|
|
|
|
|
if (sc->sc_state != PPPOE_STATE_PADO_SENT)
|
|
|
|
return EIO;
|
|
|
|
|
|
|
|
/* calc length */
|
|
|
|
len = 0;
|
|
|
|
/* include ac_cookie */
|
|
|
|
len += 2 + 2 + sizeof(sc);
|
|
|
|
/* include hunique */
|
|
|
|
len += 2 + 2 + sc->sc_hunique_len;
|
|
|
|
m0 = pppoe_get_mbuf(len + PPPOE_HEADERLEN);
|
|
|
|
if (!m0)
|
|
|
|
return EIO;
|
2008-02-20 20:05:52 +03:00
|
|
|
p = mtod(m0, uint8_t *);
|
2003-06-18 12:12:51 +04:00
|
|
|
PPPOE_ADD_HEADER(p, PPPOE_CODE_PADO, 0, len);
|
|
|
|
PPPOE_ADD_16(p, PPPOE_TAG_ACCOOKIE);
|
|
|
|
PPPOE_ADD_16(p, sizeof(sc));
|
|
|
|
memcpy(p, &sc, sizeof(sc));
|
|
|
|
p += sizeof(sc);
|
|
|
|
PPPOE_ADD_16(p, PPPOE_TAG_HUNIQUE);
|
|
|
|
PPPOE_ADD_16(p, sc->sc_hunique_len);
|
|
|
|
memcpy(p, sc->sc_hunique, sc->sc_hunique_len);
|
|
|
|
return pppoe_output(sc, m0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pppoe_send_pads(struct pppoe_softc *sc)
|
|
|
|
{
|
2006-06-08 02:33:33 +04:00
|
|
|
struct bintime bt;
|
2003-06-18 12:12:51 +04:00
|
|
|
struct mbuf *m0;
|
2008-02-20 20:05:52 +03:00
|
|
|
uint8_t *p;
|
2005-08-31 04:00:26 +04:00
|
|
|
size_t len, l1 = 0; /* XXX: gcc */
|
2003-06-18 12:12:51 +04:00
|
|
|
|
|
|
|
if (sc->sc_state != PPPOE_STATE_PADO_SENT)
|
|
|
|
return EIO;
|
|
|
|
|
2006-06-08 02:33:33 +04:00
|
|
|
getbinuptime(&bt);
|
|
|
|
sc->sc_session = bt.sec % 0xff + 1;
|
2003-06-18 12:12:51 +04:00
|
|
|
/* calc length */
|
|
|
|
len = 0;
|
|
|
|
/* include hunique */
|
|
|
|
len += 2 + 2 + 2 + 2 + sc->sc_hunique_len; /* service name, host unique*/
|
|
|
|
if (sc->sc_service_name != NULL) { /* service name tag maybe empty */
|
|
|
|
l1 = strlen(sc->sc_service_name);
|
|
|
|
len += l1;
|
|
|
|
}
|
|
|
|
m0 = pppoe_get_mbuf(len + PPPOE_HEADERLEN);
|
|
|
|
if (!m0)
|
|
|
|
return ENOBUFS;
|
2008-02-20 20:05:52 +03:00
|
|
|
p = mtod(m0, uint8_t *);
|
2003-06-18 12:12:51 +04:00
|
|
|
PPPOE_ADD_HEADER(p, PPPOE_CODE_PADS, sc->sc_session, len);
|
|
|
|
PPPOE_ADD_16(p, PPPOE_TAG_SNAME);
|
|
|
|
if (sc->sc_service_name != NULL) {
|
|
|
|
PPPOE_ADD_16(p, l1);
|
|
|
|
memcpy(p, sc->sc_service_name, l1);
|
|
|
|
p += l1;
|
|
|
|
} else {
|
|
|
|
PPPOE_ADD_16(p, 0);
|
|
|
|
}
|
|
|
|
PPPOE_ADD_16(p, PPPOE_TAG_HUNIQUE);
|
|
|
|
PPPOE_ADD_16(p, sc->sc_hunique_len);
|
|
|
|
memcpy(p, sc->sc_hunique, sc->sc_hunique_len);
|
|
|
|
return pppoe_output(sc, m0);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2001-04-29 13:50:36 +04:00
|
|
|
static void
|
|
|
|
pppoe_tls(struct sppp *sp)
|
|
|
|
{
|
2002-06-22 09:52:00 +04:00
|
|
|
struct pppoe_softc *sc = (void *)sp;
|
2008-08-19 01:43:49 +04:00
|
|
|
int wtime;
|
|
|
|
|
2001-04-29 13:50:36 +04:00
|
|
|
if (sc->sc_state != PPPOE_STATE_INITIAL)
|
|
|
|
return;
|
2008-08-19 01:43:49 +04:00
|
|
|
|
|
|
|
if (sc->sc_sppp.pp_phase == SPPP_PHASE_ESTABLISH &&
|
|
|
|
sc->sc_sppp.pp_auth_failures > 0) {
|
|
|
|
/*
|
|
|
|
* Delay trying to reconnect a bit more - the peer
|
2014-10-18 12:33:23 +04:00
|
|
|
* might have failed to contact its radius server.
|
2008-08-19 01:43:49 +04:00
|
|
|
*/
|
2008-08-20 02:03:05 +04:00
|
|
|
wtime = PPPOE_RECON_FAST * sc->sc_sppp.pp_auth_failures;
|
|
|
|
if (wtime > PPPOE_SLOW_RETRY)
|
|
|
|
wtime = PPPOE_SLOW_RETRY;
|
2008-08-19 01:43:49 +04:00
|
|
|
} else {
|
2008-08-20 02:03:05 +04:00
|
|
|
wtime = PPPOE_RECON_IMMEDIATE;
|
2008-08-19 01:43:49 +04:00
|
|
|
}
|
|
|
|
callout_reset(&sc->sc_timeout, wtime, pppoe_timeout, sc);
|
2001-04-29 13:50:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pppoe_tlf(struct sppp *sp)
|
|
|
|
{
|
2002-06-22 09:52:00 +04:00
|
|
|
struct pppoe_softc *sc = (void *)sp;
|
2001-04-29 13:50:36 +04:00
|
|
|
if (sc->sc_state < PPPOE_STATE_SESSION)
|
|
|
|
return;
|
|
|
|
/*
|
|
|
|
* Do not call pppoe_disconnect here, the upper layer state
|
|
|
|
* machine gets confused by this. We must return from this
|
|
|
|
* function and defer disconnecting to the timeout handler.
|
|
|
|
*/
|
|
|
|
sc->sc_state = PPPOE_STATE_CLOSING;
|
2001-12-15 23:43:31 +03:00
|
|
|
callout_reset(&sc->sc_timeout, hz/50, pppoe_timeout, sc);
|
2001-04-29 13:50:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pppoe_start(struct ifnet *ifp)
|
|
|
|
{
|
2002-06-22 09:52:00 +04:00
|
|
|
struct pppoe_softc *sc = (void *)ifp;
|
2001-04-29 13:50:36 +04:00
|
|
|
struct mbuf *m;
|
2008-02-20 20:05:52 +03:00
|
|
|
uint8_t *p;
|
2001-04-29 13:50:36 +04:00
|
|
|
size_t len;
|
|
|
|
|
|
|
|
if (sppp_isempty(ifp))
|
|
|
|
return;
|
|
|
|
|
2003-09-27 02:23:58 +04:00
|
|
|
/* are we ready to process data yet? */
|
2001-04-29 13:50:36 +04:00
|
|
|
if (sc->sc_state < PPPOE_STATE_SESSION) {
|
|
|
|
sppp_flush(&sc->sc_sppp.pp_if);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while ((m = sppp_dequeue(ifp)) != NULL) {
|
|
|
|
len = m->m_pkthdr.len;
|
|
|
|
M_PREPEND(m, PPPOE_HEADERLEN, M_DONTWAIT);
|
|
|
|
if (m == NULL) {
|
2003-01-07 23:02:10 +03:00
|
|
|
ifp->if_oerrors++;
|
|
|
|
continue;
|
2001-04-29 13:50:36 +04:00
|
|
|
}
|
2008-02-20 20:05:52 +03:00
|
|
|
p = mtod(m, uint8_t *);
|
2001-04-29 13:50:36 +04:00
|
|
|
PPPOE_ADD_HEADER(p, 0, sc->sc_session, len);
|
|
|
|
|
2010-04-05 11:19:28 +04:00
|
|
|
bpf_mtap(&sc->sc_sppp.pp_if, m);
|
2001-04-29 13:50:36 +04:00
|
|
|
|
|
|
|
pppoe_output(sc, m);
|
|
|
|
}
|
|
|
|
}
|
2004-11-28 14:44:36 +03:00
|
|
|
|
|
|
|
|
|
|
|
static int
|
2013-06-30 01:06:57 +04:00
|
|
|
pppoe_ifattach_hook(void *arg, struct mbuf **mp, struct ifnet *ifp, int dir)
|
2004-11-28 14:44:36 +03:00
|
|
|
{
|
|
|
|
struct pppoe_softc *sc;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
if (mp != (struct mbuf **)PFIL_IFNET_DETACH)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
s = splnet();
|
|
|
|
LIST_FOREACH(sc, &pppoe_softc_list, sc_list) {
|
|
|
|
if (sc->sc_eth_if != ifp)
|
|
|
|
continue;
|
|
|
|
if (sc->sc_sppp.pp_if.if_flags & IFF_UP) {
|
|
|
|
sc->sc_sppp.pp_if.if_flags &= ~(IFF_UP|IFF_RUNNING);
|
|
|
|
printf("%s: ethernet interface detached, going down\n",
|
|
|
|
sc->sc_sppp.pp_if.if_xname);
|
|
|
|
}
|
|
|
|
sc->sc_eth_if = NULL;
|
2004-12-08 10:43:29 +03:00
|
|
|
pppoe_clear_softc(sc, "ethernet interface detached");
|
2004-11-28 14:44:36 +03:00
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2004-12-08 10:43:29 +03:00
|
|
|
|
|
|
|
static void
|
|
|
|
pppoe_clear_softc(struct pppoe_softc *sc, const char *message)
|
|
|
|
{
|
2005-01-19 18:05:55 +03:00
|
|
|
/* stop timer */
|
2004-12-08 10:43:29 +03:00
|
|
|
callout_stop(&sc->sc_timeout);
|
|
|
|
if (sc->sc_sppp.pp_if.if_flags & IFF_DEBUG)
|
|
|
|
printf("%s: session 0x%x terminated, %s\n",
|
|
|
|
sc->sc_sppp.pp_if.if_xname, sc->sc_session, message);
|
|
|
|
|
|
|
|
/* fix our state */
|
|
|
|
sc->sc_state = PPPOE_STATE_INITIAL;
|
|
|
|
|
|
|
|
/* signal upper layer */
|
|
|
|
sc->sc_sppp.pp_down(&sc->sc_sppp);
|
|
|
|
|
|
|
|
/* clean up softc */
|
|
|
|
memcpy(&sc->sc_dest, etherbroadcastaddr, sizeof(sc->sc_dest));
|
|
|
|
if (sc->sc_ac_cookie) {
|
|
|
|
free(sc->sc_ac_cookie, M_DEVBUF);
|
|
|
|
sc->sc_ac_cookie = NULL;
|
|
|
|
}
|
2009-02-19 18:17:50 +03:00
|
|
|
if (sc->sc_relay_sid) {
|
|
|
|
free(sc->sc_relay_sid, M_DEVBUF);
|
|
|
|
sc->sc_relay_sid = NULL;
|
|
|
|
}
|
2004-12-08 10:43:29 +03:00
|
|
|
sc->sc_ac_cookie_len = 0;
|
|
|
|
sc->sc_session = 0;
|
|
|
|
}
|
2016-04-15 04:31:29 +03:00
|
|
|
|
|
|
|
static void
|
|
|
|
pppoe_enqueue(struct ifqueue *inq, struct mbuf *m)
|
|
|
|
{
|
|
|
|
if (m->m_flags & M_PROMISC) {
|
|
|
|
m_free(m);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef PPPOE_SERVER
|
|
|
|
if (m->m_flags & (M_MCAST | M_BCAST)) {
|
|
|
|
m_free(m);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-10-03 14:06:06 +03:00
|
|
|
IFQ_LOCK(inq);
|
2016-04-15 04:31:29 +03:00
|
|
|
if (IF_QFULL(inq)) {
|
|
|
|
IF_DROP(inq);
|
2016-10-03 14:06:06 +03:00
|
|
|
IFQ_UNLOCK(inq);
|
2016-04-15 04:31:29 +03:00
|
|
|
m_freem(m);
|
|
|
|
} else {
|
|
|
|
IF_ENQUEUE(inq, m);
|
2016-10-03 14:06:06 +03:00
|
|
|
IFQ_UNLOCK(inq);
|
2016-04-15 04:31:29 +03:00
|
|
|
softint_schedule(pppoe_softintr);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
pppoe_input(struct ifnet *ifp, struct mbuf *m)
|
|
|
|
{
|
|
|
|
pppoe_enqueue(&ppoeinq, m);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
pppoedisc_input(struct ifnet *ifp, struct mbuf *m)
|
|
|
|
{
|
|
|
|
pppoe_enqueue(&ppoediscinq, m);
|
|
|
|
return;
|
|
|
|
}
|
2016-08-07 02:46:30 +03:00
|
|
|
|
2016-08-11 18:16:07 +03:00
|
|
|
static void
|
|
|
|
sysctl_net_pppoe_setup(struct sysctllog **clog)
|
2016-08-07 04:59:43 +03:00
|
|
|
{
|
|
|
|
const struct sysctlnode *node = NULL;
|
|
|
|
|
|
|
|
sysctl_createv(clog, 0, NULL, &node,
|
|
|
|
CTLFLAG_PERMANENT,
|
|
|
|
CTLTYPE_NODE, "pppoe",
|
|
|
|
SYSCTL_DESCR("PPPOE protocol"),
|
|
|
|
NULL, 0, NULL, 0,
|
|
|
|
CTL_NET, CTL_CREATE, CTL_EOL);
|
|
|
|
|
|
|
|
if (node == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
sysctl_createv(clog, 0, &node, NULL,
|
|
|
|
CTLFLAG_PERMANENT | CTLFLAG_READONLY,
|
|
|
|
CTLTYPE_BOOL, "term_unknown",
|
|
|
|
SYSCTL_DESCR("Terminate unknown sessions"),
|
|
|
|
NULL, 0, &pppoe_term_unknown, sizeof(pppoe_term_unknown),
|
|
|
|
CTL_CREATE, CTL_EOL);
|
|
|
|
}
|
2016-08-07 20:38:33 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Module infrastructure
|
|
|
|
*/
|
|
|
|
#include "if_module.h"
|
|
|
|
|
|
|
|
IF_MODULE(MODULE_CLASS_DRIVER, pppoe, "sppp_subr")
|