]> xenbits.xensource.com Git - unikraft/libs/musl.git/commitdiff
gethostbyname: Option to use lwIPs `gethostbyname()` RELEASE-0.16.2
authorSimon Kuenzer <simon@unikraft.io>
Tue, 6 Feb 2024 11:54:56 +0000 (12:54 +0100)
committerRazvan Deaconescu <razvan.deaconescu@upb.ro>
Fri, 9 Feb 2024 20:32:59 +0000 (22:32 +0200)
This commit introduces redirecting `gethostbyname()` (and family) calls
to lwIP's implementation. This is only enabled if musl is configured to
forward DNS related requests to lwIP.

Signed-off-by: Simon Kuenzer <simon@unikraft.io>
Reviewed-by: Stefan Jumarea <stefanjumarea02@gmail.com>
Reviewed-by: Mihnea Firoiu <mihneafiroiu0@gmail.com>
Reviewed-by: Razvan Deaconescu <razvand@unikraft.io>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
GitHub-Closes: #74

Makefile.uk.musl.network
lwip/gethostbyname.c [new file with mode: 0644]

index 8914fbf17614bc3a58b659d758569702298412bf..485dd70d917a27299de2f7fcbfff61dc39c20011 100644 (file)
@@ -68,16 +68,17 @@ ifeq ($(filter y,$(CONFIG_LIBMUSL_NETWORK_LWIP_DNS)),)
 LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/getaddrinfo.c
 LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/freeaddrinfo.c
 LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/getnameinfo.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/gethostbyname.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/gethostbyname2.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/gethostbyname2_r.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/gethostbyname_r.c
 else
 LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL_BASE)/lwip/getaddrinfo.c
 LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL_BASE)/lwip/getnameinfo.c
+LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL_BASE)/lwip/gethostbyname.c
 endif
 LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/gethostbyaddr.c
 LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/gethostbyaddr_r.c
-LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/gethostbyname.c
-LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/gethostbyname2.c
-LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/gethostbyname2_r.c
-LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/gethostbyname_r.c
 LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/getifaddrs.c
 LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/getservbyname.c
 LIBMUSL_NETWORK_SRCS-y += $(LIBMUSL)/src/network/getservbyname_r.c
diff --git a/lwip/gethostbyname.c b/lwip/gethostbyname.c
new file mode 100644 (file)
index 0000000..16c1732
--- /dev/null
@@ -0,0 +1,44 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/* Copyright (c) 2023, Unikraft GmbH and The Unikraft Authors.
+ * Licensed under the BSD-3-Clause License (the "License").
+ * You may not use this file except in compliance with the License.
+ */
+
+#define _GNU_SOURCE /* Enables h_errno and constants */
+#include <netdb.h>
+#include <lwip/netdb.h>
+#include <uk/print.h>
+#include <uk/essentials.h>
+
+struct hostent *gethostbyname(const char *name) {
+       return lwip_gethostbyname(name);
+}
+
+struct hostent *gethostbyname2(const char *name __unused, int af __unused) {
+       /* Not supported by lwip, but the function is deprecated anyways
+        * (like the other gethostbyname() variants)
+        */
+       UK_WARN_STUBBED();
+
+       h_errno = NO_RECOVERY;
+       return NULL;
+}
+
+int gethostbyname_r(const char *name, struct hostent *ret, char *buf,
+                   size_t buflen, struct hostent **result, int *h_errnop)
+{
+       return lwip_gethostbyname_r(name, ret, buf, buflen, result, h_errnop);
+}
+
+int gethostbyname2_r(const char *name __unused, int af __unused,
+                    struct hostent *ret __unused, char *buf __unused,
+                    size_t buflen __unused, struct hostent **result __unused,
+                    int *h_errnop __unused)
+{
+       /* Not supported by lwip */
+       UK_WARN_STUBBED();
+
+       if (h_errnop)
+               *h_errnop = NO_RECOVERY;
+       return -1;
+}