lwip/src/core/init.c

381 lines
16 KiB
C
Raw Normal View History

/**
* @file
* Modules initialization
*
*/
/*
* 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 <adam@sics.se>
*/
#include "lwip/opt.h"
#include "lwip/init.h"
#include "lwip/stats.h"
#include "lwip/sys.h"
#include "lwip/mem.h"
#include "lwip/memp.h"
#include "lwip/pbuf.h"
#include "lwip/netif.h"
#include "lwip/sockets.h"
#include "lwip/ip.h"
#include "lwip/raw.h"
#include "lwip/udp.h"
#include "lwip/priv/tcp_priv.h"
2007-08-30 16:06:51 +00:00
#include "lwip/igmp.h"
#include "lwip/dns.h"
#include "lwip/timeouts.h"
#include "lwip/etharp.h"
#include "lwip/ip6.h"
#include "lwip/nd6.h"
#include "lwip/mld6.h"
#include "lwip/api.h"
#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
2017-09-17 18:38:38 +00:00
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.
*/
#ifndef BYTE_ORDER
2017-09-17 18:38:38 +00:00
#error "BYTE_ORDER is not defined, you have to define it in your cc.h"
#endif
#if (!IP_SOF_BROADCAST && IP_SOF_BROADCAST_RECV)
2017-09-17 18:38:38 +00:00
#error "If you want to use broadcast filter per pcb on recv operations, you have to define IP_SOF_BROADCAST=1 in your lwipopts.h"
#endif
#if (!LWIP_UDP && LWIP_UDPLITE)
2017-09-17 18:38:38 +00:00
#error "If you want to use UDP Lite, you have to define LWIP_UDP=1 in your lwipopts.h"
#endif
#if (!LWIP_UDP && LWIP_DHCP)
2017-09-17 18:38:38 +00:00
#error "If you want to use DHCP, you have to define LWIP_UDP=1 in your lwipopts.h"
#endif
#if (!LWIP_UDP && !LWIP_RAW && LWIP_MULTICAST_TX_OPTIONS)
2017-09-17 18:38:38 +00:00
#error "If you want to use LWIP_MULTICAST_TX_OPTIONS, you have to define LWIP_UDP=1 and/or LWIP_RAW=1 in your lwipopts.h"
#endif
#if (!LWIP_UDP && LWIP_DNS)
2017-09-17 18:38:38 +00:00
#error "If you want to use DNS, you have to define LWIP_UDP=1 in your lwipopts.h"
#endif
#if !MEMP_MEM_MALLOC /* MEMP_NUM_* checks are disabled when not using the pool allocator */
2007-08-30 16:06:51 +00:00
#if (LWIP_ARP && ARP_QUEUEING && (MEMP_NUM_ARP_QUEUE<=0))
2017-09-17 18:38:38 +00:00
#error "If you want to use ARP Queueing, you have to define MEMP_NUM_ARP_QUEUE>=1 in your lwipopts.h"
2007-08-30 16:06:51 +00:00
#endif
#if (LWIP_RAW && (MEMP_NUM_RAW_PCB<=0))
2017-09-17 18:38:38 +00:00
#error "If you want to use RAW, you have to define MEMP_NUM_RAW_PCB>=1 in your lwipopts.h"
2007-08-30 16:06:51 +00:00
#endif
#if (LWIP_UDP && (MEMP_NUM_UDP_PCB<=0))
2017-09-17 18:38:38 +00:00
#error "If you want to use UDP, you have to define MEMP_NUM_UDP_PCB>=1 in your lwipopts.h"
#endif
#if (LWIP_TCP && (MEMP_NUM_TCP_PCB<=0))
2017-09-17 18:38:38 +00:00
#error "If you want to use TCP, you have to define MEMP_NUM_TCP_PCB>=1 in your lwipopts.h"
#endif
#if (LWIP_IGMP && (MEMP_NUM_IGMP_GROUP<=1))
2017-09-17 18:38:38 +00:00
#error "If you want to use IGMP, you have to define MEMP_NUM_IGMP_GROUP>1 in your lwipopts.h"
#endif
#if (LWIP_IGMP && !LWIP_MULTICAST_TX_OPTIONS)
2017-09-17 18:38:38 +00:00
#error "If you want to use IGMP, you have to define LWIP_MULTICAST_TX_OPTIONS==1 in your lwipopts.h"
#endif
#if (LWIP_IGMP && !LWIP_IPV4)
2017-09-17 18:38:38 +00:00
#error "IGMP needs LWIP_IPV4 enabled in your lwipopts.h"
#endif
#if ((LWIP_NETCONN || LWIP_SOCKET) && (MEMP_NUM_TCPIP_MSG_API<=0))
2017-09-17 18:38:38 +00:00
#error "If you want to use Sequential API, you have to define MEMP_NUM_TCPIP_MSG_API>=1 in your lwipopts.h"
#endif
/* There must be sufficient timeouts, taking into account requirements of the subsystems. */
#if LWIP_TIMERS && (MEMP_NUM_SYS_TIMEOUT < LWIP_NUM_SYS_TIMEOUT_INTERNAL)
2017-09-17 18:38:38 +00:00
#error "MEMP_NUM_SYS_TIMEOUT is too low to accomodate all required timeouts"
#endif
#if (IP_REASSEMBLY && (MEMP_NUM_REASSDATA > IP_REASS_MAX_PBUFS))
2017-09-17 18:38:38 +00:00
#error "MEMP_NUM_REASSDATA > IP_REASS_MAX_PBUFS doesn't make sense since each struct ip_reassdata must hold 2 pbufs at least!"
#endif
#endif /* !MEMP_MEM_MALLOC */
#if LWIP_WND_SCALE
#if (LWIP_TCP && (TCP_WND > 0xffffffff))
2017-09-17 18:38:38 +00:00
#error "If you want to use TCP, TCP_WND must fit in an u32_t, so, you have to reduce it in your lwipopts.h"
#endif
#if (LWIP_TCP && (TCP_RCV_SCALE > 14))
2017-09-17 18:38:38 +00:00
#error "The maximum valid window scale value is 14!"
#endif
#if (LWIP_TCP && (TCP_WND > (0xFFFFU << TCP_RCV_SCALE)))
2017-09-17 18:38:38 +00:00
#error "TCP_WND is bigger than the configured LWIP_WND_SCALE allows!"
#endif
#if (LWIP_TCP && ((TCP_WND >> TCP_RCV_SCALE) == 0))
2017-09-17 18:38:38 +00:00
#error "TCP_WND is too small for the configured LWIP_WND_SCALE (results in zero window)!"
#endif
#else /* LWIP_WND_SCALE */
#if (LWIP_TCP && (TCP_WND > 0xffff))
2017-09-17 18:38:38 +00:00
#error "If you want to use TCP, TCP_WND must fit in an u16_t, so, you have to reduce it in your lwipopts.h (or enable window scaling)"
#endif
#endif /* LWIP_WND_SCALE */
2007-10-07 17:41:21 +00:00
#if (LWIP_TCP && (TCP_SND_QUEUELEN > 0xffff))
2017-09-17 18:38:38 +00:00
#error "If you want to use TCP, TCP_SND_QUEUELEN must fit in an u16_t, so, you have to reduce it in your lwipopts.h"
#endif
#if (LWIP_TCP && (TCP_SND_QUEUELEN < 2))
2017-09-17 18:38:38 +00:00
#error "TCP_SND_QUEUELEN must be at least 2 for no-copy TCP writes to work"
#endif
#if (LWIP_TCP && ((TCP_MAXRTX > 12) || (TCP_SYNMAXRTX > 12)))
2017-09-17 18:38:38 +00:00
#error "If you want to use TCP, TCP_MAXRTX and TCP_SYNMAXRTX must less or equal to 12 (due to tcp_backoff table), so, you have to reduce them in your lwipopts.h"
2007-10-07 17:41:21 +00:00
#endif
#if (LWIP_TCP && TCP_LISTEN_BACKLOG && ((TCP_DEFAULT_LISTEN_BACKLOG < 0) || (TCP_DEFAULT_LISTEN_BACKLOG > 0xff)))
2017-09-17 18:38:38 +00:00
#error "If you want to use TCP backlog, TCP_DEFAULT_LISTEN_BACKLOG must fit into an u8_t"
#endif
#if (LWIP_TCP && LWIP_TCP_SACK_OUT && !TCP_QUEUE_OOSEQ)
#error "To use LWIP_TCP_SACK_OUT, TCP_QUEUE_OOSEQ needs to be enabled"
#endif
#if (LWIP_TCP && LWIP_TCP_SACK_OUT && (LWIP_TCP_MAX_SACK_NUM < 1))
#error "LWIP_TCP_MAX_SACK_NUM must be greater than 0"
#endif
#if (LWIP_NETIF_API && (NO_SYS==1))
2017-09-17 18:38:38 +00:00
#error "If you want to use NETIF API, you have to define NO_SYS=0 in your lwipopts.h"
#endif
#if ((LWIP_SOCKET || LWIP_NETCONN) && (NO_SYS==1))
2017-09-17 18:38:38 +00:00
#error "If you want to use Sequential API, you have to define NO_SYS=0 in your lwipopts.h"
#endif
2014-09-17 19:30:41 +00:00
#if (LWIP_PPP_API && (NO_SYS==1))
2017-09-17 18:38:38 +00:00
#error "If you want to use PPP API, you have to define NO_SYS=0 in your lwipopts.h"
2014-09-17 19:30:41 +00:00
#endif
#if (LWIP_PPP_API && (PPP_SUPPORT==0))
2017-09-17 18:38:38 +00:00
#error "If you want to use PPP API, you have to enable PPP_SUPPORT in your lwipopts.h"
#endif
#if (((!LWIP_DHCP) || (!LWIP_AUTOIP)) && LWIP_DHCP_AUTOIP_COOP)
2017-09-17 18:38:38 +00:00
#error "If you want to use DHCP/AUTOIP cooperation mode, you have to define LWIP_DHCP=1 and LWIP_AUTOIP=1 in your lwipopts.h"
#endif
ACD module added + update and improve DHCP + AUTOIP behavior Squashed commit of the following: commit 2d98d8e2ef1941c3824ffb874f1e529d284667fc Author: Jasper Verschueren <jasper.verschueren@apart-audio.com> Date: Thu Sep 13 16:15:06 2018 +0200 AUTOIP: correct functionality autoip_supplied_address It does not mean that if autoip is bound, it also supplied the netif address. A check is added. commit 2ca0a2183991ef73860c4207d95799b37acc64cc Author: Jasper Verschueren <jasper.verschueren@apart-audio.com> Date: Thu Sep 13 16:06:49 2018 +0200 AUTOIP: keep using the same link local address as much as possible Only calculate a new link local address at start up or when a conflict occured. On link up or down -> keep same address. TODO: in the future a function for persistent storage should be added. commit aa70a693351e4c898aa28d8521308794614838f1 Author: Jasper Verschueren <jasper.verschueren@apart-audio.com> Date: Thu Sep 13 14:43:14 2018 +0200 ACD, AUTOIP & DHCP: make link up & down functions where needed When the link goes down or up the approriate functions should be stopped or started again. To accomodate this, network_changed is adjusted to network_changed_link_up and network_changed_link_down. DHCP does not need to control AUTOIP. AUTOIP can take care of itself. The only thing DHCP needs to do is starting it when discovering is failing. The AUTOIP state variable is removed from DHCP. commit ad469eb006b47f8a8c37f7c0de0216f47a8c19c7 Author: Jasper Verschueren <jasper.verschueren@apart-audio.com> Date: Thu Sep 13 11:25:58 2018 +0200 ACD: add address change listener + passive conflict detection mode In the case their previously was a LL address on a netif that is now configured with a routable address, we want the LL address to be able to keep receiving packets. for as long as the LL address is available on the interface it should do ongoing conflict detection. But we cannot defend when the LL address is not the netif address any more. An address change listener is added to detect when an ACD module needs to go from active ongoing conflict detection to passive. When a conflict is detected autoip is stopped and will not be able to receive packets any more. Because we have a valid routable address on the netif, autoip is not restarted. commit 07c4ec20cea78e2b4a6f5599569abaf075619c62 Author: Jasper Verschueren <jasper.verschueren@apart-audio.com> Date: Tue Sep 11 16:25:37 2018 +0200 ACD: make module reusable within a netif DHCP and AUTOIP both have ACD running simultaniously. The ACD struct is added to the DHCP and AUTOIP structs. In the netif a list of ACD modules is kept to loop over if functions need to perform some action on all ACD modules (for example tmr function). With acd_add a module can be added to the list. ACD_FOREACH loops over the list similar to NETIF_FOREACH. commit ee3b4585b7768f5353dd80190a2929bad45f7ff4 Author: Jasper Verschueren <jasper.verschueren@apart-audio.com> Date: Mon Sep 10 16:36:18 2018 +0200 etharp & acd: add probe and announce functions to etharp. The new probe and announce functions are independent of netif->ip_addr. This means we can keep the LL address working while we start to probe for the newly received routable address. The netif->ip_addr does not need to be any for probing to work with this patch. commit 7d3032bae8f1b8081368a807682388eb642729e0 Author: Jasper Verschueren <jasper.verschueren@apart-audio.com> Date: Mon Sep 3 13:35:51 2018 +0200 autoip -> unused random function removed + small comment update commit be749ba4eb26ddc69233c85d532dc035741275c5 Author: Jasper Verschueren <jasper.verschueren@apart-audio.com> Date: Fri Aug 31 16:37:36 2018 +0200 ACD: update comment in header commit 4491842991c90b3a58fa327f70aa42f04174546b Author: Jasper Verschueren <jasper.verschueren@apart-audio.com> Date: Fri Aug 31 15:44:45 2018 +0200 ACD: subscribe to link down messages to stop the acd process When the link goes down the acd process should be stopped independent of the acd client. Otherwise the acd will keep probing or announcing while their simply is no connection. commit 71f668aa7583354e132c20b3b50ba2c86bf08738 Author: Jasper Verschueren <jasper.verschueren@apart-audio.com> Date: Fri Aug 31 13:59:44 2018 +0200 DHCP coop autoip bug fix: wait after last discovery before starting autoip After the last dhcp discovery we need to give the dhcp server the time to respond. Currently the discovery message is send and autoip is started simultaniously. This is changed. Autoip will now be started after the next discovery timeout. commit 0da16604ec079195533f2591f0d0f04bdf212a72 Author: Jasper Verschueren <jasper.verschueren@apart-audio.com> Date: Fri Aug 31 11:23:31 2018 +0200 ACD: rate limit interval bug solved -> first decline then wait then restart. According the the ACD RFC we need to limit the rate of acquiring and probing addresses after MAX_CONFLICTS. It is important to first decline the address and stop the netif from using the address before the time is started. After this rate limit time, the address acquiring process can be started again. To make this possible we had to change the callback function and the location in the process were the rate limiting is done. commit a89a0601a251acb14abe270116f38c6d25c2d7a9 Author: Jasper Verschueren <jasper.verschueren@apart-audio.com> Date: Thu Aug 30 17:27:10 2018 +0200 DHCP: after a succesful dhcp_reboot, the address should be probed. Reboot means that the connection was gone for some amount of time. This is seen as a new connection for the ACD module so should be the address should be probed before use. commit 853afb448ba35c6e2b35e8238c9c367c599dece7 Author: Jasper Verschueren <jasper.verschueren@apart-audio.com> Date: Thu Aug 30 17:19:12 2018 +0200 DHCP_DOES_ARP_CHECK changed to DHCP_DOES_ACD_CHECK small update in opt.h to add the correct dependencies. commit e28b4766bdef69e76f6170c470c93f5b251c579a Author: Jasper Verschueren <jasper.verschueren@apart-audio.com> Date: Thu Aug 30 17:05:43 2018 +0200 DHCP check code replaced by ACD module. when DHCP_DOES_ARP_CHECK is enabled, the ACD module will take care of address conflict detection. Via a call back function the DHCP state machine will continue and bind to an address if no conflicts are found. dhcp_arp_reply is obsolete because the ACD module replaces its function. commit 52193a0f5d13e8786a4db2fff1f1a8f1367a4eba Author: Jasper Verschueren <jasper.verschueren@apart-audio.com> Date: Mon Aug 27 16:05:22 2018 +0200 Issue 2 + 3 from Comment #5, task #13508 solved Removed C++ comments and // ----... marks as requested. commit 7faaf61275d67ccfb88ea7e26c249428c3088536 Author: Jasper Verschueren <jasper.verschueren@apart-audio.com> Date: Mon Aug 27 15:55:24 2018 +0200 Issue 1 from Comment #5, task #13508 solved Comments added to clarify how arp messages are handled. commit 9348aea22623b705759fd30b873f06a50a104d16 Author: Jasper Verschueren <jasper.verschueren@apart-audio.com> Date: Tue Jul 24 11:45:35 2018 +0200 acd: add comment for callback function commit 49fdd1177c05b74d49fa179564dcaa5e650adbcc Author: Jasper Verschueren <jasper.verschueren@apart-audio.com> Date: Tue Jul 24 11:42:59 2018 +0200 autoip: Add debugging output and complete comments commit 591856b82c029687a657a1b1ccc674522e6f4be0 Author: Jasper Verschueren <jasper.verschueren@apart-audio.com> Date: Tue Jul 24 11:25:18 2018 +0200 Removed autoip from timeouts.c We do not need a timer anymore. All timing is part of acd. commit 3b3272fdd14015cfca0b3b6d149505b1cf0e36b6 Author: Jasper Verschueren <jasper.verschueren@apart-audio.com> Date: Tue Jul 24 11:22:32 2018 +0200 autoip_network_changed -> first bring down the netif and then acd Make it do what it says in the comment commit 77b0ccf96efd22774279c6f9b5bade18c5e42c59 Author: Jasper Verschueren <jasper.verschueren@apart-audio.com> Date: Tue Jul 24 11:21:23 2018 +0200 Simplified the autoIP states + update autoip_start() commit 96e0581d36857f8b70c4b4cce4fb323fd3dd51ab Author: Jasper Verschueren <jasper.verschueren@apart-audio.com> Date: Tue Jul 24 11:10:48 2018 +0200 Deleted unused variables, functions and defines from autoip module The functionality is now embedded in the acd module so can be removed from autoip. commit 9296e2ebb4b51019aaccfc47e8b9f51b265d37cd Author: Jasper Verschueren <jasper.verschueren@apart-audio.com> Date: Tue Jul 24 11:07:34 2018 +0200 Bug fix acd -> rate limiting needs to be after MAX conflicts It was only after MAX conflicts + 1. commit c55e16903c045d0ea84336b50eccbf24d3d097e9 Author: Jasper Verschueren <jasper.verschueren@apart-audio.com> Date: Mon Jul 23 17:52:45 2018 +0200 Small intruduction to module added commit d1498a37293bd9f97f6b938b48e5980ab0a01bd1 Author: Jasper Verschueren <jasper.verschueren@apart-audio.com> Date: Mon Jul 23 17:49:58 2018 +0200 Copyright information added I based the copyright text on the other files. I'm not sure this is how its done. I kept Dominik in their because I copied quite some code from the autoip module. commit 359a845ef5e73061832069f364b370634ee0b071 Author: Jasper Verschueren <jasper.verschueren@apart-audio.com> Date: Mon Jul 23 17:08:44 2018 +0200 Fixing comments in acd.c commit 100d72549d0ef44157143d031848a727f5dfbe69 Author: Jasper Verschueren <jasper.verschueren@apart-audio.com> Date: Mon Jul 23 15:43:40 2018 +0200 Probe wait time and Probe interval time made random via lwip_rand According to the RFC a random amount of time needs to be waited before probing can be started also a random amount of time needs to be waited between the probes. The random time is calculated via the LWIP_RAND function (see lwipopts and sys_arch). commit f7f037c32e9416f8b803c3c7af617b871b55ee35 Author: Jasper Verschueren <jasper.verschueren@apart-audio.com> Date: Tue Jul 17 16:56:48 2018 +0200 autoip will start probing again when the network has changed commit 1f40f6274195f24aa1b05caf82b79285ad189c2a Author: Jasper Verschueren <jasper.verschueren@apart-audio.com> Date: Tue Jul 17 16:55:47 2018 +0200 Duplicate code removed -> already present in autoip_start commit be59431271da862a8ca330dbca638842c87765bc Author: Jasper Verschueren <jasper.verschueren@apart-audio.com> Date: Tue Jul 17 16:52:49 2018 +0200 add rate limiting to acd when too many conflicts are detected. When more then max conflicts are detected during device on time, the rate at which probing for a new address starts is limited. For clarity we combined the conflict counting and the callback into a new function acd_restart. commit 91448455e95edb24c1f418c341b6fb306391f4f1 Author: Jasper Verschueren <jasper.verschueren@apart-audio.com> Date: Tue Jul 17 15:50:01 2018 +0200 ARP packet conflict detection added. If a conflict is detected between the begin until after announce wait, a new address needs to be chosen immediatly. This can occur in two situations: 1) another host already has this ip address 2) another host is also probing for the same address. If a conflict is detected during announcing or during the ongoing conflict detection, we defend our ip address once. If a second conflict occurs during defend interval, we take another ip address. If not we can keep our address and connections. When a conflict occurs and it's decided we need a new address, autoip is simply restarted. To do: test if a acd stop is needed. This will become more important when DHCP is added I believe. commit 65f47ba9444d8b9f767dc908319579323eeb8664 Author: Jasper Verschueren <jasper.verschueren@apart-audio.com> Date: Tue Jul 17 15:33:44 2018 +0200 Update ACD state machine with PROBE_WAIT and and ANNOUNCE_WAIT By adding the ANNOUNCE_WAIT state, we could remove duplicate code that was present in the original autoip state implementation. But because we cannot directly go to ANNOUNCING we needed this extra state during the wait period. It also makes the different states clearer. Their is no need to number the enum because the compiler takes care of this standard numbering. Also a indent issue on the state machine code is solved here. commit 2d9f4414c7b1f2ed35c0b5cea78dabb9c9afee77 Author: Jasper Verschueren <jasper.verschueren@apart-audio.com> Date: Tue Jul 17 15:28:33 2018 +0200 Added an extra check for etharp responses. Their is no need to answer a request that is initiated by ourselves. In my test case, a conflicting request would be seen here as a request needing a reply. Which off course isn't needed at all. The acd module will let the requester know that it is using our ip address. I could not think of a reason not to add this extra check but please check if this doesn't break other functionality. commit f84cc1dba4061219bd1aadb97bd340278db07cd7 Author: Jasper Verschueren <jasper.verschueren@apart-audio.com> Date: Tue Jul 17 15:27:13 2018 +0200 Redirect all incoming ARP messages to the ACD module. The ACD module will scan the packets and react on conflicts. autoip does not need the arp packets any more. commit 9faf266993cc2df0b9434720b59b5922f17d7d33 Author: Jasper Verschueren <jasper.verschueren@apart-audio.com> Date: Tue Jul 17 10:08:39 2018 +0200 Initiate acd from autoip implementation. The state machine in autoip is now replaced by the acd module. commit 40a5a40d911c98e6ee8566c0adce7716f26f20e0 Author: Jasper Verschueren <jasper.verschueren@apart-audio.com> Date: Tue Jul 17 10:05:59 2018 +0200 Add simple acd state machine to timer function. This state machine will be started from acd_start and will go through the probing and the announcing state. At this moment the timings are made fixed for easy debugging. Will be made variable afterwards. commit 0a2629bf1f7942e80ec11bcc3e163ac1a2b9a580 Author: Jasper Verschueren <jasper.verschueren@apart-audio.com> Date: Tue Jul 17 09:44:19 2018 +0200 Disable gratuitous ARP send from netif_issue_report when acd is enabled The acd module needs to be fully under control on what arp messages are send. It wouldn't be a clean solution if we kept this announce as one of the announce messages. So when ACD is enabled, this message will not be send. commit a7b9a4d5039168723c2043677176c5c8fc69f8df Author: Jasper Verschueren <jasper.verschueren@apart-audio.com> Date: Tue Jul 17 09:42:46 2018 +0200 ARP probe and announce functions added. Both use etharp_requests to send out an arp message. commit e2f1ce3fa84e2ce01bc944d8049412e156cd7cc7 Author: Jasper Verschueren <jasper.verschueren@apart-audio.com> Date: Tue Jul 17 09:26:07 2018 +0200 Add conflict callback mechanism to acd module When starting the acd with acd_start, a conflict callback has to be provided. After probing when no conflict is detected, the callback is called with the conflict variable on 0. From the moment a conflict is detected, it will be called set to 1. By not making a fixed link between acd, autoip and dhcp but working with callback functions the user (caller) can easily use it for fixed ip too. This keeps the acd module completely independent from the other application layer protocols. commit 21e7995888d2941601e99873ee129d1ea927e3f7 Author: Jasper Verschueren <jasper.verschueren@apart-audio.com> Date: Mon Jul 16 14:41:52 2018 +0200 acd_stop function added. When calling this function the acd state machine will be put in ACD_STATE_OFF. This will disable the acd functionality until acd_start is called. commit 503037fb462504e46a14ce7486bc763dbc6a8690 Author: Jasper Verschueren <jasper.verschueren@apart-audio.com> Date: Mon Jul 16 14:35:48 2018 +0200 acd_start function added This function will allocate a struct for the acd module if one wasn't added with acd_set_struct. It will then initialize the acd struct and start the probe wait timer (for now fixed). commit e439f6dffc44e93078a2976783bdebfe17304d8c Author: Jasper Verschueren <jasper.verschueren@apart-audio.com> Date: Mon Jul 16 14:22:39 2018 +0200 ACD_DEBUG define added for enabling / disabling debug messages. commit 80d33e1eaf092934ace1045fac096464cd5be5e9 Author: Jasper Verschueren <jasper.verschueren@apart-audio.com> Date: Mon Jul 16 11:39:37 2018 +0200 ACD struct added together with set struct function ACD needs some variables: state, timing, probe counter etc. We added the struct as netif data. For now one ACD module per netif is enough. We found some unclarities about ACD with multiple IP address on one interface. For now, ACD will only be implemented for the IP address that is going to be used / is being used on the netif. commit 2c4cca36744973318c3efe7cbae6384b52dc71a8 Author: Jasper Verschueren <jasper.verschueren@apart-audio.com> Date: Mon Jul 16 11:35:06 2018 +0200 Add acd timer to timeouts.c with interval of 100ms. This timer will be used for time to wait counting etc. Very similar to the auto ip timer. commit e2ed447e00c4df790df21509acb4ab09b5b79e66 Author: Jasper Verschueren <jasper.verschueren@apart-audio.com> Date: Fri Jul 13 16:56:39 2018 +0200 Add ACD protocol definitions commit 445733214460eae18817556439bed979e9b3747c Author: Jasper Verschueren <jasper.verschueren@apart-audio.com> Date: Fri Jul 13 16:07:58 2018 +0200 Add c++ option (to use C code module in c++) commit 63d78bc1f77ac6698c3d663a1c67b40a0c297125 Author: Jasper Verschueren <jasper.verschueren@apart-audio.com> Date: Fri Jul 13 15:57:34 2018 +0200 Added on off option for ACD module commit d5ec4b69eb4175d4dd569bcfc80ae0e192780015 Author: Jasper Verschueren <jasper.verschueren@apart-audio.com> Date: Fri Jul 13 15:09:40 2018 +0200 ACD IPv4 module files added The files for IPv4 ACD or Address Conflict Detection are added to the lwip source.
2018-09-13 15:02:21 +00:00
#if (((!LWIP_DHCP) || (!LWIP_ARP) || (!LWIP_ACD)) && DHCP_DOES_ACD_CHECK)
#error "If you want to use DHCP ACD checking, you have to define LWIP_DHCP=1, LWIP_ARP=1 and LWIP_ACD=1 in your lwipopts.h"
#endif
#if (!LWIP_ARP && LWIP_AUTOIP)
2017-09-17 18:38:38 +00:00
#error "If you want to use AUTOIP, you have to define LWIP_ARP=1 in your lwipopts.h"
#endif
#if (LWIP_TCP && ((LWIP_EVENT_API && LWIP_CALLBACK_API) || (!LWIP_EVENT_API && !LWIP_CALLBACK_API)))
2017-09-17 18:38:38 +00:00
#error "One and exactly one of LWIP_EVENT_API and LWIP_CALLBACK_API has to be enabled in your lwipopts.h"
#endif
#if (LWIP_ALTCP && LWIP_EVENT_API)
#error "The application layered tcp API does not work with LWIP_EVENT_API"
#endif
#if (MEM_LIBC_MALLOC && MEM_USE_POOLS)
2017-09-17 18:38:38 +00:00
#error "MEM_LIBC_MALLOC and MEM_USE_POOLS may not both be simultaneously enabled in your lwipopts.h"
#endif
#if (MEM_USE_POOLS && !MEMP_USE_CUSTOM_POOLS)
2017-09-17 18:38:38 +00:00
#error "MEM_USE_POOLS requires custom pools (MEMP_USE_CUSTOM_POOLS) to be enabled in your lwipopts.h"
#endif
#if (PBUF_POOL_BUFSIZE <= MEM_ALIGNMENT)
2017-09-17 18:38:38 +00:00
#error "PBUF_POOL_BUFSIZE must be greater than MEM_ALIGNMENT or the offset may take the full first pbuf"
#endif
#if (DNS_LOCAL_HOSTLIST && !DNS_LOCAL_HOSTLIST_IS_DYNAMIC && !(defined(DNS_LOCAL_HOSTLIST_INIT)))
2017-09-17 18:38:38 +00:00
#error "you have to define define DNS_LOCAL_HOSTLIST_INIT {{'host1', 0x123}, {'host2', 0x234}} to initialize DNS_LOCAL_HOSTLIST"
#endif
#if PPP_SUPPORT && !PPPOS_SUPPORT && !PPPOE_SUPPORT && !PPPOL2TP_SUPPORT
2017-09-17 18:38:38 +00:00
#error "PPP_SUPPORT needs at least one of PPPOS_SUPPORT, PPPOE_SUPPORT or PPPOL2TP_SUPPORT turned on"
#endif
#if PPP_SUPPORT && !PPP_IPV4_SUPPORT && !PPP_IPV6_SUPPORT
2017-09-17 18:38:38 +00:00
#error "PPP_SUPPORT needs PPP_IPV4_SUPPORT and/or PPP_IPV6_SUPPORT turned on"
#endif
#if PPP_SUPPORT && PPP_IPV4_SUPPORT && !LWIP_IPV4
2017-09-17 18:38:38 +00:00
#error "PPP_IPV4_SUPPORT needs LWIP_IPV4 turned on"
#endif
#if PPP_SUPPORT && PPP_IPV6_SUPPORT && !LWIP_IPV6
2017-09-17 18:38:38 +00:00
#error "PPP_IPV6_SUPPORT needs LWIP_IPV6 turned on"
#endif
#if !LWIP_ETHERNET && (LWIP_ARP || PPPOE_SUPPORT)
2017-09-17 18:38:38 +00:00
#error "LWIP_ETHERNET needs to be turned on for LWIP_ARP or PPPOE_SUPPORT"
#endif
#if LWIP_TCPIP_CORE_LOCKING_INPUT && !LWIP_TCPIP_CORE_LOCKING
2017-09-17 18:38:38 +00:00
#error "When using LWIP_TCPIP_CORE_LOCKING_INPUT, LWIP_TCPIP_CORE_LOCKING must be enabled, too"
#endif
#if LWIP_TCP && LWIP_NETIF_TX_SINGLE_PBUF && !TCP_OVERSIZE
2017-09-17 18:38:38 +00:00
#error "LWIP_NETIF_TX_SINGLE_PBUF needs TCP_OVERSIZE enabled to create single-pbuf TCP packets"
#endif
#if LWIP_NETCONN && LWIP_TCP
#if NETCONN_COPY != TCP_WRITE_FLAG_COPY
2017-09-17 18:38:38 +00:00
#error "NETCONN_COPY != TCP_WRITE_FLAG_COPY"
#endif
#if NETCONN_MORE != TCP_WRITE_FLAG_MORE
2017-09-17 18:38:38 +00:00
#error "NETCONN_MORE != TCP_WRITE_FLAG_MORE"
#endif
#endif /* LWIP_NETCONN && LWIP_TCP */
#if LWIP_SOCKET
#endif /* LWIP_SOCKET */
/* Compile-time checks for deprecated options.
*/
#ifdef MEMP_NUM_TCPIP_MSG
2017-09-17 18:38:38 +00:00
#error "MEMP_NUM_TCPIP_MSG option is deprecated. Remove it from your lwipopts.h."
#endif
#ifdef TCP_REXMIT_DEBUG
2017-09-17 18:38:38 +00:00
#error "TCP_REXMIT_DEBUG option is deprecated. Remove it from your lwipopts.h."
#endif
#ifdef RAW_STATS
2017-09-17 18:38:38 +00:00
#error "RAW_STATS option is deprecated. Remove it from your lwipopts.h."
#endif
#ifdef ETHARP_QUEUE_FIRST
2017-09-17 18:38:38 +00:00
#error "ETHARP_QUEUE_FIRST option is deprecated. Remove it from your lwipopts.h."
#endif
#ifdef ETHARP_ALWAYS_INSERT
2017-09-17 18:38:38 +00:00
#error "ETHARP_ALWAYS_INSERT option is deprecated. Remove it from your lwipopts.h."
#endif
#if !NO_SYS && LWIP_TCPIP_CORE_LOCKING && LWIP_COMPAT_MUTEX && !defined(LWIP_COMPAT_MUTEX_ALLOWED)
2017-09-17 18:38:38 +00:00
#error "LWIP_COMPAT_MUTEX cannot prevent priority inversion. It is recommended to implement priority-aware mutexes. (Define LWIP_COMPAT_MUTEX_ALLOWED to disable this error.)"
#endif
#ifndef LWIP_DISABLE_TCP_SANITY_CHECKS
#define LWIP_DISABLE_TCP_SANITY_CHECKS 0
#endif
#ifndef LWIP_DISABLE_MEMP_SANITY_CHECKS
#define LWIP_DISABLE_MEMP_SANITY_CHECKS 0
#endif
/* MEMP sanity checks */
#if MEMP_MEM_MALLOC
#if !LWIP_DISABLE_MEMP_SANITY_CHECKS
#if LWIP_NETCONN || LWIP_SOCKET
#if !MEMP_NUM_NETCONN && LWIP_SOCKET
#error "lwip_sanity_check: WARNING: MEMP_NUM_NETCONN cannot be 0 when using sockets!"
#endif
#else /* MEMP_MEM_MALLOC */
#if MEMP_NUM_NETCONN > (MEMP_NUM_TCP_PCB+MEMP_NUM_TCP_PCB_LISTEN+MEMP_NUM_UDP_PCB+MEMP_NUM_RAW_PCB)
#error "lwip_sanity_check: WARNING: MEMP_NUM_NETCONN should be less than the sum of MEMP_NUM_{TCP,RAW,UDP}_PCB+MEMP_NUM_TCP_PCB_LISTEN. If you know what you are doing, define LWIP_DISABLE_MEMP_SANITY_CHECKS to 1 to disable this error."
#endif
#endif /* LWIP_NETCONN || LWIP_SOCKET */
#endif /* !LWIP_DISABLE_MEMP_SANITY_CHECKS */
#if MEM_USE_POOLS
#error "MEMP_MEM_MALLOC and MEM_USE_POOLS cannot be enabled at the same time"
#endif
#ifdef LWIP_HOOK_MEMP_AVAILABLE
#error "LWIP_HOOK_MEMP_AVAILABLE doesn't make sense with MEMP_MEM_MALLOC"
#endif
#endif /* MEMP_MEM_MALLOC */
/* TCP sanity checks */
#if !LWIP_DISABLE_TCP_SANITY_CHECKS
#if LWIP_TCP
#if !MEMP_MEM_MALLOC && (MEMP_NUM_TCP_SEG < TCP_SND_QUEUELEN)
2017-09-17 18:38:38 +00:00
#error "lwip_sanity_check: WARNING: MEMP_NUM_TCP_SEG should be at least as big as TCP_SND_QUEUELEN. If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error."
#endif
#if TCP_SND_BUF < (2 * TCP_MSS)
2017-09-17 18:38:38 +00:00
#error "lwip_sanity_check: WARNING: TCP_SND_BUF must be at least as much as (2 * TCP_MSS) for things to work smoothly. If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error."
#endif
#if TCP_SND_QUEUELEN < (2 * (TCP_SND_BUF / TCP_MSS))
2017-09-17 18:38:38 +00:00
#error "lwip_sanity_check: WARNING: TCP_SND_QUEUELEN must be at least as much as (2 * TCP_SND_BUF/TCP_MSS) for things to work. If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error."
#endif
#if TCP_SNDLOWAT >= TCP_SND_BUF
2017-09-17 18:38:38 +00:00
#error "lwip_sanity_check: WARNING: TCP_SNDLOWAT must be less than TCP_SND_BUF. If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error."
#endif
#if TCP_SNDLOWAT >= (0xFFFF - (4 * TCP_MSS))
2017-09-17 18:38:38 +00:00
#error "lwip_sanity_check: WARNING: TCP_SNDLOWAT must at least be 4*MSS below u16_t overflow!"
#endif
#if TCP_SNDQUEUELOWAT >= TCP_SND_QUEUELEN
2017-09-17 18:38:38 +00:00
#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_SIZE && (PBUF_POOL_BUFSIZE <= (PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN + PBUF_IP_HLEN + PBUF_TRANSPORT_HLEN))
2017-09-17 18:38:38 +00:00
#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 && PBUF_POOL_SIZE && (TCP_WND > (PBUF_POOL_SIZE * (PBUF_POOL_BUFSIZE - (PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN + PBUF_IP_HLEN + PBUF_TRANSPORT_HLEN))))
2017-09-17 18:38:38 +00:00
#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
2017-09-17 18:38:38 +00:00
#error "lwip_sanity_check: WARNING: TCP_WND is smaller than MSS. If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error."
#endif
#endif /* LWIP_TCP */
#endif /* !LWIP_DISABLE_TCP_SANITY_CHECKS */
/**
2016-07-27 11:03:36 +00:00
* @ingroup lwip_nosys
* Initialize all modules.
* Use this in NO_SYS mode. Use tcpip_init() otherwise.
*/
void
lwip_init(void)
{
#ifndef LWIP_SKIP_CONST_CHECK
int a = 0;
LWIP_UNUSED_ARG(a);
2017-09-17 18:38:38 +00:00
LWIP_ASSERT("LWIP_CONST_CAST not implemented correctly. Check your lwIP port.", LWIP_CONST_CAST(void *, &a) == &a);
#endif
#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
sys_init();
#endif /* !NO_SYS */
mem_init();
memp_init();
pbuf_init();
netif_init();
#if LWIP_IPV4
ip_init();
#if LWIP_ARP
etharp_init();
#endif /* LWIP_ARP */
#endif /* LWIP_IPV4 */
#if LWIP_RAW
raw_init();
#endif /* LWIP_RAW */
#if LWIP_UDP
udp_init();
#endif /* LWIP_UDP */
#if LWIP_TCP
tcp_init();
#endif /* LWIP_TCP */
#if LWIP_IGMP
igmp_init();
#endif /* LWIP_IGMP */
#if LWIP_DNS
dns_init();
#endif /* LWIP_DNS */
#if PPP_SUPPORT
ppp_init();
#endif
2017-09-17 18:38:38 +00:00
#if LWIP_TIMERS
sys_timeouts_init();
#endif /* LWIP_TIMERS */
}