From 33a25b29a4d654f5c2a5c74725862bccb2fcccfb Mon Sep 17 00:00:00 2001 From: Ouyang Yadong Date: Sun, 21 Oct 2018 15:59:38 +0800 Subject: net,dgram: add ipv6Only option for net and dgram For TCP servers, the dual-stack support is enable by default, i.e. binding host "::" will also make "0.0.0.0" bound. This commit add ipv6Only option in `net.Server.listen()` and `dgram.createSocket()` methods which allows to disable dual-stack support. Support for cluster module is also provided in this commit. Fixes: https://github.com/nodejs/node/issues/17664 PR-URL: https://github.com/nodejs/node/pull/23798 Reviewed-By: Ben Noordhuis Reviewed-By: James M Snell --- lib/dgram.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'lib/dgram.js') diff --git a/lib/dgram.js b/lib/dgram.js index 549b6dd738..55662313d6 100644 --- a/lib/dgram.js +++ b/lib/dgram.js @@ -54,7 +54,11 @@ const { } = require('internal/async_hooks'); const { UV_UDP_REUSEADDR } = internalBinding('constants').os; -const { UDP, SendWrap } = internalBinding('udp_wrap'); +const { + constants: { UV_UDP_IPV6ONLY }, + UDP, + SendWrap +} = internalBinding('udp_wrap'); const BIND_STATE_UNBOUND = 0; const BIND_STATE_BINDING = 1; @@ -99,6 +103,7 @@ function Socket(type, listener) { bindState: BIND_STATE_UNBOUND, queue: undefined, reuseAddr: options && options.reuseAddr, // Use UV_UDP_REUSEADDR if true. + ipv6Only: options && options.ipv6Only, recvBufferSize, sendBufferSize }; @@ -270,6 +275,8 @@ Socket.prototype.bind = function(port_, address_ /* , callback */) { var flags = 0; if (state.reuseAddr) flags |= UV_UDP_REUSEADDR; + if (state.ipv6Only) + flags |= UV_UDP_IPV6ONLY; if (cluster.isWorker && !exclusive) { bindServerHandle(this, { -- cgit v1.2.3