Add --disable-ipv4 option to disable IPv4

pull/1166/head
Zero King 2018-03-17 12:21:56 +00:00
parent 431fcde29a
commit f9792ce1bf
16 changed files with 50 additions and 9 deletions

File diff suppressed because one or more lines are too long

View File

@ -1274,6 +1274,10 @@ Advanced Options
:option:`--deferred-input` option will be disabled when
:option:`--save-session` is used together.
.. option:: --disable-ipv4 [true|false]
Disable IPv4. Default: ``false``
.. option:: --disable-ipv6 [true|false]
Disable IPv6. This is useful if you have to use broken DNS and want

View File

@ -1145,6 +1145,10 @@ Opções Avançadas
and options at startup.
Padrão: ``false``
.. option:: --disable-ipv4 [true|false]
Disable IPv4. Padrão: ``false``
.. option:: --disable-ipv6 [true|false]
Disable IPv6. This is useful if you have to use broken DNS and want

View File

@ -1348,6 +1348,11 @@ HTTP(S)/FTP, они тут же могут выгружаться в BitTorrent-
параметр :option:`--deferred-input` будет заблокирован, если
используется вместе с :option:`--save-session`.
.. option:: --disable-ipv4 [true|false]
Отключить IPv4.
По умолчанию: ``false``
.. option:: --disable-ipv6 [true|false]
Отключить IPv6. Это полезно, если вы используете поврежденный DNS

View File

@ -808,6 +808,9 @@ std::string AbstractCommand::resolveHostname(std::vector<std::string>& addrs,
{
NameResolver res;
res.setSocktype(SOCK_STREAM);
if (e_->getOption()->getAsBool(PREF_DISABLE_IPV4)) {
res.setFamily(AF_INET6);
}
if (e_->getOption()->getAsBool(PREF_DISABLE_IPV6)) {
res.setFamily(AF_INET);
}

View File

@ -216,7 +216,7 @@ void configureAsyncNameResolverMan(AsyncNameResolverMan* asyncNameResolverMan,
if (!net::getIPv4AddrConfigured() && !net::getIPv6AddrConfigured()) {
net::checkAddrconfig();
}
if (!net::getIPv4AddrConfigured()) {
if (!net::getIPv4AddrConfigured() || option->getAsBool(PREF_DISABLE_IPV4)) {
asyncNameResolverMan->setIPv4(false);
}
if (!net::getIPv6AddrConfigured() || option->getAsBool(PREF_DISABLE_IPV6)) {

View File

@ -183,9 +183,11 @@ void BtSetup::setup(std::vector<std::unique_ptr<Command>>& commands,
}
if (btReg->getTcpPort() == 0) {
static int families[] = {AF_INET, AF_INET6};
size_t familiesLength =
size_t familiesStart =
e->getOption()->getAsBool(PREF_DISABLE_IPV4) ? 1 : 0;
size_t familiesEnd =
e->getOption()->getAsBool(PREF_DISABLE_IPV6) ? 1 : 2;
for (size_t i = 0; i < familiesLength; ++i) {
for (size_t i = familiesStart; i < familiesEnd; ++i) {
auto command =
make_unique<PeerListenCommand>(e->newCUID(), e, families[i]);
bool ret;

View File

@ -218,6 +218,9 @@ Context::Context(bool standalone, int argc, char** argv, const KeyVals& options)
}
#endif // defined(HAVE_SYS_RESOURCE_H) && defined(RLIMIT_NOFILE)
if (op->getAsBool(PREF_DISABLE_IPV4)) {
SocketCore::setProtocolFamily(AF_INET6);
}
if (op->getAsBool(PREF_DISABLE_IPV6)) {
SocketCore::setProtocolFamily(AF_INET);
}

View File

@ -206,8 +206,9 @@ std::unique_ptr<DownloadEngine> DownloadEngineFactory::newDownloadEngine(
A2_LOG_NOTICE("RPC transport will be encrypted.");
}
static int families[] = {AF_INET, AF_INET6};
size_t familiesLength = op->getAsBool(PREF_DISABLE_IPV6) ? 1 : 2;
for (size_t i = 0; i < familiesLength; ++i) {
size_t familiesStart = op->getAsBool(PREF_DISABLE_IPV4) ? 1 : 0;
size_t familiesEnd = op->getAsBool(PREF_DISABLE_IPV6) ? 1 : 2;
for (size_t i = familiesStart; i < familiesEnd; ++i) {
auto httpListenCommand = make_unique<HttpListenCommand>(
e->newCUID(), e.get(), families[i], secure);
if (httpListenCommand->bindPort(op->getAsInt(PREF_RPC_LISTEN_PORT))) {

View File

@ -137,7 +137,8 @@ InitiateConnectionCommand::createBackupIPv4ConnectCommand(
// fashion.
std::shared_ptr<BackupConnectInfo> info;
char buf[sizeof(in6_addr)];
if (inetPton(AF_INET6, ipaddr.c_str(), &buf) == -1) {
if (inetPton(AF_INET6, ipaddr.c_str(), &buf) == -1 ||
getOption()->getAsBool(PREF_DISABLE_IPV4)) {
return info;
}
A2_LOG_INFO("Searching IPv4 address for backup connection attempt");

View File

@ -105,6 +105,9 @@ bool NameResolveCommand::execute()
{
NameResolver resolver;
resolver.setSocktype(SOCK_DGRAM);
if (e_->getOption()->getAsBool(PREF_DISABLE_IPV4)) {
resolver.setFamily(AF_INET6);
}
if (e_->getOption()->getAsBool(PREF_DISABLE_IPV6)) {
resolver.setFamily(AF_INET);
}

View File

@ -211,6 +211,13 @@ std::vector<OptionHandler*> OptionHandlerFactory::createOptionHandlers()
op->setChangeOptionForReserved(true);
handlers.push_back(op);
}
{
OptionHandler* op(new BooleanOptionHandler(PREF_DISABLE_IPV4,
TEXT_DISABLE_IPV4, A2_V_FALSE,
OptionHandler::OPT_ARG));
op->addTag(TAG_ADVANCED);
handlers.push_back(op);
}
{
OptionHandler* op(new BooleanOptionHandler(PREF_DISABLE_IPV6,
TEXT_DISABLE_IPV6,

View File

@ -346,11 +346,13 @@ void RequestGroup::createInitialCommand(
downloadContext_, pieceStorage_, peerStorage, btAnnounce, btRuntime,
(progressInfoFile ? progressInfoFile : progressInfoFile_)));
if (option_->getAsBool(PREF_ENABLE_DHT) ||
if ((!e->getOption()->getAsBool(PREF_DISABLE_IPV4) &&
option_->getAsBool(PREF_ENABLE_DHT)) ||
(!e->getOption()->getAsBool(PREF_DISABLE_IPV6) &&
option_->getAsBool(PREF_ENABLE_DHT6))) {
if (option_->getAsBool(PREF_ENABLE_DHT)) {
if (!e->getOption()->getAsBool(PREF_DISABLE_IPV4) &&
option_->getAsBool(PREF_ENABLE_DHT)) {
std::vector<std::unique_ptr<Command>> c, rc;
std::tie(c, rc) = DHTSetup().setup(e, AF_INET);

View File

@ -302,6 +302,8 @@ PrefPtr PREF_INTERFACE = makePref("interface");
// value: string
PrefPtr PREF_MULTIPLE_INTERFACE = makePref("multiple-interface");
// value: true | false
PrefPtr PREF_DISABLE_IPV4 = makePref("disable-ipv4");
// value: true | false
PrefPtr PREF_DISABLE_IPV6 = makePref("disable-ipv6");
// value: true | false
PrefPtr PREF_HUMAN_READABLE = makePref("human-readable");

View File

@ -255,6 +255,8 @@ extern PrefPtr PREF_INTERFACE;
// value: string
extern PrefPtr PREF_MULTIPLE_INTERFACE;
// value: true | false
extern PrefPtr PREF_DISABLE_IPV4;
// value: true | false
extern PrefPtr PREF_DISABLE_IPV6;
// value: true | false
extern PrefPtr PREF_HUMAN_READABLE;

View File

@ -640,6 +640,8 @@
" specify interface name, IP address and hostname.\n" \
" If --interface is used, this option will be\n" \
" ignored.")
#define TEXT_DISABLE_IPV4 \
_(" --disable-ipv4[=true|false] Disable IPv4.")
#define TEXT_DISABLE_IPV6 \
_(" --disable-ipv6[=true|false] Disable IPv6.")
#define TEXT_BT_SAVE_METADATA \