Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ext/net): enable EDNS0 for Deno.resolveDns #27735

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion ext/net/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ where
cancel_rid,
} = args;

let (config, opts) = if let Some(name_server) =
let (config, mut opts) = if let Some(name_server) =
options.as_ref().and_then(|o| o.name_server.as_ref())
{
let group = NameServerConfigGroup::from_ips_clear(
Expand All @@ -662,6 +662,8 @@ where
system_conf::read_system_conf()?
};

opts.edns0 = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nits: Please add a comment here 🙇


{
let mut s = state.borrow_mut();
let perm = s.borrow_mut::<NP>();
Expand Down
Binary file added tests/registry/npm/dns2/dns2-2.1.0.tgz
Binary file not shown.
72 changes: 72 additions & 0 deletions tests/registry/npm/dns2/registry.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"name": "dns2",
"description": "A DNS Server and Client Implementation in Pure JavaScript with no dependencies.",
"dist-tags": {
"latest": "2.1.0"
},
"versions": {
"2.1.0": {
"name": "dns2",
"version": "2.1.0",
"description": "A DNS Server and Client Implementation in Pure JavaScript with no dependencies.",
"main": "index.js",
"scripts": {
"test": "node test",
"lint": "eslint .",
"example-server-udp": "node example/server/udp.js",
"example-server-tcp": "node example/server/tcp.js",
"example-server-doh": "node example/server/doh.js",
"example-client-doh": "node example/client/doh.js",
"example-client-udp": "node example/client/udp.js",
"example-client-tcp": "node example/client/tcp.js",
"example-client-google": "node example/client/google.js",
"example-client-udp-subnet": "node example/client/udp-subnet.js"
},
"author": {
"name": "Liu Song",
"email": "[email protected]"
},
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/song940/node-dns.git"
},
"bugs": {
"url": "https://github.com/song940/node-dns/issues"
},
"devDependencies": {
"eslint": "^7.28.0",
"eslint-config-semistandard": "^15.0.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1"
},
"gitHead": "28fd77405b98081ac1efb41d0c800e827c1cf6ff",
"_id": "[email protected]",
"_nodeVersion": "19.3.0",
"_npmVersion": "9.2.0",
"dist": {
"integrity": "sha512-m27K11aQalRbmUs7RLaz6aPyceLjAoqjPRNTdE7qUouQpl+PC8Bi67O+i9SuJUPbQC8dxFrczAxfmTPuTKHNkw==",
"shasum": "15b07567befb2b914aedbb55a9ea0862c63c3d73",
"tarball": "http://localhost:4260/dns2/dns2-2.1.0.tgz",
"fileCount": 37,
"unpackedSize": 75538
},
"directories": {},
"_hasShrinkwrap": false
}
},
"homepage": "https://github.com/song940/node-dns#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/song940/node-dns.git"
},
"author": {
"name": "Liu Song",
"email": "[email protected]"
},
"bugs": {
"url": "https://github.com/song940/node-dns/issues"
},
"license": "MIT",
"readmeFilename": "README.md"
}
9 changes: 9 additions & 0 deletions tests/specs/run/resolve_dns_edns0/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"tests": {
"resolve_dns": {
"args": "test --allow-net=127.0.0.1 test.ts",
"output": "test.out",
"exitCode": 0
}
}
}
6 changes: 6 additions & 0 deletions tests/specs/run/resolve_dns_edns0/test.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[WILDCARD]
running 1 test from ./test.ts
EDNS0 enabled ... ok ([WILDCARD]s)

ok | 1 passed | 0 failed ([WILDCARD]s)

36 changes: 36 additions & 0 deletions tests/specs/run/resolve_dns_edns0/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2018-2025 the Deno authors. MIT license.
import dns2 from "npm:[email protected]";

Deno.test("EDNS0 enabled", async () => {
// With EDNS0 enabled, Deno.resolveDns can handle 44 A records.
const NUM_RECORD = 44;
const { Packet } = dns2;
const server = dns2.createServer({
udp: true,
// deno-lint-ignore no-explicit-any
handle(request: any, send: any) {
const response = Packet.createResponseFromRequest(request);
const { name } = request.questions[0];
for (const i of [...Array(NUM_RECORD).keys()]) {
response.answers.push({
name,
type: Packet.TYPE.A,
class: Packet.CLASS.IN,
ttl: 300,
address: "1.2.3." + i,
});
}
send(response);
},
});
const { udp: { port } } = await server.listen({
udp: { port: 0, address: "127.0.0.1", type: "udp4" },
});
const addr = await Deno.resolveDns("example.com", "A", {
nameServer: { ipAddr: "127.0.0.1", port },
});
if (addr.length !== NUM_RECORD) {
throw new Error(`Expected ${NUM_RECORD} records, got ${addr.length}`);
}
await server.close();
});
Loading