Page MenuHomeFreeBSD

D45757.id140307.diff
No OneTemporary

D45757.id140307.diff

diff --git a/sys/net/if_clone.h b/sys/net/if_clone.h
--- a/sys/net/if_clone.h
+++ b/sys/net/if_clone.h
@@ -101,6 +101,7 @@
#define IFC_F_SYSSPACE 0x04 /* Cloner callback: params pointer is in kernel memory */
#define IFC_F_FORCE 0x08 /* Deletion flag: force interface deletion */
#define IFC_F_CREATE 0x10 /* Creation flag: indicate creation request */
+#define IFC_F_LIMITUNIT 0x20 /* Creation flag: the unit number is limited */
struct if_clone *ifc_attach_cloner(const char *name, struct if_clone_addreq *req);
void ifc_detach_cloner(struct if_clone *ifc);
diff --git a/sys/net/if_clone.c b/sys/net/if_clone.c
--- a/sys/net/if_clone.c
+++ b/sys/net/if_clone.c
@@ -483,12 +483,13 @@
struct if_clone *ifc;
KASSERT(name != NULL, ("%s: no name\n", __func__));
+ MPASS(maxunit >= 0);
ifc = malloc(sizeof(struct if_clone), M_CLONE, M_WAITOK | M_ZERO);
strncpy(ifc->ifc_name, name, IFCLOSIZ-1);
IF_CLONE_LOCK_INIT(ifc);
IF_CLONE_ADDREF(ifc);
- ifc->ifc_maxunit = maxunit ? maxunit : IF_MAXUNIT;
+ ifc->ifc_maxunit = maxunit;
ifc->ifc_unrhdr = new_unrhdr(0, ifc->ifc_maxunit, &ifc->ifc_mtx);
LIST_INIT(&ifc->ifc_iflist);
@@ -521,12 +522,20 @@
struct if_clone *
ifc_attach_cloner(const char *name, struct if_clone_addreq *req)
{
+ int maxunit;
+ struct if_clone *ifc;
+
if (req->create_f == NULL || req->destroy_f == NULL)
return (NULL);
if (strnlen(name, IFCLOSIZ) >= (IFCLOSIZ - 1))
return (NULL);
- struct if_clone *ifc = if_clone_alloc(name, req->maxunit);
+ /* XXX Keep old behavior if provided non-zero maxunit */
+ if ((req->flags & IFC_F_LIMITUNIT) != 0 || req->maxunit != 0)
+ maxunit = req->maxunit;
+ else
+ maxunit = IF_MAXUNIT;
+ ifc = if_clone_alloc(name, maxunit);
ifc->ifc_match = req->match_f != NULL ? req->match_f : ifc_simple_match;
ifc->ifc_create = req->create_f;
ifc->ifc_destroy = req->destroy_f;
@@ -584,7 +593,7 @@
{
struct if_clone *ifc;
- ifc = if_clone_alloc(name, maxunit);
+ ifc = if_clone_alloc(name, maxunit ? maxunit : IF_MAXUNIT);
ifc->ifc_match = match;
ifc->ifc_create = ifc_advanced_create_wrapper;
ifc->ifc_destroy = ifc_advanced_destroy_wrapper;
@@ -629,7 +638,7 @@
struct if_clone *ifc;
u_int unit;
- ifc = if_clone_alloc(name, 0);
+ ifc = if_clone_alloc(name, IF_MAXUNIT);
ifc->ifc_match = ifc_simple_match;
ifc->ifc_create = ifc_simple_create_wrapper;
ifc->ifc_destroy = ifc_simple_destroy_wrapper;

File Metadata

Mime Type
text/plain
Expires
Thu, May 1, 8:12 AM (19 h, 14 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
17877296
Default Alt Text
D45757.id140307.diff (2 KB)

Event Timeline