mirror of
https://git.savannah.nongnu.org/git/lwip.git
synced 2026-08-09 17:13:49 +08:00
Add the following features and bugfixes:
Added select() functionality to sockets library. Support for errno in sockets library. Byte ordering fixes. basic lwip_ioctl(), FIONREAD, get/setsockopt() etc. support - added additional argument to netif_add to pass state pointer so that the if_init function has access to context information before the interface is added, without accessing globals. - added netif_remove() - to conserve cpu load the tcpip_tcp_timer should only be active when tcbs that need it exist. - pass length of available data to callbacks for NETCONN_EVT_RCV events - added tcpip_link_input(), a hack to allow processing of PPP packets in tcpip_thread() context. This saves threads and context switches. - renamed incompatible ASSERT() macro to LWIP_ASSERT() to avoid name collision. - changed a bunch of %d's to %u's in format strings for unsigned values. - added ip_frag to lwip_stats. - changed IP_REASS_MAXAGE and IP_REASS_TMO defaults to more realistic values. - added sys_timeout_remove() function to cancel timeouts (needed by PPP amongst other things). - tolerate NULL returns from sys_arch_timeouts() since some threads might not need to use or have timeouts. - added sys_sem_wait_timeout() - moved mem_malloc() function to end of mem.c to work around tasking compiler bug. - automatically bind to local tcp port if 0. - allow customization of port ranges for automatic local bindings. - corrected various typos, spelling errors, etc.. Thanks to Marc Boucher for many of these changes.
This commit is contained in:
@@ -371,6 +371,7 @@ ip_input(struct pbuf *p, struct netif *inp) {
|
||||
|
||||
#if IP_REASSEMBLY
|
||||
if((IPH_OFFSET(iphdr) & htons(IP_OFFMASK | IP_MF)) != 0) {
|
||||
DEBUGF(IP_DEBUG, ("IP packet is a fragment (id=0x%04x tot_len=%u len=%u MF=%u offset=%u), calling ip_reass()\n", ntohs(IPH_ID(iphdr)), p->tot_len, ntohs(IPH_LEN(iphdr)), !!(IPH_OFFSET(iphdr) & htons(IP_MF)), (ntohs(IPH_OFFSET(iphdr)) & IP_OFFMASK))*8);
|
||||
p = ip_reass(p);
|
||||
if(p == NULL) {
|
||||
return ERR_OK;
|
||||
@@ -523,7 +524,8 @@ ip_output_if(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
|
||||
}
|
||||
|
||||
#if IP_FRAG
|
||||
if (p->tot_len > netif->mtu)
|
||||
/* don't fragment if interface has mtu set to 0 [loopif] */
|
||||
if (netif->mtu && (p->tot_len > netif->mtu))
|
||||
return ip_frag(p,netif,dest);
|
||||
#endif
|
||||
|
||||
@@ -578,20 +580,20 @@ ip_debug_print(struct pbuf *p)
|
||||
|
||||
DEBUGF(IP_DEBUG, ("IP header:\n"));
|
||||
DEBUGF(IP_DEBUG, ("+-------------------------------+\n"));
|
||||
DEBUGF(IP_DEBUG, ("|%2d |%2d | %2d | %4d | (v, hl, tos, len)\n",
|
||||
DEBUGF(IP_DEBUG, ("|%2d |%2d | %2u | %4u | (v, hl, tos, len)\n",
|
||||
IPH_V(iphdr),
|
||||
IPH_HL(iphdr),
|
||||
IPH_TOS(iphdr),
|
||||
ntohs(IPH_LEN(iphdr))));
|
||||
DEBUGF(IP_DEBUG, ("+-------------------------------+\n"));
|
||||
DEBUGF(IP_DEBUG, ("| %5d |%d%d%d| %4d | (id, flags, offset)\n",
|
||||
DEBUGF(IP_DEBUG, ("| %5u |%u%u%u| %4u | (id, flags, offset)\n",
|
||||
ntohs(IPH_ID(iphdr)),
|
||||
ntohs(IPH_OFFSET(iphdr)) >> 15 & 1,
|
||||
ntohs(IPH_OFFSET(iphdr)) >> 14 & 1,
|
||||
ntohs(IPH_OFFSET(iphdr)) >> 13 & 1,
|
||||
ntohs(IPH_OFFSET(iphdr)) & IP_OFFMASK));
|
||||
DEBUGF(IP_DEBUG, ("+-------------------------------+\n"));
|
||||
DEBUGF(IP_DEBUG, ("| %2d | %2d | 0x%04x | (ttl, proto, chksum)\n",
|
||||
DEBUGF(IP_DEBUG, ("| %2u | %2u | 0x%04x | (ttl, proto, chksum)\n",
|
||||
IPH_TTL(iphdr),
|
||||
IPH_PROTO(iphdr),
|
||||
ntohs(IPH_CHKSUM(iphdr))));
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
#include "lwip/ip_frag.h"
|
||||
#include "lwip/netif.h"
|
||||
|
||||
#include "lwip/stats.h"
|
||||
|
||||
|
||||
/*
|
||||
@@ -74,8 +75,8 @@ copy_from_pbuf(struct pbuf *p, u16_t * offset,
|
||||
}
|
||||
|
||||
#define IP_REASS_BUFSIZE 5760
|
||||
#define IP_REASS_MAXAGE 10
|
||||
#define IP_REASS_TMO 100
|
||||
#define IP_REASS_MAXAGE 30
|
||||
#define IP_REASS_TMO 1000
|
||||
|
||||
static u8_t ip_reassbuf[IP_HLEN + IP_REASS_BUFSIZE];
|
||||
static u8_t ip_reassbitmap[IP_REASS_BUFSIZE / (8 * 8)];
|
||||
@@ -92,9 +93,11 @@ static u8_t ip_reasstmr;
|
||||
static void
|
||||
ip_reass_timer(void *arg)
|
||||
{
|
||||
if(ip_reasstmr)
|
||||
if(ip_reasstmr > 1) {
|
||||
ip_reasstmr--;
|
||||
sys_timeout(IP_REASS_TMO, (sys_timeout_handler) ip_reass_timer, NULL);
|
||||
sys_timeout(IP_REASS_TMO, (sys_timeout_handler) ip_reass_timer, NULL);
|
||||
} else if(ip_reasstmr == 1)
|
||||
ip_reasstmr = 0;
|
||||
}
|
||||
|
||||
struct pbuf *
|
||||
@@ -105,6 +108,10 @@ ip_reass(struct pbuf *p)
|
||||
u16_t offset, len;
|
||||
u16_t i;
|
||||
|
||||
#ifdef IP_STATS
|
||||
++lwip_stats.ip_frag.recv;
|
||||
#endif /* IP_STATS */
|
||||
|
||||
iphdr = (struct ip_hdr *) ip_reassbuf;
|
||||
fraghdr = (struct ip_hdr *) p->payload;
|
||||
/* If ip_reasstmr is zero, no packet is present in the buffer, so we
|
||||
@@ -127,6 +134,9 @@ ip_reass(struct pbuf *p)
|
||||
ip_addr_cmp(&iphdr->dest, &fraghdr->dest) &&
|
||||
IPH_ID(iphdr) == IPH_ID(fraghdr)) {
|
||||
DEBUGF(IP_REASS_DEBUG, ("ip_reass: matching old packet\n"));
|
||||
#ifdef IP_STATS
|
||||
++lwip_stats.ip_frag.cachehit;
|
||||
#endif /* IP_STATS */
|
||||
/* Find out the offset in the reassembly buffer where we should
|
||||
copy the fragment. */
|
||||
len = ntohs(IPH_LEN(fraghdr)) - IPH_HL(fraghdr) * 4;
|
||||
@@ -138,6 +148,7 @@ ip_reass(struct pbuf *p)
|
||||
DEBUGF(IP_REASS_DEBUG,
|
||||
("ip_reass: fragment outside of buffer (%d:%d/%d).\n", offset,
|
||||
offset + len, IP_REASS_BUFSIZE));
|
||||
sys_timeout_remove((sys_timeout_handler) ip_reass_timer, NULL);
|
||||
ip_reasstmr = 0;
|
||||
goto nullreturn;
|
||||
}
|
||||
@@ -225,6 +236,7 @@ ip_reass(struct pbuf *p)
|
||||
/* If we have come this far, we have a full packet in the
|
||||
buffer, so we allocate a pbuf and copy the packet into it. We
|
||||
also reset the timer. */
|
||||
sys_timeout_remove((sys_timeout_handler) ip_reass_timer, NULL);
|
||||
ip_reasstmr = 0;
|
||||
pbuf_free(p);
|
||||
p = pbuf_alloc(PBUF_LINK, ip_reasslen, PBUF_POOL);
|
||||
@@ -242,6 +254,13 @@ ip_reass(struct pbuf *p)
|
||||
q->len > ip_reasslen - i ? ip_reasslen - i : q->len);
|
||||
i += q->len;
|
||||
}
|
||||
#ifdef IP_STATS
|
||||
++lwip_stats.ip_frag.fw;
|
||||
#endif /* IP_STATS */
|
||||
} else {
|
||||
#ifdef IP_STATS
|
||||
++lwip_stats.ip_frag.memerr;
|
||||
#endif /* IP_STATS */
|
||||
}
|
||||
DEBUGF(IP_REASS_DEBUG, ("ip_reass: p %p\n", (void*)p));
|
||||
return p;
|
||||
@@ -249,6 +268,9 @@ ip_reass(struct pbuf *p)
|
||||
}
|
||||
|
||||
nullreturn:
|
||||
#ifdef IP_STATS
|
||||
++lwip_stats.ip_frag.drop;
|
||||
#endif /* IP_STATS */
|
||||
pbuf_free(p);
|
||||
return NULL;
|
||||
}
|
||||
@@ -324,6 +346,9 @@ ip_frag(struct pbuf *p, struct netif *netif, struct ip_addr *dest)
|
||||
header = pbuf_alloc(PBUF_LINK, 0, PBUF_RAM);
|
||||
pbuf_chain(header, rambuf);
|
||||
netif->output(netif, header, dest);
|
||||
#ifdef IP_STATS
|
||||
++lwip_stats.ip_frag.xmit;
|
||||
#endif /* IP_STATS */
|
||||
pbuf_dechain(header);
|
||||
pbuf_free(header);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user