From e1a9b52b1c4ea5bd141b06ca296a85231fa72262 Mon Sep 17 00:00:00 2001 From: fabient Date: Wed, 4 Jan 2017 16:36:51 +0000 Subject: MFC r308216: In rtadvd, interface lookup calls if_indextoname() many times in a loop, (it takes a long time on systems with many interfaces) without reason and without checking its return value. Sponsored by: Stormshield --- usr.sbin/rtadvd/if.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'usr.sbin/rtadvd') diff --git a/usr.sbin/rtadvd/if.c b/usr.sbin/rtadvd/if.c index bd26dec..72ea36a 100644 --- a/usr.sbin/rtadvd/if.c +++ b/usr.sbin/rtadvd/if.c @@ -474,11 +474,18 @@ update_ifinfo(struct ifilist_head_t *ifi_head, int ifindex) ifindex != ifm->ifm_index) continue; + /* ifname */ + if (if_indextoname(ifm->ifm_index, ifname) == NULL) { + syslog(LOG_WARNING, + "<%s> ifname not found (idx=%d)", + __func__, ifm->ifm_index); + continue; + } + /* lookup an entry with the same ifindex */ TAILQ_FOREACH(ifi, ifi_head, ifi_next) { if (ifm->ifm_index == ifi->ifi_ifindex) break; - if_indextoname(ifm->ifm_index, ifname); if (strncmp(ifname, ifi->ifi_ifname, sizeof(ifname)) == 0) break; @@ -497,15 +504,7 @@ update_ifinfo(struct ifilist_head_t *ifi_head, int ifindex) ifi->ifi_ifindex = ifm->ifm_index; /* ifname */ - if_indextoname(ifm->ifm_index, ifi->ifi_ifname); - if (ifi->ifi_ifname == NULL) { - syslog(LOG_WARNING, - "<%s> ifname not found (idx=%d)", - __func__, ifm->ifm_index); - if (ifi_new) - free(ifi); - continue; - } + strlcpy(ifi->ifi_ifname, ifname, IFNAMSIZ); if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) { syslog(LOG_ERR, -- cgit v1.1