Remove ip4_frag IP_FRAG_USES_STATIC_BUF code: nearly the same as the other code, but IP_FRAG_USES_STATIC_BUF doesn't work when queuing pbufs

This commit is contained in:
sg 2016-08-31 21:00:10 +02:00
parent ac6b64cf66
commit 34682facd1
6 changed files with 11 additions and 93 deletions

View File

@ -227,9 +227,6 @@ PACK_STRUCT_END
#if LWIP_TCP && LWIP_NETIF_TX_SINGLE_PBUF && !TCP_OVERSIZE #if LWIP_TCP && LWIP_NETIF_TX_SINGLE_PBUF && !TCP_OVERSIZE
#error "LWIP_NETIF_TX_SINGLE_PBUF needs TCP_OVERSIZE enabled to create single-pbuf TCP packets" #error "LWIP_NETIF_TX_SINGLE_PBUF needs TCP_OVERSIZE enabled to create single-pbuf TCP packets"
#endif #endif
#if IP_FRAG && IP_FRAG_USES_STATIC_BUF && LWIP_NETIF_TX_SINGLE_PBUF
#error "LWIP_NETIF_TX_SINGLE_PBUF does not work with IP_FRAG_USES_STATIC_BUF==1 as that creates pbuf queues"
#endif
#if LWIP_NETCONN && LWIP_TCP #if LWIP_NETCONN && LWIP_TCP
#if NETCONN_COPY != TCP_WRITE_FLAG_COPY #if NETCONN_COPY != TCP_WRITE_FLAG_COPY
#error "NETCONN_COPY != TCP_WRITE_FLAG_COPY" #error "NETCONN_COPY != TCP_WRITE_FLAG_COPY"

View File

@ -340,7 +340,7 @@ ip_reass_chain_frag_into_datagram_and_validate(struct ip_reassdata *ipr, struct
{ {
struct ip_reass_helper *iprh, *iprh_tmp, *iprh_prev=NULL; struct ip_reass_helper *iprh, *iprh_tmp, *iprh_prev=NULL;
struct pbuf *q; struct pbuf *q;
u16_t offset,len; u16_t offset, len;
struct ip_hdr *fraghdr; struct ip_hdr *fraghdr;
int valid = 1; int valid = 1;
@ -639,10 +639,6 @@ nullreturn:
#endif /* IP_REASSEMBLY */ #endif /* IP_REASSEMBLY */
#if IP_FRAG #if IP_FRAG
#if IP_FRAG_USES_STATIC_BUF
static LWIP_DECLARE_MEMORY_ALIGNED(buf, IP_FRAG_MAX_MTU);
#else /* IP_FRAG_USES_STATIC_BUF */
#if !LWIP_NETIF_TX_SINGLE_PBUF #if !LWIP_NETIF_TX_SINGLE_PBUF
/** Allocate a new struct pbuf_custom_ref */ /** Allocate a new struct pbuf_custom_ref */
static struct pbuf_custom_ref* static struct pbuf_custom_ref*
@ -673,14 +669,12 @@ ipfrag_free_pbuf_custom(struct pbuf *p)
ip_frag_free_pbuf_custom_ref(pcr); ip_frag_free_pbuf_custom_ref(pcr);
} }
#endif /* !LWIP_NETIF_TX_SINGLE_PBUF */ #endif /* !LWIP_NETIF_TX_SINGLE_PBUF */
#endif /* IP_FRAG_USES_STATIC_BUF */
/** /**
* Fragment an IP datagram if too large for the netif. * Fragment an IP datagram if too large for the netif.
* *
* Chop the datagram in MTU sized chunks and send them in order * Chop the datagram in MTU sized chunks and send them in order
* by using a fixed size static memory buffer (PBUF_REF) or * by pointing PBUF_REFs into p.
* point PBUF_REFs into p (depending on IP_FRAG_USES_STATIC_BUF).
* *
* @param p ip packet to send * @param p ip packet to send
* @param netif the netif on which to send * @param netif the netif on which to send
@ -692,14 +686,10 @@ err_t
ip4_frag(struct pbuf *p, struct netif *netif, const ip4_addr_t *dest) ip4_frag(struct pbuf *p, struct netif *netif, const ip4_addr_t *dest)
{ {
struct pbuf *rambuf; struct pbuf *rambuf;
#if IP_FRAG_USES_STATIC_BUF
struct pbuf *header;
#else
#if !LWIP_NETIF_TX_SINGLE_PBUF #if !LWIP_NETIF_TX_SINGLE_PBUF
struct pbuf *newpbuf; struct pbuf *newpbuf;
#endif #endif
struct ip_hdr *original_iphdr; struct ip_hdr *original_iphdr;
#endif
struct ip_hdr *iphdr; struct ip_hdr *iphdr;
u16_t nfb; u16_t nfb;
u16_t left, cop; u16_t left, cop;
@ -708,32 +698,13 @@ ip4_frag(struct pbuf *p, struct netif *netif, const ip4_addr_t *dest)
u16_t last; u16_t last;
u16_t poff = IP_HLEN; u16_t poff = IP_HLEN;
u16_t tmp; u16_t tmp;
#if !IP_FRAG_USES_STATIC_BUF && !LWIP_NETIF_TX_SINGLE_PBUF #if !LWIP_NETIF_TX_SINGLE_PBUF
u16_t newpbuflen = 0; u16_t newpbuflen = 0;
u16_t left_to_copy; u16_t left_to_copy;
#endif #endif
/* Get a RAM based MTU sized pbuf */
#if IP_FRAG_USES_STATIC_BUF
/* When using a static buffer, we use a PBUF_REF, which we will
* use to reference the packet (without link header).
* Layer and length is irrelevant.
*/
rambuf = pbuf_alloc(PBUF_LINK, 0, PBUF_REF);
if (rambuf == NULL) {
LWIP_DEBUGF(IP_REASS_DEBUG, ("ip_frag: pbuf_alloc(PBUF_LINK, 0, PBUF_REF) failed\n"));
goto memerr;
}
rambuf->tot_len = rambuf->len = mtu;
rambuf->payload = LWIP_MEM_ALIGN((void *)buf);
/* Copy the IP header in it */
iphdr = (struct ip_hdr *)rambuf->payload;
SMEMCPY(iphdr, p->payload, IP_HLEN);
#else /* IP_FRAG_USES_STATIC_BUF */
original_iphdr = (struct ip_hdr *)p->payload; original_iphdr = (struct ip_hdr *)p->payload;
iphdr = original_iphdr; iphdr = original_iphdr;
#endif /* IP_FRAG_USES_STATIC_BUF */
/* Save original offset */ /* Save original offset */
tmp = ntohs(IPH_OFFSET(iphdr)); tmp = ntohs(IPH_OFFSET(iphdr));
@ -756,9 +727,6 @@ ip4_frag(struct pbuf *p, struct netif *netif, const ip4_addr_t *dest)
/* Fill this fragment */ /* Fill this fragment */
cop = last ? left : nfb * 8; cop = last ? left : nfb * 8;
#if IP_FRAG_USES_STATIC_BUF
poff += pbuf_copy_partial(p, (u8_t*)iphdr + IP_HLEN, cop, poff);
#else /* IP_FRAG_USES_STATIC_BUF */
#if LWIP_NETIF_TX_SINGLE_PBUF #if LWIP_NETIF_TX_SINGLE_PBUF
rambuf = pbuf_alloc(PBUF_IP, cop, PBUF_RAM); rambuf = pbuf_alloc(PBUF_IP, cop, PBUF_RAM);
if (rambuf == NULL) { if (rambuf == NULL) {
@ -830,7 +798,6 @@ ip4_frag(struct pbuf *p, struct netif *netif, const ip4_addr_t *dest)
} }
poff = newpbuflen; poff = newpbuflen;
#endif /* LWIP_NETIF_TX_SINGLE_PBUF */ #endif /* LWIP_NETIF_TX_SINGLE_PBUF */
#endif /* IP_FRAG_USES_STATIC_BUF */
/* Correct header */ /* Correct header */
IPH_OFFSET_SET(iphdr, htons(tmp)); IPH_OFFSET_SET(iphdr, htons(tmp));
@ -842,29 +809,6 @@ ip4_frag(struct pbuf *p, struct netif *netif, const ip4_addr_t *dest)
} }
#endif /* CHECKSUM_GEN_IP */ #endif /* CHECKSUM_GEN_IP */
#if IP_FRAG_USES_STATIC_BUF
if (last) {
pbuf_realloc(rambuf, left + IP_HLEN);
}
/* This part is ugly: we alloc a RAM based pbuf for
* the link level header for each chunk and then
* free it. A PBUF_ROM style pbuf for which pbuf_header
* worked would make things simpler.
*/
header = pbuf_alloc(PBUF_LINK, 0, PBUF_RAM);
if (header != NULL) {
pbuf_chain(header, rambuf);
netif->output(netif, header, dest);
IPFRAG_STATS_INC(ip_frag.xmit);
MIB2_STATS_INC(mib2.ipfragcreates);
pbuf_free(header);
} else {
LWIP_DEBUGF(IP_REASS_DEBUG, ("ip_frag: pbuf_alloc() for header failed\n"));
pbuf_free(rambuf);
goto memerr;
}
#else /* IP_FRAG_USES_STATIC_BUF */
/* No need for separate header pbuf - we allowed room for it in rambuf /* No need for separate header pbuf - we allowed room for it in rambuf
* when allocated. * when allocated.
*/ */
@ -879,13 +823,9 @@ ip4_frag(struct pbuf *p, struct netif *netif, const ip4_addr_t *dest)
*/ */
pbuf_free(rambuf); pbuf_free(rambuf);
#endif /* IP_FRAG_USES_STATIC_BUF */
left -= cop; left -= cop;
ofo += nfb; ofo += nfb;
} }
#if IP_FRAG_USES_STATIC_BUF
pbuf_free(rambuf);
#endif /* IP_FRAG_USES_STATIC_BUF */
MIB2_STATS_INC(mib2.ipfragoks); MIB2_STATS_INC(mib2.ipfragoks);
return ERR_OK; return ERR_OK;
memerr: memerr:

View File

@ -73,7 +73,7 @@ struct pbuf * ip4_reass(struct pbuf *p);
#endif /* IP_REASSEMBLY */ #endif /* IP_REASSEMBLY */
#if IP_FRAG #if IP_FRAG
#if !IP_FRAG_USES_STATIC_BUF && !LWIP_NETIF_TX_SINGLE_PBUF #if !LWIP_NETIF_TX_SINGLE_PBUF
#ifndef LWIP_PBUF_CUSTOM_REF_DEFINED #ifndef LWIP_PBUF_CUSTOM_REF_DEFINED
#define LWIP_PBUF_CUSTOM_REF_DEFINED #define LWIP_PBUF_CUSTOM_REF_DEFINED
/** A custom pbuf that holds a reference to another pbuf, which is freed /** A custom pbuf that holds a reference to another pbuf, which is freed
@ -86,7 +86,7 @@ struct pbuf_custom_ref {
struct pbuf *original; struct pbuf *original;
}; };
#endif /* LWIP_PBUF_CUSTOM_REF_DEFINED */ #endif /* LWIP_PBUF_CUSTOM_REF_DEFINED */
#endif /* !IP_FRAG_USES_STATIC_BUF && !LWIP_NETIF_TX_SINGLE_PBUF */ #endif /* !LWIP_NETIF_TX_SINGLE_PBUF */
err_t ip4_frag(struct pbuf *p, struct netif *netif, const ip4_addr_t *dest); err_t ip4_frag(struct pbuf *p, struct netif *netif, const ip4_addr_t *dest);
#endif /* IP_FRAG */ #endif /* IP_FRAG */

View File

@ -401,9 +401,9 @@
/** /**
* MEMP_NUM_FRAG_PBUF: the number of IP fragments simultaneously sent * MEMP_NUM_FRAG_PBUF: the number of IP fragments simultaneously sent
* (fragments, not whole packets!). * (fragments, not whole packets!).
* This is only used with IP_FRAG_USES_STATIC_BUF==0 and * This is only used with LWIP_NETIF_TX_SINGLE_PBUF==0 and only has to be > 1
* LWIP_NETIF_TX_SINGLE_PBUF==0 and only has to be > 1 with DMA-enabled MACs * with DMA-enabled MACs where the packet is not yet sent when netif->output
* where the packet is not yet sent when netif->output returns. * returns.
*/ */
#if !defined MEMP_NUM_FRAG_PBUF || defined __DOXYGEN__ #if !defined MEMP_NUM_FRAG_PBUF || defined __DOXYGEN__
#define MEMP_NUM_FRAG_PBUF 15 #define MEMP_NUM_FRAG_PBUF 15
@ -705,25 +705,6 @@
#define IP_REASS_MAX_PBUFS 10 #define IP_REASS_MAX_PBUFS 10
#endif #endif
/**
* IP_FRAG_USES_STATIC_BUF==1: Use a static MTU-sized buffer for IP
* fragmentation. Otherwise pbufs are allocated and reference the original
* packet data to be fragmented (or with LWIP_NETIF_TX_SINGLE_PBUF==1,
* new PBUF_RAM pbufs are used for fragments).
* ATTENTION: IP_FRAG_USES_STATIC_BUF==1 may not be used for DMA-enabled MACs!
*/
#if !defined IP_FRAG_USES_STATIC_BUF || defined __DOXYGEN__
#define IP_FRAG_USES_STATIC_BUF 0
#endif
/**
* IP_FRAG_MAX_MTU: Assumed max MTU on any interface for IP frag buffer
* (requires IP_FRAG_USES_STATIC_BUF==1)
*/
#if IP_FRAG_USES_STATIC_BUF && !defined(IP_FRAG_MAX_MTU) || defined __DOXYGEN__
#define IP_FRAG_MAX_MTU 1500
#endif
/** /**
* IP_DEFAULT_TTL: Default value for Time-To-Live used by transport layers. * IP_DEFAULT_TTL: Default value for Time-To-Live used by transport layers.
*/ */

View File

@ -52,7 +52,7 @@ extern "C" {
* Currently, the pbuf_custom code is only needed for one specific configuration * Currently, the pbuf_custom code is only needed for one specific configuration
* of IP_FRAG, unless required by external driver/application code. */ * of IP_FRAG, unless required by external driver/application code. */
#ifndef LWIP_SUPPORT_CUSTOM_PBUF #ifndef LWIP_SUPPORT_CUSTOM_PBUF
#define LWIP_SUPPORT_CUSTOM_PBUF ((IP_FRAG && !IP_FRAG_USES_STATIC_BUF && !LWIP_NETIF_TX_SINGLE_PBUF) || (LWIP_IPV6 && LWIP_IPV6_FRAG)) #define LWIP_SUPPORT_CUSTOM_PBUF ((IP_FRAG && !LWIP_NETIF_TX_SINGLE_PBUF) || (LWIP_IPV6 && LWIP_IPV6_FRAG))
#endif #endif
/* @todo: We need a mechanism to prevent wasting memory in every pbuf /* @todo: We need a mechanism to prevent wasting memory in every pbuf

View File

@ -55,9 +55,9 @@ LWIP_MEMPOOL(TCP_SEG, MEMP_NUM_TCP_SEG, sizeof(struct tcp_seg),
#if LWIP_IPV4 && IP_REASSEMBLY #if LWIP_IPV4 && IP_REASSEMBLY
LWIP_MEMPOOL(REASSDATA, MEMP_NUM_REASSDATA, sizeof(struct ip_reassdata), "REASSDATA") LWIP_MEMPOOL(REASSDATA, MEMP_NUM_REASSDATA, sizeof(struct ip_reassdata), "REASSDATA")
#endif /* LWIP_IPV4 && IP_REASSEMBLY */ #endif /* LWIP_IPV4 && IP_REASSEMBLY */
#if (IP_FRAG && !IP_FRAG_USES_STATIC_BUF && !LWIP_NETIF_TX_SINGLE_PBUF) || (LWIP_IPV6 && LWIP_IPV6_FRAG) #if (IP_FRAG && !LWIP_NETIF_TX_SINGLE_PBUF) || (LWIP_IPV6 && LWIP_IPV6_FRAG)
LWIP_MEMPOOL(FRAG_PBUF, MEMP_NUM_FRAG_PBUF, sizeof(struct pbuf_custom_ref),"FRAG_PBUF") LWIP_MEMPOOL(FRAG_PBUF, MEMP_NUM_FRAG_PBUF, sizeof(struct pbuf_custom_ref),"FRAG_PBUF")
#endif /* IP_FRAG && !IP_FRAG_USES_STATIC_BUF && !LWIP_NETIF_TX_SINGLE_PBUF */ #endif /* IP_FRAG && !LWIP_NETIF_TX_SINGLE_PBUF || (LWIP_IPV6 && LWIP_IPV6_FRAG) */
#if LWIP_NETCONN || LWIP_SOCKET #if LWIP_NETCONN || LWIP_SOCKET
LWIP_MEMPOOL(NETBUF, MEMP_NUM_NETBUF, sizeof(struct netbuf), "NETBUF") LWIP_MEMPOOL(NETBUF, MEMP_NUM_NETBUF, sizeof(struct netbuf), "NETBUF")