PPP: removed PPPoE and PPPoL2TP callback status notifier

Added necessary PPP core functions for PPPoE and PPPoL2TP status
notificaton (ppp_link_failed and ppp_link_end), removed callback,
low level protocol are now calling PPP core "link" functions.
This commit is contained in:
Sylvain Rochet 2015-02-15 00:35:45 +01:00
parent 74fd2dc9ad
commit 808098413c
6 changed files with 33 additions and 100 deletions

View File

@ -370,6 +370,15 @@ ppp_pcb *ppp_new(struct netif *pppif, ppp_link_status_cb_fn link_status_cb, void
/* initialize the PPP subsystem */
int ppp_init(void);
/* Initiate LCP open request */
void ppp_start(ppp_pcb *pcb);
/* Called when link failed to setup */
void ppp_link_failed(ppp_pcb *pcb);
/* Called when link is normally down (i.e. it was asked to end) */
void ppp_link_end(ppp_pcb *pcb);
/* function called by pppoe.c */
void ppp_input(ppp_pcb *pcb, struct pbuf *pb);

View File

@ -112,10 +112,6 @@ PACK_STRUCT_END
/* passive */
#define PPPOE_STATE_PADO_SENT 1
#define PPPOE_CB_STATE_UP 0 /* PPPoE link is UP */
#define PPPOE_CB_STATE_DOWN 1 /* PPPoE link is DOWN - normal condition */
#define PPPOE_CB_STATE_FAILED 2 /* Failed to setup PPPoE link */
#define PPPOE_HEADERLEN sizeof(struct pppoehdr)
#define PPPOE_VERTYPE 0x11 /* VER=1, TYPE = 1 */
@ -144,7 +140,6 @@ struct pppoe_softc {
struct pppoe_softc *next;
struct netif *sc_ethif; /* ethernet interface we are using */
ppp_pcb *pcb; /* PPP PCB */
void (*sc_link_status_cb)(ppp_pcb *pcb, int up);
struct eth_addr sc_dest; /* hardware address of concentrator */
u16_t sc_session; /* PPPoE session id */
@ -168,7 +163,6 @@ struct pppoe_softc {
#define pppoe_init() /* compatibility define, no initialization needed */
ppp_pcb *pppoe_create(struct netif *pppif,
void (*link_status_cb_ll)(ppp_pcb *pcb, int up),
struct netif *ethif,
ppp_link_status_cb_fn link_status_cb, void *ctx_cb);
err_t pppoe_destroy(struct pppoe_softc *sc);

View File

@ -155,10 +155,6 @@
#define PPPOL2TP_STATE_ICCN_SENT 3
#define PPPOL2TP_STATE_DATA 4
#define PPPOL2TP_CB_STATE_UP 0 /* PPPoL2TP link is UP */
#define PPPOL2TP_CB_STATE_DOWN 1 /* PPPo2TP link is DOWN - normal condition */
#define PPPOL2TP_CB_STATE_FAILED 2 /* Failed to setup PPPo2TP link */
#define PPPOL2TP_OUTPUT_DATA_HEADER_LEN 6 /* Our data header len */
/*
@ -168,7 +164,6 @@ typedef struct pppol2tp_pcb_s pppol2tp_pcb;
struct pppol2tp_pcb_s {
ppp_pcb *ppp; /* PPP PCB */
u8_t phase; /* L2TP phase */
void (*link_status_cb)(ppp_pcb *pcb, int status);
struct udp_pcb *udp; /* UDP L2TP Socket */
struct netif *netif; /* Output interface, used as a default route */
ip_addr_t remote_ip; /* LNS IP Address */
@ -198,7 +193,6 @@ struct pppol2tp_pcb_s {
/* Create a new L2TP session. */
ppp_pcb *pppol2tp_create(struct netif *pppif,
void (*link_status_cb_ll)(ppp_pcb *pcb, int status),
struct netif *netif, ip_addr_t *ipaddr, u16_t port, u8_t *secret, u8_t secret_len,
ppp_link_status_cb_fn link_status_cb, void *ctx_cb);

View File

@ -185,7 +185,6 @@ const struct protent* const protocols[] = {
/* Prototypes for procedures local to this file. */
static void ppp_clear(ppp_pcb *pcb);
static void ppp_do_open(void *arg);
static void ppp_start(ppp_pcb *pcb); /** Initiate LCP open request */
static void ppp_stop(ppp_pcb *pcb);
static void ppp_hup(ppp_pcb *pcb);
@ -252,23 +251,19 @@ void ppp_set_xaccm(ppp_pcb *pcb, ext_accm *accm) {
#endif /* PPPOS_SUPPORT */
#if PPPOE_SUPPORT
static void ppp_over_ethernet_link_status_cb(ppp_pcb *pcb, int state);
ppp_pcb *ppp_over_ethernet_create(struct netif *pppif, struct netif *ethif, const char *service_name, const char *concentrator_name,
ppp_link_status_cb_fn link_status_cb, void *ctx_cb) {
LWIP_UNUSED_ARG(service_name);
LWIP_UNUSED_ARG(concentrator_name);
return pppoe_create(pppif, ppp_over_ethernet_link_status_cb, ethif, link_status_cb, ctx_cb);
return pppoe_create(pppif, ethif, link_status_cb, ctx_cb);
}
#endif /* PPPOE_SUPPORT */
#if PPPOL2TP_SUPPORT
static void ppp_over_l2tp_link_status_cb(ppp_pcb *pcb, int state);
ppp_pcb *ppp_over_l2tp_create(struct netif *pppif, struct netif *netif, ip_addr_t *ipaddr, u16_t port,
u8_t *secret, u8_t secret_len,
ppp_link_status_cb_fn link_status_cb, void *ctx_cb) {
return pppol2tp_create(pppif, ppp_over_l2tp_link_status_cb, netif, ipaddr, port, secret, secret_len, link_status_cb, ctx_cb);
return pppol2tp_create(pppif, netif, ipaddr, port, secret, secret_len, link_status_cb, ctx_cb);
}
#endif /* PPPOL2TP_SUPPORT */
@ -598,13 +593,26 @@ static void ppp_do_open(void *arg) {
}
/** Initiate LCP open request */
static void ppp_start(ppp_pcb *pcb) {
void ppp_start(ppp_pcb *pcb) {
PPPDEBUG(LOG_DEBUG, ("ppp_start: unit %d\n", pcb->num));
lcp_open(pcb); /* Start protocol */
lcp_lowerup(pcb);
PPPDEBUG(LOG_DEBUG, ("ppp_start: finished\n"));
}
/** Called when link failed to setup */
void ppp_link_failed(ppp_pcb *pcb) {
PPPDEBUG(LOG_DEBUG, ("ppp_failed: unit %d\n", pcb->num));
new_phase(pcb, PPP_PHASE_DEAD);
pcb->link_status_cb(pcb, PPPERR_OPEN, pcb->ctx_cb);
}
/** Called when link is normally down (i.e. it was asked to end) */
void ppp_link_end(ppp_pcb *pcb) {
PPPDEBUG(LOG_DEBUG, ("ppp_end: unit %d\n", pcb->num));
pcb->link_status_cb(pcb, PPPERR_CONNECT, pcb->ctx_cb);
}
/** LCP close request */
static void ppp_stop(ppp_pcb *pcb) {
PPPDEBUG(LOG_DEBUG, ("ppp_stop: unit %d\n", pcb->num));
@ -1800,37 +1808,6 @@ struct pbuf * ppp_singlebuf(struct pbuf *p) {
}
#if PPPOE_SUPPORT
static void ppp_over_ethernet_link_status_cb(ppp_pcb *pcb, int state) {
int pppoe_err_code = PPPERR_NONE;
switch(state) {
/* PPPoE link is established, starting PPP negotiation */
case PPPOE_CB_STATE_UP:
PPPDEBUG(LOG_INFO, ("ppp_over_ethernet_link_status_cb: unit %d: UP, connecting\n", pcb->num));
ppp_start(pcb);
return;
/* PPPoE link normally down (i.e. asked to do so) */
case PPPOE_CB_STATE_DOWN:
PPPDEBUG(LOG_INFO, ("ppp_over_ethernet_link_status_cb: unit %d: DOWN, disconnected\n", pcb->num));
pppoe_err_code = PPPERR_CONNECT;
break;
/* PPPoE link failed to setup (i.e. PADI/PADO timeout) */
case PPPOE_CB_STATE_FAILED:
PPPDEBUG(LOG_INFO, ("ppp_over_ethernet_link_status_cb: unit %d: FAILED, aborting\n", pcb->num));
pppoe_err_code = PPPERR_OPEN;
new_phase(pcb, PPP_PHASE_DEAD);
break;
default:
break;
}
pcb->link_status_cb(pcb, pcb->err_code ? pcb->err_code : pppoe_err_code, pcb->ctx_cb);
}
static void ppp_over_ethernet_open(ppp_pcb *pcb) {
lcp_options *wo = &pcb->lcp_wantoptions;
@ -1853,37 +1830,6 @@ static void ppp_over_ethernet_open(ppp_pcb *pcb) {
#endif /* PPPOE_SUPPORT */
#if PPPOL2TP_SUPPORT
static void ppp_over_l2tp_link_status_cb(ppp_pcb *pcb, int state) {
int pppol2tp_err_code = PPPERR_NONE;
switch(state) {
/* PPPoL2TP link is established, starting PPP negotiation */
case PPPOL2TP_CB_STATE_UP:
PPPDEBUG(LOG_INFO, ("ppp_over_l2tp_link_status_cb: unit %d: UP, connecting\n", pcb->num));
ppp_start(pcb);
return;
/* PPPoL2TP link normally down (i.e. asked to do so) */
case PPPOL2TP_CB_STATE_DOWN:
PPPDEBUG(LOG_INFO, ("ppp_over_l2tp_link_status_cb: unit %d: DOWN, disconnected\n", pcb->num));
pppol2tp_err_code = PPPERR_CONNECT;
break;
/* PPPoL2TP link failed to setup (i.e. L2TP timeout) */
case PPPOL2TP_CB_STATE_FAILED:
PPPDEBUG(LOG_INFO, ("ppp_over_l2tp_link_status_cb: unit %d: FAILED, aborting\n", pcb->num));
pppol2tp_err_code = PPPERR_OPEN;
new_phase(pcb, PPP_PHASE_DEAD);
break;
default:
break;
}
pcb->link_status_cb(pcb, pcb->err_code ? pcb->err_code : pppol2tp_err_code, pcb->ctx_cb);
}
static void ppp_over_l2tp_open(ppp_pcb *pcb) {
lcp_options *wo = &pcb->lcp_wantoptions;

View File

@ -138,7 +138,6 @@ static struct pppoe_softc *pppoe_softc_list;
ppp_pcb*
pppoe_create(struct netif *pppif,
void (*link_status_cb_ll)(ppp_pcb *pcb, int up),
struct netif *ethif,
ppp_link_status_cb_fn link_status_cb, void *ctx_cb)
{
@ -161,7 +160,6 @@ pppoe_create(struct netif *pppif,
MEMCPY(&sc->sc_dest, ethbroadcast.addr, sizeof(sc->sc_dest));
sc->pcb = ppp;
sc->sc_link_status_cb = link_status_cb_ll;
sc->sc_ethif = ethif;
/* put the new interface at the head of the list */
@ -272,12 +270,6 @@ static struct pppoe_softc* pppoe_find_softc_by_hunique(u8_t *token, size_t len,
return sc;
}
static void
pppoe_linkstatus_up(struct pppoe_softc *sc)
{
sc->sc_link_status_cb(sc->pcb, PPPOE_CB_STATE_UP);
}
/* analyze and handle a single received packet while not in session state */
void
pppoe_disc_input(struct netif *netif, struct pbuf *pb)
@ -485,7 +477,7 @@ breakbreak:;
}
pppoe_send_pads(sc);
sc->sc_state = PPPOE_STATE_SESSION;
pppoe_linkstatus_up(sc); /* notify upper layers */
ppp_start(sc->pcb); /* notify upper layers */
break;
#else
/* ignore, we are no access concentrator */
@ -524,7 +516,7 @@ breakbreak:;
sys_untimeout(pppoe_timeout, sc);
PPPDEBUG(LOG_DEBUG, ("pppoe: %c%c%"U16_F": session 0x%x connected\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num, session));
sc->sc_state = PPPOE_STATE_SESSION;
pppoe_linkstatus_up(sc); /* notify upper layers */
ppp_start(sc->pcb); /* notify upper layers */
break;
case PPPOE_CODE_PADT:
if (sc == NULL) {
@ -852,7 +844,7 @@ pppoe_disconnect(struct pppoe_softc *sc)
sc->sc_padi_retried = 0;
sc->sc_padr_retried = 0;
sc->sc_link_status_cb(sc->pcb, PPPOE_CB_STATE_DOWN); /* notify upper layers */
ppp_link_end(sc->pcb); /* notify upper layers */
return;
}
@ -870,7 +862,7 @@ pppoe_abort_connect(struct pppoe_softc *sc)
sc->sc_padi_retried = 0;
sc->sc_padr_retried = 0;
sc->sc_link_status_cb(sc->pcb, PPPOE_CB_STATE_FAILED); /* notify upper layers */
ppp_link_failed(sc->pcb); /* notify upper layers */
}
/* Send a PADR packet */
@ -1109,7 +1101,7 @@ pppoe_clear_softc(struct pppoe_softc *sc, const char *message)
sc->sc_state = PPPOE_STATE_INITIAL;
/* notify upper layers */
sc->sc_link_status_cb(sc->pcb, PPPOE_CB_STATE_DOWN);
ppp_link_end(sc->pcb);
/* clean up softc */
MEMCPY(&sc->sc_dest, ethbroadcast.addr, sizeof(sc->sc_dest));

View File

@ -88,7 +88,6 @@ static err_t pppol2tp_send_stopccn(pppol2tp_pcb *l2tp, u16_t ns);
/* Create a new L2TP session. */
ppp_pcb *pppol2tp_create(struct netif *pppif,
void (*link_status_cb_ll)(ppp_pcb *pcb, int status),
struct netif *netif, ip_addr_t *ipaddr, u16_t port, u8_t *secret, u8_t secret_len,
ppp_link_status_cb_fn link_status_cb, void *ctx_cb) {
ppp_pcb *ppp;
@ -118,7 +117,6 @@ ppp_pcb *pppol2tp_create(struct netif *pppif,
l2tp->phase = PPPOL2TP_STATE_INITIAL;
l2tp->ppp = ppp;
l2tp->udp = udp;
l2tp->link_status_cb = link_status_cb_ll;
l2tp->netif = netif;
ip_addr_set(&l2tp->remote_ip, ipaddr);
l2tp->remote_port = port;
@ -188,7 +186,7 @@ void pppol2tp_disconnect(pppol2tp_pcb *l2tp) {
pppol2tp_send_stopccn(l2tp, l2tp->our_ns);
pppol2tp_clear(l2tp);
l2tp->link_status_cb(l2tp->ppp, PPPOL2TP_CB_STATE_DOWN); /* notify upper layers */
ppp_link_end(l2tp->ppp); /* notify upper layers */
}
/* UDP Callback for incoming L2TP frames */
@ -523,7 +521,7 @@ nextavp:
l2tp->iccn_retried = 0;
l2tp->phase = PPPOL2TP_STATE_ICCN_SENT;
l2tp->our_ns++;
l2tp->link_status_cb(l2tp->ppp, PPPOL2TP_CB_STATE_UP); /* notify upper layers */
ppp_start(l2tp->ppp); /* notify upper layers */
if ((err = pppol2tp_send_iccn(l2tp, l2tp->our_ns)) != 0) {
PPPDEBUG(LOG_DEBUG, ("pppol2tp: failed to send ICCN, error=%d\n", err));
}
@ -615,7 +613,7 @@ static void pppol2tp_timeout(void *arg) {
static void pppol2tp_abort_connect(pppol2tp_pcb *l2tp) {
PPPDEBUG(LOG_DEBUG, ("pppol2tp: could not establish connection\n"));
pppol2tp_clear(l2tp);
l2tp->link_status_cb(l2tp->ppp, PPPOL2TP_CB_STATE_FAILED); /* notify upper layers */
ppp_link_failed(l2tp->ppp); /* notify upper layers */
}
/* Reset L2TP control block to its initial state */