no more PPP unit number in PPPoE, now using ppp_pcb

This commit is contained in:
Sylvain Rochet 2012-06-10 01:00:50 +02:00
parent f7ef9887d7
commit 5abdc99f3e
4 changed files with 32 additions and 35 deletions

View File

@ -145,8 +145,8 @@ PACK_STRUCT_END
struct pppoe_softc { struct pppoe_softc {
struct pppoe_softc *next; struct pppoe_softc *next;
struct netif *sc_ethif; /* ethernet interface we are using */ struct netif *sc_ethif; /* ethernet interface we are using */
int sc_pd; /* ppp unit number */ ppp_pcb *pcb; /* PPP PCB */
void (*sc_link_status_cb)(int pd, int up); void (*sc_link_status_cb)(ppp_pcb *pcb, int up);
int sc_state; /* discovery phase or session connected */ int sc_state; /* discovery phase or session connected */
struct eth_addr sc_dest; /* hardware address of concentrator */ struct eth_addr sc_dest; /* hardware address of concentrator */
@ -171,7 +171,7 @@ struct pppoe_softc {
#define pppoe_init() /* compatibility define, no initialization needed */ #define pppoe_init() /* compatibility define, no initialization needed */
err_t pppoe_create(struct netif *ethif, int pd, void (*link_status_cb)(int pd, int up), struct pppoe_softc **scptr); err_t pppoe_create(struct netif *ethif, ppp_pcb *pcb, void (*link_status_cb)(ppp_pcb *pcb, int up), struct pppoe_softc **scptr);
err_t pppoe_destroy(struct netif *ifp); err_t pppoe_destroy(struct netif *ifp);
int pppoe_connect(struct pppoe_softc *sc, bool persist); int pppoe_connect(struct pppoe_softc *sc, bool persist);

View File

@ -439,7 +439,7 @@ void ppp_set_xaccm(int unit, ext_accm *accm) {
#endif /* PPPOS_SUPPORT */ #endif /* PPPOS_SUPPORT */
#if PPPOE_SUPPORT #if PPPOE_SUPPORT
static void ppp_over_ethernet_link_status_cb(int pd, int state); static void ppp_over_ethernet_link_status_cb(ppp_pcb *pcb, int state);
int ppp_over_ethernet_open(ppp_pcb *pcb, struct netif *ethif, const char *service_name, const char *concentrator_name, int ppp_over_ethernet_open(ppp_pcb *pcb, struct netif *ethif, const char *service_name, const char *concentrator_name,
ppp_link_status_cb_fn link_status_cb, void *link_status_ctx) { ppp_link_status_cb_fn link_status_cb, void *link_status_ctx) {
@ -467,7 +467,7 @@ int ppp_over_ethernet_open(ppp_pcb *pcb, struct netif *ethif, const char *servic
lcp_allowoptions[pcb->unit].neg_pcompression = 0; lcp_allowoptions[pcb->unit].neg_pcompression = 0;
lcp_allowoptions[pcb->unit].neg_accompression = 0; lcp_allowoptions[pcb->unit].neg_accompression = 0;
if(pppoe_create(ethif, pcb->unit, ppp_over_ethernet_link_status_cb, &pcb->pppoe_sc) != ERR_OK) { if(pppoe_create(ethif, pcb, ppp_over_ethernet_link_status_cb, &pcb->pppoe_sc) != ERR_OK) {
pcb->open_flag = 0; pcb->open_flag = 0;
return PPPERR_OPEN; return PPPERR_OPEN;
} }
@ -891,7 +891,7 @@ ppp_receive_wakeup(int pd)
* this is totally stupid to make room for it and then modify the packet directly * this is totally stupid to make room for it and then modify the packet directly
* or it is used in output ? have to find out... * or it is used in output ? have to find out...
*/ */
void ppp_input_over_ethernet(int pd, struct pbuf *pb) { void ppp_input_over_ethernet(ppp_pcb *pcb, struct pbuf *pb) {
struct ppp_input_header *pih; struct ppp_input_header *pih;
u16_t in_protocol; u16_t in_protocol;
@ -914,16 +914,16 @@ void ppp_input_over_ethernet(int pd, struct pbuf *pb) {
pih = pb->payload; pih = pb->payload;
pih->unit = pd; pih->unit = pcb->unit;
pih->proto = in_protocol; /* pih->proto is now in host byte order */ pih->proto = in_protocol; /* pih->proto is now in host byte order */
/* Dispatch the packet thereby consuming it. */ /* Dispatch the packet thereby consuming it. */
ppp_input(pd, pb); ppp_input(pcb->unit, pb);
return; return;
drop: drop:
LINK_STATS_INC(link.drop); LINK_STATS_INC(link.drop);
snmp_inc_ifindiscards(&ppp_pcb_list[pd].netif); snmp_inc_ifindiscards(&pcb->netif);
pbuf_free(pb); pbuf_free(pb);
return; return;
} }
@ -1685,47 +1685,44 @@ struct pbuf * ppp_singlebuf(struct pbuf *p) {
} }
#if PPPOE_SUPPORT #if PPPOE_SUPPORT
static void ppp_over_ethernet_link_status_cb(int pd, int state) { static void ppp_over_ethernet_link_status_cb(ppp_pcb *pcb, int state) {
int pppoe_err_code = PPPERR_NONE; int pppoe_err_code = PPPERR_NONE;
ppp_pcb *pc;
switch(state) { switch(state) {
/* PPPoE link is established, starting PPP negotiation */ /* PPPoE link is established, starting PPP negotiation */
case PPPOE_CB_STATE_UP: case PPPOE_CB_STATE_UP:
PPPDEBUG(LOG_INFO, ("ppp_over_ethernet_link_status_cb: unit %d: UP, connecting\n", pd)); PPPDEBUG(LOG_INFO, ("ppp_over_ethernet_link_status_cb: unit %d: UP, connecting\n", pcb->unit));
ppp_start(pd); ppp_start(pcb->unit);
return; return;
/* PPPoE link normally down (i.e. asked to do so) */ /* PPPoE link normally down (i.e. asked to do so) */
case PPPOE_CB_STATE_DOWN: case PPPOE_CB_STATE_DOWN:
PPPDEBUG(LOG_INFO, ("ppp_over_ethernet_link_status_cb: unit %d: DOWN, disconnected\n", pd)); PPPDEBUG(LOG_INFO, ("ppp_over_ethernet_link_status_cb: unit %d: DOWN, disconnected\n", pcb->unit));
pppoe_err_code = PPPERR_CONNECT; pppoe_err_code = PPPERR_CONNECT;
break; break;
/* PPPoE link failed to setup (i.e. PADI/PADO timeout */ /* PPPoE link failed to setup (i.e. PADI/PADO timeout */
case PPPOE_CB_STATE_FAILED: case PPPOE_CB_STATE_FAILED:
PPPDEBUG(LOG_INFO, ("ppp_over_ethernet_link_status_cb: unit %d: FAILED, aborting\n", pd)); PPPDEBUG(LOG_INFO, ("ppp_over_ethernet_link_status_cb: unit %d: FAILED, aborting\n", pcb->unit));
pppoe_err_code = PPPERR_OPEN; pppoe_err_code = PPPERR_OPEN;
break; break;
} }
pc = &ppp_pcb_list[pd];
/* Reconnect if persist mode is enabled */ /* Reconnect if persist mode is enabled */
if(pc->settings.persist) { if(pcb->settings.persist) {
if(pc->link_status_cb) if(pcb->link_status_cb)
pc->link_status_cb(pc->link_status_ctx, pc->err_code ? pc->err_code : pppoe_err_code, NULL); pcb->link_status_cb(pcb->link_status_ctx, pcb->err_code ? pcb->err_code : pppoe_err_code, NULL);
pppoe_connect(pc->pppoe_sc, pc->settings.persist); pppoe_connect(pcb->pppoe_sc, pcb->settings.persist);
return; return;
} }
ppp_hup(pd); ppp_hup(pcb->unit);
ppp_stop(pd); ppp_stop(pcb->unit);
pppoe_destroy(&pc->netif); pppoe_destroy(&pcb->netif);
pc->open_flag = 0; pcb->open_flag = 0;
if(pc->link_status_cb) if(pcb->link_status_cb)
pc->link_status_cb(pc->link_status_ctx, pc->err_code ? pc->err_code : pppoe_err_code, NULL); pcb->link_status_cb(pcb->link_status_ctx, pcb->err_code ? pcb->err_code : pppoe_err_code, NULL);
} }
#endif /* PPPOE_SUPPORT */ #endif /* PPPOE_SUPPORT */

View File

@ -398,7 +398,7 @@ ppp_pcb ppp_pcb_list[NUM_PPP]; /* The PPP interface control blocks. */
#if PPPOE_SUPPORT #if PPPOE_SUPPORT
void ppp_over_ethernet_init_failed(int pd); void ppp_over_ethernet_init_failed(int pd);
/* function called by pppoe.c */ /* function called by pppoe.c */
void ppp_input_over_ethernet(int pd, struct pbuf *pb); void ppp_input_over_ethernet(ppp_pcb *pcb, struct pbuf *pb);
#endif /* PPPOE_SUPPORT */ #endif /* PPPOE_SUPPORT */
/* function called by all PPP subsystems to send packets */ /* function called by all PPP subsystems to send packets */

View File

@ -141,7 +141,7 @@ static struct pppoe_softc * pppoe_find_softc_by_hunique(u8_t *, size_t, struct n
static struct pppoe_softc *pppoe_softc_list; static struct pppoe_softc *pppoe_softc_list;
err_t err_t
pppoe_create(struct netif *ethif, int pd, void (*link_status_cb)(int pd, int up), struct pppoe_softc **scptr) pppoe_create(struct netif *ethif, ppp_pcb *pcb, void (*link_status_cb)(ppp_pcb *pcb, int up), struct pppoe_softc **scptr)
{ {
struct pppoe_softc *sc; struct pppoe_softc *sc;
@ -155,7 +155,7 @@ pppoe_create(struct netif *ethif, int pd, void (*link_status_cb)(int pd, int up)
/* changed to real address later */ /* changed to real address later */
MEMCPY(&sc->sc_dest, ethbroadcast.addr, sizeof(sc->sc_dest)); MEMCPY(&sc->sc_dest, ethbroadcast.addr, sizeof(sc->sc_dest));
sc->sc_pd = pd; sc->pcb = pcb;
sc->sc_link_status_cb = link_status_cb; sc->sc_link_status_cb = link_status_cb;
sc->sc_ethif = ethif; sc->sc_ethif = ethif;
@ -277,7 +277,7 @@ pppoe_find_softc_by_hunique(u8_t *token, size_t len, struct netif *rcvif)
static void static void
pppoe_linkstatus_up(struct pppoe_softc *sc) pppoe_linkstatus_up(struct pppoe_softc *sc)
{ {
sc->sc_link_status_cb(sc->sc_pd, PPPOE_CB_STATE_UP); sc->sc_link_status_cb(sc->pcb, PPPOE_CB_STATE_UP);
} }
/* analyze and handle a single received packet while not in session state */ /* analyze and handle a single received packet while not in session state */
@ -622,7 +622,7 @@ pppoe_data_input(struct netif *netif, struct pbuf *pb)
goto drop; goto drop;
} }
ppp_input_over_ethernet(sc->sc_pd, pb); ppp_input_over_ethernet(sc->pcb, pb);
return; return;
@ -874,7 +874,7 @@ pppoe_do_disconnect(struct pppoe_softc *sc)
sc->sc_padi_retried = 0; sc->sc_padi_retried = 0;
sc->sc_padr_retried = 0; sc->sc_padr_retried = 0;
sc->sc_link_status_cb(sc->sc_pd, PPPOE_CB_STATE_DOWN); /* notify upper layers */ sc->sc_link_status_cb(sc->pcb, PPPOE_CB_STATE_DOWN); /* notify upper layers */
return err; return err;
} }
@ -892,7 +892,7 @@ pppoe_abort_connect(struct pppoe_softc *sc)
sc->sc_padi_retried = 0; sc->sc_padi_retried = 0;
sc->sc_padr_retried = 0; sc->sc_padr_retried = 0;
sc->sc_link_status_cb(sc->sc_pd, PPPOE_CB_STATE_FAILED); /* notify upper layers */ sc->sc_link_status_cb(sc->pcb, PPPOE_CB_STATE_FAILED); /* notify upper layers */
} }
/* Send a PADR packet */ /* Send a PADR packet */
@ -1130,7 +1130,7 @@ pppoe_clear_softc(struct pppoe_softc *sc, const char *message)
sc->sc_state = PPPOE_STATE_INITIAL; sc->sc_state = PPPOE_STATE_INITIAL;
/* notify upper layers */ /* notify upper layers */
sc->sc_link_status_cb(sc->sc_pd, PPPOE_CB_STATE_DOWN); sc->sc_link_status_cb(sc->pcb, PPPOE_CB_STATE_DOWN);
/* clean up softc */ /* clean up softc */
MEMCPY(&sc->sc_dest, ethbroadcast.addr, sizeof(sc->sc_dest)); MEMCPY(&sc->sc_dest, ethbroadcast.addr, sizeof(sc->sc_dest));