Fix DNS issues on Bionic

This commit is contained in:
topjohnwu 2024-10-06 01:43:13 -07:00
parent 9fa83933e1
commit 14d189ea30
19 changed files with 162 additions and 59 deletions

View File

@ -1,11 +1,11 @@
MINORLEVEL := 0
MINORLEVEL := 1
BB_VER := "$(VERSION).$(PATCHLEVEL).$(SUBLEVEL).$(MINORLEVEL) topjohnwu"
include $(CLEAR_VARS)
LOCAL_MODULE := busybox
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_STATIC_LIBRARIES := libselinux
LOCAL_LDFLAGS := -static -Wl,--wrap=realpath -Wl,--wrap=rename -Wl,--wrap=renameat
LOCAL_LDFLAGS := -static -Wl,--wrap=realpath -Wl,--wrap=rename -Wl,--wrap=renameat -Wl,--wrap=getaddrinfo
LOCAL_CFLAGS := \
-w -include include/autoconf.h -D__USE_BSD -D__USE_GNU \
-DBB_VER=\"$(BB_VER)\" -DBB_BT=AUTOCONF_TIMESTAMP

View File

@ -1,4 +1,4 @@
From 4d264bc921b1a74381d356167b4c15673c819456 Mon Sep 17 00:00:00 2001
From 7dc09d51bef3385f976237ffc1a76be9512f305d Mon Sep 17 00:00:00 2001
From: topjohnwu <topjohnwu@gmail.com>
Date: Sat, 13 Jul 2024 18:26:16 -0700
Subject: [PATCH 01/18] Fix incorrect assumptions about NDK
@ -102,5 +102,5 @@ index e2ff4b5cc..67c384db6 100644
#if ENABLE_FEATURE_SWAPONOFF_LABEL
# include "volume_id.h"
--
2.45.2
2.46.0

View File

@ -1,4 +1,4 @@
From 62dc3c2191e35983b619fc750f9f731c4a84a232 Mon Sep 17 00:00:00 2001
From fea349b03d474af1747ac271a4bc399560dc7868 Mon Sep 17 00:00:00 2001
From: Chris Renshaw <osm0sis@outlook.com>
Date: Thu, 3 Dec 2015 01:29:35 -0400
Subject: [PATCH 02/18] loadfont/setfont/conspy: add missing header
@ -51,5 +51,5 @@ index 000000000..8b8e56d4d
+
+#endif /* sys/kd.h */
--
2.45.2
2.46.0

View File

@ -1,4 +1,4 @@
From 9cf0fa6cd156d864a738c21d34ee273392c56dfc Mon Sep 17 00:00:00 2001
From c3ef5bfe51715fb2ae7bae2ce90074d5c94b363b Mon Sep 17 00:00:00 2001
From: Tias Guns <tias@ulyssis.org>
Date: Tue, 20 Mar 2012 21:26:07 +0000
Subject: [PATCH 03/18] fix ipcs, ipcrm no sys/sem-shm-msg, etc
@ -41,5 +41,5 @@ index 5973cbf57..2e43b7758 100644
#else
/* according to X/OPEN we have to define it ourselves */
--
2.45.2
2.46.0

View File

@ -1,4 +1,4 @@
From 41a741b2213a0f127c239e163d1f8f894f5390f6 Mon Sep 17 00:00:00 2001
From ef644647dca6d2d1d19c2b7eedc84fff7601eb62 Mon Sep 17 00:00:00 2001
From: topjohnwu <topjohnwu@gmail.com>
Date: Sat, 13 Jul 2024 18:35:56 -0700
Subject: [PATCH 04/18] Bionic does not have ether_hostton
@ -21,5 +21,5 @@ index 36e90acfb..0bbf2057f 100644
bb_debug_msg("Station address for hostname %s is %s\n\n", hostid, ether_ntoa(eaddr));
#endif
--
2.45.2
2.46.0

View File

@ -1,4 +1,4 @@
From 79bdb8978e9ffcfc4799ed00206602d5e57b5844 Mon Sep 17 00:00:00 2001
From fd0363ef8a6a1cb6cb4acc753f80f79b567b90e6 Mon Sep 17 00:00:00 2001
From: topjohnwu <topjohnwu@gmail.com>
Date: Sun, 14 Jul 2024 16:54:36 -0700
Subject: [PATCH 05/18] Prevent duplicate in6_ifreq definition
@ -41,5 +41,5 @@ index 6b6c0944a..cf48733da 100644
* This is from linux/include/net/ipv6.h
*/
--
2.45.2
2.46.0

View File

@ -1,4 +1,4 @@
From 1b95c833d8cda62bf79f0ec8da7cca8f3ea1e4d8 Mon Sep 17 00:00:00 2001
From 2b383c89a8021b6ff0983f706e54e0ff7de4c803 Mon Sep 17 00:00:00 2001
From: topjohnwu <topjohnwu@gmail.com>
Date: Sun, 14 Jul 2024 16:55:01 -0700
Subject: [PATCH 06/18] Add missing sigisemptyset implementation
@ -28,5 +28,5 @@ index d111f0cc5..5fbceaae3 100644
{
sigaddset(&G.pending_set, sig);
--
2.45.2
2.46.0

View File

@ -1,4 +1,4 @@
From f258400ac6119a369865606883245ecf176005ae Mon Sep 17 00:00:00 2001
From 2c918c2e8a537125eed6c25f859e692c9909c154 Mon Sep 17 00:00:00 2001
From: topjohnwu <topjohnwu@gmail.com>
Date: Sun, 14 Jul 2024 21:26:56 -0700
Subject: [PATCH 07/18] Prevent compiling mtab related features
@ -30,5 +30,5 @@ index 4e65b6b46..08058db49 100644
return rc;
}
--
2.45.2
2.46.0

View File

@ -1,4 +1,4 @@
From 12334c3e19a1e902a90b7d4898f61b08301de94d Mon Sep 17 00:00:00 2001
From 53971e30edd14c1151e7bf0330302ff3d17fcf7e Mon Sep 17 00:00:00 2001
From: topjohnwu <topjohnwu@gmail.com>
Date: Mon, 15 Jul 2024 18:50:57 -0700
Subject: [PATCH 08/18] Remove CBQ support from tc
@ -60,5 +60,5 @@ index 43187f7ee..92601d6e3 100644
/* don't know how to print options for this class */
printf("(options for %s)", name);
--
2.45.2
2.46.0

View File

@ -1,7 +1,7 @@
From cd4a191fd4c51117087c41c4898508b89389cb1e Mon Sep 17 00:00:00 2001
From 266710b5955f51982436507065c62c3854e4c26f Mon Sep 17 00:00:00 2001
From: LoveSy <shana@zju.edu.cn>
Date: Sun, 20 Mar 2022 00:51:25 +0800
Subject: [PATCH 13/18] Replace realpath to BSD implementation
Subject: [PATCH 09/18] Replace realpath to BSD implementation
---
libbb/Kbuild.src | 3 +
@ -251,5 +251,5 @@ index 000000000..d4548859a
+ return (resolved);
+}
--
2.45.2
2.46.0

View File

@ -1,7 +1,7 @@
From 6e402158a42bab0f1f45053d356beb8ec8d8e615 Mon Sep 17 00:00:00 2001
From 893dcbb6e92c3aa4dda33c5766191c1b386be621 Mon Sep 17 00:00:00 2001
From: topjohnwu <topjohnwu@gmail.com>
Date: Sat, 2 Sep 2023 05:21:13 -0700
Subject: [PATCH 14/18] Replace rename(2) with direct system call
Subject: [PATCH 10/18] Replace rename(2) with direct system call
NDK r26 introduced the following change:
https://android-review.googlesource.com/c/platform/bionic/+/2240019
@ -49,5 +49,5 @@ index d4548859a..e6a13667f 100644
+ return __wrap_renameat(AT_FDCWD, old_path, AT_FDCWD, new_path);
+}
--
2.45.2
2.46.0

View File

@ -1,19 +1,22 @@
From 2eb6acaf13508003e26d51cbce7bc42b49634e3c Mon Sep 17 00:00:00 2001
From 047d382f9fa49119cd1d901b8515e14939763f49 Mon Sep 17 00:00:00 2001
From: topjohnwu <topjohnwu@gmail.com>
Date: Mon, 15 Jul 2024 17:20:17 -0700
Subject: [PATCH 09/18] Use bionic libresolv for nslookup
Subject: [PATCH 11/18] Support DNS on statically linked Bionic
---
networking/bionic_resolv.h | 112 +++++++++++++++++++++++++++++++++++++
networking/nslookup.c | 27 ++++-----
2 files changed, 124 insertions(+), 15 deletions(-)
create mode 100644 networking/bionic_resolv.h
include/bionic_resolv.h | 112 ++++++++++++++++++++++++++++++++++++++++
include/libbb.h | 2 +
libbb/wrap_funcs.c | 11 ++++
libbb/xconnect.c | 37 +++++++++++++
networking/nslookup.c | 29 +++++------
5 files changed, 176 insertions(+), 15 deletions(-)
create mode 100644 include/bionic_resolv.h
diff --git a/networking/bionic_resolv.h b/networking/bionic_resolv.h
diff --git a/include/bionic_resolv.h b/include/bionic_resolv.h
new file mode 100644
index 000000000..a15cb587b
--- /dev/null
+++ b/networking/bionic_resolv.h
+++ b/include/bionic_resolv.h
@@ -0,0 +1,112 @@
+#pragma once
+
@ -127,8 +130,99 @@ index 000000000..a15cb587b
+
+extern struct __res_state *__res_get_state(void);
+#define _res (*__res_get_state())
diff --git a/include/libbb.h b/include/libbb.h
index cca33a177..6a7f4fc11 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -831,6 +831,8 @@ char* xmalloc_sockaddr2dotted_noport(const struct sockaddr *sa) FAST_FUNC RETURN
struct hostent *xgethostbyname(const char *name) FAST_FUNC;
// Also mount.c and inetd.c are using gethostbyname(),
// + inet_common.c has additional IPv4-only stuff
+/* Set the dns server in the global _res nameserver structure */
+void set_default_dns(const char *server);
struct tls_aes {
diff --git a/libbb/wrap_funcs.c b/libbb/wrap_funcs.c
index e6a13667f..24b7e7f23 100644
--- a/libbb/wrap_funcs.c
+++ b/libbb/wrap_funcs.c
@@ -36,6 +36,9 @@
#include <unistd.h>
#include <fcntl.h>
+#include "libbb.h"
+#include "bionic_resolv.h"
+
char * __wrap_realpath(const char * __restrict path, char * __restrict resolved)
{
struct stat sb;
@@ -233,3 +236,11 @@ int __wrap_renameat(int old_dir_fd, const char *old_path, int new_dir_fd, const
int __wrap_rename(const char *old_path, const char *new_path) {
return __wrap_renameat(AT_FDCWD, old_path, AT_FDCWD, new_path);
}
+
+extern typeof(getaddrinfo) __real_getaddrinfo;
+
+int __wrap_getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res) {
+ // Statically linked bionic does not have a global DNS, need to set it
+ set_default_dns(NULL);
+ return __real_getaddrinfo(node, service, hints, res);
+}
diff --git a/libbb/xconnect.c b/libbb/xconnect.c
index 0e0b247b8..d444fa577 100644
--- a/libbb/xconnect.c
+++ b/libbb/xconnect.c
@@ -15,6 +15,7 @@
# include <linux/netlink.h>
#endif
#include "libbb.h"
+#include "bionic_resolv.h"
int FAST_FUNC setsockopt_int(int fd, int level, int optname, int optval)
{
@@ -539,3 +540,39 @@ char* FAST_FUNC xmalloc_sockaddr2dotted_noport(const struct sockaddr *sa)
{
return sockaddr2str(sa, NI_NUMERICHOST | NI_NUMERICSCOPE | IGNORE_PORT);
}
+
+void set_default_dns(const char *server)
+{
+ static bool has_set_default_dns = false;
+ len_and_sockaddr *lsa;
+
+ // Set a fallback DNS server
+ if (!server) {
+ if (!has_set_default_dns) {
+ server = "8.8.8.8";
+ } else {
+ return;
+ }
+ }
+
+ has_set_default_dns = true;
+
+ /* NB: this works even with, say, "[::1]:5353"! :) */
+ lsa = xhost2sockaddr(server, 53);
+
+ if (lsa->u.sa.sa_family == AF_INET) {
+ _res.nscount = 1;
+ /* struct copy */
+ _res.nsaddr_list[0] = lsa->u.sin;
+ }
+#if ENABLE_FEATURE_IPV6
+ if (lsa->u.sa.sa_family == AF_INET6) {
+ _res.nscount = 1;
+ _res._u._ext.nscount = 1;
+ /* struct copy */
+ _res._u._ext.ext->nsaddrs[0].sin6 = lsa->u.sin6;
+ _res.nsaddr_list[0].sin_family = 0;
+ }
+#endif
+ free(lsa);
+}
diff --git a/networking/nslookup.c b/networking/nslookup.c
index 6da97baf4..0441ab116 100644
index 6da97baf4..56722a28b 100644
--- a/networking/nslookup.c
+++ b/networking/nslookup.c
@@ -40,6 +40,9 @@
@ -151,7 +245,14 @@ index 6da97baf4..0441ab116 100644
if (!sa)
#endif
sa = (struct sockaddr*)&_res.nsaddr_list[0];
@@ -166,8 +170,9 @@ static void set_default_dns(const char *server)
@@ -160,14 +164,16 @@ static void server_print(void)
bb_putchar('\n');
}
+#if 0
/* alter the global _res nameserver structure to use
an explicit dns server instead of what is in /etc/resolv.conf */
static void set_default_dns(const char *server)
{
len_and_sockaddr *lsa;
@ -162,7 +263,7 @@ index 6da97baf4..0441ab116 100644
/* NB: this works even with, say, "[::1]:5353"! :) */
lsa = xhost2sockaddr(server, 53);
@@ -178,20 +183,15 @@ static void set_default_dns(const char *server)
@@ -178,21 +184,17 @@ static void set_default_dns(const char *server)
_res.nsaddr_list[0] = lsa->u.sin;
}
#if ENABLE_FEATURE_IPV6
@ -186,9 +287,11 @@ index 6da97baf4..0441ab116 100644
#endif
+ free(lsa);
}
+#endif
int nslookup_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
@@ -205,9 +205,6 @@ int nslookup_main(int argc, char **argv)
int nslookup_main(int argc, char **argv)
@@ -205,9 +207,6 @@ int nslookup_main(int argc, char **argv)
if (!argv[1] || argv[1][0] == '-' || argc > 3)
bb_show_usage();
@ -199,5 +302,5 @@ index 6da97baf4..0441ab116 100644
/* (but it also says "may be enabled in /etc/resolv.conf") */
/*_res.options |= RES_USE_INET6;*/
--
2.45.2
2.46.0

View File

@ -1,17 +1,17 @@
From 9cb8d202d99a8126413283d50dbe83e457387689 Mon Sep 17 00:00:00 2001
From ee26ea829b0c9e8d3c79d0264f0fb6b47882cbe2 Mon Sep 17 00:00:00 2001
From: Chris Renshaw <osm0sis@outlook.com>
Date: Wed, 24 May 2023 14:15:00 -0300
Subject: [PATCH 10/18] Fix direct mount auto loopback and losetup for Android
Subject: [PATCH 12/18] Fix direct mount auto loopback and losetup for Android
---
include/libbb.h | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/include/libbb.h b/include/libbb.h
index cca33a177..87dd74e48 100644
index 6a7f4fc11..cae6bfb6c 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -2390,9 +2390,15 @@ extern const char bb_default_login_shell[] ALIGN1;
@@ -2392,9 +2392,15 @@ extern const char bb_default_login_shell[] ALIGN1;
# define VC_4 "/dev/tty4"
# define VC_5 "/dev/tty5"
# define VC_FORMAT "/dev/tty%d"
@ -31,5 +31,5 @@ index cca33a177..87dd74e48 100644
#endif
--
2.45.2
2.46.0

View File

@ -1,7 +1,7 @@
From 7d82ae116d7c3a3aa6d9048574fdf0564d513378 Mon Sep 17 00:00:00 2001
From b3f7ddd0ca5a8234204cd6171f04225954684c57 Mon Sep 17 00:00:00 2001
From: topjohnwu <topjohnwu@gmail.com>
Date: Mon, 15 Jul 2024 17:44:50 -0700
Subject: [PATCH 11/18] Update shell paths to Android specific values
Subject: [PATCH 13/18] Update shell paths to Android specific values
---
include/libbb.h | 4 ++--
@ -11,10 +11,10 @@ Subject: [PATCH 11/18] Update shell paths to Android specific values
4 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/include/libbb.h b/include/libbb.h
index 87dd74e48..112e45197 100644
index cae6bfb6c..2f5f61d9e 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -2341,12 +2341,12 @@ void XZALLOC_CONST_PTR(const void *pptr, size_t size) FAST_FUNC;
@@ -2343,12 +2343,12 @@ void XZALLOC_CONST_PTR(const void *pptr, size_t size) FAST_FUNC;
* use bb_default_login_shell and following defines.
* If you change LIBBB_DEFAULT_LOGIN_SHELL,
* don't forget to change increment constant. */
@ -80,5 +80,5 @@ index 9344e4de1..19eed5451 100644
state = 2;
hp = lookupvar("HOME");
--
2.45.2
2.46.0

View File

@ -1,7 +1,7 @@
From 4732054018b9f22edeb2b47153352a1399c5bc5a Mon Sep 17 00:00:00 2001
From dc8a4f4589fc32e7829514078088c3a1e3700886 Mon Sep 17 00:00:00 2001
From: topjohnwu <topjohnwu@gmail.com>
Date: Sat, 2 May 2020 01:48:30 -0700
Subject: [PATCH 12/18] Disable SELinux features for install
Subject: [PATCH 14/18] Disable SELinux features for install
matchpathcon is not usable on Android
---
@ -32,5 +32,5 @@ index c0f1c538a..16c014384 100644
static const char install_longopts[] ALIGN1 =
IF_FEATURE_VERBOSE(
--
2.45.2
2.46.0

View File

@ -1,4 +1,4 @@
From 11d2be8946ebc995890bf81bd80210ae1045cd0f Mon Sep 17 00:00:00 2001
From 2138b7ce4e4bf3403d322fc12ce0c0ffb094942a Mon Sep 17 00:00:00 2001
From: topjohnwu <topjohnwu@gmail.com>
Date: Fri, 7 Feb 2020 14:32:06 -0800
Subject: [PATCH 15/18] Add runtime toggle to enable standalone ash
@ -115,5 +115,5 @@ index 19eed5451..34a540049 100644
const char *hp;
--
2.45.2
2.46.0

View File

@ -1,4 +1,4 @@
From 86557f542be8f62b583717ae22cf10a4bbbe78f9 Mon Sep 17 00:00:00 2001
From 7eb613f2e12cc47cd8614ad914821bde2b8f8631 Mon Sep 17 00:00:00 2001
From: topjohnwu <topjohnwu@gmail.com>
Date: Thu, 25 Jun 2020 03:54:53 -0700
Subject: [PATCH 16/18] Resolve /proc/self/exe when re-exec ourselves
@ -62,5 +62,5 @@ index 34a540049..4dae9a474 100644
if (argc < 0)
/* Non-NULL minusc tells procargs that an embedded script is being run */
--
2.45.2
2.46.0

View File

@ -1,4 +1,4 @@
From 63e82e940984e1ee6f93f9ee4a6b0255bc2006dc Mon Sep 17 00:00:00 2001
From db77b8eeb81ae01685aeb3e45a9ceb4b214e39ca Mon Sep 17 00:00:00 2001
From: topjohnwu <topjohnwu@gmail.com>
Date: Thu, 21 Jan 2021 00:07:41 -0800
Subject: [PATCH 17/18] Allow running as libbusybox.so
@ -24,5 +24,5 @@ index d5335d353..460ce823f 100644
applet_name++;
applet_name = bb_basename(applet_name);
--
2.45.2
2.46.0

View File

@ -1,4 +1,4 @@
From 091ecfecb34cbc0724dedf07accc7d16880f69ca Mon Sep 17 00:00:00 2001
From 2cda0b629f8d083f2ea2346d5f452b4d1ba45dfd Mon Sep 17 00:00:00 2001
From: topjohnwu <topjohnwu@gmail.com>
Date: Fri, 21 Jun 2024 03:09:47 -0700
Subject: [PATCH 18/18] Allow variable page size on x64
@ -8,7 +8,7 @@ Subject: [PATCH 18/18] Allow variable page size on x64
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/libbb.h b/include/libbb.h
index 112e45197..401a8ec9a 100644
index 2f5f61d9e..68a78e2c3 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -435,7 +435,7 @@ void *mmap_read(int fd, size_t size) FAST_FUNC;
@ -21,5 +21,5 @@ index 112e45197..401a8ec9a 100644
#elif defined(__arm__) /* only 32bit, 64bit ARM has variable page size */
# define BB_ARCH_FIXED_PAGESIZE 4096
--
2.45.2
2.46.0