xref: /illumos-gate/usr/src/uts/common/inet/common.h (revision 0fb96ba1f1ce26ff8b286f8f928769a6afcb00a6)
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 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 /* Copyright (c) 1990 Mentat Inc. */
26 
27 #ifndef	_INET_COMMON_H
28 #define	_INET_COMMON_H
29 
30 /*
31  * WARNING: This file contains implementation-specific constants, typedefs
32  *	    and macros which may change from release to release.
33  */
34 
35 #ifdef	__cplusplus
36 extern "C" {
37 #endif
38 
39 #include <sys/inttypes.h>
40 #include <sys/sysmacros.h>
41 #include <sys/mkdev.h>
42 
43 #define	A_CNT(arr)	(sizeof (arr) / sizeof (arr[0]))
44 #define	A_END(arr)	(&arr[A_CNT(arr)])
45 #define	A_LAST(arr)	(&arr[A_CNT(arr) - 1])
46 
47 #define	nilp(t)		((t *)0)
48 #define	nil(t)		((t)0)
49 #define	noop
50 
51 typedef	int	(*pfi_t)();
52 typedef	void	(*pfv_t)();
53 
54 #define	BE32_EQL(a, b)	(((uint8_t *)a)[0] == ((uint8_t *)b)[0] && \
55 	((uint8_t *)a)[1] == ((uint8_t *)b)[1] && \
56 	((uint8_t *)a)[2] == ((uint8_t *)b)[2] && \
57 	((uint8_t *)a)[3] == ((uint8_t *)b)[3])
58 #define	BE16_EQL(a, b)	(((uint8_t *)a)[0] == ((uint8_t *)b)[0] && \
59 	((uint8_t *)a)[1] == ((uint8_t *)b)[1])
60 #define	BE16_TO_U16(a)	((((uint16_t)((uint8_t *)a)[0] << 8) | \
61 	((uint16_t)((uint8_t *)a)[1])) & 0xFFFF)
62 #define	BE32_TO_U32(a)	((((uint32_t)((uint8_t *)a)[0]) << 24) | \
63 	(((uint32_t)((uint8_t *)a)[1]) << 16) | \
64 	(((uint32_t)((uint8_t *)a)[2]) << 8)  | \
65 	((uint32_t)((uint8_t *)a)[3]))
66 #define	U16_TO_BE16(u, a) ((((uint8_t *)a)[0] = (uint8_t)((u) >> 8)), \
67 	(((uint8_t *)a)[1] = (uint8_t)(u)))
68 #define	U32_TO_BE32(u, a) ((((uint8_t *)a)[0] = (uint8_t)((u) >> 24)), \
69 	(((uint8_t *)a)[1] = (uint8_t)((u) >> 16)), \
70 	(((uint8_t *)a)[2] = (uint8_t)((u) >> 8)), \
71 	(((uint8_t *)a)[3] = (uint8_t)(u)))
72 
73 /*
74  * Local Environment Definition, this may and should override the
75  * the default definitions above where the local environment differs.
76  */
77 #include <inet/led.h>
78 #include <sys/isa_defs.h>
79 
80 #ifdef	_BIG_ENDIAN
81 #define	ABE32_TO_U32(p)		(*((uint32_t *)p))
82 #define	ABE16_TO_U16(p)		(*((uint16_t *)p))
83 #define	U16_TO_ABE16(u, p)	(*((uint16_t *)p) = (u))
84 #define	U32_TO_ABE16(u, p)	U16_TO_ABE16(u, p)
85 #define	U32_TO_ABE32(u, p)	(*((uint32_t *)p) = (u))
86 #else
87 #define	ABE16_TO_U16(p)		BE16_TO_U16(p)
88 #define	ABE32_TO_U32(p)		BE32_TO_U32(p)
89 #define	U16_TO_ABE16(u, p)	U16_TO_BE16(u, p)
90 #define	U32_TO_ABE16(u, p)	U16_TO_ABE16(u, p)
91 #define	U32_TO_ABE32(u, p)	U32_TO_BE32(u, p)
92 #endif
93 
94 #define	INET_MIN_DEV		2	/* minimum minor device number */
95 
96 #ifdef _KERNEL
97 #include <sys/stream.h>
98 
99 extern void *inet_minor_create(char *, dev_t, dev_t, int);
100 extern void inet_minor_destroy(void *);
101 extern dev_t inet_minor_alloc(void *);
102 extern void inet_minor_free(void *, dev_t);
103 extern void inet_freemsg(mblk_t *);
104 
105 #endif	/* _KERNEL */
106 
107 #ifdef	__cplusplus
108 }
109 #endif
110 
111 #endif	/* _INET_COMMON_H */
112