diff --git a/ext/net/ops.rs b/ext/net/ops.rs index 768dd33135..c4eb56af2f 100644 --- a/ext/net/ops.rs +++ b/ext/net/ops.rs @@ -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( @@ -662,6 +662,8 @@ where system_conf::read_system_conf()? }; + opts.edns0 = true; + { let mut s = state.borrow_mut(); let perm = s.borrow_mut::(); diff --git a/tests/registry/npm/dns2/dns2-2.1.0.tgz b/tests/registry/npm/dns2/dns2-2.1.0.tgz new file mode 100644 index 0000000000..1f825e4b1d Binary files /dev/null and b/tests/registry/npm/dns2/dns2-2.1.0.tgz differ diff --git a/tests/registry/npm/dns2/registry.json b/tests/registry/npm/dns2/registry.json new file mode 100644 index 0000000000..9397b42d39 --- /dev/null +++ b/tests/registry/npm/dns2/registry.json @@ -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": "song940@gmail.com" + }, + "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": "dns2@2.1.0", + "_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": "song940@gmail.com" + }, + "bugs": { + "url": "https://github.com/song940/node-dns/issues" + }, + "license": "MIT", + "readmeFilename": "README.md" +} diff --git a/tests/specs/run/resolve_dns_edns0/__test__.jsonc b/tests/specs/run/resolve_dns_edns0/__test__.jsonc new file mode 100644 index 0000000000..9124ee2593 --- /dev/null +++ b/tests/specs/run/resolve_dns_edns0/__test__.jsonc @@ -0,0 +1,9 @@ +{ + "tests": { + "resolve_dns": { + "args": "test --allow-net=127.0.0.1 test.ts", + "output": "test.out", + "exitCode": 0 + } + } +} diff --git a/tests/specs/run/resolve_dns_edns0/test.out b/tests/specs/run/resolve_dns_edns0/test.out new file mode 100644 index 0000000000..6a1929401e --- /dev/null +++ b/tests/specs/run/resolve_dns_edns0/test.out @@ -0,0 +1,6 @@ +[WILDCARD] +running 1 test from ./test.ts +EDNS0 enabled ... ok ([WILDCARD]s) + +ok | 1 passed | 0 failed ([WILDCARD]s) + diff --git a/tests/specs/run/resolve_dns_edns0/test.ts b/tests/specs/run/resolve_dns_edns0/test.ts new file mode 100644 index 0000000000..070b4dbaeb --- /dev/null +++ b/tests/specs/run/resolve_dns_edns0/test.ts @@ -0,0 +1,36 @@ +// Copyright 2018-2025 the Deno authors. MIT license. +import dns2 from "npm:dns2@2.1.0"; + +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(); +});