From: Simon Kuenzer Date: Fri, 8 Dec 2023 00:03:06 +0000 (+0100) Subject: init: Support setting statically assigned DNS server addresses X-Git-Tag: RELEASE-0.16.2~8 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=3df429f522806ecdf31b15578926bbbb998a3525;p=unikraft%2Flibs%2Flwip.git init: Support setting statically assigned DNS server addresses This commit introduces support for setting DNS server addresses to lwIP's DNS subsystem. The information is found on uknetdev's extended information fields `UK_NETDEV_IPV4_DNS0` and `UK_NETDEV_IPV4_DNS1`. Signed-off-by: Simon Kuenzer Reviewed-by: Stefan Jumarea Approved-by: Razvan Deaconescu GitHub-Closes: #42 --- diff --git a/init.c b/init.c index 7d9b13d..5aaf2fd 100644 --- a/init.c +++ b/init.c @@ -36,6 +36,7 @@ #include "lwip/opt.h" #include "lwip/tcpip.h" #include "lwip/init.h" +#include "lwip/dns.h" #include "lwip/dhcp.h" #include "lwip/inet.h" #if CONFIG_LWIP_NOTHREADS @@ -148,6 +149,10 @@ static int liblwip_init(struct uk_init_ctx *ictx __unused) ip4_addr_t gw4; ip4_addr_t *gw4_arg; const char *hostname_arg; +#if LWIP_DNS + ip4_addr_t dns4; + unsigned int nb_dns4 = 0; +#endif /* LWIP_DNS */ #endif /* LWIP_IPV4 */ #endif /* CONFIG_LWIP_UKNETDEV && CONFIG_LWIP_AUTOIFACE */ @@ -361,6 +366,45 @@ no_conf: uk_pr_info("\n"); #endif /* LWIP_CHECKSUM_CTRL_PER_NETIF */ +#if LWIP_IPV4 && LWIP_DNS + /* Primary DNS */ + if (nb_dns4 < DNS_MAX_SERVERS) { + strcfg = uk_netdev_einfo_get(dev, UK_NETDEV_IPV4_DNS0); + if (strcfg) { + if (ip4addr_aton(strcfg, &dns4) != 1) { + uk_pr_err("Failed to parse DNS server address: %s\n", + strcfg); + goto dns_secondary; + } + + dns_setserver(nb_dns4++, &dns4); + uk_pr_info("%c%c%u: Primary DNS server: %s\n", + nf->name[0], nf->name[1], nf->num, + strcfg); + } + } + +dns_secondary: + /* Secondary DNS */ + if (nb_dns4 < DNS_MAX_SERVERS) { + strcfg = uk_netdev_einfo_get(dev, UK_NETDEV_IPV4_DNS1); + if (strcfg) { + if (ip4addr_aton(strcfg, &dns4) != 1) { + uk_pr_err("Failed to parse DNS server address: %s\n", + strcfg); + goto dns_done; + } + + dns_setserver(nb_dns4++, &dns4); + uk_pr_info("%c%c%u: Secondary DNS server: %s\n", + nf->name[0], nf->name[1], nf->num, + strcfg); + } + } + +dns_done: +#endif /* LWIP_IPV4 && LWIP_DNS */ + /* Declare the first network device as default interface */ if (is_first_nf) { uk_pr_info("%c%c%u: Set as default interface\n",