Skip to content

Commit

Permalink
modules/tcpops: new module to tweak TCP options
Browse files Browse the repository at this point in the history
This module adds the ability to control TCP options (currently only keepalive)
through the kamailio cfg, on demand, and on a per-socket basis.
  • Loading branch information
camilleoudot committed Feb 6, 2015
1 parent ff11428 commit 5193ff2
Show file tree
Hide file tree
Showing 9 changed files with 709 additions and 0 deletions.
14 changes: 14 additions & 0 deletions modules/tcpops/Makefile
@@ -0,0 +1,14 @@
#
# TCP keepelive module
#
#
# WARNING: do not run this directly, it should be run by the master Makefile

include ../../Makefile.defs
auto_gen=
NAME=tcpops.so
LIBS=

DEFS+=-DKAMAILIO_MOD_INTERFACE

include ../../Makefile.modules
115 changes: 115 additions & 0 deletions modules/tcpops/README
@@ -0,0 +1,115 @@
TCP Ops module

Camille Oudot

Orange

Copyright © 2015 Orange
__________________________________________________________________

Table of Contents

1. Admin Guide

1. Overview
2. Parameters
3. Functions

3.1. tcp_keepalive_enable([conid], idle, count, interval)
3.2. tcp_keepalive_disable([conid])

List of Examples

1.1. tcp_keepalive_enable usage
1.2. tcp_keepalive_disable usage

Chapter 1. Admin Guide

Table of Contents

1. Overview
2. Parameters
3. Functions

3.1. tcp_keepalive_enable([conid], idle, count, interval)
3.2. tcp_keepalive_disable([conid])

1. Overview

This modules allows kamailio to control the TCP options (such as the
keepalive mechanism), on demand, and on a per-socket basis.

Note: the keepalive functions only work on systems with the
HAVE_TCP_KEEPIDLE, HAVE_TCP_KEEPCNT and HAVE_TCP_KEEPINTVL macros
defined (currently only Linux).

2. Parameters

3. Functions

3.1. tcp_keepalive_enable([conid], idle, count, interval)
3.2. tcp_keepalive_disable([conid])

3.1. tcp_keepalive_enable([conid], idle, count, interval)

Enables keepalive on a TCP connection.

Meaning of the parameters is as follows:
* conid (optionnal): the kamailio internal connection id on which TCP
keepalive will be enabled. If no parameter is given, the keepalive
mechanism will be enabled on the current message source connection.
* idle (seconds): the time before the first keepalive packet is sent
out.
* count: number of non-acked keepalive before reseting the
connection.
* interval (seconds): time between two keepalive probes.

Retuns 1 on success, -1 on failure.

Example 1.1. tcp_keepalive_enable usage
request_route {
if (is_method("INVITE")) {
$avp(caller_conid) = $conid;
}
...
}

onreply_route {
if (is_method("INVITE") && status == 200) {
# enable on callee's connection
tcp_keepalive_enable("60", "5", "5");
# enable on caller's connection
tcp_keepalive_enable("$avp(caller_conid)", "60", "5", "2");
}
...
}

3.2. tcp_keepalive_disable([conid])

Disables keepalive on a TCP connection.

Meaning of the parameters is as follows:
* conid (optionnal): the kamailio internal connection id on which TCP
keepalive will be disabled. If no parameter is given, the keepalive
mechanism will be disabled on the current message source
connection.

Retuns 1 on success, -1 on failure.

Example 1.2. tcp_keepalive_disable usage
request_route {
...
if (is_method("BYE")) {
$avp(bye_conid) = $conid;
}
...
}

onreply_route {
...
if (is_method("BYE") && status == 200) {
tcp_keepalive_disable();
tcp_keepalive_disable("$avp(bye_conid)");
}
...
}
4 changes: 4 additions & 0 deletions modules/tcpops/doc/Makefile
@@ -0,0 +1,4 @@
docs = tcpops.xml

docbook_dir=../../../docbook
include $(docbook_dir)/Makefile.module
107 changes: 107 additions & 0 deletions modules/tcpops/doc/functions.xml
@@ -0,0 +1,107 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">

<section id="print.functions" xmlns:xi="http://www.w3.org/2001/XInclude">
<sectioninfo>
</sectioninfo>

<title>Functions</title>

<section id="tcpops.f.tcp_keepalive_enable">
<title>
<function>tcp_keepalive_enable([conid], idle, count, interval)</function>
</title>
<para>
Enables keepalive on a TCP connection.
</para>
<para>Meaning of the parameters is as follows:</para>
<itemizedlist>
<listitem>
<para><emphasis>conid</emphasis> (optionnal): the kamailio internal
connection id on which TCP keepalive will be enabled. If no parameter
is given, the keepalive mechanism will be enabled on the current message
source connection.
</para>
</listitem>
<listitem>
<para><emphasis>idle</emphasis> (seconds): the time before the first
keepalive packet is sent out.
</para>
</listitem>
<listitem>
<para><emphasis>count</emphasis>: number of non-acked keepalive before
reseting the connection.
</para>
</listitem>
<listitem>
<para><emphasis>interval</emphasis> (seconds): time between two keepalive
probes.
</para>
</listitem>
</itemizedlist>
<para>Retuns 1 on success, -1 on failure.</para>
<example>
<title><function>tcp_keepalive_enable</function> usage</title>
<programlisting><![CDATA[
request_route {
if (is_method("INVITE")) {
$avp(caller_conid) = $conid;
}
...
}
onreply_route {
if (is_method("INVITE") && status == 200) {
# enable on callee's connection
tcp_keepalive_enable("60", "5", "5");
# enable on caller's connection
tcp_keepalive_enable("$avp(caller_conid)", "60", "5", "2");
}
...
}
]]></programlisting>
</example>
</section>

<section id="tcpops.f.tcp_keepalive_disable">
<title>
<function>tcp_keepalive_disable([conid])</function>
</title>
<para>
Disables keepalive on a TCP connection.
</para>
<para>Meaning of the parameters is as follows:</para>
<itemizedlist>
<listitem>
<para><emphasis>conid</emphasis> (optionnal): the kamailio internal
connection id on which TCP keepalive will be disabled. If no parameter
is given, the keepalive mechanism will be disabled on the current message
source connection.
</para>
</listitem>
</itemizedlist>
<para>Retuns 1 on success, -1 on failure.</para>
<example>
<title><function>tcp_keepalive_disable</function> usage</title>
<programlisting><![CDATA[
request_route {
...
if (is_method("BYE")) {
$avp(bye_conid) = $conid;
}
...
}
onreply_route {
...
if (is_method("BYE") && status == 200) {
tcp_keepalive_disable();
tcp_keepalive_disable("$avp(bye_conid)");
}
...
}
]]></programlisting>
</example>
</section>
</section>
13 changes: 13 additions & 0 deletions modules/tcpops/doc/params.xml
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">

<section id="print.parameters" xmlns:xi="http://www.w3.org/2001/XInclude">
<sectioninfo>
</sectioninfo>

<title>Parameters</title>



</section>
44 changes: 44 additions & 0 deletions modules/tcpops/doc/tcpops.xml
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">

<book id="print" xmlns:xi="http://www.w3.org/2001/XInclude">
<bookinfo>
<title>TCP Ops module</title>
<authorgroup>
<author>
<firstname>Camille</firstname>
<surname>Oudot</surname>
<affiliation><orgname>Orange</orgname></affiliation>
<address>
<email>camille.oudot@orange.com</email>
</address>
</author>
</authorgroup>
<copyright>
<year>2015</year>
<holder>Orange</holder>
</copyright>
</bookinfo>
<toc></toc>

<chapter>
<title>Admin Guide</title>
<section id="tcpops.overview">
<title>Overview</title>
<para>
This modules allows kamailio to control the TCP options (such as the keepalive
mechanism), on demand, and on a per-socket basis.
</para>
<para>
<emphasis>Note</emphasis>: the keepalive functions only work on systems with the
HAVE_TCP_KEEPIDLE, HAVE_TCP_KEEPCNT and HAVE_TCP_KEEPINTVL macros defined
(currently only Linux).
</para>
</section>

<xi:include href="params.xml"/>
<xi:include href="functions.xml"/>
</chapter>
</book>

0 comments on commit 5193ff2

Please sign in to comment.