]> xenbits.xensource.com Git - unikraft/libs/lwip.git/commitdiff
init: Support setting statically assigned DNS server addresses
authorSimon Kuenzer <simon@unikraft.io>
Fri, 8 Dec 2023 00:03:06 +0000 (01:03 +0100)
committerRazvan Deaconescu <razvan.deaconescu@upb.ro>
Tue, 16 Jan 2024 18:16:01 +0000 (20:16 +0200)
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 <simon@unikraft.io>
Reviewed-by: Stefan Jumarea <stefanjumarea02@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
GitHub-Closes: #42

init.c

diff --git a/init.c b/init.c
index 7d9b13d18a09a96d65ef5f4cc8baebe4616b80c3..5aaf2fd44db5d85a402bf4815eb5d5356172d82f 100644 (file)
--- 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",