]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
ntp: add option to select HW RX timestamping filter
authorMiroslav Lichvar <mlichvar@redhat.com>
Tue, 6 Jun 2017 15:20:03 +0000 (17:20 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Tue, 27 Jun 2017 13:29:01 +0000 (15:29 +0200)
Add an rxfilter option to the hwtimestamp directive to select which
received packets should be timestamped. It can be set to "none", "ntp",
or "all". The default value is ntp, which falls back to all when ntp is
not supported.

conf.c
conf.h
ntp_io_linux.c

diff --git a/conf.c b/conf.c
index 6fa5eee3d7e46149c22edec4eb9f2005e34f9248..2b9d37658851323ba2f5b9af2f6c2ca5fb96d5c1 100644 (file)
--- a/conf.c
+++ b/conf.c
@@ -1259,7 +1259,7 @@ static void
 parse_hwtimestamp(char *line)
 {
   CNF_HwTsInterface *iface;
-  char *p;
+  char *p, filter[5];
   int n;
 
   if (!*line) {
@@ -1274,6 +1274,7 @@ parse_hwtimestamp(char *line)
   iface->name = Strdup(p);
   iface->minpoll = 0;
   iface->nocrossts = 0;
+  iface->rxfilter = CNF_HWTS_RXFILTER_NTP;
   iface->precision = 100.0e-9;
   iface->tx_comp = 0.0;
   iface->rx_comp = 0.0;
@@ -1293,6 +1294,17 @@ parse_hwtimestamp(char *line)
     } else if (!strcasecmp(p, "txcomp")) {
       if (sscanf(line, "%lf%n", &iface->tx_comp, &n) != 1)
         break;
+    } else if (!strcasecmp(p, "rxfilter")) {
+      if (sscanf(line, "%4s%n", filter, &n) != 1)
+        break;
+      if (!strcasecmp(filter, "none"))
+        iface->rxfilter = CNF_HWTS_RXFILTER_NONE;
+      else if (!strcasecmp(filter, "ntp"))
+        iface->rxfilter = CNF_HWTS_RXFILTER_NTP;
+      else if (!strcasecmp(filter, "all"))
+        iface->rxfilter = CNF_HWTS_RXFILTER_ALL;
+      else
+        break;
     } else if (!strcasecmp(p, "nocrossts")) {
       n = 0;
       iface->nocrossts = 1;
diff --git a/conf.h b/conf.h
index 7128e6eb6198d0bbb6394c9a08c61c76128da8ac..0dde15364dd55269212b46aab8b09aca43680935 100644 (file)
--- a/conf.h
+++ b/conf.h
@@ -118,10 +118,15 @@ extern char *CNF_GetHwclockFile(void);
 extern int CNF_GetInitSources(void);
 extern double CNF_GetInitStepThreshold(void);
 
+#define CNF_HWTS_RXFILTER_NONE 0
+#define CNF_HWTS_RXFILTER_NTP 1
+#define CNF_HWTS_RXFILTER_ALL 2
+
 typedef struct {
   char *name;
   int minpoll;
   int nocrossts;
+  int rxfilter;
   double precision;
   double tx_comp;
   double rx_comp;
index 52d0e3abf28a51fe5932e4ecacaf78be7d6b1b7c..5a506773a95de096ae96525d08e3b697ed63324a 100644 (file)
@@ -152,12 +152,24 @@ add_interface(CNF_HwTsInterface *conf_iface)
 
   ts_config.flags = 0;
   ts_config.tx_type = HWTSTAMP_TX_ON;
+
+  switch (conf_iface->rxfilter) {
+    case CNF_HWTS_RXFILTER_NONE:
+      ts_config.rx_filter = HWTSTAMP_FILTER_NONE;
+      break;
+    case CNF_HWTS_RXFILTER_NTP:
 #ifdef HAVE_LINUX_TIMESTAMPING_RXFILTER_NTP
-  if (ts_info.rx_filters & (1 << HWTSTAMP_FILTER_NTP_ALL))
-    ts_config.rx_filter = HWTSTAMP_FILTER_NTP_ALL;
-  else
+      if (ts_info.rx_filters & (1 << HWTSTAMP_FILTER_NTP_ALL)) {
+        ts_config.rx_filter = HWTSTAMP_FILTER_NTP_ALL;
+        break;
+      }
 #endif
-    ts_config.rx_filter = HWTSTAMP_FILTER_ALL;
+      /* Fall through */
+    default:
+      ts_config.rx_filter = HWTSTAMP_FILTER_ALL;
+      break;
+  }
+
   req.ifr_data = (char *)&ts_config;
 
   if (ioctl(sock_fd, SIOCSHWTSTAMP, &req)) {