2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A
2N/A/*
2N/A * Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.
2N/A */
2N/A
2N/A#ifndef _LIBDLPI_IMPL_H
2N/A#define _LIBDLPI_IMPL_H
2N/A
2N/A#include <libdlpi.h>
2N/A#include <sys/sysmacros.h>
2N/A
2N/A#ifdef __cplusplus
2N/Aextern "C" {
2N/A#endif
2N/A
2N/A/*
2N/A * Maximum DLPI response size, in bytes.
2N/A */
2N/A#define DLPI_CHUNKSIZE 8192
2N/A
2N/A/*
2N/A * Maximum SAP length, in bytes.
2N/A */
2N/A#define DLPI_SAPLEN_MAX 4
2N/A
2N/A/*
2N/A * Number of elements in 'arr'.
2N/A */
2N/A#define NELEMS(arr) (sizeof (arr) / sizeof ((arr)[0]))
2N/A
2N/A/*
2N/A * Allocate buffer size for DLPI message, in bytes and set DLPI primitive.
2N/A */
2N/A#define DLPI_MSG_CREATE(dlmsg, dlprimitive) \
2N/A (dlmsg).dlm_msgsz = i_dlpi_getprimsize((dlprimitive)); \
2N/A (dlmsg).dlm_msg = alloca((dlmsg).dlm_msgsz); \
2N/A (dlmsg).dlm_msg->dl_primitive = (dlprimitive);
2N/A
2N/A/*
2N/A * Publicly available DLPI notification types. This list may change if
2N/A * new DLPI notification types are made public. See dlpi(7P).
2N/A *
2N/A */
2N/A#define DLPI_NOTIFICATION_TYPES (DL_NOTE_LINK_DOWN | DL_NOTE_LINK_UP | \
2N/A DL_NOTE_PHYS_ADDR | DL_NOTE_SDU_SIZE | DL_NOTE_SPEED | \
2N/A DL_NOTE_PROMISC_ON_PHYS | DL_NOTE_PROMISC_OFF_PHYS | \
2N/A DL_NOTE_FC_MODE|DL_NOTE_ETSBAT)
2N/A
2N/A/*
2N/A * Used in a mactype lookup table.
2N/A */
2N/Atypedef struct dlpi_mactype_s {
2N/A uint_t dm_mactype; /* DLPI/Private mactype */
2N/A char *dm_desc; /* Description of mactype */
2N/A} dlpi_mactype_t;
2N/A
2N/A/*
2N/A * Used to get the maximum DLPI message buffer size, in bytes.
2N/A */
2N/Atypedef struct dlpi_primsz {
2N/A t_uscalar_t dp_prim; /* store DLPI primitive */
2N/A size_t dp_primsz;
2N/A /* max. message size, in bytes, for dp_prim */
2N/A} dlpi_primsz_t;
2N/A
2N/A/*
2N/A * Used to create DLPI message.
2N/A */
2N/Atypedef struct dlpi_msg {
2N/A union DL_primitives *dlm_msg;
2N/A /* store DLPI primitive message */
2N/A size_t dlm_msgsz;
2N/A /* provide buffer size for dlm_msg */
2N/A} dlpi_msg_t;
2N/A
2N/Atypedef struct dlpi_notifyent {
2N/A uint_t dln_notes;
2N/A /* notification types registered */
2N/A dlpi_notifyfunc_t *dln_fnp;
2N/A /* callback to call */
2N/A void *arg; /* argument to pass to callback */
2N/A uint_t dln_rm; /* true if should be removed */
2N/A struct dlpi_notifyent *dln_next;
2N/A} dlpi_notifyent_t;
2N/A
2N/A/*
2N/A * Private libdlpi structure associated with each DLPI handle.
2N/A */
2N/Atypedef struct dlpi_impl_s {
2N/A int dli_fd; /* fd attached to stream */
2N/A int dli_timeout; /* timeout for operations, in sec */
2N/A char dli_linkname[MAXLINKNAMESPECIFIER];
2N/A /* full linkname including PPA */
2N/A char dli_provider[DLPI_LINKNAME_MAX];
2N/A /* only provider name */
2N/A t_uscalar_t dli_style; /* style 1 or 2 */
2N/A uint_t dli_saplen; /* bound SAP length */
2N/A uint_t dli_sap; /* bound SAP value */
2N/A boolean_t dli_sapbefore; /* true if SAP precedes address */
2N/A uint_t dli_ppa; /* physical point of attachment */
2N/A uint_t dli_mactype; /* mac type */
2N/A uint_t dli_oflags; /* flags set at open */
2N/A uint_t dli_note_processing;
2N/A /* true if notification is being */
2N/A /* processed */
2N/A dlpi_notifyent_t *dli_notifylistp;
2N/A /* list of registered notifications */
2N/A} dlpi_impl_t;
2N/A
2N/A/*
2N/A * dlpi_info() version support notes:
2N/A *
2N/A * We have bumped the version field to 1 in support of a larger dlpi_info_t
2N/A * structure that can hold linknames upto MAXLINKNAMESPECIFIER size. We need to
2N/A * support clients passing both version 0 and version 1. In particular, there
2N/A * are three cases we need to support:
2N/A *
2N/A * (a) Existing client binaries that pass version 0 and have a dlpi_info_t
2N/A * structure in the binary that is of version 0. libdlpi at runtime should
2N/A * copy in the version 0 dlpi_info_t back to the caller.
2N/A * (b) Existing client source compiled against libdlpi but continue to use
2N/A * version 0. The client when compiled using libdlpi.h should see the
2N/A * version 0 dlpi_info_t structure as that is the version of the structure
2N/A * we will copy back to the caller at runtime.
2N/A * (c) Finally, new clients modified to use version 1. New clients should
2N/A * be able to see version 1 dlpi_info_t from the libdlpi.h file and at
2N/A * runtime libdlpi should copy over the version 1 dlpi_info_t structure
2N/A * to the caller.
2N/A *
2N/A * We cannot modify dlpi_info_t in libdlpi.h for all clients because case (b)
2N/A * above will fail as clients passing version 0 should continue to receive the
2N/A * version 0 dlpi_info_t structure from the libdlpi.h header file. So libdlpi.h
2N/A * has to expose version 0 of the dlpi_info_t structure to existing clients
2N/A * compiled in future and expose version 1 of the dlpi_info_t structure to new
2N/A * clients passing version 1. The way we support this is by requiring new
2N/A * clients to pre-define DLPI_INFO_VERSION to value 1 before including libdlpi.h
2N/A *
2N/A * New clients that define the DLPI_INFO_VERSION to value 1 will see the
2N/A * updated version 1 of the dlpi_info_t structure from libdlpi.h header file.
2N/A * But if a new client passes value 1 but does not pre-define DLPI_INFO_VERSION
2N/A * to 1 then client will run into silent failures as we will copy over version
2N/A * 1 of the structure whereas the client has been compiled with version 0 of the
2N/A * structure. Similarly if client passes value 0 even when the client has
2N/A * pre-defined DLPI_INFO_VERSION to be 1, silent failures will occur.
2N/A * Unfortunately we cannot detect either of these cases at runtime in libdlpi
2N/A * and return an error to the caller.
2N/A *
2N/A * Existing clients will require no changes and will continue to work when
2N/A * compiled and run using libdlpi. There is also the question of which version
2N/A * of the dlpi_info_t structure that libdlpi is compiled with. We could compile
2N/A * libdlpi with either version 1 or 0. libdlpi is currently compiled to use
2N/A * version 0 of the dlpi_info_t structure.
2N/A */
2N/A
2N/A/*
2N/A * Version 1 dlpi_info_t. When callers pass version 1 this structure will be
2N/A * used by the dlpi_info() call. libdlpi is compiled with version 0 so the
2N/A * dlpi_info_t from libdlpi.h is of version 0 and is used when callers pass
2N/A * version 0. If libdlpi is compiled to use version 1 then we would need
2N/A * a similar private dlpi_info_t in support of version 0.
2N/A */
2N/Atypedef struct {
2N/A uint_t di_opts;
2N/A uint_t di_max_sdu;
2N/A uint_t di_min_sdu;
2N/A uint_t di_state;
2N/A uint_t di_mactype;
2N/A char di_linkname[MAXLINKNAMESPECIFIER];
2N/A uchar_t di_physaddr[DLPI_PHYSADDR_MAX];
2N/A uchar_t di_physaddrlen;
2N/A uchar_t di_bcastaddr[DLPI_PHYSADDR_MAX];
2N/A uchar_t di_bcastaddrlen;
2N/A uint_t di_sap;
2N/A int di_timeout;
2N/A dl_qos_cl_sel1_t di_qos_sel;
2N/A dl_qos_cl_range1_t di_qos_range;
2N/A} dlpi_info_vers1_t;
2N/A
2N/A/*
2N/A * Supported versions for dlpi_info(3DLPI). To specify version 1 callers must
2N/A * define DLPI_INFO_VERSION to value 1 and pass caller defined DLPI_INFO_VERSION
2N/A * constant to dlpi_info().
2N/A */
2N/A#define DLPI_INFO_VERS0 0
2N/A#define DLPI_INFO_VERS1 1
2N/A#define DLPI_INFO_MAXVERSION DLPI_INFO_VERS1
2N/A
2N/A/*
2N/A * Private macros to set/get/copy either the dlpi_info_vers1_t
2N/A * structure or the dlpi_info_t structure based on the given
2N/A * version argument to dlpi_info() call.
2N/A */
2N/A#define _DLPI_INFO_SET(info, version, option, value) { \
2N/A dlpi_info_vers1_t *infopv1; \
2N/A dlpi_info_t *infopv0; \
2N/A if ((version) == DLPI_INFO_VERS0) { \
2N/A infopv0 = (dlpi_info_t *)(info); \
2N/A infopv0->option = (value); \
2N/A } else { \
2N/A infopv1 = (dlpi_info_vers1_t *)(info); \
2N/A infopv1->option = (value); \
2N/A } \
2N/A}
2N/A
2N/A#define _DLPI_INFO_GET(info, version, option) \
2N/A (((version) == DLPI_INFO_VERS0) ? (((dlpi_info_t *) \
2N/A (info))->option) : (((dlpi_info_vers1_t *)(info))->option))
2N/A
2N/A#define _DLPI_INFO_GETADDR(info, version, option) \
2N/A ((((version) == DLPI_INFO_VERS0) ? (void *)&((dlpi_info_t *) \
2N/A (info))->option : (void *)&((dlpi_info_vers1_t *)(info))->option))
2N/A
2N/A#define _DLPI_INFO_COPY(info, version, option, datap, datalen) { \
2N/A (void) memcpy((_DLPI_INFO_GETADDR(info, version, option)), \
2N/A (datap), (datalen)); \
2N/A}
2N/A
2N/A#ifdef __cplusplus
2N/A}
2N/A#endif
2N/A
2N/A#endif /* _LIBDLPI_IMPL_H */