aboutsummaryrefslogtreecommitdiff
path: root/sys/net/if_clone.c
diff options
context:
space:
mode:
authorGleb Smirnoff <glebius@FreeBSD.org>2012-08-30 12:18:45 +0000
committerGleb Smirnoff <glebius@FreeBSD.org>2012-08-30 12:18:45 +0000
commit3932d7603319d795b7a851d902496bd73cd99c97 (patch)
tree898efd58b30339f0d075dbd43521d36aaca78ab3 /sys/net/if_clone.c
parentf2fbdacbf837cae0bcd9f032386ec940eabb48a5 (diff)
downloadsrc-3932d7603319d795b7a851d902496bd73cd99c97.tar.gz
src-3932d7603319d795b7a851d902496bd73cd99c97.zip
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>
Notes
Notes: svn path=/head/; revision=239905
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 5720fc4feaec..3543e2f71fca 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);
}