49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre * CDDL HEADER START
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre * The contents of this file are subject to the terms of the
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre * Common Development and Distribution License (the "License").
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre * You may not use this file except in compliance with the License.
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre * or http://www.opensolaris.org/os/licensing.
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre * See the License for the specific language governing permissions
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre * and limitations under the License.
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre * When distributing Covered Code, include this CDDL HEADER in each
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre * If applicable, add the following below this CDDL HEADER, with the
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre * fields enclosed by brackets "[]" replaced with your own identifying
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre * information: Portions Copyright [yyyy] [name of copyright owner]
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre * CDDL HEADER END
82629e3015252bf18319ba3815c773df23e21436Mike Christensen * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre * Use is subject to license terms.
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre * Logical Domains Device Agent
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre#define LDMA_NVERSIONS (sizeof (ldma_versions) / sizeof (ds_ver_t))
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre#define LDMA_NHANDLERS (sizeof (ldma_handlers) / sizeof (ldma_msg_handler_t))
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartrestatic ldm_msg_func_t ldma_dev_validate_path;
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartrestatic ldm_msg_func_t ldma_dev_validate_nic;
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartrestatic ds_ver_t ldma_versions[] = { { 1, 0 } };
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartrestatic ldma_msg_handler_t ldma_handlers[] = {
82629e3015252bf18319ba3815c773df23e21436Mike Christensen { LDMA_MSGDEV_VALIDATE_PATH, LDMA_MSGFLG_ACCESS_CONTROL,
82629e3015252bf18319ba3815c773df23e21436Mike Christensen { LDMA_MSGDEV_VALIDATE_NIC, LDMA_MSGFLG_ACCESS_CONTROL,
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartreldma_dev_validate_path(ds_ver_t *ver, ldma_message_header_t *request,
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre size_t request_dlen, ldma_message_header_t **replyp, size_t *reply_dlenp)
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre if (plen == 0 || plen > MAXPATHLEN || plen > request_dlen) {
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre (void) strncpy(path, LDMA_HDR2DATA(request), plen);
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre reply = ldma_alloc_result_msg(request, reply_dlen);
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre /* LINTED E_BAD_PTR_CAST_ALIGN */
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre path_type = (uint32_t *)(LDMA_HDR2DATA(reply));
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre /* check if path exists */
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre LDMA_DBG("VALIDATE_PATH(%s): stat failed with error %d",
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre /* path is inaccessible, the request is completed */
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre /* request has failed */
6b8303caf3c5c70ae1c1d362bf6de0c55eb622bbAlexandre Chartre LDMA_DBG("VALIDATE_PATH(%s): file mode = 0x%lx", path, st.st_mode);
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre /* we don't advertise other types (fifo, directory...) */
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre /* check if path can be opened read/write */
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre reply->msg_info |= LDMA_DEVPATH_OPENRW | LDMA_DEVPATH_OPENRO;
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre LDMA_DBG("VALIDATE_PATH(%s): open RDWR failed with error %d",
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre /* check if path can be opened read only */
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre LDMA_DBG("VALIDATE_PATH(%s): open RDONLY failed "
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre * We don't provide a reply message if the request has not
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre * been completed. The LDoms agent daemon will send an
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre * appropriate reply based on the return code of this function.
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre LDMA_DBG("VALIDATE_PATH(%s): return error %d",
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre LDMA_DBG("VALIDATE_PATH(%s): return status=0x%x type=0x%x",
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre * We check that the device is a network interface (NIC) using libdladm.
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartreldma_dev_validate_nic(ds_ver_t *ver, ldma_message_header_t *request,
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre size_t request_dlen, ldma_message_header_t **replyp, size_t *reply_dlenp)
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre if (nlen == 0 || nlen > MAXPATHLEN || nlen > request_dlen) {
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre (void) strncpy(nic, LDMA_HDR2DATA(request), nlen);
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre reply = ldma_alloc_result_msg(request, reply_dlen);
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre if (dladm_open(&dlhandle) != DLADM_STATUS_OK) {
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre if (dladm_name2info(dlhandle, nic, &linkid, &flag, &class,
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre LDMA_DBG("VALIDATE_NIC(%s): name2info failed", nic);
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre LDMA_DBG("VALIDATE_NIC(%s): media=0x%x", nic, media);
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre * We don't provide a reply message if the request has not
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre * been completed. The LDoms agent daemon will send an
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre * appropriate reply based on the return code of this function.
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre LDMA_DBG("VALIDATE_NIC(%s): return error %d",
49bfb42b00abac0958a1308f4233e366fd083366Alexandre Chartre LDMA_DBG("VALIDATE_NIC(%s): return status=0x%x",