2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A
2N/A/*
2N/A * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
2N/A */
2N/A
2N/A#include <stdio.h>
2N/A#include <string.h>
2N/A#include <strings.h>
2N/A#include <stdlib.h>
2N/A#include <assert.h>
2N/A#include <ctype.h>
2N/A#include <errno.h>
2N/A#include <sip.h>
2N/A
2N/A#include "sip_msg.h"
2N/A#include "sip_miscdefs.h"
2N/A#include "sip_xaction.h"
2N/A#include "sip_dialog.h"
2N/A
2N/A#define TIME_BUF_SIZE 50
2N/A
2N/A/*
2N/A * Contains API's which enable/disable transaction or dialog logging,
2N/A * API's which records/measures SIP Traffic.
2N/A */
2N/A/*
2N/A * Needed for measuring SIP traffic counters.
2N/A */
2N/Asip_traffic_counters_t sip_counters;
2N/A
2N/A/*
2N/A * Needed for dialog/transaction logging.
2N/A */
2N/Asip_logfile_t trans_log;
2N/Asip_logfile_t dialog_log;
2N/A
2N/A/*
2N/A * This function increments the appropriate inbound/outbound counters for
2N/A * SIP requests/responses.
2N/A */
2N/Avoid
2N/Asip_measure_traffic(boolean_t is_request, sip_method_t method, int resp_code,
2N/A boolean_t outbound, int msg_size)
2N/A{
2N/A#ifdef __solaris__
2N/A assert(mutex_held(&sip_counters.sip_counter_mutex));
2N/A#endif
2N/A if (outbound)
2N/A sip_counters.sip_total_bytes_sent += msg_size;
2N/A else
2N/A sip_counters.sip_total_bytes_rcvd += msg_size;
2N/A
2N/A if (is_request) {
2N/A if (outbound)
2N/A ++sip_counters.sip_total_req_sent;
2N/A else
2N/A ++sip_counters.sip_total_req_rcvd;
2N/A switch (method) {
2N/A case INVITE:
2N/A if (outbound)
2N/A ++sip_counters.sip_invite_req_sent;
2N/A else
2N/A ++sip_counters.sip_invite_req_rcvd;
2N/A break;
2N/A case ACK:
2N/A if (outbound)
2N/A ++sip_counters.sip_ack_req_sent;
2N/A else
2N/A ++sip_counters.sip_ack_req_rcvd;
2N/A break;
2N/A case OPTIONS:
2N/A if (outbound)
2N/A ++sip_counters.sip_options_req_sent;
2N/A else
2N/A ++sip_counters.sip_options_req_rcvd;
2N/A break;
2N/A case BYE:
2N/A if (outbound)
2N/A ++sip_counters.sip_bye_req_sent;
2N/A else
2N/A ++sip_counters.sip_bye_req_rcvd;
2N/A break;
2N/A case CANCEL:
2N/A if (outbound)
2N/A ++sip_counters.sip_cancel_req_sent;
2N/A else
2N/A ++sip_counters.sip_cancel_req_rcvd;
2N/A break;
2N/A case REGISTER:
2N/A if (outbound)
2N/A ++sip_counters.sip_register_req_sent;
2N/A else
2N/A ++sip_counters.sip_register_req_rcvd;
2N/A break;
2N/A case REFER:
2N/A if (outbound)
2N/A ++sip_counters.sip_refer_req_sent;
2N/A else
2N/A ++sip_counters.sip_refer_req_rcvd;
2N/A break;
2N/A case INFO:
2N/A if (outbound)
2N/A ++sip_counters.sip_info_req_sent;
2N/A else
2N/A ++sip_counters.sip_info_req_rcvd;
2N/A break;
2N/A case SUBSCRIBE:
2N/A if (outbound)
2N/A ++sip_counters.sip_subscribe_req_sent;
2N/A else
2N/A ++sip_counters.sip_subscribe_req_rcvd;
2N/A break;
2N/A case NOTIFY:
2N/A if (outbound)
2N/A ++sip_counters.sip_notify_req_sent;
2N/A else
2N/A ++sip_counters.sip_notify_req_rcvd;
2N/A break;
2N/A case PRACK:
2N/A if (outbound)
2N/A ++sip_counters.sip_prack_req_sent;
2N/A else
2N/A ++sip_counters.sip_prack_req_rcvd;
2N/A break;
2N/A default:
2N/A break;
2N/A }
2N/A } else {
2N/A if (outbound)
2N/A ++sip_counters.sip_total_resp_sent;
2N/A else
2N/A ++sip_counters.sip_total_resp_rcvd;
2N/A if (SIP_PROVISIONAL_RESP(resp_code)) {
2N/A if (outbound)
2N/A ++sip_counters.sip_1xx_resp_sent;
2N/A else
2N/A ++sip_counters.sip_1xx_resp_rcvd;
2N/A } else if (SIP_OK_RESP(resp_code)) {
2N/A if (outbound)
2N/A ++sip_counters.sip_2xx_resp_sent;
2N/A else
2N/A ++sip_counters.sip_2xx_resp_rcvd;
2N/A } else if (SIP_REDIRECT_RESP(resp_code)) {
2N/A if (outbound)
2N/A ++sip_counters.sip_3xx_resp_sent;
2N/A else
2N/A ++sip_counters.sip_3xx_resp_rcvd;
2N/A } else if (SIP_REQFAIL_RESP(resp_code)) {
2N/A if (outbound)
2N/A ++sip_counters.sip_4xx_resp_sent;
2N/A else
2N/A ++sip_counters.sip_4xx_resp_rcvd;
2N/A } else if (SIP_SRVFAIL_RESP(resp_code)) {
2N/A if (outbound)
2N/A ++sip_counters.sip_5xx_resp_sent;
2N/A else
2N/A ++sip_counters.sip_5xx_resp_rcvd;
2N/A } else if (SIP_GLOBFAIL_RESP(resp_code)) {
2N/A if (outbound)
2N/A ++sip_counters.sip_6xx_resp_sent;
2N/A else
2N/A ++sip_counters.sip_6xx_resp_rcvd;
2N/A }
2N/A }
2N/A}
2N/A
2N/A/*
2N/A * Enables Transaction logging. The flags argument controls the detail
2N/A * of logging.
2N/A */
2N/Aint
2N/Asip_enable_trans_logging(FILE *logfile, int flags)
2N/A{
2N/A if (logfile == NULL || flags != SIP_DETAIL_LOGGING)
2N/A return (EINVAL);
2N/A
2N/A (void) pthread_mutex_lock(&trans_log.sip_logfile_mutex);
2N/A if (!trans_log.sip_logging_enabled) {
2N/A trans_log.sip_logfile = logfile;
2N/A trans_log.sip_logging_enabled = B_TRUE;
2N/A }
2N/A (void) pthread_mutex_unlock(&trans_log.sip_logfile_mutex);
2N/A return (0);
2N/A}
2N/A
2N/A
2N/A/*
2N/A * Enables dialog logging. The flags argument controls the detail
2N/A * of logging.
2N/A */
2N/Aint
2N/Asip_enable_dialog_logging(FILE *logfile, int flags)
2N/A{
2N/A if (logfile == NULL || flags != SIP_DETAIL_LOGGING)
2N/A return (EINVAL);
2N/A
2N/A (void) pthread_mutex_lock(&dialog_log.sip_logfile_mutex);
2N/A if (!dialog_log.sip_logging_enabled) {
2N/A dialog_log.sip_logfile = logfile;
2N/A dialog_log.sip_logging_enabled = B_TRUE;
2N/A }
2N/A (void) pthread_mutex_unlock(&dialog_log.sip_logfile_mutex);
2N/A return (0);
2N/A}
2N/A
2N/Avoid
2N/Asip_disable_trans_logging(void)
2N/A{
2N/A (void) pthread_mutex_lock(&trans_log.sip_logfile_mutex);
2N/A if (trans_log.sip_logging_enabled)
2N/A trans_log.sip_logging_enabled = B_FALSE;
2N/A (void) pthread_mutex_unlock(&trans_log.sip_logfile_mutex);
2N/A}
2N/A
2N/Avoid
2N/Asip_disable_dialog_logging(void)
2N/A{
2N/A (void) pthread_mutex_lock(&dialog_log.sip_logfile_mutex);
2N/A if (dialog_log.sip_logging_enabled)
2N/A dialog_log.sip_logging_enabled = B_FALSE;
2N/A (void) pthread_mutex_unlock(&dialog_log.sip_logfile_mutex);
2N/A}
2N/A
2N/Astatic void
2N/Asip_print_digest(uint16_t *digest, int len, FILE *fp)
2N/A{
2N/A int cnt;
2N/A
2N/A for (cnt = 0; cnt < len; cnt++)
2N/A (void) fprintf(fp, "%u ", digest[cnt]);
2N/A (void) fprintf(fp, "\n\n");
2N/A}
2N/A
2N/A/*
2N/A * Logs all the messages exchanged within a transaction to the transaction
2N/A * log file. Logged messages are then freed.
2N/A */
2N/Astatic void
2N/Asip_write_xaction_to_log(void *obj)
2N/A{
2N/A sip_xaction_t *trans = (sip_xaction_t *)obj;
2N/A sip_log_t *sip_log;
2N/A int count;
2N/A sip_msg_chain_t *msg_chain;
2N/A sip_msg_chain_t *nmsg_chain;
2N/A char timebuf[TIME_BUF_SIZE];
2N/A struct tm tms;
2N/A FILE *sip_trans_logfile = trans_log.sip_logfile;
2N/A
2N/A assert(trans != NULL && sip_trans_logfile != NULL);
2N/A (void) fprintf(sip_trans_logfile, "************* Begin Transaction"
2N/A " *************\n");
2N/A (void) fprintf(sip_trans_logfile, "Branchid\t\t: %s\n",
2N/A trans->sip_xaction_branch_id);
2N/A (void) fprintf(sip_trans_logfile, "Digest\t\t\t: ");
2N/A sip_print_digest(trans->sip_xaction_hash_digest, 8, sip_trans_logfile);
2N/A (void) fprintf(sip_trans_logfile, "-----------------------------\n");
2N/A for (count = 0; count <= SIP_SRV_NONINV_TERMINATED; count++) {
2N/A sip_log = &trans->sip_xaction_log[count];
2N/A if (sip_log->sip_msgcnt == 0)
2N/A continue;
2N/A (void) fprintf(sip_trans_logfile, "Transaction State\t: %s\n\n",
2N/A sip_get_xaction_state(count));
2N/A msg_chain = sip_log->sip_msgs;
2N/A while (msg_chain != NULL) {
2N/A nmsg_chain = msg_chain->next;
2N/A (void) strftime(timebuf, sizeof (timebuf), NULL,
2N/A localtime_r(&msg_chain->msg_timestamp, &tms));
2N/A (void) fprintf(sip_trans_logfile, "%s| Message -"
2N/A " %d\n%s", timebuf, msg_chain->msg_seq, msg_chain->
2N/A sip_msg);
2N/A free(msg_chain->sip_msg);
2N/A free(msg_chain);
2N/A --sip_log->sip_msgcnt;
2N/A msg_chain = nmsg_chain;
2N/A }
2N/A (void) fprintf(sip_trans_logfile,
2N/A "-----------------------------\n");
2N/A (trans->sip_xaction_log[count]).sip_msgs = NULL;
2N/A }
2N/A (void) fprintf(sip_trans_logfile, "************* End Transaction "
2N/A "*************\n");
2N/A (void) fflush(sip_trans_logfile);
2N/A}
2N/A
2N/A/*
2N/A * Logs all the messages exchanged within a dialog to the dialog
2N/A * log file. Logged messages are then freed.
2N/A */
2N/Astatic void
2N/Asip_write_dlg_to_log(void *obj)
2N/A{
2N/A _sip_dialog_t *dialog = (_sip_dialog_t *)obj;
2N/A sip_log_t *sip_log;
2N/A int count;
2N/A sip_msg_chain_t *msg_chain;
2N/A sip_msg_chain_t *nmsg_chain;
2N/A char timebuf[TIME_BUF_SIZE];
2N/A struct tm tms;
2N/A FILE *sip_dialog_logfile = dialog_log.sip_logfile;
2N/A
2N/A assert(dialog != NULL && sip_dialog_logfile != NULL);
2N/A
2N/A (void) fprintf(sip_dialog_logfile, "************* Begin Dialog "
2N/A "*************\n");
2N/A (void) fprintf(sip_dialog_logfile, "Digest\t\t\t: ");
2N/A sip_print_digest(dialog->sip_dlg_id, 8, sip_dialog_logfile);
2N/A (void) fprintf(sip_dialog_logfile, "-----------------------------\n");
2N/A for (count = 0; count <= SIP_DLG_DESTROYED; count++) {
2N/A sip_log = &dialog->sip_dlg_log[count];
2N/A if (sip_log->sip_msgcnt == 0)
2N/A continue;
2N/A (void) fprintf(sip_dialog_logfile, "Dialog State\t\t: %s\n\n",
2N/A sip_get_dialog_state_str(count));
2N/A msg_chain = sip_log->sip_msgs;
2N/A while (msg_chain != NULL) {
2N/A nmsg_chain = msg_chain->next;
2N/A (void) strftime(timebuf, sizeof (timebuf), NULL,
2N/A localtime_r(&msg_chain->msg_timestamp, &tms));
2N/A (void) fprintf(sip_dialog_logfile, "%s| Message -"
2N/A " %d\n%s", timebuf, msg_chain->msg_seq, msg_chain->
2N/A sip_msg);
2N/A free(msg_chain->sip_msg);
2N/A free(msg_chain);
2N/A --sip_log->sip_msgcnt;
2N/A msg_chain = nmsg_chain;
2N/A }
2N/A (void) fprintf(sip_dialog_logfile,
2N/A "-----------------------------\n");
2N/A (dialog->sip_dlg_log[count]).sip_msgs = NULL;
2N/A }
2N/A (void) fprintf(sip_dialog_logfile, "************* End Dialog "
2N/A "*************\n");
2N/A (void) fflush(sip_dialog_logfile);
2N/A}
2N/A
2N/A/*
2N/A * Calls the appropriate function to log transaction or dialog messages.
2N/A * If this function is called because of assertion failure, then the file and
2N/A * line where the assertion failed is logged to the log file.
2N/A */
2N/Avoid
2N/Asip_write_to_log(void *obj, int type, char *file, int line)
2N/A{
2N/A if (type & SIP_TRANSACTION_LOG) {
2N/A (void) pthread_mutex_lock(&trans_log.sip_logfile_mutex);
2N/A if (trans_log.sip_logging_enabled) {
2N/A if (type & SIP_ASSERT_ERROR) {
2N/A (void) fprintf(trans_log.sip_logfile,
2N/A "Assertion Failure at %s:%d\n", file, line);
2N/A }
2N/A sip_write_xaction_to_log(obj);
2N/A }
2N/A (void) pthread_mutex_unlock(&trans_log.sip_logfile_mutex);
2N/A } else {
2N/A (void) pthread_mutex_lock(&dialog_log.sip_logfile_mutex);
2N/A if (dialog_log.sip_logging_enabled) {
2N/A if (type & SIP_ASSERT_ERROR) {
2N/A (void) fprintf(dialog_log.sip_logfile,
2N/A "Assertion Failure at %s:%d\n", file, line);
2N/A }
2N/A sip_write_dlg_to_log(obj);
2N/A }
2N/A (void) pthread_mutex_unlock(&dialog_log.sip_logfile_mutex);
2N/A }
2N/A}
2N/A
2N/A/*
2N/A * This function records the messages that are exchanged within a dialog or
2N/A * transaction. If logging is enabled the recorded messages are then dumped
2N/A * to the log file just before deleting the transaction or dialog.
2N/A */
2N/Avoid
2N/Asip_add_log(sip_log_t *sip_log, sip_msg_t sip_msg, int seq, int type)
2N/A{
2N/A char *msgstr;
2N/A sip_msg_chain_t *new_msg;
2N/A sip_msg_chain_t *msg_chain = sip_log->sip_msgs;
2N/A
2N/A /*
2N/A * No need to take any locks here. Caller of this function MUST
2N/A * have already taken the transaction or dialog lock.
2N/A */
2N/A if (((type == SIP_DIALOG_LOG) && !dialog_log.sip_logging_enabled) ||
2N/A ((type == SIP_TRANSACTION_LOG) && !trans_log.sip_logging_enabled)) {
2N/A return;
2N/A }
2N/A
2N/A new_msg = calloc(1, sizeof (sip_msg_chain_t));
2N/A if (new_msg == NULL)
2N/A return;
2N/A
2N/A msgstr = sip_msg_to_str(sip_msg, NULL);
2N/A if (msgstr == NULL) {
2N/A free(new_msg);
2N/A return;
2N/A }
2N/A
2N/A new_msg->sip_msg = msgstr;
2N/A new_msg->msg_seq = seq;
2N/A new_msg->msg_timestamp = time(NULL);
2N/A new_msg->next = NULL;
2N/A if (sip_log->sip_msgcnt == 0) {
2N/A sip_log->sip_msgs = new_msg;
2N/A } else {
2N/A while (msg_chain->next != NULL)
2N/A msg_chain = msg_chain->next;
2N/A msg_chain->next = new_msg;
2N/A }
2N/A sip_log->sip_msgcnt++;
2N/A}
2N/A
2N/A/*
2N/A * Given a counter group and counter name within the group, returns the value
2N/A * associated with the counter in 'cntval'.
2N/A */
2N/Aint
2N/Asip_get_counter_value(int group, int counter, void *cntval, size_t cntlen)
2N/A{
2N/A if (group != SIP_TRAFFIC_COUNTERS || cntval == NULL)
2N/A return (EINVAL);
2N/A if ((counter == SIP_COUNTER_START_TIME || counter ==
2N/A SIP_COUNTER_STOP_TIME) && (cntlen != sizeof (time_t))) {
2N/A return (EINVAL);
2N/A } else if (cntlen != sizeof (uint64_t)) {
2N/A return (EINVAL);
2N/A }
2N/A
2N/A (void) pthread_mutex_lock(&sip_counters.sip_counter_mutex);
2N/A switch (counter) {
2N/A case SIP_TOTAL_BYTES_RCVD:
2N/A *(uint64_t *)cntval = sip_counters.sip_total_bytes_rcvd;
2N/A break;
2N/A case SIP_TOTAL_BYTES_SENT:
2N/A *(uint64_t *)cntval = sip_counters.sip_total_bytes_sent;
2N/A break;
2N/A case SIP_TOTAL_REQ_RCVD:
2N/A *(uint64_t *)cntval = sip_counters.sip_total_req_rcvd;
2N/A break;
2N/A case SIP_TOTAL_REQ_SENT:
2N/A *(uint64_t *)cntval = sip_counters.sip_total_req_sent;
2N/A break;
2N/A case SIP_TOTAL_RESP_RCVD:
2N/A *(uint64_t *)cntval = sip_counters.sip_total_resp_rcvd;
2N/A break;
2N/A case SIP_TOTAL_RESP_SENT:
2N/A *(uint64_t *)cntval = sip_counters.sip_total_resp_sent;
2N/A break;
2N/A case SIP_ACK_REQ_RCVD:
2N/A *(uint64_t *)cntval = sip_counters.sip_ack_req_rcvd;
2N/A break;
2N/A case SIP_ACK_REQ_SENT:
2N/A *(uint64_t *)cntval = sip_counters.sip_ack_req_sent;
2N/A break;
2N/A case SIP_BYE_REQ_RCVD:
2N/A *(uint64_t *)cntval = sip_counters.sip_bye_req_rcvd;
2N/A break;
2N/A case SIP_BYE_REQ_SENT:
2N/A *(uint64_t *)cntval = sip_counters.sip_bye_req_sent;
2N/A break;
2N/A case SIP_CANCEL_REQ_RCVD:
2N/A *(uint64_t *)cntval = sip_counters.sip_cancel_req_rcvd;
2N/A break;
2N/A case SIP_CANCEL_REQ_SENT:
2N/A *(uint64_t *)cntval = sip_counters.sip_cancel_req_sent;
2N/A break;
2N/A case SIP_INFO_REQ_RCVD:
2N/A *(uint64_t *)cntval = sip_counters.sip_info_req_rcvd;
2N/A break;
2N/A case SIP_INFO_REQ_SENT:
2N/A *(uint64_t *)cntval = sip_counters.sip_info_req_sent;
2N/A break;
2N/A case SIP_INVITE_REQ_RCVD:
2N/A *(uint64_t *)cntval = sip_counters.sip_invite_req_rcvd;
2N/A break;
2N/A case SIP_INVITE_REQ_SENT:
2N/A *(uint64_t *)cntval = sip_counters.sip_invite_req_sent;
2N/A break;
2N/A case SIP_NOTIFY_REQ_RCVD:
2N/A *(uint64_t *)cntval = sip_counters.sip_notify_req_rcvd;
2N/A break;
2N/A case SIP_NOTIFY_REQ_SENT:
2N/A *(uint64_t *)cntval = sip_counters.sip_notify_req_sent;
2N/A break;
2N/A case SIP_OPTIONS_REQ_RCVD:
2N/A *(uint64_t *)cntval = sip_counters.sip_options_req_rcvd;
2N/A break;
2N/A case SIP_OPTIONS_REQ_SENT:
2N/A *(uint64_t *)cntval = sip_counters.sip_options_req_sent;
2N/A break;
2N/A case SIP_PRACK_REQ_RCVD:
2N/A *(uint64_t *)cntval = sip_counters.sip_prack_req_rcvd;
2N/A break;
2N/A case SIP_PRACK_REQ_SENT:
2N/A *(uint64_t *)cntval = sip_counters.sip_prack_req_sent;
2N/A break;
2N/A case SIP_REFER_REQ_RCVD:
2N/A *(uint64_t *)cntval = sip_counters.sip_refer_req_rcvd;
2N/A break;
2N/A case SIP_REFER_REQ_SENT:
2N/A *(uint64_t *)cntval = sip_counters.sip_refer_req_sent;
2N/A break;
2N/A case SIP_REGISTER_REQ_RCVD:
2N/A *(uint64_t *)cntval = sip_counters.
2N/A sip_register_req_rcvd;
2N/A break;
2N/A case SIP_REGISTER_REQ_SENT:
2N/A *(uint64_t *)cntval = sip_counters.
2N/A sip_register_req_sent;
2N/A break;
2N/A case SIP_SUBSCRIBE_REQ_RCVD:
2N/A *(uint64_t *)cntval = sip_counters.
2N/A sip_subscribe_req_rcvd;
2N/A break;
2N/A case SIP_SUBSCRIBE_REQ_SENT:
2N/A *(uint64_t *)cntval = sip_counters.
2N/A sip_subscribe_req_sent;
2N/A break;
2N/A case SIP_UPDATE_REQ_RCVD:
2N/A *(uint64_t *)cntval = sip_counters.sip_update_req_rcvd;
2N/A break;
2N/A case SIP_UPDATE_REQ_SENT:
2N/A *(uint64_t *)cntval = sip_counters.sip_update_req_sent;
2N/A break;
2N/A case SIP_1XX_RESP_RCVD:
2N/A *(uint64_t *)cntval = sip_counters.sip_1xx_resp_rcvd;
2N/A break;
2N/A case SIP_1XX_RESP_SENT:
2N/A *(uint64_t *)cntval = sip_counters.sip_1xx_resp_sent;
2N/A break;
2N/A case SIP_2XX_RESP_RCVD:
2N/A *(uint64_t *)cntval = sip_counters.sip_2xx_resp_rcvd;
2N/A break;
2N/A case SIP_2XX_RESP_SENT:
2N/A *(uint64_t *)cntval = sip_counters.sip_2xx_resp_sent;
2N/A break;
2N/A case SIP_3XX_RESP_RCVD:
2N/A *(uint64_t *)cntval = sip_counters.sip_3xx_resp_rcvd;
2N/A break;
2N/A case SIP_3XX_RESP_SENT:
2N/A *(uint64_t *)cntval = sip_counters.sip_3xx_resp_sent;
2N/A break;
2N/A case SIP_4XX_RESP_RCVD:
2N/A *(uint64_t *)cntval = sip_counters.sip_4xx_resp_rcvd;
2N/A break;
2N/A case SIP_4XX_RESP_SENT:
2N/A *(uint64_t *)cntval = sip_counters.sip_4xx_resp_sent;
2N/A break;
2N/A case SIP_5XX_RESP_RCVD:
2N/A *(uint64_t *)cntval = sip_counters.sip_5xx_resp_rcvd;
2N/A break;
2N/A case SIP_5XX_RESP_SENT:
2N/A *(uint64_t *)cntval = sip_counters.sip_5xx_resp_sent;
2N/A break;
2N/A case SIP_6XX_RESP_RCVD:
2N/A *(uint64_t *)cntval = sip_counters.sip_6xx_resp_rcvd;
2N/A break;
2N/A case SIP_6xx_RESP_SENT:
2N/A *(uint64_t *)cntval = sip_counters.sip_6xx_resp_sent;
2N/A break;
2N/A case SIP_COUNTER_START_TIME:
2N/A *(time_t *)cntval = sip_counters.starttime;
2N/A break;
2N/A case SIP_COUNTER_STOP_TIME:
2N/A *(time_t *)cntval = sip_counters.stoptime;
2N/A break;
2N/A default:
2N/A (void) pthread_mutex_unlock(&sip_counters.
2N/A sip_counter_mutex);
2N/A return (EINVAL);
2N/A }
2N/A (void) pthread_mutex_unlock(&sip_counters.sip_counter_mutex);
2N/A return (0);
2N/A}
2N/A
2N/A/*
2N/A * Enables the SIP performance/traffic counting. Also reset's the previous
2N/A * counter values and starts counting afresh.
2N/A */
2N/Aint
2N/Asip_enable_counters(int group)
2N/A{
2N/A if (group != SIP_TRAFFIC_COUNTERS)
2N/A return (EINVAL);
2N/A (void) pthread_mutex_lock(&sip_counters.sip_counter_mutex);
2N/A /* If it's not enabled, enable it and capture the start time */
2N/A if (!sip_counters.enabled) {
2N/A /* zero all the counters except for the mutex at the end */
2N/A (void) bzero(&sip_counters, sizeof (sip_traffic_counters_t) -
2N/A sizeof (pthread_mutex_t));
2N/A sip_counters.enabled = B_TRUE;
2N/A sip_counters.starttime = time(NULL);
2N/A sip_counters.stoptime = 0;
2N/A }
2N/A (void) pthread_mutex_unlock(&sip_counters.sip_counter_mutex);
2N/A return (0);
2N/A}
2N/A
2N/A/*
2N/A * Disables the SIP performance/traffic counting. If already disabled it just
2N/A * exits without doing anyting. It records the stop time.
2N/A */
2N/Aint
2N/Asip_disable_counters(int group)
2N/A{
2N/A if (group != SIP_TRAFFIC_COUNTERS)
2N/A return (EINVAL);
2N/A (void) pthread_mutex_lock(&sip_counters.sip_counter_mutex);
2N/A if (sip_counters.enabled) {
2N/A sip_counters.enabled = B_FALSE;
2N/A sip_counters.stoptime = time(NULL);
2N/A }
2N/A (void) pthread_mutex_unlock(&sip_counters.sip_counter_mutex);
2N/A return (0);
2N/A}