PPP_PCB are now allocated using memp_alloc()

This commit is contained in:
Sylvain Rochet 2012-06-17 23:48:55 +02:00
parent be2d3b5886
commit 8641b8a36e
7 changed files with 33 additions and 76 deletions

View File

@ -87,6 +87,10 @@ LWIP_MEMPOOL(NETDB, MEMP_NUM_NETDB, NETDB_ELEM_SIZE,
#if LWIP_DNS && DNS_LOCAL_HOSTLIST && DNS_LOCAL_HOSTLIST_IS_DYNAMIC #if LWIP_DNS && DNS_LOCAL_HOSTLIST && DNS_LOCAL_HOSTLIST_IS_DYNAMIC
LWIP_MEMPOOL(LOCALHOSTLIST, MEMP_NUM_LOCALHOSTLIST, LOCALHOSTLIST_ELEM_SIZE, "LOCALHOSTLIST") LWIP_MEMPOOL(LOCALHOSTLIST, MEMP_NUM_LOCALHOSTLIST, LOCALHOSTLIST_ELEM_SIZE, "LOCALHOSTLIST")
#endif /* LWIP_DNS && DNS_LOCAL_HOSTLIST && DNS_LOCAL_HOSTLIST_IS_DYNAMIC */ #endif /* LWIP_DNS && DNS_LOCAL_HOSTLIST && DNS_LOCAL_HOSTLIST_IS_DYNAMIC */
#if PPP_SUPPORT
LWIP_MEMPOOL(PPP_PCB, MEMP_NUM_PPP_PCB, sizeof(ppp_pcb), "PPP_PCB")
#endif /* PPP_SUPPORT && PPPOE_SUPPORT */
#if PPP_SUPPORT && PPPOE_SUPPORT #if PPP_SUPPORT && PPPOE_SUPPORT
LWIP_MEMPOOL(PPPOE_IF, MEMP_NUM_PPPOE_INTERFACES, sizeof(struct pppoe_softc), "PPPOE_IF") LWIP_MEMPOOL(PPPOE_IF, MEMP_NUM_PPPOE_INTERFACES, sizeof(struct pppoe_softc), "PPPOE_IF")
#endif /* PPP_SUPPORT && PPPOE_SUPPORT */ #endif /* PPP_SUPPORT && PPPOE_SUPPORT */

View File

@ -399,6 +399,14 @@
#define MEMP_NUM_LOCALHOSTLIST 1 #define MEMP_NUM_LOCALHOSTLIST 1
#endif #endif
/**
* MEMP_NUM_PPP_PCB: the number of simultaneously active PPP
* connections (requires the PPP_SUPPORT option)
*/
#ifndef MEMP_NUM_PPP_PCB
#define MEMP_NUM_PPP_PCB 1
#endif
/** /**
* MEMP_NUM_PPPOE_INTERFACES: the number of concurrently active PPPoE * MEMP_NUM_PPPOE_INTERFACES: the number of concurrently active PPPoE
* interfaces (only used with PPPOE_SUPPORT==1) * interfaces (only used with PPPOE_SUPPORT==1)
@ -1695,13 +1703,6 @@
#if PPP_SUPPORT #if PPP_SUPPORT
/**
* NUM_PPP: Max PPP sessions.
*/
#ifndef NUM_PPP
#define NUM_PPP 1
#endif
/** /**
* PAP_SUPPORT==1: Support PAP. * PAP_SUPPORT==1: Support PAP.
*/ */

View File

@ -418,7 +418,6 @@ static void chap_respond(ppp_pcb *pcb, int id,
unsigned char response[RESP_MAX_PKTLEN]; unsigned char response[RESP_MAX_PKTLEN];
char rname[MAXNAMELEN+1]; char rname[MAXNAMELEN+1];
char secret[MAXSECRETLEN+1]; char secret[MAXSECRETLEN+1];
ppp_pcb *pc = &ppp_pcb_list[0];
if ((pcb->chap_client.flags & (LOWERUP | AUTH_STARTED)) != (LOWERUP | AUTH_STARTED)) if ((pcb->chap_client.flags & (LOWERUP | AUTH_STARTED)) != (LOWERUP | AUTH_STARTED))
return; /* not ready */ return; /* not ready */
@ -431,8 +430,8 @@ static void chap_respond(ppp_pcb *pcb, int id,
slprintf(rname, sizeof(rname), "%.*v", nlen, pkt + clen + 1); slprintf(rname, sizeof(rname), "%.*v", nlen, pkt + clen + 1);
/* Microsoft doesn't send their name back in the PPP packet */ /* Microsoft doesn't send their name back in the PPP packet */
if (pc->settings.explicit_remote || (pc->settings.remote_name[0] != 0 && rname[0] == 0)) if (pcb->settings.explicit_remote || (pcb->settings.remote_name[0] != 0 && rname[0] == 0))
strlcpy(rname, pc->settings.remote_name, sizeof(rname)); strlcpy(rname, pcb->settings.remote_name, sizeof(rname));
/* get secret for authenticating ourselves with the specified host */ /* get secret for authenticating ourselves with the specified host */
if (!get_secret(pcb, pcb->chap_client.name, rname, secret, &secret_len, 0)) { if (!get_secret(pcb, pcb->chap_client.name, rname, secret, &secret_len, 0)) {

View File

@ -204,6 +204,7 @@ static err_t ppp_netif_output_over_ethernet(ppp_pcb *pcb, struct pbuf *p);
static int ppp_write_over_ethernet(ppp_pcb *pcb, const u_char *s, int n); static int ppp_write_over_ethernet(ppp_pcb *pcb, const u_char *s, int n);
#endif /* PPPOE_SUPPORT */ #endif /* PPPOE_SUPPORT */
static void ppp_destroy(ppp_pcb *pcb);
/***********************************/ /***********************************/
/*** PUBLIC FUNCTION DEFINITIONS ***/ /*** PUBLIC FUNCTION DEFINITIONS ***/
@ -223,24 +224,20 @@ int ppp_init(void) {
/* Create a new PPP session. */ /* Create a new PPP session. */
ppp_pcb *ppp_new(u8_t num) { ppp_pcb *ppp_new(u8_t num) {
int i, pd; int i;
ppp_pcb *pcb; ppp_pcb *pcb;
struct protent *protp; struct protent *protp;
/* Find a free PPP session descriptor. */ pcb = (ppp_pcb*)memp_malloc(MEMP_PPP_PCB);
for (pd = 0; pd < NUM_PPP && ppp_pcb_list[pd].open_flag != 0; pd++); if (pcb == NULL)
if (pd >= NUM_PPP)
return NULL; return NULL;
pcb = &ppp_pcb_list[pd];
#if PPP_STATS_SUPPORT #if PPP_STATS_SUPPORT
link_stats_valid = 0; link_stats_valid = 0;
#endif /* PPP_STATS_SUPPORT */ #endif /* PPP_STATS_SUPPORT */
memset(pcb, 0, sizeof(ppp_pcb)); memset(pcb, 0, sizeof(ppp_pcb));
pcb->num = num; pcb->num = num;
pcb->open_flag = 1;
pcb->status = EXIT_OK; pcb->status = EXIT_OK;
pcb->lcp_loopbackfail = DEFLOOPBACKFAIL; pcb->lcp_loopbackfail = DEFLOOPBACKFAIL;
new_phase(pcb, PHASE_INITIALIZE); new_phase(pcb, PHASE_INITIALIZE);
@ -408,7 +405,6 @@ int ppp_over_ethernet_open(ppp_pcb *pcb, struct netif *ethif, const char *servic
ao->neg_accompression = 0; ao->neg_accompression = 0;
if(pppoe_create(ethif, pcb, 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;
return PPPERR_OPEN; return PPPERR_OPEN;
} }
@ -795,8 +791,7 @@ static void
ppp_receive_wakeup(ppp_pcb *pcb) ppp_receive_wakeup(ppp_pcb *pcb)
{ {
PPPDEBUG(LOG_DEBUG, ("ppp_receive_wakeup: unit %d\n", pcb->num)); PPPDEBUG(LOG_DEBUG, ("ppp_receive_wakeup: unit %d\n", pcb->num));
if (pcb->open_flag != 0) sio_read_abort(pcb->fd);
sio_read_abort(pcb->fd);
} }
#endif /* PPP_INPROC_OWNTHREAD */ #endif /* PPP_INPROC_OWNTHREAD */
#endif /* PPPOS_SUPPORT */ #endif /* PPPOS_SUPPORT */
@ -926,7 +921,7 @@ static err_t ppp_netif_output(struct netif *netif, struct pbuf *pb, ip_addr_t *i
/* Validate parameters. */ /* Validate parameters. */
/* We let any protocol value go through - it can't hurt us /* We let any protocol value go through - it can't hurt us
* and the peer will just drop it if it's not accepting it. */ * and the peer will just drop it if it's not accepting it. */
if (!pcb->open_flag || !pb) { if (!pcb || !pb) {
PPPDEBUG(LOG_WARNING, ("ppp_netif_output[%d]: bad params prot=%d pb=%p\n", PPPDEBUG(LOG_WARNING, ("ppp_netif_output[%d]: bad params prot=%d pb=%p\n",
pcb->num, PPP_IP, (void*)pb)); pcb->num, PPP_IP, (void*)pb));
LINK_STATS_INC(link.opterr); LINK_STATS_INC(link.opterr);
@ -1626,9 +1621,9 @@ static void ppp_over_ethernet_link_status_cb(ppp_pcb *pcb, int state) {
ppp_hup(pcb); ppp_hup(pcb);
ppp_stop(pcb); ppp_stop(pcb);
pppoe_destroy(&pcb->netif); pppoe_destroy(&pcb->netif);
pcb->open_flag = 0;
if(pcb->link_status_cb) if(pcb->link_status_cb)
pcb->link_status_cb(pcb->link_status_ctx, pcb->err_code ? pcb->err_code : pppoe_err_code, NULL); pcb->link_status_cb(pcb->link_status_ctx, pcb->err_code ? pcb->err_code : pppoe_err_code, NULL);
ppp_destroy(pcb);
} }
#endif /* PPPOE_SUPPORT */ #endif /* PPPOE_SUPPORT */
@ -1658,13 +1653,17 @@ void ppp_link_terminated(ppp_pcb *pcb) {
if (pcb->link_status_cb) { if (pcb->link_status_cb) {
pcb->link_status_cb(pcb->link_status_ctx, pcb->err_code ? pcb->err_code : PPPERR_PROTOCOL, NULL); pcb->link_status_cb(pcb->link_status_ctx, pcb->err_code ? pcb->err_code : PPPERR_PROTOCOL, NULL);
} }
ppp_destroy(pcb);
pcb->open_flag = 0;
#endif /* PPPOS_SUPPORT */ #endif /* PPPOS_SUPPORT */
} }
PPPDEBUG(LOG_DEBUG, ("ppp_link_terminated: finished.\n")); PPPDEBUG(LOG_DEBUG, ("ppp_link_terminated: finished.\n"));
} }
static void ppp_destroy(ppp_pcb *pcb) {
PPPDEBUG(LOG_DEBUG, ("ppp_destroy: unit %d\n", pcb->num));
memp_free(MEMP_PPP_PCB, pcb);
}
#if LWIP_NETIF_STATUS_CALLBACK #if LWIP_NETIF_STATUS_CALLBACK
/** Set the status callback of a PPP's netif /** Set the status callback of a PPP's netif
@ -1786,11 +1785,6 @@ int ppp_recv_config(ppp_pcb *pcb, int mru, u_int32_t accm, int pcomp, int accomp
int sifaddr(ppp_pcb *pcb, u_int32_t our_adr, u_int32_t his_adr, int sifaddr(ppp_pcb *pcb, u_int32_t our_adr, u_int32_t his_adr,
u_int32_t net_mask) { u_int32_t net_mask) {
if(!pcb->open_flag) {
PPPDEBUG(LOG_WARNING, ("sifaddr[%d]: bad params\n", pcb->num));
return 0;
}
SMEMCPY(&pcb->addrs.our_ipaddr, &our_adr, sizeof(our_adr)); SMEMCPY(&pcb->addrs.our_ipaddr, &our_adr, sizeof(our_adr));
SMEMCPY(&pcb->addrs.his_ipaddr, &his_adr, sizeof(his_adr)); SMEMCPY(&pcb->addrs.his_ipaddr, &his_adr, sizeof(his_adr));
SMEMCPY(&pcb->addrs.netmask, &net_mask, sizeof(net_mask)); SMEMCPY(&pcb->addrs.netmask, &net_mask, sizeof(net_mask));
@ -1808,11 +1802,6 @@ int cifaddr(ppp_pcb *pcb, u_int32_t our_adr, u_int32_t his_adr) {
LWIP_UNUSED_ARG(our_adr); LWIP_UNUSED_ARG(our_adr);
LWIP_UNUSED_ARG(his_adr); LWIP_UNUSED_ARG(his_adr);
if(!pcb->open_flag) {
PPPDEBUG(LOG_WARNING, ("cifaddr[%d]: bad params\n", pcb->num));
return 0;
}
IP4_ADDR(&pcb->addrs.our_ipaddr, 0,0,0,0); IP4_ADDR(&pcb->addrs.our_ipaddr, 0,0,0,0);
IP4_ADDR(&pcb->addrs.his_ipaddr, 0,0,0,0); IP4_ADDR(&pcb->addrs.his_ipaddr, 0,0,0,0);
IP4_ADDR(&pcb->addrs.netmask, 255,255,255,255); IP4_ADDR(&pcb->addrs.netmask, 255,255,255,255);
@ -1825,11 +1814,6 @@ int cifaddr(ppp_pcb *pcb, u_int32_t our_adr, u_int32_t his_adr) {
*/ */
int sdns(ppp_pcb *pcb, u_int32_t ns1, u_int32_t ns2) { int sdns(ppp_pcb *pcb, u_int32_t ns1, u_int32_t ns2) {
if(!pcb->open_flag) {
PPPDEBUG(LOG_WARNING, ("sdns[%d]: bad params\n", pcb->num));
return 0;
}
SMEMCPY(&pcb->addrs.dns1, &ns1, sizeof(ns1)); SMEMCPY(&pcb->addrs.dns1, &ns1, sizeof(ns1));
SMEMCPY(&pcb->addrs.dns2, &ns2, sizeof(ns2)); SMEMCPY(&pcb->addrs.dns2, &ns2, sizeof(ns2));
return 1; return 1;
@ -1845,11 +1829,6 @@ int cdns(ppp_pcb *pcb, u_int32_t ns1, u_int32_t ns2) {
LWIP_UNUSED_ARG(ns1); LWIP_UNUSED_ARG(ns1);
LWIP_UNUSED_ARG(ns2); LWIP_UNUSED_ARG(ns2);
if(!pcb->open_flag) {
PPPDEBUG(LOG_WARNING, ("cdns[%d]: bad params\n", pcb->num));
return 0;
}
IP4_ADDR(&pcb->addrs.dns1, 0,0,0,0); IP4_ADDR(&pcb->addrs.dns1, 0,0,0,0);
IP4_ADDR(&pcb->addrs.dns2, 0,0,0,0); IP4_ADDR(&pcb->addrs.dns2, 0,0,0,0);
return 1; return 1;
@ -1861,11 +1840,6 @@ int cdns(ppp_pcb *pcb, u_int32_t ns1, u_int32_t ns2) {
*/ */
int sifup(ppp_pcb *pcb) { int sifup(ppp_pcb *pcb) {
if(!pcb->open_flag) {
PPPDEBUG(LOG_WARNING, ("sifup[%d]: bad params\n", pcb->num));
return 0;
}
netif_remove(&pcb->netif); netif_remove(&pcb->netif);
if (!netif_add(&pcb->netif, &pcb->addrs.our_ipaddr, &pcb->addrs.netmask, if (!netif_add(&pcb->netif, &pcb->addrs.our_ipaddr, &pcb->addrs.netmask,
&pcb->addrs.his_ipaddr, (void *)pcb, ppp_netif_init_cb, ip_input)) { &pcb->addrs.his_ipaddr, (void *)pcb, ppp_netif_init_cb, ip_input)) {
@ -1891,11 +1865,6 @@ int sifup(ppp_pcb *pcb) {
*/ */
int sifdown(ppp_pcb *pcb) { int sifdown(ppp_pcb *pcb) {
if(!pcb->open_flag) {
PPPDEBUG(LOG_WARNING, ("sifdown[%d]: bad params\n", pcb->num));
return 0;
}
pcb->if_up = 0; pcb->if_up = 0;
/* make sure the netif status callback is called */ /* make sure the netif status callback is called */
netif_set_down(&pcb->netif); netif_set_down(&pcb->netif);
@ -1922,10 +1891,6 @@ int sifnpmode(ppp_pcb *pcb, int proto, enum NPmode mode) {
*/ */
void netif_set_mtu(ppp_pcb *pcb, int mtu) { void netif_set_mtu(ppp_pcb *pcb, int mtu) {
/* Validate parameters. */
if(!pcb->open_flag)
return;
pcb->mtu = mtu; pcb->mtu = mtu;
} }
@ -1934,10 +1899,6 @@ void netif_set_mtu(ppp_pcb *pcb, int mtu) {
*/ */
int netif_get_mtu(ppp_pcb *pcb) { int netif_get_mtu(ppp_pcb *pcb) {
/* Validate parameters. */
if(!pcb->open_flag)
return 0;
return pcb->mtu; return pcb->mtu;
} }
@ -1959,11 +1920,6 @@ int sifdefaultroute(ppp_pcb *pcb, u_int32_t ouraddr, u_int32_t gateway, bool rep
LWIP_UNUSED_ARG(gateway); LWIP_UNUSED_ARG(gateway);
LWIP_UNUSED_ARG(replace); LWIP_UNUSED_ARG(replace);
if(!pcb->open_flag) {
PPPDEBUG(LOG_WARNING, ("sifdefaultroute[%d]: bad params\n", pcb->num));
return 0;
}
netif_set_default(&pcb->netif); netif_set_default(&pcb->netif);
return 1; return 1;
} }
@ -1977,11 +1933,6 @@ int cifdefaultroute(ppp_pcb *pcb, u_int32_t ouraddr, u_int32_t gateway) {
LWIP_UNUSED_ARG(ouraddr); LWIP_UNUSED_ARG(ouraddr);
LWIP_UNUSED_ARG(gateway); LWIP_UNUSED_ARG(gateway);
if(!pcb->open_flag) {
PPPDEBUG(LOG_WARNING, ("cifdefaultroute[%d]: bad params\n", pcb->num));
return 0;
}
netif_set_default(NULL); netif_set_default(NULL);
return 1; return 1;
} }

View File

@ -262,7 +262,6 @@ struct ppp_pcb_s {
#if PPPOS_SUPPORT #if PPPOS_SUPPORT
ppp_pcb_rx rx; ppp_pcb_rx rx;
#endif /* PPPOS_SUPPORT */ #endif /* PPPOS_SUPPORT */
char open_flag; /* True when in use. */
u8_t phase; /* where the link is at */ u8_t phase; /* where the link is at */
u8_t status; /* exit status */ u8_t status; /* exit status */
#if PPPOE_SUPPORT #if PPPOE_SUPPORT

View File

@ -371,7 +371,6 @@ struct pppd_stats {
}; };
#endif /* PPP_STATS_SUPPORT */ #endif /* PPP_STATS_SUPPORT */
ppp_pcb ppp_pcb_list[NUM_PPP]; /* The PPP interface control blocks. */
/* PPP flow functions /* PPP flow functions
*/ */

View File

@ -579,7 +579,6 @@ static int upap_printpkt(u_char *p, int plen, void (*printer) (void *, char *, .
int mlen, ulen, wlen; int mlen, ulen, wlen;
char *user, *pwd, *msg; char *user, *pwd, *msg;
u_char *pstart; u_char *pstart;
ppp_pcb *pc = &ppp_pcb_list[0];
if (plen < UPAP_HEADERLEN) if (plen < UPAP_HEADERLEN)
return 0; return 0;
@ -613,10 +612,15 @@ static int upap_printpkt(u_char *p, int plen, void (*printer) (void *, char *, .
printer(arg, " user="); printer(arg, " user=");
print_string(user, ulen, printer, arg); print_string(user, ulen, printer, arg);
printer(arg, " password="); printer(arg, " password=");
if (!pc->settings.hide_password) /* FIXME: require ppp_pcb struct as printpkt() argument */
#if 0
if (!pcb->settings.hide_password)
#endif
print_string(pwd, wlen, printer, arg); print_string(pwd, wlen, printer, arg);
#if 0
else else
printer(arg, "<hidden>"); printer(arg, "<hidden>");
#endif
break; break;
case UPAP_AUTHACK: case UPAP_AUTHACK:
case UPAP_AUTHNAK: case UPAP_AUTHNAK: