Author: glebius
Date: Thu Aug 30 12:18:45 2012
New Revision: 239905
URL: http://svn.freebsd.org/changeset/base/239905

Log:
  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>

Modified:
  head/sys/net/if_clone.c

Modified: head/sys/net/if_clone.c
==============================================================================
--- head/sys/net/if_clone.c     Thu Aug 30 11:52:26 2012        (r239904)
+++ head/sys/net/if_clone.c     Thu Aug 30 12:18:45 2012        (r239905)
@@ -443,21 +443,30 @@ ifc_alloc_unit(struct if_clone *ifc, int
 
        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);
        }
 
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "[email protected]"

Reply via email to