/* 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 {
{
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));
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++)
static void
parse_hwtimestamp(char *line)
{
- HwTs_Interface *iface;
+ CNF_HwTsInterface *iface;
char *p;
int n;
/* ================================================== */
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;
}
/* ================================================== */
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;
/* 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;
}
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;
}
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;
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;
}
/* ================================================== */
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;
}
void
NIO_Linux_Initialise(void)
{
- double tx_comp, rx_comp;
- char *name;
+ CNF_HwTsInterface *conf_iface;
unsigned int i;
int hwts;
/* 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;
}