]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
conf: return hwtimestamp data in struct
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 19 Jan 2017 11:11:32 +0000 (12:11 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Mon, 23 Jan 2017 14:58:55 +0000 (15:58 +0100)
conf.c
conf.h
ntp_io.c
ntp_io_linux.c

diff --git a/conf.c b/conf.c
index 98cb2994814b72da6aed23a9eaa8450652d5503a..e2376b3af9221c01e24ab635efeee5d9f10fcd50 100644 (file)
--- a/conf.c
+++ b/conf.c
@@ -223,13 +223,7 @@ static char *leapsec_tz = NULL;
 /* Name of the user to which will be dropped root privileges. */
 static char *user;
 
-typedef struct {
-  char *name;
-  double tx_comp;
-  double rx_comp;
-} HwTs_Interface;
-
-/* Array of HwTs_Interface */
+/* Array of CNF_HwTsInterface */
 static ARR_Instance hwts_interfaces;
 
 typedef struct {
@@ -333,7 +327,7 @@ CNF_Initialise(int r)
 {
   restarted = r;
 
-  hwts_interfaces = ARR_CreateInstance(sizeof (HwTs_Interface));
+  hwts_interfaces = ARR_CreateInstance(sizeof (CNF_HwTsInterface));
 
   init_sources = ARR_CreateInstance(sizeof (IPAddr));
   ntp_sources = ARR_CreateInstance(sizeof (NTP_Source));
@@ -360,7 +354,7 @@ CNF_Finalise(void)
   unsigned int i;
 
   for (i = 0; i < ARR_GetSize(hwts_interfaces); i++)
-    Free(((HwTs_Interface *)ARR_GetElement(hwts_interfaces, i))->name);
+    Free(((CNF_HwTsInterface *)ARR_GetElement(hwts_interfaces, i))->name);
   ARR_DestroyInstance(hwts_interfaces);
 
   for (i = 0; i < ARR_GetSize(ntp_sources); i++)
@@ -1251,7 +1245,7 @@ parse_tempcomp(char *line)
 static void
 parse_hwtimestamp(char *line)
 {
-  HwTs_Interface *iface;
+  CNF_HwTsInterface *iface;
   char *p;
   int n;
 
@@ -1968,17 +1962,11 @@ CNF_GetInitStepThreshold(void)
 /* ================================================== */
 
 int
-CNF_GetHwTsInterface(unsigned int index, char **name, double *tx_comp, double *rx_comp)
+CNF_GetHwTsInterface(unsigned int index, CNF_HwTsInterface **iface)
 {
-  HwTs_Interface *iface;
-
   if (index >= ARR_GetSize(hwts_interfaces))
     return 0;
 
-  iface = ARR_GetElement(hwts_interfaces, index);
-  *name = iface->name;
-  *tx_comp = iface->tx_comp;
-  *rx_comp = iface->rx_comp;
-
+  *iface = (CNF_HwTsInterface *)ARR_GetElement(hwts_interfaces, index);
   return 1;
 }
diff --git a/conf.h b/conf.h
index a24b8d9f6beece0397198e94dfd30ae9bed1f1f5..6bfdf7fc67a4b27a2f08bb0641ed41395bc7093c 100644 (file)
--- a/conf.h
+++ b/conf.h
@@ -119,6 +119,12 @@ extern char *CNF_GetHwclockFile(void);
 extern int CNF_GetInitSources(void);
 extern double CNF_GetInitStepThreshold(void);
 
-extern int CNF_GetHwTsInterface(unsigned int index, char **name, double *tx_comp, double *rx_comp);
+typedef struct {
+  char *name;
+  double tx_comp;
+  double rx_comp;
+} CNF_HwTsInterface;
+
+extern int CNF_GetHwTsInterface(unsigned int index, CNF_HwTsInterface **iface);
 
 #endif /* GOT_CONF_H */
index 884344977607e2a16137a508b172acb5ba0af423..05e7988752c839054c41c00ef3f7245bcad3957e 100644 (file)
--- a/ntp_io.c
+++ b/ntp_io.c
@@ -365,9 +365,8 @@ NIO_Initialise(int family)
   NIO_Linux_Initialise();
 #else
   if (1) {
-    double tx_comp, rx_comp;
-    char *name;
-    if (CNF_GetHwTsInterface(0, &name, &tx_comp, &rx_comp))
+    CNF_HwTsInterface *conf_iface;
+    if (CNF_GetHwTsInterface(0, &conf_iface))
       LOG_FATAL(LOGF_NtpIO, "HW timestamping not supported");
   }
 #endif
index 64f41adb4937cfdab073fbaa6fd130297f734d5c..0e2b438fcba294d43b2f2219e196d9cb6e798f13 100644 (file)
@@ -91,7 +91,7 @@ static int permanent_ts_options;
 /* ================================================== */
 
 static int
-add_interface(const char *name, double tx_comp, double rx_comp)
+add_interface(CNF_HwTsInterface *conf_iface)
 {
   struct ethtool_ts_info ts_info;
   struct hwtstamp_config ts_config;
@@ -103,7 +103,7 @@ add_interface(const char *name, double tx_comp, double rx_comp)
 
   /* Check if the interface was not already added */
   for (i = 0; i < ARR_GetSize(interfaces); i++) {
-    if (!strcmp(name, ((struct Interface *)ARR_GetElement(interfaces, i))->name))
+    if (!strcmp(conf_iface->name, ((struct Interface *)ARR_GetElement(interfaces, i))->name))
       return 1;
   }
 
@@ -114,7 +114,8 @@ add_interface(const char *name, double tx_comp, double rx_comp)
   memset(&req, 0, sizeof (req));
   memset(&ts_info, 0, sizeof (ts_info));
 
-  if (snprintf(req.ifr_name, sizeof (req.ifr_name), "%s", name) >= sizeof (req.ifr_name)) {
+  if (snprintf(req.ifr_name, sizeof (req.ifr_name), "%s", conf_iface->name) >=
+      sizeof (req.ifr_name)) {
     close(sock_fd);
     return 0;
   }
@@ -163,7 +164,7 @@ add_interface(const char *name, double tx_comp, double rx_comp)
 
   iface = ARR_GetNewElement(interfaces);
 
-  snprintf(iface->name, sizeof (iface->name), "%s", name);
+  snprintf(iface->name, sizeof (iface->name), "%s", conf_iface->name);
   iface->if_index = if_index;
   iface->phc_fd = phc_fd;
 
@@ -172,12 +173,12 @@ add_interface(const char *name, double tx_comp, double rx_comp)
   iface->l2_udp4_ntp_start = 42;
   iface->l2_udp6_ntp_start = 62;
 
-  iface->tx_comp = tx_comp;
-  iface->rx_comp = rx_comp;
+  iface->tx_comp = conf_iface->tx_comp;
+  iface->rx_comp = conf_iface->rx_comp;
 
   iface->clock = HCL_CreateInstance();
 
-  DEBUG_LOG(LOGF_NtpIOLinux, "Enabled HW timestamping on %s", name);
+  DEBUG_LOG(LOGF_NtpIOLinux, "Enabled HW timestamping on %s", iface->name);
 
   return 1;
 }
@@ -185,18 +186,22 @@ add_interface(const char *name, double tx_comp, double rx_comp)
 /* ================================================== */
 
 static int
-add_all_interfaces(double tx_comp, double rx_comp)
+add_all_interfaces(CNF_HwTsInterface *conf_iface_all)
 {
+  CNF_HwTsInterface conf_iface;
   struct ifaddrs *ifaddr, *ifa;
   int r;
 
+  conf_iface = *conf_iface_all;
+
   if (getifaddrs(&ifaddr)) {
     DEBUG_LOG(LOGF_NtpIOLinux, "getifaddrs() failed : %s", strerror(errno));
     return 0;
   }
 
   for (r = 0, ifa = ifaddr; ifa; ifa = ifa->ifa_next) {
-    if (add_interface(ifa->ifa_name, tx_comp, rx_comp))
+    conf_iface.name = ifa->ifa_name;
+    if (add_interface(&conf_iface))
       r = 1;
   }
   
@@ -242,8 +247,7 @@ update_interface_speed(struct Interface *iface)
 void
 NIO_Linux_Initialise(void)
 {
-  double tx_comp, rx_comp;
-  char *name;
+  CNF_HwTsInterface *conf_iface;
   unsigned int i;
   int hwts;
 
@@ -252,18 +256,18 @@ NIO_Linux_Initialise(void)
   /* Enable HW timestamping on specified interfaces.  If "*" was specified, try
      all interfaces.  If no interface was specified, enable SW timestamping. */
 
-  for (i = hwts = 0; CNF_GetHwTsInterface(i, &name, &tx_comp, &rx_comp); i++) {
-    if (!strcmp("*", name))
+  for (i = hwts = 0; CNF_GetHwTsInterface(i, &conf_iface); i++) {
+    if (!strcmp("*", conf_iface->name))
       continue;
-    if (!add_interface(name, tx_comp, rx_comp))
-      LOG_FATAL(LOGF_NtpIO, "Could not enable HW timestamping on %s", name);
+    if (!add_interface(conf_iface))
+      LOG_FATAL(LOGF_NtpIO, "Could not enable HW timestamping on %s", conf_iface->name);
     hwts = 1;
   }
 
-  for (i = 0; CNF_GetHwTsInterface(i, &name, &tx_comp, &rx_comp); i++) {
-    if (strcmp("*", name))
+  for (i = 0; CNF_GetHwTsInterface(i, &conf_iface); i++) {
+    if (strcmp("*", conf_iface->name))
       continue;
-    if (add_all_interfaces(tx_comp, rx_comp))
+    if (add_all_interfaces(conf_iface))
       hwts = 1;
     break;
   }