This patch inserts if_nametoindex calls in each of the internal ISC
routines that lookup the interface attributes. Neither getifaddrs or
the existing ioctl calls lookup the index for the interface.
This has been submitted as a patch for NTP bug 1960, and it can be
removed when NTP is upgraded to version that includes a fix for
1960.
--- lib/isc/unix/ifiter_getifaddrs.c
+++ lib/isc/unix/ifiter_getifaddrs.c
@@ -204,6 +204,9 @@ internal_current(isc_interfaceiter_t *it
get_addr(family, &iter->current.broadcast, ifa->ifa_broadaddr,
ifa->ifa_name);
+#ifdef ISC_PLATFORM_HAVEIFNAMETOINDEX
+ iter->current.ifindex = if_nametoindex(iter->current.name);
+#endif
return (ISC_R_SUCCESS);
}
--- lib/isc/unix/ifiter_ioctl.c
+++ lib/isc/unix/ifiter_ioctl.c
@@ -588,6 +588,9 @@ internal_current4(isc_interfaceiter_t *i
}
iter->current.netmask.type.in6.s6_addr[i] = (~0 << bits) & 0xff;
}
+#ifdef ISC_PLATFORM_HAVEIFNAMETOINDEX
+ iter->current.ifindex = if_nametoindex(iter->current.name);
+#endif
return (ISC_R_SUCCESS);
inet:
@@ -664,6 +667,9 @@ internal_current4(isc_interfaceiter_t *i
}
get_addr(family, &iter->current.netmask,
(struct sockaddr *)&ifreq.ifr_addr, ifreq.ifr_name);
+#ifdef ISC_PLATFORM_HAVEIFNAMETOINDEX
+ iter->current.ifindex = if_nametoindex(iter->current.name);
+#endif
return (ISC_R_SUCCESS);
}
@@ -704,7 +710,6 @@ internal_current6(isc_interfaceiter_t *i
get_addr(family, &iter->current.address,
(struct sockaddr *)&lifreq.lifr_addr, lifreq.lifr_name);
- iter->current.ifindex = lifreq.lifr_index;
if (isc_netaddr_islinklocal(&iter->current.address))
isc_netaddr_setzone(&iter->current.address,
(isc_uint32_t)lifreq.lifr_index);
@@ -844,7 +849,9 @@ internal_current6(isc_interfaceiter_t *i
iter->current.netmask.type.in6.s6_addr[i / 8] =
(~0 << bits) & 0xff;
}
-
+#ifdef ISC_PLATFORM_HAVEIFNAMETOINDEX
+ iter->current.ifindex = if_nametoindex(iter->current.name);
+#endif
return (ISC_R_SUCCESS);
}
#endif
@@ -867,6 +874,9 @@ internal_current6(isc_interfaceiter_t *i
get_addr(family, &iter->current.netmask,
(struct sockaddr *)&lifreq.lifr_addr, lifreq.lifr_name);
+#ifdef ISC_PLATFORM_HAVEIFNAMETOINDEX
+ iter->current.ifindex = if_nametoindex(iter->current.name);
+#endif
return (ISC_R_SUCCESS);
}
#endif