xref: /titanic_50/usr/src/lib/libsip/common/sip_miscdefs.h (revision c77a61a72b5ecdc507d6cf104142edd371a16c84)
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 /*
23  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SIP_MISCDEFS_H
28 #define	_SIP_MISCDEFS_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #include <sys/types.h>
37 #include <sip.h>
38 
39 #define	SIP_CR			'\r'
40 #define	SIP_SP			' '
41 #define	SIP_HCOLON		':'
42 #define	SIP_SEMI		';'
43 #define	SIP_COMMA		','
44 #define	SIP_LAQUOT		'<'
45 #define	SIP_RAQUOT		'>'
46 #define	SIP_QUOTE		'"'
47 #define	SIP_EQUAL		'='
48 #define	SIP_SLASH		'/'
49 #define	SIP_PERIOD		'.'
50 #define	SIP_LPAR		'('
51 #define	SIP_RPAR		')'
52 
53 #define	SIP_BRANCHID_LEN	28	/* incl. the magic cookie */
54 #define	SIP_TAG_LEN		20
55 #define	SIP_URI_LEN		25
56 #define	SIP_DISPLAY_LEN		25
57 #define	SIP_DOMAIN_LEN		25
58 #define	SIP_MAX_FWDLEN		5
59 #define	SIP_TRANSPORT_LEN	5
60 #define	SIP_SIZE_OF_STATUS_CODE	3
61 #define	SIP_SPACE_LEN		sizeof (char)
62 
63 #define	SIP_MS			1L
64 #define	SIP_SECONDS		(1000 * SIP_MS)
65 #define	SIP_MINUTES		(60 * SIP_SECONDS)
66 #define	SIP_HOURS   		(60 * SIP_MINUTES)
67 
68 /* timer granularity is in msecs */
69 #define	SIP_TIMER_T1		(1 * SIP_SECONDS)
70 #define	SIP_TIMER_T2		(4 * SIP_SECONDS)
71 #define	SIP_TIMER_T4		(5 * SIP_SECONDS)
72 
73 #ifdef		__linux__
74 #define		SEC		1
75 #define		MILLISEC	1000
76 #define		MICROSEC	1000000
77 #define		NANOSEC		1000000000
78 
79 typedef struct timespec	timestruc_t;
80 typedef	long long	hrtime_t;
81 #endif
82 
83 extern int	sip_timer_T1;
84 extern int	sip_timer_T2;
85 extern int	sip_timer_T4;
86 extern int	sip_timer_TD;
87 
88 /* Structure for SIP timers */
89 typedef struct sip_timer_s {
90 	uint_t		sip_timerid;
91 	struct timeval	sip_timeout_val;
92 }sip_timer_t;
93 
94 /* time is in msec */
95 #define	SIP_SET_TIMEOUT(timer, time) {					\
96 	int	mtime = (time);						\
97 									\
98 	(timer).sip_timeout_val.tv_sec = mtime / MILLISEC;	\
99 	mtime -= (timer).sip_timeout_val.tv_sec * MILLISEC;	\
100 	(timer).sip_timeout_val.tv_usec = mtime * MILLISEC;		\
101 }
102 
103 /* time is in msec */
104 #define	SIP_INIT_TIMER(timer, time) {				\
105 	SIP_SET_TIMEOUT(timer, time);				\
106 	(timer).sip_timerid = 0;				\
107 }
108 
109 #define	SIP_SCHED_TIMER(timer, obj, func) {			\
110 	(timer).sip_timerid = sip_stack_timeout((void *)(obj),	\
111 	    (func), &((timer).sip_timeout_val));			\
112 }
113 
114 #define	SIP_CANCEL_TIMER(timer) {				\
115 	if ((timer).sip_timerid != 0) {				\
116 		sip_stack_untimeout((timer).sip_timerid);	\
117 		(timer).sip_timerid = 0;			\
118 	}							\
119 }
120 
121 /* returned time is in msec */
122 #define	SIP_GET_TIMEOUT(timer)					\
123 	((timer).sip_timeout_val.tv_sec * MILLISEC +		\
124 	(timer).sip_timeout_val.tv_usec / MILLISEC)
125 
126 #define	SIP_IS_TIMER_RUNNING(timer)	((timer).sip_timerid != 0)
127 
128 /* This is the transaction list */
129 typedef struct sip_conn_cache_s {
130 	void			*obj;
131 	struct sip_conn_cache_s	*next;
132 	struct sip_conn_cache_s	*prev;
133 } sip_conn_cache_t;
134 
135 /* TCP fragment entry */
136 typedef struct sip_reass_entry_s {
137 	char		*sip_reass_msg;
138 	int		sip_reass_msglen;
139 }sip_reass_entry_t;
140 
141 /* Library data in stored in connection object */
142 typedef struct sip_conn_obj_pvt_s {
143 	sip_reass_entry_t	*sip_conn_obj_reass;
144 	pthread_mutex_t		sip_conn_obj_reass_lock;
145 	sip_conn_cache_t	*sip_conn_obj_cache;
146 	pthread_mutex_t		sip_conn_obj_cache_lock;
147 } sip_conn_obj_pvt_t;
148 
149 extern boolean_t sip_manage_dialog;
150 
151 /* To salt the hash function */
152 extern uint64_t	sip_hash_salt;
153 
154 extern void		sip_timeout_init();
155 extern uint_t		sip_timeout(void *, void (*)(void *), struct timeval *);
156 extern boolean_t	sip_untimeout(uint_t);
157 extern void		sip_md5_hash(char *, int, char *, int, char *, int,
158 			    char *, int, char *, int, char *, int, uchar_t *);
159 
160 #ifdef	__cplusplus
161 }
162 #endif
163 
164 #endif	/* _SIP_MISCDEFS_H */
165