mirror of https://github.com/sipwise/kamailio.git
parent
fafb27fb0b
commit
efce85a240
@ -1 +1 @@
|
||||
D /run/sipcapture 0700 kamailio daemon -
|
||||
D /run/sipcapture 0700 kamailio kamailio -
|
||||
|
@ -0,0 +1,434 @@
|
||||
IMS Usrloc SCSCF Module
|
||||
|
||||
Jason Penton
|
||||
|
||||
Smile Communications
|
||||
|
||||
Edited by
|
||||
|
||||
Richard Good
|
||||
|
||||
Smile Communications
|
||||
|
||||
Yasin Caner
|
||||
|
||||
Copyright © 2012 Smile Communications
|
||||
__________________________________________________________________
|
||||
|
||||
Table of Contents
|
||||
|
||||
1. Admin Guide
|
||||
|
||||
1. Overview
|
||||
2. Dependencies
|
||||
|
||||
2.1. Kamailio Modules
|
||||
|
||||
3. Parameters
|
||||
|
||||
3.1. db_url (string)
|
||||
3.2. db_mode (string)
|
||||
3.3. maxcontact (int)
|
||||
3.4. maxcontact_3gpp (int)
|
||||
3.5. maxcontact_behaviour (int)
|
||||
3.6. max_subscribes(int)
|
||||
3.7. sub_dialog_hash_size(int)
|
||||
3.8. timer_procs(int)
|
||||
3.9. timer_interval (int)
|
||||
3.10. desc_time_order (int)
|
||||
3.11. matching_mode (int)
|
||||
3.12. cseq_delay (int)
|
||||
3.13. fetch_rows(int)
|
||||
3.14. hash_size (string)
|
||||
3.15. subs_hash_size (int)
|
||||
3.16. contacts_hash_size (integer)
|
||||
3.17. nat_bflag (integer)
|
||||
3.18. contact_delete_delay (int)
|
||||
3.19. support_wildcardPSI (int)
|
||||
3.20. unreg_validity (int)
|
||||
3.21. user_data_xsd (string)
|
||||
|
||||
4. RPC Commands
|
||||
|
||||
4.1. ulscscf.status
|
||||
4.2. ulscscf.showimpu
|
||||
4.3. ulscscf.snapshot
|
||||
|
||||
2. Frequently Asked Questions
|
||||
|
||||
List of Examples
|
||||
|
||||
1.1. Set db_urlparameter
|
||||
1.2. Set db_mode(int)
|
||||
1.3. Set maxcontactparameter
|
||||
1.4. Set maxcontact_3gppparameter
|
||||
1.5. Set maxcontact_behaviour parameter
|
||||
1.6. Set subscription_expires_rangeparameter
|
||||
1.7. Setsub_dialog_hash_sizeparameter
|
||||
1.8. Settimer_procsparameter
|
||||
1.9. Set timer_intervalparameter
|
||||
1.10. Set desc_time_orderparameter
|
||||
1.11. Set matching_modeparameter
|
||||
1.12. Set scscf_nameparameter
|
||||
1.13. Set fetch_rowsparameter
|
||||
1.14. Set hash_sizeparameter
|
||||
1.15. Set subs_hash_sizeparameter
|
||||
1.16. Set contacts_hash_sizeparameter
|
||||
1.17. Set nat_bflagparameter
|
||||
1.18. Set contact_delete_delayparameter
|
||||
1.19. Set support_wildcardPSI parameter
|
||||
1.20. Set unreg_validity parameter
|
||||
1.21. Set unreg_validity parameter
|
||||
|
||||
Chapter 1. Admin Guide
|
||||
|
||||
Table of Contents
|
||||
|
||||
1. Overview
|
||||
2. Dependencies
|
||||
|
||||
2.1. Kamailio Modules
|
||||
|
||||
3. Parameters
|
||||
|
||||
3.1. db_url (string)
|
||||
3.2. db_mode (string)
|
||||
3.3. maxcontact (int)
|
||||
3.4. maxcontact_3gpp (int)
|
||||
3.5. maxcontact_behaviour (int)
|
||||
3.6. max_subscribes(int)
|
||||
3.7. sub_dialog_hash_size(int)
|
||||
3.8. timer_procs(int)
|
||||
3.9. timer_interval (int)
|
||||
3.10. desc_time_order (int)
|
||||
3.11. matching_mode (int)
|
||||
3.12. cseq_delay (int)
|
||||
3.13. fetch_rows(int)
|
||||
3.14. hash_size (string)
|
||||
3.15. subs_hash_size (int)
|
||||
3.16. contacts_hash_size (integer)
|
||||
3.17. nat_bflag (integer)
|
||||
3.18. contact_delete_delay (int)
|
||||
3.19. support_wildcardPSI (int)
|
||||
3.20. unreg_validity (int)
|
||||
3.21. user_data_xsd (string)
|
||||
|
||||
4. RPC Commands
|
||||
|
||||
4.1. ulscscf.status
|
||||
4.2. ulscscf.showimpu
|
||||
4.3. ulscscf.snapshot
|
||||
|
||||
1. Overview
|
||||
|
||||
This module serves as a storage engine for SCSCF contacts, much like
|
||||
the standard Kamailio module that is usrloc, is a storage engine for
|
||||
standard SIP contacts.
|
||||
|
||||
2. Dependencies
|
||||
|
||||
2.1. Kamailio Modules
|
||||
|
||||
2.1. Kamailio Modules
|
||||
|
||||
The following modules must be loaded before this module:
|
||||
* TM
|
||||
* Presence
|
||||
* IMS dialog
|
||||
|
||||
3. Parameters
|
||||
|
||||
3.1. db_url (string)
|
||||
3.2. db_mode (string)
|
||||
3.3. maxcontact (int)
|
||||
3.4. maxcontact_3gpp (int)
|
||||
3.5. maxcontact_behaviour (int)
|
||||
3.6. max_subscribes(int)
|
||||
3.7. sub_dialog_hash_size(int)
|
||||
3.8. timer_procs(int)
|
||||
3.9. timer_interval (int)
|
||||
3.10. desc_time_order (int)
|
||||
3.11. matching_mode (int)
|
||||
3.12. cseq_delay (int)
|
||||
3.13. fetch_rows(int)
|
||||
3.14. hash_size (string)
|
||||
3.15. subs_hash_size (int)
|
||||
3.16. contacts_hash_size (integer)
|
||||
3.17. nat_bflag (integer)
|
||||
3.18. contact_delete_delay (int)
|
||||
3.19. support_wildcardPSI (int)
|
||||
3.20. unreg_validity (int)
|
||||
3.21. user_data_xsd (string)
|
||||
|
||||
3.1. db_url (string)
|
||||
|
||||
database URL for storing impu/contacts records
|
||||
|
||||
Example 1.1. Set db_urlparameter
|
||||
modparam("ims_usrloc_scscf", "db_url", "mysql//username:password@localho
|
||||
st/scscf")
|
||||
|
||||
3.2. db_mode (string)
|
||||
|
||||
This is the database mode to be used for the SCSCF usrloc data
|
||||
persistent storage. Currently this module supports the Write-Back
|
||||
scheme only.
|
||||
* 0 - This disables database completely. Only memory will be used.
|
||||
Contacts will not survive restart.
|
||||
* 1 - Write-Backend scheme. All changes are made to memory and
|
||||
database synchronization is done in the timer
|
||||
|
||||
Default value is 0.
|
||||
|
||||
Example 1.2. Set db_mode(int)
|
||||
...
|
||||
modparam("ims_usrloc_scscf", "db_mode", 1)
|
||||
|
||||
3.3. maxcontact (int)
|
||||
|
||||
The parameter can be used to limit the number of contact for each impu
|
||||
|
||||
Default value is 0(max)
|
||||
|
||||
Example 1.3. Set maxcontactparameter
|
||||
...
|
||||
modparam("ims_usrloc_scscf", "maxcontact", 10)
|
||||
|
||||
3.4. maxcontact_3gpp (int)
|
||||
|
||||
The parameter can be used to limit the number of 3GPP contact for each
|
||||
impu
|
||||
|
||||
Default value is 0.(max)
|
||||
|
||||
Example 1.4. Set maxcontact_3gppparameter
|
||||
...
|
||||
modparam("ims_usrloc_scscf", "maxcontact_3gpp", 0)
|
||||
|
||||
3.5. maxcontact_behaviour (int)
|
||||
|
||||
Behaviour of usrloc , after impu reach max contacts limit.
|
||||
* 0 - Disabled
|
||||
* 1 - Reject after reaching limit.
|
||||
* 2 - Overwrite
|
||||
|
||||
Default value is 0.
|
||||
|
||||
Example 1.5. Set maxcontact_behaviour parameter
|
||||
...
|
||||
modparam("ims_usrloc_scscf", "maxcontact_behaviour", 2)
|
||||
|
||||
3.6. max_subscribes(int)
|
||||
|
||||
Max number of subscribes allowed per watcher for each IMPU
|
||||
|
||||
Default value is 0.
|
||||
|
||||
Example 1.6. Set subscription_expires_rangeparameter
|
||||
...
|
||||
modparam("ims_usrloc_scscf", "max_subscribes", 2)
|
||||
|
||||
3.7. sub_dialog_hash_size(int)
|
||||
|
||||
Subscriber dialog hash table size
|
||||
|
||||
Default value is 10.
|
||||
|
||||
Example 1.7. Setsub_dialog_hash_sizeparameter
|
||||
...
|
||||
modparam("ims_usrloc_scscf", "sub_dialog_hash_size", 512)
|
||||
|
||||
3.8. timer_procs(int)
|
||||
|
||||
process number of handling registeration
|
||||
|
||||
Default value is 0
|
||||
|
||||
Example 1.8. Settimer_procsparameter
|
||||
...
|
||||
modparam("ims_usrloc_scscf", "timer_procs", 5)
|
||||
|
||||
3.9. timer_interval (int)
|
||||
|
||||
Number of seconds between two timer runs. The module uses a timer to
|
||||
delete expired contacts, synchronize with database and other tasks,
|
||||
that need to be run periodically
|
||||
|
||||
Default value is 90
|
||||
|
||||
Example 1.9. Set timer_intervalparameter
|
||||
...
|
||||
modparam("ims_usrloc_scscf", "timer_interval", 120)
|
||||
|
||||
3.10. desc_time_order (int)
|
||||
|
||||
If the user's contacts should be kept timestamp ordered; otherwise the
|
||||
contact will be ordered based on q value. Non 0 value means true.
|
||||
|
||||
Default value is timestamp ordering not enabled
|
||||
|
||||
Example 1.10. Set desc_time_orderparameter
|
||||
...
|
||||
modparam("ims_usrloc_scscf", "desc_time_order", 1)
|
||||
|
||||
3.11. matching_mode (int)
|
||||
|
||||
What contact matching algorithm to be used.
|
||||
* 0 - Contact Only matching
|
||||
* 1 - Contact and Callid Matching
|
||||
* 2 - Contact and Path header matching
|
||||
* 3 - Only contact IP and Port Matching
|
||||
|
||||
Default value is 0.
|
||||
|
||||
Example 1.11. Set matching_modeparameter
|
||||
...
|
||||
modparam("ims_usrloc_scscf", "matching_mode", 0)
|
||||
|
||||
3.12. cseq_delay (int)
|
||||
|
||||
Delay (in seconds) for accepting as retransmissions register requests
|
||||
with same Call-ID and Cseq.
|
||||
|
||||
Default value is 20.
|
||||
|
||||
Example 1.12. Set scscf_nameparameter
|
||||
...
|
||||
modparam("ims_usrloc_scscf", "cseq_delay", 20)
|
||||
|
||||
3.13. fetch_rows(int)
|
||||
|
||||
The number of the rows to be fetched at once from database when loading
|
||||
the location records.
|
||||
|
||||
Default value is 2000.
|
||||
|
||||
Example 1.13. Set fetch_rowsparameter
|
||||
...
|
||||
modparam("ims_usrloc_scscf", "fetch_rows", 3000)
|
||||
|
||||
3.14. hash_size (string)
|
||||
|
||||
The number of entries of the hash table used by usrloc
|
||||
|
||||
Default value 512
|
||||
|
||||
Example 1.14. Set hash_sizeparameter
|
||||
...
|
||||
modparam("ims_usrloc_scscf", "hash_size", 512)
|
||||
|
||||
3.15. subs_hash_size (int)
|
||||
|
||||
The number of entries of the hash table used by usrloc to store the ims
|
||||
subscribe records
|
||||
|
||||
Default value 512
|
||||
|
||||
Example 1.15. Set subs_hash_sizeparameter
|
||||
...
|
||||
modparam("ims_usrloc_scscf", "subs_hash_size", 512)
|
||||
|
||||
3.16. contacts_hash_size (integer)
|
||||
|
||||
The number of entries of the hash table used by usrloc to store the
|
||||
contact records
|
||||
|
||||
Default value is 512
|
||||
|
||||
Example 1.16. Set contacts_hash_sizeparameter
|
||||
...
|
||||
modparam("ims_usrloc_scscf", "contacts_hash_size", 512)
|
||||
|
||||
3.17. nat_bflag (integer)
|
||||
|
||||
NAT marker to handle natted registration
|
||||
|
||||
Default value is 0
|
||||
|
||||
Example 1.17. Set nat_bflagparameter
|
||||
modparam("ims_usrloc_scscf", "nat_bflag", 3)
|
||||
|
||||
3.18. contact_delete_delay (int)
|
||||
|
||||
If contact is put into delay delete state ,this is how long we delay
|
||||
before deleting
|
||||
|
||||
Default value is 30
|
||||
|
||||
Example 1.18. Set contact_delete_delayparameter
|
||||
modparam("ims_usrloc_scscf", "contact_delete_delay", 32)
|
||||
|
||||
3.19. support_wildcardPSI (int)
|
||||
|
||||
Wildcard Public-Service-Identity (RFC5002). it will be actived by
|
||||
setting 1
|
||||
|
||||
Default value is 0.(disabled)
|
||||
|
||||
Example 1.19. Set support_wildcardPSI parameter
|
||||
modparam("ims_usrloc_scscf", "support_wildcardPSI", 0)
|
||||
|
||||
3.20. unreg_validity (int)
|
||||
|
||||
Default validity time in seconds for unregister assignment to SCSCF
|
||||
|
||||
Default value is 1800
|
||||
|
||||
Example 1.20. Set unreg_validity parameter
|
||||
modparam("ims_usrloc_scscf", "unreg_validity", 0)
|
||||
|
||||
3.21. user_data_xsd (string)
|
||||
|
||||
Default value is 1800
|
||||
|
||||
Example 1.21. Set unreg_validity parameter
|
||||
modparam("ims_usrloc_scscf", "user_data_xsd", "/usr/local/etc/kamailio/C
|
||||
xDataType_Rel6.xsd")
|
||||
|
||||
4. RPC Commands
|
||||
|
||||
4.1. ulscscf.status
|
||||
4.2. ulscscf.showimpu
|
||||
4.3. ulscscf.snapshot
|
||||
|
||||
Exported RPC commands.
|
||||
|
||||
4.1. ulscscf.status
|
||||
|
||||
4.2. ulscscf.showimpu
|
||||
|
||||
4.3. ulscscf.snapshot
|
||||
|
||||
Chapter 2. Frequently Asked Questions
|
||||
|
||||
2.1. Where can I find more about Kamailio?
|
||||
2.2. Where can I post a question about this module?
|
||||
2.3. How can I report a bug?
|
||||
|
||||
2.1.
|
||||
|
||||
Where can I find more about Kamailio?
|
||||
|
||||
Take a look at https://www.kamailio.org/.
|
||||
|
||||
2.2.
|
||||
|
||||
Where can I post a question about this module?
|
||||
|
||||
First at all check if your question was already answered on one of our
|
||||
mailing lists:
|
||||
* User Mailing List -
|
||||
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
|
||||
* Developer Mailing List -
|
||||
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev
|
||||
|
||||
E-mails regarding any stable Kamailio release should be sent to
|
||||
<sr-users@lists.kamailio.org> and e-mails regarding development
|
||||
versions should be sent to <sr-dev@lists.kamailio.org>.
|
||||
|
||||
2.3.
|
||||
|
||||
How can I report a bug?
|
||||
|
||||
Please follow the guidelines provided at:
|
||||
https://github.com/kamailio/kamailio/issues.
|
@ -0,0 +1,4 @@
|
||||
docs = ims_usrloc_scscf.xml
|
||||
|
||||
docbook_dir = ../../../../doc/docbook
|
||||
include $(docbook_dir)/Makefile.module
|
@ -0,0 +1,62 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
|
||||
"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [
|
||||
<!-- Include general documentation entities -->
|
||||
<!ENTITY % docentities SYSTEM "../../../../doc/docbook/entities.xml">
|
||||
%docentities;
|
||||
]>
|
||||
<book>
|
||||
<bookinfo>
|
||||
<title>IMS Usrloc SCSCF Module</title>
|
||||
|
||||
<productname class="trade">&kamailioname;</productname>
|
||||
|
||||
<authorgroup>
|
||||
<author>
|
||||
<firstname>Jason Penton</firstname>
|
||||
|
||||
<surname/>
|
||||
|
||||
<affiliation>
|
||||
<orgname>Smile Communications</orgname>
|
||||
</affiliation>
|
||||
|
||||
<address>
|
||||
<email>jason.penton@smilecoms.com</email>
|
||||
</address>
|
||||
</author>
|
||||
|
||||
<editor>
|
||||
<firstname>Richard</firstname>
|
||||
|
||||
<surname>Good</surname>
|
||||
|
||||
<affiliation>
|
||||
<orgname>Smile Communications</orgname>
|
||||
</affiliation>
|
||||
|
||||
<address>
|
||||
<email>richard.good@smilecoms.com</email>
|
||||
</address>
|
||||
</editor>
|
||||
|
||||
<editor>
|
||||
<firstname>Yasin</firstname>
|
||||
<surname>Caner</surname>
|
||||
</editor>
|
||||
</authorgroup>
|
||||
|
||||
<copyright>
|
||||
<year>2012</year>
|
||||
<holder>Smile Communications</holder>
|
||||
</copyright>
|
||||
</bookinfo>
|
||||
|
||||
<toc/>
|
||||
|
||||
<xi:include href="ims_usrloc_scscf_admin.xml"
|
||||
xmlns:xi="http://www.w3.org/2001/XInclude"/>
|
||||
|
||||
<xi:include href="ims_usrloc_scscf_faq.xml"
|
||||
xmlns:xi="http://www.w3.org/2001/XInclude"/>
|
||||
</book>
|
@ -0,0 +1,340 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
|
||||
"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [
|
||||
<!-- Include general documentation entities -->
|
||||
<!ENTITY % docentities SYSTEM "../../../../doc/docbook/entities.xml">
|
||||
%docentities;
|
||||
]>
|
||||
<!-- Module User's Guide -->
|
||||
<chapter>
|
||||
<title>&adminguide;</title>
|
||||
|
||||
<section>
|
||||
<title>Overview</title>
|
||||
<para>This module serves as a storage engine for SCSCF contacts, much like the standard Kamailio module that is usrloc, is a storage engine for standard SIP contacts.</para>
|
||||
</section>
|
||||
<section>
|
||||
<title>Dependencies</title>
|
||||
<section>
|
||||
<title>&kamailio; Modules</title>
|
||||
<para>The following modules must be loaded before this module:
|
||||
<itemizedlist>
|
||||
<listitem>
|
||||
<para><emphasis>TM</emphasis></para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para><emphasis>Presence</emphasis></para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para><emphasis>IMS dialog</emphasis></para>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
</para>
|
||||
</section>
|
||||
</section>
|
||||
<section>
|
||||
<title>Parameters</title>
|
||||
<section id="ims_usrloc_scscf.p.db_url">
|
||||
<title><varname>db_url</varname> (string)</title>
|
||||
<para>database <acronym>URL</acronym> for storing impu/contacts records</para>
|
||||
<example>
|
||||
<title>Set <varname>db_url</varname>parameter</title>
|
||||
<programlisting format="linespecific">
|
||||
modparam("ims_usrloc_scscf", "db_url", "mysql//username:password@localhost/scscf")
|
||||
</programlisting>
|
||||
</example>
|
||||
</section>
|
||||
|
||||
<section id="ims_usrloc_scscf.p.db_mode">
|
||||
<title><varname>db_mode</varname> (string)</title>
|
||||
<para>This is the database mode to be used for the SCSCF usrloc data persistent storage. Currently this module supports the Write-Back scheme only.</para>
|
||||
<itemizedlist>
|
||||
<listitem>
|
||||
<para>
|
||||
0 - This disables database completely. Only memory will be used.
|
||||
Contacts will not survive restart.
|
||||
</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>
|
||||
1 - Write-Backend scheme. All changes are made to memory and database synchronization is done in the timer
|
||||
</para>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
<para><emphasis> Default value is 0. </emphasis></para>
|
||||
<example>
|
||||
<title>Set <varname>db_mode</varname>(int)</title>
|
||||
<programlisting format="linespecific">...
|
||||
modparam("ims_usrloc_scscf", "db_mode", 1)
|
||||
</programlisting>
|
||||
</example>
|
||||
</section>
|
||||
<section id="ims_usrloc_scscf.p.maxcontact">
|
||||
<title>maxcontact (int)</title>
|
||||
<para>The parameter can be used to limit the number of contact for each impu</para>
|
||||
<para><emphasis>Default value is 0(max)</emphasis></para>
|
||||
<example>
|
||||
<title>Set <varname>maxcontact</varname>parameter</title>
|
||||
<programlisting format="linespecific">...
|
||||
modparam("ims_usrloc_scscf", "maxcontact", 10)
|
||||
</programlisting>
|
||||
</example>
|
||||
</section>
|
||||
<section id="ims_usrloc_scscf.p.maxcontact_3gpp">
|
||||
<title>maxcontact_3gpp (int)</title>
|
||||
<para>The parameter can be used to limit the number of 3GPP contact for each impu</para>
|
||||
<para><emphasis> Default value is 0.(max) </emphasis></para>
|
||||
<example>
|
||||
<title>Set <varname>maxcontact_3gpp</varname>parameter</title>
|
||||
<programlisting format="linespecific">...
|
||||
modparam("ims_usrloc_scscf", "maxcontact_3gpp", 0)
|
||||
</programlisting>
|
||||
</example>
|
||||
</section>
|
||||
<section id="ims_usrloc_scscf.p.maxcontact_behaviour">
|
||||
<title>maxcontact_behaviour (int)</title>
|
||||
<para>Behaviour of usrloc , after impu reach max contacts limit.</para>
|
||||
<itemizedlist>
|
||||
<listitem>
|
||||
<para>
|
||||
0 - Disabled
|
||||
</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>
|
||||
1 - Reject after reaching limit.
|
||||
</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>
|
||||
2 - Overwrite
|
||||
</para>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
<para><emphasis> Default value is 0. </emphasis></para>
|
||||
<example>
|
||||
<title>Set <varname>maxcontact_behaviour</varname>
|
||||
parameter</title>
|
||||
<programlisting format="linespecific">...
|
||||
modparam("ims_usrloc_scscf", "maxcontact_behaviour", 2)
|
||||
</programlisting>
|
||||
</example>
|
||||
</section>
|
||||
<section id="ims_usrloc_scscf.p.max_subscribes">
|
||||
<title>max_subscribes(int)</title>
|
||||
<para>Max number of subscribes allowed per watcher for each IMPU </para>
|
||||
<para><emphasis> Default value is 0. </emphasis></para>
|
||||
<example>
|
||||
<title>Set <varname>subscription_expires_range</varname>parameter</title>
|
||||
<programlisting format="linespecific">...
|
||||
modparam("ims_usrloc_scscf", "max_subscribes", 2)
|
||||
</programlisting>
|
||||
</example>
|
||||
</section>
|
||||
<section id="ims_usrloc_scscf.p.sub_dialog_hash_size">
|
||||
<title>sub_dialog_hash_size(int)</title>
|
||||
<para>Subscriber dialog hash table size</para>
|
||||
<para><emphasis> Default value is 10. </emphasis></para>
|
||||
<example>
|
||||
<title>Set<varname>sub_dialog_hash_size</varname>parameter</title>
|
||||
<programlisting format="linespecific">...
|
||||
modparam("ims_usrloc_scscf", "sub_dialog_hash_size", 512)
|
||||
</programlisting>
|
||||
</example>
|
||||
</section>
|
||||
<section id="ims_usrloc_scscf.p.timer_procs">
|
||||
<title>timer_procs(int)</title>
|
||||
<para>process number of handling registeration </para>
|
||||
<para><emphasis> Default value is 0 </emphasis></para>
|
||||
<example>
|
||||
<title>Set<varname>timer_procs</varname>parameter</title>
|
||||
<programlisting format="linespecific">...
|
||||
modparam("ims_usrloc_scscf", "timer_procs", 5)
|
||||
</programlisting>
|
||||
</example>
|
||||
</section>
|
||||
<section id="ims_usrloc_scscf.p.timer_interval">
|
||||
<title>timer_interval (int)</title>
|
||||
<para>Number of seconds between two timer runs. The module uses a timer to delete expired contacts,
|
||||
synchronize with database and other tasks, that need to be run periodically</para>
|
||||
<para><emphasis> Default value is 90 </emphasis></para>
|
||||
<example>
|
||||
<title>Set <varname>timer_interval</varname>parameter</title>
|
||||
<programlisting format="linespecific">...
|
||||
modparam("ims_usrloc_scscf", "timer_interval", 120)
|
||||
</programlisting>
|
||||
</example>
|
||||
</section>
|
||||
<section id="ims_usrloc_scscf.p.desc_time_order">
|
||||
<title>desc_time_order (int)</title>
|
||||
<para>If the user's contacts should be kept timestamp ordered; otherwise the contact will be ordered based on q value. Non 0 value means true.</para>
|
||||
<para><emphasis> Default value is timestamp ordering not enabled </emphasis></para>
|
||||
<example>
|
||||
<title>Set <varname>desc_time_order</varname>parameter</title>
|
||||
<programlisting format="linespecific">...
|
||||
modparam("ims_usrloc_scscf", "desc_time_order", 1)
|
||||
</programlisting>
|
||||
</example>
|
||||
</section>
|
||||
<section id="ims_usrloc_scscf.p.matching_mode">
|
||||
<title>matching_mode (int)</title>
|
||||
<para>What contact matching algorithm to be used.</para>
|
||||
<itemizedlist>
|
||||
<listitem>
|
||||
<para>
|
||||
0 - Contact Only matching
|
||||
</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>
|
||||
1 - Contact and Callid Matching
|
||||
</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>
|
||||
2 - Contact and Path header matching
|
||||
</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>
|
||||
3 - Only contact IP and Port Matching
|
||||
</para>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
<para><emphasis> Default value is 0. </emphasis></para>
|
||||
<example>
|
||||
<title>Set <varname>matching_mode</varname>parameter</title>
|
||||
<programlisting format="linespecific">...
|
||||
modparam("ims_usrloc_scscf", "matching_mode", 0)
|
||||
</programlisting>
|
||||
</example>
|
||||
</section>
|
||||
<section id="ims_usrloc_scscf.p.cseq_delay">
|
||||
<title>cseq_delay (int)</title>
|
||||
<para>Delay (in seconds) for accepting as retransmissions register requests with same Call-ID and Cseq.</para>
|
||||
<para><emphasis> Default value is 20. </emphasis></para>
|
||||
<example>
|
||||
<title>Set <varname>scscf_name</varname>parameter</title>
|
||||
<programlisting format="linespecific">...
|
||||
modparam("ims_usrloc_scscf", "cseq_delay", 20)
|
||||
</programlisting>
|
||||
</example>
|
||||
</section>
|
||||
<section id="ims_usrloc_scscf.p.fetch_rows">
|
||||
<title>fetch_rows(int)</title>
|
||||
<para>The number of the rows to be fetched at once from database when loading the location records.</para>
|
||||
<para><emphasis> Default value is 2000. </emphasis></para>
|
||||
<example>
|
||||
<title>Set <varname>fetch_rows</varname>parameter</title>
|
||||
<programlisting format="linespecific">...
|
||||
modparam("ims_usrloc_scscf", "fetch_rows", 3000)
|
||||
</programlisting>
|
||||
</example>
|
||||
</section>
|
||||
<section id="ims_usrloc_scscf.p.hash_size">
|
||||
<title>hash_size (string)</title>
|
||||
<para>The number of entries of the hash table used by usrloc </para>
|
||||
<para><emphasis> Default value 512</emphasis></para>
|
||||
<example>
|
||||
<title>Set <varname>hash_size</varname>parameter</title>
|
||||
<programlisting format="linespecific">...
|
||||
modparam("ims_usrloc_scscf", "hash_size", 512)
|
||||
</programlisting>
|
||||
</example>
|
||||
</section>
|
||||
<section id="ims_usrloc_scscf.p.subs_hash_size">
|
||||
<title>subs_hash_size (int)</title>
|
||||
<para>The number of entries of the hash table used by usrloc to store the ims subscribe records</para>
|
||||
<para><emphasis> Default value 512</emphasis></para>
|
||||
<example>
|
||||
<title>Set <varname>subs_hash_size</varname>parameter</title>
|
||||
<programlisting format="linespecific">...
|
||||
modparam("ims_usrloc_scscf", "subs_hash_size", 512)
|
||||
</programlisting>
|
||||
</example>
|
||||
</section>
|
||||
<section id="ims_usrloc_scscf.p.contacts_hash_size">
|
||||
<title>contacts_hash_size (integer)</title>
|
||||
<para>The number of entries of the hash table used by usrloc to store the contact records</para>
|
||||
<para><emphasis> Default value is 512</emphasis></para>
|
||||
<example>
|
||||
<title>Set <varname>contacts_hash_size</varname>parameter</title>
|
||||
<programlisting format="linespecific">...
|
||||
modparam("ims_usrloc_scscf", "contacts_hash_size", 512)
|
||||
</programlisting>
|
||||
</example>
|
||||
</section>
|
||||
<section id="ims_usrloc_scscf.p.nat_bflag">
|
||||
<title>nat_bflag (integer)</title>
|
||||
<para>NAT marker to handle natted registration</para>
|
||||
<para><emphasis> Default value is 0 </emphasis></para>
|
||||
<example>
|
||||
<title>Set <varname>nat_bflag</varname>parameter</title>
|
||||
<programlisting format="linespecific">
|
||||
modparam("ims_usrloc_scscf", "nat_bflag", 3)
|
||||
</programlisting>
|
||||
</example>
|
||||
</section>
|
||||
<section id="ims_usrloc_scscf.p.contact_delete_delay">
|
||||
<title>contact_delete_delay (int)</title>
|
||||
<para>If contact is put into delay delete state ,this is how long we delay before deleting </para>
|
||||
<para><emphasis> Default value is 30</emphasis></para>
|
||||
<example>
|
||||
<title>Set <varname>contact_delete_delay</varname>parameter</title>
|
||||
<programlisting format="linespecific">
|
||||
modparam("ims_usrloc_scscf", "contact_delete_delay", 32)
|
||||
</programlisting>
|
||||
</example>
|
||||
</section>
|
||||
<section id="ims_usrloc_scscf.p.support_wildcardPSI">
|
||||
<title>support_wildcardPSI (int)</title>
|
||||
<para>Wildcard Public-Service-Identity (RFC5002). it will be actived by setting 1 </para>
|
||||
<para><emphasis> Default value is 0.(disabled) </emphasis></para>
|
||||
<example>
|
||||
<title>Set <varname>support_wildcardPSI</varname> parameter</title>
|
||||
<programlisting format="linespecific">
|
||||
modparam("ims_usrloc_scscf", "support_wildcardPSI", 0)
|
||||
</programlisting>
|
||||
</example>
|
||||
</section>
|
||||
<section id="ims_usrloc_scscf.p.unreg_validity">
|
||||
<title>unreg_validity (int)</title>
|
||||
<para>Default validity time in seconds for unregister assignment to SCSCF </para>
|
||||
<para><emphasis> Default value is 1800 </emphasis></para>
|
||||
<example>
|
||||
<title>Set <varname>unreg_validity</varname> parameter</title>
|
||||
<programlisting format="linespecific">
|
||||
modparam("ims_usrloc_scscf", "unreg_validity", 0)
|
||||
</programlisting>
|
||||
</example>
|
||||
</section>
|
||||
<section id="ims_usrloc_scscf.p.user_data_xsd">
|
||||
<title>user_data_xsd (string)</title>
|
||||
<para> </para>
|
||||
<para><emphasis> Default value is 1800 </emphasis></para>
|
||||
<example>
|
||||
<title>Set <varname>unreg_validity</varname> parameter</title>
|
||||
<programlisting format="linespecific">
|
||||
modparam("ims_usrloc_scscf", "user_data_xsd", "/usr/local/etc/kamailio/CxDataType_Rel6.xsd")
|
||||
</programlisting>
|
||||
</example>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<title>RPC Commands</title>
|
||||
<para>Exported RPC commands.</para>
|
||||
<section id="ims_usrloc_scscf.r.status">
|
||||
<title>ulscscf.status</title>
|
||||
<para></para>
|
||||
</section>
|
||||
<section id="ims_usrloc_scscf.r.showimpu">
|
||||
<title>ulscscf.showimpu</title>
|
||||
<para></para>
|
||||
</section>
|
||||
<section id="ims_usrloc_scscf.r.snapshot">
|
||||
<title>ulscscf.snapshot</title>
|
||||
<para></para>
|
||||
</section>
|
||||
</section>
|
||||
</chapter>
|
@ -0,0 +1,58 @@
|
||||
<?xml version="1.0" encoding='ISO-8859-1'?>
|
||||
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
|
||||
"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [
|
||||
<!-- Include general documentation entities -->
|
||||
<!ENTITY % docentities SYSTEM "../../../../doc/docbook/entities.xml">
|
||||
%docentities;
|
||||
]>
|
||||
<!-- Module FAQ -->
|
||||
<chapter>
|
||||
<title>&faqguide;</title>
|
||||
<qandaset defaultlabel="number">
|
||||
<qandaentry>
|
||||
<question>
|
||||
<para>Where can I find more about &kamailio;?</para>
|
||||
</question>
|
||||
<answer>
|
||||
<para>
|
||||
Take a look at &kamailiohomelink;.
|
||||
</para>
|
||||
</answer>
|
||||
</qandaentry>
|
||||
<qandaentry>
|
||||
<question>
|
||||
<para>Where can I post a question about this module?</para>
|
||||
</question>
|
||||
<answer>
|
||||
<para>
|
||||
First at all check if your question was already answered on one of
|
||||
our mailing lists:
|
||||
</para>
|
||||
<itemizedlist>
|
||||
<listitem>
|
||||
<para>User Mailing List - &kamailiouserslink;</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>Developer Mailing List - &kamailiodevlink;</para>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
<para>
|
||||
E-mails regarding any stable &kamailio; release should be sent to
|
||||
&kamailiousersmail; and e-mails regarding development versions
|
||||
should be sent to &kamailiodevmail;.
|
||||
</para>
|
||||
</answer>
|
||||
</qandaentry>
|
||||
<qandaentry>
|
||||
<question>
|
||||
<para>How can I report a bug?</para>
|
||||
</question>
|
||||
<answer>
|
||||
<para>
|
||||
Please follow the guidelines provided at:
|
||||
&kamailiobugslink;.
|
||||
</para>
|
||||
</answer>
|
||||
</qandaentry>
|
||||
</qandaset>
|
||||
</chapter>
|
@ -1,2 +0,0 @@
|
||||
* "Reliable" Notifications (implement using requests, and failover on error; ignore non-error responses) ?
|
||||
* Implement timout for non-Linux systems
|
@ -0,0 +1,15 @@
|
||||
COREPATH=../../../../src
|
||||
include $(COREPATH)/Makefile.defs
|
||||
include $(COREPATH)/Makefile.targets
|
||||
|
||||
.PHONY: all
|
||||
all: libfortuna.a
|
||||
|
||||
libfortuna.a:
|
||||
$(CC) -c -fPIC -I. $(CFLAGS) fortuna.c rijndael.c sha256.c random.c
|
||||
$(AR) rc $(OUT) fortuna.o rijndael.o sha256.o random.o
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -f *.a
|
||||
rm -r *.o
|
@ -0,0 +1,461 @@
|
||||
/*
|
||||
* fortuna.c
|
||||
* Fortuna-like PRNG.
|
||||
*
|
||||
* Copyright (c) 2005 Marko Kreen
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* contrib/pgcrypto/fortuna.c
|
||||
*/
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "rijndael.h"
|
||||
#include "sha256.h"
|
||||
#include "fortuna.h"
|
||||
|
||||
|
||||
/*
|
||||
* Why Fortuna-like: There does not seem to be any definitive reference
|
||||
* on Fortuna in the net. Instead this implementation is based on
|
||||
* following references:
|
||||
*
|
||||
* http://en.wikipedia.org/wiki/Fortuna_(PRNG)
|
||||
* - Wikipedia article
|
||||
* http://jlcooke.ca/random/
|
||||
* - Jean-Luc Cooke Fortuna-based /dev/random driver for Linux.
|
||||
*/
|
||||
|
||||
/*
|
||||
* There is some confusion about whether and how to carry forward
|
||||
* the state of the pools. Seems like original Fortuna does not
|
||||
* do it, resetting hash after each request. I guess expecting
|
||||
* feeding to happen more often that requesting. This is absolutely
|
||||
* unsuitable for pgcrypto, as nothing asynchronous happens here.
|
||||
*
|
||||
* J.L. Cooke fixed this by feeding previous hash to new re-initialized
|
||||
* hash context.
|
||||
*
|
||||
* Fortuna predecessor Yarrow requires ability to query intermediate
|
||||
* 'final result' from hash, without affecting it.
|
||||
*
|
||||
* This implementation uses the Yarrow method - asking intermediate
|
||||
* results, but continuing with old state.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Algorithm parameters
|
||||
*/
|
||||
|
||||
/*
|
||||
* How many pools.
|
||||
*
|
||||
* Original Fortuna uses 32 pools, that means 32'th pool is
|
||||
* used not earlier than in 13th year. This is a waste in
|
||||
* pgcrypto, as we have very low-frequancy seeding. Here
|
||||
* is preferable to have all entropy usable in reasonable time.
|
||||
*
|
||||
* With 23 pools, 23th pool is used after 9 days which seems
|
||||
* more sane.
|
||||
*
|
||||
* In our case the minimal cycle time would be bit longer
|
||||
* than the system-randomness feeding frequency.
|
||||
*/
|
||||
#define NUM_POOLS 23
|
||||
|
||||
/* in microseconds */
|
||||
#define RESEED_INTERVAL 100000 /* 0.1 sec */
|
||||
|
||||
/* for one big request, reseed after this many bytes */
|
||||
#define RESEED_BYTES (1024*1024)
|
||||
|
||||
/*
|
||||
* Skip reseed if pool 0 has less than this many
|
||||
* bytes added since last reseed.
|
||||
*/
|
||||
#define POOL0_FILL (256/8)
|
||||
|
||||
/*
|
||||
* Algorithm constants
|
||||
*/
|
||||
|
||||
/* Both cipher key size and hash result size */
|
||||
#define BLOCK 32
|
||||
|
||||
/* cipher block size */
|
||||
#define CIPH_BLOCK 16
|
||||
|
||||
/* for internal wrappers */
|
||||
#define MD_CTX SHA256_CTX
|
||||
#define CIPH_CTX rijndael_ctx
|
||||
|
||||
struct fortuna_state
|
||||
{
|
||||
u_int8_t counter[CIPH_BLOCK];
|
||||
u_int8_t result[CIPH_BLOCK];
|
||||
u_int8_t key[BLOCK];
|
||||
MD_CTX pool[NUM_POOLS];
|
||||
CIPH_CTX ciph;
|
||||
unsigned reseed_count;
|
||||
struct timeval last_reseed_time;
|
||||
unsigned pool0_bytes;
|
||||
unsigned rnd_pos;
|
||||
int tricks_done;
|
||||
};
|
||||
typedef struct fortuna_state FState;
|
||||
|
||||
|
||||
/*
|
||||
* Use our own wrappers here.
|
||||
* - Need to get intermediate result from digest, without affecting it.
|
||||
* - Need re-set key on a cipher context.
|
||||
* - Algorithms are guaranteed to exist.
|
||||
* - No memory allocations.
|
||||
*/
|
||||
|
||||
static void
|
||||
ciph_init(CIPH_CTX * ctx, const u_int8_t *key, int klen)
|
||||
{
|
||||
rijndael_set_key(ctx, (const u_int32_t *) key, klen, 1);
|
||||
}
|
||||
|
||||
static void
|
||||
ciph_encrypt(CIPH_CTX * ctx, const u_int8_t *in, u_int8_t *out)
|
||||
{
|
||||
rijndael_encrypt(ctx, (const u_int32_t *) in, (u_int32_t *) out);
|
||||
}
|
||||
|
||||
static void
|
||||
md_init(MD_CTX * ctx)
|
||||
{
|
||||
sr_SHA256_Init(ctx);
|
||||
}
|
||||
|
||||
static void
|
||||
md_update(MD_CTX * ctx, const u_int8_t *data, int len)
|
||||
{
|
||||
sr_SHA256_Update(ctx, data, len);
|
||||
}
|
||||
|
||||
static void
|
||||
md_result(MD_CTX * ctx, u_int8_t *dst)
|
||||
{
|
||||
SHA256_CTX tmp;
|
||||
|
||||
memcpy(&tmp, ctx, sizeof(*ctx));
|
||||
sr_SHA256_Final(dst, &tmp);
|
||||
memset(&tmp, 0, sizeof(tmp));
|
||||
}
|
||||
|
||||
/*
|
||||
* initialize state
|
||||
*/
|
||||
static void
|
||||
init_state(FState *st)
|
||||
{
|
||||
int i;
|
||||
|
||||
memset(st, 0, sizeof(*st));
|
||||
for (i = 0; i < NUM_POOLS; i++)
|
||||
md_init(&st->pool[i]);
|
||||
}
|
||||
|
||||
/*
|
||||
* Endianess does not matter.
|
||||
* It just needs to change without repeating.
|
||||
*/
|
||||
static void
|
||||
inc_counter(FState *st)
|
||||
{
|
||||
u_int32_t *val = (u_int32_t *) st->counter;
|
||||
|
||||
if (++val[0])
|
||||
return;
|
||||
if (++val[1])
|
||||
return;
|
||||
if (++val[2])
|
||||
return;
|
||||
++val[3];
|
||||
}
|
||||
|
||||
/*
|
||||
* This is called 'cipher in counter mode'.
|
||||
*/
|
||||
static void
|
||||
encrypt_counter(FState *st, u_int8_t *dst)
|
||||
{
|
||||
ciph_encrypt(&st->ciph, st->counter, dst);
|
||||
inc_counter(st);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* The time between reseed must be at least RESEED_INTERVAL
|
||||
* microseconds.
|
||||
*/
|
||||
static int
|
||||
enough_time_passed(FState *st)
|
||||
{
|
||||
int ok;
|
||||
struct timeval tv;
|
||||
struct timeval *last = &st->last_reseed_time;
|
||||
|
||||
gettimeofday(&tv, NULL);
|
||||
|
||||
/* check how much time has passed */
|
||||
ok = 0;
|
||||
if (tv.tv_sec > last->tv_sec + 1)
|
||||
ok = 1;
|
||||
else if (tv.tv_sec == last->tv_sec + 1)
|
||||
{
|
||||
if (1000000 + tv.tv_usec - last->tv_usec >= RESEED_INTERVAL)
|
||||
ok = 1;
|
||||
}
|
||||
else if (tv.tv_usec - last->tv_usec >= RESEED_INTERVAL)
|
||||
ok = 1;
|
||||
|
||||
/* reseed will happen, update last_reseed_time */
|
||||
if (ok)
|
||||
memcpy(last, &tv, sizeof(tv));
|
||||
|
||||
memset(&tv, 0, sizeof(tv));
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
/*
|
||||
* generate new key from all the pools
|
||||
*/
|
||||
static void
|
||||
reseed(FState *st)
|
||||
{
|
||||
unsigned k;
|
||||
unsigned n;
|
||||
MD_CTX key_md;
|
||||
u_int8_t buf[BLOCK];
|
||||
|
||||
/* set pool as empty */
|
||||
st->pool0_bytes = 0;
|
||||
|
||||
/*
|
||||
* Both #0 and #1 reseed would use only pool 0. Just skip #0 then.
|
||||
*/
|
||||
n = ++st->reseed_count;
|
||||
|
||||
/*
|
||||
* The goal: use k-th pool only 1/(2^k) of the time.
|
||||
*/
|
||||
md_init(&key_md);
|
||||
for (k = 0; k < NUM_POOLS; k++)
|
||||
{
|
||||
md_result(&st->pool[k], buf);
|
||||
md_update(&key_md, buf, BLOCK);
|
||||
|
||||
if (n & 1 || !n)
|
||||
break;
|
||||
n >>= 1;
|
||||
}
|
||||
|
||||
/* add old key into mix too */
|
||||
md_update(&key_md, st->key, BLOCK);
|
||||
|
||||
/* now we have new key */
|
||||
md_result(&key_md, st->key);
|
||||
|
||||
/* use new key */
|
||||
ciph_init(&st->ciph, st->key, BLOCK);
|
||||
|
||||
memset(&key_md, 0, sizeof(key_md));
|
||||
memset(buf, 0, BLOCK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Pick a random pool. This uses key bytes as random source.
|
||||
*/
|
||||
static unsigned
|
||||
get_rand_pool(FState *st)
|
||||
{
|
||||
unsigned rnd;
|
||||
|
||||
/*
|
||||
* This slightly prefers lower pools - thats OK.
|
||||
*/
|
||||
rnd = st->key[st->rnd_pos] % NUM_POOLS;
|
||||
|
||||
st->rnd_pos++;
|
||||
if (st->rnd_pos >= BLOCK)
|
||||
st->rnd_pos = 0;
|
||||
|
||||
return rnd;
|
||||
}
|
||||
|
||||
/*
|
||||
* update pools
|
||||
*/
|
||||
static void
|
||||
add_entropy(FState *st, const u_int8_t *data, unsigned len)
|
||||
{
|
||||
unsigned pos;
|
||||
u_int8_t hash[BLOCK];
|
||||
MD_CTX md;
|
||||
|
||||
/* hash given data */
|
||||
md_init(&md);
|
||||
md_update(&md, data, len);
|
||||
md_result(&md, hash);
|
||||
|
||||
/*
|
||||
* Make sure the pool 0 is initialized, then update randomly.
|
||||
*/
|
||||
if (st->reseed_count == 0)
|
||||
pos = 0;
|
||||
else
|
||||
pos = get_rand_pool(st);
|
||||
md_update(&st->pool[pos], hash, BLOCK);
|
||||
|
||||
if (pos == 0)
|
||||
st->pool0_bytes += len;
|
||||
|
||||
memset(hash, 0, BLOCK);
|
||||
memset(&md, 0, sizeof(md));
|
||||
}
|
||||
|
||||
/*
|
||||
* Just take 2 next blocks as new key
|
||||
*/
|
||||
static void
|
||||
rekey(FState *st)
|
||||
{
|
||||
encrypt_counter(st, st->key);
|
||||
encrypt_counter(st, st->key + CIPH_BLOCK);
|
||||
ciph_init(&st->ciph, st->key, BLOCK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Hide public constants. (counter, pools > 0)
|
||||
*
|
||||
* This can also be viewed as spreading the startup
|
||||
* entropy over all of the components.
|
||||
*/
|
||||
static void
|
||||
startup_tricks(FState *st)
|
||||
{
|
||||
int i;
|
||||
u_int8_t buf[BLOCK];
|
||||
|
||||
/* Use next block as counter. */
|
||||
encrypt_counter(st, st->counter);
|
||||
|
||||
/* Now shuffle pools, excluding #0 */
|
||||
for (i = 1; i < NUM_POOLS; i++)
|
||||
{
|
||||
encrypt_counter(st, buf);
|
||||
encrypt_counter(st, buf + CIPH_BLOCK);
|
||||
md_update(&st->pool[i], buf, BLOCK);
|
||||
}
|
||||
memset(buf, 0, BLOCK);
|
||||
|
||||
/* Hide the key. */
|
||||
rekey(st);
|
||||
|
||||
/* This can be done only once. */
|
||||
st->tricks_done = 1;
|
||||
}
|
||||
|
||||
static void
|
||||
extract_data(FState *st, unsigned count, u_int8_t *dst)
|
||||
{
|
||||
unsigned n;
|
||||
unsigned block_nr = 0;
|
||||
|
||||
/* Should we reseed? */
|
||||
if (st->pool0_bytes >= POOL0_FILL || st->reseed_count == 0)
|
||||
if (enough_time_passed(st))
|
||||
reseed(st);
|
||||
|
||||
/* Do some randomization on first call */
|
||||
if (!st->tricks_done)
|
||||
startup_tricks(st);
|
||||
|
||||
while (count > 0)
|
||||
{
|
||||
/* produce bytes */
|
||||
encrypt_counter(st, st->result);
|
||||
|
||||
/* copy result */
|
||||
if (count > CIPH_BLOCK)
|
||||
n = CIPH_BLOCK;
|
||||
else
|
||||
n = count;
|
||||
memcpy(dst, st->result, n);
|
||||
dst += n;
|
||||
count -= n;
|
||||
|
||||
/* must not give out too many bytes with one key */
|
||||
block_nr++;
|
||||
if (block_nr > (RESEED_BYTES / CIPH_BLOCK))
|
||||
{
|
||||
rekey(st);
|
||||
block_nr = 0;
|
||||
}
|
||||
}
|
||||
/* Set new key for next request. */
|
||||
rekey(st);
|
||||
}
|
||||
|
||||
/*
|
||||
* public interface
|
||||
*/
|
||||
|
||||
FState main_state;
|
||||
int init_done = 0;
|
||||
|
||||
void
|
||||
fortuna_add_entropy(const u_int8_t *data, unsigned len)
|
||||
{
|
||||
if (!init_done)
|
||||
{
|
||||
init_state(&main_state);
|
||||
init_done = 1;
|
||||
}
|
||||
if (!data || !len)
|
||||
return;
|
||||
add_entropy(&main_state, data, len);
|
||||
}
|
||||
|
||||
void
|
||||
fortuna_get_bytes(unsigned len, u_int8_t *dst)
|
||||
{
|
||||
if (!init_done)
|
||||
{
|
||||
init_state(&main_state);
|
||||
init_done = 1;
|
||||
}
|
||||
if (!dst || !len)
|
||||
return;
|
||||
extract_data(&main_state, len, dst);
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue