PROTO_TCP module
Admin Guide
Section titled “Admin Guide”Overview
Section titled “Overview”The proto_tcp module is a built-in transport module which implements SIP TCP-based communication. It does not handle TCP connections management, but only offers higher-level primitives to read and write SIP messages over TCP.
Once loaded, you will be able to define TCP listeners in your script, by adding its IP, and optionally the listening port, in your configuration file, similar to this example:
...socket=tcp:127.0.0.1 # change the listening IPsocket=tcp:127.0.0.1:5080 # change with the listening IP and port...Dependencies
Section titled “Dependencies”OpenSIPS Modules
Section titled “OpenSIPS Modules”The following modules must be loaded before this module:
- None.
External Libraries or Applications
Section titled “External Libraries or Applications”The following libraries or applications must be installed before running OpenSIPS with this module loaded:
- None.
Exported Parameters
Section titled “Exported Parameters”tcp_port (integer)
Section titled “tcp_port (integer)”The default port to be used for all TCP related operation. Be careful as the default port impacts both the SIP listening part (if no port is defined in the TCP listeners) and the SIP sending part (if the destination URI has no explicit port).
If you want to change only the listening port for TCP, use the port option in the SIP listener defintion.
Default value is 5060.
...modparam("proto_tcp", "tcp_port", 5065)...tcp_send_timeout (integer)
Section titled “tcp_send_timeout (integer)”Time in milliseconds after a TCP connection will be closed if it is not available for blocking writing in this interval (and OpenSIPS wants to send something on it).
Default value is 100 ms.
...modparam("proto_tcp", "tcp_send_timeout", 200)...tcp_max_msg_chunks (integer)
Section titled “tcp_max_msg_chunks (integer)”The maximum number of chunks that a SIP message is expected to arrive via TCP. If a packet is received more fragmented than this, the connection is dropped (either the connection is very overloaded and this leads to high fragmentation - or we are the victim of an ongoing attack where the attacker is sending the traffic very fragmented in order to decrease our performance).
Default value is 4.
...modparam("proto_tcp", "tcp_max_msg_chunks", 8)...tcp_crlf_pingpong (integer)
Section titled “tcp_crlf_pingpong (integer)”Send CRLF pong (\r\n) to incoming CRLFCRLF ping messages over TCP. By default it is enabled (1).
Default value is 1 (enabled).
...modparam("proto_tcp", "tcp_crlf_pingpong", 0)...tcp_crlf_drop (integer)
Section titled “tcp_crlf_drop (integer)”Drop CRLF (\r\n) ping messages. When this parameter is enabled, the TCP layer drops packets that contains a single CRLF message. If a CRLFCRLF message is received, it is handled according to the tcp_crlf_pingpong parameter.
Default value is 0 (disabled).
...modparam("proto_tcp", "tcp_crlf_drop", 1)...tcp_async (integer)
Section titled “tcp_async (integer)”If the TCP connect and write operations should be done in an asynchronous mode (non-blocking connect and write). If disabled, OpenSIPS will block and wait for TCP operations like connect and write.
Default value is 1 (enabled).
...modparam("proto_tcp", "tcp_async", 0)...tcp_async_max_postponed_chunks (integer)
Section titled “tcp_async_max_postponed_chunks (integer)”If tcp_async is enabled, this specifies the maximum number of SIP messages that can be stashed for later/async writing. If the connection pending writes exceed this number, the connection will be marked as broken and dropped.
Default value is 32.
...modparam("proto_tcp", "tcp_async_max_postponed_chunks", 16)...tcp_async_local_connect_timeout (integer)
Section titled “tcp_async_local_connect_timeout (integer)”If tcp_async is enabled, this specifies the number of milliseconds that a connect will be tried in blocking mode (optimization). If the connect operation lasts more than this, the connect will go to async mode and will be passed to TCP MAIN for polling.
Default value is 100 ms.
...modparam("proto_tcp", "tcp_async_local_connect_timeout", 200)...tcp_async_local_write_timeout (integer)
Section titled “tcp_async_local_write_timeout (integer)”If tcp_async is enabled, this specifies the number of milliseconds that a write op will be tried in blocking mode (optimization). If the write operation lasts more than this, the write will go to async mode and will be passed to TCP MAIN for polling.
Default value is 10 ms.
...modparam("proto_tcp", "tcp_async_local_write_timeout", 100)...tcp_parallel_handling (integer)
Section titled “tcp_parallel_handling (integer)”This parameter says if the handling/processing (NOT READING) of the SIP messages should be done in parallel (after one SIP msg is read, while processing it, another READ op may be performed).
Default value is 0 (disabled).
...modparam("proto_tcp", "tcp_parallel_handling", 1)...trace_destination (string)
Section titled “trace_destination (string)”Trace destination as defined in the tracing module. Currently the only tracing module is proto_hep. Network events such as connect, accept and connection closed events shall be traced along with errors that could appear in the process.
Default value is none(not defined).
...modparam("proto_hep", "hep_id", "[hep_dest]10.0.0.2;transport=tcp;version=3")
modparam("proto_tcp", "trace_destination", "hep_dest")...trace_on (int)
Section titled “trace_on (int)”This controls whether tracing for tcp is on or not. You still need to define trace destination in order to work, but this value will be controlled using mi function tcp trace.
...modparam("proto_tcp", "trace_on", 1)...trace_filter_route (string)
Section titled “trace_filter_route (string)”Define the name of a route in which you can filter which connections will be trace and which connections won’t be. In this route you will have information regarding source and destination ips and ports for the current connection. To disable tracing for a specific connection the last call in this route must be drop, any other exit mode resulting in tracing the current connection ( of course you still have to define a trace destination and trace must be on at the time this connection is opened.
...modparam("proto_tcp", "trace_filter_route", "tcp_filter").../* all tcp connections will go through this route if tracing is activated * and a trace destination is defined */route[tcp_filter] { ... /* all connections opened from/by ip 1.1.1.1:8000 will be traced on interface 1.1.1.10:5060(opensips listener) all the other connections won't be */ if ( $si == "1.1.1.1" && $sp == 8000 && $socket_in(ip) == "1.1.1.10" && $socket_in(port) == 5060) exit; else drop;}...Exported MI Functions
Section titled “Exported MI Functions”tcp_trace
Section titled “tcp_trace”Name: tcp_trace
Parameters:
- trace_mode(optional): set tcp tracing on and off. This parameter
can be missing and the command will show the current tracing
status for this module( on or off ). Possible values:
- on
- off
MI FIFO Command Format:
:tcp_trace:_reply_fifo_file_ trace_mode _empty_line_Frequently Asked Questions
Section titled “Frequently Asked Questions”Q: After switching to OpenSIPS 2.1, I’m getting this error: “listeners found for protocol tcp, but no module can handle it”
You need to load the “proto_tcp” module. In your script, make sure you do a loadmodule “proto_tcp.so” after setting the mpath.
Q: I cannot locate “proto_tcp.so”. Where is it?
The “proto_udp” and “proto_tcp” modules are simply built into the opensips binary by default. They are not available as shared libraries, but look like modules for code consistency reasons.
Contributors
Section titled “Contributors”By Commit Statistics
Section titled “By Commit Statistics”Top contributors by DevScore(1), authored commits(2) and lines added/removed(3)
| # | Name | DevScore | Commits | Lines++ | Lines— |
|---|---|---|---|---|---|
| 1. | Bogdan-Andrei Iancu (@bogdan-iancu) | 87 | 48 | 2399 | 1060 |
| 2. | Razvan Crainea (@razvancrainea) | 52 | 33 | 852 | 619 |
| 3. | Ionut Ionita (@ionutrazvanionita) | 22 | 13 | 568 | 224 |
| 4. | Liviu Chircu (@liviuchircu) | 12 | 10 | 49 | 33 |
| 5. | Stefan Darius (@dariusstefan) | 10 | 4 | 472 | 85 |
| 6. | Vlad Patrascu (@rvlad-patrascu) | 9 | 7 | 55 | 47 |
| 7. | Vlad Paiu (@vladpaiu) | 5 | 3 | 17 | 11 |
| 8. | Dan Pascu (@danpascu) | 3 | 1 | 8 | 6 |
| 9. | Julián Moreno Patiño | 3 | 1 | 6 | 6 |
| 10. | Nick Altmann (@nikbyte) | 3 | 1 | 2 | 2 |
All remaining contributors: Zero King (@l2dy), Peter Lemenkov (@lemenkov), Matt Krokosz, Ionel Cerghit (@ionel-cerghit).
(1) DevScore = author_commits + author_lines_added / (project_lines_added / project_commits) + author_lines_deleted / (project_lines_deleted / project_commits)
(2) including any documentation-related commits, excluding merge commits
(3) ignoring whitespace edits, renamed files and auto-generated files
By Commit Activity
Section titled “By Commit Activity”| # | Name | Commit Activity |
|---|---|---|
| 1. | Razvan Crainea (@razvancrainea) | Jan 2015 - Jul 2026 |
| 2. | Stefan Darius (@dariusstefan) | Jun 2026 - Jul 2026 |
| 3. | Bogdan-Andrei Iancu (@bogdan-iancu) | Feb 2015 - Sep 2023 |
| 4. | Liviu Chircu (@liviuchircu) | Apr 2015 - Apr 2022 |
| 5. | Vlad Patrascu (@rvlad-patrascu) | May 2017 - Oct 2021 |
| 6. | Nick Altmann (@nikbyte) | May 2021 - May 2021 |
| 7. | Zero King (@l2dy) | Mar 2020 - Mar 2020 |
| 8. | Dan Pascu (@danpascu) | Oct 2018 - Oct 2018 |
| 9. | Peter Lemenkov (@lemenkov) | Jun 2018 - Jun 2018 |
| 10. | Matt Krokosz | Jun 2018 - Jun 2018 |
All remaining contributors: Ionut Ionita (@ionutrazvanionita), Julián Moreno Patiño, Ionel Cerghit (@ionel-cerghit), Vlad Paiu (@vladpaiu).
(1) including any documentation-related commits, excluding merge commits
Documentation
Section titled “Documentation”Contributors
Section titled “Contributors”Last edited by: Razvan Crainea (@razvancrainea), Bogdan-Andrei Iancu (@bogdan-iancu), Vlad Patrascu (@rvlad-patrascu), Zero King (@l2dy), Peter Lemenkov (@lemenkov), Ionut Ionita (@ionutrazvanionita), Liviu Chircu (@liviuchircu).
License
Section titled “License”All documentation files (i.e. .md extension) are licensed under the Creative Common License 4.0