]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
Create sockets only in selected family with -4 or -6 option
authorMiroslav Lichvar <mlichvar@redhat.com>
Mon, 20 May 2013 13:34:33 +0000 (15:34 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Mon, 20 May 2013 13:37:25 +0000 (15:37 +0200)
chrony.texi.in
chronyd.8.in
cmdmon.c
cmdmon.h
main.c
ntp_io.c
ntp_io.h

index 977a5640dac784b840bfe057d8e5acf62cbf752f..d8bdeb988aeb10c55ab26f3ee87dcf9d3fabe9e7 100644 (file)
@@ -1097,9 +1097,11 @@ supported only on Linux.
 This option will lock chronyd into RAM so that it will never be paged
 out.  This mode is only supported on Linux.
 @item -4
-With this option hostnames will be resolved only to IPv4 addresses.
+With this option hostnames will be resolved only to IPv4 addresses and only
+IPv4 sockets will be created.
 @item -6
-With this option hostnames will be resolved only to IPv6 addresses.
+With this option hostnames will be resolved only to IPv6 addresses and only
+IPv6 sockets will be created.
 @end table
 
 On systems that support an @file{/etc/rc.local} file for starting
index dc7a7d732794c2481aaeca46ec4e4047812b07c4..94471e6bf54a38fd3715bfc266cc527eb716ed91 100644 (file)
@@ -106,10 +106,10 @@ user.  So far, it works only on Linux when compiled with capabilities support.
 This option displays \fBchronyd\fR's version number to the terminal and exits
 .TP
 .B \-4
-Resolve hostnames only to IPv4 addresses.
+Resolve hostnames only to IPv4 addresses and create only IPv4 sockets.
 .TP
 .B \-6
-Resolve hostnames only to IPv6 addresses.
+Resolve hostnames only to IPv6 addresses and create only IPv6 sockets.
 
 .SH FILES
 \fI@SYSCONFDIR@/chrony.conf\fR
index d58e0f15843a13a5e48413ec192b97199f9e0a45..7c283bcb1342cba9a7a6785b82f9f038e4e8e454 100644 (file)
--- a/cmdmon.c
+++ b/cmdmon.c
@@ -262,7 +262,7 @@ prepare_socket(int family)
 /* ================================================== */
 
 void
-CAM_Initialise(void)
+CAM_Initialise(int family)
 {
   assert(!initialised);
   initialised = 1;
@@ -278,9 +278,15 @@ CAM_Initialise(void)
   free_replies = NULL;
   kept_replies.next = NULL;
 
-  sock_fd4 = prepare_socket(AF_INET);
+  if (family == IPADDR_UNSPEC || family == IPADDR_INET4)
+    sock_fd4 = prepare_socket(AF_INET);
+  else
+    sock_fd4 = -1;
 #ifdef HAVE_IPV6
-  sock_fd6 = prepare_socket(AF_INET6);
+  if (family == IPADDR_UNSPEC || family == IPADDR_INET6)
+    sock_fd6 = prepare_socket(AF_INET6);
+  else
+    sock_fd6 = -1;
 #endif
 
   if (sock_fd4 < 0
index ab505a1613a0d619d7fc9d75513862879c25b42f..ac337e7e9c20aa2e33f9b099580fff22c648f293 100644 (file)
--- a/cmdmon.h
+++ b/cmdmon.h
@@ -29,7 +29,7 @@
 
 #include "addressing.h"
 
-extern void CAM_Initialise(void);
+extern void CAM_Initialise(int family);
 
 extern void CAM_Finalise(void);
 
diff --git a/main.c b/main.c
index 59c3be5709beff4effc7ed958c28cd0295ff7dbf..2fe96faff128448655d5b5d8c54b58a53d93e050 100644 (file)
--- a/main.c
+++ b/main.c
@@ -286,7 +286,7 @@ int main
 {
   const char *conf_file = DEFAULT_CONF_FILE;
   char *user = NULL;
-  int debug = 0, nofork = 0;
+  int debug = 0, nofork = 0, address_family = IPADDR_UNSPEC;
   int do_init_rtc = 0, restarted = 0;
   int other_pid;
   int lock_memory = 0, sched_priority = 0;
@@ -329,9 +329,9 @@ int main
       debug = 1;
       nofork = 1;
     } else if (!strcmp("-4", *argv)) {
-      DNS_SetAddressFamily(IPADDR_INET4);
+      address_family = IPADDR_INET4;
     } else if (!strcmp("-6", *argv)) {
-      DNS_SetAddressFamily(IPADDR_INET6);
+      address_family = IPADDR_INET6;
     } else {
       LOG_FATAL(LOGF_Main, "Unrecognized command line option [%s]", *argv);
     }
@@ -354,6 +354,8 @@ int main
   
   LOG(LOGS_INFO, LOGF_Main, "chronyd version %s starting", CHRONY_VERSION);
 
+  DNS_SetAddressFamily(address_family);
+
   CNF_SetRestarted(restarted);
   CNF_ReadFile(conf_file);
 
@@ -376,8 +378,8 @@ int main
   LCL_Initialise();
   SCH_Initialise();
   SYS_Initialise();
-  NIO_Initialise();
-  CAM_Initialise();
+  NIO_Initialise(address_family);
+  CAM_Initialise(address_family);
   RTC_Initialise();
   SRC_Initialise();
   RCL_Initialise();
index 57e979b907bbd4918d5dfcaf6de891274326ab74..a983d8698df73cb880d7644fc01c89b80346b9ef 100644 (file)
--- a/ntp_io.c
+++ b/ntp_io.c
@@ -231,17 +231,25 @@ prepare_socket(int family)
   return sock_fd;
 }
 
+/* ================================================== */
+
 void
-NIO_Initialise(void)
+NIO_Initialise(int family)
 {
   assert(!initialised);
   initialised = 1;
 
   do_size_checks();
 
-  sock_fd4 = prepare_socket(AF_INET);
+  if (family == IPADDR_UNSPEC || family == IPADDR_INET4)
+    sock_fd4 = prepare_socket(AF_INET);
+  else
+    sock_fd4 = -1;
 #ifdef HAVE_IPV6
-  sock_fd6 = prepare_socket(AF_INET6);
+  if (family == IPADDR_UNSPEC || family == IPADDR_INET6)
+    sock_fd6 = prepare_socket(AF_INET6);
+  else
+    sock_fd6 = -1;
 #endif
 
   if (sock_fd4 < 0
index 231568bad527e80b6c1affe10b36668d48ae5927..cbbe63873b42174f64f70926ce55750989d9e664 100644 (file)
--- a/ntp_io.h
+++ b/ntp_io.h
@@ -32,7 +32,7 @@
 #include "addressing.h"
 
 /* Function to initialise the module. */
-extern void NIO_Initialise(void);
+extern void NIO_Initialise(int family);
 
 /* Function to finalise the module */
 extern void NIO_Finalise(void);