From 3d379c97ec66bef6c165f1c5bea18cf26724549a Mon Sep 17 00:00:00 2001 From: goldsimon Date: Wed, 3 Aug 2016 12:28:56 +0200 Subject: [PATCH 001/325] IPv6 is NOT experimental any more :-) --- src/core/ipv6/README | 1 - 1 file changed, 1 deletion(-) delete mode 100644 src/core/ipv6/README diff --git a/src/core/ipv6/README b/src/core/ipv6/README deleted file mode 100644 index 36200048..00000000 --- a/src/core/ipv6/README +++ /dev/null @@ -1 +0,0 @@ -IPv6 support in lwIP is very experimental. From da83946e759fe9d0b33f93758d7a40eb78c2ff5c Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Wed, 3 Aug 2016 12:32:03 +0200 Subject: [PATCH 002/325] Add one more documentation sentence in tcp.c --- src/core/tcp.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/core/tcp.c b/src/core/tcp.c index 37348281..dfda7965 100644 --- a/src/core/tcp.c +++ b/src/core/tcp.c @@ -1679,6 +1679,7 @@ tcp_sent(struct tcp_pcb *pcb, tcp_sent_fn sent) * @ingroup tcp_raw * Used to specify the function that should be called when a fatal error * has occurred on the connection. + * @note The corresponding pcb is already freed when this callback is called! * * @param pcb tcp_pcb to set the err callback * @param err callback function to call for this pcb when a fatal error From 4c06a737a4f56a7aa796a6608e1b9c569814eef0 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Wed, 3 Aug 2016 12:32:58 +0200 Subject: [PATCH 003/325] Add redirection page for HTML doxygen output so one does not have to search for index.html in the huge output/html directory --- .gitignore | 2 +- doc/doxygen/output/index.html | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 doc/doxygen/output/index.html diff --git a/.gitignore b/.gitignore index 0f13a3e8..0092ea6f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -/doc/doxygen/output +/doc/doxygen/output/html /src/apps/snmp/LwipMibCompiler/CCodeGeneration/bin/ /src/apps/snmp/LwipMibCompiler/CCodeGeneration/obj/ /src/apps/snmp/LwipMibCompiler/LwipMibCompiler/bin/ diff --git a/doc/doxygen/output/index.html b/doc/doxygen/output/index.html new file mode 100644 index 00000000..a52e09fc --- /dev/null +++ b/doc/doxygen/output/index.html @@ -0,0 +1,10 @@ + + + + Redirection + + + + index.html + + From dd110309e59ab939622cce638ccfbf447a1dbddf Mon Sep 17 00:00:00 2001 From: sg Date: Wed, 3 Aug 2016 20:21:54 +0200 Subject: [PATCH 004/325] update some FILES list files --- FILES | 1 + doc/FILES | 5 ++++- src/FILES | 6 ++++-- src/netif/FILES | 19 ++++++------------- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/FILES b/FILES index 66253196..e6e09989 100644 --- a/FILES +++ b/FILES @@ -1,4 +1,5 @@ src/ - The source code for the lwIP TCP/IP stack. doc/ - The documentation for lwIP. +test/ - Some code to test whether the sources do what they should. See also the FILES file in each subdirectory. diff --git a/doc/FILES b/doc/FILES index 05d356f4..e5885750 100644 --- a/doc/FILES +++ b/doc/FILES @@ -1,6 +1,9 @@ +doxygen/ - Configuration files and scripts to create the lwIP doxygen source + documentation (found at http://www.nongnu.org/lwip/) + savannah.txt - How to obtain the current development source code. contrib.txt - How to contribute to lwIP as a developer. rawapi.txt - The documentation for the core API of lwIP. Also provides an overview about the other APIs and multithreading. -snmp_agent.txt - The documentation for the lwIP SNMP agent. sys_arch.txt - The documentation for a system abstraction layer of lwIP. +ppp.txt - Documentation of the PPP interface for lwIP. diff --git a/src/FILES b/src/FILES index 952aeabb..0be0741d 100644 --- a/src/FILES +++ b/src/FILES @@ -1,13 +1,15 @@ api/ - The code for the high-level wrapper API. Not needed if you use the lowel-level call-back/raw API. +apps/ - Higher layer applications that are specifically programmed + with the lwIP low-level raw API. + core/ - The core of the TPC/IP stack; protocol implementations, memory and buffer management, and the low-level raw API. include/ - lwIP include files. -netif/ - Generic network interface device drivers are kept here, - as well as the ARP module. +netif/ - Generic network interface device drivers are kept here. For more information on the various subdirectories, check the FILES file in each directory. diff --git a/src/netif/FILES b/src/netif/FILES index 501edac3..a3ff431d 100644 --- a/src/netif/FILES +++ b/src/netif/FILES @@ -2,30 +2,23 @@ This directory contains generic network interface device drivers that do not contain any hardware or architecture specific code. The files are: -etharp.c - Implements the ARP (Address Resolution Protocol) over - Ethernet. The code in this file should be used together with - Ethernet device drivers. Note that this module has been - largely made Ethernet independent so you should be able to - adapt this for other link layers (such as Firewire). +ethernet.c + Shared code for Ethernet based interfaces. ethernetif.c An example of how an Ethernet device driver could look. This file can be used as a "skeleton" for developing new Ethernet network device drivers. It uses the etharp.c ARP code. -loopif.c - A "loopback" network interface driver. It requires configuration - through the define LWIP_LOOPIF_MULTITHREADING (see opt.h). +lowpan6.c + A 6LoWPAN implementation as a netif. slipif.c A generic implementation of the SLIP (Serial Line IP) protocol. It requires a sio (serial I/O) module to work. -lowpan6.c - 6LoWPAN implementation - ppp/ Point-to-Point Protocol stack The lwIP PPP support is based from pppd (http://ppp.samba.org) with huge changes to match code size and memory requirements for embedded - devices. Please read ppp/PPPD_FOLLOWUP for a detailed explanation. + devices. Please read /doc/ppp.txt and ppp/PPPD_FOLLOWUP for a detailed + explanation. From 6383ef88b4938ffce67c2390c7d4f7753cf4d06d Mon Sep 17 00:00:00 2001 From: sg Date: Wed, 3 Aug 2016 20:40:52 +0200 Subject: [PATCH 005/325] had a look through the docs... --- UPGRADING | 1 + doc/sys_arch.txt | 66 +++++++++++++++++++++++++++++++++++++----------- 2 files changed, 52 insertions(+), 15 deletions(-) diff --git a/UPGRADING b/UPGRADING index f44fb487..cfd90f33 100644 --- a/UPGRADING +++ b/UPGRADING @@ -68,6 +68,7 @@ with newer versions. * Added IPv6 support (dual-stack or IPv4/IPv6 only) * Major rewrite of PPP (incl. keep-up with apache pppd) + see doc/ppp.txt for an upgrading how-to * Major rewrite of SNMP (incl. MIB parser) * Fixed timing issues that might have lead to losing a DHCP lease * Made rx processing path more robust against crafted errors diff --git a/doc/sys_arch.txt b/doc/sys_arch.txt index 847cd777..333946da 100644 --- a/doc/sys_arch.txt +++ b/doc/sys_arch.txt @@ -1,6 +1,7 @@ -sys_arch interface for lwIP 0.6++ +sys_arch interface for lwIP Author: Adam Dunkels + Simon Goldschmidt The operating system emulation layer provides a common interface between the lwIP code and the underlying operating system kernel. The @@ -9,12 +10,11 @@ small changes to a few header files and a new sys_arch implementation. It is also possible to do a sys_arch implementation that does not rely on any underlying operating system. -The sys_arch provides semaphores and mailboxes to lwIP. For the full +The sys_arch provides semaphores, mailboxes and mutexes to lwIP. For the full lwIP functionality, multiple threads support can be implemented in the sys_arch, but this is not required for the basic lwIP -functionality. Previous versions of lwIP required the sys_arch to -implement timer scheduling as well but as of lwIP 0.5 this is -implemented in a higher layer. +functionality. Timer scheduling is implemented in lwIP, but can be implemented +by the sys_arch port (LWIP_TIMERS_CUSTOM==1). In addition to the source file providing the functionality of sys_arch, the OS emulation layer must provide several header files defining @@ -22,19 +22,18 @@ macros used throughout lwip. The files required and the macros they must define are listed below the sys_arch description. Semaphores can be either counting or binary - lwIP works with both -kinds. Mailboxes are used for message passing and can be implemented -either as a queue which allows multiple messages to be posted to a -mailbox, or as a rendez-vous point where only one message can be -posted at a time. lwIP works with both kinds, but the former type will -be more efficient. A message in a mailbox is just a pointer, nothing -more. +kinds. Mailboxes should be implemented as a queue which allows multiple messages +to be posted (implementing as a rendez-vous point where only one message can be +posted at a time can have a highly negative impact on performance). A message +in a mailbox is just a pointer, nothing more. Semaphores are represented by the type "sys_sem_t" which is typedef'd in the sys_arch.h file. Mailboxes are equivalently represented by the -type "sys_mbox_t". lwIP does not place any restrictions on how -sys_sem_t or sys_mbox_t are represented internally. +type "sys_mbox_t". Mutexes are represented ny the type "sys_mutex_t". +lwIP does not place any restrictions on how these types are represented +internally. -Since lwIP 1.4.0, semaphore and mailbox functions are prototyped in a way that +Since lwIP 1.4.0, semaphore, mutexes and mailbox functions are prototyped in a way that allows both using pointers or actual OS structures to be used. This way, memory required for such types can be either allocated in place (globally or on the stack) or on the heap (allocated internally in the "*_new()" functions). @@ -94,6 +93,40 @@ The following functions must be implemented by the sys_arch: sys_sem_free() is always called before calling this function! This may also be a define, in which case the function is not prototyped. +- void sys_mutex_new(sys_mutex_t *mutex) + + Creates a new mutex. The mutex is allocated to the memory that 'mutex' + points to (which can be both a pointer or the actual OS structure). + If the mutex has been created, ERR_OK should be returned. Returning any + other error will provide a hint what went wrong, but except for assertions, + no real error handling is implemented. + +- void sys_mutex_free(sys_mutex_t *mutex) + + Deallocates a mutex. + +- void sys_mutex_lock(sys_mutex_t *mutex) + + Blocks the thread until the mutex can be grabbed. + +- void sys_mutex_unlock(sys_mutex_t *mutex) + + Releases the mutex previously locked through 'sys_mutex_lock()'. + +- void sys_mutex_valid(sys_mutex_t *mutex) + + Returns 1 if the mutes is valid, 0 if it is not valid. + When using pointers, a simple way is to check the pointer for != NULL. + When directly using OS structures, implementing this may be more complex. + This may also be a define, in which case the function is not prototyped. + +- void sys_mutex_set_invalid(sys_mutex_t *mutex) + + Invalidate a mutex so that sys_mutex_valid() returns 0. + ATTENTION: This does NOT mean that the mutex shall be deallocated: + sys_mutex_free() is always called before calling this function! + This may also be a define, in which case the function is not prototyped. + - err_t sys_mbox_new(sys_mbox_t *mbox, int size) Creates an empty mailbox for maximum "size" elements. Elements stored @@ -176,6 +209,9 @@ to be implemented as well: the "stacksize" parameter. The id of the new thread is returned. Both the id and the priority are system dependent. +When lwIP is used from more than one context (e.g. from multiple threads OR from +main-loop and from interrupts), the SYS_LIGHTWEIGHT_PROT protection SHOULD be enabled! + - sys_prot_t sys_arch_protect(void) This optional function does a "fast" critical region protection and returns @@ -209,7 +245,7 @@ For some configurations, you also need: Note: -Be carefull with using mem_malloc() in sys_arch. When malloc() refers to +Be careful with using mem_malloc() in sys_arch. When malloc() refers to mem_malloc() you can run into a circular function call problem. In mem.c mem_init() tries to allcate a semaphore using mem_malloc, which of course can't be performed when sys_arch uses mem_malloc. From 02221cf5dc19580d7a7fb2ab5209ce87027dc110 Mon Sep 17 00:00:00 2001 From: David van Moolenbroek Date: Sat, 30 Jul 2016 13:09:00 +0000 Subject: [PATCH 006/325] Rename IP_HDRINCL to LWIP_IP_HDRINCL In the BSD socket API world, IP_HDRINCL is a socket option for "raw" sockets that indicates whether sent packets already include an IP header. Within lwIP, "IP_HDRINCL" is redefined as a special value that indicates to lwIP-internal functions that an IP header is already included. While somewhat related, the two meanings are different and, on platforms that define the IP_HDRINCL socket option, this results in a conflict. This patch renames the lwIP one to "LWIP_IP_HDRINCL", thus resolving the conflict. --- src/core/ipv4/icmp.c | 2 +- src/core/ipv4/igmp.c | 4 ++-- src/core/ipv4/ip4.c | 18 +++++++++--------- src/core/ipv6/ip6.c | 18 +++++++++--------- src/include/lwip/ip.h | 5 +---- 5 files changed, 22 insertions(+), 25 deletions(-) diff --git a/src/core/ipv4/icmp.c b/src/core/ipv4/icmp.c index d6348d89..e60e4481 100644 --- a/src/core/ipv4/icmp.c +++ b/src/core/ipv4/icmp.c @@ -236,7 +236,7 @@ icmp_input(struct pbuf *p, struct netif *inp) MIB2_STATS_INC(mib2.icmpoutechoreps); /* send an ICMP packet */ - ret = ip4_output_if(p, src, IP_HDRINCL, + ret = ip4_output_if(p, src, LWIP_IP_HDRINCL, ICMP_TTL, 0, IP_PROTO_ICMP, inp); if (ret != ERR_OK) { LWIP_DEBUGF(ICMP_DEBUG, ("icmp_input: ip_output_if returned an error: %s\n", lwip_strerr(ret))); diff --git a/src/core/ipv4/igmp.c b/src/core/ipv4/igmp.c index 50c5d9d0..089a7611 100644 --- a/src/core/ipv4/igmp.c +++ b/src/core/ipv4/igmp.c @@ -765,8 +765,8 @@ igmp_delaying_member(struct igmp_group *group, u8_t maxresp) * the IP address of the outgoing network interface is filled in as source address. * * @param p the packet to send (p->payload points to the data, e.g. next - protocol header; if dest == IP_HDRINCL, p already includes an IP - header and p->payload points to that IP header) + protocol header; if dest == LWIP_IP_HDRINCL, p already includes an + IP header and p->payload points to that IP header) * @param src the source IP address to send from (if src == IP_ADDR_ANY, the * IP address of the netif used to send is used as source address) * @param dest the destination IP address to send the packet to diff --git a/src/core/ipv4/ip4.c b/src/core/ipv4/ip4.c index 1bdc30f5..0dba2dc2 100644 --- a/src/core/ipv4/ip4.c +++ b/src/core/ipv4/ip4.c @@ -716,12 +716,12 @@ ip4_input(struct pbuf *p, struct netif *inp) * the IP header and calculates the IP header checksum. If the source * IP address is NULL, the IP address of the outgoing network * interface is filled in as source address. - * If the destination IP address is IP_HDRINCL, p is assumed to already + * If the destination IP address is LWIP_IP_HDRINCL, p is assumed to already * include an IP header and p->payload points to it instead of the data. * * @param p the packet to send (p->payload points to the data, e.g. next - protocol header; if dest == IP_HDRINCL, p already includes an IP - header and p->payload points to that IP header) + protocol header; if dest == LWIP_IP_HDRINCL, p already includes an + IP header and p->payload points to that IP header) * @param src the source IP address to send from (if src == IP_ADDR_ANY, the * IP address of the netif used to send is used as source address) * @param dest the destination IP address to send the packet to @@ -758,7 +758,7 @@ ip4_output_if_opt(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest, { #endif /* IP_OPTIONS_SEND */ const ip4_addr_t *src_used = src; - if (dest != IP_HDRINCL) { + if (dest != LWIP_IP_HDRINCL) { if (ip4_addr_isany(src)) { src_used = netif_ip4_addr(netif); } @@ -806,7 +806,7 @@ ip4_output_if_opt_src(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *d MIB2_STATS_INC(mib2.ipoutrequests); /* Should the IP header be generated or is it already included in p? */ - if (dest != IP_HDRINCL) { + if (dest != LWIP_IP_HDRINCL) { u16_t ip_hlen = IP_HLEN; #if IP_OPTIONS_SEND u16_t optlen_aligned = 0; @@ -951,8 +951,8 @@ ip4_output_if_opt_src(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *d * interface and calls upon ip_output_if to do the actual work. * * @param p the packet to send (p->payload points to the data, e.g. next - protocol header; if dest == IP_HDRINCL, p already includes an IP - header and p->payload points to that IP header) + protocol header; if dest == LWIP_IP_HDRINCL, p already includes an + IP header and p->payload points to that IP header) * @param src the source IP address to send from (if src == IP_ADDR_ANY, the * IP address of the netif used to send is used as source address) * @param dest the destination IP address to send the packet to @@ -986,8 +986,8 @@ ip4_output(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest, * before calling ip_output_if. * * @param p the packet to send (p->payload points to the data, e.g. next - protocol header; if dest == IP_HDRINCL, p already includes an IP - header and p->payload points to that IP header) + protocol header; if dest == LWIP_IP_HDRINCL, p already includes an + IP header and p->payload points to that IP header) * @param src the source IP address to send from (if src == IP_ADDR_ANY, the * IP address of the netif used to send is used as source address) * @param dest the destination IP address to send the packet to diff --git a/src/core/ipv6/ip6.c b/src/core/ipv6/ip6.c index 3f604dfd..650e5af7 100644 --- a/src/core/ipv6/ip6.c +++ b/src/core/ipv6/ip6.c @@ -781,11 +781,11 @@ ip6_input_cleanup: * used as source (usually during network startup). If the source IPv6 address it * IP6_ADDR_ANY, the most appropriate IPv6 address of the outgoing network * interface is filled in as source address. If the destination IPv6 address is - * IP_HDRINCL, p is assumed to already include an IPv6 header and p->payload points - * to it instead of the data. + * LWIP_IP_HDRINCL, p is assumed to already include an IPv6 header and + * p->payload points to it instead of the data. * * @param p the packet to send (p->payload points to the data, e.g. next - protocol header; if dest == IP_HDRINCL, p already includes an + protocol header; if dest == LWIP_IP_HDRINCL, p already includes an IPv6 header and p->payload points to that IPv6 header) * @param src the source IPv6 address to send from (if src == IP6_ADDR_ANY, an * IP address of the netif is selected and used as source address. @@ -805,7 +805,7 @@ ip6_output_if(struct pbuf *p, const ip6_addr_t *src, const ip6_addr_t *dest, u8_t nexth, struct netif *netif) { const ip6_addr_t *src_used = src; - if (dest != IP_HDRINCL) { + if (dest != LWIP_IP_HDRINCL) { if (src != NULL && ip6_addr_isany(src)) { src = ip_2_ip6(ip6_select_source_address(netif, dest)); if ((src == NULL) || ip6_addr_isany(src)) { @@ -834,7 +834,7 @@ ip6_output_if_src(struct pbuf *p, const ip6_addr_t *src, const ip6_addr_t *dest, LWIP_IP_CHECK_PBUF_REF_COUNT_FOR_TX(p); /* Should the IPv6 header be generated or is it already included in p? */ - if (dest != IP_HDRINCL) { + if (dest != LWIP_IP_HDRINCL) { /* generate IPv6 header */ if (pbuf_header(p, IP6_HLEN)) { LWIP_DEBUGF(IP6_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("ip6_output: not enough room for IPv6 header in pbuf\n")); @@ -907,7 +907,7 @@ ip6_output_if_src(struct pbuf *p, const ip6_addr_t *src, const ip6_addr_t *dest, * interface and calls upon ip6_output_if to do the actual work. * * @param p the packet to send (p->payload points to the data, e.g. next - protocol header; if dest == IP_HDRINCL, p already includes an + protocol header; if dest == LWIP_IP_HDRINCL, p already includes an IPv6 header and p->payload points to that IPv6 header) * @param src the source IPv6 address to send from (if src == IP6_ADDR_ANY, an * IP address of the netif is selected and used as source address. @@ -930,7 +930,7 @@ ip6_output(struct pbuf *p, const ip6_addr_t *src, const ip6_addr_t *dest, LWIP_IP_CHECK_PBUF_REF_COUNT_FOR_TX(p); - if (dest != IP_HDRINCL) { + if (dest != LWIP_IP_HDRINCL) { netif = ip6_route(src, dest); } else { /* IP header included in p, read addresses. */ @@ -963,7 +963,7 @@ ip6_output(struct pbuf *p, const ip6_addr_t *src, const ip6_addr_t *dest, * before calling ip6_output_if. * * @param p the packet to send (p->payload points to the data, e.g. next - protocol header; if dest == IP_HDRINCL, p already includes an + protocol header; if dest == LWIP_IP_HDRINCL, p already includes an IPv6 header and p->payload points to that IPv6 header) * @param src the source IPv6 address to send from (if src == IP6_ADDR_ANY, an * IP address of the netif is selected and used as source address. @@ -989,7 +989,7 @@ ip6_output_hinted(struct pbuf *p, const ip6_addr_t *src, const ip6_addr_t *dest, LWIP_IP_CHECK_PBUF_REF_COUNT_FOR_TX(p); - if (dest != IP_HDRINCL) { + if (dest != LWIP_IP_HDRINCL) { netif = ip6_route(src, dest); } else { /* IP header included in p, read addresses. */ diff --git a/src/include/lwip/ip.h b/src/include/lwip/ip.h index 772a4c0c..09394320 100644 --- a/src/include/lwip/ip.h +++ b/src/include/lwip/ip.h @@ -63,10 +63,7 @@ extern "C" { /* This is passed as the destination address to ip_output_if (not to ip_output), meaning that an IP header already is constructed in the pbuf. This is used when TCP retransmits. */ -#ifdef IP_HDRINCL -#undef IP_HDRINCL -#endif /* IP_HDRINCL */ -#define IP_HDRINCL NULL +#define LWIP_IP_HDRINCL NULL /** pbufs passed to IP must have a ref-count of 1 as their payload pointer gets altered as the packet is passed down the stack */ From 5f774270b656c450dca9661e73cea822232387fb Mon Sep 17 00:00:00 2001 From: sg Date: Wed, 3 Aug 2016 21:25:32 +0200 Subject: [PATCH 007/325] minor: tabs -> spaces --- src/core/ipv6/nd6.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/ipv6/nd6.c b/src/core/ipv6/nd6.c index af17aeaf..cefd013d 100644 --- a/src/core/ipv6/nd6.c +++ b/src/core/ipv6/nd6.c @@ -738,7 +738,7 @@ nd6_tmr(void) /* Process prefix entries. */ for (i = 0; i < LWIP_ND6_NUM_PREFIXES; i++) { - if (prefix_list[i].netif != NULL) { + if (prefix_list[i].netif != NULL) { if (prefix_list[i].invalidation_timer < ND6_TMR_INTERVAL / 1000) { /* Entry timed out, remove it */ prefix_list[i].invalidation_timer = 0; @@ -795,7 +795,7 @@ nd6_tmr(void) } #endif /* LWIP_IPV6_AUTOCONFIG */ } - } + } } From bae67915ab97db3f50a5d136fe81b897c70e7b08 Mon Sep 17 00:00:00 2001 From: Sylvain Rochet Date: Thu, 4 Aug 2016 22:06:45 +0200 Subject: [PATCH 008/325] PPP: fix dead phase set too early When we are disconnecting, we should switch to PPP dead phase at the very end, because this is our final disconnection phase allowing reconnect, therefore we should switch to dead phase after the link protocol finished disconnecting. We are currently switching to dead phase when LCP detected that the link is down, this is obviously wrong. Fix this flaw by continuing in disconnect phase until ppp_link_end is called from link protocol. --- src/netif/ppp/auth.c | 1 - src/netif/ppp/ppp.c | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/netif/ppp/auth.c b/src/netif/ppp/auth.c index 6e80352c..3c8bc79f 100644 --- a/src/netif/ppp/auth.c +++ b/src/netif/ppp/auth.c @@ -639,7 +639,6 @@ void link_terminated(ppp_pcb *pcb) { lcp_lowerdown(pcb); - new_phase(pcb, PPP_PHASE_DEAD); ppp_link_terminated(pcb); #if 0 /* diff --git a/src/netif/ppp/ppp.c b/src/netif/ppp/ppp.c index d5e317cb..4d14bba3 100644 --- a/src/netif/ppp/ppp.c +++ b/src/netif/ppp/ppp.c @@ -746,6 +746,7 @@ void ppp_link_failed(ppp_pcb *pcb) { /** Called when link is normally down (i.e. it was asked to end) */ void ppp_link_end(ppp_pcb *pcb) { PPPDEBUG(LOG_DEBUG, ("ppp_link_end[%d]\n", pcb->netif->num)); + new_phase(pcb, PPP_PHASE_DEAD); if (pcb->err_code == PPPERR_NONE) { pcb->err_code = PPPERR_CONNECT; } From e8d8c5dcc9b3ba42a96e70b49e1cd67ee1977b3b Mon Sep 17 00:00:00 2001 From: Sylvain Rochet Date: Thu, 4 Aug 2016 23:03:03 +0200 Subject: [PATCH 009/325] PPP, L2TP: remove useless L2TP state conditions L2TP state can't be anything else than initial state in pppol2tp_connect, this function is called from PPP core only when PPP is in the dead phase, if PPP is in the dead phase it means the link protocol is dead as well. L2TP can't be anything else than data phase in pppol2tp_xmit, this function is only called by pppol2tp_write and pppol2tp_netif_output which are both called by PPP core only when PPP session is up, if PPP session is UP it means the link protocol is UP as well. L2TP can't be anything else than data phase in pppol2tp_disconnect, this function is only called by PPP core only when PPP session is up, if PPP session is UP it means the link protocol is UP as well. --- src/netif/ppp/pppol2tp.c | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/src/netif/ppp/pppol2tp.c b/src/netif/ppp/pppol2tp.c index ae5be762..877f84dc 100644 --- a/src/netif/ppp/pppol2tp.c +++ b/src/netif/ppp/pppol2tp.c @@ -262,10 +262,6 @@ static err_t pppol2tp_connect(ppp_pcb *ppp, void *ctx) { ipcp_options *ipcp_ao; #endif /* PPP_IPV4_SUPPORT && VJ_SUPPORT */ - if (l2tp->phase != PPPOL2TP_STATE_INITIAL) { - return ERR_VAL; - } - pppol2tp_clear(l2tp); ppp_link_start(ppp); @@ -328,10 +324,6 @@ static err_t pppol2tp_connect(ppp_pcb *ppp, void *ctx) { static void pppol2tp_disconnect(ppp_pcb *ppp, void *ctx) { pppol2tp_pcb *l2tp = (pppol2tp_pcb *)ctx; - if (l2tp->phase < PPPOL2TP_STATE_DATA) { - return; - } - l2tp->our_ns++; pppol2tp_send_stopccn(l2tp, l2tp->our_ns); @@ -346,6 +338,7 @@ static void pppol2tp_input(void *arg, struct udp_pcb *pcb, struct pbuf *p, const u8_t *inp; LWIP_UNUSED_ARG(pcb); + /* we can't unbound a UDP pcb, thus we can still receive UDP frames after the link is closed */ if (l2tp->phase < PPPOL2TP_STATE_SCCRQ_SENT) { goto free_and_return; } @@ -1113,12 +1106,6 @@ static err_t pppol2tp_send_stopccn(pppol2tp_pcb *l2tp, u16_t ns) { static err_t pppol2tp_xmit(pppol2tp_pcb *l2tp, struct pbuf *pb) { u8_t *p; - /* are we ready to process data yet? */ - if (l2tp->phase < PPPOL2TP_STATE_DATA) { - pbuf_free(pb); - return ERR_CONN; - } - /* make room for L2TP header - should not fail */ if (pbuf_header(pb, (s16_t)PPPOL2TP_OUTPUT_DATA_HEADER_LEN) != 0) { /* bail out */ From 9b47b6393b1f3f593a69a96e1acd95faba27459a Mon Sep 17 00:00:00 2001 From: Sylvain Rochet Date: Thu, 4 Aug 2016 23:06:30 +0200 Subject: [PATCH 010/325] PPP, PPPoE: remove useless PPPoE state conditions sc->sc_ethif can't be NULL, it is set definitively in pppoe_create. PPPoE can't by anything else than PADI sent in pppoe_send_padi, it is only called when this is true. PPPoE state can't be anything else than initial state in pppoe_connect, this function is called from PPP core only when PPP is in the dead phase, if PPP is in the dead phase it means the link protocol is dead as well. PPPoE can't be anything else than data phase in pppoe_disconnect this function is only called by PPP core only when PPP session is up, if PPP session is UP it means the link protocol is UP as well. PPPoE can't by anything else than PADR sent in pppoe_send_padr, it is only called when this is true. PPPoE can't by anything else than PADO sent in pppoe_send_pado, it is only called when this is true. PPPoE can't by anything else than PADO sent in pppoe_send_pads, it is only called when this is true. PPPoE can't be anything else than session phase in pppoe_xmit, function is only called by pppoe_write and pppoe_netif_output which are both called by PPP core only when PPP session is up, if PPP session is UP it means the link protocol is UP as well. --- src/netif/ppp/pppoe.c | 36 ------------------------------------ 1 file changed, 36 deletions(-) diff --git a/src/netif/ppp/pppoe.c b/src/netif/ppp/pppoe.c index 348129ac..26220ffe 100644 --- a/src/netif/ppp/pppoe.c +++ b/src/netif/ppp/pppoe.c @@ -731,11 +731,6 @@ pppoe_output(struct pppoe_softc *sc, struct pbuf *pb) u16_t etype; err_t res; - if (!sc->sc_ethif) { - pbuf_free(pb); - return ERR_IF; - } - /* make room for Ethernet header - should not fail */ if (pbuf_header(pb, (s16_t)(sizeof(struct eth_hdr))) != 0) { /* bail out */ @@ -773,10 +768,6 @@ pppoe_send_padi(struct pppoe_softc *sc) int l1 = 0, l2 = 0; /* XXX: gcc */ #endif /* PPPOE_TODO */ - if (sc->sc_state >PPPOE_STATE_PADI_SENT) { - PPPDEBUG(LOG_ERR, ("ERROR: pppoe_send_padi in state %d", sc->sc_state)); - } - /* calculate length of frame (excluding ethernet header + pppoe header) */ len = 2 + 2 + 2 + 2 + sizeof sc; /* service name tag is required, host unique is send too */ #ifdef PPPOE_TODO @@ -909,10 +900,6 @@ pppoe_connect(ppp_pcb *ppp, void *ctx) ipcp_options *ipcp_ao; #endif /* PPP_IPV4_SUPPORT && VJ_SUPPORT */ - if (sc->sc_state != PPPOE_STATE_INITIAL) { - return EBUSY; - } - /* stop any timer */ sys_untimeout(pppoe_timeout, sc); sc->sc_session = 0; @@ -966,10 +953,6 @@ pppoe_disconnect(ppp_pcb *ppp, void *ctx) { struct pppoe_softc *sc = (struct pppoe_softc *)ctx; - if (sc->sc_state < PPPOE_STATE_SESSION) { - return; - } - PPPDEBUG(LOG_DEBUG, ("pppoe: %c%c%"U16_F": disconnecting\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num)); pppoe_send_padt(sc->sc_ethif, sc->sc_session, (const u8_t *)&sc->sc_dest); @@ -1020,10 +1003,6 @@ pppoe_send_padr(struct pppoe_softc *sc) size_t l1 = 0; /* XXX: gcc */ #endif /* PPPOE_TODO */ - if (sc->sc_state != PPPOE_STATE_PADR_SENT) { - return ERR_CONN; - } - len = 2 + 2 + 2 + 2 + sizeof(sc); /* service name, host unique */ #ifdef PPPOE_TODO if (sc->sc_service_name != NULL) { /* service name tag maybe empty */ @@ -1106,10 +1085,6 @@ pppoe_send_pado(struct pppoe_softc *sc) u8_t *p; size_t len; - if (sc->sc_state != PPPOE_STATE_PADO_SENT) { - return ERR_CONN; - } - /* calc length */ len = 0; /* include ac_cookie */ @@ -1140,10 +1115,6 @@ pppoe_send_pads(struct pppoe_softc *sc) u8_t *p; size_t len, l1 = 0; /* XXX: gcc */ - if (sc->sc_state != PPPOE_STATE_PADO_SENT) { - return ERR_CONN; - } - sc->sc_session = mono_time.tv_sec % 0xff + 1; /* calc length */ len = 0; @@ -1181,13 +1152,6 @@ pppoe_xmit(struct pppoe_softc *sc, struct pbuf *pb) u8_t *p; size_t len; - /* are we ready to process data yet? */ - if (sc->sc_state < PPPOE_STATE_SESSION) { - /*sppp_flush(&sc->sc_sppp.pp_if);*/ - pbuf_free(pb); - return ERR_CONN; - } - len = pb->tot_len; /* make room for PPPoE header - should not fail */ From 01561b26efad0218cf0f2fee60738039ca2ee038 Mon Sep 17 00:00:00 2001 From: Sylvain Rochet Date: Thu, 4 Aug 2016 23:43:46 +0200 Subject: [PATCH 011/325] PPP: set phase to establish before starting LCP PPP is currently in initialize phase until authentication is started or until we start IPCP negotiation. It works, because PPP states are mostly used for user information, most state are actually useless for PPP itself. Being in initialize state while PPP is started is not very consistent, switch to establish phase before starting LCP. --- src/netif/ppp/ppp.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/netif/ppp/ppp.c b/src/netif/ppp/ppp.c index 4d14bba3..96bcd8b1 100644 --- a/src/netif/ppp/ppp.c +++ b/src/netif/ppp/ppp.c @@ -730,6 +730,7 @@ void ppp_start(ppp_pcb *pcb) { #endif /* VJ_SUPPORT && LWIP_TCP */ /* Start protocol */ + new_phase(pcb, PPP_PHASE_ESTABLISH); lcp_open(pcb); lcp_lowerup(pcb); PPPDEBUG(LOG_DEBUG, ("ppp_start[%d]: finished\n", pcb->netif->num)); From c2a5480ac7c55674928c4391a3f3d24e84ec321c Mon Sep 17 00:00:00 2001 From: Sylvain Rochet Date: Thu, 4 Aug 2016 23:52:54 +0200 Subject: [PATCH 012/325] PPP: remove useless ppp_link_start function This function only set PPP to initialize phase, and it is only called at the very beginning of functions where it is called. It means we could as well set the initialize phase before calling those functions in the PPP core. --- src/include/netif/ppp/ppp_impl.h | 3 --- src/netif/ppp/ppp.c | 10 +++------- src/netif/ppp/pppoe.c | 2 -- src/netif/ppp/pppol2tp.c | 2 -- src/netif/ppp/pppos.c | 2 -- 5 files changed, 3 insertions(+), 16 deletions(-) diff --git a/src/include/netif/ppp/ppp_impl.h b/src/include/netif/ppp/ppp_impl.h index 1b27415f..8c60fef9 100644 --- a/src/include/netif/ppp/ppp_impl.h +++ b/src/include/netif/ppp/ppp_impl.h @@ -394,9 +394,6 @@ int ppp_init(void); ppp_pcb *ppp_new(struct netif *pppif, const struct link_callbacks *callbacks, void *link_ctx_cb, ppp_link_status_cb_fn link_status_cb, void *ctx_cb); -/* Called when link is starting */ -void ppp_link_start(ppp_pcb *pcb); - /* Initiate LCP open request */ void ppp_start(ppp_pcb *pcb); diff --git a/src/netif/ppp/ppp.c b/src/netif/ppp/ppp.c index 96bcd8b1..02b90f25 100644 --- a/src/netif/ppp/ppp.c +++ b/src/netif/ppp/ppp.c @@ -276,6 +276,7 @@ err_t ppp_connect(ppp_pcb *pcb, u16_t holdoff) { PPPDEBUG(LOG_DEBUG, ("ppp_connect[%d]: holdoff=%d\n", pcb->netif->num, holdoff)); if (holdoff == 0) { + new_phase(pcb, PPP_PHASE_INITIALIZE); return pcb->link_cb->connect(pcb, pcb->link_ctx_cb); } @@ -301,6 +302,7 @@ err_t ppp_listen(ppp_pcb *pcb) { PPPDEBUG(LOG_DEBUG, ("ppp_listen[%d]\n", pcb->netif->num)); if (pcb->link_cb->listen) { + new_phase(pcb, PPP_PHASE_INITIALIZE); return pcb->link_cb->listen(pcb, pcb->link_ctx_cb); } return ERR_IF; @@ -432,6 +434,7 @@ static void ppp_do_connect(void *arg) { LWIP_ASSERT("pcb->phase == PPP_PHASE_DEAD || pcb->phase == PPP_PHASE_HOLDOFF", pcb->phase == PPP_PHASE_DEAD || pcb->phase == PPP_PHASE_HOLDOFF); + new_phase(pcb, PPP_PHASE_INITIALIZE); pcb->link_cb->connect(pcb, pcb->link_ctx_cb); } @@ -705,13 +708,6 @@ ppp_pcb *ppp_new(struct netif *pppif, const struct link_callbacks *callbacks, vo return pcb; } -/** Called when link is starting */ -void ppp_link_start(ppp_pcb *pcb) { - LWIP_ASSERT("pcb->phase == PPP_PHASE_DEAD || pcb->phase == PPP_PHASE_HOLDOFF", pcb->phase == PPP_PHASE_DEAD || pcb->phase == PPP_PHASE_HOLDOFF); - PPPDEBUG(LOG_DEBUG, ("ppp_link_start[%d]\n", pcb->netif->num)); - new_phase(pcb, PPP_PHASE_INITIALIZE); -} - /** Initiate LCP open request */ void ppp_start(ppp_pcb *pcb) { PPPDEBUG(LOG_DEBUG, ("ppp_start[%d]\n", pcb->netif->num)); diff --git a/src/netif/ppp/pppoe.c b/src/netif/ppp/pppoe.c index 26220ffe..d3b6c9cf 100644 --- a/src/netif/ppp/pppoe.c +++ b/src/netif/ppp/pppoe.c @@ -912,8 +912,6 @@ pppoe_connect(ppp_pcb *ppp, void *ctx) } #endif - ppp_link_start(ppp); - lcp_wo = &ppp->lcp_wantoptions; lcp_wo->mru = sc->sc_ethif->mtu-PPPOE_HEADERLEN-2; /* two byte PPP protocol discriminator, then IP data */ lcp_wo->neg_asyncmap = 0; diff --git a/src/netif/ppp/pppol2tp.c b/src/netif/ppp/pppol2tp.c index 877f84dc..3a681254 100644 --- a/src/netif/ppp/pppol2tp.c +++ b/src/netif/ppp/pppol2tp.c @@ -264,8 +264,6 @@ static err_t pppol2tp_connect(ppp_pcb *ppp, void *ctx) { pppol2tp_clear(l2tp); - ppp_link_start(ppp); - lcp_wo = &ppp->lcp_wantoptions; lcp_wo->mru = PPPOL2TP_DEFMRU; lcp_wo->neg_asyncmap = 0; diff --git a/src/netif/ppp/pppos.c b/src/netif/ppp/pppos.c index 006971d9..69ed80e9 100644 --- a/src/netif/ppp/pppos.c +++ b/src/netif/ppp/pppos.c @@ -309,7 +309,6 @@ pppos_connect(ppp_pcb *ppp, void *ctx) pppos_input_free_current_packet(pppos); #endif /* PPP_INPROC_IRQ_SAFE */ - ppp_link_start(ppp); /* reset PPPoS control block to its initial state */ memset(&pppos->last_xmit, 0, sizeof(pppos_pcb) - offsetof(pppos_pcb, last_xmit)); @@ -343,7 +342,6 @@ pppos_listen(ppp_pcb *ppp, void *ctx) pppos_input_free_current_packet(pppos); #endif /* PPP_INPROC_IRQ_SAFE */ - ppp_link_start(ppp); /* reset PPPoS control block to its initial state */ memset(&pppos->last_xmit, 0, sizeof(pppos_pcb) - offsetof(pppos_pcb, last_xmit)); From 70ee63ef3d0cf2f754bffc69e3f46b13ea78587f Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Fri, 5 Aug 2016 09:53:50 +0200 Subject: [PATCH 013/325] Documentation: Add example code for NO_SYS use case --- doc/NO_SYS_SampleCode.c | 115 ++++++++++++++++++++++++++++++++++++++++ src/core/init.c | 4 +- 2 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 doc/NO_SYS_SampleCode.c diff --git a/doc/NO_SYS_SampleCode.c b/doc/NO_SYS_SampleCode.c new file mode 100644 index 00000000..a62cc545 --- /dev/null +++ b/doc/NO_SYS_SampleCode.c @@ -0,0 +1,115 @@ +void eth_mac_irq() +{ + /* Service MAC IRQ here */ + + /* Allocate pbuf */ + struct pbuf* p = pbuf_alloc(PBUF_RAW, eth_data_count, PBUF_RAM); + + if(p != NULL) { + /* Copy ethernet frame into pbuf */ + pbuf_take(p, eth_data, eth_data_count); + + /* Put in a queue which is processed in main loop */ + if(!queue->tryPut(p)) { + /* queue is full -> packet loss */ + pbuf_free(p); + } + } +} + +static err_t netif_output(struct netif *netif, struct pbuf *p) +{ + LINK_STATS_INC(link.xmit); + MIB2_STATS_NETIF_ADD(netif, ifoutoctets, p->tot_len); + + /* Update SNMP stats (only if you use SNMP) */ + int unicast = ((p->payload[0] & 0x01) == 0); + if (unicast) { + MIB2_STATS_NETIF_INC(netif, ifoutucastpkts); + } else { + MIB2_STATS_NETIF_INC(netif, ifoutnucastpkts); + } + + LockInterrupts(); + pbuf_copy_partial(p, mac_send_buffer, p->tot_len, 0); + /* Start MAC transmit here */ + UnlockInterrupts(); + + return ERR_OK; +} + +static void netif_status_callback(struct netif *netif) +{ + printf("netif status changed %s\n", ip4addr_ntoa(netif_ip4_addr(netif))); +} + +static err_t netif_init(struct netif *netif) +{ + netif->linkoutput = netif_output; + netif->output = etharp_output; + netif->name[0] = 'e'; + netif->name[1] = '0'; + netif->mtu = ETHERNET_MTU; + + netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_ETHERNET | NETIF_FLAG_IGMP; + MIB2_INIT_NETIF(netif, snmp_ifType_ethernet_csmacd, 100000000); + + memcpy(netif->hwaddr, your_mac_address_goes_here, sizeof(netif->hwaddr)); + netif->hwaddr_len = sizeof(netif->hwaddr); + + return ERR_OK; +} + +void main(void) +{ + struct netif netif; + + lwip_init(); + + netif_add(&netif, IPADDR_ANY, IPADDR_ANY, IPADDR_ANY, NULL, netif_init, netif_input); + netif_set_status_callback(&netif, netif_status_callback); + netif_set_default(&netif); + netif_set_up(&netif); + + /* Start DHCP */ + dhcp_init(); + + while(1) { + /* Check link state, e.g. via MDIO communication with PHY */ + if(linkStateChanged()) { + if(linkIsUp()) { + netif_set_link_up(&netif); + } else { + netif_set_link_down(&netif); + } + } + + /* Check for received frames, feed them to lwIP */ + LockInterrupts(); + struct pbuf* p = queue->tryGet(); + UnlockInterrupts(); + + if(p != NULL) { + LINK_STATS_INC(link.recv); + + /* Update SNMP stats (only if you use SNMP) */ + MIB2_STATS_NETIF_ADD(netif, ifinoctets, p->tot_len); + + int unicast = ((p->payload[0] & 0x01) == 0); + if (unicast) { + MIB2_STATS_NETIF_INC(netif, ifinucastpkts); + } else { + MIB2_STATS_NETIF_INC(netif, ifinnucastpkts); + } + + if(netif.input(p, &netif) != ERR_OK) { + pbuf_free(p); + } + } + + /* Cyclic lwIP timers check */ + sys_check_timeouts(); + + /* your application goes here */ + } +} diff --git a/src/core/init.c b/src/core/init.c index 092cd2bc..bce01bef 100644 --- a/src/core/init.c +++ b/src/core/init.c @@ -44,7 +44,9 @@ * context and put them into a queue which is processed from mainloop.\n * Call sys_check_timeouts() periodically in the mainloop.\n * Porting: implement all functions in @ref sys_time and @ref sys_prot.\n - * You can only use @ref callbackstyle_api in this mode. + * You can only use @ref callbackstyle_api in this mode.\n + * Sample code:\n + * @verbinclude NO_SYS_SampleCode.c * * @defgroup lwip_os OS mode (TCPIP thread) * @ingroup lwip From a20cdc597ab464a5fdc6ddb81aedb60dc61cb4b9 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Fri, 5 Aug 2016 09:55:48 +0200 Subject: [PATCH 014/325] Fix comment in sample code --- doc/NO_SYS_SampleCode.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/doc/NO_SYS_SampleCode.c b/doc/NO_SYS_SampleCode.c index a62cc545..83d3be57 100644 --- a/doc/NO_SYS_SampleCode.c +++ b/doc/NO_SYS_SampleCode.c @@ -20,9 +20,9 @@ void eth_mac_irq() static err_t netif_output(struct netif *netif, struct pbuf *p) { LINK_STATS_INC(link.xmit); - MIB2_STATS_NETIF_ADD(netif, ifoutoctets, p->tot_len); /* Update SNMP stats (only if you use SNMP) */ + MIB2_STATS_NETIF_ADD(netif, ifoutoctets, p->tot_len); int unicast = ((p->payload[0] & 0x01) == 0); if (unicast) { MIB2_STATS_NETIF_INC(netif, ifoutucastpkts); @@ -91,10 +91,9 @@ void main(void) if(p != NULL) { LINK_STATS_INC(link.recv); - + /* Update SNMP stats (only if you use SNMP) */ MIB2_STATS_NETIF_ADD(netif, ifinoctets, p->tot_len); - int unicast = ((p->payload[0] & 0x01) == 0); if (unicast) { MIB2_STATS_NETIF_INC(netif, ifinucastpkts); From 2acfa0ebe7a8c80e028673138a05ac548a0c9d5c Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Sat, 6 Aug 2016 20:28:01 +0200 Subject: [PATCH 015/325] Update NO_SYS_SampleCode.c: Don't access heap in IRQ --- doc/NO_SYS_SampleCode.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/NO_SYS_SampleCode.c b/doc/NO_SYS_SampleCode.c index 83d3be57..fea32d67 100644 --- a/doc/NO_SYS_SampleCode.c +++ b/doc/NO_SYS_SampleCode.c @@ -2,8 +2,8 @@ void eth_mac_irq() { /* Service MAC IRQ here */ - /* Allocate pbuf */ - struct pbuf* p = pbuf_alloc(PBUF_RAW, eth_data_count, PBUF_RAM); + /* Allocate pbuf from pool (avoid using heap in interrupts) */ + struct pbuf* p = pbuf_alloc(PBUF_RAW, eth_data_count, PBUF_POOL); if(p != NULL) { /* Copy ethernet frame into pbuf */ From 87855b0e0e8638e1b932f66cca016beedbbc2145 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Sat, 6 Aug 2016 20:28:49 +0200 Subject: [PATCH 016/325] Update doxgen docs: PBUF layers, IPv4 and IPv6 functions, add some missing tcp raw API functions --- src/core/ipv4/ip4.c | 6 ++++++ src/core/ipv6/ip6.c | 5 +++++ src/core/tcp_out.c | 7 ++++++- src/include/lwip/pbuf.h | 22 ++++++++++++++++++++++ 4 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/core/ipv4/ip4.c b/src/core/ipv4/ip4.c index 0dba2dc2..9fa9b566 100644 --- a/src/core/ipv4/ip4.c +++ b/src/core/ipv4/ip4.c @@ -134,6 +134,7 @@ ip4_route_src(const ip4_addr_t *dest, const ip4_addr_t *src) #endif /* LWIP_HOOK_IP4_ROUTE_SRC */ /** + * @ingroup ip4 * Finds the appropriate network interface for a given IP address. It * searches the list of network interfaces linearly. A match is found * if the masked IP address of the network interface equals the masked @@ -712,6 +713,7 @@ ip4_input(struct pbuf *p, struct netif *inp) } /** + * @ingroup ip4 * Sends an IP packet on a network interface. This function constructs * the IP header and calculates the IP header checksum. If the source * IP address is NULL, the IP address of the outgoing network @@ -746,6 +748,7 @@ ip4_output_if(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest, } /** + * @ingroup ip4 * Same as ip_output_if() but with the possibility to include IP options: * * @ param ip_options pointer to the IP options, copied into the IP header @@ -773,6 +776,7 @@ ip4_output_if_opt(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest, } /** + * @ingroup ip4 * Same as ip_output_if() but 'src' address is not replaced by netif address * when it is 'any'. */ @@ -786,6 +790,7 @@ ip4_output_if_src(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest, } /** + * @ingroup ip4 * Same as ip_output_if_opt() but 'src' address is not replaced by netif address * when it is 'any'. */ @@ -947,6 +952,7 @@ ip4_output_if_opt_src(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *d } /** + * @ingroup ip4 * Simple interface to ip_output_if. It finds the outgoing network * interface and calls upon ip_output_if to do the actual work. * diff --git a/src/core/ipv6/ip6.c b/src/core/ipv6/ip6.c index 650e5af7..bddf9f4f 100644 --- a/src/core/ipv6/ip6.c +++ b/src/core/ipv6/ip6.c @@ -60,6 +60,7 @@ #include "lwip/stats.h" /** + * @ingroup ip6 * Finds the appropriate network interface for a given IPv6 address. It tries to select * a netif following a sequence of heuristics: * 1) if there is only 1 netif, return it @@ -192,6 +193,7 @@ ip6_route(const ip6_addr_t *src, const ip6_addr_t *dest) } /** + * @ingroup ip6 * Select the best IPv6 source address for a given destination * IPv6 address. Loosely follows RFC 3484. "Strong host" behavior * is assumed. @@ -776,6 +778,7 @@ ip6_input_cleanup: /** + * @igroup ip6 * Sends an IPv6 packet on a network interface. This function constructs * the IPv6 header. If the source IPv6 address is NULL, the IPv6 "ANY" address is * used as source (usually during network startup). If the source IPv6 address it @@ -820,6 +823,7 @@ ip6_output_if(struct pbuf *p, const ip6_addr_t *src, const ip6_addr_t *dest, } /** + * @ingroup ip6 * Same as ip6_output_if() but 'src' address is not replaced by netif address * when it is 'any'. */ @@ -903,6 +907,7 @@ ip6_output_if_src(struct pbuf *p, const ip6_addr_t *src, const ip6_addr_t *dest, } /** + * @ingroup ip6 * Simple interface to ip6_output_if. It finds the outgoing network * interface and calls upon ip6_output_if to do the actual work. * diff --git a/src/core/tcp_out.c b/src/core/tcp_out.c index 30289791..4808f247 100644 --- a/src/core/tcp_out.c +++ b/src/core/tcp_out.c @@ -350,6 +350,7 @@ tcp_write_checks(struct tcp_pcb *pcb, u16_t len) } /** + * @ingroup tcp_raw * Write data for sending (but does not send it immediately). * * It waits in the expectation of more data being sent soon (as @@ -874,7 +875,9 @@ tcp_build_wnd_scale_option(u32_t *opts) } #endif -/** Send an ACK without data. +/** + * @ingroup tcp_raw + * Send an ACK without data. * * @param pcb Protocol control block for the TCP connection to send the ACK */ @@ -946,6 +949,7 @@ tcp_send_empty_ack(struct tcp_pcb *pcb) } /** + * @ingroup tcp_raw * Find out what we can send and send it * * @param pcb Protocol control block for the TCP connection to send data @@ -1465,6 +1469,7 @@ tcp_rexmit_fast(struct tcp_pcb *pcb) /** + * @ingroup tcp_raw * Send keepalive packets to keep a connection active although * no data is sent over it. * diff --git a/src/include/lwip/pbuf.h b/src/include/lwip/pbuf.h index a3a761f5..32b75626 100644 --- a/src/include/lwip/pbuf.h +++ b/src/include/lwip/pbuf.h @@ -65,11 +65,33 @@ extern "C" { #define PBUF_IP_HLEN 20 #endif +/** + * @ingroup pbuf + * Enumeration of pbuf layers + */ typedef enum { + /** Includes spare room for transport layer header, e.g. TCP header. + * Use this if you intend to pass the pbuf to functions like udp_send(), + * tcp_write(), netconn_send() or netconn_write(). + */ PBUF_TRANSPORT, + /** Includes spare room for IP header. + * Use this if you intend to pass the pbuf to functions like raw_send(). + */ PBUF_IP, + /** Includes spare room for link layer header (ethernet header). + * Use this if you intend to pass the pbuf to functions like ip4_output(), + * ip6_output() or ip_output(). + */ PBUF_LINK, + /** Includes spare room for additional encapsulation header before ethernet headers (e.g. 802.11). + * Use this if you intend to pass the pbuf to functions like netif->linkoutput() + */ PBUF_RAW_TX, + /** No spare room, final packet for sending. + * Use this if you intend to pass the pbuf to functions like netif->linkoutput() + * or for input packets received by ethernet-layer netif drivers. + */ PBUF_RAW } pbuf_layer; From 73131b167707e03de20d78aba9750fbf6877d53d Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Sat, 6 Aug 2016 20:29:35 +0200 Subject: [PATCH 017/325] Fix doxygen warning in ip6.c --- src/core/ipv6/ip6.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/ipv6/ip6.c b/src/core/ipv6/ip6.c index bddf9f4f..6a953f06 100644 --- a/src/core/ipv6/ip6.c +++ b/src/core/ipv6/ip6.c @@ -778,7 +778,7 @@ ip6_input_cleanup: /** - * @igroup ip6 + * @ingroup ip6 * Sends an IPv6 packet on a network interface. This function constructs * the IPv6 header. If the source IPv6 address is NULL, the IPv6 "ANY" address is * used as source (usually during network startup). If the source IPv6 address it From b94c8ee76f1d5f5675621052b790214fb700170a Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Sat, 6 Aug 2016 22:16:49 +0200 Subject: [PATCH 018/325] Add some more functions and macros to documentation --- src/core/ip.c | 7 +++++-- src/include/lwip/ip.h | 25 ++++++++++++++++++++----- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/core/ip.c b/src/core/ip.c index a1685e3a..89cd36a8 100644 --- a/src/core/ip.c +++ b/src/core/ip.c @@ -37,11 +37,14 @@ */ /** - * @defgroup ip4 IPv4 + * @defgroup ip IP * @ingroup callbackstyle_api + * + * @defgroup ip4 IPv4 + * @ingroup ip * * @defgroup ip6 IPv6 - * @ingroup callbackstyle_api + * @ingroup ip * * @defgroup ipaddr IP address handling * @ingroup infrastructure diff --git a/src/include/lwip/ip.h b/src/include/lwip/ip.h index 09394320..0138caa8 100644 --- a/src/include/lwip/ip.h +++ b/src/include/lwip/ip.h @@ -227,17 +227,26 @@ extern struct ip_globals ip_data; #define ip_reset_option(pcb, opt) ((pcb)->so_options &= ~(opt)) #if LWIP_IPV4 && LWIP_IPV6 -/** Output IP packet, netif is selected by source address */ +/** + * @ingroup ip + * Output IP packet, netif is selected by source address + */ #define ip_output(p, src, dest, ttl, tos, proto) \ (IP_IS_V6(dest) ? \ ip6_output(p, ip_2_ip6(src), ip_2_ip6(dest), ttl, tos, proto) : \ ip4_output(p, ip_2_ip4(src), ip_2_ip4(dest), ttl, tos, proto)) -/** Output IP packet to specified interface */ +/** + * @ingroup ip + * Output IP packet to specified interface + */ #define ip_output_if(p, src, dest, ttl, tos, proto, netif) \ (IP_IS_V6(dest) ? \ ip6_output_if(p, ip_2_ip6(src), ip_2_ip6(dest), ttl, tos, proto, netif) : \ ip4_output_if(p, ip_2_ip4(src), ip_2_ip4(dest), ttl, tos, proto, netif)) -/** Output IP packet to interface specifying source address */ +/** + * @ingroup ip + * Output IP packet to interface specifying source address + */ #define ip_output_if_src(p, src, dest, ttl, tos, proto, netif) \ (IP_IS_V6(dest) ? \ ip6_output_if_src(p, ip_2_ip6(src), ip_2_ip6(dest), ttl, tos, proto, netif) : \ @@ -247,12 +256,18 @@ extern struct ip_globals ip_data; (IP_IS_V6(dest) ? \ ip6_output_hinted(p, ip_2_ip6(src), ip_2_ip6(dest), ttl, tos, proto, addr_hint) : \ ip4_output_hinted(p, ip_2_ip4(src), ip_2_ip4(dest), ttl, tos, proto, addr_hint)) -/** Get netif for address combination. See \ref ip6_route and \ref ip4_route */ +/** + * @ingroup ip + * Get netif for address combination. See \ref ip6_route and \ref ip4_route + */ #define ip_route(src, dest) \ (IP_IS_V6(dest) ? \ ip6_route(ip_2_ip6(src), ip_2_ip6(dest)) : \ ip4_route_src(ip_2_ip4(dest), ip_2_ip4(src))) -/** Get netif for IP.*/ +/** + * @ingroup ip + * Get netif for IP. + */ #define ip_netif_get_local_ip(netif, dest) (IP_IS_V6(dest) ? \ ip6_netif_get_local_ip(netif, ip_2_ip6(dest)) : \ ip4_netif_get_local_ip(netif)) From cf66233873e579a162ba05c5e87c1a2ae98c0efd Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Sat, 6 Aug 2016 22:28:12 +0200 Subject: [PATCH 019/325] PBUF layer documentation clarification --- src/include/lwip/pbuf.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/include/lwip/pbuf.h b/src/include/lwip/pbuf.h index 32b75626..509bd475 100644 --- a/src/include/lwip/pbuf.h +++ b/src/include/lwip/pbuf.h @@ -82,16 +82,15 @@ typedef enum { /** Includes spare room for link layer header (ethernet header). * Use this if you intend to pass the pbuf to functions like ip4_output(), * ip6_output() or ip_output(). + * @see @ref PBUF_LINK_HLEN */ PBUF_LINK, /** Includes spare room for additional encapsulation header before ethernet headers (e.g. 802.11). - * Use this if you intend to pass the pbuf to functions like netif->linkoutput() + * Use this if you intend to pass the pbuf to functions like netif->linkoutput(). + * @see @ref PBUF_LINK_ENCAPSULATION_HLEN */ PBUF_RAW_TX, - /** No spare room, final packet for sending. - * Use this if you intend to pass the pbuf to functions like netif->linkoutput() - * or for input packets received by ethernet-layer netif drivers. - */ + /** Use this for input packets received by ethernet-layer netif drivers. */ PBUF_RAW } pbuf_layer; From 8d07629b71df3e49bc49773d893c749e00a898a9 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Sun, 7 Aug 2016 10:05:34 +0200 Subject: [PATCH 020/325] Some documentation cleanups and include more comments that have been already in code into doxygen docs --- doc/doxygen/main_page.h | 31 ++++++++++++++++++++++ src/api/api_lib.c | 38 +++++++++++++-------------- src/api/netbuf.c | 15 +++++------ src/api/netdb.c | 8 ++---- src/api/netifapi.c | 17 +++++------- src/api/sockets.c | 15 +++++------ src/core/def.c | 23 ++++++++--------- src/core/inet_chksum.c | 22 ++++++++-------- src/core/init.c | 23 ----------------- src/core/ip.c | 39 +++++++++++++--------------- src/core/ipv4/autoip.c | 57 ++++++++++++++++------------------------- src/core/ipv4/dhcp.c | 52 +++++++++++++++---------------------- src/core/ipv4/igmp.c | 9 +++---- src/core/ipv6/mld6.c | 15 +++++------ src/core/memp.c | 11 ++++---- src/core/netif.c | 8 +++--- src/core/raw.c | 22 +++++----------- src/core/tcp.c | 20 +++++++-------- src/core/udp.c | 19 +++++--------- 19 files changed, 190 insertions(+), 254 deletions(-) diff --git a/doc/doxygen/main_page.h b/doc/doxygen/main_page.h index 9f01d9f3..86f96b73 100644 --- a/doc/doxygen/main_page.h +++ b/doc/doxygen/main_page.h @@ -30,3 +30,34 @@ * @page contrib How to contribute to lwIP * @verbinclude "contrib.txt" */ + +/** + * @defgroup lwip_nosys Mainloop mode ("NO_SYS") + * @ingroup lwip + * Use this mode if you do not run an OS on your system. \#define NO_SYS to 1. + * Feed incoming packets to netif->input(pbuf, netif) function from mainloop, + * *not* *from* *interrupt* *context*. You can allocate a @ref pbuf in interrupt + * context and put them into a queue which is processed from mainloop.\n + * Call sys_check_timeouts() periodically in the mainloop.\n + * Porting: implement all functions in @ref sys_time and @ref sys_prot.\n + * You can only use @ref callbackstyle_api in this mode.\n + * Sample code:\n + * @verbinclude NO_SYS_SampleCode.c + */ + +/** + * @defgroup lwip_os OS mode (TCPIP thread) + * @ingroup lwip + * Use this mode if you run an OS on your system. It is recommended to + * use an RTOS that correctly handles priority inversion and + * to use @ref LWIP_TCPIP_CORE_LOCKING.\n + * Porting: implement all functions in @ref sys_layer.\n + * You can use @ref callbackstyle_api together with \#define tcpip_callback, + * and all @ref threadsafe_api. + */ + +/** + * @defgroup raw_api RAW API + * @ingroup callbackstyle_api + * @verbinclude "rawapi.txt" + */ diff --git a/src/api/api_lib.c b/src/api/api_lib.c index 5e696d88..740fe396 100644 --- a/src/api/api_lib.c +++ b/src/api/api_lib.c @@ -1,6 +1,24 @@ /** * @file * Sequential API External module + * + * @defgroup netconn Netconn API + * @ingroup threadsafe_api + * Thread-safe, to be called from non-TCPIP threads only. + * TX/RX handling based on @ref netbuf (containing @ref pbuf) + * to avoid copying data around. + * + * @defgroup netconn_common Common functions + * @ingroup netconn + * For use with TCP and UDP + * + * @defgroup netconn_tcp TCP only + * @ingroup netconn + * TCP only functions + * + * @defgroup netconn_udp UDP only + * @ingroup netconn + * UDP only functions */ /* @@ -34,26 +52,6 @@ * Author: Adam Dunkels */ -/** - * @defgroup netconn Netconn API - * @ingroup threadsafe_api - * Thread-safe, to be called from non-TCPIP threads only. - * TX/RX handling based on @ref netbuf (containing @ref pbuf) - * to avoid copying data around. - * - * @defgroup netconn_common Common functions - * @ingroup netconn - * For use with TCP and UDP - * - * @defgroup netconn_tcp TCP only - * @ingroup netconn - * TCP only functions - * - * @defgroup netconn_udp UDP only - * @ingroup netconn - * UDP only functions - */ - /* This is the part of the API that is linked with the application */ diff --git a/src/api/netbuf.c b/src/api/netbuf.c index 342717be..50625167 100644 --- a/src/api/netbuf.c +++ b/src/api/netbuf.c @@ -2,6 +2,12 @@ * @file * Network buffer management * + * @defgroup netbuf Network buffers + * @ingroup netconn + * Network buffer descriptor for @ref netconn. Based on @ref pbuf internally + * to avoid copying data around.\n + * Buffers must not be shared accross multiple threads, all functions except + * netbuf_new() and netbuf_delete() are not thread-safe. */ /* @@ -36,15 +42,6 @@ * */ -/** - * @defgroup netbuf Network buffers - * @ingroup netconn - * Network buffer descriptor for @ref netconn. Based on @ref pbuf internally - * to avoid copying data around.\n - * Buffers must not be shared accross multiple threads, all functions except - * netbuf_new() and netbuf_delete() are not thread-safe. - */ - #include "lwip/opt.h" #if LWIP_NETCONN /* don't build if not configured for use in lwipopts.h */ diff --git a/src/api/netdb.c b/src/api/netdb.c index f9d63d46..670f6b97 100644 --- a/src/api/netdb.c +++ b/src/api/netdb.c @@ -2,6 +2,8 @@ * @file * API functions for name resolving * + * @defgroup netdbapi NETDB API + * @ingroup socket */ /* @@ -33,12 +35,6 @@ * */ - -/** - * @defgroup netdbapi NETDB API - * @ingroup socket - */ - #include "lwip/netdb.h" #if LWIP_DNS && LWIP_SOCKET diff --git a/src/api/netifapi.c b/src/api/netifapi.c index 3a02d521..265b60c5 100644 --- a/src/api/netifapi.c +++ b/src/api/netifapi.c @@ -2,6 +2,13 @@ * @file * Network Interface Sequential API module * + * @defgroup netifapi NETIF API + * @ingroup threadsafe_api + * Thread-safe functions to be called from non-TCPIP threads + * + * @defgroup netifapi_netif NETIF related + * @ingroup netifapi + * To be called from non-TCPIP threads */ /* @@ -31,16 +38,6 @@ * */ -/** - * @defgroup netifapi NETIF API - * @ingroup threadsafe_api - * Thread-safe functions to be called from non-TCPIP threads - * - * @defgroup netifapi_netif NETIF related - * @ingroup netifapi - * To be called from non-TCPIP threads - */ - #include "lwip/opt.h" #if LWIP_NETIF_API /* don't build if not configured for use in lwipopts.h */ diff --git a/src/api/sockets.c b/src/api/sockets.c index 6547182c..db90e16c 100644 --- a/src/api/sockets.c +++ b/src/api/sockets.c @@ -2,6 +2,12 @@ * @file * Sockets BSD-Like API module * + * @defgroup socket Socket API + * @ingroup threadsafe_api + * BSD-style socket API.\n + * Thread-safe, to be called from non-TCPIP threads only.\n + * Can be activated by defining @ref LWIP_SOCKET to 1.\n + * Header is in posix/sys/socket.h\b */ /* @@ -38,15 +44,6 @@ * */ -/** - * @defgroup socket Socket API - * @ingroup threadsafe_api - * BSD-style socket API.\n - * Thread-safe, to be called from non-TCPIP threads only.\n - * Can be activated by defining LWIP_SOCKET to 1.\n - * Header is in posix/sys/socket.h\b - */ - #include "lwip/opt.h" #if LWIP_SOCKET /* don't build if not configured for use in lwipopts.h */ diff --git a/src/core/def.c b/src/core/def.c index bb4b8e01..7d3c93fb 100644 --- a/src/core/def.c +++ b/src/core/def.c @@ -2,6 +2,16 @@ * @file * Common functions used throughout the stack. * + * These are reference implementations of the byte swapping functions. + * Again with the aim of being simple, correct and fully portable. + * Byte swapping is the second thing you would want to optimize. You will + * need to port it to your architecture and in your cc.h: + * + * \#define LWIP_PLATFORM_BYTESWAP 1 + * \#define LWIP_PLATFORM_HTONS(x) your_htons + * \#define LWIP_PLATFORM_HTONL(x) your_htonl + * + * Note ntohs() and ntohl() are merely references to the htonx counterparts. */ /* @@ -39,19 +49,6 @@ #include "lwip/opt.h" #include "lwip/def.h" -/** - * These are reference implementations of the byte swapping functions. - * Again with the aim of being simple, correct and fully portable. - * Byte swapping is the second thing you would want to optimize. You will - * need to port it to your architecture and in your cc.h: - * - * #define LWIP_PLATFORM_BYTESWAP 1 - * #define LWIP_PLATFORM_HTONS(x) - * #define LWIP_PLATFORM_HTONL(x) - * - * Note ntohs() and ntohl() are merely references to the htonx counterparts. - */ - #if (LWIP_PLATFORM_BYTESWAP == 0) && (BYTE_ORDER == LITTLE_ENDIAN) /** diff --git a/src/core/inet_chksum.c b/src/core/inet_chksum.c index 57cbad79..6ccf8391 100644 --- a/src/core/inet_chksum.c +++ b/src/core/inet_chksum.c @@ -1,7 +1,16 @@ /** * @file - * Incluse internet checksum functions. + * Incluse internet checksum functions.\n * + * These are some reference implementations of the checksum algorithm, with the + * aim of being simple, correct and fully portable. Checksumming is the + * first thing you would want to optimize for your platform. If you create + * your own version, link it in and in your cc.h put: + * + * \#define LWIP_CHKSUM your_checksum_routine + * + * Or you can select from the implementations below by defining + * LWIP_CHKSUM_ALGORITHM to 1, 2 or 3. */ /* @@ -45,17 +54,6 @@ #include #include -/* These are some reference implementations of the checksum algorithm, with the - * aim of being simple, correct and fully portable. Checksumming is the - * first thing you would want to optimize for your platform. If you create - * your own version, link it in and in your cc.h put: - * - * #define LWIP_CHKSUM - * - * Or you can select from the implementations below by defining - * LWIP_CHKSUM_ALGORITHM to 1, 2 or 3. - */ - #ifndef LWIP_CHKSUM # define LWIP_CHKSUM lwip_standard_chksum # ifndef LWIP_CHKSUM_ALGORITHM diff --git a/src/core/init.c b/src/core/init.c index bce01bef..22d5616c 100644 --- a/src/core/init.c +++ b/src/core/init.c @@ -35,29 +35,6 @@ * Author: Adam Dunkels */ -/** - * @defgroup lwip_nosys Mainloop mode ("NO_SYS") - * @ingroup lwip - * Use this mode if you do not run an OS on your system. \#define NO_SYS to 1. - * Feed incoming packets to netif->input(pbuf, netif) function from mainloop, - * *not* *from* *interrupt* *context*. You can allocate a @ref pbuf in interrupt - * context and put them into a queue which is processed from mainloop.\n - * Call sys_check_timeouts() periodically in the mainloop.\n - * Porting: implement all functions in @ref sys_time and @ref sys_prot.\n - * You can only use @ref callbackstyle_api in this mode.\n - * Sample code:\n - * @verbinclude NO_SYS_SampleCode.c - * - * @defgroup lwip_os OS mode (TCPIP thread) - * @ingroup lwip - * Use this mode if you run an OS on your system. It is recommended to - * use an RTOS that correctly handles priority inversion and - * to use LWIP_TCPIP_CORE_LOCKING.\n - * Porting: implement all functions in @ref sys_layer.\n - * You can use @ref callbackstyle_api together with \#define tcpip_callback, - * and all @ref threadsafe_api. - */ - #include "lwip/opt.h" #include "lwip/init.h" diff --git a/src/core/ip.c b/src/core/ip.c index 89cd36a8..2e024085 100644 --- a/src/core/ip.c +++ b/src/core/ip.c @@ -1,7 +1,24 @@ /** - * @file ip.c + * @file * Common IPv4 and IPv6 code * + * @defgroup ip IP + * @ingroup callbackstyle_api + * + * @defgroup ip4 IPv4 + * @ingroup ip + * + * @defgroup ip6 IPv6 + * @ingroup ip + * + * @defgroup ipaddr IP address handling + * @ingroup infrastructure + * + * @defgroup ip4addr IPv4 only + * @ingroup ipaddr + * + * @defgroup ip6addr IPv6 only + * @ingroup ipaddr */ /* @@ -36,26 +53,6 @@ * */ -/** - * @defgroup ip IP - * @ingroup callbackstyle_api - * - * @defgroup ip4 IPv4 - * @ingroup ip - * - * @defgroup ip6 IPv6 - * @ingroup ip - * - * @defgroup ipaddr IP address handling - * @ingroup infrastructure - * - * @defgroup ip4addr IPv4 only - * @ingroup ipaddr - * - * @defgroup ip6addr IPv6 only - * @ingroup ipaddr - */ - #include "lwip/opt.h" #if LWIP_IPV4 || LWIP_IPV6 diff --git a/src/core/ipv4/autoip.c b/src/core/ipv4/autoip.c index 8ca26712..f9bc60c8 100644 --- a/src/core/ipv4/autoip.c +++ b/src/core/ipv4/autoip.c @@ -2,6 +2,28 @@ * @file * AutoIP Automatic LinkLocal IP Configuration * + * This is a AutoIP implementation for the lwIP TCP/IP stack. It aims to conform + * with RFC 3927. + * + * @defgroup autoip AUTOIP + * @ingroup ip4 + * AUTOIP related functions + * USAGE: + * + * define @ref LWIP_AUTOIP 1 in your lwipopts.h + * Options: + * @ref AUTOIP_TMR_INTERVAL msecs, + * I recommend a value of 100. The value must divide 1000 with a remainder almost 0. + * Possible values are 1000, 500, 333, 250, 200, 166, 142, 125, 111, 100 .... + * + * Without DHCP: + * - Call autoip_start() after netif_add(). + * + * With DHCP: + * - define @ref LWIP_DHCP_AUTOIP_COOP 1 in your lwipopts.h. + * - Configure your DHCP Client. + * + * @see netifapi_autoip */ /* @@ -32,41 +54,6 @@ * OF SUCH DAMAGE. * * Author: Dominik Spies - * - * This is a AutoIP implementation for the lwIP TCP/IP stack. It aims to conform - * with RFC 3927. - * - * - * Please coordinate changes and requests with Dominik Spies - * - */ - -/******************************************************************************* - * USAGE: - * - * define LWIP_AUTOIP 1 in your lwipopts.h - * - * If you don't use tcpip.c (so, don't call, you don't call tcpip_init): - * - First, call autoip_init(). - * - call autoip_tmr() all AUTOIP_TMR_INTERVAL msces, - * that should be defined in autoip.h. - * I recommend a value of 100. The value must divide 1000 with a remainder almost 0. - * Possible values are 1000, 500, 333, 250, 200, 166, 142, 125, 111, 100 .... - * - * Without DHCP: - * - Call autoip_start() after netif_add(). - * - * With DHCP: - * - define LWIP_DHCP_AUTOIP_COOP 1 in your lwipopts.h. - * - Configure your DHCP Client. - * - */ - -/** - * @defgroup autoip AUTOIP - * @ingroup ip4 - * AUTOIP related functions - * @see netifapi_autoip */ #include "lwip/opt.h" diff --git a/src/core/ipv4/dhcp.c b/src/core/ipv4/dhcp.c index b3307dac..7536af02 100644 --- a/src/core/ipv4/dhcp.c +++ b/src/core/ipv4/dhcp.c @@ -2,6 +2,26 @@ * @file * Dynamic Host Configuration Protocol client * + * @defgroup dhcp4 DHCPv4 + * @ingroup ip4 + * DHCP (IPv4) related functions + * This is a DHCP client for the lwIP TCP/IP stack. It aims to conform + * with RFC 2131 and RFC 2132. + * + * @todo: + * - Support for interfaces other than Ethernet (SLIP, PPP, ...) + * + * Options: + * @ref DHCP_COARSE_TIMER_SECS (recommended 60 which is a minute) + * @ref DHCP_FINE_TIMER_MSECS (recommended 500 which equals TCP coarse timer) + * + * dhcp_start() starts a DHCP client instance which + * configures the interface by obtaining an IP address lease and maintaining it. + * + * Use dhcp_release() to end the lease and use dhcp_stop() + * to remove the DHCP client. + * + * @see netifapi_dhcp4 */ /* @@ -38,38 +58,6 @@ * * Author: Leon Woestenberg * - * This is a DHCP client for the lwIP TCP/IP stack. It aims to conform - * with RFC 2131 and RFC 2132. - * - * @todo: - * - Support for interfaces other than Ethernet (SLIP, PPP, ...) - * - * Please coordinate changes and requests with Leon Woestenberg - * - * - * Integration with your code: - * - * In lwip/dhcp.h - * #define DHCP_COARSE_TIMER_SECS (recommended 60 which is a minute) - * #define DHCP_FINE_TIMER_MSECS (recommended 500 which equals TCP coarse timer) - * - * Then have your application call dhcp_coarse_tmr() and - * dhcp_fine_tmr() on the defined intervals. - * - * dhcp_start(struct netif *netif); - * starts a DHCP client instance which configures the interface by - * obtaining an IP address lease and maintaining it. - * - * Use dhcp_release(netif) to end the lease and use dhcp_stop(netif) - * to remove the DHCP client. - * - */ - -/** - * @defgroup dhcp4 DHCPv4 - * @ingroup ip4 - * DHCP (IPv4) related functions - * @see netifapi_dhcp4 */ #include "lwip/opt.h" diff --git a/src/core/ipv4/igmp.c b/src/core/ipv4/igmp.c index 089a7611..90a80d38 100644 --- a/src/core/ipv4/igmp.c +++ b/src/core/ipv4/igmp.c @@ -2,6 +2,9 @@ * @file * IGMP - Internet Group Management Protocol * + * @defgroup igmp IGMP + * @ingroup ip4 + * To be called from TCPIP thread */ /* @@ -38,12 +41,6 @@ * source code. */ -/** - * @defgroup igmp IGMP - * @ingroup ip4 - * To be called from TCPIP thread - */ - /*------------------------------------------------------------- Note 1) Although the rfc requires V1 AND V2 capability diff --git a/src/core/ipv6/mld6.c b/src/core/ipv6/mld6.c index ef854e76..82510019 100644 --- a/src/core/ipv6/mld6.c +++ b/src/core/ipv6/mld6.c @@ -1,5 +1,12 @@ /** * @file + * Multicast listener discovery + * + * @defgroup mld6 MLD6 + * @ingroup ip6 + * Multicast listener discovery for IPv6. Aims to be compliant with RFC 2710. + * No support for MLDv2.\n + * To be called from TCPIP thread */ /* @@ -37,14 +44,6 @@ * */ -/** - * @defgroup mld6 MLD6 - * @ingroup ip6 - * Multicast listener discovery for IPv6. Aims to be compliant with RFC 2710. - * No support for MLDv2.\n - * To be called from TCPIP thread - */ - /* Based on igmp.c implementation of igmp v2 protocol */ #include "lwip/opt.h" diff --git a/src/core/memp.c b/src/core/memp.c index 5d2c4fb5..6473e18b 100644 --- a/src/core/memp.c +++ b/src/core/memp.c @@ -4,6 +4,11 @@ * * lwIP has dedicated pools for many structures (netconn, protocol control blocks, * packet buffers, ...). All these pools are managed here. + * + * @defgroup mempool Memory pools + * @ingroup infrastructure + * Custom memory pools + */ /* @@ -38,12 +43,6 @@ * */ -/** - * @defgroup mempool Memory pools - * @ingroup infrastructure - * Custom memory pools - */ - #include "lwip/opt.h" #include "lwip/memp.h" diff --git a/src/core/netif.c b/src/core/netif.c index 86003175..33560ae9 100644 --- a/src/core/netif.c +++ b/src/core/netif.c @@ -1,6 +1,9 @@ /** * @file * lwIP network interface abstraction + * + * @defgroup netif Network interface (NETIF) + * @ingroup callbackstyle_api */ /* @@ -34,11 +37,6 @@ * Author: Adam Dunkels */ -/** - * @defgroup netif Network interface (NETIF) - * @ingroup callbackstyle_api - */ - #include "lwip/opt.h" #include "lwip/def.h" diff --git a/src/core/raw.c b/src/core/raw.c index 90f2e302..df94c4b3 100644 --- a/src/core/raw.c +++ b/src/core/raw.c @@ -4,6 +4,13 @@ * different types of protocols besides (or overriding) those * already available in lwIP.\n * See also @ref raw_raw + * + * @defgroup raw_raw RAW + * @ingroup raw_api + * Implementation of raw protocol PCBs for low-level handling of + * different types of protocols besides (or overriding) those + * already available in lwIP.\n + * @see @ref raw_api */ /* @@ -38,21 +45,6 @@ * */ -/** - * @defgroup raw_api RAW API - * @ingroup callbackstyle_api - * @verbinclude "rawapi.txt" - */ - -/** - * @defgroup raw_raw RAW - * @ingroup raw_api - * Implementation of raw protocol PCBs for low-level handling of - * different types of protocols besides (or overriding) those - * already available in lwIP.\n - * @see @ref raw_api - */ - #include "lwip/opt.h" #if LWIP_RAW /* don't build if not configured for use in lwipopts.h */ diff --git a/src/core/tcp.c b/src/core/tcp.c index dfda7965..09286e67 100644 --- a/src/core/tcp.c +++ b/src/core/tcp.c @@ -2,6 +2,15 @@ * @file * Transmission Control Protocol for IP * See also @ref tcp_raw + * + * @defgroup tcp_raw TCP + * @ingroup raw_api + * Transmission Control Protocol for IP\n + * @see @ref raw_api and @ref netconn + * + * Common functions for the TCP implementation, such as functinos + * for manipulating the data structures and the TCP timer functions. TCP functions + * related to input and output is found in tcp_in.c and tcp_out.c respectively.\n */ /* @@ -36,17 +45,6 @@ * */ -/** - * @defgroup tcp_raw TCP - * @ingroup raw_api - * Transmission Control Protocol for IP\n - * @see @ref raw_api and @ref netconn - * - * Common functions for the TCP implementation, such as functinos - * for manipulating the data structures and the TCP timer functions. TCP functions - * related to input and output is found in tcp_in.c and tcp_out.c respectively.\n - */ - #include "lwip/opt.h" #if LWIP_TCP /* don't build if not configured for use in lwipopts.h */ diff --git a/src/core/udp.c b/src/core/udp.c index 14130ab3..e7ff246d 100644 --- a/src/core/udp.c +++ b/src/core/udp.c @@ -1,7 +1,13 @@ /** * @file * User Datagram Protocol module\n + * The code for the User Datagram Protocol UDP & UDPLite (RFC 3828).\n * See also @ref udp_raw + * + * @defgroup udp_raw UDP + * @ingroup raw_api + * User Datagram Protocol module\n + * @see @ref raw_api and @ref netconn */ /* @@ -36,19 +42,6 @@ * */ -/** - * @defgroup udp_raw UDP - * @ingroup raw_api - * User Datagram Protocol module\n - * @see @ref raw_api and @ref netconn - */ - -/* udp.c - * - * The code for the User Datagram Protocol UDP & UDPLite (RFC 3828). - * - */ - /* @todo Check the use of '(struct udp_pcb).chksum_len_rx'! */ From 980a919c9a3f3b1aea2c51aaf34ed89ca1fb3d01 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Sun, 7 Aug 2016 10:13:50 +0200 Subject: [PATCH 021/325] Don't document IP type specific output functions, users should use IP type independent ones --- src/core/ipv4/ip4.c | 9 +++------ src/core/ipv6/ip6.c | 3 --- src/include/lwip/pbuf.h | 3 +-- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/src/core/ipv4/ip4.c b/src/core/ipv4/ip4.c index 9fa9b566..ff7b937c 100644 --- a/src/core/ipv4/ip4.c +++ b/src/core/ipv4/ip4.c @@ -106,7 +106,9 @@ static u16_t ip_id; /** The default netif used for multicast */ static struct netif* ip4_default_multicast_netif; -/** Set a default netif for IPv4 multicast. */ +/** + * @ingroup ip4 + * Set a default netif for IPv4 multicast. */ void ip4_set_default_multicast_netif(struct netif* default_multicast_netif) { @@ -713,7 +715,6 @@ ip4_input(struct pbuf *p, struct netif *inp) } /** - * @ingroup ip4 * Sends an IP packet on a network interface. This function constructs * the IP header and calculates the IP header checksum. If the source * IP address is NULL, the IP address of the outgoing network @@ -748,7 +749,6 @@ ip4_output_if(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest, } /** - * @ingroup ip4 * Same as ip_output_if() but with the possibility to include IP options: * * @ param ip_options pointer to the IP options, copied into the IP header @@ -776,7 +776,6 @@ ip4_output_if_opt(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest, } /** - * @ingroup ip4 * Same as ip_output_if() but 'src' address is not replaced by netif address * when it is 'any'. */ @@ -790,7 +789,6 @@ ip4_output_if_src(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest, } /** - * @ingroup ip4 * Same as ip_output_if_opt() but 'src' address is not replaced by netif address * when it is 'any'. */ @@ -952,7 +950,6 @@ ip4_output_if_opt_src(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *d } /** - * @ingroup ip4 * Simple interface to ip_output_if. It finds the outgoing network * interface and calls upon ip_output_if to do the actual work. * diff --git a/src/core/ipv6/ip6.c b/src/core/ipv6/ip6.c index 6a953f06..bfbe453f 100644 --- a/src/core/ipv6/ip6.c +++ b/src/core/ipv6/ip6.c @@ -778,7 +778,6 @@ ip6_input_cleanup: /** - * @ingroup ip6 * Sends an IPv6 packet on a network interface. This function constructs * the IPv6 header. If the source IPv6 address is NULL, the IPv6 "ANY" address is * used as source (usually during network startup). If the source IPv6 address it @@ -823,7 +822,6 @@ ip6_output_if(struct pbuf *p, const ip6_addr_t *src, const ip6_addr_t *dest, } /** - * @ingroup ip6 * Same as ip6_output_if() but 'src' address is not replaced by netif address * when it is 'any'. */ @@ -907,7 +905,6 @@ ip6_output_if_src(struct pbuf *p, const ip6_addr_t *src, const ip6_addr_t *dest, } /** - * @ingroup ip6 * Simple interface to ip6_output_if. It finds the outgoing network * interface and calls upon ip6_output_if to do the actual work. * diff --git a/src/include/lwip/pbuf.h b/src/include/lwip/pbuf.h index 509bd475..60eee456 100644 --- a/src/include/lwip/pbuf.h +++ b/src/include/lwip/pbuf.h @@ -80,8 +80,7 @@ typedef enum { */ PBUF_IP, /** Includes spare room for link layer header (ethernet header). - * Use this if you intend to pass the pbuf to functions like ip4_output(), - * ip6_output() or ip_output(). + * Use this if you intend to pass the pbuf to functions like ip_output(). * @see @ref PBUF_LINK_HLEN */ PBUF_LINK, From 0673fcdb443a66416b7dc2b064bab18dab42483d Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Sun, 7 Aug 2016 10:16:18 +0200 Subject: [PATCH 022/325] Fix mentioning functions that do not take pbufs as argument in pbuf layer docs --- src/include/lwip/pbuf.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/include/lwip/pbuf.h b/src/include/lwip/pbuf.h index 60eee456..83545ebd 100644 --- a/src/include/lwip/pbuf.h +++ b/src/include/lwip/pbuf.h @@ -71,8 +71,8 @@ extern "C" { */ typedef enum { /** Includes spare room for transport layer header, e.g. TCP header. - * Use this if you intend to pass the pbuf to functions like udp_send(), - * tcp_write(), netconn_send() or netconn_write(). + * Use this if you intend to pass the pbuf to functions like udp_send() or + * tcp_write(). */ PBUF_TRANSPORT, /** Includes spare room for IP header. From 0a7db8a9a5598761dddf1ee66f39b216bfd79fe8 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Sun, 7 Aug 2016 14:10:05 +0800 Subject: [PATCH 023/325] PPP: remove double include for lwip/sys.h Including it once is enough. Signed-off-by: Axel Lin Signed-off-by: Sylvain Rochet --- src/core/netif.c | 1 - src/netif/ppp/ppp.c | 1 - 2 files changed, 2 deletions(-) diff --git a/src/core/netif.c b/src/core/netif.c index 33560ae9..10e5a865 100644 --- a/src/core/netif.c +++ b/src/core/netif.c @@ -51,7 +51,6 @@ #include "lwip/stats.h" #include "lwip/sys.h" #if ENABLE_LOOPBACK -#include "lwip/sys.h" #if LWIP_NETIF_LOOPBACK_MULTITHREADING #include "lwip/tcpip.h" #endif /* LWIP_NETIF_LOOPBACK_MULTITHREADING */ diff --git a/src/netif/ppp/ppp.c b/src/netif/ppp/ppp.c index 02b90f25..6d4f3a62 100644 --- a/src/netif/ppp/ppp.c +++ b/src/netif/ppp/ppp.c @@ -94,7 +94,6 @@ #include "lwip/tcpip.h" #include "lwip/api.h" #include "lwip/snmp.h" -#include "lwip/sys.h" #include "lwip/ip4.h" /* for ip4_input() */ #if PPP_IPV6_SUPPORT #include "lwip/ip6.h" /* for ip6_input() */ From 6af213787a05bc9fce93e3b9615f9a642d0f10c0 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Sun, 7 Aug 2016 20:04:09 +0200 Subject: [PATCH 024/325] Fix clang address sanitizer errors in unit tests (buffers too small) --- test/unit/tcp/test_tcp.c | 2 +- test/unit/tcp/test_tcp_oos.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unit/tcp/test_tcp.c b/test/unit/tcp/test_tcp.c index 1b89f651..bfcfa1d9 100644 --- a/test/unit/tcp/test_tcp.c +++ b/test/unit/tcp/test_tcp.c @@ -206,7 +206,7 @@ START_TEST(test_tcp_fast_retx_recover) char data3[] = { 9, 10, 11, 12}; char data4[] = {13, 14, 15, 16}; char data5[] = {17, 18, 19, 20}; - char data6[] = {21, 22, 23, 24}; + char data6[TCP_MSS] = {21, 22, 23, 24}; ip_addr_t remote_ip, local_ip, netmask; u16_t remote_port = 0x100, local_port = 0x101; err_t err; diff --git a/test/unit/tcp/test_tcp_oos.c b/test/unit/tcp/test_tcp_oos.c index 98f7098d..be611722 100644 --- a/test/unit/tcp/test_tcp_oos.c +++ b/test/unit/tcp/test_tcp_oos.c @@ -454,7 +454,7 @@ START_TEST(test_tcp_recv_ooseq_FIN_INSEQ) } END_TEST -static char data_full_wnd[TCP_WND]; +static char data_full_wnd[TCP_WND + TCP_MSS]; /** create multiple segments and pass them to tcp_input with the first segment missing * to simulate overruning the rxwin with ooseq queueing enabled */ From 3ca4eb5cd8bb81a2830d5d6485b2b8029fbda834 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Sun, 7 Aug 2016 20:05:01 +0200 Subject: [PATCH 025/325] Minor pbuf layer doc update --- src/include/lwip/pbuf.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/include/lwip/pbuf.h b/src/include/lwip/pbuf.h index 83545ebd..82e51491 100644 --- a/src/include/lwip/pbuf.h +++ b/src/include/lwip/pbuf.h @@ -84,12 +84,14 @@ typedef enum { * @see @ref PBUF_LINK_HLEN */ PBUF_LINK, - /** Includes spare room for additional encapsulation header before ethernet headers (e.g. 802.11). + /** Includes spare room for additional encapsulation header before ethernet + * headers (e.g. 802.11). * Use this if you intend to pass the pbuf to functions like netif->linkoutput(). * @see @ref PBUF_LINK_ENCAPSULATION_HLEN */ PBUF_RAW_TX, - /** Use this for input packets received by ethernet-layer netif drivers. */ + /** Use this for input packets in a netif driver when calling netif->input() + * in the most common case - ethernet-layer netif driver. */ PBUF_RAW } pbuf_layer; From f55c0e7864aa29cefa10cfb4b59fd21c5dc1c445 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Sun, 7 Aug 2016 20:13:27 +0200 Subject: [PATCH 026/325] Move rawapi.txt description to main page - this doc really should be found and read by users --- doc/doxygen/lwip.Doxyfile | 2 +- doc/doxygen/main_page.h | 3 +-- src/core/raw.c | 2 +- src/core/tcp.c | 2 +- src/core/udp.c | 2 +- 5 files changed, 5 insertions(+), 6 deletions(-) diff --git a/doc/doxygen/lwip.Doxyfile b/doc/doxygen/lwip.Doxyfile index f9d5fc17..9f20830f 100644 --- a/doc/doxygen/lwip.Doxyfile +++ b/doc/doxygen/lwip.Doxyfile @@ -781,7 +781,7 @@ WARN_LOGFILE = # spaces. See also FILE_PATTERNS and EXTENSION_MAPPING # Note: If this tag is empty the current directory is searched. -INPUT = ../../src main_page.h +INPUT = main_page.h ../../src # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses diff --git a/doc/doxygen/main_page.h b/doc/doxygen/main_page.h index 86f96b73..d5644405 100644 --- a/doc/doxygen/main_page.h +++ b/doc/doxygen/main_page.h @@ -57,7 +57,6 @@ */ /** - * @defgroup raw_api RAW API - * @ingroup callbackstyle_api + * @page raw_api lwIP API * @verbinclude "rawapi.txt" */ diff --git a/src/core/raw.c b/src/core/raw.c index df94c4b3..863739cb 100644 --- a/src/core/raw.c +++ b/src/core/raw.c @@ -6,7 +6,7 @@ * See also @ref raw_raw * * @defgroup raw_raw RAW - * @ingroup raw_api + * @ingroup callbackstyle_api * Implementation of raw protocol PCBs for low-level handling of * different types of protocols besides (or overriding) those * already available in lwIP.\n diff --git a/src/core/tcp.c b/src/core/tcp.c index 09286e67..63972b67 100644 --- a/src/core/tcp.c +++ b/src/core/tcp.c @@ -4,7 +4,7 @@ * See also @ref tcp_raw * * @defgroup tcp_raw TCP - * @ingroup raw_api + * @ingroup callbackstyle_api * Transmission Control Protocol for IP\n * @see @ref raw_api and @ref netconn * diff --git a/src/core/udp.c b/src/core/udp.c index e7ff246d..1e7766fc 100644 --- a/src/core/udp.c +++ b/src/core/udp.c @@ -5,7 +5,7 @@ * See also @ref udp_raw * * @defgroup udp_raw UDP - * @ingroup raw_api + * @ingroup callbackstyle_api * User Datagram Protocol module\n * @see @ref raw_api and @ref netconn */ From 898e69118afc4a5daa35d6b4903513cb33eda217 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Sun, 7 Aug 2016 20:20:38 +0200 Subject: [PATCH 027/325] Minor: documentation fix --- doc/doxygen/main_page.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/doxygen/main_page.h b/doc/doxygen/main_page.h index d5644405..f93c5dff 100644 --- a/doc/doxygen/main_page.h +++ b/doc/doxygen/main_page.h @@ -52,7 +52,7 @@ * use an RTOS that correctly handles priority inversion and * to use @ref LWIP_TCPIP_CORE_LOCKING.\n * Porting: implement all functions in @ref sys_layer.\n - * You can use @ref callbackstyle_api together with \#define tcpip_callback, + * You can use @ref callbackstyle_api together with @ref tcpip_callback, * and all @ref threadsafe_api. */ From dd0779c204a096f34a1cc8c5dca33a91b2293796 Mon Sep 17 00:00:00 2001 From: Sylvain Rochet Date: Sun, 7 Aug 2016 19:27:50 +0200 Subject: [PATCH 028/325] PPP, move VJ_SUPPORT disabling if LWIP_TCP is not enabled to PPP options Van Jacobson TCP header compression only apply if TCP is enabled, therefore we need to disable VJ compression if TCP is disabled. We already have conditions to enforce VJ disabling if IPv4 is disabled or if PPPoS is disabled, add TCP to those conditions and remove unecessary VJ_SUPPORT && LWIP_TCP conditions. --- src/include/netif/ppp/ppp_opts.h | 4 ++-- src/netif/ppp/ppp.c | 12 ++++++------ src/netif/ppp/pppos.c | 4 ++-- src/netif/ppp/vj.c | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/include/netif/ppp/ppp_opts.h b/src/include/netif/ppp/ppp_opts.h index 75541f44..fa79c090 100644 --- a/src/include/netif/ppp/ppp_opts.h +++ b/src/include/netif/ppp/ppp_opts.h @@ -296,8 +296,8 @@ #ifndef VJ_SUPPORT #define VJ_SUPPORT 1 #endif -/* VJ compression is only supported for IPv4 over PPPoS. */ -#if !PPPOS_SUPPORT || !PPP_IPV4_SUPPORT +/* VJ compression is only supported for TCP over IPv4 over PPPoS. */ +#if !PPPOS_SUPPORT || !PPP_IPV4_SUPPORT || !LWIP_TCP #undef VJ_SUPPORT #define VJ_SUPPORT 0 #endif /* !PPPOS_SUPPORT */ diff --git a/src/netif/ppp/ppp.c b/src/netif/ppp/ppp.c index 6d4f3a62..4c06083c 100644 --- a/src/netif/ppp/ppp.c +++ b/src/netif/ppp/ppp.c @@ -510,7 +510,7 @@ static err_t ppp_netif_output(struct netif *netif, struct pbuf *pb, u16_t protoc } #endif /* MPPE_SUPPORT */ -#if VJ_SUPPORT && LWIP_TCP +#if VJ_SUPPORT /* * Attempt Van Jacobson header compression if VJ is configured and * this is an IP packet. @@ -541,7 +541,7 @@ static err_t ppp_netif_output(struct netif *netif, struct pbuf *pb, u16_t protoc return ERR_VAL; } } -#endif /* VJ_SUPPORT && LWIP_TCP */ +#endif /* VJ_SUPPORT */ #if CCP_SUPPORT switch (pcb->ccp_transmit_method) { @@ -720,9 +720,9 @@ void ppp_start(ppp_pcb *pcb) { memset(&pcb->mppe_comp, 0, sizeof(pcb->mppe_comp)); memset(&pcb->mppe_decomp, 0, sizeof(pcb->mppe_decomp)); #endif /* MPPE_SUPPORT */ -#if VJ_SUPPORT && LWIP_TCP +#if VJ_SUPPORT vj_compress_init(&pcb->vj_comp); -#endif /* VJ_SUPPORT && LWIP_TCP */ +#endif /* VJ_SUPPORT */ /* Start protocol */ new_phase(pcb, PPP_PHASE_ESTABLISH); @@ -871,7 +871,7 @@ void ppp_input(ppp_pcb *pcb, struct pbuf *pb) { return; #endif /* PPP_IPV6_SUPPORT */ -#if VJ_SUPPORT && LWIP_TCP +#if VJ_SUPPORT case PPP_VJC_COMP: /* VJ compressed TCP */ /* * Clip off the VJ header and prepend the rebuilt TCP/IP header and @@ -899,7 +899,7 @@ void ppp_input(ppp_pcb *pcb, struct pbuf *pb) { /* Something's wrong so drop it. */ PPPDEBUG(LOG_WARNING, ("ppp_input[%d]: Dropping VJ uncompressed\n", pcb->netif->num)); break; -#endif /* VJ_SUPPORT && LWIP_TCP */ +#endif /* VJ_SUPPORT */ default: { int i; diff --git a/src/netif/ppp/pppos.c b/src/netif/ppp/pppos.c index 69ed80e9..b4d435e8 100644 --- a/src/netif/ppp/pppos.c +++ b/src/netif/ppp/pppos.c @@ -785,9 +785,9 @@ pppos_input_drop(pppos_pcb *pppos) PPPDEBUG(LOG_INFO, ("pppos_input_drop: pbuf len=%d, addr %p\n", pppos->in_head->len, (void*)pppos->in_head)); } pppos_input_free_current_packet(pppos); -#if VJ_SUPPORT && LWIP_TCP +#if VJ_SUPPORT vj_uncompress_err(&pppos->ppp->vj_comp); -#endif /* VJ_SUPPORT && LWIP_TCP */ +#endif /* VJ_SUPPORT */ LINK_STATS_INC(link.drop); MIB2_STATS_NETIF_INC(pppos->ppp->netif, ifindiscards); diff --git a/src/netif/ppp/vj.c b/src/netif/ppp/vj.c index b297c78d..dadb38d6 100644 --- a/src/netif/ppp/vj.c +++ b/src/netif/ppp/vj.c @@ -29,7 +29,7 @@ */ #include "netif/ppp/ppp_opts.h" -#if PPP_SUPPORT && VJ_SUPPORT && LWIP_TCP /* don't build if not configured for use in lwipopts.h */ +#if PPP_SUPPORT && VJ_SUPPORT /* don't build if not configured for use in lwipopts.h */ #include "netif/ppp/ppp_impl.h" #include "netif/ppp/pppdebug.h" @@ -692,4 +692,4 @@ bad: return (-1); } -#endif /* PPP_SUPPORT && VJ_SUPPORT && LWIP_TCP */ +#endif /* PPP_SUPPORT && VJ_SUPPORT */ From 5811948b0abf1f7e2e8e6c1fcd2223f2e6121b10 Mon Sep 17 00:00:00 2001 From: Sylvain Rochet Date: Sun, 7 Aug 2016 20:50:08 +0200 Subject: [PATCH 029/325] PPP: remove PPP_PHASE_MASTER conditions if multilink mode is disabled PPP_PHASE_MASTER state is only used if multilink mode is enabled. Since we don't support multilink mode checking for this state only add some code for no value added at all. Build-out PPP_PHASE_MASTER state check if multilink mode is disabled. --- src/netif/ppp/auth.c | 12 ++++++++++-- src/netif/ppp/lcp.c | 6 +++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/netif/ppp/auth.c b/src/netif/ppp/auth.c index 3c8bc79f..109c1467 100644 --- a/src/netif/ppp/auth.c +++ b/src/netif/ppp/auth.c @@ -618,7 +618,11 @@ void start_link(unit) * physical layer down. */ void link_terminated(ppp_pcb *pcb) { - if (pcb->phase == PPP_PHASE_DEAD || pcb->phase == PPP_PHASE_MASTER) + if (pcb->phase == PPP_PHASE_DEAD +#ifdef HAVE_MULTILINK + || pcb->phase == PPP_PHASE_MASTER +#endif /* HAVE_MULTILINK */ + ) return; new_phase(pcb, PPP_PHASE_DISCONNECT); @@ -698,7 +702,11 @@ void link_down(ppp_pcb *pcb) { if (!doing_multilink) { upper_layers_down(pcb); - if (pcb->phase != PPP_PHASE_DEAD && pcb->phase != PPP_PHASE_MASTER) + if (pcb->phase != PPP_PHASE_DEAD +#ifdef HAVE_MULTILINK + && pcb->phase != PPP_PHASE_MASTER +#endif /* HAVE_MULTILINK */ + ) new_phase(pcb, PPP_PHASE_ESTABLISH); } /* XXX if doing_multilink, should do something to stop diff --git a/src/netif/ppp/lcp.c b/src/netif/ppp/lcp.c index b17964b2..90ed183b 100644 --- a/src/netif/ppp/lcp.c +++ b/src/netif/ppp/lcp.c @@ -423,7 +423,11 @@ void lcp_close(ppp_pcb *pcb, const char *reason) { fsm *f = &pcb->lcp_fsm; int oldstate; - if (pcb->phase != PPP_PHASE_DEAD && pcb->phase != PPP_PHASE_MASTER) + if (pcb->phase != PPP_PHASE_DEAD +#ifdef HAVE_MULTILINK + && pcb->phase != PPP_PHASE_MASTER +#endif /* HAVE_MULTILINK */ + ) new_phase(pcb, PPP_PHASE_TERMINATE); if (f->flags & DELAYED_UP) { From f185104ac6000a8d1fa779aecdbbd297da52e497 Mon Sep 17 00:00:00 2001 From: Sylvain Rochet Date: Sun, 7 Aug 2016 20:54:14 +0200 Subject: [PATCH 030/325] PPP: revamp PPP state order Master state is almost exactly the same thing as dead state, move it next to dead state. Holdoff state is actually the state just before initialize, move it before initialize. The goal is to be able to use > running or => terminate condition to check a currently running disconnection phase, which is not possible today without excluding master and holdoff states. --- src/include/netif/ppp/ppp.h | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/include/netif/ppp/ppp.h b/src/include/netif/ppp/ppp.h index 016d6ba2..28b2732a 100644 --- a/src/include/netif/ppp/ppp.h +++ b/src/include/netif/ppp/ppp.h @@ -110,18 +110,18 @@ * Values for phase. */ #define PPP_PHASE_DEAD 0 -#define PPP_PHASE_INITIALIZE 1 -#define PPP_PHASE_SERIALCONN 2 -#define PPP_PHASE_DORMANT 3 -#define PPP_PHASE_ESTABLISH 4 -#define PPP_PHASE_AUTHENTICATE 5 -#define PPP_PHASE_CALLBACK 6 -#define PPP_PHASE_NETWORK 7 -#define PPP_PHASE_RUNNING 8 -#define PPP_PHASE_TERMINATE 9 -#define PPP_PHASE_DISCONNECT 10 -#define PPP_PHASE_HOLDOFF 11 -#define PPP_PHASE_MASTER 12 +#define PPP_PHASE_MASTER 1 +#define PPP_PHASE_HOLDOFF 2 +#define PPP_PHASE_INITIALIZE 3 +#define PPP_PHASE_SERIALCONN 4 +#define PPP_PHASE_DORMANT 5 +#define PPP_PHASE_ESTABLISH 6 +#define PPP_PHASE_AUTHENTICATE 7 +#define PPP_PHASE_CALLBACK 8 +#define PPP_PHASE_NETWORK 9 +#define PPP_PHASE_RUNNING 10 +#define PPP_PHASE_TERMINATE 11 +#define PPP_PHASE_DISCONNECT 12 /* Error codes. */ #define PPPERR_NONE 0 /* No error. */ From d15ebc6a4cd62f7637f7b05ed68c4adb98b6977b Mon Sep 17 00:00:00 2001 From: Sylvain Rochet Date: Sun, 7 Aug 2016 21:04:56 +0200 Subject: [PATCH 031/325] PPP: don't restart LCP closing if termination is already in progress We say in the PPP documentation that ppp_close() can be called anytime, as of today, this is not entirely true, there are still conditions that are not handled properly. If PPP is already disconnecting, ppp_close() must do nothing and returns ERR_INPROGRESS instead of messing up the PPP disconnection state. --- src/netif/ppp/ppp.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/netif/ppp/ppp.c b/src/netif/ppp/ppp.c index 4c06083c..d5de30b2 100644 --- a/src/netif/ppp/ppp.c +++ b/src/netif/ppp/ppp.c @@ -336,6 +336,11 @@ ppp_close(ppp_pcb *pcb, u8_t nocarrier) return ERR_OK; } + /* Already terminating, nothing to do */ + if (pcb->phase >= PPP_PHASE_TERMINATE) { + return ERR_INPROGRESS; + } + /* * Only accept carrier lost signal on the stable running phase in order * to prevent changing the PPP phase FSM in transition phases. @@ -346,14 +351,14 @@ ppp_close(ppp_pcb *pcb, u8_t nocarrier) if (nocarrier && pcb->phase == PPP_PHASE_RUNNING) { PPPDEBUG(LOG_DEBUG, ("ppp_close[%d]: carrier lost -> lcp_lowerdown\n", pcb->netif->num)); lcp_lowerdown(pcb); - /* forced link termination, this will leave us at PPP_PHASE_DEAD. */ + /* forced link termination, this will force link protocol to disconnect. */ link_terminated(pcb); return ERR_OK; } /* Disconnect */ PPPDEBUG(LOG_DEBUG, ("ppp_close[%d]: kill_link -> lcp_close\n", pcb->netif->num)); - /* LCP close request, this will leave us at PPP_PHASE_DEAD. */ + /* LCP soft close request. */ lcp_close(pcb, "User request"); return ERR_OK; } From 7c02a85424c558170d56c710bbba25456e9ac041 Mon Sep 17 00:00:00 2001 From: Sylvain Rochet Date: Sun, 7 Aug 2016 22:35:31 +0200 Subject: [PATCH 032/325] PPP, PPPoE: add support for disconnecting in link initiation state in disconnect callback Disconnect callback does not currently support a disconnect event while initiation is in progress. Retry timer is not stopped and PADT frame is sent whatever the current state is. PADT frame can only be sent if we received a PADS frame, otherwise sc_session is 0 and sending a PADT frame is meaningless. Fix both issues to allow calling the disconnect callback whatever the PPPoE state is. --- src/netif/ppp/pppoe.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/netif/ppp/pppoe.c b/src/netif/ppp/pppoe.c index d3b6c9cf..07b9fb66 100644 --- a/src/netif/ppp/pppoe.c +++ b/src/netif/ppp/pppoe.c @@ -952,7 +952,12 @@ pppoe_disconnect(ppp_pcb *ppp, void *ctx) struct pppoe_softc *sc = (struct pppoe_softc *)ctx; PPPDEBUG(LOG_DEBUG, ("pppoe: %c%c%"U16_F": disconnecting\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num)); - pppoe_send_padt(sc->sc_ethif, sc->sc_session, (const u8_t *)&sc->sc_dest); + if (sc->sc_state == PPPOE_STATE_SESSION) { + pppoe_send_padt(sc->sc_ethif, sc->sc_session, (const u8_t *)&sc->sc_dest); + } + + /* stop any timer, disconnect can be called while initiating is in progress */ + sys_untimeout(pppoe_timeout, sc); /* cleanup softc */ sc->sc_state = PPPOE_STATE_INITIAL; From 09c22e13fe565301f883407998708c92a38d6b2f Mon Sep 17 00:00:00 2001 From: Sylvain Rochet Date: Sun, 7 Aug 2016 22:39:16 +0200 Subject: [PATCH 033/325] PPP: close link protocol if LCP is not started in ppp_close ppp_close might try to close LCP even if LCP is not started, it happens because because the PPP session might be waiting for the link protocol to come up and we do not check that. We say in the PPP documentation that ppp_close() can be called anytime, so, if link protocol is currently trying to connect, we must cancel the link connection. Fix it by calling the link protocol disconnect callback if LCP is not started yet. --- src/netif/ppp/ppp.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/netif/ppp/ppp.c b/src/netif/ppp/ppp.c index d5de30b2..a1588931 100644 --- a/src/netif/ppp/ppp.c +++ b/src/netif/ppp/ppp.c @@ -341,6 +341,12 @@ ppp_close(ppp_pcb *pcb, u8_t nocarrier) return ERR_INPROGRESS; } + /* LCP not open, close link protocol */ + if (pcb->phase < PPP_PHASE_ESTABLISH) { + ppp_link_terminated(pcb); + return ERR_OK; + } + /* * Only accept carrier lost signal on the stable running phase in order * to prevent changing the PPP phase FSM in transition phases. From 1ea10269614041d5a44b8a719b5496d9ac405631 Mon Sep 17 00:00:00 2001 From: Sylvain Rochet Date: Sun, 7 Aug 2016 23:08:50 +0200 Subject: [PATCH 034/325] PPP, PPPoE: cleanup connection state reset Instead of relying on cleanup at the end of session, cleanup as much as possible in the connect callback. It removes duplicated code and make everything simpler to read. While we are at it, remove useless initialization code from create and connect functions. --- src/netif/ppp/pppoe.c | 39 ++++++--------------------------------- 1 file changed, 6 insertions(+), 33 deletions(-) diff --git a/src/netif/ppp/pppoe.c b/src/netif/ppp/pppoe.c index 07b9fb66..22502e51 100644 --- a/src/netif/ppp/pppoe.c +++ b/src/netif/ppp/pppoe.c @@ -189,8 +189,6 @@ ppp_pcb *pppoe_create(struct netif *pppif, } memset(sc, 0, sizeof(struct pppoe_softc)); - /* changed to real address later */ - MEMCPY(&sc->sc_dest, ethbroadcast.addr, sizeof(sc->sc_dest)); sc->pcb = ppp; sc->sc_ethif = ethif; /* put the new interface at the head of the list */ @@ -900,11 +898,12 @@ pppoe_connect(ppp_pcb *ppp, void *ctx) ipcp_options *ipcp_ao; #endif /* PPP_IPV4_SUPPORT && VJ_SUPPORT */ - /* stop any timer */ - sys_untimeout(pppoe_timeout, sc); sc->sc_session = 0; + sc->sc_ac_cookie_len = 0; sc->sc_padi_retried = 0; sc->sc_padr_retried = 0; + /* changed to real address later */ + MEMCPY(&sc->sc_dest, ethbroadcast.addr, sizeof(sc->sc_dest)); #ifdef PPPOE_SERVER /* wait PADI if IFF_PASSIVE */ if ((sc->sc_sppp.pp_if.if_flags & IFF_PASSIVE)) { @@ -958,22 +957,14 @@ pppoe_disconnect(ppp_pcb *ppp, void *ctx) /* stop any timer, disconnect can be called while initiating is in progress */ sys_untimeout(pppoe_timeout, sc); - - /* cleanup softc */ sc->sc_state = PPPOE_STATE_INITIAL; - MEMCPY(&sc->sc_dest, ethbroadcast.addr, sizeof(sc->sc_dest)); - sc->sc_ac_cookie_len = 0; #ifdef PPPOE_SERVER if (sc->sc_hunique) { mem_free(sc->sc_hunique); - sc->sc_hunique = NULL; + sc->sc_hunique = NULL; /* probably not necessary, if state is initial we shouldn't have to access hunique anyway */ } - sc->sc_hunique_len = 0; + sc->sc_hunique_len = 0; /* probably not necessary, if state is initial we shouldn't have to access hunique anyway */ #endif - sc->sc_session = 0; - sc->sc_padi_retried = 0; - sc->sc_padr_retried = 0; - ppp_link_end(ppp); /* notify upper layers */ return; } @@ -983,15 +974,7 @@ static void pppoe_abort_connect(struct pppoe_softc *sc) { PPPDEBUG(LOG_DEBUG, ("%c%c%"U16_F": could not establish connection\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num)); - - /* clear connection state */ sc->sc_state = PPPOE_STATE_INITIAL; - MEMCPY(&sc->sc_dest, ethbroadcast.addr, sizeof(sc->sc_dest)); - sc->sc_ac_cookie_len = 0; - sc->sc_session = 0; - sc->sc_padi_retried = 0; - sc->sc_padr_retried = 0; - ppp_link_failed(sc->pcb); /* notify upper layers */ } @@ -1209,18 +1192,8 @@ pppoe_clear_softc(struct pppoe_softc *sc, const char *message) /* stop timer */ sys_untimeout(pppoe_timeout, sc); PPPDEBUG(LOG_DEBUG, ("pppoe: %c%c%"U16_F": session 0x%x terminated, %s\n", sc->sc_ethif->name[0], sc->sc_ethif->name[1], sc->sc_ethif->num, sc->sc_session, message)); - /* fix our state */ sc->sc_state = PPPOE_STATE_INITIAL; - - /* notify upper layers */ - ppp_link_end(sc->pcb); /* /!\ dangerous /!\ */ - - /* clean up softc */ - MEMCPY(&sc->sc_dest, ethbroadcast.addr, sizeof(sc->sc_dest)); - sc->sc_ac_cookie_len = 0; - sc->sc_session = 0; - sc->sc_padi_retried = 0; - sc->sc_padr_retried = 0; + ppp_link_end(sc->pcb); /* notify upper layers - /!\ dangerous /!\ - see pppoe_disc_input() */ } #endif /* UNUSED */ #endif /* PPP_SUPPORT && PPPOE_SUPPORT */ From 455a41822ef28d8118c10a57fdec616633447805 Mon Sep 17 00:00:00 2001 From: Sylvain Rochet Date: Sun, 7 Aug 2016 23:20:09 +0200 Subject: [PATCH 035/325] PPP, PPPoL2TP: cleanup connection state reset Remove unnecessary cleanup at the end of session, cleanup as much as possible in the connect callback instead. It follows what PPPoE is currently doing and it makes everything simpler to read. --- src/netif/ppp/pppol2tp.c | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/src/netif/ppp/pppol2tp.c b/src/netif/ppp/pppol2tp.c index 3a681254..7ecbe9eb 100644 --- a/src/netif/ppp/pppol2tp.c +++ b/src/netif/ppp/pppol2tp.c @@ -81,7 +81,6 @@ static void pppol2tp_input(void *arg, struct udp_pcb *pcb, struct pbuf *p, const static void pppol2tp_dispatch_control_packet(pppol2tp_pcb *l2tp, u16_t port, struct pbuf *p, u16_t ns, u16_t nr); static void pppol2tp_timeout(void *arg); static void pppol2tp_abort_connect(pppol2tp_pcb *l2tp); -static void pppol2tp_clear(pppol2tp_pcb *l2tp); static err_t pppol2tp_send_sccrq(pppol2tp_pcb *l2tp); static err_t pppol2tp_send_scccn(pppol2tp_pcb *l2tp, u16_t ns); static err_t pppol2tp_send_icrq(pppol2tp_pcb *l2tp, u16_t ns); @@ -262,7 +261,15 @@ static err_t pppol2tp_connect(ppp_pcb *ppp, void *ctx) { ipcp_options *ipcp_ao; #endif /* PPP_IPV4_SUPPORT && VJ_SUPPORT */ - pppol2tp_clear(l2tp); + l2tp->tunnel_port = l2tp->remote_port; + l2tp->our_ns = 0; + l2tp->peer_nr = 0; + l2tp->peer_ns = 0; + l2tp->source_tunnel_id = 0; + l2tp->remote_tunnel_id = 0; + l2tp->source_session_id = 0; + l2tp->remote_session_id = 0; + /* l2tp->*_retried are cleared when used */ lcp_wo = &ppp->lcp_wantoptions; lcp_wo->mru = PPPOL2TP_DEFMRU; @@ -325,7 +332,9 @@ static void pppol2tp_disconnect(ppp_pcb *ppp, void *ctx) { l2tp->our_ns++; pppol2tp_send_stopccn(l2tp, l2tp->our_ns); - pppol2tp_clear(l2tp); + /* stop any timer, disconnect can be called while initiating is in progress */ + sys_untimeout(pppol2tp_timeout, l2tp); + l2tp->phase = PPPOL2TP_STATE_INITIAL; ppp_link_end(ppp); /* notify upper layers */ } @@ -763,24 +772,8 @@ static void pppol2tp_timeout(void *arg) { /* Connection attempt aborted */ static void pppol2tp_abort_connect(pppol2tp_pcb *l2tp) { PPPDEBUG(LOG_DEBUG, ("pppol2tp: could not establish connection\n")); - pppol2tp_clear(l2tp); - ppp_link_failed(l2tp->ppp); /* notify upper layers */ -} - -/* Reset L2TP control block to its initial state */ -static void pppol2tp_clear(pppol2tp_pcb *l2tp) { - /* stop any timer */ - sys_untimeout(pppol2tp_timeout, l2tp); l2tp->phase = PPPOL2TP_STATE_INITIAL; - l2tp->tunnel_port = l2tp->remote_port; - l2tp->our_ns = 0; - l2tp->peer_nr = 0; - l2tp->peer_ns = 0; - l2tp->source_tunnel_id = 0; - l2tp->remote_tunnel_id = 0; - l2tp->source_session_id = 0; - l2tp->remote_session_id = 0; - /* l2tp->*_retried are cleared when used */ + ppp_link_failed(l2tp->ppp); /* notify upper layers */ } /* Initiate a new tunnel */ From 953dd5b628d935b847ccc26d3a54603df735f26f Mon Sep 17 00:00:00 2001 From: Sylvain Rochet Date: Mon, 8 Aug 2016 00:14:45 +0200 Subject: [PATCH 036/325] PPP, PPPoE: remove useless checks pppoe_softc_list is always not null when pppoe_find_softc_by_session is called, furthermore pppoe_softc_list being null here does not hurt. session is still checked whatsoever in pppoe_find_softc_by_session, prechecking the session value for a value which can't really happen except for forged frames does not add any value. --- src/netif/ppp/pppoe.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/netif/ppp/pppoe.c b/src/netif/ppp/pppoe.c index 22502e51..1530611d 100644 --- a/src/netif/ppp/pppoe.c +++ b/src/netif/ppp/pppoe.c @@ -321,10 +321,6 @@ pppoe_destroy(ppp_pcb *ppp, void *ctx) static struct pppoe_softc* pppoe_find_softc_by_session(u_int session, struct netif *rcvif) { struct pppoe_softc *sc; - if (session == 0) { - return NULL; - } - for (sc = pppoe_softc_list; sc != NULL; sc = sc->next) { if (sc->sc_state == PPPOE_STATE_SESSION && sc->sc_session == session @@ -340,10 +336,6 @@ static struct pppoe_softc* pppoe_find_softc_by_session(u_int session, struct net static struct pppoe_softc* pppoe_find_softc_by_hunique(u8_t *token, size_t len, struct netif *rcvif) { struct pppoe_softc *sc, *t; - if (pppoe_softc_list == NULL) { - return NULL; - } - if (len != sizeof sc) { return NULL; } From fa8797b86d6a25a55a3862ced4d4f27308cba4b7 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Mon, 8 Aug 2016 08:20:42 +0200 Subject: [PATCH 037/325] Fix PBUF_LINK_HLEN value in documentation --- src/include/lwip/opt.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h index b37124ce..7c936229 100644 --- a/src/include/lwip/opt.h +++ b/src/include/lwip/opt.h @@ -1359,7 +1359,7 @@ * Ethernet. */ #if !defined PBUF_LINK_HLEN || defined __DOXYGEN__ -#if defined LWIP_HOOK_VLAN_SET || defined __DOXYGEN__ +#if defined LWIP_HOOK_VLAN_SET #define PBUF_LINK_HLEN (18 + ETH_PAD_SIZE) #else /* LWIP_HOOK_VLAN_SET */ #define PBUF_LINK_HLEN (14 + ETH_PAD_SIZE) From fc66fb830c244781034ba71453f51b07025c1fd5 Mon Sep 17 00:00:00 2001 From: David van Moolenbroek Date: Sun, 7 Aug 2016 16:20:49 +0000 Subject: [PATCH 038/325] Fix compilation for LWIP_EVENT_API Without LWIP_CALLBACK_API, is no error callback function pointer in the TCP PCB, nor is it needed, so do not attempt to access it. --- src/core/tcp.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/core/tcp.c b/src/core/tcp.c index 63972b67..dab3bd62 100644 --- a/src/core/tcp.c +++ b/src/core/tcp.c @@ -1094,7 +1094,9 @@ tcp_slowtmr_start: /* If the PCB should be removed, do it. */ if (pcb_remove) { struct tcp_pcb *pcb2; +#if LWIP_CALLBACK_API tcp_err_fn err_fn; +#endif /* LWIP_CALLBACK_API */ void *err_arg; tcp_pcb_purge(pcb); /* Remove PCB from tcp_active_pcbs list. */ @@ -1112,7 +1114,9 @@ tcp_slowtmr_start: pcb->local_port, pcb->remote_port); } +#if LWIP_CALLBACK_API err_fn = pcb->errf; +#endif /* LWIP_CALLBACK_API */ err_arg = pcb->callback_arg; pcb2 = pcb; pcb = pcb->next; From 08378b7d4bbc97700a99588a4e3181102436a4ce Mon Sep 17 00:00:00 2001 From: goldsimon Date: Mon, 8 Aug 2016 08:49:14 +0200 Subject: [PATCH 039/325] Improve LWIP_EVENT_API compilation --- src/core/tcp.c | 26 ++++++++++++-------------- src/include/lwip/opt.h | 9 ++++++++- src/include/lwip/tcp.h | 6 ++++-- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/core/tcp.c b/src/core/tcp.c index dab3bd62..a3f8ea04 100644 --- a/src/core/tcp.c +++ b/src/core/tcp.c @@ -2,15 +2,6 @@ * @file * Transmission Control Protocol for IP * See also @ref tcp_raw - * - * @defgroup tcp_raw TCP - * @ingroup callbackstyle_api - * Transmission Control Protocol for IP\n - * @see @ref raw_api and @ref netconn - * - * Common functions for the TCP implementation, such as functinos - * for manipulating the data structures and the TCP timer functions. TCP functions - * related to input and output is found in tcp_in.c and tcp_out.c respectively.\n */ /* @@ -45,6 +36,17 @@ * */ +/** + * @defgroup tcp_raw TCP + * @ingroup raw_api + * Transmission Control Protocol for IP\n + * @see @ref raw_api and @ref netconn + * + * Common functions for the TCP implementation, such as functinos + * for manipulating the data structures and the TCP timer functions. TCP functions + * related to input and output is found in tcp_in.c and tcp_out.c respectively.\n + */ + #include "lwip/opt.h" #if LWIP_TCP /* don't build if not configured for use in lwipopts.h */ @@ -1095,7 +1097,7 @@ tcp_slowtmr_start: if (pcb_remove) { struct tcp_pcb *pcb2; #if LWIP_CALLBACK_API - tcp_err_fn err_fn; + tcp_err_fn err_fn = pcb->errf; #endif /* LWIP_CALLBACK_API */ void *err_arg; tcp_pcb_purge(pcb); @@ -1114,9 +1116,6 @@ tcp_slowtmr_start: pcb->local_port, pcb->remote_port); } -#if LWIP_CALLBACK_API - err_fn = pcb->errf; -#endif /* LWIP_CALLBACK_API */ err_arg = pcb->callback_arg; pcb2 = pcb; pcb = pcb->next; @@ -1681,7 +1680,6 @@ tcp_sent(struct tcp_pcb *pcb, tcp_sent_fn sent) * @ingroup tcp_raw * Used to specify the function that should be called when a fatal error * has occurred on the connection. - * @note The corresponding pcb is already freed when this callback is called! * * @param pcb tcp_pcb to set the err callback * @param err callback function to call for this pcb when a fatal error diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h index 7c936229..318514c2 100644 --- a/src/include/lwip/opt.h +++ b/src/include/lwip/opt.h @@ -1325,6 +1325,13 @@ #if !defined(LWIP_EVENT_API) && !defined(LWIP_CALLBACK_API) || defined __DOXYGEN__ #define LWIP_EVENT_API 0 #define LWIP_CALLBACK_API 1 +#else +#ifndef LWIP_EVENT_API +#define LWIP_EVENT_API 0 +#endif +#ifndef LWIP_CALLBACK_API +#define LWIP_CALLBACK_API 0 +#endif #endif /** @@ -1359,7 +1366,7 @@ * Ethernet. */ #if !defined PBUF_LINK_HLEN || defined __DOXYGEN__ -#if defined LWIP_HOOK_VLAN_SET +#if defined LWIP_HOOK_VLAN_SET || defined __DOXYGEN__ #define PBUF_LINK_HLEN (18 + ETH_PAD_SIZE) #else /* LWIP_HOOK_VLAN_SET */ #define PBUF_LINK_HLEN (14 + ETH_PAD_SIZE) diff --git a/src/include/lwip/tcp.h b/src/include/lwip/tcp.h index 0ae49a0f..35584b45 100644 --- a/src/include/lwip/tcp.h +++ b/src/include/lwip/tcp.h @@ -350,11 +350,13 @@ struct tcp_pcb * tcp_new (void); struct tcp_pcb * tcp_new_ip_type (u8_t type); void tcp_arg (struct tcp_pcb *pcb, void *arg); -void tcp_accept (struct tcp_pcb *pcb, tcp_accept_fn accept); +#if LWIP_CALLBACK_API void tcp_recv (struct tcp_pcb *pcb, tcp_recv_fn recv); void tcp_sent (struct tcp_pcb *pcb, tcp_sent_fn sent); -void tcp_poll (struct tcp_pcb *pcb, tcp_poll_fn poll, u8_t interval); void tcp_err (struct tcp_pcb *pcb, tcp_err_fn err); +void tcp_accept (struct tcp_pcb *pcb, tcp_accept_fn accept); +#endif /* LWIP_CALLBACK_API */ +void tcp_poll (struct tcp_pcb *pcb, tcp_poll_fn poll, u8_t interval); #define tcp_mss(pcb) (((pcb)->flags & TF_TIMESTAMP) ? ((pcb)->mss - 12) : (pcb)->mss) #define tcp_sndbuf(pcb) (TCPWND16((pcb)->snd_buf)) From e4c01a064e051d11bd621e37d9006220e3923ff2 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Mon, 8 Aug 2016 14:21:23 +0800 Subject: [PATCH 040/325] mem: Include stdlib.h to fix build warnings when MEM_LIBC_MALLOC is set Include stdlib.h to fix below build warnings when MEM_LIBC_MALLOC is set: src/core/mem.c:119:3: warning: implicit declaration of function 'malloc' [-Wimplicit-function-declaration] void* ret = mem_clib_malloc(size + MEM_LIBC_STATSHELPER_SIZE); ^ src/core/mem.c:96:25: warning: incompatible implicit declaration of built-in function 'malloc' #define mem_clib_malloc malloc ^ src/core/mem.c:119:15: note: in expansion of macro 'mem_clib_malloc' void* ret = mem_clib_malloc(size + MEM_LIBC_STATSHELPER_SIZE); ^ src/core/mem.c: In function 'mem_free': src/core/mem.c:146:3: warning: implicit declaration of function 'free' [-Wimplicit-function-declaration] mem_clib_free(rmem); ^ src/core/mem.c:93:23: warning: incompatible implicit declaration of built-in function 'free' #define mem_clib_free free ^ src/core/mem.c:146:3: note: in expansion of macro 'mem_clib_free' mem_clib_free(rmem); ^ Signed-off-by: Axel Lin --- src/include/lwip/mem.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/include/lwip/mem.h b/src/include/lwip/mem.h index e4f6a64d..67aa4c6a 100644 --- a/src/include/lwip/mem.h +++ b/src/include/lwip/mem.h @@ -45,6 +45,7 @@ extern "C" { #if MEM_LIBC_MALLOC +#include #include /* for size_t */ typedef size_t mem_size_t; #define MEM_SIZE_F SZT_F From 219438fb24f2510c86e182bc84ca48b29dc03fe2 Mon Sep 17 00:00:00 2001 From: goldsimon Date: Mon, 8 Aug 2016 09:11:24 +0200 Subject: [PATCH 041/325] cleanup: move stdlib.h include to mem.c, where it belongs --- src/core/mem.c | 3 ++- src/include/lwip/mem.h | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/mem.c b/src/core/mem.c index 070d103a..a3003758 100644 --- a/src/core/mem.c +++ b/src/core/mem.c @@ -54,13 +54,14 @@ */ #include "lwip/opt.h" -#include "lwip/def.h" #include "lwip/mem.h" +#include "lwip/def.h" #include "lwip/sys.h" #include "lwip/stats.h" #include "lwip/err.h" #include +#include #if MEM_LIBC_MALLOC || MEM_USE_POOLS /** mem_init is not used when using pools instead of a heap or using diff --git a/src/include/lwip/mem.h b/src/include/lwip/mem.h index 67aa4c6a..e4f6a64d 100644 --- a/src/include/lwip/mem.h +++ b/src/include/lwip/mem.h @@ -45,7 +45,6 @@ extern "C" { #if MEM_LIBC_MALLOC -#include #include /* for size_t */ typedef size_t mem_size_t; #define MEM_SIZE_F SZT_F From eba6ae0122e7f777ede16e0722484a830e3a16f2 Mon Sep 17 00:00:00 2001 From: goldsimon Date: Mon, 8 Aug 2016 09:14:50 +0200 Subject: [PATCH 042/325] minor: add a comment about where to define LWIP_RAND() --- src/core/init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/init.c b/src/core/init.c index 22d5616c..dbd630dd 100644 --- a/src/core/init.c +++ b/src/core/init.c @@ -201,7 +201,7 @@ #error "LWIP_ETHERNET needs to be turned on for LWIP_ARP or PPPOE_SUPPORT" #endif #if (LWIP_IGMP || LWIP_IPV6) && !defined(LWIP_RAND) - #error "When using IGMP or IPv6, LWIP_RAND() needs to be defined to a random-function returning an u32_t random value" + #error "When using IGMP or IPv6, LWIP_RAND() needs to be defined to a random-function returning an u32_t random value (in arch/cc.h)" #endif #if LWIP_TCPIP_CORE_LOCKING_INPUT && !LWIP_TCPIP_CORE_LOCKING #error "When using LWIP_TCPIP_CORE_LOCKING_INPUT, LWIP_TCPIP_CORE_LOCKING must be enabled, too" From b1dfd00f9233d124514a36a8c8606990016f2ad4 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Mon, 8 Aug 2016 09:16:15 +0200 Subject: [PATCH 043/325] Minor netif documentation update --- src/include/lwip/netif.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/include/lwip/netif.h b/src/include/lwip/netif.h index 8903a563..1e08b756 100644 --- a/src/include/lwip/netif.h +++ b/src/include/lwip/netif.h @@ -358,11 +358,17 @@ void netif_set_default(struct netif *netif); void netif_set_ipaddr(struct netif *netif, const ip4_addr_t *ipaddr); void netif_set_netmask(struct netif *netif, const ip4_addr_t *netmask); void netif_set_gw(struct netif *netif, const ip4_addr_t *gw); +/** @ingroup netif */ #define netif_ip4_addr(netif) ((const ip4_addr_t*)ip_2_ip4(&((netif)->ip_addr))) +/** @ingroup netif */ #define netif_ip4_netmask(netif) ((const ip4_addr_t*)ip_2_ip4(&((netif)->netmask))) +/** @ingroup netif */ #define netif_ip4_gw(netif) ((const ip4_addr_t*)ip_2_ip4(&((netif)->gw))) +/** @ingroup netif */ #define netif_ip_addr4(netif) ((const ip_addr_t*)&((netif)->ip_addr)) +/** @ingroup netif */ #define netif_ip_netmask4(netif) ((const ip_addr_t*)&((netif)->netmask)) +/** @ingroup netif */ #define netif_ip_gw4(netif) ((const ip_addr_t*)&((netif)->gw)) #endif /* LWIP_IPV4 */ @@ -390,7 +396,9 @@ void netif_set_link_callback(struct netif *netif, netif_status_callback_fn link_ #endif /* LWIP_NETIF_LINK_CALLBACK */ #if LWIP_NETIF_HOSTNAME +/** @ingroup netif */ #define netif_set_hostname(netif, name) do { if((netif) != NULL) { (netif)->hostname = name; }}while(0) +/** @ingroup netif */ #define netif_get_hostname(netif) (((netif) != NULL) ? ((netif)->hostname) : NULL) #endif /* LWIP_NETIF_HOSTNAME */ From 282b8a2b6cd9191ba92cee46b887eca8dc4dcf20 Mon Sep 17 00:00:00 2001 From: Sylvain Rochet Date: Mon, 8 Aug 2016 11:55:31 +0200 Subject: [PATCH 044/325] PPP: set disconnect state before closing link protocol in ppp_close If LCP is not started yet, we are only closing the link protocol, in this case we have to set the disconnect state ourself because PPP is not actually started yet. --- src/netif/ppp/ppp.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/netif/ppp/ppp.c b/src/netif/ppp/ppp.c index a1588931..da5337ee 100644 --- a/src/netif/ppp/ppp.c +++ b/src/netif/ppp/ppp.c @@ -343,6 +343,7 @@ ppp_close(ppp_pcb *pcb, u8_t nocarrier) /* LCP not open, close link protocol */ if (pcb->phase < PPP_PHASE_ESTABLISH) { + new_phase(pcb, PPP_PHASE_DISCONNECT); ppp_link_terminated(pcb); return ERR_OK; } From fa568f775075965cef9f0e735b77f45e2d4d611e Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Mon, 8 Aug 2016 12:15:58 +0200 Subject: [PATCH 045/325] Fix typos in docs --- README | 2 +- UPGRADING | 2 +- doc/contrib.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README b/README index fb881317..dbcec5f2 100644 --- a/README +++ b/README @@ -77,7 +77,7 @@ Self documentation of the source code is regularly extracted from the current Git sources and is available from this web page: http://www.nongnu.org/lwip/ -There is now a constantly growin wiki about lwIP at +There is now a constantly growing wiki about lwIP at http://lwip.wikia.com/wiki/LwIP_Wiki Also, there are mailing lists you can subscribe at diff --git a/UPGRADING b/UPGRADING index cfd90f33..ea0c93f1 100644 --- a/UPGRADING +++ b/UPGRADING @@ -78,7 +78,7 @@ with newer versions. * support PBUF_REF for RX packets * LWIP_NETCONN_FULLDUPLEX allows netconn/sockets to be used for reading/writing from separate threads each (needs LWIP_NETCONN_SEM_PER_THREAD) - * Moved and reorderd stats (mainly memp/mib2) + * Moved and reordered stats (mainly memp/mib2) (1.4.0) diff --git a/doc/contrib.txt b/doc/contrib.txt index fa11dfec..6f0d7bc5 100644 --- a/doc/contrib.txt +++ b/doc/contrib.txt @@ -39,7 +39,7 @@ features of Savannah help us not lose users' input. bugtracker at Savannah. 3. If you have a fix put the patch on Savannah. If it is a patch that affects both core and arch specific stuff please separate them so that the core can - be applied separately while leaving the other patch 'open'. The prefered way + be applied separately while leaving the other patch 'open'. The preferred way is to NOT touch archs you can't test and let maintainers take care of them. This is a good way to see if they are used at all - the same goes for unix netifs except tapif. From 10332773ff3fdc27daf560510b35ed3cba1f9eeb Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Mon, 8 Aug 2016 16:09:26 +0200 Subject: [PATCH 046/325] Remove tcp_accepted() from rawapi.txt. Thanks to Sergio Caprile for pointing this out! --- doc/rawapi.txt | 9 --------- 1 file changed, 9 deletions(-) diff --git a/doc/rawapi.txt b/doc/rawapi.txt index ce5b42ab..763a0efc 100644 --- a/doc/rawapi.txt +++ b/doc/rawapi.txt @@ -171,15 +171,6 @@ incoming connections or be explicitly connected to another host. in the listen queue to the value specified by the backlog argument. To use it, your need to set TCP_LISTEN_BACKLOG=1 in your lwipopts.h. -- void tcp_accepted(struct tcp_pcb *pcb) - - Inform lwIP that an incoming connection has been accepted. This would - usually be called from the accept callback. This allows lwIP to perform - housekeeping tasks, such as allowing further incoming connections to be - queued in the listen backlog. - ATTENTION: the PCB passed in must be the listening pcb, not the pcb passed - into the accept callback! - - void tcp_accept(struct tcp_pcb *pcb, err_t (* accept)(void *arg, struct tcp_pcb *newpcb, err_t err)) From 1631307bb3cc86d94fd8ebf3f3f07c614e72a748 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Mon, 8 Aug 2016 21:42:27 +0200 Subject: [PATCH 047/325] tcp.c: Partly undo Simon's changes from today (repairs doxygen docs) --- src/core/tcp.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/core/tcp.c b/src/core/tcp.c index a3f8ea04..a132cb4e 100644 --- a/src/core/tcp.c +++ b/src/core/tcp.c @@ -2,6 +2,15 @@ * @file * Transmission Control Protocol for IP * See also @ref tcp_raw + * + * @defgroup tcp_raw TCP + * @ingroup callbackstyle_api + * Transmission Control Protocol for IP\n + * @see @ref raw_api and @ref netconn + * + * Common functions for the TCP implementation, such as functinos + * for manipulating the data structures and the TCP timer functions. TCP functions + * related to input and output is found in tcp_in.c and tcp_out.c respectively.\n */ /* @@ -36,17 +45,6 @@ * */ -/** - * @defgroup tcp_raw TCP - * @ingroup raw_api - * Transmission Control Protocol for IP\n - * @see @ref raw_api and @ref netconn - * - * Common functions for the TCP implementation, such as functinos - * for manipulating the data structures and the TCP timer functions. TCP functions - * related to input and output is found in tcp_in.c and tcp_out.c respectively.\n - */ - #include "lwip/opt.h" #if LWIP_TCP /* don't build if not configured for use in lwipopts.h */ From a2fd68098ea3912a71c14eab23032ea5c1de267b Mon Sep 17 00:00:00 2001 From: sg Date: Mon, 8 Aug 2016 21:47:20 +0200 Subject: [PATCH 048/325] minor: macros should not end with underscore(s) --- src/include/lwip/ip.h | 6 +++--- src/include/lwip/ip_addr.h | 6 +++--- src/include/netif/ppp/pppol2tp.h | 6 +++--- test/unit/core/test_mem.h | 4 ++-- test/unit/core/test_pbuf.h | 4 ++-- test/unit/dhcp/test_dhcp.h | 4 ++-- test/unit/etharp/test_etharp.h | 4 ++-- test/unit/lwip_check.h | 6 +++--- test/unit/lwipopts.h | 6 +++--- test/unit/tcp/tcp_helper.h | 4 ++-- test/unit/tcp/test_tcp.h | 4 ++-- test/unit/tcp/test_tcp_oos.h | 4 ++-- test/unit/udp/test_udp.h | 4 ++-- 13 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/include/lwip/ip.h b/src/include/lwip/ip.h index 0138caa8..44e5fd80 100644 --- a/src/include/lwip/ip.h +++ b/src/include/lwip/ip.h @@ -34,8 +34,8 @@ * Author: Adam Dunkels * */ -#ifndef LWIP_HDR_IP_H__ -#define LWIP_HDR_IP_H__ +#ifndef LWIP_HDR_IP_H +#define LWIP_HDR_IP_H #include "lwip/opt.h" @@ -322,6 +322,6 @@ err_t ip_input(struct pbuf *p, struct netif *inp); } #endif -#endif /* LWIP_HDR_IP_H__ */ +#endif /* LWIP_HDR_IP_H */ diff --git a/src/include/lwip/ip_addr.h b/src/include/lwip/ip_addr.h index d2690e8b..5523ee02 100644 --- a/src/include/lwip/ip_addr.h +++ b/src/include/lwip/ip_addr.h @@ -34,8 +34,8 @@ * Author: Adam Dunkels * */ -#ifndef LWIP_HDR_IP_ADDR_H__ -#define LWIP_HDR_IP_ADDR_H__ +#ifndef LWIP_HDR_IP_ADDR_H +#define LWIP_HDR_IP_ADDR_H #include "lwip/opt.h" #include "lwip/def.h" @@ -357,4 +357,4 @@ extern const ip_addr_t ip6_addr_any; } #endif -#endif /* LWIP_HDR_IP_ADDR_H__ */ +#endif /* LWIP_HDR_IP_ADDR_H */ diff --git a/src/include/netif/ppp/pppol2tp.h b/src/include/netif/ppp/pppol2tp.h index 93842556..f03950e6 100644 --- a/src/include/netif/ppp/pppol2tp.h +++ b/src/include/netif/ppp/pppol2tp.h @@ -34,8 +34,8 @@ #include "netif/ppp/ppp_opts.h" #if PPP_SUPPORT && PPPOL2TP_SUPPORT /* don't build if not configured for use in lwipopts.h */ -#ifndef PPPOL2TP_H_ -#define PPPOL2TP_H_ +#ifndef PPPOL2TP_H +#define PPPOL2TP_H #include "ppp.h" @@ -197,5 +197,5 @@ ppp_pcb *pppol2tp_create(struct netif *pppif, const u8_t *secret, u8_t secret_len, ppp_link_status_cb_fn link_status_cb, void *ctx_cb); -#endif /* PPPOL2TP_H_ */ +#endif /* PPPOL2TP_H */ #endif /* PPP_SUPPORT && PPPOL2TP_SUPPORT */ diff --git a/test/unit/core/test_mem.h b/test/unit/core/test_mem.h index a85bccb4..325134c3 100644 --- a/test/unit/core/test_mem.h +++ b/test/unit/core/test_mem.h @@ -1,5 +1,5 @@ -#ifndef LWIP_HDR_TEST_MEM_H__ -#define LWIP_HDR_TEST_MEM_H__ +#ifndef LWIP_HDR_TEST_MEM_H +#define LWIP_HDR_TEST_MEM_H #include "../lwip_check.h" diff --git a/test/unit/core/test_pbuf.h b/test/unit/core/test_pbuf.h index 82531570..da7730a4 100644 --- a/test/unit/core/test_pbuf.h +++ b/test/unit/core/test_pbuf.h @@ -1,5 +1,5 @@ -#ifndef LWIP_HDR_TEST_PBUF_H__ -#define LWIP_HDR_TEST_PBUF_H__ +#ifndef LWIP_HDR_TEST_PBUF_H +#define LWIP_HDR_TEST_PBUF_H #include "../lwip_check.h" diff --git a/test/unit/dhcp/test_dhcp.h b/test/unit/dhcp/test_dhcp.h index 480aab9b..0d88fa1b 100644 --- a/test/unit/dhcp/test_dhcp.h +++ b/test/unit/dhcp/test_dhcp.h @@ -1,5 +1,5 @@ -#ifndef LWIP_HDR_TEST_DHCP_H__ -#define LWIP_HDR_TEST_DHCP_H__ +#ifndef LWIP_HDR_TEST_DHCP_H +#define LWIP_HDR_TEST_DHCP_H #include "../lwip_check.h" diff --git a/test/unit/etharp/test_etharp.h b/test/unit/etharp/test_etharp.h index fac7c9cf..2dd772d8 100644 --- a/test/unit/etharp/test_etharp.h +++ b/test/unit/etharp/test_etharp.h @@ -1,5 +1,5 @@ -#ifndef LWIP_HDR_TEST_ETHARP_H__ -#define LWIP_HDR_TEST_ETHARP_H__ +#ifndef LWIP_HDR_TEST_ETHARP_H +#define LWIP_HDR_TEST_ETHARP_H #include "../lwip_check.h" diff --git a/test/unit/lwip_check.h b/test/unit/lwip_check.h index 2126e2ff..0c218d1d 100644 --- a/test/unit/lwip_check.h +++ b/test/unit/lwip_check.h @@ -1,5 +1,5 @@ -#ifndef LWIP_HDR_LWIP_CHECK_H__ -#define LWIP_HDR_LWIP_CHECK_H__ +#ifndef LWIP_HDR_LWIP_CHECK_H +#define LWIP_HDR_LWIP_CHECK_H /* Common header file for lwIP unit tests using the check framework */ @@ -34,4 +34,4 @@ Suite* create_suite(const char* name, testfunc *tests, size_t num_tests, SFun se int lwip_unittests_run(void) #endif -#endif /* LWIP_HDR_LWIP_CHECK_H__ */ +#endif /* LWIP_HDR_LWIP_CHECK_H */ diff --git a/test/unit/lwipopts.h b/test/unit/lwipopts.h index 5cda4315..516a8493 100644 --- a/test/unit/lwipopts.h +++ b/test/unit/lwipopts.h @@ -29,8 +29,8 @@ * Author: Simon Goldschmidt * */ -#ifndef LWIP_HDR_LWIPOPTS_H__ -#define LWIP_HDR_LWIPOPTS_H__ +#ifndef LWIP_HDR_LWIPOPTS_H +#define LWIP_HDR_LWIPOPTS_H /* Prevent having to link sys_arch.c (we don't test the API layers in unit tests) */ #define NO_SYS 1 @@ -54,4 +54,4 @@ /* Minimal changes to opt.h required for etharp unit tests: */ #define ETHARP_SUPPORT_STATIC_ENTRIES 1 -#endif /* LWIP_HDR_LWIPOPTS_H__ */ +#endif /* LWIP_HDR_LWIPOPTS_H */ diff --git a/test/unit/tcp/tcp_helper.h b/test/unit/tcp/tcp_helper.h index 4119f37e..04974818 100644 --- a/test/unit/tcp/tcp_helper.h +++ b/test/unit/tcp/tcp_helper.h @@ -1,5 +1,5 @@ -#ifndef LWIP_HDR_TCP_HELPER_H__ -#define LWIP_HDR_TCP_HELPER_H__ +#ifndef LWIP_HDR_TCP_HELPER_H +#define LWIP_HDR_TCP_HELPER_H #include "../lwip_check.h" #include "lwip/arch.h" diff --git a/test/unit/tcp/test_tcp.h b/test/unit/tcp/test_tcp.h index ea739eba..f28ee565 100644 --- a/test/unit/tcp/test_tcp.h +++ b/test/unit/tcp/test_tcp.h @@ -1,5 +1,5 @@ -#ifndef LWIP_HDR_TEST_TCP_H__ -#define LWIP_HDR_TEST_TCP_H__ +#ifndef LWIP_HDR_TEST_TCP_H +#define LWIP_HDR_TEST_TCP_H #include "../lwip_check.h" diff --git a/test/unit/tcp/test_tcp_oos.h b/test/unit/tcp/test_tcp_oos.h index 1cb8650f..5b82013b 100644 --- a/test/unit/tcp/test_tcp_oos.h +++ b/test/unit/tcp/test_tcp_oos.h @@ -1,5 +1,5 @@ -#ifndef LWIP_HDR_TEST_TCP_OOS_H__ -#define LWIP_HDR_TEST_TCP_OOS_H__ +#ifndef LWIP_HDR_TEST_TCP_OOS_H +#define LWIP_HDR_TEST_TCP_OOS_H #include "../lwip_check.h" diff --git a/test/unit/udp/test_udp.h b/test/unit/udp/test_udp.h index eb14354b..5426bf42 100644 --- a/test/unit/udp/test_udp.h +++ b/test/unit/udp/test_udp.h @@ -1,5 +1,5 @@ -#ifndef LWIP_HDR_TEST_UDP_H__ -#define LWIP_HDR_TEST_UDP_H__ +#ifndef LWIP_HDR_TEST_UDP_H +#define LWIP_HDR_TEST_UDP_H #include "../lwip_check.h" From 4b41ef551e562fa29edf4c1bcb1afe4b38f8718f Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Mon, 8 Aug 2016 21:55:08 +0200 Subject: [PATCH 049/325] Add note about Filelists.mk in UPGRADING document --- UPGRADING | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/UPGRADING b/UPGRADING index ea0c93f1..b9ad876a 100644 --- a/UPGRADING +++ b/UPGRADING @@ -20,7 +20,7 @@ with newer versions. * Added IPv6 support (dual-stack or IPv4/IPv6 only) * Changed ip_addr_t to be a union in dual-stack mode (use ip4_addr_t where referring to IPv4 only). * Major rewrite of SNMP (added MIB parser that creates code stubs for custom MIBs); - supports SNMP2vc (experimental v3 support) + supports SNMPv2c (experimental v3 support) * Moved some core applications from contrib repository to src/apps (and include/lwip/apps) +++ Raw API: @@ -34,7 +34,8 @@ with newer versions. ++ Port changes +++ new files: - * MANY new and moved files! + * MANY new and moved files! + * Added src/Filelists.mk for use in Makefile projects * Continued moving stack-internal parts from abc.h to abc_priv.h in sub-folder "priv" to let abc.h only contain the actual application programmer's API From e5284ec61643fbaba3a184d080338d55306bf2aa Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Mon, 8 Aug 2016 22:01:38 +0200 Subject: [PATCH 050/325] Minor: documentation cosmetics --- src/include/lwip/opt.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h index 318514c2..39c45b9a 100644 --- a/src/include/lwip/opt.h +++ b/src/include/lwip/opt.h @@ -1366,7 +1366,7 @@ * Ethernet. */ #if !defined PBUF_LINK_HLEN || defined __DOXYGEN__ -#if defined LWIP_HOOK_VLAN_SET || defined __DOXYGEN__ +#if defined LWIP_HOOK_VLAN_SET && !defined __DOXYGEN__ #define PBUF_LINK_HLEN (18 + ETH_PAD_SIZE) #else /* LWIP_HOOK_VLAN_SET */ #define PBUF_LINK_HLEN (14 + ETH_PAD_SIZE) From 85ab39985a0cbb963110214b00ddfb080e64061c Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Mon, 8 Aug 2016 22:15:01 +0200 Subject: [PATCH 051/325] Fix a few incorrect uses of err_t. Found by converting lwip error codes to an enum, but I'm not sure wether I want to commit the actual enum conversion. --- src/apps/lwiperf/lwiperf.c | 5 +++-- src/apps/sntp/sntp.c | 2 +- src/core/ipv6/ip6_frag.c | 12 ++++++------ src/netif/ppp/pppoe.c | 2 +- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/apps/lwiperf/lwiperf.c b/src/apps/lwiperf/lwiperf.c index 06868676..1682f358 100644 --- a/src/apps/lwiperf/lwiperf.c +++ b/src/apps/lwiperf/lwiperf.c @@ -405,6 +405,7 @@ lwiperf_tx_start(lwiperf_state_tcp_t* conn) static err_t lwiperf_tcp_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err) { + u8_t tmp; u16_t tot_len; u32_t packet_idx; struct pbuf* q; @@ -470,8 +471,8 @@ lwiperf_tcp_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err) return ERR_OK; } conn->next_num = 4; /* 24 bytes received... */ - err = pbuf_header(p, -24); - LWIP_ASSERT("pbuf_header failed", err == ERR_OK); + tmp = pbuf_header(p, -24); + LWIP_ASSERT("pbuf_header failed", tmp == 0); } packet_idx = 0; diff --git a/src/apps/sntp/sntp.c b/src/apps/sntp/sntp.c index 8d43eb0b..a9143180 100644 --- a/src/apps/sntp/sntp.c +++ b/src/apps/sntp/sntp.c @@ -94,7 +94,7 @@ #define SNTP_DEBUG_WARN_STATE (SNTP_DEBUG | LWIP_DBG_LEVEL_WARNING | LWIP_DBG_STATE) #define SNTP_DEBUG_SERIOUS (SNTP_DEBUG | LWIP_DBG_LEVEL_SERIOUS) -#define SNTP_ERR_KOD 1 +#define SNTP_ERR_KOD ERR_CLSD /* SNTP protocol defines */ #define SNTP_MSG_LEN 48 diff --git a/src/core/ipv6/ip6_frag.c b/src/core/ipv6/ip6_frag.c index f574d380..a5f28906 100644 --- a/src/core/ipv6/ip6_frag.c +++ b/src/core/ipv6/ip6_frag.c @@ -377,8 +377,8 @@ ip6_reass(struct pbuf *p) if (IPV6_FRAG_REQROOM > 0) { /* Make room for struct ip6_reass_helper (only required if sizeof(void*) > 4). This cannot fail since we already checked when receiving this fragment. */ - err_t hdrerr = pbuf_header_force(p, IPV6_FRAG_REQROOM); - LWIP_ASSERT("no room for struct ip6_reass_helper", hdrerr == ERR_OK); + u8_t hdrerr = pbuf_header_force(p, IPV6_FRAG_REQROOM); + LWIP_ASSERT("no room for struct ip6_reass_helper", hdrerr == 0); } #else /* IPV6_FRAG_COPYHEADER */ LWIP_ASSERT("sizeof(struct ip6_reass_helper) <= IP6_FRAG_HLEN, set IPV6_FRAG_COPYHEADER to 1", @@ -528,8 +528,8 @@ ip6_reass(struct pbuf *p) #if IPV6_FRAG_COPYHEADER if (IPV6_FRAG_REQROOM > 0) { /* hide the extra bytes borrowed from ip6_hdr for struct ip6_reass_helper */ - err_t hdrerr = pbuf_header(next_pbuf, -(s16_t)(IPV6_FRAG_REQROOM)); - LWIP_ASSERT("no room for struct ip6_reass_helper", hdrerr == ERR_OK); + u8_t hdrerr = pbuf_header(next_pbuf, -(s16_t)(IPV6_FRAG_REQROOM)); + LWIP_ASSERT("no room for struct ip6_reass_helper", hdrerr == 0); } #endif pbuf_cat(ipr->p, next_pbuf); @@ -544,8 +544,8 @@ ip6_reass(struct pbuf *p) #if IPV6_FRAG_COPYHEADER if (IPV6_FRAG_REQROOM > 0) { /* get back room for struct ip6_reass_helper (only required if sizeof(void*) > 4) */ - err_t hdrerr = pbuf_header(ipr->p, -(s16_t)(IPV6_FRAG_REQROOM)); - LWIP_ASSERT("no room for struct ip6_reass_helper", hdrerr == ERR_OK); + u8_t hdrerr = pbuf_header(ipr->p, -(s16_t)(IPV6_FRAG_REQROOM)); + LWIP_ASSERT("no room for struct ip6_reass_helper", hdrerr == 0); } iphdr_ptr = (struct ip6_hdr*)((u8_t*)ipr->p->payload - IP6_HLEN); MEMCPY(iphdr_ptr, &ipr->iphdr, IP6_HLEN); diff --git a/src/netif/ppp/pppoe.c b/src/netif/ppp/pppoe.c index 1530611d..24d9c4f5 100644 --- a/src/netif/ppp/pppoe.c +++ b/src/netif/ppp/pppoe.c @@ -881,7 +881,7 @@ pppoe_timeout(void *arg) static err_t pppoe_connect(ppp_pcb *ppp, void *ctx) { - int err; + err_t err; struct pppoe_softc *sc = (struct pppoe_softc *)ctx; lcp_options *lcp_wo; lcp_options *lcp_ao; From 61dae47a71dc77fe13f5d979d461abe42cef280a Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Mon, 8 Aug 2016 22:40:57 +0200 Subject: [PATCH 052/325] Relete SNMP README and incorporate it's text in doxygen docs --- src/apps/snmp/README | 38 -------------------------------------- src/apps/snmp/snmp_core.c | 39 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 39 deletions(-) delete mode 100644 src/apps/snmp/README diff --git a/src/apps/snmp/README b/src/apps/snmp/README deleted file mode 100644 index d2815ec8..00000000 --- a/src/apps/snmp/README +++ /dev/null @@ -1,38 +0,0 @@ -lwIP SNMPv2c agent -================== - -Based on SNMP stack written by Christiaan Simons - -Rewritten by Martin Hentschel and -Dirk Ziegelmeier - -Features: - - SNMPv2c support. - - Low RAM usage - no memory pools, stack only. - - MIB2 implementation is separated from SNMP stack. - - Support for multiple MIBs (snmp_set_mibs() call) - e.g. for private MIB. - - Simple and generic API for MIB implementation. - - Comfortable node types and helper functions for scalar arrays and tables. - - Counter64, bit and truthvalue datatype support. - - Callbacks for SNMP writes e.g. to implement persistency. - - Runs on two APIs: RAW and netconn. - - Async API is gone - the stack now supports netconn API instead, - so blocking operations can be done in MIB calls. - SNMP runs in a worker thread when netconn API is used. - - Simplified thread sync support for MIBs - useful when MIBs - need to access variables shared with other threads where no locking is - possible. Used in MIB2 to access lwIP stats from lwIP thread. - -MIB compiler (code generator): - - Written in C#. MIB viewer used Windows Forms. - - Developed on Windows with Visual Studio 2010. - - Can be compiled and used under Linux with http://www.monodevelop.com/. - - Based on a heavily modified version of of SharpSnmpLib (a4bd05c6afb4) - (https://sharpsnmplib.codeplex.com/SourceControl/network/forks/Nemo157/MIBParserUpdate). - - MIB parser, C file generation framework and LWIP code generation are cleanly - separated, which means the code may be useful as a base for code generation - of other SNMP agents. - -Notes: - - Stack and MIB compiler were used to implement a Profinet device. - Compiled/implemented MIBs: LLDP-MIB, LLDP-EXT-DOT3-MIB, LLDP-EXT-PNO-MIB. diff --git a/src/apps/snmp/snmp_core.c b/src/apps/snmp/snmp_core.c index 0887243c..bdefd08e 100644 --- a/src/apps/snmp/snmp_core.c +++ b/src/apps/snmp/snmp_core.c @@ -42,11 +42,48 @@ * The agent implements the most important MIB2 MIBs including IPv6 support * (interfaces, UDP, TCP, SNMP, ICMP, SYSTEM). IP MIB is an older version * whithout IPv6 statistics (TODO).\n - * Work on SNMPv3 has started, but is not finished. + * Rewritten by Martin Hentschel and + * Dirk Ziegelmeier \n + * Work on SNMPv3 has started, but is not finished.\n * * 0 Agent Capabilities * ==================== * + * Features: + * --------- + * - SNMPv2c support. + * - Low RAM usage - no memory pools, stack only. + * - MIB2 implementation is separated from SNMP stack. + * - Support for multiple MIBs (snmp_set_mibs() call) - e.g. for private MIB. + * - Simple and generic API for MIB implementation. + * - Comfortable node types and helper functions for scalar arrays and tables. + * - Counter64, bit and truthvalue datatype support. + * - Callbacks for SNMP writes e.g. to implement persistency. + * - Runs on two APIs: RAW and netconn. + * - Async API is gone - the stack now supports netconn API instead, + * so blocking operations can be done in MIB calls. + * SNMP runs in a worker thread when netconn API is used. + * - Simplified thread sync support for MIBs - useful when MIBs + * need to access variables shared with other threads where no locking is + * possible. Used in MIB2 to access lwIP stats from lwIP thread. + * + * MIB compiler (code generator): + * ------------------------------ + * - Provided in lwIP contrib repository. + * - Written in C#. MIB viewer used Windows Forms. + * - Developed on Windows with Visual Studio 2010. + * - Can be compiled and used on all platforms with http://www.monodevelop.com/. + * - Based on a heavily modified version of of SharpSnmpLib (a4bd05c6afb4) + * (https://sharpsnmplib.codeplex.com/SourceControl/network/forks/Nemo157/MIBParserUpdate). + * - MIB parser, C file generation framework and LWIP code generation are cleanly + * separated, which means the code may be useful as a base for code generation + * of other SNMP agents. + * + * Notes: + * ------ + * - Stack and MIB compiler were used to implement a Profinet device. + * Compiled/implemented MIBs: LLDP-MIB, LLDP-EXT-DOT3-MIB, LLDP-EXT-PNO-MIB. + * * SNMPv1 per RFC1157 and SNMPv2c per RFC 3416 * ------------------------------------------- * Note the S in SNMP stands for "Simple". Note that "Simple" is From 6ba03d543fd0705db302e0931d2ebc056040288f Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Tue, 9 Aug 2016 08:18:42 +0200 Subject: [PATCH 053/325] Activate TCP backlog in documentation --- doc/doxygen/lwip.Doxyfile | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/doxygen/lwip.Doxyfile b/doc/doxygen/lwip.Doxyfile index 9f20830f..31f57657 100644 --- a/doc/doxygen/lwip.Doxyfile +++ b/doc/doxygen/lwip.Doxyfile @@ -2080,6 +2080,7 @@ PREDEFINED = __DOXYGEN__=1 \ LWIP_UDP=1 \ LWIP_IGMP=1 \ LWIP_TCP=1 \ + TCP_LISTEN_BACKLOG=1 \ LWIP_SNMP=1 \ SNMP_USE_NETCONN=1 \ SNMP_USE_RAW=1 \ From 0005b7c2d008603356bc8f8692310e80eb5c7a16 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Tue, 9 Aug 2016 08:20:28 +0200 Subject: [PATCH 054/325] Revert my last change in sntp.c - allow usage of custom error values in err_t --- src/apps/sntp/sntp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/apps/sntp/sntp.c b/src/apps/sntp/sntp.c index a9143180..8d43eb0b 100644 --- a/src/apps/sntp/sntp.c +++ b/src/apps/sntp/sntp.c @@ -94,7 +94,7 @@ #define SNTP_DEBUG_WARN_STATE (SNTP_DEBUG | LWIP_DBG_LEVEL_WARNING | LWIP_DBG_STATE) #define SNTP_DEBUG_SERIOUS (SNTP_DEBUG | LWIP_DBG_LEVEL_SERIOUS) -#define SNTP_ERR_KOD ERR_CLSD +#define SNTP_ERR_KOD 1 /* SNTP protocol defines */ #define SNTP_MSG_LEN 48 From 5a09fd3e35121244ad47fad9aff7dad585dbfefc Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Tue, 9 Aug 2016 10:16:40 +0200 Subject: [PATCH 055/325] Don't document ip4_route and ip6_route, users should use ip_route instead --- src/core/ipv4/ip4.c | 1 - src/core/ipv6/ip6.c | 1 - 2 files changed, 2 deletions(-) diff --git a/src/core/ipv4/ip4.c b/src/core/ipv4/ip4.c index ff7b937c..fb6777a6 100644 --- a/src/core/ipv4/ip4.c +++ b/src/core/ipv4/ip4.c @@ -136,7 +136,6 @@ ip4_route_src(const ip4_addr_t *dest, const ip4_addr_t *src) #endif /* LWIP_HOOK_IP4_ROUTE_SRC */ /** - * @ingroup ip4 * Finds the appropriate network interface for a given IP address. It * searches the list of network interfaces linearly. A match is found * if the masked IP address of the network interface equals the masked diff --git a/src/core/ipv6/ip6.c b/src/core/ipv6/ip6.c index bfbe453f..aa39f58c 100644 --- a/src/core/ipv6/ip6.c +++ b/src/core/ipv6/ip6.c @@ -60,7 +60,6 @@ #include "lwip/stats.h" /** - * @ingroup ip6 * Finds the appropriate network interface for a given IPv6 address. It tries to select * a netif following a sequence of heuristics: * 1) if there is only 1 netif, return it From 5c0944e01ab00135fd7e984b6abe3004a980f347 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Tue, 9 Aug 2016 10:17:16 +0200 Subject: [PATCH 056/325] Don't document tcp_send_empty_ack and tcp_keepalive - users should never need them --- src/core/tcp_out.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/core/tcp_out.c b/src/core/tcp_out.c index 4808f247..610cbd83 100644 --- a/src/core/tcp_out.c +++ b/src/core/tcp_out.c @@ -876,7 +876,6 @@ tcp_build_wnd_scale_option(u32_t *opts) #endif /** - * @ingroup tcp_raw * Send an ACK without data. * * @param pcb Protocol control block for the TCP connection to send the ACK @@ -1469,7 +1468,6 @@ tcp_rexmit_fast(struct tcp_pcb *pcb) /** - * @ingroup tcp_raw * Send keepalive packets to keep a connection active although * no data is sent over it. * From 18fcc1d50425817bc9ab85cfc8e74d4a1c9f0ac5 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Tue, 9 Aug 2016 21:52:13 +0200 Subject: [PATCH 057/325] [PATCH] debug: Add braces around empty body in an 'if' statement I have below code in my cc.h: #ifdef MYSDK_LWIP_DEBUG #define LWIP_PLATFORM_ASSERT(x) MYSDK_ASSERTION_FAIL_ACTION() #else #define LWIP_PLATFORM_ASSERT(x) #endif /* ifdef MYSDK_LWIP_DEBUG */ I got below error when in non-debug build: src/include/lwip/debug.h:76:32: error: suggest braces around empty body in an 'if' statement [-Werror=empty-body] LWIP_PLATFORM_ASSERT(message); } while(0) ^ Fix the build error by adding braces around empty body in an 'if' statement. Signed-off-by: Axel Lin Signed-off-by: sg --- src/include/lwip/debug.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/include/lwip/debug.h b/src/include/lwip/debug.h index cd6eacff..c6766120 100644 --- a/src/include/lwip/debug.h +++ b/src/include/lwip/debug.h @@ -72,8 +72,8 @@ * -- To disable assertions define LWIP_NOASSERT in arch/cc.h. */ #ifndef LWIP_NOASSERT -#define LWIP_ASSERT(message, assertion) do { if(!(assertion)) \ - LWIP_PLATFORM_ASSERT(message); } while(0) +#define LWIP_ASSERT(message, assertion) do { if (!(assertion)) { \ + LWIP_PLATFORM_ASSERT(message); }} while(0) #ifndef LWIP_PLATFORM_ASSERT #error "If you want to use LWIP_ASSERT, LWIP_PLATFORM_ASSERT(message) needs to be defined in your arch/cc.h" #endif From 3194c9c4cf33f310759702fad11d7034b849fc96 Mon Sep 17 00:00:00 2001 From: Sylvain Rochet Date: Wed, 10 Aug 2016 23:33:16 +0200 Subject: [PATCH 058/325] PPP: filter more packets in ppp_dump_packet VJ packets, Compressed packets, IPv4 and IPv6 packets are useless in the PPP packet dump. We properly filtered IPv4 and IPv6 packets but we forgot filtering VJ and Compressed packets. Improve the filtering rule to filter packets which are not auth protocol (< 0xC000) and which are not control protocol (0x8000 bit not set). --- src/netif/ppp/utils.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/netif/ppp/utils.c b/src/netif/ppp/utils.c index 5b14ac59..be53c0c6 100644 --- a/src/netif/ppp/utils.c +++ b/src/netif/ppp/utils.c @@ -706,15 +706,11 @@ void ppp_dump_packet(const char *tag, unsigned char *p, int len) { int proto; /* - * don't print IPv4 and IPv6 packets. + * don't print data packets, i.e. IPv4, IPv6, VJ, and compressed packets. */ proto = (p[0] << 8) + p[1]; - if (proto == PPP_IP) + if (proto < 0xC000 && (proto & ~0x8000) == proto) return; -#if PPP_IPV6_SUPPORT - if (proto == PPP_IPV6) - return; -#endif /* * don't print LCP echo request/reply packets if the link is up. From bf3e8e6a482ef4098e6f4ba34f39f17a51ac68b7 Mon Sep 17 00:00:00 2001 From: goldsimon Date: Thu, 11 Aug 2016 09:23:43 +0200 Subject: [PATCH 059/325] minor coding style fixes in IPv6 code --- src/core/ipv6/icmp6.c | 4 +- src/core/ipv6/ip6.c | 8 +-- src/core/ipv6/ip6_addr.c | 2 +- src/core/ipv6/ip6_frag.c | 4 +- src/core/ipv6/mld6.c | 12 ++--- src/core/ipv6/nd6.c | 102 ++++++++++++++++++------------------ src/include/lwip/ip6_frag.h | 2 +- src/include/lwip/nd6.h | 18 +++---- 8 files changed, 76 insertions(+), 76 deletions(-) diff --git a/src/core/ipv6/icmp6.c b/src/core/ipv6/icmp6.c index 397d2d6b..e4df692e 100644 --- a/src/core/ipv6/icmp6.c +++ b/src/core/ipv6/icmp6.c @@ -80,8 +80,8 @@ void icmp6_input(struct pbuf *p, struct netif *inp) { struct icmp6_hdr *icmp6hdr; - struct pbuf * r; - const ip6_addr_t * reply_src; + struct pbuf *r; + const ip6_addr_t *reply_src; ICMP6_STATS_INC(icmp6.recv); diff --git a/src/core/ipv6/ip6.c b/src/core/ipv6/ip6.c index aa39f58c..6ed95c93 100644 --- a/src/core/ipv6/ip6.c +++ b/src/core/ipv6/ip6.c @@ -203,7 +203,7 @@ ip6_route(const ip6_addr_t *src, const ip6_addr_t *dest) * source address is found */ const ip_addr_t * -ip6_select_source_address(struct netif *netif, const ip6_addr_t * dest) +ip6_select_source_address(struct netif *netif, const ip6_addr_t *dest) { const ip_addr_t *src = NULL; u8_t i; @@ -642,7 +642,7 @@ netif_found: case IP6_NEXTH_FRAGMENT: { - struct ip6_frag_hdr * frag_hdr; + struct ip6_frag_hdr *frag_hdr; LWIP_DEBUGF(IP6_DEBUG, ("ip6_input: packet with Fragment header\n")); frag_hdr = (struct ip6_frag_hdr *)p->payload; @@ -1034,9 +1034,9 @@ ip6_output_hinted(struct pbuf *p, const ip6_addr_t *src, const ip6_addr_t *dest, * @return ERR_OK if hop-by-hop header was added, ERR_* otherwise */ err_t -ip6_options_add_hbh_ra(struct pbuf * p, u8_t nexth, u8_t value) +ip6_options_add_hbh_ra(struct pbuf *p, u8_t nexth, u8_t value) { - struct ip6_hbh_hdr * hbh_hdr; + struct ip6_hbh_hdr *hbh_hdr; /* Move pointer to make room for hop-by-hop options header. */ if (pbuf_header(p, sizeof(struct ip6_hbh_hdr))) { diff --git a/src/core/ipv6/ip6_addr.c b/src/core/ipv6/ip6_addr.c index 7f14db44..1792f62e 100644 --- a/src/core/ipv6/ip6_addr.c +++ b/src/core/ipv6/ip6_addr.c @@ -73,7 +73,7 @@ int ip6addr_aton(const char *cp, ip6_addr_t *addr) { u32_t addr_index, zero_blocks, current_block_index, current_block_value; - const char * s; + const char *s; /* Count the number of colons, to count the number of blocks in a "::" sequence zero_blocks may be 1 even if there are no :: sequences */ diff --git a/src/core/ipv6/ip6_frag.c b/src/core/ipv6/ip6_frag.c index a5f28906..f41d167f 100644 --- a/src/core/ipv6/ip6_frag.c +++ b/src/core/ipv6/ip6_frag.c @@ -260,7 +260,7 @@ ip6_reass(struct pbuf *p) { struct ip6_reassdata *ipr, *ipr_prev; struct ip6_reass_helper *iprh, *iprh_tmp, *iprh_prev=NULL; - struct ip6_frag_hdr * frag_hdr; + struct ip6_frag_hdr *frag_hdr; u16_t offset, len; u8_t clen, valid = 1; struct pbuf *q; @@ -655,7 +655,7 @@ ip6_frag(struct pbuf *p, struct netif *netif, const ip6_addr_t *dest) { struct ip6_hdr *original_ip6hdr; struct ip6_hdr *ip6hdr; - struct ip6_frag_hdr * frag_hdr; + struct ip6_frag_hdr *frag_hdr; struct pbuf *rambuf; struct pbuf *newpbuf; static u32_t identification; diff --git a/src/core/ipv6/mld6.c b/src/core/ipv6/mld6.c index 82510019..e407a12a 100644 --- a/src/core/ipv6/mld6.c +++ b/src/core/ipv6/mld6.c @@ -80,7 +80,7 @@ static struct mld_group* mld_group_list; /* Forward declarations. */ -static struct mld_group * mld6_new_group(struct netif *ifp, const ip6_addr_t *addr); +static struct mld_group *mld6_new_group(struct netif *ifp, const ip6_addr_t *addr); static err_t mld6_free_group(struct mld_group *group); static void mld6_delayed_report(struct mld_group *group, u16_t maxresp); static void mld6_send(struct mld_group *group, u8_t type); @@ -242,8 +242,8 @@ mld6_free_group(struct mld_group *group) void mld6_input(struct pbuf *p, struct netif *inp) { - struct mld_header * mld_hdr; - struct mld_group* group; + struct mld_header *mld_hdr; + struct mld_group *group; MLD6_STATS_INC(mld6.recv); @@ -538,9 +538,9 @@ mld6_delayed_report(struct mld_group *group, u16_t maxresp) static void mld6_send(struct mld_group *group, u8_t type) { - struct mld_header * mld_hdr; - struct pbuf * p; - const ip6_addr_t * src_addr; + struct mld_header *mld_hdr; + struct pbuf *p; + const ip6_addr_t *src_addr; /* Allocate a packet. Size is MLD header + IPv6 Hop-by-hop options header. */ p = pbuf_alloc(PBUF_IP, sizeof(struct mld_header) + sizeof(struct ip6_hbh_hdr), PBUF_RAM); diff --git a/src/core/ipv6/nd6.c b/src/core/ipv6/nd6.c index cefd013d..4dacd4fc 100644 --- a/src/core/ipv6/nd6.c +++ b/src/core/ipv6/nd6.c @@ -82,23 +82,23 @@ static ip6_addr_t multicast_address; static u8_t nd6_ra_buffer[sizeof(struct prefix_option)]; /* Forward declarations. */ -static s8_t nd6_find_neighbor_cache_entry(const ip6_addr_t * ip6addr); +static s8_t nd6_find_neighbor_cache_entry(const ip6_addr_t *ip6addr); static s8_t nd6_new_neighbor_cache_entry(void); static void nd6_free_neighbor_cache_entry(s8_t i); -static s8_t nd6_find_destination_cache_entry(const ip6_addr_t * ip6addr); +static s8_t nd6_find_destination_cache_entry(const ip6_addr_t *ip6addr); static s8_t nd6_new_destination_cache_entry(void); -static s8_t nd6_is_prefix_in_netif(const ip6_addr_t * ip6addr, struct netif * netif); -static s8_t nd6_get_router(const ip6_addr_t * router_addr, struct netif * netif); -static s8_t nd6_new_router(const ip6_addr_t * router_addr, struct netif * netif); -static s8_t nd6_get_onlink_prefix(ip6_addr_t * prefix, struct netif * netif); -static s8_t nd6_new_onlink_prefix(ip6_addr_t * prefix, struct netif * netif); +static s8_t nd6_is_prefix_in_netif(const ip6_addr_t *ip6addr, struct netif *netif); +static s8_t nd6_get_router(const ip6_addr_t *router_addr, struct netif *netif); +static s8_t nd6_new_router(const ip6_addr_t *router_addr, struct netif *netif); +static s8_t nd6_get_onlink_prefix(ip6_addr_t *prefix, struct netif *netif); +static s8_t nd6_new_onlink_prefix(ip6_addr_t *prefix, struct netif *netif); #define ND6_SEND_FLAG_MULTICAST_DEST 0x01 #define ND6_SEND_FLAG_ALLNODES_DEST 0x02 -static void nd6_send_ns(struct netif * netif, const ip6_addr_t * target_addr, u8_t flags); -static void nd6_send_na(struct netif * netif, const ip6_addr_t * target_addr, u8_t flags); +static void nd6_send_ns(struct netif *netif, const ip6_addr_t *target_addr, u8_t flags); +static void nd6_send_na(struct netif *netif, const ip6_addr_t *target_addr, u8_t flags); #if LWIP_IPV6_SEND_ROUTER_SOLICIT -static err_t nd6_send_rs(struct netif * netif); +static err_t nd6_send_rs(struct netif *netif); #endif /* LWIP_IPV6_SEND_ROUTER_SOLICIT */ #if LWIP_ND6_QUEUEING @@ -127,8 +127,8 @@ nd6_input(struct pbuf *p, struct netif *inp) switch (msg_type) { case ICMP6_TYPE_NA: /* Neighbor Advertisement. */ { - struct na_header * na_hdr; - struct lladdr_option * lladdr_opt; + struct na_header *na_hdr; + struct lladdr_option *lladdr_opt; /* Check that na header fits in packet. */ if (p->len < (sizeof(struct na_header))) { @@ -262,8 +262,8 @@ nd6_input(struct pbuf *p, struct netif *inp) } case ICMP6_TYPE_NS: /* Neighbor solicitation. */ { - struct ns_header * ns_hdr; - struct lladdr_option * lladdr_opt; + struct ns_header *ns_hdr; + struct lladdr_option *lladdr_opt; u8_t accepted; /* Check that ns header fits in packet. */ @@ -374,8 +374,8 @@ nd6_input(struct pbuf *p, struct netif *inp) } case ICMP6_TYPE_RA: /* Router Advertisement. */ { - struct ra_header * ra_hdr; - u8_t * buffer; /* Used to copy options. */ + struct ra_header *ra_hdr; + u8_t *buffer; /* Used to copy options. */ u16_t offset; /* Check that RA header fits in packet. */ @@ -453,7 +453,7 @@ nd6_input(struct pbuf *p, struct netif *inp) switch (buffer[0]) { case ND6_OPTION_TYPE_SOURCE_LLADDR: { - struct lladdr_option * lladdr_opt; + struct lladdr_option *lladdr_opt; lladdr_opt = (struct lladdr_option *)buffer; if ((default_router_list[i].neighbor_entry != NULL) && (default_router_list[i].neighbor_entry->state == ND6_INCOMPLETE)) { @@ -465,7 +465,7 @@ nd6_input(struct pbuf *p, struct netif *inp) } case ND6_OPTION_TYPE_MTU: { - struct mtu_option * mtu_opt; + struct mtu_option *mtu_opt; mtu_opt = (struct mtu_option *)buffer; if (htonl(mtu_opt->mtu) >= 1280) { #if LWIP_ND6_ALLOW_RA_UPDATES @@ -476,7 +476,7 @@ nd6_input(struct pbuf *p, struct netif *inp) } case ND6_OPTION_TYPE_PREFIX_INFO: { - struct prefix_option * prefix_opt; + struct prefix_option *prefix_opt; prefix_opt = (struct prefix_option *)buffer; if (prefix_opt->flags & ND6_PREFIX_FLAG_ON_LINK) { @@ -526,8 +526,8 @@ nd6_input(struct pbuf *p, struct netif *inp) } case ICMP6_TYPE_RD: /* Redirect */ { - struct redirect_header * redir_hdr; - struct lladdr_option * lladdr_opt; + struct redirect_header *redir_hdr; + struct lladdr_option *lladdr_opt; /* Check that Redir header fits in packet. */ if (p->len < sizeof(struct redirect_header)) { @@ -599,7 +599,7 @@ nd6_input(struct pbuf *p, struct netif *inp) case ICMP6_TYPE_PTB: /* Packet too big */ { struct icmp6_hdr *icmp6hdr; /* Packet too big message */ - struct ip6_hdr * ip6hdr; /* IPv6 header of the packet which caused the error */ + struct ip6_hdr *ip6hdr; /* IPv6 header of the packet which caused the error */ u32_t pmtu; /* Check that ICMPv6 header + IPv6 header fit in payload */ @@ -655,7 +655,7 @@ void nd6_tmr(void) { s8_t i; - struct netif * netif; + struct netif *netif; /* Process neighbor entries. */ for (i = 0; i < LWIP_ND6_NUM_NEIGHBORS; i++) { @@ -847,11 +847,11 @@ nd6_tmr(void) * @param flags one of ND6_SEND_FLAG_* */ static void -nd6_send_ns(struct netif * netif, const ip6_addr_t * target_addr, u8_t flags) +nd6_send_ns(struct netif *netif, const ip6_addr_t *target_addr, u8_t flags) { - struct ns_header * ns_hdr; - struct pbuf * p; - const ip6_addr_t * src_addr; + struct ns_header *ns_hdr; + struct pbuf *p; + const ip6_addr_t *src_addr; u16_t lladdr_opt_len; if (ip6_addr_isvalid(netif_ip6_addr_state(netif,0))) { @@ -916,13 +916,13 @@ nd6_send_ns(struct netif * netif, const ip6_addr_t * target_addr, u8_t flags) * @param flags one of ND6_SEND_FLAG_* */ static void -nd6_send_na(struct netif * netif, const ip6_addr_t * target_addr, u8_t flags) +nd6_send_na(struct netif *netif, const ip6_addr_t *target_addr, u8_t flags) { - struct na_header * na_hdr; - struct lladdr_option * lladdr_opt; - struct pbuf * p; - const ip6_addr_t * src_addr; - const ip6_addr_t * dest_addr; + struct na_header *na_hdr; + struct lladdr_option *lladdr_opt; + struct pbuf *p; + const ip6_addr_t *src_addr; + const ip6_addr_t *dest_addr; u16_t lladdr_opt_len; /* Use link-local address as source address. */ @@ -987,12 +987,12 @@ nd6_send_na(struct netif * netif, const ip6_addr_t * target_addr, u8_t flags) * @param netif the netif on which to send the message */ static err_t -nd6_send_rs(struct netif * netif) +nd6_send_rs(struct netif *netif) { - struct rs_header * rs_hdr; - struct lladdr_option * lladdr_opt; - struct pbuf * p; - const ip6_addr_t * src_addr; + struct rs_header *rs_hdr; + struct lladdr_option *lladdr_opt; + struct pbuf *p; + const ip6_addr_t *src_addr; err_t err; u16_t lladdr_opt_len = 0; @@ -1058,7 +1058,7 @@ nd6_send_rs(struct netif * netif) * entry is found */ static s8_t -nd6_find_neighbor_cache_entry(const ip6_addr_t * ip6addr) +nd6_find_neighbor_cache_entry(const ip6_addr_t *ip6addr) { s8_t i; for (i = 0; i < LWIP_ND6_NUM_NEIGHBORS; i++) { @@ -1217,7 +1217,7 @@ nd6_free_neighbor_cache_entry(s8_t i) * entry is found */ static s8_t -nd6_find_destination_cache_entry(const ip6_addr_t * ip6addr) +nd6_find_destination_cache_entry(const ip6_addr_t *ip6addr) { s8_t i; for (i = 0; i < LWIP_ND6_NUM_DESTINATIONS; i++) { @@ -1267,7 +1267,7 @@ nd6_new_destination_cache_entry(void) * @return 1 if the address is on-link, 0 otherwise */ static s8_t -nd6_is_prefix_in_netif(const ip6_addr_t * ip6addr, struct netif * netif) +nd6_is_prefix_in_netif(const ip6_addr_t *ip6addr, struct netif *netif) { s8_t i; for (i = 0; i < LWIP_ND6_NUM_PREFIXES; i++) { @@ -1296,7 +1296,7 @@ nd6_is_prefix_in_netif(const ip6_addr_t * ip6addr, struct netif * netif) * router is found */ s8_t -nd6_select_router(const ip6_addr_t * ip6addr, struct netif * netif) +nd6_select_router(const ip6_addr_t *ip6addr, struct netif *netif) { s8_t i; /* last_router is used for round-robin router selection (as recommended @@ -1355,7 +1355,7 @@ nd6_select_router(const ip6_addr_t * ip6addr, struct netif * netif) * @return the index of the router entry, or -1 if not found */ static s8_t -nd6_get_router(const ip6_addr_t * router_addr, struct netif * netif) +nd6_get_router(const ip6_addr_t *router_addr, struct netif *netif) { s8_t i; @@ -1380,7 +1380,7 @@ nd6_get_router(const ip6_addr_t * router_addr, struct netif * netif) * @return the index on the router table, or -1 if could not be created */ static s8_t -nd6_new_router(const ip6_addr_t * router_addr, struct netif * netif) +nd6_new_router(const ip6_addr_t *router_addr, struct netif *netif) { s8_t router_index; s8_t neighbor_index; @@ -1429,7 +1429,7 @@ nd6_new_router(const ip6_addr_t * router_addr, struct netif * netif) * @return the index on the prefix table, or -1 if not found */ static s8_t -nd6_get_onlink_prefix(ip6_addr_t * prefix, struct netif * netif) +nd6_get_onlink_prefix(ip6_addr_t *prefix, struct netif *netif) { s8_t i; @@ -1453,7 +1453,7 @@ nd6_get_onlink_prefix(ip6_addr_t * prefix, struct netif * netif) * @return the index on the prefix table, or -1 if not created */ static s8_t -nd6_new_onlink_prefix(ip6_addr_t * prefix, struct netif * netif) +nd6_new_onlink_prefix(ip6_addr_t *prefix, struct netif *netif) { s8_t i; @@ -1488,7 +1488,7 @@ nd6_new_onlink_prefix(ip6_addr_t * prefix, struct netif * netif) * could be created */ s8_t -nd6_get_next_hop_entry(const ip6_addr_t * ip6addr, struct netif * netif) +nd6_get_next_hop_entry(const ip6_addr_t *ip6addr, struct netif *netif) { s8_t i; @@ -1600,7 +1600,7 @@ nd6_get_next_hop_entry(const ip6_addr_t * ip6addr, struct netif * netif) * @return ERR_OK if succeeded, ERR_MEM if out of memory */ err_t -nd6_queue_packet(s8_t neighbor_index, struct pbuf * q) +nd6_queue_packet(s8_t neighbor_index, struct pbuf *q) { err_t result = ERR_MEM; struct pbuf *p; @@ -1784,7 +1784,7 @@ nd6_send_q(s8_t i) * @return the Path MTU, if known, or the netif default MTU */ u16_t -nd6_get_destination_mtu(const ip6_addr_t * ip6addr, struct netif * netif) +nd6_get_destination_mtu(const ip6_addr_t *ip6addr, struct netif *netif) { s8_t i; @@ -1814,7 +1814,7 @@ nd6_get_destination_mtu(const ip6_addr_t * ip6addr, struct netif * netif) * by an upper layer protocol (TCP) */ void -nd6_reachability_hint(const ip6_addr_t * ip6addr) +nd6_reachability_hint(const ip6_addr_t *ip6addr) { s8_t i; @@ -1857,7 +1857,7 @@ nd6_reachability_hint(const ip6_addr_t * ip6addr) * @param netif points to a network interface */ void -nd6_cleanup_netif(struct netif * netif) +nd6_cleanup_netif(struct netif *netif) { u8_t i; s8_t router_index; diff --git a/src/include/lwip/ip6_frag.h b/src/include/lwip/ip6_frag.h index d625e4e5..6be27473 100644 --- a/src/include/lwip/ip6_frag.h +++ b/src/include/lwip/ip6_frag.h @@ -89,7 +89,7 @@ struct ip6_reassdata { #define ip6_reass_init() /* Compatibility define */ void ip6_reass_tmr(void); -struct pbuf * ip6_reass(struct pbuf *p); +struct pbuf *ip6_reass(struct pbuf *p); #endif /* LWIP_IPV6 && LWIP_IPV6_REASS */ diff --git a/src/include/lwip/nd6.h b/src/include/lwip/nd6.h index 5e096517..ac2b7877 100644 --- a/src/include/lwip/nd6.h +++ b/src/include/lwip/nd6.h @@ -61,7 +61,7 @@ extern "C" { /** Struct for tables. */ struct nd6_neighbor_cache_entry { ip6_addr_t next_hop_address; - struct netif * netif; + struct netif *netif; u8_t lladdr[NETIF_MAX_HWADDR_LEN]; /*u32_t pmtu;*/ #if LWIP_ND6_QUEUEING @@ -90,7 +90,7 @@ struct nd6_destination_cache_entry { struct nd6_prefix_list_entry { ip6_addr_t prefix; - struct netif * netif; + struct netif *netif; u32_t invalidation_timer; #if LWIP_IPV6_AUTOCONFIG u8_t flags; @@ -101,7 +101,7 @@ struct nd6_prefix_list_entry { }; struct nd6_router_list_entry { - struct nd6_neighbor_cache_entry * neighbor_entry; + struct nd6_neighbor_cache_entry *neighbor_entry; u32_t invalidation_timer; u8_t flags; }; @@ -344,14 +344,14 @@ extern u32_t retrans_timer; void nd6_tmr(void); void nd6_input(struct pbuf *p, struct netif *inp); -s8_t nd6_get_next_hop_entry(const ip6_addr_t * ip6addr, struct netif * netif); -s8_t nd6_select_router(const ip6_addr_t * ip6addr, struct netif * netif); -u16_t nd6_get_destination_mtu(const ip6_addr_t * ip6addr, struct netif * netif); -err_t nd6_queue_packet(s8_t neighbor_index, struct pbuf * p); +s8_t nd6_get_next_hop_entry(const ip6_addr_t *ip6addr, struct netif *netif); +s8_t nd6_select_router(const ip6_addr_t *ip6addr, struct netif *netif); +u16_t nd6_get_destination_mtu(const ip6_addr_t *ip6addr, struct netif *netif); +err_t nd6_queue_packet(s8_t neighbor_index, struct pbuf *p); #if LWIP_ND6_TCP_REACHABILITY_HINTS -void nd6_reachability_hint(const ip6_addr_t * ip6addr); +void nd6_reachability_hint(const ip6_addr_t *ip6addr); #endif /* LWIP_ND6_TCP_REACHABILITY_HINTS */ -void nd6_cleanup_netif(struct netif * netif); +void nd6_cleanup_netif(struct netif *netif); #ifdef __cplusplus } From d95ab511d00b89703504d1cea8b97fb3d895b0a4 Mon Sep 17 00:00:00 2001 From: Ajay Bhargav Date: Wed, 10 Aug 2016 19:19:23 +0530 Subject: [PATCH 060/325] netif:ppp: fix mempool build issues when PPP is enabled During documentation updated LWIP_MEMPOOL_PROTOTYPE was moved inside "#if MEMP_MEM_MALLOC" which cause ppp build to break. This patch fix that issue. ref commit-id: 2f950a7dcc3cc48852276d5ca03522cfe60ac99f Signed-off-by: Ajay Bhargav --- src/include/lwip/memp.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/include/lwip/memp.h b/src/include/lwip/memp.h index 8a555c89..68fcd991 100644 --- a/src/include/lwip/memp.h +++ b/src/include/lwip/memp.h @@ -58,6 +58,12 @@ typedef enum { extern const struct memp_desc* const memp_pools[MEMP_MAX]; +/** + * @ingroup mempool + * Declare prototype for private memory pool if it is used in multiple files + */ +#define LWIP_MEMPOOL_PROTOTYPE(name) extern const struct memp_desc memp_ ## name + #if MEMP_MEM_MALLOC #define LWIP_MEMPOOL_DECLARE(name,num,size,desc) \ @@ -70,12 +76,6 @@ extern const struct memp_desc* const memp_pools[MEMP_MAX]; #else /* MEMP_MEM_MALLOC */ -/** - * @ingroup mempool - * Declare prototype for private memory pool if it is used in multiple files - */ -#define LWIP_MEMPOOL_PROTOTYPE(name) extern const struct memp_desc memp_ ## name - /** * @ingroup mempool * Declare a private memory pool From dc7340bbd5209d6fc2a6df5c23d9cadc0d4244c8 Mon Sep 17 00:00:00 2001 From: goldsimon Date: Thu, 11 Aug 2016 14:35:44 +0200 Subject: [PATCH 061/325] started with bug #48728: move protocol definitions to 'include/prot/*.h' files (started with some IPv4 protocols) --- src/core/ipv4/autoip.c | 25 +---- src/core/ipv4/dhcp.c | 10 +- src/core/ipv4/ip4.c | 2 +- src/include/lwip/autoip.h | 3 - src/include/lwip/dhcp.h | 165 ++-------------------------- src/include/lwip/ip.h | 10 +- src/include/lwip/ip4.h | 57 +--------- src/include/lwip/prot/autoip.h | 82 ++++++++++++++ src/include/lwip/prot/dhcp.h | 192 +++++++++++++++++++++++++++++++++ src/include/lwip/prot/ip.h | 54 ++++++++++ src/include/lwip/prot/ip4.h | 119 ++++++++++++++++++++ 11 files changed, 464 insertions(+), 255 deletions(-) create mode 100644 src/include/lwip/prot/autoip.h create mode 100644 src/include/lwip/prot/dhcp.h create mode 100644 src/include/lwip/prot/ip.h create mode 100644 src/include/lwip/prot/ip4.h diff --git a/src/core/ipv4/autoip.c b/src/core/ipv4/autoip.c index f9bc60c8..226c43cd 100644 --- a/src/core/ipv4/autoip.c +++ b/src/core/ipv4/autoip.c @@ -66,34 +66,11 @@ #include "lwip/netif.h" #include "lwip/autoip.h" #include "lwip/etharp.h" +#include "lwip/prot/autoip.h" #include #include -/* 169.254.0.0 */ -#define AUTOIP_NET 0xA9FE0000 -/* 169.254.1.0 */ -#define AUTOIP_RANGE_START (AUTOIP_NET | 0x0100) -/* 169.254.254.255 */ -#define AUTOIP_RANGE_END (AUTOIP_NET | 0xFEFF) - -/* RFC 3927 Constants */ -#define PROBE_WAIT 1 /* second (initial random delay) */ -#define PROBE_MIN 1 /* second (minimum delay till repeated probe) */ -#define PROBE_MAX 2 /* seconds (maximum delay till repeated probe) */ -#define PROBE_NUM 3 /* (number of probe packets) */ -#define ANNOUNCE_NUM 2 /* (number of announcement packets) */ -#define ANNOUNCE_INTERVAL 2 /* seconds (time between announcement packets) */ -#define ANNOUNCE_WAIT 2 /* seconds (delay before announcing) */ -#define MAX_CONFLICTS 10 /* (max conflicts before rate limiting) */ -#define RATE_LIMIT_INTERVAL 60 /* seconds (delay between successive attempts) */ -#define DEFEND_INTERVAL 10 /* seconds (min. wait between defensive ARPs) */ - -/* AutoIP client states */ -#define AUTOIP_STATE_OFF 0 -#define AUTOIP_STATE_PROBING 1 -#define AUTOIP_STATE_ANNOUNCING 2 -#define AUTOIP_STATE_BOUND 3 /** Pseudo random macro based on netif informations. * You could use "rand()" from the C Library if you define LWIP_AUTOIP_RAND in lwipopts.h */ diff --git a/src/core/ipv4/dhcp.c b/src/core/ipv4/dhcp.c index 7536af02..af6fcde0 100644 --- a/src/core/ipv4/dhcp.c +++ b/src/core/ipv4/dhcp.c @@ -74,6 +74,7 @@ #include "lwip/autoip.h" #include "lwip/dns.h" #include "lwip/etharp.h" +#include "lwip/prot/dhcp.h" #include @@ -384,6 +385,7 @@ dhcp_select(struct netif *netif) /** * The DHCP timer that checks for lease renewal/rebind timeouts. + * Must be called once a minute (see @ref DHCP_COARSE_TIMER_SECS). */ void dhcp_coarse_tmr(void) @@ -419,7 +421,8 @@ dhcp_coarse_tmr(void) } /** - * DHCP transaction timeout handling + * DHCP transaction timeout handling (this function must be called every 500ms, + * see @ref DHCP_FINE_TIMER_MSECS). * * A DHCP server is expected to respond within a short period of time. * This timer checks whether an outstanding DHCP request is timed out. @@ -850,7 +853,8 @@ dhcp_network_changed(struct netif *netif) #if DHCP_DOES_ARP_CHECK /** - * Match an ARP reply with the offered IP address. + * Match an ARP reply with the offered IP address: + * check whether the offered IP address is not in use using ARP * * @param netif the network interface on which the reply was received * @param addr The IP address we received a reply from @@ -1241,7 +1245,7 @@ dhcp_reboot(struct netif *netif) /** * @ingroup dhcp4 - * Release a DHCP lease. + * Release a DHCP lease (usually called before @ref dhcp_stop). * * @param netif network interface which must release its lease */ diff --git a/src/core/ipv4/ip4.c b/src/core/ipv4/ip4.c index fb6777a6..b660dbbb 100644 --- a/src/core/ipv4/ip4.c +++ b/src/core/ipv4/ip4.c @@ -53,9 +53,9 @@ #include "lwip/raw.h" #include "lwip/udp.h" #include "lwip/priv/tcp_priv.h" -#include "lwip/dhcp.h" #include "lwip/autoip.h" #include "lwip/stats.h" +#include "lwip/prot/dhcp.h" #include diff --git a/src/include/lwip/autoip.h b/src/include/lwip/autoip.h index 81d89932..7ad8de42 100644 --- a/src/include/lwip/autoip.h +++ b/src/include/lwip/autoip.h @@ -36,9 +36,6 @@ * This is a AutoIP implementation for the lwIP TCP/IP stack. It aims to conform * with RFC 3927. * - * - * Please coordinate changes and requests with Dominik Spies - * */ #ifndef LWIP_HDR_AUTOIP_H diff --git a/src/include/lwip/dhcp.h b/src/include/lwip/dhcp.h index ca19a2a2..40a3e4c3 100644 --- a/src/include/lwip/dhcp.h +++ b/src/include/lwip/dhcp.h @@ -50,15 +50,13 @@ extern "C" { #endif /** period (in seconds) of the application calling dhcp_coarse_tmr() */ -#define DHCP_COARSE_TIMER_SECS 60 +#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 * 1000UL) /** period (in milliseconds) of the application calling dhcp_fine_tmr() */ -#define DHCP_FINE_TIMER_MSECS 500 +#define DHCP_FINE_TIMER_MSECS 500 -#define DHCP_CHADDR_LEN 16U -#define DHCP_SNAME_LEN 64U -#define DHCP_FILE_LEN 128U +#define DHCP_BOOT_FILE_LEN 128U struct dhcp { @@ -97,181 +95,30 @@ struct dhcp u32_t offered_t2_rebind; /* recommended rebind time (usually 87.5 of lease period) */ #if LWIP_DHCP_BOOTP_FILE ip_addr_t offered_si_addr; - char boot_file_name[DHCP_FILE_LEN]; + char boot_file_name[DHCP_BOOT_FILE_LEN]; #endif /* LWIP_DHCP_BOOTPFILE */ }; -/* MUST be compiled with "pack structs" or equivalent! */ -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/bpstruct.h" -#endif -PACK_STRUCT_BEGIN -/** minimum set of fields of any DHCP message */ -struct dhcp_msg -{ - PACK_STRUCT_FLD_8(u8_t op); - PACK_STRUCT_FLD_8(u8_t htype); - PACK_STRUCT_FLD_8(u8_t hlen); - PACK_STRUCT_FLD_8(u8_t hops); - PACK_STRUCT_FIELD(u32_t xid); - PACK_STRUCT_FIELD(u16_t secs); - PACK_STRUCT_FIELD(u16_t flags); - PACK_STRUCT_FLD_S(ip4_addr_p_t ciaddr); - PACK_STRUCT_FLD_S(ip4_addr_p_t yiaddr); - PACK_STRUCT_FLD_S(ip4_addr_p_t siaddr); - PACK_STRUCT_FLD_S(ip4_addr_p_t giaddr); - PACK_STRUCT_FLD_8(u8_t chaddr[DHCP_CHADDR_LEN]); - PACK_STRUCT_FLD_8(u8_t sname[DHCP_SNAME_LEN]); - PACK_STRUCT_FLD_8(u8_t file[DHCP_FILE_LEN]); - PACK_STRUCT_FIELD(u32_t cookie); -#define DHCP_MIN_OPTIONS_LEN 68U -/** make sure user does not configure this too small */ -#if ((defined(DHCP_OPTIONS_LEN)) && (DHCP_OPTIONS_LEN < DHCP_MIN_OPTIONS_LEN)) -# undef DHCP_OPTIONS_LEN -#endif -/** allow this to be configured in lwipopts.h, but not too small */ -#if (!defined(DHCP_OPTIONS_LEN)) -/** set this to be sufficient for your options in outgoing DHCP msgs */ -# define DHCP_OPTIONS_LEN DHCP_MIN_OPTIONS_LEN -#endif - PACK_STRUCT_FLD_8(u8_t options[DHCP_OPTIONS_LEN]); -} PACK_STRUCT_STRUCT; -PACK_STRUCT_END -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/epstruct.h" -#endif void dhcp_set_struct(struct netif *netif, struct dhcp *dhcp); /** Remove a struct dhcp previously set to the netif using dhcp_set_struct() */ #define dhcp_remove_struct(netif) do { (netif)->dhcp = NULL; } while(0) void dhcp_cleanup(struct netif *netif); -/** start DHCP configuration */ err_t dhcp_start(struct netif *netif); -/** enforce early lease renewal (not needed normally)*/ err_t dhcp_renew(struct netif *netif); -/** release the DHCP lease, usually called before dhcp_stop()*/ err_t dhcp_release(struct netif *netif); -/** stop DHCP configuration */ void dhcp_stop(struct netif *netif); -/** inform server of our manual IP address */ void dhcp_inform(struct netif *netif); -/** Handle a possible change in the network configuration */ void dhcp_network_changed(struct netif *netif); - -/** if enabled, check whether the offered IP address is not in use, using ARP */ #if DHCP_DOES_ARP_CHECK void dhcp_arp_reply(struct netif *netif, const ip4_addr_t *addr); #endif - -/** check if DHCP supplied netif->ip_addr */ u8_t dhcp_supplied_address(const struct netif *netif); - -/** to be called every minute */ +/* to be called every minute */ void dhcp_coarse_tmr(void); -/** to be called every half second */ +/* to be called every half second */ void dhcp_fine_tmr(void); -/** DHCP message item offsets and length */ -#define DHCP_OP_OFS 0 -#define DHCP_HTYPE_OFS 1 -#define DHCP_HLEN_OFS 2 -#define DHCP_HOPS_OFS 3 -#define DHCP_XID_OFS 4 -#define DHCP_SECS_OFS 8 -#define DHCP_FLAGS_OFS 10 -#define DHCP_CIADDR_OFS 12 -#define DHCP_YIADDR_OFS 16 -#define DHCP_SIADDR_OFS 20 -#define DHCP_GIADDR_OFS 24 -#define DHCP_CHADDR_OFS 28 -#define DHCP_SNAME_OFS 44 -#define DHCP_FILE_OFS 108 -#define DHCP_MSG_LEN 236 - -#define DHCP_COOKIE_OFS DHCP_MSG_LEN -#define DHCP_OPTIONS_OFS (DHCP_MSG_LEN + 4) - -#define DHCP_CLIENT_PORT 68 -#define DHCP_SERVER_PORT 67 - -/** DHCP client states */ -#define DHCP_STATE_OFF 0 -#define DHCP_STATE_REQUESTING 1 -#define DHCP_STATE_INIT 2 -#define DHCP_STATE_REBOOTING 3 -#define DHCP_STATE_REBINDING 4 -#define DHCP_STATE_RENEWING 5 -#define DHCP_STATE_SELECTING 6 -#define DHCP_STATE_INFORMING 7 -#define DHCP_STATE_CHECKING 8 -/** not yet implemented \#define DHCP_STATE_PERMANENT 9 */ -#define DHCP_STATE_BOUND 10 -/** not yet implemented \#define DHCP_STATE_RELEASING 11 */ -#define DHCP_STATE_BACKING_OFF 12 - -/** AUTOIP cooperation flags */ -#define DHCP_AUTOIP_COOP_STATE_OFF 0 -#define DHCP_AUTOIP_COOP_STATE_ON 1 - -#define DHCP_BOOTREQUEST 1 -#define DHCP_BOOTREPLY 2 - -/** DHCP message types */ -#define DHCP_DISCOVER 1 -#define DHCP_OFFER 2 -#define DHCP_REQUEST 3 -#define DHCP_DECLINE 4 -#define DHCP_ACK 5 -#define DHCP_NAK 6 -#define DHCP_RELEASE 7 -#define DHCP_INFORM 8 - -/** DHCP hardware type, currently only ethernet is supported */ -#define DHCP_HTYPE_ETH 1 - -#define DHCP_MAGIC_COOKIE 0x63825363UL - -/* This is a list of options for BOOTP and DHCP, see RFC 2132 for descriptions */ - -/** BootP options */ -#define DHCP_OPTION_PAD 0 -#define DHCP_OPTION_SUBNET_MASK 1 /* RFC 2132 3.3 */ -#define DHCP_OPTION_ROUTER 3 -#define DHCP_OPTION_DNS_SERVER 6 -#define DHCP_OPTION_HOSTNAME 12 -#define DHCP_OPTION_IP_TTL 23 -#define DHCP_OPTION_MTU 26 -#define DHCP_OPTION_BROADCAST 28 -#define DHCP_OPTION_TCP_TTL 37 -#define DHCP_OPTION_NTP 42 -#define DHCP_OPTION_END 255 - -/** DHCP options */ -#define DHCP_OPTION_REQUESTED_IP 50 /* RFC 2132 9.1, requested IP address */ -#define DHCP_OPTION_LEASE_TIME 51 /* RFC 2132 9.2, time in seconds, in 4 bytes */ -#define DHCP_OPTION_OVERLOAD 52 /* RFC2132 9.3, use file and/or sname field for options */ - -#define DHCP_OPTION_MESSAGE_TYPE 53 /* RFC 2132 9.6, important for DHCP */ -#define DHCP_OPTION_MESSAGE_TYPE_LEN 1 - -#define DHCP_OPTION_SERVER_ID 54 /* RFC 2132 9.7, server IP address */ -#define DHCP_OPTION_PARAMETER_REQUEST_LIST 55 /* RFC 2132 9.8, requested option types */ - -#define DHCP_OPTION_MAX_MSG_SIZE 57 /* RFC 2132 9.10, message size accepted >= 576 */ -#define DHCP_OPTION_MAX_MSG_SIZE_LEN 2 - -#define DHCP_OPTION_T1 58 /* T1 renewal time */ -#define DHCP_OPTION_T2 59 /* T2 rebinding time */ -#define DHCP_OPTION_US 60 -#define DHCP_OPTION_CLIENT_ID 61 -#define DHCP_OPTION_TFTP_SERVERNAME 66 -#define DHCP_OPTION_BOOTFILE 67 - -/** possible combinations of overloading the file and sname fields with options */ -#define DHCP_OVERLOAD_NONE 0 -#define DHCP_OVERLOAD_FILE 1 -#define DHCP_OVERLOAD_SNAME 2 -#define DHCP_OVERLOAD_SNAME_FILE 3 #if LWIP_DHCP_GET_NTP_SRV /** This function must exist, in other to add offered NTP servers to diff --git a/src/include/lwip/ip.h b/src/include/lwip/ip.h index 44e5fd80..7c079dd1 100644 --- a/src/include/lwip/ip.h +++ b/src/include/lwip/ip.h @@ -46,20 +46,12 @@ #include "lwip/netif.h" #include "lwip/ip4.h" #include "lwip/ip6.h" +#include "lwip/prot/ip.h" #ifdef __cplusplus extern "C" { #endif -#define IP_PROTO_ICMP 1 -#define IP_PROTO_IGMP 2 -#define IP_PROTO_UDP 17 -#define IP_PROTO_UDPLITE 136 -#define IP_PROTO_TCP 6 - -/** This operates on a void* by loading the first byte */ -#define IP_HDR_GET_VERSION(ptr) ((*(u8_t*)(ptr)) >> 4) - /* This is passed as the destination address to ip_output_if (not to ip_output), meaning that an IP header already is constructed in the pbuf. This is used when TCP retransmits. */ diff --git a/src/include/lwip/ip4.h b/src/include/lwip/ip4.h index c78c1194..48246ecc 100644 --- a/src/include/lwip/ip4.h +++ b/src/include/lwip/ip4.h @@ -46,6 +46,7 @@ #include "lwip/ip4_addr.h" #include "lwip/err.h" #include "lwip/netif.h" +#include "lwip/prot/ip4.h" #ifdef __cplusplus extern "C" { @@ -60,62 +61,6 @@ extern "C" { /** Currently, the function ip_output_if_opt() is only used with IGMP */ #define IP_OPTIONS_SEND (LWIP_IPV4 && LWIP_IGMP) -#define IP_HLEN 20 - - -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/bpstruct.h" -#endif -PACK_STRUCT_BEGIN -struct ip_hdr { - /* version / header length */ - PACK_STRUCT_FLD_8(u8_t _v_hl); - /* type of service */ - PACK_STRUCT_FLD_8(u8_t _tos); - /* total length */ - PACK_STRUCT_FIELD(u16_t _len); - /* identification */ - PACK_STRUCT_FIELD(u16_t _id); - /* fragment offset field */ - PACK_STRUCT_FIELD(u16_t _offset); -#define IP_RF 0x8000U /* reserved fragment flag */ -#define IP_DF 0x4000U /* don't fragment flag */ -#define IP_MF 0x2000U /* more fragments flag */ -#define IP_OFFMASK 0x1fffU /* mask for fragmenting bits */ - /* time to live */ - PACK_STRUCT_FLD_8(u8_t _ttl); - /* protocol*/ - PACK_STRUCT_FLD_8(u8_t _proto); - /* checksum */ - PACK_STRUCT_FIELD(u16_t _chksum); - /* source and destination IP addresses */ - PACK_STRUCT_FLD_S(ip4_addr_p_t src); - PACK_STRUCT_FLD_S(ip4_addr_p_t dest); -} PACK_STRUCT_STRUCT; -PACK_STRUCT_END -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/epstruct.h" -#endif - -#define IPH_V(hdr) ((hdr)->_v_hl >> 4) -#define IPH_HL(hdr) ((hdr)->_v_hl & 0x0f) -#define IPH_TOS(hdr) ((hdr)->_tos) -#define IPH_LEN(hdr) ((hdr)->_len) -#define IPH_ID(hdr) ((hdr)->_id) -#define IPH_OFFSET(hdr) ((hdr)->_offset) -#define IPH_TTL(hdr) ((hdr)->_ttl) -#define IPH_PROTO(hdr) ((hdr)->_proto) -#define IPH_CHKSUM(hdr) ((hdr)->_chksum) - -#define IPH_VHL_SET(hdr, v, hl) (hdr)->_v_hl = (u8_t)((((v) << 4) | (hl))) -#define IPH_TOS_SET(hdr, tos) (hdr)->_tos = (tos) -#define IPH_LEN_SET(hdr, len) (hdr)->_len = (len) -#define IPH_ID_SET(hdr, id) (hdr)->_id = (id) -#define IPH_OFFSET_SET(hdr, off) (hdr)->_offset = (off) -#define IPH_TTL_SET(hdr, ttl) (hdr)->_ttl = (u8_t)(ttl) -#define IPH_PROTO_SET(hdr, proto) (hdr)->_proto = (u8_t)(proto) -#define IPH_CHKSUM_SET(hdr, chksum) (hdr)->_chksum = (chksum) - #define ip_init() /* Compatibility define, no init needed. */ struct netif *ip4_route(const ip4_addr_t *dest); #if LWIP_IPV4_SRC_ROUTING diff --git a/src/include/lwip/prot/autoip.h b/src/include/lwip/prot/autoip.h new file mode 100644 index 00000000..37c5f715 --- /dev/null +++ b/src/include/lwip/prot/autoip.h @@ -0,0 +1,82 @@ +/** + * @file + * AutoIP protocol definitions + */ + +/* + * + * Copyright (c) 2007 Dominik Spies + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * Author: Dominik Spies + * + * This is a AutoIP implementation for the lwIP TCP/IP stack. It aims to conform + * with RFC 3927. + * + */ + +#ifndef LWIP_HDR_PROT_AUTOIP_H +#define LWIP_HDR_PROT_AUTOIP_H + +#include "lwip/opt.h" + +#if LWIP_IPV4 && LWIP_AUTOIP /* don't build if not configured for use in lwipopts.h */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* 169.254.0.0 */ +#define AUTOIP_NET 0xA9FE0000 +/* 169.254.1.0 */ +#define AUTOIP_RANGE_START (AUTOIP_NET | 0x0100) +/* 169.254.254.255 */ +#define AUTOIP_RANGE_END (AUTOIP_NET | 0xFEFF) + +/* RFC 3927 Constants */ +#define PROBE_WAIT 1 /* second (initial random delay) */ +#define PROBE_MIN 1 /* second (minimum delay till repeated probe) */ +#define PROBE_MAX 2 /* seconds (maximum delay till repeated probe) */ +#define PROBE_NUM 3 /* (number of probe packets) */ +#define ANNOUNCE_NUM 2 /* (number of announcement packets) */ +#define ANNOUNCE_INTERVAL 2 /* seconds (time between announcement packets) */ +#define ANNOUNCE_WAIT 2 /* seconds (delay before announcing) */ +#define MAX_CONFLICTS 10 /* (max conflicts before rate limiting) */ +#define RATE_LIMIT_INTERVAL 60 /* seconds (delay between successive attempts) */ +#define DEFEND_INTERVAL 10 /* seconds (min. wait between defensive ARPs) */ + +/* AutoIP client states */ +#define AUTOIP_STATE_OFF 0 +#define AUTOIP_STATE_PROBING 1 +#define AUTOIP_STATE_ANNOUNCING 2 +#define AUTOIP_STATE_BOUND 3 + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_IPV4 && LWIP_AUTOIP */ + +#endif /* LWIP_HDR_PROT_AUTOIP_H */ diff --git a/src/include/lwip/prot/dhcp.h b/src/include/lwip/prot/dhcp.h new file mode 100644 index 00000000..21b1b609 --- /dev/null +++ b/src/include/lwip/prot/dhcp.h @@ -0,0 +1,192 @@ +/** + * @file + * DHCP protocol definitions + */ + +/* + * Copyright (c) 2001-2004 Leon Woestenberg + * Copyright (c) 2001-2004 Axon Digital Design B.V., The Netherlands. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Leon Woestenberg + * + */ +#ifndef LWIP_HDR_PROT_DHCP_H +#define LWIP_HDR_PROT_DHCP_H + +#include "lwip/opt.h" + +#if LWIP_DHCP /* don't build if not configured for use in lwipopts.h */ + +#include "lwip/netif.h" +#include "lwip/udp.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define DHCP_CLIENT_PORT 68 +#define DHCP_SERVER_PORT 67 + + + /* DHCP message item offsets and length */ +#define DHCP_CHADDR_LEN 16U +#define DHCP_SNAME_OFS 44U +#define DHCP_SNAME_LEN 64U +#define DHCP_FILE_OFS 108U +#define DHCP_FILE_LEN 128U +#define DHCP_MSG_LEN 236U +#define DHCP_OPTIONS_OFS (DHCP_MSG_LEN + 4U) /* 4 byte: cookie */ + +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +/** minimum set of fields of any DHCP message */ +struct dhcp_msg +{ + PACK_STRUCT_FLD_8(u8_t op); + PACK_STRUCT_FLD_8(u8_t htype); + PACK_STRUCT_FLD_8(u8_t hlen); + PACK_STRUCT_FLD_8(u8_t hops); + PACK_STRUCT_FIELD(u32_t xid); + PACK_STRUCT_FIELD(u16_t secs); + PACK_STRUCT_FIELD(u16_t flags); + PACK_STRUCT_FLD_S(ip4_addr_p_t ciaddr); + PACK_STRUCT_FLD_S(ip4_addr_p_t yiaddr); + PACK_STRUCT_FLD_S(ip4_addr_p_t siaddr); + PACK_STRUCT_FLD_S(ip4_addr_p_t giaddr); + PACK_STRUCT_FLD_8(u8_t chaddr[DHCP_CHADDR_LEN]); + PACK_STRUCT_FLD_8(u8_t sname[DHCP_SNAME_LEN]); + PACK_STRUCT_FLD_8(u8_t file[DHCP_FILE_LEN]); + PACK_STRUCT_FIELD(u32_t cookie); +#define DHCP_MIN_OPTIONS_LEN 68U +/** make sure user does not configure this too small */ +#if ((defined(DHCP_OPTIONS_LEN)) && (DHCP_OPTIONS_LEN < DHCP_MIN_OPTIONS_LEN)) +# undef DHCP_OPTIONS_LEN +#endif +/** allow this to be configured in lwipopts.h, but not too small */ +#if (!defined(DHCP_OPTIONS_LEN)) +/** set this to be sufficient for your options in outgoing DHCP msgs */ +# define DHCP_OPTIONS_LEN DHCP_MIN_OPTIONS_LEN +#endif + PACK_STRUCT_FLD_8(u8_t options[DHCP_OPTIONS_LEN]); +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + + +/* DHCP client states */ +#define DHCP_STATE_OFF 0 +#define DHCP_STATE_REQUESTING 1 +#define DHCP_STATE_INIT 2 +#define DHCP_STATE_REBOOTING 3 +#define DHCP_STATE_REBINDING 4 +#define DHCP_STATE_RENEWING 5 +#define DHCP_STATE_SELECTING 6 +#define DHCP_STATE_INFORMING 7 +#define DHCP_STATE_CHECKING 8 +/* not yet implemented \#define DHCP_STATE_PERMANENT 9 */ +#define DHCP_STATE_BOUND 10 +/* not yet implemented \#define DHCP_STATE_RELEASING 11 */ +#define DHCP_STATE_BACKING_OFF 12 + +/* AutoIP cooperation flags */ +#define DHCP_AUTOIP_COOP_STATE_OFF 0 +#define DHCP_AUTOIP_COOP_STATE_ON 1 + +/* DHCP op codes */ +#define DHCP_BOOTREQUEST 1 +#define DHCP_BOOTREPLY 2 + +/* DHCP message types */ +#define DHCP_DISCOVER 1 +#define DHCP_OFFER 2 +#define DHCP_REQUEST 3 +#define DHCP_DECLINE 4 +#define DHCP_ACK 5 +#define DHCP_NAK 6 +#define DHCP_RELEASE 7 +#define DHCP_INFORM 8 + +/** DHCP hardware type, currently only ethernet is supported */ +#define DHCP_HTYPE_ETH 1 + +#define DHCP_MAGIC_COOKIE 0x63825363UL + +/* This is a list of options for BOOTP and DHCP, see RFC 2132 for descriptions */ + +/* BootP options */ +#define DHCP_OPTION_PAD 0 +#define DHCP_OPTION_SUBNET_MASK 1 /* RFC 2132 3.3 */ +#define DHCP_OPTION_ROUTER 3 +#define DHCP_OPTION_DNS_SERVER 6 +#define DHCP_OPTION_HOSTNAME 12 +#define DHCP_OPTION_IP_TTL 23 +#define DHCP_OPTION_MTU 26 +#define DHCP_OPTION_BROADCAST 28 +#define DHCP_OPTION_TCP_TTL 37 +#define DHCP_OPTION_NTP 42 +#define DHCP_OPTION_END 255 + +/* DHCP options */ +#define DHCP_OPTION_REQUESTED_IP 50 /* RFC 2132 9.1, requested IP address */ +#define DHCP_OPTION_LEASE_TIME 51 /* RFC 2132 9.2, time in seconds, in 4 bytes */ +#define DHCP_OPTION_OVERLOAD 52 /* RFC2132 9.3, use file and/or sname field for options */ + +#define DHCP_OPTION_MESSAGE_TYPE 53 /* RFC 2132 9.6, important for DHCP */ +#define DHCP_OPTION_MESSAGE_TYPE_LEN 1 + +#define DHCP_OPTION_SERVER_ID 54 /* RFC 2132 9.7, server IP address */ +#define DHCP_OPTION_PARAMETER_REQUEST_LIST 55 /* RFC 2132 9.8, requested option types */ + +#define DHCP_OPTION_MAX_MSG_SIZE 57 /* RFC 2132 9.10, message size accepted >= 576 */ +#define DHCP_OPTION_MAX_MSG_SIZE_LEN 2 + +#define DHCP_OPTION_T1 58 /* T1 renewal time */ +#define DHCP_OPTION_T2 59 /* T2 rebinding time */ +#define DHCP_OPTION_US 60 +#define DHCP_OPTION_CLIENT_ID 61 +#define DHCP_OPTION_TFTP_SERVERNAME 66 +#define DHCP_OPTION_BOOTFILE 67 + +/* possible combinations of overloading the file and sname fields with options */ +#define DHCP_OVERLOAD_NONE 0 +#define DHCP_OVERLOAD_FILE 1 +#define DHCP_OVERLOAD_SNAME 2 +#define DHCP_OVERLOAD_SNAME_FILE 3 + + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_DHCP */ + +#endif /*LWIP_HDR_PROT_DHCP_H*/ diff --git a/src/include/lwip/prot/ip.h b/src/include/lwip/prot/ip.h new file mode 100644 index 00000000..a544790a --- /dev/null +++ b/src/include/lwip/prot/ip.h @@ -0,0 +1,54 @@ +/** + * @file + * IP protocol definitions + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_HDR_PROT_IP_H +#define LWIP_HDR_PROT_IP_H + +#include "lwip/opt.h" +#include "lwip/arch.h" + +#define IP_PROTO_ICMP 1 +#define IP_PROTO_IGMP 2 +#define IP_PROTO_UDP 17 +#define IP_PROTO_UDPLITE 136 +#define IP_PROTO_TCP 6 + +/** This operates on a void* by loading the first byte */ +#define IP_HDR_GET_VERSION(ptr) ((*(u8_t*)(ptr)) >> 4) + +#endif /* LWIP_HDR_PROT_IP_H */ + + diff --git a/src/include/lwip/prot/ip4.h b/src/include/lwip/prot/ip4.h new file mode 100644 index 00000000..f2470164 --- /dev/null +++ b/src/include/lwip/prot/ip4.h @@ -0,0 +1,119 @@ +/** + * @file + * IPv4 protocol definitions + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_HDR_PROT_IP4_H +#define LWIP_HDR_PROT_IP4_H + +#include "lwip/opt.h" + +#if LWIP_IPV4 + +#include "lwip/arch.h" +#include "lwip/ip4_addr.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* Size of the IPv4 header. Same as 'sizeof(struct ip_hdr)'. */ +#define IP_HLEN 20 + +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +/* The IPv4 header */ +struct ip_hdr { + /* version / header length */ + PACK_STRUCT_FLD_8(u8_t _v_hl); + /* type of service */ + PACK_STRUCT_FLD_8(u8_t _tos); + /* total length */ + PACK_STRUCT_FIELD(u16_t _len); + /* identification */ + PACK_STRUCT_FIELD(u16_t _id); + /* fragment offset field */ + PACK_STRUCT_FIELD(u16_t _offset); +#define IP_RF 0x8000U /* reserved fragment flag */ +#define IP_DF 0x4000U /* don't fragment flag */ +#define IP_MF 0x2000U /* more fragments flag */ +#define IP_OFFMASK 0x1fffU /* mask for fragmenting bits */ + /* time to live */ + PACK_STRUCT_FLD_8(u8_t _ttl); + /* protocol*/ + PACK_STRUCT_FLD_8(u8_t _proto); + /* checksum */ + PACK_STRUCT_FIELD(u16_t _chksum); + /* source and destination IP addresses */ + PACK_STRUCT_FLD_S(ip4_addr_p_t src); + PACK_STRUCT_FLD_S(ip4_addr_p_t dest); +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + +/* Macros to get struct ip_hdr fields: */ +#define IPH_V(hdr) ((hdr)->_v_hl >> 4) +#define IPH_HL(hdr) ((hdr)->_v_hl & 0x0f) +#define IPH_TOS(hdr) ((hdr)->_tos) +#define IPH_LEN(hdr) ((hdr)->_len) +#define IPH_ID(hdr) ((hdr)->_id) +#define IPH_OFFSET(hdr) ((hdr)->_offset) +#define IPH_TTL(hdr) ((hdr)->_ttl) +#define IPH_PROTO(hdr) ((hdr)->_proto) +#define IPH_CHKSUM(hdr) ((hdr)->_chksum) + +/* Macros to set struct ip_hdr fields: */ +#define IPH_VHL_SET(hdr, v, hl) (hdr)->_v_hl = (u8_t)((((v) << 4) | (hl))) +#define IPH_TOS_SET(hdr, tos) (hdr)->_tos = (tos) +#define IPH_LEN_SET(hdr, len) (hdr)->_len = (len) +#define IPH_ID_SET(hdr, id) (hdr)->_id = (id) +#define IPH_OFFSET_SET(hdr, off) (hdr)->_offset = (off) +#define IPH_TTL_SET(hdr, ttl) (hdr)->_ttl = (u8_t)(ttl) +#define IPH_PROTO_SET(hdr, proto) (hdr)->_proto = (u8_t)(proto) +#define IPH_CHKSUM_SET(hdr, chksum) (hdr)->_chksum = (chksum) + + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_IPV4 */ + +#endif /* LWIP_HDR_PROT_IP4_H */ + + From 6f62fe599830486600440e31af95fb675cb70790 Mon Sep 17 00:00:00 2001 From: goldsimon Date: Thu, 11 Aug 2016 15:11:34 +0200 Subject: [PATCH 062/325] ensure the 'prot' headers are as small & portable as possible --- src/include/lwip/prot/autoip.h | 6 ------ src/include/lwip/prot/dhcp.h | 7 ------- src/include/lwip/prot/ip.h | 1 - src/include/lwip/prot/ip4.h | 6 ------ 4 files changed, 20 deletions(-) diff --git a/src/include/lwip/prot/autoip.h b/src/include/lwip/prot/autoip.h index 37c5f715..2b5034ee 100644 --- a/src/include/lwip/prot/autoip.h +++ b/src/include/lwip/prot/autoip.h @@ -40,10 +40,6 @@ #ifndef LWIP_HDR_PROT_AUTOIP_H #define LWIP_HDR_PROT_AUTOIP_H -#include "lwip/opt.h" - -#if LWIP_IPV4 && LWIP_AUTOIP /* don't build if not configured for use in lwipopts.h */ - #ifdef __cplusplus extern "C" { #endif @@ -77,6 +73,4 @@ extern "C" { } #endif -#endif /* LWIP_IPV4 && LWIP_AUTOIP */ - #endif /* LWIP_HDR_PROT_AUTOIP_H */ diff --git a/src/include/lwip/prot/dhcp.h b/src/include/lwip/prot/dhcp.h index 21b1b609..2269163c 100644 --- a/src/include/lwip/prot/dhcp.h +++ b/src/include/lwip/prot/dhcp.h @@ -40,11 +40,6 @@ #include "lwip/opt.h" -#if LWIP_DHCP /* don't build if not configured for use in lwipopts.h */ - -#include "lwip/netif.h" -#include "lwip/udp.h" - #ifdef __cplusplus extern "C" { #endif @@ -187,6 +182,4 @@ PACK_STRUCT_END } #endif -#endif /* LWIP_DHCP */ - #endif /*LWIP_HDR_PROT_DHCP_H*/ diff --git a/src/include/lwip/prot/ip.h b/src/include/lwip/prot/ip.h index a544790a..7011785d 100644 --- a/src/include/lwip/prot/ip.h +++ b/src/include/lwip/prot/ip.h @@ -37,7 +37,6 @@ #ifndef LWIP_HDR_PROT_IP_H #define LWIP_HDR_PROT_IP_H -#include "lwip/opt.h" #include "lwip/arch.h" #define IP_PROTO_ICMP 1 diff --git a/src/include/lwip/prot/ip4.h b/src/include/lwip/prot/ip4.h index f2470164..3e7cbd1f 100644 --- a/src/include/lwip/prot/ip4.h +++ b/src/include/lwip/prot/ip4.h @@ -37,10 +37,6 @@ #ifndef LWIP_HDR_PROT_IP4_H #define LWIP_HDR_PROT_IP4_H -#include "lwip/opt.h" - -#if LWIP_IPV4 - #include "lwip/arch.h" #include "lwip/ip4_addr.h" @@ -112,8 +108,6 @@ PACK_STRUCT_END } #endif -#endif /* LWIP_IPV4 */ - #endif /* LWIP_HDR_PROT_IP4_H */ From b34baff546eb73043afa1d7b4fdbe57061613591 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Thu, 11 Aug 2016 21:04:39 +0200 Subject: [PATCH 063/325] Convert state #defines in autoip.h and dhcp.h to enums. May be useful in *_state structs to simplify debugging in the future. --- src/include/lwip/prot/autoip.h | 10 ++++++---- src/include/lwip/prot/dhcp.h | 34 +++++++++++++++++++--------------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/include/lwip/prot/autoip.h b/src/include/lwip/prot/autoip.h index 2b5034ee..fd3af8a9 100644 --- a/src/include/lwip/prot/autoip.h +++ b/src/include/lwip/prot/autoip.h @@ -64,10 +64,12 @@ extern "C" { #define DEFEND_INTERVAL 10 /* seconds (min. wait between defensive ARPs) */ /* AutoIP client states */ -#define AUTOIP_STATE_OFF 0 -#define AUTOIP_STATE_PROBING 1 -#define AUTOIP_STATE_ANNOUNCING 2 -#define AUTOIP_STATE_BOUND 3 +typedef enum { + AUTOIP_STATE_OFF = 0, + AUTOIP_STATE_PROBING = 1, + AUTOIP_STATE_ANNOUNCING = 2, + AUTOIP_STATE_BOUND = 3 +} autoip_state_enum_t; #ifdef __cplusplus } diff --git a/src/include/lwip/prot/dhcp.h b/src/include/lwip/prot/dhcp.h index 2269163c..c33aa04c 100644 --- a/src/include/lwip/prot/dhcp.h +++ b/src/include/lwip/prot/dhcp.h @@ -98,23 +98,27 @@ PACK_STRUCT_END /* DHCP client states */ -#define DHCP_STATE_OFF 0 -#define DHCP_STATE_REQUESTING 1 -#define DHCP_STATE_INIT 2 -#define DHCP_STATE_REBOOTING 3 -#define DHCP_STATE_REBINDING 4 -#define DHCP_STATE_RENEWING 5 -#define DHCP_STATE_SELECTING 6 -#define DHCP_STATE_INFORMING 7 -#define DHCP_STATE_CHECKING 8 -/* not yet implemented \#define DHCP_STATE_PERMANENT 9 */ -#define DHCP_STATE_BOUND 10 -/* not yet implemented \#define DHCP_STATE_RELEASING 11 */ -#define DHCP_STATE_BACKING_OFF 12 +typedef enum { + DHCP_STATE_OFF = 0, + DHCP_STATE_REQUESTING = 1, + DHCP_STATE_INIT = 2, + DHCP_STATE_REBOOTING = 3, + DHCP_STATE_REBINDING = 4, + DHCP_STATE_RENEWING = 5, + DHCP_STATE_SELECTING = 6, + DHCP_STATE_INFORMING = 7, + DHCP_STATE_CHECKING = 8, + DHCP_STATE_PERMANENT = 9, /* not yet implemented */ + DHCP_STATE_BOUND = 10, + DHCP_STATE_RELEASING = 11, /* not yet implemented */ + DHCP_STATE_BACKING_OFF = 12 +} dhcp_state_enum_t; /* AutoIP cooperation flags */ -#define DHCP_AUTOIP_COOP_STATE_OFF 0 -#define DHCP_AUTOIP_COOP_STATE_ON 1 +typedef enum { + DHCP_AUTOIP_COOP_STATE_OFF = 0, + DHCP_AUTOIP_COOP_STATE_ON = 1 +} dhcp_autoip_coop_state_enum_t; /* DHCP op codes */ #define DHCP_BOOTREQUEST 1 From 13251526fa455e0b5807172bdeffb4a4fcdc0b2f Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Thu, 11 Aug 2016 21:25:28 +0200 Subject: [PATCH 064/325] Strip path prefix in doxygen docs - no /home/dziegel/ in the future :-) --- doc/doxygen/lwip.Doxyfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/doxygen/lwip.Doxyfile b/doc/doxygen/lwip.Doxyfile index 31f57657..8bff8f56 100644 --- a/doc/doxygen/lwip.Doxyfile +++ b/doc/doxygen/lwip.Doxyfile @@ -162,7 +162,7 @@ FULL_PATH_NAMES = YES # will be relative from the directory where doxygen is started. # This tag requires that the tag FULL_PATH_NAMES is set to YES. -STRIP_FROM_PATH = +STRIP_FROM_PATH = ../../ # The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the # path mentioned in the documentation of a class, which tells the reader which From 36b9caed23e8468bf414968457f1fcef2ef72161 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Thu, 11 Aug 2016 23:54:59 +0200 Subject: [PATCH 065/325] Fix compile of unit test --- test/unit/dhcp/test_dhcp.c | 1 + 1 file changed, 1 insertion(+) diff --git a/test/unit/dhcp/test_dhcp.c b/test/unit/dhcp/test_dhcp.c index 0d0e81af..67cc7285 100644 --- a/test/unit/dhcp/test_dhcp.c +++ b/test/unit/dhcp/test_dhcp.c @@ -2,6 +2,7 @@ #include "lwip/netif.h" #include "lwip/dhcp.h" +#include "lwip/prot/dhcp.h" #include "netif/etharp.h" struct netif net_test; From 6dcb2b2415cd65fbe256f9521875374e9b433f8f Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Fri, 12 Aug 2016 22:51:43 +0200 Subject: [PATCH 066/325] Work on bug #48730: Enums should be used instead of multiple defines (where applicable) --- src/core/dns.c | 10 +++++---- src/include/lwip/err.h | 48 ++++++++++++++++++++++-------------------- 2 files changed, 31 insertions(+), 27 deletions(-) diff --git a/src/core/dns.c b/src/core/dns.c index 9aed4733..07c330cc 100644 --- a/src/core/dns.c +++ b/src/core/dns.c @@ -205,10 +205,12 @@ static u16_t dns_txid; #define DNS_FLAG2_ERR_NAME 0x03 /* DNS protocol states */ -#define DNS_STATE_UNUSED 0 -#define DNS_STATE_NEW 1 -#define DNS_STATE_ASKING 2 -#define DNS_STATE_DONE 3 +typedef enum { + DNS_STATE_UNUSED = 0, + DNS_STATE_NEW = 1, + DNS_STATE_ASKING = 2, + DNS_STATE_DONE = 3 +} dns_state_enum_t; #ifdef PACK_STRUCT_USE_INCLUDES # include "arch/bpstruct.h" diff --git a/src/include/lwip/err.h b/src/include/lwip/err.h index 81a049d8..565a7311 100644 --- a/src/include/lwip/err.h +++ b/src/include/lwip/err.h @@ -57,44 +57,46 @@ typedef LWIP_ERR_T err_t; typedef s8_t err_t; #endif /* LWIP_ERR_T*/ -/* Definitions for error constants. */ - +/** Definitions for error constants. */ +typedef enum { /** No error, everything OK. */ -#define ERR_OK 0 + ERR_OK = 0, /** Out of memory error. */ -#define ERR_MEM -1 + ERR_MEM = -1, /** Buffer error. */ -#define ERR_BUF -2 + ERR_BUF = -2, /** Timeout. */ -#define ERR_TIMEOUT -3 + ERR_TIMEOUT = -3, /** Routing problem. */ -#define ERR_RTE -4 + ERR_RTE = -4, /** Operation in progress */ -#define ERR_INPROGRESS -5 + ERR_INPROGRESS = -5, /** Illegal value. */ -#define ERR_VAL -6 + ERR_VAL = -6, /** Operation would block. */ -#define ERR_WOULDBLOCK -7 + ERR_WOULDBLOCK = -7, /** Address in use. */ -#define ERR_USE -8 + ERR_USE = -8, /** Already connecting. */ -#define ERR_ALREADY -9 + ERR_ALREADY = -9, /** Conn already established.*/ -#define ERR_ISCONN -10 + ERR_ISCONN = -10, /** Not connected. */ -#define ERR_CONN -11 + ERR_CONN = -11, /** Low-level netif error */ -#define ERR_IF -12 + ERR_IF = -12, + +/** Connection aborted. */ + ERR_ABRT = -13, +/** Connection reset. */ + ERR_RST = -14, +/** Connection closed. */ + ERR_CLSD = -15, +/** Illegal argument. */ + ERR_ARG = -16 +} err_enum_t; #define ERR_IS_FATAL(e) ((e) <= ERR_ABRT) -/** Connection aborted. */ -#define ERR_ABRT -13 -/** Connection reset. */ -#define ERR_RST -14 -/** Connection closed. */ -#define ERR_CLSD -15 -/** Illegal argument. */ -#define ERR_ARG -16 /** * @} From ce6ea0df1557571ad418b03fd61a83952bc6d4e3 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Fri, 12 Aug 2016 22:59:21 +0200 Subject: [PATCH 067/325] Convert SNMP snmp_vb_enumerator_err_t to a typedef and fix resulting compile error --- src/apps/snmp/snmp_msg.c | 2 +- src/apps/snmp/snmp_msg.h | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/apps/snmp/snmp_msg.c b/src/apps/snmp/snmp_msg.c index 48c08d5b..912f55aa 100644 --- a/src/apps/snmp/snmp_msg.c +++ b/src/apps/snmp/snmp_msg.c @@ -1547,7 +1547,7 @@ snmp_execute_write_callbacks(struct snmp_request *request) snmp_vb_enumerator_init(&inbound_varbind_enumerator, request->inbound_pbuf, request->inbound_varbind_offset, request->inbound_varbind_len); vb.value = NULL; /* do NOT decode value (we enumerate outbound buffer here, so all varbinds have values assigned, which we don't need here) */ - while (snmp_vb_enumerator_get_next(&inbound_varbind_enumerator, &vb) == ERR_OK) { + while (snmp_vb_enumerator_get_next(&inbound_varbind_enumerator, &vb) == SNMP_VB_ENUMERATOR_ERR_OK) { snmp_write_callback(vb.oid.id, vb.oid.len, snmp_write_callback_arg); } } diff --git a/src/apps/snmp/snmp_msg.h b/src/apps/snmp/snmp_msg.h index a14b05a6..2d01ef36 100644 --- a/src/apps/snmp/snmp_msg.h +++ b/src/apps/snmp/snmp_msg.h @@ -79,11 +79,12 @@ struct snmp_varbind_enumerator u16_t varbind_count; }; -typedef u8_t snmp_vb_enumerator_err_t; -#define SNMP_VB_ENUMERATOR_ERR_OK 0 -#define SNMP_VB_ENUMERATOR_ERR_EOVB 1 -#define SNMP_VB_ENUMERATOR_ERR_ASN1ERROR 2 -#define SNMP_VB_ENUMERATOR_ERR_INVALIDLENGTH 3 +typedef enum { + SNMP_VB_ENUMERATOR_ERR_OK = 0, + SNMP_VB_ENUMERATOR_ERR_EOVB = 1, + SNMP_VB_ENUMERATOR_ERR_ASN1ERROR = 2, + SNMP_VB_ENUMERATOR_ERR_INVALIDLENGTH = 3 +} snmp_vb_enumerator_err_t; void snmp_vb_enumerator_init(struct snmp_varbind_enumerator* enumerator, struct pbuf* p, u16_t offset, u16_t length); snmp_vb_enumerator_err_t snmp_vb_enumerator_get_next(struct snmp_varbind_enumerator* enumerator, struct snmp_varbind* varbind); From 5493220c93052db4ba423e2000e85135ffb95b57 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Sat, 13 Aug 2016 09:05:28 +0200 Subject: [PATCH 068/325] Move DNS protocol structs to separate header. Needed for Erik Ekman's MDNS implementation. --- src/core/dns.c | 73 +-------------------- src/include/lwip/prot/dns.h | 126 ++++++++++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+), 72 deletions(-) create mode 100644 src/include/lwip/prot/dns.h diff --git a/src/core/dns.c b/src/core/dns.c index 07c330cc..d9d7add7 100644 --- a/src/core/dns.c +++ b/src/core/dns.c @@ -86,6 +86,7 @@ #include "lwip/mem.h" #include "lwip/memp.h" #include "lwip/dns.h" +#include "lwip/prot/dns.h" #include @@ -104,11 +105,6 @@ static u16_t dns_txid; #define DNS_PORT_ALLOWED(port) ((port) >= 1024) #endif -/** DNS server port address */ -#ifndef DNS_SERVER_PORT -#define DNS_SERVER_PORT 53 -#endif - /** DNS maximum number of retries when asking for a name, before "timeout". */ #ifndef DNS_MAX_RETRIES #define DNS_MAX_RETRIES 4 @@ -165,73 +161,6 @@ static u16_t dns_txid; #define LWIP_DNS_SET_ADDRTYPE(x, y) #endif /* LWIP_IPV4 && LWIP_IPV6 */ -/** DNS field TYPE used for "Resource Records" */ -#define DNS_RRTYPE_A 1 /* a host address */ -#define DNS_RRTYPE_NS 2 /* an authoritative name server */ -#define DNS_RRTYPE_MD 3 /* a mail destination (Obsolete - use MX) */ -#define DNS_RRTYPE_MF 4 /* a mail forwarder (Obsolete - use MX) */ -#define DNS_RRTYPE_CNAME 5 /* the canonical name for an alias */ -#define DNS_RRTYPE_SOA 6 /* marks the start of a zone of authority */ -#define DNS_RRTYPE_MB 7 /* a mailbox domain name (EXPERIMENTAL) */ -#define DNS_RRTYPE_MG 8 /* a mail group member (EXPERIMENTAL) */ -#define DNS_RRTYPE_MR 9 /* a mail rename domain name (EXPERIMENTAL) */ -#define DNS_RRTYPE_NULL 10 /* a null RR (EXPERIMENTAL) */ -#define DNS_RRTYPE_WKS 11 /* a well known service description */ -#define DNS_RRTYPE_PTR 12 /* a domain name pointer */ -#define DNS_RRTYPE_HINFO 13 /* host information */ -#define DNS_RRTYPE_MINFO 14 /* mailbox or mail list information */ -#define DNS_RRTYPE_MX 15 /* mail exchange */ -#define DNS_RRTYPE_TXT 16 /* text strings */ -#define DNS_RRTYPE_AAAA 28 /* IPv6 address */ - -/** DNS field CLASS used for "Resource Records" */ -#define DNS_RRCLASS_IN 1 /* the Internet */ -#define DNS_RRCLASS_CS 2 /* the CSNET class (Obsolete - used only for examples in some obsolete RFCs) */ -#define DNS_RRCLASS_CH 3 /* the CHAOS class */ -#define DNS_RRCLASS_HS 4 /* Hesiod [Dyer 87] */ -#define DNS_RRCLASS_FLUSH 0x800 /* Flush bit */ - -/* DNS protocol flags */ -#define DNS_FLAG1_RESPONSE 0x80 -#define DNS_FLAG1_OPCODE_STATUS 0x10 -#define DNS_FLAG1_OPCODE_INVERSE 0x08 -#define DNS_FLAG1_OPCODE_STANDARD 0x00 -#define DNS_FLAG1_AUTHORATIVE 0x04 -#define DNS_FLAG1_TRUNC 0x02 -#define DNS_FLAG1_RD 0x01 -#define DNS_FLAG2_RA 0x80 -#define DNS_FLAG2_ERR_MASK 0x0f -#define DNS_FLAG2_ERR_NONE 0x00 -#define DNS_FLAG2_ERR_NAME 0x03 - -/* DNS protocol states */ -typedef enum { - DNS_STATE_UNUSED = 0, - DNS_STATE_NEW = 1, - DNS_STATE_ASKING = 2, - DNS_STATE_DONE = 3 -} dns_state_enum_t; - -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/bpstruct.h" -#endif -PACK_STRUCT_BEGIN -/** DNS message header */ -struct dns_hdr { - PACK_STRUCT_FIELD(u16_t id); - PACK_STRUCT_FLD_8(u8_t flags1); - PACK_STRUCT_FLD_8(u8_t flags2); - PACK_STRUCT_FIELD(u16_t numquestions); - PACK_STRUCT_FIELD(u16_t numanswers); - PACK_STRUCT_FIELD(u16_t numauthrr); - PACK_STRUCT_FIELD(u16_t numextrarr); -} PACK_STRUCT_STRUCT; -PACK_STRUCT_END -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/epstruct.h" -#endif -#define SIZEOF_DNS_HDR 12 - /** DNS query message structure. No packing needed: only used locally on the stack. */ struct dns_query { diff --git a/src/include/lwip/prot/dns.h b/src/include/lwip/prot/dns.h new file mode 100644 index 00000000..cfa7dabf --- /dev/null +++ b/src/include/lwip/prot/dns.h @@ -0,0 +1,126 @@ +/** + * @file + * DNS - host name to IP address resolver. + */ + +/* + * Port to lwIP from uIP + * by Jim Pettinato April 2007 + * + * security fixes and more by Simon Goldschmidt + * + * uIP version Copyright (c) 2002-2003, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef LWIP_HDR_PROT_DNS_H +#define LWIP_HDR_PROT_DNS_H + +#include "lwip/arch.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** DNS server port address */ +#ifndef DNS_SERVER_PORT +#define DNS_SERVER_PORT 53 +#endif + +/* DNS field TYPE used for "Resource Records" */ +#define DNS_RRTYPE_A 1 /* a host address */ +#define DNS_RRTYPE_NS 2 /* an authoritative name server */ +#define DNS_RRTYPE_MD 3 /* a mail destination (Obsolete - use MX) */ +#define DNS_RRTYPE_MF 4 /* a mail forwarder (Obsolete - use MX) */ +#define DNS_RRTYPE_CNAME 5 /* the canonical name for an alias */ +#define DNS_RRTYPE_SOA 6 /* marks the start of a zone of authority */ +#define DNS_RRTYPE_MB 7 /* a mailbox domain name (EXPERIMENTAL) */ +#define DNS_RRTYPE_MG 8 /* a mail group member (EXPERIMENTAL) */ +#define DNS_RRTYPE_MR 9 /* a mail rename domain name (EXPERIMENTAL) */ +#define DNS_RRTYPE_NULL 10 /* a null RR (EXPERIMENTAL) */ +#define DNS_RRTYPE_WKS 11 /* a well known service description */ +#define DNS_RRTYPE_PTR 12 /* a domain name pointer */ +#define DNS_RRTYPE_HINFO 13 /* host information */ +#define DNS_RRTYPE_MINFO 14 /* mailbox or mail list information */ +#define DNS_RRTYPE_MX 15 /* mail exchange */ +#define DNS_RRTYPE_TXT 16 /* text strings */ +#define DNS_RRTYPE_AAAA 28 /* IPv6 address */ + +/* DNS field CLASS used for "Resource Records" */ +#define DNS_RRCLASS_IN 1 /* the Internet */ +#define DNS_RRCLASS_CS 2 /* the CSNET class (Obsolete - used only for examples in some obsolete RFCs) */ +#define DNS_RRCLASS_CH 3 /* the CHAOS class */ +#define DNS_RRCLASS_HS 4 /* Hesiod [Dyer 87] */ +#define DNS_RRCLASS_FLUSH 0x800 /* Flush bit */ + +/* DNS protocol flags */ +#define DNS_FLAG1_RESPONSE 0x80 +#define DNS_FLAG1_OPCODE_STATUS 0x10 +#define DNS_FLAG1_OPCODE_INVERSE 0x08 +#define DNS_FLAG1_OPCODE_STANDARD 0x00 +#define DNS_FLAG1_AUTHORATIVE 0x04 +#define DNS_FLAG1_TRUNC 0x02 +#define DNS_FLAG1_RD 0x01 +#define DNS_FLAG2_RA 0x80 +#define DNS_FLAG2_ERR_MASK 0x0f +#define DNS_FLAG2_ERR_NONE 0x00 +#define DNS_FLAG2_ERR_NAME 0x03 + +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +/** DNS message header */ +struct dns_hdr { + PACK_STRUCT_FIELD(u16_t id); + PACK_STRUCT_FLD_8(u8_t flags1); + PACK_STRUCT_FLD_8(u8_t flags2); + PACK_STRUCT_FIELD(u16_t numquestions); + PACK_STRUCT_FIELD(u16_t numanswers); + PACK_STRUCT_FIELD(u16_t numauthrr); + PACK_STRUCT_FIELD(u16_t numextrarr); +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif +#define SIZEOF_DNS_HDR 12 + +/* DNS protocol states */ +typedef enum { + DNS_STATE_UNUSED = 0, + DNS_STATE_NEW = 1, + DNS_STATE_ASKING = 2, + DNS_STATE_DONE = 3 +} dns_state_enum_t; + +#ifdef __cplusplus +} +#endif + +#endif /* DNS_H */ + From 4e1f8effaf70190b5441f5e8967092c2bfaa4d2f Mon Sep 17 00:00:00 2001 From: Sylvain Rochet Date: Sat, 13 Aug 2016 10:42:13 +0200 Subject: [PATCH 069/325] PPP: fix ppp_write internal documentation This function returns an err_t, not a number of characters written. --- src/netif/ppp/ppp.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/netif/ppp/ppp.c b/src/netif/ppp/ppp.c index da5337ee..75a10d2f 100644 --- a/src/netif/ppp/ppp.c +++ b/src/netif/ppp/ppp.c @@ -1003,9 +1003,6 @@ struct pbuf *ppp_singlebuf(struct pbuf *p) { * IPv4 and IPv6 packets from lwIP are sent, respectively, * with ppp_netif_output_ip4() and ppp_netif_output_ip6() * functions (which are callbacks of the netif PPP interface). - * - * RETURN: >= 0 Number of characters written - * -1 Failed to write to device */ err_t ppp_write(ppp_pcb *pcb, struct pbuf *p) { #if PRINTPKT_SUPPORT From 4af297fc2018a4ab3f1e86dfdd94cf12dbf8a0c5 Mon Sep 17 00:00:00 2001 From: Sylvain Rochet Date: Sat, 13 Aug 2016 15:56:42 +0200 Subject: [PATCH 070/325] PPP: fix don't print valid LCP echo request/reply packets if the link is up The check for link up was missing, meaning valid LCP echo request/reply packets are filtered whatever the PPP state is, despite what the comment says. Fix it by checking the PPP state as we would like to have done when it was written. --- src/include/netif/ppp/ppp_impl.h | 2 +- src/netif/ppp/ppp.c | 4 ++-- src/netif/ppp/utils.c | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/include/netif/ppp/ppp_impl.h b/src/include/netif/ppp/ppp_impl.h index 8c60fef9..e9338de5 100644 --- a/src/include/netif/ppp/ppp_impl.h +++ b/src/include/netif/ppp/ppp_impl.h @@ -620,7 +620,7 @@ void ppp_warn(const char *fmt, ...); /* log a warning message */ void ppp_error(const char *fmt, ...); /* log an error message */ void ppp_fatal(const char *fmt, ...); /* log an error message and die(1) */ #if PRINTPKT_SUPPORT -void ppp_dump_packet(const char *tag, unsigned char *p, int len); +void ppp_dump_packet(ppp_pcb *pcb, const char *tag, unsigned char *p, int len); /* dump packet to debug log if interesting */ #endif /* PRINTPKT_SUPPORT */ diff --git a/src/netif/ppp/ppp.c b/src/netif/ppp/ppp.c index 75a10d2f..2f6ae11f 100644 --- a/src/netif/ppp/ppp.c +++ b/src/netif/ppp/ppp.c @@ -780,7 +780,7 @@ void ppp_input(ppp_pcb *pcb, struct pbuf *pb) { protocol = (((u8_t *)pb->payload)[0] << 8) | ((u8_t*)pb->payload)[1]; #if PRINTPKT_SUPPORT - ppp_dump_packet("rcvd", (unsigned char *)pb->payload, pb->len); + ppp_dump_packet(pcb, "rcvd", (unsigned char *)pb->payload, pb->len); #endif /* PRINTPKT_SUPPORT */ pbuf_header(pb, -(s16_t)sizeof(protocol)); @@ -1006,7 +1006,7 @@ struct pbuf *ppp_singlebuf(struct pbuf *p) { */ err_t ppp_write(ppp_pcb *pcb, struct pbuf *p) { #if PRINTPKT_SUPPORT - ppp_dump_packet("sent", (unsigned char *)p->payload+2, p->len-2); + ppp_dump_packet(pcb, "sent", (unsigned char *)p->payload+2, p->len-2); #endif /* PRINTPKT_SUPPORT */ return pcb->link_cb->write(pcb, pcb->link_ctx_cb, p); } diff --git a/src/netif/ppp/utils.c b/src/netif/ppp/utils.c index be53c0c6..1d44e9c3 100644 --- a/src/netif/ppp/utils.c +++ b/src/netif/ppp/utils.c @@ -702,7 +702,7 @@ void ppp_dbglog(const char *fmt, ...) { * ppp_dump_packet - print out a packet in readable form if it is interesting. * Assumes len >= PPP_HDRLEN. */ -void ppp_dump_packet(const char *tag, unsigned char *p, int len) { +void ppp_dump_packet(ppp_pcb *pcb, const char *tag, unsigned char *p, int len) { int proto; /* @@ -713,9 +713,9 @@ void ppp_dump_packet(const char *tag, unsigned char *p, int len) { return; /* - * don't print LCP echo request/reply packets if the link is up. + * don't print valid LCP echo request/reply packets if the link is up. */ - if (proto == PPP_LCP && len >= 2 + HEADERLEN) { + if (proto == PPP_LCP && pcb->phase == PPP_PHASE_RUNNING && len >= 2 + HEADERLEN) { unsigned char *lcp = p + 2; int l = (lcp[2] << 8) + lcp[3]; From 4919932c495fb2f3169a933712c67ab160f289ce Mon Sep 17 00:00:00 2001 From: Erik Ekman Date: Sun, 14 Aug 2016 15:02:15 +0200 Subject: [PATCH 071/325] Apply patch #8755: Multicast DNS responder support from Erik Ekman --- README | 1 + doc/mdns.txt | 109 ++ src/Filelists.mk | 4 + src/apps/mdns/mdns.c | 2044 +++++++++++++++++++++++++++++ src/core/netif.c | 4 + src/include/lwip/apps/mdns.h | 78 ++ src/include/lwip/apps/mdns_opts.h | 41 + src/include/lwip/netif.h | 8 + src/include/lwip/prot/dns.h | 7 +- test/unit/lwip_unittests.c | 4 +- test/unit/lwipopts.h | 4 + test/unit/mdns/test_mdns.c | 887 +++++++++++++ test/unit/mdns/test_mdns.h | 8 + 13 files changed, 3197 insertions(+), 2 deletions(-) create mode 100644 doc/mdns.txt create mode 100644 src/apps/mdns/mdns.c create mode 100644 src/include/lwip/apps/mdns.h create mode 100644 src/include/lwip/apps/mdns_opts.h create mode 100644 test/unit/mdns/test_mdns.c create mode 100644 test/unit/mdns/test_mdns.h diff --git a/README b/README index dbcec5f2..3c01a901 100644 --- a/README +++ b/README @@ -28,6 +28,7 @@ FEATURES * raw/native API for enhanced performance * Optional Berkeley-like socket API * DNS (Domain names resolver) + * MDNS (Multicast DNS) responder APPLICATIONS diff --git a/doc/mdns.txt b/doc/mdns.txt new file mode 100644 index 00000000..3cbb1ba4 --- /dev/null +++ b/doc/mdns.txt @@ -0,0 +1,109 @@ +Multicast DNS for lwIP + +Author: Erik Ekman + + +Note! The MDNS responder does not have all features required by the standards. +See notes in src/core/mdns.c for what is left. It is however usable in normal +cases - but watch out if many devices on the same network try to use the same +host/service instance names. + + +How to enable: +============== + +MDNS support does not depend on DNS. +MDNS supports using IPv4 only, v6 only, or v4+v6. + +To enable MDNS responder, set + LWIP_MDNS = 1 +in lwipopts.h and add src/core/mdns.c to your list of files to build. + +The max number of services supported per netif is defined by MDNS_MAX_SERVICES, +default is 1. + +Increase MEMP_NUM_UDP_PCB. MDNS needs one PCB for IPv4 and one for IPv6. + +MDNS with IPv4 requires LWIP_IGMP = 1, and preferably LWIP_AUTOIP = 1. +MDNS with IPv6 requires LWIP_IPV6_MLD = 1, and that a link-local address is +generated. + +The MDNS code puts its structs on the stack where suitable to reduce dynamic +memory allocation. It may use up to 1kB of stack. + +MDNS needs a strncasecmp() implementation. If you have one, define +LWIP_MDNS_STRNCASECMP to it. Otherwise the code will provide an implementation +for you. + + +How to use: +=========== + +Call mdns_resp_init() during system initialization. +This opens UDP sockets on port 5353 for IPv4 and IPv6. + + +To start responding on a netif, run + mdns_resp_add_netif(struct netif *netif, char *hostname, u32_t dns_ttl) + +The hostname will be copied. If this returns successfully, the netif will join +the multicast groups and any MDNS/legacy DNS requests sent unicast or multicast +to port 5353 will be handled: +- .local type A, AAAA or ANY returns relevant IP addresses +- Reverse lookups (PTR in-addr.arpa, ip6.arpa) of netif addresses + returns .local +Answers will use the supplied TTL (in seconds) +MDNS allows UTF-8 names, but it is recommended to stay within ASCII, +since the default case-insensitive comparison assumes this. + +It is recommended to call this function after an IPv4 address has been set, +since there is currently no check if the v4 address is valid. + +To stop responding on a netif, run + mdns_resp_remove_netif(struct netif *netif) + + +Adding services: +================ + +The netif first needs to be registered. Then run + mdns_resp_add_service(struct netif *netif, char *name, char *service, + u16_t proto, u16_t port, u32_t dns_ttl, + service_get_txt_fn_t txt_fn, void *txt_userdata); + +The name and service pointers will be copied. Name refers to the name of the +service instance, and service is the type of service, like _http +proto can be DNSSD_PROTO_UDP or DNSSD_PROTO_TCP which represent _udp and _tcp. +If this call returns successfully, the following queries will be answered: +- _services._dns-sd._udp.local type PTR returns ..local +- ..local type PTR returns ...local +- ...local type SRV returns hostname and port of service +- ...local type TXT builds text strings by calling txt_fn + with the supplied userdata. The callback adds strings to the reply by calling + mdns_resp_add_service_txtitem(struct mdns_service *service, char *txt, + int txt_len). Example callback method: + + static void srv_txt(struct mdns_service *service, void *txt_userdata) + { + res = mdns_resp_add_service_txtitem(service, "path=/", 6); + LWIP_ERROR("mdns add service txt failed\n", (res == ERR_OK), return); + } + + Since a hostname struct is used for TXT storage each single item can be max + 63 bytes long, and the total max length (including length bytes for each + item) is 255 bytes. + +If your device runs a webserver on port 80, an example call might be: + + mdns_resp_add_service(netif, "myweb", "_http" + DNSSD_PROTO_TCP, 80, 3600, srv_txt, NULL); + +which will publish myweb._http._tcp.local for any hosts looking for web servers, +and point them to .local:80 + +Relevant information will be sent as additional records to reduce number of +requests required from a client. + +Removing services is currently not supported. Services are removed when the +netif is removed. + diff --git a/src/Filelists.mk b/src/Filelists.mk index b3b14ebf..2dd0d36b 100644 --- a/src/Filelists.mk +++ b/src/Filelists.mk @@ -158,6 +158,9 @@ LWIPERFFILES=$(LWIPDIR)/apps/lwiperf/lwiperf.c # SNTPFILES: SNTP client SNTPFILES=$(LWIPDIR)/apps/sntp/sntp.c +# MDNSFILES: MDNS responder +MDNSFILES=$(LWIPDIR)/apps/mdns/mdns.c + # NETBIOSNSFILES: NetBIOS name server NETBIOSNSFILES=$(LWIPDIR)/apps/netbiosns/netbiosns.c @@ -166,4 +169,5 @@ LWIPAPPFILES=$(SNMPFILES) \ $(HTTPDFILES) \ $(LWIPERFFILES) \ $(SNTPFILES) \ + $(MDNSFILES) \ $(NETBIOSNSFILES) diff --git a/src/apps/mdns/mdns.c b/src/apps/mdns/mdns.c new file mode 100644 index 00000000..14938468 --- /dev/null +++ b/src/apps/mdns/mdns.c @@ -0,0 +1,2044 @@ +/** + * @file + * MDNS responder implementation + */ + +/* + * Copyright (c) 2015 Verisure Innovation AB + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Erik Ekman + * + * Please coordinate changes and requests with Erik Ekman + * + * + */ + +/** + * @defgroup mdns MDNS + * @ingroup apps + * + * RFC 6762 - Multicast DNS + * RFC 6763 - DNS-Based Service Discovery + * + * @verbinclude mdns.txt + * + * Things left to implement: + * ------------------------- + * + * - Probing/conflict resolution + * - Sending goodbye messages (zero ttl) + * - Checking that source address of unicast requests are on the same network + * - Limiting multicast responses to 1 per second per resource record + * - Fragmenting replies if required + * - Subscribe to netif address/link change events and act on them + * - Handling multi-packet known answers + * - Individual known answer detection for all local IPv6 addresses + * - Dynamic size of outgoing packet + */ + +#include "lwip/opt.h" + +#include "lwip/apps/mdns.h" +#include "lwip/netif.h" +#include "lwip/udp.h" +#include "lwip/ip_addr.h" +#include "lwip/mem.h" +#include "lwip/prot/dns.h" + +#include +#include + +#if LWIP_MDNS + +#if (LWIP_IPV4 && !LWIP_IGMP) + #error "If you want to use MDNS with IPv4, you have to define LWIP_IGMP=1 in your lwipopts.h" +#endif +#if (LWIP_IPV6 && !LWIP_IPV6_MLD) +#error "If you want to use MDNS with IPv6, you have to define LWIP_IPV6_MLD=1 in your lwipopts.h" +#endif +#if (!LWIP_UDP) + #error "If you want to use MDNS, you have to define LWIP_UDP=1 in your lwipopts.h" +#endif + +#if LWIP_IPV4 +#include "lwip/igmp.h" +/* IPv4 multicast group 224.0.0.251 */ +static const ip_addr_t v4group = IPADDR4_INIT(PP_HTONL(0xE00000FBUL)); +#endif + +#if LWIP_IPV6 +#include "lwip/mld6.h" +/* IPv6 multicast group FF02::FB */ +static const ip_addr_t v6group = IPADDR6_INIT(PP_HTONL(0xFF020000UL), PP_HTONL(0x00000000UL), PP_HTONL(0x00000000UL), PP_HTONL(0x000000FBUL)); +#endif + +#define MDNS_PORT 5353 +#define MDNS_TTL 255 + +/* Stored offsets to beginning of domain names + * Used for compression. + */ +#define NUM_DOMAIN_OFFSETS 10 +#define DOMAIN_JUMP_SIZE 2 +#define DOMAIN_JUMP 0xc000 + +static struct mdns_data { +#if LWIP_IPV4 + struct udp_pcb *v4pcb; +#endif +#if LWIP_IPV6 + struct udp_pcb *v6pcb; +#endif +} mdns_data; + +#define TOPDOMAIN_LOCAL "local" + +#define REVERSE_PTR_TOPDOMAIN "arpa" +#define REVERSE_PTR_V4_DOMAIN "in-addr" +#define REVERSE_PTR_V6_DOMAIN "ip6" + +#define SRV_PRIORITY 0 +#define SRV_WEIGHT 0 + +/* Payload size allocated for each outgoing UDP packet */ +#define OUTPACKET_SIZE 500 + +/* Lookup from hostname -> IPv4 */ +#define REPLY_HOST_A 0x01 +/* Lookup from IPv4/v6 -> hostname */ +#define REPLY_HOST_PTR_V4 0x02 +/* Lookup from hostname -> IPv6 */ +#define REPLY_HOST_AAAA 0x04 +/* Lookup from hostname -> IPv6 */ +#define REPLY_HOST_PTR_V6 0x08 + +/* Lookup for service types */ +#define REPLY_SERVICE_TYPE_PTR 0x10 +/* Lookup for instances of service */ +#define REPLY_SERVICE_NAME_PTR 0x20 +/* Lookup for location of service instance */ +#define REPLY_SERVICE_SRV 0x40 +/* Lookup for text info on service instance */ +#define REPLY_SERVICE_TXT 0x80 + +static const char *dnssd_protos[] = { + "_udp", /* DNSSD_PROTO_UDP */ + "_tcp", /* DNSSD_PROTO_TCP */ +}; + +/** Description of a service */ +struct mdns_service { + /** TXT record to answer with */ + struct mdns_domain txtdata; + /** Name of service, like 'myweb' */ + char name[MDNS_LABEL_MAXLEN + 1]; + /** Type of service, like '_http' */ + char service[MDNS_LABEL_MAXLEN + 1]; + /** Callback function and userdata + * to update txtdata buffer */ + service_get_txt_fn_t txt_fn; + void *txt_userdata; + /** TTL in seconds of SRV/TXT replies */ + u32_t dns_ttl; + /** Protocol, TCP or UDP */ + u16_t proto; + /** Port of the service */ + u16_t port; +}; + +/** Description of a host/netif */ +struct mdns_host { + /** Hostname */ + char name[MDNS_LABEL_MAXLEN + 1]; + /** Pointer to services */ + struct mdns_service *services[MDNS_MAX_SERVICES]; + /** TTL in seconds of A/AAAA/PTR replies */ + u32_t dns_ttl; +}; + +/** Information about received packet */ +struct mdns_packet { + /** Sender IP/port */ + ip_addr_t source_addr; + u16_t source_port; + /** If packet was received unicast */ + u16_t recv_unicast; + /** Netif that received the packet */ + struct netif *netif; + /** Packet data */ + struct pbuf *pbuf; + /** Current parsing offset in packet */ + u16_t parse_offset; + /** Identifier. Used in legacy queries */ + u16_t tx_id; + /** Number of questions in packet, + * read from packet header */ + u16_t questions; + /** Number of unparsed questions */ + u16_t questions_left; + /** Number of answers in packet, + * (sum of normal, authorative and additional answers) + * read from packet header */ + u16_t answers; + /** Number of unparsed answers */ + u16_t answers_left; +}; + +/** Information about outgoing packet */ +struct mdns_outpacket { + /** Netif to send the packet on */ + struct netif *netif; + /** Packet data */ + struct pbuf *pbuf; + /** Current write offset in packet */ + u16_t write_offset; + /** Identifier. Used in legacy queries */ + u16_t tx_id; + /** Destination IP/port if sent unicast */ + ip_addr_t dest_addr; + u16_t dest_port; + /** Number of questions written */ + u16_t questions; + /** Number of normal answers written */ + u16_t answers; + /** Number of additional answers written */ + u16_t additional; + /** Offsets for written domain names in packet. + * Used for compression */ + u16_t domain_offsets[NUM_DOMAIN_OFFSETS]; + /** If all answers in packet should set cache_flush bit */ + u8_t cache_flush; + /** If reply should be sent unicast */ + u8_t unicast_reply; + /** If legacy query. (tx_id needed, and write + * question again in reply before answer) */ + u8_t legacy_query; + /* Reply bitmask for host information */ + u8_t host_replies; + /* Bitmask for which reverse IPv6 hosts to answer */ + u8_t host_reverse_v6_replies; + /* Reply bitmask per service */ + u8_t serv_replies[MDNS_MAX_SERVICES]; +}; + +/** Domain, type and class. + * Shared between questions and answers */ +struct mdns_rr_info { + struct mdns_domain domain; + u16_t type; + u16_t klass; +}; + +struct mdns_question { + struct mdns_rr_info info; + /** unicast reply requested */ + u16_t unicast; +}; + +struct mdns_answer { + struct mdns_rr_info info; + /** cache flush command bit */ + u16_t cache_flush; + /* Validity time in seconds */ + u32_t ttl; + /** Length of variable answer */ + u16_t rd_length; + /** Offset of start of variable answer in packet */ + u16_t rd_offset; +}; + +#ifndef LWIP_MDNS_STRNCASECMP +#define LWIP_MDNS_STRNCASECMP(str1, str2, len) mdns_strncasecmp(str1, str2, len) +/** + * A small but sufficient implementation for case insensitive strncmp. + * This can be defined to e.g. strnicmp for windows or strncasecmp for linux. + */ +static int +mdns_strncasecmp(const char* str1, const char* str2, size_t len) +{ + char c1, c2; + + do { + c1 = *str1++; + c2 = *str2++; + if (c1 != c2) { + char c1_upc = c1 | 0x20; + if ((c1_upc >= 'a') && (c1_upc <= 'z')) { + /* characters are not equal an one is in the alphabet range: + downcase both chars and check again */ + char c2_upc = c2 | 0x20; + if (c1_upc != c2_upc) { + /* still not equal */ + /* don't care for < or > */ + return 1; + } + } else { + /* characters are not equal but none is in the alphabet range */ + return 1; + } + } + } while (len-- && c1 != 0); + return 0; +} +#endif /* LWIP_MDNS_STRNCASECMP */ + + +/** + * Add a label part to a domain + * @param domain The domain to add a label to + * @param label The label to add, like , 'local', 'com' or '' + * @param len The length of the label + * @return ERR_OK on success, an err_t otherwise if label too long + */ +err_t +mdns_domain_add_label(struct mdns_domain *domain, const char *label, unsigned len) +{ + if (len > MDNS_LABEL_MAXLEN) { + return ERR_VAL; + } + if (len > 0 && (1 + len + domain->length >= MDNS_DOMAIN_MAXLEN)) { + return ERR_VAL; + } + /* Allow only zero marker on last byte */ + if (len == 0 && (1 + domain->length > MDNS_DOMAIN_MAXLEN)) { + return ERR_VAL; + } + domain->name[domain->length] = len; + domain->length++; + if (len) { + memcpy(&domain->name[domain->length], label, len); + domain->length += len; + } + return ERR_OK; +} + +/** + * Internal readname function with max 6 levels of recursion following jumps + * while decompressing name + */ +static u16_t +mdns_readname_loop(struct pbuf *p, u16_t offset, struct mdns_domain *domain, unsigned depth) +{ + u8_t c; + + do { + if (depth > 5) { + /* Too many jumps */ + return MDNS_READNAME_ERROR; + } + + c = pbuf_get_at(p, offset); + offset++; + + /* is this a compressed label? */ + if((c & 0xc0) == 0xc0) { + u16_t jumpaddr; + if (offset >= p->tot_len) { + /* Make sure both jump bytes fit in the packet */ + return MDNS_READNAME_ERROR; + } + jumpaddr = (((c & 0x3f) << 8) | (pbuf_get_at(p, offset) & 0xff)); + offset++; + if (jumpaddr >= SIZEOF_DNS_HDR && jumpaddr < p->tot_len) { + u16_t res; + /* Recursive call, maximum depth will be checked */ + res = mdns_readname_loop(p, jumpaddr, domain, depth + 1); + /* Dont return offset since new bytes were not read (jumped to somewhere in packet) */ + if (res == MDNS_READNAME_ERROR) { + return res; + } + } else { + return MDNS_READNAME_ERROR; + } + break; + } + + /* normal label */ + if (c <= MDNS_LABEL_MAXLEN) { + u8_t label[MDNS_LABEL_MAXLEN]; + err_t res; + + if (c + domain->length >= MDNS_DOMAIN_MAXLEN) { + return MDNS_READNAME_ERROR; + } + if (c) { + u16_t copied = pbuf_copy_partial(p, label, c, offset); + if (copied != c) { + return MDNS_READNAME_ERROR; + } + offset += c; + } + res = mdns_domain_add_label(domain, (char *) label, c); + if (res != ERR_OK) { + return MDNS_READNAME_ERROR; + } + } else { + /* bad length byte */ + return MDNS_READNAME_ERROR; + } + } while (c); + + return offset; +} + +/** + * Read possibly compressed domain name from packet buffer + * @param pbuf The packet + * @param offset start position of domain name in packet + * @param domain The domain name destination + * @return The new offset after the domain, or MDNS_READNAME_ERROR + * if reading failed + */ +u16_t +mdns_readname(struct pbuf *p, u16_t offset, struct mdns_domain *domain) +{ + memset(domain, 0, sizeof(struct mdns_domain)); + return mdns_readname_loop(p, offset, domain, 0); +} + +/** + * Print domain name to debug output + * @param debug debug level + * @param domain The domain name + */ +static void +mdns_domain_debug_print(int debug, struct mdns_domain *domain) +{ + u8_t *src = domain->name; + u8_t i; + + while (*src) { + u8_t label_len = *src; + src++; + for (i = 0; i < label_len; i++) { + LWIP_DEBUGF(debug, ("%c", src[i])); + } + src += label_len; + LWIP_DEBUGF(debug, (".")); + } +} + +/** + * Return 1 if contents of domains match (case-insensitive) + * @param a Domain name to compare 1 + * @param b Domain name to compare 2 + * @return 1 if domains are equal ignoring case, 0 otherwise + */ +int +mdns_domain_eq(struct mdns_domain *a, struct mdns_domain *b) +{ + u8_t *ptra, *ptrb; + u8_t len; + int res; + + if (a->length != b->length) { + return 0; + } + + ptra = a->name; + ptrb = b->name; + while (*ptra && *ptrb && ptra < &a->name[a->length]) { + if (*ptra != *ptrb) { + return 0; + } + len = *ptra; + ptra++; + ptrb++; + res = LWIP_MDNS_STRNCASECMP((char *) ptra, (char *) ptrb, len); + if (res != 0) { + return 0; + } + ptra += len; + ptrb += len; + } + if (*ptra != *ptrb && ptra < &a->name[a->length]) { + return 0; + } + return 1; +} + +/** + * Call user supplied function to setup TXT data + * @param service The service to build TXT record for + */ +static void +mdns_prepare_txtdata(struct mdns_service *service) +{ + memset(&service->txtdata, 0, sizeof(struct mdns_domain)); + if (service->txt_fn) { + service->txt_fn(service, service->txt_userdata); + } +} + +#if LWIP_IPV4 +/** + * Build domain for reverse lookup of IPv4 address + * like 12.0.168.192.in-addr.arpa. for 192.168.0.12 + * @param domain Where to write the domain name + * @param addr Pointer to an IPv4 address to encode + * @return ERR_OK if domain was written, an err_t otherwise + */ +static err_t +mdns_build_reverse_v4_domain(struct mdns_domain *domain, const ip4_addr_t *addr) +{ + int i; + int res; + const u8_t *ptr; + if (!domain || !addr) { + return ERR_ARG; + } + memset(domain, 0, sizeof(struct mdns_domain)); + ptr = (const u8_t *) addr; + for (i = sizeof(ip4_addr_t) - 1; i >= 0; i--) { + char buf[4]; + snprintf(buf, sizeof(buf), "%d", ptr[i]); + res = mdns_domain_add_label(domain, buf, strlen(buf)); + LWIP_ERROR("mdns_build_reverse_v4_domain: Failed to add label", (res == ERR_OK), return res); + } + res = mdns_domain_add_label(domain, REVERSE_PTR_V4_DOMAIN, strlen(REVERSE_PTR_V4_DOMAIN)); + LWIP_ERROR("mdns_build_reverse_v4_domain: Failed to add label", (res == ERR_OK), return res); + res = mdns_domain_add_label(domain, REVERSE_PTR_TOPDOMAIN, strlen(REVERSE_PTR_TOPDOMAIN)); + LWIP_ERROR("mdns_build_reverse_v4_domain: Failed to add label", (res == ERR_OK), return res); + res = mdns_domain_add_label(domain, NULL, 0); + LWIP_ERROR("mdns_build_reverse_v4_domain: Failed to add label", (res == ERR_OK), return res); + + return ERR_OK; +} +#endif + +#if LWIP_IPV6 +/** + * Build domain for reverse lookup of IP address + * like b.a.9.8.7.6.5.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa. for 2001:db8::567:89ab + * @param domain Where to write the domain name + * @param addr Pointer to an IPv6 address to encode + * @return ERR_OK if domain was written, an err_t otherwise + */ +static err_t +mdns_build_reverse_v6_domain(struct mdns_domain *domain, const ip6_addr_t *addr) +{ + int i; + int res; + const u8_t *ptr; + if (!domain || !addr) { + return ERR_ARG; + } + memset(domain, 0, sizeof(struct mdns_domain)); + ptr = (const u8_t *) addr; + for (i = sizeof(ip6_addr_t) - 1; i >= 0; i--) { + char buf; + u8_t byte = ptr[i]; + int j; + for (j = 0; j < 2; j++) { + if ((byte & 0x0F) < 0xA) { + buf = '0' + (byte & 0x0F); + } else { + buf = 'a' + (byte & 0x0F) - 0xA; + } + res = mdns_domain_add_label(domain, &buf, sizeof(buf)); + LWIP_ERROR("mdns_build_reverse_v6_domain: Failed to add label", (res == ERR_OK), return res); + byte >>= 4; + } + } + res = mdns_domain_add_label(domain, REVERSE_PTR_V6_DOMAIN, strlen(REVERSE_PTR_V6_DOMAIN)); + LWIP_ERROR("mdns_build_reverse_v6_domain: Failed to add label", (res == ERR_OK), return res); + res = mdns_domain_add_label(domain, REVERSE_PTR_TOPDOMAIN, strlen(REVERSE_PTR_TOPDOMAIN)); + LWIP_ERROR("mdns_build_reverse_v6_domain: Failed to add label", (res == ERR_OK), return res); + res = mdns_domain_add_label(domain, NULL, 0); + LWIP_ERROR("mdns_build_reverse_v6_domain: Failed to add label", (res == ERR_OK), return res); + + return ERR_OK; +} +#endif + +/* Add .local. to domain */ +static err_t +mdns_add_dotlocal(struct mdns_domain *domain) +{ + err_t res = mdns_domain_add_label(domain, TOPDOMAIN_LOCAL, strlen(TOPDOMAIN_LOCAL)); + LWIP_ERROR("mdns_add_dotlocal: Failed to add label", (res == ERR_OK), return res); + return mdns_domain_add_label(domain, NULL, 0); +} + +/** + * Build the .local. domain name + * @param domain Where to write the domain name + * @param netif The network interface to use, its MDNS struct will be referenced to + * get the hostname. + * @return ERR_OK if domain .local. was written, an err_t otherwise + */ +static err_t +mdns_build_host_domain(struct mdns_domain *domain, struct netif *netif) +{ + err_t res; + memset(domain, 0, sizeof(struct mdns_domain)); + LWIP_ERROR("mdns_resp_add_service: Not an mdns netif", (netif->mdns != NULL), return ERR_VAL); + res = mdns_domain_add_label(domain, netif->mdns->name, strlen(netif->mdns->name)); + LWIP_ERROR("mdns_build_host_domain: Failed to add label", (res == ERR_OK), return res); + return mdns_add_dotlocal(domain); +} + +/** + * Build the lookup-all-services special DNS-SD domain name + * @param domain Where to write the domain name + * @return ERR_OK if domain _services._dns-sd._udp.local. was written, an err_t otherwise + */ +static err_t +mdns_build_dnssd_domain(struct mdns_domain *domain) +{ + err_t res; + memset(domain, 0, sizeof(struct mdns_domain)); + res = mdns_domain_add_label(domain, "_services", strlen("_services")); + LWIP_ERROR("mdns_build_dnssd_domain: Failed to add label", (res == ERR_OK), return res); + res = mdns_domain_add_label(domain, "_dns-sd", strlen("_dns-sd")); + LWIP_ERROR("mdns_build_dnssd_domain: Failed to add label", (res == ERR_OK), return res); + res = mdns_domain_add_label(domain, dnssd_protos[DNSSD_PROTO_UDP], strlen(dnssd_protos[DNSSD_PROTO_UDP])); + LWIP_ERROR("mdns_build_dnssd_domain: Failed to add label", (res == ERR_OK), return res); + return mdns_add_dotlocal(domain); +} + +/** + * Build domain name for a service + * @param domain Where to write the domain name + * @param service The service struct, containing service name, type and protocol + * @param include_name Whether to include the service name in the domain + * @return ERR_OK if domain was written. If service name is included, + * ...local. will be written, otherwise ..local. + * An err_t is returned on error. + */ +static err_t +mdns_build_service_domain(struct mdns_domain *domain, struct mdns_service *service, int include_name) +{ + err_t res; + memset(domain, 0, sizeof(struct mdns_domain)); + if (include_name) { + res = mdns_domain_add_label(domain, service->name, strlen(service->name)); + LWIP_ERROR("mdns_build_service_domain: Failed to add label", (res == ERR_OK), return res); + } + res = mdns_domain_add_label(domain, service->service, strlen(service->service)); + LWIP_ERROR("mdns_build_service_domain: Failed to add label", (res == ERR_OK), return res); + res = mdns_domain_add_label(domain, dnssd_protos[service->proto], strlen(dnssd_protos[service->proto])); + LWIP_ERROR("mdns_build_service_domain: Failed to add label", (res == ERR_OK), return res); + return mdns_add_dotlocal(domain); +} + +/** + * Check which replies we should send for a host/netif based on question + * @param netif The network interface that received the question + * @param rr Domain/type/class from a question + * @param reverse_v6_reply Bitmask of which IPv6 addresses to send reverse PTRs for + * if reply bit has REPLY_HOST_PTR_V6 set + * @return Bitmask of which replies to send + */ +static int +check_host(struct netif *netif, struct mdns_rr_info *rr, u8_t *reverse_v6_reply) +{ + err_t res; + int replies = 0; + struct mdns_domain mydomain; + + LWIP_UNUSED_ARG(reverse_v6_reply); /* if ipv6 is disabled */ + + if (rr->klass != DNS_RRCLASS_IN && rr->klass != DNS_RRCLASS_ANY) { + /* Invalid class */ + return replies; + } + + /* Handle PTR for our addresses */ + if (rr->type == DNS_RRTYPE_PTR || rr->type == DNS_RRTYPE_ANY) { +#if LWIP_IPV6 + int i; + for (i = 0; i < LWIP_IPV6_NUM_ADDRESSES; i++) { + if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i))) { + res = mdns_build_reverse_v6_domain(&mydomain, netif_ip6_addr(netif, i)); + if (res == ERR_OK && mdns_domain_eq(&rr->domain, &mydomain)) { + replies |= REPLY_HOST_PTR_V6; + /* Mark which addresses where requested */ + if (reverse_v6_reply) { + *reverse_v6_reply |= (1 << i); + } + } + } + } +#endif +#if LWIP_IPV4 + res = mdns_build_reverse_v4_domain(&mydomain, netif_ip4_addr(netif)); + if (res == ERR_OK && mdns_domain_eq(&rr->domain, &mydomain)) { + replies |= REPLY_HOST_PTR_V4; + } +#endif + } + + res = mdns_build_host_domain(&mydomain, netif); + /* Handle requests for our hostname */ + if (res == ERR_OK && mdns_domain_eq(&rr->domain, &mydomain)) { + /* TODO return NSEC if unsupported protocol requested */ +#if LWIP_IPV4 + if (rr->type == DNS_RRTYPE_A || rr->type == DNS_RRTYPE_ANY) { + replies |= REPLY_HOST_A; + } +#endif +#if LWIP_IPV6 + if (rr->type == DNS_RRTYPE_AAAA || rr->type == DNS_RRTYPE_ANY) { + replies |= REPLY_HOST_AAAA; + } +#endif + } + + return replies; +} + +/** + * Check which replies we should send for a service based on question + * @param service A registered MDNS service + * @param rr Domain/type/class from a question + * @return Bitmask of which replies to send + */ +static int +check_service(struct mdns_service *service, struct mdns_rr_info *rr) +{ + err_t res; + int replies = 0; + struct mdns_domain mydomain; + + if (rr->klass != DNS_RRCLASS_IN && rr->klass != DNS_RRCLASS_ANY) { + /* Invalid class */ + return 0; + } + + res = mdns_build_dnssd_domain(&mydomain); + if (res == ERR_OK && mdns_domain_eq(&rr->domain, &mydomain) && + (rr->type == DNS_RRTYPE_PTR || rr->type == DNS_RRTYPE_ANY)) { + /* Request for all service types */ + replies |= REPLY_SERVICE_TYPE_PTR; + } + + res = mdns_build_service_domain(&mydomain, service, 0); + if (res == ERR_OK && mdns_domain_eq(&rr->domain, &mydomain) && + (rr->type == DNS_RRTYPE_PTR || rr->type == DNS_RRTYPE_ANY)) { + /* Request for the instance of my service */ + replies |= REPLY_SERVICE_NAME_PTR; + } + + res = mdns_build_service_domain(&mydomain, service, 1); + if (res == ERR_OK && mdns_domain_eq(&rr->domain, &mydomain)) { + /* Request for info about my service */ + if (rr->type == DNS_RRTYPE_SRV || rr->type == DNS_RRTYPE_ANY) { + replies |= REPLY_SERVICE_SRV; + } + if (rr->type == DNS_RRTYPE_TXT || rr->type == DNS_RRTYPE_ANY) { + replies |= REPLY_SERVICE_TXT; + } + } + + return replies; +} + +/** + * Return bytes needed to write before jump for best result of compressing supplied domain + * against domain in outpacket starting at specified offset. + * If a match is found, offset is updated to where to jump to + * @param pbuf Pointer to pbuf with the partially constructed DNS packet + * @param offset Start position of a domain written earlier. If this location is suitable + * for compression, the pointer is updated to where in the domain to jump to. + * @param domain The domain to write + * @return Number of bytes to write of the new domain before writing a jump to the offset. + * If compression can not be done against this previous domain name, the full new + * domain length is returned. + */ +u8_t +mdns_compress_domain(struct pbuf *pbuf, u16_t *offset, struct mdns_domain *domain) +{ + struct mdns_domain target; + u16_t target_end; + u8_t target_len; + u8_t writelen = 0; + u8_t *ptr; + if (pbuf == NULL) { + return domain->length; + } + target_end = mdns_readname(pbuf, *offset, &target); + if (target_end == MDNS_READNAME_ERROR) { + return domain->length; + } + target_len = target_end - *offset; + ptr = domain->name; + while (writelen < domain->length) { + u8_t domainlen = domain->length - writelen; + u8_t labellen; + if (domainlen <= target.length && domainlen > DOMAIN_JUMP_SIZE) { + /* Compare domains if target is long enough, and we have enough left of the domain */ + u8_t targetpos = target.length - domainlen; + if ((targetpos + DOMAIN_JUMP_SIZE) >= target_len) { + /* We are checking at or beyond a jump in the original, stop looking */ + break; + } + if (target.length >= domainlen && + memcmp(&domain->name[writelen], &target.name[targetpos], domainlen) == 0) { + *offset += targetpos; + return writelen; + } + } + /* Skip to next label in domain */ + labellen = *ptr; + writelen += 1 + labellen; + ptr += 1 + labellen; + } + /* Nothing found */ + return domain->length; +} + +/** + * Write domain to outpacket. Compression will be attempted, + * unless domain->skip_compression is set. + * @param outpkt The outpacket to write to + * @param domain The domain name to write + * @return ERR_OK on success, an err_t otherwise + */ +static err_t +mdns_write_domain(struct mdns_outpacket *outpkt, struct mdns_domain *domain) +{ + int i; + err_t res; + u8_t writelen = domain->length; + u16_t jump_offset = 0; + u16_t jump; + + if (outpkt && outpkt->pbuf && !domain->skip_compression) { + for (i = 0; i < NUM_DOMAIN_OFFSETS; ++i) { + u16_t offset = outpkt->domain_offsets[i]; + if (offset) { + u8_t len = mdns_compress_domain(outpkt->pbuf, &offset, domain); + if (len < writelen) { + writelen = len; + jump_offset = offset; + } + } + } + } + + if (writelen) { + /* Write uncompressed part of name */ + res = pbuf_take_at(outpkt->pbuf, domain->name, writelen, outpkt->write_offset); + if (res != ERR_OK) { + return res; + } + + /* Store offset of this new domain */ + for (i = 0; i < NUM_DOMAIN_OFFSETS; ++i) { + if (outpkt->domain_offsets[i] == 0) { + outpkt->domain_offsets[i] = outpkt->write_offset; + break; + } + } + + outpkt->write_offset += writelen; + } + if (jump_offset) { + /* Write jump */ + jump = htons(DOMAIN_JUMP | jump_offset); + res = pbuf_take_at(outpkt->pbuf, &jump, DOMAIN_JUMP_SIZE, outpkt->write_offset); + if (res != ERR_OK) { + return res; + } + outpkt->write_offset += DOMAIN_JUMP_SIZE; + } + return ERR_OK; +} + +/** + * Write a question to an outpacket + * A question contains domain, type and class. Since an answer also starts with these fields this function is also + * called from mdns_add_answer(). + * @param outpkt The outpacket to write to + * @param domain The domain name the answer is for + * @param type The DNS type of the answer (like 'AAAA', 'SRV') + * @param klass The DNS type of the answer (like 'IN') + * @param unicast If highest bit in class should be set, to instruct the responder to + * reply with a unicast packet + * @return ERR_OK on success, an err_t otherwise + */ +static err_t +mdns_add_question(struct mdns_outpacket *outpkt, struct mdns_domain *domain, u16_t type, u16_t klass, u16_t unicast) +{ + u16_t question_len; + u16_t field16; + err_t res; + + if (!outpkt->pbuf) { + /* If no pbuf is active, allocate one */ + outpkt->pbuf = pbuf_alloc(PBUF_TRANSPORT, OUTPACKET_SIZE, PBUF_POOL); + if (!outpkt->pbuf) { + return ERR_MEM; + } + outpkt->write_offset = SIZEOF_DNS_HDR; + } + + /* Worst case calculation. Domain string might be compressed */ + question_len = domain->length + sizeof(type) + sizeof(klass); + if (outpkt->write_offset + question_len > outpkt->pbuf->tot_len) { + /* No space */ + return ERR_MEM; + } + + /* Write name */ + res = mdns_write_domain(outpkt, domain); + if (res != ERR_OK) { + return res; + } + + /* Write type */ + field16 = htons(type); + res = pbuf_take_at(outpkt->pbuf, &field16, sizeof(field16), outpkt->write_offset); + if (res != ERR_OK) { + return res; + } + outpkt->write_offset += sizeof(field16); + + /* Write class */ + if (unicast) { + klass |= 0x8000; + } + field16 = htons(klass); + res = pbuf_take_at(outpkt->pbuf, &field16, sizeof(field16), outpkt->write_offset); + if (res != ERR_OK) { + return res; + } + outpkt->write_offset += sizeof(field16); + + return ERR_OK; +} + +/** + * Write answer to reply packet. + * buf or answer_domain can be null. The rd_length written will be buf_length + + * size of (compressed) domain. Most uses will need either buf or answer_domain, + * special case is SRV that starts with 3 u16 and then a domain name. + * @param reply The outpacket to write to + * @param domain The domain name the answer is for + * @param type The DNS type of the answer (like 'AAAA', 'SRV') + * @param klass The DNS type of the answer (like 'IN') + * @param cache_flush If highest bit in class should be set, to instruct receiver that + * this reply replaces any earlier answer for this domain/type/class + * @param ttl Validity time in seconds to send out for IP address data in DNS replies + * @param buf Pointer to buffer of answer data + * @param buf_length Length of variable data + * @param answer_domain A domain to write after any buffer data as answer + * @return ERR_OK on success, an err_t otherwise + */ +static err_t +mdns_add_answer(struct mdns_outpacket *reply, struct mdns_domain *domain, u16_t type, u16_t klass, u16_t cache_flush, + u32_t ttl, const u8_t *buf, size_t buf_length, struct mdns_domain *answer_domain) +{ + u16_t answer_len; + u16_t field16; + u16_t rdlen_offset; + u16_t answer_offset; + u32_t field32; + err_t res; + + if (!reply->pbuf) { + /* If no pbuf is active, allocate one */ + reply->pbuf = pbuf_alloc(PBUF_TRANSPORT, OUTPACKET_SIZE, PBUF_POOL); + if (!reply->pbuf) { + return ERR_MEM; + } + reply->write_offset = SIZEOF_DNS_HDR; + } + + /* Worst case calculation. Domain strings might be compressed */ + answer_len = domain->length + sizeof(type) + sizeof(klass) + sizeof(ttl) + sizeof(field16)/*rd_length*/; + if (buf) { + answer_len += buf_length; + } + if (answer_domain) { + answer_len += answer_domain->length; + } + if (reply->write_offset + answer_len > reply->pbuf->tot_len) { + /* No space */ + return ERR_MEM; + } + + /* Answer starts with same data as question, then more fields */ + mdns_add_question(reply, domain, type, klass, cache_flush); + + /* Write TTL */ + field32 = htonl(ttl); + res = pbuf_take_at(reply->pbuf, &field32, sizeof(field32), reply->write_offset); + if (res != ERR_OK) { + return res; + } + reply->write_offset += sizeof(field32); + + /* Store offsets and skip forward to the data */ + rdlen_offset = reply->write_offset; + reply->write_offset += sizeof(field16); + answer_offset = reply->write_offset; + + if (buf) { + /* Write static data */ + res = pbuf_take_at(reply->pbuf, buf, buf_length, reply->write_offset); + if (res != ERR_OK) { + return res; + } + reply->write_offset += buf_length; + } + + if (answer_domain) { + /* Write name answer (compressed if possible) */ + res = mdns_write_domain(reply, answer_domain); + if (res != ERR_OK) { + return res; + } + } + + /* Write rd_length after when we know the answer size */ + field16 = htons(reply->write_offset - answer_offset); + res = pbuf_take_at(reply->pbuf, &field16, sizeof(field16), rdlen_offset); + + return res; +} + +/** + * Helper function for mdns_read_question/mdns_read_answer + * Reads a domain, type and class from the packet + * @param pkt The MDNS packet to read from. The parse_offset field will be + * incremented to point to the next unparsed byte. + * @param info The struct to fill with domain, type and class + * @return ERR_OK on success, an err_t otherwise + */ +static err_t +mdns_read_rr_info(struct mdns_packet *pkt, struct mdns_rr_info *info) +{ + u16_t field16, copied; + pkt->parse_offset = mdns_readname(pkt->pbuf, pkt->parse_offset, &info->domain); + if (pkt->parse_offset == MDNS_READNAME_ERROR) { + return ERR_VAL; + } + + copied = pbuf_copy_partial(pkt->pbuf, &field16, sizeof(field16), pkt->parse_offset); + if (copied != sizeof(field16)) { + return ERR_VAL; + } + pkt->parse_offset += copied; + info->type = ntohs(field16); + + copied = pbuf_copy_partial(pkt->pbuf, &field16, sizeof(field16), pkt->parse_offset); + if (copied != sizeof(field16)) { + return ERR_VAL; + } + pkt->parse_offset += copied; + info->klass = ntohs(field16); + + return ERR_OK; +} + +/** + * Read a question from the packet. + * All questions have to be read before the answers. + * @param pkt The MDNS packet to read from. The questions_left field will be decremented + * and the parse_offset will be updated. + * @param question The struct to fill with question data + * @return ERR_OK on success, an err_t otherwise + */ +static err_t +mdns_read_question(struct mdns_packet *pkt, struct mdns_question *question) +{ + /* Safety check */ + if (pkt->pbuf->tot_len < pkt->parse_offset) { + return ERR_VAL; + } + + if (pkt->questions_left) { + err_t res; + pkt->questions_left--; + + memset(question, 0, sizeof(struct mdns_question)); + res = mdns_read_rr_info(pkt, &question->info); + if (res != ERR_OK) { + return res; + } + + /* Extract unicast flag from class field */ + question->unicast = question->info.klass & 0x8000; + question->info.klass &= 0x7FFF; + + return ERR_OK; + } + return ERR_VAL; +} + +/** + * Read an answer from the packet + * The variable length reply is not copied, its pbuf offset and length is stored instead. + * @param pkt The MDNS packet to read. The answers_left field will be decremented and + * the parse_offset will be updated. + * @param answer The struct to fill with answer data + * @return ERR_OK on success, an err_t otherwise + */ +static err_t +mdns_read_answer(struct mdns_packet *pkt, struct mdns_answer *answer) +{ + /* Read questions first */ + if (pkt->questions_left) { + return ERR_VAL; + } + + /* Safety check */ + if (pkt->pbuf->tot_len < pkt->parse_offset) { + return ERR_VAL; + } + + if (pkt->answers_left) { + u16_t copied, field16; + u32_t ttl; + err_t res; + pkt->answers_left--; + + memset(answer, 0, sizeof(struct mdns_answer)); + res = mdns_read_rr_info(pkt, &answer->info); + if (res != ERR_OK) { + return res; + } + + /* Extract cache_flush flag from class field */ + answer->cache_flush = answer->info.klass & 0x8000; + answer->info.klass &= 0x7FFF; + + copied = pbuf_copy_partial(pkt->pbuf, &ttl, sizeof(ttl), pkt->parse_offset); + if (copied != sizeof(ttl)) { + return ERR_VAL; + } + pkt->parse_offset += copied; + answer->ttl = ntohl(ttl); + + copied = pbuf_copy_partial(pkt->pbuf, &field16, sizeof(field16), pkt->parse_offset); + if (copied != sizeof(field16)) { + return ERR_VAL; + } + pkt->parse_offset += copied; + answer->rd_length = ntohs(field16); + + answer->rd_offset = pkt->parse_offset; + pkt->parse_offset += answer->rd_length; + + return ERR_OK; + } + return ERR_VAL; +} + +#if LWIP_IPV4 +/** Write an IPv4 address (A) RR to outpacket */ +static err_t +mdns_add_a_answer(struct mdns_outpacket *reply, u16_t cache_flush, struct netif *netif) +{ + struct mdns_domain host; + mdns_build_host_domain(&host, netif); + LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: Responding with A record\n")); + return mdns_add_answer(reply, &host, DNS_RRTYPE_A, DNS_RRCLASS_IN, cache_flush, netif->mdns->dns_ttl, (const u8_t *) netif_ip4_addr(netif), sizeof(ip4_addr_t), NULL); +} + +/** Write a 4.3.2.1.in-addr.arpa -> hostname.local PTR RR to outpacket */ +static err_t +mdns_add_hostv4_ptr_answer(struct mdns_outpacket *reply, u16_t cache_flush, struct netif *netif) +{ + struct mdns_domain host, revhost; + mdns_build_host_domain(&host, netif); + mdns_build_reverse_v4_domain(&revhost, netif_ip4_addr(netif)); + LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: Responding with v4 PTR record\n")); + return mdns_add_answer(reply, &revhost, DNS_RRTYPE_PTR, DNS_RRCLASS_IN, cache_flush, netif->mdns->dns_ttl, NULL, 0, &host); +} +#endif + +#if LWIP_IPV6 +/** Write an IPv6 address (AAAA) RR to outpacket */ +static err_t +mdns_add_aaaa_answer(struct mdns_outpacket *reply, u16_t cache_flush, struct netif *netif, int addrindex) +{ + struct mdns_domain host; + mdns_build_host_domain(&host, netif); + LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: Responding with AAAA record\n")); + return mdns_add_answer(reply, &host, DNS_RRTYPE_AAAA, DNS_RRCLASS_IN, cache_flush, netif->mdns->dns_ttl, (const u8_t *) netif_ip6_addr(netif, addrindex), sizeof(ip6_addr_t), NULL); +} + +/** Write a x.y.z.ip6.arpa -> hostname.local PTR RR to outpacket */ +static err_t +mdns_add_hostv6_ptr_answer(struct mdns_outpacket *reply, u16_t cache_flush, struct netif *netif, int addrindex) +{ + struct mdns_domain host, revhost; + mdns_build_host_domain(&host, netif); + mdns_build_reverse_v6_domain(&revhost, netif_ip6_addr(netif, addrindex)); + LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: Responding with v6 PTR record\n")); + return mdns_add_answer(reply, &revhost, DNS_RRTYPE_PTR, DNS_RRCLASS_IN, cache_flush, netif->mdns->dns_ttl, NULL, 0, &host); +} +#endif + +/** Write an all-services -> servicetype PTR RR to outpacket */ +static err_t +mdns_add_servicetype_ptr_answer(struct mdns_outpacket *reply, struct mdns_service *service) +{ + struct mdns_domain service_type, service_dnssd; + mdns_build_service_domain(&service_type, service, 0); + mdns_build_dnssd_domain(&service_dnssd); + LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: Responding with service type PTR record\n")); + return mdns_add_answer(reply, &service_dnssd, DNS_RRTYPE_PTR, DNS_RRCLASS_IN, 0, service->dns_ttl, NULL, 0, &service_type); +} + +/** Write a servicetype -> servicename PTR RR to outpacket */ +static err_t +mdns_add_servicename_ptr_answer(struct mdns_outpacket *reply, struct mdns_service *service) +{ + struct mdns_domain service_type, service_instance; + mdns_build_service_domain(&service_type, service, 0); + mdns_build_service_domain(&service_instance, service, 1); + LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: Responding with service name PTR record\n")); + return mdns_add_answer(reply, &service_type, DNS_RRTYPE_PTR, DNS_RRCLASS_IN, 0, service->dns_ttl, NULL, 0, &service_instance); +} + +/** Write a SRV RR to outpacket */ +static err_t +mdns_add_srv_answer(struct mdns_outpacket *reply, u16_t cache_flush, struct netif *netif, struct mdns_service *service) +{ + struct mdns_domain service_instance, srvhost; + u16_t srvdata[3]; + mdns_build_service_domain(&service_instance, service, 1); + mdns_build_host_domain(&srvhost, netif); + if (reply->legacy_query) { + /* RFC 6762 section 18.14: + * In legacy unicast responses generated to answer legacy queries, + * name compression MUST NOT be performed on SRV records. + */ + srvhost.skip_compression = 1; + } + srvdata[0] = htons(SRV_PRIORITY); + srvdata[1] = htons(SRV_WEIGHT); + srvdata[2] = htons(service->port); + LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: Responding with SRV record\n")); + return mdns_add_answer(reply, &service_instance, DNS_RRTYPE_SRV, DNS_RRCLASS_IN, cache_flush, service->dns_ttl, + (const u8_t *) &srvdata, sizeof(srvdata), &srvhost); +} + +/** Write a TXT RR to outpacket */ +static err_t +mdns_add_txt_answer(struct mdns_outpacket *reply, u16_t cache_flush, struct mdns_service *service) +{ + struct mdns_domain service_instance; + mdns_build_service_domain(&service_instance, service, 1); + mdns_prepare_txtdata(service); + LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: Responding with TXT record\n")); + return mdns_add_answer(reply, &service_instance, DNS_RRTYPE_TXT, DNS_RRCLASS_IN, cache_flush, service->dns_ttl, + (u8_t *) &service->txtdata.name, service->txtdata.length, NULL); +} + +/** + * Setup outpacket as a reply to the incoming packet + */ +static void +mdns_init_outpacket(struct mdns_outpacket *out, struct mdns_packet *in) +{ + memset(out, 0, sizeof(struct mdns_outpacket)); + out->cache_flush = 1; + out->netif = in->netif; + + /* Copy source IP/port to use when responding unicast, or to choose + * which pcb to use for multicast (IPv4/IPv6) + */ + memcpy(&out->dest_addr, &in->source_addr, sizeof(ip_addr_t)); + out->dest_port = in->source_port; + + if (in->source_port != MDNS_PORT) { + out->unicast_reply = 1; + out->cache_flush = 0; + if (in->questions == 1) { + out->legacy_query = 1; + out->tx_id = in->tx_id; + } + } + + if (in->recv_unicast) { + out->unicast_reply = 1; + } +} + +/** + * Send chosen answers as a reply + * + * Add all selected answers (first write will allocate pbuf) + * Add additional answers based on the selected answers + * Send the packet + */ +static void +mdns_send_outpacket(struct mdns_outpacket *outpkt) +{ + struct mdns_service *service; + err_t res; + int i; + + /* Write answers to host questions */ +#if LWIP_IPV4 + if (outpkt->host_replies & REPLY_HOST_A) { + res = mdns_add_a_answer(outpkt, outpkt->cache_flush, outpkt->netif); + if (res != ERR_OK) { + goto cleanup; + } + outpkt->answers++; + } + if (outpkt->host_replies & REPLY_HOST_PTR_V4) { + res = mdns_add_hostv4_ptr_answer(outpkt, outpkt->cache_flush, outpkt->netif); + if (res != ERR_OK) { + goto cleanup; + } + outpkt->answers++; + } +#endif +#if LWIP_IPV6 + if (outpkt->host_replies & REPLY_HOST_AAAA) { + int addrindex; + for (addrindex = 0; addrindex < LWIP_IPV6_NUM_ADDRESSES; ++addrindex) { + if (ip6_addr_isvalid(netif_ip6_addr_state(outpkt->netif, addrindex))) { + res = mdns_add_aaaa_answer(outpkt, outpkt->cache_flush, outpkt->netif, addrindex); + if (res != ERR_OK) { + goto cleanup; + } + outpkt->answers++; + } + } + } + if (outpkt->host_replies & REPLY_HOST_PTR_V6) { + u8_t rev_addrs = outpkt->host_reverse_v6_replies; + int addrindex = 0; + while (rev_addrs) { + if (rev_addrs & 1) { + res = mdns_add_hostv6_ptr_answer(outpkt, outpkt->cache_flush, outpkt->netif, addrindex); + if (res != ERR_OK) { + goto cleanup; + } + outpkt->answers++; + } + addrindex++; + rev_addrs >>= 1; + } + } +#endif + + /* Write answers to service questions */ + for (i = 0; i < MDNS_MAX_SERVICES; ++i) { + service = outpkt->netif->mdns->services[i]; + if (!service) { + continue; + } + + if (outpkt->serv_replies[i] & REPLY_SERVICE_TYPE_PTR) { + res = mdns_add_servicetype_ptr_answer(outpkt, service); + if (res != ERR_OK) { + goto cleanup; + } + outpkt->answers++; + } + + if (outpkt->serv_replies[i] & REPLY_SERVICE_NAME_PTR) { + res = mdns_add_servicename_ptr_answer(outpkt, service); + if (res != ERR_OK) { + goto cleanup; + } + outpkt->answers++; + } + + if (outpkt->serv_replies[i] & REPLY_SERVICE_SRV) { + res = mdns_add_srv_answer(outpkt, outpkt->cache_flush, outpkt->netif, service); + if (res != ERR_OK) { + goto cleanup; + } + outpkt->answers++; + } + + if (outpkt->serv_replies[i] & REPLY_SERVICE_TXT) { + res = mdns_add_txt_answer(outpkt, outpkt->cache_flush, service); + if (res != ERR_OK) { + goto cleanup; + } + outpkt->answers++; + } + } + + /* All answers written, add additional RRs */ + for (i = 0; i < MDNS_MAX_SERVICES; ++i) { + service = outpkt->netif->mdns->services[i]; + if (!service) { + continue; + } + + if (outpkt->serv_replies[i] & REPLY_SERVICE_NAME_PTR) { + /* Our service instance requested, include SRV & TXT + * if they are already not requested. */ + if (!(outpkt->serv_replies[i] & REPLY_SERVICE_SRV)) { + res = mdns_add_srv_answer(outpkt, outpkt->cache_flush, outpkt->netif, service); + if (res != ERR_OK) { + goto cleanup; + } + outpkt->additional++; + } + + if (!(outpkt->serv_replies[i] & REPLY_SERVICE_TXT)) { + res = mdns_add_txt_answer(outpkt, outpkt->cache_flush, service); + if (res != ERR_OK) { + goto cleanup; + } + outpkt->additional++; + } + } + + /* If service instance, SRV, record or an IP address is requested, + * supply all addresses for the host + */ + if ((outpkt->serv_replies[i] & (REPLY_SERVICE_NAME_PTR | REPLY_SERVICE_SRV)) || + (outpkt->host_replies & (REPLY_HOST_A | REPLY_HOST_AAAA))) { +#if LWIP_IPV6 + if (!(outpkt->host_replies & REPLY_HOST_AAAA)) { + int addrindex; + for (addrindex = 0; addrindex < LWIP_IPV6_NUM_ADDRESSES; ++addrindex) { + if (ip6_addr_isvalid(netif_ip6_addr_state(outpkt->netif, addrindex))) { + res = mdns_add_aaaa_answer(outpkt, outpkt->cache_flush, outpkt->netif, addrindex); + if (res != ERR_OK) { + goto cleanup; + } + outpkt->additional++; + } + } + } +#endif +#if LWIP_IPV4 + if (!(outpkt->host_replies & REPLY_HOST_A)) { + res = mdns_add_a_answer(outpkt, outpkt->cache_flush, outpkt->netif); + if (res != ERR_OK) { + goto cleanup; + } + outpkt->additional++; + } +#endif + } + } + + if (outpkt->pbuf) { + const ip_addr_t *mcast_destaddr; + struct udp_pcb *pcb = NULL; + struct dns_hdr hdr; + + /* Write header */ + memset(&hdr, 0, sizeof(hdr)); + hdr.flags1 = DNS_FLAG1_RESPONSE | DNS_FLAG1_AUTHORATIVE; + hdr.numanswers = htons(outpkt->answers); + hdr.numextrarr = htons(outpkt->additional); + if (outpkt->legacy_query) { + hdr.numquestions = htons(1); + hdr.id = htons(outpkt->tx_id); + } + pbuf_take(outpkt->pbuf, &hdr, sizeof(hdr)); + + /* Shrink packet */ + pbuf_realloc(outpkt->pbuf, outpkt->write_offset); + + if (IP_IS_V6_VAL(outpkt->dest_addr)) { +#if LWIP_IPV6 + mcast_destaddr = &v6group; + pcb = mdns_data.v6pcb; +#endif + } else { +#if LWIP_IPV4 + mcast_destaddr = &v4group; + pcb = mdns_data.v4pcb; +#endif + } + /* Send created packet */ + LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: Sending packet, len=%d, unicast=%d\n", outpkt->write_offset, outpkt->unicast_reply)); + if (outpkt->unicast_reply) { + udp_sendto_if(pcb, outpkt->pbuf, &outpkt->dest_addr, outpkt->dest_port, outpkt->netif); + } else { + udp_sendto_if(pcb, outpkt->pbuf, mcast_destaddr, MDNS_PORT, outpkt->netif); + } + } + +cleanup: + if (outpkt->pbuf) { + pbuf_free(outpkt->pbuf); + outpkt->pbuf = NULL; + } +} + +/** + * Send unsolicited answer containing all our known data + * @param netif The network interface to send on + * @param destination The target address to send to (usually multicast address) + */ +static void +mdns_announce(struct netif *netif, const ip_addr_t *destination) +{ + struct mdns_outpacket announce; + int i; + + memset(&announce, 0, sizeof(announce)); + announce.netif = netif; + announce.cache_flush = 1; + announce.host_replies = REPLY_HOST_A | REPLY_HOST_AAAA | REPLY_HOST_PTR_V4 | REPLY_HOST_PTR_V6; +#if LWIP_IPV6 + for (i = 0; i < LWIP_IPV6_NUM_ADDRESSES; ++i) { + if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i))) { + announce.host_reverse_v6_replies |= (1 << i); + } + } +#endif + + for (i = 0; i < MDNS_MAX_SERVICES; i++) { + struct mdns_service *serv = netif->mdns->services[i]; + if (serv) { + announce.serv_replies[i] = REPLY_SERVICE_TYPE_PTR | REPLY_SERVICE_NAME_PTR | + REPLY_SERVICE_SRV | REPLY_SERVICE_TXT; + } + } + + announce.dest_port = MDNS_PORT; + memcpy(&announce.dest_addr, destination, sizeof(ip_addr_t)); + mdns_send_outpacket(&announce); +} + +/** + * Handle question MDNS packet + * 1. Parse all questions and set bits what answers to send + * 2. Clear pending answers if known answers are supplied + * 3. Put chosen answers in new packet and send as reply + */ +static void +mdns_handle_question(struct mdns_packet *pkt) +{ + struct mdns_service *service; + struct mdns_outpacket reply; + int replies = 0; + int i; + err_t res; + + mdns_init_outpacket(&reply, pkt); + + while (pkt->questions_left) { + struct mdns_question q; + + res = mdns_read_question(pkt, &q); + if (res != ERR_OK) { + LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: Failed to parse question, skipping query packet\n")); + return; + } + + LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: Query for domain ")); + mdns_domain_debug_print(MDNS_DEBUG, &q.info.domain); + LWIP_DEBUGF(MDNS_DEBUG, (" type %d class %d\n", q.info.type, q.info.klass)); + + if (q.unicast) { + /* Reply unicast if any question is unicast */ + reply.unicast_reply = 1; + } + + reply.host_replies |= check_host(pkt->netif, &q.info, &reply.host_reverse_v6_replies); + replies |= reply.host_replies; + + for (i = 0; i < MDNS_MAX_SERVICES; ++i) { + service = pkt->netif->mdns->services[i]; + if (!service) { + continue; + } + reply.serv_replies[i] |= check_service(service, &q.info); + replies |= reply.serv_replies[i]; + } + + if (replies && reply.legacy_query) { + /* Add question to reply packet (legacy packet only has 1 question) */ + res = mdns_add_question(&reply, &q.info.domain, q.info.type, q.info.klass, 0); + if (res != ERR_OK) { + goto cleanup; + } + } + } + + /* Handle known answers */ + while (pkt->answers_left) { + struct mdns_answer ans; + u8_t rev_v6; + int match; + + res = mdns_read_answer(pkt, &ans); + if (res != ERR_OK) { + LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: Failed to parse answer, skipping query packet\n")); + goto cleanup; + } + + LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: Known answer for domain ")); + mdns_domain_debug_print(MDNS_DEBUG, &ans.info.domain); + LWIP_DEBUGF(MDNS_DEBUG, (" type %d class %d\n", ans.info.type, ans.info.klass)); + + + if (ans.info.type == DNS_RRTYPE_ANY || ans.info.klass == DNS_RRCLASS_ANY) { + /* Skip known answers for ANY type & class */ + continue; + } + + rev_v6 = 0; + match = reply.host_replies & check_host(pkt->netif, &ans.info, &rev_v6); + if (match && (ans.ttl > (pkt->netif->mdns->dns_ttl / 2))) { + /* The RR in the known answer matches an RR we are planning to send, + * and the TTL is less than half gone. + * If the payload matches we should not send that answer. + */ + if (ans.info.type == DNS_RRTYPE_PTR) { + /* Read domain and compare */ + struct mdns_domain known_ans, my_ans; + u16_t len; + len = mdns_readname(pkt->pbuf, ans.rd_offset, &known_ans); + res = mdns_build_host_domain(&my_ans, pkt->netif); + if (len != MDNS_READNAME_ERROR && res == ERR_OK && mdns_domain_eq(&known_ans, &my_ans)) { +#if LWIP_IPV4 + if (match & REPLY_HOST_PTR_V4) { + LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: Skipping known answer: v4 PTR\n")); + reply.host_replies &= ~REPLY_HOST_PTR_V4; + } +#endif +#if LWIP_IPV6 + if (match & REPLY_HOST_PTR_V6) { + LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: Skipping known answer: v6 PTR\n")); + reply.host_reverse_v6_replies &= ~rev_v6; + if (reply.host_reverse_v6_replies == 0) { + reply.host_replies &= ~REPLY_HOST_PTR_V6; + } + } +#endif + } + } else if (match & REPLY_HOST_A) { +#if LWIP_IPV4 + if (ans.rd_length == sizeof(ip4_addr_t) && + pbuf_memcmp(pkt->pbuf, ans.rd_offset, netif_ip4_addr(pkt->netif), ans.rd_length) == 0) { + LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: Skipping known answer: A\n")); + reply.host_replies &= ~REPLY_HOST_A; + } +#endif + } else if (match & REPLY_HOST_AAAA) { +#if LWIP_IPV6 + if (ans.rd_length == sizeof(ip6_addr_t) && + /* TODO this clears all AAAA responses if first addr is set as known */ + pbuf_memcmp(pkt->pbuf, ans.rd_offset, netif_ip6_addr(pkt->netif, 0), ans.rd_length) == 0) { + LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: Skipping known answer: AAAA\n")); + reply.host_replies &= ~REPLY_HOST_AAAA; + } +#endif + } + } + + for (i = 0; i < MDNS_MAX_SERVICES; ++i) { + service = pkt->netif->mdns->services[i]; + if (!service) { + continue; + } + match = reply.serv_replies[i] & check_service(service, &ans.info); + if (match && (ans.ttl > (service->dns_ttl / 2))) { + /* The RR in the known answer matches an RR we are planning to send, + * and the TTL is less than half gone. + * If the payload matches we should not send that answer. + */ + if (ans.info.type == DNS_RRTYPE_PTR) { + /* Read domain and compare */ + struct mdns_domain known_ans, my_ans; + u16_t len; + len = mdns_readname(pkt->pbuf, ans.rd_offset, &known_ans); + if (len != MDNS_READNAME_ERROR) { + if (match & REPLY_SERVICE_TYPE_PTR) { + res = mdns_build_service_domain(&my_ans, service, 0); + if (res == ERR_OK && mdns_domain_eq(&known_ans, &my_ans)) { + LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: Skipping known answer: service type PTR\n")); + reply.serv_replies[i] &= ~REPLY_SERVICE_TYPE_PTR; + } + } + if (match & REPLY_SERVICE_NAME_PTR) { + res = mdns_build_service_domain(&my_ans, service, 1); + if (res == ERR_OK && mdns_domain_eq(&known_ans, &my_ans)) { + LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: Skipping known answer: service name PTR\n")); + reply.serv_replies[i] &= ~REPLY_SERVICE_NAME_PTR; + } + } + } + } else if (match & REPLY_SERVICE_SRV) { + /* Read and compare to my SRV record */ + u16_t field16, len, read_pos; + struct mdns_domain known_ans, my_ans; + read_pos = ans.rd_offset; + do { + /* Check priority field */ + len = pbuf_copy_partial(pkt->pbuf, &field16, sizeof(field16), read_pos); + if (len != sizeof(field16) || ntohs(field16) != SRV_PRIORITY) { + break; + } + read_pos += len; + /* Check weight field */ + len = pbuf_copy_partial(pkt->pbuf, &field16, sizeof(field16), read_pos); + if (len != sizeof(field16) || ntohs(field16) != SRV_WEIGHT) { + break; + } + read_pos += len; + /* Check port field */ + len = pbuf_copy_partial(pkt->pbuf, &field16, sizeof(field16), read_pos); + if (len != sizeof(field16) || ntohs(field16) != service->port) { + break; + } + read_pos += len; + /* Check host field */ + len = mdns_readname(pkt->pbuf, read_pos, &known_ans); + mdns_build_host_domain(&my_ans, pkt->netif); + if (len == MDNS_READNAME_ERROR || !mdns_domain_eq(&known_ans, &my_ans)) { + break; + } + LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: Skipping known answer: SRV\n")); + reply.serv_replies[i] &= ~REPLY_SERVICE_SRV; + } while (0); + } else if (match & REPLY_SERVICE_TXT) { + mdns_prepare_txtdata(service); + if (service->txtdata.length == ans.rd_length && + pbuf_memcmp(pkt->pbuf, ans.rd_offset, service->txtdata.name, ans.rd_length) == 0) { + LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: Skipping known answer: TXT\n")); + reply.serv_replies[i] &= ~REPLY_SERVICE_TXT; + } + } + } + } + } + + mdns_send_outpacket(&reply); + +cleanup: + if (reply.pbuf) { + /* This should only happen if we fail to alloc/write question for legacy query */ + pbuf_free(reply.pbuf); + reply.pbuf = NULL; + } +} + +/** + * Handle response MDNS packet + * Only prints debug for now. Will need more code to do conflict resolution. + */ +static void +mdns_handle_response(struct mdns_packet *pkt) +{ + /* Ignore all questions */ + while (pkt->questions_left) { + struct mdns_question q; + err_t res; + + res = mdns_read_question(pkt, &q); + if (res != ERR_OK) { + LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: Failed to parse question, skipping response packet\n")); + return; + } + } + + while (pkt->answers_left) { + struct mdns_answer ans; + err_t res; + + res = mdns_read_answer(pkt, &ans); + if (res != ERR_OK) { + LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: Failed to parse answer, skipping response packet\n")); + return; + } + + LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: Answer for domain ")); + mdns_domain_debug_print(MDNS_DEBUG, &ans.info.domain); + LWIP_DEBUGF(MDNS_DEBUG, (" type %d class %d\n", ans.info.type, ans.info.klass)); + } +} + +/** + * Receive input function for MDNS packets. + * Handles both IPv4 and IPv6 UDP pcbs. + * + * @params see udp.h + */ +static void +mdns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, u16_t port) +{ + struct dns_hdr hdr; + struct mdns_packet packet; + struct netif *recv_netif = ip_current_input_netif(); + u16_t offset = 0; + + LWIP_UNUSED_ARG(arg); + LWIP_UNUSED_ARG(pcb); + + LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: Received IPv%d MDNS packet, len %d\n", IP_IS_V6(addr)? 6 : 4, p->tot_len)); + + if (!recv_netif->mdns) { + /* From netif not configured for MDNS */ + goto dealloc; + } + + if (pbuf_copy_partial(p, &hdr, SIZEOF_DNS_HDR, offset) < SIZEOF_DNS_HDR) { + /* Too small */ + goto dealloc; + } + offset += SIZEOF_DNS_HDR; + + if (DNS_HDR_GET_OPCODE(&hdr)) { + /* Ignore non-standard queries in multicast packets (RFC 6762, section 18.3) */ + goto dealloc; + } + + memset(&packet, 0, sizeof(packet)); + memcpy(&packet.source_addr, addr, sizeof(packet.source_addr)); + packet.source_port = port; + packet.netif = recv_netif; + packet.pbuf = p; + packet.parse_offset = offset; + packet.tx_id = ntohs(hdr.id); + packet.questions = packet.questions_left = ntohs(hdr.numquestions); + packet.answers = packet.answers_left = ntohs(hdr.numanswers) + ntohs(hdr.numauthrr) + ntohs(hdr.numextrarr); + +#if LWIP_IPV6 + if (IP_IS_V6(ip_current_dest_addr())) { + if (!ip_addr_cmp(ip_current_dest_addr(), &v6group)) { + packet.recv_unicast = 1; + } + } +#endif +#if LWIP_IPV4 + if (!IP_IS_V6(ip_current_dest_addr())) { + if (!ip_addr_cmp(ip_current_dest_addr(), &v4group)) { + packet.recv_unicast = 1; + } + } +#endif + + if (hdr.flags1 & DNS_FLAG1_RESPONSE) { + mdns_handle_response(&packet); + } else { + mdns_handle_question(&packet); + } + +dealloc: + pbuf_free(p); +} + +/** + * Initiate MDNS responder. Will open UDP sockets on port 5353 + */ +void +mdns_resp_init(void) +{ + err_t res; + memset(&mdns_data, 0, sizeof(mdns_data)); + +#if LWIP_IPV4 + mdns_data.v4pcb = udp_new(); + LWIP_ASSERT("Failed to allocate pcb", mdns_data.v4pcb != NULL); + udp_set_multicast_ttl(mdns_data.v4pcb, MDNS_TTL); + res = udp_bind(mdns_data.v4pcb, IP_ADDR_ANY, MDNS_PORT); + LWIP_ASSERT("Failed to bind pcb", res == ERR_OK); + udp_recv(mdns_data.v4pcb, mdns_recv, &mdns_data); +#endif + +#if LWIP_IPV6 + mdns_data.v6pcb = udp_new_ip6(); + LWIP_ASSERT("Failed to allocate pcb", mdns_data.v6pcb != NULL); + udp_set_multicast_ttl(mdns_data.v6pcb, MDNS_TTL); + res = udp_bind(mdns_data.v6pcb, IP6_ADDR_ANY, MDNS_PORT); + LWIP_ASSERT("Failed to bind pcb", res == ERR_OK); + udp_recv(mdns_data.v6pcb, mdns_recv, &mdns_data); +#endif +} + +/** + * Activate MDNS responder for a network interface and send announce packets. + * @param netif The network interface to activate. + * @param hostname Name to use. Queries for .local will be answered + * with the IP addresses of the netif. The hostname will be copied, the + * given pointer can be on the stack. + * @param dns_ttl Validity time in seconds to send out for IP address data in DNS replies + * @return ERR_OK if netif was added, an err_t otherwise + */ +err_t +mdns_resp_add_netif(struct netif *netif, char *hostname, u32_t dns_ttl) +{ + err_t res; + + LWIP_ERROR("mdns_resp_add_netif: netif != NULL", (netif != NULL), return ERR_VAL); + LWIP_ERROR("mdns_resp_add_netif: Hostname too long", (strlen(hostname) <= MDNS_LABEL_MAXLEN), return ERR_VAL); + + LWIP_ASSERT("mdns_resp_add_netif: Double add", netif->mdns == NULL); + netif->mdns = (struct mdns_host *) mem_malloc(sizeof(struct mdns_host)); + LWIP_ERROR("mdns_resp_add_netif: Alloc failed", (netif->mdns != NULL), return ERR_MEM); + + memset(netif->mdns, 0, sizeof(struct mdns_host)); + memcpy(&netif->mdns->name, hostname, LWIP_MIN(MDNS_LABEL_MAXLEN, strlen(hostname))); + netif->mdns->dns_ttl = dns_ttl; + + /* Join multicast groups */ +#if LWIP_IPV4 + res = igmp_joingroup_netif(netif, ip_2_ip4(&v4group)); + if (res != ERR_OK) { + goto cleanup; + } +#endif +#if LWIP_IPV6 + res = mld6_joingroup_netif(netif, ip_2_ip6(&v6group)); + if (res != ERR_OK) { + goto cleanup; + } +#endif + + /* Announce on IPv6 and IPv4 */ +#if LWIP_IPV6 + mdns_announce(netif, IP6_ADDR_ANY); +#endif +#if LWIP_IPV4 + mdns_announce(netif, IP_ADDR_ANY); +#endif + + return ERR_OK; + +cleanup: + mem_free(netif->mdns); + netif->mdns = NULL; + return res; +} + +/** + * Stop responding to MDNS queries on this interface, leave multicast groups, + * and free the helper structure and any of its services. + * @param netif The network interface to remove. + * @return ERR_OK if netif was removed, an err_t otherwise + */ +err_t +mdns_resp_remove_netif(struct netif *netif) +{ + int i; + LWIP_ASSERT("mdns_resp_remove_netif: Null pointer", netif); + LWIP_ERROR("mdns_resp_remove_netif: Not an active netif", (netif->mdns != NULL), return ERR_VAL); + + for (i = 0; i < MDNS_MAX_SERVICES; i++) { + struct mdns_service *service = netif->mdns->services[i]; + if (service) { + mem_free(service); + } + } + + /* Leave multicast groups */ +#if LWIP_IPV4 + igmp_leavegroup_netif(netif, ip_2_ip4(&v4group)); +#endif +#if LWIP_IPV6 + mld6_leavegroup_netif(netif, ip_2_ip6(&v6group)); +#endif + + mem_free(netif->mdns); + netif->mdns = NULL; + return ERR_OK; +} + +/** + * Add a service to the selected network interface. + * @param netif The network interface to publish this service on + * @param name The name of the service + * @param service The service type, like "_http" + * @param proto The service protocol, DNSSD_PROTO_TCP for TCP ("_tcp") and DNSSD_PROTO_UDP + * for others ("_udp") + * @param port The port the service listens to + * @param dns_ttl Validity time in seconds to send out for service data in DNS replies + * @param txt_fn Callback to get TXT data. Will be called each time a TXT reply is created to + * allow dynamic replies. + * @param txt_data Userdata pointer for txt_fn + * @return ERR_OK if the service was added to the netif, an err_t otherwise + */ +err_t +mdns_resp_add_service(struct netif *netif, char *name, char *service, u16_t proto, u16_t port, u32_t dns_ttl, service_get_txt_fn_t txt_fn, void *txt_data) +{ + int i; + int slot = -1; + struct mdns_service *srv; + + LWIP_ASSERT("mdns_resp_add_service: netif != NULL", netif); + LWIP_ERROR("mdns_resp_add_service: Not an mdns netif", (netif->mdns != NULL), return ERR_VAL); + + LWIP_ERROR("mdns_resp_add_service: Name too long", (strlen(name) <= MDNS_LABEL_MAXLEN), return ERR_VAL); + LWIP_ERROR("mdns_resp_add_service: Service too long", (strlen(service) <= MDNS_LABEL_MAXLEN), return ERR_VAL); + LWIP_ERROR("mdns_resp_add_service: Bad proto (need TCP or UDP)", (proto == DNSSD_PROTO_TCP || proto == DNSSD_PROTO_UDP), return ERR_VAL); + + for (i = 0; i < MDNS_MAX_SERVICES; i++) { + if (netif->mdns->services[i] == NULL) { + slot = i; + break; + } + } + LWIP_ERROR("mdns_resp_add_service: Service list full (increase MDNS_MAX_SERVICES)", (slot >= 0), return ERR_MEM); + + srv = (struct mdns_service*)mem_malloc(sizeof(struct mdns_service)); + LWIP_ERROR("mdns_resp_add_service: Alloc failed", (srv != NULL), return ERR_MEM); + + memset(srv, 0, sizeof(struct mdns_service)); + + memcpy(&srv->name, name, LWIP_MIN(MDNS_LABEL_MAXLEN, strlen(name))); + memcpy(&srv->service, service, LWIP_MIN(MDNS_LABEL_MAXLEN, strlen(service))); + srv->txt_fn = txt_fn; + srv->txt_userdata = txt_data; + srv->proto = proto; + srv->port = port; + srv->dns_ttl = dns_ttl; + + netif->mdns->services[slot] = srv; + + /* Announce on IPv6 and IPv4 */ +#if LWIP_IPV6 + mdns_announce(netif, IP6_ADDR_ANY); +#endif +#if LWIP_IPV4 + mdns_announce(netif, IP_ADDR_ANY); +#endif + + return ERR_OK; +} + +/** + * Call this function from inside the service_get_txt_fn_t callback to add text data. + * Buffer for TXT data is 256 bytes, and each field is prefixed with a length byte. + * @param service The service provided to the get_txt callback + * @param txt String to add to the TXT field. + * @param txt_len Length of string + * @return ERR_OK if the string was added to the reply, an err_t otherwise + */ +err_t +mdns_resp_add_service_txtitem(struct mdns_service *service, char *txt, int txt_len) +{ + LWIP_ASSERT("mdns_resp_add_service: service != NULL", service); + + /* Use a mdns_domain struct to store txt chunks since it is the same encoding */ + return mdns_domain_add_label(&service->txtdata, txt, txt_len); +} + +#endif /* LWIP_MDNS */ diff --git a/src/core/netif.c b/src/core/netif.c index 10e5a865..2d2abf59 100644 --- a/src/core/netif.c +++ b/src/core/netif.c @@ -247,6 +247,10 @@ netif_add(struct netif *netif, /* netif not under AutoIP control by default */ netif->autoip = NULL; #endif /* LWIP_AUTOIP */ +#if LWIP_MDNS + /* netif not using MDNS by default */ + netif->mdns = NULL; +#endif /* LWIP_MDNS */ #if LWIP_IPV6_AUTOCONFIG /* IPv6 address autoconfiguration not enabled by default */ netif->ip6_autoconfig_enabled = 0; diff --git a/src/include/lwip/apps/mdns.h b/src/include/lwip/apps/mdns.h new file mode 100644 index 00000000..36892192 --- /dev/null +++ b/src/include/lwip/apps/mdns.h @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2015 Verisure Innovation AB + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Erik Ekman + * + */ +#ifndef LWIP_HDR_MDNS_H +#define LWIP_HDR_MDNS_H + +#include "lwip/opt.h" +#include "lwip/netif.h" + +#if LWIP_MDNS + +#define DNSSD_PROTO_UDP 0 +#define DNSSD_PROTO_TCP 1 + +#define MDNS_LABEL_MAXLEN 63 + +struct mdns_host; +struct mdns_service; + +void mdns_resp_init(void); + +err_t mdns_resp_add_netif(struct netif *netif, char *hostname, u32_t dns_ttl); +err_t mdns_resp_remove_netif(struct netif *netif); + +typedef void (*service_get_txt_fn_t)(struct mdns_service *service, void *txt_userdata); +err_t mdns_resp_add_service(struct netif *netif, char *name, char *service, u16_t proto, u16_t port, u32_t dns_ttl, service_get_txt_fn_t txt_fn, void *txt_userdata); +err_t mdns_resp_add_service_txtitem(struct mdns_service *service, char *txt, int txt_len); + + +/* Domain struct and methods - visible for unit tests */ +#define MDNS_DOMAIN_MAXLEN 256 +#define MDNS_READNAME_ERROR 0xFFFF + +struct mdns_domain { + /* Encoded domain name */ + u8_t name[MDNS_DOMAIN_MAXLEN]; + /* Total length of domain name, including zero */ + u16_t length; + /* Set if compression of this domain is not allowed */ + u8_t skip_compression; +}; + +err_t mdns_domain_add_label(struct mdns_domain *domain, const char *label, unsigned len); +u16_t mdns_readname(struct pbuf *p, u16_t offset, struct mdns_domain *domain); +int mdns_domain_eq(struct mdns_domain *a, struct mdns_domain *b); +u8_t mdns_compress_domain(struct pbuf *pbuf, u16_t *offset, struct mdns_domain *domain); + +#endif /* LWIP_MDNS */ + +#endif /* LWIP_HDR_MDNS_H */ diff --git a/src/include/lwip/apps/mdns_opts.h b/src/include/lwip/apps/mdns_opts.h new file mode 100644 index 00000000..4d818f6d --- /dev/null +++ b/src/include/lwip/apps/mdns_opts.h @@ -0,0 +1,41 @@ +/* + * File: mdns_opts.h + * Author: dziegel + * + * Created on 13. August 2016, 09:17 + */ + +#ifndef LWIP_HDR_APPS_MDNS_OPTS_H +#define LWIP_HDR_APPS_MDNS_OPTS_H +/** + * @defgroup mdns_opts Options + * @ingroup mdns + * @{ + */ + +/** + * LWIP_MDNS==1: Turn on multicast DNS module. UDP must be available for MDNS + * transport. IGMP is needed for IPv4 multicast. + */ +#ifndef LWIP_MDNS +#define LWIP_MDNS 0 +#endif /* LWIP_MDNS */ + +/** The maximum number of services per netif */ +#ifndef MDNS_MAX_SERVICES +#define MDNS_MAX_SERVICES 1 +#endif + +/** + * MDNS_DEBUG: Enable debugging for multicast DNS. + */ +#ifndef MDNS_DEBUG +#define MDNS_DEBUG LWIP_DBG_OFF +#endif + +/** + * @} + */ + +#endif /* LWIP_HDR_APPS_MDNS_OPTS_H */ + diff --git a/src/include/lwip/netif.h b/src/include/lwip/netif.h index 1e08b756..156ceafb 100644 --- a/src/include/lwip/netif.h +++ b/src/include/lwip/netif.h @@ -38,6 +38,7 @@ #define LWIP_HDR_NETIF_H #include "lwip/opt.h" +#include "lwip/apps/mdns_opts.h" #define ENABLE_LOOPBACK (LWIP_NETIF_LOOPBACK || LWIP_HAVE_LOOPIF) @@ -58,6 +59,9 @@ struct autoip; #if LWIP_IPV6_DHCP6 struct dhcp6; #endif /* LWIP_IPV6_DHCP6 */ +#if LWIP_MDNS +struct mdns_host; +#endif #ifdef __cplusplus extern "C" { @@ -255,6 +259,10 @@ struct netif { /** the AutoIP client state information for this netif */ struct autoip *autoip; #endif +#if LWIP_MDNS + /** Interface-specific info for multicast DNS */ + struct mdns_host *mdns; +#endif /* LWIP_MDNS */ #if LWIP_IPV6_AUTOCONFIG /** is this netif enabled for IPv6 autoconfiguration */ u8_t ip6_autoconfig_enabled; diff --git a/src/include/lwip/prot/dns.h b/src/include/lwip/prot/dns.h index cfa7dabf..9998fb60 100644 --- a/src/include/lwip/prot/dns.h +++ b/src/include/lwip/prot/dns.h @@ -69,12 +69,15 @@ extern "C" { #define DNS_RRTYPE_MX 15 /* mail exchange */ #define DNS_RRTYPE_TXT 16 /* text strings */ #define DNS_RRTYPE_AAAA 28 /* IPv6 address */ +#define DNS_RRTYPE_SRV 33 /* service location */ +#define DNS_RRTYPE_ANY 255 /* any type */ /* DNS field CLASS used for "Resource Records" */ #define DNS_RRCLASS_IN 1 /* the Internet */ #define DNS_RRCLASS_CS 2 /* the CSNET class (Obsolete - used only for examples in some obsolete RFCs) */ #define DNS_RRCLASS_CH 3 /* the CHAOS class */ #define DNS_RRCLASS_HS 4 /* Hesiod [Dyer 87] */ +#define DNS_RRCLASS_ANY 255 /* any class */ #define DNS_RRCLASS_FLUSH 0x800 /* Flush bit */ /* DNS protocol flags */ @@ -90,6 +93,8 @@ extern "C" { #define DNS_FLAG2_ERR_NONE 0x00 #define DNS_FLAG2_ERR_NAME 0x03 +#define DNS_HDR_GET_OPCODE(hdr) ((((hdr)->flags1) >> 3) & 0xF) + #ifdef PACK_STRUCT_USE_INCLUDES # include "arch/bpstruct.h" #endif @@ -122,5 +127,5 @@ typedef enum { } #endif -#endif /* DNS_H */ +#endif /* LWIP_HDR_PROT_DNS_H */ diff --git a/test/unit/lwip_unittests.c b/test/unit/lwip_unittests.c index b702884a..46fd4308 100644 --- a/test/unit/lwip_unittests.c +++ b/test/unit/lwip_unittests.c @@ -7,6 +7,7 @@ #include "core/test_pbuf.h" #include "etharp/test_etharp.h" #include "dhcp/test_dhcp.h" +#include "mdns/test_mdns.h" #include "lwip/init.h" @@ -42,7 +43,8 @@ int main(void) mem_suite, pbuf_suite, etharp_suite, - dhcp_suite + dhcp_suite, + mdns_suite }; size_t num = sizeof(suites)/sizeof(void*); LWIP_ASSERT("No suites defined", num > 0); diff --git a/test/unit/lwipopts.h b/test/unit/lwipopts.h index 516a8493..5647e3e3 100644 --- a/test/unit/lwipopts.h +++ b/test/unit/lwipopts.h @@ -51,6 +51,10 @@ #define TCP_RCV_SCALE 0 #define PBUF_POOL_SIZE 400 /* pbuf tests need ~200KByte */ +/* Enable IGMP and MDNS for MDNS tests */ +#define LWIP_IGMP 1 +#define LWIP_MDNS 1 + /* Minimal changes to opt.h required for etharp unit tests: */ #define ETHARP_SUPPORT_STATIC_ENTRIES 1 diff --git a/test/unit/mdns/test_mdns.c b/test/unit/mdns/test_mdns.c new file mode 100644 index 00000000..c9a6bc3f --- /dev/null +++ b/test/unit/mdns/test_mdns.c @@ -0,0 +1,887 @@ +/* + * Copyright (c) 2015 Verisure Innovation AB + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Erik Ekman + * + * Please coordinate changes and requests with Erik Ekman + * + * + */ + +#include "test_mdns.h" + +#include "lwip/pbuf.h" +#include "lwip/apps/mdns.h" + +START_TEST(readname_basic) +{ + static const u8_t data[] = { 0x05, 'm', 'u', 'l', 't', 'i', 0x04, 'c', 'a', 's', 't', 0x00 }; + struct pbuf *p; + struct mdns_domain domain; + u16_t offset; + + p = pbuf_alloc(PBUF_RAW, sizeof(data), PBUF_ROM); + p->payload = (void *)(size_t)data; + fail_if(p == NULL); + offset = mdns_readname(p, 0, &domain); + pbuf_free(p); + fail_unless(offset == sizeof(data)); + fail_unless(domain.length == sizeof(data)); + fail_if(memcmp(&domain.name, data, sizeof(data))); +} +END_TEST + +START_TEST(readname_anydata) +{ + static const u8_t data[] = { 0x05, 0x00, 0xFF, 0x08, 0xc0, 0x0f, 0x04, 0x7f, 0x80, 0x82, 0x88, 0x00 }; + struct pbuf *p; + struct mdns_domain domain; + u16_t offset; + + p = pbuf_alloc(PBUF_RAW, sizeof(data), PBUF_ROM); + p->payload = (void *)(size_t)data; + fail_if(p == NULL); + offset = mdns_readname(p, 0, &domain); + pbuf_free(p); + fail_unless(offset == sizeof(data)); + fail_unless(domain.length == sizeof(data)); + fail_if(memcmp(&domain.name, data, sizeof(data))); +} +END_TEST + +START_TEST(readname_short_buf) +{ + static const u8_t data[] = { 0x05, 'm', 'u', 'l', 't', 'i', 0x04, 'c', 'a' }; + struct pbuf *p; + struct mdns_domain domain; + u16_t offset; + + p = pbuf_alloc(PBUF_RAW, sizeof(data), PBUF_ROM); + p->payload = (void *)(size_t)data; + fail_if(p == NULL); + offset = mdns_readname(p, 0, &domain); + pbuf_free(p); + fail_unless(offset == MDNS_READNAME_ERROR); +} +END_TEST + +START_TEST(readname_long_label) +{ static const u8_t data[] = { + 0x05, 'm', 'u', 'l', 't', 'i', + 0x52, 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', + 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', + 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', + 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', + 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', + 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 0x00, + }; + struct pbuf *p; + struct mdns_domain domain; + u16_t offset; + + p = pbuf_alloc(PBUF_RAW, sizeof(data), PBUF_ROM); + p->payload = (void *)(size_t)data; + fail_if(p == NULL); + offset = mdns_readname(p, 0, &domain); + pbuf_free(p); + fail_unless(offset == MDNS_READNAME_ERROR); +} +END_TEST + +START_TEST(readname_overflow) +{ + static const u8_t data[] = { + 0x05, 'm', 'u', 'l', 't', 'i', 0x04, 'c', 'a', 's', 't', + 0x05, 'm', 'u', 'l', 't', 'i', 0x04, 'c', 'a', 's', 't', + 0x05, 'm', 'u', 'l', 't', 'i', 0x04, 'c', 'a', 's', 't', + 0x05, 'm', 'u', 'l', 't', 'i', 0x04, 'c', 'a', 's', 't', + 0x05, 'm', 'u', 'l', 't', 'i', 0x04, 'c', 'a', 's', 't', + 0x05, 'm', 'u', 'l', 't', 'i', 0x04, 'c', 'a', 's', 't', + 0x05, 'm', 'u', 'l', 't', 'i', 0x04, 'c', 'a', 's', 't', + 0x05, 'm', 'u', 'l', 't', 'i', 0x04, 'c', 'a', 's', 't', + 0x05, 'm', 'u', 'l', 't', 'i', 0x04, 'c', 'a', 's', 't', + 0x05, 'm', 'u', 'l', 't', 'i', 0x04, 'c', 'a', 's', 't', + 0x05, 'm', 'u', 'l', 't', 'i', 0x04, 'c', 'a', 's', 't', + 0x05, 'm', 'u', 'l', 't', 'i', 0x04, 'c', 'a', 's', 't', + 0x05, 'm', 'u', 'l', 't', 'i', 0x04, 'c', 'a', 's', 't', + 0x05, 'm', 'u', 'l', 't', 'i', 0x04, 'c', 'a', 's', 't', + 0x05, 'm', 'u', 'l', 't', 'i', 0x04, 'c', 'a', 's', 't', + 0x05, 'm', 'u', 'l', 't', 'i', 0x04, 'c', 'a', 's', 't', + 0x05, 'm', 'u', 'l', 't', 'i', 0x04, 'c', 'a', 's', 't', + 0x05, 'm', 'u', 'l', 't', 'i', 0x04, 'c', 'a', 's', 't', + 0x05, 'm', 'u', 'l', 't', 'i', 0x04, 'c', 'a', 's', 't', + 0x05, 'm', 'u', 'l', 't', 'i', 0x04, 'c', 'a', 's', 't', + 0x05, 'm', 'u', 'l', 't', 'i', 0x04, 'c', 'a', 's', 't', + 0x05, 'm', 'u', 'l', 't', 'i', 0x04, 'c', 'a', 's', 't', + 0x05, 'm', 'u', 'l', 't', 'i', 0x04, 'c', 'a', 's', 't', + 0x05, 'm', 'u', 'l', 't', 'i', 0x04, 'c', 'a', 's', 't', + 0x05, 'm', 'u', 'l', 't', 'i', 0x04, 'c', 'a', 's', 't', + 0x05, 'm', 'u', 'l', 't', 'i', 0x04, 'c', 'a', 's', 't', + 0x05, 'm', 'u', 'l', 't', 'i', 0x04, 'c', 'a', 's', 't', + 0x05, 'm', 'u', 'l', 't', 'i', 0x04, 'c', 'a', 's', 't', + 0x05, 'm', 'u', 'l', 't', 'i', 0x04, 'c', 'a', 's', 't', + 0x05, 'm', 'u', 'l', 't', 'i', 0x04, 'c', 'a', 's', 't', + 0x05, 'm', 'u', 'l', 't', 'i', 0x04, 'c', 'a', 's', 't', + 0x05, 'm', 'u', 'l', 't', 'i', 0x04, 'c', 'a', 's', 't', + 0x05, 'm', 'u', 'l', 't', 'i', 0x04, 'c', 'a', 's', 't', + 0x05, 'm', 'u', 'l', 't', 'i', 0x04, 'c', 'a', 's', 't', + 0x05, 'm', 'u', 'l', 't', 'i', 0x04, 'c', 'a', 's', 't', + 0x05, 'm', 'u', 'l', 't', 'i', 0x04, 'c', 'a', 's', 't', + 0x05, 'm', 'u', 'l', 't', 'i', 0x04, 'c', 'a', 's', 't', + 0x00, + }; + struct pbuf *p; + struct mdns_domain domain; + u16_t offset; + + p = pbuf_alloc(PBUF_RAW, sizeof(data), PBUF_ROM); + p->payload = (void *)(size_t)data; + fail_if(p == NULL); + offset = mdns_readname(p, 0, &domain); + pbuf_free(p); + fail_unless(offset == MDNS_READNAME_ERROR); +} +END_TEST + +START_TEST(readname_jump_earlier) +{ + static const u8_t data[] = { + /* Some padding needed, not supported to jump to bytes containing dns header */ + /* 0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + /* 10 */ 0x0f, 0x0e, 0x05, 'l', 'o', 'c', 'a', 'l', 0x00, 0xab, + /* 20 */ 0x05, 'm', 'u', 'l', 't', 'i', 0x04, 'c', 'a', 's', 't', 0xc0, 0x0c, + }; + static const u8_t fullname[] = { + 0x05, 'm', 'u', 'l', 't', 'i', 0x04, 'c', 'a', 's', 't', 0x05, 'l', 'o', 'c', 'a', 'l', 0x00, + }; + struct pbuf *p; + struct mdns_domain domain; + u16_t offset; + + p = pbuf_alloc(PBUF_RAW, sizeof(data), PBUF_ROM); + p->payload = (void *)(size_t)data; + fail_if(p == NULL); + offset = mdns_readname(p, 20, &domain); + pbuf_free(p); + fail_unless(offset == sizeof(data)); + fail_unless(domain.length == sizeof(fullname)); + + fail_if(memcmp(&domain.name, fullname, sizeof(fullname))); +} +END_TEST + +START_TEST(readname_jump_earlier_jump) +{ + static const u8_t data[] = { + /* Some padding needed, not supported to jump to bytes containing dns header */ + /* 0x00 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + /* 0x08 */ 0x00, 0x00, 0x00, 0x00, 0x03, 0x0b, 0x0a, 0xf2, + /* 0x10 */ 0x04, 'c', 'a', 's', 't', 0x00, 0xc0, 0x10, + /* 0x18 */ 0x05, 'm', 'u', 'l', 't', 'i', 0xc0, 0x16, + }; + static const u8_t fullname[] = { + 0x05, 'm', 'u', 'l', 't', 'i', 0x04, 'c', 'a', 's', 't', 0x00, + }; + struct pbuf *p; + struct mdns_domain domain; + u16_t offset; + + p = pbuf_alloc(PBUF_RAW, sizeof(data), PBUF_ROM); + p->payload = (void *)(size_t)data; + fail_if(p == NULL); + offset = mdns_readname(p, 0x18, &domain); + pbuf_free(p); + fail_unless(offset == sizeof(data)); + fail_unless(domain.length == sizeof(fullname)); + + fail_if(memcmp(&domain.name, fullname, sizeof(fullname))); +} +END_TEST + +START_TEST(readname_jump_maxdepth) +{ + static const u8_t data[] = { + /* Some padding needed, not supported to jump to bytes containing dns header */ + /* 0x00 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + /* 0x08 */ 0x00, 0x00, 0x00, 0x00, 0x03, 0x0b, 0x0a, 0xf2, + /* 0x10 */ 0x04, 'n', 'a', 'm', 'e', 0xc0, 0x27, 0x03, + /* 0x18 */ 0x03, 'd', 'n', 's', 0xc0, 0x10, 0xc0, 0x10, + /* 0x20 */ 0x04, 'd', 'e', 'e', 'p', 0xc0, 0x18, 0x00, + /* 0x28 */ 0x04, 'c', 'a', 's', 't', 0xc0, 0x20, 0xb0, + /* 0x30 */ 0x05, 'm', 'u', 'l', 't', 'i', 0xc0, 0x28, + }; + static const u8_t fullname[] = { + 0x05, 'm', 'u', 'l', 't', 'i', 0x04, 'c', 'a', 's', 't', + 0x04, 'd', 'e', 'e', 'p', 0x03, 'd', 'n', 's', + 0x04, 'n', 'a', 'm', 'e', 0x00, + }; + struct pbuf *p; + struct mdns_domain domain; + u16_t offset; + + p = pbuf_alloc(PBUF_RAW, sizeof(data), PBUF_ROM); + p->payload = (void *)(size_t)data; + fail_if(p == NULL); + offset = mdns_readname(p, 0x30, &domain); + pbuf_free(p); + fail_unless(offset == sizeof(data)); + fail_unless(domain.length == sizeof(fullname)); + + fail_if(memcmp(&domain.name, fullname, sizeof(fullname))); +} +END_TEST + +START_TEST(readname_jump_later) +{ + static const u8_t data[] = { + /* 0x00 */ 0x05, 'm', 'u', 'l', 't', 'i', 0x04, 'c', 'a', 's', 't', 0xc0, 0x10, 0x00, 0x01, 0x40, + /* 0x10 */ 0x05, 'l', 'o', 'c', 'a', 'l', 0x00, 0xab, + }; + static const u8_t fullname[] = { + 0x05, 'm', 'u', 'l', 't', 'i', 0x04, 'c', 'a', 's', 't', 0x05, 'l', 'o', 'c', 'a', 'l', 0x00, + }; + struct pbuf *p; + struct mdns_domain domain; + u16_t offset; + + p = pbuf_alloc(PBUF_RAW, sizeof(data), PBUF_ROM); + p->payload = (void *)(size_t)data; + fail_if(p == NULL); + offset = mdns_readname(p, 0, &domain); + pbuf_free(p); + fail_unless(offset == 13); + fail_unless(domain.length == sizeof(fullname)); + + fail_if(memcmp(&domain.name, fullname, sizeof(fullname))); +} +END_TEST + +START_TEST(readname_half_jump) +{ + static const u8_t data[] = { + 0x05, 'm', 'u', 'l', 't', 'i', 0x04, 'c', 'a', 's', 't', 0xc0, + }; + struct pbuf *p; + struct mdns_domain domain; + u16_t offset; + + p = pbuf_alloc(PBUF_RAW, sizeof(data), PBUF_ROM); + p->payload = (void *)(size_t)data; + fail_if(p == NULL); + offset = mdns_readname(p, 0, &domain); + pbuf_free(p); + fail_unless(offset == MDNS_READNAME_ERROR); +} +END_TEST + +START_TEST(readname_jump_toolong) +{ + static const u8_t data[] = { + 0x05, 'm', 'u', 'l', 't', 'i', 0x04, 'c', 'a', 's', 't', 0xc2, 0x10, 0x00, 0x01, 0x40, + }; + struct pbuf *p; + struct mdns_domain domain; + u16_t offset; + + p = pbuf_alloc(PBUF_RAW, sizeof(data), PBUF_ROM); + p->payload = (void *)(size_t)data; + fail_if(p == NULL); + offset = mdns_readname(p, 0, &domain); + pbuf_free(p); + fail_unless(offset == MDNS_READNAME_ERROR); +} +END_TEST + +START_TEST(readname_jump_loop_label) +{ + static const u8_t data[] = { + /* 0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + /* 10 */ 0x05, 'm', 'u', 'l', 't', 'i', 0x04, 'c', 'a', 's', 't', 0xc0, 0x10, + }; + struct pbuf *p; + struct mdns_domain domain; + u16_t offset; + + p = pbuf_alloc(PBUF_RAW, sizeof(data), PBUF_ROM); + p->payload = (void *)(size_t)data; + fail_if(p == NULL); + offset = mdns_readname(p, 10, &domain); + pbuf_free(p); + fail_unless(offset == MDNS_READNAME_ERROR); +} +END_TEST + +START_TEST(readname_jump_loop_jump) +{ + static const u8_t data[] = { + /* 0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + /* 10 */ 0x05, 'm', 'u', 'l', 't', 'i', 0x04, 'c', 'a', 's', 't', 0xc0, 0x15, + }; + struct pbuf *p; + struct mdns_domain domain; + u16_t offset; + + p = pbuf_alloc(PBUF_RAW, sizeof(data), PBUF_ROM); + p->payload = (void *)(size_t)data; + fail_if(p == NULL); + offset = mdns_readname(p, 10, &domain); + pbuf_free(p); + fail_unless(offset == MDNS_READNAME_ERROR); +} +END_TEST + +START_TEST(add_label_basic) +{ + static const u8_t data[] = { 0x05, 'm', 'u', 'l', 't', 'i', 0x04, 'c', 'a', 's', 't', 0x00 }; + struct mdns_domain domain; + err_t res; + + memset(&domain, 0, sizeof(domain)); + res = mdns_domain_add_label(&domain, "multi", 5); + fail_unless(res == ERR_OK); + res = mdns_domain_add_label(&domain, "cast", 4); + fail_unless(res == ERR_OK); + res = mdns_domain_add_label(&domain, NULL, 0); + fail_unless(res == ERR_OK); + fail_unless(domain.length == sizeof(data)); + fail_if(memcmp(&domain.name, data, sizeof(data))); +} +END_TEST + +START_TEST(add_label_long_label) +{ + static const char *toolong = "abcdefghijklmnopqrstuvwxyz0123456789-abcdefghijklmnopqrstuvwxyz0123456789-abcdefghijklmnopqrstuvwxyz0123456789-"; + struct mdns_domain domain; + err_t res; + + memset(&domain, 0, sizeof(domain)); + res = mdns_domain_add_label(&domain, "multi", 5); + fail_unless(res == ERR_OK); + res = mdns_domain_add_label(&domain, toolong, strlen(toolong)); + fail_unless(res == ERR_VAL); +} +END_TEST + +START_TEST(add_label_full) +{ + static const char *label = "0123456789abcdef0123456789abcdef"; + struct mdns_domain domain; + err_t res; + + memset(&domain, 0, sizeof(domain)); + res = mdns_domain_add_label(&domain, label, strlen(label)); + fail_unless(res == ERR_OK); + fail_unless(domain.length == 33); + res = mdns_domain_add_label(&domain, label, strlen(label)); + fail_unless(res == ERR_OK); + fail_unless(domain.length == 66); + res = mdns_domain_add_label(&domain, label, strlen(label)); + fail_unless(res == ERR_OK); + fail_unless(domain.length == 99); + res = mdns_domain_add_label(&domain, label, strlen(label)); + fail_unless(res == ERR_OK); + fail_unless(domain.length == 132); + res = mdns_domain_add_label(&domain, label, strlen(label)); + fail_unless(res == ERR_OK); + fail_unless(domain.length == 165); + res = mdns_domain_add_label(&domain, label, strlen(label)); + fail_unless(res == ERR_OK); + fail_unless(domain.length == 198); + res = mdns_domain_add_label(&domain, label, strlen(label)); + fail_unless(res == ERR_OK); + fail_unless(domain.length == 231); + res = mdns_domain_add_label(&domain, label, strlen(label)); + fail_unless(res == ERR_VAL); + fail_unless(domain.length == 231); + res = mdns_domain_add_label(&domain, label, 25); + fail_unless(res == ERR_VAL); + fail_unless(domain.length == 231); + res = mdns_domain_add_label(&domain, label, 24); + fail_unless(res == ERR_VAL); + fail_unless(domain.length == 231); + res = mdns_domain_add_label(&domain, label, 23); + fail_unless(res == ERR_OK); + fail_unless(domain.length == 255); + res = mdns_domain_add_label(&domain, NULL, 0); + fail_unless(res == ERR_OK); + fail_unless(domain.length == 256); + res = mdns_domain_add_label(&domain, NULL, 0); + fail_unless(res == ERR_VAL); + fail_unless(domain.length == 256); +} +END_TEST + +START_TEST(domain_eq_basic) +{ + static const u8_t data[] = { + 0x05, 'm', 'u', 'l', 't', 'i', 0x04, 'c', 'a', 's', 't', 0x00, + }; + struct mdns_domain domain1, domain2; + err_t res; + + memset(&domain1, 0, sizeof(domain1)); + res = mdns_domain_add_label(&domain1, "multi", 5); + fail_unless(res == ERR_OK); + res = mdns_domain_add_label(&domain1, "cast", 4); + fail_unless(res == ERR_OK); + res = mdns_domain_add_label(&domain1, NULL, 0); + fail_unless(res == ERR_OK); + fail_unless(domain1.length == sizeof(data)); + + memset(&domain2, 0, sizeof(domain2)); + res = mdns_domain_add_label(&domain2, "multi", 5); + fail_unless(res == ERR_OK); + res = mdns_domain_add_label(&domain2, "cast", 4); + fail_unless(res == ERR_OK); + res = mdns_domain_add_label(&domain2, NULL, 0); + fail_unless(res == ERR_OK); + + fail_unless(mdns_domain_eq(&domain1, &domain2)); +} +END_TEST + +START_TEST(domain_eq_diff) +{ + struct mdns_domain domain1, domain2; + err_t res; + + memset(&domain1, 0, sizeof(domain1)); + res = mdns_domain_add_label(&domain1, "multi", 5); + fail_unless(res == ERR_OK); + res = mdns_domain_add_label(&domain1, "base", 4); + fail_unless(res == ERR_OK); + res = mdns_domain_add_label(&domain1, NULL, 0); + fail_unless(res == ERR_OK); + + memset(&domain2, 0, sizeof(domain2)); + res = mdns_domain_add_label(&domain2, "multi", 5); + fail_unless(res == ERR_OK); + res = mdns_domain_add_label(&domain2, "cast", 4); + fail_unless(res == ERR_OK); + res = mdns_domain_add_label(&domain2, NULL, 0); + fail_unless(res == ERR_OK); + + fail_if(mdns_domain_eq(&domain1, &domain2)); +} +END_TEST + +START_TEST(domain_eq_case) +{ + struct mdns_domain domain1, domain2; + err_t res; + + memset(&domain1, 0, sizeof(domain1)); + res = mdns_domain_add_label(&domain1, "multi", 5); + fail_unless(res == ERR_OK); + res = mdns_domain_add_label(&domain1, "cast", 4); + fail_unless(res == ERR_OK); + res = mdns_domain_add_label(&domain1, NULL, 0); + fail_unless(res == ERR_OK); + + memset(&domain2, 0, sizeof(domain2)); + res = mdns_domain_add_label(&domain2, "MulTI", 5); + fail_unless(res == ERR_OK); + res = mdns_domain_add_label(&domain2, "casT", 4); + fail_unless(res == ERR_OK); + res = mdns_domain_add_label(&domain2, NULL, 0); + fail_unless(res == ERR_OK); + + fail_unless(mdns_domain_eq(&domain1, &domain2)); +} +END_TEST + +START_TEST(domain_eq_anydata) +{ + static const char data1[] = { 0x05, (char)0xcc, (char)0xdc, 0x00, (char)0xa0 }; + static const char data2[] = { 0x7f, (char)0x8c, 0x01, (char)0xff, (char)0xcf }; + struct mdns_domain domain1, domain2; + err_t res; + + memset(&domain1, 0, sizeof(domain1)); + res = mdns_domain_add_label(&domain1, data1, sizeof(data1)); + fail_unless(res == ERR_OK); + res = mdns_domain_add_label(&domain1, "cast", 4); + fail_unless(res == ERR_OK); + res = mdns_domain_add_label(&domain1, data2, sizeof(data2)); + fail_unless(res == ERR_OK); + res = mdns_domain_add_label(&domain1, NULL, 0); + fail_unless(res == ERR_OK); + + memset(&domain2, 0, sizeof(domain2)); + res = mdns_domain_add_label(&domain2, data1, sizeof(data1)); + fail_unless(res == ERR_OK); + res = mdns_domain_add_label(&domain2, "casT", 4); + fail_unless(res == ERR_OK); + res = mdns_domain_add_label(&domain2, data2, sizeof(data2)); + fail_unless(res == ERR_OK); + res = mdns_domain_add_label(&domain2, NULL, 0); + fail_unless(res == ERR_OK); + + fail_unless(mdns_domain_eq(&domain1, &domain2)); +} +END_TEST + +START_TEST(domain_eq_length) +{ + struct mdns_domain domain1, domain2; + err_t res; + + memset(&domain1, 0, sizeof(domain1)); + memset(domain1.name, 0xAA, sizeof(MDNS_DOMAIN_MAXLEN)); + res = mdns_domain_add_label(&domain1, "multi", 5); + fail_unless(res == ERR_OK); + res = mdns_domain_add_label(&domain1, "cast", 4); + fail_unless(res == ERR_OK); + + memset(&domain2, 0, sizeof(domain2)); + memset(domain2.name, 0xBB, sizeof(MDNS_DOMAIN_MAXLEN)); + res = mdns_domain_add_label(&domain2, "multi", 5); + fail_unless(res == ERR_OK); + res = mdns_domain_add_label(&domain2, "cast", 4); + fail_unless(res == ERR_OK); + + fail_unless(mdns_domain_eq(&domain1, &domain2)); +} +END_TEST + +START_TEST(compress_full_match) +{ + static const u8_t data[] = { + 0x00, 0x00, + 0x06, 'f', 'o', 'o', 'b', 'a', 'r', 0x05, 'l', 'o', 'c', 'a', 'l', 0x00 + }; + struct pbuf *p; + struct mdns_domain domain; + u16_t offset; + u8_t length; + err_t res; + + p = pbuf_alloc(PBUF_RAW, sizeof(data), PBUF_ROM); + p->payload = (void *)(size_t)data; + fail_if(p == NULL); + + memset(&domain, 0, sizeof(domain)); + res = mdns_domain_add_label(&domain, "foobar", 6); + fail_unless(res == ERR_OK); + res = mdns_domain_add_label(&domain, "local", 5); + fail_unless(res == ERR_OK); + res = mdns_domain_add_label(&domain, NULL, 0); + fail_unless(res == ERR_OK); + + offset = 2; + length = mdns_compress_domain(p, &offset, &domain); + /* Write 0 bytes, then a jump to addr 2 */ + fail_unless(length == 0); + fail_unless(offset == 2); + + pbuf_free(p); +} +END_TEST + +START_TEST(compress_full_match_subset) +{ + static const u8_t data[] = { + 0x00, 0x00, + 0x02, 'g', 'o', 0x06, 'f', 'o', 'o', 'b', 'a', 'r', 0x05, 'l', 'o', 'c', 'a', 'l', 0x00 + }; + struct pbuf *p; + struct mdns_domain domain; + u16_t offset; + u8_t length; + err_t res; + + p = pbuf_alloc(PBUF_RAW, sizeof(data), PBUF_ROM); + p->payload = (void *)(size_t)data; + fail_if(p == NULL); + + memset(&domain, 0, sizeof(domain)); + res = mdns_domain_add_label(&domain, "foobar", 6); + fail_unless(res == ERR_OK); + res = mdns_domain_add_label(&domain, "local", 5); + fail_unless(res == ERR_OK); + res = mdns_domain_add_label(&domain, NULL, 0); + fail_unless(res == ERR_OK); + + offset = 2; + length = mdns_compress_domain(p, &offset, &domain); + /* Write 0 bytes, then a jump to addr 5 */ + fail_unless(length == 0); + fail_unless(offset == 5); + + pbuf_free(p); +} +END_TEST + +START_TEST(compress_full_match_jump) +{ + static const u8_t data[] = { + /* 0x00 */ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, + /* 0x10 */ 0x04, 'l', 'w', 'i', 'p', 0x05, 'l', 'o', 'c', 'a', 'l', 0x00, 0xc0, 0x00, 0x02, 0x00, + /* 0x20 */ 0x06, 'f', 'o', 'o', 'b', 'a', 'r', 0xc0, 0x15, + }; + struct pbuf *p; + struct mdns_domain domain; + u16_t offset; + u8_t length; + err_t res; + + p = pbuf_alloc(PBUF_RAW, sizeof(data), PBUF_ROM); + p->payload = (void *)(size_t)data; + fail_if(p == NULL); + + memset(&domain, 0, sizeof(domain)); + res = mdns_domain_add_label(&domain, "foobar", 6); + fail_unless(res == ERR_OK); + res = mdns_domain_add_label(&domain, "local", 5); + fail_unless(res == ERR_OK); + res = mdns_domain_add_label(&domain, NULL, 0); + fail_unless(res == ERR_OK); + + offset = 0x20; + length = mdns_compress_domain(p, &offset, &domain); + /* Write 0 bytes, then a jump to addr 0x20 */ + fail_unless(length == 0); + fail_unless(offset == 0x20); + + pbuf_free(p); +} +END_TEST + +START_TEST(compress_no_match) +{ + static const u8_t data[] = { + 0x00, 0x00, + 0x04, 'l', 'w', 'i', 'p', 0x05, 'w', 'i', 'k', 'i', 'a', 0x03, 'c', 'o', 'm', 0x00 + }; + struct pbuf *p; + struct mdns_domain domain; + u16_t offset; + u8_t length; + err_t res; + + p = pbuf_alloc(PBUF_RAW, sizeof(data), PBUF_ROM); + p->payload = (void *)(size_t)data; + fail_if(p == NULL); + + memset(&domain, 0, sizeof(domain)); + res = mdns_domain_add_label(&domain, "foobar", 6); + fail_unless(res == ERR_OK); + res = mdns_domain_add_label(&domain, "local", 5); + fail_unless(res == ERR_OK); + res = mdns_domain_add_label(&domain, NULL, 0); + fail_unless(res == ERR_OK); + + offset = 2; + length = mdns_compress_domain(p, &offset, &domain); + /* Write all bytes, no jump */ + fail_unless(length == domain.length); + + pbuf_free(p); +} +END_TEST + +START_TEST(compress_2nd_label) +{ + static const u8_t data[] = { + 0x00, 0x00, + 0x06, 'f', 'o', 'o', 'b', 'a', 'r', 0x05, 'l', 'o', 'c', 'a', 'l', 0x00 + }; + struct pbuf *p; + struct mdns_domain domain; + u16_t offset; + u8_t length; + err_t res; + + p = pbuf_alloc(PBUF_RAW, sizeof(data), PBUF_ROM); + p->payload = (void *)(size_t)data; + fail_if(p == NULL); + + memset(&domain, 0, sizeof(domain)); + res = mdns_domain_add_label(&domain, "lwip", 4); + fail_unless(res == ERR_OK); + res = mdns_domain_add_label(&domain, "local", 5); + fail_unless(res == ERR_OK); + res = mdns_domain_add_label(&domain, NULL, 0); + fail_unless(res == ERR_OK); + + offset = 2; + length = mdns_compress_domain(p, &offset, &domain); + /* Write 5 bytes, then a jump to addr 9 */ + fail_unless(length == 5); + fail_unless(offset == 9); + + pbuf_free(p); +} +END_TEST + +START_TEST(compress_2nd_label_short) +{ + static const u8_t data[] = { + 0x00, 0x00, + 0x04, 'l', 'w', 'i', 'p', 0x05, 'l', 'o', 'c', 'a', 'l', 0x00 + }; + struct pbuf *p; + struct mdns_domain domain; + u16_t offset; + u8_t length; + err_t res; + + p = pbuf_alloc(PBUF_RAW, sizeof(data), PBUF_ROM); + p->payload = (void *)(size_t)data; + fail_if(p == NULL); + + memset(&domain, 0, sizeof(domain)); + res = mdns_domain_add_label(&domain, "foobar", 6); + fail_unless(res == ERR_OK); + res = mdns_domain_add_label(&domain, "local", 5); + fail_unless(res == ERR_OK); + res = mdns_domain_add_label(&domain, NULL, 0); + fail_unless(res == ERR_OK); + + offset = 2; + length = mdns_compress_domain(p, &offset, &domain); + /* Write 5 bytes, then a jump to addr 7 */ + fail_unless(length == 7); + fail_unless(offset == 7); + + pbuf_free(p); +} +END_TEST + +START_TEST(compress_jump_to_jump) +{ + static const u8_t data[] = { + /* 0x00 */ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, + /* 0x10 */ 0x04, 'l', 'w', 'i', 'p', 0x05, 'l', 'o', 'c', 'a', 'l', 0x00, 0xc0, 0x00, 0x02, 0x00, + /* 0x20 */ 0x07, 'b', 'a', 'n', 'a', 'n', 'a', 's', 0xc0, 0x15, + }; + struct pbuf *p; + struct mdns_domain domain; + u16_t offset; + u8_t length; + err_t res; + + p = pbuf_alloc(PBUF_RAW, sizeof(data), PBUF_ROM); + p->payload = (void *)(size_t)data; + fail_if(p == NULL); + + memset(&domain, 0, sizeof(domain)); + res = mdns_domain_add_label(&domain, "foobar", 6); + fail_unless(res == ERR_OK); + res = mdns_domain_add_label(&domain, "local", 5); + fail_unless(res == ERR_OK); + res = mdns_domain_add_label(&domain, NULL, 0); + fail_unless(res == ERR_OK); + + offset = 0x20; + length = mdns_compress_domain(p, &offset, &domain); + /* Dont compress if jump would be to a jump */ + fail_unless(length == domain.length); + + offset = 0x10; + length = mdns_compress_domain(p, &offset, &domain); + /* Write 7 bytes, then a jump to addr 0x15 */ + fail_unless(length == 7); + fail_unless(offset == 0x15); + + pbuf_free(p); +} +END_TEST + +START_TEST(compress_long_match) +{ + static const u8_t data[] = { + 0x00, 0x00, + 0x06, 'f', 'o', 'o', 'b', 'a', 'r', 0x05, 'l', 'o', 'c', 'a', 'l', 0x03, 'c', 'o', 'm', 0x00 + }; + struct pbuf *p; + struct mdns_domain domain; + u16_t offset; + u8_t length; + err_t res; + + p = pbuf_alloc(PBUF_RAW, sizeof(data), PBUF_ROM); + p->payload = (void *)(size_t)data; + fail_if(p == NULL); + + memset(&domain, 0, sizeof(domain)); + res = mdns_domain_add_label(&domain, "foobar", 6); + fail_unless(res == ERR_OK); + res = mdns_domain_add_label(&domain, "local", 5); + fail_unless(res == ERR_OK); + res = mdns_domain_add_label(&domain, NULL, 0); + fail_unless(res == ERR_OK); + + offset = 2; + length = mdns_compress_domain(p, &offset, &domain); + fail_unless(length == domain.length); + + pbuf_free(p); +} +END_TEST + +Suite* mdns_suite(void) +{ + testfunc tests[] = { + TESTFUNC(readname_basic), + TESTFUNC(readname_anydata), + TESTFUNC(readname_short_buf), + TESTFUNC(readname_long_label), + TESTFUNC(readname_overflow), + TESTFUNC(readname_jump_earlier), + TESTFUNC(readname_jump_earlier_jump), + TESTFUNC(readname_jump_maxdepth), + TESTFUNC(readname_jump_later), + TESTFUNC(readname_half_jump), + TESTFUNC(readname_jump_toolong), + TESTFUNC(readname_jump_loop_label), + TESTFUNC(readname_jump_loop_jump), + + TESTFUNC(add_label_basic), + TESTFUNC(add_label_long_label), + TESTFUNC(add_label_full), + + TESTFUNC(domain_eq_basic), + TESTFUNC(domain_eq_diff), + TESTFUNC(domain_eq_case), + TESTFUNC(domain_eq_anydata), + TESTFUNC(domain_eq_length), + + TESTFUNC(compress_full_match), + TESTFUNC(compress_full_match_subset), + TESTFUNC(compress_full_match_jump), + TESTFUNC(compress_no_match), + TESTFUNC(compress_2nd_label), + TESTFUNC(compress_2nd_label_short), + TESTFUNC(compress_jump_to_jump), + TESTFUNC(compress_long_match), + }; + return create_suite("MDNS", tests, sizeof(tests)/sizeof(testfunc), NULL, NULL); +} diff --git a/test/unit/mdns/test_mdns.h b/test/unit/mdns/test_mdns.h new file mode 100644 index 00000000..c3df3391 --- /dev/null +++ b/test/unit/mdns/test_mdns.h @@ -0,0 +1,8 @@ +#ifndef LWIP_HDR_TEST_MDNS_H__ +#define LWIP_HDR_TEST_MDNS_H__ + +#include "../lwip_check.h" + +Suite* mdns_suite(void); + +#endif From 306113c8c325a3565b6833db0e160ee1c30963a2 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Sun, 14 Aug 2016 15:22:05 +0200 Subject: [PATCH 072/325] Add MDNS to doxygen docs --- doc/doxygen/lwip.Doxyfile | 1 + src/apps/mdns/mdns.c | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/doc/doxygen/lwip.Doxyfile b/doc/doxygen/lwip.Doxyfile index 8bff8f56..5b8bda3b 100644 --- a/doc/doxygen/lwip.Doxyfile +++ b/doc/doxygen/lwip.Doxyfile @@ -2085,6 +2085,7 @@ PREDEFINED = __DOXYGEN__=1 \ SNMP_USE_NETCONN=1 \ SNMP_USE_RAW=1 \ MIB2_STATS=1 \ + LWIP_MDNS=1 \ MEMP_OVERFLOW_CHECK=0 \ MEMP_SANITY_CHECK=1 \ LWIP_ARP=1 \ diff --git a/src/apps/mdns/mdns.c b/src/apps/mdns/mdns.c index 14938468..8e1c5f99 100644 --- a/src/apps/mdns/mdns.c +++ b/src/apps/mdns/mdns.c @@ -309,9 +309,10 @@ mdns_strncasecmp(const char* str1, const char* str2, size_t len) /** + * @ingroup mdns * Add a label part to a domain * @param domain The domain to add a label to - * @param label The label to add, like , 'local', 'com' or '' + * @param label The label to add, like <hostname>, 'local', 'com' or '' * @param len The length of the label * @return ERR_OK on success, an err_t otherwise if label too long */ @@ -407,8 +408,9 @@ mdns_readname_loop(struct pbuf *p, u16_t offset, struct mdns_domain *domain, uns } /** + * @ingroup mdns * Read possibly compressed domain name from packet buffer - * @param pbuf The packet + * @param p The packet * @param offset start position of domain name in packet * @param domain The domain name destination * @return The new offset after the domain, or MDNS_READNAME_ERROR @@ -444,6 +446,7 @@ mdns_domain_debug_print(int debug, struct mdns_domain *domain) } /** + * @ingroup mdns * Return 1 if contents of domains match (case-insensitive) * @param a Domain name to compare 1 * @param b Domain name to compare 2 @@ -760,6 +763,7 @@ check_service(struct mdns_service *service, struct mdns_rr_info *rr) } /** + * @ingroup mdns * Return bytes needed to write before jump for best result of compressing supplied domain * against domain in outpacket starting at specified offset. * If a match is found, offset is updated to where to jump to @@ -1847,6 +1851,7 @@ dealloc: } /** + * @ingroup mdns * Initiate MDNS responder. Will open UDP sockets on port 5353 */ void @@ -1875,9 +1880,10 @@ mdns_resp_init(void) } /** + * @ingroup mdns * Activate MDNS responder for a network interface and send announce packets. * @param netif The network interface to activate. - * @param hostname Name to use. Queries for .local will be answered + * @param hostname Name to use. Queries for <hostname>.local will be answered * with the IP addresses of the netif. The hostname will be copied, the * given pointer can be on the stack. * @param dns_ttl Validity time in seconds to send out for IP address data in DNS replies @@ -1930,6 +1936,7 @@ cleanup: } /** + * @ingroup mdns * Stop responding to MDNS queries on this interface, leave multicast groups, * and free the helper structure and any of its services. * @param netif The network interface to remove. @@ -1963,6 +1970,7 @@ mdns_resp_remove_netif(struct netif *netif) } /** + * @ingroup mdns * Add a service to the selected network interface. * @param netif The network interface to publish this service on * @param name The name of the service @@ -2025,6 +2033,7 @@ mdns_resp_add_service(struct netif *netif, char *name, char *service, u16_t prot } /** + * @ingroup mdns * Call this function from inside the service_get_txt_fn_t callback to add text data. * Buffer for TXT data is 256 bytes, and each field is prefixed with a length byte. * @param service The service provided to the get_txt callback From a2894ede1cb22cd9e8bc6d2a3de053d87e442464 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Sun, 14 Aug 2016 15:31:49 +0200 Subject: [PATCH 073/325] MDNS: make a few arguments const where suitable --- doc/mdns.txt | 4 ++-- src/apps/mdns/mdns.c | 6 +++--- src/include/lwip/apps/mdns.h | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/doc/mdns.txt b/doc/mdns.txt index 3cbb1ba4..e3921359 100644 --- a/doc/mdns.txt +++ b/doc/mdns.txt @@ -4,7 +4,7 @@ Author: Erik Ekman Note! The MDNS responder does not have all features required by the standards. -See notes in src/core/mdns.c for what is left. It is however usable in normal +See notes in src/apps/mdns/mdns.c for what is left. It is however usable in normal cases - but watch out if many devices on the same network try to use the same host/service instance names. @@ -17,7 +17,7 @@ MDNS supports using IPv4 only, v6 only, or v4+v6. To enable MDNS responder, set LWIP_MDNS = 1 -in lwipopts.h and add src/core/mdns.c to your list of files to build. +in lwipopts.h and add src/apps/mdns/mdns.c to your list of files to build. The max number of services supported per netif is defined by MDNS_MAX_SERVICES, default is 1. diff --git a/src/apps/mdns/mdns.c b/src/apps/mdns/mdns.c index 8e1c5f99..c51f5571 100644 --- a/src/apps/mdns/mdns.c +++ b/src/apps/mdns/mdns.c @@ -1890,7 +1890,7 @@ mdns_resp_init(void) * @return ERR_OK if netif was added, an err_t otherwise */ err_t -mdns_resp_add_netif(struct netif *netif, char *hostname, u32_t dns_ttl) +mdns_resp_add_netif(struct netif *netif, const char *hostname, u32_t dns_ttl) { err_t res; @@ -1985,7 +1985,7 @@ mdns_resp_remove_netif(struct netif *netif) * @return ERR_OK if the service was added to the netif, an err_t otherwise */ err_t -mdns_resp_add_service(struct netif *netif, char *name, char *service, u16_t proto, u16_t port, u32_t dns_ttl, service_get_txt_fn_t txt_fn, void *txt_data) +mdns_resp_add_service(struct netif *netif, const char *name, const char *service, u16_t proto, u16_t port, u32_t dns_ttl, service_get_txt_fn_t txt_fn, void *txt_data) { int i; int slot = -1; @@ -2042,7 +2042,7 @@ mdns_resp_add_service(struct netif *netif, char *name, char *service, u16_t prot * @return ERR_OK if the string was added to the reply, an err_t otherwise */ err_t -mdns_resp_add_service_txtitem(struct mdns_service *service, char *txt, int txt_len) +mdns_resp_add_service_txtitem(struct mdns_service *service, const char *txt, int txt_len) { LWIP_ASSERT("mdns_resp_add_service: service != NULL", service); diff --git a/src/include/lwip/apps/mdns.h b/src/include/lwip/apps/mdns.h index 36892192..08fa5df7 100644 --- a/src/include/lwip/apps/mdns.h +++ b/src/include/lwip/apps/mdns.h @@ -47,12 +47,12 @@ struct mdns_service; void mdns_resp_init(void); -err_t mdns_resp_add_netif(struct netif *netif, char *hostname, u32_t dns_ttl); +err_t mdns_resp_add_netif(struct netif *netif, const char *hostname, u32_t dns_ttl); err_t mdns_resp_remove_netif(struct netif *netif); typedef void (*service_get_txt_fn_t)(struct mdns_service *service, void *txt_userdata); -err_t mdns_resp_add_service(struct netif *netif, char *name, char *service, u16_t proto, u16_t port, u32_t dns_ttl, service_get_txt_fn_t txt_fn, void *txt_userdata); -err_t mdns_resp_add_service_txtitem(struct mdns_service *service, char *txt, int txt_len); +err_t mdns_resp_add_service(struct netif *netif, const char *name, const char *service, u16_t proto, u16_t port, u32_t dns_ttl, service_get_txt_fn_t txt_fn, void *txt_userdata); +err_t mdns_resp_add_service_txtitem(struct mdns_service *service, const char *txt, int txt_len); /* Domain struct and methods - visible for unit tests */ From b472648e40d5504198065650e624d4b9fe78cc7b Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Sun, 14 Aug 2016 15:36:41 +0200 Subject: [PATCH 074/325] Fix wrong copyright header in mdns_opts.h --- src/include/lwip/apps/mdns_opts.h | 33 +++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/src/include/lwip/apps/mdns_opts.h b/src/include/lwip/apps/mdns_opts.h index 4d818f6d..710911fc 100644 --- a/src/include/lwip/apps/mdns_opts.h +++ b/src/include/lwip/apps/mdns_opts.h @@ -1,8 +1,33 @@ -/* - * File: mdns_opts.h - * Author: dziegel +/* + * Copyright (c) 2015 Verisure Innovation AB + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Erik Ekman * - * Created on 13. August 2016, 09:17 */ #ifndef LWIP_HDR_APPS_MDNS_OPTS_H From 4d85def20a5a54b99010c638eea79196a15e886d Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Sun, 14 Aug 2016 15:39:58 +0200 Subject: [PATCH 075/325] Update README applications sections --- README | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README b/README index 3c01a901..0884d27b 100644 --- a/README +++ b/README @@ -28,7 +28,6 @@ FEATURES * raw/native API for enhanced performance * Optional Berkeley-like socket API * DNS (Domain names resolver) - * MDNS (Multicast DNS) responder APPLICATIONS @@ -36,6 +35,9 @@ APPLICATIONS * HTTP server with SSI and CGI * SNMPv2c agent with MIB compiler (Simple Network Management Protocol) * SNTP (Simple network time protocol) + * NetBIOS name service responder + * MDNS (Multicast DNS) responder + * iPerf server implementation LICENSE From ebe0e6f98d3b6bd05466037c516bbc6489edab0b Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Sun, 14 Aug 2016 15:42:22 +0200 Subject: [PATCH 076/325] Some documentation cosmetics in mdns.c --- src/apps/mdns/mdns.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/apps/mdns/mdns.c b/src/apps/mdns/mdns.c index c51f5571..a2c22e64 100644 --- a/src/apps/mdns/mdns.c +++ b/src/apps/mdns/mdns.c @@ -42,8 +42,8 @@ * @defgroup mdns MDNS * @ingroup apps * - * RFC 6762 - Multicast DNS - * RFC 6763 - DNS-Based Service Discovery + * RFC 6762 - Multicast DNS\n + * RFC 6763 - DNS-Based Service Discovery\n * * @verbinclude mdns.txt * From 2335c1a73c175dfce7e8f8fd15518ee382991ca1 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Sun, 14 Aug 2016 16:47:45 +0200 Subject: [PATCH 077/325] Port MDNS to new dual-stack API --- src/apps/mdns/mdns.c | 38 ++++++++------------------------------ 1 file changed, 8 insertions(+), 30 deletions(-) diff --git a/src/apps/mdns/mdns.c b/src/apps/mdns/mdns.c index a2c22e64..935f0cd6 100644 --- a/src/apps/mdns/mdns.c +++ b/src/apps/mdns/mdns.c @@ -107,14 +107,7 @@ static const ip_addr_t v6group = IPADDR6_INIT(PP_HTONL(0xFF020000UL), PP_HTONL(0 #define DOMAIN_JUMP_SIZE 2 #define DOMAIN_JUMP 0xc000 -static struct mdns_data { -#if LWIP_IPV4 - struct udp_pcb *v4pcb; -#endif -#if LWIP_IPV6 - struct udp_pcb *v6pcb; -#endif -} mdns_data; +static struct udp_pcb *mdns_pcb; #define TOPDOMAIN_LOCAL "local" @@ -1450,7 +1443,6 @@ mdns_send_outpacket(struct mdns_outpacket *outpkt) if (outpkt->pbuf) { const ip_addr_t *mcast_destaddr; - struct udp_pcb *pcb = NULL; struct dns_hdr hdr; /* Write header */ @@ -1470,20 +1462,18 @@ mdns_send_outpacket(struct mdns_outpacket *outpkt) if (IP_IS_V6_VAL(outpkt->dest_addr)) { #if LWIP_IPV6 mcast_destaddr = &v6group; - pcb = mdns_data.v6pcb; #endif } else { #if LWIP_IPV4 mcast_destaddr = &v4group; - pcb = mdns_data.v4pcb; #endif } /* Send created packet */ LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: Sending packet, len=%d, unicast=%d\n", outpkt->write_offset, outpkt->unicast_reply)); if (outpkt->unicast_reply) { - udp_sendto_if(pcb, outpkt->pbuf, &outpkt->dest_addr, outpkt->dest_port, outpkt->netif); + udp_sendto_if(mdns_pcb, outpkt->pbuf, &outpkt->dest_addr, outpkt->dest_port, outpkt->netif); } else { - udp_sendto_if(pcb, outpkt->pbuf, mcast_destaddr, MDNS_PORT, outpkt->netif); + udp_sendto_if(mdns_pcb, outpkt->pbuf, mcast_destaddr, MDNS_PORT, outpkt->netif); } } @@ -1858,25 +1848,13 @@ void mdns_resp_init(void) { err_t res; - memset(&mdns_data, 0, sizeof(mdns_data)); -#if LWIP_IPV4 - mdns_data.v4pcb = udp_new(); - LWIP_ASSERT("Failed to allocate pcb", mdns_data.v4pcb != NULL); - udp_set_multicast_ttl(mdns_data.v4pcb, MDNS_TTL); - res = udp_bind(mdns_data.v4pcb, IP_ADDR_ANY, MDNS_PORT); + mdns_pcb = udp_new_ip_type(IPADDR_TYPE_ANY); + LWIP_ASSERT("Failed to allocate pcb", mdns_pcb != NULL); + udp_set_multicast_ttl(mdns_pcb, MDNS_TTL); + res = udp_bind(mdns_pcb, IP_ADDR_ANY, MDNS_PORT); LWIP_ASSERT("Failed to bind pcb", res == ERR_OK); - udp_recv(mdns_data.v4pcb, mdns_recv, &mdns_data); -#endif - -#if LWIP_IPV6 - mdns_data.v6pcb = udp_new_ip6(); - LWIP_ASSERT("Failed to allocate pcb", mdns_data.v6pcb != NULL); - udp_set_multicast_ttl(mdns_data.v6pcb, MDNS_TTL); - res = udp_bind(mdns_data.v6pcb, IP6_ADDR_ANY, MDNS_PORT); - LWIP_ASSERT("Failed to bind pcb", res == ERR_OK); - udp_recv(mdns_data.v6pcb, mdns_recv, &mdns_data); -#endif + udp_recv(mdns_pcb, mdns_recv, NULL); } /** From 52449e12c08cf639484cf9b2942484d0f6f9a0e8 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Sun, 14 Aug 2016 16:56:34 +0200 Subject: [PATCH 078/325] Forgot to save before committing... --- src/apps/mdns/mdns.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/apps/mdns/mdns.c b/src/apps/mdns/mdns.c index 935f0cd6..1481c743 100644 --- a/src/apps/mdns/mdns.c +++ b/src/apps/mdns/mdns.c @@ -1852,7 +1852,7 @@ mdns_resp_init(void) mdns_pcb = udp_new_ip_type(IPADDR_TYPE_ANY); LWIP_ASSERT("Failed to allocate pcb", mdns_pcb != NULL); udp_set_multicast_ttl(mdns_pcb, MDNS_TTL); - res = udp_bind(mdns_pcb, IP_ADDR_ANY, MDNS_PORT); + res = udp_bind(mdns_pcb, IP_ANY_TYPE, MDNS_PORT); LWIP_ASSERT("Failed to bind pcb", res == ERR_OK); udp_recv(mdns_pcb, mdns_recv, NULL); } From 39ac8e2c572a2a662a1deed712328bbf0f551f9e Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Sun, 14 Aug 2016 17:08:39 +0200 Subject: [PATCH 079/325] Remove some MDNS functions from documentation, they are only visible for unit tests --- src/apps/mdns/mdns.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/apps/mdns/mdns.c b/src/apps/mdns/mdns.c index 1481c743..5744d204 100644 --- a/src/apps/mdns/mdns.c +++ b/src/apps/mdns/mdns.c @@ -302,7 +302,6 @@ mdns_strncasecmp(const char* str1, const char* str2, size_t len) /** - * @ingroup mdns * Add a label part to a domain * @param domain The domain to add a label to * @param label The label to add, like <hostname>, 'local', 'com' or '' @@ -401,7 +400,6 @@ mdns_readname_loop(struct pbuf *p, u16_t offset, struct mdns_domain *domain, uns } /** - * @ingroup mdns * Read possibly compressed domain name from packet buffer * @param p The packet * @param offset start position of domain name in packet @@ -439,7 +437,6 @@ mdns_domain_debug_print(int debug, struct mdns_domain *domain) } /** - * @ingroup mdns * Return 1 if contents of domains match (case-insensitive) * @param a Domain name to compare 1 * @param b Domain name to compare 2 @@ -756,7 +753,6 @@ check_service(struct mdns_service *service, struct mdns_rr_info *rr) } /** - * @ingroup mdns * Return bytes needed to write before jump for best result of compressing supplied domain * against domain in outpacket starting at specified offset. * If a match is found, offset is updated to where to jump to From af48bec63c8be9725147015b90ce61b2b9c4ea5d Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Sun, 14 Aug 2016 17:12:01 +0200 Subject: [PATCH 080/325] Update MDNS docs after porting to dual-stack API --- doc/mdns.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/mdns.txt b/doc/mdns.txt index e3921359..699ccbfc 100644 --- a/doc/mdns.txt +++ b/doc/mdns.txt @@ -22,7 +22,7 @@ in lwipopts.h and add src/apps/mdns/mdns.c to your list of files to build. The max number of services supported per netif is defined by MDNS_MAX_SERVICES, default is 1. -Increase MEMP_NUM_UDP_PCB. MDNS needs one PCB for IPv4 and one for IPv6. +Increase MEMP_NUM_UDP_PCB. MDNS needs one PCB. MDNS with IPv4 requires LWIP_IGMP = 1, and preferably LWIP_AUTOIP = 1. MDNS with IPv6 requires LWIP_IPV6_MLD = 1, and that a link-local address is From c61c8f3766ae83abae998caf6bb72eec0acd948a Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Tue, 16 Aug 2016 08:08:06 +0200 Subject: [PATCH 081/325] Use udp_get_multicast_ttl/udp_set_multicast_ttl accessors where applicable --- src/api/sockets.c | 4 ++-- src/core/udp.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/api/sockets.c b/src/api/sockets.c index db90e16c..440c446e 100644 --- a/src/api/sockets.c +++ b/src/api/sockets.c @@ -2019,7 +2019,7 @@ lwip_getsockopt_impl(int s, int level, int optname, void *optval, socklen_t *opt if (NETCONNTYPE_GROUP(netconn_type(sock->conn)) != NETCONN_UDP) { return ENOPROTOOPT; } - *(u8_t*)optval = sock->conn->pcb.udp->mcast_ttl; + *(u8_t*)optval = udp_get_multicast_ttl(sock->conn->pcb.udp); LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IP, IP_MULTICAST_TTL) = %d\n", s, *(int *)optval)); break; @@ -2386,7 +2386,7 @@ lwip_setsockopt_impl(int s, int level, int optname, const void *optval, socklen_ #if LWIP_MULTICAST_TX_OPTIONS case IP_MULTICAST_TTL: LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB_TYPE(sock, optlen, u8_t, NETCONN_UDP); - sock->conn->pcb.udp->mcast_ttl = (u8_t)(*(const u8_t*)optval); + udp_set_multicast_ttl(sock->conn->pcb.udp, (u8_t)(*(const u8_t*)optval)); break; case IP_MULTICAST_IF: { diff --git a/src/core/udp.c b/src/core/udp.c index 1e7766fc..9fc35876 100644 --- a/src/core/udp.c +++ b/src/core/udp.c @@ -852,7 +852,7 @@ udp_sendto_if_src_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *d /* Determine TTL to use */ #if LWIP_MULTICAST_TX_OPTIONS - ttl = (ip_addr_ismulticast(dst_ip) ? pcb->mcast_ttl : pcb->ttl); + ttl = (ip_addr_ismulticast(dst_ip) ? udp_get_multicast_ttl(pcb) : pcb->ttl); #else /* LWIP_MULTICAST_TX_OPTIONS */ ttl = pcb->ttl; #endif /* LWIP_MULTICAST_TX_OPTIONS */ @@ -1134,7 +1134,7 @@ udp_new(void) memset(pcb, 0, sizeof(struct udp_pcb)); pcb->ttl = UDP_TTL; #if LWIP_MULTICAST_TX_OPTIONS - pcb->mcast_ttl = UDP_TTL; + udp_set_multicast_ttl(pcb, UDP_TTL); #endif /* LWIP_MULTICAST_TX_OPTIONS */ } return pcb; From 482a4d2ce940e49fd47213bc8700765fa3c78392 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Tue, 16 Aug 2016 08:09:19 +0200 Subject: [PATCH 082/325] MDNS: Correct setting TTL when IGMP is not enabled --- src/apps/mdns/mdns.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/apps/mdns/mdns.c b/src/apps/mdns/mdns.c index 5744d204..7c54bc55 100644 --- a/src/apps/mdns/mdns.c +++ b/src/apps/mdns/mdns.c @@ -359,12 +359,12 @@ mdns_readname_loop(struct pbuf *p, u16_t offset, struct mdns_domain *domain, uns offset++; if (jumpaddr >= SIZEOF_DNS_HDR && jumpaddr < p->tot_len) { u16_t res; - /* Recursive call, maximum depth will be checked */ + /* Recursive call, maximum depth will be checked */ res = mdns_readname_loop(p, jumpaddr, domain, depth + 1); /* Dont return offset since new bytes were not read (jumped to somewhere in packet) */ if (res == MDNS_READNAME_ERROR) { return res; - } + } } else { return MDNS_READNAME_ERROR; } @@ -1620,7 +1620,7 @@ mdns_handle_question(struct mdns_packet *pkt) reply.host_reverse_v6_replies &= ~rev_v6; if (reply.host_reverse_v6_replies == 0) { reply.host_replies &= ~REPLY_HOST_PTR_V6; - } + } } #endif } @@ -1686,26 +1686,26 @@ mdns_handle_question(struct mdns_packet *pkt) len = pbuf_copy_partial(pkt->pbuf, &field16, sizeof(field16), read_pos); if (len != sizeof(field16) || ntohs(field16) != SRV_PRIORITY) { break; - } + } read_pos += len; /* Check weight field */ len = pbuf_copy_partial(pkt->pbuf, &field16, sizeof(field16), read_pos); if (len != sizeof(field16) || ntohs(field16) != SRV_WEIGHT) { break; - } + } read_pos += len; /* Check port field */ len = pbuf_copy_partial(pkt->pbuf, &field16, sizeof(field16), read_pos); if (len != sizeof(field16) || ntohs(field16) != service->port) { break; - } + } read_pos += len; /* Check host field */ len = mdns_readname(pkt->pbuf, read_pos, &known_ans); mdns_build_host_domain(&my_ans, pkt->netif); if (len == MDNS_READNAME_ERROR || !mdns_domain_eq(&known_ans, &my_ans)) { break; - } + } LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: Skipping known answer: SRV\n")); reply.serv_replies[i] &= ~REPLY_SERVICE_SRV; } while (0); @@ -1847,7 +1847,11 @@ mdns_resp_init(void) mdns_pcb = udp_new_ip_type(IPADDR_TYPE_ANY); LWIP_ASSERT("Failed to allocate pcb", mdns_pcb != NULL); +#if LWIP_MULTICAST_TX_OPTIONS udp_set_multicast_ttl(mdns_pcb, MDNS_TTL); +#else + mdns_pcb->ttl = MDNS_TTL; +#endif res = udp_bind(mdns_pcb, IP_ANY_TYPE, MDNS_PORT); LWIP_ASSERT("Failed to bind pcb", res == ERR_OK); udp_recv(mdns_pcb, mdns_recv, NULL); From ab72ed85177406310211c4d666faf8314dfd58a2 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Tue, 16 Aug 2016 08:22:41 +0200 Subject: [PATCH 083/325] Fix options #include in mdns code --- src/apps/mdns/mdns.c | 46 ++++++++++++++++-------------------- src/include/lwip/apps/mdns.h | 2 +- 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/src/apps/mdns/mdns.c b/src/apps/mdns/mdns.c index 7c54bc55..8e29de63 100644 --- a/src/apps/mdns/mdns.c +++ b/src/apps/mdns/mdns.c @@ -1,6 +1,27 @@ /** * @file * MDNS responder implementation + * + * @defgroup mdns MDNS + * @ingroup apps + * + * RFC 6762 - Multicast DNS\n + * RFC 6763 - DNS-Based Service Discovery\n + * + * @verbinclude mdns.txt + * + * Things left to implement: + * ------------------------- + * + * - Probing/conflict resolution + * - Sending goodbye messages (zero ttl) + * - Checking that source address of unicast requests are on the same network + * - Limiting multicast responses to 1 per second per resource record + * - Fragmenting replies if required + * - Subscribe to netif address/link change events and act on them + * - Handling multi-packet known answers + * - Individual known answer detection for all local IPv6 addresses + * - Dynamic size of outgoing packet */ /* @@ -38,31 +59,6 @@ * */ -/** - * @defgroup mdns MDNS - * @ingroup apps - * - * RFC 6762 - Multicast DNS\n - * RFC 6763 - DNS-Based Service Discovery\n - * - * @verbinclude mdns.txt - * - * Things left to implement: - * ------------------------- - * - * - Probing/conflict resolution - * - Sending goodbye messages (zero ttl) - * - Checking that source address of unicast requests are on the same network - * - Limiting multicast responses to 1 per second per resource record - * - Fragmenting replies if required - * - Subscribe to netif address/link change events and act on them - * - Handling multi-packet known answers - * - Individual known answer detection for all local IPv6 addresses - * - Dynamic size of outgoing packet - */ - -#include "lwip/opt.h" - #include "lwip/apps/mdns.h" #include "lwip/netif.h" #include "lwip/udp.h" diff --git a/src/include/lwip/apps/mdns.h b/src/include/lwip/apps/mdns.h index 08fa5df7..2391f1dd 100644 --- a/src/include/lwip/apps/mdns.h +++ b/src/include/lwip/apps/mdns.h @@ -32,7 +32,7 @@ #ifndef LWIP_HDR_MDNS_H #define LWIP_HDR_MDNS_H -#include "lwip/opt.h" +#include "lwip/apps/mdns_opts.h" #include "lwip/netif.h" #if LWIP_MDNS From af6b707e9afd200f8bf9a1fc5a41fcf616cd91da Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Tue, 16 Aug 2016 08:28:59 +0200 Subject: [PATCH 084/325] mdns_opts.h: Add missing include lwip/opt.h --- src/include/lwip/apps/mdns_opts.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/include/lwip/apps/mdns_opts.h b/src/include/lwip/apps/mdns_opts.h index 710911fc..310ec38a 100644 --- a/src/include/lwip/apps/mdns_opts.h +++ b/src/include/lwip/apps/mdns_opts.h @@ -32,6 +32,9 @@ #ifndef LWIP_HDR_APPS_MDNS_OPTS_H #define LWIP_HDR_APPS_MDNS_OPTS_H + +#include "lwip/opt.h" + /** * @defgroup mdns_opts Options * @ingroup mdns From 858287fc3a6e058473152d1caab0126c1f6915fb Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Tue, 16 Aug 2016 08:33:16 +0200 Subject: [PATCH 085/325] MDNS: Fix several MSVC warnings --- src/apps/mdns/mdns.c | 48 ++++++++++++++++++------------------ src/include/lwip/apps/mdns.h | 6 ++--- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/apps/mdns/mdns.c b/src/apps/mdns/mdns.c index 8e29de63..e93e5efd 100644 --- a/src/apps/mdns/mdns.c +++ b/src/apps/mdns/mdns.c @@ -305,7 +305,7 @@ mdns_strncasecmp(const char* str1, const char* str2, size_t len) * @return ERR_OK on success, an err_t otherwise if label too long */ err_t -mdns_domain_add_label(struct mdns_domain *domain, const char *label, unsigned len) +mdns_domain_add_label(struct mdns_domain *domain, const char *label, u8_t len) { if (len > MDNS_LABEL_MAXLEN) { return ERR_VAL; @@ -496,7 +496,7 @@ static err_t mdns_build_reverse_v4_domain(struct mdns_domain *domain, const ip4_addr_t *addr) { int i; - int res; + err_t res; const u8_t *ptr; if (!domain || !addr) { return ERR_ARG; @@ -506,12 +506,12 @@ mdns_build_reverse_v4_domain(struct mdns_domain *domain, const ip4_addr_t *addr) for (i = sizeof(ip4_addr_t) - 1; i >= 0; i--) { char buf[4]; snprintf(buf, sizeof(buf), "%d", ptr[i]); - res = mdns_domain_add_label(domain, buf, strlen(buf)); + res = mdns_domain_add_label(domain, buf, (u8_t)strlen(buf)); LWIP_ERROR("mdns_build_reverse_v4_domain: Failed to add label", (res == ERR_OK), return res); } - res = mdns_domain_add_label(domain, REVERSE_PTR_V4_DOMAIN, strlen(REVERSE_PTR_V4_DOMAIN)); + res = mdns_domain_add_label(domain, REVERSE_PTR_V4_DOMAIN, (u8_t)strlen(REVERSE_PTR_V4_DOMAIN)); LWIP_ERROR("mdns_build_reverse_v4_domain: Failed to add label", (res == ERR_OK), return res); - res = mdns_domain_add_label(domain, REVERSE_PTR_TOPDOMAIN, strlen(REVERSE_PTR_TOPDOMAIN)); + res = mdns_domain_add_label(domain, REVERSE_PTR_TOPDOMAIN, (u8_t)strlen(REVERSE_PTR_TOPDOMAIN)); LWIP_ERROR("mdns_build_reverse_v4_domain: Failed to add label", (res == ERR_OK), return res); res = mdns_domain_add_label(domain, NULL, 0); LWIP_ERROR("mdns_build_reverse_v4_domain: Failed to add label", (res == ERR_OK), return res); @@ -532,7 +532,7 @@ static err_t mdns_build_reverse_v6_domain(struct mdns_domain *domain, const ip6_addr_t *addr) { int i; - int res; + err_t res; const u8_t *ptr; if (!domain || !addr) { return ERR_ARG; @@ -569,7 +569,7 @@ mdns_build_reverse_v6_domain(struct mdns_domain *domain, const ip6_addr_t *addr) static err_t mdns_add_dotlocal(struct mdns_domain *domain) { - err_t res = mdns_domain_add_label(domain, TOPDOMAIN_LOCAL, strlen(TOPDOMAIN_LOCAL)); + err_t res = mdns_domain_add_label(domain, TOPDOMAIN_LOCAL, (u8_t)strlen(TOPDOMAIN_LOCAL)); LWIP_ERROR("mdns_add_dotlocal: Failed to add label", (res == ERR_OK), return res); return mdns_domain_add_label(domain, NULL, 0); } @@ -587,7 +587,7 @@ mdns_build_host_domain(struct mdns_domain *domain, struct netif *netif) err_t res; memset(domain, 0, sizeof(struct mdns_domain)); LWIP_ERROR("mdns_resp_add_service: Not an mdns netif", (netif->mdns != NULL), return ERR_VAL); - res = mdns_domain_add_label(domain, netif->mdns->name, strlen(netif->mdns->name)); + res = mdns_domain_add_label(domain, netif->mdns->name, (u8_t)strlen(netif->mdns->name)); LWIP_ERROR("mdns_build_host_domain: Failed to add label", (res == ERR_OK), return res); return mdns_add_dotlocal(domain); } @@ -602,11 +602,11 @@ mdns_build_dnssd_domain(struct mdns_domain *domain) { err_t res; memset(domain, 0, sizeof(struct mdns_domain)); - res = mdns_domain_add_label(domain, "_services", strlen("_services")); + res = mdns_domain_add_label(domain, "_services", (u8_t)strlen("_services")); LWIP_ERROR("mdns_build_dnssd_domain: Failed to add label", (res == ERR_OK), return res); - res = mdns_domain_add_label(domain, "_dns-sd", strlen("_dns-sd")); + res = mdns_domain_add_label(domain, "_dns-sd", (u8_t)strlen("_dns-sd")); LWIP_ERROR("mdns_build_dnssd_domain: Failed to add label", (res == ERR_OK), return res); - res = mdns_domain_add_label(domain, dnssd_protos[DNSSD_PROTO_UDP], strlen(dnssd_protos[DNSSD_PROTO_UDP])); + res = mdns_domain_add_label(domain, dnssd_protos[DNSSD_PROTO_UDP], (u8_t)strlen(dnssd_protos[DNSSD_PROTO_UDP])); LWIP_ERROR("mdns_build_dnssd_domain: Failed to add label", (res == ERR_OK), return res); return mdns_add_dotlocal(domain); } @@ -626,12 +626,12 @@ mdns_build_service_domain(struct mdns_domain *domain, struct mdns_service *servi err_t res; memset(domain, 0, sizeof(struct mdns_domain)); if (include_name) { - res = mdns_domain_add_label(domain, service->name, strlen(service->name)); + res = mdns_domain_add_label(domain, service->name, (u8_t)strlen(service->name)); LWIP_ERROR("mdns_build_service_domain: Failed to add label", (res == ERR_OK), return res); } - res = mdns_domain_add_label(domain, service->service, strlen(service->service)); + res = mdns_domain_add_label(domain, service->service, (u8_t)strlen(service->service)); LWIP_ERROR("mdns_build_service_domain: Failed to add label", (res == ERR_OK), return res); - res = mdns_domain_add_label(domain, dnssd_protos[service->proto], strlen(dnssd_protos[service->proto])); + res = mdns_domain_add_label(domain, dnssd_protos[service->proto], (u8_t)strlen(dnssd_protos[service->proto])); LWIP_ERROR("mdns_build_service_domain: Failed to add label", (res == ERR_OK), return res); return mdns_add_dotlocal(domain); } @@ -760,7 +760,7 @@ check_service(struct mdns_service *service, struct mdns_rr_info *rr) * If compression can not be done against this previous domain name, the full new * domain length is returned. */ -u8_t +u16_t mdns_compress_domain(struct pbuf *pbuf, u16_t *offset, struct mdns_domain *domain) { struct mdns_domain target; @@ -775,14 +775,14 @@ mdns_compress_domain(struct pbuf *pbuf, u16_t *offset, struct mdns_domain *domai if (target_end == MDNS_READNAME_ERROR) { return domain->length; } - target_len = target_end - *offset; + target_len = (u8_t)(target_end - *offset); ptr = domain->name; while (writelen < domain->length) { - u8_t domainlen = domain->length - writelen; + u8_t domainlen = (u8_t)(domain->length - writelen); u8_t labellen; if (domainlen <= target.length && domainlen > DOMAIN_JUMP_SIZE) { /* Compare domains if target is long enough, and we have enough left of the domain */ - u8_t targetpos = target.length - domainlen; + u8_t targetpos = (u8_t)(target.length - domainlen); if ((targetpos + DOMAIN_JUMP_SIZE) >= target_len) { /* We are checking at or beyond a jump in the original, stop looking */ break; @@ -814,7 +814,7 @@ mdns_write_domain(struct mdns_outpacket *outpkt, struct mdns_domain *domain) { int i; err_t res; - u8_t writelen = domain->length; + u16_t writelen = domain->length; u16_t jump_offset = 0; u16_t jump; @@ -822,7 +822,7 @@ mdns_write_domain(struct mdns_outpacket *outpkt, struct mdns_domain *domain) for (i = 0; i < NUM_DOMAIN_OFFSETS; ++i) { u16_t offset = outpkt->domain_offsets[i]; if (offset) { - u8_t len = mdns_compress_domain(outpkt->pbuf, &offset, domain); + u16_t len = mdns_compress_domain(outpkt->pbuf, &offset, domain); if (len < writelen) { writelen = len; jump_offset = offset; @@ -963,7 +963,7 @@ mdns_add_answer(struct mdns_outpacket *reply, struct mdns_domain *domain, u16_t /* Worst case calculation. Domain strings might be compressed */ answer_len = domain->length + sizeof(type) + sizeof(klass) + sizeof(ttl) + sizeof(field16)/*rd_length*/; if (buf) { - answer_len += buf_length; + answer_len += (u16_t)buf_length; } if (answer_domain) { answer_len += answer_domain->length; @@ -991,11 +991,11 @@ mdns_add_answer(struct mdns_outpacket *reply, struct mdns_domain *domain, u16_t if (buf) { /* Write static data */ - res = pbuf_take_at(reply->pbuf, buf, buf_length, reply->write_offset); + res = pbuf_take_at(reply->pbuf, buf, (u16_t)buf_length, reply->write_offset); if (res != ERR_OK) { return res; } - reply->write_offset += buf_length; + reply->write_offset += (u16_t)buf_length; } if (answer_domain) { @@ -2016,7 +2016,7 @@ mdns_resp_add_service(struct netif *netif, const char *name, const char *service * @return ERR_OK if the string was added to the reply, an err_t otherwise */ err_t -mdns_resp_add_service_txtitem(struct mdns_service *service, const char *txt, int txt_len) +mdns_resp_add_service_txtitem(struct mdns_service *service, const char *txt, u8_t txt_len) { LWIP_ASSERT("mdns_resp_add_service: service != NULL", service); diff --git a/src/include/lwip/apps/mdns.h b/src/include/lwip/apps/mdns.h index 2391f1dd..0214d858 100644 --- a/src/include/lwip/apps/mdns.h +++ b/src/include/lwip/apps/mdns.h @@ -52,7 +52,7 @@ err_t mdns_resp_remove_netif(struct netif *netif); typedef void (*service_get_txt_fn_t)(struct mdns_service *service, void *txt_userdata); err_t mdns_resp_add_service(struct netif *netif, const char *name, const char *service, u16_t proto, u16_t port, u32_t dns_ttl, service_get_txt_fn_t txt_fn, void *txt_userdata); -err_t mdns_resp_add_service_txtitem(struct mdns_service *service, const char *txt, int txt_len); +err_t mdns_resp_add_service_txtitem(struct mdns_service *service, const char *txt, u8_t txt_len); /* Domain struct and methods - visible for unit tests */ @@ -68,10 +68,10 @@ struct mdns_domain { u8_t skip_compression; }; -err_t mdns_domain_add_label(struct mdns_domain *domain, const char *label, unsigned len); +err_t mdns_domain_add_label(struct mdns_domain *domain, const char *label, u8_t len); u16_t mdns_readname(struct pbuf *p, u16_t offset, struct mdns_domain *domain); int mdns_domain_eq(struct mdns_domain *a, struct mdns_domain *b); -u8_t mdns_compress_domain(struct pbuf *pbuf, u16_t *offset, struct mdns_domain *domain); +u16_t mdns_compress_domain(struct pbuf *pbuf, u16_t *offset, struct mdns_domain *domain); #endif /* LWIP_MDNS */ From fec657bb382d7f05e33f07995d84d13f58390ded Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Tue, 16 Aug 2016 09:33:53 +0200 Subject: [PATCH 086/325] MDNS: Substitute a few strlens by sizeof() --- src/apps/mdns/mdns.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/apps/mdns/mdns.c b/src/apps/mdns/mdns.c index e93e5efd..0f54b395 100644 --- a/src/apps/mdns/mdns.c +++ b/src/apps/mdns/mdns.c @@ -505,13 +505,13 @@ mdns_build_reverse_v4_domain(struct mdns_domain *domain, const ip4_addr_t *addr) ptr = (const u8_t *) addr; for (i = sizeof(ip4_addr_t) - 1; i >= 0; i--) { char buf[4]; - snprintf(buf, sizeof(buf), "%d", ptr[i]); - res = mdns_domain_add_label(domain, buf, (u8_t)strlen(buf)); + size_t len = snprintf(buf, sizeof(buf), "%d", ptr[i]); + res = mdns_domain_add_label(domain, buf, (u8_t)len); LWIP_ERROR("mdns_build_reverse_v4_domain: Failed to add label", (res == ERR_OK), return res); } - res = mdns_domain_add_label(domain, REVERSE_PTR_V4_DOMAIN, (u8_t)strlen(REVERSE_PTR_V4_DOMAIN)); + res = mdns_domain_add_label(domain, REVERSE_PTR_V4_DOMAIN, (u8_t)(sizeof(REVERSE_PTR_V4_DOMAIN)-1)); LWIP_ERROR("mdns_build_reverse_v4_domain: Failed to add label", (res == ERR_OK), return res); - res = mdns_domain_add_label(domain, REVERSE_PTR_TOPDOMAIN, (u8_t)strlen(REVERSE_PTR_TOPDOMAIN)); + res = mdns_domain_add_label(domain, REVERSE_PTR_TOPDOMAIN, (u8_t)(sizeof(REVERSE_PTR_TOPDOMAIN)-1)); LWIP_ERROR("mdns_build_reverse_v4_domain: Failed to add label", (res == ERR_OK), return res); res = mdns_domain_add_label(domain, NULL, 0); LWIP_ERROR("mdns_build_reverse_v4_domain: Failed to add label", (res == ERR_OK), return res); @@ -554,9 +554,9 @@ mdns_build_reverse_v6_domain(struct mdns_domain *domain, const ip6_addr_t *addr) byte >>= 4; } } - res = mdns_domain_add_label(domain, REVERSE_PTR_V6_DOMAIN, strlen(REVERSE_PTR_V6_DOMAIN)); + res = mdns_domain_add_label(domain, REVERSE_PTR_V6_DOMAIN, (u8_t)(sizeof(REVERSE_PTR_V6_DOMAIN)-1)); LWIP_ERROR("mdns_build_reverse_v6_domain: Failed to add label", (res == ERR_OK), return res); - res = mdns_domain_add_label(domain, REVERSE_PTR_TOPDOMAIN, strlen(REVERSE_PTR_TOPDOMAIN)); + res = mdns_domain_add_label(domain, REVERSE_PTR_TOPDOMAIN, (u8_t)(sizeof(REVERSE_PTR_TOPDOMAIN)-1)); LWIP_ERROR("mdns_build_reverse_v6_domain: Failed to add label", (res == ERR_OK), return res); res = mdns_domain_add_label(domain, NULL, 0); LWIP_ERROR("mdns_build_reverse_v6_domain: Failed to add label", (res == ERR_OK), return res); @@ -569,7 +569,7 @@ mdns_build_reverse_v6_domain(struct mdns_domain *domain, const ip6_addr_t *addr) static err_t mdns_add_dotlocal(struct mdns_domain *domain) { - err_t res = mdns_domain_add_label(domain, TOPDOMAIN_LOCAL, (u8_t)strlen(TOPDOMAIN_LOCAL)); + err_t res = mdns_domain_add_label(domain, TOPDOMAIN_LOCAL, (u8_t)(sizeof(TOPDOMAIN_LOCAL)-1)); LWIP_ERROR("mdns_add_dotlocal: Failed to add label", (res == ERR_OK), return res); return mdns_domain_add_label(domain, NULL, 0); } @@ -602,11 +602,11 @@ mdns_build_dnssd_domain(struct mdns_domain *domain) { err_t res; memset(domain, 0, sizeof(struct mdns_domain)); - res = mdns_domain_add_label(domain, "_services", (u8_t)strlen("_services")); + res = mdns_domain_add_label(domain, "_services", (u8_t)(sizeof("_services")-1)); LWIP_ERROR("mdns_build_dnssd_domain: Failed to add label", (res == ERR_OK), return res); - res = mdns_domain_add_label(domain, "_dns-sd", (u8_t)strlen("_dns-sd")); + res = mdns_domain_add_label(domain, "_dns-sd", (u8_t)(sizeof("_dns-sd")-1)); LWIP_ERROR("mdns_build_dnssd_domain: Failed to add label", (res == ERR_OK), return res); - res = mdns_domain_add_label(domain, dnssd_protos[DNSSD_PROTO_UDP], (u8_t)strlen(dnssd_protos[DNSSD_PROTO_UDP])); + res = mdns_domain_add_label(domain, dnssd_protos[DNSSD_PROTO_UDP], (u8_t)(sizeof(dnssd_protos[DNSSD_PROTO_UDP])-1)); LWIP_ERROR("mdns_build_dnssd_domain: Failed to add label", (res == ERR_OK), return res); return mdns_add_dotlocal(domain); } @@ -631,7 +631,7 @@ mdns_build_service_domain(struct mdns_domain *domain, struct mdns_service *servi } res = mdns_domain_add_label(domain, service->service, (u8_t)strlen(service->service)); LWIP_ERROR("mdns_build_service_domain: Failed to add label", (res == ERR_OK), return res); - res = mdns_domain_add_label(domain, dnssd_protos[service->proto], (u8_t)strlen(dnssd_protos[service->proto])); + res = mdns_domain_add_label(domain, dnssd_protos[service->proto], (u8_t)(sizeof((dnssd_protos[service->proto])-1))); LWIP_ERROR("mdns_build_service_domain: Failed to add label", (res == ERR_OK), return res); return mdns_add_dotlocal(domain); } From 02d51e3ac55e543c07888ae20f97f028ad2f67bd Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Tue, 16 Aug 2016 09:46:19 +0200 Subject: [PATCH 087/325] Add missing file doxygen header in two mdns files --- src/include/lwip/apps/mdns.h | 7 ++++++- src/include/lwip/apps/mdns_opts.h | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/include/lwip/apps/mdns.h b/src/include/lwip/apps/mdns.h index 0214d858..3b902fc9 100644 --- a/src/include/lwip/apps/mdns.h +++ b/src/include/lwip/apps/mdns.h @@ -1,4 +1,9 @@ -/* +/** + * @file + * MDNS responder + */ + + /* * Copyright (c) 2015 Verisure Innovation AB * All rights reserved. * diff --git a/src/include/lwip/apps/mdns_opts.h b/src/include/lwip/apps/mdns_opts.h index 310ec38a..e34308e6 100644 --- a/src/include/lwip/apps/mdns_opts.h +++ b/src/include/lwip/apps/mdns_opts.h @@ -1,4 +1,9 @@ -/* +/** + * @file + * MDNS responder + */ + + /* * Copyright (c) 2015 Verisure Innovation AB * All rights reserved. * From efb7b3d5f881bb21be297ffb37479012a2fc3836 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Wed, 17 Aug 2016 12:07:38 +0200 Subject: [PATCH 088/325] Rename LWIP_MDNS to LWIP_MDNS_RESPONDER --- src/apps/mdns/mdns.c | 4 ++-- src/core/netif.c | 4 ++-- src/include/lwip/apps/mdns.h | 4 ++-- src/include/lwip/apps/mdns_opts.h | 8 ++++---- src/include/lwip/netif.h | 6 +++--- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/apps/mdns/mdns.c b/src/apps/mdns/mdns.c index 0f54b395..55fe0193 100644 --- a/src/apps/mdns/mdns.c +++ b/src/apps/mdns/mdns.c @@ -69,7 +69,7 @@ #include #include -#if LWIP_MDNS +#if LWIP_MDNS_RESPONDER #if (LWIP_IPV4 && !LWIP_IGMP) #error "If you want to use MDNS with IPv4, you have to define LWIP_IGMP=1 in your lwipopts.h" @@ -2024,4 +2024,4 @@ mdns_resp_add_service_txtitem(struct mdns_service *service, const char *txt, u8_ return mdns_domain_add_label(&service->txtdata, txt, txt_len); } -#endif /* LWIP_MDNS */ +#endif /* LWIP_MDNS_RESPONDER */ diff --git a/src/core/netif.c b/src/core/netif.c index 2d2abf59..685abaaa 100644 --- a/src/core/netif.c +++ b/src/core/netif.c @@ -247,10 +247,10 @@ netif_add(struct netif *netif, /* netif not under AutoIP control by default */ netif->autoip = NULL; #endif /* LWIP_AUTOIP */ -#if LWIP_MDNS +#if LWIP_MDNS_RESPONDER /* netif not using MDNS by default */ netif->mdns = NULL; -#endif /* LWIP_MDNS */ +#endif /* LWIP_MDNS_RESPONDER */ #if LWIP_IPV6_AUTOCONFIG /* IPv6 address autoconfiguration not enabled by default */ netif->ip6_autoconfig_enabled = 0; diff --git a/src/include/lwip/apps/mdns.h b/src/include/lwip/apps/mdns.h index 3b902fc9..f49cdf9f 100644 --- a/src/include/lwip/apps/mdns.h +++ b/src/include/lwip/apps/mdns.h @@ -40,7 +40,7 @@ #include "lwip/apps/mdns_opts.h" #include "lwip/netif.h" -#if LWIP_MDNS +#if LWIP_MDNS_RESPONDER #define DNSSD_PROTO_UDP 0 #define DNSSD_PROTO_TCP 1 @@ -78,6 +78,6 @@ u16_t mdns_readname(struct pbuf *p, u16_t offset, struct mdns_domain *domain); int mdns_domain_eq(struct mdns_domain *a, struct mdns_domain *b); u16_t mdns_compress_domain(struct pbuf *pbuf, u16_t *offset, struct mdns_domain *domain); -#endif /* LWIP_MDNS */ +#endif /* LWIP_MDNS_RESPONDER */ #endif /* LWIP_HDR_MDNS_H */ diff --git a/src/include/lwip/apps/mdns_opts.h b/src/include/lwip/apps/mdns_opts.h index e34308e6..2112e803 100644 --- a/src/include/lwip/apps/mdns_opts.h +++ b/src/include/lwip/apps/mdns_opts.h @@ -47,12 +47,12 @@ */ /** - * LWIP_MDNS==1: Turn on multicast DNS module. UDP must be available for MDNS + * LWIP_MDNS_RESPONDER==1: Turn on multicast DNS module. UDP must be available for MDNS * transport. IGMP is needed for IPv4 multicast. */ -#ifndef LWIP_MDNS -#define LWIP_MDNS 0 -#endif /* LWIP_MDNS */ +#ifndef LWIP_MDNS_RESPONDER +#define LWIP_MDNS_RESPONDER 0 +#endif /* LWIP_MDNS_RESPONDER */ /** The maximum number of services per netif */ #ifndef MDNS_MAX_SERVICES diff --git a/src/include/lwip/netif.h b/src/include/lwip/netif.h index 156ceafb..5a5d87af 100644 --- a/src/include/lwip/netif.h +++ b/src/include/lwip/netif.h @@ -59,7 +59,7 @@ struct autoip; #if LWIP_IPV6_DHCP6 struct dhcp6; #endif /* LWIP_IPV6_DHCP6 */ -#if LWIP_MDNS +#if LWIP_MDNS_RESPONDER struct mdns_host; #endif @@ -259,10 +259,10 @@ struct netif { /** the AutoIP client state information for this netif */ struct autoip *autoip; #endif -#if LWIP_MDNS +#if LWIP_MDNS_RESPONDER /** Interface-specific info for multicast DNS */ struct mdns_host *mdns; -#endif /* LWIP_MDNS */ +#endif /* LWIP_MDNS_RESPONDER */ #if LWIP_IPV6_AUTOCONFIG /** is this netif enabled for IPv6 autoconfiguration */ u8_t ip6_autoconfig_enabled; From 2a90f33757995799ef171061eea71581cd4894be Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Wed, 17 Aug 2016 12:32:33 +0200 Subject: [PATCH 089/325] MDNS responder: two functions can take struct mdns_host instead of netif as argument --- src/apps/mdns/mdns.c | 31 +++++++++++++++---------------- src/include/lwip/apps/mdns_opts.h | 2 +- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/apps/mdns/mdns.c b/src/apps/mdns/mdns.c index 55fe0193..2f7b1411 100644 --- a/src/apps/mdns/mdns.c +++ b/src/apps/mdns/mdns.c @@ -577,17 +577,16 @@ mdns_add_dotlocal(struct mdns_domain *domain) /** * Build the .local. domain name * @param domain Where to write the domain name - * @param netif The network interface to use, its MDNS struct will be referenced to - * get the hostname. + * @param mdns TMDNS netif descriptor. * @return ERR_OK if domain .local. was written, an err_t otherwise */ static err_t -mdns_build_host_domain(struct mdns_domain *domain, struct netif *netif) +mdns_build_host_domain(struct mdns_domain *domain, struct mdns_host *mdns) { err_t res; memset(domain, 0, sizeof(struct mdns_domain)); - LWIP_ERROR("mdns_resp_add_service: Not an mdns netif", (netif->mdns != NULL), return ERR_VAL); - res = mdns_domain_add_label(domain, netif->mdns->name, (u8_t)strlen(netif->mdns->name)); + LWIP_ERROR("mdns_resp_add_service: Not an mdns netif", (mdns != NULL), return ERR_VAL); + res = mdns_domain_add_label(domain, mdns->name, (u8_t)strlen(mdns->name)); LWIP_ERROR("mdns_build_host_domain: Failed to add label", (res == ERR_OK), return res); return mdns_add_dotlocal(domain); } @@ -683,7 +682,7 @@ check_host(struct netif *netif, struct mdns_rr_info *rr, u8_t *reverse_v6_reply) #endif } - res = mdns_build_host_domain(&mydomain, netif); + res = mdns_build_host_domain(&mydomain, netif->mdns); /* Handle requests for our hostname */ if (res == ERR_OK && mdns_domain_eq(&rr->domain, &mydomain)) { /* TODO return NSEC if unsupported protocol requested */ @@ -1147,7 +1146,7 @@ static err_t mdns_add_a_answer(struct mdns_outpacket *reply, u16_t cache_flush, struct netif *netif) { struct mdns_domain host; - mdns_build_host_domain(&host, netif); + mdns_build_host_domain(&host, netif->mdns); LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: Responding with A record\n")); return mdns_add_answer(reply, &host, DNS_RRTYPE_A, DNS_RRCLASS_IN, cache_flush, netif->mdns->dns_ttl, (const u8_t *) netif_ip4_addr(netif), sizeof(ip4_addr_t), NULL); } @@ -1157,7 +1156,7 @@ static err_t mdns_add_hostv4_ptr_answer(struct mdns_outpacket *reply, u16_t cache_flush, struct netif *netif) { struct mdns_domain host, revhost; - mdns_build_host_domain(&host, netif); + mdns_build_host_domain(&host, netif->mdns); mdns_build_reverse_v4_domain(&revhost, netif_ip4_addr(netif)); LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: Responding with v4 PTR record\n")); return mdns_add_answer(reply, &revhost, DNS_RRTYPE_PTR, DNS_RRCLASS_IN, cache_flush, netif->mdns->dns_ttl, NULL, 0, &host); @@ -1170,7 +1169,7 @@ static err_t mdns_add_aaaa_answer(struct mdns_outpacket *reply, u16_t cache_flush, struct netif *netif, int addrindex) { struct mdns_domain host; - mdns_build_host_domain(&host, netif); + mdns_build_host_domain(&host, netif->mdns); LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: Responding with AAAA record\n")); return mdns_add_answer(reply, &host, DNS_RRTYPE_AAAA, DNS_RRCLASS_IN, cache_flush, netif->mdns->dns_ttl, (const u8_t *) netif_ip6_addr(netif, addrindex), sizeof(ip6_addr_t), NULL); } @@ -1180,7 +1179,7 @@ static err_t mdns_add_hostv6_ptr_answer(struct mdns_outpacket *reply, u16_t cache_flush, struct netif *netif, int addrindex) { struct mdns_domain host, revhost; - mdns_build_host_domain(&host, netif); + mdns_build_host_domain(&host, netif->mdns); mdns_build_reverse_v6_domain(&revhost, netif_ip6_addr(netif, addrindex)); LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: Responding with v6 PTR record\n")); return mdns_add_answer(reply, &revhost, DNS_RRTYPE_PTR, DNS_RRCLASS_IN, cache_flush, netif->mdns->dns_ttl, NULL, 0, &host); @@ -1211,12 +1210,12 @@ mdns_add_servicename_ptr_answer(struct mdns_outpacket *reply, struct mdns_servic /** Write a SRV RR to outpacket */ static err_t -mdns_add_srv_answer(struct mdns_outpacket *reply, u16_t cache_flush, struct netif *netif, struct mdns_service *service) +mdns_add_srv_answer(struct mdns_outpacket *reply, u16_t cache_flush, struct mdns_host *mdns, struct mdns_service *service) { struct mdns_domain service_instance, srvhost; u16_t srvdata[3]; mdns_build_service_domain(&service_instance, service, 1); - mdns_build_host_domain(&srvhost, netif); + mdns_build_host_domain(&srvhost, mdns); if (reply->legacy_query) { /* RFC 6762 section 18.14: * In legacy unicast responses generated to answer legacy queries, @@ -1359,7 +1358,7 @@ mdns_send_outpacket(struct mdns_outpacket *outpkt) } if (outpkt->serv_replies[i] & REPLY_SERVICE_SRV) { - res = mdns_add_srv_answer(outpkt, outpkt->cache_flush, outpkt->netif, service); + res = mdns_add_srv_answer(outpkt, outpkt->cache_flush, outpkt->netif->mdns, service); if (res != ERR_OK) { goto cleanup; } @@ -1386,7 +1385,7 @@ mdns_send_outpacket(struct mdns_outpacket *outpkt) /* Our service instance requested, include SRV & TXT * if they are already not requested. */ if (!(outpkt->serv_replies[i] & REPLY_SERVICE_SRV)) { - res = mdns_add_srv_answer(outpkt, outpkt->cache_flush, outpkt->netif, service); + res = mdns_add_srv_answer(outpkt, outpkt->cache_flush, outpkt->netif->mdns, service); if (res != ERR_OK) { goto cleanup; } @@ -1602,7 +1601,7 @@ mdns_handle_question(struct mdns_packet *pkt) struct mdns_domain known_ans, my_ans; u16_t len; len = mdns_readname(pkt->pbuf, ans.rd_offset, &known_ans); - res = mdns_build_host_domain(&my_ans, pkt->netif); + res = mdns_build_host_domain(&my_ans, pkt->netif->mdns); if (len != MDNS_READNAME_ERROR && res == ERR_OK && mdns_domain_eq(&known_ans, &my_ans)) { #if LWIP_IPV4 if (match & REPLY_HOST_PTR_V4) { @@ -1698,7 +1697,7 @@ mdns_handle_question(struct mdns_packet *pkt) read_pos += len; /* Check host field */ len = mdns_readname(pkt->pbuf, read_pos, &known_ans); - mdns_build_host_domain(&my_ans, pkt->netif); + mdns_build_host_domain(&my_ans, pkt->netif->mdns); if (len == MDNS_READNAME_ERROR || !mdns_domain_eq(&known_ans, &my_ans)) { break; } diff --git a/src/include/lwip/apps/mdns_opts.h b/src/include/lwip/apps/mdns_opts.h index 2112e803..7a65a2dc 100644 --- a/src/include/lwip/apps/mdns_opts.h +++ b/src/include/lwip/apps/mdns_opts.h @@ -51,7 +51,7 @@ * transport. IGMP is needed for IPv4 multicast. */ #ifndef LWIP_MDNS_RESPONDER -#define LWIP_MDNS_RESPONDER 0 +#define LWIP_MDNS_RESPONDER 0 #endif /* LWIP_MDNS_RESPONDER */ /** The maximum number of services per netif */ From 93b286e5085de6ad77dc85e0a359300f56926263 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Wed, 17 Aug 2016 16:03:42 +0200 Subject: [PATCH 090/325] Also rename LWIP_MDNS to LWIP_MDNS_RESPONDER in unit tests... --- test/unit/lwipopts.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/lwipopts.h b/test/unit/lwipopts.h index 5647e3e3..d826042a 100644 --- a/test/unit/lwipopts.h +++ b/test/unit/lwipopts.h @@ -53,7 +53,7 @@ /* Enable IGMP and MDNS for MDNS tests */ #define LWIP_IGMP 1 -#define LWIP_MDNS 1 +#define LWIP_MDNS_RESPONDER 1 /* Minimal changes to opt.h required for etharp unit tests: */ #define ETHARP_SUPPORT_STATIC_ENTRIES 1 From c28fb298b7048e6bd36fe8ab6711ed743abfcc94 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Wed, 17 Aug 2016 16:37:15 +0200 Subject: [PATCH 091/325] Introduce an API to store arbitrary data pointers in struct netif Let MDNS to use the new API TODO: AutoIP, DHCP --- src/apps/mdns/mdns.c | 74 +++++++++++++++++++++++----------------- src/core/netif.c | 27 ++++++++++++--- src/include/lwip/netif.h | 15 ++++---- src/include/lwip/opt.h | 8 +++++ 4 files changed, 81 insertions(+), 43 deletions(-) diff --git a/src/apps/mdns/mdns.c b/src/apps/mdns/mdns.c index 2f7b1411..7e28985b 100644 --- a/src/apps/mdns/mdns.c +++ b/src/apps/mdns/mdns.c @@ -103,6 +103,7 @@ static const ip_addr_t v6group = IPADDR6_INIT(PP_HTONL(0xFF020000UL), PP_HTONL(0 #define DOMAIN_JUMP_SIZE 2 #define DOMAIN_JUMP 0xc000 +static u8_t mdns_netif_client_id; static struct udp_pcb *mdns_pcb; #define TOPDOMAIN_LOCAL "local" @@ -682,7 +683,7 @@ check_host(struct netif *netif, struct mdns_rr_info *rr, u8_t *reverse_v6_reply) #endif } - res = mdns_build_host_domain(&mydomain, netif->mdns); + res = mdns_build_host_domain(&mydomain, (struct mdns_host*)netif->client_data[mdns_netif_client_id]); /* Handle requests for our hostname */ if (res == ERR_OK && mdns_domain_eq(&rr->domain, &mydomain)) { /* TODO return NSEC if unsupported protocol requested */ @@ -1146,9 +1147,9 @@ static err_t mdns_add_a_answer(struct mdns_outpacket *reply, u16_t cache_flush, struct netif *netif) { struct mdns_domain host; - mdns_build_host_domain(&host, netif->mdns); + mdns_build_host_domain(&host, (struct mdns_host*)netif->client_data[mdns_netif_client_id]); LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: Responding with A record\n")); - return mdns_add_answer(reply, &host, DNS_RRTYPE_A, DNS_RRCLASS_IN, cache_flush, netif->mdns->dns_ttl, (const u8_t *) netif_ip4_addr(netif), sizeof(ip4_addr_t), NULL); + return mdns_add_answer(reply, &host, DNS_RRTYPE_A, DNS_RRCLASS_IN, cache_flush, ((struct mdns_host*)netif->client_data[mdns_netif_client_id])->dns_ttl, (const u8_t *) netif_ip4_addr(netif), sizeof(ip4_addr_t), NULL); } /** Write a 4.3.2.1.in-addr.arpa -> hostname.local PTR RR to outpacket */ @@ -1156,10 +1157,10 @@ static err_t mdns_add_hostv4_ptr_answer(struct mdns_outpacket *reply, u16_t cache_flush, struct netif *netif) { struct mdns_domain host, revhost; - mdns_build_host_domain(&host, netif->mdns); + mdns_build_host_domain(&host, (struct mdns_host*)netif->client_data[mdns_netif_client_id]); mdns_build_reverse_v4_domain(&revhost, netif_ip4_addr(netif)); LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: Responding with v4 PTR record\n")); - return mdns_add_answer(reply, &revhost, DNS_RRTYPE_PTR, DNS_RRCLASS_IN, cache_flush, netif->mdns->dns_ttl, NULL, 0, &host); + return mdns_add_answer(reply, &revhost, DNS_RRTYPE_PTR, DNS_RRCLASS_IN, cache_flush, ((struct mdns_host*)netif->client_data[mdns_netif_client_id])->dns_ttl, NULL, 0, &host); } #endif @@ -1286,6 +1287,7 @@ mdns_send_outpacket(struct mdns_outpacket *outpkt) struct mdns_service *service; err_t res; int i; + struct mdns_host* mdns = (struct mdns_host*)outpkt->netif->client_data[mdns_netif_client_id]; /* Write answers to host questions */ #if LWIP_IPV4 @@ -1336,7 +1338,7 @@ mdns_send_outpacket(struct mdns_outpacket *outpkt) /* Write answers to service questions */ for (i = 0; i < MDNS_MAX_SERVICES; ++i) { - service = outpkt->netif->mdns->services[i]; + service = mdns->services[i]; if (!service) { continue; } @@ -1358,7 +1360,7 @@ mdns_send_outpacket(struct mdns_outpacket *outpkt) } if (outpkt->serv_replies[i] & REPLY_SERVICE_SRV) { - res = mdns_add_srv_answer(outpkt, outpkt->cache_flush, outpkt->netif->mdns, service); + res = mdns_add_srv_answer(outpkt, outpkt->cache_flush, mdns, service); if (res != ERR_OK) { goto cleanup; } @@ -1376,7 +1378,7 @@ mdns_send_outpacket(struct mdns_outpacket *outpkt) /* All answers written, add additional RRs */ for (i = 0; i < MDNS_MAX_SERVICES; ++i) { - service = outpkt->netif->mdns->services[i]; + service = mdns->services[i]; if (!service) { continue; } @@ -1385,7 +1387,7 @@ mdns_send_outpacket(struct mdns_outpacket *outpkt) /* Our service instance requested, include SRV & TXT * if they are already not requested. */ if (!(outpkt->serv_replies[i] & REPLY_SERVICE_SRV)) { - res = mdns_add_srv_answer(outpkt, outpkt->cache_flush, outpkt->netif->mdns, service); + res = mdns_add_srv_answer(outpkt, outpkt->cache_flush, mdns, service); if (res != ERR_OK) { goto cleanup; } @@ -1485,6 +1487,7 @@ mdns_announce(struct netif *netif, const ip_addr_t *destination) { struct mdns_outpacket announce; int i; + struct mdns_host* mdns = (struct mdns_host*)netif->client_data[mdns_netif_client_id]; memset(&announce, 0, sizeof(announce)); announce.netif = netif; @@ -1499,7 +1502,7 @@ mdns_announce(struct netif *netif, const ip_addr_t *destination) #endif for (i = 0; i < MDNS_MAX_SERVICES; i++) { - struct mdns_service *serv = netif->mdns->services[i]; + struct mdns_service *serv = mdns->services[i]; if (serv) { announce.serv_replies[i] = REPLY_SERVICE_TYPE_PTR | REPLY_SERVICE_NAME_PTR | REPLY_SERVICE_SRV | REPLY_SERVICE_TXT; @@ -1525,6 +1528,7 @@ mdns_handle_question(struct mdns_packet *pkt) int replies = 0; int i; err_t res; + struct mdns_host* mdns = (struct mdns_host*)pkt->netif->client_data[mdns_netif_client_id]; mdns_init_outpacket(&reply, pkt); @@ -1550,7 +1554,7 @@ mdns_handle_question(struct mdns_packet *pkt) replies |= reply.host_replies; for (i = 0; i < MDNS_MAX_SERVICES; ++i) { - service = pkt->netif->mdns->services[i]; + service = mdns->services[i]; if (!service) { continue; } @@ -1591,7 +1595,7 @@ mdns_handle_question(struct mdns_packet *pkt) rev_v6 = 0; match = reply.host_replies & check_host(pkt->netif, &ans.info, &rev_v6); - if (match && (ans.ttl > (pkt->netif->mdns->dns_ttl / 2))) { + if (match && (ans.ttl > (mdns->dns_ttl / 2))) { /* The RR in the known answer matches an RR we are planning to send, * and the TTL is less than half gone. * If the payload matches we should not send that answer. @@ -1601,7 +1605,7 @@ mdns_handle_question(struct mdns_packet *pkt) struct mdns_domain known_ans, my_ans; u16_t len; len = mdns_readname(pkt->pbuf, ans.rd_offset, &known_ans); - res = mdns_build_host_domain(&my_ans, pkt->netif->mdns); + res = mdns_build_host_domain(&my_ans, mdns); if (len != MDNS_READNAME_ERROR && res == ERR_OK && mdns_domain_eq(&known_ans, &my_ans)) { #if LWIP_IPV4 if (match & REPLY_HOST_PTR_V4) { @@ -1640,7 +1644,7 @@ mdns_handle_question(struct mdns_packet *pkt) } for (i = 0; i < MDNS_MAX_SERVICES; ++i) { - service = pkt->netif->mdns->services[i]; + service = mdns->services[i]; if (!service) { continue; } @@ -1697,7 +1701,7 @@ mdns_handle_question(struct mdns_packet *pkt) read_pos += len; /* Check host field */ len = mdns_readname(pkt->pbuf, read_pos, &known_ans); - mdns_build_host_domain(&my_ans, pkt->netif->mdns); + mdns_build_host_domain(&my_ans, mdns); if (len == MDNS_READNAME_ERROR || !mdns_domain_eq(&known_ans, &my_ans)) { break; } @@ -1780,7 +1784,7 @@ mdns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: Received IPv%d MDNS packet, len %d\n", IP_IS_V6(addr)? 6 : 4, p->tot_len)); - if (!recv_netif->mdns) { + if (recv_netif->client_data[mdns_netif_client_id] == NULL) { /* From netif not configured for MDNS */ goto dealloc; } @@ -1850,6 +1854,8 @@ mdns_resp_init(void) res = udp_bind(mdns_pcb, IP_ANY_TYPE, MDNS_PORT); LWIP_ASSERT("Failed to bind pcb", res == ERR_OK); udp_recv(mdns_pcb, mdns_recv, NULL); + + mdns_netif_client_id = netif_alloc_client_data_id(); } /** @@ -1866,17 +1872,20 @@ err_t mdns_resp_add_netif(struct netif *netif, const char *hostname, u32_t dns_ttl) { err_t res; + struct mdns_host* mdns; LWIP_ERROR("mdns_resp_add_netif: netif != NULL", (netif != NULL), return ERR_VAL); LWIP_ERROR("mdns_resp_add_netif: Hostname too long", (strlen(hostname) <= MDNS_LABEL_MAXLEN), return ERR_VAL); - LWIP_ASSERT("mdns_resp_add_netif: Double add", netif->mdns == NULL); - netif->mdns = (struct mdns_host *) mem_malloc(sizeof(struct mdns_host)); - LWIP_ERROR("mdns_resp_add_netif: Alloc failed", (netif->mdns != NULL), return ERR_MEM); + LWIP_ASSERT("mdns_resp_add_netif: Double add", netif->client_data[mdns_netif_client_id] == NULL); + mdns = (struct mdns_host *) mem_malloc(sizeof(struct mdns_host)); + LWIP_ERROR("mdns_resp_add_netif: Alloc failed", (mdns != NULL), return ERR_MEM); - memset(netif->mdns, 0, sizeof(struct mdns_host)); - memcpy(&netif->mdns->name, hostname, LWIP_MIN(MDNS_LABEL_MAXLEN, strlen(hostname))); - netif->mdns->dns_ttl = dns_ttl; + netif->client_data[mdns_netif_client_id] = mdns; + + memset(mdns, 0, sizeof(struct mdns_host)); + memcpy(&mdns->name, hostname, LWIP_MIN(MDNS_LABEL_MAXLEN, strlen(hostname))); + mdns->dns_ttl = dns_ttl; /* Join multicast groups */ #if LWIP_IPV4 @@ -1903,8 +1912,8 @@ mdns_resp_add_netif(struct netif *netif, const char *hostname, u32_t dns_ttl) return ERR_OK; cleanup: - mem_free(netif->mdns); - netif->mdns = NULL; + mem_free(mdns); + netif->client_data[mdns_netif_client_id] = NULL; return res; } @@ -1919,11 +1928,13 @@ err_t mdns_resp_remove_netif(struct netif *netif) { int i; + struct mdns_host* mdns = (struct mdns_host*)netif->client_data[mdns_netif_client_id]; + LWIP_ASSERT("mdns_resp_remove_netif: Null pointer", netif); - LWIP_ERROR("mdns_resp_remove_netif: Not an active netif", (netif->mdns != NULL), return ERR_VAL); + LWIP_ERROR("mdns_resp_remove_netif: Not an active netif", (mdns != NULL), return ERR_VAL); for (i = 0; i < MDNS_MAX_SERVICES; i++) { - struct mdns_service *service = netif->mdns->services[i]; + struct mdns_service *service = mdns->services[i]; if (service) { mem_free(service); } @@ -1937,8 +1948,8 @@ mdns_resp_remove_netif(struct netif *netif) mld6_leavegroup_netif(netif, ip_2_ip6(&v6group)); #endif - mem_free(netif->mdns); - netif->mdns = NULL; + mem_free(mdns); + netif->client_data[mdns_netif_client_id] = NULL; return ERR_OK; } @@ -1963,16 +1974,17 @@ mdns_resp_add_service(struct netif *netif, const char *name, const char *service int i; int slot = -1; struct mdns_service *srv; + struct mdns_host* mdns = (struct mdns_host*)netif->client_data[mdns_netif_client_id]; LWIP_ASSERT("mdns_resp_add_service: netif != NULL", netif); - LWIP_ERROR("mdns_resp_add_service: Not an mdns netif", (netif->mdns != NULL), return ERR_VAL); + LWIP_ERROR("mdns_resp_add_service: Not an mdns netif", (mdns != NULL), return ERR_VAL); LWIP_ERROR("mdns_resp_add_service: Name too long", (strlen(name) <= MDNS_LABEL_MAXLEN), return ERR_VAL); LWIP_ERROR("mdns_resp_add_service: Service too long", (strlen(service) <= MDNS_LABEL_MAXLEN), return ERR_VAL); LWIP_ERROR("mdns_resp_add_service: Bad proto (need TCP or UDP)", (proto == DNSSD_PROTO_TCP || proto == DNSSD_PROTO_UDP), return ERR_VAL); for (i = 0; i < MDNS_MAX_SERVICES; i++) { - if (netif->mdns->services[i] == NULL) { + if (mdns->services[i] == NULL) { slot = i; break; } @@ -1992,7 +2004,7 @@ mdns_resp_add_service(struct netif *netif, const char *name, const char *service srv->port = port; srv->dns_ttl = dns_ttl; - netif->mdns->services[slot] = srv; + mdns->services[slot] = srv; /* Announce on IPv6 and IPv4 */ #if LWIP_IPV6 diff --git a/src/core/netif.c b/src/core/netif.c index 685abaaa..5927d8f7 100644 --- a/src/core/netif.c +++ b/src/core/netif.c @@ -39,6 +39,8 @@ #include "lwip/opt.h" +#include + #include "lwip/def.h" #include "lwip/ip_addr.h" #include "lwip/ip6_addr.h" @@ -247,10 +249,9 @@ netif_add(struct netif *netif, /* netif not under AutoIP control by default */ netif->autoip = NULL; #endif /* LWIP_AUTOIP */ -#if LWIP_MDNS_RESPONDER - /* netif not using MDNS by default */ - netif->mdns = NULL; -#endif /* LWIP_MDNS_RESPONDER */ +#if LWIP_NUM_NETIF_CLIENT_DATA > 0 + memset(netif->client_data, 0, sizeof(netif->client_data)); +#endif /* LWIP_NUM_NETIF_CLIENT_DATA */ #if LWIP_IPV6_AUTOCONFIG /* IPv6 address autoconfiguration not enabled by default */ netif->ip6_autoconfig_enabled = 0; @@ -947,6 +948,24 @@ netif_poll_all(void) #endif /* !LWIP_NETIF_LOOPBACK_MULTITHREADING */ #endif /* ENABLE_LOOPBACK */ +#if LWIP_NUM_NETIF_CLIENT_DATA > 0 +static u8_t netif_client_id = 0; + +/** + * @ingroup netif + * Allocate an index to store data in client_data member of struct netif. + * Returned value is an index in mentioned array. + * @see LWIP_NUM_NETIF_CLIENT_DATA + */ +u8_t netif_alloc_client_data_id(void) +{ + u8_t result = netif_client_id; + netif_client_id++; + LWIP_ASSERT("Increase LWIP_NUM_NETIF_CLIENT_DATA in lwipopts.h", netif_client_id 0 + void* client_data[LWIP_NUM_NETIF_CLIENT_DATA]; +#endif #if LWIP_IPV6_AUTOCONFIG /** is this netif enabled for IPv6 autoconfiguration */ u8_t ip6_autoconfig_enabled; @@ -431,6 +426,10 @@ void netif_poll_all(void); err_t netif_input(struct pbuf *p, struct netif *inp); +#if LWIP_NUM_NETIF_CLIENT_DATA > 0 +u8_t netif_alloc_client_data_id(void); +#endif + #if LWIP_IPV6 /** @ingroup netif */ #define netif_ip_addr6(netif, i) ((const ip_addr_t*)(&((netif)->ip6_addr[i]))) diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h index 39c45b9a..f65c7b8c 100644 --- a/src/include/lwip/opt.h +++ b/src/include/lwip/opt.h @@ -1465,6 +1465,14 @@ #if !defined LWIP_NETIF_TX_SINGLE_PBUF || defined __DOXYGEN__ #define LWIP_NETIF_TX_SINGLE_PBUF 0 #endif /* LWIP_NETIF_TX_SINGLE_PBUF */ + +/** + * LWIP_NUM_NETIF_CLIENT_DATA: Number of clients that may store + * per data in client_data member array of struct netif. + */ +#if !defined LWIP_NUM_NETIF_CLIENT_DATA || defined __DOXYGEN__ +#define LWIP_NUM_NETIF_CLIENT_DATA (LWIP_DHCP + LWIP_AUTOIP) +#endif /** * @} */ From ee815e4e7aad822c080153d770a4c7f7f257f124 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Wed, 17 Aug 2016 20:09:28 +0200 Subject: [PATCH 092/325] Finish porting MDNS to new netif client data API --- src/apps/mdns/mdns.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/apps/mdns/mdns.c b/src/apps/mdns/mdns.c index 7e28985b..a8e05a52 100644 --- a/src/apps/mdns/mdns.c +++ b/src/apps/mdns/mdns.c @@ -1170,9 +1170,9 @@ static err_t mdns_add_aaaa_answer(struct mdns_outpacket *reply, u16_t cache_flush, struct netif *netif, int addrindex) { struct mdns_domain host; - mdns_build_host_domain(&host, netif->mdns); + mdns_build_host_domain(&host, (struct mdns_host*)netif->client_data[mdns_netif_client_id]); LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: Responding with AAAA record\n")); - return mdns_add_answer(reply, &host, DNS_RRTYPE_AAAA, DNS_RRCLASS_IN, cache_flush, netif->mdns->dns_ttl, (const u8_t *) netif_ip6_addr(netif, addrindex), sizeof(ip6_addr_t), NULL); + return mdns_add_answer(reply, &host, DNS_RRTYPE_AAAA, DNS_RRCLASS_IN, cache_flush, ((struct mdns_host*)netif->client_data[mdns_netif_client_id])->dns_ttl, (const u8_t *) netif_ip6_addr(netif, addrindex), sizeof(ip6_addr_t), NULL); } /** Write a x.y.z.ip6.arpa -> hostname.local PTR RR to outpacket */ @@ -1180,10 +1180,10 @@ static err_t mdns_add_hostv6_ptr_answer(struct mdns_outpacket *reply, u16_t cache_flush, struct netif *netif, int addrindex) { struct mdns_domain host, revhost; - mdns_build_host_domain(&host, netif->mdns); + mdns_build_host_domain(&host, (struct mdns_host*)netif->client_data[mdns_netif_client_id]); mdns_build_reverse_v6_domain(&revhost, netif_ip6_addr(netif, addrindex)); LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: Responding with v6 PTR record\n")); - return mdns_add_answer(reply, &revhost, DNS_RRTYPE_PTR, DNS_RRCLASS_IN, cache_flush, netif->mdns->dns_ttl, NULL, 0, &host); + return mdns_add_answer(reply, &revhost, DNS_RRTYPE_PTR, DNS_RRCLASS_IN, cache_flush, ((struct mdns_host*)netif->client_data[mdns_netif_client_id])->dns_ttl, NULL, 0, &host); } #endif From c8c804140d553dc6df5c189f2bf1dd0d46be940e Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Wed, 17 Aug 2016 21:00:59 +0200 Subject: [PATCH 093/325] Fix possible NULL pointer dereference in mdns.c introduced in my last commit --- src/apps/mdns/mdns.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/apps/mdns/mdns.c b/src/apps/mdns/mdns.c index a8e05a52..d6c2b4b2 100644 --- a/src/apps/mdns/mdns.c +++ b/src/apps/mdns/mdns.c @@ -1928,9 +1928,10 @@ err_t mdns_resp_remove_netif(struct netif *netif) { int i; - struct mdns_host* mdns = (struct mdns_host*)netif->client_data[mdns_netif_client_id]; + struct mdns_host* mdns; LWIP_ASSERT("mdns_resp_remove_netif: Null pointer", netif); + mdns = (struct mdns_host*)netif->client_data[mdns_netif_client_id]; LWIP_ERROR("mdns_resp_remove_netif: Not an active netif", (mdns != NULL), return ERR_VAL); for (i = 0; i < MDNS_MAX_SERVICES; i++) { @@ -1974,9 +1975,10 @@ mdns_resp_add_service(struct netif *netif, const char *name, const char *service int i; int slot = -1; struct mdns_service *srv; - struct mdns_host* mdns = (struct mdns_host*)netif->client_data[mdns_netif_client_id]; + struct mdns_host* mdns; LWIP_ASSERT("mdns_resp_add_service: netif != NULL", netif); + mdns = (struct mdns_host*)netif->client_data[mdns_netif_client_id]; LWIP_ERROR("mdns_resp_add_service: Not an mdns netif", (mdns != NULL), return ERR_VAL); LWIP_ERROR("mdns_resp_add_service: Name too long", (strlen(name) <= MDNS_LABEL_MAXLEN), return ERR_VAL); From 1db9631e7d5dfd0a566f188d0f17fc017bad5af9 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Wed, 17 Aug 2016 21:04:44 +0200 Subject: [PATCH 094/325] Port DHCP to new netif client data API --- src/core/init.c | 4 ++ src/core/ipv4/dhcp.c | 100 +++++++++++++++++++++++---------------- src/core/netif.c | 14 +----- src/include/lwip/dhcp.h | 1 + src/include/lwip/netif.h | 14 ------ 5 files changed, 65 insertions(+), 68 deletions(-) diff --git a/src/core/init.c b/src/core/init.c index dbd630dd..a02c8bd6 100644 --- a/src/core/init.c +++ b/src/core/init.c @@ -50,6 +50,7 @@ #include "lwip/udp.h" #include "lwip/priv/tcp_priv.h" #include "lwip/autoip.h" +#include "lwip/dhcp.h" #include "lwip/igmp.h" #include "lwip/dns.h" #include "lwip/timeouts.h" @@ -351,6 +352,9 @@ lwip_init(void) #if LWIP_AUTOIP autoip_init(); #endif /* LWIP_AUTOIP */ +#if LWIP_DHCP + dhcp_init(); +#endif /* LWIP_DHCP */ #if LWIP_IGMP igmp_init(); #endif /* LWIP_IGMP */ diff --git a/src/core/ipv4/dhcp.c b/src/core/ipv4/dhcp.c index af6fcde0..16c7a9b4 100644 --- a/src/core/ipv4/dhcp.c +++ b/src/core/ipv4/dhcp.c @@ -156,6 +156,7 @@ static u8_t xid_initialised; static struct udp_pcb *dhcp_pcb; static u8_t dhcp_pcb_refcount; +static u8_t dhcp_netif_client_id; /* DHCP client state machine functions */ static err_t dhcp_discover(struct netif *netif); @@ -248,7 +249,8 @@ dhcp_dec_pcb_refcount(void) static void dhcp_handle_nak(struct netif *netif) { - struct dhcp *dhcp = netif->dhcp; + struct dhcp *dhcp = (struct dhcp*)netif->client_data[dhcp_netif_client_id]; + LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_handle_nak(netif=%p) %c%c%"U16_F"\n", (void*)netif, netif->name[0], netif->name[1], (u16_t)netif->num)); /* Change to a defined state - set this before assigning the address @@ -273,7 +275,7 @@ dhcp_handle_nak(struct netif *netif) static void dhcp_check(struct netif *netif) { - struct dhcp *dhcp = netif->dhcp; + struct dhcp *dhcp = (struct dhcp*)netif->client_data[dhcp_netif_client_id]; err_t result; u16_t msecs; LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_check(netif=%p) %c%c\n", (void *)netif, (s16_t)netif->name[0], @@ -302,7 +304,8 @@ dhcp_check(struct netif *netif) static void dhcp_handle_offer(struct netif *netif) { - struct dhcp *dhcp = netif->dhcp; + struct dhcp *dhcp = (struct dhcp*)netif->client_data[dhcp_netif_client_id]; + LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_handle_offer(netif=%p) %c%c%"U16_F"\n", (void*)netif, netif->name[0], netif->name[1], (u16_t)netif->num)); /* obtain the server address */ @@ -333,7 +336,7 @@ dhcp_handle_offer(struct netif *netif) static err_t dhcp_select(struct netif *netif) { - struct dhcp *dhcp = netif->dhcp; + struct dhcp *dhcp = (struct dhcp*)netif->client_data[dhcp_netif_client_id]; err_t result; u16_t msecs; u8_t i; @@ -395,7 +398,7 @@ dhcp_coarse_tmr(void) /* iterate through all network interfaces */ while (netif != NULL) { /* only act on DHCP configured interfaces */ - struct dhcp* dhcp = netif->dhcp; + struct dhcp *dhcp = (struct dhcp*)netif->client_data[dhcp_netif_client_id]; if ((dhcp != NULL) && (dhcp->state != DHCP_STATE_OFF)) { /* compare lease time to expire timeout */ if (dhcp->t0_timeout && (++dhcp->lease_used == dhcp->t0_timeout)) { @@ -433,14 +436,15 @@ dhcp_fine_tmr(void) struct netif *netif = netif_list; /* loop through netif's */ while (netif != NULL) { + struct dhcp *dhcp = (struct dhcp*)netif->client_data[dhcp_netif_client_id]; /* only act on DHCP configured interfaces */ - if (netif->dhcp != NULL) { + if (dhcp != NULL) { /* timer is active (non zero), and is about to trigger now */ - if (netif->dhcp->request_timeout > 1) { - netif->dhcp->request_timeout--; + if (dhcp->request_timeout > 1) { + dhcp->request_timeout--; } - else if (netif->dhcp->request_timeout == 1) { - netif->dhcp->request_timeout--; + else if (dhcp->request_timeout == 1) { + dhcp->request_timeout--; /* { netif->dhcp->request_timeout == 0 } */ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_fine_tmr(): request timeout\n")); /* this client's request timeout triggered */ @@ -463,7 +467,8 @@ dhcp_fine_tmr(void) static void dhcp_timeout(struct netif *netif) { - struct dhcp *dhcp = netif->dhcp; + struct dhcp *dhcp = (struct dhcp*)netif->client_data[dhcp_netif_client_id]; + LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_timeout()\n")); /* back-off period has passed, or server selection timed out */ if ((dhcp->state == DHCP_STATE_BACKING_OFF) || (dhcp->state == DHCP_STATE_SELECTING)) { @@ -509,7 +514,8 @@ dhcp_timeout(struct netif *netif) static void dhcp_t1_timeout(struct netif *netif) { - struct dhcp *dhcp = netif->dhcp; + struct dhcp *dhcp = (struct dhcp*)netif->client_data[dhcp_netif_client_id]; + LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_STATE, ("dhcp_t1_timeout()\n")); if ((dhcp->state == DHCP_STATE_REQUESTING) || (dhcp->state == DHCP_STATE_BOUND) || (dhcp->state == DHCP_STATE_RENEWING)) { @@ -521,9 +527,9 @@ dhcp_t1_timeout(struct netif *netif) DHCP_STATE_RENEWING, not DHCP_STATE_BOUND */ dhcp_renew(netif); /* Calculate next timeout */ - if (((netif->dhcp->t2_timeout - dhcp->lease_used) / 2) >= ((60 + DHCP_COARSE_TIMER_SECS / 2) / DHCP_COARSE_TIMER_SECS)) + if (((dhcp->t2_timeout - dhcp->lease_used) / 2) >= ((60 + DHCP_COARSE_TIMER_SECS / 2) / DHCP_COARSE_TIMER_SECS)) { - netif->dhcp->t1_renew_time = ((netif->dhcp->t2_timeout - dhcp->lease_used) / 2); + dhcp->t1_renew_time = ((dhcp->t2_timeout - dhcp->lease_used) / 2); } } } @@ -536,7 +542,8 @@ dhcp_t1_timeout(struct netif *netif) static void dhcp_t2_timeout(struct netif *netif) { - struct dhcp *dhcp = netif->dhcp; + struct dhcp *dhcp = (struct dhcp*)netif->client_data[dhcp_netif_client_id]; + LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_t2_timeout()\n")); if ((dhcp->state == DHCP_STATE_REQUESTING) || (dhcp->state == DHCP_STATE_BOUND) || (dhcp->state == DHCP_STATE_RENEWING) || (dhcp->state == DHCP_STATE_REBINDING)) { @@ -547,9 +554,9 @@ dhcp_t2_timeout(struct netif *netif) DHCP_STATE_REBINDING, not DHCP_STATE_BOUND */ dhcp_rebind(netif); /* Calculate next timeout */ - if (((netif->dhcp->t0_timeout - dhcp->lease_used) / 2) >= ((60 + DHCP_COARSE_TIMER_SECS / 2) / DHCP_COARSE_TIMER_SECS)) + if (((dhcp->t0_timeout - dhcp->lease_used) / 2) >= ((60 + DHCP_COARSE_TIMER_SECS / 2) / DHCP_COARSE_TIMER_SECS)) { - netif->dhcp->t2_rebind_time = ((netif->dhcp->t0_timeout - dhcp->lease_used) / 2); + dhcp->t2_rebind_time = ((dhcp->t0_timeout - dhcp->lease_used) / 2); } } } @@ -562,7 +569,8 @@ dhcp_t2_timeout(struct netif *netif) static void dhcp_handle_ack(struct netif *netif) { - struct dhcp *dhcp = netif->dhcp; + struct dhcp *dhcp = (struct dhcp*)netif->client_data[dhcp_netif_client_id]; + #if LWIP_DNS || LWIP_DHCP_GET_NTP_SRV u8_t n; #endif /* LWIP_DNS || LWIP_DHCP_GET_NTP_SRV */ @@ -654,12 +662,12 @@ dhcp_set_struct(struct netif *netif, struct dhcp *dhcp) { LWIP_ASSERT("netif != NULL", netif != NULL); LWIP_ASSERT("dhcp != NULL", dhcp != NULL); - LWIP_ASSERT("netif already has a struct dhcp set", netif->dhcp == NULL); + LWIP_ASSERT("netif already has a struct dhcp set", netif->client_data[dhcp_netif_client_id] == NULL); /* clear data structure */ memset(dhcp, 0, sizeof(struct dhcp)); /* dhcp_set_state(&dhcp, DHCP_STATE_OFF); */ - netif->dhcp = dhcp; + netif->client_data[dhcp_netif_client_id] = dhcp; } /** @@ -675,9 +683,9 @@ void dhcp_cleanup(struct netif *netif) { LWIP_ASSERT("netif != NULL", netif != NULL); - if (netif->dhcp != NULL) { - mem_free(netif->dhcp); - netif->dhcp = NULL; + if (netif->client_data[dhcp_netif_client_id] != NULL) { + mem_free(netif->client_data[dhcp_netif_client_id]); + netif->client_data[dhcp_netif_client_id] = NULL; } } @@ -702,7 +710,7 @@ dhcp_start(struct netif *netif) LWIP_ERROR("netif != NULL", (netif != NULL), return ERR_ARG;); LWIP_ERROR("netif is not up, old style port?", netif_is_up(netif), return ERR_ARG;); - dhcp = netif->dhcp; + dhcp = (struct dhcp*)netif->client_data[dhcp_netif_client_id]; 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)); /* check MTU of the netif */ @@ -721,7 +729,7 @@ dhcp_start(struct netif *netif) } /* store this dhcp client in the netif */ - netif->dhcp = dhcp; + netif->client_data[dhcp_netif_client_id] = dhcp; LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_start(): allocated dhcp")); /* already has DHCP client attached */ } else { @@ -820,7 +828,8 @@ dhcp_inform(struct netif *netif) void dhcp_network_changed(struct netif *netif) { - struct dhcp *dhcp = netif->dhcp; + struct dhcp *dhcp = (struct dhcp*)netif->client_data[dhcp_netif_client_id]; + if (!dhcp) return; switch (dhcp->state) { @@ -862,15 +871,18 @@ dhcp_network_changed(struct netif *netif) void dhcp_arp_reply(struct netif *netif, const ip4_addr_t *addr) { + struct dhcp *dhcp; + LWIP_ERROR("netif != NULL", (netif != NULL), return;); + dhcp = (struct dhcp*)netif->client_data[dhcp_netif_client_id]; LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_arp_reply()\n")); /* is a DHCP client doing an ARP check? */ - if ((netif->dhcp != NULL) && (netif->dhcp->state == DHCP_STATE_CHECKING)) { + if ((dhcp != NULL) && (dhcp->state == DHCP_STATE_CHECKING)) { LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_arp_reply(): CHECKING, arp reply for 0x%08"X32_F"\n", ip4_addr_get_u32(addr))); /* did a host respond with the address we were offered by the DHCP server? */ - if (ip4_addr_cmp(addr, &netif->dhcp->offered_ip_addr)) { + if (ip4_addr_cmp(addr, &dhcp->offered_ip_addr)) { /* we will not accept the offered address */ LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE | LWIP_DBG_LEVEL_WARNING, ("dhcp_arp_reply(): arp reply matched with offered address, declining\n")); @@ -891,7 +903,7 @@ dhcp_arp_reply(struct netif *netif, const ip4_addr_t *addr) static err_t dhcp_decline(struct netif *netif) { - struct dhcp *dhcp = netif->dhcp; + struct dhcp *dhcp = (struct dhcp*)netif->client_data[dhcp_netif_client_id]; err_t result = ERR_OK; u16_t msecs; LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_decline()\n")); @@ -933,7 +945,7 @@ dhcp_decline(struct netif *netif) static err_t dhcp_discover(struct netif *netif) { - struct dhcp *dhcp = netif->dhcp; + struct dhcp *dhcp = (struct dhcp*)netif->client_data[dhcp_netif_client_id]; err_t result = ERR_OK; u16_t msecs; u8_t i; @@ -993,7 +1005,7 @@ dhcp_bind(struct netif *netif) struct dhcp *dhcp; ip4_addr_t sn_mask, gw_addr; LWIP_ERROR("dhcp_bind: netif != NULL", (netif != NULL), return;); - dhcp = netif->dhcp; + dhcp = (struct dhcp*)netif->client_data[dhcp_netif_client_id]; LWIP_ERROR("dhcp_bind: dhcp != NULL", (dhcp != NULL), return;); LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_bind(netif=%p) %c%c%"U16_F"\n", (void*)netif, netif->name[0], netif->name[1], (u16_t)netif->num)); @@ -1099,7 +1111,7 @@ dhcp_bind(struct netif *netif) err_t dhcp_renew(struct netif *netif) { - struct dhcp *dhcp = netif->dhcp; + struct dhcp *dhcp = (struct dhcp*)netif->client_data[dhcp_netif_client_id]; err_t result; u16_t msecs; u8_t i; @@ -1151,7 +1163,7 @@ dhcp_renew(struct netif *netif) static err_t dhcp_rebind(struct netif *netif) { - struct dhcp *dhcp = netif->dhcp; + struct dhcp *dhcp = (struct dhcp*)netif->client_data[dhcp_netif_client_id]; err_t result; u16_t msecs; u8_t i; @@ -1201,7 +1213,7 @@ dhcp_rebind(struct netif *netif) static err_t dhcp_reboot(struct netif *netif) { - struct dhcp *dhcp = netif->dhcp; + struct dhcp *dhcp = (struct dhcp*)netif->client_data[dhcp_netif_client_id]; err_t result; u16_t msecs; u8_t i; @@ -1252,7 +1264,7 @@ dhcp_reboot(struct netif *netif) err_t dhcp_release(struct netif *netif) { - struct dhcp *dhcp = netif->dhcp; + struct dhcp *dhcp = (struct dhcp*)netif->client_data[dhcp_netif_client_id]; err_t result; ip_addr_t server_ip_addr; u8_t is_dhcp_supplied_address; @@ -1317,7 +1329,7 @@ dhcp_stop(struct netif *netif) { struct dhcp *dhcp; LWIP_ERROR("dhcp_stop: netif != NULL", (netif != NULL), return;); - dhcp = netif->dhcp; + dhcp = (struct dhcp*)netif->client_data[dhcp_netif_client_id]; LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_stop()\n")); /* netif is DHCP configured? */ @@ -1642,7 +1654,7 @@ static void dhcp_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, u16_t port) { struct netif *netif = ip_current_input_netif(); - struct dhcp *dhcp = netif->dhcp; + struct dhcp *dhcp = (struct dhcp*)netif->client_data[dhcp_netif_client_id]; struct dhcp_msg *reply_msg = (struct dhcp_msg *)p->payload; u8_t msg_type; u8_t i; @@ -1904,13 +1916,17 @@ dhcp_option_trailer(struct dhcp *dhcp) u8_t dhcp_supplied_address(const struct netif *netif) { - if ((netif != NULL) && (netif->dhcp != NULL)) { - if ((netif->dhcp->state == DHCP_STATE_BOUND) || - (netif->dhcp->state == DHCP_STATE_RENEWING)) { - return 1; - } + if ((netif != NULL) && (netif->client_data[dhcp_netif_client_id] != NULL)) { + struct dhcp* dhcp = (struct dhcp*)netif->client_data[dhcp_netif_client_id]; + return (dhcp->state == DHCP_STATE_BOUND) || (dhcp->state == DHCP_STATE_RENEWING); } return 0; } +void +dhcp_init(void) +{ + dhcp_netif_client_id = netif_alloc_client_data_id(); +} + #endif /* LWIP_IPV4 && LWIP_DHCP */ diff --git a/src/core/netif.c b/src/core/netif.c index 5927d8f7..9bad9c29 100644 --- a/src/core/netif.c +++ b/src/core/netif.c @@ -241,10 +241,6 @@ netif_add(struct netif *netif, #endif /* LWIP_IPV6 */ NETIF_SET_CHECKSUM_CTRL(netif, NETIF_CHECKSUM_ENABLE_ALL); netif->flags = 0; -#if LWIP_DHCP - /* netif not under DHCP control by default */ - netif->dhcp = NULL; -#endif /* LWIP_DHCP */ #if LWIP_AUTOIP /* netif not under AutoIP control by default */ netif->autoip = NULL; @@ -259,10 +255,6 @@ netif_add(struct netif *netif, #if LWIP_IPV6_SEND_ROUTER_SOLICIT netif->rs_count = LWIP_ND6_MAX_MULTICAST_SOLICIT; #endif /* LWIP_IPV6_SEND_ROUTER_SOLICIT */ -#if LWIP_IPV6_DHCP6 - /* netif not under DHCPv6 control by default */ - netif->dhcp6 = NULL; -#endif /* LWIP_IPV6_DHCP6 */ #if LWIP_NETIF_STATUS_CALLBACK netif->status_callback = NULL; #endif /* LWIP_NETIF_STATUS_CALLBACK */ @@ -696,9 +688,7 @@ netif_set_link_up(struct netif *netif) netif->flags |= NETIF_FLAG_LINK_UP; #if LWIP_DHCP - if (netif->dhcp) { - dhcp_network_changed(netif); - } + dhcp_network_changed(netif); #endif /* LWIP_DHCP */ #if LWIP_AUTOIP @@ -961,7 +951,7 @@ u8_t netif_alloc_client_data_id(void) { u8_t result = netif_client_id; netif_client_id++; - LWIP_ASSERT("Increase LWIP_NUM_NETIF_CLIENT_DATA in lwipopts.h", netif_client_id Date: Wed, 17 Aug 2016 21:26:08 +0200 Subject: [PATCH 095/325] Port AUTOIP to new netif client data API --- src/core/ipv4/autoip.c | 136 +++++++++++++++++++++++--------------- src/core/ipv4/ip4.c | 3 +- src/core/netif.c | 8 +-- src/include/lwip/autoip.h | 5 +- src/include/lwip/netif.h | 8 --- 5 files changed, 87 insertions(+), 73 deletions(-) diff --git a/src/core/ipv4/autoip.c b/src/core/ipv4/autoip.c index 226c43cd..44b35431 100644 --- a/src/core/ipv4/autoip.c +++ b/src/core/ipv4/autoip.c @@ -71,6 +71,7 @@ #include #include +static u8_t autoip_netif_client_id; /** Pseudo random macro based on netif informations. * You could use "rand()" from the C Library if you define LWIP_AUTOIP_RAND in lwipopts.h */ @@ -79,7 +80,7 @@ ((u32_t)((netif->hwaddr[3]) & 0xff) << 16) | \ ((u32_t)((netif->hwaddr[2]) & 0xff) << 8) | \ ((u32_t)((netif->hwaddr[4]) & 0xff))) + \ - (netif->autoip?netif->autoip->tried_llipaddr:0)) + (netif->client_data[autoip_netif_client_id]? ((struct autoip*)netif->client_data[autoip_netif_client_id])->tried_llipaddr : 0)) #endif /* LWIP_AUTOIP_RAND */ /** @@ -110,12 +111,13 @@ autoip_set_struct(struct netif *netif, struct autoip *autoip) { LWIP_ASSERT("netif != NULL", netif != NULL); LWIP_ASSERT("autoip != NULL", autoip != NULL); - LWIP_ASSERT("netif already has a struct autoip set", netif->autoip == NULL); + LWIP_ASSERT("netif already has a struct autoip set", + netif->client_data[autoip_netif_client_id] == NULL); /* clear data structure */ memset(autoip, 0, sizeof(struct autoip)); /* autoip->state = AUTOIP_STATE_OFF; */ - netif->autoip = autoip; + netif->client_data[autoip_netif_client_id] = autoip; } /** Restart AutoIP client and check the next address (conflict detected) @@ -125,7 +127,8 @@ autoip_set_struct(struct netif *netif, struct autoip *autoip) static void autoip_restart(struct netif *netif) { - netif->autoip->tried_llipaddr++; + struct autoip* autoip = (struct autoip*)netif->client_data[autoip_netif_client_id]; + autoip->tried_llipaddr++; autoip_start(netif); } @@ -135,6 +138,8 @@ autoip_restart(struct netif *netif) static void autoip_handle_arp_conflict(struct netif *netif) { + struct autoip* autoip = (struct autoip*)netif->client_data[autoip_netif_client_id]; + /* RFC3927, 2.5 "Conflict Detection and Defense" allows two options where a) means retreat on the first conflict and b) allows to keep an already configured address when having only one @@ -142,7 +147,7 @@ autoip_handle_arp_conflict(struct netif *netif) We use option b) since it helps to improve the chance that one of the two conflicting hosts may be able to retain its address. */ - if (netif->autoip->lastconflict > 0) { + if (autoip->lastconflict > 0) { /* retreat, there was a conflicting ARP in the last DEFEND_INTERVAL seconds */ LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("autoip_handle_arp_conflict(): we are defending, but in DEFEND_INTERVAL, retreating\n")); @@ -153,7 +158,7 @@ autoip_handle_arp_conflict(struct netif *netif) LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("autoip_handle_arp_conflict(): we are defend, send ARP Announce\n")); autoip_arp_announce(netif); - netif->autoip->lastconflict = DEFEND_INTERVAL * AUTOIP_TICKS_PER_SECOND; + autoip->lastconflict = DEFEND_INTERVAL * AUTOIP_TICKS_PER_SECOND; } } @@ -166,12 +171,14 @@ autoip_handle_arp_conflict(struct netif *netif) static void autoip_create_addr(struct netif *netif, ip4_addr_t *ipaddr) { + struct autoip* autoip = (struct autoip*)netif->client_data[autoip_netif_client_id]; + /* Here we create an IP-Address out of range 169.254.1.0 to 169.254.254.255 * compliant to RFC 3927 Section 2.1 * We have 254 * 256 possibilities */ u32_t addr = ntohl(LWIP_AUTOIP_CREATE_SEED_ADDR(netif)); - addr += netif->autoip->tried_llipaddr; + addr += autoip->tried_llipaddr; addr = AUTOIP_NET | (addr & 0xffff); /* Now, 169.254.0.0 <= addr <= 169.254.255.255 */ @@ -187,7 +194,7 @@ autoip_create_addr(struct netif *netif, ip4_addr_t *ipaddr) LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("autoip_create_addr(): tried_llipaddr=%"U16_F", %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n", - (u16_t)(netif->autoip->tried_llipaddr), ip4_addr1_16(ipaddr), ip4_addr2_16(ipaddr), + (u16_t)(autoip->tried_llipaddr), ip4_addr1_16(ipaddr), ip4_addr2_16(ipaddr), ip4_addr3_16(ipaddr), ip4_addr4_16(ipaddr))); } @@ -199,8 +206,9 @@ autoip_create_addr(struct netif *netif, ip4_addr_t *ipaddr) static err_t autoip_arp_probe(struct netif *netif) { + struct autoip* autoip = (struct autoip*)netif->client_data[autoip_netif_client_id]; /* this works because netif->ip_addr is ANY */ - return etharp_request(netif, &netif->autoip->llipaddr); + return etharp_request(netif, &autoip->llipaddr); } /** @@ -222,7 +230,7 @@ autoip_arp_announce(struct netif *netif) static err_t autoip_bind(struct netif *netif) { - struct autoip *autoip = netif->autoip; + struct autoip* autoip = (struct autoip*)netif->client_data[autoip_netif_client_id]; ip4_addr_t sn_mask, gw_addr; LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE, @@ -249,7 +257,7 @@ autoip_bind(struct netif *netif) err_t autoip_start(struct netif *netif) { - struct autoip *autoip = netif->autoip; + struct autoip* autoip = (struct autoip*)netif->client_data[autoip_netif_client_id]; err_t result = ERR_OK; LWIP_ERROR("netif is not up, old style port?", netif_is_up(netif), return ERR_ARG;); @@ -274,7 +282,7 @@ autoip_start(struct netif *netif) } memset(autoip, 0, sizeof(struct autoip)); /* store this AutoIP client in the netif */ - netif->autoip = autoip; + netif->client_data[autoip_netif_client_id] = autoip; LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE, ("autoip_start(): allocated autoip")); } else { autoip->state = AUTOIP_STATE_OFF; @@ -293,14 +301,14 @@ autoip_start(struct netif *netif) static void autoip_start_probing(struct netif *netif) { - struct autoip *autoip = netif->autoip; + struct autoip* autoip = (struct autoip*)netif->client_data[autoip_netif_client_id]; autoip->state = AUTOIP_STATE_PROBING; autoip->sent_num = 0; LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("autoip_start_probing(): changing state to PROBING: %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n", - ip4_addr1_16(&netif->autoip->llipaddr), ip4_addr2_16(&netif->autoip->llipaddr), - ip4_addr3_16(&netif->autoip->llipaddr), ip4_addr4_16(&netif->autoip->llipaddr))); + ip4_addr1_16(&autoip->llipaddr), ip4_addr2_16(&autoip->llipaddr), + ip4_addr3_16(&autoip->llipaddr), ip4_addr4_16(&autoip->llipaddr))); /* time to wait to first probe, this is randomly * chosen out of 0 to PROBE_WAIT seconds. @@ -327,7 +335,9 @@ autoip_start_probing(struct netif *netif) void autoip_network_changed(struct netif *netif) { - if (netif->autoip && netif->autoip->state != AUTOIP_STATE_OFF) { + struct autoip* autoip = (struct autoip*)netif->client_data[autoip_netif_client_id]; + + if (autoip && (autoip->state != AUTOIP_STATE_OFF)) { autoip_start_probing(netif); } } @@ -341,8 +351,10 @@ autoip_network_changed(struct netif *netif) err_t autoip_stop(struct netif *netif) { - if (netif->autoip) { - netif->autoip->state = AUTOIP_STATE_OFF; + struct autoip* autoip = (struct autoip*)netif->client_data[autoip_netif_client_id]; + + if (autoip != NULL) { + autoip->state = AUTOIP_STATE_OFF; if (ip4_addr_islinklocal(netif_ip4_addr(netif))) { netif_set_addr(netif, IP4_ADDR_ANY, IP4_ADDR_ANY, IP4_ADDR_ANY); } @@ -359,45 +371,46 @@ autoip_tmr(void) struct netif *netif = netif_list; /* loop through netif's */ while (netif != NULL) { + struct autoip* autoip = (struct autoip*)netif->client_data[autoip_netif_client_id]; /* only act on AutoIP configured interfaces */ - if (netif->autoip != NULL) { - if (netif->autoip->lastconflict > 0) { - netif->autoip->lastconflict--; + if (autoip != NULL) { + if (autoip->lastconflict > 0) { + autoip->lastconflict--; } LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE, ("autoip_tmr() AutoIP-State: %"U16_F", ttw=%"U16_F"\n", - (u16_t)(netif->autoip->state), netif->autoip->ttw)); + (u16_t)(autoip->state), autoip->ttw)); - if (netif->autoip->ttw > 0) { - netif->autoip->ttw--; + if (autoip->ttw > 0) { + autoip->ttw--; } - switch(netif->autoip->state) { + switch(autoip->state) { case AUTOIP_STATE_PROBING: - if (netif->autoip->ttw == 0) { - if (netif->autoip->sent_num >= PROBE_NUM) { + if (autoip->ttw == 0) { + if (autoip->sent_num >= PROBE_NUM) { /* Switch to ANNOUNCING: now we can bind to an IP address and use it */ - netif->autoip->state = AUTOIP_STATE_ANNOUNCING; + autoip->state = AUTOIP_STATE_ANNOUNCING; autoip_bind(netif); /* autoip_bind() calls netif_set_addr(): this triggers a gratuitous ARP which counts as an announcement */ - netif->autoip->sent_num = 1; - netif->autoip->ttw = ANNOUNCE_WAIT * AUTOIP_TICKS_PER_SECOND; + autoip->sent_num = 1; + autoip->ttw = ANNOUNCE_WAIT * AUTOIP_TICKS_PER_SECOND; LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("autoip_tmr(): changing state to ANNOUNCING: %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n", - ip4_addr1_16(&netif->autoip->llipaddr), ip4_addr2_16(&netif->autoip->llipaddr), - ip4_addr3_16(&netif->autoip->llipaddr), ip4_addr4_16(&netif->autoip->llipaddr))); + ip4_addr1_16(&autoip->llipaddr), ip4_addr2_16(&autoip->llipaddr), + ip4_addr3_16(&autoip->llipaddr), ip4_addr4_16(&autoip->llipaddr))); } else { autoip_arp_probe(netif); LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE, ("autoip_tmr() PROBING Sent Probe\n")); - netif->autoip->sent_num++; - if (netif->autoip->sent_num == PROBE_NUM) { + autoip->sent_num++; + if (autoip->sent_num == PROBE_NUM) { /* calculate time to wait to for announce */ - netif->autoip->ttw = ANNOUNCE_WAIT * AUTOIP_TICKS_PER_SECOND; + autoip->ttw = ANNOUNCE_WAIT * AUTOIP_TICKS_PER_SECOND; } else { /* calculate time to wait to next probe */ - netif->autoip->ttw = (u16_t)((LWIP_AUTOIP_RAND(netif) % + autoip->ttw = (u16_t)((LWIP_AUTOIP_RAND(netif) % ((PROBE_MAX - PROBE_MIN) * AUTOIP_TICKS_PER_SECOND) ) + PROBE_MIN * AUTOIP_TICKS_PER_SECOND); } @@ -406,20 +419,20 @@ autoip_tmr(void) break; case AUTOIP_STATE_ANNOUNCING: - if (netif->autoip->ttw == 0) { + if (autoip->ttw == 0) { autoip_arp_announce(netif); LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE, ("autoip_tmr() ANNOUNCING Sent Announce\n")); - netif->autoip->ttw = ANNOUNCE_INTERVAL * AUTOIP_TICKS_PER_SECOND; - netif->autoip->sent_num++; + autoip->ttw = ANNOUNCE_INTERVAL * AUTOIP_TICKS_PER_SECOND; + autoip->sent_num++; - if (netif->autoip->sent_num >= ANNOUNCE_NUM) { - netif->autoip->state = AUTOIP_STATE_BOUND; - netif->autoip->sent_num = 0; - netif->autoip->ttw = 0; + if (autoip->sent_num >= ANNOUNCE_NUM) { + autoip->state = AUTOIP_STATE_BOUND; + autoip->sent_num = 0; + autoip->ttw = 0; LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("autoip_tmr(): changing state to BOUND: %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n", - ip4_addr1_16(&netif->autoip->llipaddr), ip4_addr2_16(&netif->autoip->llipaddr), - ip4_addr3_16(&netif->autoip->llipaddr), ip4_addr4_16(&netif->autoip->llipaddr))); + ip4_addr1_16(&autoip->llipaddr), ip4_addr2_16(&autoip->llipaddr), + ip4_addr3_16(&autoip->llipaddr), ip4_addr4_16(&autoip->llipaddr))); } } break; @@ -443,8 +456,10 @@ autoip_tmr(void) void autoip_arp_reply(struct netif *netif, struct etharp_hdr *hdr) { + struct autoip* autoip = (struct autoip*)netif->client_data[autoip_netif_client_id]; + LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE, ("autoip_arp_reply()\n")); - if ((netif->autoip != NULL) && (netif->autoip->state != AUTOIP_STATE_OFF)) { + if ((autoip != NULL) && (autoip->state != AUTOIP_STATE_OFF)) { /* when ip.src == llipaddr && hw.src != netif->hwaddr * * when probing ip.dst == llipaddr && hw.src != netif->hwaddr @@ -460,15 +475,15 @@ autoip_arp_reply(struct netif *netif, struct etharp_hdr *hdr) IPADDR2_COPY(&sipaddr, &hdr->sipaddr); IPADDR2_COPY(&dipaddr, &hdr->dipaddr); - if (netif->autoip->state == AUTOIP_STATE_PROBING) { + if (autoip->state == AUTOIP_STATE_PROBING) { /* RFC 3927 Section 2.2.1: * from beginning to after ANNOUNCE_WAIT * seconds we have a conflict if * ip.src == llipaddr OR * ip.dst == llipaddr && hw.src != own hwaddr */ - if ((ip4_addr_cmp(&sipaddr, &netif->autoip->llipaddr)) || - (ip4_addr_cmp(&dipaddr, &netif->autoip->llipaddr) && + if ((ip4_addr_cmp(&sipaddr, &autoip->llipaddr)) || + (ip4_addr_cmp(&dipaddr, &autoip->llipaddr) && !eth_addr_cmp(&netifaddr, &hdr->shwaddr))) { LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE | LWIP_DBG_LEVEL_WARNING, ("autoip_arp_reply(): Probe Conflict detected\n")); @@ -479,7 +494,7 @@ autoip_arp_reply(struct netif *netif, struct etharp_hdr *hdr) * in any state we have a conflict if * ip.src == llipaddr && hw.src != own hwaddr */ - if (ip4_addr_cmp(&sipaddr, &netif->autoip->llipaddr) && + if (ip4_addr_cmp(&sipaddr, &autoip->llipaddr) && !eth_addr_cmp(&netifaddr, &hdr->shwaddr)) { LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE | LWIP_DBG_LEVEL_WARNING, ("autoip_arp_reply(): Conflicting ARP-Packet detected\n")); @@ -498,13 +513,24 @@ autoip_arp_reply(struct netif *netif, struct etharp_hdr *hdr) u8_t autoip_supplied_address(const struct netif *netif) { - if ((netif != NULL) && (netif->autoip != NULL)) { - if ((netif->autoip->state == AUTOIP_STATE_BOUND) || - (netif->autoip->state == AUTOIP_STATE_ANNOUNCING)) { - return 1; - } + if ((netif != NULL) && (netif->client_data[autoip_netif_client_id] != NULL)) { + struct autoip* autoip = (struct autoip*)netif->client_data[autoip_netif_client_id]; + return (autoip->state == AUTOIP_STATE_BOUND) || (autoip->state == AUTOIP_STATE_ANNOUNCING); } return 0; } +u8_t +autoip_accept_packet(struct netif *netif, const ip4_addr_t *addr) +{ + struct autoip* autoip = (struct autoip*)netif->client_data[autoip_netif_client_id]; + return (autoip != NULL) && ip4_addr_cmp(addr, &(autoip->llipaddr)); +} + +void +autoip_init(void) +{ + autoip_netif_client_id = netif_alloc_client_data_id(); +} + #endif /* LWIP_IPV4 && LWIP_AUTOIP */ diff --git a/src/core/ipv4/ip4.c b/src/core/ipv4/ip4.c index b660dbbb..fb51d221 100644 --- a/src/core/ipv4/ip4.c +++ b/src/core/ipv4/ip4.c @@ -509,8 +509,7 @@ ip4_input(struct pbuf *p, struct netif *inp) #if LWIP_AUTOIP /* connections to link-local addresses must persist after changing the netif's address (RFC3927 ch. 1.9) */ - if ((netif->autoip != NULL) && - ip4_addr_cmp(ip4_current_dest_addr(), &(netif->autoip->llipaddr))) { + if (autoip_accept_packet(netif, ip4_current_dest_addr())) { LWIP_DEBUGF(IP_DEBUG, ("ip4_input: LLA packet accepted on interface %c%c\n", netif->name[0], netif->name[1])); /* break out of for loop */ diff --git a/src/core/netif.c b/src/core/netif.c index 9bad9c29..17d7fd74 100644 --- a/src/core/netif.c +++ b/src/core/netif.c @@ -241,10 +241,6 @@ netif_add(struct netif *netif, #endif /* LWIP_IPV6 */ NETIF_SET_CHECKSUM_CTRL(netif, NETIF_CHECKSUM_ENABLE_ALL); netif->flags = 0; -#if LWIP_AUTOIP - /* netif not under AutoIP control by default */ - netif->autoip = NULL; -#endif /* LWIP_AUTOIP */ #if LWIP_NUM_NETIF_CLIENT_DATA > 0 memset(netif->client_data, 0, sizeof(netif->client_data)); #endif /* LWIP_NUM_NETIF_CLIENT_DATA */ @@ -692,9 +688,7 @@ netif_set_link_up(struct netif *netif) #endif /* LWIP_DHCP */ #if LWIP_AUTOIP - if (netif->autoip) { - autoip_network_changed(netif); - } + autoip_network_changed(netif); #endif /* LWIP_AUTOIP */ if (netif->flags & NETIF_FLAG_UP) { diff --git a/src/include/lwip/autoip.h b/src/include/lwip/autoip.h index 7ad8de42..4fb01cdb 100644 --- a/src/include/lwip/autoip.h +++ b/src/include/lwip/autoip.h @@ -75,7 +75,6 @@ struct autoip }; -#define autoip_init() /* Compatibility define, no init needed. */ void autoip_set_struct(struct netif *netif, struct autoip *autoip); /** Remove a struct autoip previously set to the netif using autoip_set_struct() */ #define autoip_remove_struct(netif) do { (netif)->autoip = NULL; } while (0) @@ -85,6 +84,10 @@ void autoip_arp_reply(struct netif *netif, struct etharp_hdr *hdr); void autoip_tmr(void); void autoip_network_changed(struct netif *netif); u8_t autoip_supplied_address(const struct netif *netif); +void autoip_init(void); + +/* for lwIP internal use by ip4.c */ +u8_t autoip_accept_packet(struct netif *netif, const ip4_addr_t *addr); #ifdef __cplusplus } diff --git a/src/include/lwip/netif.h b/src/include/lwip/netif.h index df319c4d..0796cc5c 100644 --- a/src/include/lwip/netif.h +++ b/src/include/lwip/netif.h @@ -49,10 +49,6 @@ #include "lwip/pbuf.h" #include "lwip/stats.h" -#if LWIP_AUTOIP -struct autoip; -#endif - #ifdef __cplusplus extern "C" { #endif @@ -241,10 +237,6 @@ struct netif { /** This field can be set by the device driver and could point * to state information for the device. */ void *state; -#if LWIP_AUTOIP - /** the AutoIP client state information for this netif */ - struct autoip *autoip; -#endif #if LWIP_NUM_NETIF_CLIENT_DATA > 0 void* client_data[LWIP_NUM_NETIF_CLIENT_DATA]; #endif From fa6a2d48cc170bf1b860de1935917fd62f73b1c3 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Thu, 18 Aug 2016 06:09:02 +0200 Subject: [PATCH 096/325] Fix DHCP unit test after my last changes --- src/core/ipv4/dhcp.c | 2 +- src/include/lwip/dhcp.h | 2 ++ test/unit/dhcp/test_dhcp.c | 32 ++++++++++++++++---------------- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/core/ipv4/dhcp.c b/src/core/ipv4/dhcp.c index 16c7a9b4..2417a0fb 100644 --- a/src/core/ipv4/dhcp.c +++ b/src/core/ipv4/dhcp.c @@ -156,7 +156,7 @@ static u8_t xid_initialised; static struct udp_pcb *dhcp_pcb; static u8_t dhcp_pcb_refcount; -static u8_t dhcp_netif_client_id; +u8_t dhcp_netif_client_id; /* DHCP client state machine functions */ static err_t dhcp_discover(struct netif *netif); diff --git a/src/include/lwip/dhcp.h b/src/include/lwip/dhcp.h index c5b282b5..d3ad5401 100644 --- a/src/include/lwip/dhcp.h +++ b/src/include/lwip/dhcp.h @@ -120,6 +120,8 @@ void dhcp_coarse_tmr(void); void dhcp_fine_tmr(void); void dhcp_init(void); +/* for use in unit tests only */ +extern u8_t dhcp_netif_client_id; #if LWIP_DHCP_GET_NTP_SRV /** This function must exist, in other to add offered NTP servers to diff --git a/test/unit/dhcp/test_dhcp.c b/test/unit/dhcp/test_dhcp.c index 67cc7285..169a0431 100644 --- a/test/unit/dhcp/test_dhcp.c +++ b/test/unit/dhcp/test_dhcp.c @@ -448,7 +448,7 @@ START_TEST(test_dhcp) dhcp_start(&net_test); fail_unless(txpacket == 1); /* DHCP discover sent */ - xid = net_test.dhcp->xid; /* Write bad xid, not using htonl! */ + xid = ((struct dhcp*)net_test.client_data[dhcp_netif_client_id])->xid; /* Write bad xid, not using htonl! */ memcpy(&dhcp_offer[46], &xid, 4); send_pkt(&net_test, dhcp_offer, sizeof(dhcp_offer)); @@ -458,17 +458,17 @@ START_TEST(test_dhcp) fail_if(memcmp(&gw, &net_test.gw, sizeof(ip4_addr_t))); fail_unless(txpacket == 1, "TX %d packets, expected 1", txpacket); /* Nothing more sent */ - xid = htonl(net_test.dhcp->xid); + xid = htonl(((struct dhcp*)net_test.client_data[dhcp_netif_client_id])->xid); memcpy(&dhcp_offer[46], &xid, 4); /* insert correct transaction id */ send_pkt(&net_test, dhcp_offer, sizeof(dhcp_offer)); fail_unless(txpacket == 2, "TX %d packets, expected 2", txpacket); /* DHCP request sent */ - xid = net_test.dhcp->xid; /* Write bad xid, not using htonl! */ + xid = ((struct dhcp*)net_test.client_data[dhcp_netif_client_id])->xid; /* Write bad xid, not using htonl! */ memcpy(&dhcp_ack[46], &xid, 4); send_pkt(&net_test, dhcp_ack, sizeof(dhcp_ack)); fail_unless(txpacket == 2, "TX %d packets, still expected 2", txpacket); /* No more sent */ - xid = htonl(net_test.dhcp->xid); /* xid updated */ + xid = htonl(((struct dhcp*)net_test.client_data[dhcp_netif_client_id])->xid); /* xid updated */ memcpy(&dhcp_ack[46], &xid, 4); /* insert transaction id */ send_pkt(&net_test, dhcp_ack, sizeof(dhcp_ack)); @@ -517,7 +517,7 @@ START_TEST(test_dhcp_nak) dhcp_start(&net_test); fail_unless(txpacket == 1); /* DHCP discover sent */ - xid = net_test.dhcp->xid; /* Write bad xid, not using htonl! */ + xid = ((struct dhcp*)net_test.client_data[dhcp_netif_client_id])->xid; /* Write bad xid, not using htonl! */ memcpy(&dhcp_offer[46], &xid, 4); send_pkt(&net_test, dhcp_offer, sizeof(dhcp_offer)); @@ -527,17 +527,17 @@ START_TEST(test_dhcp_nak) fail_if(memcmp(&gw, &net_test.gw, sizeof(ip4_addr_t))); fail_unless(txpacket == 1); /* Nothing more sent */ - xid = htonl(net_test.dhcp->xid); + xid = htonl(((struct dhcp*)net_test.client_data[dhcp_netif_client_id])->xid); memcpy(&dhcp_offer[46], &xid, 4); /* insert correct transaction id */ send_pkt(&net_test, dhcp_offer, sizeof(dhcp_offer)); fail_unless(txpacket == 2); /* DHCP request sent */ - xid = net_test.dhcp->xid; /* Write bad xid, not using htonl! */ + xid = ((struct dhcp*)net_test.client_data[dhcp_netif_client_id])->xid; /* Write bad xid, not using htonl! */ memcpy(&dhcp_ack[46], &xid, 4); send_pkt(&net_test, dhcp_ack, sizeof(dhcp_ack)); fail_unless(txpacket == 2); /* No more sent */ - xid = htonl(net_test.dhcp->xid); /* xid updated */ + xid = htonl(((struct dhcp*)net_test.client_data[dhcp_netif_client_id])->xid); /* xid updated */ memcpy(&dhcp_ack[46], &xid, 4); /* insert transaction id */ send_pkt(&net_test, dhcp_ack, sizeof(dhcp_ack)); @@ -742,13 +742,13 @@ START_TEST(test_dhcp_relayed) fail_if(memcmp(&gw, &net_test.gw, sizeof(ip4_addr_t))); fail_unless(txpacket == 1); /* Nothing more sent */ - xid = htonl(net_test.dhcp->xid); + xid = htonl(((struct dhcp*)net_test.client_data[dhcp_netif_client_id])->xid); memcpy(&relay_offer[46], &xid, 4); /* insert correct transaction id */ send_pkt(&net_test, relay_offer, sizeof(relay_offer)); /* request sent? */ fail_unless(txpacket == 2, "txpkt = %d, should be 2", txpacket); - xid = htonl(net_test.dhcp->xid); /* xid updated */ + xid = htonl(((struct dhcp*)net_test.client_data[dhcp_netif_client_id])->xid); /* xid updated */ memcpy(&relay_ack1[46], &xid, 4); /* insert transaction id */ send_pkt(&net_test, relay_ack1, sizeof(relay_ack1)); @@ -784,7 +784,7 @@ START_TEST(test_dhcp_relayed) fail_unless(txpacket == 7, "txpacket = %d", txpacket); fail_unless(netif_is_up(&net_test)); - xid = htonl(net_test.dhcp->xid); /* xid updated */ + xid = htonl(((struct dhcp*)net_test.client_data[dhcp_netif_client_id])->xid); /* xid updated */ memcpy(&relay_ack2[46], &xid, 4); /* insert transaction id */ send_pkt(&net_test, relay_ack2, sizeof(relay_ack2)); @@ -873,7 +873,7 @@ START_TEST(test_dhcp_nak_no_endmarker) dhcp_start(&net_test); fail_unless(txpacket == 1); /* DHCP discover sent */ - xid = net_test.dhcp->xid; /* Write bad xid, not using htonl! */ + xid = ((struct dhcp*)net_test.client_data[dhcp_netif_client_id])->xid; /* Write bad xid, not using htonl! */ memcpy(&dhcp_offer[46], &xid, 4); send_pkt(&net_test, dhcp_offer, sizeof(dhcp_offer)); @@ -883,19 +883,19 @@ START_TEST(test_dhcp_nak_no_endmarker) fail_if(memcmp(&gw, &net_test.gw, sizeof(ip4_addr_t))); fail_unless(txpacket == 1); /* Nothing more sent */ - xid = htonl(net_test.dhcp->xid); + xid = htonl(((struct dhcp*)net_test.client_data[dhcp_netif_client_id])->xid); memcpy(&dhcp_offer[46], &xid, 4); /* insert correct transaction id */ send_pkt(&net_test, dhcp_offer, sizeof(dhcp_offer)); - fail_unless(net_test.dhcp->state == DHCP_STATE_REQUESTING); + fail_unless(((struct dhcp*)net_test.client_data[dhcp_netif_client_id])->state == DHCP_STATE_REQUESTING); fail_unless(txpacket == 2); /* No more sent */ - xid = htonl(net_test.dhcp->xid); /* xid updated */ + xid = htonl(((struct dhcp*)net_test.client_data[dhcp_netif_client_id])->xid); /* xid updated */ memcpy(&dhcp_nack_no_endmarker[46], &xid, 4); /* insert transaction id */ send_pkt(&net_test, dhcp_nack_no_endmarker, sizeof(dhcp_nack_no_endmarker)); /* NAK should put us in another state for a while, no other way detecting it */ - fail_unless(net_test.dhcp->state != DHCP_STATE_REQUESTING); + fail_unless(((struct dhcp*)net_test.client_data[dhcp_netif_client_id])->state != DHCP_STATE_REQUESTING); netif_remove(&net_test); } From a262a2f25264f5e01cb5983215390c5d0e46113c Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Thu, 18 Aug 2016 10:59:08 +0200 Subject: [PATCH 097/325] MDNS: Add callback to be called manually when IP has changed to announce new IP --- src/apps/mdns/mdns.c | 39 +++++++++++++++++++++++++++--------- src/include/lwip/apps/mdns.h | 1 + 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/apps/mdns/mdns.c b/src/apps/mdns/mdns.c index d6c2b4b2..6ec1cb00 100644 --- a/src/apps/mdns/mdns.c +++ b/src/apps/mdns/mdns.c @@ -18,7 +18,7 @@ * - Checking that source address of unicast requests are on the same network * - Limiting multicast responses to 1 per second per resource record * - Fragmenting replies if required - * - Subscribe to netif address/link change events and act on them + * - Subscribe to netif address/link change events and act on them (currently needs to be done manually) * - Handling multi-packet known answers * - Individual known answer detection for all local IPv6 addresses * - Dynamic size of outgoing packet @@ -1510,7 +1510,7 @@ mdns_announce(struct netif *netif, const ip_addr_t *destination) } announce.dest_port = MDNS_PORT; - memcpy(&announce.dest_addr, destination, sizeof(ip_addr_t)); + memcpy(&announce.dest_addr, destination, sizeof(announce.dest_addr)); mdns_send_outpacket(&announce); } @@ -1858,6 +1858,32 @@ mdns_resp_init(void) mdns_netif_client_id = netif_alloc_client_data_id(); } +/** + * @ingroup mdns + * Announce IP settings have changed on netif. + * Call this in your callback registered by netif_set_status_callback(). + * This function may go away in the future when netif supports registering + * multiple callback functions. + * @param netif The network interface where settings have changed. + */ +void +mdns_resp_netif_settings_changed(struct netif *netif) +{ + LWIP_ERROR("mdns_resp_netif_ip_changed: netif != NULL", (netif != NULL), return); + + if (netif->client_data[mdns_netif_client_id] == NULL) { + return; + } + + /* Announce on IPv6 and IPv4 */ +#if LWIP_IPV6 + mdns_announce(netif, IP6_ADDR_ANY); +#endif +#if LWIP_IPV4 + mdns_announce(netif, IP_ADDR_ANY); +#endif +} + /** * @ingroup mdns * Activate MDNS responder for a network interface and send announce packets. @@ -1901,14 +1927,7 @@ mdns_resp_add_netif(struct netif *netif, const char *hostname, u32_t dns_ttl) } #endif - /* Announce on IPv6 and IPv4 */ -#if LWIP_IPV6 - mdns_announce(netif, IP6_ADDR_ANY); -#endif -#if LWIP_IPV4 - mdns_announce(netif, IP_ADDR_ANY); -#endif - + mdns_resp_netif_settings_changed(netif); return ERR_OK; cleanup: diff --git a/src/include/lwip/apps/mdns.h b/src/include/lwip/apps/mdns.h index f49cdf9f..302bdf6a 100644 --- a/src/include/lwip/apps/mdns.h +++ b/src/include/lwip/apps/mdns.h @@ -58,6 +58,7 @@ err_t mdns_resp_remove_netif(struct netif *netif); typedef void (*service_get_txt_fn_t)(struct mdns_service *service, void *txt_userdata); err_t mdns_resp_add_service(struct netif *netif, const char *name, const char *service, u16_t proto, u16_t port, u32_t dns_ttl, service_get_txt_fn_t txt_fn, void *txt_userdata); err_t mdns_resp_add_service_txtitem(struct mdns_service *service, const char *txt, u8_t txt_len); +void mdns_resp_netif_settings_changed(struct netif *netif); /* Domain struct and methods - visible for unit tests */ From c9ad58308a54913a585de07dc8082256847c03c8 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Thu, 18 Aug 2016 10:59:18 +0200 Subject: [PATCH 098/325] Minor documentation fixes --- doc/doxygen/lwip.Doxyfile | 3 ++- src/core/ipv4/autoip.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/doxygen/lwip.Doxyfile b/doc/doxygen/lwip.Doxyfile index 5b8bda3b..c3f17d23 100644 --- a/doc/doxygen/lwip.Doxyfile +++ b/doc/doxygen/lwip.Doxyfile @@ -2085,7 +2085,7 @@ PREDEFINED = __DOXYGEN__=1 \ SNMP_USE_NETCONN=1 \ SNMP_USE_RAW=1 \ MIB2_STATS=1 \ - LWIP_MDNS=1 \ + LWIP_MDNS_RESPONDER=1 \ MEMP_OVERFLOW_CHECK=0 \ MEMP_SANITY_CHECK=1 \ LWIP_ARP=1 \ @@ -2093,6 +2093,7 @@ PREDEFINED = __DOXYGEN__=1 \ LWIP_NETIF_HOSTNAME=1 \ LWIP_NETIF_API=1 \ LWIP_NETIF_CALLBACK=1 \ + LWIP_NETIF_STATUS_CALLBACK=1 \ LWIP_NETIF_REMOVE_CALLBACK=1 \ LWIP_NETIF_LINK_CALLBACK=1 \ ENABLE_LOOPBACK=1 \ diff --git a/src/core/ipv4/autoip.c b/src/core/ipv4/autoip.c index 44b35431..33249786 100644 --- a/src/core/ipv4/autoip.c +++ b/src/core/ipv4/autoip.c @@ -12,7 +12,7 @@ * * define @ref LWIP_AUTOIP 1 in your lwipopts.h * Options: - * @ref AUTOIP_TMR_INTERVAL msecs, + * AUTOIP_TMR_INTERVAL msecs, * I recommend a value of 100. The value must divide 1000 with a remainder almost 0. * Possible values are 1000, 500, 333, 250, 200, 166, 142, 125, 111, 100 .... * From 0c7a59b5dba98e4b48489a86cdcb3b43b71c409b Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Thu, 18 Aug 2016 11:06:50 +0200 Subject: [PATCH 099/325] Minor: Documentation fixes --- doc/doxygen/lwip.Doxyfile | 6 ++--- doc/mdns.txt | 8 ++++-- src/core/dns.c | 54 +++++++++++++++++++-------------------- 3 files changed, 34 insertions(+), 34 deletions(-) diff --git a/doc/doxygen/lwip.Doxyfile b/doc/doxygen/lwip.Doxyfile index c3f17d23..8a638ba8 100644 --- a/doc/doxygen/lwip.Doxyfile +++ b/doc/doxygen/lwip.Doxyfile @@ -2113,10 +2113,8 @@ PREDEFINED = __DOXYGEN__=1 \ SO_REUSE=1 \ SO_REUSE_RXTOALL=1 \ LWIP_HAVE_SLIPIF=1 \ - LWIP_6LOWPAN=1 \ - "LWIP_DNS && LWIP_SOCKET " \ - "(LWIP_DNS && LWIP_SOCKET)=1 " - + LWIP_6LOWPAN=1 + # If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this # tag can be used to specify a list of macro names that should be expanded. The # macro definition that is found in the sources will be used. Use the PREDEFINED diff --git a/doc/mdns.txt b/doc/mdns.txt index 699ccbfc..c3228432 100644 --- a/doc/mdns.txt +++ b/doc/mdns.txt @@ -16,13 +16,14 @@ MDNS support does not depend on DNS. MDNS supports using IPv4 only, v6 only, or v4+v6. To enable MDNS responder, set - LWIP_MDNS = 1 + LWIP_MDNS_RESPONDER = 1 in lwipopts.h and add src/apps/mdns/mdns.c to your list of files to build. The max number of services supported per netif is defined by MDNS_MAX_SERVICES, default is 1. -Increase MEMP_NUM_UDP_PCB. MDNS needs one PCB. +Increase MEMP_NUM_UDP_PCB by 1. MDNS needs one PCB. +Increase LWIP_NUM_NETIF_CLIENT_DATA by 1 (MDNS needs one entry on netif). MDNS with IPv4 requires LWIP_IGMP = 1, and preferably LWIP_AUTOIP = 1. MDNS with IPv6 requires LWIP_IPV6_MLD = 1, and that a link-local address is @@ -59,6 +60,9 @@ since the default case-insensitive comparison assumes this. It is recommended to call this function after an IPv4 address has been set, since there is currently no check if the v4 address is valid. +Call mdns_resp_netif_settings_changed() every time the IP address +on the netif has changed. + To stop responding on a netif, run mdns_resp_remove_netif(struct netif *netif) diff --git a/src/core/dns.c b/src/core/dns.c index d9d7add7..6ad0b4b7 100644 --- a/src/core/dns.c +++ b/src/core/dns.c @@ -1,6 +1,32 @@ /** * @file * DNS - host name to IP address resolver. + * + * @defgroup dns DNS + * @ingroup callbackstyle_api + * + * Implements a DNS host name to IP address resolver. + * + * The lwIP DNS resolver functions are used to lookup a host name and + * map it to a numerical IP address. It maintains a list of resolved + * hostnames that can be queried with the dns_lookup() function. + * New hostnames can be resolved using the dns_query() function. + * + * The lwIP version of the resolver also adds a non-blocking version of + * gethostbyname() that will work with a raw API application. This function + * checks for an IP address string first and converts it if it is valid. + * gethostbyname() then does a dns_lookup() to see if the name is + * already in the table. If so, the IP is returned. If not, a query is + * issued and the function returns with a ERR_INPROGRESS status. The app + * using the dns client must then go into a waiting state. + * + * Once a hostname has been resolved (or found to be non-existent), + * the resolver code calls a specified callback function (which + * must be implemented by the module that uses the resolver). + * + * All functions must be called from TCPIP thread. + * + * @see @ref netconn_common for thread-safe access. */ /* @@ -37,34 +63,6 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -/** - * @defgroup dns DNS - * @ingroup callbackstyle_api - * - * Implements a DNS host name to IP address resolver. - * - * The lwIP DNS resolver functions are used to lookup a host name and - * map it to a numerical IP address. It maintains a list of resolved - * hostnames that can be queried with the dns_lookup() function. - * New hostnames can be resolved using the dns_query() function. - * - * The lwIP version of the resolver also adds a non-blocking version of - * gethostbyname() that will work with a raw API application. This function - * checks for an IP address string first and converts it if it is valid. - * gethostbyname() then does a dns_lookup() to see if the name is - * already in the table. If so, the IP is returned. If not, a query is - * issued and the function returns with a ERR_INPROGRESS status. The app - * using the dns client must then go into a waiting state. - * - * Once a hostname has been resolved (or found to be non-existent), - * the resolver code calls a specified callback function (which - * must be implemented by the module that uses the resolver). - * - * All functions must be called from TCPIP thread. - * - * @see @ref netconn_common for thread-safe access. - */ - /*----------------------------------------------------------------------------- * RFC 1035 - Domain names - implementation and specification * RFC 2181 - Clarifications to the DNS Specification From ebf7959880736796aa32927aa47117f74f329286 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Thu, 18 Aug 2016 11:44:19 +0200 Subject: [PATCH 100/325] Coding style fixes in netif.c --- src/core/netif.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/core/netif.c b/src/core/netif.c index 17d7fd74..cb759f5f 100644 --- a/src/core/netif.c +++ b/src/core/netif.c @@ -91,6 +91,10 @@ struct netif *netif_default; static u8_t netif_num; +#if LWIP_NUM_NETIF_CLIENT_DATA > 0 +static u8_t netif_client_id = 0; +#endif + #define NETIF_REPORT_TYPE_IPV4 0x01 #define NETIF_REPORT_TYPE_IPV6 0x02 static void netif_issue_reports(struct netif* netif, u8_t report_type); @@ -933,20 +937,19 @@ netif_poll_all(void) #endif /* ENABLE_LOOPBACK */ #if LWIP_NUM_NETIF_CLIENT_DATA > 0 -static u8_t netif_client_id = 0; - /** * @ingroup netif * Allocate an index to store data in client_data member of struct netif. * Returned value is an index in mentioned array. * @see LWIP_NUM_NETIF_CLIENT_DATA */ -u8_t netif_alloc_client_data_id(void) +u8_t +netif_alloc_client_data_id(void) { - u8_t result = netif_client_id; - netif_client_id++; - LWIP_ASSERT("Increase LWIP_NUM_NETIF_CLIENT_DATA in lwipopts.h", netif_client_id<=LWIP_NUM_NETIF_CLIENT_DATA); - return result; + u8_t result = netif_client_id; + netif_client_id++; + LWIP_ASSERT("Increase LWIP_NUM_NETIF_CLIENT_DATA in lwipopts.h", netif_client_id<=LWIP_NUM_NETIF_CLIENT_DATA); + return result; } #endif From 7f60cb3889f5f31299d34bc7fc1f9d1913d598c3 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Thu, 18 Aug 2016 12:37:21 +0200 Subject: [PATCH 101/325] Improve netif client data API for lwIP internal clients - these can use a compile-time constant to access their data now --- src/core/init.c | 8 ----- src/core/ipv4/autoip.c | 44 ++++++++++--------------- src/core/ipv4/dhcp.c | 67 +++++++++++++++++--------------------- src/core/netif.c | 9 ++--- src/include/lwip/autoip.h | 1 - src/include/lwip/dhcp.h | 4 --- src/include/lwip/netif.h | 15 +++++++-- src/include/lwip/opt.h | 4 +-- test/unit/dhcp/test_dhcp.c | 32 +++++++++--------- test/unit/lwipopts.h | 1 + 10 files changed, 85 insertions(+), 100 deletions(-) diff --git a/src/core/init.c b/src/core/init.c index a02c8bd6..182aaff7 100644 --- a/src/core/init.c +++ b/src/core/init.c @@ -49,8 +49,6 @@ #include "lwip/raw.h" #include "lwip/udp.h" #include "lwip/priv/tcp_priv.h" -#include "lwip/autoip.h" -#include "lwip/dhcp.h" #include "lwip/igmp.h" #include "lwip/dns.h" #include "lwip/timeouts.h" @@ -349,12 +347,6 @@ lwip_init(void) #if LWIP_TCP tcp_init(); #endif /* LWIP_TCP */ -#if LWIP_AUTOIP - autoip_init(); -#endif /* LWIP_AUTOIP */ -#if LWIP_DHCP - dhcp_init(); -#endif /* LWIP_DHCP */ #if LWIP_IGMP igmp_init(); #endif /* LWIP_IGMP */ diff --git a/src/core/ipv4/autoip.c b/src/core/ipv4/autoip.c index 33249786..1da929c0 100644 --- a/src/core/ipv4/autoip.c +++ b/src/core/ipv4/autoip.c @@ -71,8 +71,6 @@ #include #include -static u8_t autoip_netif_client_id; - /** Pseudo random macro based on netif informations. * You could use "rand()" from the C Library if you define LWIP_AUTOIP_RAND in lwipopts.h */ #ifndef LWIP_AUTOIP_RAND @@ -80,7 +78,7 @@ static u8_t autoip_netif_client_id; ((u32_t)((netif->hwaddr[3]) & 0xff) << 16) | \ ((u32_t)((netif->hwaddr[2]) & 0xff) << 8) | \ ((u32_t)((netif->hwaddr[4]) & 0xff))) + \ - (netif->client_data[autoip_netif_client_id]? ((struct autoip*)netif->client_data[autoip_netif_client_id])->tried_llipaddr : 0)) + (netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP]? ((struct autoip*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP])->tried_llipaddr : 0)) #endif /* LWIP_AUTOIP_RAND */ /** @@ -112,12 +110,12 @@ autoip_set_struct(struct netif *netif, struct autoip *autoip) LWIP_ASSERT("netif != NULL", netif != NULL); LWIP_ASSERT("autoip != NULL", autoip != NULL); LWIP_ASSERT("netif already has a struct autoip set", - netif->client_data[autoip_netif_client_id] == NULL); + netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP] == NULL); /* clear data structure */ memset(autoip, 0, sizeof(struct autoip)); /* autoip->state = AUTOIP_STATE_OFF; */ - netif->client_data[autoip_netif_client_id] = autoip; + netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP] = autoip; } /** Restart AutoIP client and check the next address (conflict detected) @@ -127,7 +125,7 @@ autoip_set_struct(struct netif *netif, struct autoip *autoip) static void autoip_restart(struct netif *netif) { - struct autoip* autoip = (struct autoip*)netif->client_data[autoip_netif_client_id]; + struct autoip* autoip = (struct autoip*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP]; autoip->tried_llipaddr++; autoip_start(netif); } @@ -138,7 +136,7 @@ autoip_restart(struct netif *netif) static void autoip_handle_arp_conflict(struct netif *netif) { - struct autoip* autoip = (struct autoip*)netif->client_data[autoip_netif_client_id]; + struct autoip* autoip = (struct autoip*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP]; /* RFC3927, 2.5 "Conflict Detection and Defense" allows two options where a) means retreat on the first conflict and @@ -171,7 +169,7 @@ autoip_handle_arp_conflict(struct netif *netif) static void autoip_create_addr(struct netif *netif, ip4_addr_t *ipaddr) { - struct autoip* autoip = (struct autoip*)netif->client_data[autoip_netif_client_id]; + struct autoip* autoip = (struct autoip*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP]; /* Here we create an IP-Address out of range 169.254.1.0 to 169.254.254.255 * compliant to RFC 3927 Section 2.1 @@ -206,7 +204,7 @@ autoip_create_addr(struct netif *netif, ip4_addr_t *ipaddr) static err_t autoip_arp_probe(struct netif *netif) { - struct autoip* autoip = (struct autoip*)netif->client_data[autoip_netif_client_id]; + struct autoip* autoip = (struct autoip*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP]; /* this works because netif->ip_addr is ANY */ return etharp_request(netif, &autoip->llipaddr); } @@ -230,7 +228,7 @@ autoip_arp_announce(struct netif *netif) static err_t autoip_bind(struct netif *netif) { - struct autoip* autoip = (struct autoip*)netif->client_data[autoip_netif_client_id]; + struct autoip* autoip = (struct autoip*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP]; ip4_addr_t sn_mask, gw_addr; LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE, @@ -257,7 +255,7 @@ autoip_bind(struct netif *netif) err_t autoip_start(struct netif *netif) { - struct autoip* autoip = (struct autoip*)netif->client_data[autoip_netif_client_id]; + struct autoip* autoip = (struct autoip*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP]; err_t result = ERR_OK; LWIP_ERROR("netif is not up, old style port?", netif_is_up(netif), return ERR_ARG;); @@ -282,7 +280,7 @@ autoip_start(struct netif *netif) } memset(autoip, 0, sizeof(struct autoip)); /* store this AutoIP client in the netif */ - netif->client_data[autoip_netif_client_id] = autoip; + netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP] = autoip; LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE, ("autoip_start(): allocated autoip")); } else { autoip->state = AUTOIP_STATE_OFF; @@ -301,7 +299,7 @@ autoip_start(struct netif *netif) static void autoip_start_probing(struct netif *netif) { - struct autoip* autoip = (struct autoip*)netif->client_data[autoip_netif_client_id]; + struct autoip* autoip = (struct autoip*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP]; autoip->state = AUTOIP_STATE_PROBING; autoip->sent_num = 0; @@ -335,7 +333,7 @@ autoip_start_probing(struct netif *netif) void autoip_network_changed(struct netif *netif) { - struct autoip* autoip = (struct autoip*)netif->client_data[autoip_netif_client_id]; + struct autoip* autoip = (struct autoip*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP]; if (autoip && (autoip->state != AUTOIP_STATE_OFF)) { autoip_start_probing(netif); @@ -351,7 +349,7 @@ autoip_network_changed(struct netif *netif) err_t autoip_stop(struct netif *netif) { - struct autoip* autoip = (struct autoip*)netif->client_data[autoip_netif_client_id]; + struct autoip* autoip = (struct autoip*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP]; if (autoip != NULL) { autoip->state = AUTOIP_STATE_OFF; @@ -371,7 +369,7 @@ autoip_tmr(void) struct netif *netif = netif_list; /* loop through netif's */ while (netif != NULL) { - struct autoip* autoip = (struct autoip*)netif->client_data[autoip_netif_client_id]; + struct autoip* autoip = (struct autoip*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP]; /* only act on AutoIP configured interfaces */ if (autoip != NULL) { if (autoip->lastconflict > 0) { @@ -456,7 +454,7 @@ autoip_tmr(void) void autoip_arp_reply(struct netif *netif, struct etharp_hdr *hdr) { - struct autoip* autoip = (struct autoip*)netif->client_data[autoip_netif_client_id]; + struct autoip* autoip = (struct autoip*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP]; LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE, ("autoip_arp_reply()\n")); if ((autoip != NULL) && (autoip->state != AUTOIP_STATE_OFF)) { @@ -513,8 +511,8 @@ autoip_arp_reply(struct netif *netif, struct etharp_hdr *hdr) u8_t autoip_supplied_address(const struct netif *netif) { - if ((netif != NULL) && (netif->client_data[autoip_netif_client_id] != NULL)) { - struct autoip* autoip = (struct autoip*)netif->client_data[autoip_netif_client_id]; + if ((netif != NULL) && (netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP] != NULL)) { + struct autoip* autoip = (struct autoip*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP]; return (autoip->state == AUTOIP_STATE_BOUND) || (autoip->state == AUTOIP_STATE_ANNOUNCING); } return 0; @@ -523,14 +521,8 @@ autoip_supplied_address(const struct netif *netif) u8_t autoip_accept_packet(struct netif *netif, const ip4_addr_t *addr) { - struct autoip* autoip = (struct autoip*)netif->client_data[autoip_netif_client_id]; + struct autoip* autoip = (struct autoip*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP]; return (autoip != NULL) && ip4_addr_cmp(addr, &(autoip->llipaddr)); } -void -autoip_init(void) -{ - autoip_netif_client_id = netif_alloc_client_data_id(); -} - #endif /* LWIP_IPV4 && LWIP_AUTOIP */ diff --git a/src/core/ipv4/dhcp.c b/src/core/ipv4/dhcp.c index 2417a0fb..b1180627 100644 --- a/src/core/ipv4/dhcp.c +++ b/src/core/ipv4/dhcp.c @@ -156,7 +156,6 @@ static u8_t xid_initialised; static struct udp_pcb *dhcp_pcb; static u8_t dhcp_pcb_refcount; -u8_t dhcp_netif_client_id; /* DHCP client state machine functions */ static err_t dhcp_discover(struct netif *netif); @@ -249,7 +248,7 @@ dhcp_dec_pcb_refcount(void) static void dhcp_handle_nak(struct netif *netif) { - struct dhcp *dhcp = (struct dhcp*)netif->client_data[dhcp_netif_client_id]; + struct dhcp *dhcp = (struct dhcp*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP]; LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_handle_nak(netif=%p) %c%c%"U16_F"\n", (void*)netif, netif->name[0], netif->name[1], (u16_t)netif->num)); @@ -275,7 +274,7 @@ dhcp_handle_nak(struct netif *netif) static void dhcp_check(struct netif *netif) { - struct dhcp *dhcp = (struct dhcp*)netif->client_data[dhcp_netif_client_id]; + struct dhcp *dhcp = (struct dhcp*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP]; err_t result; u16_t msecs; LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_check(netif=%p) %c%c\n", (void *)netif, (s16_t)netif->name[0], @@ -304,7 +303,7 @@ dhcp_check(struct netif *netif) static void dhcp_handle_offer(struct netif *netif) { - struct dhcp *dhcp = (struct dhcp*)netif->client_data[dhcp_netif_client_id]; + struct dhcp *dhcp = (struct dhcp*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP]; LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_handle_offer(netif=%p) %c%c%"U16_F"\n", (void*)netif, netif->name[0], netif->name[1], (u16_t)netif->num)); @@ -336,7 +335,7 @@ dhcp_handle_offer(struct netif *netif) static err_t dhcp_select(struct netif *netif) { - struct dhcp *dhcp = (struct dhcp*)netif->client_data[dhcp_netif_client_id]; + struct dhcp *dhcp = (struct dhcp*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP]; err_t result; u16_t msecs; u8_t i; @@ -398,7 +397,7 @@ dhcp_coarse_tmr(void) /* iterate through all network interfaces */ while (netif != NULL) { /* only act on DHCP configured interfaces */ - struct dhcp *dhcp = (struct dhcp*)netif->client_data[dhcp_netif_client_id]; + struct dhcp *dhcp = (struct dhcp*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP]; if ((dhcp != NULL) && (dhcp->state != DHCP_STATE_OFF)) { /* compare lease time to expire timeout */ if (dhcp->t0_timeout && (++dhcp->lease_used == dhcp->t0_timeout)) { @@ -436,7 +435,7 @@ dhcp_fine_tmr(void) struct netif *netif = netif_list; /* loop through netif's */ while (netif != NULL) { - struct dhcp *dhcp = (struct dhcp*)netif->client_data[dhcp_netif_client_id]; + struct dhcp *dhcp = (struct dhcp*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP]; /* only act on DHCP configured interfaces */ if (dhcp != NULL) { /* timer is active (non zero), and is about to trigger now */ @@ -467,7 +466,7 @@ dhcp_fine_tmr(void) static void dhcp_timeout(struct netif *netif) { - struct dhcp *dhcp = (struct dhcp*)netif->client_data[dhcp_netif_client_id]; + struct dhcp *dhcp = (struct dhcp*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP]; LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_timeout()\n")); /* back-off period has passed, or server selection timed out */ @@ -514,7 +513,7 @@ dhcp_timeout(struct netif *netif) static void dhcp_t1_timeout(struct netif *netif) { - struct dhcp *dhcp = (struct dhcp*)netif->client_data[dhcp_netif_client_id]; + struct dhcp *dhcp = (struct dhcp*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP]; LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_STATE, ("dhcp_t1_timeout()\n")); if ((dhcp->state == DHCP_STATE_REQUESTING) || (dhcp->state == DHCP_STATE_BOUND) || @@ -542,7 +541,7 @@ dhcp_t1_timeout(struct netif *netif) static void dhcp_t2_timeout(struct netif *netif) { - struct dhcp *dhcp = (struct dhcp*)netif->client_data[dhcp_netif_client_id]; + struct dhcp *dhcp = (struct dhcp*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP]; LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_t2_timeout()\n")); if ((dhcp->state == DHCP_STATE_REQUESTING) || (dhcp->state == DHCP_STATE_BOUND) || @@ -569,7 +568,7 @@ dhcp_t2_timeout(struct netif *netif) static void dhcp_handle_ack(struct netif *netif) { - struct dhcp *dhcp = (struct dhcp*)netif->client_data[dhcp_netif_client_id]; + struct dhcp *dhcp = (struct dhcp*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP]; #if LWIP_DNS || LWIP_DHCP_GET_NTP_SRV u8_t n; @@ -662,12 +661,12 @@ dhcp_set_struct(struct netif *netif, struct dhcp *dhcp) { LWIP_ASSERT("netif != NULL", netif != NULL); LWIP_ASSERT("dhcp != NULL", dhcp != NULL); - LWIP_ASSERT("netif already has a struct dhcp set", netif->client_data[dhcp_netif_client_id] == NULL); + LWIP_ASSERT("netif already has a struct dhcp set", netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP] == NULL); /* clear data structure */ memset(dhcp, 0, sizeof(struct dhcp)); /* dhcp_set_state(&dhcp, DHCP_STATE_OFF); */ - netif->client_data[dhcp_netif_client_id] = dhcp; + netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP] = dhcp; } /** @@ -683,9 +682,9 @@ void dhcp_cleanup(struct netif *netif) { LWIP_ASSERT("netif != NULL", netif != NULL); - if (netif->client_data[dhcp_netif_client_id] != NULL) { - mem_free(netif->client_data[dhcp_netif_client_id]); - netif->client_data[dhcp_netif_client_id] = NULL; + if (netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP] != NULL) { + mem_free(netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP]); + netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP] = NULL; } } @@ -710,7 +709,7 @@ dhcp_start(struct netif *netif) LWIP_ERROR("netif != NULL", (netif != NULL), return ERR_ARG;); LWIP_ERROR("netif is not up, old style port?", netif_is_up(netif), return ERR_ARG;); - dhcp = (struct dhcp*)netif->client_data[dhcp_netif_client_id]; + dhcp = (struct dhcp*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP]; 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)); /* check MTU of the netif */ @@ -729,7 +728,7 @@ dhcp_start(struct netif *netif) } /* store this dhcp client in the netif */ - netif->client_data[dhcp_netif_client_id] = dhcp; + netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP] = dhcp; LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_start(): allocated dhcp")); /* already has DHCP client attached */ } else { @@ -828,7 +827,7 @@ dhcp_inform(struct netif *netif) void dhcp_network_changed(struct netif *netif) { - struct dhcp *dhcp = (struct dhcp*)netif->client_data[dhcp_netif_client_id]; + struct dhcp *dhcp = (struct dhcp*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP]; if (!dhcp) return; @@ -874,7 +873,7 @@ dhcp_arp_reply(struct netif *netif, const ip4_addr_t *addr) struct dhcp *dhcp; LWIP_ERROR("netif != NULL", (netif != NULL), return;); - dhcp = (struct dhcp*)netif->client_data[dhcp_netif_client_id]; + dhcp = (struct dhcp*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP]; LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_arp_reply()\n")); /* is a DHCP client doing an ARP check? */ if ((dhcp != NULL) && (dhcp->state == DHCP_STATE_CHECKING)) { @@ -903,7 +902,7 @@ dhcp_arp_reply(struct netif *netif, const ip4_addr_t *addr) static err_t dhcp_decline(struct netif *netif) { - struct dhcp *dhcp = (struct dhcp*)netif->client_data[dhcp_netif_client_id]; + struct dhcp *dhcp = (struct dhcp*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP]; err_t result = ERR_OK; u16_t msecs; LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_decline()\n")); @@ -945,7 +944,7 @@ dhcp_decline(struct netif *netif) static err_t dhcp_discover(struct netif *netif) { - struct dhcp *dhcp = (struct dhcp*)netif->client_data[dhcp_netif_client_id]; + struct dhcp *dhcp = (struct dhcp*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP]; err_t result = ERR_OK; u16_t msecs; u8_t i; @@ -1005,7 +1004,7 @@ dhcp_bind(struct netif *netif) struct dhcp *dhcp; ip4_addr_t sn_mask, gw_addr; LWIP_ERROR("dhcp_bind: netif != NULL", (netif != NULL), return;); - dhcp = (struct dhcp*)netif->client_data[dhcp_netif_client_id]; + dhcp = (struct dhcp*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP]; LWIP_ERROR("dhcp_bind: dhcp != NULL", (dhcp != NULL), return;); LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_bind(netif=%p) %c%c%"U16_F"\n", (void*)netif, netif->name[0], netif->name[1], (u16_t)netif->num)); @@ -1111,7 +1110,7 @@ dhcp_bind(struct netif *netif) err_t dhcp_renew(struct netif *netif) { - struct dhcp *dhcp = (struct dhcp*)netif->client_data[dhcp_netif_client_id]; + struct dhcp *dhcp = (struct dhcp*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP]; err_t result; u16_t msecs; u8_t i; @@ -1163,7 +1162,7 @@ dhcp_renew(struct netif *netif) static err_t dhcp_rebind(struct netif *netif) { - struct dhcp *dhcp = (struct dhcp*)netif->client_data[dhcp_netif_client_id]; + struct dhcp *dhcp = (struct dhcp*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP]; err_t result; u16_t msecs; u8_t i; @@ -1213,7 +1212,7 @@ dhcp_rebind(struct netif *netif) static err_t dhcp_reboot(struct netif *netif) { - struct dhcp *dhcp = (struct dhcp*)netif->client_data[dhcp_netif_client_id]; + struct dhcp *dhcp = (struct dhcp*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP]; err_t result; u16_t msecs; u8_t i; @@ -1264,7 +1263,7 @@ dhcp_reboot(struct netif *netif) err_t dhcp_release(struct netif *netif) { - struct dhcp *dhcp = (struct dhcp*)netif->client_data[dhcp_netif_client_id]; + struct dhcp *dhcp = (struct dhcp*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP]; err_t result; ip_addr_t server_ip_addr; u8_t is_dhcp_supplied_address; @@ -1329,7 +1328,7 @@ dhcp_stop(struct netif *netif) { struct dhcp *dhcp; LWIP_ERROR("dhcp_stop: netif != NULL", (netif != NULL), return;); - dhcp = (struct dhcp*)netif->client_data[dhcp_netif_client_id]; + dhcp = (struct dhcp*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP]; LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_stop()\n")); /* netif is DHCP configured? */ @@ -1654,7 +1653,7 @@ static void dhcp_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, u16_t port) { struct netif *netif = ip_current_input_netif(); - struct dhcp *dhcp = (struct dhcp*)netif->client_data[dhcp_netif_client_id]; + struct dhcp *dhcp = (struct dhcp*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP]; struct dhcp_msg *reply_msg = (struct dhcp_msg *)p->payload; u8_t msg_type; u8_t i; @@ -1916,17 +1915,11 @@ dhcp_option_trailer(struct dhcp *dhcp) u8_t dhcp_supplied_address(const struct netif *netif) { - if ((netif != NULL) && (netif->client_data[dhcp_netif_client_id] != NULL)) { - struct dhcp* dhcp = (struct dhcp*)netif->client_data[dhcp_netif_client_id]; + if ((netif != NULL) && (netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP] != NULL)) { + struct dhcp* dhcp = (struct dhcp*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP]; return (dhcp->state == DHCP_STATE_BOUND) || (dhcp->state == DHCP_STATE_RENEWING); } return 0; } -void -dhcp_init(void) -{ - dhcp_netif_client_id = netif_alloc_client_data_id(); -} - #endif /* LWIP_IPV4 && LWIP_DHCP */ diff --git a/src/core/netif.c b/src/core/netif.c index cb759f5f..dfc25324 100644 --- a/src/core/netif.c +++ b/src/core/netif.c @@ -92,7 +92,7 @@ struct netif *netif_default; static u8_t netif_num; #if LWIP_NUM_NETIF_CLIENT_DATA > 0 -static u8_t netif_client_id = 0; +static u8_t netif_client_id; #endif #define NETIF_REPORT_TYPE_IPV4 0x01 @@ -245,7 +245,7 @@ netif_add(struct netif *netif, #endif /* LWIP_IPV6 */ NETIF_SET_CHECKSUM_CTRL(netif, NETIF_CHECKSUM_ENABLE_ALL); netif->flags = 0; -#if LWIP_NUM_NETIF_CLIENT_DATA > 0 +#if LWIP_DHCP || LWIP_AUTOIP || (LWIP_NUM_NETIF_CLIENT_DATA > 0) memset(netif->client_data, 0, sizeof(netif->client_data)); #endif /* LWIP_NUM_NETIF_CLIENT_DATA */ #if LWIP_IPV6_AUTOCONFIG @@ -948,8 +948,9 @@ netif_alloc_client_data_id(void) { u8_t result = netif_client_id; netif_client_id++; - LWIP_ASSERT("Increase LWIP_NUM_NETIF_CLIENT_DATA in lwipopts.h", netif_client_id<=LWIP_NUM_NETIF_CLIENT_DATA); - return result; + + LWIP_ASSERT("Increase LWIP_NUM_NETIF_CLIENT_DATA in lwipopts.h", result 0 - void* client_data[LWIP_NUM_NETIF_CLIENT_DATA]; +#if LWIP_DHCP || LWIP_AUTOIP || (LWIP_NUM_NETIF_CLIENT_DATA > 0) + void* client_data[LWIP_NETIF_CLIENT_DATA_INDEX_MAX + LWIP_NUM_NETIF_CLIENT_DATA]; #endif #if LWIP_IPV6_AUTOCONFIG /** is this netif enabled for IPv6 autoconfiguration */ diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h index f65c7b8c..24a9fc68 100644 --- a/src/include/lwip/opt.h +++ b/src/include/lwip/opt.h @@ -1468,10 +1468,10 @@ /** * LWIP_NUM_NETIF_CLIENT_DATA: Number of clients that may store - * per data in client_data member array of struct netif. + * data in client_data member array of struct netif. */ #if !defined LWIP_NUM_NETIF_CLIENT_DATA || defined __DOXYGEN__ -#define LWIP_NUM_NETIF_CLIENT_DATA (LWIP_DHCP + LWIP_AUTOIP) +#define LWIP_NUM_NETIF_CLIENT_DATA 0 #endif /** * @} diff --git a/test/unit/dhcp/test_dhcp.c b/test/unit/dhcp/test_dhcp.c index 169a0431..850c213f 100644 --- a/test/unit/dhcp/test_dhcp.c +++ b/test/unit/dhcp/test_dhcp.c @@ -448,7 +448,7 @@ START_TEST(test_dhcp) dhcp_start(&net_test); fail_unless(txpacket == 1); /* DHCP discover sent */ - xid = ((struct dhcp*)net_test.client_data[dhcp_netif_client_id])->xid; /* Write bad xid, not using htonl! */ + xid = ((struct dhcp*)net_test.client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP])->xid; /* Write bad xid, not using htonl! */ memcpy(&dhcp_offer[46], &xid, 4); send_pkt(&net_test, dhcp_offer, sizeof(dhcp_offer)); @@ -458,17 +458,17 @@ START_TEST(test_dhcp) fail_if(memcmp(&gw, &net_test.gw, sizeof(ip4_addr_t))); fail_unless(txpacket == 1, "TX %d packets, expected 1", txpacket); /* Nothing more sent */ - xid = htonl(((struct dhcp*)net_test.client_data[dhcp_netif_client_id])->xid); + xid = htonl(((struct dhcp*)net_test.client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP])->xid); memcpy(&dhcp_offer[46], &xid, 4); /* insert correct transaction id */ send_pkt(&net_test, dhcp_offer, sizeof(dhcp_offer)); fail_unless(txpacket == 2, "TX %d packets, expected 2", txpacket); /* DHCP request sent */ - xid = ((struct dhcp*)net_test.client_data[dhcp_netif_client_id])->xid; /* Write bad xid, not using htonl! */ + xid = ((struct dhcp*)net_test.client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP])->xid; /* Write bad xid, not using htonl! */ memcpy(&dhcp_ack[46], &xid, 4); send_pkt(&net_test, dhcp_ack, sizeof(dhcp_ack)); fail_unless(txpacket == 2, "TX %d packets, still expected 2", txpacket); /* No more sent */ - xid = htonl(((struct dhcp*)net_test.client_data[dhcp_netif_client_id])->xid); /* xid updated */ + xid = htonl(((struct dhcp*)net_test.client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP])->xid); /* xid updated */ memcpy(&dhcp_ack[46], &xid, 4); /* insert transaction id */ send_pkt(&net_test, dhcp_ack, sizeof(dhcp_ack)); @@ -517,7 +517,7 @@ START_TEST(test_dhcp_nak) dhcp_start(&net_test); fail_unless(txpacket == 1); /* DHCP discover sent */ - xid = ((struct dhcp*)net_test.client_data[dhcp_netif_client_id])->xid; /* Write bad xid, not using htonl! */ + xid = ((struct dhcp*)net_test.client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP])->xid; /* Write bad xid, not using htonl! */ memcpy(&dhcp_offer[46], &xid, 4); send_pkt(&net_test, dhcp_offer, sizeof(dhcp_offer)); @@ -527,17 +527,17 @@ START_TEST(test_dhcp_nak) fail_if(memcmp(&gw, &net_test.gw, sizeof(ip4_addr_t))); fail_unless(txpacket == 1); /* Nothing more sent */ - xid = htonl(((struct dhcp*)net_test.client_data[dhcp_netif_client_id])->xid); + xid = htonl(((struct dhcp*)net_test.client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP])->xid); memcpy(&dhcp_offer[46], &xid, 4); /* insert correct transaction id */ send_pkt(&net_test, dhcp_offer, sizeof(dhcp_offer)); fail_unless(txpacket == 2); /* DHCP request sent */ - xid = ((struct dhcp*)net_test.client_data[dhcp_netif_client_id])->xid; /* Write bad xid, not using htonl! */ + xid = ((struct dhcp*)net_test.client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP])->xid; /* Write bad xid, not using htonl! */ memcpy(&dhcp_ack[46], &xid, 4); send_pkt(&net_test, dhcp_ack, sizeof(dhcp_ack)); fail_unless(txpacket == 2); /* No more sent */ - xid = htonl(((struct dhcp*)net_test.client_data[dhcp_netif_client_id])->xid); /* xid updated */ + xid = htonl(((struct dhcp*)net_test.client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP])->xid); /* xid updated */ memcpy(&dhcp_ack[46], &xid, 4); /* insert transaction id */ send_pkt(&net_test, dhcp_ack, sizeof(dhcp_ack)); @@ -742,13 +742,13 @@ START_TEST(test_dhcp_relayed) fail_if(memcmp(&gw, &net_test.gw, sizeof(ip4_addr_t))); fail_unless(txpacket == 1); /* Nothing more sent */ - xid = htonl(((struct dhcp*)net_test.client_data[dhcp_netif_client_id])->xid); + xid = htonl(((struct dhcp*)net_test.client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP])->xid); memcpy(&relay_offer[46], &xid, 4); /* insert correct transaction id */ send_pkt(&net_test, relay_offer, sizeof(relay_offer)); /* request sent? */ fail_unless(txpacket == 2, "txpkt = %d, should be 2", txpacket); - xid = htonl(((struct dhcp*)net_test.client_data[dhcp_netif_client_id])->xid); /* xid updated */ + xid = htonl(((struct dhcp*)net_test.client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP])->xid); /* xid updated */ memcpy(&relay_ack1[46], &xid, 4); /* insert transaction id */ send_pkt(&net_test, relay_ack1, sizeof(relay_ack1)); @@ -784,7 +784,7 @@ START_TEST(test_dhcp_relayed) fail_unless(txpacket == 7, "txpacket = %d", txpacket); fail_unless(netif_is_up(&net_test)); - xid = htonl(((struct dhcp*)net_test.client_data[dhcp_netif_client_id])->xid); /* xid updated */ + xid = htonl(((struct dhcp*)net_test.client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP])->xid); /* xid updated */ memcpy(&relay_ack2[46], &xid, 4); /* insert transaction id */ send_pkt(&net_test, relay_ack2, sizeof(relay_ack2)); @@ -873,7 +873,7 @@ START_TEST(test_dhcp_nak_no_endmarker) dhcp_start(&net_test); fail_unless(txpacket == 1); /* DHCP discover sent */ - xid = ((struct dhcp*)net_test.client_data[dhcp_netif_client_id])->xid; /* Write bad xid, not using htonl! */ + xid = ((struct dhcp*)net_test.client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP])->xid; /* Write bad xid, not using htonl! */ memcpy(&dhcp_offer[46], &xid, 4); send_pkt(&net_test, dhcp_offer, sizeof(dhcp_offer)); @@ -883,19 +883,19 @@ START_TEST(test_dhcp_nak_no_endmarker) fail_if(memcmp(&gw, &net_test.gw, sizeof(ip4_addr_t))); fail_unless(txpacket == 1); /* Nothing more sent */ - xid = htonl(((struct dhcp*)net_test.client_data[dhcp_netif_client_id])->xid); + xid = htonl(((struct dhcp*)net_test.client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP])->xid); memcpy(&dhcp_offer[46], &xid, 4); /* insert correct transaction id */ send_pkt(&net_test, dhcp_offer, sizeof(dhcp_offer)); - fail_unless(((struct dhcp*)net_test.client_data[dhcp_netif_client_id])->state == DHCP_STATE_REQUESTING); + fail_unless(((struct dhcp*)net_test.client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP])->state == DHCP_STATE_REQUESTING); fail_unless(txpacket == 2); /* No more sent */ - xid = htonl(((struct dhcp*)net_test.client_data[dhcp_netif_client_id])->xid); /* xid updated */ + xid = htonl(((struct dhcp*)net_test.client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP])->xid); /* xid updated */ memcpy(&dhcp_nack_no_endmarker[46], &xid, 4); /* insert transaction id */ send_pkt(&net_test, dhcp_nack_no_endmarker, sizeof(dhcp_nack_no_endmarker)); /* NAK should put us in another state for a while, no other way detecting it */ - fail_unless(((struct dhcp*)net_test.client_data[dhcp_netif_client_id])->state != DHCP_STATE_REQUESTING); + fail_unless(((struct dhcp*)net_test.client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP])->state != DHCP_STATE_REQUESTING); netif_remove(&net_test); } diff --git a/test/unit/lwipopts.h b/test/unit/lwipopts.h index d826042a..25252b42 100644 --- a/test/unit/lwipopts.h +++ b/test/unit/lwipopts.h @@ -54,6 +54,7 @@ /* Enable IGMP and MDNS for MDNS tests */ #define LWIP_IGMP 1 #define LWIP_MDNS_RESPONDER 1 +#define LWIP_NUM_NETIF_CLIENT_DATA (LWIP_MDNS_RESPONDER) /* Minimal changes to opt.h required for etharp unit tests: */ #define ETHARP_SUPPORT_STATIC_ENTRIES 1 From 97fae7e41bb25600e4bb3c6803b0c26c50a19aa9 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Thu, 18 Aug 2016 12:49:59 +0200 Subject: [PATCH 102/325] Code cleanup in autoip.c and dhcp.c --- src/core/ipv4/autoip.c | 33 +++++++++++++------------ src/core/ipv4/dhcp.c | 56 ++++++++++++++++++++++-------------------- 2 files changed, 46 insertions(+), 43 deletions(-) diff --git a/src/core/ipv4/autoip.c b/src/core/ipv4/autoip.c index 1da929c0..c09d2404 100644 --- a/src/core/ipv4/autoip.c +++ b/src/core/ipv4/autoip.c @@ -78,7 +78,7 @@ ((u32_t)((netif->hwaddr[3]) & 0xff) << 16) | \ ((u32_t)((netif->hwaddr[2]) & 0xff) << 8) | \ ((u32_t)((netif->hwaddr[4]) & 0xff))) + \ - (netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP]? ((struct autoip*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP])->tried_llipaddr : 0)) + (netif_autoip_data(netif)? netif_autoip_data(netif)->tried_llipaddr : 0)) #endif /* LWIP_AUTOIP_RAND */ /** @@ -95,6 +95,7 @@ static err_t autoip_arp_announce(struct netif *netif); static void autoip_start_probing(struct netif *netif); +#define netif_autoip_data(netif) ((struct autoip*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP]) /** * @ingroup autoip @@ -110,7 +111,7 @@ autoip_set_struct(struct netif *netif, struct autoip *autoip) LWIP_ASSERT("netif != NULL", netif != NULL); LWIP_ASSERT("autoip != NULL", autoip != NULL); LWIP_ASSERT("netif already has a struct autoip set", - netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP] == NULL); + netif_autoip_data(netif) == NULL); /* clear data structure */ memset(autoip, 0, sizeof(struct autoip)); @@ -125,7 +126,7 @@ autoip_set_struct(struct netif *netif, struct autoip *autoip) static void autoip_restart(struct netif *netif) { - struct autoip* autoip = (struct autoip*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP]; + struct autoip* autoip = netif_autoip_data(netif); autoip->tried_llipaddr++; autoip_start(netif); } @@ -136,7 +137,7 @@ autoip_restart(struct netif *netif) static void autoip_handle_arp_conflict(struct netif *netif) { - struct autoip* autoip = (struct autoip*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP]; + struct autoip* autoip = netif_autoip_data(netif); /* RFC3927, 2.5 "Conflict Detection and Defense" allows two options where a) means retreat on the first conflict and @@ -169,7 +170,7 @@ autoip_handle_arp_conflict(struct netif *netif) static void autoip_create_addr(struct netif *netif, ip4_addr_t *ipaddr) { - struct autoip* autoip = (struct autoip*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP]; + struct autoip* autoip = netif_autoip_data(netif); /* Here we create an IP-Address out of range 169.254.1.0 to 169.254.254.255 * compliant to RFC 3927 Section 2.1 @@ -204,7 +205,7 @@ autoip_create_addr(struct netif *netif, ip4_addr_t *ipaddr) static err_t autoip_arp_probe(struct netif *netif) { - struct autoip* autoip = (struct autoip*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP]; + struct autoip* autoip = netif_autoip_data(netif); /* this works because netif->ip_addr is ANY */ return etharp_request(netif, &autoip->llipaddr); } @@ -228,7 +229,7 @@ autoip_arp_announce(struct netif *netif) static err_t autoip_bind(struct netif *netif) { - struct autoip* autoip = (struct autoip*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP]; + struct autoip* autoip = netif_autoip_data(netif); ip4_addr_t sn_mask, gw_addr; LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE, @@ -255,7 +256,7 @@ autoip_bind(struct netif *netif) err_t autoip_start(struct netif *netif) { - struct autoip* autoip = (struct autoip*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP]; + struct autoip* autoip = netif_autoip_data(netif); err_t result = ERR_OK; LWIP_ERROR("netif is not up, old style port?", netif_is_up(netif), return ERR_ARG;); @@ -299,7 +300,7 @@ autoip_start(struct netif *netif) static void autoip_start_probing(struct netif *netif) { - struct autoip* autoip = (struct autoip*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP]; + struct autoip* autoip = netif_autoip_data(netif); autoip->state = AUTOIP_STATE_PROBING; autoip->sent_num = 0; @@ -333,7 +334,7 @@ autoip_start_probing(struct netif *netif) void autoip_network_changed(struct netif *netif) { - struct autoip* autoip = (struct autoip*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP]; + struct autoip* autoip = netif_autoip_data(netif); if (autoip && (autoip->state != AUTOIP_STATE_OFF)) { autoip_start_probing(netif); @@ -349,7 +350,7 @@ autoip_network_changed(struct netif *netif) err_t autoip_stop(struct netif *netif) { - struct autoip* autoip = (struct autoip*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP]; + struct autoip* autoip = netif_autoip_data(netif); if (autoip != NULL) { autoip->state = AUTOIP_STATE_OFF; @@ -369,7 +370,7 @@ autoip_tmr(void) struct netif *netif = netif_list; /* loop through netif's */ while (netif != NULL) { - struct autoip* autoip = (struct autoip*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP]; + struct autoip* autoip = netif_autoip_data(netif); /* only act on AutoIP configured interfaces */ if (autoip != NULL) { if (autoip->lastconflict > 0) { @@ -454,7 +455,7 @@ autoip_tmr(void) void autoip_arp_reply(struct netif *netif, struct etharp_hdr *hdr) { - struct autoip* autoip = (struct autoip*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP]; + struct autoip* autoip = netif_autoip_data(netif); LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE, ("autoip_arp_reply()\n")); if ((autoip != NULL) && (autoip->state != AUTOIP_STATE_OFF)) { @@ -511,8 +512,8 @@ autoip_arp_reply(struct netif *netif, struct etharp_hdr *hdr) u8_t autoip_supplied_address(const struct netif *netif) { - if ((netif != NULL) && (netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP] != NULL)) { - struct autoip* autoip = (struct autoip*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP]; + if ((netif != NULL) && (netif_autoip_data(netif) != NULL)) { + struct autoip* autoip = netif_autoip_data(netif); return (autoip->state == AUTOIP_STATE_BOUND) || (autoip->state == AUTOIP_STATE_ANNOUNCING); } return 0; @@ -521,7 +522,7 @@ autoip_supplied_address(const struct netif *netif) u8_t autoip_accept_packet(struct netif *netif, const ip4_addr_t *addr) { - struct autoip* autoip = (struct autoip*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP]; + struct autoip* autoip = netif_autoip_data(netif); return (autoip != NULL) && ip4_addr_cmp(addr, &(autoip->llipaddr)); } diff --git a/src/core/ipv4/dhcp.c b/src/core/ipv4/dhcp.c index b1180627..47652757 100644 --- a/src/core/ipv4/dhcp.c +++ b/src/core/ipv4/dhcp.c @@ -193,6 +193,8 @@ static void dhcp_option_hostname(struct dhcp *dhcp, struct netif *netif); /* always add the DHCP options trailer to end and pad */ static void dhcp_option_trailer(struct dhcp *dhcp); +#define netif_dhcp_data(netif) ((struct dhcp*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP]) + /** Ensure DHCP PCB is allocated and bound */ static err_t dhcp_inc_pcb_refcount(void) @@ -248,7 +250,7 @@ dhcp_dec_pcb_refcount(void) static void dhcp_handle_nak(struct netif *netif) { - struct dhcp *dhcp = (struct dhcp*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP]; + struct dhcp *dhcp = netif_dhcp_data(netif); LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_handle_nak(netif=%p) %c%c%"U16_F"\n", (void*)netif, netif->name[0], netif->name[1], (u16_t)netif->num)); @@ -274,7 +276,7 @@ dhcp_handle_nak(struct netif *netif) static void dhcp_check(struct netif *netif) { - struct dhcp *dhcp = (struct dhcp*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP]; + struct dhcp *dhcp = netif_dhcp_data(netif); err_t result; u16_t msecs; LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_check(netif=%p) %c%c\n", (void *)netif, (s16_t)netif->name[0], @@ -303,7 +305,7 @@ dhcp_check(struct netif *netif) static void dhcp_handle_offer(struct netif *netif) { - struct dhcp *dhcp = (struct dhcp*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP]; + struct dhcp *dhcp = netif_dhcp_data(netif); LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_handle_offer(netif=%p) %c%c%"U16_F"\n", (void*)netif, netif->name[0], netif->name[1], (u16_t)netif->num)); @@ -335,7 +337,7 @@ dhcp_handle_offer(struct netif *netif) static err_t dhcp_select(struct netif *netif) { - struct dhcp *dhcp = (struct dhcp*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP]; + struct dhcp *dhcp = netif_dhcp_data(netif); err_t result; u16_t msecs; u8_t i; @@ -397,7 +399,7 @@ dhcp_coarse_tmr(void) /* iterate through all network interfaces */ while (netif != NULL) { /* only act on DHCP configured interfaces */ - struct dhcp *dhcp = (struct dhcp*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP]; + struct dhcp *dhcp = netif_dhcp_data(netif); if ((dhcp != NULL) && (dhcp->state != DHCP_STATE_OFF)) { /* compare lease time to expire timeout */ if (dhcp->t0_timeout && (++dhcp->lease_used == dhcp->t0_timeout)) { @@ -435,7 +437,7 @@ dhcp_fine_tmr(void) struct netif *netif = netif_list; /* loop through netif's */ while (netif != NULL) { - struct dhcp *dhcp = (struct dhcp*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP]; + struct dhcp *dhcp = netif_dhcp_data(netif); /* only act on DHCP configured interfaces */ if (dhcp != NULL) { /* timer is active (non zero), and is about to trigger now */ @@ -466,7 +468,7 @@ dhcp_fine_tmr(void) static void dhcp_timeout(struct netif *netif) { - struct dhcp *dhcp = (struct dhcp*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP]; + struct dhcp *dhcp = netif_dhcp_data(netif); LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_timeout()\n")); /* back-off period has passed, or server selection timed out */ @@ -513,7 +515,7 @@ dhcp_timeout(struct netif *netif) static void dhcp_t1_timeout(struct netif *netif) { - struct dhcp *dhcp = (struct dhcp*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP]; + struct dhcp *dhcp = netif_dhcp_data(netif); LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_STATE, ("dhcp_t1_timeout()\n")); if ((dhcp->state == DHCP_STATE_REQUESTING) || (dhcp->state == DHCP_STATE_BOUND) || @@ -541,7 +543,7 @@ dhcp_t1_timeout(struct netif *netif) static void dhcp_t2_timeout(struct netif *netif) { - struct dhcp *dhcp = (struct dhcp*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP]; + struct dhcp *dhcp = netif_dhcp_data(netif); LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_t2_timeout()\n")); if ((dhcp->state == DHCP_STATE_REQUESTING) || (dhcp->state == DHCP_STATE_BOUND) || @@ -568,7 +570,7 @@ dhcp_t2_timeout(struct netif *netif) static void dhcp_handle_ack(struct netif *netif) { - struct dhcp *dhcp = (struct dhcp*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP]; + struct dhcp *dhcp = netif_dhcp_data(netif); #if LWIP_DNS || LWIP_DHCP_GET_NTP_SRV u8_t n; @@ -661,7 +663,7 @@ dhcp_set_struct(struct netif *netif, struct dhcp *dhcp) { LWIP_ASSERT("netif != NULL", netif != NULL); LWIP_ASSERT("dhcp != NULL", dhcp != NULL); - LWIP_ASSERT("netif already has a struct dhcp set", netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP] == NULL); + LWIP_ASSERT("netif already has a struct dhcp set", netif_dhcp_data(netif) == NULL); /* clear data structure */ memset(dhcp, 0, sizeof(struct dhcp)); @@ -682,8 +684,8 @@ void dhcp_cleanup(struct netif *netif) { LWIP_ASSERT("netif != NULL", netif != NULL); - if (netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP] != NULL) { - mem_free(netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP]); + if (netif_dhcp_data(netif) != NULL) { + mem_free(netif_dhcp_data(netif)); netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP] = NULL; } } @@ -709,7 +711,7 @@ dhcp_start(struct netif *netif) LWIP_ERROR("netif != NULL", (netif != NULL), return ERR_ARG;); LWIP_ERROR("netif is not up, old style port?", netif_is_up(netif), return ERR_ARG;); - dhcp = (struct dhcp*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP]; + dhcp = netif_dhcp_data(netif); 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)); /* check MTU of the netif */ @@ -827,7 +829,7 @@ dhcp_inform(struct netif *netif) void dhcp_network_changed(struct netif *netif) { - struct dhcp *dhcp = (struct dhcp*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP]; + struct dhcp *dhcp = netif_dhcp_data(netif); if (!dhcp) return; @@ -873,7 +875,7 @@ dhcp_arp_reply(struct netif *netif, const ip4_addr_t *addr) struct dhcp *dhcp; LWIP_ERROR("netif != NULL", (netif != NULL), return;); - dhcp = (struct dhcp*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP]; + dhcp = netif_dhcp_data(netif); LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_arp_reply()\n")); /* is a DHCP client doing an ARP check? */ if ((dhcp != NULL) && (dhcp->state == DHCP_STATE_CHECKING)) { @@ -902,7 +904,7 @@ dhcp_arp_reply(struct netif *netif, const ip4_addr_t *addr) static err_t dhcp_decline(struct netif *netif) { - struct dhcp *dhcp = (struct dhcp*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP]; + struct dhcp *dhcp = netif_dhcp_data(netif); err_t result = ERR_OK; u16_t msecs; LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_decline()\n")); @@ -944,7 +946,7 @@ dhcp_decline(struct netif *netif) static err_t dhcp_discover(struct netif *netif) { - struct dhcp *dhcp = (struct dhcp*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP]; + struct dhcp *dhcp = netif_dhcp_data(netif); err_t result = ERR_OK; u16_t msecs; u8_t i; @@ -1004,7 +1006,7 @@ dhcp_bind(struct netif *netif) struct dhcp *dhcp; ip4_addr_t sn_mask, gw_addr; LWIP_ERROR("dhcp_bind: netif != NULL", (netif != NULL), return;); - dhcp = (struct dhcp*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP]; + dhcp = netif_dhcp_data(netif); LWIP_ERROR("dhcp_bind: dhcp != NULL", (dhcp != NULL), return;); LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_bind(netif=%p) %c%c%"U16_F"\n", (void*)netif, netif->name[0], netif->name[1], (u16_t)netif->num)); @@ -1110,7 +1112,7 @@ dhcp_bind(struct netif *netif) err_t dhcp_renew(struct netif *netif) { - struct dhcp *dhcp = (struct dhcp*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP]; + struct dhcp *dhcp = netif_dhcp_data(netif); err_t result; u16_t msecs; u8_t i; @@ -1162,7 +1164,7 @@ dhcp_renew(struct netif *netif) static err_t dhcp_rebind(struct netif *netif) { - struct dhcp *dhcp = (struct dhcp*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP]; + struct dhcp *dhcp = netif_dhcp_data(netif); err_t result; u16_t msecs; u8_t i; @@ -1212,7 +1214,7 @@ dhcp_rebind(struct netif *netif) static err_t dhcp_reboot(struct netif *netif) { - struct dhcp *dhcp = (struct dhcp*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP]; + struct dhcp *dhcp = netif_dhcp_data(netif); err_t result; u16_t msecs; u8_t i; @@ -1263,7 +1265,7 @@ dhcp_reboot(struct netif *netif) err_t dhcp_release(struct netif *netif) { - struct dhcp *dhcp = (struct dhcp*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP]; + struct dhcp *dhcp = netif_dhcp_data(netif); err_t result; ip_addr_t server_ip_addr; u8_t is_dhcp_supplied_address; @@ -1328,7 +1330,7 @@ dhcp_stop(struct netif *netif) { struct dhcp *dhcp; LWIP_ERROR("dhcp_stop: netif != NULL", (netif != NULL), return;); - dhcp = (struct dhcp*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP]; + dhcp = netif_dhcp_data(netif); LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_stop()\n")); /* netif is DHCP configured? */ @@ -1653,7 +1655,7 @@ static void dhcp_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, u16_t port) { struct netif *netif = ip_current_input_netif(); - struct dhcp *dhcp = (struct dhcp*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP]; + struct dhcp *dhcp = netif_dhcp_data(netif); struct dhcp_msg *reply_msg = (struct dhcp_msg *)p->payload; u8_t msg_type; u8_t i; @@ -1915,8 +1917,8 @@ dhcp_option_trailer(struct dhcp *dhcp) u8_t dhcp_supplied_address(const struct netif *netif) { - if ((netif != NULL) && (netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP] != NULL)) { - struct dhcp* dhcp = (struct dhcp*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP]; + if ((netif != NULL) && (netif_dhcp_data(netif) != NULL)) { + struct dhcp* dhcp = netif_dhcp_data(netif); return (dhcp->state == DHCP_STATE_BOUND) || (dhcp->state == DHCP_STATE_RENEWING); } return 0; From a8c8e089844b3c5428d1e1d7a61613a3a4f0c4d3 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Thu, 18 Aug 2016 13:02:59 +0200 Subject: [PATCH 103/325] Minor: cleanups in unit test code --- test/unit/dhcp/test_dhcp.c | 34 +++++++++++++++------------- test/unit/mdns/test_mdns.c | 46 +++++++++++++++++++------------------- 2 files changed, 41 insertions(+), 39 deletions(-) diff --git a/test/unit/dhcp/test_dhcp.c b/test/unit/dhcp/test_dhcp.c index 850c213f..61471e2e 100644 --- a/test/unit/dhcp/test_dhcp.c +++ b/test/unit/dhcp/test_dhcp.c @@ -125,6 +125,8 @@ static enum tcase { static int debug = 0; static void setdebug(int a) {debug = a;} +#define netif_dhcp_data(netif) ((struct dhcp*)(netif)->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP]) + static int tick = 0; static void tick_lwip(void) { @@ -448,7 +450,7 @@ START_TEST(test_dhcp) dhcp_start(&net_test); fail_unless(txpacket == 1); /* DHCP discover sent */ - xid = ((struct dhcp*)net_test.client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP])->xid; /* Write bad xid, not using htonl! */ + xid = netif_dhcp_data(&net_test)->xid; /* Write bad xid, not using htonl! */ memcpy(&dhcp_offer[46], &xid, 4); send_pkt(&net_test, dhcp_offer, sizeof(dhcp_offer)); @@ -458,17 +460,17 @@ START_TEST(test_dhcp) fail_if(memcmp(&gw, &net_test.gw, sizeof(ip4_addr_t))); fail_unless(txpacket == 1, "TX %d packets, expected 1", txpacket); /* Nothing more sent */ - xid = htonl(((struct dhcp*)net_test.client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP])->xid); + xid = htonl(netif_dhcp_data(&net_test)->xid); memcpy(&dhcp_offer[46], &xid, 4); /* insert correct transaction id */ send_pkt(&net_test, dhcp_offer, sizeof(dhcp_offer)); fail_unless(txpacket == 2, "TX %d packets, expected 2", txpacket); /* DHCP request sent */ - xid = ((struct dhcp*)net_test.client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP])->xid; /* Write bad xid, not using htonl! */ + xid = netif_dhcp_data(&net_test)->xid; /* Write bad xid, not using htonl! */ memcpy(&dhcp_ack[46], &xid, 4); send_pkt(&net_test, dhcp_ack, sizeof(dhcp_ack)); fail_unless(txpacket == 2, "TX %d packets, still expected 2", txpacket); /* No more sent */ - xid = htonl(((struct dhcp*)net_test.client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP])->xid); /* xid updated */ + xid = htonl(netif_dhcp_data(&net_test)->xid); /* xid updated */ memcpy(&dhcp_ack[46], &xid, 4); /* insert transaction id */ send_pkt(&net_test, dhcp_ack, sizeof(dhcp_ack)); @@ -517,7 +519,7 @@ START_TEST(test_dhcp_nak) dhcp_start(&net_test); fail_unless(txpacket == 1); /* DHCP discover sent */ - xid = ((struct dhcp*)net_test.client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP])->xid; /* Write bad xid, not using htonl! */ + xid = netif_dhcp_data(&net_test)->xid; /* Write bad xid, not using htonl! */ memcpy(&dhcp_offer[46], &xid, 4); send_pkt(&net_test, dhcp_offer, sizeof(dhcp_offer)); @@ -527,17 +529,17 @@ START_TEST(test_dhcp_nak) fail_if(memcmp(&gw, &net_test.gw, sizeof(ip4_addr_t))); fail_unless(txpacket == 1); /* Nothing more sent */ - xid = htonl(((struct dhcp*)net_test.client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP])->xid); + xid = htonl(netif_dhcp_data(&net_test)->xid); memcpy(&dhcp_offer[46], &xid, 4); /* insert correct transaction id */ send_pkt(&net_test, dhcp_offer, sizeof(dhcp_offer)); fail_unless(txpacket == 2); /* DHCP request sent */ - xid = ((struct dhcp*)net_test.client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP])->xid; /* Write bad xid, not using htonl! */ + xid = netif_dhcp_data(&net_test)->xid; /* Write bad xid, not using htonl! */ memcpy(&dhcp_ack[46], &xid, 4); send_pkt(&net_test, dhcp_ack, sizeof(dhcp_ack)); fail_unless(txpacket == 2); /* No more sent */ - xid = htonl(((struct dhcp*)net_test.client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP])->xid); /* xid updated */ + xid = htonl(netif_dhcp_data(&net_test)->xid); /* xid updated */ memcpy(&dhcp_ack[46], &xid, 4); /* insert transaction id */ send_pkt(&net_test, dhcp_ack, sizeof(dhcp_ack)); @@ -742,13 +744,13 @@ START_TEST(test_dhcp_relayed) fail_if(memcmp(&gw, &net_test.gw, sizeof(ip4_addr_t))); fail_unless(txpacket == 1); /* Nothing more sent */ - xid = htonl(((struct dhcp*)net_test.client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP])->xid); + xid = htonl(netif_dhcp_data(&net_test)->xid); memcpy(&relay_offer[46], &xid, 4); /* insert correct transaction id */ send_pkt(&net_test, relay_offer, sizeof(relay_offer)); /* request sent? */ fail_unless(txpacket == 2, "txpkt = %d, should be 2", txpacket); - xid = htonl(((struct dhcp*)net_test.client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP])->xid); /* xid updated */ + xid = htonl(netif_dhcp_data(&net_test)->xid); /* xid updated */ memcpy(&relay_ack1[46], &xid, 4); /* insert transaction id */ send_pkt(&net_test, relay_ack1, sizeof(relay_ack1)); @@ -784,7 +786,7 @@ START_TEST(test_dhcp_relayed) fail_unless(txpacket == 7, "txpacket = %d", txpacket); fail_unless(netif_is_up(&net_test)); - xid = htonl(((struct dhcp*)net_test.client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP])->xid); /* xid updated */ + xid = htonl(netif_dhcp_data(&net_test)->xid); /* xid updated */ memcpy(&relay_ack2[46], &xid, 4); /* insert transaction id */ send_pkt(&net_test, relay_ack2, sizeof(relay_ack2)); @@ -873,7 +875,7 @@ START_TEST(test_dhcp_nak_no_endmarker) dhcp_start(&net_test); fail_unless(txpacket == 1); /* DHCP discover sent */ - xid = ((struct dhcp*)net_test.client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP])->xid; /* Write bad xid, not using htonl! */ + xid = netif_dhcp_data(&net_test)->xid; /* Write bad xid, not using htonl! */ memcpy(&dhcp_offer[46], &xid, 4); send_pkt(&net_test, dhcp_offer, sizeof(dhcp_offer)); @@ -883,19 +885,19 @@ START_TEST(test_dhcp_nak_no_endmarker) fail_if(memcmp(&gw, &net_test.gw, sizeof(ip4_addr_t))); fail_unless(txpacket == 1); /* Nothing more sent */ - xid = htonl(((struct dhcp*)net_test.client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP])->xid); + xid = htonl(netif_dhcp_data(&net_test)->xid); memcpy(&dhcp_offer[46], &xid, 4); /* insert correct transaction id */ send_pkt(&net_test, dhcp_offer, sizeof(dhcp_offer)); - fail_unless(((struct dhcp*)net_test.client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP])->state == DHCP_STATE_REQUESTING); + fail_unless(netif_dhcp_data(&net_test)->state == DHCP_STATE_REQUESTING); fail_unless(txpacket == 2); /* No more sent */ - xid = htonl(((struct dhcp*)net_test.client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP])->xid); /* xid updated */ + xid = htonl(netif_dhcp_data(&net_test)->xid); /* xid updated */ memcpy(&dhcp_nack_no_endmarker[46], &xid, 4); /* insert transaction id */ send_pkt(&net_test, dhcp_nack_no_endmarker, sizeof(dhcp_nack_no_endmarker)); /* NAK should put us in another state for a while, no other way detecting it */ - fail_unless(((struct dhcp*)net_test.client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP])->state != DHCP_STATE_REQUESTING); + fail_unless(netif_dhcp_data(&net_test)->state != DHCP_STATE_REQUESTING); netif_remove(&net_test); } diff --git a/test/unit/mdns/test_mdns.c b/test/unit/mdns/test_mdns.c index c9a6bc3f..d1d2cb71 100644 --- a/test/unit/mdns/test_mdns.c +++ b/test/unit/mdns/test_mdns.c @@ -382,7 +382,7 @@ START_TEST(add_label_long_label) memset(&domain, 0, sizeof(domain)); res = mdns_domain_add_label(&domain, "multi", 5); fail_unless(res == ERR_OK); - res = mdns_domain_add_label(&domain, toolong, strlen(toolong)); + res = mdns_domain_add_label(&domain, toolong, (u8_t)strlen(toolong)); fail_unless(res == ERR_VAL); } END_TEST @@ -394,28 +394,28 @@ START_TEST(add_label_full) err_t res; memset(&domain, 0, sizeof(domain)); - res = mdns_domain_add_label(&domain, label, strlen(label)); + res = mdns_domain_add_label(&domain, label, (u8_t)strlen(label)); fail_unless(res == ERR_OK); fail_unless(domain.length == 33); - res = mdns_domain_add_label(&domain, label, strlen(label)); + res = mdns_domain_add_label(&domain, label, (u8_t)strlen(label)); fail_unless(res == ERR_OK); fail_unless(domain.length == 66); - res = mdns_domain_add_label(&domain, label, strlen(label)); + res = mdns_domain_add_label(&domain, label, (u8_t)strlen(label)); fail_unless(res == ERR_OK); fail_unless(domain.length == 99); - res = mdns_domain_add_label(&domain, label, strlen(label)); + res = mdns_domain_add_label(&domain, label, (u8_t)strlen(label)); fail_unless(res == ERR_OK); fail_unless(domain.length == 132); - res = mdns_domain_add_label(&domain, label, strlen(label)); + res = mdns_domain_add_label(&domain, label, (u8_t)strlen(label)); fail_unless(res == ERR_OK); fail_unless(domain.length == 165); - res = mdns_domain_add_label(&domain, label, strlen(label)); + res = mdns_domain_add_label(&domain, label, (u8_t)strlen(label)); fail_unless(res == ERR_OK); fail_unless(domain.length == 198); - res = mdns_domain_add_label(&domain, label, strlen(label)); + res = mdns_domain_add_label(&domain, label, (u8_t)strlen(label)); fail_unless(res == ERR_OK); fail_unless(domain.length == 231); - res = mdns_domain_add_label(&domain, label, strlen(label)); + res = mdns_domain_add_label(&domain, label, (u8_t)strlen(label)); fail_unless(res == ERR_VAL); fail_unless(domain.length == 231); res = mdns_domain_add_label(&domain, label, 25); @@ -517,27 +517,27 @@ END_TEST START_TEST(domain_eq_anydata) { - static const char data1[] = { 0x05, (char)0xcc, (char)0xdc, 0x00, (char)0xa0 }; - static const char data2[] = { 0x7f, (char)0x8c, 0x01, (char)0xff, (char)0xcf }; + static const u8_t data1[] = { 0x05, 0xcc, 0xdc, 0x00, 0xa0 }; + static const u8_t data2[] = { 0x7f, 0x8c, 0x01, 0xff, 0xcf }; struct mdns_domain domain1, domain2; err_t res; memset(&domain1, 0, sizeof(domain1)); - res = mdns_domain_add_label(&domain1, data1, sizeof(data1)); + res = mdns_domain_add_label(&domain1, (char*)data1, sizeof(data1)); fail_unless(res == ERR_OK); res = mdns_domain_add_label(&domain1, "cast", 4); fail_unless(res == ERR_OK); - res = mdns_domain_add_label(&domain1, data2, sizeof(data2)); + res = mdns_domain_add_label(&domain1, (char*)data2, sizeof(data2)); fail_unless(res == ERR_OK); res = mdns_domain_add_label(&domain1, NULL, 0); fail_unless(res == ERR_OK); memset(&domain2, 0, sizeof(domain2)); - res = mdns_domain_add_label(&domain2, data1, sizeof(data1)); + res = mdns_domain_add_label(&domain2, (char*)data1, sizeof(data1)); fail_unless(res == ERR_OK); res = mdns_domain_add_label(&domain2, "casT", 4); fail_unless(res == ERR_OK); - res = mdns_domain_add_label(&domain2, data2, sizeof(data2)); + res = mdns_domain_add_label(&domain2, (char*)data2, sizeof(data2)); fail_unless(res == ERR_OK); res = mdns_domain_add_label(&domain2, NULL, 0); fail_unless(res == ERR_OK); @@ -578,7 +578,7 @@ START_TEST(compress_full_match) struct pbuf *p; struct mdns_domain domain; u16_t offset; - u8_t length; + u16_t length; err_t res; p = pbuf_alloc(PBUF_RAW, sizeof(data), PBUF_ROM); @@ -612,7 +612,7 @@ START_TEST(compress_full_match_subset) struct pbuf *p; struct mdns_domain domain; u16_t offset; - u8_t length; + u16_t length; err_t res; p = pbuf_alloc(PBUF_RAW, sizeof(data), PBUF_ROM); @@ -648,7 +648,7 @@ START_TEST(compress_full_match_jump) struct pbuf *p; struct mdns_domain domain; u16_t offset; - u8_t length; + u16_t length; err_t res; p = pbuf_alloc(PBUF_RAW, sizeof(data), PBUF_ROM); @@ -682,7 +682,7 @@ START_TEST(compress_no_match) struct pbuf *p; struct mdns_domain domain; u16_t offset; - u8_t length; + u16_t length; err_t res; p = pbuf_alloc(PBUF_RAW, sizeof(data), PBUF_ROM); @@ -715,7 +715,7 @@ START_TEST(compress_2nd_label) struct pbuf *p; struct mdns_domain domain; u16_t offset; - u8_t length; + u16_t length; err_t res; p = pbuf_alloc(PBUF_RAW, sizeof(data), PBUF_ROM); @@ -749,7 +749,7 @@ START_TEST(compress_2nd_label_short) struct pbuf *p; struct mdns_domain domain; u16_t offset; - u8_t length; + u16_t length; err_t res; p = pbuf_alloc(PBUF_RAW, sizeof(data), PBUF_ROM); @@ -785,7 +785,7 @@ START_TEST(compress_jump_to_jump) struct pbuf *p; struct mdns_domain domain; u16_t offset; - u8_t length; + u16_t length; err_t res; p = pbuf_alloc(PBUF_RAW, sizeof(data), PBUF_ROM); @@ -824,7 +824,7 @@ START_TEST(compress_long_match) struct pbuf *p; struct mdns_domain domain; u16_t offset; - u8_t length; + u16_t length; err_t res; p = pbuf_alloc(PBUF_RAW, sizeof(data), PBUF_ROM); From ef31afb92155be0e60d58996b9eae8f5c86bc202 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Thu, 18 Aug 2016 20:53:57 +0800 Subject: [PATCH 104/325] memp: Fix build error when LWIP_HOOK_MEMP_AVAILABLE is defined MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix below build error. ../../../../../lwip/src/core/memp.c: In function ‘memp_free’: ../../../../../lwip/src/core/memp.c:490:31: error: request for member ‘tab’ in something not a structure or union old_first = memp_pools[type].tab; ^ ../../Common.mk:94: recipe for target 'memp.o' failed make: *** [memp.o] Error 1 Fixes: de9054cb7a70 ("memp: cleaned up MEMP_MEM_MALLOC") Signed-off-by: Axel Lin --- src/core/memp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/memp.c b/src/core/memp.c index 6473e18b..3ee5dbd3 100644 --- a/src/core/memp.c +++ b/src/core/memp.c @@ -487,7 +487,7 @@ memp_free(memp_t type, void *mem) #endif /* MEMP_OVERFLOW_CHECK >= 2 */ #ifdef LWIP_HOOK_MEMP_AVAILABLE - old_first = memp_pools[type].tab; + old_first = *memp_pools[type]->tab; #endif do_memp_free_pool(memp_pools[type], mem); From e24fde05db0ad583882a0b082fd0ccfa633f9a66 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Wed, 17 Aug 2016 20:23:30 +0800 Subject: [PATCH 105/325] memp: Fix memp_overflow_check_element_overflow assertion Use LWIP_MEM_ALIGN() in memp_overflow_init() to get alignment address for memp. This fixes assertion in memp_overflow_check_element_overflow when MEMP_OVERFLOW_CHECK is set. Signed-off-by: Axel Lin --- src/core/memp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/memp.c b/src/core/memp.c index 3ee5dbd3..78307b53 100644 --- a/src/core/memp.c +++ b/src/core/memp.c @@ -215,7 +215,7 @@ memp_overflow_init(const struct memp_desc *desc) u16_t i; struct memp *p; - p = (struct memp *)(size_t)(desc->base); + p = (struct memp*)LWIP_MEM_ALIGN(desc->base); for (i = 0; i < desc->num; ++i) { memp_overflow_init_element(p, desc); p = (struct memp*)(size_t)((u8_t*)p + MEMP_SIZE + desc->size + MEMP_SANITY_REGION_AFTER_ALIGNED); From 16293125a6b36b25111df3f7859721721a0fa57a Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Thu, 18 Aug 2016 20:22:14 +0200 Subject: [PATCH 106/325] Work on bug #48728: headers should cleanly separate API vs. implementation TCP --- src/include/lwip/priv/tcp_priv.h | 36 +------------- src/include/lwip/prot/tcp.h | 85 ++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 35 deletions(-) create mode 100644 src/include/lwip/prot/tcp.h diff --git a/src/include/lwip/priv/tcp_priv.h b/src/include/lwip/priv/tcp_priv.h index 957408d8..afd6f937 100644 --- a/src/include/lwip/priv/tcp_priv.h +++ b/src/include/lwip/priv/tcp_priv.h @@ -49,6 +49,7 @@ #include "lwip/err.h" #include "lwip/ip6.h" #include "lwip/ip6_addr.h" +#include "lwip/prot/tcp.h" #ifdef __cplusplus extern "C" { @@ -122,9 +123,6 @@ err_t tcp_process_refused_data(struct tcp_pcb *pcb); #define TCP_FLAGS 0x3fU -/* Length of the TCP header, excluding options. */ -#define TCP_HLEN 20 - #ifndef TCP_TMR_INTERVAL #define TCP_TMR_INTERVAL 250 /* The TCP timer interval in milliseconds. */ #endif /* TCP_TMR_INTERVAL */ @@ -161,38 +159,6 @@ err_t tcp_process_refused_data(struct tcp_pcb *pcb); #define TCP_MAXIDLE TCP_KEEPCNT_DEFAULT * TCP_KEEPINTVL_DEFAULT /* Maximum KEEPALIVE probe time */ -/* Fields are (of course) in network byte order. - * Some fields are converted to host byte order in tcp_input(). - */ -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/bpstruct.h" -#endif -PACK_STRUCT_BEGIN -struct tcp_hdr { - PACK_STRUCT_FIELD(u16_t src); - PACK_STRUCT_FIELD(u16_t dest); - PACK_STRUCT_FIELD(u32_t seqno); - PACK_STRUCT_FIELD(u32_t ackno); - PACK_STRUCT_FIELD(u16_t _hdrlen_rsvd_flags); - PACK_STRUCT_FIELD(u16_t wnd); - PACK_STRUCT_FIELD(u16_t chksum); - PACK_STRUCT_FIELD(u16_t urgp); -} PACK_STRUCT_STRUCT; -PACK_STRUCT_END -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/epstruct.h" -#endif - -#define TCPH_HDRLEN(phdr) ((u16_t)(ntohs((phdr)->_hdrlen_rsvd_flags) >> 12)) -#define TCPH_FLAGS(phdr) ((u16_t)(ntohs((phdr)->_hdrlen_rsvd_flags) & TCP_FLAGS)) - -#define TCPH_HDRLEN_SET(phdr, len) (phdr)->_hdrlen_rsvd_flags = htons(((len) << 12) | TCPH_FLAGS(phdr)) -#define TCPH_FLAGS_SET(phdr, flags) (phdr)->_hdrlen_rsvd_flags = (((phdr)->_hdrlen_rsvd_flags & PP_HTONS(~TCP_FLAGS)) | htons(flags)) -#define TCPH_HDRLEN_FLAGS_SET(phdr, len, flags) (phdr)->_hdrlen_rsvd_flags = htons(((len) << 12) | (flags)) - -#define TCPH_SET_FLAG(phdr, flags ) (phdr)->_hdrlen_rsvd_flags = ((phdr)->_hdrlen_rsvd_flags | htons(flags)) -#define TCPH_UNSET_FLAG(phdr, flags) (phdr)->_hdrlen_rsvd_flags = ((phdr)->_hdrlen_rsvd_flags & ~htons(flags)) - #define TCP_TCPLEN(seg) ((seg)->len + (((TCPH_FLAGS((seg)->tcphdr) & (TCP_FIN | TCP_SYN)) != 0) ? 1U : 0U)) /** Flags used on input processing, not on pcb->flags diff --git a/src/include/lwip/prot/tcp.h b/src/include/lwip/prot/tcp.h new file mode 100644 index 00000000..64bb1fef --- /dev/null +++ b/src/include/lwip/prot/tcp.h @@ -0,0 +1,85 @@ +/** + * @file + * TCP protocol definitions + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_HDR_PROT_TCP_H +#define LWIP_HDR_PROT_TCP_H + +#include "lwip/arch.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* Length of the TCP header, excluding options. */ +#define TCP_HLEN 20 + +/* Fields are (of course) in network byte order. + * Some fields are converted to host byte order in tcp_input(). + */ +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +struct tcp_hdr { + PACK_STRUCT_FIELD(u16_t src); + PACK_STRUCT_FIELD(u16_t dest); + PACK_STRUCT_FIELD(u32_t seqno); + PACK_STRUCT_FIELD(u32_t ackno); + PACK_STRUCT_FIELD(u16_t _hdrlen_rsvd_flags); + PACK_STRUCT_FIELD(u16_t wnd); + PACK_STRUCT_FIELD(u16_t chksum); + PACK_STRUCT_FIELD(u16_t urgp); +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + +#define TCPH_HDRLEN(phdr) ((u16_t)(ntohs((phdr)->_hdrlen_rsvd_flags) >> 12)) +#define TCPH_FLAGS(phdr) ((u16_t)(ntohs((phdr)->_hdrlen_rsvd_flags) & TCP_FLAGS)) + +#define TCPH_HDRLEN_SET(phdr, len) (phdr)->_hdrlen_rsvd_flags = htons(((len) << 12) | TCPH_FLAGS(phdr)) +#define TCPH_FLAGS_SET(phdr, flags) (phdr)->_hdrlen_rsvd_flags = (((phdr)->_hdrlen_rsvd_flags & PP_HTONS(~TCP_FLAGS)) | htons(flags)) +#define TCPH_HDRLEN_FLAGS_SET(phdr, len, flags) (phdr)->_hdrlen_rsvd_flags = htons(((len) << 12) | (flags)) + +#define TCPH_SET_FLAG(phdr, flags ) (phdr)->_hdrlen_rsvd_flags = ((phdr)->_hdrlen_rsvd_flags | htons(flags)) +#define TCPH_UNSET_FLAG(phdr, flags) (phdr)->_hdrlen_rsvd_flags = ((phdr)->_hdrlen_rsvd_flags & ~htons(flags)) + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_PROT_TCP_H */ From d89fa2dcbc9ff296428e90d3a407817d4344172a Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Thu, 18 Aug 2016 20:22:35 +0200 Subject: [PATCH 107/325] Work on bug #48728: headers should cleanly separate API vs. implementation UDP --- src/include/lwip/prot/udp.h | 68 +++++++++++++++++++++++++++++++++++++ src/include/lwip/udp.h | 19 +---------- 2 files changed, 69 insertions(+), 18 deletions(-) create mode 100644 src/include/lwip/prot/udp.h diff --git a/src/include/lwip/prot/udp.h b/src/include/lwip/prot/udp.h new file mode 100644 index 00000000..fdf452a8 --- /dev/null +++ b/src/include/lwip/prot/udp.h @@ -0,0 +1,68 @@ +/** + * @file + * UDP protocol definitions + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_HDR_PROT_UDP_H +#define LWIP_HDR_PROT_UDP_H + +#include "lwip/arch.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define UDP_HLEN 8 + +/* Fields are (of course) in network byte order. */ +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +struct udp_hdr { + PACK_STRUCT_FIELD(u16_t src); + PACK_STRUCT_FIELD(u16_t dest); /* src/dest UDP ports */ + PACK_STRUCT_FIELD(u16_t len); + PACK_STRUCT_FIELD(u16_t chksum); +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_PROT_UDP_H */ diff --git a/src/include/lwip/udp.h b/src/include/lwip/udp.h index a0381ddd..3e499b06 100644 --- a/src/include/lwip/udp.h +++ b/src/include/lwip/udp.h @@ -47,29 +47,12 @@ #include "lwip/ip_addr.h" #include "lwip/ip.h" #include "lwip/ip6_addr.h" +#include "lwip/prot/udp.h" #ifdef __cplusplus extern "C" { #endif -#define UDP_HLEN 8 - -/* Fields are (of course) in network byte order. */ -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/bpstruct.h" -#endif -PACK_STRUCT_BEGIN -struct udp_hdr { - PACK_STRUCT_FIELD(u16_t src); - PACK_STRUCT_FIELD(u16_t dest); /* src/dest UDP ports */ - PACK_STRUCT_FIELD(u16_t len); - PACK_STRUCT_FIELD(u16_t chksum); -} PACK_STRUCT_STRUCT; -PACK_STRUCT_END -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/epstruct.h" -#endif - #define UDP_FLAGS_NOCHKSUM 0x01U #define UDP_FLAGS_UDPLITE 0x02U #define UDP_FLAGS_CONNECTED 0x04U From 8d68400387b0f6a852c268e743622ae5ba6962db Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Thu, 18 Aug 2016 20:28:03 +0200 Subject: [PATCH 108/325] Work on bug #48728: headers should cleanly separate API vs. implementation ND6 --- src/core/ipv6/nd6.c | 1 + src/include/lwip/nd6.h | 203 ----------------------------- src/include/lwip/prot/nd6.h | 252 ++++++++++++++++++++++++++++++++++++ 3 files changed, 253 insertions(+), 203 deletions(-) create mode 100644 src/include/lwip/prot/nd6.h diff --git a/src/core/ipv6/nd6.c b/src/core/ipv6/nd6.c index 4dacd4fc..e3616813 100644 --- a/src/core/ipv6/nd6.c +++ b/src/core/ipv6/nd6.c @@ -46,6 +46,7 @@ #if LWIP_IPV6 /* don't build if not configured for use in lwipopts.h */ #include "lwip/nd6.h" +#include "lwip/prot/nd6.h" #include "lwip/pbuf.h" #include "lwip/mem.h" #include "lwip/memp.h" diff --git a/src/include/lwip/nd6.h b/src/include/lwip/nd6.h index ac2b7877..c5f27d73 100644 --- a/src/include/lwip/nd6.h +++ b/src/include/lwip/nd6.h @@ -106,7 +106,6 @@ struct nd6_router_list_entry { u8_t flags; }; - enum nd6_neighbor_cache_entry_state { ND6_NO_ENTRY = 0, ND6_INCOMPLETE, @@ -126,208 +125,6 @@ struct nd6_q_entry { }; #endif /* LWIP_ND6_QUEUEING */ -/** Neighbor solicitation message header. */ -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/bpstruct.h" -#endif -PACK_STRUCT_BEGIN -struct ns_header { - PACK_STRUCT_FLD_8(u8_t type); - PACK_STRUCT_FLD_8(u8_t code); - PACK_STRUCT_FIELD(u16_t chksum); - PACK_STRUCT_FIELD(u32_t reserved); - PACK_STRUCT_FLD_S(ip6_addr_p_t target_address); - /* Options follow. */ -} PACK_STRUCT_STRUCT; -PACK_STRUCT_END -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/epstruct.h" -#endif - -/** Neighbor advertisement message header. */ -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/bpstruct.h" -#endif -PACK_STRUCT_BEGIN -struct na_header { - PACK_STRUCT_FLD_8(u8_t type); - PACK_STRUCT_FLD_8(u8_t code); - PACK_STRUCT_FIELD(u16_t chksum); - PACK_STRUCT_FLD_8(u8_t flags); - PACK_STRUCT_FLD_8(u8_t reserved[3]); - PACK_STRUCT_FLD_S(ip6_addr_p_t target_address); - /* Options follow. */ -} PACK_STRUCT_STRUCT; -PACK_STRUCT_END -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/epstruct.h" -#endif -#define ND6_FLAG_ROUTER (0x80) -#define ND6_FLAG_SOLICITED (0x40) -#define ND6_FLAG_OVERRIDE (0x20) - -/** Router solicitation message header. */ -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/bpstruct.h" -#endif -PACK_STRUCT_BEGIN -struct rs_header { - PACK_STRUCT_FLD_8(u8_t type); - PACK_STRUCT_FLD_8(u8_t code); - PACK_STRUCT_FIELD(u16_t chksum); - PACK_STRUCT_FIELD(u32_t reserved); - /* Options follow. */ -} PACK_STRUCT_STRUCT; -PACK_STRUCT_END -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/epstruct.h" -#endif - -/** Router advertisement message header. */ -#define ND6_RA_FLAG_MANAGED_ADDR_CONFIG (0x80) -#define ND6_RA_FLAG_OTHER_CONFIG (0x40) -#define ND6_RA_FLAG_HOME_AGENT (0x20) -#define ND6_RA_PREFERENCE_MASK (0x18) -#define ND6_RA_PREFERENCE_HIGH (0x08) -#define ND6_RA_PREFERENCE_MEDIUM (0x00) -#define ND6_RA_PREFERENCE_LOW (0x18) -#define ND6_RA_PREFERENCE_DISABLED (0x10) -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/bpstruct.h" -#endif -PACK_STRUCT_BEGIN -struct ra_header { - PACK_STRUCT_FLD_8(u8_t type); - PACK_STRUCT_FLD_8(u8_t code); - PACK_STRUCT_FIELD(u16_t chksum); - PACK_STRUCT_FLD_8(u8_t current_hop_limit); - PACK_STRUCT_FLD_8(u8_t flags); - PACK_STRUCT_FIELD(u16_t router_lifetime); - PACK_STRUCT_FIELD(u32_t reachable_time); - PACK_STRUCT_FIELD(u32_t retrans_timer); - /* Options follow. */ -} PACK_STRUCT_STRUCT; -PACK_STRUCT_END -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/epstruct.h" -#endif - -/** Redirect message header. */ -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/bpstruct.h" -#endif -PACK_STRUCT_BEGIN -struct redirect_header { - PACK_STRUCT_FLD_8(u8_t type); - PACK_STRUCT_FLD_8(u8_t code); - PACK_STRUCT_FIELD(u16_t chksum); - PACK_STRUCT_FIELD(u32_t reserved); - PACK_STRUCT_FLD_S(ip6_addr_p_t target_address); - PACK_STRUCT_FLD_S(ip6_addr_p_t destination_address); - /* Options follow. */ -} PACK_STRUCT_STRUCT; -PACK_STRUCT_END -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/epstruct.h" -#endif - -/** Link-layer address option. */ -#define ND6_OPTION_TYPE_SOURCE_LLADDR (0x01) -#define ND6_OPTION_TYPE_TARGET_LLADDR (0x02) -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/bpstruct.h" -#endif -PACK_STRUCT_BEGIN -struct lladdr_option { - PACK_STRUCT_FLD_8(u8_t type); - PACK_STRUCT_FLD_8(u8_t length); - PACK_STRUCT_FLD_8(u8_t addr[NETIF_MAX_HWADDR_LEN]); -} PACK_STRUCT_STRUCT; -PACK_STRUCT_END -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/epstruct.h" -#endif - -/** Prefix information option. */ -#define ND6_OPTION_TYPE_PREFIX_INFO (0x03) -#define ND6_PREFIX_FLAG_ON_LINK (0x80) -#define ND6_PREFIX_FLAG_AUTONOMOUS (0x40) -#define ND6_PREFIX_FLAG_ROUTER_ADDRESS (0x20) -#define ND6_PREFIX_FLAG_SITE_PREFIX (0x10) -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/bpstruct.h" -#endif -PACK_STRUCT_BEGIN -struct prefix_option { - PACK_STRUCT_FLD_8(u8_t type); - PACK_STRUCT_FLD_8(u8_t length); - PACK_STRUCT_FLD_8(u8_t prefix_length); - PACK_STRUCT_FLD_8(u8_t flags); - PACK_STRUCT_FIELD(u32_t valid_lifetime); - PACK_STRUCT_FIELD(u32_t preferred_lifetime); - PACK_STRUCT_FLD_8(u8_t reserved2[3]); - PACK_STRUCT_FLD_8(u8_t site_prefix_length); - PACK_STRUCT_FLD_S(ip6_addr_p_t prefix); -} PACK_STRUCT_STRUCT; -PACK_STRUCT_END -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/epstruct.h" -#endif - -/** Redirected header option. */ -#define ND6_OPTION_TYPE_REDIR_HDR (0x04) -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/bpstruct.h" -#endif -PACK_STRUCT_BEGIN -struct redirected_header_option { - PACK_STRUCT_FLD_8(u8_t type); - PACK_STRUCT_FLD_8(u8_t length); - PACK_STRUCT_FLD_8(u8_t reserved[6]); - /* Portion of redirected packet follows. */ - /* PACK_STRUCT_FLD_8(u8_t redirected[8]); */ -} PACK_STRUCT_STRUCT; -PACK_STRUCT_END -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/epstruct.h" -#endif - -/** MTU option. */ -#define ND6_OPTION_TYPE_MTU (0x05) -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/bpstruct.h" -#endif -PACK_STRUCT_BEGIN -struct mtu_option { - PACK_STRUCT_FLD_8(u8_t type); - PACK_STRUCT_FLD_8(u8_t length); - PACK_STRUCT_FIELD(u16_t reserved); - PACK_STRUCT_FIELD(u32_t mtu); -} PACK_STRUCT_STRUCT; -PACK_STRUCT_END -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/epstruct.h" -#endif - -/** Route information option. */ -#define ND6_OPTION_TYPE_ROUTE_INFO (24) -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/bpstruct.h" -#endif -PACK_STRUCT_BEGIN -struct route_option { - PACK_STRUCT_FLD_8(u8_t type); - PACK_STRUCT_FLD_8(u8_t length); - PACK_STRUCT_FLD_8(u8_t prefix_length); - PACK_STRUCT_FLD_8(u8_t preference); - PACK_STRUCT_FIELD(u32_t route_lifetime); - PACK_STRUCT_FLD_S(ip6_addr_p_t prefix); -} PACK_STRUCT_STRUCT; -PACK_STRUCT_END -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/epstruct.h" -#endif - /** 1 second period */ #define ND6_TMR_INTERVAL 1000 diff --git a/src/include/lwip/prot/nd6.h b/src/include/lwip/prot/nd6.h new file mode 100644 index 00000000..37a079b3 --- /dev/null +++ b/src/include/lwip/prot/nd6.h @@ -0,0 +1,252 @@ +/** + * @file + * UDP protocol definitions + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_HDR_PROT_ND6_H +#define LWIP_HDR_PROT_ND6_H + +#include "lwip/arch.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** Neighbor solicitation message header. */ +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +struct ns_header { + PACK_STRUCT_FLD_8(u8_t type); + PACK_STRUCT_FLD_8(u8_t code); + PACK_STRUCT_FIELD(u16_t chksum); + PACK_STRUCT_FIELD(u32_t reserved); + PACK_STRUCT_FLD_S(ip6_addr_p_t target_address); + /* Options follow. */ +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + +/** Neighbor advertisement message header. */ +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +struct na_header { + PACK_STRUCT_FLD_8(u8_t type); + PACK_STRUCT_FLD_8(u8_t code); + PACK_STRUCT_FIELD(u16_t chksum); + PACK_STRUCT_FLD_8(u8_t flags); + PACK_STRUCT_FLD_8(u8_t reserved[3]); + PACK_STRUCT_FLD_S(ip6_addr_p_t target_address); + /* Options follow. */ +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif +#define ND6_FLAG_ROUTER (0x80) +#define ND6_FLAG_SOLICITED (0x40) +#define ND6_FLAG_OVERRIDE (0x20) + +/** Router solicitation message header. */ +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +struct rs_header { + PACK_STRUCT_FLD_8(u8_t type); + PACK_STRUCT_FLD_8(u8_t code); + PACK_STRUCT_FIELD(u16_t chksum); + PACK_STRUCT_FIELD(u32_t reserved); + /* Options follow. */ +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + +/** Router advertisement message header. */ +#define ND6_RA_FLAG_MANAGED_ADDR_CONFIG (0x80) +#define ND6_RA_FLAG_OTHER_CONFIG (0x40) +#define ND6_RA_FLAG_HOME_AGENT (0x20) +#define ND6_RA_PREFERENCE_MASK (0x18) +#define ND6_RA_PREFERENCE_HIGH (0x08) +#define ND6_RA_PREFERENCE_MEDIUM (0x00) +#define ND6_RA_PREFERENCE_LOW (0x18) +#define ND6_RA_PREFERENCE_DISABLED (0x10) +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +struct ra_header { + PACK_STRUCT_FLD_8(u8_t type); + PACK_STRUCT_FLD_8(u8_t code); + PACK_STRUCT_FIELD(u16_t chksum); + PACK_STRUCT_FLD_8(u8_t current_hop_limit); + PACK_STRUCT_FLD_8(u8_t flags); + PACK_STRUCT_FIELD(u16_t router_lifetime); + PACK_STRUCT_FIELD(u32_t reachable_time); + PACK_STRUCT_FIELD(u32_t retrans_timer); + /* Options follow. */ +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + +/** Redirect message header. */ +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +struct redirect_header { + PACK_STRUCT_FLD_8(u8_t type); + PACK_STRUCT_FLD_8(u8_t code); + PACK_STRUCT_FIELD(u16_t chksum); + PACK_STRUCT_FIELD(u32_t reserved); + PACK_STRUCT_FLD_S(ip6_addr_p_t target_address); + PACK_STRUCT_FLD_S(ip6_addr_p_t destination_address); + /* Options follow. */ +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + +/** Link-layer address option. */ +#define ND6_OPTION_TYPE_SOURCE_LLADDR (0x01) +#define ND6_OPTION_TYPE_TARGET_LLADDR (0x02) +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +struct lladdr_option { + PACK_STRUCT_FLD_8(u8_t type); + PACK_STRUCT_FLD_8(u8_t length); + PACK_STRUCT_FLD_8(u8_t addr[NETIF_MAX_HWADDR_LEN]); +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + +/** Prefix information option. */ +#define ND6_OPTION_TYPE_PREFIX_INFO (0x03) +#define ND6_PREFIX_FLAG_ON_LINK (0x80) +#define ND6_PREFIX_FLAG_AUTONOMOUS (0x40) +#define ND6_PREFIX_FLAG_ROUTER_ADDRESS (0x20) +#define ND6_PREFIX_FLAG_SITE_PREFIX (0x10) +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +struct prefix_option { + PACK_STRUCT_FLD_8(u8_t type); + PACK_STRUCT_FLD_8(u8_t length); + PACK_STRUCT_FLD_8(u8_t prefix_length); + PACK_STRUCT_FLD_8(u8_t flags); + PACK_STRUCT_FIELD(u32_t valid_lifetime); + PACK_STRUCT_FIELD(u32_t preferred_lifetime); + PACK_STRUCT_FLD_8(u8_t reserved2[3]); + PACK_STRUCT_FLD_8(u8_t site_prefix_length); + PACK_STRUCT_FLD_S(ip6_addr_p_t prefix); +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + +/** Redirected header option. */ +#define ND6_OPTION_TYPE_REDIR_HDR (0x04) +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +struct redirected_header_option { + PACK_STRUCT_FLD_8(u8_t type); + PACK_STRUCT_FLD_8(u8_t length); + PACK_STRUCT_FLD_8(u8_t reserved[6]); + /* Portion of redirected packet follows. */ + /* PACK_STRUCT_FLD_8(u8_t redirected[8]); */ +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + +/** MTU option. */ +#define ND6_OPTION_TYPE_MTU (0x05) +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +struct mtu_option { + PACK_STRUCT_FLD_8(u8_t type); + PACK_STRUCT_FLD_8(u8_t length); + PACK_STRUCT_FIELD(u16_t reserved); + PACK_STRUCT_FIELD(u32_t mtu); +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + +/** Route information option. */ +#define ND6_OPTION_TYPE_ROUTE_INFO (24) +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +struct route_option { + PACK_STRUCT_FLD_8(u8_t type); + PACK_STRUCT_FLD_8(u8_t length); + PACK_STRUCT_FLD_8(u8_t prefix_length); + PACK_STRUCT_FLD_8(u8_t preference); + PACK_STRUCT_FIELD(u32_t route_lifetime); + PACK_STRUCT_FLD_S(ip6_addr_p_t prefix); +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_PROT_ND6_H */ From f299b4b7cf3ef8e83c1dd6ed345c31eab8142555 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Thu, 18 Aug 2016 20:33:38 +0200 Subject: [PATCH 109/325] Work on bug #48728: headers should cleanly separate API vs. implementation Ethernet --- src/include/lwip/prot/ethernet.h | 134 +++++++++++++++++++++++++++++++ src/include/netif/ethernet.h | 89 +------------------- 2 files changed, 135 insertions(+), 88 deletions(-) create mode 100644 src/include/lwip/prot/ethernet.h diff --git a/src/include/lwip/prot/ethernet.h b/src/include/lwip/prot/ethernet.h new file mode 100644 index 00000000..4a29af8a --- /dev/null +++ b/src/include/lwip/prot/ethernet.h @@ -0,0 +1,134 @@ +/** + * @file + * UDP protocol definitions + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_HDR_PROT_ETHERNET_H +#define LWIP_HDR_PROT_ETHERNET_H + +#include "lwip/arch.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef ETH_HWADDR_LEN +#ifdef ETHARP_HWADDR_LEN +#define ETH_HWADDR_LEN ETHARP_HWADDR_LEN /* compatibility mode */ +#else +#define ETH_HWADDR_LEN 6 +#endif +#endif + +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +struct eth_addr { + PACK_STRUCT_FLD_8(u8_t addr[ETH_HWADDR_LEN]); +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +/** Ethernet header */ +struct eth_hdr { +#if ETH_PAD_SIZE + PACK_STRUCT_FLD_8(u8_t padding[ETH_PAD_SIZE]); +#endif + PACK_STRUCT_FLD_S(struct eth_addr dest); + PACK_STRUCT_FLD_S(struct eth_addr src); + PACK_STRUCT_FIELD(u16_t type); +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + +#define SIZEOF_ETH_HDR (14 + ETH_PAD_SIZE) + +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +/** VLAN header inserted between ethernet header and payload + * if 'type' in ethernet header is ETHTYPE_VLAN. + * See IEEE802.Q */ +struct eth_vlan_hdr { + PACK_STRUCT_FIELD(u16_t prio_vid); + PACK_STRUCT_FIELD(u16_t tpid); +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + +#define SIZEOF_VLAN_HDR 4 +#define VLAN_ID(vlan_hdr) (htons((vlan_hdr)->prio_vid) & 0xFFF) + +/* A list of often ethtypes (although lwIP does not use all of them): */ +#define ETHTYPE_IP 0x0800U /* Internet protocol v4 */ +#define ETHTYPE_ARP 0x0806U /* Address resolution protocol */ +#define ETHTYPE_WOL 0x0842U /* Wake on lan */ +#define ETHTYPE_VLAN 0x8100U /* Virtual local area network */ +#define ETHTYPE_IPV6 0x86DDU /* Internet protocol v6 */ +#define ETHTYPE_PPPOEDISC 0x8863U /* PPP Over Ethernet Discovery Stage */ +#define ETHTYPE_PPPOE 0x8864U /* PPP Over Ethernet Session Stage */ +#define ETHTYPE_JUMBO 0x8870U /* Jumbo Frames */ +#define ETHTYPE_PROFINET 0x8892U /* Process field network */ +#define ETHTYPE_ETHERCAT 0x88A4U /* Ethernet for control automation technology */ +#define ETHTYPE_LLDP 0x88CCU /* Link layer discovery protocol */ +#define ETHTYPE_SERCOS 0x88CDU /* Serial real-time communication system */ +#define ETHTYPE_PTP 0x88F7U /* Precision time protocol */ +#define ETHTYPE_QINQ 0x9100U /* Q-in-Q, 802.1ad */ + +/** The 24-bit IANA IPv4-multicast OUI is 01-00-5e: */ +#define LL_IP4_MULTICAST_ADDR_0 0x01 +#define LL_IP4_MULTICAST_ADDR_1 0x00 +#define LL_IP4_MULTICAST_ADDR_2 0x5e + +/** IPv6 multicast uses this prefix */ +#define LL_IP6_MULTICAST_ADDR_0 0x33 +#define LL_IP6_MULTICAST_ADDR_1 0x33 + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_PROT_ETHERNET_H */ diff --git a/src/include/netif/ethernet.h b/src/include/netif/ethernet.h index 03bfe7f8..7d41af10 100644 --- a/src/include/netif/ethernet.h +++ b/src/include/netif/ethernet.h @@ -45,99 +45,12 @@ #include "lwip/pbuf.h" #include "lwip/netif.h" +#include "lwip/prot/ethernet.h" #ifdef __cplusplus extern "C" { #endif -#ifndef ETH_HWADDR_LEN -#ifdef ETHARP_HWADDR_LEN -#define ETH_HWADDR_LEN ETHARP_HWADDR_LEN /* compatibility mode */ -#else -#define ETH_HWADDR_LEN 6 -#endif -#endif - -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/bpstruct.h" -#endif -PACK_STRUCT_BEGIN -struct eth_addr { - PACK_STRUCT_FLD_8(u8_t addr[ETH_HWADDR_LEN]); -} PACK_STRUCT_STRUCT; -PACK_STRUCT_END -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/epstruct.h" -#endif - -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/bpstruct.h" -#endif -PACK_STRUCT_BEGIN -/** Ethernet header */ -struct eth_hdr { -#if ETH_PAD_SIZE - PACK_STRUCT_FLD_8(u8_t padding[ETH_PAD_SIZE]); -#endif - PACK_STRUCT_FLD_S(struct eth_addr dest); - PACK_STRUCT_FLD_S(struct eth_addr src); - PACK_STRUCT_FIELD(u16_t type); -} PACK_STRUCT_STRUCT; -PACK_STRUCT_END -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/epstruct.h" -#endif - -#define SIZEOF_ETH_HDR (14 + ETH_PAD_SIZE) - -#if ETHARP_SUPPORT_VLAN - -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/bpstruct.h" -#endif -PACK_STRUCT_BEGIN -/** VLAN header inserted between ethernet header and payload - * if 'type' in ethernet header is ETHTYPE_VLAN. - * See IEEE802.Q */ -struct eth_vlan_hdr { - PACK_STRUCT_FIELD(u16_t prio_vid); - PACK_STRUCT_FIELD(u16_t tpid); -} PACK_STRUCT_STRUCT; -PACK_STRUCT_END -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/epstruct.h" -#endif - -#define SIZEOF_VLAN_HDR 4 -#define VLAN_ID(vlan_hdr) (htons((vlan_hdr)->prio_vid) & 0xFFF) - -#endif /* ETHARP_SUPPORT_VLAN */ - -/* A list of often ethtypes (although lwIP does not use all of them): */ -#define ETHTYPE_IP 0x0800U /* Internet protocol v4 */ -#define ETHTYPE_ARP 0x0806U /* Address resolution protocol */ -#define ETHTYPE_WOL 0x0842U /* Wake on lan */ -#define ETHTYPE_VLAN 0x8100U /* Virtual local area network */ -#define ETHTYPE_IPV6 0x86DDU /* Internet protocol v6 */ -#define ETHTYPE_PPPOEDISC 0x8863U /* PPP Over Ethernet Discovery Stage */ -#define ETHTYPE_PPPOE 0x8864U /* PPP Over Ethernet Session Stage */ -#define ETHTYPE_JUMBO 0x8870U /* Jumbo Frames */ -#define ETHTYPE_PROFINET 0x8892U /* Process field network */ -#define ETHTYPE_ETHERCAT 0x88A4U /* Ethernet for control automation technology */ -#define ETHTYPE_LLDP 0x88CCU /* Link layer discovery protocol */ -#define ETHTYPE_SERCOS 0x88CDU /* Serial real-time communication system */ -#define ETHTYPE_PTP 0x88F7U /* Precision time protocol */ -#define ETHTYPE_QINQ 0x9100U /* Q-in-Q, 802.1ad */ - -/** The 24-bit IANA IPv4-multicast OUI is 01-00-5e: */ -#define LL_IP4_MULTICAST_ADDR_0 0x01 -#define LL_IP4_MULTICAST_ADDR_1 0x00 -#define LL_IP4_MULTICAST_ADDR_2 0x5e - -/** IPv6 multicast uses this prefix */ -#define LL_IP6_MULTICAST_ADDR_0 0x33 -#define LL_IP6_MULTICAST_ADDR_1 0x33 - /** MEMCPY-like macro to copy to/from struct eth_addr's that are local variables * or known to be 32-bit aligned within the protocol header. */ #ifndef ETHADDR32_COPY From 81c68f529ba96b26339d0932259aed1526657103 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Thu, 18 Aug 2016 20:36:44 +0200 Subject: [PATCH 110/325] Work on bug #48728: headers should cleanly separate API vs. implementation MLD6 --- src/core/ipv6/mld6.c | 1 + src/include/lwip/mld6.h | 22 ------------ src/include/lwip/prot/mld6.h | 70 ++++++++++++++++++++++++++++++++++++ src/include/lwip/prot/nd6.h | 1 + 4 files changed, 72 insertions(+), 22 deletions(-) create mode 100644 src/include/lwip/prot/mld6.h diff --git a/src/core/ipv6/mld6.c b/src/core/ipv6/mld6.c index e407a12a..f5e07ec4 100644 --- a/src/core/ipv6/mld6.c +++ b/src/core/ipv6/mld6.c @@ -51,6 +51,7 @@ #if LWIP_IPV6 && LWIP_IPV6_MLD /* don't build if not configured for use in lwipopts.h */ #include "lwip/mld6.h" +#include "lwip/prot/mld6.h" #include "lwip/icmp6.h" #include "lwip/ip6.h" #include "lwip/ip6_addr.h" diff --git a/src/include/lwip/mld6.h b/src/include/lwip/mld6.h index 6fcd110f..000053be 100644 --- a/src/include/lwip/mld6.h +++ b/src/include/lwip/mld6.h @@ -50,7 +50,6 @@ #include "lwip/pbuf.h" #include "lwip/netif.h" - #ifdef __cplusplus extern "C" { #endif @@ -73,25 +72,6 @@ struct mld_group { u8_t use; }; -/** Multicast listener report/query/done message header. */ -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/bpstruct.h" -#endif -PACK_STRUCT_BEGIN -struct mld_header { - PACK_STRUCT_FLD_8(u8_t type); - PACK_STRUCT_FLD_8(u8_t code); - PACK_STRUCT_FIELD(u16_t chksum); - PACK_STRUCT_FIELD(u16_t max_resp_delay); - PACK_STRUCT_FIELD(u16_t reserved); - PACK_STRUCT_FLD_S(ip6_addr_p_t multicast_address); - /* Options follow. */ -} PACK_STRUCT_STRUCT; -PACK_STRUCT_END -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/epstruct.h" -#endif - #define MLD6_TMR_INTERVAL 100 /* Milliseconds */ /* MAC Filter Actions, these are passed to a netif's @@ -99,7 +79,6 @@ PACK_STRUCT_END #define MLD6_DEL_MAC_FILTER 0 #define MLD6_ADD_MAC_FILTER 1 - err_t mld6_stop(struct netif *netif); void mld6_report_groups(struct netif *netif); void mld6_tmr(void); @@ -110,7 +89,6 @@ err_t mld6_joingroup_netif(struct netif *netif, const ip6_addr_t *groupaddr); err_t mld6_leavegroup(const ip6_addr_t *srcaddr, const ip6_addr_t *groupaddr); err_t mld6_leavegroup_netif(struct netif *netif, const ip6_addr_t *groupaddr); - #ifdef __cplusplus } #endif diff --git a/src/include/lwip/prot/mld6.h b/src/include/lwip/prot/mld6.h new file mode 100644 index 00000000..8755d51a --- /dev/null +++ b/src/include/lwip/prot/mld6.h @@ -0,0 +1,70 @@ +/** + * @file + * UDP protocol definitions + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_HDR_PROT_MLD6_H +#define LWIP_HDR_PROT_MLD6_H + +#include "lwip/arch.h" +#include "lwip/ip6_addr.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** Multicast listener report/query/done message header. */ +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +struct mld_header { + PACK_STRUCT_FLD_8(u8_t type); + PACK_STRUCT_FLD_8(u8_t code); + PACK_STRUCT_FIELD(u16_t chksum); + PACK_STRUCT_FIELD(u16_t max_resp_delay); + PACK_STRUCT_FIELD(u16_t reserved); + PACK_STRUCT_FLD_S(ip6_addr_p_t multicast_address); + /* Options follow. */ +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_PROT_MLD6_H */ diff --git a/src/include/lwip/prot/nd6.h b/src/include/lwip/prot/nd6.h index 37a079b3..0a0dde48 100644 --- a/src/include/lwip/prot/nd6.h +++ b/src/include/lwip/prot/nd6.h @@ -38,6 +38,7 @@ #define LWIP_HDR_PROT_ND6_H #include "lwip/arch.h" +#include "lwip/ip6_addr.h" #ifdef __cplusplus extern "C" { From 84e139f20ca937ea46125d84b14588c1116e50fd Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Thu, 18 Aug 2016 20:40:15 +0200 Subject: [PATCH 111/325] Work on bug #48728: headers should cleanly separate API vs. implementation IP6 --- src/include/lwip/ip6.h | 106 +------------------------ src/include/lwip/prot/ip6.h | 154 ++++++++++++++++++++++++++++++++++++ 2 files changed, 155 insertions(+), 105 deletions(-) create mode 100644 src/include/lwip/prot/ip6.h diff --git a/src/include/lwip/ip6.h b/src/include/lwip/ip6.h index 7b3fe876..099b94fb 100644 --- a/src/include/lwip/ip6.h +++ b/src/include/lwip/ip6.h @@ -46,6 +46,7 @@ #if LWIP_IPV6 /* don't build if not configured for use in lwipopts.h */ #include "lwip/ip6_addr.h" +#include "lwip/prot/ip6.h" #include "lwip/def.h" #include "lwip/pbuf.h" #include "lwip/netif.h" @@ -56,111 +57,6 @@ extern "C" { #endif -#define IP6_HLEN 40 - -#define IP6_NEXTH_HOPBYHOP 0 -#define IP6_NEXTH_TCP 6 -#define IP6_NEXTH_UDP 17 -#define IP6_NEXTH_ENCAPS 41 -#define IP6_NEXTH_ROUTING 43 -#define IP6_NEXTH_FRAGMENT 44 -#define IP6_NEXTH_ICMP6 58 -#define IP6_NEXTH_NONE 59 -#define IP6_NEXTH_DESTOPTS 60 -#define IP6_NEXTH_UDPLITE 136 - - -/** The IPv6 header. */ -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/bpstruct.h" -#endif -PACK_STRUCT_BEGIN -struct ip6_hdr { - /** version / traffic class / flow label */ - PACK_STRUCT_FIELD(u32_t _v_tc_fl); - /** payload length */ - PACK_STRUCT_FIELD(u16_t _plen); - /** next header */ - PACK_STRUCT_FLD_8(u8_t _nexth); - /** hop limit */ - PACK_STRUCT_FLD_8(u8_t _hoplim); - /** source and destination IP addresses */ - PACK_STRUCT_FLD_S(ip6_addr_p_t src); - PACK_STRUCT_FLD_S(ip6_addr_p_t dest); -} PACK_STRUCT_STRUCT; -PACK_STRUCT_END -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/epstruct.h" -#endif - -/* Hop-by-hop router alert option. */ -#define IP6_HBH_HLEN 8 -#define IP6_PAD1_OPTION 0 -#define IP6_PADN_ALERT_OPTION 1 -#define IP6_ROUTER_ALERT_OPTION 5 -#define IP6_ROUTER_ALERT_VALUE_MLD 0 -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/bpstruct.h" -#endif -PACK_STRUCT_BEGIN -struct ip6_hbh_hdr { - /* next header */ - PACK_STRUCT_FLD_8(u8_t _nexth); - /* header length */ - PACK_STRUCT_FLD_8(u8_t _hlen); - /* router alert option type */ - PACK_STRUCT_FLD_8(u8_t _ra_opt_type); - /* router alert option data len */ - PACK_STRUCT_FLD_8(u8_t _ra_opt_dlen); - /* router alert option data */ - PACK_STRUCT_FIELD(u16_t _ra_opt_data); - /* PadN option type */ - PACK_STRUCT_FLD_8(u8_t _padn_opt_type); - /* PadN option data len */ - PACK_STRUCT_FLD_8(u8_t _padn_opt_dlen); -} PACK_STRUCT_STRUCT; -PACK_STRUCT_END -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/epstruct.h" -#endif - -/* Fragment header. */ -#define IP6_FRAG_HLEN 8 -#define IP6_FRAG_OFFSET_MASK 0xfff8 -#define IP6_FRAG_MORE_FLAG 0x0001 -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/bpstruct.h" -#endif -PACK_STRUCT_BEGIN -struct ip6_frag_hdr { - /* next header */ - PACK_STRUCT_FLD_8(u8_t _nexth); - /* reserved */ - PACK_STRUCT_FLD_8(u8_t reserved); - /* fragment offset */ - PACK_STRUCT_FIELD(u16_t _fragment_offset); - /* fragmented packet identification */ - PACK_STRUCT_FIELD(u32_t _identification); -} PACK_STRUCT_STRUCT; -PACK_STRUCT_END -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/epstruct.h" -#endif - -#define IP6H_V(hdr) ((ntohl((hdr)->_v_tc_fl) >> 28) & 0x0f) -#define IP6H_TC(hdr) ((ntohl((hdr)->_v_tc_fl) >> 20) & 0xff) -#define IP6H_FL(hdr) (ntohl((hdr)->_v_tc_fl) & 0x000fffff) -#define IP6H_PLEN(hdr) (ntohs((hdr)->_plen)) -#define IP6H_NEXTH(hdr) ((hdr)->_nexth) -#define IP6H_NEXTH_P(hdr) ((u8_t *)(hdr) + 6) -#define IP6H_HOPLIM(hdr) ((hdr)->_hoplim) - -#define IP6H_VTCFL_SET(hdr, v, tc, fl) (hdr)->_v_tc_fl = (htonl((((u32_t)(v)) << 28) | (((u32_t)(tc)) << 20) | (fl))) -#define IP6H_PLEN_SET(hdr, plen) (hdr)->_plen = htons(plen) -#define IP6H_NEXTH_SET(hdr, nexth) (hdr)->_nexth = (nexth) -#define IP6H_HOPLIM_SET(hdr, hl) (hdr)->_hoplim = (u8_t)(hl) - - struct netif *ip6_route(const ip6_addr_t *src, const ip6_addr_t *dest); const ip_addr_t *ip6_select_source_address(struct netif *netif, const ip6_addr_t * dest); err_t ip6_input(struct pbuf *p, struct netif *inp); diff --git a/src/include/lwip/prot/ip6.h b/src/include/lwip/prot/ip6.h new file mode 100644 index 00000000..0e801bf9 --- /dev/null +++ b/src/include/lwip/prot/ip6.h @@ -0,0 +1,154 @@ +/** + * @file + * IPv6 protocol definitions + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_HDR_PROT_IP6_H +#define LWIP_HDR_PROT_IP6_H + +#include "lwip/arch.h" +#include "lwip/ip6_addr.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define IP6_HLEN 40 + +#define IP6_NEXTH_HOPBYHOP 0 +#define IP6_NEXTH_TCP 6 +#define IP6_NEXTH_UDP 17 +#define IP6_NEXTH_ENCAPS 41 +#define IP6_NEXTH_ROUTING 43 +#define IP6_NEXTH_FRAGMENT 44 +#define IP6_NEXTH_ICMP6 58 +#define IP6_NEXTH_NONE 59 +#define IP6_NEXTH_DESTOPTS 60 +#define IP6_NEXTH_UDPLITE 136 + +/** The IPv6 header. */ +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +struct ip6_hdr { + /** version / traffic class / flow label */ + PACK_STRUCT_FIELD(u32_t _v_tc_fl); + /** payload length */ + PACK_STRUCT_FIELD(u16_t _plen); + /** next header */ + PACK_STRUCT_FLD_8(u8_t _nexth); + /** hop limit */ + PACK_STRUCT_FLD_8(u8_t _hoplim); + /** source and destination IP addresses */ + PACK_STRUCT_FLD_S(ip6_addr_p_t src); + PACK_STRUCT_FLD_S(ip6_addr_p_t dest); +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + +/* Hop-by-hop router alert option. */ +#define IP6_HBH_HLEN 8 +#define IP6_PAD1_OPTION 0 +#define IP6_PADN_ALERT_OPTION 1 +#define IP6_ROUTER_ALERT_OPTION 5 +#define IP6_ROUTER_ALERT_VALUE_MLD 0 +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +struct ip6_hbh_hdr { + /* next header */ + PACK_STRUCT_FLD_8(u8_t _nexth); + /* header length */ + PACK_STRUCT_FLD_8(u8_t _hlen); + /* router alert option type */ + PACK_STRUCT_FLD_8(u8_t _ra_opt_type); + /* router alert option data len */ + PACK_STRUCT_FLD_8(u8_t _ra_opt_dlen); + /* router alert option data */ + PACK_STRUCT_FIELD(u16_t _ra_opt_data); + /* PadN option type */ + PACK_STRUCT_FLD_8(u8_t _padn_opt_type); + /* PadN option data len */ + PACK_STRUCT_FLD_8(u8_t _padn_opt_dlen); +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + +/* Fragment header. */ +#define IP6_FRAG_HLEN 8 +#define IP6_FRAG_OFFSET_MASK 0xfff8 +#define IP6_FRAG_MORE_FLAG 0x0001 +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +struct ip6_frag_hdr { + /* next header */ + PACK_STRUCT_FLD_8(u8_t _nexth); + /* reserved */ + PACK_STRUCT_FLD_8(u8_t reserved); + /* fragment offset */ + PACK_STRUCT_FIELD(u16_t _fragment_offset); + /* fragmented packet identification */ + PACK_STRUCT_FIELD(u32_t _identification); +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + +#define IP6H_V(hdr) ((ntohl((hdr)->_v_tc_fl) >> 28) & 0x0f) +#define IP6H_TC(hdr) ((ntohl((hdr)->_v_tc_fl) >> 20) & 0xff) +#define IP6H_FL(hdr) (ntohl((hdr)->_v_tc_fl) & 0x000fffff) +#define IP6H_PLEN(hdr) (ntohs((hdr)->_plen)) +#define IP6H_NEXTH(hdr) ((hdr)->_nexth) +#define IP6H_NEXTH_P(hdr) ((u8_t *)(hdr) + 6) +#define IP6H_HOPLIM(hdr) ((hdr)->_hoplim) + +#define IP6H_VTCFL_SET(hdr, v, tc, fl) (hdr)->_v_tc_fl = (htonl((((u32_t)(v)) << 28) | (((u32_t)(tc)) << 20) | (fl))) +#define IP6H_PLEN_SET(hdr, plen) (hdr)->_plen = htons(plen) +#define IP6H_NEXTH_SET(hdr, nexth) (hdr)->_nexth = (nexth) +#define IP6H_HOPLIM_SET(hdr, hl) (hdr)->_hoplim = (u8_t)(hl) + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_PROT_IP6_H */ From 458211c2aff8fd486505fc79f8c82952c7bb08d9 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Thu, 18 Aug 2016 20:41:39 +0200 Subject: [PATCH 112/325] Comment fixes in my last commits --- src/include/lwip/prot/ethernet.h | 2 +- src/include/lwip/prot/mld6.h | 2 +- src/include/lwip/prot/nd6.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/include/lwip/prot/ethernet.h b/src/include/lwip/prot/ethernet.h index 4a29af8a..6ebc1008 100644 --- a/src/include/lwip/prot/ethernet.h +++ b/src/include/lwip/prot/ethernet.h @@ -1,6 +1,6 @@ /** * @file - * UDP protocol definitions + * Ethernet protocol definitions */ /* diff --git a/src/include/lwip/prot/mld6.h b/src/include/lwip/prot/mld6.h index 8755d51a..86ccc8fb 100644 --- a/src/include/lwip/prot/mld6.h +++ b/src/include/lwip/prot/mld6.h @@ -1,6 +1,6 @@ /** * @file - * UDP protocol definitions + * MLD6 protocol definitions */ /* diff --git a/src/include/lwip/prot/nd6.h b/src/include/lwip/prot/nd6.h index 0a0dde48..eae3d28e 100644 --- a/src/include/lwip/prot/nd6.h +++ b/src/include/lwip/prot/nd6.h @@ -1,6 +1,6 @@ /** * @file - * UDP protocol definitions + * ND6 protocol definitions */ /* From 5df88220c4f3b25c9debf626fa6b227c637a9d4b Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Thu, 18 Aug 2016 20:43:33 +0200 Subject: [PATCH 113/325] Fix compile of MDNS unit test with GCC --- test/unit/mdns/test_mdns.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/unit/mdns/test_mdns.c b/test/unit/mdns/test_mdns.c index d1d2cb71..b149a7e0 100644 --- a/test/unit/mdns/test_mdns.c +++ b/test/unit/mdns/test_mdns.c @@ -523,21 +523,21 @@ START_TEST(domain_eq_anydata) err_t res; memset(&domain1, 0, sizeof(domain1)); - res = mdns_domain_add_label(&domain1, (char*)data1, sizeof(data1)); + res = mdns_domain_add_label(&domain1, (const char*)data1, sizeof(data1)); fail_unless(res == ERR_OK); res = mdns_domain_add_label(&domain1, "cast", 4); fail_unless(res == ERR_OK); - res = mdns_domain_add_label(&domain1, (char*)data2, sizeof(data2)); + res = mdns_domain_add_label(&domain1, (const char*)data2, sizeof(data2)); fail_unless(res == ERR_OK); res = mdns_domain_add_label(&domain1, NULL, 0); fail_unless(res == ERR_OK); memset(&domain2, 0, sizeof(domain2)); - res = mdns_domain_add_label(&domain2, (char*)data1, sizeof(data1)); + res = mdns_domain_add_label(&domain2, (const char*)data1, sizeof(data1)); fail_unless(res == ERR_OK); res = mdns_domain_add_label(&domain2, "casT", 4); fail_unless(res == ERR_OK); - res = mdns_domain_add_label(&domain2, (char*)data2, sizeof(data2)); + res = mdns_domain_add_label(&domain2, (const char*)data2, sizeof(data2)); fail_unless(res == ERR_OK); res = mdns_domain_add_label(&domain2, NULL, 0); fail_unless(res == ERR_OK); From 2d503f4433d6f94308ac7105cb438433f519fa52 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Thu, 18 Aug 2016 20:52:00 +0200 Subject: [PATCH 114/325] Work on bug #48728: headers should cleanly separate API vs. implementation ICMP6 --- src/core/ipv6/icmp6.c | 1 + src/core/ipv6/nd6.c | 1 + src/include/lwip/icmp6.h | 34 -------------- src/include/lwip/prot/icmp6.h | 83 +++++++++++++++++++++++++++++++++++ 4 files changed, 85 insertions(+), 34 deletions(-) create mode 100644 src/include/lwip/prot/icmp6.h diff --git a/src/core/ipv6/icmp6.c b/src/core/ipv6/icmp6.c index e4df692e..323b69a2 100644 --- a/src/core/ipv6/icmp6.c +++ b/src/core/ipv6/icmp6.c @@ -44,6 +44,7 @@ #if LWIP_ICMP6 && LWIP_IPV6 /* don't build if not configured for use in lwipopts.h */ #include "lwip/icmp6.h" +#include "lwip/prot/icmp6.h" #include "lwip/ip6.h" #include "lwip/ip6_addr.h" #include "lwip/inet_chksum.h" diff --git a/src/core/ipv6/nd6.c b/src/core/ipv6/nd6.c index e3616813..ffa135b9 100644 --- a/src/core/ipv6/nd6.c +++ b/src/core/ipv6/nd6.c @@ -47,6 +47,7 @@ #include "lwip/nd6.h" #include "lwip/prot/nd6.h" +#include "lwip/prot/icmp6.h" #include "lwip/pbuf.h" #include "lwip/mem.h" #include "lwip/memp.h" diff --git a/src/include/lwip/icmp6.h b/src/include/lwip/icmp6.h index cfa99c27..7ef98a18 100644 --- a/src/include/lwip/icmp6.h +++ b/src/include/lwip/icmp6.h @@ -138,40 +138,6 @@ enum icmp6_pp_code { ICMP6_PP_OPTION = 2 }; -/** This is the standard ICMP6 header. */ -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/bpstruct.h" -#endif -PACK_STRUCT_BEGIN -struct icmp6_hdr { - PACK_STRUCT_FLD_8(u8_t type); - PACK_STRUCT_FLD_8(u8_t code); - PACK_STRUCT_FIELD(u16_t chksum); - PACK_STRUCT_FIELD(u32_t data); -} PACK_STRUCT_STRUCT; -PACK_STRUCT_END -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/epstruct.h" -#endif - -/** This is the ICMP6 header adapted for echo req/resp. */ -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/bpstruct.h" -#endif -PACK_STRUCT_BEGIN -struct icmp6_echo_hdr { - PACK_STRUCT_FLD_8(u8_t type); - PACK_STRUCT_FLD_8(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 -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/epstruct.h" -#endif - - #if LWIP_ICMP6 && LWIP_IPV6 /* don't build if not configured for use in lwipopts.h */ void icmp6_input(struct pbuf *p, struct netif *inp); diff --git a/src/include/lwip/prot/icmp6.h b/src/include/lwip/prot/icmp6.h new file mode 100644 index 00000000..a0a713ba --- /dev/null +++ b/src/include/lwip/prot/icmp6.h @@ -0,0 +1,83 @@ +/** + * @file + * ICMP6 protocol definitions + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_HDR_PROT_ICMP6_H +#define LWIP_HDR_PROT_ICMP6_H + +#include "lwip/arch.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** This is the standard ICMP6 header. */ +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +struct icmp6_hdr { + PACK_STRUCT_FLD_8(u8_t type); + PACK_STRUCT_FLD_8(u8_t code); + PACK_STRUCT_FIELD(u16_t chksum); + PACK_STRUCT_FIELD(u32_t data); +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + +/** This is the ICMP6 header adapted for echo req/resp. */ +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +struct icmp6_echo_hdr { + PACK_STRUCT_FLD_8(u8_t type); + PACK_STRUCT_FLD_8(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 +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_PROT_ICMP6_H */ From ad357a4c89203e1fee27b3d4cddb99c8c2c566f0 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Thu, 18 Aug 2016 20:55:09 +0200 Subject: [PATCH 115/325] Work on bug #48728: headers should cleanly separate API vs. implementation ICMP --- src/include/lwip/icmp.h | 44 +---------------- src/include/lwip/prot/icmp.h | 92 ++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+), 43 deletions(-) create mode 100644 src/include/lwip/prot/icmp.h diff --git a/src/include/lwip/icmp.h b/src/include/lwip/icmp.h index 0d3652b5..490fbf74 100644 --- a/src/include/lwip/icmp.h +++ b/src/include/lwip/icmp.h @@ -41,6 +41,7 @@ #include "lwip/pbuf.h" #include "lwip/ip_addr.h" #include "lwip/netif.h" +#include "lwip/prot/icmp.h" #if LWIP_IPV6 && LWIP_ICMP6 #include "lwip/icmp6.h" @@ -50,20 +51,6 @@ extern "C" { #endif -#define ICMP_ER 0 /* echo reply */ -#define ICMP_DUR 3 /* destination unreachable */ -#define ICMP_SQ 4 /* source quench */ -#define ICMP_RD 5 /* redirect */ -#define ICMP_ECHO 8 /* echo */ -#define ICMP_TE 11 /* time exceeded */ -#define ICMP_PP 12 /* parameter problem */ -#define ICMP_TS 13 /* timestamp */ -#define ICMP_TSR 14 /* timestamp reply */ -#define ICMP_IRQ 15 /* information request */ -#define ICMP_IR 16 /* information reply */ -#define ICMP_AM 17 /* address mask request */ -#define ICMP_AMR 18 /* address mask reply */ - /** ICMP destination unreachable codes */ enum icmp_dur_type { /** net unreachable */ @@ -88,35 +75,6 @@ enum icmp_te_type { ICMP_TE_FRAG = 1 }; -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/bpstruct.h" -#endif -/** This is the standard ICMP header only that the u32_t data - * is split 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_FLD_8(u8_t type); - PACK_STRUCT_FLD_8(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 -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/epstruct.h" -#endif - -#define ICMPH_TYPE(hdr) ((hdr)->type) -#define ICMPH_CODE(hdr) ((hdr)->code) - -/** 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)) - - #if LWIP_IPV4 && LWIP_ICMP /* don't build if not configured for use in lwipopts.h */ void icmp_input(struct pbuf *p, struct netif *inp); diff --git a/src/include/lwip/prot/icmp.h b/src/include/lwip/prot/icmp.h new file mode 100644 index 00000000..b0005a6b --- /dev/null +++ b/src/include/lwip/prot/icmp.h @@ -0,0 +1,92 @@ +/** + * @file + * ICMP protocol definitions + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_HDR_PROT_ICMP_H +#define LWIP_HDR_PROT_ICMP_H + +#include "lwip/arch.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define ICMP_ER 0 /* echo reply */ +#define ICMP_DUR 3 /* destination unreachable */ +#define ICMP_SQ 4 /* source quench */ +#define ICMP_RD 5 /* redirect */ +#define ICMP_ECHO 8 /* echo */ +#define ICMP_TE 11 /* time exceeded */ +#define ICMP_PP 12 /* parameter problem */ +#define ICMP_TS 13 /* timestamp */ +#define ICMP_TSR 14 /* timestamp reply */ +#define ICMP_IRQ 15 /* information request */ +#define ICMP_IR 16 /* information reply */ +#define ICMP_AM 17 /* address mask request */ +#define ICMP_AMR 18 /* address mask reply */ + +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +/** This is the standard ICMP header only that the u32_t data + * is split 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_FLD_8(u8_t type); + PACK_STRUCT_FLD_8(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 +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + +#define ICMPH_TYPE(hdr) ((hdr)->type) +#define ICMPH_CODE(hdr) ((hdr)->code) + +/** 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 +} +#endif + +#endif /* LWIP_HDR_PROT_ICMP_H */ From c4e3be814f359952b22c944aaff2d0f178ff19d4 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Thu, 18 Aug 2016 20:58:51 +0200 Subject: [PATCH 116/325] Work on bug #48728: headers should cleanly separate API vs. implementation ARP --- src/include/lwip/etharp.h | 29 +------------- src/include/lwip/prot/arp.h | 79 +++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 27 deletions(-) create mode 100644 src/include/lwip/prot/arp.h diff --git a/src/include/lwip/etharp.h b/src/include/lwip/etharp.h index d23b6c23..6c0b2d78 100644 --- a/src/include/lwip/etharp.h +++ b/src/include/lwip/etharp.h @@ -58,33 +58,8 @@ extern "C" { #if LWIP_IPV4 && LWIP_ARP /* don't build if not configured for use in lwipopts.h */ -#ifndef ETHARP_HWADDR_LEN -#define ETHARP_HWADDR_LEN ETH_HWADDR_LEN -#endif - -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/bpstruct.h" -#endif -PACK_STRUCT_BEGIN -/** the ARP message, see RFC 826 ("Packet format") */ -struct etharp_hdr { - PACK_STRUCT_FIELD(u16_t hwtype); - PACK_STRUCT_FIELD(u16_t proto); - PACK_STRUCT_FLD_8(u8_t hwlen); - PACK_STRUCT_FLD_8(u8_t protolen); - PACK_STRUCT_FIELD(u16_t opcode); - PACK_STRUCT_FLD_S(struct eth_addr shwaddr); - PACK_STRUCT_FLD_S(struct ip4_addr2 sipaddr); - PACK_STRUCT_FLD_S(struct eth_addr dhwaddr); - PACK_STRUCT_FLD_S(struct ip4_addr2 dipaddr); -} PACK_STRUCT_STRUCT; -PACK_STRUCT_END -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/epstruct.h" -#endif - -#define SIZEOF_ETHARP_HDR 28 - +#include "lwip/prot/arp.h" + #define SIZEOF_ETHARP_PACKET (SIZEOF_ETH_HDR + SIZEOF_ETHARP_HDR) #if ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET) #define SIZEOF_ETHARP_PACKET_TX (SIZEOF_ETHARP_PACKET + SIZEOF_VLAN_HDR) diff --git a/src/include/lwip/prot/arp.h b/src/include/lwip/prot/arp.h new file mode 100644 index 00000000..94084b90 --- /dev/null +++ b/src/include/lwip/prot/arp.h @@ -0,0 +1,79 @@ +/** + * @file + * ARP protocol definitions + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_HDR_PROT_ARP_H +#define LWIP_HDR_PROT_ARP_H + +#include "lwip/arch.h" +#include "lwip/prot/ethernet.h" +#include "lwip/ip4_addr.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef ETHARP_HWADDR_LEN +#define ETHARP_HWADDR_LEN ETH_HWADDR_LEN +#endif + +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +/** the ARP message, see RFC 826 ("Packet format") */ +struct etharp_hdr { + PACK_STRUCT_FIELD(u16_t hwtype); + PACK_STRUCT_FIELD(u16_t proto); + PACK_STRUCT_FLD_8(u8_t hwlen); + PACK_STRUCT_FLD_8(u8_t protolen); + PACK_STRUCT_FIELD(u16_t opcode); + PACK_STRUCT_FLD_S(struct eth_addr shwaddr); + PACK_STRUCT_FLD_S(struct ip4_addr2 sipaddr); + PACK_STRUCT_FLD_S(struct eth_addr dhwaddr); + PACK_STRUCT_FLD_S(struct ip4_addr2 dipaddr); +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + +#define SIZEOF_ETHARP_HDR 28 + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_PROT_ARP_H */ From 7c0d9523793e4e2f1e4ab23faa37beab430a5008 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Thu, 18 Aug 2016 21:09:34 +0200 Subject: [PATCH 117/325] Add explicit documentation page about reporting bugs --- doc/doxygen/main_page.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/doc/doxygen/main_page.h b/doc/doxygen/main_page.h index f93c5dff..6486a17d 100644 --- a/doc/doxygen/main_page.h +++ b/doc/doxygen/main_page.h @@ -31,6 +31,13 @@ * @verbinclude "contrib.txt" */ +/** + * @page bugs Reporting bugs + * Please report bugs in the lwIP bug tracker at savannah.\n + * BEFORE submitting, please check if the bug has already been reported!\n + * https://savannah.nongnu.org/bugs/?group=lwip + */ + /** * @defgroup lwip_nosys Mainloop mode ("NO_SYS") * @ingroup lwip From 43d6812b3eb5f4de8b8d8d7aba94daef54e62cd5 Mon Sep 17 00:00:00 2001 From: sg Date: Thu, 18 Aug 2016 22:02:57 +0200 Subject: [PATCH 118/325] IPv6 addr: clarify tentative count/LWIP_IPV6_DUP_DETECT_ATTEMPTS --- src/core/ipv6/nd6.c | 7 +++++-- src/include/lwip/ip6_addr.h | 2 ++ src/include/lwip/opt.h | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/core/ipv6/nd6.c b/src/core/ipv6/nd6.c index ffa135b9..d56d4e92 100644 --- a/src/core/ipv6/nd6.c +++ b/src/core/ipv6/nd6.c @@ -62,6 +62,9 @@ #include +#if LWIP_IPV6_DUP_DETECT_ATTEMPTS > IP6_ADDR_TENTATIVE_COUNT_MASK +#error LWIP_IPV6_DUP_DETECT_ATTEMPTS > IP6_ADDR_TENTATIVE_COUNT_MASK +#endif /* Router tables. */ struct nd6_neighbor_cache_entry neighbor_cache[LWIP_ND6_NUM_NEIGHBORS]; @@ -805,13 +808,13 @@ nd6_tmr(void) for (netif = netif_list; netif != NULL; netif = netif->next) { for (i = 0; i < LWIP_IPV6_NUM_ADDRESSES; ++i) { if (ip6_addr_istentative(netif->ip6_addr_state[i])) { - if ((netif->ip6_addr_state[i] & 0x07) >= LWIP_IPV6_DUP_DETECT_ATTEMPTS) { + if ((netif->ip6_addr_state[i] & IP6_ADDR_TENTATIVE_COUNT_MASK) >= LWIP_IPV6_DUP_DETECT_ATTEMPTS) { /* No NA received in response. Mark address as valid. */ netif->ip6_addr_state[i] = IP6_ADDR_PREFERRED; /* @todo implement preferred and valid lifetimes. */ } else if (netif->flags & NETIF_FLAG_UP) { #if LWIP_IPV6_MLD - if ((netif->ip6_addr_state[i] & 0x07) == 0) { + if ((netif->ip6_addr_state[i] & IP6_ADDR_TENTATIVE_COUNT_MASK) == 0) { /* Join solicited node multicast group. */ ip6_addr_set_solicitednode(&multicast_address, netif_ip6_addr(netif, i)->addr[3]); mld6_joingroup(netif_ip6_addr(netif, i), &multicast_address); diff --git a/src/include/lwip/ip6_addr.h b/src/include/lwip/ip6_addr.h index 665e75f2..622fee0a 100644 --- a/src/include/lwip/ip6_addr.h +++ b/src/include/lwip/ip6_addr.h @@ -263,6 +263,8 @@ Little-endian version, stored in network order (no htonl). */ #define IP6_ADDR_PREFERRED 0x30 #define IP6_ADDR_DEPRECATED 0x50 +#define IP6_ADDR_TENTATIVE_COUNT_MASK 0x07 /* 1-7 probes sent */ + #define ip6_addr_isinvalid(addr_state) (addr_state == IP6_ADDR_INVALID) #define ip6_addr_istentative(addr_state) (addr_state & IP6_ADDR_TENTATIVE) #define ip6_addr_isvalid(addr_state) (addr_state & IP6_ADDR_VALID) /* Include valid, preferred, and deprecated. */ diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h index 24a9fc68..0c499841 100644 --- a/src/include/lwip/opt.h +++ b/src/include/lwip/opt.h @@ -2214,7 +2214,7 @@ #endif /** - * LWIP_IPV6_DUP_DETECT_ATTEMPTS: Number of duplicate address detection attempts. + * LWIP_IPV6_DUP_DETECT_ATTEMPTS=[0..7]: Number of duplicate address detection attempts. */ #if !defined LWIP_IPV6_DUP_DETECT_ATTEMPTS || defined __DOXYGEN__ #define LWIP_IPV6_DUP_DETECT_ATTEMPTS 1 From 8eb9db18a2d95235cce4a8b5ed41370277b35622 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Fri, 19 Aug 2016 08:36:00 +0200 Subject: [PATCH 119/325] Reduce usage of netif/ethernet.h header, mostly lwip/prot/ethernet.h is sufficient --- src/api/tcpip.c | 1 + src/core/ipv4/etharp.c | 1 + src/core/ipv6/ethip6.c | 2 +- src/core/netif.c | 2 ++ src/include/lwip/etharp.h | 2 +- src/include/lwip/prot/ethernet.h | 16 +++++++++++++++- src/include/netif/ethernet.h | 14 -------------- 7 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/api/tcpip.c b/src/api/tcpip.c index 5ab26584..46fa6029 100644 --- a/src/api/tcpip.c +++ b/src/api/tcpip.c @@ -48,6 +48,7 @@ #include "lwip/ip.h" #include "lwip/pbuf.h" #include "lwip/etharp.h" +#include "netif/ethernet.h" #define TCPIP_MSG_VAR_REF(name) API_VAR_REF(name) #define TCPIP_MSG_VAR_DECLARE(name) API_VAR_DECLARE(struct tcpip_msg, name) diff --git a/src/core/ipv4/etharp.c b/src/core/ipv4/etharp.c index 5481d3bd..2b3e9ca7 100644 --- a/src/core/ipv4/etharp.c +++ b/src/core/ipv4/etharp.c @@ -52,6 +52,7 @@ #include "lwip/snmp.h" #include "lwip/dhcp.h" #include "lwip/autoip.h" +#include "netif/ethernet.h" #include diff --git a/src/core/ipv6/ethip6.c b/src/core/ipv6/ethip6.c index 81a19955..b3a3cafb 100644 --- a/src/core/ipv6/ethip6.c +++ b/src/core/ipv6/ethip6.c @@ -51,7 +51,7 @@ #include "lwip/inet_chksum.h" #include "lwip/netif.h" #include "lwip/icmp6.h" -#include "netif/ethernet.h" +#include "lwip/prot/ethernet.h" #include diff --git a/src/core/netif.c b/src/core/netif.c index dfc25324..5c194588 100644 --- a/src/core/netif.c +++ b/src/core/netif.c @@ -58,6 +58,8 @@ #endif /* LWIP_NETIF_LOOPBACK_MULTITHREADING */ #endif /* ENABLE_LOOPBACK */ +#include "netif/ethernet.h" + #if LWIP_AUTOIP #include "lwip/autoip.h" #endif /* LWIP_AUTOIP */ diff --git a/src/include/lwip/etharp.h b/src/include/lwip/etharp.h index 6c0b2d78..d02f1d41 100644 --- a/src/include/lwip/etharp.h +++ b/src/include/lwip/etharp.h @@ -50,7 +50,7 @@ #include "lwip/ip4_addr.h" #include "lwip/netif.h" #include "lwip/ip4.h" -#include "netif/ethernet.h" +#include "lwip/prot/ethernet.h" #ifdef __cplusplus extern "C" { diff --git a/src/include/lwip/prot/ethernet.h b/src/include/lwip/prot/ethernet.h index 6ebc1008..4d11328d 100644 --- a/src/include/lwip/prot/ethernet.h +++ b/src/include/lwip/prot/ethernet.h @@ -126,7 +126,21 @@ PACK_STRUCT_END /** IPv6 multicast uses this prefix */ #define LL_IP6_MULTICAST_ADDR_0 0x33 #define LL_IP6_MULTICAST_ADDR_1 0x33 - + +/** MEMCPY-like macro to copy to/from struct eth_addr's that are local variables + * or known to be 32-bit aligned within the protocol header. */ +#ifndef ETHADDR32_COPY +#define ETHADDR32_COPY(dst, src) SMEMCPY(dst, src, ETH_HWADDR_LEN) +#endif + +/** MEMCPY-like macro to copy to/from struct eth_addr's that are no local + * variables and known to be 16-bit aligned within the protocol header. */ +#ifndef ETHADDR16_COPY +#define ETHADDR16_COPY(dst, src) SMEMCPY(dst, src, ETH_HWADDR_LEN) +#endif + +#define eth_addr_cmp(addr1, addr2) (memcmp((addr1)->addr, (addr2)->addr, ETH_HWADDR_LEN) == 0) + #ifdef __cplusplus } #endif diff --git a/src/include/netif/ethernet.h b/src/include/netif/ethernet.h index 7d41af10..ec961c4d 100644 --- a/src/include/netif/ethernet.h +++ b/src/include/netif/ethernet.h @@ -51,18 +51,6 @@ extern "C" { #endif -/** MEMCPY-like macro to copy to/from struct eth_addr's that are local variables - * or known to be 32-bit aligned within the protocol header. */ -#ifndef ETHADDR32_COPY -#define ETHADDR32_COPY(dst, src) SMEMCPY(dst, src, ETH_HWADDR_LEN) -#endif - -/** MEMCPY-like macro to copy to/from struct eth_addr's that are no local - * variables and known to be 16-bit aligned within the protocol header. */ -#ifndef ETHADDR16_COPY -#define ETHADDR16_COPY(dst, src) SMEMCPY(dst, src, ETH_HWADDR_LEN) -#endif - #if LWIP_ARP || LWIP_ETHERNET /** Define this to 1 and define LWIP_ARP_FILTER_NETIF_FN(pbuf, netif, type) @@ -77,8 +65,6 @@ extern "C" { err_t ethernet_input(struct pbuf *p, struct netif *netif); -#define eth_addr_cmp(addr1, addr2) (memcmp((addr1)->addr, (addr2)->addr, ETH_HWADDR_LEN) == 0) - extern const struct eth_addr ethbroadcast, ethzero; #endif /* LWIP_ARP || LWIP_ETHERNET */ From 11386a26d9d727d2df0e6e9011513201250cf07f Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Fri, 19 Aug 2016 09:00:35 +0200 Subject: [PATCH 120/325] Fix compile of DHCP unit test --- test/unit/dhcp/test_dhcp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/unit/dhcp/test_dhcp.c b/test/unit/dhcp/test_dhcp.c index 61471e2e..68f28819 100644 --- a/test/unit/dhcp/test_dhcp.c +++ b/test/unit/dhcp/test_dhcp.c @@ -3,7 +3,8 @@ #include "lwip/netif.h" #include "lwip/dhcp.h" #include "lwip/prot/dhcp.h" -#include "netif/etharp.h" +#include "lwip/etharp.h" +#include "netif/ethernet.h" struct netif net_test; From e844159f0af44ff114e316b648e44f6950a92e71 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Fri, 19 Aug 2016 09:03:57 +0200 Subject: [PATCH 121/325] Fix warning in test_etharp.c --- test/unit/etharp/test_etharp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/unit/etharp/test_etharp.c b/test/unit/etharp/test_etharp.c index ba9a40dc..59d73b9b 100644 --- a/test/unit/etharp/test_etharp.c +++ b/test/unit/etharp/test_etharp.c @@ -1,7 +1,8 @@ #include "test_etharp.h" #include "lwip/udp.h" -#include "netif/etharp.h" +#include "lwip/etharp.h" +#include "netif/ethernet.h" #include "lwip/stats.h" #if !LWIP_STATS || !UDP_STATS || !MEMP_STATS || !ETHARP_STATS From 967516aa40e84a5a98f521ca319d7af372ef1580 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Fri, 19 Aug 2016 09:15:35 +0200 Subject: [PATCH 122/325] Add #include to netif/ethernet.h to netif/etharp.h to maintian compatibility --- src/include/netif/etharp.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/include/netif/etharp.h b/src/include/netif/etharp.h index df63a70a..b536fd28 100644 --- a/src/include/netif/etharp.h +++ b/src/include/netif/etharp.h @@ -1,2 +1,3 @@ /* ARP has been moved to core/ipv4, provide this #include for compatibility only */ #include "lwip/etharp.h" +#include "netif/ethernet.h" From 9725a496b5708bbab7486192110c566ecfe06e6e Mon Sep 17 00:00:00 2001 From: goldsimon Date: Fri, 19 Aug 2016 09:40:27 +0200 Subject: [PATCH 123/325] moved 2 enums from 'prot' headers to where they belong (dns, dhcp) --- src/core/dns.c | 8 ++++++++ src/include/lwip/dhcp.h | 6 ++++++ src/include/lwip/prot/dhcp.h | 8 +------- src/include/lwip/prot/dns.h | 15 +++------------ src/include/lwip/prot/icmp.h | 3 +-- 5 files changed, 19 insertions(+), 21 deletions(-) diff --git a/src/core/dns.c b/src/core/dns.c index 6ad0b4b7..cc8dc852 100644 --- a/src/core/dns.c +++ b/src/core/dns.c @@ -183,6 +183,14 @@ struct dns_answer { /* maximum allowed size for the struct due to non-packed */ #define SIZEOF_DNS_ANSWER_ASSERT 12 +/* DNS table entry states */ +typedef enum { + DNS_STATE_UNUSED = 0, + DNS_STATE_NEW = 1, + DNS_STATE_ASKING = 2, + DNS_STATE_DONE = 3 +} dns_state_enum_t; + /** DNS table entry */ struct dns_table_entry { u32_t ttl; diff --git a/src/include/lwip/dhcp.h b/src/include/lwip/dhcp.h index f9bdb1ee..220342b3 100644 --- a/src/include/lwip/dhcp.h +++ b/src/include/lwip/dhcp.h @@ -58,6 +58,12 @@ extern "C" { #define DHCP_BOOT_FILE_LEN 128U +/* AutoIP cooperation flags (struct dhcp.autoip_coop_state) */ +typedef enum { + DHCP_AUTOIP_COOP_STATE_OFF = 0, + DHCP_AUTOIP_COOP_STATE_ON = 1 +} dhcp_autoip_coop_state_enum_t; + struct dhcp { /** transaction identifier of last sent request */ diff --git a/src/include/lwip/prot/dhcp.h b/src/include/lwip/prot/dhcp.h index c33aa04c..112953cb 100644 --- a/src/include/lwip/prot/dhcp.h +++ b/src/include/lwip/prot/dhcp.h @@ -114,12 +114,6 @@ typedef enum { DHCP_STATE_BACKING_OFF = 12 } dhcp_state_enum_t; -/* AutoIP cooperation flags */ -typedef enum { - DHCP_AUTOIP_COOP_STATE_OFF = 0, - DHCP_AUTOIP_COOP_STATE_ON = 1 -} dhcp_autoip_coop_state_enum_t; - /* DHCP op codes */ #define DHCP_BOOTREQUEST 1 #define DHCP_BOOTREPLY 2 @@ -172,7 +166,7 @@ typedef enum { #define DHCP_OPTION_T2 59 /* T2 rebinding time */ #define DHCP_OPTION_US 60 #define DHCP_OPTION_CLIENT_ID 61 -#define DHCP_OPTION_TFTP_SERVERNAME 66 +#define DHCP_OPTION_TFTP_SERVERNAME 66 #define DHCP_OPTION_BOOTFILE 67 /* possible combinations of overloading the file and sname fields with options */ diff --git a/src/include/lwip/prot/dns.h b/src/include/lwip/prot/dns.h index 9998fb60..0a99ab0c 100644 --- a/src/include/lwip/prot/dns.h +++ b/src/include/lwip/prot/dns.h @@ -42,7 +42,7 @@ #include "lwip/arch.h" -#ifdef __cplusplus +#ifdef __cplusplus extern "C" { #endif @@ -114,18 +114,9 @@ PACK_STRUCT_END # include "arch/epstruct.h" #endif #define SIZEOF_DNS_HDR 12 - -/* DNS protocol states */ -typedef enum { - DNS_STATE_UNUSED = 0, - DNS_STATE_NEW = 1, - DNS_STATE_ASKING = 2, - DNS_STATE_DONE = 3 -} dns_state_enum_t; -#ifdef __cplusplus +#ifdef __cplusplus } #endif -#endif /* LWIP_HDR_PROT_DNS_H */ - +#endif /* LWIP_HDR_PROT_DNS_H */ diff --git a/src/include/lwip/prot/icmp.h b/src/include/lwip/prot/icmp.h index b0005a6b..7d19385c 100644 --- a/src/include/lwip/prot/icmp.h +++ b/src/include/lwip/prot/icmp.h @@ -78,10 +78,9 @@ PACK_STRUCT_END # include "arch/epstruct.h" #endif +/* Compatibility defines, old versions used to combine type and code to an u16_t */ #define ICMPH_TYPE(hdr) ((hdr)->type) #define ICMPH_CODE(hdr) ((hdr)->code) - -/** 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)) From 14fb48cd7aec3beb5e297d3c6b950a365dd86420 Mon Sep 17 00:00:00 2001 From: goldsimon Date: Fri, 19 Aug 2016 09:40:55 +0200 Subject: [PATCH 124/325] minor: whitespace cleanups --- src/api/sockets.c | 2 +- src/api/tcpip.c | 2 +- src/apps/httpd/httpd.c | 8 ++--- src/apps/httpd/makefsdata/makefsdata.c | 4 +-- src/apps/mdns/mdns.c | 2 +- src/apps/snmp/snmp_asn1.c | 16 +++++----- src/apps/snmp/snmp_core.c | 40 +++++++++++------------ src/apps/snmp/snmp_mib2_interfaces.c | 19 ++++++----- src/apps/snmp/snmp_mib2_ip.c | 10 +++--- src/apps/snmp/snmp_mib2_snmp.c | 2 +- src/apps/snmp/snmp_mib2_system.c | 10 +++--- src/apps/snmp/snmp_mib2_tcp.c | 44 +++++++++++++------------- src/apps/snmp/snmp_mib2_udp.c | 8 ++--- src/core/ipv4/autoip.c | 4 +-- src/core/ipv4/dhcp.c | 16 +++++----- src/core/ipv6/ip6.c | 2 +- src/core/raw.c | 4 +-- src/core/tcp_in.c | 2 +- src/core/udp.c | 2 +- src/include/lwip/api.h | 2 +- src/include/lwip/apps/mdns_opts.h | 4 +-- src/include/lwip/apps/snmp_core.h | 4 +-- src/include/lwip/apps/snmp_table.h | 2 +- src/include/lwip/arch.h | 4 +-- src/include/lwip/err.h | 2 +- src/include/lwip/etharp.h | 2 +- src/include/lwip/icmp6.h | 4 +-- src/include/lwip/ip.h | 4 +-- src/include/lwip/netif.h | 2 +- src/include/lwip/opt.h | 6 ++-- src/include/lwip/priv/tcpip_priv.h | 2 +- src/include/lwip/prot/arp.h | 2 +- src/include/lwip/prot/ethernet.h | 2 +- src/include/lwip/prot/ip.h | 2 -- src/include/lwip/prot/ip4.h | 4 +-- src/include/lwip/prot/ip6.h | 2 +- src/include/lwip/prot/mld6.h | 2 +- src/include/lwip/prot/tcp.h | 2 +- src/include/lwip/prot/udp.h | 2 +- src/include/lwip/stats.h | 12 +++---- src/include/lwip/sys.h | 4 +-- src/include/lwip/tcpip.h | 2 +- src/netif/ethernetif.c | 2 +- src/netif/slipif.c | 4 +-- 44 files changed, 136 insertions(+), 141 deletions(-) diff --git a/src/api/sockets.c b/src/api/sockets.c index 440c446e..68ff0a51 100644 --- a/src/api/sockets.c +++ b/src/api/sockets.c @@ -1086,7 +1086,7 @@ lwip_sendmsg(int s, const struct msghdr *msg, int flags) } else { pbuf_cat(chain_buf->p, p); } - } + } /* save size of total chain */ if (err == ERR_OK) { size = netbuf_len(chain_buf); diff --git a/src/api/tcpip.c b/src/api/tcpip.c index 46fa6029..e9d3ad77 100644 --- a/src/api/tcpip.c +++ b/src/api/tcpip.c @@ -375,7 +375,7 @@ tcpip_api_call(tcpip_api_call_fn fn, struct tcpip_api_call_data *call) #endif /* LWIP_NETCONN_SEM_PER_THREAD */ LWIP_ASSERT("Invalid mbox", sys_mbox_valid_val(mbox)); - + TCPIP_MSG_VAR_ALLOC(msg); TCPIP_MSG_VAR_REF(msg).type = TCPIP_MSG_API_CALL; TCPIP_MSG_VAR_REF(msg).msg.api_call.arg = call; diff --git a/src/apps/httpd/httpd.c b/src/apps/httpd/httpd.c index 6be2573e..f8e2e282 100644 --- a/src/apps/httpd/httpd.c +++ b/src/apps/httpd/httpd.c @@ -353,7 +353,7 @@ strnstr(const char* buffer, const char* token, size_t n) } } return NULL; -} +} #endif /* LWIP_HTTPD_STRNSTR_PRIVATE */ #if LWIP_HTTPD_STRICMP_PRIVATE @@ -1112,7 +1112,7 @@ http_send_headers(struct tcp_pcb *pcb, struct http_state *hs) * (which would happen when sending files from async read). */ if(http_check_eof(pcb, hs)) { data_to_send = HTTP_DATA_TO_SEND_CONTINUE; - } + } } /* If we get here and there are still header bytes to send, we send * the header information we just wrote immediately. If there are no @@ -2584,7 +2584,7 @@ http_accept(void *arg, struct tcp_pcb *pcb, err_t err) LWIP_UNUSED_ARG(err); LWIP_UNUSED_ARG(arg); LWIP_DEBUGF(HTTPD_DEBUG, ("http_accept %p / %p\n", (void*)pcb, arg)); - + if ((err != ERR_OK) || (pcb == NULL)) { return ERR_VAL; } @@ -2684,7 +2684,7 @@ http_set_cgi_handlers(const tCGI *cgis, int num_handlers) { LWIP_ASSERT("no cgis given", cgis != NULL); LWIP_ASSERT("invalid number of handlers", num_handlers > 0); - + g_pCGIs = cgis; g_iNumCGIs = num_handlers; } diff --git a/src/apps/httpd/makefsdata/makefsdata.c b/src/apps/httpd/makefsdata/makefsdata.c index 34101a48..934e7219 100644 --- a/src/apps/httpd/makefsdata/makefsdata.c +++ b/src/apps/httpd/makefsdata/makefsdata.c @@ -2,7 +2,7 @@ * makefsdata: Converts a directory structure for use with the lwIP httpd. * * This file is part of the lwIP TCP/IP stack. - * + * * Author: Jim Pettinato * Simon Goldschmidt * @@ -818,7 +818,7 @@ int file_write_http_header(FILE *data_file, const char *filename, int file_size, u8_t provide_last_modified = includeLastModified; memset(hdr_buf, 0, sizeof(hdr_buf)); - + if (useHttp11) { response_type = HTTP_HDR_OK_11; } diff --git a/src/apps/mdns/mdns.c b/src/apps/mdns/mdns.c index 6ec1cb00..e89c88e6 100644 --- a/src/apps/mdns/mdns.c +++ b/src/apps/mdns/mdns.c @@ -1778,7 +1778,7 @@ mdns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, struct mdns_packet packet; struct netif *recv_netif = ip_current_input_netif(); u16_t offset = 0; - + LWIP_UNUSED_ARG(arg); LWIP_UNUSED_ARG(pcb); diff --git a/src/apps/snmp/snmp_asn1.c b/src/apps/snmp/snmp_asn1.c index e2cb02c4..7b41445e 100644 --- a/src/apps/snmp/snmp_asn1.c +++ b/src/apps/snmp/snmp_asn1.c @@ -196,10 +196,10 @@ snmp_asn1_enc_u64t(struct snmp_pbuf_stream* pbuf_stream, u16_t octets_needed, co octets_needed--; PBUF_OP_EXEC(snmp_pbuf_stream_write(pbuf_stream, (u8_t)(*value >> ((octets_needed-4) << 3)))); } - + /* skip to low u32 */ value++; - + while (octets_needed > 1) { octets_needed--; PBUF_OP_EXEC(snmp_pbuf_stream_write(pbuf_stream, (u8_t)(*value >> (octets_needed << 3)))); @@ -367,7 +367,7 @@ snmp_asn1_enc_s32t_cnt(s32_t value, u16_t *octets_needed) { if (value < 0) { value = ~value; - } + } if (value < 0x80L) { *octets_needed = 1; } else if (value < 0x8000L) { @@ -453,7 +453,7 @@ snmp_asn1_dec_tlv(struct snmp_pbuf_stream* pbuf_stream, struct snmp_asn1_tlv* tl PBUF_OP_EXEC(snmp_pbuf_stream_read(pbuf_stream, &data)); tlv->value_len <<= 8; tlv->value_len |= data; - + /* take care for special value used for indefinite length */ if (tlv->value_len == 0xFFFF) { return ERR_VAL; @@ -551,7 +551,7 @@ snmp_asn1_dec_u64t(struct snmp_pbuf_stream *pbuf_stream, u16_t len, u32_t *value } else { *value <<= 8; } - + *value |= data; len--; } @@ -588,7 +588,7 @@ snmp_asn1_dec_s32t(struct snmp_pbuf_stream *pbuf_stream, u16_t len, s32_t *value if ((len > 0) && (len < 5)) { PBUF_OP_EXEC(snmp_pbuf_stream_read(pbuf_stream, &data)); len--; - + if (data & 0x80) { /* negative, start from -1 */ *value = -1; @@ -649,7 +649,7 @@ snmp_asn1_dec_oid(struct snmp_pbuf_stream *pbuf_stream, u16_t len, u32_t* oid, u if (oid_max_len < 2) { return ERR_MEM; } - + PBUF_OP_EXEC(snmp_pbuf_stream_read(pbuf_stream, &data)); len--; @@ -736,7 +736,7 @@ snmp_asn1_dec_raw(struct snmp_pbuf_stream *pbuf_stream, u16_t len, u8_t *buf, u1 return ERR_MEM; } *buf_len = len; - + while (len > 0) { PBUF_OP_EXEC(snmp_pbuf_stream_read(pbuf_stream, buf)); buf++; diff --git a/src/apps/snmp/snmp_core.c b/src/apps/snmp/snmp_core.c index bdefd08e..1230d62b 100644 --- a/src/apps/snmp/snmp_core.c +++ b/src/apps/snmp/snmp_core.c @@ -322,10 +322,10 @@ snmp_oid_to_ip6(const u32_t *oid, ip6_addr_t *ip) return 0; } - ip->addr[0] = (oid[0] << 24) | (oid[1] << 16) | (oid[2] << 8) | (oid[3] << 0); - ip->addr[1] = (oid[4] << 24) | (oid[5] << 16) | (oid[6] << 8) | (oid[7] << 0); - ip->addr[2] = (oid[8] << 24) | (oid[9] << 16) | (oid[10] << 8) | (oid[11] << 0); - ip->addr[3] = (oid[12] << 24) | (oid[13] << 16) | (oid[14] << 8) | (oid[15] << 0); + ip->addr[0] = (oid[0] << 24) | (oid[1] << 16) | (oid[2] << 8) | (oid[3] << 0); + ip->addr[1] = (oid[4] << 24) | (oid[5] << 16) | (oid[6] << 8) | (oid[7] << 0); + ip->addr[2] = (oid[8] << 24) | (oid[9] << 16) | (oid[10] << 8) | (oid[11] << 0); + ip->addr[3] = (oid[12] << 24) | (oid[13] << 16) | (oid[14] << 8) | (oid[15] << 0); return 1; } @@ -372,7 +372,7 @@ snmp_ip_port_to_oid(const ip_addr_t *ip, u16_t port, u32_t *oid) idx = snmp_ip_to_oid(ip, oid); oid[idx] = port; idx++; - + return idx; } @@ -424,7 +424,7 @@ snmp_oid_to_ip(const u32_t *oid, u8_t oid_len, ip_addr_t *ip) if (oid_len < 1) { return 0; } - + if (oid[0] == 0) { /* any */ /* 1x InetAddressType, 1x OID len */ if (oid_len < 2) { @@ -454,7 +454,7 @@ snmp_oid_to_ip(const u32_t *oid, u8_t oid_len, ip_addr_t *ip) if (!snmp_oid_to_ip4(&oid[2], ip_2_ip4(ip))) { return 0; } - + return 6; #else /* LWIP_IPV4 */ return 0; @@ -497,7 +497,7 @@ u8_t snmp_oid_to_ip_port(const u32_t *oid, u8_t oid_len, ip_addr_t *ip, u16_t *port) { u8_t idx = 0; - + /* InetAddressType + InetAddress */ idx += snmp_oid_to_ip(&oid[idx], oid_len-idx, ip); if (idx == 0) { @@ -581,7 +581,7 @@ snmp_oid_combine(struct snmp_obj_id* target, const u32_t *oid1, u8_t oid1_len, c * @param oid * @param oid_len */ -void +void snmp_oid_append(struct snmp_obj_id* target, const u32_t *oid, u8_t oid_len) { LWIP_ASSERT("offset + oid_len <= LWIP_SNMP_OBJ_ID_LEN", (target->len + oid_len) <= SNMP_MAX_OBJ_ID_LEN); @@ -629,7 +629,7 @@ snmp_oid_compare(const u32_t *oid1, u8_t oid1_len, const u32_t *oid2, u8_t oid2_ } /* they are equal */ - return 0; + return 0; } @@ -772,7 +772,7 @@ snmp_get_node_instance_from_oid(const u32_t *oid, u8_t oid_len, struct snmp_node mib = snmp_get_mib_from_oid(oid, oid_len); if (mib != NULL) { u8_t oid_instance_len; - + mn = snmp_mib_tree_resolve_exact(mib, oid, oid_len, &oid_instance_len); if ((mn != NULL) && (mn->node_type != SNMP_NODE_TREE)) { /* get instance */ @@ -802,7 +802,7 @@ snmp_get_node_instance_from_oid(const u32_t *oid, u8_t oid_len, struct snmp_node return result; } -u8_t +u8_t snmp_get_next_node_instance_from_oid(const u32_t *oid, u8_t oid_len, snmp_validate_node_instance_method validate_node_instance_method, void* validate_node_instance_arg, struct snmp_obj_id* node_oid, struct snmp_node_instance* node_instance) { const struct snmp_mib *mib; @@ -828,7 +828,7 @@ snmp_get_next_node_instance_from_oid(const u32_t *oid, u8_t oid_len, snmp_valida /* resolve target node from MIB, skip to next MIB if no suitable node is found in current MIB */ while ((mib != NULL) && (mn == NULL)) { u8_t oid_instance_len; - + /* check if OID directly references a node inside current MIB, in this case we have to ask this node for the next instance */ mn = snmp_mib_tree_resolve_exact(mib, start_oid, start_oid_len, &oid_instance_len); if (mn != NULL) { @@ -881,9 +881,9 @@ snmp_get_next_node_instance_from_oid(const u32_t *oid, u8_t oid_len, snmp_valida if (node_instance->release_instance != NULL) { node_instance->release_instance(node_instance); } - /* + /* the instance itself is not valid, ask for next instance from same node. - we don't have to change any variables because node_instance->instance_oid is used as input (starting point) + we don't have to change any variables because node_instance->instance_oid is used as input (starting point) as well as output (resulting next OID), so we have to simply call get_next_instance method again */ } else { @@ -926,7 +926,7 @@ snmp_get_next_node_instance_from_oid(const u32_t *oid, u8_t oid_len, snmp_valida } /* else { we found out target node } */ } else { - /* + /* there is no further (suitable) node inside this MIB, search for the next MIB with following priority 1. search for inner MIB's (whose root is located inside tree of current MIB) 2. search for surrouding MIB's (where the current MIB is the inner MIB) and continue there if any @@ -1004,11 +1004,11 @@ snmp_mib_tree_resolve_exact(const struct snmp_mib *mib, const u32_t *oid, u8_t o *oid_instance_len = oid_len - oid_offset; return (*node); } - + return NULL; } -const struct snmp_node* +const struct snmp_node* snmp_mib_tree_resolve_next(const struct snmp_mib *mib, const u32_t *oid, u8_t oid_len, struct snmp_obj_id* oidret) { u8_t oid_offset = mib->base_oid_len; @@ -1099,7 +1099,7 @@ snmp_mib_tree_resolve_next(const struct snmp_mib *mib, const u32_t *oid, u8_t oi } } } - + return NULL; } @@ -1140,7 +1140,7 @@ snmp_next_oid_precheck(struct snmp_next_oid_state *state, const u32_t *oid, cons } /** checks the passed OID if it is a candidate to be the next one (get_next); returns !=0 if passed oid is currently closest, otherwise 0 */ -u8_t +u8_t snmp_next_oid_check(struct snmp_next_oid_state *state, const u32_t *oid, const u8_t oid_len, void* reference) { /* do not overwrite a fail result */ diff --git a/src/apps/snmp/snmp_mib2_interfaces.c b/src/apps/snmp/snmp_mib2_interfaces.c index c957a5a4..979b5073 100644 --- a/src/apps/snmp/snmp_mib2_interfaces.c +++ b/src/apps/snmp/snmp_mib2_interfaces.c @@ -58,7 +58,7 @@ /* --- interfaces .1.3.6.1.2.1.2 ----------------------------------------------------- */ -static s16_t +static s16_t interfaces_get_value(struct snmp_node_instance* instance, void* value) { if (instance->node->oid == 1) { @@ -131,7 +131,7 @@ interfaces_Table_get_next_cell_instance(const u32_t* column, struct snmp_obj_id* u32_t result_temp[LWIP_ARRAYSIZE(interfaces_Table_oid_ranges)]; LWIP_UNUSED_ARG(column); - + /* init struct to search next oid */ snmp_next_oid_init(&state, row_oid->id, row_oid->len, result_temp, LWIP_ARRAYSIZE(interfaces_Table_oid_ranges)); @@ -289,11 +289,10 @@ interfaces_Table_set_test(struct snmp_node_instance* instance, u16_t len, void * LWIP_ASSERT("Invalid column", (SNMP_TABLE_GET_COLUMN_FROM_OID(instance->instance_oid.id) == 7)); LWIP_UNUSED_ARG(len); - if (*sint_ptr == 1 || *sint_ptr == 2) - { + if (*sint_ptr == 1 || *sint_ptr == 2) { return SNMP_ERR_NOERROR; } - + return SNMP_ERR_WRONGVALUE; } @@ -352,17 +351,17 @@ static const struct snmp_table_col_def interfaces_Table_columns[] = { #if !SNMP_SAFE_REQUESTS static const struct snmp_table_node interfaces_Table = SNMP_TABLE_CREATE( - 2, interfaces_Table_columns, - interfaces_Table_get_cell_instance, interfaces_Table_get_next_cell_instance, + 2, interfaces_Table_columns, + interfaces_Table_get_cell_instance, interfaces_Table_get_next_cell_instance, interfaces_Table_get_value, interfaces_Table_set_test, interfaces_Table_set_value); #else static const struct snmp_table_node interfaces_Table = SNMP_TABLE_CREATE( - 2, interfaces_Table_columns, - interfaces_Table_get_cell_instance, interfaces_Table_get_next_cell_instance, + 2, interfaces_Table_columns, + interfaces_Table_get_cell_instance, interfaces_Table_get_next_cell_instance, interfaces_Table_get_value, NULL, NULL); #endif -/* the following nodes access variables in LWIP stack from SNMP worker thread and must therefore be synced to LWIP (TCPIP) thread */ +/* the following nodes access variables in LWIP stack from SNMP worker thread and must therefore be synced to LWIP (TCPIP) thread */ CREATE_LWIP_SYNC_NODE(1, interfaces_Number) CREATE_LWIP_SYNC_NODE(2, interfaces_Table) diff --git a/src/apps/snmp/snmp_mib2_ip.c b/src/apps/snmp/snmp_mib2_ip.c index da0e6f57..b14a5565 100644 --- a/src/apps/snmp/snmp_mib2_ip.c +++ b/src/apps/snmp/snmp_mib2_ip.c @@ -58,7 +58,7 @@ #if LWIP_IPV4 /* --- ip .1.3.6.1.2.1.4 ----------------------------------------------------- */ -static s16_t +static s16_t ip_get_value(struct snmp_node_instance* instance, void* value) { s32_t* sint_ptr = (s32_t*)value; @@ -304,7 +304,7 @@ ip_AddrTable_get_next_cell_instance_and_value(const u32_t* column, struct snmp_o /* fill in object properties */ return ip_AddrTable_get_cell_value_core((struct netif*)state.reference, column, value, value_len); } - + /* not found */ return SNMP_ERR_NOSUCHINSTANCE; } @@ -464,7 +464,7 @@ ip_RouteTable_get_next_cell_instance_and_value(const u32_t* column, struct snmp_ snmp_ip4_to_oid(&dst, &test_oid[0]); snmp_next_oid_check(&state, test_oid, LWIP_ARRAYSIZE(ip_RouteTable_oid_ranges), netif); } - + netif = netif->next; } @@ -660,7 +660,7 @@ static const struct snmp_table_simple_node ip_NetToMediaTable = SNMP_TABLE_CREAT #endif /* LWIP_ARP && LWIP_IPV4 */ #if LWIP_IPV4 -/* the following nodes access variables in LWIP stack from SNMP worker thread and must therefore be synced to LWIP (TCPIP) thread */ +/* the following nodes access variables in LWIP stack from SNMP worker thread and must therefore be synced to LWIP (TCPIP) thread */ CREATE_LWIP_SYNC_NODE( 1, ip_Forwarding) CREATE_LWIP_SYNC_NODE( 2, ip_DefaultTTL) CREATE_LWIP_SYNC_NODE( 3, ip_InReceives) @@ -730,7 +730,7 @@ static const struct snmp_table_simple_col_def at_Table_columns[] = { static const struct snmp_table_simple_node at_Table = SNMP_TABLE_CREATE_SIMPLE(1, at_Table_columns, ip_NetToMediaTable_get_cell_value, ip_NetToMediaTable_get_next_cell_instance_and_value); -/* the following nodes access variables in LWIP stack from SNMP worker thread and must therefore be synced to LWIP (TCPIP) thread */ +/* the following nodes access variables in LWIP stack from SNMP worker thread and must therefore be synced to LWIP (TCPIP) thread */ CREATE_LWIP_SYNC_NODE(1, at_Table) static const struct snmp_node* const at_nodes[] = { diff --git a/src/apps/snmp/snmp_mib2_snmp.c b/src/apps/snmp/snmp_mib2_snmp.c index a991fad7..8a36d61f 100644 --- a/src/apps/snmp/snmp_mib2_snmp.c +++ b/src/apps/snmp/snmp_mib2_snmp.c @@ -188,7 +188,7 @@ snmp_set_value(const struct snmp_scalar_array_node_def *node, u16_t len, void *v return SNMP_ERR_NOERROR; } -/* the following nodes access variables in SNMP stack (snmp_stats) from SNMP worker thread -> OK, no sync needed */ +/* the following nodes access variables in SNMP stack (snmp_stats) from SNMP worker thread -> OK, no sync needed */ static const struct snmp_scalar_array_node_def snmp_nodes[] = { { 1, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY}, /* snmpInPkts */ { 2, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY}, /* snmpOutPkts */ diff --git a/src/apps/snmp/snmp_mib2_system.c b/src/apps/snmp/snmp_mib2_system.c index 2cf88486..90e57805 100644 --- a/src/apps/snmp/snmp_mib2_system.c +++ b/src/apps/snmp/snmp_mib2_system.c @@ -106,7 +106,7 @@ snmp_mib2_set_sysdescr(const u8_t *str, const u16_t *len) * Initializes sysContact pointers * * @param ocstr if non-NULL then copy str pointer - * @param ocstrlen points to string length, excluding zero terminator. + * @param ocstrlen points to string length, excluding zero terminator. * if set to NULL it is assumed that ocstr is NULL-terminated. * @param bufsize size of the buffer in bytes. * (this is required because the buffer can be overwritten by snmp-set) @@ -148,7 +148,7 @@ snmp_mib2_set_syscontact_readonly(const u8_t *ocstr, const u16_t *ocstrlen) * Initializes sysName pointers * * @param ocstr if non-NULL then copy str pointer - * @param ocstrlen points to string length, excluding zero terminator. + * @param ocstrlen points to string length, excluding zero terminator. * if set to NULL it is assumed that ocstr is NULL-terminated. * @param bufsize size of the buffer in bytes. * (this is required because the buffer can be overwritten by snmp-set) @@ -189,7 +189,7 @@ snmp_mib2_set_sysname_readonly(const u8_t *ocstr, const u16_t *ocstrlen) * Initializes sysLocation pointers * * @param ocstr if non-NULL then copy str pointer - * @param ocstrlen points to string length, excluding zero terminator. + * @param ocstrlen points to string length, excluding zero terminator. * if set to NULL it is assumed that ocstr is NULL-terminated. * @param bufsize size of the buffer in bytes. * (this is required because the buffer can be overwritten by snmp-set) @@ -278,7 +278,7 @@ system_get_value(const struct snmp_scalar_array_node_def *node, void *value) return result; } -static snmp_err_t +static snmp_err_t system_set_test(const struct snmp_scalar_array_node_def *node, u16_t len, void *value) { snmp_err_t ret = SNMP_ERR_WRONGVALUE; @@ -324,7 +324,7 @@ system_set_test(const struct snmp_scalar_array_node_def *node, u16_t len, void * return ret; } -static snmp_err_t +static snmp_err_t system_set_value(const struct snmp_scalar_array_node_def *node, u16_t len, void *value) { u8_t* var_wr = NULL; diff --git a/src/apps/snmp/snmp_mib2_tcp.c b/src/apps/snmp/snmp_mib2_tcp.c index db3f74ca..f72e6a51 100644 --- a/src/apps/snmp/snmp_mib2_tcp.c +++ b/src/apps/snmp/snmp_mib2_tcp.c @@ -58,7 +58,7 @@ /* --- tcp .1.3.6.1.2.1.6 ----------------------------------------------------- */ -static s16_t +static s16_t tcp_get_value(struct snmp_node_instance* instance, void* value) { u32_t *uint_ptr = (u32_t*)value; @@ -154,7 +154,7 @@ static const struct snmp_oid_range tcp_ConnTable_oid_ranges[] = { { 0, 0xffff } /* Port */ }; -static snmp_err_t +static snmp_err_t tcp_ConnTable_get_cell_value_core(struct tcp_pcb *pcb, const u32_t* column, union snmp_variant_value* value, u32_t* value_len) { LWIP_UNUSED_ARG(value_len); @@ -212,7 +212,7 @@ tcp_ConnTable_get_cell_value(const u32_t* column, const u32_t* row_oid, u8_t row local_port = (u16_t)row_oid[4]; snmp_oid_to_ip4(&row_oid[5], &remote_ip); /* we know it succeeds because of oid_in_range check above */ remote_port = (u16_t)row_oid[9]; - + /* find tcp_pcb with requested ips and ports */ for (i = 0; i < LWIP_ARRAYSIZE(tcp_pcb_lists); i++) { pcb = *tcp_pcb_lists[i]; @@ -261,7 +261,7 @@ tcp_ConnTable_get_next_cell_instance_and_value(const u32_t* column, struct snmp_ pcb = *tcp_pcb_lists[i]; while (pcb != NULL) { u32_t test_oid[LWIP_ARRAYSIZE(tcp_ConnTable_oid_ranges)]; - + if (IP_IS_V4_VAL(pcb->local_ip)) { snmp_ip4_to_oid(ip_2_ip4(&pcb->local_ip), &test_oid[0]); test_oid[4] = pcb->local_port; @@ -281,7 +281,7 @@ tcp_ConnTable_get_next_cell_instance_and_value(const u32_t* column, struct snmp_ /* check generated OID: is it a candidate for the next one? */ snmp_next_oid_check(&state, test_oid, LWIP_ARRAYSIZE(tcp_ConnTable_oid_ranges), pcb); } - + pcb = pcb->next; } } @@ -301,10 +301,10 @@ tcp_ConnTable_get_next_cell_instance_and_value(const u32_t* column, struct snmp_ /* --- tcpConnectionTable --- */ -static snmp_err_t +static snmp_err_t tcp_ConnectionTable_get_cell_value_core(const u32_t* column, struct tcp_pcb *pcb, union snmp_variant_value* value) { - /* all items except tcpConnectionState and tcpConnectionProcess are declared as not-accessible */ + /* all items except tcpConnectionState and tcpConnectionProcess are declared as not-accessible */ switch (*column) { case 7: /* tcpConnectionState */ value->u32 = pcb->state + 1; @@ -336,7 +336,7 @@ tcp_ConnectionTable_get_cell_value(const u32_t* column, const u32_t* row_oid, u8 if (idx == 0) { return SNMP_ERR_NOSUCHINSTANCE; } - + /* tcpConnectionRemAddressType + tcpConnectionRemAddress + tcpConnectionRemPort */ idx += snmp_oid_to_ip_port(&row_oid[idx], row_oid_len-idx, &remote_ip, &remote_port); if (idx == 0) { @@ -346,7 +346,7 @@ tcp_ConnectionTable_get_cell_value(const u32_t* column, const u32_t* row_oid, u8 /* find tcp_pcb with requested ip and port*/ for (i = 0; i < LWIP_ARRAYSIZE(tcp_pcb_nonlisten_lists); i++) { pcb = *tcp_pcb_nonlisten_lists[i]; - + while (pcb != NULL) { if (ip_addr_cmp(&local_ip, &pcb->local_ip) && (local_port == pcb->local_port) && @@ -358,9 +358,9 @@ tcp_ConnectionTable_get_cell_value(const u32_t* column, const u32_t* row_oid, u8 pcb = pcb->next; } } - + /* not found */ - return SNMP_ERR_NOSUCHINSTANCE; + return SNMP_ERR_NOSUCHINSTANCE; } static snmp_err_t @@ -395,11 +395,11 @@ tcp_ConnectionTable_get_next_cell_instance_and_value(const u32_t* column, struct /* check generated OID: is it a candidate for the next one? */ snmp_next_oid_check(&state, test_oid, idx, pcb); - + pcb = pcb->next; } } - + /* did we find a next one? */ if (state.status == SNMP_NEXT_OID_STATUS_SUCCESS) { snmp_oid_assign(row_oid, state.next_oid, state.next_oid_len); @@ -413,10 +413,10 @@ tcp_ConnectionTable_get_next_cell_instance_and_value(const u32_t* column, struct /* --- tcpListenerTable --- */ -static snmp_err_t +static snmp_err_t tcp_ListenerTable_get_cell_value_core(const u32_t* column, union snmp_variant_value* value) { - /* all items except tcpListenerProcess are declared as not-accessible */ + /* all items except tcpListenerProcess are declared as not-accessible */ switch (*column) { case 4: /* tcpListenerProcess */ value->u32 = 0; /* not supported */ @@ -443,7 +443,7 @@ tcp_ListenerTable_get_cell_value(const u32_t* column, const u32_t* row_oid, u8_t if (idx == 0) { return SNMP_ERR_NOSUCHINSTANCE; } - + /* find tcp_pcb with requested ip and port*/ pcb = tcp_listen_pcbs.listen_pcbs; while (pcb != NULL) { @@ -456,7 +456,7 @@ tcp_ListenerTable_get_cell_value(const u32_t* column, const u32_t* row_oid, u8_t } /* not found */ - return SNMP_ERR_NOSUCHINSTANCE; + return SNMP_ERR_NOSUCHINSTANCE; } static snmp_err_t @@ -477,13 +477,13 @@ tcp_ListenerTable_get_next_cell_instance_and_value(const u32_t* column, struct s while (pcb != NULL) { u8_t idx = 0; u32_t test_oid[LWIP_ARRAYSIZE(result_temp)]; - + /* tcpListenerLocalAddressType + tcpListenerLocalAddress + tcpListenerLocalPort */ idx += snmp_ip_port_to_oid(&pcb->local_ip, pcb->local_port, &test_oid[idx]); /* check generated OID: is it a candidate for the next one? */ snmp_next_oid_check(&state, test_oid, idx, NULL); - + pcb = pcb->next; } @@ -528,7 +528,7 @@ static const struct snmp_table_simple_node tcp_ConnTable = SNMP_TABLE_CREATE_SIM #endif /* LWIP_IPV4 */ static const struct snmp_table_simple_col_def tcp_ConnectionTable_columns[] = { - /* all items except tcpConnectionState and tcpConnectionProcess are declared as not-accessible */ + /* all items except tcpConnectionState and tcpConnectionProcess are declared as not-accessible */ { 7, SNMP_ASN1_TYPE_INTEGER, SNMP_VARIANT_VALUE_TYPE_U32 }, /* tcpConnectionState */ { 8, SNMP_ASN1_TYPE_UNSIGNED32, SNMP_VARIANT_VALUE_TYPE_U32 } /* tcpConnectionProcess */ }; @@ -537,13 +537,13 @@ static const struct snmp_table_simple_node tcp_ConnectionTable = SNMP_TABLE_CREA static const struct snmp_table_simple_col_def tcp_ListenerTable_columns[] = { - /* all items except tcpListenerProcess are declared as not-accessible */ + /* all items except tcpListenerProcess are declared as not-accessible */ { 4, SNMP_ASN1_TYPE_UNSIGNED32, SNMP_VARIANT_VALUE_TYPE_U32 } /* tcpListenerProcess */ }; static const struct snmp_table_simple_node tcp_ListenerTable = SNMP_TABLE_CREATE_SIMPLE(20, tcp_ListenerTable_columns, tcp_ListenerTable_get_cell_value, tcp_ListenerTable_get_next_cell_instance_and_value); -/* the following nodes access variables in LWIP stack from SNMP worker thread and must therefore be synced to LWIP (TCPIP) thread */ +/* the following nodes access variables in LWIP stack from SNMP worker thread and must therefore be synced to LWIP (TCPIP) thread */ CREATE_LWIP_SYNC_NODE( 1, tcp_RtoAlgorithm) CREATE_LWIP_SYNC_NODE( 2, tcp_RtoMin) CREATE_LWIP_SYNC_NODE( 3, tcp_RtoMax) diff --git a/src/apps/snmp/snmp_mib2_udp.c b/src/apps/snmp/snmp_mib2_udp.c index de1c858f..6a983df2 100644 --- a/src/apps/snmp/snmp_mib2_udp.c +++ b/src/apps/snmp/snmp_mib2_udp.c @@ -57,7 +57,7 @@ /* --- udp .1.3.6.1.2.1.7 ----------------------------------------------------- */ -static s16_t +static s16_t udp_get_value(struct snmp_node_instance* instance, void* value) { u32_t *uint_ptr = (u32_t*)value; @@ -91,10 +91,10 @@ udp_get_value(struct snmp_node_instance* instance, void* value) /* --- udpEndpointTable --- */ -static snmp_err_t +static snmp_err_t udp_endpointTable_get_cell_value_core(const u32_t* column, union snmp_variant_value* value) { - /* all items except udpEndpointProcess are declared as not-accessible */ + /* all items except udpEndpointProcess are declared as not-accessible */ switch (*column) { case 8: /* udpEndpointProcess */ value->u32 = 0; /* not supported */ @@ -106,7 +106,7 @@ udp_endpointTable_get_cell_value_core(const u32_t* column, union snmp_variant_va return SNMP_ERR_NOERROR; } -static snmp_err_t +static snmp_err_t udp_endpointTable_get_cell_value(const u32_t* column, const u32_t* row_oid, u8_t row_oid_len, union snmp_variant_value* value, u32_t* value_len) { ip_addr_t local_ip, remote_ip; diff --git a/src/core/ipv4/autoip.c b/src/core/ipv4/autoip.c index c09d2404..daa3eb9f 100644 --- a/src/core/ipv4/autoip.c +++ b/src/core/ipv4/autoip.c @@ -110,7 +110,7 @@ autoip_set_struct(struct netif *netif, struct autoip *autoip) { LWIP_ASSERT("netif != NULL", netif != NULL); LWIP_ASSERT("autoip != NULL", autoip != NULL); - LWIP_ASSERT("netif already has a struct autoip set", + LWIP_ASSERT("netif already has a struct autoip set", netif_autoip_data(netif) == NULL); /* clear data structure */ @@ -522,7 +522,7 @@ autoip_supplied_address(const struct netif *netif) u8_t autoip_accept_packet(struct netif *netif, const ip4_addr_t *addr) { - struct autoip* autoip = netif_autoip_data(netif); + struct autoip* autoip = netif_autoip_data(netif); return (autoip != NULL) && ip4_addr_cmp(addr, &(autoip->llipaddr)); } diff --git a/src/core/ipv4/dhcp.c b/src/core/ipv4/dhcp.c index 47652757..041699d6 100644 --- a/src/core/ipv4/dhcp.c +++ b/src/core/ipv4/dhcp.c @@ -214,11 +214,11 @@ dhcp_inc_pcb_refcount(void) /* set up local and remote port for the pcb -> listen on all interfaces on all src/dest IPs */ udp_bind(dhcp_pcb, IP_ADDR_ANY, DHCP_CLIENT_PORT); udp_connect(dhcp_pcb, IP_ADDR_ANY, DHCP_SERVER_PORT); - udp_recv(dhcp_pcb, dhcp_recv, NULL); + udp_recv(dhcp_pcb, dhcp_recv, NULL); } dhcp_pcb_refcount++; - + return ERR_OK; } @@ -228,7 +228,7 @@ dhcp_dec_pcb_refcount(void) { LWIP_ASSERT("dhcp_pcb_refcount(): refcount error", (dhcp_pcb_refcount > 0)); dhcp_pcb_refcount--; - + if (dhcp_pcb_refcount == 0) { udp_remove(dhcp_pcb); dhcp_pcb = NULL; @@ -728,7 +728,7 @@ dhcp_start(struct netif *netif) LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_start(): could not allocate dhcp\n")); return ERR_MEM; } - + /* store this dhcp client in the netif */ netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP] = dhcp; LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_start(): allocated dhcp")); @@ -748,7 +748,7 @@ dhcp_start(struct netif *netif) memset(dhcp, 0, sizeof(struct dhcp)); /* dhcp_set_state(&dhcp, DHCP_STATE_OFF); */ - LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_start(): starting DHCP configuration\n")); + LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_start(): starting DHCP configuration\n")); if (dhcp_inc_pcb_refcount() != ERR_OK) { /* ensure DHCP PCB is allocated */ return ERR_MEM; @@ -810,7 +810,7 @@ dhcp_inform(struct netif *netif) pbuf_realloc(dhcp.p_out, sizeof(struct dhcp_msg) - DHCP_OPTIONS_LEN + dhcp.options_out_len); LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_inform: INFORMING\n")); - + udp_sendto_if(dhcp_pcb, dhcp.p_out, IP_ADDR_BROADCAST, DHCP_SERVER_PORT, netif); dhcp_delete_msg(&dhcp); @@ -1659,7 +1659,7 @@ dhcp_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, struct dhcp_msg *reply_msg = (struct dhcp_msg *)p->payload; u8_t msg_type; u8_t i; - + LWIP_UNUSED_ARG(arg); /* Caught DHCP message from netif that does not have DHCP enabled? -> not interested */ @@ -1668,7 +1668,7 @@ dhcp_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, } LWIP_ASSERT("invalid server address type", IP_IS_V4(addr)); - + LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_recv(pbuf = %p) from DHCP server %"U16_F".%"U16_F".%"U16_F".%"U16_F" port %"U16_F"\n", (void*)p, ip4_addr1_16(ip_2_ip4(addr)), ip4_addr2_16(ip_2_ip4(addr)), ip4_addr3_16(ip_2_ip4(addr)), ip4_addr4_16(ip_2_ip4(addr)), port)); LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("pbuf->len = %"U16_F"\n", p->len)); diff --git a/src/core/ipv6/ip6.c b/src/core/ipv6/ip6.c index 6ed95c93..3362249f 100644 --- a/src/core/ipv6/ip6.c +++ b/src/core/ipv6/ip6.c @@ -452,7 +452,7 @@ ip6_input(struct pbuf *p, struct netif *inp) IP6_STATS_INC(ip6.drop); return ERR_OK; } - + /* current header pointer. */ ip_data.current_ip6_header = ip6hdr; diff --git a/src/core/raw.c b/src/core/raw.c index 863739cb..efa21f90 100644 --- a/src/core/raw.c +++ b/src/core/raw.c @@ -80,7 +80,7 @@ raw_input_match(struct raw_pcb *pcb, u8_t broadcast) return 1; } #endif /* LWIP_IPV4 && LWIP_IPV6 */ - + /* Only need to check PCB if incoming IP version matches PCB IP version */ if (IP_ADDR_PCB_VERSION_MATCH_EXACT(pcb, ip_current_dest_addr())) { #if LWIP_IPV4 @@ -103,7 +103,7 @@ raw_input_match(struct raw_pcb *pcb, u8_t broadcast) return 1; } } - + return 0; } diff --git a/src/core/tcp_in.c b/src/core/tcp_in.c index 80e47ba7..2ad8f006 100644 --- a/src/core/tcp_in.c +++ b/src/core/tcp_in.c @@ -199,7 +199,7 @@ tcp_input(struct pbuf *p, struct netif *inp) /* remember the pointer to the second part of the options */ tcphdr_opt2 = (u8_t*)p->next->payload; - + /* advance p->next to point after the options, and manually adjust p->tot_len to keep it consistent with the changed p->next */ pbuf_header(p->next, -(s16_t)opt2len); diff --git a/src/core/udp.c b/src/core/udp.c index 9fc35876..bb957faf 100644 --- a/src/core/udp.c +++ b/src/core/udp.c @@ -191,7 +191,7 @@ udp_input_local_match(struct udp_pcb *pcb, struct netif *inp, u8_t broadcast) return 1; } } - + return 0; } diff --git a/src/include/lwip/api.h b/src/include/lwip/api.h index 8bd8bf1e..b821841b 100644 --- a/src/include/lwip/api.h +++ b/src/include/lwip/api.h @@ -327,7 +327,7 @@ err_t netconn_gethostbyname(const char *name, ip_addr_t *addr); #if LWIP_IPV6 /** @ingroup netconn_common - * TCP: Set the IPv6 ONLY status of netconn calls (see NETCONN_FLAG_IPV6_V6ONLY) + * TCP: Set the IPv6 ONLY status of netconn calls (see NETCONN_FLAG_IPV6_V6ONLY) */ #define netconn_set_ipv6only(conn, val) do { if(val) { \ (conn)->flags |= NETCONN_FLAG_IPV6_V6ONLY; \ diff --git a/src/include/lwip/apps/mdns_opts.h b/src/include/lwip/apps/mdns_opts.h index 7a65a2dc..a298c5aa 100644 --- a/src/include/lwip/apps/mdns_opts.h +++ b/src/include/lwip/apps/mdns_opts.h @@ -36,7 +36,7 @@ */ #ifndef LWIP_HDR_APPS_MDNS_OPTS_H -#define LWIP_HDR_APPS_MDNS_OPTS_H +#define LWIP_HDR_APPS_MDNS_OPTS_H #include "lwip/opt.h" @@ -70,5 +70,5 @@ * @} */ -#endif /* LWIP_HDR_APPS_MDNS_OPTS_H */ +#endif /* LWIP_HDR_APPS_MDNS_OPTS_H */ diff --git a/src/include/lwip/apps/snmp_core.h b/src/include/lwip/apps/snmp_core.h index 938be509..e781c532 100644 --- a/src/include/lwip/apps/snmp_core.h +++ b/src/include/lwip/apps/snmp_core.h @@ -200,7 +200,7 @@ struct snmp_node_instance u8_t asn1_type; /** one out of instance access types defined above (SNMP_NODE_INSTANCE_READ_ONLY,...) */ snmp_access_t access; - + /** returns object value for the given object identifier. Return values <0 to indicate an error */ node_instance_get_value_method get_value; /** tests length and/or range BEFORE setting */ @@ -278,7 +278,7 @@ struct snmp_next_oid_state u32_t* next_oid; u8_t next_oid_len; u8_t next_oid_max_len; - + snmp_next_oid_status_t status; void* reference; }; diff --git a/src/include/lwip/apps/snmp_table.h b/src/include/lwip/apps/snmp_table.h index c08f1aa5..4988b51c 100644 --- a/src/include/lwip/apps/snmp_table.h +++ b/src/include/lwip/apps/snmp_table.h @@ -85,7 +85,7 @@ snmp_err_t snmp_table_get_next_instance(const u32_t *root_oid, u8_t root_oid_len #define SNMP_TABLE_GET_COLUMN_FROM_OID(oid) ((oid)[1]) /* first array value is (fixed) row entry (fixed to 1) and 2nd value is column, follow3ed by instance */ - + /** simple read-only table */ typedef enum { SNMP_VARIANT_VALUE_TYPE_U32, diff --git a/src/include/lwip/arch.h b/src/include/lwip/arch.h index 372cea13..f20f6e4f 100644 --- a/src/include/lwip/arch.h +++ b/src/include/lwip/arch.h @@ -48,7 +48,7 @@ #include "arch/cc.h" /** Define this to 1 in arch/cc.h of your port if your compiler does not provide - * the stdint.h header. This cannot be \#defined in lwipopts.h since + * the stdint.h header. This cannot be \#defined in lwipopts.h since * this is not an option of lwIP itself, but an option of the lwIP port * to your system. * Additionally, this header is meant to be \#included in lwipopts.h @@ -71,7 +71,7 @@ typedef uintptr_t mem_ptr_t; #endif /** Define this to 1 in arch/cc.h of your port if your compiler does not provide - * the inttypes.h header. This cannot be \#defined in lwipopts.h since + * the inttypes.h header. This cannot be \#defined in lwipopts.h since * this is not an option of lwIP itself, but an option of the lwIP port * to your system. * Additionally, this header is meant to be \#included in lwipopts.h diff --git a/src/include/lwip/err.h b/src/include/lwip/err.h index 565a7311..f60c6fce 100644 --- a/src/include/lwip/err.h +++ b/src/include/lwip/err.h @@ -60,7 +60,7 @@ typedef s8_t err_t; /** Definitions for error constants. */ typedef enum { /** No error, everything OK. */ - ERR_OK = 0, + ERR_OK = 0, /** Out of memory error. */ ERR_MEM = -1, /** Buffer error. */ diff --git a/src/include/lwip/etharp.h b/src/include/lwip/etharp.h index d02f1d41..6b629d37 100644 --- a/src/include/lwip/etharp.h +++ b/src/include/lwip/etharp.h @@ -59,7 +59,7 @@ extern "C" { #if LWIP_IPV4 && LWIP_ARP /* don't build if not configured for use in lwipopts.h */ #include "lwip/prot/arp.h" - + #define SIZEOF_ETHARP_PACKET (SIZEOF_ETH_HDR + SIZEOF_ETHARP_HDR) #if ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET) #define SIZEOF_ETHARP_PACKET_TX (SIZEOF_ETHARP_PACKET + SIZEOF_VLAN_HDR) diff --git a/src/include/lwip/icmp6.h b/src/include/lwip/icmp6.h index 7ef98a18..e66557d4 100644 --- a/src/include/lwip/icmp6.h +++ b/src/include/lwip/icmp6.h @@ -62,7 +62,7 @@ enum icmp6_type { /** Parameter problem */ ICMP6_TYPE_PP = 4, /** Private experimentation */ - ICMP6_TYPE_PE1 = 100, + ICMP6_TYPE_PE1 = 100, /** Private experimentation */ ICMP6_TYPE_PE2 = 101, /** Reserved for expansion of error messages */ @@ -73,7 +73,7 @@ enum icmp6_type { /** Echo reply */ ICMP6_TYPE_EREP = 129, /** Multicast listener query */ - ICMP6_TYPE_MLQ = 130, + ICMP6_TYPE_MLQ = 130, /** Multicast listener report */ ICMP6_TYPE_MLR = 131, /** Multicast listener done */ diff --git a/src/include/lwip/ip.h b/src/include/lwip/ip.h index 7c079dd1..0673be9b 100644 --- a/src/include/lwip/ip.h +++ b/src/include/lwip/ip.h @@ -248,9 +248,9 @@ extern struct ip_globals ip_data; (IP_IS_V6(dest) ? \ ip6_output_hinted(p, ip_2_ip6(src), ip_2_ip6(dest), ttl, tos, proto, addr_hint) : \ ip4_output_hinted(p, ip_2_ip4(src), ip_2_ip4(dest), ttl, tos, proto, addr_hint)) -/** +/** * @ingroup ip - * Get netif for address combination. See \ref ip6_route and \ref ip4_route + * Get netif for address combination. See \ref ip6_route and \ref ip4_route */ #define ip_route(src, dest) \ (IP_IS_V6(dest) ? \ diff --git a/src/include/lwip/netif.h b/src/include/lwip/netif.h index 366cfe1f..593c3af4 100644 --- a/src/include/lwip/netif.h +++ b/src/include/lwip/netif.h @@ -68,7 +68,7 @@ extern "C" { * @ingroup netif * @{ */ - + /** Whether the network interface is 'up'. This is * a software flag used to control whether this network * interface is enabled and processes traffic. diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h index 0c499841..17ba18d2 100644 --- a/src/include/lwip/opt.h +++ b/src/include/lwip/opt.h @@ -36,8 +36,8 @@ * */ -/* - * NOTE: || defined __DOXYGEN__ is a workaround for doxygen bug - +/* + * NOTE: || defined __DOXYGEN__ is a workaround for doxygen bug - * without this, doxygen does not see the actual #define */ @@ -51,7 +51,7 @@ #include "lwipopts.h" #include "lwip/debug.h" -/** +/** * @defgroup lwip_opts Options (lwipopts.h) * @ingroup lwip * diff --git a/src/include/lwip/priv/tcpip_priv.h b/src/include/lwip/priv/tcpip_priv.h index d9fe37ae..b6e42935 100644 --- a/src/include/lwip/priv/tcpip_priv.h +++ b/src/include/lwip/priv/tcpip_priv.h @@ -48,7 +48,7 @@ #ifdef __cplusplus extern "C" { #endif - + struct pbuf; struct netif; diff --git a/src/include/lwip/prot/arp.h b/src/include/lwip/prot/arp.h index 94084b90..8e32df50 100644 --- a/src/include/lwip/prot/arp.h +++ b/src/include/lwip/prot/arp.h @@ -71,7 +71,7 @@ PACK_STRUCT_END #endif #define SIZEOF_ETHARP_HDR 28 - + #ifdef __cplusplus } #endif diff --git a/src/include/lwip/prot/ethernet.h b/src/include/lwip/prot/ethernet.h index 4d11328d..d7a56f6c 100644 --- a/src/include/lwip/prot/ethernet.h +++ b/src/include/lwip/prot/ethernet.h @@ -138,7 +138,7 @@ PACK_STRUCT_END #ifndef ETHADDR16_COPY #define ETHADDR16_COPY(dst, src) SMEMCPY(dst, src, ETH_HWADDR_LEN) #endif - + #define eth_addr_cmp(addr1, addr2) (memcmp((addr1)->addr, (addr2)->addr, ETH_HWADDR_LEN) == 0) #ifdef __cplusplus diff --git a/src/include/lwip/prot/ip.h b/src/include/lwip/prot/ip.h index 7011785d..bbfae367 100644 --- a/src/include/lwip/prot/ip.h +++ b/src/include/lwip/prot/ip.h @@ -49,5 +49,3 @@ #define IP_HDR_GET_VERSION(ptr) ((*(u8_t*)(ptr)) >> 4) #endif /* LWIP_HDR_PROT_IP_H */ - - diff --git a/src/include/lwip/prot/ip4.h b/src/include/lwip/prot/ip4.h index 3e7cbd1f..c3c34038 100644 --- a/src/include/lwip/prot/ip4.h +++ b/src/include/lwip/prot/ip4.h @@ -46,7 +46,7 @@ extern "C" { /* Size of the IPv4 header. Same as 'sizeof(struct ip_hdr)'. */ #define IP_HLEN 20 - + #ifdef PACK_STRUCT_USE_INCLUDES # include "arch/bpstruct.h" #endif @@ -109,5 +109,3 @@ PACK_STRUCT_END #endif #endif /* LWIP_HDR_PROT_IP4_H */ - - diff --git a/src/include/lwip/prot/ip6.h b/src/include/lwip/prot/ip6.h index 0e801bf9..9a1aaa9f 100644 --- a/src/include/lwip/prot/ip6.h +++ b/src/include/lwip/prot/ip6.h @@ -146,7 +146,7 @@ PACK_STRUCT_END #define IP6H_PLEN_SET(hdr, plen) (hdr)->_plen = htons(plen) #define IP6H_NEXTH_SET(hdr, nexth) (hdr)->_nexth = (nexth) #define IP6H_HOPLIM_SET(hdr, hl) (hdr)->_hoplim = (u8_t)(hl) - + #ifdef __cplusplus } #endif diff --git a/src/include/lwip/prot/mld6.h b/src/include/lwip/prot/mld6.h index 86ccc8fb..2664829b 100644 --- a/src/include/lwip/prot/mld6.h +++ b/src/include/lwip/prot/mld6.h @@ -62,7 +62,7 @@ PACK_STRUCT_END #ifdef PACK_STRUCT_USE_INCLUDES # include "arch/epstruct.h" #endif - + #ifdef __cplusplus } #endif diff --git a/src/include/lwip/prot/tcp.h b/src/include/lwip/prot/tcp.h index 64bb1fef..3e263304 100644 --- a/src/include/lwip/prot/tcp.h +++ b/src/include/lwip/prot/tcp.h @@ -77,7 +77,7 @@ PACK_STRUCT_END #define TCPH_SET_FLAG(phdr, flags ) (phdr)->_hdrlen_rsvd_flags = ((phdr)->_hdrlen_rsvd_flags | htons(flags)) #define TCPH_UNSET_FLAG(phdr, flags) (phdr)->_hdrlen_rsvd_flags = ((phdr)->_hdrlen_rsvd_flags & ~htons(flags)) - + #ifdef __cplusplus } #endif diff --git a/src/include/lwip/prot/udp.h b/src/include/lwip/prot/udp.h index fdf452a8..664f19a3 100644 --- a/src/include/lwip/prot/udp.h +++ b/src/include/lwip/prot/udp.h @@ -60,7 +60,7 @@ PACK_STRUCT_END #ifdef PACK_STRUCT_USE_INCLUDES # include "arch/epstruct.h" #endif - + #ifdef __cplusplus } #endif diff --git a/src/include/lwip/stats.h b/src/include/lwip/stats.h index 99f49cce..bcda2ace 100644 --- a/src/include/lwip/stats.h +++ b/src/include/lwip/stats.h @@ -189,16 +189,16 @@ struct stats_mib2_netif_ctrs { /** The number of packets, delivered by this sub-layer to a higher (sub-)layer, which were * not addressed to a multicast or broadcast address at this sub-layer */ u32_t ifinucastpkts; - /** The number of packets, delivered by this sub-layer to a higher (sub-)layer, which were + /** The number of packets, delivered by this sub-layer to a higher (sub-)layer, which were * addressed to a multicast or broadcast address at this sub-layer */ u32_t ifinnucastpkts; - /** The number of inbound packets which were chosen to be discarded even though no errors had - * been detected to prevent their being deliverable to a higher-layer protocol. One possible + /** The number of inbound packets which were chosen to be discarded even though no errors had + * been detected to prevent their being deliverable to a higher-layer protocol. One possible * reason for discarding such a packet could be to free up buffer space */ u32_t ifindiscards; - /** For packet-oriented interfaces, the number of inbound packets that contained errors + /** For packet-oriented interfaces, the number of inbound packets that contained errors * preventing them from being deliverable to a higher-layer protocol. For character- - * oriented or fixed-length interfaces, the number of inbound transmission units that + * oriented or fixed-length interfaces, the number of inbound transmission units that * contained errors preventing them from being deliverable to a higher-layer protocol. */ u32_t ifinerrors; /** For packet-oriented interfaces, the number of packets received via the interface which @@ -408,7 +408,7 @@ void stats_init(void); #define MEMP_STATS_DISPLAY(i) #define MEMP_STATS_GET(x, i) 0 #endif - + #if SYS_STATS #define SYS_STATS_INC(x) STATS_INC(sys.x) #define SYS_STATS_DEC(x) STATS_DEC(sys.x) diff --git a/src/include/lwip/sys.h b/src/include/lwip/sys.h index c05af04e..f8804df4 100644 --- a/src/include/lwip/sys.h +++ b/src/include/lwip/sys.h @@ -60,10 +60,10 @@ * @defgroup sys_prot Critical sections * @ingroup sys_layer * Used to protect short regions of code against concurrent access. - * - Your system is a bare-metal system (probably with an RTOS) + * - Your system is a bare-metal system (probably with an RTOS) * and interrupts are under your control: * Implement this as LockInterrupts() / UnlockInterrupts() - * - Your system uses an RTOS with deferred interrupt handling from a + * - Your system uses an RTOS with deferred interrupt handling from a * worker thread: Implement as a global mutex or lock/unlock scheduler * - Your system uses a high-level OS with e.g. POSIX signals: * Implement as a global mutex diff --git a/src/include/lwip/tcpip.h b/src/include/lwip/tcpip.h index 796f34aa..dc060b20 100644 --- a/src/include/lwip/tcpip.h +++ b/src/include/lwip/tcpip.h @@ -76,7 +76,7 @@ err_t tcpip_inpkt(struct pbuf *p, struct netif *inp, netif_input_fn input_fn); err_t tcpip_input(struct pbuf *p, struct netif *inp); err_t tcpip_callback_with_block(tcpip_callback_fn function, void *ctx, u8_t block); -/** +/** * @ingroup lwip_os * @see tcpip_callback_with_block */ diff --git a/src/netif/ethernetif.c b/src/netif/ethernetif.c index 973b3e15..c873c8c8 100644 --- a/src/netif/ethernetif.c +++ b/src/netif/ethernetif.c @@ -266,7 +266,7 @@ ethernetif_input(struct netif *netif) /* if no packet could be read, silently ignore this */ if (p != NULL) { /* pass all packets to ethernet_input, which decides what packets it supports */ - if (netif->input(p, netif) != ERR_OK) { + if (netif->input(p, netif) != ERR_OK) { LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n")); pbuf_free(p); p = NULL; diff --git a/src/netif/slipif.c b/src/netif/slipif.c index f6c5d4b7..8849fbf6 100644 --- a/src/netif/slipif.c +++ b/src/netif/slipif.c @@ -42,10 +42,10 @@ /** * @defgroup slipif SLIP netif * @ingroup addons - * + * * This is an arch independent SLIP netif. The specific serial hooks must be * provided by another file. They are sio_open, sio_read/sio_tryread and sio_send - * + * * Usage: This netif can be used in three ways:\n * 1) For NO_SYS==0, an RX thread can be used which blocks on sio_read() * until data is received.\n From 96c3c48ba762b0af30e0d2e37b4203d6e298f4eb Mon Sep 17 00:00:00 2001 From: goldsimon Date: Fri, 19 Aug 2016 09:52:30 +0200 Subject: [PATCH 125/325] mdns: moved private things into mdns_priv.h --- src/apps/mdns/mdns.c | 4 +- src/include/lwip/apps/mdns.h | 31 ++++----------- src/include/lwip/apps/mdns_priv.h | 66 +++++++++++++++++++++++++++++++ test/unit/mdns/test_mdns.c | 1 + 4 files changed, 77 insertions(+), 25 deletions(-) create mode 100644 src/include/lwip/apps/mdns_priv.h diff --git a/src/apps/mdns/mdns.c b/src/apps/mdns/mdns.c index e89c88e6..e9c2d136 100644 --- a/src/apps/mdns/mdns.c +++ b/src/apps/mdns/mdns.c @@ -1989,7 +1989,7 @@ mdns_resp_remove_netif(struct netif *netif) * @return ERR_OK if the service was added to the netif, an err_t otherwise */ err_t -mdns_resp_add_service(struct netif *netif, const char *name, const char *service, u16_t proto, u16_t port, u32_t dns_ttl, service_get_txt_fn_t txt_fn, void *txt_data) +mdns_resp_add_service(struct netif *netif, const char *name, const char *service, enum mdns_sd_proto proto, u16_t port, u32_t dns_ttl, service_get_txt_fn_t txt_fn, void *txt_data) { int i; int slot = -1; @@ -2021,7 +2021,7 @@ mdns_resp_add_service(struct netif *netif, const char *name, const char *service memcpy(&srv->service, service, LWIP_MIN(MDNS_LABEL_MAXLEN, strlen(service))); srv->txt_fn = txt_fn; srv->txt_userdata = txt_data; - srv->proto = proto; + srv->proto = (u16_t)proto; srv->port = port; srv->dns_ttl = dns_ttl; diff --git a/src/include/lwip/apps/mdns.h b/src/include/lwip/apps/mdns.h index 302bdf6a..f57b182f 100644 --- a/src/include/lwip/apps/mdns.h +++ b/src/include/lwip/apps/mdns.h @@ -42,43 +42,28 @@ #if LWIP_MDNS_RESPONDER -#define DNSSD_PROTO_UDP 0 -#define DNSSD_PROTO_TCP 1 +enum mdns_sd_proto { + DNSSD_PROTO_UDP = 0, + DNSSD_PROTO_TCP = 1 +}; #define MDNS_LABEL_MAXLEN 63 struct mdns_host; struct mdns_service; +/** Callback function to add text to a reply, called when generating the reply */ +typedef void (*service_get_txt_fn_t)(struct mdns_service *service, void *txt_userdata); + void mdns_resp_init(void); err_t mdns_resp_add_netif(struct netif *netif, const char *hostname, u32_t dns_ttl); err_t mdns_resp_remove_netif(struct netif *netif); -typedef void (*service_get_txt_fn_t)(struct mdns_service *service, void *txt_userdata); -err_t mdns_resp_add_service(struct netif *netif, const char *name, const char *service, u16_t proto, u16_t port, u32_t dns_ttl, service_get_txt_fn_t txt_fn, void *txt_userdata); +err_t mdns_resp_add_service(struct netif *netif, const char *name, const char *service, enum mdns_sd_proto proto, u16_t port, u32_t dns_ttl, service_get_txt_fn_t txt_fn, void *txt_userdata); err_t mdns_resp_add_service_txtitem(struct mdns_service *service, const char *txt, u8_t txt_len); void mdns_resp_netif_settings_changed(struct netif *netif); - -/* Domain struct and methods - visible for unit tests */ -#define MDNS_DOMAIN_MAXLEN 256 -#define MDNS_READNAME_ERROR 0xFFFF - -struct mdns_domain { - /* Encoded domain name */ - u8_t name[MDNS_DOMAIN_MAXLEN]; - /* Total length of domain name, including zero */ - u16_t length; - /* Set if compression of this domain is not allowed */ - u8_t skip_compression; -}; - -err_t mdns_domain_add_label(struct mdns_domain *domain, const char *label, u8_t len); -u16_t mdns_readname(struct pbuf *p, u16_t offset, struct mdns_domain *domain); -int mdns_domain_eq(struct mdns_domain *a, struct mdns_domain *b); -u16_t mdns_compress_domain(struct pbuf *pbuf, u16_t *offset, struct mdns_domain *domain); - #endif /* LWIP_MDNS_RESPONDER */ #endif /* LWIP_HDR_MDNS_H */ diff --git a/src/include/lwip/apps/mdns_priv.h b/src/include/lwip/apps/mdns_priv.h new file mode 100644 index 00000000..9ae2cef9 --- /dev/null +++ b/src/include/lwip/apps/mdns_priv.h @@ -0,0 +1,66 @@ +/** + * @file + * MDNS responder private definitions + */ + + /* + * Copyright (c) 2015 Verisure Innovation AB + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Erik Ekman + * + */ +#ifndef LWIP_HDR_MDNS_PRIV_H +#define LWIP_HDR_MDNS_PRIV_H + +#include "lwip/apps/mdns_opts.h" +#include "lwip/pbuf.h" + +#if LWIP_MDNS_RESPONDER + +/* Domain struct and methods - visible for unit tests */ + +#define MDNS_DOMAIN_MAXLEN 256 +#define MDNS_READNAME_ERROR 0xFFFF + +struct mdns_domain { + /* Encoded domain name */ + u8_t name[MDNS_DOMAIN_MAXLEN]; + /* Total length of domain name, including zero */ + u16_t length; + /* Set if compression of this domain is not allowed */ + u8_t skip_compression; +}; + +err_t mdns_domain_add_label(struct mdns_domain *domain, const char *label, u8_t len); +u16_t mdns_readname(struct pbuf *p, u16_t offset, struct mdns_domain *domain); +int mdns_domain_eq(struct mdns_domain *a, struct mdns_domain *b); +u16_t mdns_compress_domain(struct pbuf *pbuf, u16_t *offset, struct mdns_domain *domain); + +#endif /* LWIP_MDNS_RESPONDER */ + +#endif /* LWIP_HDR_MDNS_PRIV_H */ diff --git a/test/unit/mdns/test_mdns.c b/test/unit/mdns/test_mdns.c index b149a7e0..9cff0fd7 100644 --- a/test/unit/mdns/test_mdns.c +++ b/test/unit/mdns/test_mdns.c @@ -37,6 +37,7 @@ #include "lwip/pbuf.h" #include "lwip/apps/mdns.h" +#include "lwip/apps/mdns_priv.h" START_TEST(readname_basic) { From 1e6f33d44b8f37adfd0109603926c05726b5ce71 Mon Sep 17 00:00:00 2001 From: goldsimon Date: Fri, 19 Aug 2016 10:41:01 +0200 Subject: [PATCH 126/325] tcp: move tcp header flags definitions to 'prot' --- src/include/lwip/priv/tcp_priv.h | 10 ---------- src/include/lwip/prot/tcp.h | 12 ++++++++++++ 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/include/lwip/priv/tcp_priv.h b/src/include/lwip/priv/tcp_priv.h index afd6f937..c0c9110d 100644 --- a/src/include/lwip/priv/tcp_priv.h +++ b/src/include/lwip/priv/tcp_priv.h @@ -112,16 +112,6 @@ err_t tcp_process_refused_data(struct tcp_pcb *pcb); #define TCP_SEQ_BETWEEN(a,b,c) ((c)-(b) >= (a)-(b)) #endif #define TCP_SEQ_BETWEEN(a,b,c) (TCP_SEQ_GEQ(a,b) && TCP_SEQ_LEQ(a,c)) -#define TCP_FIN 0x01U -#define TCP_SYN 0x02U -#define TCP_RST 0x04U -#define TCP_PSH 0x08U -#define TCP_ACK 0x10U -#define TCP_URG 0x20U -#define TCP_ECE 0x40U -#define TCP_CWR 0x80U - -#define TCP_FLAGS 0x3fU #ifndef TCP_TMR_INTERVAL #define TCP_TMR_INTERVAL 250 /* The TCP timer interval in milliseconds. */ diff --git a/src/include/lwip/prot/tcp.h b/src/include/lwip/prot/tcp.h index 3e263304..8ef0bf1d 100644 --- a/src/include/lwip/prot/tcp.h +++ b/src/include/lwip/prot/tcp.h @@ -68,6 +68,18 @@ PACK_STRUCT_END # include "arch/epstruct.h" #endif +/* TCP header flags bits */ +#define TCP_FIN 0x01U +#define TCP_SYN 0x02U +#define TCP_RST 0x04U +#define TCP_PSH 0x08U +#define TCP_ACK 0x10U +#define TCP_URG 0x20U +#define TCP_ECE 0x40U +#define TCP_CWR 0x80U +/* Valid TCP header flags */ +#define TCP_FLAGS 0x3fU + #define TCPH_HDRLEN(phdr) ((u16_t)(ntohs((phdr)->_hdrlen_rsvd_flags) >> 12)) #define TCPH_FLAGS(phdr) ((u16_t)(ntohs((phdr)->_hdrlen_rsvd_flags) & TCP_FLAGS)) From 4a7dafc6a6f8c33b6f7b2bcadb139b0f661f4dd3 Mon Sep 17 00:00:00 2001 From: goldsimon Date: Fri, 19 Aug 2016 11:02:37 +0200 Subject: [PATCH 127/325] fixed compiling mdns.c after moving things to mdns_priv.h --- src/apps/mdns/mdns.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/apps/mdns/mdns.c b/src/apps/mdns/mdns.c index e9c2d136..b16be10e 100644 --- a/src/apps/mdns/mdns.c +++ b/src/apps/mdns/mdns.c @@ -60,6 +60,7 @@ */ #include "lwip/apps/mdns.h" +#include "lwip/apps/mdns_privs.h" #include "lwip/netif.h" #include "lwip/udp.h" #include "lwip/ip_addr.h" From ebd1bf8a494962dad0dc87b9c57c0be996e1eb85 Mon Sep 17 00:00:00 2001 From: goldsimon Date: Fri, 19 Aug 2016 11:03:09 +0200 Subject: [PATCH 128/325] fixed typo :-( --- src/apps/mdns/mdns.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/apps/mdns/mdns.c b/src/apps/mdns/mdns.c index b16be10e..7017146b 100644 --- a/src/apps/mdns/mdns.c +++ b/src/apps/mdns/mdns.c @@ -60,7 +60,7 @@ */ #include "lwip/apps/mdns.h" -#include "lwip/apps/mdns_privs.h" +#include "lwip/apps/mdns_priv.h" #include "lwip/netif.h" #include "lwip/udp.h" #include "lwip/ip_addr.h" From 64f79e7ffc32c1de5211872a78e3891f5ea6315f Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Fri, 19 Aug 2016 16:30:47 +0800 Subject: [PATCH 129/325] PPP, PPPoE: Include netif/ethernet.h to fix build error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix below build errors: In file included from ../../../../../lwip/src/include/netif/ppp/ppp_opts.h:31:0, from ../../../../../lwip/src/netif/ppp/pppoe.c:71: ../../../../../lwip/src/netif/ppp/pppoe.c: In function ‘pppoe_timeout’: ../../../../../lwip/src/netif/ppp/pppoe.c:861:30: error: ‘ethbroadcast’ undeclared (first use in this function) MEMCPY(&sc->sc_dest, ethbroadcast.addr, sizeof(sc->sc_dest)); ^ ../../../../../lwip/src/include/lwip/opt.h:137:52: note: in definition of macro ‘MEMCPY’ #define MEMCPY(dst,src,len) memcpy(dst,src,len) ^ ../../../../../lwip/src/netif/ppp/pppoe.c:861:30: note: each undeclared identifier is reported only once for each function it appears in MEMCPY(&sc->sc_dest, ethbroadcast.addr, sizeof(sc->sc_dest)); ^ ../../../../../lwip/src/include/lwip/opt.h:137:52: note: in definition of macro ‘MEMCPY’ #define MEMCPY(dst,src,len) memcpy(dst,src,len) ^ ../../../../../lwip/src/netif/ppp/pppoe.c: In function ‘pppoe_connect’: ../../../../../lwip/src/netif/ppp/pppoe.c:899:24: error: ‘ethbroadcast’ undeclared (first use in this function) MEMCPY(&sc->sc_dest, ethbroadcast.addr, sizeof(sc->sc_dest)); ^ ../../../../../lwip/src/include/lwip/opt.h:137:52: note: in definition of macro ‘MEMCPY’ #define MEMCPY(dst,src,len) memcpy(dst,src,len) ^ ../../Common.mk:94: recipe for target 'pppoe.o' failed make: *** [pppoe.o] Error 1 Fixes: 8eb9db18a2d9 ("Reduce usage of netif/ethernet.h header, mostly lwip/prot/ethernet.h is sufficient") Signed-off-by: Axel Lin Signed-off-by: goldsimon --- src/netif/ppp/pppoe.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/netif/ppp/pppoe.c b/src/netif/ppp/pppoe.c index 24d9c4f5..768d22be 100644 --- a/src/netif/ppp/pppoe.c +++ b/src/netif/ppp/pppoe.c @@ -81,6 +81,7 @@ #include "lwip/stats.h" #include "lwip/snmp.h" +#include "netif/ethernet.h" #include "netif/ppp/ppp_impl.h" #include "netif/ppp/lcp.h" #include "netif/ppp/ipcp.h" From 12609c951c0ae1edb5695b31dd8010649ddc1517 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Fri, 19 Aug 2016 12:21:01 +0200 Subject: [PATCH 130/325] Fix compile of SNMPv3 code with MSVC --- src/apps/snmp/snmp_msg.c | 30 ++++++++++++++++-------------- src/include/lwip/apps/snmp_opts.h | 6 +++++- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/apps/snmp/snmp_msg.c b/src/apps/snmp/snmp_msg.c index 912f55aa..3401f5b5 100644 --- a/src/apps/snmp/snmp_msg.c +++ b/src/apps/snmp/snmp_msg.c @@ -650,11 +650,12 @@ snmp_parse_inbound_frame(struct snmp_request *request) #if LWIP_SNMP_V3 if (request->version == SNMP_VERSION_3) { u16_t u16_value; + u16_t inbound_msgAuthenticationParameters_offset; /* SNMPv3 doesn't use communities */ /* @todo: Differentiate read/write access */ strcpy((char*)request->community, snmp_community); - request->community_strlen = strlen(snmp_community); + request->community_strlen = (u16_t)strlen(snmp_community); /* RFC3414 globalData */ IF_PARSE_EXEC(snmp_asn1_dec_tlv(&pbuf_stream, &tlv)); @@ -687,7 +688,7 @@ snmp_parse_inbound_frame(struct snmp_request *request) IF_PARSE_ASSERT(parent_tlv_value_len > 0); IF_PARSE_EXEC(snmp_asn1_dec_s32t(&pbuf_stream, tlv.value_len, &s32_value)); - request->msg_flags = s32_value; + request->msg_flags = (u8_t)s32_value; /* decode msgSecurityModel */ IF_PARSE_EXEC(snmp_asn1_dec_tlv(&pbuf_stream, &tlv)); @@ -724,7 +725,7 @@ snmp_parse_inbound_frame(struct snmp_request *request) IF_PARSE_EXEC(snmp_asn1_dec_raw(&pbuf_stream, tlv.value_len, request->msg_authoritative_engine_id, &u16_value, SNMP_V3_MAX_ENGINE_ID_LENGTH)); - request->msg_authoritative_engine_id_len = u16_value; + request->msg_authoritative_engine_id_len = (u8_t)u16_value; /* msgAuthoritativeEngineBoots */ IF_PARSE_EXEC(snmp_asn1_dec_tlv(&pbuf_stream, &tlv)); @@ -749,7 +750,7 @@ snmp_parse_inbound_frame(struct snmp_request *request) IF_PARSE_EXEC(snmp_asn1_dec_raw(&pbuf_stream, tlv.value_len, request->msg_user_name, &u16_value, SNMP_V3_MAX_USER_LENGTH)); - request->msg_user_name_len = u16_value; + request->msg_user_name_len = (u8_t)u16_value; /* @todo: Implement unknown user error response */ IF_PARSE_EXEC(snmpv3_get_user((char*)request->msg_user_name, NULL, NULL, NULL, NULL)); @@ -760,7 +761,7 @@ snmp_parse_inbound_frame(struct snmp_request *request) parent_tlv_value_len -= SNMP_ASN1_TLV_LENGTH(tlv); IF_PARSE_ASSERT(parent_tlv_value_len > 0); /* Remember position */ - u16_t inbound_msgAuthenticationParameters_offset = pbuf_stream.offset; + inbound_msgAuthenticationParameters_offset = pbuf_stream.offset; LWIP_UNUSED_ARG(inbound_msgAuthenticationParameters_offset); /* Read auth parameters */ IF_PARSE_ASSERT(tlv.value_len <= SNMP_V3_MAX_AUTH_PARAM_LENGTH); @@ -769,18 +770,19 @@ snmp_parse_inbound_frame(struct snmp_request *request) #if LWIP_SNMP_V3_CRYPTO if (request->msg_flags & SNMP_V3_AUTH_FLAG) { - /* Rewind stream */ - IF_PARSE_EXEC(snmp_pbuf_stream_init(&pbuf_stream, request->inbound_pbuf, 0, request->inbound_pbuf->tot_len)); - IF_PARSE_EXEC(snmp_pbuf_stream_seek_abs(&pbuf_stream, inbound_msgAuthenticationParameters_offset)); - /* Set auth parameters to zero for verification */ const u8_t zero_arr[SNMP_V3_MAX_AUTH_PARAM_LENGTH] = { 0 }; - IF_PARSE_EXEC(snmp_asn1_enc_raw(&pbuf_stream, zero_arr, tlv.value_len)); - - /* Verify authentication */ u8_t key[20]; u8_t algo; u8_t hmac[LWIP_MAX(SNMP_V3_SHA_LEN, SNMP_V3_MD5_LEN)]; struct snmp_pbuf_stream auth_stream; + + /* Rewind stream */ + IF_PARSE_EXEC(snmp_pbuf_stream_init(&pbuf_stream, request->inbound_pbuf, 0, request->inbound_pbuf->tot_len)); + IF_PARSE_EXEC(snmp_pbuf_stream_seek_abs(&pbuf_stream, inbound_msgAuthenticationParameters_offset)); + /* Set auth parameters to zero for verification */ + IF_PARSE_EXEC(snmp_asn1_enc_raw(&pbuf_stream, zero_arr, tlv.value_len)); + + /* Verify authentication */ IF_PARSE_EXEC(snmp_pbuf_stream_init(&auth_stream, request->inbound_pbuf, 0, request->inbound_pbuf->tot_len)); IF_PARSE_EXEC(snmpv3_get_user((char*)request->msg_user_name, &algo, key, NULL, NULL)); @@ -839,7 +841,7 @@ snmp_parse_inbound_frame(struct snmp_request *request) IF_PARSE_EXEC(snmp_asn1_dec_raw(&pbuf_stream, tlv.value_len, request->context_engine_id, &u16_value, SNMP_V3_MAX_ENGINE_ID_LENGTH)); - request->context_engine_id_len = u16_value; + request->context_engine_id_len = (u8_t)u16_value; /* contextName */ IF_PARSE_EXEC(snmp_asn1_dec_tlv(&pbuf_stream, &tlv)); @@ -849,7 +851,7 @@ snmp_parse_inbound_frame(struct snmp_request *request) IF_PARSE_EXEC(snmp_asn1_dec_raw(&pbuf_stream, tlv.value_len, request->context_name, &u16_value, SNMP_V3_MAX_ENGINE_ID_LENGTH)); - request->context_name_len = u16_value; + request->context_name_len = (u8_t)u16_value; } else #endif { diff --git a/src/include/lwip/apps/snmp_opts.h b/src/include/lwip/apps/snmp_opts.h index bf6f0093..6c9ba7be 100644 --- a/src/include/lwip/apps/snmp_opts.h +++ b/src/include/lwip/apps/snmp_opts.h @@ -283,7 +283,11 @@ #endif #ifndef LWIP_SNMP_V3_CRYPTO -#define LWIP_SNMP_V3_CRYPTO LWIP_SNMP_V3 +#define LWIP_SNMP_V3_CRYPTO LWIP_SNMP_V3 +#endif + +#ifndef LWIP_SNMP_V3_MBEDTLS +#define LWIP_SNMP_V3_MBEDTLS LWIP_SNMP_V3 #endif #endif /* LWIP_HDR_SNMP_OPTS_H */ From fefb782bfe0d6683d5515dfa91a2bdfeef0e6992 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Fri, 19 Aug 2016 12:22:42 +0200 Subject: [PATCH 131/325] Apply fix by Marco Veeneman in SNMPv3: The outbound_padding is calculated wrong in snmp_complete_outbound_frame() --- src/apps/snmp/snmp_msg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/apps/snmp/snmp_msg.c b/src/apps/snmp/snmp_msg.c index 3401f5b5..6a083ad1 100644 --- a/src/apps/snmp/snmp_msg.c +++ b/src/apps/snmp/snmp_msg.c @@ -1384,7 +1384,7 @@ snmp_complete_outbound_frame(struct snmp_request *request) /* Calculate padding for encryption */ if (request->version == SNMP_VERSION_3 && (request->msg_flags & SNMP_V3_PRIV_FLAG)) { u8_t i; - outbound_padding = (u8_t)((frame_size - request->outbound_scoped_pdu_seq_offset) & 0x03); + outbound_padding = (8 - (u8_t)((frame_size - request->outbound_scoped_pdu_seq_offset) & 0x07)) & 0x07; for (i = 0; i < outbound_padding; i++) { snmp_pbuf_stream_write(&request->outbound_pbuf_stream, 0); } From 0e9ef19cfb5640da686f3f30404d84c8b5bc5197 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Fri, 19 Aug 2016 07:34:33 +0800 Subject: [PATCH 132/325] memp: Remove memp_overflow_init() function There is only one caller using memp_overflow_init(), and at that context calling memp_overflow_init_element() actually simplifes the code. Thus remove memp_overflow_init() function. Signed-off-by: Axel Lin Signed-off-by: goldsimon --- src/core/memp.c | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/src/core/memp.c b/src/core/memp.c index 78307b53..f78db10f 100644 --- a/src/core/memp.c +++ b/src/core/memp.c @@ -204,24 +204,6 @@ memp_overflow_check_all(void) SYS_ARCH_UNPROTECT(old_level); } #endif /* MEMP_OVERFLOW_CHECK >= 2 */ - -#if !MEMP_MEM_MALLOC -/** - * Initialize the restricted areas of all memp elements in a pool. - */ -static void -memp_overflow_init(const struct memp_desc *desc) -{ - u16_t i; - struct memp *p; - - p = (struct memp*)LWIP_MEM_ALIGN(desc->base); - for (i = 0; i < desc->num; ++i) { - memp_overflow_init_element(p, desc); - p = (struct memp*)(size_t)((u8_t*)p + MEMP_SIZE + desc->size + MEMP_SANITY_REGION_AFTER_ALIGNED); - } -} -#endif /* !MEMP_MEM_MALLOC */ #endif /* MEMP_OVERFLOW_CHECK */ /** @@ -245,6 +227,9 @@ memp_init_pool(const struct memp_desc *desc) for (i = 0; i < desc->num; ++i) { memp->next = *desc->tab; *desc->tab = memp; +#if MEMP_OVERFLOW_CHECK + memp_overflow_init_element(memp, desc); +#endif /* MEMP_OVERFLOW_CHECK */ /* cast through void* to get rid of alignment warnings */ memp = (struct memp *)(void *)((u8_t *)memp + MEMP_SIZE + desc->size #if MEMP_OVERFLOW_CHECK @@ -252,10 +237,6 @@ memp_init_pool(const struct memp_desc *desc) #endif ); } - -#if MEMP_OVERFLOW_CHECK - memp_overflow_init(desc); -#endif /* MEMP_OVERFLOW_CHECK */ #endif /* !MEMP_MEM_MALLOC */ #if MEMP_STATS From 55d05092ef0108f3181dc4eb824243f1c9dbb0e3 Mon Sep 17 00:00:00 2001 From: goldsimon Date: Fri, 19 Aug 2016 12:24:26 +0200 Subject: [PATCH 133/325] simplify memp.c code a bit --- src/core/memp.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/core/memp.c b/src/core/memp.c index f78db10f..626bc641 100644 --- a/src/core/memp.c +++ b/src/core/memp.c @@ -237,17 +237,14 @@ memp_init_pool(const struct memp_desc *desc) #endif ); } -#endif /* !MEMP_MEM_MALLOC */ - #if MEMP_STATS -#if !MEMP_MEM_MALLOC desc->stats->avail = desc->num; +#endif /* MEMP_STATS */ #endif /* !MEMP_MEM_MALLOC */ -#if defined(LWIP_DEBUG) || LWIP_STATS_DISPLAY +#if MEMP_STATS && (defined(LWIP_DEBUG) || LWIP_STATS_DISPLAY) desc->stats->name = desc->desc; -#endif /* defined(LWIP_DEBUG) || LWIP_STATS_DISPLAY */ -#endif /* MEMP_STATS */ +#endif /* MEMP_STATS && (defined(LWIP_DEBUG) || LWIP_STATS_DISPLAY) */ } /** From ed566cceaa522b0183d3fb4a9a2de148a23380d9 Mon Sep 17 00:00:00 2001 From: goldsimon Date: Fri, 19 Aug 2016 12:49:02 +0200 Subject: [PATCH 134/325] minor cleaup in (eth)arp --- src/core/ipv4/etharp.c | 7 +------ src/include/lwip/etharp.h | 12 ------------ src/include/lwip/prot/arp.h | 13 +++++++++++++ 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/core/ipv4/etharp.c b/src/core/ipv4/etharp.c index 2b3e9ca7..8020f346 100644 --- a/src/core/ipv4/etharp.c +++ b/src/core/ipv4/etharp.c @@ -72,8 +72,6 @@ */ #define ARP_MAXPENDING 5 -#define HWTYPE_ETHERNET 1 - enum etharp_state { ETHARP_STATE_EMPTY = 0, ETHARP_STATE_PENDING, @@ -1246,10 +1244,7 @@ etharp_query(struct netif *netif, const ip4_addr_t *ipaddr, struct pbuf *q) * ERR_MEM if the ARP packet couldn't be allocated * any other err_t on failure */ -#if !LWIP_AUTOIP -static -#endif /* LWIP_AUTOIP */ -err_t +static err_t etharp_raw(struct netif *netif, const struct eth_addr *ethsrc_addr, const struct eth_addr *ethdst_addr, const struct eth_addr *hwsrc_addr, const ip4_addr_t *ipsrc_addr, diff --git a/src/include/lwip/etharp.h b/src/include/lwip/etharp.h index 6b629d37..389cf9c4 100644 --- a/src/include/lwip/etharp.h +++ b/src/include/lwip/etharp.h @@ -70,10 +70,6 @@ extern "C" { /** 1 seconds period */ #define ARP_TMR_INTERVAL 1000 -/** ARP message types (opcodes) */ -#define ARP_REQUEST 1 -#define ARP_REPLY 2 - #if ARP_QUEUEING /** struct for queueing outgoing packets for unknown address * defined here to be accessed by memp.h @@ -105,14 +101,6 @@ err_t etharp_add_static_entry(const ip4_addr_t *ipaddr, struct eth_addr *ethaddr err_t etharp_remove_static_entry(const ip4_addr_t *ipaddr); #endif /* ETHARP_SUPPORT_STATIC_ENTRIES */ -#if LWIP_AUTOIP -err_t etharp_raw(struct netif *netif, const struct eth_addr *ethsrc_addr, - const struct eth_addr *ethdst_addr, - const struct eth_addr *hwsrc_addr, const ip4_addr_t *ipsrc_addr, - const struct eth_addr *hwdst_addr, const ip4_addr_t *ipdst_addr, - const u16_t opcode); -#endif /* LWIP_AUTOIP */ - #endif /* LWIP_IPV4 && LWIP_ARP */ void etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr, struct pbuf *p); diff --git a/src/include/lwip/prot/arp.h b/src/include/lwip/prot/arp.h index 8e32df50..382c6a92 100644 --- a/src/include/lwip/prot/arp.h +++ b/src/include/lwip/prot/arp.h @@ -72,6 +72,19 @@ PACK_STRUCT_END #define SIZEOF_ETHARP_HDR 28 +/* ARP hwtype values */ +enum etharp_hwtype { + HWTYPE_ETHERNET = 1 + /* others not used */ +}; + +/* ARP message types (opcodes) */ +enum etharp_opcode { + ARP_REQUEST = 1, + ARP_REPLY = 2 +}; + + #ifdef __cplusplus } #endif From 6688033bc462f04ac3348d1da341008b9e08c6c3 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Fri, 19 Aug 2016 12:50:41 +0200 Subject: [PATCH 135/325] Move IGMP protocol struct to prot/igmp.h --- src/core/ipv4/igmp.c | 43 +---------------- src/include/lwip/prot/igmp.h | 89 ++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 42 deletions(-) create mode 100644 src/include/lwip/prot/igmp.h diff --git a/src/core/ipv4/igmp.c b/src/core/ipv4/igmp.c index 90a80d38..94397274 100644 --- a/src/core/ipv4/igmp.c +++ b/src/core/ipv4/igmp.c @@ -92,49 +92,10 @@ Steve Reynolds #include "lwip/inet_chksum.h" #include "lwip/netif.h" #include "lwip/stats.h" +#include "lwip/prot/igmp.h" #include "string.h" -/* - * IGMP constants - */ -#define IGMP_TTL 1 -#define IGMP_MINLEN 8 -#define ROUTER_ALERT 0x9404U -#define ROUTER_ALERTLEN 4 - -/* - * IGMP message types, including version number. - */ -#define IGMP_MEMB_QUERY 0x11 /* Membership query */ -#define IGMP_V1_MEMB_REPORT 0x12 /* Ver. 1 membership report */ -#define IGMP_V2_MEMB_REPORT 0x16 /* Ver. 2 membership report */ -#define IGMP_LEAVE_GROUP 0x17 /* Leave-group message */ - -/* Group membership states */ -#define IGMP_GROUP_NON_MEMBER 0 -#define IGMP_GROUP_DELAYING_MEMBER 1 -#define IGMP_GROUP_IDLE_MEMBER 2 - -/** - * IGMP packet format. - */ -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/bpstruct.h" -#endif -PACK_STRUCT_BEGIN -struct igmp_msg { - PACK_STRUCT_FLD_8(u8_t igmp_msgtype); - PACK_STRUCT_FLD_8(u8_t igmp_maxresp); - PACK_STRUCT_FIELD(u16_t igmp_checksum); - PACK_STRUCT_FLD_S(ip4_addr_p_t igmp_group_address); -} PACK_STRUCT_STRUCT; -PACK_STRUCT_END -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/epstruct.h" -#endif - - static struct igmp_group *igmp_lookup_group(struct netif *ifp, const ip4_addr_t *addr); static err_t igmp_remove_group(struct igmp_group *group); static void igmp_timeout( struct igmp_group *group); @@ -143,12 +104,10 @@ static void igmp_delaying_member(struct igmp_group *group, u8_t maxresp); static err_t igmp_ip_output_if(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest, struct netif *netif); static void igmp_send(struct igmp_group *group, u8_t type); - static struct igmp_group* igmp_group_list; static ip4_addr_t allsystems; static ip4_addr_t allrouters; - /** * Initialize the IGMP module */ diff --git a/src/include/lwip/prot/igmp.h b/src/include/lwip/prot/igmp.h new file mode 100644 index 00000000..6e26b2c5 --- /dev/null +++ b/src/include/lwip/prot/igmp.h @@ -0,0 +1,89 @@ +/** + * @file + * UDP protocol definitions + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_HDR_PROT_IGMP_H +#define LWIP_HDR_PROT_IGMP_H + +#include "lwip/arch.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * IGMP constants + */ +#define IGMP_TTL 1 +#define IGMP_MINLEN 8 +#define ROUTER_ALERT 0x9404U +#define ROUTER_ALERTLEN 4 + +/* + * IGMP message types, including version number. + */ +#define IGMP_MEMB_QUERY 0x11 /* Membership query */ +#define IGMP_V1_MEMB_REPORT 0x12 /* Ver. 1 membership report */ +#define IGMP_V2_MEMB_REPORT 0x16 /* Ver. 2 membership report */ +#define IGMP_LEAVE_GROUP 0x17 /* Leave-group message */ + +/* Group membership states */ +#define IGMP_GROUP_NON_MEMBER 0 +#define IGMP_GROUP_DELAYING_MEMBER 1 +#define IGMP_GROUP_IDLE_MEMBER 2 + +/** + * IGMP packet format. + */ +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +struct igmp_msg { + PACK_STRUCT_FLD_8(u8_t igmp_msgtype); + PACK_STRUCT_FLD_8(u8_t igmp_maxresp); + PACK_STRUCT_FIELD(u16_t igmp_checksum); + PACK_STRUCT_FLD_S(ip4_addr_p_t igmp_group_address); +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_PROT_IGMP_H */ From 01d8e5013f58fd265b309b9f58de4291b607fe9a Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Fri, 19 Aug 2016 13:02:17 +0200 Subject: [PATCH 136/325] Add missing include in prot/igmp.h --- src/include/lwip/prot/igmp.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/include/lwip/prot/igmp.h b/src/include/lwip/prot/igmp.h index 6e26b2c5..bdc3bf24 100644 --- a/src/include/lwip/prot/igmp.h +++ b/src/include/lwip/prot/igmp.h @@ -38,6 +38,7 @@ #define LWIP_HDR_PROT_IGMP_H #include "lwip/arch.h" +#include "lwip/ip4_addr.h" #ifdef __cplusplus extern "C" { From 5e36815867dec8757ad7f1e386061d90874832ad Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Fri, 19 Aug 2016 13:05:51 +0200 Subject: [PATCH 137/325] init.c: Implement check for correct implementation of struct packing in lwip port --- src/core/init.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/core/init.c b/src/core/init.c index 182aaff7..3e39f9d5 100644 --- a/src/core/init.c +++ b/src/core/init.c @@ -61,6 +61,25 @@ #include "netif/ppp/ppp_opts.h" #include "netif/ppp/ppp_impl.h" +#ifndef LWIP_SKIP_PACKING_CHECK + +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +struct packed_struct_test +{ + PACK_STRUCT_FLD_8(u8_t dummy1); + PACK_STRUCT_FIELD(u32_t dummy2); +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif +#define PACKED_STRUCT_TEST_EXPECTED_SIZE 5 + +#endif + /* Compile-time sanity checks for configuration errors. * These can be done independently of LWIP_DEBUG, without penalty. */ @@ -323,6 +342,10 @@ void lwip_init(void) { +#ifndef LWIP_SKIP_PACKING_CHECK + LWIP_ASSERT("Struct packing not implemented correctly. Check your lwIP port.", sizeof(struct packed_struct_test) == PACKED_STRUCT_TEST_EXPECTED_SIZE); +#endif + /* Modules initialization */ stats_init(); #if !NO_SYS From f93a6e3310332120969603998800bccf9a7c2d5d Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Fri, 19 Aug 2016 13:09:58 +0200 Subject: [PATCH 138/325] Rename lwip/prot/arp.h to lwip/prot/etharp.h for consistence --- src/include/lwip/etharp.h | 2 +- src/include/lwip/prot/{arp.h => etharp.h} | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) rename src/include/lwip/prot/{arp.h => etharp.h} (96%) diff --git a/src/include/lwip/etharp.h b/src/include/lwip/etharp.h index 389cf9c4..04a56e65 100644 --- a/src/include/lwip/etharp.h +++ b/src/include/lwip/etharp.h @@ -58,7 +58,7 @@ extern "C" { #if LWIP_IPV4 && LWIP_ARP /* don't build if not configured for use in lwipopts.h */ -#include "lwip/prot/arp.h" +#include "lwip/prot/etharp.h" #define SIZEOF_ETHARP_PACKET (SIZEOF_ETH_HDR + SIZEOF_ETHARP_HDR) #if ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET) diff --git a/src/include/lwip/prot/arp.h b/src/include/lwip/prot/etharp.h similarity index 96% rename from src/include/lwip/prot/arp.h rename to src/include/lwip/prot/etharp.h index 382c6a92..ec78305b 100644 --- a/src/include/lwip/prot/arp.h +++ b/src/include/lwip/prot/etharp.h @@ -34,8 +34,8 @@ * Author: Adam Dunkels * */ -#ifndef LWIP_HDR_PROT_ARP_H -#define LWIP_HDR_PROT_ARP_H +#ifndef LWIP_HDR_PROT_ETHARP_H +#define LWIP_HDR_PROT_ETHARP_H #include "lwip/arch.h" #include "lwip/prot/ethernet.h" @@ -84,9 +84,8 @@ enum etharp_opcode { ARP_REPLY = 2 }; - #ifdef __cplusplus } #endif -#endif /* LWIP_HDR_PROT_ARP_H */ +#endif /* LWIP_HDR_PROT_ETHARP_H */ From a189941da6c9df9bbf9e04f26660ca53f23ee493 Mon Sep 17 00:00:00 2001 From: goldsimon Date: Fri, 19 Aug 2016 13:10:19 +0200 Subject: [PATCH 139/325] make igmp/mld6 filter actions an enum and define them in netif.h where the callback function prototypes are defined --- src/include/lwip/igmp.h | 7 ------- src/include/lwip/mld6.h | 5 ----- src/include/lwip/netif.h | 20 ++++++++++++++++++-- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/include/lwip/igmp.h b/src/include/lwip/igmp.h index 292e5c3b..cc312238 100644 --- a/src/include/lwip/igmp.h +++ b/src/include/lwip/igmp.h @@ -51,18 +51,11 @@ extern "C" { #endif - /* IGMP timer */ #define IGMP_TMR_INTERVAL 100 /* Milliseconds */ #define IGMP_V1_DELAYING_MEMBER_TMR (1000/IGMP_TMR_INTERVAL) #define IGMP_JOIN_DELAYING_MEMBER_TMR (500 /IGMP_TMR_INTERVAL) -/* MAC Filter Actions, these are passed to a netif's - * igmp_mac_filter callback function. */ -#define IGMP_DEL_MAC_FILTER 0 -#define IGMP_ADD_MAC_FILTER 1 - - /** * igmp group structure - there is * a list of groups for each interface diff --git a/src/include/lwip/mld6.h b/src/include/lwip/mld6.h index 000053be..089974ae 100644 --- a/src/include/lwip/mld6.h +++ b/src/include/lwip/mld6.h @@ -74,11 +74,6 @@ struct mld_group { #define MLD6_TMR_INTERVAL 100 /* Milliseconds */ -/* MAC Filter Actions, these are passed to a netif's - * mld_mac_filter callback function. */ -#define MLD6_DEL_MAC_FILTER 0 -#define MLD6_ADD_MAC_FILTER 1 - err_t mld6_stop(struct netif *netif); void mld6_report_groups(struct netif *netif); void mld6_tmr(void); diff --git a/src/include/lwip/netif.h b/src/include/lwip/netif.h index 593c3af4..f316116a 100644 --- a/src/include/lwip/netif.h +++ b/src/include/lwip/netif.h @@ -181,15 +181,31 @@ typedef err_t (*netif_output_ip6_fn)(struct netif *netif, struct pbuf *p, typedef err_t (*netif_linkoutput_fn)(struct netif *netif, struct pbuf *p); /** Function prototype for netif status- or link-callback functions. */ typedef void (*netif_status_callback_fn)(struct netif *netif); + #if LWIP_IPV4 && LWIP_IGMP +/** MAC Filter Actions, these are passed to a netif's igmp_mac_filter callback function. */ +enum netif_igmp_filter_action { + /** Delete a filter entry */ + IGMP_DEL_MAC_FILTER = 0, + /** Add a filter entry */ + IGMP_ADD_MAC_FILTER = 1 +}; /** Function prototype for netif igmp_mac_filter functions */ typedef err_t (*netif_igmp_mac_filter_fn)(struct netif *netif, - const ip4_addr_t *group, u8_t action); + const ip4_addr_t *group, enum netif_igmp_filter_action action); #endif /* LWIP_IPV4 && LWIP_IGMP */ + #if LWIP_IPV6 && LWIP_IPV6_MLD +/** MAC Filter Actions, these are passed to a netif's mld_mac_filter callback function. */ +enum netif_mld6_filter_action { + /** Delete a filter entry */ + MLD6_DEL_MAC_FILTER = 0, + /** Add a filter entry */ + MLD6_ADD_MAC_FILTER = 1 +}; /** Function prototype for netif mld_mac_filter functions */ typedef err_t (*netif_mld_mac_filter_fn)(struct netif *netif, - const ip6_addr_t *group, u8_t action); + const ip6_addr_t *group, enum netif_mld6_filter_action action); #endif /* LWIP_IPV6 && LWIP_IPV6_MLD */ /** Generic data structure used for all lwIP network interfaces. From 730080f20e656b8fae99cfac20ab9f9d08353a6a Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Fri, 19 Aug 2016 13:15:23 +0200 Subject: [PATCH 140/325] Fix doxygen comment in lwip/prot/igmp.h --- src/include/lwip/prot/igmp.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/include/lwip/prot/igmp.h b/src/include/lwip/prot/igmp.h index bdc3bf24..d60cb31e 100644 --- a/src/include/lwip/prot/igmp.h +++ b/src/include/lwip/prot/igmp.h @@ -1,6 +1,6 @@ /** * @file - * UDP protocol definitions + * IGMP protocol definitions */ /* From b3bae1b44c4f892a3adef35912630d78f93d265a Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Fri, 19 Aug 2016 16:34:12 +0800 Subject: [PATCH 141/325] memp: Fix unused variable build error when MEMP_SANITY_REGION_BEFORE/AFTER is 0 MEMP_SANITY_REGION_BEFORE and MEMP_SANITY_REGION_AFTER can be overridden in lwipopts.h, if one of it is set to 0 we got build error due to unused variable. Fix unused variable build error when MEMP_OVERFLOW_CHECK >= 1 && (MEMP_SANITY_REGION_BEFORE == 0 || MEMP_SANITY_REGION_AFTER == 0). Signed-off-by: Axel Lin Signed-off-by: goldsimon --- src/core/memp.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/core/memp.c b/src/core/memp.c index 626bc641..94559922 100644 --- a/src/core/memp.c +++ b/src/core/memp.c @@ -124,9 +124,9 @@ memp_sanity(const struct memp_desc *desc) static void memp_overflow_check_element_overflow(struct memp *p, const struct memp_desc *desc) { +#if MEMP_SANITY_REGION_AFTER_ALIGNED > 0 u16_t k; u8_t *m; -#if MEMP_SANITY_REGION_AFTER_ALIGNED > 0 m = (u8_t*)p + MEMP_SIZE + desc->size; for (k = 0; k < MEMP_SANITY_REGION_AFTER_ALIGNED; k++) { if (m[k] != 0xcd) { @@ -135,7 +135,10 @@ memp_overflow_check_element_overflow(struct memp *p, const struct memp_desc *des LWIP_ASSERT(errstr, 0); } } -#endif +#else /* MEMP_SANITY_REGION_AFTER_ALIGNED > 0 */ + LWIP_UNUSED_ARG(p); + LWIP_UNUSED_ARG(desc); +#endif /* MEMP_SANITY_REGION_AFTER_ALIGNED > 0 */ } /** @@ -148,9 +151,9 @@ memp_overflow_check_element_overflow(struct memp *p, const struct memp_desc *des static void memp_overflow_check_element_underflow(struct memp *p, const struct memp_desc *desc) { +#if MEMP_SANITY_REGION_BEFORE_ALIGNED > 0 u16_t k; u8_t *m; -#if MEMP_SANITY_REGION_BEFORE_ALIGNED > 0 m = (u8_t*)p + MEMP_SIZE - MEMP_SANITY_REGION_BEFORE_ALIGNED; for (k = 0; k < MEMP_SANITY_REGION_BEFORE_ALIGNED; k++) { if (m[k] != 0xcd) { @@ -159,7 +162,10 @@ memp_overflow_check_element_underflow(struct memp *p, const struct memp_desc *de LWIP_ASSERT(errstr, 0); } } -#endif +#else /* MEMP_SANITY_REGION_BEFORE_ALIGNED > 0 */ + LWIP_UNUSED_ARG(p); + LWIP_UNUSED_ARG(desc); +#endif /* MEMP_SANITY_REGION_BEFORE_ALIGNED > 0 */ } /** @@ -168,6 +174,7 @@ memp_overflow_check_element_underflow(struct memp *p, const struct memp_desc *de static void memp_overflow_init_element(struct memp *p, const struct memp_desc *desc) { +#if MEMP_SANITY_REGION_BEFORE_ALIGNED > 0 || MEMP_SANITY_REGION_AFTER_ALIGNED > 0 u8_t *m; #if MEMP_SANITY_REGION_BEFORE_ALIGNED > 0 m = (u8_t*)p + MEMP_SIZE - MEMP_SANITY_REGION_BEFORE_ALIGNED; @@ -177,6 +184,10 @@ memp_overflow_init_element(struct memp *p, const struct memp_desc *desc) m = (u8_t*)p + MEMP_SIZE + desc->size; memset(m, 0xcd, MEMP_SANITY_REGION_AFTER_ALIGNED); #endif +#else /* MEMP_SANITY_REGION_BEFORE_ALIGNED > 0 || MEMP_SANITY_REGION_AFTER_ALIGNED > 0 */ + LWIP_UNUSED_ARG(p); + LWIP_UNUSED_ARG(desc); +#endif /* MEMP_SANITY_REGION_BEFORE_ALIGNED > 0 || MEMP_SANITY_REGION_AFTER_ALIGNED > 0 */ } #if MEMP_OVERFLOW_CHECK >= 2 From 6b1e1af3d19c28f26519460531f28b23d4f6e1f0 Mon Sep 17 00:00:00 2001 From: goldsimon Date: Fri, 19 Aug 2016 13:54:14 +0200 Subject: [PATCH 142/325] combine MAC filter actions for IGMP and MLD6 (IGMP has compatibility defines for old code, MLD6 filter functions must be adapted) --- src/core/ipv4/igmp.c | 8 ++++---- src/core/ipv6/mld6.c | 6 +++--- src/include/lwip/igmp.h | 4 ++++ src/include/lwip/netif.h | 29 +++++++++++------------------ src/netif/ethernetif.c | 2 +- 5 files changed, 23 insertions(+), 26 deletions(-) diff --git a/src/core/ipv4/igmp.c b/src/core/ipv4/igmp.c index 94397274..164a3bf1 100644 --- a/src/core/ipv4/igmp.c +++ b/src/core/ipv4/igmp.c @@ -143,7 +143,7 @@ igmp_start(struct netif *netif) LWIP_DEBUGF(IGMP_DEBUG, ("igmp_start: igmp_mac_filter(ADD ")); ip4_addr_debug_print_val(IGMP_DEBUG, allsystems); LWIP_DEBUGF(IGMP_DEBUG, (") on if %p\n", (void*)netif)); - netif->igmp_mac_filter(netif, &allsystems, IGMP_ADD_MAC_FILTER); + netif->igmp_mac_filter(netif, &allsystems, NETIF_ADD_MAC_FILTER); } return ERR_OK; @@ -182,7 +182,7 @@ igmp_stop(struct netif *netif) LWIP_DEBUGF(IGMP_DEBUG, ("igmp_stop: igmp_mac_filter(DEL ")); ip4_addr_debug_print(IGMP_DEBUG, &group->group_address); LWIP_DEBUGF(IGMP_DEBUG, (") on if %p\n", (void*)netif)); - netif->igmp_mac_filter(netif, &(group->group_address), IGMP_DEL_MAC_FILTER); + netif->igmp_mac_filter(netif, &(group->group_address), NETIF_DEL_MAC_FILTER); } /* free group */ memp_free(MEMP_IGMP_GROUP, group); @@ -513,7 +513,7 @@ igmp_joingroup_netif(struct netif *netif, const ip4_addr_t *groupaddr) LWIP_DEBUGF(IGMP_DEBUG, ("igmp_joingroup_netif: igmp_mac_filter(ADD ")); ip4_addr_debug_print(IGMP_DEBUG, groupaddr); LWIP_DEBUGF(IGMP_DEBUG, (") on if %p\n", (void*)netif)); - netif->igmp_mac_filter(netif, groupaddr, IGMP_ADD_MAC_FILTER); + netif->igmp_mac_filter(netif, groupaddr, NETIF_ADD_MAC_FILTER); } IGMP_STATS_INC(igmp.tx_join); @@ -613,7 +613,7 @@ igmp_leavegroup_netif(struct netif *netif, const ip4_addr_t *groupaddr) LWIP_DEBUGF(IGMP_DEBUG, ("igmp_leavegroup_netif: igmp_mac_filter(DEL ")); ip4_addr_debug_print(IGMP_DEBUG, groupaddr); LWIP_DEBUGF(IGMP_DEBUG, (") on if %p\n", (void*)netif)); - netif->igmp_mac_filter(netif, groupaddr, IGMP_DEL_MAC_FILTER); + netif->igmp_mac_filter(netif, groupaddr, NETIF_DEL_MAC_FILTER); } LWIP_DEBUGF(IGMP_DEBUG, ("igmp_leavegroup_netif: remove group: ")); diff --git a/src/core/ipv6/mld6.c b/src/core/ipv6/mld6.c index f5e07ec4..9ae44c06 100644 --- a/src/core/ipv6/mld6.c +++ b/src/core/ipv6/mld6.c @@ -114,7 +114,7 @@ mld6_stop(struct netif *netif) } /* disable the group at the MAC level */ if (netif->mld_mac_filter != NULL) { - netif->mld_mac_filter(netif, &(group->group_address), MLD6_DEL_MAC_FILTER); + netif->mld_mac_filter(netif, &(group->group_address), NETIF_DEL_MAC_FILTER); } /* free group */ memp_free(MEMP_MLD6_GROUP, group); @@ -373,7 +373,7 @@ mld6_joingroup_netif(struct netif *netif, const ip6_addr_t *groupaddr) /* Activate this address on the MAC layer. */ if (netif->mld_mac_filter != NULL) { - netif->mld_mac_filter(netif, groupaddr, MLD6_ADD_MAC_FILTER); + netif->mld_mac_filter(netif, groupaddr, NETIF_ADD_MAC_FILTER); } /* Report our membership. */ @@ -448,7 +448,7 @@ mld6_leavegroup_netif(struct netif *netif, const ip6_addr_t *groupaddr) /* Disable the group at the MAC level */ if (netif->mld_mac_filter != NULL) { - netif->mld_mac_filter(netif, groupaddr, MLD6_DEL_MAC_FILTER); + netif->mld_mac_filter(netif, groupaddr, NETIF_DEL_MAC_FILTER); } /* Free the group */ diff --git a/src/include/lwip/igmp.h b/src/include/lwip/igmp.h index cc312238..be78c332 100644 --- a/src/include/lwip/igmp.h +++ b/src/include/lwip/igmp.h @@ -56,6 +56,10 @@ extern "C" { #define IGMP_V1_DELAYING_MEMBER_TMR (1000/IGMP_TMR_INTERVAL) #define IGMP_JOIN_DELAYING_MEMBER_TMR (500 /IGMP_TMR_INTERVAL) +/* Compatibility defines (don't use for new code) */ +#define IGMP_DEL_MAC_FILTER NETIF_DEL_MAC_FILTER +#define IGMP_ADD_MAC_FILTER NETIF_ADD_MAC_FILTER + /** * igmp group structure - there is * a list of groups for each interface diff --git a/src/include/lwip/netif.h b/src/include/lwip/netif.h index f316116a..1f11551b 100644 --- a/src/include/lwip/netif.h +++ b/src/include/lwip/netif.h @@ -132,6 +132,15 @@ enum lwip_internal_netif_client_data_index struct netif; +/** MAC Filter Actions, these are passed to a netif's igmp_mac_filter or + * mld_mac_filter callback function. */ +enum netif_mac_filter_action { + /** Delete a filter entry */ + NETIF_DEL_MAC_FILTER = 0, + /** Add a filter entry */ + NETIF_ADD_MAC_FILTER = 1 +}; + /** Function prototype for netif init functions. Set up flags and output/linkoutput * callback functions in this function. * @@ -181,31 +190,15 @@ typedef err_t (*netif_output_ip6_fn)(struct netif *netif, struct pbuf *p, typedef err_t (*netif_linkoutput_fn)(struct netif *netif, struct pbuf *p); /** Function prototype for netif status- or link-callback functions. */ typedef void (*netif_status_callback_fn)(struct netif *netif); - #if LWIP_IPV4 && LWIP_IGMP -/** MAC Filter Actions, these are passed to a netif's igmp_mac_filter callback function. */ -enum netif_igmp_filter_action { - /** Delete a filter entry */ - IGMP_DEL_MAC_FILTER = 0, - /** Add a filter entry */ - IGMP_ADD_MAC_FILTER = 1 -}; /** Function prototype for netif igmp_mac_filter functions */ typedef err_t (*netif_igmp_mac_filter_fn)(struct netif *netif, - const ip4_addr_t *group, enum netif_igmp_filter_action action); + const ip4_addr_t *group, enum netif_mac_filter_action action); #endif /* LWIP_IPV4 && LWIP_IGMP */ - #if LWIP_IPV6 && LWIP_IPV6_MLD -/** MAC Filter Actions, these are passed to a netif's mld_mac_filter callback function. */ -enum netif_mld6_filter_action { - /** Delete a filter entry */ - MLD6_DEL_MAC_FILTER = 0, - /** Add a filter entry */ - MLD6_ADD_MAC_FILTER = 1 -}; /** Function prototype for netif mld_mac_filter functions */ typedef err_t (*netif_mld_mac_filter_fn)(struct netif *netif, - const ip6_addr_t *group, enum netif_mld6_filter_action action); + const ip6_addr_t *group, enum netif_mac_filter_action action); #endif /* LWIP_IPV6 && LWIP_IPV6_MLD */ /** Generic data structure used for all lwIP network interfaces. diff --git a/src/netif/ethernetif.c b/src/netif/ethernetif.c index c873c8c8..dc8ae6c4 100644 --- a/src/netif/ethernetif.c +++ b/src/netif/ethernetif.c @@ -110,7 +110,7 @@ low_level_init(struct netif *netif) if (netif->mld_mac_filter != NULL) { ip6_addr_t ip6_allnodes_ll; ip6_addr_set_allnodes_linklocal(&ip6_allnodes_ll); - netif->mld_mac_filter(netif, &ip6_allnodes_ll, MLD6_ADD_MAC_FILTER); + netif->mld_mac_filter(netif, &ip6_allnodes_ll, NETIF_ADD_MAC_FILTER); } #endif /* LWIP_IPV6 && LWIP_IPV6_MLD */ From 4f4d16260f735c1bd9a8ff5396b5018a5c26d906 Mon Sep 17 00:00:00 2001 From: goldsimon Date: Fri, 19 Aug 2016 15:40:36 +0200 Subject: [PATCH 143/325] minor: fixed typo --- src/core/tcp_out.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/tcp_out.c b/src/core/tcp_out.c index 610cbd83..7e1803fe 100644 --- a/src/core/tcp_out.c +++ b/src/core/tcp_out.c @@ -1379,7 +1379,7 @@ tcp_rexmit_rto(struct tcp_pcb *pcb) /** * Requeue the first unacked segment for retransmission * - * Called by tcp_receive() for fast retramsmit. + * Called by tcp_receive() for fast retransmit. * * @param pcb the tcp_pcb for which to retransmit the first unacked segment */ From a032ccafe7d414ce3e317ff78320d695f5701ac0 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Fri, 19 Aug 2016 20:54:25 +0800 Subject: [PATCH 144/325] mem: Fix trivial comment typo about using custom pools Signed-off-by: Axel Lin --- src/core/mem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/mem.c b/src/core/mem.c index a3003758..3a53fb5f 100644 --- a/src/core/mem.c +++ b/src/core/mem.c @@ -9,7 +9,7 @@ * * To let mem_malloc() use pools (prevents fragmentation and is much faster than * a heap but might waste some memory), define MEM_USE_POOLS to 1, define - * MEM_USE_CUSTOM_POOLS to 1 and create a file "lwippools.h" that includes a list + * MEMP_USE_CUSTOM_POOLS to 1 and create a file "lwippools.h" that includes a list * of pools like this (more pools can be added between _START and _END): * * Define three pools with sizes 256, 512, and 1512 bytes From 21c99b6ebb9d4b250ec3e29c59e6af6a16d1fb4a Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Sat, 20 Aug 2016 09:23:29 +0200 Subject: [PATCH 145/325] Add documentation page about example lwIP ports. Start with FreeRTOS from Pavel Pisa. --- doc/doxygen/main_page.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/doxygen/main_page.h b/doc/doxygen/main_page.h index 6486a17d..bdb177a3 100644 --- a/doc/doxygen/main_page.h +++ b/doc/doxygen/main_page.h @@ -38,6 +38,11 @@ * https://savannah.nongnu.org/bugs/?group=lwip */ +/** + * @page ports Example ports + * - RTEMS and FreeRTOS: https://sourceforge.net/p/ulan/lwip-omk/ci/omk-devel/tree/ports/os/ + */ + /** * @defgroup lwip_nosys Mainloop mode ("NO_SYS") * @ingroup lwip From 40f2bed5c4763d70efa5c794c656e5de59f85a15 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Fri, 19 Aug 2016 19:08:08 +0800 Subject: [PATCH 146/325] mem: Simplify the code for try bigger pool in mem_malloc Signed-off-by: Axel Lin Signed-off-by: sg --- src/core/mem.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/src/core/mem.c b/src/core/mem.c index 3a53fb5f..40f4cb9e 100644 --- a/src/core/mem.c +++ b/src/core/mem.c @@ -167,12 +167,21 @@ mem_malloc(mem_size_t size) mem_size_t required_size = size + LWIP_MEM_ALIGN_SIZE(sizeof(struct memp_malloc_helper)); for (poolnr = MEMP_POOL_FIRST; poolnr <= MEMP_POOL_LAST; poolnr = (memp_t)(poolnr + 1)) { -#if MEM_USE_POOLS_TRY_BIGGER_POOL -again: -#endif /* MEM_USE_POOLS_TRY_BIGGER_POOL */ /* is this pool big enough to hold an element of the required size plus a struct memp_malloc_helper that saves the pool this element came from? */ if (required_size <= memp_pools[poolnr]->size) { + element = (struct memp_malloc_helper*)memp_malloc(poolnr); + if (element == NULL) { + /* No need to DEBUGF or ASSERT: This error is already taken care of in memp.c */ +#if MEM_USE_POOLS_TRY_BIGGER_POOL + /** Try a bigger pool if this one is empty! */ + if (poolnr < MEMP_POOL_LAST) { + continue; + } +#endif /* MEM_USE_POOLS_TRY_BIGGER_POOL */ + MEM_STATS_INC(err); + return NULL; + } break; } } @@ -181,20 +190,6 @@ again: MEM_STATS_INC(err); return NULL; } - element = (struct memp_malloc_helper*)memp_malloc(poolnr); - if (element == NULL) { - /* No need to DEBUGF or ASSERT: This error is already - taken care of in memp.c */ -#if MEM_USE_POOLS_TRY_BIGGER_POOL - /** Try a bigger pool if this one is empty! */ - if (poolnr < MEMP_POOL_LAST) { - poolnr++; - goto again; - } -#endif /* MEM_USE_POOLS_TRY_BIGGER_POOL */ - MEM_STATS_INC(err); - return NULL; - } /* save the pool number this element came from */ element->poolnr = poolnr; From 1c5c96a50a0caad8f50463646947443db580b174 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Mon, 22 Aug 2016 23:09:57 +0800 Subject: [PATCH 147/325] pbuf: Use SYS_ARCH_INC in pbuf_ref() Use SYS_ARCH_INC to simplify the code. Signed-off-by: Axel Lin Signed-off-by: goldsimon --- src/core/pbuf.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/core/pbuf.c b/src/core/pbuf.c index 671397cd..c290e492 100644 --- a/src/core/pbuf.c +++ b/src/core/pbuf.c @@ -766,12 +766,9 @@ pbuf_clen(struct pbuf *p) void pbuf_ref(struct pbuf *p) { - SYS_ARCH_DECL_PROTECT(old_level); /* pbuf given? */ if (p != NULL) { - SYS_ARCH_PROTECT(old_level); - ++(p->ref); - SYS_ARCH_UNPROTECT(old_level); + SYS_ARCH_INC(p->ref, 1); } } From 42c193821cf8cdd8ae09362c3e00fd2fde480540 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Mon, 22 Aug 2016 22:08:34 +0800 Subject: [PATCH 148/325] netbuf: Use memset to zero the allocated memory for netbuf_new Use memset to zero the allocated memory rather than explicitly init each field. Signed-off-by: Axel Lin Signed-off-by: goldsimon --- src/api/netbuf.c | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/src/api/netbuf.c b/src/api/netbuf.c index 50625167..8d2cd1b7 100644 --- a/src/api/netbuf.c +++ b/src/api/netbuf.c @@ -66,23 +66,9 @@ netbuf *netbuf_new(void) buf = (struct netbuf *)memp_malloc(MEMP_NETBUF); if (buf != NULL) { - buf->p = NULL; - buf->ptr = NULL; - ip_addr_set_zero(&buf->addr); - buf->port = 0; -#if LWIP_NETBUF_RECVINFO || LWIP_CHECKSUM_ON_COPY -#if LWIP_CHECKSUM_ON_COPY - buf->flags = 0; -#endif /* LWIP_CHECKSUM_ON_COPY */ - buf->toport_chksum = 0; -#if LWIP_NETBUF_RECVINFO - ip_addr_set_zero(&buf->toaddr); -#endif /* LWIP_NETBUF_RECVINFO */ -#endif /* LWIP_NETBUF_RECVINFO || LWIP_CHECKSUM_ON_COPY */ - return buf; - } else { - return NULL; + memset(buf, 0, sizeof(struct netbuf)); } + return buf; } /** From d9eaf6f310709caca58f6107713e383bdb40b7fe Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Tue, 23 Aug 2016 09:34:14 +0200 Subject: [PATCH 149/325] docs: Remove link to example ports again, this should rather go to lwIP wiki... --- doc/doxygen/main_page.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/doc/doxygen/main_page.h b/doc/doxygen/main_page.h index bdb177a3..6486a17d 100644 --- a/doc/doxygen/main_page.h +++ b/doc/doxygen/main_page.h @@ -38,11 +38,6 @@ * https://savannah.nongnu.org/bugs/?group=lwip */ -/** - * @page ports Example ports - * - RTEMS and FreeRTOS: https://sourceforge.net/p/ulan/lwip-omk/ci/omk-devel/tree/ports/os/ - */ - /** * @defgroup lwip_nosys Mainloop mode ("NO_SYS") * @ingroup lwip From 18136c047bc36934c868af9b779bffa217014cd0 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Tue, 23 Aug 2016 10:15:03 +0200 Subject: [PATCH 150/325] Work on bug #48824: ethernet.c extensions: Implement ethernet_output(); Fixes bug #48862: ethip6 does not support setting vlan --- src/core/ipv4/etharp.c | 69 +++--------------------------------- src/core/ipv6/ethip6.c | 39 ++------------------ src/include/netif/ethernet.h | 1 + src/netif/ethernet.c | 58 ++++++++++++++++++++++++++++++ 4 files changed, 67 insertions(+), 100 deletions(-) diff --git a/src/core/ipv4/etharp.c b/src/core/ipv4/etharp.c index 8020f346..3119504e 100644 --- a/src/core/ipv4/etharp.c +++ b/src/core/ipv4/etharp.c @@ -393,47 +393,6 @@ etharp_find_entry(const ip4_addr_t *ipaddr, u8_t flags, struct netif* netif) return (err_t)i; } -/** - * Send an IP packet on the network using netif->linkoutput - * The ethernet header is filled in before sending. - * - * @params netif the lwIP network interface on which to send the packet - * @params p the packet to send, p->payload pointing to the (uninitialized) ethernet header - * @params src the source MAC address to be copied into the ethernet header - * @params dst the destination MAC address to be copied into the ethernet header - * @return ERR_OK if the packet was sent, any other err_t on failure - */ -static err_t -etharp_send_ip(struct netif *netif, struct pbuf *p, struct eth_addr *src, const struct eth_addr *dst) -{ - struct eth_hdr *ethhdr = (struct eth_hdr *)p->payload; -#if ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET) - struct eth_vlan_hdr *vlanhdr; -#endif /* ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET) */ - - LWIP_ASSERT("netif->hwaddr_len must be the same as ETH_HWADDR_LEN for etharp!", - (netif->hwaddr_len == ETH_HWADDR_LEN)); -#if ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET) - ethhdr->type = PP_HTONS(ETHTYPE_VLAN); - vlanhdr = (struct eth_vlan_hdr*)(((u8_t*)ethhdr) + SIZEOF_ETH_HDR); - vlanhdr->prio_vid = 0; - vlanhdr->tpid = PP_HTONS(ETHTYPE_IP); - if (!LWIP_HOOK_VLAN_SET(netif, ethhdr, vlanhdr)) { - /* packet shall not contain VLAN header, so hide it and set correct ethertype */ - pbuf_header(p, -SIZEOF_VLAN_HDR); - ethhdr = (struct eth_hdr *)p->payload; -#endif /* ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET) */ - ethhdr->type = PP_HTONS(ETHTYPE_IP); -#if ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET) - } -#endif /* ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET) */ - ETHADDR32_COPY(ðhdr->dest, dst); - ETHADDR16_COPY(ðhdr->src, src); - LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_send_ip: sending packet %p\n", (void *)p)); - /* send the packet */ - return netif->linkoutput(netif, p); -} - /** * Update (or insert) a IP/MAC address pair in the ARP cache. * @@ -517,7 +476,7 @@ etharp_update_arp_entry(struct netif *netif, const ip4_addr_t *ipaddr, struct et arp_table[i].q = NULL; #endif /* ARP_QUEUEING */ /* send the queued IP packet */ - etharp_send_ip(netif, p, (struct eth_addr*)(netif->hwaddr), ethaddr); + ethernet_output(netif, p, (struct eth_addr*)(netif->hwaddr), ethaddr, ETHTYPE_IP); /* free the queued IP packet */ pbuf_free(p); } @@ -898,8 +857,7 @@ etharp_output_to_arp_index(struct netif *netif, struct pbuf *q, u8_t arp_idx) } } - return etharp_send_ip(netif, q, (struct eth_addr*)(netif->hwaddr), - &arp_table[arp_idx].ethaddr); + return ethernet_output(netif, q, (struct eth_addr*)(netif->hwaddr), &arp_table[arp_idx].ethaddr, ETHTYPE_IP); } /** @@ -931,19 +889,6 @@ etharp_output(struct netif *netif, struct pbuf *q, const ip4_addr_t *ipaddr) LWIP_ASSERT("q != NULL", q != NULL); LWIP_ASSERT("ipaddr != NULL", ipaddr != NULL); - /* make room for Ethernet header - should not fail */ -#if ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET) - if (pbuf_header(q, sizeof(struct eth_hdr) + SIZEOF_VLAN_HDR) != 0) { -#else /* ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET) */ - if (pbuf_header(q, sizeof(struct eth_hdr)) != 0) { -#endif /* ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET) */ - /* bail out */ - LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_SERIOUS, - ("etharp_output: could not allocate room for header.\n")); - LINK_STATS_INC(link.lenerr); - return ERR_BUF; - } - /* Determine on destination hardware address. Broadcasts and multicasts * are special, other IP addresses are looked up in the ARP table. */ @@ -970,11 +915,7 @@ etharp_output(struct netif *netif, struct pbuf *q, const ip4_addr_t *ipaddr) if (!ip4_addr_netcmp(ipaddr, netif_ip4_addr(netif), netif_ip4_netmask(netif)) && !ip4_addr_islinklocal(ipaddr)) { #if LWIP_AUTOIP - struct ip_hdr *iphdr = (struct ip_hdr*)((u8_t*)q->payload + -#if ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET) - SIZEOF_VLAN_HDR + -#endif /* ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET) */ - sizeof(struct eth_hdr)); + struct ip_hdr *iphdr = (struct ip_hdr*)(size_t)q->payload; /* According to RFC 3297, chapter 2.6.2 (Forwarding Rules), a packet with a link-local source address must always be "directly to its destination on the same physical link. The host MUST NOT send the packet to any @@ -1036,7 +977,7 @@ etharp_output(struct netif *netif, struct pbuf *q, const ip4_addr_t *ipaddr) /* continuation for multicast/broadcast destinations */ /* obtain source Ethernet address of the given interface */ /* send packet directly on the link */ - return etharp_send_ip(netif, q, (struct eth_addr*)(netif->hwaddr), dest); + return ethernet_output(netif, q, (struct eth_addr*)(netif->hwaddr), dest, ETHTYPE_IP); } /** @@ -1136,7 +1077,7 @@ etharp_query(struct netif *netif, const ip4_addr_t *ipaddr, struct pbuf *q) /* we have a valid IP->Ethernet address mapping */ ETHARP_SET_HINT(netif, i); /* send the packet */ - result = etharp_send_ip(netif, q, srcaddr, &(arp_table[i].ethaddr)); + result = ethernet_output(netif, q, srcaddr, &(arp_table[i].ethaddr), ETHTYPE_IP); /* pending entry? (either just created or already pending */ } else if (arp_table[i].state == ETHARP_STATE_PENDING) { /* entry is still pending, queue the given packet 'q' */ diff --git a/src/core/ipv6/ethip6.c b/src/core/ipv6/ethip6.c index b3a3cafb..751cf037 100644 --- a/src/core/ipv6/ethip6.c +++ b/src/core/ipv6/ethip6.c @@ -52,34 +52,10 @@ #include "lwip/netif.h" #include "lwip/icmp6.h" #include "lwip/prot/ethernet.h" +#include "netif/ethernet.h" #include -/** - * Send an IPv6 packet on the network using netif->linkoutput - * The ethernet header is filled in before sending. - * - * @params netif the lwIP network interface on which to send the packet - * @params p the packet to send, p->payload pointing to the (uninitialized) ethernet header - * @params src the source MAC address to be copied into the ethernet header - * @params dst the destination MAC address to be copied into the ethernet header - * @return ERR_OK if the packet was sent, any other err_t on failure - */ -static err_t -ethip6_send(struct netif *netif, struct pbuf *p, struct eth_addr *src, struct eth_addr *dst) -{ - struct eth_hdr *ethhdr = (struct eth_hdr *)p->payload; - - LWIP_ASSERT("netif->hwaddr_len must be 6 for ethip6!", - (netif->hwaddr_len == 6)); - SMEMCPY(ðhdr->dest, dst, 6); - SMEMCPY(ðhdr->src, src, 6); - ethhdr->type = PP_HTONS(ETHTYPE_IPV6); - LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("ethip6_send: sending packet %p\n", (void *)p)); - /* send the packet */ - return netif->linkoutput(netif, p); -} - /** * Resolve and fill-in Ethernet address header for outgoing IPv6 packet. * @@ -104,14 +80,6 @@ ethip6_output(struct netif *netif, struct pbuf *q, const ip6_addr_t *ip6addr) struct eth_addr dest; s8_t i; - /* make room for Ethernet header - should not fail */ - if (pbuf_header(q, sizeof(struct eth_hdr)) != 0) { - /* bail out */ - LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_SERIOUS, - ("etharp_output: could not allocate room for header.\n")); - return ERR_BUF; - } - /* multicast destination IP address? */ if (ip6_addr_ismulticast(ip6addr)) { /* Hash IP multicast address to MAC address.*/ @@ -123,7 +91,7 @@ ethip6_output(struct netif *netif, struct pbuf *q, const ip6_addr_t *ip6addr) dest.addr[5] = ((const u8_t *)(&(ip6addr->addr[3])))[3]; /* Send out. */ - return ethip6_send(netif, q, (struct eth_addr*)(netif->hwaddr), &dest); + return ethernet_output(netif, q, (struct eth_addr*)(netif->hwaddr), &dest, ETHTYPE_IPV6); } /* We have a unicast destination IP address */ @@ -148,11 +116,10 @@ ethip6_output(struct netif *netif, struct pbuf *q, const ip6_addr_t *ip6addr) /* Send out. */ SMEMCPY(dest.addr, neighbor_cache[i].lladdr, 6); - return ethip6_send(netif, q, (struct eth_addr*)(netif->hwaddr), &dest); + return ethernet_output(netif, q, (struct eth_addr*)(netif->hwaddr), &dest, ETHTYPE_IPV6); } /* We should queue packet on this interface. */ - pbuf_header(q, -(s16_t)SIZEOF_ETH_HDR); return nd6_queue_packet(i, q); } diff --git a/src/include/netif/ethernet.h b/src/include/netif/ethernet.h index ec961c4d..49649cbf 100644 --- a/src/include/netif/ethernet.h +++ b/src/include/netif/ethernet.h @@ -64,6 +64,7 @@ extern "C" { #endif err_t ethernet_input(struct pbuf *p, struct netif *netif); +err_t ethernet_output(struct netif* netif, struct pbuf* p, const struct eth_addr* src, const struct eth_addr* dst, u16_t eth_type); extern const struct eth_addr ethbroadcast, ethzero; diff --git a/src/netif/ethernet.c b/src/netif/ethernet.c index 26e360af..57c3f117 100644 --- a/src/netif/ethernet.c +++ b/src/netif/ethernet.c @@ -222,4 +222,62 @@ free_and_return: pbuf_free(p); return ERR_OK; } + +/** + * Send an ethernet packet on the network using netif->linkoutput + * The ethernet header is filled in before sending. + * + * @params netif the lwIP network interface on which to send the packet + * @params p the packet to send, p->payload pointing to the (uninitialized) ethernet header + * @params src the source MAC address to be copied into the ethernet header + * @params dst the destination MAC address to be copied into the ethernet header + * @params eth_type ethernet type + * @return ERR_OK if the packet was sent, any other err_t on failure + */ +err_t +ethernet_output(struct netif* netif, struct pbuf* p, const struct eth_addr* src, const struct eth_addr* dst, u16_t eth_type) +{ + struct eth_hdr *ethhdr; +#if ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET) + struct eth_vlan_hdr *vlanhdr; +#endif /* ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET) */ + + LWIP_ASSERT("netif->hwaddr_len must be 6 for ethernet_send!", (netif->hwaddr_len == ETH_HWADDR_LEN)); + +#if ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET) + if (pbuf_header(p, sizeof(struct eth_hdr) + SIZEOF_VLAN_HDR) != 0) { +#else /* ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET) */ + if (pbuf_header(p, sizeof(struct eth_hdr)) != 0) { +#endif /* ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET) */ + LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_SERIOUS, + ("ethernet_send: could not allocate room for header.\n")); + LINK_STATS_INC(link.lenerr); + return ERR_BUF; + } + ethhdr = (struct eth_hdr *)p->payload; + +#if ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET) + ethhdr->type = PP_HTONS(ETHTYPE_VLAN); + vlanhdr = (struct eth_vlan_hdr*)(((u8_t*)ethhdr) + SIZEOF_ETH_HDR); + vlanhdr->prio_vid = 0; + vlanhdr->tpid = ntohs(eth_type); + if (!LWIP_HOOK_VLAN_SET(netif, ethhdr, vlanhdr)) { + /* packet shall not contain VLAN header, so hide it and set correct ethertype */ + pbuf_header(p, -SIZEOF_VLAN_HDR); + ethhdr = (struct eth_hdr *)p->payload; +#endif /* ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET) */ + ethhdr->type = ntohs(eth_type); +#if ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET) + } +#endif /* ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET) */ + + ETHADDR32_COPY(ðhdr->dest, dst); + ETHADDR16_COPY(ðhdr->src, src); + + LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("ethernet_send: sending packet %p\n", (void *)p)); + + /* send the packet */ + return netif->linkoutput(netif, p); +} + #endif /* LWIP_ARP || LWIP_ETHERNET */ From bae4d6398cd2d9f473b5274b1e7375757445d73f Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Tue, 23 Aug 2016 10:23:59 +0200 Subject: [PATCH 151/325] Fix some comments to reference ethernet_output now --- src/core/ipv4/etharp.c | 2 +- src/core/ipv6/ethip6.c | 2 +- src/include/lwip/opt.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/ipv4/etharp.c b/src/core/ipv4/etharp.c index 3119504e..5288b744 100644 --- a/src/core/ipv4/etharp.c +++ b/src/core/ipv4/etharp.c @@ -876,7 +876,7 @@ etharp_output_to_arp_index(struct netif *netif, struct pbuf *q, u8_t arp_idx) * * @return * - ERR_RTE No route to destination (no gateway to external networks), - * or the return type of either etharp_query() or etharp_send_ip(). + * or the return type of either etharp_query() or ethernet_output(). */ err_t etharp_output(struct netif *netif, struct pbuf *q, const ip4_addr_t *ipaddr) diff --git a/src/core/ipv6/ethip6.c b/src/core/ipv6/ethip6.c index 751cf037..1ae784f8 100644 --- a/src/core/ipv6/ethip6.c +++ b/src/core/ipv6/ethip6.c @@ -72,7 +72,7 @@ * * @return * - ERR_RTE No route to destination (no gateway to external networks), - * or the return type of either etharp_query() or etharp_send_ip(). + * or the return type of either etharp_query() or ethernet_output(). */ err_t ethip6_output(struct netif *netif, struct pbuf *q, const ip6_addr_t *ip6addr) diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h index 17ba18d2..71a465f0 100644 --- a/src/include/lwip/opt.h +++ b/src/include/lwip/opt.h @@ -2509,7 +2509,7 @@ /** * LWIP_HOOK_VLAN_SET(netif, eth_hdr, vlan_hdr): - * - called from etharp_raw() and etharp_send_ip() if VLAN support is enabled + * - called from etharp_raw() and ethernet_output() if VLAN support is enabled * - netif: struct netif that the packet will be sent through * - eth_hdr: struct eth_hdr of the packet * - vlan_hdr: struct eth_vlan_hdr of the packet From f170dde1c656f1603b055af25973abc6328ab5b1 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Tue, 23 Aug 2016 10:48:38 +0200 Subject: [PATCH 152/325] Work on bug #48824: ethernet.c extensions: Implement hook for unknown ethernet protocols --- src/include/lwip/opt.h | 9 +++++++++ src/netif/ethernet.c | 15 +++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h index 71a465f0..1abdf294 100644 --- a/src/include/lwip/opt.h +++ b/src/include/lwip/opt.h @@ -2529,6 +2529,15 @@ #ifdef __DOXYGEN__ #define LWIP_HOOK_MEMP_AVAILABLE(memp_t_type) #endif + +/** + * LWIP_HOOK_UNKNOWN_ETH_PROTOCOL(pbuf, netif): + * Called from ethernet_input() when an unknown eth type is encountered. + * Return ERR_OK if packet is accepted, any error code otherwise. + */ +#ifdef __DOXYGEN__ +#define LWIP_HOOK_UNKNOWN_ETH_PROTOCOL(pbuf, netif) +#endif /** * @} */ diff --git a/src/netif/ethernet.c b/src/netif/ethernet.c index 57c3f117..b84fcdc7 100644 --- a/src/netif/ethernet.c +++ b/src/netif/ethernet.c @@ -208,10 +208,17 @@ ethernet_input(struct pbuf *p, struct netif *netif) #endif /* LWIP_IPV6 */ default: - ETHARP_STATS_INC(etharp.proterr); - ETHARP_STATS_INC(etharp.drop); - MIB2_STATS_NETIF_INC(netif, ifinunknownprotos); - goto free_and_return; +#ifdef LWIP_HOOK_UNKNOWN_ETH_PROTOCOL + if(LWIP_HOOK_UNKNOWN_ETH_PROTOCOL(p, netif) != ERR_OK) { +#endif + ETHARP_STATS_INC(etharp.proterr); + ETHARP_STATS_INC(etharp.drop); + MIB2_STATS_NETIF_INC(netif, ifinunknownprotos); + goto free_and_return; +#ifdef LWIP_HOOK_UNKNOWN_ETH_PROTOCOL + } + break; +#endif } /* This means the pbuf is freed or consumed, From 4456c7d230d91ac60401db02e15178fe0636007d Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Tue, 23 Aug 2016 12:32:57 +0200 Subject: [PATCH 153/325] Fix regression in etharp.c: Allocate correct pbuf layer --- src/core/ipv4/etharp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/ipv4/etharp.c b/src/core/ipv4/etharp.c index 5288b744..42485d17 100644 --- a/src/core/ipv4/etharp.c +++ b/src/core/ipv4/etharp.c @@ -1097,7 +1097,7 @@ etharp_query(struct netif *netif, const ip4_addr_t *ipaddr, struct pbuf *q) } if (copy_needed) { /* copy the whole packet into new pbufs */ - p = pbuf_alloc(PBUF_RAW_TX, p->tot_len, PBUF_RAM); + p = pbuf_alloc(PBUF_LINK, p->tot_len, PBUF_RAM); if (p != NULL) { if (pbuf_copy(p, q) != ERR_OK) { pbuf_free(p); From 0d5eea288c3a7d9df626c67acd87addf279d54d5 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Tue, 23 Aug 2016 12:54:29 +0200 Subject: [PATCH 154/325] Clarify LWIP_HOOK_UNKNOWN_ETH_PROTOCOL in opt.h --- src/include/lwip/opt.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h index 1abdf294..3c405e75 100644 --- a/src/include/lwip/opt.h +++ b/src/include/lwip/opt.h @@ -2534,6 +2534,7 @@ * LWIP_HOOK_UNKNOWN_ETH_PROTOCOL(pbuf, netif): * Called from ethernet_input() when an unknown eth type is encountered. * Return ERR_OK if packet is accepted, any error code otherwise. + * Payload points to ethernet header! */ #ifdef __DOXYGEN__ #define LWIP_HOOK_UNKNOWN_ETH_PROTOCOL(pbuf, netif) From fc54556d80eb9498d76db85087952a341b0ece9b Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Tue, 23 Aug 2016 12:55:21 +0200 Subject: [PATCH 155/325] Code beautification in LWIP_HOOK_UNKNOWN_ETH_PROTOCOL usage --- src/netif/ethernet.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/netif/ethernet.c b/src/netif/ethernet.c index b84fcdc7..73a5a4e8 100644 --- a/src/netif/ethernet.c +++ b/src/netif/ethernet.c @@ -209,16 +209,14 @@ ethernet_input(struct pbuf *p, struct netif *netif) default: #ifdef LWIP_HOOK_UNKNOWN_ETH_PROTOCOL - if(LWIP_HOOK_UNKNOWN_ETH_PROTOCOL(p, netif) != ERR_OK) { -#endif - ETHARP_STATS_INC(etharp.proterr); - ETHARP_STATS_INC(etharp.drop); - MIB2_STATS_NETIF_INC(netif, ifinunknownprotos); - goto free_and_return; -#ifdef LWIP_HOOK_UNKNOWN_ETH_PROTOCOL + if(LWIP_HOOK_UNKNOWN_ETH_PROTOCOL(p, netif) == ERR_OK) { + break; } - break; #endif + ETHARP_STATS_INC(etharp.proterr); + ETHARP_STATS_INC(etharp.drop); + MIB2_STATS_NETIF_INC(netif, ifinunknownprotos); + goto free_and_return; } /* This means the pbuf is freed or consumed, From d99d91dae97cdc76fdde28e5e3cf04b1c198a27e Mon Sep 17 00:00:00 2001 From: goldsimon Date: Tue, 23 Aug 2016 13:00:15 +0200 Subject: [PATCH 156/325] removed ETHARP_TRUST_IP_MAC since it is insecure and we don't need it any more after implementing unicast ARP renewal towards arp entry timeout --- CHANGELOG | 4 ++++ src/core/ipv4/etharp.c | 50 --------------------------------------- src/include/lwip/etharp.h | 1 - src/include/lwip/opt.h | 14 ----------- src/netif/ethernet.c | 4 ---- 5 files changed, 4 insertions(+), 69 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 39177b8f..8f030fde 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -328,6 +328,10 @@ HISTORY ++ Bugfixes: + 2016-08-23: Simon Goldschmidt + * etharp: removed ETHARP_TRUST_IP_MAC since it is insecure and we don't need + it any more after implementing unicast ARP renewal towards arp entry timeout + 2016-07-20: Simon Goldschmidt * memp.h/.c: fixed bug #48442 (memp stats don't work for MEMP_MEM_MALLOC) diff --git a/src/core/ipv4/etharp.c b/src/core/ipv4/etharp.c index 42485d17..789ac19f 100644 --- a/src/core/ipv4/etharp.c +++ b/src/core/ipv4/etharp.c @@ -616,56 +616,6 @@ etharp_get_entry(u8_t i, ip4_addr_t **ipaddr, struct netif **netif, struct eth_a } } -#if ETHARP_TRUST_IP_MAC -/** - * Updates the ARP table using the given IP packet. - * - * Uses the incoming IP packet's source address to update the - * ARP cache for the local network. The function does not alter - * or free the packet. This function must be called before the - * packet p is passed to the IP layer. - * - * @param netif The lwIP network interface on which the IP packet pbuf arrived. - * @param p The IP packet that arrived on netif. - * - * @return NULL - * - * @see pbuf_free() - */ -void -etharp_ip_input(struct netif *netif, struct pbuf *p) -{ - struct eth_hdr *ethhdr; - struct ip_hdr *iphdr; - ip4_addr_t iphdr_src; - LWIP_ERROR("netif != NULL", (netif != NULL), return;); - - /* Only insert an entry if the source IP address of the - incoming IP packet comes from a host on the local network. */ - ethhdr = (struct eth_hdr *)p->payload; - iphdr = (struct ip_hdr *)((u8_t*)ethhdr + SIZEOF_ETH_HDR); -#if ETHARP_SUPPORT_VLAN - if (ethhdr->type == PP_HTONS(ETHTYPE_VLAN)) { - iphdr = (struct ip_hdr *)((u8_t*)ethhdr + SIZEOF_ETH_HDR + SIZEOF_VLAN_HDR); - } -#endif /* ETHARP_SUPPORT_VLAN */ - - ip4_addr_copy(iphdr_src, iphdr->src); - - /* source is not on the local network? */ - if (!ip4_addr_netcmp(&iphdr_src, netif_ip4_addr(netif), netif_ip4_netmask(netif))) { - /* do nothing */ - return; - } - - LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_ip_input: updating ETHARP table.\n")); - /* update the source IP address in the cache, if present */ - /* @todo We could use ETHARP_FLAG_TRY_HARD if we think we are going to talk - * back soon (for example, if the destination IP address is ours. */ - etharp_update_arp_entry(netif, &iphdr_src, &(ethhdr->src), ETHARP_FLAG_FIND_ONLY); -} -#endif /* ETHARP_TRUST_IP_MAC */ - /** * Responds to ARP requests to us. Upon ARP replies to us, add entry to cache * send out queued IP packets. Updates cache with snooped address pairs. diff --git a/src/include/lwip/etharp.h b/src/include/lwip/etharp.h index 04a56e65..249b5c25 100644 --- a/src/include/lwip/etharp.h +++ b/src/include/lwip/etharp.h @@ -94,7 +94,6 @@ err_t etharp_request(struct netif *netif, const ip4_addr_t *ipaddr); * From RFC 3220 "IP Mobility Support for IPv4" section 4.6. */ #define etharp_gratuitous(netif) etharp_request((netif), netif_ip4_addr(netif)) void etharp_cleanup_netif(struct netif *netif); -void etharp_ip_input(struct netif *netif, struct pbuf *p); #if ETHARP_SUPPORT_STATIC_ENTRIES err_t etharp_add_static_entry(const ip4_addr_t *ipaddr, struct eth_addr *ethaddr); diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h index 3c405e75..85d45821 100644 --- a/src/include/lwip/opt.h +++ b/src/include/lwip/opt.h @@ -576,20 +576,6 @@ #define ARP_QUEUE_LEN 3 #endif -/** - * ETHARP_TRUST_IP_MAC==1: Incoming IP packets cause the ARP table to be - * updated with the source MAC and IP addresses supplied in the packet. - * You may want to disable this if you do not trust LAN peers to have the - * correct addresses, or as a limited approach to attempt to handle - * spoofing. If disabled, lwIP will need to make a new ARP request if - * the peer is not already in the ARP table, adding a little latency. - * The peer *is* in the ARP table if it requested our address before. - * Also notice that this slows down input processing of every IP packet! - */ -#if !defined ETHARP_TRUST_IP_MAC || defined __DOXYGEN__ -#define ETHARP_TRUST_IP_MAC 0 -#endif - /** * ETHARP_SUPPORT_VLAN==1: support receiving and sending ethernet packets with * VLAN header. See the description of LWIP_HOOK_VLAN_CHECK and diff --git a/src/netif/ethernet.c b/src/netif/ethernet.c index 73a5a4e8..9e9610c8 100644 --- a/src/netif/ethernet.c +++ b/src/netif/ethernet.c @@ -157,10 +157,6 @@ ethernet_input(struct pbuf *p, struct netif *netif) if (!(netif->flags & NETIF_FLAG_ETHARP)) { goto free_and_return; } -#if ETHARP_TRUST_IP_MAC - /* update ARP table */ - etharp_ip_input(netif, p); -#endif /* ETHARP_TRUST_IP_MAC */ /* skip Ethernet header */ if ((p->len < ip_hdr_offset) || pbuf_header(p, (s16_t)-ip_hdr_offset)) { LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_WARNING, From 306171c93ba748ce6a593f9715a7fbbaac58a7bc Mon Sep 17 00:00:00 2001 From: goldsimon Date: Tue, 23 Aug 2016 15:25:39 +0200 Subject: [PATCH 157/325] DHCP: fixed compiling LWIP_DHCP_BOOTP_FILE==1 --- src/core/ipv4/dhcp.c | 7 ++++--- src/include/lwip/dhcp.h | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/core/ipv4/dhcp.c b/src/core/ipv4/dhcp.c index 041699d6..d9ee38ed 100644 --- a/src/core/ipv4/dhcp.c +++ b/src/core/ipv4/dhcp.c @@ -615,7 +615,7 @@ dhcp_handle_ack(struct netif *netif) #if LWIP_DHCP_BOOTP_FILE /* copy boot server address, boot file name copied in dhcp_parse_reply if not overloaded */ - ip_addr_copy(dhcp->offered_si_addr, dhcp->msg_in->siaddr); + ip4_addr_copy(dhcp->offered_si_addr, dhcp->msg_in->siaddr); #endif /* LWIP_DHCP_BOOTP_FILE */ /* subnet mask given? */ @@ -1415,14 +1415,15 @@ dhcp_option_hostname(struct dhcp *dhcp, struct netif *netif) if (netif->hostname != NULL) { size_t namelen = strlen(netif->hostname); if (namelen > 0) { - u8_t len; + size_t len; const char *p = netif->hostname; /* Shrink len to available bytes (need 2 bytes for OPTION_HOSTNAME and 1 byte for trailer) */ size_t available = DHCP_OPTIONS_LEN - dhcp->options_out_len - 3; LWIP_ASSERT("DHCP: hostname is too long!", namelen <= available); len = LWIP_MIN(namelen, available); - dhcp_option(dhcp, DHCP_OPTION_HOSTNAME, len); + LWIP_ASSERT("DHCP: hostname is too long!", len <= 0xFF); + dhcp_option(dhcp, DHCP_OPTION_HOSTNAME, (u8_t)len); while (len--) { dhcp_option_byte(dhcp, *p++); } diff --git a/src/include/lwip/dhcp.h b/src/include/lwip/dhcp.h index 220342b3..f7503280 100644 --- a/src/include/lwip/dhcp.h +++ b/src/include/lwip/dhcp.h @@ -100,7 +100,7 @@ struct dhcp u32_t offered_t1_renew; /* recommended renew time (usually 50% of lease period) */ u32_t offered_t2_rebind; /* recommended rebind time (usually 87.5 of lease period) */ #if LWIP_DHCP_BOOTP_FILE - ip_addr_t offered_si_addr; + ip4_addr_t offered_si_addr; char boot_file_name[DHCP_BOOT_FILE_LEN]; #endif /* LWIP_DHCP_BOOTPFILE */ }; From fd5b34ae430acd212f09383801dd4a9ee0a17e6a Mon Sep 17 00:00:00 2001 From: goldsimon Date: Tue, 23 Aug 2016 15:26:05 +0200 Subject: [PATCH 158/325] ip4_forward(): fixed compiling IP_FORWARD_ALLOW_TX_ON_RX_NETIF==1 --- src/core/ipv4/ip4.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/core/ipv4/ip4.c b/src/core/ipv4/ip4.c index fb51d221..27747ea7 100644 --- a/src/core/ipv4/ip4.c +++ b/src/core/ipv4/ip4.c @@ -267,6 +267,7 @@ ip4_forward(struct pbuf *p, struct ip_hdr *iphdr, struct netif *inp) struct netif *netif; PERF_START; + LWIP_UNUSED_ARG(inp); if (!ip4_canforward(p)) { goto return_noroute; From e4c74109cdf3122ef8ff84b00b75254b08d09282 Mon Sep 17 00:00:00 2001 From: goldsimon Date: Tue, 23 Aug 2016 15:50:48 +0200 Subject: [PATCH 159/325] fixed bug #47652: there is always a delay to send the first Neighbor Solicitation for the new add INCOMPLETE state neighbor entry --- src/core/ipv6/nd6.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/core/ipv6/nd6.c b/src/core/ipv6/nd6.c index d56d4e92..6c47dbca 100644 --- a/src/core/ipv6/nd6.c +++ b/src/core/ipv6/nd6.c @@ -102,6 +102,7 @@ static s8_t nd6_new_onlink_prefix(ip6_addr_t *prefix, struct netif *netif); #define ND6_SEND_FLAG_ALLNODES_DEST 0x02 static void nd6_send_ns(struct netif *netif, const ip6_addr_t *target_addr, u8_t flags); static void nd6_send_na(struct netif *netif, const ip6_addr_t *target_addr, u8_t flags); +static void nd6_send_neighbor_cache_probe(struct nd6_neighbor_cache_entry *entry, u8_t flags); #if LWIP_IPV6_SEND_ROUTER_SOLICIT static err_t nd6_send_rs(struct netif *netif); #endif /* LWIP_IPV6_SEND_ROUTER_SOLICIT */ @@ -673,7 +674,7 @@ nd6_tmr(void) } else { /* Send a NS for this entry. */ neighbor_cache[i].counter.probes_sent++; - nd6_send_ns(neighbor_cache[i].netif, &(neighbor_cache[i].next_hop_address), ND6_SEND_FLAG_MULTICAST_DEST); + nd6_send_neighbor_cache_probe(&neighbor_cache[i], ND6_SEND_FLAG_MULTICAST_DEST); } break; case ND6_REACHABLE: @@ -709,7 +710,7 @@ nd6_tmr(void) } else { /* Send a NS for this entry. */ neighbor_cache[i].counter.probes_sent++; - nd6_send_ns(neighbor_cache[i].netif, &(neighbor_cache[i].next_hop_address), 0); + nd6_send_neighbor_cache_probe(&neighbor_cache[i], 0); } break; case ND6_NO_ENTRY: @@ -844,6 +845,17 @@ nd6_tmr(void) } +/** Send a neighbor solicitation message for a specific neighbor cache entry + * + * @param entry the neightbor cache entry for wich to send the message + * @param flags one of ND6_SEND_FLAG_* + */ +static void +nd6_send_neighbor_cache_probe(struct nd6_neighbor_cache_entry *entry, u8_t flags) +{ + nd6_send_ns(entry->netif, &entry->next_hop_address, flags); +} + /** * Send a neighbor solicitation message * @@ -1403,7 +1415,8 @@ nd6_new_router(const ip6_addr_t *router_addr, struct netif *netif) neighbor_cache[neighbor_index].netif = netif; neighbor_cache[neighbor_index].q = NULL; neighbor_cache[neighbor_index].state = ND6_INCOMPLETE; - neighbor_cache[neighbor_index].counter.probes_sent = 0; + neighbor_cache[neighbor_index].counter.probes_sent = 1; + nd6_send_neighbor_cache_probe(&neighbor_cache[neighbor_index], ND6_SEND_FLAG_MULTICAST_DEST); } /* Mark neighbor as router. */ @@ -1587,7 +1600,8 @@ nd6_get_next_hop_entry(const ip6_addr_t *ip6addr, struct netif *netif) neighbor_cache[i].isrouter = 0; neighbor_cache[i].netif = netif; neighbor_cache[i].state = ND6_INCOMPLETE; - neighbor_cache[i].counter.probes_sent = 0; + neighbor_cache[i].counter.probes_sent = 1; + nd6_send_neighbor_cache_probe(&neighbor_cache[i], ND6_SEND_FLAG_MULTICAST_DEST); } } From 56dc574bed85c1e6ef024619f0570de7ba43efb5 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Tue, 23 Aug 2016 16:07:48 +0200 Subject: [PATCH 160/325] Fix comment in pbuf layer description --- src/include/lwip/pbuf.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/include/lwip/pbuf.h b/src/include/lwip/pbuf.h index 82e51491..2ae22647 100644 --- a/src/include/lwip/pbuf.h +++ b/src/include/lwip/pbuf.h @@ -80,7 +80,7 @@ typedef enum { */ PBUF_IP, /** Includes spare room for link layer header (ethernet header). - * Use this if you intend to pass the pbuf to functions like ip_output(). + * Use this if you intend to pass the pbuf to functions like ethernet_output(). * @see @ref PBUF_LINK_HLEN */ PBUF_LINK, From d2f52e19d5065fe7d8133cf71c7f3ff42c36fafd Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Tue, 23 Aug 2016 16:09:32 +0200 Subject: [PATCH 161/325] Fix doxygen comment in ethernet.c --- src/netif/ethernet.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/netif/ethernet.c b/src/netif/ethernet.c index 9e9610c8..36ff762c 100644 --- a/src/netif/ethernet.c +++ b/src/netif/ethernet.c @@ -139,7 +139,7 @@ ethernet_input(struct pbuf *p, struct netif *netif) } #if LWIP_IPV6 else if ((ethhdr->dest.addr[0] == LL_IP6_MULTICAST_ADDR_0) && - (ethhdr->dest.addr[1] == LL_IP6_MULTICAST_ADDR_1)) { + (ethhdr->dest.addr[1] == LL_IP6_MULTICAST_ADDR_1)) { /* mark the pbuf as link-layer multicast */ p->flags |= PBUF_FLAG_LLMCAST; } @@ -228,11 +228,11 @@ free_and_return: * Send an ethernet packet on the network using netif->linkoutput * The ethernet header is filled in before sending. * - * @params netif the lwIP network interface on which to send the packet - * @params p the packet to send, p->payload pointing to the (uninitialized) ethernet header - * @params src the source MAC address to be copied into the ethernet header - * @params dst the destination MAC address to be copied into the ethernet header - * @params eth_type ethernet type + * @param netif the lwIP network interface on which to send the packet + * @param p the packet to send, p->payload pointing to the (uninitialized) ethernet header + * @param src the source MAC address to be copied into the ethernet header + * @param dst the destination MAC address to be copied into the ethernet header + * @param eth_type ethernet type * @return ERR_OK if the packet was sent, any other err_t on failure */ err_t From 979bee386c60fbd5f74a5e7bb3e2e25af35ef46e Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Tue, 23 Aug 2016 16:58:17 +0200 Subject: [PATCH 162/325] Work on bug #48868: Cleanup etharp.c not to use struct eth_hdr: Cleanup etharp_raw() to use ethernet_output() --- src/core/ipv4/etharp.c | 60 +++++++++++------------------------------- 1 file changed, 16 insertions(+), 44 deletions(-) diff --git a/src/core/ipv4/etharp.c b/src/core/ipv4/etharp.c index 789ac19f..8f56c70c 100644 --- a/src/core/ipv4/etharp.c +++ b/src/core/ipv4/etharp.c @@ -1144,19 +1144,12 @@ etharp_raw(struct netif *netif, const struct eth_addr *ethsrc_addr, { struct pbuf *p; err_t result = ERR_OK; - struct eth_hdr *ethhdr; -#if ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET) - struct eth_vlan_hdr *vlanhdr; -#endif /* ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET) */ struct etharp_hdr *hdr; -#if LWIP_AUTOIP - const u8_t * ethdst_hwaddr; -#endif /* LWIP_AUTOIP */ LWIP_ASSERT("netif != NULL", netif != NULL); /* allocate a pbuf for the outgoing ARP request packet */ - p = pbuf_alloc(PBUF_RAW_TX, SIZEOF_ETHARP_PACKET_TX, PBUF_RAM); + p = pbuf_alloc(PBUF_LINK, SIZEOF_ETHARP_PACKET_TX, PBUF_RAM); /* could allocate a pbuf for an ARP request? */ if (p == NULL) { LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_SERIOUS, @@ -1167,24 +1160,13 @@ etharp_raw(struct netif *netif, const struct eth_addr *ethsrc_addr, LWIP_ASSERT("check that first pbuf can hold struct etharp_hdr", (p->len >= SIZEOF_ETHARP_PACKET_TX)); - ethhdr = (struct eth_hdr *)p->payload; -#if ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET) - vlanhdr = (struct eth_vlan_hdr*)(((u8_t*)ethhdr) + SIZEOF_ETH_HDR); - hdr = (struct etharp_hdr *)((u8_t*)ethhdr + SIZEOF_ETH_HDR + SIZEOF_VLAN_HDR); -#else /* ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET) */ - hdr = (struct etharp_hdr *)((u8_t*)ethhdr + SIZEOF_ETH_HDR); -#endif /* ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET) */ + hdr = (struct etharp_hdr *)p->payload; LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_raw: sending raw ARP packet.\n")); hdr->opcode = htons(opcode); LWIP_ASSERT("netif->hwaddr_len must be the same as ETH_HWADDR_LEN for etharp!", (netif->hwaddr_len == ETH_HWADDR_LEN)); -#if LWIP_AUTOIP - /* If we are using Link-Local, all ARP packets that contain a Link-Local - * 'sender IP address' MUST be sent using link-layer broadcast instead of - * link-layer unicast. (See RFC3927 Section 2.5, last paragraph) */ - ethdst_hwaddr = ip4_addr_islinklocal(ipsrc_addr) ? (const u8_t*)(ethbroadcast.addr) : ethdst_addr->addr; -#endif /* LWIP_AUTOIP */ + /* Write the ARP MAC-Addresses */ ETHADDR16_COPY(&hdr->shwaddr, hwsrc_addr); ETHADDR16_COPY(&hdr->dhwaddr, hwdst_addr); @@ -1199,30 +1181,20 @@ etharp_raw(struct netif *netif, const struct eth_addr *ethsrc_addr, hdr->hwlen = ETH_HWADDR_LEN; hdr->protolen = sizeof(ip4_addr_t); -#if ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET) - ethhdr->type = PP_HTONS(ETHTYPE_VLAN); - vlanhdr->tpid = PP_HTONS(ETHTYPE_ARP); - vlanhdr->prio_vid = 0; - if (!LWIP_HOOK_VLAN_SET(netif, ethhdr, vlanhdr)) { - /* packet shall not contain VLAN header, so hide it and set correct ethertype */ - pbuf_header(p, -SIZEOF_VLAN_HDR); - ethhdr = (struct eth_hdr *)p->payload; -#endif /* ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET) */ - ethhdr->type = PP_HTONS(ETHTYPE_ARP); -#if ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET) - } -#endif /* ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET) */ - - /* Write the Ethernet MAC-Addresses */ -#if LWIP_AUTOIP - ETHADDR16_COPY(ðhdr->dest, ethdst_hwaddr); -#else /* LWIP_AUTOIP */ - ETHADDR16_COPY(ðhdr->dest, ethdst_addr); -#endif /* LWIP_AUTOIP */ - ETHADDR16_COPY(ðhdr->src, ethsrc_addr); - /* send ARP query */ - result = netif->linkoutput(netif, p); +#if LWIP_AUTOIP + /* If we are using Link-Local, all ARP packets that contain a Link-Local + * 'sender IP address' MUST be sent using link-layer broadcast instead of + * link-layer unicast. (See RFC3927 Section 2.5, last paragraph) */ + if(ip4_addr_islinklocal(ipsrc_addr)) { + ethernet_output(netif, p, ethsrc_addr, ðbroadcast, ETHTYPE_ARP); + } else { + ethernet_output(netif, p, ethsrc_addr, ethdst_addr, ETHTYPE_ARP); + } +#else /* LWIP_AUTOIP */ + ethernet_output(netif, p, ethsrc_addr, ethdst_addr, ETHTYPE_ARP); +#endif /* LWIP_AUTOIP */ + ETHARP_STATS_INC(etharp.xmit); /* free ARP query packet */ pbuf_free(p); From 6caa7b99272b118fdb1c6a89aec17df77c9905f0 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Tue, 23 Aug 2016 17:03:51 +0200 Subject: [PATCH 163/325] Cleanup etharp_arp_input() signature to match the sig of other input functions (pbuf, netif). Rename to etharp_input() --- src/core/ipv4/autoip.c | 2 +- src/core/ipv4/etharp.c | 25 ++++++++++++------------- src/include/lwip/etharp.h | 2 +- src/netif/ethernet.c | 2 +- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/core/ipv4/autoip.c b/src/core/ipv4/autoip.c index daa3eb9f..7b53ef1d 100644 --- a/src/core/ipv4/autoip.c +++ b/src/core/ipv4/autoip.c @@ -447,7 +447,7 @@ autoip_tmr(void) } /** - * Handles every incoming ARP Packet, called by etharp_arp_input. + * Handles every incoming ARP Packet, called by etharp_input(). * * @param netif network interface to use for autoip processing * @param hdr Incoming ARP packet diff --git a/src/core/ipv4/etharp.c b/src/core/ipv4/etharp.c index 8f56c70c..e0e1382f 100644 --- a/src/core/ipv4/etharp.c +++ b/src/core/ipv4/etharp.c @@ -623,16 +623,15 @@ etharp_get_entry(u8_t i, ip4_addr_t **ipaddr, struct netif **netif, struct eth_a * Should be called for incoming ARP packets. The pbuf in the argument * is freed by this function. * - * @param netif The lwIP network interface on which the ARP packet pbuf arrived. - * @param ethaddr Ethernet address of netif. * @param p The ARP packet that arrived on netif. Is freed by this function. + * @param netif The lwIP network interface on which the ARP packet pbuf arrived. * * @return NULL * * @see pbuf_free() */ void -etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr, struct pbuf *p) +etharp_input(struct pbuf *p, struct netif *netif) { struct etharp_hdr *hdr; struct eth_hdr *ethhdr; @@ -649,7 +648,7 @@ etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr, struct pbuf *p) since a struct etharp_hdr is pointed to p->payload, so it musn't be chained! */ if (p->len < SIZEOF_ETHARP_PACKET) { LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_WARNING, - ("etharp_arp_input: packet dropped, too short (%"S16_F"/%"S16_F")\n", p->tot_len, + ("etharp_input: packet dropped, too short (%"S16_F"/%"S16_F")\n", p->tot_len, (s16_t)SIZEOF_ETHARP_PACKET)); ETHARP_STATS_INC(etharp.lenerr); ETHARP_STATS_INC(etharp.drop); @@ -671,7 +670,7 @@ etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr, struct pbuf *p) (hdr->protolen != sizeof(ip4_addr_t)) || (hdr->proto != PP_HTONS(ETHTYPE_IP))) { LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_WARNING, - ("etharp_arp_input: packet dropped, wrong hw type, hwlen, proto, protolen or ethernet type (%"U16_F"/%"U16_F"/%"U16_F"/%"U16_F")\n", + ("etharp_input: packet dropped, wrong hw type, hwlen, proto, protolen or ethernet type (%"U16_F"/%"U16_F"/%"U16_F"/%"U16_F")\n", hdr->hwtype, (u16_t)hdr->hwlen, hdr->proto, (u16_t)hdr->protolen)); ETHARP_STATS_INC(etharp.proterr); ETHARP_STATS_INC(etharp.drop); @@ -716,11 +715,11 @@ etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr, struct pbuf *p) * reply. In any case, we time-stamp any existing ARP entry, * and possibly send out an IP packet that was queued on it. */ - LWIP_DEBUGF (ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_arp_input: incoming ARP request\n")); + LWIP_DEBUGF (ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_input: incoming ARP request\n")); /* ARP request for our address? */ if (for_us) { - LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_arp_input: replying to ARP request for our IP address\n")); + LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_input: replying to ARP request for our IP address\n")); /* Re-use pbuf to send ARP reply. Since we are re-using an existing pbuf, we can't call etharp_raw since that would allocate a new pbuf. */ @@ -744,8 +743,8 @@ etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr, struct pbuf *p) #else /* LWIP_AUTOIP */ ETHADDR16_COPY(ðhdr->dest, &hdr->shwaddr); #endif /* LWIP_AUTOIP */ - ETHADDR16_COPY(&hdr->shwaddr, ethaddr); - ETHADDR16_COPY(ðhdr->src, ethaddr); + ETHADDR16_COPY(&hdr->shwaddr, netif->hwaddr); + ETHADDR16_COPY(ðhdr->src, netif->hwaddr); /* hwtype, hwaddr_len, proto, protolen and the type in the ethernet header are already correct, we tested that before */ @@ -755,16 +754,16 @@ etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr, struct pbuf *p) /* we are not configured? */ } else if (ip4_addr_isany_val(*netif_ip4_addr(netif))) { /* { for_us == 0 and netif->ip_addr.addr == 0 } */ - LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_arp_input: we are unconfigured, ARP request ignored.\n")); + LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_input: we are unconfigured, ARP request ignored.\n")); /* request was not directed to us */ } else { /* { for_us == 0 and netif->ip_addr.addr != 0 } */ - LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_arp_input: ARP request was not for us.\n")); + LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_input: ARP request was not for us.\n")); } break; case PP_HTONS(ARP_REPLY): /* ARP reply. We already updated the ARP cache earlier. */ - LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_arp_input: incoming ARP reply\n")); + LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_input: incoming ARP reply\n")); #if (LWIP_DHCP && DHCP_DOES_ARP_CHECK) /* DHCP wants to know about ARP replies from any host with an * IP address also offered to us by the DHCP server. We do not @@ -774,7 +773,7 @@ etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr, struct pbuf *p) #endif /* (LWIP_DHCP && DHCP_DOES_ARP_CHECK) */ break; default: - LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_arp_input: ARP unknown opcode type %"S16_F"\n", htons(hdr->opcode))); + LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_input: ARP unknown opcode type %"S16_F"\n", htons(hdr->opcode))); ETHARP_STATS_INC(etharp.err); break; } diff --git a/src/include/lwip/etharp.h b/src/include/lwip/etharp.h index 249b5c25..b1cebf57 100644 --- a/src/include/lwip/etharp.h +++ b/src/include/lwip/etharp.h @@ -102,7 +102,7 @@ err_t etharp_remove_static_entry(const ip4_addr_t *ipaddr); #endif /* LWIP_IPV4 && LWIP_ARP */ -void etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr, struct pbuf *p); +void etharp_input(struct pbuf *p, struct netif *netif); #ifdef __cplusplus } diff --git a/src/netif/ethernet.c b/src/netif/ethernet.c index 36ff762c..3696d89d 100644 --- a/src/netif/ethernet.c +++ b/src/netif/ethernet.c @@ -175,7 +175,7 @@ ethernet_input(struct pbuf *p, struct netif *netif) goto free_and_return; } /* pass p to ARP module */ - etharp_arp_input(netif, (struct eth_addr*)(netif->hwaddr), p); + etharp_input(p, netif); break; #endif /* LWIP_IPV4 && LWIP_ARP */ #if PPPOE_SUPPORT From 31778193da09a4394749ed3d5cc20aa35c418b1f Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Tue, 23 Aug 2016 17:23:21 +0200 Subject: [PATCH 164/325] Work on bug #48868: Cleanup etharp.c not to use struct eth_hdr: Cleanup etharp_input() to use ethernet_output() --- src/core/ipv4/etharp.c | 62 +++++++++++++----------------------------- src/netif/ethernet.c | 15 ++++++++-- 2 files changed, 32 insertions(+), 45 deletions(-) diff --git a/src/core/ipv4/etharp.c b/src/core/ipv4/etharp.c index e0e1382f..b6db8a0f 100644 --- a/src/core/ipv4/etharp.c +++ b/src/core/ipv4/etharp.c @@ -634,35 +634,13 @@ void etharp_input(struct pbuf *p, struct netif *netif) { struct etharp_hdr *hdr; - struct eth_hdr *ethhdr; /* these are aligned properly, whereas the ARP header fields might not be */ ip4_addr_t sipaddr, dipaddr; u8_t for_us; -#if LWIP_AUTOIP - const u8_t * ethdst_hwaddr; -#endif /* LWIP_AUTOIP */ LWIP_ERROR("netif != NULL", (netif != NULL), return;); - /* drop short ARP packets: we have to check for p->len instead of p->tot_len here - since a struct etharp_hdr is pointed to p->payload, so it musn't be chained! */ - if (p->len < SIZEOF_ETHARP_PACKET) { - LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_WARNING, - ("etharp_input: packet dropped, too short (%"S16_F"/%"S16_F")\n", p->tot_len, - (s16_t)SIZEOF_ETHARP_PACKET)); - ETHARP_STATS_INC(etharp.lenerr); - ETHARP_STATS_INC(etharp.drop); - pbuf_free(p); - return; - } - - ethhdr = (struct eth_hdr *)p->payload; - hdr = (struct etharp_hdr *)((u8_t*)ethhdr + SIZEOF_ETH_HDR); -#if ETHARP_SUPPORT_VLAN - if (ethhdr->type == PP_HTONS(ETHTYPE_VLAN)) { - hdr = (struct etharp_hdr *)(((u8_t*)ethhdr) + SIZEOF_ETH_HDR + SIZEOF_VLAN_HDR); - } -#endif /* ETHARP_SUPPORT_VLAN */ + hdr = (struct etharp_hdr *)p->payload; /* RFC 826 "Packet Reception": */ if ((hdr->hwtype != PP_HTONS(HWTYPE_ETHERNET)) || @@ -730,27 +708,26 @@ etharp_input(struct pbuf *p, struct netif *netif) LWIP_ASSERT("netif->hwaddr_len must be the same as ETH_HWADDR_LEN for etharp!", (netif->hwaddr_len == ETH_HWADDR_LEN)); -#if LWIP_AUTOIP - /* If we are using Link-Local, all ARP packets that contain a Link-Local - * 'sender IP address' MUST be sent using link-layer broadcast instead of - * link-layer unicast. (See RFC3927 Section 2.5, last paragraph) */ - ethdst_hwaddr = ip4_addr_islinklocal(netif_ip4_addr(netif)) ? (const u8_t*)(ethbroadcast.addr) : hdr->shwaddr.addr; -#endif /* LWIP_AUTOIP */ - - ETHADDR16_COPY(&hdr->dhwaddr, &hdr->shwaddr); -#if LWIP_AUTOIP - ETHADDR16_COPY(ðhdr->dest, ethdst_hwaddr); -#else /* LWIP_AUTOIP */ - ETHADDR16_COPY(ðhdr->dest, &hdr->shwaddr); -#endif /* LWIP_AUTOIP */ - ETHADDR16_COPY(&hdr->shwaddr, netif->hwaddr); - ETHADDR16_COPY(ðhdr->src, netif->hwaddr); /* hwtype, hwaddr_len, proto, protolen and the type in the ethernet header are already correct, we tested that before */ + ETHADDR16_COPY(&hdr->dhwaddr, &hdr->shwaddr); + ETHADDR16_COPY(&hdr->shwaddr, netif->hwaddr); + /* return ARP reply */ - netif->linkoutput(netif, p); +#if LWIP_AUTOIP + /* If we are using Link-Local, all ARP packets that contain a Link-Local + * 'sender IP address' MUST be sent using link-layer broadcast instead of + * link-layer unicast. (See RFC3927 Section 2.5, last paragraph) */ + if (ip4_addr_islinklocal(netif_ip4_addr(netif))) { + ethernet_output(netif, p, &hdr->shwaddr, ðbroadcast, ETHTYPE_ARP); + } else +#endif /* LWIP_AUTOIP */ + { + ethernet_output(netif, p, &hdr->shwaddr, &hdr->dhwaddr, ETHTYPE_ARP); + } + /* we are not configured? */ } else if (ip4_addr_isany_val(*netif_ip4_addr(netif))) { /* { for_us == 0 and netif->ip_addr.addr == 0 } */ @@ -1187,12 +1164,11 @@ etharp_raw(struct netif *netif, const struct eth_addr *ethsrc_addr, * link-layer unicast. (See RFC3927 Section 2.5, last paragraph) */ if(ip4_addr_islinklocal(ipsrc_addr)) { ethernet_output(netif, p, ethsrc_addr, ðbroadcast, ETHTYPE_ARP); - } else { + } else +#endif /* LWIP_AUTOIP */ + { ethernet_output(netif, p, ethsrc_addr, ethdst_addr, ETHTYPE_ARP); } -#else /* LWIP_AUTOIP */ - ethernet_output(netif, p, ethsrc_addr, ethdst_addr, ETHTYPE_ARP); -#endif /* LWIP_AUTOIP */ ETHARP_STATS_INC(etharp.xmit); /* free ARP query packet */ diff --git a/src/netif/ethernet.c b/src/netif/ethernet.c index 3696d89d..bf261bc2 100644 --- a/src/netif/ethernet.c +++ b/src/netif/ethernet.c @@ -174,8 +174,19 @@ ethernet_input(struct pbuf *p, struct netif *netif) if (!(netif->flags & NETIF_FLAG_ETHARP)) { goto free_and_return; } - /* pass p to ARP module */ - etharp_input(p, netif); + /* skip Ethernet header */ + if ((p->len < ip_hdr_offset) || pbuf_header(p, (s16_t)-ip_hdr_offset)) { + LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_WARNING, + ("ethernet_input: ARP response packet dropped, too short (%"S16_F"/%"S16_F")\n", + p->tot_len, ip_hdr_offset)); + LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("Can't move over header in packet")); + ETHARP_STATS_INC(etharp.lenerr); + ETHARP_STATS_INC(etharp.drop); + goto free_and_return; + } else { + /* pass p to ARP module */ + etharp_input(p, netif); + } break; #endif /* LWIP_IPV4 && LWIP_ARP */ #if PPPOE_SUPPORT From c719c466b3a1cfa8ad7b55fa51070ab32047a00e Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Tue, 23 Aug 2016 20:41:37 +0200 Subject: [PATCH 165/325] Remove SIZEOF_ETHARP_PACKET_TX #define, it is not needed any more after my last cleanups --- src/core/ipv4/etharp.c | 4 ++-- src/include/lwip/etharp.h | 7 ------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/core/ipv4/etharp.c b/src/core/ipv4/etharp.c index b6db8a0f..364023e4 100644 --- a/src/core/ipv4/etharp.c +++ b/src/core/ipv4/etharp.c @@ -1125,7 +1125,7 @@ etharp_raw(struct netif *netif, const struct eth_addr *ethsrc_addr, LWIP_ASSERT("netif != NULL", netif != NULL); /* allocate a pbuf for the outgoing ARP request packet */ - p = pbuf_alloc(PBUF_LINK, SIZEOF_ETHARP_PACKET_TX, PBUF_RAM); + p = pbuf_alloc(PBUF_LINK, SIZEOF_ETHARP_HDR, PBUF_RAM); /* could allocate a pbuf for an ARP request? */ if (p == NULL) { LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_SERIOUS, @@ -1134,7 +1134,7 @@ etharp_raw(struct netif *netif, const struct eth_addr *ethsrc_addr, return ERR_MEM; } LWIP_ASSERT("check that first pbuf can hold struct etharp_hdr", - (p->len >= SIZEOF_ETHARP_PACKET_TX)); + (p->len >= SIZEOF_ETHARP_HDR)); hdr = (struct etharp_hdr *)p->payload; LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_raw: sending raw ARP packet.\n")); diff --git a/src/include/lwip/etharp.h b/src/include/lwip/etharp.h index b1cebf57..7080a19d 100644 --- a/src/include/lwip/etharp.h +++ b/src/include/lwip/etharp.h @@ -60,13 +60,6 @@ extern "C" { #include "lwip/prot/etharp.h" -#define SIZEOF_ETHARP_PACKET (SIZEOF_ETH_HDR + SIZEOF_ETHARP_HDR) -#if ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET) -#define SIZEOF_ETHARP_PACKET_TX (SIZEOF_ETHARP_PACKET + SIZEOF_VLAN_HDR) -#else /* ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET) */ -#define SIZEOF_ETHARP_PACKET_TX SIZEOF_ETHARP_PACKET -#endif /* ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET) */ - /** 1 seconds period */ #define ARP_TMR_INTERVAL 1000 From e78bc41116fe299e063b36b1f7363e4b6f27c6de Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Wed, 24 Aug 2016 08:01:36 +0200 Subject: [PATCH 166/325] Document ethernet level functions --- src/include/lwip/prot/ethernet.h | 52 +++++++++++++++++++++++--------- src/netif/ethernet.c | 10 ++++-- 2 files changed, 45 insertions(+), 17 deletions(-) diff --git a/src/include/lwip/prot/ethernet.h b/src/include/lwip/prot/ethernet.h index d7a56f6c..792f5a22 100644 --- a/src/include/lwip/prot/ethernet.h +++ b/src/include/lwip/prot/ethernet.h @@ -102,21 +102,43 @@ PACK_STRUCT_END #define SIZEOF_VLAN_HDR 4 #define VLAN_ID(vlan_hdr) (htons((vlan_hdr)->prio_vid) & 0xFFF) -/* A list of often ethtypes (although lwIP does not use all of them): */ -#define ETHTYPE_IP 0x0800U /* Internet protocol v4 */ -#define ETHTYPE_ARP 0x0806U /* Address resolution protocol */ -#define ETHTYPE_WOL 0x0842U /* Wake on lan */ -#define ETHTYPE_VLAN 0x8100U /* Virtual local area network */ -#define ETHTYPE_IPV6 0x86DDU /* Internet protocol v6 */ -#define ETHTYPE_PPPOEDISC 0x8863U /* PPP Over Ethernet Discovery Stage */ -#define ETHTYPE_PPPOE 0x8864U /* PPP Over Ethernet Session Stage */ -#define ETHTYPE_JUMBO 0x8870U /* Jumbo Frames */ -#define ETHTYPE_PROFINET 0x8892U /* Process field network */ -#define ETHTYPE_ETHERCAT 0x88A4U /* Ethernet for control automation technology */ -#define ETHTYPE_LLDP 0x88CCU /* Link layer discovery protocol */ -#define ETHTYPE_SERCOS 0x88CDU /* Serial real-time communication system */ -#define ETHTYPE_PTP 0x88F7U /* Precision time protocol */ -#define ETHTYPE_QINQ 0x9100U /* Q-in-Q, 802.1ad */ +/** + * @ingroup ethernet + * A list of often ethtypes (although lwIP does not use all of them): */ +enum eth_type { + /** Internet protocol v4 */ + ETHTYPE_IP = 0x0800U, + /** Address resolution protocol */ + ETHTYPE_ARP = 0x0806U, + /** Wake on lan */ + ETHTYPE_WOL = 0x0842U, + /** RARP */ + ETHTYPE_RARP = 0x8035U, + /** Virtual local area network */ + ETHTYPE_VLAN = 0x8100U, + /** Internet protocol v6 */ + ETHTYPE_IPV6 = 0x86DDU, + /** PPP Over Ethernet Discovery Stage */ + ETHTYPE_PPPOEDISC = 0x8863U, + /** PPP Over Ethernet Session Stage */ + ETHTYPE_PPPOE = 0x8864U, + /** Jumbo Frames */ + ETHTYPE_JUMBO = 0x8870U, + /** Process field network */ + ETHTYPE_PROFINET = 0x8892U, + /** Ethernet for control automation technology */ + ETHTYPE_ETHERCAT = 0x88A4U, + /** Link layer discovery protocol */ + ETHTYPE_LLDP = 0x88CCU, + /** Serial real-time communication system */ + ETHTYPE_SERCOS = 0x88CDU, + /** Media redundancy protocol */ + ETHTYPE_MRP = 0x88E3U, + /** Precision time protocol */ + ETHTYPE_PTP = 0x88F7U, + /** Q-in-Q, 802.1ad */ + ETHTYPE_QINQ = 0x9100U +}; /** The 24-bit IANA IPv4-multicast OUI is 01-00-5e: */ #define LL_IP4_MULTICAST_ADDR_0 0x01 diff --git a/src/netif/ethernet.c b/src/netif/ethernet.c index bf261bc2..e0c19760 100644 --- a/src/netif/ethernet.c +++ b/src/netif/ethernet.c @@ -1,6 +1,9 @@ /** * @file * Ethernet common functions + * + * @defgroup ethernet Ethernet + * @ingroup callbackstyle_api */ /* @@ -236,14 +239,17 @@ free_and_return: } /** - * Send an ethernet packet on the network using netif->linkoutput + * @ingroup ethernet + * Send an ethernet packet on the network using netif->linkoutput(). * The ethernet header is filled in before sending. * + * @see @ref LWIP_HOOK_UNKNOWN_ETH_PROTOCOL + * * @param netif the lwIP network interface on which to send the packet * @param p the packet to send, p->payload pointing to the (uninitialized) ethernet header * @param src the source MAC address to be copied into the ethernet header * @param dst the destination MAC address to be copied into the ethernet header - * @param eth_type ethernet type + * @param eth_type ethernet type (@ref eth_type) * @return ERR_OK if the packet was sent, any other err_t on failure */ err_t From d9b0236525b9b6e59c28710d8547d2d742246054 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Wed, 24 Aug 2016 08:04:04 +0200 Subject: [PATCH 167/325] Fix MDNS did not allocate TX packets from RAM but from POOL --- src/apps/mdns/mdns.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/apps/mdns/mdns.c b/src/apps/mdns/mdns.c index 7017146b..d8bf02ae 100644 --- a/src/apps/mdns/mdns.c +++ b/src/apps/mdns/mdns.c @@ -882,7 +882,7 @@ mdns_add_question(struct mdns_outpacket *outpkt, struct mdns_domain *domain, u16 if (!outpkt->pbuf) { /* If no pbuf is active, allocate one */ - outpkt->pbuf = pbuf_alloc(PBUF_TRANSPORT, OUTPACKET_SIZE, PBUF_POOL); + outpkt->pbuf = pbuf_alloc(PBUF_TRANSPORT, OUTPACKET_SIZE, PBUF_RAM); if (!outpkt->pbuf) { return ERR_MEM; } @@ -954,7 +954,7 @@ mdns_add_answer(struct mdns_outpacket *reply, struct mdns_domain *domain, u16_t if (!reply->pbuf) { /* If no pbuf is active, allocate one */ - reply->pbuf = pbuf_alloc(PBUF_TRANSPORT, OUTPACKET_SIZE, PBUF_POOL); + reply->pbuf = pbuf_alloc(PBUF_TRANSPORT, OUTPACKET_SIZE, PBUF_RAM); if (!reply->pbuf) { return ERR_MEM; } From 831b7fc7d30c5d7c05abc9112f073a4855e22e45 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Wed, 24 Aug 2016 08:09:03 +0200 Subject: [PATCH 168/325] Add note to pbuf_type about correct TX/RX type selection --- src/include/lwip/pbuf.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/include/lwip/pbuf.h b/src/include/lwip/pbuf.h index 2ae22647..3129311d 100644 --- a/src/include/lwip/pbuf.h +++ b/src/include/lwip/pbuf.h @@ -102,9 +102,10 @@ typedef enum { typedef enum { /** pbuf data is stored in RAM, used for TX mostly, struct pbuf and its payload are allocated in one piece of contiguous memory (so the first payload byte - can be calculated from struct pbuf) + can be calculated from struct pbuf). pbuf_alloc() allocates PBUF_RAM pbufs as unchained pbufs (although that might - change in future versions) */ + change in future versions). + This should be used for all OUTGOING packets (TX).*/ PBUF_RAM, /** pbuf data is stored in ROM, i.e. struct pbuf and its payload are located in totally different memory areas. Since it points to ROM, payload does not @@ -117,7 +118,9 @@ typedef enum { /** pbuf payload refers to RAM. This one comes from a pool and should be used for RX. Payload can be chained (scatter-gather RX) but like PBUF_RAM, struct pbuf and its payload are allocated in one piece of contiguous memory (so - the first payload byte can be calculated from struct pbuf) */ + the first payload byte can be calculated from struct pbuf). + Don't use this for TX, if the pool becomes empty e.g. because of TCP queuing, + you are unable to receive TCP acks! */ PBUF_POOL } pbuf_type; From 6fc7f8449741f6289f596e4748607266c6b1dd45 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Wed, 24 Aug 2016 08:19:51 +0200 Subject: [PATCH 169/325] Minor: documentation updates --- src/core/raw.c | 4 ++-- src/core/udp.c | 6 +++--- src/include/lwip/pbuf.h | 3 +-- src/netif/ethernet.c | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/core/raw.c b/src/core/raw.c index efa21f90..e024410e 100644 --- a/src/core/raw.c +++ b/src/core/raw.c @@ -271,7 +271,7 @@ raw_recv(struct raw_pcb *pcb, raw_recv_fn recv, void *recv_arg) * then.) * * @param pcb the raw pcb which to send - * @param p the IP payload to send + * @param p the IP payload to send. pbuf layer must be @ref PBUF_IP. * @param ipaddr the destination address of the IP packet * */ @@ -393,7 +393,7 @@ raw_sendto(struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *ipaddr) * Send the raw IP packet to the address given by raw_connect() * * @param pcb the raw pcb which to send - * @param p the IP payload to send + * @param p the IP payload to send. pbuf layer must be @ref PBUF_IP. * */ err_t diff --git a/src/core/udp.c b/src/core/udp.c index bb957faf..050a9364 100644 --- a/src/core/udp.c +++ b/src/core/udp.c @@ -462,7 +462,7 @@ chkerr: * Send data using UDP. * * @param pcb UDP PCB used to send the data. - * @param p chain of pbuf's to be sent. + * @param p chain of pbuf's to be sent. pbuf layer must be @ref PBUF_TRANSPORT. * * The datagram will be sent to the current remote_ip & remote_port * stored in pcb. If the pcb is not bound to a port, it will @@ -511,7 +511,7 @@ udp_send_chksum(struct udp_pcb *pcb, struct pbuf *p, * Send data to a specified address using UDP. * * @param pcb UDP PCB used to send the data. - * @param p chain of pbuf's to be sent. + * @param p chain of pbuf's to be sent. pbuf layer must be @ref PBUF_TRANSPORT. * @param dst_ip Destination IP address. * @param dst_port Destination UDP port. * @@ -598,7 +598,7 @@ udp_sendto_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip, * on a netif that is still down. * * @param pcb UDP PCB used to send the data. - * @param p chain of pbuf's to be sent. + * @param p chain of pbuf's to be sent. pbuf layer must be @ref PBUF_TRANSPORT. * @param dst_ip Destination IP address. * @param dst_port Destination UDP port. * @param netif the netif used for sending. diff --git a/src/include/lwip/pbuf.h b/src/include/lwip/pbuf.h index 3129311d..d21ab8cb 100644 --- a/src/include/lwip/pbuf.h +++ b/src/include/lwip/pbuf.h @@ -71,8 +71,7 @@ extern "C" { */ typedef enum { /** Includes spare room for transport layer header, e.g. TCP header. - * Use this if you intend to pass the pbuf to functions like udp_send() or - * tcp_write(). + * Use this if you intend to pass the pbuf to functions like udp_send(). */ PBUF_TRANSPORT, /** Includes spare room for IP header. diff --git a/src/netif/ethernet.c b/src/netif/ethernet.c index e0c19760..fcb259c1 100644 --- a/src/netif/ethernet.c +++ b/src/netif/ethernet.c @@ -246,7 +246,7 @@ free_and_return: * @see @ref LWIP_HOOK_UNKNOWN_ETH_PROTOCOL * * @param netif the lwIP network interface on which to send the packet - * @param p the packet to send, p->payload pointing to the (uninitialized) ethernet header + * @param p the packet to send. pbuf layer must be @ref PBUF_LINK. * @param src the source MAC address to be copied into the ethernet header * @param dst the destination MAC address to be copied into the ethernet header * @param eth_type ethernet type (@ref eth_type) From 8426dfa14d1feb63b1fd1fc17f170d3bbc4e3f40 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Wed, 24 Aug 2016 08:45:37 +0200 Subject: [PATCH 170/325] Remove misleading comments from udp_send() and raw_send(). A pbuf may be added automatically in front of the chain to be able to send PBUF_REFs --- src/core/raw.c | 4 ++-- src/core/udp.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/core/raw.c b/src/core/raw.c index e024410e..efa21f90 100644 --- a/src/core/raw.c +++ b/src/core/raw.c @@ -271,7 +271,7 @@ raw_recv(struct raw_pcb *pcb, raw_recv_fn recv, void *recv_arg) * then.) * * @param pcb the raw pcb which to send - * @param p the IP payload to send. pbuf layer must be @ref PBUF_IP. + * @param p the IP payload to send * @param ipaddr the destination address of the IP packet * */ @@ -393,7 +393,7 @@ raw_sendto(struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *ipaddr) * Send the raw IP packet to the address given by raw_connect() * * @param pcb the raw pcb which to send - * @param p the IP payload to send. pbuf layer must be @ref PBUF_IP. + * @param p the IP payload to send * */ err_t diff --git a/src/core/udp.c b/src/core/udp.c index 050a9364..bb957faf 100644 --- a/src/core/udp.c +++ b/src/core/udp.c @@ -462,7 +462,7 @@ chkerr: * Send data using UDP. * * @param pcb UDP PCB used to send the data. - * @param p chain of pbuf's to be sent. pbuf layer must be @ref PBUF_TRANSPORT. + * @param p chain of pbuf's to be sent. * * The datagram will be sent to the current remote_ip & remote_port * stored in pcb. If the pcb is not bound to a port, it will @@ -511,7 +511,7 @@ udp_send_chksum(struct udp_pcb *pcb, struct pbuf *p, * Send data to a specified address using UDP. * * @param pcb UDP PCB used to send the data. - * @param p chain of pbuf's to be sent. pbuf layer must be @ref PBUF_TRANSPORT. + * @param p chain of pbuf's to be sent. * @param dst_ip Destination IP address. * @param dst_port Destination UDP port. * @@ -598,7 +598,7 @@ udp_sendto_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip, * on a netif that is still down. * * @param pcb UDP PCB used to send the data. - * @param p chain of pbuf's to be sent. pbuf layer must be @ref PBUF_TRANSPORT. + * @param p chain of pbuf's to be sent. * @param dst_ip Destination IP address. * @param dst_port Destination UDP port. * @param netif the netif used for sending. From 43ddf6eee6bc1b2b2d32b98dc103ec5a8e112196 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Wed, 24 Aug 2016 08:46:32 +0200 Subject: [PATCH 171/325] Fix debug strings in ethernet_output --- src/netif/ethernet.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/netif/ethernet.c b/src/netif/ethernet.c index fcb259c1..5e55596a 100644 --- a/src/netif/ethernet.c +++ b/src/netif/ethernet.c @@ -260,7 +260,7 @@ ethernet_output(struct netif* netif, struct pbuf* p, const struct eth_addr* src, struct eth_vlan_hdr *vlanhdr; #endif /* ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET) */ - LWIP_ASSERT("netif->hwaddr_len must be 6 for ethernet_send!", (netif->hwaddr_len == ETH_HWADDR_LEN)); + LWIP_ASSERT("netif->hwaddr_len must be 6 for ethernet_output!", (netif->hwaddr_len == ETH_HWADDR_LEN)); #if ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET) if (pbuf_header(p, sizeof(struct eth_hdr) + SIZEOF_VLAN_HDR) != 0) { @@ -268,7 +268,7 @@ ethernet_output(struct netif* netif, struct pbuf* p, const struct eth_addr* src, if (pbuf_header(p, sizeof(struct eth_hdr)) != 0) { #endif /* ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET) */ LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_SERIOUS, - ("ethernet_send: could not allocate room for header.\n")); + ("ethernet_output: could not allocate room for header.\n")); LINK_STATS_INC(link.lenerr); return ERR_BUF; } @@ -292,7 +292,7 @@ ethernet_output(struct netif* netif, struct pbuf* p, const struct eth_addr* src, ETHADDR32_COPY(ðhdr->dest, dst); ETHADDR16_COPY(ðhdr->src, src); - LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("ethernet_send: sending packet %p\n", (void *)p)); + LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("ethernet_output: sending packet %p\n", (void *)p)); /* send the packet */ return netif->linkoutput(netif, p); From 1ba0e17157dab23d8067703134a7cd1817c172f3 Mon Sep 17 00:00:00 2001 From: goldsimon Date: Wed, 24 Aug 2016 09:06:48 +0200 Subject: [PATCH 172/325] ip6_addr: a valid address is either preferred or deprecated, no need to reserve 3 bits for that --- src/include/lwip/ip6_addr.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/include/lwip/ip6_addr.h b/src/include/lwip/ip6_addr.h index 622fee0a..2d269a6e 100644 --- a/src/include/lwip/ip6_addr.h +++ b/src/include/lwip/ip6_addr.h @@ -259,9 +259,9 @@ Little-endian version, stored in network order (no htonl). */ #define IP6_ADDR_TENTATIVE_5 0x0d /* 5 probes sent */ #define IP6_ADDR_TENTATIVE_6 0x0e /* 6 probes sent */ #define IP6_ADDR_TENTATIVE_7 0x0f /* 7 probes sent */ -#define IP6_ADDR_VALID 0x10 +#define IP6_ADDR_VALID 0x10 /* This bit marks an address as valid (preferred or deprecated) */ #define IP6_ADDR_PREFERRED 0x30 -#define IP6_ADDR_DEPRECATED 0x50 +#define IP6_ADDR_DEPRECATED 0x10 /* Same as VALID (valid but not preferred) */ #define IP6_ADDR_TENTATIVE_COUNT_MASK 0x07 /* 1-7 probes sent */ From 298ec340e50219f78c190f7b54a3133893ddd56e Mon Sep 17 00:00:00 2001 From: goldsimon Date: Wed, 24 Aug 2016 09:19:53 +0200 Subject: [PATCH 173/325] set netif IPv6 address & state via function to implement change triggers (task #13517) --- src/core/ipv6/nd6.c | 19 +++++----- src/core/netif.c | 82 ++++++++++++++++++++++++++++++++++++++-- src/include/lwip/netif.h | 5 ++- 3 files changed, 92 insertions(+), 14 deletions(-) diff --git a/src/core/ipv6/nd6.c b/src/core/ipv6/nd6.c index 6c47dbca..8b24180b 100644 --- a/src/core/ipv6/nd6.c +++ b/src/core/ipv6/nd6.c @@ -751,8 +751,7 @@ nd6_tmr(void) #if LWIP_IPV6_AUTOCONFIG /* If any addresses were configured with this prefix, remove them */ - if (prefix_list[i].flags & ND6_PREFIX_AUTOCONFIG_ADDRESS_GENERATED) - { + if (prefix_list[i].flags & ND6_PREFIX_AUTOCONFIG_ADDRESS_GENERATED) { s8_t j; for (j = 1; j < LWIP_IPV6_NUM_ADDRESSES; j++) { @@ -784,7 +783,7 @@ nd6_tmr(void) for (j = 1; j < LWIP_IPV6_NUM_ADDRESSES; j++) { if (netif_ip6_addr_state(prefix_list[i].netif, j) == IP6_ADDR_INVALID) { /* Generate an address using this prefix and interface ID from link-local address. */ - IP_ADDR6(&prefix_list[i].netif->ip6_addr[j], + netif_ip6_addr_set_parts(prefix_list[i].netif, j, prefix_list[i].prefix.addr[0], prefix_list[i].prefix.addr[1], netif_ip6_addr(prefix_list[i].netif, 0)->addr[2], netif_ip6_addr(prefix_list[i].netif, 0)->addr[3]); @@ -808,14 +807,15 @@ nd6_tmr(void) /* Process our own addresses, if DAD configured. */ for (netif = netif_list; netif != NULL; netif = netif->next) { for (i = 0; i < LWIP_IPV6_NUM_ADDRESSES; ++i) { - if (ip6_addr_istentative(netif->ip6_addr_state[i])) { - if ((netif->ip6_addr_state[i] & IP6_ADDR_TENTATIVE_COUNT_MASK) >= LWIP_IPV6_DUP_DETECT_ATTEMPTS) { + u8_t addr_state = netif_ip6_addr_state(netif, i); + if (ip6_addr_istentative(addr_state)) { + if ((addr_state & IP6_ADDR_TENTATIVE_COUNT_MASK) >= LWIP_IPV6_DUP_DETECT_ATTEMPTS) { /* No NA received in response. Mark address as valid. */ - netif->ip6_addr_state[i] = IP6_ADDR_PREFERRED; + netif_ip6_addr_set_state(netif, i, IP6_ADDR_PREFERRED); /* @todo implement preferred and valid lifetimes. */ } else if (netif->flags & NETIF_FLAG_UP) { #if LWIP_IPV6_MLD - if ((netif->ip6_addr_state[i] & IP6_ADDR_TENTATIVE_COUNT_MASK) == 0) { + if ((addr_state & IP6_ADDR_TENTATIVE_COUNT_MASK) == 0) { /* Join solicited node multicast group. */ ip6_addr_set_solicitednode(&multicast_address, netif_ip6_addr(netif, i)->addr[3]); mld6_joingroup(netif_ip6_addr(netif, i), &multicast_address); @@ -823,7 +823,8 @@ nd6_tmr(void) #endif /* LWIP_IPV6_MLD */ /* Send a NS for this address. */ nd6_send_ns(netif, netif_ip6_addr(netif, i), ND6_SEND_FLAG_MULTICAST_DEST); - netif->ip6_addr_state[i]++; + /* tentative: set next state by increasing by one */ + netif_ip6_addr_set_state(netif, i, addr_state + 1); /* @todo send max 1 NS per tmr call? enable return*/ /*return;*/ } @@ -943,7 +944,7 @@ nd6_send_na(struct netif *netif, const ip6_addr_t *target_addr, u8_t flags) u16_t lladdr_opt_len; /* Use link-local address as source address. */ - /* src_addr = &(netif->ip6_addr[0]); */ + /* src_addr = netif_ip6_addr(netif, 0); */ /* Use target address as source address. */ src_addr = target_addr; diff --git a/src/core/netif.c b/src/core/netif.c index 5c194588..718b5587 100644 --- a/src/core/netif.c +++ b/src/core/netif.c @@ -227,7 +227,7 @@ netif_add(struct netif *netif, void *state, netif_init_fn init, netif_input_fn input) { #if LWIP_IPV6 - u32_t i; + s8_t i; #endif LWIP_ASSERT("No init function given", init != NULL); @@ -241,7 +241,7 @@ netif_add(struct netif *netif, #if LWIP_IPV6 for (i = 0; i < LWIP_IPV6_NUM_ADDRESSES; i++) { ip_addr_set_zero_ip6(&netif->ip6_addr[i]); - netif_ip6_addr_set_state(netif, i, IP6_ADDR_INVALID); + netif->ip6_addr_state[0] = IP6_ADDR_INVALID; } netif->output_ip6 = netif_null_output_ip6; #endif /* LWIP_IPV6 */ @@ -951,12 +951,88 @@ netif_alloc_client_data_id(void) u8_t result = netif_client_id; netif_client_id++; - LWIP_ASSERT("Increase LWIP_NUM_NETIF_CLIENT_DATA in lwipopts.h", resultaddr[0], addr6->addr[1], + addr6->addr[2], addr6->addr[3]); +} + +void +netif_ip6_addr_set_parts(struct netif *netif, s8_t addr_idx, u32_t i0, u32_t i1, u32_t i2, u32_t i3) +{ + const ip6_addr_t *old_addr; + LWIP_ASSERT("netif != NULL", netif != NULL); + LWIP_ASSERT("invalid index", addr_idx < LWIP_IPV6_NUM_ADDRESSES); + + old_addr = netif_ip6_addr(netif, addr_idx); + /* address is actually being changed? */ + if ((old_addr->addr[0] != i0) || (old_addr->addr[1] != i1) || + (old_addr->addr[2] != i2) || (old_addr->addr[3] != i3)) { + LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_STATE, ("netif_ip6_addr_set: netif address being changed\n")); + + /* @todo: tcp_netif_ipv6_addr_changed()/udp_netif_ipv6_addr_changed() */ + /* @todo: remove/readd mib2 ip6 entries? */ + + IP6_ADDR(ip_2_ip6(&(netif->ip6_addr[addr_idx])), i0, i1, i2, i3); + IP_SET_TYPE_VAL(netif->ip6_addr[addr_idx], IPADDR_TYPE_V6); + + if (netif_ip6_addr_state(netif, addr_idx) & IP6_ADDR_VALID) { + netif_issue_reports(netif, NETIF_REPORT_TYPE_IPV6); + NETIF_STATUS_CALLBACK(netif); + } + } + + LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("netif: IPv6 address %d of interface %c%c set to %s/0x%"X8_F"\n", + addr_idx, netif->name[0], netif->name[1], ip6addr_ntoa(netif_ip6_addr(netif, addr_idx)), + netif_ip6_addr_state(netif, addr_idx))); +} + +void +netif_ip6_addr_set_state(struct netif* netif, s8_t addr_idx, u8_t state) +{ + u8_t old_state; + LWIP_ASSERT("netif != NULL", netif != NULL); + LWIP_ASSERT("invalid index", addr_idx < LWIP_IPV6_NUM_ADDRESSES); + + old_state = netif_ip6_addr_state(netif, addr_idx); + /* state is actually being changed? */ + if (old_state != state) { + u8_t old_valid = old_state & IP6_ADDR_VALID; + u8_t new_valid = state & IP6_ADDR_VALID; + LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_STATE, ("netif_ip6_addr_set_state: netif address state being changed\n")); + + if (old_valid && !new_valid) { + /* address about to be removed by setting invalid */ + /* @todo: tcp_netif_ipv6_addr_changed()/udp_netif_ipv6_addr_changed() */ + /* @todo: remove mib2 ip6 entries? */ + } + netif->ip6_addr_state[addr_idx] = state; + + if (!old_valid && new_valid) { + /* address added by setting valid */ + /* @todo: add mib2 ip6 entries? */ + netif_issue_reports(netif, NETIF_REPORT_TYPE_IPV6); + } + if ((old_state & IP6_ADDR_PREFERRED) != (state & IP6_ADDR_PREFERRED)) { + /* address state has changed (valid flag changed or switched between + preferred and deprecated) -> call the callback function */ + NETIF_STATUS_CALLBACK(netif); + } + } + + LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("netif: IPv6 address %d of interface %c%c set to %s/0x%"X8_F"\n", + addr_idx, netif->name[0], netif->name[1], ip6addr_ntoa(netif_ip6_addr(netif, addr_idx)), + netif_ip6_addr_state(netif, addr_idx))); +} + /** * Checks if a specific address is assigned to the netif and returns its * index. diff --git a/src/include/lwip/netif.h b/src/include/lwip/netif.h index 1f11551b..782f7b27 100644 --- a/src/include/lwip/netif.h +++ b/src/include/lwip/netif.h @@ -433,9 +433,10 @@ u8_t netif_alloc_client_data_id(void); #define netif_ip_addr6(netif, i) ((const ip_addr_t*)(&((netif)->ip6_addr[i]))) /** @ingroup netif */ #define netif_ip6_addr(netif, i) ((const ip6_addr_t*)ip_2_ip6(&((netif)->ip6_addr[i]))) -#define netif_ip6_addr_set(netif, i, addr6) do { ip6_addr_set(ip_2_ip6(&((netif)->ip6_addr[i])), addr6); IP_SET_TYPE_VAL((netif)->ip6_addr[i], IPADDR_TYPE_V6); } while(0) +void netif_ip6_addr_set(struct netif *netif, s8_t addr_idx, ip6_addr_t *addr6); +void netif_ip6_addr_set_parts(struct netif *netif, s8_t addr_idx, u32_t i0, u32_t i1, u32_t i2, u32_t i3); #define netif_ip6_addr_state(netif, i) ((netif)->ip6_addr_state[i]) -#define netif_ip6_addr_set_state(netif, i, state) ((netif)->ip6_addr_state[i] = (state)) +void netif_ip6_addr_set_state(struct netif* netif, s8_t addr_idx, u8_t state); s8_t netif_get_ip6_addr_match(struct netif *netif, const ip6_addr_t *ip6addr); void netif_create_ip6_linklocal_address(struct netif *netif, u8_t from_mac_48bit); err_t netif_add_ip6_address(struct netif *netif, const ip6_addr_t *ip6addr, s8_t *chosen_idx); From bf5866b27dbe82ef3b61db35eb8f410a1dd75743 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Wed, 24 Aug 2016 16:49:03 +0800 Subject: [PATCH 174/325] tcp: Prevents a 0 sized (invalid) backlog commit 44e1a2d8e23f accidently includes below changes in tcp_listen_with_backlog - tcp_backlog_set(lpcb, backlog); + lpcb->backlog = backlog; Thus pass 0 to the backlog parameter of netconn_listen_with_backlog() fails. Fixes: 44e1a2d8e23f ("define tcp_backlog_set() as dummy-define when backlog feature is disable") Signed-off-by: Axel Lin Signed-off-by: goldsimon --- src/core/tcp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/tcp.c b/src/core/tcp.c index a132cb4e..115b9145 100644 --- a/src/core/tcp.c +++ b/src/core/tcp.c @@ -688,7 +688,7 @@ tcp_listen_with_backlog(struct tcp_pcb *pcb, u8_t backlog) #endif /* LWIP_CALLBACK_API */ #if TCP_LISTEN_BACKLOG lpcb->accepts_pending = 0; - lpcb->backlog = backlog; + tcp_backlog_set(lpcb, backlog); #endif /* TCP_LISTEN_BACKLOG */ TCP_REG(&tcp_listen_pcbs.pcbs, (struct tcp_pcb *)lpcb); return (struct tcp_pcb *)lpcb; From a1db05c11e5795e732c5eb9bdc6501d28e65d700 Mon Sep 17 00:00:00 2001 From: Erik Ekman Date: Wed, 24 Aug 2016 14:41:48 +0200 Subject: [PATCH 175/325] Fix const argument warning in netif_ip6_addr_set ../../../../../lwip/src/netif/ppp/ppp.c:1276:37: error: passing 'const ip6_addr_t *' (aka 'const struct ip6_addr *') to parameter of type 'ip6_addr_t *' (aka 'struct ip6_addr *') discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers] netif_ip6_addr_set(pcb->netif, 0, IP6_ADDR_ANY6); ^~~~~~~~~~~~~ ../../../../../lwip/src/include/lwip/ip_addr.h:340:24: note: expanded from macro 'IP6_ADDR_ANY6' ^~~~~~~~~~~~~~~~~~~~~~~~~ ../../../../../lwip/src/include/lwip/netif.h:436:73: note: passing argument to parameter 'addr6' here void netif_ip6_addr_set(struct netif *netif, s8_t addr_idx, ip6_addr_t *addr6); --- src/core/netif.c | 2 +- src/include/lwip/netif.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/netif.c b/src/core/netif.c index 718b5587..c2a64d6f 100644 --- a/src/core/netif.c +++ b/src/core/netif.c @@ -958,7 +958,7 @@ netif_alloc_client_data_id(void) #if LWIP_IPV6 void -netif_ip6_addr_set(struct netif *netif, s8_t addr_idx, ip6_addr_t *addr6) +netif_ip6_addr_set(struct netif *netif, s8_t addr_idx, const ip6_addr_t *addr6) { LWIP_ASSERT("addr6 != NULL", addr6 != NULL); netif_ip6_addr_set_parts(netif, addr_idx, addr6->addr[0], addr6->addr[1], diff --git a/src/include/lwip/netif.h b/src/include/lwip/netif.h index 782f7b27..6b727044 100644 --- a/src/include/lwip/netif.h +++ b/src/include/lwip/netif.h @@ -433,7 +433,7 @@ u8_t netif_alloc_client_data_id(void); #define netif_ip_addr6(netif, i) ((const ip_addr_t*)(&((netif)->ip6_addr[i]))) /** @ingroup netif */ #define netif_ip6_addr(netif, i) ((const ip6_addr_t*)ip_2_ip6(&((netif)->ip6_addr[i]))) -void netif_ip6_addr_set(struct netif *netif, s8_t addr_idx, ip6_addr_t *addr6); +void netif_ip6_addr_set(struct netif *netif, s8_t addr_idx, const ip6_addr_t *addr6); void netif_ip6_addr_set_parts(struct netif *netif, s8_t addr_idx, u32_t i0, u32_t i1, u32_t i2, u32_t i3); #define netif_ip6_addr_state(netif, i) ((netif)->ip6_addr_state[i]) void netif_ip6_addr_set_state(struct netif* netif, s8_t addr_idx, u8_t state); From 4c390ad39c4da7f10a291844ba49ce8036ba24c4 Mon Sep 17 00:00:00 2001 From: sg Date: Wed, 24 Aug 2016 20:51:05 +0200 Subject: [PATCH 176/325] update netif address change triggers to tpc & udp to work with IPv6, too --- src/core/netif.c | 87 ++++++++++++++++++++++++++++---- src/core/tcp.c | 38 +++++++------- src/core/udp.c | 24 ++++----- src/include/lwip/priv/tcp_priv.h | 4 +- src/include/lwip/udp.h | 4 +- 5 files changed, 105 insertions(+), 52 deletions(-) diff --git a/src/core/netif.c b/src/core/netif.c index c2a64d6f..b386354a 100644 --- a/src/core/netif.c +++ b/src/core/netif.c @@ -358,6 +358,10 @@ netif_set_addr(struct netif *netif, const ip4_addr_t *ipaddr, const ip4_addr_t * void netif_remove(struct netif *netif) { +#if LWIP_IPV6 + int i; +#endif + if (netif == NULL) { return; } @@ -365,9 +369,11 @@ netif_remove(struct netif *netif) #if LWIP_IPV4 if (!ip4_addr_isany_val(*netif_ip4_addr(netif))) { #if LWIP_TCP - tcp_netif_ipv4_addr_changed(netif_ip4_addr(netif), NULL); + tcp_netif_ip_addr_changed(netif_ip_addr4(netif), NULL); #endif /* LWIP_TCP */ - /* cannot do this for UDP, as there is no 'err' callback in udp pcbs */ +#if LWIP_UDP + udp_netif_ip_addr_changed(netif_ip_addr4(netif), NULL); +#endif /* LWIP_UDP */ } #if LWIP_IGMP @@ -378,10 +384,22 @@ netif_remove(struct netif *netif) #endif /* LWIP_IGMP */ #endif /* LWIP_IPV4*/ -#if LWIP_IPV6 && LWIP_IPV6_MLD +#if LWIP_IPV6 + for (i = 0; i < LWIP_IPV6_NUM_ADDRESSES; i++) { + if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i))) { +#if LWIP_TCP + tcp_netif_ip_addr_changed(netif_ip_addr6(netif, i), NULL); +#endif /* LWIP_TCP */ +#if LWIP_UDP + udp_netif_ip_addr_changed(netif_ip_addr6(netif, i), NULL); +#endif /* LWIP_UDP */ + } + } +#if LWIP_IPV6_MLD /* stop MLD processing */ mld6_stop(netif); -#endif /* LWIP_IPV6 && LWIP_IPV6_MLD */ +#endif /* LWIP_IPV6_MLD */ +#endif /* LWIP_IPV6 */ if (netif_is_up(netif)) { /* set netif down before removing (call callback function) */ netif_set_down(netif); @@ -464,15 +482,18 @@ netif_find(const char *name) void netif_set_ipaddr(struct netif *netif, const ip4_addr_t *ipaddr) { - ip4_addr_t new_addr = (ipaddr ? *ipaddr : *IP4_ADDR_ANY); + ip_addr_t new_addr; + *ip_2_ip4(&new_addr) = (ipaddr ? *ipaddr : *IP4_ADDR_ANY); + IP_SET_TYPE_VAL(new_addr, IPADDR_TYPE_V4); + /* address is actually being changed? */ - if (ip4_addr_cmp(&new_addr, netif_ip4_addr(netif)) == 0) { + if (ip4_addr_cmp(ip_2_ip4(&new_addr), netif_ip4_addr(netif)) == 0) { LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_STATE, ("netif_set_ipaddr: netif address being changed\n")); #if LWIP_TCP - tcp_netif_ipv4_addr_changed(netif_ip4_addr(netif), ipaddr); + tcp_netif_ip_addr_changed(netif_ip_addr4(netif), &new_addr); #endif /* LWIP_TCP */ #if LWIP_UDP - udp_netif_ipv4_addr_changed(netif_ip4_addr(netif), ipaddr); + udp_netif_ip_addr_changed(netif_ip_addr4(netif), &new_addr); #endif /* LWIP_UDP */ mib2_remove_ip4(netif); @@ -957,6 +978,16 @@ netif_alloc_client_data_id(void) #endif #if LWIP_IPV6 +/** + * @ingroup netif + * Change an IPv6 address of a network interface + * + * @param netif the network interface to change + * @param addr_idx index of the IPv6 address + * @param addr6 the new IPv6 address + * + * @note call netif_ip6_addr_set_state() to set the address valid/temptative + */ void netif_ip6_addr_set(struct netif *netif, s8_t addr_idx, const ip6_addr_t *addr6) { @@ -965,6 +996,16 @@ netif_ip6_addr_set(struct netif *netif, s8_t addr_idx, const ip6_addr_t *addr6) addr6->addr[2], addr6->addr[3]); } +/* + * Change an IPv6 address of a network interface (internal version taking 4 * u32_t) + * + * @param netif the network interface to change + * @param addr_idx index of the IPv6 address + * @param i0 word0 of the new IPv6 address + * @param i1 word1 of the new IPv6 address + * @param i2 word2 of the new IPv6 address + * @param i3 word3 of the new IPv6 address + */ void netif_ip6_addr_set_parts(struct netif *netif, s8_t addr_idx, u32_t i0, u32_t i1, u32_t i2, u32_t i3) { @@ -978,7 +1019,18 @@ netif_ip6_addr_set_parts(struct netif *netif, s8_t addr_idx, u32_t i0, u32_t i1, (old_addr->addr[2] != i2) || (old_addr->addr[3] != i3)) { LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_STATE, ("netif_ip6_addr_set: netif address being changed\n")); - /* @todo: tcp_netif_ipv6_addr_changed()/udp_netif_ipv6_addr_changed() */ + if (netif_ip6_addr_state(netif, addr_idx) & IP6_ADDR_VALID) { +#if LWIP_TCP || LWIP_UDP + ip_addr_t new_ipaddr; + IP_ADDR6(&new_ipaddr, i0, i1, i2, i3); +#endif /* LWIP_TCP || LWIP_UDP */ +#if LWIP_TCP + tcp_netif_ip_addr_changed(netif_ip_addr6(netif, addr_idx), &new_ipaddr); +#endif /* LWIP_TCP */ +#if LWIP_UDP + udp_netif_ip_addr_changed(netif_ip_addr6(netif, addr_idx), &new_ipaddr); +#endif /* LWIP_UDP */ + } /* @todo: remove/readd mib2 ip6 entries? */ IP6_ADDR(ip_2_ip6(&(netif->ip6_addr[addr_idx])), i0, i1, i2, i3); @@ -995,6 +1047,16 @@ netif_ip6_addr_set_parts(struct netif *netif, s8_t addr_idx, u32_t i0, u32_t i1, netif_ip6_addr_state(netif, addr_idx))); } +/** + * @ingroup netif + * Change the state of an IPv6 address of a network interface + * (INVALID, TEMPTATIVE, PREFERRED, DEPRECATED, where TEMPTATIVE + * includes the number of checks done, see ip6_addr.h) + * + * @param netif the network interface to change + * @param addr_idx index of the IPv6 address + * @param state the new IPv6 address state + */ void netif_ip6_addr_set_state(struct netif* netif, s8_t addr_idx, u8_t state) { @@ -1011,7 +1073,12 @@ netif_ip6_addr_set_state(struct netif* netif, s8_t addr_idx, u8_t state) if (old_valid && !new_valid) { /* address about to be removed by setting invalid */ - /* @todo: tcp_netif_ipv6_addr_changed()/udp_netif_ipv6_addr_changed() */ +#if LWIP_TCP + tcp_netif_ip_addr_changed(netif_ip_addr6(netif, addr_idx), NULL); +#endif /* LWIP_TCP */ +#if LWIP_UDP + udp_netif_ip_addr_changed(netif_ip_addr6(netif, addr_idx), NULL); +#endif /* LWIP_UDP */ /* @todo: remove mib2 ip6 entries? */ } netif->ip6_addr_state[addr_idx] = state; diff --git a/src/core/tcp.c b/src/core/tcp.c index 115b9145..8049c263 100644 --- a/src/core/tcp.c +++ b/src/core/tcp.c @@ -1896,19 +1896,18 @@ tcp_eff_send_mss_impl(u16_t sendmss, const ip_addr_t *dest } #endif /* TCP_CALCULATE_EFF_SEND_MSS */ -#if LWIP_IPV4 -/** Helper function for tcp_netif_ipv4_addr_changed() that iterates a pcb list */ +/** Helper function for tcp_netif_ip_addr_changed() that iterates a pcb list */ static void -tcp_netif_ipv4_addr_changed_pcblist(const ip4_addr_t* old_addr, struct tcp_pcb* pcb_list) +tcp_netif_ip_addr_changed_pcblist(const ip_addr_t* old_addr, struct tcp_pcb* pcb_list) { struct tcp_pcb *pcb; pcb = pcb_list; while (pcb != NULL) { /* PCB bound to current local interface address? */ - if (IP_IS_V4_VAL(pcb->local_ip) && ip4_addr_cmp(ip_2_ip4(&pcb->local_ip), old_addr) + if (ip_addr_cmp(&pcb->local_ip, old_addr) #if LWIP_AUTOIP /* connections to link-local addresses must persist (RFC3927 ch. 1.9) */ - && !ip4_addr_islinklocal(ip_2_ip4(&pcb->local_ip)) + && (!IP_IS_V4_VAL(pcb->local_ip) || !ip4_addr_islinklocal(ip_2_ip4(&pcb->local_ip))) #endif /* LWIP_AUTOIP */ ) { /* this connection must be aborted */ @@ -1924,35 +1923,32 @@ tcp_netif_ipv4_addr_changed_pcblist(const ip4_addr_t* old_addr, struct tcp_pcb* /** This function is called from netif.c when address is changed or netif is removed * - * @param old_addr IPv4 address of the netif before change - * @param new_addr IPv4 address of the netif after change or NULL if netif has been removed + * @param old_addr IP address of the netif before change + * @param new_addr IP address of the netif after change or NULL if netif has been removed */ void -tcp_netif_ipv4_addr_changed(const ip4_addr_t* old_addr, const ip4_addr_t* new_addr) +tcp_netif_ip_addr_changed(const ip_addr_t* old_addr, const ip_addr_t* new_addr) { struct tcp_pcb_listen *lpcb, *next; - tcp_netif_ipv4_addr_changed_pcblist(old_addr, tcp_active_pcbs); - tcp_netif_ipv4_addr_changed_pcblist(old_addr, tcp_bound_pcbs); + if (!ip_addr_isany(old_addr)) { + tcp_netif_ip_addr_changed_pcblist(old_addr, tcp_active_pcbs); + tcp_netif_ip_addr_changed_pcblist(old_addr, tcp_bound_pcbs); - if (!ip4_addr_isany(new_addr)) { - /* PCB bound to current local interface address? */ - for (lpcb = tcp_listen_pcbs.listen_pcbs; lpcb != NULL; lpcb = next) { - next = lpcb->next; - /* Is this an IPv4 pcb? */ - if (IP_IS_V4_VAL(lpcb->local_ip)) { + if (!ip_addr_isany(new_addr)) { + /* PCB bound to current local interface address? */ + for (lpcb = tcp_listen_pcbs.listen_pcbs; lpcb != NULL; lpcb = next) { + next = lpcb->next; /* PCB bound to current local interface address? */ - if ((!(ip4_addr_isany(ip_2_ip4(&lpcb->local_ip)))) && - (ip4_addr_cmp(ip_2_ip4(&lpcb->local_ip), old_addr))) { + if (ip_addr_cmp(&lpcb->local_ip, old_addr)) { /* The PCB is listening to the old ipaddr and - * is set to listen to the new one instead */ - ip_addr_copy_from_ip4(lpcb->local_ip, *new_addr); + * is set to listen to the new one instead */ + ip_addr_copy(lpcb->local_ip, *new_addr); } } } } } -#endif /* LWIP_IPV4 */ const char* tcp_debug_state_str(enum tcp_state s) diff --git a/src/core/udp.c b/src/core/udp.c index bb957faf..04a64537 100644 --- a/src/core/udp.c +++ b/src/core/udp.c @@ -1166,32 +1166,26 @@ udp_new_ip_type(u8_t type) return pcb; } -#if LWIP_IPV4 /** This function is called from netif.c when address is changed * - * @param old_addr IPv4 address of the netif before change - * @param new_addr IPv4 address of the netif after change + * @param old_addr IP address of the netif before change + * @param new_addr IP address of the netif after change */ -void udp_netif_ipv4_addr_changed(const ip4_addr_t* old_addr, const ip4_addr_t* new_addr) +void udp_netif_ip_addr_changed(const ip_addr_t* old_addr, const ip_addr_t* new_addr) { struct udp_pcb* upcb; - if (!ip4_addr_isany(new_addr)) { + if (!ip_addr_isany(old_addr) && !ip_addr_isany(new_addr)) { for (upcb = udp_pcbs; upcb != NULL; upcb = upcb->next) { - /* Is this an IPv4 pcb? */ - if (IP_IS_V4_VAL(upcb->local_ip)) { - /* PCB bound to current local interface address? */ - if (!ip4_addr_isany(ip_2_ip4(&upcb->local_ip)) && - ip4_addr_cmp(ip_2_ip4(&upcb->local_ip), old_addr)) { - /* The PCB is bound to the old ipaddr and - * is set to bound to the new one instead */ - ip_addr_copy_from_ip4(upcb->local_ip, *new_addr); - } + /* PCB bound to current local interface address? */ + if (ip_addr_cmp(&upcb->local_ip, old_addr)) { + /* The PCB is bound to the old ipaddr and + * is set to bound to the new one instead */ + ip_addr_copy(upcb->local_ip, *new_addr); } } } } -#endif /* LWIP_IPV4 */ #if UDP_DEBUG /** diff --git a/src/include/lwip/priv/tcp_priv.h b/src/include/lwip/priv/tcp_priv.h index c0c9110d..736dc325 100644 --- a/src/include/lwip/priv/tcp_priv.h +++ b/src/include/lwip/priv/tcp_priv.h @@ -493,9 +493,7 @@ s16_t tcp_pcbs_sane(void); * that a timer is needed (i.e. active- or time-wait-pcb found). */ void tcp_timer_needed(void); -#if LWIP_IPV4 -void tcp_netif_ipv4_addr_changed(const ip4_addr_t* old_addr, const ip4_addr_t* new_addr); -#endif /* LWIP_IPV4 */ +void tcp_netif_ip_addr_changed(const ip_addr_t* old_addr, const ip_addr_t* new_addr); #ifdef __cplusplus } diff --git a/src/include/lwip/udp.h b/src/include/lwip/udp.h index 3e499b06..b9299073 100644 --- a/src/include/lwip/udp.h +++ b/src/include/lwip/udp.h @@ -171,9 +171,7 @@ void udp_debug_print(struct udp_hdr *udphdr); #define udp_debug_print(udphdr) #endif -#if LWIP_IPV4 -void udp_netif_ipv4_addr_changed(const ip4_addr_t* old_addr, const ip4_addr_t* new_addr); -#endif /* LWIP_IPV4 */ +void udp_netif_ip_addr_changed(const ip_addr_t* old_addr, const ip_addr_t* new_addr); #ifdef __cplusplus } From a2ca85a260edd9e3ecc00b8dd24d802d32291a07 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Thu, 25 Aug 2016 10:50:24 +0800 Subject: [PATCH 177/325] tcp: Make tcp_state_str/tcp_backoff/tcp_persist_backoff static They are only referenced in tcp.c, so make them static. Signed-off-by: Axel Lin Signed-off-by: goldsimon --- src/core/tcp.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/tcp.c b/src/core/tcp.c index 8049c263..7f15c04c 100644 --- a/src/core/tcp.c +++ b/src/core/tcp.c @@ -85,7 +85,7 @@ #define INITIAL_MSS TCP_MSS #endif -const char * const tcp_state_str[] = { +static const char * const tcp_state_str[] = { "CLOSED", "LISTEN", "SYN_SENT", @@ -104,10 +104,10 @@ static u16_t tcp_port = TCP_LOCAL_PORT_RANGE_START; /* Incremented every coarse grained timer shot (typically every 500 ms). */ u32_t tcp_ticks; -const u8_t tcp_backoff[13] = +static const u8_t tcp_backoff[13] = { 1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7}; /* Times per slowtmr hits */ -const u8_t tcp_persist_backoff[7] = { 3, 6, 12, 24, 48, 96, 120 }; +static const u8_t tcp_persist_backoff[7] = { 3, 6, 12, 24, 48, 96, 120 }; /* The TCP PCB lists. */ From 475d49440c6d07332565a6ea886628ccb9a179d2 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Thu, 25 Aug 2016 14:07:35 +0200 Subject: [PATCH 178/325] Fix handling of LWIP_HOOK_VLAN_SET(). Previous implementation supplied uninitialized arguments to the macro (struct eth_hdr). Change macro signature to be universal: netif, pbuf, src, dst, eth_type - whatever the user needs to decide about VLAN header. Return value <0 means "no VLAN header", 0 <= return_value <= 0xFFFF -> value is prio_vid of header. Clean up ethernet_output function to be more readable. --- UPGRADING | 2 ++ src/include/lwip/opt.h | 19 ++++++------ src/netif/ethernet.c | 65 ++++++++++++++++++++++-------------------- 3 files changed, 47 insertions(+), 39 deletions(-) diff --git a/UPGRADING b/UPGRADING index b9ad876a..2190ec98 100644 --- a/UPGRADING +++ b/UPGRADING @@ -57,6 +57,8 @@ with newer versions. * added hook LWIP_HOOK_MEMP_AVAILABLE() to get informed when a memp pool was empty and an item is now available + * Signature of LWIP_HOOK_VLAN_SET macro was changed + * LWIP_DECLARE_MEMORY_ALIGNED() may be used to declare aligned memory buffers (mem/memp) or to move buffers to dedicated memory using compiler attributes diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h index 85d45821..d4061d8b 100644 --- a/src/include/lwip/opt.h +++ b/src/include/lwip/opt.h @@ -2495,17 +2495,20 @@ /** * LWIP_HOOK_VLAN_SET(netif, eth_hdr, vlan_hdr): - * - called from etharp_raw() and ethernet_output() if VLAN support is enabled - * - netif: struct netif that the packet will be sent through - * - eth_hdr: struct eth_hdr of the packet - * - vlan_hdr: struct eth_vlan_hdr of the packet - * Return values: - * - 0: Packet shall not contain VLAN header. - * - != 0: Packet shall contain VLAN header. * Hook can be used to set prio_vid field of vlan_hdr. + * Called from ethernet_output() if VLAN support is enabled. + * Arguments: + * - netif: struct netif that the packet will be sent through + * - p: struct pbuf packet to be sent + * - src: source eth address + * - dst: destination eth address + * - eth_type: ethernet type to packet to be sent + * Return values: + * - <0: Packet shall not contain VLAN header. + * - 0 <= return value <= 0xFFFF: Packet shall contain VLAN header. Return value is prio_vid in host byte order. */ #ifdef __DOXYGEN__ -#define LWIP_HOOK_VLAN_SET(netif, eth_hdr, vlan_hdr) +#define LWIP_HOOK_VLAN_SET(netif, p, src, dst, eth_type) #endif /** diff --git a/src/netif/ethernet.c b/src/netif/ethernet.c index 5e55596a..fffa48f9 100644 --- a/src/netif/ethernet.c +++ b/src/netif/ethernet.c @@ -253,49 +253,52 @@ free_and_return: * @return ERR_OK if the packet was sent, any other err_t on failure */ err_t -ethernet_output(struct netif* netif, struct pbuf* p, const struct eth_addr* src, const struct eth_addr* dst, u16_t eth_type) +ethernet_output(struct netif* netif, struct pbuf* p, + const struct eth_addr* src, const struct eth_addr* dst, + u16_t eth_type) { - struct eth_hdr *ethhdr; -#if ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET) - struct eth_vlan_hdr *vlanhdr; -#endif /* ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET) */ - - LWIP_ASSERT("netif->hwaddr_len must be 6 for ethernet_output!", (netif->hwaddr_len == ETH_HWADDR_LEN)); + struct eth_hdr* ethhdr; + u16_t eth_type_be = ntohs(eth_type); #if ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET) - if (pbuf_header(p, sizeof(struct eth_hdr) + SIZEOF_VLAN_HDR) != 0) { -#else /* ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET) */ - if (pbuf_header(p, sizeof(struct eth_hdr)) != 0) { + s32_t vlan_prio_vid = LWIP_HOOK_VLAN_SET(netif, p, src, dst, eth_type); + if (vlan_prio_vid >= 0) { + struct eth_vlan_hdr* vlanhdr; + + if (pbuf_header(p, SIZEOF_ETH_HDR + SIZEOF_VLAN_HDR) != 0) { + goto pbuf_header_failed; + } + vlanhdr = (struct eth_vlan_hdr*)(((u8_t*)p->payload) + SIZEOF_ETH_HDR); + vlanhdr->tpid = eth_type_be; + vlanhdr->prio_vid = ntohs((u16_t)vlan_prio_vid); + + eth_type_be = PP_HTONS(ETHTYPE_VLAN); + } else #endif /* ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET) */ - LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_SERIOUS, - ("ethernet_output: could not allocate room for header.\n")); - LINK_STATS_INC(link.lenerr); - return ERR_BUF; + { + if (pbuf_header(p, SIZEOF_ETH_HDR) != 0) { + goto pbuf_header_failed; + } } - ethhdr = (struct eth_hdr *)p->payload; - -#if ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET) - ethhdr->type = PP_HTONS(ETHTYPE_VLAN); - vlanhdr = (struct eth_vlan_hdr*)(((u8_t*)ethhdr) + SIZEOF_ETH_HDR); - vlanhdr->prio_vid = 0; - vlanhdr->tpid = ntohs(eth_type); - if (!LWIP_HOOK_VLAN_SET(netif, ethhdr, vlanhdr)) { - /* packet shall not contain VLAN header, so hide it and set correct ethertype */ - pbuf_header(p, -SIZEOF_VLAN_HDR); - ethhdr = (struct eth_hdr *)p->payload; -#endif /* ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET) */ - ethhdr->type = ntohs(eth_type); -#if ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET) - } -#endif /* ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET) */ + ethhdr = (struct eth_hdr*)p->payload; + ethhdr->type = eth_type_be; ETHADDR32_COPY(ðhdr->dest, dst); ETHADDR16_COPY(ðhdr->src, src); - LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("ethernet_output: sending packet %p\n", (void *)p)); + LWIP_ASSERT("netif->hwaddr_len must be 6 for ethernet_output!", + (netif->hwaddr_len == ETH_HWADDR_LEN)); + LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, + ("ethernet_output: sending packet %p\n", (void *)p)); /* send the packet */ return netif->linkoutput(netif, p); + +pbuf_header_failed: + LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_SERIOUS, + ("ethernet_output: could not allocate room for header.\n")); + LINK_STATS_INC(link.lenerr); + return ERR_BUF; } #endif /* LWIP_ARP || LWIP_ETHERNET */ From aeb3834219a78624f3d1dc8e050dd1ec3d38e521 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Thu, 25 Aug 2016 14:12:49 +0200 Subject: [PATCH 179/325] Add debug assert to my last commit and improve comment in opt.h --- src/include/lwip/opt.h | 1 + src/netif/ethernet.c | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h index d4061d8b..49b6c17b 100644 --- a/src/include/lwip/opt.h +++ b/src/include/lwip/opt.h @@ -2497,6 +2497,7 @@ * LWIP_HOOK_VLAN_SET(netif, eth_hdr, vlan_hdr): * Hook can be used to set prio_vid field of vlan_hdr. * Called from ethernet_output() if VLAN support is enabled. + * Signature: s32_t my_hook_vlan_set(struct netif* netif, struct pbuf* pbuf, const struct eth_addr* src, const struct eth_addr* dst, u16_t eth_type); * Arguments: * - netif: struct netif that the packet will be sent through * - p: struct pbuf packet to be sent diff --git a/src/netif/ethernet.c b/src/netif/ethernet.c index fffa48f9..681991ee 100644 --- a/src/netif/ethernet.c +++ b/src/netif/ethernet.c @@ -265,6 +265,8 @@ ethernet_output(struct netif* netif, struct pbuf* p, if (vlan_prio_vid >= 0) { struct eth_vlan_hdr* vlanhdr; + LWIP_ASSERT("prio_vid must be <= 0xFFFF", vlan_prio_vid <= 0xFFFF); + if (pbuf_header(p, SIZEOF_ETH_HDR + SIZEOF_VLAN_HDR) != 0) { goto pbuf_header_failed; } From 3e23eb764b81ac598bfe97a4c5759562f00efc19 Mon Sep 17 00:00:00 2001 From: goldsimon Date: Thu, 25 Aug 2016 14:20:15 +0200 Subject: [PATCH 180/325] fixed compiling TCP_OOSEQ_MAX_BYTES || TCP_OOSEQ_MAX_PBUFS (local variable 'p' was hidden) --- src/core/tcp_in.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/core/tcp_in.c b/src/core/tcp_in.c index 2ad8f006..c618e006 100644 --- a/src/core/tcp_in.c +++ b/src/core/tcp_in.c @@ -997,7 +997,6 @@ tcp_receive(struct tcp_pcb *pcb) #if TCP_QUEUE_OOSEQ struct tcp_seg *prev, *cseg; #endif /* TCP_QUEUE_OOSEQ */ - struct pbuf *p; s32_t off; s16_t m; u32_t right_wnd_edge; @@ -1314,8 +1313,8 @@ tcp_receive(struct tcp_pcb *pcb) adjust the ->data pointer in the seg and the segment length.*/ + struct pbuf *p = inseg.p; off = pcb->rcv_nxt - seqno; - p = inseg.p; LWIP_ASSERT("inseg.p != NULL", inseg.p); LWIP_ASSERT("insane offset!", (off < 0x7fff)); if (inseg.p->len < off) { From 89aa4e7d7939b16496ac45e538ea3d792f35cade Mon Sep 17 00:00:00 2001 From: goldsimon Date: Thu, 25 Aug 2016 14:20:40 +0200 Subject: [PATCH 181/325] fixed bug #47921: link-local prefix in router advertisement must not be processes for SLAAC (patch by abhishek ambure) --- src/core/ipv6/nd6.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/core/ipv6/nd6.c b/src/core/ipv6/nd6.c index 8b24180b..ec29a9bb 100644 --- a/src/core/ipv6/nd6.c +++ b/src/core/ipv6/nd6.c @@ -485,7 +485,9 @@ nd6_input(struct pbuf *p, struct netif *inp) struct prefix_option *prefix_opt; prefix_opt = (struct prefix_option *)buffer; - if (prefix_opt->flags & ND6_PREFIX_FLAG_ON_LINK) { + if ((prefix_opt->flags & ND6_PREFIX_FLAG_ON_LINK) && + (prefix_opt->length == 64) && + !ip6_addr_islinklocal(&(prefix_opt->prefix))) { /* Add to on-link prefix list. */ s8_t prefix; From 2980a12373244434cb01586196e48b904210f471 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Thu, 25 Aug 2016 14:25:16 +0200 Subject: [PATCH 182/325] Fix ntohs -> htons in ethernet.c --- src/netif/ethernet.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/netif/ethernet.c b/src/netif/ethernet.c index 681991ee..88705f3b 100644 --- a/src/netif/ethernet.c +++ b/src/netif/ethernet.c @@ -258,7 +258,7 @@ ethernet_output(struct netif* netif, struct pbuf* p, u16_t eth_type) { struct eth_hdr* ethhdr; - u16_t eth_type_be = ntohs(eth_type); + u16_t eth_type_be = htons(eth_type); #if ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET) s32_t vlan_prio_vid = LWIP_HOOK_VLAN_SET(netif, p, src, dst, eth_type); @@ -272,7 +272,7 @@ ethernet_output(struct netif* netif, struct pbuf* p, } vlanhdr = (struct eth_vlan_hdr*)(((u8_t*)p->payload) + SIZEOF_ETH_HDR); vlanhdr->tpid = eth_type_be; - vlanhdr->prio_vid = ntohs((u16_t)vlan_prio_vid); + vlanhdr->prio_vid = htons((u16_t)vlan_prio_vid); eth_type_be = PP_HTONS(ETHTYPE_VLAN); } else From 452f5d6296094cf96d4983c867b68d3f98a0a369 Mon Sep 17 00:00:00 2001 From: sg Date: Thu, 25 Aug 2016 21:15:26 +0200 Subject: [PATCH 183/325] fix tcpip.c for LWIP_TIMERS==0 --- src/api/tcpip.c | 17 ++++++++++++----- src/include/lwip/priv/tcpip_priv.h | 8 ++++---- src/include/lwip/tcpip.h | 4 ++-- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/api/tcpip.c b/src/api/tcpip.c index e9d3ad77..4dfeabd3 100644 --- a/src/api/tcpip.c +++ b/src/api/tcpip.c @@ -65,6 +65,13 @@ static sys_mbox_t mbox; sys_mutex_t lock_tcpip_core; #endif /* LWIP_TCPIP_CORE_LOCKING */ +#if LWIP_TIMERS +/* wait for a message, timeouts are processed while waiting */ +#define TCPIP_MBOX_FETCH(mbox, msg) sys_timeouts_mbox_fetch(mbox, msg) +#else /* LWIP_TIMERS */ +/* wait for a message with timers disabled (e.g. pass a timer-check trigger into tcpip_thread) */ +#define TCPIP_MBOX_FETCH(mbox, msg) sys_mbox_fetch(mbox, msg) +#endif /* LWIP_TIMERS */ /** * The main lwIP thread. This thread has exclusive access to lwIP core functions @@ -91,7 +98,7 @@ tcpip_thread(void *arg) UNLOCK_TCPIP_CORE(); LWIP_TCPIP_THREAD_ALIVE(); /* wait for a message, timeouts are processed while waiting */ - sys_timeouts_mbox_fetch(&mbox, (void **)&msg); + TCPIP_MBOX_FETCH(&mbox, (void **)&msg); LOCK_TCPIP_CORE(); if (msg == NULL) { LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: invalid message: NULL\n")); @@ -119,7 +126,7 @@ tcpip_thread(void *arg) break; #endif /* !LWIP_TCPIP_CORE_LOCKING_INPUT */ -#if LWIP_TCPIP_TIMEOUT +#if LWIP_TCPIP_TIMEOUT && LWIP_TIMERS case TCPIP_MSG_TIMEOUT: LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: TIMEOUT %p\n", (void *)msg)); sys_timeout(msg->msg.tmo.msecs, msg->msg.tmo.h, msg->msg.tmo.arg); @@ -130,7 +137,7 @@ tcpip_thread(void *arg) sys_untimeout(msg->msg.tmo.h, msg->msg.tmo.arg); memp_free(MEMP_TCPIP_MSG_API, msg); break; -#endif /* LWIP_TCPIP_TIMEOUT */ +#endif /* LWIP_TCPIP_TIMEOUT && LWIP_TIMERS */ case TCPIP_MSG_CALLBACK: LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: CALLBACK %p\n", (void *)msg)); @@ -249,7 +256,7 @@ tcpip_callback_with_block(tcpip_callback_fn function, void *ctx, u8_t block) return ERR_OK; } -#if LWIP_TCPIP_TIMEOUT +#if LWIP_TCPIP_TIMEOUT && LWIP_TIMERS /** * call sys_timeout in tcpip_thread * @@ -304,7 +311,7 @@ tcpip_untimeout(sys_timeout_handler h, void *arg) sys_mbox_post(&mbox, msg); return ERR_OK; } -#endif /* LWIP_TCPIP_TIMEOUT */ +#endif /* LWIP_TCPIP_TIMEOUT && LWIP_TIMERS */ /** diff --git a/src/include/lwip/priv/tcpip_priv.h b/src/include/lwip/priv/tcpip_priv.h index b6e42935..5fc80f3f 100644 --- a/src/include/lwip/priv/tcpip_priv.h +++ b/src/include/lwip/priv/tcpip_priv.h @@ -112,10 +112,10 @@ enum tcpip_msg_type { TCPIP_MSG_API, TCPIP_MSG_API_CALL, TCPIP_MSG_INPKT, -#if LWIP_TCPIP_TIMEOUT +#if LWIP_TCPIP_TIMEOUT && LWIP_TIMERS TCPIP_MSG_TIMEOUT, TCPIP_MSG_UNTIMEOUT, -#endif /* LWIP_TCPIP_TIMEOUT */ +#endif /* LWIP_TCPIP_TIMEOUT && LWIP_TIMERS */ TCPIP_MSG_CALLBACK, TCPIP_MSG_CALLBACK_STATIC }; @@ -141,13 +141,13 @@ struct tcpip_msg { tcpip_callback_fn function; void *ctx; } cb; -#if LWIP_TCPIP_TIMEOUT +#if LWIP_TCPIP_TIMEOUT && LWIP_TIMERS struct { u32_t msecs; sys_timeout_handler h; void *arg; } tmo; -#endif /* LWIP_TCPIP_TIMEOUT */ +#endif /* LWIP_TCPIP_TIMEOUT && LWIP_TIMERS */ } msg; }; diff --git a/src/include/lwip/tcpip.h b/src/include/lwip/tcpip.h index dc060b20..404a4a2c 100644 --- a/src/include/lwip/tcpip.h +++ b/src/include/lwip/tcpip.h @@ -90,10 +90,10 @@ err_t tcpip_trycallback(struct tcpip_callback_msg* msg); err_t pbuf_free_callback(struct pbuf *p); err_t mem_free_callback(void *m); -#if LWIP_TCPIP_TIMEOUT +#if LWIP_TCPIP_TIMEOUT && LWIP_TIMERS err_t tcpip_timeout(u32_t msecs, sys_timeout_handler h, void *arg); err_t tcpip_untimeout(sys_timeout_handler h, void *arg); -#endif /* LWIP_TCPIP_TIMEOUT */ +#endif /* LWIP_TCPIP_TIMEOUT && LWIP_TIMERS */ #ifdef __cplusplus } From 57468b8a302969880125a4a9440f94b3a794fdad Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Thu, 25 Aug 2016 22:04:04 +0200 Subject: [PATCH 184/325] Minor: Several documentation updates --- src/core/netif.c | 22 ++++++++++++++-------- src/include/lwip/netif.h | 16 ++++++++-------- src/include/lwip/opt.h | 14 ++++++++------ src/netif/ethernet.c | 4 +++- 4 files changed, 33 insertions(+), 23 deletions(-) diff --git a/src/core/netif.c b/src/core/netif.c index b386354a..d6cfb55c 100644 --- a/src/core/netif.c +++ b/src/core/netif.c @@ -4,6 +4,12 @@ * * @defgroup netif Network interface (NETIF) * @ingroup callbackstyle_api + * + * @defgroup netif_ip4 IPv4 address handling + * @ingroup netif + * + * @defgroup netif_ip6 IPv6 address handling + * @ingroup netif */ /* @@ -321,7 +327,7 @@ netif_add(struct netif *netif, #if LWIP_IPV4 /** - * @ingroup netif + * @ingroup netif_ip4 * Change IP address configuration for a network interface (including netmask * and default gateway). * @@ -470,7 +476,7 @@ netif_find(const char *name) #if LWIP_IPV4 /** - * @ingroup netif + * @ingroup netif_ip4 * Change the IP address of a network interface * * @param netif the network interface to change @@ -518,7 +524,7 @@ netif_set_ipaddr(struct netif *netif, const ip4_addr_t *ipaddr) } /** - * @ingroup netif + * @ingroup netif_ip4 * Change the default gateway for a network interface * * @param netif the network interface to change @@ -540,7 +546,7 @@ netif_set_gw(struct netif *netif, const ip4_addr_t *gw) } /** - * @ingroup netif + * @ingroup netif_ip4 * Change the netmask of a network interface * * @param netif the network interface to change @@ -979,7 +985,7 @@ netif_alloc_client_data_id(void) #if LWIP_IPV6 /** - * @ingroup netif + * @ingroup netif_ip6 * Change an IPv6 address of a network interface * * @param netif the network interface to change @@ -1048,7 +1054,7 @@ netif_ip6_addr_set_parts(struct netif *netif, s8_t addr_idx, u32_t i0, u32_t i1, } /** - * @ingroup netif + * @ingroup netif_ip6 * Change the state of an IPv6 address of a network interface * (INVALID, TEMPTATIVE, PREFERRED, DEPRECATED, where TEMPTATIVE * includes the number of checks done, see ip6_addr.h) @@ -1123,7 +1129,7 @@ netif_get_ip6_addr_match(struct netif *netif, const ip6_addr_t *ip6addr) } /** - * @ingroup netif + * @ingroup netif_ip6 * Create a link-local IPv6 address on a netif (stored in slot 0) * * @param netif the netif to create the address on @@ -1175,7 +1181,7 @@ netif_create_ip6_linklocal_address(struct netif *netif, u8_t from_mac_48bit) } /** - * @ingroup netif + * @ingroup netif_ip6 * This function allows for the easy addition of a new IPv6 address to an interface. * It takes care of finding an empty slot and then sets the address tentative * (to make sure that all the subsequent processing happens). diff --git a/src/include/lwip/netif.h b/src/include/lwip/netif.h index 6b727044..1b5f21c7 100644 --- a/src/include/lwip/netif.h +++ b/src/include/lwip/netif.h @@ -359,17 +359,17 @@ void netif_set_default(struct netif *netif); void netif_set_ipaddr(struct netif *netif, const ip4_addr_t *ipaddr); void netif_set_netmask(struct netif *netif, const ip4_addr_t *netmask); void netif_set_gw(struct netif *netif, const ip4_addr_t *gw); -/** @ingroup netif */ +/** @ingroup netif_ip4 */ #define netif_ip4_addr(netif) ((const ip4_addr_t*)ip_2_ip4(&((netif)->ip_addr))) -/** @ingroup netif */ +/** @ingroup netif_ip4 */ #define netif_ip4_netmask(netif) ((const ip4_addr_t*)ip_2_ip4(&((netif)->netmask))) -/** @ingroup netif */ +/** @ingroup netif_ip4 */ #define netif_ip4_gw(netif) ((const ip4_addr_t*)ip_2_ip4(&((netif)->gw))) -/** @ingroup netif */ +/** @ingroup netif_ip4 */ #define netif_ip_addr4(netif) ((const ip_addr_t*)&((netif)->ip_addr)) -/** @ingroup netif */ +/** @ingroup netif_ip4 */ #define netif_ip_netmask4(netif) ((const ip_addr_t*)&((netif)->netmask)) -/** @ingroup netif */ +/** @ingroup netif_ip4 */ #define netif_ip_gw4(netif) ((const ip_addr_t*)&((netif)->gw)) #endif /* LWIP_IPV4 */ @@ -429,9 +429,9 @@ u8_t netif_alloc_client_data_id(void); #endif #if LWIP_IPV6 -/** @ingroup netif */ +/** @ingroup netif_ip6 */ #define netif_ip_addr6(netif, i) ((const ip_addr_t*)(&((netif)->ip6_addr[i]))) -/** @ingroup netif */ +/** @ingroup netif_ip6 */ #define netif_ip6_addr(netif, i) ((const ip6_addr_t*)ip_2_ip6(&((netif)->ip6_addr[i]))) void netif_ip6_addr_set(struct netif *netif, s8_t addr_idx, const ip6_addr_t *addr6); void netif_ip6_addr_set_parts(struct netif *netif, s8_t addr_idx, u32_t i0, u32_t i1, u32_t i2, u32_t i3); diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h index 49b6c17b..eeb3e6c0 100644 --- a/src/include/lwip/opt.h +++ b/src/include/lwip/opt.h @@ -2494,19 +2494,21 @@ #endif /** - * LWIP_HOOK_VLAN_SET(netif, eth_hdr, vlan_hdr): + * LWIP_HOOK_VLAN_SET: * Hook can be used to set prio_vid field of vlan_hdr. - * Called from ethernet_output() if VLAN support is enabled. - * Signature: s32_t my_hook_vlan_set(struct netif* netif, struct pbuf* pbuf, const struct eth_addr* src, const struct eth_addr* dst, u16_t eth_type); + * Called from ethernet_output() if VLAN support (@ref ETHARP_SUPPORT_VLAN) is enabled.\n + * Signature: s32_t my_hook_vlan_set(struct netif* netif, struct pbuf* pbuf, const struct eth_addr* src, const struct eth_addr* dst, u16_t eth_type);\n * Arguments: * - netif: struct netif that the packet will be sent through * - p: struct pbuf packet to be sent * - src: source eth address * - dst: destination eth address - * - eth_type: ethernet type to packet to be sent + * - eth_type: ethernet type to packet to be sent\n + * + * * Return values: - * - <0: Packet shall not contain VLAN header. - * - 0 <= return value <= 0xFFFF: Packet shall contain VLAN header. Return value is prio_vid in host byte order. + * - <0: Packet shall not contain VLAN header. + * - 0 <= return value <= 0xFFFF: Packet shall contain VLAN header. Return value is prio_vid in host byte order. */ #ifdef __DOXYGEN__ #define LWIP_HOOK_VLAN_SET(netif, p, src, dst, eth_type) diff --git a/src/netif/ethernet.c b/src/netif/ethernet.c index 88705f3b..6eeab95a 100644 --- a/src/netif/ethernet.c +++ b/src/netif/ethernet.c @@ -68,6 +68,8 @@ const struct eth_addr ethzero = {{0,0,0,0,0,0}}; * * @param p the received packet, p->payload pointing to the ethernet header * @param netif the network interface on which the packet was received + * + * @see @ref LWIP_HOOK_UNKNOWN_ETH_PROTOCOL */ err_t ethernet_input(struct pbuf *p, struct netif *netif) @@ -243,7 +245,7 @@ free_and_return: * Send an ethernet packet on the network using netif->linkoutput(). * The ethernet header is filled in before sending. * - * @see @ref LWIP_HOOK_UNKNOWN_ETH_PROTOCOL + * @see @ref LWIP_HOOK_VLAN_SET * * @param netif the lwIP network interface on which to send the packet * @param p the packet to send. pbuf layer must be @ref PBUF_LINK. From 537bd836c98948fb85a0344232a8228e7dbca847 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Thu, 25 Aug 2016 22:23:11 +0200 Subject: [PATCH 185/325] Minor: More documentation updates --- doc/NO_SYS_SampleCode.c | 19 ++++++++++--------- src/netif/ethernet.c | 4 +++- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/doc/NO_SYS_SampleCode.c b/doc/NO_SYS_SampleCode.c index fea32d67..a8dc377b 100644 --- a/doc/NO_SYS_SampleCode.c +++ b/doc/NO_SYS_SampleCode.c @@ -10,7 +10,7 @@ void eth_mac_irq() pbuf_take(p, eth_data, eth_data_count); /* Put in a queue which is processed in main loop */ - if(!queue->tryPut(p)) { + if(!queue_try_put(&queue, p)) { /* queue is full -> packet loss */ pbuf_free(p); } @@ -30,10 +30,10 @@ static err_t netif_output(struct netif *netif, struct pbuf *p) MIB2_STATS_NETIF_INC(netif, ifoutnucastpkts); } - LockInterrupts(); + lock_interrupts(); pbuf_copy_partial(p, mac_send_buffer, p->tot_len, 0); /* Start MAC transmit here */ - UnlockInterrupts(); + unlock_interrupts(); return ERR_OK; } @@ -71,13 +71,14 @@ void main(void) netif_set_default(&netif); netif_set_up(&netif); - /* Start DHCP */ + /* Start DHCP and HTTPD */ dhcp_init(); + httpd_init(); while(1) { /* Check link state, e.g. via MDIO communication with PHY */ - if(linkStateChanged()) { - if(linkIsUp()) { + if(link_state_changed()) { + if(link_is_up()) { netif_set_link_up(&netif); } else { netif_set_link_down(&netif); @@ -85,9 +86,9 @@ void main(void) } /* Check for received frames, feed them to lwIP */ - LockInterrupts(); - struct pbuf* p = queue->tryGet(); - UnlockInterrupts(); + lock_interrupts(); + struct pbuf* p = queue_try_get(&queue); + unlock_interrupts(); if(p != NULL) { LINK_STATS_INC(link.recv); diff --git a/src/netif/ethernet.c b/src/netif/ethernet.c index 6eeab95a..621838e1 100644 --- a/src/netif/ethernet.c +++ b/src/netif/ethernet.c @@ -69,7 +69,9 @@ const struct eth_addr ethzero = {{0,0,0,0,0,0}}; * @param p the received packet, p->payload pointing to the ethernet header * @param netif the network interface on which the packet was received * - * @see @ref LWIP_HOOK_UNKNOWN_ETH_PROTOCOL + * @see @ref LWIP_HOOK_UNKNOWN_ETH_PROTOCOL, + * @ref ETHARP_SUPPORT_VLAN and + * @ref LWIP_HOOK_VLAN_CHECK. */ err_t ethernet_input(struct pbuf *p, struct netif *netif) From 0d510dd66ddd38fa5c1330b9a763319d2929ac41 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Fri, 26 Aug 2016 11:21:49 +0200 Subject: [PATCH 186/325] Add API macros for netif client data handling and update documentation accordingly --- doc/doxygen/lwip.Doxyfile | 1 + src/core/ipv4/autoip.c | 6 +++--- src/core/ipv4/dhcp.c | 8 ++++---- src/core/netif.c | 7 ++++++- src/include/lwip/netif.h | 8 ++++++++ src/include/lwip/opt.h | 3 ++- 6 files changed, 24 insertions(+), 9 deletions(-) diff --git a/doc/doxygen/lwip.Doxyfile b/doc/doxygen/lwip.Doxyfile index 8a638ba8..c86326b0 100644 --- a/doc/doxygen/lwip.Doxyfile +++ b/doc/doxygen/lwip.Doxyfile @@ -2096,6 +2096,7 @@ PREDEFINED = __DOXYGEN__=1 \ LWIP_NETIF_STATUS_CALLBACK=1 \ LWIP_NETIF_REMOVE_CALLBACK=1 \ LWIP_NETIF_LINK_CALLBACK=1 \ + LWIP_NUM_NETIF_CLIENT_DATA=1 \ ENABLE_LOOPBACK=1 \ LWIP_AUTOIP=1 \ ARP_QUEUEING=1 \ diff --git a/src/core/ipv4/autoip.c b/src/core/ipv4/autoip.c index 7b53ef1d..01fccf8a 100644 --- a/src/core/ipv4/autoip.c +++ b/src/core/ipv4/autoip.c @@ -95,7 +95,7 @@ static err_t autoip_arp_announce(struct netif *netif); static void autoip_start_probing(struct netif *netif); -#define netif_autoip_data(netif) ((struct autoip*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP]) +#define netif_autoip_data(netif) ((struct autoip*)netif_get_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP)) /** * @ingroup autoip @@ -116,7 +116,7 @@ autoip_set_struct(struct netif *netif, struct autoip *autoip) /* clear data structure */ memset(autoip, 0, sizeof(struct autoip)); /* autoip->state = AUTOIP_STATE_OFF; */ - netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP] = autoip; + netif_set_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP, autoip); } /** Restart AutoIP client and check the next address (conflict detected) @@ -281,7 +281,7 @@ autoip_start(struct netif *netif) } memset(autoip, 0, sizeof(struct autoip)); /* store this AutoIP client in the netif */ - netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP] = autoip; + netif_set_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP, autoip); LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE, ("autoip_start(): allocated autoip")); } else { autoip->state = AUTOIP_STATE_OFF; diff --git a/src/core/ipv4/dhcp.c b/src/core/ipv4/dhcp.c index d9ee38ed..46bfcf2c 100644 --- a/src/core/ipv4/dhcp.c +++ b/src/core/ipv4/dhcp.c @@ -193,7 +193,7 @@ static void dhcp_option_hostname(struct dhcp *dhcp, struct netif *netif); /* always add the DHCP options trailer to end and pad */ static void dhcp_option_trailer(struct dhcp *dhcp); -#define netif_dhcp_data(netif) ((struct dhcp*)netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP]) +#define netif_dhcp_data(netif) ((struct dhcp*)netif_get_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_DHCP)) /** Ensure DHCP PCB is allocated and bound */ static err_t @@ -668,7 +668,7 @@ dhcp_set_struct(struct netif *netif, struct dhcp *dhcp) /* clear data structure */ memset(dhcp, 0, sizeof(struct dhcp)); /* dhcp_set_state(&dhcp, DHCP_STATE_OFF); */ - netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP] = dhcp; + netif_set_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_DHCP, dhcp); } /** @@ -686,7 +686,7 @@ void dhcp_cleanup(struct netif *netif) if (netif_dhcp_data(netif) != NULL) { mem_free(netif_dhcp_data(netif)); - netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP] = NULL; + netif_set_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_DHCP, NULL); } } @@ -730,7 +730,7 @@ dhcp_start(struct netif *netif) } /* store this dhcp client in the netif */ - netif->client_data[LWIP_NETIF_CLIENT_DATA_INDEX_DHCP] = dhcp; + netif_set_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_DHCP, dhcp); LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_start(): allocated dhcp")); /* already has DHCP client attached */ } else { diff --git a/src/core/netif.c b/src/core/netif.c index d6cfb55c..1c4b1b42 100644 --- a/src/core/netif.c +++ b/src/core/netif.c @@ -10,6 +10,11 @@ * * @defgroup netif_ip6 IPv6 address handling * @ingroup netif + * + * @defgroup netif_cd Client data handling + * Store data (void*) on a netif for application usage. + * @see @ref LWIP_NUM_NETIF_CLIENT_DATA + * @ingroup netif */ /* @@ -967,7 +972,7 @@ netif_poll_all(void) #if LWIP_NUM_NETIF_CLIENT_DATA > 0 /** - * @ingroup netif + * @ingroup netif_cd * Allocate an index to store data in client_data member of struct netif. * Returned value is an index in mentioned array. * @see LWIP_NUM_NETIF_CLIENT_DATA diff --git a/src/include/lwip/netif.h b/src/include/lwip/netif.h index 1b5f21c7..c039da1f 100644 --- a/src/include/lwip/netif.h +++ b/src/include/lwip/netif.h @@ -426,6 +426,14 @@ err_t netif_input(struct pbuf *p, struct netif *inp); #if LWIP_NUM_NETIF_CLIENT_DATA > 0 u8_t netif_alloc_client_data_id(void); +/** @ingroup netif_cd + * Set client data. Obtain ID from netif_alloc_client_data_id(). + */ +#define netif_set_client_data(netif, id, data) netif_get_client_data(netif, id) = (data) +/** @ingroup netif_cd + * Get client data. Obtain ID from netif_alloc_client_data_id(). + */ +#define netif_get_client_data(netif, id) (netif)->client_data[(id)] #endif #if LWIP_IPV6 diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h index eeb3e6c0..01631c62 100644 --- a/src/include/lwip/opt.h +++ b/src/include/lwip/opt.h @@ -2495,7 +2495,8 @@ /** * LWIP_HOOK_VLAN_SET: - * Hook can be used to set prio_vid field of vlan_hdr. + * Hook can be used to set prio_vid field of vlan_hdr. If you need to store data + * on per-netif basis to implement this callback, see @ref netif_cd. * Called from ethernet_output() if VLAN support (@ref ETHARP_SUPPORT_VLAN) is enabled.\n * Signature: s32_t my_hook_vlan_set(struct netif* netif, struct pbuf* pbuf, const struct eth_addr* src, const struct eth_addr* dst, u16_t eth_type);\n * Arguments: From 05a6d82fa17b02a9895e2447879df57dab92c7ce Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Fri, 26 Aug 2016 15:39:15 +0200 Subject: [PATCH 187/325] Let comment in pbuf.h be consistent with provided example function --- src/include/lwip/pbuf.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/include/lwip/pbuf.h b/src/include/lwip/pbuf.h index d21ab8cb..460e310d 100644 --- a/src/include/lwip/pbuf.h +++ b/src/include/lwip/pbuf.h @@ -70,7 +70,7 @@ extern "C" { * Enumeration of pbuf layers */ typedef enum { - /** Includes spare room for transport layer header, e.g. TCP header. + /** Includes spare room for transport layer header, e.g. UDP header. * Use this if you intend to pass the pbuf to functions like udp_send(). */ PBUF_TRANSPORT, From 4b45baee101b02f29143c22db92f33162edb1ece Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Fri, 26 Aug 2016 15:58:18 +0200 Subject: [PATCH 188/325] Add some dual-stack notes to documentation --- src/core/raw.c | 2 ++ src/core/tcp.c | 2 ++ src/core/udp.c | 2 ++ src/include/lwip/ip_addr.h | 6 +++++- 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/core/raw.c b/src/core/raw.c index efa21f90..a3a90778 100644 --- a/src/core/raw.c +++ b/src/core/raw.c @@ -472,6 +472,8 @@ raw_new(u8_t proto) * could not be allocated. * * @param type IP address type, see IPADDR_TYPE_XX definitions. + * If you want to listen to IPv4 and IPv6 (dual-stack) packets, + * supply @ref IPADDR_TYPE_ANY as argument and bind to @ref IP_ANY_TYPE. * @param proto the protocol number (next header) of the IPv6 packet payload * (e.g. IP6_NEXTH_ICMP6) * diff --git a/src/core/tcp.c b/src/core/tcp.c index 7f15c04c..64eef699 100644 --- a/src/core/tcp.c +++ b/src/core/tcp.c @@ -1603,6 +1603,8 @@ tcp_new(void) * The pcb is not put on any list until binding using tcp_bind(). * * @param type IP address type, see IPADDR_TYPE_XX definitions. + * If you want to listen to IPv4 and IPv6 (dual-stack) connections, + * supply @ref IPADDR_TYPE_ANY as argument and bind to @ref IP_ANY_TYPE. * @return a new tcp_pcb that initially is in state CLOSED */ struct tcp_pcb * diff --git a/src/core/udp.c b/src/core/udp.c index 04a64537..60d3f4a6 100644 --- a/src/core/udp.c +++ b/src/core/udp.c @@ -1145,6 +1145,8 @@ udp_new(void) * Create a UDP PCB for specific IP type. * * @param type IP address type, see IPADDR_TYPE_XX definitions. + * If you want to listen to IPv4 and IPv6 (dual-stack) packets, + * supply @ref IPADDR_TYPE_ANY as argument and bind to @ref IP_ANY_TYPE. * @return The UDP PCB which was created. NULL if the PCB data structure * could not be allocated. * diff --git a/src/include/lwip/ip_addr.h b/src/include/lwip/ip_addr.h index 5523ee02..4b13e702 100644 --- a/src/include/lwip/ip_addr.h +++ b/src/include/lwip/ip_addr.h @@ -47,9 +47,13 @@ extern "C" { #endif -/** These are the values for ip_addr_t.type */ +/** Value for ip_addr_t.type: IPv4 */ #define IPADDR_TYPE_V4 0U +/** Value for ip_addr_t.type: IPv6 */ #define IPADDR_TYPE_V6 6U +/** Value for ip_addr_t.type: IPv4+IPv6 ("dual-stack") + * @see tcp_new_ip_type(), udp_new_ip_type(), raw_new_ip_type(). + */ #define IPADDR_TYPE_ANY 46U #if LWIP_IPV4 && LWIP_IPV6 From c9dff6b5aab2a0b979d1701e344e920ff64748f0 Mon Sep 17 00:00:00 2001 From: Joel Cunningham Date: Fri, 26 Aug 2016 09:33:14 -0500 Subject: [PATCH 189/325] Correct TCP_OOSEQ_MAX_* opt.h documentation This corrects documentation on TCP_OOSEQ_MAX_BYTES and _PBUFS to list their dependency on TCP_QUEUE_OOSEQ==1 (out of order sequence queueing enabled) rather than ==0 (disabled) --- src/include/lwip/opt.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h index 01631c62..1568080c 100644 --- a/src/include/lwip/opt.h +++ b/src/include/lwip/opt.h @@ -1235,7 +1235,7 @@ /** * TCP_OOSEQ_MAX_BYTES: The maximum number of bytes queued on ooseq per pcb. - * Default is 0 (no limit). Only valid for TCP_QUEUE_OOSEQ==0. + * Default is 0 (no limit). Only valid for TCP_QUEUE_OOSEQ==1. */ #if !defined TCP_OOSEQ_MAX_BYTES || defined __DOXYGEN__ #define TCP_OOSEQ_MAX_BYTES 0 @@ -1243,7 +1243,7 @@ /** * TCP_OOSEQ_MAX_PBUFS: The maximum number of pbufs queued on ooseq per pcb. - * Default is 0 (no limit). Only valid for TCP_QUEUE_OOSEQ==0. + * Default is 0 (no limit). Only valid for TCP_QUEUE_OOSEQ==1. */ #if !defined TCP_OOSEQ_MAX_PBUFS || defined __DOXYGEN__ #define TCP_OOSEQ_MAX_PBUFS 0 From db6aa82a10a3ccfae4eaebdfc4ceb88bb7d15f14 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Fri, 26 Aug 2016 23:13:05 +0800 Subject: [PATCH 190/325] memp: Fix comment for memp_overflow_check_element_overflow/underflow These functions now take desc rather than memp_type as second parameter. Signed-off-by: Axel Lin --- src/core/memp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/memp.c b/src/core/memp.c index 94559922..19198eb7 100644 --- a/src/core/memp.c +++ b/src/core/memp.c @@ -119,7 +119,7 @@ memp_sanity(const struct memp_desc *desc) * (e.g. the restricted area after it has been altered) * * @param p the memp element to check - * @param memp_type the pool p comes from + * @param desc the pool p comes from */ static void memp_overflow_check_element_overflow(struct memp *p, const struct memp_desc *desc) @@ -146,7 +146,7 @@ memp_overflow_check_element_overflow(struct memp *p, const struct memp_desc *des * (e.g. the restricted area before it has been altered) * * @param p the memp element to check - * @param memp_type the pool p comes from + * @param desc the pool p comes from */ static void memp_overflow_check_element_underflow(struct memp *p, const struct memp_desc *desc) From fb62e9350fb54fd398b24a02023a0ad4652e74c8 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Mon, 29 Aug 2016 19:15:22 +0200 Subject: [PATCH 191/325] Fix wrong sizeof() and remove superfluous NULL pointer check in MDNS --- src/apps/mdns/mdns.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/apps/mdns/mdns.c b/src/apps/mdns/mdns.c index d8bf02ae..900b936a 100644 --- a/src/apps/mdns/mdns.c +++ b/src/apps/mdns/mdns.c @@ -632,7 +632,7 @@ mdns_build_service_domain(struct mdns_domain *domain, struct mdns_service *servi } res = mdns_domain_add_label(domain, service->service, (u8_t)strlen(service->service)); LWIP_ERROR("mdns_build_service_domain: Failed to add label", (res == ERR_OK), return res); - res = mdns_domain_add_label(domain, dnssd_protos[service->proto], (u8_t)(sizeof((dnssd_protos[service->proto])-1))); + res = mdns_domain_add_label(domain, dnssd_protos[service->proto], (u8_t)(sizeof(dnssd_protos[DNSSD_PROTO_UDP])-1)); LWIP_ERROR("mdns_build_service_domain: Failed to add label", (res == ERR_OK), return res); return mdns_add_dotlocal(domain); } @@ -819,7 +819,7 @@ mdns_write_domain(struct mdns_outpacket *outpkt, struct mdns_domain *domain) u16_t jump_offset = 0; u16_t jump; - if (outpkt && outpkt->pbuf && !domain->skip_compression) { + if (!domain->skip_compression) { for (i = 0; i < NUM_DOMAIN_OFFSETS; ++i) { u16_t offset = outpkt->domain_offsets[i]; if (offset) { From e545262d9850d4c1a82994aee6a51ffe8b0f0354 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Mon, 29 Aug 2016 19:32:39 +0200 Subject: [PATCH 192/325] Remove superfluous parameter from mdns_domain_debug_print() --- src/apps/mdns/mdns.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/apps/mdns/mdns.c b/src/apps/mdns/mdns.c index 900b936a..c512904a 100644 --- a/src/apps/mdns/mdns.c +++ b/src/apps/mdns/mdns.c @@ -414,11 +414,10 @@ mdns_readname(struct pbuf *p, u16_t offset, struct mdns_domain *domain) /** * Print domain name to debug output - * @param debug debug level * @param domain The domain name */ static void -mdns_domain_debug_print(int debug, struct mdns_domain *domain) +mdns_domain_debug_print(struct mdns_domain *domain) { u8_t *src = domain->name; u8_t i; @@ -427,10 +426,10 @@ mdns_domain_debug_print(int debug, struct mdns_domain *domain) u8_t label_len = *src; src++; for (i = 0; i < label_len; i++) { - LWIP_DEBUGF(debug, ("%c", src[i])); + LWIP_DEBUGF(MDNS_DEBUG, ("%c", src[i])); } src += label_len; - LWIP_DEBUGF(debug, (".")); + LWIP_DEBUGF(MDNS_DEBUG, (".")); } } @@ -1543,7 +1542,7 @@ mdns_handle_question(struct mdns_packet *pkt) } LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: Query for domain ")); - mdns_domain_debug_print(MDNS_DEBUG, &q.info.domain); + mdns_domain_debug_print(&q.info.domain); LWIP_DEBUGF(MDNS_DEBUG, (" type %d class %d\n", q.info.type, q.info.klass)); if (q.unicast) { @@ -1585,7 +1584,7 @@ mdns_handle_question(struct mdns_packet *pkt) } LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: Known answer for domain ")); - mdns_domain_debug_print(MDNS_DEBUG, &ans.info.domain); + mdns_domain_debug_print(&ans.info.domain); LWIP_DEBUGF(MDNS_DEBUG, (" type %d class %d\n", ans.info.type, ans.info.klass)); @@ -1761,7 +1760,7 @@ mdns_handle_response(struct mdns_packet *pkt) } LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: Answer for domain ")); - mdns_domain_debug_print(MDNS_DEBUG, &ans.info.domain); + mdns_domain_debug_print(&ans.info.domain); LWIP_DEBUGF(MDNS_DEBUG, (" type %d class %d\n", ans.info.type, ans.info.klass)); } } From ef827e85b8aa8fda66005fdbfce94cee02f66378 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Tue, 30 Aug 2016 10:05:42 +0800 Subject: [PATCH 193/325] apps/mdns: Fixup LWIP_ERROR message in mdns_build_host_domain Signed-off-by: Axel Lin Signed-off-by: Dirk Ziegelmeier --- src/apps/mdns/mdns.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/apps/mdns/mdns.c b/src/apps/mdns/mdns.c index c512904a..1f121266 100644 --- a/src/apps/mdns/mdns.c +++ b/src/apps/mdns/mdns.c @@ -586,7 +586,7 @@ mdns_build_host_domain(struct mdns_domain *domain, struct mdns_host *mdns) { err_t res; memset(domain, 0, sizeof(struct mdns_domain)); - LWIP_ERROR("mdns_resp_add_service: Not an mdns netif", (mdns != NULL), return ERR_VAL); + LWIP_ERROR("mdns_build_host_domain: Not an mdns netif", (mdns != NULL), return ERR_VAL); res = mdns_domain_add_label(domain, mdns->name, (u8_t)strlen(mdns->name)); LWIP_ERROR("mdns_build_host_domain: Failed to add label", (res == ERR_OK), return res); return mdns_add_dotlocal(domain); From 198fa5dbfa353fb2c75fb3e7eb550a5f4ef179ef Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Tue, 30 Aug 2016 15:42:27 +0800 Subject: [PATCH 194/325] Remove duplicated include for lwip/inet_chksum.h Include it once is enough. Signed-off-by: Axel Lin Signed-off-by: Dirk Ziegelmeier --- src/core/tcp_in.c | 1 - src/core/tcp_out.c | 1 - src/core/udp.c | 1 - 3 files changed, 3 deletions(-) diff --git a/src/core/tcp_in.c b/src/core/tcp_in.c index c618e006..dd88e1e5 100644 --- a/src/core/tcp_in.c +++ b/src/core/tcp_in.c @@ -55,7 +55,6 @@ #include "lwip/stats.h" #include "lwip/ip6.h" #include "lwip/ip6_addr.h" -#include "lwip/inet_chksum.h" #if LWIP_ND6_TCP_REACHABILITY_HINTS #include "lwip/nd6.h" #endif /* LWIP_ND6_TCP_REACHABILITY_HINTS */ diff --git a/src/core/tcp_out.c b/src/core/tcp_out.c index 7e1803fe..70bdfea5 100644 --- a/src/core/tcp_out.c +++ b/src/core/tcp_out.c @@ -52,7 +52,6 @@ #include "lwip/stats.h" #include "lwip/ip6.h" #include "lwip/ip6_addr.h" -#include "lwip/inet_chksum.h" #if LWIP_TCP_TIMESTAMPS #include "lwip/sys.h" #endif diff --git a/src/core/udp.c b/src/core/udp.c index 60d3f4a6..20e97da6 100644 --- a/src/core/udp.c +++ b/src/core/udp.c @@ -56,7 +56,6 @@ #include "lwip/ip_addr.h" #include "lwip/ip6.h" #include "lwip/ip6_addr.h" -#include "lwip/inet_chksum.h" #include "lwip/netif.h" #include "lwip/icmp.h" #include "lwip/icmp6.h" From 840d1e60faec96c5556a717fbc55d00c58b433f8 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Tue, 30 Aug 2016 21:07:37 +0200 Subject: [PATCH 195/325] Fix bug #48924: Potential out of bound reads in DNS codes of lwip project by adding checks for pbuf_copy_partial() return values. Add some comments to clarify handling of untrusted network data handling. --- src/core/dns.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/core/dns.c b/src/core/dns.c index cc8dc852..46498667 100644 --- a/src/core/dns.c +++ b/src/core/dns.c @@ -640,6 +640,7 @@ dns_parse_name(struct pbuf* p, u16_t query_idx) unsigned char n; do { + /* pbuf_get_at() returns 0 on out-of-bounds access, so we will terminate */ n = pbuf_get_at(p, query_idx++); /** @see RFC 1035 - 4.1.4. Message compression */ if ((n & 0xc0) == 0xc0) { @@ -652,6 +653,7 @@ dns_parse_name(struct pbuf* p, u16_t query_idx) --n; } } + /* pbuf_get_at() returns 0 on out-of-bounds access, so we will terminate */ } while (pbuf_get_at(p, query_idx) != 0); return query_idx + 1; @@ -1096,7 +1098,9 @@ dns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, } /* check if "question" part matches the request */ - pbuf_copy_partial(p, &qry, SIZEOF_DNS_QUERY, res_idx); + if (pbuf_copy_partial(p, &qry, SIZEOF_DNS_QUERY, res_idx) != SIZEOF_DNS_QUERY) { + goto memerr; /* ignore this packet */ + } if ((qry.cls != PP_HTONS(DNS_RRCLASS_IN)) || (LWIP_DNS_ADDRTYPE_IS_IPV6(entry->reqaddrtype) && (qry.type != PP_HTONS(DNS_RRTYPE_AAAA))) || (!LWIP_DNS_ADDRTYPE_IS_IPV6(entry->reqaddrtype) && (qry.type != PP_HTONS(DNS_RRTYPE_A)))) { @@ -1113,10 +1117,16 @@ dns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, while ((nanswers > 0) && (res_idx < p->tot_len)) { /* skip answer resource record's host name */ res_idx = dns_parse_name(p, res_idx); + /* dns_parse_name() may return an res_idx out of pbuf bounds. + * This will be caught in pbuf_copy_partial() below. + */ /* Check for IP address type and Internet class. Others are discarded. */ - pbuf_copy_partial(p, &ans, SIZEOF_DNS_ANSWER, res_idx); + if (pbuf_copy_partial(p, &ans, SIZEOF_DNS_ANSWER, res_idx) != SIZEOF_DNS_ANSWER) { + goto memerr; /* ignore this packet */ + } res_idx += SIZEOF_DNS_ANSWER; + if (ans.cls == PP_HTONS(DNS_RRCLASS_IN)) { #if LWIP_IPV4 if ((ans.type == PP_HTONS(DNS_RRTYPE_A)) && (ans.len == PP_HTONS(sizeof(ip4_addr_t)))) { @@ -1126,7 +1136,9 @@ dns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, { ip4_addr_t ip4addr; /* read the IP address after answer resource record's header */ - pbuf_copy_partial(p, &ip4addr, sizeof(ip4_addr_t), res_idx); + if (pbuf_copy_partial(p, &ip4addr, sizeof(ip4_addr_t), res_idx) != sizeof(ip4_addr_t)) { + goto memerr; /* ignore this packet */ + } ip_addr_copy_from_ip4(dns_table[i].ipaddr, ip4addr); pbuf_free(p); /* handle correct response */ @@ -1143,7 +1155,9 @@ dns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, { ip6_addr_t ip6addr; /* read the IP address after answer resource record's header */ - pbuf_copy_partial(p, &ip6addr, sizeof(ip6_addr_t), res_idx); + if (pbuf_copy_partial(p, &ip6addr, sizeof(ip6_addr_t), res_idx) != sizeof(ip6_addr_t)) { + goto memerr; /* ignore this packet */ + } ip_addr_copy_from_ip6(dns_table[i].ipaddr, ip6addr); pbuf_free(p); /* handle correct response */ From aef3d2cb87c0151243ad63998946f3c21414dc29 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Tue, 30 Aug 2016 21:08:12 +0200 Subject: [PATCH 196/325] Minor coding style fix in pbuf.c --- src/core/pbuf.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/core/pbuf.c b/src/core/pbuf.c index c290e492..c7b8812d 100644 --- a/src/core/pbuf.c +++ b/src/core/pbuf.c @@ -982,8 +982,9 @@ pbuf_copy_partial(struct pbuf *buf, void *dataptr, u16_t len, u16_t offset) } else { /* copy from this buffer. maybe only partially. */ buf_copy_len = p->len - offset; - if (buf_copy_len > len) - buf_copy_len = len; + if (buf_copy_len > len) { + buf_copy_len = len; + } /* copy the necessary parts of the buffer */ MEMCPY(&((char*)dataptr)[left], &((char*)p->payload)[offset], buf_copy_len); copied_total += buf_copy_len; From 2137f49d32c36bf39eb57d32ea23135706003204 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Tue, 30 Aug 2016 21:20:58 +0200 Subject: [PATCH 197/325] Fix usage of uninitialized data in nd6.c because of unchecked pbuf_copy_partial() return value --- src/core/ipv6/nd6.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/core/ipv6/nd6.c b/src/core/ipv6/nd6.c index ec29a9bb..ff26d095 100644 --- a/src/core/ipv6/nd6.c +++ b/src/core/ipv6/nd6.c @@ -447,7 +447,12 @@ nd6_input(struct pbuf *p, struct netif *inp) buffer = &((u8_t*)p->payload)[offset]; } else { buffer = nd6_ra_buffer; - pbuf_copy_partial(p, buffer, sizeof(struct prefix_option), offset); + if (pbuf_copy_partial(p, buffer, sizeof(struct prefix_option), offset) != sizeof(struct prefix_option)) { + pbuf_free(p); + ND6_STATS_INC(nd6.lenerr); + ND6_STATS_INC(nd6.drop); + return; + } } if (buffer[1] == 0) { /* zero-length extension. drop packet */ From f5135b05d90028bb4aa2a05beab52841b823c8f4 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Tue, 30 Aug 2016 21:21:32 +0200 Subject: [PATCH 198/325] Minor coding style fixes in mdns.c --- src/apps/mdns/mdns.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/apps/mdns/mdns.c b/src/apps/mdns/mdns.c index 1f121266..4cf32ea1 100644 --- a/src/apps/mdns/mdns.c +++ b/src/apps/mdns/mdns.c @@ -377,9 +377,8 @@ mdns_readname_loop(struct pbuf *p, u16_t offset, struct mdns_domain *domain, uns if (c + domain->length >= MDNS_DOMAIN_MAXLEN) { return MDNS_READNAME_ERROR; } - if (c) { - u16_t copied = pbuf_copy_partial(p, label, c, offset); - if (copied != c) { + if (c != 0) { + if (pbuf_copy_partial(p, label, c, offset) != c) { return MDNS_READNAME_ERROR; } offset += c; @@ -392,7 +391,7 @@ mdns_readname_loop(struct pbuf *p, u16_t offset, struct mdns_domain *domain, uns /* bad length byte */ return MDNS_READNAME_ERROR; } - } while (c); + } while (c != 0); return offset; } From 8d45162a59481cc6ed35e9ff9ebf13b18cbf7d9a Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Tue, 30 Aug 2016 21:33:43 +0200 Subject: [PATCH 199/325] Fix usage of uninitialized data in dhcp.c by checking pbuf_copy_partial() return value --- src/core/ipv4/dhcp.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/core/ipv4/dhcp.c b/src/core/ipv4/dhcp.c index 46bfcf2c..4ffd86b0 100644 --- a/src/core/ipv4/dhcp.c +++ b/src/core/ipv4/dhcp.c @@ -1493,7 +1493,7 @@ again: int decode_idx = -1; u16_t val_offset = offset + 2; /* len byte might be in the next pbuf */ - if (offset + 1 < q->len) { + if ((offset + 1) < q->len) { len = options[offset + 1]; } else { len = (q->next != NULL ? ((u8_t*)q->next->payload)[0] : 0); @@ -1572,7 +1572,9 @@ decode_next: LWIP_ASSERT("check decode_idx", decode_idx >= 0 && decode_idx < DHCP_OPTION_IDX_MAX); if (!dhcp_option_given(dhcp, decode_idx)) { copy_len = LWIP_MIN(decode_len, 4); - pbuf_copy_partial(q, &value, copy_len, val_offset); + if (pbuf_copy_partial(q, &value, copy_len, val_offset) != copy_len) { + return ERR_BUF; + } if (decode_len > 4) { /* decode more than one u32_t */ LWIP_ERROR("decode_len % 4 == 0", decode_len % 4 == 0, return ERR_VAL;); @@ -1628,7 +1630,9 @@ decode_next: if (dhcp_option_given(dhcp, DHCP_OPTION_IDX_MSG_TYPE) && (dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_MSG_TYPE) == DHCP_ACK)) /* copy bootp file name, don't care for sname (server hostname) */ - pbuf_copy_partial(p, dhcp->boot_file_name, DHCP_FILE_LEN-1, DHCP_FILE_OFS); + if (pbuf_copy_partial(p, dhcp->boot_file_name, DHCP_FILE_LEN-1, DHCP_FILE_OFS) != (DHCP_FILE_LEN-1)) { + return ERR_BUF; + } /* make sure the string is really NULL-terminated */ dhcp->boot_file_name[DHCP_FILE_LEN-1] = 0; } From a08ed9148d2e79392e32f6546741bb3be9208cfa Mon Sep 17 00:00:00 2001 From: sg Date: Tue, 30 Aug 2016 21:31:00 +0200 Subject: [PATCH 200/325] added pbuf_try_get_at() (much like pbuf_get_at() but can return out-of-pbuf error) --- src/core/pbuf.c | 22 ++++++++++++++++++++-- src/include/lwip/pbuf.h | 1 + 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/core/pbuf.c b/src/core/pbuf.c index c7b8812d..1e6efb05 100644 --- a/src/core/pbuf.c +++ b/src/core/pbuf.c @@ -1223,7 +1223,7 @@ pbuf_fill_chksum(struct pbuf *p, u16_t start_offset, const void *dataptr, } #endif /* LWIP_CHECKSUM_ON_COPY */ -/** +/** * @ingroup pbuf * Get one byte from the specified position in a pbuf * WARNING: returns zero for offset >= p->tot_len @@ -1234,6 +1234,24 @@ pbuf_fill_chksum(struct pbuf *p, u16_t start_offset, const void *dataptr, */ u8_t pbuf_get_at(struct pbuf* p, u16_t offset) +{ + int ret = pbuf_try_get_at(p, offset); + if (ret >= 0) { + return (u8_t)ret; + } + return 0; +} + +/** + * @ingroup pbuf + * Get one byte from the specified position in a pbuf + * + * @param p pbuf to parse + * @param offset offset into p of the byte to return + * @return byte at an offset into p [0..0xFF] OR negative if 'offset' >= p->tot_len + */ +int +pbuf_try_get_at(struct pbuf* p, u16_t offset) { u16_t q_idx; struct pbuf* q = pbuf_skip(p, offset, &q_idx); @@ -1242,7 +1260,7 @@ pbuf_get_at(struct pbuf* p, u16_t offset) if ((q != NULL) && (q->len > q_idx)) { return ((u8_t*)q->payload)[q_idx]; } - return 0; + return -1; } /** diff --git a/src/include/lwip/pbuf.h b/src/include/lwip/pbuf.h index 460e310d..16f96860 100644 --- a/src/include/lwip/pbuf.h +++ b/src/include/lwip/pbuf.h @@ -250,6 +250,7 @@ void pbuf_split_64k(struct pbuf *p, struct pbuf **rest); #endif /* LWIP_TCP && TCP_QUEUE_OOSEQ && LWIP_WND_SCALE */ u8_t pbuf_get_at(struct pbuf* p, u16_t offset); +int pbuf_try_get_at(struct pbuf* p, u16_t offset); void pbuf_put_at(struct pbuf* p, u16_t offset, u8_t data); u16_t pbuf_memcmp(struct pbuf* p, u16_t offset, const void* s2, u16_t n); u16_t pbuf_memfind(struct pbuf* p, const void* mem, u16_t mem_len, u16_t start_offset); From 9078f3154437d690d839c269b1666410a239f248 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Tue, 30 Aug 2016 21:51:05 +0200 Subject: [PATCH 201/325] Minor: memcpy -> MEMCPY / SMEMCPY --- doc/NO_SYS_SampleCode.c | 2 +- src/api/sockets.c | 4 ++-- src/apps/lwiperf/lwiperf.c | 2 +- src/apps/mdns/mdns.c | 14 +++++++------- src/apps/netbiosns/netbiosns.c | 2 +- src/apps/snmp/snmp_msg.c | 6 +++--- src/apps/snmp/snmpv3.c | 8 ++++---- src/apps/snmp/snmpv3_mbedtls.c | 14 +++++++------- 8 files changed, 26 insertions(+), 26 deletions(-) diff --git a/doc/NO_SYS_SampleCode.c b/doc/NO_SYS_SampleCode.c index a8dc377b..f20106f5 100644 --- a/doc/NO_SYS_SampleCode.c +++ b/doc/NO_SYS_SampleCode.c @@ -54,7 +54,7 @@ static err_t netif_init(struct netif *netif) netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_ETHERNET | NETIF_FLAG_IGMP; MIB2_INIT_NETIF(netif, snmp_ifType_ethernet_csmacd, 100000000); - memcpy(netif->hwaddr, your_mac_address_goes_here, sizeof(netif->hwaddr)); + SMEMCPY(netif->hwaddr, your_mac_address_goes_here, sizeof(netif->hwaddr)); netif->hwaddr_len = sizeof(netif->hwaddr); return ERR_OK; diff --git a/src/api/sockets.c b/src/api/sockets.c index 68ff0a51..620e4849 100644 --- a/src/api/sockets.c +++ b/src/api/sockets.c @@ -1829,7 +1829,7 @@ lwip_getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen) /* write back optlen and optval */ *optlen = LWIP_SETGETSOCKOPT_DATA_VAR_REF(data).optlen; #if LWIP_MPU_COMPATIBLE - memcpy(optval, LWIP_SETGETSOCKOPT_DATA_VAR_REF(data).optval, + MEMCPY(optval, LWIP_SETGETSOCKOPT_DATA_VAR_REF(data).optval, LWIP_SETGETSOCKOPT_DATA_VAR_REF(data).optlen); #endif /* LWIP_MPU_COMPATIBLE */ @@ -2217,7 +2217,7 @@ lwip_setsockopt(int s, int level, int optname, const void *optval, socklen_t opt LWIP_SETGETSOCKOPT_DATA_VAR_REF(data).optname = optname; LWIP_SETGETSOCKOPT_DATA_VAR_REF(data).optlen = optlen; #if LWIP_MPU_COMPATIBLE - memcpy(LWIP_SETGETSOCKOPT_DATA_VAR_REF(data).optval, optval, optlen); + MEMCPY(LWIP_SETGETSOCKOPT_DATA_VAR_REF(data).optval, optval, optlen); #else /* LWIP_MPU_COMPATIBLE */ LWIP_SETGETSOCKOPT_DATA_VAR_REF(data).optval.pc = (const void*)optval; #endif /* LWIP_MPU_COMPATIBLE */ diff --git a/src/apps/lwiperf/lwiperf.c b/src/apps/lwiperf/lwiperf.c index 1682f358..fea2c06f 100644 --- a/src/apps/lwiperf/lwiperf.c +++ b/src/apps/lwiperf/lwiperf.c @@ -374,7 +374,7 @@ lwiperf_tx_start(lwiperf_state_tcp_t* conn) return ERR_MEM; } - memcpy(client_conn, conn, sizeof(lwiperf_state_tcp_t)); + MEMCPY(client_conn, conn, sizeof(lwiperf_state_tcp_t)); client_conn->base.server = 0; client_conn->server_pcb = NULL; client_conn->conn_pcb = newpcb; diff --git a/src/apps/mdns/mdns.c b/src/apps/mdns/mdns.c index 4cf32ea1..6fc7ce7f 100644 --- a/src/apps/mdns/mdns.c +++ b/src/apps/mdns/mdns.c @@ -322,7 +322,7 @@ mdns_domain_add_label(struct mdns_domain *domain, const char *label, u8_t len) domain->name[domain->length] = len; domain->length++; if (len) { - memcpy(&domain->name[domain->length], label, len); + MEMCPY(&domain->name[domain->length], label, len); domain->length += len; } return ERR_OK; @@ -1256,7 +1256,7 @@ mdns_init_outpacket(struct mdns_outpacket *out, struct mdns_packet *in) /* Copy source IP/port to use when responding unicast, or to choose * which pcb to use for multicast (IPv4/IPv6) */ - memcpy(&out->dest_addr, &in->source_addr, sizeof(ip_addr_t)); + SMEMCPY(&out->dest_addr, &in->source_addr, sizeof(ip_addr_t)); out->dest_port = in->source_port; if (in->source_port != MDNS_PORT) { @@ -1509,7 +1509,7 @@ mdns_announce(struct netif *netif, const ip_addr_t *destination) } announce.dest_port = MDNS_PORT; - memcpy(&announce.dest_addr, destination, sizeof(announce.dest_addr)); + SMEMCPY(&announce.dest_addr, destination, sizeof(announce.dest_addr)); mdns_send_outpacket(&announce); } @@ -1800,7 +1800,7 @@ mdns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, } memset(&packet, 0, sizeof(packet)); - memcpy(&packet.source_addr, addr, sizeof(packet.source_addr)); + SMEMCPY(&packet.source_addr, addr, sizeof(packet.source_addr)); packet.source_port = port; packet.netif = recv_netif; packet.pbuf = p; @@ -1909,7 +1909,7 @@ mdns_resp_add_netif(struct netif *netif, const char *hostname, u32_t dns_ttl) netif->client_data[mdns_netif_client_id] = mdns; memset(mdns, 0, sizeof(struct mdns_host)); - memcpy(&mdns->name, hostname, LWIP_MIN(MDNS_LABEL_MAXLEN, strlen(hostname))); + MEMCPY(&mdns->name, hostname, LWIP_MIN(MDNS_LABEL_MAXLEN, strlen(hostname))); mdns->dns_ttl = dns_ttl; /* Join multicast groups */ @@ -2016,8 +2016,8 @@ mdns_resp_add_service(struct netif *netif, const char *name, const char *service memset(srv, 0, sizeof(struct mdns_service)); - memcpy(&srv->name, name, LWIP_MIN(MDNS_LABEL_MAXLEN, strlen(name))); - memcpy(&srv->service, service, LWIP_MIN(MDNS_LABEL_MAXLEN, strlen(service))); + MEMCPY(&srv->name, name, LWIP_MIN(MDNS_LABEL_MAXLEN, strlen(name))); + MEMCPY(&srv->service, service, LWIP_MIN(MDNS_LABEL_MAXLEN, strlen(service))); srv->txt_fn = txt_fn; srv->txt_userdata = txt_data; srv->proto = (u16_t)proto; diff --git a/src/apps/netbiosns/netbiosns.c b/src/apps/netbiosns/netbiosns.c index dd01c026..1b1f952e 100644 --- a/src/apps/netbiosns/netbiosns.c +++ b/src/apps/netbiosns/netbiosns.c @@ -346,7 +346,7 @@ netbiosns_set_name(const char* hostname) if (copy_len >= NETBIOS_NAME_LEN) { copy_len = NETBIOS_NAME_LEN - 1; } - memcpy(netbiosns_local_name, hostname, copy_len + 1); + MEMCPY(netbiosns_local_name, hostname, copy_len + 1); } #endif diff --git a/src/apps/snmp/snmp_msg.c b/src/apps/snmp/snmp_msg.c index 6a083ad1..b06266f6 100644 --- a/src/apps/snmp/snmp_msg.c +++ b/src/apps/snmp/snmp_msg.c @@ -1067,7 +1067,7 @@ snmp_prepare_outbound_frame(struct snmp_request *request) /* msgAuthoritativeEngineID */ snmpv3_get_engine_id(&id, &request->msg_authoritative_engine_id_len); - memcpy(request->msg_authoritative_engine_id, id, request->msg_authoritative_engine_id_len); + MEMCPY(request->msg_authoritative_engine_id, id, request->msg_authoritative_engine_id_len); SNMP_ASN1_SET_TLV_PARAMS(tlv, SNMP_ASN1_TYPE_OCTET_STRING, 0, request->msg_authoritative_engine_id_len); OF_BUILD_EXEC(snmp_ans1_enc_tlv(pbuf_stream, &tlv)); OF_BUILD_EXEC(snmp_asn1_enc_raw(pbuf_stream, request->msg_authoritative_engine_id, request->msg_authoritative_engine_id_len)); @@ -1142,7 +1142,7 @@ snmp_prepare_outbound_frame(struct snmp_request *request) /* contextEngineID */ snmpv3_get_engine_id(&id, &request->context_engine_id_len); - memcpy(request->context_engine_id, id, request->context_engine_id_len); + MEMCPY(request->context_engine_id, id, request->context_engine_id_len); SNMP_ASN1_SET_TLV_PARAMS(tlv, SNMP_ASN1_TYPE_OCTET_STRING, 0, request->context_engine_id_len); OF_BUILD_EXEC(snmp_ans1_enc_tlv(pbuf_stream, &tlv)); OF_BUILD_EXEC(snmp_asn1_enc_raw(pbuf_stream, request->context_engine_id, request->context_engine_id_len)); @@ -1519,7 +1519,7 @@ snmp_complete_outbound_frame(struct snmp_request *request) request->outbound_pbuf, 0, request->outbound_pbuf->tot_len)); OF_BUILD_EXEC(snmpv3_auth(&request->outbound_pbuf_stream, frame_size + outbound_padding, key, algo, hmac)); - memcpy(request->msg_authentication_parameters, hmac, SNMP_V3_MAX_AUTH_PARAM_LENGTH); + MEMCPY(request->msg_authentication_parameters, hmac, SNMP_V3_MAX_AUTH_PARAM_LENGTH); OF_BUILD_EXEC(snmp_pbuf_stream_init(&request->outbound_pbuf_stream, request->outbound_pbuf, 0, request->outbound_pbuf->tot_len)); OF_BUILD_EXEC(snmp_pbuf_stream_seek_abs(&request->outbound_pbuf_stream, diff --git a/src/apps/snmp/snmpv3.c b/src/apps/snmp/snmpv3.c index e5dfa321..69fb3a0a 100644 --- a/src/apps/snmp/snmpv3.c +++ b/src/apps/snmp/snmpv3.c @@ -114,8 +114,8 @@ snmpv3_build_priv_param(u8_t* priv_param) priv2 = LWIP_RAND(); } - memcpy(&priv_param[0], &priv1, sizeof(priv1)); - memcpy(&priv_param[4], &priv2, sizeof(priv2)); + SMEMCPY(&priv_param[0], &priv1, sizeof(priv1)); + SMEMCPY(&priv_param[4], &priv2, sizeof(priv2)); /* Emulate 64bit increment */ priv1++; @@ -125,8 +125,8 @@ snmpv3_build_priv_param(u8_t* priv_param) #else /* Based on RFC3414 */ static u32_t ctr; u32_t boots = LWIP_SNMPV3_GET_ENGINE_BOOTS(); - memcpy(&priv_param[0], &boots, 4); - memcpy(&priv_param[4], &ctr, 4); + SMEMCPY(&priv_param[0], &boots, 4); + SMEMCPY(&priv_param[4], &ctr, 4); ctr++; #endif return ERR_OK; diff --git a/src/apps/snmp/snmpv3_mbedtls.c b/src/apps/snmp/snmpv3_mbedtls.c index 2a0598ba..0b1eefb8 100644 --- a/src/apps/snmp/snmpv3_mbedtls.c +++ b/src/apps/snmp/snmpv3_mbedtls.c @@ -192,7 +192,7 @@ snmpv3_crypt(struct snmp_pbuf_stream* stream, u16_t length, iv_local[4 + 1] = (engine_time >> 16) & 0xFF; iv_local[4 + 2] = (engine_time >> 8) & 0xFF; iv_local[4 + 3] = (engine_time >> 0) & 0xFF; - memcpy(iv_local + 8, priv_param, 8); + SMEMCPY(iv_local + 8, priv_param, 8); if(mbedtls_cipher_set_iv(&ctx, iv_local, LWIP_ARRAYSIZE(iv_local)) != 0) { goto error; } @@ -263,9 +263,9 @@ snmpv3_password_to_key_md5( /* May want to ensure that engineLength <= 32, */ /* otherwise need to use a buffer larger than 64 */ /*****************************************************/ - memcpy(password_buf, key, 16); - memcpy(password_buf + 16, engineID, engineLength); - memcpy(password_buf + 16 + engineLength, key, 16); + SMEMCPY(password_buf, key, 16); + MEMCPY(password_buf + 16, engineID, engineLength); + SMEMCPY(password_buf + 16 + engineLength, key, 16); mbedtls_md5_starts(&MD); mbedtls_md5_update(&MD, password_buf, 32 + engineLength); @@ -316,9 +316,9 @@ snmpv3_password_to_key_sha( /* May want to ensure that engineLength <= 32, */ /* otherwise need to use a buffer larger than 72 */ /*****************************************************/ - memcpy(password_buf, key, 20); - memcpy(password_buf + 20, engineID, engineLength); - memcpy(password_buf + 20 + engineLength, key, 20); + SMEMCPY(password_buf, key, 20); + MEMCPY(password_buf + 20, engineID, engineLength); + SMEMCPY(password_buf + 20 + engineLength, key, 20); mbedtls_sha1_starts(&SH); mbedtls_sha1_update(&SH, password_buf, 40 + engineLength); From 23147b0e21539be20d55c371bc7668d82b786e64 Mon Sep 17 00:00:00 2001 From: sg Date: Tue, 30 Aug 2016 22:17:36 +0200 Subject: [PATCH 202/325] added more out of range checks to dns_recv() (see bug #48924) --- src/core/dns.c | 58 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 19 deletions(-) diff --git a/src/core/dns.c b/src/core/dns.c index 46498667..11d8f200 100644 --- a/src/core/dns.c +++ b/src/core/dns.c @@ -601,11 +601,14 @@ dns_lookup(const char *name, ip_addr_t *addr LWIP_DNS_ADDRTYPE_ARG(u8_t dns_addr static u16_t dns_compare_name(const char *query, struct pbuf* p, u16_t start_offset) { - unsigned char n; + int n; u16_t response_offset = start_offset; do { - n = pbuf_get_at(p, response_offset++); + n = pbuf_try_get_at(p, response_offset++); + if (n < 0) { + return 0xFFFF; + } /** @see RFC 1035 - 4.1.4. Message compression */ if ((n & 0xc0) == 0xc0) { /* Compressed name: cannot be equal since we don't send them */ @@ -613,7 +616,11 @@ dns_compare_name(const char *query, struct pbuf* p, u16_t start_offset) } else { /* Not compressed name */ while (n > 0) { - if ((*query) != pbuf_get_at(p, response_offset)) { + int c = pbuf_try_get_at(p, response_offset); + if (c < 0) { + return 0xFFFF; + } + if ((*query) != (u8_t)c) { return 0xFFFF; } ++response_offset; @@ -622,7 +629,11 @@ dns_compare_name(const char *query, struct pbuf* p, u16_t start_offset) } ++query; } - } while (pbuf_get_at(p, response_offset) != 0); + n = pbuf_try_get_at(p, response_offset); + if (n < 0) { + return 0xFFFF; + } + } while (n != 0); return response_offset + 1; } @@ -635,28 +646,34 @@ dns_compare_name(const char *query, struct pbuf* p, u16_t start_offset) * @return index to end of the name */ static u16_t -dns_parse_name(struct pbuf* p, u16_t query_idx) +dns_skip_name(struct pbuf* p, u16_t query_idx) { - unsigned char n; + int n; + u16_t offset = query_idx; do { - /* pbuf_get_at() returns 0 on out-of-bounds access, so we will terminate */ - n = pbuf_get_at(p, query_idx++); + n = pbuf_try_get_at(p, offset++); + if (n < 0) { + return 0xFFFF; + } /** @see RFC 1035 - 4.1.4. Message compression */ if ((n & 0xc0) == 0xc0) { - /* Compressed name */ + /* Compressed name: since we only want to skip it (not check it), stop here */ break; } else { /* Not compressed name */ - while (n > 0) { - ++query_idx; - --n; + if (offset + n >= p->tot_len) { + return 0xFFFF; } + offset = (u16_t)(offset + n); } - /* pbuf_get_at() returns 0 on out-of-bounds access, so we will terminate */ - } while (pbuf_get_at(p, query_idx) != 0); + n = pbuf_try_get_at(p, offset); + if (n < 0) { + return 0xFFFF; + } + } while (n != 0); - return query_idx + 1; + return offset + 1; } /** @@ -1116,10 +1133,10 @@ dns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, } else { while ((nanswers > 0) && (res_idx < p->tot_len)) { /* skip answer resource record's host name */ - res_idx = dns_parse_name(p, res_idx); - /* dns_parse_name() may return an res_idx out of pbuf bounds. - * This will be caught in pbuf_copy_partial() below. - */ + res_idx = dns_skip_name(p, res_idx); + if (res_idx == 0xFFFF) { + goto memerr; /* ignore this packet */ + } /* Check for IP address type and Internet class. Others are discarded. */ if (pbuf_copy_partial(p, &ans, SIZEOF_DNS_ANSWER, res_idx) != SIZEOF_DNS_ANSWER) { @@ -1168,6 +1185,9 @@ dns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, #endif /* LWIP_IPV6 */ } /* skip this answer */ + if ((int)(res_idx + htons(ans.len)) > 0xFFFF) { + goto memerr; /* ignore this packet */ + } res_idx += htons(ans.len); --nanswers; } From 4325aca0f7a2a8c34b2f9db2c97bcc93aef76d5d Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Wed, 31 Aug 2016 10:35:42 +0200 Subject: [PATCH 203/325] Fix pbuf_memcmp() implementation by using pbuf_try_get_at() instead of pbuf_get_at(). Payload out-of-bounds access was not handled correctly. --- src/core/pbuf.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/core/pbuf.c b/src/core/pbuf.c index 1e6efb05..28fccc2b 100644 --- a/src/core/pbuf.c +++ b/src/core/pbuf.c @@ -1310,8 +1310,11 @@ pbuf_memcmp(struct pbuf* p, u16_t offset, const void* s2, u16_t n) if ((q != NULL) && (q->len > start)) { u16_t i; for (i = 0; i < n; i++) { - u8_t a = pbuf_get_at(q, start + i); u8_t b = ((const u8_t*)s2)[i]; + int a = pbuf_try_get_at(q, start + i); + if (a < 0) { + return 0xffff; + } if (a != b) { return i+1; } From ab8a1a0430c3880815310f0ff89be1321cfd7767 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Wed, 31 Aug 2016 17:49:19 +0800 Subject: [PATCH 204/325] netbuf: Fixup a copule LWIP_ERROR messages Fix trivial copy-n-paste mistake. Signed-off-by: Axel Lin Signed-off-by: Dirk Ziegelmeier --- src/api/netbuf.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/api/netbuf.c b/src/api/netbuf.c index 8d2cd1b7..eb250115 100644 --- a/src/api/netbuf.c +++ b/src/api/netbuf.c @@ -171,7 +171,7 @@ netbuf_ref(struct netbuf *buf, const void *dataptr, u16_t size) void netbuf_chain(struct netbuf *head, struct netbuf *tail) { - LWIP_ERROR("netbuf_ref: invalid head", (head != NULL), return;); + LWIP_ERROR("netbuf_chain: invalid head", (head != NULL), return;); LWIP_ERROR("netbuf_chain: invalid tail", (tail != NULL), return;); pbuf_cat(head->p, tail->p); head->ptr = head->p; @@ -217,7 +217,7 @@ netbuf_data(struct netbuf *buf, void **dataptr, u16_t *len) s8_t netbuf_next(struct netbuf *buf) { - LWIP_ERROR("netbuf_free: invalid buf", (buf != NULL), return -1;); + LWIP_ERROR("netbuf_next: invalid buf", (buf != NULL), return -1;); if (buf->ptr->next == NULL) { return -1; } @@ -239,7 +239,7 @@ netbuf_next(struct netbuf *buf) void netbuf_first(struct netbuf *buf) { - LWIP_ERROR("netbuf_free: invalid buf", (buf != NULL), return;); + LWIP_ERROR("netbuf_first: invalid buf", (buf != NULL), return;); buf->ptr = buf->p; } From b944ceb89d85739a4f291d56de44ee381f07e485 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Wed, 31 Aug 2016 20:17:04 +0200 Subject: [PATCH 205/325] Fix compile when LWIP_NUM_NETIF_CLIENT_DATA == 0 and AUTOIP or DHCP are enabled --- src/include/lwip/netif.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/include/lwip/netif.h b/src/include/lwip/netif.h index c039da1f..0b2bfab3 100644 --- a/src/include/lwip/netif.h +++ b/src/include/lwip/netif.h @@ -424,7 +424,7 @@ void netif_poll_all(void); err_t netif_input(struct pbuf *p, struct netif *inp); -#if LWIP_NUM_NETIF_CLIENT_DATA > 0 +#if LWIP_DHCP || LWIP_AUTOIP || (LWIP_NUM_NETIF_CLIENT_DATA > 0) u8_t netif_alloc_client_data_id(void); /** @ingroup netif_cd * Set client data. Obtain ID from netif_alloc_client_data_id(). @@ -434,7 +434,7 @@ u8_t netif_alloc_client_data_id(void); * Get client data. Obtain ID from netif_alloc_client_data_id(). */ #define netif_get_client_data(netif, id) (netif)->client_data[(id)] -#endif +#endif /* LWIP_DHCP || LWIP_AUTOIP || (LWIP_NUM_NETIF_CLIENT_DATA > 0) */ #if LWIP_IPV6 /** @ingroup netif_ip6 */ From ac6b64cf66fdc21bc8850deddcf5f9fb2e264a0b Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Wed, 31 Aug 2016 20:24:37 +0200 Subject: [PATCH 206/325] Implement a more readable fix for pbuf_memcmp than my last fix --- src/core/pbuf.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/core/pbuf.c b/src/core/pbuf.c index 28fccc2b..14dfb720 100644 --- a/src/core/pbuf.c +++ b/src/core/pbuf.c @@ -1300,28 +1300,29 @@ pbuf_memcmp(struct pbuf* p, u16_t offset, const void* s2, u16_t n) { u16_t start = offset; struct pbuf* q = p; - - /* get the correct pbuf */ + u16_t i; + + /* pbuf long enough to perform check? */ + if(p->tot_len < (offset + n)) { + return 0xffff; + } + + /* get the correct pbuf from chain. We know it succeeds because of p->tot_len check above. */ while ((q != NULL) && (q->len <= start)) { start -= q->len; q = q->next; } + /* return requested data if pbuf is OK */ - if ((q != NULL) && (q->len > start)) { - u16_t i; - for (i = 0; i < n; i++) { - u8_t b = ((const u8_t*)s2)[i]; - int a = pbuf_try_get_at(q, start + i); - if (a < 0) { - return 0xffff; - } - if (a != b) { - return i+1; - } + for (i = 0; i < n; i++) { + /* We know pbuf_get_at() succeeds because of p->tot_len check above. */ + u8_t a = pbuf_get_at(q, start + i); + u8_t b = ((const u8_t*)s2)[i]; + if (a != b) { + return i+1; } - return 0; } - return 0xffff; + return 0; } /** From 34682facd1f3c6d0c8c167df100e7fb63e90b37e Mon Sep 17 00:00:00 2001 From: sg Date: Wed, 31 Aug 2016 21:00:10 +0200 Subject: [PATCH 207/325] Remove ip4_frag IP_FRAG_USES_STATIC_BUF code: nearly the same as the other code, but IP_FRAG_USES_STATIC_BUF doesn't work when queuing pbufs --- src/core/init.c | 3 -- src/core/ipv4/ip4_frag.c | 66 ++------------------------------ src/include/lwip/ip4_frag.h | 4 +- src/include/lwip/opt.h | 25 ++---------- src/include/lwip/pbuf.h | 2 +- src/include/lwip/priv/memp_std.h | 4 +- 6 files changed, 11 insertions(+), 93 deletions(-) diff --git a/src/core/init.c b/src/core/init.c index 3e39f9d5..a539931f 100644 --- a/src/core/init.c +++ b/src/core/init.c @@ -227,9 +227,6 @@ PACK_STRUCT_END #if LWIP_TCP && LWIP_NETIF_TX_SINGLE_PBUF && !TCP_OVERSIZE #error "LWIP_NETIF_TX_SINGLE_PBUF needs TCP_OVERSIZE enabled to create single-pbuf TCP packets" #endif -#if IP_FRAG && IP_FRAG_USES_STATIC_BUF && LWIP_NETIF_TX_SINGLE_PBUF - #error "LWIP_NETIF_TX_SINGLE_PBUF does not work with IP_FRAG_USES_STATIC_BUF==1 as that creates pbuf queues" -#endif #if LWIP_NETCONN && LWIP_TCP #if NETCONN_COPY != TCP_WRITE_FLAG_COPY #error "NETCONN_COPY != TCP_WRITE_FLAG_COPY" diff --git a/src/core/ipv4/ip4_frag.c b/src/core/ipv4/ip4_frag.c index b18d904e..50edd121 100644 --- a/src/core/ipv4/ip4_frag.c +++ b/src/core/ipv4/ip4_frag.c @@ -340,7 +340,7 @@ ip_reass_chain_frag_into_datagram_and_validate(struct ip_reassdata *ipr, struct { struct ip_reass_helper *iprh, *iprh_tmp, *iprh_prev=NULL; struct pbuf *q; - u16_t offset,len; + u16_t offset, len; struct ip_hdr *fraghdr; int valid = 1; @@ -639,10 +639,6 @@ nullreturn: #endif /* IP_REASSEMBLY */ #if IP_FRAG -#if IP_FRAG_USES_STATIC_BUF -static LWIP_DECLARE_MEMORY_ALIGNED(buf, IP_FRAG_MAX_MTU); -#else /* IP_FRAG_USES_STATIC_BUF */ - #if !LWIP_NETIF_TX_SINGLE_PBUF /** Allocate a new struct pbuf_custom_ref */ static struct pbuf_custom_ref* @@ -673,14 +669,12 @@ ipfrag_free_pbuf_custom(struct pbuf *p) ip_frag_free_pbuf_custom_ref(pcr); } #endif /* !LWIP_NETIF_TX_SINGLE_PBUF */ -#endif /* IP_FRAG_USES_STATIC_BUF */ /** * Fragment an IP datagram if too large for the netif. * * Chop the datagram in MTU sized chunks and send them in order - * by using a fixed size static memory buffer (PBUF_REF) or - * point PBUF_REFs into p (depending on IP_FRAG_USES_STATIC_BUF). + * by pointing PBUF_REFs into p. * * @param p ip packet to send * @param netif the netif on which to send @@ -692,14 +686,10 @@ err_t ip4_frag(struct pbuf *p, struct netif *netif, const ip4_addr_t *dest) { struct pbuf *rambuf; -#if IP_FRAG_USES_STATIC_BUF - struct pbuf *header; -#else #if !LWIP_NETIF_TX_SINGLE_PBUF struct pbuf *newpbuf; #endif struct ip_hdr *original_iphdr; -#endif struct ip_hdr *iphdr; u16_t nfb; u16_t left, cop; @@ -708,32 +698,13 @@ ip4_frag(struct pbuf *p, struct netif *netif, const ip4_addr_t *dest) u16_t last; u16_t poff = IP_HLEN; u16_t tmp; -#if !IP_FRAG_USES_STATIC_BUF && !LWIP_NETIF_TX_SINGLE_PBUF +#if !LWIP_NETIF_TX_SINGLE_PBUF u16_t newpbuflen = 0; u16_t left_to_copy; #endif - /* Get a RAM based MTU sized pbuf */ -#if IP_FRAG_USES_STATIC_BUF - /* When using a static buffer, we use a PBUF_REF, which we will - * use to reference the packet (without link header). - * Layer and length is irrelevant. - */ - rambuf = pbuf_alloc(PBUF_LINK, 0, PBUF_REF); - if (rambuf == NULL) { - LWIP_DEBUGF(IP_REASS_DEBUG, ("ip_frag: pbuf_alloc(PBUF_LINK, 0, PBUF_REF) failed\n")); - goto memerr; - } - rambuf->tot_len = rambuf->len = mtu; - rambuf->payload = LWIP_MEM_ALIGN((void *)buf); - - /* Copy the IP header in it */ - iphdr = (struct ip_hdr *)rambuf->payload; - SMEMCPY(iphdr, p->payload, IP_HLEN); -#else /* IP_FRAG_USES_STATIC_BUF */ original_iphdr = (struct ip_hdr *)p->payload; iphdr = original_iphdr; -#endif /* IP_FRAG_USES_STATIC_BUF */ /* Save original offset */ tmp = ntohs(IPH_OFFSET(iphdr)); @@ -756,9 +727,6 @@ ip4_frag(struct pbuf *p, struct netif *netif, const ip4_addr_t *dest) /* Fill this fragment */ cop = last ? left : nfb * 8; -#if IP_FRAG_USES_STATIC_BUF - poff += pbuf_copy_partial(p, (u8_t*)iphdr + IP_HLEN, cop, poff); -#else /* IP_FRAG_USES_STATIC_BUF */ #if LWIP_NETIF_TX_SINGLE_PBUF rambuf = pbuf_alloc(PBUF_IP, cop, PBUF_RAM); if (rambuf == NULL) { @@ -830,7 +798,6 @@ ip4_frag(struct pbuf *p, struct netif *netif, const ip4_addr_t *dest) } poff = newpbuflen; #endif /* LWIP_NETIF_TX_SINGLE_PBUF */ -#endif /* IP_FRAG_USES_STATIC_BUF */ /* Correct header */ IPH_OFFSET_SET(iphdr, htons(tmp)); @@ -842,29 +809,6 @@ ip4_frag(struct pbuf *p, struct netif *netif, const ip4_addr_t *dest) } #endif /* CHECKSUM_GEN_IP */ -#if IP_FRAG_USES_STATIC_BUF - if (last) { - pbuf_realloc(rambuf, left + IP_HLEN); - } - - /* This part is ugly: we alloc a RAM based pbuf for - * the link level header for each chunk and then - * free it. A PBUF_ROM style pbuf for which pbuf_header - * worked would make things simpler. - */ - header = pbuf_alloc(PBUF_LINK, 0, PBUF_RAM); - if (header != NULL) { - pbuf_chain(header, rambuf); - netif->output(netif, header, dest); - IPFRAG_STATS_INC(ip_frag.xmit); - MIB2_STATS_INC(mib2.ipfragcreates); - pbuf_free(header); - } else { - LWIP_DEBUGF(IP_REASS_DEBUG, ("ip_frag: pbuf_alloc() for header failed\n")); - pbuf_free(rambuf); - goto memerr; - } -#else /* IP_FRAG_USES_STATIC_BUF */ /* No need for separate header pbuf - we allowed room for it in rambuf * when allocated. */ @@ -879,13 +823,9 @@ ip4_frag(struct pbuf *p, struct netif *netif, const ip4_addr_t *dest) */ pbuf_free(rambuf); -#endif /* IP_FRAG_USES_STATIC_BUF */ left -= cop; ofo += nfb; } -#if IP_FRAG_USES_STATIC_BUF - pbuf_free(rambuf); -#endif /* IP_FRAG_USES_STATIC_BUF */ MIB2_STATS_INC(mib2.ipfragoks); return ERR_OK; memerr: diff --git a/src/include/lwip/ip4_frag.h b/src/include/lwip/ip4_frag.h index 89b9e311..ed5bf14a 100644 --- a/src/include/lwip/ip4_frag.h +++ b/src/include/lwip/ip4_frag.h @@ -73,7 +73,7 @@ struct pbuf * ip4_reass(struct pbuf *p); #endif /* IP_REASSEMBLY */ #if IP_FRAG -#if !IP_FRAG_USES_STATIC_BUF && !LWIP_NETIF_TX_SINGLE_PBUF +#if !LWIP_NETIF_TX_SINGLE_PBUF #ifndef LWIP_PBUF_CUSTOM_REF_DEFINED #define LWIP_PBUF_CUSTOM_REF_DEFINED /** A custom pbuf that holds a reference to another pbuf, which is freed @@ -86,7 +86,7 @@ struct pbuf_custom_ref { struct pbuf *original; }; #endif /* LWIP_PBUF_CUSTOM_REF_DEFINED */ -#endif /* !IP_FRAG_USES_STATIC_BUF && !LWIP_NETIF_TX_SINGLE_PBUF */ +#endif /* !LWIP_NETIF_TX_SINGLE_PBUF */ err_t ip4_frag(struct pbuf *p, struct netif *netif, const ip4_addr_t *dest); #endif /* IP_FRAG */ diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h index 1568080c..36107506 100644 --- a/src/include/lwip/opt.h +++ b/src/include/lwip/opt.h @@ -401,9 +401,9 @@ /** * MEMP_NUM_FRAG_PBUF: the number of IP fragments simultaneously sent * (fragments, not whole packets!). - * This is only used with IP_FRAG_USES_STATIC_BUF==0 and - * LWIP_NETIF_TX_SINGLE_PBUF==0 and only has to be > 1 with DMA-enabled MACs - * where the packet is not yet sent when netif->output returns. + * This is only used with LWIP_NETIF_TX_SINGLE_PBUF==0 and only has to be > 1 + * with DMA-enabled MACs where the packet is not yet sent when netif->output + * returns. */ #if !defined MEMP_NUM_FRAG_PBUF || defined __DOXYGEN__ #define MEMP_NUM_FRAG_PBUF 15 @@ -705,25 +705,6 @@ #define IP_REASS_MAX_PBUFS 10 #endif -/** - * IP_FRAG_USES_STATIC_BUF==1: Use a static MTU-sized buffer for IP - * fragmentation. Otherwise pbufs are allocated and reference the original - * packet data to be fragmented (or with LWIP_NETIF_TX_SINGLE_PBUF==1, - * new PBUF_RAM pbufs are used for fragments). - * ATTENTION: IP_FRAG_USES_STATIC_BUF==1 may not be used for DMA-enabled MACs! - */ -#if !defined IP_FRAG_USES_STATIC_BUF || defined __DOXYGEN__ -#define IP_FRAG_USES_STATIC_BUF 0 -#endif - -/** - * IP_FRAG_MAX_MTU: Assumed max MTU on any interface for IP frag buffer - * (requires IP_FRAG_USES_STATIC_BUF==1) - */ -#if IP_FRAG_USES_STATIC_BUF && !defined(IP_FRAG_MAX_MTU) || defined __DOXYGEN__ -#define IP_FRAG_MAX_MTU 1500 -#endif - /** * IP_DEFAULT_TTL: Default value for Time-To-Live used by transport layers. */ diff --git a/src/include/lwip/pbuf.h b/src/include/lwip/pbuf.h index 16f96860..bc7296e0 100644 --- a/src/include/lwip/pbuf.h +++ b/src/include/lwip/pbuf.h @@ -52,7 +52,7 @@ extern "C" { * Currently, the pbuf_custom code is only needed for one specific configuration * of IP_FRAG, unless required by external driver/application code. */ #ifndef LWIP_SUPPORT_CUSTOM_PBUF -#define LWIP_SUPPORT_CUSTOM_PBUF ((IP_FRAG && !IP_FRAG_USES_STATIC_BUF && !LWIP_NETIF_TX_SINGLE_PBUF) || (LWIP_IPV6 && LWIP_IPV6_FRAG)) +#define LWIP_SUPPORT_CUSTOM_PBUF ((IP_FRAG && !LWIP_NETIF_TX_SINGLE_PBUF) || (LWIP_IPV6 && LWIP_IPV6_FRAG)) #endif /* @todo: We need a mechanism to prevent wasting memory in every pbuf diff --git a/src/include/lwip/priv/memp_std.h b/src/include/lwip/priv/memp_std.h index ee3e2537..ce9fd500 100644 --- a/src/include/lwip/priv/memp_std.h +++ b/src/include/lwip/priv/memp_std.h @@ -55,9 +55,9 @@ LWIP_MEMPOOL(TCP_SEG, MEMP_NUM_TCP_SEG, sizeof(struct tcp_seg), #if LWIP_IPV4 && IP_REASSEMBLY LWIP_MEMPOOL(REASSDATA, MEMP_NUM_REASSDATA, sizeof(struct ip_reassdata), "REASSDATA") #endif /* LWIP_IPV4 && IP_REASSEMBLY */ -#if (IP_FRAG && !IP_FRAG_USES_STATIC_BUF && !LWIP_NETIF_TX_SINGLE_PBUF) || (LWIP_IPV6 && LWIP_IPV6_FRAG) +#if (IP_FRAG && !LWIP_NETIF_TX_SINGLE_PBUF) || (LWIP_IPV6 && LWIP_IPV6_FRAG) LWIP_MEMPOOL(FRAG_PBUF, MEMP_NUM_FRAG_PBUF, sizeof(struct pbuf_custom_ref),"FRAG_PBUF") -#endif /* IP_FRAG && !IP_FRAG_USES_STATIC_BUF && !LWIP_NETIF_TX_SINGLE_PBUF */ +#endif /* IP_FRAG && !LWIP_NETIF_TX_SINGLE_PBUF || (LWIP_IPV6 && LWIP_IPV6_FRAG) */ #if LWIP_NETCONN || LWIP_SOCKET LWIP_MEMPOOL(NETBUF, MEMP_NUM_NETBUF, sizeof(struct netbuf), "NETBUF") From aeae4e91dbc3f5b3c67bda526492ed6ac17b6d61 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Tue, 6 Sep 2016 12:30:15 +0200 Subject: [PATCH 208/325] Fix compile when UDP is disabled --- src/api/sockets.c | 137 +++++++++++++++++++++-------------------- src/include/lwip/opt.h | 2 +- 2 files changed, 70 insertions(+), 69 deletions(-) diff --git a/src/api/sockets.c b/src/api/sockets.c index 620e4849..72e777d4 100644 --- a/src/api/sockets.c +++ b/src/api/sockets.c @@ -969,8 +969,6 @@ int lwip_sendmsg(int s, const struct msghdr *msg, int flags) { struct lwip_sock *sock; - struct netbuf *chain_buf; - u16_t remote_port; int i; #if LWIP_TCP u8_t write_flags; @@ -1027,82 +1025,85 @@ lwip_sendmsg(int s, const struct msghdr *msg, int flags) } /* else, UDP and RAW NETCONNs */ #if LWIP_UDP || LWIP_RAW + { + struct netbuf *chain_buf; - LWIP_UNUSED_ARG(flags); - LWIP_ERROR("lwip_sendmsg: invalid msghdr name", (((msg->msg_name == NULL) && (msg->msg_namelen == 0)) || - IS_SOCK_ADDR_LEN_VALID(msg->msg_namelen)) , - sock_set_errno(sock, err_to_errno(ERR_ARG)); return -1;); + LWIP_UNUSED_ARG(flags); + LWIP_ERROR("lwip_sendmsg: invalid msghdr name", (((msg->msg_name == NULL) && (msg->msg_namelen == 0)) || + IS_SOCK_ADDR_LEN_VALID(msg->msg_namelen)) , + sock_set_errno(sock, err_to_errno(ERR_ARG)); return -1;); - /* initialize chain buffer with destination */ - chain_buf = netbuf_new(); - if (!chain_buf) { - sock_set_errno(sock, err_to_errno(ERR_MEM)); - return -1; - } - if (msg->msg_name) { - SOCKADDR_TO_IPADDR_PORT((const struct sockaddr *)msg->msg_name, &chain_buf->addr, remote_port); - netbuf_fromport(chain_buf) = remote_port; - } + /* initialize chain buffer with destination */ + chain_buf = netbuf_new(); + if (!chain_buf) { + sock_set_errno(sock, err_to_errno(ERR_MEM)); + return -1; + } + if (msg->msg_name) { + u16_t remote_port; + SOCKADDR_TO_IPADDR_PORT((const struct sockaddr *)msg->msg_name, &chain_buf->addr, remote_port); + netbuf_fromport(chain_buf) = remote_port; + } #if LWIP_NETIF_TX_SINGLE_PBUF - for (i = 0; i < msg->msg_iovlen; i++) { - size += msg->msg_iov[i].iov_len; - } - /* Allocate a new netbuf and copy the data into it. */ - if (netbuf_alloc(chain_buf, (u16_t)size) == NULL) { - err = ERR_MEM; - } - else { - /* flatten the IO vectors */ - size_t offset = 0; for (i = 0; i < msg->msg_iovlen; i++) { - MEMCPY(&((u8_t*)chain_buf->p->payload)[offset], msg->msg_iov[i].iov_base, msg->msg_iov[i].iov_len); - offset += msg->msg_iov[i].iov_len; + size += msg->msg_iov[i].iov_len; } -#if LWIP_CHECKSUM_ON_COPY - { - /* This can be improved by using LWIP_CHKSUM_COPY() and aggregating the checksum for each IO vector */ - u16_t chksum = ~inet_chksum_pbuf(chain_buf->p); - netbuf_set_chksum(chain_buf, chksum); - } -#endif /* LWIP_CHECKSUM_ON_COPY */ - err = ERR_OK; - } -#else /* LWIP_NETIF_TX_SINGLE_PBUF */ - /* create a chained netbuf from the IO vectors. NOTE: we assemble a pbuf chain - manually to avoid having to allocate, chain, and delete a netbuf for each iov */ - for (i = 0; i < msg->msg_iovlen; i++) { - struct pbuf *p = pbuf_alloc(PBUF_TRANSPORT, 0, PBUF_REF); - if (p == NULL) { - err = ERR_MEM; /* let netbuf_delete() cleanup chain_buf */ - break; - } - p->payload = msg->msg_iov[i].iov_base; - LWIP_ASSERT("iov_len < u16_t", msg->msg_iov[i].iov_len <= 0xFFFF); - p->len = p->tot_len = (u16_t)msg->msg_iov[i].iov_len; - /* netbuf empty, add new pbuf */ - if (chain_buf->p == NULL) { - chain_buf->p = chain_buf->ptr = p; - /* add pbuf to existing pbuf chain */ + /* Allocate a new netbuf and copy the data into it. */ + if (netbuf_alloc(chain_buf, (u16_t)size) == NULL) { + err = ERR_MEM; } else { - pbuf_cat(chain_buf->p, p); + /* flatten the IO vectors */ + size_t offset = 0; + for (i = 0; i < msg->msg_iovlen; i++) { + MEMCPY(&((u8_t*)chain_buf->p->payload)[offset], msg->msg_iov[i].iov_base, msg->msg_iov[i].iov_len); + offset += msg->msg_iov[i].iov_len; + } +#if LWIP_CHECKSUM_ON_COPY + { + /* This can be improved by using LWIP_CHKSUM_COPY() and aggregating the checksum for each IO vector */ + u16_t chksum = ~inet_chksum_pbuf(chain_buf->p); + netbuf_set_chksum(chain_buf, chksum); + } +#endif /* LWIP_CHECKSUM_ON_COPY */ + err = ERR_OK; + } +#else /* LWIP_NETIF_TX_SINGLE_PBUF */ + /* create a chained netbuf from the IO vectors. NOTE: we assemble a pbuf chain + manually to avoid having to allocate, chain, and delete a netbuf for each iov */ + for (i = 0; i < msg->msg_iovlen; i++) { + struct pbuf *p = pbuf_alloc(PBUF_TRANSPORT, 0, PBUF_REF); + if (p == NULL) { + err = ERR_MEM; /* let netbuf_delete() cleanup chain_buf */ + break; + } + p->payload = msg->msg_iov[i].iov_base; + LWIP_ASSERT("iov_len < u16_t", msg->msg_iov[i].iov_len <= 0xFFFF); + p->len = p->tot_len = (u16_t)msg->msg_iov[i].iov_len; + /* netbuf empty, add new pbuf */ + if (chain_buf->p == NULL) { + chain_buf->p = chain_buf->ptr = p; + /* add pbuf to existing pbuf chain */ + } else { + pbuf_cat(chain_buf->p, p); + } + } + /* save size of total chain */ + if (err == ERR_OK) { + size = netbuf_len(chain_buf); } - } - /* save size of total chain */ - if (err == ERR_OK) { - size = netbuf_len(chain_buf); - } #endif /* LWIP_NETIF_TX_SINGLE_PBUF */ - if (err == ERR_OK) { - /* send the data */ - err = netconn_send(sock->conn, chain_buf); + if (err == ERR_OK) { + /* send the data */ + err = netconn_send(sock->conn, chain_buf); + } + + /* deallocated the buffer */ + netbuf_delete(chain_buf); + + sock_set_errno(sock, err_to_errno(err)); + return (err == ERR_OK ? size : -1); } - - /* deallocated the buffer */ - netbuf_delete(chain_buf); - - sock_set_errno(sock, err_to_errno(err)); - return (err == ERR_OK ? size : -1); #else /* LWIP_UDP || LWIP_RAW */ sock_set_errno(sock, err_to_errno(ERR_ARG)); return -1; diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h index 36107506..0db03b50 100644 --- a/src/include/lwip/opt.h +++ b/src/include/lwip/opt.h @@ -978,7 +978,7 @@ * IP_MULTICAST_TTL/IP_MULTICAST_IF/IP_MULTICAST_LOOP */ #if !defined LWIP_MULTICAST_TX_OPTIONS || defined __DOXYGEN__ -#define LWIP_MULTICAST_TX_OPTIONS LWIP_IGMP +#define LWIP_MULTICAST_TX_OPTIONS (LWIP_IGMP && LWIP_UDP) #endif /** * @} From d66442ba9120e3526876a95bc87d96f83a723300 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Wed, 7 Sep 2016 08:11:30 +0200 Subject: [PATCH 209/325] Fix compile when TCP, UDP and RAW are disabled --- src/core/ipv6/ip6.c | 1 + src/core/netif.c | 1 + 2 files changed, 2 insertions(+) diff --git a/src/core/ipv6/ip6.c b/src/core/ipv6/ip6.c index 3362249f..8cc9c010 100644 --- a/src/core/ipv6/ip6.c +++ b/src/core/ipv6/ip6.c @@ -46,6 +46,7 @@ #include "lwip/def.h" #include "lwip/mem.h" #include "lwip/netif.h" +#include "lwip/ip.h" #include "lwip/ip6.h" #include "lwip/ip6_addr.h" #include "lwip/ip6_frag.h" diff --git a/src/core/netif.c b/src/core/netif.c index 1c4b1b42..819b4ecc 100644 --- a/src/core/netif.c +++ b/src/core/netif.c @@ -63,6 +63,7 @@ #include "lwip/etharp.h" #include "lwip/stats.h" #include "lwip/sys.h" +#include "lwip/ip.h" #if ENABLE_LOOPBACK #if LWIP_NETIF_LOOPBACK_MULTITHREADING #include "lwip/tcpip.h" From f8a95aa27f7b97eb791d0a95125a597990f56f64 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Tue, 6 Sep 2016 23:11:20 +0800 Subject: [PATCH 210/325] dns: Drop unnecessary txid variable in dns_check_entry Signed-off-by: Axel Lin --- src/core/dns.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/core/dns.c b/src/core/dns.c index 11d8f200..b19f9b08 100644 --- a/src/core/dns.c +++ b/src/core/dns.c @@ -938,12 +938,9 @@ dns_check_entry(u8_t i) LWIP_ASSERT("array index out of bounds", i < DNS_TABLE_SIZE); switch (entry->state) { - - case DNS_STATE_NEW: { - u16_t txid; + case DNS_STATE_NEW: /* initialize new entry */ - txid = dns_create_txid(); - entry->txid = txid; + entry->txid = dns_create_txid(); entry->state = DNS_STATE_ASKING; entry->server_idx = 0; entry->tmr = 1; @@ -956,8 +953,6 @@ dns_check_entry(u8_t i) ("dns_send returned error: %s\n", lwip_strerr(err))); } break; - } - case DNS_STATE_ASKING: if (--entry->tmr == 0) { if (++entry->retries == DNS_MAX_RETRIES) { From b7c2553b46f9102a127517d839fadf7994f94f89 Mon Sep 17 00:00:00 2001 From: Joel Cunningham Date: Thu, 1 Sep 2016 10:29:06 -0500 Subject: [PATCH 211/325] bug #48964: Make PBUF_POOL sanity checks contingent on PBUF_POOL_SIZE This commit adds support to the sanity checks in init.c to ensure that PBUF_POOL is in use In ports with drivers/netifs that use PBUF_REF for the RX pathway, there is no need for the PBUF_POOL memory pool. This allows the port to define PBUF_POOL_SIZE to 0 --- src/core/init.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/init.c b/src/core/init.c index a539931f..0eb1e44c 100644 --- a/src/core/init.c +++ b/src/core/init.c @@ -319,10 +319,10 @@ PACK_STRUCT_END #if TCP_SNDQUEUELOWAT >= TCP_SND_QUEUELEN #error "lwip_sanity_check: WARNING: TCP_SNDQUEUELOWAT must be less than TCP_SND_QUEUELEN. If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error." #endif -#if !MEMP_MEM_MALLOC && (PBUF_POOL_BUFSIZE <= (PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN + PBUF_IP_HLEN + PBUF_TRANSPORT_HLEN)) +#if !MEMP_MEM_MALLOC && PBUF_POOL_SIZE && (PBUF_POOL_BUFSIZE <= (PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN + PBUF_IP_HLEN + PBUF_TRANSPORT_HLEN)) #error "lwip_sanity_check: WARNING: PBUF_POOL_BUFSIZE does not provide enough space for protocol headers. If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error." #endif -#if !MEMP_MEM_MALLOC && (TCP_WND > (PBUF_POOL_SIZE * (PBUF_POOL_BUFSIZE - (PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN + PBUF_IP_HLEN + PBUF_TRANSPORT_HLEN)))) +#if !MEMP_MEM_MALLOC && PBUF_POOL_SIZE && (TCP_WND > (PBUF_POOL_SIZE * (PBUF_POOL_BUFSIZE - (PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN + PBUF_IP_HLEN + PBUF_TRANSPORT_HLEN)))) #error "lwip_sanity_check: WARNING: TCP_WND is larger than space provided by PBUF_POOL_SIZE * (PBUF_POOL_BUFSIZE - protocol headers). If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error." #endif #if TCP_WND < TCP_MSS From f38705c38cb3814d4902ddab60204e85edfd1fa7 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Fri, 9 Sep 2016 16:59:26 +0800 Subject: [PATCH 212/325] mdns: Update answers counter in mdns_add_answer rather than each caller This simplifies the code and less error prone. Signed-off-by: Axel Lin --- src/apps/mdns/mdns.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/apps/mdns/mdns.c b/src/apps/mdns/mdns.c index 6fc7ce7f..98b9e801 100644 --- a/src/apps/mdns/mdns.c +++ b/src/apps/mdns/mdns.c @@ -1008,6 +1008,9 @@ mdns_add_answer(struct mdns_outpacket *reply, struct mdns_domain *domain, u16_t /* Write rd_length after when we know the answer size */ field16 = htons(reply->write_offset - answer_offset); res = pbuf_take_at(reply->pbuf, &field16, sizeof(field16), rdlen_offset); + if (res == ERR_OK) { + reply->answers++; + } return res; } @@ -1295,14 +1298,12 @@ mdns_send_outpacket(struct mdns_outpacket *outpkt) if (res != ERR_OK) { goto cleanup; } - outpkt->answers++; } if (outpkt->host_replies & REPLY_HOST_PTR_V4) { res = mdns_add_hostv4_ptr_answer(outpkt, outpkt->cache_flush, outpkt->netif); if (res != ERR_OK) { goto cleanup; } - outpkt->answers++; } #endif #if LWIP_IPV6 @@ -1314,7 +1315,6 @@ mdns_send_outpacket(struct mdns_outpacket *outpkt) if (res != ERR_OK) { goto cleanup; } - outpkt->answers++; } } } @@ -1327,7 +1327,6 @@ mdns_send_outpacket(struct mdns_outpacket *outpkt) if (res != ERR_OK) { goto cleanup; } - outpkt->answers++; } addrindex++; rev_addrs >>= 1; @@ -1347,7 +1346,6 @@ mdns_send_outpacket(struct mdns_outpacket *outpkt) if (res != ERR_OK) { goto cleanup; } - outpkt->answers++; } if (outpkt->serv_replies[i] & REPLY_SERVICE_NAME_PTR) { @@ -1355,7 +1353,6 @@ mdns_send_outpacket(struct mdns_outpacket *outpkt) if (res != ERR_OK) { goto cleanup; } - outpkt->answers++; } if (outpkt->serv_replies[i] & REPLY_SERVICE_SRV) { @@ -1363,7 +1360,6 @@ mdns_send_outpacket(struct mdns_outpacket *outpkt) if (res != ERR_OK) { goto cleanup; } - outpkt->answers++; } if (outpkt->serv_replies[i] & REPLY_SERVICE_TXT) { @@ -1371,7 +1367,6 @@ mdns_send_outpacket(struct mdns_outpacket *outpkt) if (res != ERR_OK) { goto cleanup; } - outpkt->answers++; } } From 4a73bcbc65b0ffc6fea05c4e7575f4c33fe34594 Mon Sep 17 00:00:00 2001 From: Erik Ekman Date: Fri, 9 Sep 2016 17:04:12 +0200 Subject: [PATCH 213/325] mdns: Revert answer count patch Answers written to outpackets can be additional answers or normal answers to questions. --- src/apps/mdns/mdns.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/apps/mdns/mdns.c b/src/apps/mdns/mdns.c index 98b9e801..6fc7ce7f 100644 --- a/src/apps/mdns/mdns.c +++ b/src/apps/mdns/mdns.c @@ -1008,9 +1008,6 @@ mdns_add_answer(struct mdns_outpacket *reply, struct mdns_domain *domain, u16_t /* Write rd_length after when we know the answer size */ field16 = htons(reply->write_offset - answer_offset); res = pbuf_take_at(reply->pbuf, &field16, sizeof(field16), rdlen_offset); - if (res == ERR_OK) { - reply->answers++; - } return res; } @@ -1298,12 +1295,14 @@ mdns_send_outpacket(struct mdns_outpacket *outpkt) if (res != ERR_OK) { goto cleanup; } + outpkt->answers++; } if (outpkt->host_replies & REPLY_HOST_PTR_V4) { res = mdns_add_hostv4_ptr_answer(outpkt, outpkt->cache_flush, outpkt->netif); if (res != ERR_OK) { goto cleanup; } + outpkt->answers++; } #endif #if LWIP_IPV6 @@ -1315,6 +1314,7 @@ mdns_send_outpacket(struct mdns_outpacket *outpkt) if (res != ERR_OK) { goto cleanup; } + outpkt->answers++; } } } @@ -1327,6 +1327,7 @@ mdns_send_outpacket(struct mdns_outpacket *outpkt) if (res != ERR_OK) { goto cleanup; } + outpkt->answers++; } addrindex++; rev_addrs >>= 1; @@ -1346,6 +1347,7 @@ mdns_send_outpacket(struct mdns_outpacket *outpkt) if (res != ERR_OK) { goto cleanup; } + outpkt->answers++; } if (outpkt->serv_replies[i] & REPLY_SERVICE_NAME_PTR) { @@ -1353,6 +1355,7 @@ mdns_send_outpacket(struct mdns_outpacket *outpkt) if (res != ERR_OK) { goto cleanup; } + outpkt->answers++; } if (outpkt->serv_replies[i] & REPLY_SERVICE_SRV) { @@ -1360,6 +1363,7 @@ mdns_send_outpacket(struct mdns_outpacket *outpkt) if (res != ERR_OK) { goto cleanup; } + outpkt->answers++; } if (outpkt->serv_replies[i] & REPLY_SERVICE_TXT) { @@ -1367,6 +1371,7 @@ mdns_send_outpacket(struct mdns_outpacket *outpkt) if (res != ERR_OK) { goto cleanup; } + outpkt->answers++; } } From 8cd43a3dd9fc839be6a66da9cef8bdb271b2cc1d Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Fri, 9 Sep 2016 17:36:49 +0200 Subject: [PATCH 214/325] Documentation: Add one more note PCB is already freed in tcp_err callback. --- src/core/tcp.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/core/tcp.c b/src/core/tcp.c index 64eef699..50aa31f2 100644 --- a/src/core/tcp.c +++ b/src/core/tcp.c @@ -1681,6 +1681,8 @@ tcp_sent(struct tcp_pcb *pcb, tcp_sent_fn sent) * Used to specify the function that should be called when a fatal error * has occurred on the connection. * + * @note The corresponding pcb is already freed when this callback is called! + * * @param pcb tcp_pcb to set the err callback * @param err callback function to call for this pcb when a fatal error * has occurred on the connection From ef0dc65515d4d428381db1b2a8e61d8dc2200a1b Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Mon, 12 Sep 2016 07:37:35 +0200 Subject: [PATCH 215/325] Fix GCC warning "invalid suffix on literal; C++11 requires a space between literal and string macro" in arch.h. Pointed out by Thomas Nittel. --- src/include/lwip/arch.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/include/lwip/arch.h b/src/include/lwip/arch.h index f20f6e4f..ee4a0b98 100644 --- a/src/include/lwip/arch.h +++ b/src/include/lwip/arch.h @@ -85,7 +85,7 @@ typedef uintptr_t mem_ptr_t; #if !LWIP_NO_INTTYPES_H #include #ifndef X8_F -#define X8_F "02"PRIx8 +#define X8_F "02" PRIx8 #endif #ifndef U16_F #define U16_F PRIu16 From 8dbd1abdc4b693e79cff5036e595625689024e95 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Mon, 12 Sep 2016 12:55:24 +0200 Subject: [PATCH 216/325] Minor coding style fixes while reading SNMP code --- src/apps/snmp/snmp_msg.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/apps/snmp/snmp_msg.c b/src/apps/snmp/snmp_msg.c index b06266f6..be98a4f6 100644 --- a/src/apps/snmp/snmp_msg.c +++ b/src/apps/snmp/snmp_msg.c @@ -272,8 +272,7 @@ snmp_process_varbind(struct snmp_request *request, struct snmp_varbind *vb, u8_t } } - if (request->error_status != SNMP_ERR_NOERROR) - { + if (request->error_status != SNMP_ERR_NOERROR) { if (request->error_status >= SNMP_VARBIND_EXCEPTION_OFFSET) { if ((request->version == SNMP_VERSION_2c) || request->version == SNMP_VERSION_3) { /* in SNMP v2c a varbind related exception is stored in varbind and not in frame header */ @@ -512,8 +511,7 @@ snmp_process_set_request(struct snmp_request *request) memset(&node_instance, 0, sizeof(node_instance)); request->error_status = snmp_get_node_instance_from_oid(vb.oid.id, vb.oid.len, &node_instance); - if (request->error_status == SNMP_ERR_NOERROR) - { + if (request->error_status == SNMP_ERR_NOERROR) { if (node_instance.asn1_type != vb.type) { request->error_status = SNMP_ERR_WRONGTYPE; } else if (((node_instance.access & SNMP_NODE_INSTANCE_ACCESS_WRITE) != SNMP_NODE_INSTANCE_ACCESS_WRITE) || (node_instance.set_value == NULL)) { @@ -528,8 +526,7 @@ snmp_process_set_request(struct snmp_request *request) node_instance.release_instance(&node_instance); } } - } - else if (err == SNMP_VB_ENUMERATOR_ERR_EOVB) { + } else if (err == SNMP_VB_ENUMERATOR_ERR_EOVB) { /* no more varbinds in request */ break; } else if (err == SNMP_VB_ENUMERATOR_ERR_INVALIDLENGTH) { @@ -551,10 +548,8 @@ snmp_process_set_request(struct snmp_request *request) struct snmp_node_instance node_instance; memset(&node_instance, 0, sizeof(node_instance)); request->error_status = snmp_get_node_instance_from_oid(vb.oid.id, vb.oid.len, &node_instance); - if (request->error_status == SNMP_ERR_NOERROR) - { - if (node_instance.set_value(&node_instance, vb.value_len, vb.value) != SNMP_ERR_NOERROR) - { + if (request->error_status == SNMP_ERR_NOERROR) { + if (node_instance.set_value(&node_instance, vb.value_len, vb.value) != SNMP_ERR_NOERROR) { if (request->inbound_varbind_enumerator.varbind_count == 1) { request->error_status = SNMP_ERR_COMMITFAILED; } else { From 58c8e0f8ca3d322eac22828d396851743ecdfbc2 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Thu, 15 Sep 2016 10:41:05 +0200 Subject: [PATCH 217/325] Implement request by Marco Veeneman: Make snmp_send_trap() public --- src/apps/snmp/snmp_traps.c | 11 ++++++----- src/include/lwip/apps/snmp.h | 1 + 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/apps/snmp/snmp_traps.c b/src/apps/snmp/snmp_traps.c index 8061766e..61ceee65 100644 --- a/src/apps/snmp/snmp_traps.c +++ b/src/apps/snmp/snmp_traps.c @@ -149,9 +149,10 @@ snmp_get_auth_traps_enabled(void) /** * Sends an generic or enterprise specific trap message. * - * @param generic_trap is the trap code * @param eoid points to enterprise object identifier + * @param generic_trap is the trap code * @param specific_trap used for enterprise traps when generic_trap == 6 + * @param varbinds linked list of varbinds to be sent * @return ERR_OK when success, ERR_MEM if we're out of memory * * @note the use of the enterprise identifier field @@ -160,8 +161,8 @@ snmp_get_auth_traps_enabled(void) * and .iso.org.dod.internet.private.enterprises.yourenterprise * (sysObjectID) for specific traps. */ -static err_t -snmp_send_trap(const struct snmp_obj_id *device_enterprise_oid, s32_t generic_trap, s32_t specific_trap, struct snmp_varbind *varbinds) +err_t +snmp_send_trap(const struct snmp_obj_id* eoid, s32_t generic_trap, s32_t specific_trap, struct snmp_varbind *varbinds) { struct snmp_msg_trap trap_msg; struct snmp_trap_dst *td; @@ -175,10 +176,10 @@ snmp_send_trap(const struct snmp_obj_id *device_enterprise_oid, s32_t generic_tr if ((td->enable != 0) && !ip_addr_isany(&td->dip)) { /* lookup current source address for this dst */ if (snmp_get_local_ip_for_dst(snmp_traps_handle, &td->dip, &trap_msg.sip)) { - if (device_enterprise_oid == NULL) { + if (eoid == NULL) { trap_msg.enterprise = snmp_get_device_enterprise_oid(); } else { - trap_msg.enterprise = device_enterprise_oid; + trap_msg.enterprise = eoid; } trap_msg.gen_trap = generic_trap; diff --git a/src/include/lwip/apps/snmp.h b/src/include/lwip/apps/snmp.h index 60ce9c92..10e8ff43 100644 --- a/src/include/lwip/apps/snmp.h +++ b/src/include/lwip/apps/snmp.h @@ -99,6 +99,7 @@ void snmp_trap_dst_ip_set(u8_t dst_idx, const ip_addr_t *dst); err_t snmp_send_trap_generic(s32_t generic_trap); err_t snmp_send_trap_specific(s32_t specific_trap, struct snmp_varbind *varbinds); +err_t snmp_send_trap(const struct snmp_obj_id* oid, s32_t generic_trap, s32_t specific_trap, struct snmp_varbind *varbinds); #define SNMP_AUTH_TRAPS_DISABLED 0 #define SNMP_AUTH_TRAPS_ENABLED 1 From ee4cd45c989101e0620d3e36184ae095fd6eac24 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Mon, 19 Sep 2016 08:45:57 +0200 Subject: [PATCH 218/325] Fix bug #49125: Need a way to iterate multicast groups for MAC filtering -> let list heads be a public symbol --- src/core/ipv4/igmp.c | 2 +- src/core/ipv6/mld6.c | 2 +- src/include/lwip/igmp.h | 3 +++ src/include/lwip/mld6.h | 3 +++ 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/core/ipv4/igmp.c b/src/core/ipv4/igmp.c index 164a3bf1..ef3b8ab9 100644 --- a/src/core/ipv4/igmp.c +++ b/src/core/ipv4/igmp.c @@ -104,7 +104,7 @@ static void igmp_delaying_member(struct igmp_group *group, u8_t maxresp); static err_t igmp_ip_output_if(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest, struct netif *netif); static void igmp_send(struct igmp_group *group, u8_t type); -static struct igmp_group* igmp_group_list; +struct igmp_group* igmp_group_list; static ip4_addr_t allsystems; static ip4_addr_t allrouters; diff --git a/src/core/ipv6/mld6.c b/src/core/ipv6/mld6.c index 9ae44c06..09fe2a26 100644 --- a/src/core/ipv6/mld6.c +++ b/src/core/ipv6/mld6.c @@ -77,7 +77,7 @@ /* The list of joined groups. */ -static struct mld_group* mld_group_list; +struct mld_group* mld_group_list; /* Forward declarations. */ diff --git a/src/include/lwip/igmp.h b/src/include/lwip/igmp.h index be78c332..6b46bbcc 100644 --- a/src/include/lwip/igmp.h +++ b/src/include/lwip/igmp.h @@ -88,6 +88,9 @@ struct igmp_group { u8_t use; }; +/* Head of IGMP group list */ +extern struct igmp_group* igmp_group_list; + /* Prototypes */ void igmp_init(void); err_t igmp_start(struct netif *netif); diff --git a/src/include/lwip/mld6.h b/src/include/lwip/mld6.h index 089974ae..02637e8b 100644 --- a/src/include/lwip/mld6.h +++ b/src/include/lwip/mld6.h @@ -72,6 +72,9 @@ struct mld_group { u8_t use; }; +/* Head of MLD group list */ +extern struct mld_group* mld_group_list; + #define MLD6_TMR_INTERVAL 100 /* Milliseconds */ err_t mld6_stop(struct netif *netif); From 2facd2d64d579e614273f7f674290969e03ee89d Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Mon, 19 Sep 2016 12:20:20 +0200 Subject: [PATCH 219/325] Apply modified patch from Daniel Elstner to fix bug #49124: mDNS should not use snprintf() --- src/apps/mdns/mdns.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/apps/mdns/mdns.c b/src/apps/mdns/mdns.c index 6fc7ce7f..7c02c914 100644 --- a/src/apps/mdns/mdns.c +++ b/src/apps/mdns/mdns.c @@ -504,9 +504,15 @@ mdns_build_reverse_v4_domain(struct mdns_domain *domain, const ip4_addr_t *addr) memset(domain, 0, sizeof(struct mdns_domain)); ptr = (const u8_t *) addr; for (i = sizeof(ip4_addr_t) - 1; i >= 0; i--) { - char buf[4]; - size_t len = snprintf(buf, sizeof(buf), "%d", ptr[i]); - res = mdns_domain_add_label(domain, buf, (u8_t)len); + char buf[3]; + size_t pos = sizeof(buf); + u8_t val = ptr[i]; + do { + pos--; + buf[pos] = '0' + (val % 10); + val /= 10; + } while (val != 0); /* loop is correct because u8_t needs at most 3 chars */ + res = mdns_domain_add_label(domain, &buf[pos], (u8_t)(3 - pos)); LWIP_ERROR("mdns_build_reverse_v4_domain: Failed to add label", (res == ERR_OK), return res); } res = mdns_domain_add_label(domain, REVERSE_PTR_V4_DOMAIN, (u8_t)(sizeof(REVERSE_PTR_V4_DOMAIN)-1)); From 4d4710dadf121bab0b8b7f431d92978eb1a05b34 Mon Sep 17 00:00:00 2001 From: Daniel Elstner Date: Mon, 19 Sep 2016 10:01:47 +0200 Subject: [PATCH 220/325] Bug #49125 addendum: Remove group from list before callback When leaving a multicast group, remove the group from the list before invoking the MAC filter callback. This avoids the need for the callee to skip over the group that is about to be deleted. --- src/core/ipv4/igmp.c | 19 ++++++++++--------- src/core/ipv6/mld6.c | 15 ++++++++------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/core/ipv4/igmp.c b/src/core/ipv4/igmp.c index ef3b8ab9..a748b5be 100644 --- a/src/core/ipv4/igmp.c +++ b/src/core/ipv4/igmp.c @@ -284,7 +284,7 @@ igmp_lookup_group(struct netif *ifp, const ip4_addr_t *addr) } /** - * Remove a group in the global igmp_group_list + * Remove a group in the global igmp_group_list, but don't free it yet * * @param group the group to remove from the global igmp_group_list * @return ERR_OK if group was removed from the list, an err_t otherwise @@ -311,8 +311,6 @@ igmp_remove_group(struct igmp_group *group) err = ERR_ARG; } } - /* free group */ - memp_free(MEMP_IGMP_GROUP, group); return err; } @@ -601,6 +599,9 @@ igmp_leavegroup_netif(struct netif *netif, const ip4_addr_t *groupaddr) /* If there is no other use of the group */ if (group->use <= 1) { + /* Remove the group from the list */ + igmp_remove_group(group); + /* If we are the last reporter for this group */ if (group->last_reporter_flag) { LWIP_DEBUGF(IGMP_DEBUG, ("igmp_leavegroup_netif: sending leaving group\n")); @@ -608,6 +609,10 @@ igmp_leavegroup_netif(struct netif *netif, const ip4_addr_t *groupaddr) igmp_send(group, IGMP_LEAVE_GROUP); } + LWIP_DEBUGF(IGMP_DEBUG, ("igmp_leavegroup_netif: remove group: ")); + ip4_addr_debug_print(IGMP_DEBUG, groupaddr); + LWIP_DEBUGF(IGMP_DEBUG, ("\n")); + /* Disable the group at the MAC level */ if (netif->igmp_mac_filter != NULL) { LWIP_DEBUGF(IGMP_DEBUG, ("igmp_leavegroup_netif: igmp_mac_filter(DEL ")); @@ -616,12 +621,8 @@ igmp_leavegroup_netif(struct netif *netif, const ip4_addr_t *groupaddr) netif->igmp_mac_filter(netif, groupaddr, NETIF_DEL_MAC_FILTER); } - LWIP_DEBUGF(IGMP_DEBUG, ("igmp_leavegroup_netif: remove group: ")); - ip4_addr_debug_print(IGMP_DEBUG, groupaddr); - LWIP_DEBUGF(IGMP_DEBUG, ("\n")); - - /* Free the group */ - igmp_remove_group(group); + /* Free group struct */ + memp_free(MEMP_IGMP_GROUP, group); } else { /* Decrement group use */ group->use--; diff --git a/src/core/ipv6/mld6.c b/src/core/ipv6/mld6.c index 09fe2a26..0f92548d 100644 --- a/src/core/ipv6/mld6.c +++ b/src/core/ipv6/mld6.c @@ -82,7 +82,7 @@ struct mld_group* mld_group_list; /* Forward declarations. */ static struct mld_group *mld6_new_group(struct netif *ifp, const ip6_addr_t *addr); -static err_t mld6_free_group(struct mld_group *group); +static err_t mld6_remove_group(struct mld_group *group); static void mld6_delayed_report(struct mld_group *group, u16_t maxresp); static void mld6_send(struct mld_group *group, u8_t type); @@ -200,13 +200,13 @@ mld6_new_group(struct netif *ifp, const ip6_addr_t *addr) } /** - * Remove a group in the mld_group_list and free + * Remove a group from the mld_group_list, but do not free it yet * * @param group the group to remove * @return ERR_OK if group was removed from the list, an err_t otherwise */ static err_t -mld6_free_group(struct mld_group *group) +mld6_remove_group(struct mld_group *group) { err_t err = ERR_OK; @@ -227,8 +227,6 @@ mld6_free_group(struct mld_group *group) err = ERR_ARG; } } - /* free group */ - memp_free(MEMP_MLD6_GROUP, group); return err; } @@ -440,6 +438,9 @@ mld6_leavegroup_netif(struct netif *netif, const ip6_addr_t *groupaddr) if (group != NULL) { /* Leave if there is no other use of the group */ if (group->use <= 1) { + /* Remove the group from the list */ + mld6_remove_group(group); + /* If we are the last reporter for this group */ if (group->last_reporter_flag) { MLD6_STATS_INC(mld6.tx_leave); @@ -451,8 +452,8 @@ mld6_leavegroup_netif(struct netif *netif, const ip6_addr_t *groupaddr) netif->mld_mac_filter(netif, groupaddr, NETIF_DEL_MAC_FILTER); } - /* Free the group */ - mld6_free_group(group); + /* free group struct */ + memp_free(MEMP_MLD6_GROUP, group); } else { /* Decrement group use */ group->use--; From 623f9ce04697e58b95bcc524fa7e7ccc0946bffb Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Mon, 19 Sep 2016 12:32:43 +0200 Subject: [PATCH 221/325] Remove one debug message from Daniel's patch --- src/core/ipv4/igmp.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/core/ipv4/igmp.c b/src/core/ipv4/igmp.c index a748b5be..3173221f 100644 --- a/src/core/ipv4/igmp.c +++ b/src/core/ipv4/igmp.c @@ -609,10 +609,6 @@ igmp_leavegroup_netif(struct netif *netif, const ip4_addr_t *groupaddr) igmp_send(group, IGMP_LEAVE_GROUP); } - LWIP_DEBUGF(IGMP_DEBUG, ("igmp_leavegroup_netif: remove group: ")); - ip4_addr_debug_print(IGMP_DEBUG, groupaddr); - LWIP_DEBUGF(IGMP_DEBUG, ("\n")); - /* Disable the group at the MAC level */ if (netif->igmp_mac_filter != NULL) { LWIP_DEBUGF(IGMP_DEBUG, ("igmp_leavegroup_netif: igmp_mac_filter(DEL ")); From 22907c7b27c997c77962a4c9006057823e931b71 Mon Sep 17 00:00:00 2001 From: Daniel Elstner Date: Mon, 19 Sep 2016 03:30:14 +0200 Subject: [PATCH 222/325] bug #74921: check prefix_length, not length --- src/core/ipv6/nd6.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/ipv6/nd6.c b/src/core/ipv6/nd6.c index ff26d095..7806f6e5 100644 --- a/src/core/ipv6/nd6.c +++ b/src/core/ipv6/nd6.c @@ -491,7 +491,7 @@ nd6_input(struct pbuf *p, struct netif *inp) prefix_opt = (struct prefix_option *)buffer; if ((prefix_opt->flags & ND6_PREFIX_FLAG_ON_LINK) && - (prefix_opt->length == 64) && + (prefix_opt->prefix_length == 64) && !ip6_addr_islinklocal(&(prefix_opt->prefix))) { /* Add to on-link prefix list. */ s8_t prefix; From 470dae613e00133fad698d986b75a38fe4600b37 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Tue, 20 Sep 2016 09:03:49 +0200 Subject: [PATCH 223/325] Documentation: Add example for zero-copy RX using custom PBUF --- src/core/pbuf.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/core/pbuf.c b/src/core/pbuf.c index 14dfb720..1400a752 100644 --- a/src/core/pbuf.c +++ b/src/core/pbuf.c @@ -32,6 +32,40 @@ * * Therefore, looping through a pbuf of a single packet, has an * loop end condition (tot_len == p->len), NOT (next == NULL). + * + * Example of custom pbuf usage for zero-copy RX: + @code{.c} +typedef struct my_custom_pbuf +{ + struct pbuf_custom p; + void* dma_descriptor; +} my_custom_pbuf_t; + +void my_pbuf_free_custom(void* p) +{ + my_custom_pbuf_t* my_puf = (my_custom_pbuf_t*)p; + free_rx_dma_descriptor(my_pbuf->dma_descriptor); + my_pbuf_pool_put(my_pbuf); +} + +void eth_rx_irq() +{ + dma_descriptor* dma_desc = get_RX_DMA_descriptor_from_ethernet(); + my_custom_pbuf_t* my_pbuf = my_pbuf_pool_get(); + + my_pbuf->p.custom_free_function = my_pbuf_free_custom; + my_pbuf->dma_descriptor = dma_desc; + + struct pbuf* p = pbuf_alloced_custom(PBUF_RAW, + dma_desc->rx_length, + PBUF_REF, + &my_pbuf.p, + dma_desc->rx_data, + dma_desc->max_buffer_size); + + netif->input(p, netif); +} + @endcode */ /* From eb3a08308d7822a0b244265d89c72a2492eca49a Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Tue, 20 Sep 2016 09:14:32 +0200 Subject: [PATCH 224/325] Improve my last docs --- src/core/pbuf.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/core/pbuf.c b/src/core/pbuf.c index 1400a752..db017fa4 100644 --- a/src/core/pbuf.c +++ b/src/core/pbuf.c @@ -63,7 +63,9 @@ void eth_rx_irq() dma_desc->rx_data, dma_desc->max_buffer_size); - netif->input(p, netif); + if(netif->input(p, netif) != ERR_OK) { + pbuf_free(p); + } } @endcode */ From 19e27806566f2d99a1274a6f5c3acb34512a55e8 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Tue, 20 Sep 2016 14:06:20 +0200 Subject: [PATCH 225/325] Fix bug #49136: No SNMPv2 SetRequest response when OID does not exist --- src/apps/snmp/snmp_msg.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/apps/snmp/snmp_msg.c b/src/apps/snmp/snmp_msg.c index be98a4f6..25c3b3ed 100644 --- a/src/apps/snmp/snmp_msg.c +++ b/src/apps/snmp/snmp_msg.c @@ -525,6 +525,9 @@ snmp_process_set_request(struct snmp_request *request) if (node_instance.release_instance != NULL) { node_instance.release_instance(&node_instance); } + } else if ((request->error_status == SNMP_ERR_NOSUCHINSTANCE) || (request->error_status == SNMP_ERR_NOSUCHOBJECT) || (request->error_status == SNMP_ERR_ENDOFMIBVIEW)) { + /* according to RFC 1905 (4.2.5. The SetRequest-PDU) return 'NotWritable' for unknown OIDs */ + request->error_status = SNMP_ERR_NOTWRITABLE; } } else if (err == SNMP_VB_ENUMERATOR_ERR_EOVB) { /* no more varbinds in request */ From dbd847b70ca7283bfbb58c9c03767289c958b811 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Tue, 20 Sep 2016 14:28:40 +0200 Subject: [PATCH 226/325] Fix bugfix for bug #49136: No SNMPv2 SetRequest response when OID does not exist Last commit broke SNMPv1 answers --- src/apps/snmp/snmp_msg.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/apps/snmp/snmp_msg.c b/src/apps/snmp/snmp_msg.c index 25c3b3ed..e993db33 100644 --- a/src/apps/snmp/snmp_msg.c +++ b/src/apps/snmp/snmp_msg.c @@ -525,9 +525,6 @@ snmp_process_set_request(struct snmp_request *request) if (node_instance.release_instance != NULL) { node_instance.release_instance(&node_instance); } - } else if ((request->error_status == SNMP_ERR_NOSUCHINSTANCE) || (request->error_status == SNMP_ERR_NOSUCHOBJECT) || (request->error_status == SNMP_ERR_ENDOFMIBVIEW)) { - /* according to RFC 1905 (4.2.5. The SetRequest-PDU) return 'NotWritable' for unknown OIDs */ - request->error_status = SNMP_ERR_NOTWRITABLE; } } else if (err == SNMP_VB_ENUMERATOR_ERR_EOVB) { /* no more varbinds in request */ @@ -1361,6 +1358,19 @@ snmp_complete_outbound_frame(struct snmp_request *request) } } } else { + if (request->request_type == SNMP_ASN1_CONTEXT_PDU_SET_REQ) { + /* map error codes to according to RFC 1905 (4.2.5. The SetRequest-PDU) return 'NotWritable' for unknown OIDs) */ + switch (request->error_status) { + case SNMP_ERR_NOSUCHINSTANCE: + case SNMP_ERR_NOSUCHOBJECT: + case SNMP_ERR_ENDOFMIBVIEW: + request->error_status = SNMP_ERR_NOTWRITABLE; + break; + default: + break; + } + } + if (request->error_status >= SNMP_VARBIND_EXCEPTION_OFFSET) { /* should never occur because v2 frames store exceptions directly inside varbinds and not as frame error_status */ LWIP_DEBUGF(SNMP_DEBUG, ("snmp_complete_outbound_frame() > Found v2 request with varbind exception code stored as error status!\n")); From c9bae5ea9bfe288b6a546bd9723893d05b0cfe93 Mon Sep 17 00:00:00 2001 From: Daniel Elstner Date: Tue, 20 Sep 2016 23:22:04 +0200 Subject: [PATCH 227/325] Fix bug #49134: Do not announce invalid IPv4 address via mDNS In a dual stack configuration it is not really feasible to wait until the IPv4 address is valid before starting the mDNS responder. If there is no DHCPv4 server in the network, the IPv4 address may never become valid, which should however not preclude IPv6 mDNS from working. --- src/apps/mdns/mdns.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/apps/mdns/mdns.c b/src/apps/mdns/mdns.c index 7c02c914..5bf15d8c 100644 --- a/src/apps/mdns/mdns.c +++ b/src/apps/mdns/mdns.c @@ -681,9 +681,11 @@ check_host(struct netif *netif, struct mdns_rr_info *rr, u8_t *reverse_v6_reply) } #endif #if LWIP_IPV4 - res = mdns_build_reverse_v4_domain(&mydomain, netif_ip4_addr(netif)); - if (res == ERR_OK && mdns_domain_eq(&rr->domain, &mydomain)) { - replies |= REPLY_HOST_PTR_V4; + if (!ip4_addr_isany_val(*netif_ip4_addr(netif))) { + res = mdns_build_reverse_v4_domain(&mydomain, netif_ip4_addr(netif)); + if (res == ERR_OK && mdns_domain_eq(&rr->domain, &mydomain)) { + replies |= REPLY_HOST_PTR_V4; + } } #endif } @@ -693,7 +695,8 @@ check_host(struct netif *netif, struct mdns_rr_info *rr, u8_t *reverse_v6_reply) if (res == ERR_OK && mdns_domain_eq(&rr->domain, &mydomain)) { /* TODO return NSEC if unsupported protocol requested */ #if LWIP_IPV4 - if (rr->type == DNS_RRTYPE_A || rr->type == DNS_RRTYPE_ANY) { + if (!ip4_addr_isany_val(*netif_ip4_addr(netif)) + && (rr->type == DNS_RRTYPE_A || rr->type == DNS_RRTYPE_ANY)) { replies |= REPLY_HOST_A; } #endif @@ -1497,10 +1500,14 @@ mdns_announce(struct netif *netif, const ip_addr_t *destination) memset(&announce, 0, sizeof(announce)); announce.netif = netif; announce.cache_flush = 1; - announce.host_replies = REPLY_HOST_A | REPLY_HOST_AAAA | REPLY_HOST_PTR_V4 | REPLY_HOST_PTR_V6; +#if LWIP_IPV4 + if (!ip4_addr_isany_val(*netif_ip4_addr(netif))) + announce.host_replies = REPLY_HOST_A | REPLY_HOST_PTR_V4; +#endif #if LWIP_IPV6 for (i = 0; i < LWIP_IPV6_NUM_ADDRESSES; ++i) { if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i))) { + announce.host_replies |= REPLY_HOST_AAAA | REPLY_HOST_PTR_V6; announce.host_reverse_v6_replies |= (1 << i); } } From c25de8f317bd7ba32a269670373c4d7d33b7c755 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Wed, 21 Sep 2016 12:37:31 +0200 Subject: [PATCH 228/325] Update comment in MDNS and pbuf.c --- src/apps/mdns/mdns.c | 2 +- src/core/pbuf.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/apps/mdns/mdns.c b/src/apps/mdns/mdns.c index 5bf15d8c..5da37bcf 100644 --- a/src/apps/mdns/mdns.c +++ b/src/apps/mdns/mdns.c @@ -14,7 +14,7 @@ * ------------------------- * * - Probing/conflict resolution - * - Sending goodbye messages (zero ttl) + * - Sending goodbye messages (zero ttl) - shutdown, DHCP lease about to expire, DHCP turned off... * - Checking that source address of unicast requests are on the same network * - Limiting multicast responses to 1 per second per resource record * - Fragmenting replies if required diff --git a/src/core/pbuf.c b/src/core/pbuf.c index db017fa4..a145dffc 100644 --- a/src/core/pbuf.c +++ b/src/core/pbuf.c @@ -59,7 +59,7 @@ void eth_rx_irq() struct pbuf* p = pbuf_alloced_custom(PBUF_RAW, dma_desc->rx_length, PBUF_REF, - &my_pbuf.p, + &my_pbuf->p, dma_desc->rx_data, dma_desc->max_buffer_size); From c7c6b7ce93b35ea422648c9b088a214554fab8f7 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Wed, 21 Sep 2016 13:33:33 +0200 Subject: [PATCH 229/325] Rework IGMP and MLD6 code to store group info per-netif. Reasoning: - Makes code in single-netif case perform better and smaller - IGMP / MLD6 code is a little bit easier to read and understand - Easier to get multicast groups per netif when implementing drivers Downside: In multi-netif mode, there are two more pointers on each netif, even if IGMP/MLD6 is not used on it. But these systems should not be so memory-constrained that this will matter. --- src/core/ipv4/igmp.c | 113 ++++++++++++++++++--------------------- src/core/ipv6/mld6.c | 113 +++++++++++++++++---------------------- src/core/netif.c | 2 +- src/include/lwip/igmp.h | 8 ++- src/include/lwip/mld6.h | 8 ++- src/include/lwip/netif.h | 32 ++++++----- 6 files changed, 126 insertions(+), 150 deletions(-) diff --git a/src/core/ipv4/igmp.c b/src/core/ipv4/igmp.c index 3173221f..f3db5914 100644 --- a/src/core/ipv4/igmp.c +++ b/src/core/ipv4/igmp.c @@ -97,14 +97,13 @@ Steve Reynolds #include "string.h" static struct igmp_group *igmp_lookup_group(struct netif *ifp, const ip4_addr_t *addr); -static err_t igmp_remove_group(struct igmp_group *group); -static void igmp_timeout( struct igmp_group *group); +static err_t igmp_remove_group(struct netif* netif, struct igmp_group *group); +static void igmp_timeout(struct netif *netif, struct igmp_group *group); static void igmp_start_timer(struct igmp_group *group, u8_t max_time); static void igmp_delaying_member(struct igmp_group *group, u8_t maxresp); static err_t igmp_ip_output_if(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest, struct netif *netif); -static void igmp_send(struct igmp_group *group, u8_t type); +static void igmp_send(struct netif *netif, struct igmp_group *group, u8_t type); -struct igmp_group* igmp_group_list; static ip4_addr_t allsystems; static ip4_addr_t allrouters; @@ -160,36 +159,24 @@ igmp_start(struct netif *netif) err_t igmp_stop(struct netif *netif) { - struct igmp_group *group = igmp_group_list; - struct igmp_group *prev = NULL; - struct igmp_group *next; + struct igmp_group *group = netif_igmp_data(netif); + + netif_set_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_IGMP, NULL); - /* look for groups joined on this interface further down the list */ while (group != NULL) { - next = group->next; - /* is it a group joined on this interface? */ - if (group->netif == netif) { - /* is it the first group of the list? */ - if (group == igmp_group_list) { - igmp_group_list = next; - } - /* is there a "previous" group defined? */ - if (prev != NULL) { - prev->next = next; - } - /* disable the group at the MAC level */ - if (netif->igmp_mac_filter != NULL) { - LWIP_DEBUGF(IGMP_DEBUG, ("igmp_stop: igmp_mac_filter(DEL ")); - ip4_addr_debug_print(IGMP_DEBUG, &group->group_address); - LWIP_DEBUGF(IGMP_DEBUG, (") on if %p\n", (void*)netif)); - netif->igmp_mac_filter(netif, &(group->group_address), NETIF_DEL_MAC_FILTER); - } - /* free group */ - memp_free(MEMP_IGMP_GROUP, group); - } else { - /* change the "previous" */ - prev = group; + struct igmp_group *next = group->next; /* avoid use-after-free below */ + + /* disable the group at the MAC level */ + if (netif->igmp_mac_filter != NULL) { + LWIP_DEBUGF(IGMP_DEBUG, ("igmp_stop: igmp_mac_filter(DEL ")); + ip4_addr_debug_print(IGMP_DEBUG, &group->group_address); + LWIP_DEBUGF(IGMP_DEBUG, (") on if %p\n", (void*)netif)); + netif->igmp_mac_filter(netif, &(group->group_address), NETIF_DEL_MAC_FILTER); } + + /* free group */ + memp_free(MEMP_IGMP_GROUP, group); + /* move to "next" */ group = next; } @@ -204,12 +191,12 @@ igmp_stop(struct netif *netif) void igmp_report_groups(struct netif *netif) { - struct igmp_group *group = igmp_group_list; + struct igmp_group *group = netif_igmp_data(netif); LWIP_DEBUGF(IGMP_DEBUG, ("igmp_report_groups: sending IGMP reports on if %p\n", (void*)netif)); while (group != NULL) { - if ((group->netif == netif) && (!(ip4_addr_cmp(&(group->group_address), &allsystems)))) { + if (!(ip4_addr_cmp(&(group->group_address), &allsystems))) { igmp_delaying_member(group, IGMP_JOIN_DELAYING_MEMBER_TMR); } group = group->next; @@ -227,10 +214,10 @@ igmp_report_groups(struct netif *netif) struct igmp_group * igmp_lookfor_group(struct netif *ifp, const ip4_addr_t *addr) { - struct igmp_group *group = igmp_group_list; + struct igmp_group *group = netif_igmp_data(ifp); while (group != NULL) { - if ((group->netif == ifp) && (ip4_addr_cmp(&(group->group_address), addr))) { + if (ip4_addr_cmp(&(group->group_address), addr)) { return group; } group = group->next; @@ -265,15 +252,14 @@ igmp_lookup_group(struct netif *ifp, const ip4_addr_t *addr) /* Group doesn't exist yet, create a new one */ group = (struct igmp_group *)memp_malloc(MEMP_IGMP_GROUP); if (group != NULL) { - group->netif = ifp; ip4_addr_set(&(group->group_address), addr); group->timer = 0; /* Not running */ group->group_state = IGMP_GROUP_NON_MEMBER; group->last_reporter_flag = 0; group->use = 0; - group->next = igmp_group_list; + group->next = netif_igmp_data(ifp); - igmp_group_list = group; + netif_set_client_data(ifp, LWIP_NETIF_CLIENT_DATA_INDEX_IGMP, group); } LWIP_DEBUGF(IGMP_DEBUG, ("igmp_lookup_group: %sallocated a new group with address ", (group?"":"impossible to "))); @@ -290,17 +276,17 @@ igmp_lookup_group(struct netif *ifp, const ip4_addr_t *addr) * @return ERR_OK if group was removed from the list, an err_t otherwise */ static err_t -igmp_remove_group(struct igmp_group *group) +igmp_remove_group(struct netif* netif, struct igmp_group *group) { err_t err = ERR_OK; /* Is it the first group? */ - if (igmp_group_list == group) { - igmp_group_list = group->next; + if (netif_igmp_data(netif) == group) { + netif_set_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_IGMP, group->next); } else { /* look for group further down the list */ struct igmp_group *tmpGroup; - for (tmpGroup = igmp_group_list; tmpGroup != NULL; tmpGroup = tmpGroup->next) { + for (tmpGroup = netif_igmp_data(netif); tmpGroup != NULL; tmpGroup = tmpGroup->next) { if (tmpGroup->next == group) { tmpGroup->next = group->next; break; @@ -381,10 +367,10 @@ igmp_input(struct pbuf *p, struct netif *inp, const ip4_addr_t *dest) IGMP_STATS_INC(igmp.rx_general); } - groupref = igmp_group_list; + groupref = netif_igmp_data(inp); while (groupref) { /* Do not send messages on the all systems group address! */ - if ((groupref->netif == inp) && (!(ip4_addr_cmp(&(groupref->group_address), &allsystems)))) { + if (!(ip4_addr_cmp(&(groupref->group_address), &allsystems))) { igmp_delaying_member(groupref, igmp->igmp_maxresp); } groupref = groupref->next; @@ -427,7 +413,7 @@ igmp_input(struct pbuf *p, struct netif *inp, const ip4_addr_t *dest) break; default: LWIP_DEBUGF(IGMP_DEBUG, ("igmp_input: unexpected msg %d in state %d on group %p on if %p\n", - igmp->igmp_msgtype, group->group_state, (void*)&group, (void*)group->netif)); + igmp->igmp_msgtype, group->group_state, (void*)&group, (void*)inp)); IGMP_STATS_INC(igmp.proterr); break; } @@ -515,7 +501,7 @@ igmp_joingroup_netif(struct netif *netif, const ip4_addr_t *groupaddr) } IGMP_STATS_INC(igmp.tx_join); - igmp_send(group, IGMP_V2_MEMB_REPORT); + igmp_send(netif, group, IGMP_V2_MEMB_REPORT); igmp_start_timer(group, IGMP_JOIN_DELAYING_MEMBER_TMR); @@ -600,13 +586,13 @@ igmp_leavegroup_netif(struct netif *netif, const ip4_addr_t *groupaddr) /* If there is no other use of the group */ if (group->use <= 1) { /* Remove the group from the list */ - igmp_remove_group(group); + igmp_remove_group(netif, group); /* If we are the last reporter for this group */ if (group->last_reporter_flag) { LWIP_DEBUGF(IGMP_DEBUG, ("igmp_leavegroup_netif: sending leaving group\n")); IGMP_STATS_INC(igmp.tx_leave); - igmp_send(group, IGMP_LEAVE_GROUP); + igmp_send(netif, group, IGMP_LEAVE_GROUP); } /* Disable the group at the MAC level */ @@ -637,16 +623,21 @@ igmp_leavegroup_netif(struct netif *netif, const ip4_addr_t *groupaddr) void igmp_tmr(void) { - struct igmp_group *group = igmp_group_list; + struct netif *netif = netif_list; - while (group != NULL) { - if (group->timer > 0) { - group->timer--; - if (group->timer == 0) { - igmp_timeout(group); + while (netif != NULL) { + struct igmp_group *group = netif_igmp_data(netif); + + while (group != NULL) { + if (group->timer > 0) { + group->timer--; + if (group->timer == 0) { + igmp_timeout(netif, group); + } } + group = group->next; } - group = group->next; + netif = netif->next; } } @@ -657,7 +648,7 @@ igmp_tmr(void) * @param group an igmp_group for which a timeout is reached */ static void -igmp_timeout(struct igmp_group *group) +igmp_timeout(struct netif *netif, struct igmp_group *group) { /* If the state is IGMP_GROUP_DELAYING_MEMBER then we send a report for this group (unless it is the allsystems group) */ @@ -665,10 +656,10 @@ igmp_timeout(struct igmp_group *group) (!(ip4_addr_cmp(&(group->group_address), &allsystems)))) { LWIP_DEBUGF(IGMP_DEBUG, ("igmp_timeout: report membership for group with address ")); ip4_addr_debug_print(IGMP_DEBUG, &(group->group_address)); - LWIP_DEBUGF(IGMP_DEBUG, (" on if %p\n", (void*)group->netif)); + LWIP_DEBUGF(IGMP_DEBUG, (" on if %p\n", (void*)netif)); IGMP_STATS_INC(igmp.tx_report); - igmp_send(group, IGMP_V2_MEMB_REPORT); + igmp_send(netif, group, IGMP_V2_MEMB_REPORT); } } @@ -748,7 +739,7 @@ igmp_ip_output_if(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest, * @param type the type of igmp packet to send */ static void -igmp_send(struct igmp_group *group, u8_t type) +igmp_send(struct netif *netif, struct igmp_group *group, u8_t type) { struct pbuf* p = NULL; struct igmp_msg* igmp = NULL; @@ -762,7 +753,7 @@ igmp_send(struct igmp_group *group, u8_t type) igmp = (struct igmp_msg *)p->payload; LWIP_ASSERT("igmp_send: check that first pbuf can hold struct igmp_msg", (p->len >= sizeof(struct igmp_msg))); - ip4_addr_copy(src, *netif_ip4_addr(group->netif)); + ip4_addr_copy(src, *netif_ip4_addr(netif)); if (type == IGMP_V2_MEMB_REPORT) { dest = &(group->group_address); @@ -781,7 +772,7 @@ igmp_send(struct igmp_group *group, u8_t type) igmp->igmp_checksum = 0; igmp->igmp_checksum = inet_chksum(igmp, IGMP_MINLEN); - igmp_ip_output_if(p, &src, dest, group->netif); + igmp_ip_output_if(p, &src, dest, netif); } pbuf_free(p); diff --git a/src/core/ipv6/mld6.c b/src/core/ipv6/mld6.c index 0f92548d..c8910428 100644 --- a/src/core/ipv6/mld6.c +++ b/src/core/ipv6/mld6.c @@ -75,16 +75,11 @@ #define MLD6_GROUP_DELAYING_MEMBER 1 #define MLD6_GROUP_IDLE_MEMBER 2 - -/* The list of joined groups. */ -struct mld_group* mld_group_list; - - /* Forward declarations. */ static struct mld_group *mld6_new_group(struct netif *ifp, const ip6_addr_t *addr); -static err_t mld6_remove_group(struct mld_group *group); +static err_t mld6_remove_group(struct netif *netif, struct mld_group *group); static void mld6_delayed_report(struct mld_group *group, u16_t maxresp); -static void mld6_send(struct mld_group *group, u8_t type); +static void mld6_send(struct netif *netif, struct mld_group *group, u8_t type); /** @@ -95,33 +90,21 @@ static void mld6_send(struct mld_group *group, u8_t type); err_t mld6_stop(struct netif *netif) { - struct mld_group *group = mld_group_list; - struct mld_group *prev = NULL; - struct mld_group *next; + struct mld_group *group = netif_mld6_data(netif); + + netif_set_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_MLD6, NULL); - /* look for groups joined on this interface further down the list */ while (group != NULL) { - next = group->next; - /* is it a group joined on this interface? */ - if (group->netif == netif) { - /* is it the first group of the list? */ - if (group == mld_group_list) { - mld_group_list = next; - } - /* is there a "previous" group defined? */ - if (prev != NULL) { - prev->next = next; - } - /* disable the group at the MAC level */ - if (netif->mld_mac_filter != NULL) { - netif->mld_mac_filter(netif, &(group->group_address), NETIF_DEL_MAC_FILTER); - } - /* free group */ - memp_free(MEMP_MLD6_GROUP, group); - } else { - /* change the "previous" */ - prev = group; + struct mld_group *next = group->next; /* avoid use-after-free below */ + + /* disable the group at the MAC level */ + if (netif->mld_mac_filter != NULL) { + netif->mld_mac_filter(netif, &(group->group_address), NETIF_DEL_MAC_FILTER); } + + /* free group */ + memp_free(MEMP_MLD6_GROUP, group); + /* move to "next" */ group = next; } @@ -136,12 +119,10 @@ mld6_stop(struct netif *netif) void mld6_report_groups(struct netif *netif) { - struct mld_group *group = mld_group_list; + struct mld_group *group = netif_mld6_data(netif); while (group != NULL) { - if (group->netif == netif) { - mld6_delayed_report(group, MLD6_JOIN_DELAYING_MEMBER_TMR_MS); - } + mld6_delayed_report(group, MLD6_JOIN_DELAYING_MEMBER_TMR_MS); group = group->next; } } @@ -157,10 +138,10 @@ mld6_report_groups(struct netif *netif) struct mld_group * mld6_lookfor_group(struct netif *ifp, const ip6_addr_t *addr) { - struct mld_group *group = mld_group_list; + struct mld_group *group = netif_mld6_data(ifp); while (group != NULL) { - if ((group->netif == ifp) && (ip6_addr_cmp(&(group->group_address), addr))) { + if (ip6_addr_cmp(&(group->group_address), addr)) { return group; } group = group->next; @@ -185,15 +166,14 @@ mld6_new_group(struct netif *ifp, const ip6_addr_t *addr) group = (struct mld_group *)memp_malloc(MEMP_MLD6_GROUP); if (group != NULL) { - group->netif = ifp; ip6_addr_set(&(group->group_address), addr); group->timer = 0; /* Not running */ group->group_state = MLD6_GROUP_IDLE_MEMBER; group->last_reporter_flag = 0; group->use = 0; - group->next = mld_group_list; + group->next = netif_mld6_data(ifp); - mld_group_list = group; + netif_set_client_data(ifp, LWIP_NETIF_CLIENT_DATA_INDEX_MLD6, group); } return group; @@ -206,17 +186,17 @@ mld6_new_group(struct netif *ifp, const ip6_addr_t *addr) * @return ERR_OK if group was removed from the list, an err_t otherwise */ static err_t -mld6_remove_group(struct mld_group *group) +mld6_remove_group(struct netif *netif, struct mld_group *group) { err_t err = ERR_OK; /* Is it the first group? */ - if (mld_group_list == group) { - mld_group_list = group->next; + if (netif_mld6_data(netif) == group) { + netif_set_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_MLD6, group->next); } else { /* look for group further down the list */ struct mld_group *tmpGroup; - for (tmpGroup = mld_group_list; tmpGroup != NULL; tmpGroup = tmpGroup->next) { + for (tmpGroup = netif_mld6_data(netif); tmpGroup != NULL; tmpGroup = tmpGroup->next) { if (tmpGroup->next == group) { tmpGroup->next = group->next; break; @@ -264,10 +244,9 @@ mld6_input(struct pbuf *p, struct netif *inp) ip6_addr_isany(&(mld_hdr->multicast_address))) { MLD6_STATS_INC(mld6.rx_general); /* Report all groups, except all nodes group, and if-local groups. */ - group = mld_group_list; + group = netif_mld6_data(inp); while (group != NULL) { - if ((group->netif == inp) && - (!(ip6_addr_ismulticast_iflocal(&(group->group_address)))) && + if ((!(ip6_addr_ismulticast_iflocal(&(group->group_address)))) && (!(ip6_addr_isallnodes_linklocal(&(group->group_address))))) { mld6_delayed_report(group, mld_hdr->max_resp_delay); } @@ -376,7 +355,7 @@ mld6_joingroup_netif(struct netif *netif, const ip6_addr_t *groupaddr) /* Report our membership. */ MLD6_STATS_INC(mld6.tx_report); - mld6_send(group, ICMP6_TYPE_MLR); + mld6_send(netif, group, ICMP6_TYPE_MLR); mld6_delayed_report(group, MLD6_JOIN_DELAYING_MEMBER_TMR_MS); } @@ -439,12 +418,12 @@ mld6_leavegroup_netif(struct netif *netif, const ip6_addr_t *groupaddr) /* Leave if there is no other use of the group */ if (group->use <= 1) { /* Remove the group from the list */ - mld6_remove_group(group); + mld6_remove_group(netif, group); /* If we are the last reporter for this group */ if (group->last_reporter_flag) { MLD6_STATS_INC(mld6.tx_leave); - mld6_send(group, ICMP6_TYPE_MLD); + mld6_send(netif, group, ICMP6_TYPE_MLD); } /* Disable the group at the MAC level */ @@ -477,21 +456,25 @@ mld6_leavegroup_netif(struct netif *netif, const ip6_addr_t *groupaddr) void mld6_tmr(void) { - struct mld_group *group = mld_group_list; + struct netif *netif = netif_list; - while (group != NULL) { - if (group->timer > 0) { - group->timer--; - if (group->timer == 0) { - /* If the state is MLD6_GROUP_DELAYING_MEMBER then we send a report for this group */ - if (group->group_state == MLD6_GROUP_DELAYING_MEMBER) { - MLD6_STATS_INC(mld6.tx_report); - mld6_send(group, ICMP6_TYPE_MLR); - group->group_state = MLD6_GROUP_IDLE_MEMBER; + while (netif != NULL) { + struct mld_group *group = netif_mld6_data(netif); + + while (group != NULL) { + if (group->timer > 0) { + group->timer--; + if (group->timer == 0) { + /* If the state is MLD6_GROUP_DELAYING_MEMBER then we send a report for this group */ + if (group->group_state == MLD6_GROUP_DELAYING_MEMBER) { + MLD6_STATS_INC(mld6.tx_report); + mld6_send(netif, group, ICMP6_TYPE_MLR); + group->group_state = MLD6_GROUP_IDLE_MEMBER; + } } } + group = group->next; } - group = group->next; } } @@ -538,7 +521,7 @@ mld6_delayed_report(struct mld_group *group, u16_t maxresp) * @param type ICMP6_TYPE_MLR (report) or ICMP6_TYPE_MLD (done) */ static void -mld6_send(struct mld_group *group, u8_t type) +mld6_send(struct netif *netif, struct mld_group *group, u8_t type) { struct mld_header *mld_hdr; struct pbuf *p; @@ -559,13 +542,13 @@ mld6_send(struct mld_group *group, u8_t type) } /* Select our source address. */ - if (!ip6_addr_isvalid(netif_ip6_addr_state(group->netif, 0))) { + if (!ip6_addr_isvalid(netif_ip6_addr_state(netif, 0))) { /* This is a special case, when we are performing duplicate address detection. * We must join the multicast group, but we don't have a valid address yet. */ src_addr = IP6_ADDR_ANY6; } else { /* Use link-local address as source address. */ - src_addr = netif_ip6_addr(group->netif, 0); + src_addr = netif_ip6_addr(netif, 0); } /* MLD message header pointer. */ @@ -592,7 +575,7 @@ mld6_send(struct mld_group *group, u8_t type) /* Send the packet out. */ MLD6_STATS_INC(mld6.xmit); ip6_output_if(p, (ip6_addr_isany(src_addr)) ? NULL : src_addr, &(group->group_address), - MLD6_HL, 0, IP6_NEXTH_HOPBYHOP, group->netif); + MLD6_HL, 0, IP6_NEXTH_HOPBYHOP, netif); pbuf_free(p); } diff --git a/src/core/netif.c b/src/core/netif.c index 819b4ecc..7ea44829 100644 --- a/src/core/netif.c +++ b/src/core/netif.c @@ -259,7 +259,7 @@ netif_add(struct netif *netif, #endif /* LWIP_IPV6 */ NETIF_SET_CHECKSUM_CTRL(netif, NETIF_CHECKSUM_ENABLE_ALL); netif->flags = 0; -#if LWIP_DHCP || LWIP_AUTOIP || (LWIP_NUM_NETIF_CLIENT_DATA > 0) +#ifdef netif_get_client_data memset(netif->client_data, 0, sizeof(netif->client_data)); #endif /* LWIP_NUM_NETIF_CLIENT_DATA */ #if LWIP_IPV6_AUTOCONFIG diff --git a/src/include/lwip/igmp.h b/src/include/lwip/igmp.h index 6b46bbcc..ba9986b2 100644 --- a/src/include/lwip/igmp.h +++ b/src/include/lwip/igmp.h @@ -74,8 +74,6 @@ extern "C" { struct igmp_group { /** next link */ struct igmp_group *next; - /** interface on which the group is active */ - struct netif *netif; /** multicast address */ ip4_addr_t group_address; /** signifies we were the last person to report */ @@ -88,9 +86,6 @@ struct igmp_group { u8_t use; }; -/* Head of IGMP group list */ -extern struct igmp_group* igmp_group_list; - /* Prototypes */ void igmp_init(void); err_t igmp_start(struct netif *netif); @@ -104,6 +99,9 @@ err_t igmp_leavegroup(const ip4_addr_t *ifaddr, const ip4_addr_t *groupaddr); err_t igmp_leavegroup_netif(struct netif *netif, const ip4_addr_t *groupaddr); void igmp_tmr(void); +/* Get list of IGMP groups for netif */ +#define netif_igmp_data(netif) ((struct igmp_group *)netif_get_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_IGMP)) + #ifdef __cplusplus } #endif diff --git a/src/include/lwip/mld6.h b/src/include/lwip/mld6.h index 02637e8b..eebab250 100644 --- a/src/include/lwip/mld6.h +++ b/src/include/lwip/mld6.h @@ -58,8 +58,6 @@ extern "C" { struct mld_group { /** next link */ struct mld_group *next; - /** interface on which the group is active */ - struct netif *netif; /** multicast address */ ip6_addr_t group_address; /** signifies we were the last person to report */ @@ -72,9 +70,6 @@ struct mld_group { u8_t use; }; -/* Head of MLD group list */ -extern struct mld_group* mld_group_list; - #define MLD6_TMR_INTERVAL 100 /* Milliseconds */ err_t mld6_stop(struct netif *netif); @@ -87,6 +82,9 @@ err_t mld6_joingroup_netif(struct netif *netif, const ip6_addr_t *groupaddr); err_t mld6_leavegroup(const ip6_addr_t *srcaddr, const ip6_addr_t *groupaddr); err_t mld6_leavegroup_netif(struct netif *netif, const ip6_addr_t *groupaddr); +/* Get list of MLD6 groups for netif */ +#define netif_mld6_data(netif) ((struct mld_group *)netif_get_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_MLD6)) + #ifdef __cplusplus } #endif diff --git a/src/include/lwip/netif.h b/src/include/lwip/netif.h index 0b2bfab3..1d19b27a 100644 --- a/src/include/lwip/netif.h +++ b/src/include/lwip/netif.h @@ -111,6 +111,12 @@ enum lwip_internal_netif_client_data_index #endif #if LWIP_AUTOIP LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP, +#endif +#if LWIP_IGMP + LWIP_NETIF_CLIENT_DATA_INDEX_IGMP, +#endif +#if LWIP_IPV6_MLD + LWIP_NETIF_CLIENT_DATA_INDEX_MLD6, #endif LWIP_NETIF_CLIENT_DATA_INDEX_MAX }; @@ -201,6 +207,18 @@ typedef err_t (*netif_mld_mac_filter_fn)(struct netif *netif, const ip6_addr_t *group, enum netif_mac_filter_action action); #endif /* LWIP_IPV6 && LWIP_IPV6_MLD */ +#if LWIP_DHCP || LWIP_AUTOIP || LWIP_IGMP || LWIP_IPV6_MLD || (LWIP_NUM_NETIF_CLIENT_DATA > 0) +u8_t netif_alloc_client_data_id(void); +/** @ingroup netif_cd + * Set client data. Obtain ID from netif_alloc_client_data_id(). + */ +#define netif_set_client_data(netif, id, data) netif_get_client_data(netif, id) = (data) +/** @ingroup netif_cd + * Get client data. Obtain ID from netif_alloc_client_data_id(). + */ +#define netif_get_client_data(netif, id) (netif)->client_data[(id)] +#endif /* LWIP_DHCP || LWIP_AUTOIP || (LWIP_NUM_NETIF_CLIENT_DATA > 0) */ + /** Generic data structure used for all lwIP network interfaces. * The following fields should be filled in by the initialization * function for the device driver: hwaddr_len, hwaddr[], mtu, flags */ @@ -257,7 +275,7 @@ struct netif { /** This field can be set by the device driver and could point * to state information for the device. */ void *state; -#if LWIP_DHCP || LWIP_AUTOIP || (LWIP_NUM_NETIF_CLIENT_DATA > 0) +#ifdef netif_get_client_data void* client_data[LWIP_NETIF_CLIENT_DATA_INDEX_MAX + LWIP_NUM_NETIF_CLIENT_DATA]; #endif #if LWIP_IPV6_AUTOCONFIG @@ -424,18 +442,6 @@ void netif_poll_all(void); err_t netif_input(struct pbuf *p, struct netif *inp); -#if LWIP_DHCP || LWIP_AUTOIP || (LWIP_NUM_NETIF_CLIENT_DATA > 0) -u8_t netif_alloc_client_data_id(void); -/** @ingroup netif_cd - * Set client data. Obtain ID from netif_alloc_client_data_id(). - */ -#define netif_set_client_data(netif, id, data) netif_get_client_data(netif, id) = (data) -/** @ingroup netif_cd - * Get client data. Obtain ID from netif_alloc_client_data_id(). - */ -#define netif_get_client_data(netif, id) (netif)->client_data[(id)] -#endif /* LWIP_DHCP || LWIP_AUTOIP || (LWIP_NUM_NETIF_CLIENT_DATA > 0) */ - #if LWIP_IPV6 /** @ingroup netif_ip6 */ #define netif_ip_addr6(netif, i) ((const ip_addr_t*)(&((netif)->ip6_addr[i]))) From 354e385453807638ee682521af4fc0fd638a660c Mon Sep 17 00:00:00 2001 From: Daniel Elstner Date: Thu, 22 Sep 2016 00:04:56 +0200 Subject: [PATCH 230/325] Fix infinite loop in new MLD6 code --- src/core/ipv6/mld6.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/core/ipv6/mld6.c b/src/core/ipv6/mld6.c index c8910428..2ebcff32 100644 --- a/src/core/ipv6/mld6.c +++ b/src/core/ipv6/mld6.c @@ -475,6 +475,7 @@ mld6_tmr(void) } group = group->next; } + netif = netif->next; } } From 2f085aa441b18cd61c55186ab67eecbf22d817fe Mon Sep 17 00:00:00 2001 From: Daniel Elstner Date: Thu, 22 Sep 2016 00:08:45 +0200 Subject: [PATCH 231/325] ND6: Join/leave groups directly on the netif --- src/core/ipv6/nd6.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/ipv6/nd6.c b/src/core/ipv6/nd6.c index 7806f6e5..d097f373 100644 --- a/src/core/ipv6/nd6.c +++ b/src/core/ipv6/nd6.c @@ -186,7 +186,7 @@ nd6_input(struct pbuf *p, struct netif *inp) #if LWIP_IPV6_MLD /* Leave solicited node multicast group. */ ip6_addr_set_solicitednode(&multicast_address, netif_ip6_addr(inp, i)->addr[3]); - mld6_leavegroup(netif_ip6_addr(inp, i), &multicast_address); + mld6_leavegroup_netif(inp, &multicast_address); #endif /* LWIP_IPV6_MLD */ #if LWIP_IPV6_AUTOCONFIG @@ -825,7 +825,7 @@ nd6_tmr(void) if ((addr_state & IP6_ADDR_TENTATIVE_COUNT_MASK) == 0) { /* Join solicited node multicast group. */ ip6_addr_set_solicitednode(&multicast_address, netif_ip6_addr(netif, i)->addr[3]); - mld6_joingroup(netif_ip6_addr(netif, i), &multicast_address); + mld6_joingroup_netif(netif, &multicast_address); } #endif /* LWIP_IPV6_MLD */ /* Send a NS for this address. */ From 97b774ceb9f3fc8552839c709dc27f6f245d19b8 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Mon, 26 Sep 2016 21:45:29 +0200 Subject: [PATCH 232/325] Minor: Documentation updates --- src/core/ipv6/ethip6.c | 2 +- src/core/netif.c | 4 +++- src/include/lwip/netif.h | 8 +++++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/core/ipv6/ethip6.c b/src/core/ipv6/ethip6.c index 1ae784f8..f863d2bb 100644 --- a/src/core/ipv6/ethip6.c +++ b/src/core/ipv6/ethip6.c @@ -72,7 +72,7 @@ * * @return * - ERR_RTE No route to destination (no gateway to external networks), - * or the return type of either etharp_query() or ethernet_output(). + * or the return type of either nd6_queue_packet() or ethernet_output(). */ err_t ethip6_output(struct netif *netif, struct pbuf *q, const ip6_addr_t *ip6addr) diff --git a/src/core/netif.c b/src/core/netif.c index 7ea44829..2d7c8750 100644 --- a/src/core/netif.c +++ b/src/core/netif.c @@ -227,7 +227,9 @@ netif_input(struct pbuf *p, struct netif *inp) * These functions use netif flags NETIF_FLAG_ETHARP and NETIF_FLAG_ETHERNET * to decide whether to forward to ethernet_input() or ip_input(). * In other words, the functions only work when the netif - * driver is implemented correctly! + * driver is implemented correctly!\n + * Members of struct netif should be be initialized by the + * netif init function = netif driver (init parameter of this function). * * @return netif, or NULL if failed. */ diff --git a/src/include/lwip/netif.h b/src/include/lwip/netif.h index 1d19b27a..6b164b4c 100644 --- a/src/include/lwip/netif.h +++ b/src/include/lwip/netif.h @@ -245,17 +245,19 @@ struct netif { #if LWIP_IPV4 /** This function is called by the IP module when it wants * to send a packet on the interface. This function typically - * first resolves the hardware address, then sends the packet. */ + * first resolves the hardware address, then sends the packet. + * For ethernet physical layer, this is usually etharp_output() */ netif_output_fn output; #endif /* LWIP_IPV4 */ - /** This function is called by the ARP module when it wants + /** This function is called by ethernet_output() when it wants * to send a packet on the interface. This function outputs * the pbuf as-is on the link medium. */ netif_linkoutput_fn linkoutput; #if LWIP_IPV6 /** This function is called by the IPv6 module when it wants * to send a packet on the interface. This function typically - * first resolves the hardware address, then sends the packet. */ + * first resolves the hardware address, then sends the packet. + * For ethernet physical layer, this is usually ethip6_output() */ netif_output_ip6_fn output_ip6; #endif /* LWIP_IPV6 */ #if LWIP_NETIF_STATUS_CALLBACK From 6abcd00f71becf31c43fd66ee85e758863b43b65 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Tue, 27 Sep 2016 09:46:51 +0200 Subject: [PATCH 233/325] Convert IP address type numbers to an enum to improve documentation --- src/core/raw.c | 2 +- src/core/tcp.c | 2 +- src/core/udp.c | 2 +- src/include/lwip/ip_addr.h | 17 +++++++++++------ 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/core/raw.c b/src/core/raw.c index a3a90778..244ab40a 100644 --- a/src/core/raw.c +++ b/src/core/raw.c @@ -471,7 +471,7 @@ raw_new(u8_t proto) * @return The RAW PCB which was created. NULL if the PCB data structure * could not be allocated. * - * @param type IP address type, see IPADDR_TYPE_XX definitions. + * @param type IP address type, see @ref lwip_ip_addr_type definitions. * If you want to listen to IPv4 and IPv6 (dual-stack) packets, * supply @ref IPADDR_TYPE_ANY as argument and bind to @ref IP_ANY_TYPE. * @param proto the protocol number (next header) of the IPv6 packet payload diff --git a/src/core/tcp.c b/src/core/tcp.c index 50aa31f2..9c31f4b8 100644 --- a/src/core/tcp.c +++ b/src/core/tcp.c @@ -1602,7 +1602,7 @@ tcp_new(void) * place it on any of the TCP PCB lists. * The pcb is not put on any list until binding using tcp_bind(). * - * @param type IP address type, see IPADDR_TYPE_XX definitions. + * @param type IP address type, see @ref lwip_ip_addr_type definitions. * If you want to listen to IPv4 and IPv6 (dual-stack) connections, * supply @ref IPADDR_TYPE_ANY as argument and bind to @ref IP_ANY_TYPE. * @return a new tcp_pcb that initially is in state CLOSED diff --git a/src/core/udp.c b/src/core/udp.c index 20e97da6..34fbdd14 100644 --- a/src/core/udp.c +++ b/src/core/udp.c @@ -1143,7 +1143,7 @@ udp_new(void) * @ingroup udp_raw * Create a UDP PCB for specific IP type. * - * @param type IP address type, see IPADDR_TYPE_XX definitions. + * @param type IP address type, see @ref lwip_ip_addr_type definitions. * If you want to listen to IPv4 and IPv6 (dual-stack) packets, * supply @ref IPADDR_TYPE_ANY as argument and bind to @ref IP_ANY_TYPE. * @return The UDP PCB which was created. NULL if the PCB data structure diff --git a/src/include/lwip/ip_addr.h b/src/include/lwip/ip_addr.h index 4b13e702..864f12f9 100644 --- a/src/include/lwip/ip_addr.h +++ b/src/include/lwip/ip_addr.h @@ -47,14 +47,18 @@ extern "C" { #endif -/** Value for ip_addr_t.type: IPv4 */ -#define IPADDR_TYPE_V4 0U -/** Value for ip_addr_t.type: IPv6 */ -#define IPADDR_TYPE_V6 6U -/** Value for ip_addr_t.type: IPv4+IPv6 ("dual-stack") +/** @ingroup ipaddr + * IP address types for use in ip_addr_t.type member. * @see tcp_new_ip_type(), udp_new_ip_type(), raw_new_ip_type(). */ -#define IPADDR_TYPE_ANY 46U +enum lwip_ip_addr_type { + /** IPv4 */ + IPADDR_TYPE_V4 = 0U, + /** IPv6 */ + IPADDR_TYPE_V6 = 6U, + /** IPv4+IPv6 ("dual-stack") */ + IPADDR_TYPE_ANY = 46U +}; #if LWIP_IPV4 && LWIP_IPV6 /** @@ -67,6 +71,7 @@ typedef struct _ip_addr { ip6_addr_t ip6; ip4_addr_t ip4; } u_addr; + /** @ref lwip_ip_addr_type */ u8_t type; } ip_addr_t; From 5d811d799c318c9069917ebbf779687a6ec861d9 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Tue, 27 Sep 2016 21:18:03 +0200 Subject: [PATCH 234/325] Minor: Documentation updates --- doc/doxygen/main_page.h | 2 +- src/include/lwip/igmp.h | 4 +++- src/include/lwip/mld6.h | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/doc/doxygen/main_page.h b/doc/doxygen/main_page.h index 6486a17d..db9c81e4 100644 --- a/doc/doxygen/main_page.h +++ b/doc/doxygen/main_page.h @@ -49,7 +49,7 @@ * Porting: implement all functions in @ref sys_time and @ref sys_prot.\n * You can only use @ref callbackstyle_api in this mode.\n * Sample code:\n - * @verbinclude NO_SYS_SampleCode.c + * @include NO_SYS_SampleCode.c */ /** diff --git a/src/include/lwip/igmp.h b/src/include/lwip/igmp.h index ba9986b2..58c34fc3 100644 --- a/src/include/lwip/igmp.h +++ b/src/include/lwip/igmp.h @@ -99,7 +99,9 @@ err_t igmp_leavegroup(const ip4_addr_t *ifaddr, const ip4_addr_t *groupaddr); err_t igmp_leavegroup_netif(struct netif *netif, const ip4_addr_t *groupaddr); void igmp_tmr(void); -/* Get list of IGMP groups for netif */ +/** @ingroup igmp + * Get list head of IGMP groups for netif + */ #define netif_igmp_data(netif) ((struct igmp_group *)netif_get_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_IGMP)) #ifdef __cplusplus diff --git a/src/include/lwip/mld6.h b/src/include/lwip/mld6.h index eebab250..1c724c02 100644 --- a/src/include/lwip/mld6.h +++ b/src/include/lwip/mld6.h @@ -82,7 +82,9 @@ err_t mld6_joingroup_netif(struct netif *netif, const ip6_addr_t *groupaddr); err_t mld6_leavegroup(const ip6_addr_t *srcaddr, const ip6_addr_t *groupaddr); err_t mld6_leavegroup_netif(struct netif *netif, const ip6_addr_t *groupaddr); -/* Get list of MLD6 groups for netif */ +/** @ingroup mld6 + * Get list head of MLD6 groups for netif + */ #define netif_mld6_data(netif) ((struct mld_group *)netif_get_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_MLD6)) #ifdef __cplusplus From 0e2354e658d9dc193d60048a8394517a41ca64ff Mon Sep 17 00:00:00 2001 From: goldsimon Date: Wed, 28 Sep 2016 12:53:07 +0200 Subject: [PATCH 235/325] Fixed bug #49209: netconn_drain() fails to handle 'netconn_aborted' pointer --- src/api/api_msg.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/api/api_msg.c b/src/api/api_msg.c index 9dfea64e..8b7a6bd9 100644 --- a/src/api/api_msg.c +++ b/src/api/api_msg.c @@ -780,7 +780,8 @@ netconn_drain(struct netconn *conn) /* Delete and drain the acceptmbox. */ #if LWIP_TCP if (sys_mbox_valid(&conn->acceptmbox)) { - while (sys_mbox_tryfetch(&conn->acceptmbox, &mem) != SYS_MBOX_EMPTY) { + while ((sys_mbox_tryfetch(&conn->acceptmbox, &mem) != SYS_MBOX_EMPTY) && + (mem != &netconn_aborted)) { struct netconn *newconn = (struct netconn *)mem; /* Only tcp pcbs have an acceptmbox, so no need to check conn->type */ /* pcb might be set to NULL already by err_tcp() */ From 633696c1532374c624eb475111e02743e7af2cd1 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Wed, 28 Sep 2016 12:56:39 +0200 Subject: [PATCH 236/325] Implement consistent IPx_ADDR_ANYx macro naming between IPv4 and IPv6 - rename IP4_ADDR_ANY to IP4_ADDR_ANY4 - IP4_ADDR_ANY (= IP_ADDR_ANY) is now IPv4 any address in ip_addr_t format --- src/api/api_lib.c | 12 ++++++------ src/api/netifapi.c | 12 ++++++------ src/apps/lwiperf/lwiperf.c | 2 +- src/apps/mdns/mdns.c | 4 ++-- src/apps/snmp/snmp_core.c | 2 +- src/apps/snmp/snmp_mib2_ip.c | 6 +++--- src/apps/snmp/snmp_mib2_tcp.c | 6 +++--- src/apps/snmp/snmp_netconn.c | 2 +- src/apps/snmp/snmp_raw.c | 2 +- src/apps/sntp/sntp.c | 2 +- src/core/dns.c | 4 ++-- src/core/ipv4/autoip.c | 4 ++-- src/core/ipv4/dhcp.c | 14 +++++++------- src/core/ipv4/igmp.c | 4 ++-- src/core/ipv4/ip4.c | 8 ++++---- src/core/ipv4/ip4_addr.c | 2 +- src/core/netif.c | 2 +- src/core/raw.c | 2 +- src/core/tcp.c | 4 ++-- src/core/udp.c | 4 ++-- src/include/lwip/ip_addr.h | 22 ++++++++++++++-------- src/netif/ppp/ppp.c | 8 ++++---- src/netif/ppp/pppol2tp.c | 2 +- 23 files changed, 68 insertions(+), 62 deletions(-) diff --git a/src/api/api_lib.c b/src/api/api_lib.c index 740fe396..e129473d 100644 --- a/src/api/api_lib.c +++ b/src/api/api_lib.c @@ -241,8 +241,8 @@ netconn_getaddr(struct netconn *conn, ip_addr_t *addr, u16_t *port, u8_t local) * Binding one netconn twice might not always be checked correctly! * * @param conn the netconn to bind - * @param addr the local IP address to bind the netconn to (use IP_ADDR_ANY - * to bind to all addresses) + * @param addr the local IP address to bind the netconn to + * (use IP4_ADDR_ANY/IP6_ADDR_ANY to bind to all addresses) * @param port the local port to bind the netconn to (not used for RAW) * @return ERR_OK if bound, any other err_t on failure */ @@ -256,7 +256,7 @@ netconn_bind(struct netconn *conn, const ip_addr_t *addr, u16_t port) /* Don't propagate NULL pointer (IP_ADDR_ANY alias) to subsequent functions */ if (addr == NULL) { - addr = IP_ADDR_ANY; + addr = IP4_ADDR_ANY; } API_MSG_VAR_ALLOC(msg); @@ -288,7 +288,7 @@ netconn_connect(struct netconn *conn, const ip_addr_t *addr, u16_t port) /* Don't propagate NULL pointer (IP_ADDR_ANY alias) to subsequent functions */ if (addr == NULL) { - addr = IP_ADDR_ANY; + addr = IP4_ADDR_ANY; } API_MSG_VAR_ALLOC(msg); @@ -867,10 +867,10 @@ netconn_join_leave_group(struct netconn *conn, /* Don't propagate NULL pointer (IP_ADDR_ANY alias) to subsequent functions */ if (multiaddr == NULL) { - multiaddr = IP_ADDR_ANY; + multiaddr = IP4_ADDR_ANY; } if (netif_addr == NULL) { - netif_addr = IP_ADDR_ANY; + netif_addr = IP4_ADDR_ANY; } API_MSG_VAR_REF(msg).conn = conn; diff --git a/src/api/netifapi.c b/src/api/netifapi.c index 265b60c5..6f7e55bf 100644 --- a/src/api/netifapi.c +++ b/src/api/netifapi.c @@ -134,13 +134,13 @@ netifapi_netif_add(struct netif *netif, #if LWIP_IPV4 if (ipaddr == NULL) { - ipaddr = IP4_ADDR_ANY; + ipaddr = IP4_ADDR_ANY4; } if (netmask == NULL) { - netmask = IP4_ADDR_ANY; + netmask = IP4_ADDR_ANY4; } if (gw == NULL) { - gw = IP4_ADDR_ANY; + gw = IP4_ADDR_ANY4; } #endif /* LWIP_IPV4 */ @@ -177,13 +177,13 @@ netifapi_netif_set_addr(struct netif *netif, NETIFAPI_VAR_ALLOC(msg); if (ipaddr == NULL) { - ipaddr = IP4_ADDR_ANY; + ipaddr = IP4_ADDR_ANY4; } if (netmask == NULL) { - netmask = IP4_ADDR_ANY; + netmask = IP4_ADDR_ANY4; } if (gw == NULL) { - gw = IP4_ADDR_ANY; + gw = IP4_ADDR_ANY4; } NETIFAPI_VAR_REF(msg).netif = netif; diff --git a/src/apps/lwiperf/lwiperf.c b/src/apps/lwiperf/lwiperf.c index fea2c06f..255e282a 100644 --- a/src/apps/lwiperf/lwiperf.c +++ b/src/apps/lwiperf/lwiperf.c @@ -579,7 +579,7 @@ lwiperf_tcp_accept(void *arg, struct tcp_pcb *newpcb, err_t err) void* lwiperf_start_tcp_server_default(lwiperf_report_fn report_fn, void* report_arg) { - return lwiperf_start_tcp_server(IP_ADDR_ANY, LWIPERF_TCP_PORT_DEFAULT, + return lwiperf_start_tcp_server(IP4_ADDR_ANY, LWIPERF_TCP_PORT_DEFAULT, report_fn, report_arg); } diff --git a/src/apps/mdns/mdns.c b/src/apps/mdns/mdns.c index 5da37bcf..662ccd31 100644 --- a/src/apps/mdns/mdns.c +++ b/src/apps/mdns/mdns.c @@ -1892,7 +1892,7 @@ mdns_resp_netif_settings_changed(struct netif *netif) mdns_announce(netif, IP6_ADDR_ANY); #endif #if LWIP_IPV4 - mdns_announce(netif, IP_ADDR_ANY); + mdns_announce(netif, IP4_ADDR_ANY); #endif } @@ -2044,7 +2044,7 @@ mdns_resp_add_service(struct netif *netif, const char *name, const char *service mdns_announce(netif, IP6_ADDR_ANY); #endif #if LWIP_IPV4 - mdns_announce(netif, IP_ADDR_ANY); + mdns_announce(netif, IP4_ADDR_ANY); #endif return ERR_OK; diff --git a/src/apps/snmp/snmp_core.c b/src/apps/snmp/snmp_core.c index 1230d62b..a9213727 100644 --- a/src/apps/snmp/snmp_core.c +++ b/src/apps/snmp/snmp_core.c @@ -270,7 +270,7 @@ snmp_oid_to_ip4(const u32_t *oid, ip4_addr_t *ip) (oid[1] > 0xFF) || (oid[2] > 0xFF) || (oid[3] > 0xFF)) { - ip4_addr_copy(*ip, *IP4_ADDR_ANY); + ip4_addr_copy(*ip, *IP4_ADDR_ANY4); return 0; } diff --git a/src/apps/snmp/snmp_mib2_ip.c b/src/apps/snmp/snmp_mib2_ip.c index b14a5565..b28e162f 100644 --- a/src/apps/snmp/snmp_mib2_ip.c +++ b/src/apps/snmp/snmp_mib2_ip.c @@ -326,7 +326,7 @@ ip_RouteTable_get_cell_value_core(struct netif *netif, u8_t default_route, const case 1: /* ipRouteDest */ if (default_route) { /* default rte has 0.0.0.0 dest */ - value->u32 = IP4_ADDR_ANY->addr; + value->u32 = IP4_ADDR_ANY4->addr; } else { /* netifs have netaddress dest */ ip4_addr_t tmp; @@ -378,7 +378,7 @@ ip_RouteTable_get_cell_value_core(struct netif *netif, u8_t default_route, const case 11: /* ipRouteMask */ if (default_route) { /* default rte use 0.0.0.0 mask */ - value->u32 = IP4_ADDR_ANY->addr; + value->u32 = IP4_ADDR_ANY4->addr; } else { /* other rtes use netmask */ value->u32 = netif_ip4_netmask(netif)->addr; @@ -449,7 +449,7 @@ ip_RouteTable_get_next_cell_instance_and_value(const u32_t* column, struct snmp_ /* check default route */ if (netif_default != NULL) { - snmp_ip4_to_oid(IP4_ADDR_ANY, &test_oid[0]); + snmp_ip4_to_oid(IP4_ADDR_ANY4, &test_oid[0]); snmp_next_oid_check(&state, test_oid, LWIP_ARRAYSIZE(ip_RouteTable_oid_ranges), netif_default); } diff --git a/src/apps/snmp/snmp_mib2_tcp.c b/src/apps/snmp/snmp_mib2_tcp.c index f72e6a51..21f69656 100644 --- a/src/apps/snmp/snmp_mib2_tcp.c +++ b/src/apps/snmp/snmp_mib2_tcp.c @@ -172,7 +172,7 @@ tcp_ConnTable_get_cell_value_core(struct tcp_pcb *pcb, const u32_t* column, unio break; case 4: /* tcpConnRemAddress */ if (pcb->state == LISTEN) { - value->u32 = IP4_ADDR_ANY->addr; + value->u32 = IP4_ADDR_ANY4->addr; } else { value->u32 = ip_2_ip4(&pcb->remote_ip)->addr; } @@ -224,7 +224,7 @@ tcp_ConnTable_get_cell_value(const u32_t* column, const u32_t* row_oid, u8_t row /* PCBs in state LISTEN are not connected and have no remote_ip or remote_port */ if (pcb->state == LISTEN) { - if (ip4_addr_cmp(&remote_ip, IP4_ADDR_ANY) && (remote_port == 0)) { + if (ip4_addr_cmp(&remote_ip, IP4_ADDR_ANY4) && (remote_port == 0)) { /* fill in object properties */ return tcp_ConnTable_get_cell_value_core(pcb, column, value, value_len); } @@ -268,7 +268,7 @@ tcp_ConnTable_get_next_cell_instance_and_value(const u32_t* column, struct snmp_ /* PCBs in state LISTEN are not connected and have no remote_ip or remote_port */ if (pcb->state == LISTEN) { - snmp_ip4_to_oid(IP4_ADDR_ANY, &test_oid[5]); + snmp_ip4_to_oid(IP4_ADDR_ANY4, &test_oid[5]); test_oid[9] = 0; } else { if (IP_IS_V6_VAL(pcb->remote_ip)) { /* should never happen */ diff --git a/src/apps/snmp/snmp_netconn.c b/src/apps/snmp/snmp_netconn.c index 7eead2e6..070b41c3 100644 --- a/src/apps/snmp/snmp_netconn.c +++ b/src/apps/snmp/snmp_netconn.c @@ -57,7 +57,7 @@ snmp_netconn_thread(void *arg) netconn_bind(conn, IP6_ADDR_ANY, SNMP_IN_PORT); #else /* LWIP_IPV6 */ conn = netconn_new(NETCONN_UDP); - netconn_bind(conn, IP_ADDR_ANY, SNMP_IN_PORT); + netconn_bind(conn, IP4_ADDR_ANY, SNMP_IN_PORT); #endif /* LWIP_IPV6 */ LWIP_ERROR("snmp_netconn: invalid conn", (conn != NULL), return;); diff --git a/src/apps/snmp/snmp_raw.c b/src/apps/snmp/snmp_raw.c index 8cfe77a6..4a40864f 100644 --- a/src/apps/snmp/snmp_raw.c +++ b/src/apps/snmp/snmp_raw.c @@ -80,7 +80,7 @@ snmp_get_local_ip_for_dst(void* handle, const ip_addr_t *dst, ip_addr_t *result) /** * @ingroup snmp_core * Starts SNMP Agent. - * Allocates UDP pcb and binds it to IP_ADDR_ANY port 161. + * Allocates UDP pcb and binds it to IP_ANY_TYPE port 161. */ void snmp_init(void) diff --git a/src/apps/sntp/sntp.c b/src/apps/sntp/sntp.c index 8d43eb0b..9f8a1dc8 100644 --- a/src/apps/sntp/sntp.c +++ b/src/apps/sntp/sntp.c @@ -688,7 +688,7 @@ sntp_getserver(u8_t idx) if (idx < SNTP_MAX_SERVERS) { return &sntp_servers[idx].addr; } - return IP_ADDR_ANY; + return IP4_ADDR_ANY; } #if SNTP_SERVER_DNS diff --git a/src/core/dns.c b/src/core/dns.c index b19f9b08..e643aa30 100644 --- a/src/core/dns.c +++ b/src/core/dns.c @@ -362,7 +362,7 @@ dns_setserver(u8_t numdns, const ip_addr_t *dnsserver) if (dnsserver != NULL) { dns_servers[numdns] = (*dnsserver); } else { - dns_servers[numdns] = *IP_ADDR_ANY; + dns_servers[numdns] = *IP4_ADDR_ANY; } } } @@ -381,7 +381,7 @@ dns_getserver(u8_t numdns) if (numdns < DNS_MAX_SERVERS) { return &dns_servers[numdns]; } else { - return IP_ADDR_ANY; + return IP4_ADDR_ANY; } } diff --git a/src/core/ipv4/autoip.c b/src/core/ipv4/autoip.c index 01fccf8a..ad494feb 100644 --- a/src/core/ipv4/autoip.c +++ b/src/core/ipv4/autoip.c @@ -264,7 +264,7 @@ autoip_start(struct netif *netif) /* Set IP-Address, Netmask and Gateway to 0 to make sure that * ARP Packets are formed correctly */ - netif_set_addr(netif, IP4_ADDR_ANY, IP4_ADDR_ANY, IP4_ADDR_ANY); + netif_set_addr(netif, IP4_ADDR_ANY4, IP4_ADDR_ANY4, IP4_ADDR_ANY4); LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("autoip_start(netif=%p) %c%c%"U16_F"\n", (void*)netif, netif->name[0], @@ -355,7 +355,7 @@ autoip_stop(struct netif *netif) if (autoip != NULL) { autoip->state = AUTOIP_STATE_OFF; if (ip4_addr_islinklocal(netif_ip4_addr(netif))) { - netif_set_addr(netif, IP4_ADDR_ANY, IP4_ADDR_ANY, IP4_ADDR_ANY); + netif_set_addr(netif, IP4_ADDR_ANY4, IP4_ADDR_ANY4, IP4_ADDR_ANY4); } } return ERR_OK; diff --git a/src/core/ipv4/dhcp.c b/src/core/ipv4/dhcp.c index 4ffd86b0..62a32c52 100644 --- a/src/core/ipv4/dhcp.c +++ b/src/core/ipv4/dhcp.c @@ -212,8 +212,8 @@ dhcp_inc_pcb_refcount(void) ip_set_option(dhcp_pcb, SOF_BROADCAST); /* set up local and remote port for the pcb -> listen on all interfaces on all src/dest IPs */ - udp_bind(dhcp_pcb, IP_ADDR_ANY, DHCP_CLIENT_PORT); - udp_connect(dhcp_pcb, IP_ADDR_ANY, DHCP_SERVER_PORT); + udp_bind(dhcp_pcb, IP4_ADDR_ANY, DHCP_CLIENT_PORT); + udp_connect(dhcp_pcb, IP4_ADDR_ANY, DHCP_SERVER_PORT); udp_recv(dhcp_pcb, dhcp_recv, NULL); } @@ -258,7 +258,7 @@ dhcp_handle_nak(struct netif *netif) to ensure the callback can use dhcp_supplied_address() */ dhcp_set_state(dhcp, DHCP_STATE_BACKING_OFF); /* remove IP address from interface (must no longer be used, as per RFC2131) */ - netif_set_addr(netif, IP4_ADDR_ANY, IP4_ADDR_ANY, IP4_ADDR_ANY); + netif_set_addr(netif, IP4_ADDR_ANY4, IP4_ADDR_ANY4, IP4_ADDR_ANY4); /* We can immediately restart discovery */ dhcp_discover(netif); } @@ -372,7 +372,7 @@ dhcp_select(struct netif *netif) pbuf_realloc(dhcp->p_out, sizeof(struct dhcp_msg) - DHCP_OPTIONS_LEN + dhcp->options_out_len); /* send broadcast to any DHCP server */ - udp_sendto_if_src(dhcp_pcb, dhcp->p_out, IP_ADDR_BROADCAST, DHCP_SERVER_PORT, netif, IP_ADDR_ANY); + udp_sendto_if_src(dhcp_pcb, dhcp->p_out, IP_ADDR_BROADCAST, DHCP_SERVER_PORT, netif, IP4_ADDR_ANY); dhcp_delete_msg(dhcp); LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_select: REQUESTING\n")); } else { @@ -920,7 +920,7 @@ dhcp_decline(struct netif *netif) pbuf_realloc(dhcp->p_out, sizeof(struct dhcp_msg) - DHCP_OPTIONS_LEN + dhcp->options_out_len); /* per section 4.4.4, broadcast DECLINE messages */ - udp_sendto_if_src(dhcp_pcb, dhcp->p_out, IP_ADDR_BROADCAST, DHCP_SERVER_PORT, netif, IP_ADDR_ANY); + udp_sendto_if_src(dhcp_pcb, dhcp->p_out, IP_ADDR_BROADCAST, DHCP_SERVER_PORT, netif, IP4_ADDR_ANY); dhcp_delete_msg(dhcp); LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_decline: BACKING OFF\n")); } else { @@ -971,7 +971,7 @@ dhcp_discover(struct netif *netif) pbuf_realloc(dhcp->p_out, sizeof(struct dhcp_msg) - DHCP_OPTIONS_LEN + dhcp->options_out_len); LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_discover: sendto(DISCOVER, IP_ADDR_BROADCAST, DHCP_SERVER_PORT)\n")); - udp_sendto_if_src(dhcp_pcb, dhcp->p_out, IP_ADDR_BROADCAST, DHCP_SERVER_PORT, netif, IP_ADDR_ANY); + udp_sendto_if_src(dhcp_pcb, dhcp->p_out, IP_ADDR_BROADCAST, DHCP_SERVER_PORT, netif, IP4_ADDR_ANY); LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_discover: deleting()ing\n")); dhcp_delete_msg(dhcp); LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_discover: SELECTING\n")); @@ -1314,7 +1314,7 @@ dhcp_release(struct netif *netif) LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_SERIOUS, ("dhcp_release: could not allocate DHCP request\n")); } /* remove IP address from interface (prevents routing from selecting this interface) */ - netif_set_addr(netif, IP4_ADDR_ANY, IP4_ADDR_ANY, IP4_ADDR_ANY); + netif_set_addr(netif, IP4_ADDR_ANY4, IP4_ADDR_ANY4, IP4_ADDR_ANY4); return result; } diff --git a/src/core/ipv4/igmp.c b/src/core/ipv4/igmp.c index f3db5914..ab20b883 100644 --- a/src/core/ipv4/igmp.c +++ b/src/core/ipv4/igmp.c @@ -711,7 +711,7 @@ igmp_delaying_member(struct igmp_group *group, u8_t maxresp) * @param p the packet to send (p->payload points to the data, e.g. next protocol header; if dest == LWIP_IP_HDRINCL, p already includes an IP header and p->payload points to that IP header) - * @param src the source IP address to send from (if src == IP_ADDR_ANY, the + * @param src the source IP address to send from (if src == IP4_ADDR_ANY, the * IP address of the netif used to send is used as source address) * @param dest the destination IP address to send the packet to * @param ttl the TTL value to be set in the IP header @@ -743,7 +743,7 @@ igmp_send(struct netif *netif, struct igmp_group *group, u8_t type) { struct pbuf* p = NULL; struct igmp_msg* igmp = NULL; - ip4_addr_t src = *IP4_ADDR_ANY; + ip4_addr_t src = *IP4_ADDR_ANY4; ip4_addr_t* dest = NULL; /* IP header + "router alert" option + IGMP header */ diff --git a/src/core/ipv4/ip4.c b/src/core/ipv4/ip4.c index 27747ea7..1f1b3ac0 100644 --- a/src/core/ipv4/ip4.c +++ b/src/core/ipv4/ip4.c @@ -724,7 +724,7 @@ ip4_input(struct pbuf *p, struct netif *inp) * @param p the packet to send (p->payload points to the data, e.g. next protocol header; if dest == LWIP_IP_HDRINCL, p already includes an IP header and p->payload points to that IP header) - * @param src the source IP address to send from (if src == IP_ADDR_ANY, the + * @param src the source IP address to send from (if src == IP4_ADDR_ANY, the * IP address of the netif used to send is used as source address) * @param dest the destination IP address to send the packet to * @param ttl the TTL value to be set in the IP header @@ -881,7 +881,7 @@ ip4_output_if_opt_src(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *d ++ip_id; if (src == NULL) { - ip4_addr_copy(iphdr->src, *IP4_ADDR_ANY); + ip4_addr_copy(iphdr->src, *IP4_ADDR_ANY4); } else { /* src cannot be NULL here */ ip4_addr_copy(iphdr->src, *src); @@ -955,7 +955,7 @@ ip4_output_if_opt_src(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *d * @param p the packet to send (p->payload points to the data, e.g. next protocol header; if dest == LWIP_IP_HDRINCL, p already includes an IP header and p->payload points to that IP header) - * @param src the source IP address to send from (if src == IP_ADDR_ANY, the + * @param src the source IP address to send from (if src == IP4_ADDR_ANY, the * IP address of the netif used to send is used as source address) * @param dest the destination IP address to send the packet to * @param ttl the TTL value to be set in the IP header @@ -990,7 +990,7 @@ ip4_output(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest, * @param p the packet to send (p->payload points to the data, e.g. next protocol header; if dest == LWIP_IP_HDRINCL, p already includes an IP header and p->payload points to that IP header) - * @param src the source IP address to send from (if src == IP_ADDR_ANY, the + * @param src the source IP address to send from (if src == IP4_ADDR_ANY, the * IP address of the netif used to send is used as source address) * @param dest the destination IP address to send the packet to * @param ttl the TTL value to be set in the IP header diff --git a/src/core/ipv4/ip4_addr.c b/src/core/ipv4/ip4_addr.c index 7fe35c98..d0a81072 100644 --- a/src/core/ipv4/ip4_addr.c +++ b/src/core/ipv4/ip4_addr.c @@ -43,7 +43,7 @@ #include "lwip/ip_addr.h" #include "lwip/netif.h" -/* used by IP_ADDR_ANY and IP_ADDR_BROADCAST in ip_addr.h */ +/* used by IP4_ADDR_ANY and IP_ADDR_BROADCAST in ip_addr.h */ const ip_addr_t ip_addr_any = IPADDR4_INIT(IPADDR_ANY); const ip_addr_t ip_addr_broadcast = IPADDR4_INIT(IPADDR_BROADCAST); diff --git a/src/core/netif.c b/src/core/netif.c index 2d7c8750..9adb50be 100644 --- a/src/core/netif.c +++ b/src/core/netif.c @@ -497,7 +497,7 @@ void netif_set_ipaddr(struct netif *netif, const ip4_addr_t *ipaddr) { ip_addr_t new_addr; - *ip_2_ip4(&new_addr) = (ipaddr ? *ipaddr : *IP4_ADDR_ANY); + *ip_2_ip4(&new_addr) = (ipaddr ? *ipaddr : *IP4_ADDR_ANY4); IP_SET_TYPE_VAL(new_addr, IPADDR_TYPE_V4); /* address is actually being changed? */ diff --git a/src/core/raw.c b/src/core/raw.c index 244ab40a..a9174542 100644 --- a/src/core/raw.c +++ b/src/core/raw.c @@ -196,7 +196,7 @@ raw_input(struct pbuf *p, struct netif *inp) * Bind a RAW PCB. * * @param pcb RAW PCB to be bound with a local address ipaddr. - * @param ipaddr local IP address to bind with. Use IP_ADDR_ANY to + * @param ipaddr local IP address to bind with. Use IP4_ADDR_ANY to * bind to all local interfaces. * * @return lwIP error code. diff --git a/src/core/tcp.c b/src/core/tcp.c index 9c31f4b8..a91c1f4e 100644 --- a/src/core/tcp.c +++ b/src/core/tcp.c @@ -529,7 +529,7 @@ tcp_abort(struct tcp_pcb *pcb) * * @param pcb the tcp_pcb to bind (no check is done whether this pcb is * already bound!) - * @param ipaddr the local ip address to bind to (use IP_ADDR_ANY to bind + * @param ipaddr the local ip address to bind to (use IP4_ADDR_ANY to bind * to any local address * @param port the local port to bind to * @return ERR_USE if the port is already in use @@ -546,7 +546,7 @@ tcp_bind(struct tcp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port) #if LWIP_IPV4 /* Don't propagate NULL pointer (IPv4 ANY) to subsequent functions */ if (ipaddr == NULL) { - ipaddr = IP_ADDR_ANY; + ipaddr = IP4_ADDR_ANY; } #endif /* LWIP_IPV4 */ diff --git a/src/core/udp.c b/src/core/udp.c index 34fbdd14..67b6c94b 100644 --- a/src/core/udp.c +++ b/src/core/udp.c @@ -883,7 +883,7 @@ udp_sendto_if_src_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *d * Bind an UDP PCB. * * @param pcb UDP PCB to be bound with a local address ipaddr and port. - * @param ipaddr local IP address to bind with. Use IP_ADDR_ANY to + * @param ipaddr local IP address to bind with. Use IP4_ADDR_ANY to * bind to all local interfaces. * @param port local UDP port to bind with. Use 0 to automatically bind * to a random port between UDP_LOCAL_PORT_RANGE_START and @@ -907,7 +907,7 @@ udp_bind(struct udp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port) #if LWIP_IPV4 /* Don't propagate NULL pointer (IPv4 ANY) to subsequent functions */ if (ipaddr == NULL) { - ipaddr = IP_ADDR_ANY; + ipaddr = IP4_ADDR_ANY; } #endif /* LWIP_IPV4 */ diff --git a/src/include/lwip/ip_addr.h b/src/include/lwip/ip_addr.h index 864f12f9..c1df7464 100644 --- a/src/include/lwip/ip_addr.h +++ b/src/include/lwip/ip_addr.h @@ -313,19 +313,25 @@ extern const ip_addr_t ip_addr_any; extern const ip_addr_t ip_addr_broadcast; /** - * @ingroup ipaddr - * IP_ADDR_ can be used as a fixed/const ip_addr_t - * for the IPv4 wildcard and the broadcast address + * @ingroup ip4addr + * Provided for compatibility. Use IP4_ADDR_ANY for better readability. */ -#define IP_ADDR_ANY (&ip_addr_any) -/** @ingroup ipaddr */ -#define IP_ADDR_BROADCAST (&ip_addr_broadcast) +#define IP_ADDR_ANY IP4_ADDR_ANY /** * @ingroup ip4addr - * IP4_ADDR_ can be used as a fixed/const ip4_addr_t + * Can be used as a fixed/const ip_addr_t + * for the IPv4 wildcard and the broadcast address + */ +#define IP4_ADDR_ANY (&ip_addr_any) +/** + * @ingroup ip4addr + * Can be used as a fixed/const ip4_addr_t * for the wildcard and the broadcast address */ -#define IP4_ADDR_ANY (ip_2_ip4(&ip_addr_any)) +#define IP4_ADDR_ANY4 (ip_2_ip4(&ip_addr_any)) + +/** @ingroup ip4addr */ +#define IP_ADDR_BROADCAST (&ip_addr_broadcast) /** @ingroup ip4addr */ #define IP4_ADDR_BROADCAST (ip_2_ip4(&ip_addr_broadcast)) diff --git a/src/netif/ppp/ppp.c b/src/netif/ppp/ppp.c index 2f6ae11f..4bd17003 100644 --- a/src/netif/ppp/ppp.c +++ b/src/netif/ppp/ppp.c @@ -695,7 +695,7 @@ ppp_pcb *ppp_new(struct netif *pppif, const struct link_callbacks *callbacks, vo MIB2_INIT_NETIF(pppif, snmp_ifType_ppp, 0); if (!netif_add(pcb->netif, #if LWIP_IPV4 - IP4_ADDR_ANY, IP4_ADDR_BROADCAST, IP4_ADDR_ANY, + IP4_ADDR_ANY4, IP4_ADDR_BROADCAST, IP4_ADDR_ANY4, #endif /* LWIP_IPV4 */ (void *)pcb, ppp_netif_init_cb, NULL)) { LWIP_MEMPOOL_FREE(PPP_PCB, pcb); @@ -1090,7 +1090,7 @@ int cifaddr(ppp_pcb *pcb, u32_t our_adr, u32_t his_adr) { LWIP_UNUSED_ARG(our_adr); LWIP_UNUSED_ARG(his_adr); - netif_set_addr(pcb->netif, IP4_ADDR_ANY, IP4_ADDR_BROADCAST, IP4_ADDR_ANY); + netif_set_addr(pcb->netif, IP4_ADDR_ANY4, IP4_ADDR_BROADCAST, IP4_ADDR_ANY4); return 1; } @@ -1145,12 +1145,12 @@ int cdns(ppp_pcb *pcb, u32_t ns1, u32_t ns2) { nsa = dns_getserver(0); ip_addr_set_ip4_u32(&nsb, ns1); if (ip_addr_cmp(nsa, &nsb)) { - dns_setserver(0, IP_ADDR_ANY); + dns_setserver(0, IP4_ADDR_ANY); } nsa = dns_getserver(1); ip_addr_set_ip4_u32(&nsb, ns2); if (ip_addr_cmp(nsa, &nsb)) { - dns_setserver(1, IP_ADDR_ANY); + dns_setserver(1, IP4_ADDR_ANY); } return 1; } diff --git a/src/netif/ppp/pppol2tp.c b/src/netif/ppp/pppol2tp.c index 7ecbe9eb..c215cff6 100644 --- a/src/netif/ppp/pppol2tp.c +++ b/src/netif/ppp/pppol2tp.c @@ -303,7 +303,7 @@ static err_t pppol2tp_connect(ppp_pcb *ppp, void *ctx) { udp_bind(l2tp->udp, IP6_ADDR_ANY, 0); } else #endif /* LWIP_IPV6 */ - udp_bind(l2tp->udp, IP_ADDR_ANY, 0); + udp_bind(l2tp->udp, IP4_ADDR_ANY, 0); #if PPPOL2TP_AUTH_SUPPORT /* Generate random vector */ From 78498981e29dcff7de7bad9b8c88021bea0d11c4 Mon Sep 17 00:00:00 2001 From: Erik Ekman Date: Wed, 28 Sep 2016 17:23:54 +0200 Subject: [PATCH 237/325] mdns: Update error message after argument type changed Method argument is no longer netif, but a mdns_host --- src/apps/mdns/mdns.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/apps/mdns/mdns.c b/src/apps/mdns/mdns.c index 662ccd31..0e07e79e 100644 --- a/src/apps/mdns/mdns.c +++ b/src/apps/mdns/mdns.c @@ -591,7 +591,7 @@ mdns_build_host_domain(struct mdns_domain *domain, struct mdns_host *mdns) { err_t res; memset(domain, 0, sizeof(struct mdns_domain)); - LWIP_ERROR("mdns_build_host_domain: Not an mdns netif", (mdns != NULL), return ERR_VAL); + LWIP_ERROR("mdns_build_host_domain: mdns != NULL", (mdns != NULL), return ERR_VAL); res = mdns_domain_add_label(domain, mdns->name, (u8_t)strlen(mdns->name)); LWIP_ERROR("mdns_build_host_domain: Failed to add label", (res == ERR_OK), return res); return mdns_add_dotlocal(domain); From 87e815030ce493b737f5a92a70309e82505d2dcb Mon Sep 17 00:00:00 2001 From: Erik Ekman Date: Wed, 28 Sep 2016 17:47:15 +0200 Subject: [PATCH 238/325] mdns: Use macro to get mdns_host from netif --- src/apps/mdns/mdns.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/apps/mdns/mdns.c b/src/apps/mdns/mdns.c index 0e07e79e..e542dc8b 100644 --- a/src/apps/mdns/mdns.c +++ b/src/apps/mdns/mdns.c @@ -107,6 +107,8 @@ static const ip_addr_t v6group = IPADDR6_INIT(PP_HTONL(0xFF020000UL), PP_HTONL(0 static u8_t mdns_netif_client_id; static struct udp_pcb *mdns_pcb; +#define NETIF_TO_HOST(netif) (struct mdns_host*)((netif)->client_data[mdns_netif_client_id]) + #define TOPDOMAIN_LOCAL "local" #define REVERSE_PTR_TOPDOMAIN "arpa" @@ -690,7 +692,7 @@ check_host(struct netif *netif, struct mdns_rr_info *rr, u8_t *reverse_v6_reply) #endif } - res = mdns_build_host_domain(&mydomain, (struct mdns_host*)netif->client_data[mdns_netif_client_id]); + res = mdns_build_host_domain(&mydomain, NETIF_TO_HOST(netif)); /* Handle requests for our hostname */ if (res == ERR_OK && mdns_domain_eq(&rr->domain, &mydomain)) { /* TODO return NSEC if unsupported protocol requested */ @@ -1155,9 +1157,9 @@ static err_t mdns_add_a_answer(struct mdns_outpacket *reply, u16_t cache_flush, struct netif *netif) { struct mdns_domain host; - mdns_build_host_domain(&host, (struct mdns_host*)netif->client_data[mdns_netif_client_id]); + mdns_build_host_domain(&host, NETIF_TO_HOST(netif)); LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: Responding with A record\n")); - return mdns_add_answer(reply, &host, DNS_RRTYPE_A, DNS_RRCLASS_IN, cache_flush, ((struct mdns_host*)netif->client_data[mdns_netif_client_id])->dns_ttl, (const u8_t *) netif_ip4_addr(netif), sizeof(ip4_addr_t), NULL); + return mdns_add_answer(reply, &host, DNS_RRTYPE_A, DNS_RRCLASS_IN, cache_flush, (NETIF_TO_HOST(netif))->dns_ttl, (const u8_t *) netif_ip4_addr(netif), sizeof(ip4_addr_t), NULL); } /** Write a 4.3.2.1.in-addr.arpa -> hostname.local PTR RR to outpacket */ @@ -1165,10 +1167,10 @@ static err_t mdns_add_hostv4_ptr_answer(struct mdns_outpacket *reply, u16_t cache_flush, struct netif *netif) { struct mdns_domain host, revhost; - mdns_build_host_domain(&host, (struct mdns_host*)netif->client_data[mdns_netif_client_id]); + mdns_build_host_domain(&host, NETIF_TO_HOST(netif)); mdns_build_reverse_v4_domain(&revhost, netif_ip4_addr(netif)); LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: Responding with v4 PTR record\n")); - return mdns_add_answer(reply, &revhost, DNS_RRTYPE_PTR, DNS_RRCLASS_IN, cache_flush, ((struct mdns_host*)netif->client_data[mdns_netif_client_id])->dns_ttl, NULL, 0, &host); + return mdns_add_answer(reply, &revhost, DNS_RRTYPE_PTR, DNS_RRCLASS_IN, cache_flush, (NETIF_TO_HOST(netif))->dns_ttl, NULL, 0, &host); } #endif @@ -1178,9 +1180,9 @@ static err_t mdns_add_aaaa_answer(struct mdns_outpacket *reply, u16_t cache_flush, struct netif *netif, int addrindex) { struct mdns_domain host; - mdns_build_host_domain(&host, (struct mdns_host*)netif->client_data[mdns_netif_client_id]); + mdns_build_host_domain(&host, NETIF_TO_HOST(netif)); LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: Responding with AAAA record\n")); - return mdns_add_answer(reply, &host, DNS_RRTYPE_AAAA, DNS_RRCLASS_IN, cache_flush, ((struct mdns_host*)netif->client_data[mdns_netif_client_id])->dns_ttl, (const u8_t *) netif_ip6_addr(netif, addrindex), sizeof(ip6_addr_t), NULL); + return mdns_add_answer(reply, &host, DNS_RRTYPE_AAAA, DNS_RRCLASS_IN, cache_flush, (NETIF_TO_HOST(netif))->dns_ttl, (const u8_t *) netif_ip6_addr(netif, addrindex), sizeof(ip6_addr_t), NULL); } /** Write a x.y.z.ip6.arpa -> hostname.local PTR RR to outpacket */ @@ -1188,10 +1190,10 @@ static err_t mdns_add_hostv6_ptr_answer(struct mdns_outpacket *reply, u16_t cache_flush, struct netif *netif, int addrindex) { struct mdns_domain host, revhost; - mdns_build_host_domain(&host, (struct mdns_host*)netif->client_data[mdns_netif_client_id]); + mdns_build_host_domain(&host, NETIF_TO_HOST(netif)); mdns_build_reverse_v6_domain(&revhost, netif_ip6_addr(netif, addrindex)); LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: Responding with v6 PTR record\n")); - return mdns_add_answer(reply, &revhost, DNS_RRTYPE_PTR, DNS_RRCLASS_IN, cache_flush, ((struct mdns_host*)netif->client_data[mdns_netif_client_id])->dns_ttl, NULL, 0, &host); + return mdns_add_answer(reply, &revhost, DNS_RRTYPE_PTR, DNS_RRCLASS_IN, cache_flush, (NETIF_TO_HOST(netif)->dns_ttl, NULL, 0, &host); } #endif @@ -1295,7 +1297,7 @@ mdns_send_outpacket(struct mdns_outpacket *outpkt) struct mdns_service *service; err_t res; int i; - struct mdns_host* mdns = (struct mdns_host*)outpkt->netif->client_data[mdns_netif_client_id]; + struct mdns_host* mdns = NETIF_TO_HOST(outpkt->netif); /* Write answers to host questions */ #if LWIP_IPV4 From f3cec74bd630572d79927fa43e35ad5f65980b32 Mon Sep 17 00:00:00 2001 From: Erik Ekman Date: Wed, 28 Sep 2016 18:15:11 +0200 Subject: [PATCH 239/325] mdns: Use macro to get mdns_host from netif v2 Add missing ) --- src/apps/mdns/mdns.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/apps/mdns/mdns.c b/src/apps/mdns/mdns.c index e542dc8b..751836d4 100644 --- a/src/apps/mdns/mdns.c +++ b/src/apps/mdns/mdns.c @@ -1193,7 +1193,7 @@ mdns_add_hostv6_ptr_answer(struct mdns_outpacket *reply, u16_t cache_flush, stru mdns_build_host_domain(&host, NETIF_TO_HOST(netif)); mdns_build_reverse_v6_domain(&revhost, netif_ip6_addr(netif, addrindex)); LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: Responding with v6 PTR record\n")); - return mdns_add_answer(reply, &revhost, DNS_RRTYPE_PTR, DNS_RRCLASS_IN, cache_flush, (NETIF_TO_HOST(netif)->dns_ttl, NULL, 0, &host); + return mdns_add_answer(reply, &revhost, DNS_RRTYPE_PTR, DNS_RRCLASS_IN, cache_flush, (NETIF_TO_HOST(netif))->dns_ttl, NULL, 0, &host); } #endif From f8d19e28deb49094abee4c1731a4293807745fab Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Tue, 27 Sep 2016 21:28:34 +0200 Subject: [PATCH 240/325] Minor: Documentation updates --- src/apps/snmp/snmp_traps.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/apps/snmp/snmp_traps.c b/src/apps/snmp/snmp_traps.c index 61ceee65..e698e872 100644 --- a/src/apps/snmp/snmp_traps.c +++ b/src/apps/snmp/snmp_traps.c @@ -147,7 +147,8 @@ snmp_get_auth_traps_enabled(void) /** - * Sends an generic or enterprise specific trap message. + * @ingroup snmp_traps + * Sends a generic or enterprise specific trap message. * * @param eoid points to enterprise object identifier * @param generic_trap is the trap code @@ -225,7 +226,7 @@ snmp_send_trap(const struct snmp_obj_id* eoid, s32_t generic_trap, s32_t specifi /** * @ingroup snmp_traps - * Send generic SNMP trap + * Send generic SNMP trap */ err_t snmp_send_trap_generic(s32_t generic_trap) @@ -235,7 +236,7 @@ snmp_send_trap_generic(s32_t generic_trap) } /** - *@ingroup snmp_traps + * @ingroup snmp_traps * Send specific SNMP trap with variable bindings */ err_t From 1f68b3248527608ac7520429b99aa412ca4d686d Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Wed, 28 Sep 2016 21:52:11 +0200 Subject: [PATCH 241/325] Cleanup handling of non-standard functions in lwIP - itoa - strnicmp, stricmp/strcasecmp - strnstr Related to patch #9115: httpd.c: strcasecmp for GCC and stricmp for Windows --- src/apps/httpd/httpd.c | 102 +++--------------------- src/apps/mdns/mdns.c | 38 +-------- src/apps/netbiosns/netbiosns.c | 3 +- src/core/def.c | 106 +++++++++++++++++++++++++ src/core/dns.c | 45 ++--------- src/include/lwip/apps/httpd_opts.h | 22 ----- src/include/lwip/apps/netbiosns_opts.h | 10 --- src/include/lwip/def.h | 19 ++++- 8 files changed, 146 insertions(+), 199 deletions(-) diff --git a/src/apps/httpd/httpd.c b/src/apps/httpd/httpd.c index f8e2e282..42a1c99b 100644 --- a/src/apps/httpd/httpd.c +++ b/src/apps/httpd/httpd.c @@ -337,82 +337,6 @@ char *http_cgi_param_vals[LWIP_HTTPD_MAX_CGI_PARAMETERS]; /* Values for each ext static struct http_state *http_connections; #endif /* LWIP_HTTPD_KILL_OLD_ON_CONNECTIONS_EXCEEDED */ -#if LWIP_HTTPD_STRNSTR_PRIVATE -/** Like strstr but does not need 'buffer' to be NULL-terminated */ -static char* -strnstr(const char* buffer, const char* token, size_t n) -{ - const char* p; - int tokenlen = (int)strlen(token); - if (tokenlen == 0) { - return (char *)(size_t)buffer; - } - for (p = buffer; *p && (p + tokenlen <= buffer + n); p++) { - if ((*p == *token) && (strncmp(p, token, tokenlen) == 0)) { - return (char *)(size_t)p; - } - } - return NULL; -} -#endif /* LWIP_HTTPD_STRNSTR_PRIVATE */ - -#if LWIP_HTTPD_STRICMP_PRIVATE -static int -stricmp(const char* str1, const char* str2) -{ - char c1, c2; - - do { - c1 = *str1++; - c2 = *str2++; - if (c1 != c2) { - char c1_upc = c1 | 0x20; - if ((c1_upc >= 'a') && (c1_upc <= 'z')) { - /* characters are not equal an one is in the alphabet range: - downcase both chars and check again */ - char c2_upc = c2 | 0x20; - if (c1_upc != c2_upc) { - /* still not equal */ - /* don't care for < or > */ - return 1; - } - } else { - /* characters are not equal but none is in the alphabet range */ - return 1; - } - } - } while (c1 != 0); - return 0; -} -#endif /* LWIP_HTTPD_STRICMP_PRIVATE */ - -#if LWIP_HTTPD_ITOA_PRIVATE && LWIP_HTTPD_DYNAMIC_HEADERS -static void -httpd_itoa(int value, char* result) -{ - const int base = 10; - char* ptr = result, *ptr1 = result, tmp_char; - int tmp_value; - - do { - tmp_value = value; - value /= base; - *ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz"[35 + (tmp_value - value * base)]; - } while(value); - - /* Apply negative sign */ - if (tmp_value < 0) { - *ptr++ = '-'; - } - *ptr-- = '\0'; - while(ptr1 < ptr) { - tmp_char = *ptr; - *ptr--= *ptr1; - *ptr1++ = tmp_char; - } -} -#endif - #if LWIP_HTTPD_KILL_OLD_ON_CONNECTIONS_EXCEEDED static void http_kill_oldest_connection(u8_t ssi_required) @@ -964,7 +888,7 @@ get_http_headers(struct http_state *hs, const char *uri) /* Now determine the content type and add the relevant header for that. */ for (content_type = 0; content_type < NUM_HTTP_HEADERS; content_type++) { /* Have we found a matching extension? */ - if(!stricmp(g_psHTTPHeaders[content_type].extension, ext)) { + if(!lwip_stricmp(g_psHTTPHeaders[content_type].extension, ext)) { break; } } @@ -1012,7 +936,7 @@ get_http_headers(struct http_state *hs, const char *uri) } if (add_content_len) { size_t len; - LWIP_HTTPD_ITOA(hs->hdr_content_len, (size_t)LWIP_HTTPD_MAX_CONTENT_LEN_SIZE, + lwip_itoa(hs->hdr_content_len, (size_t)LWIP_HTTPD_MAX_CONTENT_LEN_SIZE, hs->handle->len); len = strlen(hs->hdr_content_len); if (len <= LWIP_HTTPD_MAX_CONTENT_LEN_SIZE - LWIP_HTTPD_MAX_CONTENT_LEN_OFFSET) { @@ -1802,16 +1726,16 @@ http_post_request(struct pbuf *inp, struct http_state *hs, { err_t err; /* search for end-of-header (first double-CRLF) */ - char* crlfcrlf = strnstr(uri_end + 1, CRLF CRLF, data_len - (uri_end + 1 - data)); + char* crlfcrlf = lwip_strnstr(uri_end + 1, CRLF CRLF, data_len - (uri_end + 1 - data)); if (crlfcrlf != NULL) { /* search for "Content-Length: " */ #define HTTP_HDR_CONTENT_LEN "Content-Length: " #define HTTP_HDR_CONTENT_LEN_LEN 16 #define HTTP_HDR_CONTENT_LEN_DIGIT_MAX_LEN 10 - char *scontent_len = strnstr(uri_end + 1, HTTP_HDR_CONTENT_LEN, crlfcrlf - (uri_end + 1)); + char *scontent_len = lwip_strnstr(uri_end + 1, HTTP_HDR_CONTENT_LEN, crlfcrlf - (uri_end + 1)); if (scontent_len != NULL) { - char *scontent_len_end = strnstr(scontent_len + HTTP_HDR_CONTENT_LEN_LEN, CRLF, HTTP_HDR_CONTENT_LEN_DIGIT_MAX_LEN); + char *scontent_len_end = lwip_strnstr(scontent_len + HTTP_HDR_CONTENT_LEN_LEN, CRLF, HTTP_HDR_CONTENT_LEN_DIGIT_MAX_LEN); if (scontent_len_end != NULL) { int content_len; char *content_len_num = scontent_len + HTTP_HDR_CONTENT_LEN_LEN; @@ -2020,7 +1944,7 @@ http_parse_request(struct pbuf *inp, struct http_state *hs, struct tcp_pcb *pcb) /* received enough data for minimal request? */ if (data_len >= MIN_REQ_LEN) { /* wait for CRLF before parsing anything */ - crlf = strnstr(data, CRLF, data_len); + crlf = lwip_strnstr(data, CRLF, data_len); if (crlf != NULL) { #if LWIP_HTTPD_SUPPORT_POST int is_post = 0; @@ -2052,11 +1976,11 @@ http_parse_request(struct pbuf *inp, struct http_state *hs, struct tcp_pcb *pcb) } /* if we come here, method is OK, parse URI */ left_len = (u16_t)(data_len - ((sp1 +1) - data)); - sp2 = strnstr(sp1 + 1, " ", left_len); + sp2 = lwip_strnstr(sp1 + 1, " ", left_len); #if LWIP_HTTPD_SUPPORT_V09 if (sp2 == NULL) { /* HTTP 0.9: respond with correct protocol version */ - sp2 = strnstr(sp1 + 1, CRLF, left_len); + sp2 = lwip_strnstr(sp1 + 1, CRLF, left_len); is_09 = 1; #if LWIP_HTTPD_SUPPORT_POST if (is_post) { @@ -2069,13 +1993,13 @@ http_parse_request(struct pbuf *inp, struct http_state *hs, struct tcp_pcb *pcb) uri_len = (u16_t)(sp2 - (sp1 + 1)); if ((sp2 != 0) && (sp2 > sp1)) { /* wait for CRLFCRLF (indicating end of HTTP headers) before parsing anything */ - if (strnstr(data, CRLF CRLF, data_len) != NULL) { + if (lwip_strnstr(data, CRLF CRLF, data_len) != NULL) { char *uri = sp1 + 1; #if LWIP_HTTPD_SUPPORT_11_KEEPALIVE /* This is HTTP/1.0 compatible: for strict 1.1, a connection would always be persistent unless "close" was specified. */ - if (!is_09 && (strnstr(data, HTTP11_CONNECTIONKEEPALIVE, data_len) || - strnstr(data, HTTP11_CONNECTIONKEEPALIVE2, data_len))) { + if (!is_09 && (lwip_strnstr(data, HTTP11_CONNECTIONKEEPALIVE, data_len) || + lwip_strnstr(data, HTTP11_CONNECTIONKEEPALIVE2, data_len))) { hs->keepalive = 1; } else { hs->keepalive = 0; @@ -2259,7 +2183,7 @@ http_find_file(struct http_state *hs, const char *uri, int is_09) } tag_check = 0; for (loop = 0; loop < NUM_SHTML_EXTENSIONS; loop++) { - if (!stricmp(ext, g_pcSSIExtensions[loop])) { + if (!lwip_stricmp(ext, g_pcSSIExtensions[loop])) { tag_check = 1; break; } @@ -2334,7 +2258,7 @@ http_init_file(struct http_state *hs, struct fs_file *file, int is_09, const cha if (is_09 && ((hs->handle->flags & FS_FILE_FLAGS_HEADER_INCLUDED) != 0)) { /* HTTP/0.9 responses are sent without HTTP header, search for the end of the header. */ - char *file_start = strnstr(hs->file, CRLF CRLF, hs->left); + char *file_start = lwip_strnstr(hs->file, CRLF CRLF, hs->left); if (file_start != NULL) { size_t diff = file_start + 4 - hs->file; hs->file += diff; diff --git a/src/apps/mdns/mdns.c b/src/apps/mdns/mdns.c index 751836d4..110affb4 100644 --- a/src/apps/mdns/mdns.c +++ b/src/apps/mdns/mdns.c @@ -265,42 +265,6 @@ struct mdns_answer { u16_t rd_offset; }; -#ifndef LWIP_MDNS_STRNCASECMP -#define LWIP_MDNS_STRNCASECMP(str1, str2, len) mdns_strncasecmp(str1, str2, len) -/** - * A small but sufficient implementation for case insensitive strncmp. - * This can be defined to e.g. strnicmp for windows or strncasecmp for linux. - */ -static int -mdns_strncasecmp(const char* str1, const char* str2, size_t len) -{ - char c1, c2; - - do { - c1 = *str1++; - c2 = *str2++; - if (c1 != c2) { - char c1_upc = c1 | 0x20; - if ((c1_upc >= 'a') && (c1_upc <= 'z')) { - /* characters are not equal an one is in the alphabet range: - downcase both chars and check again */ - char c2_upc = c2 | 0x20; - if (c1_upc != c2_upc) { - /* still not equal */ - /* don't care for < or > */ - return 1; - } - } else { - /* characters are not equal but none is in the alphabet range */ - return 1; - } - } - } while (len-- && c1 != 0); - return 0; -} -#endif /* LWIP_MDNS_STRNCASECMP */ - - /** * Add a label part to a domain * @param domain The domain to add a label to @@ -460,7 +424,7 @@ mdns_domain_eq(struct mdns_domain *a, struct mdns_domain *b) len = *ptra; ptra++; ptrb++; - res = LWIP_MDNS_STRNCASECMP((char *) ptra, (char *) ptrb, len); + res = lwip_strnicmp((char *) ptra, (char *) ptrb, len); if (res != 0) { return 0; } diff --git a/src/apps/netbiosns/netbiosns.c b/src/apps/netbiosns/netbiosns.c index 1b1f952e..7e6ac08e 100644 --- a/src/apps/netbiosns/netbiosns.c +++ b/src/apps/netbiosns/netbiosns.c @@ -46,6 +46,7 @@ #if LWIP_IPV4 && LWIP_UDP /* don't build if not configured for use in lwipopts.h */ +#include "lwip/def.h" #include "lwip/udp.h" #include "lwip/netif.h" @@ -270,7 +271,7 @@ netbiosns_recv(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t /* decode the NetBIOS name */ netbiosns_name_decode((char*)(netbios_name_hdr->encname), netbios_name, sizeof(netbios_name)); /* if the packet is for us */ - if (NETBIOS_STRCMP(netbios_name, NETBIOS_LOCAL_NAME) == 0) { + if (lwip_strnicmp(netbios_name, NETBIOS_LOCAL_NAME, sizeof(NETBIOS_LOCAL_NAME)) == 0) { struct pbuf *q; struct netbios_resp *resp; diff --git a/src/core/def.c b/src/core/def.c index 7d3c93fb..7d91a3b1 100644 --- a/src/core/def.c +++ b/src/core/def.c @@ -102,4 +102,110 @@ lwip_ntohl(u32_t n) return lwip_htonl(n); } +#ifndef lwip_strnstr +/** Like strstr but does not need 'buffer' to be NULL-terminated */ +char* +lwip_strnstr(const char* buffer, const char* token, size_t n) +{ + const char* p; + int tokenlen = (int)strlen(token); + if (tokenlen == 0) { + return (char *)(size_t)buffer; + } + for (p = buffer; *p && (p + tokenlen <= buffer + n); p++) { + if ((*p == *token) && (strncmp(p, token, tokenlen) == 0)) { + return (char *)(size_t)p; + } + } + return NULL; +} +#endif + +#ifndef lwip_stricmp +int +lwip_stricmp(const char* str1, const char* str2) +{ + char c1, c2; + + do { + c1 = *str1++; + c2 = *str2++; + if (c1 != c2) { + char c1_upc = c1 | 0x20; + if ((c1_upc >= 'a') && (c1_upc <= 'z')) { + /* characters are not equal an one is in the alphabet range: + downcase both chars and check again */ + char c2_upc = c2 | 0x20; + if (c1_upc != c2_upc) { + /* still not equal */ + /* don't care for < or > */ + return 1; + } + } else { + /* characters are not equal but none is in the alphabet range */ + return 1; + } + } + } while (c1 != 0); + return 0; +} +#endif + +#ifndef lwip_strnicmp +int +lwip_strnicmp(const char* str1, const char* str2, size_t len) +{ + char c1, c2; + + do { + c1 = *str1++; + c2 = *str2++; + if (c1 != c2) { + char c1_upc = c1 | 0x20; + if ((c1_upc >= 'a') && (c1_upc <= 'z')) { + /* characters are not equal an one is in the alphabet range: + downcase both chars and check again */ + char c2_upc = c2 | 0x20; + if (c1_upc != c2_upc) { + /* still not equal */ + /* don't care for < or > */ + return 1; + } + } else { + /* characters are not equal but none is in the alphabet range */ + return 1; + } + } + } while (len-- && c1 != 0); + return 0; +} +#endif + +#ifndef lwip_itoa +void +lwip_itoa(int value, char* result) +{ + const int base = 10; + char* ptr = result, *ptr1 = result, tmp_char; + int tmp_value; + + do { + tmp_value = value; + value /= base; + *ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz"[35 + (tmp_value - value * base)]; + } while(value); + + /* Apply negative sign */ + if (tmp_value < 0) { + *ptr++ = '-'; + } + *ptr-- = '\0'; + while(ptr1 < ptr) { + tmp_char = *ptr; + *ptr--= *ptr1; + *ptr1++ = tmp_char; + } +} +#endif + #endif /* (LWIP_PLATFORM_BYTESWAP == 0) && (BYTE_ORDER == LITTLE_ENDIAN) */ diff --git a/src/core/dns.c b/src/core/dns.c index e643aa30..22368f04 100644 --- a/src/core/dns.c +++ b/src/core/dns.c @@ -80,6 +80,7 @@ #if LWIP_DNS /* don't build if not configured for use in lwipopts.h */ +#include "lwip/def.h" #include "lwip/udp.h" #include "lwip/mem.h" #include "lwip/memp.h" @@ -271,40 +272,6 @@ static struct dns_table_entry dns_table[DNS_TABLE_SIZE]; static struct dns_req_entry dns_requests[DNS_MAX_REQUESTS]; static ip_addr_t dns_servers[DNS_MAX_SERVERS]; -#ifndef LWIP_DNS_STRICMP -#define LWIP_DNS_STRICMP(str1, str2) dns_stricmp(str1, str2) -/** - * A small but sufficient implementation for case insensitive strcmp. - * This can be defined to e.g. stricmp for windows or strcasecmp for linux. */ -static int -dns_stricmp(const char* str1, const char* str2) -{ - char c1, c2; - - do { - c1 = *str1++; - c2 = *str2++; - if (c1 != c2) { - char c1_upc = c1 | 0x20; - if ((c1_upc >= 'a') && (c1_upc <= 'z')) { - /* characters are not equal an one is in the alphabet range: - downcase both chars and check again */ - char c2_upc = c2 | 0x20; - if (c1_upc != c2_upc) { - /* still not equal */ - /* don't care for < or > */ - return 1; - } - } else { - /* characters are not equal but none is in the alphabet range */ - return 1; - } - } - } while (c1 != 0); - return 0; -} -#endif /* LWIP_DNS_STRICMP */ - /** * Initialize the resolver: set up the UDP pcb and configure the default server * (if DNS_SERVER_ADDRESS is set). @@ -441,7 +408,7 @@ dns_lookup_local(const char *hostname, ip_addr_t *addr LWIP_DNS_ADDRTYPE_ARG(u8_ #if DNS_LOCAL_HOSTLIST_IS_DYNAMIC struct local_hostlist_entry *entry = local_hostlist_dynamic; while (entry != NULL) { - if ((LWIP_DNS_STRICMP(entry->name, hostname) == 0) && + if ((lwip_stricmp(entry->name, hostname) == 0) && LWIP_DNS_ADDRTYPE_MATCH_IP(dns_addrtype, entry->addr)) { if (addr) { ip_addr_copy(*addr, entry->addr); @@ -453,7 +420,7 @@ dns_lookup_local(const char *hostname, ip_addr_t *addr LWIP_DNS_ADDRTYPE_ARG(u8_ #else /* DNS_LOCAL_HOSTLIST_IS_DYNAMIC */ size_t i; for (i = 0; i < LWIP_ARRAYSIZE(local_hostlist_static); i++) { - if ((LWIP_DNS_STRICMP(local_hostlist_static[i].name, hostname) == 0) && + if ((lwip_stricmp(local_hostlist_static[i].name, hostname) == 0) && LWIP_DNS_ADDRTYPE_MATCH_IP(dns_addrtype, local_hostlist_static[i].addr)) { if (addr) { ip_addr_copy(*addr, local_hostlist_static[i].addr); @@ -483,7 +450,7 @@ dns_local_removehost(const char *hostname, const ip_addr_t *addr) struct local_hostlist_entry *entry = local_hostlist_dynamic; struct local_hostlist_entry *last_entry = NULL; while (entry != NULL) { - if (((hostname == NULL) || !LWIP_DNS_STRICMP(entry->name, hostname)) && + if (((hostname == NULL) || !lwip_stricmp(entry->name, hostname)) && ((addr == NULL) || ip_addr_cmp(&entry->addr, addr))) { struct local_hostlist_entry *free_entry; if (last_entry != NULL) { @@ -572,7 +539,7 @@ dns_lookup(const char *name, ip_addr_t *addr LWIP_DNS_ADDRTYPE_ARG(u8_t dns_addr /* Walk through name list, return entry if found. If not, return NULL. */ for (i = 0; i < DNS_TABLE_SIZE; ++i) { if ((dns_table[i].state == DNS_STATE_DONE) && - (LWIP_DNS_STRICMP(name, dns_table[i].name) == 0) && + (lwip_strnicmp(name, dns_table[i].name, sizeof(dns_table[i].name)) == 0) && LWIP_DNS_ADDRTYPE_MATCH_IP(dns_addrtype, dns_table[i].ipaddr)) { LWIP_DEBUGF(DNS_DEBUG, ("dns_lookup: \"%s\": found = ", name)); ip_addr_debug_print(DNS_DEBUG, &(dns_table[i].ipaddr)); @@ -1243,7 +1210,7 @@ dns_enqueue(const char *name, size_t hostnamelen, dns_found_callback found, /* check for duplicate entries */ for (i = 0; i < DNS_TABLE_SIZE; i++) { if ((dns_table[i].state == DNS_STATE_ASKING) && - (LWIP_DNS_STRICMP(name, dns_table[i].name) == 0)) { + (lwip_strnicmp(name, dns_table[i].name, sizeof(dns_table[i].name)) == 0)) { #if LWIP_IPV4 && LWIP_IPV6 if (dns_table[i].reqaddrtype != dns_addrtype) { /* requested address types don't match diff --git a/src/include/lwip/apps/httpd_opts.h b/src/include/lwip/apps/httpd_opts.h index 5fa84024..340db15f 100644 --- a/src/include/lwip/apps/httpd_opts.h +++ b/src/include/lwip/apps/httpd_opts.h @@ -161,28 +161,6 @@ #define HTTPD_DEBUG_TIMING LWIP_DBG_OFF #endif -/** Set this to 1 on platforms where strnstr is not available */ -#if !defined LWIP_HTTPD_STRNSTR_PRIVATE || defined __DOXYGEN__ -#define LWIP_HTTPD_STRNSTR_PRIVATE 1 -#endif - -/** Set this to 1 on platforms where stricmp is not available */ -#if !defined LWIP_HTTPD_STRICMP_PRIVATE || defined __DOXYGEN__ -#define LWIP_HTTPD_STRICMP_PRIVATE 0 -#endif - -/** Define this to a smaller function if you have itoa() at hand... */ -#if !defined LWIP_HTTPD_ITOA || defined __DOXYGEN__ -#if !defined LWIP_HTTPD_ITOA_PRIVATE || defined __DOXYGEN__ -#define LWIP_HTTPD_ITOA_PRIVATE 1 -#endif -#if LWIP_HTTPD_ITOA_PRIVATE -#define LWIP_HTTPD_ITOA(buffer, bufsize, number) httpd_itoa(number, buffer) -#else -#define LWIP_HTTPD_ITOA(buffer, bufsize, number) snprintf(buffer, bufsize, "%d", number) -#endif -#endif - /** Set this to one to show error pages when parsing a request fails instead of simply closing the connection. */ #if !defined LWIP_HTTPD_SUPPORT_EXTSTATUS || defined __DOXYGEN__ diff --git a/src/include/lwip/apps/netbiosns_opts.h b/src/include/lwip/apps/netbiosns_opts.h index 870b9fdf..0909ef7b 100644 --- a/src/include/lwip/apps/netbiosns_opts.h +++ b/src/include/lwip/apps/netbiosns_opts.h @@ -40,16 +40,6 @@ * @{ */ -/** Since there's no standard function for case-insensitive string comparision, - * we need another define here: - * define this to stricmp() for windows or strcasecmp() for linux. - * If not defined, comparision is case sensitive and the provided hostname must be - * uppercase. - */ -#if !defined NETBIOS_STRCMP || defined __DOXYGEN__ -#define NETBIOS_STRCMP(str1, str2) strcmp(str1, str2) -#endif - /** NetBIOS name of lwip device * This must be uppercase until NETBIOS_STRCMP() is defined to a string * comparision function that is case insensitive. diff --git a/src/include/lwip/def.h b/src/include/lwip/def.h index 39d720c0..d4c13a9e 100644 --- a/src/include/lwip/def.h +++ b/src/include/lwip/def.h @@ -133,9 +133,26 @@ u32_t lwip_ntohl(u32_t x); #endif /* BYTE_ORDER == BIG_ENDIAN */ +/* Functions that are not available as standard implementations. + * In lwipopts.h, you can #define these to implementations available on + * your platform to save some code bytes if you use these functions + * in your application, too. + */ +#ifndef lwip_itoa +void lwip_itoa(int value, char* result); +#endif +#ifndef lwip_strnicmp +int lwip_strnicmp(const char* str1, const char* str2, size_t len); +#endif +#ifndef lwip_stricmp +int lwip_stricmp(const char* str1, const char* str2); +#endif +#ifndef lwip_strnstr +char* lwip_strnstr(const char* buffer, const char* token, size_t n); +#endif + #ifdef __cplusplus } #endif #endif /* LWIP_HDR_DEF_H */ - From 837b7b3f98a592d0b5107ad115a450e28f421ecc Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Wed, 28 Sep 2016 21:55:29 +0200 Subject: [PATCH 242/325] Fix comment in my last commit --- src/include/lwip/def.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/include/lwip/def.h b/src/include/lwip/def.h index d4c13a9e..7b431b6f 100644 --- a/src/include/lwip/def.h +++ b/src/include/lwip/def.h @@ -134,7 +134,7 @@ u32_t lwip_ntohl(u32_t x); #endif /* BYTE_ORDER == BIG_ENDIAN */ /* Functions that are not available as standard implementations. - * In lwipopts.h, you can #define these to implementations available on + * In cc.h, you can #define these to implementations available on * your platform to save some code bytes if you use these functions * in your application, too. */ From 4144d546420212d0fbfd8d6179f71724d97104fc Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Wed, 28 Sep 2016 22:05:18 +0200 Subject: [PATCH 243/325] Fix implementation of lwip_itoa to take more parameters --- src/core/def.c | 11 ++++++----- src/include/lwip/def.h | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/core/def.c b/src/core/def.c index 7d91a3b1..05785486 100644 --- a/src/core/def.c +++ b/src/core/def.c @@ -183,17 +183,18 @@ lwip_strnicmp(const char* str1, const char* str2, size_t len) #ifndef lwip_itoa void -lwip_itoa(int value, char* result) +lwip_itoa(char* result, size_t bufsize, int number) { const int base = 10; char* ptr = result, *ptr1 = result, tmp_char; int tmp_value; + LWIP_UNUSED_ARG(bufsize); do { - tmp_value = value; - value /= base; - *ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz"[35 + (tmp_value - value * base)]; - } while(value); + tmp_value = number; + number /= base; + *ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz"[35 + (tmp_value - number * base)]; + } while(number); /* Apply negative sign */ if (tmp_value < 0) { diff --git a/src/include/lwip/def.h b/src/include/lwip/def.h index 7b431b6f..95d2d70c 100644 --- a/src/include/lwip/def.h +++ b/src/include/lwip/def.h @@ -139,7 +139,7 @@ u32_t lwip_ntohl(u32_t x); * in your application, too. */ #ifndef lwip_itoa -void lwip_itoa(int value, char* result); +void lwip_itoa(char* result, size_t bufsize, int number); #endif #ifndef lwip_strnicmp int lwip_strnicmp(const char* str1, const char* str2, size_t len); From 461b3531c787ddadf79d3bedecf6cec8c54104e9 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Wed, 28 Sep 2016 22:05:52 +0200 Subject: [PATCH 244/325] httpd.c: add missing default in case statement --- src/apps/httpd/httpd.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/apps/httpd/httpd.c b/src/apps/httpd/httpd.c index 42a1c99b..6039baef 100644 --- a/src/apps/httpd/httpd.c +++ b/src/apps/httpd/httpd.c @@ -1477,6 +1477,8 @@ http_send_data_ssi(struct tcp_pcb *pcb, struct http_state *hs) } } break; + default: + break; } } } From 0e7f48d81c382e2eda14bb50e2a8f5cac42cdb15 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Wed, 28 Sep 2016 22:26:55 +0200 Subject: [PATCH 245/325] Fix compile of new functions in def.c - I accidentally put them in a #ifdef section Thanks to Daniel Elstner --- src/core/def.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/def.c b/src/core/def.c index 05785486..1f8a4b96 100644 --- a/src/core/def.c +++ b/src/core/def.c @@ -102,6 +102,8 @@ lwip_ntohl(u32_t n) return lwip_htonl(n); } +#endif /* (LWIP_PLATFORM_BYTESWAP == 0) && (BYTE_ORDER == LITTLE_ENDIAN) */ + #ifndef lwip_strnstr /** Like strstr but does not need 'buffer' to be NULL-terminated */ char* @@ -208,5 +210,3 @@ lwip_itoa(char* result, size_t bufsize, int number) } } #endif - -#endif /* (LWIP_PLATFORM_BYTESWAP == 0) && (BYTE_ORDER == LITTLE_ENDIAN) */ From 17e6c9dd02e775210e9cc6972c9efe99d92c039a Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Thu, 29 Sep 2016 08:08:26 +0200 Subject: [PATCH 246/325] Add #include in def.c since lwip_strnstr uses strlen and strcmp --- src/core/def.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/core/def.c b/src/core/def.c index 1f8a4b96..c0cfba3b 100644 --- a/src/core/def.c +++ b/src/core/def.c @@ -49,6 +49,8 @@ #include "lwip/opt.h" #include "lwip/def.h" +#include + #if (LWIP_PLATFORM_BYTESWAP == 0) && (BYTE_ORDER == LITTLE_ENDIAN) /** From 5ddd2aef4b44f9a871a8ea387d0e2e1b6f542163 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Thu, 29 Sep 2016 08:25:57 +0200 Subject: [PATCH 247/325] Substitute custom itoa implementation mdns by lwip_itoa() and strlen() call --- src/apps/mdns/mdns.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/apps/mdns/mdns.c b/src/apps/mdns/mdns.c index 110affb4..085bebd4 100644 --- a/src/apps/mdns/mdns.c +++ b/src/apps/mdns/mdns.c @@ -470,15 +470,11 @@ mdns_build_reverse_v4_domain(struct mdns_domain *domain, const ip4_addr_t *addr) memset(domain, 0, sizeof(struct mdns_domain)); ptr = (const u8_t *) addr; for (i = sizeof(ip4_addr_t) - 1; i >= 0; i--) { - char buf[3]; - size_t pos = sizeof(buf); + char buf[4]; u8_t val = ptr[i]; - do { - pos--; - buf[pos] = '0' + (val % 10); - val /= 10; - } while (val != 0); /* loop is correct because u8_t needs at most 3 chars */ - res = mdns_domain_add_label(domain, &buf[pos], (u8_t)(3 - pos)); + + lwip_itoa(buf, sizeof(buf), val); + res = mdns_domain_add_label(domain, buf, (u8_t)strlen(buf)); LWIP_ERROR("mdns_build_reverse_v4_domain: Failed to add label", (res == ERR_OK), return res); } res = mdns_domain_add_label(domain, REVERSE_PTR_V4_DOMAIN, (u8_t)(sizeof(REVERSE_PTR_V4_DOMAIN)-1)); From af04864094375f8fe91c9990f8bc163245049262 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Thu, 29 Sep 2016 08:30:33 +0200 Subject: [PATCH 248/325] Remove non-standard strnlen() call in snmp_msg.c --- src/apps/snmp/snmp_msg.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/apps/snmp/snmp_msg.c b/src/apps/snmp/snmp_msg.c index e993db33..c33180d0 100644 --- a/src/apps/snmp/snmp_msg.c +++ b/src/apps/snmp/snmp_msg.c @@ -125,6 +125,7 @@ snmp_get_community_trap(void) void snmp_set_community_write(const char * const community) { + LWIP_ASSERT("community string must not be NULL", community != NULL); LWIP_ASSERT("community string is too long!", strlen(community) <= SNMP_MAX_COMMUNITY_STR_LEN); snmp_community_write = community; } @@ -910,7 +911,7 @@ snmp_parse_inbound_frame(struct snmp_request *request) snmp_authfail_trap(); return ERR_ARG; } else if (request->request_type == SNMP_ASN1_CONTEXT_PDU_SET_REQ) { - if (strnlen(snmp_community_write, SNMP_MAX_COMMUNITY_STR_LEN) == 0) { + if (snmp_community_write[0] == 0) { /* our write community is empty, that means all our objects are readonly */ request->error_status = SNMP_ERR_NOTWRITABLE; request->error_index = 1; From 40846260b5a433ddf1d8471f9e99217aa2011133 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Thu, 29 Sep 2016 10:44:53 +0200 Subject: [PATCH 249/325] Add comment about possible definitions for non-standard functions --- src/include/lwip/def.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/include/lwip/def.h b/src/include/lwip/def.h index 95d2d70c..35359b3a 100644 --- a/src/include/lwip/def.h +++ b/src/include/lwip/def.h @@ -138,16 +138,21 @@ u32_t lwip_ntohl(u32_t x); * your platform to save some code bytes if you use these functions * in your application, too. */ + #ifndef lwip_itoa +/* This can be #defined to itoa() or snprintf(result, bufsize, "%d", number) depending on your platform */ void lwip_itoa(char* result, size_t bufsize, int number); #endif #ifndef lwip_strnicmp +/* This can be #defined to strnicmp() or strncasecmp() depending on your platform */ int lwip_strnicmp(const char* str1, const char* str2, size_t len); #endif #ifndef lwip_stricmp +/* This can be #defined to stricmp() or strcasecmp() depending on your platform */ int lwip_stricmp(const char* str1, const char* str2); #endif #ifndef lwip_strnstr +/* This can be #defined to strnstr() depending on your platform */ char* lwip_strnstr(const char* buffer, const char* token, size_t n); #endif From 65796cd82734ffd1716225b4fa17a88749ff763a Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Thu, 29 Sep 2016 12:02:50 +0200 Subject: [PATCH 250/325] "Fix" bug #49078: lwip cannot establish ipv6 connection, because of failed to fill ipv6 source address in Neighbor Solicitation Message by adding a note to netif_add not to forget to create a link-local IPv6 address --- src/core/netif.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/core/netif.c b/src/core/netif.c index 9adb50be..3f074813 100644 --- a/src/core/netif.c +++ b/src/core/netif.c @@ -228,9 +228,12 @@ netif_input(struct pbuf *p, struct netif *inp) * to decide whether to forward to ethernet_input() or ip_input(). * In other words, the functions only work when the netif * driver is implemented correctly!\n - * Members of struct netif should be be initialized by the - * netif init function = netif driver (init parameter of this function). - * + * Most members of struct netif should be be initialized by the + * netif init function = netif driver (init parameter of this function).\n + * IPv6: Don't forget to call netif_create_ip6_linklocal_address() after + * setting the MAC address in struct netif.hwaddr + * (IPv6 requires a link-local address). + * * @return netif, or NULL if failed. */ struct netif * From 682b82aad8cec82f79a9d766b381d3978020d38a Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Thu, 29 Sep 2016 12:51:45 +0200 Subject: [PATCH 251/325] Improve documentation: Some words about multiple execution contexts in lwIP --- doc/doxygen/lwip.Doxyfile | 1 + doc/doxygen/main_page.h | 63 +++++++++++++++++++++++++++++++++++++-- src/api/api_lib.c | 2 +- src/api/netifapi.c | 2 +- src/api/sockets.c | 2 +- src/include/lwip/tcpip.h | 2 ++ 6 files changed, 66 insertions(+), 6 deletions(-) diff --git a/doc/doxygen/lwip.Doxyfile b/doc/doxygen/lwip.Doxyfile index c86326b0..125d3239 100644 --- a/doc/doxygen/lwip.Doxyfile +++ b/doc/doxygen/lwip.Doxyfile @@ -2071,6 +2071,7 @@ INCLUDE_FILE_PATTERNS = *.h PREDEFINED = __DOXYGEN__=1 \ NO_SYS=0 \ SYS_LIGHTWEIGHT_PROT=1 \ + LWIP_TCPIP_CORE_LOCKING=1 \ LWIP_IPV4=1 \ LWIP_IPV6=1 \ LWIP_ICMP=1 \ diff --git a/doc/doxygen/main_page.h b/doc/doxygen/main_page.h index db9c81e4..ad890234 100644 --- a/doc/doxygen/main_page.h +++ b/doc/doxygen/main_page.h @@ -1,4 +1,4 @@ -/** +/** * @defgroup lwip lwIP * * @defgroup infrastructure Infrastructure @@ -7,7 +7,7 @@ * Non thread-safe APIs, callback style for maximum performance and minimum * memory footprint. * - * @defgroup threadsafe_api Thread-safe APIs + * @defgroup sequential_api Sequential-style APIs * Thread-safe APIs, blocking functions. More overhead, but can be called * from any thread except TCPIP thread. * @@ -31,6 +31,63 @@ * @verbinclude "contrib.txt" */ +/** + * @page pitfalls Common pitfalls + * + * Multiple Execution Contexts in lwIP code + * ======================================== + * + * The most common source of lwIP problems is to have multiple execution contexts + * inside the lwIP code. + * + * lwIP can be used in two basic modes: @ref lwip_nosys (no OS/RTOS + * running on target system) or @ref lwip_os (there is an OS running + * on the target system). + * + * Mainloop Mode + * ------------- + * In mainloop mode, only @ref callbackstyle_api can be used. + * The user has two possibilities to ensure there is only one + * exection context at a time in lwIP: + * + * 1) Deliver RX ethernet packets directly in interrupt context to lwIP + * by calling netif->input directly in interrupt. This implies all lwIP + * callback functions are called in IRQ context, which may cause further + * problems in application code: IRQ is blocked for a long time, multiple + * execution contexts in application code etc. When the application wants + * to call lwIP, it only needs to disable interrupts during the call. + * If timers are involved, even more locking code is needed to lock out + * timer IRQ and ethernet IRQ from each other, assuming these may be nested. + * + * 2) Run lwIP in a mainloop. There is example code here: @ref lwip_nosys. + * lwIP is _ONLY_ called from mainloop callstacks here. The ethernet IRQ + * has to put received telegrams into a queue which is polled in the + * mainloop. Ensure lwIP is _NEVER_ called from an interrupt, e.g. + * some SPI IRQ wants to forward data to udp_send() or tcp_write()! + * + * OS Mode + * ------- + * In OS mode, @ref callbackstyle_api AND @ref sequential_api can be used. + * @ref sequential_api are designed to be called from threads other than + * the TCPIP thread, so there is nothing to consider here. + * But @ref callbackstyle_api functions must _ONLY_ be called from + * TCPIP thread. It is a common error to call these from other threads + * or from IRQ contexts. ​Ethernet RX needs to deliver incoming packets + * in the correct way by sending a message to TCPIP thread, this is + * implemented in tcpip_input().​​ + * Again, ensure lwIP is _NEVER_ called from an interrupt, e.g. + * some SPI IRQ wants to forward data to udp_send() or tcp_write()! + * + * 1) tcpip_callback() can be used get called back from TCPIP thread, + * it is safe to call any @ref callbackstyle_api from there. + * + * 2) Use @ref LWIP_TCPIP_CORE_LOCKING. All @ref callbackstyle_api + * functions can be called when lwIP core lock is aquired, see + * @ref LOCK_TCPIP_CORE() and @ref UNLOCK_TCPIP_CORE(). + * These macros cannot be used in an interrupt context! + * Note the OS must correctly handle priority inversion for this. + */ + /** * @page bugs Reporting bugs * Please report bugs in the lwIP bug tracker at savannah.\n @@ -60,7 +117,7 @@ * to use @ref LWIP_TCPIP_CORE_LOCKING.\n * Porting: implement all functions in @ref sys_layer.\n * You can use @ref callbackstyle_api together with @ref tcpip_callback, - * and all @ref threadsafe_api. + * and all @ref sequential_api. */ /** diff --git a/src/api/api_lib.c b/src/api/api_lib.c index e129473d..99c4b54d 100644 --- a/src/api/api_lib.c +++ b/src/api/api_lib.c @@ -3,7 +3,7 @@ * Sequential API External module * * @defgroup netconn Netconn API - * @ingroup threadsafe_api + * @ingroup sequential_api * Thread-safe, to be called from non-TCPIP threads only. * TX/RX handling based on @ref netbuf (containing @ref pbuf) * to avoid copying data around. diff --git a/src/api/netifapi.c b/src/api/netifapi.c index 6f7e55bf..fef05a34 100644 --- a/src/api/netifapi.c +++ b/src/api/netifapi.c @@ -3,7 +3,7 @@ * Network Interface Sequential API module * * @defgroup netifapi NETIF API - * @ingroup threadsafe_api + * @ingroup sequential_api * Thread-safe functions to be called from non-TCPIP threads * * @defgroup netifapi_netif NETIF related diff --git a/src/api/sockets.c b/src/api/sockets.c index 72e777d4..d6455534 100644 --- a/src/api/sockets.c +++ b/src/api/sockets.c @@ -3,7 +3,7 @@ * Sockets BSD-Like API module * * @defgroup socket Socket API - * @ingroup threadsafe_api + * @ingroup sequential_api * BSD-style socket API.\n * Thread-safe, to be called from non-TCPIP threads only.\n * Can be activated by defining @ref LWIP_SOCKET to 1.\n diff --git a/src/include/lwip/tcpip.h b/src/include/lwip/tcpip.h index 404a4a2c..f2f6b469 100644 --- a/src/include/lwip/tcpip.h +++ b/src/include/lwip/tcpip.h @@ -52,7 +52,9 @@ extern "C" { #if LWIP_TCPIP_CORE_LOCKING /** The global semaphore to lock the stack. */ extern sys_mutex_t lock_tcpip_core; +/** Lock lwIP core mutex (needs @ref LWIP_TCPIP_CORE_LOCKING 1) */ #define LOCK_TCPIP_CORE() sys_mutex_lock(&lock_tcpip_core) +/** Unlock lwIP core mutex (needs @ref LWIP_TCPIP_CORE_LOCKING 1) */ #define UNLOCK_TCPIP_CORE() sys_mutex_unlock(&lock_tcpip_core) #else /* LWIP_TCPIP_CORE_LOCKING */ #define LOCK_TCPIP_CORE() From 149701b34780dd78ba25cd6f2c695cff5ce82c31 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Fri, 30 Sep 2016 09:04:36 +0200 Subject: [PATCH 252/325] Fix bug #49218: pbuf_clen() overflow as a result of tcp_write concatenation Let pbuf_clen() return u16_t --- src/core/ipv4/ip4_frag.c | 5 ++--- src/core/ipv6/ip6_frag.c | 5 +++-- src/core/netif.c | 2 +- src/core/pbuf.c | 4 ++-- src/include/lwip/pbuf.h | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/core/ipv4/ip4_frag.c b/src/core/ipv4/ip4_frag.c index 50edd121..8f65b736 100644 --- a/src/core/ipv4/ip4_frag.c +++ b/src/core/ipv4/ip4_frag.c @@ -160,7 +160,7 @@ static int ip_reass_free_complete_datagram(struct ip_reassdata *ipr, struct ip_reassdata *prev) { u16_t pbufs_freed = 0; - u8_t clen; + u16_t clen; struct pbuf *p; struct ip_reass_helper *iprh; @@ -487,8 +487,7 @@ ip4_reass(struct pbuf *p) struct ip_hdr *fraghdr; struct ip_reassdata *ipr; struct ip_reass_helper *iprh; - u16_t offset, len; - u8_t clen; + u16_t offset, len, clen; IPFRAG_STATS_INC(ip_frag.recv); MIB2_STATS_INC(mib2.ipreasmreqds); diff --git a/src/core/ipv6/ip6_frag.c b/src/core/ipv6/ip6_frag.c index f41d167f..a7e88e4f 100644 --- a/src/core/ipv6/ip6_frag.c +++ b/src/core/ipv6/ip6_frag.c @@ -147,7 +147,7 @@ ip6_reass_free_complete_datagram(struct ip6_reassdata *ipr) { struct ip6_reassdata *prev; u16_t pbufs_freed = 0; - u8_t clen; + u16_t clen; struct pbuf *p; struct ip6_reass_helper *iprh; @@ -262,7 +262,8 @@ ip6_reass(struct pbuf *p) struct ip6_reass_helper *iprh, *iprh_tmp, *iprh_prev=NULL; struct ip6_frag_hdr *frag_hdr; u16_t offset, len; - u8_t clen, valid = 1; + u16_t clen; + u8_t valid = 1; struct pbuf *q; IP6_FRAG_STATS_INC(ip6_frag.recv); diff --git a/src/core/netif.c b/src/core/netif.c index 3f074813..9bbd8246 100644 --- a/src/core/netif.c +++ b/src/core/netif.c @@ -791,7 +791,7 @@ netif_loop_output(struct netif *netif, struct pbuf *p) err_t err; struct pbuf *last; #if LWIP_LOOPBACK_MAX_PBUFS - u8_t clen = 0; + u16_t clen = 0; #endif /* LWIP_LOOPBACK_MAX_PBUFS */ /* If we have a loopif, SNMP counters are adjusted for it, * if not they are adjusted for 'netif'. */ diff --git a/src/core/pbuf.c b/src/core/pbuf.c index a145dffc..b45ea8c9 100644 --- a/src/core/pbuf.c +++ b/src/core/pbuf.c @@ -779,10 +779,10 @@ pbuf_free(struct pbuf *p) * @param p first pbuf of chain * @return the number of pbufs in a chain */ -u8_t +u16_t pbuf_clen(struct pbuf *p) { - u8_t len; + u16_t len; len = 0; while (p != NULL) { diff --git a/src/include/lwip/pbuf.h b/src/include/lwip/pbuf.h index bc7296e0..d79d1717 100644 --- a/src/include/lwip/pbuf.h +++ b/src/include/lwip/pbuf.h @@ -231,7 +231,7 @@ u8_t pbuf_header(struct pbuf *p, s16_t header_size); u8_t pbuf_header_force(struct pbuf *p, s16_t header_size); void pbuf_ref(struct pbuf *p); u8_t pbuf_free(struct pbuf *p); -u8_t pbuf_clen(struct pbuf *p); +u16_t pbuf_clen(struct pbuf *p); void pbuf_cat(struct pbuf *head, struct pbuf *tail); void pbuf_chain(struct pbuf *head, struct pbuf *tail); struct pbuf *pbuf_dechain(struct pbuf *p); From db9c866fff188f781a8e3a8ac57ca28defcc7fca Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Fri, 30 Sep 2016 09:05:33 +0200 Subject: [PATCH 253/325] Minor: Documentation update --- doc/doxygen/main_page.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/doxygen/main_page.h b/doc/doxygen/main_page.h index ad890234..31cc0df6 100644 --- a/doc/doxygen/main_page.h +++ b/doc/doxygen/main_page.h @@ -8,7 +8,7 @@ * memory footprint. * * @defgroup sequential_api Sequential-style APIs - * Thread-safe APIs, blocking functions. More overhead, but can be called + * Sequential-style APIs, blocking functions. More overhead, but can be called * from any thread except TCPIP thread. * * @defgroup addons Addons From d7f8d33506dea115c33e5ef910e8bda26abaedb8 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Fri, 30 Sep 2016 09:35:27 +0200 Subject: [PATCH 254/325] Minor: update NO_SYS_SampleCode.c for IPv6 --- doc/NO_SYS_SampleCode.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/doc/NO_SYS_SampleCode.c b/doc/NO_SYS_SampleCode.c index f20106f5..f5c6c10b 100644 --- a/doc/NO_SYS_SampleCode.c +++ b/doc/NO_SYS_SampleCode.c @@ -46,12 +46,10 @@ static void netif_status_callback(struct netif *netif) static err_t netif_init(struct netif *netif) { netif->linkoutput = netif_output; - netif->output = etharp_output; - netif->name[0] = 'e'; - netif->name[1] = '0'; - netif->mtu = ETHERNET_MTU; - - netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_ETHERNET | NETIF_FLAG_IGMP; + netif->output = etharp_output; + netif->output_ip6 = ethip6_output; + netif->mtu = ETHERNET_MTU; + netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_ETHERNET | NETIF_FLAG_IGMP | NETIF_FLAG_MLD6; MIB2_INIT_NETIF(netif, snmp_ifType_ethernet_csmacd, 100000000); SMEMCPY(netif->hwaddr, your_mac_address_goes_here, sizeof(netif->hwaddr)); @@ -66,7 +64,11 @@ void main(void) lwip_init(); - netif_add(&netif, IPADDR_ANY, IPADDR_ANY, IPADDR_ANY, NULL, netif_init, netif_input); + netif_add(&netif, IP4_ADDR_ANY, IP4_ADDR_ANY, IP4_ADDR_ANY, NULL, netif_init, netif_input); + netif.name[0] = 'e'; + netif.name[1] = '0'; + netif_create_ip6_linklocal_address(&netif, 1); + netif.ip6_autoconfig_enabled = 1; netif_set_status_callback(&netif, netif_status_callback); netif_set_default(&netif); netif_set_up(&netif); From df5a79966ddd83a7c21a22c3cc2666a37559b340 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Sat, 1 Oct 2016 17:13:33 +0200 Subject: [PATCH 255/325] Fix bug #48886: raw pcbs are not handled on netif address change --- src/core/netif.c | 16 ++++++++++++++++ src/core/raw.c | 21 +++++++++++++++++++++ src/include/lwip/raw.h | 2 ++ 3 files changed, 39 insertions(+) diff --git a/src/core/netif.c b/src/core/netif.c index 9bbd8246..79b4652c 100644 --- a/src/core/netif.c +++ b/src/core/netif.c @@ -58,6 +58,7 @@ #include "lwip/netif.h" #include "lwip/priv/tcp_priv.h" #include "lwip/udp.h" +#include "lwip/raw.h" #include "lwip/snmp.h" #include "lwip/igmp.h" #include "lwip/etharp.h" @@ -391,6 +392,9 @@ netif_remove(struct netif *netif) #if LWIP_UDP udp_netif_ip_addr_changed(netif_ip_addr4(netif), NULL); #endif /* LWIP_UDP */ +#if LWIP_RAW + raw_netif_ip_addr_changed(netif_ip_addr4(netif), NULL); +#endif /* LWIP_RAW */ } #if LWIP_IGMP @@ -410,6 +414,9 @@ netif_remove(struct netif *netif) #if LWIP_UDP udp_netif_ip_addr_changed(netif_ip_addr6(netif, i), NULL); #endif /* LWIP_UDP */ +#if LWIP_RAW + raw_netif_ip_addr_changed(netif_ip_addr6(netif, i), NULL); +#endif /* LWIP_RAW */ } } #if LWIP_IPV6_MLD @@ -512,6 +519,9 @@ netif_set_ipaddr(struct netif *netif, const ip4_addr_t *ipaddr) #if LWIP_UDP udp_netif_ip_addr_changed(netif_ip_addr4(netif), &new_addr); #endif /* LWIP_UDP */ +#if LWIP_RAW + raw_netif_ip_addr_changed(netif_ip_addr4(netif), &new_addr); +#endif /* LWIP_RAW */ mib2_remove_ip4(netif); mib2_remove_route_ip4(0, netif); @@ -1047,6 +1057,9 @@ netif_ip6_addr_set_parts(struct netif *netif, s8_t addr_idx, u32_t i0, u32_t i1, #if LWIP_UDP udp_netif_ip_addr_changed(netif_ip_addr6(netif, addr_idx), &new_ipaddr); #endif /* LWIP_UDP */ +#if LWIP_RAW + raw_netif_ip_addr_changed(netif_ip_addr6(netif, addr_idx), &new_ipaddr); +#endif /* LWIP_RAW */ } /* @todo: remove/readd mib2 ip6 entries? */ @@ -1096,6 +1109,9 @@ netif_ip6_addr_set_state(struct netif* netif, s8_t addr_idx, u8_t state) #if LWIP_UDP udp_netif_ip_addr_changed(netif_ip_addr6(netif, addr_idx), NULL); #endif /* LWIP_UDP */ +#if LWIP_RAW + raw_netif_ip_addr_changed(netif_ip_addr6(netif, addr_idx), NULL); +#endif /* LWIP_RAW */ /* @todo: remove mib2 ip6 entries? */ } netif->ip6_addr_state[addr_idx] = state; diff --git a/src/core/raw.c b/src/core/raw.c index a9174542..111e47fb 100644 --- a/src/core/raw.c +++ b/src/core/raw.c @@ -495,4 +495,25 @@ raw_new_ip_type(u8_t type, u8_t proto) return pcb; } +/** This function is called from netif.c when address is changed + * + * @param old_addr IP address of the netif before change + * @param new_addr IP address of the netif after change + */ +void raw_netif_ip_addr_changed(const ip_addr_t* old_addr, const ip_addr_t* new_addr) +{ + struct raw_pcb* rpcb; + + if (!ip_addr_isany(old_addr) && !ip_addr_isany(new_addr)) { + for (rpcb = raw_pcbs; rpcb != NULL; rpcb = rpcb->next) { + /* PCB bound to current local interface address? */ + if (ip_addr_cmp(&rpcb->local_ip, old_addr)) { + /* The PCB is bound to the old ipaddr and + * is set to bound to the new one instead */ + ip_addr_copy(rpcb->local_ip, *new_addr); + } + } + } +} + #endif /* LWIP_RAW */ diff --git a/src/include/lwip/raw.h b/src/include/lwip/raw.h index f92c8ee9..30aa1471 100644 --- a/src/include/lwip/raw.h +++ b/src/include/lwip/raw.h @@ -104,6 +104,8 @@ void raw_recv (struct raw_pcb *pcb, raw_recv_fn recv, void *re u8_t raw_input (struct pbuf *p, struct netif *inp); #define raw_init() /* Compatibility define, no init needed. */ +void raw_netif_ip_addr_changed(const ip_addr_t* old_addr, const ip_addr_t* new_addr); + /* for compatibility with older implementation */ #define raw_new_ip6(proto) raw_new_ip_type(IPADDR_TYPE_V6, proto) From 8c52afb6ca2108153d020e5fc214ad8df7e9ebc7 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Sat, 1 Oct 2016 17:28:36 +0200 Subject: [PATCH 256/325] igmp: Optimize code by always skipping the first entry in the linked groups list - it is always the "allsystems" entry --- src/core/ipv4/igmp.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/core/ipv4/igmp.c b/src/core/ipv4/igmp.c index ab20b883..45388aa7 100644 --- a/src/core/ipv4/igmp.c +++ b/src/core/ipv4/igmp.c @@ -195,10 +195,13 @@ igmp_report_groups(struct netif *netif) LWIP_DEBUGF(IGMP_DEBUG, ("igmp_report_groups: sending IGMP reports on if %p\n", (void*)netif)); + /* Skip the first group in the list, it is always the allsystems group added in igmp_start() */ + if(group != NULL) { + group = group->next; + } + while (group != NULL) { - if (!(ip4_addr_cmp(&(group->group_address), &allsystems))) { - igmp_delaying_member(group, IGMP_JOIN_DELAYING_MEMBER_TMR); - } + igmp_delaying_member(group, IGMP_JOIN_DELAYING_MEMBER_TMR); group = group->next; } } @@ -368,11 +371,15 @@ igmp_input(struct pbuf *p, struct netif *inp, const ip4_addr_t *dest) } groupref = netif_igmp_data(inp); + + /* Do not send messages on the all systems group address! */ + /* Skip the first group in the list, it is always the allsystems group added in igmp_start() */ + if(group != NULL) { + group = group->next; + } + while (groupref) { - /* Do not send messages on the all systems group address! */ - if (!(ip4_addr_cmp(&(groupref->group_address), &allsystems))) { - igmp_delaying_member(groupref, igmp->igmp_maxresp); - } + igmp_delaying_member(groupref, igmp->igmp_maxresp); groupref = groupref->next; } } else { From b33070e0cff0aeae1d9acb10a5ac4fec9781731a Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Sat, 1 Oct 2016 21:13:05 +0200 Subject: [PATCH 257/325] Add documentation for bug #49139: IGMP "All Systems" vs MLD "All Nodes" inconsistency --- src/include/lwip/igmp.h | 4 +++- src/include/lwip/mld6.h | 5 ++++- src/include/lwip/netif.h | 2 ++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/include/lwip/igmp.h b/src/include/lwip/igmp.h index 58c34fc3..ffd80e68 100644 --- a/src/include/lwip/igmp.h +++ b/src/include/lwip/igmp.h @@ -100,7 +100,9 @@ err_t igmp_leavegroup_netif(struct netif *netif, const ip4_addr_t *groupaddr); void igmp_tmr(void); /** @ingroup igmp - * Get list head of IGMP groups for netif + * Get list head of IGMP groups for netif. + * Note: The allsystems group IP is contained in the list as first entry. + * @see @ref netif_set_igmp_mac_filter() */ #define netif_igmp_data(netif) ((struct igmp_group *)netif_get_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_IGMP)) diff --git a/src/include/lwip/mld6.h b/src/include/lwip/mld6.h index 1c724c02..7fa0797f 100644 --- a/src/include/lwip/mld6.h +++ b/src/include/lwip/mld6.h @@ -83,7 +83,10 @@ err_t mld6_leavegroup(const ip6_addr_t *srcaddr, const ip6_addr_t *groupaddr); err_t mld6_leavegroup_netif(struct netif *netif, const ip6_addr_t *groupaddr); /** @ingroup mld6 - * Get list head of MLD6 groups for netif + * Get list head of MLD6 groups for netif. + * Note: The allnodes group IP is NOT in the list, since it must always + * be received for correct IPv6 operation. + * @see @ref netif_set_mld_mac_filter() */ #define netif_mld6_data(netif) ((struct mld_group *)netif_get_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_MLD6)) diff --git a/src/include/lwip/netif.h b/src/include/lwip/netif.h index 6b164b4c..67a2d24d 100644 --- a/src/include/lwip/netif.h +++ b/src/include/lwip/netif.h @@ -424,11 +424,13 @@ void netif_set_link_callback(struct netif *netif, netif_status_callback_fn link_ #endif /* LWIP_NETIF_HOSTNAME */ #if LWIP_IGMP +/** @ingroup netif */ #define netif_set_igmp_mac_filter(netif, function) do { if((netif) != NULL) { (netif)->igmp_mac_filter = function; }}while(0) #define netif_get_igmp_mac_filter(netif) (((netif) != NULL) ? ((netif)->igmp_mac_filter) : NULL) #endif /* LWIP_IGMP */ #if LWIP_IPV6 && LWIP_IPV6_MLD +/** @ingroup netif */ #define netif_set_mld_mac_filter(netif, function) do { if((netif) != NULL) { (netif)->mld_mac_filter = function; }}while(0) #define netif_get_mld_mac_filter(netif) (((netif) != NULL) ? ((netif)->mld_mac_filter) : NULL) #define netif_mld_mac_filter(netif, addr, action) do { if((netif) && (netif)->mld_mac_filter) { (netif)->mld_mac_filter((netif), (addr), (action)); }}while(0) From 8f8f56914bc80655a1ce88d93513f934434f0ee2 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Sat, 1 Oct 2016 21:27:00 +0200 Subject: [PATCH 258/325] Fix bug #47731: IGMP state transition missing Set state variable according to RFC 2236 on timeout in delaying member state --- src/core/ipv4/igmp.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/core/ipv4/igmp.c b/src/core/ipv4/igmp.c index 45388aa7..79ba690d 100644 --- a/src/core/ipv4/igmp.c +++ b/src/core/ipv4/igmp.c @@ -665,6 +665,8 @@ igmp_timeout(struct netif *netif, struct igmp_group *group) ip4_addr_debug_print(IGMP_DEBUG, &(group->group_address)); LWIP_DEBUGF(IGMP_DEBUG, (" on if %p\n", (void*)netif)); + group->group_state = IGMP_GROUP_IDLE_MEMBER; + IGMP_STATS_INC(igmp.tx_report); igmp_send(netif, group, IGMP_V2_MEMB_REPORT); } From 5e15125b3df98ece8910ff1d8ec739bb8f391922 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Sun, 2 Oct 2016 20:50:32 +0800 Subject: [PATCH 259/325] igmp: Fix optimized code by always skipping the first entry in the linked groups list commit 8c52afb6ca21 ("igmp: Optimize code by always skipping the first entry in the linked groups list - it is always the "allsystems" entry") accidently changes the code logic. it should check groupref rather than group. Signed-off-by: Axel Lin --- src/core/ipv4/igmp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/ipv4/igmp.c b/src/core/ipv4/igmp.c index 79ba690d..d8e8f9c2 100644 --- a/src/core/ipv4/igmp.c +++ b/src/core/ipv4/igmp.c @@ -374,8 +374,8 @@ igmp_input(struct pbuf *p, struct netif *inp, const ip4_addr_t *dest) /* Do not send messages on the all systems group address! */ /* Skip the first group in the list, it is always the allsystems group added in igmp_start() */ - if(group != NULL) { - group = group->next; + if(groupref != NULL) { + groupref = groupref->next; } while (groupref) { From eb77c839fc51c585abf60e0c19a464ca0ad92e16 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Mon, 3 Oct 2016 09:45:59 +0200 Subject: [PATCH 260/325] Minor: comment in pbuf.c --- src/core/pbuf.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/core/pbuf.c b/src/core/pbuf.c index b45ea8c9..bb2c8311 100644 --- a/src/core/pbuf.c +++ b/src/core/pbuf.c @@ -56,6 +56,8 @@ void eth_rx_irq() my_pbuf->p.custom_free_function = my_pbuf_free_custom; my_pbuf->dma_descriptor = dma_desc; + invalidate_cpu_cache(dma_desc->rx_data, dma_desc->rx_length); + struct pbuf* p = pbuf_alloced_custom(PBUF_RAW, dma_desc->rx_length, PBUF_REF, From b040544628654cbea70f50866160e1316e3b2e64 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Mon, 3 Oct 2016 09:47:41 +0200 Subject: [PATCH 261/325] task #14150: Add TFTP server from Logan Gunthorpe Originally written by Logan Gunthorpe, modifications/fixes/IPv6 by Dirk Ziegelmeier --- src/Filelists.mk | 6 +- src/apps/tftp/tftp_server.c | 412 ++++++++++++++++++++++++++++ src/include/lwip/apps/tftp_opts.h | 105 +++++++ src/include/lwip/apps/tftp_server.h | 94 +++++++ 4 files changed, 616 insertions(+), 1 deletion(-) create mode 100644 src/apps/tftp/tftp_server.c create mode 100644 src/include/lwip/apps/tftp_opts.h create mode 100644 src/include/lwip/apps/tftp_server.h diff --git a/src/Filelists.mk b/src/Filelists.mk index 2dd0d36b..ac79422c 100644 --- a/src/Filelists.mk +++ b/src/Filelists.mk @@ -164,10 +164,14 @@ MDNSFILES=$(LWIPDIR)/apps/mdns/mdns.c # NETBIOSNSFILES: NetBIOS name server NETBIOSNSFILES=$(LWIPDIR)/apps/netbiosns/netbiosns.c +# TFTPFILES: TFTP server files +TFTPFILES=$(LWIPDIR)/apps/tftp/tftp_server.c + # LWIPAPPFILES: All LWIP APPs LWIPAPPFILES=$(SNMPFILES) \ $(HTTPDFILES) \ $(LWIPERFFILES) \ $(SNTPFILES) \ $(MDNSFILES) \ - $(NETBIOSNSFILES) + $(NETBIOSNSFILES) \ + $(TFTPFILES) diff --git a/src/apps/tftp/tftp_server.c b/src/apps/tftp/tftp_server.c new file mode 100644 index 00000000..bca18a6b --- /dev/null +++ b/src/apps/tftp/tftp_server.c @@ -0,0 +1,412 @@ +/****************************************************************//** + * + * @file tftp_server.c + * + * @author Logan Gunthorpe + * Dirk Ziegelmeier + * + * @brief Trivial File Transfer Protocol (RFC 1350) + * + * Copyright (c) Deltatee Enterprises Ltd. 2013 + * All rights reserved. + * + ********************************************************************/ + +/* + * Redistribution and use in source and binary forms, with or without + * modification,are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Author: Logan Gunthorpe + * Dirk Ziegelmeier + * + */ + +/** + * @defgroup tftp TFTP server + * @ingroup apps + * + * This is simple TFTP server for the lwIP raw API. + */ + +#include "lwip/apps/tftp_server.h" +#include "lwip/udp.h" +#include "lwip/timeouts.h" +#include "lwip/debug.h" + +#define TFTP_MAX_PAYLOAD_SIZE 512 +#define TFTP_HEADER_LENGTH 4 + +#define RRQ 1 +#define WRQ 2 +#define DATA 3 +#define ACK 4 +#define ERROR 5 + +enum tftp_error { + ERROR_FILE_NOT_FOUND = 1, + ERROR_ACCESS_VIOLATION = 2, + ERROR_DISK_FULL = 3, + ERROR_ILLEGAL_OPERATION = 4, + ERROR_UNKNOWN_TRFR_ID = 5, + ERROR_FILE_EXISTS = 6, + ERROR_NO_SUCH_USER = 7 +}; + +#include + +struct tftp_state { + const struct tftp_context *ctx; + void *handle; + struct pbuf *last_data; + struct udp_pcb *upcb; + ip_addr_t addr; + u16_t port; + int timer; + int last_pkt; + u16_t blknum; + u8_t retries; + u8_t mode_write; +}; + +static struct tftp_state tftp_state; + +static void tftp_tmr(void* arg); + +static void +close_handle(void) +{ + tftp_state.port = 0; + ip_addr_set_any(0, &tftp_state.addr); + + if(tftp_state.last_data != NULL) { + pbuf_free(tftp_state.last_data); + tftp_state.last_data = NULL; + } + + sys_untimeout(tftp_tmr, NULL); + + if (tftp_state.handle) { + tftp_state.ctx->close(tftp_state.handle); + tftp_state.handle = NULL; + LWIP_DEBUGF(TFTP_DEBUG | LWIP_DBG_STATE, ("tftp: closing\n")); + } +} + +static void +send_error(const ip_addr_t *addr, u16_t port, enum tftp_error code, const char *str) +{ + int str_length = strlen(str); + struct pbuf* p; + u16_t* payload; + + p = pbuf_alloc(PBUF_TRANSPORT, TFTP_HEADER_LENGTH + str_length + 1, PBUF_RAM); + if(p == NULL) { + return; + } + + payload = (u16_t*) p->payload; + payload[0] = PP_HTONS(ERROR); + payload[1] = htons(code); + MEMCPY(&payload[2], str, str_length + 1); + + udp_sendto(tftp_state.upcb, p, addr, port); + pbuf_free(p); +} + +static void +send_ack(u16_t blknum) +{ + struct pbuf* p; + u16_t* payload; + + p = pbuf_alloc(PBUF_TRANSPORT, TFTP_HEADER_LENGTH, PBUF_RAM); + if(p == NULL) { + return; + } + payload = (u16_t*) p->payload; + + payload[0] = PP_HTONS(ACK); + payload[1] = htons(blknum); + udp_sendto(tftp_state.upcb, p, &tftp_state.addr, tftp_state.port); + pbuf_free(p); +} + +static void +resend_data(void) +{ + struct pbuf *p = pbuf_alloc(PBUF_TRANSPORT, tftp_state.last_data->len, PBUF_RAM); + if(p == NULL) { + return; + } + + if(pbuf_copy(p, tftp_state.last_data) != ERR_OK) { + pbuf_free(p); + return; + } + + udp_sendto(tftp_state.upcb, p, &tftp_state.addr, tftp_state.port); + pbuf_free(p); +} + +static void +send_data(void) +{ + u16_t *payload; + int ret; + + if(tftp_state.last_data != NULL) { + pbuf_free(tftp_state.last_data); + } + + tftp_state.last_data = pbuf_alloc(PBUF_TRANSPORT, TFTP_HEADER_LENGTH + TFTP_MAX_PAYLOAD_SIZE, PBUF_RAM); + if(tftp_state.last_data == NULL) { + return; + } + + payload = (u16_t *) tftp_state.last_data->payload; + payload[0] = PP_HTONS(DATA); + payload[1] = htons(tftp_state.blknum); + + ret = tftp_state.ctx->read(tftp_state.handle, &payload[2], TFTP_MAX_PAYLOAD_SIZE); + if (ret < 0) { + send_error(&tftp_state.addr, tftp_state.port, ERROR_ACCESS_VIOLATION, "Error occured while reading the file."); + close_handle(); + return; + } + + pbuf_realloc(tftp_state.last_data, TFTP_HEADER_LENGTH + ret); + resend_data(); +} + +static void +recv(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16_t port) +{ + u16_t *sbuf = (u16_t *) p->payload; + int opcode; + + LWIP_UNUSED_ARG(arg); + LWIP_UNUSED_ARG(upcb); + + if (((tftp_state.port != 0) && (port != tftp_state.port)) || + (!ip_addr_isany_val(tftp_state.addr) && !ip_addr_cmp(&tftp_state.addr, addr))) { + send_error(addr, port, ERROR_ACCESS_VIOLATION, "Only one connection at a time is supported"); + pbuf_free(p); + return; + } + + opcode = sbuf[0]; + + tftp_state.last_pkt = tftp_state.timer; + tftp_state.retries = 0; + + switch (opcode) { + case PP_HTONS(RRQ): /* fall through */ + case PP_HTONS(WRQ): + { + const char tftp_null = 0; + char filename[TFTP_MAX_FILENAME_LEN]; + char mode[TFTP_MAX_MODE_LEN]; + u16_t filename_end_offset; + u16_t mode_end_offset; + + if(tftp_state.handle != NULL) { + send_error(addr, port, ERROR_ACCESS_VIOLATION, "Only one connection at a time is supported"); + break; + } + + sys_timeout(TFTP_TIMER_MSECS, tftp_tmr, NULL); + + /* find \0 in pbuf -> end of filename string */ + filename_end_offset = pbuf_memfind(p, &tftp_null, sizeof(tftp_null), 2); + if((u16_t)(filename_end_offset-2) > sizeof(filename)) { + send_error(addr, port, ERROR_ACCESS_VIOLATION, "Filename too long/not NULL terminated"); + break; + } + pbuf_copy_partial(p, filename, filename_end_offset-2, 2); + + /* find \0 in pbuf -> end of mode string */ + mode_end_offset = pbuf_memfind(p, &tftp_null, sizeof(tftp_null), filename_end_offset+1); + if((u16_t)(mode_end_offset-filename_end_offset) > sizeof(mode)) { + send_error(addr, port, ERROR_ACCESS_VIOLATION, "Mode too long/not NULL terminated"); + break; + } + pbuf_copy_partial(p, mode, mode_end_offset-filename_end_offset, filename_end_offset+1); + + tftp_state.handle = tftp_state.ctx->open(filename, mode, opcode == PP_HTONS(WRQ)); + tftp_state.blknum = 1; + + if (!tftp_state.handle) { + send_error(addr, port, ERROR_FILE_NOT_FOUND, "Unable to open requested file."); + break; + } + + LWIP_DEBUGF(TFTP_DEBUG | LWIP_DBG_STATE, ("tftp: %s request from ", (opcode == PP_HTONS(WRQ)) ? "write" : "read")); + ip_addr_debug_print(TFTP_DEBUG | LWIP_DBG_STATE, addr); + LWIP_DEBUGF(TFTP_DEBUG | LWIP_DBG_STATE, (" for '%s' mode '%s'\n", filename, mode)); + + ip_addr_copy(tftp_state.addr, *addr); + tftp_state.port = port; + + if (opcode == PP_HTONS(WRQ)) { + tftp_state.mode_write = 1; + send_ack(0); + } else { + tftp_state.mode_write = 0; + send_data(); + } + + break; + } + + case PP_HTONS(DATA): + { + int ret; + u16_t blknum; + + if (tftp_state.handle == NULL) { + send_error(addr, port, ERROR_ACCESS_VIOLATION, "No connection"); + break; + } + + if (tftp_state.mode_write != 1) { + send_error(addr, port, ERROR_ACCESS_VIOLATION, "Not a write connection"); + break; + } + + blknum = ntohs(sbuf[1]); + pbuf_header(p, -TFTP_HEADER_LENGTH); + + ret = tftp_state.ctx->write(tftp_state.handle, p); + if (ret < 0) { + send_error(addr, port, ERROR_ACCESS_VIOLATION, "error writing file"); + close_handle(); + } else { + send_ack(blknum); + } + + if (p->tot_len < TFTP_MAX_PAYLOAD_SIZE) { + close_handle(); + } + break; + } + + case PP_HTONS(ACK): + { + u16_t blknum; + int lastpkt; + + if (tftp_state.handle == NULL) { + send_error(addr, port, ERROR_ACCESS_VIOLATION, "No connection"); + break; + } + + if (tftp_state.mode_write != 0) { + send_error(addr, port, ERROR_ACCESS_VIOLATION, "Not a read connection"); + break; + } + + blknum = ntohs(sbuf[1]); + if (blknum != tftp_state.blknum) { + send_error(addr, port, ERROR_UNKNOWN_TRFR_ID, "Wrong block number"); + break; + } + + lastpkt = 0; + + if (tftp_state.last_data != NULL) { + lastpkt = tftp_state.last_data->tot_len != (TFTP_MAX_PAYLOAD_SIZE + TFTP_HEADER_LENGTH); + } + + if (!lastpkt) { + tftp_state.blknum++; + send_data(); + } else { + close_handle(); + } + + break; + } + + default: + send_error(addr, port, ERROR_ILLEGAL_OPERATION, "Unknown operation"); + break; + } + + pbuf_free(p); +} + +static void +tftp_tmr(void* arg) +{ + LWIP_UNUSED_ARG(arg); + + tftp_state.timer++; + + if (tftp_state.handle == NULL) { + return; + } + + sys_timeout(TFTP_TIMER_MSECS, tftp_tmr, NULL); + + if ((tftp_state.timer - tftp_state.last_pkt) > (TFTP_TIMEOUT_MSECS / TFTP_TIMER_MSECS)) { + if ((tftp_state.last_data != NULL) && (tftp_state.retries < TFTP_MAX_RETRIES)) { + LWIP_DEBUGF(TFTP_DEBUG | LWIP_DBG_STATE, ("tftp: timeout, retrying\n")); + resend_data(); + tftp_state.retries++; + } else { + LWIP_DEBUGF(TFTP_DEBUG | LWIP_DBG_STATE, ("tftp: timeout\n")); + close_handle(); + } + } +} + +/** @ingroup tftp + * Initialize TFTP server. + * @param ctx TFTP callback struct + */ +err_t +tftp_init(const struct tftp_context *ctx) +{ + err_t ret; + + struct udp_pcb *pcb = udp_new_ip_type(IPADDR_TYPE_ANY); + if (pcb == NULL) { + return ERR_MEM; + } + + ret = udp_bind(pcb, IP_ANY_TYPE, TFTP_PORT); + if (ret != ERR_OK) { + udp_remove(pcb); + return ret; + } + + tftp_state.handle = NULL; + tftp_state.port = 0; + tftp_state.ctx = ctx; + tftp_state.timer = 0; + tftp_state.last_data = NULL; + tftp_state.upcb = pcb; + + udp_recv(pcb, recv, NULL); + + return ERR_OK; +} diff --git a/src/include/lwip/apps/tftp_opts.h b/src/include/lwip/apps/tftp_opts.h new file mode 100644 index 00000000..6968a803 --- /dev/null +++ b/src/include/lwip/apps/tftp_opts.h @@ -0,0 +1,105 @@ +/****************************************************************//** + * + * @file tftp_opts.h + * + * @author Logan Gunthorpe + * + * @brief Trivial File Transfer Protocol (RFC 1350) implementation options + * + * Copyright (c) Deltatee Enterprises Ltd. 2013 + * All rights reserved. + * + ********************************************************************/ + +/* + * Redistribution and use in source and binary forms, with or without + * modification,are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Author: Logan Gunthorpe + * + */ + +#ifndef LWIP_HDR_APPS_TFTP_OPTS_H +#define LWIP_HDR_APPS_TFTP_OPTS_H + +#include "lwip/opt.h" + +/** + * @defgroup tftp_opts Options + * @ingroup tftp + * @{ + */ + +/** + * Enable TFTP debug messages + */ +#if !defined TFTP_DEBUG || defined __DOXYGEN__ +#define TFTP_DEBUG LWIP_DBG_ON +#endif + +/** + * TFTP server port + */ +#if !defined TFTP_PORT || defined __DOXYGEN__ +#define TFTP_PORT 69 +#endif + +/** + * TFTP timeout + */ +#if !defined TFTP_TIMEOUT_MSECS || defined __DOXYGEN__ +#define TFTP_TIMEOUT_MSECS 10000 +#endif + +/** + * Max. number of retries when a file is read from server + */ +#if !defined TFTP_MAX_RETRIES || defined __DOXYGEN__ +#define TFTP_MAX_RETRIES 5 +#endif + +/** + * TFTP timer cyclic interval + */ +#if !defined TFTP_TIMER_MSECS || defined __DOXYGEN__ +#define TFTP_TIMER_MSECS 50 +#endif + +/** + * Max. length of TFTP filename + */ +#if !defined TFTP_MAX_FILENAME_LEN || defined __DOXYGEN__ +#define TFTP_MAX_FILENAME_LEN 20 +#endif + +/** + * Max. length of TFTP mode + */ +#if !defined TFTP_MAX_MODE_LEN || defined __DOXYGEN__ +#define TFTP_MAX_MODE_LEN 7 +#endif + +/** + * @} + */ + +#endif /* LWIP_HDR_APPS_TFTP_OPTS_H */ diff --git a/src/include/lwip/apps/tftp_server.h b/src/include/lwip/apps/tftp_server.h new file mode 100644 index 00000000..ba7da964 --- /dev/null +++ b/src/include/lwip/apps/tftp_server.h @@ -0,0 +1,94 @@ +/****************************************************************//** + * + * @file tftp_server.h + * + * @author Logan Gunthorpe + * + * @brief Trivial File Transfer Protocol (RFC 1350) + * + * Copyright (c) Deltatee Enterprises Ltd. 2013 + * All rights reserved. + * + ********************************************************************/ + +/* + * Redistribution and use in source and binary forms, with or without + * modification,are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Author: Logan Gunthorpe + * + */ + +#ifndef LWIP_HDR_APPS_TFTP_SERVER_H +#define LWIP_HDR_APPS_TFTP_SERVER_H + +#include "lwip/apps/tftp_opts.h" +#include "lwip/err.h" +#include "lwip/pbuf.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** @ingroup tftp + * TFTP context containing callback functions for TFTP transfers + */ +struct tftp_context { + /** + * Open file for read/write. + * @param fname Filename + * @param mode Mode string from TFTP RFC 1350 (netascii, octet, mail) + * @param write Flag indicating read (0) or write (!= 0) access + * @returns File handle supplied to other functions + */ + void* (*open)(const char* fname, const char* mode, u8_t write); + /** + * Close file handle + * @param handle File handle returned by open() + */ + void (*close)(void* handle); + /** + * Read from file + * @param handle File handle returned by open() + * @param buf Target buffer to copy read data to + * @param bytes Number of bytes to copy to buf + * @returns >= 0: Success; < 0: Error + */ + int (*read)(void* handle, void* buf, int bytes); + /** + * Write to file + * @param handle File handle returned by open() + * @param pbuf PBUF adjusted such that payload pointer points + * to the beginning of write data. In other words, + * TFTP headers are stripped off. + * @returns >= 0: Success; < 0: Error + */ + int (*write)(void* handle, struct pbuf* p); +}; + +err_t tftp_init(const struct tftp_context* ctx); + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_APPS_TFTP_SERVER_H */ From 1e5efee7cbdc5821f46a77de3bbbad63ab6bf012 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Mon, 3 Oct 2016 09:50:34 +0200 Subject: [PATCH 262/325] TFTP server depends on UDP --- src/apps/tftp/tftp_server.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/apps/tftp/tftp_server.c b/src/apps/tftp/tftp_server.c index bca18a6b..89dd7a1c 100644 --- a/src/apps/tftp/tftp_server.c +++ b/src/apps/tftp/tftp_server.c @@ -48,6 +48,9 @@ */ #include "lwip/apps/tftp_server.h" + +#if LWIP_UDP + #include "lwip/udp.h" #include "lwip/timeouts.h" #include "lwip/debug.h" @@ -410,3 +413,5 @@ tftp_init(const struct tftp_context *ctx) return ERR_OK; } + +#endif /* LWIP_UDP */ \ No newline at end of file From f8683499a645f5ff08a6459c367c659832804f21 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Mon, 3 Oct 2016 14:33:57 +0200 Subject: [PATCH 263/325] TFTP: Add missing newline at end of file --- src/apps/tftp/tftp_server.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/apps/tftp/tftp_server.c b/src/apps/tftp/tftp_server.c index 89dd7a1c..2363adce 100644 --- a/src/apps/tftp/tftp_server.c +++ b/src/apps/tftp/tftp_server.c @@ -414,4 +414,4 @@ tftp_init(const struct tftp_context *ctx) return ERR_OK; } -#endif /* LWIP_UDP */ \ No newline at end of file +#endif /* LWIP_UDP */ From 81549578bf2bfe792c406013b8a9c8e4897c246c Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Tue, 4 Oct 2016 08:54:52 +0200 Subject: [PATCH 264/325] Fix compile of TFTP with MSVC --- src/apps/tftp/tftp_server.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/apps/tftp/tftp_server.c b/src/apps/tftp/tftp_server.c index 2363adce..ea7e7246 100644 --- a/src/apps/tftp/tftp_server.c +++ b/src/apps/tftp/tftp_server.c @@ -121,7 +121,7 @@ send_error(const ip_addr_t *addr, u16_t port, enum tftp_error code, const char * struct pbuf* p; u16_t* payload; - p = pbuf_alloc(PBUF_TRANSPORT, TFTP_HEADER_LENGTH + str_length + 1, PBUF_RAM); + p = pbuf_alloc(PBUF_TRANSPORT, (u16_t)(TFTP_HEADER_LENGTH + str_length + 1), PBUF_RAM); if(p == NULL) { return; } @@ -196,7 +196,7 @@ send_data(void) return; } - pbuf_realloc(tftp_state.last_data, TFTP_HEADER_LENGTH + ret); + pbuf_realloc(tftp_state.last_data, (u16_t)(TFTP_HEADER_LENGTH + ret)); resend_data(); } From d1ed89b2e4463903e579622befbcabde96b319f6 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Tue, 4 Oct 2016 10:31:43 +0200 Subject: [PATCH 265/325] Fix accidental TAB in tftp_server.h --- src/include/lwip/apps/tftp_server.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/include/lwip/apps/tftp_server.h b/src/include/lwip/apps/tftp_server.h index ba7da964..3fbe701e 100644 --- a/src/include/lwip/apps/tftp_server.h +++ b/src/include/lwip/apps/tftp_server.h @@ -45,7 +45,7 @@ #include "lwip/err.h" #include "lwip/pbuf.h" -#ifdef __cplusplus +#ifdef __cplusplus extern "C" { #endif @@ -87,7 +87,7 @@ struct tftp_context { err_t tftp_init(const struct tftp_context* ctx); -#ifdef __cplusplus +#ifdef __cplusplus } #endif From 30251b14046c942a03f088c0a7cc991c4f2e4e9b Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Tue, 4 Oct 2016 12:34:53 +0200 Subject: [PATCH 266/325] Fix bug #49264: Crash Error when LWIP_SOCKET_OFFSET is in use Handle LWIP_SOCKET_OFFSET in lwip_socket_drop_registered_memberships, lwip_socket_unregister_membership and lwip_socket_register_membership. --- src/api/sockets.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/api/sockets.c b/src/api/sockets.c index d6455534..d63924e7 100644 --- a/src/api/sockets.c +++ b/src/api/sockets.c @@ -2732,7 +2732,7 @@ lwip_socket_register_membership(int s, const ip4_addr_t *if_addr, const ip4_addr { /* s+1 is stored in the array to prevent having to initialize the array (default initialization is to 0) */ - int sa = s + 1; + int sa = s + 1 - LWIP_SOCKET_OFFSET; int i; for (i = 0; i < LWIP_SOCKET_MAX_MEMBERSHIPS; i++) { @@ -2756,7 +2756,7 @@ lwip_socket_unregister_membership(int s, const ip4_addr_t *if_addr, const ip4_ad { /* s+1 is stored in the array to prevent having to initialize the array (default initialization is to 0) */ - int sa = s + 1; + int sa = s + 1 - LWIP_SOCKET_OFFSET; int i; for (i = 0; i < LWIP_SOCKET_MAX_MEMBERSHIPS; i++) { @@ -2779,7 +2779,7 @@ static void lwip_socket_drop_registered_memberships(int s) { /* s+1 is stored in the array to prevent having to initialize the array (default initialization is to 0) */ - int sa = s + 1; + int sa = s + 1 - LWIP_SOCKET_OFFSET; int i; LWIP_ASSERT("socket has no netconn", sockets[s].conn != NULL); From d9c6badc551d2ce37a18a5ef6ab2bd3dd60efcb6 Mon Sep 17 00:00:00 2001 From: goldsimon Date: Tue, 4 Oct 2016 12:27:33 +0200 Subject: [PATCH 267/325] Revert "Fixed bug #49209: netconn_drain() fails to handle 'netconn_aborted' pointer" This reverts commit 0e2354e658d9dc193d60048a8394517a41ca64ff. --- src/api/api_msg.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/api/api_msg.c b/src/api/api_msg.c index 8b7a6bd9..9dfea64e 100644 --- a/src/api/api_msg.c +++ b/src/api/api_msg.c @@ -780,8 +780,7 @@ netconn_drain(struct netconn *conn) /* Delete and drain the acceptmbox. */ #if LWIP_TCP if (sys_mbox_valid(&conn->acceptmbox)) { - while ((sys_mbox_tryfetch(&conn->acceptmbox, &mem) != SYS_MBOX_EMPTY) && - (mem != &netconn_aborted)) { + while (sys_mbox_tryfetch(&conn->acceptmbox, &mem) != SYS_MBOX_EMPTY) { struct netconn *newconn = (struct netconn *)mem; /* Only tcp pcbs have an acceptmbox, so no need to check conn->type */ /* pcb might be set to NULL already by err_tcp() */ From cdc97d277929db78ee7f8e117fb1223515b4d1bd Mon Sep 17 00:00:00 2001 From: goldsimon Date: Tue, 4 Oct 2016 12:29:22 +0200 Subject: [PATCH 268/325] Correctly fix bug #49209: netconn_drain() fails to handle 'netconn_aborted' pointer --- src/api/api_msg.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/api/api_msg.c b/src/api/api_msg.c index 9dfea64e..fafc9eb9 100644 --- a/src/api/api_msg.c +++ b/src/api/api_msg.c @@ -781,16 +781,18 @@ netconn_drain(struct netconn *conn) #if LWIP_TCP if (sys_mbox_valid(&conn->acceptmbox)) { while (sys_mbox_tryfetch(&conn->acceptmbox, &mem) != SYS_MBOX_EMPTY) { - struct netconn *newconn = (struct netconn *)mem; - /* Only tcp pcbs have an acceptmbox, so no need to check conn->type */ - /* pcb might be set to NULL already by err_tcp() */ - /* drain recvmbox */ - netconn_drain(newconn); - if (newconn->pcb.tcp != NULL) { - tcp_abort(newconn->pcb.tcp); - newconn->pcb.tcp = NULL; + if (mem != &netconn_aborted) { + struct netconn *newconn = (struct netconn *)mem; + /* Only tcp pcbs have an acceptmbox, so no need to check conn->type */ + /* pcb might be set to NULL already by err_tcp() */ + /* drain recvmbox */ + netconn_drain(newconn); + if (newconn->pcb.tcp != NULL) { + tcp_abort(newconn->pcb.tcp); + newconn->pcb.tcp = NULL; + } + netconn_free(newconn); } - netconn_free(newconn); } sys_mbox_free(&conn->acceptmbox); sys_mbox_set_invalid(&conn->acceptmbox); From ee27daffc4749f066e76ba15b36ef008ff11d883 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Tue, 4 Oct 2016 13:30:23 +0200 Subject: [PATCH 269/325] Fix bug #48876: nd6: timers should be in ticks, not ms delay_time and stale_time are ticks now. reachable_time and invalidation_timer are untouched since they may originate from telegram values -> not converting them to ticks avoids an integer division --- src/core/ipv6/ethip6.c | 2 +- src/core/ipv6/nd6.c | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/core/ipv6/ethip6.c b/src/core/ipv6/ethip6.c index f863d2bb..509fc1c5 100644 --- a/src/core/ipv6/ethip6.c +++ b/src/core/ipv6/ethip6.c @@ -107,7 +107,7 @@ ethip6_output(struct netif *netif, struct pbuf *q, const ip6_addr_t *ip6addr) if (neighbor_cache[i].state == ND6_STALE) { /* Switch to delay state. */ neighbor_cache[i].state = ND6_DELAY; - neighbor_cache[i].counter.delay_time = LWIP_ND6_DELAY_FIRST_PROBE_TIME; + neighbor_cache[i].counter.delay_time = LWIP_ND6_DELAY_FIRST_PROBE_TIME / ND6_TMR_INTERVAL; } /* @todo should we send or queue if PROBE? send for now, to let unicast NS pass. */ if ((neighbor_cache[i].state == ND6_REACHABLE) || diff --git a/src/core/ipv6/nd6.c b/src/core/ipv6/nd6.c index d097f373..505d4f9c 100644 --- a/src/core/ipv6/nd6.c +++ b/src/core/ipv6/nd6.c @@ -345,7 +345,7 @@ nd6_input(struct pbuf *p, struct netif *inp) /* Delay probe in case we get confirmation of reachability from upper layer (TCP). */ neighbor_cache[i].state = ND6_DELAY; - neighbor_cache[i].counter.delay_time = LWIP_ND6_DELAY_FIRST_PROBE_TIME; + neighbor_cache[i].counter.delay_time = LWIP_ND6_DELAY_FIRST_PROBE_TIME / ND6_TMR_INTERVAL; } } else { /* Add their IPv6 address and link-layer address to neighbor cache. @@ -366,7 +366,7 @@ nd6_input(struct pbuf *p, struct netif *inp) /* Receiving a message does not prove reachability: only in one direction. * Delay probe in case we get confirmation of reachability from upper layer (TCP). */ neighbor_cache[i].state = ND6_DELAY; - neighbor_cache[i].counter.delay_time = LWIP_ND6_DELAY_FIRST_PROBE_TIME; + neighbor_cache[i].counter.delay_time = LWIP_ND6_DELAY_FIRST_PROBE_TIME / ND6_TMR_INTERVAL; } /* Override ip6_current_dest_addr() so that we have an aligned copy. */ @@ -593,7 +593,7 @@ nd6_input(struct pbuf *p, struct netif *inp) /* Receiving a message does not prove reachability: only in one direction. * Delay probe in case we get confirmation of reachability from upper layer (TCP). */ neighbor_cache[i].state = ND6_DELAY; - neighbor_cache[i].counter.delay_time = LWIP_ND6_DELAY_FIRST_PROBE_TIME; + neighbor_cache[i].counter.delay_time = LWIP_ND6_DELAY_FIRST_PROBE_TIME / ND6_TMR_INTERVAL; } } if (i >= 0) { @@ -602,7 +602,7 @@ nd6_input(struct pbuf *p, struct netif *inp) /* Receiving a message does not prove reachability: only in one direction. * Delay probe in case we get confirmation of reachability from upper layer (TCP). */ neighbor_cache[i].state = ND6_DELAY; - neighbor_cache[i].counter.delay_time = LWIP_ND6_DELAY_FIRST_PROBE_TIME; + neighbor_cache[i].counter.delay_time = LWIP_ND6_DELAY_FIRST_PROBE_TIME / ND6_TMR_INTERVAL; } } } @@ -698,15 +698,15 @@ nd6_tmr(void) } break; case ND6_STALE: - neighbor_cache[i].counter.stale_time += ND6_TMR_INTERVAL; + neighbor_cache[i].counter.stale_time++; break; case ND6_DELAY: - if (neighbor_cache[i].counter.delay_time <= ND6_TMR_INTERVAL) { + if (neighbor_cache[i].counter.delay_time <= 1) { /* Change to PROBE state. */ neighbor_cache[i].state = ND6_PROBE; neighbor_cache[i].counter.probes_sent = 0; } else { - neighbor_cache[i].counter.delay_time -= ND6_TMR_INTERVAL; + neighbor_cache[i].counter.delay_time--; } break; case ND6_PROBE: From ec236da9728b1ac07761f67d90b73b4614070118 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Tue, 4 Oct 2016 13:36:30 +0200 Subject: [PATCH 270/325] Add comment for my last changes --- src/include/lwip/nd6.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/include/lwip/nd6.h b/src/include/lwip/nd6.h index c5f27d73..e4715ad3 100644 --- a/src/include/lwip/nd6.h +++ b/src/include/lwip/nd6.h @@ -74,10 +74,10 @@ struct nd6_neighbor_cache_entry { u8_t state; u8_t isrouter; union { - u32_t reachable_time; - u32_t delay_time; + u32_t reachable_time; /* in ms since value may originate from network packet */ + u32_t delay_time; /* ticks (ND6_TMR_INTERVAL) */ u32_t probes_sent; - u32_t stale_time; + u32_t stale_time; /* ticks (ND6_TMR_INTERVAL) */ } counter; }; @@ -91,7 +91,7 @@ struct nd6_destination_cache_entry { struct nd6_prefix_list_entry { ip6_addr_t prefix; struct netif *netif; - u32_t invalidation_timer; + u32_t invalidation_timer; /* in ms since value may originate from network packet */ #if LWIP_IPV6_AUTOCONFIG u8_t flags; #define ND6_PREFIX_AUTOCONFIG_AUTONOMOUS 0x01 @@ -102,7 +102,7 @@ struct nd6_prefix_list_entry { struct nd6_router_list_entry { struct nd6_neighbor_cache_entry *neighbor_entry; - u32_t invalidation_timer; + u32_t invalidation_timer; /* in ms since value may originate from network packet */ u8_t flags; }; From bef787304228213a29ff6dba60fab369d785508e Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Tue, 4 Oct 2016 13:59:05 +0200 Subject: [PATCH 271/325] ND6: Always set neighbor_cache.state together with counter value to avoid inconsistency --- src/core/ipv6/nd6.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/core/ipv6/nd6.c b/src/core/ipv6/nd6.c index 505d4f9c..c06b1780 100644 --- a/src/core/ipv6/nd6.c +++ b/src/core/ipv6/nd6.c @@ -231,8 +231,6 @@ nd6_input(struct pbuf *p, struct netif *inp) } /* Update cache entry. */ - neighbor_cache[i].netif = inp; - neighbor_cache[i].counter.reachable_time = reachable_time; if ((na_hdr->flags & ND6_FLAG_OVERRIDE) || (neighbor_cache[i].state == ND6_INCOMPLETE)) { /* Check that link-layer address option also fits in packet. */ @@ -256,7 +254,10 @@ nd6_input(struct pbuf *p, struct netif *inp) MEMCPY(neighbor_cache[i].lladdr, lladdr_opt->addr, inp->hwaddr_len); } + + neighbor_cache[i].netif = inp; neighbor_cache[i].state = ND6_REACHABLE; + neighbor_cache[i].counter.reachable_time = reachable_time; /* Send queued packets, if any. */ if (neighbor_cache[i].q != NULL) { From 95754ba95abe2a243531a983cda34e043c5d4e9f Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Tue, 4 Oct 2016 14:05:56 +0200 Subject: [PATCH 272/325] Another try to fix bug #49264: Crash Error when LWIP_SOCKET_OFFSET is in use --- src/api/sockets.c | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/src/api/sockets.c b/src/api/sockets.c index d63924e7..dbf91399 100644 --- a/src/api/sockets.c +++ b/src/api/sockets.c @@ -266,8 +266,8 @@ union sockaddr_aligned { /* This is to keep track of IP_ADD_MEMBERSHIP calls to drop the membership when a socket is closed */ struct lwip_socket_multicast_pair { - /** the socket (+1 to not require initialization) */ - int sa; + /** the socket */ + struct lwip_sock* sock; /** the interface address */ ip4_addr_t if_addr; /** the group address */ @@ -2730,14 +2730,16 @@ lwip_fcntl(int s, int cmd, int val) static int lwip_socket_register_membership(int s, const ip4_addr_t *if_addr, const ip4_addr_t *multi_addr) { - /* s+1 is stored in the array to prevent having to initialize the array - (default initialization is to 0) */ - int sa = s + 1 - LWIP_SOCKET_OFFSET; + struct lwip_sock *sock = get_socket(s); int i; + if (!sock) { + return 0; + } + for (i = 0; i < LWIP_SOCKET_MAX_MEMBERSHIPS; i++) { - if (socket_ipv4_multicast_memberships[i].sa == 0) { - socket_ipv4_multicast_memberships[i].sa = sa; + if (socket_ipv4_multicast_memberships[i].sock == NULL) { + socket_ipv4_multicast_memberships[i].sock = sock; ip4_addr_copy(socket_ipv4_multicast_memberships[i].if_addr, *if_addr); ip4_addr_copy(socket_ipv4_multicast_memberships[i].multi_addr, *multi_addr); return 1; @@ -2754,16 +2756,18 @@ lwip_socket_register_membership(int s, const ip4_addr_t *if_addr, const ip4_addr static void lwip_socket_unregister_membership(int s, const ip4_addr_t *if_addr, const ip4_addr_t *multi_addr) { - /* s+1 is stored in the array to prevent having to initialize the array - (default initialization is to 0) */ - int sa = s + 1 - LWIP_SOCKET_OFFSET; + struct lwip_sock *sock = get_socket(s); int i; + if (!sock) { + return; + } + for (i = 0; i < LWIP_SOCKET_MAX_MEMBERSHIPS; i++) { - if ((socket_ipv4_multicast_memberships[i].sa == sa) && + if ((socket_ipv4_multicast_memberships[i].sock == sock) && ip4_addr_cmp(&socket_ipv4_multicast_memberships[i].if_addr, if_addr) && ip4_addr_cmp(&socket_ipv4_multicast_memberships[i].multi_addr, multi_addr)) { - socket_ipv4_multicast_memberships[i].sa = 0; + socket_ipv4_multicast_memberships[i].sock = NULL; ip4_addr_set_zero(&socket_ipv4_multicast_memberships[i].if_addr); ip4_addr_set_zero(&socket_ipv4_multicast_memberships[i].multi_addr); return; @@ -2775,21 +2779,22 @@ lwip_socket_unregister_membership(int s, const ip4_addr_t *if_addr, const ip4_ad * * ATTENTION: this function is NOT called from tcpip_thread (or under CORE_LOCK). */ -static void lwip_socket_drop_registered_memberships(int s) +static void +lwip_socket_drop_registered_memberships(int s) { - /* s+1 is stored in the array to prevent having to initialize the array - (default initialization is to 0) */ - int sa = s + 1 - LWIP_SOCKET_OFFSET; + struct lwip_sock *sock = get_socket(s); int i; - LWIP_ASSERT("socket has no netconn", sockets[s].conn != NULL); + if (!sock) { + return; + } for (i = 0; i < LWIP_SOCKET_MAX_MEMBERSHIPS; i++) { - if (socket_ipv4_multicast_memberships[i].sa == sa) { + if (socket_ipv4_multicast_memberships[i].sock == sock) { ip_addr_t multi_addr, if_addr; ip_addr_copy_from_ip4(multi_addr, socket_ipv4_multicast_memberships[i].multi_addr); ip_addr_copy_from_ip4(if_addr, socket_ipv4_multicast_memberships[i].if_addr); - socket_ipv4_multicast_memberships[i].sa = 0; + socket_ipv4_multicast_memberships[i].sock = NULL; ip4_addr_set_zero(&socket_ipv4_multicast_memberships[i].if_addr); ip4_addr_set_zero(&socket_ipv4_multicast_memberships[i].multi_addr); From 9ba9dee2aa809624eda0e96c96abd8abff29539e Mon Sep 17 00:00:00 2001 From: David van Moolenbroek Date: Mon, 19 Sep 2016 11:33:34 +0000 Subject: [PATCH 273/325] tcp: advance next seq nr for zero window probes It is possible that the byte sent as a zero window probe is accepted and acknowledged by the receiver side without the window being opened. In that case, the stream has effectively advanced by one byte, and since lwIP did not take this into account on the sender side, the result was a desynchronization between the sender and the receiver. That situation could occur even on a lwIP loopback device, after filling up the receiver side's receive buffer, and resulted in an ACK storm. This patch corrects the problem by advancing the sender's next sequence number by one as needed when sending a zero window probe. --- src/core/tcp_out.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/core/tcp_out.c b/src/core/tcp_out.c index 70bdfea5..78ff0a1a 100644 --- a/src/core/tcp_out.c +++ b/src/core/tcp_out.c @@ -1537,6 +1537,7 @@ tcp_zero_window_probe(struct tcp_pcb *pcb) struct tcp_seg *seg; u16_t len; u8_t is_fin; + u32_t snd_nxt; struct netif *netif; LWIP_DEBUGF(TCP_DEBUG, ("tcp_zero_window_probe: sending ZERO WINDOW probe to ")); @@ -1581,6 +1582,12 @@ tcp_zero_window_probe(struct tcp_pcb *pcb) pbuf_copy_partial(seg->p, d, 1, seg->p->tot_len - seg->len); } + /* The byte may be acknowledged without the window being opened. */ + snd_nxt = ntohl(seg->tcphdr->seqno) + 1; + if (TCP_SEQ_LT(pcb->snd_nxt, snd_nxt)) { + pcb->snd_nxt = snd_nxt; + } + netif = ip_route(&pcb->local_ip, &pcb->remote_ip); if (netif == NULL) { err = ERR_RTE; From 0d7805a86a538404ea89a51f85dd16cd435cecbe Mon Sep 17 00:00:00 2001 From: David van Moolenbroek Date: Thu, 29 Sep 2016 19:31:22 +0000 Subject: [PATCH 274/325] tcp: fix FIN ACK handling with unsent data TCP's snd_nxt represents the next sequence number after sent data, and as such does not cover any unsent data queued on the connection. The current implementation does not take the latter point into account when processing FIN acknowledgments, mistakenly assuming that an outgoing FIN is ACK'ed when the acknowledgment covers up to snd_nxt while there is still unsent data. This patch adds a check for unsent data to correct this, effectively preventing that TCP connections are closed prematurely. --- src/core/tcp_in.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/core/tcp_in.c b/src/core/tcp_in.c index dd88e1e5..1ee0e127 100644 --- a/src/core/tcp_in.c +++ b/src/core/tcp_in.c @@ -886,7 +886,8 @@ tcp_process(struct tcp_pcb *pcb) case FIN_WAIT_1: tcp_receive(pcb); if (recv_flags & TF_GOT_FIN) { - if ((flags & TCP_ACK) && (ackno == pcb->snd_nxt)) { + if ((flags & TCP_ACK) && (ackno == pcb->snd_nxt) && + pcb->unsent == NULL) { LWIP_DEBUGF(TCP_DEBUG, ("TCP connection closed: FIN_WAIT_1 %"U16_F" -> %"U16_F".\n", inseg.tcphdr->src, inseg.tcphdr->dest)); tcp_ack_now(pcb); @@ -898,7 +899,8 @@ tcp_process(struct tcp_pcb *pcb) tcp_ack_now(pcb); pcb->state = CLOSING; } - } else if ((flags & TCP_ACK) && (ackno == pcb->snd_nxt)) { + } else if ((flags & TCP_ACK) && (ackno == pcb->snd_nxt) && + pcb->unsent == NULL) { pcb->state = FIN_WAIT_2; } break; @@ -915,7 +917,7 @@ tcp_process(struct tcp_pcb *pcb) break; case CLOSING: tcp_receive(pcb); - if (flags & TCP_ACK && ackno == pcb->snd_nxt) { + if (flags & TCP_ACK && ackno == pcb->snd_nxt && pcb->unsent == NULL) { LWIP_DEBUGF(TCP_DEBUG, ("TCP connection closed: CLOSING %"U16_F" -> %"U16_F".\n", inseg.tcphdr->src, inseg.tcphdr->dest)); tcp_pcb_purge(pcb); TCP_RMV_ACTIVE(pcb); @@ -925,7 +927,7 @@ tcp_process(struct tcp_pcb *pcb) break; case LAST_ACK: tcp_receive(pcb); - if (flags & TCP_ACK && ackno == pcb->snd_nxt) { + if (flags & TCP_ACK && ackno == pcb->snd_nxt && pcb->unsent == NULL) { LWIP_DEBUGF(TCP_DEBUG, ("TCP connection closed: LAST_ACK %"U16_F" -> %"U16_F".\n", inseg.tcphdr->src, inseg.tcphdr->dest)); /* bugfix #21699: don't set pcb->state to CLOSED here or we risk leaking segments */ recv_flags |= TF_CLOSED; From 60a507f88b3812a0696fd70bff74e422cf057b3e Mon Sep 17 00:00:00 2001 From: Elias Reichart Date: Fri, 30 Sep 2016 21:40:10 +0200 Subject: [PATCH 275/325] ETHARP_TABLE_MATCH_NETIF is also used in the etharp_output shortcut --- src/core/ipv4/etharp.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/core/ipv4/etharp.c b/src/core/ipv4/etharp.c index 364023e4..2040f390 100644 --- a/src/core/ipv4/etharp.c +++ b/src/core/ipv4/etharp.c @@ -875,6 +875,9 @@ etharp_output(struct netif *netif, struct pbuf *q, const ip4_addr_t *ipaddr) if (etharp_cached_entry < ARP_TABLE_SIZE) { #endif /* LWIP_NETIF_HWADDRHINT */ if ((arp_table[etharp_cached_entry].state >= ETHARP_STATE_STABLE) && +#if ETHARP_TABLE_MATCH_NETIF + (arp_table[etharp_cached_entry].netif == netif) && +#endif (ip4_addr_cmp(dst_addr, &arp_table[etharp_cached_entry].ipaddr))) { /* the per-pcb-cached entry is stable and the right one! */ ETHARP_STATS_INC(etharp.cachehit); @@ -889,6 +892,9 @@ etharp_output(struct netif *netif, struct pbuf *q, const ip4_addr_t *ipaddr) throughput and etharp_find_entry() is kind of slow */ for (i = 0; i < ARP_TABLE_SIZE; i++) { if ((arp_table[i].state >= ETHARP_STATE_STABLE) && +#if ETHARP_TABLE_MATCH_NETIF + (arp_table[i].netif == netif) && +#endif (ip4_addr_cmp(dst_addr, &arp_table[i].ipaddr))) { /* found an existing, stable entry */ ETHARP_SET_HINT(netif, i); From 87172d6d35708b1dac6beab760cbe2a4c3c1d558 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Wed, 5 Oct 2016 15:02:59 +0800 Subject: [PATCH 276/325] mdns: Use NETIF_TO_HOST at appropriate places Trivial cleanup, use NETIF_TO_HOST macro to get mdns_host from netif. Signed-off-by: Axel Lin --- src/apps/mdns/mdns.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/apps/mdns/mdns.c b/src/apps/mdns/mdns.c index 085bebd4..d9ef9a3e 100644 --- a/src/apps/mdns/mdns.c +++ b/src/apps/mdns/mdns.c @@ -1457,7 +1457,7 @@ mdns_announce(struct netif *netif, const ip_addr_t *destination) { struct mdns_outpacket announce; int i; - struct mdns_host* mdns = (struct mdns_host*)netif->client_data[mdns_netif_client_id]; + struct mdns_host* mdns = NETIF_TO_HOST(netif); memset(&announce, 0, sizeof(announce)); announce.netif = netif; @@ -1502,7 +1502,7 @@ mdns_handle_question(struct mdns_packet *pkt) int replies = 0; int i; err_t res; - struct mdns_host* mdns = (struct mdns_host*)pkt->netif->client_data[mdns_netif_client_id]; + struct mdns_host* mdns = NETIF_TO_HOST(pkt->netif); mdns_init_outpacket(&reply, pkt); @@ -1924,7 +1924,7 @@ mdns_resp_remove_netif(struct netif *netif) struct mdns_host* mdns; LWIP_ASSERT("mdns_resp_remove_netif: Null pointer", netif); - mdns = (struct mdns_host*)netif->client_data[mdns_netif_client_id]; + mdns = NETIF_TO_HOST(netif); LWIP_ERROR("mdns_resp_remove_netif: Not an active netif", (mdns != NULL), return ERR_VAL); for (i = 0; i < MDNS_MAX_SERVICES; i++) { @@ -1971,7 +1971,7 @@ mdns_resp_add_service(struct netif *netif, const char *name, const char *service struct mdns_host* mdns; LWIP_ASSERT("mdns_resp_add_service: netif != NULL", netif); - mdns = (struct mdns_host*)netif->client_data[mdns_netif_client_id]; + mdns = NETIF_TO_HOST(netif); LWIP_ERROR("mdns_resp_add_service: Not an mdns netif", (mdns != NULL), return ERR_VAL); LWIP_ERROR("mdns_resp_add_service: Name too long", (strlen(name) <= MDNS_LABEL_MAXLEN), return ERR_VAL); From fa211096c2ae892263152a3168eada8211d95e44 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Wed, 5 Oct 2016 21:02:46 +0200 Subject: [PATCH 277/325] Fix macro name clash with windows headers in TFTP server Reported by Gisle Vanem --- src/apps/tftp/tftp_server.c | 70 ++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/src/apps/tftp/tftp_server.c b/src/apps/tftp/tftp_server.c index ea7e7246..b96031c4 100644 --- a/src/apps/tftp/tftp_server.c +++ b/src/apps/tftp/tftp_server.c @@ -58,20 +58,20 @@ #define TFTP_MAX_PAYLOAD_SIZE 512 #define TFTP_HEADER_LENGTH 4 -#define RRQ 1 -#define WRQ 2 -#define DATA 3 -#define ACK 4 -#define ERROR 5 +#define TFTP_RRQ 1 +#define TFTP_WRQ 2 +#define TFTP_DATA 3 +#define TFTP_ACK 4 +#define TFTP_ERROR 5 enum tftp_error { - ERROR_FILE_NOT_FOUND = 1, - ERROR_ACCESS_VIOLATION = 2, - ERROR_DISK_FULL = 3, - ERROR_ILLEGAL_OPERATION = 4, - ERROR_UNKNOWN_TRFR_ID = 5, - ERROR_FILE_EXISTS = 6, - ERROR_NO_SUCH_USER = 7 + TFTP_ERROR_FILE_NOT_FOUND = 1, + TFTP_ERROR_ACCESS_VIOLATION = 2, + TFTP_ERROR_DISK_FULL = 3, + TFTP_ERROR_ILLEGAL_OPERATION = 4, + TFTP_ERROR_UNKNOWN_TRFR_ID = 5, + TFTP_ERROR_FILE_EXISTS = 6, + TFTP_ERROR_NO_SUCH_USER = 7 }; #include @@ -127,7 +127,7 @@ send_error(const ip_addr_t *addr, u16_t port, enum tftp_error code, const char * } payload = (u16_t*) p->payload; - payload[0] = PP_HTONS(ERROR); + payload[0] = PP_HTONS(TFTP_ERROR); payload[1] = htons(code); MEMCPY(&payload[2], str, str_length + 1); @@ -147,7 +147,7 @@ send_ack(u16_t blknum) } payload = (u16_t*) p->payload; - payload[0] = PP_HTONS(ACK); + payload[0] = PP_HTONS(TFTP_ACK); payload[1] = htons(blknum); udp_sendto(tftp_state.upcb, p, &tftp_state.addr, tftp_state.port); pbuf_free(p); @@ -186,12 +186,12 @@ send_data(void) } payload = (u16_t *) tftp_state.last_data->payload; - payload[0] = PP_HTONS(DATA); + payload[0] = PP_HTONS(TFTP_DATA); payload[1] = htons(tftp_state.blknum); ret = tftp_state.ctx->read(tftp_state.handle, &payload[2], TFTP_MAX_PAYLOAD_SIZE); if (ret < 0) { - send_error(&tftp_state.addr, tftp_state.port, ERROR_ACCESS_VIOLATION, "Error occured while reading the file."); + send_error(&tftp_state.addr, tftp_state.port, TFTP_ERROR_ACCESS_VIOLATION, "Error occured while reading the file."); close_handle(); return; } @@ -211,7 +211,7 @@ recv(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16 if (((tftp_state.port != 0) && (port != tftp_state.port)) || (!ip_addr_isany_val(tftp_state.addr) && !ip_addr_cmp(&tftp_state.addr, addr))) { - send_error(addr, port, ERROR_ACCESS_VIOLATION, "Only one connection at a time is supported"); + send_error(addr, port, TFTP_ERROR_ACCESS_VIOLATION, "Only one connection at a time is supported"); pbuf_free(p); return; } @@ -222,8 +222,8 @@ recv(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16 tftp_state.retries = 0; switch (opcode) { - case PP_HTONS(RRQ): /* fall through */ - case PP_HTONS(WRQ): + case PP_HTONS(TFTP_RRQ): /* fall through */ + case PP_HTONS(TFTP_WRQ): { const char tftp_null = 0; char filename[TFTP_MAX_FILENAME_LEN]; @@ -232,7 +232,7 @@ recv(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16 u16_t mode_end_offset; if(tftp_state.handle != NULL) { - send_error(addr, port, ERROR_ACCESS_VIOLATION, "Only one connection at a time is supported"); + send_error(addr, port, TFTP_ERROR_ACCESS_VIOLATION, "Only one connection at a time is supported"); break; } @@ -241,7 +241,7 @@ recv(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16 /* find \0 in pbuf -> end of filename string */ filename_end_offset = pbuf_memfind(p, &tftp_null, sizeof(tftp_null), 2); if((u16_t)(filename_end_offset-2) > sizeof(filename)) { - send_error(addr, port, ERROR_ACCESS_VIOLATION, "Filename too long/not NULL terminated"); + send_error(addr, port, TFTP_ERROR_ACCESS_VIOLATION, "Filename too long/not NULL terminated"); break; } pbuf_copy_partial(p, filename, filename_end_offset-2, 2); @@ -249,27 +249,27 @@ recv(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16 /* find \0 in pbuf -> end of mode string */ mode_end_offset = pbuf_memfind(p, &tftp_null, sizeof(tftp_null), filename_end_offset+1); if((u16_t)(mode_end_offset-filename_end_offset) > sizeof(mode)) { - send_error(addr, port, ERROR_ACCESS_VIOLATION, "Mode too long/not NULL terminated"); + send_error(addr, port, TFTP_ERROR_ACCESS_VIOLATION, "Mode too long/not NULL terminated"); break; } pbuf_copy_partial(p, mode, mode_end_offset-filename_end_offset, filename_end_offset+1); - tftp_state.handle = tftp_state.ctx->open(filename, mode, opcode == PP_HTONS(WRQ)); + tftp_state.handle = tftp_state.ctx->open(filename, mode, opcode == PP_HTONS(TFTP_WRQ)); tftp_state.blknum = 1; if (!tftp_state.handle) { - send_error(addr, port, ERROR_FILE_NOT_FOUND, "Unable to open requested file."); + send_error(addr, port, TFTP_ERROR_FILE_NOT_FOUND, "Unable to open requested file."); break; } - LWIP_DEBUGF(TFTP_DEBUG | LWIP_DBG_STATE, ("tftp: %s request from ", (opcode == PP_HTONS(WRQ)) ? "write" : "read")); + LWIP_DEBUGF(TFTP_DEBUG | LWIP_DBG_STATE, ("tftp: %s request from ", (opcode == PP_HTONS(TFTP_WRQ)) ? "write" : "read")); ip_addr_debug_print(TFTP_DEBUG | LWIP_DBG_STATE, addr); LWIP_DEBUGF(TFTP_DEBUG | LWIP_DBG_STATE, (" for '%s' mode '%s'\n", filename, mode)); ip_addr_copy(tftp_state.addr, *addr); tftp_state.port = port; - if (opcode == PP_HTONS(WRQ)) { + if (opcode == PP_HTONS(TFTP_WRQ)) { tftp_state.mode_write = 1; send_ack(0); } else { @@ -280,18 +280,18 @@ recv(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16 break; } - case PP_HTONS(DATA): + case PP_HTONS(TFTP_DATA): { int ret; u16_t blknum; if (tftp_state.handle == NULL) { - send_error(addr, port, ERROR_ACCESS_VIOLATION, "No connection"); + send_error(addr, port, TFTP_ERROR_ACCESS_VIOLATION, "No connection"); break; } if (tftp_state.mode_write != 1) { - send_error(addr, port, ERROR_ACCESS_VIOLATION, "Not a write connection"); + send_error(addr, port, TFTP_ERROR_ACCESS_VIOLATION, "Not a write connection"); break; } @@ -300,7 +300,7 @@ recv(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16 ret = tftp_state.ctx->write(tftp_state.handle, p); if (ret < 0) { - send_error(addr, port, ERROR_ACCESS_VIOLATION, "error writing file"); + send_error(addr, port, TFTP_ERROR_ACCESS_VIOLATION, "error writing file"); close_handle(); } else { send_ack(blknum); @@ -312,24 +312,24 @@ recv(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16 break; } - case PP_HTONS(ACK): + case PP_HTONS(TFTP_ACK): { u16_t blknum; int lastpkt; if (tftp_state.handle == NULL) { - send_error(addr, port, ERROR_ACCESS_VIOLATION, "No connection"); + send_error(addr, port, TFTP_ERROR_ACCESS_VIOLATION, "No connection"); break; } if (tftp_state.mode_write != 0) { - send_error(addr, port, ERROR_ACCESS_VIOLATION, "Not a read connection"); + send_error(addr, port, TFTP_ERROR_ACCESS_VIOLATION, "Not a read connection"); break; } blknum = ntohs(sbuf[1]); if (blknum != tftp_state.blknum) { - send_error(addr, port, ERROR_UNKNOWN_TRFR_ID, "Wrong block number"); + send_error(addr, port, TFTP_ERROR_UNKNOWN_TRFR_ID, "Wrong block number"); break; } @@ -350,7 +350,7 @@ recv(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16 } default: - send_error(addr, port, ERROR_ILLEGAL_OPERATION, "Unknown operation"); + send_error(addr, port, TFTP_ERROR_ILLEGAL_OPERATION, "Unknown operation"); break; } From 50e09ccd2c7310348f8ab7d3f57ae0608e72c0bc Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Thu, 6 Oct 2016 09:22:16 +0200 Subject: [PATCH 278/325] Add note about new abstactions for itoa(), strnicmp(), stricmp() and strnstr() to UPGRADING document --- UPGRADING | 3 +++ 1 file changed, 3 insertions(+) diff --git a/UPGRADING b/UPGRADING index 2190ec98..d2cd1f26 100644 --- a/UPGRADING +++ b/UPGRADING @@ -46,6 +46,9 @@ with newer versions. * Added LWIP_NETCONN_SEM_PER_THREAD to use one "op_completed" semaphore per thread instead of using one per netconn (these semaphores are used even with core locking enabled as some longer lasting functions like big writes still need to delay) + * Added generalized abstraction for itoa(), strnicmp(), stricmp() and strnstr() + in def.h (to be overridden in cc.h) instead of config + options for netbiosns, httpd, dns, etc. ... +++ new options: * TODO From 0c0607381950c3169c7f3fc3eae8ed1b0ffb1ffd Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Thu, 6 Oct 2016 09:26:59 +0200 Subject: [PATCH 279/325] Avoid code duplication in def.c --- src/core/def.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/core/def.c b/src/core/def.c index c0cfba3b..68137ed6 100644 --- a/src/core/def.c +++ b/src/core/def.c @@ -62,7 +62,7 @@ u16_t lwip_htons(u16_t n) { - return ((n & 0xff) << 8) | ((n & 0xff00) >> 8); + return (u16_t)PP_HTONS(n); } /** @@ -86,10 +86,7 @@ lwip_ntohs(u16_t n) u32_t lwip_htonl(u32_t n) { - return ((n & 0xff) << 24) | - ((n & 0xff00) << 8) | - ((n & 0xff0000UL) >> 8) | - ((n & 0xff000000UL) >> 24); + return (u32_t)PP_HTONL(n); } /** From 13fb616bb260057f481c5ed93396650b4d9dbf84 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Thu, 6 Oct 2016 12:55:57 +0200 Subject: [PATCH 280/325] Cleanup hton*/ntoh* function handling and platform abstraction Let lwip use functions/macros prefixed by lwip_ internally to avoid naming clashes with external #includes. Remove over-complicated #define handling in def.h Make functions easier to override in cc.h. The following is sufficient now (no more LWIP_PLATFORM_BYTESWAP): #define lwip_htons(x) #define lwip_htonl(x) --- doc/rawapi.txt | 5 +- src/api/netdb.c | 4 +- src/api/sockets.c | 8 +-- src/apps/lwiperf/lwiperf.c | 6 +-- src/apps/mdns/mdns.c | 44 ++++++++-------- src/apps/sntp/sntp.c | 8 +-- src/apps/tftp/tftp_server.c | 10 ++-- src/core/def.c | 39 ++++---------- src/core/dns.c | 16 +++--- src/core/inet_chksum.c | 14 ++--- src/core/ipv4/autoip.c | 6 +-- src/core/ipv4/dhcp.c | 30 +++++------ src/core/ipv4/etharp.c | 6 +-- src/core/ipv4/ip4.c | 28 +++++----- src/core/ipv4/ip4_addr.c | 2 +- src/core/ipv4/ip4_frag.c | 22 ++++---- src/core/ipv6/ip6_addr.c | 6 +-- src/core/ipv6/ip6_frag.c | 10 ++-- src/core/ipv6/nd6.c | 14 ++--- src/core/netif.c | 4 +- src/core/tcp.c | 10 ++-- src/core/tcp_in.c | 30 +++++------ src/core/tcp_out.c | 72 +++++++++++++------------- src/core/udp.c | 22 ++++---- src/include/lwip/def.h | 42 +++------------ src/include/lwip/inet_chksum.h | 8 +-- src/include/lwip/ip4_addr.h | 6 +-- src/include/lwip/ip6_addr.h | 32 ++++++------ src/include/lwip/priv/tcp_priv.h | 2 +- src/include/lwip/prot/ethernet.h | 2 +- src/include/lwip/prot/ip6.h | 12 ++--- src/include/lwip/prot/tcp.h | 14 ++--- src/include/netif/ppp/eui64.h | 2 +- src/include/netif/ppp/mppe.h | 2 +- src/netif/ethernet.c | 8 +-- src/netif/lowpan6.c | 62 +++++++++++----------- src/netif/ppp/auth.c | 10 ++-- src/netif/ppp/ipcp.c | 88 ++++++++++++++++---------------- src/netif/ppp/ipv6cp.c | 4 +- src/netif/ppp/multilink.c | 4 +- src/netif/ppp/ppp.c | 4 +- src/netif/ppp/pppoe.c | 14 ++--- src/netif/ppp/utils.c | 2 +- src/netif/ppp/vj.c | 62 +++++++++++----------- 44 files changed, 370 insertions(+), 426 deletions(-) diff --git a/doc/rawapi.txt b/doc/rawapi.txt index 763a0efc..9a5c3e00 100644 --- a/doc/rawapi.txt +++ b/doc/rawapi.txt @@ -456,9 +456,8 @@ introduction to this subject. Other significant improvements can be made by supplying assembly or inline replacements for htons() and htonl() if you're using a little-endian architecture. -#define LWIP_PLATFORM_BYTESWAP 1 -#define LWIP_PLATFORM_HTONS(x) -#define LWIP_PLATFORM_HTONL(x) +#define lwip_htons(x) +#define lwip_htonl(x) Check your network interface driver if it reads at a higher speed than the maximum wire-speed. If the diff --git a/src/api/netdb.c b/src/api/netdb.c index 670f6b97..ef0c79b1 100644 --- a/src/api/netdb.c +++ b/src/api/netdb.c @@ -375,7 +375,7 @@ lwip_getaddrinfo(const char *nodename, const char *servname, inet6_addr_from_ip6addr(&sa6->sin6_addr, ip_2_ip6(&addr)); sa6->sin6_family = AF_INET6; sa6->sin6_len = sizeof(struct sockaddr_in6); - sa6->sin6_port = htons((u16_t)port_nr); + sa6->sin6_port = lwip_htons((u16_t)port_nr); ai->ai_family = AF_INET6; #endif /* LWIP_IPV6 */ } else { @@ -385,7 +385,7 @@ lwip_getaddrinfo(const char *nodename, const char *servname, inet_addr_from_ipaddr(&sa4->sin_addr, ip_2_ip4(&addr)); sa4->sin_family = AF_INET; sa4->sin_len = sizeof(struct sockaddr_in); - sa4->sin_port = htons((u16_t)port_nr); + sa4->sin_port = lwip_htons((u16_t)port_nr); ai->ai_family = AF_INET; #endif /* LWIP_IPV4 */ } diff --git a/src/api/sockets.c b/src/api/sockets.c index dbf91399..87878fb4 100644 --- a/src/api/sockets.c +++ b/src/api/sockets.c @@ -81,25 +81,25 @@ #define IP4ADDR_PORT_TO_SOCKADDR(sin, ipaddr, port) do { \ (sin)->sin_len = sizeof(struct sockaddr_in); \ (sin)->sin_family = AF_INET; \ - (sin)->sin_port = htons((port)); \ + (sin)->sin_port = lwip_htons((port)); \ inet_addr_from_ipaddr(&(sin)->sin_addr, ipaddr); \ memset((sin)->sin_zero, 0, SIN_ZERO_LEN); }while(0) #define SOCKADDR4_TO_IP4ADDR_PORT(sin, ipaddr, port) do { \ inet_addr_to_ipaddr(ip_2_ip4(ipaddr), &((sin)->sin_addr)); \ - (port) = ntohs((sin)->sin_port); }while(0) + (port) = lwip_ntohs((sin)->sin_port); }while(0) #endif /* LWIP_IPV4 */ #if LWIP_IPV6 #define IP6ADDR_PORT_TO_SOCKADDR(sin6, ipaddr, port) do { \ (sin6)->sin6_len = sizeof(struct sockaddr_in6); \ (sin6)->sin6_family = AF_INET6; \ - (sin6)->sin6_port = htons((port)); \ + (sin6)->sin6_port = lwip_htons((port)); \ (sin6)->sin6_flowinfo = 0; \ inet6_addr_from_ip6addr(&(sin6)->sin6_addr, ipaddr); \ (sin6)->sin6_scope_id = 0; }while(0) #define SOCKADDR6_TO_IP6ADDR_PORT(sin6, ipaddr, port) do { \ inet6_addr_to_ip6addr(ip_2_ip6(ipaddr), &((sin6)->sin6_addr)); \ - (port) = ntohs((sin6)->sin6_port); }while(0) + (port) = lwip_ntohs((sin6)->sin6_port); }while(0) #endif /* LWIP_IPV6 */ #if LWIP_IPV4 && LWIP_IPV6 diff --git a/src/apps/lwiperf/lwiperf.c b/src/apps/lwiperf/lwiperf.c index 255e282a..1996cd1a 100644 --- a/src/apps/lwiperf/lwiperf.c +++ b/src/apps/lwiperf/lwiperf.c @@ -262,7 +262,7 @@ lwiperf_tcp_client_send_more(lwiperf_state_tcp_t* conn) /* this session is time-limited */ u32_t now = sys_now(); u32_t diff_ms = now - conn->time_started; - u32_t time = (u32_t)-(s32_t)htonl(conn->settings.amount); + u32_t time = (u32_t)-(s32_t)lwip_htonl(conn->settings.amount); u32_t time_ms = time * 10; if (diff_ms >= time_ms) { /* time specified by the client is over -> close the connection */ @@ -271,7 +271,7 @@ lwiperf_tcp_client_send_more(lwiperf_state_tcp_t* conn) } } else { /* this session is byte-limited */ - u32_t amount_bytes = htonl(conn->settings.amount); + u32_t amount_bytes = lwip_htonl(conn->settings.amount); /* @todo: this can send up to 1*MSS more than requested... */ if (amount_bytes >= conn->bytes_transferred) { /* all requested bytes transferred -> close the connection */ @@ -390,7 +390,7 @@ lwiperf_tx_start(lwiperf_state_tcp_t* conn) tcp_err(newpcb, lwiperf_tcp_err); ip_addr_copy(remote_addr, conn->conn_pcb->remote_ip); - remote_port = (u16_t)htonl(client_conn->settings.remote_port); + remote_port = (u16_t)lwip_htonl(client_conn->settings.remote_port); err = tcp_connect(newpcb, &remote_addr, remote_port, lwiperf_tcp_client_connected); if (err != ERR_OK) { diff --git a/src/apps/mdns/mdns.c b/src/apps/mdns/mdns.c index d9ef9a3e..49bcab5b 100644 --- a/src/apps/mdns/mdns.c +++ b/src/apps/mdns/mdns.c @@ -820,7 +820,7 @@ mdns_write_domain(struct mdns_outpacket *outpkt, struct mdns_domain *domain) } if (jump_offset) { /* Write jump */ - jump = htons(DOMAIN_JUMP | jump_offset); + jump = lwip_htons(DOMAIN_JUMP | jump_offset); res = pbuf_take_at(outpkt->pbuf, &jump, DOMAIN_JUMP_SIZE, outpkt->write_offset); if (res != ERR_OK) { return res; @@ -872,7 +872,7 @@ mdns_add_question(struct mdns_outpacket *outpkt, struct mdns_domain *domain, u16 } /* Write type */ - field16 = htons(type); + field16 = lwip_htons(type); res = pbuf_take_at(outpkt->pbuf, &field16, sizeof(field16), outpkt->write_offset); if (res != ERR_OK) { return res; @@ -883,7 +883,7 @@ mdns_add_question(struct mdns_outpacket *outpkt, struct mdns_domain *domain, u16 if (unicast) { klass |= 0x8000; } - field16 = htons(klass); + field16 = lwip_htons(klass); res = pbuf_take_at(outpkt->pbuf, &field16, sizeof(field16), outpkt->write_offset); if (res != ERR_OK) { return res; @@ -947,7 +947,7 @@ mdns_add_answer(struct mdns_outpacket *reply, struct mdns_domain *domain, u16_t mdns_add_question(reply, domain, type, klass, cache_flush); /* Write TTL */ - field32 = htonl(ttl); + field32 = lwip_htonl(ttl); res = pbuf_take_at(reply->pbuf, &field32, sizeof(field32), reply->write_offset); if (res != ERR_OK) { return res; @@ -977,7 +977,7 @@ mdns_add_answer(struct mdns_outpacket *reply, struct mdns_domain *domain, u16_t } /* Write rd_length after when we know the answer size */ - field16 = htons(reply->write_offset - answer_offset); + field16 = lwip_htons(reply->write_offset - answer_offset); res = pbuf_take_at(reply->pbuf, &field16, sizeof(field16), rdlen_offset); return res; @@ -1005,14 +1005,14 @@ mdns_read_rr_info(struct mdns_packet *pkt, struct mdns_rr_info *info) return ERR_VAL; } pkt->parse_offset += copied; - info->type = ntohs(field16); + info->type = lwip_ntohs(field16); copied = pbuf_copy_partial(pkt->pbuf, &field16, sizeof(field16), pkt->parse_offset); if (copied != sizeof(field16)) { return ERR_VAL; } pkt->parse_offset += copied; - info->klass = ntohs(field16); + info->klass = lwip_ntohs(field16); return ERR_OK; } @@ -1094,14 +1094,14 @@ mdns_read_answer(struct mdns_packet *pkt, struct mdns_answer *answer) return ERR_VAL; } pkt->parse_offset += copied; - answer->ttl = ntohl(ttl); + answer->ttl = lwip_ntohl(ttl); copied = pbuf_copy_partial(pkt->pbuf, &field16, sizeof(field16), pkt->parse_offset); if (copied != sizeof(field16)) { return ERR_VAL; } pkt->parse_offset += copied; - answer->rd_length = ntohs(field16); + answer->rd_length = lwip_ntohs(field16); answer->rd_offset = pkt->parse_offset; pkt->parse_offset += answer->rd_length; @@ -1194,9 +1194,9 @@ mdns_add_srv_answer(struct mdns_outpacket *reply, u16_t cache_flush, struct mdns */ srvhost.skip_compression = 1; } - srvdata[0] = htons(SRV_PRIORITY); - srvdata[1] = htons(SRV_WEIGHT); - srvdata[2] = htons(service->port); + srvdata[0] = lwip_htons(SRV_PRIORITY); + srvdata[1] = lwip_htons(SRV_WEIGHT); + srvdata[2] = lwip_htons(service->port); LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: Responding with SRV record\n")); return mdns_add_answer(reply, &service_instance, DNS_RRTYPE_SRV, DNS_RRCLASS_IN, cache_flush, service->dns_ttl, (const u8_t *) &srvdata, sizeof(srvdata), &srvhost); @@ -1411,11 +1411,11 @@ mdns_send_outpacket(struct mdns_outpacket *outpkt) /* Write header */ memset(&hdr, 0, sizeof(hdr)); hdr.flags1 = DNS_FLAG1_RESPONSE | DNS_FLAG1_AUTHORATIVE; - hdr.numanswers = htons(outpkt->answers); - hdr.numextrarr = htons(outpkt->additional); + hdr.numanswers = lwip_htons(outpkt->answers); + hdr.numextrarr = lwip_htons(outpkt->additional); if (outpkt->legacy_query) { - hdr.numquestions = htons(1); - hdr.id = htons(outpkt->tx_id); + hdr.numquestions = lwip_htons(1); + hdr.id = lwip_htons(outpkt->tx_id); } pbuf_take(outpkt->pbuf, &hdr, sizeof(hdr)); @@ -1657,19 +1657,19 @@ mdns_handle_question(struct mdns_packet *pkt) do { /* Check priority field */ len = pbuf_copy_partial(pkt->pbuf, &field16, sizeof(field16), read_pos); - if (len != sizeof(field16) || ntohs(field16) != SRV_PRIORITY) { + if (len != sizeof(field16) || lwip_ntohs(field16) != SRV_PRIORITY) { break; } read_pos += len; /* Check weight field */ len = pbuf_copy_partial(pkt->pbuf, &field16, sizeof(field16), read_pos); - if (len != sizeof(field16) || ntohs(field16) != SRV_WEIGHT) { + if (len != sizeof(field16) || lwip_ntohs(field16) != SRV_WEIGHT) { break; } read_pos += len; /* Check port field */ len = pbuf_copy_partial(pkt->pbuf, &field16, sizeof(field16), read_pos); - if (len != sizeof(field16) || ntohs(field16) != service->port) { + if (len != sizeof(field16) || lwip_ntohs(field16) != service->port) { break; } read_pos += len; @@ -1780,9 +1780,9 @@ mdns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, packet.netif = recv_netif; packet.pbuf = p; packet.parse_offset = offset; - packet.tx_id = ntohs(hdr.id); - packet.questions = packet.questions_left = ntohs(hdr.numquestions); - packet.answers = packet.answers_left = ntohs(hdr.numanswers) + ntohs(hdr.numauthrr) + ntohs(hdr.numextrarr); + packet.tx_id = lwip_ntohs(hdr.id); + packet.questions = packet.questions_left = lwip_ntohs(hdr.numquestions); + packet.answers = packet.answers_left = lwip_ntohs(hdr.numanswers) + lwip_ntohs(hdr.numauthrr) + lwip_ntohs(hdr.numextrarr); #if LWIP_IPV6 if (IP_IS_V6(ip_current_dest_addr())) { diff --git a/src/apps/sntp/sntp.c b/src/apps/sntp/sntp.c index 9f8a1dc8..fb952111 100644 --- a/src/apps/sntp/sntp.c +++ b/src/apps/sntp/sntp.c @@ -212,13 +212,13 @@ sntp_process(u32_t *receive_timestamp) /* convert SNTP time (1900-based) to unix GMT time (1970-based) * if MSB is 0, SNTP time is 2036-based! */ - u32_t rx_secs = ntohl(receive_timestamp[0]); + u32_t rx_secs = lwip_ntohl(receive_timestamp[0]); int is_1900_based = ((rx_secs & 0x80000000) != 0); u32_t t = is_1900_based ? (rx_secs - DIFF_SEC_1900_1970) : (rx_secs + DIFF_SEC_1970_2036); time_t tim = t; #if SNTP_CALC_TIME_US - u32_t us = ntohl(receive_timestamp[1]) / 4295; + u32_t us = lwip_ntohl(receive_timestamp[1]) / 4295; SNTP_SET_SYSTEM_TIME_US(t, us); /* display local time from GMT time */ LWIP_DEBUGF(SNTP_DEBUG_TRACE, ("sntp_process: %s, %"U32_F" us", ctime(&tim), us)); @@ -247,10 +247,10 @@ sntp_initialize_request(struct sntp_msg *req) u32_t sntp_time_sec, sntp_time_us; /* fill in transmit timestamp and save it in 'sntp_last_timestamp_sent' */ SNTP_GET_SYSTEM_TIME(sntp_time_sec, sntp_time_us); - sntp_last_timestamp_sent[0] = htonl(sntp_time_sec + DIFF_SEC_1900_1970); + sntp_last_timestamp_sent[0] = lwip_htonl(sntp_time_sec + DIFF_SEC_1900_1970); req->transmit_timestamp[0] = sntp_last_timestamp_sent[0]; /* we send/save us instead of fraction to be faster... */ - sntp_last_timestamp_sent[1] = htonl(sntp_time_us); + sntp_last_timestamp_sent[1] = lwip_htonl(sntp_time_us); req->transmit_timestamp[1] = sntp_last_timestamp_sent[1]; } #endif /* SNTP_CHECK_RESPONSE >= 2 */ diff --git a/src/apps/tftp/tftp_server.c b/src/apps/tftp/tftp_server.c index b96031c4..243b0924 100644 --- a/src/apps/tftp/tftp_server.c +++ b/src/apps/tftp/tftp_server.c @@ -128,7 +128,7 @@ send_error(const ip_addr_t *addr, u16_t port, enum tftp_error code, const char * payload = (u16_t*) p->payload; payload[0] = PP_HTONS(TFTP_ERROR); - payload[1] = htons(code); + payload[1] = lwip_htons(code); MEMCPY(&payload[2], str, str_length + 1); udp_sendto(tftp_state.upcb, p, addr, port); @@ -148,7 +148,7 @@ send_ack(u16_t blknum) payload = (u16_t*) p->payload; payload[0] = PP_HTONS(TFTP_ACK); - payload[1] = htons(blknum); + payload[1] = lwip_htons(blknum); udp_sendto(tftp_state.upcb, p, &tftp_state.addr, tftp_state.port); pbuf_free(p); } @@ -187,7 +187,7 @@ send_data(void) payload = (u16_t *) tftp_state.last_data->payload; payload[0] = PP_HTONS(TFTP_DATA); - payload[1] = htons(tftp_state.blknum); + payload[1] = lwip_htons(tftp_state.blknum); ret = tftp_state.ctx->read(tftp_state.handle, &payload[2], TFTP_MAX_PAYLOAD_SIZE); if (ret < 0) { @@ -295,7 +295,7 @@ recv(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16 break; } - blknum = ntohs(sbuf[1]); + blknum = lwip_ntohs(sbuf[1]); pbuf_header(p, -TFTP_HEADER_LENGTH); ret = tftp_state.ctx->write(tftp_state.handle, p); @@ -327,7 +327,7 @@ recv(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16 break; } - blknum = ntohs(sbuf[1]); + blknum = lwip_ntohs(sbuf[1]); if (blknum != tftp_state.blknum) { send_error(addr, port, TFTP_ERROR_UNKNOWN_TRFR_ID, "Wrong block number"); break; diff --git a/src/core/def.c b/src/core/def.c index 68137ed6..88f5724d 100644 --- a/src/core/def.c +++ b/src/core/def.c @@ -7,11 +7,10 @@ * Byte swapping is the second thing you would want to optimize. You will * need to port it to your architecture and in your cc.h: * - * \#define LWIP_PLATFORM_BYTESWAP 1 - * \#define LWIP_PLATFORM_HTONS(x) your_htons - * \#define LWIP_PLATFORM_HTONL(x) your_htonl + * \#define lwip_htons(x) your_htons + * \#define lwip_htonl(x) your_htonl * - * Note ntohs() and ntohl() are merely references to the htonx counterparts. + * Note lwip_ntohs() and lwip_ntohl() are merely references to the htonx counterparts. */ /* @@ -51,8 +50,9 @@ #include -#if (LWIP_PLATFORM_BYTESWAP == 0) && (BYTE_ORDER == LITTLE_ENDIAN) +#if BYTE_ORDER == LITTLE_ENDIAN +#if !defined(lwip_htons) /** * Convert an u16_t from host- to network byte order. * @@ -64,19 +64,9 @@ lwip_htons(u16_t n) { return (u16_t)PP_HTONS(n); } +#endif /* lwip_htons */ -/** - * Convert an u16_t from network- to host byte order. - * - * @param n u16_t in network byte order - * @return n in host byte order - */ -u16_t -lwip_ntohs(u16_t n) -{ - return lwip_htons(n); -} - +#if !defined(lwip_htonl) /** * Convert an u32_t from host- to network byte order. * @@ -88,20 +78,9 @@ lwip_htonl(u32_t n) { return (u32_t)PP_HTONL(n); } +#endif /* lwip_htonl */ -/** - * Convert an u32_t from network- to host byte order. - * - * @param n u32_t in network byte order - * @return n in host byte order - */ -u32_t -lwip_ntohl(u32_t n) -{ - return lwip_htonl(n); -} - -#endif /* (LWIP_PLATFORM_BYTESWAP == 0) && (BYTE_ORDER == LITTLE_ENDIAN) */ +#endif /* BYTE_ORDER == LITTLE_ENDIAN */ #ifndef lwip_strnstr /** Like strstr but does not need 'buffer' to be NULL-terminated */ diff --git a/src/core/dns.c b/src/core/dns.c index 22368f04..f1b0f436 100644 --- a/src/core/dns.c +++ b/src/core/dns.c @@ -680,7 +680,7 @@ dns_send(u8_t idx) if (p != NULL) { /* fill dns header */ memset(&hdr, 0, SIZEOF_DNS_HDR); - hdr.id = htons(entry->txid); + hdr.id = lwip_htons(entry->txid); hdr.flags1 = DNS_FLAG1_RD; hdr.numquestions = PP_HTONS(1); pbuf_take(p, &hdr, SIZEOF_DNS_HDR); @@ -1041,7 +1041,7 @@ dns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, /* copy dns payload inside static buffer for processing */ if (pbuf_copy_partial(p, &hdr, SIZEOF_DNS_HDR, 0) == SIZEOF_DNS_HDR) { /* Match the ID in the DNS header with the name table. */ - txid = htons(hdr.id); + txid = lwip_htons(hdr.id); for (i = 0; i < DNS_TABLE_SIZE; i++) { const struct dns_table_entry *entry = &dns_table[i]; if ((entry->state == DNS_STATE_ASKING) && @@ -1049,8 +1049,8 @@ dns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, /* We only care about the question(s) and the answers. The authrr and the extrarr are simply discarded. */ - nquestions = htons(hdr.numquestions); - nanswers = htons(hdr.numanswers); + nquestions = lwip_htons(hdr.numquestions); + nanswers = lwip_htons(hdr.numanswers); /* Check for correct response. */ if ((hdr.flags1 & DNS_FLAG1_RESPONSE) == 0) { @@ -1121,7 +1121,7 @@ dns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, ip_addr_copy_from_ip4(dns_table[i].ipaddr, ip4addr); pbuf_free(p); /* handle correct response */ - dns_correct_response(i, ntohl(ans.ttl)); + dns_correct_response(i, lwip_ntohl(ans.ttl)); return; } } @@ -1140,17 +1140,17 @@ dns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, ip_addr_copy_from_ip6(dns_table[i].ipaddr, ip6addr); pbuf_free(p); /* handle correct response */ - dns_correct_response(i, ntohl(ans.ttl)); + dns_correct_response(i, lwip_ntohl(ans.ttl)); return; } } #endif /* LWIP_IPV6 */ } /* skip this answer */ - if ((int)(res_idx + htons(ans.len)) > 0xFFFF) { + if ((int)(res_idx + lwip_htons(ans.len)) > 0xFFFF) { goto memerr; /* ignore this packet */ } - res_idx += htons(ans.len); + res_idx += lwip_htons(ans.len); --nanswers; } #if LWIP_IPV4 && LWIP_IPV6 diff --git a/src/core/inet_chksum.c b/src/core/inet_chksum.c index 6ccf8391..80289528 100644 --- a/src/core/inet_chksum.c +++ b/src/core/inet_chksum.c @@ -108,10 +108,10 @@ lwip_standard_chksum(const void *dataptr, int len) if ((acc & 0xffff0000UL) != 0) { acc = (acc >> 16) + (acc & 0x0000ffffUL); } - /* This maybe a little confusing: reorder sum using htons() - instead of ntohs() since it has a little less call overhead. + /* This maybe a little confusing: reorder sum using lwip_htons() + instead of lwip_ntohs() since it has a little less call overhead. The caller must invert bits for Internet sum ! */ - return htons((u16_t)acc); + return lwip_htons((u16_t)acc); } #endif @@ -283,8 +283,8 @@ inet_cksum_pseudo_base(struct pbuf *p, u8_t proto, u16_t proto_len, u32_t acc) acc = SWAP_BYTES_IN_WORD(acc); } - acc += (u32_t)htons((u16_t)proto); - acc += (u32_t)htons(proto_len); + acc += (u32_t)lwip_htons((u16_t)proto); + acc += (u32_t)lwip_htons(proto_len); /* Fold 32-bit sum to 16 bits calling this twice is probably faster than if statements... */ @@ -429,8 +429,8 @@ inet_cksum_pseudo_partial_base(struct pbuf *p, u8_t proto, u16_t proto_len, acc = SWAP_BYTES_IN_WORD(acc); } - acc += (u32_t)htons((u16_t)proto); - acc += (u32_t)htons(proto_len); + acc += (u32_t)lwip_htons((u16_t)proto); + acc += (u32_t)lwip_htons(proto_len); /* Fold 32-bit sum to 16 bits calling this twice is probably faster than if statements... */ diff --git a/src/core/ipv4/autoip.c b/src/core/ipv4/autoip.c index ad494feb..86a4aed3 100644 --- a/src/core/ipv4/autoip.c +++ b/src/core/ipv4/autoip.c @@ -87,7 +87,7 @@ */ #ifndef LWIP_AUTOIP_CREATE_SEED_ADDR #define LWIP_AUTOIP_CREATE_SEED_ADDR(netif) \ - htonl(AUTOIP_RANGE_START + ((u32_t)(((u8_t)(netif->hwaddr[4])) | \ + lwip_htonl(AUTOIP_RANGE_START + ((u32_t)(((u8_t)(netif->hwaddr[4])) | \ ((u32_t)((u8_t)(netif->hwaddr[5]))) << 8))) #endif /* LWIP_AUTOIP_CREATE_SEED_ADDR */ @@ -176,7 +176,7 @@ autoip_create_addr(struct netif *netif, ip4_addr_t *ipaddr) * compliant to RFC 3927 Section 2.1 * We have 254 * 256 possibilities */ - u32_t addr = ntohl(LWIP_AUTOIP_CREATE_SEED_ADDR(netif)); + u32_t addr = lwip_ntohl(LWIP_AUTOIP_CREATE_SEED_ADDR(netif)); addr += autoip->tried_llipaddr; addr = AUTOIP_NET | (addr & 0xffff); /* Now, 169.254.0.0 <= addr <= 169.254.255.255 */ @@ -189,7 +189,7 @@ autoip_create_addr(struct netif *netif, ip4_addr_t *ipaddr) } LWIP_ASSERT("AUTOIP address not in range", (addr >= AUTOIP_RANGE_START) && (addr <= AUTOIP_RANGE_END)); - ip4_addr_set_u32(ipaddr, htonl(addr)); + ip4_addr_set_u32(ipaddr, lwip_htonl(addr)); LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("autoip_create_addr(): tried_llipaddr=%"U16_F", %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n", diff --git a/src/core/ipv4/dhcp.c b/src/core/ipv4/dhcp.c index 62a32c52..ecf19bdb 100644 --- a/src/core/ipv4/dhcp.c +++ b/src/core/ipv4/dhcp.c @@ -311,7 +311,7 @@ dhcp_handle_offer(struct netif *netif) (void*)netif, netif->name[0], netif->name[1], (u16_t)netif->num)); /* obtain the server address */ if (dhcp_option_given(dhcp, DHCP_OPTION_IDX_SERVER_ID)) { - ip_addr_set_ip4_u32(&dhcp->server_ip_addr, htonl(dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_SERVER_ID))); + ip_addr_set_ip4_u32(&dhcp->server_ip_addr, lwip_htonl(dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_SERVER_ID))); LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_STATE, ("dhcp_handle_offer(): server 0x%08"X32_F"\n", ip4_addr_get_u32(ip_2_ip4(&dhcp->server_ip_addr)))); /* remember offered address */ @@ -353,10 +353,10 @@ dhcp_select(struct netif *netif) /* MUST request the offered IP address */ dhcp_option(dhcp, DHCP_OPTION_REQUESTED_IP, 4); - dhcp_option_long(dhcp, ntohl(ip4_addr_get_u32(&dhcp->offered_ip_addr))); + dhcp_option_long(dhcp, lwip_ntohl(ip4_addr_get_u32(&dhcp->offered_ip_addr))); dhcp_option(dhcp, DHCP_OPTION_SERVER_ID, 4); - dhcp_option_long(dhcp, ntohl(ip4_addr_get_u32(ip_2_ip4(&dhcp->server_ip_addr)))); + dhcp_option_long(dhcp, lwip_ntohl(ip4_addr_get_u32(ip_2_ip4(&dhcp->server_ip_addr)))); dhcp_option(dhcp, DHCP_OPTION_PARAMETER_REQUEST_LIST, LWIP_ARRAYSIZE(dhcp_discover_request_options)); for (i = 0; i < LWIP_ARRAYSIZE(dhcp_discover_request_options); i++) { @@ -621,7 +621,7 @@ dhcp_handle_ack(struct netif *netif) /* subnet mask given? */ if (dhcp_option_given(dhcp, DHCP_OPTION_IDX_SUBNET_MASK)) { /* remember given subnet mask */ - ip4_addr_set_u32(&dhcp->offered_sn_mask, htonl(dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_SUBNET_MASK))); + ip4_addr_set_u32(&dhcp->offered_sn_mask, lwip_htonl(dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_SUBNET_MASK))); dhcp->subnet_mask_given = 1; } else { dhcp->subnet_mask_given = 0; @@ -629,13 +629,13 @@ dhcp_handle_ack(struct netif *netif) /* gateway router */ if (dhcp_option_given(dhcp, DHCP_OPTION_IDX_ROUTER)) { - ip4_addr_set_u32(&dhcp->offered_gw_addr, htonl(dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_ROUTER))); + ip4_addr_set_u32(&dhcp->offered_gw_addr, lwip_htonl(dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_ROUTER))); } #if LWIP_DHCP_GET_NTP_SRV /* NTP servers */ for (n = 0; (n < LWIP_DHCP_MAX_NTP_SERVERS) && dhcp_option_given(dhcp, DHCP_OPTION_IDX_NTP_SERVER + n); n++) { - ip4_addr_set_u32(&ntp_server_addrs[n], htonl(dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_NTP_SERVER + n))); + ip4_addr_set_u32(&ntp_server_addrs[n], lwip_htonl(dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_NTP_SERVER + n))); } dhcp_set_ntp_servers(n, ntp_server_addrs); #endif /* LWIP_DHCP_GET_NTP_SRV */ @@ -644,7 +644,7 @@ dhcp_handle_ack(struct netif *netif) /* DNS servers */ for (n = 0; (n < DNS_MAX_SERVERS) && dhcp_option_given(dhcp, DHCP_OPTION_IDX_DNS_SERVER + n); n++) { ip_addr_t dns_addr; - ip_addr_set_ip4_u32(&dns_addr, htonl(dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_DNS_SERVER + n))); + ip_addr_set_ip4_u32(&dns_addr, lwip_htonl(dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_DNS_SERVER + n))); dns_setserver(n, &dns_addr); } #endif /* LWIP_DNS */ @@ -913,7 +913,7 @@ dhcp_decline(struct netif *netif) result = dhcp_create_msg(netif, dhcp, DHCP_DECLINE); if (result == ERR_OK) { dhcp_option(dhcp, DHCP_OPTION_REQUESTED_IP, 4); - dhcp_option_long(dhcp, ntohl(ip4_addr_get_u32(&dhcp->offered_ip_addr))); + dhcp_option_long(dhcp, lwip_ntohl(ip4_addr_get_u32(&dhcp->offered_ip_addr))); dhcp_option_trailer(dhcp); /* resize pbuf to reflect true size of options */ @@ -1228,7 +1228,7 @@ dhcp_reboot(struct netif *netif) dhcp_option_short(dhcp, 576); dhcp_option(dhcp, DHCP_OPTION_REQUESTED_IP, 4); - dhcp_option_long(dhcp, ntohl(ip4_addr_get_u32(&dhcp->offered_ip_addr))); + dhcp_option_long(dhcp, lwip_ntohl(ip4_addr_get_u32(&dhcp->offered_ip_addr))); dhcp_option(dhcp, DHCP_OPTION_PARAMETER_REQUEST_LIST, LWIP_ARRAYSIZE(dhcp_discover_request_options)); for (i = 0; i < LWIP_ARRAYSIZE(dhcp_discover_request_options); i++) { @@ -1300,7 +1300,7 @@ dhcp_release(struct netif *netif) result = dhcp_create_msg(netif, dhcp, DHCP_RELEASE); if (result == ERR_OK) { dhcp_option(dhcp, DHCP_OPTION_SERVER_ID, 4); - dhcp_option_long(dhcp, ntohl(ip4_addr_get_u32(ip_2_ip4(&server_ip_addr)))); + dhcp_option_long(dhcp, lwip_ntohl(ip4_addr_get_u32(ip_2_ip4(&server_ip_addr)))); dhcp_option_trailer(dhcp); @@ -1579,13 +1579,13 @@ decode_next: /* decode more than one u32_t */ LWIP_ERROR("decode_len % 4 == 0", decode_len % 4 == 0, return ERR_VAL;); dhcp_got_option(dhcp, decode_idx); - dhcp_set_option_value(dhcp, decode_idx, htonl(value)); + dhcp_set_option_value(dhcp, decode_idx, lwip_htonl(value)); decode_len -= 4; val_offset += 4; decode_idx++; goto decode_next; } else if (decode_len == 4) { - value = ntohl(value); + value = lwip_ntohl(value); } else { LWIP_ERROR("invalid decode_len", decode_len == 1, return ERR_VAL;); value = ((u8_t*)&value)[0]; @@ -1704,9 +1704,9 @@ dhcp_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, } } /* match transaction ID against what we expected */ - if (ntohl(reply_msg->xid) != dhcp->xid) { + if (lwip_ntohl(reply_msg->xid) != dhcp->xid) { LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_WARNING, - ("transaction id mismatch reply_msg->xid(%"X32_F")!=dhcp->xid(%"X32_F")\n",ntohl(reply_msg->xid),dhcp->xid)); + ("transaction id mismatch reply_msg->xid(%"X32_F")!=dhcp->xid(%"X32_F")\n",lwip_ntohl(reply_msg->xid),dhcp->xid)); goto free_pbuf_and_return; } /* option fields could be unfold? */ @@ -1835,7 +1835,7 @@ dhcp_create_msg(struct netif *netif, struct dhcp *dhcp, u8_t message_type) dhcp->msg_out->htype = DHCP_HTYPE_ETH; dhcp->msg_out->hlen = netif->hwaddr_len; dhcp->msg_out->hops = 0; - dhcp->msg_out->xid = htonl(dhcp->xid); + dhcp->msg_out->xid = lwip_htonl(dhcp->xid); dhcp->msg_out->secs = 0; /* we don't need the broadcast flag since we can receive unicast traffic before being fully configured! */ diff --git a/src/core/ipv4/etharp.c b/src/core/ipv4/etharp.c index 2040f390..7b41dd94 100644 --- a/src/core/ipv4/etharp.c +++ b/src/core/ipv4/etharp.c @@ -701,7 +701,7 @@ etharp_input(struct pbuf *p, struct netif *netif) /* Re-use pbuf to send ARP reply. Since we are re-using an existing pbuf, we can't call etharp_raw since that would allocate a new pbuf. */ - hdr->opcode = htons(ARP_REPLY); + hdr->opcode = lwip_htons(ARP_REPLY); IPADDR2_COPY(&hdr->dipaddr, &hdr->sipaddr); IPADDR2_COPY(&hdr->sipaddr, netif_ip4_addr(netif)); @@ -750,7 +750,7 @@ etharp_input(struct pbuf *p, struct netif *netif) #endif /* (LWIP_DHCP && DHCP_DOES_ARP_CHECK) */ break; default: - LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_input: ARP unknown opcode type %"S16_F"\n", htons(hdr->opcode))); + LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_input: ARP unknown opcode type %"S16_F"\n", lwip_htons(hdr->opcode))); ETHARP_STATS_INC(etharp.err); break; } @@ -1144,7 +1144,7 @@ etharp_raw(struct netif *netif, const struct eth_addr *ethsrc_addr, hdr = (struct etharp_hdr *)p->payload; LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_raw: sending raw ARP packet.\n")); - hdr->opcode = htons(opcode); + hdr->opcode = lwip_htons(opcode); LWIP_ASSERT("netif->hwaddr_len must be the same as ETH_HWADDR_LEN for etharp!", (netif->hwaddr_len == ETH_HWADDR_LEN)); diff --git a/src/core/ipv4/ip4.c b/src/core/ipv4/ip4.c index 1f1b3ac0..5ddd9ffe 100644 --- a/src/core/ipv4/ip4.c +++ b/src/core/ipv4/ip4.c @@ -228,7 +228,7 @@ ip4_route(const ip4_addr_t *dest) static int ip4_canforward(struct pbuf *p) { - u32_t addr = htonl(ip4_addr_get_u32(ip4_current_dest_addr())); + u32_t addr = lwip_htonl(ip4_addr_get_u32(ip4_current_dest_addr())); if (p->flags & PBUF_FLAG_LLBCAST) { /* don't route link-layer broadcasts */ @@ -405,7 +405,7 @@ ip4_input(struct pbuf *p, struct netif *inp) /* calculate IP header length in bytes */ iphdr_hlen *= 4; /* obtain ip length in bytes */ - iphdr_len = ntohs(IPH_LEN(iphdr)); + iphdr_len = lwip_ntohs(IPH_LEN(iphdr)); /* Trim pbuf. This is especially required for packets < 60 bytes. */ if (iphdr_len < p->tot_len) { @@ -545,7 +545,7 @@ ip4_input(struct pbuf *p, struct netif *inp) if (IPH_PROTO(iphdr) == IP_PROTO_UDP) { struct udp_hdr *udphdr = (struct udp_hdr *)((u8_t *)iphdr + iphdr_hlen); LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_TRACE, ("ip4_input: UDP packet to DHCP client port %"U16_F"\n", - ntohs(udphdr->dest))); + lwip_ntohs(udphdr->dest))); if (IP_ACCEPT_LINK_LAYER_ADDRESSED_PORT(udphdr->dest)) { LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_TRACE, ("ip4_input: DHCP packet accepted.\n")); netif = inp; @@ -600,7 +600,7 @@ ip4_input(struct pbuf *p, struct netif *inp) if ((IPH_OFFSET(iphdr) & PP_HTONS(IP_OFFMASK | IP_MF)) != 0) { #if IP_REASSEMBLY /* packet fragment reassembly code present? */ LWIP_DEBUGF(IP_DEBUG, ("IP packet is a fragment (id=0x%04"X16_F" tot_len=%"U16_F" len=%"U16_F" MF=%"U16_F" offset=%"U16_F"), calling ip4_reass()\n", - ntohs(IPH_ID(iphdr)), p->tot_len, ntohs(IPH_LEN(iphdr)), (u16_t)!!(IPH_OFFSET(iphdr) & PP_HTONS(IP_MF)), (u16_t)((ntohs(IPH_OFFSET(iphdr)) & IP_OFFMASK)*8))); + lwip_ntohs(IPH_ID(iphdr)), p->tot_len, lwip_ntohs(IPH_LEN(iphdr)), (u16_t)!!(IPH_OFFSET(iphdr) & PP_HTONS(IP_MF)), (u16_t)((lwip_ntohs(IPH_OFFSET(iphdr)) & IP_OFFMASK)*8))); /* reassemble the packet*/ p = ip4_reass(p); /* packet not fully reassembled yet? */ @@ -611,7 +611,7 @@ ip4_input(struct pbuf *p, struct netif *inp) #else /* IP_REASSEMBLY == 0, no packet fragment reassembly code present */ pbuf_free(p); LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("IP packet dropped since it was fragmented (0x%"X16_F") (while IP_REASSEMBLY == 0).\n", - ntohs(IPH_OFFSET(iphdr)))); + lwip_ntohs(IPH_OFFSET(iphdr)))); IP_STATS_INC(ip.opterr); IP_STATS_INC(ip.drop); /* unsupported protocol feature */ @@ -869,12 +869,12 @@ ip4_output_if_opt_src(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *d #if CHECKSUM_GEN_IP_INLINE chk_sum += LWIP_MAKE_U16(tos, iphdr->_v_hl); #endif /* CHECKSUM_GEN_IP_INLINE */ - IPH_LEN_SET(iphdr, htons(p->tot_len)); + IPH_LEN_SET(iphdr, lwip_htons(p->tot_len)); #if CHECKSUM_GEN_IP_INLINE chk_sum += iphdr->_len; #endif /* CHECKSUM_GEN_IP_INLINE */ IPH_OFFSET_SET(iphdr, 0); - IPH_ID_SET(iphdr, htons(ip_id)); + IPH_ID_SET(iphdr, lwip_htons(ip_id)); #if CHECKSUM_GEN_IP_INLINE chk_sum += iphdr->_id; #endif /* CHECKSUM_GEN_IP_INLINE */ @@ -1041,19 +1041,19 @@ ip4_debug_print(struct pbuf *p) (u16_t)IPH_V(iphdr), (u16_t)IPH_HL(iphdr), (u16_t)IPH_TOS(iphdr), - ntohs(IPH_LEN(iphdr)))); + lwip_ntohs(IPH_LEN(iphdr)))); LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n")); LWIP_DEBUGF(IP_DEBUG, ("| %5"U16_F" |%"U16_F"%"U16_F"%"U16_F"| %4"U16_F" | (id, flags, offset)\n", - ntohs(IPH_ID(iphdr)), - (u16_t)(ntohs(IPH_OFFSET(iphdr)) >> 15 & 1), - (u16_t)(ntohs(IPH_OFFSET(iphdr)) >> 14 & 1), - (u16_t)(ntohs(IPH_OFFSET(iphdr)) >> 13 & 1), - (u16_t)(ntohs(IPH_OFFSET(iphdr)) & IP_OFFMASK))); + lwip_ntohs(IPH_ID(iphdr)), + (u16_t)(lwip_ntohs(IPH_OFFSET(iphdr)) >> 15 & 1), + (u16_t)(lwip_ntohs(IPH_OFFSET(iphdr)) >> 14 & 1), + (u16_t)(lwip_ntohs(IPH_OFFSET(iphdr)) >> 13 & 1), + (u16_t)(lwip_ntohs(IPH_OFFSET(iphdr)) & IP_OFFMASK))); LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n")); LWIP_DEBUGF(IP_DEBUG, ("| %3"U16_F" | %3"U16_F" | 0x%04"X16_F" | (ttl, proto, chksum)\n", (u16_t)IPH_TTL(iphdr), (u16_t)IPH_PROTO(iphdr), - ntohs(IPH_CHKSUM(iphdr)))); + lwip_ntohs(IPH_CHKSUM(iphdr)))); LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n")); LWIP_DEBUGF(IP_DEBUG, ("| %3"U16_F" | %3"U16_F" | %3"U16_F" | %3"U16_F" | (src)\n", ip4_addr1_16(&iphdr->src), diff --git a/src/core/ipv4/ip4_addr.c b/src/core/ipv4/ip4_addr.c index d0a81072..eb812afb 100644 --- a/src/core/ipv4/ip4_addr.c +++ b/src/core/ipv4/ip4_addr.c @@ -260,7 +260,7 @@ ip4addr_aton(const char *cp, ip4_addr_t *addr) break; } if (addr) { - ip4_addr_set_u32(addr, htonl(val)); + ip4_addr_set_u32(addr, lwip_htonl(val)); } return 1; } diff --git a/src/core/ipv4/ip4_frag.c b/src/core/ipv4/ip4_frag.c index 8f65b736..dc4c3d45 100644 --- a/src/core/ipv4/ip4_frag.c +++ b/src/core/ipv4/ip4_frag.c @@ -346,8 +346,8 @@ ip_reass_chain_frag_into_datagram_and_validate(struct ip_reassdata *ipr, struct /* Extract length and fragment offset from current fragment */ fraghdr = (struct ip_hdr*)new_p->payload; - len = ntohs(IPH_LEN(fraghdr)) - IPH_HL(fraghdr) * 4; - offset = (ntohs(IPH_OFFSET(fraghdr)) & IP_OFFMASK) * 8; + len = lwip_ntohs(IPH_LEN(fraghdr)) - IPH_HL(fraghdr) * 4; + offset = (lwip_ntohs(IPH_OFFSET(fraghdr)) & IP_OFFMASK) * 8; /* overwrite the fragment's ip header from the pbuf with our helper struct, * and setup the embedded helper structure. */ @@ -500,8 +500,8 @@ ip4_reass(struct pbuf *p) goto nullreturn; } - offset = (ntohs(IPH_OFFSET(fraghdr)) & IP_OFFMASK) * 8; - len = ntohs(IPH_LEN(fraghdr)) - IPH_HL(fraghdr) * 4; + offset = (lwip_ntohs(IPH_OFFSET(fraghdr)) & IP_OFFMASK) * 8; + len = lwip_ntohs(IPH_LEN(fraghdr)) - IPH_HL(fraghdr) * 4; /* Check if we are allowed to enqueue more datagrams. */ clen = pbuf_clen(p); @@ -529,7 +529,7 @@ ip4_reass(struct pbuf *p) fragment into the buffer. */ if (IP_ADDRESSES_AND_ID_MATCH(&ipr->iphdr, fraghdr)) { LWIP_DEBUGF(IP_REASS_DEBUG, ("ip4_reass: matching previous fragment ID=%"X16_F"\n", - ntohs(IPH_ID(fraghdr)))); + lwip_ntohs(IPH_ID(fraghdr)))); IPFRAG_STATS_INC(ip_frag.cachehit); break; } @@ -543,8 +543,8 @@ ip4_reass(struct pbuf *p) goto nullreturn; } } else { - if (((ntohs(IPH_OFFSET(fraghdr)) & IP_OFFMASK) == 0) && - ((ntohs(IPH_OFFSET(&ipr->iphdr)) & IP_OFFMASK) != 0)) { + if (((lwip_ntohs(IPH_OFFSET(fraghdr)) & IP_OFFMASK) == 0) && + ((lwip_ntohs(IPH_OFFSET(&ipr->iphdr)) & IP_OFFMASK) != 0)) { /* ipr->iphdr is not the header from the first fragment, but fraghdr is * -> copy fraghdr into ipr->iphdr since we want to have the header * of the first fragment (for ICMP time exceeded and later, for copying @@ -581,7 +581,7 @@ ip4_reass(struct pbuf *p) /* copy the original ip header back to the first pbuf */ fraghdr = (struct ip_hdr*)(ipr->p->payload); SMEMCPY(fraghdr, &ipr->iphdr, IP_HLEN); - IPH_LEN_SET(fraghdr, htons(ipr->datagram_len)); + IPH_LEN_SET(fraghdr, lwip_htons(ipr->datagram_len)); IPH_OFFSET_SET(fraghdr, 0); IPH_CHKSUM_SET(fraghdr, 0); /* @todo: do we need to set/calculate the correct checksum? */ @@ -706,7 +706,7 @@ ip4_frag(struct pbuf *p, struct netif *netif, const ip4_addr_t *dest) iphdr = original_iphdr; /* Save original offset */ - tmp = ntohs(IPH_OFFSET(iphdr)); + tmp = lwip_ntohs(IPH_OFFSET(iphdr)); ofo = tmp & IP_OFFMASK; omf = tmp & IP_MF; @@ -799,8 +799,8 @@ ip4_frag(struct pbuf *p, struct netif *netif, const ip4_addr_t *dest) #endif /* LWIP_NETIF_TX_SINGLE_PBUF */ /* Correct header */ - IPH_OFFSET_SET(iphdr, htons(tmp)); - IPH_LEN_SET(iphdr, htons(cop + IP_HLEN)); + IPH_OFFSET_SET(iphdr, lwip_htons(tmp)); + IPH_LEN_SET(iphdr, lwip_htons(cop + IP_HLEN)); IPH_CHKSUM_SET(iphdr, 0); #if CHECKSUM_GEN_IP IF__NETIF_CHECKSUM_ENABLED(netif, NETIF_CHECKSUM_GEN_IP) { diff --git a/src/core/ipv6/ip6_addr.c b/src/core/ipv6/ip6_addr.c index 1792f62e..964291ee 100644 --- a/src/core/ipv6/ip6_addr.c +++ b/src/core/ipv6/ip6_addr.c @@ -152,7 +152,7 @@ ip6addr_aton(const char *cp, ip6_addr_t *addr) /* convert to network byte order. */ if (addr) { for (addr_index = 0; addr_index < 4; addr_index++) { - addr->addr[addr_index] = htonl(addr->addr[addr_index]); + addr->addr[addr_index] = lwip_htonl(addr->addr[addr_index]); } } @@ -199,7 +199,7 @@ ip6addr_ntoa_r(const ip6_addr_t *addr, char *buf, int buflen) for (current_block_index = 0; current_block_index < 8; current_block_index++) { /* get the current 16-bit block */ - current_block_value = htonl(addr->addr[current_block_index >> 1]); + current_block_value = lwip_htonl(addr->addr[current_block_index >> 1]); if ((current_block_index & 0x1) == 0) { current_block_value = current_block_value >> 16; } @@ -218,7 +218,7 @@ ip6addr_ntoa_r(const ip6_addr_t *addr, char *buf, int buflen) if (empty_block_flag == 0) { /* generate empty block "::", but only if more than one contiguous zero block, * according to current formatting suggestions RFC 5952. */ - next_block_value = htonl(addr->addr[(current_block_index + 1) >> 1]); + next_block_value = lwip_htonl(addr->addr[(current_block_index + 1) >> 1]); if ((current_block_index & 0x1) == 0x01) { next_block_value = next_block_value >> 16; } diff --git a/src/core/ipv6/ip6_frag.c b/src/core/ipv6/ip6_frag.c index a7e88e4f..1f746732 100644 --- a/src/core/ipv6/ip6_frag.c +++ b/src/core/ipv6/ip6_frag.c @@ -279,12 +279,12 @@ ip6_reass(struct pbuf *p) clen = pbuf_clen(p); - offset = ntohs(frag_hdr->_fragment_offset); + offset = lwip_ntohs(frag_hdr->_fragment_offset); /* Calculate fragment length from IPv6 payload length. * Adjust for headers before Fragment Header. * And finally adjust by Fragment Header length. */ - len = ntohs(ip6_current_header()->_plen); + len = lwip_ntohs(ip6_current_header()->_plen); len -= (u16_t)(((u8_t*)p->payload - (const u8_t*)ip6_current_header()) - IP6_HLEN); len -= IP6_FRAG_HLEN; @@ -560,7 +560,7 @@ ip6_reass(struct pbuf *p) - IP6_HLEN); /* Set payload length in ip header. */ - iphdr_ptr->_plen = htons(ipr->datagram_len); + iphdr_ptr->_plen = lwip_htons(ipr->datagram_len); /* Get the first pbuf. */ p = ipr->p; @@ -748,8 +748,8 @@ ip6_frag(struct pbuf *p, struct netif *netif, const ip6_addr_t *dest) /* Set headers */ frag_hdr->_nexth = original_ip6hdr->_nexth; frag_hdr->reserved = 0; - frag_hdr->_fragment_offset = htons((fragment_offset & IP6_FRAG_OFFSET_MASK) | (last ? 0 : IP6_FRAG_MORE_FLAG)); - frag_hdr->_identification = htonl(identification); + frag_hdr->_fragment_offset = lwip_htons((fragment_offset & IP6_FRAG_OFFSET_MASK) | (last ? 0 : IP6_FRAG_MORE_FLAG)); + frag_hdr->_identification = lwip_htonl(identification); IP6H_NEXTH_SET(ip6hdr, IP6_NEXTH_FRAGMENT); IP6H_PLEN_SET(ip6hdr, cop + IP6_FRAG_HLEN); diff --git a/src/core/ipv6/nd6.c b/src/core/ipv6/nd6.c index c06b1780..ec996e42 100644 --- a/src/core/ipv6/nd6.c +++ b/src/core/ipv6/nd6.c @@ -420,15 +420,15 @@ nd6_input(struct pbuf *p, struct netif *inp) } /* Re-set invalidation timer. */ - default_router_list[i].invalidation_timer = htons(ra_hdr->router_lifetime); + default_router_list[i].invalidation_timer = lwip_htons(ra_hdr->router_lifetime); /* Re-set default timer values. */ #if LWIP_ND6_ALLOW_RA_UPDATES if (ra_hdr->retrans_timer > 0) { - retrans_timer = htonl(ra_hdr->retrans_timer); + retrans_timer = lwip_htonl(ra_hdr->retrans_timer); } if (ra_hdr->reachable_time > 0) { - reachable_time = htonl(ra_hdr->reachable_time); + reachable_time = lwip_htonl(ra_hdr->reachable_time); } #endif /* LWIP_ND6_ALLOW_RA_UPDATES */ @@ -479,9 +479,9 @@ nd6_input(struct pbuf *p, struct netif *inp) { struct mtu_option *mtu_opt; mtu_opt = (struct mtu_option *)buffer; - if (htonl(mtu_opt->mtu) >= 1280) { + if (lwip_htonl(mtu_opt->mtu) >= 1280) { #if LWIP_ND6_ALLOW_RA_UPDATES - inp->mtu = (u16_t)htonl(mtu_opt->mtu); + inp->mtu = (u16_t)lwip_htonl(mtu_opt->mtu); #endif /* LWIP_ND6_ALLOW_RA_UPDATES */ } break; @@ -507,7 +507,7 @@ nd6_input(struct pbuf *p, struct netif *inp) prefix = nd6_new_onlink_prefix(ip6_current_dest_addr(), inp); } if (prefix >= 0) { - prefix_list[prefix].invalidation_timer = htonl(prefix_opt->valid_lifetime); + prefix_list[prefix].invalidation_timer = lwip_htonl(prefix_opt->valid_lifetime); #if LWIP_IPV6_AUTOCONFIG if (prefix_opt->flags & ND6_PREFIX_FLAG_AUTONOMOUS) { @@ -640,7 +640,7 @@ nd6_input(struct pbuf *p, struct netif *inp) } /* Change the Path MTU. */ - pmtu = htonl(icmp6hdr->data); + pmtu = lwip_htonl(icmp6hdr->data); destination_cache[i].pmtu = (u16_t)LWIP_MIN(pmtu, 0xFFFF); break; /* ICMP6_TYPE_PTB */ diff --git a/src/core/netif.c b/src/core/netif.c index 79b4652c..d9f595e6 100644 --- a/src/core/netif.c +++ b/src/core/netif.c @@ -1175,11 +1175,11 @@ netif_create_ip6_linklocal_address(struct netif *netif, u8_t from_mac_48bit) /* Generate interface ID. */ if (from_mac_48bit) { /* Assume hwaddr is a 48-bit IEEE 802 MAC. Convert to EUI-64 address. Complement Group bit. */ - ip_2_ip6(&netif->ip6_addr[0])->addr[2] = htonl((((u32_t)(netif->hwaddr[0] ^ 0x02)) << 24) | + ip_2_ip6(&netif->ip6_addr[0])->addr[2] = lwip_htonl((((u32_t)(netif->hwaddr[0] ^ 0x02)) << 24) | ((u32_t)(netif->hwaddr[1]) << 16) | ((u32_t)(netif->hwaddr[2]) << 8) | (0xff)); - ip_2_ip6(&netif->ip6_addr[0])->addr[3] = htonl((0xfeul << 24) | + ip_2_ip6(&netif->ip6_addr[0])->addr[3] = lwip_htonl((0xfeul << 24) | ((u32_t)(netif->hwaddr[3]) << 16) | ((u32_t)(netif->hwaddr[4]) << 8) | (netif->hwaddr[5])); diff --git a/src/core/tcp.c b/src/core/tcp.c index a91c1f4e..1d700980 100644 --- a/src/core/tcp.c +++ b/src/core/tcp.c @@ -1972,13 +1972,13 @@ tcp_debug_print(struct tcp_hdr *tcphdr) LWIP_DEBUGF(TCP_DEBUG, ("TCP header:\n")); LWIP_DEBUGF(TCP_DEBUG, ("+-------------------------------+\n")); LWIP_DEBUGF(TCP_DEBUG, ("| %5"U16_F" | %5"U16_F" | (src port, dest port)\n", - ntohs(tcphdr->src), ntohs(tcphdr->dest))); + lwip_ntohs(tcphdr->src), lwip_ntohs(tcphdr->dest))); LWIP_DEBUGF(TCP_DEBUG, ("+-------------------------------+\n")); LWIP_DEBUGF(TCP_DEBUG, ("| %010"U32_F" | (seq no)\n", - ntohl(tcphdr->seqno))); + lwip_ntohl(tcphdr->seqno))); LWIP_DEBUGF(TCP_DEBUG, ("+-------------------------------+\n")); LWIP_DEBUGF(TCP_DEBUG, ("| %010"U32_F" | (ack no)\n", - ntohl(tcphdr->ackno))); + lwip_ntohl(tcphdr->ackno))); LWIP_DEBUGF(TCP_DEBUG, ("+-------------------------------+\n")); LWIP_DEBUGF(TCP_DEBUG, ("| %2"U16_F" | |%"U16_F"%"U16_F"%"U16_F"%"U16_F"%"U16_F"%"U16_F"| %5"U16_F" | (hdrlen, flags (", TCPH_HDRLEN(tcphdr), @@ -1988,12 +1988,12 @@ tcp_debug_print(struct tcp_hdr *tcphdr) (u16_t)(TCPH_FLAGS(tcphdr) >> 2 & 1), (u16_t)(TCPH_FLAGS(tcphdr) >> 1 & 1), (u16_t)(TCPH_FLAGS(tcphdr) & 1), - ntohs(tcphdr->wnd))); + lwip_ntohs(tcphdr->wnd))); tcp_debug_print_flags(TCPH_FLAGS(tcphdr)); LWIP_DEBUGF(TCP_DEBUG, ("), win)\n")); LWIP_DEBUGF(TCP_DEBUG, ("+-------------------------------+\n")); LWIP_DEBUGF(TCP_DEBUG, ("| 0x%04"X16_F" | %5"U16_F" | (chksum, urgp)\n", - ntohs(tcphdr->chksum), ntohs(tcphdr->urgp))); + lwip_ntohs(tcphdr->chksum), lwip_ntohs(tcphdr->urgp))); LWIP_DEBUGF(TCP_DEBUG, ("+-------------------------------+\n")); } diff --git a/src/core/tcp_in.c b/src/core/tcp_in.c index 1ee0e127..8925d7a6 100644 --- a/src/core/tcp_in.c +++ b/src/core/tcp_in.c @@ -209,11 +209,11 @@ tcp_input(struct pbuf *p, struct netif *inp) } /* Convert fields in TCP header to host byte order. */ - tcphdr->src = ntohs(tcphdr->src); - tcphdr->dest = ntohs(tcphdr->dest); - seqno = tcphdr->seqno = ntohl(tcphdr->seqno); - ackno = tcphdr->ackno = ntohl(tcphdr->ackno); - tcphdr->wnd = ntohs(tcphdr->wnd); + tcphdr->src = lwip_ntohs(tcphdr->src); + tcphdr->dest = lwip_ntohs(tcphdr->dest); + seqno = tcphdr->seqno = lwip_ntohl(tcphdr->seqno); + ackno = tcphdr->ackno = lwip_ntohl(tcphdr->ackno); + tcphdr->wnd = lwip_ntohs(tcphdr->wnd); flags = TCPH_FLAGS(tcphdr); tcplen = p->tot_len + ((flags & (TCP_FIN | TCP_SYN)) ? 1 : 0); @@ -747,7 +747,7 @@ tcp_process(struct tcp_pcb *pcb) switch (pcb->state) { case SYN_SENT: LWIP_DEBUGF(TCP_INPUT_DEBUG, ("SYN-SENT: ackno %"U32_F" pcb->snd_nxt %"U32_F" unacked %"U32_F"\n", ackno, - pcb->snd_nxt, ntohl(pcb->unacked->tcphdr->seqno))); + pcb->snd_nxt, lwip_ntohl(pcb->unacked->tcphdr->seqno))); /* received SYN ACK with expected sequence number? */ if ((flags & TCP_ACK) && (flags & TCP_SYN) && (ackno == pcb->lastack + 1)) { @@ -1140,18 +1140,18 @@ tcp_receive(struct tcp_pcb *pcb) LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_receive: ACK for %"U32_F", unacked->seqno %"U32_F":%"U32_F"\n", ackno, pcb->unacked != NULL? - ntohl(pcb->unacked->tcphdr->seqno): 0, + lwip_ntohl(pcb->unacked->tcphdr->seqno): 0, pcb->unacked != NULL? - ntohl(pcb->unacked->tcphdr->seqno) + TCP_TCPLEN(pcb->unacked): 0)); + lwip_ntohl(pcb->unacked->tcphdr->seqno) + TCP_TCPLEN(pcb->unacked): 0)); /* Remove segment from the unacknowledged list if the incoming ACK acknowledges them. */ while (pcb->unacked != NULL && - TCP_SEQ_LEQ(ntohl(pcb->unacked->tcphdr->seqno) + + TCP_SEQ_LEQ(lwip_ntohl(pcb->unacked->tcphdr->seqno) + TCP_TCPLEN(pcb->unacked), ackno)) { LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_receive: removing %"U32_F":%"U32_F" from pcb->unacked\n", - ntohl(pcb->unacked->tcphdr->seqno), - ntohl(pcb->unacked->tcphdr->seqno) + + lwip_ntohl(pcb->unacked->tcphdr->seqno), + lwip_ntohl(pcb->unacked->tcphdr->seqno) + TCP_TCPLEN(pcb->unacked))); next = pcb->unacked; @@ -1199,10 +1199,10 @@ tcp_receive(struct tcp_pcb *pcb) ->unsent list after a retransmission, so these segments may in fact have been sent once. */ while (pcb->unsent != NULL && - TCP_SEQ_BETWEEN(ackno, ntohl(pcb->unsent->tcphdr->seqno) + + TCP_SEQ_BETWEEN(ackno, lwip_ntohl(pcb->unsent->tcphdr->seqno) + TCP_TCPLEN(pcb->unsent), pcb->snd_nxt)) { LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_receive: removing %"U32_F":%"U32_F" from pcb->unsent\n", - ntohl(pcb->unsent->tcphdr->seqno), ntohl(pcb->unsent->tcphdr->seqno) + + lwip_ntohl(pcb->unsent->tcphdr->seqno), lwip_ntohl(pcb->unsent->tcphdr->seqno) + TCP_TCPLEN(pcb->unsent))); next = pcb->unsent; @@ -1779,12 +1779,12 @@ tcp_parseopt(struct tcp_pcb *pcb) tsval |= (tcp_getoptbyte() << 16); tsval |= (tcp_getoptbyte() << 24); if (flags & TCP_SYN) { - pcb->ts_recent = ntohl(tsval); + pcb->ts_recent = lwip_ntohl(tsval); /* Enable sending timestamps in every segment now that we know the remote host supports it. */ pcb->flags |= TF_TIMESTAMP; } else if (TCP_SEQ_BETWEEN(pcb->ts_lastacksent, seqno, seqno+tcplen)) { - pcb->ts_recent = ntohl(tsval); + pcb->ts_recent = lwip_ntohl(tsval); } /* Advance to next option (6 bytes already read) */ tcp_optidx += LWIP_TCP_OPT_LEN_TS - 6; diff --git a/src/core/tcp_out.c b/src/core/tcp_out.c index 78ff0a1a..5a9c0319 100644 --- a/src/core/tcp_out.c +++ b/src/core/tcp_out.c @@ -114,12 +114,12 @@ tcp_output_alloc_header(struct tcp_pcb *pcb, u16_t optlen, u16_t datalen, LWIP_ASSERT("check that first pbuf can hold struct tcp_hdr", (p->len >= TCP_HLEN + optlen)); tcphdr = (struct tcp_hdr *)p->payload; - tcphdr->src = htons(pcb->local_port); - tcphdr->dest = htons(pcb->remote_port); + tcphdr->src = lwip_htons(pcb->local_port); + tcphdr->dest = lwip_htons(pcb->remote_port); tcphdr->seqno = seqno_be; - tcphdr->ackno = htonl(pcb->rcv_nxt); + tcphdr->ackno = lwip_htonl(pcb->rcv_nxt); TCPH_HDRLEN_FLAGS_SET(tcphdr, (5 + optlen / 4), TCP_ACK); - tcphdr->wnd = htons(TCPWND_MIN16(RCV_WND_SCALE(pcb, pcb->rcv_ann_wnd))); + tcphdr->wnd = lwip_htons(TCPWND_MIN16(RCV_WND_SCALE(pcb, pcb->rcv_ann_wnd))); tcphdr->chksum = 0; tcphdr->urgp = 0; @@ -204,9 +204,9 @@ tcp_create_segment(struct tcp_pcb *pcb, struct pbuf *p, u8_t flags, u32_t seqno, return NULL; } seg->tcphdr = (struct tcp_hdr *)seg->p->payload; - seg->tcphdr->src = htons(pcb->local_port); - seg->tcphdr->dest = htons(pcb->remote_port); - seg->tcphdr->seqno = htonl(seqno); + seg->tcphdr->src = lwip_htons(pcb->local_port); + seg->tcphdr->dest = lwip_htons(pcb->remote_port); + seg->tcphdr->seqno = lwip_htonl(seqno); /* ackno is set in tcp_output */ TCPH_HDRLEN_FLAGS_SET(seg->tcphdr, (5 + optlen / 4), flags); /* wnd and chksum are set in tcp_output */ @@ -633,8 +633,8 @@ tcp_write(struct tcp_pcb *pcb, const void *arg, u16_t len, u8_t apiflags) prev_seg = seg; LWIP_DEBUGF(TCP_OUTPUT_DEBUG | LWIP_DBG_TRACE, ("tcp_write: queueing %"U32_F":%"U32_F"\n", - ntohl(seg->tcphdr->seqno), - ntohl(seg->tcphdr->seqno) + TCP_TCPLEN(seg))); + lwip_ntohl(seg->tcphdr->seqno), + lwip_ntohl(seg->tcphdr->seqno) + TCP_TCPLEN(seg))); pos += seglen; } @@ -808,8 +808,8 @@ tcp_enqueue_flags(struct tcp_pcb *pcb, u8_t flags) LWIP_DEBUGF(TCP_OUTPUT_DEBUG | LWIP_DBG_TRACE, ("tcp_enqueue_flags: queueing %"U32_F":%"U32_F" (0x%"X16_F")\n", - ntohl(seg->tcphdr->seqno), - ntohl(seg->tcphdr->seqno) + TCP_TCPLEN(seg), + lwip_ntohl(seg->tcphdr->seqno), + lwip_ntohl(seg->tcphdr->seqno) + TCP_TCPLEN(seg), (u16_t)flags)); /* Now append seg to pcb->unsent queue */ @@ -856,8 +856,8 @@ tcp_build_timestamp_option(struct tcp_pcb *pcb, u32_t *opts) { /* Pad with two NOP options to make everything nicely aligned */ opts[0] = PP_HTONL(0x0101080A); - opts[1] = htonl(sys_now()); - opts[2] = htonl(pcb->ts_recent); + opts[1] = lwip_htonl(sys_now()); + opts[2] = lwip_htonl(pcb->ts_recent); } #endif @@ -896,7 +896,7 @@ tcp_send_empty_ack(struct tcp_pcb *pcb) } #endif - p = tcp_output_alloc_header(pcb, optlen, 0, htonl(pcb->snd_nxt)); + p = tcp_output_alloc_header(pcb, optlen, 0, lwip_htonl(pcb->snd_nxt)); if (p == NULL) { /* let tcp_fasttmr retry sending this ACK */ pcb->flags |= (TF_ACK_DELAY | TF_ACK_NOW); @@ -989,7 +989,7 @@ tcp_output(struct tcp_pcb *pcb) */ if (pcb->flags & TF_ACK_NOW && (seg == NULL || - ntohl(seg->tcphdr->seqno) - pcb->lastack + seg->len > wnd)) { + lwip_ntohl(seg->tcphdr->seqno) - pcb->lastack + seg->len > wnd)) { return tcp_send_empty_ack(pcb); } @@ -1030,13 +1030,13 @@ tcp_output(struct tcp_pcb *pcb) ("tcp_output: snd_wnd %"TCPWNDSIZE_F", cwnd %"TCPWNDSIZE_F", wnd %"U32_F ", effwnd %"U32_F", seq %"U32_F", ack %"U32_F"\n", pcb->snd_wnd, pcb->cwnd, wnd, - ntohl(seg->tcphdr->seqno) - pcb->lastack + seg->len, - ntohl(seg->tcphdr->seqno), pcb->lastack)); + lwip_ntohl(seg->tcphdr->seqno) - pcb->lastack + seg->len, + lwip_ntohl(seg->tcphdr->seqno), pcb->lastack)); } #endif /* TCP_CWND_DEBUG */ /* data available and window allows it to be sent? */ while (seg != NULL && - ntohl(seg->tcphdr->seqno) - pcb->lastack + seg->len <= wnd) { + lwip_ntohl(seg->tcphdr->seqno) - pcb->lastack + seg->len <= wnd) { LWIP_ASSERT("RST not expected here!", (TCPH_FLAGS(seg->tcphdr) & TCP_RST) == 0); /* Stop sending if the nagle algorithm would prevent it @@ -1053,9 +1053,9 @@ tcp_output(struct tcp_pcb *pcb) #if TCP_CWND_DEBUG LWIP_DEBUGF(TCP_CWND_DEBUG, ("tcp_output: snd_wnd %"TCPWNDSIZE_F", cwnd %"TCPWNDSIZE_F", wnd %"U32_F", effwnd %"U32_F", seq %"U32_F", ack %"U32_F", i %"S16_F"\n", pcb->snd_wnd, pcb->cwnd, wnd, - ntohl(seg->tcphdr->seqno) + seg->len - + lwip_ntohl(seg->tcphdr->seqno) + seg->len - pcb->lastack, - ntohl(seg->tcphdr->seqno), pcb->lastack, i)); + lwip_ntohl(seg->tcphdr->seqno), pcb->lastack, i)); ++i; #endif /* TCP_CWND_DEBUG */ @@ -1076,7 +1076,7 @@ tcp_output(struct tcp_pcb *pcb) if (pcb->state != SYN_SENT) { pcb->flags &= ~(TF_ACK_DELAY | TF_ACK_NOW); } - snd_nxt = ntohl(seg->tcphdr->seqno) + TCP_TCPLEN(seg); + snd_nxt = lwip_ntohl(seg->tcphdr->seqno) + TCP_TCPLEN(seg); if (TCP_SEQ_LT(pcb->snd_nxt, snd_nxt)) { pcb->snd_nxt = snd_nxt; } @@ -1092,11 +1092,11 @@ tcp_output(struct tcp_pcb *pcb) /* In the case of fast retransmit, the packet should not go to the tail * of the unacked queue, but rather somewhere before it. We need to check for * this case. -STJ Jul 27, 2004 */ - if (TCP_SEQ_LT(ntohl(seg->tcphdr->seqno), ntohl(useg->tcphdr->seqno))) { + if (TCP_SEQ_LT(lwip_ntohl(seg->tcphdr->seqno), lwip_ntohl(useg->tcphdr->seqno))) { /* add segment to before tail of unacked list, keeping the list sorted */ struct tcp_seg **cur_seg = &(pcb->unacked); while (*cur_seg && - TCP_SEQ_LT(ntohl((*cur_seg)->tcphdr->seqno), ntohl(seg->tcphdr->seqno))) { + TCP_SEQ_LT(lwip_ntohl((*cur_seg)->tcphdr->seqno), lwip_ntohl(seg->tcphdr->seqno))) { cur_seg = &((*cur_seg)->next ); } seg->next = (*cur_seg); @@ -1147,18 +1147,18 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb, struct netif *netif /* The TCP header has already been constructed, but the ackno and wnd fields remain. */ - seg->tcphdr->ackno = htonl(pcb->rcv_nxt); + seg->tcphdr->ackno = lwip_htonl(pcb->rcv_nxt); /* advertise our receive window size in this TCP segment */ #if LWIP_WND_SCALE if (seg->flags & TF_SEG_OPTS_WND_SCALE) { /* The Window field in a SYN segment itself (the only type where we send the window scale option) is never scaled. */ - seg->tcphdr->wnd = htons(TCPWND_MIN16(pcb->rcv_ann_wnd)); + seg->tcphdr->wnd = lwip_htons(TCPWND_MIN16(pcb->rcv_ann_wnd)); } else #endif /* LWIP_WND_SCALE */ { - seg->tcphdr->wnd = htons(TCPWND_MIN16(RCV_WND_SCALE(pcb, pcb->rcv_ann_wnd))); + seg->tcphdr->wnd = lwip_htons(TCPWND_MIN16(RCV_WND_SCALE(pcb, pcb->rcv_ann_wnd))); } pcb->rcv_ann_right_edge = pcb->rcv_nxt + pcb->rcv_ann_wnd; @@ -1200,12 +1200,12 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb, struct netif *netif if (pcb->rttest == 0) { pcb->rttest = tcp_ticks; - pcb->rtseq = ntohl(seg->tcphdr->seqno); + pcb->rtseq = lwip_ntohl(seg->tcphdr->seqno); LWIP_DEBUGF(TCP_RTO_DEBUG, ("tcp_output_segment: rtseq %"U32_F"\n", pcb->rtseq)); } LWIP_DEBUGF(TCP_OUTPUT_DEBUG, ("tcp_output_segment: %"U32_F":%"U32_F"\n", - htonl(seg->tcphdr->seqno), htonl(seg->tcphdr->seqno) + + lwip_htonl(seg->tcphdr->seqno), lwip_htonl(seg->tcphdr->seqno) + seg->len)); len = (u16_t)((u8_t *)seg->tcphdr - (u8_t *)seg->p->payload); @@ -1303,10 +1303,10 @@ tcp_rst(u32_t seqno, u32_t ackno, (p->len >= sizeof(struct tcp_hdr))); tcphdr = (struct tcp_hdr *)p->payload; - tcphdr->src = htons(local_port); - tcphdr->dest = htons(remote_port); - tcphdr->seqno = htonl(seqno); - tcphdr->ackno = htonl(ackno); + tcphdr->src = lwip_htons(local_port); + tcphdr->dest = lwip_htons(remote_port); + tcphdr->seqno = lwip_htonl(seqno); + tcphdr->ackno = lwip_htonl(ackno); TCPH_HDRLEN_FLAGS_SET(tcphdr, TCP_HLEN/4, TCP_RST | TCP_ACK); #if LWIP_WND_SCALE tcphdr->wnd = PP_HTONS(((TCP_WND >> TCP_RCV_SCALE) & 0xFFFF)); @@ -1399,7 +1399,7 @@ tcp_rexmit(struct tcp_pcb *pcb) cur_seg = &(pcb->unsent); while (*cur_seg && - TCP_SEQ_LT(ntohl((*cur_seg)->tcphdr->seqno), ntohl(seg->tcphdr->seqno))) { + TCP_SEQ_LT(lwip_ntohl((*cur_seg)->tcphdr->seqno), lwip_ntohl(seg->tcphdr->seqno))) { cur_seg = &((*cur_seg)->next ); } seg->next = *cur_seg; @@ -1437,7 +1437,7 @@ tcp_rexmit_fast(struct tcp_pcb *pcb) ("tcp_receive: dupacks %"U16_F" (%"U32_F "), fast retransmit %"U32_F"\n", (u16_t)pcb->dupacks, pcb->lastack, - ntohl(pcb->unacked->tcphdr->seqno))); + lwip_ntohl(pcb->unacked->tcphdr->seqno))); tcp_rexmit(pcb); /* Set ssthresh to half of the minimum of the current @@ -1488,7 +1488,7 @@ tcp_keepalive(struct tcp_pcb *pcb) LWIP_DEBUGF(TCP_DEBUG, ("tcp_keepalive: tcp_ticks %"U32_F" pcb->tmr %"U32_F" pcb->keep_cnt_sent %"U16_F"\n", tcp_ticks, pcb->tmr, (u16_t)pcb->keep_cnt_sent)); - p = tcp_output_alloc_header(pcb, 0, 0, htonl(pcb->snd_nxt - 1)); + p = tcp_output_alloc_header(pcb, 0, 0, lwip_htonl(pcb->snd_nxt - 1)); if (p == NULL) { LWIP_DEBUGF(TCP_DEBUG, ("tcp_keepalive: could not allocate memory for pbuf\n")); @@ -1583,7 +1583,7 @@ tcp_zero_window_probe(struct tcp_pcb *pcb) } /* The byte may be acknowledged without the window being opened. */ - snd_nxt = ntohl(seg->tcphdr->seqno) + 1; + snd_nxt = lwip_ntohl(seg->tcphdr->seqno) + 1; if (TCP_SEQ_LT(pcb->snd_nxt, snd_nxt)) { pcb->snd_nxt = snd_nxt; } diff --git a/src/core/udp.c b/src/core/udp.c index 67b6c94b..f9aee732 100644 --- a/src/core/udp.c +++ b/src/core/udp.c @@ -242,17 +242,17 @@ udp_input(struct pbuf *p, struct netif *inp) LWIP_DEBUGF(UDP_DEBUG, ("udp_input: received datagram of length %"U16_F"\n", p->tot_len)); /* convert src and dest ports to host byte order */ - src = ntohs(udphdr->src); - dest = ntohs(udphdr->dest); + src = lwip_ntohs(udphdr->src); + dest = lwip_ntohs(udphdr->dest); udp_debug_print(udphdr); /* print the UDP source and destination */ LWIP_DEBUGF(UDP_DEBUG, ("udp (")); ip_addr_debug_print(UDP_DEBUG, ip_current_dest_addr()); - LWIP_DEBUGF(UDP_DEBUG, (", %"U16_F") <-- (", ntohs(udphdr->dest))); + LWIP_DEBUGF(UDP_DEBUG, (", %"U16_F") <-- (", lwip_ntohs(udphdr->dest))); ip_addr_debug_print(UDP_DEBUG, ip_current_src_addr()); - LWIP_DEBUGF(UDP_DEBUG, (", %"U16_F")\n", ntohs(udphdr->src))); + LWIP_DEBUGF(UDP_DEBUG, (", %"U16_F")\n", lwip_ntohs(udphdr->src))); pcb = NULL; prev = NULL; @@ -331,7 +331,7 @@ udp_input(struct pbuf *p, struct netif *inp) #if LWIP_UDPLITE if (ip_current_header_proto() == IP_PROTO_UDPLITE) { /* Do the UDP Lite checksum */ - u16_t chklen = ntohs(udphdr->len); + u16_t chklen = lwip_ntohs(udphdr->len); if (chklen < sizeof(struct udp_hdr)) { if (chklen == 0) { /* For UDP-Lite, checksum length of 0 means checksum @@ -752,8 +752,8 @@ udp_sendto_if_src_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *d (q->len >= sizeof(struct udp_hdr))); /* q now represents the packet to be sent */ udphdr = (struct udp_hdr *)q->payload; - udphdr->src = htons(pcb->local_port); - udphdr->dest = htons(dst_port); + udphdr->src = lwip_htons(pcb->local_port); + udphdr->dest = lwip_htons(dst_port); /* in UDP, 0 checksum means 'no checksum' */ udphdr->chksum = 0x0000; @@ -786,7 +786,7 @@ udp_sendto_if_src_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *d chklen_hdr = 0; chklen = q->tot_len; } - udphdr->len = htons(chklen_hdr); + udphdr->len = lwip_htons(chklen_hdr); /* calculate checksum */ #if CHECKSUM_GEN_UDP IF__NETIF_CHECKSUM_ENABLED(netif, NETIF_CHECKSUM_GEN_UDP) { @@ -817,7 +817,7 @@ udp_sendto_if_src_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *d #endif /* LWIP_UDPLITE */ { /* UDP */ LWIP_DEBUGF(UDP_DEBUG, ("udp_send: UDP packet length %"U16_F"\n", q->tot_len)); - udphdr->len = htons(q->tot_len); + udphdr->len = lwip_htons(q->tot_len); /* calculate checksum */ #if CHECKSUM_GEN_UDP IF__NETIF_CHECKSUM_ENABLED(netif, NETIF_CHECKSUM_GEN_UDP) { @@ -1200,10 +1200,10 @@ udp_debug_print(struct udp_hdr *udphdr) LWIP_DEBUGF(UDP_DEBUG, ("UDP header:\n")); LWIP_DEBUGF(UDP_DEBUG, ("+-------------------------------+\n")); LWIP_DEBUGF(UDP_DEBUG, ("| %5"U16_F" | %5"U16_F" | (src port, dest port)\n", - ntohs(udphdr->src), ntohs(udphdr->dest))); + lwip_ntohs(udphdr->src), lwip_ntohs(udphdr->dest))); LWIP_DEBUGF(UDP_DEBUG, ("+-------------------------------+\n")); LWIP_DEBUGF(UDP_DEBUG, ("| %5"U16_F" | 0x%04"X16_F" | (len, chksum)\n", - ntohs(udphdr->len), ntohs(udphdr->chksum))); + lwip_ntohs(udphdr->len), lwip_ntohs(udphdr->chksum))); LWIP_DEBUGF(UDP_DEBUG, ("+-------------------------------+\n")); } #endif /* UDP_DEBUG */ diff --git a/src/include/lwip/def.h b/src/include/lwip/def.h index 35359b3a..aafbd7cc 100644 --- a/src/include/lwip/def.h +++ b/src/include/lwip/def.h @@ -72,32 +72,6 @@ extern "C" { #define LWIP_MAKE_U16(a, b) ((b << 8) | a) #endif -#ifndef LWIP_PLATFORM_BYTESWAP -#define LWIP_PLATFORM_BYTESWAP 0 -#endif - -#ifndef LWIP_PREFIX_BYTEORDER_FUNCS -/* workaround for naming collisions on some platforms */ - -#ifdef htons -#undef htons -#endif /* htons */ -#ifdef htonl -#undef htonl -#endif /* htonl */ -#ifdef ntohs -#undef ntohs -#endif /* ntohs */ -#ifdef ntohl -#undef ntohl -#endif /* ntohl */ - -#define htons(x) lwip_htons(x) -#define ntohs(x) lwip_ntohs(x) -#define htonl(x) lwip_htonl(x) -#define ntohl(x) lwip_ntohl(x) -#endif /* LWIP_PREFIX_BYTEORDER_FUNCS */ - #if BYTE_ORDER == BIG_ENDIAN #define lwip_htons(x) (x) #define lwip_ntohs(x) (x) @@ -108,17 +82,15 @@ extern "C" { #define PP_HTONL(x) (x) #define PP_NTOHL(x) (x) #else /* BYTE_ORDER != BIG_ENDIAN */ -#if LWIP_PLATFORM_BYTESWAP -#define lwip_htons(x) LWIP_PLATFORM_HTONS(x) -#define lwip_ntohs(x) LWIP_PLATFORM_HTONS(x) -#define lwip_htonl(x) LWIP_PLATFORM_HTONL(x) -#define lwip_ntohl(x) LWIP_PLATFORM_HTONL(x) -#else /* LWIP_PLATFORM_BYTESWAP */ +#ifndef lwip_htons u16_t lwip_htons(u16_t x); -u16_t lwip_ntohs(u16_t x); +#endif +#define lwip_ntohs(x) lwip_htons(x) + +#ifndef lwip_htonl u32_t lwip_htonl(u32_t x); -u32_t lwip_ntohl(u32_t x); -#endif /* LWIP_PLATFORM_BYTESWAP */ +#endif +#define lwip_ntohl(x) lwip_htonl(x) /* These macros should be calculated by the preprocessor and are used with compile-time constants only (so that there is no little-endian diff --git a/src/include/lwip/inet_chksum.h b/src/include/lwip/inet_chksum.h index 52d76d38..4e23d7f1 100644 --- a/src/include/lwip/inet_chksum.h +++ b/src/include/lwip/inet_chksum.h @@ -42,15 +42,9 @@ #include "lwip/pbuf.h" #include "lwip/ip_addr.h" -/** Swap the bytes in an u16_t: much like htons() for little-endian */ +/** Swap the bytes in an u16_t: much like lwip_htons() for little-endian */ #ifndef SWAP_BYTES_IN_WORD -#if LWIP_PLATFORM_BYTESWAP && (BYTE_ORDER == LITTLE_ENDIAN) -/* little endian and PLATFORM_BYTESWAP defined */ -#define SWAP_BYTES_IN_WORD(w) LWIP_PLATFORM_HTONS(w) -#else /* LWIP_PLATFORM_BYTESWAP && (BYTE_ORDER == LITTLE_ENDIAN) */ -/* can't use htons on big endian (or PLATFORM_BYTESWAP not defined)... */ #define SWAP_BYTES_IN_WORD(w) (((w) & 0xff) << 8) | (((w) & 0xff00) >> 8) -#endif /* LWIP_PLATFORM_BYTESWAP && (BYTE_ORDER == LITTLE_ENDIAN)*/ #endif /* SWAP_BYTES_IN_WORD */ /** Split an u32_t in two u16_ts and add them up */ diff --git a/src/include/lwip/ip4_addr.h b/src/include/lwip/ip4_addr.h index 2db8bd51..166acfab 100644 --- a/src/include/lwip/ip4_addr.h +++ b/src/include/lwip/ip4_addr.h @@ -141,7 +141,7 @@ struct netif; (u32_t)((d) & 0xff) #else /** Set an IP address given by the four byte-parts. - Little-endian version that prevents the use of htonl. */ + Little-endian version that prevents the use of lwip_htonl. */ #define IP4_ADDR(ipaddr, a,b,c,d) \ (ipaddr)->addr = ((u32_t)((d) & 0xff) << 24) | \ ((u32_t)((c) & 0xff) << 16) | \ @@ -164,7 +164,7 @@ struct netif; (src)->addr)) /** Set complete address to zero */ #define ip4_addr_set_zero(ipaddr) ((ipaddr)->addr = 0) -/** Set address to IPADDR_ANY (no need for htonl()) */ +/** Set address to IPADDR_ANY (no need for lwip_htonl()) */ #define ip4_addr_set_any(ipaddr) ((ipaddr)->addr = IPADDR_ANY) /** Set address to loopback address */ #define ip4_addr_set_loopback(ipaddr) ((ipaddr)->addr = PP_HTONL(IPADDR_LOOPBACK)) @@ -174,7 +174,7 @@ struct netif; * from host- to network-order. */ #define ip4_addr_set_hton(dest, src) ((dest)->addr = \ ((src) == NULL ? 0:\ - htonl((src)->addr))) + lwip_htonl((src)->addr))) /** IPv4 only: set the IP address given as an u32_t */ #define ip4_addr_set_u32(dest_ipaddr, src_u32) ((dest_ipaddr)->addr = (src_u32)) /** IPv4 only: get the IP address as an u32_t */ diff --git a/src/include/lwip/ip6_addr.h b/src/include/lwip/ip6_addr.h index 2d269a6e..14d0f7cf 100644 --- a/src/include/lwip/ip6_addr.h +++ b/src/include/lwip/ip6_addr.h @@ -86,7 +86,7 @@ typedef struct ip6_addr_packed ip6_addr_p_t; (u32_t)((d) & 0xff) #else /** Set an IPv6 partial address given by byte-parts. -Little-endian version, stored in network order (no htonl). */ +Little-endian version, stored in network order (no lwip_htonl). */ #define IP6_ADDR_PART(ip6addr, index, a,b,c,d) \ (ip6addr)->addr[index] = ((u32_t)((d) & 0xff) << 24) | \ ((u32_t)((c) & 0xff) << 16) | \ @@ -103,21 +103,21 @@ Little-endian version, stored in network order (no htonl). */ (ip6addr)->addr[3] = idx3; } while(0) /** Access address in 16-bit block */ -#define IP6_ADDR_BLOCK1(ip6addr) ((u16_t)((htonl((ip6addr)->addr[0]) >> 16) & 0xffff)) +#define IP6_ADDR_BLOCK1(ip6addr) ((u16_t)((lwip_htonl((ip6addr)->addr[0]) >> 16) & 0xffff)) /** Access address in 16-bit block */ -#define IP6_ADDR_BLOCK2(ip6addr) ((u16_t)((htonl((ip6addr)->addr[0])) & 0xffff)) +#define IP6_ADDR_BLOCK2(ip6addr) ((u16_t)((lwip_htonl((ip6addr)->addr[0])) & 0xffff)) /** Access address in 16-bit block */ -#define IP6_ADDR_BLOCK3(ip6addr) ((u16_t)((htonl((ip6addr)->addr[1]) >> 16) & 0xffff)) +#define IP6_ADDR_BLOCK3(ip6addr) ((u16_t)((lwip_htonl((ip6addr)->addr[1]) >> 16) & 0xffff)) /** Access address in 16-bit block */ -#define IP6_ADDR_BLOCK4(ip6addr) ((u16_t)((htonl((ip6addr)->addr[1])) & 0xffff)) +#define IP6_ADDR_BLOCK4(ip6addr) ((u16_t)((lwip_htonl((ip6addr)->addr[1])) & 0xffff)) /** Access address in 16-bit block */ -#define IP6_ADDR_BLOCK5(ip6addr) ((u16_t)((htonl((ip6addr)->addr[2]) >> 16) & 0xffff)) +#define IP6_ADDR_BLOCK5(ip6addr) ((u16_t)((lwip_htonl((ip6addr)->addr[2]) >> 16) & 0xffff)) /** Access address in 16-bit block */ -#define IP6_ADDR_BLOCK6(ip6addr) ((u16_t)((htonl((ip6addr)->addr[2])) & 0xffff)) +#define IP6_ADDR_BLOCK6(ip6addr) ((u16_t)((lwip_htonl((ip6addr)->addr[2])) & 0xffff)) /** Access address in 16-bit block */ -#define IP6_ADDR_BLOCK7(ip6addr) ((u16_t)((htonl((ip6addr)->addr[3]) >> 16) & 0xffff)) +#define IP6_ADDR_BLOCK7(ip6addr) ((u16_t)((lwip_htonl((ip6addr)->addr[3]) >> 16) & 0xffff)) /** Access address in 16-bit block */ -#define IP6_ADDR_BLOCK8(ip6addr) ((u16_t)((htonl((ip6addr)->addr[3])) & 0xffff)) +#define IP6_ADDR_BLOCK8(ip6addr) ((u16_t)((lwip_htonl((ip6addr)->addr[3])) & 0xffff)) /** Copy IPv6 address - faster than ip6_addr_set: no NULL check */ #define ip6_addr_copy(dest, src) do{(dest).addr[0] = (src).addr[0]; \ @@ -136,7 +136,7 @@ Little-endian version, stored in network order (no htonl). */ (ip6addr)->addr[2] = 0; \ (ip6addr)->addr[3] = 0;}while(0) -/** Set address to ipv6 'any' (no need for htonl()) */ +/** Set address to ipv6 'any' (no need for lwip_htonl()) */ #define ip6_addr_set_any(ip6addr) ip6_addr_set_zero(ip6addr) /** Set address to ipv6 loopback address */ #define ip6_addr_set_loopback(ip6addr) do{(ip6addr)->addr[0] = 0; \ @@ -145,10 +145,10 @@ Little-endian version, stored in network order (no htonl). */ (ip6addr)->addr[3] = PP_HTONL(0x00000001UL);}while(0) /** Safely copy one IPv6 address to another and change byte order * from host- to network-order. */ -#define ip6_addr_set_hton(dest, src) do{(dest)->addr[0] = (src) == NULL ? 0 : htonl((src)->addr[0]); \ - (dest)->addr[1] = (src) == NULL ? 0 : htonl((src)->addr[1]); \ - (dest)->addr[2] = (src) == NULL ? 0 : htonl((src)->addr[2]); \ - (dest)->addr[3] = (src) == NULL ? 0 : htonl((src)->addr[3]);}while(0) +#define ip6_addr_set_hton(dest, src) do{(dest)->addr[0] = (src) == NULL ? 0 : lwip_htonl((src)->addr[0]); \ + (dest)->addr[1] = (src) == NULL ? 0 : lwip_htonl((src)->addr[1]); \ + (dest)->addr[2] = (src) == NULL ? 0 : lwip_htonl((src)->addr[2]); \ + (dest)->addr[3] = (src) == NULL ? 0 : lwip_htonl((src)->addr[3]);}while(0) /** @@ -166,7 +166,7 @@ Little-endian version, stored in network order (no htonl). */ ((addr1)->addr[2] == (addr2)->addr[2]) && \ ((addr1)->addr[3] == (addr2)->addr[3])) -#define ip6_get_subnet_id(ip6addr) (htonl((ip6addr)->addr[2]) & 0x0000ffffUL) +#define ip6_get_subnet_id(ip6addr) (lwip_htonl((ip6addr)->addr[2]) & 0x0000ffffUL) #define ip6_addr_isany_val(ip6addr) (((ip6addr).addr[0] == 0) && \ ((ip6addr).addr[1] == 0) && \ @@ -193,7 +193,7 @@ Little-endian version, stored in network order (no htonl). */ #define ip6_addr_multicast_transient_flag(ip6addr) ((ip6addr)->addr[0] & PP_HTONL(0x00100000UL)) #define ip6_addr_multicast_prefix_flag(ip6addr) ((ip6addr)->addr[0] & PP_HTONL(0x00200000UL)) #define ip6_addr_multicast_rendezvous_flag(ip6addr) ((ip6addr)->addr[0] & PP_HTONL(0x00400000UL)) -#define ip6_addr_multicast_scope(ip6addr) ((htonl((ip6addr)->addr[0]) >> 16) & 0xf) +#define ip6_addr_multicast_scope(ip6addr) ((lwip_htonl((ip6addr)->addr[0]) >> 16) & 0xf) #define IP6_MULTICAST_SCOPE_RESERVED 0x0 #define IP6_MULTICAST_SCOPE_RESERVED0 0x0 #define IP6_MULTICAST_SCOPE_INTERFACE_LOCAL 0x1 diff --git a/src/include/lwip/priv/tcp_priv.h b/src/include/lwip/priv/tcp_priv.h index 736dc325..51747e0f 100644 --- a/src/include/lwip/priv/tcp_priv.h +++ b/src/include/lwip/priv/tcp_priv.h @@ -290,7 +290,7 @@ struct tcp_seg { (flags & TF_SEG_OPTS_WND_SCALE ? LWIP_TCP_OPT_LEN_WS_OUT : 0) /** This returns a TCP header option for MSS in an u32_t */ -#define TCP_BUILD_MSS_OPTION(mss) htonl(0x02040000 | ((mss) & 0xFFFF)) +#define TCP_BUILD_MSS_OPTION(mss) lwip_htonl(0x02040000 | ((mss) & 0xFFFF)) #if LWIP_WND_SCALE #define TCPWNDSIZE_F U32_F diff --git a/src/include/lwip/prot/ethernet.h b/src/include/lwip/prot/ethernet.h index 792f5a22..e4baa29d 100644 --- a/src/include/lwip/prot/ethernet.h +++ b/src/include/lwip/prot/ethernet.h @@ -100,7 +100,7 @@ PACK_STRUCT_END #endif #define SIZEOF_VLAN_HDR 4 -#define VLAN_ID(vlan_hdr) (htons((vlan_hdr)->prio_vid) & 0xFFF) +#define VLAN_ID(vlan_hdr) (lwip_htons((vlan_hdr)->prio_vid) & 0xFFF) /** * @ingroup ethernet diff --git a/src/include/lwip/prot/ip6.h b/src/include/lwip/prot/ip6.h index 9a1aaa9f..4e3ca37d 100644 --- a/src/include/lwip/prot/ip6.h +++ b/src/include/lwip/prot/ip6.h @@ -134,16 +134,16 @@ PACK_STRUCT_END # include "arch/epstruct.h" #endif -#define IP6H_V(hdr) ((ntohl((hdr)->_v_tc_fl) >> 28) & 0x0f) -#define IP6H_TC(hdr) ((ntohl((hdr)->_v_tc_fl) >> 20) & 0xff) -#define IP6H_FL(hdr) (ntohl((hdr)->_v_tc_fl) & 0x000fffff) -#define IP6H_PLEN(hdr) (ntohs((hdr)->_plen)) +#define IP6H_V(hdr) ((lwip_ntohl((hdr)->_v_tc_fl) >> 28) & 0x0f) +#define IP6H_TC(hdr) ((lwip_ntohl((hdr)->_v_tc_fl) >> 20) & 0xff) +#define IP6H_FL(hdr) (lwip_ntohl((hdr)->_v_tc_fl) & 0x000fffff) +#define IP6H_PLEN(hdr) (lwip_ntohs((hdr)->_plen)) #define IP6H_NEXTH(hdr) ((hdr)->_nexth) #define IP6H_NEXTH_P(hdr) ((u8_t *)(hdr) + 6) #define IP6H_HOPLIM(hdr) ((hdr)->_hoplim) -#define IP6H_VTCFL_SET(hdr, v, tc, fl) (hdr)->_v_tc_fl = (htonl((((u32_t)(v)) << 28) | (((u32_t)(tc)) << 20) | (fl))) -#define IP6H_PLEN_SET(hdr, plen) (hdr)->_plen = htons(plen) +#define IP6H_VTCFL_SET(hdr, v, tc, fl) (hdr)->_v_tc_fl = (lwip_htonl((((u32_t)(v)) << 28) | (((u32_t)(tc)) << 20) | (fl))) +#define IP6H_PLEN_SET(hdr, plen) (hdr)->_plen = lwip_htons(plen) #define IP6H_NEXTH_SET(hdr, nexth) (hdr)->_nexth = (nexth) #define IP6H_HOPLIM_SET(hdr, hl) (hdr)->_hoplim = (u8_t)(hl) diff --git a/src/include/lwip/prot/tcp.h b/src/include/lwip/prot/tcp.h index 8ef0bf1d..c2c03aa4 100644 --- a/src/include/lwip/prot/tcp.h +++ b/src/include/lwip/prot/tcp.h @@ -80,15 +80,15 @@ PACK_STRUCT_END /* Valid TCP header flags */ #define TCP_FLAGS 0x3fU -#define TCPH_HDRLEN(phdr) ((u16_t)(ntohs((phdr)->_hdrlen_rsvd_flags) >> 12)) -#define TCPH_FLAGS(phdr) ((u16_t)(ntohs((phdr)->_hdrlen_rsvd_flags) & TCP_FLAGS)) +#define TCPH_HDRLEN(phdr) ((u16_t)(lwip_ntohs((phdr)->_hdrlen_rsvd_flags) >> 12)) +#define TCPH_FLAGS(phdr) ((u16_t)(lwip_ntohs((phdr)->_hdrlen_rsvd_flags) & TCP_FLAGS)) -#define TCPH_HDRLEN_SET(phdr, len) (phdr)->_hdrlen_rsvd_flags = htons(((len) << 12) | TCPH_FLAGS(phdr)) -#define TCPH_FLAGS_SET(phdr, flags) (phdr)->_hdrlen_rsvd_flags = (((phdr)->_hdrlen_rsvd_flags & PP_HTONS(~TCP_FLAGS)) | htons(flags)) -#define TCPH_HDRLEN_FLAGS_SET(phdr, len, flags) (phdr)->_hdrlen_rsvd_flags = htons(((len) << 12) | (flags)) +#define TCPH_HDRLEN_SET(phdr, len) (phdr)->_hdrlen_rsvd_flags = lwip_htons(((len) << 12) | TCPH_FLAGS(phdr)) +#define TCPH_FLAGS_SET(phdr, flags) (phdr)->_hdrlen_rsvd_flags = (((phdr)->_hdrlen_rsvd_flags & PP_HTONS(~TCP_FLAGS)) | lwip_htons(flags)) +#define TCPH_HDRLEN_FLAGS_SET(phdr, len, flags) (phdr)->_hdrlen_rsvd_flags = lwip_htons(((len) << 12) | (flags)) -#define TCPH_SET_FLAG(phdr, flags ) (phdr)->_hdrlen_rsvd_flags = ((phdr)->_hdrlen_rsvd_flags | htons(flags)) -#define TCPH_UNSET_FLAG(phdr, flags) (phdr)->_hdrlen_rsvd_flags = ((phdr)->_hdrlen_rsvd_flags & ~htons(flags)) +#define TCPH_SET_FLAG(phdr, flags ) (phdr)->_hdrlen_rsvd_flags = ((phdr)->_hdrlen_rsvd_flags | lwip_htons(flags)) +#define TCPH_UNSET_FLAG(phdr, flags) (phdr)->_hdrlen_rsvd_flags = ((phdr)->_hdrlen_rsvd_flags & ~lwip_htons(flags)) #ifdef __cplusplus } diff --git a/src/include/netif/ppp/eui64.h b/src/include/netif/ppp/eui64.h index 1b5147f4..20ac22ee 100644 --- a/src/include/netif/ppp/eui64.h +++ b/src/include/netif/ppp/eui64.h @@ -84,7 +84,7 @@ typedef union #define eui64_set32(e, l) do { \ (e).e32[0] = 0; \ - (e).e32[1] = htonl(l); \ + (e).e32[1] = lwip_htonl(l); \ } while (0) #define eui64_setlo32(e, l) eui64_set32(e, l) diff --git a/src/include/netif/ppp/mppe.h b/src/include/netif/ppp/mppe.h index 551a47e5..1ae8a5d9 100644 --- a/src/include/netif/ppp/mppe.h +++ b/src/include/netif/ppp/mppe.h @@ -59,7 +59,7 @@ * This is not nice ... the alternative is a bitfield struct though. * And unfortunately, we cannot share the same bits for the option * names above since C and H are the same bit. We could do a u_int32 - * but then we have to do a htonl() all the time and/or we still need + * but then we have to do a lwip_htonl() all the time and/or we still need * to know which octet is which. */ #define MPPE_C_BIT 0x01 /* MPPC */ diff --git a/src/netif/ethernet.c b/src/netif/ethernet.c index 621838e1..246eb459 100644 --- a/src/netif/ethernet.c +++ b/src/netif/ethernet.c @@ -98,7 +98,7 @@ ethernet_input(struct pbuf *p, struct netif *netif) (unsigned)ethhdr->dest.addr[3], (unsigned)ethhdr->dest.addr[4], (unsigned)ethhdr->dest.addr[5], (unsigned)ethhdr->src.addr[0], (unsigned)ethhdr->src.addr[1], (unsigned)ethhdr->src.addr[2], (unsigned)ethhdr->src.addr[3], (unsigned)ethhdr->src.addr[4], (unsigned)ethhdr->src.addr[5], - htons(ethhdr->type))); + lwip_htons(ethhdr->type))); type = ethhdr->type; #if ETHARP_SUPPORT_VLAN @@ -130,7 +130,7 @@ ethernet_input(struct pbuf *p, struct netif *netif) #endif /* ETHARP_SUPPORT_VLAN */ #if LWIP_ARP_FILTER_NETIF - netif = LWIP_ARP_FILTER_NETIF_FN(p, netif, htons(type)); + netif = LWIP_ARP_FILTER_NETIF_FN(p, netif, lwip_htons(type)); #endif /* LWIP_ARP_FILTER_NETIF*/ if (ethhdr->dest.addr[0] & 1) { @@ -262,7 +262,7 @@ ethernet_output(struct netif* netif, struct pbuf* p, u16_t eth_type) { struct eth_hdr* ethhdr; - u16_t eth_type_be = htons(eth_type); + u16_t eth_type_be = lwip_htons(eth_type); #if ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET) s32_t vlan_prio_vid = LWIP_HOOK_VLAN_SET(netif, p, src, dst, eth_type); @@ -276,7 +276,7 @@ ethernet_output(struct netif* netif, struct pbuf* p, } vlanhdr = (struct eth_vlan_hdr*)(((u8_t*)p->payload) + SIZEOF_ETH_HDR); vlanhdr->tpid = eth_type_be; - vlanhdr->prio_vid = htons((u16_t)vlan_prio_vid); + vlanhdr->prio_vid = lwip_htons((u16_t)vlan_prio_vid); eth_type_be = PP_HTONS(ETHTYPE_VLAN); } else diff --git a/src/netif/lowpan6.c b/src/netif/lowpan6.c index 407848c4..eb0fe71d 100644 --- a/src/netif/lowpan6.c +++ b/src/netif/lowpan6.c @@ -160,13 +160,13 @@ lowpan6_get_address_mode(const ip6_addr_t *ip6addr, const struct ieee_802154_add if (mac_addr->addr_len == 2) { if ((ip6addr->addr[2] == (u32_t)PP_HTONL(0x000000ff)) && ((ip6addr->addr[3] & PP_HTONL(0xffff0000)) == PP_NTOHL(0xfe000000))) { - if ((ip6addr->addr[3] & PP_HTONL(0x0000ffff)) == ntohl((mac_addr->addr[0] << 8) | mac_addr->addr[1])) { + if ((ip6addr->addr[3] & PP_HTONL(0x0000ffff)) == lwip_ntohl((mac_addr->addr[0] << 8) | mac_addr->addr[1])) { return 3; } } } else if (mac_addr->addr_len == 8) { - if ((ip6addr->addr[2] == ntohl(((mac_addr->addr[0] ^ 2) << 24) | (mac_addr->addr[1] << 16) | mac_addr->addr[2] << 8 | mac_addr->addr[3])) && - (ip6addr->addr[3] == ntohl((mac_addr->addr[4] << 24) | (mac_addr->addr[5] << 16) | mac_addr->addr[6] << 8 | mac_addr->addr[7]))) { + if ((ip6addr->addr[2] == lwip_ntohl(((mac_addr->addr[0] ^ 2) << 24) | (mac_addr->addr[1] << 16) | mac_addr->addr[2] << 8 | mac_addr->addr[3])) && + (ip6addr->addr[3] == lwip_ntohl((mac_addr->addr[4] << 24) | (mac_addr->addr[5] << 16) | mac_addr->addr[6] << 8 | mac_addr->addr[7]))) { return 3; } } @@ -768,7 +768,7 @@ lowpan6_decompress(struct pbuf * p, struct ieee_802154_addr * src, struct ieee_8 ip6hdr->src.addr[0] = PP_HTONL(0xfe800000UL); ip6hdr->src.addr[1] = 0; ip6hdr->src.addr[2] = PP_HTONL(0x000000ffUL); - ip6hdr->src.addr[3] = htonl(0xfe000000UL | (lowpan6_buffer[lowpan6_offset] << 8) | + ip6hdr->src.addr[3] = lwip_htonl(0xfe000000UL | (lowpan6_buffer[lowpan6_offset] << 8) | lowpan6_buffer[lowpan6_offset+1]); lowpan6_offset += 2; } else if ((lowpan6_buffer[1] & 0x30) == 0x30) { @@ -776,11 +776,11 @@ lowpan6_decompress(struct pbuf * p, struct ieee_802154_addr * src, struct ieee_8 ip6hdr->src.addr[1] = 0; if (src->addr_len == 2) { ip6hdr->src.addr[2] = PP_HTONL(0x000000ffUL); - ip6hdr->src.addr[3] = htonl(0xfe000000UL | (src->addr[0] << 8) | src->addr[1]); + ip6hdr->src.addr[3] = lwip_htonl(0xfe000000UL | (src->addr[0] << 8) | src->addr[1]); } else { - ip6hdr->src.addr[2] = htonl(((src->addr[0] ^ 2) << 24) | (src->addr[1] << 16) | + ip6hdr->src.addr[2] = lwip_htonl(((src->addr[0] ^ 2) << 24) | (src->addr[1] << 16) | (src->addr[2] << 8) | src->addr[3]); - ip6hdr->src.addr[3] = htonl((src->addr[4] << 24) | (src->addr[5] << 16) | + ip6hdr->src.addr[3] = lwip_htonl((src->addr[4] << 24) | (src->addr[5] << 16) | (src->addr[6] << 8) | src->addr[7]); } } @@ -815,15 +815,15 @@ lowpan6_decompress(struct pbuf * p, struct ieee_802154_addr * src, struct ieee_8 lowpan6_offset += 8; } else if ((lowpan6_buffer[1] & 0x30) == 0x20) { ip6hdr->src.addr[2] = PP_HTONL(0x000000ffUL); - ip6hdr->src.addr[3] = htonl(0xfe000000UL | (lowpan6_buffer[lowpan6_offset] << 8) | lowpan6_buffer[lowpan6_offset+1]); + ip6hdr->src.addr[3] = lwip_htonl(0xfe000000UL | (lowpan6_buffer[lowpan6_offset] << 8) | lowpan6_buffer[lowpan6_offset+1]); lowpan6_offset += 2; } else if ((lowpan6_buffer[1] & 0x30) == 0x30) { if (src->addr_len == 2) { ip6hdr->src.addr[2] = PP_HTONL(0x000000ffUL); - ip6hdr->src.addr[3] = htonl(0xfe000000UL | (src->addr[0] << 8) | src->addr[1]); + ip6hdr->src.addr[3] = lwip_htonl(0xfe000000UL | (src->addr[0] << 8) | src->addr[1]); } else { - ip6hdr->src.addr[2] = htonl(((src->addr[0] ^ 2) << 24) | (src->addr[1] << 16) | (src->addr[2] << 8) | src->addr[3]); - ip6hdr->src.addr[3] = htonl((src->addr[4] << 24) | (src->addr[5] << 16) | (src->addr[6] << 8) | src->addr[7]); + ip6hdr->src.addr[2] = lwip_htonl(((src->addr[0] ^ 2) << 24) | (src->addr[1] << 16) | (src->addr[2] << 8) | src->addr[3]); + ip6hdr->src.addr[3] = lwip_htonl((src->addr[4] << 24) | (src->addr[5] << 16) | (src->addr[6] << 8) | src->addr[7]); } } } @@ -843,22 +843,22 @@ lowpan6_decompress(struct pbuf * p, struct ieee_802154_addr * src, struct ieee_8 MEMCPY(&ip6hdr->dest.addr[0], lowpan6_buffer + lowpan6_offset, 16); lowpan6_offset += 16; } else if ((lowpan6_buffer[1] & 0x03) == 0x01) { - ip6hdr->dest.addr[0] = htonl(0xff000000UL | (lowpan6_buffer[lowpan6_offset++] << 16)); + ip6hdr->dest.addr[0] = lwip_htonl(0xff000000UL | (lowpan6_buffer[lowpan6_offset++] << 16)); ip6hdr->dest.addr[1] = 0; - ip6hdr->dest.addr[2] = htonl(lowpan6_buffer[lowpan6_offset++]); - ip6hdr->dest.addr[3] = htonl((lowpan6_buffer[lowpan6_offset] << 24) | (lowpan6_buffer[lowpan6_offset + 1] << 16) | (lowpan6_buffer[lowpan6_offset + 2] << 8) | lowpan6_buffer[lowpan6_offset + 3]); + ip6hdr->dest.addr[2] = lwip_htonl(lowpan6_buffer[lowpan6_offset++]); + ip6hdr->dest.addr[3] = lwip_htonl((lowpan6_buffer[lowpan6_offset] << 24) | (lowpan6_buffer[lowpan6_offset + 1] << 16) | (lowpan6_buffer[lowpan6_offset + 2] << 8) | lowpan6_buffer[lowpan6_offset + 3]); lowpan6_offset += 4; } else if ((lowpan6_buffer[1] & 0x03) == 0x02) { - ip6hdr->dest.addr[0] = htonl(0xff000000UL | lowpan6_buffer[lowpan6_offset++]); + ip6hdr->dest.addr[0] = lwip_htonl(0xff000000UL | lowpan6_buffer[lowpan6_offset++]); ip6hdr->dest.addr[1] = 0; ip6hdr->dest.addr[2] = 0; - ip6hdr->dest.addr[3] = htonl((lowpan6_buffer[lowpan6_offset] << 16) | (lowpan6_buffer[lowpan6_offset + 1] << 8) | lowpan6_buffer[lowpan6_offset + 2]); + ip6hdr->dest.addr[3] = lwip_htonl((lowpan6_buffer[lowpan6_offset] << 16) | (lowpan6_buffer[lowpan6_offset + 1] << 8) | lowpan6_buffer[lowpan6_offset + 2]); lowpan6_offset += 3; } else if ((lowpan6_buffer[1] & 0x03) == 0x03) { ip6hdr->dest.addr[0] = PP_HTONL(0xff020000UL); ip6hdr->dest.addr[1] = 0; ip6hdr->dest.addr[2] = 0; - ip6hdr->dest.addr[3] = htonl(lowpan6_buffer[lowpan6_offset++]); + ip6hdr->dest.addr[3] = lwip_htonl(lowpan6_buffer[lowpan6_offset++]); } } else { @@ -894,15 +894,15 @@ lowpan6_decompress(struct pbuf * p, struct ieee_802154_addr * src, struct ieee_8 lowpan6_offset += 8; } else if ((lowpan6_buffer[1] & 0x03) == 0x02) { ip6hdr->dest.addr[2] = PP_HTONL(0x000000ffUL); - ip6hdr->dest.addr[3] = htonl(0xfe000000UL | (lowpan6_buffer[lowpan6_offset] << 8) | lowpan6_buffer[lowpan6_offset + 1]); + ip6hdr->dest.addr[3] = lwip_htonl(0xfe000000UL | (lowpan6_buffer[lowpan6_offset] << 8) | lowpan6_buffer[lowpan6_offset + 1]); lowpan6_offset += 2; } else if ((lowpan6_buffer[1] & 0x03) == 0x03) { if (dest->addr_len == 2) { ip6hdr->dest.addr[2] = PP_HTONL(0x000000ffUL); - ip6hdr->dest.addr[3] = htonl(0xfe000000UL | (dest->addr[0] << 8) | dest->addr[1]); + ip6hdr->dest.addr[3] = lwip_htonl(0xfe000000UL | (dest->addr[0] << 8) | dest->addr[1]); } else { - ip6hdr->dest.addr[2] = htonl(((dest->addr[0] ^ 2) << 24) | (dest->addr[1] << 16) | dest->addr[2] << 8 | dest->addr[3]); - ip6hdr->dest.addr[3] = htonl((dest->addr[4] << 24) | (dest->addr[5] << 16) | dest->addr[6] << 8 | dest->addr[7]); + ip6hdr->dest.addr[2] = lwip_htonl(((dest->addr[0] ^ 2) << 24) | (dest->addr[1] << 16) | dest->addr[2] << 8 | dest->addr[3]); + ip6hdr->dest.addr[3] = lwip_htonl((dest->addr[4] << 24) | (dest->addr[5] << 16) | dest->addr[6] << 8 | dest->addr[7]); } } } @@ -927,26 +927,26 @@ lowpan6_decompress(struct pbuf * p, struct ieee_802154_addr * src, struct ieee_8 /* Decompress ports */ i = lowpan6_buffer[lowpan6_offset++] & 0x03; if (i == 0) { - udphdr->src = htons(lowpan6_buffer[lowpan6_offset] << 8 | lowpan6_buffer[lowpan6_offset + 1]); - udphdr->dest = htons(lowpan6_buffer[lowpan6_offset + 2] << 8 | lowpan6_buffer[lowpan6_offset + 3]); + udphdr->src = lwip_htons(lowpan6_buffer[lowpan6_offset] << 8 | lowpan6_buffer[lowpan6_offset + 1]); + udphdr->dest = lwip_htons(lowpan6_buffer[lowpan6_offset + 2] << 8 | lowpan6_buffer[lowpan6_offset + 3]); lowpan6_offset += 4; } else if (i == 0x01) { - udphdr->src = htons(lowpan6_buffer[lowpan6_offset] << 8 | lowpan6_buffer[lowpan6_offset + 1]); - udphdr->dest = htons(0xf000 | lowpan6_buffer[lowpan6_offset + 2]); + udphdr->src = lwip_htons(lowpan6_buffer[lowpan6_offset] << 8 | lowpan6_buffer[lowpan6_offset + 1]); + udphdr->dest = lwip_htons(0xf000 | lowpan6_buffer[lowpan6_offset + 2]); lowpan6_offset += 3; } else if (i == 0x02) { - udphdr->src = htons(0xf000 | lowpan6_buffer[lowpan6_offset]); - udphdr->dest = htons(lowpan6_buffer[lowpan6_offset + 1] << 8 | lowpan6_buffer[lowpan6_offset + 2]); + udphdr->src = lwip_htons(0xf000 | lowpan6_buffer[lowpan6_offset]); + udphdr->dest = lwip_htons(lowpan6_buffer[lowpan6_offset + 1] << 8 | lowpan6_buffer[lowpan6_offset + 2]); lowpan6_offset += 3; } else if (i == 0x03) { - udphdr->src = htons(0xf0b0 | ((lowpan6_buffer[lowpan6_offset] >> 4) & 0x0f)); - udphdr->dest = htons(0xf0b0 | (lowpan6_buffer[lowpan6_offset] & 0x0f)); + udphdr->src = lwip_htons(0xf0b0 | ((lowpan6_buffer[lowpan6_offset] >> 4) & 0x0f)); + udphdr->dest = lwip_htons(0xf0b0 | (lowpan6_buffer[lowpan6_offset] & 0x0f)); lowpan6_offset += 1; } - udphdr->chksum = htons(lowpan6_buffer[lowpan6_offset] << 8 | lowpan6_buffer[lowpan6_offset + 1]); + udphdr->chksum = lwip_htons(lowpan6_buffer[lowpan6_offset] << 8 | lowpan6_buffer[lowpan6_offset + 1]); lowpan6_offset += 2; - udphdr->len = htons(p->tot_len - lowpan6_offset + UDP_HLEN); + udphdr->len = lwip_htons(p->tot_len - lowpan6_offset + UDP_HLEN); ip6_offset += UDP_HLEN; } else { diff --git a/src/netif/ppp/auth.c b/src/netif/ppp/auth.c index 109c1467..c8673ad0 100644 --- a/src/netif/ppp/auth.c +++ b/src/netif/ppp/auth.c @@ -2121,10 +2121,10 @@ set_allowed_addrs(unit, addrs, opts) } else { np = getnetbyname (ptr_word); if (np != NULL && np->n_addrtype == AF_INET) { - a = htonl ((u32_t)np->n_net); + a = lwip_htonl ((u32_t)np->n_net); if (ptr_mask == NULL) { /* calculate appropriate mask for net */ - ah = ntohl(a); + ah = lwip_ntohl(a); if (IN_CLASSA(ah)) mask = IN_CLASSA_NET; else if (IN_CLASSB(ah)) @@ -2150,10 +2150,10 @@ set_allowed_addrs(unit, addrs, opts) ifunit, ptr_word); continue; } - a = htonl((ntohl(a) & mask) + offset); + a = lwip_htonl((lwip_ntohl(a) & mask) + offset); mask = ~(u32_t)0; } - ip[n].mask = htonl(mask); + ip[n].mask = lwip_htonl(mask); ip[n].base = a & ip[n].mask; ++n; if (~mask == 0 && suggested_ip == 0) @@ -2234,7 +2234,7 @@ int bad_ip_adrs(addr) u32_t addr; { - addr = ntohl(addr); + addr = lwip_ntohl(addr); return (addr >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET || IN_MULTICAST(addr) || IN_BADCLASS(addr); } diff --git a/src/netif/ppp/ipcp.c b/src/netif/ppp/ipcp.c index 2cdcba85..7d9d6fd8 100644 --- a/src/netif/ppp/ipcp.c +++ b/src/netif/ppp/ipcp.c @@ -542,7 +542,7 @@ setnetmask(argv) p = *argv; n = parse_dotted_ip(p, &mask); - mask = htonl(mask); + mask = lwip_htonl(mask); if (n == 0 || p[n] != 0 || (netmask & ~mask) != 0) { option_error("invalid netmask value '%s'", *argv); @@ -822,9 +822,9 @@ static void ipcp_addci(fsm *f, u_char *ucp, int *lenp) { u32_t l; \ PUTCHAR(opt, ucp); \ PUTCHAR(CILEN_ADDRS, ucp); \ - l = ntohl(val1); \ + l = lwip_ntohl(val1); \ PUTLONG(l, ucp); \ - l = ntohl(val2); \ + l = lwip_ntohl(val2); \ PUTLONG(l, ucp); \ len -= CILEN_ADDRS; \ } else \ @@ -855,7 +855,7 @@ static void ipcp_addci(fsm *f, u_char *ucp, int *lenp) { u32_t l; \ PUTCHAR(opt, ucp); \ PUTCHAR(CILEN_ADDR, ucp); \ - l = ntohl(val); \ + l = lwip_ntohl(val); \ PUTLONG(l, ucp); \ len -= CILEN_ADDR; \ } else \ @@ -869,7 +869,7 @@ static void ipcp_addci(fsm *f, u_char *ucp, int *lenp) { u32_t l; \ PUTCHAR(opt, ucp); \ PUTCHAR(CILEN_ADDR, ucp); \ - l = ntohl(addr); \ + l = lwip_ntohl(addr); \ PUTLONG(l, ucp); \ len -= CILEN_ADDR; \ } else \ @@ -884,7 +884,7 @@ static void ipcp_addci(fsm *f, u_char *ucp, int *lenp) { u32_t l; \ PUTCHAR(opt, ucp); \ PUTCHAR(CILEN_ADDR, ucp); \ - l = ntohl(addr); \ + l = lwip_ntohl(addr); \ PUTLONG(l, ucp); \ len -= CILEN_ADDR; \ } else \ @@ -953,11 +953,11 @@ static int ipcp_ackci(fsm *f, u_char *p, int len) { citype != opt) \ goto bad; \ GETLONG(l, p); \ - cilong = htonl(l); \ + cilong = lwip_htonl(l); \ if (val1 != cilong) \ goto bad; \ GETLONG(l, p); \ - cilong = htonl(l); \ + cilong = lwip_htonl(l); \ if (val2 != cilong) \ goto bad; \ } @@ -998,7 +998,7 @@ static int ipcp_ackci(fsm *f, u_char *p, int len) { citype != opt) \ goto bad; \ GETLONG(l, p); \ - cilong = htonl(l); \ + cilong = lwip_htonl(l); \ if (val != cilong) \ goto bad; \ } @@ -1014,7 +1014,7 @@ static int ipcp_ackci(fsm *f, u_char *p, int len) { if (cilen != CILEN_ADDR || citype != opt) \ goto bad; \ GETLONG(l, p); \ - cilong = htonl(l); \ + cilong = lwip_htonl(l); \ if (addr != cilong) \ goto bad; \ } @@ -1031,7 +1031,7 @@ static int ipcp_ackci(fsm *f, u_char *p, int len) { if (cilen != CILEN_ADDR || citype != opt) \ goto bad; \ GETLONG(l, p); \ - cilong = htonl(l); \ + cilong = lwip_htonl(l); \ if (addr != cilong) \ goto bad; \ } @@ -1112,9 +1112,9 @@ static int ipcp_nakci(fsm *f, u_char *p, int len, int treat_as_reject) { len -= cilen; \ INCPTR(2, p); \ GETLONG(l, p); \ - ciaddr1 = htonl(l); \ + ciaddr1 = lwip_htonl(l); \ GETLONG(l, p); \ - ciaddr2 = htonl(l); \ + ciaddr2 = lwip_htonl(l); \ no.old_addrs = 1; \ code \ } @@ -1141,7 +1141,7 @@ static int ipcp_nakci(fsm *f, u_char *p, int len, int treat_as_reject) { len -= cilen; \ INCPTR(2, p); \ GETLONG(l, p); \ - ciaddr1 = htonl(l); \ + ciaddr1 = lwip_htonl(l); \ no.neg = 1; \ code \ } @@ -1155,7 +1155,7 @@ static int ipcp_nakci(fsm *f, u_char *p, int len, int treat_as_reject) { len -= cilen; \ INCPTR(2, p); \ GETLONG(l, p); \ - cidnsaddr = htonl(l); \ + cidnsaddr = lwip_htonl(l); \ no.neg = 1; \ code \ } @@ -1271,11 +1271,11 @@ static int ipcp_nakci(fsm *f, u_char *p, int len, int treat_as_reject) { goto bad; try_.neg_addr = 0; GETLONG(l, p); - ciaddr1 = htonl(l); + ciaddr1 = lwip_htonl(l); if (ciaddr1 && go->accept_local) try_.ouraddr = ciaddr1; GETLONG(l, p); - ciaddr2 = htonl(l); + ciaddr2 = lwip_htonl(l); if (ciaddr2 && go->accept_remote) try_.hisaddr = ciaddr2; no.old_addrs = 1; @@ -1285,7 +1285,7 @@ static int ipcp_nakci(fsm *f, u_char *p, int len, int treat_as_reject) { goto bad; try_.old_addrs = 0; GETLONG(l, p); - ciaddr1 = htonl(l); + ciaddr1 = lwip_htonl(l); if (ciaddr1 && go->accept_local) try_.ouraddr = ciaddr1; if (try_.ouraddr != 0) @@ -1297,7 +1297,7 @@ static int ipcp_nakci(fsm *f, u_char *p, int len, int treat_as_reject) { if (go->req_dns1 || no.req_dns1 || cilen != CILEN_ADDR) goto bad; GETLONG(l, p); - try_.dnsaddr[0] = htonl(l); + try_.dnsaddr[0] = lwip_htonl(l); try_.req_dns1 = 1; no.req_dns1 = 1; break; @@ -1305,7 +1305,7 @@ static int ipcp_nakci(fsm *f, u_char *p, int len, int treat_as_reject) { if (go->req_dns2 || no.req_dns2 || cilen != CILEN_ADDR) goto bad; GETLONG(l, p); - try_.dnsaddr[1] = htonl(l); + try_.dnsaddr[1] = lwip_htonl(l); try_.req_dns2 = 1; no.req_dns2 = 1; break; @@ -1316,7 +1316,7 @@ static int ipcp_nakci(fsm *f, u_char *p, int len, int treat_as_reject) { if (cilen != CILEN_ADDR) goto bad; GETLONG(l, p); - ciaddr1 = htonl(l); + ciaddr1 = lwip_htonl(l); if (ciaddr1) try_.winsaddr[citype == CI_MS_WINS2] = ciaddr1; break; @@ -1372,12 +1372,12 @@ static int ipcp_rejci(fsm *f, u_char *p, int len) { len -= cilen; \ INCPTR(2, p); \ GETLONG(l, p); \ - cilong = htonl(l); \ + cilong = lwip_htonl(l); \ /* Check rejected value. */ \ if (cilong != val1) \ goto bad; \ GETLONG(l, p); \ - cilong = htonl(l); \ + cilong = lwip_htonl(l); \ /* Check rejected value. */ \ if (cilong != val2) \ goto bad; \ @@ -1417,7 +1417,7 @@ static int ipcp_rejci(fsm *f, u_char *p, int len) { len -= cilen; \ INCPTR(2, p); \ GETLONG(l, p); \ - cilong = htonl(l); \ + cilong = lwip_htonl(l); \ /* Check rejected value. */ \ if (cilong != val) \ goto bad; \ @@ -1434,7 +1434,7 @@ static int ipcp_rejci(fsm *f, u_char *p, int len) { len -= cilen; \ INCPTR(2, p); \ GETLONG(l, p); \ - cilong = htonl(l); \ + cilong = lwip_htonl(l); \ /* Check rejected value. */ \ if (cilong != dnsaddr) \ goto bad; \ @@ -1452,7 +1452,7 @@ static int ipcp_rejci(fsm *f, u_char *p, int len) { len -= cilen; \ INCPTR(2, p); \ GETLONG(l, p); \ - cilong = htonl(l); \ + cilong = lwip_htonl(l); \ /* Check rejected value. */ \ if (cilong != addr) \ goto bad; \ @@ -1575,13 +1575,13 @@ static int ipcp_reqci(fsm *f, u_char *inp, int *len, int reject_if_disagree) { * then accept it. */ GETLONG(tl, p); /* Parse source address (his) */ - ciaddr1 = htonl(tl); + ciaddr1 = lwip_htonl(tl); if (ciaddr1 != wo->hisaddr && (ciaddr1 == 0 || !wo->accept_remote)) { orc = CONFNAK; if (!reject_if_disagree) { DECPTR(sizeof(u32_t), p); - tl = ntohl(wo->hisaddr); + tl = lwip_ntohl(wo->hisaddr); PUTLONG(tl, p); } } else if (ciaddr1 == 0 && wo->hisaddr == 0) { @@ -1598,13 +1598,13 @@ static int ipcp_reqci(fsm *f, u_char *inp, int *len, int reject_if_disagree) { * but disagree about it, then NAK it with our idea. */ GETLONG(tl, p); /* Parse desination address (ours) */ - ciaddr2 = htonl(tl); + ciaddr2 = lwip_htonl(tl); if (ciaddr2 != wo->ouraddr) { if (ciaddr2 == 0 || !wo->accept_local) { orc = CONFNAK; if (!reject_if_disagree) { DECPTR(sizeof(u32_t), p); - tl = ntohl(wo->ouraddr); + tl = lwip_ntohl(wo->ouraddr); PUTLONG(tl, p); } } else { @@ -1631,13 +1631,13 @@ static int ipcp_reqci(fsm *f, u_char *inp, int *len, int reject_if_disagree) { * then accept it. */ GETLONG(tl, p); /* Parse source address (his) */ - ciaddr1 = htonl(tl); + ciaddr1 = lwip_htonl(tl); if (ciaddr1 != wo->hisaddr && (ciaddr1 == 0 || !wo->accept_remote)) { orc = CONFNAK; if (!reject_if_disagree) { DECPTR(sizeof(u32_t), p); - tl = ntohl(wo->hisaddr); + tl = lwip_ntohl(wo->hisaddr); PUTLONG(tl, p); } } else if (ciaddr1 == 0 && wo->hisaddr == 0) { @@ -1666,9 +1666,9 @@ static int ipcp_reqci(fsm *f, u_char *inp, int *len, int reject_if_disagree) { break; } GETLONG(tl, p); - if (htonl(tl) != ao->dnsaddr[d]) { + if (lwip_htonl(tl) != ao->dnsaddr[d]) { DECPTR(sizeof(u32_t), p); - tl = ntohl(ao->dnsaddr[d]); + tl = lwip_ntohl(ao->dnsaddr[d]); PUTLONG(tl, p); orc = CONFNAK; } @@ -1688,9 +1688,9 @@ static int ipcp_reqci(fsm *f, u_char *inp, int *len, int reject_if_disagree) { break; } GETLONG(tl, p); - if (htonl(tl) != ao->winsaddr[d]) { + if (lwip_htonl(tl) != ao->winsaddr[d]) { DECPTR(sizeof(u32_t), p); - tl = ntohl(ao->winsaddr[d]); + tl = lwip_ntohl(ao->winsaddr[d]); PUTLONG(tl, p); orc = CONFNAK; } @@ -1793,7 +1793,7 @@ endswitch: } PUTCHAR(CI_ADDR, ucp); PUTCHAR(CILEN_ADDR, ucp); - tl = ntohl(wo->hisaddr); + tl = lwip_ntohl(wo->hisaddr); PUTLONG(tl, ucp); } @@ -1850,12 +1850,12 @@ ip_demand_conf(u) if (wo->hisaddr == 0 && !pcb->settings.noremoteip) { /* make up an arbitrary address for the peer */ - wo->hisaddr = htonl(0x0a707070 + ifunit); + wo->hisaddr = lwip_htonl(0x0a707070 + ifunit); wo->accept_remote = 1; } if (wo->ouraddr == 0) { /* make up an arbitrary address for us */ - wo->ouraddr = htonl(0x0a404040 + ifunit); + wo->ouraddr = lwip_htonl(0x0a404040 + ifunit); wo->accept_local = 1; ask_for_local = 0; /* don't tell the peer this address */ } @@ -1917,7 +1917,7 @@ static void ipcp_up(fsm *f) { return; } if (ho->hisaddr == 0 && !pcb->settings.noremoteip) { - ho->hisaddr = htonl(0x0a404040); + ho->hisaddr = lwip_htonl(0x0a404040); ppp_warn("Could not determine remote IP address: defaulting to %I", ho->hisaddr); } @@ -2271,9 +2271,9 @@ static int ipcp_printpkt(const u_char *p, int plen, if (olen == CILEN_ADDRS) { p += 2; GETLONG(cilong, p); - printer(arg, "addrs %I", htonl(cilong)); + printer(arg, "addrs %I", lwip_htonl(cilong)); GETLONG(cilong, p); - printer(arg, " %I", htonl(cilong)); + printer(arg, " %I", lwip_htonl(cilong)); } break; #if VJ_SUPPORT @@ -2299,7 +2299,7 @@ static int ipcp_printpkt(const u_char *p, int plen, if (olen == CILEN_ADDR) { p += 2; GETLONG(cilong, p); - printer(arg, "addr %I", htonl(cilong)); + printer(arg, "addr %I", lwip_htonl(cilong)); } break; #if LWIP_DNS @@ -2316,7 +2316,7 @@ static int ipcp_printpkt(const u_char *p, int plen, case CI_MS_WINS2: p += 2; GETLONG(cilong, p); - printer(arg, "ms-wins %I", htonl(cilong)); + printer(arg, "ms-wins %I", lwip_htonl(cilong)); break; #endif /* UNUSED - WINS */ default: diff --git a/src/netif/ppp/ipv6cp.c b/src/netif/ppp/ipv6cp.c index f0f4eee0..11c18df7 100644 --- a/src/netif/ppp/ipv6cp.c +++ b/src/netif/ppp/ipv6cp.c @@ -1093,7 +1093,7 @@ static void ipv6_check_options() { if (!wo->opt_local) { /* init interface identifier */ if (wo->use_ip && eui64_iszero(wo->ourid)) { - eui64_setlo32(wo->ourid, ntohl(ipcp_wantoptions[0].ouraddr)); + eui64_setlo32(wo->ourid, lwip_ntohl(ipcp_wantoptions[0].ouraddr)); if (!eui64_iszero(wo->ourid)) wo->opt_local = 1; } @@ -1104,7 +1104,7 @@ static void ipv6_check_options() { if (!wo->opt_remote) { if (wo->use_ip && eui64_iszero(wo->hisid)) { - eui64_setlo32(wo->hisid, ntohl(ipcp_wantoptions[0].hisaddr)); + eui64_setlo32(wo->hisid, lwip_ntohl(ipcp_wantoptions[0].hisaddr)); if (!eui64_iszero(wo->hisid)) wo->opt_remote = 1; } diff --git a/src/netif/ppp/multilink.c b/src/netif/ppp/multilink.c index 0d617a0f..62014e8c 100644 --- a/src/netif/ppp/multilink.c +++ b/src/netif/ppp/multilink.c @@ -469,7 +469,7 @@ get_default_epdisc(ep) if (hp != NULL) { addr = *(u32_t *)hp->h_addr; if (!bad_ip_adrs(addr)) { - addr = ntohl(addr); + addr = lwip_ntohl(addr); if (!LOCAL_IP_ADDR(addr)) { ep->class = EPD_IP; set_ip_epdisc(ep, addr); @@ -504,7 +504,7 @@ epdisc_to_str(ep) u32_t addr; GETLONG(addr, p); - slprintf(str, sizeof(str), "IP:%I", htonl(addr)); + slprintf(str, sizeof(str), "IP:%I", lwip_htonl(addr)); return str; } diff --git a/src/netif/ppp/ppp.c b/src/netif/ppp/ppp.c index 4bd17003..39c3c240 100644 --- a/src/netif/ppp/ppp.c +++ b/src/netif/ppp/ppp.c @@ -1219,7 +1219,7 @@ u32_t get_mask(u32_t addr) { #if 0 u32_t mask, nmask; - addr = htonl(addr); + addr = lwip_htonl(addr); if (IP_CLASSA(addr)) { /* determine network mask for address class */ nmask = IP_CLASSA_NET; } else if (IP_CLASSB(addr)) { @@ -1229,7 +1229,7 @@ u32_t get_mask(u32_t addr) { } /* class D nets are disallowed by bad_ip_adrs */ - mask = PP_HTONL(0xffffff00UL) | htonl(nmask); + mask = PP_HTONL(0xffffff00UL) | lwip_htonl(nmask); /* XXX * Scan through the system's network interfaces. diff --git a/src/netif/ppp/pppoe.c b/src/netif/ppp/pppoe.c index 768d22be..ed061c31 100644 --- a/src/netif/ppp/pppoe.c +++ b/src/netif/ppp/pppoe.c @@ -419,8 +419,8 @@ pppoe_disc_input(struct netif *netif, struct pbuf *pb) PPPDEBUG(LOG_DEBUG, ("pppoe: unknown version/type packet: 0x%x\n", ph->vertype)); goto done; } - session = ntohs(ph->session); - plen = ntohs(ph->plen); + session = lwip_ntohs(ph->session); + plen = lwip_ntohs(ph->plen); off += sizeof(*ph); if (plen + off > pb->len) { @@ -436,8 +436,8 @@ pppoe_disc_input(struct netif *netif, struct pbuf *pb) sc = NULL; while (off + sizeof(pt) <= pb->len) { MEMCPY(&pt, (u8_t*)pb->payload + off, sizeof(pt)); - tag = ntohs(pt.tag); - len = ntohs(pt.len); + tag = lwip_ntohs(pt.tag); + len = lwip_ntohs(pt.len); if (off + sizeof(pt) + len > pb->len) { PPPDEBUG(LOG_DEBUG, ("pppoe: tag 0x%x len 0x%x is too long\n", tag, len)); goto done; @@ -680,7 +680,7 @@ pppoe_data_input(struct netif *netif, struct pbuf *pb) goto drop; } - session = ntohs(ph->session); + session = lwip_ntohs(ph->session); sc = pppoe_find_softc_by_session(session, netif); if (sc == NULL) { #ifdef PPPOE_TERM_UNKNOWN_SESSIONS @@ -690,7 +690,7 @@ pppoe_data_input(struct netif *netif, struct pbuf *pb) goto drop; } - plen = ntohs(ph->plen); + plen = lwip_ntohs(ph->plen); if (pbuf_header(pb, -(s16_t)(PPPOE_HEADERLEN)) != 0) { /* bail out */ @@ -732,7 +732,7 @@ pppoe_output(struct pppoe_softc *sc, struct pbuf *pb) } ethhdr = (struct eth_hdr *)pb->payload; etype = sc->sc_state == PPPOE_STATE_SESSION ? ETHTYPE_PPPOE : ETHTYPE_PPPOEDISC; - ethhdr->type = htons(etype); + ethhdr->type = lwip_htons(etype); MEMCPY(ðhdr->dest.addr, &sc->sc_dest.addr, sizeof(ethhdr->dest.addr)); MEMCPY(ðhdr->src.addr, &sc->sc_ethif->hwaddr, sizeof(ethhdr->src.addr)); diff --git a/src/netif/ppp/utils.c b/src/netif/ppp/utils.c index 1d44e9c3..a5ae86f0 100644 --- a/src/netif/ppp/utils.c +++ b/src/netif/ppp/utils.c @@ -267,7 +267,7 @@ int ppp_vslprintf(char *buf, int buflen, const char *fmt, va_list args) { #endif /* do we always have strerror() in embedded ? */ case 'I': ip = va_arg(args, u32_t); - ip = ntohl(ip); + ip = lwip_ntohl(ip); ppp_slprintf(num, sizeof(num), "%d.%d.%d.%d", (ip >> 24) & 0xff, (ip >> 16) & 0xff, (ip >> 8) & 0xff, ip & 0xff); str = num; diff --git a/src/netif/ppp/vj.c b/src/netif/ppp/vj.c index dadb38d6..168c3400 100644 --- a/src/netif/ppp/vj.c +++ b/src/netif/ppp/vj.c @@ -95,32 +95,32 @@ vj_compress_init(struct vjcompress *comp) #define DECODEL(f) { \ if (*cp == 0) {\ - u32_t tmp_ = ntohl(f) + ((cp[1] << 8) | cp[2]); \ - (f) = htonl(tmp_); \ + u32_t tmp_ = lwip_ntohl(f) + ((cp[1] << 8) | cp[2]); \ + (f) = lwip_htonl(tmp_); \ cp += 3; \ } else { \ - u32_t tmp_ = ntohl(f) + (u32_t)*cp++; \ - (f) = htonl(tmp_); \ + u32_t tmp_ = lwip_ntohl(f) + (u32_t)*cp++; \ + (f) = lwip_htonl(tmp_); \ } \ } #define DECODES(f) { \ if (*cp == 0) {\ - u16_t tmp_ = ntohs(f) + (((u16_t)cp[1] << 8) | cp[2]); \ - (f) = htons(tmp_); \ + u16_t tmp_ = lwip_ntohs(f) + (((u16_t)cp[1] << 8) | cp[2]); \ + (f) = lwip_htons(tmp_); \ cp += 3; \ } else { \ - u16_t tmp_ = ntohs(f) + (u16_t)*cp++; \ - (f) = htons(tmp_); \ + u16_t tmp_ = lwip_ntohs(f) + (u16_t)*cp++; \ + (f) = lwip_htons(tmp_); \ } \ } #define DECODEU(f) { \ if (*cp == 0) {\ - (f) = htons(((u16_t)cp[1] << 8) | cp[2]); \ + (f) = lwip_htons(((u16_t)cp[1] << 8) | cp[2]); \ cp += 3; \ } else { \ - (f) = htons((u16_t)*cp++); \ + (f) = lwip_htons((u16_t)*cp++); \ } \ } @@ -306,7 +306,7 @@ vj_compress_tcp(struct vjcompress *comp, struct pbuf **pb) * needed in this section of code). */ if (TCPH_FLAGS(th) & TCP_URG) { - deltaS = ntohs(th->urgp); + deltaS = lwip_ntohs(th->urgp); ENCODEZ(deltaS); changes |= NEW_U; } else if (th->urgp != oth->urgp) { @@ -317,12 +317,12 @@ vj_compress_tcp(struct vjcompress *comp, struct pbuf **pb) goto uncompressed; } - if ((deltaS = (u16_t)(ntohs(th->wnd) - ntohs(oth->wnd))) != 0) { + if ((deltaS = (u16_t)(lwip_ntohs(th->wnd) - lwip_ntohs(oth->wnd))) != 0) { ENCODE(deltaS); changes |= NEW_W; } - if ((deltaL = ntohl(th->ackno) - ntohl(oth->ackno)) != 0) { + if ((deltaL = lwip_ntohl(th->ackno) - lwip_ntohl(oth->ackno)) != 0) { if (deltaL > 0xffff) { goto uncompressed; } @@ -331,7 +331,7 @@ vj_compress_tcp(struct vjcompress *comp, struct pbuf **pb) changes |= NEW_A; } - if ((deltaL = ntohl(th->seqno) - ntohl(oth->seqno)) != 0) { + if ((deltaL = lwip_ntohl(th->seqno) - lwip_ntohl(oth->seqno)) != 0) { if (deltaL > 0xffff) { goto uncompressed; } @@ -351,7 +351,7 @@ vj_compress_tcp(struct vjcompress *comp, struct pbuf **pb) * in case the other side missed the compressed version. */ if (IPH_LEN(ip) != IPH_LEN(&cs->cs_ip) && - ntohs(IPH_LEN(&cs->cs_ip)) == hlen) { + lwip_ntohs(IPH_LEN(&cs->cs_ip)) == hlen) { break; } /* no break */ @@ -366,7 +366,7 @@ vj_compress_tcp(struct vjcompress *comp, struct pbuf **pb) goto uncompressed; case NEW_S|NEW_A: - if (deltaS == deltaA && deltaS == ntohs(IPH_LEN(&cs->cs_ip)) - hlen) { + if (deltaS == deltaA && deltaS == lwip_ntohs(IPH_LEN(&cs->cs_ip)) - hlen) { /* special case for echoed terminal traffic */ changes = SPECIAL_I; cp = new_seq; @@ -374,7 +374,7 @@ vj_compress_tcp(struct vjcompress *comp, struct pbuf **pb) break; case NEW_S: - if (deltaS == ntohs(IPH_LEN(&cs->cs_ip)) - hlen) { + if (deltaS == lwip_ntohs(IPH_LEN(&cs->cs_ip)) - hlen) { /* special case for data xfer */ changes = SPECIAL_D; cp = new_seq; @@ -384,7 +384,7 @@ vj_compress_tcp(struct vjcompress *comp, struct pbuf **pb) break; } - deltaS = (u16_t)(ntohs(IPH_ID(ip)) - ntohs(IPH_ID(&cs->cs_ip))); + deltaS = (u16_t)(lwip_ntohs(IPH_ID(ip)) - lwip_ntohs(IPH_ID(&cs->cs_ip))); if (deltaS != 1) { ENCODEZ(deltaS); changes |= NEW_I; @@ -396,7 +396,7 @@ vj_compress_tcp(struct vjcompress *comp, struct pbuf **pb) * Grab the cksum before we overwrite it below. Then update our * state with this packet's header. */ - deltaA = ntohs(th->chksum); + deltaA = lwip_ntohs(th->chksum); MEMCPY(&cs->cs_ip, ip, hlen); /* @@ -538,7 +538,7 @@ vj_uncompress_tcp(struct pbuf **nb, struct vjcompress *comp) cs = &comp->rstate[comp->last_recv]; hlen = IPH_HL(&cs->cs_ip) << 2; th = (struct tcp_hdr *)&((u8_t*)&cs->cs_ip)[hlen]; - th->chksum = htons((*cp << 8) | cp[1]); + th->chksum = lwip_htons((*cp << 8) | cp[1]); cp += 2; if (changes & TCP_PUSH_BIT) { TCPH_SET_FLAG(th, TCP_PSH); @@ -549,19 +549,19 @@ vj_uncompress_tcp(struct pbuf **nb, struct vjcompress *comp) switch (changes & SPECIALS_MASK) { case SPECIAL_I: { - u32_t i = ntohs(IPH_LEN(&cs->cs_ip)) - cs->cs_hlen; + u32_t i = lwip_ntohs(IPH_LEN(&cs->cs_ip)) - cs->cs_hlen; /* some compilers can't nest inline assembler.. */ - tmp = ntohl(th->ackno) + i; - th->ackno = htonl(tmp); - tmp = ntohl(th->seqno) + i; - th->seqno = htonl(tmp); + tmp = lwip_ntohl(th->ackno) + i; + th->ackno = lwip_htonl(tmp); + tmp = lwip_ntohl(th->seqno) + i; + th->seqno = lwip_htonl(tmp); } break; case SPECIAL_D: /* some compilers can't nest inline assembler.. */ - tmp = ntohl(th->seqno) + ntohs(IPH_LEN(&cs->cs_ip)) - cs->cs_hlen; - th->seqno = htonl(tmp); + tmp = lwip_ntohl(th->seqno) + lwip_ntohs(IPH_LEN(&cs->cs_ip)) - cs->cs_hlen; + th->seqno = lwip_htonl(tmp); break; default: @@ -585,8 +585,8 @@ vj_uncompress_tcp(struct pbuf **nb, struct vjcompress *comp) if (changes & NEW_I) { DECODES(cs->cs_ip._id); } else { - IPH_ID_SET(&cs->cs_ip, ntohs(IPH_ID(&cs->cs_ip)) + 1); - IPH_ID_SET(&cs->cs_ip, htons(IPH_ID(&cs->cs_ip))); + IPH_ID_SET(&cs->cs_ip, lwip_ntohs(IPH_ID(&cs->cs_ip)) + 1); + IPH_ID_SET(&cs->cs_ip, lwip_htons(IPH_ID(&cs->cs_ip))); } /* @@ -607,9 +607,9 @@ vj_uncompress_tcp(struct pbuf **nb, struct vjcompress *comp) #if BYTE_ORDER == LITTLE_ENDIAN tmp = n0->tot_len - vjlen + cs->cs_hlen; - IPH_LEN_SET(&cs->cs_ip, htons((u16_t)tmp)); + IPH_LEN_SET(&cs->cs_ip, lwip_htons((u16_t)tmp)); #else - IPH_LEN_SET(&cs->cs_ip, htons(n0->tot_len - vjlen + cs->cs_hlen)); + IPH_LEN_SET(&cs->cs_ip, lwip_htons(n0->tot_len - vjlen + cs->cs_hlen)); #endif /* recompute the ip header checksum */ From 05419912e0bdb8c3396044f9eaf1433b574ce606 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Thu, 6 Oct 2016 13:13:10 +0200 Subject: [PATCH 281/325] def.h: Provide hton* / ntoh* functions to users by default for compatibility (can be turned off) Add note to UPGRADING document --- UPGRADING | 4 ++++ src/include/lwip/def.h | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/UPGRADING b/UPGRADING index d2cd1f26..c42c67d1 100644 --- a/UPGRADING +++ b/UPGRADING @@ -49,6 +49,10 @@ with newer versions. * Added generalized abstraction for itoa(), strnicmp(), stricmp() and strnstr() in def.h (to be overridden in cc.h) instead of config options for netbiosns, httpd, dns, etc. ... + * New abstraction for hton* and ntoh* functions in def.h. + To override them, use the following in cc.h: + #define lwip_htons(x) + #define lwip_htonl(x) +++ new options: * TODO diff --git a/src/include/lwip/def.h b/src/include/lwip/def.h index aafbd7cc..bb07009c 100644 --- a/src/include/lwip/def.h +++ b/src/include/lwip/def.h @@ -92,6 +92,14 @@ u32_t lwip_htonl(u32_t x); #endif #define lwip_ntohl(x) lwip_htonl(x) +/* Provide usual function names as macros for users, but this can be turned off */ +#ifndef LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS +#define htons(x) lwip_htons(x) +#define ntohs(x) lwip_ntohs(x) +#define htonl(x) lwip_htonl(x) +#define ntohl(x) lwip_ntohl(x) +#endif + /* These macros should be calculated by the preprocessor and are used with compile-time constants only (so that there is no little-endian overhead at runtime). */ From a1c0a0185bc0a58e4594c0a1d8bcde04614fe5ed Mon Sep 17 00:00:00 2001 From: goldsimon Date: Thu, 6 Oct 2016 13:21:00 +0200 Subject: [PATCH 282/325] bug #48823: posix errors should be removed from arch.h (to new file 'lwip/errno.h') --- src/api/err.c | 37 ++++++++ src/api/sockets.c | 28 ------ src/include/lwip/arch.h | 136 --------------------------- src/include/lwip/err.h | 2 + src/include/lwip/errno.h | 182 +++++++++++++++++++++++++++++++++++++ src/include/lwip/sockets.h | 1 + src/include/posix/errno.h | 33 +++++++ 7 files changed, 255 insertions(+), 164 deletions(-) create mode 100644 src/include/lwip/errno.h create mode 100644 src/include/posix/errno.h diff --git a/src/api/err.c b/src/api/err.c index f3650f4c..e1ef344f 100644 --- a/src/api/err.c +++ b/src/api/err.c @@ -37,6 +37,31 @@ */ #include "lwip/err.h" +#include "lwip/def.h" + +#include "lwip/errno.h" + +/** Table to quickly map an lwIP error (err_t) to a socket error + * by using -err as an index */ +static const int err_to_errno_table[] = { + 0, /* ERR_OK 0 No error, everything OK. */ + ENOMEM, /* ERR_MEM -1 Out of memory error. */ + ENOBUFS, /* ERR_BUF -2 Buffer error. */ + EWOULDBLOCK, /* ERR_TIMEOUT -3 Timeout */ + EHOSTUNREACH, /* ERR_RTE -4 Routing problem. */ + EINPROGRESS, /* ERR_INPROGRESS -5 Operation in progress */ + EINVAL, /* ERR_VAL -6 Illegal value. */ + EWOULDBLOCK, /* ERR_WOULDBLOCK -7 Operation would block. */ + EADDRINUSE, /* ERR_USE -8 Address in use. */ + EALREADY, /* ERR_ALREADY -9 Already connecting. */ + EISCONN, /* ERR_ISCONN -10 Conn already established.*/ + ENOTCONN, /* ERR_CONN -11 Not connected. */ + -1, /* ERR_IF -12 Low-level netif error */ + ECONNABORTED, /* ERR_ABRT -13 Connection aborted. */ + ECONNRESET, /* ERR_RST -14 Connection reset. */ + ENOTCONN, /* ERR_CLSD -15 Connection closed. */ + EIO /* ERR_ARG -16 Illegal argument. */ +}; #ifdef LWIP_DEBUG @@ -69,7 +94,19 @@ static const char *err_strerr[] = { const char * lwip_strerr(err_t err) { + if ((err > 0) || (-err >= LWIP_ARRAYSIZE(err_strerr))) { + return "Unknown error."; + } return err_strerr[-err]; } #endif /* LWIP_DEBUG */ + +int +err_to_errno(err_t err) +{ + if ((err > 0) || (-err >= LWIP_ARRAYSIZE(err_strerr))) { + return EIO; + } + return err_to_errno_table[-err]; +} diff --git a/src/api/sockets.c b/src/api/sockets.c index 87878fb4..01d974e9 100644 --- a/src/api/sockets.c +++ b/src/api/sockets.c @@ -289,34 +289,6 @@ static struct lwip_select_cb *select_cb_list; and checked in event_callback to see if it has changed. */ static volatile int select_cb_ctr; -/** Table to quickly map an lwIP error (err_t) to a socket error - * by using -err as an index */ -static const int err_to_errno_table[] = { - 0, /* ERR_OK 0 No error, everything OK. */ - ENOMEM, /* ERR_MEM -1 Out of memory error. */ - ENOBUFS, /* ERR_BUF -2 Buffer error. */ - EWOULDBLOCK, /* ERR_TIMEOUT -3 Timeout */ - EHOSTUNREACH, /* ERR_RTE -4 Routing problem. */ - EINPROGRESS, /* ERR_INPROGRESS -5 Operation in progress */ - EINVAL, /* ERR_VAL -6 Illegal value. */ - EWOULDBLOCK, /* ERR_WOULDBLOCK -7 Operation would block. */ - EADDRINUSE, /* ERR_USE -8 Address in use. */ - EALREADY, /* ERR_ALREADY -9 Already connecting. */ - EISCONN, /* ERR_ISCONN -10 Conn already established.*/ - ENOTCONN, /* ERR_CONN -11 Not connected. */ - -1, /* ERR_IF -12 Low-level netif error */ - ECONNABORTED, /* ERR_ABRT -13 Connection aborted. */ - ECONNRESET, /* ERR_RST -14 Connection reset. */ - ENOTCONN, /* ERR_CLSD -15 Connection closed. */ - EIO /* ERR_ARG -16 Illegal argument. */ -}; - -#define ERR_TO_ERRNO_TABLE_SIZE LWIP_ARRAYSIZE(err_to_errno_table) - -#define err_to_errno(err) \ - ((unsigned)(-(signed)(err)) < ERR_TO_ERRNO_TABLE_SIZE ? \ - err_to_errno_table[-(signed)(err)] : EIO) - #if LWIP_SOCKET_SET_ERRNO #ifndef set_errno #define set_errno(err) do { if (err) { errno = (err); } } while(0) diff --git a/src/include/lwip/arch.h b/src/include/lwip/arch.h index ee4a0b98..473e4a4a 100644 --- a/src/include/lwip/arch.h +++ b/src/include/lwip/arch.h @@ -185,142 +185,6 @@ extern "C" { #endif /* LWIP_UNUSED_ARG */ -#ifdef LWIP_PROVIDE_ERRNO - -#define EPERM 1 /* Operation not permitted */ -#define ENOENT 2 /* No such file or directory */ -#define ESRCH 3 /* No such process */ -#define EINTR 4 /* Interrupted system call */ -#define EIO 5 /* I/O error */ -#define ENXIO 6 /* No such device or address */ -#define E2BIG 7 /* Arg list too long */ -#define ENOEXEC 8 /* Exec format error */ -#define EBADF 9 /* Bad file number */ -#define ECHILD 10 /* No child processes */ -#define EAGAIN 11 /* Try again */ -#define ENOMEM 12 /* Out of memory */ -#define EACCES 13 /* Permission denied */ -#define EFAULT 14 /* Bad address */ -#define ENOTBLK 15 /* Block device required */ -#define EBUSY 16 /* Device or resource busy */ -#define EEXIST 17 /* File exists */ -#define EXDEV 18 /* Cross-device link */ -#define ENODEV 19 /* No such device */ -#define ENOTDIR 20 /* Not a directory */ -#define EISDIR 21 /* Is a directory */ -#define EINVAL 22 /* Invalid argument */ -#define ENFILE 23 /* File table overflow */ -#define EMFILE 24 /* Too many open files */ -#define ENOTTY 25 /* Not a typewriter */ -#define ETXTBSY 26 /* Text file busy */ -#define EFBIG 27 /* File too large */ -#define ENOSPC 28 /* No space left on device */ -#define ESPIPE 29 /* Illegal seek */ -#define EROFS 30 /* Read-only file system */ -#define EMLINK 31 /* Too many links */ -#define EPIPE 32 /* Broken pipe */ -#define EDOM 33 /* Math argument out of domain of func */ -#define ERANGE 34 /* Math result not representable */ -#define EDEADLK 35 /* Resource deadlock would occur */ -#define ENAMETOOLONG 36 /* File name too long */ -#define ENOLCK 37 /* No record locks available */ -#define ENOSYS 38 /* Function not implemented */ -#define ENOTEMPTY 39 /* Directory not empty */ -#define ELOOP 40 /* Too many symbolic links encountered */ -#define EWOULDBLOCK EAGAIN /* Operation would block */ -#define ENOMSG 42 /* No message of desired type */ -#define EIDRM 43 /* Identifier removed */ -#define ECHRNG 44 /* Channel number out of range */ -#define EL2NSYNC 45 /* Level 2 not synchronized */ -#define EL3HLT 46 /* Level 3 halted */ -#define EL3RST 47 /* Level 3 reset */ -#define ELNRNG 48 /* Link number out of range */ -#define EUNATCH 49 /* Protocol driver not attached */ -#define ENOCSI 50 /* No CSI structure available */ -#define EL2HLT 51 /* Level 2 halted */ -#define EBADE 52 /* Invalid exchange */ -#define EBADR 53 /* Invalid request descriptor */ -#define EXFULL 54 /* Exchange full */ -#define ENOANO 55 /* No anode */ -#define EBADRQC 56 /* Invalid request code */ -#define EBADSLT 57 /* Invalid slot */ - -#define EDEADLOCK EDEADLK - -#define EBFONT 59 /* Bad font file format */ -#define ENOSTR 60 /* Device not a stream */ -#define ENODATA 61 /* No data available */ -#define ETIME 62 /* Timer expired */ -#define ENOSR 63 /* Out of streams resources */ -#define ENONET 64 /* Machine is not on the network */ -#define ENOPKG 65 /* Package not installed */ -#define EREMOTE 66 /* Object is remote */ -#define ENOLINK 67 /* Link has been severed */ -#define EADV 68 /* Advertise error */ -#define ESRMNT 69 /* Srmount error */ -#define ECOMM 70 /* Communication error on send */ -#define EPROTO 71 /* Protocol error */ -#define EMULTIHOP 72 /* Multihop attempted */ -#define EDOTDOT 73 /* RFS specific error */ -#define EBADMSG 74 /* Not a data message */ -#define EOVERFLOW 75 /* Value too large for defined data type */ -#define ENOTUNIQ 76 /* Name not unique on network */ -#define EBADFD 77 /* File descriptor in bad state */ -#define EREMCHG 78 /* Remote address changed */ -#define ELIBACC 79 /* Can not access a needed shared library */ -#define ELIBBAD 80 /* Accessing a corrupted shared library */ -#define ELIBSCN 81 /* .lib section in a.out corrupted */ -#define ELIBMAX 82 /* Attempting to link in too many shared libraries */ -#define ELIBEXEC 83 /* Cannot exec a shared library directly */ -#define EILSEQ 84 /* Illegal byte sequence */ -#define ERESTART 85 /* Interrupted system call should be restarted */ -#define ESTRPIPE 86 /* Streams pipe error */ -#define EUSERS 87 /* Too many users */ -#define ENOTSOCK 88 /* Socket operation on non-socket */ -#define EDESTADDRREQ 89 /* Destination address required */ -#define EMSGSIZE 90 /* Message too long */ -#define EPROTOTYPE 91 /* Protocol wrong type for socket */ -#define ENOPROTOOPT 92 /* Protocol not available */ -#define EPROTONOSUPPORT 93 /* Protocol not supported */ -#define ESOCKTNOSUPPORT 94 /* Socket type not supported */ -#define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */ -#define EPFNOSUPPORT 96 /* Protocol family not supported */ -#define EAFNOSUPPORT 97 /* Address family not supported by protocol */ -#define EADDRINUSE 98 /* Address already in use */ -#define EADDRNOTAVAIL 99 /* Cannot assign requested address */ -#define ENETDOWN 100 /* Network is down */ -#define ENETUNREACH 101 /* Network is unreachable */ -#define ENETRESET 102 /* Network dropped connection because of reset */ -#define ECONNABORTED 103 /* Software caused connection abort */ -#define ECONNRESET 104 /* Connection reset by peer */ -#define ENOBUFS 105 /* No buffer space available */ -#define EISCONN 106 /* Transport endpoint is already connected */ -#define ENOTCONN 107 /* Transport endpoint is not connected */ -#define ESHUTDOWN 108 /* Cannot send after transport endpoint shutdown */ -#define ETOOMANYREFS 109 /* Too many references: cannot splice */ -#define ETIMEDOUT 110 /* Connection timed out */ -#define ECONNREFUSED 111 /* Connection refused */ -#define EHOSTDOWN 112 /* Host is down */ -#define EHOSTUNREACH 113 /* No route to host */ -#define EALREADY 114 /* Operation already in progress */ -#define EINPROGRESS 115 /* Operation now in progress */ -#define ESTALE 116 /* Stale NFS file handle */ -#define EUCLEAN 117 /* Structure needs cleaning */ -#define ENOTNAM 118 /* Not a XENIX named type file */ -#define ENAVAIL 119 /* No XENIX semaphores available */ -#define EISNAM 120 /* Is a named type file */ -#define EREMOTEIO 121 /* Remote I/O error */ -#define EDQUOT 122 /* Quota exceeded */ - -#define ENOMEDIUM 123 /* No medium found */ -#define EMEDIUMTYPE 124 /* Wrong medium type */ - -#ifndef errno -extern int errno; -#endif - -#endif /* LWIP_PROVIDE_ERRNO */ - #ifdef __cplusplus } #endif diff --git a/src/include/lwip/err.h b/src/include/lwip/err.h index f60c6fce..136e6b2c 100644 --- a/src/include/lwip/err.h +++ b/src/include/lwip/err.h @@ -108,6 +108,8 @@ extern const char *lwip_strerr(err_t err); #define lwip_strerr(x) "" #endif /* LWIP_DEBUG */ +int err_to_errno(err_t err); + #ifdef __cplusplus } #endif diff --git a/src/include/lwip/errno.h b/src/include/lwip/errno.h new file mode 100644 index 00000000..b6a897b7 --- /dev/null +++ b/src/include/lwip/errno.h @@ -0,0 +1,182 @@ +/** + * @file + * Posix Errno defines + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_HDR_ERRNO_H +#define LWIP_HDR_ERRNO_H + +#include "lwip/opt.h" + +#ifdef LWIP_PROVIDE_ERRNO + +#define EPERM 1 /* Operation not permitted */ +#define ENOENT 2 /* No such file or directory */ +#define ESRCH 3 /* No such process */ +#define EINTR 4 /* Interrupted system call */ +#define EIO 5 /* I/O error */ +#define ENXIO 6 /* No such device or address */ +#define E2BIG 7 /* Arg list too long */ +#define ENOEXEC 8 /* Exec format error */ +#define EBADF 9 /* Bad file number */ +#define ECHILD 10 /* No child processes */ +#define EAGAIN 11 /* Try again */ +#define ENOMEM 12 /* Out of memory */ +#define EACCES 13 /* Permission denied */ +#define EFAULT 14 /* Bad address */ +#define ENOTBLK 15 /* Block device required */ +#define EBUSY 16 /* Device or resource busy */ +#define EEXIST 17 /* File exists */ +#define EXDEV 18 /* Cross-device link */ +#define ENODEV 19 /* No such device */ +#define ENOTDIR 20 /* Not a directory */ +#define EISDIR 21 /* Is a directory */ +#define EINVAL 22 /* Invalid argument */ +#define ENFILE 23 /* File table overflow */ +#define EMFILE 24 /* Too many open files */ +#define ENOTTY 25 /* Not a typewriter */ +#define ETXTBSY 26 /* Text file busy */ +#define EFBIG 27 /* File too large */ +#define ENOSPC 28 /* No space left on device */ +#define ESPIPE 29 /* Illegal seek */ +#define EROFS 30 /* Read-only file system */ +#define EMLINK 31 /* Too many links */ +#define EPIPE 32 /* Broken pipe */ +#define EDOM 33 /* Math argument out of domain of func */ +#define ERANGE 34 /* Math result not representable */ +#define EDEADLK 35 /* Resource deadlock would occur */ +#define ENAMETOOLONG 36 /* File name too long */ +#define ENOLCK 37 /* No record locks available */ +#define ENOSYS 38 /* Function not implemented */ +#define ENOTEMPTY 39 /* Directory not empty */ +#define ELOOP 40 /* Too many symbolic links encountered */ +#define EWOULDBLOCK EAGAIN /* Operation would block */ +#define ENOMSG 42 /* No message of desired type */ +#define EIDRM 43 /* Identifier removed */ +#define ECHRNG 44 /* Channel number out of range */ +#define EL2NSYNC 45 /* Level 2 not synchronized */ +#define EL3HLT 46 /* Level 3 halted */ +#define EL3RST 47 /* Level 3 reset */ +#define ELNRNG 48 /* Link number out of range */ +#define EUNATCH 49 /* Protocol driver not attached */ +#define ENOCSI 50 /* No CSI structure available */ +#define EL2HLT 51 /* Level 2 halted */ +#define EBADE 52 /* Invalid exchange */ +#define EBADR 53 /* Invalid request descriptor */ +#define EXFULL 54 /* Exchange full */ +#define ENOANO 55 /* No anode */ +#define EBADRQC 56 /* Invalid request code */ +#define EBADSLT 57 /* Invalid slot */ + +#define EDEADLOCK EDEADLK + +#define EBFONT 59 /* Bad font file format */ +#define ENOSTR 60 /* Device not a stream */ +#define ENODATA 61 /* No data available */ +#define ETIME 62 /* Timer expired */ +#define ENOSR 63 /* Out of streams resources */ +#define ENONET 64 /* Machine is not on the network */ +#define ENOPKG 65 /* Package not installed */ +#define EREMOTE 66 /* Object is remote */ +#define ENOLINK 67 /* Link has been severed */ +#define EADV 68 /* Advertise error */ +#define ESRMNT 69 /* Srmount error */ +#define ECOMM 70 /* Communication error on send */ +#define EPROTO 71 /* Protocol error */ +#define EMULTIHOP 72 /* Multihop attempted */ +#define EDOTDOT 73 /* RFS specific error */ +#define EBADMSG 74 /* Not a data message */ +#define EOVERFLOW 75 /* Value too large for defined data type */ +#define ENOTUNIQ 76 /* Name not unique on network */ +#define EBADFD 77 /* File descriptor in bad state */ +#define EREMCHG 78 /* Remote address changed */ +#define ELIBACC 79 /* Can not access a needed shared library */ +#define ELIBBAD 80 /* Accessing a corrupted shared library */ +#define ELIBSCN 81 /* .lib section in a.out corrupted */ +#define ELIBMAX 82 /* Attempting to link in too many shared libraries */ +#define ELIBEXEC 83 /* Cannot exec a shared library directly */ +#define EILSEQ 84 /* Illegal byte sequence */ +#define ERESTART 85 /* Interrupted system call should be restarted */ +#define ESTRPIPE 86 /* Streams pipe error */ +#define EUSERS 87 /* Too many users */ +#define ENOTSOCK 88 /* Socket operation on non-socket */ +#define EDESTADDRREQ 89 /* Destination address required */ +#define EMSGSIZE 90 /* Message too long */ +#define EPROTOTYPE 91 /* Protocol wrong type for socket */ +#define ENOPROTOOPT 92 /* Protocol not available */ +#define EPROTONOSUPPORT 93 /* Protocol not supported */ +#define ESOCKTNOSUPPORT 94 /* Socket type not supported */ +#define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */ +#define EPFNOSUPPORT 96 /* Protocol family not supported */ +#define EAFNOSUPPORT 97 /* Address family not supported by protocol */ +#define EADDRINUSE 98 /* Address already in use */ +#define EADDRNOTAVAIL 99 /* Cannot assign requested address */ +#define ENETDOWN 100 /* Network is down */ +#define ENETUNREACH 101 /* Network is unreachable */ +#define ENETRESET 102 /* Network dropped connection because of reset */ +#define ECONNABORTED 103 /* Software caused connection abort */ +#define ECONNRESET 104 /* Connection reset by peer */ +#define ENOBUFS 105 /* No buffer space available */ +#define EISCONN 106 /* Transport endpoint is already connected */ +#define ENOTCONN 107 /* Transport endpoint is not connected */ +#define ESHUTDOWN 108 /* Cannot send after transport endpoint shutdown */ +#define ETOOMANYREFS 109 /* Too many references: cannot splice */ +#define ETIMEDOUT 110 /* Connection timed out */ +#define ECONNREFUSED 111 /* Connection refused */ +#define EHOSTDOWN 112 /* Host is down */ +#define EHOSTUNREACH 113 /* No route to host */ +#define EALREADY 114 /* Operation already in progress */ +#define EINPROGRESS 115 /* Operation now in progress */ +#define ESTALE 116 /* Stale NFS file handle */ +#define EUCLEAN 117 /* Structure needs cleaning */ +#define ENOTNAM 118 /* Not a XENIX named type file */ +#define ENAVAIL 119 /* No XENIX semaphores available */ +#define EISNAM 120 /* Is a named type file */ +#define EREMOTEIO 121 /* Remote I/O error */ +#define EDQUOT 122 /* Quota exceeded */ + +#define ENOMEDIUM 123 /* No medium found */ +#define EMEDIUMTYPE 124 /* Wrong medium type */ + +#ifndef errno +extern int errno; +#endif + +#endif /* LWIP_PROVIDE_ERRNO */ + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_ERRNO_H */ diff --git a/src/include/lwip/sockets.h b/src/include/lwip/sockets.h index 20ba6293..33d3cda2 100644 --- a/src/include/lwip/sockets.h +++ b/src/include/lwip/sockets.h @@ -48,6 +48,7 @@ #include "lwip/ip_addr.h" #include "lwip/err.h" #include "lwip/inet.h" +#include "lwip/errno.h" #ifdef __cplusplus extern "C" { diff --git a/src/include/posix/errno.h b/src/include/posix/errno.h new file mode 100644 index 00000000..5917c75e --- /dev/null +++ b/src/include/posix/errno.h @@ -0,0 +1,33 @@ +/** + * @file + * This file is a posix wrapper for lwip/errno.h. + */ + +/* + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + */ + +#include "lwip/errno.h" From 2afc2a52d577d10a34b439841dd0479323e0bbef Mon Sep 17 00:00:00 2001 From: goldsimon Date: Thu, 6 Oct 2016 13:25:11 +0200 Subject: [PATCH 283/325] Fix comment on sys_mbox_new() (bug #49279) --- src/include/lwip/sys.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/include/lwip/sys.h b/src/include/lwip/sys.h index f8804df4..bb06a404 100644 --- a/src/include/lwip/sys.h +++ b/src/include/lwip/sys.h @@ -160,9 +160,11 @@ typedef void (*lwip_thread_fn)(void *arg); /** * @ingroup sys_mutex - * Create a new mutex + * Create a new mutex. + * Note that mutexes are expected to not be taken recursively by the lwIP code, + * so both implementation types (recursive or non-recursive) should work. * @param mutex pointer to the mutex to create - * @return a new mutex + * @return ERR_OK if successful, another err_t otherwise */ err_t sys_mutex_new(sys_mutex_t *mutex); /** From 86a92543de980f97105c3cc61db60da8e8fa4f24 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Thu, 6 Oct 2016 16:01:32 +0200 Subject: [PATCH 284/325] Try to fix unix build after Simon's errno changes (need sys_arch.h) --- src/api/err.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/api/err.c b/src/api/err.c index e1ef344f..cce723be 100644 --- a/src/api/err.c +++ b/src/api/err.c @@ -38,6 +38,7 @@ #include "lwip/err.h" #include "lwip/def.h" +#include "lwip/sys.h" #include "lwip/errno.h" From ad3530ee1063955c71bf8602bbcc0cac303fc144 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Thu, 6 Oct 2016 20:20:07 +0200 Subject: [PATCH 285/325] One more compile fix in err.c --- src/api/err.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/api/err.c b/src/api/err.c index cce723be..604278bf 100644 --- a/src/api/err.c +++ b/src/api/err.c @@ -95,7 +95,7 @@ static const char *err_strerr[] = { const char * lwip_strerr(err_t err) { - if ((err > 0) || (-err >= LWIP_ARRAYSIZE(err_strerr))) { + if ((err > 0) || (-err >= (err_t)LWIP_ARRAYSIZE(err_strerr))) { return "Unknown error."; } return err_strerr[-err]; @@ -106,7 +106,7 @@ lwip_strerr(err_t err) int err_to_errno(err_t err) { - if ((err > 0) || (-err >= LWIP_ARRAYSIZE(err_strerr))) { + if ((err > 0) || (-err >= (err_t)LWIP_ARRAYSIZE(err_strerr))) { return EIO; } return err_to_errno_table[-err]; From 740182de3cbc4298d16db17948ad4197af052c04 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Fri, 7 Oct 2016 08:30:44 +0800 Subject: [PATCH 286/325] err: Fixup error code range checking in err_to_errno This also fixes build error in non-debug build because err_strerr is guarded by LWIP_DEBUG. Fixes: a1c0a0185bc0 ("bug #48823: posix errors should be removed from arch.h (to new file 'lwip/errno.h'))" Signed-off-by: Axel Lin --- src/api/err.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/err.c b/src/api/err.c index 604278bf..30348a91 100644 --- a/src/api/err.c +++ b/src/api/err.c @@ -106,7 +106,7 @@ lwip_strerr(err_t err) int err_to_errno(err_t err) { - if ((err > 0) || (-err >= (err_t)LWIP_ARRAYSIZE(err_strerr))) { + if ((err > 0) || (-err >= (err_t)LWIP_ARRAYSIZE(err_to_errno_table))) { return EIO; } return err_to_errno_table[-err]; From 69be49fdc3cc7f3efafa8718f1a635d9cd98669f Mon Sep 17 00:00:00 2001 From: goldsimon Date: Fri, 7 Oct 2016 16:22:33 +0200 Subject: [PATCH 287/325] Try to fix !defined(LWIP_PROVIDE_ERRNO) --- src/api/err.c | 4 ++++ src/include/lwip/err.h | 2 ++ src/include/lwip/errno.h | 7 +++++++ 3 files changed, 13 insertions(+) diff --git a/src/api/err.c b/src/api/err.c index 30348a91..1593e70a 100644 --- a/src/api/err.c +++ b/src/api/err.c @@ -42,6 +42,7 @@ #include "lwip/errno.h" +#if !NO_SYS /** Table to quickly map an lwIP error (err_t) to a socket error * by using -err as an index */ static const int err_to_errno_table[] = { @@ -63,6 +64,7 @@ static const int err_to_errno_table[] = { ENOTCONN, /* ERR_CLSD -15 Connection closed. */ EIO /* ERR_ARG -16 Illegal argument. */ }; +#endif /* !NO_SYS */ #ifdef LWIP_DEBUG @@ -103,6 +105,7 @@ lwip_strerr(err_t err) #endif /* LWIP_DEBUG */ +#if !NO_SYS int err_to_errno(err_t err) { @@ -111,3 +114,4 @@ err_to_errno(err_t err) } return err_to_errno_table[-err]; } +#endif /* !NO_SYS */ diff --git a/src/include/lwip/err.h b/src/include/lwip/err.h index 136e6b2c..84e528d1 100644 --- a/src/include/lwip/err.h +++ b/src/include/lwip/err.h @@ -108,7 +108,9 @@ extern const char *lwip_strerr(err_t err); #define lwip_strerr(x) "" #endif /* LWIP_DEBUG */ +#if !NO_SYS int err_to_errno(err_t err); +#endif /* !NO_SYS */ #ifdef __cplusplus } diff --git a/src/include/lwip/errno.h b/src/include/lwip/errno.h index b6a897b7..e2d996c6 100644 --- a/src/include/lwip/errno.h +++ b/src/include/lwip/errno.h @@ -173,6 +173,13 @@ extern int errno; #endif +#else /* LWIP_PROVIDE_ERRNO */ + +/* Define LWIP_ERRNO_INCLUDE to to include the error defines here */ +#ifdef LWIP_ERRNO_INCLUDE +#include LWIP_ERRNO_INCLUDE +#endif /* LWIP_ERRNO_INCLUDE */ + #endif /* LWIP_PROVIDE_ERRNO */ #ifdef __cplusplus From 70ccea9207f70e0946fdd738d575804aa4e26945 Mon Sep 17 00:00:00 2001 From: Ari Suutari Date: Fri, 7 Oct 2016 20:31:15 +0200 Subject: [PATCH 288/325] Make sys_restart_timeouts public also for !NO_SYS targets --- src/core/timeouts.c | 2 -- src/include/lwip/timeouts.h | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/core/timeouts.c b/src/core/timeouts.c index fcba0a1a..e2dc0fc7 100644 --- a/src/core/timeouts.c +++ b/src/core/timeouts.c @@ -360,7 +360,6 @@ sys_check_timeouts(void) } } -#if NO_SYS /** Set back the timestamp of the last call to sys_check_timeouts() * This is necessary if sys_check_timeouts() hasn't been called for a long * time (e.g. while saving energy) to prevent all timer functions of that @@ -371,7 +370,6 @@ sys_restart_timeouts(void) { timeouts_last_time = sys_now(); } -#endif /* NO_SYS */ /** Return the time left before the next timeout is due. If no timeouts are * enqueued, returns 0xffffffff diff --git a/src/include/lwip/timeouts.h b/src/include/lwip/timeouts.h index 4988b151..c9b93aa0 100644 --- a/src/include/lwip/timeouts.h +++ b/src/include/lwip/timeouts.h @@ -103,9 +103,9 @@ void sys_timeout(u32_t msecs, sys_timeout_handler handler, void *arg); #endif /* LWIP_DEBUG_TIMERNAMES */ void sys_untimeout(sys_timeout_handler handler, void *arg); +void sys_restart_timeouts(void); #if NO_SYS void sys_check_timeouts(void); -void sys_restart_timeouts(void); u32_t sys_timeouts_sleeptime(void); #else /* NO_SYS */ void sys_timeouts_mbox_fetch(sys_mbox_t *mbox, void **msg); From 5477aa5a4277dc93763e693e728da25ffe325397 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Sun, 9 Oct 2016 09:41:26 +0200 Subject: [PATCH 289/325] Minor: Documentation update --- doc/rawapi.txt | 3 +++ src/core/def.c | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/doc/rawapi.txt b/doc/rawapi.txt index 9a5c3e00..0cdfdcea 100644 --- a/doc/rawapi.txt +++ b/doc/rawapi.txt @@ -458,6 +458,9 @@ assembly or inline replacements for htons() and htonl() if you're using a little-endian architecture. #define lwip_htons(x) #define lwip_htonl(x) +If you #define them to htons() and htonl(), you should +#define LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS to prevent lwIP from +defining hton*/ntoh* compatibility macros. Check your network interface driver if it reads at a higher speed than the maximum wire-speed. If the diff --git a/src/core/def.c b/src/core/def.c index 88f5724d..819b7a81 100644 --- a/src/core/def.c +++ b/src/core/def.c @@ -11,6 +11,10 @@ * \#define lwip_htonl(x) your_htonl * * Note lwip_ntohs() and lwip_ntohl() are merely references to the htonx counterparts. + * + * If you #define them to htons() and htonl(), you should + * \#define LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS to prevent lwIP from + * defining htonx/ntohx compatibility macros. */ /* From 4e74ae4bc9376baeffc08e3c326da7e2042951c3 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Sun, 9 Oct 2016 10:23:36 +0200 Subject: [PATCH 290/325] Minor: documentation updates --- src/core/def.c | 2 +- src/include/lwip/api.h | 27 ++++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/core/def.c b/src/core/def.c index 819b7a81..f3cf8a48 100644 --- a/src/core/def.c +++ b/src/core/def.c @@ -12,7 +12,7 @@ * * Note lwip_ntohs() and lwip_ntohl() are merely references to the htonx counterparts. * - * If you #define them to htons() and htonl(), you should + * If you \#define them to htons() and htonl(), you should * \#define LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS to prevent lwIP from * defining htonx/ntohx compatibility macros. */ diff --git a/src/include/lwip/api.h b/src/include/lwip/api.h index b821841b..1ed5a51a 100644 --- a/src/include/lwip/api.h +++ b/src/include/lwip/api.h @@ -139,7 +139,32 @@ enum netconn_state { NETCONN_CLOSE }; -/** Use to inform the callback function about changes */ +/** Used to inform the callback function about changes + * + * Event explanation: + * + * In the netconn implementation, there are three ways to block a client: + * + * - accept mbox (sys_arch_mbox_fetch(&conn->acceptmbox, &accept_ptr, 0); in netconn_accept()) + * - receive mbox (sys_arch_mbox_fetch(&conn->recvmbox, &buf, 0); in netconn_recv_data()) + * - send queue is full (sys_arch_sem_wait(LWIP_API_MSG_SEM(msg), 0); in lwip_netconn_do_write()) + * + * The events have to be seen as events signaling the state of these mboxes/semaphores. For non-blocking + * connections, you need to know in advance whether a call to a netconn function call would block or not, + * and these events tell you about that. + * + * RCVPLUS events say: Safe to perform a potentially blocking call call once more. + * They are counted in sockets - three RCVPLUS events for accept mbox means you are safe + * to call netconn_accept 3 times without being blocked. + * Same thing for receive mbox. + * + * RCVMINUS events say: Your call to to a possibly blocking function is "acknowledged". + * Socket implementation decrements the counter. + * + * For TX, there is no need to count, its merely a flag. SENDPLUS means you may send something. + * PLUS occurs when enough data was delivered to peer so netconn_send() can be called again. + * A SENDMINUS event occurs when the next call to a netconn_send() would be blocking. + */ enum netconn_evt { NETCONN_EVT_RCVPLUS, NETCONN_EVT_RCVMINUS, From 9cd555c51a6c675b42b021ac597cc4f069a7d8b5 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Sun, 9 Oct 2016 10:24:26 +0200 Subject: [PATCH 291/325] Minor: documentation typo fix --- src/include/lwip/api.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/include/lwip/api.h b/src/include/lwip/api.h index 1ed5a51a..e8620dd8 100644 --- a/src/include/lwip/api.h +++ b/src/include/lwip/api.h @@ -162,7 +162,7 @@ enum netconn_state { * Socket implementation decrements the counter. * * For TX, there is no need to count, its merely a flag. SENDPLUS means you may send something. - * PLUS occurs when enough data was delivered to peer so netconn_send() can be called again. + * SENDPLUS occurs when enough data was delivered to peer so netconn_send() can be called again. * A SENDMINUS event occurs when the next call to a netconn_send() would be blocking. */ enum netconn_evt { From f6e27940bd9679232f2a82859b30ffaf3899e8f6 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Sun, 9 Oct 2016 12:21:39 +0200 Subject: [PATCH 292/325] Make lwIP compile with clang -Wdocumentation -> several documentation fixes --- src/api/api_lib.c | 2 +- src/api/api_msg.c | 3 -- src/api/sockets.c | 12 +++--- src/api/tcpip.c | 3 +- src/apps/httpd/httpd.c | 4 +- src/apps/mdns/mdns.c | 2 - src/apps/snmp/snmp_asn1.c | 8 ++-- src/apps/snmp/snmp_core.c | 82 ++++++++++++++++++------------------ src/apps/snmp/snmp_mib2_ip.c | 2 +- src/apps/snmp/snmp_msg.c | 8 ++-- src/apps/snmp/snmp_traps.c | 2 +- src/core/dns.c | 6 +-- src/core/ipv4/etharp.c | 7 ++- src/core/ipv4/igmp.c | 2 - src/core/ipv4/ip4.c | 1 - src/core/ipv4/ip4_frag.c | 2 +- src/core/raw.c | 3 -- src/core/tcp_in.c | 3 -- src/include/lwip/pbuf.h | 4 +- src/netif/ethernet.c | 8 ++-- src/netif/lowpan6.c | 2 +- src/netif/ppp/pppos.c | 12 +++--- src/netif/slipif.c | 2 +- 23 files changed, 81 insertions(+), 99 deletions(-) diff --git a/src/api/api_lib.c b/src/api/api_lib.c index 99c4b54d..193a608f 100644 --- a/src/api/api_lib.c +++ b/src/api/api_lib.c @@ -306,7 +306,7 @@ netconn_connect(struct netconn *conn, const ip_addr_t *addr, u16_t port) * Disconnect a netconn from its current peer (only valid for UDP netconns). * * @param conn the netconn to disconnect - * @return @todo: return value is not set here... + * @return See @ref err_t */ err_t netconn_disconnect(struct netconn *conn) diff --git a/src/api/api_msg.c b/src/api/api_msg.c index fafc9eb9..7d0f24d1 100644 --- a/src/api/api_msg.c +++ b/src/api/api_msg.c @@ -540,7 +540,6 @@ accept_function(void *arg, struct tcp_pcb *newpcb, err_t err) * Called from lwip_netconn_do_newconn(). * * @param msg the api_msg_msg describing the connection type - * @return msg->conn->err, but the return value is currently ignored */ static void pcb_new(struct api_msg *msg) @@ -807,7 +806,6 @@ netconn_drain(struct netconn *conn) * places. * * @param conn the TCP netconn to close - * [@param delay 1 if called from sent/poll (wake up calling thread on end)] */ static err_t lwip_netconn_do_close_internal(struct netconn *conn WRITE_DELAYED_PARAM) @@ -1492,7 +1490,6 @@ lwip_netconn_do_accepted(void *m) * blocking application thread (waiting in netconn_write) is released. * * @param conn netconn (that is currently in state NETCONN_WRITE) to process - * [@param delay 1 if called from sent/poll (wake up calling thread on end)] * @return ERR_OK * ERR_MEM if LWIP_TCPIP_CORE_LOCKING=1 and sending hasn't yet finished */ diff --git a/src/api/sockets.c b/src/api/sockets.c index 01d974e9..9968a9ae 100644 --- a/src/api/sockets.c +++ b/src/api/sockets.c @@ -1258,12 +1258,12 @@ lwip_writev(int s, const struct iovec *iov, int iovcnt) * the sockets enabled that had events. * * @param maxfdp1 the highest socket index in the sets - * @param readset_in: set of sockets to check for read events - * @param writeset_in: set of sockets to check for write events - * @param exceptset_in: set of sockets to check for error events - * @param readset_out: set of sockets that had read events - * @param writeset_out: set of sockets that had write events - * @param exceptset_out: set os sockets that had error events + * @param readset_in set of sockets to check for read events + * @param writeset_in set of sockets to check for write events + * @param exceptset_in set of sockets to check for error events + * @param readset_out set of sockets that had read events + * @param writeset_out set of sockets that had write events + * @param exceptset_out set os sockets that had error events * @return number of sockets that had events (read/write/exception) (>= 0) */ static int diff --git a/src/api/tcpip.c b/src/api/tcpip.c index 4dfeabd3..07b2f984 100644 --- a/src/api/tcpip.c +++ b/src/api/tcpip.c @@ -260,7 +260,7 @@ tcpip_callback_with_block(tcpip_callback_fn function, void *ctx, u8_t block) /** * call sys_timeout in tcpip_thread * - * @param msec time in milliseconds for timeout + * @param msecs time in milliseconds for timeout * @param h function to be called on timeout * @param arg argument to pass to timeout function h * @return ERR_MEM on memory error, ERR_OK otherwise @@ -288,7 +288,6 @@ tcpip_timeout(u32_t msecs, sys_timeout_handler h, void *arg) /** * call sys_untimeout in tcpip_thread * - * @param msec time in milliseconds for timeout * @param h function to be called on timeout * @param arg argument to pass to timeout function h * @return ERR_MEM on memory error, ERR_OK otherwise diff --git a/src/apps/httpd/httpd.c b/src/apps/httpd/httpd.c index 6039baef..103f9acb 100644 --- a/src/apps/httpd/httpd.c +++ b/src/apps/httpd/httpd.c @@ -1879,7 +1879,7 @@ http_continue(void *connection) * When data has been received in the correct state, try to parse it * as a HTTP request. * - * @param p the received pbuf + * @param inp the received pbuf * @param hs the connection state * @param pcb the tcp_pcb which received this packet * @return ERR_OK if request was OK and hs has been initialized correctly @@ -2211,7 +2211,7 @@ http_find_file(struct http_state *hs, const char *uri, int is_09) * @param is_09 1 if the request is HTTP/0.9 (no HTTP headers in response) * @param uri the HTTP header URI * @param tag_check enable SSI tag checking - * @param uri_has_params != NULL if URI has parameters (separated by '?') + * @param params != NULL if URI has parameters (separated by '?') * @return ERR_OK if file was found and hs has been initialized correctly * another err_t otherwise */ diff --git a/src/apps/mdns/mdns.c b/src/apps/mdns/mdns.c index 49bcab5b..519a630c 100644 --- a/src/apps/mdns/mdns.c +++ b/src/apps/mdns/mdns.c @@ -1742,8 +1742,6 @@ mdns_handle_response(struct mdns_packet *pkt) /** * Receive input function for MDNS packets. * Handles both IPv4 and IPv6 UDP pcbs. - * - * @params see udp.h */ static void mdns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, u16_t port) diff --git a/src/apps/snmp/snmp_asn1.c b/src/apps/snmp/snmp_asn1.c index 7b41445e..f35b7604 100644 --- a/src/apps/snmp/snmp_asn1.c +++ b/src/apps/snmp/snmp_asn1.c @@ -288,7 +288,7 @@ snmp_asn1_enc_oid(struct snmp_pbuf_stream* pbuf_stream, const u32_t *oid, u16_t /** * Returns octet count for length. * - * @param length + * @param length parameter length * @param octets_needed points to the return value */ void @@ -306,7 +306,7 @@ snmp_asn1_enc_length_cnt(u16_t length, u8_t *octets_needed) /** * Returns octet count for an u32_t. * - * @param value + * @param value value to be encoded * @param octets_needed points to the return value * * @note ASN coded integers are _always_ signed. E.g. +0xFFFF is coded @@ -332,7 +332,7 @@ snmp_asn1_enc_u32t_cnt(u32_t value, u16_t *octets_needed) /** * Returns octet count for an u64_t. * - * @param value + * @param value value to be encoded * @param octets_needed points to the return value * * @note ASN coded integers are _always_ signed. E.g. +0xFFFF is coded @@ -357,7 +357,7 @@ snmp_asn1_enc_u64t_cnt(const u32_t *value, u16_t *octets_needed) /** * Returns octet count for an s32_t. * - * @param value + * @param value value to be encoded * @param octets_needed points to the return value * * @note ASN coded integers are _always_ signed. diff --git a/src/apps/snmp/snmp_core.c b/src/apps/snmp/snmp_core.c index a9213727..c0418336 100644 --- a/src/apps/snmp/snmp_core.c +++ b/src/apps/snmp/snmp_core.c @@ -359,9 +359,9 @@ snmp_ip6_to_oid(const ip6_addr_t *ip, u32_t *oid) #if LWIP_IPV4 || LWIP_IPV6 /** * Convert to InetAddressType+InetAddress+InetPortNumber - * @param ip - * @param port - * @param oid + * @param ip IP address + * @param port Port + * @param oid OID * @return OID length */ u8_t @@ -378,8 +378,8 @@ snmp_ip_port_to_oid(const ip_addr_t *ip, u16_t port, u32_t *oid) /** * Convert to InetAddressType+InetAddress - * @param ip - * @param oid + * @param ip IP address + * @param oid OID * @return OID length */ u8_t @@ -412,9 +412,9 @@ snmp_ip_to_oid(const ip_addr_t *ip, u32_t *oid) /** * Convert from InetAddressType+InetAddress to ip_addr_t - * @param oid - * @param oid_len - * @param ip + * @param oid OID + * @param oid_len OID length + * @param ip IP address * @return Parsed OID length */ u8_t @@ -487,10 +487,10 @@ snmp_oid_to_ip(const u32_t *oid, u8_t oid_len, ip_addr_t *ip) /** * Convert from InetAddressType+InetAddress+InetPortNumber to ip_addr_t and u16_t - * @param oid - * @param oid_len - * @param ip - * @param port + * @param oid OID + * @param oid_len OID length + * @param ip IP address + * @param port Port * @return Parsed OID length */ u8_t @@ -520,10 +520,10 @@ snmp_oid_to_ip_port(const u32_t *oid, u8_t oid_len, ip_addr_t *ip, u16_t *port) #endif /* LWIP_IPV4 || LWIP_IPV6 */ /** - * Assign an OID to \struct snmp_obj_id - * @param target - * @param oid - * @param oid_len + * Assign an OID to struct snmp_obj_id + * @param target Assignment target + * @param oid OID + * @param oid_len OID length */ void snmp_oid_assign(struct snmp_obj_id* target, const u32_t *oid, u8_t oid_len) @@ -538,10 +538,10 @@ snmp_oid_assign(struct snmp_obj_id* target, const u32_t *oid, u8_t oid_len) } /** - * Prefix an OID to OID in \struct snmp_obj_id - * @param target - * @param oid - * @param oid_len + * Prefix an OID to OID in struct snmp_obj_id + * @param target Assignment target to prefix + * @param oid OID + * @param oid_len OID length */ void snmp_oid_prefix(struct snmp_obj_id* target, const u32_t *oid, u8_t oid_len) @@ -561,12 +561,12 @@ snmp_oid_prefix(struct snmp_obj_id* target, const u32_t *oid, u8_t oid_len) } /** - * Combine two OIDs into \struct snmp_obj_id - * @param target - * @param oid1 - * @param oid1_len - * @param oid2 - * @param oid2_len + * Combine two OIDs into struct snmp_obj_id + * @param target Assignmet target + * @param oid1 OID 1 + * @param oid1_len OID 1 length + * @param oid2 OID 2 + * @param oid2_len OID 2 length */ void snmp_oid_combine(struct snmp_obj_id* target, const u32_t *oid1, u8_t oid1_len, const u32_t *oid2, u8_t oid2_len) @@ -576,10 +576,10 @@ snmp_oid_combine(struct snmp_obj_id* target, const u32_t *oid1, u8_t oid1_len, c } /** - * Append OIDs to \struct snmp_obj_id - * @param target - * @param oid - * @param oid_len + * Append OIDs to struct snmp_obj_id + * @param target Assignment target to append to + * @param oid OID + * @param oid_len OID length */ void snmp_oid_append(struct snmp_obj_id* target, const u32_t *oid, u8_t oid_len) @@ -594,11 +594,11 @@ snmp_oid_append(struct snmp_obj_id* target, const u32_t *oid, u8_t oid_len) /** * Compare two OIDs - * @param oid1 - * @param oid1_len - * @param oid2 - * @param oid2_len - * @return + * @param oid1 OID 1 + * @param oid1_len OID 1 length + * @param oid2 OID 2 + * @param oid2_len OID 2 length + * @return -1: OID1<OID2 1: OID1 >OID2 0: equal */ s8_t snmp_oid_compare(const u32_t *oid1, u8_t oid1_len, const u32_t *oid2, u8_t oid2_len) @@ -635,11 +635,11 @@ snmp_oid_compare(const u32_t *oid1, u8_t oid1_len, const u32_t *oid2, u8_t oid2_ /** * Check of two OIDs are equal - * @param oid1 - * @param oid1_len - * @param oid2 - * @param oid2_len - * @return + * @param oid1 OID 1 + * @param oid1_len OID 1 length + * @param oid2 OID 2 + * @param oid2_len OID 2 length + * @return 1: equal 0: non-equal */ u8_t snmp_oid_equal(const u32_t *oid1, u8_t oid1_len, const u32_t *oid2, u8_t oid2_len) @@ -649,7 +649,7 @@ snmp_oid_equal(const u32_t *oid1, u8_t oid1_len, const u32_t *oid2, u8_t oid2_le /** * Convert netif to interface index - * @param netif + * @param netif netif * @return index */ u8_t diff --git a/src/apps/snmp/snmp_mib2_ip.c b/src/apps/snmp/snmp_mib2_ip.c index b28e162f..913d97f9 100644 --- a/src/apps/snmp/snmp_mib2_ip.c +++ b/src/apps/snmp/snmp_mib2_ip.c @@ -146,7 +146,7 @@ ip_get_value(struct snmp_node_instance* instance, void* value) /** * Test ip object value before setting. * - * @param od is the object definition + * @param instance node instance * @param len return value space (in bytes) * @param value points to (varbind) space to copy value from. * diff --git a/src/apps/snmp/snmp_msg.c b/src/apps/snmp/snmp_msg.c index c33180d0..0cb7ca99 100644 --- a/src/apps/snmp/snmp_msg.c +++ b/src/apps/snmp/snmp_msg.c @@ -323,7 +323,7 @@ snmp_process_varbind(struct snmp_request *request, struct snmp_varbind *vb, u8_t /** * Service an internal or external event for SNMP GET. * - * @param msg_ps points to the associated message process state + * @param request points to the associated message process state */ static err_t snmp_process_get_request(struct snmp_request *request) @@ -359,7 +359,7 @@ snmp_process_get_request(struct snmp_request *request) /** * Service an internal or external event for SNMP GET. * - * @param msg_ps points to the associated message process state + * @param request points to the associated message process state */ static err_t snmp_process_getnext_request(struct snmp_request *request) @@ -395,7 +395,7 @@ snmp_process_getnext_request(struct snmp_request *request) /** * Service an internal or external event for SNMP GETBULKT. * - * @param msg_ps points to the associated message process state + * @param request points to the associated message process state */ static err_t snmp_process_getbulk_request(struct snmp_request *request) @@ -493,7 +493,7 @@ snmp_process_getbulk_request(struct snmp_request *request) /** * Service an internal or external event for SNMP SET. * - * @param msg_ps points to the associated message process state + * @param request points to the associated message process state */ static err_t snmp_process_set_request(struct snmp_request *request) diff --git a/src/apps/snmp/snmp_traps.c b/src/apps/snmp/snmp_traps.c index e698e872..0d2df649 100644 --- a/src/apps/snmp/snmp_traps.c +++ b/src/apps/snmp/snmp_traps.c @@ -297,8 +297,8 @@ snmp_trap_varbind_sum(struct snmp_msg_trap *trap, struct snmp_varbind *varbinds) * Sums trap header field lengths from tail to head and * returns trap_header_lengths for second encoding pass. * + * @param trap Trap message * @param vb_len varbind-list length - * @param thl points to returned header lengths * @return the required length for encoding the trap header */ static u16_t diff --git a/src/core/dns.c b/src/core/dns.c index f1b0f436..2aa1dd99 100644 --- a/src/core/dns.c +++ b/src/core/dns.c @@ -1013,8 +1013,6 @@ dns_correct_response(u8_t idx, u32_t ttl) } /** * Receive input function for DNS response packets arriving for the dns UDP pcb. - * - * @params see udp.h */ static void dns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, u16_t port) @@ -1193,7 +1191,7 @@ memerr: * @param hostnamelen length of the hostname * @param found a callback function to be called on success, failure or timeout * @param callback_arg argument to pass to the callback function - * @return @return a err_t return code. + * @return err_t return code. */ static err_t dns_enqueue(const char *name, size_t hostnamelen, dns_found_callback found, @@ -1357,7 +1355,7 @@ dns_gethostbyname(const char *hostname, ip_addr_t *addr, dns_found_callback foun * @param found a callback function to be called on success, failure or timeout (only if * ERR_INPROGRESS is returned!) * @param callback_arg argument to pass to the callback function - * @param dns_addrtype: - LWIP_DNS_ADDRTYPE_IPV4_IPV6: try to resolve IPv4 first, try IPv6 if IPv4 fails only + * @param dns_addrtype - LWIP_DNS_ADDRTYPE_IPV4_IPV6: try to resolve IPv4 first, try IPv6 if IPv4 fails only * - LWIP_DNS_ADDRTYPE_IPV6_IPV4: try to resolve IPv6 first, try IPv4 if IPv6 fails only * - LWIP_DNS_ADDRTYPE_IPV4: try to resolve IPv4 only * - LWIP_DNS_ADDRTYPE_IPV6: try to resolve IPv6 only diff --git a/src/core/ipv4/etharp.c b/src/core/ipv4/etharp.c index 7b41dd94..ba92cde4 100644 --- a/src/core/ipv4/etharp.c +++ b/src/core/ipv4/etharp.c @@ -72,6 +72,7 @@ */ #define ARP_MAXPENDING 5 +/** ARP states */ enum etharp_state { ETHARP_STATE_EMPTY = 0, ETHARP_STATE_PENDING, @@ -239,7 +240,7 @@ etharp_tmr(void) * old entries. Heuristic choose the least important entry for recycling. * * @param ipaddr IP address to find in ARP cache, or to add if not found. - * @param flags @see definition of ETHARP_FLAG_* + * @param flags See @ref etharp_state * @param netif netif related to this address (used for NETIF_HWADDRHINT) * * @return The ARP entry index that matched or is created, ERR_MEM if no @@ -402,7 +403,7 @@ etharp_find_entry(const ip4_addr_t *ipaddr, u8_t flags, struct netif* netif) * @param netif netif related to this entry (used for NETIF_ADDRHINT) * @param ipaddr IP address of the inserted ARP entry. * @param ethaddr Ethernet address of the inserted ARP entry. - * @param flags @see definition of ETHARP_FLAG_* + * @param flags See @ref etharp_state * * @return * - ERR_OK Successfully updated ARP cache. @@ -626,8 +627,6 @@ etharp_get_entry(u8_t i, ip4_addr_t **ipaddr, struct netif **netif, struct eth_a * @param p The ARP packet that arrived on netif. Is freed by this function. * @param netif The lwIP network interface on which the ARP packet pbuf arrived. * - * @return NULL - * * @see pbuf_free() */ void diff --git a/src/core/ipv4/igmp.c b/src/core/ipv4/igmp.c index d8e8f9c2..5ae7d9c8 100644 --- a/src/core/ipv4/igmp.c +++ b/src/core/ipv4/igmp.c @@ -723,8 +723,6 @@ igmp_delaying_member(struct igmp_group *group, u8_t maxresp) * @param src the source IP address to send from (if src == IP4_ADDR_ANY, the * IP address of the netif used to send is used as source address) * @param dest the destination IP address to send the packet to - * @param ttl the TTL value to be set in the IP header - * @param proto the PROTOCOL to be set in the IP header * @param netif the netif on which to send this packet * @return ERR_OK if the packet was sent OK * ERR_BUF if p doesn't have enough space for IP/LINK headers diff --git a/src/core/ipv4/ip4.c b/src/core/ipv4/ip4.c index 5ddd9ffe..c7836774 100644 --- a/src/core/ipv4/ip4.c +++ b/src/core/ipv4/ip4.c @@ -222,7 +222,6 @@ ip4_route(const ip4_addr_t *dest) * that may not be forwarded, or whether datagrams to that destination * may be forwarded. * @param p the packet to forward - * @param dest the destination IP address * @return 1: can forward 0: discard */ static int diff --git a/src/core/ipv4/ip4_frag.c b/src/core/ipv4/ip4_frag.c index dc4c3d45..f5a4d1e9 100644 --- a/src/core/ipv4/ip4_frag.c +++ b/src/core/ipv4/ip4_frag.c @@ -331,7 +331,7 @@ ip_reass_dequeue_datagram(struct ip_reassdata *ipr, struct ip_reassdata *prev) * will grow over time as new pbufs are rx. * Also checks that the datagram passes basic continuity checks (if the last * fragment was received at least once). - * @param root_p points to the 'root' pbuf for the current datagram being assembled. + * @param ipr points to the reassembly state * @param new_p points to the pbuf for the current fragment * @return 0 if invalid, >0 otherwise */ diff --git a/src/core/raw.c b/src/core/raw.c index 111e47fb..e79ffd14 100644 --- a/src/core/raw.c +++ b/src/core/raw.c @@ -250,9 +250,6 @@ raw_connect(struct raw_pcb *pcb, const ip_addr_t *ipaddr) * packet will not be passed to other raw PCBs or other protocol layers. * - not free the packet, and return zero. The packet will be matched * against further PCBs and/or forwarded to another protocol layers. - * - * @return non-zero if the packet was free()d, zero if the packet remains - * available for others. */ void raw_recv(struct raw_pcb *pcb, raw_recv_fn recv, void *recv_arg) diff --git a/src/core/tcp_in.c b/src/core/tcp_in.c index 8925d7a6..93268b34 100644 --- a/src/core/tcp_in.c +++ b/src/core/tcp_in.c @@ -534,10 +534,7 @@ dropped: * connection (from tcp_input()). * * @param pcb the tcp_pcb_listen for which a segment arrived - * @return ERR_OK if the segment was processed - * another err_t on error * - * @note the return value is not (yet?) used in tcp_input() * @note the segment which arrived is saved in global variables, therefore only the pcb * involved is passed as a parameter to this function */ diff --git a/src/include/lwip/pbuf.h b/src/include/lwip/pbuf.h index d79d1717..67405dc1 100644 --- a/src/include/lwip/pbuf.h +++ b/src/include/lwip/pbuf.h @@ -80,13 +80,13 @@ typedef enum { PBUF_IP, /** Includes spare room for link layer header (ethernet header). * Use this if you intend to pass the pbuf to functions like ethernet_output(). - * @see @ref PBUF_LINK_HLEN + * @see PBUF_LINK_HLEN */ PBUF_LINK, /** Includes spare room for additional encapsulation header before ethernet * headers (e.g. 802.11). * Use this if you intend to pass the pbuf to functions like netif->linkoutput(). - * @see @ref PBUF_LINK_ENCAPSULATION_HLEN + * @see PBUF_LINK_ENCAPSULATION_HLEN */ PBUF_RAW_TX, /** Use this for input packets in a netif driver when calling netif->input() diff --git a/src/netif/ethernet.c b/src/netif/ethernet.c index 246eb459..9b76e85f 100644 --- a/src/netif/ethernet.c +++ b/src/netif/ethernet.c @@ -69,9 +69,9 @@ const struct eth_addr ethzero = {{0,0,0,0,0,0}}; * @param p the received packet, p->payload pointing to the ethernet header * @param netif the network interface on which the packet was received * - * @see @ref LWIP_HOOK_UNKNOWN_ETH_PROTOCOL, - * @ref ETHARP_SUPPORT_VLAN and - * @ref LWIP_HOOK_VLAN_CHECK. + * @see LWIP_HOOK_UNKNOWN_ETH_PROTOCOL + * @see ETHARP_SUPPORT_VLAN + * @see LWIP_HOOK_VLAN_CHECK */ err_t ethernet_input(struct pbuf *p, struct netif *netif) @@ -247,7 +247,7 @@ free_and_return: * Send an ethernet packet on the network using netif->linkoutput(). * The ethernet header is filled in before sending. * - * @see @ref LWIP_HOOK_VLAN_SET + * @see LWIP_HOOK_VLAN_SET * * @param netif the lwIP network interface on which to send the packet * @param p the packet to send. pbuf layer must be @ref PBUF_LINK. diff --git a/src/netif/lowpan6.c b/src/netif/lowpan6.c index eb0fe71d..eca9a453 100644 --- a/src/netif/lowpan6.c +++ b/src/netif/lowpan6.c @@ -611,7 +611,7 @@ lowpan4_output(struct netif *netif, struct pbuf *q, const ip4_addr_t *ipaddr) * @param q The pbuf(s) containing the IP packet to be sent. * @param ip6addr The IP address of the packet destination. * - * @return + * @return err_t */ err_t lowpan6_output(struct netif *netif, struct pbuf *q, const ip6_addr_t *ip6addr) diff --git a/src/netif/ppp/pppos.c b/src/netif/ppp/pppos.c index b4d435e8..5220ed30 100644 --- a/src/netif/ppp/pppos.c +++ b/src/netif/ppp/pppos.c @@ -404,9 +404,9 @@ pppos_destroy(ppp_pcb *ppp, void *ctx) #if !NO_SYS && !PPP_INPROC_IRQ_SAFE /** Pass received raw characters to PPPoS to be decoded through lwIP TCPIP thread. * - * @param pcb PPP descriptor index, returned by pppos_create() - * @param data received data - * @param len length of received data + * @param ppp PPP descriptor index, returned by pppos_create() + * @param s received data + * @param l length of received data */ err_t pppos_input_tcpip(ppp_pcb *ppp, u8_t *s, int l) @@ -458,9 +458,9 @@ PACK_STRUCT_END /** Pass received raw characters to PPPoS to be decoded. * - * @param pcb PPP descriptor index, returned by pppos_create() - * @param data received data - * @param len length of received data + * @param ppp PPP descriptor index, returned by pppos_create() + * @param s received data + * @param l length of received data */ void pppos_input(ppp_pcb *ppp, u8_t *s, int l) diff --git a/src/netif/slipif.c b/src/netif/slipif.c index 8849fbf6..6eb83c35 100644 --- a/src/netif/slipif.c +++ b/src/netif/slipif.c @@ -304,7 +304,7 @@ slipif_rxbyte(struct netif *netif, u8_t c) /** Like slipif_rxbyte, but passes completed packets to netif->input * * @param netif The lwip network interface structure for this slipif - * @param data received character + * @param c received character */ static void slipif_rxbyte_input(struct netif *netif, u8_t c) From 695c81762c598a76b43ca1f23f3c1da5df40a2d1 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Sun, 9 Oct 2016 12:28:34 +0200 Subject: [PATCH 293/325] Minor: Fix comment in etharp.c --- src/core/ipv4/etharp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/ipv4/etharp.c b/src/core/ipv4/etharp.c index ba92cde4..bf4dad53 100644 --- a/src/core/ipv4/etharp.c +++ b/src/core/ipv4/etharp.c @@ -491,7 +491,7 @@ etharp_update_arp_entry(struct netif *netif, const ip4_addr_t *ipaddr, struct et * * @param ipaddr IP address for the new static entry * @param ethaddr ethernet address for the new static entry - * @return @see return values of etharp_add_static_entry + * @return See return values of etharp_add_static_entry */ err_t etharp_add_static_entry(const ip4_addr_t *ipaddr, struct eth_addr *ethaddr) From ed239c4e71cc4737969909d8f5274b1e7a416c13 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Mon, 10 Oct 2016 09:57:07 +0200 Subject: [PATCH 294/325] Apply patch #9139: Invalid format string in dhcp.c by Thomas Mueller --- src/core/ipv4/dhcp.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/ipv4/dhcp.c b/src/core/ipv4/dhcp.c index ecf19bdb..b17fd779 100644 --- a/src/core/ipv4/dhcp.c +++ b/src/core/ipv4/dhcp.c @@ -1519,7 +1519,7 @@ again: break; case(DHCP_OPTION_DNS_SERVER): /* special case: there might be more than one server */ - LWIP_ERROR("len % 4 == 0", len % 4 == 0, return ERR_VAL;); + LWIP_ERROR("len %% 4 == 0", len % 4 == 0, return ERR_VAL;); /* limit number of DNS servers */ decode_len = LWIP_MIN(len, 4 * DNS_MAX_SERVERS); LWIP_ERROR("len >= decode_len", len >= decode_len, return ERR_VAL;); @@ -1532,7 +1532,7 @@ again: #if LWIP_DHCP_GET_NTP_SRV case(DHCP_OPTION_NTP): /* special case: there might be more than one server */ - LWIP_ERROR("len % 4 == 0", len % 4 == 0, return ERR_VAL;); + LWIP_ERROR("len %% 4 == 0", len % 4 == 0, return ERR_VAL;); /* limit number of NTP servers */ decode_len = LWIP_MIN(len, 4 * LWIP_DHCP_MAX_NTP_SERVERS); LWIP_ERROR("len >= decode_len", len >= decode_len, return ERR_VAL;); @@ -1577,7 +1577,7 @@ decode_next: } if (decode_len > 4) { /* decode more than one u32_t */ - LWIP_ERROR("decode_len % 4 == 0", decode_len % 4 == 0, return ERR_VAL;); + LWIP_ERROR("decode_len %% 4 == 0", decode_len % 4 == 0, return ERR_VAL;); dhcp_got_option(dhcp, decode_idx); dhcp_set_option_value(dhcp, decode_idx, lwip_htonl(value)); decode_len -= 4; From 0a343948d9446fcbe2290d411e526d826f55fb83 Mon Sep 17 00:00:00 2001 From: sg Date: Fri, 7 Oct 2016 21:46:26 +0200 Subject: [PATCH 295/325] Fix netconn/socket race condition when receiving RST while waiting on recvmbox --- src/api/api_lib.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/api/api_lib.c b/src/api/api_lib.c index 193a608f..b4fc403d 100644 --- a/src/api/api_lib.c +++ b/src/api/api_lib.c @@ -544,6 +544,10 @@ netconn_recv_data(struct netconn *conn, void **new_buf) /* If we are closed, we indicate that we no longer wish to use the socket */ if (buf == NULL) { API_EVENT(conn, NETCONN_EVT_RCVMINUS, 0); + if (conn->pcb.ip == NULL) { + /* race condition: RST during recv */ + return conn->last_err == ERR_OK ? ERR_RST : conn->last_err; + } /* RX side is closed, so deallocate the recvmbox */ netconn_close_shutdown(conn, NETCONN_SHUT_RD); /* Don' store ERR_CLSD as conn->err since we are only half-closed */ From c9cfbe27c13a6dcf696e8281763d1fc21648c7cf Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Sun, 9 Oct 2016 15:48:07 +0800 Subject: [PATCH 296/325] tcp_out: Remove misleading comment in tcp_pbuf_prealloc() This comment is incorrect since commit 7d0dab9d7d0c "partly fixed bug #25882: TCP hangs on MSS > pcb->snd_wnd (by not creating segments bigger than half the window)". Signed-off-by: Axel Lin --- src/core/tcp_out.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/core/tcp_out.c b/src/core/tcp_out.c index 5a9c0319..a64e420d 100644 --- a/src/core/tcp_out.c +++ b/src/core/tcp_out.c @@ -242,7 +242,6 @@ tcp_pbuf_prealloc(pbuf_layer layer, u16_t length, u16_t max_length, LWIP_UNUSED_ARG(pcb); LWIP_UNUSED_ARG(apiflags); LWIP_UNUSED_ARG(first_seg); - /* always create MSS-sized pbufs */ alloc = max_length; #else /* LWIP_NETIF_TX_SINGLE_PBUF */ if (length < max_length) { From 697be5c2c384dbecd849743de692d4385b4ab0f3 Mon Sep 17 00:00:00 2001 From: goldsimon Date: Tue, 11 Oct 2016 09:23:45 +0200 Subject: [PATCH 297/325] Make some pbuf functions take const pbuf pointers --- src/core/pbuf.c | 53 +++++++++++++++++++++++------------------ src/include/lwip/pbuf.h | 16 ++++++------- 2 files changed, 38 insertions(+), 31 deletions(-) diff --git a/src/core/pbuf.c b/src/core/pbuf.c index bb2c8311..ac638046 100644 --- a/src/core/pbuf.c +++ b/src/core/pbuf.c @@ -782,7 +782,7 @@ pbuf_free(struct pbuf *p) * @return the number of pbufs in a chain */ u16_t -pbuf_clen(struct pbuf *p) +pbuf_clen(const struct pbuf *p) { u16_t len; @@ -929,7 +929,7 @@ pbuf_dechain(struct pbuf *p) * enough to hold p_from */ err_t -pbuf_copy(struct pbuf *p_to, struct pbuf *p_from) +pbuf_copy(struct pbuf *p_to, const struct pbuf *p_from) { u16_t offset_to=0, offset_from=0, len; @@ -996,9 +996,9 @@ pbuf_copy(struct pbuf *p_to, struct pbuf *p_from) * @return the number of bytes copied, or 0 on failure */ u16_t -pbuf_copy_partial(struct pbuf *buf, void *dataptr, u16_t len, u16_t offset) +pbuf_copy_partial(const struct pbuf *buf, void *dataptr, u16_t len, u16_t offset) { - struct pbuf *p; + const struct pbuf *p; u16_t left; u16_t buf_copy_len; u16_t copied_total = 0; @@ -1084,6 +1084,24 @@ void pbuf_split_64k(struct pbuf *p, struct pbuf **rest) } #endif /* LWIP_TCP && TCP_QUEUE_OOSEQ && LWIP_WND_SCALE */ +/* Actual implementation of pbuf_skip() but returning const pointer... */ +static const struct pbuf* +pbuf_skip_const(const struct pbuf* in, u16_t in_offset, u16_t* out_offset) +{ + u16_t offset_left = in_offset; + const struct pbuf* q = in; + + /* get the correct pbuf */ + while ((q != NULL) && (q->len <= offset_left)) { + offset_left -= q->len; + q = q->next; + } + if (out_offset != NULL) { + *out_offset = offset_left; + } + return q; +} + /** * @ingroup pbuf * Skip a number of bytes at the start of a pbuf @@ -1096,18 +1114,7 @@ void pbuf_split_64k(struct pbuf *p, struct pbuf **rest) struct pbuf* pbuf_skip(struct pbuf* in, u16_t in_offset, u16_t* out_offset) { - u16_t offset_left = in_offset; - struct pbuf* q = in; - - /* get the correct pbuf */ - while ((q != NULL) && (q->len <= offset_left)) { - offset_left -= q->len; - q = q->next; - } - if (out_offset != NULL) { - *out_offset = offset_left; - } - return q; + return (struct pbuf*)(size_t)pbuf_skip_const(in, in_offset, out_offset); } /** @@ -1271,7 +1278,7 @@ pbuf_fill_chksum(struct pbuf *p, u16_t start_offset, const void *dataptr, * @return byte at an offset into p OR ZERO IF 'offset' >= p->tot_len */ u8_t -pbuf_get_at(struct pbuf* p, u16_t offset) +pbuf_get_at(const struct pbuf* p, u16_t offset) { int ret = pbuf_try_get_at(p, offset); if (ret >= 0) { @@ -1289,10 +1296,10 @@ pbuf_get_at(struct pbuf* p, u16_t offset) * @return byte at an offset into p [0..0xFF] OR negative if 'offset' >= p->tot_len */ int -pbuf_try_get_at(struct pbuf* p, u16_t offset) +pbuf_try_get_at(const struct pbuf* p, u16_t offset) { u16_t q_idx; - struct pbuf* q = pbuf_skip(p, offset, &q_idx); + const struct pbuf* q = pbuf_skip_const(p, offset, &q_idx); /* return requested data if pbuf is OK */ if ((q != NULL) && (q->len > q_idx)) { @@ -1334,10 +1341,10 @@ pbuf_put_at(struct pbuf* p, u16_t offset, u8_t data) * (0xffff if p is too short, diffoffset+1 otherwise) */ u16_t -pbuf_memcmp(struct pbuf* p, u16_t offset, const void* s2, u16_t n) +pbuf_memcmp(const struct pbuf* p, u16_t offset, const void* s2, u16_t n) { u16_t start = offset; - struct pbuf* q = p; + const struct pbuf* q = p; u16_t i; /* pbuf long enough to perform check? */ @@ -1376,7 +1383,7 @@ pbuf_memcmp(struct pbuf* p, u16_t offset, const void* s2, u16_t n) * @return 0xFFFF if substr was not found in p or the index where it was found */ u16_t -pbuf_memfind(struct pbuf* p, const void* mem, u16_t mem_len, u16_t start_offset) +pbuf_memfind(const struct pbuf* p, const void* mem, u16_t mem_len, u16_t start_offset) { u16_t i; u16_t max = p->tot_len - mem_len; @@ -1403,7 +1410,7 @@ pbuf_memfind(struct pbuf* p, const void* mem, u16_t mem_len, u16_t start_offset) * @return 0xFFFF if substr was not found in p or the index where it was found */ u16_t -pbuf_strstr(struct pbuf* p, const char* substr) +pbuf_strstr(const struct pbuf* p, const char* substr) { size_t substr_len; if ((substr == NULL) || (substr[0] == 0) || (p->tot_len == 0xFFFF)) { diff --git a/src/include/lwip/pbuf.h b/src/include/lwip/pbuf.h index 67405dc1..90610461 100644 --- a/src/include/lwip/pbuf.h +++ b/src/include/lwip/pbuf.h @@ -231,12 +231,12 @@ u8_t pbuf_header(struct pbuf *p, s16_t header_size); u8_t pbuf_header_force(struct pbuf *p, s16_t header_size); void pbuf_ref(struct pbuf *p); u8_t pbuf_free(struct pbuf *p); -u16_t pbuf_clen(struct pbuf *p); +u16_t pbuf_clen(const struct pbuf *p); void pbuf_cat(struct pbuf *head, struct pbuf *tail); 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_copy(struct pbuf *p_to, const struct pbuf *p_from); +u16_t pbuf_copy_partial(const struct pbuf *p, void *dataptr, u16_t len, u16_t offset); err_t pbuf_take(struct pbuf *buf, const void *dataptr, u16_t len); err_t pbuf_take_at(struct pbuf *buf, const void *dataptr, u16_t len, u16_t offset); struct pbuf *pbuf_skip(struct pbuf* in, u16_t in_offset, u16_t* out_offset); @@ -249,12 +249,12 @@ err_t pbuf_fill_chksum(struct pbuf *p, u16_t start_offset, const void *dataptr, void pbuf_split_64k(struct pbuf *p, struct pbuf **rest); #endif /* LWIP_TCP && TCP_QUEUE_OOSEQ && LWIP_WND_SCALE */ -u8_t pbuf_get_at(struct pbuf* p, u16_t offset); -int pbuf_try_get_at(struct pbuf* p, u16_t offset); +u8_t pbuf_get_at(const struct pbuf* p, u16_t offset); +int pbuf_try_get_at(const struct pbuf* p, u16_t offset); void pbuf_put_at(struct pbuf* p, u16_t offset, u8_t data); -u16_t pbuf_memcmp(struct pbuf* p, u16_t offset, const void* s2, u16_t n); -u16_t pbuf_memfind(struct pbuf* p, const void* mem, u16_t mem_len, u16_t start_offset); -u16_t pbuf_strstr(struct pbuf* p, const char* substr); +u16_t pbuf_memcmp(const struct pbuf* p, u16_t offset, const void* s2, u16_t n); +u16_t pbuf_memfind(const struct pbuf* p, const void* mem, u16_t mem_len, u16_t start_offset); +u16_t pbuf_strstr(const struct pbuf* p, const char* substr); #ifdef __cplusplus } From 576f49ee2bad3839490e915c24ad1837d655637a Mon Sep 17 00:00:00 2001 From: goldsimon Date: Tue, 11 Oct 2016 09:47:03 +0200 Subject: [PATCH 298/325] Fixed bug #46467: ip_frag() shouldn't modify pbuf in case of a retransmission --- src/core/ipv4/ip4_frag.c | 55 +++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/src/core/ipv4/ip4_frag.c b/src/core/ipv4/ip4_frag.c index f5a4d1e9..56a9b044 100644 --- a/src/core/ipv4/ip4_frag.c +++ b/src/core/ipv4/ip4_frag.c @@ -690,11 +690,10 @@ ip4_frag(struct pbuf *p, struct netif *netif, const ip4_addr_t *dest) #endif struct ip_hdr *original_iphdr; struct ip_hdr *iphdr; - u16_t nfb; - u16_t left, cop; - u16_t mtu = netif->mtu; - u16_t ofo, omf; - u16_t last; + const u16_t nfb = (netif->mtu - IP_HLEN) / 8; + u16_t left, fragsize; + u16_t ofo; + int last; u16_t poff = IP_HLEN; u16_t tmp; #if !LWIP_NETIF_TX_SINGLE_PBUF @@ -704,36 +703,27 @@ ip4_frag(struct pbuf *p, struct netif *netif, const ip4_addr_t *dest) original_iphdr = (struct ip_hdr *)p->payload; iphdr = original_iphdr; + LWIP_ERROR("ip4_frag() does not support IP options", IPH_HL(iphdr) * 4 == IP_HLEN, return ERR_VAL); /* Save original offset */ - tmp = lwip_ntohs(IPH_OFFSET(iphdr)); + tmp = ntohs(IPH_OFFSET(iphdr)); ofo = tmp & IP_OFFMASK; - omf = tmp & IP_MF; + LWIP_ERROR("ip_frag(): MF already set", (tmp & IP_MF) == 0, return ERR_VAL); left = p->tot_len - IP_HLEN; - nfb = (mtu - IP_HLEN) / 8; - while (left) { - last = (left <= mtu - IP_HLEN); - - /* Set new offset and MF flag */ - tmp = omf | (IP_OFFMASK & (ofo)); - if (!last) { - tmp = tmp | IP_MF; - } - /* Fill this fragment */ - cop = last ? left : nfb * 8; + fragsize = (left < nfb * 8) ? left : nfb * 8; #if LWIP_NETIF_TX_SINGLE_PBUF - rambuf = pbuf_alloc(PBUF_IP, cop, PBUF_RAM); + rambuf = pbuf_alloc(PBUF_IP, fragsize, PBUF_RAM); if (rambuf == NULL) { goto memerr; } LWIP_ASSERT("this needs a pbuf in one piece!", (rambuf->len == rambuf->tot_len) && (rambuf->next == NULL)); - poff += pbuf_copy_partial(p, rambuf->payload, cop, poff); + poff += pbuf_copy_partial(p, rambuf->payload, fragsize, poff); /* make room for the IP header */ if (pbuf_header(rambuf, IP_HLEN)) { pbuf_free(rambuf); @@ -757,16 +747,14 @@ ip4_frag(struct pbuf *p, struct netif *netif, const ip4_addr_t *dest) SMEMCPY(rambuf->payload, original_iphdr, IP_HLEN); iphdr = (struct ip_hdr *)rambuf->payload; - /* Can just adjust p directly for needed offset. */ - p->payload = (u8_t *)p->payload + poff; - p->len -= poff; - - left_to_copy = cop; + left_to_copy = fragsize; while (left_to_copy) { struct pbuf_custom_ref *pcr; - newpbuflen = (left_to_copy < p->len) ? left_to_copy : p->len; + u16_t plen = p->len - poff; + newpbuflen = (left_to_copy < plen) ? left_to_copy : plen; /* Is this pbuf already empty? */ if (!newpbuflen) { + poff = 0; p = p->next; continue; } @@ -776,7 +764,8 @@ ip4_frag(struct pbuf *p, struct netif *netif, const ip4_addr_t *dest) goto memerr; } /* Mirror this pbuf, although we might not need all of it. */ - newpbuf = pbuf_alloced_custom(PBUF_RAW, newpbuflen, PBUF_REF, &pcr->pc, p->payload, newpbuflen); + newpbuf = pbuf_alloced_custom(PBUF_RAW, newpbuflen, PBUF_REF, &pcr->pc, + (u8_t*)p->payload + poff, newpbuflen); if (newpbuf == NULL) { ip_frag_free_pbuf_custom_ref(pcr); pbuf_free(rambuf); @@ -792,6 +781,7 @@ ip4_frag(struct pbuf *p, struct netif *netif, const ip4_addr_t *dest) pbuf_cat(rambuf, newpbuf); left_to_copy -= newpbuflen; if (left_to_copy) { + poff = 0; p = p->next; } } @@ -799,8 +789,15 @@ ip4_frag(struct pbuf *p, struct netif *netif, const ip4_addr_t *dest) #endif /* LWIP_NETIF_TX_SINGLE_PBUF */ /* Correct header */ + last = (left <= netif->mtu - IP_HLEN); + + /* Set new offset and MF flag */ + tmp = (IP_OFFMASK & (ofo)); + if (!last) { + tmp = tmp | IP_MF; + } IPH_OFFSET_SET(iphdr, lwip_htons(tmp)); - IPH_LEN_SET(iphdr, lwip_htons(cop + IP_HLEN)); + IPH_LEN_SET(iphdr, lwip_htons(fragsize + IP_HLEN)); IPH_CHKSUM_SET(iphdr, 0); #if CHECKSUM_GEN_IP IF__NETIF_CHECKSUM_ENABLED(netif, NETIF_CHECKSUM_GEN_IP) { @@ -822,7 +819,7 @@ ip4_frag(struct pbuf *p, struct netif *netif, const ip4_addr_t *dest) */ pbuf_free(rambuf); - left -= cop; + left -= fragsize; ofo += nfb; } MIB2_STATS_INC(mib2.ipfragoks); From d5bfec2e52d337b21634fb1401b5f468479181a7 Mon Sep 17 00:00:00 2001 From: goldsimon Date: Tue, 11 Oct 2016 09:52:20 +0200 Subject: [PATCH 299/325] ip4_frag: restore "lwip_ntohs" after last change --- src/core/ipv4/ip4_frag.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/ipv4/ip4_frag.c b/src/core/ipv4/ip4_frag.c index 56a9b044..9812a085 100644 --- a/src/core/ipv4/ip4_frag.c +++ b/src/core/ipv4/ip4_frag.c @@ -706,7 +706,7 @@ ip4_frag(struct pbuf *p, struct netif *netif, const ip4_addr_t *dest) LWIP_ERROR("ip4_frag() does not support IP options", IPH_HL(iphdr) * 4 == IP_HLEN, return ERR_VAL); /* Save original offset */ - tmp = ntohs(IPH_OFFSET(iphdr)); + tmp = lwip_ntohs(IPH_OFFSET(iphdr)); ofo = tmp & IP_OFFMASK; LWIP_ERROR("ip_frag(): MF already set", (tmp & IP_MF) == 0, return ERR_VAL); From 6edde498e386ee0f359da27c5167fba75415d449 Mon Sep 17 00:00:00 2001 From: goldsimon Date: Tue, 11 Oct 2016 09:52:44 +0200 Subject: [PATCH 300/325] pbuf_copy: try to fix GCC const warning --- src/core/pbuf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/pbuf.c b/src/core/pbuf.c index ac638046..1c45224a 100644 --- a/src/core/pbuf.c +++ b/src/core/pbuf.c @@ -934,7 +934,7 @@ pbuf_copy(struct pbuf *p_to, const struct pbuf *p_from) u16_t offset_to=0, offset_from=0, len; LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_copy(%p, %p)\n", - (void*)p_to, (void*)p_from)); + (const void*)p_to, (const void*)p_from)); /* is the target big enough to hold the source? */ LWIP_ERROR("pbuf_copy: target not big enough to hold source", ((p_to != NULL) && From 725feb0d4ada64d5dd9675df9aaa66b922ef74e0 Mon Sep 17 00:00:00 2001 From: Erik Ekman Date: Tue, 11 Oct 2016 11:34:59 +0200 Subject: [PATCH 301/325] mdns: Use netif_get/set_client_data helpers --- src/apps/mdns/mdns.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/apps/mdns/mdns.c b/src/apps/mdns/mdns.c index 519a630c..e0c528c3 100644 --- a/src/apps/mdns/mdns.c +++ b/src/apps/mdns/mdns.c @@ -107,7 +107,7 @@ static const ip_addr_t v6group = IPADDR6_INIT(PP_HTONL(0xFF020000UL), PP_HTONL(0 static u8_t mdns_netif_client_id; static struct udp_pcb *mdns_pcb; -#define NETIF_TO_HOST(netif) (struct mdns_host*)((netif)->client_data[mdns_netif_client_id]) +#define NETIF_TO_HOST(netif) (struct mdns_host*)(netif_get_client_data(netif, mdns_netif_client_id)) #define TOPDOMAIN_LOCAL "local" @@ -1756,7 +1756,7 @@ mdns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, LWIP_DEBUGF(MDNS_DEBUG, ("MDNS: Received IPv%d MDNS packet, len %d\n", IP_IS_V6(addr)? 6 : 4, p->tot_len)); - if (recv_netif->client_data[mdns_netif_client_id] == NULL) { + if (NETIF_TO_HOST(recv_netif) == NULL) { /* From netif not configured for MDNS */ goto dealloc; } @@ -1843,7 +1843,7 @@ mdns_resp_netif_settings_changed(struct netif *netif) { LWIP_ERROR("mdns_resp_netif_ip_changed: netif != NULL", (netif != NULL), return); - if (netif->client_data[mdns_netif_client_id] == NULL) { + if (NETIF_TO_HOST(netif) == NULL) { return; } @@ -1875,11 +1875,11 @@ mdns_resp_add_netif(struct netif *netif, const char *hostname, u32_t dns_ttl) LWIP_ERROR("mdns_resp_add_netif: netif != NULL", (netif != NULL), return ERR_VAL); LWIP_ERROR("mdns_resp_add_netif: Hostname too long", (strlen(hostname) <= MDNS_LABEL_MAXLEN), return ERR_VAL); - LWIP_ASSERT("mdns_resp_add_netif: Double add", netif->client_data[mdns_netif_client_id] == NULL); + LWIP_ASSERT("mdns_resp_add_netif: Double add", NETIF_TO_HOST(netif) == NULL); mdns = (struct mdns_host *) mem_malloc(sizeof(struct mdns_host)); LWIP_ERROR("mdns_resp_add_netif: Alloc failed", (mdns != NULL), return ERR_MEM); - netif->client_data[mdns_netif_client_id] = mdns; + netif_set_client_data(netif, mdns_netif_client_id, mdns); memset(mdns, 0, sizeof(struct mdns_host)); MEMCPY(&mdns->name, hostname, LWIP_MIN(MDNS_LABEL_MAXLEN, strlen(hostname))); @@ -1904,7 +1904,7 @@ mdns_resp_add_netif(struct netif *netif, const char *hostname, u32_t dns_ttl) cleanup: mem_free(mdns); - netif->client_data[mdns_netif_client_id] = NULL; + netif_set_client_data(netif, mdns_netif_client_id, NULL); return res; } @@ -1941,7 +1941,7 @@ mdns_resp_remove_netif(struct netif *netif) #endif mem_free(mdns); - netif->client_data[mdns_netif_client_id] = NULL; + netif_set_client_data(netif, mdns_netif_client_id, NULL); return ERR_OK; } From 37d5691b19d5d90757df2548584f065320d7f092 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Wed, 12 Oct 2016 07:37:39 +0200 Subject: [PATCH 302/325] Fix bug #49321: error.h missing opening "#ifdef __cplusplus" Reported by Martin Kortmann --- src/include/lwip/errno.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/include/lwip/errno.h b/src/include/lwip/errno.h index e2d996c6..25bc1f89 100644 --- a/src/include/lwip/errno.h +++ b/src/include/lwip/errno.h @@ -39,6 +39,10 @@ #include "lwip/opt.h" +#ifdef __cplusplus +extern "C" { +#endif + #ifdef LWIP_PROVIDE_ERRNO #define EPERM 1 /* Operation not permitted */ From e3a9f01fe4df341cb4a73b3f4ba5535b20b499df Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Wed, 12 Oct 2016 21:41:02 +0200 Subject: [PATCH 303/325] Implement task #14180: IPv6 code should not reuse ip6_current_dest_addr() as temporary storage --- src/core/ipv6/nd6.c | 50 ++++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/src/core/ipv6/nd6.c b/src/core/ipv6/nd6.c index ec996e42..82394f6e 100644 --- a/src/core/ipv6/nd6.c +++ b/src/core/ipv6/nd6.c @@ -149,6 +149,8 @@ nd6_input(struct pbuf *p, struct netif *inp) /* Unsolicited NA?*/ if (ip6_addr_ismulticast(ip6_current_dest_addr())) { + ip6_addr_t target_address; + /* This is an unsolicited NA. * link-layer changed? * part of DAD mechanism? */ @@ -172,14 +174,14 @@ nd6_input(struct pbuf *p, struct netif *inp) return; } - /* Override ip6_current_dest_addr() so that we have an aligned copy. */ - ip6_addr_set(ip6_current_dest_addr(), &(na_hdr->target_address)); + /* Create an aligned copy. */ + ip6_addr_set(&target_address, &(na_hdr->target_address)); #if LWIP_IPV6_DUP_DETECT_ATTEMPTS /* If the target address matches this netif, it is a DAD response. */ for (i = 0; i < LWIP_IPV6_NUM_ADDRESSES; i++) { if (!ip6_addr_isinvalid(netif_ip6_addr_state(inp, i)) && - ip6_addr_cmp(ip6_current_dest_addr(), netif_ip6_addr(inp, i))) { + ip6_addr_cmp(&target_address, netif_ip6_addr(inp, i))) { /* We are using a duplicate address. */ netif_ip6_addr_set_state(inp, i, IP6_ADDR_INVALID); @@ -191,8 +193,8 @@ nd6_input(struct pbuf *p, struct netif *inp) #if LWIP_IPV6_AUTOCONFIG /* Check to see if this address was autoconfigured. */ - if (!ip6_addr_islinklocal(ip6_current_dest_addr())) { - i = nd6_get_onlink_prefix(ip6_current_dest_addr(), inp); + if (!ip6_addr_islinklocal(&target_address)) { + i = nd6_get_onlink_prefix(&target_address, inp); if (i >= 0) { /* Mark this prefix as duplicate, so that we don't use it * to generate this address again. */ @@ -208,22 +210,24 @@ nd6_input(struct pbuf *p, struct netif *inp) #endif /* LWIP_IPV6_DUP_DETECT_ATTEMPTS */ /* This is an unsolicited NA, most likely there was a LLADDR change. */ - i = nd6_find_neighbor_cache_entry(ip6_current_dest_addr()); + i = nd6_find_neighbor_cache_entry(&target_address); if (i >= 0) { if (na_hdr->flags & ND6_FLAG_OVERRIDE) { MEMCPY(neighbor_cache[i].lladdr, lladdr_opt->addr, inp->hwaddr_len); } } } else { + ip6_addr_t target_address; + /* This is a solicited NA. * neighbor address resolution response? * neighbor unreachability detection response? */ - /* Override ip6_current_dest_addr() so that we have an aligned copy. */ - ip6_addr_set(ip6_current_dest_addr(), &(na_hdr->target_address)); + /* Create an aligned copy. */ + ip6_addr_set(&target_address, &(na_hdr->target_address)); /* Find the cache entry corresponding to this na. */ - i = nd6_find_neighbor_cache_entry(ip6_current_dest_addr()); + i = nd6_find_neighbor_cache_entry(&target_address); if (i < 0) { /* We no longer care about this target address. drop it. */ pbuf_free(p); @@ -327,6 +331,8 @@ nd6_input(struct pbuf *p, struct netif *inp) } } } else { + ip6_addr_t target_address; + /* Sender is trying to resolve our address. */ /* Verify that they included their own link-layer address. */ if (lladdr_opt == NULL) { @@ -370,11 +376,11 @@ nd6_input(struct pbuf *p, struct netif *inp) neighbor_cache[i].counter.delay_time = LWIP_ND6_DELAY_FIRST_PROBE_TIME / ND6_TMR_INTERVAL; } - /* Override ip6_current_dest_addr() so that we have an aligned copy. */ - ip6_addr_set(ip6_current_dest_addr(), &(ns_hdr->target_address)); + /* Create an aligned copy. */ + ip6_addr_set(&target_address, &(ns_hdr->target_address)); /* Send back a NA for us. Allocate the reply pbuf. */ - nd6_send_na(inp, ip6_current_dest_addr(), ND6_FLAG_SOLICITED | ND6_FLAG_OVERRIDE); + nd6_send_na(inp, &target_address, ND6_FLAG_SOLICITED | ND6_FLAG_OVERRIDE); } break; /* ICMP6_TYPE_NS */ @@ -496,15 +502,16 @@ nd6_input(struct pbuf *p, struct netif *inp) !ip6_addr_islinklocal(&(prefix_opt->prefix))) { /* Add to on-link prefix list. */ s8_t prefix; + ip6_addr_t prefix_addr; /* Get a memory-aligned copy of the prefix. */ - ip6_addr_set(ip6_current_dest_addr(), &(prefix_opt->prefix)); + ip6_addr_set(&prefix_addr, &(prefix_opt->prefix)); /* find cache entry for this prefix. */ - prefix = nd6_get_onlink_prefix(ip6_current_dest_addr(), inp); + prefix = nd6_get_onlink_prefix(&prefix_addr, inp); if (prefix < 0) { /* Create a new cache entry. */ - prefix = nd6_new_onlink_prefix(ip6_current_dest_addr(), inp); + prefix = nd6_new_onlink_prefix(&prefix_addr, inp); } if (prefix >= 0) { prefix_list[prefix].invalidation_timer = lwip_htonl(prefix_opt->valid_lifetime); @@ -1763,6 +1770,7 @@ static void nd6_send_q(s8_t i) { struct ip6_hdr *ip6hdr; + ip6_addr_t dest; #if LWIP_ND6_QUEUEING struct nd6_q_entry *q; #endif /* LWIP_ND6_QUEUEING */ @@ -1779,10 +1787,10 @@ nd6_send_q(s8_t i) neighbor_cache[i].q = q->next; /* Get ipv6 header. */ ip6hdr = (struct ip6_hdr *)(q->p->payload); - /* Override ip6_current_dest_addr() so that we have an aligned copy. */ - ip6_addr_set(ip6_current_dest_addr(), &(ip6hdr->dest)); + /* Create an aligned copy. */ + ip6_addr_set(&dest, &(ip6hdr->dest)); /* send the queued IPv6 packet */ - (neighbor_cache[i].netif)->output_ip6(neighbor_cache[i].netif, q->p, ip6_current_dest_addr()); + (neighbor_cache[i].netif)->output_ip6(neighbor_cache[i].netif, q->p, &dest); /* free the queued IP packet */ pbuf_free(q->p); /* now queue entry can be freed */ @@ -1792,10 +1800,10 @@ nd6_send_q(s8_t i) if (neighbor_cache[i].q != NULL) { /* Get ipv6 header. */ ip6hdr = (struct ip6_hdr *)(neighbor_cache[i].q->payload); - /* Override ip6_current_dest_addr() so that we have an aligned copy. */ - ip6_addr_set(ip6_current_dest_addr(), &(ip6hdr->dest)); + /* Create an aligned copy. */ + ip6_addr_set(&dest, &(ip6hdr->dest)); /* send the queued IPv6 packet */ - (neighbor_cache[i].netif)->output_ip6(neighbor_cache[i].netif, neighbor_cache[i].q, ip6_current_dest_addr()); + (neighbor_cache[i].netif)->output_ip6(neighbor_cache[i].netif, neighbor_cache[i].q, &dest); /* free the queued IP packet */ pbuf_free(neighbor_cache[i].q); neighbor_cache[i].q = NULL; From f5f8ab5acf389a9cda805830c04ef44fc89266ba Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Thu, 13 Oct 2016 08:50:47 +0200 Subject: [PATCH 304/325] Fix bug #49328: Crash error in ip6_frag due to Assertion Fail --- src/core/ipv6/ip6_frag.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/ipv6/ip6_frag.c b/src/core/ipv6/ip6_frag.c index 1f746732..b374f691 100644 --- a/src/core/ipv6/ip6_frag.c +++ b/src/core/ipv6/ip6_frag.c @@ -697,7 +697,7 @@ ip6_frag(struct pbuf *p, struct netif *netif, const ip6_addr_t *dest) return ERR_MEM; } LWIP_ASSERT("this needs a pbuf in one piece!", - (p->len >= (IP6_HLEN + IP6_FRAG_HLEN))); + (p->len >= (IP6_HLEN))); SMEMCPY(rambuf->payload, original_ip6hdr, IP6_HLEN); ip6hdr = (struct ip6_hdr *)rambuf->payload; frag_hdr = (struct ip6_frag_hdr *)((u8_t*)rambuf->payload + IP6_HLEN); From 4dffe521a3b1b4139216c63920eec69dec8d158b Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Thu, 13 Oct 2016 23:37:14 +0800 Subject: [PATCH 305/325] api_msg.c: Trivial code cleanup Slightly improve readability by testing apiflags with NETCONN_DONTBLOCK. Also remove an empty else clause. Signed-off-by: Axel Lin --- src/api/api_msg.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/api/api_msg.c b/src/api/api_msg.c index 7d0f24d1..86546c29 100644 --- a/src/api/api_msg.c +++ b/src/api/api_msg.c @@ -1511,9 +1511,8 @@ lwip_netconn_do_writemore(struct netconn *conn WRITE_DELAYED_PARAM) LWIP_ASSERT("conn->write_offset < conn->current_msg->msg.w.len", conn->write_offset < conn->current_msg->msg.w.len); - dontblock = netconn_is_nonblocking(conn) || - (conn->current_msg->msg.w.apiflags & NETCONN_DONTBLOCK); apiflags = conn->current_msg->msg.w.apiflags; + dontblock = netconn_is_nonblocking(conn) || (apiflags & NETCONN_DONTBLOCK); #if LWIP_SO_SNDTIMEO if ((conn->send_timeout != 0) && @@ -1603,7 +1602,6 @@ err_mem: err = out_err; write_finished = 1; conn->current_msg->msg.w.len = 0; - } else { } } else { /* On errors != ERR_MEM, we don't try writing any more but return From 801f26ee0c4fac8bfda52d0a8707ee8ba72efacc Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Sun, 16 Oct 2016 19:07:55 +0200 Subject: [PATCH 306/325] Minor documentation update --- src/core/pbuf.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/core/pbuf.c b/src/core/pbuf.c index 1c45224a..887dc8aa 100644 --- a/src/core/pbuf.c +++ b/src/core/pbuf.c @@ -41,17 +41,22 @@ typedef struct my_custom_pbuf void* dma_descriptor; } my_custom_pbuf_t; +LWIP_MEMPOOL_DECLARE(RX_POOL, 10, sizeof(my_custom_pbuf_t), "Zero-copy RX PBUF pool"); + void my_pbuf_free_custom(void* p) { my_custom_pbuf_t* my_puf = (my_custom_pbuf_t*)p; + + LOCK_INTERRUPTS(); free_rx_dma_descriptor(my_pbuf->dma_descriptor); - my_pbuf_pool_put(my_pbuf); + LWIP_MEMPOOL_FREE(RX_POOL, my_pbuf); + UNLOCK_INTERRUPTS(); } void eth_rx_irq() { dma_descriptor* dma_desc = get_RX_DMA_descriptor_from_ethernet(); - my_custom_pbuf_t* my_pbuf = my_pbuf_pool_get(); + my_custom_pbuf_t* my_pbuf = (my_custom_pbuf_t*)LWIP_MEMPOOL_ALLOC(RX_POOL); my_pbuf->p.custom_free_function = my_pbuf_free_custom; my_pbuf->dma_descriptor = dma_desc; From 67895e7bddd6e7456c1e5c104ea9b85cc8a01cef Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Wed, 19 Oct 2016 08:36:43 +0200 Subject: [PATCH 307/325] Fixup new IPv4 fragmentation code - thanks to Zach Smith --- src/core/ipv4/ip4_frag.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/ipv4/ip4_frag.c b/src/core/ipv4/ip4_frag.c index 9812a085..c1201cda 100644 --- a/src/core/ipv4/ip4_frag.c +++ b/src/core/ipv4/ip4_frag.c @@ -785,7 +785,7 @@ ip4_frag(struct pbuf *p, struct netif *netif, const ip4_addr_t *dest) p = p->next; } } - poff = newpbuflen; + poff += newpbuflen; #endif /* LWIP_NETIF_TX_SINGLE_PBUF */ /* Correct header */ From 20fde0be6ca106027d8cc1ff0fa8d6a69c23c48d Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Wed, 19 Oct 2016 09:54:39 +0800 Subject: [PATCH 308/325] ip4_frag: Use LWIP_MIN instead of open-coded Signed-off-by: Axel Lin --- src/core/ipv4/ip4_frag.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/ipv4/ip4_frag.c b/src/core/ipv4/ip4_frag.c index c1201cda..b6f90945 100644 --- a/src/core/ipv4/ip4_frag.c +++ b/src/core/ipv4/ip4_frag.c @@ -714,7 +714,7 @@ ip4_frag(struct pbuf *p, struct netif *netif, const ip4_addr_t *dest) while (left) { /* Fill this fragment */ - fragsize = (left < nfb * 8) ? left : nfb * 8; + fragsize = LWIP_MIN(left, nfb * 8); #if LWIP_NETIF_TX_SINGLE_PBUF rambuf = pbuf_alloc(PBUF_IP, fragsize, PBUF_RAM); @@ -751,7 +751,7 @@ ip4_frag(struct pbuf *p, struct netif *netif, const ip4_addr_t *dest) while (left_to_copy) { struct pbuf_custom_ref *pcr; u16_t plen = p->len - poff; - newpbuflen = (left_to_copy < plen) ? left_to_copy : plen; + newpbuflen = LWIP_MIN(left_to_copy, plen); /* Is this pbuf already empty? */ if (!newpbuflen) { poff = 0; From 760281207ede6225971ef39ce42f1cc56d1d2af0 Mon Sep 17 00:00:00 2001 From: David van Moolenbroek Date: Thu, 13 Oct 2016 16:30:32 +0000 Subject: [PATCH 309/325] mld6: fix conditional checksumming The mld_group structure no longer has a 'netif' field, as such structures are now linked from the corresponding netif structure. For conditional checksumming, use the calling function's netif reference instead. --- src/core/ipv6/mld6.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/ipv6/mld6.c b/src/core/ipv6/mld6.c index 2ebcff32..0cd0078b 100644 --- a/src/core/ipv6/mld6.c +++ b/src/core/ipv6/mld6.c @@ -564,7 +564,7 @@ mld6_send(struct netif *netif, struct mld_group *group, u8_t type) ip6_addr_set(&(mld_hdr->multicast_address), &(group->group_address)); #if CHECKSUM_GEN_ICMP6 - IF__NETIF_CHECKSUM_ENABLED(group->netif, NETIF_CHECKSUM_GEN_ICMP6) { + IF__NETIF_CHECKSUM_ENABLED(netif, NETIF_CHECKSUM_GEN_ICMP6) { mld_hdr->chksum = ip6_chksum_pseudo(p, IP6_NEXTH_ICMP6, p->len, src_addr, &(group->group_address)); } From e040132d9210b995463651ac1697119aa20609a9 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Fri, 21 Oct 2016 23:12:17 +0800 Subject: [PATCH 310/325] PPP, documentation: Fix example code Fix the example code in status_cb() because dns_getserver() returns const ip_addr_t *. Signed-off-by: Axel Lin --- doc/ppp.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/ppp.txt b/doc/ppp.txt index e40c0126..8b88b3a6 100644 --- a/doc/ppp.txt +++ b/doc/ppp.txt @@ -79,7 +79,7 @@ static void status_cb(ppp_pcb *pcb, int err_code, void *ctx) { switch(err_code) { case PPPERR_NONE: { #if LWIP_DNS - ip_addr_t ns; + const ip_addr_t *ns; #endif /* LWIP_DNS */ printf("status_cb: Connected\n"); #if PPP_IPV4_SUPPORT @@ -88,9 +88,9 @@ static void status_cb(ppp_pcb *pcb, int err_code, void *ctx) { printf(" netmask = %s\n", ipaddr_ntoa(&pppif->netmask)); #if LWIP_DNS ns = dns_getserver(0); - printf(" dns1 = %s\n", ipaddr_ntoa(&ns)); + printf(" dns1 = %s\n", ipaddr_ntoa(ns)); ns = dns_getserver(1); - printf(" dns2 = %s\n", ipaddr_ntoa(&ns)); + printf(" dns2 = %s\n", ipaddr_ntoa(ns)); #endif /* LWIP_DNS */ #endif /* PPP_IPV4_SUPPORT */ #if PPP_IPV6_SUPPORT From 5079e4552c0465695ae838fdc4d44915588db650 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Sun, 23 Oct 2016 10:34:52 +0200 Subject: [PATCH 311/325] Document non-standard functions in sys abstraction layer --- src/core/def.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/core/def.c b/src/core/def.c index f3cf8a48..99f3d62e 100644 --- a/src/core/def.c +++ b/src/core/def.c @@ -15,6 +15,11 @@ * If you \#define them to htons() and htonl(), you should * \#define LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS to prevent lwIP from * defining htonx/ntohx compatibility macros. + + * @defgroup sys_nonstandard Non-standard functions + * @ingroup sys_layer + * lwIP provides default implementations for non-standard functions. + * These can be mapped to OS functions to reduce code footprint if desired. */ /* @@ -87,7 +92,11 @@ lwip_htonl(u32_t n) #endif /* BYTE_ORDER == LITTLE_ENDIAN */ #ifndef lwip_strnstr -/** Like strstr but does not need 'buffer' to be NULL-terminated */ +/** + * @ingroup sys_nonstandard + * lwIP default implementation for strnstr() non-standard function. + * This can be \#defined to strnstr() depending on your platform port. + */ char* lwip_strnstr(const char* buffer, const char* token, size_t n) { @@ -106,6 +115,11 @@ lwip_strnstr(const char* buffer, const char* token, size_t n) #endif #ifndef lwip_stricmp +/** + * @ingroup sys_nonstandard + * lwIP default implementation for stricmp() non-standard function. + * This can be \#defined to stricmp() depending on your platform port. + */ int lwip_stricmp(const char* str1, const char* str2) { @@ -136,6 +150,11 @@ lwip_stricmp(const char* str1, const char* str2) #endif #ifndef lwip_strnicmp +/** + * @ingroup sys_nonstandard + * lwIP default implementation for strnicmp() non-standard function. + * This can be \#defined to strnicmp() depending on your platform port. + */ int lwip_strnicmp(const char* str1, const char* str2, size_t len) { @@ -166,6 +185,11 @@ lwip_strnicmp(const char* str1, const char* str2, size_t len) #endif #ifndef lwip_itoa +/** + * @ingroup sys_nonstandard + * lwIP default implementation for itoa() non-standard function. + * This can be \#defined to itoa() or snprintf(result, bufsize, "%d", number) depending on your platform port. + */ void lwip_itoa(char* result, size_t bufsize, int number) { From 7d8989e3eae0e2c801088edd8727f58e577dbc81 Mon Sep 17 00:00:00 2001 From: Joel Cunningham Date: Wed, 2 Nov 2016 14:10:20 -0500 Subject: [PATCH 312/325] TCP documentation: fix tcp_pbuf_prealloc typo This commit fixes a typo in the tcp_pbuf_prealloc documentation that used "willo" in place of "will" --- src/core/tcp_out.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/tcp_out.c b/src/core/tcp_out.c index a64e420d..3c2bc81a 100644 --- a/src/core/tcp_out.c +++ b/src/core/tcp_out.c @@ -224,7 +224,7 @@ tcp_create_segment(struct tcp_pcb *pcb, struct pbuf *p, u8_t flags, u32_t seqno, * @param length size of the pbuf's payload. * @param max_length maximum usable size of payload+oversize. * @param oversize pointer to a u16_t that will receive the number of usable tail bytes. - * @param pcb The TCP connection that willo enqueue the pbuf. + * @param pcb The TCP connection that will enqueue the pbuf. * @param apiflags API flags given to tcp_write. * @param first_seg true when this pbuf will be used in the first enqueued segment. */ From a82ec4499f02585ae093ba676ee92ba25b2093cf Mon Sep 17 00:00:00 2001 From: Erik Ekman Date: Thu, 3 Nov 2016 12:13:05 +0100 Subject: [PATCH 313/325] memp: Check for null in memp_free When memp_free_pool was split out from memp_free (c838e1ed5b8c42648de2), the check for freeing the null pointer was lost. This resulted in the null value being put back in the list of free objects, causing all subsequent allocations of that type to fail. --- src/core/memp.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/core/memp.c b/src/core/memp.c index 19198eb7..ad8e8fd6 100644 --- a/src/core/memp.c +++ b/src/core/memp.c @@ -471,6 +471,10 @@ memp_free(memp_t type, void *mem) LWIP_ERROR("memp_free: type < MEMP_MAX", (type < MEMP_MAX), return;); + if (mem == NULL) { + return; + } + #if MEMP_OVERFLOW_CHECK >= 2 memp_overflow_check_all(); #endif /* MEMP_OVERFLOW_CHECK >= 2 */ From d4384cfac41c83e67179013b9d59f6ecb84bf03a Mon Sep 17 00:00:00 2001 From: Joel Cunningham Date: Mon, 31 Oct 2016 15:37:13 -0500 Subject: [PATCH 314/325] Sockets: check external FD_SETSIZE against number of sockets This commit adds a compiler check to verify an external FD_SETSIZE has enough space to store the configured number of sockets --- 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 33d3cda2..9d76776f 100644 --- a/src/include/lwip/sockets.h +++ b/src/include/lwip/sockets.h @@ -428,6 +428,8 @@ typedef struct fd_set #elif LWIP_SOCKET_OFFSET #error LWIP_SOCKET_OFFSET does not work with external FD_SET! +#elif FD_SETSIZE < MEMP_NUM_NETCONN +#error "external FD_SETSIZE too small for number of sockets" #endif /* FD_SET */ /** LWIP_TIMEVAL_PRIVATE: if you want to use the struct timeval provided From 1a7ba24d13aaf8f350475b61e544e4217c02d93d Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Fri, 4 Nov 2016 09:01:58 +0800 Subject: [PATCH 315/325] memp: Fix memp_overflow_check_all failure p needs to point to LWIP_MEM_ALIGN(memp_pools[i]->base) otherwise it will cause assertion in overflow checking. Fixes: c838e1ed5b8c ("Implement possibility to declare private memory pools") Signed-off-by: Axel Lin --- src/core/memp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/memp.c b/src/core/memp.c index ad8e8fd6..2e3db28e 100644 --- a/src/core/memp.c +++ b/src/core/memp.c @@ -205,7 +205,7 @@ memp_overflow_check_all(void) SYS_ARCH_PROTECT(old_level); for (i = 0; i < MEMP_MAX; ++i) { - p = (struct memp *)(size_t)(memp_pools[i]->base); + p = (struct memp*)LWIP_MEM_ALIGN(memp_pools[i]->base); for (j = 0; j < memp_pools[i]->num; ++j) { memp_overflow_check_element_overflow(p, memp_pools[i]); memp_overflow_check_element_underflow(p, memp_pools[i]); From 1c9e603299e4141d9be8093aa00e567f990178db Mon Sep 17 00:00:00 2001 From: David van Moolenbroek Date: Fri, 28 Oct 2016 21:28:48 +0000 Subject: [PATCH 316/325] netif: fix reset of IPv6 addresses in netif_add() Previously, only the state of the first IPv6 address would be reset, thus possibly keeping other addresses valid (even though zeroed). --- src/core/netif.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/netif.c b/src/core/netif.c index d9f595e6..fc9e50b0 100644 --- a/src/core/netif.c +++ b/src/core/netif.c @@ -259,7 +259,7 @@ netif_add(struct netif *netif, #if LWIP_IPV6 for (i = 0; i < LWIP_IPV6_NUM_ADDRESSES; i++) { ip_addr_set_zero_ip6(&netif->ip6_addr[i]); - netif->ip6_addr_state[0] = IP6_ADDR_INVALID; + netif->ip6_addr_state[i] = IP6_ADDR_INVALID; } netif->output_ip6 = netif_null_output_ip6; #endif /* LWIP_IPV6 */ From b6f32caaadec82cb8e2987bf4f97a53721ea8160 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Sat, 5 Nov 2016 10:51:06 +0100 Subject: [PATCH 317/325] Fix inet_addr_to_ipaddr_p() macro --- src/include/lwip/inet.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/include/lwip/inet.h b/src/include/lwip/inet.h index 036cd988..17edef33 100644 --- a/src/include/lwip/inet.h +++ b/src/include/lwip/inet.h @@ -134,8 +134,8 @@ extern const struct in6_addr in6addr_any; #define inet_addr_from_ipaddr(target_inaddr, source_ipaddr) ((target_inaddr)->s_addr = ip4_addr_get_u32(source_ipaddr)) #define inet_addr_to_ipaddr(target_ipaddr, source_inaddr) (ip4_addr_set_u32(target_ipaddr, (source_inaddr)->s_addr)) -/* ATTENTION: the next define only works because both s_addr and ip_addr_t are an u32_t effectively! */ -#define inet_addr_to_ipaddr_p(target_ipaddr_p, source_inaddr) ((target_ipaddr_p) = (ip_addr_t*)&((source_inaddr)->s_addr)) +/* ATTENTION: the next define only works because both s_addr and ip4_addr_t are an u32_t effectively! */ +#define inet_addr_to_ipaddr_p(target_ip4addr_p, source_inaddr) ((target_ip4addr_p) = (ip4_addr_t*)&((source_inaddr)->s_addr)) /* directly map this to the lwip internal functions */ #define inet_addr(cp) ipaddr_addr(cp) From 54d76ffd6d16270ec3dee210ad038a053e145f03 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Sat, 5 Nov 2016 15:13:57 +0100 Subject: [PATCH 318/325] Remove superfluous local variable in raw.c --- src/core/raw.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/core/raw.c b/src/core/raw.c index e79ffd14..f692c9c2 100644 --- a/src/core/raw.c +++ b/src/core/raw.c @@ -280,7 +280,6 @@ raw_sendto(struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *ipaddr) const ip_addr_t *src_ip; struct pbuf *q; /* q will be sent down the stack */ s16_t header_size; - const ip_addr_t *dst_ip = ipaddr; if ((pcb == NULL) || (ipaddr == NULL) || !IP_ADDR_PCB_VERSION_MATCH(pcb, ipaddr)) { return ERR_VAL; @@ -321,10 +320,10 @@ raw_sendto(struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *ipaddr) } } - netif = ip_route(&pcb->local_ip, dst_ip); + netif = ip_route(&pcb->local_ip, ipaddr); if (netif == NULL) { LWIP_DEBUGF(RAW_DEBUG | LWIP_DBG_LEVEL_WARNING, ("raw_sendto: No route to ")); - ip_addr_debug_print(RAW_DEBUG | LWIP_DBG_LEVEL_WARNING, dst_ip); + ip_addr_debug_print(RAW_DEBUG | LWIP_DBG_LEVEL_WARNING, ipaddr); /* free any temporary header pbuf allocated by pbuf_header() */ if (q != p) { pbuf_free(q); @@ -349,7 +348,7 @@ raw_sendto(struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *ipaddr) if (ip_addr_isany(&pcb->local_ip)) { /* use outgoing network interface IP address as source address */ - src_ip = ip_netif_get_local_ip(netif, dst_ip); + src_ip = ip_netif_get_local_ip(netif, ipaddr); #if LWIP_IPV6 if (src_ip == NULL) { if (q != p) { @@ -366,15 +365,15 @@ raw_sendto(struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *ipaddr) #if LWIP_IPV6 /* If requested, based on the IPV6_CHECKSUM socket option per RFC3542, compute the checksum and update the checksum in the payload. */ - if (IP_IS_V6(dst_ip) && pcb->chksum_reqd) { - u16_t chksum = ip6_chksum_pseudo(p, pcb->protocol, p->tot_len, ip_2_ip6(src_ip), ip_2_ip6(dst_ip)); + if (IP_IS_V6(ipaddr) && pcb->chksum_reqd) { + u16_t chksum = ip6_chksum_pseudo(p, pcb->protocol, p->tot_len, ip_2_ip6(src_ip), ip_2_ip6(ipaddr)); LWIP_ASSERT("Checksum must fit into first pbuf", p->len >= (pcb->chksum_offset + 2)); SMEMCPY(((u8_t *)p->payload) + pcb->chksum_offset, &chksum, sizeof(u16_t)); } #endif NETIF_SET_HWADDRHINT(netif, &pcb->addr_hint); - err = ip_output_if(q, src_ip, dst_ip, pcb->ttl, pcb->tos, pcb->protocol, netif); + err = ip_output_if(q, src_ip, ipaddr, pcb->ttl, pcb->tos, pcb->protocol, netif); NETIF_SET_HWADDRHINT(netif, NULL); /* did we chain a header earlier? */ From 132dafa3fc014c5e044286a8c6efe5eed2b7b033 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Sat, 5 Nov 2016 15:15:08 +0100 Subject: [PATCH 319/325] Correct macro parentheses in tcpip_priv.h --- src/include/lwip/priv/tcpip_priv.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/include/lwip/priv/tcpip_priv.h b/src/include/lwip/priv/tcpip_priv.h index 5fc80f3f..630efb14 100644 --- a/src/include/lwip/priv/tcpip_priv.h +++ b/src/include/lwip/priv/tcpip_priv.h @@ -69,7 +69,7 @@ struct netif; } while(0) #define API_VAR_FREE(pool, name) memp_free(pool, name) #define API_VAR_FREE_POOL(pool, name) LWIP_MEMPOOL_FREE(pool, name) -#define API_EXPR_REF(expr) &(expr) +#define API_EXPR_REF(expr) (&(expr)) #if LWIP_NETCONN_SEM_PER_THREAD #define API_EXPR_REF_SEM(expr) (expr) #else @@ -87,7 +87,7 @@ struct netif; #define API_VAR_FREE_POOL(pool, name) #define API_EXPR_REF(expr) expr #define API_EXPR_REF_SEM(expr) API_EXPR_REF(expr) -#define API_EXPR_DEREF(expr) *(expr) +#define API_EXPR_DEREF(expr) (*(expr)) #define API_MSG_M_DEF(m) *m #define API_MSG_M_DEF_C(t, m) const t * m #endif /* LWIP_MPU_COMPATIBLE */ From 5d22679c6708d560b45b89844dad6e615d0487a2 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Sat, 5 Nov 2016 16:14:11 +0100 Subject: [PATCH 320/325] Use API function instead of accessing struct members directly --- src/apps/netbiosns/netbiosns.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/apps/netbiosns/netbiosns.c b/src/apps/netbiosns/netbiosns.c index 7e6ac08e..2dfbe659 100644 --- a/src/apps/netbiosns/netbiosns.c +++ b/src/apps/netbiosns/netbiosns.c @@ -328,7 +328,7 @@ netbiosns_init(void) netbiosns_pcb = udp_new_ip_type(IPADDR_TYPE_ANY); if (netbiosns_pcb != NULL) { /* we have to be allowed to send broadcast packets! */ - netbiosns_pcb->so_options |= SOF_BROADCAST; + ip_set_option(netbiosns_pcb, SOF_BROADCAST); udp_bind(netbiosns_pcb, IP_ANY_TYPE, NETBIOS_PORT); udp_recv(netbiosns_pcb, netbiosns_recv, netbiosns_pcb); } From dde55c6c0efcdf3869416c1c2231488e33ca9343 Mon Sep 17 00:00:00 2001 From: Sylvain Rochet Date: Sat, 5 Nov 2016 21:34:23 +0100 Subject: [PATCH 321/325] PPP, IPCP: fix reset state before reconnecting Commit 7df5496e7b revealed a regression introduced in commit 5a71509353 which broke IPCP reset state. ask_for_local was set to 0 if ouraddr initial value is 0, if ask_for_local was false go->ouraddr was cleared in reset callback, commit 5a71509353 breaks it by removing this clearing. This regression was silent because the whole ppp pcb runtime data was cleared before reconnecting until commit 7df5496e7b which removed this giant clearing. Fix it by reintroducing ask_for_local boolean value, with proper initial value following what unused function ip_check_options do. Fixes: 7df5496e7b ("PPP, rework initial/reconnect cleanup") Fixes: 5a71509353 ("PPP, CORE, IPCP: removed useless ask_for_local boolean") --- src/include/netif/ppp/ppp.h | 4 +++- src/netif/ppp/ipcp.c | 7 +------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/include/netif/ppp/ppp.h b/src/include/netif/ppp/ppp.h index 28b2732a..d9ea097e 100644 --- a/src/include/netif/ppp/ppp.h +++ b/src/include/netif/ppp/ppp.h @@ -324,6 +324,7 @@ struct ppp_pcb_s { /* flags */ #if PPP_IPV4_SUPPORT + unsigned int ask_for_local :1; /* request our address from peer */ unsigned int ipcp_is_open :1; /* haven't called np_finished() */ unsigned int ipcp_is_up :1; /* have called ipcp_up() */ unsigned int if4_up :1; /* True when the IPv4 interface is up. */ @@ -475,7 +476,8 @@ void ppp_set_auth(ppp_pcb *pcb, u8_t authtype, const char *user, const char *pas * * Default is unset (0.0.0.0). */ -#define ppp_set_ipcp_ouraddr(ppp, addr) (ppp->ipcp_wantoptions.ouraddr = ip4_addr_get_u32(addr)) +#define ppp_set_ipcp_ouraddr(ppp, addr) do { ppp->ipcp_wantoptions.ouraddr = ip4_addr_get_u32(addr); \ + ppp->ask_for_local = ppp->ipcp_wantoptions.ouraddr != 0; } while(0) #define ppp_set_ipcp_hisaddr(ppp, addr) (ppp->ipcp_wantoptions.hisaddr = ip4_addr_get_u32(addr)) #if LWIP_DNS /* diff --git a/src/netif/ppp/ipcp.c b/src/netif/ppp/ipcp.c index 7d9d6fd8..5d859299 100644 --- a/src/netif/ppp/ipcp.c +++ b/src/netif/ppp/ipcp.c @@ -728,13 +728,8 @@ static void ipcp_resetci(fsm *f) { wo->req_dns1 = wo->req_dns2 = pcb->settings.usepeerdns; /* Request DNS addresses from the peer */ #endif /* LWIP_DNS */ *go = *wo; -#if 0 /* UNUSED */ - /* We don't need ask_for_local, this is only useful for setup which - * can determine the local IP address from the system hostname. - */ - if (!ask_for_local) + if (!pcb->ask_for_local) go->ouraddr = 0; -#endif /* UNUSED */ #if 0 /* UNUSED */ if (ip_choose_hook) { ip_choose_hook(&wo->hisaddr); From b978d17ca0780f1c594405d11c264f8d6a69e7e9 Mon Sep 17 00:00:00 2001 From: Sylvain Rochet Date: Sun, 6 Nov 2016 12:54:26 +0100 Subject: [PATCH 322/325] PPP, IPCP: remove obvious FIXME No-op. This is now unused code and it is pretty self explanatory what int_option do; it checks that passed parameter is an unsigned integer. --- src/netif/ppp/ipcp.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/netif/ppp/ipcp.c b/src/netif/ppp/ipcp.c index 5d859299..29fb188c 100644 --- a/src/netif/ppp/ipcp.c +++ b/src/netif/ppp/ipcp.c @@ -350,11 +350,8 @@ setvjslots(argv) { int value; -/* FIXME: found what int_option() did */ -#if PPP_OPTIONS if (!int_option(*argv, &value)) return 0; -#endif /* PPP_OPTIONS */ if (value < 2 || value > 16) { option_error("vj-max-slots value must be between 2 and 16"); From 1e6c4ac0174cfa24a390a038045b0f631c8d52ba Mon Sep 17 00:00:00 2001 From: Sylvain Rochet Date: Sun, 6 Nov 2016 17:39:59 +0100 Subject: [PATCH 323/325] PPP, IPCP: check that the peer is allowed to use the IP address it wants This is done in the pppd upstream and was disabled because we don't have the allowed addresses list required for the auth_ip_addr function. This is mostly necessary for PPP in server mode to prevent the peer to use the IP address it wants instead of the one we want, which is currently allowed. Rewrite auth_ip_addr in a simple way where we forbid PPP peer to use loopback net, a multicast address or a reserved class address. Added to that we consider that PPP in server mode with peer required to authenticate must provide the peer IP address, reject any IP address wanted by peer different than the one we wanted. This is actually an allowed addresses "list" of one entry that follows what is done in the unused auth_ip_addr function. --- src/netif/ppp/ipcp.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/netif/ppp/ipcp.c b/src/netif/ppp/ipcp.c index 29fb188c..b7c766eb 100644 --- a/src/netif/ppp/ipcp.c +++ b/src/netif/ppp/ipcp.c @@ -1939,11 +1939,29 @@ static void ipcp_up(fsm *f) { } #endif /* LWIP_DNS */ -/* FIXME: check why it fails, just to know */ -#if 0 /* Unused */ /* * Check that the peer is allowed to use the IP address it wants. */ + if (ho->hisaddr != 0) { + u32_t addr = lwip_ntohl(ho->hisaddr); + if ((addr >> IP_CLASSA_NSHIFT) == IP_LOOPBACKNET + || IP_MULTICAST(addr) || IP_BADCLASS(addr) + /* + * For now, consider that PPP in server mode with peer required + * to authenticate must provide the peer IP address, reject any + * IP address wanted by peer different than the one we wanted. + */ +#if PPP_SERVER && PPP_AUTH_SUPPORT + || (pcb->settings.auth_required && wo->hisaddr != ho->hisaddr) +#endif /* PPP_SERVER && PPP_AUTH_SUPPORT */ + ) { + ppp_error("Peer is not authorized to use remote address %I", ho->hisaddr); + ipcp_close(pcb, "Unauthorized remote IP address"); + return; + } + } +#if 0 /* Unused */ + /* Upstream checking code */ if (ho->hisaddr != 0 && !auth_ip_addr(f->unit, ho->hisaddr)) { ppp_error("Peer is not authorized to use remote address %I", ho->hisaddr); ipcp_close(f->unit, "Unauthorized remote IP address"); From c4eb52dcff402ecc0ef543c4d96afad4d7410464 Mon Sep 17 00:00:00 2001 From: Sylvain Rochet Date: Sun, 6 Nov 2016 20:00:31 +0100 Subject: [PATCH 324/325] PPP: set protocol_list[] const This array is a constant list of protocols, save some ram space by adding the const modifier it deserves. --- src/netif/ppp/ppp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/netif/ppp/ppp.c b/src/netif/ppp/ppp.c index 39c3c240..0e37eeb2 100644 --- a/src/netif/ppp/ppp.c +++ b/src/netif/ppp/ppp.c @@ -1447,7 +1447,7 @@ int get_loop_output(void) { struct protocol_list { u_short proto; const char *name; -} protocol_list[] = { +} const protocol_list[] = { { 0x21, "IP" }, { 0x23, "OSI Network Layer" }, { 0x25, "Xerox NS IDP" }, @@ -1582,7 +1582,7 @@ struct protocol_list { * protocol_name - find a name for a PPP protocol. */ const char * protocol_name(int proto) { - struct protocol_list *lp; + const struct protocol_list *lp; for (lp = protocol_list; lp->proto != 0; ++lp) { if (proto == lp->proto) { From d5dd5241e76a38e75f0469ca77376314037b2e7c Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Mon, 24 Oct 2016 17:51:21 +0800 Subject: [PATCH 325/325] dhcp: Use DHCP_MAX_MSG_LEN_MIN_REQUIRED instead of hard-coded value Signed-off-by: Axel Lin --- src/core/ipv4/dhcp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/ipv4/dhcp.c b/src/core/ipv4/dhcp.c index b17fd779..de5fc73b 100644 --- a/src/core/ipv4/dhcp.c +++ b/src/core/ipv4/dhcp.c @@ -1225,7 +1225,7 @@ dhcp_reboot(struct netif *netif) result = dhcp_create_msg(netif, dhcp, DHCP_REQUEST); if (result == ERR_OK) { dhcp_option(dhcp, DHCP_OPTION_MAX_MSG_SIZE, DHCP_OPTION_MAX_MSG_SIZE_LEN); - dhcp_option_short(dhcp, 576); + dhcp_option_short(dhcp, DHCP_MAX_MSG_LEN_MIN_REQUIRED); dhcp_option(dhcp, DHCP_OPTION_REQUESTED_IP, 4); dhcp_option_long(dhcp, lwip_ntohl(ip4_addr_get_u32(&dhcp->offered_ip_addr)));