Skip to content

Commit

Permalink
feat(ppp): Allow config PPP DNS servers for peer
Browse files Browse the repository at this point in the history
Make it possible to set the DNS servers to provide to the peer. This is
useful when acting as a PPP server.

If any DNS server is set, don't request a DNS server from the peer.
  • Loading branch information
gonzzor committed Feb 24, 2025
1 parent 877057d commit f6ab11e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions components/esp_netif/include/esp_netif_ppp.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ typedef struct esp_netif_ppp_config {
#ifdef CONFIG_LWIP_PPP_SERVER_SUPPORT
esp_ip4_addr_t ppp_our_ip4_addr; /**< Set our preferred address, typically used when we're the PPP server */
esp_ip4_addr_t ppp_their_ip4_addr; /**< Set our preferred address, typically used when we're the PPP server */
esp_ip4_addr_t ppp_dns1_addr; /**< DNS to provide if peer asks for it, typically used when we're the PPP server */
esp_ip4_addr_t ppp_dns2_addr; /**< DNS to provide if peer asks for it, typically used when we're the PPP server */
#endif // CONFIG_LWIP_PPP_SERVER_SUPPORT
} esp_netif_ppp_config_t;

Expand Down
17 changes: 17 additions & 0 deletions components/esp_netif/lwip/esp_netif_lwip_ppp.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ typedef struct lwip_peer2peer_ctx {
#ifdef CONFIG_LWIP_PPP_SERVER_SUPPORT
esp_ip4_addr_t ppp_our_ip4_addr; // our desired IP (IPADDR_ANY if no preference)
esp_ip4_addr_t ppp_their_ip4_addr; // their desired IP (IPADDR_ANY if no preference)
esp_ip4_addr_t ppp_dns1_addr; // dns server 1 IP (IPADDR_ANY if no preference)
esp_ip4_addr_t ppp_dns2_addr; // dns server 2 IP (IPADDR_ANY if no preference)
#endif
ppp_pcb *ppp;
} lwip_peer2peer_ctx_t;
Expand Down Expand Up @@ -268,6 +270,17 @@ esp_err_t esp_netif_start_ppp(esp_netif_t *esp_netif)
ppp_ctx->ppp->ipcp_wantoptions.hisaddr = ppp_ctx->ppp_their_ip4_addr.addr;
ppp_ctx->ppp->ipcp_wantoptions.accept_local = 1;
}
if (ppp_ctx->ppp_dns1_addr.addr != IPADDR_TYPE_ANY) {
ppp_set_ipcp_dnsaddr(ppp_ctx->ppp, 0, &ppp_ctx->ppp_dns1_addr);
}
if (ppp_ctx->ppp_dns2_addr.addr != IPADDR_TYPE_ANY) {
ppp_set_ipcp_dnsaddr(ppp_ctx->ppp, 1, &ppp_ctx->ppp_dns2_addr);
}
if (ppp_ctx->ppp_dns1_addr.addr != IPADDR_TYPE_ANY ||
ppp_ctx->ppp_dns2_addr.addr != IPADDR_TYPE_ANY) {
// No need to request DNS servers from peer when providing DNS servers.
ppp_set_usepeerdns(ppp_ctx->ppp, 0);
}
#endif // CONFIG_LWIP_PPP_SERVER_SUPPORT

#if ESP_IPV6_AUTOCONFIG
Expand Down Expand Up @@ -338,6 +351,8 @@ esp_err_t esp_netif_ppp_set_params(esp_netif_t *netif, const esp_netif_ppp_confi
#ifdef CONFIG_LWIP_PPP_SERVER_SUPPORT
obj->ppp_our_ip4_addr = config->ppp_our_ip4_addr;
obj->ppp_their_ip4_addr = config->ppp_their_ip4_addr;
obj->ppp_dns1_addr = config->ppp_dns1_addr;
obj->ppp_dns2_addr = config->ppp_dns2_addr;
#endif
return ESP_OK;
}
Expand All @@ -357,6 +372,8 @@ esp_err_t esp_netif_ppp_get_params(esp_netif_t *netif, esp_netif_ppp_config_t *c
#ifdef CONFIG_LWIP_PPP_SERVER_SUPPORT
config->ppp_our_ip4_addr = obj->ppp_our_ip4_addr;
config->ppp_their_ip4_addr = obj->ppp_their_ip4_addr;
config->ppp_dns1_addr = obj->ppp_dns1_addr;
config->ppp_dns2_addr = obj->ppp_dns2_addr;
#endif

return ESP_OK;
Expand Down

0 comments on commit f6ab11e

Please sign in to comment.