Ethernet test for ECE 4180 and others to find your IP address and do a simple HTTP GET request over port 80.

Dependencies:   mbed Socket lwip-eth lwip-sys lwip

Committer:
mkersh3
Date:
Thu Apr 04 05:26:09 2013 +0000
Revision:
0:e7ca326e76ee
Ethernet Test for ECE4180 and others to find their IP Address and do a simple HTTP GET request over port 80.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mkersh3 0:e7ca326e76ee 1 /**
mkersh3 0:e7ca326e76ee 2 * @file
mkersh3 0:e7ca326e76ee 3 * This is the IPv4 packet segmentation and reassembly implementation.
mkersh3 0:e7ca326e76ee 4 *
mkersh3 0:e7ca326e76ee 5 */
mkersh3 0:e7ca326e76ee 6
mkersh3 0:e7ca326e76ee 7 /*
mkersh3 0:e7ca326e76ee 8 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
mkersh3 0:e7ca326e76ee 9 * All rights reserved.
mkersh3 0:e7ca326e76ee 10 *
mkersh3 0:e7ca326e76ee 11 * Redistribution and use in source and binary forms, with or without modification,
mkersh3 0:e7ca326e76ee 12 * are permitted provided that the following conditions are met:
mkersh3 0:e7ca326e76ee 13 *
mkersh3 0:e7ca326e76ee 14 * 1. Redistributions of source code must retain the above copyright notice,
mkersh3 0:e7ca326e76ee 15 * this list of conditions and the following disclaimer.
mkersh3 0:e7ca326e76ee 16 * 2. Redistributions in binary form must reproduce the above copyright notice,
mkersh3 0:e7ca326e76ee 17 * this list of conditions and the following disclaimer in the documentation
mkersh3 0:e7ca326e76ee 18 * and/or other materials provided with the distribution.
mkersh3 0:e7ca326e76ee 19 * 3. The name of the author may not be used to endorse or promote products
mkersh3 0:e7ca326e76ee 20 * derived from this software without specific prior written permission.
mkersh3 0:e7ca326e76ee 21 *
mkersh3 0:e7ca326e76ee 22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
mkersh3 0:e7ca326e76ee 23 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
mkersh3 0:e7ca326e76ee 24 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
mkersh3 0:e7ca326e76ee 25 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
mkersh3 0:e7ca326e76ee 26 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
mkersh3 0:e7ca326e76ee 27 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
mkersh3 0:e7ca326e76ee 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
mkersh3 0:e7ca326e76ee 29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
mkersh3 0:e7ca326e76ee 30 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
mkersh3 0:e7ca326e76ee 31 * OF SUCH DAMAGE.
mkersh3 0:e7ca326e76ee 32 *
mkersh3 0:e7ca326e76ee 33 * This file is part of the lwIP TCP/IP stack.
mkersh3 0:e7ca326e76ee 34 *
mkersh3 0:e7ca326e76ee 35 * Author: Jani Monoses <jani@iv.ro>
mkersh3 0:e7ca326e76ee 36 * Simon Goldschmidt
mkersh3 0:e7ca326e76ee 37 * original reassembly code by Adam Dunkels <adam@sics.se>
mkersh3 0:e7ca326e76ee 38 *
mkersh3 0:e7ca326e76ee 39 */
mkersh3 0:e7ca326e76ee 40
mkersh3 0:e7ca326e76ee 41 #include "lwip/opt.h"
mkersh3 0:e7ca326e76ee 42 #include "lwip/ip_frag.h"
mkersh3 0:e7ca326e76ee 43 #include "lwip/def.h"
mkersh3 0:e7ca326e76ee 44 #include "lwip/inet_chksum.h"
mkersh3 0:e7ca326e76ee 45 #include "lwip/netif.h"
mkersh3 0:e7ca326e76ee 46 #include "lwip/snmp.h"
mkersh3 0:e7ca326e76ee 47 #include "lwip/stats.h"
mkersh3 0:e7ca326e76ee 48 #include "lwip/icmp.h"
mkersh3 0:e7ca326e76ee 49
mkersh3 0:e7ca326e76ee 50 #include <string.h>
mkersh3 0:e7ca326e76ee 51
mkersh3 0:e7ca326e76ee 52 #if IP_REASSEMBLY
mkersh3 0:e7ca326e76ee 53 /**
mkersh3 0:e7ca326e76ee 54 * The IP reassembly code currently has the following limitations:
mkersh3 0:e7ca326e76ee 55 * - IP header options are not supported
mkersh3 0:e7ca326e76ee 56 * - fragments must not overlap (e.g. due to different routes),
mkersh3 0:e7ca326e76ee 57 * currently, overlapping or duplicate fragments are thrown away
mkersh3 0:e7ca326e76ee 58 * if IP_REASS_CHECK_OVERLAP=1 (the default)!
mkersh3 0:e7ca326e76ee 59 *
mkersh3 0:e7ca326e76ee 60 * @todo: work with IP header options
mkersh3 0:e7ca326e76ee 61 */
mkersh3 0:e7ca326e76ee 62
mkersh3 0:e7ca326e76ee 63 /** Setting this to 0, you can turn off checking the fragments for overlapping
mkersh3 0:e7ca326e76ee 64 * regions. The code gets a little smaller. Only use this if you know that
mkersh3 0:e7ca326e76ee 65 * overlapping won't occur on your network! */
mkersh3 0:e7ca326e76ee 66 #ifndef IP_REASS_CHECK_OVERLAP
mkersh3 0:e7ca326e76ee 67 #define IP_REASS_CHECK_OVERLAP 1
mkersh3 0:e7ca326e76ee 68 #endif /* IP_REASS_CHECK_OVERLAP */
mkersh3 0:e7ca326e76ee 69
mkersh3 0:e7ca326e76ee 70 /** Set to 0 to prevent freeing the oldest datagram when the reassembly buffer is
mkersh3 0:e7ca326e76ee 71 * full (IP_REASS_MAX_PBUFS pbufs are enqueued). The code gets a little smaller.
mkersh3 0:e7ca326e76ee 72 * Datagrams will be freed by timeout only. Especially useful when MEMP_NUM_REASSDATA
mkersh3 0:e7ca326e76ee 73 * is set to 1, so one datagram can be reassembled at a time, only. */
mkersh3 0:e7ca326e76ee 74 #ifndef IP_REASS_FREE_OLDEST
mkersh3 0:e7ca326e76ee 75 #define IP_REASS_FREE_OLDEST 1
mkersh3 0:e7ca326e76ee 76 #endif /* IP_REASS_FREE_OLDEST */
mkersh3 0:e7ca326e76ee 77
mkersh3 0:e7ca326e76ee 78 #define IP_REASS_FLAG_LASTFRAG 0x01
mkersh3 0:e7ca326e76ee 79
mkersh3 0:e7ca326e76ee 80 /** This is a helper struct which holds the starting
mkersh3 0:e7ca326e76ee 81 * offset and the ending offset of this fragment to
mkersh3 0:e7ca326e76ee 82 * easily chain the fragments.
mkersh3 0:e7ca326e76ee 83 * It has the same packing requirements as the IP header, since it replaces
mkersh3 0:e7ca326e76ee 84 * the IP header in memory in incoming fragments (after copying it) to keep
mkersh3 0:e7ca326e76ee 85 * track of the various fragments. (-> If the IP header doesn't need packing,
mkersh3 0:e7ca326e76ee 86 * this struct doesn't need packing, too.)
mkersh3 0:e7ca326e76ee 87 */
mkersh3 0:e7ca326e76ee 88 #ifdef PACK_STRUCT_USE_INCLUDES
mkersh3 0:e7ca326e76ee 89 # include "arch/bpstruct.h"
mkersh3 0:e7ca326e76ee 90 #endif
mkersh3 0:e7ca326e76ee 91 PACK_STRUCT_BEGIN
mkersh3 0:e7ca326e76ee 92 struct ip_reass_helper {
mkersh3 0:e7ca326e76ee 93 PACK_STRUCT_FIELD(struct pbuf *next_pbuf);
mkersh3 0:e7ca326e76ee 94 PACK_STRUCT_FIELD(u16_t start);
mkersh3 0:e7ca326e76ee 95 PACK_STRUCT_FIELD(u16_t end);
mkersh3 0:e7ca326e76ee 96 } PACK_STRUCT_STRUCT;
mkersh3 0:e7ca326e76ee 97 PACK_STRUCT_END
mkersh3 0:e7ca326e76ee 98 #ifdef PACK_STRUCT_USE_INCLUDES
mkersh3 0:e7ca326e76ee 99 # include "arch/epstruct.h"
mkersh3 0:e7ca326e76ee 100 #endif
mkersh3 0:e7ca326e76ee 101
mkersh3 0:e7ca326e76ee 102 #define IP_ADDRESSES_AND_ID_MATCH(iphdrA, iphdrB) \
mkersh3 0:e7ca326e76ee 103 (ip_addr_cmp(&(iphdrA)->src, &(iphdrB)->src) && \
mkersh3 0:e7ca326e76ee 104 ip_addr_cmp(&(iphdrA)->dest, &(iphdrB)->dest) && \
mkersh3 0:e7ca326e76ee 105 IPH_ID(iphdrA) == IPH_ID(iphdrB)) ? 1 : 0
mkersh3 0:e7ca326e76ee 106
mkersh3 0:e7ca326e76ee 107 /* global variables */
mkersh3 0:e7ca326e76ee 108 static struct ip_reassdata *reassdatagrams;
mkersh3 0:e7ca326e76ee 109 static u16_t ip_reass_pbufcount;
mkersh3 0:e7ca326e76ee 110
mkersh3 0:e7ca326e76ee 111 /* function prototypes */
mkersh3 0:e7ca326e76ee 112 static void ip_reass_dequeue_datagram(struct ip_reassdata *ipr, struct ip_reassdata *prev);
mkersh3 0:e7ca326e76ee 113 static int ip_reass_free_complete_datagram(struct ip_reassdata *ipr, struct ip_reassdata *prev);
mkersh3 0:e7ca326e76ee 114
mkersh3 0:e7ca326e76ee 115 /**
mkersh3 0:e7ca326e76ee 116 * Reassembly timer base function
mkersh3 0:e7ca326e76ee 117 * for both NO_SYS == 0 and 1 (!).
mkersh3 0:e7ca326e76ee 118 *
mkersh3 0:e7ca326e76ee 119 * Should be called every 1000 msec (defined by IP_TMR_INTERVAL).
mkersh3 0:e7ca326e76ee 120 */
mkersh3 0:e7ca326e76ee 121 void
mkersh3 0:e7ca326e76ee 122 ip_reass_tmr(void)
mkersh3 0:e7ca326e76ee 123 {
mkersh3 0:e7ca326e76ee 124 struct ip_reassdata *r, *prev = NULL;
mkersh3 0:e7ca326e76ee 125
mkersh3 0:e7ca326e76ee 126 r = reassdatagrams;
mkersh3 0:e7ca326e76ee 127 while (r != NULL) {
mkersh3 0:e7ca326e76ee 128 /* Decrement the timer. Once it reaches 0,
mkersh3 0:e7ca326e76ee 129 * clean up the incomplete fragment assembly */
mkersh3 0:e7ca326e76ee 130 if (r->timer > 0) {
mkersh3 0:e7ca326e76ee 131 r->timer--;
mkersh3 0:e7ca326e76ee 132 LWIP_DEBUGF(IP_REASS_DEBUG, ("ip_reass_tmr: timer dec %"U16_F"\n",(u16_t)r->timer));
mkersh3 0:e7ca326e76ee 133 prev = r;
mkersh3 0:e7ca326e76ee 134 r = r->next;
mkersh3 0:e7ca326e76ee 135 } else {
mkersh3 0:e7ca326e76ee 136 /* reassembly timed out */
mkersh3 0:e7ca326e76ee 137 struct ip_reassdata *tmp;
mkersh3 0:e7ca326e76ee 138 LWIP_DEBUGF(IP_REASS_DEBUG, ("ip_reass_tmr: timer timed out\n"));
mkersh3 0:e7ca326e76ee 139 tmp = r;
mkersh3 0:e7ca326e76ee 140 /* get the next pointer before freeing */
mkersh3 0:e7ca326e76ee 141 r = r->next;
mkersh3 0:e7ca326e76ee 142 /* free the helper struct and all enqueued pbufs */
mkersh3 0:e7ca326e76ee 143 ip_reass_free_complete_datagram(tmp, prev);
mkersh3 0:e7ca326e76ee 144 }
mkersh3 0:e7ca326e76ee 145 }
mkersh3 0:e7ca326e76ee 146 }
mkersh3 0:e7ca326e76ee 147
mkersh3 0:e7ca326e76ee 148 /**
mkersh3 0:e7ca326e76ee 149 * Free a datagram (struct ip_reassdata) and all its pbufs.
mkersh3 0:e7ca326e76ee 150 * Updates the total count of enqueued pbufs (ip_reass_pbufcount),
mkersh3 0:e7ca326e76ee 151 * SNMP counters and sends an ICMP time exceeded packet.
mkersh3 0:e7ca326e76ee 152 *
mkersh3 0:e7ca326e76ee 153 * @param ipr datagram to free
mkersh3 0:e7ca326e76ee 154 * @param prev the previous datagram in the linked list
mkersh3 0:e7ca326e76ee 155 * @return the number of pbufs freed
mkersh3 0:e7ca326e76ee 156 */
mkersh3 0:e7ca326e76ee 157 static int
mkersh3 0:e7ca326e76ee 158 ip_reass_free_complete_datagram(struct ip_reassdata *ipr, struct ip_reassdata *prev)
mkersh3 0:e7ca326e76ee 159 {
mkersh3 0:e7ca326e76ee 160 u16_t pbufs_freed = 0;
mkersh3 0:e7ca326e76ee 161 u8_t clen;
mkersh3 0:e7ca326e76ee 162 struct pbuf *p;
mkersh3 0:e7ca326e76ee 163 struct ip_reass_helper *iprh;
mkersh3 0:e7ca326e76ee 164
mkersh3 0:e7ca326e76ee 165 LWIP_ASSERT("prev != ipr", prev != ipr);
mkersh3 0:e7ca326e76ee 166 if (prev != NULL) {
mkersh3 0:e7ca326e76ee 167 LWIP_ASSERT("prev->next == ipr", prev->next == ipr);
mkersh3 0:e7ca326e76ee 168 }
mkersh3 0:e7ca326e76ee 169
mkersh3 0:e7ca326e76ee 170 snmp_inc_ipreasmfails();
mkersh3 0:e7ca326e76ee 171 #if LWIP_ICMP
mkersh3 0:e7ca326e76ee 172 iprh = (struct ip_reass_helper *)ipr->p->payload;
mkersh3 0:e7ca326e76ee 173 if (iprh->start == 0) {
mkersh3 0:e7ca326e76ee 174 /* The first fragment was received, send ICMP time exceeded. */
mkersh3 0:e7ca326e76ee 175 /* First, de-queue the first pbuf from r->p. */
mkersh3 0:e7ca326e76ee 176 p = ipr->p;
mkersh3 0:e7ca326e76ee 177 ipr->p = iprh->next_pbuf;
mkersh3 0:e7ca326e76ee 178 /* Then, copy the original header into it. */
mkersh3 0:e7ca326e76ee 179 SMEMCPY(p->payload, &ipr->iphdr, IP_HLEN);
mkersh3 0:e7ca326e76ee 180 icmp_time_exceeded(p, ICMP_TE_FRAG);
mkersh3 0:e7ca326e76ee 181 clen = pbuf_clen(p);
mkersh3 0:e7ca326e76ee 182 LWIP_ASSERT("pbufs_freed + clen <= 0xffff", pbufs_freed + clen <= 0xffff);
mkersh3 0:e7ca326e76ee 183 pbufs_freed += clen;
mkersh3 0:e7ca326e76ee 184 pbuf_free(p);
mkersh3 0:e7ca326e76ee 185 }
mkersh3 0:e7ca326e76ee 186 #endif /* LWIP_ICMP */
mkersh3 0:e7ca326e76ee 187
mkersh3 0:e7ca326e76ee 188 /* First, free all received pbufs. The individual pbufs need to be released
mkersh3 0:e7ca326e76ee 189 separately as they have not yet been chained */
mkersh3 0:e7ca326e76ee 190 p = ipr->p;
mkersh3 0:e7ca326e76ee 191 while (p != NULL) {
mkersh3 0:e7ca326e76ee 192 struct pbuf *pcur;
mkersh3 0:e7ca326e76ee 193 iprh = (struct ip_reass_helper *)p->payload;
mkersh3 0:e7ca326e76ee 194 pcur = p;
mkersh3 0:e7ca326e76ee 195 /* get the next pointer before freeing */
mkersh3 0:e7ca326e76ee 196 p = iprh->next_pbuf;
mkersh3 0:e7ca326e76ee 197 clen = pbuf_clen(pcur);
mkersh3 0:e7ca326e76ee 198 LWIP_ASSERT("pbufs_freed + clen <= 0xffff", pbufs_freed + clen <= 0xffff);
mkersh3 0:e7ca326e76ee 199 pbufs_freed += clen;
mkersh3 0:e7ca326e76ee 200 pbuf_free(pcur);
mkersh3 0:e7ca326e76ee 201 }
mkersh3 0:e7ca326e76ee 202 /* Then, unchain the struct ip_reassdata from the list and free it. */
mkersh3 0:e7ca326e76ee 203 ip_reass_dequeue_datagram(ipr, prev);
mkersh3 0:e7ca326e76ee 204 LWIP_ASSERT("ip_reass_pbufcount >= clen", ip_reass_pbufcount >= pbufs_freed);
mkersh3 0:e7ca326e76ee 205 ip_reass_pbufcount -= pbufs_freed;
mkersh3 0:e7ca326e76ee 206
mkersh3 0:e7ca326e76ee 207 return pbufs_freed;
mkersh3 0:e7ca326e76ee 208 }
mkersh3 0:e7ca326e76ee 209
mkersh3 0:e7ca326e76ee 210 #if IP_REASS_FREE_OLDEST
mkersh3 0:e7ca326e76ee 211 /**
mkersh3 0:e7ca326e76ee 212 * Free the oldest datagram to make room for enqueueing new fragments.
mkersh3 0:e7ca326e76ee 213 * The datagram 'fraghdr' belongs to is not freed!
mkersh3 0:e7ca326e76ee 214 *
mkersh3 0:e7ca326e76ee 215 * @param fraghdr IP header of the current fragment
mkersh3 0:e7ca326e76ee 216 * @param pbufs_needed number of pbufs needed to enqueue
mkersh3 0:e7ca326e76ee 217 * (used for freeing other datagrams if not enough space)
mkersh3 0:e7ca326e76ee 218 * @return the number of pbufs freed
mkersh3 0:e7ca326e76ee 219 */
mkersh3 0:e7ca326e76ee 220 static int
mkersh3 0:e7ca326e76ee 221 ip_reass_remove_oldest_datagram(struct ip_hdr *fraghdr, int pbufs_needed)
mkersh3 0:e7ca326e76ee 222 {
mkersh3 0:e7ca326e76ee 223 /* @todo Can't we simply remove the last datagram in the
mkersh3 0:e7ca326e76ee 224 * linked list behind reassdatagrams?
mkersh3 0:e7ca326e76ee 225 */
mkersh3 0:e7ca326e76ee 226 struct ip_reassdata *r, *oldest, *prev;
mkersh3 0:e7ca326e76ee 227 int pbufs_freed = 0, pbufs_freed_current;
mkersh3 0:e7ca326e76ee 228 int other_datagrams;
mkersh3 0:e7ca326e76ee 229
mkersh3 0:e7ca326e76ee 230 /* Free datagrams until being allowed to enqueue 'pbufs_needed' pbufs,
mkersh3 0:e7ca326e76ee 231 * but don't free the datagram that 'fraghdr' belongs to! */
mkersh3 0:e7ca326e76ee 232 do {
mkersh3 0:e7ca326e76ee 233 oldest = NULL;
mkersh3 0:e7ca326e76ee 234 prev = NULL;
mkersh3 0:e7ca326e76ee 235 other_datagrams = 0;
mkersh3 0:e7ca326e76ee 236 r = reassdatagrams;
mkersh3 0:e7ca326e76ee 237 while (r != NULL) {
mkersh3 0:e7ca326e76ee 238 if (!IP_ADDRESSES_AND_ID_MATCH(&r->iphdr, fraghdr)) {
mkersh3 0:e7ca326e76ee 239 /* Not the same datagram as fraghdr */
mkersh3 0:e7ca326e76ee 240 other_datagrams++;
mkersh3 0:e7ca326e76ee 241 if (oldest == NULL) {
mkersh3 0:e7ca326e76ee 242 oldest = r;
mkersh3 0:e7ca326e76ee 243 } else if (r->timer <= oldest->timer) {
mkersh3 0:e7ca326e76ee 244 /* older than the previous oldest */
mkersh3 0:e7ca326e76ee 245 oldest = r;
mkersh3 0:e7ca326e76ee 246 }
mkersh3 0:e7ca326e76ee 247 }
mkersh3 0:e7ca326e76ee 248 if (r->next != NULL) {
mkersh3 0:e7ca326e76ee 249 prev = r;
mkersh3 0:e7ca326e76ee 250 }
mkersh3 0:e7ca326e76ee 251 r = r->next;
mkersh3 0:e7ca326e76ee 252 }
mkersh3 0:e7ca326e76ee 253 if (oldest != NULL) {
mkersh3 0:e7ca326e76ee 254 pbufs_freed_current = ip_reass_free_complete_datagram(oldest, prev);
mkersh3 0:e7ca326e76ee 255 pbufs_freed += pbufs_freed_current;
mkersh3 0:e7ca326e76ee 256 }
mkersh3 0:e7ca326e76ee 257 } while ((pbufs_freed < pbufs_needed) && (other_datagrams > 1));
mkersh3 0:e7ca326e76ee 258 return pbufs_freed;
mkersh3 0:e7ca326e76ee 259 }
mkersh3 0:e7ca326e76ee 260 #endif /* IP_REASS_FREE_OLDEST */
mkersh3 0:e7ca326e76ee 261
mkersh3 0:e7ca326e76ee 262 /**
mkersh3 0:e7ca326e76ee 263 * Enqueues a new fragment into the fragment queue
mkersh3 0:e7ca326e76ee 264 * @param fraghdr points to the new fragments IP hdr
mkersh3 0:e7ca326e76ee 265 * @param clen number of pbufs needed to enqueue (used for freeing other datagrams if not enough space)
mkersh3 0:e7ca326e76ee 266 * @return A pointer to the queue location into which the fragment was enqueued
mkersh3 0:e7ca326e76ee 267 */
mkersh3 0:e7ca326e76ee 268 static struct ip_reassdata*
mkersh3 0:e7ca326e76ee 269 ip_reass_enqueue_new_datagram(struct ip_hdr *fraghdr, int clen)
mkersh3 0:e7ca326e76ee 270 {
mkersh3 0:e7ca326e76ee 271 struct ip_reassdata* ipr;
mkersh3 0:e7ca326e76ee 272 /* No matching previous fragment found, allocate a new reassdata struct */
mkersh3 0:e7ca326e76ee 273 ipr = (struct ip_reassdata *)memp_malloc(MEMP_REASSDATA);
mkersh3 0:e7ca326e76ee 274 if (ipr == NULL) {
mkersh3 0:e7ca326e76ee 275 #if IP_REASS_FREE_OLDEST
mkersh3 0:e7ca326e76ee 276 if (ip_reass_remove_oldest_datagram(fraghdr, clen) >= clen) {
mkersh3 0:e7ca326e76ee 277 ipr = (struct ip_reassdata *)memp_malloc(MEMP_REASSDATA);
mkersh3 0:e7ca326e76ee 278 }
mkersh3 0:e7ca326e76ee 279 if (ipr == NULL)
mkersh3 0:e7ca326e76ee 280 #endif /* IP_REASS_FREE_OLDEST */
mkersh3 0:e7ca326e76ee 281 {
mkersh3 0:e7ca326e76ee 282 IPFRAG_STATS_INC(ip_frag.memerr);
mkersh3 0:e7ca326e76ee 283 LWIP_DEBUGF(IP_REASS_DEBUG,("Failed to alloc reassdata struct\n"));
mkersh3 0:e7ca326e76ee 284 return NULL;
mkersh3 0:e7ca326e76ee 285 }
mkersh3 0:e7ca326e76ee 286 }
mkersh3 0:e7ca326e76ee 287 memset(ipr, 0, sizeof(struct ip_reassdata));
mkersh3 0:e7ca326e76ee 288 ipr->timer = IP_REASS_MAXAGE;
mkersh3 0:e7ca326e76ee 289
mkersh3 0:e7ca326e76ee 290 /* enqueue the new structure to the front of the list */
mkersh3 0:e7ca326e76ee 291 ipr->next = reassdatagrams;
mkersh3 0:e7ca326e76ee 292 reassdatagrams = ipr;
mkersh3 0:e7ca326e76ee 293 /* copy the ip header for later tests and input */
mkersh3 0:e7ca326e76ee 294 /* @todo: no ip options supported? */
mkersh3 0:e7ca326e76ee 295 SMEMCPY(&(ipr->iphdr), fraghdr, IP_HLEN);
mkersh3 0:e7ca326e76ee 296 return ipr;
mkersh3 0:e7ca326e76ee 297 }
mkersh3 0:e7ca326e76ee 298
mkersh3 0:e7ca326e76ee 299 /**
mkersh3 0:e7ca326e76ee 300 * Dequeues a datagram from the datagram queue. Doesn't deallocate the pbufs.
mkersh3 0:e7ca326e76ee 301 * @param ipr points to the queue entry to dequeue
mkersh3 0:e7ca326e76ee 302 */
mkersh3 0:e7ca326e76ee 303 static void
mkersh3 0:e7ca326e76ee 304 ip_reass_dequeue_datagram(struct ip_reassdata *ipr, struct ip_reassdata *prev)
mkersh3 0:e7ca326e76ee 305 {
mkersh3 0:e7ca326e76ee 306
mkersh3 0:e7ca326e76ee 307 /* dequeue the reass struct */
mkersh3 0:e7ca326e76ee 308 if (reassdatagrams == ipr) {
mkersh3 0:e7ca326e76ee 309 /* it was the first in the list */
mkersh3 0:e7ca326e76ee 310 reassdatagrams = ipr->next;
mkersh3 0:e7ca326e76ee 311 } else {
mkersh3 0:e7ca326e76ee 312 /* it wasn't the first, so it must have a valid 'prev' */
mkersh3 0:e7ca326e76ee 313 LWIP_ASSERT("sanity check linked list", prev != NULL);
mkersh3 0:e7ca326e76ee 314 prev->next = ipr->next;
mkersh3 0:e7ca326e76ee 315 }
mkersh3 0:e7ca326e76ee 316
mkersh3 0:e7ca326e76ee 317 /* now we can free the ip_reass struct */
mkersh3 0:e7ca326e76ee 318 memp_free(MEMP_REASSDATA, ipr);
mkersh3 0:e7ca326e76ee 319 }
mkersh3 0:e7ca326e76ee 320
mkersh3 0:e7ca326e76ee 321 /**
mkersh3 0:e7ca326e76ee 322 * Chain a new pbuf into the pbuf list that composes the datagram. The pbuf list
mkersh3 0:e7ca326e76ee 323 * will grow over time as new pbufs are rx.
mkersh3 0:e7ca326e76ee 324 * Also checks that the datagram passes basic continuity checks (if the last
mkersh3 0:e7ca326e76ee 325 * fragment was received at least once).
mkersh3 0:e7ca326e76ee 326 * @param root_p points to the 'root' pbuf for the current datagram being assembled.
mkersh3 0:e7ca326e76ee 327 * @param new_p points to the pbuf for the current fragment
mkersh3 0:e7ca326e76ee 328 * @return 0 if invalid, >0 otherwise
mkersh3 0:e7ca326e76ee 329 */
mkersh3 0:e7ca326e76ee 330 static int
mkersh3 0:e7ca326e76ee 331 ip_reass_chain_frag_into_datagram_and_validate(struct ip_reassdata *ipr, struct pbuf *new_p)
mkersh3 0:e7ca326e76ee 332 {
mkersh3 0:e7ca326e76ee 333 struct ip_reass_helper *iprh, *iprh_tmp, *iprh_prev=NULL;
mkersh3 0:e7ca326e76ee 334 struct pbuf *q;
mkersh3 0:e7ca326e76ee 335 u16_t offset,len;
mkersh3 0:e7ca326e76ee 336 struct ip_hdr *fraghdr;
mkersh3 0:e7ca326e76ee 337 int valid = 1;
mkersh3 0:e7ca326e76ee 338
mkersh3 0:e7ca326e76ee 339 /* Extract length and fragment offset from current fragment */
mkersh3 0:e7ca326e76ee 340 fraghdr = (struct ip_hdr*)new_p->payload;
mkersh3 0:e7ca326e76ee 341 len = ntohs(IPH_LEN(fraghdr)) - IPH_HL(fraghdr) * 4;
mkersh3 0:e7ca326e76ee 342 offset = (ntohs(IPH_OFFSET(fraghdr)) & IP_OFFMASK) * 8;
mkersh3 0:e7ca326e76ee 343
mkersh3 0:e7ca326e76ee 344 /* overwrite the fragment's ip header from the pbuf with our helper struct,
mkersh3 0:e7ca326e76ee 345 * and setup the embedded helper structure. */
mkersh3 0:e7ca326e76ee 346 /* make sure the struct ip_reass_helper fits into the IP header */
mkersh3 0:e7ca326e76ee 347 LWIP_ASSERT("sizeof(struct ip_reass_helper) <= IP_HLEN",
mkersh3 0:e7ca326e76ee 348 sizeof(struct ip_reass_helper) <= IP_HLEN);
mkersh3 0:e7ca326e76ee 349 iprh = (struct ip_reass_helper*)new_p->payload;
mkersh3 0:e7ca326e76ee 350 iprh->next_pbuf = NULL;
mkersh3 0:e7ca326e76ee 351 iprh->start = offset;
mkersh3 0:e7ca326e76ee 352 iprh->end = offset + len;
mkersh3 0:e7ca326e76ee 353
mkersh3 0:e7ca326e76ee 354 /* Iterate through until we either get to the end of the list (append),
mkersh3 0:e7ca326e76ee 355 * or we find on with a larger offset (insert). */
mkersh3 0:e7ca326e76ee 356 for (q = ipr->p; q != NULL;) {
mkersh3 0:e7ca326e76ee 357 iprh_tmp = (struct ip_reass_helper*)q->payload;
mkersh3 0:e7ca326e76ee 358 if (iprh->start < iprh_tmp->start) {
mkersh3 0:e7ca326e76ee 359 /* the new pbuf should be inserted before this */
mkersh3 0:e7ca326e76ee 360 iprh->next_pbuf = q;
mkersh3 0:e7ca326e76ee 361 if (iprh_prev != NULL) {
mkersh3 0:e7ca326e76ee 362 /* not the fragment with the lowest offset */
mkersh3 0:e7ca326e76ee 363 #if IP_REASS_CHECK_OVERLAP
mkersh3 0:e7ca326e76ee 364 if ((iprh->start < iprh_prev->end) || (iprh->end > iprh_tmp->start)) {
mkersh3 0:e7ca326e76ee 365 /* fragment overlaps with previous or following, throw away */
mkersh3 0:e7ca326e76ee 366 goto freepbuf;
mkersh3 0:e7ca326e76ee 367 }
mkersh3 0:e7ca326e76ee 368 #endif /* IP_REASS_CHECK_OVERLAP */
mkersh3 0:e7ca326e76ee 369 iprh_prev->next_pbuf = new_p;
mkersh3 0:e7ca326e76ee 370 } else {
mkersh3 0:e7ca326e76ee 371 /* fragment with the lowest offset */
mkersh3 0:e7ca326e76ee 372 ipr->p = new_p;
mkersh3 0:e7ca326e76ee 373 }
mkersh3 0:e7ca326e76ee 374 break;
mkersh3 0:e7ca326e76ee 375 } else if(iprh->start == iprh_tmp->start) {
mkersh3 0:e7ca326e76ee 376 /* received the same datagram twice: no need to keep the datagram */
mkersh3 0:e7ca326e76ee 377 goto freepbuf;
mkersh3 0:e7ca326e76ee 378 #if IP_REASS_CHECK_OVERLAP
mkersh3 0:e7ca326e76ee 379 } else if(iprh->start < iprh_tmp->end) {
mkersh3 0:e7ca326e76ee 380 /* overlap: no need to keep the new datagram */
mkersh3 0:e7ca326e76ee 381 goto freepbuf;
mkersh3 0:e7ca326e76ee 382 #endif /* IP_REASS_CHECK_OVERLAP */
mkersh3 0:e7ca326e76ee 383 } else {
mkersh3 0:e7ca326e76ee 384 /* Check if the fragments received so far have no wholes. */
mkersh3 0:e7ca326e76ee 385 if (iprh_prev != NULL) {
mkersh3 0:e7ca326e76ee 386 if (iprh_prev->end != iprh_tmp->start) {
mkersh3 0:e7ca326e76ee 387 /* There is a fragment missing between the current
mkersh3 0:e7ca326e76ee 388 * and the previous fragment */
mkersh3 0:e7ca326e76ee 389 valid = 0;
mkersh3 0:e7ca326e76ee 390 }
mkersh3 0:e7ca326e76ee 391 }
mkersh3 0:e7ca326e76ee 392 }
mkersh3 0:e7ca326e76ee 393 q = iprh_tmp->next_pbuf;
mkersh3 0:e7ca326e76ee 394 iprh_prev = iprh_tmp;
mkersh3 0:e7ca326e76ee 395 }
mkersh3 0:e7ca326e76ee 396
mkersh3 0:e7ca326e76ee 397 /* If q is NULL, then we made it to the end of the list. Determine what to do now */
mkersh3 0:e7ca326e76ee 398 if (q == NULL) {
mkersh3 0:e7ca326e76ee 399 if (iprh_prev != NULL) {
mkersh3 0:e7ca326e76ee 400 /* this is (for now), the fragment with the highest offset:
mkersh3 0:e7ca326e76ee 401 * chain it to the last fragment */
mkersh3 0:e7ca326e76ee 402 #if IP_REASS_CHECK_OVERLAP
mkersh3 0:e7ca326e76ee 403 LWIP_ASSERT("check fragments don't overlap", iprh_prev->end <= iprh->start);
mkersh3 0:e7ca326e76ee 404 #endif /* IP_REASS_CHECK_OVERLAP */
mkersh3 0:e7ca326e76ee 405 iprh_prev->next_pbuf = new_p;
mkersh3 0:e7ca326e76ee 406 if (iprh_prev->end != iprh->start) {
mkersh3 0:e7ca326e76ee 407 valid = 0;
mkersh3 0:e7ca326e76ee 408 }
mkersh3 0:e7ca326e76ee 409 } else {
mkersh3 0:e7ca326e76ee 410 #if IP_REASS_CHECK_OVERLAP
mkersh3 0:e7ca326e76ee 411 LWIP_ASSERT("no previous fragment, this must be the first fragment!",
mkersh3 0:e7ca326e76ee 412 ipr->p == NULL);
mkersh3 0:e7ca326e76ee 413 #endif /* IP_REASS_CHECK_OVERLAP */
mkersh3 0:e7ca326e76ee 414 /* this is the first fragment we ever received for this ip datagram */
mkersh3 0:e7ca326e76ee 415 ipr->p = new_p;
mkersh3 0:e7ca326e76ee 416 }
mkersh3 0:e7ca326e76ee 417 }
mkersh3 0:e7ca326e76ee 418
mkersh3 0:e7ca326e76ee 419 /* At this point, the validation part begins: */
mkersh3 0:e7ca326e76ee 420 /* If we already received the last fragment */
mkersh3 0:e7ca326e76ee 421 if ((ipr->flags & IP_REASS_FLAG_LASTFRAG) != 0) {
mkersh3 0:e7ca326e76ee 422 /* and had no wholes so far */
mkersh3 0:e7ca326e76ee 423 if (valid) {
mkersh3 0:e7ca326e76ee 424 /* then check if the rest of the fragments is here */
mkersh3 0:e7ca326e76ee 425 /* Check if the queue starts with the first datagram */
mkersh3 0:e7ca326e76ee 426 if (((struct ip_reass_helper*)ipr->p->payload)->start != 0) {
mkersh3 0:e7ca326e76ee 427 valid = 0;
mkersh3 0:e7ca326e76ee 428 } else {
mkersh3 0:e7ca326e76ee 429 /* and check that there are no wholes after this datagram */
mkersh3 0:e7ca326e76ee 430 iprh_prev = iprh;
mkersh3 0:e7ca326e76ee 431 q = iprh->next_pbuf;
mkersh3 0:e7ca326e76ee 432 while (q != NULL) {
mkersh3 0:e7ca326e76ee 433 iprh = (struct ip_reass_helper*)q->payload;
mkersh3 0:e7ca326e76ee 434 if (iprh_prev->end != iprh->start) {
mkersh3 0:e7ca326e76ee 435 valid = 0;
mkersh3 0:e7ca326e76ee 436 break;
mkersh3 0:e7ca326e76ee 437 }
mkersh3 0:e7ca326e76ee 438 iprh_prev = iprh;
mkersh3 0:e7ca326e76ee 439 q = iprh->next_pbuf;
mkersh3 0:e7ca326e76ee 440 }
mkersh3 0:e7ca326e76ee 441 /* if still valid, all fragments are received
mkersh3 0:e7ca326e76ee 442 * (because to the MF==0 already arrived */
mkersh3 0:e7ca326e76ee 443 if (valid) {
mkersh3 0:e7ca326e76ee 444 LWIP_ASSERT("sanity check", ipr->p != NULL);
mkersh3 0:e7ca326e76ee 445 LWIP_ASSERT("sanity check",
mkersh3 0:e7ca326e76ee 446 ((struct ip_reass_helper*)ipr->p->payload) != iprh);
mkersh3 0:e7ca326e76ee 447 LWIP_ASSERT("validate_datagram:next_pbuf!=NULL",
mkersh3 0:e7ca326e76ee 448 iprh->next_pbuf == NULL);
mkersh3 0:e7ca326e76ee 449 LWIP_ASSERT("validate_datagram:datagram end!=datagram len",
mkersh3 0:e7ca326e76ee 450 iprh->end == ipr->datagram_len);
mkersh3 0:e7ca326e76ee 451 }
mkersh3 0:e7ca326e76ee 452 }
mkersh3 0:e7ca326e76ee 453 }
mkersh3 0:e7ca326e76ee 454 /* If valid is 0 here, there are some fragments missing in the middle
mkersh3 0:e7ca326e76ee 455 * (since MF == 0 has already arrived). Such datagrams simply time out if
mkersh3 0:e7ca326e76ee 456 * no more fragments are received... */
mkersh3 0:e7ca326e76ee 457 return valid;
mkersh3 0:e7ca326e76ee 458 }
mkersh3 0:e7ca326e76ee 459 /* If we come here, not all fragments were received, yet! */
mkersh3 0:e7ca326e76ee 460 return 0; /* not yet valid! */
mkersh3 0:e7ca326e76ee 461 #if IP_REASS_CHECK_OVERLAP
mkersh3 0:e7ca326e76ee 462 freepbuf:
mkersh3 0:e7ca326e76ee 463 ip_reass_pbufcount -= pbuf_clen(new_p);
mkersh3 0:e7ca326e76ee 464 pbuf_free(new_p);
mkersh3 0:e7ca326e76ee 465 return 0;
mkersh3 0:e7ca326e76ee 466 #endif /* IP_REASS_CHECK_OVERLAP */
mkersh3 0:e7ca326e76ee 467 }
mkersh3 0:e7ca326e76ee 468
mkersh3 0:e7ca326e76ee 469 /**
mkersh3 0:e7ca326e76ee 470 * Reassembles incoming IP fragments into an IP datagram.
mkersh3 0:e7ca326e76ee 471 *
mkersh3 0:e7ca326e76ee 472 * @param p points to a pbuf chain of the fragment
mkersh3 0:e7ca326e76ee 473 * @return NULL if reassembly is incomplete, ? otherwise
mkersh3 0:e7ca326e76ee 474 */
mkersh3 0:e7ca326e76ee 475 struct pbuf *
mkersh3 0:e7ca326e76ee 476 ip_reass(struct pbuf *p)
mkersh3 0:e7ca326e76ee 477 {
mkersh3 0:e7ca326e76ee 478 struct pbuf *r;
mkersh3 0:e7ca326e76ee 479 struct ip_hdr *fraghdr;
mkersh3 0:e7ca326e76ee 480 struct ip_reassdata *ipr;
mkersh3 0:e7ca326e76ee 481 struct ip_reass_helper *iprh;
mkersh3 0:e7ca326e76ee 482 u16_t offset, len;
mkersh3 0:e7ca326e76ee 483 u8_t clen;
mkersh3 0:e7ca326e76ee 484 struct ip_reassdata *ipr_prev = NULL;
mkersh3 0:e7ca326e76ee 485
mkersh3 0:e7ca326e76ee 486 IPFRAG_STATS_INC(ip_frag.recv);
mkersh3 0:e7ca326e76ee 487 snmp_inc_ipreasmreqds();
mkersh3 0:e7ca326e76ee 488
mkersh3 0:e7ca326e76ee 489 fraghdr = (struct ip_hdr*)p->payload;
mkersh3 0:e7ca326e76ee 490
mkersh3 0:e7ca326e76ee 491 if ((IPH_HL(fraghdr) * 4) != IP_HLEN) {
mkersh3 0:e7ca326e76ee 492 LWIP_DEBUGF(IP_REASS_DEBUG,("ip_reass: IP options currently not supported!\n"));
mkersh3 0:e7ca326e76ee 493 IPFRAG_STATS_INC(ip_frag.err);
mkersh3 0:e7ca326e76ee 494 goto nullreturn;
mkersh3 0:e7ca326e76ee 495 }
mkersh3 0:e7ca326e76ee 496
mkersh3 0:e7ca326e76ee 497 offset = (ntohs(IPH_OFFSET(fraghdr)) & IP_OFFMASK) * 8;
mkersh3 0:e7ca326e76ee 498 len = ntohs(IPH_LEN(fraghdr)) - IPH_HL(fraghdr) * 4;
mkersh3 0:e7ca326e76ee 499
mkersh3 0:e7ca326e76ee 500 /* Check if we are allowed to enqueue more datagrams. */
mkersh3 0:e7ca326e76ee 501 clen = pbuf_clen(p);
mkersh3 0:e7ca326e76ee 502 if ((ip_reass_pbufcount + clen) > IP_REASS_MAX_PBUFS) {
mkersh3 0:e7ca326e76ee 503 #if IP_REASS_FREE_OLDEST
mkersh3 0:e7ca326e76ee 504 if (!ip_reass_remove_oldest_datagram(fraghdr, clen) ||
mkersh3 0:e7ca326e76ee 505 ((ip_reass_pbufcount + clen) > IP_REASS_MAX_PBUFS))
mkersh3 0:e7ca326e76ee 506 #endif /* IP_REASS_FREE_OLDEST */
mkersh3 0:e7ca326e76ee 507 {
mkersh3 0:e7ca326e76ee 508 /* No datagram could be freed and still too many pbufs enqueued */
mkersh3 0:e7ca326e76ee 509 LWIP_DEBUGF(IP_REASS_DEBUG,("ip_reass: Overflow condition: pbufct=%d, clen=%d, MAX=%d\n",
mkersh3 0:e7ca326e76ee 510 ip_reass_pbufcount, clen, IP_REASS_MAX_PBUFS));
mkersh3 0:e7ca326e76ee 511 IPFRAG_STATS_INC(ip_frag.memerr);
mkersh3 0:e7ca326e76ee 512 /* @todo: send ICMP time exceeded here? */
mkersh3 0:e7ca326e76ee 513 /* drop this pbuf */
mkersh3 0:e7ca326e76ee 514 goto nullreturn;
mkersh3 0:e7ca326e76ee 515 }
mkersh3 0:e7ca326e76ee 516 }
mkersh3 0:e7ca326e76ee 517
mkersh3 0:e7ca326e76ee 518 /* Look for the datagram the fragment belongs to in the current datagram queue,
mkersh3 0:e7ca326e76ee 519 * remembering the previous in the queue for later dequeueing. */
mkersh3 0:e7ca326e76ee 520 for (ipr = reassdatagrams; ipr != NULL; ipr = ipr->next) {
mkersh3 0:e7ca326e76ee 521 /* Check if the incoming fragment matches the one currently present
mkersh3 0:e7ca326e76ee 522 in the reassembly buffer. If so, we proceed with copying the
mkersh3 0:e7ca326e76ee 523 fragment into the buffer. */
mkersh3 0:e7ca326e76ee 524 if (IP_ADDRESSES_AND_ID_MATCH(&ipr->iphdr, fraghdr)) {
mkersh3 0:e7ca326e76ee 525 LWIP_DEBUGF(IP_REASS_DEBUG, ("ip_reass: matching previous fragment ID=%"X16_F"\n",
mkersh3 0:e7ca326e76ee 526 ntohs(IPH_ID(fraghdr))));
mkersh3 0:e7ca326e76ee 527 IPFRAG_STATS_INC(ip_frag.cachehit);
mkersh3 0:e7ca326e76ee 528 break;
mkersh3 0:e7ca326e76ee 529 }
mkersh3 0:e7ca326e76ee 530 ipr_prev = ipr;
mkersh3 0:e7ca326e76ee 531 }
mkersh3 0:e7ca326e76ee 532
mkersh3 0:e7ca326e76ee 533 if (ipr == NULL) {
mkersh3 0:e7ca326e76ee 534 /* Enqueue a new datagram into the datagram queue */
mkersh3 0:e7ca326e76ee 535 ipr = ip_reass_enqueue_new_datagram(fraghdr, clen);
mkersh3 0:e7ca326e76ee 536 /* Bail if unable to enqueue */
mkersh3 0:e7ca326e76ee 537 if(ipr == NULL) {
mkersh3 0:e7ca326e76ee 538 goto nullreturn;
mkersh3 0:e7ca326e76ee 539 }
mkersh3 0:e7ca326e76ee 540 } else {
mkersh3 0:e7ca326e76ee 541 if (((ntohs(IPH_OFFSET(fraghdr)) & IP_OFFMASK) == 0) &&
mkersh3 0:e7ca326e76ee 542 ((ntohs(IPH_OFFSET(&ipr->iphdr)) & IP_OFFMASK) != 0)) {
mkersh3 0:e7ca326e76ee 543 /* ipr->iphdr is not the header from the first fragment, but fraghdr is
mkersh3 0:e7ca326e76ee 544 * -> copy fraghdr into ipr->iphdr since we want to have the header
mkersh3 0:e7ca326e76ee 545 * of the first fragment (for ICMP time exceeded and later, for copying
mkersh3 0:e7ca326e76ee 546 * all options, if supported)*/
mkersh3 0:e7ca326e76ee 547 SMEMCPY(&ipr->iphdr, fraghdr, IP_HLEN);
mkersh3 0:e7ca326e76ee 548 }
mkersh3 0:e7ca326e76ee 549 }
mkersh3 0:e7ca326e76ee 550 /* Track the current number of pbufs current 'in-flight', in order to limit
mkersh3 0:e7ca326e76ee 551 the number of fragments that may be enqueued at any one time */
mkersh3 0:e7ca326e76ee 552 ip_reass_pbufcount += clen;
mkersh3 0:e7ca326e76ee 553
mkersh3 0:e7ca326e76ee 554 /* At this point, we have either created a new entry or pointing
mkersh3 0:e7ca326e76ee 555 * to an existing one */
mkersh3 0:e7ca326e76ee 556
mkersh3 0:e7ca326e76ee 557 /* check for 'no more fragments', and update queue entry*/
mkersh3 0:e7ca326e76ee 558 if ((IPH_OFFSET(fraghdr) & PP_NTOHS(IP_MF)) == 0) {
mkersh3 0:e7ca326e76ee 559 ipr->flags |= IP_REASS_FLAG_LASTFRAG;
mkersh3 0:e7ca326e76ee 560 ipr->datagram_len = offset + len;
mkersh3 0:e7ca326e76ee 561 LWIP_DEBUGF(IP_REASS_DEBUG,
mkersh3 0:e7ca326e76ee 562 ("ip_reass: last fragment seen, total len %"S16_F"\n",
mkersh3 0:e7ca326e76ee 563 ipr->datagram_len));
mkersh3 0:e7ca326e76ee 564 }
mkersh3 0:e7ca326e76ee 565 /* find the right place to insert this pbuf */
mkersh3 0:e7ca326e76ee 566 /* @todo: trim pbufs if fragments are overlapping */
mkersh3 0:e7ca326e76ee 567 if (ip_reass_chain_frag_into_datagram_and_validate(ipr, p)) {
mkersh3 0:e7ca326e76ee 568 /* the totally last fragment (flag more fragments = 0) was received at least
mkersh3 0:e7ca326e76ee 569 * once AND all fragments are received */
mkersh3 0:e7ca326e76ee 570 ipr->datagram_len += IP_HLEN;
mkersh3 0:e7ca326e76ee 571
mkersh3 0:e7ca326e76ee 572 /* save the second pbuf before copying the header over the pointer */
mkersh3 0:e7ca326e76ee 573 r = ((struct ip_reass_helper*)ipr->p->payload)->next_pbuf;
mkersh3 0:e7ca326e76ee 574
mkersh3 0:e7ca326e76ee 575 /* copy the original ip header back to the first pbuf */
mkersh3 0:e7ca326e76ee 576 fraghdr = (struct ip_hdr*)(ipr->p->payload);
mkersh3 0:e7ca326e76ee 577 SMEMCPY(fraghdr, &ipr->iphdr, IP_HLEN);
mkersh3 0:e7ca326e76ee 578 IPH_LEN_SET(fraghdr, htons(ipr->datagram_len));
mkersh3 0:e7ca326e76ee 579 IPH_OFFSET_SET(fraghdr, 0);
mkersh3 0:e7ca326e76ee 580 IPH_CHKSUM_SET(fraghdr, 0);
mkersh3 0:e7ca326e76ee 581 /* @todo: do we need to set calculate the correct checksum? */
mkersh3 0:e7ca326e76ee 582 IPH_CHKSUM_SET(fraghdr, inet_chksum(fraghdr, IP_HLEN));
mkersh3 0:e7ca326e76ee 583
mkersh3 0:e7ca326e76ee 584 p = ipr->p;
mkersh3 0:e7ca326e76ee 585
mkersh3 0:e7ca326e76ee 586 /* chain together the pbufs contained within the reass_data list. */
mkersh3 0:e7ca326e76ee 587 while(r != NULL) {
mkersh3 0:e7ca326e76ee 588 iprh = (struct ip_reass_helper*)r->payload;
mkersh3 0:e7ca326e76ee 589
mkersh3 0:e7ca326e76ee 590 /* hide the ip header for every succeding fragment */
mkersh3 0:e7ca326e76ee 591 pbuf_header(r, -IP_HLEN);
mkersh3 0:e7ca326e76ee 592 pbuf_cat(p, r);
mkersh3 0:e7ca326e76ee 593 r = iprh->next_pbuf;
mkersh3 0:e7ca326e76ee 594 }
mkersh3 0:e7ca326e76ee 595 /* release the sources allocate for the fragment queue entry */
mkersh3 0:e7ca326e76ee 596 ip_reass_dequeue_datagram(ipr, ipr_prev);
mkersh3 0:e7ca326e76ee 597
mkersh3 0:e7ca326e76ee 598 /* and adjust the number of pbufs currently queued for reassembly. */
mkersh3 0:e7ca326e76ee 599 ip_reass_pbufcount -= pbuf_clen(p);
mkersh3 0:e7ca326e76ee 600
mkersh3 0:e7ca326e76ee 601 /* Return the pbuf chain */
mkersh3 0:e7ca326e76ee 602 return p;
mkersh3 0:e7ca326e76ee 603 }
mkersh3 0:e7ca326e76ee 604 /* the datagram is not (yet?) reassembled completely */
mkersh3 0:e7ca326e76ee 605 LWIP_DEBUGF(IP_REASS_DEBUG,("ip_reass_pbufcount: %d out\n", ip_reass_pbufcount));
mkersh3 0:e7ca326e76ee 606 return NULL;
mkersh3 0:e7ca326e76ee 607
mkersh3 0:e7ca326e76ee 608 nullreturn:
mkersh3 0:e7ca326e76ee 609 LWIP_DEBUGF(IP_REASS_DEBUG,("ip_reass: nullreturn\n"));
mkersh3 0:e7ca326e76ee 610 IPFRAG_STATS_INC(ip_frag.drop);
mkersh3 0:e7ca326e76ee 611 pbuf_free(p);
mkersh3 0:e7ca326e76ee 612 return NULL;
mkersh3 0:e7ca326e76ee 613 }
mkersh3 0:e7ca326e76ee 614 #endif /* IP_REASSEMBLY */
mkersh3 0:e7ca326e76ee 615
mkersh3 0:e7ca326e76ee 616 #if IP_FRAG
mkersh3 0:e7ca326e76ee 617 #if IP_FRAG_USES_STATIC_BUF
mkersh3 0:e7ca326e76ee 618 static u8_t buf[LWIP_MEM_ALIGN_SIZE(IP_FRAG_MAX_MTU + MEM_ALIGNMENT - 1)];
mkersh3 0:e7ca326e76ee 619 #else /* IP_FRAG_USES_STATIC_BUF */
mkersh3 0:e7ca326e76ee 620
mkersh3 0:e7ca326e76ee 621 #if !LWIP_NETIF_TX_SINGLE_PBUF
mkersh3 0:e7ca326e76ee 622 /** Allocate a new struct pbuf_custom_ref */
mkersh3 0:e7ca326e76ee 623 static struct pbuf_custom_ref*
mkersh3 0:e7ca326e76ee 624 ip_frag_alloc_pbuf_custom_ref(void)
mkersh3 0:e7ca326e76ee 625 {
mkersh3 0:e7ca326e76ee 626 return (struct pbuf_custom_ref*)memp_malloc(MEMP_FRAG_PBUF);
mkersh3 0:e7ca326e76ee 627 }
mkersh3 0:e7ca326e76ee 628
mkersh3 0:e7ca326e76ee 629 /** Free a struct pbuf_custom_ref */
mkersh3 0:e7ca326e76ee 630 static void
mkersh3 0:e7ca326e76ee 631 ip_frag_free_pbuf_custom_ref(struct pbuf_custom_ref* p)
mkersh3 0:e7ca326e76ee 632 {
mkersh3 0:e7ca326e76ee 633 LWIP_ASSERT("p != NULL", p != NULL);
mkersh3 0:e7ca326e76ee 634 memp_free(MEMP_FRAG_PBUF, p);
mkersh3 0:e7ca326e76ee 635 }
mkersh3 0:e7ca326e76ee 636
mkersh3 0:e7ca326e76ee 637 /** Free-callback function to free a 'struct pbuf_custom_ref', called by
mkersh3 0:e7ca326e76ee 638 * pbuf_free. */
mkersh3 0:e7ca326e76ee 639 static void
mkersh3 0:e7ca326e76ee 640 ipfrag_free_pbuf_custom(struct pbuf *p)
mkersh3 0:e7ca326e76ee 641 {
mkersh3 0:e7ca326e76ee 642 struct pbuf_custom_ref *pcr = (struct pbuf_custom_ref*)p;
mkersh3 0:e7ca326e76ee 643 LWIP_ASSERT("pcr != NULL", pcr != NULL);
mkersh3 0:e7ca326e76ee 644 LWIP_ASSERT("pcr == p", (void*)pcr == (void*)p);
mkersh3 0:e7ca326e76ee 645 if (pcr->original != NULL) {
mkersh3 0:e7ca326e76ee 646 pbuf_free(pcr->original);
mkersh3 0:e7ca326e76ee 647 }
mkersh3 0:e7ca326e76ee 648 ip_frag_free_pbuf_custom_ref(pcr);
mkersh3 0:e7ca326e76ee 649 }
mkersh3 0:e7ca326e76ee 650 #endif /* !LWIP_NETIF_TX_SINGLE_PBUF */
mkersh3 0:e7ca326e76ee 651 #endif /* IP_FRAG_USES_STATIC_BUF */
mkersh3 0:e7ca326e76ee 652
mkersh3 0:e7ca326e76ee 653 /**
mkersh3 0:e7ca326e76ee 654 * Fragment an IP datagram if too large for the netif.
mkersh3 0:e7ca326e76ee 655 *
mkersh3 0:e7ca326e76ee 656 * Chop the datagram in MTU sized chunks and send them in order
mkersh3 0:e7ca326e76ee 657 * by using a fixed size static memory buffer (PBUF_REF) or
mkersh3 0:e7ca326e76ee 658 * point PBUF_REFs into p (depending on IP_FRAG_USES_STATIC_BUF).
mkersh3 0:e7ca326e76ee 659 *
mkersh3 0:e7ca326e76ee 660 * @param p ip packet to send
mkersh3 0:e7ca326e76ee 661 * @param netif the netif on which to send
mkersh3 0:e7ca326e76ee 662 * @param dest destination ip address to which to send
mkersh3 0:e7ca326e76ee 663 *
mkersh3 0:e7ca326e76ee 664 * @return ERR_OK if sent successfully, err_t otherwise
mkersh3 0:e7ca326e76ee 665 */
mkersh3 0:e7ca326e76ee 666 err_t
mkersh3 0:e7ca326e76ee 667 ip_frag(struct pbuf *p, struct netif *netif, ip_addr_t *dest)
mkersh3 0:e7ca326e76ee 668 {
mkersh3 0:e7ca326e76ee 669 struct pbuf *rambuf;
mkersh3 0:e7ca326e76ee 670 #if IP_FRAG_USES_STATIC_BUF
mkersh3 0:e7ca326e76ee 671 struct pbuf *header;
mkersh3 0:e7ca326e76ee 672 #else
mkersh3 0:e7ca326e76ee 673 #if !LWIP_NETIF_TX_SINGLE_PBUF
mkersh3 0:e7ca326e76ee 674 struct pbuf *newpbuf;
mkersh3 0:e7ca326e76ee 675 #endif
mkersh3 0:e7ca326e76ee 676 struct ip_hdr *original_iphdr;
mkersh3 0:e7ca326e76ee 677 #endif
mkersh3 0:e7ca326e76ee 678 struct ip_hdr *iphdr;
mkersh3 0:e7ca326e76ee 679 u16_t nfb;
mkersh3 0:e7ca326e76ee 680 u16_t left, cop;
mkersh3 0:e7ca326e76ee 681 u16_t mtu = netif->mtu;
mkersh3 0:e7ca326e76ee 682 u16_t ofo, omf;
mkersh3 0:e7ca326e76ee 683 u16_t last;
mkersh3 0:e7ca326e76ee 684 u16_t poff = IP_HLEN;
mkersh3 0:e7ca326e76ee 685 u16_t tmp;
mkersh3 0:e7ca326e76ee 686 #if !IP_FRAG_USES_STATIC_BUF && !LWIP_NETIF_TX_SINGLE_PBUF
mkersh3 0:e7ca326e76ee 687 u16_t newpbuflen = 0;
mkersh3 0:e7ca326e76ee 688 u16_t left_to_copy;
mkersh3 0:e7ca326e76ee 689 #endif
mkersh3 0:e7ca326e76ee 690
mkersh3 0:e7ca326e76ee 691 /* Get a RAM based MTU sized pbuf */
mkersh3 0:e7ca326e76ee 692 #if IP_FRAG_USES_STATIC_BUF
mkersh3 0:e7ca326e76ee 693 /* When using a static buffer, we use a PBUF_REF, which we will
mkersh3 0:e7ca326e76ee 694 * use to reference the packet (without link header).
mkersh3 0:e7ca326e76ee 695 * Layer and length is irrelevant.
mkersh3 0:e7ca326e76ee 696 */
mkersh3 0:e7ca326e76ee 697 rambuf = pbuf_alloc(PBUF_LINK, 0, PBUF_REF);
mkersh3 0:e7ca326e76ee 698 if (rambuf == NULL) {
mkersh3 0:e7ca326e76ee 699 LWIP_DEBUGF(IP_REASS_DEBUG, ("ip_frag: pbuf_alloc(PBUF_LINK, 0, PBUF_REF) failed\n"));
mkersh3 0:e7ca326e76ee 700 return ERR_MEM;
mkersh3 0:e7ca326e76ee 701 }
mkersh3 0:e7ca326e76ee 702 rambuf->tot_len = rambuf->len = mtu;
mkersh3 0:e7ca326e76ee 703 rambuf->payload = LWIP_MEM_ALIGN((void *)buf);
mkersh3 0:e7ca326e76ee 704
mkersh3 0:e7ca326e76ee 705 /* Copy the IP header in it */
mkersh3 0:e7ca326e76ee 706 iphdr = (struct ip_hdr *)rambuf->payload;
mkersh3 0:e7ca326e76ee 707 SMEMCPY(iphdr, p->payload, IP_HLEN);
mkersh3 0:e7ca326e76ee 708 #else /* IP_FRAG_USES_STATIC_BUF */
mkersh3 0:e7ca326e76ee 709 original_iphdr = (struct ip_hdr *)p->payload;
mkersh3 0:e7ca326e76ee 710 iphdr = original_iphdr;
mkersh3 0:e7ca326e76ee 711 #endif /* IP_FRAG_USES_STATIC_BUF */
mkersh3 0:e7ca326e76ee 712
mkersh3 0:e7ca326e76ee 713 /* Save original offset */
mkersh3 0:e7ca326e76ee 714 tmp = ntohs(IPH_OFFSET(iphdr));
mkersh3 0:e7ca326e76ee 715 ofo = tmp & IP_OFFMASK;
mkersh3 0:e7ca326e76ee 716 omf = tmp & IP_MF;
mkersh3 0:e7ca326e76ee 717
mkersh3 0:e7ca326e76ee 718 left = p->tot_len - IP_HLEN;
mkersh3 0:e7ca326e76ee 719
mkersh3 0:e7ca326e76ee 720 nfb = (mtu - IP_HLEN) / 8;
mkersh3 0:e7ca326e76ee 721
mkersh3 0:e7ca326e76ee 722 while (left) {
mkersh3 0:e7ca326e76ee 723 last = (left <= mtu - IP_HLEN);
mkersh3 0:e7ca326e76ee 724
mkersh3 0:e7ca326e76ee 725 /* Set new offset and MF flag */
mkersh3 0:e7ca326e76ee 726 tmp = omf | (IP_OFFMASK & (ofo));
mkersh3 0:e7ca326e76ee 727 if (!last) {
mkersh3 0:e7ca326e76ee 728 tmp = tmp | IP_MF;
mkersh3 0:e7ca326e76ee 729 }
mkersh3 0:e7ca326e76ee 730
mkersh3 0:e7ca326e76ee 731 /* Fill this fragment */
mkersh3 0:e7ca326e76ee 732 cop = last ? left : nfb * 8;
mkersh3 0:e7ca326e76ee 733
mkersh3 0:e7ca326e76ee 734 #if IP_FRAG_USES_STATIC_BUF
mkersh3 0:e7ca326e76ee 735 poff += pbuf_copy_partial(p, (u8_t*)iphdr + IP_HLEN, cop, poff);
mkersh3 0:e7ca326e76ee 736 #else /* IP_FRAG_USES_STATIC_BUF */
mkersh3 0:e7ca326e76ee 737 #if LWIP_NETIF_TX_SINGLE_PBUF
mkersh3 0:e7ca326e76ee 738 rambuf = pbuf_alloc(PBUF_IP, cop, PBUF_RAM);
mkersh3 0:e7ca326e76ee 739 if (rambuf == NULL) {
mkersh3 0:e7ca326e76ee 740 return ERR_MEM;
mkersh3 0:e7ca326e76ee 741 }
mkersh3 0:e7ca326e76ee 742 LWIP_ASSERT("this needs a pbuf in one piece!",
mkersh3 0:e7ca326e76ee 743 (rambuf->len == rambuf->tot_len) && (rambuf->next == NULL));
mkersh3 0:e7ca326e76ee 744 poff += pbuf_copy_partial(p, rambuf->payload, cop, poff);
mkersh3 0:e7ca326e76ee 745 /* make room for the IP header */
mkersh3 0:e7ca326e76ee 746 if(pbuf_header(rambuf, IP_HLEN)) {
mkersh3 0:e7ca326e76ee 747 pbuf_free(rambuf);
mkersh3 0:e7ca326e76ee 748 return ERR_MEM;
mkersh3 0:e7ca326e76ee 749 }
mkersh3 0:e7ca326e76ee 750 /* fill in the IP header */
mkersh3 0:e7ca326e76ee 751 SMEMCPY(rambuf->payload, original_iphdr, IP_HLEN);
mkersh3 0:e7ca326e76ee 752 iphdr = rambuf->payload;
mkersh3 0:e7ca326e76ee 753 #else /* LWIP_NETIF_TX_SINGLE_PBUF */
mkersh3 0:e7ca326e76ee 754 /* When not using a static buffer, create a chain of pbufs.
mkersh3 0:e7ca326e76ee 755 * The first will be a PBUF_RAM holding the link and IP header.
mkersh3 0:e7ca326e76ee 756 * The rest will be PBUF_REFs mirroring the pbuf chain to be fragged,
mkersh3 0:e7ca326e76ee 757 * but limited to the size of an mtu.
mkersh3 0:e7ca326e76ee 758 */
mkersh3 0:e7ca326e76ee 759 rambuf = pbuf_alloc(PBUF_LINK, IP_HLEN, PBUF_RAM);
mkersh3 0:e7ca326e76ee 760 if (rambuf == NULL) {
mkersh3 0:e7ca326e76ee 761 return ERR_MEM;
mkersh3 0:e7ca326e76ee 762 }
mkersh3 0:e7ca326e76ee 763 LWIP_ASSERT("this needs a pbuf in one piece!",
mkersh3 0:e7ca326e76ee 764 (p->len >= (IP_HLEN)));
mkersh3 0:e7ca326e76ee 765 SMEMCPY(rambuf->payload, original_iphdr, IP_HLEN);
mkersh3 0:e7ca326e76ee 766 iphdr = (struct ip_hdr *)rambuf->payload;
mkersh3 0:e7ca326e76ee 767
mkersh3 0:e7ca326e76ee 768 /* Can just adjust p directly for needed offset. */
mkersh3 0:e7ca326e76ee 769 p->payload = (u8_t *)p->payload + poff;
mkersh3 0:e7ca326e76ee 770 p->len -= poff;
mkersh3 0:e7ca326e76ee 771
mkersh3 0:e7ca326e76ee 772 left_to_copy = cop;
mkersh3 0:e7ca326e76ee 773 while (left_to_copy) {
mkersh3 0:e7ca326e76ee 774 struct pbuf_custom_ref *pcr;
mkersh3 0:e7ca326e76ee 775 newpbuflen = (left_to_copy < p->len) ? left_to_copy : p->len;
mkersh3 0:e7ca326e76ee 776 /* Is this pbuf already empty? */
mkersh3 0:e7ca326e76ee 777 if (!newpbuflen) {
mkersh3 0:e7ca326e76ee 778 p = p->next;
mkersh3 0:e7ca326e76ee 779 continue;
mkersh3 0:e7ca326e76ee 780 }
mkersh3 0:e7ca326e76ee 781 pcr = ip_frag_alloc_pbuf_custom_ref();
mkersh3 0:e7ca326e76ee 782 if (pcr == NULL) {
mkersh3 0:e7ca326e76ee 783 pbuf_free(rambuf);
mkersh3 0:e7ca326e76ee 784 return ERR_MEM;
mkersh3 0:e7ca326e76ee 785 }
mkersh3 0:e7ca326e76ee 786 /* Mirror this pbuf, although we might not need all of it. */
mkersh3 0:e7ca326e76ee 787 newpbuf = pbuf_alloced_custom(PBUF_RAW, newpbuflen, PBUF_REF, &pcr->pc, p->payload, newpbuflen);
mkersh3 0:e7ca326e76ee 788 if (newpbuf == NULL) {
mkersh3 0:e7ca326e76ee 789 ip_frag_free_pbuf_custom_ref(pcr);
mkersh3 0:e7ca326e76ee 790 pbuf_free(rambuf);
mkersh3 0:e7ca326e76ee 791 return ERR_MEM;
mkersh3 0:e7ca326e76ee 792 }
mkersh3 0:e7ca326e76ee 793 pbuf_ref(p);
mkersh3 0:e7ca326e76ee 794 pcr->original = p;
mkersh3 0:e7ca326e76ee 795 pcr->pc.custom_free_function = ipfrag_free_pbuf_custom;
mkersh3 0:e7ca326e76ee 796
mkersh3 0:e7ca326e76ee 797 /* Add it to end of rambuf's chain, but using pbuf_cat, not pbuf_chain
mkersh3 0:e7ca326e76ee 798 * so that it is removed when pbuf_dechain is later called on rambuf.
mkersh3 0:e7ca326e76ee 799 */
mkersh3 0:e7ca326e76ee 800 pbuf_cat(rambuf, newpbuf);
mkersh3 0:e7ca326e76ee 801 left_to_copy -= newpbuflen;
mkersh3 0:e7ca326e76ee 802 if (left_to_copy) {
mkersh3 0:e7ca326e76ee 803 p = p->next;
mkersh3 0:e7ca326e76ee 804 }
mkersh3 0:e7ca326e76ee 805 }
mkersh3 0:e7ca326e76ee 806 poff = newpbuflen;
mkersh3 0:e7ca326e76ee 807 #endif /* LWIP_NETIF_TX_SINGLE_PBUF */
mkersh3 0:e7ca326e76ee 808 #endif /* IP_FRAG_USES_STATIC_BUF */
mkersh3 0:e7ca326e76ee 809
mkersh3 0:e7ca326e76ee 810 /* Correct header */
mkersh3 0:e7ca326e76ee 811 IPH_OFFSET_SET(iphdr, htons(tmp));
mkersh3 0:e7ca326e76ee 812 IPH_LEN_SET(iphdr, htons(cop + IP_HLEN));
mkersh3 0:e7ca326e76ee 813 IPH_CHKSUM_SET(iphdr, 0);
mkersh3 0:e7ca326e76ee 814 IPH_CHKSUM_SET(iphdr, inet_chksum(iphdr, IP_HLEN));
mkersh3 0:e7ca326e76ee 815
mkersh3 0:e7ca326e76ee 816 #if IP_FRAG_USES_STATIC_BUF
mkersh3 0:e7ca326e76ee 817 if (last) {
mkersh3 0:e7ca326e76ee 818 pbuf_realloc(rambuf, left + IP_HLEN);
mkersh3 0:e7ca326e76ee 819 }
mkersh3 0:e7ca326e76ee 820
mkersh3 0:e7ca326e76ee 821 /* This part is ugly: we alloc a RAM based pbuf for
mkersh3 0:e7ca326e76ee 822 * the link level header for each chunk and then
mkersh3 0:e7ca326e76ee 823 * free it.A PBUF_ROM style pbuf for which pbuf_header
mkersh3 0:e7ca326e76ee 824 * worked would make things simpler.
mkersh3 0:e7ca326e76ee 825 */
mkersh3 0:e7ca326e76ee 826 header = pbuf_alloc(PBUF_LINK, 0, PBUF_RAM);
mkersh3 0:e7ca326e76ee 827 if (header != NULL) {
mkersh3 0:e7ca326e76ee 828 pbuf_chain(header, rambuf);
mkersh3 0:e7ca326e76ee 829 netif->output(netif, header, dest);
mkersh3 0:e7ca326e76ee 830 IPFRAG_STATS_INC(ip_frag.xmit);
mkersh3 0:e7ca326e76ee 831 snmp_inc_ipfragcreates();
mkersh3 0:e7ca326e76ee 832 pbuf_free(header);
mkersh3 0:e7ca326e76ee 833 } else {
mkersh3 0:e7ca326e76ee 834 LWIP_DEBUGF(IP_REASS_DEBUG, ("ip_frag: pbuf_alloc() for header failed\n"));
mkersh3 0:e7ca326e76ee 835 pbuf_free(rambuf);
mkersh3 0:e7ca326e76ee 836 return ERR_MEM;
mkersh3 0:e7ca326e76ee 837 }
mkersh3 0:e7ca326e76ee 838 #else /* IP_FRAG_USES_STATIC_BUF */
mkersh3 0:e7ca326e76ee 839 /* No need for separate header pbuf - we allowed room for it in rambuf
mkersh3 0:e7ca326e76ee 840 * when allocated.
mkersh3 0:e7ca326e76ee 841 */
mkersh3 0:e7ca326e76ee 842 netif->output(netif, rambuf, dest);
mkersh3 0:e7ca326e76ee 843 IPFRAG_STATS_INC(ip_frag.xmit);
mkersh3 0:e7ca326e76ee 844
mkersh3 0:e7ca326e76ee 845 /* Unfortunately we can't reuse rambuf - the hardware may still be
mkersh3 0:e7ca326e76ee 846 * using the buffer. Instead we free it (and the ensuing chain) and
mkersh3 0:e7ca326e76ee 847 * recreate it next time round the loop. If we're lucky the hardware
mkersh3 0:e7ca326e76ee 848 * will have already sent the packet, the free will really free, and
mkersh3 0:e7ca326e76ee 849 * there will be zero memory penalty.
mkersh3 0:e7ca326e76ee 850 */
mkersh3 0:e7ca326e76ee 851
mkersh3 0:e7ca326e76ee 852 pbuf_free(rambuf);
mkersh3 0:e7ca326e76ee 853 #endif /* IP_FRAG_USES_STATIC_BUF */
mkersh3 0:e7ca326e76ee 854 left -= cop;
mkersh3 0:e7ca326e76ee 855 ofo += nfb;
mkersh3 0:e7ca326e76ee 856 }
mkersh3 0:e7ca326e76ee 857 #if IP_FRAG_USES_STATIC_BUF
mkersh3 0:e7ca326e76ee 858 pbuf_free(rambuf);
mkersh3 0:e7ca326e76ee 859 #endif /* IP_FRAG_USES_STATIC_BUF */
mkersh3 0:e7ca326e76ee 860 snmp_inc_ipfragoks();
mkersh3 0:e7ca326e76ee 861 return ERR_OK;
mkersh3 0:e7ca326e76ee 862 }
mkersh3 0:e7ca326e76ee 863 #endif /* IP_FRAG */