Merged from DEVEL.

This commit is contained in:
marcbou 2003-06-27 20:46:11 +00:00
parent 45756246b9
commit 351e590e01
13 changed files with 131 additions and 94 deletions

View File

@ -5,7 +5,7 @@ HISTORY
++ Bug fixes: ++ Bug fixes:
* some debug formatters and casts fixed. * some debug formatters and casts fixed.
* numereous fixes in PPP. * numerous fixes in PPP.
++ Changes: ++ Changes:

View File

@ -44,7 +44,7 @@ netbuf *netbuf_new(void)
{ {
struct netbuf *buf; struct netbuf *buf;
buf = memp_mallocp(MEMP_NETBUF); buf = memp_malloc(MEMP_NETBUF);
if (buf != NULL) { if (buf != NULL) {
buf->p = NULL; buf->p = NULL;
buf->ptr = NULL; buf->ptr = NULL;
@ -62,7 +62,7 @@ netbuf_delete(struct netbuf *buf)
pbuf_free(buf->p); pbuf_free(buf->p);
buf->p = buf->ptr = NULL; buf->p = buf->ptr = NULL;
} }
memp_freep(MEMP_NETBUF, buf); memp_free(MEMP_NETBUF, buf);
} }
} }
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
@ -107,7 +107,7 @@ netbuf_chain(struct netbuf *head, struct netbuf *tail)
{ {
pbuf_chain(head->p, tail->p); pbuf_chain(head->p, tail->p);
head->ptr = head->p; head->ptr = head->p;
memp_freep(MEMP_NETBUF, tail); memp_free(MEMP_NETBUF, tail);
} }
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
u16_t u16_t
@ -198,7 +198,7 @@ netconn *netconn_new(enum netconn_type t)
{ {
struct netconn *conn; struct netconn *conn;
conn = memp_mallocp(MEMP_NETCONN); conn = memp_malloc(MEMP_NETCONN);
if (conn == NULL) { if (conn == NULL) {
return NULL; return NULL;
} }
@ -206,7 +206,7 @@ netconn *netconn_new(enum netconn_type t)
conn->pcb.tcp = NULL; conn->pcb.tcp = NULL;
if ((conn->mbox = sys_mbox_new()) == SYS_MBOX_NULL) { if ((conn->mbox = sys_mbox_new()) == SYS_MBOX_NULL) {
memp_freep(MEMP_NETCONN, conn); memp_free(MEMP_NETCONN, conn);
return NULL; return NULL;
} }
conn->recvmbox = SYS_MBOX_NULL; conn->recvmbox = SYS_MBOX_NULL;
@ -243,7 +243,7 @@ netconn_delete(struct netconn *conn)
return ERR_OK; return ERR_OK;
} }
if ((msg = memp_mallocp(MEMP_API_MSG)) == NULL) { if ((msg = memp_malloc(MEMP_API_MSG)) == NULL) {
return ERR_MEM; return ERR_MEM;
} }
@ -251,7 +251,7 @@ netconn_delete(struct netconn *conn)
msg->msg.conn = conn; msg->msg.conn = conn;
api_msg_post(msg); api_msg_post(msg);
sys_mbox_fetch(conn->mbox, NULL); sys_mbox_fetch(conn->mbox, NULL);
memp_freep(MEMP_API_MSG, msg); memp_free(MEMP_API_MSG, msg);
/* Drain the recvmbox. */ /* Drain the recvmbox. */
if (conn->recvmbox != SYS_MBOX_NULL) { if (conn->recvmbox != SYS_MBOX_NULL) {
@ -353,7 +353,7 @@ netconn_bind(struct netconn *conn, struct ip_addr *addr,
} }
} }
if ((msg = memp_mallocp(MEMP_API_MSG)) == NULL) { if ((msg = memp_malloc(MEMP_API_MSG)) == NULL) {
return (conn->err = ERR_MEM); return (conn->err = ERR_MEM);
} }
msg->type = API_MSG_BIND; msg->type = API_MSG_BIND;
@ -362,7 +362,7 @@ netconn_bind(struct netconn *conn, struct ip_addr *addr,
msg->msg.msg.bc.port = port; msg->msg.msg.bc.port = port;
api_msg_post(msg); api_msg_post(msg);
sys_mbox_fetch(conn->mbox, NULL); sys_mbox_fetch(conn->mbox, NULL);
memp_freep(MEMP_API_MSG, msg); memp_free(MEMP_API_MSG, msg);
return conn->err; return conn->err;
} }
@ -384,7 +384,7 @@ netconn_connect(struct netconn *conn, struct ip_addr *addr,
} }
} }
if ((msg = memp_mallocp(MEMP_API_MSG)) == NULL) { if ((msg = memp_malloc(MEMP_API_MSG)) == NULL) {
return ERR_MEM; return ERR_MEM;
} }
msg->type = API_MSG_CONNECT; msg->type = API_MSG_CONNECT;
@ -393,7 +393,7 @@ netconn_connect(struct netconn *conn, struct ip_addr *addr,
msg->msg.msg.bc.port = port; msg->msg.msg.bc.port = port;
api_msg_post(msg); api_msg_post(msg);
sys_mbox_fetch(conn->mbox, NULL); sys_mbox_fetch(conn->mbox, NULL);
memp_freep(MEMP_API_MSG, msg); memp_free(MEMP_API_MSG, msg);
return conn->err; return conn->err;
} }
@ -406,14 +406,14 @@ netconn_disconnect(struct netconn *conn)
return ERR_VAL; return ERR_VAL;
} }
if ((msg = memp_mallocp(MEMP_API_MSG)) == NULL) { if ((msg = memp_malloc(MEMP_API_MSG)) == NULL) {
return ERR_MEM; return ERR_MEM;
} }
msg->type = API_MSG_DISCONNECT; msg->type = API_MSG_DISCONNECT;
msg->msg.conn = conn; msg->msg.conn = conn;
api_msg_post(msg); api_msg_post(msg);
sys_mbox_fetch(conn->mbox, NULL); sys_mbox_fetch(conn->mbox, NULL);
memp_freep(MEMP_API_MSG, msg); memp_free(MEMP_API_MSG, msg);
return conn->err; return conn->err;
} }
@ -434,14 +434,14 @@ netconn_listen(struct netconn *conn)
} }
} }
if ((msg = memp_mallocp(MEMP_API_MSG)) == NULL) { if ((msg = memp_malloc(MEMP_API_MSG)) == NULL) {
return (conn->err = ERR_MEM); return (conn->err = ERR_MEM);
} }
msg->type = API_MSG_LISTEN; msg->type = API_MSG_LISTEN;
msg->msg.conn = conn; msg->msg.conn = conn;
api_msg_post(msg); api_msg_post(msg);
sys_mbox_fetch(conn->mbox, NULL); sys_mbox_fetch(conn->mbox, NULL);
memp_freep(MEMP_API_MSG, msg); memp_free(MEMP_API_MSG, msg);
return conn->err; return conn->err;
} }
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
@ -490,7 +490,7 @@ netconn_recv(struct netconn *conn)
} }
buf = memp_mallocp(MEMP_NETBUF); buf = memp_malloc(MEMP_NETBUF);
if (buf == NULL) { if (buf == NULL) {
conn->err = ERR_MEM; conn->err = ERR_MEM;
@ -514,7 +514,7 @@ netconn_recv(struct netconn *conn)
/* If we are closed, we indicate that we no longer wish to receive /* If we are closed, we indicate that we no longer wish to receive
data by setting conn->recvmbox to SYS_MBOX_NULL. */ data by setting conn->recvmbox to SYS_MBOX_NULL. */
if (p == NULL) { if (p == NULL) {
memp_freep(MEMP_NETBUF, buf); memp_free(MEMP_NETBUF, buf);
sys_mbox_free(conn->recvmbox); sys_mbox_free(conn->recvmbox);
conn->recvmbox = SYS_MBOX_NULL; conn->recvmbox = SYS_MBOX_NULL;
return NULL; return NULL;
@ -526,7 +526,7 @@ netconn_recv(struct netconn *conn)
buf->fromaddr = NULL; buf->fromaddr = NULL;
/* Let the stack know that we have taken the data. */ /* Let the stack know that we have taken the data. */
if ((msg = memp_mallocp(MEMP_API_MSG)) == NULL) { if ((msg = memp_malloc(MEMP_API_MSG)) == NULL) {
conn->err = ERR_MEM; conn->err = ERR_MEM;
return buf; return buf;
} }
@ -540,7 +540,7 @@ netconn_recv(struct netconn *conn)
api_msg_post(msg); api_msg_post(msg);
sys_mbox_fetch(conn->mbox, NULL); sys_mbox_fetch(conn->mbox, NULL);
memp_freep(MEMP_API_MSG, msg); memp_free(MEMP_API_MSG, msg);
} else { } else {
sys_mbox_fetch(conn->recvmbox, (void **)&buf); sys_mbox_fetch(conn->recvmbox, (void **)&buf);
conn->recv_avail -= buf->p->tot_len; conn->recv_avail -= buf->p->tot_len;
@ -571,7 +571,7 @@ netconn_send(struct netconn *conn, struct netbuf *buf)
return conn->err; return conn->err;
} }
if ((msg = memp_mallocp(MEMP_API_MSG)) == NULL) { if ((msg = memp_malloc(MEMP_API_MSG)) == NULL) {
return (conn->err = ERR_MEM); return (conn->err = ERR_MEM);
} }
@ -582,7 +582,7 @@ netconn_send(struct netconn *conn, struct netbuf *buf)
api_msg_post(msg); api_msg_post(msg);
sys_mbox_fetch(conn->mbox, NULL); sys_mbox_fetch(conn->mbox, NULL);
memp_freep(MEMP_API_MSG, msg); memp_free(MEMP_API_MSG, msg);
return conn->err; return conn->err;
} }
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
@ -607,7 +607,7 @@ netconn_write(struct netconn *conn, void *dataptr, u16_t size, u8_t copy)
} }
} }
if ((msg = memp_mallocp(MEMP_API_MSG)) == NULL) { if ((msg = memp_malloc(MEMP_API_MSG)) == NULL) {
return (conn->err = ERR_MEM); return (conn->err = ERR_MEM);
} }
msg->type = API_MSG_WRITE; msg->type = API_MSG_WRITE;
@ -652,7 +652,7 @@ netconn_write(struct netconn *conn, void *dataptr, u16_t size, u8_t copy)
} }
} }
ret: ret:
memp_freep(MEMP_API_MSG, msg); memp_free(MEMP_API_MSG, msg);
conn->state = NETCONN_NONE; conn->state = NETCONN_NONE;
if (conn->sem != SYS_SEM_NULL) { if (conn->sem != SYS_SEM_NULL) {
sys_sem_free(conn->sem); sys_sem_free(conn->sem);
@ -670,7 +670,7 @@ netconn_close(struct netconn *conn)
if (conn == NULL) { if (conn == NULL) {
return ERR_VAL; return ERR_VAL;
} }
if ((msg = memp_mallocp(MEMP_API_MSG)) == NULL) { if ((msg = memp_malloc(MEMP_API_MSG)) == NULL) {
return (conn->err = ERR_MEM); return (conn->err = ERR_MEM);
} }
@ -686,7 +686,7 @@ netconn_close(struct netconn *conn)
goto again; goto again;
} }
conn->state = NETCONN_NONE; conn->state = NETCONN_NONE;
memp_freep(MEMP_API_MSG, msg); memp_free(MEMP_API_MSG, msg);
return conn->err; return conn->err;
} }
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/

View File

@ -52,7 +52,7 @@ recv_udp(void *arg, struct udp_pcb *pcb, struct pbuf *p,
return; return;
} }
if (conn->recvmbox != SYS_MBOX_NULL) { if (conn->recvmbox != SYS_MBOX_NULL) {
buf = memp_mallocp(MEMP_NETBUF); buf = memp_malloc(MEMP_NETBUF);
if (buf == NULL) { if (buf == NULL) {
pbuf_free(p); pbuf_free(p);
return; return;
@ -193,7 +193,7 @@ accept_function(void *arg, struct tcp_pcb *newpcb, err_t err)
#endif /* API_MSG_DEBUG */ #endif /* API_MSG_DEBUG */
conn = (struct netconn *)arg; conn = (struct netconn *)arg;
mbox = conn->acceptmbox; mbox = conn->acceptmbox;
newconn = memp_mallocp(MEMP_NETCONN); newconn = memp_malloc(MEMP_NETCONN);
if (newconn == NULL) { if (newconn == NULL) {
return ERR_MEM; return ERR_MEM;
} }

View File

@ -110,7 +110,7 @@ tcpip_thread(void *arg)
default: default:
break; break;
} }
memp_freep(MEMP_TCPIP_MSG, msg); memp_free(MEMP_TCPIP_MSG, msg);
} }
} }
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
@ -119,7 +119,7 @@ tcpip_input(struct pbuf *p, struct netif *inp)
{ {
struct tcpip_msg *msg; struct tcpip_msg *msg;
msg = memp_mallocp(MEMP_TCPIP_MSG); msg = memp_malloc(MEMP_TCPIP_MSG);
if (msg == NULL) { if (msg == NULL) {
pbuf_free(p); pbuf_free(p);
return ERR_MEM; return ERR_MEM;
@ -137,7 +137,7 @@ tcpip_callback(void (*f)(void *ctx), void *ctx)
{ {
struct tcpip_msg *msg; struct tcpip_msg *msg;
msg = memp_mallocp(MEMP_TCPIP_MSG); msg = memp_malloc(MEMP_TCPIP_MSG);
if (msg == NULL) { if (msg == NULL) {
return ERR_MEM; return ERR_MEM;
} }
@ -153,7 +153,7 @@ void
tcpip_apimsg(struct api_msg *apimsg) tcpip_apimsg(struct api_msg *apimsg)
{ {
struct tcpip_msg *msg; struct tcpip_msg *msg;
msg = memp_mallocp(MEMP_TCPIP_MSG); msg = memp_malloc(MEMP_TCPIP_MSG);
if (msg == NULL) { if (msg == NULL) {
memp_free(MEMP_API_MSG, apimsg); memp_free(MEMP_API_MSG, apimsg);
return; return;

View File

@ -182,9 +182,18 @@ memp_malloc(memp_t type)
{ {
struct memp *memp; struct memp *memp;
void *mem; void *mem;
#ifdef SYS_LIGHTWEIGHT_PROT
SYS_ARCH_DECL_PROTECT(old_level);
#endif
LWIP_ASSERT("memp_malloc: type < MEMP_MAX", type < MEMP_MAX); LWIP_ASSERT("memp_malloc: type < MEMP_MAX", type < MEMP_MAX);
#ifdef SYS_LIGHTWEIGHT_PROT
SYS_ARCH_PROTECT(old_level);
#else /* SYS_LIGHTWEIGHT_PROT */
sys_sem_wait(mutex);
#endif /* SYS_LIGHTWEIGHT_PROT */
memp = memp_tab[type]; memp = memp_tab[type];
if (memp != NULL) { if (memp != NULL) {
@ -196,6 +205,11 @@ memp_malloc(memp_t type)
lwip_stats.memp[type].max = lwip_stats.memp[type].used; lwip_stats.memp[type].max = lwip_stats.memp[type].used;
} }
#endif /* MEMP_STATS */ #endif /* MEMP_STATS */
#ifdef SYS_LIGHTWEIGHT_PROT
SYS_ARCH_UNPROTECT(old_level);
#else /* SYS_LIGHTWEIGHT_PROT */
sys_sem_signal(mutex);
#endif /* SYS_LIGHTWEIGHT_PROT */
LWIP_ASSERT("memp_malloc: memp properly aligned", LWIP_ASSERT("memp_malloc: memp properly aligned",
((u32_t)MEM_ALIGN((u8_t *)memp + sizeof(struct memp)) % MEM_ALIGNMENT) == 0); ((u32_t)MEM_ALIGN((u8_t *)memp + sizeof(struct memp)) % MEM_ALIGNMENT) == 0);
@ -208,41 +222,34 @@ memp_malloc(memp_t type)
#ifdef MEMP_STATS #ifdef MEMP_STATS
++lwip_stats.memp[type].err; ++lwip_stats.memp[type].err;
#endif /* MEMP_STATS */ #endif /* MEMP_STATS */
return NULL;
}
}
/*-----------------------------------------------------------------------------------*/
void *
memp_mallocp(memp_t type)
{
void *mem;
#if SYS_LIGHTWEIGHT_PROT
SYS_ARCH_DECL_PROTECT(old_level);
SYS_ARCH_PROTECT(old_level);
#else /* SYS_LIGHTWEIGHT_PROT */
sys_sem_wait(mutex);
#endif /* SYS_LIGHTWEIGHT_PROT */
mem = memp_malloc(type);
#if SYS_LIGHTWEIGHT_PROT #if SYS_LIGHTWEIGHT_PROT
SYS_ARCH_UNPROTECT(old_level); SYS_ARCH_UNPROTECT(old_level);
#else /* SYS_LIGHTWEIGHT_PROT */ #else /* SYS_LIGHTWEIGHT_PROT */
sys_sem_signal(mutex); sys_sem_signal(mutex);
#endif /* SYS_LIGHTWEIGHT_PROT */ #endif /* SYS_LIGHTWEIGHT_PROT */
return mem; return NULL;
}
} }
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
void void
memp_free(memp_t type, void *mem) memp_free(memp_t type, void *mem)
{ {
struct memp *memp; struct memp *memp;
#ifdef SYS_LIGHTWEIGHT_PROT
SYS_ARCH_DECL_PROTECT(old_level);
#endif /* SYS_LIGHTWEIGHT_PROT */
if (mem == NULL) { if (mem == NULL) {
return; return;
} }
memp = (struct memp *)((u8_t *)mem - sizeof(struct memp)); memp = (struct memp *)((u8_t *)mem - sizeof(struct memp));
#ifdef SYS_LIGHTWEIGHT_PROT
SYS_ARCH_PROTECT(old_level);
#else /* SYS_LIGHTWEIGHT_PROT */
sys_sem_wait(mutex);
#endif /* SYS_LIGHTWEIGHT_PROT */
#ifdef MEMP_STATS #ifdef MEMP_STATS
lwip_stats.memp[type].used--; lwip_stats.memp[type].used--;
#endif /* MEMP_STATS */ #endif /* MEMP_STATS */
@ -252,26 +259,10 @@ memp_free(memp_t type, void *mem)
LWIP_ASSERT("memp sanity", memp_sanity()); LWIP_ASSERT("memp sanity", memp_sanity());
return;
}
/*-----------------------------------------------------------------------------------*/
void
memp_freep(memp_t type, void *mem)
{
#if SYS_LIGHTWEIGHT_PROT
SYS_ARCH_DECL_PROTECT(old_level);
SYS_ARCH_PROTECT(old_level);
#else /* SYS_LIGHTWEIGHT_PROT */
sys_sem_wait(mutex);
#endif /* SYS_LIGHTWEIGHT_PROT */
memp_free(type, mem);
#if SYS_LIGHTWEIGHT_PROT #if SYS_LIGHTWEIGHT_PROT
SYS_ARCH_UNPROTECT(old_level); SYS_ARCH_UNPROTECT(old_level);
#else /* SYS_LIGHTWEIGHT_PROT */ #else /* SYS_LIGHTWEIGHT_PROT */
sys_sem_signal(mutex); sys_sem_signal(mutex);
#endif /* SYS_LIGHTWEIGHT_PROT */ #endif /* SYS_LIGHTWEIGHT_PROT */
} }
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/

View File

@ -300,7 +300,7 @@ pbuf_alloc(pbuf_layer l, u16_t length, pbuf_flag flag)
r = q; r = q;
} }
/* end of chain */ /* end of chain */
//r->next = NULL; /*r->next = NULL;*/
break; break;
case PBUF_RAM: case PBUF_RAM:
@ -323,7 +323,7 @@ pbuf_alloc(pbuf_layer l, u16_t length, pbuf_flag flag)
/* pbuf references existing (externally allocated) RAM payload? */ /* pbuf references existing (externally allocated) RAM payload? */
case PBUF_REF: case PBUF_REF:
/* only allocate memory for the pbuf structure */ /* only allocate memory for the pbuf structure */
p = memp_mallocp(MEMP_PBUF); p = memp_malloc(MEMP_PBUF);
if (p == NULL) { if (p == NULL) {
LWIP_DEBUGF(PBUF_DEBUG | DBG_TRACE | 2, ("pbuf_alloc: Could not allocate MEMP_PBUF for PBUF_%s.\n", flag == PBUF_ROM?"ROM":"REF")); LWIP_DEBUGF(PBUF_DEBUG | DBG_TRACE | 2, ("pbuf_alloc: Could not allocate MEMP_PBUF for PBUF_%s.\n", flag == PBUF_ROM?"ROM":"REF"));
return NULL; return NULL;
@ -576,7 +576,7 @@ pbuf_free(struct pbuf *p)
PBUF_POOL_FREE(p); PBUF_POOL_FREE(p);
/* a ROM or RAM referencing pbuf */ /* a ROM or RAM referencing pbuf */
} else if (p->flags == PBUF_FLAG_ROM || p->flags == PBUF_FLAG_REF) { } else if (p->flags == PBUF_FLAG_ROM || p->flags == PBUF_FLAG_REF) {
memp_freep(MEMP_PBUF, p); memp_free(MEMP_PBUF, p);
/* p->flags == PBUF_FLAG_RAM */ /* p->flags == PBUF_FLAG_RAM */
} else { } else {
mem_free(p); mem_free(p);

View File

@ -474,7 +474,7 @@ udp_bind(struct udp_pcb *pcb, struct ip_addr *ipaddr, u16_t port)
listening to broadcast or multicast traffic (See SO_REUSE_ADDR and listening to broadcast or multicast traffic (See SO_REUSE_ADDR and
SO_REUSE_PORT under *BSD). TODO: See where it fits instead, OR SO_REUSE_PORT under *BSD). TODO: See where it fits instead, OR
combine with implementation of UDP PCB flags. Leon Woestenberg. */ combine with implementation of UDP PCB flags. Leon Woestenberg. */
#if 0 #ifdef LWIP_UDP_TODO
/* port matches that of PCB in list? */ /* port matches that of PCB in list? */
else if ((ipcb->local_port == port) && else if ((ipcb->local_port == port) &&
/* IP address matches, or one is IP_ADDR_ANY? */ /* IP address matches, or one is IP_ADDR_ANY? */
@ -552,7 +552,7 @@ udp_connect(struct udp_pcb *pcb, struct ip_addr *ipaddr, u16_t port)
pcb->remote_port = port; pcb->remote_port = port;
pcb->flags |= UDP_FLAGS_CONNECTED; pcb->flags |= UDP_FLAGS_CONNECTED;
/** TODO: this functionality belongs in upper layers */ /** TODO: this functionality belongs in upper layers */
#if 0 #ifdef LWIP_UDP_TODO
/* Nail down local IP for netconn_addr()/getsockname() */ /* Nail down local IP for netconn_addr()/getsockname() */
if (ip_addr_isany(&pcb->local_ip) && !ip_addr_isany(&pcb->remote_ip)) { if (ip_addr_isany(&pcb->local_ip) && !ip_addr_isany(&pcb->remote_ip)) {
struct netif *netif; struct netif *netif;

View File

@ -67,6 +67,13 @@ u8_t *inet_ntoa(u32_t addr); /* returns ptr to static buffer; not reentrant! */
#define htonl(x) (x) #define htonl(x) (x)
#define ntohl(x) (x) #define ntohl(x) (x)
#else #else
#ifdef LWIP_PREFIX_BYTEORDER_FUNCS
/* workaround for naming collisions on some platforms */
#define htons lwip_htons
#define ntohs lwip_ntohs
#define htonl lwip_htonl
#define ntohl lwip_ntohl
#endif
u16_t htons(u16_t x); u16_t htons(u16_t x);
u16_t ntohs(u16_t x); u16_t ntohs(u16_t x);
u32_t htonl(u32_t x); u32_t htonl(u32_t x);

View File

@ -58,8 +58,5 @@ void *memp_malloc(memp_t type);
void *memp_realloc(memp_t fromtype, memp_t totype, void *mem); void *memp_realloc(memp_t fromtype, memp_t totype, void *mem);
void memp_free(memp_t type, void *mem); void memp_free(memp_t type, void *mem);
void *memp_mallocp(memp_t type);
void memp_freep(memp_t type, void *mem);
#endif /* __LWIP_MEMP_H__ */ #endif /* __LWIP_MEMP_H__ */

View File

@ -38,8 +38,6 @@
#include "lwip/inet.h" #include "lwip/inet.h"
#include "lwip/ip.h" #include "lwip/ip.h"
#include "lwip/err.h"
#define UDP_HLEN 8 #define UDP_HLEN 8
struct udp_hdr { struct udp_hdr {

View File

@ -122,7 +122,7 @@ static int get_pap_passwd (int, char *, char *);
static int have_pap_secret (void); static int have_pap_secret (void);
static int have_chap_secret (char *, char *, u32_t); static int have_chap_secret (char *, char *, u32_t);
static int ip_addr_check (u32_t, struct wordlist *); static int ip_addr_check (u32_t, struct wordlist *);
#if PAP_SUPPORT > 0 || CHAP_SUPPORT > 0 #if 0 /* PAP_SUPPORT > 0 || CHAP_SUPPORT > 0 */
static void set_allowed_addrs(int unit, struct wordlist *addrs); static void set_allowed_addrs(int unit, struct wordlist *addrs);
static void free_wordlist (struct wordlist *); static void free_wordlist (struct wordlist *);
#endif #endif
@ -476,7 +476,7 @@ void auth_reset(int unit)
AUTHDEBUG((LOG_INFO, "auth_reset: %d\n", unit)); AUTHDEBUG((LOG_INFO, "auth_reset: %d\n", unit));
ao->neg_upap = !ppp_settings.refuse_pap && (ppp_settings.passwd[0] != 0 || get_pap_passwd(unit, NULL, NULL)); ao->neg_upap = !ppp_settings.refuse_pap && (ppp_settings.passwd[0] != 0 || get_pap_passwd(unit, NULL, NULL));
ao->neg_chap = !ppp_settings.refuse_chap && have_chap_secret(ppp_settings.user, ppp_settings.remote_name, (u32_t)0); ao->neg_chap = !ppp_settings.refuse_chap && ppp_settings.passwd[0] != 0 /*have_chap_secret(ppp_settings.user, ppp_settings.remote_name, (u32_t)0)*/;
if (go->neg_upap && !have_pap_secret()) if (go->neg_upap && !have_pap_secret())
go->neg_upap = 0; go->neg_upap = 0;
@ -605,7 +605,24 @@ int get_secret(
) )
{ {
#if 1 #if 1
int len;
struct wordlist *addrs;
addrs = NULL;
if(!client || !client[0] && strcmp(client, ppp_settings.user)) {
return 0; return 0;
}
len = strlen(ppp_settings.passwd);
if (len > MAXSECRETLEN) {
ppp_trace(LOG_ERR, "Secret for %s on %s is too long\n", client, server);
len = MAXSECRETLEN;
}
BCOPY(ppp_settings.passwd, secret, len);
*secret_len = len;
return 1;
#else #else
int ret = 0, len; int ret = 0, len;
struct wordlist *addrs; struct wordlist *addrs;
@ -841,7 +858,7 @@ static int have_chap_secret(char *client, char *server, u32_t remote)
} }
#if PAP_SUPPORT > 0 || CHAP_SUPPORT > 0 #if 0 /* PAP_SUPPORT > 0 || CHAP_SUPPORT > 0 */
/* /*
* set_allowed_addrs() - set the list of allowed addresses. * set_allowed_addrs() - set the list of allowed addresses.
*/ */
@ -891,7 +908,7 @@ static int ip_addr_check(u32_t addr, struct wordlist *addrs)
return 1; return 1;
} }
#if PAP_SUPPORT > 0 || CHAP_SUPPORT #if 0 /* PAP_SUPPORT > 0 || CHAP_SUPPORT */
/* /*
* free_wordlist - release memory allocated for a wordlist. * free_wordlist - release memory allocated for a wordlist.
*/ */

View File

@ -290,7 +290,7 @@ void pppInit(void)
memset(&ppp_settings, 0, sizeof(ppp_settings)); memset(&ppp_settings, 0, sizeof(ppp_settings));
ppp_settings.usepeerdns = 1; ppp_settings.usepeerdns = 1;
ppp_settings.refuse_chap = (CHAP_SUPPORT == 0); pppSetAuth(PPPAUTHTYPE_NONE, NULL, NULL);
magicInit(); magicInit();
@ -313,19 +313,40 @@ void pppInit(void)
#endif #endif
} }
void pppSetAuth(const char *user, const char *passwd) void pppSetAuth(enum pppAuthType authType, const char *user, const char *passwd)
{ {
if(user) { switch(authType) {
strncpy(ppp_settings.user, user, sizeof(ppp_settings.user)-1); case PPPAUTHTYPE_NONE:
ppp_settings.user[sizeof(ppp_settings.user)-1] = '\0'; default:
} else #ifdef LWIP_PPP_STRICT_PAP_REJECT
ppp_settings.user[0] = '\0'; ppp_settings.refuse_pap = 1;
#else
/* some providers request pap and accept an empty login/pw */
ppp_settings.refuse_pap = 0;
#endif
ppp_settings.refuse_chap = 1;
break;
case PPPAUTHTYPE_PAP:
ppp_settings.refuse_pap = 0;
ppp_settings.refuse_chap = 1;
break;
case PPPAUTHTYPE_CHAP:
ppp_settings.refuse_pap = 1;
ppp_settings.refuse_chap = 0;
break;
}
if(passwd) { if(user) {
strncpy(ppp_settings.passwd, passwd, sizeof(ppp_settings.passwd)-1); strncpy(ppp_settings.user, user, sizeof(ppp_settings.user)-1);
ppp_settings.passwd[sizeof(ppp_settings.passwd)-1] = '\0'; ppp_settings.user[sizeof(ppp_settings.user)-1] = '\0';
} else } else
ppp_settings.passwd[0] = '\0'; ppp_settings.user[0] = '\0';
if(passwd) {
strncpy(ppp_settings.passwd, passwd, sizeof(ppp_settings.passwd)-1);
ppp_settings.passwd[sizeof(ppp_settings.passwd)-1] = '\0';
} else
ppp_settings.passwd[0] = '\0';
} }
/* Open a new PPP connection using the given I/O device. /* Open a new PPP connection using the given I/O device.

View File

@ -313,7 +313,7 @@ struct ppp_settings {
int maxconnect; /* Maximum connect time (seconds) */ int maxconnect; /* Maximum connect time (seconds) */
char user[MAXNAMELEN + 1];/* Username for PAP */ char user[MAXNAMELEN + 1];/* Username for PAP */
char passwd[MAXNAMELEN + 1]; /* Password for PAP */ char passwd[MAXSECRETLEN + 1]; /* Password for PAP, secret for CHAP */
char our_name[MAXNAMELEN + 1]; /* Our name for authentication purposes */ char our_name[MAXNAMELEN + 1]; /* Our name for authentication purposes */
char remote_name[MAXNAMELEN + 1]; /* Peer's name for authentication */ char remote_name[MAXNAMELEN + 1]; /* Peer's name for authentication */
}; };
@ -340,7 +340,13 @@ extern struct protent *ppp_protocols[];/* Table of pointers to supported protoco
/* Initialize the PPP subsystem. */ /* Initialize the PPP subsystem. */
void pppInit(void); void pppInit(void);
void pppSetAuth(const char *user, const char *passwd); enum pppAuthType {
PPPAUTHTYPE_NONE,
PPPAUTHTYPE_PAP,
PPPAUTHTYPE_CHAP
};
void pppSetAuth(enum pppAuthType authType, const char *user, const char *passwd);
/* /*
* Open a new PPP connection using the given I/O device. * Open a new PPP connection using the given I/O device.