Kamailio Basic routing
Installation for kamailio version 5.1.8
- get source
git clone https://github.com/kamailio/kamailio kamailio_source_code cd kamailio_source_code git checkout -b 5.1 origin/5.1 - craete clear cfg
make cfg - enable db_mysql module in file src/modules.lst in include_modules
```
this file is autogenerated by make modules-cfg
the list of sub-directories with modules
modules_dirs:=modules
the list of module groups to compile
cfg_group_include=
the list of extra modules to compile
include_modules=db_mysql app_lua
the list of static modules
static_modules=
the list of modules to skip from compile list
skip_modules=
the list of modules to exclude from compile list
exclude_modules= acc_radius app_java app_mono app_perl app_python auth_ephemeral auth_identity auth_radius carrierroute cdp cdp_avp cnxcc cplc crypto db2_ldap db_berkeley db_cassandra db_mongodb db_oracle db_perlvdb db_postgres db_sqlite db_unixodbc dialplan dnssec erlang evapi geoip geoip2 gzcompress h350 http_async_client http_client ims_auth ims_charging ims_dialog ims_diameter_server ims_icscf ims_isc ims_ocs ims_qos ims_registrar_pcscf ims_registrar_scscf ims_usrloc_pcscf ims_usrloc_scscf jansson janssonrpcc json jsonrpcc kazoo lcr ldap log_systemd memcached misc_radius ndb_cassandra ndb_mongodb ndb_redis nsq osp outbound peering phonenum presence presence_conference presence_dialoginfo presence_mwi presence_profile presence_reginfo presence_xml pua pua_bla pua_dialoginfo pua_reginfo pua_rpc pua_usrloc pua_xmpp rabbitmq regex rls sctp snmpstats tls topos_redis utils uuid websocket xcap_client xcap_server xhttp_pi xmlops xmlrpc xmpp $(skip_modules)
modules_all= $(filter-out modules/CVS,$(wildcard modules/*)) modules_noinc= $(filter-out $(addprefix modules/, $(exclude_modules) $(static_modules)), $(modules_all)) modules= $(filter-out $(modules_noinc), $(addprefix modules/, $(include_modules) )) $(modules_noinc) modules_configured:=1
4. compile
make all
3. install
make install
4. verify version
version: kamailio 5.1.8 (x86_64/linux) 1ebdde flags: STATS: Off, USE_TCP, USE_TLS, USE_SCTP, TLS_HOOKS, USE_RAW_SOCKS, DISABLE_NAGLE, USE_MCAST, DNS_IP_HACK, SHM_MEM, SHM_MMAP, PKG_MALLOC, Q_MALLOC, F_MALLOC, TLSF_MALLOC, DBG_SR_MEMORY, USE_FUTEX, FAST_LOCK-ADAPTIVE_WAIT, USE_DNS_CACHE, USE_DNS_FAILOVER, USE_NAPTR, USE_DST_BLACKLIST, HAVE_RESOLV_RES ADAPTIVE_WAIT_LOOPS=1024, MAX_RECV_BUFFER_SIZE 262144 MAX_URI_SIZE 1024, BUF_SIZE 65535, DEFAULT PKG_SIZE 8MB poll method support: poll, epoll_lt, epoll_et, sigio_rt, select. id: 1ebdde compiled on 05:47:46 Jul 10 2019 with gcc 5.4.0
### Mysql installation
apt-get install mysql-server
optional :allow remote access
ufw allow mysql
start mysql as service
systemctl start mysql
assume your gave root password 1234 during installation
login to mysql using the above root password
mysql -u root -p 1234
* Adding users manually *
See existing users
SELECT User, Host, authentication_string FROM mysql.user; +——————+———–+——————————————-+ | User | Host | authentication_string | +——————+———–+——————————————-+ | root | localhost | *xxxx | | mysql.session | localhost | *xxxx | | mysql.sys | localhost | *xxxx | | debian-sys-maint | localhost | *xxxx | +——————+———–+——————————————-+
optional : Maually creating db kamailio , you can do this via kamctl
CREATE DATABASE kamailio;
add new user for the db
INSERT INTO mysql.user (User,Host,authentication_string,ssl_cipher,x509_issuer,x509_subject) VALUES(‘kamailio’,’localhost’,PASSWORD(‘123456’),’’,’’,’’);
verify new user is added
SELECT User, Host, authentication_string FROM mysql.user; +——————+———–+——————————————-+ | User | Host | authentication_string | +——————+———–+——————————————-+ | root | localhost | *xxx | | mysql.session | localhost | *xxx | | mysql.sys | localhost | *xxx | | debian-sys-maint | localhost | *xxx | | kamailio | localhost | *xxx | +——————+———–+——————————————-+
* Creating DB and Adding users kamctl *
Add DB creds to kamctlrc
```sh
vi /usr/local/etc/kamailio/kamctlrc
the contents of file should be
...
DBENGINE=MYSQL
## database host
DBHOST=localhost
## database host
DBPORT=3306
## database name (for ORACLE this is TNS name)
DBNAME=kamailio
# database path used by dbtext, db_berkeley or sqlite
# DB_PATH="/usr/local/etc/kamailio/dbtext"
## database read/write user
DBRWUSER="kamailio"
## password for database read/write user
DBRWPW="kamailiorw"
## database read only user
# DBROUSER="kamailioro"
## password for database read only user
# DBROPW="kamailioro"
## database access host (from where is kamctl used)
# DBACCESSHOST=192.168.0.1
## database super user (for ORACLE this is 'scheme-creator' user)
# DBROOTUSER="root"
DBROOTUSER="root"
## password for database super user
## - important: this is insecure, targeting the use only for automatic testing
## - known to work for: mysql
# DBROOTPW="dbrootpw"
DBROOTPW="kamailio"
...
run kamdbctl to automatically create kamailio tables
/usr/local/sbin/kamdbctl create
output
INFO: test server charset
...
INFO: creating database kamailio ...
...
INFO: granting privileges to database kamailio ...
...
INFO: creating standard tables into kamailio ...
...
INFO: Core Kamailio tables succesfully created.
Install presence related tables? (y/n): y
INFO: creating presence tables into kamailio ...
...
INFO: Presence tables succesfully created.
Install tables for imc cpl siptrace domainpolicy carrierroute
drouting userblacklist htable purple uac pipelimit mtree sca mohqueue
rtpproxy rtpengine? (y/n): y
INFO: creating extra tables into kamailio ...
...
INFO: Extra tables succesfully created.
Install tables for uid_auth_db uid_avp_db uid_domain uid_gflags
uid_uri_db? (y/n): y
INFO: creating uid tables into kamailio ...
...
INFO: UID tables succesfully created.
tables list
mysql> show tables from kamailio;
+---------------------+
| Tables_in_kamailio |
+---------------------+
| acc |
| acc_cdrs |
| active_watchers |
| address |
| aliases |
| carrier_name |
| carrierfailureroute |
| carrierroute |
| cpl |
| dbaliases |
| dialog |
| dialog_vars |
| dialplan |
| dispatcher |
| domain |
| domain_attrs |
| domain_name |
| domainpolicy |
| dr_gateways |
| dr_groups |
| dr_gw_lists |
| dr_rules |
| globalblacklist |
| grp |
| htable |
| imc_members |
| imc_rooms |
| lcr_gw |
| lcr_rule |
| lcr_rule_target |
| location |
| location_attrs |
| missed_calls |
| mohqcalls |
| mohqueues |
| mtree |
| mtrees |
| pdt |
| pl_pipes |
| presentity |
| pua |
| purplemap |
| re_grp |
| rls_presentity |
| rls_watchers |
| rtpengine |
| rtpproxy |
| sca_subscriptions |
| silo |
| sip_trace |
| speed_dial |
| subscriber |
| topos_d |
| topos_t |
| trusted |
| uacreg |
| uid_credentials |
| uid_domain |
| uid_domain_attrs |
| uid_global_attrs |
| uid_uri |
| uid_uri_attrs |
| uid_user_attrs |
| uri |
| userblacklist |
| usr_preferences |
| version |
| watchers |
| xcap |
+---------------------+
69 rows in set (0.00 sec
you can check the structure of any one of tables
mysql> desc dialog;
+------------------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------------+------------------+------+-----+---------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| hash_entry | int(10) unsigned | NO | MUL | NULL | |
| hash_id | int(10) unsigned | NO | | NULL | |
| callid | varchar(255) | NO | | NULL | |
| from_uri | varchar(128) | NO | | NULL | |
| from_tag | varchar(64) | NO | | NULL | |
| to_uri | varchar(128) | NO | | NULL | |
| to_tag | varchar(64) | NO | | NULL | |
| caller_cseq | varchar(20) | NO | | NULL | |
| callee_cseq | varchar(20) | NO | | NULL | |
| caller_route_set | varchar(512) | YES | | NULL | |
| callee_route_set | varchar(512) | YES | | NULL | |
| caller_contact | varchar(128) | NO | | NULL | |
| callee_contact | varchar(128) | NO | | NULL | |
| caller_sock | varchar(64) | NO | | NULL | |
| callee_sock | varchar(64) | NO | | NULL | |
| state | int(10) unsigned | NO | | NULL | |
| start_time | int(10) unsigned | NO | | NULL | |
| timeout | int(10) unsigned | NO | | 0 | |
| sflags | int(10) unsigned | NO | | 0 | |
| iflags | int(10) unsigned | NO | | 0 | |
| toroute_name | varchar(32) | YES | | NULL | |
| req_uri | varchar(128) | NO | | NULL | |
| xdata | varchar(512) | YES | | NULL | |
+------------------+------------------+------+-----+---------+----------------+
Run
start kamailio giving the path of kamailio.cfg
kamailio -f kamailio.cfg -E
Feartures
1.Registeration handling checks if incoming REGISTER domain is present in subscriber tabel and throw back auth challenge to supply username and password
Registeration
subscriber table used by db_auth desc subscriber; +—————+——————+——+—–+———+—————-+ | Field | Type | Null | Key | Default | Extra | +—————+——————+——+—–+———+—————-+ | id | int(10) unsigned | NO | PRI | NULL | auto_increment | | username | varchar(64) | NO | MUL | | | | domain | varchar(64) | NO | | | | | password | varchar(64) | NO | | | | | ha1 | varchar(128) | NO | | | | | ha1b | varchar(128) | NO | | | | | email_address | varchar(128) | YES | | NULL | | | rpid | varchar(128) | YES | | NULL | | +—————+——————+——+—–+———+—————-+
Debugging
-Issue while run version mismatch
ERROR:
-Issue cannot find -lncurses5 during make install solution : install ncurses and make install again apt-get install lib32ncurses5-dev
-Issue while creating db using kamctl ERROR 1133 (42000) at line 1: Can’t find any matching row in the user table ERROR: granting privileges to database kamailio failed!
- Issue ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES) solution : DBRWUSER and DBROUSER are users created by kamdbctl to access the kamailio database. If set to root, it seems the root password gets overwritten. ( Ref : https://lists.kamailio.org/pipermail/sr-users/2012-May/073268.html) . Use the newly set password .
-Issue while using kamctl : kamctl nont loading DBEngine missing Solution : Add DBENGINE in /usr/local/etc/kamailio/kamctlrc
Ref : kamailio 5.1 installation guide - https://kamailio.org/docs/tutorials/5.1.x/kamailio-install-guide-git/ Lua Routing- https://github.com/kamailio/kamailio/blob/master/misc/examples/kemi/kamailio-basic-kemi-lua.lua KEMI framework - https://kamailio.org/docs/tutorials/devel/kamailio-kemi-framework/