DHCP Service IPADDR Pool

diomed
Posts: 2
Joined: Fri Jun 23, 2023 11:47 pm

DHCP Service IPADDR Pool

Postby diomed » Sat Jun 24, 2023 12:25 am

Hello, I'm testing and learning the IP Internal Network example from the ESP-IDF example projects. I'm currently trying to figure out how or where the DHCP pool is assigned for the root node. I understand that the root node initializes the DHCP client service to request an external IP, then initializes the DHCP service for the mesh to assign internal IPs, and for internal IPs uses the 10.0.0.0/8 network by default in the example. Where is this network address (10.0.0.0) located/set? This is the contents of the first few lines of app_main():
  1. ESP_ERROR_CHECK(nvs_flash_init());
  2. /*  tcpip initialization */
  3. ESP_ERROR_CHECK(esp_netif_init());
  4. /*  event initialization */
  5. ESP_ERROR_CHECK(esp_event_loop_create_default());
  6. /*  crete network interfaces for mesh (only station instance saved for further manipulation, soft AP instance ignored */
  7. ESP_ERROR_CHECK(mesh_netifs_init(recv_cb));
  8.  
  9. /*  wifi initialization */
  10. wifi_init_config_t config = WIFI_INIT_CONFIG_DEFAULT();
  11. ESP_ERROR_CHECK(esp_wifi_init(&config));
  12. ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &ip_event_handler, NULL));
  13. ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_FLASH));
  14. ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_NONE));
  15. ESP_ERROR_CHECK(esp_wifi_start());
I'm kind of lost. I tried following the function pointer for ip_event_handler but could not find where event_data was passed and work backwards to determine the IP address. Any help is appreciated, thanks.

diomed
Posts: 2
Joined: Fri Jun 23, 2023 11:47 pm

Re: DHCP Service IPADDR Pool

Postby diomed » Fri Jul 28, 2023 7:25 pm

I figured it out; it's in mesh_netif.c. I'm not sure why I passed over this file initially; it cause me a lot of unnecessary headache. The struct is declared:
  1. const esp_netif_ip_info_t g_mesh_netif_subnet_ip = {        // mesh subnet IP info
  2.         .ip = { .addr = ESP_IP4TOADDR( 192, 168, 0, 1) },
  3.         .gw = { .addr = ESP_IP4TOADDR( 192, 168, 0, 1) },
  4.         .netmask = { .addr = ESP_IP4TOADDR( 255, 255, 255, 0) },
  5. };
Root node assumes this IP; child nodes check the ARP table and increment until an address is available, then send the DHCPREQUEST to root.

Who is online

Users browsing this forum: iancoullie, snutw_ and 78 guests