Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
84ab232
topology_hiding: add a stored thinfo encoding type
Lt-Flash Oct 30, 2026
ba4ba46
topology_hiding: drop the stored state of a rejected SUBSCRIBE
Lt-Flash Oct 30, 2026
9edd2b7
topology_hiding: add th_state_options to leave OPTIONS without state
Lt-Flash Oct 30, 2026
27b3bde
topology_hiding: refuse a th_state_url which never expires the state
Lt-Flash Oct 30, 2026
b2fd033
topology_hiding: add a sample for the stored encoding
Lt-Flash Oct 30, 2026
64de6a9
topology_hiding: let the stored state test keep its logs
Lt-Flash Oct 30, 2026
a5b2e6e
topology_hiding: send the state inline when th_state_url fails to sto…
Lt-Flash Nov 22, 2026
6473c64
topology_hiding: bound the stored state lifetime by th_state_ttl_max
Lt-Flash Nov 22, 2026
f06933c
topology_hiding: read a Contact ;expires only for a REGISTER
Lt-Flash Nov 22, 2026
682af3b
topology_hiding: tie a stored state key to its own dialog
Lt-Flash Nov 22, 2026
7cf98b2
topology_hiding: stop removing and refreshing a stored state on match
Lt-Flash Nov 22, 2026
b90a978
topology_hiding: keep each dialog to the usage which created its state
Lt-Flash Nov 22, 2026
54fdc45
topology_hiding: give a stored caller state the lifetime its answer set
Lt-Flash Nov 22, 2026
003e8a5
topology_hiding: nest a twice hidden Contact inline
Lt-Flash Nov 22, 2026
efe3c95
topology_hiding: decode a stored state as fully as an inline one
Lt-Flash Nov 22, 2026
4b51b00
topology_hiding: fall back inline only when the state was not stored
Lt-Flash Nov 22, 2026
e678033
topology_hiding: start and recover with th_state_url down or empty
Lt-Flash Nov 22, 2026
3ce6b9e
topology_hiding: drop a SUBSCRIBE state on a local final reply too
Lt-Flash Nov 22, 2026
796de69
topology_hiding: tighten the stored state test
Lt-Flash Nov 22, 2026
cb9a249
topology_hiding: document the stored state lifetimes as they now are
Lt-Flash Nov 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 114 additions & 1 deletion modules/topology_hiding/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ The value has the format *param_name[:password[:encoding_type]]*:

- *param_name* - the name of the Contact URI parameter holding the encoded topology hiding information.
- *password* - the string password used to encode/decode the data. If omitted, the default password "ToPoCtPaSS" is used.
- *encoding_type* - the encoding layout, one of *C*/*c* (compact, the default) or *L*/*l* (long).
- *encoding_type* - the encoding layout, one of *C*/*c* (compact, the default), *L*/*l* (long) or *S*/*s* (stored, see *th_state_url*).


This parameter may be set more than once in order to define multiple (param name, password) entries, which allows password rotation - data encoded with an older password can still be decoded while new data is encoded with the current one. At most 2 entries are supported. Use *th_use_param* to select which entry is used when encoding.
Expand Down Expand Up @@ -306,6 +306,115 @@ modparam("topology_hiding", "th_auto_route_on_trusted_socket", 0)
```


#### th_state_url (string)


A cachedb URL where the topology hiding information of the Contact URI params with the *S* encoding type is kept. Only a 17 characters key, *_* followed by 16 hex digits, then travels in the Contact instead of the whole encoded information, which helps the user agents that truncate long Contact URI params.


The key is derived from the param's password, the Call-ID and the tag of the party whose Contact is hidden, so each refresh of a dialog leg overwrites that leg's information in place. A sequential request is only routed by the key of its own Call-ID and To tag.


The information expires on its own, it is never removed when used:

- a SUBSCRIBE or NOTIFY keeps it for its expires plus 30 seconds. The subscriber's information (stored by its SUBSCRIBEs and its replies to NOTIFYs) never gets less than *th_state_ttl*, as all the notifier dialogs of a forked SUBSCRIBE share it.
- an INVITE or UPDATE keeps it for its Session-Expires plus 30 seconds. Its 2xx then sets the caller's lifetime again: the 2xx's own Session-Expires plus 30 seconds, or *th_state_ttl* when the callee answered without session timers (nothing refreshes such a call, so *th_state_ttl* bounds how long it can last).
- a reply which says nothing about it, as long as its request says, and other messages *th_state_ttl* or *th_state_ttl_short*.
- all of these are cut down to *th_state_ttl_max*.

The reply of the far party to a refresh stores the information again with the lifetime its dialog now has. A final reply of 300 or above to an initial SUBSCRIBE, relayed or our own, drops the subscriber's information (a challenged SUBSCRIBE stores it again when retried).


The information stays in the Contact, compact encoded, for an INVITE or UPDATE without Session-Expires (initial or in-dialog), for a message lacking its Call-ID or tag, for a reply carrying its caller's tag as To tag, for a Contact which already carries one of our keys (a request hidden twice, by a spiral or by two nodes sharing the backend, nests the second state inline), and whenever storing it fails, such as while the backend is down (each process logs a warning counting these at most once a minute, and retries a failed connection every 5 seconds). Inside a dialog, only the messages of the usage which created it are stored (INVITE/UPDATE for a call, SUBSCRIBE/NOTIFY for a subscription): a REFER and its NOTIFYs inside a call go inline and leave the call's information alone.


A Contact URI param value holding a key is looked up whatever the encoding type of its param, as long as *th_state_url* is set. So a param can be switched in place from *C* to *S* and back: a dialog keeps the encoding it started with, its sequential replies included.


The value is the URL of the cachedb module to use, which has to be loaded, such as *redis:th://127.0.0.1:6379/*, *memcached:th://127.0.0.1:11211/* or *local://*. Any cachedb backend supporting get, set and remove, and honouring the expiration of what it stores, can be used: this rules out *cachedb_mongodb*, which is refused at startup. Note that:


- the backend has to be shared by all the nodes which may receive the sequential requests of a dialog. With *cachedb_local*, each node only sees its own states, unless the collection is replicated (see its *cluster_id* parameter).
- *cachedb_sql* and *cachedb_dynamodb* do not check the expiration when reading, so a state may still be found for a while after it expired (up to *cache_clean_period* with *cachedb_sql*).
- the stored information is not obfuscated, so the backend must not be reachable from untrusted networks.
- while the backend is down, new states go inline, but the sequential requests of the dialogs already stored cannot be routed until it is back. A backend which loses what it stores on restart (*cachedb_local* without replication, a Redis without persistence) loses those dialogs too.


*Default value is "empty" ( no storage ), which an empty string also means*


```opensips title="Set th_state_url parameter"
...
modparam("topology_hiding", "th_contact_encode_param_password", "thinfo:my_topoh_passwd:S")
modparam("topology_hiding", "th_state_url", "redis:th://127.0.0.1:6379/")
...
```


#### th_state_ttl (int)


The lifetime, in seconds, of the stored information whose message does not say how long its dialog lives.


*Default value is "3600"*


```opensips title="Set th_state_ttl parameter"
...
modparam("topology_hiding", "th_state_ttl", 7200)
...
```


#### th_state_ttl_short (int)


The lifetime, in seconds, of the stored information which is only needed while its transaction runs: OPTIONS, MESSAGE, INFO and PUBLISH, a rejected SUBSCRIBE, and the notifier's side of a subscription being ended.


*Default value is "60"*


```opensips title="Set th_state_ttl_short parameter"
...
modparam("topology_hiding", "th_state_ttl_short", 120)
...
```


#### th_state_ttl_max (int)


The longest lifetime, in seconds, the stored information may get. The lifetimes taken from a message (its expires plus 30 seconds, its Session-Expires plus 30 seconds) come from the far end, so they are cut down to this value. It may not exceed 2592000 (30 days, beyond which memcached takes an expiration for an absolute time), nor be lower than *th_state_ttl* or *th_state_ttl_short*.


*Default value is "86400"*


```opensips title="Set th_state_ttl_max parameter"
...
modparam("topology_hiding", "th_state_ttl_max", 7200)
...
```


#### th_state_options (int)


When set to 0, an OPTIONS and its reply carry no topology hiding information at all: their Contact is the address of the proxy with no encoded param, and nothing is stored. Nothing is ever routed to such a Contact, so this saves encoding (or storing) what no request will use. Applies to all the encoding types.


*Default value is "1" ( OPTIONS are handled like any other request )*


```opensips title="Set th_state_options parameter"
...
modparam("topology_hiding", "th_state_options", 0)
...
```


### Exported Functions


Expand Down Expand Up @@ -451,6 +560,10 @@ Read only variable that will contain the callid as it is propagated towards the


NULL will be returned if there is no topology hiding dialog for the request or if topology_hiding with callid encoding was not used for the current dialog.
## Samples

[samples](./samples/samples.md "include")

<!-- CONTRIBUTORS -->

### License
Expand Down
111 changes: 111 additions & 0 deletions modules/topology_hiding/samples/opensips-th-stored.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#
# OpenSIPS dialog-less topology hiding, with the state kept in Redis
#
# Please refer to the OpenSIPS Manuals at:
# https://docs.opensips.org/manual/devel/
# for an explanation of available statements, functions and parameters.
#


####### Global Parameters #########

log_level=3
xlog_level=3
stderror_enabled=no
syslog_enabled=yes
syslog_facility=LOG_LOCAL0

udp_workers=4

socket=udp:127.0.0.1:5060 # CUSTOMIZE ME



####### Modules Section ########

#set module path
mpath="/usr/local/lib/opensips/modules/"

#### SIGNALING module
loadmodule "signaling.so"

#### StateLess module
loadmodule "sl.so"

#### Transaction Module
loadmodule "tm.so"

#### Record Route Module
loadmodule "rr.so"

#### MAX ForWarD module
loadmodule "maxfwd.so"

#### SIP MSG OPerationS module
loadmodule "sipmsgops.so"

#### Redis cachedb backend, holding the topology hiding states
loadmodule "cachedb_redis.so"

#### Topology Hiding module
loadmodule "topology_hiding.so"
/* "S": only a 17 characters key travels in the Contact, the state itself
is stored in th_state_url */
modparam("topology_hiding", "th_contact_encode_param_password",
"thinfo:CHANGE_ME:S") # CUSTOMIZE ME
modparam("topology_hiding", "th_state_url",
"redis:th://127.0.0.1:6379/") # CUSTOMIZE ME
/* nothing is ever routed to the Contact of an OPTIONS keepalive */
modparam("topology_hiding", "th_state_options", 0)

loadmodule "proto_udp.so"


####### Routing Logic ########

# main request routing logic

route{

if (!mf_process_maxfwd_header(10)) {
send_reply(483,"Too Many Hops");
exit;
}

if (has_totag()) {
# sequential requests are routed by the state their R-URI
# points to, whether it was stored or came inline
if (topology_hiding_match()) {
t_relay();
exit;
}

# handle hop-by-hop ACK (no routing required)
if ( is_method("ACK") && t_check_trans() ) {
t_relay();
exit;
}

# unknown or expired state
send_reply(404,"Not here");
exit;
}

# CANCEL processing
if (is_method("CANCEL")) {
if (t_check_trans())
t_relay();
exit;
}

# absorb retransmissions, but do not create transaction
t_check_trans();

# no dialog is created, so any method gets the dialog-less hiding,
# SUBSCRIBE included
topology_hiding();

if (!t_relay())
send_reply(500,"Internal Error");
exit;
}
3 changes: 3 additions & 0 deletions modules/topology_hiding/samples/samples.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### OpenSIPS Config - Dialog-less topology hiding with the stored encoding

[opensips-th-stored.cfg](./opensips-th-stored.cfg "include")
Loading