dls_link.c revision 6b6515e229cf9a7ed588f9e8614175a4540d1ae2
/*
* 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/ethernet.h>
#include <sys/byteorder.h>
#include <sys/dld_impl.h>
#include <sys/dls_impl.h>
static kmem_cache_t *i_dls_link_cachep;
static mod_hash_t *i_dls_link_hash;
static uint_t i_dls_link_count;
static krwlock_t i_dls_link_lock;
/*
* Construct a hash key encompassing both DLSAP value and VLAN idenitifier.
*/
((mod_hash_key_t)(uintptr_t) \
/*
* Extract the DLSAP value from the hash key.
*/
/*
* Private functions.
*/
/*ARGSUSED*/
static int
{
char name[MAXNAMELEN];
return (0);
}
/*ARGSUSED*/
static void
{
}
\
if (delta < 0) \
} \
}
static mblk_t *
{
struct ether_header *ehp;
struct ether_vlan_header *evhp;
mblk_t *p;
/*
* Packets should always be at least 16 bit aligned.
*/
/*
* Determine whether this is a VLAN or non-VLAN packet.
*/
goto vlan;
/*
* It is a non-VLAN header.
*/
*header_lengthp = sizeof (struct ether_header);
/*
* Parse the rest of the header information that we need.
*/
*vidp = VLAN_ID_NONE;
/*
* Compare with subsequent headers until we find one that has
* differing header information. After checking each packet
* strip padding and skip over the header.
*/
npacket = 1;
break;
p->b_rptr += sizeof (struct ether_header);
npacket++;
}
/*
* Strip padding and skip over the initial packet's header.
*/
goto done;
vlan:
/*
* It is a VLAN header.
*/
*header_lengthp = sizeof (struct ether_vlan_header);
/*
* Parse the header information.
*/
/*
* Compare with subsequent headers until we find one that has
* differing header information. After checking each packet
* strip padding and skip over the header.
*/
npacket = 1;
break;
p->b_rptr += sizeof (struct ether_vlan_header);
npacket++;
}
/*
* Strip padding and skip over the initial packet's header.
*/
done:
/*
* Break the chain at this point and return a pointer to the next
* sub-chain.
*/
return (p);
}
static void
{
}
static void
{
}
static dls_head_t *
{
return (dhp);
}
static void
{
}
static void
{
void *di_rx_arg, *ndi_rx_arg;
/*
* Walk the packet chain.
*/
/*
* Wipe the accepted state.
*/
/*
* Grab the longest sub-chain we can process as a single
* unit.
*/
/*
* interpreted as a length, otherwise it is the value of the
*/
/*
* Construct a hash key from the VLAN identifier and the
* DLSAP.
*/
/*
* Search the has table for dls_impl_t eligible to receive
*/
goto loop;
}
/*
* Find the first dls_impl_t that will accept the sub-chain.
*/
break;
/*
* If we did not find any dls_impl_t willing to accept the
* sub-chain then throw it away.
*/
goto loop;
}
/*
* We have at least one acceptor.
*/
for (;;) {
/*
* Find the next dls_impl_t that will accept the
* sub-chain.
*/
&ndi_rx_arg))
break;
/*
* If there are no more dls_impl_t that are willing
* to accept the sub-chain then we don't need to dup
* it before handing it to the current one.
*/
/*
* Since there are no more dls_impl_t, we're
* done.
*/
break;
}
/*
* There are more dls_impl_t so dup the sub-chain.
*/
}
/*
* Release the hold on the dls_impl_t chain now that we have
* finished walking it.
*/
loop:
/*
* If there were no acceptors then add the packet count to the
* 'unknown' count.
*/
if (!accepted)
/*
* Move onto the next sub-chain.
*/
}
}
static void
{
void *di_rx_arg, *ndi_rx_arg;
/*
* Walk the packet chain.
*/
/*
* Wipe the accepted state.
*/
/*
* Grab the longest sub-chain we can process as a single
* unit.
*/
/*
* Construct a hash key from the VLAN identifier and the
* DLSAP that represents dls_impl_t in promiscuous mode.
*/
/*
* Search the has table for dls_impl_t eligible to receive
*/
goto non_promisc;
}
/*
* Find dls_impl_t that will accept the sub-chain.
*/
continue;
/*
* We have at least one acceptor.
*/
/*
* There will normally be at least more dls_impl_t
* (since we've yet to check for non-promiscuous
* dls_impl_t) so dup the sub-chain.
*/
}
/*
* Release the hold on the dls_impl_t chain now that we have
* finished walking it.
*/
/*
* interpreted as a length, otherwise it is the value of the
*/
/*
* Construct a hash key from the VLAN identifier and the
* DLSAP.
*/
/*
* Search the has table for dls_impl_t eligible to receive
*/
goto loop;
}
/*
* Find the first dls_impl_t that will accept the sub-chain.
*/
break;
/*
* If we did not find any dls_impl_t willing to accept the
* sub-chain then throw it away.
*/
goto loop;
}
/*
* We have at least one acceptor.
*/
for (;;) {
/*
* Find the next dls_impl_t that will accept the
* sub-chain.
*/
&ndi_rx_arg))
break;
/*
* If there are no more dls_impl_t that are willing
* to accept the sub-chain then we don't need to dup
* it before handing it to the current one.
*/
/*
* Since there are no more dls_impl_t, we're
* done.
*/
break;
}
/*
* There are more dls_impl_t so dup the sub-chain.
*/
}
/*
* Release the hold on the dls_impl_t chain now that we have
* finished walking it.
*/
loop:
/*
* If there were no acceptors then add the packet count to the
* 'unknown' count.
*/
if (!accepted)
/*
* Move onto the next sub-chain.
*/
}
}
static void
{
void *di_rx_arg, *ndi_rx_arg;
/*
* Walk the packet chain.
*/
/*
* Grab the longest sub-chain we can process as a single
* unit.
*/
/*
* interpreted as a length, otherwise it is the value of the
*/
/*
* Construct a hash key from the VLAN identifier and the
* DLSAP.
*/
/*
* Search the has table for dls_impl_t eligible to receive
*/
goto promisc;
}
/*
* Find dls_impl_t that will accept the sub-chain.
*/
&di_rx_arg))
continue;
/*
* There should be at least more dls_impl_t (since
* we've yet to check for dls_impl_t in promiscuous
* mode) so dup the sub-chain.
*/
}
/*
* Release the hold on the dls_impl_t chain now that we have
* finished walking it.
*/
/*
* Construct a hash key from the VLAN identifier and the
* DLSAP that represents dls_impl_t in promiscuous mode.
*/
/*
* Search the has table for dls_impl_t eligible to receive
*/
goto loop;
}
/*
* Find the first dls_impl_t that will accept the sub-chain.
*/
break;
/*
* If we did not find any dls_impl_t willing to accept the
* sub-chain then throw it away.
*/
goto loop;
}
for (;;) {
/*
* Find the next dls_impl_t that will accept the
* sub-chain.
*/
&ndi_rx, &ndi_rx_arg))
break;
/*
* If there are no more dls_impl_t that are willing
* to accept the sub-chain then we don't need to dup
* it before handing it to the current one.
*/
/*
* Since there are no more dls_impl_t, we're
* done.
*/
break;
}
/*
* There are more dls_impl_t so dup the sub-chain.
*/
}
/*
* Release the hold on the dls_impl_t chain now that we have
* finished walking it.
*/
loop:
/*
* Move onto the next sub-chain.
*/
}
}
/*ARGSUSED*/
static uint_t
{
if (sap == DLS_SAP_PROMISC) {
return (MH_WALK_TERMINATE);
}
return (MH_WALK_CONTINUE);
}
static int
{
/*
* Allocate a new dls_link_t structure.
*/
/*
* Name the dls_link_t after the MAC interface it represents.
*/
/*
* Set the packet loopback function for use when the MAC is in
* promiscuous mode, and initialize promiscuous bookeeping fields.
*/
dlp->dl_npromisc = 0;
return (0);
}
static void
{
/*
* Free the structure back to the cache.
*/
dlp->dl_unknowns = 0;
}
/*
* Module initialization functions.
*/
void
dls_link_init(void)
{
/*
* Create a kmem_cache of dls_link_t structures.
*/
sizeof (dls_link_t), 0, i_dls_link_constructor,
/*
* Create a dls_link_t hash table and associated lock.
*/
i_dls_link_count = 0;
}
int
dls_link_fini(void)
{
if (i_dls_link_count > 0)
return (EBUSY);
/*
* Destroy the kmem_cache.
*/
/*
* Destroy the hash table and associated lock.
*/
return (0);
}
/*
* Exported functions.
*/
int
{
char name[MAXNAMELEN];
int err;
/*
* Construct a copy of the name used to identify any existing
* dls_link_t.
*/
/*
* Look up a dls_link_t corresponding to the given mac_handle_t
* in the global hash table. We need to hold i_dls_link_lock in
* order to atomically find and insert a dls_link_t into the
* hash table.
*/
(mod_hash_val_t *)&dlp)) == 0)
goto done;
/*
* We didn't find anything so we need to create one.
*/
return (err);
}
/*
* Insert the dls_link_t.
*/
ASSERT(i_dls_link_count != 0);
done:
/*
* Bump the reference count and hand back the reference.
*/
return (0);
}
void
{
/*
* Check if there are any more references.
*/
/*
* There are more references so there's nothing more to do.
*/
goto done;
}
(void) mod_hash_remove(i_dls_link_hash,
/*
* Destroy the dls_link_t.
*/
ASSERT(i_dls_link_count > 0);
done:
}
int
{
int err = 0;
/*
* First reference; hold open the MAC interface.
*/
if (err != 0)
goto done;
}
done:
return (err);
}
void
{
}
}
void
{
dls_impl_t *p;
int err;
/*
* For ethernet media, sap values less than or equal to
* ETHERMTU (1500) represent LLC channels. (See PSARC 2003/150).
* We strictly use 0 to represent LLC channels.
*/
/*
* Make the appropriate key value depending on whether the
* dls_impl_t is in promiscuous mode or not.
*/
/*
* We need dl_lock here because we want to be able to walk
* the hash table *and* set the mac rx func atomically. if
* these two operations are separate, someone else could
* drop the hash lock and this could cause our chosen rx
* func to be incorrect. note that we cannot call mac_rx_add
* when holding the hash lock because this can cause deadlock.
*/
/*
* Search the table for a list head with this key.
*/
}
/*
* Add the dls_impl_t to the head of the list.
*/
/*
* Save a pointer to the list head.
*/
dlp->dl_impl_count++;
/*
* Walk the bound dls_impl_t to see if there are any
* in promiscuous 'all sap' mode.
*/
/*
* If there are then we need to use a receive routine
* which will route packets to those dls_impl_t as well
* as ones bound to the DLSAP of the packet.
*/
if (promisc)
else
/* Replace the existing receive function if there is one. */
}
void
{
dls_impl_t **pp;
dls_impl_t *p;
/*
* We need dl_lock here because we want to be able to walk
* the hash table *and* set the mac rx func atomically. if
* these two operations are separate, someone else could
* drop the hash lock and this could cause our chosen rx
* func to be incorrect. note that we cannot call mac_rx_add
* when holding the hash lock because this can cause deadlock.
*/
/*
* Poll the hash table entry until all references have been dropped.
* We need to drop all locks before sleeping because we don't want
* the interrupt handler to block. We set di_removing here to
* tell the receive callbacks not to pass up packets anymore.
* This is only a hint to quicken the decrease of the refcnt so
* the assignment need not be protected by any lock.
*/
}
/*
* Walk the list and remove the dls_impl_t.
*/
if (p == dip)
break;
}
dlp->dl_impl_count--;
/*
* The list is empty so remove the hash table entry.
*/
}
/*
* If there are no dls_impl_t then there's no need to register a
* receive function with the mac.
*/
if (dlp->dl_impl_count == 0) {
} else {
/*
* Walk the bound dls_impl_t to see if there are any
* in promiscuous 'all sap' mode.
*/
/*
* If there are then we need to use a receive routine
* which will route packets to those dls_impl_t as well
* as ones bound to the DLSAP of the packet.
*/
if (promisc)
else
}
}