DHCP hostname: send net.hostname in DHCP requests
- aes67_net: esp_netif_set_hostname() before the interface starts, and in the net apply callback (takes effect at the next lease renewal). - Verified: the router's DNS (lan.apointless.space) resolves p4-aes67 to 192.168.192.244. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -128,6 +128,8 @@ static void mdns_setup(void)
|
||||
static void net_apply(const cJSON *g)
|
||||
{
|
||||
const char *host = cJSON_GetObjectItemCaseSensitive(g, "hostname")->valuestring;
|
||||
// DHCP server sees the new name at the next lease renewal.
|
||||
esp_netif_set_hostname(s_netif, host);
|
||||
if (mdns_hostname_set(host) == ESP_OK && mdns_instance_name_set(host) == ESP_OK) {
|
||||
ESP_LOGI(TAG, "mDNS: now %s.local", host);
|
||||
}
|
||||
@@ -155,7 +157,7 @@ static void net_status(cJSON *st)
|
||||
|
||||
esp_err_t aes67_net_init(esp_eth_handle_t eth)
|
||||
{
|
||||
// Applied so far: hostname (mDNS). Static IP and VLAN come later.
|
||||
// Applied so far: hostname (DHCP, mDNS, LLDP). Static IP and VLAN come later.
|
||||
ESP_ERROR_CHECK(cfg_register("net", NET_DEFAULTS, net_validate, net_apply));
|
||||
ESP_ERROR_CHECK(cfg_register("inet", INET_DEFAULTS, inet_validate, NULL));
|
||||
|
||||
@@ -172,6 +174,10 @@ esp_err_t aes67_net_init(esp_eth_handle_t eth)
|
||||
ESP_ERROR_CHECK(esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, eth_event, NULL));
|
||||
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_ETH_GOT_IP, ip_event, NULL));
|
||||
|
||||
// Hostname in DHCP requests (option 12), so the router's lease list shows it.
|
||||
cJSON *net = cfg_get("net");
|
||||
ESP_ERROR_CHECK(esp_netif_set_hostname(s_netif, cJSON_GetObjectItemCaseSensitive(net, "hostname")->valuestring));
|
||||
cJSON_Delete(net);
|
||||
mdns_setup();
|
||||
ESP_ERROR_CHECK(lldp_start(eth, s_netif));
|
||||
status_register(net_status);
|
||||
|
||||
Reference in New Issue
Block a user