/** * Start AutoIP client * * @param netif network interface on which start the AutoIP client */ err_t autoip_start(struct netif *netif) { struct autoip *autoip = netif->autoip; err_t result = ERR_OK; if(netif_is_up(netif)) { netif_set_down(netif); } /* Set IP-Address, Netmask and Gateway to 0 to make sure that * ARP Packets are formed correctly */ netif->ip_addr.addr = 0; netif->netmask.addr = 0; netif->gw.addr = 0; LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("autoip_start(netif=%p) %c%c%"U16_F"\n", (void*)netif, netif->name[0], netif->name[1], (u16_t)netif->num)); if(autoip == NULL) { /* no AutoIP client attached yet? */ LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE, ("autoip_start(): starting new AUTOIP client\n")); autoip = mem_malloc(sizeof(struct autoip)); if(autoip == NULL) { LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE, ("autoip_start(): could not allocate autoip\n")); return ERR_MEM; } memset( autoip, 0, sizeof(struct autoip)); /* store this AutoIP client in the netif */ netif->autoip = autoip; LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE, ("autoip_start(): allocated autoip")); } else { autoip->state = AUTOIP_STATE_OFF; autoip->ttw = 0; autoip->sent_num = 0; memset(&autoip->llipaddr, 0, sizeof(struct ip_addr)); autoip->lastconflict = 0; } autoip_create_addr(netif, &(autoip->llipaddr)); autoip->tried_llipaddr++; autoip_start_probing(netif); return result; }
/** * Start AutoIP client * * @param netif network interface on which start the AutoIP client */ err_t autoip_start(struct netif *netif) { struct autoip *autoip = netif->autoip; err_t result = ERR_OK; if(netif_is_up(netif)) { netif_set_down(netif); } /* Set IP-Address, Netmask and Gateway to 0 to make sure that * ARP Packets are formed correctly */ netif->ip_addr.addr = 0; netif->netmask.addr = 0; netif->gw.addr = 0; LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("autoip_start(netif=%p) %c%c%"U16_F"\n", (void*)netif, netif->name[0], netif->name[1], (u16_t)netif->num)); if(autoip == NULL) { /* no AutoIP client attached yet? */ LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE, ("autoip_start(): starting new AUTOIP client\n")); autoip = mem_malloc(sizeof(struct autoip)); if(autoip == NULL) { LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE, ("autoip_start(): could not allocate autoip\n")); return ERR_MEM; } memset( autoip, 0, sizeof(struct autoip)); /* store this AutoIP client in the netif */ netif->autoip = autoip; LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE, ("autoip_start(): allocated autoip")); } else { autoip->state = AUTOIP_STATE_OFF; autoip->ttw = 0; autoip->sent_num = 0; memset(&autoip->llipaddr, 0, sizeof(struct ip_addr)); autoip->lastconflict = 0; } autoip_create_addr(netif, &(autoip->llipaddr)); autoip->tried_llipaddr++; autoip->state = AUTOIP_STATE_PROBING; autoip->sent_num = 0; /* time to wait to first probe, this is randomly * choosen out of 0 to PROBE_WAIT seconds. * compliant to RFC 3927 Section 2.2.1 */ autoip->ttw = (u16_t)(LWIP_AUTOIP_RAND(netif) % (PROBE_WAIT * AUTOIP_TICKS_PER_SECOND)); /* * if we tried more then MAX_CONFLICTS we must limit our rate for * accquiring and probing address * compliant to RFC 3927 Section 2.2.1 */ if(autoip->tried_llipaddr > MAX_CONFLICTS) { autoip->ttw = RATE_LIMIT_INTERVAL * AUTOIP_TICKS_PER_SECOND; } return result; }