debuggers.hg

annotate stubdom/lwip.patch-cvs @ 22848:6341fe0f4e5a

Added tag 4.1.0-rc2 for changeset 9dca60d88c63
author Keir Fraser <keir@xen.org>
date Tue Jan 25 14:06:55 2011 +0000 (2011-01-25)
parents a8603b2fb786
children
rev   line source
keir@18114 1 ? .ChangeLog.swp
keir@18114 2 ? ChangeLog
keir@18114 3 Index: CHANGELOG
keir@18114 4 ===================================================================
keir@18114 5 RCS file: /sources/lwip/lwip/CHANGELOG,v
keir@18114 6 retrieving revision 1.300
keir@18114 7 retrieving revision 1.318
keir@18114 8 diff -u -p -r1.300 -r1.318
keir@18114 9 --- CHANGELOG 23 Mar 2008 13:49:39 -0000 1.300
keir@18114 10 +++ CHANGELOG 14 Jul 2008 20:12:36 -0000 1.318
keir@18114 11 @@ -19,9 +19,77 @@ HISTORY
keir@18114 12
keir@18114 13 ++ New features:
keir@18114 14
keir@18114 15 + 2008-06-30 Simon Goldschmidt
keir@18114 16 + * mem.c, opt.h, stats.h: fixed bug #21433: Calling mem_free/pbuf_free from
keir@18114 17 + interrupt context isn't safe: LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT allows
keir@18114 18 + mem_free to run between mem_malloc iterations. Added illegal counter for
keir@18114 19 + mem stats.
keir@18114 20 +
keir@18114 21 + 2008-06-27 Simon Goldschmidt
keir@18114 22 + * stats.h/.c, some other files: patch #6483: stats module improvement:
keir@18114 23 + Added defines to display each module's statistic individually, added stats
keir@18114 24 + defines for MEM, MEMP and SYS modules, removed (unused) rexmit counter.
keir@18114 25 +
keir@18114 26 + 2008-06-17 Simon Goldschmidt
keir@18114 27 + * err.h: patch #6459: Made err_t overridable to use a more efficient type
keir@18114 28 + (define LWIP_ERR_T in cc.h)
keir@18114 29 +
keir@18114 30 + 2008-06-17 Simon Goldschmidt
keir@18114 31 + * slipif.c: patch #6480: Added a configuration option for slipif for symmetry
keir@18114 32 + to loopif
keir@18114 33 +
keir@18114 34 + 2008-06-17 Simon Goldschmidt (patch by Luca Ceresoli)
keir@18114 35 + * netif.c, loopif.c, ip.c, netif.h, loopif.h, opt.h: Checked in slightly
keir@18114 36 + modified version of patch # 6370: Moved loopif code to netif.c so that
keir@18114 37 + loopback traffic is supported on all netifs (all local IPs).
keir@18114 38 + Added option to limit loopback packets for each netifs.
keir@18114 39 +
keir@18114 40
keir@18114 41 ++ Bugfixes:
keir@18114 42
keir@18114 43 + 2008-08-14 Simon Goldschmidt
keir@18114 44 + * api_msg.c: fixed bug #23847: do_close_internal references freed memory (when
keir@18114 45 + tcp_close returns != ERR_OK)
keir@18114 46 +
keir@18114 47 + 2008-07-08 Frédéric Bernon
keir@18114 48 + * stats.h: Fix some build bugs introduced with patch #6483 (missing some parameters
keir@18114 49 + in macros, mainly if MEM_STATS=0 and MEMP_STATS=0).
keir@18114 50 +
keir@18114 51 + 2008-06-24 Jonathan Larmour
keir@18114 52 + * tcp_in.c: Fix for bug #23693 as suggested by Art R. Ensure cseg is unused
keir@18114 53 + if tcp_seg_copy fails.
keir@18114 54 +
keir@18114 55 + 2008-06-17 Simon Goldschmidt
keir@18114 56 + * inet_chksum.c: Checked in some ideas of patch #6460 (loop optimizations)
keir@18114 57 + and created defines for swapping bytes and folding u32 to u16.
keir@18114 58 +
keir@18114 59 + 2008-05-30 Kieran Mansley
keir@18114 60 + * tcp_in.c Remove redundant "if" statement, and use real rcv_wnd
keir@18114 61 + rather than rcv_ann_wnd when deciding if packets are in-window.
keir@18114 62 + Contributed by <arasmussen@consultant.datasys.swri.edu>
keir@18114 63 +
keir@18114 64 + 2008-05-30 Kieran Mansley
keir@18114 65 + * mem.h: Fix BUG#23254. Change macro definition of mem_* to allow
keir@18114 66 + passing as function pointers when MEM_LIBC_MALLOC is defined.
keir@18114 67 +
keir@18114 68 + 2008-05-09 Jonathan Larmour
keir@18114 69 + * err.h, err.c, sockets.c: Fix bug #23119: Reorder timeout error code to
keir@18114 70 + stop it being treated as a fatal error.
keir@18114 71 +
keir@18114 72 + 2008-04-15 Simon Goldschmidt
keir@18114 73 + * dhcp.c: fixed bug #22804: dhcp_stop doesn't clear NETIF_FLAG_DHCP
keir@18114 74 + (flag now cleared)
keir@18114 75 +
keir@18114 76 + 2008-03-27 Simon Goldschmidt
keir@18114 77 + * mem.c, tcpip.c, tcpip.h, opt.h: fixed bug #21433 (Calling mem_free/pbuf_free
keir@18114 78 + from interrupt context isn't safe): set LWIP_USE_HEAP_FROM_INTERRUPT to 1
keir@18114 79 + in lwipopts.h or use pbuf_free_callback(p)/mem_free_callback(m) to free pbufs
keir@18114 80 + or heap memory from interrupt context
keir@18114 81 +
keir@18114 82 + 2008-03-26 Simon Goldschmidt
keir@18114 83 + * tcp_in.c, tcp.c: fixed bug #22249: division by zero could occur if a remote
keir@18114 84 + host sent a zero mss as TCP option.
keir@18114 85 +
keir@18114 86
keir@18114 87 (STABLE-1.3.0)
keir@18114 88
keir@18114 89 Index: src/api/api_msg.c
keir@18114 90 ===================================================================
keir@18114 91 RCS file: /sources/lwip/lwip/src/api/api_msg.c,v
keir@18114 92 retrieving revision 1.102
keir@18114 93 retrieving revision 1.104
keir@18114 94 diff -u -p -r1.102 -r1.104
keir@18114 95 --- src/api/api_msg.c 21 Mar 2008 16:23:14 -0000 1.102
keir@18114 96 +++ src/api/api_msg.c 15 Jul 2008 11:18:58 -0000 1.104
keir@18114 97 @@ -598,11 +598,16 @@ do_close_internal(struct netconn *conn)
keir@18114 98 LWIP_ASSERT("pcb already closed", (conn->pcb.tcp != NULL));
keir@18114 99
keir@18114 100 /* Set back some callback pointers */
keir@18114 101 + tcp_arg(conn->pcb.tcp, NULL);
keir@18114 102 if (conn->pcb.tcp->state == LISTEN) {
keir@18114 103 - tcp_arg(conn->pcb.tcp, NULL);
keir@18114 104 tcp_accept(conn->pcb.tcp, NULL);
keir@18114 105 } else {
keir@18114 106 tcp_recv(conn->pcb.tcp, NULL);
keir@18114 107 + tcp_accept(conn->pcb.tcp, NULL);
keir@18114 108 + /* some callbacks have to be reset if tcp_close is not successful */
keir@18114 109 + tcp_sent(conn->pcb.tcp, NULL);
keir@18114 110 + tcp_poll(conn->pcb.tcp, NULL, 4);
keir@18114 111 + tcp_err(conn->pcb.tcp, NULL);
keir@18114 112 }
keir@18114 113 /* Try to close the connection */
keir@18114 114 err = tcp_close(conn->pcb.tcp);
keir@18114 115 @@ -610,11 +615,6 @@ do_close_internal(struct netconn *conn)
keir@18114 116 /* Closing succeeded */
keir@18114 117 conn->state = NETCONN_NONE;
keir@18114 118 /* Set back some callback pointers as conn is going away */
keir@18114 119 - tcp_err(conn->pcb.tcp, NULL);
keir@18114 120 - tcp_poll(conn->pcb.tcp, NULL, 4);
keir@18114 121 - tcp_sent(conn->pcb.tcp, NULL);
keir@18114 122 - tcp_recv(conn->pcb.tcp, NULL);
keir@18114 123 - tcp_arg(conn->pcb.tcp, NULL);
keir@18114 124 conn->pcb.tcp = NULL;
keir@18114 125 conn->err = ERR_OK;
keir@18114 126 /* Trigger select() in socket layer. This send should something else so the
keir@18114 127 @@ -623,6 +623,14 @@ do_close_internal(struct netconn *conn)
keir@18114 128 API_EVENT(conn, NETCONN_EVT_SENDPLUS, 0);
keir@18114 129 /* wake up the application task */
keir@18114 130 sys_sem_signal(conn->op_completed);
keir@18114 131 + } else {
keir@18114 132 + /* Closing failed, restore some of the callbacks */
keir@18114 133 + /* Closing of listen pcb will never fail! */
keir@18114 134 + LWIP_ASSERT("Closing a listen pcb may not fail!", (conn->pcb.tcp->state != LISTEN));
keir@18114 135 + tcp_sent(conn->pcb.tcp, sent_tcp);
keir@18114 136 + tcp_poll(conn->pcb.tcp, poll_tcp, 4);
keir@18114 137 + tcp_err(conn->pcb.tcp, err_tcp);
keir@18114 138 + tcp_arg(conn->pcb.tcp, conn);
keir@18114 139 }
keir@18114 140 /* If closing didn't succeed, we get called again either
keir@18114 141 from poll_tcp or from sent_tcp */
keir@18114 142 Index: src/api/err.c
keir@18114 143 ===================================================================
keir@18114 144 RCS file: /sources/lwip/lwip/src/api/err.c,v
keir@18114 145 retrieving revision 1.11
keir@18114 146 retrieving revision 1.12
keir@18114 147 diff -u -p -r1.11 -r1.12
keir@18114 148 --- src/api/err.c 13 Dec 2007 23:06:50 -0000 1.11
keir@18114 149 +++ src/api/err.c 9 May 2008 12:14:23 -0000 1.12
keir@18114 150 @@ -44,17 +44,17 @@ static const char *err_strerr[] = {
keir@18114 151 "Ok.", /* ERR_OK 0 */
keir@18114 152 "Out of memory error.", /* ERR_MEM -1 */
keir@18114 153 "Buffer error.", /* ERR_BUF -2 */
keir@18114 154 - "Routing problem.", /* ERR_RTE -3 */
keir@18114 155 - "Connection aborted.", /* ERR_ABRT -4 */
keir@18114 156 - "Connection reset.", /* ERR_RST -5 */
keir@18114 157 - "Connection closed.", /* ERR_CLSD -6 */
keir@18114 158 - "Not connected.", /* ERR_CONN -7 */
keir@18114 159 - "Illegal value.", /* ERR_VAL -8 */
keir@18114 160 - "Illegal argument.", /* ERR_ARG -9 */
keir@18114 161 - "Address in use.", /* ERR_USE -10 */
keir@18114 162 - "Low-level netif error.", /* ERR_IF -11 */
keir@18114 163 - "Already connected.", /* ERR_ISCONN -12 */
keir@18114 164 - "Timeout.", /* ERR_TIMEOUT -13 */
keir@18114 165 + "Timeout.", /* ERR_TIMEOUT -3 */
keir@18114 166 + "Routing problem.", /* ERR_RTE -4 */
keir@18114 167 + "Connection aborted.", /* ERR_ABRT -5 */
keir@18114 168 + "Connection reset.", /* ERR_RST -6 */
keir@18114 169 + "Connection closed.", /* ERR_CLSD -7 */
keir@18114 170 + "Not connected.", /* ERR_CONN -8 */
keir@18114 171 + "Illegal value.", /* ERR_VAL -9 */
keir@18114 172 + "Illegal argument.", /* ERR_ARG -10 */
keir@18114 173 + "Address in use.", /* ERR_USE -11 */
keir@18114 174 + "Low-level netif error.", /* ERR_IF -12 */
keir@18114 175 + "Already connected.", /* ERR_ISCONN -13 */
keir@18114 176 "Operation in progress." /* ERR_INPROGRESS -14 */
keir@18114 177 };
keir@18114 178
keir@18114 179 Index: src/api/netdb.c
keir@18114 180 ===================================================================
keir@18114 181 RCS file: /sources/lwip/lwip/src/api/netdb.c,v
keir@18114 182 retrieving revision 1.4
keir@18114 183 retrieving revision 1.5
keir@18114 184 diff -u -p -r1.4 -r1.5
keir@18114 185 --- src/api/netdb.c 26 Jan 2008 16:11:39 -0000 1.4
keir@18114 186 +++ src/api/netdb.c 16 Jul 2008 20:36:12 -0000 1.5
keir@18114 187 @@ -326,7 +326,8 @@ lwip_getaddrinfo(const char *nodename, c
keir@18114 188 if (nodename != NULL) {
keir@18114 189 /* copy nodename to canonname if specified */
keir@18114 190 size_t namelen = strlen(nodename);
keir@18114 191 - ai->ai_canonname = mem_malloc(namelen + 1);
keir@18114 192 + LWIP_ASSERT("namelen is too long", (namelen + 1) <= (mem_size_t)-1);
keir@18114 193 + ai->ai_canonname = mem_malloc((mem_size_t)(namelen + 1));
keir@18114 194 if (ai->ai_canonname == NULL) {
keir@18114 195 goto memerr;
keir@18114 196 }
keir@18114 197 Index: src/api/sockets.c
keir@18114 198 ===================================================================
keir@18114 199 RCS file: /sources/lwip/lwip/src/api/sockets.c,v
keir@18114 200 retrieving revision 1.116
keir@18114 201 retrieving revision 1.117
keir@18114 202 diff -u -p -r1.116 -r1.117
keir@18114 203 --- src/api/sockets.c 13 Mar 2008 20:03:57 -0000 1.116
keir@18114 204 +++ src/api/sockets.c 9 May 2008 12:14:24 -0000 1.117
keir@18114 205 @@ -128,17 +128,17 @@ static const int err_to_errno_table[] =
keir@18114 206 0, /* ERR_OK 0 No error, everything OK. */
keir@18114 207 ENOMEM, /* ERR_MEM -1 Out of memory error. */
keir@18114 208 ENOBUFS, /* ERR_BUF -2 Buffer error. */
keir@18114 209 - EHOSTUNREACH, /* ERR_RTE -3 Routing problem. */
keir@18114 210 - ECONNABORTED, /* ERR_ABRT -4 Connection aborted. */
keir@18114 211 - ECONNRESET, /* ERR_RST -5 Connection reset. */
keir@18114 212 - ESHUTDOWN, /* ERR_CLSD -6 Connection closed. */
keir@18114 213 - ENOTCONN, /* ERR_CONN -7 Not connected. */
keir@18114 214 - EINVAL, /* ERR_VAL -8 Illegal value. */
keir@18114 215 - EIO, /* ERR_ARG -9 Illegal argument. */
keir@18114 216 - EADDRINUSE, /* ERR_USE -10 Address in use. */
keir@18114 217 - -1, /* ERR_IF -11 Low-level netif error */
keir@18114 218 - -1, /* ERR_ISCONN -12 Already connected. */
keir@18114 219 - ETIMEDOUT, /* ERR_TIMEOUT -13 Timeout */
keir@18114 220 + ETIMEDOUT, /* ERR_TIMEOUT -3 Timeout */
keir@18114 221 + EHOSTUNREACH, /* ERR_RTE -4 Routing problem. */
keir@18114 222 + ECONNABORTED, /* ERR_ABRT -5 Connection aborted. */
keir@18114 223 + ECONNRESET, /* ERR_RST -6 Connection reset. */
keir@18114 224 + ESHUTDOWN, /* ERR_CLSD -7 Connection closed. */
keir@18114 225 + ENOTCONN, /* ERR_CONN -8 Not connected. */
keir@18114 226 + EINVAL, /* ERR_VAL -9 Illegal value. */
keir@18114 227 + EIO, /* ERR_ARG -10 Illegal argument. */
keir@18114 228 + EADDRINUSE, /* ERR_USE -11 Address in use. */
keir@18114 229 + -1, /* ERR_IF -12 Low-level netif error */
keir@18114 230 + -1, /* ERR_ISCONN -13 Already connected. */
keir@18114 231 EINPROGRESS /* ERR_INPROGRESS -14 Operation in progress */
keir@18114 232 };
keir@18114 233
keir@18114 234 Index: src/api/tcpip.c
keir@18114 235 ===================================================================
keir@18114 236 RCS file: /sources/lwip/lwip/src/api/tcpip.c,v
keir@18114 237 retrieving revision 1.70
keir@18114 238 retrieving revision 1.73
keir@18114 239 diff -u -p -r1.70 -r1.73
keir@18114 240 --- src/api/tcpip.c 12 Jan 2008 11:52:22 -0000 1.70
keir@18114 241 +++ src/api/tcpip.c 27 Jun 2008 20:34:51 -0000 1.73
keir@18114 242 @@ -518,4 +518,42 @@ tcpip_init(void (* initfunc)(void *), vo
keir@18114 243 sys_thread_new(TCPIP_THREAD_NAME, tcpip_thread, NULL, TCPIP_THREAD_STACKSIZE, TCPIP_THREAD_PRIO);
keir@18114 244 }
keir@18114 245
keir@18114 246 +/**
keir@18114 247 + * Simple callback function used with tcpip_callback to free a pbuf
keir@18114 248 + * (pbuf_free has a wrong signature for tcpip_callback)
keir@18114 249 + *
keir@18114 250 + * @param p The pbuf (chain) to be dereferenced.
keir@18114 251 + */
keir@18114 252 +static void
keir@18114 253 +pbuf_free_int(void *p)
keir@18114 254 +{
keir@18114 255 + struct pbuf *q = p;
keir@18114 256 + pbuf_free(q);
keir@18114 257 +}
keir@18114 258 +
keir@18114 259 +/**
keir@18114 260 + * A simple wrapper function that allows you to free a pbuf from interrupt context.
keir@18114 261 + *
keir@18114 262 + * @param p The pbuf (chain) to be dereferenced.
keir@18114 263 + * @return ERR_OK if callback could be enqueued, an err_t if not
keir@18114 264 + */
keir@18114 265 +err_t
keir@18114 266 +pbuf_free_callback(struct pbuf *p)
keir@18114 267 +{
keir@18114 268 + return tcpip_callback_with_block(pbuf_free_int, p, 0);
keir@18114 269 +}
keir@18114 270 +
keir@18114 271 +/**
keir@18114 272 + * A simple wrapper function that allows you to free heap memory from
keir@18114 273 + * interrupt context.
keir@18114 274 + *
keir@18114 275 + * @param m the heap memory to free
keir@18114 276 + * @return ERR_OK if callback could be enqueued, an err_t if not
keir@18114 277 + */
keir@18114 278 +err_t
keir@18114 279 +mem_free_callback(void *m)
keir@18114 280 +{
keir@18114 281 + return tcpip_callback_with_block(mem_free, m, 0);
keir@18114 282 +}
keir@18114 283 +
keir@18114 284 #endif /* !NO_SYS */
keir@18114 285 Index: src/core/dhcp.c
keir@18114 286 ===================================================================
keir@18114 287 RCS file: /sources/lwip/lwip/src/core/dhcp.c,v
keir@18114 288 retrieving revision 1.86
keir@18114 289 retrieving revision 1.87
keir@18114 290 diff -u -p -r1.86 -r1.87
keir@18114 291 --- src/core/dhcp.c 4 Mar 2008 14:25:58 -0000 1.86
keir@18114 292 +++ src/core/dhcp.c 15 Apr 2008 17:24:55 -0000 1.87
keir@18114 293 @@ -568,6 +568,8 @@ dhcp_start(struct netif *netif)
keir@18114 294 LWIP_ERROR("netif != NULL", (netif != NULL), return ERR_ARG;);
keir@18114 295 dhcp = netif->dhcp;
keir@18114 296 LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_start(netif=%p) %c%c%"U16_F"\n", (void*)netif, netif->name[0], netif->name[1], (u16_t)netif->num));
keir@18114 297 + /* Remove the flag that says this netif is handled by DHCP,
keir@18114 298 + it is set when we succeeded starting. */
keir@18114 299 netif->flags &= ~NETIF_FLAG_DHCP;
keir@18114 300
keir@18114 301 /* no DHCP client attached yet? */
keir@18114 302 @@ -609,6 +611,7 @@ dhcp_start(struct netif *netif)
keir@18114 303 dhcp_stop(netif);
keir@18114 304 return ERR_MEM;
keir@18114 305 }
keir@18114 306 + /* Set the flag that says this netif is handled by DHCP. */
keir@18114 307 netif->flags |= NETIF_FLAG_DHCP;
keir@18114 308 return result;
keir@18114 309 }
keir@18114 310 @@ -1063,6 +1066,8 @@ dhcp_stop(struct netif *netif)
keir@18114 311 {
keir@18114 312 struct dhcp *dhcp = netif->dhcp;
keir@18114 313 LWIP_ERROR("dhcp_stop: netif != NULL", (netif != NULL), return;);
keir@18114 314 + /* Remove the flag that says this netif is handled by DHCP. */
keir@18114 315 + netif->flags &= ~NETIF_FLAG_DHCP;
keir@18114 316
keir@18114 317 LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | 3, ("dhcp_stop()\n"));
keir@18114 318 /* netif is DHCP configured? */
keir@18114 319 Index: src/core/mem.c
keir@18114 320 ===================================================================
keir@18114 321 RCS file: /sources/lwip/lwip/src/core/mem.c,v
keir@18114 322 retrieving revision 1.59
keir@18114 323 retrieving revision 1.62
keir@18114 324 diff -u -p -r1.59 -r1.62
keir@18114 325 --- src/core/mem.c 4 Mar 2008 16:31:32 -0000 1.59
keir@18114 326 +++ src/core/mem.c 30 Jun 2008 18:16:51 -0000 1.62
keir@18114 327 @@ -177,9 +177,36 @@ static u8_t *ram;
keir@18114 328 static struct mem *ram_end;
keir@18114 329 /** pointer to the lowest free block, this is used for faster search */
keir@18114 330 static struct mem *lfree;
keir@18114 331 +
keir@18114 332 /** concurrent access protection */
keir@18114 333 static sys_sem_t mem_sem;
keir@18114 334
keir@18114 335 +#if LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT
keir@18114 336 +
keir@18114 337 +static volatile u8_t mem_free_count;
keir@18114 338 +
keir@18114 339 +/* Allow mem_free from other (e.g. interrupt) context */
keir@18114 340 +#define LWIP_MEM_FREE_DECL_PROTECT() SYS_ARCH_DECL_PROTECT(lev_free)
keir@18114 341 +#define LWIP_MEM_FREE_PROTECT() SYS_ARCH_PROTECT(lev_free)
keir@18114 342 +#define LWIP_MEM_FREE_UNPROTECT() SYS_ARCH_UNPROTECT(lev_free)
keir@18114 343 +#define LWIP_MEM_ALLOC_DECL_PROTECT() SYS_ARCH_DECL_PROTECT(lev_alloc)
keir@18114 344 +#define LWIP_MEM_ALLOC_PROTECT() SYS_ARCH_PROTECT(lev_alloc)
keir@18114 345 +#define LWIP_MEM_ALLOC_UNPROTECT() SYS_ARCH_UNPROTECT(lev_alloc)
keir@18114 346 +
keir@18114 347 +#else /* LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT */
keir@18114 348 +
keir@18114 349 +/* Protect the heap only by using a semaphore */
keir@18114 350 +#define LWIP_MEM_FREE_DECL_PROTECT()
keir@18114 351 +#define LWIP_MEM_FREE_PROTECT() sys_arch_sem_wait(mem_sem, 0)
keir@18114 352 +#define LWIP_MEM_FREE_UNPROTECT() sys_sem_signal(mem_sem)
keir@18114 353 +/* mem_malloc is protected using semaphore AND LWIP_MEM_ALLOC_PROTECT */
keir@18114 354 +#define LWIP_MEM_ALLOC_DECL_PROTECT()
keir@18114 355 +#define LWIP_MEM_ALLOC_PROTECT()
keir@18114 356 +#define LWIP_MEM_ALLOC_UNPROTECT()
keir@18114 357 +
keir@18114 358 +#endif /* LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT */
keir@18114 359 +
keir@18114 360 +
keir@18114 361 /**
keir@18114 362 * "Plug holes" by combining adjacent empty struct mems.
keir@18114 363 * After this function is through, there should not exist
keir@18114 364 @@ -255,9 +282,7 @@ mem_init(void)
keir@18114 365 /* initialize the lowest-free pointer to the start of the heap */
keir@18114 366 lfree = (struct mem *)ram;
keir@18114 367
keir@18114 368 -#if MEM_STATS
keir@18114 369 - lwip_stats.mem.avail = MEM_SIZE_ALIGNED;
keir@18114 370 -#endif /* MEM_STATS */
keir@18114 371 + MEM_STATS_AVAIL(avail, MEM_SIZE_ALIGNED);
keir@18114 372 }
keir@18114 373
keir@18114 374 /**
keir@18114 375 @@ -270,6 +295,7 @@ void
keir@18114 376 mem_free(void *rmem)
keir@18114 377 {
keir@18114 378 struct mem *mem;
keir@18114 379 + LWIP_MEM_FREE_DECL_PROTECT();
keir@18114 380
keir@18114 381 if (rmem == NULL) {
keir@18114 382 LWIP_DEBUGF(MEM_DEBUG | LWIP_DBG_TRACE | 2, ("mem_free(p == NULL) was called.\n"));
keir@18114 383 @@ -277,20 +303,20 @@ mem_free(void *rmem)
keir@18114 384 }
keir@18114 385 LWIP_ASSERT("mem_free: sanity check alignment", (((mem_ptr_t)rmem) & (MEM_ALIGNMENT-1)) == 0);
keir@18114 386
keir@18114 387 - /* protect the heap from concurrent access */
keir@18114 388 - sys_arch_sem_wait(mem_sem, 0);
keir@18114 389 -
keir@18114 390 LWIP_ASSERT("mem_free: legal memory", (u8_t *)rmem >= (u8_t *)ram &&
keir@18114 391 (u8_t *)rmem < (u8_t *)ram_end);
keir@18114 392
keir@18114 393 if ((u8_t *)rmem < (u8_t *)ram || (u8_t *)rmem >= (u8_t *)ram_end) {
keir@18114 394 + SYS_ARCH_DECL_PROTECT(lev);
keir@18114 395 LWIP_DEBUGF(MEM_DEBUG | 3, ("mem_free: illegal memory\n"));
keir@18114 396 -#if MEM_STATS
keir@18114 397 - ++lwip_stats.mem.err;
keir@18114 398 -#endif /* MEM_STATS */
keir@18114 399 - sys_sem_signal(mem_sem);
keir@18114 400 + /* protect mem stats from concurrent access */
keir@18114 401 + SYS_ARCH_PROTECT(lev);
keir@18114 402 + MEM_STATS_INC(illegal);
keir@18114 403 + SYS_ARCH_UNPROTECT(lev);
keir@18114 404 return;
keir@18114 405 }
keir@18114 406 + /* protect the heap from concurrent access */
keir@18114 407 + LWIP_MEM_FREE_PROTECT();
keir@18114 408 /* Get the corresponding struct mem ... */
keir@18114 409 mem = (struct mem *)((u8_t *)rmem - SIZEOF_STRUCT_MEM);
keir@18114 410 /* ... which has to be in a used state ... */
keir@18114 411 @@ -303,13 +329,14 @@ mem_free(void *rmem)
keir@18114 412 lfree = mem;
keir@18114 413 }
keir@18114 414
keir@18114 415 -#if MEM_STATS
keir@18114 416 - lwip_stats.mem.used -= mem->next - ((u8_t *)mem - ram);
keir@18114 417 -#endif /* MEM_STATS */
keir@18114 418 + MEM_STATS_DEC_USED(used, mem->next - ((u8_t *)mem - ram));
keir@18114 419
keir@18114 420 /* finally, see if prev or next are free also */
keir@18114 421 plug_holes(mem);
keir@18114 422 - sys_sem_signal(mem_sem);
keir@18114 423 +#if LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT
keir@18114 424 + mem_free_count = 1;
keir@18114 425 +#endif /* LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT */
keir@18114 426 + LWIP_MEM_FREE_UNPROTECT();
keir@18114 427 }
keir@18114 428
keir@18114 429 /**
keir@18114 430 @@ -321,6 +348,8 @@ mem_free(void *rmem)
keir@18114 431 * @param newsize required size after shrinking (needs to be smaller than or
keir@18114 432 * equal to the previous size)
keir@18114 433 * @return for compatibility reasons: is always == rmem, at the moment
keir@18114 434 + * or NULL if newsize is > old size, in which case rmem is NOT touched
keir@18114 435 + * or freed!
keir@18114 436 */
keir@18114 437 void *
keir@18114 438 mem_realloc(void *rmem, mem_size_t newsize)
keir@18114 439 @@ -328,6 +357,8 @@ mem_realloc(void *rmem, mem_size_t newsi
keir@18114 440 mem_size_t size;
keir@18114 441 mem_size_t ptr, ptr2;
keir@18114 442 struct mem *mem, *mem2;
keir@18114 443 + /* use the FREE_PROTECT here: it protects with sem OR SYS_ARCH_PROTECT */
keir@18114 444 + LWIP_MEM_FREE_DECL_PROTECT();
keir@18114 445
keir@18114 446 /* Expand the size of the allocated memory region so that we can
keir@18114 447 adjust for alignment. */
keir@18114 448 @@ -346,7 +377,12 @@ mem_realloc(void *rmem, mem_size_t newsi
keir@18114 449 (u8_t *)rmem < (u8_t *)ram_end);
keir@18114 450
keir@18114 451 if ((u8_t *)rmem < (u8_t *)ram || (u8_t *)rmem >= (u8_t *)ram_end) {
keir@18114 452 + SYS_ARCH_DECL_PROTECT(lev);
keir@18114 453 LWIP_DEBUGF(MEM_DEBUG | 3, ("mem_realloc: illegal memory\n"));
keir@18114 454 + /* protect mem stats from concurrent access */
keir@18114 455 + SYS_ARCH_PROTECT(lev);
keir@18114 456 + MEM_STATS_INC(illegal);
keir@18114 457 + SYS_ARCH_UNPROTECT(lev);
keir@18114 458 return rmem;
keir@18114 459 }
keir@18114 460 /* Get the corresponding struct mem ... */
keir@18114 461 @@ -366,11 +402,9 @@ mem_realloc(void *rmem, mem_size_t newsi
keir@18114 462 }
keir@18114 463
keir@18114 464 /* protect the heap from concurrent access */
keir@18114 465 - sys_arch_sem_wait(mem_sem, 0);
keir@18114 466 + LWIP_MEM_FREE_PROTECT();
keir@18114 467
keir@18114 468 -#if MEM_STATS
keir@18114 469 - lwip_stats.mem.used -= (size - newsize);
keir@18114 470 -#endif /* MEM_STATS */
keir@18114 471 + MEM_STATS_DEC_USED(used, (size - newsize));
keir@18114 472
keir@18114 473 mem2 = (struct mem *)&ram[mem->next];
keir@18114 474 if(mem2->used == 0) {
keir@18114 475 @@ -426,7 +460,10 @@ mem_realloc(void *rmem, mem_size_t newsi
keir@18114 476 -> don't do anyhting.
keir@18114 477 -> the remaining space stays unused since it is too small
keir@18114 478 } */
keir@18114 479 - sys_sem_signal(mem_sem);
keir@18114 480 +#if LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT
keir@18114 481 + mem_free_count = 1;
keir@18114 482 +#endif /* LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT */
keir@18114 483 + LWIP_MEM_FREE_UNPROTECT();
keir@18114 484 return rmem;
keir@18114 485 }
keir@18114 486
keir@18114 487 @@ -444,6 +481,10 @@ mem_malloc(mem_size_t size)
keir@18114 488 {
keir@18114 489 mem_size_t ptr, ptr2;
keir@18114 490 struct mem *mem, *mem2;
keir@18114 491 +#if LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT
keir@18114 492 + u8_t local_mem_free_count = 0;
keir@18114 493 +#endif /* LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT */
keir@18114 494 + LWIP_MEM_ALLOC_DECL_PROTECT();
keir@18114 495
keir@18114 496 if (size == 0) {
keir@18114 497 return NULL;
keir@18114 498 @@ -464,88 +505,101 @@ mem_malloc(mem_size_t size)
keir@18114 499
keir@18114 500 /* protect the heap from concurrent access */
keir@18114 501 sys_arch_sem_wait(mem_sem, 0);
keir@18114 502 + LWIP_MEM_ALLOC_PROTECT();
keir@18114 503 +#if LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT
keir@18114 504 + /* run as long as a mem_free disturbed mem_malloc */
keir@18114 505 + do {
keir@18114 506 + local_mem_free_count = 0;
keir@18114 507 +#endif /* LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT */
keir@18114 508 +
keir@18114 509 + /* Scan through the heap searching for a free block that is big enough,
keir@18114 510 + * beginning with the lowest free block.
keir@18114 511 + */
keir@18114 512 + for (ptr = (u8_t *)lfree - ram; ptr < MEM_SIZE_ALIGNED - size;
keir@18114 513 + ptr = ((struct mem *)&ram[ptr])->next) {
keir@18114 514 + mem = (struct mem *)&ram[ptr];
keir@18114 515 +#if LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT
keir@18114 516 + mem_free_count = 0;
keir@18114 517 + LWIP_MEM_ALLOC_UNPROTECT();
keir@18114 518 + /* allow mem_free to run */
keir@18114 519 + LWIP_MEM_ALLOC_PROTECT();
keir@18114 520 + if (mem_free_count != 0) {
keir@18114 521 + local_mem_free_count = mem_free_count;
keir@18114 522 + }
keir@18114 523 + mem_free_count = 0;
keir@18114 524 +#endif /* LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT */
keir@18114 525
keir@18114 526 - /* Scan through the heap searching for a free block that is big enough,
keir@18114 527 - * beginning with the lowest free block.
keir@18114 528 - */
keir@18114 529 - for (ptr = (u8_t *)lfree - ram; ptr < MEM_SIZE_ALIGNED - size;
keir@18114 530 - ptr = ((struct mem *)&ram[ptr])->next) {
keir@18114 531 - mem = (struct mem *)&ram[ptr];
keir@18114 532 -
keir@18114 533 - if ((!mem->used) &&
keir@18114 534 - (mem->next - (ptr + SIZEOF_STRUCT_MEM)) >= size) {
keir@18114 535 - /* mem is not used and at least perfect fit is possible:
keir@18114 536 - * mem->next - (ptr + SIZEOF_STRUCT_MEM) gives us the 'user data size' of mem */
keir@18114 537 -
keir@18114 538 - if (mem->next - (ptr + SIZEOF_STRUCT_MEM) >= (size + SIZEOF_STRUCT_MEM + MIN_SIZE_ALIGNED)) {
keir@18114 539 - /* (in addition to the above, we test if another struct mem (SIZEOF_STRUCT_MEM) containing
keir@18114 540 - * at least MIN_SIZE_ALIGNED of data also fits in the 'user data space' of 'mem')
keir@18114 541 - * -> split large block, create empty remainder,
keir@18114 542 - * remainder must be large enough to contain MIN_SIZE_ALIGNED data: if
keir@18114 543 - * mem->next - (ptr + (2*SIZEOF_STRUCT_MEM)) == size,
keir@18114 544 - * struct mem would fit in but no data between mem2 and mem2->next
keir@18114 545 - * @todo we could leave out MIN_SIZE_ALIGNED. We would create an empty
keir@18114 546 - * region that couldn't hold data, but when mem->next gets freed,
keir@18114 547 - * the 2 regions would be combined, resulting in more free memory
keir@18114 548 - */
keir@18114 549 - ptr2 = ptr + SIZEOF_STRUCT_MEM + size;
keir@18114 550 - /* create mem2 struct */
keir@18114 551 - mem2 = (struct mem *)&ram[ptr2];
keir@18114 552 - mem2->used = 0;
keir@18114 553 - mem2->next = mem->next;
keir@18114 554 - mem2->prev = ptr;
keir@18114 555 - /* and insert it between mem and mem->next */
keir@18114 556 - mem->next = ptr2;
keir@18114 557 - mem->used = 1;
keir@18114 558 -
keir@18114 559 - if (mem2->next != MEM_SIZE_ALIGNED) {
keir@18114 560 - ((struct mem *)&ram[mem2->next])->prev = ptr2;
keir@18114 561 - }
keir@18114 562 -#if MEM_STATS
keir@18114 563 - lwip_stats.mem.used += (size + SIZEOF_STRUCT_MEM);
keir@18114 564 - if (lwip_stats.mem.max < lwip_stats.mem.used) {
keir@18114 565 - lwip_stats.mem.max = lwip_stats.mem.used;
keir@18114 566 + if ((!mem->used) &&
keir@18114 567 + (mem->next - (ptr + SIZEOF_STRUCT_MEM)) >= size) {
keir@18114 568 + /* mem is not used and at least perfect fit is possible:
keir@18114 569 + * mem->next - (ptr + SIZEOF_STRUCT_MEM) gives us the 'user data size' of mem */
keir@18114 570 +
keir@18114 571 + if (mem->next - (ptr + SIZEOF_STRUCT_MEM) >= (size + SIZEOF_STRUCT_MEM + MIN_SIZE_ALIGNED)) {
keir@18114 572 + /* (in addition to the above, we test if another struct mem (SIZEOF_STRUCT_MEM) containing
keir@18114 573 + * at least MIN_SIZE_ALIGNED of data also fits in the 'user data space' of 'mem')
keir@18114 574 + * -> split large block, create empty remainder,
keir@18114 575 + * remainder must be large enough to contain MIN_SIZE_ALIGNED data: if
keir@18114 576 + * mem->next - (ptr + (2*SIZEOF_STRUCT_MEM)) == size,
keir@18114 577 + * struct mem would fit in but no data between mem2 and mem2->next
keir@18114 578 + * @todo we could leave out MIN_SIZE_ALIGNED. We would create an empty
keir@18114 579 + * region that couldn't hold data, but when mem->next gets freed,
keir@18114 580 + * the 2 regions would be combined, resulting in more free memory
keir@18114 581 + */
keir@18114 582 + ptr2 = ptr + SIZEOF_STRUCT_MEM + size;
keir@18114 583 + /* create mem2 struct */
keir@18114 584 + mem2 = (struct mem *)&ram[ptr2];
keir@18114 585 + mem2->used = 0;
keir@18114 586 + mem2->next = mem->next;
keir@18114 587 + mem2->prev = ptr;
keir@18114 588 + /* and insert it between mem and mem->next */
keir@18114 589 + mem->next = ptr2;
keir@18114 590 + mem->used = 1;
keir@18114 591 +
keir@18114 592 + if (mem2->next != MEM_SIZE_ALIGNED) {
keir@18114 593 + ((struct mem *)&ram[mem2->next])->prev = ptr2;
keir@18114 594 + }
keir@18114 595 + MEM_STATS_INC_USED(used, (size + SIZEOF_STRUCT_MEM));
keir@18114 596 + } else {
keir@18114 597 + /* (a mem2 struct does no fit into the user data space of mem and mem->next will always
keir@18114 598 + * be used at this point: if not we have 2 unused structs in a row, plug_holes should have
keir@18114 599 + * take care of this).
keir@18114 600 + * -> near fit or excact fit: do not split, no mem2 creation
keir@18114 601 + * also can't move mem->next directly behind mem, since mem->next
keir@18114 602 + * will always be used at this point!
keir@18114 603 + */
keir@18114 604 + mem->used = 1;
keir@18114 605 + MEM_STATS_INC_USED(used, mem->next - ((u8_t *)mem - ram));
keir@18114 606 }
keir@18114 607 -#endif /* MEM_STATS */
keir@18114 608 - } else {
keir@18114 609 - /* (a mem2 struct does no fit into the user data space of mem and mem->next will always
keir@18114 610 - * be used at this point: if not we have 2 unused structs in a row, plug_holes should have
keir@18114 611 - * take care of this).
keir@18114 612 - * -> near fit or excact fit: do not split, no mem2 creation
keir@18114 613 - * also can't move mem->next directly behind mem, since mem->next
keir@18114 614 - * will always be used at this point!
keir@18114 615 - */
keir@18114 616 - mem->used = 1;
keir@18114 617 -#if MEM_STATS
keir@18114 618 - lwip_stats.mem.used += mem->next - ((u8_t *)mem - ram);
keir@18114 619 - if (lwip_stats.mem.max < lwip_stats.mem.used) {
keir@18114 620 - lwip_stats.mem.max = lwip_stats.mem.used;
keir@18114 621 - }
keir@18114 622 -#endif /* MEM_STATS */
keir@18114 623 - }
keir@18114 624
keir@18114 625 - if (mem == lfree) {
keir@18114 626 - /* Find next free block after mem and update lowest free pointer */
keir@18114 627 - while (lfree->used && lfree != ram_end) {
keir@18114 628 - lfree = (struct mem *)&ram[lfree->next];
keir@18114 629 + if (mem == lfree) {
keir@18114 630 + /* Find next free block after mem and update lowest free pointer */
keir@18114 631 + while (lfree->used && lfree != ram_end) {
keir@18114 632 + LWIP_MEM_ALLOC_UNPROTECT();
keir@18114 633 + /* prevent high interrupt latency... */
keir@18114 634 + LWIP_MEM_ALLOC_PROTECT();
keir@18114 635 + lfree = (struct mem *)&ram[lfree->next];
keir@18114 636 + }
keir@18114 637 + LWIP_ASSERT("mem_malloc: !lfree->used", ((lfree == ram_end) || (!lfree->used)));
keir@18114 638 }
keir@18114 639 - LWIP_ASSERT("mem_malloc: !lfree->used", ((lfree == ram_end) || (!lfree->used)));
keir@18114 640 - }
keir@18114 641 - sys_sem_signal(mem_sem);
keir@18114 642 - LWIP_ASSERT("mem_malloc: allocated memory not above ram_end.",
keir@18114 643 - (mem_ptr_t)mem + SIZEOF_STRUCT_MEM + size <= (mem_ptr_t)ram_end);
keir@18114 644 - LWIP_ASSERT("mem_malloc: allocated memory properly aligned.",
keir@18114 645 - (unsigned long)((u8_t *)mem + SIZEOF_STRUCT_MEM) % MEM_ALIGNMENT == 0);
keir@18114 646 - LWIP_ASSERT("mem_malloc: sanity check alignment",
keir@18114 647 - (((mem_ptr_t)mem) & (MEM_ALIGNMENT-1)) == 0);
keir@18114 648 + LWIP_MEM_ALLOC_UNPROTECT();
keir@18114 649 + sys_sem_signal(mem_sem);
keir@18114 650 + LWIP_ASSERT("mem_malloc: allocated memory not above ram_end.",
keir@18114 651 + (mem_ptr_t)mem + SIZEOF_STRUCT_MEM + size <= (mem_ptr_t)ram_end);
keir@18114 652 + LWIP_ASSERT("mem_malloc: allocated memory properly aligned.",
keir@18114 653 + (unsigned long)((u8_t *)mem + SIZEOF_STRUCT_MEM) % MEM_ALIGNMENT == 0);
keir@18114 654 + LWIP_ASSERT("mem_malloc: sanity check alignment",
keir@18114 655 + (((mem_ptr_t)mem) & (MEM_ALIGNMENT-1)) == 0);
keir@18114 656
keir@18114 657 - return (u8_t *)mem + SIZEOF_STRUCT_MEM;
keir@18114 658 + return (u8_t *)mem + SIZEOF_STRUCT_MEM;
keir@18114 659 + }
keir@18114 660 }
keir@18114 661 - }
keir@18114 662 +#if LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT
keir@18114 663 + /* if we got interrupted by a mem_free, try again */
keir@18114 664 + } while(local_mem_free_count != 0);
keir@18114 665 +#endif /* LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT */
keir@18114 666 LWIP_DEBUGF(MEM_DEBUG | 2, ("mem_malloc: could not allocate %"S16_F" bytes\n", (s16_t)size));
keir@18114 667 -#if MEM_STATS
keir@18114 668 - ++lwip_stats.mem.err;
keir@18114 669 -#endif /* MEM_STATS */
keir@18114 670 + MEM_STATS_INC(err);
keir@18114 671 + LWIP_MEM_ALLOC_UNPROTECT();
keir@18114 672 sys_sem_signal(mem_sem);
keir@18114 673 return NULL;
keir@18114 674 }
keir@18114 675 Index: src/core/memp.c
keir@18114 676 ===================================================================
keir@18114 677 RCS file: /sources/lwip/lwip/src/core/memp.c,v
keir@18114 678 retrieving revision 1.55
keir@18114 679 retrieving revision 1.56
keir@18114 680 diff -u -p -r1.55 -r1.56
keir@18114 681 --- src/core/memp.c 25 Nov 2007 10:43:28 -0000 1.55
keir@18114 682 +++ src/core/memp.c 27 Jun 2008 18:37:54 -0000 1.56
keir@18114 683 @@ -252,13 +252,12 @@ memp_init(void)
keir@18114 684 struct memp *memp;
keir@18114 685 u16_t i, j;
keir@18114 686
keir@18114 687 -#if MEMP_STATS
keir@18114 688 for (i = 0; i < MEMP_MAX; ++i) {
keir@18114 689 - lwip_stats.memp[i].used = lwip_stats.memp[i].max =
keir@18114 690 - lwip_stats.memp[i].err = 0;
keir@18114 691 - lwip_stats.memp[i].avail = memp_num[i];
keir@18114 692 + MEMP_STATS_AVAIL(used, i, 0);
keir@18114 693 + MEMP_STATS_AVAIL(max, i, 0);
keir@18114 694 + MEMP_STATS_AVAIL(err, i, 0);
keir@18114 695 + MEMP_STATS_AVAIL(avail, i, memp_num[i]);
keir@18114 696 }
keir@18114 697 -#endif /* MEMP_STATS */
keir@18114 698
keir@18114 699 memp = LWIP_MEM_ALIGN(memp_memory);
keir@18114 700 /* for every pool: */
keir@18114 701 @@ -315,20 +314,13 @@ memp_malloc_fn(memp_t type, const char*
keir@18114 702 memp->file = file;
keir@18114 703 memp->line = line;
keir@18114 704 #endif /* MEMP_OVERFLOW_CHECK */
keir@18114 705 -#if MEMP_STATS
keir@18114 706 - ++lwip_stats.memp[type].used;
keir@18114 707 - if (lwip_stats.memp[type].used > lwip_stats.memp[type].max) {
keir@18114 708 - lwip_stats.memp[type].max = lwip_stats.memp[type].used;
keir@18114 709 - }
keir@18114 710 -#endif /* MEMP_STATS */
keir@18114 711 + MEMP_STATS_INC_USED(used, type);
keir@18114 712 LWIP_ASSERT("memp_malloc: memp properly aligned",
keir@18114 713 ((mem_ptr_t)memp % MEM_ALIGNMENT) == 0);
keir@18114 714 memp = (struct memp*)((u8_t*)memp + MEMP_SIZE);
keir@18114 715 } else {
keir@18114 716 LWIP_DEBUGF(MEMP_DEBUG | 2, ("memp_malloc: out of memory in pool %s\n", memp_desc[type]));
keir@18114 717 -#if MEMP_STATS
keir@18114 718 - ++lwip_stats.memp[type].err;
keir@18114 719 -#endif /* MEMP_STATS */
keir@18114 720 + MEMP_STATS_INC(err, type);
keir@18114 721 }
keir@18114 722
keir@18114 723 SYS_ARCH_UNPROTECT(old_level);
keir@18114 724 @@ -365,9 +357,7 @@ memp_free(memp_t type, void *mem)
keir@18114 725 #endif /* MEMP_OVERFLOW_CHECK >= 2 */
keir@18114 726 #endif /* MEMP_OVERFLOW_CHECK */
keir@18114 727
keir@18114 728 -#if MEMP_STATS
keir@18114 729 - lwip_stats.memp[type].used--;
keir@18114 730 -#endif /* MEMP_STATS */
keir@18114 731 + MEMP_STATS_DEC(used, type);
keir@18114 732
keir@18114 733 memp->next = memp_tab[type];
keir@18114 734 memp_tab[type] = memp;
keir@18114 735 Index: src/core/netif.c
keir@18114 736 ===================================================================
keir@18114 737 RCS file: /sources/lwip/lwip/src/core/netif.c,v
keir@18114 738 retrieving revision 1.65
keir@18114 739 retrieving revision 1.68
keir@18114 740 diff -u -p -r1.65 -r1.68
keir@18114 741 --- src/core/netif.c 9 Oct 2007 20:00:55 -0000 1.65
keir@18114 742 +++ src/core/netif.c 19 Jun 2008 16:27:18 -0000 1.68
keir@18114 743 @@ -45,6 +45,12 @@
keir@18114 744 #include "lwip/snmp.h"
keir@18114 745 #include "lwip/igmp.h"
keir@18114 746 #include "netif/etharp.h"
keir@18114 747 +#if ENABLE_LOOPBACK
keir@18114 748 +#include "lwip/sys.h"
keir@18114 749 +#if LWIP_NETIF_LOOPBACK_MULTITHREADING
keir@18114 750 +#include "lwip/tcpip.h"
keir@18114 751 +#endif /* LWIP_NETIF_LOOPBACK_MULTITHREADING */
keir@18114 752 +#endif /* ENABLE_LOOPBACK */
keir@18114 753
keir@18114 754 #if LWIP_NETIF_STATUS_CALLBACK
keir@18114 755 #define NETIF_STATUS_CALLBACK(n) { if (n->status_callback) (n->status_callback)(n); }
keir@18114 756 @@ -106,6 +112,10 @@ netif_add(struct netif *netif, struct ip
keir@18114 757 #if LWIP_IGMP
keir@18114 758 netif->igmp_mac_filter = NULL;
keir@18114 759 #endif /* LWIP_IGMP */
keir@18114 760 +#if ENABLE_LOOPBACK
keir@18114 761 + netif->loop_first = NULL;
keir@18114 762 + netif->loop_last = NULL;
keir@18114 763 +#endif /* ENABLE_LOOPBACK */
keir@18114 764
keir@18114 765 /* remember netif specific state information data */
keir@18114 766 netif->state = state;
keir@18114 767 @@ -114,6 +124,9 @@ netif_add(struct netif *netif, struct ip
keir@18114 768 #if LWIP_NETIF_HWADDRHINT
keir@18114 769 netif->addr_hint = NULL;
keir@18114 770 #endif /* LWIP_NETIF_HWADDRHINT*/
keir@18114 771 +#if ENABLE_LOOPBACK && LWIP_LOOPBACK_MAX_PBUFS
keir@18114 772 + netif->loop_cnt_current = 0;
keir@18114 773 +#endif /* ENABLE_LOOPBACK && LWIP_LOOPBACK_MAX_PBUFS */
keir@18114 774
keir@18114 775 netif_set_addr(netif, ipaddr, netmask, gw);
keir@18114 776
keir@18114 777 @@ -493,7 +506,158 @@ u8_t netif_is_link_up(struct netif *neti
keir@18114 778 */
keir@18114 779 void netif_set_link_callback(struct netif *netif, void (* link_callback)(struct netif *netif ))
keir@18114 780 {
keir@18114 781 - if ( netif )
keir@18114 782 - netif->link_callback = link_callback;
keir@18114 783 + if (netif) {
keir@18114 784 + netif->link_callback = link_callback;
keir@18114 785 + }
keir@18114 786 }
keir@18114 787 #endif /* LWIP_NETIF_LINK_CALLBACK */
keir@18114 788 +
keir@18114 789 +#if ENABLE_LOOPBACK
keir@18114 790 +/**
keir@18114 791 + * Send an IP packet to be received on the same netif (loopif-like).
keir@18114 792 + * The pbuf is simply copied and handed back to netif->input.
keir@18114 793 + * In multithreaded mode, this is done directly since netif->input must put
keir@18114 794 + * the packet on a queue.
keir@18114 795 + * In callback mode, the packet is put on an internal queue and is fed to
keir@18114 796 + * netif->input by netif_poll().
keir@18114 797 + *
keir@18114 798 + * @param netif the lwip network interface structure
keir@18114 799 + * @param p the (IP) packet to 'send'
keir@18114 800 + * @param ipaddr the ip address to send the packet to (not used)
keir@18114 801 + * @return ERR_OK if the packet has been sent
keir@18114 802 + * ERR_MEM if the pbuf used to copy the packet couldn't be allocated
keir@18114 803 + */
keir@18114 804 +err_t
keir@18114 805 +netif_loop_output(struct netif *netif, struct pbuf *p,
keir@18114 806 + struct ip_addr *ipaddr)
keir@18114 807 +{
keir@18114 808 + struct pbuf *r;
keir@18114 809 + err_t err;
keir@18114 810 + struct pbuf *last;
keir@18114 811 +#if LWIP_LOOPBACK_MAX_PBUFS
keir@18114 812 + u8_t clen = 0;
keir@18114 813 +#endif /* LWIP_LOOPBACK_MAX_PBUFS */
keir@18114 814 + SYS_ARCH_DECL_PROTECT(lev);
keir@18114 815 + LWIP_UNUSED_ARG(ipaddr);
keir@18114 816 +
keir@18114 817 + /* Allocate a new pbuf */
keir@18114 818 + r = pbuf_alloc(PBUF_LINK, p->tot_len, PBUF_RAM);
keir@18114 819 + if (r == NULL) {
keir@18114 820 + return ERR_MEM;
keir@18114 821 + }
keir@18114 822 +#if LWIP_LOOPBACK_MAX_PBUFS
keir@18114 823 + clen = pbuf_clen(r);
keir@18114 824 + /* check for overflow or too many pbuf on queue */
keir@18114 825 + if(((netif->loop_cnt_current + clen) < netif->loop_cnt_current) ||
keir@18114 826 + ((netif->loop_cnt_current + clen) > LWIP_LOOPBACK_MAX_PBUFS)) {
keir@18114 827 + pbuf_free(r);
keir@18114 828 + r = NULL;
keir@18114 829 + return ERR_MEM;
keir@18114 830 + }
keir@18114 831 + netif->loop_cnt_current += clen;
keir@18114 832 +#endif /* LWIP_LOOPBACK_MAX_PBUFS */
keir@18114 833 +
keir@18114 834 + /* Copy the whole pbuf queue p into the single pbuf r */
keir@18114 835 + if ((err = pbuf_copy(r, p)) != ERR_OK) {
keir@18114 836 + pbuf_free(r);
keir@18114 837 + r = NULL;
keir@18114 838 + return err;
keir@18114 839 + }
keir@18114 840 +
keir@18114 841 + /* Put the packet on a linked list which gets emptied through calling
keir@18114 842 + netif_poll(). */
keir@18114 843 +
keir@18114 844 + /* let last point to the last pbuf in chain r */
keir@18114 845 + for (last = r; last->next != NULL; last = last->next);
keir@18114 846 +
keir@18114 847 + SYS_ARCH_PROTECT(lev);
keir@18114 848 + if(netif->loop_first != NULL) {
keir@18114 849 + LWIP_ASSERT("if first != NULL, last must also be != NULL", netif->loop_last != NULL);
keir@18114 850 + netif->loop_last->next = r;
keir@18114 851 + netif->loop_last = last;
keir@18114 852 + } else {
keir@18114 853 + netif->loop_first = r;
keir@18114 854 + netif->loop_last = last;
keir@18114 855 + }
keir@18114 856 + SYS_ARCH_UNPROTECT(lev);
keir@18114 857 +
keir@18114 858 +#if LWIP_NETIF_LOOPBACK_MULTITHREADING
keir@18114 859 + /* For multithreading environment, schedule a call to netif_poll */
keir@18114 860 + tcpip_callback(netif_poll, netif);
keir@18114 861 +#endif /* LWIP_NETIF_LOOPBACK_MULTITHREADING */
keir@18114 862 +
keir@18114 863 + return ERR_OK;
keir@18114 864 +}
keir@18114 865 +
keir@18114 866 +/**
keir@18114 867 + * Call netif_poll() in the main loop of your application. This is to prevent
keir@18114 868 + * reentering non-reentrant functions like tcp_input(). Packets passed to
keir@18114 869 + * netif_loop_output() are put on a list that is passed to netif->input() by
keir@18114 870 + * netif_poll().
keir@18114 871 + */
keir@18114 872 +void
keir@18114 873 +netif_poll(struct netif *netif)
keir@18114 874 +{
keir@18114 875 + struct pbuf *in;
keir@18114 876 + SYS_ARCH_DECL_PROTECT(lev);
keir@18114 877 +
keir@18114 878 + do {
keir@18114 879 + /* Get a packet from the list. With SYS_LIGHTWEIGHT_PROT=1, this is protected */
keir@18114 880 + SYS_ARCH_PROTECT(lev);
keir@18114 881 + in = netif->loop_first;
keir@18114 882 + if(in != NULL) {
keir@18114 883 + struct pbuf *in_end = in;
keir@18114 884 +#if LWIP_LOOPBACK_MAX_PBUFS
keir@18114 885 + u8_t clen = pbuf_clen(in);
keir@18114 886 + /* adjust the number of pbufs on queue */
keir@18114 887 + LWIP_ASSERT("netif->loop_cnt_current underflow",
keir@18114 888 + ((netif->loop_cnt_current - clen) < netif->loop_cnt_current));
keir@18114 889 + netif->loop_cnt_current -= clen;
keir@18114 890 +#endif /* LWIP_LOOPBACK_MAX_PBUFS */
keir@18114 891 + while(in_end->len != in_end->tot_len) {
keir@18114 892 + LWIP_ASSERT("bogus pbuf: len != tot_len but next == NULL!", in_end->next != NULL);
keir@18114 893 + in_end = in_end->next;
keir@18114 894 + }
keir@18114 895 + /* 'in_end' now points to the last pbuf from 'in' */
keir@18114 896 + if(in_end == netif->loop_last) {
keir@18114 897 + /* this was the last pbuf in the list */
keir@18114 898 + netif->loop_first = netif->loop_last = NULL;
keir@18114 899 + } else {
keir@18114 900 + /* pop the pbuf off the list */
keir@18114 901 + netif->loop_first = in_end->next;
keir@18114 902 + LWIP_ASSERT("should not be null since first != last!", netif->loop_first != NULL);
keir@18114 903 + }
keir@18114 904 + /* De-queue the pbuf from its successors on the 'loop_' list. */
keir@18114 905 + in_end->next = NULL;
keir@18114 906 + }
keir@18114 907 + SYS_ARCH_UNPROTECT(lev);
keir@18114 908 +
keir@18114 909 + if(in != NULL) {
keir@18114 910 + /* loopback packets are always IP packets! */
keir@18114 911 + if(ip_input(in, netif) != ERR_OK) {
keir@18114 912 + pbuf_free(in);
keir@18114 913 + }
keir@18114 914 + /* Don't reference the packet any more! */
keir@18114 915 + in = NULL;
keir@18114 916 + }
keir@18114 917 + /* go on while there is a packet on the list */
keir@18114 918 + } while(netif->loop_first != NULL);
keir@18114 919 +}
keir@18114 920 +
keir@18114 921 +#if !LWIP_NETIF_LOOPBACK_MULTITHREADING
keir@18114 922 +/**
keir@18114 923 + * Calls netif_poll() for every netif on the netif_list.
keir@18114 924 + */
keir@18114 925 +void
keir@18114 926 +netif_poll_all(void)
keir@18114 927 +{
keir@18114 928 + struct netif *netif = netif_list;
keir@18114 929 + /* loop through netifs */
keir@18114 930 + while (netif != NULL) {
keir@18114 931 + netif_poll(netif);
keir@18114 932 + /* proceed to next network interface */
keir@18114 933 + netif = netif->next;
keir@18114 934 + }
keir@18114 935 +}
keir@18114 936 +#endif /* !LWIP_NETIF_LOOPBACK_MULTITHREADING */
keir@18114 937 +#endif /* ENABLE_LOOPBACK */
keir@18114 938 Index: src/core/pbuf.c
keir@18114 939 ===================================================================
keir@18114 940 RCS file: /sources/lwip/lwip/src/core/pbuf.c,v
keir@18114 941 retrieving revision 1.127
keir@18114 942 retrieving revision 1.128
keir@18114 943 diff -u -p -r1.127 -r1.128
keir@18114 944 --- src/core/pbuf.c 4 Mar 2008 16:37:46 -0000 1.127
keir@18114 945 +++ src/core/pbuf.c 1 Apr 2008 19:05:40 -0000 1.128
keir@18114 946 @@ -667,8 +667,8 @@ pbuf_dechain(struct pbuf *p)
keir@18114 947 *
keir@18114 948 * @note Only one packet is copied, no packet queue!
keir@18114 949 *
keir@18114 950 - * @param p_to pbuf source of the copy
keir@18114 951 - * @param p_from pbuf destination of the copy
keir@18114 952 + * @param p_to pbuf destination of the copy
keir@18114 953 + * @param p_from pbuf source of the copy
keir@18114 954 *
keir@18114 955 * @return ERR_OK if pbuf was copied
keir@18114 956 * ERR_ARG if one of the pbufs is NULL or p_to is not big
keir@18114 957 Index: src/core/stats.c
keir@18114 958 ===================================================================
keir@18114 959 RCS file: /sources/lwip/lwip/src/core/stats.c,v
keir@18114 960 retrieving revision 1.27
keir@18114 961 retrieving revision 1.28
keir@18114 962 diff -u -p -r1.27 -r1.28
keir@18114 963 --- src/core/stats.c 4 Mar 2008 16:31:32 -0000 1.27
keir@18114 964 +++ src/core/stats.c 27 Jun 2008 18:37:54 -0000 1.28
keir@18114 965 @@ -54,7 +54,6 @@ stats_display_proto(struct stats_proto *
keir@18114 966 {
keir@18114 967 LWIP_PLATFORM_DIAG(("\n%s\n\t", name));
keir@18114 968 LWIP_PLATFORM_DIAG(("xmit: %"STAT_COUNTER_F"\n\t", proto->xmit));
keir@18114 969 - LWIP_PLATFORM_DIAG(("rexmit: %"STAT_COUNTER_F"\n\t", proto->rexmit));
keir@18114 970 LWIP_PLATFORM_DIAG(("recv: %"STAT_COUNTER_F"\n\t", proto->recv));
keir@18114 971 LWIP_PLATFORM_DIAG(("fw: %"STAT_COUNTER_F"\n\t", proto->fw));
keir@18114 972 LWIP_PLATFORM_DIAG(("drop: %"STAT_COUNTER_F"\n\t", proto->drop));
keir@18114 973 @@ -68,6 +67,7 @@ stats_display_proto(struct stats_proto *
keir@18114 974 LWIP_PLATFORM_DIAG(("cachehit: %"STAT_COUNTER_F"\n", proto->cachehit));
keir@18114 975 }
keir@18114 976
keir@18114 977 +#if IGMP_STATS
keir@18114 978 void
keir@18114 979 stats_display_igmp(struct stats_igmp *igmp)
keir@18114 980 {
keir@18114 981 @@ -82,7 +82,9 @@ stats_display_igmp(struct stats_igmp *ig
keir@18114 982 LWIP_PLATFORM_DIAG(("report_rxed: %"STAT_COUNTER_F"\n\t", igmp->report_rxed));
keir@18114 983 LWIP_PLATFORM_DIAG(("group_query_rxed: %"STAT_COUNTER_F"\n", igmp->group_query_rxed));
keir@18114 984 }
keir@18114 985 +#endif /* IGMP_STATS */
keir@18114 986
keir@18114 987 +#if MEM_STATS || MEMP_STATS
keir@18114 988 void
keir@18114 989 stats_display_mem(struct stats_mem *mem, char *name)
keir@18114 990 {
keir@18114 991 @@ -93,48 +95,53 @@ stats_display_mem(struct stats_mem *mem,
keir@18114 992 LWIP_PLATFORM_DIAG(("err: %"U32_F"\n", (u32_t)mem->err));
keir@18114 993 }
keir@18114 994
keir@18114 995 +#if MEMP_STATS
keir@18114 996 void
keir@18114 997 -stats_display(void)
keir@18114 998 +stats_display_memp(struct stats_mem *mem, int index)
keir@18114 999 {
keir@18114 1000 -#if MEMP_STATS
keir@18114 1001 - s16_t i;
keir@18114 1002 char * memp_names[] = {
keir@18114 1003 #define LWIP_MEMPOOL(name,num,size,desc) desc,
keir@18114 1004 #include "lwip/memp_std.h"
keir@18114 1005 };
keir@18114 1006 -#endif
keir@18114 1007 -#if LINK_STATS
keir@18114 1008 - stats_display_proto(&lwip_stats.link, "LINK");
keir@18114 1009 -#endif
keir@18114 1010 -#if ETHARP_STATS
keir@18114 1011 - stats_display_proto(&lwip_stats.etharp, "ETHARP");
keir@18114 1012 -#endif
keir@18114 1013 -#if IPFRAG_STATS
keir@18114 1014 - stats_display_proto(&lwip_stats.ip_frag, "IP_FRAG");
keir@18114 1015 -#endif
keir@18114 1016 -#if IP_STATS
keir@18114 1017 - stats_display_proto(&lwip_stats.ip, "IP");
keir@18114 1018 -#endif
keir@18114 1019 -#if ICMP_STATS
keir@18114 1020 - stats_display_proto(&lwip_stats.icmp, "ICMP");
keir@18114 1021 -#endif
keir@18114 1022 -#if IGMP_STATS
keir@18114 1023 - stats_display_igmp(&lwip_stats.igmp);
keir@18114 1024 -#endif
keir@18114 1025 -#if UDP_STATS
keir@18114 1026 - stats_display_proto(&lwip_stats.udp, "UDP");
keir@18114 1027 -#endif
keir@18114 1028 -#if TCP_STATS
keir@18114 1029 - stats_display_proto(&lwip_stats.tcp, "TCP");
keir@18114 1030 -#endif
keir@18114 1031 -#if MEM_STATS
keir@18114 1032 - stats_display_mem(&lwip_stats.mem, "HEAP");
keir@18114 1033 -#endif
keir@18114 1034 -#if MEMP_STATS
keir@18114 1035 + if(index < MEMP_MAX) {
keir@18114 1036 + stats_display_mem(mem, memp_names[index]);
keir@18114 1037 + }
keir@18114 1038 +}
keir@18114 1039 +#endif /* MEMP_STATS */
keir@18114 1040 +#endif /* MEM_STATS || MEMP_STATS */
keir@18114 1041 +
keir@18114 1042 +#if SYS_STATS
keir@18114 1043 +void
keir@18114 1044 +stats_display_sys(struct stats_sys *sys)
keir@18114 1045 +{
keir@18114 1046 + LWIP_PLATFORM_DIAG(("\nSYS\n\t"));
keir@18114 1047 + LWIP_PLATFORM_DIAG(("sem.used: %"U32_F"\n\t", (u32_t)sys->sem.used));
keir@18114 1048 + LWIP_PLATFORM_DIAG(("sem.max: %"U32_F"\n\t", (u32_t)sys->sem.max));
keir@18114 1049 + LWIP_PLATFORM_DIAG(("sem.err: %"U32_F"\n\t", (u32_t)sys->sem.err));
keir@18114 1050 + LWIP_PLATFORM_DIAG(("mbox.used: %"U32_F"\n\t", (u32_t)sys->mbox.used));
keir@18114 1051 + LWIP_PLATFORM_DIAG(("mbox.max: %"U32_F"\n\t", (u32_t)sys->mbox.max));
keir@18114 1052 + LWIP_PLATFORM_DIAG(("mbox.err: %"U32_F"\n\t", (u32_t)sys->mbox.err));
keir@18114 1053 +}
keir@18114 1054 +#endif /* SYS_STATS */
keir@18114 1055 +
keir@18114 1056 +void
keir@18114 1057 +stats_display(void)
keir@18114 1058 +{
keir@18114 1059 + s16_t i;
keir@18114 1060 +
keir@18114 1061 + LINK_STATS_DISPLAY();
keir@18114 1062 + ETHARP_STATS_DISPLAY();
keir@18114 1063 + IPFRAG_STATS_DISPLAY();
keir@18114 1064 + IP_STATS_DISPLAY();
keir@18114 1065 + IGMP_STATS_DISPLAY();
keir@18114 1066 + ICMP_STATS_DISPLAY();
keir@18114 1067 + UDP_STATS_DISPLAY();
keir@18114 1068 + TCP_STATS_DISPLAY();
keir@18114 1069 + MEM_STATS_DISPLAY();
keir@18114 1070 for (i = 0; i < MEMP_MAX; i++) {
keir@18114 1071 - stats_display_mem(&lwip_stats.memp[i], memp_names[i]);
keir@18114 1072 + MEMP_STATS_DISPLAY(i);
keir@18114 1073 }
keir@18114 1074 -#endif
keir@18114 1075 + SYS_STATS_DISPLAY();
keir@18114 1076 }
keir@18114 1077 #endif /* LWIP_STATS_DISPLAY */
keir@18114 1078
keir@18114 1079 Index: src/core/sys.c
keir@18114 1080 ===================================================================
keir@18114 1081 RCS file: /sources/lwip/lwip/src/core/sys.c,v
keir@18114 1082 retrieving revision 1.32
keir@18114 1083 retrieving revision 1.33
keir@18114 1084 diff -u -p -r1.32 -r1.33
keir@18114 1085 --- src/core/sys.c 25 Nov 2007 13:57:05 -0000 1.32
keir@18114 1086 +++ src/core/sys.c 16 Jul 2008 20:36:12 -0000 1.33
keir@18114 1087 @@ -65,7 +65,7 @@ struct sswt_cb
keir@18114 1088 void
keir@18114 1089 sys_mbox_fetch(sys_mbox_t mbox, void **msg)
keir@18114 1090 {
keir@18114 1091 - u32_t time;
keir@18114 1092 + u32_t time_needed;
keir@18114 1093 struct sys_timeouts *timeouts;
keir@18114 1094 struct sys_timeo *tmptimeout;
keir@18114 1095 sys_timeout_handler h;
keir@18114 1096 @@ -76,18 +76,18 @@ sys_mbox_fetch(sys_mbox_t mbox, void **m
keir@18114 1097
keir@18114 1098 if (!timeouts || !timeouts->next) {
keir@18114 1099 UNLOCK_TCPIP_CORE();
keir@18114 1100 - time = sys_arch_mbox_fetch(mbox, msg, 0);
keir@18114 1101 + time_needed = sys_arch_mbox_fetch(mbox, msg, 0);
keir@18114 1102 LOCK_TCPIP_CORE();
keir@18114 1103 } else {
keir@18114 1104 if (timeouts->next->time > 0) {
keir@18114 1105 UNLOCK_TCPIP_CORE();
keir@18114 1106 - time = sys_arch_mbox_fetch(mbox, msg, timeouts->next->time);
keir@18114 1107 + time_needed = sys_arch_mbox_fetch(mbox, msg, timeouts->next->time);
keir@18114 1108 LOCK_TCPIP_CORE();
keir@18114 1109 } else {
keir@18114 1110 - time = SYS_ARCH_TIMEOUT;
keir@18114 1111 + time_needed = SYS_ARCH_TIMEOUT;
keir@18114 1112 }
keir@18114 1113
keir@18114 1114 - if (time == SYS_ARCH_TIMEOUT) {
keir@18114 1115 + if (time_needed == SYS_ARCH_TIMEOUT) {
keir@18114 1116 /* If time == SYS_ARCH_TIMEOUT, a timeout occured before a message
keir@18114 1117 could be fetched. We should now call the timeout handler and
keir@18114 1118 deallocate the memory allocated for the timeout. */
keir@18114 1119 @@ -107,8 +107,8 @@ sys_mbox_fetch(sys_mbox_t mbox, void **m
keir@18114 1120 /* If time != SYS_ARCH_TIMEOUT, a message was received before the timeout
keir@18114 1121 occured. The time variable is set to the number of
keir@18114 1122 milliseconds we waited for the message. */
keir@18114 1123 - if (time < timeouts->next->time) {
keir@18114 1124 - timeouts->next->time -= time;
keir@18114 1125 + if (time_needed < timeouts->next->time) {
keir@18114 1126 + timeouts->next->time -= time_needed;
keir@18114 1127 } else {
keir@18114 1128 timeouts->next->time = 0;
keir@18114 1129 }
keir@18114 1130 @@ -125,7 +125,7 @@ sys_mbox_fetch(sys_mbox_t mbox, void **m
keir@18114 1131 void
keir@18114 1132 sys_sem_wait(sys_sem_t sem)
keir@18114 1133 {
keir@18114 1134 - u32_t time;
keir@18114 1135 + u32_t time_needed;
keir@18114 1136 struct sys_timeouts *timeouts;
keir@18114 1137 struct sys_timeo *tmptimeout;
keir@18114 1138 sys_timeout_handler h;
keir@18114 1139 @@ -139,12 +139,12 @@ sys_sem_wait(sys_sem_t sem)
keir@18114 1140 sys_arch_sem_wait(sem, 0);
keir@18114 1141 } else {
keir@18114 1142 if (timeouts->next->time > 0) {
keir@18114 1143 - time = sys_arch_sem_wait(sem, timeouts->next->time);
keir@18114 1144 + time_needed = sys_arch_sem_wait(sem, timeouts->next->time);
keir@18114 1145 } else {
keir@18114 1146 - time = SYS_ARCH_TIMEOUT;
keir@18114 1147 + time_needed = SYS_ARCH_TIMEOUT;
keir@18114 1148 }
keir@18114 1149
keir@18114 1150 - if (time == SYS_ARCH_TIMEOUT) {
keir@18114 1151 + if (time_needed == SYS_ARCH_TIMEOUT) {
keir@18114 1152 /* If time == SYS_ARCH_TIMEOUT, a timeout occured before a message
keir@18114 1153 could be fetched. We should now call the timeout handler and
keir@18114 1154 deallocate the memory allocated for the timeout. */
keir@18114 1155 @@ -164,8 +164,8 @@ sys_sem_wait(sys_sem_t sem)
keir@18114 1156 /* If time != SYS_ARCH_TIMEOUT, a message was received before the timeout
keir@18114 1157 occured. The time variable is set to the number of
keir@18114 1158 milliseconds we waited for the message. */
keir@18114 1159 - if (time < timeouts->next->time) {
keir@18114 1160 - timeouts->next->time -= time;
keir@18114 1161 + if (time_needed < timeouts->next->time) {
keir@18114 1162 + timeouts->next->time -= time_needed;
keir@18114 1163 } else {
keir@18114 1164 timeouts->next->time = 0;
keir@18114 1165 }
keir@18114 1166 Index: src/core/tcp.c
keir@18114 1167 ===================================================================
keir@18114 1168 RCS file: /sources/lwip/lwip/src/core/tcp.c,v
keir@18114 1169 retrieving revision 1.85
keir@18114 1170 retrieving revision 1.86
keir@18114 1171 diff -u -p -r1.85 -r1.86
keir@18114 1172 --- src/core/tcp.c 22 Jan 2008 21:15:15 -0000 1.85
keir@18114 1173 +++ src/core/tcp.c 26 Mar 2008 11:57:13 -0000 1.86
keir@18114 1174 @@ -509,7 +509,8 @@ tcp_connect(struct tcp_pcb *pcb, struct
keir@18114 1175 pcb->rcv_wnd = TCP_WND;
keir@18114 1176 pcb->rcv_ann_wnd = TCP_WND;
keir@18114 1177 pcb->snd_wnd = TCP_WND;
keir@18114 1178 - /* The send MSS is updated when an MSS option is received. */
keir@18114 1179 + /* As initial send MSS, we use TCP_MSS but limit it to 536.
keir@18114 1180 + The send MSS is updated when an MSS option is received. */
keir@18114 1181 pcb->mss = (TCP_MSS > 536) ? 536 : TCP_MSS;
keir@18114 1182 #if TCP_CALCULATE_EFF_SEND_MSS
keir@18114 1183 pcb->mss = tcp_eff_send_mss(pcb->mss, ipaddr);
keir@18114 1184 @@ -991,7 +992,8 @@ tcp_alloc(u8_t prio)
keir@18114 1185 pcb->rcv_ann_wnd = TCP_WND;
keir@18114 1186 pcb->tos = 0;
keir@18114 1187 pcb->ttl = TCP_TTL;
keir@18114 1188 - /* The send MSS is updated when an MSS option is received. */
keir@18114 1189 + /* As initial send MSS, we use TCP_MSS but limit it to 536.
keir@18114 1190 + The send MSS is updated when an MSS option is received. */
keir@18114 1191 pcb->mss = (TCP_MSS > 536) ? 536 : TCP_MSS;
keir@18114 1192 pcb->rto = 3000 / TCP_SLOW_INTERVAL;
keir@18114 1193 pcb->sa = 0;
keir@18114 1194 Index: src/core/tcp_in.c
keir@18114 1195 ===================================================================
keir@18114 1196 RCS file: /sources/lwip/lwip/src/core/tcp_in.c,v
keir@18114 1197 retrieving revision 1.97
keir@18114 1198 retrieving revision 1.100
keir@18114 1199 diff -u -p -r1.97 -r1.100
keir@18114 1200 --- src/core/tcp_in.c 22 Jan 2008 21:15:15 -0000 1.97
keir@18114 1201 +++ src/core/tcp_in.c 24 Jun 2008 15:46:39 -0000 1.100
keir@18114 1202 @@ -511,7 +511,7 @@ tcp_process(struct tcp_pcb *pcb)
keir@18114 1203 }
keir@18114 1204 } else {
keir@18114 1205 if (TCP_SEQ_BETWEEN(seqno, pcb->rcv_nxt,
keir@18114 1206 - pcb->rcv_nxt+pcb->rcv_ann_wnd)) {
keir@18114 1207 + pcb->rcv_nxt+pcb->rcv_wnd)) {
keir@18114 1208 acceptable = 1;
keir@18114 1209 }
keir@18114 1210 }
keir@18114 1211 @@ -1038,7 +1038,7 @@ tcp_receive(struct tcp_pcb *pcb)
keir@18114 1212 and below rcv_nxt + rcv_wnd) in order to be further
keir@18114 1213 processed. */
keir@18114 1214 if (TCP_SEQ_BETWEEN(seqno, pcb->rcv_nxt,
keir@18114 1215 - pcb->rcv_nxt + pcb->rcv_ann_wnd - 1)){
keir@18114 1216 + pcb->rcv_nxt + pcb->rcv_wnd - 1)){
keir@18114 1217 if (pcb->rcv_nxt == seqno) {
keir@18114 1218 accepted_inseq = 1;
keir@18114 1219 /* The incoming segment is the next in sequence. We check if
keir@18114 1220 @@ -1195,14 +1195,14 @@ tcp_receive(struct tcp_pcb *pcb)
keir@18114 1221 } else {
keir@18114 1222 pcb->ooseq = cseg;
keir@18114 1223 }
keir@18114 1224 - }
keir@18114 1225 - tcp_seg_free(next);
keir@18114 1226 - if (cseg->next != NULL) {
keir@18114 1227 - next = cseg->next;
keir@18114 1228 - if (TCP_SEQ_GT(seqno + cseg->len, next->tcphdr->seqno)) {
keir@18114 1229 - /* We need to trim the incoming segment. */
keir@18114 1230 - cseg->len = (u16_t)(next->tcphdr->seqno - seqno);
keir@18114 1231 - pbuf_realloc(cseg->p, cseg->len);
keir@18114 1232 + tcp_seg_free(next);
keir@18114 1233 + if (cseg->next != NULL) {
keir@18114 1234 + next = cseg->next;
keir@18114 1235 + if (TCP_SEQ_GT(seqno + cseg->len, next->tcphdr->seqno)) {
keir@18114 1236 + /* We need to trim the incoming segment. */
keir@18114 1237 + cseg->len = (u16_t)(next->tcphdr->seqno - seqno);
keir@18114 1238 + pbuf_realloc(cseg->p, cseg->len);
keir@18114 1239 + }
keir@18114 1240 }
keir@18114 1241 }
keir@18114 1242 break;
keir@18114 1243 @@ -1282,10 +1282,7 @@ tcp_receive(struct tcp_pcb *pcb)
keir@18114 1244
keir@18114 1245 }
keir@18114 1246 } else {
keir@18114 1247 - if(!TCP_SEQ_BETWEEN(seqno, pcb->rcv_nxt,
keir@18114 1248 - pcb->rcv_nxt + pcb->rcv_ann_wnd-1)){
keir@18114 1249 - tcp_ack_now(pcb);
keir@18114 1250 - }
keir@18114 1251 + tcp_ack_now(pcb);
keir@18114 1252 }
keir@18114 1253 } else {
keir@18114 1254 /* Segments with length 0 is taken care of here. Segments that
keir@18114 1255 @@ -1331,7 +1328,8 @@ tcp_parseopt(struct tcp_pcb *pcb)
keir@18114 1256 opts[c + 1] == 0x04) {
keir@18114 1257 /* An MSS option with the right option length. */
keir@18114 1258 mss = (opts[c + 2] << 8) | opts[c + 3];
keir@18114 1259 - pcb->mss = mss > TCP_MSS? TCP_MSS: mss;
keir@18114 1260 + /* Limit the mss to the configured TCP_MSS and prevent division by zero */
keir@18114 1261 + pcb->mss = ((mss > TCP_MSS) || (mss == 0)) ? TCP_MSS : mss;
keir@18114 1262
keir@18114 1263 /* And we are done processing options. */
keir@18114 1264 break;
keir@18114 1265 Index: src/core/ipv4/autoip.c
keir@18114 1266 ===================================================================
keir@18114 1267 RCS file: /sources/lwip/lwip/src/core/ipv4/autoip.c,v
keir@18114 1268 retrieving revision 1.16
keir@18114 1269 retrieving revision 1.17
keir@18114 1270 diff -u -p -r1.16 -r1.17
keir@18114 1271 --- src/core/ipv4/autoip.c 26 Jan 2008 16:11:40 -0000 1.16
keir@18114 1272 +++ src/core/ipv4/autoip.c 17 Jun 2008 20:16:23 -0000 1.17
keir@18114 1273 @@ -395,8 +395,8 @@ autoip_arp_reply(struct netif *netif, st
keir@18114 1274 /* Copy struct ip_addr2 to aligned ip_addr, to support compilers without
keir@18114 1275 * structure packing (not using structure copy which breaks strict-aliasing rules).
keir@18114 1276 */
keir@18114 1277 - MEMCPY(&sipaddr, &hdr->sipaddr, sizeof(sipaddr));
keir@18114 1278 - MEMCPY(&dipaddr, &hdr->dipaddr, sizeof(dipaddr));
keir@18114 1279 + SMEMCPY(&sipaddr, &hdr->sipaddr, sizeof(sipaddr));
keir@18114 1280 + SMEMCPY(&dipaddr, &hdr->dipaddr, sizeof(dipaddr));
keir@18114 1281
keir@18114 1282 if ((netif->autoip->state == AUTOIP_STATE_PROBING) ||
keir@18114 1283 ((netif->autoip->state == AUTOIP_STATE_ANNOUNCING) &&
keir@18114 1284 Index: src/core/ipv4/inet_chksum.c
keir@18114 1285 ===================================================================
keir@18114 1286 RCS file: /sources/lwip/lwip/src/core/ipv4/inet_chksum.c,v
keir@18114 1287 retrieving revision 1.4
keir@18114 1288 retrieving revision 1.5
keir@18114 1289 diff -u -p -r1.4 -r1.5
keir@18114 1290 --- src/core/ipv4/inet_chksum.c 10 Mar 2008 16:12:31 -0000 1.4
keir@18114 1291 +++ src/core/ipv4/inet_chksum.c 17 Jun 2008 20:06:25 -0000 1.5
keir@18114 1292 @@ -41,8 +41,6 @@
keir@18114 1293 #include "lwip/inet_chksum.h"
keir@18114 1294 #include "lwip/inet.h"
keir@18114 1295
keir@18114 1296 -#include <string.h>
keir@18114 1297 -
keir@18114 1298 /* These are some reference implementations of the checksum algorithm, with the
keir@18114 1299 * aim of being simple, correct and fully portable. Checksumming is the
keir@18114 1300 * first thing you would want to optimize for your platform. If you create
keir@18114 1301 @@ -65,6 +63,11 @@
keir@18114 1302 # define LWIP_CHKSUM_ALGORITHM 0
keir@18114 1303 #endif
keir@18114 1304
keir@18114 1305 +/** Like the name says... */
keir@18114 1306 +#define SWAP_BYTES_IN_WORD(w) ((w & 0xff) << 8) | ((w & 0xff00) >> 8)
keir@18114 1307 +/** Split an u32_t in two u16_ts and add them up */
keir@18114 1308 +#define FOLD_U32T(u) ((u >> 16) + (u & 0x0000ffffUL))
keir@18114 1309 +
keir@18114 1310 #if (LWIP_CHKSUM_ALGORITHM == 1) /* Version #1 */
keir@18114 1311 /**
keir@18114 1312 * lwip checksum
keir@18114 1313 @@ -86,8 +89,7 @@ lwip_standard_chksum(void *dataptr, u16_
keir@18114 1314 acc = 0;
keir@18114 1315 /* dataptr may be at odd or even addresses */
keir@18114 1316 octetptr = (u8_t*)dataptr;
keir@18114 1317 - while (len > 1)
keir@18114 1318 - {
keir@18114 1319 + while (len > 1) {
keir@18114 1320 /* declare first octet as most significant
keir@18114 1321 thus assume network order, ignoring host order */
keir@18114 1322 src = (*octetptr) << 8;
keir@18114 1323 @@ -98,8 +100,7 @@ lwip_standard_chksum(void *dataptr, u16_
keir@18114 1324 acc += src;
keir@18114 1325 len -= 2;
keir@18114 1326 }
keir@18114 1327 - if (len > 0)
keir@18114 1328 - {
keir@18114 1329 + if (len > 0) {
keir@18114 1330 /* accumulate remaining octet */
keir@18114 1331 src = (*octetptr) << 8;
keir@18114 1332 acc += src;
keir@18114 1333 @@ -154,19 +155,22 @@ lwip_standard_chksum(void *dataptr, int
keir@18114 1334 }
keir@18114 1335
keir@18114 1336 /* Consume left-over byte, if any */
keir@18114 1337 - if (len > 0)
keir@18114 1338 + if (len > 0) {
keir@18114 1339 ((u8_t *)&t)[0] = *(u8_t *)ps;;
keir@18114 1340 + }
keir@18114 1341
keir@18114 1342 /* Add end bytes */
keir@18114 1343 sum += t;
keir@18114 1344
keir@18114 1345 - /* Fold 32-bit sum to 16 bits */
keir@18114 1346 - while ((sum >> 16) != 0)
keir@18114 1347 - sum = (sum & 0xffff) + (sum >> 16);
keir@18114 1348 + /* Fold 32-bit sum to 16 bits
keir@18114 1349 + calling this twice is propably faster than if statements... */
keir@18114 1350 + sum = FOLD_U32T(sum);
keir@18114 1351 + sum = FOLD_U32T(sum);
keir@18114 1352
keir@18114 1353 /* Swap if alignment was odd */
keir@18114 1354 - if (odd)
keir@18114 1355 - sum = ((sum & 0xff) << 8) | ((sum & 0xff00) >> 8);
keir@18114 1356 + if (odd) {
keir@18114 1357 + sum = SWAP_BYTES_IN_WORD(sum);
keir@18114 1358 + }
keir@18114 1359
keir@18114 1360 return sum;
keir@18114 1361 }
keir@18114 1362 @@ -211,18 +215,20 @@ lwip_standard_chksum(void *dataptr, int
keir@18114 1363
keir@18114 1364 while (len > 7) {
keir@18114 1365 tmp = sum + *pl++; /* ping */
keir@18114 1366 - if (tmp < sum)
keir@18114 1367 + if (tmp < sum) {
keir@18114 1368 tmp++; /* add back carry */
keir@18114 1369 + }
keir@18114 1370
keir@18114 1371 sum = tmp + *pl++; /* pong */
keir@18114 1372 - if (sum < tmp)
keir@18114 1373 + if (sum < tmp) {
keir@18114 1374 sum++; /* add back carry */
keir@18114 1375 + }
keir@18114 1376
keir@18114 1377 len -= 8;
keir@18114 1378 }
keir@18114 1379
keir@18114 1380 /* make room in upper bits */
keir@18114 1381 - sum = (sum >> 16) + (sum & 0xffff);
keir@18114 1382 + sum = FOLD_U32T(sum);
keir@18114 1383
keir@18114 1384 ps = (u16_t *)pl;
keir@18114 1385
keir@18114 1386 @@ -233,16 +239,20 @@ lwip_standard_chksum(void *dataptr, int
keir@18114 1387 }
keir@18114 1388
keir@18114 1389 /* dangling tail byte remaining? */
keir@18114 1390 - if (len > 0) /* include odd byte */
keir@18114 1391 + if (len > 0) { /* include odd byte */
keir@18114 1392 ((u8_t *)&t)[0] = *(u8_t *)ps;
keir@18114 1393 + }
keir@18114 1394
keir@18114 1395 sum += t; /* add end bytes */
keir@18114 1396
keir@18114 1397 - while ((sum >> 16) != 0) /* combine halves */
keir@18114 1398 - sum = (sum >> 16) + (sum & 0xffff);
keir@18114 1399 + /* Fold 32-bit sum to 16 bits
keir@18114 1400 + calling this twice is propably faster than if statements... */
keir@18114 1401 + sum = FOLD_U32T(sum);
keir@18114 1402 + sum = FOLD_U32T(sum);
keir@18114 1403
keir@18114 1404 - if (odd)
keir@18114 1405 - sum = ((sum & 0xff) << 8) | ((sum & 0xff00) >> 8);
keir@18114 1406 + if (odd) {
keir@18114 1407 + sum = SWAP_BYTES_IN_WORD(sum);
keir@18114 1408 + }
keir@18114 1409
keir@18114 1410 return sum;
keir@18114 1411 }
keir@18114 1412 @@ -277,18 +287,18 @@ inet_chksum_pseudo(struct pbuf *p,
keir@18114 1413 (void *)q, (void *)q->next));
keir@18114 1414 acc += LWIP_CHKSUM(q->payload, q->len);
keir@18114 1415 /*LWIP_DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): unwrapped lwip_chksum()=%"X32_F" \n", acc));*/
keir@18114 1416 - while ((acc >> 16) != 0) {
keir@18114 1417 - acc = (acc & 0xffffUL) + (acc >> 16);
keir@18114 1418 - }
keir@18114 1419 + /* just executing this next line is probably faster that the if statement needed
keir@18114 1420 + to check whether we really need to execute it, and does no harm */
keir@18114 1421 + acc = FOLD_U32T(acc);
keir@18114 1422 if (q->len % 2 != 0) {
keir@18114 1423 swapped = 1 - swapped;
keir@18114 1424 - acc = ((acc & 0xff) << 8) | ((acc & 0xff00UL) >> 8);
keir@18114 1425 + acc = SWAP_BYTES_IN_WORD(acc);
keir@18114 1426 }
keir@18114 1427 /*LWIP_DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): wrapped lwip_chksum()=%"X32_F" \n", acc));*/
keir@18114 1428 }
keir@18114 1429
keir@18114 1430 if (swapped) {
keir@18114 1431 - acc = ((acc & 0xff) << 8) | ((acc & 0xff00UL) >> 8);
keir@18114 1432 + acc = SWAP_BYTES_IN_WORD(acc);
keir@18114 1433 }
keir@18114 1434 acc += (src->addr & 0xffffUL);
keir@18114 1435 acc += ((src->addr >> 16) & 0xffffUL);
keir@18114 1436 @@ -297,9 +307,10 @@ inet_chksum_pseudo(struct pbuf *p,
keir@18114 1437 acc += (u32_t)htons((u16_t)proto);
keir@18114 1438 acc += (u32_t)htons(proto_len);
keir@18114 1439
keir@18114 1440 - while ((acc >> 16) != 0) {
keir@18114 1441 - acc = (acc & 0xffffUL) + (acc >> 16);
keir@18114 1442 - }
keir@18114 1443 + /* Fold 32-bit sum to 16 bits
keir@18114 1444 + calling this twice is propably faster than if statements... */
keir@18114 1445 + acc = FOLD_U32T(acc);
keir@18114 1446 + acc = FOLD_U32T(acc);
keir@18114 1447 LWIP_DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): pbuf chain lwip_chksum()=%"X32_F"\n", acc));
keir@18114 1448 return (u16_t)~(acc & 0xffffUL);
keir@18114 1449 }
keir@18114 1450 @@ -340,18 +351,17 @@ inet_chksum_pseudo_partial(struct pbuf *
keir@18114 1451 chksum_len -= chklen;
keir@18114 1452 LWIP_ASSERT("delete me", chksum_len < 0x7fff);
keir@18114 1453 /*LWIP_DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): unwrapped lwip_chksum()=%"X32_F" \n", acc));*/
keir@18114 1454 - while ((acc >> 16) != 0) {
keir@18114 1455 - acc = (acc & 0xffffUL) + (acc >> 16);
keir@18114 1456 - }
keir@18114 1457 + /* fold the upper bit down */
keir@18114 1458 + acc = FOLD_U32T(acc);
keir@18114 1459 if (q->len % 2 != 0) {
keir@18114 1460 swapped = 1 - swapped;
keir@18114 1461 - acc = ((acc & 0xff) << 8) | ((acc & 0xff00UL) >> 8);
keir@18114 1462 + acc = SWAP_BYTES_IN_WORD(acc);
keir@18114 1463 }
keir@18114 1464 /*LWIP_DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): wrapped lwip_chksum()=%"X32_F" \n", acc));*/
keir@18114 1465 }
keir@18114 1466
keir@18114 1467 if (swapped) {
keir@18114 1468 - acc = ((acc & 0xff) << 8) | ((acc & 0xff00UL) >> 8);
keir@18114 1469 + acc = SWAP_BYTES_IN_WORD(acc);
keir@18114 1470 }
keir@18114 1471 acc += (src->addr & 0xffffUL);
keir@18114 1472 acc += ((src->addr >> 16) & 0xffffUL);
keir@18114 1473 @@ -360,9 +370,10 @@ inet_chksum_pseudo_partial(struct pbuf *
keir@18114 1474 acc += (u32_t)htons((u16_t)proto);
keir@18114 1475 acc += (u32_t)htons(proto_len);
keir@18114 1476
keir@18114 1477 - while ((acc >> 16) != 0) {
keir@18114 1478 - acc = (acc & 0xffffUL) + (acc >> 16);
keir@18114 1479 - }
keir@18114 1480 + /* Fold 32-bit sum to 16 bits
keir@18114 1481 + calling this twice is propably faster than if statements... */
keir@18114 1482 + acc = FOLD_U32T(acc);
keir@18114 1483 + acc = FOLD_U32T(acc);
keir@18114 1484 LWIP_DEBUGF(INET_DEBUG, ("inet_chksum_pseudo(): pbuf chain lwip_chksum()=%"X32_F"\n", acc));
keir@18114 1485 return (u16_t)~(acc & 0xffffUL);
keir@18114 1486 }
keir@18114 1487 @@ -380,13 +391,7 @@ inet_chksum_pseudo_partial(struct pbuf *
keir@18114 1488 u16_t
keir@18114 1489 inet_chksum(void *dataptr, u16_t len)
keir@18114 1490 {
keir@18114 1491 - u32_t acc;
keir@18114 1492 -
keir@18114 1493 - acc = LWIP_CHKSUM(dataptr, len);
keir@18114 1494 - while ((acc >> 16) != 0) {
keir@18114 1495 - acc = (acc & 0xffff) + (acc >> 16);
keir@18114 1496 - }
keir@18114 1497 - return (u16_t)~(acc & 0xffff);
keir@18114 1498 + return ~LWIP_CHKSUM(dataptr, len);
keir@18114 1499 }
keir@18114 1500
keir@18114 1501 /**
keir@18114 1502 @@ -407,17 +412,15 @@ inet_chksum_pbuf(struct pbuf *p)
keir@18114 1503 swapped = 0;
keir@18114 1504 for(q = p; q != NULL; q = q->next) {
keir@18114 1505 acc += LWIP_CHKSUM(q->payload, q->len);
keir@18114 1506 - while ((acc >> 16) != 0) {
keir@18114 1507 - acc = (acc & 0xffffUL) + (acc >> 16);
keir@18114 1508 - }
keir@18114 1509 + acc = FOLD_U32T(acc);
keir@18114 1510 if (q->len % 2 != 0) {
keir@18114 1511 swapped = 1 - swapped;
keir@18114 1512 - acc = (acc & 0x00ffUL << 8) | (acc & 0xff00UL >> 8);
keir@18114 1513 + acc = SWAP_BYTES_IN_WORD(acc);
keir@18114 1514 }
keir@18114 1515 }
keir@18114 1516
keir@18114 1517 if (swapped) {
keir@18114 1518 - acc = ((acc & 0x00ffUL) << 8) | ((acc & 0xff00UL) >> 8);
keir@18114 1519 + acc = SWAP_BYTES_IN_WORD(acc);
keir@18114 1520 }
keir@18114 1521 return (u16_t)~(acc & 0xffffUL);
keir@18114 1522 }
keir@18114 1523 Index: src/core/ipv4/ip.c
keir@18114 1524 ===================================================================
keir@18114 1525 RCS file: /sources/lwip/lwip/src/core/ipv4/ip.c,v
keir@18114 1526 retrieving revision 1.66
keir@18114 1527 retrieving revision 1.68
keir@18114 1528 diff -u -p -r1.66 -r1.68
keir@18114 1529 --- src/core/ipv4/ip.c 14 Jan 2008 20:53:23 -0000 1.66
keir@18114 1530 +++ src/core/ipv4/ip.c 17 Jun 2008 19:39:22 -0000 1.68
keir@18114 1531 @@ -531,9 +531,19 @@ ip_output_if(struct pbuf *p, struct ip_a
keir@18114 1532 LWIP_DEBUGF(IP_DEBUG, ("ip_output_if: %c%c%"U16_F"\n", netif->name[0], netif->name[1], netif->num));
keir@18114 1533 ip_debug_print(p);
keir@18114 1534
keir@18114 1535 - LWIP_DEBUGF(IP_DEBUG, ("netif->output()"));
keir@18114 1536 +#if (LWIP_NETIF_LOOPBACK || LWIP_HAVE_LOOPIF)
keir@18114 1537 + if (ip_addr_cmp(dest, &netif->ip_addr)) {
keir@18114 1538 + /* Packet to self, enqueue it for loopback */
keir@18114 1539 + LWIP_DEBUGF(IP_DEBUG, ("netif_loop_output()"));
keir@18114 1540 +
keir@18114 1541 + return netif_loop_output(netif, p, dest);
keir@18114 1542 + } else
keir@18114 1543 +#endif /* (LWIP_NETIF_LOOPBACK || LWIP_HAVE_LOOPIF) */
keir@18114 1544 + {
keir@18114 1545 + LWIP_DEBUGF(IP_DEBUG, ("netif->output()"));
keir@18114 1546
keir@18114 1547 - return netif->output(netif, p, dest);
keir@18114 1548 + return netif->output(netif, p, dest);
keir@18114 1549 + }
keir@18114 1550 }
keir@18114 1551
keir@18114 1552 /**
keir@18114 1553 Index: src/include/lwip/debug.h
keir@18114 1554 ===================================================================
keir@18114 1555 RCS file: /sources/lwip/lwip/src/include/lwip/debug.h,v
keir@18114 1556 retrieving revision 1.37
keir@18114 1557 retrieving revision 1.39
keir@18114 1558 diff -u -p -r1.37 -r1.39
keir@18114 1559 --- src/include/lwip/debug.h 22 Sep 2007 11:16:07 -0000 1.37
keir@18114 1560 +++ src/include/lwip/debug.h 16 Jul 2008 20:36:22 -0000 1.39
keir@18114 1561 @@ -61,26 +61,28 @@
keir@18114 1562 #define LWIP_DBG_HALT 0x08U
keir@18114 1563
keir@18114 1564 #ifndef LWIP_NOASSERT
keir@18114 1565 -#define LWIP_ASSERT(x,y) do { if(!(y)) LWIP_PLATFORM_ASSERT(x); } while(0)
keir@18114 1566 +#define LWIP_ASSERT(message, assertion) do { if(!(assertion)) \
keir@18114 1567 + LWIP_PLATFORM_ASSERT(message); } while(0)
keir@18114 1568 #else /* LWIP_NOASSERT */
keir@18114 1569 -#define LWIP_ASSERT(x,y)
keir@18114 1570 +#define LWIP_ASSERT(message, assertion)
keir@18114 1571 #endif /* LWIP_NOASSERT */
keir@18114 1572
keir@18114 1573 -/** print "m" message only if "e" is true, and execute "h" expression */
keir@18114 1574 +/** if "expression" isn't true, then print "message" and execute "handler" expression */
keir@18114 1575 #ifndef LWIP_ERROR
keir@18114 1576 -#define LWIP_ERROR(m,e,h) do { if (!(e)) { LWIP_PLATFORM_ASSERT(m); h;}} while(0)
keir@18114 1577 +#define LWIP_ERROR(message, expression, handler) do { if (!(expression)) { \
keir@18114 1578 + LWIP_PLATFORM_ASSERT(message); handler;}} while(0)
keir@18114 1579 #endif /* LWIP_ERROR */
keir@18114 1580
keir@18114 1581 #ifdef LWIP_DEBUG
keir@18114 1582 /** print debug message only if debug message type is enabled...
keir@18114 1583 * AND is of correct type AND is at least LWIP_DBG_LEVEL
keir@18114 1584 */
keir@18114 1585 -#define LWIP_DEBUGF(debug,x) do { \
keir@18114 1586 +#define LWIP_DEBUGF(debug, message) do { \
keir@18114 1587 if ( \
keir@18114 1588 ((debug) & LWIP_DBG_ON) && \
keir@18114 1589 ((debug) & LWIP_DBG_TYPES_ON) && \
keir@18114 1590 ((s16_t)((debug) & LWIP_DBG_MASK_LEVEL) >= LWIP_DBG_MIN_LEVEL)) { \
keir@18114 1591 - LWIP_PLATFORM_DIAG(x); \
keir@18114 1592 + LWIP_PLATFORM_DIAG(message); \
keir@18114 1593 if ((debug) & LWIP_DBG_HALT) { \
keir@18114 1594 while(1); \
keir@18114 1595 } \
keir@18114 1596 @@ -88,7 +90,7 @@
keir@18114 1597 } while(0)
keir@18114 1598
keir@18114 1599 #else /* LWIP_DEBUG */
keir@18114 1600 -#define LWIP_DEBUGF(debug,x)
keir@18114 1601 +#define LWIP_DEBUGF(debug, message)
keir@18114 1602 #endif /* LWIP_DEBUG */
keir@18114 1603
keir@18114 1604 #endif /* __LWIP_DEBUG_H__ */
keir@18114 1605 Index: src/include/lwip/err.h
keir@18114 1606 ===================================================================
keir@18114 1607 RCS file: /sources/lwip/lwip/src/include/lwip/err.h,v
keir@18114 1608 retrieving revision 1.13
keir@18114 1609 retrieving revision 1.15
keir@18114 1610 diff -u -p -r1.13 -r1.15
keir@18114 1611 --- src/include/lwip/err.h 13 Dec 2007 23:06:50 -0000 1.13
keir@18114 1612 +++ src/include/lwip/err.h 17 Jun 2008 20:27:32 -0000 1.15
keir@18114 1613 @@ -33,37 +33,43 @@
keir@18114 1614 #define __LWIP_ERR_H__
keir@18114 1615
keir@18114 1616 #include "lwip/opt.h"
keir@18114 1617 +#include "lwip/arch.h"
keir@18114 1618
keir@18114 1619 #ifdef __cplusplus
keir@18114 1620 extern "C" {
keir@18114 1621 #endif
keir@18114 1622
keir@18114 1623 -typedef s8_t err_t;
keir@18114 1624 +/** Define LWIP_ERR_T in cc.h if you want to use
keir@18114 1625 + * a different type for your platform (must be signed). */
keir@18114 1626 +#ifdef LWIP_ERR_T
keir@18114 1627 +typedef LWIP_ERR_T err_t;
keir@18114 1628 +#else /* LWIP_ERR_T */
keir@18114 1629 + typedef s8_t err_t;
keir@18114 1630 +#endif /* LWIP_ERR_T*/
keir@18114 1631
keir@18114 1632 /* Definitions for error constants. */
keir@18114 1633
keir@18114 1634 #define ERR_OK 0 /* No error, everything OK. */
keir@18114 1635 #define ERR_MEM -1 /* Out of memory error. */
keir@18114 1636 #define ERR_BUF -2 /* Buffer error. */
keir@18114 1637 -#define ERR_RTE -3 /* Routing problem. */
keir@18114 1638 +#define ERR_TIMEOUT -3 /* Timeout. */
keir@18114 1639 +#define ERR_RTE -4 /* Routing problem. */
keir@18114 1640
keir@18114 1641 #define ERR_IS_FATAL(e) ((e) < ERR_RTE)
keir@18114 1642
keir@18114 1643 -#define ERR_ABRT -4 /* Connection aborted. */
keir@18114 1644 -#define ERR_RST -5 /* Connection reset. */
keir@18114 1645 -#define ERR_CLSD -6 /* Connection closed. */
keir@18114 1646 -#define ERR_CONN -7 /* Not connected. */
keir@18114 1647 +#define ERR_ABRT -5 /* Connection aborted. */
keir@18114 1648 +#define ERR_RST -6 /* Connection reset. */
keir@18114 1649 +#define ERR_CLSD -7 /* Connection closed. */
keir@18114 1650 +#define ERR_CONN -8 /* Not connected. */
keir@18114 1651
keir@18114 1652 -#define ERR_VAL -8 /* Illegal value. */
keir@18114 1653 +#define ERR_VAL -9 /* Illegal value. */
keir@18114 1654
keir@18114 1655 -#define ERR_ARG -9 /* Illegal argument. */
keir@18114 1656 +#define ERR_ARG -10 /* Illegal argument. */
keir@18114 1657
keir@18114 1658 -#define ERR_USE -10 /* Address in use. */
keir@18114 1659 +#define ERR_USE -11 /* Address in use. */
keir@18114 1660
keir@18114 1661 -#define ERR_IF -11 /* Low-level netif error */
keir@18114 1662 -#define ERR_ISCONN -12 /* Already connected. */
keir@18114 1663 -
keir@18114 1664 -#define ERR_TIMEOUT -13 /* Timeout. */
keir@18114 1665 +#define ERR_IF -12 /* Low-level netif error */
keir@18114 1666 +#define ERR_ISCONN -13 /* Already connected. */
keir@18114 1667
keir@18114 1668 #define ERR_INPROGRESS -14 /* Operation in progress */
keir@18114 1669
keir@18114 1670 Index: src/include/lwip/mem.h
keir@18114 1671 ===================================================================
keir@18114 1672 RCS file: /sources/lwip/lwip/src/include/lwip/mem.h,v
keir@18114 1673 retrieving revision 1.21
keir@18114 1674 retrieving revision 1.22
keir@18114 1675 diff -u -p -r1.21 -r1.22
keir@18114 1676 --- src/include/lwip/mem.h 4 Mar 2008 16:31:32 -0000 1.21
keir@18114 1677 +++ src/include/lwip/mem.h 30 May 2008 11:37:15 -0000 1.22
keir@18114 1678 @@ -50,16 +50,16 @@ typedef size_t mem_size_t;
keir@18114 1679 * allow these defines to be overridden.
keir@18114 1680 */
keir@18114 1681 #ifndef mem_free
keir@18114 1682 -#define mem_free(x) free(x)
keir@18114 1683 +#define mem_free free
keir@18114 1684 #endif
keir@18114 1685 #ifndef mem_malloc
keir@18114 1686 -#define mem_malloc(x) malloc(x)
keir@18114 1687 +#define mem_malloc malloc
keir@18114 1688 #endif
keir@18114 1689 #ifndef mem_calloc
keir@18114 1690 -#define mem_calloc(x, y) calloc(x, y)
keir@18114 1691 +#define mem_calloc calloc
keir@18114 1692 #endif
keir@18114 1693 #ifndef mem_realloc
keir@18114 1694 -#define mem_realloc(x, size) (x)
keir@18114 1695 +#define mem_realloc realloc
keir@18114 1696 #endif
keir@18114 1697 #else /* MEM_LIBC_MALLOC */
keir@18114 1698
keir@18114 1699 Index: src/include/lwip/netif.h
keir@18114 1700 ===================================================================
keir@18114 1701 RCS file: /sources/lwip/lwip/src/include/lwip/netif.h,v
keir@18114 1702 retrieving revision 1.43
keir@18114 1703 retrieving revision 1.46
keir@18114 1704 diff -u -p -r1.43 -r1.46
keir@18114 1705 --- src/include/lwip/netif.h 9 Oct 2007 19:59:59 -0000 1.43
keir@18114 1706 +++ src/include/lwip/netif.h 19 Jun 2008 16:27:23 -0000 1.46
keir@18114 1707 @@ -34,6 +34,8 @@
keir@18114 1708
keir@18114 1709 #include "lwip/opt.h"
keir@18114 1710
keir@18114 1711 +#define ENABLE_LOOPBACK (LWIP_NETIF_LOOPBACK || LWIP_HAVE_LOOPIF)
keir@18114 1712 +
keir@18114 1713 #include "lwip/err.h"
keir@18114 1714
keir@18114 1715 #include "lwip/ip_addr.h"
keir@18114 1716 @@ -165,6 +167,14 @@ struct netif {
keir@18114 1717 #if LWIP_NETIF_HWADDRHINT
keir@18114 1718 u8_t *addr_hint;
keir@18114 1719 #endif /* LWIP_NETIF_HWADDRHINT */
keir@18114 1720 +#if ENABLE_LOOPBACK
keir@18114 1721 + /* List of packets to be queued for ourselves. */
keir@18114 1722 + struct pbuf *loop_first;
keir@18114 1723 + struct pbuf *loop_last;
keir@18114 1724 +#if LWIP_LOOPBACK_MAX_PBUFS
keir@18114 1725 + u16_t loop_cnt_current;
keir@18114 1726 +#endif /* LWIP_LOOPBACK_MAX_PBUFS */
keir@18114 1727 +#endif /* ENABLE_LOOPBACK */
keir@18114 1728 };
keir@18114 1729
keir@18114 1730 #if LWIP_SNMP
keir@18114 1731 @@ -242,4 +252,12 @@ void netif_set_link_callback(struct neti
keir@18114 1732 }
keir@18114 1733 #endif
keir@18114 1734
keir@18114 1735 +#if ENABLE_LOOPBACK
keir@18114 1736 +err_t netif_loop_output(struct netif *netif, struct pbuf *p, struct ip_addr *dest_ip);
keir@18114 1737 +void netif_poll(struct netif *netif);
keir@18114 1738 +#if !LWIP_NETIF_LOOPBACK_MULTITHREADING
keir@18114 1739 +void netif_poll_all(void);
keir@18114 1740 +#endif /* !LWIP_NETIF_LOOPBACK_MULTITHREADING */
keir@18114 1741 +#endif /* ENABLE_LOOPBACK */
keir@18114 1742 +
keir@18114 1743 #endif /* __LWIP_NETIF_H__ */
keir@18114 1744 Index: src/include/lwip/opt.h
keir@18114 1745 ===================================================================
keir@18114 1746 RCS file: /sources/lwip/lwip/src/include/lwip/opt.h,v
keir@18114 1747 retrieving revision 1.116
keir@18114 1748 retrieving revision 1.122
keir@18114 1749 diff -u -p -r1.116 -r1.122
keir@18114 1750 --- src/include/lwip/opt.h 31 Jan 2008 18:19:29 -0000 1.116
keir@18114 1751 +++ src/include/lwip/opt.h 30 Jun 2008 18:16:52 -0000 1.122
keir@18114 1752 @@ -155,6 +155,27 @@
keir@18114 1753 #define MEMP_USE_CUSTOM_POOLS 0
keir@18114 1754 #endif
keir@18114 1755
keir@18114 1756 +/**
keir@18114 1757 + * Set this to 1 if you want to free PBUF_RAM pbufs (or call mem_free()) from
keir@18114 1758 + * interrupt context (or another context that doesn't allow waiting for a
keir@18114 1759 + * semaphore).
keir@18114 1760 + * If set to 1, mem_malloc will be protected by a semaphore and SYS_ARCH_PROTECT,
keir@18114 1761 + * while mem_free will only use SYS_ARCH_PROTECT. mem_malloc SYS_ARCH_UNPROTECTs
keir@18114 1762 + * with each loop so that mem_free can run.
keir@18114 1763 + *
keir@18114 1764 + * ATTENTION: As you can see from the above description, this leads to dis-/
keir@18114 1765 + * enabling interrupts often, which can be slow! Also, on low memory, mem_malloc
keir@18114 1766 + * can need longer.
keir@18114 1767 + *
keir@18114 1768 + * If you don't want that, at least for NO_SYS=0, you can still use the following
keir@18114 1769 + * functions to enqueue a deallocation call which then runs in the tcpip_thread
keir@18114 1770 + * context:
keir@18114 1771 + * - pbuf_free_callback(p);
keir@18114 1772 + * - mem_free_callback(m);
keir@18114 1773 + */
keir@18114 1774 +#ifndef LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT
keir@18114 1775 +#define LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT 0
keir@18114 1776 +#endif
keir@18114 1777
keir@18114 1778 /*
keir@18114 1779 ------------------------------------------------
keir@18114 1780 @@ -815,6 +836,39 @@
keir@18114 1781 #define LWIP_NETIF_HWADDRHINT 0
keir@18114 1782 #endif
keir@18114 1783
keir@18114 1784 +/**
keir@18114 1785 + * LWIP_NETIF_LOOPBACK==1: Support sending packets with a destination IP
keir@18114 1786 + * address equal to the netif IP address, looping them back up the stack.
keir@18114 1787 + */
keir@18114 1788 +#ifndef LWIP_NETIF_LOOPBACK
keir@18114 1789 +#define LWIP_NETIF_LOOPBACK 0
keir@18114 1790 +#endif
keir@18114 1791 +
keir@18114 1792 +/**
keir@18114 1793 + * LWIP_LOOPBACK_MAX_PBUFS: Maximum number of pbufs on queue for loopback
keir@18114 1794 + * sending for each netif (0 = disabled)
keir@18114 1795 + */
keir@18114 1796 +#ifndef LWIP_LOOPBACK_MAX_PBUFS
keir@18114 1797 +#define LWIP_LOOPBACK_MAX_PBUFS 0
keir@18114 1798 +#endif
keir@18114 1799 +
keir@18114 1800 +/**
keir@18114 1801 + * LWIP_NETIF_LOOPBACK_MULTITHREADING: Indicates whether threading is enabled in
keir@18114 1802 + * the system, as netifs must change how they behave depending on this setting
keir@18114 1803 + * for the LWIP_NETIF_LOOPBACK option to work.
keir@18114 1804 + * Setting this is needed to avoid reentering non-reentrant functions like
keir@18114 1805 + * tcp_input().
keir@18114 1806 + * LWIP_NETIF_LOOPBACK_MULTITHREADING==1: Indicates that the user is using a
keir@18114 1807 + * multithreaded environment like tcpip.c. In this case, netif->input()
keir@18114 1808 + * is called directly.
keir@18114 1809 + * LWIP_NETIF_LOOPBACK_MULTITHREADING==0: Indicates a polling (or NO_SYS) setup.
keir@18114 1810 + * The packets are put on a list and netif_poll() must be called in
keir@18114 1811 + * the main application loop.
keir@18114 1812 + */
keir@18114 1813 +#ifndef LWIP_NETIF_LOOPBACK_MULTITHREADING
keir@18114 1814 +#define LWIP_NETIF_LOOPBACK_MULTITHREADING (!NO_SYS)
keir@18114 1815 +#endif
keir@18114 1816 +
keir@18114 1817 /*
keir@18114 1818 ------------------------------------
keir@18114 1819 ---------- LOOPIF options ----------
keir@18114 1820 @@ -827,20 +881,16 @@
keir@18114 1821 #define LWIP_HAVE_LOOPIF 0
keir@18114 1822 #endif
keir@18114 1823
keir@18114 1824 +/*
keir@18114 1825 + ------------------------------------
keir@18114 1826 + ---------- SLIPIF options ----------
keir@18114 1827 + ------------------------------------
keir@18114 1828 +*/
keir@18114 1829 /**
keir@18114 1830 - * LWIP_LOOPIF_MULTITHREADING: Indicates whether threading is enabled in
keir@18114 1831 - * the system, as LOOPIF must change how it behaves depending on this setting.
keir@18114 1832 - * Setting this is needed to avoid reentering non-reentrant functions like
keir@18114 1833 - * tcp_input().
keir@18114 1834 - * LWIP_LOOPIF_MULTITHREADING==1: Indicates that the user is using a
keir@18114 1835 - * multithreaded environment like tcpip.c. In this case, netif->input()
keir@18114 1836 - * is called directly.
keir@18114 1837 - * LWIP_LOOPIF_MULTITHREADING==0: Indicates a polling (or NO_SYS) setup.
keir@18114 1838 - * The packets are put on a list and loopif_poll() must be called in
keir@18114 1839 - * the main application loop.
keir@18114 1840 + * LWIP_HAVE_SLIPIF==1: Support slip interface and slipif.c
keir@18114 1841 */
keir@18114 1842 -#ifndef LWIP_LOOPIF_MULTITHREADING
keir@18114 1843 -#define LWIP_LOOPIF_MULTITHREADING 1
keir@18114 1844 +#ifndef LWIP_HAVE_SLIPIF
keir@18114 1845 +#define LWIP_HAVE_SLIPIF 0
keir@18114 1846 #endif
keir@18114 1847
keir@18114 1848 /*
keir@18114 1849 Index: src/include/lwip/sio.h
keir@18114 1850 ===================================================================
keir@18114 1851 RCS file: /sources/lwip/lwip/src/include/lwip/sio.h,v
keir@18114 1852 retrieving revision 1.7
keir@18114 1853 retrieving revision 1.8
keir@18114 1854 diff -u -p -r1.7 -r1.8
keir@18114 1855 --- src/include/lwip/sio.h 6 Sep 2007 16:43:44 -0000 1.7
keir@18114 1856 +++ src/include/lwip/sio.h 27 Mar 2008 18:06:02 -0000 1.8
keir@18114 1857 @@ -32,16 +32,24 @@
keir@18114 1858 * It needs to be implemented by those platforms which need SLIP or PPP
keir@18114 1859 */
keir@18114 1860
keir@18114 1861 +#ifndef __SIO_H__
keir@18114 1862 +#define __SIO_H__
keir@18114 1863 +
keir@18114 1864 #include "lwip/arch.h"
keir@18114 1865
keir@18114 1866 #ifdef __cplusplus
keir@18114 1867 extern "C" {
keir@18114 1868 #endif
keir@18114 1869
keir@18114 1870 +/* If you want to define sio_fd_t elsewhere or differently,
keir@18114 1871 + define this in your cc.h file. */
keir@18114 1872 #ifndef __sio_fd_t_defined
keir@18114 1873 typedef void * sio_fd_t;
keir@18114 1874 #endif
keir@18114 1875
keir@18114 1876 +/* The following functions can be defined to something else in your cc.h file
keir@18114 1877 + or be implemented in your custom sio.c file. */
keir@18114 1878 +
keir@18114 1879 #ifndef sio_open
keir@18114 1880 sio_fd_t sio_open(u8_t);
keir@18114 1881 #endif
keir@18114 1882 @@ -69,3 +77,5 @@ void sio_read_abort(sio_fd_t);
keir@18114 1883 #ifdef __cplusplus
keir@18114 1884 }
keir@18114 1885 #endif
keir@18114 1886 +
keir@18114 1887 +#endif /* __SIO_H__ */
keir@18114 1888 Index: src/include/lwip/sockets.h
keir@18114 1889 ===================================================================
keir@18114 1890 RCS file: /sources/lwip/lwip/src/include/lwip/sockets.h,v
keir@18114 1891 retrieving revision 1.38
keir@18114 1892 retrieving revision 1.39
keir@18114 1893 diff -u -p -r1.38 -r1.39
keir@18114 1894 --- src/include/lwip/sockets.h 2 Dec 2007 15:24:02 -0000 1.38
keir@18114 1895 +++ src/include/lwip/sockets.h 26 Apr 2008 10:46:23 -0000 1.39
keir@18114 1896 @@ -177,7 +177,22 @@ typedef struct ip_mreq {
keir@18114 1897 } ip_mreq;
keir@18114 1898 #endif /* LWIP_IGMP */
keir@18114 1899
keir@18114 1900 -/* Unimplemented for now... */
keir@18114 1901 +/*
keir@18114 1902 + * The Type of Service provides an indication of the abstract
keir@18114 1903 + * parameters of the quality of service desired. These parameters are
keir@18114 1904 + * to be used to guide the selection of the actual service parameters
keir@18114 1905 + * when transmitting a datagram through a particular network. Several
keir@18114 1906 + * networks offer service precedence, which somehow treats high
keir@18114 1907 + * precedence traffic as more important than other traffic (generally
keir@18114 1908 + * by accepting only traffic above a certain precedence at time of high
keir@18114 1909 + * load). The major choice is a three way tradeoff between low-delay,
keir@18114 1910 + * high-reliability, and high-throughput.
keir@18114 1911 + * The use of the Delay, Throughput, and Reliability indications may
keir@18114 1912 + * increase the cost (in some sense) of the service. In many networks
keir@18114 1913 + * better performance for one of these parameters is coupled with worse
keir@18114 1914 + * performance on another. Except for very unusual cases at most two
keir@18114 1915 + * of these three indications should be set.
keir@18114 1916 + */
keir@18114 1917 #define IPTOS_TOS_MASK 0x1E
keir@18114 1918 #define IPTOS_TOS(tos) ((tos) & IPTOS_TOS_MASK)
keir@18114 1919 #define IPTOS_LOWDELAY 0x10
keir@18114 1920 @@ -187,7 +202,13 @@ typedef struct ip_mreq {
keir@18114 1921 #define IPTOS_MINCOST IPTOS_LOWCOST
keir@18114 1922
keir@18114 1923 /*
keir@18114 1924 - * Definitions for IP precedence (also in ip_tos) (Unimplemented)
keir@18114 1925 + * The Network Control precedence designation is intended to be used
keir@18114 1926 + * within a network only. The actual use and control of that
keir@18114 1927 + * designation is up to each network. The Internetwork Control
keir@18114 1928 + * designation is intended for use by gateway control originators only.
keir@18114 1929 + * If the actual use of these precedence designations is of concern to
keir@18114 1930 + * a particular network, it is the responsibility of that network to
keir@18114 1931 + * control the access to, and use of, those precedence designations.
keir@18114 1932 */
keir@18114 1933 #define IPTOS_PREC_MASK 0xe0
keir@18114 1934 #define IPTOS_PREC(tos) ((tos) & IPTOS_PREC_MASK)
keir@18114 1935 Index: src/include/lwip/stats.h
keir@18114 1936 ===================================================================
keir@18114 1937 RCS file: /sources/lwip/lwip/src/include/lwip/stats.h,v
keir@18114 1938 retrieving revision 1.19
keir@18114 1939 retrieving revision 1.23
keir@18114 1940 diff -u -p -r1.19 -r1.23
keir@18114 1941 --- src/include/lwip/stats.h 28 Nov 2007 21:25:07 -0000 1.19
keir@18114 1942 +++ src/include/lwip/stats.h 8 Jul 2008 09:15:57 -0000 1.23
keir@18114 1943 @@ -57,7 +57,6 @@ extern "C" {
keir@18114 1944
keir@18114 1945 struct stats_proto {
keir@18114 1946 STAT_COUNTER xmit; /* Transmitted packets. */
keir@18114 1947 - STAT_COUNTER rexmit; /* Retransmitted packets. */
keir@18114 1948 STAT_COUNTER recv; /* Received packets. */
keir@18114 1949 STAT_COUNTER fw; /* Forwarded packets. */
keir@18114 1950 STAT_COUNTER drop; /* Dropped packets. */
keir@18114 1951 @@ -87,7 +86,8 @@ struct stats_mem {
keir@18114 1952 mem_size_t avail;
keir@18114 1953 mem_size_t used;
keir@18114 1954 mem_size_t max;
keir@18114 1955 - mem_size_t err;
keir@18114 1956 + STAT_COUNTER err;
keir@18114 1957 + STAT_COUNTER illegal;
keir@18114 1958 };
keir@18114 1959
keir@18114 1960 struct stats_syselem {
keir@18114 1961 @@ -142,64 +142,138 @@ extern struct stats_ lwip_stats;
keir@18114 1962 #define stats_init() /* Compatibility define, not init needed. */
keir@18114 1963
keir@18114 1964 #define STATS_INC(x) ++lwip_stats.x
keir@18114 1965 +#define STATS_DEC(x) --lwip_stats.x
keir@18114 1966 #else
keir@18114 1967 #define stats_init()
keir@18114 1968 #define STATS_INC(x)
keir@18114 1969 +#define STATS_DEC(x)
keir@18114 1970 #endif /* LWIP_STATS */
keir@18114 1971
keir@18114 1972 #if TCP_STATS
keir@18114 1973 #define TCP_STATS_INC(x) STATS_INC(x)
keir@18114 1974 +#define TCP_STATS_DISPLAY() stats_display_proto(&lwip_stats.tcp, "TCP")
keir@18114 1975 #else
keir@18114 1976 #define TCP_STATS_INC(x)
keir@18114 1977 +#define TCP_STATS_DISPLAY()
keir@18114 1978 #endif
keir@18114 1979
keir@18114 1980 #if UDP_STATS
keir@18114 1981 #define UDP_STATS_INC(x) STATS_INC(x)
keir@18114 1982 +#define UDP_STATS_DISPLAY() stats_display_proto(&lwip_stats.udp, "UDP")
keir@18114 1983 #else
keir@18114 1984 #define UDP_STATS_INC(x)
keir@18114 1985 +#define UDP_STATS_DISPLAY()
keir@18114 1986 #endif
keir@18114 1987
keir@18114 1988 #if ICMP_STATS
keir@18114 1989 #define ICMP_STATS_INC(x) STATS_INC(x)
keir@18114 1990 +#define ICMP_STATS_DISPLAY() stats_display_proto(&lwip_stats.icmp, "ICMP")
keir@18114 1991 #else
keir@18114 1992 #define ICMP_STATS_INC(x)
keir@18114 1993 +#define ICMP_STATS_DISPLAY()
keir@18114 1994 #endif
keir@18114 1995
keir@18114 1996 #if IGMP_STATS
keir@18114 1997 #define IGMP_STATS_INC(x) STATS_INC(x)
keir@18114 1998 +#define IGMP_STATS_DISPLAY() stats_display_igmp(&lwip_stats.igmp)
keir@18114 1999 #else
keir@18114 2000 #define IGMP_STATS_INC(x)
keir@18114 2001 +#define IGMP_STATS_DISPLAY()
keir@18114 2002 #endif
keir@18114 2003
keir@18114 2004 #if IP_STATS
keir@18114 2005 #define IP_STATS_INC(x) STATS_INC(x)
keir@18114 2006 +#define IP_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip, "IP")
keir@18114 2007 #else
keir@18114 2008 #define IP_STATS_INC(x)
keir@18114 2009 +#define IP_STATS_DISPLAY()
keir@18114 2010 #endif
keir@18114 2011
keir@18114 2012 #if IPFRAG_STATS
keir@18114 2013 #define IPFRAG_STATS_INC(x) STATS_INC(x)
keir@18114 2014 +#define IPFRAG_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip_frag, "IP_FRAG")
keir@18114 2015 #else
keir@18114 2016 #define IPFRAG_STATS_INC(x)
keir@18114 2017 +#define IPFRAG_STATS_DISPLAY()
keir@18114 2018 #endif
keir@18114 2019
keir@18114 2020 #if ETHARP_STATS
keir@18114 2021 #define ETHARP_STATS_INC(x) STATS_INC(x)
keir@18114 2022 +#define ETHARP_STATS_DISPLAY() stats_display_proto(&lwip_stats.etharp, "ETHARP")
keir@18114 2023 #else
keir@18114 2024 #define ETHARP_STATS_INC(x)
keir@18114 2025 +#define ETHARP_STATS_DISPLAY()
keir@18114 2026 #endif
keir@18114 2027
keir@18114 2028 #if LINK_STATS
keir@18114 2029 #define LINK_STATS_INC(x) STATS_INC(x)
keir@18114 2030 +#define LINK_STATS_DISPLAY() stats_display_proto(&lwip_stats.link, "LINK")
keir@18114 2031 #else
keir@18114 2032 #define LINK_STATS_INC(x)
keir@18114 2033 +#define LINK_STATS_DISPLAY()
keir@18114 2034 +#endif
keir@18114 2035 +
keir@18114 2036 +#if MEM_STATS
keir@18114 2037 +#define MEM_STATS_AVAIL(x, y) lwip_stats.mem.x = y
keir@18114 2038 +#define MEM_STATS_INC(x) STATS_INC(mem.x)
keir@18114 2039 +#define MEM_STATS_INC_USED(x, y) do { lwip_stats.mem.used += y; \
keir@18114 2040 + if (lwip_stats.mem.max < lwip_stats.mem.used) { \
keir@18114 2041 + lwip_stats.mem.max = lwip_stats.mem.used; \
keir@18114 2042 + } \
keir@18114 2043 + } while(0)
keir@18114 2044 +#define MEM_STATS_DEC_USED(x, y) lwip_stats.mem.x -= y
keir@18114 2045 +#define MEM_STATS_DISPLAY() stats_display_mem(&lwip_stats.mem, "HEAP")
keir@18114 2046 +#else
keir@18114 2047 +#define MEM_STATS_AVAIL(x, y)
keir@18114 2048 +#define MEM_STATS_INC(x)
keir@18114 2049 +#define MEM_STATS_INC_USED(x, y)
keir@18114 2050 +#define MEM_STATS_DEC_USED(x, y)
keir@18114 2051 +#define MEM_STATS_DISPLAY()
keir@18114 2052 +#endif
keir@18114 2053 +
keir@18114 2054 +#if MEMP_STATS
keir@18114 2055 +#define MEMP_STATS_AVAIL(x, i, y) lwip_stats.memp[i].x = y
keir@18114 2056 +#define MEMP_STATS_INC(x, i) STATS_INC(memp[i].x)
keir@18114 2057 +#define MEMP_STATS_DEC(x, i) STATS_DEC(memp[i].x)
keir@18114 2058 +#define MEMP_STATS_INC_USED(x, i) do { ++lwip_stats.memp[i].used; \
keir@18114 2059 + if (lwip_stats.memp[i].max < lwip_stats.memp[i].used) { \
keir@18114 2060 + lwip_stats.memp[i].max = lwip_stats.memp[i].used; \
keir@18114 2061 + } \
keir@18114 2062 + } while(0)
keir@18114 2063 +#define MEMP_STATS_DISPLAY(i) stats_display_memp(&lwip_stats.memp[i], i)
keir@18114 2064 +#else
keir@18114 2065 +#define MEMP_STATS_AVAIL(x, i, y)
keir@18114 2066 +#define MEMP_STATS_INC(x, i)
keir@18114 2067 +#define MEMP_STATS_DEC(x, i)
keir@18114 2068 +#define MEMP_STATS_INC_USED(x, i)
keir@18114 2069 +#define MEMP_STATS_DISPLAY(i)
keir@18114 2070 +#endif
keir@18114 2071 +
keir@18114 2072 +#if SYS_STATS
keir@18114 2073 +#define SYS_STATS_INC(x) STATS_INC(sys.x)
keir@18114 2074 +#define SYS_STATS_DEC(x) STATS_DEC(sys.x)
keir@18114 2075 +#define SYS_STATS_DISPLAY() stats_display_sys(&lwip_stats.sys)
keir@18114 2076 +#else
keir@18114 2077 +#define SYS_STATS_INC(x)
keir@18114 2078 +#define SYS_STATS_DEC(x)
keir@18114 2079 +#define SYS_STATS_DISPLAY()
keir@18114 2080 #endif
keir@18114 2081
keir@18114 2082 /* Display of statistics */
keir@18114 2083 #if LWIP_STATS_DISPLAY
keir@18114 2084 void stats_display(void);
keir@18114 2085 +void stats_display_proto(struct stats_proto *proto, char *name);
keir@18114 2086 +void stats_display_igmp(struct stats_igmp *igmp);
keir@18114 2087 +void stats_display_mem(struct stats_mem *mem, char *name);
keir@18114 2088 +void stats_display_memp(struct stats_mem *mem, int index);
keir@18114 2089 +void stats_display_sys(struct stats_sys *sys);
keir@18114 2090 #else
keir@18114 2091 #define stats_display()
keir@18114 2092 +#define stats_display_proto(proto, name)
keir@18114 2093 +#define stats_display_igmp(igmp)
keir@18114 2094 +#define stats_display_mem(mem, name)
keir@18114 2095 +#define stats_display_memp(mem, index)
keir@18114 2096 +#define stats_display_sys(sys)
keir@18114 2097 #endif /* LWIP_STATS_DISPLAY */
keir@18114 2098
keir@18114 2099 #ifdef __cplusplus
keir@18114 2100 Index: src/include/lwip/tcpip.h
keir@18114 2101 ===================================================================
keir@18114 2102 RCS file: /sources/lwip/lwip/src/include/lwip/tcpip.h,v
keir@18114 2103 retrieving revision 1.24
keir@18114 2104 retrieving revision 1.27
keir@18114 2105 diff -u -p -r1.24 -r1.27
keir@18114 2106 --- src/include/lwip/tcpip.h 12 Jan 2008 11:52:22 -0000 1.24
keir@18114 2107 +++ src/include/lwip/tcpip.h 27 Jun 2008 20:34:55 -0000 1.27
keir@18114 2108 @@ -83,7 +83,11 @@ err_t tcpip_netifapi_lock(struct netifap
keir@18114 2109 #endif /* LWIP_NETIF_API */
keir@18114 2110
keir@18114 2111 err_t tcpip_callback_with_block(void (*f)(void *ctx), void *ctx, u8_t block);
keir@18114 2112 -#define tcpip_callback(f,ctx) tcpip_callback_with_block(f,ctx,1)
keir@18114 2113 +#define tcpip_callback(f, ctx) tcpip_callback_with_block(f, ctx, 1)
keir@18114 2114 +
keir@18114 2115 +/* free pbufs or heap memory from another context without blocking */
keir@18114 2116 +err_t pbuf_free_callback(struct pbuf *p);
keir@18114 2117 +err_t mem_free_callback(void *m);
keir@18114 2118
keir@18114 2119 err_t tcpip_timeout(u32_t msecs, sys_timeout_handler h, void *arg);
keir@18114 2120 #define tcpip_untimeout(h, arg) tcpip_timeout(0xffffffff, h, arg)
keir@18114 2121 Index: src/include/netif/loopif.h
keir@18114 2122 ===================================================================
keir@18114 2123 RCS file: /sources/lwip/lwip/src/include/netif/loopif.h,v
keir@18114 2124 retrieving revision 1.7
keir@18114 2125 retrieving revision 1.9
keir@18114 2126 diff -u -p -r1.7 -r1.9
keir@18114 2127 --- src/include/netif/loopif.h 10 May 2007 10:59:20 -0000 1.7
keir@18114 2128 +++ src/include/netif/loopif.h 17 Jun 2008 20:12:22 -0000 1.9
keir@18114 2129 @@ -32,6 +32,7 @@
keir@18114 2130 #ifndef __NETIF_LOOPIF_H__
keir@18114 2131 #define __NETIF_LOOPIF_H__
keir@18114 2132
keir@18114 2133 +#include "lwip/opt.h"
keir@18114 2134 #include "lwip/netif.h"
keir@18114 2135 #include "lwip/err.h"
keir@18114 2136
keir@18114 2137 @@ -39,9 +40,9 @@
keir@18114 2138 extern "C" {
keir@18114 2139 #endif
keir@18114 2140
keir@18114 2141 -#if !LWIP_LOOPIF_MULTITHREADING
keir@18114 2142 -void loopif_poll(struct netif *netif);
keir@18114 2143 -#endif
keir@18114 2144 +#if !LWIP_NETIF_LOOPBACK_MULTITHREADING
keir@18114 2145 +#define loopif_poll netif_poll
keir@18114 2146 +#endif /* !LWIP_NETIF_LOOPBACK_MULTITHREADING */
keir@18114 2147
keir@18114 2148 err_t loopif_init(struct netif *netif);
keir@18114 2149
keir@18114 2150 Index: src/netif/etharp.c
keir@18114 2151 ===================================================================
keir@18114 2152 RCS file: /sources/lwip/lwip/src/netif/etharp.c,v
keir@18114 2153 retrieving revision 1.145
keir@18114 2154 retrieving revision 1.148
keir@18114 2155 diff -u -p -r1.145 -r1.148
keir@18114 2156 --- src/netif/etharp.c 4 Mar 2008 13:41:24 -0000 1.145
keir@18114 2157 +++ src/netif/etharp.c 19 Jun 2008 16:40:59 -0000 1.148
keir@18114 2158 @@ -353,7 +353,7 @@ find_entry(struct ip_addr *ipaddr, u8_t
keir@18114 2159 * 1) empty entry
keir@18114 2160 * 2) oldest stable entry
keir@18114 2161 * 3) oldest pending entry without queued packets
keir@18114 2162 - * 4) oldest pending entry without queued packets
keir@18114 2163 + * 4) oldest pending entry with queued packets
keir@18114 2164 *
keir@18114 2165 * { ETHARP_TRY_HARD is set at this point }
keir@18114 2166 */
keir@18114 2167 @@ -1130,7 +1130,14 @@ ethernet_input(struct pbuf *p, struct ne
keir@18114 2168
keir@18114 2169 /* points to packet payload, which starts with an Ethernet header */
keir@18114 2170 ethhdr = p->payload;
keir@18114 2171 -
keir@18114 2172 + LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE,
keir@18114 2173 + ("ethernet_input: dest:%02x:%02x:%02x:%02x:%02x:%02x, src:%02x:%02x:%02x:%02x:%02x:%02x, type:%2hx\n",
keir@18114 2174 + (unsigned)ethhdr->dest.addr[0], (unsigned)ethhdr->dest.addr[1], (unsigned)ethhdr->dest.addr[2],
keir@18114 2175 + (unsigned)ethhdr->dest.addr[3], (unsigned)ethhdr->dest.addr[4], (unsigned)ethhdr->dest.addr[5],
keir@18114 2176 + (unsigned)ethhdr->src.addr[0], (unsigned)ethhdr->src.addr[1], (unsigned)ethhdr->src.addr[2],
keir@18114 2177 + (unsigned)ethhdr->src.addr[3], (unsigned)ethhdr->src.addr[4], (unsigned)ethhdr->src.addr[5],
keir@18114 2178 + (unsigned)htons(ethhdr->type)));
keir@18114 2179 +
keir@18114 2180 switch (htons(ethhdr->type)) {
keir@18114 2181 /* IP packet? */
keir@18114 2182 case ETHTYPE_IP:
keir@18114 2183 @@ -1165,6 +1172,8 @@ ethernet_input(struct pbuf *p, struct ne
keir@18114 2184 #endif /* PPPOE_SUPPORT */
keir@18114 2185
keir@18114 2186 default:
keir@18114 2187 + ETHARP_STATS_INC(etharp.proterr);
keir@18114 2188 + ETHARP_STATS_INC(etharp.drop);
keir@18114 2189 pbuf_free(p);
keir@18114 2190 p = NULL;
keir@18114 2191 break;
keir@18114 2192 Index: src/netif/loopif.c
keir@18114 2193 ===================================================================
keir@18114 2194 RCS file: /sources/lwip/lwip/src/netif/loopif.c,v
keir@18114 2195 retrieving revision 1.26
keir@18114 2196 retrieving revision 1.27
keir@18114 2197 diff -u -p -r1.26 -r1.27
keir@18114 2198 --- src/netif/loopif.c 31 Aug 2007 10:14:09 -0000 1.26
keir@18114 2199 +++ src/netif/loopif.c 12 Jun 2008 20:10:10 -0000 1.27
keir@18114 2200 @@ -40,149 +40,8 @@
keir@18114 2201 #if LWIP_HAVE_LOOPIF
keir@18114 2202
keir@18114 2203 #include "netif/loopif.h"
keir@18114 2204 -#include "lwip/pbuf.h"
keir@18114 2205 #include "lwip/snmp.h"
keir@18114 2206
keir@18114 2207 -#include <string.h>
keir@18114 2208 -
keir@18114 2209 -#if !LWIP_LOOPIF_MULTITHREADING
keir@18114 2210 -
keir@18114 2211 -#include "lwip/sys.h"
keir@18114 2212 -#include "lwip/mem.h"
keir@18114 2213 -
keir@18114 2214 -/* helper struct for the linked list of pbufs */
keir@18114 2215 -struct loopif_private {
keir@18114 2216 - struct pbuf *first;
keir@18114 2217 - struct pbuf *last;
keir@18114 2218 -};
keir@18114 2219 -
keir@18114 2220 -/**
keir@18114 2221 - * Call loopif_poll() in the main loop of your application. This is to prevent
keir@18114 2222 - * reentering non-reentrant functions like tcp_input(). Packets passed to
keir@18114 2223 - * loopif_output() are put on a list that is passed to netif->input() by
keir@18114 2224 - * loopif_poll().
keir@18114 2225 - *
keir@18114 2226 - * @param netif the lwip network interface structure for this loopif
keir@18114 2227 - */
keir@18114 2228 -void
keir@18114 2229 -loopif_poll(struct netif *netif)
keir@18114 2230 -{
keir@18114 2231 - SYS_ARCH_DECL_PROTECT(lev);
keir@18114 2232 - struct pbuf *in, *in_end;
keir@18114 2233 - struct loopif_private *priv = (struct loopif_private*)netif->state;
keir@18114 2234 -
keir@18114 2235 - LWIP_ERROR("priv != NULL", (priv != NULL), return;);
keir@18114 2236 -
keir@18114 2237 - do {
keir@18114 2238 - /* Get a packet from the list. With SYS_LIGHTWEIGHT_PROT=1, this is protected */
keir@18114 2239 - SYS_ARCH_PROTECT(lev);
keir@18114 2240 - in = priv->first;
keir@18114 2241 - if(in) {
keir@18114 2242 - in_end = in;
keir@18114 2243 - while(in_end->len != in_end->tot_len) {
keir@18114 2244 - LWIP_ASSERT("bogus pbuf: len != tot_len but next == NULL!", in_end->next != NULL);
keir@18114 2245 - in_end = in_end->next;
keir@18114 2246 - }
keir@18114 2247 - /* 'in_end' now points to the last pbuf from 'in' */
keir@18114 2248 - if(in_end == priv->last) {
keir@18114 2249 - /* this was the last pbuf in the list */
keir@18114 2250 - priv->first = priv->last = NULL;
keir@18114 2251 - } else {
keir@18114 2252 - /* pop the pbuf off the list */
keir@18114 2253 - priv->first = in_end->next;
keir@18114 2254 - LWIP_ASSERT("should not be null since first != last!", priv->first != NULL);
keir@18114 2255 - }
keir@18114 2256 - }
keir@18114 2257 - SYS_ARCH_UNPROTECT(lev);
keir@18114 2258 -
keir@18114 2259 - if(in != NULL) {
keir@18114 2260 - if(in_end->next != NULL) {
keir@18114 2261 - /* De-queue the pbuf from its successors on the 'priv' list. */
keir@18114 2262 - in_end->next = NULL;
keir@18114 2263 - }
keir@18114 2264 - if(netif->input(in, netif) != ERR_OK) {
keir@18114 2265 - pbuf_free(in);
keir@18114 2266 - }
keir@18114 2267 - /* Don't reference the packet any more! */
keir@18114 2268 - in = NULL;
keir@18114 2269 - in_end = NULL;
keir@18114 2270 - }
keir@18114 2271 - /* go on while there is a packet on the list */
keir@18114 2272 - } while(priv->first != NULL);
keir@18114 2273 -}
keir@18114 2274 -#endif /* LWIP_LOOPIF_MULTITHREADING */
keir@18114 2275 -
keir@18114 2276 -/**
keir@18114 2277 - * Send an IP packet over the loopback interface.
keir@18114 2278 - * The pbuf is simply copied and handed back to netif->input.
keir@18114 2279 - * In multithreaded mode, this is done directly since netif->input must put
keir@18114 2280 - * the packet on a queue.
keir@18114 2281 - * In callback mode, the packet is put on an internal queue and is fed to
keir@18114 2282 - * netif->input by loopif_poll().
keir@18114 2283 - *
keir@18114 2284 - * @param netif the lwip network interface structure for this loopif
keir@18114 2285 - * @param p the (IP) packet to 'send'
keir@18114 2286 - * @param ipaddr the ip address to send the packet to (not used for loopif)
keir@18114 2287 - * @return ERR_OK if the packet has been sent
keir@18114 2288 - * ERR_MEM if the pbuf used to copy the packet couldn't be allocated
keir@18114 2289 - */
keir@18114 2290 -static err_t
keir@18114 2291 -loopif_output(struct netif *netif, struct pbuf *p,
keir@18114 2292 - struct ip_addr *ipaddr)
keir@18114 2293 -{
keir@18114 2294 -#if !LWIP_LOOPIF_MULTITHREADING
keir@18114 2295 - SYS_ARCH_DECL_PROTECT(lev);
keir@18114 2296 - struct loopif_private *priv;
keir@18114 2297 - struct pbuf *last;
keir@18114 2298 -#endif /* LWIP_LOOPIF_MULTITHREADING */
keir@18114 2299 - struct pbuf *r;
keir@18114 2300 - err_t err;
keir@18114 2301 -
keir@18114 2302 - LWIP_UNUSED_ARG(ipaddr);
keir@18114 2303 -
keir@18114 2304 - /* Allocate a new pbuf */
keir@18114 2305 - r = pbuf_alloc(PBUF_RAW, p->tot_len, PBUF_RAM);
keir@18114 2306 - if (r == NULL) {
keir@18114 2307 - return ERR_MEM;
keir@18114 2308 - }
keir@18114 2309 -
keir@18114 2310 - /* Copy the whole pbuf queue p into the single pbuf r */
keir@18114 2311 - if ((err = pbuf_copy(r, p)) != ERR_OK) {
keir@18114 2312 - pbuf_free(r);
keir@18114 2313 - r = NULL;
keir@18114 2314 - return err;
keir@18114 2315 - }
keir@18114 2316 -
keir@18114 2317 -#if LWIP_LOOPIF_MULTITHREADING
keir@18114 2318 - /* Multithreading environment, netif->input() is supposed to put the packet
keir@18114 2319 - into a mailbox, so we can safely call it here without risking to re-enter
keir@18114 2320 - functions that are not reentrant (TCP!!!) */
keir@18114 2321 - if(netif->input(r, netif) != ERR_OK) {
keir@18114 2322 - pbuf_free(r);
keir@18114 2323 - r = NULL;
keir@18114 2324 - }
keir@18114 2325 -#else /* LWIP_LOOPIF_MULTITHREADING */
keir@18114 2326 - /* Raw API without threads: put the packet on a linked list which gets emptied
keir@18114 2327 - through calling loopif_poll(). */
keir@18114 2328 - priv = (struct loopif_private*)netif->state;
keir@18114 2329 -
keir@18114 2330 - /* let last point to the last pbuf in chain r */
keir@18114 2331 - for (last = r; last->next != NULL; last = last->next);
keir@18114 2332 - SYS_ARCH_PROTECT(lev);
keir@18114 2333 - if(priv->first != NULL) {
keir@18114 2334 - LWIP_ASSERT("if first != NULL, last must also be != NULL", priv->last != NULL);
keir@18114 2335 - priv->last->next = r;
keir@18114 2336 - priv->last = last;
keir@18114 2337 - } else {
keir@18114 2338 - priv->first = r;
keir@18114 2339 - priv->last = last;
keir@18114 2340 - }
keir@18114 2341 - SYS_ARCH_UNPROTECT(lev);
keir@18114 2342 -#endif /* LWIP_LOOPIF_MULTITHREADING */
keir@18114 2343 -
keir@18114 2344 - return ERR_OK;
keir@18114 2345 -}
keir@18114 2346 -
keir@18114 2347 /**
keir@18114 2348 * Initialize a lwip network interface structure for a loopback interface
keir@18114 2349 *
keir@18114 2350 @@ -193,16 +52,6 @@ loopif_output(struct netif *netif, struc
keir@18114 2351 err_t
keir@18114 2352 loopif_init(struct netif *netif)
keir@18114 2353 {
keir@18114 2354 -#if !LWIP_LOOPIF_MULTITHREADING
keir@18114 2355 - struct loopif_private *priv;
keir@18114 2356 -
keir@18114 2357 - priv = (struct loopif_private*)mem_malloc(sizeof(struct loopif_private));
keir@18114 2358 - if(priv == NULL)
keir@18114 2359 - return ERR_MEM;
keir@18114 2360 - priv->first = priv->last = NULL;
keir@18114 2361 - netif->state = priv;
keir@18114 2362 -#endif /* LWIP_LOOPIF_MULTITHREADING */
keir@18114 2363 -
keir@18114 2364 /* initialize the snmp variables and counters inside the struct netif
keir@18114 2365 * ifSpeed: no assumption can be made!
keir@18114 2366 */
keir@18114 2367 @@ -210,7 +59,7 @@ loopif_init(struct netif *netif)
keir@18114 2368
keir@18114 2369 netif->name[0] = 'l';
keir@18114 2370 netif->name[1] = 'o';
keir@18114 2371 - netif->output = loopif_output;
keir@18114 2372 + netif->output = netif_loop_output;
keir@18114 2373 return ERR_OK;
keir@18114 2374 }
keir@18114 2375
keir@18114 2376 Index: src/netif/slipif.c
keir@18114 2377 ===================================================================
keir@18114 2378 RCS file: /sources/lwip/lwip/src/netif/slipif.c,v
keir@18114 2379 retrieving revision 1.29
keir@18114 2380 retrieving revision 1.30
keir@18114 2381 diff -u -p -r1.29 -r1.30
keir@18114 2382 --- src/netif/slipif.c 30 Nov 2007 17:22:21 -0000 1.29
keir@18114 2383 +++ src/netif/slipif.c 17 Jun 2008 20:14:05 -0000 1.30
keir@18114 2384 @@ -44,6 +44,9 @@
keir@18114 2385
keir@18114 2386 #include "netif/slipif.h"
keir@18114 2387 #include "lwip/opt.h"
keir@18114 2388 +
keir@18114 2389 +#if LWIP_HAVE_SLIPIF
keir@18114 2390 +
keir@18114 2391 #include "lwip/def.h"
keir@18114 2392 #include "lwip/pbuf.h"
keir@18114 2393 #include "lwip/sys.h"
keir@18114 2394 @@ -273,3 +276,4 @@ slipif_init(struct netif *netif)
keir@18114 2395 sys_thread_new(SLIPIF_THREAD_NAME, slipif_loop, netif, SLIPIF_THREAD_STACKSIZE, SLIPIF_THREAD_PRIO);
keir@18114 2396 return ERR_OK;
keir@18114 2397 }
keir@18114 2398 +#endif /* LWIP_HAVE_SLIPIF */