summaryrefslogtreecommitdiffstats
path: root/freebsd/sys/net/if_clone.c
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2018-08-09 14:02:09 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2018-09-21 10:29:38 +0200
commitbb80d9df8bac71eedee1a6787ca63aef972a7e48 (patch)
tree1b5cb9443c5ead5706c35afb618abbbd1592315e /freebsd/sys/net/if_clone.c
parentUpdate to FreeBSD head 2017-10-01 (diff)
downloadrtems-libbsd-bb80d9df8bac71eedee1a6787ca63aef972a7e48.tar.bz2
Update to FreeBSD head 2017-12-01
Git mirror commit e724f51f811a4b2bd29447f8b85ab5c2f9b88266. Update #3472.
Diffstat (limited to 'freebsd/sys/net/if_clone.c')
-rw-r--r--freebsd/sys/net/if_clone.c62
1 files changed, 38 insertions, 24 deletions
diff --git a/freebsd/sys/net/if_clone.c b/freebsd/sys/net/if_clone.c
index e7339423..99faa05f 100644
--- a/freebsd/sys/net/if_clone.c
+++ b/freebsd/sys/net/if_clone.c
@@ -1,6 +1,8 @@
#include <machine/rtems-bsd-kernel-space.h>
/*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
* Copyright (c) 2012 Gleb Smirnoff <glebius@FreeBSD.org>
* Copyright (c) 1980, 1986, 1993
* The Regents of the University of California. All rights reserved.
@@ -597,39 +599,21 @@ ifc_name2unit(const char *name, int *unit)
return (0);
}
-int
-ifc_alloc_unit(struct if_clone *ifc, int *unit)
+static int
+ifc_alloc_unit_specific(struct if_clone *ifc, int *unit)
{
char name[IFNAMSIZ];
- int wildcard;
- wildcard = (*unit < 0);
-retry:
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) {
- if (wildcard) {
- (*unit)++;
- goto retry;
- } else
- return (EEXIST);
- }
- }
+
+ if (alloc_unr_specific(ifc->ifc_unrhdr, *unit) == -1)
+ return (EEXIST);
snprintf(name, IFNAMSIZ, "%s%d", ifc->ifc_name, *unit);
if (ifunit(name) != NULL) {
free_unr(ifc->ifc_unrhdr, *unit);
- if (wildcard) {
- (*unit)++;
- goto retry;
- } else
- return (EEXIST);
+ return (EEXIST);
}
IF_CLONE_ADDREF(ifc);
@@ -637,6 +621,36 @@ retry:
return (0);
}
+static int
+ifc_alloc_unit_next(struct if_clone *ifc, int *unit)
+{
+ int error;
+
+ *unit = alloc_unr(ifc->ifc_unrhdr);
+ if (*unit == -1)
+ return (ENOSPC);
+
+ free_unr(ifc->ifc_unrhdr, *unit);
+ for (;;) {
+ error = ifc_alloc_unit_specific(ifc, unit);
+ if (error != EEXIST)
+ break;
+
+ (*unit)++;
+ }
+
+ return (error);
+}
+
+int
+ifc_alloc_unit(struct if_clone *ifc, int *unit)
+{
+ if (*unit < 0)
+ return (ifc_alloc_unit_next(ifc, unit));
+ else
+ return (ifc_alloc_unit_specific(ifc, unit));
+}
+
void
ifc_free_unit(struct if_clone *ifc, int unit)
{