|
@@ -23,7 +23,7 @@ Ovidiu Sas
|
|
|
|
|
|
<[email protected]>
|
|
|
|
|
|
- Copyright © 2008-2011 http://www.asipto.com
|
|
|
+ Copyright © 2008-2011 http://www.asipto.com
|
|
|
__________________________________________________________________
|
|
|
|
|
|
Table of Contents
|
|
@@ -52,6 +52,7 @@ Ovidiu Sas
|
|
|
3.11. timer_mode (integer)
|
|
|
3.12. db_expires (integer)
|
|
|
3.13. enable_dmq (integer)
|
|
|
+ 3.14. timer_procs (integer)
|
|
|
|
|
|
4. Functions
|
|
|
|
|
@@ -106,15 +107,16 @@ Ovidiu Sas
|
|
|
1.14. Set timer_mode parameter
|
|
|
1.15. Set db_expires parameter
|
|
|
1.16. Set enable_dmq parameter
|
|
|
- 1.17. sht_print usage
|
|
|
- 1.18. sht_rm_name_re usage
|
|
|
- 1.19. sht_rm_value_re usage
|
|
|
- 1.20. sht_reset usage
|
|
|
- 1.21. sht_lock usage
|
|
|
- 1.22. sht_unlock usage
|
|
|
- 1.23. sht_iterator_start usage
|
|
|
- 1.24. sht_iterator_end usage
|
|
|
- 1.25. sht_iterator_next usage
|
|
|
+ 1.17. Set timer_procs parameter
|
|
|
+ 1.18. sht_print usage
|
|
|
+ 1.19. sht_rm_name_re usage
|
|
|
+ 1.20. sht_rm_value_re usage
|
|
|
+ 1.21. sht_reset usage
|
|
|
+ 1.22. sht_lock usage
|
|
|
+ 1.23. sht_unlock usage
|
|
|
+ 1.24. sht_iterator_start usage
|
|
|
+ 1.25. sht_iterator_end usage
|
|
|
+ 1.26. sht_iterator_next usage
|
|
|
|
|
|
Chapter 1. Admin Guide
|
|
|
|
|
@@ -142,6 +144,7 @@ Chapter 1. Admin Guide
|
|
|
3.11. timer_mode (integer)
|
|
|
3.12. db_expires (integer)
|
|
|
3.13. enable_dmq (integer)
|
|
|
+ 3.14. timer_procs (integer)
|
|
|
|
|
|
4. Functions
|
|
|
|
|
@@ -199,7 +202,7 @@ Chapter 1. Admin Guide
|
|
|
You can read more about hash tables at:
|
|
|
http://en.wikipedia.org/wiki/Hash_table.
|
|
|
|
|
|
- The “name� can be a static string or can include pseudo- variables that
|
|
|
+ The "name" can be a static string or can include pseudo- variables that
|
|
|
will be replaced at runtime.
|
|
|
|
|
|
Example 1.1. Accessing $sht(htname=>key)
|
|
@@ -213,7 +216,7 @@ $sht(a=>$ci::srcip) = $si;
|
|
|
Next example shows a way to protect against dictionary attacks. If
|
|
|
someone fails to authenticate 3 times, it is forbidden for 15min.
|
|
|
Authenticatiion against database is expensive as it does a select on
|
|
|
- the “subscriberthe� table. By disabling the DB auth for 15min,
|
|
|
+ the "subscriberthe" table. By disabling the DB auth for 15min,
|
|
|
resources on the server are saved and time to discover the password is
|
|
|
increased substantially. Additional alerting can be done by writing a
|
|
|
message to syslog or sending email, etc.
|
|
@@ -222,7 +225,7 @@ $sht(a=>$ci::srcip) = $si;
|
|
|
the failed authentications per user and one for storing the time of
|
|
|
last authentication attempt. To ensure a unique name per user, the hash
|
|
|
table uses a combination of authentication username and text
|
|
|
- “::auth_count� and “::last_auth�.
|
|
|
+ "::auth_count" and "::last_auth".
|
|
|
|
|
|
Example 1.2. Dictionary attack limitation
|
|
|
...
|
|
@@ -414,6 +417,7 @@ $ kamcmd htable.dump htable
|
|
|
3.11. timer_mode (integer)
|
|
|
3.12. db_expires (integer)
|
|
|
3.13. enable_dmq (integer)
|
|
|
+ 3.14. timer_procs (integer)
|
|
|
|
|
|
3.1. htable (str)
|
|
|
|
|
@@ -447,7 +451,7 @@ $ kamcmd htable.dump htable
|
|
|
however, in which case this attribute can be set to 0.
|
|
|
* dmqreplicate - if set to 1, any actions (set, update, delete etc.)
|
|
|
performed upon entries in this table will be replicated to other
|
|
|
- nodes (htable peers). Please note, module parameter “enable_dmq�
|
|
|
+ nodes (htable peers). Please note, module parameter "enable_dmq"
|
|
|
must also be set in order for this to apply (see below). Default is
|
|
|
0 (no replication).
|
|
|
|
|
@@ -610,6 +614,20 @@ modparam("htable", "db_expires", 1)
|
|
|
modparam("htable", "enable_dmq", 1)
|
|
|
...
|
|
|
|
|
|
+3.14. timer_procs (integer)
|
|
|
+
|
|
|
+ If set to 1, the module will create its own timer process to scan for
|
|
|
+ expired items in hash tables. If set to zero, it will use the core
|
|
|
+ timer for this task. Set it to 1 if you store a lot of items with
|
|
|
+ autoexpire property.
|
|
|
+
|
|
|
+ Default value is 0.
|
|
|
+
|
|
|
+ Example 1.17. Set timer_procs parameter
|
|
|
+...
|
|
|
+modparam("htable", "timer_procs", 1)
|
|
|
+...
|
|
|
+
|
|
|
4. Functions
|
|
|
|
|
|
4.1. sht_print()
|
|
@@ -622,7 +640,7 @@ modparam("htable", "enable_dmq", 1)
|
|
|
4.8. sht_iterator_end(iname)
|
|
|
4.9. sht_iterator_next(iname)
|
|
|
|
|
|
-4.1. sht_print()
|
|
|
+4.1. sht_print()
|
|
|
|
|
|
Dump content of hash table to L_ERR log level. Intended for debug
|
|
|
purposes.
|
|
@@ -630,12 +648,12 @@ modparam("htable", "enable_dmq", 1)
|
|
|
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
|
|
|
ONREPLY_ROUTE, BRANCH_ROUTE.
|
|
|
|
|
|
- Example 1.17. sht_print usage
|
|
|
+ Example 1.18. sht_print usage
|
|
|
...
|
|
|
sht_print();
|
|
|
...
|
|
|
|
|
|
-4.2. sht_rm_name_re(htable=>regexp)
|
|
|
+4.2. sht_rm_name_re(htable=>regexp)
|
|
|
|
|
|
Delete all entries in the htable that match the name against regular
|
|
|
expression.
|
|
@@ -643,12 +661,12 @@ sht_print();
|
|
|
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
|
|
|
ONREPLY_ROUTE, BRANCH_ROUTE.
|
|
|
|
|
|
- Example 1.18. sht_rm_name_re usage
|
|
|
+ Example 1.19. sht_rm_name_re usage
|
|
|
...
|
|
|
sht_rm_name_re("ha=>.*");
|
|
|
...
|
|
|
|
|
|
-4.3. sht_rm_value_re(htable=>regexp)
|
|
|
+4.3. sht_rm_value_re(htable=>regexp)
|
|
|
|
|
|
Delete all entries in the htable that match the value against regular
|
|
|
expression.
|
|
@@ -656,24 +674,24 @@ sht_rm_name_re("ha=>.*");
|
|
|
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
|
|
|
ONREPLY_ROUTE, BRANCH_ROUTE.
|
|
|
|
|
|
- Example 1.19. sht_rm_value_re usage
|
|
|
+ Example 1.20. sht_rm_value_re usage
|
|
|
...
|
|
|
sht_rm_value_re("ha=>.*");
|
|
|
...
|
|
|
|
|
|
-4.4. sht_reset(htable)
|
|
|
+4.4. sht_reset(htable)
|
|
|
|
|
|
Delete all entries in the htable. The name of the hash table can be a
|
|
|
dynamic string with variables.
|
|
|
|
|
|
This function can be used from ANY_ROUTE.
|
|
|
|
|
|
- Example 1.20. sht_reset usage
|
|
|
+ Example 1.21. sht_reset usage
|
|
|
...
|
|
|
sht_reset("ha$var(x)");
|
|
|
...
|
|
|
|
|
|
-4.5. sht_lock(htable=>key)
|
|
|
+4.5. sht_lock(htable=>key)
|
|
|
|
|
|
Lock the slot in htable corespoding to the key item. Note that the
|
|
|
locking is re-entrant for the process, therefore the lock and unlock
|
|
@@ -681,12 +699,12 @@ sht_reset("ha$var(x)");
|
|
|
|
|
|
This function can be used from ANY_ROUTE.
|
|
|
|
|
|
- Example 1.21. sht_lock usage
|
|
|
+ Example 1.22. sht_lock usage
|
|
|
...
|
|
|
sht_lock("ha=>test");
|
|
|
...
|
|
|
|
|
|
-4.6. sht_unlock(htable=>key)
|
|
|
+4.6. sht_unlock(htable=>key)
|
|
|
|
|
|
Unlock the slot in htable corespoding to the key item. Note that the
|
|
|
locking is re-entrant for the process, therefore the lock and unlock
|
|
@@ -694,14 +712,14 @@ sht_lock("ha=>test");
|
|
|
|
|
|
This function can be used from ANY_ROUTE.
|
|
|
|
|
|
- Example 1.22. sht_unlock usage
|
|
|
+ Example 1.23. sht_unlock usage
|
|
|
...
|
|
|
sht_lock("ha=>test");
|
|
|
$sht(ha=>test) = $sht(ha=>test) + 10;
|
|
|
sht_unlock("ha=>test");
|
|
|
...
|
|
|
|
|
|
-4.7. sht_iterator_start(iname, hname)
|
|
|
+4.7. sht_iterator_start(iname, hname)
|
|
|
|
|
|
Start an iterator for hash table named by the value of parameter hname.
|
|
|
The parameter iname is used to identify the iterator. There can be up
|
|
@@ -716,12 +734,12 @@ sht_unlock("ha=>test");
|
|
|
|
|
|
This function can be used from ANY_ROUTE.
|
|
|
|
|
|
- Example 1.23. sht_iterator_start usage
|
|
|
+ Example 1.24. sht_iterator_start usage
|
|
|
...
|
|
|
sht_iterator_start("i1", "h1");
|
|
|
...
|
|
|
|
|
|
-4.8. sht_iterator_end(iname)
|
|
|
+4.8. sht_iterator_end(iname)
|
|
|
|
|
|
Close the iterator identified by iname parameter and release the hash
|
|
|
table slot aquired by the iterator. The iname value must be the same
|
|
@@ -731,12 +749,12 @@ sht_iterator_start("i1", "h1");
|
|
|
|
|
|
This function can be used from ANY_ROUTE.
|
|
|
|
|
|
- Example 1.24. sht_iterator_end usage
|
|
|
+ Example 1.25. sht_iterator_end usage
|
|
|
...
|
|
|
sht_iterator_end("i1");
|
|
|
...
|
|
|
|
|
|
-4.9. sht_iterator_next(iname)
|
|
|
+4.9. sht_iterator_next(iname)
|
|
|
|
|
|
Move the iterator to the next item in hash table. It must be called
|
|
|
also after sht_iterator_start() to get the first item in the hash
|
|
@@ -753,7 +771,7 @@ sht_iterator_end("i1");
|
|
|
|
|
|
This function can be used from ANY_ROUTE.
|
|
|
|
|
|
- Example 1.25. sht_iterator_next usage
|
|
|
+ Example 1.26. sht_iterator_next usage
|
|
|
...
|
|
|
sht_iterator_start("i1", "h1");
|
|
|
while(sht_iterator_next("i1")) {
|
|
@@ -781,7 +799,7 @@ sht_iterator_end("i1");
|
|
|
6.2. sht_dump
|
|
|
6.3. sht_delete
|
|
|
|
|
|
-6.1. sht_reload
|
|
|
+6.1. sht_reload
|
|
|
|
|
|
Reload a hash table from database.
|
|
|
|
|
@@ -794,7 +812,7 @@ sht_iterator_end("i1");
|
|
|
_hash_table_name_
|
|
|
_empty_line_
|
|
|
|
|
|
-6.2. sht_dump
|
|
|
+6.2. sht_dump
|
|
|
|
|
|
Dump content of a hash table via MI.
|
|
|
|
|
@@ -807,7 +825,7 @@ sht_iterator_end("i1");
|
|
|
_hash_table_name_
|
|
|
_empty_line_
|
|
|
|
|
|
-6.3. sht_delete
|
|
|
+6.3. sht_delete
|
|
|
|
|
|
Delete a key from a hash table via MI.
|
|
|
|
|
@@ -837,7 +855,7 @@ sht_iterator_end("i1");
|
|
|
7.7. htable.listTables
|
|
|
7.8. htable.stats
|
|
|
|
|
|
-7.1. htable.get htable key
|
|
|
+7.1. htable.get htable key
|
|
|
|
|
|
Lists one value in a hash table
|
|
|
|
|
@@ -856,7 +874,7 @@ kamcmd htable.get students daniel
|
|
|
kamcmd htable.get students course[0]
|
|
|
...
|
|
|
|
|
|
-7.2. htable.delete htable key
|
|
|
+7.2. htable.delete htable key
|
|
|
|
|
|
Delete one value in a hash table
|
|
|
|
|
@@ -875,7 +893,7 @@ kamcmd htable.delete students anna
|
|
|
kamcmd htable.delete students course[0]
|
|
|
...
|
|
|
|
|
|
-7.3. htable.sets htable key value
|
|
|
+7.3. htable.sets htable key value
|
|
|
|
|
|
Set an item in hash table to string value.
|
|
|
|
|
@@ -895,7 +913,7 @@ kamcmd htable.sets test x abc
|
|
|
kamcmd htable.sets test x[0] abc
|
|
|
...
|
|
|
|
|
|
-7.4. htable.seti htable key value
|
|
|
+7.4. htable.seti htable key value
|
|
|
|
|
|
Set an item in hash table to integer value.
|
|
|
|
|
@@ -915,7 +933,7 @@ kamcmd htable.seti test x 123
|
|
|
kamcmd htable.sets test x[0] 123
|
|
|
...
|
|
|
|
|
|
-7.5. htable.dump htable
|
|
|
+7.5. htable.dump htable
|
|
|
|
|
|
Lists all the values in a hash table
|
|
|
|
|
@@ -929,7 +947,7 @@ kamcmd htable.sets test x[0] 123
|
|
|
kamcmd htable.dump ipban
|
|
|
...
|
|
|
|
|
|
-7.6. htable.reload htable
|
|
|
+7.6. htable.reload htable
|
|
|
|
|
|
Reload hash table from database.
|
|
|
|
|
@@ -943,7 +961,7 @@ kamcmd htable.dump ipban
|
|
|
kamcmd htable.reload ipban
|
|
|
...
|
|
|
|
|
|
-7.7. htable.listTables
|
|
|
+7.7. htable.listTables
|
|
|
|
|
|
Lists all defined tables
|
|
|
|
|
@@ -957,7 +975,7 @@ kamcmd htable.reload ipban
|
|
|
kamcmd htable.listTables
|
|
|
...
|
|
|
|
|
|
-7.8. htable.stats
|
|
|
+7.8. htable.stats
|
|
|
|
|
|
Get statistics for hash tables - name, number of slots, number of
|
|
|
items, max number of items per slot, min number of items per slot.
|
|
@@ -977,7 +995,7 @@ kamcmd htable.stats
|
|
|
8.1. htable:mod-init
|
|
|
8.2. htable:expired:<table>
|
|
|
|
|
|
-8.1. htable:mod-init
|
|
|
+8.1. htable:mod-init
|
|
|
|
|
|
When defined, the module calls event_route[htable:mod-init] after all
|
|
|
modules have been initialized. A typical use case is to initialise
|
|
@@ -990,7 +1008,7 @@ event_route[htable:mod-init] {
|
|
|
}
|
|
|
...
|
|
|
|
|
|
-8.2. htable:expired:<table>
|
|
|
+8.2. htable:expired:<table>
|
|
|
|
|
|
When defined, the module calls event_route[htable:expired:<table>] when
|
|
|
an entry in the given table expires. In this event route, the key and
|