Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPekka Nikander <pekka.nikander@iki.fi>2017-07-26 14:49:21 +0300
committerStewart Addison <sxa@uk.ibm.com>2020-07-21 13:59:50 +0300
commitbdf6827edcaea80dee719cd70647d983a3438b6d (patch)
treed6cec2ca3b42d601f06a7a684d724929d48cfcc0 /src/tcp_wrap.cc
parent2c05beeb54cef998fc11933936e18094ec3c540f (diff)
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: https://github.com/nodejs/node/issues/1649 PR-URL: https://github.com/nodejs/node/pull/14500 Refs: https://github.com/nodejs/node/issues/1649 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Stewart X Addison <sxa@uk.ibm.com>
Diffstat (limited to 'src/tcp_wrap.cc')
-rw-r--r--src/tcp_wrap.cc15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/tcp_wrap.cc b/src/tcp_wrap.cc
index ef1b80939e9..fa45bd118d4 100644
--- a/src/tcp_wrap.cc
+++ b/src/tcp_wrap.cc
@@ -337,9 +337,10 @@ Local<Object> AddressToJS(Environment* env,
const sockaddr* addr,
Local<Object> info) {
EscapableHandleScope scope(env->isolate());
- char ip[INET6_ADDRSTRLEN];
+ char ip[INET6_ADDRSTRLEN + UV_IF_NAMESIZE];
const sockaddr_in* a4;
const sockaddr_in6* a6;
+
int port;
if (info.IsEmpty())
@@ -349,6 +350,18 @@ Local<Object> AddressToJS(Environment* env,
case AF_INET6:
a6 = reinterpret_cast<const sockaddr_in6*>(addr);
uv_inet_ntop(AF_INET6, &a6->sin6_addr, ip, sizeof ip);
+ // Add an interface identifier to a link local address.
+ if (IN6_IS_ADDR_LINKLOCAL(&a6->sin6_addr)) {
+ const size_t addrlen = strlen(ip);
+ CHECK_LT(addrlen, sizeof(ip));
+ ip[addrlen] = '%';
+ size_t scopeidlen = sizeof(ip) - addrlen - 1;
+ CHECK_GE(scopeidlen, UV_IF_NAMESIZE);
+ const int r = uv_if_indextoiid(a6->sin6_scope_id,
+ ip + addrlen + 1,
+ &scopeidlen);
+ CHECK_EQ(r, 0);
+ }
port = ntohs(a6->sin6_port);
info->Set(env->context(),
env->address_string(),