From 252abbeb8d1f0bdf8e0d6dd18a4384fd845cac55 Mon Sep 17 00:00:00 2001 From: chrysn Date: Thu, 21 Nov 2013 08:37:39 +0100 Subject: [PATCH 01/12] make timeouts usable reliably from outside of the timeout routine although timeouts are relative to timeouts_last_time (transitively by addition to the time values of their predecessors, if there are any), sys_timeout does not compensate for that; as a result, timeouts fire too early unless invoked from within a timeout handler (when timeouts_last_time == now). --- src/core/timers.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/core/timers.c b/src/core/timers.c index c8ead4e7..23f8296b 100644 --- a/src/core/timers.c +++ b/src/core/timers.c @@ -326,16 +326,26 @@ sys_timeout(u32_t msecs, sys_timeout_handler handler, void *arg) #endif /* LWIP_DEBUG_TIMERNAMES */ { struct sys_timeo *timeout, *t; + u32_t now, diff; timeout = (struct sys_timeo *)memp_malloc(MEMP_SYS_TIMEOUT); if (timeout == NULL) { LWIP_ASSERT("sys_timeout: timeout != NULL, pool MEMP_SYS_TIMEOUT is empty", timeout != NULL); return; } + + now = sys_now(); + if (next_timeout == NULL) { + diff = 0; + timeouts_last_time = now; + } else { + diff = now - timeouts_last_time; + } + timeout->next = NULL; timeout->h = handler; timeout->arg = arg; - timeout->time = msecs; + timeout->time = msecs + diff; #if LWIP_DEBUG_TIMERNAMES timeout->handler_name = handler_name; LWIP_DEBUGF(TIMERS_DEBUG, ("sys_timeout: %p msecs=%"U32_F" handler=%s arg=%p\n", @@ -437,7 +447,7 @@ sys_check_timeouts(void) if (tmptimeout && (tmptimeout->time <= diff)) { /* timeout has expired */ had_one = 1; - timeouts_last_time = now; + timeouts_last_time += tmptimeout->time; diff -= tmptimeout->time; next_timeout = tmptimeout->next; handler = tmptimeout->h; From 51012d07cce2d76f28217b9e656f5e5d9100403d Mon Sep 17 00:00:00 2001 From: Simon Goldschmidt Date: Tue, 14 Jan 2014 21:27:40 +0100 Subject: [PATCH 02/12] updated CHANGELOG --- CHANGELOG | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 6ab1d5c1..8f40e408 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -80,6 +80,10 @@ HISTORY ++ Bugfixes: + 2014-01-14: chrysn + * timers.c: patch #8244 make timeouts usable reliably from outside of the + timeout routine + 2014-01-10: Simon Goldschmidt * ip_frag.c, ip6_frag.c: fixed bug #41041 Potential use-after-free in IPv6 reassembly From 2cf5eec62f9805792e56c30e88201a8de56f60f5 Mon Sep 17 00:00:00 2001 From: Simon Goldschmidt Date: Tue, 14 Jan 2014 21:32:45 +0100 Subject: [PATCH 03/12] patch by Thomas Faber: patch #8241: Fix implicit declaration of ip_input with LWIP_TCPIP_CORE_LOCKING_INPUT disabled --- CHANGELOG | 4 ++++ src/api/tcpip.c | 1 + 2 files changed, 5 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 8f40e408..e455f70f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -80,6 +80,10 @@ HISTORY ++ Bugfixes: + 2014-01-14: Simo Goldschmidt (patch by Thomas Faber) + * tcpip.c: patch #8241: Fix implicit declaration of ip_input with + LWIP_TCPIP_CORE_LOCKING_INPUT disabled + 2014-01-14: chrysn * timers.c: patch #8244 make timeouts usable reliably from outside of the timeout routine diff --git a/src/api/tcpip.c b/src/api/tcpip.c index 7c1c9cad..2c0032c2 100644 --- a/src/api/tcpip.c +++ b/src/api/tcpip.c @@ -46,6 +46,7 @@ #include "lwip/pbuf.h" #include "lwip/tcpip.h" #include "lwip/init.h" +#include "lwip/ip.h" #include "netif/etharp.h" #include "netif/ppp_oe.h" From 9975dbededf8878be8c059fc066bc89478477804 Mon Sep 17 00:00:00 2001 From: Simon Goldschmidt Date: Tue, 14 Jan 2014 21:48:58 +0100 Subject: [PATCH 04/12] Fixed chrysn's patch: it only works for NO_SYS :-( --- src/core/timers.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/core/timers.c b/src/core/timers.c index 23f8296b..94e8029a 100644 --- a/src/core/timers.c +++ b/src/core/timers.c @@ -326,7 +326,9 @@ sys_timeout(u32_t msecs, sys_timeout_handler handler, void *arg) #endif /* LWIP_DEBUG_TIMERNAMES */ { struct sys_timeo *timeout, *t; +#if NO_SYS u32_t now, diff; +#endif timeout = (struct sys_timeo *)memp_malloc(MEMP_SYS_TIMEOUT); if (timeout == NULL) { @@ -334,6 +336,7 @@ sys_timeout(u32_t msecs, sys_timeout_handler handler, void *arg) return; } +#if NO_SYS now = sys_now(); if (next_timeout == NULL) { diff = 0; @@ -341,11 +344,16 @@ sys_timeout(u32_t msecs, sys_timeout_handler handler, void *arg) } else { diff = now - timeouts_last_time; } +#endif timeout->next = NULL; timeout->h = handler; timeout->arg = arg; +#if NO_SYS timeout->time = msecs + diff; +#else + timeout->time = msecs; +#endif #if LWIP_DEBUG_TIMERNAMES timeout->handler_name = handler_name; LWIP_DEBUGF(TIMERS_DEBUG, ("sys_timeout: %p msecs=%"U32_F" handler=%s arg=%p\n", From a15b28a24e0781951e799fab06b002d0c2e30841 Mon Sep 17 00:00:00 2001 From: Simon Goldschmidt Date: Tue, 14 Jan 2014 21:49:33 +0100 Subject: [PATCH 05/12] SNMP: fixed typo: snmp_set_sysdesr -> snmp_set_sysdescr --- src/core/snmp/mib2.c | 2 +- src/include/lwip/snmp.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/snmp/mib2.c b/src/core/snmp/mib2.c index dcd3b62c..9e26ee64 100644 --- a/src/core/snmp/mib2.c +++ b/src/core/snmp/mib2.c @@ -933,7 +933,7 @@ void objectidncpy(s32_t *dst, s32_t *src, u8_t n) * @param str if non-NULL then copy str pointer * @param len points to string length, excluding zero terminator */ -void snmp_set_sysdesr(u8_t *str, u8_t *len) +void snmp_set_sysdescr(u8_t *str, u8_t *len) { if (str != NULL) { diff --git a/src/include/lwip/snmp.h b/src/include/lwip/snmp.h index 2ed043dd..4c1c9cd4 100644 --- a/src/include/lwip/snmp.h +++ b/src/include/lwip/snmp.h @@ -98,7 +98,7 @@ struct snmp_obj_id }; /* system */ -void snmp_set_sysdesr(u8_t* str, u8_t* len); +void snmp_set_sysdescr(u8_t* str, u8_t* len); void snmp_set_sysobjid(struct snmp_obj_id *oid); void snmp_get_sysobjid_ptr(struct snmp_obj_id **oid); void snmp_inc_sysuptime(void); @@ -231,7 +231,7 @@ void snmp_get_snmpenableauthentraps(u8_t *value); #else /* system */ -#define snmp_set_sysdesr(str, len) +#define snmp_set_sysdescr(str, len) #define snmp_set_sysobjid(oid); #define snmp_get_sysobjid_ptr(oid) #define snmp_inc_sysuptime() From e6202cfa972148e3417ad93d7c0547dfa5a9142e Mon Sep 17 00:00:00 2001 From: Freddie Chopin Date: Sat, 26 Oct 2013 19:22:11 +0200 Subject: [PATCH 06/12] SNMP: source of ocstrncpy() and objectidncpy() may be const Signed-off-by: Freddie Chopin --- src/core/snmp/mib2.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/snmp/mib2.c b/src/core/snmp/mib2.c index 9e26ee64..e8c94cc4 100644 --- a/src/core/snmp/mib2.c +++ b/src/core/snmp/mib2.c @@ -902,7 +902,7 @@ static u32_t snmpinpkts = 0, * @param src points to source * @param n number of octets to copy. */ -static void ocstrncpy(u8_t *dst, u8_t *src, u16_t n) +static void ocstrncpy(u8_t *dst, const u8_t *src, u16_t n) { u16_t i = n; while (i > 0) { @@ -918,7 +918,7 @@ static void ocstrncpy(u8_t *dst, u8_t *src, u16_t n) * @param src points to source * @param n number of sub identifiers to copy. */ -void objectidncpy(s32_t *dst, s32_t *src, u8_t n) +void objectidncpy(s32_t *dst, const s32_t *src, u8_t n) { u8_t i = n; while(i > 0) { From 4e1320d480625a79799bcc83657f2f8c0f9700a9 Mon Sep 17 00:00:00 2001 From: Freddie Chopin Date: Sat, 26 Oct 2013 19:27:25 +0200 Subject: [PATCH 07/12] SNMP: mib-2.system.sysDescr is read-only, so add const qualifiers to functions and pointers Signed-off-by: Freddie Chopin --- src/core/snmp/mib2.c | 6 +++--- src/include/lwip/snmp.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/core/snmp/mib2.c b/src/core/snmp/mib2.c index e8c94cc4..fe1bf6d7 100644 --- a/src/core/snmp/mib2.c +++ b/src/core/snmp/mib2.c @@ -772,8 +772,8 @@ static const s32_t sysservices = SNMP_SYSSERVICES; /** mib-2.system.sysDescr */ static const u8_t sysdescr_len_default = 4; static const u8_t sysdescr_default[] = "lwIP"; -static u8_t* sysdescr_len_ptr = (u8_t*)&sysdescr_len_default; -static u8_t* sysdescr_ptr = (u8_t*)&sysdescr_default[0]; +static const u8_t* sysdescr_len_ptr = &sysdescr_len_default; +static const u8_t* sysdescr_ptr = &sysdescr_default[0]; /** mib-2.system.sysContact */ static const u8_t syscontact_len_default = 0; static const u8_t syscontact_default[] = ""; @@ -933,7 +933,7 @@ void objectidncpy(s32_t *dst, const s32_t *src, u8_t n) * @param str if non-NULL then copy str pointer * @param len points to string length, excluding zero terminator */ -void snmp_set_sysdescr(u8_t *str, u8_t *len) +void snmp_set_sysdescr(const u8_t *str, const u8_t *len) { if (str != NULL) { diff --git a/src/include/lwip/snmp.h b/src/include/lwip/snmp.h index 4c1c9cd4..7844cc11 100644 --- a/src/include/lwip/snmp.h +++ b/src/include/lwip/snmp.h @@ -98,7 +98,7 @@ struct snmp_obj_id }; /* system */ -void snmp_set_sysdescr(u8_t* str, u8_t* len); +void snmp_set_sysdescr(const u8_t* str, const u8_t* len); void snmp_set_sysobjid(struct snmp_obj_id *oid); void snmp_get_sysobjid_ptr(struct snmp_obj_id **oid); void snmp_inc_sysuptime(void); From 2f9b28c0fc892183d8c1686795c6667cf64b5eea Mon Sep 17 00:00:00 2001 From: Simon Goldschmidt Date: Tue, 14 Jan 2014 21:53:40 +0100 Subject: [PATCH 08/12] Updated CHANGELOG --- CHANGELOG | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index e455f70f..efa5055c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -80,7 +80,10 @@ HISTORY ++ Bugfixes: - 2014-01-14: Simo Goldschmidt (patch by Thomas Faber) + 2014-01-14: "Freddie Chopin" + * snmp.h, mib2.c: fixed constness and spelling of sysdescr + + 2014-01-14: Simon Goldschmidt (patch by Thomas Faber) * tcpip.c: patch #8241: Fix implicit declaration of ip_input with LWIP_TCPIP_CORE_LOCKING_INPUT disabled From 08370c723092e7a8f5cbea3f063f460cb7530d26 Mon Sep 17 00:00:00 2001 From: Simon Goldschmidt Date: Thu, 16 Jan 2014 21:28:38 +0100 Subject: [PATCH 09/12] Patch #7904 by Grant Erickson: Add mnemonics for IPPROTO_{ICMP,ICMPV6} --- src/include/lwip/sockets.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/include/lwip/sockets.h b/src/include/lwip/sockets.h index 4d6e055a..853beea8 100644 --- a/src/include/lwip/sockets.h +++ b/src/include/lwip/sockets.h @@ -167,10 +167,12 @@ struct linger { #define PF_UNSPEC AF_UNSPEC #define IPPROTO_IP 0 +#define IPPROTO_ICMP 1 #define IPPROTO_TCP 6 #define IPPROTO_UDP 17 #if LWIP_IPV6 #define IPPROTO_IPV6 41 +#define IPPROTO_ICMPV6 58 #endif /* LWIP_IPV6 */ #define IPPROTO_UDPLITE 136 From 039737ffc2aaea0bfb136b36625fdc04e0a8ac12 Mon Sep 17 00:00:00 2001 From: Stathis Voukelatos Date: Wed, 12 Dec 2012 16:34:09 +0000 Subject: [PATCH 10/12] Fixed netif_poll() operation when LWIP_LOOPBACK_MAX_PBUFS > 0. Using the pbuf_clen() function to calculate the number of pbufs for the first packet in the queue is not correct here, as pbuf_clen() will return the total number of pbufs in the loopback I/F queue. --- src/core/netif.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/core/netif.c b/src/core/netif.c index e7a87c3c..068c3e5d 100644 --- a/src/core/netif.c +++ b/src/core/netif.c @@ -769,16 +769,22 @@ netif_poll(struct netif *netif) if (in != NULL) { struct pbuf *in_end = in; #if LWIP_LOOPBACK_MAX_PBUFS - u8_t clen = pbuf_clen(in); + u8_t clen = 1; +#endif /* LWIP_LOOPBACK_MAX_PBUFS */ + while (in_end->len != in_end->tot_len) { + LWIP_ASSERT("bogus pbuf: len != tot_len but next == NULL!", in_end->next != NULL); + in_end = in_end->next; +#if LWIP_LOOPBACK_MAX_PBUFS + clen++; +#endif /* LWIP_LOOPBACK_MAX_PBUFS */ + } +#if LWIP_LOOPBACK_MAX_PBUFS /* adjust the number of pbufs on queue */ LWIP_ASSERT("netif->loop_cnt_current underflow", ((netif->loop_cnt_current - clen) < netif->loop_cnt_current)); netif->loop_cnt_current -= clen; #endif /* LWIP_LOOPBACK_MAX_PBUFS */ - while (in_end->len != in_end->tot_len) { - LWIP_ASSERT("bogus pbuf: len != tot_len but next == NULL!", in_end->next != NULL); - in_end = in_end->next; - } + /* 'in_end' now points to the last pbuf from 'in' */ if (in_end == netif->loop_last) { /* this was the last pbuf in the list */ From 94eff945b46a537fcb435386b1858175300640df Mon Sep 17 00:00:00 2001 From: Simon Goldschmidt Date: Thu, 16 Jan 2014 21:42:10 +0100 Subject: [PATCH 11/12] Updated CHANGELOG --- CHANGELOG | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index efa5055c..8b9e502c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -80,6 +80,9 @@ HISTORY ++ Bugfixes: + 2014-01-16: Stathis Voukelatos + * netif.c: patch #7902 Fixed netif_poll() operation when LWIP_LOOPBACK_MAX_PBUFS > 0 + 2014-01-14: "Freddie Chopin" * snmp.h, mib2.c: fixed constness and spelling of sysdescr From 8b63a89267bdc538489575564c74b5f324021c1c Mon Sep 17 00:00:00 2001 From: Simon Goldschmidt Date: Thu, 16 Jan 2014 21:50:53 +0100 Subject: [PATCH 12/12] patch #7912 by Grant Erickson: Add a macro for introspecting the IPv6 loopback address. --- src/include/ipv6/lwip/ip6_addr.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/include/ipv6/lwip/ip6_addr.h b/src/include/ipv6/lwip/ip6_addr.h index 89b5b811..555f77c1 100644 --- a/src/include/ipv6/lwip/ip6_addr.h +++ b/src/include/ipv6/lwip/ip6_addr.h @@ -170,6 +170,10 @@ Little-endian version, stored in network order (no htonl). */ ((ip6addr)->addr[2] == 0) && \ ((ip6addr)->addr[3] == 0))) +#define ip6_addr_isloopback(ip6addr) (((ip6addr)->addr[0] == 0UL) && \ + ((ip6addr)->addr[1] == 0UL) && \ + ((ip6addr)->addr[2] == 0UL) && \ + ((ip6addr)->addr[3] == PP_HTONL(0x00000001UL))) #define ip6_addr_isglobal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xe0000000UL)) == PP_HTONL(0x20000000UL))