ApiListener: Choose bind host default based on OS IPv6 support

This commit is contained in:
Julian Brost 2021-08-06 10:43:38 +02:00
parent aaccd0448f
commit ec73b417f2
3 changed files with 16 additions and 3 deletions

View File

@ -1095,7 +1095,7 @@ Configuration Attributes:
ca\_path | String | **Deprecated.** Path to the CA certificate file.
ticket\_salt | String | **Optional.** Private key for [CSR auto-signing](06-distributed-monitoring.md#distributed-monitoring-setup-csr-auto-signing). **Required** for a signing master instance.
crl\_path | String | **Optional.** Path to the CRL file.
bind\_host | String | **Optional.** The IP address the api listener should be bound to. If not specified, the ApiListener is bound to `::` and listens for both IPv4 and IPv6 connections.
bind\_host | String | **Optional.** The IP address the api listener should be bound to. If not specified, the ApiListener is bound to `::` and listens for both IPv4 and IPv6 connections or to `0.0.0.0` if IPv6 is not supported by the operating system.
bind\_port | Number | **Optional.** The port the api listener should be bound to. Defaults to `5665`.
accept\_config | Boolean | **Optional.** Accept zone configuration. Defaults to `false`.
accept\_commands | Boolean | **Optional.** Accept remote commands. Defaults to `false`.

View File

@ -504,7 +504,7 @@ Environment |**Read-write.** The name of the Icinga environment. Include
RunAsUser |**Read-write.** Defines the user the Icinga 2 daemon is running as. Set in the Icinga 2 sysconfig.
RunAsGroup |**Read-write.** Defines the group the Icinga 2 daemon is running as. Set in the Icinga 2 sysconfig.
MaxConcurrentChecks |**Read-write.** The number of max checks run simultaneously. Defaults to `512`.
ApiBindHost |**Read-write.** Overrides the default value for the ApiListener `bind_host` attribute. Defaults to `::`.
ApiBindHost |**Read-write.** Overrides the default value for the ApiListener `bind_host` attribute. Defaults to `::` if IPv6 is supported by the operating system and to `0.0.0.0` otherwise.
ApiBindPort |**Read-write.** Overrides the default value for the ApiListener `bind_port` attribute. Not set by default.
#### Application Runtime Constants <a id="icinga-constants-application-runtime"></a>

View File

@ -8,7 +8,20 @@ using namespace icinga;
REGISTER_TYPE(Configuration);
String Configuration::ApiBindHost{"::"};
String Configuration::ApiBindHost = []() {
#ifndef _WIN32
// Automatically fall back to an IPv4 default if socket() tells us that IPv6 is not supported.
int fd = socket(AF_INET6, SOCK_STREAM, 0);
if (fd < 0 && errno == EAFNOSUPPORT) {
return "0.0.0.0";
} else if (fd >= 0) {
close(fd);
}
#endif /* _WIN32 */
return "::";
}();
String Configuration::ApiBindPort{"5665"};
bool Configuration::AttachDebugger{false};
String Configuration::CacheDir;