Print this page
OS-406
OS-249


   3  *
   4  * The contents of this file are subject to the terms of the
   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  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.

  23  */
  24 
  25 /*
  26  * Data-Link Driver
  27  */
  28 
  29 #include        <sys/conf.h>
  30 #include        <sys/mkdev.h>
  31 #include        <sys/modctl.h>
  32 #include        <sys/stat.h>
  33 #include        <sys/dld_impl.h>
  34 #include        <sys/dld_ioc.h>
  35 #include        <sys/dls_impl.h>
  36 #include        <sys/softmac.h>
  37 #include        <sys/mac.h>
  38 #include        <sys/mac_ether.h>
  39 #include        <sys/mac_client.h>
  40 #include        <sys/mac_client_impl.h>
  41 #include        <sys/mac_client_priv.h>
  42 #include        <inet/common.h>


 684         if (zoneid != dls_devnet_getownerzid(dlh)) {
 685                 err = ENOENT;
 686                 goto done;
 687         }
 688 
 689         if (!mac_prop_check_size(kprop->pr_num, kprop->pr_valsize,
 690             kprop->pr_flags & DLD_PROP_POSSIBLE)) {
 691                 err = ENOBUFS;
 692                 goto done;
 693         }
 694 
 695         switch (kprop->pr_num) {
 696         case MAC_PROP_ZONE:
 697                 if (set) {
 698                         dld_ioc_zid_t *dzp = (dld_ioc_zid_t *)kprop->pr_val;
 699 
 700                         if (zoneid != GLOBAL_ZONEID) {
 701                                 err = EACCES;
 702                                 goto done;
 703                         }
 704                         err = dls_devnet_setzid(dlh, dzp->diz_zid);

 705                 } else {
 706                         kprop->pr_perm_flags = MAC_PROP_PERM_RW;
 707                         (*(zoneid_t *)kprop->pr_val) = dls_devnet_getzid(dlh);
 708                 }
 709                 break;
 710         case MAC_PROP_AUTOPUSH: {
 711                 struct dlautopush *dlap = (struct dlautopush *)kprop->pr_val;
 712 
 713                 if (set) {
 714                         if (kprop->pr_valsize != 0)
 715                                 err = drv_ioc_setap(linkid, dlap);
 716                         else
 717                                 err = drv_ioc_clrap(linkid);
 718                 } else {
 719                         if (kprop->pr_valsize == 0)
 720                                 return (ENOBUFS);
 721 
 722                         kprop->pr_perm_flags = MAC_PROP_PERM_RW;
 723                         err = drv_ioc_getap(linkid, dlap);
 724                 }


 848         mod_hash_key_t          key;
 849         mod_hash_val_t          val;
 850         zoneid_t                zoneid = crgetzoneid(cred);
 851         datalink_class_t        class;
 852         int                     err;
 853 
 854         if (zoneid != GLOBAL_ZONEID &&
 855             (zone_check_datalink(&zoneid, dir->dir_linkid1) != 0 ||
 856             dir->dir_linkid2 != DATALINK_INVALID_LINKID &&
 857             zone_check_datalink(&zoneid, dir->dir_linkid2) != 0))
 858                 return (ENOENT);
 859 
 860         if ((err = dls_mgmt_get_linkinfo(dir->dir_linkid1, NULL, &class, NULL,
 861             NULL)) != 0)
 862                 return (err);
 863 
 864         if ((err = drv_ioc_checkprivs(class, cred)) != 0)
 865                 return (err);
 866 
 867         if ((err = dls_devnet_rename(dir->dir_linkid1, dir->dir_linkid2,
 868             dir->dir_link)) != 0)
 869                 return (err);
 870 
 871         if (dir->dir_linkid2 == DATALINK_INVALID_LINKID)
 872                 return (0);
 873 
 874         /*
 875          * if dir_linkid2 is not DATALINK_INVALID_LINKID, it means this
 876          * renaming request is to rename a valid physical link (dir_linkid1)
 877          * to a "removed" physical link (dir_linkid2, which is removed by DR
 878          * or during system shutdown). In this case, the link (specified by
 879          * dir_linkid1) would inherit all the configuration of dir_linkid2,
 880          * and dir_linkid1 and its configuration would be lost.
 881          *
 882          * Remove per-link autopush configuration of dir_linkid1 in this case.
 883          */
 884         key = (mod_hash_key_t)(uintptr_t)dir->dir_linkid1;
 885         rw_enter(&dld_ap_hash_lock, RW_WRITER);
 886         if (mod_hash_find(dld_ap_hashp, key, &val) != 0) {
 887                 rw_exit(&dld_ap_hash_lock);
 888                 return (0);




   3  *
   4  * The contents of this file are subject to the terms of the
   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  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
  23  * Copyright (c) 2011, Joyent Inc. All rights reserved.
  24  */
  25 
  26 /*
  27  * Data-Link Driver
  28  */
  29 
  30 #include        <sys/conf.h>
  31 #include        <sys/mkdev.h>
  32 #include        <sys/modctl.h>
  33 #include        <sys/stat.h>
  34 #include        <sys/dld_impl.h>
  35 #include        <sys/dld_ioc.h>
  36 #include        <sys/dls_impl.h>
  37 #include        <sys/softmac.h>
  38 #include        <sys/mac.h>
  39 #include        <sys/mac_ether.h>
  40 #include        <sys/mac_client.h>
  41 #include        <sys/mac_client_impl.h>
  42 #include        <sys/mac_client_priv.h>
  43 #include        <inet/common.h>


 685         if (zoneid != dls_devnet_getownerzid(dlh)) {
 686                 err = ENOENT;
 687                 goto done;
 688         }
 689 
 690         if (!mac_prop_check_size(kprop->pr_num, kprop->pr_valsize,
 691             kprop->pr_flags & DLD_PROP_POSSIBLE)) {
 692                 err = ENOBUFS;
 693                 goto done;
 694         }
 695 
 696         switch (kprop->pr_num) {
 697         case MAC_PROP_ZONE:
 698                 if (set) {
 699                         dld_ioc_zid_t *dzp = (dld_ioc_zid_t *)kprop->pr_val;
 700 
 701                         if (zoneid != GLOBAL_ZONEID) {
 702                                 err = EACCES;
 703                                 goto done;
 704                         }
 705                         err = dls_devnet_setzid(dlh, dzp->diz_zid,
 706                             dzp->diz_transient);
 707                 } else {
 708                         kprop->pr_perm_flags = MAC_PROP_PERM_RW;
 709                         (*(zoneid_t *)kprop->pr_val) = dls_devnet_getzid(dlh);
 710                 }
 711                 break;
 712         case MAC_PROP_AUTOPUSH: {
 713                 struct dlautopush *dlap = (struct dlautopush *)kprop->pr_val;
 714 
 715                 if (set) {
 716                         if (kprop->pr_valsize != 0)
 717                                 err = drv_ioc_setap(linkid, dlap);
 718                         else
 719                                 err = drv_ioc_clrap(linkid);
 720                 } else {
 721                         if (kprop->pr_valsize == 0)
 722                                 return (ENOBUFS);
 723 
 724                         kprop->pr_perm_flags = MAC_PROP_PERM_RW;
 725                         err = drv_ioc_getap(linkid, dlap);
 726                 }


 850         mod_hash_key_t          key;
 851         mod_hash_val_t          val;
 852         zoneid_t                zoneid = crgetzoneid(cred);
 853         datalink_class_t        class;
 854         int                     err;
 855 
 856         if (zoneid != GLOBAL_ZONEID &&
 857             (zone_check_datalink(&zoneid, dir->dir_linkid1) != 0 ||
 858             dir->dir_linkid2 != DATALINK_INVALID_LINKID &&
 859             zone_check_datalink(&zoneid, dir->dir_linkid2) != 0))
 860                 return (ENOENT);
 861 
 862         if ((err = dls_mgmt_get_linkinfo(dir->dir_linkid1, NULL, &class, NULL,
 863             NULL)) != 0)
 864                 return (err);
 865 
 866         if ((err = drv_ioc_checkprivs(class, cred)) != 0)
 867                 return (err);
 868 
 869         if ((err = dls_devnet_rename(dir->dir_linkid1, dir->dir_linkid2,
 870             dir->dir_link, dir->dir_zoneinit)) != 0)
 871                 return (err);
 872 
 873         if (dir->dir_linkid2 == DATALINK_INVALID_LINKID)
 874                 return (0);
 875 
 876         /*
 877          * if dir_linkid2 is not DATALINK_INVALID_LINKID, it means this
 878          * renaming request is to rename a valid physical link (dir_linkid1)
 879          * to a "removed" physical link (dir_linkid2, which is removed by DR
 880          * or during system shutdown). In this case, the link (specified by
 881          * dir_linkid1) would inherit all the configuration of dir_linkid2,
 882          * and dir_linkid1 and its configuration would be lost.
 883          *
 884          * Remove per-link autopush configuration of dir_linkid1 in this case.
 885          */
 886         key = (mod_hash_key_t)(uintptr_t)dir->dir_linkid1;
 887         rw_enter(&dld_ap_hash_lock, RW_WRITER);
 888         if (mod_hash_find(dld_ap_hashp, key, &val) != 0) {
 889                 rw_exit(&dld_ap_hash_lock);
 890                 return (0);