The following sections in the config file can be used to configure how calls are routed. A bit simplified, "routing" means that the gatekeeper must find a destination IP where to send each incomming call. Usually this is done by looking at the called name or number, but there are also other possibilities.
Each call gets passed down a chain of routing policies. Each policy may route the call and terminate the chain or modify it and pass it on. You can use the setting in the following sections to specify which policies to use and modify their behavior.
This section explains how the various potential routing policies within the GNU Gatekeeper work.
The incoming call requests can be routed using the following possibilities:
explicit
The destination is explicitly specified in the call to be routed. This policy is needed for dialing by IP number. You can define mappings for the destination IP in the Routing::Explicit section.
internal
The classical rule; search the destination in RegistrationTable
parent
Route the call using information sent by the parent gatekeeper in reply to an ARQ the gatekeeper will send. You can define your parent gatekeeper using the Endpoint section.
neighbor
Route the call using neighbors by exchanging LRQ messages.
dns
The destination is resolved from DNS A records or plain IP adresses in the called alias. This policy can be configured in the Routing::DNS section.
sql
Route calls by rewriting the called alias with a database query or send them directly to a destination IP. The database parameters are specified in the Routing::Sql section.
vqueue
Use the virtual queue mechanism and generate a RouteRequest event to let an external application do the routing.
numberanalysis
Provides support for overlapped digit sending for ARQ messages. This also partially supports Setup messages (no overlapped sending - only number length validation).
enum
ENUM (RFC3761) is a method to use DNS lookups to convert
real International Direct Dialing E.164 numbers into H.323 dialing information. The default servers
are e164.voxgratia.net
, e164.org
and e164.arpa
.
To specify your own list of servers use the ENUMservers
switch in the RoutedMode section.
The enum policy replaces the destination with the information returned by the ENUM server, so you must have the appropriate routing policies to continue processing the call after the enum policy. You should have the srv and dns policies after the enum policy, because the new location is often returned in the form of 'number@gatekeeper' and the srv and dns policies are needed to resolve this.
Finally, keep in mind that each routing check with the enum policy requires a DNS lookup. To speed up your routing, make sure you resolve internal destinations before the enum policy is applied.
This policy can be configured in the Routing::ENUM section.
srv
DNS SRV or H.323 Annex O allows for the routing of calls using a H.323 URI. Addresses can be configured as user (at) domain. H.323 URIs are stored in the SRV DNS records of the domain and are queried to find the destination.
This policy can be configured in the Routing::SRV section.
rds
URN RDS or Universal resources name resolver discovery system is a system (as defined in RFC 2915 Sect 7.2 whereby domain names SRV records are hosted on other domains. In this policy the servers set by [RoutedMode] RDSServers are queried to resolve URI's whose domains do not have SRV records. This can be used to virtually host URL domains or centralize the control of SRV records.
This policy can be configured in the Routing::RDS section.
catchall
This policy will route all calls that reach it to one endpoint specified in the Routing::CatchAll section. You can use it as a fallback at the end of the policy chain to route all calls which would otherwise fail.
Default configuration for routing policies is as follows:
[RoutingPolicy]
default=explicit,internal,parent,neighbor
If one policy does not match, the next policy is tried.
These policies can be applied to a number of routing request types and routing input data. The different types are ARQ, LRQ, Setup and Facility (with the callForwarded reason). There is also the general routing policy, which is a default for the other types.
[RoutingPolicy]
h323_ID=dns,internal
002=neighbor,internal
Default=internal,neighbor,parent
When a message is received which requires a routing decision, all calls to an alias of the h323_ID type will be resolved using DNS. If DNS fails to resolve the alias, it is matched against the internal registration table. If a call is requested to an alias starting with 002, first the neighbors are checked and then the internal registration table. If the requested alias is not an h323_ID or an alias starting with 002, the default policy is used by querying the internal registration table, then the neighbors, and if that fails the parent.
For the ARQ, LRQ, Setup and Facility messages one would use the [RoutingPolicy::OnARQ], [RoutingPolicy::OnLRQ], [RoutingPolicy::OnSetup] and [RoutingPolicy::OnFacility] sections using the syntax explained above.
[RoutingPolicy::OnARQ]
default=numberanalysis,internal,neighbor
A typical ENUM routing setup would look like this:
[RoutingPolicy]
default=explicit,internal,enum,srv,dns,internal,parent,neighbor
This section defines the rewriting rules for dialedDigits (E.164 number).
[!]original-prefix=target-prefix
If the number begins with original-prefix
,
it is rewritten to target-prefix
.
If the `!
' flag precedes the original-prefix
, the sense is inverted
and the target-prefix is prepended to the dialed number. Special wildcard
characters ('.'
and '%'
) are available.
08=18888
If you dial 08345718
, it is rewritten to 18888345718
.
!08=18888
If you dial 09345718
, it is rewritten to 1888809345718
.
Option:
Fastmatch=08
N/A
Only rewrite dialDigits beginning with the specified prefix.
This section defines the rewriting rules for aliases. This can be used to map gatekeeper assigned aliases to registered endpoints.
[!]original-alias=target-alias
If the alias is original-alias
,
it is rewritten to target-alias
.
bill=033123456
This section describes rewriting the dialedDigits E.164 number depending on the gateway a call has come from or is being sent to. This allows for more flexible manipulation of the dialedDigits for routing etc.
Despite the name of the section, you can not only rewrite calls from and to gateways, but also calls from terminals (regular endpoints) and neighbor gatekeepers.
In combination with the RasSrv::RewriteE164 you can have triple stage rewriting:
Call from "gw1", dialedDigits 0867822
|
|
V
Input rules for "gw1", dialedDigits now 550867822
|
|
V
Global rules, dialedDigits now 440867822
|
|
V
Gateway selection, dialedDigits now 440867822, outbound gateway "gw2"
|
|
V
Output rules for "gw2", dialedDigits now 0867822
|
|
V
Call to "gw2", dialedDigits 0867822
alias=in|out=[!]original-prefix=target-prefix[;in|out...]
If the call matches the alias, the direction and begins with
original-prefix
it is rewritten to target-prefix
.
If the `!
' flag precedes the original-prefix
, the sense is inverted.
Special wildcard characters ('.'
and '%'
) are available.
'.' matches one character and '%' matches any number of characters.
Multiple rules for the same gateway are separated by ';'.
Calls from and to gateways and terminals are matched by their first alias. Calls from and to neighbors are matched by the neighbor ID in the GnuGk config (the XXX in the [Neighbor::XXX] section name) or the gatekeeper identifier of the neighbor if it is set.
Note that when you have multi-homed neighbors or are accepting non-neighbor LRQs, the source of the call can not always be determined and no IN rule for a neighbor will match. In these cases you should only use OUT and [RasSrv::RewriteE164] rules.
gw1=in=123=321
If a call is received from "gw1" to 12377897
, it is rewritten to 32177897
before further action is taken.
In this example the neighbor is identified by it's ID and incoming calls from NbGk will have their 01 prefix replaced by an 04 prefix and the reverse for outgoing calls.
[RasSrv::Neighbors]
NbGk=GnuGk
[Neighbor::NbGk]
GatekeeperIdentifier=GK-PW-Prox
Host=192.168.1.100
SendPrefixes=*
AcceptPrefixes=*
[RasSrv::GWRewriteE164]
NbGk=in=01=04;out=04=01
In this example the neighbor is identified by it's gatekeeper identifier and incoming calls from GK-PW-Prox that don't have a 0049 prefix get this prefix prepended. Eg. a call to 1234 would be rewritten to 00491234 while a call to 00496789 would proceed unchanged.
[RasSrv::Neighbors]
NbGk=GnuGk
[Neighbor::NbGk]
GatekeeperIdentifier=GK-PW-Prox
Host=192.168.1.100
SendPrefixes=*
AcceptPrefixes=*
[RasSrv::GWRewriteE164]
GK-PW-Prox=in=!0049.=0049.
Once you specify prefix(es) for your gatekeeper endpoint, the parent gatekeeper will route calls with dialedDigits beginning with that prefixes. The child gatekeeper can rewrite the destination according to the rules specified in this section. By contrast, when an internal endpoint calls an endpoint registered to the parent gatekeeper, the source will be rewritten reversely.
external prefix=internal prefix
For example, if you have the following configuration,
[Parent GK]
ID=MasterGK
/ \
/ \
/ \
/ \
[Child GK] [EP3]
ID=ProxyGK E164=18888200
Prefix=188886
/ \
/ \
/ \
[EP1] [EP2]
E164=601 E164=602
With this rule:
188886=6
When EP1 calls EP3 by 18888200
, the CallingPartyNumber in the Q.931 Setup
will be rewritten to 18888601
. Conversely, EP3 can reach EP1 and EP2
by calling 18888601
and 18888602
, respectively. In consequence, an
endpoint registered to the child gatekeeper with prefix '6
' will appear
as an endpoint with prefix '188886
', for endpoints registered to
the parent gatekeeper.
The section does not relate to the section RasSrv::RewriteE164, though the latter will take effect first.
ResolveNonLocalLRQ=0
1
This switch selects if the DNS policy should resolve hostnames or IPs in LRQs that don't terminate locally.
ResolveLRQ=1
0
This switch selects if the 'enum' policy should resolve LRQs.
ResolveNonLocalLRQ=1
0
This switch selects if the 'srv' policy should resolve hostnames in LRQs that don't terminate locally.
ResolveLRQ=1
0
This switch selects if the 'rds' policy should resolve hostnames in LRQs.
You can define a mapping where calls to certain IPs should be routed by the 'explicit' policy.
IP=newIP[:port]
[Routing::Explicit]
192.168.1.100=10.10.1.100
192.168.1.101=10.10.1.101:1720
Rewrite the called alias with a SQL query. Supports routing OnARQ, OnLRQ and OnSetup.
If the string returned from the database is 'REJECT' (upper or lower case), the call is rejected. If the string matches a dotted IP address, it is taken as destination IP otherwise it is treated as a new destination alias. If 2 columns are returned, the first is treated as the new destination alias and the second is treated as new destination IP. If the 2nd column contains 'IGNORE', the database result is treated as if it would only contain 1 result column. (This allows simpler SQL queries in some cases.)
If multiple rows of destination IPs are returned they are used as alternative routes for failover and GnuGk will try them in order.
When at least one destination IP is specified or the call is rejected, the SQL policy will end the routing chain. If only the alias is changed, the chain continues with this updated alias.
When rejecting a call, the 2nd column can contain an integer designating the reject reason (H.225 AdmissionRejectReason for registered calls, H.225 LocationRejectReason for neighbor calls, H.225 disconnect reason for unregistered calls).
If the database returns nothing, the call is passed on unchanged.
Use the common database configuration options to define your database connection for this module.
Query=SELECT ...
N/A
Define a SQL query to fetch the new destination number. The query is parameterized - that means parameter replacement is made before each query is executed. The following parameters are defined:
%c
- the called alias%p
- the called IP (only available on Setup, empty otherwise)%s
- the calling IP%r
- the calling aliases%{Calling-Station-Id}
- the calling station ID (same value as used in accounting and authentication events)%i
- the call ID%m
- the message type (ARQ, LRQ or Setup)%{client-auth-id}
- a 64 bit integer ID provided to GnuGk when authenticating the call (through SQLAuth)If the query returns no rows, the current alias is used. Otherwise, the first result row is used.
Query string examples. Note that these are examples; the actual structure and schema are user defined, as are the various field names in these examples. GnuGk is simply expecting either IP addresses or aliases as a result of the query.
SELECT destination FROM routes WHERE called = '%c'
SELECT concat(prefix,'%c') FROM routes WHERE prefix = LEFT('%c', 5)
SELECT gatewayip FROM routes WHERE prefix = LEFT('%c',5)
SELECT concat(prefix,'%c'), gatewayip FROM routes WHERE route = LEFT('%c', 5) limit 3
This section defines rules for the numberanalysis
routing policy.
The policy checks a dialed number for minimum and/or maximum number of digits
and sends ARJ, if necessary (number of digits is out of range), to support
overlapped digit sending. It also partially supports Setup messages (no overlapped sending
- only number length validation).
prefix=MIN_DIGITS[:MAX_DIGITS]
If the number matches the prefix
, it is verified to consist of at least
MIN_DIGITS
digits and (if MAX_DIGITS is present) at most MAX_DIGITS
digits. Special wildcard characters (!
, '.'
and '%'
) are available.
If the number is too short, an ARJ is send with rejectReason
set to incompleteAddress
.
If the number is too long, an ARJ is send with rejectReason
set to undefinedReason
.
Prefix list is searched from the longest to the shortest prefix for a match.
For Setup messages, a Release Complete with "badFormatAddress" is sent when the number
has an incorrect length.
[RoutingPolicy::OnARQ]
default=numberanalysis,internal
[Routing::NumberAnalysis]
0048=12
48=10
.=6:20
Calls to destinations starting with 0048 require at least 12 digits, to 48 we require 10 digits and to all other destinations at least 6 and at most 20 digits.
CatchAllIP=1.2.3.4
(empty)
Specify an IP address to route all calls to. This overrides CatchAllAlias.
CatchAllAlias=Frank
catchall
If CatchAllIP is not specified, then route all calls to this alias.
This section contains a set of rewrite rules for ANI/CLI/H.323_ID numbers (Caller ID). The rewrite process is done in two stages - inbound rewrite and outbound rewrite. The inbound rewrite is done before any other Q.931 Setup message processing (such as inbound GWRewrite, authentication, accounting, ...), and because it alters the Calling-Station-Id it will have an effect in the authorization and accounting modules. The outbound rewrite takes place just before the Setup message is to be forwarded and its effect is visible only to the callee.
An inbound rewrite rule can be matched by a caller's IP and a dialed number or an original CLI/ANI. An outbound rewrite rule can be matched by a caller's IP, callee's IP and a dialed number or a destination number (the dialed number after rewrite) or a CLI/ANI (after inbound rewrite).
This module also provides CLIR (Calling Line Identification Restriction) feature that can be configured for each endpoint (rule).
ProcessSourceAddress=1
1
In addition to rewriting a Calling-Party-Number Information Element ("IE"), the sourceAddress element of a H.225.0 Setup message can be rewritten, so both contain consistent information.
RemoveH323Id=1
1
When a sourceInfo element of an H.225.0 Setup message is rewritten, aliases of type H323_ID, email_ID and url_ID can be left untouched if this option is disabled.
CLIRPolicy=apply
N/A
A global Presentation Indicator ("PI") processing policy can be set up.
This policy will be applied to all CLI rewrite rules that do not override it.
Possible choices are forward
- just forward the received PI as-is,
apply
- examine the received PI and hide CLI if it is set to "presentation
restricted" and applyforterminals
- similar to apply
except that the number
is removed only when the call is sent to a terminal, not a gateway.
in:CALLER_IP=[pi=[allow|restrict][,forward|apply|applyforterminals]] [cli:|dno:]number_prefix(=|*=|~=|^=|/=)NEW_CLI[,NEW_CLI]...
The in:
prefix specifies that this is an inbound rule and the CALLER_IP
will be used to match the rule (it can be a single IP or an entire subnet).
You can use IPv4 or IPv6 addresses for the CALLER_IP
.
The optional pi=
parameter controls CLIR (Calling Line Identification Restriction)
features. Specifying either allow
or restrict
forces presentation indicator
to be set to "presentation allowed" or "presentation restricted". forward
, apply
and applyforterminals
controls how the received (if any) presentation indicator
is processed by the gatekeeper. forward
means forward it to the callee as-is,
apply
is used to hide the CLI if the PI is set to "presentation restricted", applyforterminals
is similar to apply
, except that CLI is hidden only when sending the call to a terminal,
not a gateway.
The prefix cli:
or dno:
(the default) selects what number will be used
to match the number_prefix
- a caller id (CLI/ANI) or a dialed number.
Number matching/rewriting can be done in five ways:
=
- a cli
or dno
number will be matched using a prefix
match against number_prefix
and, if the match is found,
CLI will be replaced with NEW_CLI.~=
- a cli
or dno
number will be matched using an identity
match against number_prefix
and, if both numbers are the same,
CLI will be replaced with NEW_CLI.*=
- (VALID ONLY FOR cli
) a cli
number will be matched using
a prefix match against number_prefix
and, if the match is found,
the matched CLI prefix (number_prefix
) will be replaced
with a NEW_CLI prefix.^=
- a cli
or dno
number will be matched using a prefix
match against number_prefix
and, if the match is found,
H.323_ID will be replaced with NEW_CLI, Calling-Station-Id will remain unchanged./=
- a cli
or dno
number will be matched using an identity
match against number_prefix
and, if both numbers are the same,
H.323_ID will be replaced with NEW_CLI, Calling-Station=Id will remain unchanged,CALLER_IP
or the number_prefix
. To enable CLIR
for this rule,
use the special string constant "hide"
instead of the list of new CLI values.
Note that CLIR is far more useful for outbound rules.
[RewriteCLI]
in:192.168.1.1=dno:5551=3003
in:192.168.1.1=cli:1001=2222
in:192.168.1.1=any=1111
These rules state that for calls from the IP 192.168.1.1: 1) if the user dialed a number beginning with 5551, set CLI to 3003, 2) if the call is from user with CLI beginning with 1001, set CLI to 2222, 3) for other calls from this IP, set CLI to 1111.
[RewriteCLI]
in:192.168.1.0/24=any=18001111
in:192.168.2.0/24=any=18002222
in:2002:4ad0:ff00:79a::2/64=any=18003333
in:any=any=0
These rules state that: 1) for calls from the network 192.168.1.0/24, set CLI to 18001111, 2) for calls from the network 192.168.2.0/24, set CLI to 18002222, 3) for calls from the network 2002:4ad0:ff00:79a::2/64, set CLI to 18003333, 4) for other calls, set CLI to 0.
[RewriteCLI]
in:192.168.1.0/24=0048*=48
in:192.168.1.0/24=0*=48
in:any=100.~=48900900900
These rules state that: 1) for calls from the network 192.168.1.0/24, rewrite 0048 to 48 (example - 0048900900900 => 48900900900), 2) for other calls from the network 192.168.1.0/24, rewrite 0 to 48 (example - 0900900900 => 48900900900), 3) for other calls, if CLI is 4 digits and starts with 100, set it to 48900900900.
[RewriteCLI]
in:192.168.1.0/24=any=hide
This example causes caller's number to be removed from Setup messages originating from the 192.168.1.0/24 network. It also causes proper presentation and screening indicators to be set in Setup messages.
out:CALLER_IP=CALLEE_IP [pi=[allow|restrict][,forward|apply|applyforterminals]] [cli:|dno:|cno:]number_prefix(=|~=|*=)NEW_CLI[,NEW_CLI]...
The out:
prefix tells that this is an outbound rule, the CALLER_IP
and the CALLEE_IP
will be used to match the rule and can be a single IP
or a subnet address.
The optional pi=
parameter controls CLIR (Calling Line Identification Restriction)
features. Specifying either allow
or restrict
forces the presentation indicator
to be set to "presentation allowed" or "presentation restricted". forward
, apply
and applyforterminals
controls how the received (if any) presentation indicator
is processed by the gatekeeper. forward
means just to forward it to the callee as-is,
apply
means hiding CLI if the PI is set to "presentation restricted", applyforterminals
is similar to apply
, except that the CLI is hidden only when sending the call to a terminal,
not a gateway.
The prefix cli:
, dno:
(the default) or cno:
selects what number
will be used to match the number_prefix
- a caller id (CLI/ANI),
a dialed number or a destination/called number (the dialed number after rewrite).
Number matching/rewriting can be done in three ways:
=
- a cli
or dno
number will be matched using a prefix
match against number_prefix
and, if the match is found,
CLI will be replaced with NEW_CLI,~=
- a cli
or dno
number will be matched using an identity
match against number_prefix
and, if both numbers are the same,
CLI will be replaced with NEW_CLI,*=
- (VALID ONLY FOR cli
) a cli
number will be matched using
a prefix match against number_prefix
and, if the match is found,
the matched CLI prefix (number_prefix
) will be replaced
with a NEW_CLI prefix.CALLER_IP
, the CALLEE_IP
or the number_prefix
.
To enable CLIR
for this rule, use a special string constant "hide"
or "hidefromterminals"
instead of the list of new CLI values.
[RewriteCLI]
out:any=192.168.1.1 any=1001
out:any=192.168.1.2 any=1002
These rules set a fixed ANI/CLI for each terminating IP: 1) present myself with ANI 1001, when sending calls to IP 192.168.1.1, 2) present myself with ANI 1002, when sending calls to IP 192.168.1.2.
[RewriteCLI]
out:any=192.168.1.1 any=1001-1999,3001-3999
This rule randomly selects ANI/CLI from range 1001-1999, 3001-3999 for calls sent to 192.168.1.1.
[RewriteCLI]
out:any=any any=hidefromterminals
out:192.168.1.1=any any=hide
In this example each subscriber has enabled CLIR, so all calls to terminals
will have a caller's number removed and presentation/screening indicators set.
Calls to gateways will have the presentation indicator set to "presentation restricted"
and the caller's number will not be removed to allow proper call routing and number
removal at the destination equipment.
One exception to these rules are calls from 192.168.1.1 which will have a caller's number
always removed, no matter whether calling a terminal or a gateway.
[RewriteCLI]
out:any=192.168.1.1 any=hide
In this example CLIP (Calling Line Identification Presentation) feature is disabled for the user 192.168.1.1.
[RewriteCLI]
out:192.168.1.1=any pi=restrict,apply cli:.*=.
out:any=any pi=allow cli:.*=.
These rules do not change CLI (.*=.) and:
1) enable CLIR for an endpoint 192.168.1.1. apply
tells the gatekeeper
to not only set the PI, but also to hide the number.
2) force CLI presentation for other endpoints.
The rule matching process has a strictly defined order:
dno:
type (dialed number) rules are searched,cno:
type (destination/called number) rules are searched,cli:
type (caller id) rules are searched.On the Windows platform, there is a problem with duplicated config
keys in INI files, so GnuGk provides a workaround for this restriction. This example
will not work because of the same key (in:192.168.1.1
):
[RewriteCLI]
in:192.168.1.1=1001=2001
in:192.168.1.1=any=2000
As a workaround, you can use a string with percent signs (%) at the beginning
and at the end before the key. This prefix will be automatically stripped
from the key name before loading rules:
[RewriteCLI]
%r1% in:192.168.1.1=1001=2001
%r2% in:192.168.1.1=any=2000