summaryrefslogtreecommitdiffstats
path: root/sys/net/if_clone.c
diff options
context:
space:
mode:
authorglebius <glebius@FreeBSD.org>2012-08-30 12:18:45 +0000
committerglebius <glebius@FreeBSD.org>2012-08-30 12:18:45 +0000
commit165d5550eb3668154608da5722a38b550124ecfd (patch)
tree898efd58b30339f0d075dbd43521d36aaca78ab3 /sys/net/if_clone.c
parentef55aebbf3b3f982030b8abd3f009d00561c2419 (diff)
downloadFreeBSD-src-165d5550eb3668154608da5722a38b550124ecfd.zip
FreeBSD-src-165d5550eb3668154608da5722a38b550124ecfd.tar.gz
In ifc_alloc_unit():
- In the !wildcard case, return ENOSPC instead of confusing EEXIST in case if ifc->ifc_maxunit reached. - Fix unit leak, that I've introduced in previous revision. Submitted by: Daan Vreeken <Daan vitsch.nl>
Diffstat (limited to 'sys/net/if_clone.c')
-rw-r--r--sys/net/if_clone.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/sys/net/if_clone.c b/sys/net/if_clone.c
index 5720fc4..3543e2f 100644
--- a/sys/net/if_clone.c
+++ b/sys/net/if_clone.c
@@ -443,21 +443,30 @@ ifc_alloc_unit(struct if_clone *ifc, int *unit)
wildcard = (*unit < 0);
retry:
- if (wildcard) {
+ if (*unit > ifc->ifc_maxunit)
+ return (ENOSPC);
+ if (*unit < 0) {
*unit = alloc_unr(ifc->ifc_unrhdr);
if (*unit == -1)
return (ENOSPC);
} else {
*unit = alloc_unr_specific(ifc->ifc_unrhdr, *unit);
- if (*unit == -1)
- return (EEXIST);
+ if (*unit == -1) {
+ if (wildcard) {
+ (*unit)++;
+ goto retry;
+ } else
+ return (EEXIST);
+ }
}
snprintf(name, IFNAMSIZ, "%s%d", ifc->ifc_name, *unit);
if (ifunit(name) != NULL) {
- if (wildcard)
- goto retry; /* XXXGL: yep, it's a unit leak */
- else
+ free_unr(ifc->ifc_unrhdr, *unit);
+ if (wildcard) {
+ (*unit)++;
+ goto retry;
+ } else
return (EEXIST);
}
OpenPOWER on IntegriCloud