Skip to content

Commit 15b5b21

Browse files
committed
test: fix link-local dgram scope assertion
AIX can report lo0 as the scope ID for a datagram sent to a local interface. Validate that the received address includes a non-empty scope ID and verify that the address can be used to reply, instead of requiring the scope ID to match the destination interface. Refs: #46792 Assisted-by: Codex Signed-off-by: Filip Skokan <panva.ip@gmail.com> PR-URL: #65629 Refs: #46792 Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 6cff903 commit 15b5b21

1 file changed

Lines changed: 17 additions & 10 deletions

File tree

test/parallel/test-dgram-udp6-link-local-address.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ const { isWindows } = common;
1111

1212
function linklocal() {
1313
for (const [ifname, entries] of Object.entries(os.networkInterfaces())) {
14-
for (const { address, family, scopeid } of entries) {
14+
for (const { address, family } of entries) {
1515
if (family === 'IPv6' && address.startsWith('fe80:')) {
16-
return { address, ifname, scopeid };
16+
return { address, ifname };
1717
}
1818
}
1919
}
@@ -32,6 +32,12 @@ const client = dgram.createSocket('udp6');
3232
// Create the server socket listening on the link-local address.
3333
const server = dgram.createSocket('udp6');
3434

35+
client.on('message', common.mustCall((buf) => {
36+
assert.strictEqual(buf.toString(), message);
37+
server.close();
38+
client.close();
39+
}));
40+
3541
server.on('listening', common.mustCall(() => {
3642
const port = server.address().port;
3743
client.send(message, 0, message.length, port, address);
@@ -40,14 +46,15 @@ server.on('listening', common.mustCall(() => {
4046
server.on('message', common.mustCall((buf, info) => {
4147
const received = buf.toString();
4248
assert.strictEqual(received, message);
43-
// Check that the sender address is the one bound,
44-
// including the link local scope identifier.
45-
assert.strictEqual(
46-
info.address,
47-
isWindows ? `${iface.address}%${iface.scopeid}` : address
48-
);
49-
server.close();
50-
client.close();
49+
// AIX may use `lo0` as the scope ID for a datagram sent to a local interface.
50+
// See https://github.com/nodejs/node/issues/46792#issuecomment-1455049522.
51+
const scopeIndex = info.address.lastIndexOf('%');
52+
assert.notStrictEqual(scopeIndex, -1);
53+
assert.strictEqual(info.address.slice(0, scopeIndex), iface.address);
54+
assert.notStrictEqual(info.address.slice(scopeIndex + 1), '');
55+
56+
// Verify that the scoped sender address can be used for a reply.
57+
server.send(buf, info.port, info.address);
5158
}, 1));
5259

5360
server.bind({ address });

0 commit comments

Comments
 (0)