Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
lwip_autoip.c
00001 /** 00002 * @file 00003 * AutoIP Automatic LinkLocal IP Configuration 00004 * 00005 * This is a AutoIP implementation for the lwIP TCP/IP stack. It aims to conform 00006 * with RFC 3927. 00007 * 00008 * @defgroup autoip AUTOIP 00009 * @ingroup ip4 00010 * AUTOIP related functions 00011 * USAGE: 00012 * 00013 * define @ref LWIP_AUTOIP 1 in your lwipopts.h 00014 * Options: 00015 * AUTOIP_TMR_INTERVAL msecs, 00016 * I recommend a value of 100. The value must divide 1000 with a remainder almost 0. 00017 * Possible values are 1000, 500, 333, 250, 200, 166, 142, 125, 111, 100 .... 00018 * 00019 * Without DHCP: 00020 * - Call autoip_start() after netif_add(). 00021 * 00022 * With DHCP: 00023 * - define @ref LWIP_DHCP_AUTOIP_COOP 1 in your lwipopts.h. 00024 * - Configure your DHCP Client. 00025 * 00026 * @see netifapi_autoip 00027 */ 00028 00029 /* 00030 * 00031 * Copyright (c) 2007 Dominik Spies <kontakt@dspies.de> 00032 * All rights reserved. 00033 * 00034 * Redistribution and use in source and binary forms, with or without modification, 00035 * are permitted provided that the following conditions are met: 00036 * 00037 * 1. Redistributions of source code must retain the above copyright notice, 00038 * this list of conditions and the following disclaimer. 00039 * 2. Redistributions in binary form must reproduce the above copyright notice, 00040 * this list of conditions and the following disclaimer in the documentation 00041 * and/or other materials provided with the distribution. 00042 * 3. The name of the author may not be used to endorse or promote products 00043 * derived from this software without specific prior written permission. 00044 * 00045 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 00046 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00047 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 00048 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00049 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 00050 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00051 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00052 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 00053 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 00054 * OF SUCH DAMAGE. 00055 * 00056 * Author: Dominik Spies <kontakt@dspies.de> 00057 */ 00058 00059 #include "lwip/opt.h" 00060 00061 #if LWIP_IPV4 && LWIP_AUTOIP /* don't build if not configured for use in lwipopts.h */ 00062 00063 #include "lwip/mem.h" 00064 /* #include "lwip/udp.h" */ 00065 #include "lwip/ip_addr.h" 00066 #include "lwip/netif.h" 00067 #include "lwip/autoip.h" 00068 #include "lwip/etharp.h" 00069 #include "lwip/prot/autoip.h" 00070 00071 #include <string.h> 00072 00073 /** Pseudo random macro based on netif informations. 00074 * You could use "rand()" from the C Library if you define LWIP_AUTOIP_RAND in lwipopts.h */ 00075 #ifndef LWIP_AUTOIP_RAND 00076 #define LWIP_AUTOIP_RAND(netif) ( (((u32_t)((netif->hwaddr[5]) & 0xff) << 24) | \ 00077 ((u32_t)((netif->hwaddr[3]) & 0xff) << 16) | \ 00078 ((u32_t)((netif->hwaddr[2]) & 0xff) << 8) | \ 00079 ((u32_t)((netif->hwaddr[4]) & 0xff))) + \ 00080 (netif_autoip_data(netif)? netif_autoip_data(netif)->tried_llipaddr : 0)) 00081 #endif /* LWIP_AUTOIP_RAND */ 00082 00083 /** 00084 * Macro that generates the initial IP address to be tried by AUTOIP. 00085 * If you want to override this, define it to something else in lwipopts.h. 00086 */ 00087 #ifndef LWIP_AUTOIP_CREATE_SEED_ADDR 00088 #define LWIP_AUTOIP_CREATE_SEED_ADDR(netif) \ 00089 lwip_htonl(AUTOIP_RANGE_START + ((u32_t)(((u8_t)(netif->hwaddr[4])) | \ 00090 ((u32_t)((u8_t)(netif->hwaddr[5]))) << 8))) 00091 #endif /* LWIP_AUTOIP_CREATE_SEED_ADDR */ 00092 00093 /* static functions */ 00094 static err_t autoip_arp_announce(struct netif *netif); 00095 static void autoip_start_probing(struct netif *netif); 00096 00097 /* static variables */ 00098 static u8_t is_autoip_allocated = 0; /* Set when 'struct autoip' is allocated dynamically and assigned to 'netif' */ 00099 00100 /** 00101 * @ingroup autoip 00102 * Set a statically allocated struct autoip to work with. 00103 * Using this prevents autoip_start to allocate it using mem_malloc. 00104 * 00105 * @param netif the netif for which to set the struct autoip 00106 * @param autoip (uninitialised) autoip struct allocated by the application 00107 */ 00108 void 00109 autoip_set_struct(struct netif *netif, struct autoip *autoip) 00110 { 00111 LWIP_ASSERT_CORE_LOCKED(); 00112 LWIP_ASSERT("netif != NULL", netif != NULL); 00113 LWIP_ASSERT("autoip != NULL", autoip != NULL); 00114 LWIP_ASSERT("netif already has a struct autoip set", 00115 netif_autoip_data(netif) == NULL); 00116 00117 /* clear data structure */ 00118 memset(autoip, 0, sizeof(struct autoip)); 00119 /* autoip->state = AUTOIP_STATE_OFF; */ 00120 netif_set_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP, autoip); 00121 } 00122 00123 /** Restart AutoIP client and check the next address (conflict detected) 00124 * 00125 * @param netif The netif under AutoIP control 00126 */ 00127 static void 00128 autoip_restart(struct netif *netif) 00129 { 00130 struct autoip *autoip = netif_autoip_data(netif); 00131 autoip->tried_llipaddr++; 00132 autoip_start(netif); 00133 } 00134 00135 /** 00136 * Handle a IP address conflict after an ARP conflict detection 00137 */ 00138 static void 00139 autoip_handle_arp_conflict(struct netif *netif) 00140 { 00141 struct autoip *autoip = netif_autoip_data(netif); 00142 00143 /* RFC3927, 2.5 "Conflict Detection and Defense" allows two options where 00144 a) means retreat on the first conflict and 00145 b) allows to keep an already configured address when having only one 00146 conflict in 10 seconds 00147 We use option b) since it helps to improve the chance that one of the two 00148 conflicting hosts may be able to retain its address. */ 00149 00150 if (autoip->lastconflict > 0) { 00151 /* retreat, there was a conflicting ARP in the last DEFEND_INTERVAL seconds */ 00152 LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, 00153 ("autoip_handle_arp_conflict(): we are defending, but in DEFEND_INTERVAL, retreating\n")); 00154 00155 /* Active TCP sessions are aborted when removing the ip addresss */ 00156 autoip_restart(netif); 00157 } else { 00158 LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, 00159 ("autoip_handle_arp_conflict(): we are defend, send ARP Announce\n")); 00160 autoip_arp_announce(netif); 00161 autoip->lastconflict = DEFEND_INTERVAL * AUTOIP_TICKS_PER_SECOND; 00162 } 00163 } 00164 00165 /** 00166 * Create an IP-Address out of range 169.254.1.0 to 169.254.254.255 00167 * 00168 * @param netif network interface on which create the IP-Address 00169 * @param ipaddr ip address to initialize 00170 */ 00171 static void 00172 autoip_create_addr(struct netif *netif, ip4_addr_t *ipaddr) 00173 { 00174 struct autoip *autoip = netif_autoip_data(netif); 00175 00176 /* Here we create an IP-Address out of range 169.254.1.0 to 169.254.254.255 00177 * compliant to RFC 3927 Section 2.1 00178 * We have 254 * 256 possibilities */ 00179 00180 u32_t addr = lwip_ntohl(LWIP_AUTOIP_CREATE_SEED_ADDR(netif)); 00181 addr += autoip->tried_llipaddr; 00182 addr = AUTOIP_NET | (addr & 0xffff); 00183 /* Now, 169.254.0.0 <= addr <= 169.254.255.255 */ 00184 00185 if (addr < AUTOIP_RANGE_START) { 00186 addr += AUTOIP_RANGE_END - AUTOIP_RANGE_START + 1; 00187 } 00188 if (addr > AUTOIP_RANGE_END) { 00189 addr -= AUTOIP_RANGE_END - AUTOIP_RANGE_START + 1; 00190 } 00191 LWIP_ASSERT("AUTOIP address not in range", (addr >= AUTOIP_RANGE_START) && 00192 (addr <= AUTOIP_RANGE_END)); 00193 ip4_addr_set_u32(ipaddr, lwip_htonl(addr)); 00194 00195 LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, 00196 ("autoip_create_addr(): tried_llipaddr=%"U16_F", %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n", 00197 (u16_t)(autoip->tried_llipaddr), ip4_addr1_16(ipaddr), ip4_addr2_16(ipaddr), 00198 ip4_addr3_16(ipaddr), ip4_addr4_16(ipaddr))); 00199 } 00200 00201 /** 00202 * Sends an ARP probe from a network interface 00203 * 00204 * @param netif network interface used to send the probe 00205 */ 00206 static err_t 00207 autoip_arp_probe(struct netif *netif) 00208 { 00209 struct autoip *autoip = netif_autoip_data(netif); 00210 /* this works because netif->ip_addr is ANY */ 00211 return etharp_request(netif, &autoip->llipaddr); 00212 } 00213 00214 /** 00215 * Sends an ARP announce from a network interface 00216 * 00217 * @param netif network interface used to send the announce 00218 */ 00219 static err_t 00220 autoip_arp_announce(struct netif *netif) 00221 { 00222 return etharp_gratuitous(netif); 00223 } 00224 00225 /** 00226 * Configure interface for use with current LL IP-Address 00227 * 00228 * @param netif network interface to configure with current LL IP-Address 00229 */ 00230 static err_t 00231 autoip_bind(struct netif *netif) 00232 { 00233 struct autoip *autoip = netif_autoip_data(netif); 00234 ip4_addr_t sn_mask, gw_addr; 00235 00236 LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE, 00237 ("autoip_bind(netif=%p) %c%c%"U16_F" %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n", 00238 (void *)netif, netif->name[0], netif->name[1], (u16_t)netif->num, 00239 ip4_addr1_16(&autoip->llipaddr), ip4_addr2_16(&autoip->llipaddr), 00240 ip4_addr3_16(&autoip->llipaddr), ip4_addr4_16(&autoip->llipaddr))); 00241 00242 IP4_ADDR(&sn_mask, 255, 255, 0, 0); 00243 IP4_ADDR(&gw_addr, 0, 0, 0, 0); 00244 00245 netif_set_addr(netif, &autoip->llipaddr, &sn_mask, &gw_addr); 00246 /* interface is used by routing now that an address is set */ 00247 00248 return ERR_OK; 00249 } 00250 00251 /** 00252 * @ingroup autoip 00253 * Start AutoIP client 00254 * 00255 * @param netif network interface on which start the AutoIP client 00256 */ 00257 err_t 00258 autoip_start(struct netif *netif) 00259 { 00260 struct autoip *autoip = netif_autoip_data(netif); 00261 err_t result = ERR_OK; 00262 00263 LWIP_ASSERT_CORE_LOCKED(); 00264 LWIP_ERROR("netif is not up, old style port?", netif_is_up(netif), return ERR_ARG;); 00265 00266 /* Set IP-Address, Netmask and Gateway to 0 to make sure that 00267 * ARP Packets are formed correctly 00268 */ 00269 netif_set_addr(netif, IP4_ADDR_ANY4, IP4_ADDR_ANY4, IP4_ADDR_ANY4); 00270 00271 LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, 00272 ("autoip_start(netif=%p) %c%c%"U16_F"\n", (void *)netif, netif->name[0], 00273 netif->name[1], (u16_t)netif->num)); 00274 if (autoip == NULL) { 00275 /* no AutoIP client attached yet? */ 00276 LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE, 00277 ("autoip_start(): starting new AUTOIP client\n")); 00278 autoip = (struct autoip *)mem_calloc(1, sizeof(struct autoip)); 00279 if (autoip == NULL) { 00280 LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE, 00281 ("autoip_start(): could not allocate autoip\n")); 00282 return ERR_MEM; 00283 } 00284 is_autoip_allocated = 1; 00285 /* store this AutoIP client in the netif */ 00286 netif_set_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP, autoip); 00287 LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE, ("autoip_start(): allocated autoip")); 00288 } else { 00289 autoip->state = AUTOIP_STATE_OFF; 00290 autoip->ttw = 0; 00291 autoip->sent_num = 0; 00292 ip4_addr_set_zero(&autoip->llipaddr); 00293 autoip->lastconflict = 0; 00294 } 00295 00296 autoip_create_addr(netif, &(autoip->llipaddr)); 00297 autoip_start_probing(netif); 00298 00299 return result; 00300 } 00301 00302 static void 00303 autoip_start_probing(struct netif *netif) 00304 { 00305 struct autoip *autoip = netif_autoip_data(netif); 00306 00307 autoip->state = AUTOIP_STATE_PROBING; 00308 autoip->sent_num = 0; 00309 LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, 00310 ("autoip_start_probing(): changing state to PROBING: %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n", 00311 ip4_addr1_16(&autoip->llipaddr), ip4_addr2_16(&autoip->llipaddr), 00312 ip4_addr3_16(&autoip->llipaddr), ip4_addr4_16(&autoip->llipaddr))); 00313 00314 /* time to wait to first probe, this is randomly 00315 * chosen out of 0 to PROBE_WAIT seconds. 00316 * compliant to RFC 3927 Section 2.2.1 00317 */ 00318 autoip->ttw = (u16_t)(LWIP_AUTOIP_RAND(netif) % (PROBE_WAIT * AUTOIP_TICKS_PER_SECOND)); 00319 00320 /* 00321 * if we tried more then MAX_CONFLICTS we must limit our rate for 00322 * acquiring and probing address 00323 * compliant to RFC 3927 Section 2.2.1 00324 */ 00325 if (autoip->tried_llipaddr >= MAX_CONFLICTS) { 00326 autoip->ttw = RATE_LIMIT_INTERVAL * AUTOIP_TICKS_PER_SECOND; 00327 } 00328 } 00329 00330 /** 00331 * Handle a possible change in the network configuration. 00332 * 00333 * If there is an AutoIP address configured, take the interface down 00334 * and begin probing with the same address. 00335 */ 00336 void 00337 autoip_network_changed(struct netif *netif) 00338 { 00339 struct autoip *autoip = netif_autoip_data(netif); 00340 00341 if (autoip && (autoip->state != AUTOIP_STATE_OFF)) { 00342 autoip_start_probing(netif); 00343 } 00344 } 00345 00346 /** 00347 * @ingroup autoip 00348 * Stop AutoIP client 00349 * 00350 * @param netif network interface on which stop the AutoIP client 00351 */ 00352 err_t 00353 autoip_stop(struct netif *netif) 00354 { 00355 struct autoip *autoip = netif_autoip_data(netif); 00356 00357 LWIP_ASSERT_CORE_LOCKED(); 00358 if (autoip != NULL) { 00359 autoip->state = AUTOIP_STATE_OFF; 00360 /* If autoip is dynamically allocated in start, free autoip structure and reset autoip index in netif */ 00361 if (is_autoip_allocated) { 00362 /* Reset the auto IP index and then free autoip structure */ 00363 netif_set_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP, NULL); 00364 mem_free(autoip); 00365 autoip = NULL; 00366 is_autoip_allocated = 0; 00367 } else { 00368 autoip->tried_llipaddr = 0; 00369 } 00370 if (ip4_addr_islinklocal(netif_ip4_addr(netif))) { 00371 netif_set_addr(netif, IP4_ADDR_ANY4, IP4_ADDR_ANY4, IP4_ADDR_ANY4); 00372 } 00373 } 00374 return ERR_OK; 00375 } 00376 00377 /** 00378 * Has to be called in loop every AUTOIP_TMR_INTERVAL milliseconds 00379 */ 00380 void 00381 autoip_tmr(void) 00382 { 00383 struct netif *netif; 00384 /* loop through netif's */ 00385 NETIF_FOREACH(netif) { 00386 struct autoip *autoip = netif_autoip_data(netif); 00387 /* only act on AutoIP configured interfaces */ 00388 if (autoip != NULL) { 00389 if (autoip->lastconflict > 0) { 00390 autoip->lastconflict--; 00391 } 00392 00393 LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE, 00394 ("autoip_tmr() AutoIP-State: %"U16_F", ttw=%"U16_F"\n", 00395 (u16_t)(autoip->state), autoip->ttw)); 00396 00397 if (autoip->ttw > 0) { 00398 autoip->ttw--; 00399 } 00400 00401 switch (autoip->state) { 00402 case AUTOIP_STATE_PROBING: 00403 if (autoip->ttw == 0) { 00404 if (autoip->sent_num >= PROBE_NUM) { 00405 /* Switch to ANNOUNCING: now we can bind to an IP address and use it */ 00406 autoip->state = AUTOIP_STATE_ANNOUNCING; 00407 autoip_bind(netif); 00408 /* autoip_bind() calls netif_set_addr(): this triggers a gratuitous ARP 00409 which counts as an announcement */ 00410 autoip->sent_num = 1; 00411 autoip->ttw = ANNOUNCE_WAIT * AUTOIP_TICKS_PER_SECOND; 00412 LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, 00413 ("autoip_tmr(): changing state to ANNOUNCING: %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n", 00414 ip4_addr1_16(&autoip->llipaddr), ip4_addr2_16(&autoip->llipaddr), 00415 ip4_addr3_16(&autoip->llipaddr), ip4_addr4_16(&autoip->llipaddr))); 00416 } else { 00417 autoip_arp_probe(netif); 00418 LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE, ("autoip_tmr() PROBING Sent Probe\n")); 00419 autoip->sent_num++; 00420 if (autoip->sent_num == PROBE_NUM) { 00421 /* calculate time to wait to for announce */ 00422 autoip->ttw = ANNOUNCE_WAIT * AUTOIP_TICKS_PER_SECOND; 00423 } else { 00424 /* calculate time to wait to next probe */ 00425 autoip->ttw = (u16_t)((LWIP_AUTOIP_RAND(netif) % 00426 ((PROBE_MAX - PROBE_MIN) * AUTOIP_TICKS_PER_SECOND) ) + 00427 PROBE_MIN * AUTOIP_TICKS_PER_SECOND); 00428 } 00429 } 00430 } 00431 break; 00432 00433 case AUTOIP_STATE_ANNOUNCING: 00434 if (autoip->ttw == 0) { 00435 autoip_arp_announce(netif); 00436 LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE, ("autoip_tmr() ANNOUNCING Sent Announce\n")); 00437 autoip->ttw = ANNOUNCE_INTERVAL * AUTOIP_TICKS_PER_SECOND; 00438 autoip->sent_num++; 00439 00440 if (autoip->sent_num >= ANNOUNCE_NUM) { 00441 autoip->state = AUTOIP_STATE_BOUND; 00442 autoip->sent_num = 0; 00443 autoip->ttw = 0; 00444 LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, 00445 ("autoip_tmr(): changing state to BOUND: %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n", 00446 ip4_addr1_16(&autoip->llipaddr), ip4_addr2_16(&autoip->llipaddr), 00447 ip4_addr3_16(&autoip->llipaddr), ip4_addr4_16(&autoip->llipaddr))); 00448 } 00449 } 00450 break; 00451 00452 default: 00453 /* nothing to do in other states */ 00454 break; 00455 } 00456 } 00457 } 00458 } 00459 00460 /** 00461 * Handles every incoming ARP Packet, called by etharp_input(). 00462 * 00463 * @param netif network interface to use for autoip processing 00464 * @param hdr Incoming ARP packet 00465 */ 00466 void 00467 autoip_arp_reply(struct netif *netif, struct etharp_hdr *hdr) 00468 { 00469 struct autoip *autoip = netif_autoip_data(netif); 00470 00471 LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE, ("autoip_arp_reply()\n")); 00472 if ((autoip != NULL) && (autoip->state != AUTOIP_STATE_OFF)) { 00473 /* when ip.src == llipaddr && hw.src != netif->hwaddr 00474 * 00475 * when probing ip.dst == llipaddr && hw.src != netif->hwaddr 00476 * we have a conflict and must solve it 00477 */ 00478 ip4_addr_t sipaddr, dipaddr; 00479 struct eth_addr netifaddr; 00480 SMEMCPY(netifaddr.addr, netif->hwaddr, ETH_HWADDR_LEN); 00481 00482 /* Copy struct ip4_addr_wordaligned to aligned ip4_addr, to support compilers without 00483 * structure packing (not using structure copy which breaks strict-aliasing rules). 00484 */ 00485 IPADDR_WORDALIGNED_COPY_TO_IP4_ADDR_T(&sipaddr, &hdr->sipaddr); 00486 IPADDR_WORDALIGNED_COPY_TO_IP4_ADDR_T(&dipaddr, &hdr->dipaddr); 00487 00488 if (autoip->state == AUTOIP_STATE_PROBING) { 00489 /* RFC 3927 Section 2.2.1: 00490 * from beginning to after ANNOUNCE_WAIT 00491 * seconds we have a conflict if 00492 * ip.src == llipaddr OR 00493 * ip.dst == llipaddr && hw.src != own hwaddr 00494 */ 00495 if ((ip4_addr_cmp(&sipaddr, &autoip->llipaddr)) || 00496 (ip4_addr_isany_val(sipaddr) && 00497 ip4_addr_cmp(&dipaddr, &autoip->llipaddr) && 00498 !eth_addr_cmp(&netifaddr, &hdr->shwaddr))) { 00499 LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE | LWIP_DBG_LEVEL_WARNING, 00500 ("autoip_arp_reply(): Probe Conflict detected\n")); 00501 autoip_restart(netif); 00502 } 00503 } else { 00504 /* RFC 3927 Section 2.5: 00505 * in any state we have a conflict if 00506 * ip.src == llipaddr && hw.src != own hwaddr 00507 */ 00508 if (ip4_addr_cmp(&sipaddr, &autoip->llipaddr) && 00509 !eth_addr_cmp(&netifaddr, &hdr->shwaddr)) { 00510 LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE | LWIP_DBG_LEVEL_WARNING, 00511 ("autoip_arp_reply(): Conflicting ARP-Packet detected\n")); 00512 autoip_handle_arp_conflict(netif); 00513 } 00514 } 00515 } 00516 } 00517 00518 /** check if AutoIP supplied netif->ip_addr 00519 * 00520 * @param netif the netif to check 00521 * @return 1 if AutoIP supplied netif->ip_addr (state BOUND or ANNOUNCING), 00522 * 0 otherwise 00523 */ 00524 u8_t 00525 autoip_supplied_address(const struct netif *netif) 00526 { 00527 if ((netif != NULL) && (netif_autoip_data(netif) != NULL)) { 00528 struct autoip *autoip = netif_autoip_data(netif); 00529 return (autoip->state == AUTOIP_STATE_BOUND) || (autoip->state == AUTOIP_STATE_ANNOUNCING); 00530 } 00531 return 0; 00532 } 00533 00534 u8_t 00535 autoip_accept_packet(struct netif *netif, const ip4_addr_t *addr) 00536 { 00537 struct autoip *autoip = netif_autoip_data(netif); 00538 return (autoip != NULL) && ip4_addr_cmp(addr, &(autoip->llipaddr)); 00539 } 00540 00541 #endif /* LWIP_IPV4 && LWIP_AUTOIP */
Generated on Tue Jul 12 2022 13:54:28 by
1.7.2