summaryrefslogtreecommitdiffstats
path: root/sbin/ifconfig
diff options
context:
space:
mode:
authorambrisko <ambrisko@FreeBSD.org>2004-04-30 22:34:12 +0000
committerambrisko <ambrisko@FreeBSD.org>2004-04-30 22:34:12 +0000
commit8abe6632d3c2a913fdbb461ba5fa74a260ce895c (patch)
tree85e5ce6415aa05ca134796f95d041a6be5fd14ba /sbin/ifconfig
parentc14039802334822a4159818e193f9e41eb2cca8e (diff)
downloadFreeBSD-src-8abe6632d3c2a913fdbb461ba5fa74a260ce895c.zip
FreeBSD-src-8abe6632d3c2a913fdbb461ba5fa74a260ce895c.tar.gz
For both ifconfig and route if we didn't get enough memory from the
prior sysctl due to the structure growing between calls try again. Also try again for deleting routes if things fail. We've seen route -f fail this way which does not actually flush all routes. This fixes it. It will whine but it will do the work. PR: 56732 Obtained from: IronPort
Diffstat (limited to 'sbin/ifconfig')
-rw-r--r--sbin/ifconfig/ifconfig.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c
index 27ffcda..b35ed9e 100644
--- a/sbin/ifconfig/ifconfig.c
+++ b/sbin/ifconfig/ifconfig.c
@@ -417,7 +417,7 @@ main(int argc, char *argv[])
{
int c;
int all, namesonly, downonly, uponly;
- int need_nl = 0;
+ int need_nl = 0, count = 0;
const struct afswtch *afp = 0;
int addrcount, ifindex;
struct if_msghdr *ifm, *nextifm;
@@ -543,6 +543,7 @@ main(int argc, char *argv[])
afp = NULL; /* not a family, NULL */
}
+retry:
mib[0] = CTL_NET;
mib[1] = PF_ROUTE;
mib[2] = 0;
@@ -558,8 +559,15 @@ main(int argc, char *argv[])
errx(1, "iflist-sysctl-estimate");
if ((buf = malloc(needed)) == NULL)
errx(1, "malloc");
- if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0)
+ if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0) {
+ if (errno == ENOMEM && count++ < 10) {
+ warnx("Routing table grew, retrying");
+ free(buf);
+ sleep(1);
+ goto retry;
+ }
errx(1, "actual retrieval of interface table");
+ }
lim = buf + needed;
next = buf;
OpenPOWER on IntegriCloud