Skip to content

Commit 377dbd3

Browse files
authored
Merge pull request #8961 from Icinga/bugfix/apilistener-detect-ipv6-support
ApiListener: Choose bind host default based on OS IPv6 support (2.13)
2 parents aaccd04 + ec73b41 commit 377dbd3

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

doc/09-object-types.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,7 @@ Configuration Attributes:
10951095
ca\_path | String | **Deprecated.** Path to the CA certificate file.
10961096
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.
10971097
crl\_path | String | **Optional.** Path to the CRL file.
1098-
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.
1098+
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.
10991099
bind\_port | Number | **Optional.** The port the api listener should be bound to. Defaults to `5665`.
11001100
accept\_config | Boolean | **Optional.** Accept zone configuration. Defaults to `false`.
11011101
accept\_commands | Boolean | **Optional.** Accept remote commands. Defaults to `false`.

doc/17-language-reference.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ Environment |**Read-write.** The name of the Icinga environment. Include
504504
RunAsUser |**Read-write.** Defines the user the Icinga 2 daemon is running as. Set in the Icinga 2 sysconfig.
505505
RunAsGroup |**Read-write.** Defines the group the Icinga 2 daemon is running as. Set in the Icinga 2 sysconfig.
506506
MaxConcurrentChecks |**Read-write.** The number of max checks run simultaneously. Defaults to `512`.
507-
ApiBindHost |**Read-write.** Overrides the default value for the ApiListener `bind_host` attribute. Defaults to `::`.
507+
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.
508508
ApiBindPort |**Read-write.** Overrides the default value for the ApiListener `bind_port` attribute. Not set by default.
509509

510510
#### Application Runtime Constants <a id="icinga-constants-application-runtime"></a>

lib/base/configuration.cpp

+14-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,20 @@ using namespace icinga;
88

99
REGISTER_TYPE(Configuration);
1010

11-
String Configuration::ApiBindHost{"::"};
11+
String Configuration::ApiBindHost = []() {
12+
#ifndef _WIN32
13+
// Automatically fall back to an IPv4 default if socket() tells us that IPv6 is not supported.
14+
int fd = socket(AF_INET6, SOCK_STREAM, 0);
15+
if (fd < 0 && errno == EAFNOSUPPORT) {
16+
return "0.0.0.0";
17+
} else if (fd >= 0) {
18+
close(fd);
19+
}
20+
#endif /* _WIN32 */
21+
22+
return "::";
23+
}();
24+
1225
String Configuration::ApiBindPort{"5665"};
1326
bool Configuration::AttachDebugger{false};
1427
String Configuration::CacheDir;

0 commit comments

Comments
 (0)