/*
* 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 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Data-Link Services Module
*/
#include <sys/sysmacros.h>
#include <sys/dld_impl.h>
/*
* Construct a hash key encompassing both DLSAP value and VLAN idenitifier.
*/
if (pktsize != 0) { \
\
if (delta < 0) \
} \
}
/*
* Private functions.
*/
/*ARGSUSED*/
static int
{
return (0);
}
/*ARGSUSED*/
static void
{
}
/*
* - Parse the mac header information of the given packet.
* - Strip the padding and skip over the header. Note that because some
* DLS consumers only check the db_ref count of the first mblk, we
* pullup the message into a single mblk. Because the original message
* is freed as the result of message pulling up, mac_vlan_header_info()
* is called again to update the mhi_saddr and mhi_daddr pointers in the
* mhip. Further, the mac_vlan_header_info() function ensures that the
* size of the pulled message is greater than the MAC header size,
* therefore we can directly advance b_rptr to point at the payload.
*
* We choose to use a macro for performance reasons.
*/
} else { \
} \
} else { \
} \
} \
}
/*
* Truncate the chain starting at mp such that all packets in the chain
* have identical source and destination addresses, saps, and tag types
* (see below). It returns a pointer to the mblk following the chain,
* NULL if there is no further packet following the processed chain.
* The countp argument is set to the number of valid packets in the chain.
* Note that the whole MAC header (including the VLAN tag if any) in each
* packet will be stripped.
*/
static mblk_t *
{
/*
* Compare with subsequent headers until we find one that has
* differing header information. After checking each packet
* strip padding and skip over the header.
*/
int err;
if (err != 0)
break;
/*
* The source, destination, sap, vlan tag must all match in
* a given subchain.
*/
/*
* Note that we don't need to restore the padding.
*/
break;
}
/*
* There are several types of packets. Packets don't match
* if they are classified to different type or if they are
* VLAN packets but belong to different VLANs:
*
* packet type tagged vid pri
* ---------------------------------------------------------
* untagged No zero zero
* VLAN packets Yes non-zero -
* priority tagged Yes zero non-zero
* 0 tagged Yes zero zero
*/
break;
}
npacket++;
}
/*
* Break the chain at this point and return a pointer to the next
* sub-chain.
*/
return (mp);
}
/* ARGSUSED */
static int
{
/*
* The lock order is mod_hash's internal lock -> dh_lock as in the
* call to i_dls_link_rx -> mod_hash_find_cb_rval -> i_dls_head_hold
*/
if (dhp->dh_removing) {
return (-1);
}
return (0);
}
void
{
}
static dls_head_t *
{
return (dhp);
}
static void
{
}
/*
* Try to send mp up to the streams of the given sap and vid. Return B_TRUE
* if this message is sent to any streams.
* Note that this function will copy the message chain and the original
* mp will remain valid after this function
*/
static uint_t
boolean_t (*acceptfunc)())
{
void *ds_rx_arg;
int rval;
/*
* Construct a hash key from the VLAN identifier and the
* DLSAP that represents dld_str_t in promiscuous mode.
*/
/*
* Search the hash table for dld_str_t eligible to receive
* Incrementing the dh_ref (while holding the mod hash lock) ensures
* dls_link_remove will wait for the upcall to finish.
*/
return (B_FALSE);
}
/*
* Find dld_str_t that will accept the sub-chain.
*/
continue;
/*
* We have at least one acceptor.
*/
naccepted++;
/*
* There will normally be at least more dld_str_t
* (since we've yet to check for non-promiscuous
* dld_str_t) so dup the sub-chain.
*/
}
/*
* Release the hold on the dld_str_t chain now that we have
* finished walking it.
*/
return (naccepted);
}
/* ARGSUSED */
void
{
/*
* Walk the packet chain.
*/
/*
* Wipe the accepted state.
*/
if (err != 0) {
continue;
}
/*
* Grab the longest sub-chain we can process as a single
* unit.
*/
if (mhi.mhi_istagged) {
/*
* If it is tagged traffic, send it upstream to
* all dld_str_t which are attached to the physical
* link and bound to SAP 0x8100.
*/
ETHERTYPE_VLAN, dls_accept) > 0) {
}
/*
* Don't pass the packets up if they are tagged
* packets and:
* - their VID and priority are both zero and the
* original packet isn't using the PVID (invalid
* packets).
* - their sap is ETHERTYPE_VLAN and their VID is
* zero as they have already been sent upstreams.
*/
vid == VLAN_ID_NONE)) {
goto loop;
}
}
/*
* Construct a hash key from the VLAN identifier and the
* DLSAP.
*/
/*
* Search the has table for dld_str_t eligible to receive
*/
goto loop;
}
/*
* Find the first dld_str_t that will accept the sub-chain.
*/
break;
/*
* If we did not find any dld_str_t willing to accept the
* sub-chain then throw it away.
*/
goto loop;
}
/*
* We have at least one acceptor.
*/
for (;;) {
/*
* Find the next dld_str_t that will accept the
* sub-chain.
*/
&nds_rx_arg))
break;
/*
* If there are no more dld_str_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 dld_str_t, we're
* done.
*/
break;
}
/*
* There are more dld_str_t so dup the sub-chain.
*/
}
/*
* Release the hold on the dld_str_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)
}
}
/* ARGSUSED */
void
{
void *ds_rx_arg;
int err;
if (err != 0)
goto drop;
/*
* If there is promiscuous handle for vlan, we filter out the untagged
* pkts and pkts that are not for the primary unicast address.
*/
if (!(mhi.mhi_istagged))
goto drop;
goto drop;
goto drop;
return;
}
drop:
}
/* ARGSUSED */
void
{
void *ds_rx_arg;
int err;
if (err != 0)
goto drop;
/*
* In order to filter out sap pkt that no dls channel listens, search
* the hash table trying to find a dld_str_t eligible to receive the pkt
*/
(mod_hash_val_t *)&dhp) != 0)
goto drop;
}
goto drop;
return;
drop:
}
static void
{
/*
* Free the structure back to the cache.
*/
}
dlp->dl_unknowns = 0;
dlp->dl_nonip_cnt = 0;
}
static int
{
int err;
/*
* Allocate a new dls_link_t structure.
*/
/*
* Name the dls_link_t after the MAC interface it represents.
*/
/*
* First reference; hold open the MAC interface.
*/
if (err != 0)
goto bail;
/* DLS is the "primary" MAC client */
if (err != 0)
goto bail;
return (0);
bail:
return (err);
}
/*
* 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.
*/
static int
{
int err;
/*
* Look up a dls_link_t corresponding to the given macname in the
* global hash table. The i_dls_link_hash itself is protected by the
* mod_hash package's internal lock which synchronizes
* inserts and removes are single threaded on a per mac end point
* by the mac perimeter.
*/
(mod_hash_val_t *)&dlp)) == 0)
goto done;
if (!create)
return (ENOENT);
/*
* 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);
}
int
{
}
int
{
}
{
char *drv;
return (NULL);
/*
* The code below assumes that the name constructed above is the
* macname. This is not the case for legacy devices. Currently this
* is ok because this function is only called in the getinfo(9e) path,
* which for a legacy device would directly end up in the driver's
* getinfo, rather than here
*/
return (NULL);
return (NULL);
}
return (dip);
}
{
}
void
{
/*
* Check if there are any more references.
*/
(void) mod_hash_remove(i_dls_link_hash,
/*
* Destroy the dls_link_t.
*/
ASSERT(i_dls_link_count > 0);
}
}
int
{
(mod_hash_val_t *)&dlp) != 0)
return (ENOENT);
/*
* Must fail detach if mac client is busy.
*/
return (ENOTEMPTY);
return (0);
}
int
{
int err = 0;
return (err);
goto done;
/*
* Check whether this dlp is used by its own zone. If yes, we cannot
* change its zoneid.
*/
if (dlp->dl_zone_ref != 0) {
goto done;
}
if (zid == GLOBAL_ZONEID) {
/*
* The link is moving from a non-global zone to the global
* zone, so we need to release the reference that was held
* when the link was originally assigned to the non-global
* zone.
*/
}
done:
/*
* We only keep the reference to this link open if the link has
* successfully moved from the global zone to a non-global zone.
*/
return (err);
}
int
{
int err = 0;
return (err);
return (0);
}
void
{
dld_str_t *p;
int err;
/*
* Generate a hash key based on the sap.
*/
/*
* Search the table for a list head with this key.
*/
}
/*
* Add the dld_str_t to the head of the list. List walkers in
* i_dls_link_rx_* bump up dh_ref to ensure the list does not change
* while they walk the list. The membar below ensures that list walkers
* see exactly the old list or the new list.
*/
/*
* Save a pointer to the list head.
*/
dlp->dl_impl_count++;
}
void
{
dld_str_t *p;
/*
* We set dh_removing here to tell the receive callbacks not to pass
* up packets anymore. Then wait till the current callbacks are done.
* This happens either in the close path or in processing the
* DL_UNBIND_REQ via a taskq thread, and it is ok to cv_wait in either.
* The dh_ref ensures there aren't and there won't be any upcalls
* walking or using the dh_list. The mod hash internal lock ensures
* any i_dls_link_rx trying to locate it. The perimeter ensures that
* there isn't another simultaneous dls_link_add/remove.
*/
/*
* Walk the list and remove the dld_str_t.
*/
if (p == dsp)
break;
}
dlp->dl_impl_count--;
/*
* The list is empty so remove the hash table entry.
*/
} else {
}
}