# &adminguide;

## Overview

This module offers topology hiding for INVITE-based dialogs, by stripping the SIP routing headers that show topology details . The script interpreter gets the SIP messages with full content, so all existing functionality is preserved.

The module is transparent for the configuration writer. It only needs to be loaded (tune the module parameters if needed).

It also works for SIP MESSAGE or other requests that do not create a dialog -- record_route() must be used for them as well, the headers are not going to be in the messages sent to the network, they are needed to know local addresses used to communicate with each side. At this moment it is not designed to work for presence (SUBSCRIBE-based) dialogs. The REGISTER and PUBLISH requests are skipped from processing by this module, expected to be terminated on a local SIP server.

## Dependencies

### &kamailio; Modules

The following modules must be loaded before this module:

- rr module - server must perform record routing to ensure in-dialog requests are encoded/decoded (it must be done for all initial requests).

- database module - to store the data for topology stripping and restoring.

### External Libraries or Applications

The following libraries or applications must be installed before running &kamailio; with this module loaded:

- none.

## Parameters

### `storage` (str)

Type of storage, valid types are:

- db - Database Backend

- redis - Redis Backend

Default value is db.

#### Set `storage` parameter

    ...
    modparam("topos", "storage", "redis")
    ...

### `db_url` (str)

Database URL.

Default value is &defaultdb;.

#### Set `db_url` parameter

    ...
    modparam("topos", "db_url", "&exampledb;")
    ...

### `mask_callid` (int)

Note: this functionality is not implemented yet - the parameter is present in order to be in pair with topoh module.

Whether to replace or not the Call-ID with another unique id generated by &kamailio;.

Default value is 0 (do not mask).

#### Set `mask_callid` parameter

    ...
    modparam("topos", "mask_callid", 1)
    ...

### `sanity_checks` (int)

If set to 1, topos module will bind to sanity module in order to perform sanity checks over received SIP request. Default sanity checks are done. It is useful to check if received request is well formatted before proceeding to encoding/decoding.

Default value is 0 (do not bind to sanity module).

#### Set `sanity_checks` parameter

    ...
    modparam("topos", "sanity_checks", 1)
    ...

### `branch_expire` (int)

Interval in seconds after which the branch records are deleted.

Default value is 180 (3 min).

#### Set `branch_expire` parameter

    ...
    modparam("topos", "branch_expire", 300)
    ...

### `dialog_expire` (int)

Interval in seconds after which the dialog records are deleted. Keep in mind that the module does not update the dialog timestamp after the initial call setup on re-INVITEs or other in-dialog messages. So set a large enough value (according your longest call duration) to prevent problems in re-writing messages.

Default value is 10800 (3 hours).

#### Set `dialog_expire` parameter

    ...
    modparam("topos", "dialog_expire", 3600)
    ...

### `clean_interval` (int)

Interval in seconds to run the clean up of stored records.

Default value is 60 (1 min).

#### Set `clean_interval` parameter

    ...
    modparam("topos", "clean_interval", 30)
    ...

### `event_callback` (str)

The name of the function in the KEMI configuration file (embedded scripting language such as Lua, Python, ...) to be executed instead of event_route[...] blocks.

The function receives a string parameter with the name of the event.

Default value is 'empty' (no function is executed for events).

#### Set `event_callback` parameter

    ...
    modparam("topos", "event_callback", "ksr_topos_event")
    ...
    -- event callback function implemented in Lua
    function ksr_topos_event(evname)
    	KSR.info("===== topos module triggered event: " .. evname .. "\n");
    	return 1;
    end
    ...

### `event_mode` (int)

Control what event_route blocks to be executed. It is a bitmask of: 1 - execute event_route[topos:outgoing]; 2 - execute event_route[topos:sending].

Default value is 3 (execute both event_route blocks).

#### Set `event_mode` parameter

    ...
    modparam("topos", "event_mode", 2)
    ...

### `contact_host` (str)

You may need to control the host part of the Contact header added by topos. For example when using TLS with TOPOS the remote UAS must be able to open a new TLS socket to the contact header. In this case, the contact header must contain a domain name with a trusted CA signed certitificate.

Default value is taken from the Record-Route URI.

#### Set `contact_host` parameter

    ...
    modparam("topos", "contact_host", "proxy.domain.com")
    ...

## Event Routes

### event_route[topos:msg-outgoing]

It is executed before doing topology stripping processing for an outgoing SIP message. If 'drop' is executed inside the event route, then the module skips doing the topology hiding.

Inside the event route the variables $sndto(ip), $sndto(port) and $sndto(proto) point to the destination. The SIP message is not the one to be sent out, but an internally generated one at startup, to avoid reparsing the outgoing SIP message for the cases when topology hiding is not wanted.

#### Usage of event_route[topos:msg-outgoing]

    ...
    event_route[topos:msg-outgoing] {
      if($sndto(ip)=="10.1.1.10") {
        drop;
      }
    }
    ...

### event_route[topos:msg-sending]

It is executed before doing topology stripping processing for a SIP message to be sent out, being executed after event_route[topos:msg-outgoing].

Inside the event route the variables $sndto(ip), $sndto(port) and $sndto(proto) point to the destination. The SIP message is the one to be sent out.

#### Usage of event_route[topos:msg-sending]

    ...
    event_route[topos:msg-sending] {
      if(is_request() and $fU=="alice") {
        drop;
      }
    }
    ...