12882Svi117747 /* 22882Svi117747 * CDDL HEADER START 32882Svi117747 * 42882Svi117747 * The contents of this file are subject to the terms of the 52882Svi117747 * Common Development and Distribution License (the "License"). 62882Svi117747 * You may not use this file except in compliance with the License. 72882Svi117747 * 82882Svi117747 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 92882Svi117747 * or http://www.opensolaris.org/os/licensing. 102882Svi117747 * See the License for the specific language governing permissions 112882Svi117747 * and limitations under the License. 122882Svi117747 * 132882Svi117747 * When distributing Covered Code, include this CDDL HEADER in each 142882Svi117747 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 152882Svi117747 * If applicable, add the following below this CDDL HEADER, with the 162882Svi117747 * fields enclosed by brackets "[]" replaced with your own identifying 172882Svi117747 * information: Portions Copyright [yyyy] [name of copyright owner] 182882Svi117747 * 192882Svi117747 * CDDL HEADER END 202882Svi117747 */ 212882Svi117747 222882Svi117747 /* 23*5842Sgm209912 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 242882Svi117747 * Use is subject to license terms. 252882Svi117747 */ 262882Svi117747 272882Svi117747 #ifndef _SIP_MISCDEFS_H 282882Svi117747 #define _SIP_MISCDEFS_H 292882Svi117747 302882Svi117747 #pragma ident "%Z%%M% %I% %E% SMI" 312882Svi117747 322882Svi117747 #ifdef __cplusplus 332882Svi117747 extern "C" { 342882Svi117747 #endif 352882Svi117747 363439Svi117747 #include <pthread.h> 372882Svi117747 #include <sys/types.h> 383439Svi117747 #include <sys/time.h> 39*5842Sgm209912 #include <stdio.h> 402882Svi117747 412882Svi117747 #define SIP_CR '\r' 422882Svi117747 #define SIP_SP ' ' 432882Svi117747 #define SIP_HCOLON ':' 442882Svi117747 #define SIP_SEMI ';' 452882Svi117747 #define SIP_COMMA ',' 462882Svi117747 #define SIP_LAQUOT '<' 472882Svi117747 #define SIP_RAQUOT '>' 482882Svi117747 #define SIP_QUOTE '"' 492882Svi117747 #define SIP_EQUAL '=' 502882Svi117747 #define SIP_SLASH '/' 512882Svi117747 #define SIP_PERIOD '.' 522882Svi117747 #define SIP_LPAR '(' 532882Svi117747 #define SIP_RPAR ')' 542882Svi117747 552882Svi117747 #define SIP_BRANCHID_LEN 28 /* incl. the magic cookie */ 562882Svi117747 #define SIP_TAG_LEN 20 572882Svi117747 #define SIP_URI_LEN 25 582882Svi117747 #define SIP_DISPLAY_LEN 25 592882Svi117747 #define SIP_DOMAIN_LEN 25 602882Svi117747 #define SIP_MAX_FWDLEN 5 612882Svi117747 #define SIP_TRANSPORT_LEN 5 622882Svi117747 #define SIP_SIZE_OF_STATUS_CODE 3 632882Svi117747 #define SIP_SPACE_LEN sizeof (char) 642882Svi117747 65*5842Sgm209912 #define SIP_TRANSACTION_LOG 0x0001 66*5842Sgm209912 #define SIP_DIALOG_LOG 0x0002 67*5842Sgm209912 #define SIP_ASSERT_ERROR 0x0004 68*5842Sgm209912 692882Svi117747 #define SIP_MS 1L 702882Svi117747 #define SIP_SECONDS (1000 * SIP_MS) 712882Svi117747 #define SIP_MINUTES (60 * SIP_SECONDS) 722882Svi117747 #define SIP_HOURS (60 * SIP_MINUTES) 732882Svi117747 742882Svi117747 /* timer granularity is in msecs */ 752882Svi117747 #define SIP_TIMER_T1 (1 * SIP_SECONDS) 762882Svi117747 #define SIP_TIMER_T2 (4 * SIP_SECONDS) 772882Svi117747 #define SIP_TIMER_T4 (5 * SIP_SECONDS) 782882Svi117747 792882Svi117747 #ifdef __linux__ 802882Svi117747 #define SEC 1 812882Svi117747 #define MILLISEC 1000 822882Svi117747 #define MICROSEC 1000000 832882Svi117747 #define NANOSEC 1000000000 842882Svi117747 852882Svi117747 typedef struct timespec timestruc_t; 862882Svi117747 typedef long long hrtime_t; 872882Svi117747 #endif 882882Svi117747 892882Svi117747 extern int sip_timer_T1; 902882Svi117747 extern int sip_timer_T2; 912882Svi117747 extern int sip_timer_T4; 922882Svi117747 extern int sip_timer_TD; 932882Svi117747 942882Svi117747 /* Structure for SIP timers */ 952882Svi117747 typedef struct sip_timer_s { 962882Svi117747 uint_t sip_timerid; 972882Svi117747 struct timeval sip_timeout_val; 982882Svi117747 }sip_timer_t; 992882Svi117747 1002882Svi117747 /* time is in msec */ 1012882Svi117747 #define SIP_SET_TIMEOUT(timer, time) { \ 1022882Svi117747 int mtime = (time); \ 1032882Svi117747 \ 1042882Svi117747 (timer).sip_timeout_val.tv_sec = mtime / MILLISEC; \ 1052882Svi117747 mtime -= (timer).sip_timeout_val.tv_sec * MILLISEC; \ 1062882Svi117747 (timer).sip_timeout_val.tv_usec = mtime * MILLISEC; \ 1072882Svi117747 } 1082882Svi117747 1092882Svi117747 /* time is in msec */ 1102882Svi117747 #define SIP_INIT_TIMER(timer, time) { \ 1112882Svi117747 SIP_SET_TIMEOUT(timer, time); \ 1122882Svi117747 (timer).sip_timerid = 0; \ 1132882Svi117747 } 1142882Svi117747 1152882Svi117747 #define SIP_SCHED_TIMER(timer, obj, func) { \ 1162882Svi117747 (timer).sip_timerid = sip_stack_timeout((void *)(obj), \ 1172882Svi117747 (func), &((timer).sip_timeout_val)); \ 1182882Svi117747 } 1192882Svi117747 1202882Svi117747 #define SIP_CANCEL_TIMER(timer) { \ 1212882Svi117747 if ((timer).sip_timerid != 0) { \ 1222882Svi117747 sip_stack_untimeout((timer).sip_timerid); \ 1232882Svi117747 (timer).sip_timerid = 0; \ 1242882Svi117747 } \ 1252882Svi117747 } 1262882Svi117747 1272882Svi117747 /* returned time is in msec */ 1282882Svi117747 #define SIP_GET_TIMEOUT(timer) \ 1292882Svi117747 ((timer).sip_timeout_val.tv_sec * MILLISEC + \ 1302882Svi117747 (timer).sip_timeout_val.tv_usec / MILLISEC) 1312882Svi117747 1322882Svi117747 #define SIP_IS_TIMER_RUNNING(timer) ((timer).sip_timerid != 0) 1332882Svi117747 134*5842Sgm209912 #define SIP_UPDATE_COUNTERS(is_request, method, resp_code, outbound, size) { \ 135*5842Sgm209912 (void) pthread_mutex_lock(&sip_counters.sip_counter_mutex); \ 136*5842Sgm209912 if (sip_counters.enabled) { \ 137*5842Sgm209912 (void) sip_measure_traffic((is_request), (method), (resp_code),\ 138*5842Sgm209912 (outbound), (size)); \ 139*5842Sgm209912 } \ 140*5842Sgm209912 (void) pthread_mutex_unlock(&sip_counters.sip_counter_mutex); \ 141*5842Sgm209912 } 142*5842Sgm209912 1432882Svi117747 /* This is the transaction list */ 1442882Svi117747 typedef struct sip_conn_cache_s { 1452882Svi117747 void *obj; 1462882Svi117747 struct sip_conn_cache_s *next; 1472882Svi117747 struct sip_conn_cache_s *prev; 1482882Svi117747 } sip_conn_cache_t; 1492882Svi117747 1502882Svi117747 /* TCP fragment entry */ 1512882Svi117747 typedef struct sip_reass_entry_s { 1522882Svi117747 char *sip_reass_msg; 1532882Svi117747 int sip_reass_msglen; 1542882Svi117747 }sip_reass_entry_t; 1552882Svi117747 1562882Svi117747 /* Library data in stored in connection object */ 1572882Svi117747 typedef struct sip_conn_obj_pvt_s { 1582882Svi117747 sip_reass_entry_t *sip_conn_obj_reass; 1592882Svi117747 pthread_mutex_t sip_conn_obj_reass_lock; 1602882Svi117747 sip_conn_cache_t *sip_conn_obj_cache; 1612882Svi117747 pthread_mutex_t sip_conn_obj_cache_lock; 1622882Svi117747 } sip_conn_obj_pvt_t; 1632882Svi117747 164*5842Sgm209912 /* SIP traffic counters structure */ 165*5842Sgm209912 166*5842Sgm209912 typedef struct sip_traffic_counters_s { 167*5842Sgm209912 boolean_t enabled; 168*5842Sgm209912 time_t starttime; 169*5842Sgm209912 time_t stoptime; 170*5842Sgm209912 uint64_t sip_total_bytes_rcvd; 171*5842Sgm209912 uint64_t sip_total_bytes_sent; 172*5842Sgm209912 uint64_t sip_total_req_rcvd; 173*5842Sgm209912 uint64_t sip_total_req_sent; 174*5842Sgm209912 uint64_t sip_total_resp_rcvd; 175*5842Sgm209912 uint64_t sip_total_resp_sent; 176*5842Sgm209912 uint64_t sip_ack_req_rcvd; 177*5842Sgm209912 uint64_t sip_ack_req_sent; 178*5842Sgm209912 uint64_t sip_bye_req_rcvd; 179*5842Sgm209912 uint64_t sip_bye_req_sent; 180*5842Sgm209912 uint64_t sip_cancel_req_rcvd; 181*5842Sgm209912 uint64_t sip_cancel_req_sent; 182*5842Sgm209912 uint64_t sip_info_req_rcvd; 183*5842Sgm209912 uint64_t sip_info_req_sent; 184*5842Sgm209912 uint64_t sip_invite_req_rcvd; 185*5842Sgm209912 uint64_t sip_invite_req_sent; 186*5842Sgm209912 uint64_t sip_notify_req_rcvd; 187*5842Sgm209912 uint64_t sip_notify_req_sent; 188*5842Sgm209912 uint64_t sip_options_req_rcvd; 189*5842Sgm209912 uint64_t sip_options_req_sent; 190*5842Sgm209912 uint64_t sip_prack_req_rcvd; 191*5842Sgm209912 uint64_t sip_prack_req_sent; 192*5842Sgm209912 uint64_t sip_refer_req_rcvd; 193*5842Sgm209912 uint64_t sip_refer_req_sent; 194*5842Sgm209912 uint64_t sip_register_req_rcvd; 195*5842Sgm209912 uint64_t sip_register_req_sent; 196*5842Sgm209912 uint64_t sip_subscribe_req_rcvd; 197*5842Sgm209912 uint64_t sip_subscribe_req_sent; 198*5842Sgm209912 uint64_t sip_update_req_rcvd; 199*5842Sgm209912 uint64_t sip_update_req_sent; 200*5842Sgm209912 uint64_t sip_1xx_resp_rcvd; 201*5842Sgm209912 uint64_t sip_1xx_resp_sent; 202*5842Sgm209912 uint64_t sip_2xx_resp_rcvd; 203*5842Sgm209912 uint64_t sip_2xx_resp_sent; 204*5842Sgm209912 uint64_t sip_3xx_resp_rcvd; 205*5842Sgm209912 uint64_t sip_3xx_resp_sent; 206*5842Sgm209912 uint64_t sip_4xx_resp_rcvd; 207*5842Sgm209912 uint64_t sip_4xx_resp_sent; 208*5842Sgm209912 uint64_t sip_5xx_resp_rcvd; 209*5842Sgm209912 uint64_t sip_5xx_resp_sent; 210*5842Sgm209912 uint64_t sip_6xx_resp_rcvd; 211*5842Sgm209912 uint64_t sip_6xx_resp_sent; 212*5842Sgm209912 pthread_mutex_t sip_counter_mutex; /* Mutex should be always at end */ 213*5842Sgm209912 } sip_traffic_counters_t; 214*5842Sgm209912 215*5842Sgm209912 /* SIP logfile structure */ 216*5842Sgm209912 typedef struct sip_logfile_s { 217*5842Sgm209912 boolean_t sip_logging_enabled; 218*5842Sgm209912 FILE *sip_logfile; 219*5842Sgm209912 pthread_mutex_t sip_logfile_mutex; 220*5842Sgm209912 } sip_logfile_t; 221*5842Sgm209912 222*5842Sgm209912 typedef struct sip_msg_chain_s { 223*5842Sgm209912 char *sip_msg; 224*5842Sgm209912 int msg_seq; 225*5842Sgm209912 time_t msg_timestamp; 226*5842Sgm209912 struct sip_msg_chain_s *next; 227*5842Sgm209912 }sip_msg_chain_t; 228*5842Sgm209912 229*5842Sgm209912 typedef struct sip_log_s { 230*5842Sgm209912 sip_msg_chain_t *sip_msgs; 231*5842Sgm209912 int sip_msgcnt; 232*5842Sgm209912 }sip_log_t; 233*5842Sgm209912 234*5842Sgm209912 extern sip_traffic_counters_t sip_counters; 235*5842Sgm209912 236*5842Sgm209912 extern sip_logfile_t trans_log; 237*5842Sgm209912 extern sip_logfile_t dialog_log; 238*5842Sgm209912 2392882Svi117747 extern boolean_t sip_manage_dialog; 2402882Svi117747 2412882Svi117747 /* To salt the hash function */ 2422882Svi117747 extern uint64_t sip_hash_salt; 2432882Svi117747 2442882Svi117747 extern void sip_timeout_init(); 2452882Svi117747 extern uint_t sip_timeout(void *, void (*)(void *), struct timeval *); 2462882Svi117747 extern boolean_t sip_untimeout(uint_t); 2472882Svi117747 extern void sip_md5_hash(char *, int, char *, int, char *, int, 2482882Svi117747 char *, int, char *, int, char *, int, uchar_t *); 249*5842Sgm209912 extern void sip_measure_traffic(boolean_t, sip_method_t, int, 250*5842Sgm209912 boolean_t, int); 251*5842Sgm209912 extern void sip_add_log(sip_log_t *, sip_msg_t, int, int); 252*5842Sgm209912 extern void sip_write_to_log(void *, int, char *, int); 2532882Svi117747 2542882Svi117747 #ifdef __cplusplus 2552882Svi117747 } 2562882Svi117747 #endif 2572882Svi117747 2582882Svi117747 #endif /* _SIP_MISCDEFS_H */ 259