mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2025-03-23 19:20:52 +00:00
PPP_PCB are now allocated using memp_alloc()
This commit is contained in:
parent
be2d3b5886
commit
8641b8a36e
@ -87,6 +87,10 @@ LWIP_MEMPOOL(NETDB, MEMP_NUM_NETDB, NETDB_ELEM_SIZE,
|
||||
#if LWIP_DNS && DNS_LOCAL_HOSTLIST && DNS_LOCAL_HOSTLIST_IS_DYNAMIC
|
||||
LWIP_MEMPOOL(LOCALHOSTLIST, MEMP_NUM_LOCALHOSTLIST, LOCALHOSTLIST_ELEM_SIZE, "LOCALHOSTLIST")
|
||||
#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
|
||||
LWIP_MEMPOOL(PPPOE_IF, MEMP_NUM_PPPOE_INTERFACES, sizeof(struct pppoe_softc), "PPPOE_IF")
|
||||
#endif /* PPP_SUPPORT && PPPOE_SUPPORT */
|
||||
|
@ -399,6 +399,14 @@
|
||||
#define MEMP_NUM_LOCALHOSTLIST 1
|
||||
#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
|
||||
* interfaces (only used with PPPOE_SUPPORT==1)
|
||||
@ -1695,13 +1703,6 @@
|
||||
|
||||
#if PPP_SUPPORT
|
||||
|
||||
/**
|
||||
* NUM_PPP: Max PPP sessions.
|
||||
*/
|
||||
#ifndef NUM_PPP
|
||||
#define NUM_PPP 1
|
||||
#endif
|
||||
|
||||
/**
|
||||
* PAP_SUPPORT==1: Support PAP.
|
||||
*/
|
||||
|
@ -418,7 +418,6 @@ static void chap_respond(ppp_pcb *pcb, int id,
|
||||
unsigned char response[RESP_MAX_PKTLEN];
|
||||
char rname[MAXNAMELEN+1];
|
||||
char secret[MAXSECRETLEN+1];
|
||||
ppp_pcb *pc = &ppp_pcb_list[0];
|
||||
|
||||
if ((pcb->chap_client.flags & (LOWERUP | AUTH_STARTED)) != (LOWERUP | AUTH_STARTED))
|
||||
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);
|
||||
|
||||
/* 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))
|
||||
strlcpy(rname, pc->settings.remote_name, sizeof(rname));
|
||||
if (pcb->settings.explicit_remote || (pcb->settings.remote_name[0] != 0 && rname[0] == 0))
|
||||
strlcpy(rname, pcb->settings.remote_name, sizeof(rname));
|
||||
|
||||
/* get secret for authenticating ourselves with the specified host */
|
||||
if (!get_secret(pcb, pcb->chap_client.name, rname, secret, &secret_len, 0)) {
|
||||
|
@ -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);
|
||||
#endif /* PPPOE_SUPPORT */
|
||||
|
||||
static void ppp_destroy(ppp_pcb *pcb);
|
||||
|
||||
/***********************************/
|
||||
/*** PUBLIC FUNCTION DEFINITIONS ***/
|
||||
@ -223,24 +224,20 @@ int ppp_init(void) {
|
||||
|
||||
/* Create a new PPP session. */
|
||||
ppp_pcb *ppp_new(u8_t num) {
|
||||
int i, pd;
|
||||
int i;
|
||||
ppp_pcb *pcb;
|
||||
struct protent *protp;
|
||||
|
||||
/* Find a free PPP session descriptor. */
|
||||
for (pd = 0; pd < NUM_PPP && ppp_pcb_list[pd].open_flag != 0; pd++);
|
||||
if (pd >= NUM_PPP)
|
||||
pcb = (ppp_pcb*)memp_malloc(MEMP_PPP_PCB);
|
||||
if (pcb == NULL)
|
||||
return NULL;
|
||||
|
||||
pcb = &ppp_pcb_list[pd];
|
||||
|
||||
#if PPP_STATS_SUPPORT
|
||||
link_stats_valid = 0;
|
||||
#endif /* PPP_STATS_SUPPORT */
|
||||
|
||||
memset(pcb, 0, sizeof(ppp_pcb));
|
||||
pcb->num = num;
|
||||
pcb->open_flag = 1;
|
||||
pcb->status = EXIT_OK;
|
||||
pcb->lcp_loopbackfail = DEFLOOPBACKFAIL;
|
||||
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;
|
||||
|
||||
if(pppoe_create(ethif, pcb, ppp_over_ethernet_link_status_cb, &pcb->pppoe_sc) != ERR_OK) {
|
||||
pcb->open_flag = 0;
|
||||
return PPPERR_OPEN;
|
||||
}
|
||||
|
||||
@ -795,8 +791,7 @@ static void
|
||||
ppp_receive_wakeup(ppp_pcb *pcb)
|
||||
{
|
||||
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 /* PPPOS_SUPPORT */
|
||||
@ -926,7 +921,7 @@ static err_t ppp_netif_output(struct netif *netif, struct pbuf *pb, ip_addr_t *i
|
||||
/* Validate parameters. */
|
||||
/* 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. */
|
||||
if (!pcb->open_flag || !pb) {
|
||||
if (!pcb || !pb) {
|
||||
PPPDEBUG(LOG_WARNING, ("ppp_netif_output[%d]: bad params prot=%d pb=%p\n",
|
||||
pcb->num, PPP_IP, (void*)pb));
|
||||
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_stop(pcb);
|
||||
pppoe_destroy(&pcb->netif);
|
||||
pcb->open_flag = 0;
|
||||
if(pcb->link_status_cb)
|
||||
pcb->link_status_cb(pcb->link_status_ctx, pcb->err_code ? pcb->err_code : pppoe_err_code, NULL);
|
||||
ppp_destroy(pcb);
|
||||
}
|
||||
#endif /* PPPOE_SUPPORT */
|
||||
|
||||
@ -1658,13 +1653,17 @@ void ppp_link_terminated(ppp_pcb *pcb) {
|
||||
if (pcb->link_status_cb) {
|
||||
pcb->link_status_cb(pcb->link_status_ctx, pcb->err_code ? pcb->err_code : PPPERR_PROTOCOL, NULL);
|
||||
}
|
||||
|
||||
pcb->open_flag = 0;
|
||||
ppp_destroy(pcb);
|
||||
#endif /* PPPOS_SUPPORT */
|
||||
}
|
||||
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
|
||||
/** 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,
|
||||
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.his_ipaddr, &his_adr, sizeof(his_adr));
|
||||
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(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.his_ipaddr, 0,0,0,0);
|
||||
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) {
|
||||
|
||||
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.dns2, &ns2, sizeof(ns2));
|
||||
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(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.dns2, 0,0,0,0);
|
||||
return 1;
|
||||
@ -1861,11 +1840,6 @@ int cdns(ppp_pcb *pcb, u_int32_t ns1, u_int32_t ns2) {
|
||||
*/
|
||||
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);
|
||||
if (!netif_add(&pcb->netif, &pcb->addrs.our_ipaddr, &pcb->addrs.netmask,
|
||||
&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) {
|
||||
|
||||
if(!pcb->open_flag) {
|
||||
PPPDEBUG(LOG_WARNING, ("sifdown[%d]: bad params\n", pcb->num));
|
||||
return 0;
|
||||
}
|
||||
|
||||
pcb->if_up = 0;
|
||||
/* make sure the netif status callback is called */
|
||||
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) {
|
||||
|
||||
/* Validate parameters. */
|
||||
if(!pcb->open_flag)
|
||||
return;
|
||||
|
||||
pcb->mtu = mtu;
|
||||
}
|
||||
|
||||
@ -1934,10 +1899,6 @@ void netif_set_mtu(ppp_pcb *pcb, int mtu) {
|
||||
*/
|
||||
int netif_get_mtu(ppp_pcb *pcb) {
|
||||
|
||||
/* Validate parameters. */
|
||||
if(!pcb->open_flag)
|
||||
return 0;
|
||||
|
||||
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(replace);
|
||||
|
||||
if(!pcb->open_flag) {
|
||||
PPPDEBUG(LOG_WARNING, ("sifdefaultroute[%d]: bad params\n", pcb->num));
|
||||
return 0;
|
||||
}
|
||||
|
||||
netif_set_default(&pcb->netif);
|
||||
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(gateway);
|
||||
|
||||
if(!pcb->open_flag) {
|
||||
PPPDEBUG(LOG_WARNING, ("cifdefaultroute[%d]: bad params\n", pcb->num));
|
||||
return 0;
|
||||
}
|
||||
|
||||
netif_set_default(NULL);
|
||||
return 1;
|
||||
}
|
||||
|
@ -262,7 +262,6 @@ struct ppp_pcb_s {
|
||||
#if PPPOS_SUPPORT
|
||||
ppp_pcb_rx rx;
|
||||
#endif /* PPPOS_SUPPORT */
|
||||
char open_flag; /* True when in use. */
|
||||
u8_t phase; /* where the link is at */
|
||||
u8_t status; /* exit status */
|
||||
#if PPPOE_SUPPORT
|
||||
|
@ -371,7 +371,6 @@ struct pppd_stats {
|
||||
};
|
||||
#endif /* PPP_STATS_SUPPORT */
|
||||
|
||||
ppp_pcb ppp_pcb_list[NUM_PPP]; /* The PPP interface control blocks. */
|
||||
|
||||
/* PPP flow functions
|
||||
*/
|
||||
|
@ -579,7 +579,6 @@ static int upap_printpkt(u_char *p, int plen, void (*printer) (void *, char *, .
|
||||
int mlen, ulen, wlen;
|
||||
char *user, *pwd, *msg;
|
||||
u_char *pstart;
|
||||
ppp_pcb *pc = &ppp_pcb_list[0];
|
||||
|
||||
if (plen < UPAP_HEADERLEN)
|
||||
return 0;
|
||||
@ -613,10 +612,15 @@ static int upap_printpkt(u_char *p, int plen, void (*printer) (void *, char *, .
|
||||
printer(arg, " user=");
|
||||
print_string(user, ulen, printer, arg);
|
||||
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);
|
||||
#if 0
|
||||
else
|
||||
printer(arg, "<hidden>");
|
||||
#endif
|
||||
break;
|
||||
case UPAP_AUTHACK:
|
||||
case UPAP_AUTHNAK:
|
||||
|
Loading…
x
Reference in New Issue
Block a user