From: Martin Schwenke Date: Mon, 12 Jan 2026 07:05:23 +0000 (+1100) Subject: ctdb-common: Use if_nametoindex(3) to check if interface exists X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d19ad0bec55dccfc1891c320a2fed41cc139927f;p=thirdparty%2Fsamba.git ctdb-common: Use if_nametoindex(3) to check if interface exists This is much simpler than looping through the array. It will also find an interface by altname, which could be very useful. Signed-off-by: Martin Schwenke Reviewed-by: Volker Lendecke --- diff --git a/ctdb/common/system.c b/ctdb/common/system.c index 05a95647233..170268c41fc 100644 --- a/ctdb/common/system.c +++ b/ctdb/common/system.c @@ -148,36 +148,18 @@ void ctdb_wait_for_process_to_exit(pid_t pid) } } -#ifdef HAVE_IF_NAMEINDEX +#ifdef HAVE_IF_NAMETOINDEX bool ctdb_sys_check_iface_exists(const char *iface) { - struct if_nameindex *ifnis, *ifni; - bool found = false; + unsigned int index = 0; - ifnis = if_nameindex(); - if (ifnis == NULL) { - DBG_ERR("Failed to retrieve interface list\n"); - return false; - } - - for (ifni = ifnis; - ifni->if_index != 0 || ifni->if_name != NULL; - ifni++) { - int cmp = strcmp(iface, ifni->if_name); - if (cmp == 0) { - found = true; - goto done; - } - } - -done: - if_freenameindex(ifnis); + index = if_nametoindex(iface); - return found; + return index != 0; } -#else /* HAVE_IF_NAMEINDEX */ +#else /* HAVE_IF_NAMETOINDEX */ bool ctdb_sys_check_iface_exists(const char *iface) { @@ -185,7 +167,7 @@ bool ctdb_sys_check_iface_exists(const char *iface) return true; } -#endif /* HAVE_IF_NAMEINDEX */ +#endif /* HAVE_IF_NAMETOINDEX */ #ifdef HAVE_PEERCRED