diff options
| author | bernard.xiong <[email protected]> | 2009-09-06 11:04:38 +0000 |
|---|---|---|
| committer | bernard.xiong <[email protected]> | 2009-09-06 11:04:38 +0000 |
| commit | b9290bcef45a9ebc088e1f20596b7e02c7ca47f6 (patch) | |
| tree | d3545a00a8b25782bf32c52f491df1188abdcfee /net/lwip/src/include | |
| parent | 1ae9da2752f5ae98d029dce078c49f2a5364019c (diff) | |
update lwip to 1.3.1
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@37 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'net/lwip/src/include')
32 files changed, 680 insertions, 227 deletions
diff --git a/net/lwip/src/include/ipv4/lwip/icmp.h b/net/lwip/src/include/ipv4/lwip/icmp.h index 59a31f9c66..ff838f43a1 100644 --- a/net/lwip/src/include/ipv4/lwip/icmp.h +++ b/net/lwip/src/include/ipv4/lwip/icmp.h @@ -78,39 +78,30 @@ void icmp_time_exceeded(struct pbuf *p, enum icmp_te_type t); #ifdef PACK_STRUCT_USE_INCLUDES # include "arch/bpstruct.h" #endif +/** This is the standard ICMP header only that the u32_t data + * is splitted to two u16_t like ICMP echo needs it. + * This header is also used for other ICMP types that do not + * use the data part. + */ PACK_STRUCT_BEGIN struct icmp_echo_hdr { - PACK_STRUCT_FIELD(u16_t _type_code); + PACK_STRUCT_FIELD(u8_t type); + PACK_STRUCT_FIELD(u8_t code); PACK_STRUCT_FIELD(u16_t chksum); PACK_STRUCT_FIELD(u16_t id); PACK_STRUCT_FIELD(u16_t seqno); } PACK_STRUCT_STRUCT; PACK_STRUCT_END - -PACK_STRUCT_BEGIN -struct icmp_dur_hdr { - PACK_STRUCT_FIELD(u16_t _type_code); - PACK_STRUCT_FIELD(u16_t chksum); - PACK_STRUCT_FIELD(u32_t unused); -} PACK_STRUCT_STRUCT; -PACK_STRUCT_END - -PACK_STRUCT_BEGIN -struct icmp_te_hdr { - PACK_STRUCT_FIELD(u16_t _type_code); - PACK_STRUCT_FIELD(u16_t chksum); - PACK_STRUCT_FIELD(u32_t unused); -} PACK_STRUCT_STRUCT; -PACK_STRUCT_END #ifdef PACK_STRUCT_USE_INCLUDES # include "arch/epstruct.h" #endif -#define ICMPH_TYPE(hdr) (ntohs((hdr)->_type_code) >> 8) -#define ICMPH_CODE(hdr) (ntohs((hdr)->_type_code) & 0xff) +#define ICMPH_TYPE(hdr) ((hdr)->type) +#define ICMPH_CODE(hdr) ((hdr)->code) -#define ICMPH_TYPE_SET(hdr, type) ((hdr)->_type_code = htons(ICMPH_CODE(hdr) | ((type) << 8))) -#define ICMPH_CODE_SET(hdr, code) ((hdr)->_type_code = htons((code) | (ICMPH_TYPE(hdr) << 8))) +/** Combines type and code to an u16_t */ +#define ICMPH_TYPE_SET(hdr, t) ((hdr)->type = (t)) +#define ICMPH_CODE_SET(hdr, c) ((hdr)->code = (c)) #ifdef __cplusplus } diff --git a/net/lwip/src/include/ipv4/lwip/inet.h b/net/lwip/src/include/ipv4/lwip/inet.h index 1ffcf7070a..6f30d0d12a 100644 --- a/net/lwip/src/include/ipv4/lwip/inet.h +++ b/net/lwip/src/include/ipv4/lwip/inet.h @@ -34,12 +34,20 @@ #include "lwip/opt.h" -#include "lwip/ip_addr.h" - #ifdef __cplusplus extern "C" { #endif +/* For compatibility with BSD code */ +struct in_addr { + u32_t s_addr; +}; + +#define INADDR_NONE ((u32_t)0xffffffffUL) /* 255.255.255.255 */ +#define INADDR_LOOPBACK ((u32_t)0x7f000001UL) /* 127.0.0.1 */ +#define INADDR_ANY ((u32_t)0x00000000UL) /* 0.0.0.0 */ +#define INADDR_BROADCAST ((u32_t)0xffffffffUL) /* 255.255.255.255 */ + u32_t inet_addr(const char *cp); int inet_aton(const char *cp, struct in_addr *addr); char *inet_ntoa(struct in_addr addr); /* returns ptr to static buffer; not reentrant! */ diff --git a/net/lwip/src/include/ipv4/lwip/inet_chksum.h b/net/lwip/src/include/ipv4/lwip/inet_chksum.h index d7c7492690..5cae59cbd4 100644 --- a/net/lwip/src/include/ipv4/lwip/inet_chksum.h +++ b/net/lwip/src/include/ipv4/lwip/inet_chksum.h @@ -46,9 +46,11 @@ u16_t inet_chksum_pbuf(struct pbuf *p); u16_t inet_chksum_pseudo(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, u8_t proto, u16_t proto_len); +#if LWIP_UDPLITE u16_t inet_chksum_pseudo_partial(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, u8_t proto, u16_t proto_len, u16_t chksum_len); +#endif #ifdef __cplusplus } diff --git a/net/lwip/src/include/ipv4/lwip/ip.h b/net/lwip/src/include/ipv4/lwip/ip.h index 3b760f0066..14eba3ca53 100644 --- a/net/lwip/src/include/ipv4/lwip/ip.h +++ b/net/lwip/src/include/ipv4/lwip/ip.h @@ -38,19 +38,14 @@ #include "lwip/pbuf.h" #include "lwip/ip_addr.h" #include "lwip/err.h" +#include "lwip/netif.h" #ifdef __cplusplus extern "C" { #endif -#define ip_init() /* Compatibility define, not init needed. */ -struct netif *ip_route(struct ip_addr *dest); -err_t ip_input(struct pbuf *p, struct netif *inp); -err_t ip_output(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, - u8_t ttl, u8_t tos, u8_t proto); -err_t ip_output_if(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, - u8_t ttl, u8_t tos, u8_t proto, - struct netif *netif); +/** Currently, the function ip_output_if_opt() is only used with IGMP */ +#define IP_OPTIONS_SEND LWIP_IGMP #define IP_HLEN 20 @@ -103,7 +98,7 @@ struct ip_pcb { #define SOF_REUSEADDR (u16_t)0x0004U /* allow local address reuse */ #define SOF_KEEPALIVE (u16_t)0x0008U /* keep connections alive */ #define SOF_DONTROUTE (u16_t)0x0010U /* just use interface addresses */ -#define SOF_BROADCAST (u16_t)0x0020U /* permit sending of broadcast msgs */ +#define SOF_BROADCAST (u16_t)0x0020U /* permit to send and to receive broadcast messages (see IP_SOF_BROADCAST option) */ #define SOF_USELOOPBACK (u16_t)0x0040U /* bypass hardware when possible */ #define SOF_LINGER (u16_t)0x0080U /* linger on close if data present */ #define SOF_OOBINLINE (u16_t)0x0100U /* leave received OOB data in line */ @@ -158,6 +153,25 @@ PACK_STRUCT_END #define IPH_PROTO_SET(hdr, proto) (hdr)->_ttl_proto = (htons((proto) | (IPH_TTL(hdr) << 8))) #define IPH_CHKSUM_SET(hdr, chksum) (hdr)->_chksum = (chksum) +#define ip_init() /* Compatibility define, not init needed. */ +struct netif *ip_route(struct ip_addr *dest); +err_t ip_input(struct pbuf *p, struct netif *inp); +err_t ip_output(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, + u8_t ttl, u8_t tos, u8_t proto); +err_t ip_output_if(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, + u8_t ttl, u8_t tos, u8_t proto, + struct netif *netif); +#if LWIP_NETIF_HWADDRHINT +err_t ip_output_hinted(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, + u8_t ttl, u8_t tos, u8_t proto, u8_t *addr_hint); +#endif /* LWIP_NETIF_HWADDRHINT */ +#if IP_OPTIONS_SEND +err_t ip_output_if_opt(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, + u8_t ttl, u8_t tos, u8_t proto, struct netif *netif, void *ip_options, + u16_t optlen); +#endif /* IP_OPTIONS_SEND */ +struct netif *ip_current_netif(void); +const struct ip_hdr *ip_current_header(void); #if IP_DEBUG void ip_debug_print(struct pbuf *p); #else diff --git a/net/lwip/src/include/ipv4/lwip/ip_addr.h b/net/lwip/src/include/ipv4/lwip/ip_addr.h index 7f24336382..f2e4c22338 100644 --- a/net/lwip/src/include/ipv4/lwip/ip_addr.h +++ b/net/lwip/src/include/ipv4/lwip/ip_addr.h @@ -34,6 +34,8 @@ #include "lwip/opt.h" +#include "lwip/inet.h" + #ifdef __cplusplus extern "C" { #endif @@ -66,11 +68,6 @@ PACK_STRUCT_END # include "arch/epstruct.h" #endif -/* For compatibility with BSD code */ -struct in_addr { - u32_t s_addr; -}; - struct netif; extern const struct ip_addr ip_addr_any; @@ -82,9 +79,6 @@ extern const struct ip_addr ip_addr_broadcast; #define IP_ADDR_ANY ((struct ip_addr *)&ip_addr_any) #define IP_ADDR_BROADCAST ((struct ip_addr *)&ip_addr_broadcast) -#define INADDR_NONE ((u32_t)0xffffffffUL) /* 255.255.255.255 */ -#define INADDR_LOOPBACK ((u32_t)0x7f000001UL) /* 127.0.0.1 */ - /* Definitions of the bits in an Internet address integer. On subnets, host and network parts are found according to @@ -150,11 +144,15 @@ u8_t ip_addr_isbroadcast(struct ip_addr *, struct netif *); #define ip_addr_islinklocal(addr1) (((addr1)->addr & ntohl(0xffff0000UL)) == ntohl(0xa9fe0000UL)) #define ip_addr_debug_print(debug, ipaddr) \ - LWIP_DEBUGF(debug, ("%"U16_F".%"U16_F".%"U16_F".%"U16_F, \ - ipaddr ? (u16_t)(ntohl((ipaddr)->addr) >> 24) & 0xff : 0, \ - ipaddr ? (u16_t)(ntohl((ipaddr)->addr) >> 16) & 0xff : 0, \ - ipaddr ? (u16_t)(ntohl((ipaddr)->addr) >> 8) & 0xff : 0, \ - ipaddr ? (u16_t)ntohl((ipaddr)->addr) & 0xff : 0)) + LWIP_DEBUGF(debug, ("%"U16_F".%"U16_F".%"U16_F".%"U16_F, \ + ipaddr != NULL ? \ + (u16_t)(ntohl((ipaddr)->addr) >> 24) & 0xff : 0, \ + ipaddr != NULL ? \ + (u16_t)(ntohl((ipaddr)->addr) >> 16) & 0xff : 0, \ + ipaddr != NULL ? \ + (u16_t)(ntohl((ipaddr)->addr) >> 8) & 0xff : 0, \ + ipaddr != NULL ? \ + (u16_t)ntohl((ipaddr)->addr) & 0xff : 0)) /* These are cast to u16_t, with the intent that they are often arguments * to printf using the U16_F format from cc.h. */ diff --git a/net/lwip/src/include/ipv6/lwip/ip.h b/net/lwip/src/include/ipv6/lwip/ip.h index f6e59cc64a..a01cfc65b3 100644 --- a/net/lwip/src/include/ipv6/lwip/ip.h +++ b/net/lwip/src/include/ipv6/lwip/ip.h @@ -114,6 +114,9 @@ err_t ip_output_if(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, u8_t ttl, u8_t proto, struct netif *netif); +#define ip_current_netif() NULL +#define ip_current_header() NULL + #if IP_DEBUG void ip_debug_print(struct pbuf *p); #endif /* IP_DEBUG */ diff --git a/net/lwip/src/include/lwip/api.h b/net/lwip/src/include/lwip/api.h index 31d767f218..f6b1f74343 100644 --- a/net/lwip/src/include/lwip/api.h +++ b/net/lwip/src/include/lwip/api.h @@ -36,6 +36,8 @@ #if LWIP_NETCONN /* don't build if not configured for use in lwipopts.h */ +#include <stddef.h> /* for size_t */ + #include "lwip/netbuf.h" #include "lwip/sys.h" #include "lwip/ip_addr.h" @@ -137,19 +139,21 @@ struct netconn { /** maximum amount of bytes queued in recvmbox */ int recv_bufsize; #endif /* LWIP_SO_RCVBUF */ - u16_t recv_avail; + s16_t recv_avail; +#if LWIP_TCP /** TCP: when data passed to netconn_write doesn't fit into the send buffer, this temporarily stores the message. */ struct api_msg_msg *write_msg; /** TCP: when data passed to netconn_write doesn't fit into the send buffer, this temporarily stores how much is already sent. */ - int write_offset; + size_t write_offset; #if LWIP_TCPIP_CORE_LOCKING /** TCP: when data passed to netconn_write doesn't fit into the send buffer, this temporarily stores whether to wake up the original application task if data couldn't be sent in the first try. */ u8_t write_delayed; #endif /* LWIP_TCPIP_CORE_LOCKING */ +#endif /* LWIP_TCP */ /** A callback function that is informed about events for this netconn */ netconn_callback callback; }; @@ -166,7 +170,8 @@ struct netconn *netconn_new_with_proto_and_callback(enum netconn_type t, u8_t proto, netconn_callback callback); err_t netconn_delete (struct netconn *conn); -enum netconn_type netconn_type (struct netconn *conn); +/** Get the type of a netconn (as enum netconn_type). */ +#define netconn_type(conn) (conn->type) err_t netconn_getaddr (struct netconn *conn, struct ip_addr *addr, @@ -191,7 +196,7 @@ err_t netconn_sendto (struct netconn *conn, err_t netconn_send (struct netconn *conn, struct netbuf *buf); err_t netconn_write (struct netconn *conn, - const void *dataptr, int size, + const void *dataptr, size_t size, u8_t apiflags); err_t netconn_close (struct netconn *conn); diff --git a/net/lwip/src/include/lwip/api_msg.h b/net/lwip/src/include/lwip/api_msg.h index 4c9b48ef59..4272d77ccb 100644 --- a/net/lwip/src/include/lwip/api_msg.h +++ b/net/lwip/src/include/lwip/api_msg.h @@ -36,6 +36,8 @@ #if LWIP_NETCONN /* don't build if not configured for use in lwipopts.h */ +#include <stddef.h> /* for size_t */ + #include "lwip/ip_addr.h" #include "lwip/err.h" #include "lwip/sys.h" @@ -78,7 +80,7 @@ struct api_msg_msg { /** used for do_write */ struct { const void *dataptr; - int len; + size_t len; u8_t apiflags; } w; /** used ofr do_recv */ diff --git a/net/lwip/src/include/lwip/arch.h b/net/lwip/src/include/lwip/arch.h index 32018e47cd..3a5a0e4f20 100644 --- a/net/lwip/src/include/lwip/arch.h +++ b/net/lwip/src/include/lwip/arch.h @@ -42,6 +42,11 @@ #include "arch/cc.h" +/** Temporary: define format string for size_t if not defined in cc.h */ +#ifndef SZT_F +#define SZT_F U32_F +#endif /* SZT_F */ + #ifdef __cplusplus extern "C" { #endif @@ -194,13 +199,7 @@ extern "C" { #define ENOMEDIUM 123 /* No medium found */ #define EMEDIUMTYPE 124 /* Wrong medium type */ -#ifndef errno -extern int errno; -#endif - -#endif /* LWIP_PROVIDE_ERRNO */ -/*[email protected], Newlib does not provide following errno*/ #define ENSROK 0 /* DNS server returned answer with no data */ #define ENSRNODATA 160 /* DNS server returned answer with no data */ #define ENSRFORMERR 161 /* DNS server claims query was misformatted */ @@ -221,6 +220,12 @@ extern int errno; #define ENSRQUERYDOMAINTOOLONG 176 /* Domain name is too long */ #define ENSRCNAMELOOP 177 /* Domain name is too long */ +#ifndef errno +extern int errno; +#endif + +#endif /* LWIP_PROVIDE_ERRNO */ + #ifdef __cplusplus } #endif diff --git a/net/lwip/src/include/lwip/debug.h b/net/lwip/src/include/lwip/debug.h index 8070027d19..d5c4e47473 100644 --- a/net/lwip/src/include/lwip/debug.h +++ b/net/lwip/src/include/lwip/debug.h @@ -61,26 +61,28 @@ #define LWIP_DBG_HALT 0x08U #ifndef LWIP_NOASSERT -#define LWIP_ASSERT(x,y) do { if(!(y)) LWIP_PLATFORM_ASSERT(x); } while(0) +#define LWIP_ASSERT(message, assertion) do { if(!(assertion)) \ + LWIP_PLATFORM_ASSERT(message); } while(0) #else /* LWIP_NOASSERT */ -#define LWIP_ASSERT(x,y) +#define LWIP_ASSERT(message, assertion) #endif /* LWIP_NOASSERT */ -/** print "m" message only if "e" is true, and execute "h" expression */ +/** if "expression" isn't true, then print "message" and execute "handler" expression */ #ifndef LWIP_ERROR -#define LWIP_ERROR(m,e,h) do { if (!(e)) { LWIP_PLATFORM_ASSERT(m); h;}} while(0) +#define LWIP_ERROR(message, expression, handler) do { if (!(expression)) { \ + LWIP_PLATFORM_ASSERT(message); handler;}} while(0) #endif /* LWIP_ERROR */ #ifdef LWIP_DEBUG /** print debug message only if debug message type is enabled... * AND is of correct type AND is at least LWIP_DBG_LEVEL */ -#define LWIP_DEBUGF(debug,x) do { \ +#define LWIP_DEBUGF(debug, message) do { \ if ( \ ((debug) & LWIP_DBG_ON) && \ ((debug) & LWIP_DBG_TYPES_ON) && \ ((s16_t)((debug) & LWIP_DBG_MASK_LEVEL) >= LWIP_DBG_MIN_LEVEL)) { \ - LWIP_PLATFORM_DIAG(x); \ + LWIP_PLATFORM_DIAG(message); \ if ((debug) & LWIP_DBG_HALT) { \ while(1); \ } \ @@ -88,7 +90,7 @@ } while(0) #else /* LWIP_DEBUG */ -#define LWIP_DEBUGF(debug,x) +#define LWIP_DEBUGF(debug, message) #endif /* LWIP_DEBUG */ #endif /* __LWIP_DEBUG_H__ */ diff --git a/net/lwip/src/include/lwip/dhcp.h b/net/lwip/src/include/lwip/dhcp.h index 400f81fdf0..825dba6ecb 100644 --- a/net/lwip/src/include/lwip/dhcp.h +++ b/net/lwip/src/include/lwip/dhcp.h @@ -18,7 +18,7 @@ extern "C" { /** period (in seconds) of the application calling dhcp_coarse_tmr() */ #define DHCP_COARSE_TIMER_SECS 60 /** period (in milliseconds) of the application calling dhcp_coarse_tmr() */ -#define DHCP_COARSE_TIMER_MSECS (DHCP_COARSE_TIMER_SECS*1000) +#define DHCP_COARSE_TIMER_MSECS (DHCP_COARSE_TIMER_SECS * 1000UL) /** period (in milliseconds) of the application calling dhcp_fine_tmr() */ #define DHCP_FINE_TIMER_MSECS 500 diff --git a/net/lwip/src/include/lwip/dns.h b/net/lwip/src/include/lwip/dns.h index 6196742928..e5f4b7a3d6 100644 --- a/net/lwip/src/include/lwip/dns.h +++ b/net/lwip/src/include/lwip/dns.h @@ -87,6 +87,11 @@ struct ip_addr dns_getserver(u8_t numdns); err_t dns_gethostbyname(const char *hostname, struct ip_addr *addr, dns_found_callback found, void *callback_arg); +#if DNS_LOCAL_HOSTLIST && DNS_LOCAL_HOSTLIST_IS_DYNAMIC +int dns_local_removehost(const char *hostname, const struct ip_addr *addr); +err_t dns_local_addhost(const char *hostname, const struct ip_addr *addr); +#endif /* DNS_LOCAL_HOSTLIST && DNS_LOCAL_HOSTLIST_IS_DYNAMIC */ + #endif /* LWIP_DNS */ #endif /* __LWIP_DNS_H__ */ diff --git a/net/lwip/src/include/lwip/err.h b/net/lwip/src/include/lwip/err.h index e506323526..696764454f 100644 --- a/net/lwip/src/include/lwip/err.h +++ b/net/lwip/src/include/lwip/err.h @@ -33,37 +33,43 @@ #define __LWIP_ERR_H__ #include "lwip/opt.h" +#include "lwip/arch.h" #ifdef __cplusplus extern "C" { #endif -typedef s8_t err_t; +/** Define LWIP_ERR_T in cc.h if you want to use + * a different type for your platform (must be signed). */ +#ifdef LWIP_ERR_T +typedef LWIP_ERR_T err_t; +#else /* LWIP_ERR_T */ + typedef s8_t err_t; +#endif /* LWIP_ERR_T*/ /* Definitions for error constants. */ #define ERR_OK 0 /* No error, everything OK. */ #define ERR_MEM -1 /* Out of memory error. */ #define ERR_BUF -2 /* Buffer error. */ -#define ERR_RTE -3 /* Routing problem. */ +#define ERR_TIMEOUT -3 /* Timeout. */ +#define ERR_RTE -4 /* Routing problem. */ #define ERR_IS_FATAL(e) ((e) < ERR_RTE) -#define ERR_ABRT -4 /* Connection aborted. */ -#define ERR_RST -5 /* Connection reset. */ -#define ERR_CLSD -6 /* Connection closed. */ -#define ERR_CONN -7 /* Not connected. */ +#define ERR_ABRT -5 /* Connection aborted. */ +#define ERR_RST -6 /* Connection reset. */ +#define ERR_CLSD -7 /* Connection closed. */ +#define ERR_CONN -8 /* Not connected. */ -#define ERR_VAL -8 /* Illegal value. */ +#define ERR_VAL -9 /* Illegal value. */ -#define ERR_ARG -9 /* Illegal argument. */ +#define ERR_ARG -10 /* Illegal argument. */ -#define ERR_USE -10 /* Address in use. */ +#define ERR_USE -11 /* Address in use. */ -#define ERR_IF -11 /* Low-level netif error */ -#define ERR_ISCONN -12 /* Already connected. */ - -#define ERR_TIMEOUT -13 /* Timeout. */ +#define ERR_IF -12 /* Low-level netif error */ +#define ERR_ISCONN -13 /* Already connected. */ #define ERR_INPROGRESS -14 /* Operation in progress */ diff --git a/net/lwip/src/include/lwip/init.h b/net/lwip/src/include/lwip/init.h index c0869cfd88..a4dc0577f4 100644 --- a/net/lwip/src/include/lwip/init.h +++ b/net/lwip/src/include/lwip/init.h @@ -38,6 +38,30 @@ extern "C" { #endif +/** X.x.x: Major version of the stack */ +#define LWIP_VERSION_MAJOR 1U +/** x.X.x: Minor version of the stack */ +#define LWIP_VERSION_MINOR 3U +/** x.x.X: Revision of the stack */ +#define LWIP_VERSION_REVISION 1U +/** For release candidates, this is set to 1..254 + * For official releases, this is set to 255 (LWIP_RC_RELEASE) + * For development versions (CVS), this is set to 0 (LWIP_RC_DEVELOPMENT) */ +#define LWIP_VERSION_RC 255U + +/** LWIP_VERSION_RC is set to LWIP_RC_RELEASE for official releases */ +#define LWIP_RC_RELEASE 255U +/** LWIP_VERSION_RC is set to LWIP_RC_DEVELOPMENT for CVS versions */ +#define LWIP_RC_DEVELOPMENT 0U + +#define LWIP_VERSION_IS_RELEASE (LWIP_VERSION_RC == LWIP_RC_RELEASE) +#define LWIP_VERSION_IS_DEVELOPMENT (LWIP_VERSION_RC == LWIP_RC_DEVELOPMENT) +#define LWIP_VERSION_IS_RC ((LWIP_VERSION_RC != LWIP_RC_RELEASE) && (LWIP_VERSION_RC != LWIP_RC_DEVELOPMENT)) + +/** Provides the version of the stack */ +#define LWIP_VERSION (LWIP_VERSION_MAJOR << 24 | LWIP_VERSION_MINOR << 16 | \ + LWIP_VERSION_REVISION << 8 | LWIP_VERSION_RC) + /* Modules initialization */ void lwip_init(void); diff --git a/net/lwip/src/include/lwip/mem.h b/net/lwip/src/include/lwip/mem.h index cf91733498..327c2049ff 100644 --- a/net/lwip/src/include/lwip/mem.h +++ b/net/lwip/src/include/lwip/mem.h @@ -50,16 +50,20 @@ typedef size_t mem_size_t; * allow these defines to be overridden. */ #ifndef mem_free -#define mem_free(x) free(x) +#define mem_free free #endif #ifndef mem_malloc -#define mem_malloc(x) malloc(x) +#define mem_malloc malloc #endif #ifndef mem_calloc -#define mem_calloc(x, y) calloc(x, y) +#define mem_calloc calloc #endif #ifndef mem_realloc -#define mem_realloc(x, size) (x) +static void *mem_realloc(void *mem, mem_size_t size) +{ + LWIP_UNUSED_ARG(size); + return mem; +} #endif #else /* MEM_LIBC_MALLOC */ diff --git a/net/lwip/src/include/lwip/memp.h b/net/lwip/src/include/lwip/memp.h index a04386335e..f0d0739943 100644 --- a/net/lwip/src/include/lwip/memp.h +++ b/net/lwip/src/include/lwip/memp.h @@ -73,8 +73,28 @@ typedef enum { We use this helper type and these defines so we can avoid using const memp_t values */ #define MEMP_POOL_FIRST ((memp_t) MEMP_POOL_HELPER_FIRST) #define MEMP_POOL_LAST ((memp_t) MEMP_POOL_HELPER_LAST) +#endif /* MEM_USE_POOLS */ +#if MEMP_MEM_MALLOC || MEM_USE_POOLS extern const u16_t memp_sizes[MEMP_MAX]; +#endif /* MEMP_MEM_MALLOC || MEM_USE_POOLS */ + +#if MEMP_MEM_MALLOC + +#include "mem.h" + +#define memp_init() +#define memp_malloc(type) mem_malloc(memp_sizes[type]) +#define memp_free(type, mem) mem_free(mem) + +#else /* MEMP_MEM_MALLOC */ + +#if MEM_USE_POOLS +/** This structure is used to save the pool one element came from. */ +struct memp_malloc_helper +{ + memp_t poolnr; +}; #endif /* MEM_USE_POOLS */ void memp_init(void); @@ -87,6 +107,8 @@ void *memp_malloc(memp_t type); #endif void memp_free(memp_t type, void *mem); +#endif /* MEMP_MEM_MALLOC */ + #ifdef __cplusplus } #endif diff --git a/net/lwip/src/include/lwip/memp_std.h b/net/lwip/src/include/lwip/memp_std.h index c314bf879f..344690328c 100644 --- a/net/lwip/src/include/lwip/memp_std.h +++ b/net/lwip/src/include/lwip/memp_std.h @@ -10,8 +10,9 @@ * above, then will declare #2 & #3 to be just standard mempools. */ #ifndef LWIP_MALLOC_MEMPOOL -/* This treats "malloc pools" just like any other pool */ -#define LWIP_MALLOC_MEMPOOL(num, size) LWIP_MEMPOOL(POOL_##size, num, size, "MALLOC_"#size) +/* This treats "malloc pools" just like any other pool. + The pools are a little bigger to provide 'size' as the amount of user data. */ +#define LWIP_MALLOC_MEMPOOL(num, size) LWIP_MEMPOOL(POOL_##size, num, (size + sizeof(struct memp_malloc_helper)), "MALLOC_"#size) #define LWIP_MALLOC_MEMPOOL_START #define LWIP_MALLOC_MEMPOOL_END #endif /* LWIP_MALLOC_MEMPOOL */ diff --git a/net/lwip/src/include/lwip/netbuf.h b/net/lwip/src/include/lwip/netbuf.h index f6de3a4f6a..6d84dd073b 100644 --- a/net/lwip/src/include/lwip/netbuf.h +++ b/net/lwip/src/include/lwip/netbuf.h @@ -65,6 +65,7 @@ void netbuf_first (struct netbuf *buf); #define netbuf_copy_partial(buf, dataptr, len, offset) \ pbuf_copy_partial((buf)->p, (dataptr), (len), (offset)) #define netbuf_copy(buf,dataptr,len) netbuf_copy_partial(buf, dataptr, len, 0) +#define netbuf_take(buf, dataptr, len) pbuf_take((buf)->p, dataptr, len) #define netbuf_len(buf) ((buf)->p->tot_len) #define netbuf_fromaddr(buf) ((buf)->addr) #define netbuf_fromport(buf) ((buf)->port) diff --git a/net/lwip/src/include/lwip/netdb.h b/net/lwip/src/include/lwip/netdb.h index ce175ce4fa..0f7b2ec04a 100644 --- a/net/lwip/src/include/lwip/netdb.h +++ b/net/lwip/src/include/lwip/netdb.h @@ -31,6 +31,8 @@ #if LWIP_DNS && LWIP_SOCKET +#include <stddef.h> /* for size_t */ + #include "lwip/sockets.h" /* some rarely used options */ diff --git a/net/lwip/src/include/lwip/netif.h b/net/lwip/src/include/lwip/netif.h index 19c38087bc..a325030526 100644 --- a/net/lwip/src/include/lwip/netif.h +++ b/net/lwip/src/include/lwip/netif.h @@ -34,6 +34,8 @@ #include "lwip/opt.h" +#define ENABLE_LOOPBACK (LWIP_NETIF_LOOPBACK || LWIP_HAVE_LOOPIF) + #include "lwip/err.h" #include "lwip/ip_addr.h" @@ -165,6 +167,14 @@ struct netif { #if LWIP_NETIF_HWADDRHINT u8_t *addr_hint; #endif /* LWIP_NETIF_HWADDRHINT */ +#if ENABLE_LOOPBACK + /* List of packets to be queued for ourselves. */ + struct pbuf *loop_first; + struct pbuf *loop_last; +#if LWIP_LOOPBACK_MAX_PBUFS + u16_t loop_cnt_current; +#endif /* LWIP_LOOPBACK_MAX_PBUFS */ +#endif /* ENABLE_LOOPBACK */ }; #if LWIP_SNMP @@ -242,4 +252,12 @@ void netif_set_link_callback(struct netif *netif, void (* link_callback)(struct } #endif +#if ENABLE_LOOPBACK +err_t netif_loop_output(struct netif *netif, struct pbuf *p, struct ip_addr *dest_ip); +void netif_poll(struct netif *netif); +#if !LWIP_NETIF_LOOPBACK_MULTITHREADING +void netif_poll_all(void); +#endif /* !LWIP_NETIF_LOOPBACK_MULTITHREADING */ +#endif /* ENABLE_LOOPBACK */ + #endif /* __LWIP_NETIF_H__ */ diff --git a/net/lwip/src/include/lwip/opt.h b/net/lwip/src/include/lwip/opt.h index df83afe297..e8bd8b89e4 100644 --- a/net/lwip/src/include/lwip/opt.h +++ b/net/lwip/src/include/lwip/opt.h @@ -99,6 +99,15 @@ #endif /** +* MEMP_MEM_MALLOC==1: Use mem_malloc/mem_free instead of the lwip pool allocator. +* Especially useful with MEM_LIBC_MALLOC but handle with care regarding execution +* speed and usage from interrupts! +*/ +#ifndef MEMP_MEM_MALLOC +#define MEMP_MEM_MALLOC 0 +#endif + +/** * MEM_ALIGNMENT: should be set to the alignment of the CPU * 4 byte alignment -> #define MEM_ALIGNMENT 4 * 2 byte alignment -> #define MEM_ALIGNMENT 2 @@ -139,13 +148,22 @@ /** * MEM_USE_POOLS==1: Use an alternative to malloc() by allocating from a set * of memory pools of various sizes. When mem_malloc is called, an element of - * the smallest pool that can provide the lenght needed is returned. + * the smallest pool that can provide the length needed is returned. + * To use this, MEMP_USE_CUSTOM_POOLS also has to be enabled. */ #ifndef MEM_USE_POOLS #define MEM_USE_POOLS 0 #endif /** + * MEM_USE_POOLS_TRY_BIGGER_POOL==1: if one malloc-pool is empty, try the next + * bigger pool - WARNING: THIS MIGHT WASTE MEMORY but it can make a system more + * reliable. */ +#ifndef MEM_USE_POOLS_TRY_BIGGER_POOL +#define MEM_USE_POOLS_TRY_BIGGER_POOL 0 +#endif + +/** * MEMP_USE_CUSTOM_POOLS==1: whether to include a user file lwippools.h * that defines additional pools beyond the "standard" ones required * by lwIP. If you set this to 1, you must have lwippools.h in your @@ -155,6 +173,27 @@ #define MEMP_USE_CUSTOM_POOLS 0 #endif +/** + * Set this to 1 if you want to free PBUF_RAM pbufs (or call mem_free()) from + * interrupt context (or another context that doesn't allow waiting for a + * semaphore). + * If set to 1, mem_malloc will be protected by a semaphore and SYS_ARCH_PROTECT, + * while mem_free will only use SYS_ARCH_PROTECT. mem_malloc SYS_ARCH_UNPROTECTs + * with each loop so that mem_free can run. + * + * ATTENTION: As you can see from the above description, this leads to dis-/ + * enabling interrupts often, which can be slow! Also, on low memory, mem_malloc + * can need longer. + * + * If you don't want that, at least for NO_SYS=0, you can still use the following + * functions to enqueue a deallocation call which then runs in the tcpip_thread + * context: + * - pbuf_free_callback(p); + * - mem_free_callback(m); + */ +#ifndef LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT +#define LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT 0 +#endif /* ------------------------------------------------ @@ -411,6 +450,23 @@ #define IP_DEFAULT_TTL 255 #endif +/** + * IP_SOF_BROADCAST=1: Use the SOF_BROADCAST field to enable broadcast + * filter per pcb on udp and raw send operations. To enable broadcast filter + * on recv operations, you also have to set IP_SOF_BROADCAST_RECV=1. + */ +#ifndef IP_SOF_BROADCAST +#define IP_SOF_BROADCAST 0 +#endif + +/** + * IP_SOF_BROADCAST_RECV (requires IP_SOF_BROADCAST=1) enable the broadcast + * filter on recv operations. + */ +#ifndef IP_SOF_BROADCAST_RECV +#define IP_SOF_BROADCAST_RECV 0 +#endif + /* ---------------------------------- ---------- ICMP options ---------- @@ -431,6 +487,20 @@ #define ICMP_TTL (IP_DEFAULT_TTL) #endif +/** + * LWIP_BROADCAST_PING==1: respond to broadcast pings (default is unicast only) + */ +#ifndef LWIP_BROADCAST_PING +#define LWIP_BROADCAST_PING 0 +#endif + +/** + * LWIP_MULTICAST_PING==1: respond to multicast pings (default is unicast only) + */ +#ifndef LWIP_MULTICAST_PING +#define LWIP_MULTICAST_PING 0 +#endif + /* --------------------------------- ---------- RAW options ---------- @@ -489,6 +559,17 @@ #define LWIP_DHCP_AUTOIP_COOP 0 #endif +/** + * LWIP_DHCP_AUTOIP_COOP_TRIES: Set to the number of DHCP DISCOVER probes + * that should be sent before falling back on AUTOIP. This can be set + * as low as 1 to get an AutoIP address very quickly, but you should + * be prepared to handle a changing IP address when DHCP overrides + * AutoIP. + */ +#ifndef LWIP_DHCP_AUTOIP_COOP_TRIES +#define LWIP_DHCP_AUTOIP_COOP_TRIES 9 +#endif + /* ---------------------------------- ---------- SNMP options ---------- @@ -591,6 +672,26 @@ #define DNS_MSG_SIZE 512 #endif +/** DNS_LOCAL_HOSTLIST: Implements a local host-to-address list. If enabled, + * you have to define + * #define DNS_LOCAL_HOSTLIST_INIT {{"host1", 0x123}, {"host2", 0x234}} + * (an array of structs name/address, where address is an u32_t in network + * byte order). + * + * Instead, you can also use an external function: + * #define DNS_LOOKUP_LOCAL_EXTERN(x) extern u32_t my_lookup_function(const char *name) + * that returns the IP address or INADDR_NONE if not found. + */ +#ifndef DNS_LOCAL_HOSTLIST +#define DNS_LOCAL_HOSTLIST 0 +#endif /* DNS_LOCAL_HOSTLIST */ + +/** If this is turned on, the local host-list can be dynamically changed + * at runtime. */ +#ifndef DNS_LOCAL_HOSTLIST_IS_DYNAMIC +#define DNS_LOCAL_HOSTLIST_IS_DYNAMIC 0 +#endif /* DNS_LOCAL_HOSTLIST_IS_DYNAMIC */ + /* --------------------------------- ---------- UDP options ---------- @@ -637,7 +738,8 @@ #endif /** - * TCP_WND: The size of a TCP window. + * TCP_WND: The size of a TCP window. This must be at least + * (2 * TCP_MSS) for things to work well */ #ifndef TCP_WND #define TCP_WND 2048 @@ -662,7 +764,7 @@ * Define to 0 if your device is low on memory. */ #ifndef TCP_QUEUE_OOSEQ -#define TCP_QUEUE_OOSEQ 1 +#define TCP_QUEUE_OOSEQ (LWIP_TCP) #endif /** @@ -730,6 +832,21 @@ #endif /** + * LWIP_TCP_TIMESTAMPS==1: support the TCP timestamp option. + */ +#ifndef LWIP_TCP_TIMESTAMPS +#define LWIP_TCP_TIMESTAMPS 0 +#endif + +/** + * TCP_WND_UPDATE_THRESHOLD: difference in window to trigger an + * explicit window update + */ +#ifndef TCP_WND_UPDATE_THRESHOLD +#define TCP_WND_UPDATE_THRESHOLD (TCP_WND / 4) +#endif + +/** * LWIP_EVENT_API and LWIP_CALLBACK_API: Only one of these should be set to 1. * LWIP_EVENT_API==1: The user defines lwip_tcp_event() to receive all * events (accept, sent, etc) that happen in the system. @@ -815,6 +932,52 @@ #define LWIP_NETIF_HWADDRHINT 0 #endif +/** + * LWIP_NETIF_LOOPBACK==1: Support sending packets with a destination IP + * address equal to the netif IP address, looping them back up the stack. + */ +#ifndef LWIP_NETIF_LOOPBACK +#define LWIP_NETIF_LOOPBACK 0 +#endif + +/** + * LWIP_LOOPBACK_MAX_PBUFS: Maximum number of pbufs on queue for loopback + * sending for each netif (0 = disabled) + */ +#ifndef LWIP_LOOPBACK_MAX_PBUFS +#define LWIP_LOOPBACK_MAX_PBUFS 0 +#endif + +/** + * LWIP_NETIF_LOOPBACK_MULTITHREADING: Indicates whether threading is enabled in + * the system, as netifs must change how they behave depending on this setting + * for the LWIP_NETIF_LOOPBACK option to work. + * Setting this is needed to avoid reentering non-reentrant functions like + * tcp_input(). + * LWIP_NETIF_LOOPBACK_MULTITHREADING==1: Indicates that the user is using a + * multithreaded environment like tcpip.c. In this case, netif->input() + * is called directly. + * LWIP_NETIF_LOOPBACK_MULTITHREADING==0: Indicates a polling (or NO_SYS) setup. + * The packets are put on a list and netif_poll() must be called in + * the main application loop. + */ +#ifndef LWIP_NETIF_LOOPBACK_MULTITHREADING +#define LWIP_NETIF_LOOPBACK_MULTITHREADING (!NO_SYS) +#endif + +/** + * LWIP_NETIF_TX_SINGLE_PBUF: if this is set to 1, lwIP tries to put all data + * to be sent into one single pbuf. This is for compatibility with DMA-enabled + * MACs that do not support scatter-gather. + * Beware that this might involve CPU-memcpy before transmitting that would not + * be needed without this flag! Use this only if you need to! + * + * @todo: TCP and IP-frag do not work with this, yet: + */ +#ifndef LWIP_NETIF_TX_SINGLE_PBUF +#define LWIP_NETIF_TX_SINGLE_PBUF 0 +#endif /* LWIP_NETIF_TX_SINGLE_PBUF */ + /* ------------------------------------ ---------- LOOPIF options ---------- @@ -827,20 +990,16 @@ #define LWIP_HAVE_LOOPIF 0 #endif +/* + ------------------------------------ + ---------- SLIPIF options ---------- + ------------------------------------ +*/ /** - * LWIP_LOOPIF_MULTITHREADING: Indicates whether threading is enabled in - * the system, as LOOPIF must change how it behaves depending on this setting. - * Setting this is needed to avoid reentering non-reentrant functions like - * tcp_input(). - * LWIP_LOOPIF_MULTITHREADING==1: Indicates that the user is using a - * multithreaded environment like tcpip.c. In this case, netif->input() - * is called directly. - * LWIP_LOOPIF_MULTITHREADING==0: Indicates a polling (or NO_SYS) setup. - * The packets are put on a list and loopif_poll() must be called in - * the main application loop. + * LWIP_HAVE_SLIPIF==1: Support slip interface and slipif.c */ -#ifndef LWIP_LOOPIF_MULTITHREADING -#define LWIP_LOOPIF_MULTITHREADING 1 +#ifndef LWIP_HAVE_SLIPIF +#define LWIP_HAVE_SLIPIF 0 #endif /* @@ -1039,7 +1198,7 @@ * names (read, write & close). (only used if you use sockets.c) */ #ifndef LWIP_POSIX_SOCKETS_IO_NAMES -#define LWIP_POSIX_SOCKETS_IO_NAMES 0 +#define LWIP_POSIX_SOCKETS_IO_NAMES 1 #endif /** @@ -1066,6 +1225,13 @@ #endif /** + * If LWIP_SO_RCVBUF is used, this is the default value for recv_bufsize. + */ +#ifndef RECV_BUFSIZE_DEFAULT +#define RECV_BUFSIZE_DEFAULT INT_MAX +#endif + +/** * SO_REUSE==1: Enable SO_REUSEADDR and SO_REUSEPORT options. DO NOT USE! */ #ifndef SO_REUSE diff --git a/net/lwip/src/include/lwip/pbuf.h b/net/lwip/src/include/lwip/pbuf.h index 57a1e9991f..8380f65da7 100644 --- a/net/lwip/src/include/lwip/pbuf.h +++ b/net/lwip/src/include/lwip/pbuf.h @@ -110,6 +110,8 @@ void pbuf_chain(struct pbuf *head, struct pbuf *tail); struct pbuf *pbuf_dechain(struct pbuf *p); err_t pbuf_copy(struct pbuf *p_to, struct pbuf *p_from); u16_t pbuf_copy_partial(struct pbuf *p, void *dataptr, u16_t len, u16_t offset); +err_t pbuf_take(struct pbuf *buf, const void *dataptr, u16_t len); +struct pbuf *pbuf_coalesce(struct pbuf *p, pbuf_layer layer); #ifdef __cplusplus } diff --git a/net/lwip/src/include/lwip/sio.h b/net/lwip/src/include/lwip/sio.h index 7437522c73..7d9162e49e 100644 --- a/net/lwip/src/include/lwip/sio.h +++ b/net/lwip/src/include/lwip/sio.h @@ -32,16 +32,24 @@ * It needs to be implemented by those platforms which need SLIP or PPP */ +#ifndef __SIO_H__ +#define __SIO_H__ + #include "lwip/arch.h" #ifdef __cplusplus extern "C" { #endif +/* If you want to define sio_fd_t elsewhere or differently, + define this in your cc.h file. */ #ifndef __sio_fd_t_defined typedef void * sio_fd_t; #endif +/* The following functions can be defined to something else in your cc.h file + or be implemented in your custom sio.c file. */ + #ifndef sio_open sio_fd_t sio_open(u8_t); #endif @@ -69,3 +77,5 @@ void sio_read_abort(sio_fd_t); #ifdef __cplusplus } #endif + +#endif /* __SIO_H__ */ diff --git a/net/lwip/src/include/lwip/snmp_asn1.h b/net/lwip/src/include/lwip/snmp_asn1.h index 3d70d330ed..8a602881fe 100644 --- a/net/lwip/src/include/lwip/snmp_asn1.h +++ b/net/lwip/src/include/lwip/snmp_asn1.h @@ -40,6 +40,8 @@ #include "lwip/pbuf.h" #include "lwip/snmp.h" +#if LWIP_SNMP + #ifdef __cplusplus extern "C" { #endif @@ -94,4 +96,6 @@ err_t snmp_asn1_enc_raw(struct pbuf *p, u16_t ofs, u8_t raw_len, u8_t *raw); } #endif +#endif /* LWIP_SNMP */ + #endif /* __LWIP_SNMP_ASN1_H__ */ diff --git a/net/lwip/src/include/lwip/snmp_msg.h b/net/lwip/src/include/lwip/snmp_msg.h index d202825580..b2f69c4be2 100644 --- a/net/lwip/src/include/lwip/snmp_msg.h +++ b/net/lwip/src/include/lwip/snmp_msg.h @@ -39,6 +39,8 @@ #include "lwip/snmp.h" #include "lwip/snmp_structs.h" +#if LWIP_SNMP + #if SNMP_PRIVATE_MIB #include "private_mib.h" #endif @@ -304,4 +306,6 @@ void snmp_authfail_trap(void); } #endif +#endif /* LWIP_SNMP */ + #endif /* __LWIP_SNMP_MSG_H__ */ diff --git a/net/lwip/src/include/lwip/sockets.h b/net/lwip/src/include/lwip/sockets.h index f105d5b52a..7b52e151c1 100644 --- a/net/lwip/src/include/lwip/sockets.h +++ b/net/lwip/src/include/lwip/sockets.h @@ -38,6 +38,8 @@ #if LWIP_SOCKET /* don't build if not configured for use in lwipopts.h */ +#include <stddef.h> /* for size_t */ + #include "lwip/ip_addr.h" #include "lwip/inet.h" @@ -70,13 +72,6 @@ struct sockaddr { #define SOCK_RAW 3 /* - * Maximum queue length specifiable by listen(2). - */ -#ifndef SOMAXCONN -#define SOMAXCONN 128 -#endif - -/* * Option flags per-socket. These must match the SOF_ flags in ip.h! */ #define SO_DEBUG 0x0001 /* Unimplemented: turn on debugging info recording */ @@ -84,7 +79,7 @@ struct sockaddr { #define SO_REUSEADDR 0x0004 /* Unimplemented: allow local address reuse */ #define SO_KEEPALIVE 0x0008 /* keep connections alive */ #define SO_DONTROUTE 0x0010 /* Unimplemented: just use interface addresses */ -#define SO_BROADCAST 0x0020 /* Unimplemented: permit sending of broadcast msgs */ +#define SO_BROADCAST 0x0020 /* permit to send and to receive broadcast messages (see IP_SOF_BROADCAST option) */ #define SO_USELOOPBACK 0x0040 /* Unimplemented: bypass hardware when possible */ #define SO_LINGER 0x0080 /* linger on close if data present */ #define SO_OOBINLINE 0x0100 /* Unimplemented: leave received OOB data in line */ @@ -131,9 +126,6 @@ struct linger { #define IPPROTO_UDP 17 #define IPPROTO_UDPLITE 136 -#define INADDR_ANY 0 -#define INADDR_BROADCAST 0xffffffff - /* Flags we can use with send and recv. */ #define MSG_PEEK 0x01 /* Peeks at an incoming message */ #define MSG_WAITALL 0x02 /* Unimplemented: Requests that the function block until the full amount of data requested can be returned */ @@ -184,7 +176,22 @@ typedef struct ip_mreq { } ip_mreq; #endif /* LWIP_IGMP */ -/* Unimplemented for now... */ +/* + * The Type of Service provides an indication of the abstract + * parameters of the quality of service desired. These parameters are + * to be used to guide the selection of the actual service parameters + * when transmitting a datagram through a particular network. Several + * networks offer service precedence, which somehow treats high + * precedence traffic as more important than other traffic (generally + * by accepting only traffic above a certain precedence at time of high + * load). The major choice is a three way tradeoff between low-delay, + * high-reliability, and high-throughput. + * The use of the Delay, Throughput, and Reliability indications may + * increase the cost (in some sense) of the service. In many networks + * better performance for one of these parameters is coupled with worse + * performance on another. Except for very unusual cases at most two + * of these three indications should be set. + */ #define IPTOS_TOS_MASK 0x1E #define IPTOS_TOS(tos) ((tos) & IPTOS_TOS_MASK) #define IPTOS_LOWDELAY 0x10 @@ -194,7 +201,13 @@ typedef struct ip_mreq { #define IPTOS_MINCOST IPTOS_LOWCOST /* - * Definitions for IP precedence (also in ip_tos) (Unimplemented) + * The Network Control precedence designation is intended to be used + * within a network only. The actual use and control of that + * designation is up to each network. The Internetwork Control + * designation is intended for use by gateway control originators only. + * If the actual use of these precedence designations is of concern to + * a particular network, it is the responsibility of that network to + * control the access to, and use of, those precedence designations. */ #define IPTOS_PREC_MASK 0xe0 #define IPTOS_PREC(tos) ((tos) & IPTOS_PREC_MASK) @@ -286,7 +299,7 @@ struct timeval { void lwip_socket_init(void); int lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen); -int lwip_bind(int s, struct sockaddr *name, socklen_t namelen); +int lwip_bind(int s, const struct sockaddr *name, socklen_t namelen); int lwip_shutdown(int s, int how); int lwip_getpeername (int s, struct sockaddr *name, socklen_t *namelen); int lwip_getsockname (int s, struct sockaddr *name, socklen_t *namelen); @@ -295,15 +308,15 @@ int lwip_setsockopt (int s, int level, int optname, const void *optval, socklen_ int lwip_close(int s); int lwip_connect(int s, const struct sockaddr *name, socklen_t namelen); int lwip_listen(int s, int backlog); -int lwip_recv(int s, void *mem, int len, unsigned int flags); -int lwip_read(int s, void *mem, int len); -int lwip_recvfrom(int s, void *mem, int len, unsigned int flags, +int lwip_recv(int s, void *mem, size_t len, int flags); +int lwip_read(int s, void *mem, size_t len); +int lwip_recvfrom(int s, void *mem, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen); -int lwip_send(int s, const void *dataptr, int size, unsigned int flags); -int lwip_sendto(int s, const void *dataptr, int size, unsigned int flags, - struct sockaddr *to, socklen_t tolen); +int lwip_send(int s, const void *dataptr, size_t size, int flags); +int lwip_sendto(int s, const void *dataptr, size_t size, int flags, + const struct sockaddr *to, socklen_t tolen); int lwip_socket(int domain, int type, int protocol); -int lwip_write(int s, const void *dataptr, int size); +int lwip_write(int s, const void *dataptr, size_t size); int lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, struct timeval *timeout); int lwip_ioctl(int s, long cmd, void *argp); diff --git a/net/lwip/src/include/lwip/stats.h b/net/lwip/src/include/lwip/stats.h index 755092ece0..aa179f5c00 100644 --- a/net/lwip/src/include/lwip/stats.h +++ b/net/lwip/src/include/lwip/stats.h @@ -57,7 +57,6 @@ extern "C" { struct stats_proto { STAT_COUNTER xmit; /* Transmitted packets. */ - STAT_COUNTER rexmit; /* Retransmitted packets. */ STAT_COUNTER recv; /* Received packets. */ STAT_COUNTER fw; /* Forwarded packets. */ STAT_COUNTER drop; /* Dropped packets. */ @@ -87,7 +86,8 @@ struct stats_mem { mem_size_t avail; mem_size_t used; mem_size_t max; - mem_size_t err; + STAT_COUNTER err; + STAT_COUNTER illegal; }; struct stats_syselem { @@ -142,64 +142,138 @@ extern struct stats_ lwip_stats; #define stats_init() /* Compatibility define, not init needed. */ #define STATS_INC(x) ++lwip_stats.x +#define STATS_DEC(x) --lwip_stats.x #else #define stats_init() #define STATS_INC(x) +#define STATS_DEC(x) #endif /* LWIP_STATS */ #if TCP_STATS #define TCP_STATS_INC(x) STATS_INC(x) +#define TCP_STATS_DISPLAY() stats_display_proto(&lwip_stats.tcp, "TCP") #else #define TCP_STATS_INC(x) +#define TCP_STATS_DISPLAY() #endif #if UDP_STATS #define UDP_STATS_INC(x) STATS_INC(x) +#define UDP_STATS_DISPLAY() stats_display_proto(&lwip_stats.udp, "UDP") #else #define UDP_STATS_INC(x) +#define UDP_STATS_DISPLAY() #endif #if ICMP_STATS #define ICMP_STATS_INC(x) STATS_INC(x) +#define ICMP_STATS_DISPLAY() stats_display_proto(&lwip_stats.icmp, "ICMP") #else #define ICMP_STATS_INC(x) +#define ICMP_STATS_DISPLAY() #endif #if IGMP_STATS #define IGMP_STATS_INC(x) STATS_INC(x) +#define IGMP_STATS_DISPLAY() stats_display_igmp(&lwip_stats.igmp) #else #define IGMP_STATS_INC(x) +#define IGMP_STATS_DISPLAY() #endif #if IP_STATS #define IP_STATS_INC(x) STATS_INC(x) +#define IP_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip, "IP") #else #define IP_STATS_INC(x) +#define IP_STATS_DISPLAY() #endif #if IPFRAG_STATS #define IPFRAG_STATS_INC(x) STATS_INC(x) +#define IPFRAG_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip_frag, "IP_FRAG") #else #define IPFRAG_STATS_INC(x) +#define IPFRAG_STATS_DISPLAY() #endif #if ETHARP_STATS #define ETHARP_STATS_INC(x) STATS_INC(x) +#define ETHARP_STATS_DISPLAY() stats_display_proto(&lwip_stats.etharp, "ETHARP") #else #define ETHARP_STATS_INC(x) +#define ETHARP_STATS_DISPLAY() #endif #if LINK_STATS #define LINK_STATS_INC(x) STATS_INC(x) +#define LINK_STATS_DISPLAY() stats_display_proto(&lwip_stats.link, "LINK") #else #define LINK_STATS_INC(x) +#define LINK_STATS_DISPLAY() +#endif + +#if MEM_STATS +#define MEM_STATS_AVAIL(x, y) lwip_stats.mem.x = y +#define MEM_STATS_INC(x) STATS_INC(mem.x) +#define MEM_STATS_INC_USED(x, y) do { lwip_stats.mem.used += y; \ + if (lwip_stats.mem.max < lwip_stats.mem.used) { \ + lwip_stats.mem.max = lwip_stats.mem.used; \ + } \ + } while(0) +#define MEM_STATS_DEC_USED(x, y) lwip_stats.mem.x -= y +#define MEM_STATS_DISPLAY() stats_display_mem(&lwip_stats.mem, "HEAP") +#else +#define MEM_STATS_AVAIL(x, y) +#define MEM_STATS_INC(x) +#define MEM_STATS_INC_USED(x, y) +#define MEM_STATS_DEC_USED(x, y) +#define MEM_STATS_DISPLAY() +#endif + +#if MEMP_STATS +#define MEMP_STATS_AVAIL(x, i, y) lwip_stats.memp[i].x = y +#define MEMP_STATS_INC(x, i) STATS_INC(memp[i].x) +#define MEMP_STATS_DEC(x, i) STATS_DEC(memp[i].x) +#define MEMP_STATS_INC_USED(x, i) do { ++lwip_stats.memp[i].used; \ + if (lwip_stats.memp[i].max < lwip_stats.memp[i].used) { \ + lwip_stats.memp[i].max = lwip_stats.memp[i].used; \ + } \ + } while(0) +#define MEMP_STATS_DISPLAY(i) stats_display_memp(&lwip_stats.memp[i], i) +#else +#define MEMP_STATS_AVAIL(x, i, y) +#define MEMP_STATS_INC(x, i) +#define MEMP_STATS_DEC(x, i) +#define MEMP_STATS_INC_USED(x, i) +#define MEMP_STATS_DISPLAY(i) +#endif + +#if SYS_STATS +#define SYS_STATS_INC(x) STATS_INC(sys.x) +#define SYS_STATS_DEC(x) STATS_DEC(sys.x) +#define SYS_STATS_DISPLAY() stats_display_sys(&lwip_stats.sys) +#else +#define SYS_STATS_INC(x) +#define SYS_STATS_DEC(x) +#define SYS_STATS_DISPLAY() #endif /* Display of statistics */ #if LWIP_STATS_DISPLAY void stats_display(void); +void stats_display_proto(struct stats_proto *proto, char *name); +void stats_display_igmp(struct stats_igmp *igmp); +void stats_display_mem(struct stats_mem *mem, char *name); +void stats_display_memp(struct stats_mem *mem, int index); +void stats_display_sys(struct stats_sys *sys); #else #define stats_display() +#define stats_display_proto(proto, name) +#define stats_display_igmp(igmp) +#define stats_display_mem(mem, name) +#define stats_display_memp(mem, index) +#define stats_display_sys(sys) #endif /* LWIP_STATS_DISPLAY */ #ifdef __cplusplus diff --git a/net/lwip/src/include/lwip/sys.h b/net/lwip/src/include/lwip/sys.h index ce73beacf5..0cc84ddf1d 100644 --- a/net/lwip/src/include/lwip/sys.h +++ b/net/lwip/src/include/lwip/sys.h @@ -44,7 +44,6 @@ extern "C" { definitions of the sys_ functions. */ typedef u8_t sys_sem_t; typedef u8_t sys_mbox_t; -typedef u8_t sys_prot_t; struct sys_timeo {u8_t dummy;}; #define sys_init() @@ -139,13 +138,11 @@ void sys_mbox_fetch(sys_mbox_t mbox, void **msg); /* Thread functions. */ sys_thread_t sys_thread_new(char *name, void (* thread)(void *arg), void *arg, int stacksize, int prio); -/* The following functions are used only in Unix code, and - can be omitted when porting the stack. */ -/* Returns the current time in microseconds. */ -unsigned long sys_now(void); - #endif /* NO_SYS */ +/** Returns the current time in milliseconds. */ +u32_t sys_now(void); + /* Critical Region Protection */ /* These functions must be implemented in the sys_arch.c file. In some implementations they can provide a more light-weight protection diff --git a/net/lwip/src/include/lwip/tcp.h b/net/lwip/src/include/lwip/tcp.h index 883b0b8316..8f6b9d3c13 100644 --- a/net/lwip/src/include/lwip/tcp.h +++ b/net/lwip/src/include/lwip/tcp.h @@ -96,7 +96,8 @@ err_t tcp_connect (struct tcp_pcb *pcb, struct ip_addr *ipaddr, struct tcp_pcb * tcp_listen_with_backlog(struct tcp_pcb *pcb, u8_t backlog); #define tcp_listen(pcb) tcp_listen_with_backlog(pcb, TCP_DEFAULT_LISTEN_BACKLOG) -void tcp_abort (struct tcp_pcb *pcb); +void tcp_abandon (struct tcp_pcb *pcb, int reset); +#define tcp_abort(pcb) tcp_abandon((pcb), 1) err_t tcp_close (struct tcp_pcb *pcb); /* Flags for "apiflags" parameter in tcp_write and tcp_enqueue */ @@ -124,26 +125,24 @@ void tcp_input (struct pbuf *p, struct netif *inp); err_t tcp_output (struct tcp_pcb *pcb); void tcp_rexmit (struct tcp_pcb *pcb); void tcp_rexmit_rto (struct tcp_pcb *pcb); +u32_t tcp_update_rcv_ann_wnd(struct tcp_pcb *pcb); /** - * This is the Nagle algorithm: inhibit the sending of new TCP - * segments when new outgoing data arrives from the user if any - * previously transmitted data on the connection remains - * unacknowledged. + * This is the Nagle algorithm: try to combine user data to send as few TCP + * segments as possible. Only send if + * - no previously transmitted data on the connection remains unacknowledged or + * - the TF_NODELAY flag is set (nagle algorithm turned off for this pcb) or + * - the only unsent segment is at least pcb->mss bytes long (or there is more + * than one unsent segment - with lwIP, this can happen although unsent->len < mss) */ #define tcp_do_output_nagle(tpcb) ((((tpcb)->unacked == NULL) || \ ((tpcb)->flags & TF_NODELAY) || \ - (((tpcb)->unsent != NULL) && ((tpcb)->unsent->next != NULL))) ? \ - 1 : 0) + (((tpcb)->unsent != NULL) && (((tpcb)->unsent->next != NULL) || \ + ((tpcb)->unsent->len >= (tpcb)->mss))) \ + ) ? 1 : 0) #define tcp_output_nagle(tpcb) (tcp_do_output_nagle(tpcb) ? tcp_output(tpcb) : ERR_OK) -/** This returns a TCP header option for MSS in an u32_t */ -#define TCP_BUILD_MSS_OPTION() htonl(((u32_t)2 << 24) | \ - ((u32_t)4 << 16) | \ - (((u32_t)TCP_MSS / 256) << 8) | \ - (TCP_MSS & 255)) - #define TCP_SEQ_LT(a,b) ((s32_t)((a)-(b)) < 0) #define TCP_SEQ_LEQ(a,b) ((s32_t)((a)-(b)) <= 0) #define TCP_SEQ_GT(a,b) ((s32_t)((a)-(b)) > 0) @@ -185,7 +184,7 @@ void tcp_rexmit_rto (struct tcp_pcb *pcb); #define TCP_OOSEQ_TIMEOUT 6U /* x RTO */ #ifndef TCP_MSL -#define TCP_MSL 60000U /* The maximum segment lifetime in milliseconds */ +#define TCP_MSL 60000UL /* The maximum segment lifetime in milliseconds */ #endif /* Keepalive values, compliant with RFC 1122. Don't change this unless you know what you're doing */ @@ -258,6 +257,20 @@ enum tcp_state { #define TF_CLOSED (u8_t)0x10U /* Connection was sucessfully closed. */ #define TF_GOT_FIN (u8_t)0x20U /* Connection was closed by the remote end. */ + +#if LWIP_CALLBACK_API + /* Function to call when a listener has been connected. + * @param arg user-supplied argument (tcp_pcb.callback_arg) + * @param pcb a new tcp_pcb that now is connected + * @param err an error argument (TODO: that is current always ERR_OK?) + * @return ERR_OK: accept the new connection, + * any other err_t abortsthe new connection + */ +#define DEF_ACCEPT_CALLBACK err_t (* accept)(void *arg, struct tcp_pcb *newpcb, err_t err) +#else /* LWIP_CALLBACK_API */ +#define DEF_ACCEPT_CALLBACK +#endif /* LWIP_CALLBACK_API */ + /** * members common to struct tcp_pcb and struct tcp_listen_pcb */ @@ -267,7 +280,10 @@ enum tcp_state { u8_t prio; \ void *callback_arg; \ /* ports are in host byte order */ \ - u16_t local_port + u16_t local_port; \ + /* the accept callback for listen- and normal pcbs, if LWIP_CALLBACK_API */ \ + DEF_ACCEPT_CALLBACK + /* the TCP protocol control block */ struct tcp_pcb { @@ -280,19 +296,21 @@ struct tcp_pcb { u16_t remote_port; u8_t flags; -#define TF_ACK_DELAY (u8_t)0x01U /* Delayed ACK. */ -#define TF_ACK_NOW (u8_t)0x02U /* Immediate ACK. */ -#define TF_INFR (u8_t)0x04U /* In fast recovery. */ -#define TF_FIN (u8_t)0x20U /* Connection was closed locally (FIN segment enqueued). */ -#define TF_NODELAY (u8_t)0x40U /* Disable Nagle algorithm */ -#define TF_NAGLEMEMERR (u8_t)0x80U /* nagle enabled, memerr, try to output to prevent delayed ACK to happen */ +#define TF_ACK_DELAY ((u8_t)0x01U) /* Delayed ACK. */ +#define TF_ACK_NOW ((u8_t)0x02U) /* Immediate ACK. */ +#define TF_INFR ((u8_t)0x04U) /* In fast recovery. */ +#define TF_TIMESTAMP ((u8_t)0x08U) /* Timestamp option enabled */ +#define TF_FIN ((u8_t)0x20U) /* Connection was closed locally (FIN segment enqueued). */ +#define TF_NODELAY ((u8_t)0x40U) /* Disable Nagle algorithm */ +#define TF_NAGLEMEMERR ((u8_t)0x80U) /* nagle enabled, memerr, try to output to prevent delayed ACK to happen */ /* the rest of the fields are in host byte order as we have to do some math with them */ /* receiver variables */ u32_t rcv_nxt; /* next seqno expected */ - u16_t rcv_wnd; /* receiver window */ - u16_t rcv_ann_wnd; /* announced receive window */ + u16_t rcv_wnd; /* receiver window available */ + u16_t rcv_ann_wnd; /* receiver window to announce */ + u32_t rcv_ann_right_edge; /* announced right edge of window */ /* Timers */ u32_t tmr; @@ -320,12 +338,11 @@ struct tcp_pcb { u16_t ssthresh; /* sender variables */ - u32_t snd_nxt, /* next seqno to be sent */ - snd_max; /* Highest seqno sent. */ + u32_t snd_nxt; /* next new seqno to be sent */ u16_t snd_wnd; /* sender window */ - u32_t snd_wl1, snd_wl2, /* Sequence and acknowledgement numbers of last + u32_t snd_wl1, snd_wl2; /* Sequence and acknowledgement numbers of last window update. */ - snd_lbb; /* Sequence number of next byte to be buffered. */ + u32_t snd_lbb; /* Sequence number of next byte to be buffered. */ u16_t acked; @@ -369,15 +386,6 @@ struct tcp_pcb { */ err_t (* connected)(void *arg, struct tcp_pcb *pcb, err_t err); - /* Function to call when a listener has been connected. - * @param arg user-supplied argument (tcp_pcb.callback_arg) - * @param pcb a new tcp_pcb that now is connected - * @param err an error argument (TODO: that is current always ERR_OK?) - * @return ERR_OK: accept the new connection, - * any other err_t abortsthe new connection - */ - err_t (* accept)(void *arg, struct tcp_pcb *newpcb, err_t err); - /* Function which is called periodically. * The period can be adjusted in multiples of the TCP slow timer interval * by changing tcp_pcb.polltmr. @@ -398,6 +406,11 @@ struct tcp_pcb { void (* errf)(void *arg, err_t err); #endif /* LWIP_CALLBACK_API */ +#if LWIP_TCP_TIMESTAMPS + u32_t ts_lastacksent; + u32_t ts_recent; +#endif /* LWIP_TCP_TIMESTAMPS */ + /* idle time before KEEPALIVE is sent */ u32_t keep_idle; #if LWIP_TCP_KEEPALIVE @@ -420,16 +433,6 @@ struct tcp_pcb_listen { /* Protocol specific PCB members */ TCP_PCB_COMMON(struct tcp_pcb_listen); -#if LWIP_CALLBACK_API - /* Function to call when a listener has been connected. - * @param arg user-supplied argument (tcp_pcb.callback_arg) - * @param pcb a new tcp_pcb that now is connected - * @param err an error argument (TODO: that is current always ERR_OK?) - * @return ERR_OK: accept the new connection, - * any other err_t abortsthe new connection - */ - err_t (* accept)(void *arg, struct tcp_pcb *newpcb, err_t err); -#endif /* LWIP_CALLBACK_API */ #if TCP_LISTEN_BACKLOG u8_t backlog; u8_t accepts_pending; @@ -466,26 +469,52 @@ err_t lwip_tcp_event(void *arg, struct tcp_pcb *pcb, #define TCP_EVENT_ERR(errf,arg,err) lwip_tcp_event((arg), NULL, \ LWIP_EVENT_ERR, NULL, 0, (err)) #else /* LWIP_EVENT_API */ -#define TCP_EVENT_ACCEPT(pcb,err,ret) \ - if((pcb)->accept != NULL) \ - (ret = (pcb)->accept((pcb)->callback_arg,(pcb),(err))) -#define TCP_EVENT_SENT(pcb,space,ret) \ - if((pcb)->sent != NULL) \ - (ret = (pcb)->sent((pcb)->callback_arg,(pcb),(space))) -#define TCP_EVENT_RECV(pcb,p,err,ret) \ - if((pcb)->recv != NULL) \ - { ret = (pcb)->recv((pcb)->callback_arg,(pcb),(p),(err)); } else { \ - ret = ERR_OK; \ - if (p) pbuf_free(p); } -#define TCP_EVENT_CONNECTED(pcb,err,ret) \ - if((pcb)->connected != NULL) \ - (ret = (pcb)->connected((pcb)->callback_arg,(pcb),(err))) -#define TCP_EVENT_POLL(pcb,ret) \ - if((pcb)->poll != NULL) \ - (ret = (pcb)->poll((pcb)->callback_arg,(pcb))) -#define TCP_EVENT_ERR(errf,arg,err) \ - if((errf) != NULL) \ - (errf)((arg),(err)) + +#define TCP_EVENT_ACCEPT(pcb,err,ret) \ + do { \ + if((pcb)->accept != NULL) \ + (ret) = (pcb)->accept((pcb)->callback_arg,(pcb),(err)); \ + else (ret) = ERR_OK; \ + } while (0) + +#define TCP_EVENT_SENT(pcb,space,ret) \ + do { \ + if((pcb)->sent != NULL) \ + (ret) = (pcb)->sent((pcb)->callback_arg,(pcb),(space)); \ + else (ret) = ERR_OK; \ + } while (0) + +#define TCP_EVENT_RECV(pcb,p,err,ret) \ + do { \ + if((pcb)->recv != NULL) { \ + (ret) = (pcb)->recv((pcb)->callback_arg,(pcb),(p),(err)); \ + } else { \ + (ret) = ERR_OK; \ + if (p != NULL) \ + pbuf_free(p); \ + } \ + } while (0) + +#define TCP_EVENT_CONNECTED(pcb,err,ret) \ + do { \ + if((pcb)->connected != NULL) \ + (ret) = (pcb)->connected((pcb)->callback_arg,(pcb),(err)); \ + else (ret) = ERR_OK; \ + } while (0) + +#define TCP_EVENT_POLL(pcb,ret) \ + do { \ + if((pcb)->poll != NULL) \ + (ret) = (pcb)->poll((pcb)->callback_arg,(pcb)); \ + else (ret) = ERR_OK; \ + } while (0) + +#define TCP_EVENT_ERR(errf,arg,err) \ + do { \ + if((errf) != NULL) \ + (errf)((arg),(err)); \ + } while (0) + #endif /* LWIP_EVENT_API */ /* This structure represents a TCP segment on the unsent and unacked queues */ @@ -494,9 +523,22 @@ struct tcp_seg { struct pbuf *p; /* buffer containing data + TCP header */ void *dataptr; /* pointer to the TCP data in the pbuf */ u16_t len; /* the TCP length of this segment */ + u8_t flags; +#define TF_SEG_OPTS_MSS (u8_t)0x01U /* Include MSS option. */ +#define TF_SEG_OPTS_TS (u8_t)0x02U /* Include timestamp option. */ struct tcp_hdr *tcphdr; /* the TCP header */ }; +#define LWIP_TCP_OPT_LENGTH(flags) \ + (flags & TF_SEG_OPTS_MSS ? 4 : 0) + \ + (flags & TF_SEG_OPTS_TS ? 12 : 0) + +/** This returns a TCP header option for MSS in an u32_t */ +#define TCP_BUILD_MSS_OPTION(x) (x) = htonl(((u32_t)2 << 24) | \ + ((u32_t)4 << 16) | \ + (((u32_t)TCP_MSS / 256) << 8) | \ + (TCP_MSS & 255)) + /* Internal functions and global variables: */ struct tcp_pcb *tcp_pcb_copy(struct tcp_pcb *pcb); void tcp_pcb_purge(struct tcp_pcb *pcb); @@ -506,21 +548,27 @@ u8_t tcp_segs_free(struct tcp_seg *seg); u8_t tcp_seg_free(struct tcp_seg *seg); struct tcp_seg *tcp_seg_copy(struct tcp_seg *seg); -#define tcp_ack(pcb) if((pcb)->flags & TF_ACK_DELAY) { \ - (pcb)->flags &= ~TF_ACK_DELAY; \ - (pcb)->flags |= TF_ACK_NOW; \ - tcp_output(pcb); \ - } else { \ - (pcb)->flags |= TF_ACK_DELAY; \ - } +#define tcp_ack(pcb) \ + do { \ + if((pcb)->flags & TF_ACK_DELAY) { \ + (pcb)->flags &= ~TF_ACK_DELAY; \ + (pcb)->flags |= TF_ACK_NOW; \ + tcp_output(pcb); \ + } \ + else { \ + (pcb)->flags |= TF_ACK_DELAY; \ + } \ + } while (0) -#define tcp_ack_now(pcb) (pcb)->flags |= TF_ACK_NOW; \ - tcp_output(pcb) +#define tcp_ack_now(pcb) \ + do { \ + (pcb)->flags |= TF_ACK_NOW; \ + tcp_output(pcb); \ + } while (0) err_t tcp_send_ctrl(struct tcp_pcb *pcb, u8_t flags); err_t tcp_enqueue(struct tcp_pcb *pcb, void *dataptr, u16_t len, - u8_t flags, u8_t apiflags, - u8_t *optdata, u8_t optlen); + u8_t flags, u8_t apiflags, u8_t optflags); void tcp_rexmit_seg(struct tcp_pcb *pcb, struct tcp_seg *seg); @@ -614,22 +662,32 @@ extern struct tcp_pcb *tcp_tmp_pcb; /* Only used for temporary storage. */ } while(0) #else /* LWIP_DEBUG */ -#define TCP_REG(pcbs, npcb) do { \ - npcb->next = *pcbs; \ - *(pcbs) = npcb; \ - tcp_timer_needed(); \ - } while(0) -#define TCP_RMV(pcbs, npcb) do { \ - if(*(pcbs) == npcb) { \ - (*(pcbs)) = (*pcbs)->next; \ - } else for(tcp_tmp_pcb = *pcbs; tcp_tmp_pcb != NULL; tcp_tmp_pcb = tcp_tmp_pcb->next) { \ - if(tcp_tmp_pcb->next != NULL && tcp_tmp_pcb->next == npcb) { \ - tcp_tmp_pcb->next = npcb->next; \ - break; \ - } \ - } \ - npcb->next = NULL; \ - } while(0) + +#define TCP_REG(pcbs, npcb) \ + do { \ + npcb->next = *pcbs; \ + *(pcbs) = npcb; \ + tcp_timer_needed(); \ + } while (0) + +#define TCP_RMV(pcbs, npcb) \ + do { \ + if(*(pcbs) == npcb) { \ + (*(pcbs)) = (*pcbs)->next; \ + } \ + else { \ + for(tcp_tmp_pcb = *pcbs; \ + tcp_tmp_pcb != NULL; \ + tcp_tmp_pcb = tcp_tmp_pcb->next) { \ + if(tcp_tmp_pcb->next != NULL && tcp_tmp_pcb->next == npcb) { \ + tcp_tmp_pcb->next = npcb->next; \ + break; \ + } \ + } \ + } \ + npcb->next = NULL; \ + } while(0) + #endif /* LWIP_DEBUG */ #ifdef __cplusplus diff --git a/net/lwip/src/include/lwip/tcpip.h b/net/lwip/src/include/lwip/tcpip.h index 541d28ac68..75393ee911 100644 --- a/net/lwip/src/include/lwip/tcpip.h +++ b/net/lwip/src/include/lwip/tcpip.h @@ -41,6 +41,7 @@ #include "lwip/pbuf.h" #include "lwip/api.h" #include "lwip/sys.h" +#include "lwip/netif.h" #ifdef __cplusplus extern "C" { @@ -83,10 +84,14 @@ err_t tcpip_netifapi_lock(struct netifapi_msg *netifapimsg); #endif /* LWIP_NETIF_API */ err_t tcpip_callback_with_block(void (*f)(void *ctx), void *ctx, u8_t block); -#define tcpip_callback(f,ctx) tcpip_callback_with_block(f,ctx,1) +#define tcpip_callback(f, ctx) tcpip_callback_with_block(f, ctx, 1) + +/* free pbufs or heap memory from another context without blocking */ +err_t pbuf_free_callback(struct pbuf *p); +err_t mem_free_callback(void *m); err_t tcpip_timeout(u32_t msecs, sys_timeout_handler h, void *arg); -#define tcpip_untimeout(h, arg) tcpip_timeout(0xffffffff, h, arg) +err_t tcpip_untimeout(sys_timeout_handler h, void *arg); enum tcpip_msg_type { #if LWIP_NETCONN @@ -97,7 +102,8 @@ enum tcpip_msg_type { TCPIP_MSG_NETIFAPI, #endif /* LWIP_NETIF_API */ TCPIP_MSG_CALLBACK, - TCPIP_MSG_TIMEOUT + TCPIP_MSG_TIMEOUT, + TCPIP_MSG_UNTIMEOUT }; struct tcpip_msg { diff --git a/net/lwip/src/include/netif/etharp.h b/net/lwip/src/include/netif/etharp.h index 2b76823bb1..db691d91d2 100644 --- a/net/lwip/src/include/netif/etharp.h +++ b/net/lwip/src/include/netif/etharp.h @@ -151,6 +151,11 @@ void etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr, err_t etharp_output(struct netif *netif, struct pbuf *q, struct ip_addr *ipaddr); err_t etharp_query(struct netif *netif, struct ip_addr *ipaddr, struct pbuf *q); err_t etharp_request(struct netif *netif, struct ip_addr *ipaddr); +/** For Ethernet network interfaces, we might want to send "gratuitous ARP"; + * this is an ARP packet sent by a node in order to spontaneously cause other + * nodes to update an entry in their ARP cache. + * From RFC 3220 "IP Mobility Support for IPv4" section 4.6. */ +#define etharp_gratuitous(netif) etharp_request((netif), &(netif)->ip_addr) err_t ethernet_input(struct pbuf *p, struct netif *netif); diff --git a/net/lwip/src/include/netif/loopif.h b/net/lwip/src/include/netif/loopif.h index 68fc7b399a..304af4b39a 100644 --- a/net/lwip/src/include/netif/loopif.h +++ b/net/lwip/src/include/netif/loopif.h @@ -32,6 +32,7 @@ #ifndef __NETIF_LOOPIF_H__ #define __NETIF_LOOPIF_H__ +#include "lwip/opt.h" #include "lwip/netif.h" #include "lwip/err.h" @@ -39,9 +40,9 @@ extern "C" { #endif -#if !LWIP_LOOPIF_MULTITHREADING -void loopif_poll(struct netif *netif); -#endif +#if !LWIP_NETIF_LOOPBACK_MULTITHREADING +#define loopif_poll netif_poll +#endif /* !LWIP_NETIF_LOOPBACK_MULTITHREADING */ err_t loopif_init(struct netif *netif); |
