Skip to content
Snippets Groups Projects
chan_iax2.c 321 KiB
Newer Older
 * Asterisk -- An open source telephony toolkit.
 * Copyright (C) 1999 - 2006, Digium, Inc.
 *
 * Mark Spencer <markster@digium.com>
 *
 * See http://www.asterisk.org for more information about
 * the Asterisk project. Please do not directly contact
 * any of the maintainers of this project for assistance;
 * the project provides a web site, mailing lists and IRC
 * channels for your use.
 *
 * This program is free software, distributed under the terms of
 * the GNU General Public License Version 2. See the LICENSE file
 * at the top of the source tree.
 */

 * \brief Implementation of Inter-Asterisk eXchange Version 2
 * \author Mark Spencer <markster@digium.com>
 *
Russell Bryant's avatar
Russell Bryant committed
 * \par See also
 * \arg \ref Config_iax
 *
 * \ingroup channel_drivers
Kevin P. Fleming's avatar
Kevin P. Fleming committed
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
Kevin P. Fleming's avatar
Kevin P. Fleming committed
#include <sys/mman.h>
#include <dirent.h>
#include <sys/socket.h>
#include <netinet/in.h>
Mark Spencer's avatar
Mark Spencer committed
#include <arpa/inet.h>
Kevin P. Fleming's avatar
Kevin P. Fleming committed
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <sys/time.h>
#include <sys/signal.h>
#include <signal.h>
#include <string.h>
#include <strings.h>
Kevin P. Fleming's avatar
Kevin P. Fleming committed
#include <errno.h>
#include <unistd.h>
#include <netdb.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <regex.h>
#ifdef IAX_TRUNKING
#include <sys/ioctl.h>
#ifdef __linux__
#include <linux/zaptel.h>
#else
#include <zaptel.h>
#endif /* __linux__ */
#endif

Kevin P. Fleming's avatar
Kevin P. Fleming committed
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/lock.h"
#include "asterisk/frame.h" 
#include "asterisk/channel.h"
#include "asterisk/logger.h"
#include "asterisk/module.h"
#include "asterisk/pbx.h"
#include "asterisk/sched.h"
#include "asterisk/io.h"
#include "asterisk/config.h"
#include "asterisk/options.h"
#include "asterisk/cli.h"
#include "asterisk/translate.h"
#include "asterisk/md5.h"
#include "asterisk/cdr.h"
#include "asterisk/crypto.h"
#include "asterisk/acl.h"
#include "asterisk/manager.h"
#include "asterisk/callerid.h"
#include "asterisk/app.h"
#include "asterisk/astdb.h"
#include "asterisk/musiconhold.h"
#include "asterisk/features.h"
#include "asterisk/utils.h"
#include "asterisk/causes.h"
#include "asterisk/localtime.h"
#include "asterisk/aes.h"
#include "asterisk/dnsmgr.h"
#include "asterisk/stringfields.h"
#include "iax2.h"
#include "iax2-parser.h"
#include "iax2-provision.h"
/* Define NEWJB to use the new channel independent jitterbuffer,
 * otherwise, use the old jitterbuffer */
#define NEWJB

Mark Spencer's avatar
Mark Spencer committed
/* Define SCHED_MULTITHREADED to run the scheduler in a special
   multithreaded mode. */
Russell Bryant's avatar
Russell Bryant committed
#define SCHED_MULTITHREADED
/* Define DEBUG_SCHED_MULTITHREADED to keep track of where each
   thread is actually doing. */
Russell Bryant's avatar
Russell Bryant committed
#define DEBUG_SCHED_MULTITHREAD
Mark Spencer's avatar
Mark Spencer committed
#ifndef IPTOS_MINCOST
#define IPTOS_MINCOST 0x02
#endif

#ifdef SO_NO_CHECK
static int nochecksums = 0;
#endif

/*
 * Uncomment to try experimental IAX bridge optimization,
 * designed to reduce latency when IAX calls cannot
Mark Spencer's avatar
Mark Spencer committed
 * be trasnferred -- obsolete
Mark Spencer's avatar
Mark Spencer committed
/* #define BRIDGE_OPTIMIZATION  */

#define PTR_TO_CALLNO(a) ((unsigned short)(unsigned long)(a))
#define CALLNO_TO_PTR(a) ((void *)(unsigned long)(a))
Mark Spencer's avatar
Mark Spencer committed
#define DEFAULT_THREAD_COUNT 10
#define DEFAULT_RETRY_TIME 1000
#define MEMORY_SIZE 100
#define DEFAULT_DROP 3
/* Flag to use with trunk calls, keeping these calls high up.  It halves our effective use
   but keeps the division between trunked and non-trunked better. */
#define TRUNK_CALL_START	0x4000

#define DEBUG_SUPPORT

#define MIN_REUSE_TIME		60	/* Don't reuse a call number within 60 seconds */

/* Sample over last 100 units to determine historic jitter */
#define GAMMA (0.01)

static struct ast_codec_pref prefs;

static const char desc[] = "Inter Asterisk eXchange (Ver 2)";
static const char tdesc[] = "Inter Asterisk eXchange Driver (Ver 2)";

static char context[80] = "default";

static char language[MAX_LANGUAGE] = "";
static char regcontext[AST_MAX_CONTEXT] = "";
static int max_retries = 4;
static int ping_time = 20;
static int lagrq_time = 10;
static int maxtrunkcall = TRUNK_CALL_START;
static int maxnontrunkcall = 1;
static int maxjitterbuffer=1000;
#ifdef NEWJB
static int resyncthreshold=1000;
static int jittershrinkrate=2;
static int trunkfreq = 20;
Mark Spencer's avatar
Mark Spencer committed
static int authdebug = 1;
Mark Spencer's avatar
Mark Spencer committed
static int autokill = 0;

static int iaxdefaultdpcache=10 * 60;	/* Cache dialplan entries for 10 minutes by default */

static int iaxdefaulttimeout = 5;		/* Default to wait no more than 5 seconds for a reply to come back */

static int tos = 0;

static int min_reg_expire;
static int max_reg_expire;
static int timingfd = -1;				/* Timing file descriptor */

static int usecnt;
AST_MUTEX_DEFINE_STATIC(usecnt_lock);
int (*iax2_regfunk)(char *username, int onoff) = NULL;

/* Ethernet, etc */
#define IAX_CAPABILITY_FULLBANDWIDTH 	0xFFFF
/* T1, maybe ISDN */
Russell Bryant's avatar
Russell Bryant committed
#define IAX_CAPABILITY_MEDBANDWIDTH 	(IAX_CAPABILITY_FULLBANDWIDTH & 	\
							~AST_FORMAT_SLINEAR & 	\
Loading
Loading full blame...