static void pico_slaacv4_receive_ipconflict(int reason) { struct slaacv4_cookie *tmp = &slaacv4_local; tmp->conflict_nb++; pico_slaacv4_cancel_timers(tmp); if(tmp->state == SLAACV4_CLAIMED) { if(reason == PICO_ARP_CONFLICT_REASON_CONFLICT) { pico_ipv4_link_del(tmp->device, tmp->ip); } } if (tmp->conflict_nb < MAX_CONFLICTS) { tmp->state = SLAACV4_CLAIMING; tmp->probe_try_nb = 0; tmp->announce_nb = 0; tmp->ip.addr = pico_slaacv4_getip(tmp->device, (uint8_t)1); pico_arp_register_ipconflict(&tmp->ip, &tmp->device->eth->mac, pico_slaacv4_receive_ipconflict); pico_arp_request(tmp->device, &tmp->ip, PICO_ARP_PROBE); tmp->probe_try_nb++; tmp->timer = pico_timer_add(PROBE_WAIT * 1000, pico_slaacv4_send_probe_timer, tmp); if (!tmp->timer) { slaacv4_dbg("SLAACV4: Failed to start probe timer\n"); tmp->state = SLAACV4_ERROR; if (tmp->cb != NULL) tmp->cb(&tmp->ip, PICO_SLAACV4_ERROR); } } else if (tmp->conflict_nb < MAX_CONFLICTS_FAIL) { tmp->state = SLAACV4_CLAIMING; tmp->probe_try_nb = 0; tmp->announce_nb = 0; tmp->ip.addr = pico_slaacv4_getip(tmp->device, (uint8_t)1); pico_arp_register_ipconflict(&tmp->ip, &tmp->device->eth->mac, pico_slaacv4_receive_ipconflict); tmp->timer = pico_timer_add(RATE_LIMIT_INTERVAL * 1000, pico_slaacv4_send_probe_timer, tmp); if (!tmp->timer) { slaacv4_dbg("SLAACV4: Failed to start probe timer\n"); tmp->state = SLAACV4_ERROR; if (tmp->cb != NULL) tmp->cb(&tmp->ip, PICO_SLAACV4_ERROR); } } else { if (tmp->cb != NULL) { pico_hotplug_deregister(tmp->device, &pico_slaacv4_hotplug_cb); tmp->cb(&tmp->ip, PICO_SLAACV4_ERROR); } tmp->state = SLAACV4_ERROR; } }
static int pico_dhcp_client_del_cookie(uint32_t xid) { struct pico_dhcp_client_cookie test = { 0 }, *found = NULL; test.xid = xid; found = pico_tree_findKey(&DHCPCookies, &test); if (!found) return -1; pico_socket_close(found->s); pico_ipv4_link_del(found->dev, found->address); pico_tree_delete(&DHCPCookies, found); pico_free(found); return 0; }