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