-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dgram: add IPv6 scope id suffix to received udp6 dgrams
Add IPv6 link local scope ID suffix to the rinfo address in those received upd6 datagrams whose source address is a link local address. Add a new test case, test-dgram-udp6-link-local-address, to verify that IPv6 UDP datagrams received from a link-local source address do contain the scope ID suffix in the rinfo address field. When a packet is received from a link-local source address, if the address does not contain the scope ID suffix, it is impossible to reply back to the sender, as the kernel is not able to determine the right network interface to send the packet through and returns with an error. Ref: #1649 PR-URL: #14500 Refs: #1649 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Stewart X Addison <[email protected]>
- Loading branch information
1 parent
f4d61c7
commit 02ae6d6
Showing
3 changed files
with
71 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
if (!common.hasIPv6) | ||
common.skip('no IPv6 support'); | ||
|
||
const assert = require('assert'); | ||
const dgram = require('dgram'); | ||
const os = require('os'); | ||
|
||
function linklocal() { | ||
for (const [ifname, entries] of Object.entries(os.networkInterfaces())) { | ||
for (const { address, family, scopeid } of entries) { | ||
if (family === 'IPv6' && address.startsWith('fe80:')) { | ||
return { address, ifname, scopeid }; | ||
} | ||
} | ||
} | ||
} | ||
const iface = linklocal(); | ||
|
||
if (!iface) | ||
common.skip('cannot find any IPv6 interfaces with a link local address'); | ||
|
||
const address = `${iface.address}%${iface.ifname}`; | ||
const message = 'Hello, local world!'; | ||
|
||
// Create a client socket for sending to the link-local address. | ||
const client = dgram.createSocket('udp6'); | ||
|
||
// Create the server socket listening on the link-local address. | ||
const server = dgram.createSocket('udp6'); | ||
|
||
server.on('listening', common.mustCall(() => { | ||
const port = server.address().port; | ||
client.send(message, 0, message.length, port, address); | ||
})); | ||
|
||
server.on('message', common.mustCall((buf, info) => { | ||
const received = buf.toString(); | ||
assert.strictEqual(received, message); | ||
// Check that the sender address is the one bound, | ||
// including the link local scope identifier. | ||
assert.strictEqual( | ||
info.address, | ||
common.isWindows ? `${iface.address}%${iface.scopeid}` : address | ||
); | ||
server.close(); | ||
client.close(); | ||
}, 1)); | ||
|
||
server.bind({ address }); |