diff options
author | Sara Golemon <sara.golemon@mongodb.com> | 2018-09-12 18:27:59 +0000 |
---|---|---|
committer | Sara Golemon <sara.golemon@mongodb.com> | 2018-09-17 17:38:36 +0000 |
commit | 5c71b34bbe40040272f1174508366ff8a5668cbc (patch) | |
tree | a0e8a79d4676ab3ba1e01bfed5238e42bd9179ee | |
parent | 9011c8cff2985a1f60d558f62fe0d712b48b9b99 (diff) | |
download | mongo-5c71b34bbe40040272f1174508366ff8a5668cbc.tar.gz |
SERVER-36572 Canonicalize bindIpAll to bindIp=='*'
-rw-r--r-- | jstests/noPassthrough/bind_ip_all.js | 23 | ||||
-rw-r--r-- | jstests/noPassthrough/libs/net.bindIpAll.yaml | 2 | ||||
-rw-r--r-- | jstests/noPassthrough/libs/net.bindIp_localhost.yaml | 2 | ||||
-rw-r--r-- | src/mongo/db/server_options_server_helpers.cpp | 44 |
4 files changed, 52 insertions, 19 deletions
diff --git a/jstests/noPassthrough/bind_ip_all.js b/jstests/noPassthrough/bind_ip_all.js new file mode 100644 index 00000000000..e840cb2e404 --- /dev/null +++ b/jstests/noPassthrough/bind_ip_all.js @@ -0,0 +1,23 @@ +// Startup with --bind_ip_all should override net.bindIp and vice versa. + +(function() { + 'use strict'; + + const port = allocatePort(); + const BINDIP = 'jstests/noPassthrough/libs/net.bindIp_localhost.yaml'; + const BINDIPALL = 'jstests/noPassthrough/libs/net.bindIpAll.yaml'; + + function runTest(config, opt, expectStar, expectLocalhost) { + clearRawMongoProgramOutput(); + const mongod = + runMongoProgram('./mongod', '--port', port, '--config', config, opt, '--outputConfig'); + assert.eq(mongod, 0); + const output = rawMongoProgramOutput(); + assert.eq(output.search(/bindIp: "\*"/) >= 0, expectStar, output); + assert.eq(output.search(/bindIp: localhost/) >= 0, expectLocalhost, output); + assert.eq(output.search(/bindIpAll:/) >= 0, false, output); + } + + runTest(BINDIP, '--bind_ip_all', true, false); + runTest(BINDIPALL, '--bind_ip=localhost', false, true); +}()); diff --git a/jstests/noPassthrough/libs/net.bindIpAll.yaml b/jstests/noPassthrough/libs/net.bindIpAll.yaml new file mode 100644 index 00000000000..22ad5e7842a --- /dev/null +++ b/jstests/noPassthrough/libs/net.bindIpAll.yaml @@ -0,0 +1,2 @@ +net: + bindIpAll: true diff --git a/jstests/noPassthrough/libs/net.bindIp_localhost.yaml b/jstests/noPassthrough/libs/net.bindIp_localhost.yaml new file mode 100644 index 00000000000..61de93d131f --- /dev/null +++ b/jstests/noPassthrough/libs/net.bindIp_localhost.yaml @@ -0,0 +1,2 @@ +net: + bindIp: localhost diff --git a/src/mongo/db/server_options_server_helpers.cpp b/src/mongo/db/server_options_server_helpers.cpp index 97d396567eb..6ba968ad126 100644 --- a/src/mongo/db/server_options_server_helpers.cpp +++ b/src/mongo/db/server_options_server_helpers.cpp @@ -116,17 +116,22 @@ Status addGeneralServerOptions(moe::OptionSection* options) { .setSources(moe::SourceCommandLine) .hidden(); - options - ->addOptionChaining( - "net.bindIp", - "bind_ip", - moe::String, - "comma separated list of ip addresses to listen on - localhost by default") - .incompatibleWith("bind_ip_all"); + options->addOptionChaining( + "net.bindIp", + "bind_ip", + moe::String, + "comma separated list of ip addresses to listen on - localhost by default"); options ->addOptionChaining("net.bindIpAll", "bind_ip_all", moe::Switch, "bind to all ip addresses") - .incompatibleWith("bind_ip"); + .canonicalize([](moe::Environment* env) { + bool all = (*env)["net.bindIpAll"].as<bool>(); + auto status = env->remove("net.bindIpAll"); + if (!status.isOK()) { + return status; + } + return all ? env->set("net.bindIp", moe::Value("*")) : Status::OK(); + }); options->addOptionChaining( "net.ipv6", "ipv6", moe::Switch, "enable IPv6 support (disabled by default)"); @@ -641,18 +646,19 @@ Status storeServerOptions(const moe::Environment& params) { serverGlobalParams.objcheck = params["net.wireObjectCheck"].as<bool>(); } - if (params.count("net.bindIpAll") && params["net.bindIpAll"].as<bool>()) { - // Bind to all IP addresses - serverGlobalParams.bind_ips.emplace_back("0.0.0.0"); - if (params.count("net.ipv6") && params["net.ipv6"].as<bool>()) { - serverGlobalParams.bind_ips.emplace_back("::"); - } - } else if (params.count("net.bindIp")) { + if (params.count("net.bindIp")) { std::string bind_ip = params["net.bindIp"].as<std::string>(); - boost::split(serverGlobalParams.bind_ips, - bind_ip, - [](char c) { return c == ','; }, - boost::token_compress_on); + if (bind_ip == "*") { + serverGlobalParams.bind_ips.emplace_back("0.0.0.0"); + if (params.count("net.ipv6") && params["net.ipv6"].as<bool>()) { + serverGlobalParams.bind_ips.emplace_back("::"); + } + } else { + boost::split(serverGlobalParams.bind_ips, + bind_ip, + [](char c) { return c == ','; }, + boost::token_compress_on); + } } for (auto& ip : serverGlobalParams.bind_ips) { |