From c7e0fa715221e4fd973a717c12e68caf67b94403 Mon Sep 17 00:00:00 2001 From: Adam Dunkels Date: Thu, 12 Dec 2013 20:57:35 +0100 Subject: [PATCH 1/4] Moved #defines so that UIP_TCPIP_HLEN and UIP_LLH_LEN are defined before they are used --- core/net/uip.h | 76 +++++++++---------- core/net/uipopt.h | 190 +++++++++++++++++++++++----------------------- 2 files changed, 133 insertions(+), 133 deletions(-) diff --git a/core/net/uip.h b/core/net/uip.h index c4df7cff0..5805ebcd2 100644 --- a/core/net/uip.h +++ b/core/net/uip.h @@ -53,6 +53,44 @@ #ifndef UIP_H_ #define UIP_H_ +/* Header sizes. */ +#if UIP_CONF_IPV6 +#define UIP_IPH_LEN 40 +#define UIP_FRAGH_LEN 8 +#else /* UIP_CONF_IPV6 */ +#define UIP_IPH_LEN 20 /* Size of IP header */ +#endif /* UIP_CONF_IPV6 */ + +#define UIP_UDPH_LEN 8 /* Size of UDP header */ +#define UIP_TCPH_LEN 20 /* Size of TCP header */ +#ifdef UIP_IPH_LEN +#define UIP_ICMPH_LEN 4 /* Size of ICMP header */ +#endif +#define UIP_IPUDPH_LEN (UIP_UDPH_LEN + UIP_IPH_LEN) /* Size of IP + + * UDP + * header */ +#define UIP_IPTCPH_LEN (UIP_TCPH_LEN + UIP_IPH_LEN) /* Size of IP + + * TCP + * header */ +#define UIP_TCPIP_HLEN UIP_IPTCPH_LEN +#define UIP_IPICMPH_LEN (UIP_IPH_LEN + UIP_ICMPH_LEN) /* size of ICMP + + IP header */ +#define UIP_LLIPH_LEN (UIP_LLH_LEN + UIP_IPH_LEN) /* size of L2 + + IP header */ +#if UIP_CONF_IPV6 +/** + * The sums below are quite used in ND. When used for uip_buf, we + * include link layer length when used for uip_len, we do not, hence + * we need values with and without LLH_LEN we do not use capital + * letters as these values are variable + */ +#define uip_l2_l3_hdr_len (UIP_LLH_LEN + UIP_IPH_LEN + uip_ext_len) +#define uip_l2_l3_icmp_hdr_len (UIP_LLH_LEN + UIP_IPH_LEN + uip_ext_len + UIP_ICMPH_LEN) +#define uip_l3_hdr_len (UIP_IPH_LEN + uip_ext_len) +#define uip_l3_icmp_hdr_len (UIP_IPH_LEN + uip_ext_len + UIP_ICMPH_LEN) +#endif /*UIP_CONF_IPV6*/ + + #include "net/uipopt.h" /** @@ -1881,44 +1919,6 @@ struct uip_udp_hdr { #endif /* UIP_CONF_IPV6 */ -/* Header sizes. */ -#if UIP_CONF_IPV6 -#define UIP_IPH_LEN 40 -#define UIP_FRAGH_LEN 8 -#else /* UIP_CONF_IPV6 */ -#define UIP_IPH_LEN 20 /* Size of IP header */ -#endif /* UIP_CONF_IPV6 */ - -#define UIP_UDPH_LEN 8 /* Size of UDP header */ -#define UIP_TCPH_LEN 20 /* Size of TCP header */ -#ifdef UIP_IPH_LEN -#define UIP_ICMPH_LEN 4 /* Size of ICMP header */ -#endif -#define UIP_IPUDPH_LEN (UIP_UDPH_LEN + UIP_IPH_LEN) /* Size of IP + - * UDP - * header */ -#define UIP_IPTCPH_LEN (UIP_TCPH_LEN + UIP_IPH_LEN) /* Size of IP + - * TCP - * header */ -#define UIP_TCPIP_HLEN UIP_IPTCPH_LEN -#define UIP_IPICMPH_LEN (UIP_IPH_LEN + UIP_ICMPH_LEN) /* size of ICMP - + IP header */ -#define UIP_LLIPH_LEN (UIP_LLH_LEN + UIP_IPH_LEN) /* size of L2 - + IP header */ -#if UIP_CONF_IPV6 -/** - * The sums below are quite used in ND. When used for uip_buf, we - * include link layer length when used for uip_len, we do not, hence - * we need values with and without LLH_LEN we do not use capital - * letters as these values are variable - */ -#define uip_l2_l3_hdr_len (UIP_LLH_LEN + UIP_IPH_LEN + uip_ext_len) -#define uip_l2_l3_icmp_hdr_len (UIP_LLH_LEN + UIP_IPH_LEN + uip_ext_len + UIP_ICMPH_LEN) -#define uip_l3_hdr_len (UIP_IPH_LEN + uip_ext_len) -#define uip_l3_icmp_hdr_len (UIP_IPH_LEN + uip_ext_len + UIP_ICMPH_LEN) -#endif /*UIP_CONF_IPV6*/ - - #if UIP_FIXEDADDR CCIF extern const uip_ipaddr_t uip_hostaddr, uip_netmask, uip_draddr; #else /* UIP_FIXEDADDR */ diff --git a/core/net/uipopt.h b/core/net/uipopt.h index d496f4a42..55fff0ad1 100644 --- a/core/net/uipopt.h +++ b/core/net/uipopt.h @@ -132,6 +132,101 @@ */ #define UIP_FIXEDETHADDR 0 +/** @} */ +/*------------------------------------------------------------------------------*/ + +/** + * \defgroup uipoptgeneral General configuration options + * @{ + */ + +/** + * The link level header length. + * + * This is the offset into the uip_buf where the IP header can be + * found. For Ethernet, this should be set to 14. For SLIP, this + * should be set to 0. + * + * \note we probably won't use this constant for other link layers than + * ethernet as they have variable header length (this is due to variable + * number and type of address fields and to optional security features) + * E.g.: 802.15.4 -> 2 + (1/2*4/8) + 0/5/6/10/14 + * 802.11 -> 4 + (6*3/4) + 2 + * \hideinitializer + */ +#ifdef UIP_CONF_LLH_LEN +#define UIP_LLH_LEN (UIP_CONF_LLH_LEN) +#else /* UIP_LLH_LEN */ +#define UIP_LLH_LEN 14 +#endif /* UIP_CONF_LLH_LEN */ + +/** + * The size of the uIP packet buffer. + * + * The uIP packet buffer should not be smaller than 60 bytes, and does + * not need to be larger than 1514 bytes. Lower size results in lower + * TCP throughput, larger size results in higher TCP throughput. + * + * \hideinitializer + */ +#ifndef UIP_CONF_BUFFER_SIZE +#define UIP_BUFSIZE (UIP_LINK_MTU + UIP_LLH_LEN) +#else /* UIP_CONF_BUFFER_SIZE */ +#define UIP_BUFSIZE (UIP_CONF_BUFFER_SIZE) +#endif /* UIP_CONF_BUFFER_SIZE */ + + +/** + * Determines if statistics support should be compiled in. + * + * The statistics is useful for debugging and to show the user. + * + * \hideinitializer + */ +#ifndef UIP_CONF_STATISTICS +#define UIP_STATISTICS 0 +#else /* UIP_CONF_STATISTICS */ +#define UIP_STATISTICS (UIP_CONF_STATISTICS) +#endif /* UIP_CONF_STATISTICS */ + +/** + * Determines if logging of certain events should be compiled in. + * + * This is useful mostly for debugging. The function uip_log() + * must be implemented to suit the architecture of the project, if + * logging is turned on. + * + * \hideinitializer + */ +#ifndef UIP_CONF_LOGGING +#define UIP_LOGGING 0 +#else /* UIP_CONF_LOGGING */ +#define UIP_LOGGING (UIP_CONF_LOGGING) +#endif /* UIP_CONF_LOGGING */ + +/** + * Broadcast support. + * + * This flag configures IP broadcast support. This is useful only + * together with UDP. + * + * \hideinitializer + * + */ +#ifndef UIP_CONF_BROADCAST +#define UIP_BROADCAST 0 +#else /* UIP_CONF_BROADCAST */ +#define UIP_BROADCAST (UIP_CONF_BROADCAST) +#endif /* UIP_CONF_BROADCAST */ + +/** + * Print out a uIP log message. + * + * This function must be implemented by the module that uses uIP, and + * is called by uIP whenever a log message is generated. + */ +void uip_log(char *msg); + /** @} */ /*------------------------------------------------------------------------------*/ /** @@ -498,101 +593,6 @@ /** @} */ -/*------------------------------------------------------------------------------*/ - -/** - * \defgroup uipoptgeneral General configuration options - * @{ - */ - -/** - * The size of the uIP packet buffer. - * - * The uIP packet buffer should not be smaller than 60 bytes, and does - * not need to be larger than 1514 bytes. Lower size results in lower - * TCP throughput, larger size results in higher TCP throughput. - * - * \hideinitializer - */ -#ifndef UIP_CONF_BUFFER_SIZE -#define UIP_BUFSIZE (UIP_LINK_MTU + UIP_LLH_LEN) -#else /* UIP_CONF_BUFFER_SIZE */ -#define UIP_BUFSIZE (UIP_CONF_BUFFER_SIZE) -#endif /* UIP_CONF_BUFFER_SIZE */ - - -/** - * Determines if statistics support should be compiled in. - * - * The statistics is useful for debugging and to show the user. - * - * \hideinitializer - */ -#ifndef UIP_CONF_STATISTICS -#define UIP_STATISTICS 0 -#else /* UIP_CONF_STATISTICS */ -#define UIP_STATISTICS (UIP_CONF_STATISTICS) -#endif /* UIP_CONF_STATISTICS */ - -/** - * Determines if logging of certain events should be compiled in. - * - * This is useful mostly for debugging. The function uip_log() - * must be implemented to suit the architecture of the project, if - * logging is turned on. - * - * \hideinitializer - */ -#ifndef UIP_CONF_LOGGING -#define UIP_LOGGING 0 -#else /* UIP_CONF_LOGGING */ -#define UIP_LOGGING (UIP_CONF_LOGGING) -#endif /* UIP_CONF_LOGGING */ - -/** - * Broadcast support. - * - * This flag configures IP broadcast support. This is useful only - * together with UDP. - * - * \hideinitializer - * - */ -#ifndef UIP_CONF_BROADCAST -#define UIP_BROADCAST 0 -#else /* UIP_CONF_BROADCAST */ -#define UIP_BROADCAST (UIP_CONF_BROADCAST) -#endif /* UIP_CONF_BROADCAST */ - -/** - * Print out a uIP log message. - * - * This function must be implemented by the module that uses uIP, and - * is called by uIP whenever a log message is generated. - */ -void uip_log(char *msg); - -/** - * The link level header length. - * - * This is the offset into the uip_buf where the IP header can be - * found. For Ethernet, this should be set to 14. For SLIP, this - * should be set to 0. - * - * \note we probably won't use this constant for other link layers than - * ethernet as they have variable header length (this is due to variable - * number and type of address fields and to optional security features) - * E.g.: 802.15.4 -> 2 + (1/2*4/8) + 0/5/6/10/14 - * 802.11 -> 4 + (6*3/4) + 2 - * \hideinitializer - */ -#ifdef UIP_CONF_LLH_LEN -#define UIP_LLH_LEN (UIP_CONF_LLH_LEN) -#else /* UIP_LLH_LEN */ -#define UIP_LLH_LEN 14 -#endif /* UIP_CONF_LLH_LEN */ - -/** @} */ /*------------------------------------------------------------------------------*/ /** * \defgroup uipoptcpu CPU architecture configuration From c0b3c87ba757b949aadfe20c3fcbc701c3ce192b Mon Sep 17 00:00:00 2001 From: Adam Dunkels Date: Thu, 12 Dec 2013 22:20:09 +0100 Subject: [PATCH 2/4] Make 0 the default link-layer header length, as far as uIP is concerned. Most currently used linke layers (specifically, 802.15.4) has adaptation layers that use separate buffers, so there is no need to reserve space in the uIP buffer. --- core/net/uipopt.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/net/uipopt.h b/core/net/uipopt.h index 55fff0ad1..117fb20b5 100644 --- a/core/net/uipopt.h +++ b/core/net/uipopt.h @@ -157,7 +157,7 @@ #ifdef UIP_CONF_LLH_LEN #define UIP_LLH_LEN (UIP_CONF_LLH_LEN) #else /* UIP_LLH_LEN */ -#define UIP_LLH_LEN 14 +#define UIP_LLH_LEN 0 #endif /* UIP_CONF_LLH_LEN */ /** From ef83850e633c4089c45adf739585a597e512dc64 Mon Sep 17 00:00:00 2001 From: Adam Dunkels Date: Thu, 12 Dec 2013 22:20:20 +0100 Subject: [PATCH 3/4] Removed redundant #ifdef --- core/net/uip.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/net/uip.h b/core/net/uip.h index 5805ebcd2..3e3d959bc 100644 --- a/core/net/uip.h +++ b/core/net/uip.h @@ -63,9 +63,8 @@ #define UIP_UDPH_LEN 8 /* Size of UDP header */ #define UIP_TCPH_LEN 20 /* Size of TCP header */ -#ifdef UIP_IPH_LEN #define UIP_ICMPH_LEN 4 /* Size of ICMP header */ -#endif + #define UIP_IPUDPH_LEN (UIP_UDPH_LEN + UIP_IPH_LEN) /* Size of IP + * UDP * header */ From a6a081e67d334501ae0e32c5baa82127a151fd32 Mon Sep 17 00:00:00 2001 From: Adam Dunkels Date: Thu, 12 Dec 2013 22:43:10 +0100 Subject: [PATCH 4/4] Fixed a severe error in the bugfix: the conditional was reversed. The check must be if the TCP MSS is larger than the BUFSIZE and not the other way around. --- core/net/uipopt.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/net/uipopt.h b/core/net/uipopt.h index 117fb20b5..7708d205c 100644 --- a/core/net/uipopt.h +++ b/core/net/uipopt.h @@ -477,7 +477,7 @@ void uip_log(char *msg); * UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN. */ #ifdef UIP_CONF_TCP_MSS -#if UIP_CONF_TCP_MSS < (UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN) +#if UIP_CONF_TCP_MSS > (UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN) #error UIP_CONF_TCP_MSS is too large for the current UIP_BUFSIZE #endif /* UIP_CONF_TCP_MSS < (UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN) */ #define UIP_TCP_MSS (UIP_CONF_TCP_MSS)