Skip to content

Commit 89ef9bd

Browse files
authored
Fix remote DNS (#898)
* dns remote resolv * add fionread * lint
1 parent f77760a commit 89ef9bd

File tree

5 files changed

+86
-7
lines changed

5 files changed

+86
-7
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
passwd: files
22
group: files
3-
hosts: files
3+
hosts: files dns
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
nameserver 8.8.8.8
2+
nameserver 8.8.4.4

src/rawposix/src/fs_calls.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ use libc::c_void;
99
use std::sync::Arc;
1010
use sysdefs::constants::err_const::{get_errno, handle_errno, syscall_error, Errno};
1111
use sysdefs::constants::fs_const::{
12-
FIOASYNC, FIONBIO, F_GETLK64, F_SETLK64, F_SETLKW64, MAP_ANONYMOUS, MAP_FIXED, MAP_POPULATE,
13-
MAP_PRIVATE, MAP_SHARED, O_CLOEXEC, PAGESHIFT, PAGESIZE, PROT_EXEC, PROT_NONE, PROT_READ,
14-
PROT_WRITE, SHMMAX, SHMMIN, SHM_DEST, SHM_RDONLY, STDERR_FILENO, STDIN_FILENO, STDOUT_FILENO,
15-
TIOCGWINSZ,
12+
FIOASYNC, FIONBIO, FIONREAD, F_GETLK64, F_SETLK64, F_SETLKW64, MAP_ANONYMOUS, MAP_FIXED,
13+
MAP_POPULATE, MAP_PRIVATE, MAP_SHARED, O_CLOEXEC, PAGESHIFT, PAGESIZE, PROT_EXEC, PROT_NONE,
14+
PROT_READ, PROT_WRITE, SHMMAX, SHMMIN, SHM_DEST, SHM_RDONLY, STDERR_FILENO, STDIN_FILENO,
15+
STDOUT_FILENO, TIOCGWINSZ,
1616
};
1717

1818
use sysdefs::constants::lind_platform_const::{FDKIND_KERNEL, MAXFD, UNUSED_ARG, UNUSED_ID};
@@ -3857,9 +3857,9 @@ pub extern "C" fn ioctl_syscall(
38573857
return ret;
38583858
}
38593859

3860-
// Besides FIOCLEX, we only support FIONBIO, FIOASYNC, and TIOCGWINSZ right now.
3860+
// Besides FIOCLEX, we only support FIONBIO, FIOASYNC, FIONREAD, and TIOCGWINSZ right now.
38613861
// Return error for unsupported requests.
3862-
if req != FIONBIO && req != FIOASYNC && req != TIOCGWINSZ {
3862+
if req != FIONBIO && req != FIOASYNC && req != FIONREAD && req != TIOCGWINSZ {
38633863
lind_debug_panic("Lind unsupported ioctl request");
38643864
}
38653865

src/sysdefs/src/constants/fs_const.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ pub const F_NOTIFY: i32 = 1026;
8181
pub const FIONBIO: u32 = 21537;
8282
pub const FIOASYNC: u32 = 21586;
8383
pub const TIOCGWINSZ: u32 = 21523;
84+
pub const FIONREAD: u32 = 21531;
8485

8586
//File types for open/stat etc.
8687
// Source: include/linux/stat.h
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/* Test DNS resolution for external hostnames via getaddrinfo.
2+
*
3+
* Requires:
4+
* - /etc/nsswitch.conf with "hosts: files dns"
5+
* - /etc/resolv.conf with valid nameserver entries
6+
* - Network access to the configured nameserver
7+
*
8+
* Tests:
9+
* 1. localhost resolves via /etc/hosts (files backend)
10+
* 2. external hostname resolves via DNS (dns backend)
11+
* 3. numeric IP resolves without DNS
12+
*/
13+
#include <stdio.h>
14+
#include <string.h>
15+
#include <netdb.h>
16+
#include <arpa/inet.h>
17+
#include <unistd.h>
18+
19+
static int test_resolve(const char *host, int expect_success) {
20+
struct addrinfo hints, *res;
21+
memset(&hints, 0, sizeof(hints));
22+
hints.ai_family = AF_INET;
23+
hints.ai_socktype = SOCK_STREAM;
24+
25+
int ret = getaddrinfo(host, "80", &hints, &res);
26+
if (expect_success && ret != 0) {
27+
char buf[256];
28+
int len = snprintf(buf, sizeof(buf),
29+
"FAIL: getaddrinfo(\"%s\") failed: %s\n",
30+
host, gai_strerror(ret));
31+
write(2, buf, len);
32+
return 1;
33+
}
34+
if (!expect_success && ret == 0) {
35+
freeaddrinfo(res);
36+
char buf[256];
37+
int len = snprintf(buf, sizeof(buf),
38+
"FAIL: getaddrinfo(\"%s\") succeeded but expected failure\n", host);
39+
write(2, buf, len);
40+
return 1;
41+
}
42+
if (expect_success) {
43+
char addr_str[INET_ADDRSTRLEN];
44+
struct sockaddr_in *sa = (struct sockaddr_in *)res->ai_addr;
45+
inet_ntop(AF_INET, &sa->sin_addr, addr_str, sizeof(addr_str));
46+
char buf[256];
47+
int len = snprintf(buf, sizeof(buf),
48+
"OK: %s -> %s\n", host, addr_str);
49+
write(1, buf, len);
50+
freeaddrinfo(res);
51+
}
52+
return 0;
53+
}
54+
55+
int main(void) {
56+
int failures = 0;
57+
58+
/* Test 1: localhost via /etc/hosts */
59+
failures += test_resolve("localhost", 1);
60+
61+
/* Test 2: numeric IP (no DNS needed) */
62+
failures += test_resolve("93.184.216.34", 1);
63+
64+
/* Test 3: external hostname via DNS */
65+
failures += test_resolve("example.com", 1);
66+
67+
if (failures) {
68+
char buf[64];
69+
int len = snprintf(buf, sizeof(buf), "%d test(s) failed\n", failures);
70+
write(2, buf, len);
71+
return 1;
72+
}
73+
74+
write(1, "done\n", 5);
75+
return 0;
76+
}

0 commit comments

Comments
 (0)