Print this page
10543 dls_unbind() needs better checking
Reviewed by: Andy Fiddaman <andy@omniosce.org>
Reviewed by: Dan McDonald <danmcd@joyent.com>


   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  * Copyright 2012, Nexenta Systems, Inc. All rights reserved.
  25  */
  26 
  27 /*
  28  * Copyright (c) 2013 Joyent, Inc.  All rights reserved.
  29  */
  30 
  31 /*
  32  * Data-Link Services Module
  33  */
  34 
  35 #include        <sys/strsun.h>
  36 #include        <sys/vlan.h>
  37 #include        <sys/dld_impl.h>
  38 #include        <sys/mac_client_priv.h>
  39 
  40 int
  41 dls_open(dls_link_t *dlp, dls_dl_handle_t ddh, dld_str_t *dsp)
  42 {
  43         zoneid_t        zid = getzoneid();
  44         boolean_t       local;
  45         int             err;
  46 
  47         /*
  48          * Check whether this client belongs to the zone of this dlp. Note that


 201         /*
 202          * Now bind the dld_str_t by adding it into the hash table in the
 203          * dls_link_t.
 204          */
 205         dls_link_add(dsp->ds_dlp, dls_sap, dsp);
 206         if (dsp->ds_nonip && dsp->ds_dlp->dl_nonip_cnt++ == 0)
 207                 mac_rx_bypass_disable(dsp->ds_mch);
 208 
 209         return (0);
 210 }
 211 
 212 void
 213 dls_unbind(dld_str_t *dsp)
 214 {
 215         ASSERT(MAC_PERIM_HELD(dsp->ds_mh));
 216 
 217         if (dsp->ds_nonip && --dsp->ds_dlp->dl_nonip_cnt == 0)
 218                 mac_rx_bypass_enable(dsp->ds_mch);
 219 
 220         /*
 221          * For VLAN SAP, there was a promisc handle registered when dls_bind.
 222          * When unbind this dls link, we need to remove the promisc handle.
 223          * See comments in dls_bind().
 224          */

 225         if (dsp->ds_vlan_mph != NULL) {
 226                 mac_promisc_remove(dsp->ds_vlan_mph);
 227                 dsp->ds_vlan_mph = NULL;

 228                 return;
 229         }
 230 
 231         /*
 232          * Unbind the dld_str_t by removing it from the hash table in the
 233          * dls_link_t.
 234          */
 235         dls_link_remove(dsp->ds_dlp, dsp);
 236         dsp->ds_sap = 0;
 237 }
 238 
 239 /*
 240  * In order to prevent promiscuous-mode processing with dsp->ds_promisc
 241  * set to inaccurate values, this function sets dsp->ds_promisc with new
 242  * flags.  For enabling (mac_promisc_add), the flags are set prior to the
 243  * actual enabling.  For disabling (mac_promisc_remove), the flags are set
 244  * after the actual disabling.
 245  */
 246 int
 247 dls_promisc(dld_str_t *dsp, uint32_t new_flags)




   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  * Copyright 2012, Nexenta Systems, Inc. All rights reserved.
  25  */
  26 
  27 /*
  28  * Copyright (c) 2019 Joyent, Inc.  All rights reserved.
  29  */
  30 
  31 /*
  32  * Data-Link Services Module
  33  */
  34 
  35 #include        <sys/strsun.h>
  36 #include        <sys/vlan.h>
  37 #include        <sys/dld_impl.h>
  38 #include        <sys/mac_client_priv.h>
  39 
  40 int
  41 dls_open(dls_link_t *dlp, dls_dl_handle_t ddh, dld_str_t *dsp)
  42 {
  43         zoneid_t        zid = getzoneid();
  44         boolean_t       local;
  45         int             err;
  46 
  47         /*
  48          * Check whether this client belongs to the zone of this dlp. Note that


 201         /*
 202          * Now bind the dld_str_t by adding it into the hash table in the
 203          * dls_link_t.
 204          */
 205         dls_link_add(dsp->ds_dlp, dls_sap, dsp);
 206         if (dsp->ds_nonip && dsp->ds_dlp->dl_nonip_cnt++ == 0)
 207                 mac_rx_bypass_disable(dsp->ds_mch);
 208 
 209         return (0);
 210 }
 211 
 212 void
 213 dls_unbind(dld_str_t *dsp)
 214 {
 215         ASSERT(MAC_PERIM_HELD(dsp->ds_mh));
 216 
 217         if (dsp->ds_nonip && --dsp->ds_dlp->dl_nonip_cnt == 0)
 218                 mac_rx_bypass_enable(dsp->ds_mch);
 219 
 220         /*
 221          * A VLAN SAP does not actually add itself to the STREAM head today.
 222          * While we initially set up a VLAN handle below, it's possible that
 223          * something else will have come in and clobberd it.
 224          */
 225         if (dsp->ds_sap == ETHERTYPE_VLAN) {
 226                 if (dsp->ds_vlan_mph != NULL) {
 227                         mac_promisc_remove(dsp->ds_vlan_mph);
 228                         dsp->ds_vlan_mph = NULL;
 229                 }
 230                 return;
 231         }
 232 
 233         /*
 234          * Unbind the dld_str_t by removing it from the hash table in the
 235          * dls_link_t.
 236          */
 237         dls_link_remove(dsp->ds_dlp, dsp);
 238         dsp->ds_sap = 0;
 239 }
 240 
 241 /*
 242  * In order to prevent promiscuous-mode processing with dsp->ds_promisc
 243  * set to inaccurate values, this function sets dsp->ds_promisc with new
 244  * flags.  For enabling (mac_promisc_add), the flags are set prior to the
 245  * actual enabling.  For disabling (mac_promisc_remove), the flags are set
 246  * after the actual disabling.
 247  */
 248 int
 249 dls_promisc(dld_str_t *dsp, uint32_t new_flags)