]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
socket: add function to check supported family
authorMiroslav Lichvar <mlichvar@redhat.com>
Fri, 3 Jan 2020 08:36:59 +0000 (09:36 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Fri, 3 Jan 2020 10:47:41 +0000 (11:47 +0100)
Don't log error when an IPv6 socket cannot be opened and chronyd was
built without IPv6 support.

Reported-by: Lonnie Abelbeck <lonnie@abelbeck.com>
cmdmon.c
ntp_io.c
socket.c
socket.h

index ce5c719788c78193763c021743c53ff778e21d88..ba6e9857ce6d625f20401b23e2f3fc76e3a26fc4 100644 (file)
--- a/cmdmon.c
+++ b/cmdmon.c
@@ -159,7 +159,7 @@ open_socket(int family)
     case IPADDR_INET4:
     case IPADDR_INET6:
       port = CNF_GetCommandPort();
-      if (port == 0)
+      if (port == 0 || !SCK_IsFamilySupported(family))
         return INVALID_SOCK_FD;
 
       CNF_GetBindCommandAddress(family, &local_addr.ip_addr);
index 4d9699db0dc78e8cd764e37895c644bc890dc63d..7a70ff4a1404ceeb20c5ce2cfb4d2542b9e6cda5 100644 (file)
--- a/ntp_io.c
+++ b/ntp_io.c
@@ -86,6 +86,9 @@ open_socket(int family, int local_port, int client_only, IPSockAddr *remote_addr
   int sock_fd, sock_flags, events = SCH_FILE_INPUT;
   IPSockAddr local_addr;
 
+  if (!SCK_IsFamilySupported(family))
+    return INVALID_SOCK_FD;
+
   if (!client_only)
     CNF_GetBindAddress(family, &local_addr.ip_addr);
   else
index 466727f173751cb3213e048eb5c74c32e6b38df1..677a1425ea884b83ba65ac2a0b8b72821b78d382 100644 (file)
--- a/socket.c
+++ b/socket.c
@@ -1115,6 +1115,23 @@ SCK_Finalise(void)
 
 /* ================================================== */
 
+int
+SCK_IsFamilySupported(int family)
+{
+  switch (family) {
+    case IPADDR_INET4:
+      return 1;
+    case IPADDR_INET6:
+#ifdef FEAT_IPV6
+      return 1;
+#endif
+    default:
+      return 0;
+  }
+}
+
+/* ================================================== */
+
 void
 SCK_GetAnyLocalIPAddress(int family, IPAddr *local_addr)
 {
index 823dfb6b125a862a65536e15a0b2b6a360d80bd0..ee44526631dcfa0482a0ba4a1f2f9a2cd9211132 100644 (file)
--- a/socket.h
+++ b/socket.h
@@ -82,6 +82,9 @@ extern void SCK_Initialise(void);
 /* Finalisation function */
 extern void SCK_Finalise(void);
 
+/* Check if support for the IP family was enabled in the build */
+extern int SCK_IsFamilySupported(int family);
+
 /* Get the 0.0.0.0/::0 or 127.0.0.1/::1 address */
 extern void SCK_GetAnyLocalIPAddress(int family, IPAddr *local_addr);
 extern void SCK_GetLoopbackIPAddress(int family, IPAddr *local_addr);