mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2025-01-30 12:32:37 +00:00
opt.h, ip_frag.h, tcpip.h, tcpip.c, ethernetif.c: add new configuration option named ETHARP_TCPIP_ETHINPUT, which enable the new tcpip_ethinput. Allow to do ARP processing for incoming packets inside tcpip_thread (protecting ARP layer against concurrent access). You can also disable old code using tcp_input with new define ETHARP_TCPIP_INPUT set to 0. Older ports have to use tcpip_ethinput.
This commit is contained in:
parent
7115975212
commit
ed07d481d6
12
CHANGELOG
12
CHANGELOG
@ -5,10 +5,6 @@ FUTURE
|
||||
problems with exoteric (/DSP) architectures showing these problems.
|
||||
We still have to fix some of these issues neatly.
|
||||
|
||||
* TODO: the ARP layer is not protected against concurrent access. If
|
||||
you run from a multitasking OS, serialize access to ARP (called from
|
||||
your network device driver and from a timeout thread.)
|
||||
|
||||
* TODO: the PPP code is broken in a few ways. There are namespace
|
||||
collisions on BSD systems and many assumptions on word-length
|
||||
(sizeof(int)). In ppp.c an assumption is made on the availability of
|
||||
@ -42,6 +38,14 @@ HISTORY
|
||||
|
||||
++ Bug fixes:
|
||||
|
||||
2007-03-06 Frédéric Bernon, Simon Goldschmidt
|
||||
* opt.h, ip_frag.h, tcpip.h, tcpip.c, ethernetif.c: add new configuration
|
||||
option named ETHARP_TCPIP_ETHINPUT, which enable the new tcpip_ethinput.
|
||||
Allow to do ARP processing for incoming packets inside tcpip_thread
|
||||
(protecting ARP layer against concurrent access). You can also disable
|
||||
old code using tcp_input with new define ETHARP_TCPIP_INPUT set to 0.
|
||||
Older ports have to use tcpip_ethinput.
|
||||
|
||||
2007-03-06 Simon Goldschmidt (based on patch from Dmitry Potapov)
|
||||
* err.h, err.c: fixed compiler warning "initialization dircards qualifiers
|
||||
from pointer target type"
|
||||
|
@ -37,6 +37,8 @@
|
||||
#include "lwip/memp.h"
|
||||
#include "lwip/pbuf.h"
|
||||
|
||||
#include "netif/etharp.h"
|
||||
|
||||
#include "lwip/ip.h"
|
||||
#include "lwip/ip_frag.h"
|
||||
#include "lwip/udp.h"
|
||||
@ -88,18 +90,67 @@ ip_timer(void *data)
|
||||
{
|
||||
LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip: ip_reass_tmr()\n"));
|
||||
ip_reass_tmr();
|
||||
sys_timeout(1000, ip_timer, NULL);
|
||||
sys_timeout( IP_TMR_INTERVAL, ip_timer, NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
arp_timer(void *arg)
|
||||
{
|
||||
LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip: etharp_tmr()\n"));
|
||||
etharp_tmr();
|
||||
sys_timeout( ARP_TMR_INTERVAL, arp_timer, NULL);
|
||||
}
|
||||
|
||||
#if ETHARP_TCPIP_ETHINPUT
|
||||
static void
|
||||
ethernet_input(struct pbuf *p, struct netif *netif)
|
||||
{
|
||||
struct eth_hdr* ethhdr;
|
||||
|
||||
/* points to packet payload, which starts with an Ethernet header */
|
||||
ethhdr = p->payload;
|
||||
|
||||
#if LINK_STATS
|
||||
lwip_stats.link.recv++;
|
||||
#endif /* LINK_STATS */
|
||||
|
||||
switch (htons(ethhdr->type)) {
|
||||
/* IP packet? */
|
||||
case ETHTYPE_IP:
|
||||
#if ETHARP_TRUST_IP_MAC
|
||||
/* update ARP table */
|
||||
etharp_ip_input( netif, p);
|
||||
#endif
|
||||
/* skip Ethernet header */
|
||||
pbuf_header(p, -sizeof(struct eth_hdr));
|
||||
/* pass to IP layer */
|
||||
ip_input(p, netif);
|
||||
break;
|
||||
|
||||
case ETHTYPE_ARP:
|
||||
/* pass p to ARP module */
|
||||
etharp_arp_input(netif, (struct eth_addr*)(netif->hwaddr), p);
|
||||
break;
|
||||
|
||||
default:
|
||||
pbuf_free(p);
|
||||
p = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif /* ETHARP_TCPIP_ETHINPUT */
|
||||
|
||||
static void
|
||||
tcpip_thread(void *arg)
|
||||
{
|
||||
struct tcpip_msg *msg;
|
||||
|
||||
#if IP_REASSEMBLY
|
||||
sys_timeout(1000, ip_timer, NULL);
|
||||
sys_timeout( IP_TMR_INTERVAL, ip_timer, NULL);
|
||||
#endif
|
||||
sys_timeout( ARP_TMR_INTERVAL, arp_timer, NULL);
|
||||
|
||||
if (tcpip_init_done != NULL) {
|
||||
tcpip_init_done(tcpip_init_done_arg);
|
||||
}
|
||||
@ -111,10 +162,21 @@ tcpip_thread(void *arg)
|
||||
LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: API message %p\n", (void *)msg));
|
||||
api_msg_input(msg->msg.apimsg);
|
||||
break;
|
||||
|
||||
#if ETHARP_TCPIP_INPUT
|
||||
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);
|
||||
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);
|
||||
break;
|
||||
#endif /* ETHARP_TCPIP_ETHINPUT */
|
||||
|
||||
case TCPIP_MSG_CALLBACK:
|
||||
LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: CALLBACK %p\n", (void *)msg));
|
||||
msg->msg.cb.f(msg->msg.cb.ctx);
|
||||
@ -126,6 +188,7 @@ tcpip_thread(void *arg)
|
||||
}
|
||||
}
|
||||
|
||||
#if ETHARP_TCPIP_INPUT
|
||||
err_t
|
||||
tcpip_input(struct pbuf *p, struct netif *inp)
|
||||
{
|
||||
@ -143,6 +206,27 @@ tcpip_input(struct pbuf *p, struct netif *inp)
|
||||
sys_mbox_post(mbox, msg);
|
||||
return ERR_OK;
|
||||
}
|
||||
#endif /* ETHARP_TCPIP_INPUT */
|
||||
|
||||
#if ETHARP_TCPIP_ETHINPUT
|
||||
err_t
|
||||
tcpip_ethinput(struct pbuf *p, struct netif *inp)
|
||||
{
|
||||
struct tcpip_msg *msg;
|
||||
|
||||
msg = memp_malloc(MEMP_TCPIP_MSG);
|
||||
if (msg == NULL) {
|
||||
pbuf_free(p);
|
||||
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;
|
||||
}
|
||||
#endif /* ETHARP_TCPIP_ETHINPUT */
|
||||
|
||||
err_t
|
||||
tcpip_callback(void (*f)(void *ctx), void *ctx)
|
||||
|
@ -39,6 +39,9 @@
|
||||
#include "lwip/netif.h"
|
||||
#include "lwip/ip_addr.h"
|
||||
|
||||
/* The IP timer interval in milliseconds. */
|
||||
#define IP_TMR_INTERVAL 1000
|
||||
|
||||
void ip_frag_init(void);
|
||||
void ip_reass_tmr(void);
|
||||
struct pbuf * ip_reass(struct pbuf *p);
|
||||
|
@ -199,6 +199,16 @@ a lot of data that needs to be copied, this should be set high. */
|
||||
#define ETHARP_TRUST_IP_MAC 1
|
||||
#endif
|
||||
|
||||
/* If enabled, allow to do ARP processing for incoming packets inside network driver, before process packets using the tcpip_input. */
|
||||
#ifndef ETHARP_TCPIP_INPUT
|
||||
#define ETHARP_TCPIP_INPUT 1
|
||||
#endif
|
||||
|
||||
/* If enabled, allow to do ARP processing for incoming packets inside tcpip_thread, using the tcpip_ethinput (and not tcpip_input).
|
||||
The aim is to protect ARP layer against concurrent access. Older ports have to be update to use tcpip_ethinput. */
|
||||
#ifndef ETHARP_TCPIP_ETHINPUT
|
||||
#define ETHARP_TCPIP_ETHINPUT 1
|
||||
#endif
|
||||
|
||||
/* This option is deprecated */
|
||||
#ifdef ETHARP_QUEUE_FIRST
|
||||
|
@ -37,14 +37,24 @@
|
||||
|
||||
void tcpip_init(void (* tcpip_init_done)(void *), void *arg);
|
||||
void tcpip_apimsg(struct api_msg *apimsg);
|
||||
#if ETHARP_TCPIP_INPUT
|
||||
err_t tcpip_input(struct pbuf *p, struct netif *inp);
|
||||
#endif /* ETHARP_TCPIP_INPUT */
|
||||
#if ETHARP_TCPIP_ETHINPUT
|
||||
err_t tcpip_ethinput(struct pbuf *p, struct netif *inp);
|
||||
#endif /* ETHARP_TCPIP_ETHINPUT */
|
||||
err_t tcpip_callback(void (*f)(void *ctx), void *ctx);
|
||||
|
||||
void tcpip_tcp_timer_needed(void);
|
||||
|
||||
enum tcpip_msg_type {
|
||||
TCPIP_MSG_API,
|
||||
#if ETHARP_TCPIP_INPUT
|
||||
TCPIP_MSG_INPUT,
|
||||
#endif /* ETHARP_TCPIP_INPUT */
|
||||
#if ETHARP_TCPIP_ETHINPUT
|
||||
TCPIP_MSG_ETHINPUT,
|
||||
#endif /* ETHARP_TCPIP_ETHINPUT */
|
||||
TCPIP_MSG_CALLBACK
|
||||
};
|
||||
|
||||
|
@ -237,24 +237,39 @@ ethernetif_input(struct netif *netif)
|
||||
ethhdr = p->payload;
|
||||
|
||||
switch (htons(ethhdr->type)) {
|
||||
|
||||
#if ETHARP_TCPIP_ETHINPUT
|
||||
/* IP or ARP packet? */
|
||||
case ETHTYPE_IP:
|
||||
case ETHTYPE_ARP:
|
||||
/* full packet send to tcpip_thread to process */
|
||||
pnetif->input( p, pnetif);
|
||||
break;
|
||||
|
||||
#else /* ETHARP_TCPIP_ETHINPUT */
|
||||
#if ETHARP_TCPIP_INPUT
|
||||
|
||||
/* IP packet? */
|
||||
case ETHTYPE_IP:
|
||||
#if 0
|
||||
/* CSi disabled ARP table update on ingress IP packets.
|
||||
This seems to work but needs thorough testing. */
|
||||
#if ETHARP_TRUST_IP_MAC
|
||||
/* update ARP table */
|
||||
etharp_ip_input(netif, p);
|
||||
#endif
|
||||
#endif /* ETHARP_TRUST_IP_MAC */
|
||||
/* skip Ethernet header */
|
||||
pbuf_header(p, -sizeof(struct eth_hdr));
|
||||
/* pass to network layer */
|
||||
netif->input(p, netif);
|
||||
break;
|
||||
|
||||
/* ARP packet? */
|
||||
case ETHTYPE_ARP:
|
||||
/* pass p to ARP module */
|
||||
etharp_arp_input(netif, ethernetif->ethaddr, p);
|
||||
break;
|
||||
|
||||
#endif /* ETHARP_TCPIP_INPUT */
|
||||
#endif /* ETHARP_TCPIP_ETHINPUT */
|
||||
|
||||
default:
|
||||
pbuf_free(p);
|
||||
p = NULL;
|
||||
@ -262,13 +277,6 @@ ethernetif_input(struct netif *netif)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
arp_timer(void *arg)
|
||||
{
|
||||
etharp_tmr();
|
||||
sys_timeout(ARP_TMR_INTERVAL, arp_timer, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* ethernetif_init():
|
||||
*
|
||||
@ -317,10 +325,6 @@ ethernetif_init(struct netif *netif)
|
||||
|
||||
low_level_init(netif);
|
||||
|
||||
etharp_init();
|
||||
|
||||
sys_timeout(ARP_TMR_INTERVAL, arp_timer, NULL);
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user