Home | History | Annotate | Download | only in common
      1 /*
      2  * CDDL HEADER START
      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 2009 Sun Microsystems, Inc.  All rights reserved.
     23  * Use is subject to license terms.
     24  */
     25 
     26 #ifndef	_LIBDLPI_IMPL_H
     27 #define	_LIBDLPI_IMPL_H
     28 
     29 #include <libdlpi.h>
     30 #include <sys/sysmacros.h>
     31 
     32 #ifdef __cplusplus
     33 extern "C" {
     34 #endif
     35 
     36 /*
     37  * Maximum DLPI response size, in bytes.
     38  */
     39 #define	DLPI_CHUNKSIZE	8192
     40 
     41 /*
     42  * Maximum SAP length, in bytes.
     43  */
     44 #define	DLPI_SAPLEN_MAX	4
     45 
     46 /*
     47  * Number of elements in 'arr'.
     48  */
     49 #define	NELEMS(arr)	(sizeof (arr) / sizeof ((arr)[0]))
     50 
     51 /*
     52  * Allocate buffer size for DLPI message, in bytes and set DLPI primitive.
     53  */
     54 #define	DLPI_MSG_CREATE(dlmsg, dlprimitive) \
     55 	(dlmsg).dlm_msgsz = i_dlpi_getprimsize((dlprimitive)); \
     56 	(dlmsg).dlm_msg = alloca((dlmsg).dlm_msgsz); \
     57 	(dlmsg).dlm_msg->dl_primitive = (dlprimitive);
     58 
     59 /*
     60  * Publicly available DLPI notification types. This list may change if
     61  * new DLPI notification types are made public. See dlpi(7P).
     62  *
     63  */
     64 #define	DLPI_NOTIFICATION_TYPES	(DL_NOTE_LINK_DOWN | DL_NOTE_LINK_UP | \
     65 	DL_NOTE_PHYS_ADDR | DL_NOTE_SDU_SIZE | DL_NOTE_SPEED | \
     66 	DL_NOTE_PROMISC_ON_PHYS | DL_NOTE_PROMISC_OFF_PHYS)
     67 
     68 /*
     69  * Used in a mactype lookup table.
     70  */
     71 typedef struct dlpi_mactype_s {
     72 	uint_t	dm_mactype;	/* DLPI/Private mactype */
     73 	char 	*dm_desc;	/* Description of mactype */
     74 } dlpi_mactype_t;
     75 
     76 /*
     77  * Used to get the maximum DLPI message buffer size, in bytes.
     78  */
     79 typedef struct dlpi_primsz {
     80 	t_uscalar_t	dp_prim;	/* store DLPI primitive */
     81 	size_t		dp_primsz;
     82 				/* max. message size, in bytes, for dp_prim */
     83 } dlpi_primsz_t;
     84 
     85 /*
     86  * Used to create DLPI message.
     87  */
     88 typedef struct dlpi_msg {
     89 	union DL_primitives	*dlm_msg;
     90 					/* store DLPI primitive message */
     91 	size_t			dlm_msgsz;
     92 					/* provide buffer size for dlm_msg */
     93 } dlpi_msg_t;
     94 
     95 typedef struct dlpi_notifyent {
     96 	uint_t			dln_notes;
     97 					/* notification types registered */
     98 	dlpi_notifyfunc_t	*dln_fnp;
     99 					/* callback to call */
    100 	void 			*arg;	/* argument to pass to callback */
    101 	uint_t			dln_rm;	/* true if should be removed */
    102 	struct dlpi_notifyent	*dln_next;
    103 } dlpi_notifyent_t;
    104 
    105 /*
    106  * Private libdlpi structure associated with each DLPI handle.
    107  */
    108 typedef struct dlpi_impl_s {
    109 	int		dli_fd;		/* fd attached to stream */
    110 	int		dli_timeout;	/* timeout for operations, in sec */
    111 	char		dli_linkname[DLPI_LINKNAME_MAX];
    112 					/* full linkname including PPA */
    113 	char		dli_provider[DLPI_LINKNAME_MAX];
    114 					/* only provider name */
    115 	t_uscalar_t	dli_style;	/* style 1 or 2 */
    116 	uint_t		dli_saplen;	/* bound SAP length */
    117 	uint_t		dli_sap;	/* bound SAP value */
    118 	boolean_t 	dli_sapbefore;	/* true if SAP precedes address */
    119 	uint_t		dli_ppa;	/* physical point of attachment */
    120 	uint_t		dli_mactype;	/* mac type */
    121 	uint_t		dli_oflags;	/* flags set at open */
    122 	uint_t		dli_note_processing;
    123 					/* true if notification is being */
    124 					/* processed */
    125 	dlpi_notifyent_t *dli_notifylistp;
    126 					/* list of registered notifications */
    127 } dlpi_impl_t;
    128 
    129 #ifdef __cplusplus
    130 }
    131 #endif
    132 
    133 #endif /* _LIBDLPI_IMPL_H */
    134