/*
* 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
*/
/*
*/
/*
* Data-Link Driver
*/
#include <sys/dld_impl.h>
#include <sys/dls_impl.h>
#include <sys/mac_ether.h>
#include <sys/mac_client.h>
#include <sys/mac_client_impl.h>
#include <sys/mac_client_priv.h>
#include <sys/priv_names.h>
#include <sys/sysmacros.h>
static void drv_init(void);
static int drv_fini(void);
/*
* Secure objects declarations
*/
static void drv_secobj_init(void);
static void drv_secobj_fini(void);
static int drv_ioc_clrap(datalink_id_t);
/*
* The following entry points are private to dld and are used for control
* operations only. The entry points exported to mac drivers are defined
*/
drv_open, /* open */
nulldev, /* close */
nulldev, /* strategy */
nulldev, /* print */
nodev, /* dump */
nodev, /* read */
nodev, /* write */
drv_ioctl, /* ioctl */
nodev, /* devmap */
nodev, /* mmap */
nodev, /* segmap */
nochpoll, /* poll */
ddi_prop_op, /* cb_prop_op */
0, /* streamtab */
D_MP /* Driver compatibility flag */
};
DEVO_REV, /* devo_rev */
0, /* refcnt */
drv_getinfo, /* get_dev_info */
nulldev, /* identify */
nulldev, /* probe */
drv_attach, /* attach */
drv_detach, /* detach */
nodev, /* reset */
&drv_cb_ops, /* driver operations */
NULL, /* bus operations */
nodev, /* dev power */
ddi_quiesce_not_supported, /* dev quiesce */
};
/*
* Module linkage information for the kernel.
*/
};
};
int
_init(void)
{
return (mod_install(&drv_modlinkage));
}
int
_fini(void)
{
return (mod_remove(&drv_modlinkage));
}
int
{
}
/*
* Initialize component modules.
*/
static void
drv_init(void)
{
dld_str_init();
/*
* Create a hash table for autopush configuration.
*/
}
/* ARGSUSED */
static uint_t
{
return (MH_WALK_TERMINATE);
}
static int
drv_fini(void)
{
int err;
if (exist)
return (EBUSY);
if ((err = dld_str_fini()) != 0)
return (err);
return (0);
}
/*
* devo_getinfo: getinfo(9e)
*/
/*ARGSUSED*/
static int
{
return (DDI_FAILURE);
switch (cmd) {
case DDI_INFO_DEVT2INSTANCE:
*resp = 0;
break;
case DDI_INFO_DEVT2DEVINFO:
break;
default:
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
/*
* Check properties to set options. (See dld.h for property definitions).
*/
static void
{
DLD_PROP_NO_FASTPATH, 0) != 0) {
}
DLD_PROP_NO_POLL, 0) != 0) {
}
DLD_PROP_NO_ZEROCOPY, 0) != 0) {
}
DLD_PROP_NO_SOFTRING, 0) != 0) {
}
}
/*
* devo_attach: attach(9e)
*/
static int
{
if (cmd != DDI_ATTACH)
return (DDI_FAILURE);
drv_init();
/*
* Create control node. DLPI provider nodes will be created on demand.
*/
return (DDI_FAILURE);
/*
* Log the fact that the driver is now attached.
*/
return (DDI_SUCCESS);
}
/*
* devo_detach: detach(9e)
*/
static int
{
if (cmd != DDI_DETACH)
return (DDI_FAILURE);
if (drv_fini() != 0)
return (DDI_FAILURE);
/*
* Remove the control node.
*/
return (DDI_SUCCESS);
}
/*
* dld control node open procedure.
*/
/*ARGSUSED*/
static int
{
/*
* Only the control node can be opened.
*/
return (ENODEV);
return (0);
}
/*
* Verify if the caller is allowed to modify a link of the given class.
*/
static int
{
if (class == DATALINK_CLASS_IPTUN)
return (secpolicy_iptun_config(cred));
return (secpolicy_dl_config(cred));
}
/*
* DLDIOC_ATTR
*/
/* ARGSUSED */
static int
{
int err;
if (zoneid != GLOBAL_ZONEID &&
return (ENOENT);
return (err);
if ((err = mac_perim_enter_by_macname(
return (err);
}
return (err);
}
return (0);
}
/*
* DLDIOC_PHYS_ATTR
*/
/* ARGSUSED */
static int
{
int err;
if (zoneid != GLOBAL_ZONEID &&
return (ENOENT);
/*
* Every physical link should have its physical dev_t kept in the
* daemon. If not, it is not a valid physical link.
*/
return (EINVAL);
/*
* Although this is a valid physical link, it might already be removed
* by DR or during system shutdown. softmac_hold_device() would return
* ENOENT in this case.
*/
return (err);
/*
* Although this is an active physical link, its link type is
* not supported by GLDv3, and therefore it does not have
* vanity naming support.
*/
} else {
}
/*
* Get the physical device name from the major number and the instance
* number derived from phydev.
*/
return (0);
}
/* ARGSUSED */
static int
{
int totgrps = 0;
if (zoneid != GLOBAL_ZONEID &&
return (ENOENT);
hwgrpp->dih_n_groups = 0;
if (err != 0)
goto done;
hip = (dld_hwgrpinfo_t *)
/* display the default group information first */
if (rgrpnum > 0) {
if (sizeof (dld_hwgrpinfo_t) > bytes_left) {
goto done;
}
sizeof (hwgrp.dhi_link_name));
if (hwgrp.dhi_n_rings != 0) {
goto done;
}
}
hip++;
totgrps++;
bytes_left -= sizeof (dld_hwgrpinfo_t);
}
/* display the default group information first */
if (tgrpnum > 0) {
if (sizeof (dld_hwgrpinfo_t) > bytes_left) {
goto done;
}
sizeof (hwgrp.dhi_link_name));
if (hwgrp.dhi_n_rings != 0) {
goto done;
}
}
hip++;
totgrps++;
bytes_left -= sizeof (dld_hwgrpinfo_t);
}
/* Rest of the rx groups */
for (i = 1; i < rgrpnum; i++) {
if (sizeof (dld_hwgrpinfo_t) > bytes_left) {
goto done;
}
sizeof (hwgrp.dhi_link_name));
if (hwgrp.dhi_n_rings == 0)
continue;
goto done;
}
hip++;
totgrps++;
bytes_left -= sizeof (dld_hwgrpinfo_t);
}
/* Rest of the tx group */
for (i = 0; i < tgrpnum - 1; i++) {
if (sizeof (dld_hwgrpinfo_t) > bytes_left) {
goto done;
}
sizeof (hwgrp.dhi_link_name));
if (hwgrp.dhi_n_rings == 0)
continue;
goto done;
}
hip++;
totgrps++;
bytes_left -= sizeof (dld_hwgrpinfo_t);
}
done:
if (err == 0)
return (err);
}
/* ARGSUSED */
static int
{
int i, err;
if (zoneid != GLOBAL_ZONEID &&
return (ENOENT);
if (err != 0)
goto done;
maip = (dld_macaddrinfo_t *)
if (sizeof (dld_macaddrinfo_t) > bytes_left) {
goto done;
}
if (i == 0) {
/* primary MAC address */
&is_used);
} else {
/* factory MAC address slot */
}
if (is_used)
goto done;
}
maip++;
bytes_left -= sizeof (dld_macaddrinfo_t);
}
done:
if (err == 0)
return (err);
}
/*
*/
static int
{
/*
* We only use pr_valsize from prop, as the caller only did a
* copyin() for sizeof (dld_ioc_prop_t), which doesn't cover
* the property data. We copyin the full dld_ioc_prop_t
* including the data into kprop down below.
*/
return (EINVAL);
/*
* The property data is variable size, so we need to allocate
* a buffer for kernel use as this data was not part of the
* prop allocation and copyin() done by the framework.
*/
return (ENOMEM);
goto done;
}
if (set) {
goto done;
}
goto done;
goto done;
goto done;
/*
* Don't allow a process to get or set properties of a link if that
* link doesn't belong to that zone.
*/
goto done;
}
goto done;
}
case MAC_PROP_ZONE:
if (set) {
if (zoneid != GLOBAL_ZONEID) {
goto done;
}
} else {
}
break;
case MAC_PROP_AUTOPUSH: {
if (set) {
if (kprop->pr_valsize != 0)
else
} else {
if (kprop->pr_valsize == 0)
return (ENOBUFS);
}
break;
}
case MAC_PROP_TAGMODE:
if (set) {
if (mode != LINK_TAGMODE_VLANONLY &&
mode != LINK_TAGMODE_NORMAL) {
} else {
err = 0;
}
} else {
err = 0;
}
break;
default: {
/* set a property value */
if (set) {
break;
}
/*
* Get the property value, default, or possible value
* depending on flags passed from the user.
*/
/* a property has RW permissions by default */
/*
* fail if rangep is not aligned to first
* member of mac_propval_range_t.
*/
}
/*
* Always return the permissions, and optionally return
* the default value or possible values range.
*/
if (err != 0)
goto done;
}
}
}
done:
}
}
return (err);
}
/* ARGSUSED */
static int
{
}
/* ARGSUSED */
static int
{
}
/*
* DLDIOC_RENAME.
*
* This function handles two cases of link renaming. See more in comments above
* dls_datalink_rename().
*/
/* ARGSUSED */
static int
{
int err;
if (zoneid != GLOBAL_ZONEID &&
return (ENOENT);
NULL)) != 0)
return (err);
return (err);
return (err);
return (0);
/*
* if dir_linkid2 is not DATALINK_INVALID_LINKID, it means this
* renaming request is to rename a valid physical link (dir_linkid1)
* to a "removed" physical link (dir_linkid2, which is removed by DR
* or during system shutdown). In this case, the link (specified by
* dir_linkid1) would inherit all the configuration of dir_linkid2,
* and dir_linkid1 and its configuration would be lost.
*
* Remove per-link autopush configuration of dir_linkid1 in this case.
*/
return (0);
}
return (0);
}
static int
{
int i;
return (EINVAL);
/*
* Validate that the specified list of modules exist.
*/
return (EINVAL);
}
return (ENOMEM);
}
(mod_hash_val_t)dap) == 0);
}
/*
* Update the configuration.
*/
FMNAMESZ + 1);
}
return (0);
}
static int
{
int i;
(mod_hash_val_t *)&dap) != 0) {
return (0);
}
/*
* Retrieve the configuration.
*/
FMNAMESZ + 1);
}
return (0);
}
static int
{
return (0);
}
return (0);
}
/*
* DLDIOC_DOORSERVER
*/
/* ARGSUSED */
static int
{
}
/*
* DLDIOC_USAGELOG
*/
/* ARGSUSED */
static int
int *rvalp)
{
int err = 0;
return (EINVAL);
} else {
}
return (err);
}
/*
* Process a DLDIOC_ADDFLOW request.
*/
/* ARGSUSED */
static int
{
}
/*
* Process a DLDIOC_REMOVEFLOW request.
*/
/* ARGSUSED */
static int
{
}
/*
* Process a DLDIOC_MODIFYFLOW request.
*/
/* ARGSUSED */
static int
{
}
/*
* Process a DLDIOC_WALKFLOW request.
*/
/* ARGSUSED */
static int
{
}
/*
* Check for GLDv3 autopush information. There are three cases:
*
* 1. If devp points to a GLDv3 datalink and it has autopush configuration,
* fill dlap in with that information and return 0.
*
* 2. If devp points to a GLDv3 datalink but it doesn't have autopush
* configuration, then replace devp with the physical device (if one
* exists) and return 1. This allows stropen() to find the old-school
* per-driver autopush configuration. (For softmac, the result is that
* the softmac dev_t is replaced with the legacy device's dev_t).
*
* 3. If neither of the above apply, don't touch the args and return -1.
*/
int
{
return (-1);
/*
* Find the linkid by the link's dev_t.
*/
return (-1);
/*
* Find the autopush configuration associated with the linkid.
*/
(mod_hash_val_t *)&dap) == 0) {
return (0);
}
return (-1);
return (1);
}
/*
* Secure objects implementation
*/
/* ARGSUSED */
static int
{
return (0);
}
static void
drv_secobj_init(void)
{
}
static void
drv_secobj_fini(void)
{
}
/* ARGSUSED */
static int
{
int err;
return (EINVAL);
return (EINVAL);
(mod_hash_val_t *)&objp);
if (err == 0) {
return (EEXIST);
}
} else {
return (ENOENT);
}
}
return (0);
}
typedef struct dld_secobj_state {
int ss_rc;
int ss_mode;
/* ARGSUSED */
static uint_t
{
return (MH_WALK_TERMINATE);
}
return (MH_WALK_TERMINATE);
}
return (MH_WALK_CONTINUE);
}
/* ARGSUSED */
static int
{
int err;
return (EINVAL);
if (err != 0) {
return (ENOENT);
}
} else {
sizeof (dld_ioc_secobj_get_t));
}
}
return (0);
}
/* ARGSUSED */
static int
int *rvalp)
{
int err;
return (EINVAL);
(mod_hash_val_t *)&objp);
if (err != 0) {
return (ENOENT);
}
(mod_hash_val_t *)&val) == 0);
return (0);
}
/*
* Note that ioctls that modify links have a NULL di_priv_func(), as
* privileges can only be checked after we know the class of the link being
* modified (due to class-specific fine-grained privileges such as
* sys_iptun_config).
*/
drv_ioc_attr, NULL},
};
typedef struct dld_ioc_modentry {
/*
* For all modules except for dld, dim_list and dim_count are assigned
* when the modules register their ioctls in dld_ioc_register(). We
* can statically initialize dld's ioctls in-line here; there's no
* need for it to call dld_ioc_register() itself. ctrl_node_inst controls
* whether an instance of the device will be held or the driver. If set to
* a non-negative integer, device instance specified in ctrl_node_inst will
* be held; so dld_ioc_register() _must_ be called in xxx_attach() routine of
* the driver. If set to -1, driver will be held; so dld_ioc_register() _must_
* be called in xxx_init() routine of the driver.
*/
};
#define DLDIOC_CNT \
(sizeof (dld_ioc_modtable) / sizeof (dld_ioc_modentry_t))
static dld_ioc_modentry_t *
{
int i;
for (i = 0; i < DLDIOC_CNT; i++) {
return (&dld_ioc_modtable[i]);
}
return (NULL);
}
int
{
return (ENOENT);
return (0);
}
void
{
}
/*
* The general design with GLDv3 ioctls is that all ioctls issued
* function handles all ioctls on behalf of modules listed in
* dld_ioc_modtable.
*
* When an ioctl is received, this function looks for the associated
* module-id-specific ioctl information using dld_ioc_findmod(). The
* call to ddi_hold_driver() or ddi_hold_devi_by_instance() on the
* associated device will cause the kernel module responsible for the
* ioctl to be loaded if it's not already loaded, which should result
* in that module calling dld_ioc_register(), thereby filling in the
* dim_list containing the details for the ioctl being processed.
*
* This function can then perform operations such as copyin() data and
* do credential checks based on the registered ioctl information,
* then issue the callback function di_func() registered by the
* responsible module. Upon return, the appropriate copyout()
* operation can be performed and the operation completes.
*/
/* ARGSUSED */
static int
{
int i, err;
return (ENOTSUP);
/*
* No dedicated instance to process ioctls.
* dld_ioc_register() is called in xxx_init().
*/
} else {
/*
* Dedicated instance to handle ioctl.
* dld_ioc_register() is called in xxx_attach().
*/
}
goto done;
}
break;
}
goto done;
}
goto done;
goto done;
}
goto done;
}
done:
return (err);
}