SIP Sockets Management at runtime in OpenSIPS 3.6

When it comes to high-performance SIP platforms like OpenSIPS, flexibility and uptime are crucial, especially in scenarios involving Session Border Controllers (SBCs) and trunking services. Traditionally, OpenSIPS has only supported statically defined SIP sockets, meaning any changes — such as adding new sockets to support additional interconnections — required a full service restart. This limitation becomes particularly problematic in SBC or trunking scenarios, where new interconnections often need to be established dynamically in response to new network demands. In such high-traffic environments, restarting OpenSIPS just to accommodate a new socket can lead to unnecessary downtime and potential service disruption.

Consider a trunking setup where new carriers are added dynamically over a separate/new VLAN, or an SBC that needs to open up new pathways based on changing interconnection demands. Restarting OpenSIPS just to add a new socket is hardly ideal.

To address this, OpenSIPS 3.6 is introducing a new Sockets Management module that provides support for dynamic sockets. This module allows sockets to be provisioned via a database and refreshed by OpenSIPS at runtime, eliminating the need for service interruptions. Through this module, OpenSIPS offers a flexible and efficient way to manage sockets dynamically while maintaining service continuity.

How It Works

When it comes to handling, dynamic sockets in OpenSIPS operate slightly differently compared to the traditional static ones, especially for UDP-based traffic. While we strive to preserve the platform’s flexibility and scalability, the dynamic requirements introduce a new approach. For static sockets, each configured socket has its own dedicated pool of worker processes assigned at startup, ensuring isolated and optimized handling of traffic per socket. In contrast, all dynamic UDP sockets share a common set of processes. This shared pool is statically allocated at startup and is responsible for handling all dynamically added UDP sockets. This design allows OpenSIPS to support dynamic socket management without the need to spawn or adjust processes at runtime, keeping resource usage predictable and stable.

On the other hand, TCP-based dynamic sockets (such as TCP, TLS, WSS) — are handled in the same manner as static ones. The existing TCP process pool manages both static and dynamic sockets uniformly, preserving the well-established and scalable model OpenSIPS uses for connection-oriented transports.

Setting up

To get started with dynamic socket management in OpenSIPS, the first step is to load the dynamic sockets management module.

loadmodule "sockets_mgm.so"

Once that’s in place, you need to configure and scale it properly.

modparam("sockets_mgm", "processes", 8)
modparam("sockets_mgm", "max_sockets", 100)
modparam("sockets_mgm", "db_url", "mysql://...")

Do note that the values above are the default ones and you need to adjust them properly. This step is quite sensitive, as it requires a careful estimation of how many sockets you might need. You don’t want to set too many processes, as this could lead to unnecessary resource usage, but you also want to ensure there are enough processes available to adapt to any topology changes. Striking the right balance is crucial to maintaining both efficiency and flexibility.

Once the parameters are carefully selected, you can start OpenSIPS.

Whenever new socket requirements arise, the first step is to ensure the machine is configured to provide the new IP addresses. Next, you’ll need to provision the dynamic socket in the database. This is done by inserting the new socket entries into the (default) sockets table. Here, you can define the protocol, IP, and port for the new socket. Additionally, you have the option to fine-tune various parameters, such as the advertised address and ports, assign a tag, and set specific flags (e.g., reuse_port, anycast) or a ToS (Type of Service) value.

Once all the new sockets are set up in the database, you need to inform OpenSIPS to use the newly provisioned sockets. This is done by running the sockets_reload MI (Management Interface) command.

You can also use the sockets_list MI (Management Interface) command at any time to list the active (or provisioned) sockets.

Limitations

While dynamic sockets bring valuable flexibility to OpenSIPS deployments, there are several important limitations to be aware of:

FIFO Rotation Mechanism
The sockets allocated under max_sockets are rotated using a FIFO (First-In, First-Out) scheme. This helps avoid overlapping socket assignments within a short period, ensuring smoother socket lifecycle management.

Fixed Process Pool for UDP Handling
UDP dynamic sockets do not benefit from the autoscaling feature available for designated extra processes. The number of processes allocated at startup is fixed, and only these processes will handle all traffic for dynamically added UDP sockets.

SIP-Only Support
Currently, the dynamic sockets module supports only SIP-based dynamic listeners. Other protocols such as HEP and BIN are not supported.

Single Listener per Socket Definition
Sockets defined in the database cannot expand to multiple listeners. Using an interface name or an alias that resolves to multiple IPs is not supported. Each dynamic socket must be provisioned with a specific IP:port pair.

Pre-Allocation Requirement
Due to internal limitations, dynamic sockets must be pre-allocated at startup. The number of dynamic sockets used at runtime is capped by a static limit defined at startup. It is recommended to set this limit generously using the max_sockets parameter — by default, OpenSIPS sets this to a comfortable 100 sockets.

Conclusions

In today’s dynamic SIP environments, network topologies and interconnection requirements can change frequently. That’s why it is a good idea to always be prepared for such changes by adopting dynamic socket management. By leveraging dynamic sockets in OpenSIPS, you gain the flexibility to adapt to new scenarios without service interruptions. This ensures your platform remains agile and scalable as your deployment grows.

To delve deeper into dynamic sockets and other exciting features, consider attending the OpenSIPS Summit 2025. It will take place from May 27th to 30th at the Radisson Blu City Center in Amsterdam.

Leave a comment