Use IPv4 for health and API server when configured
authorMichal Skvely <michal.sedlak@ubnt.com>
Wed, 2 Dec 2020 14:13:33 +0000 (15:13 +0100)
committerMichal Skvely <michal.sedlak@ubnt.com>
Wed, 2 Dec 2020 14:13:33 +0000 (15:13 +0100)
src/siri/api.c
src/siri/health.c

index 32ce1849c9ab9715f46c54177836f5329e3197b4..724ab5033784e11121e8d856133e01cf034359ab 100644 (file)
@@ -11,6 +11,7 @@
 #include <siri/db/query.h>
 #include <siri/db/insert.h>
 #include <siri/service/account.h>
+#include <siri/net/tcp.h>
 
 #define API__HEADER_MAX_SZ 256
 
@@ -836,7 +837,11 @@ int siri_api_init(void)
     if (port == 0)
         return 0;
 
-    (void) uv_ip6_addr("::", (int) port, (struct sockaddr_in6 *) &addr);
+    if (siri.cfg->ip_support == IP_SUPPORT_IPV4ONLY) {
+        (void) uv_ip4_addr("0.0.0.0", (int) port, (struct sockaddr_in *) &addr);
+    } else {
+        (void) uv_ip6_addr("::", (int) port, (struct sockaddr_in6 *) &addr);
+    }
 
     api__settings.on_url = api__url_cb;
     api__settings.on_header_field = api__header_field_cb;
@@ -850,7 +855,7 @@ int siri_api_init(void)
         (rc = uv_tcp_bind(
                 &api__uv_server,
                 (const struct sockaddr *) &addr,
-                0)) ||
+                (siri.cfg->ip_support == IP_SUPPORT_IPV6ONLY) ? UV_TCP_IPV6ONLY : 0)) ||
         (rc = uv_listen(
                 (uv_stream_t *) &api__uv_server,
                 128,
index 7d4c5e73c9da94834e9736d630ee15a72aa11c39..1e9957abd5b90d6f420d00cc2385739909f29fde 100644 (file)
@@ -3,6 +3,7 @@
  */
 #include <siri/health.h>
 #include <siri/siri.h>
+#include <siri/net/tcp.h>
 #include <logger/logger.h>
 
 #define OK_RESPONSE \
@@ -311,7 +312,11 @@ int siri_health_init(void)
     struct sockaddr_storage addr = {0};
     uint16_t port = siri.cfg->http_status_port;
 
-    (void) uv_ip6_addr("::", (int) port, (struct sockaddr_in6 *) &addr);
+    if (siri.cfg->ip_support == IP_SUPPORT_IPV4ONLY) {
+        (void) uv_ip4_addr("0.0.0.0", (int) port, (struct sockaddr_in *) &addr);
+    } else {
+        (void) uv_ip6_addr("::", (int) port, (struct sockaddr_in6 *) &addr);
+    }
 
     health__uv_ok_buf =
             uv_buf_init(OK_RESPONSE, strlen(OK_RESPONSE));
@@ -336,7 +341,7 @@ int siri_health_init(void)
         (rc = uv_tcp_bind(
                 &health__uv_server,
                 (const struct sockaddr *) &addr,
-                0)) ||
+                (siri.cfg->ip_support == IP_SUPPORT_IPV6ONLY) ? UV_TCP_IPV6ONLY : 0)) ||
         (rc = uv_listen(
                 (uv_stream_t *) &health__uv_server,
                 128,