Realtime H.323 friends
Introduction
Like SIP realtime friends, H.323 friends also can be configured using dynamic realtime objects. In Sep 2006 Paul Cadach merged into the trunk his code that provides realtime peers functionality. How to use it? In the same way as SIP and IAX2 realtime is configured. Below is step-by-step guide how to get h323 realtime freinds up and running.
Database structure
h323_peer table has the following structure
DROP TABLE IF EXISTS h323_peer; CREATE TABLE h323_peer( id BIGINT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(128) NOT NULL UNIQUE, host VARCHAR(15) DEFAULT NULL , secret VARCHAR(64) DEFAULT NULL, context VARCHAR(64) NOT NULL, type VARCHAR(6) NOT NULL, port INT DEFAULT NULL, permit VARCHAR(128) DEFAULT NULL, deny VARCHAR(128) DEFAULT NULL, mailbox VARCHAR(128) DEFAULT NULL, e164 VARCHAR(128) DEFAULT NULL, prefix VARCHAR(128) DEFAULT NULL, allow VARCHAR(128) DEFAULT NULL, disallow VARCHAR(128) DEFAULT NULL, dtmfmode VARCHAR(128) DEFAULT NULL, accountcode INT DEFAULT NULL, amaflags varchar(13) DEFAULT NULL, INDEX idx_name(name), INDEX idx_host(host) ); INSERT INTO h323_peer (name, host, context, type, accountcode) VALUES ('test', '192.168.11.2', 'user_context', 'friend', '123');
Configure Asterisk to load peers via realtime
We use [MySQL] database so we define database connection in res_mysql.conf:
[general] dbhost = 127.0.0.1 dbname = billing dbuser = user dbpass = pass dbport = 3306
Add the following lines in extconfig.conf:
[settings] h323 => mysql,billing,h323_peer
After saving the file tell asterisk to reload extconfig binding.
module reload extconfig == Parsing '/home/asterisk/pbx/etc/asterisk/extconfig.conf': Found == Binding sipusers to mysql/billing/v_peer == Binding sippeers to mysql/billing/v_peer == Binding iaxusers to mysql/billing/v_peer == Binding iaxpeers to mysql/billing/v_peer == Binding h323 to mysql/billing/v_h323_peer == Binding voicemail to mysql/billing/asterisk_voicemail == Binding sip.conf to mysql/billing/asterisk_astconfig == Binding iax.conf to mysql/billing/asterisk_astconfig *CLI>
Tuning peer matching
Depending on your h323.conf !UserByAlias setting asterisk will use either name column or host column to query database. If !UserByAlias=yes (default) then asterisk realtime will call the following quiery:
SELECT * FROM h323_peer WHERE name = 'test'
If [UserByAlias]=yes and also host is given and host does not match configured ip address then asterisk will complain:
chan_h323.c:2142 setup_incoming_call: Call from 'test' rejected due to non-matching IP address (192.168.11.3)s
If !UserByAlias=no then it will be like this:
SELECT * FROM h323_peer WHERE host = '192.168.11.2'
I guess using [UserByAlias]=yes and always specifying host will be the best choice for those not using gk.
I also recommend !AcceptAnonymous=no to disallow calls from peers that are not configured in h323.conf or database.
In our howto we do not use gatekeeper. Having gatekeeper allows to configure peer as type=h323 and use secret.
Testing
We can use CLI> command realtime to test if all is working as expected.
*CLI> realtime load h323 name test Column Name Column Value -------------------- -------------------- id 1 name test context user_context type friend accountcode 123 *CLI> *CLI> realtime load h323 host 192.168.11.2 Column Name Column Value -------------------- -------------------- id 1 name test host 192.168.11.2 context user_context type friend accountcode 123 *CLI>