Print this page
8478 mac: suggest parentheses around '&&' within '||'
Reviewed by: Ryan Zezeski <rpz@joyent.com>
Reviewed by: Alexander Stetsenko <astetsenko@racktopsystems.com>


   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   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 /*
  23  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright (c) 2014, Joyent, Inc.  All rights reserved.

  25  */
  26 
  27 /*
  28  * - General Introduction:
  29  *
  30  * This file contains the implementation of the MAC client kernel
  31  * API and related code. The MAC client API allows a kernel module
  32  * to gain access to a MAC instance (physical NIC, link aggregation, etc).
  33  * It allows a MAC client to associate itself with a MAC address,
  34  * VLANs, callback functions for data traffic and for promiscuous mode.
  35  * The MAC client API is also used to specify the properties associated
  36  * with a MAC client, such as bandwidth limits, priority, CPUS, etc.
  37  * These properties are further used to determine the hardware resources
  38  * to allocate to the various MAC clients.
  39  *
  40  * - Primary MAC clients:
  41  *
  42  * The MAC client API refers to "primary MAC clients". A primary MAC
  43  * client is a client which "owns" the primary MAC address of
  44  * the underlying MAC instance. The primary MAC address is called out


2714                 ASSERT(((flags & MAC_UNICAST_TAG_DISABLE) != 0 &&
2715                     (mcip->mci_state_flags & MCIS_TAG_DISABLE) != 0) ||
2716                     ((flags & MAC_UNICAST_TAG_DISABLE) == 0 &&
2717                     (mcip->mci_state_flags & MCIS_TAG_DISABLE) == 0));
2718 
2719                 ASSERT(((flags & MAC_UNICAST_STRIP_DISABLE) != 0 &&
2720                     (mcip->mci_state_flags & MCIS_STRIP_DISABLE) != 0) ||
2721                     ((flags & MAC_UNICAST_STRIP_DISABLE) == 0 &&
2722                     (mcip->mci_state_flags & MCIS_STRIP_DISABLE) == 0));
2723 
2724                 ASSERT(((flags & MAC_UNICAST_DISABLE_TX_VID_CHECK) != 0 &&
2725                     (mcip->mci_state_flags & MCIS_DISABLE_TX_VID_CHECK) != 0) ||
2726                     ((flags & MAC_UNICAST_DISABLE_TX_VID_CHECK) == 0 &&
2727                     (mcip->mci_state_flags & MCIS_DISABLE_TX_VID_CHECK) == 0));
2728 
2729                 /*
2730                  * Make sure the client is consistent about its requests
2731                  * for MAC addresses. I.e. all requests from the clients
2732                  * must have the MAC_UNICAST_HW flag set or clear.
2733                  */
2734                 if ((mcip->mci_state_flags & MCIS_UNICAST_HW) != 0 &&
2735                     !is_unicast_hw ||
2736                     (mcip->mci_state_flags & MCIS_UNICAST_HW) == 0 &&
2737                     is_unicast_hw) {
2738                         err = EINVAL;
2739                         goto bail_out;
2740                 }
2741         }
2742         /*
2743          * Make sure the MAC address is not already used by
2744          * another MAC client defined on top of the same
2745          * underlying NIC. Unless we have MAC_CLIENT_FLAGS_MULTI_PRIMARY
2746          * set when we allow a passive client to be present which will
2747          * be activated when the currently active client goes away - this
2748          * works only with primary addresses.
2749          */
2750         if ((check_dups || is_primary || is_vnic_primary) &&
2751             mac_addr_in_use(mip, mac_addr, vid)) {
2752                 /*
2753                  * Must have set the multiple primary address flag when
2754                  * we did a mac_client_open AND this should be a primary
2755                  * MAC client AND there should not already be a passive
2756                  * primary. If all is true then we let this succeed
2757                  * even if the address is a dup.




   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   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 /*
  23  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright (c) 2014, Joyent, Inc.  All rights reserved.
  25  * Copyright 2017 RackTop Systems.
  26  */
  27 
  28 /*
  29  * - General Introduction:
  30  *
  31  * This file contains the implementation of the MAC client kernel
  32  * API and related code. The MAC client API allows a kernel module
  33  * to gain access to a MAC instance (physical NIC, link aggregation, etc).
  34  * It allows a MAC client to associate itself with a MAC address,
  35  * VLANs, callback functions for data traffic and for promiscuous mode.
  36  * The MAC client API is also used to specify the properties associated
  37  * with a MAC client, such as bandwidth limits, priority, CPUS, etc.
  38  * These properties are further used to determine the hardware resources
  39  * to allocate to the various MAC clients.
  40  *
  41  * - Primary MAC clients:
  42  *
  43  * The MAC client API refers to "primary MAC clients". A primary MAC
  44  * client is a client which "owns" the primary MAC address of
  45  * the underlying MAC instance. The primary MAC address is called out


2715                 ASSERT(((flags & MAC_UNICAST_TAG_DISABLE) != 0 &&
2716                     (mcip->mci_state_flags & MCIS_TAG_DISABLE) != 0) ||
2717                     ((flags & MAC_UNICAST_TAG_DISABLE) == 0 &&
2718                     (mcip->mci_state_flags & MCIS_TAG_DISABLE) == 0));
2719 
2720                 ASSERT(((flags & MAC_UNICAST_STRIP_DISABLE) != 0 &&
2721                     (mcip->mci_state_flags & MCIS_STRIP_DISABLE) != 0) ||
2722                     ((flags & MAC_UNICAST_STRIP_DISABLE) == 0 &&
2723                     (mcip->mci_state_flags & MCIS_STRIP_DISABLE) == 0));
2724 
2725                 ASSERT(((flags & MAC_UNICAST_DISABLE_TX_VID_CHECK) != 0 &&
2726                     (mcip->mci_state_flags & MCIS_DISABLE_TX_VID_CHECK) != 0) ||
2727                     ((flags & MAC_UNICAST_DISABLE_TX_VID_CHECK) == 0 &&
2728                     (mcip->mci_state_flags & MCIS_DISABLE_TX_VID_CHECK) == 0));
2729 
2730                 /*
2731                  * Make sure the client is consistent about its requests
2732                  * for MAC addresses. I.e. all requests from the clients
2733                  * must have the MAC_UNICAST_HW flag set or clear.
2734                  */
2735                 if (((mcip->mci_state_flags & MCIS_UNICAST_HW) != 0 &&
2736                     !is_unicast_hw) ||
2737                     ((mcip->mci_state_flags & MCIS_UNICAST_HW) == 0 &&
2738                     is_unicast_hw)) {
2739                         err = EINVAL;
2740                         goto bail_out;
2741                 }
2742         }
2743         /*
2744          * Make sure the MAC address is not already used by
2745          * another MAC client defined on top of the same
2746          * underlying NIC. Unless we have MAC_CLIENT_FLAGS_MULTI_PRIMARY
2747          * set when we allow a passive client to be present which will
2748          * be activated when the currently active client goes away - this
2749          * works only with primary addresses.
2750          */
2751         if ((check_dups || is_primary || is_vnic_primary) &&
2752             mac_addr_in_use(mip, mac_addr, vid)) {
2753                 /*
2754                  * Must have set the multiple primary address flag when
2755                  * we did a mac_client_open AND this should be a primary
2756                  * MAC client AND there should not already be a passive
2757                  * primary. If all is true then we let this succeed
2758                  * even if the address is a dup.