]> xenbits.xensource.com Git - unikraft/libs/lwip.git/commitdiff
Fix invalid pointer type for dns
authorMichael Pucher <contact@cluo.sh>
Sun, 8 Dec 2024 11:02:04 +0000 (12:02 +0100)
committerRazvan Deaconescu <razvand@unikraft.io>
Thu, 19 Dec 2024 15:27:42 +0000 (17:27 +0200)
The invalid pointer warning becomes an error in gcc14, and it turns out
it's actually an invalid pointer, because it expects a pointer to a
struct with a type tag and not just the IPv4 address, if we have IPv4
and IPv6 enabled (otherwise it typedefs to the IPv4 address and
everything is fine).

Github-fixes: #59
Signed-off-by: Michael Pucher <contact@cluo.sh>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Reviewed-by: Razvan Deaconescu <razvand@unikraft.io>
GitHub-Closes: #60

init.c

diff --git a/init.c b/init.c
index c16a8185f95866a2a65a25c97cc376614f7d5936..4952d222ae9e4dfb92d1d6175f9ba3ae47d4f2fd 100644 (file)
--- a/init.c
+++ b/init.c
@@ -165,7 +165,7 @@ static int liblwip_init(struct uk_init_ctx *ictx __unused)
        ip4_addr_t *gw4_arg;
        const char *hostname_arg;
 #if LWIP_DNS
-       ip4_addr_t dns4;
+       ip_addr_t dns;
        unsigned int nb_dns4 = 0;
 #endif /* LWIP_DNS */
 #endif /* LWIP_IPV4 */
@@ -393,13 +393,18 @@ no_conf:
                if (nb_dns4 < DNS_MAX_SERVERS) {
                        strcfg = uk_netdev_einfo_get(dev, UK_NETDEV_IPV4_DNS0);
                        if (strcfg) {
-                               if (ip4addr_aton(strcfg, &dns4) != 1) {
+#if LWIP_IPV6
+                               dns.type = IPADDR_TYPE_V4;
+                               if (ip4addr_aton(strcfg, &dns.u_addr.ip4) != 1) {
+#else /* LWIP_IPV6 */
+                               if (ip4addr_aton(strcfg, &dns) != 1) {
+#endif /* LWIP_IPV6 */
                                        uk_pr_err("Failed to parse DNS server address: %s\n",
                                                  strcfg);
                                        goto dns_secondary;
                                }
 
-                               dns_setserver(nb_dns4++, &dns4);
+                               dns_setserver(nb_dns4++, &dns);
                                uk_pr_info("%c%c%u: Primary DNS server: %s\n",
                                           nf->name[0], nf->name[1], nf->num,
                                           strcfg);
@@ -411,13 +416,18 @@ dns_secondary:
                if (nb_dns4 < DNS_MAX_SERVERS) {
                        strcfg = uk_netdev_einfo_get(dev, UK_NETDEV_IPV4_DNS1);
                        if (strcfg) {
-                               if (ip4addr_aton(strcfg, &dns4) != 1) {
+#if LWIP_IPV6
+                               dns.type = IPADDR_TYPE_V4;
+                               if (ip4addr_aton(strcfg, &dns.u_addr.ip4) != 1) {
+#else /* LWIP_IPV6 */
+                               if (ip4addr_aton(strcfg, &dns) != 1) {
+#endif /* LWIP_IPV6 */
                                        uk_pr_err("Failed to parse DNS server address: %s\n",
                                                  strcfg);
                                        goto dns_done;
                                }
 
-                               dns_setserver(nb_dns4++, &dns4);
+                               dns_setserver(nb_dns4++, &dns);
                                uk_pr_info("%c%c%u: Secondary DNS server: %s\n",
                                           nf->name[0], nf->name[1], nf->num,
                                           strcfg);