Call Us Today! 877.742.2583




Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Fix all links and import a 404 from web archive in the examples.

...

The limit APIs are implemented by mod_commands. You can also use them via the dialplan like so:

...

Variables Set by Limit

The following channel variables are set when limit is called.

...

You may choose to take advantage of the db backend mod_db to allow multiple servers to limit the number of calls and stay aware of how many calls <resource> has in session across all participating servers.

hash

mod_hash provides a hashtable backend for limit. It uses a hashtable as data structure (faster) and has some additional features. Here is the syntax for the main application:

...

If the maximum isn't specified, limit will count the number of active calls but won't limit anything.

hiredis

mod_hiredis provides a redis backend for limit.

Which Backend Do I Use?

BackendSpeedPersistenceCluster-abilityInterval Support
Hashfastestnosee hash_remoteyes
DBslowyespossibleno
Hiredisfastyes, configurableyesyes

...

Code Block
languagexml
themeEmacs
    <!-- set outound caller limit -->                                                                                                                           
    <extension name="set outbound limit" continue="true">                                                                                                       
      <condition field="destination_number" expression="^1?\d{7}" break="on-false"/>                                                                            
      <condition field="caller_id_number" expression="^(10[01][0-9])">                                                                                          
        <action application="limit" data="hash ${domain} $1 4 handle_over_limit XML over_limit_actions"/>                
        <action application="log" data="INFO Added limit for caller $1"/>                                                                                       
      </condition>                                                                                                                                              
    </extension>

More Examples

Some examples of using limit to protect against toll fraud is here.

...

Imported from an old FreeSwitch weekly article.

With the growing number of SIP attacks on the rise, a lot of people are worried about their exposure to toll fraud. A simple way of protecting
your wallet would be to limit the number of outbound calls your system can place using the dial plan. If one your extension get compromised
your attacker can only do so much damage per day.

Code Block
languagexml
themeEmacs
  <extension name="domestic.VoiceNetwork.ca">
    <condition field="${toll_allow}" expression="domestic"/>
    <condition field="destination_number" expression="^(\d{11})$">
      <action application="set" data="effective_caller_id_number=${outbound_caller_id_number}"/>
      <action application="set" data="effective_caller_id_name=${outbound_caller_id_name}"/>

    <!-- Only allow 4 simultaneous call -->
      <action application="limit" data="hash fraud_protection calls_max 4 !NORMAL_TEMPORARY_FAILURE"/>

    <!-- Only allow 250 calls per day -->
      <action application="limit" data="hash fraud_protection call_per_day 250/86400 !NORMAL_TEMPORARY_FAILURE"/>

      <action application="bridge" data="sofia/gateway/VoiceNetwork/$1"/>
    </condition>
  </extension> 


If you're not doing a lot of international calls why not limit the number of calls per day, the maximum duration of any call, and
the number of simultaneous calls.

Code Block
languagexml
themeEmacs
  <extension name="international.VoiceNetwork.ca">
    <condition field="${toll_allow}" expression="international"/>
    <condition field="destination_number" expression="^(011\d+)$">
      <action application="set" data="effective_caller_id_number=${outbound_caller_id_number}"/>
      <action application="set" data="effective_caller_id_name=${outbound_caller_id_name}"/>

      <!-- Limit the Call duration to 30 minutes per call, set lower if you need to -->
      <action application="sched_hangup" data="+1800 alloted_timeout"/>

      <!-- Only allow 1 simultaneous call -->
      <action application="limit" data="hash fraud_protection calls_max_intl 1 !NORMAL_TEMPORARY_FAILURE"/>

      <!-- Only allow 10 calls per day -->
      <action application="limit" data="hash fraud_protection call_per_day_intl 10/86400 !NORMAL_TEMPORARY_FAILURE"/>
      <action application="bridge" data="sofia/gateway/VoiceNetwork/$1"/>
    </condition>
  </extension> 


If you wanted to expand on this you could add variables to your user registrations this would allow you to set limits
for each registered user. Here is an example for user 1001.xml

Code Block
languagexml
themeEmacs
  <user id="1001">
    <params>
      <param name="password" value="$${default_password}"/>
      <param name="vm-password" value="1001"/>
    </params>
    <variables>
      <variable name="toll_allow" value="domestic,international,local"/>

      <!-- Set your Limits outbound call limits here for International calls -->
      <variable name="calls_max_intl" value="1"/>
      <variable name="call_per_day_intl" value="3"/>

      <variable name="accountcode" value="1001"/>
      <variable name="user_context" value="default"/>
      <variable name="effective_caller_id_name" value="Extension 1001"/>
      <variable name="effective_caller_id_number" value="1001"/>
      <variable name="outbound_caller_id_name" value="$${outbound_caller_name}"/>
      <variable name="outbound_caller_id_number" value="$${outbound_caller_id}"/>
      <variable name="callgroup" value="techsupport"/>
    </variables>
  </user> 


And your new international dialplan would have variables instead of hard coded values, and
you could change the limits on a per user bases.

Code Block
languagexml
themeEmacs
  <extension name="international.VoiceNetwork.ca">
    <condition field="${toll_allow}" expression="international"/>
    <condition field="destination_number" expression="^(011\d+)$">
      <action application="set" data="effective_caller_id_number=${outbound_caller_id_number}"/>
      <action application="set" data="effective_caller_id_name=${outbound_caller_id_name}"/>

      <!-- Limit the Call duration to 30 minutes per call, set lower if you need to -->
      <action application="sched_hangup" data="+1800 alloted_timeout"/>

      <!-- Only allow 1 simultaneous call -->
      <action application="limit" data="hash fraud_protection calls_max_intl ${calls_max_intl} !NORMAL_TEMPORARY_FAILURE"/>

      <!-- Only allow 10 calls per day -->
      <action application="limit" data="hash fraud_protection call_per_day_intl ${call_per_day_intl}/86400 !NORMAL_TEMPORARY_FAILURE"/>
      <action application="bridge" data="sofia/gateway/VoiceNetwork/$1"/>
    </condition>
  </extension>