mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2025-03-13 07:14:31 +00:00
PPP: moved ppp_new() to low level protocol init for PPPoE and PPPoL2TP
First step of a rework of how low level protocols are using the PPP core. Low level protocols are now going to use the core instead of core using the low level protocols. Final goal: separate PPP core code from low level protocols.
This commit is contained in:
parent
443b2551c7
commit
74fd2dc9ad
@ -179,6 +179,9 @@ typedef unsigned char u_char;
|
||||
#include "vj.h"
|
||||
#endif /* VJ_SUPPORT */
|
||||
|
||||
/* Link status callback function prototype */
|
||||
typedef void (*ppp_link_status_cb_fn)(ppp_pcb *pcb, int err_code, void *ctx);
|
||||
|
||||
#if PPPOE_SUPPORT
|
||||
#include "netif/ppp/pppoe.h"
|
||||
#endif /* PPPOE_SUPPORT */
|
||||
@ -504,9 +507,6 @@ struct ppp_pcb_s {
|
||||
#define PPPAUTHTYPE_EAP 0x08
|
||||
#define PPPAUTHTYPE_ANY 0xff
|
||||
|
||||
/* Link status callback function prototype */
|
||||
typedef void (*ppp_link_status_cb_fn)(ppp_pcb *pcb, int err_code, void *ctx);
|
||||
|
||||
#if PPPOS_SUPPORT
|
||||
/*
|
||||
* Create a new PPP connection using the given serial I/O device.
|
||||
|
@ -362,8 +362,11 @@ struct pppd_stats {
|
||||
#endif /* PPP_STATS_SUPPORT */
|
||||
|
||||
|
||||
/* PPP flow functions
|
||||
/* PPP functions
|
||||
*/
|
||||
/* Create a new PPP control block */
|
||||
ppp_pcb *ppp_new(struct netif *pppif, ppp_link_status_cb_fn link_status_cb, void *ctx_cb);
|
||||
|
||||
/* initialize the PPP subsystem */
|
||||
int ppp_init(void);
|
||||
|
||||
|
@ -167,7 +167,10 @@ struct pppoe_softc {
|
||||
|
||||
#define pppoe_init() /* compatibility define, no initialization needed */
|
||||
|
||||
err_t pppoe_create(struct netif *ethif, ppp_pcb *pcb, void (*link_status_cb)(ppp_pcb *pcb, int up), struct pppoe_softc **scptr);
|
||||
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);
|
||||
|
||||
int pppoe_connect(struct pppoe_softc *sc);
|
||||
|
@ -197,9 +197,10 @@ struct pppol2tp_pcb_s {
|
||||
|
||||
|
||||
/* Create a new L2TP session. */
|
||||
err_t pppol2tp_create(ppp_pcb *ppp, void (*link_status_cb)(ppp_pcb *pcb, int status), pppol2tp_pcb **l2tpptr,
|
||||
struct netif *netif, ip_addr_t *ipaddr, u16_t port,
|
||||
u8_t *secret, u8_t secret_len);
|
||||
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);
|
||||
|
||||
/* Destroy a L2TP control block */
|
||||
err_t pppol2tp_destroy(pppol2tp_pcb *l2tp);
|
||||
|
@ -183,7 +183,6 @@ const struct protent* const protocols[] = {
|
||||
};
|
||||
|
||||
/* Prototypes for procedures local to this file. */
|
||||
static ppp_pcb *ppp_new(struct netif *pppif, ppp_link_status_cb_fn link_status_cb, void *ctx_cb);
|
||||
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 */
|
||||
@ -257,22 +256,9 @@ 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) {
|
||||
ppp_pcb *pcb;
|
||||
|
||||
LWIP_UNUSED_ARG(service_name);
|
||||
LWIP_UNUSED_ARG(concentrator_name);
|
||||
|
||||
pcb = ppp_new(pppif, link_status_cb, ctx_cb);
|
||||
if (pppif == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (pppoe_create(ethif, pcb, ppp_over_ethernet_link_status_cb, &pcb->pppoe_sc) != ERR_OK) {
|
||||
ppp_free(pcb);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pcb;
|
||||
return pppoe_create(pppif, ppp_over_ethernet_link_status_cb, ethif, link_status_cb, ctx_cb);
|
||||
}
|
||||
#endif /* PPPOE_SUPPORT */
|
||||
|
||||
@ -282,19 +268,7 @@ 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) {
|
||||
ppp_pcb *pcb;
|
||||
|
||||
pcb = ppp_new(pppif, link_status_cb, ctx_cb);
|
||||
if (pppif == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (pppol2tp_create(pcb, ppp_over_l2tp_link_status_cb, &pcb->l2tp_pcb, netif, ipaddr, port, secret, secret_len) != ERR_OK) {
|
||||
ppp_free(pcb);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pcb;
|
||||
return pppol2tp_create(pppif, ppp_over_l2tp_link_status_cb, netif, ipaddr, port, secret, secret_len, link_status_cb, ctx_cb);
|
||||
}
|
||||
#endif /* PPPOL2TP_SUPPORT */
|
||||
|
||||
@ -497,7 +471,7 @@ int ppp_init(void) {
|
||||
}
|
||||
|
||||
/*
|
||||
* Create a new PPP session.
|
||||
* Create a new PPP control block.
|
||||
*
|
||||
* This initializes the PPP control block but does not
|
||||
* attempt to negotiate the LCP session.
|
||||
@ -505,7 +479,7 @@ int ppp_init(void) {
|
||||
* Return a new PPP connection control block pointer
|
||||
* on success or a null pointer on failure.
|
||||
*/
|
||||
static ppp_pcb *ppp_new(struct netif *pppif, ppp_link_status_cb_fn link_status_cb, void *ctx_cb) {
|
||||
ppp_pcb *ppp_new(struct netif *pppif, ppp_link_status_cb_fn link_status_cb, void *ctx_cb) {
|
||||
ppp_pcb *pcb;
|
||||
|
||||
/* PPP is single-threaded: without a callback,
|
||||
|
@ -136,32 +136,40 @@ static struct pppoe_softc* pppoe_find_softc_by_hunique(u8_t *token, size_t len,
|
||||
/** linked list of created pppoe interfaces */
|
||||
static struct pppoe_softc *pppoe_softc_list;
|
||||
|
||||
err_t
|
||||
pppoe_create(struct netif *ethif, ppp_pcb *pcb, void (*link_status_cb)(ppp_pcb *pcb, int up), struct pppoe_softc **scptr)
|
||||
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)
|
||||
{
|
||||
ppp_pcb *ppp;
|
||||
struct pppoe_softc *sc;
|
||||
|
||||
ppp = ppp_new(pppif, link_status_cb, ctx_cb);
|
||||
if (ppp == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sc = (struct pppoe_softc *)memp_malloc(MEMP_PPPOE_IF);
|
||||
if (sc == NULL) {
|
||||
*scptr = NULL;
|
||||
return ERR_MEM;
|
||||
ppp_free(ppp);
|
||||
return NULL;
|
||||
}
|
||||
memset(sc, 0, sizeof(struct pppoe_softc));
|
||||
|
||||
/* changed to real address later */
|
||||
MEMCPY(&sc->sc_dest, ethbroadcast.addr, sizeof(sc->sc_dest));
|
||||
|
||||
sc->pcb = pcb;
|
||||
sc->sc_link_status_cb = link_status_cb;
|
||||
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 */
|
||||
sc->next = pppoe_softc_list;
|
||||
pppoe_softc_list = sc;
|
||||
|
||||
*scptr = sc;
|
||||
|
||||
return ERR_OK;
|
||||
ppp->pppoe_sc = sc;
|
||||
return ppp;
|
||||
}
|
||||
|
||||
err_t
|
||||
|
@ -87,23 +87,30 @@ static err_t pppol2tp_send_stopccn(pppol2tp_pcb *l2tp, u16_t ns);
|
||||
|
||||
|
||||
/* Create a new L2TP session. */
|
||||
err_t pppol2tp_create(ppp_pcb *ppp, void (*link_status_cb)(ppp_pcb *pcb, int status), pppol2tp_pcb **l2tpptr,
|
||||
struct netif *netif, ip_addr_t *ipaddr, u16_t port,
|
||||
u8_t *secret, u8_t secret_len) {
|
||||
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;
|
||||
pppol2tp_pcb *l2tp;
|
||||
struct udp_pcb *udp;
|
||||
|
||||
ppp = ppp_new(pppif, link_status_cb, ctx_cb);
|
||||
if (ppp == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
l2tp = (pppol2tp_pcb *)memp_malloc(MEMP_PPPOL2TP_PCB);
|
||||
if (l2tp == NULL) {
|
||||
*l2tpptr = NULL;
|
||||
return ERR_MEM;
|
||||
ppp_free(ppp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
udp = udp_new();
|
||||
if (udp == NULL) {
|
||||
memp_free(MEMP_PPPOL2TP_PCB, l2tp);
|
||||
*l2tpptr = NULL;
|
||||
return ERR_MEM;
|
||||
ppp_free(ppp);
|
||||
return NULL;
|
||||
}
|
||||
udp_recv(udp, pppol2tp_input, l2tp);
|
||||
|
||||
@ -111,7 +118,7 @@ err_t pppol2tp_create(ppp_pcb *ppp, void (*link_status_cb)(ppp_pcb *pcb, int sta
|
||||
l2tp->phase = PPPOL2TP_STATE_INITIAL;
|
||||
l2tp->ppp = ppp;
|
||||
l2tp->udp = udp;
|
||||
l2tp->link_status_cb = link_status_cb;
|
||||
l2tp->link_status_cb = link_status_cb_ll;
|
||||
l2tp->netif = netif;
|
||||
ip_addr_set(&l2tp->remote_ip, ipaddr);
|
||||
l2tp->remote_port = port;
|
||||
@ -120,8 +127,8 @@ err_t pppol2tp_create(ppp_pcb *ppp, void (*link_status_cb)(ppp_pcb *pcb, int sta
|
||||
l2tp->secret_len = secret_len;
|
||||
#endif /* PPPOL2TP_AUTH_SUPPORT */
|
||||
|
||||
*l2tpptr = l2tp;
|
||||
return ERR_OK;
|
||||
ppp->l2tp_pcb = l2tp;
|
||||
return ppp;
|
||||
}
|
||||
|
||||
/* Destroy a L2TP control block */
|
||||
|
Loading…
x
Reference in New Issue
Block a user