dls_vlan.c revision f4b3ec61df05330d25f55a36b975b4d7519fdeb1
/*
* 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 2007 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 mod_hash_t *i_dls_vlan_dev_hash;
static krwlock_t i_dls_vlan_lock;
static uint_t i_dls_vlan_count;
static vmem_t *minor_arenap;
/*
* 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.
*/
/*
* Create a second hash table, keyed by minor, of dls_vlan_t.
* The number of the hash slots is the same.
*/
i_dls_vlan_count = 0;
/*
* Allocate a vmem arena to manage minor numbers. The range of the
* arena will be from DLD_MAX_MINOR + 1 to MAXMIN (maximum legal
* minor number).
*/
}
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;
/* Create a minor node for this VLAN */
if (vid != 0 && vlan_created) {
/* A tagged VLAN */
if (err != 0) {
(mod_hash_val_t *)&val);
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
{
/* a minor node has been created for this vlan */
int err;
(mod_hash_val_t *)&val);
}
/*
* 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
{
}
int
{
if (minor <= DLD_MAX_MINOR) {
return (0);
}
(mod_hash_val_t *)&dvp) != 0) {
return (ENOENT);
}
return (0);
}
int
dls_vlan_rele_by_name(const char *name)
{
(mod_hash_val_t *)&dvp) != 0) {
return (ENOENT);
}
/* a minor node has been created for this vlan */
int err;
(mod_hash_val_t *)&val);
}
/* Tagged vlans get destroyed when dv_ref drops to 0. */
}
if (destroy_vlan)
(void) dls_vlan_destroy(name);
return (0);
}
typedef struct dls_vlan_dip_state {
static int
{
if (dls_mac_hold(dlp) != 0)
return (0);
return (1);
}
return (0);
}
{
return (vlan_state.dip);
}
/*
* Allocate a new minor number.
*/
{
/*
* Grab a value from the arena.
*/
}
/*
* Release a previously allocated minor number.
*/
void
{
/*
* Return the value to the arena.
*/
}
int
{
int err;
return (err);
if (!docheck) {
} else {
break;
else
}
return (err);
}
int
{
int err;
return (err);
return (0);
}
void
{
}
void
{
dls_impl_t **pp;
dls_impl_t *p;
pp = &(p->di_next_impl))
if (p == dip)
break;
*pp = p->di_next_impl;
p->di_next_impl = NULL;
}