Added distinct memp (MEMP_TCPIP_MSG_INPUT) for input packets to prevent

floods from consuming all of MEMP_TCPIP_MSG and starving other message types.
This commit is contained in:
marcbou 2007-08-16 19:49:08 +00:00
parent 58bfb0458e
commit 1b98df4a0d
4 changed files with 35 additions and 29 deletions

View File

@ -310,21 +310,13 @@ tcpip_thread(void *arg)
msg->msg.apimsg->function(&(msg->msg.apimsg->msg));
break;
#if ETHARP_TCPIP_INPUT
#if ETHARP_TCPIP_INPUT || ETHARP_TCPIP_ETHINPUT
case TCPIP_MSG_INPUT:
LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: IP packet %p\n", (void *)msg));
ip_input(msg->msg.inp.p, msg->msg.inp.netif);
memp_free(MEMP_TCPIP_MSG, msg);
LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: PACKET %p\n", (void *)msg));
msg->msg.inp.f(msg->msg.inp.p, msg->msg.inp.netif);
memp_free(MEMP_TCPIP_MSG_INPUT, msg);
break;
#endif /* ETHARP_TCPIP_INPUT */
#if ETHARP_TCPIP_ETHINPUT
case TCPIP_MSG_ETHINPUT:
LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: Ethernet packet %p\n", (void *)msg));
ethernet_input(msg->msg.inp.p, msg->msg.inp.netif);
memp_free(MEMP_TCPIP_MSG, msg);
break;
#endif /* ETHARP_TCPIP_ETHINPUT */
#endif /* ETHARP_TCPIP_INPUT || ETHARP_TCPIP_ETHINPUT */
#if LWIP_NETIF_API
case TCPIP_MSG_NETIFAPI:
@ -345,6 +337,7 @@ tcpip_thread(void *arg)
sys_timeout (msg->msg.tmo.msecs, msg->msg.tmo.h, msg->msg.tmo.arg);
else
sys_untimeout (msg->msg.tmo.h, msg->msg.tmo.arg);
memp_free(MEMP_TCPIP_MSG, msg);
break;
default:
break;
@ -365,12 +358,34 @@ tcpip_input(struct pbuf *p, struct netif *inp)
struct tcpip_msg *msg;
if (mbox != SYS_MBOX_NULL) {
msg = memp_malloc(MEMP_TCPIP_MSG);
msg = memp_malloc(MEMP_TCPIP_MSG_INPUT);
if (msg == NULL) {
return ERR_MEM;
}
msg->type = TCPIP_MSG_INPUT;
msg->msg.inp.f = ip_input;
msg->msg.inp.p = p;
msg->msg.inp.netif = inp;
sys_mbox_post(mbox, msg);
return ERR_OK;
}
return ERR_VAL;
}
err_t
tcpip_input_callback(struct pbuf *p, struct netif *inp, err_t (*f)(struct pbuf *, struct netif *))
{
struct tcpip_msg *msg;
if (mbox != SYS_MBOX_NULL) {
msg = memp_malloc(MEMP_TCPIP_MSG_INPUT);
if (msg == NULL) {
return ERR_MEM;
}
msg->type = TCPIP_MSG_INPUT;
msg->msg.inp.f = f;
msg->msg.inp.p = p;
msg->msg.inp.netif = inp;
sys_mbox_post(mbox, msg);
@ -390,21 +405,7 @@ tcpip_input(struct pbuf *p, struct netif *inp)
err_t
tcpip_ethinput(struct pbuf *p, struct netif *inp)
{
struct tcpip_msg *msg;
if (mbox != SYS_MBOX_NULL) {
msg = memp_malloc(MEMP_TCPIP_MSG);
if (msg == NULL) {
return ERR_MEM;
}
msg->type = TCPIP_MSG_ETHINPUT;
msg->msg.inp.p = p;
msg->msg.inp.netif = inp;
sys_mbox_post(mbox, msg);
return ERR_OK;
}
return ERR_VAL;
return tcpip_input_callback(p, inp, ethernet_input);
}
#endif /* ETHARP_TCPIP_ETHINPUT */

View File

@ -118,6 +118,7 @@ const u16_t memp_sizes[MEMP_MAX] = {
MEMP_ALIGN_SIZE(sizeof(struct netbuf)),
MEMP_ALIGN_SIZE(sizeof(struct netconn)),
MEMP_ALIGN_SIZE(sizeof(struct tcpip_msg)),
MEMP_ALIGN_SIZE(sizeof(struct tcpip_msg)),
#if ARP_QUEUEING
MEMP_ALIGN_SIZE(sizeof(struct etharp_q_entry)),
#endif
@ -141,6 +142,7 @@ static const u16_t memp_num[MEMP_MAX] = {
MEMP_NUM_NETBUF,
MEMP_NUM_NETCONN,
MEMP_NUM_TCPIP_MSG,
MEMP_NUM_TCPIP_MSG_INPUT,
#if ARP_QUEUEING
MEMP_NUM_ARP_QUEUE,
#endif
@ -167,6 +169,7 @@ static u8_t memp_memory[MEM_ALIGNMENT - 1 +
MEMP_TYPE_SIZE(MEMP_NUM_NETBUF, struct netbuf) +
MEMP_TYPE_SIZE(MEMP_NUM_NETCONN, struct netconn) +
MEMP_TYPE_SIZE(MEMP_NUM_TCPIP_MSG, struct tcpip_msg) +
MEMP_TYPE_SIZE(MEMP_NUM_TCPIP_MSG_INPUT, struct tcpip_msg) +
#if ARP_QUEUEING
MEMP_TYPE_SIZE(MEMP_NUM_ARP_QUEUE, struct etharp_q_entry) +
#endif

View File

@ -51,6 +51,7 @@ typedef enum {
MEMP_NETBUF,
MEMP_NETCONN,
MEMP_TCPIP_MSG,
MEMP_TCPIP_MSG_INPUT,
#if ARP_QUEUEING
MEMP_ARP_QUEUE,
#endif

View File

@ -66,6 +66,7 @@ err_t tcpip_apimsg_lock(struct api_msg *apimsg);
#if ETHARP_TCPIP_INPUT
err_t tcpip_input(struct pbuf *p, struct netif *inp);
err_t tcpip_input_callback(struct pbuf *p, struct netif *inp, err_t (*f)(struct pbuf *, struct netif *));
#endif /* ETHARP_TCPIP_INPUT */
#if ETHARP_TCPIP_ETHINPUT