dls_vlan.c revision 0ba2cbe97e0678a691742f98d2532caed0a2c4aa
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Data-Link Services Module
*/
#include <sys/sysmacros.h>
#include <sys/dls_impl.h>
static kmem_cache_t *i_dls_vlan_cachep;
static mod_hash_t *i_dls_vlan_hash;
static krwlock_t i_dls_vlan_lock;
static uint_t i_dls_vlan_count;
/*
* Private functions.
*/
/*ARGSUSED*/
static int
{
return (0);
}
/*ARGSUSED*/
static void
{
}
/*
* Module initialization functions.
*/
void
dls_vlan_init(void)
{
/*
* Create a kmem_cache of dls_vlan_t structures.
*/
sizeof (dls_vlan_t), 0, i_dls_vlan_constructor,
/*
* Create a hash table, keyed by name, of dls_vlan_t.
*/
i_dls_vlan_count = 0;
}
int
dls_vlan_fini(void)
{
if (i_dls_vlan_count > 0)
return (EBUSY);
/*
* Destroy the hash table
*/
/*
* Destroy the kmem_cache.
*/
return (0);
}
/*
* Exported functions.
*/
int
{
int err;
/*
* Check to see the name is legal. It must be less than IFNAMSIZ
* characters in length and must terminate with a digit (before the
* NUL, of course).
*/
return (EINVAL);
return (EINVAL);
/*
* Get a reference to a dls_link_t representing the MAC. This call
* will create one if necessary.
*/
return (err);
/*
* Allocate a new dls_vlan_t.
*/
/*
* Insert the entry into the table.
*/
goto done;
}
done:
return (err);
}
int
dls_vlan_destroy(const char *name)
{
int err;
/*
* Find the dls_vlan_t in the global hash table.
*/
(mod_hash_val_t *)&dvp);
if (err != 0) {
goto done;
}
/*
* Check to see if it is referenced by any dls_impl_t.
*/
goto done;
}
/*
* Remove and destroy the hash table entry.
*/
(mod_hash_val_t *)&val);
ASSERT(i_dls_vlan_count > 0);
/*
* Save a reference to dv_dlp before freeing the dls_vlan_t back
* to the cache.
*/
/*
* Release the dls_link_t. This will destroy the dls_link_t and
* release the MAC if there are no more dls_vlan_t.
*/
done:
return (err);
}
int
{
int err;
(mod_hash_val_t *)&dvp);
if (err != 0) {
char mac[MAXNAMELEN];
if (!create_vlan) {
goto done;
}
/*
* Only create tagged vlans on demand.
* Note that if we get here, 'name' must be a sane
* value because it must have been derived from
* ddi_major_to_name().
*/
vid > VLAN_ID_MAX) {
goto done;
}
ddi_inst = 0;
else
goto done;
}
/*
* At this point someone else could do a dls_vlan_hold and
* dls_vlan_rele on this new vlan and causes it to be
* destroyed. This will at worst cause us to spin a few
* times.
*/
goto again;
}
goto done;
/*
* Do not allow the creation of tagged VLAN interfaces on
* non-Ethernet links. Note that we cannot do this check in
* dls_vlan_create() nor in this function prior to the call to
* dls_mac_hold(). The reason is that before we do a
* dls_mac_hold(), we may not have opened the mac, and therefore do
* not know what kind of media the mac represents. In other words,
* dls_mac_hold() assigns the dl_mip of the dls_link_t we're
* interested in.
*/
goto done;
}
goto done;
}
done:
/*
* We could be destroying a vlan created by another thread. This
* is ok because this other thread will just loop back up and
* recreate the vlan.
*/
if (err != 0 && vlan_created)
(void) dls_vlan_destroy(name);
return (err);
}
void
{
/*
* Tagged vlans get destroyed when dv_ref drops
* to 0. We need to copy dv_name here because
* dvp could disappear after we drop i_dls_vlan_lock.
*/
}
}
if (destroy_vlan)
(void) dls_vlan_destroy(name);
}
typedef struct dls_vlan_walk_state {
int (*fn)(dls_vlan_t *, void *);
void *arg;
int rc;
/*ARGSUSED*/
static uint_t
{
}
int
{
}